@copilotkit/react-core 1.56.5 → 1.57.0-canary.1778082736

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 (47) hide show
  1. package/dist/{copilotkit-DFaI4j2r.d.mts → copilotkit-BNlJq5UO.d.mts} +60 -6
  2. package/dist/copilotkit-BNlJq5UO.d.mts.map +1 -0
  3. package/dist/{copilotkit-DMFu29Kx.cjs → copilotkit-B_k0HSNz.cjs} +322 -175
  4. package/dist/copilotkit-B_k0HSNz.cjs.map +1 -0
  5. package/dist/{copilotkit-Dg4r4Gi_.d.cts → copilotkit-DgC5oCFO.d.cts} +60 -6
  6. package/dist/copilotkit-DgC5oCFO.d.cts.map +1 -0
  7. package/dist/{copilotkit-OmIUrWym.mjs → copilotkit-ak8sGvQr.mjs} +317 -176
  8. package/dist/copilotkit-ak8sGvQr.mjs.map +1 -0
  9. package/dist/index.cjs +2 -5
  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 +2 -5
  14. package/dist/index.mjs.map +1 -1
  15. package/dist/index.umd.js +117 -172
  16. package/dist/index.umd.js.map +1 -1
  17. package/dist/v2/index.cjs +2 -1
  18. package/dist/v2/index.css +1 -1
  19. package/dist/v2/index.d.cts +2 -2
  20. package/dist/v2/index.d.mts +2 -2
  21. package/dist/v2/index.mjs +2 -2
  22. package/dist/v2/index.umd.js +332 -181
  23. package/dist/v2/index.umd.js.map +1 -1
  24. package/package.json +6 -6
  25. package/src/hooks/__tests__/use-copilot-chat-internal-connect.test.tsx +5 -6
  26. package/src/hooks/use-copilot-chat_internal.ts +0 -1
  27. package/src/v2/components/chat/CopilotChat.tsx +2 -1
  28. package/src/v2/components/chat/CopilotChatMessageView.tsx +24 -9
  29. package/src/v2/components/chat/CopilotChatView.tsx +2 -2
  30. package/src/v2/components/chat/__tests__/CopilotChat.welcomeGate.test.tsx +1 -3
  31. package/src/v2/components/chat/__tests__/CopilotChatActivityRendering.e2e.test.tsx +29 -25
  32. package/src/v2/components/chat/__tests__/MCPAppsUiMessage.e2e.test.tsx +5 -60
  33. package/src/v2/components/index.ts +1 -0
  34. package/src/v2/components/intelligence-indicator/IntelligenceIndicator.tsx +286 -0
  35. package/src/v2/components/intelligence-indicator/__tests__/IntelligenceIndicator.e2e.test.tsx +464 -0
  36. package/src/v2/components/intelligence-indicator/index.ts +2 -0
  37. package/src/v2/hooks/__tests__/use-threads.test.tsx +229 -27
  38. package/src/v2/hooks/use-agent.tsx +7 -116
  39. package/src/v2/hooks/use-render-activity-message.tsx +3 -11
  40. package/src/v2/hooks/use-render-custom-messages.tsx +1 -6
  41. package/src/v2/hooks/use-threads.tsx +7 -1
  42. package/src/v2/styles/globals.css +118 -0
  43. package/dist/copilotkit-DFaI4j2r.d.mts.map +0 -1
  44. package/dist/copilotkit-DMFu29Kx.cjs.map +0 -1
  45. package/dist/copilotkit-Dg4r4Gi_.d.cts.map +0 -1
  46. package/dist/copilotkit-OmIUrWym.mjs.map +0 -1
  47. package/src/v2/hooks/__tests__/use-agent-thread-isolation.test.tsx +0 -333
@@ -3558,171 +3558,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
3558
3558
  ]);
3559
3559
  }
3560
3560
 
3561
- //#endregion
3562
- //#region src/v2/hooks/use-agent.tsx
3563
- let UseAgentUpdate = /* @__PURE__ */ function(UseAgentUpdate) {
3564
- UseAgentUpdate["OnMessagesChanged"] = "OnMessagesChanged";
3565
- UseAgentUpdate["OnStateChanged"] = "OnStateChanged";
3566
- UseAgentUpdate["OnRunStatusChanged"] = "OnRunStatusChanged";
3567
- return UseAgentUpdate;
3568
- }({});
3569
- const ALL_UPDATES = [
3570
- UseAgentUpdate.OnMessagesChanged,
3571
- UseAgentUpdate.OnStateChanged,
3572
- UseAgentUpdate.OnRunStatusChanged
3573
- ];
3574
- /**
3575
- * Clone a registry agent for per-thread isolation.
3576
- * Copies agent configuration (transport, headers, etc.) but resets conversation
3577
- * state (messages, threadId, state) so each thread starts fresh.
3578
- */
3579
- function cloneForThread(source, threadId, headers) {
3580
- const clone = source.clone();
3581
- if (clone === source) throw new Error(`useAgent: ${source.constructor.name}.clone() returned the same instance. clone() must return a new, independent object.`);
3582
- clone.threadId = threadId;
3583
- clone.setMessages([]);
3584
- clone.setState({});
3585
- if (clone instanceof _ag_ui_client.HttpAgent) clone.headers = { ...headers };
3586
- return clone;
3587
- }
3588
- /**
3589
- * Module-level WeakMap: registryAgent → (threadId → clone).
3590
- * Shared across all useAgent() calls so that every component using the same
3591
- * (agentId, threadId) pair receives the same agent instance. Using WeakMap
3592
- * ensures the clone map is garbage-collected when the registry agent is
3593
- * replaced (e.g. after reconnect or hot-reload).
3594
- */
3595
- const globalThreadCloneMap = /* @__PURE__ */ new WeakMap();
3596
- /**
3597
- * Look up an existing per-thread clone without creating one.
3598
- * Returns undefined when no clone has been created yet for this pair.
3599
- */
3600
- function getThreadClone(registryAgent, threadId) {
3601
- var _globalThreadCloneMap;
3602
- if (!registryAgent || !threadId) return void 0;
3603
- return (_globalThreadCloneMap = globalThreadCloneMap.get(registryAgent)) === null || _globalThreadCloneMap === void 0 ? void 0 : _globalThreadCloneMap.get(threadId);
3604
- }
3605
- function getOrCreateThreadClone(existing, threadId, headers) {
3606
- let byThread = globalThreadCloneMap.get(existing);
3607
- if (!byThread) {
3608
- byThread = /* @__PURE__ */ new Map();
3609
- globalThreadCloneMap.set(existing, byThread);
3610
- }
3611
- const cached = byThread.get(threadId);
3612
- if (cached) return cached;
3613
- const clone = cloneForThread(existing, threadId, headers);
3614
- byThread.set(threadId, clone);
3615
- return clone;
3616
- }
3617
- function useAgent({ agentId, threadId, updates, throttleMs } = {}) {
3618
- var _agentId, _threadId;
3619
- (_agentId = agentId) !== null && _agentId !== void 0 || (agentId = _copilotkit_shared.DEFAULT_AGENT_ID);
3620
- const { copilotkit } = useCopilotKit();
3621
- const providerThrottleMs = copilotkit.defaultThrottleMs;
3622
- const chatConfig = useCopilotChatConfiguration();
3623
- (_threadId = threadId) !== null && _threadId !== void 0 || (threadId = chatConfig === null || chatConfig === void 0 ? void 0 : chatConfig.threadId);
3624
- const [, forceUpdate] = (0, react.useReducer)((x) => x + 1, 0);
3625
- const updateFlags = (0, react.useMemo)(() => updates !== null && updates !== void 0 ? updates : ALL_UPDATES, [JSON.stringify(updates)]);
3626
- const provisionalAgentCache = (0, react.useRef)(/* @__PURE__ */ new Map());
3627
- const agent = (0, react.useMemo)(() => {
3628
- var _copilotkit$agents;
3629
- const cacheKey = threadId ? `${agentId}:${threadId}` : agentId;
3630
- const existing = copilotkit.getAgent(agentId);
3631
- if (existing) {
3632
- provisionalAgentCache.current.delete(cacheKey);
3633
- provisionalAgentCache.current.delete(agentId);
3634
- if (!threadId) return existing;
3635
- return getOrCreateThreadClone(existing, threadId, copilotkit.headers);
3636
- }
3637
- const isRuntimeConfigured = copilotkit.runtimeUrl !== void 0;
3638
- const status = copilotkit.runtimeConnectionStatus;
3639
- if (isRuntimeConfigured && (status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Disconnected || status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Connecting)) {
3640
- const cached = provisionalAgentCache.current.get(cacheKey);
3641
- if (cached) {
3642
- cached.headers = { ...copilotkit.headers };
3643
- return cached;
3644
- }
3645
- const provisional = new _copilotkit_core.ProxiedCopilotRuntimeAgent({
3646
- runtimeUrl: copilotkit.runtimeUrl,
3647
- agentId,
3648
- transport: copilotkit.runtimeTransport,
3649
- runtimeMode: "pending"
3650
- });
3651
- provisional.headers = { ...copilotkit.headers };
3652
- if (threadId) provisional.threadId = threadId;
3653
- provisionalAgentCache.current.set(cacheKey, provisional);
3654
- return provisional;
3655
- }
3656
- if (isRuntimeConfigured && status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Error) {
3657
- const cached = provisionalAgentCache.current.get(cacheKey);
3658
- if (cached) {
3659
- cached.headers = { ...copilotkit.headers };
3660
- return cached;
3661
- }
3662
- const provisional = new _copilotkit_core.ProxiedCopilotRuntimeAgent({
3663
- runtimeUrl: copilotkit.runtimeUrl,
3664
- agentId,
3665
- transport: copilotkit.runtimeTransport,
3666
- runtimeMode: "pending"
3667
- });
3668
- provisional.headers = { ...copilotkit.headers };
3669
- if (threadId) provisional.threadId = threadId;
3670
- provisionalAgentCache.current.set(cacheKey, provisional);
3671
- return provisional;
3672
- }
3673
- const knownAgents = Object.keys((_copilotkit$agents = copilotkit.agents) !== null && _copilotkit$agents !== void 0 ? _copilotkit$agents : {});
3674
- const runtimePart = isRuntimeConfigured ? `runtimeUrl=${copilotkit.runtimeUrl}` : "no runtimeUrl";
3675
- throw new Error(`useAgent: Agent '${agentId}' not found after runtime sync (${runtimePart}). ` + (knownAgents.length ? `Known agents: [${knownAgents.join(", ")}]` : "No agents registered.") + " Verify your runtime /info and/or agents__unsafe_dev_only.");
3676
- }, [
3677
- agentId,
3678
- threadId,
3679
- copilotkit.agents,
3680
- copilotkit.runtimeConnectionStatus,
3681
- copilotkit.runtimeUrl,
3682
- copilotkit.runtimeTransport,
3683
- JSON.stringify(copilotkit.headers)
3684
- ]);
3685
- (0, react.useEffect)(() => {
3686
- if (updateFlags.length === 0) return;
3687
- let active = true;
3688
- const handlers = {};
3689
- let batchScheduled = false;
3690
- const batchedForceUpdate = () => {
3691
- if (!active) return;
3692
- if (!batchScheduled) {
3693
- batchScheduled = true;
3694
- queueMicrotask(() => {
3695
- batchScheduled = false;
3696
- if (active) forceUpdate();
3697
- });
3698
- }
3699
- };
3700
- if (updateFlags.includes(UseAgentUpdate.OnMessagesChanged)) handlers.onMessagesChanged = forceUpdate;
3701
- if (updateFlags.includes(UseAgentUpdate.OnStateChanged)) handlers.onStateChanged = batchedForceUpdate;
3702
- if (updateFlags.includes(UseAgentUpdate.OnRunStatusChanged)) {
3703
- handlers.onRunInitialized = batchedForceUpdate;
3704
- handlers.onRunFinalized = batchedForceUpdate;
3705
- handlers.onRunFailed = batchedForceUpdate;
3706
- handlers.onRunErrorEvent = batchedForceUpdate;
3707
- }
3708
- const subscription = copilotkit.subscribeToAgentWithOptions(agent, handlers, { throttleMs });
3709
- return () => {
3710
- active = false;
3711
- subscription.unsubscribe();
3712
- };
3713
- }, [
3714
- agent,
3715
- forceUpdate,
3716
- throttleMs,
3717
- providerThrottleMs,
3718
- updateFlags
3719
- ]);
3720
- (0, react.useEffect)(() => {
3721
- if (agent instanceof _ag_ui_client.HttpAgent) agent.headers = { ...copilotkit.headers };
3722
- }, [agent, JSON.stringify(copilotkit.headers)]);
3723
- return { agent };
3724
- }
3725
-
3726
3561
  //#endregion
3727
3562
  //#region src/v2/hooks/use-render-custom-messages.tsx
3728
3563
  function useRenderCustomMessages() {
@@ -3736,13 +3571,12 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
3736
3571
  return aHasAgent ? -1 : 1;
3737
3572
  });
3738
3573
  return function(params) {
3739
- var _copilotkit$getRunIdF, _getThreadClone;
3574
+ var _copilotkit$getRunIdF;
3740
3575
  if (!customMessageRenderers.length) return null;
3741
3576
  const { message, position } = params;
3742
3577
  const resolvedRunId = (_copilotkit$getRunIdF = copilotkit.getRunIdForMessage(agentId, threadId, message.id)) !== null && _copilotkit$getRunIdF !== void 0 ? _copilotkit$getRunIdF : copilotkit.getRunIdsForThread(agentId, threadId).slice(-1)[0];
3743
3578
  const runId = resolvedRunId !== null && resolvedRunId !== void 0 ? resolvedRunId : `missing-run-id:${message.id}`;
3744
- const registryAgent = copilotkit.getAgent(agentId);
3745
- const agent = (_getThreadClone = getThreadClone(registryAgent, threadId)) !== null && _getThreadClone !== void 0 ? _getThreadClone : registryAgent;
3579
+ const agent = copilotkit.getAgent(agentId);
3746
3580
  if (!agent) return null;
3747
3581
  const messagesIdsInRun = resolvedRunId ? agent.messages.filter((msg) => copilotkit.getRunIdForMessage(agentId, threadId, msg.id) === resolvedRunId).map((msg) => msg.id) : [message.id];
3748
3582
  const rawMessageIndex = agent.messages.findIndex((msg) => msg.id === message.id);
@@ -3773,10 +3607,9 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
3773
3607
  //#endregion
3774
3608
  //#region src/v2/hooks/use-render-activity-message.tsx
3775
3609
  function useRenderActivityMessage() {
3776
- var _config$agentId;
3610
+ var _useCopilotChatConfig, _useCopilotChatConfig2;
3777
3611
  const { copilotkit } = useCopilotKit();
3778
- const config = useCopilotChatConfiguration();
3779
- const agentId = (_config$agentId = config === null || config === void 0 ? void 0 : config.agentId) !== null && _config$agentId !== void 0 ? _config$agentId : _copilotkit_shared.DEFAULT_AGENT_ID;
3612
+ const agentId = (_useCopilotChatConfig = (_useCopilotChatConfig2 = useCopilotChatConfiguration()) === null || _useCopilotChatConfig2 === void 0 ? void 0 : _useCopilotChatConfig2.agentId) !== null && _useCopilotChatConfig !== void 0 ? _useCopilotChatConfig : _copilotkit_shared.DEFAULT_AGENT_ID;
3780
3613
  const renderers = copilotkit.renderActivityMessages;
3781
3614
  const findRenderer = (0, react.useCallback)((activityType) => {
3782
3615
  var _ref, _ref2, _matches$find;
@@ -3785,7 +3618,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
3785
3618
  return (_ref = (_ref2 = (_matches$find = matches.find((candidate) => candidate.agentId === agentId)) !== null && _matches$find !== void 0 ? _matches$find : matches.find((candidate) => candidate.agentId === void 0)) !== null && _ref2 !== void 0 ? _ref2 : renderers.find((candidate) => candidate.activityType === "*")) !== null && _ref !== void 0 ? _ref : null;
3786
3619
  }, [agentId, renderers]);
3787
3620
  const renderActivityMessage = (0, react.useCallback)((message) => {
3788
- var _getThreadClone;
3789
3621
  const renderer = findRenderer(message.activityType);
3790
3622
  if (!renderer) return null;
3791
3623
  const parseResult = renderer.content.safeParse(message.content);
@@ -3794,8 +3626,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
3794
3626
  return null;
3795
3627
  }
3796
3628
  const Component = renderer.render;
3797
- const registryAgent = copilotkit.getAgent(agentId);
3798
- const agent = (_getThreadClone = getThreadClone(registryAgent, config === null || config === void 0 ? void 0 : config.threadId)) !== null && _getThreadClone !== void 0 ? _getThreadClone : registryAgent;
3629
+ const agent = copilotkit.getAgent(agentId);
3799
3630
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Component, {
3800
3631
  activityType: message.activityType,
3801
3632
  content: parseResult.data,
@@ -3804,7 +3635,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
3804
3635
  }, message.id);
3805
3636
  }, [
3806
3637
  agentId,
3807
- config === null || config === void 0 ? void 0 : config.threadId,
3808
3638
  copilotkit,
3809
3639
  findRenderer
3810
3640
  ]);
@@ -4245,6 +4075,120 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
4245
4075
  ]);
4246
4076
  }
4247
4077
 
4078
+ //#endregion
4079
+ //#region src/v2/hooks/use-agent.tsx
4080
+ let UseAgentUpdate = /* @__PURE__ */ function(UseAgentUpdate) {
4081
+ UseAgentUpdate["OnMessagesChanged"] = "OnMessagesChanged";
4082
+ UseAgentUpdate["OnStateChanged"] = "OnStateChanged";
4083
+ UseAgentUpdate["OnRunStatusChanged"] = "OnRunStatusChanged";
4084
+ return UseAgentUpdate;
4085
+ }({});
4086
+ const ALL_UPDATES = [
4087
+ UseAgentUpdate.OnMessagesChanged,
4088
+ UseAgentUpdate.OnStateChanged,
4089
+ UseAgentUpdate.OnRunStatusChanged
4090
+ ];
4091
+ function useAgent({ agentId, updates, throttleMs } = {}) {
4092
+ var _agentId;
4093
+ (_agentId = agentId) !== null && _agentId !== void 0 || (agentId = _copilotkit_shared.DEFAULT_AGENT_ID);
4094
+ const { copilotkit } = useCopilotKit();
4095
+ const providerThrottleMs = copilotkit.defaultThrottleMs;
4096
+ const [, forceUpdate] = (0, react.useReducer)((x) => x + 1, 0);
4097
+ const updateFlags = (0, react.useMemo)(() => updates !== null && updates !== void 0 ? updates : ALL_UPDATES, [JSON.stringify(updates)]);
4098
+ const provisionalAgentCache = (0, react.useRef)(/* @__PURE__ */ new Map());
4099
+ const agent = (0, react.useMemo)(() => {
4100
+ var _copilotkit$agents;
4101
+ const existing = copilotkit.getAgent(agentId);
4102
+ if (existing) {
4103
+ provisionalAgentCache.current.delete(agentId);
4104
+ return existing;
4105
+ }
4106
+ const isRuntimeConfigured = copilotkit.runtimeUrl !== void 0;
4107
+ const status = copilotkit.runtimeConnectionStatus;
4108
+ if (isRuntimeConfigured && (status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Disconnected || status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Connecting)) {
4109
+ const cached = provisionalAgentCache.current.get(agentId);
4110
+ if (cached) {
4111
+ cached.headers = { ...copilotkit.headers };
4112
+ return cached;
4113
+ }
4114
+ const provisional = new _copilotkit_core.ProxiedCopilotRuntimeAgent({
4115
+ runtimeUrl: copilotkit.runtimeUrl,
4116
+ agentId,
4117
+ transport: copilotkit.runtimeTransport,
4118
+ runtimeMode: "pending"
4119
+ });
4120
+ provisional.headers = { ...copilotkit.headers };
4121
+ provisionalAgentCache.current.set(agentId, provisional);
4122
+ return provisional;
4123
+ }
4124
+ if (isRuntimeConfigured && status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Error) {
4125
+ const cached = provisionalAgentCache.current.get(agentId);
4126
+ if (cached) {
4127
+ cached.headers = { ...copilotkit.headers };
4128
+ return cached;
4129
+ }
4130
+ const provisional = new _copilotkit_core.ProxiedCopilotRuntimeAgent({
4131
+ runtimeUrl: copilotkit.runtimeUrl,
4132
+ agentId,
4133
+ transport: copilotkit.runtimeTransport,
4134
+ runtimeMode: "pending"
4135
+ });
4136
+ provisional.headers = { ...copilotkit.headers };
4137
+ provisionalAgentCache.current.set(agentId, provisional);
4138
+ return provisional;
4139
+ }
4140
+ const knownAgents = Object.keys((_copilotkit$agents = copilotkit.agents) !== null && _copilotkit$agents !== void 0 ? _copilotkit$agents : {});
4141
+ const runtimePart = isRuntimeConfigured ? `runtimeUrl=${copilotkit.runtimeUrl}` : "no runtimeUrl";
4142
+ throw new Error(`useAgent: Agent '${agentId}' not found after runtime sync (${runtimePart}). ` + (knownAgents.length ? `Known agents: [${knownAgents.join(", ")}]` : "No agents registered.") + " Verify your runtime /info and/or agents__unsafe_dev_only.");
4143
+ }, [
4144
+ agentId,
4145
+ copilotkit.agents,
4146
+ copilotkit.runtimeConnectionStatus,
4147
+ copilotkit.runtimeUrl,
4148
+ copilotkit.runtimeTransport,
4149
+ JSON.stringify(copilotkit.headers)
4150
+ ]);
4151
+ (0, react.useEffect)(() => {
4152
+ if (updateFlags.length === 0) return;
4153
+ let active = true;
4154
+ const handlers = {};
4155
+ let batchScheduled = false;
4156
+ const batchedForceUpdate = () => {
4157
+ if (!active) return;
4158
+ if (!batchScheduled) {
4159
+ batchScheduled = true;
4160
+ queueMicrotask(() => {
4161
+ batchScheduled = false;
4162
+ if (active) forceUpdate();
4163
+ });
4164
+ }
4165
+ };
4166
+ if (updateFlags.includes(UseAgentUpdate.OnMessagesChanged)) handlers.onMessagesChanged = forceUpdate;
4167
+ if (updateFlags.includes(UseAgentUpdate.OnStateChanged)) handlers.onStateChanged = batchedForceUpdate;
4168
+ if (updateFlags.includes(UseAgentUpdate.OnRunStatusChanged)) {
4169
+ handlers.onRunInitialized = batchedForceUpdate;
4170
+ handlers.onRunFinalized = batchedForceUpdate;
4171
+ handlers.onRunFailed = batchedForceUpdate;
4172
+ handlers.onRunErrorEvent = batchedForceUpdate;
4173
+ }
4174
+ const subscription = copilotkit.subscribeToAgentWithOptions(agent, handlers, { throttleMs });
4175
+ return () => {
4176
+ active = false;
4177
+ subscription.unsubscribe();
4178
+ };
4179
+ }, [
4180
+ agent,
4181
+ forceUpdate,
4182
+ throttleMs,
4183
+ providerThrottleMs,
4184
+ updateFlags
4185
+ ]);
4186
+ (0, react.useEffect)(() => {
4187
+ if (agent instanceof _ag_ui_client.HttpAgent) agent.headers = { ...copilotkit.headers };
4188
+ }, [agent, JSON.stringify(copilotkit.headers)]);
4189
+ return { agent };
4190
+ }
4191
+
4248
4192
  //#endregion
4249
4193
  //#region src/v2/hooks/use-capabilities.tsx
4250
4194
  /**
@@ -4741,6 +4685,16 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
4741
4685
  };
4742
4686
  }, [store]);
4743
4687
  const runtimeStatus = copilotkit.runtimeConnectionStatus;
4688
+ (0, react.useEffect)(() => {
4689
+ copilotkit.registerThreadStore(agentId, store);
4690
+ return () => {
4691
+ copilotkit.unregisterThreadStore(agentId);
4692
+ };
4693
+ }, [
4694
+ copilotkit,
4695
+ agentId,
4696
+ store
4697
+ ]);
4744
4698
  (0, react.useEffect)(() => {
4745
4699
  var _copilotkit$intellige;
4746
4700
  if (!copilotkit.runtimeUrl) {
@@ -4765,7 +4719,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
4765
4719
  headersKey,
4766
4720
  (_copilotkit$intellige2 = copilotkit.intelligence) === null || _copilotkit$intellige2 === void 0 ? void 0 : _copilotkit$intellige2.wsUrl,
4767
4721
  agentId,
4768
- copilotkit.headers,
4769
4722
  includeArchived,
4770
4723
  limit
4771
4724
  ]);
@@ -5744,6 +5697,199 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
5744
5697
  */
5745
5698
  const ScrollElementContext = react.default.createContext(null);
5746
5699
 
5700
+ //#endregion
5701
+ //#region src/v2/components/intelligence-indicator/IntelligenceIndicator.tsx
5702
+ /**
5703
+ * Grace window before showing the spinner. A matching tool call must
5704
+ * remain unresolved (no `tool`-role result message in `agent.messages`)
5705
+ * for at least this long before the pill appears. This filters out
5706
+ * history-replay flashes — during `connectAgent` replay, tool calls and
5707
+ * their results arrive back-to-back in sub-millisecond bursts, so the
5708
+ * timer is cancelled before it fires. Live runs cross the threshold
5709
+ * easily because the tool actually has to execute.
5710
+ */
5711
+ const PENDING_THRESHOLD_MS = 100;
5712
+ /** Hold the checkmark briefly before fading out. */
5713
+ const CHECK_HOLD_MS = 800;
5714
+ /**
5715
+ * Duration of the fade-out animation. Must match
5716
+ * `cpk-intelligence-pill-fade-out` keyframes in `v2/styles/globals.css`.
5717
+ */
5718
+ const FADE_OUT_ANIMATION_MS = 480;
5719
+ /**
5720
+ * Tool-name regex patterns that trigger the indicator. Currently
5721
+ * hardcoded to the Intelligence MCP server's canonical tool name. If
5722
+ * we add per-instance customization later (e.g. a `CopilotKitProvider`
5723
+ * prop or a runtime-info field), this constant becomes the fallback.
5724
+ */
5725
+ const DEFAULT_TOOL_PATTERNS = [/^copilotkit_knowledge_base_shell$/];
5726
+ const isMatchingToolCallName = (name) => typeof name === "string" && DEFAULT_TOOL_PATTERNS.some((p) => p.test(name));
5727
+ /**
5728
+ * "Tool-call-like" messages do NOT count as a real follow-up: tool
5729
+ * result messages, assistant messages that carry tool calls, and
5730
+ * empty-content assistant messages (which some providers emit as a
5731
+ * standalone wrapper around a batch of tool calls). A real follow-up
5732
+ * is anything else — most importantly an assistant message with prose
5733
+ * content, or a fresh user message.
5734
+ */
5735
+ const isToolCallLikeMessage = (m) => {
5736
+ if (m.role === "tool") return true;
5737
+ if (m.role === "assistant") {
5738
+ if ((Array.isArray(m.toolCalls) ? m.toolCalls : []).length > 0) return true;
5739
+ const content = m.content;
5740
+ return typeof content !== "string" || content.trim().length === 0;
5741
+ }
5742
+ return false;
5743
+ };
5744
+ /**
5745
+ * The "Using CopilotKit Intelligence" pill. Auto-mounted by
5746
+ * `CopilotChatMessageView` for every message slot when
5747
+ * `copilotkit.intelligence` is configured — callers do not register
5748
+ * this themselves. Self-gates so only the canonical message renders a
5749
+ * pill.
5750
+ *
5751
+ * Render gates (all must hold):
5752
+ * 1. `copilotkit.intelligence !== undefined`
5753
+ * 2. The message is an assistant message with at least one tool call
5754
+ * whose name matches {@link DEFAULT_TOOL_PATTERNS}
5755
+ * 3. The message is the *latest* such matching-assistant message in
5756
+ * `agent.messages` — tool-result messages and prose-only assistant
5757
+ * messages don't invalidate the slot, so the pill stays
5758
+ * continuously through a multi-step tool chain.
5759
+ * 4. The phase machine is past `idle` (the pending-grace timer fired)
5760
+ * and not yet `hidden`.
5761
+ *
5762
+ * Phase machine (per-instance, all timers local):
5763
+ * - Starts in `idle` — nothing rendered.
5764
+ * - `idle → spinner` once a matching tool call has been pending
5765
+ * (no `tool`-role result with a matching `toolCallId`) for
5766
+ * {@link PENDING_THRESHOLD_MS}. Replay flashes (tool call + result
5767
+ * in the same tick) never cross this threshold.
5768
+ * - `spinner → check` as soon as EITHER `agent.isRunning` flips
5769
+ * false OR a non-tool-call-like message appears later in
5770
+ * `agent.messages` (i.e. the agent has produced a "real"
5771
+ * follow-up — prose answer or a new user turn).
5772
+ * - `check → fading` after {@link CHECK_HOLD_MS}.
5773
+ * - `fading → hidden` after {@link FADE_OUT_ANIMATION_MS}.
5774
+ *
5775
+ * Once `hidden`, the phase is sticky — a finished pill never re-spawns
5776
+ * on the same message. New runs mount fresh indicator instances on
5777
+ * their own assistant messages.
5778
+ *
5779
+ * The "exactly one pill at a time" guarantee is structural: only one
5780
+ * message satisfies the latest-matching-assistant gate at any moment.
5781
+ */
5782
+ function IntelligenceIndicator(props) {
5783
+ const { message, agentId, label = "Using CopilotKit Intelligence" } = props;
5784
+ const { copilotkit } = useCopilotKit();
5785
+ const config = useCopilotChatConfiguration();
5786
+ const { agent } = useAgent({
5787
+ agentId,
5788
+ updates: [UseAgentUpdate.OnRunStatusChanged, UseAgentUpdate.OnMessagesChanged]
5789
+ });
5790
+ const matchingToolCallIds = (0, react.useMemo)(() => {
5791
+ if (message.role !== "assistant") return [];
5792
+ const tcs = Array.isArray(message.toolCalls) ? message.toolCalls : [];
5793
+ const ids = [];
5794
+ for (const tc of tcs) {
5795
+ var _tc$function;
5796
+ if (isMatchingToolCallName(tc === null || tc === void 0 || (_tc$function = tc.function) === null || _tc$function === void 0 ? void 0 : _tc$function.name) && (tc === null || tc === void 0 ? void 0 : tc.id)) ids.push(tc.id);
5797
+ }
5798
+ return ids;
5799
+ }, [message]);
5800
+ const hasPending = (0, react.useMemo)(() => {
5801
+ if (matchingToolCallIds.length === 0) return false;
5802
+ const resolved = /* @__PURE__ */ new Set();
5803
+ for (const m of agent.messages) if (m.role === "tool" && m.toolCallId) resolved.add(m.toolCallId);
5804
+ return matchingToolCallIds.some((id) => !resolved.has(id));
5805
+ }, [matchingToolCallIds, agent.messages]);
5806
+ const sawRealFollowup = (0, react.useMemo)(() => {
5807
+ const idx = agent.messages.findIndex((m) => m.id === message.id);
5808
+ if (idx < 0) return false;
5809
+ for (let i = idx + 1; i < agent.messages.length; i += 1) if (!isToolCallLikeMessage(agent.messages[i])) return true;
5810
+ return false;
5811
+ }, [agent.messages, message.id]);
5812
+ const [phase, setPhase] = (0, react.useState)("idle");
5813
+ (0, react.useEffect)(() => {
5814
+ if (phase !== "idle") return void 0;
5815
+ if (!hasPending) return void 0;
5816
+ const t = setTimeout(() => setPhase("spinner"), PENDING_THRESHOLD_MS);
5817
+ return () => clearTimeout(t);
5818
+ }, [phase, hasPending]);
5819
+ (0, react.useEffect)(() => {
5820
+ if (phase !== "spinner") return void 0;
5821
+ if (!agent.isRunning || sawRealFollowup) setPhase("check");
5822
+ }, [
5823
+ phase,
5824
+ agent.isRunning,
5825
+ sawRealFollowup
5826
+ ]);
5827
+ (0, react.useEffect)(() => {
5828
+ if (phase !== "check") return void 0;
5829
+ const t = setTimeout(() => setPhase("fading"), CHECK_HOLD_MS);
5830
+ return () => clearTimeout(t);
5831
+ }, [phase]);
5832
+ (0, react.useEffect)(() => {
5833
+ if (phase !== "fading") return void 0;
5834
+ const t = setTimeout(() => setPhase("hidden"), FADE_OUT_ANIMATION_MS);
5835
+ return () => clearTimeout(t);
5836
+ }, [phase]);
5837
+ if (copilotkit.intelligence === void 0) return null;
5838
+ if (!config) return null;
5839
+ if (phase === "idle" || phase === "hidden") return null;
5840
+ if (message.role !== "assistant") return null;
5841
+ if (!(Array.isArray(message.toolCalls) ? message.toolCalls : []).some((tc) => {
5842
+ var _tc$function2;
5843
+ return isMatchingToolCallName(tc === null || tc === void 0 || (_tc$function2 = tc.function) === null || _tc$function2 === void 0 ? void 0 : _tc$function2.name);
5844
+ })) return null;
5845
+ let latestMatchingAssistantId;
5846
+ for (let i = agent.messages.length - 1; i >= 0; i -= 1) {
5847
+ const m = agent.messages[i];
5848
+ if (m.role !== "assistant") continue;
5849
+ if ((Array.isArray(m.toolCalls) ? m.toolCalls : []).some((tc) => {
5850
+ var _tc$function3;
5851
+ return isMatchingToolCallName(tc === null || tc === void 0 || (_tc$function3 = tc.function) === null || _tc$function3 === void 0 ? void 0 : _tc$function3.name);
5852
+ })) {
5853
+ latestMatchingAssistantId = m.id;
5854
+ break;
5855
+ }
5856
+ }
5857
+ if (latestMatchingAssistantId !== message.id) return null;
5858
+ const showSpinner = phase === "spinner";
5859
+ const isFading = phase === "fading";
5860
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
5861
+ className: "cpk-intelligence-pill" + (isFading ? " cpk-intelligence-pill--fading" : ""),
5862
+ role: "status",
5863
+ "aria-live": "polite",
5864
+ "aria-hidden": isFading || void 0,
5865
+ "data-testid": `cpk-intelligence-pill-${message.id}`,
5866
+ title: label,
5867
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
5868
+ className: "cpk-intelligence-pill__icon",
5869
+ viewBox: "0 0 24 24",
5870
+ width: "14",
5871
+ height: "14",
5872
+ "aria-hidden": "true",
5873
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
5874
+ cx: "12",
5875
+ cy: "12",
5876
+ r: "9",
5877
+ fill: "none",
5878
+ strokeWidth: "2.5",
5879
+ strokeLinecap: "round",
5880
+ className: "cpk-intelligence-pill__ring" + (showSpinner ? "" : " cpk-intelligence-pill__ring--done")
5881
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
5882
+ d: "M8 12.5l3 3 5-6",
5883
+ fill: "none",
5884
+ strokeWidth: "2.5",
5885
+ strokeLinecap: "round",
5886
+ strokeLinejoin: "round",
5887
+ className: "cpk-intelligence-pill__check" + (showSpinner ? "" : " cpk-intelligence-pill__check--shown")
5888
+ })]
5889
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: label })]
5890
+ });
5891
+ }
5892
+
5747
5893
  //#endregion
5748
5894
  //#region src/v2/components/chat/CopilotChatMessageView.tsx
5749
5895
  /**
@@ -5904,16 +6050,13 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
5904
6050
  const config = useCopilotChatConfiguration();
5905
6051
  const [, forceUpdate] = (0, react.useReducer)((x) => x + 1, 0);
5906
6052
  (0, react.useEffect)(() => {
5907
- var _getThreadClone;
5908
6053
  if (!(config === null || config === void 0 ? void 0 : config.agentId)) return;
5909
- const registryAgent = copilotkit.getAgent(config.agentId);
5910
- const agent = (_getThreadClone = getThreadClone(registryAgent, config.threadId)) !== null && _getThreadClone !== void 0 ? _getThreadClone : registryAgent;
6054
+ const agent = copilotkit.getAgent(config.agentId);
5911
6055
  if (!agent) return;
5912
6056
  const subscription = agent.subscribe({ onStateChanged: forceUpdate });
5913
6057
  return () => subscription.unsubscribe();
5914
6058
  }, [
5915
6059
  config === null || config === void 0 ? void 0 : config.agentId,
5916
- config === null || config === void 0 ? void 0 : config.threadId,
5917
6060
  copilotkit,
5918
6061
  forceUpdate
5919
6062
  ]);
@@ -5999,6 +6142,13 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
5999
6142
  renderCustomMessage,
6000
6143
  stateSnapshot
6001
6144
  }, `${message.id}-custom-after`));
6145
+ if (copilotkit.intelligence !== void 0 && message.role === "assistant") {
6146
+ var _config$agentId;
6147
+ elements.push(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(IntelligenceIndicator, {
6148
+ message,
6149
+ agentId: (_config$agentId = config === null || config === void 0 ? void 0 : config.agentId) !== null && _config$agentId !== void 0 ? _config$agentId : _copilotkit_shared.DEFAULT_AGENT_ID
6150
+ }, `${message.id}-intelligence`));
6151
+ }
6002
6152
  return elements.filter(Boolean);
6003
6153
  };
6004
6154
  const messageElements = shouldVirtualize ? [] : deduplicatedMessages.flatMap(renderMessageBlock);
@@ -6952,7 +7102,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
6952
7102
  const hasExplicitThreadId = !!threadId || !!(existingConfig === null || existingConfig === void 0 ? void 0 : existingConfig.hasExplicitThreadId);
6953
7103
  const { agent } = useAgent({
6954
7104
  agentId: resolvedAgentId,
6955
- threadId: resolvedThreadId,
6956
7105
  throttleMs
6957
7106
  });
6958
7107
  const { copilotkit } = useCopilotKit();
@@ -6998,6 +7147,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
6998
7147
  let detached = false;
6999
7148
  const connectAbortController = new AbortController();
7000
7149
  if (agent instanceof _ag_ui_client.HttpAgent) agent.abortController = connectAbortController;
7150
+ agent.threadId = resolvedThreadId;
7001
7151
  const connect = async (agent) => {
7002
7152
  try {
7003
7153
  await copilotkit.connectAgent({ agent });
@@ -9913,6 +10063,7 @@ Object.defineProperty(exports, 'CopilotSidebarView', {
9913
10063
  return CopilotSidebarView;
9914
10064
  }
9915
10065
  });
10066
+ exports.IntelligenceIndicator = IntelligenceIndicator;
9916
10067
  exports.MCPAppsActivityContentSchema = MCPAppsActivityContentSchema;
9917
10068
  exports.MCPAppsActivityRenderer = MCPAppsActivityRenderer;
9918
10069
  exports.MCPAppsActivityType = MCPAppsActivityType;