@assistant-ui/react-langgraph 0.2.5 → 0.2.6
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/index.d.mts +37 -7
- package/dist/index.d.ts +37 -7
- package/dist/index.js +561 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +571 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
9
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
+
};
|
|
6
11
|
var __export = (target, all) => {
|
|
7
12
|
for (var name in all)
|
|
8
13
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -15,12 +20,127 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
20
|
}
|
|
16
21
|
return to;
|
|
17
22
|
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
+
mod
|
|
30
|
+
));
|
|
18
31
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
32
|
|
|
33
|
+
// ../../node_modules/.pnpm/secure-json-parse@3.0.2/node_modules/secure-json-parse/index.js
|
|
34
|
+
var require_secure_json_parse = __commonJS({
|
|
35
|
+
"../../node_modules/.pnpm/secure-json-parse@3.0.2/node_modules/secure-json-parse/index.js"(exports2, module2) {
|
|
36
|
+
"use strict";
|
|
37
|
+
var hasBuffer = typeof Buffer !== "undefined";
|
|
38
|
+
var suspectProtoRx = /"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/;
|
|
39
|
+
var suspectConstructorRx = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;
|
|
40
|
+
function _parse(text, reviver, options) {
|
|
41
|
+
if (options == null) {
|
|
42
|
+
if (reviver !== null && typeof reviver === "object") {
|
|
43
|
+
options = reviver;
|
|
44
|
+
reviver = void 0;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (hasBuffer && Buffer.isBuffer(text)) {
|
|
48
|
+
text = text.toString();
|
|
49
|
+
}
|
|
50
|
+
if (text && text.charCodeAt(0) === 65279) {
|
|
51
|
+
text = text.slice(1);
|
|
52
|
+
}
|
|
53
|
+
const obj = JSON.parse(text, reviver);
|
|
54
|
+
if (obj === null || typeof obj !== "object") {
|
|
55
|
+
return obj;
|
|
56
|
+
}
|
|
57
|
+
const protoAction = options && options.protoAction || "error";
|
|
58
|
+
const constructorAction = options && options.constructorAction || "error";
|
|
59
|
+
if (protoAction === "ignore" && constructorAction === "ignore") {
|
|
60
|
+
return obj;
|
|
61
|
+
}
|
|
62
|
+
if (protoAction !== "ignore" && constructorAction !== "ignore") {
|
|
63
|
+
if (suspectProtoRx.test(text) === false && suspectConstructorRx.test(text) === false) {
|
|
64
|
+
return obj;
|
|
65
|
+
}
|
|
66
|
+
} else if (protoAction !== "ignore" && constructorAction === "ignore") {
|
|
67
|
+
if (suspectProtoRx.test(text) === false) {
|
|
68
|
+
return obj;
|
|
69
|
+
}
|
|
70
|
+
} else {
|
|
71
|
+
if (suspectConstructorRx.test(text) === false) {
|
|
72
|
+
return obj;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return filter(obj, { protoAction, constructorAction, safe: options && options.safe });
|
|
76
|
+
}
|
|
77
|
+
function filter(obj, { protoAction = "error", constructorAction = "error", safe } = {}) {
|
|
78
|
+
let next = [obj];
|
|
79
|
+
while (next.length) {
|
|
80
|
+
const nodes = next;
|
|
81
|
+
next = [];
|
|
82
|
+
for (const node of nodes) {
|
|
83
|
+
if (protoAction !== "ignore" && Object.prototype.hasOwnProperty.call(node, "__proto__")) {
|
|
84
|
+
if (safe === true) {
|
|
85
|
+
return null;
|
|
86
|
+
} else if (protoAction === "error") {
|
|
87
|
+
throw new SyntaxError("Object contains forbidden prototype property");
|
|
88
|
+
}
|
|
89
|
+
delete node.__proto__;
|
|
90
|
+
}
|
|
91
|
+
if (constructorAction !== "ignore" && Object.prototype.hasOwnProperty.call(node, "constructor") && Object.prototype.hasOwnProperty.call(node.constructor, "prototype")) {
|
|
92
|
+
if (safe === true) {
|
|
93
|
+
return null;
|
|
94
|
+
} else if (constructorAction === "error") {
|
|
95
|
+
throw new SyntaxError("Object contains forbidden prototype property");
|
|
96
|
+
}
|
|
97
|
+
delete node.constructor;
|
|
98
|
+
}
|
|
99
|
+
for (const key in node) {
|
|
100
|
+
const value = node[key];
|
|
101
|
+
if (value && typeof value === "object") {
|
|
102
|
+
next.push(value);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return obj;
|
|
108
|
+
}
|
|
109
|
+
function parse(text, reviver, options) {
|
|
110
|
+
const { stackTraceLimit } = Error;
|
|
111
|
+
Error.stackTraceLimit = 0;
|
|
112
|
+
try {
|
|
113
|
+
return _parse(text, reviver, options);
|
|
114
|
+
} finally {
|
|
115
|
+
Error.stackTraceLimit = stackTraceLimit;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function safeParse(text, reviver) {
|
|
119
|
+
const { stackTraceLimit } = Error;
|
|
120
|
+
Error.stackTraceLimit = 0;
|
|
121
|
+
try {
|
|
122
|
+
return _parse(text, reviver, { safe: true });
|
|
123
|
+
} catch (_e) {
|
|
124
|
+
return null;
|
|
125
|
+
} finally {
|
|
126
|
+
Error.stackTraceLimit = stackTraceLimit;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
module2.exports = parse;
|
|
130
|
+
module2.exports.default = parse;
|
|
131
|
+
module2.exports.parse = parse;
|
|
132
|
+
module2.exports.safeParse = safeParse;
|
|
133
|
+
module2.exports.scan = filter;
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
|
|
20
137
|
// src/index.ts
|
|
21
138
|
var index_exports = {};
|
|
22
139
|
__export(index_exports, {
|
|
23
|
-
|
|
140
|
+
LangGraphMessageAccumulator: () => LangGraphMessageAccumulator,
|
|
141
|
+
appendLangChainChunk: () => appendLangChainChunk,
|
|
142
|
+
convertLangChainMessages: () => convertLangChainMessages,
|
|
143
|
+
convertLangchainMessages: () => convertLangChainMessages,
|
|
24
144
|
useLangGraphInterruptState: () => useLangGraphInterruptState,
|
|
25
145
|
useLangGraphMessages: () => useLangGraphMessages,
|
|
26
146
|
useLangGraphRuntime: () => useLangGraphRuntime,
|
|
@@ -33,7 +153,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
33
153
|
var import_react2 = require("react");
|
|
34
154
|
var import_react3 = require("@assistant-ui/react");
|
|
35
155
|
|
|
36
|
-
// src/
|
|
156
|
+
// src/convertLangChainMessages.ts
|
|
37
157
|
var contentToParts = (content) => {
|
|
38
158
|
if (typeof content === "string")
|
|
39
159
|
return [{ type: "text", text: content }];
|
|
@@ -59,7 +179,7 @@ var contentToParts = (content) => {
|
|
|
59
179
|
}
|
|
60
180
|
}).filter((a) => a !== null);
|
|
61
181
|
};
|
|
62
|
-
var
|
|
182
|
+
var convertLangChainMessages = (message) => {
|
|
63
183
|
switch (message.type) {
|
|
64
184
|
case "system":
|
|
65
185
|
return {
|
|
@@ -102,25 +222,59 @@ var convertLangchainMessages = (message) => {
|
|
|
102
222
|
|
|
103
223
|
// src/useLangGraphMessages.ts
|
|
104
224
|
var import_react = require("react");
|
|
225
|
+
var import_uuid2 = require("uuid");
|
|
226
|
+
|
|
227
|
+
// src/LangGraphMessageAccumulator.ts
|
|
105
228
|
var import_uuid = require("uuid");
|
|
229
|
+
var LangGraphMessageAccumulator = class {
|
|
230
|
+
messagesMap = /* @__PURE__ */ new Map();
|
|
231
|
+
appendMessage;
|
|
232
|
+
constructor({
|
|
233
|
+
initialMessages = [],
|
|
234
|
+
appendMessage = (_, curr) => curr
|
|
235
|
+
} = {}) {
|
|
236
|
+
this.appendMessage = appendMessage;
|
|
237
|
+
this.addMessages(initialMessages);
|
|
238
|
+
}
|
|
239
|
+
ensureMessageId(message) {
|
|
240
|
+
return message.id ? message : { ...message, id: (0, import_uuid.v4)() };
|
|
241
|
+
}
|
|
242
|
+
addMessages(newMessages) {
|
|
243
|
+
if (newMessages.length === 0) return this.getMessages();
|
|
244
|
+
for (const message of newMessages.map(this.ensureMessageId)) {
|
|
245
|
+
const previous = message.id ? this.messagesMap.get(message.id) : void 0;
|
|
246
|
+
this.messagesMap.set(
|
|
247
|
+
message.id ?? (0, import_uuid.v4)(),
|
|
248
|
+
this.appendMessage(previous, message)
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
return this.getMessages();
|
|
252
|
+
}
|
|
253
|
+
getMessages() {
|
|
254
|
+
return [...this.messagesMap.values()];
|
|
255
|
+
}
|
|
256
|
+
clear() {
|
|
257
|
+
this.messagesMap.clear();
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
// src/useLangGraphMessages.ts
|
|
262
|
+
var DEFAULT_APPEND_MESSAGE = (_, curr) => curr;
|
|
106
263
|
var useLangGraphMessages = ({
|
|
107
|
-
stream
|
|
264
|
+
stream,
|
|
265
|
+
appendMessage = DEFAULT_APPEND_MESSAGE
|
|
108
266
|
}) => {
|
|
109
267
|
const [interrupt, setInterrupt] = (0, import_react.useState)();
|
|
110
268
|
const [messages, setMessages] = (0, import_react.useState)([]);
|
|
111
269
|
const abortControllerRef = (0, import_react.useRef)(null);
|
|
112
270
|
const sendMessage = (0, import_react.useCallback)(
|
|
113
271
|
async (newMessages, config) => {
|
|
114
|
-
newMessages = newMessages.map((m) => m.id ? m : { ...m, id: (0,
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
setMessages([...messagesMap.values()]);
|
|
122
|
-
};
|
|
123
|
-
addMessages([...messages, ...newMessages]);
|
|
272
|
+
newMessages = newMessages.map((m) => m.id ? m : { ...m, id: (0, import_uuid2.v4)() });
|
|
273
|
+
const accumulator = new LangGraphMessageAccumulator({
|
|
274
|
+
initialMessages: messages,
|
|
275
|
+
appendMessage
|
|
276
|
+
});
|
|
277
|
+
setMessages(accumulator.addMessages(newMessages));
|
|
124
278
|
const abortController = new AbortController();
|
|
125
279
|
abortControllerRef.current = abortController;
|
|
126
280
|
const response = await stream(newMessages, {
|
|
@@ -129,13 +283,13 @@ var useLangGraphMessages = ({
|
|
|
129
283
|
});
|
|
130
284
|
for await (const chunk of response) {
|
|
131
285
|
if (chunk.event === "messages/partial" || chunk.event === "messages/complete") {
|
|
132
|
-
addMessages(chunk.data);
|
|
286
|
+
setMessages(accumulator.addMessages(chunk.data));
|
|
133
287
|
} else if (chunk.event === "updates") {
|
|
134
288
|
setInterrupt(chunk.data.__interrupt__?.[0]);
|
|
135
289
|
}
|
|
136
290
|
}
|
|
137
291
|
},
|
|
138
|
-
[messages, stream]
|
|
292
|
+
[messages, stream, appendMessage]
|
|
139
293
|
);
|
|
140
294
|
const cancel = (0, import_react.useCallback)(() => {
|
|
141
295
|
if (abortControllerRef.current) {
|
|
@@ -154,6 +308,392 @@ var useLangGraphMessages = ({
|
|
|
154
308
|
|
|
155
309
|
// src/useLangGraphRuntime.ts
|
|
156
310
|
var import_react4 = require("@assistant-ui/react");
|
|
311
|
+
|
|
312
|
+
// ../react/src/utils/json/parse-partial-json.ts
|
|
313
|
+
var import_secure_json_parse = __toESM(require_secure_json_parse());
|
|
314
|
+
|
|
315
|
+
// ../react/src/utils/json/fix-json.ts
|
|
316
|
+
function fixJson(input) {
|
|
317
|
+
const stack = ["ROOT"];
|
|
318
|
+
let lastValidIndex = -1;
|
|
319
|
+
let literalStart = null;
|
|
320
|
+
function processValueStart(char, i, swapState) {
|
|
321
|
+
{
|
|
322
|
+
switch (char) {
|
|
323
|
+
case '"': {
|
|
324
|
+
lastValidIndex = i;
|
|
325
|
+
stack.pop();
|
|
326
|
+
stack.push(swapState);
|
|
327
|
+
stack.push("INSIDE_STRING");
|
|
328
|
+
break;
|
|
329
|
+
}
|
|
330
|
+
case "f":
|
|
331
|
+
case "t":
|
|
332
|
+
case "n": {
|
|
333
|
+
lastValidIndex = i;
|
|
334
|
+
literalStart = i;
|
|
335
|
+
stack.pop();
|
|
336
|
+
stack.push(swapState);
|
|
337
|
+
stack.push("INSIDE_LITERAL");
|
|
338
|
+
break;
|
|
339
|
+
}
|
|
340
|
+
case "-": {
|
|
341
|
+
stack.pop();
|
|
342
|
+
stack.push(swapState);
|
|
343
|
+
stack.push("INSIDE_NUMBER");
|
|
344
|
+
break;
|
|
345
|
+
}
|
|
346
|
+
case "0":
|
|
347
|
+
case "1":
|
|
348
|
+
case "2":
|
|
349
|
+
case "3":
|
|
350
|
+
case "4":
|
|
351
|
+
case "5":
|
|
352
|
+
case "6":
|
|
353
|
+
case "7":
|
|
354
|
+
case "8":
|
|
355
|
+
case "9": {
|
|
356
|
+
lastValidIndex = i;
|
|
357
|
+
stack.pop();
|
|
358
|
+
stack.push(swapState);
|
|
359
|
+
stack.push("INSIDE_NUMBER");
|
|
360
|
+
break;
|
|
361
|
+
}
|
|
362
|
+
case "{": {
|
|
363
|
+
lastValidIndex = i;
|
|
364
|
+
stack.pop();
|
|
365
|
+
stack.push(swapState);
|
|
366
|
+
stack.push("INSIDE_OBJECT_START");
|
|
367
|
+
break;
|
|
368
|
+
}
|
|
369
|
+
case "[": {
|
|
370
|
+
lastValidIndex = i;
|
|
371
|
+
stack.pop();
|
|
372
|
+
stack.push(swapState);
|
|
373
|
+
stack.push("INSIDE_ARRAY_START");
|
|
374
|
+
break;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
function processAfterObjectValue(char, i) {
|
|
380
|
+
switch (char) {
|
|
381
|
+
case ",": {
|
|
382
|
+
stack.pop();
|
|
383
|
+
stack.push("INSIDE_OBJECT_AFTER_COMMA");
|
|
384
|
+
break;
|
|
385
|
+
}
|
|
386
|
+
case "}": {
|
|
387
|
+
lastValidIndex = i;
|
|
388
|
+
stack.pop();
|
|
389
|
+
break;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
function processAfterArrayValue(char, i) {
|
|
394
|
+
switch (char) {
|
|
395
|
+
case ",": {
|
|
396
|
+
stack.pop();
|
|
397
|
+
stack.push("INSIDE_ARRAY_AFTER_COMMA");
|
|
398
|
+
break;
|
|
399
|
+
}
|
|
400
|
+
case "]": {
|
|
401
|
+
lastValidIndex = i;
|
|
402
|
+
stack.pop();
|
|
403
|
+
break;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
for (let i = 0; i < input.length; i++) {
|
|
408
|
+
const char = input[i];
|
|
409
|
+
const currentState = stack[stack.length - 1];
|
|
410
|
+
switch (currentState) {
|
|
411
|
+
case "ROOT":
|
|
412
|
+
processValueStart(char, i, "FINISH");
|
|
413
|
+
break;
|
|
414
|
+
case "INSIDE_OBJECT_START": {
|
|
415
|
+
switch (char) {
|
|
416
|
+
case '"': {
|
|
417
|
+
stack.pop();
|
|
418
|
+
stack.push("INSIDE_OBJECT_KEY");
|
|
419
|
+
break;
|
|
420
|
+
}
|
|
421
|
+
case "}": {
|
|
422
|
+
lastValidIndex = i;
|
|
423
|
+
stack.pop();
|
|
424
|
+
break;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
break;
|
|
428
|
+
}
|
|
429
|
+
case "INSIDE_OBJECT_AFTER_COMMA": {
|
|
430
|
+
switch (char) {
|
|
431
|
+
case '"': {
|
|
432
|
+
stack.pop();
|
|
433
|
+
stack.push("INSIDE_OBJECT_KEY");
|
|
434
|
+
break;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
break;
|
|
438
|
+
}
|
|
439
|
+
case "INSIDE_OBJECT_KEY": {
|
|
440
|
+
switch (char) {
|
|
441
|
+
case '"': {
|
|
442
|
+
stack.pop();
|
|
443
|
+
stack.push("INSIDE_OBJECT_AFTER_KEY");
|
|
444
|
+
break;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
break;
|
|
448
|
+
}
|
|
449
|
+
case "INSIDE_OBJECT_AFTER_KEY": {
|
|
450
|
+
switch (char) {
|
|
451
|
+
case ":": {
|
|
452
|
+
stack.pop();
|
|
453
|
+
stack.push("INSIDE_OBJECT_BEFORE_VALUE");
|
|
454
|
+
break;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
break;
|
|
458
|
+
}
|
|
459
|
+
case "INSIDE_OBJECT_BEFORE_VALUE": {
|
|
460
|
+
processValueStart(char, i, "INSIDE_OBJECT_AFTER_VALUE");
|
|
461
|
+
break;
|
|
462
|
+
}
|
|
463
|
+
case "INSIDE_OBJECT_AFTER_VALUE": {
|
|
464
|
+
processAfterObjectValue(char, i);
|
|
465
|
+
break;
|
|
466
|
+
}
|
|
467
|
+
case "INSIDE_STRING": {
|
|
468
|
+
switch (char) {
|
|
469
|
+
case '"': {
|
|
470
|
+
stack.pop();
|
|
471
|
+
lastValidIndex = i;
|
|
472
|
+
break;
|
|
473
|
+
}
|
|
474
|
+
case "\\": {
|
|
475
|
+
stack.push("INSIDE_STRING_ESCAPE");
|
|
476
|
+
break;
|
|
477
|
+
}
|
|
478
|
+
default: {
|
|
479
|
+
lastValidIndex = i;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
break;
|
|
483
|
+
}
|
|
484
|
+
case "INSIDE_ARRAY_START": {
|
|
485
|
+
switch (char) {
|
|
486
|
+
case "]": {
|
|
487
|
+
lastValidIndex = i;
|
|
488
|
+
stack.pop();
|
|
489
|
+
break;
|
|
490
|
+
}
|
|
491
|
+
default: {
|
|
492
|
+
lastValidIndex = i;
|
|
493
|
+
processValueStart(char, i, "INSIDE_ARRAY_AFTER_VALUE");
|
|
494
|
+
break;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
break;
|
|
498
|
+
}
|
|
499
|
+
case "INSIDE_ARRAY_AFTER_VALUE": {
|
|
500
|
+
switch (char) {
|
|
501
|
+
case ",": {
|
|
502
|
+
stack.pop();
|
|
503
|
+
stack.push("INSIDE_ARRAY_AFTER_COMMA");
|
|
504
|
+
break;
|
|
505
|
+
}
|
|
506
|
+
case "]": {
|
|
507
|
+
lastValidIndex = i;
|
|
508
|
+
stack.pop();
|
|
509
|
+
break;
|
|
510
|
+
}
|
|
511
|
+
default: {
|
|
512
|
+
lastValidIndex = i;
|
|
513
|
+
break;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
break;
|
|
517
|
+
}
|
|
518
|
+
case "INSIDE_ARRAY_AFTER_COMMA": {
|
|
519
|
+
processValueStart(char, i, "INSIDE_ARRAY_AFTER_VALUE");
|
|
520
|
+
break;
|
|
521
|
+
}
|
|
522
|
+
case "INSIDE_STRING_ESCAPE": {
|
|
523
|
+
stack.pop();
|
|
524
|
+
lastValidIndex = i;
|
|
525
|
+
break;
|
|
526
|
+
}
|
|
527
|
+
case "INSIDE_NUMBER": {
|
|
528
|
+
switch (char) {
|
|
529
|
+
case "0":
|
|
530
|
+
case "1":
|
|
531
|
+
case "2":
|
|
532
|
+
case "3":
|
|
533
|
+
case "4":
|
|
534
|
+
case "5":
|
|
535
|
+
case "6":
|
|
536
|
+
case "7":
|
|
537
|
+
case "8":
|
|
538
|
+
case "9": {
|
|
539
|
+
lastValidIndex = i;
|
|
540
|
+
break;
|
|
541
|
+
}
|
|
542
|
+
case "e":
|
|
543
|
+
case "E":
|
|
544
|
+
case "-":
|
|
545
|
+
case ".": {
|
|
546
|
+
break;
|
|
547
|
+
}
|
|
548
|
+
case ",": {
|
|
549
|
+
stack.pop();
|
|
550
|
+
if (stack[stack.length - 1] === "INSIDE_ARRAY_AFTER_VALUE") {
|
|
551
|
+
processAfterArrayValue(char, i);
|
|
552
|
+
}
|
|
553
|
+
if (stack[stack.length - 1] === "INSIDE_OBJECT_AFTER_VALUE") {
|
|
554
|
+
processAfterObjectValue(char, i);
|
|
555
|
+
}
|
|
556
|
+
break;
|
|
557
|
+
}
|
|
558
|
+
case "}": {
|
|
559
|
+
stack.pop();
|
|
560
|
+
if (stack[stack.length - 1] === "INSIDE_OBJECT_AFTER_VALUE") {
|
|
561
|
+
processAfterObjectValue(char, i);
|
|
562
|
+
}
|
|
563
|
+
break;
|
|
564
|
+
}
|
|
565
|
+
case "]": {
|
|
566
|
+
stack.pop();
|
|
567
|
+
if (stack[stack.length - 1] === "INSIDE_ARRAY_AFTER_VALUE") {
|
|
568
|
+
processAfterArrayValue(char, i);
|
|
569
|
+
}
|
|
570
|
+
break;
|
|
571
|
+
}
|
|
572
|
+
default: {
|
|
573
|
+
stack.pop();
|
|
574
|
+
break;
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
break;
|
|
578
|
+
}
|
|
579
|
+
case "INSIDE_LITERAL": {
|
|
580
|
+
const partialLiteral = input.substring(literalStart, i + 1);
|
|
581
|
+
if (!"false".startsWith(partialLiteral) && !"true".startsWith(partialLiteral) && !"null".startsWith(partialLiteral)) {
|
|
582
|
+
stack.pop();
|
|
583
|
+
if (stack[stack.length - 1] === "INSIDE_OBJECT_AFTER_VALUE") {
|
|
584
|
+
processAfterObjectValue(char, i);
|
|
585
|
+
} else if (stack[stack.length - 1] === "INSIDE_ARRAY_AFTER_VALUE") {
|
|
586
|
+
processAfterArrayValue(char, i);
|
|
587
|
+
}
|
|
588
|
+
} else {
|
|
589
|
+
lastValidIndex = i;
|
|
590
|
+
}
|
|
591
|
+
break;
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
let result = input.slice(0, lastValidIndex + 1);
|
|
596
|
+
let partialCount = 0;
|
|
597
|
+
for (let i = stack.length - 1; i >= 0; i--) {
|
|
598
|
+
const state = stack[i];
|
|
599
|
+
switch (state) {
|
|
600
|
+
case "INSIDE_STRING": {
|
|
601
|
+
result += '"';
|
|
602
|
+
partialCount++;
|
|
603
|
+
break;
|
|
604
|
+
}
|
|
605
|
+
case "INSIDE_OBJECT_KEY":
|
|
606
|
+
case "INSIDE_OBJECT_AFTER_KEY":
|
|
607
|
+
case "INSIDE_OBJECT_AFTER_COMMA":
|
|
608
|
+
case "INSIDE_OBJECT_START":
|
|
609
|
+
case "INSIDE_OBJECT_BEFORE_VALUE":
|
|
610
|
+
case "INSIDE_OBJECT_AFTER_VALUE": {
|
|
611
|
+
result += "}";
|
|
612
|
+
partialCount++;
|
|
613
|
+
break;
|
|
614
|
+
}
|
|
615
|
+
case "INSIDE_ARRAY_START":
|
|
616
|
+
case "INSIDE_ARRAY_AFTER_COMMA":
|
|
617
|
+
case "INSIDE_ARRAY_AFTER_VALUE": {
|
|
618
|
+
result += "]";
|
|
619
|
+
partialCount++;
|
|
620
|
+
break;
|
|
621
|
+
}
|
|
622
|
+
case "INSIDE_LITERAL": {
|
|
623
|
+
const partialLiteral = input.substring(literalStart, input.length);
|
|
624
|
+
if ("true".startsWith(partialLiteral)) {
|
|
625
|
+
result += "true".slice(partialLiteral.length);
|
|
626
|
+
} else if ("false".startsWith(partialLiteral)) {
|
|
627
|
+
result += "false".slice(partialLiteral.length);
|
|
628
|
+
} else if ("null".startsWith(partialLiteral)) {
|
|
629
|
+
result += "null".slice(partialLiteral.length);
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
return [result, partialCount];
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
// ../react/src/utils/json/parse-partial-json.ts
|
|
638
|
+
var PARTIAL_JSON_COUNT_SYMBOL = Symbol("partial-json-count");
|
|
639
|
+
var parsePartialJson = (json) => {
|
|
640
|
+
try {
|
|
641
|
+
return import_secure_json_parse.default.parse(json);
|
|
642
|
+
} catch {
|
|
643
|
+
try {
|
|
644
|
+
const [fixedJson, partialCount] = fixJson(json);
|
|
645
|
+
const res = import_secure_json_parse.default.parse(fixedJson);
|
|
646
|
+
res[PARTIAL_JSON_COUNT_SYMBOL] = partialCount;
|
|
647
|
+
return res;
|
|
648
|
+
} catch {
|
|
649
|
+
return void 0;
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
};
|
|
653
|
+
var COMPLETE_STATUS = Object.freeze({ type: "complete" });
|
|
654
|
+
|
|
655
|
+
// src/appendLangChainChunk.ts
|
|
656
|
+
var appendLangChainChunk = (prev, curr) => {
|
|
657
|
+
if (curr.type !== "AIMessageChunk") {
|
|
658
|
+
return curr;
|
|
659
|
+
}
|
|
660
|
+
if (!prev || prev.type !== "ai") {
|
|
661
|
+
return {
|
|
662
|
+
...curr,
|
|
663
|
+
type: curr.type.replace("MessageChunk", "").toLowerCase()
|
|
664
|
+
};
|
|
665
|
+
}
|
|
666
|
+
const newContent = typeof prev.content === "string" ? [{ type: "text", text: prev.content }] : [...prev.content];
|
|
667
|
+
for (const chunk of curr.content) {
|
|
668
|
+
if (chunk.type === "text") {
|
|
669
|
+
const existing = newContent[chunk.index] ?? { type: "text", text: "" };
|
|
670
|
+
if (existing.type !== "text") throw new Error("");
|
|
671
|
+
newContent[chunk.index] = {
|
|
672
|
+
...existing,
|
|
673
|
+
...chunk,
|
|
674
|
+
text: existing.text + chunk.text
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
const newToolCalls = [...prev.tool_calls ?? []];
|
|
679
|
+
for (const chunk of curr.tool_call_chunks) {
|
|
680
|
+
const existing = newToolCalls[chunk.index - 1] ?? { argsText: "" };
|
|
681
|
+
const newArgsText = existing.argsText + chunk.args;
|
|
682
|
+
newToolCalls[chunk.index - 1] = {
|
|
683
|
+
...chunk,
|
|
684
|
+
...existing,
|
|
685
|
+
argsText: newArgsText,
|
|
686
|
+
args: parsePartialJson(newArgsText)
|
|
687
|
+
};
|
|
688
|
+
}
|
|
689
|
+
return {
|
|
690
|
+
...prev,
|
|
691
|
+
content: newContent,
|
|
692
|
+
tool_calls: newToolCalls
|
|
693
|
+
};
|
|
694
|
+
};
|
|
695
|
+
|
|
696
|
+
// src/useLangGraphRuntime.ts
|
|
157
697
|
var getPendingToolCalls = (messages) => {
|
|
158
698
|
const pendingToolCalls = /* @__PURE__ */ new Map();
|
|
159
699
|
for (const message of messages) {
|
|
@@ -232,6 +772,7 @@ var useLangGraphRuntime = ({
|
|
|
232
772
|
cancel,
|
|
233
773
|
setMessages
|
|
234
774
|
} = useLangGraphMessages({
|
|
775
|
+
appendMessage: appendLangChainChunk,
|
|
235
776
|
stream
|
|
236
777
|
});
|
|
237
778
|
const [isRunning, setIsRunning] = (0, import_react2.useState)(false);
|
|
@@ -246,7 +787,7 @@ var useLangGraphRuntime = ({
|
|
|
246
787
|
}
|
|
247
788
|
};
|
|
248
789
|
const threadMessages = (0, import_react3.useExternalMessageConverter)({
|
|
249
|
-
callback:
|
|
790
|
+
callback: convertLangChainMessages,
|
|
250
791
|
messages,
|
|
251
792
|
isRunning
|
|
252
793
|
});
|
|
@@ -338,6 +879,9 @@ var useLangGraphRuntime = ({
|
|
|
338
879
|
};
|
|
339
880
|
// Annotate the CommonJS export names for ESM import in node:
|
|
340
881
|
0 && (module.exports = {
|
|
882
|
+
LangGraphMessageAccumulator,
|
|
883
|
+
appendLangChainChunk,
|
|
884
|
+
convertLangChainMessages,
|
|
341
885
|
convertLangchainMessages,
|
|
342
886
|
useLangGraphInterruptState,
|
|
343
887
|
useLangGraphMessages,
|