veryfront 0.1.326 → 0.1.328

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/esm/deno.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export default {
2
2
  "name": "veryfront",
3
- "version": "0.1.326",
3
+ "version": "0.1.328",
4
4
  "license": "Apache-2.0",
5
5
  "nodeModulesDir": "auto",
6
6
  "workspace": [
@@ -125,6 +125,35 @@ export declare function runFrameworkForkStep(input: {
125
125
  stream: ReadableStream<Uint8Array>;
126
126
  responsePromise: Promise<AgentResponse>;
127
127
  }>;
128
+ export type ForkRuntimeContinuationPromptResolver = (input: {
129
+ step: ForkRuntimeStep;
130
+ stepIndex: number;
131
+ }) => Promise<string | null> | string | null;
132
+ export declare function buildForkRuntimeStepFromResponse(response: AgentResponse): ForkRuntimeStep;
133
+ export declare function shouldContinueForkRuntimeStep(step: ForkRuntimeStep, response: AgentResponse): boolean;
134
+ export declare function createForkRuntimeUserMessage(input: {
135
+ text: string;
136
+ id?: string;
137
+ timestamp?: number;
138
+ }): AgentMessage;
139
+ export declare function createInitialForkRuntimeMessages(input: {
140
+ initialMessages?: readonly AgentMessage[];
141
+ prompt?: string;
142
+ }): AgentMessage[];
143
+ export declare function getMaxForkRuntimeStepCount(input: {
144
+ maxSteps: number;
145
+ maxContinuationSteps?: number;
146
+ }): number;
147
+ export declare function resolveForkRuntimeContinuationState(input: {
148
+ continuationStepsRemaining: number;
149
+ onBeforeStop?: ForkRuntimeContinuationPromptResolver;
150
+ step: ForkRuntimeStep;
151
+ currentMessages: AgentMessage[];
152
+ stepIndex: number;
153
+ }): Promise<{
154
+ continuationStepsRemaining: number;
155
+ currentMessages: AgentMessage[];
156
+ } | null>;
128
157
  export declare function createStreamedStepState(): StreamedStepState;
129
158
  export declare function applyPartToStreamedStepState(state: StreamedStepState, part: ForkPart): void;
130
159
  export declare function resolveForkStepResponse(input: {
@@ -1 +1 @@
1
- {"version":3,"file":"fork-runtime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EAAE,sBAAsB,EAC7B,KAAK,EAAE,oBAAoB,GAC1B,QAAQ,EAAE,CAqJZ"}
@@ -56,6 +56,75 @@ export async function runFrameworkForkStep(input) {
56
56
  responsePromise,
57
57
  };
58
58
  }
59
+ export function buildForkRuntimeStepFromResponse(response) {
60
+ const toolCalls = response.toolCalls.map((toolCall) => ({
61
+ toolCallId: toolCall.id,
62
+ toolName: toolCall.name,
63
+ input: toolCall.args,
64
+ }));
65
+ const toolResults = response.toolCalls.flatMap((toolCall) => toolCall.status === "completed"
66
+ ? [
67
+ {
68
+ toolCallId: toolCall.id,
69
+ toolName: toolCall.name,
70
+ input: toolCall.args,
71
+ output: toolCall.result,
72
+ },
73
+ ]
74
+ : []);
75
+ const finishReasonValue = response.metadata?.finishReason;
76
+ return {
77
+ text: response.text,
78
+ messages: structuredClone(response.messages),
79
+ toolCalls,
80
+ toolResults,
81
+ finishReason: typeof finishReasonValue === "string" ? finishReasonValue : null,
82
+ };
83
+ }
84
+ export function shouldContinueForkRuntimeStep(step, response) {
85
+ return step.finishReason === "tool-calls" &&
86
+ response.toolCalls.some((toolCall) => toolCall.status !== "error");
87
+ }
88
+ export function createForkRuntimeUserMessage(input) {
89
+ return {
90
+ id: input.id ?? dntShim.crypto.randomUUID(),
91
+ role: "user",
92
+ parts: [{ type: "text", text: input.text }],
93
+ timestamp: input.timestamp ?? Date.now(),
94
+ };
95
+ }
96
+ export function createInitialForkRuntimeMessages(input) {
97
+ const currentMessages = input.initialMessages?.map((message) => ({
98
+ ...message,
99
+ parts: [...message.parts],
100
+ })) ?? [];
101
+ if (typeof input.prompt !== "string") {
102
+ return currentMessages;
103
+ }
104
+ return [...currentMessages, createForkRuntimeUserMessage({ text: input.prompt })];
105
+ }
106
+ export function getMaxForkRuntimeStepCount(input) {
107
+ return input.maxSteps + (input.maxContinuationSteps ?? 0);
108
+ }
109
+ export async function resolveForkRuntimeContinuationState(input) {
110
+ if (input.continuationStepsRemaining <= 0 || !input.onBeforeStop) {
111
+ return null;
112
+ }
113
+ const continuationPrompt = await input.onBeforeStop({
114
+ step: input.step,
115
+ stepIndex: input.stepIndex,
116
+ });
117
+ if (typeof continuationPrompt !== "string" || continuationPrompt.trim().length === 0) {
118
+ return null;
119
+ }
120
+ return {
121
+ continuationStepsRemaining: input.continuationStepsRemaining - 1,
122
+ currentMessages: [
123
+ ...input.currentMessages,
124
+ createForkRuntimeUserMessage({ text: continuationPrompt }),
125
+ ],
126
+ };
127
+ }
59
128
  export function createStreamedStepState() {
60
129
  return {
61
130
  text: "",
@@ -0,0 +1,130 @@
1
+ import type { ChatMessageMetadata, ChatUiMessageChunk } from "../chat/protocol.js";
2
+ import { type ChildRunExecutionResult, type ChildRunExecutionSnapshot, type ChildRunExecutionUsage } from "./child-run-execution-snapshot.js";
3
+ import { type HostedChildExecutionLogEntry } from "./hosted-child-execution-logging.js";
4
+ import type { HostedChildPendingToolCallState, HostedChildPendingToolLifecycleCloseReason } from "./hosted-child-pending-tool-lifecycle.js";
5
+ import type { ForkPart, ForkRuntimeStreamResult } from "./fork-runtime-stream.js";
6
+ export interface HostedChildForkStreamHandlingState {
7
+ activeToolCallId: string | null;
8
+ finalText: string;
9
+ shouldSeparateNextTextBlock: boolean;
10
+ }
11
+ export interface HostedChildForkStreamLogger {
12
+ debug?: (message: string, metadata?: Record<string, unknown>) => void;
13
+ info?: (message: string, metadata?: Record<string, unknown>) => void;
14
+ warn?: (message: string, metadata?: Record<string, unknown>) => void;
15
+ }
16
+ export interface HostedChildForkPendingToolLifecycle {
17
+ emitToolInputStartIfNeeded: (toolCallId: string, toolName: string) => Promise<void> | void;
18
+ upsertPendingToolCall: (toolCallId: string, state: HostedChildPendingToolCallState) => void;
19
+ deletePendingToolCall: (toolCallId: string) => void;
20
+ closePendingToolCalls: (reason: HostedChildPendingToolLifecycleCloseReason) => Promise<void> | void;
21
+ }
22
+ export interface HostedChildForkStreamTraceInput {
23
+ conversationId?: string;
24
+ parentRunId?: string;
25
+ partType: ForkPart["type"];
26
+ }
27
+ export interface ExecuteHostedChildForkStreamInput {
28
+ streamResult: ForkRuntimeStreamResult;
29
+ abortSignal?: AbortSignal;
30
+ abortForkStream: (error: Error) => void;
31
+ conversationId?: string;
32
+ parentRunId?: string;
33
+ description: string;
34
+ kind: string;
35
+ durableRunMirror: boolean;
36
+ durableMessageId: string | null;
37
+ durableReasoningMessageId: string | null;
38
+ durableMirrorState: {
39
+ reasoningStarted: boolean;
40
+ textStarted: boolean;
41
+ };
42
+ appendDurableMirrorChunk: (chunk: ChatUiMessageChunk<ChatMessageMetadata>) => Promise<void>;
43
+ closeDurableMirrorReasoning: () => Promise<void>;
44
+ closeDurableMirrorText: () => Promise<void>;
45
+ markDurableStepStarted: () => void;
46
+ durableMirrorHasEmittedProgress: () => boolean;
47
+ pendingToolLifecycle: HostedChildForkPendingToolLifecycle;
48
+ toolCalls: Array<{
49
+ toolName: string;
50
+ toolCallId: string;
51
+ input?: unknown;
52
+ }>;
53
+ toolResults: Array<{
54
+ toolName: string;
55
+ toolCallId: string;
56
+ input: unknown;
57
+ output: unknown;
58
+ }>;
59
+ streamState: {
60
+ finalText: string;
61
+ };
62
+ usage?: ChildRunExecutionUsage;
63
+ maxSteps: number;
64
+ startTime: number;
65
+ finalizationTimeoutMs: number;
66
+ onSettled?: (snapshot: ChildRunExecutionSnapshot) => void | Promise<void>;
67
+ idleTimeoutMs: number;
68
+ activeToolTimeoutMs: number;
69
+ postToolIdleTimeoutMs: number;
70
+ logger?: HostedChildForkStreamLogger;
71
+ writeLog?: (entry: HostedChildExecutionLogEntry) => void;
72
+ tracePart?: (input: HostedChildForkStreamTraceInput) => void | Promise<void>;
73
+ }
74
+ export declare function finalizeHostedChildForkCompletion(input: {
75
+ streamResult: ForkRuntimeStreamResult;
76
+ finalText: string;
77
+ description: string;
78
+ kind: string;
79
+ maxSteps: number;
80
+ toolCalls: Array<{
81
+ toolName: string;
82
+ toolCallId: string;
83
+ input?: unknown;
84
+ }>;
85
+ toolResults: Array<{
86
+ toolName: string;
87
+ toolCallId: string;
88
+ input: unknown;
89
+ output: unknown;
90
+ }>;
91
+ usage?: ChildRunExecutionUsage;
92
+ startTime: number;
93
+ durableMessageId: string | null;
94
+ durableMirrorHasEmittedProgress: boolean;
95
+ appendDurableMirrorChunk: (chunk: ChatUiMessageChunk<ChatMessageMetadata>) => Promise<void>;
96
+ finalizationTimeoutMs: number;
97
+ onSettled?: (snapshot: ChildRunExecutionSnapshot) => void | Promise<void>;
98
+ logger?: HostedChildForkStreamLogger;
99
+ writeLog?: (entry: HostedChildExecutionLogEntry) => void;
100
+ }): Promise<ChildRunExecutionResult>;
101
+ export declare function handleHostedChildForkStreamPart(input: {
102
+ part: ForkPart;
103
+ conversationId?: string;
104
+ description: string;
105
+ durableMessageId: string | null;
106
+ durableReasoningMessageId: string | null;
107
+ durableMirrorState: {
108
+ reasoningStarted: boolean;
109
+ textStarted: boolean;
110
+ };
111
+ appendDurableMirrorChunk: (chunk: ChatUiMessageChunk<ChatMessageMetadata>) => Promise<void>;
112
+ closeDurableMirrorReasoning: () => Promise<void>;
113
+ closeDurableMirrorText: () => Promise<void>;
114
+ pendingToolLifecycle: HostedChildForkPendingToolLifecycle;
115
+ toolCalls: Array<{
116
+ toolName: string;
117
+ toolCallId: string;
118
+ input?: unknown;
119
+ }>;
120
+ toolResults: Array<{
121
+ toolName: string;
122
+ toolCallId: string;
123
+ input: unknown;
124
+ output: unknown;
125
+ }>;
126
+ state: HostedChildForkStreamHandlingState;
127
+ logger?: HostedChildForkStreamLogger;
128
+ }): Promise<HostedChildForkStreamHandlingState>;
129
+ export declare function executeHostedChildForkStream(input: ExecuteHostedChildForkStreamInput): Promise<ChildRunExecutionResult>;
130
+ //# sourceMappingURL=hosted-child-fork-stream-execution.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hosted-child-fork-stream-execution.d.ts","sourceRoot":"","sources":["../../../src/src/agent/hosted-child-fork-stream-execution.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,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AM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IAC5E,WAAW,EAAE,KAAK,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IAC9F,KAAK,EAAE,kCAAkC,CAAC;IAC1C,MAAM,CAAC,EAAE,2BAA2B,CAAC;CACtC,GAAG,OAAO,CAAC,kCAAkC,CAAC,CAuJ9C;AAED,wBAAsB,4BAA4B,CAChD,KAAK,EAAE,iCAAiC,GACvC,OAAO,CAAC,uBAAuB,CAAC,CA8JlC"}
@@ -0,0 +1,391 @@
1
+ import { buildFallbackUiMessageChunks, extractFinalStepFinishReason, extractFinalStepText, extractFinalStepToolCalls, extractFinalStepToolResults, getStreamSteps, } from "../chat/final-step-fallback.js";
2
+ import { mapHostedStreamPartToChatUiChunks } from "../chat/hosted-ui-chunk-mapping.js";
3
+ import { appendMissingChildRunToolCalls, appendMissingChildRunToolResults, buildChildRunExhaustedStepBudgetErrorMessage, } from "./child-run-final-step-support.js";
4
+ import { buildChildRunFailureResult, buildChildRunFailureSnapshot, buildChildRunResultCommon, buildChildRunSuccessResult, buildChildRunSuccessSnapshot, } from "./child-run-execution-snapshot.js";
5
+ import { formatChildRunStreamPartError, throwIfChildRunAborted, toChildRunToolInputRecord, } from "./child-run-execution-support.js";
6
+ import { buildChildRunResultSummary, summarizeChildRunResultValue, } from "./child-run-result-summary.js";
7
+ import { buildHostedChildCompletedLog, buildHostedChildExhaustedStepBudgetLog, } from "./hosted-child-execution-logging.js";
8
+ import { isAlreadyMirroredHostedChunk, toMirroredHostedStreamPart } from "./hosted-child-mirror.js";
9
+ import { HOSTED_CHILD_STREAM_TIMEOUT_TOKEN, resolveHostedChildPromiseWithTimeout, resolveHostedChildStreamWatchdogState, withHostedChildStreamIdleTimeout, } from "./hosted-child-stream-watchdog.js";
10
+ const SOFT_IDLE_HEARTBEAT_PHASE = "post_tool_idle";
11
+ const MAX_SOFT_IDLE_HEARTBEATS = 2;
12
+ function isSoftIdleHeartbeatPhase(phase) {
13
+ return phase === SOFT_IDLE_HEARTBEAT_PHASE;
14
+ }
15
+ function getStructuredContent(value) {
16
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
17
+ return value;
18
+ }
19
+ if (!("structuredContent" in value)) {
20
+ return value;
21
+ }
22
+ return value.structuredContent;
23
+ }
24
+ export async function finalizeHostedChildForkCompletion(input) {
25
+ const { steps: resolvedSteps, lastStep: finalStep } = await getStreamSteps(input.streamResult, input.finalizationTimeoutMs);
26
+ const stepCount = resolvedSteps.length;
27
+ let finalText = input.finalText;
28
+ let usage = input.usage;
29
+ if (finalText.trim().length === 0) {
30
+ finalText = extractFinalStepText(finalStep);
31
+ }
32
+ const fallbackToolCalls = extractFinalStepToolCalls(finalStep);
33
+ appendMissingChildRunToolCalls(input.toolCalls, fallbackToolCalls);
34
+ const fallbackToolResults = extractFinalStepToolResults(finalStep);
35
+ appendMissingChildRunToolResults(input.toolResults, fallbackToolResults);
36
+ if (!input.durableMirrorHasEmittedProgress && input.durableMessageId) {
37
+ const fallbackChunks = buildFallbackUiMessageChunks(finalStep, input.durableMessageId);
38
+ for (const chunk of fallbackChunks) {
39
+ await input.appendDurableMirrorChunk(chunk);
40
+ }
41
+ }
42
+ const totalUsage = await resolveHostedChildPromiseWithTimeout(input.streamResult.totalUsage, input.finalizationTimeoutMs).catch((error) => {
43
+ input.logger?.warn?.("Child fork total usage failed after stream completion", {
44
+ description: input.description,
45
+ kind: input.kind,
46
+ error: error instanceof Error ? error.message : String(error),
47
+ });
48
+ return null;
49
+ });
50
+ if (totalUsage === HOSTED_CHILD_STREAM_TIMEOUT_TOKEN) {
51
+ input.logger?.warn?.("Child fork total usage timed out after stream completion", {
52
+ description: input.description,
53
+ kind: input.kind,
54
+ timeoutMs: input.finalizationTimeoutMs,
55
+ });
56
+ }
57
+ else if (totalUsage) {
58
+ usage = {
59
+ inputTokens: totalUsage.inputTokens ?? 0,
60
+ outputTokens: totalUsage.outputTokens ?? 0,
61
+ totalTokens: (totalUsage.inputTokens ?? 0) + (totalUsage.outputTokens ?? 0),
62
+ };
63
+ }
64
+ const finalStepFinishReason = extractFinalStepFinishReason(finalStep);
65
+ const agentWantedToContinue = finalStepFinishReason === "tool-calls";
66
+ const exhaustedStepBudget = stepCount >= input.maxSteps && agentWantedToContinue;
67
+ if (exhaustedStepBudget) {
68
+ const errorMessage = buildChildRunExhaustedStepBudgetErrorMessage(stepCount, input.toolCalls);
69
+ input.writeLog?.(buildHostedChildExhaustedStepBudgetLog({
70
+ description: input.description,
71
+ kind: input.kind,
72
+ stepCount,
73
+ maxSteps: input.maxSteps,
74
+ toolCallsLength: input.toolCalls.length,
75
+ }));
76
+ const common = buildChildRunResultCommon({
77
+ description: input.description,
78
+ steps: stepCount,
79
+ toolCalls: input.toolCalls,
80
+ toolResults: input.toolResults,
81
+ usage,
82
+ durationMs: Date.now() - input.startTime,
83
+ });
84
+ const snapshot = buildChildRunFailureSnapshot(common, errorMessage, finalText || null);
85
+ await input.onSettled?.(snapshot);
86
+ return buildChildRunFailureResult(common, errorMessage);
87
+ }
88
+ input.writeLog?.(buildHostedChildCompletedLog({
89
+ description: input.description,
90
+ kind: input.kind,
91
+ toolCallsLength: input.toolCalls.length,
92
+ finalText,
93
+ }));
94
+ const common = buildChildRunResultCommon({
95
+ description: input.description,
96
+ steps: stepCount,
97
+ toolCalls: input.toolCalls,
98
+ toolResults: input.toolResults,
99
+ usage,
100
+ durationMs: Date.now() - input.startTime,
101
+ });
102
+ const snapshot = buildChildRunSuccessSnapshot(common, finalText);
103
+ await input.onSettled?.(snapshot);
104
+ return buildChildRunSuccessResult(common, buildChildRunResultSummary(finalText));
105
+ }
106
+ export async function handleHostedChildForkStreamPart(input) {
107
+ let { activeToolCallId, finalText, shouldSeparateNextTextBlock } = input.state;
108
+ const part = input.part;
109
+ if (part.type === "reasoning-delta") {
110
+ if (input.durableReasoningMessageId) {
111
+ if (!input.durableMirrorState.reasoningStarted) {
112
+ input.durableMirrorState.reasoningStarted = true;
113
+ await input.appendDurableMirrorChunk({
114
+ type: "reasoning-start",
115
+ id: input.durableReasoningMessageId,
116
+ });
117
+ }
118
+ await input.appendDurableMirrorChunk({
119
+ type: "reasoning-delta",
120
+ id: input.durableReasoningMessageId,
121
+ delta: part.text,
122
+ });
123
+ }
124
+ return { activeToolCallId, finalText, shouldSeparateNextTextBlock };
125
+ }
126
+ if (part.type === "text-delta") {
127
+ await input.closeDurableMirrorReasoning();
128
+ const nextText = shouldSeparateNextTextBlock && finalText.length > 0
129
+ ? `\n\n${part.text}`
130
+ : part.text;
131
+ finalText += nextText;
132
+ shouldSeparateNextTextBlock = false;
133
+ if (input.durableMessageId) {
134
+ if (!input.durableMirrorState.textStarted) {
135
+ input.durableMirrorState.textStarted = true;
136
+ await input.appendDurableMirrorChunk({
137
+ type: "text-start",
138
+ id: input.durableMessageId,
139
+ });
140
+ }
141
+ await input.appendDurableMirrorChunk({
142
+ type: "text-delta",
143
+ id: input.durableMessageId,
144
+ delta: part.text,
145
+ });
146
+ }
147
+ return { activeToolCallId, finalText, shouldSeparateNextTextBlock };
148
+ }
149
+ if (part.type === "tool-input-start") {
150
+ await input.closeDurableMirrorReasoning();
151
+ await input.closeDurableMirrorText();
152
+ activeToolCallId = part.toolCallId;
153
+ shouldSeparateNextTextBlock = finalText.length > 0;
154
+ await input.pendingToolLifecycle.emitToolInputStartIfNeeded(part.toolCallId, part.toolName);
155
+ input.pendingToolLifecycle.upsertPendingToolCall(part.toolCallId, {
156
+ phase: "input_streaming",
157
+ toolName: part.toolName,
158
+ });
159
+ return { activeToolCallId, finalText, shouldSeparateNextTextBlock };
160
+ }
161
+ if (part.type === "tool-input-delta") {
162
+ input.pendingToolLifecycle.upsertPendingToolCall(part.toolCallId, {
163
+ phase: "input_streaming",
164
+ });
165
+ return { activeToolCallId, finalText, shouldSeparateNextTextBlock };
166
+ }
167
+ if (part.type === "tool-call") {
168
+ await input.closeDurableMirrorReasoning();
169
+ await input.closeDurableMirrorText();
170
+ activeToolCallId = part.toolCallId;
171
+ shouldSeparateNextTextBlock = finalText.length > 0;
172
+ const summarizedInput = summarizeChildRunResultValue(part.input);
173
+ input.toolCalls.push({
174
+ toolName: part.toolName,
175
+ toolCallId: part.toolCallId,
176
+ input: summarizedInput,
177
+ });
178
+ input.logger?.debug?.("Child fork tool call", {
179
+ conversationId: input.conversationId,
180
+ toolCallId: part.toolCallId,
181
+ toolName: part.toolName,
182
+ description: input.description,
183
+ });
184
+ input.pendingToolLifecycle.upsertPendingToolCall(part.toolCallId, {
185
+ phase: "awaiting_result",
186
+ toolName: part.toolName,
187
+ input: summarizedInput,
188
+ });
189
+ await input.pendingToolLifecycle.emitToolInputStartIfNeeded(part.toolCallId, part.toolName);
190
+ await input.appendDurableMirrorChunk({
191
+ type: "tool-input-available",
192
+ toolCallId: part.toolCallId,
193
+ toolName: part.toolName,
194
+ input: toChildRunToolInputRecord(summarizedInput),
195
+ });
196
+ return { activeToolCallId, finalText, shouldSeparateNextTextBlock };
197
+ }
198
+ if (part.type === "tool-result") {
199
+ await input.closeDurableMirrorReasoning();
200
+ await input.closeDurableMirrorText();
201
+ activeToolCallId = null;
202
+ shouldSeparateNextTextBlock = finalText.length > 0;
203
+ const rawOutput = getStructuredContent(part.output);
204
+ const summarizedInput = summarizeChildRunResultValue(part.input);
205
+ const summarizedOutput = summarizeChildRunResultValue(rawOutput);
206
+ input.logger?.debug?.("Child fork tool result", {
207
+ conversationId: input.conversationId,
208
+ toolCallId: part.toolCallId,
209
+ toolName: part.toolName,
210
+ description: input.description,
211
+ });
212
+ input.toolResults.push({
213
+ toolName: part.toolName,
214
+ toolCallId: part.toolCallId,
215
+ input: summarizedInput,
216
+ output: summarizedOutput,
217
+ });
218
+ await input.appendDurableMirrorChunk({
219
+ type: "tool-output-available",
220
+ toolCallId: part.toolCallId,
221
+ output: summarizedOutput,
222
+ });
223
+ input.pendingToolLifecycle.deletePendingToolCall(part.toolCallId);
224
+ return { activeToolCallId, finalText, shouldSeparateNextTextBlock };
225
+ }
226
+ if (part.type === "tool-error") {
227
+ await input.closeDurableMirrorReasoning();
228
+ await input.closeDurableMirrorText();
229
+ shouldSeparateNextTextBlock = finalText.length > 0;
230
+ input.logger?.warn?.("Child fork tool error", {
231
+ conversationId: input.conversationId,
232
+ toolCallId: part.toolCallId,
233
+ toolName: part.toolName,
234
+ description: input.description,
235
+ });
236
+ await input.pendingToolLifecycle.emitToolInputStartIfNeeded(part.toolCallId, part.toolName);
237
+ await input.appendDurableMirrorChunk({
238
+ type: "tool-input-error",
239
+ toolCallId: part.toolCallId,
240
+ toolName: part.toolName,
241
+ input: toChildRunToolInputRecord(part.input),
242
+ errorText: part.error.message,
243
+ });
244
+ input.pendingToolLifecycle.deletePendingToolCall(part.toolCallId);
245
+ activeToolCallId = null;
246
+ return { activeToolCallId, finalText, shouldSeparateNextTextBlock };
247
+ }
248
+ return { activeToolCallId, finalText, shouldSeparateNextTextBlock };
249
+ }
250
+ export async function executeHostedChildForkStream(input) {
251
+ let activeToolCallId = null;
252
+ let finalText = input.streamState.finalText;
253
+ let shouldSeparateNextTextBlock = false;
254
+ let softIdleHeartbeatCount = 0;
255
+ if (input.durableRunMirror) {
256
+ input.markDurableStepStarted();
257
+ await input.appendDurableMirrorChunk({
258
+ type: "start-step",
259
+ });
260
+ }
261
+ let lastWatchdogPhase = null;
262
+ for await (const part of withHostedChildStreamIdleTimeout({
263
+ stream: input.streamResult.fullStream,
264
+ getWatchdogState: () => {
265
+ const state = resolveHostedChildStreamWatchdogState({
266
+ activeToolCallId,
267
+ completedToolResults: input.toolResults.length,
268
+ idleTimeoutMs: input.idleTimeoutMs,
269
+ activeToolTimeoutMs: input.activeToolTimeoutMs,
270
+ postToolIdleTimeoutMs: input.postToolIdleTimeoutMs,
271
+ });
272
+ if (state.phase !== lastWatchdogPhase) {
273
+ input.logger?.debug?.("Fork watchdog phase changed", {
274
+ conversationId: input.conversationId,
275
+ description: input.description,
276
+ phase: state.phase,
277
+ previousPhase: lastWatchdogPhase,
278
+ timeoutMs: state.timeoutMs,
279
+ });
280
+ lastWatchdogPhase = state.phase;
281
+ }
282
+ return state;
283
+ },
284
+ abortSignal: input.abortSignal,
285
+ onIdleTimeout: async (watchdogState) => {
286
+ if (isSoftIdleHeartbeatPhase(watchdogState.phase) &&
287
+ softIdleHeartbeatCount < MAX_SOFT_IDLE_HEARTBEATS) {
288
+ softIdleHeartbeatCount += 1;
289
+ input.logger?.info?.("Fork stream soft-idle heartbeat", {
290
+ conversationId: input.conversationId,
291
+ description: input.description,
292
+ watchdogPhase: watchdogState.phase,
293
+ heartbeatCount: softIdleHeartbeatCount,
294
+ timeoutMs: watchdogState.timeoutMs,
295
+ toolCallsCompleted: input.toolResults.length,
296
+ });
297
+ await input.appendDurableMirrorChunk({
298
+ type: "message-metadata",
299
+ messageMetadata: {
300
+ createdAt: new Date().toISOString(),
301
+ },
302
+ });
303
+ return "continue";
304
+ }
305
+ input.logger?.warn?.("Fork stream idle timeout triggered", {
306
+ conversationId: input.conversationId,
307
+ description: input.description,
308
+ watchdogPhase: watchdogState.phase ?? lastWatchdogPhase,
309
+ softIdleHeartbeatCount,
310
+ timeoutMs: watchdogState.timeoutMs,
311
+ toolCallsCompleted: input.toolResults.length,
312
+ });
313
+ input.abortForkStream(new DOMException("Child fork stream idle timeout", "AbortError"));
314
+ return undefined;
315
+ },
316
+ })) {
317
+ softIdleHeartbeatCount = 0;
318
+ throwIfChildRunAborted(input.abortSignal);
319
+ await input.tracePart?.({
320
+ conversationId: input.conversationId,
321
+ parentRunId: input.parentRunId,
322
+ partType: part.type,
323
+ });
324
+ input.logger?.debug?.("Child fork stream part received", {
325
+ conversationId: input.conversationId,
326
+ runId: input.parentRunId,
327
+ partType: part.type,
328
+ });
329
+ ({ activeToolCallId, finalText, shouldSeparateNextTextBlock } =
330
+ await handleHostedChildForkStreamPart({
331
+ part,
332
+ conversationId: input.conversationId,
333
+ description: input.description,
334
+ durableMessageId: input.durableMessageId,
335
+ durableReasoningMessageId: input.durableReasoningMessageId,
336
+ durableMirrorState: input.durableMirrorState,
337
+ appendDurableMirrorChunk: input.appendDurableMirrorChunk,
338
+ closeDurableMirrorReasoning: input.closeDurableMirrorReasoning,
339
+ closeDurableMirrorText: input.closeDurableMirrorText,
340
+ pendingToolLifecycle: input.pendingToolLifecycle,
341
+ toolCalls: input.toolCalls,
342
+ toolResults: input.toolResults,
343
+ state: {
344
+ activeToolCallId,
345
+ finalText,
346
+ shouldSeparateNextTextBlock,
347
+ },
348
+ logger: input.logger,
349
+ }));
350
+ input.streamState.finalText = finalText;
351
+ if (input.durableRunMirror) {
352
+ const mirroredChunks = mapHostedStreamPartToChatUiChunks(toMirroredHostedStreamPart(part, {
353
+ messageId: input.durableMessageId,
354
+ reasoningMessageId: input.durableReasoningMessageId,
355
+ }), {
356
+ messageId: input.durableMessageId,
357
+ reasoningMessageId: input.durableReasoningMessageId,
358
+ onError: formatChildRunStreamPartError,
359
+ });
360
+ for (const mirroredChunk of mirroredChunks) {
361
+ if (isAlreadyMirroredHostedChunk(part.type, mirroredChunk.type)) {
362
+ continue;
363
+ }
364
+ await input.appendDurableMirrorChunk(mirroredChunk);
365
+ }
366
+ }
367
+ }
368
+ await input.closeDurableMirrorReasoning();
369
+ await input.closeDurableMirrorText();
370
+ await input.pendingToolLifecycle.closePendingToolCalls({ kind: "ended" });
371
+ throwIfChildRunAborted(input.abortSignal);
372
+ input.streamState.finalText = finalText;
373
+ return finalizeHostedChildForkCompletion({
374
+ streamResult: input.streamResult,
375
+ finalText,
376
+ description: input.description,
377
+ kind: input.kind,
378
+ maxSteps: input.maxSteps,
379
+ toolCalls: input.toolCalls,
380
+ toolResults: input.toolResults,
381
+ usage: input.usage,
382
+ startTime: input.startTime,
383
+ durableMessageId: input.durableMessageId,
384
+ durableMirrorHasEmittedProgress: input.durableMirrorHasEmittedProgress(),
385
+ appendDurableMirrorChunk: input.appendDurableMirrorChunk,
386
+ finalizationTimeoutMs: input.finalizationTimeoutMs,
387
+ onSettled: input.onSettled,
388
+ logger: input.logger,
389
+ writeLog: input.writeLog,
390
+ });
391
+ }