@copilotkit/react-core 1.64.0 → 1.64.2-canary.1785346263

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.
@@ -2116,6 +2116,8 @@ const MCPAppsActivityRenderer = function MCPAppsActivityRenderer({ content, agen
2116
2116
  iframe.style.backgroundColor = "transparent";
2117
2117
  iframe.style.display = "block";
2118
2118
  iframe.setAttribute("sandbox", "allow-scripts allow-same-origin allow-forms");
2119
+ iframe.setAttribute("data-testid", "mcp-app-iframe");
2120
+ iframe.setAttribute("title", "Interactive MCP application");
2119
2121
  const sandboxReady = new Promise((resolve) => {
2120
2122
  initialListener = (event) => {
2121
2123
  if (event.source === iframe.contentWindow) {
@@ -4422,7 +4424,10 @@ const ALL_UPDATES = [
4422
4424
  UseAgentUpdate.OnStateChanged,
4423
4425
  UseAgentUpdate.OnRunStatusChanged
4424
4426
  ];
4425
- function useAgent({ agentId, updates, throttleMs } = {}) {
4427
+ function useAgent({ agentId, threadId, runtimeAgentId, updates, throttleMs } = {}) {
4428
+ if (threadId != null && runtimeAgentId == null) throw new Error(`useAgent: \`threadId\` requires \`runtimeAgentId\`. A threadId is written onto a single agent, but an agent resolved by agentId alone is shared, so scoping a thread to it would clobber other useAgent callers. Pass a distinct local \`agentId\` and the runtime agent to route to, e.g. useAgent({ agentId: "chat-1", runtimeAgentId: "${agentId ?? "default"}", threadId }).`);
4429
+ 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}" }).`);
4430
+ 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 }).`);
4426
4431
  const chatConfig = useCopilotChatConfiguration();
4427
4432
  const resolvedAgentId = agentId ?? chatConfig?.agentId ?? _copilotkit_shared.DEFAULT_AGENT_ID;
4428
4433
  const { copilotkit } = useCopilotKit();
@@ -4430,7 +4435,58 @@ function useAgent({ agentId, updates, throttleMs } = {}) {
4430
4435
  const [, forceUpdate] = (0, react.useReducer)((x) => x + 1, 0);
4431
4436
  const updateFlags = (0, react.useMemo)(() => updates ?? ALL_UPDATES, [JSON.stringify(updates)]);
4432
4437
  const provisionalAgentCache = (0, react.useRef)(/* @__PURE__ */ new Map());
4438
+ const [registeredProxyAgent, setRegisteredProxyAgent] = (0, react.useState)(null);
4439
+ (0, react.useEffect)(() => {
4440
+ if (runtimeAgentId == null) {
4441
+ setRegisteredProxyAgent(null);
4442
+ return;
4443
+ }
4444
+ const { agent: proxy, unregister } = copilotkit.registerProxiedAgent({
4445
+ agentId: resolvedAgentId,
4446
+ runtimeAgentId
4447
+ });
4448
+ provisionalAgentCache.current.delete(resolvedAgentId);
4449
+ setRegisteredProxyAgent(proxy);
4450
+ return () => {
4451
+ unregister();
4452
+ setRegisteredProxyAgent(null);
4453
+ };
4454
+ }, [
4455
+ copilotkit,
4456
+ resolvedAgentId,
4457
+ runtimeAgentId
4458
+ ]);
4433
4459
  const { agent, isReady } = (0, react.useMemo)(() => {
4460
+ if (runtimeAgentId != null) {
4461
+ if (registeredProxyAgent) {
4462
+ provisionalAgentCache.current.delete(resolvedAgentId);
4463
+ return {
4464
+ agent: registeredProxyAgent,
4465
+ isReady: true
4466
+ };
4467
+ }
4468
+ const cached = provisionalAgentCache.current.get(resolvedAgentId);
4469
+ if (cached) {
4470
+ copilotkit.applyHeadersToAgent(cached);
4471
+ return {
4472
+ agent: cached,
4473
+ isReady: false
4474
+ };
4475
+ }
4476
+ const provisional = new _copilotkit_core.ProxiedCopilotRuntimeAgent({
4477
+ runtimeUrl: copilotkit.runtimeUrl,
4478
+ agentId: resolvedAgentId,
4479
+ runtimeAgentId,
4480
+ transport: copilotkit.runtimeTransport,
4481
+ runtimeMode: "pending"
4482
+ });
4483
+ copilotkit.applyHeadersToAgent(provisional);
4484
+ provisionalAgentCache.current.set(resolvedAgentId, provisional);
4485
+ return {
4486
+ agent: provisional,
4487
+ isReady: false
4488
+ };
4489
+ }
4434
4490
  const existing = copilotkit.getAgent(resolvedAgentId);
4435
4491
  if (existing) {
4436
4492
  provisionalAgentCache.current.delete(resolvedAgentId);
@@ -4486,6 +4542,8 @@ function useAgent({ agentId, updates, throttleMs } = {}) {
4486
4542
  throw new Error(`useAgent: Agent '${resolvedAgentId}' 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.");
4487
4543
  }, [
4488
4544
  resolvedAgentId,
4545
+ runtimeAgentId,
4546
+ registeredProxyAgent,
4489
4547
  copilotkit.agents,
4490
4548
  copilotkit.runtimeConnectionStatus,
4491
4549
  copilotkit.runtimeUrl,
@@ -4538,14 +4596,11 @@ function useAgent({ agentId, updates, throttleMs } = {}) {
4538
4596
  ]);
4539
4597
  const configThreadId = chatConfig?.threadId;
4540
4598
  const configHasExplicitThreadId = chatConfig?.hasExplicitThreadId;
4599
+ const resolvedThreadId = threadId ?? (configHasExplicitThreadId ? configThreadId : void 0);
4541
4600
  (0, react.useEffect)(() => {
4542
- if (!configHasExplicitThreadId || !configThreadId) return;
4543
- agent.threadId = configThreadId;
4544
- }, [
4545
- agent,
4546
- configThreadId,
4547
- configHasExplicitThreadId
4548
- ]);
4601
+ if (!resolvedThreadId) return;
4602
+ agent.threadId = resolvedThreadId;
4603
+ }, [agent, resolvedThreadId]);
4549
4604
  return {
4550
4605
  agent,
4551
4606
  isReady
@@ -12189,4 +12244,4 @@ Object.defineProperty(exports, 'ɵrunMcpFollowUp', {
12189
12244
  return ɵrunMcpFollowUp;
12190
12245
  }
12191
12246
  });
12192
- //# sourceMappingURL=copilotkit-DiLTL1ZM.cjs.map
12247
+ //# sourceMappingURL=copilotkit-BrNiD3wI.cjs.map