veryfront 0.1.703 → 0.1.704
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 +1 -1
- package/esm/src/agent/streaming/fork-runtime-step-state.d.ts +36 -0
- package/esm/src/agent/streaming/fork-runtime-step-state.d.ts.map +1 -0
- package/esm/src/agent/streaming/fork-runtime-step-state.js +240 -0
- package/esm/src/agent/streaming/fork-runtime-stream.d.ts +2 -31
- package/esm/src/agent/streaming/fork-runtime-stream.d.ts.map +1 -1
- package/esm/src/agent/streaming/fork-runtime-stream.js +4 -239
- package/esm/src/internal-agents/run-stream.d.ts.map +1 -1
- package/esm/src/internal-agents/run-stream.js +3 -0
- package/esm/src/tool/types.d.ts +2 -0
- package/esm/src/tool/types.d.ts.map +1 -1
- package/esm/src/utils/version-constant.d.ts +1 -1
- package/esm/src/utils/version-constant.js +1 -1
- package/package.json +1 -1
package/esm/deno.js
CHANGED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { AgentResponse, Message as AgentMessage } from "../schemas/index.js";
|
|
2
|
+
import type { ForkPart } from "./fork-runtime-stream.js";
|
|
3
|
+
type StreamedToolCallState = {
|
|
4
|
+
toolCallId: string;
|
|
5
|
+
toolName: string;
|
|
6
|
+
inputText: string;
|
|
7
|
+
input: unknown;
|
|
8
|
+
status: "pending" | "completed" | "error";
|
|
9
|
+
output?: unknown;
|
|
10
|
+
errorText?: string;
|
|
11
|
+
};
|
|
12
|
+
type StreamedMessage = {
|
|
13
|
+
role: "assistant" | "tool";
|
|
14
|
+
parts: AgentMessage["parts"];
|
|
15
|
+
};
|
|
16
|
+
export type StreamedStepState = {
|
|
17
|
+
text: string;
|
|
18
|
+
toolCalls: Map<string, StreamedToolCallState>;
|
|
19
|
+
messages: StreamedMessage[];
|
|
20
|
+
streamError?: Error;
|
|
21
|
+
};
|
|
22
|
+
export declare function createAgentRuntimeForkAbortError(abortSignal?: AbortSignal): Error;
|
|
23
|
+
/** State for create streamed step. */
|
|
24
|
+
export declare function createStreamedStepState(): StreamedStepState;
|
|
25
|
+
/** State for apply part to streamed step. */
|
|
26
|
+
export declare function applyPartToStreamedStepState(state: StreamedStepState, part: ForkPart): void;
|
|
27
|
+
/** Response payload for resolve fork step. */
|
|
28
|
+
export declare function resolveForkStepResponse(input: {
|
|
29
|
+
responsePromise: Promise<AgentResponse>;
|
|
30
|
+
responseTimeoutMs: number;
|
|
31
|
+
abortSignal?: AbortSignal;
|
|
32
|
+
currentMessages: readonly AgentMessage[];
|
|
33
|
+
streamedStepState: StreamedStepState;
|
|
34
|
+
}): Promise<AgentResponse>;
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=fork-runtime-step-state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fork-runtime-step-state.d.ts","sourceRoot":"","sources":["../../../../src/src/agent/streaming/fork-runtime-step-state.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAOlF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEzD,KAAK,qBAAqB,GAAG;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,SAAS,GAAG,WAAW,GAAG,OAAO,CAAC;IAC1C,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,KAAK,eAAe,GAAG;IACrB,IAAI,EAAE,WAAW,GAAG,MAAM,CAAC;IAC3B,KAAK,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC;IAC9C,QAAQ,EAAE,eAAe,EAAE,CAAC;IAC5B,WAAW,CAAC,EAAE,KAAK,CAAC;CACrB,CAAC;AAEF,wBAAgB,gCAAgC,CAAC,WAAW,CAAC,EAAE,WAAW,GAAG,KAAK,CAMjF;AAED,sCAAsC;AACtC,wBAAgB,uBAAuB,IAAI,iBAAiB,CAM3D;AAyBD,6CAA6C;AAC7C,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,iBAAiB,EAAE,IAAI,EAAE,QAAQ,QAsGpF;AAyGD,8CAA8C;AAC9C,wBAAsB,uBAAuB,CAAC,KAAK,EAAE;IACnD,eAAe,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;IACxC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,eAAe,EAAE,SAAS,YAAY,EAAE,CAAC;IACzC,iBAAiB,EAAE,iBAAiB,CAAC;CACtC,GAAG,OAAO,CAAC,aAAa,CAAC,CAgCzB"}
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import * as dntShim from "../../../_dnt.shims.js";
|
|
2
|
+
import { isRecord } from "../../chat/conversation.js";
|
|
3
|
+
import { HOSTED_CHILD_STREAM_TIMEOUT_TOKEN, resolveHostedChildPromiseWithTimeout, } from "../hosted/child-stream-watchdog.js";
|
|
4
|
+
import { mergeToolInputDelta, parseToolInputObject } from "./data-stream.js";
|
|
5
|
+
import { getParsedStreamedToolInput } from "./fork-runtime-part-mapper.js";
|
|
6
|
+
export function createAgentRuntimeForkAbortError(abortSignal) {
|
|
7
|
+
if (abortSignal?.reason instanceof Error) {
|
|
8
|
+
return abortSignal.reason;
|
|
9
|
+
}
|
|
10
|
+
return new DOMException("Agent runtime fork aborted before completion.", "AbortError");
|
|
11
|
+
}
|
|
12
|
+
/** State for create streamed step. */
|
|
13
|
+
export function createStreamedStepState() {
|
|
14
|
+
return {
|
|
15
|
+
text: "",
|
|
16
|
+
toolCalls: new Map(),
|
|
17
|
+
messages: [],
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function appendStreamedMessagePart(state, role, part) {
|
|
21
|
+
const lastMessage = state.messages.at(-1);
|
|
22
|
+
if (lastMessage?.role === role) {
|
|
23
|
+
lastMessage.parts.push(part);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
state.messages.push({
|
|
27
|
+
role,
|
|
28
|
+
parts: [part],
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
function isFrameworkTextPart(part) {
|
|
32
|
+
return part.type === "text";
|
|
33
|
+
}
|
|
34
|
+
/** State for apply part to streamed step. */
|
|
35
|
+
export function applyPartToStreamedStepState(state, part) {
|
|
36
|
+
switch (part.type) {
|
|
37
|
+
case "tool-input-start": {
|
|
38
|
+
const existing = state.toolCalls.get(part.toolCallId);
|
|
39
|
+
state.toolCalls.set(part.toolCallId, {
|
|
40
|
+
toolCallId: part.toolCallId,
|
|
41
|
+
toolName: part.toolName,
|
|
42
|
+
inputText: existing?.inputText ?? "",
|
|
43
|
+
input: existing?.input ?? {},
|
|
44
|
+
status: existing?.status ?? "pending",
|
|
45
|
+
...(existing?.output !== undefined ? { output: existing.output } : {}),
|
|
46
|
+
...(existing?.errorText ? { errorText: existing.errorText } : {}),
|
|
47
|
+
});
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
case "text-delta": {
|
|
51
|
+
state.text += part.text;
|
|
52
|
+
const lastAssistantMessage = state.messages.at(-1);
|
|
53
|
+
const lastAssistantPart = lastAssistantMessage?.role === "assistant"
|
|
54
|
+
? lastAssistantMessage.parts.at(-1)
|
|
55
|
+
: null;
|
|
56
|
+
if (lastAssistantMessage && lastAssistantPart && isFrameworkTextPart(lastAssistantPart)) {
|
|
57
|
+
lastAssistantPart.text += part.text;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
appendStreamedMessagePart(state, "assistant", {
|
|
61
|
+
type: "text",
|
|
62
|
+
text: part.text,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
case "tool-input-delta": {
|
|
68
|
+
const existing = state.toolCalls.get(part.toolCallId);
|
|
69
|
+
if (!existing) {
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
existing.inputText = mergeToolInputDelta(existing.inputText, part.delta);
|
|
73
|
+
const parsedInput = getParsedStreamedToolInput(existing.inputText);
|
|
74
|
+
if (parsedInput) {
|
|
75
|
+
existing.input = parsedInput;
|
|
76
|
+
}
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
case "tool-call": {
|
|
80
|
+
const existing = state.toolCalls.get(part.toolCallId);
|
|
81
|
+
state.toolCalls.set(part.toolCallId, {
|
|
82
|
+
toolCallId: part.toolCallId,
|
|
83
|
+
toolName: part.toolName,
|
|
84
|
+
input: part.input,
|
|
85
|
+
inputText: existing?.inputText ?? "",
|
|
86
|
+
status: "pending",
|
|
87
|
+
...(existing?.output !== undefined ? { output: existing.output } : {}),
|
|
88
|
+
...(existing?.errorText ? { errorText: existing.errorText } : {}),
|
|
89
|
+
});
|
|
90
|
+
appendStreamedMessagePart(state, "assistant", {
|
|
91
|
+
type: `tool-${part.toolName}`,
|
|
92
|
+
toolCallId: part.toolCallId,
|
|
93
|
+
toolName: part.toolName,
|
|
94
|
+
args: parseToolInputObject(part.input),
|
|
95
|
+
});
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
case "tool-result": {
|
|
99
|
+
const existing = state.toolCalls.get(part.toolCallId);
|
|
100
|
+
state.toolCalls.set(part.toolCallId, {
|
|
101
|
+
toolCallId: part.toolCallId,
|
|
102
|
+
toolName: part.toolName,
|
|
103
|
+
input: part.input,
|
|
104
|
+
inputText: existing?.inputText ?? "",
|
|
105
|
+
status: "completed",
|
|
106
|
+
output: part.output,
|
|
107
|
+
...(existing?.errorText ? { errorText: existing.errorText } : {}),
|
|
108
|
+
});
|
|
109
|
+
appendStreamedMessagePart(state, "tool", {
|
|
110
|
+
type: "tool-result",
|
|
111
|
+
toolCallId: part.toolCallId,
|
|
112
|
+
toolName: part.toolName,
|
|
113
|
+
result: part.output,
|
|
114
|
+
});
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
case "tool-error": {
|
|
118
|
+
const existing = state.toolCalls.get(part.toolCallId);
|
|
119
|
+
state.toolCalls.set(part.toolCallId, {
|
|
120
|
+
toolCallId: part.toolCallId,
|
|
121
|
+
toolName: part.toolName,
|
|
122
|
+
input: part.input,
|
|
123
|
+
inputText: existing?.inputText ?? "",
|
|
124
|
+
status: "error",
|
|
125
|
+
...(existing?.output !== undefined ? { output: existing.output } : {}),
|
|
126
|
+
errorText: part.error.message,
|
|
127
|
+
});
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
case "error": {
|
|
131
|
+
state.streamError = part.error;
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
default:
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function buildFallbackAgentRuntimeMessages(baseMessages, state) {
|
|
139
|
+
const messages = baseMessages.map((message) => ({
|
|
140
|
+
...message,
|
|
141
|
+
parts: [...message.parts],
|
|
142
|
+
}));
|
|
143
|
+
if (state.messages.length > 0) {
|
|
144
|
+
messages.push(...state.messages.map((message) => ({
|
|
145
|
+
id: dntShim.crypto.randomUUID(),
|
|
146
|
+
role: message.role,
|
|
147
|
+
timestamp: Date.now(),
|
|
148
|
+
parts: structuredClone(message.parts),
|
|
149
|
+
})));
|
|
150
|
+
}
|
|
151
|
+
else if (state.text.trim().length > 0) {
|
|
152
|
+
messages.push({
|
|
153
|
+
id: dntShim.crypto.randomUUID(),
|
|
154
|
+
role: "assistant",
|
|
155
|
+
timestamp: Date.now(),
|
|
156
|
+
parts: [{ type: "text", text: state.text }],
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
return messages;
|
|
160
|
+
}
|
|
161
|
+
function collectToolResultPaths(messages) {
|
|
162
|
+
const paths = new Set();
|
|
163
|
+
for (const message of messages) {
|
|
164
|
+
for (const part of message.parts) {
|
|
165
|
+
if (part.type !== "tool-result") {
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
const partResult = "result" in part ? part.result : null;
|
|
169
|
+
const result = isRecord(partResult) ? partResult : null;
|
|
170
|
+
const path = typeof result?.path === "string" ? result.path : null;
|
|
171
|
+
if (path) {
|
|
172
|
+
paths.add(path);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return [...paths];
|
|
177
|
+
}
|
|
178
|
+
function buildRecoverablePriorWorkState(messages) {
|
|
179
|
+
const paths = collectToolResultPaths(messages);
|
|
180
|
+
if (paths.length === 0) {
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
const previewPaths = paths.slice(0, 8);
|
|
184
|
+
const suffix = paths.length > previewPaths.length
|
|
185
|
+
? ` and ${paths.length - previewPaths.length} more`
|
|
186
|
+
: "";
|
|
187
|
+
const text = `Completed child tool work. Project artifact(s): ${previewPaths.join(", ")}${suffix}.`;
|
|
188
|
+
return {
|
|
189
|
+
text,
|
|
190
|
+
toolCalls: new Map(),
|
|
191
|
+
messages: [
|
|
192
|
+
{
|
|
193
|
+
role: "assistant",
|
|
194
|
+
parts: [{ type: "text", text }],
|
|
195
|
+
},
|
|
196
|
+
],
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
function hasFallbackStepContent(state) {
|
|
200
|
+
return state.text.trim().length > 0 || state.toolCalls.size > 0;
|
|
201
|
+
}
|
|
202
|
+
function buildFallbackAgentResponse(input) {
|
|
203
|
+
return {
|
|
204
|
+
text: input.state.text,
|
|
205
|
+
messages: buildFallbackAgentRuntimeMessages(input.baseMessages, input.state),
|
|
206
|
+
toolCalls: [...input.state.toolCalls.values()].map((toolCall) => ({
|
|
207
|
+
id: toolCall.toolCallId,
|
|
208
|
+
name: toolCall.toolName,
|
|
209
|
+
args: parseToolInputObject(toolCall.input),
|
|
210
|
+
status: toolCall.status,
|
|
211
|
+
...(toolCall.status === "completed" ? { result: toolCall.output } : {}),
|
|
212
|
+
...(toolCall.status === "error" && toolCall.errorText ? { error: toolCall.errorText } : {}),
|
|
213
|
+
})),
|
|
214
|
+
metadata: {},
|
|
215
|
+
status: "completed",
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
/** Response payload for resolve fork step. */
|
|
219
|
+
export async function resolveForkStepResponse(input) {
|
|
220
|
+
const resolvedResponse = await resolveHostedChildPromiseWithTimeout(input.responsePromise, input.responseTimeoutMs);
|
|
221
|
+
if (resolvedResponse !== HOSTED_CHILD_STREAM_TIMEOUT_TOKEN) {
|
|
222
|
+
return resolvedResponse;
|
|
223
|
+
}
|
|
224
|
+
if (input.abortSignal?.aborted) {
|
|
225
|
+
throw createAgentRuntimeForkAbortError(input.abortSignal);
|
|
226
|
+
}
|
|
227
|
+
if (input.streamedStepState.streamError) {
|
|
228
|
+
throw input.streamedStepState.streamError;
|
|
229
|
+
}
|
|
230
|
+
const fallbackState = hasFallbackStepContent(input.streamedStepState)
|
|
231
|
+
? input.streamedStepState
|
|
232
|
+
: buildRecoverablePriorWorkState(input.currentMessages);
|
|
233
|
+
if (!fallbackState) {
|
|
234
|
+
throw new Error("Agent runtime fork stream ended without onFinish and without recoverable output.");
|
|
235
|
+
}
|
|
236
|
+
return buildFallbackAgentResponse({
|
|
237
|
+
baseMessages: input.currentMessages,
|
|
238
|
+
state: fallbackState,
|
|
239
|
+
});
|
|
240
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { type HostToolSet, type HostToolTraceAttributes, type Tool, type TraceHostToolsOptions } from "../../tool/index.js";
|
|
2
2
|
import type { AgentResponse, Message as AgentMessage } from "../schemas/index.js";
|
|
3
3
|
export { buildRecoveredStepParts, createForkRuntimeStreamMappingState, createFrameworkStreamState, mapAgUiRuntimeEventToForkParts, mapFrameworkEventToForkParts, } from "./fork-runtime-part-mapper.js";
|
|
4
|
+
export { applyPartToStreamedStepState, createStreamedStepState, resolveForkStepResponse, } from "./fork-runtime-step-state.js";
|
|
4
5
|
export type { ForkRecoveredPartsState, ForkRuntimeStreamMappingState, FrameworkStreamState, RecoveredToolObservation, } from "./fork-runtime-part-mapper.js";
|
|
6
|
+
export type { StreamedStepState } from "./fork-runtime-step-state.js";
|
|
5
7
|
interface ForkStreamPart {
|
|
6
8
|
type: "reasoning-delta" | "text-delta";
|
|
7
9
|
text: string;
|
|
@@ -57,25 +59,6 @@ export interface ForkRuntimeStep {
|
|
|
57
59
|
}>;
|
|
58
60
|
finishReason: string | null;
|
|
59
61
|
}
|
|
60
|
-
type StreamedToolCallState = {
|
|
61
|
-
toolCallId: string;
|
|
62
|
-
toolName: string;
|
|
63
|
-
inputText: string;
|
|
64
|
-
input: unknown;
|
|
65
|
-
status: "pending" | "completed" | "error";
|
|
66
|
-
output?: unknown;
|
|
67
|
-
errorText?: string;
|
|
68
|
-
};
|
|
69
|
-
type StreamedMessage = {
|
|
70
|
-
role: "assistant" | "tool";
|
|
71
|
-
parts: AgentMessage["parts"];
|
|
72
|
-
};
|
|
73
|
-
type StreamedStepState = {
|
|
74
|
-
text: string;
|
|
75
|
-
toolCalls: Map<string, StreamedToolCallState>;
|
|
76
|
-
messages: StreamedMessage[];
|
|
77
|
-
streamError?: Error;
|
|
78
|
-
};
|
|
79
62
|
/** Public API contract for fork part. */
|
|
80
63
|
export type ForkPart = ForkStreamPart | ForkToolInputStartPart | ForkToolInputDeltaPart | ForkToolCallPart | ForkToolResultPart | ForkToolErrorPart | ForkErrorPart;
|
|
81
64
|
/** Public API contract for fork runtime stream logger. */
|
|
@@ -212,16 +195,4 @@ export declare function resolveForkRuntimeContinuationState(input: {
|
|
|
212
195
|
} | null>;
|
|
213
196
|
/** Starts agent runtime fork. */
|
|
214
197
|
export declare function startAgentRuntimeFork(input: StartAgentRuntimeForkInput): ForkRuntimeStreamResult;
|
|
215
|
-
/** State for create streamed step. */
|
|
216
|
-
export declare function createStreamedStepState(): StreamedStepState;
|
|
217
|
-
/** State for apply part to streamed step. */
|
|
218
|
-
export declare function applyPartToStreamedStepState(state: StreamedStepState, part: ForkPart): void;
|
|
219
|
-
/** Response payload for resolve fork step. */
|
|
220
|
-
export declare function resolveForkStepResponse(input: {
|
|
221
|
-
responsePromise: Promise<AgentResponse>;
|
|
222
|
-
responseTimeoutMs: number;
|
|
223
|
-
abortSignal?: AbortSignal;
|
|
224
|
-
currentMessages: readonly AgentMessage[];
|
|
225
|
-
streamedStepState: StreamedStepState;
|
|
226
|
-
}): Promise<AgentResponse>;
|
|
227
198
|
//# sourceMappingURL=fork-runtime-stream.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fork-runtime-stream.d.ts","sourceRoot":"","sources":["../../../../src/src/agent/streaming/fork-runtime-stream.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,uBAAuB,EAC5B,KAAK,IAAI,EAET,KAAK,qBAAqB,EAC3B,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"fork-runtime-stream.d.ts","sourceRoot":"","sources":["../../../../src/src/agent/streaming/fork-runtime-stream.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,uBAAuB,EAC5B,KAAK,IAAI,EAET,KAAK,qBAAqB,EAC3B,MAAM,qBAAqB,CAAC;AAmB7B,OAAO,KAAK,EAAE,aAAa,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAElF,OAAO,EACL,uBAAuB,EACvB,mCAAmC,EACnC,0BAA0B,EAC1B,8BAA8B,EAC9B,4BAA4B,GAC7B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,4BAA4B,EAC5B,uBAAuB,EACvB,uBAAuB,GACxB,MAAM,8BAA8B,CAAC;AACtC,YAAY,EACV,uBAAuB,EACvB,6BAA6B,EAC7B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AAmC,CAAC,KAAK,EAAE;IAC/D,0BAA0B,EAAE,MAAM,CAAC;IACnC,YAAY,CAAC,EAAE,qCAAqC,CAAC;IACrD,IAAI,EAAE,eAAe,CAAC;IACtB,eAAe,EAAE,YAAY,EAAE,CAAC;IAChC,SAAS,EAAE,MAAM,CAAC;CACnB,GAAG,OAAO,CAAC;IAAE,0BAA0B,EAAE,MAAM,CAAC;IAAC,eAAe,EAAE,YAAY,EAAE,CAAA;CAAE,GAAG,IAAI,CAAC,CAoB1F;AAED,iCAAiC;AACjC,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,0BAA0B,GAAG,uBAAuB,CA2GhG"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import * as dntShim from "../../../_dnt.shims.js";
|
|
2
2
|
import { createToolsFromHostDefinitions, traceHostTools, } from "../../tool/index.js";
|
|
3
|
-
import { isRecord } from "../../chat/conversation.js";
|
|
4
3
|
import { runWithVeryfrontCloudContextAsync } from "../../provider/veryfront-cloud/context.js";
|
|
5
|
-
import {
|
|
6
|
-
import { buildRecoveredStepParts, createForkRuntimeStreamMappingState,
|
|
7
|
-
import {
|
|
4
|
+
import { streamDataStreamEvents } from "./data-stream.js";
|
|
5
|
+
import { buildRecoveredStepParts, createForkRuntimeStreamMappingState, mapAgUiRuntimeEventToForkParts, } from "./fork-runtime-part-mapper.js";
|
|
6
|
+
import { applyPartToStreamedStepState, createAgentRuntimeForkAbortError, createStreamedStepState, resolveForkStepResponse, } from "./fork-runtime-step-state.js";
|
|
8
7
|
import { getForkRuntimeAllowedToolNames, getProviderNativeToolNames, } from "../runtime/provider-native-tool-inventory.js";
|
|
9
8
|
import { AgentRuntime } from "../runtime/index.js";
|
|
10
9
|
export { buildRecoveredStepParts, createForkRuntimeStreamMappingState, createFrameworkStreamState, mapAgUiRuntimeEventToForkParts, mapFrameworkEventToForkParts, } from "./fork-runtime-part-mapper.js";
|
|
10
|
+
export { applyPartToStreamedStepState, createStreamedStepState, resolveForkStepResponse, } from "./fork-runtime-step-state.js";
|
|
11
11
|
/** Default value for fork response promise timeout ms. */
|
|
12
12
|
export const DEFAULT_FORK_RESPONSE_PROMISE_TIMEOUT_MS = 1_000;
|
|
13
13
|
/** Starts agent runtime fork with host tools. */
|
|
@@ -79,12 +79,6 @@ async function prepareForkRuntimeStep(input) {
|
|
|
79
79
|
system: input.buildInstructions(),
|
|
80
80
|
};
|
|
81
81
|
}
|
|
82
|
-
function createAgentRuntimeForkAbortError(abortSignal) {
|
|
83
|
-
if (abortSignal?.reason instanceof Error) {
|
|
84
|
-
return abortSignal.reason;
|
|
85
|
-
}
|
|
86
|
-
return new DOMException("Agent runtime fork aborted before completion.", "AbortError");
|
|
87
|
-
}
|
|
88
82
|
/** Run agent runtime fork step. */
|
|
89
83
|
export async function runAgentRuntimeForkStep(input) {
|
|
90
84
|
let resolveResponsePromise;
|
|
@@ -319,232 +313,3 @@ export function startAgentRuntimeFork(input) {
|
|
|
319
313
|
totalUsage: totalUsageDeferred.promise,
|
|
320
314
|
};
|
|
321
315
|
}
|
|
322
|
-
/** State for create streamed step. */
|
|
323
|
-
export function createStreamedStepState() {
|
|
324
|
-
return {
|
|
325
|
-
text: "",
|
|
326
|
-
toolCalls: new Map(),
|
|
327
|
-
messages: [],
|
|
328
|
-
};
|
|
329
|
-
}
|
|
330
|
-
function appendStreamedMessagePart(state, role, part) {
|
|
331
|
-
const lastMessage = state.messages.at(-1);
|
|
332
|
-
if (lastMessage?.role === role) {
|
|
333
|
-
lastMessage.parts.push(part);
|
|
334
|
-
return;
|
|
335
|
-
}
|
|
336
|
-
state.messages.push({
|
|
337
|
-
role,
|
|
338
|
-
parts: [part],
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
|
-
function isFrameworkTextPart(part) {
|
|
342
|
-
return part.type === "text";
|
|
343
|
-
}
|
|
344
|
-
/** State for apply part to streamed step. */
|
|
345
|
-
export function applyPartToStreamedStepState(state, part) {
|
|
346
|
-
switch (part.type) {
|
|
347
|
-
case "tool-input-start": {
|
|
348
|
-
const existing = state.toolCalls.get(part.toolCallId);
|
|
349
|
-
state.toolCalls.set(part.toolCallId, {
|
|
350
|
-
toolCallId: part.toolCallId,
|
|
351
|
-
toolName: part.toolName,
|
|
352
|
-
inputText: existing?.inputText ?? "",
|
|
353
|
-
input: existing?.input ?? {},
|
|
354
|
-
status: existing?.status ?? "pending",
|
|
355
|
-
...(existing?.output !== undefined ? { output: existing.output } : {}),
|
|
356
|
-
...(existing?.errorText ? { errorText: existing.errorText } : {}),
|
|
357
|
-
});
|
|
358
|
-
break;
|
|
359
|
-
}
|
|
360
|
-
case "text-delta": {
|
|
361
|
-
state.text += part.text;
|
|
362
|
-
const lastAssistantMessage = state.messages.at(-1);
|
|
363
|
-
const lastAssistantPart = lastAssistantMessage?.role === "assistant"
|
|
364
|
-
? lastAssistantMessage.parts.at(-1)
|
|
365
|
-
: null;
|
|
366
|
-
if (lastAssistantMessage && lastAssistantPart && isFrameworkTextPart(lastAssistantPart)) {
|
|
367
|
-
lastAssistantPart.text += part.text;
|
|
368
|
-
}
|
|
369
|
-
else {
|
|
370
|
-
appendStreamedMessagePart(state, "assistant", {
|
|
371
|
-
type: "text",
|
|
372
|
-
text: part.text,
|
|
373
|
-
});
|
|
374
|
-
}
|
|
375
|
-
break;
|
|
376
|
-
}
|
|
377
|
-
case "tool-input-delta": {
|
|
378
|
-
const existing = state.toolCalls.get(part.toolCallId);
|
|
379
|
-
if (!existing) {
|
|
380
|
-
break;
|
|
381
|
-
}
|
|
382
|
-
existing.inputText = mergeToolInputDelta(existing.inputText, part.delta);
|
|
383
|
-
const parsedInput = getParsedStreamedToolInput(existing.inputText);
|
|
384
|
-
if (parsedInput) {
|
|
385
|
-
existing.input = parsedInput;
|
|
386
|
-
}
|
|
387
|
-
break;
|
|
388
|
-
}
|
|
389
|
-
case "tool-call": {
|
|
390
|
-
const existing = state.toolCalls.get(part.toolCallId);
|
|
391
|
-
state.toolCalls.set(part.toolCallId, {
|
|
392
|
-
toolCallId: part.toolCallId,
|
|
393
|
-
toolName: part.toolName,
|
|
394
|
-
input: part.input,
|
|
395
|
-
inputText: existing?.inputText ?? "",
|
|
396
|
-
status: "pending",
|
|
397
|
-
...(existing?.output !== undefined ? { output: existing.output } : {}),
|
|
398
|
-
...(existing?.errorText ? { errorText: existing.errorText } : {}),
|
|
399
|
-
});
|
|
400
|
-
appendStreamedMessagePart(state, "assistant", {
|
|
401
|
-
type: `tool-${part.toolName}`,
|
|
402
|
-
toolCallId: part.toolCallId,
|
|
403
|
-
toolName: part.toolName,
|
|
404
|
-
args: parseToolInputObject(part.input),
|
|
405
|
-
});
|
|
406
|
-
break;
|
|
407
|
-
}
|
|
408
|
-
case "tool-result": {
|
|
409
|
-
const existing = state.toolCalls.get(part.toolCallId);
|
|
410
|
-
state.toolCalls.set(part.toolCallId, {
|
|
411
|
-
toolCallId: part.toolCallId,
|
|
412
|
-
toolName: part.toolName,
|
|
413
|
-
input: part.input,
|
|
414
|
-
inputText: existing?.inputText ?? "",
|
|
415
|
-
status: "completed",
|
|
416
|
-
output: part.output,
|
|
417
|
-
...(existing?.errorText ? { errorText: existing.errorText } : {}),
|
|
418
|
-
});
|
|
419
|
-
appendStreamedMessagePart(state, "tool", {
|
|
420
|
-
type: "tool-result",
|
|
421
|
-
toolCallId: part.toolCallId,
|
|
422
|
-
toolName: part.toolName,
|
|
423
|
-
result: part.output,
|
|
424
|
-
});
|
|
425
|
-
break;
|
|
426
|
-
}
|
|
427
|
-
case "tool-error": {
|
|
428
|
-
const existing = state.toolCalls.get(part.toolCallId);
|
|
429
|
-
state.toolCalls.set(part.toolCallId, {
|
|
430
|
-
toolCallId: part.toolCallId,
|
|
431
|
-
toolName: part.toolName,
|
|
432
|
-
input: part.input,
|
|
433
|
-
inputText: existing?.inputText ?? "",
|
|
434
|
-
status: "error",
|
|
435
|
-
...(existing?.output !== undefined ? { output: existing.output } : {}),
|
|
436
|
-
errorText: part.error.message,
|
|
437
|
-
});
|
|
438
|
-
break;
|
|
439
|
-
}
|
|
440
|
-
case "error": {
|
|
441
|
-
state.streamError = part.error;
|
|
442
|
-
break;
|
|
443
|
-
}
|
|
444
|
-
default:
|
|
445
|
-
break;
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
function buildFallbackAgentRuntimeMessages(baseMessages, state) {
|
|
449
|
-
const messages = baseMessages.map((message) => ({
|
|
450
|
-
...message,
|
|
451
|
-
parts: [...message.parts],
|
|
452
|
-
}));
|
|
453
|
-
if (state.messages.length > 0) {
|
|
454
|
-
messages.push(...state.messages.map((message) => ({
|
|
455
|
-
id: dntShim.crypto.randomUUID(),
|
|
456
|
-
role: message.role,
|
|
457
|
-
timestamp: Date.now(),
|
|
458
|
-
parts: structuredClone(message.parts),
|
|
459
|
-
})));
|
|
460
|
-
}
|
|
461
|
-
else if (state.text.trim().length > 0) {
|
|
462
|
-
messages.push({
|
|
463
|
-
id: dntShim.crypto.randomUUID(),
|
|
464
|
-
role: "assistant",
|
|
465
|
-
timestamp: Date.now(),
|
|
466
|
-
parts: [{ type: "text", text: state.text }],
|
|
467
|
-
});
|
|
468
|
-
}
|
|
469
|
-
return messages;
|
|
470
|
-
}
|
|
471
|
-
function collectToolResultPaths(messages) {
|
|
472
|
-
const paths = new Set();
|
|
473
|
-
for (const message of messages) {
|
|
474
|
-
for (const part of message.parts) {
|
|
475
|
-
if (part.type !== "tool-result") {
|
|
476
|
-
continue;
|
|
477
|
-
}
|
|
478
|
-
const partResult = "result" in part ? part.result : null;
|
|
479
|
-
const result = isRecord(partResult) ? partResult : null;
|
|
480
|
-
const path = typeof result?.path === "string" ? result.path : null;
|
|
481
|
-
if (path) {
|
|
482
|
-
paths.add(path);
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
return [...paths];
|
|
487
|
-
}
|
|
488
|
-
function buildRecoverablePriorWorkState(messages) {
|
|
489
|
-
const paths = collectToolResultPaths(messages);
|
|
490
|
-
if (paths.length === 0) {
|
|
491
|
-
return null;
|
|
492
|
-
}
|
|
493
|
-
const previewPaths = paths.slice(0, 8);
|
|
494
|
-
const suffix = paths.length > previewPaths.length
|
|
495
|
-
? ` and ${paths.length - previewPaths.length} more`
|
|
496
|
-
: "";
|
|
497
|
-
const text = `Completed child tool work. Project artifact(s): ${previewPaths.join(", ")}${suffix}.`;
|
|
498
|
-
return {
|
|
499
|
-
text,
|
|
500
|
-
toolCalls: new Map(),
|
|
501
|
-
messages: [
|
|
502
|
-
{
|
|
503
|
-
role: "assistant",
|
|
504
|
-
parts: [{ type: "text", text }],
|
|
505
|
-
},
|
|
506
|
-
],
|
|
507
|
-
};
|
|
508
|
-
}
|
|
509
|
-
function hasFallbackStepContent(state) {
|
|
510
|
-
return state.text.trim().length > 0 || state.toolCalls.size > 0;
|
|
511
|
-
}
|
|
512
|
-
function buildFallbackAgentResponse(input) {
|
|
513
|
-
return {
|
|
514
|
-
text: input.state.text,
|
|
515
|
-
messages: buildFallbackAgentRuntimeMessages(input.baseMessages, input.state),
|
|
516
|
-
toolCalls: [...input.state.toolCalls.values()].map((toolCall) => ({
|
|
517
|
-
id: toolCall.toolCallId,
|
|
518
|
-
name: toolCall.toolName,
|
|
519
|
-
args: parseToolInputObject(toolCall.input),
|
|
520
|
-
status: toolCall.status,
|
|
521
|
-
...(toolCall.status === "completed" ? { result: toolCall.output } : {}),
|
|
522
|
-
...(toolCall.status === "error" && toolCall.errorText ? { error: toolCall.errorText } : {}),
|
|
523
|
-
})),
|
|
524
|
-
metadata: {},
|
|
525
|
-
status: "completed",
|
|
526
|
-
};
|
|
527
|
-
}
|
|
528
|
-
/** Response payload for resolve fork step. */
|
|
529
|
-
export async function resolveForkStepResponse(input) {
|
|
530
|
-
const resolvedResponse = await resolveHostedChildPromiseWithTimeout(input.responsePromise, input.responseTimeoutMs);
|
|
531
|
-
if (resolvedResponse !== HOSTED_CHILD_STREAM_TIMEOUT_TOKEN) {
|
|
532
|
-
return resolvedResponse;
|
|
533
|
-
}
|
|
534
|
-
if (input.abortSignal?.aborted) {
|
|
535
|
-
throw createAgentRuntimeForkAbortError(input.abortSignal);
|
|
536
|
-
}
|
|
537
|
-
if (input.streamedStepState.streamError) {
|
|
538
|
-
throw input.streamedStepState.streamError;
|
|
539
|
-
}
|
|
540
|
-
const fallbackState = hasFallbackStepContent(input.streamedStepState)
|
|
541
|
-
? input.streamedStepState
|
|
542
|
-
: buildRecoverablePriorWorkState(input.currentMessages);
|
|
543
|
-
if (!fallbackState) {
|
|
544
|
-
throw new Error("Agent runtime fork stream ended without onFinish and without recoverable output.");
|
|
545
|
-
}
|
|
546
|
-
return buildFallbackAgentResponse({
|
|
547
|
-
baseMessages: input.currentMessages,
|
|
548
|
-
state: fallbackState,
|
|
549
|
-
});
|
|
550
|
-
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-stream.d.ts","sourceRoot":"","sources":["../../../src/src/internal-agents/run-stream.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,KAAK,EACV,KAAK,YAAY,IAAI,OAAO,EAC5B,KAAK,aAAa,EAEnB,MAAM,mBAAmB,CAAC;AAQ3B,OAAO,KAAK,EACV,+BAA+B,EAC/B,8BAA8B,EAC/B,MAAM,qBAAqB,CAAC;AAkB7B,OAAO,EAA0B,KAAK,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC3F,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAkCxD,MAAM,WAAW,+BAA+B;IAC9C,cAAc,EAAE,sBAAsB,CAAC;IACvC,mBAAmB,CAAC,EAAE;QACpB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QAC1B,eAAe,CAAC,EAAE,MAAM,CAAC;KAC1B,CAAC;IACF,cAAc,CAAC,EAAE,+BAA+B,CAAC,gBAAgB,CAAC,CAAC;IACnE,8BAA8B,CAAC,EAAE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M,CAAC;QACnB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QAC1B,eAAe,CAAC,EAAE,MAAM,CAAC;KAC1B,CAAC;IACF,cAAc,CAAC,EAAE,+BAA+B,CAAC,gBAAgB,CAAC,CAAC;IACnE,8BAA8B,CAAC,EAAE,CAC/B,KAAK,EAAE,+BAA+B,KACnC,OAAO,CAAC,8BAA8B,CAAC,CAAC;IAC7C,aAAa,CAAC,EAAE,CACd,KAAK,EAAE,KAAK,EACZ,WAAW,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,KAClC;QACH,MAAM,EAAE,CACN,QAAQ,EAAE,OAAO,EAAE,EACnB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,SAAS,CAAC,EAAE;YACV,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,aAAa,KAAK,IAAI,CAAC;SAC9C,EACD,aAAa,CAAC,EAAE,MAAM,EACtB,uBAAuB,CAAC,EAAE,MAAM,EAChC,WAAW,CAAC,EAAE,WAAW,KACtB,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC;KAC1C,CAAC;CACH;AA0RD,wBAAsB,gCAAgC,CACpD,KAAK,EAAE,oBAAoB,EAC3B,KAAK,EAAE,KAAK,EACZ,IAAI,EAAE,+BAA+B,GACpC,OAAO,CAAC,QAAQ,CAAC,CAgTnB"}
|
|
@@ -273,6 +273,9 @@ export async function createRuntimeAgentStreamResponse(input, agent, deps) {
|
|
|
273
273
|
runtimeStream = await runtime.stream(runtimeMessages, {
|
|
274
274
|
threadId: input.threadId,
|
|
275
275
|
runId: input.runId,
|
|
276
|
+
...(deps.projectAgentSandbox?.authToken
|
|
277
|
+
? { authToken: deps.projectAgentSandbox.authToken }
|
|
278
|
+
: {}),
|
|
276
279
|
...(input.parentRunId ? { parentRunId: input.parentRunId } : {}),
|
|
277
280
|
...(input.state !== undefined ? { state: input.state } : {}),
|
|
278
281
|
context: input.context,
|
package/esm/src/tool/types.d.ts
CHANGED
|
@@ -60,6 +60,8 @@ export interface ToolExecutionContext {
|
|
|
60
60
|
toolCallId?: string;
|
|
61
61
|
/** Project identity used by integration token resolution */
|
|
62
62
|
projectId?: string;
|
|
63
|
+
/** Request-scoped Veryfront auth token for project-local platform API tools */
|
|
64
|
+
authToken?: string;
|
|
63
65
|
/** Abort signal for cooperative cancellation during long-running tool execution */
|
|
64
66
|
abortSignal?: AbortSignal;
|
|
65
67
|
/** Progress token for sending progress notifications (MCP 2025-11-25) */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/src/tool/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAC;AACxE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D;;GAEG;AAEH,MAAM,WAAW,UAAU,CAAC,MAAM,GAAG,GAAG,EAAE,OAAO,GAAG,GAAG;IACrD,yDAAyD;IACzD,EAAE,CAAC,EAAE,MAAM,CAAC;IAEZ,wCAAwC;IACxC,WAAW,EAAE,MAAM,CAAC;IAEpB;;;;;OAKG;IACH,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,UAAU,CAAC;IAEzC;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,UAAU,CAAC;IAE5C;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B;;OAEG;IACH,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,oBAAoB,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;IAEvF,wBAAwB;IACxB,GAAG,CAAC,EAAE;QACJ,qBAAqB;QACr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