(message: Record<string, unknown>)
| 37 | } |
| 38 | |
| 39 | function summarizeMessage(message: Record<string, unknown>): string { |
| 40 | const role = typeof message.role === "string" ? message.role : "unknown"; |
| 41 | const content = message.content; |
| 42 | |
| 43 | if (role === "assistant" && Array.isArray(content)) { |
| 44 | const toolCalls = content |
| 45 | .filter((block) => block && typeof block === "object") |
| 46 | .map((block) => block as Record<string, unknown>) |
| 47 | .filter((block) => { |
| 48 | const type = typeof block.type === "string" ? block.type.toLowerCase() : ""; |
| 49 | return type === "toolcall" || type === "tool_use" || type === "tooluse" || type === "functioncall"; |
| 50 | }) |
| 51 | .map((block) => { |
| 52 | const name = typeof block.name === "string" ? block.name : "unknown"; |
| 53 | const args = block.arguments ?? block.input ?? block.params; |
| 54 | return args === undefined ? name : `${name} ${shortText(args, MAX_TOOL_ARGS_LEN)}`; |
| 55 | }); |
| 56 | if (toolCalls.length > 0) return `assistant tool call: ${toolCalls.join("; ")}`; |
| 57 | } |
| 58 | |
| 59 | if (role === "toolResult") { |
| 60 | const toolName = typeof message.toolName === "string" ? message.toolName : "unknown"; |
| 61 | const isError = message.isError === true ? "true" : "false"; |
| 62 | return `toolResult(${toolName}, error=${isError}): ${shortText(content, 260)}`; |
| 63 | } |
| 64 | |
| 65 | return `${role}: ${shortText(content)}`; |
| 66 | } |
| 67 | |
| 68 | function buildJudgeInput(state: SessionState, assistantMessage: unknown): string { |
| 69 | const messages = [...(state.historyMessages ?? []), ...(state.currentMessages ?? [])] |
no test coverage detected