@assistant-ui/react-langgraph 0.3.1 → 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 {
@@ -199,7 +69,8 @@ var convertLangChainMessages = (message) => {
199
69
  role: "tool",
200
70
  toolName: message.name,
201
71
  toolCallId: message.tool_call_id,
202
- result: message.content
72
+ result: message.content,
73
+ artifact: message.artifact
203
74
  };
204
75
  }
205
76
  };
@@ -290,353 +161,8 @@ var useLangGraphMessages = ({
290
161
  };
291
162
  };
292
163
 
293
- // src/useLangGraphRuntime.ts
294
- import { SimpleImageAttachmentAdapter } from "@assistant-ui/react";
295
-
296
- // ../react/src/utils/json/parse-partial-json.ts
297
- var import_secure_json_parse = __toESM(require_secure_json_parse());
298
-
299
- // ../react/src/utils/json/fix-json.ts
300
- function fixJson(input) {
301
- const stack = ["ROOT"];
302
- let lastValidIndex = -1;
303
- let literalStart = null;
304
- function processValueStart(char, i, swapState) {
305
- {
306
- switch (char) {
307
- case '"': {
308
- lastValidIndex = i;
309
- stack.pop();
310
- stack.push(swapState);
311
- stack.push("INSIDE_STRING");
312
- break;
313
- }
314
- case "f":
315
- case "t":
316
- case "n": {
317
- lastValidIndex = i;
318
- literalStart = i;
319
- stack.pop();
320
- stack.push(swapState);
321
- stack.push("INSIDE_LITERAL");
322
- break;
323
- }
324
- case "-": {
325
- stack.pop();
326
- stack.push(swapState);
327
- stack.push("INSIDE_NUMBER");
328
- break;
329
- }
330
- case "0":
331
- case "1":
332
- case "2":
333
- case "3":
334
- case "4":
335
- case "5":
336
- case "6":
337
- case "7":
338
- case "8":
339
- case "9": {
340
- lastValidIndex = i;
341
- stack.pop();
342
- stack.push(swapState);
343
- stack.push("INSIDE_NUMBER");
344
- break;
345
- }
346
- case "{": {
347
- lastValidIndex = i;
348
- stack.pop();
349
- stack.push(swapState);
350
- stack.push("INSIDE_OBJECT_START");
351
- break;
352
- }
353
- case "[": {
354
- lastValidIndex = i;
355
- stack.pop();
356
- stack.push(swapState);
357
- stack.push("INSIDE_ARRAY_START");
358
- break;
359
- }
360
- }
361
- }
362
- }
363
- function processAfterObjectValue(char, i) {
364
- switch (char) {
365
- case ",": {
366
- stack.pop();
367
- stack.push("INSIDE_OBJECT_AFTER_COMMA");
368
- break;
369
- }
370
- case "}": {
371
- lastValidIndex = i;
372
- stack.pop();
373
- break;
374
- }
375
- }
376
- }
377
- function processAfterArrayValue(char, i) {
378
- switch (char) {
379
- case ",": {
380
- stack.pop();
381
- stack.push("INSIDE_ARRAY_AFTER_COMMA");
382
- break;
383
- }
384
- case "]": {
385
- lastValidIndex = i;
386
- stack.pop();
387
- break;
388
- }
389
- }
390
- }
391
- for (let i = 0; i < input.length; i++) {
392
- const char = input[i];
393
- const currentState = stack[stack.length - 1];
394
- switch (currentState) {
395
- case "ROOT":
396
- processValueStart(char, i, "FINISH");
397
- break;
398
- case "INSIDE_OBJECT_START": {
399
- switch (char) {
400
- case '"': {
401
- stack.pop();
402
- stack.push("INSIDE_OBJECT_KEY");
403
- break;
404
- }
405
- case "}": {
406
- lastValidIndex = i;
407
- stack.pop();
408
- break;
409
- }
410
- }
411
- break;
412
- }
413
- case "INSIDE_OBJECT_AFTER_COMMA": {
414
- switch (char) {
415
- case '"': {
416
- stack.pop();
417
- stack.push("INSIDE_OBJECT_KEY");
418
- break;
419
- }
420
- }
421
- break;
422
- }
423
- case "INSIDE_OBJECT_KEY": {
424
- switch (char) {
425
- case '"': {
426
- stack.pop();
427
- stack.push("INSIDE_OBJECT_AFTER_KEY");
428
- break;
429
- }
430
- }
431
- break;
432
- }
433
- case "INSIDE_OBJECT_AFTER_KEY": {
434
- switch (char) {
435
- case ":": {
436
- stack.pop();
437
- stack.push("INSIDE_OBJECT_BEFORE_VALUE");
438
- break;
439
- }
440
- }
441
- break;
442
- }
443
- case "INSIDE_OBJECT_BEFORE_VALUE": {
444
- processValueStart(char, i, "INSIDE_OBJECT_AFTER_VALUE");
445
- break;
446
- }
447
- case "INSIDE_OBJECT_AFTER_VALUE": {
448
- processAfterObjectValue(char, i);
449
- break;
450
- }
451
- case "INSIDE_STRING": {
452
- switch (char) {
453
- case '"': {
454
- stack.pop();
455
- lastValidIndex = i;
456
- break;
457
- }
458
- case "\\": {
459
- stack.push("INSIDE_STRING_ESCAPE");
460
- break;
461
- }
462
- default: {
463
- lastValidIndex = i;
464
- }
465
- }
466
- break;
467
- }
468
- case "INSIDE_ARRAY_START": {
469
- switch (char) {
470
- case "]": {
471
- lastValidIndex = i;
472
- stack.pop();
473
- break;
474
- }
475
- default: {
476
- lastValidIndex = i;
477
- processValueStart(char, i, "INSIDE_ARRAY_AFTER_VALUE");
478
- break;
479
- }
480
- }
481
- break;
482
- }
483
- case "INSIDE_ARRAY_AFTER_VALUE": {
484
- switch (char) {
485
- case ",": {
486
- stack.pop();
487
- stack.push("INSIDE_ARRAY_AFTER_COMMA");
488
- break;
489
- }
490
- case "]": {
491
- lastValidIndex = i;
492
- stack.pop();
493
- break;
494
- }
495
- default: {
496
- lastValidIndex = i;
497
- break;
498
- }
499
- }
500
- break;
501
- }
502
- case "INSIDE_ARRAY_AFTER_COMMA": {
503
- processValueStart(char, i, "INSIDE_ARRAY_AFTER_VALUE");
504
- break;
505
- }
506
- case "INSIDE_STRING_ESCAPE": {
507
- stack.pop();
508
- lastValidIndex = i;
509
- break;
510
- }
511
- case "INSIDE_NUMBER": {
512
- switch (char) {
513
- case "0":
514
- case "1":
515
- case "2":
516
- case "3":
517
- case "4":
518
- case "5":
519
- case "6":
520
- case "7":
521
- case "8":
522
- case "9": {
523
- lastValidIndex = i;
524
- break;
525
- }
526
- case "e":
527
- case "E":
528
- case "-":
529
- case ".": {
530
- break;
531
- }
532
- case ",": {
533
- stack.pop();
534
- if (stack[stack.length - 1] === "INSIDE_ARRAY_AFTER_VALUE") {
535
- processAfterArrayValue(char, i);
536
- }
537
- if (stack[stack.length - 1] === "INSIDE_OBJECT_AFTER_VALUE") {
538
- processAfterObjectValue(char, i);
539
- }
540
- break;
541
- }
542
- case "}": {
543
- stack.pop();
544
- if (stack[stack.length - 1] === "INSIDE_OBJECT_AFTER_VALUE") {
545
- processAfterObjectValue(char, i);
546
- }
547
- break;
548
- }
549
- case "]": {
550
- stack.pop();
551
- if (stack[stack.length - 1] === "INSIDE_ARRAY_AFTER_VALUE") {
552
- processAfterArrayValue(char, i);
553
- }
554
- break;
555
- }
556
- default: {
557
- stack.pop();
558
- break;
559
- }
560
- }
561
- break;
562
- }
563
- case "INSIDE_LITERAL": {
564
- const partialLiteral = input.substring(literalStart, i + 1);
565
- if (!"false".startsWith(partialLiteral) && !"true".startsWith(partialLiteral) && !"null".startsWith(partialLiteral)) {
566
- stack.pop();
567
- if (stack[stack.length - 1] === "INSIDE_OBJECT_AFTER_VALUE") {
568
- processAfterObjectValue(char, i);
569
- } else if (stack[stack.length - 1] === "INSIDE_ARRAY_AFTER_VALUE") {
570
- processAfterArrayValue(char, i);
571
- }
572
- } else {
573
- lastValidIndex = i;
574
- }
575
- break;
576
- }
577
- }
578
- }
579
- let result = input.slice(0, lastValidIndex + 1);
580
- let partialCount = 0;
581
- for (let i = stack.length - 1; i >= 0; i--) {
582
- const state = stack[i];
583
- switch (state) {
584
- case "INSIDE_STRING": {
585
- result += '"';
586
- partialCount++;
587
- break;
588
- }
589
- case "INSIDE_OBJECT_KEY":
590
- case "INSIDE_OBJECT_AFTER_KEY":
591
- case "INSIDE_OBJECT_AFTER_COMMA":
592
- case "INSIDE_OBJECT_START":
593
- case "INSIDE_OBJECT_BEFORE_VALUE":
594
- case "INSIDE_OBJECT_AFTER_VALUE": {
595
- result += "}";
596
- partialCount++;
597
- break;
598
- }
599
- case "INSIDE_ARRAY_START":
600
- case "INSIDE_ARRAY_AFTER_COMMA":
601
- case "INSIDE_ARRAY_AFTER_VALUE": {
602
- result += "]";
603
- partialCount++;
604
- break;
605
- }
606
- case "INSIDE_LITERAL": {
607
- const partialLiteral = input.substring(literalStart, input.length);
608
- if ("true".startsWith(partialLiteral)) {
609
- result += "true".slice(partialLiteral.length);
610
- } else if ("false".startsWith(partialLiteral)) {
611
- result += "false".slice(partialLiteral.length);
612
- } else if ("null".startsWith(partialLiteral)) {
613
- result += "null".slice(partialLiteral.length);
614
- }
615
- }
616
- }
617
- }
618
- return [result, partialCount];
619
- }
620
-
621
- // ../react/src/utils/json/parse-partial-json.ts
622
- var PARTIAL_JSON_COUNT_SYMBOL = Symbol("partial-json-count");
623
- var parsePartialJson = (json) => {
624
- try {
625
- return import_secure_json_parse.default.parse(json);
626
- } catch {
627
- try {
628
- const [fixedJson, partialCount] = fixJson(json);
629
- const res = import_secure_json_parse.default.parse(fixedJson);
630
- res[PARTIAL_JSON_COUNT_SYMBOL] = partialCount;
631
- return res;
632
- } catch {
633
- return void 0;
634
- }
635
- }
636
- };
637
- var COMPLETE_STATUS = Object.freeze({ type: "complete" });
638
-
639
164
  // src/appendLangChainChunk.ts
165
+ import { parsePartialJson } from "assistant-stream/utils";
640
166
  var appendLangChainChunk = (prev, curr) => {
641
167
  if (curr.type !== "AIMessageChunk") {
642
168
  return curr;
@@ -695,7 +221,7 @@ var getPendingToolCalls = (messages) => {
695
221
  var getMessageContent = (msg) => {
696
222
  const allContent = [
697
223
  ...msg.content,
698
- ...msg.attachments.flatMap((a) => a.content)
224
+ ...msg.attachments?.flatMap((a) => a.content) ?? []
699
225
  ];
700
226
  const content = allContent.map((part) => {
701
227
  const type = part.type;
@@ -741,7 +267,6 @@ var useLangGraphSendCommand = () => {
741
267
  var useLangGraphRuntime = ({
742
268
  autoCancelPendingToolCalls,
743
269
  adapters: { attachments, feedback, speech } = {},
744
- unstable_allowImageAttachments,
745
270
  unstable_allowCancellation,
746
271
  stream,
747
272
  threadId,
@@ -775,12 +300,6 @@ var useLangGraphRuntime = ({
775
300
  messages,
776
301
  isRunning
777
302
  });
778
- if (attachments && unstable_allowImageAttachments)
779
- throw new Error(
780
- "Replace unstable_allowImageAttachments with `adapters: { attachments: new SimpleImageAttachmentAdapter() }`."
781
- );
782
- if (unstable_allowImageAttachments)
783
- attachments = new SimpleImageAttachmentAdapter();
784
303
  const switchToThread = !onSwitchToThread ? void 0 : async (externalId) => {
785
304
  const { messages: messages2, interrupts } = await onSwitchToThread(externalId);
786
305
  setMessages(messages2);