@copilotkit/react-core 1.50.0-beta.1 → 1.50.0-beta.10
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 +93 -0
- package/dist/{chunk-UJBV5GAG.mjs → chunk-3775VM7Y.mjs} +32 -65
- package/dist/chunk-3775VM7Y.mjs.map +1 -0
- package/dist/{chunk-3GURHDG7.mjs → chunk-4HRUQH6U.mjs} +3 -3
- package/dist/{chunk-7BYHZLPL.mjs → chunk-4RRMC7L2.mjs} +4 -4
- package/dist/chunk-4RRMC7L2.mjs.map +1 -0
- package/dist/{chunk-D3QSYDJR.mjs → chunk-7IBF6RBW.mjs} +2 -2
- package/dist/{chunk-GMI4KO4X.mjs → chunk-7SHWECGN.mjs} +2 -2
- package/dist/{chunk-OVYFRPSN.mjs → chunk-ABWT4DRT.mjs} +2 -2
- package/dist/{chunk-WVLHXIFP.mjs → chunk-AFNWX62Q.mjs} +2 -2
- package/dist/{chunk-WVLHXIFP.mjs.map → chunk-AFNWX62Q.mjs.map} +1 -1
- package/dist/{chunk-JRT5BJF3.mjs → chunk-B5ELMVT7.mjs} +2 -2
- package/dist/{chunk-TXI72QHK.mjs → chunk-EG56H77V.mjs} +2 -2
- package/dist/{chunk-DCHSCK62.mjs → chunk-FYMZKPOL.mjs} +36 -42
- package/dist/chunk-FYMZKPOL.mjs.map +1 -0
- package/dist/{chunk-FBD24VEH.mjs → chunk-HE22TZMF.mjs} +2 -2
- package/dist/{chunk-FBD24VEH.mjs.map → chunk-HE22TZMF.mjs.map} +1 -1
- package/dist/chunk-I76HKHPJ.mjs +32 -0
- package/dist/chunk-I76HKHPJ.mjs.map +1 -0
- package/dist/{chunk-LHKZJ2ND.mjs → chunk-PMWUKW3Z.mjs} +3 -3
- package/dist/{chunk-NROJOTQP.mjs → chunk-QNUAXSDP.mjs} +9 -6
- package/dist/chunk-QNUAXSDP.mjs.map +1 -0
- package/dist/{chunk-NG26QEGF.mjs → chunk-T2VBHAAP.mjs} +9 -3
- package/dist/chunk-T2VBHAAP.mjs.map +1 -0
- package/dist/{chunk-QU6NONOD.mjs → chunk-U2ZRVVKT.mjs} +2 -2
- package/dist/{chunk-R4MR43UQ.mjs → chunk-VV56AVPB.mjs} +33 -9
- package/dist/chunk-VV56AVPB.mjs.map +1 -0
- package/dist/{chunk-5X5DJRQQ.mjs → chunk-WF65O6HX.mjs} +2 -7
- package/dist/chunk-WF65O6HX.mjs.map +1 -0
- package/dist/chunk-XDFVCQD3.mjs +27 -0
- package/dist/chunk-XDFVCQD3.mjs.map +1 -0
- package/dist/{chunk-WMJVBMUX.mjs → chunk-YCG6SNAU.mjs} +2 -2
- package/dist/{chunk-3R423LZT.mjs → chunk-YJGPIN3R.mjs} +3 -3
- package/dist/{chunk-BR5YEYZJ.mjs → chunk-YTQHRJUA.mjs} +2 -2
- package/dist/chunk-Z6JV2LRY.mjs +37 -0
- package/dist/chunk-Z6JV2LRY.mjs.map +1 -0
- package/dist/{chunk-24SCZAB4.mjs → chunk-ZYTXB6HH.mjs} +22 -14
- package/dist/chunk-ZYTXB6HH.mjs.map +1 -0
- package/dist/components/CopilotListeners.js +13 -146
- package/dist/components/CopilotListeners.js.map +1 -1
- package/dist/components/CopilotListeners.mjs +1 -6
- package/dist/components/copilot-provider/copilot-messages.js +1 -1
- package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
- package/dist/components/copilot-provider/copilot-messages.mjs +2 -2
- package/dist/components/copilot-provider/copilotkit-props.d.ts +1 -1
- package/dist/components/copilot-provider/copilotkit.d.ts +1 -1
- package/dist/components/copilot-provider/copilotkit.js +35 -40
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +9 -9
- package/dist/components/copilot-provider/index.d.ts +1 -1
- package/dist/components/copilot-provider/index.js +35 -40
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +9 -9
- package/dist/components/dev-console/console-trigger.js +1 -1
- package/dist/components/dev-console/console-trigger.js.map +1 -1
- package/dist/components/dev-console/console-trigger.mjs +3 -3
- package/dist/components/dev-console/developer-console-modal.js +1 -1
- package/dist/components/dev-console/developer-console-modal.js.map +1 -1
- package/dist/components/dev-console/developer-console-modal.mjs +2 -2
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.js +35 -40
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +9 -9
- package/dist/context/copilot-context.d.ts +1 -1
- package/dist/context/copilot-context.js +1 -1
- package/dist/context/copilot-context.js.map +1 -1
- package/dist/context/copilot-context.mjs +1 -1
- package/dist/context/index.d.ts +1 -1
- package/dist/context/index.js +1 -1
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +1 -1
- package/dist/{copilot-context-1cd70a3f.d.ts → copilot-context-ec77e921.d.ts} +3 -3
- package/dist/hooks/index.d.ts +2 -2
- package/dist/hooks/index.js +254 -219
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +24 -23
- package/dist/hooks/use-agent-nodename.d.ts +3 -0
- package/dist/hooks/use-agent-nodename.js +56 -0
- package/dist/hooks/use-agent-nodename.js.map +1 -0
- package/dist/hooks/use-agent-nodename.mjs +8 -0
- package/dist/hooks/use-coagent-state-render-bridge.js +8 -5
- package/dist/hooks/use-coagent-state-render-bridge.js.map +1 -1
- package/dist/hooks/use-coagent-state-render-bridge.mjs +2 -2
- package/dist/hooks/use-coagent-state-render.js +1 -1
- package/dist/hooks/use-coagent-state-render.js.map +1 -1
- package/dist/hooks/use-coagent-state-render.mjs +2 -2
- package/dist/hooks/use-coagent.js +58 -21
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +2 -1
- package/dist/hooks/use-copilot-action.js +5 -1
- package/dist/hooks/use-copilot-action.js.map +1 -1
- package/dist/hooks/use-copilot-action.mjs +2 -2
- package/dist/hooks/use-copilot-additional-instructions.js +1 -1
- package/dist/hooks/use-copilot-additional-instructions.js.map +1 -1
- package/dist/hooks/use-copilot-additional-instructions.mjs +2 -2
- package/dist/hooks/use-copilot-authenticated-action.js +6 -2
- package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
- package/dist/hooks/use-copilot-authenticated-action.mjs +4 -4
- package/dist/hooks/use-copilot-chat-headless_c.js +128 -140
- package/dist/hooks/use-copilot-chat-headless_c.js.map +1 -1
- package/dist/hooks/use-copilot-chat-headless_c.mjs +6 -6
- package/dist/hooks/{use-configure-chat-suggestions.d.ts → use-copilot-chat-suggestions.d.ts} +2 -3
- package/dist/hooks/use-copilot-chat-suggestions.js +60 -0
- package/dist/hooks/use-copilot-chat-suggestions.js.map +1 -0
- package/dist/hooks/use-copilot-chat-suggestions.mjs +8 -0
- package/dist/hooks/use-copilot-chat-suggestions.mjs.map +1 -0
- package/dist/hooks/use-copilot-chat.js +126 -138
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +6 -6
- package/dist/hooks/use-copilot-chat_internal.d.ts +18 -1
- package/dist/hooks/use-copilot-chat_internal.js +126 -138
- package/dist/hooks/use-copilot-chat_internal.js.map +1 -1
- package/dist/hooks/use-copilot-chat_internal.mjs +5 -5
- package/dist/hooks/use-copilot-readable.d.ts +1 -1
- package/dist/hooks/use-copilot-readable.js +29 -5
- package/dist/hooks/use-copilot-readable.js.map +1 -1
- package/dist/hooks/use-copilot-readable.mjs +1 -1
- package/dist/hooks/use-default-tool.js +5 -1
- package/dist/hooks/use-default-tool.js.map +1 -1
- package/dist/hooks/use-default-tool.mjs +3 -3
- package/dist/hooks/use-frontend-tool.js +5 -1
- package/dist/hooks/use-frontend-tool.js.map +1 -1
- package/dist/hooks/use-frontend-tool.mjs +1 -1
- package/dist/hooks/use-langgraph-interrupt-render.js +77 -13
- package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt-render.mjs +3 -2
- package/dist/hooks/use-langgraph-interrupt.d.ts +1 -1
- package/dist/hooks/use-langgraph-interrupt.js +3 -3
- package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt.mjs +2 -2
- package/dist/hooks/use-make-copilot-document-readable.js +1 -1
- package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
- package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +273 -246
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +34 -33
- package/dist/lib/copilot-task.d.ts +1 -1
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +10 -10
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +10 -10
- package/dist/types/index.d.ts +1 -1
- package/dist/types/interrupt-action.d.ts +1 -1
- package/dist/types/interrupt-action.js.map +1 -1
- package/dist/utils/index.mjs +3 -3
- package/dist/v2/index.css +4 -0
- package/dist/v2/index.css.map +1 -0
- package/dist/v2/index.js.map +1 -1
- package/dist/v2/index.mjs +2 -0
- package/dist/v2/index.mjs.map +1 -1
- package/jest.config.js +12 -0
- package/package.json +14 -11
- package/src/components/CopilotListeners.tsx +1 -2
- package/src/components/copilot-provider/copilot-messages.tsx +0 -41
- package/src/components/copilot-provider/copilotkit.tsx +31 -31
- package/src/context/copilot-context.tsx +2 -2
- package/src/hooks/__tests__/use-coagent-config.test.ts +189 -129
- package/src/hooks/index.ts +2 -2
- package/src/hooks/use-agent-nodename.ts +30 -0
- package/src/hooks/use-coagent-state-render-bridge.tsx +22 -22
- package/src/hooks/use-coagent.ts +22 -13
- package/src/hooks/use-copilot-chat-suggestions.tsx +124 -0
- package/src/hooks/use-copilot-chat_internal.ts +78 -78
- package/src/hooks/use-copilot-readable.ts +30 -12
- package/src/hooks/use-frontend-tool.ts +10 -2
- package/src/hooks/use-langgraph-interrupt-render.ts +25 -7
- package/src/hooks/use-langgraph-interrupt.ts +2 -3
- package/src/types/interrupt-action.ts +2 -5
- package/src/v2/index.ts +2 -0
- package/tsup.config.ts +1 -1
- package/dist/chunk-24SCZAB4.mjs.map +0 -1
- package/dist/chunk-5X5DJRQQ.mjs.map +0 -1
- package/dist/chunk-7BYHZLPL.mjs.map +0 -1
- package/dist/chunk-CB7CRBDG.mjs +0 -48
- package/dist/chunk-CB7CRBDG.mjs.map +0 -1
- package/dist/chunk-DCHSCK62.mjs.map +0 -1
- package/dist/chunk-IUSKVYUI.mjs +0 -13
- package/dist/chunk-IUSKVYUI.mjs.map +0 -1
- package/dist/chunk-NG26QEGF.mjs.map +0 -1
- package/dist/chunk-NROJOTQP.mjs.map +0 -1
- package/dist/chunk-R4MR43UQ.mjs.map +0 -1
- package/dist/chunk-UJBV5GAG.mjs.map +0 -1
- package/dist/hooks/use-configure-chat-suggestions.js +0 -210
- package/dist/hooks/use-configure-chat-suggestions.js.map +0 -1
- package/dist/hooks/use-configure-chat-suggestions.mjs +0 -13
- package/src/hooks/use-configure-chat-suggestions.tsx +0 -85
- /package/dist/{chunk-3GURHDG7.mjs.map → chunk-4HRUQH6U.mjs.map} +0 -0
- /package/dist/{chunk-D3QSYDJR.mjs.map → chunk-7IBF6RBW.mjs.map} +0 -0
- /package/dist/{chunk-GMI4KO4X.mjs.map → chunk-7SHWECGN.mjs.map} +0 -0
- /package/dist/{chunk-OVYFRPSN.mjs.map → chunk-ABWT4DRT.mjs.map} +0 -0
- /package/dist/{chunk-JRT5BJF3.mjs.map → chunk-B5ELMVT7.mjs.map} +0 -0
- /package/dist/{chunk-TXI72QHK.mjs.map → chunk-EG56H77V.mjs.map} +0 -0
- /package/dist/{chunk-LHKZJ2ND.mjs.map → chunk-PMWUKW3Z.mjs.map} +0 -0
- /package/dist/{chunk-QU6NONOD.mjs.map → chunk-U2ZRVVKT.mjs.map} +0 -0
- /package/dist/{chunk-WMJVBMUX.mjs.map → chunk-YCG6SNAU.mjs.map} +0 -0
- /package/dist/{chunk-3R423LZT.mjs.map → chunk-YJGPIN3R.mjs.map} +0 -0
- /package/dist/{chunk-BR5YEYZJ.mjs.map → chunk-YTQHRJUA.mjs.map} +0 -0
- /package/dist/hooks/{use-configure-chat-suggestions.mjs.map → use-agent-nodename.mjs.map} +0 -0
- /package/src/v2/{styles.css → index.css} +0 -0
package/dist/index.js
CHANGED
|
@@ -95,13 +95,13 @@ __export(src_exports, {
|
|
|
95
95
|
useCoAgent: () => useCoAgent,
|
|
96
96
|
useCoAgentStateRender: () => useCoAgentStateRender,
|
|
97
97
|
useCoAgentStateRenders: () => useCoAgentStateRenders,
|
|
98
|
-
useConfigureChatSuggestions: () => useConfigureChatSuggestions,
|
|
99
98
|
useCopilotAction: () => useCopilotAction,
|
|
100
99
|
useCopilotAdditionalInstructions: () => useCopilotAdditionalInstructions,
|
|
101
100
|
useCopilotAuthenticatedAction_c: () => useCopilotAuthenticatedAction_c,
|
|
102
101
|
useCopilotChat: () => useCopilotChat,
|
|
103
102
|
useCopilotChatHeadless_c: () => useCopilotChatHeadless_c,
|
|
104
103
|
useCopilotChatInternal: () => useCopilotChatInternal,
|
|
104
|
+
useCopilotChatSuggestions: () => useCopilotChatSuggestions,
|
|
105
105
|
useCopilotContext: () => useCopilotContext,
|
|
106
106
|
useCopilotMessagesContext: () => useCopilotMessagesContext,
|
|
107
107
|
useCopilotReadable: () => useCopilotReadable,
|
|
@@ -198,7 +198,7 @@ var emptyCopilotContext = {
|
|
|
198
198
|
interruptEventQueue: {},
|
|
199
199
|
addInterruptEvent: () => {
|
|
200
200
|
},
|
|
201
|
-
|
|
201
|
+
resolveInterruptEvent: () => {
|
|
202
202
|
},
|
|
203
203
|
onError: () => {
|
|
204
204
|
},
|
|
@@ -2447,6 +2447,8 @@ function useThreads() {
|
|
|
2447
2447
|
// src/hooks/use-coagent-state-render-bridge.tsx
|
|
2448
2448
|
var import_shared10 = require("@copilotkit/shared");
|
|
2449
2449
|
function getStateWithoutConstantKeys(state) {
|
|
2450
|
+
if (!state)
|
|
2451
|
+
return {};
|
|
2450
2452
|
const _a = state, { messages, tools, copilotkit } = _a, stateWithoutConstantKeys = __objRest(_a, ["messages", "tools", "copilotkit"]);
|
|
2451
2453
|
return stateWithoutConstantKeys;
|
|
2452
2454
|
}
|
|
@@ -2493,9 +2495,6 @@ function useCoagentStateRenderBridge(agentId, props) {
|
|
|
2493
2495
|
unsubscribe();
|
|
2494
2496
|
};
|
|
2495
2497
|
}, [agentId, nodeName]);
|
|
2496
|
-
if (messageIndexInRun !== 0) {
|
|
2497
|
-
return null;
|
|
2498
|
-
}
|
|
2499
2498
|
const getStateRender = (0, import_react14.useCallback)(
|
|
2500
2499
|
(messageId) => {
|
|
2501
2500
|
return Object.entries(coAgentStateRenders).find(([stateRenderId, stateRender]) => {
|
|
@@ -2523,7 +2522,7 @@ function useCoagentStateRenderBridge(agentId, props) {
|
|
|
2523
2522
|
return canRender;
|
|
2524
2523
|
}
|
|
2525
2524
|
const renderClaimedByOtherMessage = Object.values(claimsRef.current).find(
|
|
2526
|
-
(c) => c.stateRenderId === stateRenderId && (0, import_shared10.dataToUUID)(
|
|
2525
|
+
(c) => c.stateRenderId === stateRenderId && (0, import_shared10.dataToUUID)(getStateWithoutConstantKeys(c.stateSnapshot)) === (0, import_shared10.dataToUUID)(getStateWithoutConstantKeys(renderSnapshot))
|
|
2527
2526
|
);
|
|
2528
2527
|
if (renderClaimedByOtherMessage) {
|
|
2529
2528
|
if (renderSnapshot && renderClaimedByOtherMessage.stateSnapshot && !areStatesEquals(renderClaimedByOtherMessage.stateSnapshot, renderSnapshot)) {
|
|
@@ -2540,6 +2539,9 @@ function useCoagentStateRenderBridge(agentId, props) {
|
|
|
2540
2539
|
};
|
|
2541
2540
|
return (0, import_react14.useMemo)(() => {
|
|
2542
2541
|
var _a2, _b, _c;
|
|
2542
|
+
if (messageIndexInRun !== 0) {
|
|
2543
|
+
return null;
|
|
2544
|
+
}
|
|
2543
2545
|
const [stateRenderId, stateRender] = (_a2 = getStateRender(message.id)) != null ? _a2 : [];
|
|
2544
2546
|
if (!stateRender || !stateRenderId) {
|
|
2545
2547
|
return null;
|
|
@@ -2586,7 +2588,8 @@ function useCoagentStateRenderBridge(agentId, props) {
|
|
|
2586
2588
|
agent == null ? void 0 : agent.isRunning,
|
|
2587
2589
|
nodeName,
|
|
2588
2590
|
effectiveRunId,
|
|
2589
|
-
message.id
|
|
2591
|
+
message.id,
|
|
2592
|
+
messageIndexInRun
|
|
2590
2593
|
]);
|
|
2591
2594
|
}
|
|
2592
2595
|
function CoAgentStateRenderBridge(props) {
|
|
@@ -2631,11 +2634,9 @@ var usePredictStateSubscription = (agent) => {
|
|
|
2631
2634
|
}, [agent, getSubscriber]);
|
|
2632
2635
|
};
|
|
2633
2636
|
function CopilotListeners() {
|
|
2634
|
-
var _a, _b;
|
|
2635
2637
|
const { copilotkit } = (0, import_react16.useCopilotKit)();
|
|
2636
|
-
const { agentSession } = useCopilotContext();
|
|
2637
2638
|
const existingConfig = (0, import_react16.useCopilotChatConfiguration)();
|
|
2638
|
-
const resolvedAgentId =
|
|
2639
|
+
const resolvedAgentId = existingConfig == null ? void 0 : existingConfig.agentId;
|
|
2639
2640
|
const { setBannerError } = useToast();
|
|
2640
2641
|
const { agent } = (0, import_react16.useAgent)({ agentId: resolvedAgentId });
|
|
2641
2642
|
usePredictStateSubscription(agent);
|
|
@@ -2660,15 +2661,7 @@ function CopilotKit(_a) {
|
|
|
2660
2661
|
const enabled = shouldShowDevConsole(props.showDevConsole);
|
|
2661
2662
|
const publicApiKey = props.publicApiKey || props.publicLicenseKey;
|
|
2662
2663
|
const renderArr = (0, import_react17.useMemo)(() => [{ render: CoAgentStateRenderBridge }], []);
|
|
2663
|
-
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(ToastProvider, { enabled, children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(CopilotErrorBoundary, { publicApiKey, showUsageBanner: enabled, children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(ThreadsProvider, { threadId: props.threadId, children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
2664
|
-
import_react18.CopilotKitProvider,
|
|
2665
|
-
{
|
|
2666
|
-
runtimeUrl: props.runtimeUrl,
|
|
2667
|
-
renderCustomMessages: renderArr,
|
|
2668
|
-
useSingleEndpoint: true,
|
|
2669
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(CopilotKitInternal, __spreadProps(__spreadValues({}, props), { children }))
|
|
2670
|
-
}
|
|
2671
|
-
) }) }) });
|
|
2664
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(ToastProvider, { enabled, children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(CopilotErrorBoundary, { publicApiKey, showUsageBanner: enabled, children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(ThreadsProvider, { threadId: props.threadId, children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_react18.CopilotKitProvider, __spreadProps(__spreadValues({}, props), { renderCustomMessages: renderArr, useSingleEndpoint: true, children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(CopilotKitInternal, __spreadProps(__spreadValues({}, props), { children })) })) }) }) });
|
|
2672
2665
|
}
|
|
2673
2666
|
function CopilotKitInternal(cpkProps) {
|
|
2674
2667
|
var _b;
|
|
@@ -2906,20 +2899,17 @@ ${nonDocumentStrings}`;
|
|
|
2906
2899
|
const chatAbortControllerRef = (0, import_react17.useRef)(null);
|
|
2907
2900
|
const showDevConsole = shouldShowDevConsole(props.showDevConsole);
|
|
2908
2901
|
const [interruptActions, _setInterruptActions] = (0, import_react17.useState)({});
|
|
2909
|
-
const setInterruptAction = (0, import_react17.useCallback)(
|
|
2910
|
-
(
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
[action.id]: __spreadValues(__spreadValues({}, (_a2 = prev[action.id]) != null ? _a2 : {}), action)
|
|
2918
|
-
});
|
|
2902
|
+
const setInterruptAction = (0, import_react17.useCallback)((action) => {
|
|
2903
|
+
_setInterruptActions((prev) => {
|
|
2904
|
+
var _a2;
|
|
2905
|
+
if (action == null || !action.id) {
|
|
2906
|
+
return prev;
|
|
2907
|
+
}
|
|
2908
|
+
return __spreadProps(__spreadValues({}, prev), {
|
|
2909
|
+
[action.id]: __spreadValues(__spreadValues({}, (_a2 = prev[action.id]) != null ? _a2 : {}), action)
|
|
2919
2910
|
});
|
|
2920
|
-
}
|
|
2921
|
-
|
|
2922
|
-
);
|
|
2911
|
+
});
|
|
2912
|
+
}, []);
|
|
2923
2913
|
const removeInterruptAction = (0, import_react17.useCallback)((actionId) => {
|
|
2924
2914
|
_setInterruptActions((prev) => {
|
|
2925
2915
|
const _a2 = prev, { [actionId]: _ } = _a2, rest = __objRest(_a2, [__restKey(actionId)]);
|
|
@@ -2935,14 +2925,19 @@ ${nonDocumentStrings}`;
|
|
|
2935
2925
|
});
|
|
2936
2926
|
});
|
|
2937
2927
|
}, []);
|
|
2938
|
-
const
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2928
|
+
const resolveInterruptEvent = (0, import_react17.useCallback)(
|
|
2929
|
+
(threadId2, eventId, response) => {
|
|
2930
|
+
setInterruptEventQueue((prev) => {
|
|
2931
|
+
const threadQueue = prev[threadId2] || [];
|
|
2932
|
+
return __spreadProps(__spreadValues({}, prev), {
|
|
2933
|
+
[threadId2]: threadQueue.map(
|
|
2934
|
+
(queuedEvent) => queuedEvent.eventId === eventId ? __spreadProps(__spreadValues({}, queuedEvent), { event: __spreadProps(__spreadValues({}, queuedEvent.event), { response }) }) : queuedEvent
|
|
2935
|
+
)
|
|
2936
|
+
});
|
|
2943
2937
|
});
|
|
2944
|
-
}
|
|
2945
|
-
|
|
2938
|
+
},
|
|
2939
|
+
[]
|
|
2940
|
+
);
|
|
2946
2941
|
const memoizedChildren = (0, import_react17.useMemo)(() => children, [children]);
|
|
2947
2942
|
const [bannerError, setBannerError] = (0, import_react17.useState)(null);
|
|
2948
2943
|
const agentLock = (0, import_react17.useMemo)(() => {
|
|
@@ -3005,7 +3000,7 @@ ${nonDocumentStrings}`;
|
|
|
3005
3000
|
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
3006
3001
|
import_react18.CopilotChatConfigurationProvider,
|
|
3007
3002
|
{
|
|
3008
|
-
agentId: (_b =
|
|
3003
|
+
agentId: (_b = props.agent) != null ? _b : "default",
|
|
3009
3004
|
threadId,
|
|
3010
3005
|
children: /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
|
|
3011
3006
|
CopilotContext.Provider,
|
|
@@ -3060,7 +3055,7 @@ ${nonDocumentStrings}`;
|
|
|
3060
3055
|
removeInterruptAction,
|
|
3061
3056
|
interruptEventQueue,
|
|
3062
3057
|
addInterruptEvent,
|
|
3063
|
-
|
|
3058
|
+
resolveInterruptEvent,
|
|
3064
3059
|
bannerError,
|
|
3065
3060
|
setBannerError,
|
|
3066
3061
|
onError: handleErrors,
|
|
@@ -3137,28 +3132,64 @@ function validateProps(props) {
|
|
|
3137
3132
|
}
|
|
3138
3133
|
|
|
3139
3134
|
// src/hooks/use-copilot-chat_internal.ts
|
|
3140
|
-
var
|
|
3135
|
+
var import_react25 = require("react");
|
|
3141
3136
|
var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
|
|
3142
3137
|
|
|
3143
3138
|
// src/hooks/use-langgraph-interrupt-render.ts
|
|
3144
|
-
var
|
|
3139
|
+
var import_react21 = __toESM(require("react"));
|
|
3145
3140
|
var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
|
|
3146
3141
|
var import_shared14 = require("@copilotkit/shared");
|
|
3142
|
+
|
|
3143
|
+
// src/hooks/use-agent-nodename.ts
|
|
3144
|
+
var import_react19 = require("react");
|
|
3145
|
+
var import_react20 = require("@copilotkitnext/react");
|
|
3146
|
+
function useAgentNodeName(agentName) {
|
|
3147
|
+
const { agent } = (0, import_react20.useAgent)({ agentId: agentName });
|
|
3148
|
+
const nodeNameRef = (0, import_react19.useRef)("start");
|
|
3149
|
+
(0, import_react19.useEffect)(() => {
|
|
3150
|
+
if (!agent)
|
|
3151
|
+
return;
|
|
3152
|
+
const subscriber = {
|
|
3153
|
+
onStepStartedEvent: ({ event }) => {
|
|
3154
|
+
nodeNameRef.current = event.stepName;
|
|
3155
|
+
},
|
|
3156
|
+
onRunStartedEvent: () => {
|
|
3157
|
+
nodeNameRef.current = "start";
|
|
3158
|
+
},
|
|
3159
|
+
onRunFinishedEvent: () => {
|
|
3160
|
+
nodeNameRef.current = "end";
|
|
3161
|
+
}
|
|
3162
|
+
};
|
|
3163
|
+
const subscription = agent.subscribe(subscriber);
|
|
3164
|
+
return () => {
|
|
3165
|
+
subscription.unsubscribe();
|
|
3166
|
+
};
|
|
3167
|
+
}, [agent]);
|
|
3168
|
+
return nodeNameRef.current;
|
|
3169
|
+
}
|
|
3170
|
+
|
|
3171
|
+
// src/hooks/use-langgraph-interrupt-render.ts
|
|
3172
|
+
var import_react22 = require("@copilotkitnext/react");
|
|
3147
3173
|
var InterruptRenderer = ({ event, result, render, resolve }) => {
|
|
3148
3174
|
return render({ event, result, resolve });
|
|
3149
3175
|
};
|
|
3150
3176
|
function useLangGraphInterruptRender(agent) {
|
|
3177
|
+
var _a;
|
|
3151
3178
|
const {
|
|
3152
3179
|
interruptActions,
|
|
3153
3180
|
agentSession,
|
|
3154
3181
|
threadId,
|
|
3155
3182
|
interruptEventQueue,
|
|
3156
3183
|
addInterruptEvent,
|
|
3157
|
-
|
|
3184
|
+
resolveInterruptEvent
|
|
3158
3185
|
} = useCopilotContext();
|
|
3159
|
-
(0,
|
|
3186
|
+
const existingConfig = (0, import_react22.useCopilotChatConfiguration)();
|
|
3187
|
+
const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
|
|
3188
|
+
const nodeName = useAgentNodeName(resolvedAgentId);
|
|
3189
|
+
(0, import_react21.useEffect)(() => {
|
|
3160
3190
|
if (!agent)
|
|
3161
3191
|
return;
|
|
3192
|
+
let localInterrupt = null;
|
|
3162
3193
|
const subscriber = {
|
|
3163
3194
|
onCustomEvent: ({ event }) => {
|
|
3164
3195
|
if (event.name === "on_interrupt") {
|
|
@@ -3167,12 +3198,21 @@ function useLangGraphInterruptRender(agent) {
|
|
|
3167
3198
|
type: event.type,
|
|
3168
3199
|
value: (0, import_shared14.parseJson)(event.value, event.value)
|
|
3169
3200
|
};
|
|
3170
|
-
const eventId = (0, import_shared14.dataToUUID)(
|
|
3171
|
-
|
|
3201
|
+
const eventId = (0, import_shared14.dataToUUID)(eventData, "interruptEvents");
|
|
3202
|
+
localInterrupt = {
|
|
3172
3203
|
eventId,
|
|
3173
3204
|
threadId,
|
|
3174
3205
|
event: eventData
|
|
3175
|
-
}
|
|
3206
|
+
};
|
|
3207
|
+
}
|
|
3208
|
+
},
|
|
3209
|
+
onRunStartedEvent: () => {
|
|
3210
|
+
localInterrupt = null;
|
|
3211
|
+
},
|
|
3212
|
+
onRunFinalized: () => {
|
|
3213
|
+
if (localInterrupt) {
|
|
3214
|
+
addInterruptEvent(localInterrupt);
|
|
3215
|
+
localInterrupt = null;
|
|
3176
3216
|
}
|
|
3177
3217
|
}
|
|
3178
3218
|
};
|
|
@@ -3181,7 +3221,7 @@ function useLangGraphInterruptRender(agent) {
|
|
|
3181
3221
|
unsubscribe();
|
|
3182
3222
|
};
|
|
3183
3223
|
}, [agent, threadId]);
|
|
3184
|
-
const handleResolve = (0,
|
|
3224
|
+
const handleResolve = (0, import_react21.useCallback)(
|
|
3185
3225
|
(eventId, response) => {
|
|
3186
3226
|
agent == null ? void 0 : agent.runAgent({
|
|
3187
3227
|
forwardedProps: {
|
|
@@ -3190,15 +3230,15 @@ function useLangGraphInterruptRender(agent) {
|
|
|
3190
3230
|
}
|
|
3191
3231
|
}
|
|
3192
3232
|
});
|
|
3193
|
-
|
|
3233
|
+
resolveInterruptEvent(threadId, eventId, response != null ? response : "");
|
|
3194
3234
|
},
|
|
3195
3235
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3196
3236
|
[agent, threadId]
|
|
3197
3237
|
);
|
|
3198
|
-
return (0,
|
|
3238
|
+
return (0, import_react21.useMemo)(() => {
|
|
3199
3239
|
const eventQueue = interruptEventQueue[threadId] || [];
|
|
3200
3240
|
const currentQueuedEvent = eventQueue.find((qe) => !qe.event.response);
|
|
3201
|
-
if (!currentQueuedEvent)
|
|
3241
|
+
if (!currentQueuedEvent || !agentSession)
|
|
3202
3242
|
return null;
|
|
3203
3243
|
const allActions = Object.values(interruptActions);
|
|
3204
3244
|
const matchingAction = allActions.find((action) => {
|
|
@@ -3206,7 +3246,9 @@ function useLangGraphInterruptRender(agent) {
|
|
|
3206
3246
|
return true;
|
|
3207
3247
|
return action.enabled({
|
|
3208
3248
|
eventValue: currentQueuedEvent.event.value,
|
|
3209
|
-
agentMetadata: agentSession
|
|
3249
|
+
agentMetadata: __spreadProps(__spreadValues({}, agentSession), {
|
|
3250
|
+
nodeName
|
|
3251
|
+
})
|
|
3210
3252
|
});
|
|
3211
3253
|
});
|
|
3212
3254
|
if (!matchingAction)
|
|
@@ -3224,7 +3266,7 @@ function useLangGraphInterruptRender(agent) {
|
|
|
3224
3266
|
}
|
|
3225
3267
|
if (!render)
|
|
3226
3268
|
return null;
|
|
3227
|
-
return
|
|
3269
|
+
return import_react21.default.createElement(InterruptRenderer, {
|
|
3228
3270
|
event: currentQueuedEvent.event,
|
|
3229
3271
|
result,
|
|
3230
3272
|
render,
|
|
@@ -3234,14 +3276,14 @@ function useLangGraphInterruptRender(agent) {
|
|
|
3234
3276
|
}
|
|
3235
3277
|
|
|
3236
3278
|
// src/hooks/use-copilot-chat_internal.ts
|
|
3237
|
-
var
|
|
3279
|
+
var import_react26 = require("@copilotkitnext/react");
|
|
3238
3280
|
|
|
3239
3281
|
// src/hooks/use-lazy-tool-renderer.tsx
|
|
3240
|
-
var
|
|
3241
|
-
var
|
|
3282
|
+
var import_react23 = require("@copilotkitnext/react");
|
|
3283
|
+
var import_react24 = require("react");
|
|
3242
3284
|
function useLazyToolRenderer() {
|
|
3243
|
-
const renderToolCall = (0,
|
|
3244
|
-
return (0,
|
|
3285
|
+
const renderToolCall = (0, import_react23.useRenderToolCall)();
|
|
3286
|
+
return (0, import_react24.useCallback)(
|
|
3245
3287
|
(message, messages) => {
|
|
3246
3288
|
var _a;
|
|
3247
3289
|
if (!((_a = message == null ? void 0 : message.toolCalls) == null ? void 0 : _a.length))
|
|
@@ -3261,39 +3303,7 @@ function useLazyToolRenderer() {
|
|
|
3261
3303
|
);
|
|
3262
3304
|
}
|
|
3263
3305
|
|
|
3264
|
-
//
|
|
3265
|
-
var import_react22 = require("@copilotkitnext/react");
|
|
3266
|
-
var import_react23 = require("react");
|
|
3267
|
-
function useConfigureChatSuggestions(config, dependencies = []) {
|
|
3268
|
-
const { agentSession } = useCopilotContext();
|
|
3269
|
-
const { copilotkit } = (0, import_react22.useCopilotKit)();
|
|
3270
|
-
const available = config.available === "enabled" ? "always" : config.available;
|
|
3271
|
-
const finalSuggestionConfig = __spreadProps(__spreadValues({}, config), {
|
|
3272
|
-
available,
|
|
3273
|
-
consumerAgentId: agentSession == null ? void 0 : agentSession.agentName
|
|
3274
|
-
// Use chatConfig.agentId here
|
|
3275
|
-
});
|
|
3276
|
-
(0, import_react22.useConfigureSuggestions)(finalSuggestionConfig, { deps: dependencies });
|
|
3277
|
-
const result = (0, import_react22.useSuggestions)({ agentId: agentSession == null ? void 0 : agentSession.agentName });
|
|
3278
|
-
(0, import_react23.useEffect)(() => {
|
|
3279
|
-
if (finalSuggestionConfig.available === "disabled")
|
|
3280
|
-
return;
|
|
3281
|
-
const subscription = copilotkit.subscribe({
|
|
3282
|
-
onAgentsChanged: () => {
|
|
3283
|
-
const agent = copilotkit.getAgent(agentSession == null ? void 0 : agentSession.agentName);
|
|
3284
|
-
if (agent && !agent.isRunning && !result.suggestions.length) {
|
|
3285
|
-
copilotkit.reloadSuggestions(agentSession == null ? void 0 : agentSession.agentName);
|
|
3286
|
-
}
|
|
3287
|
-
}
|
|
3288
|
-
});
|
|
3289
|
-
return () => {
|
|
3290
|
-
subscription.unsubscribe();
|
|
3291
|
-
};
|
|
3292
|
-
}, []);
|
|
3293
|
-
return result;
|
|
3294
|
-
}
|
|
3295
|
-
|
|
3296
|
-
// ../../node_modules/.pnpm/@ag-ui+core@0.0.42-alpha.1/node_modules/@ag-ui/core/dist/index.mjs
|
|
3306
|
+
// ../../node_modules/.pnpm/@ag-ui+core@0.0.42/node_modules/@ag-ui/core/dist/index.mjs
|
|
3297
3307
|
var import_zod = require("zod");
|
|
3298
3308
|
var import_zod2 = require("zod");
|
|
3299
3309
|
var FunctionCallSchema = import_zod.z.object({
|
|
@@ -3699,35 +3709,17 @@ var EventSchemas = import_zod2.z.discriminatedUnion("type", [
|
|
|
3699
3709
|
]);
|
|
3700
3710
|
|
|
3701
3711
|
// src/hooks/use-copilot-chat_internal.ts
|
|
3702
|
-
function useConfigureSuggestions2(suggestions) {
|
|
3703
|
-
let suggestionsConfig;
|
|
3704
|
-
if (Array.isArray(suggestions)) {
|
|
3705
|
-
suggestionsConfig = {
|
|
3706
|
-
suggestions,
|
|
3707
|
-
available: "always"
|
|
3708
|
-
};
|
|
3709
|
-
} else if (suggestions === "auto") {
|
|
3710
|
-
suggestionsConfig = {
|
|
3711
|
-
available: suggestions === "auto" ? "always" : "disabled",
|
|
3712
|
-
instructions: "Suggest what the user could say next. Provide clear, highly relevant suggestions. Do not literally suggest function calls."
|
|
3713
|
-
};
|
|
3714
|
-
} else {
|
|
3715
|
-
suggestionsConfig = { available: "disabled" };
|
|
3716
|
-
}
|
|
3717
|
-
useConfigureChatSuggestions(suggestionsConfig);
|
|
3718
|
-
}
|
|
3719
3712
|
function useCopilotChatInternal({
|
|
3720
3713
|
suggestions
|
|
3721
3714
|
} = {}) {
|
|
3722
|
-
var _a, _b, _c
|
|
3723
|
-
const { copilotkit } = (0,
|
|
3715
|
+
var _a, _b, _c;
|
|
3716
|
+
const { copilotkit } = (0, import_react26.useCopilotKit)();
|
|
3724
3717
|
const { threadId, agentSession } = useCopilotContext();
|
|
3725
|
-
const existingConfig = (0,
|
|
3726
|
-
const [agentAvailable, setAgentAvailable] = (0,
|
|
3727
|
-
|
|
3728
|
-
const
|
|
3729
|
-
|
|
3730
|
-
(0, import_react24.useEffect)(() => {
|
|
3718
|
+
const existingConfig = (0, import_react26.useCopilotChatConfiguration)();
|
|
3719
|
+
const [agentAvailable, setAgentAvailable] = (0, import_react25.useState)(false);
|
|
3720
|
+
const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
|
|
3721
|
+
const { agent } = (0, import_react26.useAgent)({ agentId: resolvedAgentId });
|
|
3722
|
+
(0, import_react25.useEffect)(() => {
|
|
3731
3723
|
const connect = (agent2) => __async(this, null, function* () {
|
|
3732
3724
|
setAgentAvailable(false);
|
|
3733
3725
|
try {
|
|
@@ -3752,7 +3744,7 @@ function useCopilotChatInternal({
|
|
|
3752
3744
|
agent == null ? void 0 : agent.setMessages([]);
|
|
3753
3745
|
agent == null ? void 0 : agent.setState(null);
|
|
3754
3746
|
};
|
|
3755
|
-
const deleteMessage = (0,
|
|
3747
|
+
const deleteMessage = (0, import_react25.useCallback)(
|
|
3756
3748
|
(messageId) => {
|
|
3757
3749
|
var _a2;
|
|
3758
3750
|
const filteredMessages = ((_a2 = agent == null ? void 0 : agent.messages) != null ? _a2 : []).filter(
|
|
@@ -3763,13 +3755,13 @@ function useCopilotChatInternal({
|
|
|
3763
3755
|
[agent == null ? void 0 : agent.setMessages, agent == null ? void 0 : agent.messages]
|
|
3764
3756
|
);
|
|
3765
3757
|
const latestDelete = useUpdatedRef(deleteMessage);
|
|
3766
|
-
const latestDeleteFunc = (0,
|
|
3758
|
+
const latestDeleteFunc = (0, import_react25.useCallback)(
|
|
3767
3759
|
(messageId) => {
|
|
3768
3760
|
return latestDelete.current(messageId);
|
|
3769
3761
|
},
|
|
3770
3762
|
[latestDelete]
|
|
3771
3763
|
);
|
|
3772
|
-
const currentSuggestions = (0,
|
|
3764
|
+
const currentSuggestions = (0, import_react26.useSuggestions)({ agentId: resolvedAgentId });
|
|
3773
3765
|
const reload = useAsyncCallback(
|
|
3774
3766
|
(reloadMessageId) => __async(this, null, function* () {
|
|
3775
3767
|
var _a2;
|
|
@@ -3836,16 +3828,15 @@ function useCopilotChatInternal({
|
|
|
3836
3828
|
}),
|
|
3837
3829
|
[latestSendMessageFunc]
|
|
3838
3830
|
);
|
|
3839
|
-
const
|
|
3840
|
-
const latestSetMessagesFunc = (0, import_react24.useCallback)(
|
|
3831
|
+
const latestSetMessagesFunc = (0, import_react25.useCallback)(
|
|
3841
3832
|
(messages) => {
|
|
3842
3833
|
var _a2, _b2;
|
|
3843
3834
|
if (messages.every((message) => message instanceof import_runtime_client_gql2.Message)) {
|
|
3844
|
-
return (_a2 =
|
|
3835
|
+
return (_a2 = agent == null ? void 0 : agent.setMessages) == null ? void 0 : _a2.call(agent, (0, import_runtime_client_gql2.gqlToAGUI)(messages));
|
|
3845
3836
|
}
|
|
3846
|
-
return (_b2 =
|
|
3837
|
+
return (_b2 = agent == null ? void 0 : agent.setMessages) == null ? void 0 : _b2.call(agent, messages);
|
|
3847
3838
|
},
|
|
3848
|
-
[
|
|
3839
|
+
[agent == null ? void 0 : agent.setMessages, agent]
|
|
3849
3840
|
);
|
|
3850
3841
|
const latestReload = useUpdatedRef(reload);
|
|
3851
3842
|
const latestReloadFunc = useAsyncCallback(
|
|
@@ -3854,25 +3845,24 @@ function useCopilotChatInternal({
|
|
|
3854
3845
|
}),
|
|
3855
3846
|
[latestReload]
|
|
3856
3847
|
);
|
|
3857
|
-
const
|
|
3858
|
-
const latestStopFunc = (0, import_react24.useCallback)(() => {
|
|
3848
|
+
const latestStopFunc = (0, import_react25.useCallback)(() => {
|
|
3859
3849
|
var _a2;
|
|
3860
|
-
return (_a2 =
|
|
3861
|
-
}, [
|
|
3850
|
+
return (_a2 = agent == null ? void 0 : agent.abortRun) == null ? void 0 : _a2.call(agent);
|
|
3851
|
+
}, [agent == null ? void 0 : agent.abortRun]);
|
|
3862
3852
|
const latestReset = useUpdatedRef(reset);
|
|
3863
|
-
const latestResetFunc = (0,
|
|
3853
|
+
const latestResetFunc = (0, import_react25.useCallback)(() => {
|
|
3864
3854
|
return latestReset.current();
|
|
3865
3855
|
}, [latestReset]);
|
|
3866
3856
|
const lazyToolRendered = useLazyToolRenderer();
|
|
3867
|
-
const renderCustomMessage = (0,
|
|
3857
|
+
const renderCustomMessage = (0, import_react26.useRenderCustomMessages)();
|
|
3868
3858
|
const legacyCustomMessageRenderer = useLegacyCoagentRenderer({
|
|
3869
3859
|
copilotkit,
|
|
3870
3860
|
agent,
|
|
3871
3861
|
agentId: resolvedAgentId,
|
|
3872
|
-
threadId: (
|
|
3862
|
+
threadId: (_b = existingConfig == null ? void 0 : existingConfig.threadId) != null ? _b : threadId
|
|
3873
3863
|
});
|
|
3874
|
-
const allMessages = (
|
|
3875
|
-
const resolvedMessages = (0,
|
|
3864
|
+
const allMessages = (_c = agent == null ? void 0 : agent.messages) != null ? _c : [];
|
|
3865
|
+
const resolvedMessages = (0, import_react25.useMemo)(() => {
|
|
3876
3866
|
let processedMessages = allMessages.map((message) => {
|
|
3877
3867
|
if (message.role !== "assistant") {
|
|
3878
3868
|
return message;
|
|
@@ -3900,33 +3890,24 @@ function useCopilotChatInternal({
|
|
|
3900
3890
|
return message;
|
|
3901
3891
|
});
|
|
3902
3892
|
const hasAssistantMessages = processedMessages.some((msg) => msg.role === "assistant");
|
|
3903
|
-
if (legacyCustomMessageRenderer && !hasAssistantMessages) {
|
|
3904
|
-
const placeholderId = `coagent-state-render-${resolvedAgentId}`;
|
|
3905
|
-
const placeholderMessage = {
|
|
3906
|
-
id: placeholderId,
|
|
3907
|
-
role: "assistant",
|
|
3908
|
-
content: "",
|
|
3909
|
-
name: "coagent-state-render"
|
|
3910
|
-
};
|
|
3911
|
-
processedMessages = [
|
|
3912
|
-
...processedMessages,
|
|
3913
|
-
__spreadProps(__spreadValues({}, placeholderMessage), {
|
|
3914
|
-
generativeUI: () => legacyCustomMessageRenderer({
|
|
3915
|
-
message: placeholderMessage,
|
|
3916
|
-
position: "before"
|
|
3917
|
-
})
|
|
3918
|
-
})
|
|
3919
|
-
];
|
|
3920
|
-
}
|
|
3921
3893
|
return processedMessages;
|
|
3922
3894
|
}, [
|
|
3923
3895
|
agent == null ? void 0 : agent.messages,
|
|
3924
3896
|
lazyToolRendered,
|
|
3925
3897
|
allMessages,
|
|
3926
3898
|
renderCustomMessage,
|
|
3927
|
-
legacyCustomMessageRenderer,
|
|
3899
|
+
// legacyCustomMessageRenderer,
|
|
3928
3900
|
resolvedAgentId
|
|
3929
3901
|
]);
|
|
3902
|
+
const renderedSuggestions = (0, import_react25.useMemo)(() => {
|
|
3903
|
+
if (Array.isArray(suggestions)) {
|
|
3904
|
+
return {
|
|
3905
|
+
suggestions: suggestions.map((s) => __spreadProps(__spreadValues({}, s), { isLoading: false })),
|
|
3906
|
+
isLoading: false
|
|
3907
|
+
};
|
|
3908
|
+
}
|
|
3909
|
+
return currentSuggestions;
|
|
3910
|
+
}, [suggestions, currentSuggestions]);
|
|
3930
3911
|
return {
|
|
3931
3912
|
messages: resolvedMessages,
|
|
3932
3913
|
sendMessage: latestSendMessageFunc,
|
|
@@ -3936,25 +3917,25 @@ function useCopilotChatInternal({
|
|
|
3936
3917
|
stopGeneration: latestStopFunc,
|
|
3937
3918
|
reset: latestResetFunc,
|
|
3938
3919
|
deleteMessage: latestDeleteFunc,
|
|
3939
|
-
isAvailable:
|
|
3920
|
+
isAvailable: agentAvailable,
|
|
3940
3921
|
isLoading: Boolean(agent == null ? void 0 : agent.isRunning),
|
|
3941
3922
|
// mcpServers,
|
|
3942
3923
|
// setMcpServers,
|
|
3943
|
-
suggestions:
|
|
3924
|
+
suggestions: renderedSuggestions.suggestions,
|
|
3944
3925
|
setSuggestions: (suggestions2) => copilotkit.addSuggestionsConfig({ suggestions: suggestions2 }),
|
|
3945
3926
|
generateSuggestions: () => __async(this, null, function* () {
|
|
3946
3927
|
return copilotkit.reloadSuggestions(resolvedAgentId);
|
|
3947
3928
|
}),
|
|
3948
3929
|
resetSuggestions: () => copilotkit.clearSuggestions(resolvedAgentId),
|
|
3949
|
-
isLoadingSuggestions:
|
|
3930
|
+
isLoadingSuggestions: renderedSuggestions.isLoading,
|
|
3950
3931
|
interrupt,
|
|
3951
3932
|
agent,
|
|
3952
3933
|
threadId
|
|
3953
3934
|
};
|
|
3954
3935
|
}
|
|
3955
3936
|
function useUpdatedRef(value) {
|
|
3956
|
-
const ref = (0,
|
|
3957
|
-
(0,
|
|
3937
|
+
const ref = (0, import_react25.useRef)(value);
|
|
3938
|
+
(0, import_react25.useEffect)(() => {
|
|
3958
3939
|
ref.current = value;
|
|
3959
3940
|
}, [value]);
|
|
3960
3941
|
return ref;
|
|
@@ -3965,20 +3946,19 @@ function useLegacyCoagentRenderer({
|
|
|
3965
3946
|
agentId,
|
|
3966
3947
|
threadId
|
|
3967
3948
|
}) {
|
|
3968
|
-
return (0,
|
|
3949
|
+
return (0, import_react25.useMemo)(() => {
|
|
3969
3950
|
if (!copilotkit || !agent) {
|
|
3970
3951
|
return null;
|
|
3971
3952
|
}
|
|
3972
3953
|
return ({ message, position }) => {
|
|
3973
3954
|
var _a;
|
|
3974
3955
|
const effectiveThreadId = (_a = threadId != null ? threadId : agent.threadId) != null ? _a : "default";
|
|
3975
|
-
const existingRunId = copilotkit.getRunIdForMessage(
|
|
3976
|
-
agentId,
|
|
3977
|
-
effectiveThreadId,
|
|
3978
|
-
message.id
|
|
3979
|
-
);
|
|
3956
|
+
const existingRunId = copilotkit.getRunIdForMessage(agentId, effectiveThreadId, message.id);
|
|
3980
3957
|
const runId = existingRunId || `pending:${message.id}`;
|
|
3981
|
-
const messageIndex = Math.max(
|
|
3958
|
+
const messageIndex = Math.max(
|
|
3959
|
+
agent.messages.findIndex((msg) => msg.id === message.id),
|
|
3960
|
+
0
|
|
3961
|
+
);
|
|
3982
3962
|
const bridgeProps = {
|
|
3983
3963
|
message,
|
|
3984
3964
|
position,
|
|
@@ -3989,7 +3969,7 @@ function useLegacyCoagentRenderer({
|
|
|
3989
3969
|
agentId,
|
|
3990
3970
|
stateSnapshot: message.state
|
|
3991
3971
|
};
|
|
3992
|
-
return (0,
|
|
3972
|
+
return (0, import_react25.createElement)(CoAgentStateRenderBridge, bridgeProps);
|
|
3993
3973
|
};
|
|
3994
3974
|
}, [agent, agentId, copilotkit, threadId]);
|
|
3995
3975
|
}
|
|
@@ -4023,7 +4003,7 @@ function useCopilotChat(options = {}) {
|
|
|
4023
4003
|
}
|
|
4024
4004
|
|
|
4025
4005
|
// src/hooks/use-copilot-chat-headless_c.ts
|
|
4026
|
-
var
|
|
4006
|
+
var import_react27 = require("react");
|
|
4027
4007
|
var import_shared15 = require("@copilotkit/shared");
|
|
4028
4008
|
var createNonFunctionalReturn = () => ({
|
|
4029
4009
|
visibleMessages: [],
|
|
@@ -4064,7 +4044,7 @@ function useCopilotChatHeadless_c(options = {}) {
|
|
|
4064
4044
|
const { copilotApiConfig, setBannerError } = useCopilotContext();
|
|
4065
4045
|
const hasPublicApiKey = Boolean(copilotApiConfig.publicApiKey);
|
|
4066
4046
|
const internalResult = useCopilotChatInternal(options);
|
|
4067
|
-
(0,
|
|
4047
|
+
(0, import_react27.useEffect)(() => {
|
|
4068
4048
|
if (!hasPublicApiKey) {
|
|
4069
4049
|
setBannerError(
|
|
4070
4050
|
new import_shared15.CopilotKitError({
|
|
@@ -4089,13 +4069,13 @@ function useCopilotChatHeadless_c(options = {}) {
|
|
|
4089
4069
|
}
|
|
4090
4070
|
|
|
4091
4071
|
// src/hooks/use-copilot-action.ts
|
|
4092
|
-
var
|
|
4072
|
+
var import_react34 = require("react");
|
|
4093
4073
|
|
|
4094
4074
|
// src/hooks/use-frontend-tool.ts
|
|
4095
|
-
var
|
|
4075
|
+
var import_react28 = __toESM(require("react"));
|
|
4096
4076
|
var import_shared16 = require("@copilotkit/shared");
|
|
4097
4077
|
var import_shared17 = require("@copilotkit/shared");
|
|
4098
|
-
var
|
|
4078
|
+
var import_react29 = require("@copilotkitnext/react");
|
|
4099
4079
|
function useFrontendTool(tool, dependencies) {
|
|
4100
4080
|
const { name, description, parameters, render, followUp } = tool;
|
|
4101
4081
|
const zodParameters = (0, import_shared16.getZodParameters)(parameters);
|
|
@@ -4105,7 +4085,11 @@ function useFrontendTool(tool, dependencies) {
|
|
|
4105
4085
|
}
|
|
4106
4086
|
if (typeof render === "string") {
|
|
4107
4087
|
const staticRender = render;
|
|
4108
|
-
return () =>
|
|
4088
|
+
return () => import_react28.default.createElement(
|
|
4089
|
+
import_react28.default.Fragment,
|
|
4090
|
+
null,
|
|
4091
|
+
staticRender
|
|
4092
|
+
);
|
|
4109
4093
|
}
|
|
4110
4094
|
return (args) => {
|
|
4111
4095
|
const renderArgs = __spreadProps(__spreadValues({}, args), {
|
|
@@ -4113,12 +4097,12 @@ function useFrontendTool(tool, dependencies) {
|
|
|
4113
4097
|
});
|
|
4114
4098
|
const rendered = render(renderArgs);
|
|
4115
4099
|
if (typeof rendered === "string") {
|
|
4116
|
-
return
|
|
4100
|
+
return import_react28.default.createElement(import_react28.default.Fragment, null, rendered);
|
|
4117
4101
|
}
|
|
4118
4102
|
return rendered != null ? rendered : null;
|
|
4119
4103
|
};
|
|
4120
4104
|
})();
|
|
4121
|
-
(0,
|
|
4105
|
+
(0, import_react29.useFrontendTool)({
|
|
4122
4106
|
name,
|
|
4123
4107
|
description,
|
|
4124
4108
|
parameters: zodParameters,
|
|
@@ -4130,23 +4114,23 @@ function useFrontendTool(tool, dependencies) {
|
|
|
4130
4114
|
|
|
4131
4115
|
// src/hooks/use-render-tool-call.ts
|
|
4132
4116
|
var import_shared18 = require("@copilotkit/shared");
|
|
4133
|
-
var
|
|
4134
|
-
var
|
|
4117
|
+
var import_react30 = require("react");
|
|
4118
|
+
var import_react31 = require("@copilotkitnext/react");
|
|
4135
4119
|
var import_shared19 = require("@copilotkit/shared");
|
|
4136
4120
|
function useRenderToolCall2(tool, dependencies) {
|
|
4137
|
-
const { copilotkit } = (0,
|
|
4138
|
-
const hasAddedRef = (0,
|
|
4139
|
-
(0,
|
|
4121
|
+
const { copilotkit } = (0, import_react31.useCopilotKit)();
|
|
4122
|
+
const hasAddedRef = (0, import_react30.useRef)(false);
|
|
4123
|
+
(0, import_react30.useEffect)(() => {
|
|
4140
4124
|
const { name, parameters, render } = tool;
|
|
4141
4125
|
const zodParameters = (0, import_shared18.getZodParameters)(parameters);
|
|
4142
|
-
const renderToolCall = name === "*" ? (0,
|
|
4126
|
+
const renderToolCall = name === "*" ? (0, import_react31.defineToolCallRenderer)({
|
|
4143
4127
|
name: "*",
|
|
4144
4128
|
render: (args) => {
|
|
4145
4129
|
return render(__spreadProps(__spreadValues({}, args), {
|
|
4146
4130
|
result: args.result ? (0, import_shared19.parseJson)(args.result, args.result) : args.result
|
|
4147
4131
|
}));
|
|
4148
4132
|
}
|
|
4149
|
-
}) : (0,
|
|
4133
|
+
}) : (0, import_react31.defineToolCallRenderer)({
|
|
4150
4134
|
name,
|
|
4151
4135
|
args: zodParameters,
|
|
4152
4136
|
render: (args) => {
|
|
@@ -4175,18 +4159,18 @@ function useRenderToolCall2(tool, dependencies) {
|
|
|
4175
4159
|
|
|
4176
4160
|
// src/hooks/use-human-in-the-loop.ts
|
|
4177
4161
|
var import_shared20 = require("@copilotkit/shared");
|
|
4178
|
-
var
|
|
4162
|
+
var import_react32 = require("@copilotkitnext/react");
|
|
4179
4163
|
var import_core = require("@copilotkitnext/core");
|
|
4180
|
-
var
|
|
4164
|
+
var import_react33 = __toESM(require("react"));
|
|
4181
4165
|
function useHumanInTheLoop(tool, dependencies) {
|
|
4182
4166
|
const _a = tool, { render } = _a, toolRest = __objRest(_a, ["render"]);
|
|
4183
4167
|
const { name, description, parameters, followUp } = toolRest;
|
|
4184
4168
|
const zodParameters = (0, import_shared20.getZodParameters)(parameters);
|
|
4185
|
-
const renderRef = (0,
|
|
4186
|
-
(0,
|
|
4169
|
+
const renderRef = (0, import_react33.useRef)(null);
|
|
4170
|
+
(0, import_react33.useEffect)(() => {
|
|
4187
4171
|
renderRef.current = (args) => {
|
|
4188
4172
|
if (typeof render === "string") {
|
|
4189
|
-
return
|
|
4173
|
+
return import_react33.default.createElement(import_react33.default.Fragment, null, render);
|
|
4190
4174
|
}
|
|
4191
4175
|
if (!render) {
|
|
4192
4176
|
return null;
|
|
@@ -4226,12 +4210,12 @@ function useHumanInTheLoop(tool, dependencies) {
|
|
|
4226
4210
|
})();
|
|
4227
4211
|
const rendered = render(renderProps);
|
|
4228
4212
|
if (typeof rendered === "string") {
|
|
4229
|
-
return
|
|
4213
|
+
return import_react33.default.createElement(import_react33.default.Fragment, null, rendered);
|
|
4230
4214
|
}
|
|
4231
4215
|
return rendered != null ? rendered : null;
|
|
4232
4216
|
};
|
|
4233
4217
|
}, [render, ...dependencies != null ? dependencies : []]);
|
|
4234
|
-
(0,
|
|
4218
|
+
(0, import_react32.useHumanInTheLoop)({
|
|
4235
4219
|
name,
|
|
4236
4220
|
description,
|
|
4237
4221
|
followUp,
|
|
@@ -4287,7 +4271,7 @@ function getActionConfig(action) {
|
|
|
4287
4271
|
throw new Error("Invalid action configuration");
|
|
4288
4272
|
}
|
|
4289
4273
|
function useCopilotAction(action, dependencies) {
|
|
4290
|
-
const [initialActionConfig] = (0,
|
|
4274
|
+
const [initialActionConfig] = (0, import_react34.useState)(getActionConfig(action));
|
|
4291
4275
|
const currentActionConfig = getActionConfig(action);
|
|
4292
4276
|
if (initialActionConfig.type !== currentActionConfig.type) {
|
|
4293
4277
|
throw new Error("Action configuration changed between renders");
|
|
@@ -4305,14 +4289,14 @@ function useCopilotAction(action, dependencies) {
|
|
|
4305
4289
|
}
|
|
4306
4290
|
|
|
4307
4291
|
// src/hooks/use-coagent-state-render.ts
|
|
4308
|
-
var
|
|
4292
|
+
var import_react35 = require("react");
|
|
4309
4293
|
var import_shared21 = require("@copilotkit/shared");
|
|
4310
4294
|
function useCoAgentStateRender(action, dependencies) {
|
|
4311
|
-
const { chatComponentsCache, availableAgents } = (0,
|
|
4295
|
+
const { chatComponentsCache, availableAgents } = (0, import_react35.useContext)(CopilotContext);
|
|
4312
4296
|
const { setCoAgentStateRender, removeCoAgentStateRender, coAgentStateRenders } = useCoAgentStateRenders();
|
|
4313
|
-
const idRef = (0,
|
|
4297
|
+
const idRef = (0, import_react35.useRef)((0, import_shared21.randomId)());
|
|
4314
4298
|
const { setBannerError, addToast } = useToast();
|
|
4315
|
-
(0,
|
|
4299
|
+
(0, import_react35.useEffect)(() => {
|
|
4316
4300
|
if ((availableAgents == null ? void 0 : availableAgents.length) && !availableAgents.some((a) => a.name === action.name)) {
|
|
4317
4301
|
const message = `(useCoAgentStateRender): Agent "${action.name}" not found. Make sure the agent exists and is properly configured.`;
|
|
4318
4302
|
const agentError = new import_shared21.CopilotKitAgentDiscoveryError({
|
|
@@ -4333,7 +4317,7 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
4333
4317
|
}
|
|
4334
4318
|
}
|
|
4335
4319
|
}
|
|
4336
|
-
(0,
|
|
4320
|
+
(0, import_react35.useEffect)(() => {
|
|
4337
4321
|
const currentId = idRef.current;
|
|
4338
4322
|
const hasDuplicate = Object.entries(coAgentStateRenders).some(([id, otherAction]) => {
|
|
4339
4323
|
if (id === currentId)
|
|
@@ -4357,7 +4341,7 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
4357
4341
|
});
|
|
4358
4342
|
}
|
|
4359
4343
|
}, [coAgentStateRenders]);
|
|
4360
|
-
(0,
|
|
4344
|
+
(0, import_react35.useEffect)(() => {
|
|
4361
4345
|
setCoAgentStateRender(idRef.current, action);
|
|
4362
4346
|
if (chatComponentsCache.current !== null && action.render !== void 0) {
|
|
4363
4347
|
chatComponentsCache.current.coAgentStateRenders[key] = action.render;
|
|
@@ -4377,11 +4361,11 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
4377
4361
|
}
|
|
4378
4362
|
|
|
4379
4363
|
// src/hooks/use-make-copilot-document-readable.ts
|
|
4380
|
-
var
|
|
4364
|
+
var import_react36 = require("react");
|
|
4381
4365
|
function useMakeCopilotDocumentReadable(document2, categories, dependencies = []) {
|
|
4382
4366
|
const { addDocumentContext, removeDocumentContext } = useCopilotContext();
|
|
4383
|
-
const idRef = (0,
|
|
4384
|
-
(0,
|
|
4367
|
+
const idRef = (0, import_react36.useRef)(void 0);
|
|
4368
|
+
(0, import_react36.useEffect)(() => {
|
|
4385
4369
|
const id = addDocumentContext(document2, categories);
|
|
4386
4370
|
idRef.current = id;
|
|
4387
4371
|
return () => {
|
|
@@ -4392,21 +4376,46 @@ function useMakeCopilotDocumentReadable(document2, categories, dependencies = []
|
|
|
4392
4376
|
}
|
|
4393
4377
|
|
|
4394
4378
|
// src/hooks/use-copilot-readable.ts
|
|
4395
|
-
var
|
|
4396
|
-
|
|
4397
|
-
|
|
4398
|
-
|
|
4399
|
-
|
|
4400
|
-
|
|
4379
|
+
var import_react37 = require("@copilotkitnext/react");
|
|
4380
|
+
var import_react38 = require("react");
|
|
4381
|
+
function useCopilotReadable({ description, value, convert, available }, dependencies) {
|
|
4382
|
+
const { copilotkit } = (0, import_react37.useCopilotKit)();
|
|
4383
|
+
const ctxIdRef = (0, import_react38.useRef)(void 0);
|
|
4384
|
+
(0, import_react38.useEffect)(() => {
|
|
4385
|
+
if (!copilotkit)
|
|
4386
|
+
return;
|
|
4387
|
+
const found = Object.entries(copilotkit.context).find(([id, ctxItem]) => {
|
|
4388
|
+
return JSON.stringify({ description, value }) == JSON.stringify(ctxItem);
|
|
4389
|
+
});
|
|
4390
|
+
if (found) {
|
|
4391
|
+
ctxIdRef.current = found[0];
|
|
4392
|
+
if (available === "disabled")
|
|
4393
|
+
copilotkit.removeContext(ctxIdRef.current);
|
|
4394
|
+
return;
|
|
4395
|
+
}
|
|
4396
|
+
if (!found && available === "disabled")
|
|
4397
|
+
return;
|
|
4398
|
+
ctxIdRef.current = copilotkit.addContext({
|
|
4399
|
+
description,
|
|
4400
|
+
value: (convert != null ? convert : JSON.stringify)(value)
|
|
4401
|
+
});
|
|
4402
|
+
return () => {
|
|
4403
|
+
if (!ctxIdRef.current)
|
|
4404
|
+
return;
|
|
4405
|
+
copilotkit.removeContext(ctxIdRef.current);
|
|
4406
|
+
};
|
|
4407
|
+
}, [description, value, convert]);
|
|
4408
|
+
return ctxIdRef.current;
|
|
4401
4409
|
}
|
|
4402
4410
|
|
|
4403
4411
|
// src/hooks/use-coagent.ts
|
|
4404
|
-
var
|
|
4405
|
-
var
|
|
4412
|
+
var import_react39 = require("react");
|
|
4413
|
+
var import_react40 = require("@copilotkitnext/react");
|
|
4406
4414
|
function useCoAgent(options) {
|
|
4407
|
-
const { agent } = (0,
|
|
4408
|
-
const
|
|
4409
|
-
const
|
|
4415
|
+
const { agent } = (0, import_react40.useAgent)({ agentId: options.name });
|
|
4416
|
+
const { copilotkit } = (0, import_react40.useCopilotKit)();
|
|
4417
|
+
const nodeName = useAgentNodeName(options.name);
|
|
4418
|
+
const handleStateUpdate = (0, import_react39.useCallback)(
|
|
4410
4419
|
(newState) => {
|
|
4411
4420
|
if (!agent)
|
|
4412
4421
|
return;
|
|
@@ -4419,22 +4428,34 @@ function useCoAgent(options) {
|
|
|
4419
4428
|
},
|
|
4420
4429
|
[agent == null ? void 0 : agent.state, agent == null ? void 0 : agent.setState]
|
|
4421
4430
|
);
|
|
4422
|
-
|
|
4431
|
+
(0, import_react39.useEffect)(() => {
|
|
4432
|
+
var _a;
|
|
4433
|
+
if (!options.config && !options.configurable)
|
|
4434
|
+
return;
|
|
4435
|
+
let config = (_a = options.config) != null ? _a : {};
|
|
4436
|
+
if (options.configurable) {
|
|
4437
|
+
config = __spreadProps(__spreadValues({}, config), {
|
|
4438
|
+
configurable: __spreadValues(__spreadValues({}, options.configurable), config.configurable)
|
|
4439
|
+
});
|
|
4440
|
+
}
|
|
4441
|
+
copilotkit.setProperties(config);
|
|
4442
|
+
}, [options.config, options.configurable]);
|
|
4443
|
+
const externalStateStr = (0, import_react39.useMemo)(
|
|
4423
4444
|
() => isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0,
|
|
4424
4445
|
[isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0]
|
|
4425
4446
|
);
|
|
4426
|
-
(0,
|
|
4447
|
+
(0, import_react39.useEffect)(() => {
|
|
4427
4448
|
if ((agent == null ? void 0 : agent.state) && isExternalStateManagement(options) && JSON.stringify(options.state) !== JSON.stringify(agent.state)) {
|
|
4428
4449
|
handleStateUpdate(options.state);
|
|
4429
4450
|
}
|
|
4430
4451
|
}, [agent, externalStateStr, handleStateUpdate]);
|
|
4431
|
-
const hasStateValues = (0,
|
|
4452
|
+
const hasStateValues = (0, import_react39.useCallback)((value) => {
|
|
4432
4453
|
return Boolean(value && Object.keys(value).length);
|
|
4433
4454
|
}, []);
|
|
4434
|
-
const initialStateRef = (0,
|
|
4455
|
+
const initialStateRef = (0, import_react39.useRef)(
|
|
4435
4456
|
isExternalStateManagement(options) ? options.state : "initialState" in options ? options.initialState : void 0
|
|
4436
4457
|
);
|
|
4437
|
-
(0,
|
|
4458
|
+
(0, import_react39.useEffect)(() => {
|
|
4438
4459
|
if (isExternalStateManagement(options)) {
|
|
4439
4460
|
initialStateRef.current = options.state;
|
|
4440
4461
|
} else if ("initialState" in options) {
|
|
@@ -4443,7 +4464,7 @@ function useCoAgent(options) {
|
|
|
4443
4464
|
}, [
|
|
4444
4465
|
isExternalStateManagement(options) ? JSON.stringify(options.state) : "initialState" in options ? JSON.stringify(options.initialState) : void 0
|
|
4445
4466
|
]);
|
|
4446
|
-
(0,
|
|
4467
|
+
(0, import_react39.useEffect)(() => {
|
|
4447
4468
|
if (!agent)
|
|
4448
4469
|
return;
|
|
4449
4470
|
const subscriber = {
|
|
@@ -4464,15 +4485,6 @@ function useCoAgent(options) {
|
|
|
4464
4485
|
if (initialStateRef.current !== void 0) {
|
|
4465
4486
|
handleStateUpdate(initialStateRef.current);
|
|
4466
4487
|
}
|
|
4467
|
-
},
|
|
4468
|
-
onStepStartedEvent: ({ event }) => {
|
|
4469
|
-
nodeNameRef.current = event.stepName;
|
|
4470
|
-
},
|
|
4471
|
-
onRunStartedEvent: () => {
|
|
4472
|
-
nodeNameRef.current = "start";
|
|
4473
|
-
},
|
|
4474
|
-
onRunFinishedEvent: () => {
|
|
4475
|
-
nodeNameRef.current = "end";
|
|
4476
4488
|
}
|
|
4477
4489
|
};
|
|
4478
4490
|
const subscription = agent.subscribe(subscriber);
|
|
@@ -4480,7 +4492,7 @@ function useCoAgent(options) {
|
|
|
4480
4492
|
subscription.unsubscribe();
|
|
4481
4493
|
};
|
|
4482
4494
|
}, [agent, handleStateUpdate, hasStateValues]);
|
|
4483
|
-
return (0,
|
|
4495
|
+
return (0, import_react39.useMemo)(() => {
|
|
4484
4496
|
var _a, _b, _c;
|
|
4485
4497
|
if (!agent) {
|
|
4486
4498
|
const noop = () => {
|
|
@@ -4496,7 +4508,7 @@ function useCoAgent(options) {
|
|
|
4496
4508
|
);
|
|
4497
4509
|
return {
|
|
4498
4510
|
name: options.name,
|
|
4499
|
-
nodeName
|
|
4511
|
+
nodeName,
|
|
4500
4512
|
threadId: void 0,
|
|
4501
4513
|
running: false,
|
|
4502
4514
|
state: initialState,
|
|
@@ -4508,7 +4520,7 @@ function useCoAgent(options) {
|
|
|
4508
4520
|
}
|
|
4509
4521
|
return {
|
|
4510
4522
|
name: (_c = agent == null ? void 0 : agent.agentId) != null ? _c : options.name,
|
|
4511
|
-
nodeName
|
|
4523
|
+
nodeName,
|
|
4512
4524
|
threadId: agent.threadId,
|
|
4513
4525
|
running: agent.isRunning,
|
|
4514
4526
|
state: agent.state,
|
|
@@ -4536,12 +4548,12 @@ var isExternalStateManagement = (options) => {
|
|
|
4536
4548
|
|
|
4537
4549
|
// src/hooks/use-copilot-runtime-client.ts
|
|
4538
4550
|
var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
|
|
4539
|
-
var
|
|
4551
|
+
var import_react41 = require("react");
|
|
4540
4552
|
var import_shared22 = require("@copilotkit/shared");
|
|
4541
4553
|
var useCopilotRuntimeClient = (options) => {
|
|
4542
4554
|
const { setBannerError } = useToast();
|
|
4543
4555
|
const _a = options, { showDevConsole, onError } = _a, runtimeOptions = __objRest(_a, ["showDevConsole", "onError"]);
|
|
4544
|
-
const lastStructuredErrorRef = (0,
|
|
4556
|
+
const lastStructuredErrorRef = (0, import_react41.useRef)(null);
|
|
4545
4557
|
const traceUIError = (error, originalError) => __async(void 0, null, function* () {
|
|
4546
4558
|
try {
|
|
4547
4559
|
const errorEvent = {
|
|
@@ -4567,7 +4579,7 @@ var useCopilotRuntimeClient = (options) => {
|
|
|
4567
4579
|
console.error("Error in onError handler:", error2);
|
|
4568
4580
|
}
|
|
4569
4581
|
});
|
|
4570
|
-
const runtimeClient = (0,
|
|
4582
|
+
const runtimeClient = (0, import_react41.useMemo)(() => {
|
|
4571
4583
|
return new import_runtime_client_gql3.CopilotRuntimeClient(__spreadProps(__spreadValues({}, runtimeOptions), {
|
|
4572
4584
|
handleGQLErrors: (error) => {
|
|
4573
4585
|
var _a2;
|
|
@@ -4646,28 +4658,28 @@ function createStructuredError(gqlError) {
|
|
|
4646
4658
|
}
|
|
4647
4659
|
|
|
4648
4660
|
// src/hooks/use-copilot-authenticated-action.ts
|
|
4649
|
-
var
|
|
4650
|
-
var
|
|
4661
|
+
var import_react42 = require("react");
|
|
4662
|
+
var import_react43 = __toESM(require("react"));
|
|
4651
4663
|
function useCopilotAuthenticatedAction_c(action, dependencies) {
|
|
4652
4664
|
const { authConfig_c, authStates_c, setAuthStates_c } = useCopilotContext();
|
|
4653
|
-
const pendingActionRef = (0,
|
|
4654
|
-
const executeAction = (0,
|
|
4665
|
+
const pendingActionRef = (0, import_react42.useRef)(null);
|
|
4666
|
+
const executeAction = (0, import_react42.useCallback)(
|
|
4655
4667
|
(props) => {
|
|
4656
4668
|
if (typeof action.render === "function") {
|
|
4657
4669
|
return action.render(props);
|
|
4658
4670
|
}
|
|
4659
|
-
return action.render ||
|
|
4671
|
+
return action.render || import_react43.default.createElement(import_react42.Fragment);
|
|
4660
4672
|
},
|
|
4661
4673
|
[action]
|
|
4662
4674
|
);
|
|
4663
|
-
const wrappedRender = (0,
|
|
4675
|
+
const wrappedRender = (0, import_react42.useCallback)(
|
|
4664
4676
|
(props) => {
|
|
4665
4677
|
const isAuthenticated = Object.values(authStates_c || {}).some(
|
|
4666
4678
|
(state) => state.status === "authenticated"
|
|
4667
4679
|
);
|
|
4668
4680
|
if (!isAuthenticated) {
|
|
4669
4681
|
pendingActionRef.current = props;
|
|
4670
|
-
return (authConfig_c == null ? void 0 : authConfig_c.SignInComponent) ?
|
|
4682
|
+
return (authConfig_c == null ? void 0 : authConfig_c.SignInComponent) ? import_react43.default.createElement(authConfig_c.SignInComponent, {
|
|
4671
4683
|
onSignInComplete: (authState) => {
|
|
4672
4684
|
setAuthStates_c == null ? void 0 : setAuthStates_c((prev) => __spreadProps(__spreadValues({}, prev), { [action.name]: authState }));
|
|
4673
4685
|
if (pendingActionRef.current) {
|
|
@@ -4675,7 +4687,7 @@ function useCopilotAuthenticatedAction_c(action, dependencies) {
|
|
|
4675
4687
|
pendingActionRef.current = null;
|
|
4676
4688
|
}
|
|
4677
4689
|
}
|
|
4678
|
-
}) :
|
|
4690
|
+
}) : import_react43.default.createElement(import_react42.Fragment);
|
|
4679
4691
|
}
|
|
4680
4692
|
return executeAction(props);
|
|
4681
4693
|
},
|
|
@@ -4690,16 +4702,16 @@ function useCopilotAuthenticatedAction_c(action, dependencies) {
|
|
|
4690
4702
|
}
|
|
4691
4703
|
|
|
4692
4704
|
// src/hooks/use-langgraph-interrupt.ts
|
|
4693
|
-
var
|
|
4705
|
+
var import_react44 = require("react");
|
|
4694
4706
|
var import_shared23 = require("@copilotkit/shared");
|
|
4695
4707
|
function useLangGraphInterrupt(action, dependencies) {
|
|
4696
|
-
const { setInterruptAction, removeInterruptAction, interruptActions, threadId } = (0,
|
|
4708
|
+
const { setInterruptAction, removeInterruptAction, interruptActions, threadId } = (0, import_react44.useContext)(CopilotContext);
|
|
4697
4709
|
const { addToast } = useToast();
|
|
4698
|
-
const actionId = (0, import_shared23.dataToUUID)(
|
|
4699
|
-
(0,
|
|
4710
|
+
const actionId = (0, import_shared23.dataToUUID)(action, "lgAction");
|
|
4711
|
+
(0, import_react44.useEffect)(() => {
|
|
4700
4712
|
if (!action)
|
|
4701
4713
|
return;
|
|
4702
|
-
setInterruptAction(
|
|
4714
|
+
setInterruptAction(__spreadProps(__spreadValues({}, action), { id: actionId }));
|
|
4703
4715
|
return () => {
|
|
4704
4716
|
removeInterruptAction(actionId);
|
|
4705
4717
|
};
|
|
@@ -4707,10 +4719,10 @@ function useLangGraphInterrupt(action, dependencies) {
|
|
|
4707
4719
|
}
|
|
4708
4720
|
|
|
4709
4721
|
// src/hooks/use-copilot-additional-instructions.ts
|
|
4710
|
-
var
|
|
4722
|
+
var import_react45 = require("react");
|
|
4711
4723
|
function useCopilotAdditionalInstructions({ instructions, available = "enabled" }, dependencies) {
|
|
4712
4724
|
const { setAdditionalInstructions } = useCopilotContext();
|
|
4713
|
-
(0,
|
|
4725
|
+
(0, import_react45.useEffect)(() => {
|
|
4714
4726
|
if (available === "disabled")
|
|
4715
4727
|
return;
|
|
4716
4728
|
setAdditionalInstructions((prevInstructions) => [...prevInstructions || [], instructions]);
|
|
@@ -4727,6 +4739,21 @@ function useDefaultTool(tool, dependencies) {
|
|
|
4727
4739
|
useCopilotAction(__spreadProps(__spreadValues({}, tool), { name: "*" }), dependencies);
|
|
4728
4740
|
}
|
|
4729
4741
|
|
|
4742
|
+
// src/hooks/use-copilot-chat-suggestions.tsx
|
|
4743
|
+
var import_react46 = require("@copilotkitnext/react");
|
|
4744
|
+
function useCopilotChatSuggestions(config, dependencies = []) {
|
|
4745
|
+
var _a, _b;
|
|
4746
|
+
const existingConfig = (0, import_react46.useCopilotChatConfiguration)();
|
|
4747
|
+
const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
|
|
4748
|
+
const available = (_b = config.available === "enabled" ? "always" : config.available) != null ? _b : "before-first-message";
|
|
4749
|
+
const finalSuggestionConfig = __spreadProps(__spreadValues({}, config), {
|
|
4750
|
+
available,
|
|
4751
|
+
consumerAgentId: resolvedAgentId
|
|
4752
|
+
// Use chatConfig.agentId here
|
|
4753
|
+
});
|
|
4754
|
+
(0, import_react46.useConfigureSuggestions)(finalSuggestionConfig, dependencies);
|
|
4755
|
+
}
|
|
4756
|
+
|
|
4730
4757
|
// src/lib/copilot-task.ts
|
|
4731
4758
|
var import_runtime_client_gql5 = require("@copilotkit/runtime-client-gql");
|
|
4732
4759
|
|
|
@@ -4866,13 +4893,13 @@ ${instructions}
|
|
|
4866
4893
|
useCoAgent,
|
|
4867
4894
|
useCoAgentStateRender,
|
|
4868
4895
|
useCoAgentStateRenders,
|
|
4869
|
-
useConfigureChatSuggestions,
|
|
4870
4896
|
useCopilotAction,
|
|
4871
4897
|
useCopilotAdditionalInstructions,
|
|
4872
4898
|
useCopilotAuthenticatedAction_c,
|
|
4873
4899
|
useCopilotChat,
|
|
4874
4900
|
useCopilotChatHeadless_c,
|
|
4875
4901
|
useCopilotChatInternal,
|
|
4902
|
+
useCopilotChatSuggestions,
|
|
4876
4903
|
useCopilotContext,
|
|
4877
4904
|
useCopilotMessagesContext,
|
|
4878
4905
|
useCopilotReadable,
|