@copilotkit/react-core 1.50.0-beta.1 → 1.50.0-beta.2
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 +7 -0
- package/dist/{chunk-IUSKVYUI.mjs → chunk-2CYJN455.mjs} +2 -1
- package/dist/{chunk-IUSKVYUI.mjs.map → chunk-2CYJN455.mjs.map} +1 -1
- package/dist/{chunk-UJBV5GAG.mjs → chunk-6F7Q6CPI.mjs} +17 -36
- package/dist/chunk-6F7Q6CPI.mjs.map +1 -0
- package/dist/{chunk-JRT5BJF3.mjs → chunk-6SK26J65.mjs} +2 -2
- package/dist/{chunk-3GURHDG7.mjs → chunk-BPJ6V4YX.mjs} +2 -2
- package/dist/{chunk-TXI72QHK.mjs → chunk-EG56H77V.mjs} +2 -2
- package/dist/{chunk-3R423LZT.mjs → chunk-EHXVGFWN.mjs} +2 -2
- package/dist/{chunk-CB7CRBDG.mjs → chunk-FBVI3LQ6.mjs} +11 -11
- package/dist/chunk-FBVI3LQ6.mjs.map +1 -0
- package/dist/chunk-I76HKHPJ.mjs +32 -0
- package/dist/chunk-I76HKHPJ.mjs.map +1 -0
- package/dist/{chunk-R4MR43UQ.mjs → chunk-ISNVEPPQ.mjs} +17 -3
- package/dist/chunk-ISNVEPPQ.mjs.map +1 -0
- package/dist/{chunk-FBD24VEH.mjs → chunk-LD3MGPZB.mjs} +1 -1
- package/dist/{chunk-FBD24VEH.mjs.map → chunk-LD3MGPZB.mjs.map} +1 -1
- package/dist/{chunk-GMI4KO4X.mjs → chunk-OAEX7G5G.mjs} +2 -2
- package/dist/{chunk-DCHSCK62.mjs → chunk-SD7TUPQM.mjs} +13 -14
- package/dist/chunk-SD7TUPQM.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-NROJOTQP.mjs → chunk-TGIWTM6S.mjs} +8 -5
- package/dist/chunk-TGIWTM6S.mjs.map +1 -0
- package/dist/{chunk-QU6NONOD.mjs → chunk-U2ZRVVKT.mjs} +2 -2
- package/dist/{chunk-5X5DJRQQ.mjs → chunk-WF65O6HX.mjs} +2 -7
- package/dist/chunk-WF65O6HX.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.map +1 -1
- package/dist/components/copilot-provider/copilot-messages.mjs +1 -1
- 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 +11 -11
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +6 -6
- package/dist/components/copilot-provider/index.d.ts +1 -1
- package/dist/components/copilot-provider/index.js +11 -11
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +6 -6
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.js +11 -11
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +6 -6
- package/dist/context/copilot-context.d.ts +1 -1
- package/dist/context/index.d.ts +1 -1
- package/dist/{copilot-context-1cd70a3f.d.ts → copilot-context-81022020.d.ts} +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +187 -155
- 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-agent-nodename.mjs.map +1 -0
- package/dist/hooks/use-coagent-state-render-bridge.js +7 -4
- package/dist/hooks/use-coagent-state-render-bridge.js.map +1 -1
- package/dist/hooks/use-coagent-state-render-bridge.mjs +1 -1
- 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-configure-chat-suggestions.js +13 -144
- package/dist/hooks/use-configure-chat-suggestions.js.map +1 -1
- package/dist/hooks/use-configure-chat-suggestions.mjs +1 -6
- 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-authenticated-action.js +5 -1
- package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
- package/dist/hooks/use-copilot-authenticated-action.mjs +3 -3
- package/dist/hooks/use-copilot-chat-headless_c.js +107 -84
- package/dist/hooks/use-copilot-chat-headless_c.js.map +1 -1
- package/dist/hooks/use-copilot-chat-headless_c.mjs +6 -5
- package/dist/hooks/use-copilot-chat.js +105 -82
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +6 -5
- package/dist/hooks/use-copilot-chat_internal.d.ts +1 -1
- package/dist/hooks/use-copilot-chat_internal.js +105 -82
- package/dist/hooks/use-copilot-chat_internal.js.map +1 -1
- package/dist/hooks/use-copilot-chat_internal.mjs +5 -4
- package/dist/hooks/use-copilot-readable.d.ts +1 -1
- package/dist/hooks/use-copilot-readable.js +1 -0
- 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 +61 -7
- package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt-render.mjs +2 -1
- package/dist/hooks/use-langgraph-interrupt.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +184 -155
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +31 -30
- package/dist/lib/copilot-task.d.ts +1 -1
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +7 -7
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +7 -7
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.mjs +1 -1
- package/dist/types/interrupt-action.d.ts +1 -1
- package/dist/types/interrupt-action.js.map +1 -1
- package/jest.config.js +12 -0
- package/package.json +7 -6
- package/src/components/CopilotListeners.tsx +1 -2
- package/src/components/copilot-provider/copilot-messages.tsx +0 -41
- package/src/components/copilot-provider/copilotkit.tsx +2 -2
- package/src/hooks/__tests__/use-coagent-config.test.ts +189 -129
- package/src/hooks/use-agent-nodename.ts +30 -0
- package/src/hooks/use-coagent-state-render-bridge.tsx +20 -20
- package/src/hooks/use-coagent.ts +22 -13
- package/src/hooks/use-configure-chat-suggestions.tsx +8 -7
- package/src/hooks/use-copilot-chat_internal.ts +44 -42
- package/src/hooks/use-copilot-readable.ts +2 -1
- package/src/hooks/use-frontend-tool.ts +10 -2
- package/src/hooks/use-langgraph-interrupt-render.ts +10 -2
- package/src/types/interrupt-action.ts +1 -1
- package/dist/chunk-24SCZAB4.mjs.map +0 -1
- package/dist/chunk-5X5DJRQQ.mjs.map +0 -1
- package/dist/chunk-CB7CRBDG.mjs.map +0 -1
- package/dist/chunk-DCHSCK62.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/{chunk-JRT5BJF3.mjs.map → chunk-6SK26J65.mjs.map} +0 -0
- /package/dist/{chunk-3GURHDG7.mjs.map → chunk-BPJ6V4YX.mjs.map} +0 -0
- /package/dist/{chunk-TXI72QHK.mjs.map → chunk-EG56H77V.mjs.map} +0 -0
- /package/dist/{chunk-3R423LZT.mjs.map → chunk-EHXVGFWN.mjs.map} +0 -0
- /package/dist/{chunk-GMI4KO4X.mjs.map → chunk-OAEX7G5G.mjs.map} +0 -0
- /package/dist/{chunk-QU6NONOD.mjs.map → chunk-U2ZRVVKT.mjs.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -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]) => {
|
|
@@ -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);
|
|
@@ -2662,12 +2663,11 @@ function CopilotKit(_a) {
|
|
|
2662
2663
|
const renderArr = (0, import_react17.useMemo)(() => [{ render: CoAgentStateRenderBridge }], []);
|
|
2663
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)(
|
|
2664
2665
|
import_react18.CopilotKitProvider,
|
|
2665
|
-
{
|
|
2666
|
-
runtimeUrl: props.runtimeUrl,
|
|
2666
|
+
__spreadProps(__spreadValues({}, props), {
|
|
2667
2667
|
renderCustomMessages: renderArr,
|
|
2668
2668
|
useSingleEndpoint: true,
|
|
2669
2669
|
children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(CopilotKitInternal, __spreadProps(__spreadValues({}, props), { children }))
|
|
2670
|
-
}
|
|
2670
|
+
})
|
|
2671
2671
|
) }) }) });
|
|
2672
2672
|
}
|
|
2673
2673
|
function CopilotKitInternal(cpkProps) {
|
|
@@ -3005,7 +3005,7 @@ ${nonDocumentStrings}`;
|
|
|
3005
3005
|
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
3006
3006
|
import_react18.CopilotChatConfigurationProvider,
|
|
3007
3007
|
{
|
|
3008
|
-
agentId: (_b =
|
|
3008
|
+
agentId: (_b = props.agent) != null ? _b : "default",
|
|
3009
3009
|
threadId,
|
|
3010
3010
|
children: /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
|
|
3011
3011
|
CopilotContext.Provider,
|
|
@@ -3137,17 +3137,49 @@ function validateProps(props) {
|
|
|
3137
3137
|
}
|
|
3138
3138
|
|
|
3139
3139
|
// src/hooks/use-copilot-chat_internal.ts
|
|
3140
|
-
var
|
|
3140
|
+
var import_react27 = require("react");
|
|
3141
3141
|
var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
|
|
3142
3142
|
|
|
3143
3143
|
// src/hooks/use-langgraph-interrupt-render.ts
|
|
3144
|
-
var
|
|
3144
|
+
var import_react21 = __toESM(require("react"));
|
|
3145
3145
|
var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
|
|
3146
3146
|
var import_shared14 = require("@copilotkit/shared");
|
|
3147
|
+
|
|
3148
|
+
// src/hooks/use-agent-nodename.ts
|
|
3149
|
+
var import_react19 = require("react");
|
|
3150
|
+
var import_react20 = require("@copilotkitnext/react");
|
|
3151
|
+
function useAgentNodeName(agentName) {
|
|
3152
|
+
const { agent } = (0, import_react20.useAgent)({ agentId: agentName });
|
|
3153
|
+
const nodeNameRef = (0, import_react19.useRef)("start");
|
|
3154
|
+
(0, import_react19.useEffect)(() => {
|
|
3155
|
+
if (!agent)
|
|
3156
|
+
return;
|
|
3157
|
+
const subscriber = {
|
|
3158
|
+
onStepStartedEvent: ({ event }) => {
|
|
3159
|
+
nodeNameRef.current = event.stepName;
|
|
3160
|
+
},
|
|
3161
|
+
onRunStartedEvent: () => {
|
|
3162
|
+
nodeNameRef.current = "start";
|
|
3163
|
+
},
|
|
3164
|
+
onRunFinishedEvent: () => {
|
|
3165
|
+
nodeNameRef.current = "end";
|
|
3166
|
+
}
|
|
3167
|
+
};
|
|
3168
|
+
const subscription = agent.subscribe(subscriber);
|
|
3169
|
+
return () => {
|
|
3170
|
+
subscription.unsubscribe();
|
|
3171
|
+
};
|
|
3172
|
+
}, [agent]);
|
|
3173
|
+
return nodeNameRef.current;
|
|
3174
|
+
}
|
|
3175
|
+
|
|
3176
|
+
// src/hooks/use-langgraph-interrupt-render.ts
|
|
3177
|
+
var import_react22 = require("@copilotkitnext/react");
|
|
3147
3178
|
var InterruptRenderer = ({ event, result, render, resolve }) => {
|
|
3148
3179
|
return render({ event, result, resolve });
|
|
3149
3180
|
};
|
|
3150
3181
|
function useLangGraphInterruptRender(agent) {
|
|
3182
|
+
var _a;
|
|
3151
3183
|
const {
|
|
3152
3184
|
interruptActions,
|
|
3153
3185
|
agentSession,
|
|
@@ -3156,7 +3188,10 @@ function useLangGraphInterruptRender(agent) {
|
|
|
3156
3188
|
addInterruptEvent,
|
|
3157
3189
|
removeInterruptEvent
|
|
3158
3190
|
} = useCopilotContext();
|
|
3159
|
-
(0,
|
|
3191
|
+
const existingConfig = (0, import_react22.useCopilotChatConfiguration)();
|
|
3192
|
+
const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
|
|
3193
|
+
const nodeName = useAgentNodeName(resolvedAgentId);
|
|
3194
|
+
(0, import_react21.useEffect)(() => {
|
|
3160
3195
|
if (!agent)
|
|
3161
3196
|
return;
|
|
3162
3197
|
const subscriber = {
|
|
@@ -3181,7 +3216,7 @@ function useLangGraphInterruptRender(agent) {
|
|
|
3181
3216
|
unsubscribe();
|
|
3182
3217
|
};
|
|
3183
3218
|
}, [agent, threadId]);
|
|
3184
|
-
const handleResolve = (0,
|
|
3219
|
+
const handleResolve = (0, import_react21.useCallback)(
|
|
3185
3220
|
(eventId, response) => {
|
|
3186
3221
|
agent == null ? void 0 : agent.runAgent({
|
|
3187
3222
|
forwardedProps: {
|
|
@@ -3195,10 +3230,10 @@ function useLangGraphInterruptRender(agent) {
|
|
|
3195
3230
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3196
3231
|
[agent, threadId]
|
|
3197
3232
|
);
|
|
3198
|
-
return (0,
|
|
3233
|
+
return (0, import_react21.useMemo)(() => {
|
|
3199
3234
|
const eventQueue = interruptEventQueue[threadId] || [];
|
|
3200
3235
|
const currentQueuedEvent = eventQueue.find((qe) => !qe.event.response);
|
|
3201
|
-
if (!currentQueuedEvent)
|
|
3236
|
+
if (!currentQueuedEvent || !agentSession)
|
|
3202
3237
|
return null;
|
|
3203
3238
|
const allActions = Object.values(interruptActions);
|
|
3204
3239
|
const matchingAction = allActions.find((action) => {
|
|
@@ -3206,7 +3241,9 @@ function useLangGraphInterruptRender(agent) {
|
|
|
3206
3241
|
return true;
|
|
3207
3242
|
return action.enabled({
|
|
3208
3243
|
eventValue: currentQueuedEvent.event.value,
|
|
3209
|
-
agentMetadata: agentSession
|
|
3244
|
+
agentMetadata: __spreadProps(__spreadValues({}, agentSession), {
|
|
3245
|
+
nodeName
|
|
3246
|
+
})
|
|
3210
3247
|
});
|
|
3211
3248
|
});
|
|
3212
3249
|
if (!matchingAction)
|
|
@@ -3224,7 +3261,7 @@ function useLangGraphInterruptRender(agent) {
|
|
|
3224
3261
|
}
|
|
3225
3262
|
if (!render)
|
|
3226
3263
|
return null;
|
|
3227
|
-
return
|
|
3264
|
+
return import_react21.default.createElement(InterruptRenderer, {
|
|
3228
3265
|
event: currentQueuedEvent.event,
|
|
3229
3266
|
result,
|
|
3230
3267
|
render,
|
|
@@ -3234,14 +3271,14 @@ function useLangGraphInterruptRender(agent) {
|
|
|
3234
3271
|
}
|
|
3235
3272
|
|
|
3236
3273
|
// src/hooks/use-copilot-chat_internal.ts
|
|
3237
|
-
var
|
|
3274
|
+
var import_react28 = require("@copilotkitnext/react");
|
|
3238
3275
|
|
|
3239
3276
|
// src/hooks/use-lazy-tool-renderer.tsx
|
|
3240
|
-
var
|
|
3241
|
-
var
|
|
3277
|
+
var import_react23 = require("@copilotkitnext/react");
|
|
3278
|
+
var import_react24 = require("react");
|
|
3242
3279
|
function useLazyToolRenderer() {
|
|
3243
|
-
const renderToolCall = (0,
|
|
3244
|
-
return (0,
|
|
3280
|
+
const renderToolCall = (0, import_react23.useRenderToolCall)();
|
|
3281
|
+
return (0, import_react24.useCallback)(
|
|
3245
3282
|
(message, messages) => {
|
|
3246
3283
|
var _a;
|
|
3247
3284
|
if (!((_a = message == null ? void 0 : message.toolCalls) == null ? void 0 : _a.length))
|
|
@@ -3262,34 +3299,36 @@ function useLazyToolRenderer() {
|
|
|
3262
3299
|
}
|
|
3263
3300
|
|
|
3264
3301
|
// src/hooks/use-configure-chat-suggestions.tsx
|
|
3265
|
-
var
|
|
3266
|
-
var
|
|
3302
|
+
var import_react25 = require("@copilotkitnext/react");
|
|
3303
|
+
var import_react26 = require("react");
|
|
3267
3304
|
function useConfigureChatSuggestions(config, dependencies = []) {
|
|
3268
|
-
|
|
3269
|
-
const
|
|
3305
|
+
var _a;
|
|
3306
|
+
const existingConfig = (0, import_react25.useCopilotChatConfiguration)();
|
|
3307
|
+
const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
|
|
3308
|
+
const { copilotkit } = (0, import_react25.useCopilotKit)();
|
|
3270
3309
|
const available = config.available === "enabled" ? "always" : config.available;
|
|
3271
3310
|
const finalSuggestionConfig = __spreadProps(__spreadValues({}, config), {
|
|
3272
3311
|
available,
|
|
3273
|
-
consumerAgentId:
|
|
3312
|
+
consumerAgentId: resolvedAgentId
|
|
3274
3313
|
// Use chatConfig.agentId here
|
|
3275
3314
|
});
|
|
3276
|
-
(0,
|
|
3277
|
-
const result = (0,
|
|
3278
|
-
(0,
|
|
3315
|
+
(0, import_react25.useConfigureSuggestions)(finalSuggestionConfig, dependencies);
|
|
3316
|
+
const result = (0, import_react25.useSuggestions)({ agentId: resolvedAgentId });
|
|
3317
|
+
(0, import_react26.useEffect)(() => {
|
|
3279
3318
|
if (finalSuggestionConfig.available === "disabled")
|
|
3280
3319
|
return;
|
|
3281
3320
|
const subscription = copilotkit.subscribe({
|
|
3282
3321
|
onAgentsChanged: () => {
|
|
3283
|
-
const agent = copilotkit.getAgent(
|
|
3322
|
+
const agent = copilotkit.getAgent(resolvedAgentId);
|
|
3284
3323
|
if (agent && !agent.isRunning && !result.suggestions.length) {
|
|
3285
|
-
copilotkit.reloadSuggestions(
|
|
3324
|
+
copilotkit.reloadSuggestions(resolvedAgentId);
|
|
3286
3325
|
}
|
|
3287
3326
|
}
|
|
3288
3327
|
});
|
|
3289
3328
|
return () => {
|
|
3290
3329
|
subscription.unsubscribe();
|
|
3291
3330
|
};
|
|
3292
|
-
}, []);
|
|
3331
|
+
}, [resolvedAgentId]);
|
|
3293
3332
|
return result;
|
|
3294
3333
|
}
|
|
3295
3334
|
|
|
@@ -3719,15 +3758,15 @@ function useConfigureSuggestions2(suggestions) {
|
|
|
3719
3758
|
function useCopilotChatInternal({
|
|
3720
3759
|
suggestions
|
|
3721
3760
|
} = {}) {
|
|
3722
|
-
var _a, _b, _c
|
|
3723
|
-
const { copilotkit } = (0,
|
|
3761
|
+
var _a, _b, _c;
|
|
3762
|
+
const { copilotkit } = (0, import_react28.useCopilotKit)();
|
|
3724
3763
|
const { threadId, agentSession } = useCopilotContext();
|
|
3725
|
-
const existingConfig = (0,
|
|
3726
|
-
const [agentAvailable, setAgentAvailable] = (0,
|
|
3764
|
+
const existingConfig = (0, import_react28.useCopilotChatConfiguration)();
|
|
3765
|
+
const [agentAvailable, setAgentAvailable] = (0, import_react27.useState)(false);
|
|
3727
3766
|
useConfigureSuggestions2(suggestions);
|
|
3728
|
-
const resolvedAgentId = (
|
|
3729
|
-
const { agent } = (0,
|
|
3730
|
-
(0,
|
|
3767
|
+
const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
|
|
3768
|
+
const { agent } = (0, import_react28.useAgent)({ agentId: resolvedAgentId });
|
|
3769
|
+
(0, import_react27.useEffect)(() => {
|
|
3731
3770
|
const connect = (agent2) => __async(this, null, function* () {
|
|
3732
3771
|
setAgentAvailable(false);
|
|
3733
3772
|
try {
|
|
@@ -3752,7 +3791,7 @@ function useCopilotChatInternal({
|
|
|
3752
3791
|
agent == null ? void 0 : agent.setMessages([]);
|
|
3753
3792
|
agent == null ? void 0 : agent.setState(null);
|
|
3754
3793
|
};
|
|
3755
|
-
const deleteMessage = (0,
|
|
3794
|
+
const deleteMessage = (0, import_react27.useCallback)(
|
|
3756
3795
|
(messageId) => {
|
|
3757
3796
|
var _a2;
|
|
3758
3797
|
const filteredMessages = ((_a2 = agent == null ? void 0 : agent.messages) != null ? _a2 : []).filter(
|
|
@@ -3763,13 +3802,13 @@ function useCopilotChatInternal({
|
|
|
3763
3802
|
[agent == null ? void 0 : agent.setMessages, agent == null ? void 0 : agent.messages]
|
|
3764
3803
|
);
|
|
3765
3804
|
const latestDelete = useUpdatedRef(deleteMessage);
|
|
3766
|
-
const latestDeleteFunc = (0,
|
|
3805
|
+
const latestDeleteFunc = (0, import_react27.useCallback)(
|
|
3767
3806
|
(messageId) => {
|
|
3768
3807
|
return latestDelete.current(messageId);
|
|
3769
3808
|
},
|
|
3770
3809
|
[latestDelete]
|
|
3771
3810
|
);
|
|
3772
|
-
const currentSuggestions = (0,
|
|
3811
|
+
const currentSuggestions = (0, import_react28.useSuggestions)({ agentId: resolvedAgentId });
|
|
3773
3812
|
const reload = useAsyncCallback(
|
|
3774
3813
|
(reloadMessageId) => __async(this, null, function* () {
|
|
3775
3814
|
var _a2;
|
|
@@ -3837,7 +3876,7 @@ function useCopilotChatInternal({
|
|
|
3837
3876
|
[latestSendMessageFunc]
|
|
3838
3877
|
);
|
|
3839
3878
|
const latestSetMessages = useUpdatedRef(agent == null ? void 0 : agent.setMessages);
|
|
3840
|
-
const latestSetMessagesFunc = (0,
|
|
3879
|
+
const latestSetMessagesFunc = (0, import_react27.useCallback)(
|
|
3841
3880
|
(messages) => {
|
|
3842
3881
|
var _a2, _b2;
|
|
3843
3882
|
if (messages.every((message) => message instanceof import_runtime_client_gql2.Message)) {
|
|
@@ -3855,24 +3894,24 @@ function useCopilotChatInternal({
|
|
|
3855
3894
|
[latestReload]
|
|
3856
3895
|
);
|
|
3857
3896
|
const latestStop = useUpdatedRef(agent == null ? void 0 : agent.abortRun);
|
|
3858
|
-
const latestStopFunc = (0,
|
|
3897
|
+
const latestStopFunc = (0, import_react27.useCallback)(() => {
|
|
3859
3898
|
var _a2;
|
|
3860
3899
|
return (_a2 = latestStop.current) == null ? void 0 : _a2.call(latestStop);
|
|
3861
3900
|
}, [latestStop]);
|
|
3862
3901
|
const latestReset = useUpdatedRef(reset);
|
|
3863
|
-
const latestResetFunc = (0,
|
|
3902
|
+
const latestResetFunc = (0, import_react27.useCallback)(() => {
|
|
3864
3903
|
return latestReset.current();
|
|
3865
3904
|
}, [latestReset]);
|
|
3866
3905
|
const lazyToolRendered = useLazyToolRenderer();
|
|
3867
|
-
const renderCustomMessage = (0,
|
|
3906
|
+
const renderCustomMessage = (0, import_react28.useRenderCustomMessages)();
|
|
3868
3907
|
const legacyCustomMessageRenderer = useLegacyCoagentRenderer({
|
|
3869
3908
|
copilotkit,
|
|
3870
3909
|
agent,
|
|
3871
3910
|
agentId: resolvedAgentId,
|
|
3872
|
-
threadId: (
|
|
3911
|
+
threadId: (_b = existingConfig == null ? void 0 : existingConfig.threadId) != null ? _b : threadId
|
|
3873
3912
|
});
|
|
3874
|
-
const allMessages = (
|
|
3875
|
-
const resolvedMessages = (0,
|
|
3913
|
+
const allMessages = (_c = agent == null ? void 0 : agent.messages) != null ? _c : [];
|
|
3914
|
+
const resolvedMessages = (0, import_react27.useMemo)(() => {
|
|
3876
3915
|
let processedMessages = allMessages.map((message) => {
|
|
3877
3916
|
if (message.role !== "assistant") {
|
|
3878
3917
|
return message;
|
|
@@ -3900,31 +3939,13 @@ function useCopilotChatInternal({
|
|
|
3900
3939
|
return message;
|
|
3901
3940
|
});
|
|
3902
3941
|
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
3942
|
return processedMessages;
|
|
3922
3943
|
}, [
|
|
3923
3944
|
agent == null ? void 0 : agent.messages,
|
|
3924
3945
|
lazyToolRendered,
|
|
3925
3946
|
allMessages,
|
|
3926
3947
|
renderCustomMessage,
|
|
3927
|
-
legacyCustomMessageRenderer,
|
|
3948
|
+
// legacyCustomMessageRenderer,
|
|
3928
3949
|
resolvedAgentId
|
|
3929
3950
|
]);
|
|
3930
3951
|
return {
|
|
@@ -3936,7 +3957,7 @@ function useCopilotChatInternal({
|
|
|
3936
3957
|
stopGeneration: latestStopFunc,
|
|
3937
3958
|
reset: latestResetFunc,
|
|
3938
3959
|
deleteMessage: latestDeleteFunc,
|
|
3939
|
-
isAvailable:
|
|
3960
|
+
isAvailable: agentAvailable,
|
|
3940
3961
|
isLoading: Boolean(agent == null ? void 0 : agent.isRunning),
|
|
3941
3962
|
// mcpServers,
|
|
3942
3963
|
// setMcpServers,
|
|
@@ -3953,8 +3974,8 @@ function useCopilotChatInternal({
|
|
|
3953
3974
|
};
|
|
3954
3975
|
}
|
|
3955
3976
|
function useUpdatedRef(value) {
|
|
3956
|
-
const ref = (0,
|
|
3957
|
-
(0,
|
|
3977
|
+
const ref = (0, import_react27.useRef)(value);
|
|
3978
|
+
(0, import_react27.useEffect)(() => {
|
|
3958
3979
|
ref.current = value;
|
|
3959
3980
|
}, [value]);
|
|
3960
3981
|
return ref;
|
|
@@ -3965,20 +3986,19 @@ function useLegacyCoagentRenderer({
|
|
|
3965
3986
|
agentId,
|
|
3966
3987
|
threadId
|
|
3967
3988
|
}) {
|
|
3968
|
-
return (0,
|
|
3989
|
+
return (0, import_react27.useMemo)(() => {
|
|
3969
3990
|
if (!copilotkit || !agent) {
|
|
3970
3991
|
return null;
|
|
3971
3992
|
}
|
|
3972
3993
|
return ({ message, position }) => {
|
|
3973
3994
|
var _a;
|
|
3974
3995
|
const effectiveThreadId = (_a = threadId != null ? threadId : agent.threadId) != null ? _a : "default";
|
|
3975
|
-
const existingRunId = copilotkit.getRunIdForMessage(
|
|
3976
|
-
agentId,
|
|
3977
|
-
effectiveThreadId,
|
|
3978
|
-
message.id
|
|
3979
|
-
);
|
|
3996
|
+
const existingRunId = copilotkit.getRunIdForMessage(agentId, effectiveThreadId, message.id);
|
|
3980
3997
|
const runId = existingRunId || `pending:${message.id}`;
|
|
3981
|
-
const messageIndex = Math.max(
|
|
3998
|
+
const messageIndex = Math.max(
|
|
3999
|
+
agent.messages.findIndex((msg) => msg.id === message.id),
|
|
4000
|
+
0
|
|
4001
|
+
);
|
|
3982
4002
|
const bridgeProps = {
|
|
3983
4003
|
message,
|
|
3984
4004
|
position,
|
|
@@ -3989,7 +4009,7 @@ function useLegacyCoagentRenderer({
|
|
|
3989
4009
|
agentId,
|
|
3990
4010
|
stateSnapshot: message.state
|
|
3991
4011
|
};
|
|
3992
|
-
return (0,
|
|
4012
|
+
return (0, import_react27.createElement)(CoAgentStateRenderBridge, bridgeProps);
|
|
3993
4013
|
};
|
|
3994
4014
|
}, [agent, agentId, copilotkit, threadId]);
|
|
3995
4015
|
}
|
|
@@ -4023,7 +4043,7 @@ function useCopilotChat(options = {}) {
|
|
|
4023
4043
|
}
|
|
4024
4044
|
|
|
4025
4045
|
// src/hooks/use-copilot-chat-headless_c.ts
|
|
4026
|
-
var
|
|
4046
|
+
var import_react29 = require("react");
|
|
4027
4047
|
var import_shared15 = require("@copilotkit/shared");
|
|
4028
4048
|
var createNonFunctionalReturn = () => ({
|
|
4029
4049
|
visibleMessages: [],
|
|
@@ -4064,7 +4084,7 @@ function useCopilotChatHeadless_c(options = {}) {
|
|
|
4064
4084
|
const { copilotApiConfig, setBannerError } = useCopilotContext();
|
|
4065
4085
|
const hasPublicApiKey = Boolean(copilotApiConfig.publicApiKey);
|
|
4066
4086
|
const internalResult = useCopilotChatInternal(options);
|
|
4067
|
-
(0,
|
|
4087
|
+
(0, import_react29.useEffect)(() => {
|
|
4068
4088
|
if (!hasPublicApiKey) {
|
|
4069
4089
|
setBannerError(
|
|
4070
4090
|
new import_shared15.CopilotKitError({
|
|
@@ -4089,13 +4109,13 @@ function useCopilotChatHeadless_c(options = {}) {
|
|
|
4089
4109
|
}
|
|
4090
4110
|
|
|
4091
4111
|
// src/hooks/use-copilot-action.ts
|
|
4092
|
-
var
|
|
4112
|
+
var import_react36 = require("react");
|
|
4093
4113
|
|
|
4094
4114
|
// src/hooks/use-frontend-tool.ts
|
|
4095
|
-
var
|
|
4115
|
+
var import_react30 = __toESM(require("react"));
|
|
4096
4116
|
var import_shared16 = require("@copilotkit/shared");
|
|
4097
4117
|
var import_shared17 = require("@copilotkit/shared");
|
|
4098
|
-
var
|
|
4118
|
+
var import_react31 = require("@copilotkitnext/react");
|
|
4099
4119
|
function useFrontendTool(tool, dependencies) {
|
|
4100
4120
|
const { name, description, parameters, render, followUp } = tool;
|
|
4101
4121
|
const zodParameters = (0, import_shared16.getZodParameters)(parameters);
|
|
@@ -4105,7 +4125,11 @@ function useFrontendTool(tool, dependencies) {
|
|
|
4105
4125
|
}
|
|
4106
4126
|
if (typeof render === "string") {
|
|
4107
4127
|
const staticRender = render;
|
|
4108
|
-
return () =>
|
|
4128
|
+
return () => import_react30.default.createElement(
|
|
4129
|
+
import_react30.default.Fragment,
|
|
4130
|
+
null,
|
|
4131
|
+
staticRender
|
|
4132
|
+
);
|
|
4109
4133
|
}
|
|
4110
4134
|
return (args) => {
|
|
4111
4135
|
const renderArgs = __spreadProps(__spreadValues({}, args), {
|
|
@@ -4113,12 +4137,12 @@ function useFrontendTool(tool, dependencies) {
|
|
|
4113
4137
|
});
|
|
4114
4138
|
const rendered = render(renderArgs);
|
|
4115
4139
|
if (typeof rendered === "string") {
|
|
4116
|
-
return
|
|
4140
|
+
return import_react30.default.createElement(import_react30.default.Fragment, null, rendered);
|
|
4117
4141
|
}
|
|
4118
4142
|
return rendered != null ? rendered : null;
|
|
4119
4143
|
};
|
|
4120
4144
|
})();
|
|
4121
|
-
(0,
|
|
4145
|
+
(0, import_react31.useFrontendTool)({
|
|
4122
4146
|
name,
|
|
4123
4147
|
description,
|
|
4124
4148
|
parameters: zodParameters,
|
|
@@ -4130,23 +4154,23 @@ function useFrontendTool(tool, dependencies) {
|
|
|
4130
4154
|
|
|
4131
4155
|
// src/hooks/use-render-tool-call.ts
|
|
4132
4156
|
var import_shared18 = require("@copilotkit/shared");
|
|
4133
|
-
var
|
|
4134
|
-
var
|
|
4157
|
+
var import_react32 = require("react");
|
|
4158
|
+
var import_react33 = require("@copilotkitnext/react");
|
|
4135
4159
|
var import_shared19 = require("@copilotkit/shared");
|
|
4136
4160
|
function useRenderToolCall2(tool, dependencies) {
|
|
4137
|
-
const { copilotkit } = (0,
|
|
4138
|
-
const hasAddedRef = (0,
|
|
4139
|
-
(0,
|
|
4161
|
+
const { copilotkit } = (0, import_react33.useCopilotKit)();
|
|
4162
|
+
const hasAddedRef = (0, import_react32.useRef)(false);
|
|
4163
|
+
(0, import_react32.useEffect)(() => {
|
|
4140
4164
|
const { name, parameters, render } = tool;
|
|
4141
4165
|
const zodParameters = (0, import_shared18.getZodParameters)(parameters);
|
|
4142
|
-
const renderToolCall = name === "*" ? (0,
|
|
4166
|
+
const renderToolCall = name === "*" ? (0, import_react33.defineToolCallRenderer)({
|
|
4143
4167
|
name: "*",
|
|
4144
4168
|
render: (args) => {
|
|
4145
4169
|
return render(__spreadProps(__spreadValues({}, args), {
|
|
4146
4170
|
result: args.result ? (0, import_shared19.parseJson)(args.result, args.result) : args.result
|
|
4147
4171
|
}));
|
|
4148
4172
|
}
|
|
4149
|
-
}) : (0,
|
|
4173
|
+
}) : (0, import_react33.defineToolCallRenderer)({
|
|
4150
4174
|
name,
|
|
4151
4175
|
args: zodParameters,
|
|
4152
4176
|
render: (args) => {
|
|
@@ -4175,18 +4199,18 @@ function useRenderToolCall2(tool, dependencies) {
|
|
|
4175
4199
|
|
|
4176
4200
|
// src/hooks/use-human-in-the-loop.ts
|
|
4177
4201
|
var import_shared20 = require("@copilotkit/shared");
|
|
4178
|
-
var
|
|
4202
|
+
var import_react34 = require("@copilotkitnext/react");
|
|
4179
4203
|
var import_core = require("@copilotkitnext/core");
|
|
4180
|
-
var
|
|
4204
|
+
var import_react35 = __toESM(require("react"));
|
|
4181
4205
|
function useHumanInTheLoop(tool, dependencies) {
|
|
4182
4206
|
const _a = tool, { render } = _a, toolRest = __objRest(_a, ["render"]);
|
|
4183
4207
|
const { name, description, parameters, followUp } = toolRest;
|
|
4184
4208
|
const zodParameters = (0, import_shared20.getZodParameters)(parameters);
|
|
4185
|
-
const renderRef = (0,
|
|
4186
|
-
(0,
|
|
4209
|
+
const renderRef = (0, import_react35.useRef)(null);
|
|
4210
|
+
(0, import_react35.useEffect)(() => {
|
|
4187
4211
|
renderRef.current = (args) => {
|
|
4188
4212
|
if (typeof render === "string") {
|
|
4189
|
-
return
|
|
4213
|
+
return import_react35.default.createElement(import_react35.default.Fragment, null, render);
|
|
4190
4214
|
}
|
|
4191
4215
|
if (!render) {
|
|
4192
4216
|
return null;
|
|
@@ -4226,12 +4250,12 @@ function useHumanInTheLoop(tool, dependencies) {
|
|
|
4226
4250
|
})();
|
|
4227
4251
|
const rendered = render(renderProps);
|
|
4228
4252
|
if (typeof rendered === "string") {
|
|
4229
|
-
return
|
|
4253
|
+
return import_react35.default.createElement(import_react35.default.Fragment, null, rendered);
|
|
4230
4254
|
}
|
|
4231
4255
|
return rendered != null ? rendered : null;
|
|
4232
4256
|
};
|
|
4233
4257
|
}, [render, ...dependencies != null ? dependencies : []]);
|
|
4234
|
-
(0,
|
|
4258
|
+
(0, import_react34.useHumanInTheLoop)({
|
|
4235
4259
|
name,
|
|
4236
4260
|
description,
|
|
4237
4261
|
followUp,
|
|
@@ -4287,7 +4311,7 @@ function getActionConfig(action) {
|
|
|
4287
4311
|
throw new Error("Invalid action configuration");
|
|
4288
4312
|
}
|
|
4289
4313
|
function useCopilotAction(action, dependencies) {
|
|
4290
|
-
const [initialActionConfig] = (0,
|
|
4314
|
+
const [initialActionConfig] = (0, import_react36.useState)(getActionConfig(action));
|
|
4291
4315
|
const currentActionConfig = getActionConfig(action);
|
|
4292
4316
|
if (initialActionConfig.type !== currentActionConfig.type) {
|
|
4293
4317
|
throw new Error("Action configuration changed between renders");
|
|
@@ -4305,14 +4329,14 @@ function useCopilotAction(action, dependencies) {
|
|
|
4305
4329
|
}
|
|
4306
4330
|
|
|
4307
4331
|
// src/hooks/use-coagent-state-render.ts
|
|
4308
|
-
var
|
|
4332
|
+
var import_react37 = require("react");
|
|
4309
4333
|
var import_shared21 = require("@copilotkit/shared");
|
|
4310
4334
|
function useCoAgentStateRender(action, dependencies) {
|
|
4311
|
-
const { chatComponentsCache, availableAgents } = (0,
|
|
4335
|
+
const { chatComponentsCache, availableAgents } = (0, import_react37.useContext)(CopilotContext);
|
|
4312
4336
|
const { setCoAgentStateRender, removeCoAgentStateRender, coAgentStateRenders } = useCoAgentStateRenders();
|
|
4313
|
-
const idRef = (0,
|
|
4337
|
+
const idRef = (0, import_react37.useRef)((0, import_shared21.randomId)());
|
|
4314
4338
|
const { setBannerError, addToast } = useToast();
|
|
4315
|
-
(0,
|
|
4339
|
+
(0, import_react37.useEffect)(() => {
|
|
4316
4340
|
if ((availableAgents == null ? void 0 : availableAgents.length) && !availableAgents.some((a) => a.name === action.name)) {
|
|
4317
4341
|
const message = `(useCoAgentStateRender): Agent "${action.name}" not found. Make sure the agent exists and is properly configured.`;
|
|
4318
4342
|
const agentError = new import_shared21.CopilotKitAgentDiscoveryError({
|
|
@@ -4333,7 +4357,7 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
4333
4357
|
}
|
|
4334
4358
|
}
|
|
4335
4359
|
}
|
|
4336
|
-
(0,
|
|
4360
|
+
(0, import_react37.useEffect)(() => {
|
|
4337
4361
|
const currentId = idRef.current;
|
|
4338
4362
|
const hasDuplicate = Object.entries(coAgentStateRenders).some(([id, otherAction]) => {
|
|
4339
4363
|
if (id === currentId)
|
|
@@ -4357,7 +4381,7 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
4357
4381
|
});
|
|
4358
4382
|
}
|
|
4359
4383
|
}, [coAgentStateRenders]);
|
|
4360
|
-
(0,
|
|
4384
|
+
(0, import_react37.useEffect)(() => {
|
|
4361
4385
|
setCoAgentStateRender(idRef.current, action);
|
|
4362
4386
|
if (chatComponentsCache.current !== null && action.render !== void 0) {
|
|
4363
4387
|
chatComponentsCache.current.coAgentStateRenders[key] = action.render;
|
|
@@ -4377,11 +4401,11 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
4377
4401
|
}
|
|
4378
4402
|
|
|
4379
4403
|
// src/hooks/use-make-copilot-document-readable.ts
|
|
4380
|
-
var
|
|
4404
|
+
var import_react38 = require("react");
|
|
4381
4405
|
function useMakeCopilotDocumentReadable(document2, categories, dependencies = []) {
|
|
4382
4406
|
const { addDocumentContext, removeDocumentContext } = useCopilotContext();
|
|
4383
|
-
const idRef = (0,
|
|
4384
|
-
(0,
|
|
4407
|
+
const idRef = (0, import_react38.useRef)(void 0);
|
|
4408
|
+
(0, import_react38.useEffect)(() => {
|
|
4385
4409
|
const id = addDocumentContext(document2, categories);
|
|
4386
4410
|
idRef.current = id;
|
|
4387
4411
|
return () => {
|
|
@@ -4392,21 +4416,23 @@ function useMakeCopilotDocumentReadable(document2, categories, dependencies = []
|
|
|
4392
4416
|
}
|
|
4393
4417
|
|
|
4394
4418
|
// src/hooks/use-copilot-readable.ts
|
|
4395
|
-
var
|
|
4419
|
+
var import_react39 = require("@copilotkitnext/react");
|
|
4396
4420
|
function useCopilotReadable({ description, value }, dependencies) {
|
|
4397
|
-
(0,
|
|
4421
|
+
(0, import_react39.useAgentContext)({
|
|
4398
4422
|
description,
|
|
4399
4423
|
value
|
|
4400
4424
|
});
|
|
4425
|
+
return;
|
|
4401
4426
|
}
|
|
4402
4427
|
|
|
4403
4428
|
// src/hooks/use-coagent.ts
|
|
4404
|
-
var
|
|
4405
|
-
var
|
|
4429
|
+
var import_react40 = require("react");
|
|
4430
|
+
var import_react41 = require("@copilotkitnext/react");
|
|
4406
4431
|
function useCoAgent(options) {
|
|
4407
|
-
const { agent } = (0,
|
|
4408
|
-
const
|
|
4409
|
-
const
|
|
4432
|
+
const { agent } = (0, import_react41.useAgent)({ agentId: options.name });
|
|
4433
|
+
const { copilotkit } = (0, import_react41.useCopilotKit)();
|
|
4434
|
+
const nodeName = useAgentNodeName(options.name);
|
|
4435
|
+
const handleStateUpdate = (0, import_react40.useCallback)(
|
|
4410
4436
|
(newState) => {
|
|
4411
4437
|
if (!agent)
|
|
4412
4438
|
return;
|
|
@@ -4419,22 +4445,34 @@ function useCoAgent(options) {
|
|
|
4419
4445
|
},
|
|
4420
4446
|
[agent == null ? void 0 : agent.state, agent == null ? void 0 : agent.setState]
|
|
4421
4447
|
);
|
|
4422
|
-
|
|
4448
|
+
(0, import_react40.useEffect)(() => {
|
|
4449
|
+
var _a;
|
|
4450
|
+
if (!options.config && !options.configurable)
|
|
4451
|
+
return;
|
|
4452
|
+
let config = (_a = options.config) != null ? _a : {};
|
|
4453
|
+
if (options.configurable) {
|
|
4454
|
+
config = __spreadProps(__spreadValues({}, config), {
|
|
4455
|
+
configurable: __spreadValues(__spreadValues({}, options.configurable), config.configurable)
|
|
4456
|
+
});
|
|
4457
|
+
}
|
|
4458
|
+
copilotkit.setProperties(config);
|
|
4459
|
+
}, [options.config, options.configurable]);
|
|
4460
|
+
const externalStateStr = (0, import_react40.useMemo)(
|
|
4423
4461
|
() => isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0,
|
|
4424
4462
|
[isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0]
|
|
4425
4463
|
);
|
|
4426
|
-
(0,
|
|
4464
|
+
(0, import_react40.useEffect)(() => {
|
|
4427
4465
|
if ((agent == null ? void 0 : agent.state) && isExternalStateManagement(options) && JSON.stringify(options.state) !== JSON.stringify(agent.state)) {
|
|
4428
4466
|
handleStateUpdate(options.state);
|
|
4429
4467
|
}
|
|
4430
4468
|
}, [agent, externalStateStr, handleStateUpdate]);
|
|
4431
|
-
const hasStateValues = (0,
|
|
4469
|
+
const hasStateValues = (0, import_react40.useCallback)((value) => {
|
|
4432
4470
|
return Boolean(value && Object.keys(value).length);
|
|
4433
4471
|
}, []);
|
|
4434
|
-
const initialStateRef = (0,
|
|
4472
|
+
const initialStateRef = (0, import_react40.useRef)(
|
|
4435
4473
|
isExternalStateManagement(options) ? options.state : "initialState" in options ? options.initialState : void 0
|
|
4436
4474
|
);
|
|
4437
|
-
(0,
|
|
4475
|
+
(0, import_react40.useEffect)(() => {
|
|
4438
4476
|
if (isExternalStateManagement(options)) {
|
|
4439
4477
|
initialStateRef.current = options.state;
|
|
4440
4478
|
} else if ("initialState" in options) {
|
|
@@ -4443,7 +4481,7 @@ function useCoAgent(options) {
|
|
|
4443
4481
|
}, [
|
|
4444
4482
|
isExternalStateManagement(options) ? JSON.stringify(options.state) : "initialState" in options ? JSON.stringify(options.initialState) : void 0
|
|
4445
4483
|
]);
|
|
4446
|
-
(0,
|
|
4484
|
+
(0, import_react40.useEffect)(() => {
|
|
4447
4485
|
if (!agent)
|
|
4448
4486
|
return;
|
|
4449
4487
|
const subscriber = {
|
|
@@ -4464,15 +4502,6 @@ function useCoAgent(options) {
|
|
|
4464
4502
|
if (initialStateRef.current !== void 0) {
|
|
4465
4503
|
handleStateUpdate(initialStateRef.current);
|
|
4466
4504
|
}
|
|
4467
|
-
},
|
|
4468
|
-
onStepStartedEvent: ({ event }) => {
|
|
4469
|
-
nodeNameRef.current = event.stepName;
|
|
4470
|
-
},
|
|
4471
|
-
onRunStartedEvent: () => {
|
|
4472
|
-
nodeNameRef.current = "start";
|
|
4473
|
-
},
|
|
4474
|
-
onRunFinishedEvent: () => {
|
|
4475
|
-
nodeNameRef.current = "end";
|
|
4476
4505
|
}
|
|
4477
4506
|
};
|
|
4478
4507
|
const subscription = agent.subscribe(subscriber);
|
|
@@ -4480,7 +4509,7 @@ function useCoAgent(options) {
|
|
|
4480
4509
|
subscription.unsubscribe();
|
|
4481
4510
|
};
|
|
4482
4511
|
}, [agent, handleStateUpdate, hasStateValues]);
|
|
4483
|
-
return (0,
|
|
4512
|
+
return (0, import_react40.useMemo)(() => {
|
|
4484
4513
|
var _a, _b, _c;
|
|
4485
4514
|
if (!agent) {
|
|
4486
4515
|
const noop = () => {
|
|
@@ -4496,7 +4525,7 @@ function useCoAgent(options) {
|
|
|
4496
4525
|
);
|
|
4497
4526
|
return {
|
|
4498
4527
|
name: options.name,
|
|
4499
|
-
nodeName
|
|
4528
|
+
nodeName,
|
|
4500
4529
|
threadId: void 0,
|
|
4501
4530
|
running: false,
|
|
4502
4531
|
state: initialState,
|
|
@@ -4508,7 +4537,7 @@ function useCoAgent(options) {
|
|
|
4508
4537
|
}
|
|
4509
4538
|
return {
|
|
4510
4539
|
name: (_c = agent == null ? void 0 : agent.agentId) != null ? _c : options.name,
|
|
4511
|
-
nodeName
|
|
4540
|
+
nodeName,
|
|
4512
4541
|
threadId: agent.threadId,
|
|
4513
4542
|
running: agent.isRunning,
|
|
4514
4543
|
state: agent.state,
|
|
@@ -4536,12 +4565,12 @@ var isExternalStateManagement = (options) => {
|
|
|
4536
4565
|
|
|
4537
4566
|
// src/hooks/use-copilot-runtime-client.ts
|
|
4538
4567
|
var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
|
|
4539
|
-
var
|
|
4568
|
+
var import_react42 = require("react");
|
|
4540
4569
|
var import_shared22 = require("@copilotkit/shared");
|
|
4541
4570
|
var useCopilotRuntimeClient = (options) => {
|
|
4542
4571
|
const { setBannerError } = useToast();
|
|
4543
4572
|
const _a = options, { showDevConsole, onError } = _a, runtimeOptions = __objRest(_a, ["showDevConsole", "onError"]);
|
|
4544
|
-
const lastStructuredErrorRef = (0,
|
|
4573
|
+
const lastStructuredErrorRef = (0, import_react42.useRef)(null);
|
|
4545
4574
|
const traceUIError = (error, originalError) => __async(void 0, null, function* () {
|
|
4546
4575
|
try {
|
|
4547
4576
|
const errorEvent = {
|
|
@@ -4567,7 +4596,7 @@ var useCopilotRuntimeClient = (options) => {
|
|
|
4567
4596
|
console.error("Error in onError handler:", error2);
|
|
4568
4597
|
}
|
|
4569
4598
|
});
|
|
4570
|
-
const runtimeClient = (0,
|
|
4599
|
+
const runtimeClient = (0, import_react42.useMemo)(() => {
|
|
4571
4600
|
return new import_runtime_client_gql3.CopilotRuntimeClient(__spreadProps(__spreadValues({}, runtimeOptions), {
|
|
4572
4601
|
handleGQLErrors: (error) => {
|
|
4573
4602
|
var _a2;
|
|
@@ -4646,28 +4675,28 @@ function createStructuredError(gqlError) {
|
|
|
4646
4675
|
}
|
|
4647
4676
|
|
|
4648
4677
|
// src/hooks/use-copilot-authenticated-action.ts
|
|
4649
|
-
var
|
|
4650
|
-
var
|
|
4678
|
+
var import_react43 = require("react");
|
|
4679
|
+
var import_react44 = __toESM(require("react"));
|
|
4651
4680
|
function useCopilotAuthenticatedAction_c(action, dependencies) {
|
|
4652
4681
|
const { authConfig_c, authStates_c, setAuthStates_c } = useCopilotContext();
|
|
4653
|
-
const pendingActionRef = (0,
|
|
4654
|
-
const executeAction = (0,
|
|
4682
|
+
const pendingActionRef = (0, import_react43.useRef)(null);
|
|
4683
|
+
const executeAction = (0, import_react43.useCallback)(
|
|
4655
4684
|
(props) => {
|
|
4656
4685
|
if (typeof action.render === "function") {
|
|
4657
4686
|
return action.render(props);
|
|
4658
4687
|
}
|
|
4659
|
-
return action.render ||
|
|
4688
|
+
return action.render || import_react44.default.createElement(import_react43.Fragment);
|
|
4660
4689
|
},
|
|
4661
4690
|
[action]
|
|
4662
4691
|
);
|
|
4663
|
-
const wrappedRender = (0,
|
|
4692
|
+
const wrappedRender = (0, import_react43.useCallback)(
|
|
4664
4693
|
(props) => {
|
|
4665
4694
|
const isAuthenticated = Object.values(authStates_c || {}).some(
|
|
4666
4695
|
(state) => state.status === "authenticated"
|
|
4667
4696
|
);
|
|
4668
4697
|
if (!isAuthenticated) {
|
|
4669
4698
|
pendingActionRef.current = props;
|
|
4670
|
-
return (authConfig_c == null ? void 0 : authConfig_c.SignInComponent) ?
|
|
4699
|
+
return (authConfig_c == null ? void 0 : authConfig_c.SignInComponent) ? import_react44.default.createElement(authConfig_c.SignInComponent, {
|
|
4671
4700
|
onSignInComplete: (authState) => {
|
|
4672
4701
|
setAuthStates_c == null ? void 0 : setAuthStates_c((prev) => __spreadProps(__spreadValues({}, prev), { [action.name]: authState }));
|
|
4673
4702
|
if (pendingActionRef.current) {
|
|
@@ -4675,7 +4704,7 @@ function useCopilotAuthenticatedAction_c(action, dependencies) {
|
|
|
4675
4704
|
pendingActionRef.current = null;
|
|
4676
4705
|
}
|
|
4677
4706
|
}
|
|
4678
|
-
}) :
|
|
4707
|
+
}) : import_react44.default.createElement(import_react43.Fragment);
|
|
4679
4708
|
}
|
|
4680
4709
|
return executeAction(props);
|
|
4681
4710
|
},
|
|
@@ -4690,13 +4719,13 @@ function useCopilotAuthenticatedAction_c(action, dependencies) {
|
|
|
4690
4719
|
}
|
|
4691
4720
|
|
|
4692
4721
|
// src/hooks/use-langgraph-interrupt.ts
|
|
4693
|
-
var
|
|
4722
|
+
var import_react45 = require("react");
|
|
4694
4723
|
var import_shared23 = require("@copilotkit/shared");
|
|
4695
4724
|
function useLangGraphInterrupt(action, dependencies) {
|
|
4696
|
-
const { setInterruptAction, removeInterruptAction, interruptActions, threadId } = (0,
|
|
4725
|
+
const { setInterruptAction, removeInterruptAction, interruptActions, threadId } = (0, import_react45.useContext)(CopilotContext);
|
|
4697
4726
|
const { addToast } = useToast();
|
|
4698
4727
|
const actionId = (0, import_shared23.dataToUUID)(JSON.stringify(action), "lgAction");
|
|
4699
|
-
(0,
|
|
4728
|
+
(0, import_react45.useEffect)(() => {
|
|
4700
4729
|
if (!action)
|
|
4701
4730
|
return;
|
|
4702
4731
|
setInterruptAction(threadId, __spreadProps(__spreadValues({}, action), { id: actionId }));
|
|
@@ -4707,10 +4736,10 @@ function useLangGraphInterrupt(action, dependencies) {
|
|
|
4707
4736
|
}
|
|
4708
4737
|
|
|
4709
4738
|
// src/hooks/use-copilot-additional-instructions.ts
|
|
4710
|
-
var
|
|
4739
|
+
var import_react46 = require("react");
|
|
4711
4740
|
function useCopilotAdditionalInstructions({ instructions, available = "enabled" }, dependencies) {
|
|
4712
4741
|
const { setAdditionalInstructions } = useCopilotContext();
|
|
4713
|
-
(0,
|
|
4742
|
+
(0, import_react46.useEffect)(() => {
|
|
4714
4743
|
if (available === "disabled")
|
|
4715
4744
|
return;
|
|
4716
4745
|
setAdditionalInstructions((prevInstructions) => [...prevInstructions || [], instructions]);
|