@assistant-ui/react-langgraph 0.3.2 → 0.4.1

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 CHANGED
@@ -109,16 +109,12 @@ declare const useLangGraphMessages: <TMessage extends {
109
109
  declare const useLangGraphInterruptState: () => LangGraphInterruptState | undefined;
110
110
  declare const useLangGraphSend: () => (messages: LangChainMessage[], config: LangGraphSendMessageConfig) => Promise<void>;
111
111
  declare const useLangGraphSendCommand: () => (command: LangGraphCommand) => Promise<void>;
112
- declare const useLangGraphRuntime: ({ autoCancelPendingToolCalls, adapters: { attachments, feedback, speech }, unstable_allowImageAttachments, unstable_allowCancellation, stream, threadId, onSwitchToNewThread, onSwitchToThread, }: {
112
+ declare const useLangGraphRuntime: ({ autoCancelPendingToolCalls, adapters: { attachments, feedback, speech }, unstable_allowCancellation, stream, threadId, onSwitchToNewThread, onSwitchToThread, }: {
113
113
  /**
114
114
  * @deprecated For thread management use `useCloudThreadListRuntime` instead. This option will be removed in a future version.
115
115
  */
116
116
  threadId?: string | undefined;
117
117
  autoCancelPendingToolCalls?: boolean | undefined;
118
- /**
119
- * @deprecated Use `adapters: { attachments: new SimpleImageAttachmentAdapter() }` instead. This option will be removed in a future version.
120
- */
121
- unstable_allowImageAttachments?: boolean | undefined;
122
118
  unstable_allowCancellation?: boolean | undefined;
123
119
  stream: LangGraphStreamCallback<LangChainMessage>;
124
120
  /**
package/dist/index.d.ts CHANGED
@@ -109,16 +109,12 @@ declare const useLangGraphMessages: <TMessage extends {
109
109
  declare const useLangGraphInterruptState: () => LangGraphInterruptState | undefined;
110
110
  declare const useLangGraphSend: () => (messages: LangChainMessage[], config: LangGraphSendMessageConfig) => Promise<void>;
111
111
  declare const useLangGraphSendCommand: () => (command: LangGraphCommand) => Promise<void>;
112
- declare const useLangGraphRuntime: ({ autoCancelPendingToolCalls, adapters: { attachments, feedback, speech }, unstable_allowImageAttachments, unstable_allowCancellation, stream, threadId, onSwitchToNewThread, onSwitchToThread, }: {
112
+ declare const useLangGraphRuntime: ({ autoCancelPendingToolCalls, adapters: { attachments, feedback, speech }, unstable_allowCancellation, stream, threadId, onSwitchToNewThread, onSwitchToThread, }: {
113
113
  /**
114
114
  * @deprecated For thread management use `useCloudThreadListRuntime` instead. This option will be removed in a future version.
115
115
  */
116
116
  threadId?: string | undefined;
117
117
  autoCancelPendingToolCalls?: boolean | undefined;
118
- /**
119
- * @deprecated Use `adapters: { attachments: new SimpleImageAttachmentAdapter() }` instead. This option will be removed in a future version.
120
- */
121
- unstable_allowImageAttachments?: boolean | undefined;
122
118
  unstable_allowCancellation?: boolean | undefined;
123
119
  stream: LangGraphStreamCallback<LangChainMessage>;
124
120
  /**
package/dist/index.js CHANGED
@@ -1,13 +1,8 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  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
- };
11
6
  var __export = (target, all) => {
12
7
  for (var name in all)
13
8
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -20,120 +15,8 @@ var __copyProps = (to, from, except, desc) => {
20
15
  }
21
16
  return to;
22
17
  };
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
- ));
31
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
19
 
33
- // ../../node_modules/.pnpm/secure-json-parse@4.0.0/node_modules/secure-json-parse/index.js
34
- var require_secure_json_parse = __commonJS({
35
- "../../node_modules/.pnpm/secure-json-parse@4.0.0/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 {
124
- return void 0;
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
-
137
20
  // src/index.ts
138
21
  var index_exports = {};
139
22
  __export(index_exports, {
@@ -307,353 +190,8 @@ var useLangGraphMessages = ({
307
190
  };
308
191
  };
309
192
 
310
- // src/useLangGraphRuntime.ts
311
- var import_react4 = require("@assistant-ui/react");
312
-
313
- // ../react/src/utils/json/parse-partial-json.ts
314
- var import_secure_json_parse = __toESM(require_secure_json_parse());
315
-
316
- // ../react/src/utils/json/fix-json.ts
317
- function fixJson(input) {
318
- const stack = ["ROOT"];
319
- let lastValidIndex = -1;
320
- let literalStart = null;
321
- function processValueStart(char, i, swapState) {
322
- {
323
- switch (char) {
324
- case '"': {
325
- lastValidIndex = i;
326
- stack.pop();
327
- stack.push(swapState);
328
- stack.push("INSIDE_STRING");
329
- break;
330
- }
331
- case "f":
332
- case "t":
333
- case "n": {
334
- lastValidIndex = i;
335
- literalStart = i;
336
- stack.pop();
337
- stack.push(swapState);
338
- stack.push("INSIDE_LITERAL");
339
- break;
340
- }
341
- case "-": {
342
- stack.pop();
343
- stack.push(swapState);
344
- stack.push("INSIDE_NUMBER");
345
- break;
346
- }
347
- case "0":
348
- case "1":
349
- case "2":
350
- case "3":
351
- case "4":
352
- case "5":
353
- case "6":
354
- case "7":
355
- case "8":
356
- case "9": {
357
- lastValidIndex = i;
358
- stack.pop();
359
- stack.push(swapState);
360
- stack.push("INSIDE_NUMBER");
361
- break;
362
- }
363
- case "{": {
364
- lastValidIndex = i;
365
- stack.pop();
366
- stack.push(swapState);
367
- stack.push("INSIDE_OBJECT_START");
368
- break;
369
- }
370
- case "[": {
371
- lastValidIndex = i;
372
- stack.pop();
373
- stack.push(swapState);
374
- stack.push("INSIDE_ARRAY_START");
375
- break;
376
- }
377
- }
378
- }
379
- }
380
- function processAfterObjectValue(char, i) {
381
- switch (char) {
382
- case ",": {
383
- stack.pop();
384
- stack.push("INSIDE_OBJECT_AFTER_COMMA");
385
- break;
386
- }
387
- case "}": {
388
- lastValidIndex = i;
389
- stack.pop();
390
- break;
391
- }
392
- }
393
- }
394
- function processAfterArrayValue(char, i) {
395
- switch (char) {
396
- case ",": {
397
- stack.pop();
398
- stack.push("INSIDE_ARRAY_AFTER_COMMA");
399
- break;
400
- }
401
- case "]": {
402
- lastValidIndex = i;
403
- stack.pop();
404
- break;
405
- }
406
- }
407
- }
408
- for (let i = 0; i < input.length; i++) {
409
- const char = input[i];
410
- const currentState = stack[stack.length - 1];
411
- switch (currentState) {
412
- case "ROOT":
413
- processValueStart(char, i, "FINISH");
414
- break;
415
- case "INSIDE_OBJECT_START": {
416
- switch (char) {
417
- case '"': {
418
- stack.pop();
419
- stack.push("INSIDE_OBJECT_KEY");
420
- break;
421
- }
422
- case "}": {
423
- lastValidIndex = i;
424
- stack.pop();
425
- break;
426
- }
427
- }
428
- break;
429
- }
430
- case "INSIDE_OBJECT_AFTER_COMMA": {
431
- switch (char) {
432
- case '"': {
433
- stack.pop();
434
- stack.push("INSIDE_OBJECT_KEY");
435
- break;
436
- }
437
- }
438
- break;
439
- }
440
- case "INSIDE_OBJECT_KEY": {
441
- switch (char) {
442
- case '"': {
443
- stack.pop();
444
- stack.push("INSIDE_OBJECT_AFTER_KEY");
445
- break;
446
- }
447
- }
448
- break;
449
- }
450
- case "INSIDE_OBJECT_AFTER_KEY": {
451
- switch (char) {
452
- case ":": {
453
- stack.pop();
454
- stack.push("INSIDE_OBJECT_BEFORE_VALUE");
455
- break;
456
- }
457
- }
458
- break;
459
- }
460
- case "INSIDE_OBJECT_BEFORE_VALUE": {
461
- processValueStart(char, i, "INSIDE_OBJECT_AFTER_VALUE");
462
- break;
463
- }
464
- case "INSIDE_OBJECT_AFTER_VALUE": {
465
- processAfterObjectValue(char, i);
466
- break;
467
- }
468
- case "INSIDE_STRING": {
469
- switch (char) {
470
- case '"': {
471
- stack.pop();
472
- lastValidIndex = i;
473
- break;
474
- }
475
- case "\\": {
476
- stack.push("INSIDE_STRING_ESCAPE");
477
- break;
478
- }
479
- default: {
480
- lastValidIndex = i;
481
- }
482
- }
483
- break;
484
- }
485
- case "INSIDE_ARRAY_START": {
486
- switch (char) {
487
- case "]": {
488
- lastValidIndex = i;
489
- stack.pop();
490
- break;
491
- }
492
- default: {
493
- lastValidIndex = i;
494
- processValueStart(char, i, "INSIDE_ARRAY_AFTER_VALUE");
495
- break;
496
- }
497
- }
498
- break;
499
- }
500
- case "INSIDE_ARRAY_AFTER_VALUE": {
501
- switch (char) {
502
- case ",": {
503
- stack.pop();
504
- stack.push("INSIDE_ARRAY_AFTER_COMMA");
505
- break;
506
- }
507
- case "]": {
508
- lastValidIndex = i;
509
- stack.pop();
510
- break;
511
- }
512
- default: {
513
- lastValidIndex = i;
514
- break;
515
- }
516
- }
517
- break;
518
- }
519
- case "INSIDE_ARRAY_AFTER_COMMA": {
520
- processValueStart(char, i, "INSIDE_ARRAY_AFTER_VALUE");
521
- break;
522
- }
523
- case "INSIDE_STRING_ESCAPE": {
524
- stack.pop();
525
- lastValidIndex = i;
526
- break;
527
- }
528
- case "INSIDE_NUMBER": {
529
- switch (char) {
530
- case "0":
531
- case "1":
532
- case "2":
533
- case "3":
534
- case "4":
535
- case "5":
536
- case "6":
537
- case "7":
538
- case "8":
539
- case "9": {
540
- lastValidIndex = i;
541
- break;
542
- }
543
- case "e":
544
- case "E":
545
- case "-":
546
- case ".": {
547
- break;
548
- }
549
- case ",": {
550
- stack.pop();
551
- if (stack[stack.length - 1] === "INSIDE_ARRAY_AFTER_VALUE") {
552
- processAfterArrayValue(char, i);
553
- }
554
- if (stack[stack.length - 1] === "INSIDE_OBJECT_AFTER_VALUE") {
555
- processAfterObjectValue(char, i);
556
- }
557
- break;
558
- }
559
- case "}": {
560
- stack.pop();
561
- if (stack[stack.length - 1] === "INSIDE_OBJECT_AFTER_VALUE") {
562
- processAfterObjectValue(char, i);
563
- }
564
- break;
565
- }
566
- case "]": {
567
- stack.pop();
568
- if (stack[stack.length - 1] === "INSIDE_ARRAY_AFTER_VALUE") {
569
- processAfterArrayValue(char, i);
570
- }
571
- break;
572
- }
573
- default: {
574
- stack.pop();
575
- break;
576
- }
577
- }
578
- break;
579
- }
580
- case "INSIDE_LITERAL": {
581
- const partialLiteral = input.substring(literalStart, i + 1);
582
- if (!"false".startsWith(partialLiteral) && !"true".startsWith(partialLiteral) && !"null".startsWith(partialLiteral)) {
583
- stack.pop();
584
- if (stack[stack.length - 1] === "INSIDE_OBJECT_AFTER_VALUE") {
585
- processAfterObjectValue(char, i);
586
- } else if (stack[stack.length - 1] === "INSIDE_ARRAY_AFTER_VALUE") {
587
- processAfterArrayValue(char, i);
588
- }
589
- } else {
590
- lastValidIndex = i;
591
- }
592
- break;
593
- }
594
- }
595
- }
596
- let result = input.slice(0, lastValidIndex + 1);
597
- let partialCount = 0;
598
- for (let i = stack.length - 1; i >= 0; i--) {
599
- const state = stack[i];
600
- switch (state) {
601
- case "INSIDE_STRING": {
602
- result += '"';
603
- partialCount++;
604
- break;
605
- }
606
- case "INSIDE_OBJECT_KEY":
607
- case "INSIDE_OBJECT_AFTER_KEY":
608
- case "INSIDE_OBJECT_AFTER_COMMA":
609
- case "INSIDE_OBJECT_START":
610
- case "INSIDE_OBJECT_BEFORE_VALUE":
611
- case "INSIDE_OBJECT_AFTER_VALUE": {
612
- result += "}";
613
- partialCount++;
614
- break;
615
- }
616
- case "INSIDE_ARRAY_START":
617
- case "INSIDE_ARRAY_AFTER_COMMA":
618
- case "INSIDE_ARRAY_AFTER_VALUE": {
619
- result += "]";
620
- partialCount++;
621
- break;
622
- }
623
- case "INSIDE_LITERAL": {
624
- const partialLiteral = input.substring(literalStart, input.length);
625
- if ("true".startsWith(partialLiteral)) {
626
- result += "true".slice(partialLiteral.length);
627
- } else if ("false".startsWith(partialLiteral)) {
628
- result += "false".slice(partialLiteral.length);
629
- } else if ("null".startsWith(partialLiteral)) {
630
- result += "null".slice(partialLiteral.length);
631
- }
632
- }
633
- }
634
- }
635
- return [result, partialCount];
636
- }
637
-
638
- // ../react/src/utils/json/parse-partial-json.ts
639
- var PARTIAL_JSON_COUNT_SYMBOL = Symbol("partial-json-count");
640
- var parsePartialJson = (json) => {
641
- try {
642
- return import_secure_json_parse.default.parse(json);
643
- } catch {
644
- try {
645
- const [fixedJson, partialCount] = fixJson(json);
646
- const res = import_secure_json_parse.default.parse(fixedJson);
647
- res[PARTIAL_JSON_COUNT_SYMBOL] = partialCount;
648
- return res;
649
- } catch {
650
- return void 0;
651
- }
652
- }
653
- };
654
- var COMPLETE_STATUS = Object.freeze({ type: "complete" });
655
-
656
193
  // src/appendLangChainChunk.ts
194
+ var import_utils = require("assistant-stream/utils");
657
195
  var appendLangChainChunk = (prev, curr) => {
658
196
  if (curr.type !== "AIMessageChunk") {
659
197
  return curr;
@@ -684,7 +222,7 @@ var appendLangChainChunk = (prev, curr) => {
684
222
  ...chunk,
685
223
  ...existing,
686
224
  argsText: newArgsText,
687
- args: parsePartialJson(newArgsText)
225
+ args: (0, import_utils.parsePartialJson)(newArgsText)
688
226
  };
689
227
  }
690
228
  return {
@@ -712,7 +250,7 @@ var getPendingToolCalls = (messages) => {
712
250
  var getMessageContent = (msg) => {
713
251
  const allContent = [
714
252
  ...msg.content,
715
- ...msg.attachments.flatMap((a) => a.content)
253
+ ...msg.attachments?.flatMap((a) => a.content) ?? []
716
254
  ];
717
255
  const content = allContent.map((part) => {
718
256
  const type = part.type;
@@ -758,7 +296,6 @@ var useLangGraphSendCommand = () => {
758
296
  var useLangGraphRuntime = ({
759
297
  autoCancelPendingToolCalls,
760
298
  adapters: { attachments, feedback, speech } = {},
761
- unstable_allowImageAttachments,
762
299
  unstable_allowCancellation,
763
300
  stream,
764
301
  threadId,
@@ -792,12 +329,6 @@ var useLangGraphRuntime = ({
792
329
  messages,
793
330
  isRunning
794
331
  });
795
- if (attachments && unstable_allowImageAttachments)
796
- throw new Error(
797
- "Replace unstable_allowImageAttachments with `adapters: { attachments: new SimpleImageAttachmentAdapter() }`."
798
- );
799
- if (unstable_allowImageAttachments)
800
- attachments = new import_react4.SimpleImageAttachmentAdapter();
801
332
  const switchToThread = !onSwitchToThread ? void 0 : async (externalId) => {
802
333
  const { messages: messages2, interrupts } = await onSwitchToThread(externalId);
803
334
  setMessages(messages2);