@copilotkit/react-core 1.70.3 → 1.71.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.
Files changed (60) hide show
  1. package/dist/{copilotkit-BU3OvveB.cjs → copilotkit-BkVEkUS0.cjs} +369 -154
  2. package/dist/copilotkit-BkVEkUS0.cjs.map +1 -0
  3. package/dist/{copilotkit-Bs98akp9.d.mts → copilotkit-ChjzWqn6.d.mts} +33 -8
  4. package/dist/copilotkit-ChjzWqn6.d.mts.map +1 -0
  5. package/dist/{copilotkit-Ap_yisA5.mjs → copilotkit-D5BTo0YG.mjs} +368 -153
  6. package/dist/copilotkit-D5BTo0YG.mjs.map +1 -0
  7. package/dist/{copilotkit-X2eGbOwf.d.cts → copilotkit-DCIXZawe.d.cts} +33 -8
  8. package/dist/copilotkit-DCIXZawe.d.cts.map +1 -0
  9. package/dist/index.cjs +3 -3
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.cts +1 -1
  12. package/dist/index.d.mts +1 -1
  13. package/dist/index.mjs +4 -4
  14. package/dist/index.mjs.map +1 -1
  15. package/dist/index.umd.js +180 -139
  16. package/dist/index.umd.js.map +1 -1
  17. package/dist/v2/context.cjs +4 -0
  18. package/dist/v2/context.cjs.map +1 -1
  19. package/dist/v2/context.d.cts +3 -1
  20. package/dist/v2/context.d.cts.map +1 -1
  21. package/dist/v2/context.d.mts +3 -1
  22. package/dist/v2/context.d.mts.map +1 -1
  23. package/dist/v2/context.mjs +3 -1
  24. package/dist/v2/context.mjs.map +1 -1
  25. package/dist/v2/headless.cjs +20 -5
  26. package/dist/v2/headless.cjs.map +1 -1
  27. package/dist/v2/headless.d.cts +9 -4
  28. package/dist/v2/headless.d.cts.map +1 -1
  29. package/dist/v2/headless.d.mts +9 -4
  30. package/dist/v2/headless.d.mts.map +1 -1
  31. package/dist/v2/headless.mjs +21 -6
  32. package/dist/v2/headless.mjs.map +1 -1
  33. package/dist/v2/index.cjs +1 -1
  34. package/dist/v2/index.css +1 -1
  35. package/dist/v2/index.d.cts +1 -1
  36. package/dist/v2/index.d.mts +1 -1
  37. package/dist/v2/index.mjs +1 -1
  38. package/dist/v2/index.umd.js +495 -278
  39. package/dist/v2/index.umd.js.map +1 -1
  40. package/package.json +8 -9
  41. package/dist/copilotkit-Ap_yisA5.mjs.map +0 -1
  42. package/dist/copilotkit-BU3OvveB.cjs.map +0 -1
  43. package/dist/copilotkit-Bs98akp9.d.mts.map +0 -1
  44. package/dist/copilotkit-X2eGbOwf.d.cts.map +0 -1
  45. package/skills/react-core/SKILL.md +0 -110
  46. package/skills/react-core/references/agent-access.md +0 -355
  47. package/skills/react-core/references/attachments.md +0 -311
  48. package/skills/react-core/references/capabilities.md +0 -138
  49. package/skills/react-core/references/chat-components.md +0 -229
  50. package/skills/react-core/references/client-side-tools.md +0 -358
  51. package/skills/react-core/references/custom-message-renderers.md +0 -223
  52. package/skills/react-core/references/debug-mode.md +0 -140
  53. package/skills/react-core/references/human-in-the-loop.md +0 -312
  54. package/skills/react-core/references/provider-setup.md +0 -358
  55. package/skills/react-core/references/rendering-activity-messages.md +0 -201
  56. package/skills/react-core/references/rendering-tool-calls.md +0 -319
  57. package/skills/react-core/references/suggestions.md +0 -211
  58. package/skills/react-core/references/switching-agents-recipes.md +0 -161
  59. package/skills/react-core/references/switching-agents.md +0 -240
  60. package/skills/react-core/references/threads.md +0 -289
@@ -37,6 +37,134 @@ react = __toESM(react);
37
37
  _radix_ui_react_tooltip = __toESM(_radix_ui_react_tooltip);
38
38
  _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
39
39
 
40
+ //#region src/v2/lib/react-core.ts
41
+ var CopilotKitCoreReact = class extends _copilotkit_core.CopilotKitCore {
42
+ constructor(config) {
43
+ super(config);
44
+ this._renderToolCalls = [];
45
+ this._hookRenderToolCalls = /* @__PURE__ */ new Map();
46
+ this._cachedMergedRenderToolCalls = null;
47
+ this._renderCustomMessages = [];
48
+ this._renderActivityMessages = [];
49
+ this._interruptElement = null;
50
+ this._renderToolCalls = config.renderToolCalls ?? [];
51
+ this._renderCustomMessages = config.renderCustomMessages ?? [];
52
+ this._renderActivityMessages = config.renderActivityMessages ?? [];
53
+ }
54
+ get renderCustomMessages() {
55
+ return this._renderCustomMessages;
56
+ }
57
+ get renderActivityMessages() {
58
+ return this._renderActivityMessages;
59
+ }
60
+ get renderToolCalls() {
61
+ if (this._hookRenderToolCalls.size === 0) return this._renderToolCalls;
62
+ if (this._cachedMergedRenderToolCalls) return this._cachedMergedRenderToolCalls;
63
+ const merged = /* @__PURE__ */ new Map();
64
+ for (const rc of this._renderToolCalls) merged.set(`${rc.agentId ?? ""}:${rc.name}`, rc);
65
+ for (const [key, rc] of this._hookRenderToolCalls) merged.set(key, rc);
66
+ this._cachedMergedRenderToolCalls = Array.from(merged.values());
67
+ return this._cachedMergedRenderToolCalls;
68
+ }
69
+ setRenderActivityMessages(renderers) {
70
+ this._renderActivityMessages = renderers;
71
+ }
72
+ setRenderCustomMessages(renderers) {
73
+ this._renderCustomMessages = renderers;
74
+ }
75
+ setRenderToolCalls(renderToolCalls) {
76
+ this._renderToolCalls = renderToolCalls;
77
+ this._cachedMergedRenderToolCalls = null;
78
+ this._notifyRenderToolCallsChanged();
79
+ }
80
+ addHookRenderToolCall(entry) {
81
+ const key = `${entry.agentId ?? ""}:${entry.name}`;
82
+ this._hookRenderToolCalls.set(key, entry);
83
+ this._cachedMergedRenderToolCalls = null;
84
+ this._notifyRenderToolCallsChanged();
85
+ }
86
+ removeHookRenderToolCall(name, agentId) {
87
+ const key = `${agentId ?? ""}:${name}`;
88
+ if (this._hookRenderToolCalls.delete(key)) {
89
+ this._cachedMergedRenderToolCalls = null;
90
+ this._notifyRenderToolCallsChanged();
91
+ }
92
+ }
93
+ _notifyRenderToolCallsChanged() {
94
+ this.notifySubscribers((subscriber) => {
95
+ const reactSubscriber = subscriber;
96
+ if (reactSubscriber.onRenderToolCallsChanged) reactSubscriber.onRenderToolCallsChanged({
97
+ copilotkit: this,
98
+ renderToolCalls: this.renderToolCalls
99
+ });
100
+ }, "Subscriber onRenderToolCallsChanged error:");
101
+ }
102
+ get interruptElement() {
103
+ return this._interruptElement;
104
+ }
105
+ setInterruptElement(element) {
106
+ this._interruptElement = element;
107
+ this.notifySubscribers((subscriber) => {
108
+ subscriber.onInterruptElementChanged?.({
109
+ copilotkit: this,
110
+ interruptElement: this._interruptElement
111
+ });
112
+ }, "Subscriber onInterruptElementChanged error:");
113
+ }
114
+ subscribe(subscriber) {
115
+ return super.subscribe(subscriber);
116
+ }
117
+ /**
118
+ * Wait for pending React state updates before the follow-up agent run.
119
+ *
120
+ * When a frontend tool handler calls setState(), React 18 batches the update
121
+ * and schedules a commit via its internal scheduler (MessageChannel). The
122
+ * useAgentContext hook registers context via useLayoutEffect, which runs
123
+ * synchronously after React commits that batch.
124
+ *
125
+ * Awaiting a zero-delay timeout yields to the macrotask queue. React's
126
+ * MessageChannel task runs first, committing the pending state and running
127
+ * useLayoutEffect (which updates the context store). The follow-up runAgent
128
+ * call then reads fresh context.
129
+ */
130
+ async waitForPendingFrameworkUpdates() {
131
+ await new Promise((resolve) => setTimeout(resolve, 0));
132
+ }
133
+ };
134
+
135
+ //#endregion
136
+ //#region src/v2/context.ts
137
+ const CopilotKitContext = (0, react.createContext)(null);
138
+ const useCopilotKit = () => {
139
+ const context = (0, react.useContext)(CopilotKitContext);
140
+ const [, forceUpdate] = (0, react.useReducer)((x) => x + 1, 0);
141
+ if (!context) throw new Error("useCopilotKit must be used within CopilotKitProvider");
142
+ (0, react.useEffect)(() => {
143
+ const subscription = context.copilotkit.subscribe({
144
+ onRuntimeConnectionStatusChanged: () => {
145
+ forceUpdate();
146
+ },
147
+ onHeadersChanged: () => {
148
+ forceUpdate();
149
+ }
150
+ });
151
+ return () => {
152
+ subscription.unsubscribe();
153
+ };
154
+ }, []);
155
+ return context;
156
+ };
157
+ const LicenseContext = (0, react.createContext)({
158
+ status: null,
159
+ license: null,
160
+ checkFeature: () => true,
161
+ getLimit: () => null
162
+ });
163
+ const useLicenseContext = () => (0, react.useContext)(LicenseContext);
164
+ const CopilotKitAgentIdContext = (0, react.createContext)(void 0);
165
+ const useDefaultAgentId = () => (0, react.useContext)(CopilotKitAgentIdContext);
166
+
167
+ //#endregion
40
168
  //#region src/v2/lib/shallow-stable-ref.ts
41
169
  /**
42
170
  * Shallow equality comparison for objects.
@@ -91,7 +219,12 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
91
219
  assistantMessageToolbarCopyCodeCopiedLabel: "Copied",
92
220
  assistantMessageToolbarCopyMessageLabel: "Copy",
93
221
  assistantMessageToolbarInspectorLabel: "View in Inspector",
94
- assistantMessageToolbarInspectorLocalOnlyLabel: "Development Only",
222
+ assistantMessageToolbarInspectorDescription: "Open this message in the Inspector",
223
+ assistantMessageToolbarInspectorLocalOnlyLabel: "Local only",
224
+ assistantMessageToolbarInspectorLocalOnlyDescription: "Only visible on localhost or loopback hosts in development. Never shown in production.",
225
+ assistantMessageToolbarInspectorTitle: "CopilotKit Inspector",
226
+ assistantMessageToolbarInspectorHideLabel: "Hide this icon",
227
+ assistantMessageToolbarInspectorHideDescription: "Until you reload this page",
95
228
  assistantMessageToolbarThumbsUpLabel: "Good response",
96
229
  assistantMessageToolbarThumbsDownLabel: "Bad response",
97
230
  assistantMessageToolbarReadAloudLabel: "Read aloud",
@@ -132,7 +265,8 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
132
265
  ...parentConfig?.labels,
133
266
  ...stableLabels
134
267
  }), [stableLabels, parentConfig?.labels]);
135
- const resolvedAgentId = agentId ?? parentConfig?.agentId ?? _copilotkit_shared.DEFAULT_AGENT_ID;
268
+ const providerAgentId = useDefaultAgentId();
269
+ const resolvedAgentId = agentId ?? parentConfig?.agentId ?? providerAgentId ?? _copilotkit_shared.DEFAULT_AGENT_ID;
136
270
  const threadIdPropIsAuthoritative = threadId !== void 0 && hasExplicitThreadId !== false;
137
271
  const isThreadIdControlled = threadIdPropIsAuthoritative;
138
272
  const [activeThreadOverride, setActiveThreadOverride] = (0, react.useState)(null);
@@ -342,9 +476,9 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
342
476
 
343
477
  //#endregion
344
478
  //#region src/v2/lib/utils.ts
345
- const twMerge$9 = (0, tailwind_merge.extendTailwindMerge)({ prefix: "cpk" });
479
+ const twMerge$10 = (0, tailwind_merge.extendTailwindMerge)({ prefix: "cpk" });
346
480
  function cn(...inputs) {
347
- return twMerge$9((0, clsx.clsx)(inputs));
481
+ return twMerge$10((0, clsx.clsx)(inputs));
348
482
  }
349
483
 
350
484
  //#endregion
@@ -489,6 +623,14 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
489
623
  ...props
490
624
  });
491
625
  }
626
+ function DropdownMenuLabel({ className, inset, ...props }) {
627
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_dropdown_menu.Label, {
628
+ "data-slot": "dropdown-menu-label",
629
+ "data-inset": inset,
630
+ className: cn("cpk:px-2 cpk:py-1.5 cpk:text-sm cpk:font-medium cpk:data-[inset]:pl-8", className),
631
+ ...props
632
+ });
633
+ }
492
634
  function DropdownMenuSeparator({ className, ...props }) {
493
635
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_dropdown_menu.Separator, {
494
636
  "data-slot": "dropdown-menu-separator",
@@ -1494,132 +1636,6 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
1494
1636
  }, []);
1495
1637
  }
1496
1638
 
1497
- //#endregion
1498
- //#region src/v2/lib/react-core.ts
1499
- var CopilotKitCoreReact = class extends _copilotkit_core.CopilotKitCore {
1500
- constructor(config) {
1501
- super(config);
1502
- this._renderToolCalls = [];
1503
- this._hookRenderToolCalls = /* @__PURE__ */ new Map();
1504
- this._cachedMergedRenderToolCalls = null;
1505
- this._renderCustomMessages = [];
1506
- this._renderActivityMessages = [];
1507
- this._interruptElement = null;
1508
- this._renderToolCalls = config.renderToolCalls ?? [];
1509
- this._renderCustomMessages = config.renderCustomMessages ?? [];
1510
- this._renderActivityMessages = config.renderActivityMessages ?? [];
1511
- }
1512
- get renderCustomMessages() {
1513
- return this._renderCustomMessages;
1514
- }
1515
- get renderActivityMessages() {
1516
- return this._renderActivityMessages;
1517
- }
1518
- get renderToolCalls() {
1519
- if (this._hookRenderToolCalls.size === 0) return this._renderToolCalls;
1520
- if (this._cachedMergedRenderToolCalls) return this._cachedMergedRenderToolCalls;
1521
- const merged = /* @__PURE__ */ new Map();
1522
- for (const rc of this._renderToolCalls) merged.set(`${rc.agentId ?? ""}:${rc.name}`, rc);
1523
- for (const [key, rc] of this._hookRenderToolCalls) merged.set(key, rc);
1524
- this._cachedMergedRenderToolCalls = Array.from(merged.values());
1525
- return this._cachedMergedRenderToolCalls;
1526
- }
1527
- setRenderActivityMessages(renderers) {
1528
- this._renderActivityMessages = renderers;
1529
- }
1530
- setRenderCustomMessages(renderers) {
1531
- this._renderCustomMessages = renderers;
1532
- }
1533
- setRenderToolCalls(renderToolCalls) {
1534
- this._renderToolCalls = renderToolCalls;
1535
- this._cachedMergedRenderToolCalls = null;
1536
- this._notifyRenderToolCallsChanged();
1537
- }
1538
- addHookRenderToolCall(entry) {
1539
- const key = `${entry.agentId ?? ""}:${entry.name}`;
1540
- this._hookRenderToolCalls.set(key, entry);
1541
- this._cachedMergedRenderToolCalls = null;
1542
- this._notifyRenderToolCallsChanged();
1543
- }
1544
- removeHookRenderToolCall(name, agentId) {
1545
- const key = `${agentId ?? ""}:${name}`;
1546
- if (this._hookRenderToolCalls.delete(key)) {
1547
- this._cachedMergedRenderToolCalls = null;
1548
- this._notifyRenderToolCallsChanged();
1549
- }
1550
- }
1551
- _notifyRenderToolCallsChanged() {
1552
- this.notifySubscribers((subscriber) => {
1553
- const reactSubscriber = subscriber;
1554
- if (reactSubscriber.onRenderToolCallsChanged) reactSubscriber.onRenderToolCallsChanged({
1555
- copilotkit: this,
1556
- renderToolCalls: this.renderToolCalls
1557
- });
1558
- }, "Subscriber onRenderToolCallsChanged error:");
1559
- }
1560
- get interruptElement() {
1561
- return this._interruptElement;
1562
- }
1563
- setInterruptElement(element) {
1564
- this._interruptElement = element;
1565
- this.notifySubscribers((subscriber) => {
1566
- subscriber.onInterruptElementChanged?.({
1567
- copilotkit: this,
1568
- interruptElement: this._interruptElement
1569
- });
1570
- }, "Subscriber onInterruptElementChanged error:");
1571
- }
1572
- subscribe(subscriber) {
1573
- return super.subscribe(subscriber);
1574
- }
1575
- /**
1576
- * Wait for pending React state updates before the follow-up agent run.
1577
- *
1578
- * When a frontend tool handler calls setState(), React 18 batches the update
1579
- * and schedules a commit via its internal scheduler (MessageChannel). The
1580
- * useAgentContext hook registers context via useLayoutEffect, which runs
1581
- * synchronously after React commits that batch.
1582
- *
1583
- * Awaiting a zero-delay timeout yields to the macrotask queue. React's
1584
- * MessageChannel task runs first, committing the pending state and running
1585
- * useLayoutEffect (which updates the context store). The follow-up runAgent
1586
- * call then reads fresh context.
1587
- */
1588
- async waitForPendingFrameworkUpdates() {
1589
- await new Promise((resolve) => setTimeout(resolve, 0));
1590
- }
1591
- };
1592
-
1593
- //#endregion
1594
- //#region src/v2/context.ts
1595
- const CopilotKitContext = (0, react.createContext)(null);
1596
- const useCopilotKit = () => {
1597
- const context = (0, react.useContext)(CopilotKitContext);
1598
- const [, forceUpdate] = (0, react.useReducer)((x) => x + 1, 0);
1599
- if (!context) throw new Error("useCopilotKit must be used within CopilotKitProvider");
1600
- (0, react.useEffect)(() => {
1601
- const subscription = context.copilotkit.subscribe({
1602
- onRuntimeConnectionStatusChanged: () => {
1603
- forceUpdate();
1604
- },
1605
- onHeadersChanged: () => {
1606
- forceUpdate();
1607
- }
1608
- });
1609
- return () => {
1610
- subscription.unsubscribe();
1611
- };
1612
- }, []);
1613
- return context;
1614
- };
1615
- const LicenseContext = (0, react.createContext)({
1616
- status: null,
1617
- license: null,
1618
- checkFeature: () => true,
1619
- getLimit: () => null
1620
- });
1621
- const useLicenseContext = () => (0, react.useContext)(LicenseContext);
1622
-
1623
1639
  //#endregion
1624
1640
  //#region src/v2/hooks/use-render-tool-call.tsx
1625
1641
  /**
@@ -1731,21 +1747,28 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
1731
1747
 
1732
1748
  //#endregion
1733
1749
  //#region src/v2/components/CopilotKitInspector.tsx
1734
- const CopilotKitInspector = ({ core, openRequest }) => {
1750
+ const CopilotKitInspector = ({ core, openRequest, onVisibilityChange }) => {
1735
1751
  const mountRef = react.useRef(null);
1736
1752
  const inspectorRef = react.useRef(null);
1737
1753
  const latestCoreRef = react.useRef(core ?? null);
1738
1754
  const latestOpenRequestRef = react.useRef(openRequest);
1755
+ const visibilityCallbackRef = react.useRef(onVisibilityChange);
1756
+ visibilityCallbackRef.current = onVisibilityChange;
1739
1757
  latestCoreRef.current = core ?? null;
1740
1758
  latestOpenRequestRef.current = openRequest;
1741
1759
  react.useEffect(() => {
1742
1760
  let mounted = true;
1743
1761
  let inspector = null;
1762
+ const handleVisibilityChange = (event) => {
1763
+ const visible = event.detail?.visible;
1764
+ visibilityCallbackRef.current?.(visible === true);
1765
+ };
1744
1766
  import("@copilotkit/web-inspector").then((mod) => {
1745
1767
  if (!mounted || !mountRef.current) return;
1746
1768
  mod.defineWebInspector?.();
1747
1769
  inspector = mountRef.current.ownerDocument.createElement(mod.WEB_INSPECTOR_TAG);
1748
1770
  mod.configureWebInspectorElement(inspector, latestCoreRef.current);
1771
+ inspector.addEventListener("cpk-inspector-visibility-change", handleVisibilityChange);
1749
1772
  mountRef.current.appendChild(inspector);
1750
1773
  inspectorRef.current = inspector;
1751
1774
  const request = latestOpenRequestRef.current;
@@ -1755,7 +1778,9 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
1755
1778
  });
1756
1779
  return () => {
1757
1780
  mounted = false;
1781
+ inspector?.removeEventListener("cpk-inspector-visibility-change", handleVisibilityChange);
1758
1782
  inspector?.remove();
1783
+ visibilityCallbackRef.current?.(false);
1759
1784
  if (inspectorRef.current === inspector) inspectorRef.current = null;
1760
1785
  };
1761
1786
  }, []);
@@ -3688,14 +3713,19 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
3688
3713
  }, [value, warningMessage]);
3689
3714
  return value;
3690
3715
  }
3691
- const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY_HEADERS, credentials, publicApiKey, publicLicenseKey, licenseToken, properties = EMPTY_PROPERTIES, agents__unsafe_dev_only: agents = EMPTY_AGENTS, selfManagedAgents = EMPTY_AGENTS, renderToolCalls, renderActivityMessages, renderCustomMessages, frontendTools, humanInTheLoop, openGenerativeUI, enableInspector, useSingleEndpoint, onError, a2ui, defaultThrottleMs, debug }) => {
3716
+ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY_HEADERS, credentials, publicApiKey, publicLicenseKey, licenseToken, properties = EMPTY_PROPERTIES, agents__unsafe_dev_only: agents = EMPTY_AGENTS, selfManagedAgents = EMPTY_AGENTS, renderToolCalls, renderActivityMessages, renderCustomMessages, frontendTools, humanInTheLoop, openGenerativeUI, enableInspector, agentId, useSingleEndpoint, onError, a2ui, defaultThrottleMs, debug }) => {
3692
3717
  const [shouldRenderInspector, setShouldRenderInspector] = (0, react.useState)(false);
3718
+ const [inspectorVisible, setInspectorVisible] = (0, react.useState)(false);
3693
3719
  (0, react.useEffect)(() => {
3694
3720
  setShouldRenderInspector((0, _copilotkit_shared.shouldEnableInspector)({
3695
3721
  enableInspector,
3696
3722
  isBrowser: true,
3697
3723
  isDevelopment: process.env.NODE_ENV === "development"
3698
- }));
3724
+ }) && [
3725
+ "localhost",
3726
+ "127.0.0.1",
3727
+ "[::1]"
3728
+ ].includes(window.location.hostname));
3699
3729
  }, [enableInspector]);
3700
3730
  const [inspectorOpenRequest, setInspectorOpenRequest] = (0, react.useState)(null);
3701
3731
  const [runtimeA2UIEnabled, setRuntimeA2UIEnabled] = (0, react.useState)(false);
@@ -3711,9 +3741,15 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
3711
3741
  setInspectorOpenRequest({ ...request });
3712
3742
  }, []);
3713
3743
  const inspectorContextValue = (0, react.useMemo)(() => ({
3714
- isInspectorEnabled: shouldRenderInspector,
3744
+ providerEnableInspector: enableInspector,
3745
+ isInspectorEnabled: shouldRenderInspector && inspectorVisible,
3715
3746
  openInspector: requestInspectorOpen
3716
- }), [shouldRenderInspector, requestInspectorOpen]);
3747
+ }), [
3748
+ enableInspector,
3749
+ shouldRenderInspector,
3750
+ inspectorVisible,
3751
+ requestInspectorOpen
3752
+ ]);
3717
3753
  const renderToolCallsList = useStableArrayProp(renderToolCalls, "renderToolCalls must be a stable array. If you want to dynamically add or remove tools, use `useFrontendTool` instead.", (initial, next) => {
3718
3754
  const key = (rc) => `${rc?.agentId ?? ""}:${rc?.name ?? ""}`;
3719
3755
  const setFrom = (arr) => new Set(arr.map(key));
@@ -4110,9 +4146,13 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
4110
4146
  }),
4111
4147
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(CopilotKitInspectorContextProvider, {
4112
4148
  value: inspectorContextValue,
4113
- children: [children, shouldRenderInspector ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitInspector, {
4149
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitAgentIdContext.Provider, {
4150
+ value: agentId,
4151
+ children
4152
+ }), shouldRenderInspector ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitInspector, {
4114
4153
  core: copilotkit,
4115
- openRequest: inspectorOpenRequest
4154
+ openRequest: inspectorOpenRequest,
4155
+ onVisibilityChange: setInspectorVisible
4116
4156
  }) : null]
4117
4157
  }),
4118
4158
  runtimeLicenseWarningStatus === "none" && !resolvedPublicKey && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LicenseWarningBanner, { type: "no_license" }),
@@ -4694,7 +4734,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
4694
4734
  if (runtimeAgentId != null && threadId == null) throw new Error(`useAgent: \`runtimeAgentId\` requires \`threadId\`. A proxied agent exists to scope a thread to a private instance; without a threadId it behaves like the shared agent while adding a registration and a local agentId to keep unique. Either pass the thread, e.g. useAgent({ agentId: "${agentId ?? "chat-1"}", runtimeAgentId: "${runtimeAgentId}", threadId }), or bind to the agent directly with useAgent({ agentId: "${runtimeAgentId}" }).`);
4695
4735
  if (runtimeAgentId != null && agentId == null) throw new Error(`useAgent: \`runtimeAgentId\` requires an explicit \`agentId\`. The proxied agent is registered under \`agentId\`, and the usual fallbacks (chat configuration, then "${_copilotkit_shared.DEFAULT_AGENT_ID}") name agents that already exist — registering over one throws or shadows it. Pick a local id for this hook, e.g. useAgent({ agentId: "chat-1", runtimeAgentId: "${runtimeAgentId}", threadId }).`);
4696
4736
  const chatConfig = useCopilotChatConfiguration();
4697
- const resolvedAgentId = agentId ?? chatConfig?.agentId ?? _copilotkit_shared.DEFAULT_AGENT_ID;
4737
+ const providerAgentId = useDefaultAgentId();
4738
+ const resolvedAgentId = agentId ?? chatConfig?.agentId ?? providerAgentId ?? _copilotkit_shared.DEFAULT_AGENT_ID;
4698
4739
  const { copilotkit } = useCopilotKit();
4699
4740
  const providerThrottleMs = copilotkit.defaultThrottleMs;
4700
4741
  const [, forceUpdate] = (0, react.useReducer)((x) => x + 1, 0);
@@ -4922,7 +4963,12 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
4922
4963
  function useSuggestions({ agentId } = {}) {
4923
4964
  const { copilotkit } = useCopilotKit();
4924
4965
  const config = useCopilotChatConfiguration();
4925
- const resolvedAgentId = (0, react.useMemo)(() => agentId ?? config?.agentId ?? _copilotkit_shared.DEFAULT_AGENT_ID, [agentId, config?.agentId]);
4966
+ const providerAgentId = useDefaultAgentId();
4967
+ const resolvedAgentId = (0, react.useMemo)(() => agentId ?? config?.agentId ?? providerAgentId ?? _copilotkit_shared.DEFAULT_AGENT_ID, [
4968
+ agentId,
4969
+ config?.agentId,
4970
+ providerAgentId
4971
+ ]);
4926
4972
  const [suggestions, setSuggestions] = (0, react.useState)(() => {
4927
4973
  return copilotkit.getSuggestions(resolvedAgentId).suggestions;
4928
4974
  });
@@ -5176,7 +5222,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
5176
5222
  */
5177
5223
  function useInterrupt(config) {
5178
5224
  const { copilotkit } = useCopilotKit();
5179
- const { agent } = useAgent({ agentId: config.agentId });
5225
+ const { agent } = useAgent({
5226
+ agentId: config.agentId,
5227
+ updates: []
5228
+ });
5180
5229
  const [pending, setPending] = (0, react.useState)(null);
5181
5230
  const pendingRef = (0, react.useRef)(pending);
5182
5231
  pendingRef.current = pending;
@@ -6226,6 +6275,289 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
6226
6275
  }) });
6227
6276
  }
6228
6277
 
6278
+ //#endregion
6279
+ //#region src/v2/components/chat/CopilotChatInspectorButton.tsx
6280
+ let shortcutsHidden = false;
6281
+ const listeners = /* @__PURE__ */ new Set();
6282
+ const subscribe = (listener) => {
6283
+ listeners.add(listener);
6284
+ return () => {
6285
+ listeners.delete(listener);
6286
+ };
6287
+ };
6288
+ const getSnapshot = () => shortcutsHidden;
6289
+ const getServerSnapshot = () => false;
6290
+ function useInspectorShortcutsHidden() {
6291
+ return (0, react.useSyncExternalStore)(subscribe, getSnapshot, getServerSnapshot);
6292
+ }
6293
+ function hideShortcuts() {
6294
+ shortcutsHidden = true;
6295
+ listeners.forEach((listener) => listener());
6296
+ }
6297
+ function InspectorKiteIcon({ className, ...props }) {
6298
+ const id = (0, react.useId)();
6299
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
6300
+ ...props,
6301
+ "aria-hidden": "true",
6302
+ className: (0, tailwind_merge.twMerge)("cpk:size-4", className),
6303
+ viewBox: "4.57 3.36 17.8 17.8",
6304
+ fill: "none",
6305
+ children: [
6306
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
6307
+ d: "M6.36084 10.9855C8.34277 8.393 9.98843 5.82939 10.6204 3.75914C10.6382 3.70281 10.7043 3.67888 10.7534 3.7114C12.9536 5.16894 16.9635 6.12833 20.5086 6.15085C20.5703 6.15124 20.6124 6.2114 20.5895 6.26829C19.4109 9.25938 17.9705 14.6189 17.9148 20.7392C17.9148 20.8301 17.7873 20.8627 17.7419 20.7837C15.7236 17.2522 9.26021 12.2898 6.39414 11.1186C6.34112 11.0968 6.32556 11.0313 6.36084 10.9855Z",
6308
+ fill: `url(#${id}-paint0_linear)`
6309
+ }),
6310
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
6311
+ d: "M13.0475 9.39974C9.95016 10.3806 7.11935 10.9259 6.44331 11.0498C6.40027 11.0577 6.39115 11.1172 6.43152 11.134C9.3203 12.3347 15.7516 17.2826 17.7511 20.7998C17.7551 20.8075 17.7647 20.8103 17.7728 20.8068C17.7809 20.803 17.7853 20.793 17.7819 20.7844L13.0475 9.39974Z",
6312
+ fill: `url(#${id}-paint1_linear)`
6313
+ }),
6314
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
6315
+ d: "M10.762 3.705C13.4137 5.15161 16.4787 5.80132 20.545 6.14367C20.5703 6.14585 20.5787 6.18008 20.5557 6.19197C20.0359 6.45923 17.0574 7.97512 14.8455 8.78701C14.2524 9.00453 13.6564 9.20632 13.0692 9.39249C13.0562 9.39656 13.0419 9.39015 13.0369 9.37774L10.7005 3.75979C10.6849 3.72196 10.7257 3.68538 10.762 3.705Z",
6316
+ fill: `url(#${id}-paint2_linear)`
6317
+ }),
6318
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
6319
+ d: "M10.7145 3.79041L17.8305 20.7659",
6320
+ stroke: "#513C9F",
6321
+ strokeWidth: "0.17284",
6322
+ strokeLinecap: "round"
6323
+ }),
6324
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
6325
+ d: "M6.44531 11.0476C6.44531 11.0476 10.375 10.3422 14.0686 9.06804C17.7623 7.7939 20.5122 6.23373 20.5122 6.23373",
6326
+ stroke: "#513C9F",
6327
+ strokeWidth: "0.17284",
6328
+ strokeLinecap: "round"
6329
+ }),
6330
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
6331
+ d: "M11.6914 5.93518L9.05534 14.7068M9.05534 14.7068H15.3203M9.05534 14.7068L0.15625 26.3646",
6332
+ stroke: "#ABABAB",
6333
+ strokeWidth: "0.302474",
6334
+ strokeLinecap: "round"
6335
+ }),
6336
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
6337
+ d: "M6.02539 23.9646L4.85806 24.1287C5.46272 25.7287 6.70381 26.4276 8.18528 26.4276C11.8147 26.4276 10.707 22.3227 12.8103 22.3227C14.3358 22.3227 13.7155 25.6498 16.9992 25.6498C19.0029 25.6498 19.2028 23.631 18.8607 22.7625C18.8589 22.7572 18.8568 22.7524 18.8538 22.7476L18.3166 21.9253C18.2817 21.8706 18.1968 21.8912 18.1907 21.9562L18.0908 22.9529C18.0838 23.0222 18.0857 23.0913 18.0936 23.1605C18.1764 23.8491 18.2291 25.5202 16.9992 25.5202C15.7015 25.5202 15.3895 22.2362 12.8103 22.2362C9.78393 22.2362 10.1726 26.298 8.31487 26.298C7.08938 26.298 6.15447 24.9153 6.02539 23.9646Z",
6338
+ fill: `url(#${id}-paint3_linear)`
6339
+ }),
6340
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("defs", { children: [
6341
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("linearGradient", {
6342
+ id: `${id}-paint0_linear`,
6343
+ x1: "15.5372",
6344
+ y1: "5.0278",
6345
+ x2: "12.0802",
6346
+ y2: "14.534",
6347
+ gradientUnits: "userSpaceOnUse",
6348
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", { stopColor: "#6430AB" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", {
6349
+ offset: "1",
6350
+ stopColor: "#AA89D8"
6351
+ })]
6352
+ }),
6353
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("linearGradient", {
6354
+ id: `${id}-paint1_linear`,
6355
+ x1: "12.8583",
6356
+ y1: "10.3858",
6357
+ x2: "8.40764",
6358
+ y2: "18.9846",
6359
+ gradientUnits: "userSpaceOnUse",
6360
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", { stopColor: "#005DBB" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", {
6361
+ offset: "1",
6362
+ stopColor: "#3D92E8"
6363
+ })]
6364
+ }),
6365
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("linearGradient", {
6366
+ id: `${id}-paint2_linear`,
6367
+ x1: "14.8452",
6368
+ y1: "5.02774",
6369
+ x2: "13.5047",
6370
+ y2: "9.21911",
6371
+ gradientUnits: "userSpaceOnUse",
6372
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", { stopColor: "#1B70C4" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", {
6373
+ offset: "1",
6374
+ stopColor: "#54A4F2"
6375
+ })]
6376
+ }),
6377
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("linearGradient", {
6378
+ id: `${id}-paint3_linear`,
6379
+ x1: "4.85806",
6380
+ y1: "24.2455",
6381
+ x2: "18.9963",
6382
+ y2: "24.2455",
6383
+ gradientUnits: "userSpaceOnUse",
6384
+ children: [
6385
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", { stopColor: "#4497EA" }),
6386
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", {
6387
+ offset: "0.254755",
6388
+ stopColor: "#1463B2"
6389
+ }),
6390
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", {
6391
+ offset: "0.498725",
6392
+ stopColor: "#0A437D"
6393
+ }),
6394
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", {
6395
+ offset: "0.666667",
6396
+ stopColor: "#2476C8"
6397
+ }),
6398
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", {
6399
+ offset: "0.972542",
6400
+ stopColor: "#0C549A"
6401
+ })
6402
+ ]
6403
+ })
6404
+ ] })
6405
+ ]
6406
+ });
6407
+ }
6408
+ function CopilotChatInspectorButton({ title, className, onClick, onPointerDown, onPointerEnter, onPointerLeave, onKeyDown, disabled, ...props }) {
6409
+ const labels = useCopilotChatConfiguration()?.labels ?? CopilotChatDefaultLabels;
6410
+ const { isInspectorEnabled } = useCopilotKitInspector();
6411
+ const hidden = useInspectorShortcutsHidden();
6412
+ const [open, setOpen] = (0, react.useState)(false);
6413
+ const [dark, setDark] = (0, react.useState)(false);
6414
+ const trigger = (0, react.useRef)(null);
6415
+ const closeTimer = (0, react.useRef)(null);
6416
+ const openedByHover = (0, react.useRef)(false);
6417
+ const primaryLabel = title || labels.assistantMessageToolbarInspectorLabel;
6418
+ const cancelClose = () => {
6419
+ if (closeTimer.current !== null) clearTimeout(closeTimer.current);
6420
+ closeTimer.current = null;
6421
+ };
6422
+ (0, react.useEffect)(() => cancelClose, []);
6423
+ const changeOpen = (next) => {
6424
+ cancelClose();
6425
+ if (next) setDark(!!trigger.current?.closest(".dark"));
6426
+ setOpen(next);
6427
+ };
6428
+ const scheduleClose = () => {
6429
+ cancelClose();
6430
+ closeTimer.current = setTimeout(() => {
6431
+ if (openedByHover.current) setOpen(false);
6432
+ }, 180);
6433
+ };
6434
+ if (!isInspectorEnabled || hidden) return null;
6435
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(DropdownMenu, {
6436
+ open,
6437
+ onOpenChange: changeOpen,
6438
+ modal: false,
6439
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(DropdownMenuTrigger, {
6440
+ asChild: true,
6441
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
6442
+ ...props,
6443
+ ref: trigger,
6444
+ type: "button",
6445
+ disabled,
6446
+ variant: "assistantMessageToolbarButton",
6447
+ size: "icon",
6448
+ "data-testid": "copilot-inspector-button",
6449
+ "aria-label": `${labels.assistantMessageToolbarInspectorTitle} (${labels.assistantMessageToolbarInspectorLocalOnlyLabel.toLowerCase()})`,
6450
+ className: (0, tailwind_merge.twMerge)("cpk:size-8 cpk:p-1.5", className),
6451
+ onPointerEnter: (event) => {
6452
+ onPointerEnter?.(event);
6453
+ if (!disabled && event.pointerType !== "touch") {
6454
+ openedByHover.current = true;
6455
+ changeOpen(true);
6456
+ }
6457
+ },
6458
+ onPointerLeave: (event) => {
6459
+ onPointerLeave?.(event);
6460
+ scheduleClose();
6461
+ },
6462
+ onPointerDown: (event) => {
6463
+ onPointerDown?.(event);
6464
+ event.preventDefault();
6465
+ },
6466
+ onClick: (event) => {
6467
+ changeOpen(false);
6468
+ onClick?.(event);
6469
+ },
6470
+ onKeyDown: (event) => {
6471
+ openedByHover.current = false;
6472
+ onKeyDown?.(event);
6473
+ if (!event.defaultPrevented && (event.key === "Enter" || event.key === " ")) {
6474
+ event.preventDefault();
6475
+ event.currentTarget.click();
6476
+ }
6477
+ },
6478
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Wrench, {
6479
+ "aria-hidden": "true",
6480
+ className: "cpk:size-4",
6481
+ "data-testid": "copilot-inspector-icon"
6482
+ })
6483
+ })
6484
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(DropdownMenuContent, {
6485
+ align: "start",
6486
+ side: "top",
6487
+ sideOffset: 6,
6488
+ className: (0, tailwind_merge.twMerge)("cpk:w-64 cpk:p-1 cpk:text-sm", dark && "dark"),
6489
+ onPointerEnter: cancelClose,
6490
+ onPointerLeave: scheduleClose,
6491
+ onKeyDown: () => {
6492
+ openedByHover.current = false;
6493
+ },
6494
+ onOpenAutoFocus: (event) => {
6495
+ if (openedByHover.current) event.preventDefault();
6496
+ },
6497
+ onCloseAutoFocus: (event) => {
6498
+ if (openedByHover.current) event.preventDefault();
6499
+ },
6500
+ onFocusOutside: () => changeOpen(false),
6501
+ children: [
6502
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(DropdownMenuLabel, {
6503
+ className: "cpk:flex cpk:items-center cpk:justify-between cpk:gap-3 cpk:px-2 cpk:py-2",
6504
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
6505
+ className: "cpk:text-xs cpk:font-medium",
6506
+ children: labels.assistantMessageToolbarInspectorTitle
6507
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(Tooltip, {
6508
+ delayDuration: 1e3,
6509
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(TooltipTrigger, {
6510
+ asChild: true,
6511
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
6512
+ tabIndex: 0,
6513
+ className: "cpk:cursor-help cpk:rounded cpk:bg-muted cpk:px-1.5 cpk:py-0.5 cpk:text-[10px] cpk:font-normal cpk:text-muted-foreground",
6514
+ children: labels.assistantMessageToolbarInspectorLocalOnlyLabel
6515
+ })
6516
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TooltipContent, {
6517
+ side: "top",
6518
+ sideOffset: 6,
6519
+ className: (0, tailwind_merge.twMerge)("cpk:max-w-48 cpk:text-wrap", dark && "dark"),
6520
+ onPointerEnter: cancelClose,
6521
+ onPointerLeave: scheduleClose,
6522
+ children: labels.assistantMessageToolbarInspectorLocalOnlyDescription
6523
+ })]
6524
+ })]
6525
+ }),
6526
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DropdownMenuSeparator, {}),
6527
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DropdownMenuItem, {
6528
+ asChild: true,
6529
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
6530
+ type: "button",
6531
+ onClick,
6532
+ className: "cpk:w-full cpk:cursor-pointer cpk:items-start cpk:text-left",
6533
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(InspectorKiteIcon, { className: "cpk:mt-0.5" }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
6534
+ className: "cpk:block",
6535
+ children: primaryLabel
6536
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
6537
+ className: "cpk:block cpk:text-xs cpk:text-muted-foreground",
6538
+ children: labels.assistantMessageToolbarInspectorDescription
6539
+ })] })]
6540
+ })
6541
+ }),
6542
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(DropdownMenuItem, {
6543
+ onSelect: hideShortcuts,
6544
+ className: "cpk:cursor-pointer cpk:items-start",
6545
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.EyeOff, {
6546
+ "aria-hidden": "true",
6547
+ className: "cpk:mt-0.5"
6548
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
6549
+ className: "cpk:block",
6550
+ children: labels.assistantMessageToolbarInspectorHideLabel
6551
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
6552
+ className: "cpk:block cpk:text-xs cpk:text-muted-foreground",
6553
+ children: labels.assistantMessageToolbarInspectorHideDescription
6554
+ })] })]
6555
+ })
6556
+ ]
6557
+ })]
6558
+ });
6559
+ }
6560
+
6229
6561
  //#endregion
6230
6562
  //#region src/v2/components/chat/CopilotChatAssistantMessage.tsx
6231
6563
  /**
@@ -6246,30 +6578,32 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
6246
6578
  function CopilotChatAssistantMessage({ message, messages, isRunning, onThumbsUp, onThumbsDown, onReadAloud, onRegenerate, additionalToolbarItems, toolbarVisible = true, markdownRenderer, toolbar, copyButton, inspectorButton, thumbsUpButton, thumbsDownButton, readAloudButton, regenerateButton, toolCallsView, children, className, ...props }) {
6247
6579
  useKatexStyles();
6248
6580
  const { isInspectorEnabled, openInspector } = useCopilotKitInspector();
6581
+ const shortcutsHidden = useInspectorShortcutsHidden();
6582
+ const showInspectorShortcut = isInspectorEnabled && !shortcutsHidden;
6249
6583
  const boundMarkdownRenderer = renderSlot(markdownRenderer, CopilotChatAssistantMessage.MarkdownRenderer, { content: message.content || "" });
6250
6584
  const boundCopyButton = renderSlot(copyButton, CopilotChatAssistantMessage.CopyButton, { onClick: async () => {
6251
6585
  if (message.content) return await (0, _copilotkit_shared.copyToClipboard)(message.content);
6252
6586
  return false;
6253
6587
  } });
6254
6588
  const boundThumbsUpButton = renderSlot(thumbsUpButton, CopilotChatAssistantMessage.ThumbsUpButton, { onClick: onThumbsUp ? () => onThumbsUp(message) : void 0 });
6255
- const boundInspectorButton = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(BoundInspectorButton, {
6589
+ const boundInspectorButton = showInspectorShortcut ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(BoundInspectorButton, {
6256
6590
  inspectorButton,
6257
6591
  messageId: message.id,
6258
6592
  openInspector
6259
- });
6593
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, {});
6260
6594
  const boundThumbsDownButton = renderSlot(thumbsDownButton, CopilotChatAssistantMessage.ThumbsDownButton, { onClick: onThumbsDown ? () => onThumbsDown(message) : void 0 });
6261
6595
  const boundReadAloudButton = renderSlot(readAloudButton, CopilotChatAssistantMessage.ReadAloudButton, { onClick: onReadAloud ? () => onReadAloud(message) : void 0 });
6262
6596
  const boundRegenerateButton = renderSlot(regenerateButton, CopilotChatAssistantMessage.RegenerateButton, { onClick: onRegenerate ? () => onRegenerate(message) : void 0 });
6263
6597
  const boundToolbar = renderSlot(toolbar, CopilotChatAssistantMessage.Toolbar, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
6264
- className: "cpk:flex cpk:items-center cpk:gap-1",
6598
+ className: "cpk:flex cpk:w-full cpk:items-center cpk:gap-1",
6265
6599
  children: [
6266
6600
  boundCopyButton,
6267
- isInspectorEnabled && boundInspectorButton,
6268
6601
  (onThumbsUp || thumbsUpButton) && boundThumbsUpButton,
6269
6602
  (onThumbsDown || thumbsDownButton) && boundThumbsDownButton,
6270
6603
  (onReadAloud || readAloudButton) && boundReadAloudButton,
6271
6604
  (onRegenerate || regenerateButton) && boundRegenerateButton,
6272
- additionalToolbarItems
6605
+ additionalToolbarItems,
6606
+ showInspectorShortcut && boundInspectorButton
6273
6607
  ]
6274
6608
  }) });
6275
6609
  const boundToolCallsView = renderSlot(toolCallsView, CopilotChatToolCallsView, {
@@ -6278,7 +6612,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
6278
6612
  });
6279
6613
  const hasContent = !!(message.content && message.content.trim().length > 0);
6280
6614
  const isLatestAssistantMessage = message.role === "assistant" && messages?.[messages.length - 1]?.id === message.id;
6281
- const shouldShowToolbar = toolbarVisible && (hasContent || isInspectorEnabled) && !(isRunning && isLatestAssistantMessage);
6615
+ const shouldShowToolbar = toolbarVisible && (hasContent || showInspectorShortcut) && !(isRunning && isLatestAssistantMessage);
6282
6616
  if (children) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
6283
6617
  "data-copilotkit": true,
6284
6618
  style: { display: "contents" },
@@ -6319,110 +6653,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
6319
6653
  ]
6320
6654
  });
6321
6655
  }
6322
- function CopilotKitColoredIcon() {
6323
- const gradientId = (0, react.useId)().replace(/:/g, "");
6324
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
6325
- "aria-hidden": "true",
6326
- className: "cpk:size-5",
6327
- "data-testid": "copilot-inspector-icon",
6328
- viewBox: "0 0 24 24",
6329
- children: [
6330
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
6331
- d: "M8.162 7.758c2.093-2.738 3.831-5.445 4.498-7.63a.093.093 0 01.14-.051c2.324 1.539 6.558 2.552 10.301 2.576a.09.09 0 01.085.124c-1.243 3.158-2.765 8.817-2.823 15.28-.001.095-.135.13-.183.046-2.131-3.729-8.955-8.968-11.982-10.205a.09.09 0 01-.036-.14z",
6332
- fill: `url(#${gradientId}-purple)`
6333
- }),
6334
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
6335
- d: "M15.223 6.083A61.492 61.492 0 018.25 7.827c-.045.008-.055.071-.012.089 3.05 1.267 9.84 6.492 11.952 10.206a.017.017 0 00.022.007.018.018 0 00.01-.024l-4.999-12.02z",
6336
- fill: `url(#${gradientId}-blue)`
6337
- }),
6338
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
6339
- d: "M12.81.07c2.8 1.528 6.037 2.214 10.33 2.575.028.002.036.039.012.051-.55.282-3.695 1.883-6.03 2.74-.626.23-1.256.443-1.876.64a.028.028 0 01-.033-.016L12.746.128c-.017-.04.027-.078.065-.058z",
6340
- fill: `url(#${gradientId}-light-blue)`
6341
- }),
6342
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
6343
- className: "cpk:fill-[#513C9F] cpk:dark:fill-[#B99AE8]",
6344
- d: "M12.725.075c.046-.019.1.003.119.05l7.514 17.923a.091.091 0 01-.148.1l-.02-.03L12.675.195a.091.091 0 01.049-.12z"
6345
- }),
6346
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
6347
- className: "cpk:fill-[#513C9F] cpk:dark:fill-[#B99AE8]",
6348
- d: "M23.06 2.66c.044-.025.1-.01.125.034.025.044.009.1-.035.124v.001l-.008.004-.025.015-.1.054a41.384 41.384 0 01-1.811.92A47.05 47.05 0 0116.33 5.82c-1.954.674-3.97 1.197-5.497 1.552a66.27 66.27 0 01-2.38.507l-.138.026-.036.007h-.01l-.002.002a.091.091 0 11-.033-.18l.016.09-.015-.09h.002l.01-.002.035-.007.137-.025a66.16 66.16 0 002.373-.506c1.524-.354 3.533-.876 5.479-1.547a46.857 46.857 0 006.276-2.709c.166-.087.295-.156.381-.204l.099-.054.024-.014.008-.004z"
6349
- }),
6350
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
6351
- className: "cpk:fill-[#ABABAB] cpk:dark:fill-[#D4D4D4]",
6352
- d: "M13.838 2.272a.16.16 0 01.107.2l-2.72 9.055h6.4l.061.013a.16.16 0 010 .295l-.061.013h-6.541L.679 24.099l-.05.04a.16.16 0 01-.194-.245l10.43-12.285 2.773-9.23a.16.16 0 01.2-.107z"
6353
- }),
6354
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
6355
- d: "M7.809 21.461l-1.232.173c.638 1.69 1.949 2.427 3.514 2.427 3.831 0 2.661-4.334 4.883-4.334 1.61 0 .956 3.513 4.423 3.513 2.116 0 2.326-2.131 1.966-3.048l-.008-.016-.567-.868c-.037-.058-.127-.036-.133.032l-.106 1.053a1.01 1.01 0 00.003.219c.088.727.144 2.491-1.155 2.491-1.37 0-1.7-3.467-4.423-3.467-3.196 0-2.785 4.289-4.747 4.289-1.294 0-2.28-1.46-2.418-2.464z",
6356
- fill: `url(#${gradientId}-tail)`
6357
- }),
6358
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("defs", { children: [
6359
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("linearGradient", {
6360
- gradientUnits: "userSpaceOnUse",
6361
- id: `${gradientId}-purple`,
6362
- x1: "17.852",
6363
- x2: "14.202",
6364
- y1: "1.467",
6365
- y2: "11.504",
6366
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", { className: "cpk:[stop-color:#6430AB] cpk:dark:[stop-color:#B792F0]" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", {
6367
- className: "cpk:[stop-color:#AA89D8] cpk:dark:[stop-color:#D3BDF7]",
6368
- offset: "1"
6369
- })]
6370
- }),
6371
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("linearGradient", {
6372
- gradientUnits: "userSpaceOnUse",
6373
- id: `${gradientId}-blue`,
6374
- x1: "15.024",
6375
- x2: "10.324",
6376
- y1: "7.125",
6377
- y2: "16.204",
6378
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", { className: "cpk:[stop-color:#005DBB] cpk:dark:[stop-color:#4D9FEF]" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", {
6379
- className: "cpk:[stop-color:#3D92E8] cpk:dark:[stop-color:#84C0FA]",
6380
- offset: "1"
6381
- })]
6382
- }),
6383
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("linearGradient", {
6384
- gradientUnits: "userSpaceOnUse",
6385
- id: `${gradientId}-light-blue`,
6386
- x1: "17.122",
6387
- x2: "15.707",
6388
- y1: "1.467",
6389
- y2: "5.892",
6390
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", { className: "cpk:[stop-color:#1B70C4] cpk:dark:[stop-color:#61ACF2]" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", {
6391
- className: "cpk:[stop-color:#54A4F2] cpk:dark:[stop-color:#9ACDFF]",
6392
- offset: "1"
6393
- })]
6394
- }),
6395
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("linearGradient", {
6396
- gradientUnits: "userSpaceOnUse",
6397
- id: `${gradientId}-tail`,
6398
- x1: "6.577",
6399
- x2: "21.506",
6400
- y1: "21.758",
6401
- y2: "21.758",
6402
- children: [
6403
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", { className: "cpk:[stop-color:#4497EA] cpk:dark:[stop-color:#79BCF5]" }),
6404
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", {
6405
- className: "cpk:[stop-color:#1463B2] cpk:dark:[stop-color:#4594D8]",
6406
- offset: ".255"
6407
- }),
6408
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", {
6409
- className: "cpk:[stop-color:#0A437D] cpk:dark:[stop-color:#347CB7]",
6410
- offset: ".499"
6411
- }),
6412
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", {
6413
- className: "cpk:[stop-color:#2476C8] cpk:dark:[stop-color:#58A4E5]",
6414
- offset: ".667"
6415
- }),
6416
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", {
6417
- className: "cpk:[stop-color:#0C549A] cpk:dark:[stop-color:#3C87C7]",
6418
- offset: ".973"
6419
- })
6420
- ]
6421
- })
6422
- ] })
6423
- ]
6424
- });
6425
- }
6426
6656
  (function(_CopilotChatAssistantMessage) {
6427
6657
  _CopilotChatAssistantMessage.MarkdownRenderer = ({ content, className, ...props }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(streamdown.Streamdown, {
6428
6658
  className,
@@ -6480,30 +6710,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
6480
6710
  children: copied ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Check, { className: "cpk:size-[18px]" }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Copy, { className: "cpk:size-[18px]" })
6481
6711
  });
6482
6712
  };
6483
- _CopilotChatAssistantMessage.InspectorButton = ({ title, className, ...props }) => {
6484
- const labels = useCopilotChatConfiguration()?.labels ?? CopilotChatDefaultLabels;
6485
- const primaryLabel = title || labels.assistantMessageToolbarInspectorLabel;
6486
- const accessibleLabel = `${primaryLabel} (local only)`;
6487
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(ToolbarButton, {
6488
- "data-testid": "copilot-inspector-button",
6489
- title: accessibleLabel,
6490
- className: (0, tailwind_merge.twMerge)("cpk:w-auto cpk:gap-1.5 cpk:px-2", className),
6491
- tooltipClassName: "cpk:max-w-64 cpk:text-left cpk:leading-4",
6492
- tooltip: "View this message in the Inspector to get more information. This button and the inspector only display during local development (localhost, dev env).",
6493
- ...props,
6494
- children: [
6495
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitColoredIcon, {}),
6496
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
6497
- className: "cpk:font-medium",
6498
- children: primaryLabel
6499
- }),
6500
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
6501
- className: "cpk:text-xs cpk:text-muted-foreground",
6502
- children: "(local only)"
6503
- })
6504
- ]
6505
- });
6506
- };
6713
+ _CopilotChatAssistantMessage.InspectorButton = CopilotChatInspectorButton;
6507
6714
  _CopilotChatAssistantMessage.ThumbsUpButton = ({ title, ...props }) => {
6508
6715
  const labels = useCopilotChatConfiguration()?.labels ?? CopilotChatDefaultLabels;
6509
6716
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolbarButton, {
@@ -8753,9 +8960,15 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
8753
8960
 
8754
8961
  //#endregion
8755
8962
  //#region src/v2/components/chat/CopilotChat.tsx
8756
- function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen, attachments: attachmentsConfig, onError, throttleMs, ...props }) {
8963
+ function CopilotChat({ agentId, threadId, labels, inspectorTools, chatView, isModalDefaultOpen, attachments: attachmentsConfig, onError, throttleMs, ...props }) {
8757
8964
  const existingConfig = useCopilotChatConfiguration();
8758
- const resolvedAgentId = agentId ?? existingConfig?.agentId ?? _copilotkit_shared.DEFAULT_AGENT_ID;
8965
+ const inspector = useCopilotKitInspector();
8966
+ const inspectorContextValue = (0, react.useMemo)(() => ({
8967
+ ...inspector,
8968
+ isInspectorEnabled: inspector.isInspectorEnabled && (inspector.providerEnableInspector ?? inspectorTools ?? true)
8969
+ }), [inspector, inspectorTools]);
8970
+ const providerAgentId = useDefaultAgentId();
8971
+ const resolvedAgentId = agentId ?? existingConfig?.agentId ?? providerAgentId ?? _copilotkit_shared.DEFAULT_AGENT_ID;
8759
8972
  const providedThreadId = threadId ?? existingConfig?.threadId;
8760
8973
  const baseThreadId = (0, react.useMemo)(() => providedThreadId ?? (0, _copilotkit_shared.randomUUID)(), [providedThreadId]);
8761
8974
  const baseHasExplicitThreadId = !!threadId || !!existingConfig?.hasExplicitThreadId;
@@ -9328,7 +9541,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
9328
9541
  }),
9329
9542
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LastUserMessageContext.Provider, {
9330
9543
  value: lastUserMessageState,
9331
- children: RenderedChatView
9544
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitInspectorContextProvider, {
9545
+ value: inspectorContextValue,
9546
+ children: RenderedChatView
9547
+ })
9332
9548
  })
9333
9549
  ]
9334
9550
  })
@@ -10036,7 +10252,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
10036
10252
  const featureLicensed = checkFeature("threads");
10037
10253
  const licensed = licensePresent && featureLicensed;
10038
10254
  const licensePending = status === null;
10039
- const resolvedAgentId = agentId ?? configuration?.agentId ?? _copilotkit_shared.DEFAULT_AGENT_ID;
10255
+ const providerAgentId = useDefaultAgentId();
10256
+ const resolvedAgentId = agentId ?? configuration?.agentId ?? providerAgentId ?? _copilotkit_shared.DEFAULT_AGENT_ID;
10040
10257
  const activeThreadId = configuration?.threadId ?? null;
10041
10258
  const { threads, isLoading, listError, fetchMoreError, hasMoreThreads, isFetchingMoreThreads, archiveThread, unarchiveThread, deleteThread, fetchMoreThreads, refetchThreads, startNewThread } = useThreads({
10042
10259
  agentId: resolvedAgentId,