assistant-stream 0.1.1 → 0.1.3
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/dist/ai-sdk.d.mts +2 -1
- package/dist/ai-sdk.d.ts +2 -1
- package/dist/{assistant-stream-54RSz6y3.d.mts → assistant-stream-CgeUyrON.d.ts} +2 -6
- package/dist/{assistant-stream-54RSz6y3.d.ts → assistant-stream-ujRn7KXt.d.mts} +2 -6
- package/dist/{chunk-C7JS3OBQ.mjs → chunk-LHNPFNMI.mjs} +96 -9
- package/dist/chunk-LHNPFNMI.mjs.map +1 -0
- package/dist/index.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +71 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3 -8
- package/dist/index.mjs.map +1 -1
- package/dist/json-value-DvDjYV7y.d.mts +7 -0
- package/dist/json-value-DvDjYV7y.d.ts +7 -0
- package/dist/utils.d.mts +16 -2
- package/dist/utils.d.ts +16 -2
- package/dist/utils.js +117 -9
- package/dist/utils.js.map +1 -1
- package/dist/utils.mjs +24 -3
- package/dist/utils.mjs.map +1 -1
- package/package.json +7 -4
- package/dist/chunk-C7JS3OBQ.mjs.map +0 -1
package/dist/ai-sdk.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { TextStreamPart, Tool, ObjectStreamPart, LanguageModelV1StreamPart } from 'ai';
|
|
2
|
-
import { A as AssistantStream, a as AssistantStreamChunk, b as AssistantStreamController } from './assistant-stream-
|
|
2
|
+
import { A as AssistantStream, a as AssistantStreamChunk, b as AssistantStreamController } from './assistant-stream-ujRn7KXt.mjs';
|
|
3
|
+
import './json-value-DvDjYV7y.mjs';
|
|
3
4
|
|
|
4
5
|
declare const fromStreamText: (stream: ReadableStream<TextStreamPart<Record<string, Tool>>>) => AssistantStream;
|
|
5
6
|
declare const fromStreamObject: (stream: ReadableStream<ObjectStreamPart<unknown>>, toolName: string) => AssistantStream;
|
package/dist/ai-sdk.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { TextStreamPart, Tool, ObjectStreamPart, LanguageModelV1StreamPart } from 'ai';
|
|
2
|
-
import { A as AssistantStream, a as AssistantStreamChunk, b as AssistantStreamController } from './assistant-stream-
|
|
2
|
+
import { A as AssistantStream, a as AssistantStreamChunk, b as AssistantStreamController } from './assistant-stream-CgeUyrON.js';
|
|
3
|
+
import './json-value-DvDjYV7y.js';
|
|
3
4
|
|
|
4
5
|
declare const fromStreamText: (stream: ReadableStream<TextStreamPart<Record<string, Tool>>>) => AssistantStream;
|
|
5
6
|
declare const fromStreamObject: (stream: ReadableStream<ObjectStreamPart<unknown>>, toolName: string) => AssistantStream;
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
type ReadonlyJSONObject = {
|
|
3
|
-
readonly [key: string]: ReadonlyJSONValue;
|
|
4
|
-
};
|
|
5
|
-
type ReadonlyJSONArray = readonly ReadonlyJSONValue[];
|
|
1
|
+
import { R as ReadonlyJSONValue, a as ReadonlyJSONObject } from './json-value-DvDjYV7y.js';
|
|
6
2
|
|
|
7
3
|
type PartInit = {
|
|
8
4
|
readonly type: "text" | "reasoning";
|
|
@@ -226,4 +222,4 @@ type AssistantStreamController = {
|
|
|
226
222
|
declare function createAssistantStream(callback: (controller: AssistantStreamController) => PromiseLike<void> | void): AssistantStream;
|
|
227
223
|
declare function createAssistantStreamResponse(callback: (controller: AssistantStreamController) => PromiseLike<void> | void): Response;
|
|
228
224
|
|
|
229
|
-
export { AssistantStream as A,
|
|
225
|
+
export { AssistantStream as A, ToolResponse as T, type AssistantStreamChunk as a, type AssistantStreamController as b, type AssistantMessage as c, type AssistantStreamEncoder as d, createAssistantStream as e, createAssistantStreamResponse as f };
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
type ReadonlyJSONObject = {
|
|
3
|
-
readonly [key: string]: ReadonlyJSONValue;
|
|
4
|
-
};
|
|
5
|
-
type ReadonlyJSONArray = readonly ReadonlyJSONValue[];
|
|
1
|
+
import { R as ReadonlyJSONValue, a as ReadonlyJSONObject } from './json-value-DvDjYV7y.mjs';
|
|
6
2
|
|
|
7
3
|
type PartInit = {
|
|
8
4
|
readonly type: "text" | "reasoning";
|
|
@@ -226,4 +222,4 @@ type AssistantStreamController = {
|
|
|
226
222
|
declare function createAssistantStream(callback: (controller: AssistantStreamController) => PromiseLike<void> | void): AssistantStream;
|
|
227
223
|
declare function createAssistantStreamResponse(callback: (controller: AssistantStreamController) => PromiseLike<void> | void): Response;
|
|
228
224
|
|
|
229
|
-
export { AssistantStream as A,
|
|
225
|
+
export { AssistantStream as A, ToolResponse as T, type AssistantStreamChunk as a, type AssistantStreamController as b, type AssistantMessage as c, type AssistantStreamEncoder as d, createAssistantStream as e, createAssistantStreamResponse as f };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// src/core/utils/json/parse-partial-json.ts
|
|
1
|
+
// src/core/utils/json/parse-partial-json-object.ts
|
|
2
2
|
import sjson from "secure-json-parse";
|
|
3
3
|
|
|
4
4
|
// src/core/utils/json/fix-json.ts
|
|
@@ -6,6 +6,14 @@ function fixJson(input) {
|
|
|
6
6
|
const stack = ["ROOT"];
|
|
7
7
|
let lastValidIndex = -1;
|
|
8
8
|
let literalStart = null;
|
|
9
|
+
const path = [];
|
|
10
|
+
let currentKey;
|
|
11
|
+
function pushCurrentKeyToPath() {
|
|
12
|
+
if (currentKey !== void 0) {
|
|
13
|
+
path.push(JSON.parse('"' + currentKey + '"'));
|
|
14
|
+
currentKey = void 0;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
9
17
|
function processValueStart(char, i, swapState) {
|
|
10
18
|
{
|
|
11
19
|
switch (char) {
|
|
@@ -14,6 +22,7 @@ function fixJson(input) {
|
|
|
14
22
|
stack.pop();
|
|
15
23
|
stack.push(swapState);
|
|
16
24
|
stack.push("INSIDE_STRING");
|
|
25
|
+
pushCurrentKeyToPath();
|
|
17
26
|
break;
|
|
18
27
|
}
|
|
19
28
|
case "f":
|
|
@@ -30,6 +39,7 @@ function fixJson(input) {
|
|
|
30
39
|
stack.pop();
|
|
31
40
|
stack.push(swapState);
|
|
32
41
|
stack.push("INSIDE_NUMBER");
|
|
42
|
+
pushCurrentKeyToPath();
|
|
33
43
|
break;
|
|
34
44
|
}
|
|
35
45
|
case "0":
|
|
@@ -46,6 +56,7 @@ function fixJson(input) {
|
|
|
46
56
|
stack.pop();
|
|
47
57
|
stack.push(swapState);
|
|
48
58
|
stack.push("INSIDE_NUMBER");
|
|
59
|
+
pushCurrentKeyToPath();
|
|
49
60
|
break;
|
|
50
61
|
}
|
|
51
62
|
case "{": {
|
|
@@ -53,6 +64,7 @@ function fixJson(input) {
|
|
|
53
64
|
stack.pop();
|
|
54
65
|
stack.push(swapState);
|
|
55
66
|
stack.push("INSIDE_OBJECT_START");
|
|
67
|
+
pushCurrentKeyToPath();
|
|
56
68
|
break;
|
|
57
69
|
}
|
|
58
70
|
case "[": {
|
|
@@ -60,6 +72,7 @@ function fixJson(input) {
|
|
|
60
72
|
stack.pop();
|
|
61
73
|
stack.push(swapState);
|
|
62
74
|
stack.push("INSIDE_ARRAY_START");
|
|
75
|
+
pushCurrentKeyToPath();
|
|
63
76
|
break;
|
|
64
77
|
}
|
|
65
78
|
}
|
|
@@ -75,6 +88,7 @@ function fixJson(input) {
|
|
|
75
88
|
case "}": {
|
|
76
89
|
lastValidIndex = i;
|
|
77
90
|
stack.pop();
|
|
91
|
+
currentKey = path.pop();
|
|
78
92
|
break;
|
|
79
93
|
}
|
|
80
94
|
}
|
|
@@ -84,11 +98,13 @@ function fixJson(input) {
|
|
|
84
98
|
case ",": {
|
|
85
99
|
stack.pop();
|
|
86
100
|
stack.push("INSIDE_ARRAY_AFTER_COMMA");
|
|
101
|
+
currentKey = (Number(currentKey) + 1).toString();
|
|
87
102
|
break;
|
|
88
103
|
}
|
|
89
104
|
case "]": {
|
|
90
105
|
lastValidIndex = i;
|
|
91
106
|
stack.pop();
|
|
107
|
+
currentKey = path.pop();
|
|
92
108
|
break;
|
|
93
109
|
}
|
|
94
110
|
}
|
|
@@ -105,11 +121,13 @@ function fixJson(input) {
|
|
|
105
121
|
case '"': {
|
|
106
122
|
stack.pop();
|
|
107
123
|
stack.push("INSIDE_OBJECT_KEY");
|
|
124
|
+
currentKey = "";
|
|
108
125
|
break;
|
|
109
126
|
}
|
|
110
127
|
case "}": {
|
|
111
128
|
lastValidIndex = i;
|
|
112
129
|
stack.pop();
|
|
130
|
+
currentKey = path.pop();
|
|
113
131
|
break;
|
|
114
132
|
}
|
|
115
133
|
}
|
|
@@ -120,6 +138,7 @@ function fixJson(input) {
|
|
|
120
138
|
case '"': {
|
|
121
139
|
stack.pop();
|
|
122
140
|
stack.push("INSIDE_OBJECT_KEY");
|
|
141
|
+
currentKey = "";
|
|
123
142
|
break;
|
|
124
143
|
}
|
|
125
144
|
}
|
|
@@ -132,6 +151,15 @@ function fixJson(input) {
|
|
|
132
151
|
stack.push("INSIDE_OBJECT_AFTER_KEY");
|
|
133
152
|
break;
|
|
134
153
|
}
|
|
154
|
+
case "\\": {
|
|
155
|
+
stack.push("INSIDE_STRING_ESCAPE");
|
|
156
|
+
currentKey += char;
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
default: {
|
|
160
|
+
currentKey += char;
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
135
163
|
}
|
|
136
164
|
break;
|
|
137
165
|
}
|
|
@@ -158,6 +186,7 @@ function fixJson(input) {
|
|
|
158
186
|
case '"': {
|
|
159
187
|
stack.pop();
|
|
160
188
|
lastValidIndex = i;
|
|
189
|
+
currentKey = path.pop();
|
|
161
190
|
break;
|
|
162
191
|
}
|
|
163
192
|
case "\\": {
|
|
@@ -175,10 +204,12 @@ function fixJson(input) {
|
|
|
175
204
|
case "]": {
|
|
176
205
|
lastValidIndex = i;
|
|
177
206
|
stack.pop();
|
|
207
|
+
currentKey = path.pop();
|
|
178
208
|
break;
|
|
179
209
|
}
|
|
180
210
|
default: {
|
|
181
211
|
lastValidIndex = i;
|
|
212
|
+
currentKey = "0";
|
|
182
213
|
processValueStart(char, i, "INSIDE_ARRAY_AFTER_VALUE");
|
|
183
214
|
break;
|
|
184
215
|
}
|
|
@@ -190,11 +221,13 @@ function fixJson(input) {
|
|
|
190
221
|
case ",": {
|
|
191
222
|
stack.pop();
|
|
192
223
|
stack.push("INSIDE_ARRAY_AFTER_COMMA");
|
|
224
|
+
currentKey = (Number(currentKey) + 1).toString();
|
|
193
225
|
break;
|
|
194
226
|
}
|
|
195
227
|
case "]": {
|
|
196
228
|
lastValidIndex = i;
|
|
197
229
|
stack.pop();
|
|
230
|
+
currentKey = path.pop();
|
|
198
231
|
break;
|
|
199
232
|
}
|
|
200
233
|
default: {
|
|
@@ -210,7 +243,11 @@ function fixJson(input) {
|
|
|
210
243
|
}
|
|
211
244
|
case "INSIDE_STRING_ESCAPE": {
|
|
212
245
|
stack.pop();
|
|
213
|
-
|
|
246
|
+
if (stack[stack.length - 1] === "INSIDE_STRING") {
|
|
247
|
+
lastValidIndex = i;
|
|
248
|
+
} else if (stack[stack.length - 1] === "INSIDE_OBJECT_KEY") {
|
|
249
|
+
currentKey += char;
|
|
250
|
+
}
|
|
214
251
|
break;
|
|
215
252
|
}
|
|
216
253
|
case "INSIDE_NUMBER": {
|
|
@@ -236,6 +273,7 @@ function fixJson(input) {
|
|
|
236
273
|
}
|
|
237
274
|
case ",": {
|
|
238
275
|
stack.pop();
|
|
276
|
+
currentKey = path.pop();
|
|
239
277
|
if (stack[stack.length - 1] === "INSIDE_ARRAY_AFTER_VALUE") {
|
|
240
278
|
processAfterArrayValue(char, i);
|
|
241
279
|
}
|
|
@@ -246,6 +284,7 @@ function fixJson(input) {
|
|
|
246
284
|
}
|
|
247
285
|
case "}": {
|
|
248
286
|
stack.pop();
|
|
287
|
+
currentKey = path.pop();
|
|
249
288
|
if (stack[stack.length - 1] === "INSIDE_OBJECT_AFTER_VALUE") {
|
|
250
289
|
processAfterObjectValue(char, i);
|
|
251
290
|
}
|
|
@@ -253,6 +292,7 @@ function fixJson(input) {
|
|
|
253
292
|
}
|
|
254
293
|
case "]": {
|
|
255
294
|
stack.pop();
|
|
295
|
+
currentKey = path.pop();
|
|
256
296
|
if (stack[stack.length - 1] === "INSIDE_ARRAY_AFTER_VALUE") {
|
|
257
297
|
processAfterArrayValue(char, i);
|
|
258
298
|
}
|
|
@@ -260,6 +300,7 @@ function fixJson(input) {
|
|
|
260
300
|
}
|
|
261
301
|
default: {
|
|
262
302
|
stack.pop();
|
|
303
|
+
currentKey = path.pop();
|
|
263
304
|
break;
|
|
264
305
|
}
|
|
265
306
|
}
|
|
@@ -316,23 +357,69 @@ function fixJson(input) {
|
|
|
316
357
|
}
|
|
317
358
|
}
|
|
318
359
|
}
|
|
319
|
-
return result;
|
|
360
|
+
return [result, path];
|
|
320
361
|
}
|
|
321
362
|
|
|
322
|
-
// src/core/utils/json/parse-partial-json.ts
|
|
323
|
-
var
|
|
363
|
+
// src/core/utils/json/parse-partial-json-object.ts
|
|
364
|
+
var PARTIAL_JSON_OBJECT_META_SYMBOL = Symbol(
|
|
365
|
+
"aui.parse-partial-json-object.meta"
|
|
366
|
+
);
|
|
367
|
+
var getPartialJsonObjectMeta = (obj) => {
|
|
368
|
+
return obj?.[PARTIAL_JSON_OBJECT_META_SYMBOL];
|
|
369
|
+
};
|
|
370
|
+
var parsePartialJsonObject = (json) => {
|
|
371
|
+
if (json.length === 0)
|
|
372
|
+
return {
|
|
373
|
+
[PARTIAL_JSON_OBJECT_META_SYMBOL]: { state: "partial", partialPath: [] }
|
|
374
|
+
};
|
|
324
375
|
try {
|
|
325
|
-
|
|
376
|
+
const res = sjson.parse(json);
|
|
377
|
+
if (typeof res !== "object" || res === null)
|
|
378
|
+
throw new Error("argsText is expected to be an object");
|
|
379
|
+
res[PARTIAL_JSON_OBJECT_META_SYMBOL] = {
|
|
380
|
+
state: "complete",
|
|
381
|
+
partialPath: []
|
|
382
|
+
};
|
|
383
|
+
return res;
|
|
326
384
|
} catch {
|
|
327
385
|
try {
|
|
328
|
-
|
|
386
|
+
const [fixedJson, partialPath] = fixJson(json);
|
|
387
|
+
const res = sjson.parse(fixedJson);
|
|
388
|
+
if (typeof res !== "object" || res === null)
|
|
389
|
+
throw new Error("argsText is expected to be an object");
|
|
390
|
+
res[PARTIAL_JSON_OBJECT_META_SYMBOL] = {
|
|
391
|
+
state: "partial",
|
|
392
|
+
partialPath
|
|
393
|
+
};
|
|
394
|
+
return res;
|
|
329
395
|
} catch {
|
|
330
396
|
return void 0;
|
|
331
397
|
}
|
|
332
398
|
}
|
|
333
399
|
};
|
|
400
|
+
var getFieldState = (parent, parentMeta, fieldPath) => {
|
|
401
|
+
if (typeof parent !== "object" || parent === null) return parentMeta.state;
|
|
402
|
+
if (parentMeta.state === "complete") return "complete";
|
|
403
|
+
if (fieldPath.length === 0) return parentMeta.state;
|
|
404
|
+
const [field, ...restPath] = fieldPath;
|
|
405
|
+
if (!Object.prototype.hasOwnProperty.call(parent, field)) return "partial";
|
|
406
|
+
const [partialField, ...restPartialPath] = parentMeta.partialPath;
|
|
407
|
+
if (field !== partialField) return "complete";
|
|
408
|
+
const child = parent[field];
|
|
409
|
+
const childMeta = {
|
|
410
|
+
state: "partial",
|
|
411
|
+
partialPath: restPartialPath
|
|
412
|
+
};
|
|
413
|
+
return getFieldState(child, childMeta, restPath);
|
|
414
|
+
};
|
|
415
|
+
var getPartialJsonObjectFieldState = (args, fieldPath) => {
|
|
416
|
+
const meta = getPartialJsonObjectMeta(args);
|
|
417
|
+
if (!meta) throw new Error("unable to determine args state");
|
|
418
|
+
return getFieldState(args, meta, fieldPath.map(String));
|
|
419
|
+
};
|
|
334
420
|
|
|
335
421
|
export {
|
|
336
|
-
|
|
422
|
+
parsePartialJsonObject,
|
|
423
|
+
getPartialJsonObjectFieldState
|
|
337
424
|
};
|
|
338
|
-
//# sourceMappingURL=chunk-
|
|
425
|
+
//# sourceMappingURL=chunk-LHNPFNMI.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/utils/json/parse-partial-json-object.ts","../src/core/utils/json/fix-json.ts"],"sourcesContent":["import sjson from \"secure-json-parse\";\nimport { fixJson } from \"./fix-json\";\nimport { ReadonlyJSONObject } from \"./json-value\";\n\nconst PARTIAL_JSON_OBJECT_META_SYMBOL = Symbol(\n \"aui.parse-partial-json-object.meta\",\n);\n\ntype FieldState = \"complete\" | \"partial\";\n\ntype PartialJsonObjectMeta = {\n state: \"complete\" | \"partial\";\n partialPath: string[];\n};\n\nexport const getPartialJsonObjectMeta = (\n obj: Record<symbol, unknown>,\n): PartialJsonObjectMeta | undefined => {\n return obj?.[PARTIAL_JSON_OBJECT_META_SYMBOL] as PartialJsonObjectMeta;\n};\n\nexport const parsePartialJsonObject = (\n json: string,\n):\n | (ReadonlyJSONObject & {\n [PARTIAL_JSON_OBJECT_META_SYMBOL]: PartialJsonObjectMeta;\n })\n | undefined => {\n if (json.length === 0)\n return {\n [PARTIAL_JSON_OBJECT_META_SYMBOL]: { state: \"partial\", partialPath: [] },\n };\n\n try {\n const res = sjson.parse(json);\n if (typeof res !== \"object\" || res === null)\n throw new Error(\"argsText is expected to be an object\");\n\n res[PARTIAL_JSON_OBJECT_META_SYMBOL] = {\n state: \"complete\",\n partialPath: [],\n };\n return res;\n } catch {\n try {\n const [fixedJson, partialPath] = fixJson(json);\n const res = sjson.parse(fixedJson);\n if (typeof res !== \"object\" || res === null)\n throw new Error(\"argsText is expected to be an object\");\n\n res[PARTIAL_JSON_OBJECT_META_SYMBOL] = {\n state: \"partial\",\n partialPath,\n };\n return res;\n } catch {\n return undefined;\n }\n }\n};\n\nconst getFieldState = (\n parent: unknown,\n parentMeta: PartialJsonObjectMeta,\n fieldPath: string[],\n): FieldState => {\n if (typeof parent !== \"object\" || parent === null) return parentMeta.state;\n\n // 1) parent is complete: return \"complete\"\n if (parentMeta.state === \"complete\") return \"complete\";\n\n // 2) we finished traversing: return parent state\n if (fieldPath.length === 0) return parentMeta.state;\n\n const [field, ...restPath] = fieldPath as [string, ...string[]];\n\n // 3) field doesn't yet exist in parent: return \"partial\"\n if (!Object.prototype.hasOwnProperty.call(parent, field)) return \"partial\";\n\n const [partialField, ...restPartialPath] = parentMeta.partialPath;\n\n // 4) field exists but is not partial: return \"complete\"\n if (field !== partialField) return \"complete\";\n\n // 5) field exists and is partial: return child state\n const child = (parent as Record<string, unknown>)[field];\n const childMeta: PartialJsonObjectMeta = {\n state: \"partial\",\n partialPath: restPartialPath,\n };\n\n return getFieldState(child, childMeta, restPath);\n};\n\nexport const getPartialJsonObjectFieldState = (\n args: Record<string, unknown>,\n fieldPath: (string | number)[],\n): FieldState => {\n const meta = getPartialJsonObjectMeta(args);\n if (!meta) throw new Error(\"unable to determine args state\");\n\n return getFieldState(args, meta, fieldPath.map(String));\n};\n","// LICENSE for this file only\n\n// MIT License\n\n// Copyright (c) 2025 AgentbaseAI Inc.\n// Copyright (c) 2023 Lars Grammel\n\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n\n// The above copyright notice and this permission notice shall be included in all\n// copies or substantial portions of the Software.\n\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n// SOFTWARE.\n\ntype State =\n | \"ROOT\"\n | \"FINISH\"\n | \"INSIDE_STRING\"\n | \"INSIDE_STRING_ESCAPE\"\n | \"INSIDE_LITERAL\"\n | \"INSIDE_NUMBER\"\n | \"INSIDE_OBJECT_START\"\n | \"INSIDE_OBJECT_KEY\"\n | \"INSIDE_OBJECT_AFTER_KEY\"\n | \"INSIDE_OBJECT_BEFORE_VALUE\"\n | \"INSIDE_OBJECT_AFTER_VALUE\"\n | \"INSIDE_OBJECT_AFTER_COMMA\"\n | \"INSIDE_ARRAY_START\"\n | \"INSIDE_ARRAY_AFTER_VALUE\"\n | \"INSIDE_ARRAY_AFTER_COMMA\";\n\n// Implemented as a scanner with additional fixing\n// that performs a single linear time scan pass over the partial JSON.\n//\n// The states should ideally match relevant states from the JSON spec:\n// https://www.json.org/json-en.html\n//\n// Please note that invalid JSON is not considered/covered, because it\n// is assumed that the resulting JSON will be processed by a standard\n// JSON parser that will detect any invalid JSON.\n\n// Returns a tuple of [fixedJson, partialPath]\n// partialPath is an array of object/array keys that represent\n// the currently partial values. An object is considered partial\n// if through appending extra characters to the JSON string, its\n// value could change.\n\n// Example input: '{\"foo\":[{\"a\":f'\n// Example output: ['{\"foo\":[{\"a\":false}]}', ['foo', '0']]\n// Example input: '{\"foo\":'\n// Example output: ['{}', []]\n\nexport function fixJson(input: string): [string, string[]] {\n const stack: State[] = [\"ROOT\"];\n let lastValidIndex = -1;\n let literalStart: number | null = null;\n const path: string[] = [];\n let currentKey: string | undefined;\n\n function pushCurrentKeyToPath(): void {\n if (currentKey !== undefined) {\n path.push(JSON.parse('\"' + currentKey + '\"'));\n currentKey = undefined;\n }\n }\n\n function processValueStart(char: string, i: number, swapState: State) {\n {\n switch (char) {\n case '\"': {\n lastValidIndex = i;\n stack.pop();\n stack.push(swapState);\n stack.push(\"INSIDE_STRING\");\n\n pushCurrentKeyToPath();\n break;\n }\n\n case \"f\":\n case \"t\":\n case \"n\": {\n lastValidIndex = i;\n literalStart = i;\n stack.pop();\n stack.push(swapState);\n stack.push(\"INSIDE_LITERAL\");\n break;\n }\n\n case \"-\": {\n stack.pop();\n stack.push(swapState);\n stack.push(\"INSIDE_NUMBER\");\n\n pushCurrentKeyToPath();\n break;\n }\n case \"0\":\n case \"1\":\n case \"2\":\n case \"3\":\n case \"4\":\n case \"5\":\n case \"6\":\n case \"7\":\n case \"8\":\n case \"9\": {\n lastValidIndex = i;\n stack.pop();\n stack.push(swapState);\n stack.push(\"INSIDE_NUMBER\");\n\n pushCurrentKeyToPath();\n break;\n }\n\n case \"{\": {\n lastValidIndex = i;\n stack.pop();\n stack.push(swapState);\n stack.push(\"INSIDE_OBJECT_START\");\n\n pushCurrentKeyToPath();\n break;\n }\n\n case \"[\": {\n lastValidIndex = i;\n stack.pop();\n stack.push(swapState);\n stack.push(\"INSIDE_ARRAY_START\");\n\n pushCurrentKeyToPath();\n break;\n }\n }\n }\n }\n\n function processAfterObjectValue(char: string, i: number) {\n switch (char) {\n case \",\": {\n stack.pop();\n stack.push(\"INSIDE_OBJECT_AFTER_COMMA\");\n break;\n }\n case \"}\": {\n lastValidIndex = i;\n stack.pop();\n currentKey = path.pop();\n break;\n }\n }\n }\n\n function processAfterArrayValue(char: string, i: number) {\n switch (char) {\n case \",\": {\n stack.pop();\n stack.push(\"INSIDE_ARRAY_AFTER_COMMA\");\n currentKey = (Number(currentKey) + 1).toString();\n break;\n }\n case \"]\": {\n lastValidIndex = i;\n stack.pop();\n currentKey = path.pop();\n break;\n }\n }\n }\n\n for (let i = 0; i < input.length; i++) {\n const char = input[i]!;\n const currentState = stack[stack.length - 1];\n\n switch (currentState) {\n case \"ROOT\":\n processValueStart(char, i, \"FINISH\");\n break;\n\n case \"INSIDE_OBJECT_START\": {\n switch (char) {\n case '\"': {\n stack.pop();\n stack.push(\"INSIDE_OBJECT_KEY\");\n currentKey = \"\";\n break;\n }\n case \"}\": {\n lastValidIndex = i;\n stack.pop();\n currentKey = path.pop();\n break;\n }\n }\n break;\n }\n\n case \"INSIDE_OBJECT_AFTER_COMMA\": {\n switch (char) {\n case '\"': {\n stack.pop();\n stack.push(\"INSIDE_OBJECT_KEY\");\n currentKey = \"\";\n break;\n }\n }\n break;\n }\n\n case \"INSIDE_OBJECT_KEY\": {\n switch (char) {\n case '\"': {\n stack.pop();\n stack.push(\"INSIDE_OBJECT_AFTER_KEY\");\n break;\n }\n case \"\\\\\": {\n stack.push(\"INSIDE_STRING_ESCAPE\");\n currentKey += char;\n break;\n }\n default: {\n currentKey += char;\n break;\n }\n }\n break;\n }\n\n case \"INSIDE_OBJECT_AFTER_KEY\": {\n switch (char) {\n case \":\": {\n stack.pop();\n stack.push(\"INSIDE_OBJECT_BEFORE_VALUE\");\n\n break;\n }\n }\n break;\n }\n\n case \"INSIDE_OBJECT_BEFORE_VALUE\": {\n processValueStart(char, i, \"INSIDE_OBJECT_AFTER_VALUE\");\n break;\n }\n\n case \"INSIDE_OBJECT_AFTER_VALUE\": {\n processAfterObjectValue(char, i);\n break;\n }\n\n case \"INSIDE_STRING\": {\n switch (char) {\n case '\"': {\n stack.pop();\n lastValidIndex = i;\n\n currentKey = path.pop();\n break;\n }\n\n case \"\\\\\": {\n stack.push(\"INSIDE_STRING_ESCAPE\");\n break;\n }\n\n default: {\n lastValidIndex = i;\n }\n }\n\n break;\n }\n\n case \"INSIDE_ARRAY_START\": {\n switch (char) {\n case \"]\": {\n lastValidIndex = i;\n stack.pop();\n currentKey = path.pop();\n break;\n }\n\n default: {\n lastValidIndex = i;\n currentKey = \"0\";\n processValueStart(char, i, \"INSIDE_ARRAY_AFTER_VALUE\");\n break;\n }\n }\n break;\n }\n\n case \"INSIDE_ARRAY_AFTER_VALUE\": {\n switch (char) {\n case \",\": {\n stack.pop();\n stack.push(\"INSIDE_ARRAY_AFTER_COMMA\");\n\n currentKey = (Number(currentKey) + 1).toString();\n break;\n }\n\n case \"]\": {\n lastValidIndex = i;\n stack.pop();\n currentKey = path.pop();\n break;\n }\n\n default: {\n lastValidIndex = i;\n break;\n }\n }\n\n break;\n }\n\n case \"INSIDE_ARRAY_AFTER_COMMA\": {\n processValueStart(char, i, \"INSIDE_ARRAY_AFTER_VALUE\");\n break;\n }\n\n case \"INSIDE_STRING_ESCAPE\": {\n stack.pop();\n\n if (stack[stack.length - 1] === \"INSIDE_STRING\") {\n lastValidIndex = i;\n } else if (stack[stack.length - 1] === \"INSIDE_OBJECT_KEY\") {\n currentKey += char;\n }\n\n break;\n }\n\n case \"INSIDE_NUMBER\": {\n switch (char) {\n case \"0\":\n case \"1\":\n case \"2\":\n case \"3\":\n case \"4\":\n case \"5\":\n case \"6\":\n case \"7\":\n case \"8\":\n case \"9\": {\n lastValidIndex = i;\n break;\n }\n\n case \"e\":\n case \"E\":\n case \"-\":\n case \".\": {\n break;\n }\n\n case \",\": {\n stack.pop();\n currentKey = path.pop();\n\n if (stack[stack.length - 1] === \"INSIDE_ARRAY_AFTER_VALUE\") {\n processAfterArrayValue(char, i);\n }\n\n if (stack[stack.length - 1] === \"INSIDE_OBJECT_AFTER_VALUE\") {\n processAfterObjectValue(char, i);\n }\n\n break;\n }\n\n case \"}\": {\n stack.pop();\n currentKey = path.pop();\n\n if (stack[stack.length - 1] === \"INSIDE_OBJECT_AFTER_VALUE\") {\n processAfterObjectValue(char, i);\n }\n\n break;\n }\n\n case \"]\": {\n stack.pop();\n currentKey = path.pop();\n\n if (stack[stack.length - 1] === \"INSIDE_ARRAY_AFTER_VALUE\") {\n processAfterArrayValue(char, i);\n }\n\n break;\n }\n\n default: {\n stack.pop();\n currentKey = path.pop();\n break;\n }\n }\n\n break;\n }\n\n case \"INSIDE_LITERAL\": {\n const partialLiteral = input.substring(literalStart!, i + 1);\n\n if (\n !\"false\".startsWith(partialLiteral) &&\n !\"true\".startsWith(partialLiteral) &&\n !\"null\".startsWith(partialLiteral)\n ) {\n stack.pop();\n\n if (stack[stack.length - 1] === \"INSIDE_OBJECT_AFTER_VALUE\") {\n processAfterObjectValue(char, i);\n } else if (stack[stack.length - 1] === \"INSIDE_ARRAY_AFTER_VALUE\") {\n processAfterArrayValue(char, i);\n }\n } else {\n lastValidIndex = i;\n }\n\n break;\n }\n }\n }\n\n let result = input.slice(0, lastValidIndex + 1);\n\n for (let i = stack.length - 1; i >= 0; i--) {\n const state = stack[i];\n\n switch (state) {\n case \"INSIDE_STRING\": {\n result += '\"';\n break;\n }\n\n case \"INSIDE_OBJECT_KEY\":\n case \"INSIDE_OBJECT_AFTER_KEY\":\n case \"INSIDE_OBJECT_AFTER_COMMA\":\n case \"INSIDE_OBJECT_START\":\n case \"INSIDE_OBJECT_BEFORE_VALUE\":\n case \"INSIDE_OBJECT_AFTER_VALUE\": {\n result += \"}\";\n break;\n }\n\n case \"INSIDE_ARRAY_START\":\n case \"INSIDE_ARRAY_AFTER_COMMA\":\n case \"INSIDE_ARRAY_AFTER_VALUE\": {\n result += \"]\";\n break;\n }\n\n case \"INSIDE_LITERAL\": {\n const partialLiteral = input.substring(literalStart!, input.length);\n\n if (\"true\".startsWith(partialLiteral)) {\n result += \"true\".slice(partialLiteral.length);\n } else if (\"false\".startsWith(partialLiteral)) {\n result += \"false\".slice(partialLiteral.length);\n } else if (\"null\".startsWith(partialLiteral)) {\n result += \"null\".slice(partialLiteral.length);\n }\n }\n }\n }\n\n return [result, path];\n}\n"],"mappings":";AAAA,OAAO,WAAW;;;AC+DX,SAAS,QAAQ,OAAmC;AACzD,QAAM,QAAiB,CAAC,MAAM;AAC9B,MAAI,iBAAiB;AACrB,MAAI,eAA8B;AAClC,QAAM,OAAiB,CAAC;AACxB,MAAI;AAEJ,WAAS,uBAA6B;AACpC,QAAI,eAAe,QAAW;AAC5B,WAAK,KAAK,KAAK,MAAM,MAAM,aAAa,GAAG,CAAC;AAC5C,mBAAa;AAAA,IACf;AAAA,EACF;AAEA,WAAS,kBAAkB,MAAc,GAAW,WAAkB;AACpE;AACE,cAAQ,MAAM;AAAA,QACZ,KAAK,KAAK;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KAAK,EAAG,QAAO;AAEjE,QAAM,CAAC,cAAc,GAAG,eAAe,IAAI,WAAW;AAGtD,MAAI,UAAU,aAAc,QAAO;AAGnC,QAAM,QAAS,OAAmC,KAAK;AACvD,QAAM,YAAmC;AAAA,IACvC,OAAO;AAAA,IACP,aAAa;AAAA,EACf;AAEA,SAAO,cAAc,OAAO,WAAW,QAAQ;AACjD;AAEO,IAAM,iCAAiC,CAC5C,MACA,cACe;AACf,QAAM,OAAO,yBAAyB,IAAI;AAC1C,MAAI,CAAC,KAAM,OAAM,IAAI,MAAM,gCAAgC;AAE3D,SAAO,cAAc,MAAM,MAAM,UAAU,IAAI,MAAM,CAAC;AACxD;","names":[]}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { a as AssistantStreamChunk, T as ToolResponse,
|
|
2
|
-
export { e as createAssistantStream, f as createAssistantStreamResponse } from './assistant-stream-
|
|
1
|
+
import { a as AssistantStreamChunk, T as ToolResponse, c as AssistantMessage, d as AssistantStreamEncoder, A as AssistantStream } from './assistant-stream-ujRn7KXt.mjs';
|
|
2
|
+
export { e as createAssistantStream, f as createAssistantStreamResponse } from './assistant-stream-ujRn7KXt.mjs';
|
|
3
|
+
import { R as ReadonlyJSONValue } from './json-value-DvDjYV7y.mjs';
|
|
3
4
|
|
|
4
5
|
declare class PipeableTransformStream<I, O> extends TransformStream<I, O> {
|
|
5
6
|
constructor(transform: (readable: ReadableStream<I>) => ReadableStream<O>);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { a as AssistantStreamChunk, T as ToolResponse,
|
|
2
|
-
export { e as createAssistantStream, f as createAssistantStreamResponse } from './assistant-stream-
|
|
1
|
+
import { a as AssistantStreamChunk, T as ToolResponse, c as AssistantMessage, d as AssistantStreamEncoder, A as AssistantStream } from './assistant-stream-CgeUyrON.js';
|
|
2
|
+
export { e as createAssistantStream, f as createAssistantStreamResponse } from './assistant-stream-CgeUyrON.js';
|
|
3
|
+
import { R as ReadonlyJSONValue } from './json-value-DvDjYV7y.js';
|
|
3
4
|
|
|
4
5
|
declare class PipeableTransformStream<I, O> extends TransformStream<I, O> {
|
|
5
6
|
constructor(transform: (readable: ReadableStream<I>) => ReadableStream<O>);
|
package/dist/index.js
CHANGED
|
@@ -1097,7 +1097,7 @@ var ToolExecutionStream = class extends PipeableTransformStream {
|
|
|
1097
1097
|
}
|
|
1098
1098
|
};
|
|
1099
1099
|
|
|
1100
|
-
// src/core/utils/json/parse-partial-json.ts
|
|
1100
|
+
// src/core/utils/json/parse-partial-json-object.ts
|
|
1101
1101
|
var import_secure_json_parse2 = __toESM(require("secure-json-parse"));
|
|
1102
1102
|
|
|
1103
1103
|
// src/core/utils/json/fix-json.ts
|
|
@@ -1105,6 +1105,14 @@ function fixJson(input) {
|
|
|
1105
1105
|
const stack = ["ROOT"];
|
|
1106
1106
|
let lastValidIndex = -1;
|
|
1107
1107
|
let literalStart = null;
|
|
1108
|
+
const path = [];
|
|
1109
|
+
let currentKey;
|
|
1110
|
+
function pushCurrentKeyToPath() {
|
|
1111
|
+
if (currentKey !== void 0) {
|
|
1112
|
+
path.push(JSON.parse('"' + currentKey + '"'));
|
|
1113
|
+
currentKey = void 0;
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1108
1116
|
function processValueStart(char, i, swapState) {
|
|
1109
1117
|
{
|
|
1110
1118
|
switch (char) {
|
|
@@ -1113,6 +1121,7 @@ function fixJson(input) {
|
|
|
1113
1121
|
stack.pop();
|
|
1114
1122
|
stack.push(swapState);
|
|
1115
1123
|
stack.push("INSIDE_STRING");
|
|
1124
|
+
pushCurrentKeyToPath();
|
|
1116
1125
|
break;
|
|
1117
1126
|
}
|
|
1118
1127
|
case "f":
|
|
@@ -1129,6 +1138,7 @@ function fixJson(input) {
|
|
|
1129
1138
|
stack.pop();
|
|
1130
1139
|
stack.push(swapState);
|
|
1131
1140
|
stack.push("INSIDE_NUMBER");
|
|
1141
|
+
pushCurrentKeyToPath();
|
|
1132
1142
|
break;
|
|
1133
1143
|
}
|
|
1134
1144
|
case "0":
|
|
@@ -1145,6 +1155,7 @@ function fixJson(input) {
|
|
|
1145
1155
|
stack.pop();
|
|
1146
1156
|
stack.push(swapState);
|
|
1147
1157
|
stack.push("INSIDE_NUMBER");
|
|
1158
|
+
pushCurrentKeyToPath();
|
|
1148
1159
|
break;
|
|
1149
1160
|
}
|
|
1150
1161
|
case "{": {
|
|
@@ -1152,6 +1163,7 @@ function fixJson(input) {
|
|
|
1152
1163
|
stack.pop();
|
|
1153
1164
|
stack.push(swapState);
|
|
1154
1165
|
stack.push("INSIDE_OBJECT_START");
|
|
1166
|
+
pushCurrentKeyToPath();
|
|
1155
1167
|
break;
|
|
1156
1168
|
}
|
|
1157
1169
|
case "[": {
|
|
@@ -1159,6 +1171,7 @@ function fixJson(input) {
|
|
|
1159
1171
|
stack.pop();
|
|
1160
1172
|
stack.push(swapState);
|
|
1161
1173
|
stack.push("INSIDE_ARRAY_START");
|
|
1174
|
+
pushCurrentKeyToPath();
|
|
1162
1175
|
break;
|
|
1163
1176
|
}
|
|
1164
1177
|
}
|
|
@@ -1174,6 +1187,7 @@ function fixJson(input) {
|
|
|
1174
1187
|
case "}": {
|
|
1175
1188
|
lastValidIndex = i;
|
|
1176
1189
|
stack.pop();
|
|
1190
|
+
currentKey = path.pop();
|
|
1177
1191
|
break;
|
|
1178
1192
|
}
|
|
1179
1193
|
}
|
|
@@ -1183,11 +1197,13 @@ function fixJson(input) {
|
|
|
1183
1197
|
case ",": {
|
|
1184
1198
|
stack.pop();
|
|
1185
1199
|
stack.push("INSIDE_ARRAY_AFTER_COMMA");
|
|
1200
|
+
currentKey = (Number(currentKey) + 1).toString();
|
|
1186
1201
|
break;
|
|
1187
1202
|
}
|
|
1188
1203
|
case "]": {
|
|
1189
1204
|
lastValidIndex = i;
|
|
1190
1205
|
stack.pop();
|
|
1206
|
+
currentKey = path.pop();
|
|
1191
1207
|
break;
|
|
1192
1208
|
}
|
|
1193
1209
|
}
|
|
@@ -1204,11 +1220,13 @@ function fixJson(input) {
|
|
|
1204
1220
|
case '"': {
|
|
1205
1221
|
stack.pop();
|
|
1206
1222
|
stack.push("INSIDE_OBJECT_KEY");
|
|
1223
|
+
currentKey = "";
|
|
1207
1224
|
break;
|
|
1208
1225
|
}
|
|
1209
1226
|
case "}": {
|
|
1210
1227
|
lastValidIndex = i;
|
|
1211
1228
|
stack.pop();
|
|
1229
|
+
currentKey = path.pop();
|
|
1212
1230
|
break;
|
|
1213
1231
|
}
|
|
1214
1232
|
}
|
|
@@ -1219,6 +1237,7 @@ function fixJson(input) {
|
|
|
1219
1237
|
case '"': {
|
|
1220
1238
|
stack.pop();
|
|
1221
1239
|
stack.push("INSIDE_OBJECT_KEY");
|
|
1240
|
+
currentKey = "";
|
|
1222
1241
|
break;
|
|
1223
1242
|
}
|
|
1224
1243
|
}
|
|
@@ -1231,6 +1250,15 @@ function fixJson(input) {
|
|
|
1231
1250
|
stack.push("INSIDE_OBJECT_AFTER_KEY");
|
|
1232
1251
|
break;
|
|
1233
1252
|
}
|
|
1253
|
+
case "\\": {
|
|
1254
|
+
stack.push("INSIDE_STRING_ESCAPE");
|
|
1255
|
+
currentKey += char;
|
|
1256
|
+
break;
|
|
1257
|
+
}
|
|
1258
|
+
default: {
|
|
1259
|
+
currentKey += char;
|
|
1260
|
+
break;
|
|
1261
|
+
}
|
|
1234
1262
|
}
|
|
1235
1263
|
break;
|
|
1236
1264
|
}
|
|
@@ -1257,6 +1285,7 @@ function fixJson(input) {
|
|
|
1257
1285
|
case '"': {
|
|
1258
1286
|
stack.pop();
|
|
1259
1287
|
lastValidIndex = i;
|
|
1288
|
+
currentKey = path.pop();
|
|
1260
1289
|
break;
|
|
1261
1290
|
}
|
|
1262
1291
|
case "\\": {
|
|
@@ -1274,10 +1303,12 @@ function fixJson(input) {
|
|
|
1274
1303
|
case "]": {
|
|
1275
1304
|
lastValidIndex = i;
|
|
1276
1305
|
stack.pop();
|
|
1306
|
+
currentKey = path.pop();
|
|
1277
1307
|
break;
|
|
1278
1308
|
}
|
|
1279
1309
|
default: {
|
|
1280
1310
|
lastValidIndex = i;
|
|
1311
|
+
currentKey = "0";
|
|
1281
1312
|
processValueStart(char, i, "INSIDE_ARRAY_AFTER_VALUE");
|
|
1282
1313
|
break;
|
|
1283
1314
|
}
|
|
@@ -1289,11 +1320,13 @@ function fixJson(input) {
|
|
|
1289
1320
|
case ",": {
|
|
1290
1321
|
stack.pop();
|
|
1291
1322
|
stack.push("INSIDE_ARRAY_AFTER_COMMA");
|
|
1323
|
+
currentKey = (Number(currentKey) + 1).toString();
|
|
1292
1324
|
break;
|
|
1293
1325
|
}
|
|
1294
1326
|
case "]": {
|
|
1295
1327
|
lastValidIndex = i;
|
|
1296
1328
|
stack.pop();
|
|
1329
|
+
currentKey = path.pop();
|
|
1297
1330
|
break;
|
|
1298
1331
|
}
|
|
1299
1332
|
default: {
|
|
@@ -1309,7 +1342,11 @@ function fixJson(input) {
|
|
|
1309
1342
|
}
|
|
1310
1343
|
case "INSIDE_STRING_ESCAPE": {
|
|
1311
1344
|
stack.pop();
|
|
1312
|
-
|
|
1345
|
+
if (stack[stack.length - 1] === "INSIDE_STRING") {
|
|
1346
|
+
lastValidIndex = i;
|
|
1347
|
+
} else if (stack[stack.length - 1] === "INSIDE_OBJECT_KEY") {
|
|
1348
|
+
currentKey += char;
|
|
1349
|
+
}
|
|
1313
1350
|
break;
|
|
1314
1351
|
}
|
|
1315
1352
|
case "INSIDE_NUMBER": {
|
|
@@ -1335,6 +1372,7 @@ function fixJson(input) {
|
|
|
1335
1372
|
}
|
|
1336
1373
|
case ",": {
|
|
1337
1374
|
stack.pop();
|
|
1375
|
+
currentKey = path.pop();
|
|
1338
1376
|
if (stack[stack.length - 1] === "INSIDE_ARRAY_AFTER_VALUE") {
|
|
1339
1377
|
processAfterArrayValue(char, i);
|
|
1340
1378
|
}
|
|
@@ -1345,6 +1383,7 @@ function fixJson(input) {
|
|
|
1345
1383
|
}
|
|
1346
1384
|
case "}": {
|
|
1347
1385
|
stack.pop();
|
|
1386
|
+
currentKey = path.pop();
|
|
1348
1387
|
if (stack[stack.length - 1] === "INSIDE_OBJECT_AFTER_VALUE") {
|
|
1349
1388
|
processAfterObjectValue(char, i);
|
|
1350
1389
|
}
|
|
@@ -1352,6 +1391,7 @@ function fixJson(input) {
|
|
|
1352
1391
|
}
|
|
1353
1392
|
case "]": {
|
|
1354
1393
|
stack.pop();
|
|
1394
|
+
currentKey = path.pop();
|
|
1355
1395
|
if (stack[stack.length - 1] === "INSIDE_ARRAY_AFTER_VALUE") {
|
|
1356
1396
|
processAfterArrayValue(char, i);
|
|
1357
1397
|
}
|
|
@@ -1359,6 +1399,7 @@ function fixJson(input) {
|
|
|
1359
1399
|
}
|
|
1360
1400
|
default: {
|
|
1361
1401
|
stack.pop();
|
|
1402
|
+
currentKey = path.pop();
|
|
1362
1403
|
break;
|
|
1363
1404
|
}
|
|
1364
1405
|
}
|
|
@@ -1415,16 +1456,38 @@ function fixJson(input) {
|
|
|
1415
1456
|
}
|
|
1416
1457
|
}
|
|
1417
1458
|
}
|
|
1418
|
-
return result;
|
|
1459
|
+
return [result, path];
|
|
1419
1460
|
}
|
|
1420
1461
|
|
|
1421
|
-
// src/core/utils/json/parse-partial-json.ts
|
|
1422
|
-
var
|
|
1462
|
+
// src/core/utils/json/parse-partial-json-object.ts
|
|
1463
|
+
var PARTIAL_JSON_OBJECT_META_SYMBOL = Symbol(
|
|
1464
|
+
"aui.parse-partial-json-object.meta"
|
|
1465
|
+
);
|
|
1466
|
+
var parsePartialJsonObject = (json) => {
|
|
1467
|
+
if (json.length === 0)
|
|
1468
|
+
return {
|
|
1469
|
+
[PARTIAL_JSON_OBJECT_META_SYMBOL]: { state: "partial", partialPath: [] }
|
|
1470
|
+
};
|
|
1423
1471
|
try {
|
|
1424
|
-
|
|
1472
|
+
const res = import_secure_json_parse2.default.parse(json);
|
|
1473
|
+
if (typeof res !== "object" || res === null)
|
|
1474
|
+
throw new Error("argsText is expected to be an object");
|
|
1475
|
+
res[PARTIAL_JSON_OBJECT_META_SYMBOL] = {
|
|
1476
|
+
state: "complete",
|
|
1477
|
+
partialPath: []
|
|
1478
|
+
};
|
|
1479
|
+
return res;
|
|
1425
1480
|
} catch {
|
|
1426
1481
|
try {
|
|
1427
|
-
|
|
1482
|
+
const [fixedJson, partialPath] = fixJson(json);
|
|
1483
|
+
const res = import_secure_json_parse2.default.parse(fixedJson);
|
|
1484
|
+
if (typeof res !== "object" || res === null)
|
|
1485
|
+
throw new Error("argsText is expected to be an object");
|
|
1486
|
+
res[PARTIAL_JSON_OBJECT_META_SYMBOL] = {
|
|
1487
|
+
state: "partial",
|
|
1488
|
+
partialPath
|
|
1489
|
+
};
|
|
1490
|
+
return res;
|
|
1428
1491
|
} catch {
|
|
1429
1492
|
return void 0;
|
|
1430
1493
|
}
|
|
@@ -1553,12 +1616,7 @@ var handleTextDelta = (message, chunk) => {
|
|
|
1553
1616
|
return { ...part, text: part.text + chunk.textDelta };
|
|
1554
1617
|
} else if (part.type === "tool-call") {
|
|
1555
1618
|
const newArgsText = part.argsText + chunk.textDelta;
|
|
1556
|
-
|
|
1557
|
-
try {
|
|
1558
|
-
newArgs = parsePartialJson(newArgsText);
|
|
1559
|
-
} catch (err) {
|
|
1560
|
-
newArgs = part.args;
|
|
1561
|
-
}
|
|
1619
|
+
const newArgs = parsePartialJsonObject(newArgsText) ?? part.args;
|
|
1562
1620
|
return { ...part, argsText: newArgsText, args: newArgs };
|
|
1563
1621
|
} else {
|
|
1564
1622
|
throw new Error(
|