veryfront 0.1.196 → 0.1.198
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/chat/ag-ui.d.ts +11 -0
- package/esm/src/chat/ag-ui.d.ts.map +1 -1
- package/esm/src/chat/ag-ui.js +14 -2
- package/esm/src/provider/runtime-loader.d.ts.map +1 -1
- package/esm/src/provider/runtime-loader.js +148 -45
- 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/deno.js +1 -1
- package/src/src/chat/ag-ui.ts +27 -2
- package/src/src/provider/runtime-loader.ts +166 -46
- package/src/src/utils/version-constant.ts +1 -1
package/esm/deno.js
CHANGED
package/esm/src/chat/ag-ui.d.ts
CHANGED
|
@@ -18,12 +18,18 @@ export type AgUiDecodedChunk = {
|
|
|
18
18
|
events: AgUiDecodedEvent[];
|
|
19
19
|
remainder: string;
|
|
20
20
|
};
|
|
21
|
+
export type AgUiDecoderValidationMode = "permissive" | "strict";
|
|
21
22
|
export type AgUiChatEventDecoderState = {
|
|
22
23
|
remainder: string;
|
|
23
24
|
lastEventId: number;
|
|
24
25
|
toolCalls: Map<string, ToolCallState>;
|
|
25
26
|
reasoningFallbackIndex: number;
|
|
26
27
|
activeFallbackReasoningPartId: string | null;
|
|
28
|
+
validationMode: AgUiDecoderValidationMode;
|
|
29
|
+
onInvalidJson: ((details: {
|
|
30
|
+
eventName: string | null;
|
|
31
|
+
dataLength: number;
|
|
32
|
+
}) => void) | null;
|
|
27
33
|
};
|
|
28
34
|
export declare const AgUiRunFinishedMetadataSchema: z.ZodObject<{
|
|
29
35
|
provider: z.ZodOptional<z.ZodString>;
|
|
@@ -299,6 +305,11 @@ export type AgUiWireEvent = z.infer<typeof AgUiWireEventSchema>;
|
|
|
299
305
|
export declare function parseSseEvent(raw: string): ParsedSseEvent;
|
|
300
306
|
export declare function createAgUiChatEventDecoderState(input?: {
|
|
301
307
|
lastEventId?: number;
|
|
308
|
+
validationMode?: AgUiDecoderValidationMode;
|
|
309
|
+
onInvalidJson?: (details: {
|
|
310
|
+
eventName: string | null;
|
|
311
|
+
dataLength: number;
|
|
312
|
+
}) => void;
|
|
302
313
|
}): AgUiChatEventDecoderState;
|
|
303
314
|
export declare function decodeAgUiSseChunk(state: AgUiChatEventDecoderState, chunk: string): AgUiDecodedChunk;
|
|
304
315
|
export declare function flushAgUiSseChunk(state: AgUiChatEventDecoderState): AgUiDecodedChunk;
|
|
@@ -1 +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,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AAC,UAAU,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;CAChF,GACL,yBAAyB,CAU3B;AAED,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,yBAAyB,EAChC,KAAK,EAAE,MAAM,GACZ,gBAAgB,CAuClB;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,yBAAyB,GAAG,gBAAgB,CAWpF"}
|
package/esm/src/chat/ag-ui.js
CHANGED
|
@@ -361,7 +361,7 @@ function isCommentOnlySseFrame(raw) {
|
|
|
361
361
|
.split("\n")
|
|
362
362
|
.every((line) => line.trim().length === 0 || line.trimStart().startsWith(":"));
|
|
363
363
|
}
|
|
364
|
-
function parseAgUiWireEvent(frame) {
|
|
364
|
+
function parseAgUiWireEvent(frame, input) {
|
|
365
365
|
if (frame.data === "[DONE]" || !frame.event || !frame.data) {
|
|
366
366
|
return null;
|
|
367
367
|
}
|
|
@@ -374,6 +374,10 @@ function parseAgUiWireEvent(frame) {
|
|
|
374
374
|
payload = JSON.parse(frame.data);
|
|
375
375
|
}
|
|
376
376
|
catch {
|
|
377
|
+
input.onInvalidJson?.({
|
|
378
|
+
eventName: frame.event,
|
|
379
|
+
dataLength: frame.data.length,
|
|
380
|
+
});
|
|
377
381
|
return null;
|
|
378
382
|
}
|
|
379
383
|
if (!isRecord(payload)) {
|
|
@@ -383,6 +387,9 @@ function parseAgUiWireEvent(frame) {
|
|
|
383
387
|
eventName: eventName.data,
|
|
384
388
|
payload,
|
|
385
389
|
});
|
|
390
|
+
if (!parsed.success && input.validationMode === "strict") {
|
|
391
|
+
throw new Error(`Malformed AG-UI event payload for ${eventName.data}`);
|
|
392
|
+
}
|
|
386
393
|
return parsed.success ? parsed.data : null;
|
|
387
394
|
}
|
|
388
395
|
function mapWireEventToChatEvents(state, wireEvent) {
|
|
@@ -563,6 +570,8 @@ export function createAgUiChatEventDecoderState(input = {}) {
|
|
|
563
570
|
toolCalls: new Map(),
|
|
564
571
|
reasoningFallbackIndex: 0,
|
|
565
572
|
activeFallbackReasoningPartId: null,
|
|
573
|
+
validationMode: input.validationMode ?? "permissive",
|
|
574
|
+
onInvalidJson: input.onInvalidJson ?? null,
|
|
566
575
|
};
|
|
567
576
|
}
|
|
568
577
|
export function decodeAgUiSseChunk(state, chunk) {
|
|
@@ -581,7 +590,10 @@ export function decodeAgUiSseChunk(state, chunk) {
|
|
|
581
590
|
}
|
|
582
591
|
state.lastEventId = frame.id;
|
|
583
592
|
}
|
|
584
|
-
const wireEvent = parseAgUiWireEvent(frame
|
|
593
|
+
const wireEvent = parseAgUiWireEvent(frame, {
|
|
594
|
+
validationMode: state.validationMode,
|
|
595
|
+
onInvalidJson: state.onInvalidJson,
|
|
596
|
+
});
|
|
585
597
|
if (!wireEvent) {
|
|
586
598
|
continue;
|
|
587
599
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-loader.d.ts","sourceRoot":"","sources":["../../../src/src/provider/runtime-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEjE,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;CACjC;AAED,MAAM,WAAW,sBAAsB;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;CACjC;AAED,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,K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,mBAAmB,EAC3B,OAAO,EAAE,MAAM,GACd,gBAAgB,CAgDlB"}
|
|
@@ -440,6 +440,7 @@ async function* streamAnthropicCompatibleParts(stream) {
|
|
|
440
440
|
const decoder = new TextDecoder();
|
|
441
441
|
let buffer = "";
|
|
442
442
|
const toolCalls = new Map();
|
|
443
|
+
const reasoningBlocks = new Map();
|
|
443
444
|
let finishReason = null;
|
|
444
445
|
let usage;
|
|
445
446
|
for await (const chunk of stream) {
|
|
@@ -466,6 +467,22 @@ async function* streamAnthropicCompatibleParts(stream) {
|
|
|
466
467
|
yield { type: "text-delta", delta: contentBlock.text };
|
|
467
468
|
continue;
|
|
468
469
|
}
|
|
470
|
+
if (blockType === "thinking") {
|
|
471
|
+
const reasoningId = `thinking-${index}`;
|
|
472
|
+
reasoningBlocks.set(index, { id: reasoningId });
|
|
473
|
+
yield {
|
|
474
|
+
type: "reasoning-start",
|
|
475
|
+
id: reasoningId,
|
|
476
|
+
};
|
|
477
|
+
if (typeof contentBlock?.thinking === "string" && contentBlock.thinking.length > 0) {
|
|
478
|
+
yield {
|
|
479
|
+
type: "reasoning-delta",
|
|
480
|
+
id: reasoningId,
|
|
481
|
+
delta: contentBlock.thinking,
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
continue;
|
|
485
|
+
}
|
|
469
486
|
if ((blockType === "tool_use" || blockType === "server_tool_use") &&
|
|
470
487
|
typeof contentBlock?.id === "string" &&
|
|
471
488
|
typeof contentBlock?.name === "string") {
|
|
@@ -527,6 +544,19 @@ async function* streamAnthropicCompatibleParts(stream) {
|
|
|
527
544
|
yield { type: "text-delta", delta: delta.text };
|
|
528
545
|
continue;
|
|
529
546
|
}
|
|
547
|
+
if (deltaType === "thinking_delta" && typeof delta?.thinking === "string" &&
|
|
548
|
+
delta.thinking.length > 0) {
|
|
549
|
+
const current = reasoningBlocks.get(index);
|
|
550
|
+
if (!current) {
|
|
551
|
+
continue;
|
|
552
|
+
}
|
|
553
|
+
yield {
|
|
554
|
+
type: "reasoning-delta",
|
|
555
|
+
id: current.id,
|
|
556
|
+
delta: delta.thinking,
|
|
557
|
+
};
|
|
558
|
+
continue;
|
|
559
|
+
}
|
|
530
560
|
if (deltaType === "input_json_delta" && typeof delta?.partial_json === "string") {
|
|
531
561
|
const current = toolCalls.get(index);
|
|
532
562
|
if (!current) {
|
|
@@ -543,6 +573,15 @@ async function* streamAnthropicCompatibleParts(stream) {
|
|
|
543
573
|
}
|
|
544
574
|
if (eventType === "content_block_stop") {
|
|
545
575
|
const index = typeof record?.index === "number" ? record.index : 0;
|
|
576
|
+
const reasoning = reasoningBlocks.get(index);
|
|
577
|
+
if (reasoning) {
|
|
578
|
+
yield {
|
|
579
|
+
type: "reasoning-end",
|
|
580
|
+
id: reasoning.id,
|
|
581
|
+
};
|
|
582
|
+
reasoningBlocks.delete(index);
|
|
583
|
+
continue;
|
|
584
|
+
}
|
|
546
585
|
const current = toolCalls.get(index);
|
|
547
586
|
if (!current) {
|
|
548
587
|
continue;
|
|
@@ -871,6 +910,8 @@ async function* streamGoogleCompatibleParts(stream) {
|
|
|
871
910
|
const decoder = new TextDecoder();
|
|
872
911
|
let buffer = "";
|
|
873
912
|
const seenToolCalls = new Set();
|
|
913
|
+
let reasoningId = null;
|
|
914
|
+
let reasoningIndex = 0;
|
|
874
915
|
let finishReason = null;
|
|
875
916
|
let usage;
|
|
876
917
|
for await (const chunk of stream) {
|
|
@@ -888,6 +929,29 @@ async function* streamGoogleCompatibleParts(stream) {
|
|
|
888
929
|
finishReason = normalizedFinishReason;
|
|
889
930
|
}
|
|
890
931
|
for (const [index, part] of extractGoogleCandidateParts(event).entries()) {
|
|
932
|
+
const isThought = part.thought === true;
|
|
933
|
+
if (isThought && typeof part.text === "string" && part.text.length > 0) {
|
|
934
|
+
if (!reasoningId) {
|
|
935
|
+
reasoningId = `reasoning-${reasoningIndex++}`;
|
|
936
|
+
yield {
|
|
937
|
+
type: "reasoning-start",
|
|
938
|
+
id: reasoningId,
|
|
939
|
+
};
|
|
940
|
+
}
|
|
941
|
+
yield {
|
|
942
|
+
type: "reasoning-delta",
|
|
943
|
+
id: reasoningId,
|
|
944
|
+
delta: part.text,
|
|
945
|
+
};
|
|
946
|
+
continue;
|
|
947
|
+
}
|
|
948
|
+
if (reasoningId) {
|
|
949
|
+
yield {
|
|
950
|
+
type: "reasoning-end",
|
|
951
|
+
id: reasoningId,
|
|
952
|
+
};
|
|
953
|
+
reasoningId = null;
|
|
954
|
+
}
|
|
891
955
|
if (typeof part.text === "string" && part.text.length > 0) {
|
|
892
956
|
yield { type: "text-delta", delta: part.text };
|
|
893
957
|
continue;
|
|
@@ -930,6 +994,12 @@ async function* streamGoogleCompatibleParts(stream) {
|
|
|
930
994
|
usage = extractGoogleUsage(event) ?? usage;
|
|
931
995
|
}
|
|
932
996
|
}
|
|
997
|
+
if (reasoningId) {
|
|
998
|
+
yield {
|
|
999
|
+
type: "reasoning-end",
|
|
1000
|
+
id: reasoningId,
|
|
1001
|
+
};
|
|
1002
|
+
}
|
|
933
1003
|
yield {
|
|
934
1004
|
type: "finish",
|
|
935
1005
|
finishReason,
|
|
@@ -971,6 +1041,8 @@ async function* streamOpenAICompatibleParts(stream) {
|
|
|
971
1041
|
const decoder = new TextDecoder();
|
|
972
1042
|
let buffer = "";
|
|
973
1043
|
const toolCalls = new Map();
|
|
1044
|
+
let reasoningId = null;
|
|
1045
|
+
let reasoningIndex = 0;
|
|
974
1046
|
let finishReason = null;
|
|
975
1047
|
let usage;
|
|
976
1048
|
for await (const chunk of stream) {
|
|
@@ -983,56 +1055,81 @@ async function* streamOpenAICompatibleParts(stream) {
|
|
|
983
1055
|
}
|
|
984
1056
|
const record = readRecord(event);
|
|
985
1057
|
usage = extractOpenAIUsage(record) ?? usage;
|
|
986
|
-
const
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
1058
|
+
const choice = extractFirstChoice(record);
|
|
1059
|
+
if (!choice) {
|
|
1060
|
+
continue;
|
|
1061
|
+
}
|
|
1062
|
+
const delta = readRecord(choice.delta);
|
|
1063
|
+
if (typeof delta?.reasoning_content === "string" && delta.reasoning_content.length > 0) {
|
|
1064
|
+
if (!reasoningId) {
|
|
1065
|
+
reasoningId = `reasoning-${reasoningIndex++}`;
|
|
1066
|
+
yield {
|
|
1067
|
+
type: "reasoning-start",
|
|
1068
|
+
id: reasoningId,
|
|
1069
|
+
};
|
|
991
1070
|
}
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
1071
|
+
yield {
|
|
1072
|
+
type: "reasoning-delta",
|
|
1073
|
+
id: reasoningId,
|
|
1074
|
+
delta: delta.reasoning_content,
|
|
1075
|
+
};
|
|
1076
|
+
}
|
|
1077
|
+
const textDelta = extractOpenAIContentText(delta?.content);
|
|
1078
|
+
if (textDelta.length > 0) {
|
|
1079
|
+
if (reasoningId) {
|
|
1080
|
+
yield {
|
|
1081
|
+
type: "reasoning-end",
|
|
1082
|
+
id: reasoningId,
|
|
1083
|
+
};
|
|
1084
|
+
reasoningId = null;
|
|
996
1085
|
}
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
started: false,
|
|
1086
|
+
yield { type: "text-delta", delta: textDelta };
|
|
1087
|
+
}
|
|
1088
|
+
const rawToolCalls = Array.isArray(delta?.tool_calls) ? delta.tool_calls : [];
|
|
1089
|
+
for (const rawToolCall of rawToolCalls) {
|
|
1090
|
+
if (reasoningId) {
|
|
1091
|
+
yield {
|
|
1092
|
+
type: "reasoning-end",
|
|
1093
|
+
id: reasoningId,
|
|
1006
1094
|
};
|
|
1007
|
-
|
|
1008
|
-
current.id = toolCallRecord.id;
|
|
1009
|
-
}
|
|
1010
|
-
const fn = readRecord(toolCallRecord?.function);
|
|
1011
|
-
if (typeof fn?.name === "string") {
|
|
1012
|
-
current.name = fn.name;
|
|
1013
|
-
}
|
|
1014
|
-
if (!current.started && current.name.length > 0) {
|
|
1015
|
-
current.started = true;
|
|
1016
|
-
yield {
|
|
1017
|
-
type: "tool-input-start",
|
|
1018
|
-
id: current.id,
|
|
1019
|
-
toolName: current.name,
|
|
1020
|
-
};
|
|
1021
|
-
}
|
|
1022
|
-
if (typeof fn?.arguments === "string" && fn.arguments.length > 0) {
|
|
1023
|
-
current.arguments += fn.arguments;
|
|
1024
|
-
yield {
|
|
1025
|
-
type: "tool-input-delta",
|
|
1026
|
-
id: current.id,
|
|
1027
|
-
delta: fn.arguments,
|
|
1028
|
-
};
|
|
1029
|
-
}
|
|
1030
|
-
toolCalls.set(index, current);
|
|
1095
|
+
reasoningId = null;
|
|
1031
1096
|
}
|
|
1032
|
-
const
|
|
1033
|
-
|
|
1034
|
-
|
|
1097
|
+
const toolCallRecord = readRecord(rawToolCall);
|
|
1098
|
+
const index = typeof toolCallRecord?.index === "number" ? toolCallRecord.index : 0;
|
|
1099
|
+
const current = toolCalls.get(index) ?? {
|
|
1100
|
+
id: typeof toolCallRecord?.id === "string" ? toolCallRecord.id : `tool-${index}`,
|
|
1101
|
+
name: "",
|
|
1102
|
+
arguments: "",
|
|
1103
|
+
started: false,
|
|
1104
|
+
};
|
|
1105
|
+
if (typeof toolCallRecord?.id === "string") {
|
|
1106
|
+
current.id = toolCallRecord.id;
|
|
1107
|
+
}
|
|
1108
|
+
const fn = readRecord(toolCallRecord?.function);
|
|
1109
|
+
if (typeof fn?.name === "string") {
|
|
1110
|
+
current.name = fn.name;
|
|
1111
|
+
}
|
|
1112
|
+
if (!current.started && current.name.length > 0) {
|
|
1113
|
+
current.started = true;
|
|
1114
|
+
yield {
|
|
1115
|
+
type: "tool-input-start",
|
|
1116
|
+
id: current.id,
|
|
1117
|
+
toolName: current.name,
|
|
1118
|
+
};
|
|
1119
|
+
}
|
|
1120
|
+
if (typeof fn?.arguments === "string" && fn.arguments.length > 0) {
|
|
1121
|
+
current.arguments += fn.arguments;
|
|
1122
|
+
yield {
|
|
1123
|
+
type: "tool-input-delta",
|
|
1124
|
+
id: current.id,
|
|
1125
|
+
delta: fn.arguments,
|
|
1126
|
+
};
|
|
1035
1127
|
}
|
|
1128
|
+
toolCalls.set(index, current);
|
|
1129
|
+
}
|
|
1130
|
+
const normalizedFinishReason = normalizeOpenAIFinishReason(choice.finish_reason);
|
|
1131
|
+
if (normalizedFinishReason) {
|
|
1132
|
+
finishReason = normalizedFinishReason;
|
|
1036
1133
|
}
|
|
1037
1134
|
}
|
|
1038
1135
|
}
|
|
@@ -1046,6 +1143,12 @@ async function* streamOpenAICompatibleParts(stream) {
|
|
|
1046
1143
|
usage = extractOpenAIUsage(record) ?? usage;
|
|
1047
1144
|
}
|
|
1048
1145
|
}
|
|
1146
|
+
if (reasoningId) {
|
|
1147
|
+
yield {
|
|
1148
|
+
type: "reasoning-end",
|
|
1149
|
+
id: reasoningId,
|
|
1150
|
+
};
|
|
1151
|
+
}
|
|
1049
1152
|
if (finishReason &&
|
|
1050
1153
|
typeof finishReason === "object" &&
|
|
1051
1154
|
finishReason.unified === "tool-calls") {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.1.
|
|
1
|
+
export declare const VERSION = "0.1.198";
|
|
2
2
|
//# sourceMappingURL=version-constant.d.ts.map
|
package/package.json
CHANGED
package/src/deno.js
CHANGED
package/src/src/chat/ag-ui.ts
CHANGED
|
@@ -37,12 +37,16 @@ export type AgUiDecodedChunk = {
|
|
|
37
37
|
remainder: string;
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
+
export type AgUiDecoderValidationMode = "permissive" | "strict";
|
|
41
|
+
|
|
40
42
|
export type AgUiChatEventDecoderState = {
|
|
41
43
|
remainder: string;
|
|
42
44
|
lastEventId: number;
|
|
43
45
|
toolCalls: Map<string, ToolCallState>;
|
|
44
46
|
reasoningFallbackIndex: number;
|
|
45
47
|
activeFallbackReasoningPartId: string | null;
|
|
48
|
+
validationMode: AgUiDecoderValidationMode;
|
|
49
|
+
onInvalidJson: ((details: { eventName: string | null; dataLength: number }) => void) | null;
|
|
46
50
|
};
|
|
47
51
|
|
|
48
52
|
export const AgUiRunFinishedMetadataSchema = z.object({
|
|
@@ -449,7 +453,13 @@ function isCommentOnlySseFrame(raw: string): boolean {
|
|
|
449
453
|
.every((line) => line.trim().length === 0 || line.trimStart().startsWith(":"));
|
|
450
454
|
}
|
|
451
455
|
|
|
452
|
-
function parseAgUiWireEvent(
|
|
456
|
+
function parseAgUiWireEvent(
|
|
457
|
+
frame: ParsedSseEvent,
|
|
458
|
+
input: {
|
|
459
|
+
validationMode: AgUiDecoderValidationMode;
|
|
460
|
+
onInvalidJson: ((details: { eventName: string | null; dataLength: number }) => void) | null;
|
|
461
|
+
},
|
|
462
|
+
): AgUiWireEvent | null {
|
|
453
463
|
if (frame.data === "[DONE]" || !frame.event || !frame.data) {
|
|
454
464
|
return null;
|
|
455
465
|
}
|
|
@@ -463,6 +473,10 @@ function parseAgUiWireEvent(frame: ParsedSseEvent): AgUiWireEvent | null {
|
|
|
463
473
|
try {
|
|
464
474
|
payload = JSON.parse(frame.data);
|
|
465
475
|
} catch {
|
|
476
|
+
input.onInvalidJson?.({
|
|
477
|
+
eventName: frame.event,
|
|
478
|
+
dataLength: frame.data.length,
|
|
479
|
+
});
|
|
466
480
|
return null;
|
|
467
481
|
}
|
|
468
482
|
|
|
@@ -475,6 +489,10 @@ function parseAgUiWireEvent(frame: ParsedSseEvent): AgUiWireEvent | null {
|
|
|
475
489
|
payload,
|
|
476
490
|
});
|
|
477
491
|
|
|
492
|
+
if (!parsed.success && input.validationMode === "strict") {
|
|
493
|
+
throw new Error(`Malformed AG-UI event payload for ${eventName.data}`);
|
|
494
|
+
}
|
|
495
|
+
|
|
478
496
|
return parsed.success ? parsed.data : null;
|
|
479
497
|
}
|
|
480
498
|
|
|
@@ -687,6 +705,8 @@ export function parseSseEvent(raw: string): ParsedSseEvent {
|
|
|
687
705
|
export function createAgUiChatEventDecoderState(
|
|
688
706
|
input: {
|
|
689
707
|
lastEventId?: number;
|
|
708
|
+
validationMode?: AgUiDecoderValidationMode;
|
|
709
|
+
onInvalidJson?: (details: { eventName: string | null; dataLength: number }) => void;
|
|
690
710
|
} = {},
|
|
691
711
|
): AgUiChatEventDecoderState {
|
|
692
712
|
return {
|
|
@@ -695,6 +715,8 @@ export function createAgUiChatEventDecoderState(
|
|
|
695
715
|
toolCalls: new Map<string, ToolCallState>(),
|
|
696
716
|
reasoningFallbackIndex: 0,
|
|
697
717
|
activeFallbackReasoningPartId: null,
|
|
718
|
+
validationMode: input.validationMode ?? "permissive",
|
|
719
|
+
onInvalidJson: input.onInvalidJson ?? null,
|
|
698
720
|
};
|
|
699
721
|
}
|
|
700
722
|
|
|
@@ -721,7 +743,10 @@ export function decodeAgUiSseChunk(
|
|
|
721
743
|
state.lastEventId = frame.id;
|
|
722
744
|
}
|
|
723
745
|
|
|
724
|
-
const wireEvent = parseAgUiWireEvent(frame
|
|
746
|
+
const wireEvent = parseAgUiWireEvent(frame, {
|
|
747
|
+
validationMode: state.validationMode,
|
|
748
|
+
onInvalidJson: state.onInvalidJson,
|
|
749
|
+
});
|
|
725
750
|
if (!wireEvent) {
|
|
726
751
|
continue;
|
|
727
752
|
}
|
|
@@ -156,6 +156,9 @@ type AnthropicStreamToolCallState = {
|
|
|
156
156
|
input: string;
|
|
157
157
|
providerExecuted?: boolean;
|
|
158
158
|
};
|
|
159
|
+
type AnthropicStreamReasoningState = {
|
|
160
|
+
id: string;
|
|
161
|
+
};
|
|
159
162
|
type GoogleCompatibleContent = {
|
|
160
163
|
role: "user" | "model";
|
|
161
164
|
parts: Array<Record<string, unknown>>;
|
|
@@ -780,6 +783,7 @@ async function* streamAnthropicCompatibleParts(
|
|
|
780
783
|
const decoder = new TextDecoder();
|
|
781
784
|
let buffer = "";
|
|
782
785
|
const toolCalls = new Map<number, AnthropicStreamToolCallState>();
|
|
786
|
+
const reasoningBlocks = new Map<number, AnthropicStreamReasoningState>();
|
|
783
787
|
let finishReason: string | { unified: string; raw: string } | null = null;
|
|
784
788
|
let usage: { inputTokens?: number; outputTokens?: number; totalTokens?: number } | undefined;
|
|
785
789
|
|
|
@@ -815,6 +819,24 @@ async function* streamAnthropicCompatibleParts(
|
|
|
815
819
|
continue;
|
|
816
820
|
}
|
|
817
821
|
|
|
822
|
+
if (blockType === "thinking") {
|
|
823
|
+
const reasoningId = `thinking-${index}`;
|
|
824
|
+
reasoningBlocks.set(index, { id: reasoningId });
|
|
825
|
+
yield {
|
|
826
|
+
type: "reasoning-start",
|
|
827
|
+
id: reasoningId,
|
|
828
|
+
};
|
|
829
|
+
|
|
830
|
+
if (typeof contentBlock?.thinking === "string" && contentBlock.thinking.length > 0) {
|
|
831
|
+
yield {
|
|
832
|
+
type: "reasoning-delta",
|
|
833
|
+
id: reasoningId,
|
|
834
|
+
delta: contentBlock.thinking,
|
|
835
|
+
};
|
|
836
|
+
}
|
|
837
|
+
continue;
|
|
838
|
+
}
|
|
839
|
+
|
|
818
840
|
if (
|
|
819
841
|
(blockType === "tool_use" || blockType === "server_tool_use") &&
|
|
820
842
|
typeof contentBlock?.id === "string" &&
|
|
@@ -892,6 +914,23 @@ async function* streamAnthropicCompatibleParts(
|
|
|
892
914
|
continue;
|
|
893
915
|
}
|
|
894
916
|
|
|
917
|
+
if (
|
|
918
|
+
deltaType === "thinking_delta" && typeof delta?.thinking === "string" &&
|
|
919
|
+
delta.thinking.length > 0
|
|
920
|
+
) {
|
|
921
|
+
const current = reasoningBlocks.get(index);
|
|
922
|
+
if (!current) {
|
|
923
|
+
continue;
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
yield {
|
|
927
|
+
type: "reasoning-delta",
|
|
928
|
+
id: current.id,
|
|
929
|
+
delta: delta.thinking,
|
|
930
|
+
};
|
|
931
|
+
continue;
|
|
932
|
+
}
|
|
933
|
+
|
|
895
934
|
if (deltaType === "input_json_delta" && typeof delta?.partial_json === "string") {
|
|
896
935
|
const current = toolCalls.get(index);
|
|
897
936
|
if (!current) {
|
|
@@ -911,6 +950,16 @@ async function* streamAnthropicCompatibleParts(
|
|
|
911
950
|
|
|
912
951
|
if (eventType === "content_block_stop") {
|
|
913
952
|
const index = typeof record?.index === "number" ? record.index : 0;
|
|
953
|
+
const reasoning = reasoningBlocks.get(index);
|
|
954
|
+
if (reasoning) {
|
|
955
|
+
yield {
|
|
956
|
+
type: "reasoning-end",
|
|
957
|
+
id: reasoning.id,
|
|
958
|
+
};
|
|
959
|
+
reasoningBlocks.delete(index);
|
|
960
|
+
continue;
|
|
961
|
+
}
|
|
962
|
+
|
|
914
963
|
const current = toolCalls.get(index);
|
|
915
964
|
if (!current) {
|
|
916
965
|
continue;
|
|
@@ -1334,6 +1383,8 @@ async function* streamGoogleCompatibleParts(
|
|
|
1334
1383
|
const decoder = new TextDecoder();
|
|
1335
1384
|
let buffer = "";
|
|
1336
1385
|
const seenToolCalls = new Set<string>();
|
|
1386
|
+
let reasoningId: string | null = null;
|
|
1387
|
+
let reasoningIndex = 0;
|
|
1337
1388
|
let finishReason: string | { unified: string; raw: string } | null = null;
|
|
1338
1389
|
let usage: { inputTokens?: number; outputTokens?: number; totalTokens?: number } | undefined;
|
|
1339
1390
|
|
|
@@ -1355,6 +1406,32 @@ async function* streamGoogleCompatibleParts(
|
|
|
1355
1406
|
}
|
|
1356
1407
|
|
|
1357
1408
|
for (const [index, part] of extractGoogleCandidateParts(event).entries()) {
|
|
1409
|
+
const isThought = part.thought === true;
|
|
1410
|
+
if (isThought && typeof part.text === "string" && part.text.length > 0) {
|
|
1411
|
+
if (!reasoningId) {
|
|
1412
|
+
reasoningId = `reasoning-${reasoningIndex++}`;
|
|
1413
|
+
yield {
|
|
1414
|
+
type: "reasoning-start",
|
|
1415
|
+
id: reasoningId,
|
|
1416
|
+
};
|
|
1417
|
+
}
|
|
1418
|
+
|
|
1419
|
+
yield {
|
|
1420
|
+
type: "reasoning-delta",
|
|
1421
|
+
id: reasoningId,
|
|
1422
|
+
delta: part.text,
|
|
1423
|
+
};
|
|
1424
|
+
continue;
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
if (reasoningId) {
|
|
1428
|
+
yield {
|
|
1429
|
+
type: "reasoning-end",
|
|
1430
|
+
id: reasoningId,
|
|
1431
|
+
};
|
|
1432
|
+
reasoningId = null;
|
|
1433
|
+
}
|
|
1434
|
+
|
|
1358
1435
|
if (typeof part.text === "string" && part.text.length > 0) {
|
|
1359
1436
|
yield { type: "text-delta", delta: part.text };
|
|
1360
1437
|
continue;
|
|
@@ -1402,6 +1479,13 @@ async function* streamGoogleCompatibleParts(
|
|
|
1402
1479
|
}
|
|
1403
1480
|
}
|
|
1404
1481
|
|
|
1482
|
+
if (reasoningId) {
|
|
1483
|
+
yield {
|
|
1484
|
+
type: "reasoning-end",
|
|
1485
|
+
id: reasoningId,
|
|
1486
|
+
};
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1405
1489
|
yield {
|
|
1406
1490
|
type: "finish",
|
|
1407
1491
|
finishReason,
|
|
@@ -1462,6 +1546,8 @@ async function* streamOpenAICompatibleParts(
|
|
|
1462
1546
|
const decoder = new TextDecoder();
|
|
1463
1547
|
let buffer = "";
|
|
1464
1548
|
const toolCalls = new Map<number, OpenAIStreamToolCallState>();
|
|
1549
|
+
let reasoningId: string | null = null;
|
|
1550
|
+
let reasoningIndex = 0;
|
|
1465
1551
|
let finishReason: string | { unified: string; raw: string } | null = null;
|
|
1466
1552
|
let usage: { inputTokens?: number; outputTokens?: number; totalTokens?: number } | undefined;
|
|
1467
1553
|
|
|
@@ -1477,65 +1563,92 @@ async function* streamOpenAICompatibleParts(
|
|
|
1477
1563
|
|
|
1478
1564
|
const record = readRecord(event);
|
|
1479
1565
|
usage = extractOpenAIUsage(record) ?? usage;
|
|
1480
|
-
const
|
|
1566
|
+
const choice = extractFirstChoice(record);
|
|
1567
|
+
if (!choice) {
|
|
1568
|
+
continue;
|
|
1569
|
+
}
|
|
1481
1570
|
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
if (!
|
|
1485
|
-
|
|
1571
|
+
const delta = readRecord(choice.delta);
|
|
1572
|
+
if (typeof delta?.reasoning_content === "string" && delta.reasoning_content.length > 0) {
|
|
1573
|
+
if (!reasoningId) {
|
|
1574
|
+
reasoningId = `reasoning-${reasoningIndex++}`;
|
|
1575
|
+
yield {
|
|
1576
|
+
type: "reasoning-start",
|
|
1577
|
+
id: reasoningId,
|
|
1578
|
+
};
|
|
1486
1579
|
}
|
|
1487
1580
|
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
}
|
|
1581
|
+
yield {
|
|
1582
|
+
type: "reasoning-delta",
|
|
1583
|
+
id: reasoningId,
|
|
1584
|
+
delta: delta.reasoning_content,
|
|
1585
|
+
};
|
|
1586
|
+
}
|
|
1493
1587
|
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
id:
|
|
1500
|
-
name: "",
|
|
1501
|
-
arguments: "",
|
|
1502
|
-
started: false,
|
|
1588
|
+
const textDelta = extractOpenAIContentText(delta?.content);
|
|
1589
|
+
if (textDelta.length > 0) {
|
|
1590
|
+
if (reasoningId) {
|
|
1591
|
+
yield {
|
|
1592
|
+
type: "reasoning-end",
|
|
1593
|
+
id: reasoningId,
|
|
1503
1594
|
};
|
|
1595
|
+
reasoningId = null;
|
|
1596
|
+
}
|
|
1597
|
+
yield { type: "text-delta", delta: textDelta };
|
|
1598
|
+
}
|
|
1504
1599
|
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1600
|
+
const rawToolCalls = Array.isArray(delta?.tool_calls) ? delta.tool_calls : [];
|
|
1601
|
+
for (const rawToolCall of rawToolCalls) {
|
|
1602
|
+
if (reasoningId) {
|
|
1603
|
+
yield {
|
|
1604
|
+
type: "reasoning-end",
|
|
1605
|
+
id: reasoningId,
|
|
1606
|
+
};
|
|
1607
|
+
reasoningId = null;
|
|
1608
|
+
}
|
|
1508
1609
|
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
}
|
|
1610
|
+
const toolCallRecord = readRecord(rawToolCall);
|
|
1611
|
+
const index = typeof toolCallRecord?.index === "number" ? toolCallRecord.index : 0;
|
|
1612
|
+
const current = toolCalls.get(index) ?? {
|
|
1613
|
+
id: typeof toolCallRecord?.id === "string" ? toolCallRecord.id : `tool-${index}`,
|
|
1614
|
+
name: "",
|
|
1615
|
+
arguments: "",
|
|
1616
|
+
started: false,
|
|
1617
|
+
};
|
|
1513
1618
|
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
type: "tool-input-start",
|
|
1518
|
-
id: current.id,
|
|
1519
|
-
toolName: current.name,
|
|
1520
|
-
};
|
|
1521
|
-
}
|
|
1619
|
+
if (typeof toolCallRecord?.id === "string") {
|
|
1620
|
+
current.id = toolCallRecord.id;
|
|
1621
|
+
}
|
|
1522
1622
|
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
id: current.id,
|
|
1528
|
-
delta: fn.arguments,
|
|
1529
|
-
};
|
|
1530
|
-
}
|
|
1623
|
+
const fn = readRecord(toolCallRecord?.function);
|
|
1624
|
+
if (typeof fn?.name === "string") {
|
|
1625
|
+
current.name = fn.name;
|
|
1626
|
+
}
|
|
1531
1627
|
|
|
1532
|
-
|
|
1628
|
+
if (!current.started && current.name.length > 0) {
|
|
1629
|
+
current.started = true;
|
|
1630
|
+
yield {
|
|
1631
|
+
type: "tool-input-start",
|
|
1632
|
+
id: current.id,
|
|
1633
|
+
toolName: current.name,
|
|
1634
|
+
};
|
|
1533
1635
|
}
|
|
1534
1636
|
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1637
|
+
if (typeof fn?.arguments === "string" && fn.arguments.length > 0) {
|
|
1638
|
+
current.arguments += fn.arguments;
|
|
1639
|
+
yield {
|
|
1640
|
+
type: "tool-input-delta",
|
|
1641
|
+
id: current.id,
|
|
1642
|
+
delta: fn.arguments,
|
|
1643
|
+
};
|
|
1538
1644
|
}
|
|
1645
|
+
|
|
1646
|
+
toolCalls.set(index, current);
|
|
1647
|
+
}
|
|
1648
|
+
|
|
1649
|
+
const normalizedFinishReason = normalizeOpenAIFinishReason(choice.finish_reason);
|
|
1650
|
+
if (normalizedFinishReason) {
|
|
1651
|
+
finishReason = normalizedFinishReason;
|
|
1539
1652
|
}
|
|
1540
1653
|
}
|
|
1541
1654
|
}
|
|
@@ -1552,6 +1665,13 @@ async function* streamOpenAICompatibleParts(
|
|
|
1552
1665
|
}
|
|
1553
1666
|
}
|
|
1554
1667
|
|
|
1668
|
+
if (reasoningId) {
|
|
1669
|
+
yield {
|
|
1670
|
+
type: "reasoning-end",
|
|
1671
|
+
id: reasoningId,
|
|
1672
|
+
};
|
|
1673
|
+
}
|
|
1674
|
+
|
|
1555
1675
|
if (
|
|
1556
1676
|
finishReason &&
|
|
1557
1677
|
typeof finishReason === "object" &&
|