@assistant-ui/react-langgraph 0.3.2 → 0.4.0

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.mjs CHANGED
@@ -1,133 +1,3 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __commonJS = (cb, mod) => function __require() {
8
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
19
- // If the importer is in node compatibility mode or this is not an ESM
20
- // file that has been converted to a CommonJS file using a Babel-
21
- // compatible transform (i.e. "__esModule" has not been set), then set
22
- // "default" to the CommonJS "module.exports" for node compatibility.
23
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
24
- mod
25
- ));
26
-
27
- // ../../node_modules/.pnpm/secure-json-parse@4.0.0/node_modules/secure-json-parse/index.js
28
- var require_secure_json_parse = __commonJS({
29
- "../../node_modules/.pnpm/secure-json-parse@4.0.0/node_modules/secure-json-parse/index.js"(exports, module) {
30
- "use strict";
31
- var hasBuffer = typeof Buffer !== "undefined";
32
- var suspectProtoRx = /"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/;
33
- 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*:/;
34
- function _parse(text, reviver, options) {
35
- if (options == null) {
36
- if (reviver !== null && typeof reviver === "object") {
37
- options = reviver;
38
- reviver = void 0;
39
- }
40
- }
41
- if (hasBuffer && Buffer.isBuffer(text)) {
42
- text = text.toString();
43
- }
44
- if (text && text.charCodeAt(0) === 65279) {
45
- text = text.slice(1);
46
- }
47
- const obj = JSON.parse(text, reviver);
48
- if (obj === null || typeof obj !== "object") {
49
- return obj;
50
- }
51
- const protoAction = options && options.protoAction || "error";
52
- const constructorAction = options && options.constructorAction || "error";
53
- if (protoAction === "ignore" && constructorAction === "ignore") {
54
- return obj;
55
- }
56
- if (protoAction !== "ignore" && constructorAction !== "ignore") {
57
- if (suspectProtoRx.test(text) === false && suspectConstructorRx.test(text) === false) {
58
- return obj;
59
- }
60
- } else if (protoAction !== "ignore" && constructorAction === "ignore") {
61
- if (suspectProtoRx.test(text) === false) {
62
- return obj;
63
- }
64
- } else {
65
- if (suspectConstructorRx.test(text) === false) {
66
- return obj;
67
- }
68
- }
69
- return filter(obj, { protoAction, constructorAction, safe: options && options.safe });
70
- }
71
- function filter(obj, { protoAction = "error", constructorAction = "error", safe } = {}) {
72
- let next = [obj];
73
- while (next.length) {
74
- const nodes = next;
75
- next = [];
76
- for (const node of nodes) {
77
- if (protoAction !== "ignore" && Object.prototype.hasOwnProperty.call(node, "__proto__")) {
78
- if (safe === true) {
79
- return null;
80
- } else if (protoAction === "error") {
81
- throw new SyntaxError("Object contains forbidden prototype property");
82
- }
83
- delete node.__proto__;
84
- }
85
- if (constructorAction !== "ignore" && Object.prototype.hasOwnProperty.call(node, "constructor") && Object.prototype.hasOwnProperty.call(node.constructor, "prototype")) {
86
- if (safe === true) {
87
- return null;
88
- } else if (constructorAction === "error") {
89
- throw new SyntaxError("Object contains forbidden prototype property");
90
- }
91
- delete node.constructor;
92
- }
93
- for (const key in node) {
94
- const value = node[key];
95
- if (value && typeof value === "object") {
96
- next.push(value);
97
- }
98
- }
99
- }
100
- }
101
- return obj;
102
- }
103
- function parse(text, reviver, options) {
104
- const { stackTraceLimit } = Error;
105
- Error.stackTraceLimit = 0;
106
- try {
107
- return _parse(text, reviver, options);
108
- } finally {
109
- Error.stackTraceLimit = stackTraceLimit;
110
- }
111
- }
112
- function safeParse(text, reviver) {
113
- const { stackTraceLimit } = Error;
114
- Error.stackTraceLimit = 0;
115
- try {
116
- return _parse(text, reviver, { safe: true });
117
- } catch {
118
- return void 0;
119
- } finally {
120
- Error.stackTraceLimit = stackTraceLimit;
121
- }
122
- }
123
- module.exports = parse;
124
- module.exports.default = parse;
125
- module.exports.parse = parse;
126
- module.exports.safeParse = safeParse;
127
- module.exports.scan = filter;
128
- }
129
- });
130
-
131
1
  // src/useLangGraphRuntime.ts
132
2
  import { useEffect, useRef as useRef2, useState as useState2 } from "react";
133
3
  import {
@@ -291,353 +161,8 @@ var useLangGraphMessages = ({
291
161
  };
292
162
  };
293
163
 
294
- // src/useLangGraphRuntime.ts
295
- import { SimpleImageAttachmentAdapter } from "@assistant-ui/react";
296
-
297
- // ../react/src/utils/json/parse-partial-json.ts
298
- var import_secure_json_parse = __toESM(require_secure_json_parse());
299
-
300
- // ../react/src/utils/json/fix-json.ts
301
- function fixJson(input) {
302
- const stack = ["ROOT"];
303
- let lastValidIndex = -1;
304
- let literalStart = null;
305
- function processValueStart(char, i, swapState) {
306
- {
307
- switch (char) {
308
- case '"': {
309
- lastValidIndex = i;
310
- stack.pop();
311
- stack.push(swapState);
312
- stack.push("INSIDE_STRING");
313
- break;
314
- }
315
- case "f":
316
- case "t":
317
- case "n": {
318
- lastValidIndex = i;
319
- literalStart = i;
320
- stack.pop();
321
- stack.push(swapState);
322
- stack.push("INSIDE_LITERAL");
323
- break;
324
- }
325
- case "-": {
326
- stack.pop();
327
- stack.push(swapState);
328
- stack.push("INSIDE_NUMBER");
329
- break;
330
- }
331
- case "0":
332
- case "1":
333
- case "2":
334
- case "3":
335
- case "4":
336
- case "5":
337
- case "6":
338
- case "7":
339
- case "8":
340
- case "9": {
341
- lastValidIndex = i;
342
- stack.pop();
343
- stack.push(swapState);
344
- stack.push("INSIDE_NUMBER");
345
- break;
346
- }
347
- case "{": {
348
- lastValidIndex = i;
349
- stack.pop();
350
- stack.push(swapState);
351
- stack.push("INSIDE_OBJECT_START");
352
- break;
353
- }
354
- case "[": {
355
- lastValidIndex = i;
356
- stack.pop();
357
- stack.push(swapState);
358
- stack.push("INSIDE_ARRAY_START");
359
- break;
360
- }
361
- }
362
- }
363
- }
364
- function processAfterObjectValue(char, i) {
365
- switch (char) {
366
- case ",": {
367
- stack.pop();
368
- stack.push("INSIDE_OBJECT_AFTER_COMMA");
369
- break;
370
- }
371
- case "}": {
372
- lastValidIndex = i;
373
- stack.pop();
374
- break;
375
- }
376
- }
377
- }
378
- function processAfterArrayValue(char, i) {
379
- switch (char) {
380
- case ",": {
381
- stack.pop();
382
- stack.push("INSIDE_ARRAY_AFTER_COMMA");
383
- break;
384
- }
385
- case "]": {
386
- lastValidIndex = i;
387
- stack.pop();
388
- break;
389
- }
390
- }
391
- }
392
- for (let i = 0; i < input.length; i++) {
393
- const char = input[i];
394
- const currentState = stack[stack.length - 1];
395
- switch (currentState) {
396
- case "ROOT":
397
- processValueStart(char, i, "FINISH");
398
- break;
399
- case "INSIDE_OBJECT_START": {
400
- switch (char) {
401
- case '"': {
402
- stack.pop();
403
- stack.push("INSIDE_OBJECT_KEY");
404
- break;
405
- }
406
- case "}": {
407
- lastValidIndex = i;
408
- stack.pop();
409
- break;
410
- }
411
- }
412
- break;
413
- }
414
- case "INSIDE_OBJECT_AFTER_COMMA": {
415
- switch (char) {
416
- case '"': {
417
- stack.pop();
418
- stack.push("INSIDE_OBJECT_KEY");
419
- break;
420
- }
421
- }
422
- break;
423
- }
424
- case "INSIDE_OBJECT_KEY": {
425
- switch (char) {
426
- case '"': {
427
- stack.pop();
428
- stack.push("INSIDE_OBJECT_AFTER_KEY");
429
- break;
430
- }
431
- }
432
- break;
433
- }
434
- case "INSIDE_OBJECT_AFTER_KEY": {
435
- switch (char) {
436
- case ":": {
437
- stack.pop();
438
- stack.push("INSIDE_OBJECT_BEFORE_VALUE");
439
- break;
440
- }
441
- }
442
- break;
443
- }
444
- case "INSIDE_OBJECT_BEFORE_VALUE": {
445
- processValueStart(char, i, "INSIDE_OBJECT_AFTER_VALUE");
446
- break;
447
- }
448
- case "INSIDE_OBJECT_AFTER_VALUE": {
449
- processAfterObjectValue(char, i);
450
- break;
451
- }
452
- case "INSIDE_STRING": {
453
- switch (char) {
454
- case '"': {
455
- stack.pop();
456
- lastValidIndex = i;
457
- break;
458
- }
459
- case "\\": {
460
- stack.push("INSIDE_STRING_ESCAPE");
461
- break;
462
- }
463
- default: {
464
- lastValidIndex = i;
465
- }
466
- }
467
- break;
468
- }
469
- case "INSIDE_ARRAY_START": {
470
- switch (char) {
471
- case "]": {
472
- lastValidIndex = i;
473
- stack.pop();
474
- break;
475
- }
476
- default: {
477
- lastValidIndex = i;
478
- processValueStart(char, i, "INSIDE_ARRAY_AFTER_VALUE");
479
- break;
480
- }
481
- }
482
- break;
483
- }
484
- case "INSIDE_ARRAY_AFTER_VALUE": {
485
- switch (char) {
486
- case ",": {
487
- stack.pop();
488
- stack.push("INSIDE_ARRAY_AFTER_COMMA");
489
- break;
490
- }
491
- case "]": {
492
- lastValidIndex = i;
493
- stack.pop();
494
- break;
495
- }
496
- default: {
497
- lastValidIndex = i;
498
- break;
499
- }
500
- }
501
- break;
502
- }
503
- case "INSIDE_ARRAY_AFTER_COMMA": {
504
- processValueStart(char, i, "INSIDE_ARRAY_AFTER_VALUE");
505
- break;
506
- }
507
- case "INSIDE_STRING_ESCAPE": {
508
- stack.pop();
509
- lastValidIndex = i;
510
- break;
511
- }
512
- case "INSIDE_NUMBER": {
513
- switch (char) {
514
- case "0":
515
- case "1":
516
- case "2":
517
- case "3":
518
- case "4":
519
- case "5":
520
- case "6":
521
- case "7":
522
- case "8":
523
- case "9": {
524
- lastValidIndex = i;
525
- break;
526
- }
527
- case "e":
528
- case "E":
529
- case "-":
530
- case ".": {
531
- break;
532
- }
533
- case ",": {
534
- stack.pop();
535
- if (stack[stack.length - 1] === "INSIDE_ARRAY_AFTER_VALUE") {
536
- processAfterArrayValue(char, i);
537
- }
538
- if (stack[stack.length - 1] === "INSIDE_OBJECT_AFTER_VALUE") {
539
- processAfterObjectValue(char, i);
540
- }
541
- break;
542
- }
543
- case "}": {
544
- stack.pop();
545
- if (stack[stack.length - 1] === "INSIDE_OBJECT_AFTER_VALUE") {
546
- processAfterObjectValue(char, i);
547
- }
548
- break;
549
- }
550
- case "]": {
551
- stack.pop();
552
- if (stack[stack.length - 1] === "INSIDE_ARRAY_AFTER_VALUE") {
553
- processAfterArrayValue(char, i);
554
- }
555
- break;
556
- }
557
- default: {
558
- stack.pop();
559
- break;
560
- }
561
- }
562
- break;
563
- }
564
- case "INSIDE_LITERAL": {
565
- const partialLiteral = input.substring(literalStart, i + 1);
566
- if (!"false".startsWith(partialLiteral) && !"true".startsWith(partialLiteral) && !"null".startsWith(partialLiteral)) {
567
- stack.pop();
568
- if (stack[stack.length - 1] === "INSIDE_OBJECT_AFTER_VALUE") {
569
- processAfterObjectValue(char, i);
570
- } else if (stack[stack.length - 1] === "INSIDE_ARRAY_AFTER_VALUE") {
571
- processAfterArrayValue(char, i);
572
- }
573
- } else {
574
- lastValidIndex = i;
575
- }
576
- break;
577
- }
578
- }
579
- }
580
- let result = input.slice(0, lastValidIndex + 1);
581
- let partialCount = 0;
582
- for (let i = stack.length - 1; i >= 0; i--) {
583
- const state = stack[i];
584
- switch (state) {
585
- case "INSIDE_STRING": {
586
- result += '"';
587
- partialCount++;
588
- break;
589
- }
590
- case "INSIDE_OBJECT_KEY":
591
- case "INSIDE_OBJECT_AFTER_KEY":
592
- case "INSIDE_OBJECT_AFTER_COMMA":
593
- case "INSIDE_OBJECT_START":
594
- case "INSIDE_OBJECT_BEFORE_VALUE":
595
- case "INSIDE_OBJECT_AFTER_VALUE": {
596
- result += "}";
597
- partialCount++;
598
- break;
599
- }
600
- case "INSIDE_ARRAY_START":
601
- case "INSIDE_ARRAY_AFTER_COMMA":
602
- case "INSIDE_ARRAY_AFTER_VALUE": {
603
- result += "]";
604
- partialCount++;
605
- break;
606
- }
607
- case "INSIDE_LITERAL": {
608
- const partialLiteral = input.substring(literalStart, input.length);
609
- if ("true".startsWith(partialLiteral)) {
610
- result += "true".slice(partialLiteral.length);
611
- } else if ("false".startsWith(partialLiteral)) {
612
- result += "false".slice(partialLiteral.length);
613
- } else if ("null".startsWith(partialLiteral)) {
614
- result += "null".slice(partialLiteral.length);
615
- }
616
- }
617
- }
618
- }
619
- return [result, partialCount];
620
- }
621
-
622
- // ../react/src/utils/json/parse-partial-json.ts
623
- var PARTIAL_JSON_COUNT_SYMBOL = Symbol("partial-json-count");
624
- var parsePartialJson = (json) => {
625
- try {
626
- return import_secure_json_parse.default.parse(json);
627
- } catch {
628
- try {
629
- const [fixedJson, partialCount] = fixJson(json);
630
- const res = import_secure_json_parse.default.parse(fixedJson);
631
- res[PARTIAL_JSON_COUNT_SYMBOL] = partialCount;
632
- return res;
633
- } catch {
634
- return void 0;
635
- }
636
- }
637
- };
638
- var COMPLETE_STATUS = Object.freeze({ type: "complete" });
639
-
640
164
  // src/appendLangChainChunk.ts
165
+ import { parsePartialJson } from "assistant-stream/utils";
641
166
  var appendLangChainChunk = (prev, curr) => {
642
167
  if (curr.type !== "AIMessageChunk") {
643
168
  return curr;
@@ -696,7 +221,7 @@ var getPendingToolCalls = (messages) => {
696
221
  var getMessageContent = (msg) => {
697
222
  const allContent = [
698
223
  ...msg.content,
699
- ...msg.attachments.flatMap((a) => a.content)
224
+ ...msg.attachments?.flatMap((a) => a.content) ?? []
700
225
  ];
701
226
  const content = allContent.map((part) => {
702
227
  const type = part.type;
@@ -742,7 +267,6 @@ var useLangGraphSendCommand = () => {
742
267
  var useLangGraphRuntime = ({
743
268
  autoCancelPendingToolCalls,
744
269
  adapters: { attachments, feedback, speech } = {},
745
- unstable_allowImageAttachments,
746
270
  unstable_allowCancellation,
747
271
  stream,
748
272
  threadId,
@@ -776,12 +300,6 @@ var useLangGraphRuntime = ({
776
300
  messages,
777
301
  isRunning
778
302
  });
779
- if (attachments && unstable_allowImageAttachments)
780
- throw new Error(
781
- "Replace unstable_allowImageAttachments with `adapters: { attachments: new SimpleImageAttachmentAdapter() }`."
782
- );
783
- if (unstable_allowImageAttachments)
784
- attachments = new SimpleImageAttachmentAdapter();
785
303
  const switchToThread = !onSwitchToThread ? void 0 : async (externalId) => {
786
304
  const { messages: messages2, interrupts } = await onSwitchToThread(externalId);
787
305
  setMessages(messages2);