feat: initial commit
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import type { AgentSessionEvent } from "@earendil-works/pi-coding-agent";
|
||||
import type { EventInput, HarnessEventType } from "@agent-studio/shared";
|
||||
import { redactValue } from "./errors.js";
|
||||
|
||||
export interface PiAdapterContext { runId: string; assistantMessageId: string }
|
||||
export type MappedEvent = { [T in HarnessEventType]: EventInput<T> }[HarnessEventType];
|
||||
|
||||
export function mapPiEvent(event: AgentSessionEvent, context: PiAdapterContext): MappedEvent[] {
|
||||
switch (event.type) {
|
||||
case "message_update":
|
||||
if (event.assistantMessageEvent.type === "text_delta") return [{ type: "assistant.delta", runId: context.runId, payload: { messageId: context.assistantMessageId, delta: event.assistantMessageEvent.delta } }];
|
||||
return [];
|
||||
case "message_end":
|
||||
if (event.message.role === "assistant") return [{ type: "assistant.completed", runId: context.runId, payload: { messageId: context.assistantMessageId } }];
|
||||
return [];
|
||||
case "tool_execution_start":
|
||||
return [{ type: "tool.requested", runId: context.runId, payload: { toolCallId: event.toolCallId, toolName: event.toolName, arguments: redactValue(event.args) } }];
|
||||
case "tool_execution_end":
|
||||
return event.isError
|
||||
? [{ type: "tool.failed", runId: context.runId, payload: { toolCallId: event.toolCallId, toolName: event.toolName, error: "Tool execution failed" } }]
|
||||
: [{ type: "tool.completed", runId: context.runId, payload: { toolCallId: event.toolCallId, toolName: event.toolName, result: summarizeToolResult(event.toolName, event.result) } }];
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
function summarizeToolResult(toolName: string, result: unknown): unknown {
|
||||
if (["read", "grep", "find", "ls"].includes(toolName)) return { status: "success" };
|
||||
return redactValue(result);
|
||||
}
|
||||
Reference in New Issue
Block a user