Verbose: include tool arg metadata in prefixes
This commit is contained in:
@@ -69,11 +69,16 @@ describe("agent buildArgs + parseOutput helpers", () => {
|
||||
|
||||
it("piSpec carries tool names when present", () => {
|
||||
const stdout =
|
||||
'{"type":"message_end","message":{"role":"tool_result","name":"bash","content":[{"type":"text","text":"ls output"}]}}';
|
||||
'{"type":"message_end","message":{"role":"tool_result","name":"bash","details":{"command":"ls -la"},"content":[{"type":"text","text":"ls output"}]}}';
|
||||
const parsed = piSpec.parseOutput(stdout);
|
||||
const tool = parsed.toolResults?.[0] as { text?: string; toolName?: string };
|
||||
const tool = parsed.toolResults?.[0] as {
|
||||
text?: string;
|
||||
toolName?: string;
|
||||
meta?: string;
|
||||
};
|
||||
expect(tool?.text).toBe("ls output");
|
||||
expect(tool?.toolName).toBe("bash");
|
||||
expect(tool?.meta).toBe("ls -la");
|
||||
});
|
||||
|
||||
it("codexSpec parses agent_message and aggregates usage", () => {
|
||||
|
||||
@@ -18,6 +18,8 @@ type PiAssistantMessage = {
|
||||
toolName?: string;
|
||||
tool_call_id?: string;
|
||||
toolCallId?: string;
|
||||
details?: Record<string, unknown>;
|
||||
arguments?: Record<string, unknown>;
|
||||
};
|
||||
|
||||
function inferToolName(msg: PiAssistantMessage): string | undefined {
|
||||
@@ -39,6 +41,23 @@ function inferToolName(msg: PiAssistantMessage): string | undefined {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function deriveToolMeta(msg: PiAssistantMessage): string | undefined {
|
||||
const details = msg.details ?? msg.arguments;
|
||||
const pathVal = details && typeof details.path === "string" ? details.path : undefined;
|
||||
const offset = details && typeof details.offset === "number" ? details.offset : undefined;
|
||||
const limit = details && typeof details.limit === "number" ? details.limit : undefined;
|
||||
const command = details && typeof details.command === "string" ? details.command : undefined;
|
||||
|
||||
if (pathVal) {
|
||||
if (offset !== undefined && limit !== undefined) {
|
||||
return `${pathVal}:${offset}-${offset + limit}`;
|
||||
}
|
||||
return pathVal;
|
||||
}
|
||||
if (command) return command;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function parsePiJson(raw: string): AgentParseResult {
|
||||
const lines = raw.split(/\n+/).filter((l) => l.trim().startsWith("{"));
|
||||
|
||||
@@ -87,7 +106,11 @@ function parsePiJson(raw: string): AgentParseResult {
|
||||
.join("\n")
|
||||
.trim();
|
||||
if (toolText) {
|
||||
toolResults.push({ text: toolText, toolName: inferToolName(msg) });
|
||||
toolResults.push({
|
||||
text: toolText,
|
||||
toolName: inferToolName(msg),
|
||||
meta: deriveToolMeta(msg),
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
|
||||
@@ -18,6 +18,7 @@ export type AgentMeta = {
|
||||
export type AgentToolResult = {
|
||||
text: string;
|
||||
toolName?: string;
|
||||
meta?: string;
|
||||
};
|
||||
|
||||
export type AgentParseResult = {
|
||||
|
||||
Reference in New Issue
Block a user