@copilotkit/react-core 1.70.2 → 1.71.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 (49) hide show
  1. package/dist/{copilotkit-DcFo270Y.cjs → copilotkit-B4Jb1QEy.cjs} +582 -168
  2. package/dist/copilotkit-B4Jb1QEy.cjs.map +1 -0
  3. package/dist/{copilotkit--Jyzm6hS.d.mts → copilotkit-ChjzWqn6.d.mts} +34 -9
  4. package/dist/copilotkit-ChjzWqn6.d.mts.map +1 -0
  5. package/dist/{copilotkit-BLYaCGcz.d.cts → copilotkit-DCIXZawe.d.cts} +34 -9
  6. package/dist/copilotkit-DCIXZawe.d.cts.map +1 -0
  7. package/dist/{copilotkit-B1jSvZeb.mjs → copilotkit-snbJkMqQ.mjs} +583 -169
  8. package/dist/copilotkit-snbJkMqQ.mjs.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.cts.map +1 -1
  13. package/dist/index.d.mts +1 -1
  14. package/dist/index.d.mts.map +1 -1
  15. package/dist/index.mjs +4 -4
  16. package/dist/index.mjs.map +1 -1
  17. package/dist/index.umd.js +393 -153
  18. package/dist/index.umd.js.map +1 -1
  19. package/dist/v2/context.cjs +4 -0
  20. package/dist/v2/context.cjs.map +1 -1
  21. package/dist/v2/context.d.cts +3 -1
  22. package/dist/v2/context.d.cts.map +1 -1
  23. package/dist/v2/context.d.mts +3 -1
  24. package/dist/v2/context.d.mts.map +1 -1
  25. package/dist/v2/context.mjs +3 -1
  26. package/dist/v2/context.mjs.map +1 -1
  27. package/dist/v2/headless.cjs +57 -6
  28. package/dist/v2/headless.cjs.map +1 -1
  29. package/dist/v2/headless.d.cts +9 -4
  30. package/dist/v2/headless.d.cts.map +1 -1
  31. package/dist/v2/headless.d.mts +9 -4
  32. package/dist/v2/headless.d.mts.map +1 -1
  33. package/dist/v2/headless.mjs +58 -7
  34. package/dist/v2/headless.mjs.map +1 -1
  35. package/dist/v2/index.cjs +1 -1
  36. package/dist/v2/index.css +1 -1
  37. package/dist/v2/index.d.cts +1 -1
  38. package/dist/v2/index.d.mts +1 -1
  39. package/dist/v2/index.mjs +1 -1
  40. package/dist/v2/index.umd.js +708 -292
  41. package/dist/v2/index.umd.js.map +1 -1
  42. package/package.json +7 -7
  43. package/skills/react-core/SKILL.md +1 -1
  44. package/skills/react-core/references/agent-access.md +69 -26
  45. package/skills/react-core/references/chat-components.md +22 -5
  46. package/dist/copilotkit--Jyzm6hS.d.mts.map +0 -1
  47. package/dist/copilotkit-B1jSvZeb.mjs.map +0 -1
  48. package/dist/copilotkit-BLYaCGcz.d.cts.map +0 -1
  49. package/dist/copilotkit-DcFo270Y.cjs.map +0 -1
@@ -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
  /**
@@ -1660,6 +1676,29 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
1660
1676
  if (prevProps.RenderComponent !== nextProps.RenderComponent) return false;
1661
1677
  return true;
1662
1678
  });
1679
+ const IS_DEVELOPMENT$1 = process.env.NODE_ENV !== "production";
1680
+ /**
1681
+ * Reports tool calls that resolved to no renderer.
1682
+ *
1683
+ * A tool call with no renderer paints an empty message container and says
1684
+ * nothing else, so the only signal a developer gets today is a blank space in
1685
+ * the chat. This names the call and the renderers that *are* registered, which
1686
+ * is the whole diagnosis when the cause is a name that does not match.
1687
+ *
1688
+ * @param toolNames - The unmatched tool names collected during render.
1689
+ * @param registered - The registry as it stands now, re-read at report time.
1690
+ * @param alreadyWarned - Names already reported, mutated to keep this once per name.
1691
+ */
1692
+ function warnAboutUnrenderedToolCalls(toolNames, registered, alreadyWarned) {
1693
+ const registeredNames = Array.from(new Set(registered.map((rc) => rc.name)));
1694
+ const hasWildcard = registeredNames.includes("*");
1695
+ for (const toolName of toolNames) {
1696
+ if (hasWildcard || registeredNames.includes(toolName)) continue;
1697
+ if (alreadyWarned.has(toolName)) continue;
1698
+ alreadyWarned.add(toolName);
1699
+ console.warn(`[CopilotKit] The agent called the tool "${toolName}", and no renderer is registered for it, so that message rendered nothing. ` + (registeredNames.length === 0 ? "No tool-call renderers are registered. " : `Registered renderers: ${registeredNames.map((name) => `"${name}"`).join(", ")}. `) + `Register one with useRenderTool({ name: "${toolName}", ... }), or call useDefaultRenderTool() for a built-in card that covers every tool the agent calls. This warning is development-only.`);
1700
+ }
1701
+ }
1663
1702
  /**
1664
1703
  * Hook that returns a function to render tool calls based on the render functions
1665
1704
  * defined in CopilotKitProvider.
@@ -1669,13 +1708,18 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
1669
1708
  function useRenderToolCall() {
1670
1709
  const { copilotkit, executingToolCallIds } = useCopilotKit();
1671
1710
  const agentId = useCopilotChatConfiguration()?.agentId ?? _copilotkit_shared.DEFAULT_AGENT_ID;
1711
+ const unrenderedToolNames = (0, react.useRef)(/* @__PURE__ */ new Set());
1712
+ const warnedToolNames = (0, react.useRef)(/* @__PURE__ */ new Set());
1672
1713
  const renderToolCalls = (0, react.useSyncExternalStore)((callback) => {
1673
1714
  return copilotkit.subscribe({ onRenderToolCallsChanged: callback }).unsubscribe;
1674
1715
  }, () => copilotkit.renderToolCalls, () => copilotkit.renderToolCalls);
1675
- return (0, react.useCallback)(({ toolCall, toolMessage }) => {
1716
+ const renderToolCall = (0, react.useCallback)(({ toolCall, toolMessage }) => {
1676
1717
  const exactMatches = renderToolCalls.filter((rc) => rc.name === toolCall.function.name);
1677
1718
  const renderConfig = exactMatches.find((rc) => rc.agentId === agentId) || exactMatches.find((rc) => !rc.agentId) || exactMatches[0] || renderToolCalls.find((rc) => rc.name === "*");
1678
- if (!renderConfig) return null;
1719
+ if (!renderConfig) {
1720
+ if (IS_DEVELOPMENT$1) unrenderedToolNames.current.add(toolCall.function.name);
1721
+ return null;
1722
+ }
1679
1723
  const RenderComponent = renderConfig.render;
1680
1724
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolCallRenderer, {
1681
1725
  toolCall,
@@ -1688,25 +1732,43 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
1688
1732
  executingToolCallIds,
1689
1733
  agentId
1690
1734
  ]);
1735
+ (0, react.useEffect)(() => {
1736
+ if (!IS_DEVELOPMENT$1) return;
1737
+ if (unrenderedToolNames.current.size === 0) return;
1738
+ const timer = setTimeout(() => {
1739
+ const pending = Array.from(unrenderedToolNames.current);
1740
+ unrenderedToolNames.current.clear();
1741
+ warnAboutUnrenderedToolCalls(pending, copilotkit.renderToolCalls, warnedToolNames.current);
1742
+ }, 0);
1743
+ return () => clearTimeout(timer);
1744
+ });
1745
+ return renderToolCall;
1691
1746
  }
1692
1747
 
1693
1748
  //#endregion
1694
1749
  //#region src/v2/components/CopilotKitInspector.tsx
1695
- const CopilotKitInspector = ({ core, openRequest }) => {
1750
+ const CopilotKitInspector = ({ core, openRequest, onVisibilityChange }) => {
1696
1751
  const mountRef = react.useRef(null);
1697
1752
  const inspectorRef = react.useRef(null);
1698
1753
  const latestCoreRef = react.useRef(core ?? null);
1699
1754
  const latestOpenRequestRef = react.useRef(openRequest);
1755
+ const visibilityCallbackRef = react.useRef(onVisibilityChange);
1756
+ visibilityCallbackRef.current = onVisibilityChange;
1700
1757
  latestCoreRef.current = core ?? null;
1701
1758
  latestOpenRequestRef.current = openRequest;
1702
1759
  react.useEffect(() => {
1703
1760
  let mounted = true;
1704
1761
  let inspector = null;
1762
+ const handleVisibilityChange = (event) => {
1763
+ const visible = event.detail?.visible;
1764
+ visibilityCallbackRef.current?.(visible === true);
1765
+ };
1705
1766
  import("@copilotkit/web-inspector").then((mod) => {
1706
1767
  if (!mounted || !mountRef.current) return;
1707
1768
  mod.defineWebInspector?.();
1708
1769
  inspector = mountRef.current.ownerDocument.createElement(mod.WEB_INSPECTOR_TAG);
1709
1770
  mod.configureWebInspectorElement(inspector, latestCoreRef.current);
1771
+ inspector.addEventListener("cpk-inspector-visibility-change", handleVisibilityChange);
1710
1772
  mountRef.current.appendChild(inspector);
1711
1773
  inspectorRef.current = inspector;
1712
1774
  const request = latestOpenRequestRef.current;
@@ -1716,7 +1778,9 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
1716
1778
  });
1717
1779
  return () => {
1718
1780
  mounted = false;
1781
+ inspector?.removeEventListener("cpk-inspector-visibility-change", handleVisibilityChange);
1719
1782
  inspector?.remove();
1783
+ visibilityCallbackRef.current?.(false);
1720
1784
  if (inspectorRef.current === inspector) inspectorRef.current = null;
1721
1785
  };
1722
1786
  }, []);
@@ -3166,6 +3230,95 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
3166
3230
  a2ui_operations: zod.z.array(zod.z.any()).optional(),
3167
3231
  ...A2UILifecycleFields
3168
3232
  }).passthrough();
3233
+ const IS_DEVELOPMENT = process.env.NODE_ENV !== "production";
3234
+ /**
3235
+ * How long to wait for a surface to report its first paint before giving up on
3236
+ * the loader cross-over. Reaching it also means `onReady` never fired, which is
3237
+ * the signal the warning below reports.
3238
+ */
3239
+ const PAINT_FALLBACK_MS = 8e3;
3240
+ /**
3241
+ * Names the operation kinds a surface received, for a warning that has to say
3242
+ * what did arrive as well as what did not.
3243
+ *
3244
+ * @param operations - The operations grouped under one surface.
3245
+ * @returns A comma-separated list of operation keys, or "none".
3246
+ */
3247
+ function describeOperationKinds(operations) {
3248
+ const kinds = /* @__PURE__ */ new Set();
3249
+ for (const operation of operations) {
3250
+ if (!operation || typeof operation !== "object") continue;
3251
+ for (const key of Object.keys(operation)) if (key !== "version") kinds.add(key);
3252
+ }
3253
+ return kinds.size === 0 ? "none" : Array.from(kinds).join(", ");
3254
+ }
3255
+ /**
3256
+ * Reports surfaces that received operations and never painted.
3257
+ *
3258
+ * Reaching {@link PAINT_FALLBACK_MS} with no `onReady` means the operations were
3259
+ * accepted, were not malformed enough to raise the provider's error state, and
3260
+ * still put nothing on screen. Left alone that is invisible: the loader drops,
3261
+ * the turn finishes, and the only trace is an empty placeholder above the reply.
3262
+ *
3263
+ * `surfaceHasRenderableContent` already knows which half is missing, so the
3264
+ * warning says which rather than making the reader re-derive it.
3265
+ *
3266
+ * @param grouped - Operations grouped by surface id.
3267
+ */
3268
+ function warnAboutUnpaintedSurfaces(grouped) {
3269
+ for (const [surfaceId, operations] of grouped) {
3270
+ if (surfaceHasRenderableContent(operations)) continue;
3271
+ const cause = operations.filter((o) => o?.updateComponents).length === 0 ? "no updateComponents operation arrived, so the surface was never given anything to draw" : "its components address their values by \"path\" and no updateDataModel carried a non-empty value, so every bound component drew empty";
3272
+ console.warn(`[CopilotKit] A2UI surface "${surfaceId}" received operations and never painted after ${String(PAINT_FALLBACK_MS)}ms: ${cause}. Operations received: ${describeOperationKinds(operations)}. The payload was accepted, so check what the agent sent rather than the client wiring. This warning is development-only.`);
3273
+ }
3274
+ }
3275
+ /**
3276
+ * Names the component ids a surface was sent, for a warning about the one id
3277
+ * that is missing.
3278
+ *
3279
+ * @param operations - The operations grouped under one surface.
3280
+ * @returns A quoted, comma-separated list of ids, or "none".
3281
+ */
3282
+ function describeComponentIds(operations) {
3283
+ const ids = [];
3284
+ for (const operation of operations) {
3285
+ const components = operation?.updateComponents?.components;
3286
+ if (!Array.isArray(components)) continue;
3287
+ for (const component of components) {
3288
+ const id = component?.id;
3289
+ if (typeof id === "string" && !ids.includes(id)) ids.push(id);
3290
+ }
3291
+ }
3292
+ return ids.length === 0 ? "none" : ids.map((id) => `"${id}"`).join(", ");
3293
+ }
3294
+ /**
3295
+ * Reports a surface that is still waiting for its {@link ROOT_COMPONENT_ID}
3296
+ * component once its operations have stopped arriving.
3297
+ *
3298
+ * Both renderers begin walking a surface at that one id, and treat an id they
3299
+ * cannot find as not arrived yet — an animated placeholder. That is right while
3300
+ * operations stream. Once they have stopped it is not waiting, it is stuck, and
3301
+ * every other check calls it healthy: the surface exists, `processMessages` did
3302
+ * not throw, the component types were never reached, and
3303
+ * `surfaceHasRenderableContent` says yes on the strength of components plus a
3304
+ * data model, so `onReady` fires and the never-painted report is suppressed.
3305
+ * A complete, accepted payload therefore animates a grey box forever in silence.
3306
+ *
3307
+ * Reads the live components model rather than scanning the operations for the
3308
+ * id, so it covers every way the root can fail to resolve — not only a payload
3309
+ * that never named one.
3310
+ *
3311
+ * @param surfaceId - The surface the operations were addressed to.
3312
+ * @param operations - The operations processed for that surface.
3313
+ * @param surface - The live surface model, already known to exist.
3314
+ */
3315
+ function warnAboutUnresolvedRoot(surfaceId, operations, surface) {
3316
+ if (surface?.componentsModel?.get?.(_copilotkit_a2ui_renderer.ROOT_COMPONENT_ID)) return;
3317
+ const componentOps = operations.filter((o) => o?.updateComponents);
3318
+ if (componentOps.length === 0) return;
3319
+ const cause = componentOps.some((o) => o.updateComponents?.components?.some?.((c) => c?.id === _copilotkit_a2ui_renderer.ROOT_COMPONENT_ID)) ? `a component with id "${_copilotkit_a2ui_renderer.ROOT_COMPONENT_ID}" WAS sent, so the components did not reach the surface's model — check for an A2UI render error above, or a catalog that took none of them` : `the components it received are named ${describeComponentIds(operations)}, and none of them is "${_copilotkit_a2ui_renderer.ROOT_COMPONENT_ID}" — rename the entry-point component to "${_copilotkit_a2ui_renderer.ROOT_COMPONENT_ID}", and make every other component reachable from it through child/children`;
3320
+ console.warn(`[CopilotKit] A2UI surface "${surfaceId}" has no "${_copilotkit_a2ui_renderer.ROOT_COMPONENT_ID}" component ${String(PAINT_FALLBACK_MS)}ms after its last operations were processed, so it is showing the placeholder for a component that has not arrived yet and will keep showing it: ${cause}. Operations received: ${describeOperationKinds(operations)}. This warning is development-only.`);
3321
+ }
3169
3322
  function createA2UIMessageRenderer(options) {
3170
3323
  const { theme, catalog, loadingComponent, recovery, onAction } = options;
3171
3324
  const showAfterMs = recovery?.showAfterMs ?? 2e3;
@@ -3199,6 +3352,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
3199
3352
  return groups;
3200
3353
  }, [operations]);
3201
3354
  const hasOps = groupedOperations.size > 0;
3355
+ const groupedOperationsRef = (0, react.useRef)(groupedOperations);
3356
+ groupedOperationsRef.current = groupedOperations;
3202
3357
  const renderLifecycle = (c) => {
3203
3358
  const status = c?.status;
3204
3359
  const debugExposure = resolveDebugExposure(c, optionDebugExposure);
@@ -3230,7 +3385,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
3230
3385
  readyRef.current = false;
3231
3386
  return;
3232
3387
  }
3233
- const t = setTimeout(() => setSurfaceReady(true), 8e3);
3388
+ const t = setTimeout(() => {
3389
+ setSurfaceReady(true);
3390
+ if (IS_DEVELOPMENT && !readyRef.current) warnAboutUnpaintedSurfaces(groupedOperationsRef.current);
3391
+ }, PAINT_FALLBACK_MS);
3234
3392
  return () => clearTimeout(t);
3235
3393
  }, [hasOps]);
3236
3394
  if (!hasOps) return renderLifecycle(content);
@@ -3354,8 +3512,21 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
3354
3512
  const hash = JSON.stringify(operations);
3355
3513
  if (hash === lastHashRef.current) return;
3356
3514
  lastHashRef.current = hash;
3357
- processMessages(getSurface(surfaceId) ? operations.filter((op) => !op?.createSurface) : operations);
3515
+ const ops = getSurface(surfaceId) ? operations.filter((op) => !op?.createSurface) : operations;
3516
+ processMessages(ops);
3358
3517
  if (onReady && surfaceHasRenderableContent(operations)) onReady();
3518
+ if (!IS_DEVELOPMENT) return;
3519
+ if (!getSurface(surfaceId)) {
3520
+ const missingSurfaceCheck = setTimeout(() => {
3521
+ if (getSurface(surfaceId)) return;
3522
+ console.warn(`[CopilotKit] A2UI processed ${String(ops.length)} operation(s) addressed to surface "${surfaceId}" and no surface by that id exists, so this card rendered nothing. Operations received: ${describeOperationKinds(ops)}. A createSurface for "${surfaceId}" has to arrive before, or with, the operations that target it. This warning is development-only.`);
3523
+ }, 0);
3524
+ return () => clearTimeout(missingSurfaceCheck);
3525
+ }
3526
+ const unresolvedRootCheck = setTimeout(() => {
3527
+ warnAboutUnresolvedRoot(surfaceId, operations, getSurface(surfaceId));
3528
+ }, PAINT_FALLBACK_MS);
3529
+ return () => clearTimeout(unresolvedRootCheck);
3359
3530
  }, [
3360
3531
  processMessages,
3361
3532
  getSurface,
@@ -3382,10 +3553,26 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
3382
3553
  return Object.values(v).some((x) => Array.isArray(x) ? x.length > 0 : x !== null && x !== void 0 && x !== "");
3383
3554
  });
3384
3555
  }
3556
+ /**
3557
+ * Resolves the surface an operation addresses.
3558
+ *
3559
+ * The nested v0.9 `surfaceId` wins, because that is the id `MessageProcessor`
3560
+ * creates the surface under. Grouping by a top-level `surfaceId` instead files
3561
+ * the operations against a surface that never exists, which paints nothing —
3562
+ * the silence the missing-surface report above now names. A top-level
3563
+ * `surfaceId` is not the v0.9 shape, so it is honoured only when no nested id is
3564
+ * present. `getSurfaceId` in `@copilotkit/a2ui-renderer`'s web-components path
3565
+ * resolves it in the same order; the two disagreeing is what OSS-1048 recorded.
3566
+ *
3567
+ * @param operation - One A2UI operation, of any shape.
3568
+ * @returns The surface id, or null when the operation names none.
3569
+ */
3385
3570
  function getOperationSurfaceId(operation) {
3386
3571
  if (!operation || typeof operation !== "object") return null;
3572
+ const nested = operation?.createSurface?.surfaceId ?? operation?.updateComponents?.surfaceId ?? operation?.updateDataModel?.surfaceId ?? operation?.deleteSurface?.surfaceId;
3573
+ if (typeof nested === "string") return nested;
3387
3574
  if (typeof operation.surfaceId === "string") return operation.surfaceId;
3388
- return operation?.createSurface?.surfaceId ?? operation?.updateComponents?.surfaceId ?? operation?.updateDataModel?.surfaceId ?? operation?.deleteSurface?.surfaceId ?? null;
3575
+ return null;
3389
3576
  }
3390
3577
 
3391
3578
  //#endregion
@@ -3503,6 +3690,9 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
3503
3690
  const EMPTY_HEADERS = Object.freeze({});
3504
3691
  const EMPTY_PROPERTIES = Object.freeze({});
3505
3692
  const EMPTY_AGENTS = Object.freeze({});
3693
+ /** Registration name of a catch-all tool: handles any otherwise-unhandled call. */
3694
+ const WILDCARD_TOOL_NAME$1 = "*";
3695
+ const HUMAN_IN_THE_LOOP_ABORTED_MESSAGE = "Human-in-the-loop interaction aborted";
3506
3696
  const DEFAULT_DESIGN_SKILL = `When generating UI with generateSandboxedUi, follow these design principles inspired by shadcn/ui:
3507
3697
 
3508
3698
  - Use a minimal, flat aesthetic. Avoid drop shadows and gradients — rely on subtle borders (1px solid, light gray like #e5e7eb) to define surfaces.
@@ -3523,14 +3713,19 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
3523
3713
  }, [value, warningMessage]);
3524
3714
  return value;
3525
3715
  }
3526
- 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 }) => {
3527
3717
  const [shouldRenderInspector, setShouldRenderInspector] = (0, react.useState)(false);
3718
+ const [inspectorVisible, setInspectorVisible] = (0, react.useState)(false);
3528
3719
  (0, react.useEffect)(() => {
3529
3720
  setShouldRenderInspector((0, _copilotkit_shared.shouldEnableInspector)({
3530
3721
  enableInspector,
3531
3722
  isBrowser: true,
3532
3723
  isDevelopment: process.env.NODE_ENV === "development"
3533
- }));
3724
+ }) && [
3725
+ "localhost",
3726
+ "127.0.0.1",
3727
+ "[::1]"
3728
+ ].includes(window.location.hostname));
3534
3729
  }, [enableInspector]);
3535
3730
  const [inspectorOpenRequest, setInspectorOpenRequest] = (0, react.useState)(null);
3536
3731
  const [runtimeA2UIEnabled, setRuntimeA2UIEnabled] = (0, react.useState)(false);
@@ -3546,9 +3741,15 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
3546
3741
  setInspectorOpenRequest({ ...request });
3547
3742
  }, []);
3548
3743
  const inspectorContextValue = (0, react.useMemo)(() => ({
3549
- isInspectorEnabled: shouldRenderInspector,
3744
+ providerEnableInspector: enableInspector,
3745
+ isInspectorEnabled: shouldRenderInspector && inspectorVisible,
3550
3746
  openInspector: requestInspectorOpen
3551
- }), [shouldRenderInspector, requestInspectorOpen]);
3747
+ }), [
3748
+ enableInspector,
3749
+ shouldRenderInspector,
3750
+ inspectorVisible,
3751
+ requestInspectorOpen
3752
+ ]);
3552
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) => {
3553
3754
  const key = (rc) => `${rc?.agentId ?? ""}:${rc?.name ?? ""}`;
3554
3755
  const setFrom = (arr) => new Set(arr.map(key));
@@ -3621,6 +3822,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
3621
3822
  }
3622
3823
  const chatApiEndpoint = runtimeUrl ?? (resolvedPublicKey ? COPILOT_CLOUD_CHAT_URL$1 : void 0);
3623
3824
  const frontendToolsList = useStableArrayProp(frontendTools, "frontendTools must be a stable array. If you want to dynamically add or remove tools, use `useFrontendTool` instead.");
3825
+ /**
3826
+ * A `humanInTheLoop` prop tool call that is parked, waiting on the user.
3827
+ * Keyed by tool call id, so parallel calls of one tool stay independent.
3828
+ */
3829
+ const pendingHumanInTheLoopRef = (0, react.useRef)(/* @__PURE__ */ new Map());
3624
3830
  const humanInTheLoopList = useStableArrayProp(humanInTheLoop, "humanInTheLoop must be a stable array. If you want to dynamically add or remove human-in-the-loop tools, use `useHumanInTheLoop` instead.");
3625
3831
  const sandboxFunctionsList = useStableArrayProp(openGenerativeUI?.sandboxFunctions, "openGenerativeUI.sandboxFunctions must be a stable array.");
3626
3832
  const processedHumanInTheLoopTools = (0, react.useMemo)(() => {
@@ -3633,20 +3839,52 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
3633
3839
  parameters: tool.parameters,
3634
3840
  followUp: tool.followUp,
3635
3841
  ...tool.agentId && { agentId: tool.agentId },
3636
- handler: async () => {
3637
- return new Promise((resolve) => {
3638
- console.warn(`Human-in-the-loop tool '${tool.name}' called but no interactive handler is set up.`);
3639
- resolve(void 0);
3842
+ handler: async (_args, context) => {
3843
+ const signal = context?.signal;
3844
+ const key = context?.toolCall?.id ?? tool.name;
3845
+ return new Promise((resolve, reject) => {
3846
+ if (signal?.aborted) {
3847
+ reject(new Error(HUMAN_IN_THE_LOOP_ABORTED_MESSAGE));
3848
+ return;
3849
+ }
3850
+ const pending = { resolve };
3851
+ pendingHumanInTheLoopRef.current.set(key, pending);
3852
+ if (signal) {
3853
+ const onAbort = () => {
3854
+ pendingHumanInTheLoopRef.current.delete(key);
3855
+ reject(new Error(HUMAN_IN_THE_LOOP_ABORTED_MESSAGE));
3856
+ };
3857
+ signal.addEventListener("abort", onAbort, { once: true });
3858
+ pending.detachAbort = () => {
3859
+ signal.removeEventListener("abort", onAbort);
3860
+ };
3861
+ }
3640
3862
  });
3641
3863
  }
3642
3864
  };
3643
3865
  processedTools.push(frontendTool);
3644
- if (tool.render) processedRenderToolCalls.push({
3645
- name: tool.name,
3646
- args: tool.parameters,
3647
- render: tool.render,
3648
- ...tool.agentId && { agentId: tool.agentId }
3649
- });
3866
+ if (tool.render) {
3867
+ const ToolComponent = tool.render;
3868
+ const RenderComponent = (props) => (0, react.createElement)(ToolComponent, {
3869
+ ...props,
3870
+ name: tool.name === WILDCARD_TOOL_NAME$1 ? props.name : tool.name,
3871
+ description: tool.description || "",
3872
+ agentId: tool.agentId,
3873
+ respond: props.status === _copilotkit_core.ToolCallStatus.Executing ? async (result) => {
3874
+ const pending = pendingHumanInTheLoopRef.current.get(props.toolCallId);
3875
+ if (!pending) return;
3876
+ pending.detachAbort?.();
3877
+ pendingHumanInTheLoopRef.current.delete(props.toolCallId);
3878
+ pending.resolve(result);
3879
+ } : void 0
3880
+ });
3881
+ processedRenderToolCalls.push({
3882
+ name: tool.name,
3883
+ args: tool.parameters,
3884
+ render: RenderComponent,
3885
+ ...tool.agentId && { agentId: tool.agentId }
3886
+ });
3887
+ }
3650
3888
  });
3651
3889
  return {
3652
3890
  tools: processedTools,
@@ -3908,9 +4146,13 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
3908
4146
  }),
3909
4147
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(CopilotKitInspectorContextProvider, {
3910
4148
  value: inspectorContextValue,
3911
- 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, {
3912
4153
  core: copilotkit,
3913
- openRequest: inspectorOpenRequest
4154
+ openRequest: inspectorOpenRequest,
4155
+ onVisibilityChange: setInspectorVisible
3914
4156
  }) : null]
3915
4157
  }),
3916
4158
  runtimeLicenseWarningStatus === "none" && !resolvedPublicKey && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LicenseWarningBanner, { type: "no_license" }),
@@ -4492,7 +4734,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
4492
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}" }).`);
4493
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 }).`);
4494
4736
  const chatConfig = useCopilotChatConfiguration();
4495
- 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;
4496
4739
  const { copilotkit } = useCopilotKit();
4497
4740
  const providerThrottleMs = copilotkit.defaultThrottleMs;
4498
4741
  const [, forceUpdate] = (0, react.useReducer)((x) => x + 1, 0);
@@ -4720,7 +4963,12 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
4720
4963
  function useSuggestions({ agentId } = {}) {
4721
4964
  const { copilotkit } = useCopilotKit();
4722
4965
  const config = useCopilotChatConfiguration();
4723
- 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
+ ]);
4724
4972
  const [suggestions, setSuggestions] = (0, react.useState)(() => {
4725
4973
  return copilotkit.getSuggestions(resolvedAgentId).suggestions;
4726
4974
  });
@@ -6024,6 +6272,289 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
6024
6272
  }) });
6025
6273
  }
6026
6274
 
6275
+ //#endregion
6276
+ //#region src/v2/components/chat/CopilotChatInspectorButton.tsx
6277
+ let shortcutsHidden = false;
6278
+ const listeners = /* @__PURE__ */ new Set();
6279
+ const subscribe = (listener) => {
6280
+ listeners.add(listener);
6281
+ return () => {
6282
+ listeners.delete(listener);
6283
+ };
6284
+ };
6285
+ const getSnapshot = () => shortcutsHidden;
6286
+ const getServerSnapshot = () => false;
6287
+ function useInspectorShortcutsHidden() {
6288
+ return (0, react.useSyncExternalStore)(subscribe, getSnapshot, getServerSnapshot);
6289
+ }
6290
+ function hideShortcuts() {
6291
+ shortcutsHidden = true;
6292
+ listeners.forEach((listener) => listener());
6293
+ }
6294
+ function InspectorKiteIcon({ className, ...props }) {
6295
+ const id = (0, react.useId)();
6296
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
6297
+ ...props,
6298
+ "aria-hidden": "true",
6299
+ className: (0, tailwind_merge.twMerge)("cpk:size-4", className),
6300
+ viewBox: "4.57 3.36 17.8 17.8",
6301
+ fill: "none",
6302
+ children: [
6303
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
6304
+ 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",
6305
+ fill: `url(#${id}-paint0_linear)`
6306
+ }),
6307
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
6308
+ 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",
6309
+ fill: `url(#${id}-paint1_linear)`
6310
+ }),
6311
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
6312
+ 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",
6313
+ fill: `url(#${id}-paint2_linear)`
6314
+ }),
6315
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
6316
+ d: "M10.7145 3.79041L17.8305 20.7659",
6317
+ stroke: "#513C9F",
6318
+ strokeWidth: "0.17284",
6319
+ strokeLinecap: "round"
6320
+ }),
6321
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
6322
+ 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",
6323
+ stroke: "#513C9F",
6324
+ strokeWidth: "0.17284",
6325
+ strokeLinecap: "round"
6326
+ }),
6327
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
6328
+ d: "M11.6914 5.93518L9.05534 14.7068M9.05534 14.7068H15.3203M9.05534 14.7068L0.15625 26.3646",
6329
+ stroke: "#ABABAB",
6330
+ strokeWidth: "0.302474",
6331
+ strokeLinecap: "round"
6332
+ }),
6333
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
6334
+ 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",
6335
+ fill: `url(#${id}-paint3_linear)`
6336
+ }),
6337
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("defs", { children: [
6338
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("linearGradient", {
6339
+ id: `${id}-paint0_linear`,
6340
+ x1: "15.5372",
6341
+ y1: "5.0278",
6342
+ x2: "12.0802",
6343
+ y2: "14.534",
6344
+ gradientUnits: "userSpaceOnUse",
6345
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", { stopColor: "#6430AB" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", {
6346
+ offset: "1",
6347
+ stopColor: "#AA89D8"
6348
+ })]
6349
+ }),
6350
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("linearGradient", {
6351
+ id: `${id}-paint1_linear`,
6352
+ x1: "12.8583",
6353
+ y1: "10.3858",
6354
+ x2: "8.40764",
6355
+ y2: "18.9846",
6356
+ gradientUnits: "userSpaceOnUse",
6357
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", { stopColor: "#005DBB" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", {
6358
+ offset: "1",
6359
+ stopColor: "#3D92E8"
6360
+ })]
6361
+ }),
6362
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("linearGradient", {
6363
+ id: `${id}-paint2_linear`,
6364
+ x1: "14.8452",
6365
+ y1: "5.02774",
6366
+ x2: "13.5047",
6367
+ y2: "9.21911",
6368
+ gradientUnits: "userSpaceOnUse",
6369
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", { stopColor: "#1B70C4" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", {
6370
+ offset: "1",
6371
+ stopColor: "#54A4F2"
6372
+ })]
6373
+ }),
6374
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("linearGradient", {
6375
+ id: `${id}-paint3_linear`,
6376
+ x1: "4.85806",
6377
+ y1: "24.2455",
6378
+ x2: "18.9963",
6379
+ y2: "24.2455",
6380
+ gradientUnits: "userSpaceOnUse",
6381
+ children: [
6382
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", { stopColor: "#4497EA" }),
6383
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", {
6384
+ offset: "0.254755",
6385
+ stopColor: "#1463B2"
6386
+ }),
6387
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", {
6388
+ offset: "0.498725",
6389
+ stopColor: "#0A437D"
6390
+ }),
6391
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", {
6392
+ offset: "0.666667",
6393
+ stopColor: "#2476C8"
6394
+ }),
6395
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", {
6396
+ offset: "0.972542",
6397
+ stopColor: "#0C549A"
6398
+ })
6399
+ ]
6400
+ })
6401
+ ] })
6402
+ ]
6403
+ });
6404
+ }
6405
+ function CopilotChatInspectorButton({ title, className, onClick, onPointerDown, onPointerEnter, onPointerLeave, onKeyDown, disabled, ...props }) {
6406
+ const labels = useCopilotChatConfiguration()?.labels ?? CopilotChatDefaultLabels;
6407
+ const { isInspectorEnabled } = useCopilotKitInspector();
6408
+ const hidden = useInspectorShortcutsHidden();
6409
+ const [open, setOpen] = (0, react.useState)(false);
6410
+ const [dark, setDark] = (0, react.useState)(false);
6411
+ const trigger = (0, react.useRef)(null);
6412
+ const closeTimer = (0, react.useRef)(null);
6413
+ const openedByHover = (0, react.useRef)(false);
6414
+ const primaryLabel = title || labels.assistantMessageToolbarInspectorLabel;
6415
+ const cancelClose = () => {
6416
+ if (closeTimer.current !== null) clearTimeout(closeTimer.current);
6417
+ closeTimer.current = null;
6418
+ };
6419
+ (0, react.useEffect)(() => cancelClose, []);
6420
+ const changeOpen = (next) => {
6421
+ cancelClose();
6422
+ if (next) setDark(!!trigger.current?.closest(".dark"));
6423
+ setOpen(next);
6424
+ };
6425
+ const scheduleClose = () => {
6426
+ cancelClose();
6427
+ closeTimer.current = setTimeout(() => {
6428
+ if (openedByHover.current) setOpen(false);
6429
+ }, 180);
6430
+ };
6431
+ if (!isInspectorEnabled || hidden) return null;
6432
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(DropdownMenu, {
6433
+ open,
6434
+ onOpenChange: changeOpen,
6435
+ modal: false,
6436
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(DropdownMenuTrigger, {
6437
+ asChild: true,
6438
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
6439
+ ...props,
6440
+ ref: trigger,
6441
+ type: "button",
6442
+ disabled,
6443
+ variant: "assistantMessageToolbarButton",
6444
+ size: "icon",
6445
+ "data-testid": "copilot-inspector-button",
6446
+ "aria-label": `${labels.assistantMessageToolbarInspectorTitle} (${labels.assistantMessageToolbarInspectorLocalOnlyLabel.toLowerCase()})`,
6447
+ className: (0, tailwind_merge.twMerge)("cpk:size-8 cpk:p-1.5", className),
6448
+ onPointerEnter: (event) => {
6449
+ onPointerEnter?.(event);
6450
+ if (!disabled && event.pointerType !== "touch") {
6451
+ openedByHover.current = true;
6452
+ changeOpen(true);
6453
+ }
6454
+ },
6455
+ onPointerLeave: (event) => {
6456
+ onPointerLeave?.(event);
6457
+ scheduleClose();
6458
+ },
6459
+ onPointerDown: (event) => {
6460
+ onPointerDown?.(event);
6461
+ event.preventDefault();
6462
+ },
6463
+ onClick: (event) => {
6464
+ changeOpen(false);
6465
+ onClick?.(event);
6466
+ },
6467
+ onKeyDown: (event) => {
6468
+ openedByHover.current = false;
6469
+ onKeyDown?.(event);
6470
+ if (!event.defaultPrevented && (event.key === "Enter" || event.key === " ")) {
6471
+ event.preventDefault();
6472
+ event.currentTarget.click();
6473
+ }
6474
+ },
6475
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Wrench, {
6476
+ "aria-hidden": "true",
6477
+ className: "cpk:size-4",
6478
+ "data-testid": "copilot-inspector-icon"
6479
+ })
6480
+ })
6481
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(DropdownMenuContent, {
6482
+ align: "start",
6483
+ side: "top",
6484
+ sideOffset: 6,
6485
+ className: (0, tailwind_merge.twMerge)("cpk:w-64 cpk:p-1 cpk:text-sm", dark && "dark"),
6486
+ onPointerEnter: cancelClose,
6487
+ onPointerLeave: scheduleClose,
6488
+ onKeyDown: () => {
6489
+ openedByHover.current = false;
6490
+ },
6491
+ onOpenAutoFocus: (event) => {
6492
+ if (openedByHover.current) event.preventDefault();
6493
+ },
6494
+ onCloseAutoFocus: (event) => {
6495
+ if (openedByHover.current) event.preventDefault();
6496
+ },
6497
+ onFocusOutside: () => changeOpen(false),
6498
+ children: [
6499
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(DropdownMenuLabel, {
6500
+ className: "cpk:flex cpk:items-center cpk:justify-between cpk:gap-3 cpk:px-2 cpk:py-2",
6501
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
6502
+ className: "cpk:text-xs cpk:font-medium",
6503
+ children: labels.assistantMessageToolbarInspectorTitle
6504
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(Tooltip, {
6505
+ delayDuration: 1e3,
6506
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(TooltipTrigger, {
6507
+ asChild: true,
6508
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
6509
+ tabIndex: 0,
6510
+ 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",
6511
+ children: labels.assistantMessageToolbarInspectorLocalOnlyLabel
6512
+ })
6513
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TooltipContent, {
6514
+ side: "top",
6515
+ sideOffset: 6,
6516
+ className: (0, tailwind_merge.twMerge)("cpk:max-w-48 cpk:text-wrap", dark && "dark"),
6517
+ onPointerEnter: cancelClose,
6518
+ onPointerLeave: scheduleClose,
6519
+ children: labels.assistantMessageToolbarInspectorLocalOnlyDescription
6520
+ })]
6521
+ })]
6522
+ }),
6523
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DropdownMenuSeparator, {}),
6524
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DropdownMenuItem, {
6525
+ asChild: true,
6526
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
6527
+ type: "button",
6528
+ onClick,
6529
+ className: "cpk:w-full cpk:cursor-pointer cpk:items-start cpk:text-left",
6530
+ 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", {
6531
+ className: "cpk:block",
6532
+ children: primaryLabel
6533
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
6534
+ className: "cpk:block cpk:text-xs cpk:text-muted-foreground",
6535
+ children: labels.assistantMessageToolbarInspectorDescription
6536
+ })] })]
6537
+ })
6538
+ }),
6539
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(DropdownMenuItem, {
6540
+ onSelect: hideShortcuts,
6541
+ className: "cpk:cursor-pointer cpk:items-start",
6542
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.EyeOff, {
6543
+ "aria-hidden": "true",
6544
+ className: "cpk:mt-0.5"
6545
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
6546
+ className: "cpk:block",
6547
+ children: labels.assistantMessageToolbarInspectorHideLabel
6548
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
6549
+ className: "cpk:block cpk:text-xs cpk:text-muted-foreground",
6550
+ children: labels.assistantMessageToolbarInspectorHideDescription
6551
+ })] })]
6552
+ })
6553
+ ]
6554
+ })]
6555
+ });
6556
+ }
6557
+
6027
6558
  //#endregion
6028
6559
  //#region src/v2/components/chat/CopilotChatAssistantMessage.tsx
6029
6560
  /**
@@ -6044,30 +6575,32 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
6044
6575
  function CopilotChatAssistantMessage({ message, messages, isRunning, onThumbsUp, onThumbsDown, onReadAloud, onRegenerate, additionalToolbarItems, toolbarVisible = true, markdownRenderer, toolbar, copyButton, inspectorButton, thumbsUpButton, thumbsDownButton, readAloudButton, regenerateButton, toolCallsView, children, className, ...props }) {
6045
6576
  useKatexStyles();
6046
6577
  const { isInspectorEnabled, openInspector } = useCopilotKitInspector();
6578
+ const shortcutsHidden = useInspectorShortcutsHidden();
6579
+ const showInspectorShortcut = isInspectorEnabled && !shortcutsHidden;
6047
6580
  const boundMarkdownRenderer = renderSlot(markdownRenderer, CopilotChatAssistantMessage.MarkdownRenderer, { content: message.content || "" });
6048
6581
  const boundCopyButton = renderSlot(copyButton, CopilotChatAssistantMessage.CopyButton, { onClick: async () => {
6049
6582
  if (message.content) return await (0, _copilotkit_shared.copyToClipboard)(message.content);
6050
6583
  return false;
6051
6584
  } });
6052
6585
  const boundThumbsUpButton = renderSlot(thumbsUpButton, CopilotChatAssistantMessage.ThumbsUpButton, { onClick: onThumbsUp ? () => onThumbsUp(message) : void 0 });
6053
- const boundInspectorButton = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(BoundInspectorButton, {
6586
+ const boundInspectorButton = showInspectorShortcut ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(BoundInspectorButton, {
6054
6587
  inspectorButton,
6055
6588
  messageId: message.id,
6056
6589
  openInspector
6057
- });
6590
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, {});
6058
6591
  const boundThumbsDownButton = renderSlot(thumbsDownButton, CopilotChatAssistantMessage.ThumbsDownButton, { onClick: onThumbsDown ? () => onThumbsDown(message) : void 0 });
6059
6592
  const boundReadAloudButton = renderSlot(readAloudButton, CopilotChatAssistantMessage.ReadAloudButton, { onClick: onReadAloud ? () => onReadAloud(message) : void 0 });
6060
6593
  const boundRegenerateButton = renderSlot(regenerateButton, CopilotChatAssistantMessage.RegenerateButton, { onClick: onRegenerate ? () => onRegenerate(message) : void 0 });
6061
6594
  const boundToolbar = renderSlot(toolbar, CopilotChatAssistantMessage.Toolbar, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
6062
- className: "cpk:flex cpk:items-center cpk:gap-1",
6595
+ className: "cpk:flex cpk:w-full cpk:items-center cpk:gap-1",
6063
6596
  children: [
6064
6597
  boundCopyButton,
6065
- isInspectorEnabled && boundInspectorButton,
6066
6598
  (onThumbsUp || thumbsUpButton) && boundThumbsUpButton,
6067
6599
  (onThumbsDown || thumbsDownButton) && boundThumbsDownButton,
6068
6600
  (onReadAloud || readAloudButton) && boundReadAloudButton,
6069
6601
  (onRegenerate || regenerateButton) && boundRegenerateButton,
6070
- additionalToolbarItems
6602
+ additionalToolbarItems,
6603
+ showInspectorShortcut && boundInspectorButton
6071
6604
  ]
6072
6605
  }) });
6073
6606
  const boundToolCallsView = renderSlot(toolCallsView, CopilotChatToolCallsView, {
@@ -6076,7 +6609,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
6076
6609
  });
6077
6610
  const hasContent = !!(message.content && message.content.trim().length > 0);
6078
6611
  const isLatestAssistantMessage = message.role === "assistant" && messages?.[messages.length - 1]?.id === message.id;
6079
- const shouldShowToolbar = toolbarVisible && (hasContent || isInspectorEnabled) && !(isRunning && isLatestAssistantMessage);
6612
+ const shouldShowToolbar = toolbarVisible && (hasContent || showInspectorShortcut) && !(isRunning && isLatestAssistantMessage);
6080
6613
  if (children) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
6081
6614
  "data-copilotkit": true,
6082
6615
  style: { display: "contents" },
@@ -6117,110 +6650,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
6117
6650
  ]
6118
6651
  });
6119
6652
  }
6120
- function CopilotKitColoredIcon() {
6121
- const gradientId = (0, react.useId)().replace(/:/g, "");
6122
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
6123
- "aria-hidden": "true",
6124
- className: "cpk:size-5",
6125
- "data-testid": "copilot-inspector-icon",
6126
- viewBox: "0 0 24 24",
6127
- children: [
6128
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
6129
- 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",
6130
- fill: `url(#${gradientId}-purple)`
6131
- }),
6132
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
6133
- 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",
6134
- fill: `url(#${gradientId}-blue)`
6135
- }),
6136
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
6137
- 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",
6138
- fill: `url(#${gradientId}-light-blue)`
6139
- }),
6140
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
6141
- className: "cpk:fill-[#513C9F] cpk:dark:fill-[#B99AE8]",
6142
- 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"
6143
- }),
6144
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
6145
- className: "cpk:fill-[#513C9F] cpk:dark:fill-[#B99AE8]",
6146
- 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"
6147
- }),
6148
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
6149
- className: "cpk:fill-[#ABABAB] cpk:dark:fill-[#D4D4D4]",
6150
- 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"
6151
- }),
6152
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
6153
- 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",
6154
- fill: `url(#${gradientId}-tail)`
6155
- }),
6156
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("defs", { children: [
6157
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("linearGradient", {
6158
- gradientUnits: "userSpaceOnUse",
6159
- id: `${gradientId}-purple`,
6160
- x1: "17.852",
6161
- x2: "14.202",
6162
- y1: "1.467",
6163
- y2: "11.504",
6164
- 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", {
6165
- className: "cpk:[stop-color:#AA89D8] cpk:dark:[stop-color:#D3BDF7]",
6166
- offset: "1"
6167
- })]
6168
- }),
6169
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("linearGradient", {
6170
- gradientUnits: "userSpaceOnUse",
6171
- id: `${gradientId}-blue`,
6172
- x1: "15.024",
6173
- x2: "10.324",
6174
- y1: "7.125",
6175
- y2: "16.204",
6176
- 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", {
6177
- className: "cpk:[stop-color:#3D92E8] cpk:dark:[stop-color:#84C0FA]",
6178
- offset: "1"
6179
- })]
6180
- }),
6181
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("linearGradient", {
6182
- gradientUnits: "userSpaceOnUse",
6183
- id: `${gradientId}-light-blue`,
6184
- x1: "17.122",
6185
- x2: "15.707",
6186
- y1: "1.467",
6187
- y2: "5.892",
6188
- 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", {
6189
- className: "cpk:[stop-color:#54A4F2] cpk:dark:[stop-color:#9ACDFF]",
6190
- offset: "1"
6191
- })]
6192
- }),
6193
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("linearGradient", {
6194
- gradientUnits: "userSpaceOnUse",
6195
- id: `${gradientId}-tail`,
6196
- x1: "6.577",
6197
- x2: "21.506",
6198
- y1: "21.758",
6199
- y2: "21.758",
6200
- children: [
6201
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", { className: "cpk:[stop-color:#4497EA] cpk:dark:[stop-color:#79BCF5]" }),
6202
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", {
6203
- className: "cpk:[stop-color:#1463B2] cpk:dark:[stop-color:#4594D8]",
6204
- offset: ".255"
6205
- }),
6206
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", {
6207
- className: "cpk:[stop-color:#0A437D] cpk:dark:[stop-color:#347CB7]",
6208
- offset: ".499"
6209
- }),
6210
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", {
6211
- className: "cpk:[stop-color:#2476C8] cpk:dark:[stop-color:#58A4E5]",
6212
- offset: ".667"
6213
- }),
6214
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("stop", {
6215
- className: "cpk:[stop-color:#0C549A] cpk:dark:[stop-color:#3C87C7]",
6216
- offset: ".973"
6217
- })
6218
- ]
6219
- })
6220
- ] })
6221
- ]
6222
- });
6223
- }
6224
6653
  (function(_CopilotChatAssistantMessage) {
6225
6654
  _CopilotChatAssistantMessage.MarkdownRenderer = ({ content, className, ...props }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(streamdown.Streamdown, {
6226
6655
  className,
@@ -6278,30 +6707,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
6278
6707
  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]" })
6279
6708
  });
6280
6709
  };
6281
- _CopilotChatAssistantMessage.InspectorButton = ({ title, className, ...props }) => {
6282
- const labels = useCopilotChatConfiguration()?.labels ?? CopilotChatDefaultLabels;
6283
- const primaryLabel = title || labels.assistantMessageToolbarInspectorLabel;
6284
- const accessibleLabel = `${primaryLabel} (local only)`;
6285
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(ToolbarButton, {
6286
- "data-testid": "copilot-inspector-button",
6287
- title: accessibleLabel,
6288
- className: (0, tailwind_merge.twMerge)("cpk:w-auto cpk:gap-1.5 cpk:px-2", className),
6289
- tooltipClassName: "cpk:max-w-64 cpk:text-left cpk:leading-4",
6290
- tooltip: "View this message in the Inspector to get more information. This button and the inspector only display during local development (localhost, dev env).",
6291
- ...props,
6292
- children: [
6293
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitColoredIcon, {}),
6294
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
6295
- className: "cpk:font-medium",
6296
- children: primaryLabel
6297
- }),
6298
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
6299
- className: "cpk:text-xs cpk:text-muted-foreground",
6300
- children: "(local only)"
6301
- })
6302
- ]
6303
- });
6304
- };
6710
+ _CopilotChatAssistantMessage.InspectorButton = CopilotChatInspectorButton;
6305
6711
  _CopilotChatAssistantMessage.ThumbsUpButton = ({ title, ...props }) => {
6306
6712
  const labels = useCopilotChatConfiguration()?.labels ?? CopilotChatDefaultLabels;
6307
6713
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolbarButton, {
@@ -8551,9 +8957,15 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
8551
8957
 
8552
8958
  //#endregion
8553
8959
  //#region src/v2/components/chat/CopilotChat.tsx
8554
- function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen, attachments: attachmentsConfig, onError, throttleMs, ...props }) {
8960
+ function CopilotChat({ agentId, threadId, labels, inspectorTools, chatView, isModalDefaultOpen, attachments: attachmentsConfig, onError, throttleMs, ...props }) {
8555
8961
  const existingConfig = useCopilotChatConfiguration();
8556
- const resolvedAgentId = agentId ?? existingConfig?.agentId ?? _copilotkit_shared.DEFAULT_AGENT_ID;
8962
+ const inspector = useCopilotKitInspector();
8963
+ const inspectorContextValue = (0, react.useMemo)(() => ({
8964
+ ...inspector,
8965
+ isInspectorEnabled: inspector.isInspectorEnabled && (inspector.providerEnableInspector ?? inspectorTools ?? true)
8966
+ }), [inspector, inspectorTools]);
8967
+ const providerAgentId = useDefaultAgentId();
8968
+ const resolvedAgentId = agentId ?? existingConfig?.agentId ?? providerAgentId ?? _copilotkit_shared.DEFAULT_AGENT_ID;
8557
8969
  const providedThreadId = threadId ?? existingConfig?.threadId;
8558
8970
  const baseThreadId = (0, react.useMemo)(() => providedThreadId ?? (0, _copilotkit_shared.randomUUID)(), [providedThreadId]);
8559
8971
  const baseHasExplicitThreadId = !!threadId || !!existingConfig?.hasExplicitThreadId;
@@ -9126,7 +9538,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
9126
9538
  }),
9127
9539
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LastUserMessageContext.Provider, {
9128
9540
  value: lastUserMessageState,
9129
- children: RenderedChatView
9541
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitInspectorContextProvider, {
9542
+ value: inspectorContextValue,
9543
+ children: RenderedChatView
9544
+ })
9130
9545
  })
9131
9546
  ]
9132
9547
  })
@@ -9834,7 +10249,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
9834
10249
  const featureLicensed = checkFeature("threads");
9835
10250
  const licensed = licensePresent && featureLicensed;
9836
10251
  const licensePending = status === null;
9837
- const resolvedAgentId = agentId ?? configuration?.agentId ?? _copilotkit_shared.DEFAULT_AGENT_ID;
10252
+ const providerAgentId = useDefaultAgentId();
10253
+ const resolvedAgentId = agentId ?? configuration?.agentId ?? providerAgentId ?? _copilotkit_shared.DEFAULT_AGENT_ID;
9838
10254
  const activeThreadId = configuration?.threadId ?? null;
9839
10255
  const { threads, isLoading, listError, fetchMoreError, hasMoreThreads, isFetchingMoreThreads, archiveThread, unarchiveThread, deleteThread, fetchMoreThreads, refetchThreads, startNewThread } = useThreads({
9840
10256
  agentId: resolvedAgentId,