veryfront 0.1.192 → 0.1.195
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.d.ts +2 -0
- package/esm/deno.js +3 -1
- package/esm/src/agent/ag-ui-handler.d.ts.map +1 -1
- package/esm/src/agent/ag-ui-handler.js +3 -25
- package/esm/src/agent/data-stream.d.ts +11 -0
- package/esm/src/agent/data-stream.d.ts.map +1 -0
- package/esm/src/agent/data-stream.js +96 -0
- package/esm/src/agent/index.d.ts +1 -0
- package/esm/src/agent/index.d.ts.map +1 -1
- package/esm/src/agent/index.js +1 -0
- package/esm/src/agent/runtime/chat-stream-handler.d.ts.map +1 -1
- package/esm/src/agent/runtime/chat-stream-handler.js +2 -36
- package/esm/src/chat/ag-ui.d.ts +307 -0
- package/esm/src/chat/ag-ui.d.ts.map +1 -0
- package/esm/src/chat/ag-ui.js +610 -0
- package/esm/src/internal-agents/ag-ui-sse.d.ts.map +1 -1
- package/esm/src/internal-agents/ag-ui-sse.js +6 -24
- package/esm/src/utils/version-constant.d.ts +1 -1
- package/esm/src/utils/version-constant.js +1 -1
- package/package.json +4 -1
- package/src/deno.js +3 -1
- package/src/src/agent/ag-ui-handler.ts +4 -28
- package/src/src/agent/data-stream.ts +121 -0
- package/src/src/agent/index.ts +8 -0
- package/src/src/agent/runtime/chat-stream-handler.ts +2 -44
- package/src/src/chat/ag-ui.ts +753 -0
- package/src/src/internal-agents/ag-ui-sse.ts +6 -26
- package/src/src/utils/version-constant.ts +1 -1
package/esm/deno.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ declare namespace _default {
|
|
|
11
11
|
"./context": string;
|
|
12
12
|
"./fonts": string;
|
|
13
13
|
"./chat": string;
|
|
14
|
+
"./chat/ag-ui": string;
|
|
14
15
|
"./chat/protocol": string;
|
|
15
16
|
"./markdown": string;
|
|
16
17
|
"./mdx": string;
|
|
@@ -41,6 +42,7 @@ declare namespace _default {
|
|
|
41
42
|
"veryfront/context": string;
|
|
42
43
|
"veryfront/fonts": string;
|
|
43
44
|
"veryfront/chat": string;
|
|
45
|
+
"veryfront/chat/ag-ui": string;
|
|
44
46
|
"veryfront/chat/protocol": string;
|
|
45
47
|
"veryfront/markdown": string;
|
|
46
48
|
"veryfront/mdx": string;
|
package/esm/deno.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export default {
|
|
2
2
|
"name": "veryfront",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.195",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"nodeModulesDir": "auto",
|
|
6
6
|
"exclude": [
|
|
@@ -21,6 +21,7 @@ export default {
|
|
|
21
21
|
"./context": "./src/react/context/index.tsx",
|
|
22
22
|
"./fonts": "./src/react/fonts/index.ts",
|
|
23
23
|
"./chat": "./src/chat/index.ts",
|
|
24
|
+
"./chat/ag-ui": "./src/chat/ag-ui.ts",
|
|
24
25
|
"./chat/protocol": "./src/chat/protocol.ts",
|
|
25
26
|
"./markdown": "./src/markdown/index.ts",
|
|
26
27
|
"./mdx": "./src/mdx/index.ts",
|
|
@@ -51,6 +52,7 @@ export default {
|
|
|
51
52
|
"veryfront/context": "./src/react/runtime/core.ts",
|
|
52
53
|
"veryfront/fonts": "./src/react/fonts/index.ts",
|
|
53
54
|
"veryfront/chat": "./src/chat/index.ts",
|
|
55
|
+
"veryfront/chat/ag-ui": "./src/chat/ag-ui.ts",
|
|
54
56
|
"veryfront/chat/protocol": "./src/chat/protocol.ts",
|
|
55
57
|
"veryfront/markdown": "./src/markdown/index.ts",
|
|
56
58
|
"veryfront/mdx": "./src/mdx/index.ts",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ag-ui-handler.d.ts","sourceRoot":"","sources":["../../../src/src/agent/ag-ui-handler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,KAAK,EAAW,MAAM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AM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAG5D,KAAK,eAAe,GAAG;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC;AAyY7D,MAAM,WAAW,kBAAkB;IACjC,OAAO,CAAC,EACJ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACvB,CAAC,CAAC,OAAO,EAAE,OAAO,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IACvF,cAAc,CAAC,EAAE,uBAAuB,CAAC,eAAe,CAAC,CAAC;CAC3D;AAED,MAAM,WAAW,0BAA2B,SAAQ,kBAAkB;IACpE,KAAK,EAAE,KAAK,CAAC;CACd;AAUD,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,kBAAkB,GAC3B,CAAC,YAAY,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAChD,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,0BAA0B,EAClC,OAAO,CAAC,EAAE,kBAAkB,GAC3B,CAAC,YAAY,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC"}
|
|
@@ -5,7 +5,8 @@ import { AgentRuntime, RunAlreadyExistsError, } from "./runtime/index.js";
|
|
|
5
5
|
import { INVALID_ARGUMENT } from "../errors/index.js";
|
|
6
6
|
import { SKILL_TOOL_IDS } from "../skill/types.js";
|
|
7
7
|
import { toolRegistry } from "../tool/index.js";
|
|
8
|
-
import { createStreamTransformState, finalizeRunEvents, formatAgUiEvent, mapRuntimeEventToAgUi,
|
|
8
|
+
import { createStreamTransformState, finalizeRunEvents, formatAgUiEvent, mapRuntimeEventToAgUi, } from "../internal-agents/ag-ui-sse.js";
|
|
9
|
+
import { streamDataStreamEvents } from "./data-stream.js";
|
|
9
10
|
const AGENT_ID_PATTERN = /^[a-zA-Z0-9_-]+$/;
|
|
10
11
|
const MAX_TOOL_PARAMETERS_BYTES = 16_384;
|
|
11
12
|
const MAX_CONTEXT_ITEM_BYTES = 16_384;
|
|
@@ -202,9 +203,6 @@ async function createAgUiStreamResponse(options) {
|
|
|
202
203
|
const stream = new ReadableStream({
|
|
203
204
|
start: async (controller) => {
|
|
204
205
|
const state = createStreamTransformState();
|
|
205
|
-
let reader = null;
|
|
206
|
-
let remainder = "";
|
|
207
|
-
const decoder = new TextDecoder();
|
|
208
206
|
const prepareToolResultIfNeeded = (event, payload) => {
|
|
209
207
|
if (event !== "ToolCallStart" && event !== "ToolCallArgs" &&
|
|
210
208
|
event !== "ToolCallEnd") {
|
|
@@ -235,26 +233,7 @@ async function createAgUiStreamResponse(options) {
|
|
|
235
233
|
closeController(controller);
|
|
236
234
|
return;
|
|
237
235
|
}
|
|
238
|
-
|
|
239
|
-
while (true) {
|
|
240
|
-
const { done, value } = await reader.read();
|
|
241
|
-
if (done)
|
|
242
|
-
break;
|
|
243
|
-
remainder += decoder.decode(value, { stream: true });
|
|
244
|
-
const parsed = parseSseJsonEvents(remainder);
|
|
245
|
-
remainder = parsed.remainder;
|
|
246
|
-
for (const event of parsed.events) {
|
|
247
|
-
for (const mapped of mapRuntimeEventToAgUi(state, event)) {
|
|
248
|
-
prepareToolResultIfNeeded(mapped.event, mapped.payload);
|
|
249
|
-
if (!enqueueEvent(controller, mapped.event, mapped.payload)) {
|
|
250
|
-
return;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
remainder += decoder.decode();
|
|
256
|
-
const parsed = parseSseJsonEvents(remainder);
|
|
257
|
-
for (const event of parsed.events) {
|
|
236
|
+
for await (const event of streamDataStreamEvents(upstreamBody)) {
|
|
258
237
|
for (const mapped of mapRuntimeEventToAgUi(state, event)) {
|
|
259
238
|
prepareToolResultIfNeeded(mapped.event, mapped.payload);
|
|
260
239
|
if (!enqueueEvent(controller, mapped.event, mapped.payload)) {
|
|
@@ -276,7 +255,6 @@ async function createAgUiStreamResponse(options) {
|
|
|
276
255
|
});
|
|
277
256
|
}
|
|
278
257
|
finally {
|
|
279
|
-
await reader?.cancel().catch(() => undefined);
|
|
280
258
|
closeController(controller);
|
|
281
259
|
}
|
|
282
260
|
},
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AgUiRuntimeStreamEvent } from "./ag-ui-browser-encoder.js";
|
|
2
|
+
export declare function stripLeadingEmptyObjectPlaceholder(rawArgs: string): string;
|
|
3
|
+
export declare function mergeToolInputDelta(currentArguments: string, nextDelta: string): string;
|
|
4
|
+
export declare function mergeToolCallInput(currentArguments: string, nextInput: string): string;
|
|
5
|
+
export declare function parseToolInputObject(input: unknown): Record<string, unknown>;
|
|
6
|
+
export declare function parseDataStreamSseEvents(chunk: string): {
|
|
7
|
+
events: AgUiRuntimeStreamEvent[];
|
|
8
|
+
remainder: string;
|
|
9
|
+
};
|
|
10
|
+
export declare function streamDataStreamEvents(stream: ReadableStream<Uint8Array>): AsyncGenerator<AgUiRuntimeStreamEvent>;
|
|
11
|
+
//# sourceMappingURL=data-stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-stream.d.ts","sourceRoot":"","sources":["../../../src/src/agent/data-stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAMzE,wBAAgB,kCAAkC,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAQ1E;AAED,wBAAgB,mBAAmB,CAAC,gBAAgB,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAMvF;AAED,wBAAgB,kBAAkB,CAAC,gBAAgB,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CActF;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAiB5E;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,GAAG;IACvD,MAAM,EAAE,sBAAsB,EAAE,CAAC;IACjC,SAAS,EAAE,MAAM,CAAC;CACnB,CAoBA;AAED,wBAAuB,sBAAsB,CAC3C,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,GACjC,cAAc,CAAC,sBAAsB,CAAC,CAkCxC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
function isRecord(value) {
|
|
2
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3
|
+
}
|
|
4
|
+
export function stripLeadingEmptyObjectPlaceholder(rawArgs) {
|
|
5
|
+
let normalized = rawArgs.trim();
|
|
6
|
+
while (normalized.startsWith("{}") && normalized.slice(2).trimStart().startsWith("{")) {
|
|
7
|
+
normalized = normalized.slice(2).trimStart();
|
|
8
|
+
}
|
|
9
|
+
return normalized;
|
|
10
|
+
}
|
|
11
|
+
export function mergeToolInputDelta(currentArguments, nextDelta) {
|
|
12
|
+
if (currentArguments === "{}" && nextDelta.trimStart().startsWith("{")) {
|
|
13
|
+
return nextDelta;
|
|
14
|
+
}
|
|
15
|
+
return currentArguments + nextDelta;
|
|
16
|
+
}
|
|
17
|
+
export function mergeToolCallInput(currentArguments, nextInput) {
|
|
18
|
+
if (currentArguments.length === 0) {
|
|
19
|
+
return nextInput;
|
|
20
|
+
}
|
|
21
|
+
if (nextInput.trim() === "{}" && currentArguments.trim().startsWith("{")) {
|
|
22
|
+
return currentArguments;
|
|
23
|
+
}
|
|
24
|
+
if (currentArguments.trim() === "{}" && nextInput.trim().startsWith("{")) {
|
|
25
|
+
return nextInput;
|
|
26
|
+
}
|
|
27
|
+
return nextInput;
|
|
28
|
+
}
|
|
29
|
+
export function parseToolInputObject(input) {
|
|
30
|
+
if (isRecord(input)) {
|
|
31
|
+
return input;
|
|
32
|
+
}
|
|
33
|
+
if (typeof input === "string") {
|
|
34
|
+
try {
|
|
35
|
+
const parsed = JSON.parse(stripLeadingEmptyObjectPlaceholder(input));
|
|
36
|
+
if (isRecord(parsed)) {
|
|
37
|
+
return parsed;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return {};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return {};
|
|
45
|
+
}
|
|
46
|
+
export function parseDataStreamSseEvents(chunk) {
|
|
47
|
+
const blocks = chunk.split("\n\n");
|
|
48
|
+
const remainder = blocks.pop() ?? "";
|
|
49
|
+
const events = blocks.flatMap((block) => {
|
|
50
|
+
const dataLines = block.split("\n")
|
|
51
|
+
.filter((line) => line.startsWith("data:"))
|
|
52
|
+
.map((line) => line.slice(5).trimStart());
|
|
53
|
+
if (!dataLines.length) {
|
|
54
|
+
return [];
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
return [JSON.parse(dataLines.join("\n"))];
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return [];
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
return { events, remainder };
|
|
64
|
+
}
|
|
65
|
+
export async function* streamDataStreamEvents(stream) {
|
|
66
|
+
const reader = stream.getReader();
|
|
67
|
+
const decoder = new TextDecoder();
|
|
68
|
+
let remainder = "";
|
|
69
|
+
let completed = false;
|
|
70
|
+
try {
|
|
71
|
+
while (true) {
|
|
72
|
+
const { done, value } = await reader.read();
|
|
73
|
+
if (done) {
|
|
74
|
+
completed = true;
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
remainder += decoder.decode(value, { stream: true });
|
|
78
|
+
const parsed = parseDataStreamSseEvents(remainder);
|
|
79
|
+
remainder = parsed.remainder;
|
|
80
|
+
for (const event of parsed.events) {
|
|
81
|
+
yield event;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
remainder += decoder.decode();
|
|
85
|
+
const parsed = parseDataStreamSseEvents(`${remainder}\n\n`);
|
|
86
|
+
for (const event of parsed.events) {
|
|
87
|
+
yield event;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
finally {
|
|
91
|
+
if (!completed) {
|
|
92
|
+
await reader.cancel().catch(() => undefined);
|
|
93
|
+
}
|
|
94
|
+
reader.releaseLock();
|
|
95
|
+
}
|
|
96
|
+
}
|
package/esm/src/agent/index.d.ts
CHANGED
|
@@ -86,6 +86,7 @@ export { agentAsTool, createWorkflow, getAgent, getAgentsAsTools, getAllAgentIds
|
|
|
86
86
|
export { agent } from "./factory.js";
|
|
87
87
|
export { type AgUiRuntimeContextItem, AgUiRuntimeContextItemSchema, type AgUiRuntimeInjectedTool, AgUiRuntimeInjectedToolSchema, type AgUiRuntimeMessage, AgUiRuntimeMessageSchema, type AgUiRuntimeRequest, AgUiRuntimeRequestSchema, } from "./runtime-ag-ui-contract.js";
|
|
88
88
|
export { type AgUiBrowserEncodedEvent, type AgUiBrowserEncoderState, type AgUiBrowserRunFinishedMetadata, type AgUiRuntimeStreamEvent, createAgUiBrowserEncoderState, finalizeAgUiBrowserEvents, mapRuntimeStreamEventToAgUiBrowserEvents, } from "./ag-ui-browser-encoder.js";
|
|
89
|
+
export { mergeToolCallInput, mergeToolInputDelta, parseDataStreamSseEvents, parseToolInputObject, streamDataStreamEvents, stripLeadingEmptyObjectPlaceholder, } from "./data-stream.js";
|
|
89
90
|
export { expandAllowedRemoteToolNames, getProviderNativeToolNames, type ProviderNativeToolInventoryOptions, } from "./provider-native-tool-inventory.js";
|
|
90
91
|
export { type AgUiCancelHandlerOptions, type AgUiResumeHandlerOptions, type AgUiResumeSignal, AgUiResumeSignalSchema, createAgUiCancelHandler, createAgUiResumeHandler, } from "./ag-ui-run-control.js";
|
|
91
92
|
export { type AgUiContextItem, type AgUiHandlerConfigWithAgent, type AgUiHandlerOptions, type AgUiInjectedTool, type AgUiRequest, AgUiRequestSchema, createAgUiHandler, } from "./ag-ui-handler.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/src/agent/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+EG;AACH,OAAO,yBAAyB,CAAC;AAGjC,YAAY,EACV,KAAK,EACL,WAAW,EACX,YAAY,EACZ,eAAe,EACf,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,UAAU,EACV,YAAY,EACZ,OAAO,IAAI,YAAY,EACvB,WAAW,EACX,aAAa,EACb,WAAW,EACX,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,EACnB,sBAAsB,EACtB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,cAAc,EACd,QAAQ,EACR,YAAY,EACZ,oBAAoB,EACpB,qBAAqB,EACrB,cAAc,GACf,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEnF,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,YAAY,EACZ,iBAAiB,EACjB,KAAK,MAAM,EACX,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,WAAW,EACX,KAAK,iBAAiB,EACtB,aAAa,GACd,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,WAAW,EACX,cAAc,EACd,QAAQ,EACR,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,YAAY,GAClB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EACL,KAAK,sBAAsB,EAC3B,4BAA4B,EAC5B,KAAK,uBAAuB,EAC5B,6BAA6B,EAC7B,KAAK,kBAAkB,EACvB,wBAAwB,EACxB,K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AK,gBAAgB,EACrB,KAAK,wBAAwB,EAC7B,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/src/agent/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+EG;AACH,OAAO,yBAAyB,CAAC;AAGjC,YAAY,EACV,KAAK,EACL,WAAW,EACX,YAAY,EACZ,eAAe,EACf,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,UAAU,EACV,YAAY,EACZ,OAAO,IAAI,YAAY,EACvB,WAAW,EACX,aAAa,EACb,WAAW,EACX,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,EACnB,sBAAsB,EACtB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,cAAc,EACd,QAAQ,EACR,YAAY,EACZ,oBAAoB,EACpB,qBAAqB,EACrB,cAAc,GACf,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEnF,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,YAAY,EACZ,iBAAiB,EACjB,KAAK,MAAM,EACX,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,WAAW,EACX,KAAK,iBAAiB,EACtB,aAAa,GACd,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,WAAW,EACX,cAAc,EACd,QAAQ,EACR,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,YAAY,GAClB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EACL,KAA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C,KAAK,6BAA6B,EAClC,KAAK,0BAA0B,EAC/B,KAAK,uBAAuB,EAC5B,KAAK,kBAAkB,EACvB,iBAAiB,GAClB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,YAAY,EACZ,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EACjB,uBAAuB,EACvB,KAAK,8BAA8B,EACnC,KAAK,gBAAgB,EACrB,KAAK,wBAAwB,EAC7B,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,oBAAoB,CAAC"}
|
package/esm/src/agent/index.js
CHANGED
|
@@ -85,6 +85,7 @@ export { agentAsTool, createWorkflow, getAgent, getAgentsAsTools, getAllAgentIds
|
|
|
85
85
|
export { agent } from "./factory.js";
|
|
86
86
|
export { AgUiRuntimeContextItemSchema, AgUiRuntimeInjectedToolSchema, AgUiRuntimeMessageSchema, AgUiRuntimeRequestSchema, } from "./runtime-ag-ui-contract.js";
|
|
87
87
|
export { createAgUiBrowserEncoderState, finalizeAgUiBrowserEvents, mapRuntimeStreamEventToAgUiBrowserEvents, } from "./ag-ui-browser-encoder.js";
|
|
88
|
+
export { mergeToolCallInput, mergeToolInputDelta, parseDataStreamSseEvents, parseToolInputObject, streamDataStreamEvents, stripLeadingEmptyObjectPlaceholder, } from "./data-stream.js";
|
|
88
89
|
export { expandAllowedRemoteToolNames, getProviderNativeToolNames, } from "./provider-native-tool-inventory.js";
|
|
89
90
|
export { AgUiResumeSignalSchema, createAgUiCancelHandler, createAgUiResumeHandler, } from "./ag-ui-run-control.js";
|
|
90
91
|
export { AgUiRequestSchema, createAgUiHandler, } from "./ag-ui-handler.js";
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
1
|
+
{"version":3,"file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C;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,CAqPf"}
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* @module agent/runtime/chat-stream-handler
|
|
9
9
|
*/
|
|
10
10
|
import { sendSSE } from "./sse-utils.js";
|
|
11
|
+
import { mergeToolCallInput, mergeToolInputDelta, parseToolInputObject } from "../data-stream.js";
|
|
11
12
|
import { isDynamicTool } from "./tool-helpers.js";
|
|
12
13
|
import { serverLogger } from "../../utils/index.js";
|
|
13
14
|
import { isAnyDebugEnabled } from "../../utils/constants/env.js";
|
|
@@ -24,41 +25,6 @@ function normalizeToolInputString(input) {
|
|
|
24
25
|
}
|
|
25
26
|
return JSON.stringify(input ?? null) ?? "null";
|
|
26
27
|
}
|
|
27
|
-
function mergeToolInputDelta(currentArguments, nextDelta) {
|
|
28
|
-
if (currentArguments === "{}" && nextDelta.trimStart().startsWith("{")) {
|
|
29
|
-
return nextDelta;
|
|
30
|
-
}
|
|
31
|
-
return currentArguments + nextDelta;
|
|
32
|
-
}
|
|
33
|
-
function mergeToolCallInput(currentArguments, nextInput) {
|
|
34
|
-
if (currentArguments.length === 0) {
|
|
35
|
-
return nextInput;
|
|
36
|
-
}
|
|
37
|
-
if (nextInput.trim() === "{}" && currentArguments.trim().startsWith("{")) {
|
|
38
|
-
return currentArguments;
|
|
39
|
-
}
|
|
40
|
-
if (currentArguments.trim() === "{}" && nextInput.trim().startsWith("{")) {
|
|
41
|
-
return nextInput;
|
|
42
|
-
}
|
|
43
|
-
return nextInput;
|
|
44
|
-
}
|
|
45
|
-
function normalizeToolInputObject(input) {
|
|
46
|
-
if (isRecord(input)) {
|
|
47
|
-
return input;
|
|
48
|
-
}
|
|
49
|
-
if (typeof input === "string") {
|
|
50
|
-
try {
|
|
51
|
-
const parsed = JSON.parse(input);
|
|
52
|
-
if (isRecord(parsed)) {
|
|
53
|
-
return parsed;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
catch {
|
|
57
|
-
return {};
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return {};
|
|
61
|
-
}
|
|
62
28
|
function summarizeDebugValue(value) {
|
|
63
29
|
if (value instanceof Error) {
|
|
64
30
|
return {
|
|
@@ -206,7 +172,7 @@ export function processStream(result, state, controller, encoder, textPartId, ca
|
|
|
206
172
|
dynamic: typedPart.dynamic,
|
|
207
173
|
});
|
|
208
174
|
const dynamic = isDynamicTool(typedPart.toolName);
|
|
209
|
-
const inputObj =
|
|
175
|
+
const inputObj = parseToolInputObject(typedPart.input);
|
|
210
176
|
sendSSE(controller, encoder, {
|
|
211
177
|
type: "tool-input-available",
|
|
212
178
|
toolCallId: toolId,
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import "../../_dnt.polyfills.js";
|
|
2
|
+
import type { ChatStreamEvent } from "./protocol.js";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
type ToolCallState = {
|
|
5
|
+
toolName: string;
|
|
6
|
+
argsText: string;
|
|
7
|
+
};
|
|
8
|
+
export type ParsedSseEvent = {
|
|
9
|
+
id: number | null;
|
|
10
|
+
event: string | null;
|
|
11
|
+
data: string;
|
|
12
|
+
};
|
|
13
|
+
export type AgUiDecodedEvent = {
|
|
14
|
+
eventId: number | null;
|
|
15
|
+
wireEvent: AgUiWireEvent;
|
|
16
|
+
chatEvents: ChatStreamEvent[];
|
|
17
|
+
};
|
|
18
|
+
export type AgUiDecodedChunk = {
|
|
19
|
+
events: AgUiDecodedEvent[];
|
|
20
|
+
remainder: string;
|
|
21
|
+
};
|
|
22
|
+
export type AgUiChatEventDecoderState = {
|
|
23
|
+
remainder: string;
|
|
24
|
+
lastEventId: number;
|
|
25
|
+
toolCalls: Map<string, ToolCallState>;
|
|
26
|
+
reasoningFallbackIndex: number;
|
|
27
|
+
activeFallbackReasoningPartId: string | null;
|
|
28
|
+
};
|
|
29
|
+
export declare const AgUiRunFinishedMetadataSchema: z.ZodObject<{
|
|
30
|
+
provider: z.ZodOptional<z.ZodString>;
|
|
31
|
+
model: z.ZodOptional<z.ZodString>;
|
|
32
|
+
inputTokens: z.ZodOptional<z.ZodNumber>;
|
|
33
|
+
outputTokens: z.ZodOptional<z.ZodNumber>;
|
|
34
|
+
totalTokens: z.ZodOptional<z.ZodNumber>;
|
|
35
|
+
cachedInputTokens: z.ZodOptional<z.ZodNumber>;
|
|
36
|
+
reasoningTokens: z.ZodOptional<z.ZodNumber>;
|
|
37
|
+
finishReason: z.ZodOptional<z.ZodString>;
|
|
38
|
+
providerRequestId: z.ZodOptional<z.ZodString>;
|
|
39
|
+
}, z.core.$strip>;
|
|
40
|
+
export declare const AgUiSnapshotToolCallSchema: z.ZodObject<{
|
|
41
|
+
id: z.ZodString;
|
|
42
|
+
type: z.ZodLiteral<"function">;
|
|
43
|
+
function: z.ZodObject<{
|
|
44
|
+
name: z.ZodString;
|
|
45
|
+
arguments: z.ZodString;
|
|
46
|
+
}, z.core.$strip>;
|
|
47
|
+
encryptedValue: z.ZodOptional<z.ZodString>;
|
|
48
|
+
}, z.core.$strip>;
|
|
49
|
+
export declare const AgUiSnapshotMessageSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
50
|
+
id: z.ZodString;
|
|
51
|
+
role: z.ZodLiteral<"assistant">;
|
|
52
|
+
content: z.ZodOptional<z.ZodString>;
|
|
53
|
+
name: z.ZodOptional<z.ZodString>;
|
|
54
|
+
encryptedValue: z.ZodOptional<z.ZodString>;
|
|
55
|
+
toolCalls: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
56
|
+
id: z.ZodString;
|
|
57
|
+
type: z.ZodLiteral<"function">;
|
|
58
|
+
function: z.ZodObject<{
|
|
59
|
+
name: z.ZodString;
|
|
60
|
+
arguments: z.ZodString;
|
|
61
|
+
}, z.core.$strip>;
|
|
62
|
+
encryptedValue: z.ZodOptional<z.ZodString>;
|
|
63
|
+
}, z.core.$strip>>>;
|
|
64
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
65
|
+
id: z.ZodString;
|
|
66
|
+
role: z.ZodLiteral<"user">;
|
|
67
|
+
content: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
68
|
+
type: z.ZodLiteral<"text">;
|
|
69
|
+
text: z.ZodString;
|
|
70
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
71
|
+
type: z.ZodLiteral<"binary">;
|
|
72
|
+
mimeType: z.ZodString;
|
|
73
|
+
id: z.ZodOptional<z.ZodString>;
|
|
74
|
+
url: z.ZodOptional<z.ZodString>;
|
|
75
|
+
data: z.ZodOptional<z.ZodString>;
|
|
76
|
+
filename: z.ZodOptional<z.ZodString>;
|
|
77
|
+
}, z.core.$strip>], "type">>]>;
|
|
78
|
+
name: z.ZodOptional<z.ZodString>;
|
|
79
|
+
encryptedValue: z.ZodOptional<z.ZodString>;
|
|
80
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
81
|
+
id: z.ZodString;
|
|
82
|
+
role: z.ZodLiteral<"tool">;
|
|
83
|
+
toolCallId: z.ZodString;
|
|
84
|
+
content: z.ZodString;
|
|
85
|
+
error: z.ZodOptional<z.ZodString>;
|
|
86
|
+
encryptedValue: z.ZodOptional<z.ZodString>;
|
|
87
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
88
|
+
id: z.ZodString;
|
|
89
|
+
role: z.ZodLiteral<"reasoning">;
|
|
90
|
+
content: z.ZodString;
|
|
91
|
+
name: z.ZodOptional<z.ZodString>;
|
|
92
|
+
encryptedValue: z.ZodOptional<z.ZodString>;
|
|
93
|
+
}, z.core.$strip>], "role">;
|
|
94
|
+
export declare const AgUiWireEventNameSchema: z.ZodEnum<{
|
|
95
|
+
ToolCallArgs: "ToolCallArgs";
|
|
96
|
+
ToolCallEnd: "ToolCallEnd";
|
|
97
|
+
ToolCallResult: "ToolCallResult";
|
|
98
|
+
Custom: "Custom";
|
|
99
|
+
ReasoningMessageStart: "ReasoningMessageStart";
|
|
100
|
+
ReasoningMessageContent: "ReasoningMessageContent";
|
|
101
|
+
ReasoningMessageEnd: "ReasoningMessageEnd";
|
|
102
|
+
TextMessageStart: "TextMessageStart";
|
|
103
|
+
TextMessageContent: "TextMessageContent";
|
|
104
|
+
TextMessageEnd: "TextMessageEnd";
|
|
105
|
+
ToolCallStart: "ToolCallStart";
|
|
106
|
+
RunError: "RunError";
|
|
107
|
+
RunFinished: "RunFinished";
|
|
108
|
+
RunStarted: "RunStarted";
|
|
109
|
+
StateSnapshot: "StateSnapshot";
|
|
110
|
+
MessagesSnapshot: "MessagesSnapshot";
|
|
111
|
+
ToolCallChunk: "ToolCallChunk";
|
|
112
|
+
StateDelta: "StateDelta";
|
|
113
|
+
}>;
|
|
114
|
+
export declare const AgUiWireEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
115
|
+
eventName: z.ZodLiteral<"RunStarted">;
|
|
116
|
+
payload: z.ZodObject<{
|
|
117
|
+
runId: z.ZodOptional<z.ZodString>;
|
|
118
|
+
threadId: z.ZodOptional<z.ZodString>;
|
|
119
|
+
agentId: z.ZodOptional<z.ZodString>;
|
|
120
|
+
}, z.core.$strip>;
|
|
121
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
122
|
+
eventName: z.ZodLiteral<"Custom">;
|
|
123
|
+
payload: z.ZodObject<{
|
|
124
|
+
name: z.ZodString;
|
|
125
|
+
value: z.ZodUnknown;
|
|
126
|
+
}, z.core.$strip>;
|
|
127
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
128
|
+
eventName: z.ZodLiteral<"TextMessageStart">;
|
|
129
|
+
payload: z.ZodObject<{
|
|
130
|
+
messageId: z.ZodString;
|
|
131
|
+
id: z.ZodOptional<z.ZodString>;
|
|
132
|
+
contentId: z.ZodOptional<z.ZodString>;
|
|
133
|
+
role: z.ZodOptional<z.ZodString>;
|
|
134
|
+
}, z.core.$strip>;
|
|
135
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
136
|
+
eventName: z.ZodLiteral<"TextMessageContent">;
|
|
137
|
+
payload: z.ZodObject<{
|
|
138
|
+
messageId: z.ZodString;
|
|
139
|
+
id: z.ZodOptional<z.ZodString>;
|
|
140
|
+
contentId: z.ZodOptional<z.ZodString>;
|
|
141
|
+
delta: z.ZodString;
|
|
142
|
+
}, z.core.$strip>;
|
|
143
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
144
|
+
eventName: z.ZodLiteral<"TextMessageEnd">;
|
|
145
|
+
payload: z.ZodObject<{
|
|
146
|
+
messageId: z.ZodString;
|
|
147
|
+
id: z.ZodOptional<z.ZodString>;
|
|
148
|
+
contentId: z.ZodOptional<z.ZodString>;
|
|
149
|
+
}, z.core.$strip>;
|
|
150
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
151
|
+
eventName: z.ZodLiteral<"ToolCallStart">;
|
|
152
|
+
payload: z.ZodObject<{
|
|
153
|
+
toolCallId: z.ZodString;
|
|
154
|
+
toolCallName: z.ZodString;
|
|
155
|
+
}, z.core.$strip>;
|
|
156
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
157
|
+
eventName: z.ZodLiteral<"ToolCallArgs">;
|
|
158
|
+
payload: z.ZodObject<{
|
|
159
|
+
toolCallId: z.ZodString;
|
|
160
|
+
delta: z.ZodString;
|
|
161
|
+
}, z.core.$strip>;
|
|
162
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
163
|
+
eventName: z.ZodLiteral<"ToolCallChunk">;
|
|
164
|
+
payload: z.ZodObject<{
|
|
165
|
+
toolCallId: z.ZodString;
|
|
166
|
+
delta: z.ZodString;
|
|
167
|
+
}, z.core.$strip>;
|
|
168
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
169
|
+
eventName: z.ZodLiteral<"ToolCallEnd">;
|
|
170
|
+
payload: z.ZodObject<{
|
|
171
|
+
toolCallId: z.ZodString;
|
|
172
|
+
}, z.core.$strip>;
|
|
173
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
174
|
+
eventName: z.ZodLiteral<"ToolCallResult">;
|
|
175
|
+
payload: z.ZodObject<{
|
|
176
|
+
messageId: z.ZodOptional<z.ZodString>;
|
|
177
|
+
toolCallId: z.ZodString;
|
|
178
|
+
content: z.ZodOptional<z.ZodUnknown>;
|
|
179
|
+
result: z.ZodOptional<z.ZodUnknown>;
|
|
180
|
+
role: z.ZodOptional<z.ZodLiteral<"tool">>;
|
|
181
|
+
isError: z.ZodOptional<z.ZodBoolean>;
|
|
182
|
+
}, z.core.$strip>;
|
|
183
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
184
|
+
eventName: z.ZodLiteral<"StateSnapshot">;
|
|
185
|
+
payload: z.ZodObject<{
|
|
186
|
+
snapshot: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
187
|
+
}, z.core.$strip>;
|
|
188
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
189
|
+
eventName: z.ZodLiteral<"MessagesSnapshot">;
|
|
190
|
+
payload: z.ZodObject<{
|
|
191
|
+
messages: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
192
|
+
id: z.ZodString;
|
|
193
|
+
role: z.ZodLiteral<"assistant">;
|
|
194
|
+
content: z.ZodOptional<z.ZodString>;
|
|
195
|
+
name: z.ZodOptional<z.ZodString>;
|
|
196
|
+
encryptedValue: z.ZodOptional<z.ZodString>;
|
|
197
|
+
toolCalls: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
198
|
+
id: z.ZodString;
|
|
199
|
+
type: z.ZodLiteral<"function">;
|
|
200
|
+
function: z.ZodObject<{
|
|
201
|
+
name: z.ZodString;
|
|
202
|
+
arguments: z.ZodString;
|
|
203
|
+
}, z.core.$strip>;
|
|
204
|
+
encryptedValue: z.ZodOptional<z.ZodString>;
|
|
205
|
+
}, z.core.$strip>>>;
|
|
206
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
207
|
+
id: z.ZodString;
|
|
208
|
+
role: z.ZodLiteral<"user">;
|
|
209
|
+
content: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
210
|
+
type: z.ZodLiteral<"text">;
|
|
211
|
+
text: z.ZodString;
|
|
212
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
213
|
+
type: z.ZodLiteral<"binary">;
|
|
214
|
+
mimeType: z.ZodString;
|
|
215
|
+
id: z.ZodOptional<z.ZodString>;
|
|
216
|
+
url: z.ZodOptional<z.ZodString>;
|
|
217
|
+
data: z.ZodOptional<z.ZodString>;
|
|
218
|
+
filename: z.ZodOptional<z.ZodString>;
|
|
219
|
+
}, z.core.$strip>], "type">>]>;
|
|
220
|
+
name: z.ZodOptional<z.ZodString>;
|
|
221
|
+
encryptedValue: z.ZodOptional<z.ZodString>;
|
|
222
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
223
|
+
id: z.ZodString;
|
|
224
|
+
role: z.ZodLiteral<"tool">;
|
|
225
|
+
toolCallId: z.ZodString;
|
|
226
|
+
content: z.ZodString;
|
|
227
|
+
error: z.ZodOptional<z.ZodString>;
|
|
228
|
+
encryptedValue: z.ZodOptional<z.ZodString>;
|
|
229
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
230
|
+
id: z.ZodString;
|
|
231
|
+
role: z.ZodLiteral<"reasoning">;
|
|
232
|
+
content: z.ZodString;
|
|
233
|
+
name: z.ZodOptional<z.ZodString>;
|
|
234
|
+
encryptedValue: z.ZodOptional<z.ZodString>;
|
|
235
|
+
}, z.core.$strip>], "role">>;
|
|
236
|
+
}, z.core.$strip>;
|
|
237
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
238
|
+
eventName: z.ZodLiteral<"ReasoningMessageStart">;
|
|
239
|
+
payload: z.ZodObject<{
|
|
240
|
+
id: z.ZodOptional<z.ZodString>;
|
|
241
|
+
messageId: z.ZodOptional<z.ZodString>;
|
|
242
|
+
role: z.ZodOptional<z.ZodString>;
|
|
243
|
+
}, z.core.$strip>;
|
|
244
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
245
|
+
eventName: z.ZodLiteral<"ReasoningMessageContent">;
|
|
246
|
+
payload: z.ZodObject<{
|
|
247
|
+
id: z.ZodOptional<z.ZodString>;
|
|
248
|
+
messageId: z.ZodOptional<z.ZodString>;
|
|
249
|
+
delta: z.ZodString;
|
|
250
|
+
}, z.core.$strip>;
|
|
251
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
252
|
+
eventName: z.ZodLiteral<"ReasoningMessageEnd">;
|
|
253
|
+
payload: z.ZodObject<{
|
|
254
|
+
id: z.ZodOptional<z.ZodString>;
|
|
255
|
+
messageId: z.ZodOptional<z.ZodString>;
|
|
256
|
+
}, z.core.$strip>;
|
|
257
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
258
|
+
eventName: z.ZodLiteral<"StateDelta">;
|
|
259
|
+
payload: z.ZodObject<{
|
|
260
|
+
delta: z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodUnknown>, z.ZodArray<z.ZodObject<{
|
|
261
|
+
op: z.ZodEnum<{
|
|
262
|
+
copy: "copy";
|
|
263
|
+
test: "test";
|
|
264
|
+
remove: "remove";
|
|
265
|
+
replace: "replace";
|
|
266
|
+
add: "add";
|
|
267
|
+
move: "move";
|
|
268
|
+
}>;
|
|
269
|
+
path: z.ZodString;
|
|
270
|
+
from: z.ZodOptional<z.ZodString>;
|
|
271
|
+
value: z.ZodOptional<z.ZodUnknown>;
|
|
272
|
+
}, z.core.$strip>>]>;
|
|
273
|
+
}, z.core.$strip>;
|
|
274
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
275
|
+
eventName: z.ZodLiteral<"RunFinished">;
|
|
276
|
+
payload: z.ZodObject<{
|
|
277
|
+
metadata: z.ZodOptional<z.ZodObject<{
|
|
278
|
+
provider: z.ZodOptional<z.ZodString>;
|
|
279
|
+
model: z.ZodOptional<z.ZodString>;
|
|
280
|
+
inputTokens: z.ZodOptional<z.ZodNumber>;
|
|
281
|
+
outputTokens: z.ZodOptional<z.ZodNumber>;
|
|
282
|
+
totalTokens: z.ZodOptional<z.ZodNumber>;
|
|
283
|
+
cachedInputTokens: z.ZodOptional<z.ZodNumber>;
|
|
284
|
+
reasoningTokens: z.ZodOptional<z.ZodNumber>;
|
|
285
|
+
finishReason: z.ZodOptional<z.ZodString>;
|
|
286
|
+
providerRequestId: z.ZodOptional<z.ZodString>;
|
|
287
|
+
}, z.core.$strip>>;
|
|
288
|
+
}, z.core.$strip>;
|
|
289
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
290
|
+
eventName: z.ZodLiteral<"RunError">;
|
|
291
|
+
payload: z.ZodObject<{
|
|
292
|
+
code: z.ZodOptional<z.ZodString>;
|
|
293
|
+
message: z.ZodOptional<z.ZodString>;
|
|
294
|
+
}, z.core.$strip>;
|
|
295
|
+
}, z.core.$strip>], "eventName">;
|
|
296
|
+
export type AgUiRunFinishedMetadata = z.infer<typeof AgUiRunFinishedMetadataSchema>;
|
|
297
|
+
export type AgUiSnapshotMessage = z.infer<typeof AgUiSnapshotMessageSchema>;
|
|
298
|
+
export type AgUiWireEventName = z.infer<typeof AgUiWireEventNameSchema>;
|
|
299
|
+
export type AgUiWireEvent = z.infer<typeof AgUiWireEventSchema>;
|
|
300
|
+
export declare function parseSseEvent(raw: string): ParsedSseEvent;
|
|
301
|
+
export declare function createAgUiChatEventDecoderState(input?: {
|
|
302
|
+
lastEventId?: number;
|
|
303
|
+
}): AgUiChatEventDecoderState;
|
|
304
|
+
export declare function decodeAgUiSseChunk(state: AgUiChatEventDecoderState, chunk: string): AgUiDecodedChunk;
|
|
305
|
+
export declare function flushAgUiSseChunk(state: AgUiChatEventDecoderState): AgUiDecodedChunk;
|
|
306
|
+
export {};
|
|
307
|
+
//# sourceMappingURL=ag-ui.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ag-ui.d.ts","sourceRoot":"","sources":["../../../src/src/chat/ag-ui.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AAEjC,OAAO,KAAK,EAAoB,eAAe,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAcxB,KAAK,aAAa,GAAG;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAClB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,SAAS,EAAE,aAAa,CAAC;IACzB,UAAU,EAAE,eAAe,EAAE,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE,gBAAgB,EAAE,CAAC;IAC3B,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IACtC,sBAAsB,EAAE,MAAM,CAAC;IAC/B,6BAA6B,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9C,CAAC;AAEF,eAAO,MAAM,6BAA6B;;;;;;;;;;iBAUxC,CAAC;AAEH,eAAO,MAAM,0BAA0B;;;;;;;;iBAQrC,CAA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