veryfront 0.1.199 → 0.1.201
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/cli/commands/knowledge/command.d.ts +13 -0
- package/esm/cli/commands/knowledge/command.d.ts.map +1 -1
- package/esm/cli/commands/knowledge/command.js +52 -19
- package/esm/deno.js +1 -1
- package/esm/src/agent/ag-ui-browser-encoder.d.ts.map +1 -1
- package/esm/src/agent/ag-ui-browser-encoder.js +97 -34
- package/esm/src/agent/runtime/chat-stream-handler.d.ts +1 -0
- package/esm/src/agent/runtime/chat-stream-handler.d.ts.map +1 -1
- package/esm/src/agent/runtime/chat-stream-handler.js +149 -9
- package/esm/src/agent/runtime/index.d.ts.map +1 -1
- package/esm/src/agent/runtime/index.js +0 -2
- 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/src/cli/commands/knowledge/command.ts +77 -21
- package/src/deno.js +1 -1
- package/src/src/agent/ag-ui-browser-encoder.ts +101 -31
- package/src/src/agent/runtime/chat-stream-handler.ts +172 -9
- package/src/src/agent/runtime/index.ts +0 -3
- package/src/src/utils/version-constant.ts +1 -1
|
@@ -6,6 +6,7 @@ type SafeParseResult<T> = {
|
|
|
6
6
|
success: false;
|
|
7
7
|
error: z.ZodError;
|
|
8
8
|
};
|
|
9
|
+
import { type CommandResult } from "../../../src/platform/compat/process.js";
|
|
9
10
|
import { type ApiClient } from "../../shared/config.js";
|
|
10
11
|
import type { ParsedArgs } from "../../shared/types.js";
|
|
11
12
|
import { type Logger } from "../../../src/utils/index.js";
|
|
@@ -89,6 +90,18 @@ export declare function runKnowledgeParser(input: {
|
|
|
89
90
|
sourceReference?: string;
|
|
90
91
|
env?: Record<string, string>;
|
|
91
92
|
}): Promise<KnowledgeParserResult>;
|
|
93
|
+
export declare function executeKnowledgeParserCommand(input: {
|
|
94
|
+
scriptPath: string;
|
|
95
|
+
inputJsonPath: string;
|
|
96
|
+
outputJsonPath: string;
|
|
97
|
+
env?: Record<string, string>;
|
|
98
|
+
}, deps?: {
|
|
99
|
+
runCommandFn?: (cmd: string, options: {
|
|
100
|
+
args: string[];
|
|
101
|
+
env?: Record<string, string>;
|
|
102
|
+
capture: true;
|
|
103
|
+
}) => Promise<CommandResult>;
|
|
104
|
+
}): Promise<void>;
|
|
92
105
|
export declare function runKnowledgeParsers(input: {
|
|
93
106
|
files: KnowledgeParserInput[];
|
|
94
107
|
outputDir: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/knowledge/command.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,KAAK,eAAe,CAAC,CAAC,IAAI;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,CAAC,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,CAAC,CAAC,QAAQ,CAAA;CAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/knowledge/command.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,KAAK,eAAe,CAAC,CAAC,IAAI;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,CAAC,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,CAAC,CAAC,QAAQ,CAAA;CAAE,CAAC;AAG7F,OAAO,EAAE,KAAK,aAAa,EAAc,MAAM,yCAAyC,CAAC;AAGzF,OAAO,EAAE,KAAK,SAAS,EAA0C,MAAM,wBAAwB,CAAC;AAChG,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAKxD,OAAO,EAAuB,KAAK,MAAM,EAAgB,MAAM,6BAA6B,CAAC;AAG7F,O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AE,KAAK,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;CACvE,GACA,OAAO,CAAC,yBAAyB,CAAC,CAuJpC;AAED,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,eAAe,EAAE,EAC1B,OAAO,EAAE,sBAAsB,EAC/B,IAAI,EAAE;IACJ,MAAM,EAAE,SAAS,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,OAAO,kBAAkB,CAAC;IACrC,mBAAmB,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC1F,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B,GACA,OAAO,CAAC;IACT,QAAQ,EAAE,yBAAyB,EAAE,CAAC;IACtC,MAAM,EAAE,+BAA+B,EAAE,CAAC;CAC3C,CAAC,CAsGD;AAED,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAwItE"}
|
|
@@ -2,6 +2,7 @@ import * as dntShim from "../../../_dnt.shims.js";
|
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { createFileSystem, getEnv } from "../../../src/platform/index.js";
|
|
4
4
|
import { basename, extname, join, normalize, relative } from "../../../src/platform/compat/path/index.js";
|
|
5
|
+
import { runCommand } from "../../../src/platform/compat/process.js";
|
|
5
6
|
import { withSpan } from "../../../src/observability/tracing/otlp-setup.js";
|
|
6
7
|
import { cliLogger } from "../../utils/index.js";
|
|
7
8
|
import { createApiClient, resolveConfigWithAuth } from "../../shared/config.js";
|
|
@@ -356,6 +357,51 @@ export async function runKnowledgeParser(input) {
|
|
|
356
357
|
}
|
|
357
358
|
return result;
|
|
358
359
|
}
|
|
360
|
+
function isMissingPythonExecutableError(error) {
|
|
361
|
+
if (!(error instanceof Error)) {
|
|
362
|
+
return false;
|
|
363
|
+
}
|
|
364
|
+
const errorWithCode = error;
|
|
365
|
+
if (errorWithCode.code === "ENOENT") {
|
|
366
|
+
return true;
|
|
367
|
+
}
|
|
368
|
+
return error.name === "NotFound" ||
|
|
369
|
+
/\bENOENT\b/i.test(error.message) ||
|
|
370
|
+
/not found/i.test(error.message) ||
|
|
371
|
+
/no such file or directory/i.test(error.message);
|
|
372
|
+
}
|
|
373
|
+
export async function executeKnowledgeParserCommand(input, deps = {}) {
|
|
374
|
+
const runCommandFn = deps.runCommandFn ?? runCommand;
|
|
375
|
+
let result;
|
|
376
|
+
try {
|
|
377
|
+
result = await runCommandFn("python3", {
|
|
378
|
+
args: [
|
|
379
|
+
input.scriptPath,
|
|
380
|
+
"--input-json",
|
|
381
|
+
input.inputJsonPath,
|
|
382
|
+
"--output-json",
|
|
383
|
+
input.outputJsonPath,
|
|
384
|
+
],
|
|
385
|
+
...(input.env ? { env: input.env } : {}),
|
|
386
|
+
capture: true,
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
catch (error) {
|
|
390
|
+
if (isMissingPythonExecutableError(error)) {
|
|
391
|
+
throw new Error("python3 is required. Install python3 and the supported parser packages, or run the command inside the Veryfront sandbox.");
|
|
392
|
+
}
|
|
393
|
+
throw error;
|
|
394
|
+
}
|
|
395
|
+
if (result.success) {
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
const stderr = result.stderr?.trim();
|
|
399
|
+
const stdout = result.stdout?.trim();
|
|
400
|
+
if (result.code === 1 && !stderr && !stdout) {
|
|
401
|
+
throw new Error("python3 is required. Install python3 and the supported parser packages, or run the command inside the Veryfront sandbox.");
|
|
402
|
+
}
|
|
403
|
+
throw new Error(stderr || stdout || "parser exited unsuccessfully");
|
|
404
|
+
}
|
|
359
405
|
export async function runKnowledgeParsers(input) {
|
|
360
406
|
if (!input.files.length) {
|
|
361
407
|
return [];
|
|
@@ -376,25 +422,12 @@ export async function runKnowledgeParsers(input) {
|
|
|
376
422
|
output_dir: input.outputDir,
|
|
377
423
|
}));
|
|
378
424
|
await dntShim.Deno.writeTextFile(scriptPath, knowledgeIngestPythonSource);
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
stderr: "piped",
|
|
386
|
-
}).output();
|
|
387
|
-
}
|
|
388
|
-
catch (error) {
|
|
389
|
-
if (error instanceof dntShim.Deno.errors.NotFound) {
|
|
390
|
-
throw new Error("python3 is required. Install python3 and the supported parser packages, or run the command inside the Veryfront sandbox.");
|
|
391
|
-
}
|
|
392
|
-
throw error;
|
|
393
|
-
}
|
|
394
|
-
if (result.code !== 0) {
|
|
395
|
-
const stderr = new TextDecoder().decode(result.stderr).trim();
|
|
396
|
-
throw new Error(stderr || "parser exited unsuccessfully");
|
|
397
|
-
}
|
|
425
|
+
await executeKnowledgeParserCommand({
|
|
426
|
+
scriptPath,
|
|
427
|
+
inputJsonPath,
|
|
428
|
+
outputJsonPath,
|
|
429
|
+
env: input.env,
|
|
430
|
+
});
|
|
398
431
|
const raw = await dntShim.Deno.readTextFile(outputJsonPath);
|
|
399
432
|
const parsed = JSON.parse(raw);
|
|
400
433
|
return Array.isArray(parsed) ? parsed : [parsed];
|
package/esm/deno.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ag-ui-browser-encoder.d.ts","sourceRoot":"","sources":["../../../src/src/agent/ag-ui-browser-encoder.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,MAAM,MAAM,sBAAsB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhF,MAAM,WAAW,8BAA8B;IAC7C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC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M,GAAG,IAAI,CAAC;IACzB,QAAQ,EAAE,OAAO,CAAC;IAClB,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,oBAAoB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAClC,gBAAgB,EAAE,OAAO,CAAC;IAC1B,gBAAgB,EAAE,OAAO,CAAC;IAC1B,QAAQ,EAAE,8BAA8B,CAAC;CAC1C;AAED,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED,wBAAgB,6BAA6B,IAAI,uBAAuB,CAYvE;AAuND,wBAAgB,wCAAwC,CACtD,KAAK,EAAE,uBAAuB,EAC9B,KAAK,EAAE,sBAAsB,GAC5B,uBAAuB,EAAE,CAyM3B;AAED,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,uBAAuB,EAC9B,QAAQ,EAAE,aAAa,GAAG,IAAI,GAC7B,uBAAuB,EAAE,CA8B3B"}
|
|
@@ -153,6 +153,24 @@ function createTextEvent(messageId, type, delta = "") {
|
|
|
153
153
|
: { messageId },
|
|
154
154
|
};
|
|
155
155
|
}
|
|
156
|
+
function closeOpenTextEvent(state) {
|
|
157
|
+
if (!state.textOpen) {
|
|
158
|
+
return [];
|
|
159
|
+
}
|
|
160
|
+
state.textOpen = false;
|
|
161
|
+
return [createTextEvent(getMessageId(state, { type: "text-end" }), "TextMessageEnd")];
|
|
162
|
+
}
|
|
163
|
+
function closeOpenReasoningEvent(state) {
|
|
164
|
+
if (state.reasoningMessageId === null) {
|
|
165
|
+
return [];
|
|
166
|
+
}
|
|
167
|
+
const messageId = state.reasoningMessageId;
|
|
168
|
+
state.reasoningMessageId = null;
|
|
169
|
+
return [{
|
|
170
|
+
event: "ReasoningMessageEnd",
|
|
171
|
+
payload: { messageId },
|
|
172
|
+
}];
|
|
173
|
+
}
|
|
156
174
|
export function mapRuntimeStreamEventToAgUiBrowserEvents(state, event) {
|
|
157
175
|
if (event.type.startsWith("data-")) {
|
|
158
176
|
const name = event.type.slice("data-".length);
|
|
@@ -167,24 +185,26 @@ export function mapRuntimeStreamEventToAgUiBrowserEvents(state, event) {
|
|
|
167
185
|
getMessageId(state, event);
|
|
168
186
|
return [];
|
|
169
187
|
case "text-start": {
|
|
188
|
+
const events = closeOpenReasoningEvent(state);
|
|
170
189
|
if (state.textOpen)
|
|
171
190
|
return [];
|
|
172
191
|
const messageId = getMessageId(state, event);
|
|
173
192
|
state.textOpen = true;
|
|
174
193
|
state.sawVisibleOutput = true;
|
|
175
|
-
|
|
194
|
+
events.push(createTextEvent(messageId, "TextMessageStart"));
|
|
195
|
+
return events;
|
|
176
196
|
}
|
|
177
197
|
case "text-delta": {
|
|
198
|
+
const events = closeOpenReasoningEvent(state);
|
|
178
199
|
const messageId = getMessageId(state, event);
|
|
179
200
|
state.sawVisibleOutput = true;
|
|
180
201
|
if (!state.textOpen) {
|
|
181
202
|
state.textOpen = true;
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
createTextEvent(messageId, "TextMessageContent", typeof event.delta === "string" ? event.delta : ""),
|
|
185
|
-
];
|
|
203
|
+
events.push(createTextEvent(messageId, "TextMessageStart"), createTextEvent(messageId, "TextMessageContent", typeof event.delta === "string" ? event.delta : ""));
|
|
204
|
+
return events;
|
|
186
205
|
}
|
|
187
|
-
|
|
206
|
+
events.push(createTextEvent(messageId, "TextMessageContent", typeof event.delta === "string" ? event.delta : ""));
|
|
207
|
+
return events;
|
|
188
208
|
}
|
|
189
209
|
case "text-end": {
|
|
190
210
|
if (!state.textOpen)
|
|
@@ -192,26 +212,42 @@ export function mapRuntimeStreamEventToAgUiBrowserEvents(state, event) {
|
|
|
192
212
|
state.textOpen = false;
|
|
193
213
|
return [createTextEvent(getMessageId(state, event), "TextMessageEnd")];
|
|
194
214
|
}
|
|
195
|
-
case "reasoning-start":
|
|
215
|
+
case "reasoning-start": {
|
|
216
|
+
const events = closeOpenTextEvent(state);
|
|
217
|
+
events.push(...closeOpenReasoningEvent(state));
|
|
196
218
|
state.sawVisibleOutput = true;
|
|
197
|
-
|
|
198
|
-
|
|
219
|
+
events.push(createReasoningEvent(state, event, "ReasoningMessageStart"));
|
|
220
|
+
return events;
|
|
221
|
+
}
|
|
222
|
+
case "reasoning-delta": {
|
|
223
|
+
const events = closeOpenTextEvent(state);
|
|
199
224
|
state.sawVisibleOutput = true;
|
|
200
|
-
|
|
225
|
+
if (state.reasoningMessageId === null) {
|
|
226
|
+
events.push(createReasoningEvent(state, event, "ReasoningMessageStart"));
|
|
227
|
+
}
|
|
228
|
+
events.push(createReasoningEvent(state, event, "ReasoningMessageContent"));
|
|
229
|
+
return events;
|
|
230
|
+
}
|
|
201
231
|
case "reasoning-end": {
|
|
202
232
|
const reasoningEvent = createReasoningEvent(state, event, "ReasoningMessageEnd");
|
|
203
233
|
state.reasoningMessageId = null;
|
|
204
234
|
return [reasoningEvent];
|
|
205
235
|
}
|
|
206
|
-
case "tool-input-start":
|
|
236
|
+
case "tool-input-start": {
|
|
237
|
+
const events = [
|
|
238
|
+
...closeOpenTextEvent(state),
|
|
239
|
+
...closeOpenReasoningEvent(state),
|
|
240
|
+
];
|
|
207
241
|
state.sawVisibleOutput = true;
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
242
|
+
events.push({
|
|
243
|
+
event: "ToolCallStart",
|
|
244
|
+
payload: {
|
|
245
|
+
toolCallId: event.toolCallId,
|
|
246
|
+
toolCallName: event.toolName,
|
|
247
|
+
},
|
|
248
|
+
});
|
|
249
|
+
return events;
|
|
250
|
+
}
|
|
215
251
|
case "tool-input-delta":
|
|
216
252
|
state.sawVisibleOutput = true;
|
|
217
253
|
if (typeof event.toolCallId === "string") {
|
|
@@ -226,11 +262,19 @@ export function mapRuntimeStreamEventToAgUiBrowserEvents(state, event) {
|
|
|
226
262
|
}];
|
|
227
263
|
case "tool-input-available": {
|
|
228
264
|
state.sawVisibleOutput = true;
|
|
229
|
-
return
|
|
265
|
+
return [
|
|
266
|
+
...closeOpenTextEvent(state),
|
|
267
|
+
...closeOpenReasoningEvent(state),
|
|
268
|
+
...completeToolInput(state, event),
|
|
269
|
+
];
|
|
230
270
|
}
|
|
231
271
|
case "tool-input-error": {
|
|
232
272
|
state.sawVisibleOutput = true;
|
|
233
|
-
const events =
|
|
273
|
+
const events = [
|
|
274
|
+
...closeOpenTextEvent(state),
|
|
275
|
+
...closeOpenReasoningEvent(state),
|
|
276
|
+
...completeToolInput(state, event),
|
|
277
|
+
];
|
|
234
278
|
events.push({
|
|
235
279
|
event: "ToolCallResult",
|
|
236
280
|
payload: {
|
|
@@ -245,32 +289,56 @@ export function mapRuntimeStreamEventToAgUiBrowserEvents(state, event) {
|
|
|
245
289
|
}
|
|
246
290
|
case "tool-output-available":
|
|
247
291
|
state.sawVisibleOutput = true;
|
|
248
|
-
return [
|
|
292
|
+
return [
|
|
293
|
+
...closeOpenTextEvent(state),
|
|
294
|
+
...closeOpenReasoningEvent(state),
|
|
295
|
+
createToolResultEvent(event.toolCallId, event.output),
|
|
296
|
+
];
|
|
249
297
|
case "tool-output-error":
|
|
250
298
|
state.sawVisibleOutput = true;
|
|
251
|
-
return [
|
|
299
|
+
return [
|
|
300
|
+
...closeOpenTextEvent(state),
|
|
301
|
+
...closeOpenReasoningEvent(state),
|
|
302
|
+
createToolResultEvent(event.toolCallId, { error: event.errorText }, true),
|
|
303
|
+
];
|
|
252
304
|
case "tool-output-denied":
|
|
253
305
|
state.sawVisibleOutput = true;
|
|
254
|
-
return [
|
|
306
|
+
return [
|
|
307
|
+
...closeOpenTextEvent(state),
|
|
308
|
+
...closeOpenReasoningEvent(state),
|
|
309
|
+
createToolResultEvent(event.toolCallId, { error: "Tool output denied" }, true),
|
|
310
|
+
];
|
|
255
311
|
case "step-start":
|
|
256
312
|
case "start-step":
|
|
257
313
|
state.sawVisibleOutput = true;
|
|
258
|
-
return [
|
|
314
|
+
return [
|
|
315
|
+
...closeOpenTextEvent(state),
|
|
316
|
+
...closeOpenReasoningEvent(state),
|
|
317
|
+
createStepEvent(state, "StepStarted"),
|
|
318
|
+
];
|
|
259
319
|
case "step-end":
|
|
260
320
|
case "finish-step":
|
|
261
321
|
state.sawVisibleOutput = true;
|
|
262
|
-
return [
|
|
322
|
+
return [
|
|
323
|
+
...closeOpenTextEvent(state),
|
|
324
|
+
...closeOpenReasoningEvent(state),
|
|
325
|
+
createStepEvent(state, "StepFinished"),
|
|
326
|
+
];
|
|
263
327
|
case "data":
|
|
264
328
|
applyDataMetadata(state, event);
|
|
265
329
|
return [];
|
|
266
330
|
case "error":
|
|
267
331
|
state.sawTerminalError = true;
|
|
268
|
-
return [
|
|
332
|
+
return [
|
|
333
|
+
...closeOpenTextEvent(state),
|
|
334
|
+
...closeOpenReasoningEvent(state),
|
|
335
|
+
{
|
|
269
336
|
event: "RunError",
|
|
270
337
|
payload: {
|
|
271
338
|
message: typeof event.error === "string" ? event.error : "Agent run failed",
|
|
272
339
|
},
|
|
273
|
-
}
|
|
340
|
+
},
|
|
341
|
+
];
|
|
274
342
|
default:
|
|
275
343
|
return [];
|
|
276
344
|
}
|
|
@@ -291,13 +359,8 @@ export function finalizeAgUiBrowserEvents(state, response) {
|
|
|
291
359
|
}];
|
|
292
360
|
}
|
|
293
361
|
const events = [];
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
events.push({
|
|
297
|
-
event: "TextMessageEnd",
|
|
298
|
-
payload: { messageId: getMessageId(state, { type: "text-end" }) },
|
|
299
|
-
});
|
|
300
|
-
}
|
|
362
|
+
events.push(...closeOpenTextEvent(state));
|
|
363
|
+
events.push(...closeOpenReasoningEvent(state));
|
|
301
364
|
events.push({
|
|
302
365
|
event: "RunFinished",
|
|
303
366
|
payload: {
|
|
@@ -1 +1 @@
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C;KACtB,KAAK,IAAI,CAAC;CACZ;AAyED,wBAAgB,iBAAiB,IAAI,eAAe,CAQnD;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,mBAAmB,EAC3B,KAAK,EAAE,eAAe,EACtB,UAAU,EAAE,+BAA+B,EAC3C,OAAO,EAAE,WAAW,EACpB,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,SAAS,CAAC,EAAE,mBAAmB,EAC/B,WAAW,CAAC,EAAE,WAAW,GACxB,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"chat-stream-handler.d.ts","sourceRoot":"","sources":["../../../../src/src/agent/runtime/chat-stream-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAqB,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAYtF,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,mBAAmB;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,eAAe;IAC9B,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;IAC1C,WAAW,EAAE,mBAAmB,EAAE,CAAC;IACnC,KAAK,EAAE;QAAE,YAAY,EAAE,MAAM,CAAC;QAAC,gBAAgB,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC;CAChF;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE;QAChB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,KAAK,IAAI,CAAC;CACZ;AAyED,wBAAgB,iBAAiB,IAAI,eAAe,CAQnD;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,mBAAmB,EAC3B,KAAK,EAAE,eAAe,EACtB,UAAU,EAAE,+BAA+B,EAC3C,OAAO,EAAE,WAAW,EACpB,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,SAAS,CAAC,EAAE,mBAAmB,EAC/B,WAAW,CAAC,EAAE,WAAW,GACxB,OAAO,CAAC,IAAI,CAAC,CAuZf"}
|
|
@@ -86,6 +86,114 @@ export function createStreamState() {
|
|
|
86
86
|
export function processStream(result, state, controller, encoder, textPartId, callbacks, abortSignal) {
|
|
87
87
|
return withSpan("agent.runtime.processStream", async () => {
|
|
88
88
|
let eventCount = 0;
|
|
89
|
+
let textOpen = false;
|
|
90
|
+
let activeReasoningId = null;
|
|
91
|
+
const normalizeReasoningId = (part) => typeof part.id === "string" && part.id.length > 0 ? part.id : "reasoning";
|
|
92
|
+
const openTextSegment = () => {
|
|
93
|
+
if (textOpen) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
textOpen = true;
|
|
97
|
+
sendSSE(controller, encoder, {
|
|
98
|
+
type: "text-start",
|
|
99
|
+
id: textPartId,
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
const closeTextSegment = () => {
|
|
103
|
+
if (!textOpen) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
textOpen = false;
|
|
107
|
+
sendSSE(controller, encoder, {
|
|
108
|
+
type: "text-end",
|
|
109
|
+
id: textPartId,
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
const openReasoningSegment = (reasoningId) => {
|
|
113
|
+
if (activeReasoningId === reasoningId) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (activeReasoningId !== null) {
|
|
117
|
+
sendSSE(controller, encoder, {
|
|
118
|
+
type: "reasoning-end",
|
|
119
|
+
id: activeReasoningId,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
activeReasoningId = reasoningId;
|
|
123
|
+
sendSSE(controller, encoder, {
|
|
124
|
+
type: "reasoning-start",
|
|
125
|
+
id: reasoningId,
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
const closeReasoningSegment = () => {
|
|
129
|
+
if (activeReasoningId === null) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
sendSSE(controller, encoder, {
|
|
133
|
+
type: "reasoning-end",
|
|
134
|
+
id: activeReasoningId,
|
|
135
|
+
});
|
|
136
|
+
activeReasoningId = null;
|
|
137
|
+
};
|
|
138
|
+
const ensureToolLifecycle = (part) => {
|
|
139
|
+
const dynamic = part.dynamic ?? isDynamicTool(part.toolName);
|
|
140
|
+
const existing = state.toolCalls.get(part.toolCallId);
|
|
141
|
+
if (!existing) {
|
|
142
|
+
const normalizedInput = parseToolInputObject(part.input);
|
|
143
|
+
state.toolCalls.set(part.toolCallId, {
|
|
144
|
+
id: part.toolCallId,
|
|
145
|
+
name: part.toolName,
|
|
146
|
+
arguments: normalizeToolInputString(part.input),
|
|
147
|
+
inputAvailable: true,
|
|
148
|
+
...(part.providerExecuted !== undefined
|
|
149
|
+
? { providerExecuted: part.providerExecuted }
|
|
150
|
+
: {}),
|
|
151
|
+
...(dynamic ? { dynamic: true } : {}),
|
|
152
|
+
});
|
|
153
|
+
sendSSE(controller, encoder, {
|
|
154
|
+
type: "tool-input-start",
|
|
155
|
+
toolCallId: part.toolCallId,
|
|
156
|
+
toolName: part.toolName,
|
|
157
|
+
...(dynamic ? { dynamic: true } : {}),
|
|
158
|
+
});
|
|
159
|
+
sendSSE(controller, encoder, {
|
|
160
|
+
type: "tool-input-available",
|
|
161
|
+
toolCallId: part.toolCallId,
|
|
162
|
+
toolName: part.toolName,
|
|
163
|
+
input: normalizedInput,
|
|
164
|
+
...(part.providerExecuted !== undefined
|
|
165
|
+
? { providerExecuted: part.providerExecuted }
|
|
166
|
+
: {}),
|
|
167
|
+
...(dynamic ? { dynamic: true } : {}),
|
|
168
|
+
});
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
if (existing.inputAvailable) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
const resolvedArguments = part.input !== undefined
|
|
175
|
+
? mergeToolCallInput(existing.arguments, normalizeToolInputString(part.input))
|
|
176
|
+
: existing.arguments;
|
|
177
|
+
const resolvedInput = parseToolInputObject(resolvedArguments);
|
|
178
|
+
existing.arguments = resolvedArguments;
|
|
179
|
+
existing.inputAvailable = true;
|
|
180
|
+
if (part.providerExecuted !== undefined) {
|
|
181
|
+
existing.providerExecuted = part.providerExecuted;
|
|
182
|
+
}
|
|
183
|
+
if (dynamic) {
|
|
184
|
+
existing.dynamic = true;
|
|
185
|
+
}
|
|
186
|
+
sendSSE(controller, encoder, {
|
|
187
|
+
type: "tool-input-available",
|
|
188
|
+
toolCallId: part.toolCallId,
|
|
189
|
+
toolName: existing.name,
|
|
190
|
+
input: resolvedInput,
|
|
191
|
+
...(existing.providerExecuted !== undefined
|
|
192
|
+
? { providerExecuted: existing.providerExecuted }
|
|
193
|
+
: {}),
|
|
194
|
+
...(existing.dynamic ? { dynamic: true } : {}),
|
|
195
|
+
});
|
|
196
|
+
};
|
|
89
197
|
throwIfAborted(abortSignal);
|
|
90
198
|
for await (const part of result.fullStream) {
|
|
91
199
|
throwIfAborted(abortSignal);
|
|
@@ -96,6 +204,8 @@ export function processStream(result, state, controller, encoder, textPartId, ca
|
|
|
96
204
|
const typedPart = part;
|
|
97
205
|
switch (typedPart.type) {
|
|
98
206
|
case "text-delta": {
|
|
207
|
+
closeReasoningSegment();
|
|
208
|
+
openTextSegment();
|
|
99
209
|
state.accumulatedText += typedPart.text;
|
|
100
210
|
sendSSE(controller, encoder, {
|
|
101
211
|
type: "text-delta",
|
|
@@ -106,33 +216,37 @@ export function processStream(result, state, controller, encoder, textPartId, ca
|
|
|
106
216
|
break;
|
|
107
217
|
}
|
|
108
218
|
case "reasoning-start": {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
id: typeof typedPart.id === "string" ? typedPart.id : "reasoning",
|
|
112
|
-
});
|
|
219
|
+
closeTextSegment();
|
|
220
|
+
openReasoningSegment(normalizeReasoningId(typedPart));
|
|
113
221
|
break;
|
|
114
222
|
}
|
|
115
223
|
case "reasoning-delta": {
|
|
224
|
+
closeTextSegment();
|
|
225
|
+
openReasoningSegment(normalizeReasoningId(typedPart));
|
|
116
226
|
sendSSE(controller, encoder, {
|
|
117
227
|
type: "reasoning-delta",
|
|
118
|
-
id:
|
|
228
|
+
id: normalizeReasoningId(typedPart),
|
|
119
229
|
delta: typeof typedPart.delta === "string" ? typedPart.delta : "",
|
|
120
230
|
});
|
|
121
231
|
break;
|
|
122
232
|
}
|
|
123
233
|
case "reasoning-end": {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
234
|
+
closeTextSegment();
|
|
235
|
+
if (activeReasoningId === null) {
|
|
236
|
+
activeReasoningId = normalizeReasoningId(typedPart);
|
|
237
|
+
}
|
|
238
|
+
closeReasoningSegment();
|
|
128
239
|
break;
|
|
129
240
|
}
|
|
130
241
|
case "tool-input-start": {
|
|
242
|
+
closeTextSegment();
|
|
243
|
+
closeReasoningSegment();
|
|
131
244
|
const toolId = typedPart.id;
|
|
132
245
|
state.toolCalls.set(toolId, {
|
|
133
246
|
id: toolId,
|
|
134
247
|
name: typedPart.toolName,
|
|
135
248
|
arguments: "",
|
|
249
|
+
inputAvailable: false,
|
|
136
250
|
providerExecuted: typedPart.providerExecuted,
|
|
137
251
|
dynamic: typedPart.dynamic,
|
|
138
252
|
});
|
|
@@ -146,6 +260,7 @@ export function processStream(result, state, controller, encoder, textPartId, ca
|
|
|
146
260
|
break;
|
|
147
261
|
}
|
|
148
262
|
case "tool-input-delta": {
|
|
263
|
+
closeReasoningSegment();
|
|
149
264
|
const toolId = typedPart.id;
|
|
150
265
|
const tc = state.toolCalls.get(toolId);
|
|
151
266
|
if (!tc)
|
|
@@ -159,6 +274,8 @@ export function processStream(result, state, controller, encoder, textPartId, ca
|
|
|
159
274
|
break;
|
|
160
275
|
}
|
|
161
276
|
case "tool-call": {
|
|
277
|
+
closeTextSegment();
|
|
278
|
+
closeReasoningSegment();
|
|
162
279
|
// tool-call fires when the full tool call is available
|
|
163
280
|
const toolId = typedPart.toolCallId;
|
|
164
281
|
const inputStr = normalizeToolInputString(typedPart.input);
|
|
@@ -168,6 +285,7 @@ export function processStream(result, state, controller, encoder, textPartId, ca
|
|
|
168
285
|
id: toolId,
|
|
169
286
|
name: typedPart.toolName,
|
|
170
287
|
arguments: resolvedArguments,
|
|
288
|
+
inputAvailable: true,
|
|
171
289
|
providerExecuted: typedPart.providerExecuted,
|
|
172
290
|
dynamic: typedPart.dynamic,
|
|
173
291
|
});
|
|
@@ -186,6 +304,15 @@ export function processStream(result, state, controller, encoder, textPartId, ca
|
|
|
186
304
|
break;
|
|
187
305
|
}
|
|
188
306
|
case "tool-result": {
|
|
307
|
+
closeTextSegment();
|
|
308
|
+
closeReasoningSegment();
|
|
309
|
+
ensureToolLifecycle({
|
|
310
|
+
toolCallId: typedPart.toolCallId,
|
|
311
|
+
toolName: typedPart.toolName,
|
|
312
|
+
input: typedPart.input,
|
|
313
|
+
providerExecuted: typedPart.providerExecuted,
|
|
314
|
+
dynamic: typedPart.dynamic,
|
|
315
|
+
});
|
|
189
316
|
const isError = typedPart.isError === true;
|
|
190
317
|
logProviderToolPart("tool-result", {
|
|
191
318
|
toolCallId: typedPart.toolCallId,
|
|
@@ -241,6 +368,15 @@ export function processStream(result, state, controller, encoder, textPartId, ca
|
|
|
241
368
|
break;
|
|
242
369
|
}
|
|
243
370
|
case "tool-error": {
|
|
371
|
+
closeTextSegment();
|
|
372
|
+
closeReasoningSegment();
|
|
373
|
+
ensureToolLifecycle({
|
|
374
|
+
toolCallId: typedPart.toolCallId,
|
|
375
|
+
toolName: typedPart.toolName,
|
|
376
|
+
input: typedPart.input,
|
|
377
|
+
providerExecuted: typedPart.providerExecuted,
|
|
378
|
+
dynamic: typedPart.dynamic,
|
|
379
|
+
});
|
|
244
380
|
logProviderToolPart("tool-error", {
|
|
245
381
|
toolCallId: typedPart.toolCallId,
|
|
246
382
|
toolName: typedPart.toolName,
|
|
@@ -270,6 +406,8 @@ export function processStream(result, state, controller, encoder, textPartId, ca
|
|
|
270
406
|
break;
|
|
271
407
|
}
|
|
272
408
|
case "finish": {
|
|
409
|
+
closeTextSegment();
|
|
410
|
+
closeReasoningSegment();
|
|
273
411
|
state.finishReason = typedPart.finishReason ?? null;
|
|
274
412
|
if (typedPart.totalUsage) {
|
|
275
413
|
const input = typedPart.totalUsage.inputTokens ?? 0;
|
|
@@ -284,6 +422,8 @@ export function processStream(result, state, controller, encoder, textPartId, ca
|
|
|
284
422
|
break;
|
|
285
423
|
}
|
|
286
424
|
case "error": {
|
|
425
|
+
closeTextSegment();
|
|
426
|
+
closeReasoningSegment();
|
|
287
427
|
logger.warn("Runtime stream error:", typedPart.error);
|
|
288
428
|
sendSSE(controller, encoder, {
|
|
289
429
|
type: "error",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/src/agent/runtime/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG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