@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
@@ -85,7 +85,7 @@ __export(copilotkit_exports, {
85
85
  defaultCopilotContextCategories: () => defaultCopilotContextCategories
86
86
  });
87
87
  module.exports = __toCommonJS(copilotkit_exports);
88
- var import_react8 = require("react");
88
+ var import_react10 = require("react");
89
89
 
90
90
  // src/context/copilot-context.tsx
91
91
  var import_react = __toESM(require("react"));
@@ -141,7 +141,15 @@ var emptyCopilotContext = {
141
141
  },
142
142
  agentSession: null,
143
143
  setAgentSession: () => {
144
- }
144
+ },
145
+ agentLock: null,
146
+ threadId: null,
147
+ setThreadId: () => {
148
+ },
149
+ runId: null,
150
+ setRunId: () => {
151
+ },
152
+ chatAbortControllerRef: { current: null }
145
153
  };
146
154
  var CopilotContext = import_react.default.createContext(emptyCopilotContext);
147
155
  function returnAndThrowInDebug(value) {
@@ -379,6 +387,9 @@ function CopilotMessages(_a) {
379
387
  }
380
388
 
381
389
  // src/components/toast/toast-provider.tsx
390
+ var import_react7 = require("react");
391
+
392
+ // src/components/error-boundary/error-utils.tsx
382
393
  var import_react6 = require("react");
383
394
 
384
395
  // src/components/toast/exclamation-mark-icon.tsx
@@ -408,11 +419,82 @@ var ExclamationMarkIcon = ({
408
419
  }
409
420
  );
410
421
 
411
- // src/components/toast/toast-provider.tsx
422
+ // src/components/error-boundary/error-utils.tsx
412
423
  var import_jsx_runtime3 = require("react/jsx-runtime");
413
- var ToastContext = (0, import_react6.createContext)(void 0);
424
+ function ErrorToast({ errors }) {
425
+ const errorsToRender = errors.map((error, idx) => {
426
+ var _a, _b, _c;
427
+ const message = "extensions" in error ? (_b = (_a = error.extensions) == null ? void 0 : _a.originalError) == null ? void 0 : _b.message : error.message;
428
+ const code = "extensions" in error ? (_c = error.extensions) == null ? void 0 : _c.code : null;
429
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
430
+ "div",
431
+ {
432
+ style: {
433
+ marginTop: idx === 0 ? 0 : 10,
434
+ marginBottom: 14
435
+ },
436
+ children: [
437
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ExclamationMarkIcon, { style: { marginBottom: 4 } }),
438
+ code && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
439
+ "div",
440
+ {
441
+ style: {
442
+ fontWeight: "600",
443
+ marginBottom: 4
444
+ },
445
+ children: [
446
+ "Copilot Cloud Error:",
447
+ " ",
448
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { fontFamily: "monospace", fontWeight: "normal" }, children: code })
449
+ ]
450
+ }
451
+ ),
452
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: message })
453
+ ]
454
+ },
455
+ idx
456
+ );
457
+ });
458
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
459
+ "div",
460
+ {
461
+ style: {
462
+ fontSize: "13px",
463
+ maxWidth: "600px"
464
+ },
465
+ children: [
466
+ errorsToRender,
467
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { fontSize: "11px", opacity: 0.75 }, children: "NOTE: This error only displays during local development." })
468
+ ]
469
+ }
470
+ );
471
+ }
472
+ function useErrorToast() {
473
+ const { addToast } = useToast();
474
+ return (0, import_react6.useCallback)(
475
+ (error) => {
476
+ const errorId = error.map((err) => {
477
+ var _a, _b;
478
+ const message = "extensions" in err ? ((_b = (_a = err.extensions) == null ? void 0 : _a.originalError) == null ? void 0 : _b.message) || err.message : err.message;
479
+ const stack = err.stack || "";
480
+ return btoa(message + stack).slice(0, 32);
481
+ }).join("|");
482
+ addToast({
483
+ type: "error",
484
+ id: errorId,
485
+ // Toast libraries typically dedupe by id
486
+ message: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ErrorToast, { errors: error })
487
+ });
488
+ },
489
+ [addToast]
490
+ );
491
+ }
492
+
493
+ // src/components/toast/toast-provider.tsx
494
+ var import_jsx_runtime4 = require("react/jsx-runtime");
495
+ var ToastContext = (0, import_react7.createContext)(void 0);
414
496
  function useToast() {
415
- const context = (0, import_react6.useContext)(ToastContext);
497
+ const context = (0, import_react7.useContext)(ToastContext);
416
498
  if (!context) {
417
499
  throw new Error("useToast must be used within a ToastProvider");
418
500
  }
@@ -422,68 +504,28 @@ function ToastProvider({
422
504
  enabled,
423
505
  children
424
506
  }) {
425
- const [toasts, setToasts] = (0, import_react6.useState)([]);
426
- const addToast = (0, import_react6.useCallback)((toast) => {
427
- const id = Math.random().toString(36).substring(2, 9);
428
- setToasts((currentToasts) => [...currentToasts, __spreadProps(__spreadValues({}, toast), { id })]);
507
+ const [toasts, setToasts] = (0, import_react7.useState)([]);
508
+ const addToast = (0, import_react7.useCallback)((toast) => {
509
+ var _a;
510
+ const id = (_a = toast.id) != null ? _a : Math.random().toString(36).substring(2, 9);
511
+ setToasts((currentToasts) => {
512
+ if (currentToasts.find((toast2) => toast2.id === id))
513
+ return currentToasts;
514
+ return [...currentToasts, __spreadProps(__spreadValues({}, toast), { id })];
515
+ });
429
516
  if (toast.duration) {
430
517
  setTimeout(() => {
431
518
  removeToast(id);
432
519
  }, toast.duration);
433
520
  }
434
521
  }, []);
435
- const addGraphQLErrorsToast = (0, import_react6.useCallback)((errors) => {
436
- const errorsToRender = errors.map((error, idx) => {
437
- var _a;
438
- const message = error.message;
439
- const code = (_a = error.extensions) == null ? void 0 : _a.code;
440
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
441
- "div",
442
- {
443
- style: {
444
- marginTop: idx === 0 ? 0 : 10,
445
- marginBottom: 14
446
- },
447
- children: [
448
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ExclamationMarkIcon, { style: { marginBottom: 4 } }),
449
- code && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
450
- "div",
451
- {
452
- style: {
453
- fontWeight: "600",
454
- marginBottom: 4
455
- },
456
- children: [
457
- "Copilot Cloud Error:",
458
- " ",
459
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { fontFamily: "monospace", fontWeight: "normal" }, children: code })
460
- ]
461
- }
462
- ),
463
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: message })
464
- ]
465
- },
466
- idx
467
- );
468
- });
522
+ const addGraphQLErrorsToast = (0, import_react7.useCallback)((errors) => {
469
523
  addToast({
470
524
  type: "error",
471
- message: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
472
- "div",
473
- {
474
- style: {
475
- fontSize: "13px",
476
- maxWidth: "600px"
477
- },
478
- children: [
479
- errorsToRender,
480
- /* @__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." })
481
- ]
482
- }
483
- )
525
+ message: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ErrorToast, { errors })
484
526
  });
485
527
  }, []);
486
- const removeToast = (0, import_react6.useCallback)((id) => {
528
+ const removeToast = (0, import_react7.useCallback)((id) => {
487
529
  setToasts((currentToasts) => currentToasts.filter((toast) => toast.id !== id));
488
530
  }, []);
489
531
  const value = {
@@ -493,8 +535,8 @@ function ToastProvider({
493
535
  removeToast,
494
536
  enabled
495
537
  };
496
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(ToastContext.Provider, { value, children: [
497
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
538
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(ToastContext.Provider, { value, children: [
539
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
498
540
  "div",
499
541
  {
500
542
  style: {
@@ -508,7 +550,7 @@ function ToastProvider({
508
550
  gap: "0.5rem"
509
551
  },
510
552
  children: [
511
- toasts.length > 1 && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { textAlign: "right" }, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
553
+ toasts.length > 1 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { style: { textAlign: "right" }, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
512
554
  "button",
513
555
  {
514
556
  onClick: () => setToasts([]),
@@ -523,7 +565,7 @@ function ToastProvider({
523
565
  children: "Close All"
524
566
  }
525
567
  ) }),
526
- toasts.map((toast) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
568
+ toasts.map((toast) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
527
569
  Toast,
528
570
  {
529
571
  message: toast.message,
@@ -549,7 +591,7 @@ function Toast({
549
591
  warning: "#eab308",
550
592
  error: "#ef4444"
551
593
  };
552
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
594
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
553
595
  "div",
554
596
  {
555
597
  style: {
@@ -562,8 +604,8 @@ function Toast({
562
604
  minWidth: "200px"
563
605
  },
564
606
  children: [
565
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: message }),
566
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
607
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { children: message }),
608
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
567
609
  "button",
568
610
  {
569
611
  onClick: onClose,
@@ -588,14 +630,17 @@ function Toast({
588
630
 
589
631
  // src/hooks/use-copilot-runtime-client.ts
590
632
  var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
591
- var import_react7 = require("react");
633
+ var import_react8 = require("react");
592
634
  var useCopilotRuntimeClient = (options) => {
593
635
  const { addGraphQLErrorsToast } = useToast();
594
- const runtimeClient = (0, import_react7.useMemo)(() => {
636
+ const addErrorToast = useErrorToast();
637
+ const runtimeClient = (0, import_react8.useMemo)(() => {
595
638
  return new import_runtime_client_gql.CopilotRuntimeClient(__spreadProps(__spreadValues({}, options), {
596
639
  handleGQLErrors: (error) => {
597
640
  if (error.graphQLErrors.length) {
598
641
  addGraphQLErrorsToast(error.graphQLErrors);
642
+ } else {
643
+ addErrorToast([error]);
599
644
  }
600
645
  }
601
646
  }));
@@ -617,13 +662,41 @@ function getHostname() {
617
662
  return "";
618
663
  }
619
664
 
665
+ // src/components/error-boundary/error-boundary.tsx
666
+ var import_react9 = __toESM(require("react"));
667
+ var import_jsx_runtime5 = require("react/jsx-runtime");
668
+ var CopilotErrorBoundary = class extends import_react9.default.Component {
669
+ constructor(props) {
670
+ super(props);
671
+ this.state = { hasError: false };
672
+ }
673
+ static getDerivedStateFromError(error) {
674
+ return { hasError: true, error };
675
+ }
676
+ componentDidCatch(error, errorInfo) {
677
+ console.error("CopilotKit Error:", error, errorInfo);
678
+ }
679
+ render() {
680
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ErrorToast2, { error: this.state.error, children: this.props.children });
681
+ }
682
+ };
683
+ function ErrorToast2({ error, children }) {
684
+ const addErrorToast = useErrorToast();
685
+ (0, import_react9.useEffect)(() => {
686
+ if (error) {
687
+ addErrorToast([error]);
688
+ }
689
+ }, [error, addErrorToast]);
690
+ return children;
691
+ }
692
+
620
693
  // src/components/copilot-provider/copilotkit.tsx
621
- var import_jsx_runtime4 = require("react/jsx-runtime");
694
+ var import_jsx_runtime6 = require("react/jsx-runtime");
622
695
  function CopilotKit(_a) {
623
696
  var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
624
697
  const showDevConsole = props.showDevConsole === void 0 ? "auto" : props.showDevConsole;
625
698
  const enabled = shouldShowDevConsole(showDevConsole);
626
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ToastProvider, { enabled, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CopilotKitInternal, __spreadProps(__spreadValues({}, props), { children })) });
699
+ 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 })) }) });
627
700
  }
628
701
  function CopilotKitInternal(_a) {
629
702
  var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
@@ -633,49 +706,49 @@ function CopilotKitInternal(_a) {
633
706
  );
634
707
  }
635
708
  const chatApiEndpoint = props.runtimeUrl || import_shared3.COPILOT_CLOUD_CHAT_URL;
636
- const [actions, setActions] = (0, import_react8.useState)({});
637
- const [coAgentStateRenders, setCoAgentStateRenders] = (0, import_react8.useState)({});
638
- const chatComponentsCache = (0, import_react8.useRef)({
709
+ const [actions, setActions] = (0, import_react10.useState)({});
710
+ const [coAgentStateRenders, setCoAgentStateRenders] = (0, import_react10.useState)({});
711
+ const chatComponentsCache = (0, import_react10.useRef)({
639
712
  actions: {},
640
713
  coAgentStateRenders: {}
641
714
  });
642
715
  const { addElement, removeElement, printTree } = use_tree_default();
643
- const [isLoading, setIsLoading] = (0, import_react8.useState)(false);
644
- const [chatInstructions, setChatInstructions] = (0, import_react8.useState)("");
716
+ const [isLoading, setIsLoading] = (0, import_react10.useState)(false);
717
+ const [chatInstructions, setChatInstructions] = (0, import_react10.useState)("");
645
718
  const {
646
719
  addElement: addDocument,
647
720
  removeElement: removeDocument,
648
721
  allElements: allDocuments
649
722
  } = use_flat_category_store_default();
650
- const setAction = (0, import_react8.useCallback)((id, action) => {
723
+ const setAction = (0, import_react10.useCallback)((id, action) => {
651
724
  setActions((prevPoints) => {
652
725
  return __spreadProps(__spreadValues({}, prevPoints), {
653
726
  [id]: action
654
727
  });
655
728
  });
656
729
  }, []);
657
- const removeAction = (0, import_react8.useCallback)((id) => {
730
+ const removeAction = (0, import_react10.useCallback)((id) => {
658
731
  setActions((prevPoints) => {
659
732
  const newPoints = __spreadValues({}, prevPoints);
660
733
  delete newPoints[id];
661
734
  return newPoints;
662
735
  });
663
736
  }, []);
664
- const setCoAgentStateRender = (0, import_react8.useCallback)((id, stateRender) => {
737
+ const setCoAgentStateRender = (0, import_react10.useCallback)((id, stateRender) => {
665
738
  setCoAgentStateRenders((prevPoints) => {
666
739
  return __spreadProps(__spreadValues({}, prevPoints), {
667
740
  [id]: stateRender
668
741
  });
669
742
  });
670
743
  }, []);
671
- const removeCoAgentStateRender = (0, import_react8.useCallback)((id) => {
744
+ const removeCoAgentStateRender = (0, import_react10.useCallback)((id) => {
672
745
  setCoAgentStateRenders((prevPoints) => {
673
746
  const newPoints = __spreadValues({}, prevPoints);
674
747
  delete newPoints[id];
675
748
  return newPoints;
676
749
  });
677
750
  }, []);
678
- const getContextString = (0, import_react8.useCallback)(
751
+ const getContextString = (0, import_react10.useCallback)(
679
752
  (documents, categories) => {
680
753
  const documentsString = documents.map((document) => {
681
754
  return `${document.name} (${document.sourceApplication}):
@@ -688,37 +761,37 @@ ${nonDocumentStrings}`;
688
761
  },
689
762
  [printTree]
690
763
  );
691
- const addContext = (0, import_react8.useCallback)(
764
+ const addContext = (0, import_react10.useCallback)(
692
765
  (context, parentId, categories = defaultCopilotContextCategories) => {
693
766
  return addElement(context, categories, parentId);
694
767
  },
695
768
  [addElement]
696
769
  );
697
- const removeContext = (0, import_react8.useCallback)(
770
+ const removeContext = (0, import_react10.useCallback)(
698
771
  (id) => {
699
772
  removeElement(id);
700
773
  },
701
774
  [removeElement]
702
775
  );
703
- const getFunctionCallHandler = (0, import_react8.useCallback)(
776
+ const getFunctionCallHandler = (0, import_react10.useCallback)(
704
777
  (customEntryPoints) => {
705
778
  return entryPointsToFunctionCallHandler(Object.values(customEntryPoints || actions));
706
779
  },
707
780
  [actions]
708
781
  );
709
- const getDocumentsContext = (0, import_react8.useCallback)(
782
+ const getDocumentsContext = (0, import_react10.useCallback)(
710
783
  (categories) => {
711
784
  return allDocuments(categories);
712
785
  },
713
786
  [allDocuments]
714
787
  );
715
- const addDocumentContext = (0, import_react8.useCallback)(
788
+ const addDocumentContext = (0, import_react10.useCallback)(
716
789
  (documentPointer, categories = defaultCopilotContextCategories) => {
717
790
  return addDocument(documentPointer, categories);
718
791
  },
719
792
  [addDocument]
720
793
  );
721
- const removeDocumentContext = (0, import_react8.useCallback)(
794
+ const removeDocumentContext = (0, import_react10.useCallback)(
722
795
  (documentId) => {
723
796
  removeDocument(documentId);
724
797
  },
@@ -731,7 +804,7 @@ ${nonDocumentStrings}`;
731
804
  );
732
805
  }
733
806
  }
734
- const copilotApiConfig = (0, import_react8.useMemo)(() => {
807
+ const copilotApiConfig = (0, import_react10.useMemo)(() => {
735
808
  var _a2, _b2;
736
809
  let cloud = void 0;
737
810
  if (props.publicApiKey) {
@@ -773,7 +846,7 @@ ${nonDocumentStrings}`;
773
846
  headers,
774
847
  credentials: copilotApiConfig.credentials
775
848
  });
776
- const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = (0, import_react8.useState)({});
849
+ const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = (0, import_react10.useState)({});
777
850
  const addChatSuggestionConfiguration = (id, suggestion) => {
778
851
  setChatSuggestionConfiguration((prev) => __spreadProps(__spreadValues({}, prev), { [id]: suggestion }));
779
852
  };
@@ -783,9 +856,9 @@ ${nonDocumentStrings}`;
783
856
  return rest;
784
857
  });
785
858
  };
786
- const [coagentStates, setCoagentStates] = (0, import_react8.useState)({});
787
- const coagentStatesRef = (0, import_react8.useRef)({});
788
- const setCoagentStatesWithRef = (0, import_react8.useCallback)(
859
+ const [coagentStates, setCoagentStates] = (0, import_react10.useState)({});
860
+ const coagentStatesRef = (0, import_react10.useRef)({});
861
+ const setCoagentStatesWithRef = (0, import_react10.useCallback)(
789
862
  (value) => {
790
863
  const newValue = typeof value === "function" ? value(coagentStatesRef.current) : value;
791
864
  coagentStatesRef.current = newValue;
@@ -801,9 +874,12 @@ ${nonDocumentStrings}`;
801
874
  agentName: props.agent
802
875
  };
803
876
  }
804
- const [agentSession, setAgentSession] = (0, import_react8.useState)(initialAgentSession);
877
+ const [agentSession, setAgentSession] = (0, import_react10.useState)(initialAgentSession);
878
+ const [threadId, setThreadId] = (0, import_react10.useState)(null);
879
+ const [runId, setRunId] = (0, import_react10.useState)(null);
880
+ const chatAbortControllerRef = (0, import_react10.useRef)(null);
805
881
  const showDevConsole = props.showDevConsole === void 0 ? "auto" : props.showDevConsole;
806
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
882
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
807
883
  CopilotContext.Provider,
808
884
  {
809
885
  value: {
@@ -836,9 +912,15 @@ ${nonDocumentStrings}`;
836
912
  setCoagentStatesWithRef,
837
913
  agentSession,
838
914
  setAgentSession,
839
- runtimeClient
915
+ runtimeClient,
916
+ agentLock: props.agent || null,
917
+ threadId,
918
+ setThreadId,
919
+ runId,
920
+ setRunId,
921
+ chatAbortControllerRef
840
922
  },
841
- children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CopilotMessages, { children })
923
+ children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(CopilotMessages, { children })
842
924
  }
843
925
  );
844
926
  }