feat: add structured silent output contract

This commit is contained in:
Eyejoker
2026-03-28 05:56:58 +09:00
parent e1fdc47552
commit fe6314108c
13 changed files with 346 additions and 52 deletions

37
src/agent-output.ts Normal file
View File

@@ -0,0 +1,37 @@
import type { StructuredAgentOutput } from './types.js';
export function stringifyLegacyAgentResult(
result: string | object | null | undefined,
): string | null {
if (result === null || result === undefined) return null;
if (typeof result === 'string') return result;
try {
return JSON.stringify(result);
} catch {
return null;
}
}
export function getAgentOutputText(
output: {
output?: StructuredAgentOutput;
result?: string | object | null;
},
): string | null {
if (output.output?.visibility === 'silent') {
return null;
}
if (output.output?.visibility === 'public') {
return output.output.text;
}
return stringifyLegacyAgentResult(output.result);
}
export function isSilentAgentOutput(
output: {
output?: StructuredAgentOutput;
},
): boolean {
return output.output?.visibility === 'silent';
}