fix: 收敛 commandExecution toolcall 摘要 (#70)
Co-authored-by: Codex <codex@pikas.tech>
This commit is contained in:
@@ -695,9 +695,42 @@ function terminalStatusFromValue(value: unknown): TerminalStatus {
|
||||
|
||||
function toolCallPayload(method: string, item: JsonRecord): JsonRecord {
|
||||
const redacted = redactJson(item);
|
||||
const summary = boundedTextSummary(JSON.stringify(redacted));
|
||||
if (summary.outputTruncated !== true) return { method, item: redacted, summary, outputBytes: summary.outputBytes, outputTruncated: false };
|
||||
return { method, itemPreview: summary.text, summary, outputBytes: summary.outputBytes, outputTruncated: true };
|
||||
const itemId = typeof redacted.id === "string" ? redacted.id : null;
|
||||
const itemType = typeof redacted.type === "string" ? redacted.type : "unknown";
|
||||
const command = typeof redacted.command === "string" ? redacted.command : null;
|
||||
const cwd = typeof redacted.cwd === "string" ? redacted.cwd : null;
|
||||
const status = typeof redacted.status === "string" ? redacted.status : null;
|
||||
const processId = typeof redacted.processId === "string" || typeof redacted.processId === "number" ? String(redacted.processId) : null;
|
||||
const exitCode = typeof redacted.exitCode === "number" ? redacted.exitCode : null;
|
||||
const durationMs = typeof redacted.durationMs === "number" ? redacted.durationMs : null;
|
||||
const outputSummary = toolCallOutputSummary(redacted);
|
||||
return {
|
||||
method,
|
||||
itemId,
|
||||
type: itemType,
|
||||
toolName: itemType,
|
||||
...(command ? { command } : {}),
|
||||
...(cwd ? { cwd } : {}),
|
||||
...(status ? { status } : {}),
|
||||
...(processId ? { processId } : {}),
|
||||
...(exitCode !== null ? { exitCode } : {}),
|
||||
...(durationMs !== null ? { durationMs } : {}),
|
||||
...(outputSummary ? { outputSummary } : {}),
|
||||
valuesPrinted: false,
|
||||
};
|
||||
}
|
||||
|
||||
function toolCallOutputSummary(item: JsonRecord): string | null {
|
||||
const direct = item.outputSummary ?? item.stdoutSummary ?? item.message;
|
||||
if (typeof direct === "string" && direct.trim().length > 0) return String(boundedTextSummary(direct).text);
|
||||
const summary = item.summary;
|
||||
if (typeof summary === "object" && summary !== null && !Array.isArray(summary) && typeof (summary as JsonRecord).text === "string") {
|
||||
const text = String((summary as JsonRecord).text);
|
||||
if (text.trim().length > 0) return String(boundedTextSummary(text).text);
|
||||
}
|
||||
const aggregated = item.aggregatedOutput;
|
||||
if (typeof aggregated === "string" && aggregated.trim().length > 0) return String(boundedTextSummary(aggregated).text);
|
||||
return null;
|
||||
}
|
||||
|
||||
function withOptionalModel(params: JsonRecord, model: string | undefined): JsonRecord {
|
||||
|
||||
Reference in New Issue
Block a user