


























@@ -192,16 +192,21 @@ export function createCodexDynamicToolBridge(params: {
192192 startedAt,
193193});
194194const terminalType = inferToolResultDiagnosticTerminalType(result, resultIsError);
195-return withSideEffectEvidence(
196-withDiagnosticTerminalType(
197-{
198-contentItems: convertToolContents(result.content, toolResultMaxChars),
199-success: !resultIsError,
200-},
201-terminalType,
202-),
203-terminalType !== "blocked",
195+const response = withDiagnosticTerminalType(
196+{
197+contentItems: convertToolContents(result.content, toolResultMaxChars),
198+success: !resultIsError,
199+},
200+terminalType,
201+);
202+withDynamicToolTermination(
203+response,
204+rawResult.terminate === true ||
205+result.terminate === true ||
206+isToolResultYield(rawResult) ||
207+isToolResultYield(result),
204208);
209+return withSideEffectEvidence(response, terminalType !== "blocked");
205210} catch (error) {
206211collectToolTelemetry({
207212toolName: tool.name,
@@ -463,10 +468,21 @@ function isToolResultError(result: AgentToolResult<unknown>): boolean {
463468status !== "success" &&
464469status !== "completed" &&
465470status !== "recorded" &&
466-status !== "running"
471+status !== "pending" &&
472+status !== "started" &&
473+status !== "running" &&
474+status !== "yielded"
467475);
468476}
469477478+function isToolResultYield(result: AgentToolResult<unknown>): boolean {
479+const details = result.details;
480+if (!isRecord(details) || typeof details.status !== "string") {
481+return false;
482+}
483+return details.status.trim().toLowerCase() === "yielded";
484+}
485+470486function inferToolResultDiagnosticTerminalType(
471487result: AgentToolResult<unknown>,
472488isError: boolean,
@@ -508,6 +524,21 @@ function withSideEffectEvidence<T extends CodexDynamicToolCallResponse>(
508524return response;
509525}
510526527+function withDynamicToolTermination<T extends CodexDynamicToolCallResponse>(
528+response: T,
529+terminate: boolean,
530+): T {
531+if (!terminate) {
532+return response;
533+}
534+Object.defineProperty(response, "terminate", {
535+configurable: true,
536+enumerable: false,
537+value: true,
538+});
539+return response;
540+}
541+511542function normalizeToolResultMaxChars(maxChars: number): number {
512543return typeof maxChars === "number" && Number.isFinite(maxChars) && maxChars > 0
513544 ? Math.floor(maxChars)
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。