@copilotkit/react-core 1.4.8-no-pino-redact.1 → 1.5.0-coagents-v0-3.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.
Files changed (141) hide show
  1. package/CHANGELOG.md +22 -3
  2. package/dist/{chunk-JHEAUB3Z.mjs → chunk-35EN6BG4.mjs} +2 -2
  3. package/dist/{chunk-JHEAUB3Z.mjs.map → chunk-35EN6BG4.mjs.map} +1 -1
  4. package/dist/{chunk-O22KGHOQ.mjs → chunk-42N5VKIX.mjs} +38 -16
  5. package/dist/chunk-42N5VKIX.mjs.map +1 -0
  6. package/dist/{chunk-AG7FH7OD.mjs → chunk-5FYKUKG3.mjs} +2 -2
  7. package/dist/{chunk-ODN4H66E.mjs → chunk-7LRDVJH5.mjs} +6 -2
  8. package/dist/chunk-7LRDVJH5.mjs.map +1 -0
  9. package/dist/{chunk-Y7MI4PBB.mjs → chunk-ALR5W5JK.mjs} +22 -10
  10. package/dist/chunk-ALR5W5JK.mjs.map +1 -0
  11. package/dist/{chunk-XBVKTDXP.mjs → chunk-BT6WK2JZ.mjs} +57 -17
  12. package/dist/chunk-BT6WK2JZ.mjs.map +1 -0
  13. package/dist/chunk-QCUP6HLK.mjs +37 -0
  14. package/dist/chunk-QCUP6HLK.mjs.map +1 -0
  15. package/dist/chunk-QTDCEDOC.mjs +392 -0
  16. package/dist/chunk-QTDCEDOC.mjs.map +1 -0
  17. package/dist/{chunk-OT67R4NB.mjs → chunk-QX6V774L.mjs} +6 -8
  18. package/dist/chunk-QX6V774L.mjs.map +1 -0
  19. package/dist/{chunk-2KCEHGSI.mjs → chunk-SFPANIOY.mjs} +99 -49
  20. package/dist/chunk-SFPANIOY.mjs.map +1 -0
  21. package/dist/{chunk-XQFVXX6R.mjs → chunk-TQN3EZWQ.mjs} +10 -2
  22. package/dist/chunk-TQN3EZWQ.mjs.map +1 -0
  23. package/dist/{chunk-UOVONDR6.mjs → chunk-V3PFWGIY.mjs} +2 -2
  24. package/dist/{chunk-DHGXL5PC.mjs → chunk-VMP6JWBB.mjs} +18 -6
  25. package/dist/chunk-VMP6JWBB.mjs.map +1 -0
  26. package/dist/chunk-XERJQUHA.mjs +31 -0
  27. package/dist/chunk-XERJQUHA.mjs.map +1 -0
  28. package/dist/components/copilot-provider/copilotkit.js +175 -93
  29. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  30. package/dist/components/copilot-provider/copilotkit.mjs +5 -4
  31. package/dist/components/copilot-provider/index.js +175 -93
  32. package/dist/components/copilot-provider/index.js.map +1 -1
  33. package/dist/components/copilot-provider/index.mjs +5 -4
  34. package/dist/components/error-boundary/error-boundary.d.ts +22 -0
  35. package/dist/components/error-boundary/error-boundary.js +183 -0
  36. package/dist/components/error-boundary/error-boundary.js.map +1 -0
  37. package/dist/components/error-boundary/error-boundary.mjs +12 -0
  38. package/dist/components/error-boundary/error-boundary.mjs.map +1 -0
  39. package/dist/components/error-boundary/error-utils.d.ts +11 -0
  40. package/dist/components/error-boundary/error-utils.js +177 -0
  41. package/dist/components/error-boundary/error-utils.js.map +1 -0
  42. package/dist/components/error-boundary/error-utils.mjs +13 -0
  43. package/dist/components/error-boundary/error-utils.mjs.map +1 -0
  44. package/dist/components/index.js +175 -93
  45. package/dist/components/index.js.map +1 -1
  46. package/dist/components/index.mjs +5 -4
  47. package/dist/components/toast/toast-provider.d.ts +2 -1
  48. package/dist/components/toast/toast-provider.js +76 -62
  49. package/dist/components/toast/toast-provider.js.map +1 -1
  50. package/dist/components/toast/toast-provider.mjs +1 -1
  51. package/dist/context/copilot-context.d.ts +8 -2
  52. package/dist/context/copilot-context.js +9 -1
  53. package/dist/context/copilot-context.js.map +1 -1
  54. package/dist/context/copilot-context.mjs +1 -1
  55. package/dist/context/index.d.ts +1 -1
  56. package/dist/context/index.js +9 -1
  57. package/dist/context/index.js.map +1 -1
  58. package/dist/context/index.mjs +1 -1
  59. package/dist/hooks/index.d.ts +2 -1
  60. package/dist/hooks/index.js +584 -270
  61. package/dist/hooks/index.js.map +1 -1
  62. package/dist/hooks/index.mjs +19 -11
  63. package/dist/hooks/use-chat.d.ts +20 -0
  64. package/dist/hooks/use-chat.js +438 -200
  65. package/dist/hooks/use-chat.js.map +1 -1
  66. package/dist/hooks/use-chat.mjs +4 -3
  67. package/dist/hooks/use-coagent-state-render.d.ts +2 -2
  68. package/dist/hooks/use-coagent-state-render.js +9 -1
  69. package/dist/hooks/use-coagent-state-render.js.map +1 -1
  70. package/dist/hooks/use-coagent-state-render.mjs +2 -2
  71. package/dist/hooks/use-coagent.d.ts +14 -1
  72. package/dist/hooks/use-coagent.js +547 -242
  73. package/dist/hooks/use-coagent.js.map +1 -1
  74. package/dist/hooks/use-coagent.mjs +15 -7
  75. package/dist/hooks/use-copilot-action.d.ts +12 -2
  76. package/dist/hooks/use-copilot-action.js +156 -14
  77. package/dist/hooks/use-copilot-action.js.map +1 -1
  78. package/dist/hooks/use-copilot-action.mjs +4 -2
  79. package/dist/hooks/use-copilot-chat.d.ts +1 -0
  80. package/dist/hooks/use-copilot-chat.js +514 -231
  81. package/dist/hooks/use-copilot-chat.js.map +1 -1
  82. package/dist/hooks/use-copilot-chat.mjs +8 -6
  83. package/dist/hooks/use-copilot-readable.js +9 -1
  84. package/dist/hooks/use-copilot-readable.js.map +1 -1
  85. package/dist/hooks/use-copilot-readable.mjs +2 -2
  86. package/dist/hooks/use-copilot-runtime-client.js +110 -4
  87. package/dist/hooks/use-copilot-runtime-client.js.map +1 -1
  88. package/dist/hooks/use-copilot-runtime-client.mjs +2 -2
  89. package/dist/hooks/use-make-copilot-document-readable.js +9 -1
  90. package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
  91. package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
  92. package/dist/index.d.ts +2 -2
  93. package/dist/index.js +642 -363
  94. package/dist/index.js.map +1 -1
  95. package/dist/index.mjs +20 -12
  96. package/dist/lib/copilot-task.d.ts +1 -1
  97. package/dist/lib/copilot-task.js +33 -13
  98. package/dist/lib/copilot-task.js.map +1 -1
  99. package/dist/lib/copilot-task.mjs +7 -5
  100. package/dist/lib/index.d.ts +1 -1
  101. package/dist/lib/index.js +33 -13
  102. package/dist/lib/index.js.map +1 -1
  103. package/dist/lib/index.mjs +7 -5
  104. package/dist/types/frontend-action.d.ts +21 -2
  105. package/dist/types/frontend-action.js +34 -0
  106. package/dist/types/frontend-action.js.map +1 -1
  107. package/dist/types/frontend-action.mjs +7 -0
  108. package/dist/types/index.d.ts +2 -1
  109. package/dist/types/index.js.map +1 -1
  110. package/dist/utils/extract.js.map +1 -1
  111. package/dist/utils/extract.mjs +5 -4
  112. package/dist/utils/index.js.map +1 -1
  113. package/dist/utils/index.mjs +5 -4
  114. package/package.json +3 -3
  115. package/src/components/copilot-provider/copilotkit.tsx +14 -1
  116. package/src/components/error-boundary/error-boundary.tsx +42 -0
  117. package/src/components/error-boundary/error-utils.tsx +95 -0
  118. package/src/components/toast/toast-provider.tsx +10 -49
  119. package/src/context/copilot-context.tsx +30 -2
  120. package/src/hooks/index.ts +1 -1
  121. package/src/hooks/use-chat.ts +391 -256
  122. package/src/hooks/use-coagent-state-render.ts +2 -2
  123. package/src/hooks/use-coagent.ts +35 -15
  124. package/src/hooks/use-copilot-action.ts +41 -12
  125. package/src/hooks/use-copilot-chat.ts +52 -11
  126. package/src/hooks/use-copilot-runtime-client.ts +4 -0
  127. package/src/lib/copilot-task.ts +2 -8
  128. package/src/types/frontend-action.ts +55 -2
  129. package/src/types/index.ts +5 -1
  130. package/dist/chunk-2KCEHGSI.mjs.map +0 -1
  131. package/dist/chunk-DHGXL5PC.mjs.map +0 -1
  132. package/dist/chunk-EUIBVFV6.mjs +0 -294
  133. package/dist/chunk-EUIBVFV6.mjs.map +0 -1
  134. package/dist/chunk-O22KGHOQ.mjs.map +0 -1
  135. package/dist/chunk-ODN4H66E.mjs.map +0 -1
  136. package/dist/chunk-OT67R4NB.mjs.map +0 -1
  137. package/dist/chunk-XBVKTDXP.mjs.map +0 -1
  138. package/dist/chunk-XQFVXX6R.mjs.map +0 -1
  139. package/dist/chunk-Y7MI4PBB.mjs.map +0 -1
  140. /package/dist/{chunk-AG7FH7OD.mjs.map → chunk-5FYKUKG3.mjs.map} +0 -0
  141. /package/dist/{chunk-UOVONDR6.mjs.map → chunk-V3PFWGIY.mjs.map} +0 -0
@@ -86,7 +86,7 @@ __export(copilot_provider_exports, {
86
86
  module.exports = __toCommonJS(copilot_provider_exports);
87
87
 
88
88
  // src/components/copilot-provider/copilotkit.tsx
89
- var import_react8 = require("react");
89
+ var import_react10 = require("react");
90
90
 
91
91
  // src/context/copilot-context.tsx
92
92
  var import_react = __toESM(require("react"));
@@ -142,7 +142,15 @@ var emptyCopilotContext = {
142
142
  },
143
143
  agentSession: null,
144
144
  setAgentSession: () => {
145
- }
145
+ },
146
+ agentLock: null,
147
+ threadId: null,
148
+ setThreadId: () => {
149
+ },
150
+ runId: null,
151
+ setRunId: () => {
152
+ },
153
+ chatAbortControllerRef: { current: null }
146
154
  };
147
155
  var CopilotContext = import_react.default.createContext(emptyCopilotContext);
148
156
  function returnAndThrowInDebug(value) {
@@ -380,6 +388,9 @@ function CopilotMessages(_a) {
380
388
  }
381
389
 
382
390
  // src/components/toast/toast-provider.tsx
391
+ var import_react7 = require("react");
392
+
393
+ // src/components/error-boundary/error-utils.tsx
383
394
  var import_react6 = require("react");
384
395
 
385
396
  // src/components/toast/exclamation-mark-icon.tsx
@@ -409,11 +420,82 @@ var ExclamationMarkIcon = ({
409
420
  }
410
421
  );
411
422
 
412
- // src/components/toast/toast-provider.tsx
423
+ // src/components/error-boundary/error-utils.tsx
413
424
  var import_jsx_runtime3 = require("react/jsx-runtime");
414
- var ToastContext = (0, import_react6.createContext)(void 0);
425
+ function ErrorToast({ errors }) {
426
+ const errorsToRender = errors.map((error, idx) => {
427
+ var _a, _b, _c;
428
+ const message = "extensions" in error ? (_b = (_a = error.extensions) == null ? void 0 : _a.originalError) == null ? void 0 : _b.message : error.message;
429
+ const code = "extensions" in error ? (_c = error.extensions) == null ? void 0 : _c.code : null;
430
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
431
+ "div",
432
+ {
433
+ style: {
434
+ marginTop: idx === 0 ? 0 : 10,
435
+ marginBottom: 14
436
+ },
437
+ children: [
438
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ExclamationMarkIcon, { style: { marginBottom: 4 } }),
439
+ code && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
440
+ "div",
441
+ {
442
+ style: {
443
+ fontWeight: "600",
444
+ marginBottom: 4
445
+ },
446
+ children: [
447
+ "Copilot Cloud Error:",
448
+ " ",
449
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { fontFamily: "monospace", fontWeight: "normal" }, children: code })
450
+ ]
451
+ }
452
+ ),
453
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: message })
454
+ ]
455
+ },
456
+ idx
457
+ );
458
+ });
459
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
460
+ "div",
461
+ {
462
+ style: {
463
+ fontSize: "13px",
464
+ maxWidth: "600px"
465
+ },
466
+ children: [
467
+ errorsToRender,
468
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { fontSize: "11px", opacity: 0.75 }, children: "NOTE: This error only displays during local development." })
469
+ ]
470
+ }
471
+ );
472
+ }
473
+ function useErrorToast() {
474
+ const { addToast } = useToast();
475
+ return (0, import_react6.useCallback)(
476
+ (error) => {
477
+ const errorId = error.map((err) => {
478
+ var _a, _b;
479
+ const message = "extensions" in err ? ((_b = (_a = err.extensions) == null ? void 0 : _a.originalError) == null ? void 0 : _b.message) || err.message : err.message;
480
+ const stack = err.stack || "";
481
+ return btoa(message + stack).slice(0, 32);
482
+ }).join("|");
483
+ addToast({
484
+ type: "error",
485
+ id: errorId,
486
+ // Toast libraries typically dedupe by id
487
+ message: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ErrorToast, { errors: error })
488
+ });
489
+ },
490
+ [addToast]
491
+ );
492
+ }
493
+
494
+ // src/components/toast/toast-provider.tsx
495
+ var import_jsx_runtime4 = require("react/jsx-runtime");
496
+ var ToastContext = (0, import_react7.createContext)(void 0);
415
497
  function useToast() {
416
- const context = (0, import_react6.useContext)(ToastContext);
498
+ const context = (0, import_react7.useContext)(ToastContext);
417
499
  if (!context) {
418
500
  throw new Error("useToast must be used within a ToastProvider");
419
501
  }
@@ -423,68 +505,28 @@ function ToastProvider({
423
505
  enabled,
424
506
  children
425
507
  }) {
426
- const [toasts, setToasts] = (0, import_react6.useState)([]);
427
- const addToast = (0, import_react6.useCallback)((toast) => {
428
- const id = Math.random().toString(36).substring(2, 9);
429
- setToasts((currentToasts) => [...currentToasts, __spreadProps(__spreadValues({}, toast), { id })]);
508
+ const [toasts, setToasts] = (0, import_react7.useState)([]);
509
+ const addToast = (0, import_react7.useCallback)((toast) => {
510
+ var _a;
511
+ const id = (_a = toast.id) != null ? _a : Math.random().toString(36).substring(2, 9);
512
+ setToasts((currentToasts) => {
513
+ if (currentToasts.find((toast2) => toast2.id === id))
514
+ return currentToasts;
515
+ return [...currentToasts, __spreadProps(__spreadValues({}, toast), { id })];
516
+ });
430
517
  if (toast.duration) {
431
518
  setTimeout(() => {
432
519
  removeToast(id);
433
520
  }, toast.duration);
434
521
  }
435
522
  }, []);
436
- const addGraphQLErrorsToast = (0, import_react6.useCallback)((errors) => {
437
- const errorsToRender = errors.map((error, idx) => {
438
- var _a;
439
- const message = error.message;
440
- const code = (_a = error.extensions) == null ? void 0 : _a.code;
441
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
442
- "div",
443
- {
444
- style: {
445
- marginTop: idx === 0 ? 0 : 10,
446
- marginBottom: 14
447
- },
448
- children: [
449
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ExclamationMarkIcon, { style: { marginBottom: 4 } }),
450
- code && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
451
- "div",
452
- {
453
- style: {
454
- fontWeight: "600",
455
- marginBottom: 4
456
- },
457
- children: [
458
- "Copilot Cloud Error:",
459
- " ",
460
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { fontFamily: "monospace", fontWeight: "normal" }, children: code })
461
- ]
462
- }
463
- ),
464
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: message })
465
- ]
466
- },
467
- idx
468
- );
469
- });
523
+ const addGraphQLErrorsToast = (0, import_react7.useCallback)((errors) => {
470
524
  addToast({
471
525
  type: "error",
472
- message: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
473
- "div",
474
- {
475
- style: {
476
- fontSize: "13px",
477
- maxWidth: "600px"
478
- },
479
- children: [
480
- errorsToRender,
481
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { fontSize: "11px", opacity: 0.75 }, children: "NOTE: This is a Copilot Cloud error, and it only displays during local development." })
482
- ]
483
- }
484
- )
526
+ message: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ErrorToast, { errors })
485
527
  });
486
528
  }, []);
487
- const removeToast = (0, import_react6.useCallback)((id) => {
529
+ const removeToast = (0, import_react7.useCallback)((id) => {
488
530
  setToasts((currentToasts) => currentToasts.filter((toast) => toast.id !== id));
489
531
  }, []);
490
532
  const value = {
@@ -494,8 +536,8 @@ function ToastProvider({
494
536
  removeToast,
495
537
  enabled
496
538
  };
497
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(ToastContext.Provider, { value, children: [
498
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
539
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(ToastContext.Provider, { value, children: [
540
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
499
541
  "div",
500
542
  {
501
543
  style: {
@@ -509,7 +551,7 @@ function ToastProvider({
509
551
  gap: "0.5rem"
510
552
  },
511
553
  children: [
512
- toasts.length > 1 && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { textAlign: "right" }, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
554
+ toasts.length > 1 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { style: { textAlign: "right" }, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
513
555
  "button",
514
556
  {
515
557
  onClick: () => setToasts([]),
@@ -524,7 +566,7 @@ function ToastProvider({
524
566
  children: "Close All"
525
567
  }
526
568
  ) }),
527
- toasts.map((toast) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
569
+ toasts.map((toast) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
528
570
  Toast,
529
571
  {
530
572
  message: toast.message,
@@ -550,7 +592,7 @@ function Toast({
550
592
  warning: "#eab308",
551
593
  error: "#ef4444"
552
594
  };
553
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
595
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
554
596
  "div",
555
597
  {
556
598
  style: {
@@ -563,8 +605,8 @@ function Toast({
563
605
  minWidth: "200px"
564
606
  },
565
607
  children: [
566
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: message }),
567
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
608
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { children: message }),
609
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
568
610
  "button",
569
611
  {
570
612
  onClick: onClose,
@@ -589,14 +631,17 @@ function Toast({
589
631
 
590
632
  // src/hooks/use-copilot-runtime-client.ts
591
633
  var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
592
- var import_react7 = require("react");
634
+ var import_react8 = require("react");
593
635
  var useCopilotRuntimeClient = (options) => {
594
636
  const { addGraphQLErrorsToast } = useToast();
595
- const runtimeClient = (0, import_react7.useMemo)(() => {
637
+ const addErrorToast = useErrorToast();
638
+ const runtimeClient = (0, import_react8.useMemo)(() => {
596
639
  return new import_runtime_client_gql.CopilotRuntimeClient(__spreadProps(__spreadValues({}, options), {
597
640
  handleGQLErrors: (error) => {
598
641
  if (error.graphQLErrors.length) {
599
642
  addGraphQLErrorsToast(error.graphQLErrors);
643
+ } else {
644
+ addErrorToast([error]);
600
645
  }
601
646
  }
602
647
  }));
@@ -618,13 +663,41 @@ function getHostname() {
618
663
  return "";
619
664
  }
620
665
 
666
+ // src/components/error-boundary/error-boundary.tsx
667
+ var import_react9 = __toESM(require("react"));
668
+ var import_jsx_runtime5 = require("react/jsx-runtime");
669
+ var CopilotErrorBoundary = class extends import_react9.default.Component {
670
+ constructor(props) {
671
+ super(props);
672
+ this.state = { hasError: false };
673
+ }
674
+ static getDerivedStateFromError(error) {
675
+ return { hasError: true, error };
676
+ }
677
+ componentDidCatch(error, errorInfo) {
678
+ console.error("CopilotKit Error:", error, errorInfo);
679
+ }
680
+ render() {
681
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ErrorToast2, { error: this.state.error, children: this.props.children });
682
+ }
683
+ };
684
+ function ErrorToast2({ error, children }) {
685
+ const addErrorToast = useErrorToast();
686
+ (0, import_react9.useEffect)(() => {
687
+ if (error) {
688
+ addErrorToast([error]);
689
+ }
690
+ }, [error, addErrorToast]);
691
+ return children;
692
+ }
693
+
621
694
  // src/components/copilot-provider/copilotkit.tsx
622
- var import_jsx_runtime4 = require("react/jsx-runtime");
695
+ var import_jsx_runtime6 = require("react/jsx-runtime");
623
696
  function CopilotKit(_a) {
624
697
  var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
625
698
  const showDevConsole = props.showDevConsole === void 0 ? "auto" : props.showDevConsole;
626
699
  const enabled = shouldShowDevConsole(showDevConsole);
627
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ToastProvider, { enabled, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CopilotKitInternal, __spreadProps(__spreadValues({}, props), { children })) });
700
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ToastProvider, { enabled, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(CopilotErrorBoundary, { children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(CopilotKitInternal, __spreadProps(__spreadValues({}, props), { children })) }) });
628
701
  }
629
702
  function CopilotKitInternal(_a) {
630
703
  var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
@@ -634,49 +707,49 @@ function CopilotKitInternal(_a) {
634
707
  );
635
708
  }
636
709
  const chatApiEndpoint = props.runtimeUrl || import_shared3.COPILOT_CLOUD_CHAT_URL;
637
- const [actions, setActions] = (0, import_react8.useState)({});
638
- const [coAgentStateRenders, setCoAgentStateRenders] = (0, import_react8.useState)({});
639
- const chatComponentsCache = (0, import_react8.useRef)({
710
+ const [actions, setActions] = (0, import_react10.useState)({});
711
+ const [coAgentStateRenders, setCoAgentStateRenders] = (0, import_react10.useState)({});
712
+ const chatComponentsCache = (0, import_react10.useRef)({
640
713
  actions: {},
641
714
  coAgentStateRenders: {}
642
715
  });
643
716
  const { addElement, removeElement, printTree } = use_tree_default();
644
- const [isLoading, setIsLoading] = (0, import_react8.useState)(false);
645
- const [chatInstructions, setChatInstructions] = (0, import_react8.useState)("");
717
+ const [isLoading, setIsLoading] = (0, import_react10.useState)(false);
718
+ const [chatInstructions, setChatInstructions] = (0, import_react10.useState)("");
646
719
  const {
647
720
  addElement: addDocument,
648
721
  removeElement: removeDocument,
649
722
  allElements: allDocuments
650
723
  } = use_flat_category_store_default();
651
- const setAction = (0, import_react8.useCallback)((id, action) => {
724
+ const setAction = (0, import_react10.useCallback)((id, action) => {
652
725
  setActions((prevPoints) => {
653
726
  return __spreadProps(__spreadValues({}, prevPoints), {
654
727
  [id]: action
655
728
  });
656
729
  });
657
730
  }, []);
658
- const removeAction = (0, import_react8.useCallback)((id) => {
731
+ const removeAction = (0, import_react10.useCallback)((id) => {
659
732
  setActions((prevPoints) => {
660
733
  const newPoints = __spreadValues({}, prevPoints);
661
734
  delete newPoints[id];
662
735
  return newPoints;
663
736
  });
664
737
  }, []);
665
- const setCoAgentStateRender = (0, import_react8.useCallback)((id, stateRender) => {
738
+ const setCoAgentStateRender = (0, import_react10.useCallback)((id, stateRender) => {
666
739
  setCoAgentStateRenders((prevPoints) => {
667
740
  return __spreadProps(__spreadValues({}, prevPoints), {
668
741
  [id]: stateRender
669
742
  });
670
743
  });
671
744
  }, []);
672
- const removeCoAgentStateRender = (0, import_react8.useCallback)((id) => {
745
+ const removeCoAgentStateRender = (0, import_react10.useCallback)((id) => {
673
746
  setCoAgentStateRenders((prevPoints) => {
674
747
  const newPoints = __spreadValues({}, prevPoints);
675
748
  delete newPoints[id];
676
749
  return newPoints;
677
750
  });
678
751
  }, []);
679
- const getContextString = (0, import_react8.useCallback)(
752
+ const getContextString = (0, import_react10.useCallback)(
680
753
  (documents, categories) => {
681
754
  const documentsString = documents.map((document) => {
682
755
  return `${document.name} (${document.sourceApplication}):
@@ -689,37 +762,37 @@ ${nonDocumentStrings}`;
689
762
  },
690
763
  [printTree]
691
764
  );
692
- const addContext = (0, import_react8.useCallback)(
765
+ const addContext = (0, import_react10.useCallback)(
693
766
  (context, parentId, categories = defaultCopilotContextCategories) => {
694
767
  return addElement(context, categories, parentId);
695
768
  },
696
769
  [addElement]
697
770
  );
698
- const removeContext = (0, import_react8.useCallback)(
771
+ const removeContext = (0, import_react10.useCallback)(
699
772
  (id) => {
700
773
  removeElement(id);
701
774
  },
702
775
  [removeElement]
703
776
  );
704
- const getFunctionCallHandler = (0, import_react8.useCallback)(
777
+ const getFunctionCallHandler = (0, import_react10.useCallback)(
705
778
  (customEntryPoints) => {
706
779
  return entryPointsToFunctionCallHandler(Object.values(customEntryPoints || actions));
707
780
  },
708
781
  [actions]
709
782
  );
710
- const getDocumentsContext = (0, import_react8.useCallback)(
783
+ const getDocumentsContext = (0, import_react10.useCallback)(
711
784
  (categories) => {
712
785
  return allDocuments(categories);
713
786
  },
714
787
  [allDocuments]
715
788
  );
716
- const addDocumentContext = (0, import_react8.useCallback)(
789
+ const addDocumentContext = (0, import_react10.useCallback)(
717
790
  (documentPointer, categories = defaultCopilotContextCategories) => {
718
791
  return addDocument(documentPointer, categories);
719
792
  },
720
793
  [addDocument]
721
794
  );
722
- const removeDocumentContext = (0, import_react8.useCallback)(
795
+ const removeDocumentContext = (0, import_react10.useCallback)(
723
796
  (documentId) => {
724
797
  removeDocument(documentId);
725
798
  },
@@ -732,7 +805,7 @@ ${nonDocumentStrings}`;
732
805
  );
733
806
  }
734
807
  }
735
- const copilotApiConfig = (0, import_react8.useMemo)(() => {
808
+ const copilotApiConfig = (0, import_react10.useMemo)(() => {
736
809
  var _a2, _b2;
737
810
  let cloud = void 0;
738
811
  if (props.publicApiKey) {
@@ -774,7 +847,7 @@ ${nonDocumentStrings}`;
774
847
  headers,
775
848
  credentials: copilotApiConfig.credentials
776
849
  });
777
- const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = (0, import_react8.useState)({});
850
+ const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = (0, import_react10.useState)({});
778
851
  const addChatSuggestionConfiguration = (id, suggestion) => {
779
852
  setChatSuggestionConfiguration((prev) => __spreadProps(__spreadValues({}, prev), { [id]: suggestion }));
780
853
  };
@@ -784,9 +857,9 @@ ${nonDocumentStrings}`;
784
857
  return rest;
785
858
  });
786
859
  };
787
- const [coagentStates, setCoagentStates] = (0, import_react8.useState)({});
788
- const coagentStatesRef = (0, import_react8.useRef)({});
789
- const setCoagentStatesWithRef = (0, import_react8.useCallback)(
860
+ const [coagentStates, setCoagentStates] = (0, import_react10.useState)({});
861
+ const coagentStatesRef = (0, import_react10.useRef)({});
862
+ const setCoagentStatesWithRef = (0, import_react10.useCallback)(
790
863
  (value) => {
791
864
  const newValue = typeof value === "function" ? value(coagentStatesRef.current) : value;
792
865
  coagentStatesRef.current = newValue;
@@ -802,9 +875,12 @@ ${nonDocumentStrings}`;
802
875
  agentName: props.agent
803
876
  };
804
877
  }
805
- const [agentSession, setAgentSession] = (0, import_react8.useState)(initialAgentSession);
878
+ const [agentSession, setAgentSession] = (0, import_react10.useState)(initialAgentSession);
879
+ const [threadId, setThreadId] = (0, import_react10.useState)(null);
880
+ const [runId, setRunId] = (0, import_react10.useState)(null);
881
+ const chatAbortControllerRef = (0, import_react10.useRef)(null);
806
882
  const showDevConsole = props.showDevConsole === void 0 ? "auto" : props.showDevConsole;
807
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
883
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
808
884
  CopilotContext.Provider,
809
885
  {
810
886
  value: {
@@ -837,9 +913,15 @@ ${nonDocumentStrings}`;
837
913
  setCoagentStatesWithRef,
838
914
  agentSession,
839
915
  setAgentSession,
840
- runtimeClient
916
+ runtimeClient,
917
+ agentLock: props.agent || null,
918
+ threadId,
919
+ setThreadId,
920
+ runId,
921
+ setRunId,
922
+ chatAbortControllerRef
841
923
  },
842
- children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CopilotMessages, { children })
924
+ children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(CopilotMessages, { children })
843
925
  }
844
926
  );
845
927
  }