@copilotkit/react-core 1.55.0-next.7 → 1.55.0-next.9
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.
- package/CHANGELOG.md +23 -0
- package/dist/{copilotkit-B3Mb1yVE.cjs → copilotkit-BDNjFNmk.cjs} +156 -92
- package/dist/copilotkit-BDNjFNmk.cjs.map +1 -0
- package/dist/{copilotkit-Dy5w3qEV.d.mts → copilotkit-BqcyhQjT.d.mts} +3 -1
- package/dist/{copilotkit-Dy5w3qEV.d.mts.map → copilotkit-BqcyhQjT.d.mts.map} +1 -1
- package/dist/{copilotkit-DNYSFuz5.mjs → copilotkit-DeOzjPsb.mjs} +157 -93
- package/dist/copilotkit-DeOzjPsb.mjs.map +1 -0
- package/dist/{copilotkit-DBzgOMby.d.cts → copilotkit-l-IBF4Xp.d.cts} +3 -1
- package/dist/{copilotkit-DBzgOMby.d.cts.map → copilotkit-l-IBF4Xp.d.cts.map} +1 -1
- package/dist/index.cjs +9 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +9 -4
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +160 -94
- package/dist/index.umd.js.map +1 -1
- package/dist/v2/index.cjs +1 -1
- package/dist/v2/index.d.cts +1 -1
- package/dist/v2/index.d.mts +1 -1
- package/dist/v2/index.mjs +1 -1
- package/dist/v2/index.umd.js +160 -94
- package/dist/v2/index.umd.js.map +1 -1
- package/package.json +6 -6
- package/src/components/copilot-provider/__tests__/copilot-messages-key.test.tsx +92 -0
- package/src/components/copilot-provider/copilotkit.tsx +3 -3
- package/src/hooks/__tests__/use-copilot-chat-internal-connect.test.tsx +27 -16
- package/src/hooks/use-copilot-chat_internal.ts +15 -4
- package/src/v2/__tests__/utils/test-helpers.tsx +40 -7
- package/src/v2/components/chat/CopilotChat.tsx +4 -2
- package/src/v2/components/chat/CopilotChatMessageView.tsx +7 -2
- package/src/v2/components/chat/__tests__/CopilotChatToolRendering.e2e.test.tsx +5 -2
- package/src/v2/components/chat/__tests__/CopilotChatToolRerenders.e2e.test.tsx +5 -2
- package/src/v2/components/chat/__tests__/MCPAppsActivityRenderer.e2e.test.tsx +17 -1
- package/src/v2/hooks/__tests__/use-agent-context-timing.e2e.test.tsx +8 -0
- package/src/v2/hooks/__tests__/use-agent-thread-isolation.test.tsx +327 -0
- package/src/v2/hooks/__tests__/use-agent.e2e.test.tsx +13 -2
- package/src/v2/hooks/__tests__/use-frontend-tool.e2e.test.tsx +23 -4
- package/src/v2/hooks/use-agent.tsx +126 -6
- package/src/v2/hooks/use-render-custom-messages.tsx +6 -1
- package/dist/copilotkit-B3Mb1yVE.cjs.map +0 -1
- package/dist/copilotkit-DNYSFuz5.mjs.map +0 -1
package/dist/v2/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_copilotkit = require('../copilotkit-
|
|
4
|
+
const require_copilotkit = require('../copilotkit-BDNjFNmk.cjs');
|
|
5
5
|
require("./index.css");
|
|
6
6
|
|
|
7
7
|
exports.AudioRecorderError = require_copilotkit.AudioRecorderError;
|
package/dist/v2/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as CopilotSidebar, A as useFrontendTool, At as CopilotChatInputProps, B as useRenderCustomMessages, C as useAgentContext, Ct as CopilotChatUserMessage, D as useDefaultRenderTool, Dt as CopilotChatToolCallsView, E as useHumanInTheLoop, Et as CopilotChatAssistantMessageProps, F as defineToolCallRenderer, Ft as CopilotChatLabels, G as MCPAppsActivityContentSchema, H as ReactCustomMessageRendererPosition, I as ReactHumanInTheLoop, It as useCopilotChatConfiguration, J as CopilotKitInspector, K as MCPAppsActivityRenderer, L as ReactFrontendTool, Lt as AudioRecorderError, M as InterruptEvent, Mt as CopilotChatConfigurationProvider, N as InterruptHandlerProps, Nt as CopilotChatConfigurationProviderProps, O as useRenderTool, Ot as CopilotChatToolCallsViewProps, P as InterruptRenderProps, Pt as CopilotChatConfigurationValue, Q as CopilotPopupProps, R as ReactActivityMessageRenderer, Rt as AudioRecorderState, S as JsonSerializable, St as CopilotChatReasoningMessageProps, T as useAgent, Tt as CopilotChatAssistantMessage, U as useRenderToolCall, V as ReactCustomMessageRenderer, W as MCPAppsActivityContent, X as WildcardToolCallRender, Y as CopilotKitInspectorProps, Z as CopilotPopup, _ as UseInterruptConfig, _t as CopilotChatSuggestionView, a as createA2UIMessageRenderer, at as CopilotModalHeader, b as useSuggestions, bt as CopilotChatSuggestionPillProps, c as CopilotKitProviderProps, ct as CopilotChatToggleButtonProps, d as CopilotKitCoreReactConfig, dt as CopilotChat, et as CopilotSidebarProps, f as CopilotKitCoreReactSubscriber, ft as CopilotChatProps, g as useThreads, gt as CopilotChatMessageViewProps, h as UseThreadsResult, ht as CopilotChatMessageView, i as A2UIMessageRendererOptions, it as CopilotSidebarViewProps, j as useRenderActivityMessage, jt as ToolsMenuItem, k as useComponent, kt as CopilotChatInput, l as useCopilotKit, lt as DefaultCloseIcon, m as UseThreadsInput, mt as CopilotChatViewProps, nt as CopilotPopupViewProps, o as CopilotKitContextValue, ot as CopilotModalHeaderProps, p as Thread, pt as CopilotChatView, q as MCPAppsActivityType, r as CopilotKitProps, rt as CopilotSidebarView, s as CopilotKitProvider, st as CopilotChatToggleButton, t as CopilotKit, tt as CopilotPopupView, u as CopilotKitCoreReact, ut as DefaultOpenIcon, v as useInterrupt, vt as CopilotChatSuggestionViewProps, w as UseAgentUpdate, wt as CopilotChatUserMessageProps, x as AgentContextInput, xt as CopilotChatReasoningMessage, y as useConfigureSuggestions, yt as CopilotChatSuggestionPill, z as ReactToolCallRenderer, zt as CopilotChatAudioRecorder } from "../copilotkit-
|
|
1
|
+
import { $ as CopilotSidebar, A as useFrontendTool, At as CopilotChatInputProps, B as useRenderCustomMessages, C as useAgentContext, Ct as CopilotChatUserMessage, D as useDefaultRenderTool, Dt as CopilotChatToolCallsView, E as useHumanInTheLoop, Et as CopilotChatAssistantMessageProps, F as defineToolCallRenderer, Ft as CopilotChatLabels, G as MCPAppsActivityContentSchema, H as ReactCustomMessageRendererPosition, I as ReactHumanInTheLoop, It as useCopilotChatConfiguration, J as CopilotKitInspector, K as MCPAppsActivityRenderer, L as ReactFrontendTool, Lt as AudioRecorderError, M as InterruptEvent, Mt as CopilotChatConfigurationProvider, N as InterruptHandlerProps, Nt as CopilotChatConfigurationProviderProps, O as useRenderTool, Ot as CopilotChatToolCallsViewProps, P as InterruptRenderProps, Pt as CopilotChatConfigurationValue, Q as CopilotPopupProps, R as ReactActivityMessageRenderer, Rt as AudioRecorderState, S as JsonSerializable, St as CopilotChatReasoningMessageProps, T as useAgent, Tt as CopilotChatAssistantMessage, U as useRenderToolCall, V as ReactCustomMessageRenderer, W as MCPAppsActivityContent, X as WildcardToolCallRender, Y as CopilotKitInspectorProps, Z as CopilotPopup, _ as UseInterruptConfig, _t as CopilotChatSuggestionView, a as createA2UIMessageRenderer, at as CopilotModalHeader, b as useSuggestions, bt as CopilotChatSuggestionPillProps, c as CopilotKitProviderProps, ct as CopilotChatToggleButtonProps, d as CopilotKitCoreReactConfig, dt as CopilotChat, et as CopilotSidebarProps, f as CopilotKitCoreReactSubscriber, ft as CopilotChatProps, g as useThreads, gt as CopilotChatMessageViewProps, h as UseThreadsResult, ht as CopilotChatMessageView, i as A2UIMessageRendererOptions, it as CopilotSidebarViewProps, j as useRenderActivityMessage, jt as ToolsMenuItem, k as useComponent, kt as CopilotChatInput, l as useCopilotKit, lt as DefaultCloseIcon, m as UseThreadsInput, mt as CopilotChatViewProps, nt as CopilotPopupViewProps, o as CopilotKitContextValue, ot as CopilotModalHeaderProps, p as Thread, pt as CopilotChatView, q as MCPAppsActivityType, r as CopilotKitProps, rt as CopilotSidebarView, s as CopilotKitProvider, st as CopilotChatToggleButton, t as CopilotKit, tt as CopilotPopupView, u as CopilotKitCoreReact, ut as DefaultOpenIcon, v as useInterrupt, vt as CopilotChatSuggestionViewProps, w as UseAgentUpdate, wt as CopilotChatUserMessageProps, x as AgentContextInput, xt as CopilotChatReasoningMessage, y as useConfigureSuggestions, yt as CopilotChatSuggestionPill, z as ReactToolCallRenderer, zt as CopilotChatAudioRecorder } from "../copilotkit-l-IBF4Xp.cjs";
|
|
2
2
|
import "./index.css";
|
|
3
3
|
import { Theme as A2UITheme } from "@copilotkit/a2ui-renderer";
|
|
4
4
|
export * from "@copilotkit/core";
|
package/dist/v2/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as CopilotSidebar, A as useFrontendTool, At as CopilotChatInputProps, B as useRenderCustomMessages, C as useAgentContext, Ct as CopilotChatUserMessage, D as useDefaultRenderTool, Dt as CopilotChatToolCallsView, E as useHumanInTheLoop, Et as CopilotChatAssistantMessageProps, F as defineToolCallRenderer, Ft as CopilotChatLabels, G as MCPAppsActivityContentSchema, H as ReactCustomMessageRendererPosition, I as ReactHumanInTheLoop, It as useCopilotChatConfiguration, J as CopilotKitInspector, K as MCPAppsActivityRenderer, L as ReactFrontendTool, Lt as AudioRecorderError, M as InterruptEvent, Mt as CopilotChatConfigurationProvider, N as InterruptHandlerProps, Nt as CopilotChatConfigurationProviderProps, O as useRenderTool, Ot as CopilotChatToolCallsViewProps, P as InterruptRenderProps, Pt as CopilotChatConfigurationValue, Q as CopilotPopupProps, R as ReactActivityMessageRenderer, Rt as AudioRecorderState, S as JsonSerializable, St as CopilotChatReasoningMessageProps, T as useAgent, Tt as CopilotChatAssistantMessage, U as useRenderToolCall, V as ReactCustomMessageRenderer, W as MCPAppsActivityContent, X as WildcardToolCallRender, Y as CopilotKitInspectorProps, Z as CopilotPopup, _ as UseInterruptConfig, _t as CopilotChatSuggestionView, a as createA2UIMessageRenderer, at as CopilotModalHeader, b as useSuggestions, bt as CopilotChatSuggestionPillProps, c as CopilotKitProviderProps, ct as CopilotChatToggleButtonProps, d as CopilotKitCoreReactConfig, dt as CopilotChat, et as CopilotSidebarProps, f as CopilotKitCoreReactSubscriber, ft as CopilotChatProps, g as useThreads, gt as CopilotChatMessageViewProps, h as UseThreadsResult, ht as CopilotChatMessageView, i as A2UIMessageRendererOptions, it as CopilotSidebarViewProps, j as useRenderActivityMessage, jt as ToolsMenuItem, k as useComponent, kt as CopilotChatInput, l as useCopilotKit, lt as DefaultCloseIcon, m as UseThreadsInput, mt as CopilotChatViewProps, nt as CopilotPopupViewProps, o as CopilotKitContextValue, ot as CopilotModalHeaderProps, p as Thread, pt as CopilotChatView, q as MCPAppsActivityType, r as CopilotKitProps, rt as CopilotSidebarView, s as CopilotKitProvider, st as CopilotChatToggleButton, t as CopilotKit, tt as CopilotPopupView, u as CopilotKitCoreReact, ut as DefaultOpenIcon, v as useInterrupt, vt as CopilotChatSuggestionViewProps, w as UseAgentUpdate, wt as CopilotChatUserMessageProps, x as AgentContextInput, xt as CopilotChatReasoningMessage, y as useConfigureSuggestions, yt as CopilotChatSuggestionPill, z as ReactToolCallRenderer, zt as CopilotChatAudioRecorder } from "../copilotkit-
|
|
1
|
+
import { $ as CopilotSidebar, A as useFrontendTool, At as CopilotChatInputProps, B as useRenderCustomMessages, C as useAgentContext, Ct as CopilotChatUserMessage, D as useDefaultRenderTool, Dt as CopilotChatToolCallsView, E as useHumanInTheLoop, Et as CopilotChatAssistantMessageProps, F as defineToolCallRenderer, Ft as CopilotChatLabels, G as MCPAppsActivityContentSchema, H as ReactCustomMessageRendererPosition, I as ReactHumanInTheLoop, It as useCopilotChatConfiguration, J as CopilotKitInspector, K as MCPAppsActivityRenderer, L as ReactFrontendTool, Lt as AudioRecorderError, M as InterruptEvent, Mt as CopilotChatConfigurationProvider, N as InterruptHandlerProps, Nt as CopilotChatConfigurationProviderProps, O as useRenderTool, Ot as CopilotChatToolCallsViewProps, P as InterruptRenderProps, Pt as CopilotChatConfigurationValue, Q as CopilotPopupProps, R as ReactActivityMessageRenderer, Rt as AudioRecorderState, S as JsonSerializable, St as CopilotChatReasoningMessageProps, T as useAgent, Tt as CopilotChatAssistantMessage, U as useRenderToolCall, V as ReactCustomMessageRenderer, W as MCPAppsActivityContent, X as WildcardToolCallRender, Y as CopilotKitInspectorProps, Z as CopilotPopup, _ as UseInterruptConfig, _t as CopilotChatSuggestionView, a as createA2UIMessageRenderer, at as CopilotModalHeader, b as useSuggestions, bt as CopilotChatSuggestionPillProps, c as CopilotKitProviderProps, ct as CopilotChatToggleButtonProps, d as CopilotKitCoreReactConfig, dt as CopilotChat, et as CopilotSidebarProps, f as CopilotKitCoreReactSubscriber, ft as CopilotChatProps, g as useThreads, gt as CopilotChatMessageViewProps, h as UseThreadsResult, ht as CopilotChatMessageView, i as A2UIMessageRendererOptions, it as CopilotSidebarViewProps, j as useRenderActivityMessage, jt as ToolsMenuItem, k as useComponent, kt as CopilotChatInput, l as useCopilotKit, lt as DefaultCloseIcon, m as UseThreadsInput, mt as CopilotChatViewProps, nt as CopilotPopupViewProps, o as CopilotKitContextValue, ot as CopilotModalHeaderProps, p as Thread, pt as CopilotChatView, q as MCPAppsActivityType, r as CopilotKitProps, rt as CopilotSidebarView, s as CopilotKitProvider, st as CopilotChatToggleButton, t as CopilotKit, tt as CopilotPopupView, u as CopilotKitCoreReact, ut as DefaultOpenIcon, v as useInterrupt, vt as CopilotChatSuggestionViewProps, w as UseAgentUpdate, wt as CopilotChatUserMessageProps, x as AgentContextInput, xt as CopilotChatReasoningMessage, y as useConfigureSuggestions, yt as CopilotChatSuggestionPill, z as ReactToolCallRenderer, zt as CopilotChatAudioRecorder } from "../copilotkit-BqcyhQjT.mjs";
|
|
2
2
|
import "./index.css";
|
|
3
3
|
import { Theme as A2UITheme } from "@copilotkit/a2ui-renderer";
|
|
4
4
|
export * from "@copilotkit/core";
|
package/dist/v2/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { $ as CopilotKitCoreReact, A as CopilotChatSuggestionPill, B as
|
|
3
|
+
import { $ as CopilotKitCoreReact, A as CopilotChatSuggestionPill, B as useHumanInTheLoop, C as CopilotChatToggleButton, D as CopilotChatView_default, E as CopilotChat, F as useThreads, G as useFrontendTool, H as useRenderTool, I as useInterrupt, J as UseAgentUpdate, K as useRenderActivityMessage, L as useConfigureSuggestions, M as CopilotChatUserMessage_default, N as CopilotChatAssistantMessage_default, O as CopilotChatMessageView, P as CopilotChatToolCallsView, Q as useCopilotKit, R as useSuggestions, S as CopilotModalHeader, T as DefaultOpenIcon, U as defineToolCallRenderer, V as useDefaultRenderTool, W as useComponent, X as useRenderToolCall, Y as useAgent, Z as CopilotKitProvider, _ as WildcardToolCallRender, at as CopilotChatInput_default, b as CopilotPopupView, ct as CopilotChatConfigurationProvider, et as createA2UIMessageRenderer, it as CopilotKitInspector, j as CopilotChatReasoningMessage_default, k as CopilotChatSuggestionView, lt as useCopilotChatConfiguration, nt as MCPAppsActivityRenderer, ot as AudioRecorderError, q as useRenderCustomMessages, rt as MCPAppsActivityType, st as CopilotChatAudioRecorder, t as CopilotKit, tt as MCPAppsActivityContentSchema, v as CopilotPopup, w as DefaultCloseIcon, x as CopilotSidebarView, y as CopilotSidebar, z as useAgentContext } from "../copilotkit-DeOzjPsb.mjs";
|
|
4
4
|
import "./index.css";
|
|
5
5
|
|
|
6
6
|
export * from "@copilotkit/core"
|
package/dist/v2/index.umd.js
CHANGED
|
@@ -2514,6 +2514,154 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2514
2514
|
]);
|
|
2515
2515
|
}
|
|
2516
2516
|
|
|
2517
|
+
//#endregion
|
|
2518
|
+
//#region src/v2/hooks/use-agent.tsx
|
|
2519
|
+
let UseAgentUpdate = /* @__PURE__ */ function(UseAgentUpdate) {
|
|
2520
|
+
UseAgentUpdate["OnMessagesChanged"] = "OnMessagesChanged";
|
|
2521
|
+
UseAgentUpdate["OnStateChanged"] = "OnStateChanged";
|
|
2522
|
+
UseAgentUpdate["OnRunStatusChanged"] = "OnRunStatusChanged";
|
|
2523
|
+
return UseAgentUpdate;
|
|
2524
|
+
}({});
|
|
2525
|
+
const ALL_UPDATES = [
|
|
2526
|
+
UseAgentUpdate.OnMessagesChanged,
|
|
2527
|
+
UseAgentUpdate.OnStateChanged,
|
|
2528
|
+
UseAgentUpdate.OnRunStatusChanged
|
|
2529
|
+
];
|
|
2530
|
+
/**
|
|
2531
|
+
* Clone a registry agent for per-thread isolation.
|
|
2532
|
+
* Copies agent configuration (transport, headers, etc.) but resets conversation
|
|
2533
|
+
* state (messages, threadId, state) so each thread starts fresh.
|
|
2534
|
+
*/
|
|
2535
|
+
function cloneForThread(source, threadId, headers) {
|
|
2536
|
+
const clone = source.clone();
|
|
2537
|
+
if (clone === source) throw new Error(`useAgent: ${source.constructor.name}.clone() returned the same instance. clone() must return a new, independent object.`);
|
|
2538
|
+
clone.threadId = threadId;
|
|
2539
|
+
clone.setMessages([]);
|
|
2540
|
+
clone.setState({});
|
|
2541
|
+
if (clone instanceof _ag_ui_client.HttpAgent) clone.headers = { ...headers };
|
|
2542
|
+
return clone;
|
|
2543
|
+
}
|
|
2544
|
+
/**
|
|
2545
|
+
* Module-level WeakMap: registryAgent → (threadId → clone).
|
|
2546
|
+
* Shared across all useAgent() calls so that every component using the same
|
|
2547
|
+
* (agentId, threadId) pair receives the same agent instance. Using WeakMap
|
|
2548
|
+
* ensures the clone map is garbage-collected when the registry agent is
|
|
2549
|
+
* replaced (e.g. after reconnect or hot-reload).
|
|
2550
|
+
*/
|
|
2551
|
+
const globalThreadCloneMap = /* @__PURE__ */ new WeakMap();
|
|
2552
|
+
/**
|
|
2553
|
+
* Look up an existing per-thread clone without creating one.
|
|
2554
|
+
* Returns undefined when no clone has been created yet for this pair.
|
|
2555
|
+
*/
|
|
2556
|
+
function getThreadClone(registryAgent, threadId) {
|
|
2557
|
+
var _globalThreadCloneMap;
|
|
2558
|
+
if (!registryAgent || !threadId) return void 0;
|
|
2559
|
+
return (_globalThreadCloneMap = globalThreadCloneMap.get(registryAgent)) === null || _globalThreadCloneMap === void 0 ? void 0 : _globalThreadCloneMap.get(threadId);
|
|
2560
|
+
}
|
|
2561
|
+
function getOrCreateThreadClone(existing, threadId, headers) {
|
|
2562
|
+
let byThread = globalThreadCloneMap.get(existing);
|
|
2563
|
+
if (!byThread) {
|
|
2564
|
+
byThread = /* @__PURE__ */ new Map();
|
|
2565
|
+
globalThreadCloneMap.set(existing, byThread);
|
|
2566
|
+
}
|
|
2567
|
+
const cached = byThread.get(threadId);
|
|
2568
|
+
if (cached) return cached;
|
|
2569
|
+
const clone = cloneForThread(existing, threadId, headers);
|
|
2570
|
+
byThread.set(threadId, clone);
|
|
2571
|
+
return clone;
|
|
2572
|
+
}
|
|
2573
|
+
function useAgent({ agentId, threadId, updates } = {}) {
|
|
2574
|
+
var _agentId, _threadId;
|
|
2575
|
+
(_agentId = agentId) !== null && _agentId !== void 0 || (agentId = _copilotkit_shared.DEFAULT_AGENT_ID);
|
|
2576
|
+
const { copilotkit } = useCopilotKit();
|
|
2577
|
+
const chatConfig = useCopilotChatConfiguration();
|
|
2578
|
+
(_threadId = threadId) !== null && _threadId !== void 0 || (threadId = chatConfig === null || chatConfig === void 0 ? void 0 : chatConfig.threadId);
|
|
2579
|
+
const [, forceUpdate] = (0, react.useReducer)((x) => x + 1, 0);
|
|
2580
|
+
const updateFlags = (0, react.useMemo)(() => updates !== null && updates !== void 0 ? updates : ALL_UPDATES, [JSON.stringify(updates)]);
|
|
2581
|
+
const provisionalAgentCache = (0, react.useRef)(/* @__PURE__ */ new Map());
|
|
2582
|
+
const agent = (0, react.useMemo)(() => {
|
|
2583
|
+
var _copilotkit$agents;
|
|
2584
|
+
const cacheKey = threadId ? `${agentId}:${threadId}` : agentId;
|
|
2585
|
+
const existing = copilotkit.getAgent(agentId);
|
|
2586
|
+
if (existing) {
|
|
2587
|
+
provisionalAgentCache.current.delete(cacheKey);
|
|
2588
|
+
provisionalAgentCache.current.delete(agentId);
|
|
2589
|
+
if (!threadId) return existing;
|
|
2590
|
+
return getOrCreateThreadClone(existing, threadId, copilotkit.headers);
|
|
2591
|
+
}
|
|
2592
|
+
const isRuntimeConfigured = copilotkit.runtimeUrl !== void 0;
|
|
2593
|
+
const status = copilotkit.runtimeConnectionStatus;
|
|
2594
|
+
if (isRuntimeConfigured && (status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Disconnected || status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Connecting)) {
|
|
2595
|
+
const cached = provisionalAgentCache.current.get(cacheKey);
|
|
2596
|
+
if (cached) {
|
|
2597
|
+
cached.headers = { ...copilotkit.headers };
|
|
2598
|
+
return cached;
|
|
2599
|
+
}
|
|
2600
|
+
const provisional = new _copilotkit_core.ProxiedCopilotRuntimeAgent({
|
|
2601
|
+
runtimeUrl: copilotkit.runtimeUrl,
|
|
2602
|
+
agentId,
|
|
2603
|
+
transport: copilotkit.runtimeTransport,
|
|
2604
|
+
runtimeMode: "pending"
|
|
2605
|
+
});
|
|
2606
|
+
provisional.headers = { ...copilotkit.headers };
|
|
2607
|
+
if (threadId) provisional.threadId = threadId;
|
|
2608
|
+
provisionalAgentCache.current.set(cacheKey, provisional);
|
|
2609
|
+
return provisional;
|
|
2610
|
+
}
|
|
2611
|
+
if (isRuntimeConfigured && status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Error) {
|
|
2612
|
+
const cached = provisionalAgentCache.current.get(cacheKey);
|
|
2613
|
+
if (cached) {
|
|
2614
|
+
cached.headers = { ...copilotkit.headers };
|
|
2615
|
+
return cached;
|
|
2616
|
+
}
|
|
2617
|
+
const provisional = new _copilotkit_core.ProxiedCopilotRuntimeAgent({
|
|
2618
|
+
runtimeUrl: copilotkit.runtimeUrl,
|
|
2619
|
+
agentId,
|
|
2620
|
+
transport: copilotkit.runtimeTransport,
|
|
2621
|
+
runtimeMode: "pending"
|
|
2622
|
+
});
|
|
2623
|
+
provisional.headers = { ...copilotkit.headers };
|
|
2624
|
+
if (threadId) provisional.threadId = threadId;
|
|
2625
|
+
provisionalAgentCache.current.set(cacheKey, provisional);
|
|
2626
|
+
return provisional;
|
|
2627
|
+
}
|
|
2628
|
+
const knownAgents = Object.keys((_copilotkit$agents = copilotkit.agents) !== null && _copilotkit$agents !== void 0 ? _copilotkit$agents : {});
|
|
2629
|
+
const runtimePart = isRuntimeConfigured ? `runtimeUrl=${copilotkit.runtimeUrl}` : "no runtimeUrl";
|
|
2630
|
+
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.");
|
|
2631
|
+
}, [
|
|
2632
|
+
agentId,
|
|
2633
|
+
threadId,
|
|
2634
|
+
copilotkit.agents,
|
|
2635
|
+
copilotkit.runtimeConnectionStatus,
|
|
2636
|
+
copilotkit.runtimeUrl,
|
|
2637
|
+
copilotkit.runtimeTransport,
|
|
2638
|
+
JSON.stringify(copilotkit.headers)
|
|
2639
|
+
]);
|
|
2640
|
+
(0, react.useEffect)(() => {
|
|
2641
|
+
if (updateFlags.length === 0) return;
|
|
2642
|
+
const handlers = {};
|
|
2643
|
+
if (updateFlags.includes(UseAgentUpdate.OnMessagesChanged)) handlers.onMessagesChanged = () => {
|
|
2644
|
+
forceUpdate();
|
|
2645
|
+
};
|
|
2646
|
+
if (updateFlags.includes(UseAgentUpdate.OnStateChanged)) handlers.onStateChanged = forceUpdate;
|
|
2647
|
+
if (updateFlags.includes(UseAgentUpdate.OnRunStatusChanged)) {
|
|
2648
|
+
handlers.onRunInitialized = forceUpdate;
|
|
2649
|
+
handlers.onRunFinalized = forceUpdate;
|
|
2650
|
+
handlers.onRunFailed = forceUpdate;
|
|
2651
|
+
}
|
|
2652
|
+
const subscription = agent.subscribe(handlers);
|
|
2653
|
+
return () => subscription.unsubscribe();
|
|
2654
|
+
}, [
|
|
2655
|
+
agent,
|
|
2656
|
+
forceUpdate,
|
|
2657
|
+
JSON.stringify(updateFlags)
|
|
2658
|
+
]);
|
|
2659
|
+
(0, react.useEffect)(() => {
|
|
2660
|
+
if (agent instanceof _ag_ui_client.HttpAgent) agent.headers = { ...copilotkit.headers };
|
|
2661
|
+
}, [agent, JSON.stringify(copilotkit.headers)]);
|
|
2662
|
+
return { agent };
|
|
2663
|
+
}
|
|
2664
|
+
|
|
2517
2665
|
//#endregion
|
|
2518
2666
|
//#region src/v2/hooks/use-render-custom-messages.tsx
|
|
2519
2667
|
function useRenderCustomMessages() {
|
|
@@ -2527,12 +2675,13 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
2527
2675
|
return aHasAgent ? -1 : 1;
|
|
2528
2676
|
});
|
|
2529
2677
|
return function(params) {
|
|
2530
|
-
var _copilotkit$getRunIdF;
|
|
2678
|
+
var _copilotkit$getRunIdF, _getThreadClone;
|
|
2531
2679
|
if (!customMessageRenderers.length) return null;
|
|
2532
2680
|
const { message, position } = params;
|
|
2533
2681
|
const resolvedRunId = (_copilotkit$getRunIdF = copilotkit.getRunIdForMessage(agentId, threadId, message.id)) !== null && _copilotkit$getRunIdF !== void 0 ? _copilotkit$getRunIdF : copilotkit.getRunIdsForThread(agentId, threadId).slice(-1)[0];
|
|
2534
2682
|
const runId = resolvedRunId !== null && resolvedRunId !== void 0 ? resolvedRunId : `missing-run-id:${message.id}`;
|
|
2535
|
-
const
|
|
2683
|
+
const registryAgent = copilotkit.getAgent(agentId);
|
|
2684
|
+
const agent = (_getThreadClone = getThreadClone(registryAgent, threadId)) !== null && _getThreadClone !== void 0 ? _getThreadClone : registryAgent;
|
|
2536
2685
|
if (!agent) throw new Error("Agent not found");
|
|
2537
2686
|
const messagesIdsInRun = resolvedRunId ? agent.messages.filter((msg) => copilotkit.getRunIdForMessage(agentId, threadId, msg.id) === resolvedRunId).map((msg) => msg.id) : [message.id];
|
|
2538
2687
|
const rawMessageIndex = agent.messages.findIndex((msg) => msg.id === message.id);
|
|
@@ -3044,94 +3193,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
3044
3193
|
]);
|
|
3045
3194
|
}
|
|
3046
3195
|
|
|
3047
|
-
//#endregion
|
|
3048
|
-
//#region src/v2/hooks/use-agent.tsx
|
|
3049
|
-
let UseAgentUpdate = /* @__PURE__ */ function(UseAgentUpdate) {
|
|
3050
|
-
UseAgentUpdate["OnMessagesChanged"] = "OnMessagesChanged";
|
|
3051
|
-
UseAgentUpdate["OnStateChanged"] = "OnStateChanged";
|
|
3052
|
-
UseAgentUpdate["OnRunStatusChanged"] = "OnRunStatusChanged";
|
|
3053
|
-
return UseAgentUpdate;
|
|
3054
|
-
}({});
|
|
3055
|
-
const ALL_UPDATES = [
|
|
3056
|
-
UseAgentUpdate.OnMessagesChanged,
|
|
3057
|
-
UseAgentUpdate.OnStateChanged,
|
|
3058
|
-
UseAgentUpdate.OnRunStatusChanged
|
|
3059
|
-
];
|
|
3060
|
-
function useAgent({ agentId, updates } = {}) {
|
|
3061
|
-
var _agentId;
|
|
3062
|
-
(_agentId = agentId) !== null && _agentId !== void 0 || (agentId = _copilotkit_shared.DEFAULT_AGENT_ID);
|
|
3063
|
-
const { copilotkit } = useCopilotKit();
|
|
3064
|
-
const [, forceUpdate] = (0, react.useReducer)((x) => x + 1, 0);
|
|
3065
|
-
const updateFlags = (0, react.useMemo)(() => updates !== null && updates !== void 0 ? updates : ALL_UPDATES, [JSON.stringify(updates)]);
|
|
3066
|
-
const provisionalAgentCache = (0, react.useRef)(/* @__PURE__ */ new Map());
|
|
3067
|
-
const agent = (0, react.useMemo)(() => {
|
|
3068
|
-
var _copilotkit$agents;
|
|
3069
|
-
const existing = copilotkit.getAgent(agentId);
|
|
3070
|
-
if (existing) {
|
|
3071
|
-
provisionalAgentCache.current.delete(agentId);
|
|
3072
|
-
return existing;
|
|
3073
|
-
}
|
|
3074
|
-
const isRuntimeConfigured = copilotkit.runtimeUrl !== void 0;
|
|
3075
|
-
const status = copilotkit.runtimeConnectionStatus;
|
|
3076
|
-
if (isRuntimeConfigured && (status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Disconnected || status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Connecting)) {
|
|
3077
|
-
const cached = provisionalAgentCache.current.get(agentId);
|
|
3078
|
-
if (cached) {
|
|
3079
|
-
cached.headers = { ...copilotkit.headers };
|
|
3080
|
-
return cached;
|
|
3081
|
-
}
|
|
3082
|
-
const provisional = new _copilotkit_core.ProxiedCopilotRuntimeAgent({
|
|
3083
|
-
runtimeUrl: copilotkit.runtimeUrl,
|
|
3084
|
-
agentId,
|
|
3085
|
-
transport: copilotkit.runtimeTransport,
|
|
3086
|
-
runtimeMode: "pending"
|
|
3087
|
-
});
|
|
3088
|
-
provisional.headers = { ...copilotkit.headers };
|
|
3089
|
-
provisionalAgentCache.current.set(agentId, provisional);
|
|
3090
|
-
return provisional;
|
|
3091
|
-
}
|
|
3092
|
-
if (isRuntimeConfigured && status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Error) {
|
|
3093
|
-
const provisional = new _copilotkit_core.ProxiedCopilotRuntimeAgent({
|
|
3094
|
-
runtimeUrl: copilotkit.runtimeUrl,
|
|
3095
|
-
agentId,
|
|
3096
|
-
transport: copilotkit.runtimeTransport,
|
|
3097
|
-
runtimeMode: "pending"
|
|
3098
|
-
});
|
|
3099
|
-
provisional.headers = { ...copilotkit.headers };
|
|
3100
|
-
return provisional;
|
|
3101
|
-
}
|
|
3102
|
-
const knownAgents = Object.keys((_copilotkit$agents = copilotkit.agents) !== null && _copilotkit$agents !== void 0 ? _copilotkit$agents : {});
|
|
3103
|
-
const runtimePart = isRuntimeConfigured ? `runtimeUrl=${copilotkit.runtimeUrl}` : "no runtimeUrl";
|
|
3104
|
-
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.");
|
|
3105
|
-
}, [
|
|
3106
|
-
agentId,
|
|
3107
|
-
copilotkit.agents,
|
|
3108
|
-
copilotkit.runtimeConnectionStatus,
|
|
3109
|
-
copilotkit.runtimeUrl,
|
|
3110
|
-
copilotkit.runtimeTransport,
|
|
3111
|
-
JSON.stringify(copilotkit.headers)
|
|
3112
|
-
]);
|
|
3113
|
-
(0, react.useEffect)(() => {
|
|
3114
|
-
if (updateFlags.length === 0) return;
|
|
3115
|
-
const handlers = {};
|
|
3116
|
-
if (updateFlags.includes(UseAgentUpdate.OnMessagesChanged)) handlers.onMessagesChanged = () => {
|
|
3117
|
-
forceUpdate();
|
|
3118
|
-
};
|
|
3119
|
-
if (updateFlags.includes(UseAgentUpdate.OnStateChanged)) handlers.onStateChanged = forceUpdate;
|
|
3120
|
-
if (updateFlags.includes(UseAgentUpdate.OnRunStatusChanged)) {
|
|
3121
|
-
handlers.onRunInitialized = forceUpdate;
|
|
3122
|
-
handlers.onRunFinalized = forceUpdate;
|
|
3123
|
-
handlers.onRunFailed = forceUpdate;
|
|
3124
|
-
}
|
|
3125
|
-
const subscription = agent.subscribe(handlers);
|
|
3126
|
-
return () => subscription.unsubscribe();
|
|
3127
|
-
}, [
|
|
3128
|
-
agent,
|
|
3129
|
-
forceUpdate,
|
|
3130
|
-
JSON.stringify(updateFlags)
|
|
3131
|
-
]);
|
|
3132
|
-
return { agent };
|
|
3133
|
-
}
|
|
3134
|
-
|
|
3135
3196
|
//#endregion
|
|
3136
3197
|
//#region src/v2/hooks/use-agent-context.tsx
|
|
3137
3198
|
function useAgentContext(context) {
|
|
@@ -4330,13 +4391,16 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4330
4391
|
const config = useCopilotChatConfiguration();
|
|
4331
4392
|
const [, forceUpdate] = (0, react.useReducer)((x) => x + 1, 0);
|
|
4332
4393
|
(0, react.useEffect)(() => {
|
|
4394
|
+
var _getThreadClone;
|
|
4333
4395
|
if (!(config === null || config === void 0 ? void 0 : config.agentId)) return;
|
|
4334
|
-
const
|
|
4396
|
+
const registryAgent = copilotkit.getAgent(config.agentId);
|
|
4397
|
+
const agent = (_getThreadClone = getThreadClone(registryAgent, config.threadId)) !== null && _getThreadClone !== void 0 ? _getThreadClone : registryAgent;
|
|
4335
4398
|
if (!agent) return;
|
|
4336
4399
|
const subscription = agent.subscribe({ onStateChanged: forceUpdate });
|
|
4337
4400
|
return () => subscription.unsubscribe();
|
|
4338
4401
|
}, [
|
|
4339
4402
|
config === null || config === void 0 ? void 0 : config.agentId,
|
|
4403
|
+
config === null || config === void 0 ? void 0 : config.threadId,
|
|
4340
4404
|
copilotkit,
|
|
4341
4405
|
forceUpdate
|
|
4342
4406
|
]);
|
|
@@ -4895,7 +4959,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4895
4959
|
var _ref2;
|
|
4896
4960
|
return (_ref2 = threadId !== null && threadId !== void 0 ? threadId : existingConfig === null || existingConfig === void 0 ? void 0 : existingConfig.threadId) !== null && _ref2 !== void 0 ? _ref2 : (0, _copilotkit_shared.randomUUID)();
|
|
4897
4961
|
}, [threadId, existingConfig === null || existingConfig === void 0 ? void 0 : existingConfig.threadId]);
|
|
4898
|
-
const { agent } = useAgent({
|
|
4962
|
+
const { agent } = useAgent({
|
|
4963
|
+
agentId: resolvedAgentId,
|
|
4964
|
+
threadId: resolvedThreadId
|
|
4965
|
+
});
|
|
4899
4966
|
const { copilotkit } = useCopilotKit();
|
|
4900
4967
|
const { suggestions: autoSuggestions } = useSuggestions({ agentId: resolvedAgentId });
|
|
4901
4968
|
const { checkFeature } = useLicenseContext();
|
|
@@ -4943,7 +5010,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
4943
5010
|
console.error("CopilotChat: connectAgent failed", error);
|
|
4944
5011
|
}
|
|
4945
5012
|
};
|
|
4946
|
-
agent.threadId = resolvedThreadId;
|
|
4947
5013
|
connect(agent);
|
|
4948
5014
|
return () => {
|
|
4949
5015
|
detached = true;
|
|
@@ -7566,7 +7632,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
|
|
|
7566
7632
|
children: [
|
|
7567
7633
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotListeners, {}),
|
|
7568
7634
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitErrorBridge, {}),
|
|
7569
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(CoAgentStateRendersProvider, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(MessagesTapProvider, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(CopilotMessages, { children: [memoizedChildren, /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RegisteredActionsRenderer, {})] }) }), bannerError && showDevConsole && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(UsageBanner, {
|
|
7635
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(CoAgentStateRendersProvider, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(MessagesTapProvider, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(CopilotMessages, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.default.Fragment, { children: memoizedChildren }, "children"), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RegisteredActionsRenderer, {}, "actions")] }) }), bannerError && showDevConsole && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(UsageBanner, {
|
|
7570
7636
|
severity: bannerError.severity,
|
|
7571
7637
|
message: bannerError.message,
|
|
7572
7638
|
onClose: () => setBannerError(null),
|