@copilotkit/react-core 1.69.2 → 1.70.0
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/dist/{copilotkit-BmW2sFH6.mjs → copilotkit-B7aFKfQR.mjs} +138 -77
- package/dist/copilotkit-B7aFKfQR.mjs.map +1 -0
- package/dist/{copilotkit-Ba7qwYt3.cjs → copilotkit-BE76j111.cjs} +142 -75
- package/dist/copilotkit-BE76j111.cjs.map +1 -0
- package/dist/{copilotkit-CF1Pm2VG.d.cts → copilotkit-BuzP0VeG.d.cts} +47 -18
- package/dist/copilotkit-BuzP0VeG.d.cts.map +1 -0
- package/dist/{copilotkit-TdM-5onZ.d.mts → copilotkit-CbZGwElm.d.mts} +47 -18
- package/dist/copilotkit-CbZGwElm.d.mts.map +1 -0
- package/dist/index.cjs +93 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +17 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +93 -21
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +206 -87
- package/dist/index.umd.js.map +1 -1
- package/dist/v2/headless.cjs +15 -8
- package/dist/v2/headless.cjs.map +1 -1
- package/dist/v2/headless.d.cts.map +1 -1
- package/dist/v2/headless.d.mts.map +1 -1
- package/dist/v2/headless.mjs +15 -8
- package/dist/v2/headless.mjs.map +1 -1
- package/dist/v2/index.cjs +2 -1
- package/dist/v2/index.d.cts +2 -2
- package/dist/v2/index.d.mts +2 -2
- package/dist/v2/index.mjs +2 -2
- package/dist/v2/index.umd.js +140 -77
- package/dist/v2/index.umd.js.map +1 -1
- package/package.json +9 -10
- package/skills/react-core/SKILL.md +5 -3
- package/skills/react-core/references/agent-access.md +68 -1
- package/skills/react-core/references/debug-mode.md +21 -34
- package/skills/react-core/references/switching-agents-recipes.md +1 -0
- package/skills/react-core/references/switching-agents.md +9 -0
- package/skills/react-core/references/threads.md +65 -0
- package/dist/copilotkit-Ba7qwYt3.cjs.map +0 -1
- package/dist/copilotkit-BmW2sFH6.mjs.map +0 -1
- package/dist/copilotkit-CF1Pm2VG.d.cts.map +0 -1
- package/dist/copilotkit-TdM-5onZ.d.mts.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_copilotkit = require('./copilotkit-
|
|
4
|
+
const require_copilotkit = require('./copilotkit-BE76j111.cjs');
|
|
5
5
|
let react = require("react");
|
|
6
6
|
react = require_copilotkit.__toESM(react);
|
|
7
7
|
let _copilotkit_core = require("@copilotkit/core");
|
|
8
8
|
let _ag_ui_client = require("@ag-ui/client");
|
|
9
9
|
let _copilotkit_shared = require("@copilotkit/shared");
|
|
10
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
10
11
|
let _copilotkit_runtime_client_gql = require("@copilotkit/runtime-client-gql");
|
|
11
12
|
let _copilotkit_react_core_v2_context = require("@copilotkit/react-core/v2/context");
|
|
12
13
|
|
|
@@ -25,13 +26,18 @@ function useLazyToolRenderer() {
|
|
|
25
26
|
const renderToolCall = require_copilotkit.useRenderToolCall();
|
|
26
27
|
return (0, react.useCallback)((message, messages) => {
|
|
27
28
|
if (!message?.toolCalls?.length) return null;
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
const toolCalls = message.toolCalls;
|
|
30
|
+
return () => {
|
|
31
|
+
const renderedToolCalls = toolCalls.map((toolCall) => {
|
|
32
|
+
const toolMessage = messages?.find((m) => m.role === "tool" && m.toolCallId === toolCall.id);
|
|
33
|
+
return renderToolCall({
|
|
34
|
+
toolCall,
|
|
35
|
+
toolMessage
|
|
36
|
+
});
|
|
37
|
+
}).filter((renderedToolCall) => renderedToolCall !== null);
|
|
38
|
+
if (!renderedToolCalls.length) return null;
|
|
39
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: renderedToolCalls });
|
|
40
|
+
};
|
|
35
41
|
}, [renderToolCall]);
|
|
36
42
|
}
|
|
37
43
|
|
|
@@ -726,20 +732,24 @@ function useHumanInTheLoop(tool, dependencies) {
|
|
|
726
732
|
if (!render) return null;
|
|
727
733
|
const rendered = render((() => {
|
|
728
734
|
const mappedArgs = args.args;
|
|
735
|
+
const toolCallName = args.name;
|
|
729
736
|
switch (args.status) {
|
|
730
737
|
case _copilotkit_core.ToolCallStatus.InProgress: return {
|
|
738
|
+
name: toolCallName,
|
|
731
739
|
args: mappedArgs,
|
|
732
740
|
respond: args.respond,
|
|
733
741
|
status: args.status,
|
|
734
742
|
handler: void 0
|
|
735
743
|
};
|
|
736
744
|
case _copilotkit_core.ToolCallStatus.Executing: return {
|
|
745
|
+
name: toolCallName,
|
|
737
746
|
args: mappedArgs,
|
|
738
747
|
respond: args.respond,
|
|
739
748
|
status: args.status,
|
|
740
749
|
handler: () => {}
|
|
741
750
|
};
|
|
742
751
|
case _copilotkit_core.ToolCallStatus.Complete: return {
|
|
752
|
+
name: toolCallName,
|
|
743
753
|
args: mappedArgs,
|
|
744
754
|
respond: args.respond,
|
|
745
755
|
status: args.status,
|
|
@@ -899,10 +909,21 @@ function useHumanInTheLoop(tool, dependencies) {
|
|
|
899
909
|
* This hooks enables you to dynamically generate UI elements and render them in the copilot chat. For more information, check out the [Generative UI](/guides/generative-ui) page.
|
|
900
910
|
*/
|
|
901
911
|
function getActionConfig(action) {
|
|
902
|
-
if (action.name === "*")
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
912
|
+
if (action.name === "*") {
|
|
913
|
+
const catchAll = action;
|
|
914
|
+
const waitRender = catchAll.renderAndWaitForResponse ?? catchAll.renderAndWait;
|
|
915
|
+
if (waitRender) return {
|
|
916
|
+
type: "hitl",
|
|
917
|
+
action: {
|
|
918
|
+
...catchAll,
|
|
919
|
+
render: waitRender
|
|
920
|
+
}
|
|
921
|
+
};
|
|
922
|
+
return {
|
|
923
|
+
type: "render",
|
|
924
|
+
action
|
|
925
|
+
};
|
|
926
|
+
}
|
|
906
927
|
if ("renderAndWaitForResponse" in action || "renderAndWait" in action) {
|
|
907
928
|
let render = action.render;
|
|
908
929
|
if (!render && "renderAndWaitForResponse" in action) render = action.renderAndWaitForResponse;
|
|
@@ -1213,37 +1234,87 @@ function useCopilotReadable({ description, value, convert, available = "enabled"
|
|
|
1213
1234
|
|
|
1214
1235
|
//#endregion
|
|
1215
1236
|
//#region src/v1-deprecated/hooks/use-agent-nodename.ts
|
|
1237
|
+
const initialAgentNodeNameState = {
|
|
1238
|
+
nodeName: "start",
|
|
1239
|
+
lastActiveNodeName: "start",
|
|
1240
|
+
hasLegacyInterrupt: false
|
|
1241
|
+
};
|
|
1242
|
+
const transitionAgentNodeName = (state, event) => {
|
|
1243
|
+
switch (event.type) {
|
|
1244
|
+
case "reset":
|
|
1245
|
+
case "runStarted": return initialAgentNodeNameState;
|
|
1246
|
+
case "stepStarted": return {
|
|
1247
|
+
...state,
|
|
1248
|
+
nodeName: event.nodeName,
|
|
1249
|
+
lastActiveNodeName: event.nodeName
|
|
1250
|
+
};
|
|
1251
|
+
case "legacyInterruptReceived": return {
|
|
1252
|
+
...state,
|
|
1253
|
+
hasLegacyInterrupt: true
|
|
1254
|
+
};
|
|
1255
|
+
case "runFinished":
|
|
1256
|
+
if (event.outcome === "interrupt" || state.hasLegacyInterrupt) return {
|
|
1257
|
+
...state,
|
|
1258
|
+
nodeName: state.lastActiveNodeName,
|
|
1259
|
+
hasLegacyInterrupt: false
|
|
1260
|
+
};
|
|
1261
|
+
return {
|
|
1262
|
+
...state,
|
|
1263
|
+
nodeName: "end",
|
|
1264
|
+
hasLegacyInterrupt: false
|
|
1265
|
+
};
|
|
1266
|
+
case "runError": return {
|
|
1267
|
+
...state,
|
|
1268
|
+
nodeName: "end",
|
|
1269
|
+
hasLegacyInterrupt: false
|
|
1270
|
+
};
|
|
1271
|
+
}
|
|
1272
|
+
};
|
|
1216
1273
|
/**
|
|
1217
1274
|
* Tracks the node the agent is currently executing.
|
|
1218
1275
|
*
|
|
1219
1276
|
* Backed by state rather than a ref: mutating a ref schedules no render, so
|
|
1220
1277
|
* consumers such as `useCoAgent().nodeName` kept reporting whichever node was
|
|
1221
|
-
* current at their last render and never updated on their own.
|
|
1278
|
+
* current at their last render and never updated on their own. Interrupt-aware
|
|
1279
|
+
* transitions keep the last active node available while an interrupt is pending.
|
|
1222
1280
|
*/
|
|
1223
1281
|
function useAgentNodeName(agentName) {
|
|
1224
1282
|
const { agent } = require_copilotkit.useAgent({ agentId: agentName });
|
|
1225
|
-
const [
|
|
1283
|
+
const [nodeNameState, setNodeNameState] = (0, react.useState)(initialAgentNodeNameState);
|
|
1226
1284
|
(0, react.useEffect)(() => {
|
|
1285
|
+
const transition = (event) => {
|
|
1286
|
+
setNodeNameState((state) => transitionAgentNodeName(state, event));
|
|
1287
|
+
};
|
|
1288
|
+
transition({ type: "reset" });
|
|
1227
1289
|
if (!agent) return;
|
|
1228
1290
|
const subscription = agent.subscribe({
|
|
1229
1291
|
onStepStartedEvent: ({ event }) => {
|
|
1230
|
-
|
|
1292
|
+
transition({
|
|
1293
|
+
type: "stepStarted",
|
|
1294
|
+
nodeName: event.stepName
|
|
1295
|
+
});
|
|
1231
1296
|
},
|
|
1232
1297
|
onRunStartedEvent: () => {
|
|
1233
|
-
|
|
1298
|
+
transition({ type: "runStarted" });
|
|
1234
1299
|
},
|
|
1235
|
-
onRunFinishedEvent: () => {
|
|
1236
|
-
|
|
1300
|
+
onRunFinishedEvent: ({ outcome }) => {
|
|
1301
|
+
transition({
|
|
1302
|
+
type: "runFinished",
|
|
1303
|
+
outcome
|
|
1304
|
+
});
|
|
1237
1305
|
},
|
|
1238
1306
|
onRunErrorEvent: () => {
|
|
1239
|
-
|
|
1307
|
+
transition({ type: "runError" });
|
|
1308
|
+
},
|
|
1309
|
+
onCustomEvent: ({ event }) => {
|
|
1310
|
+
if (event.name === require_copilotkit.INTERRUPT_EVENT_NAME) transition({ type: "legacyInterruptReceived" });
|
|
1240
1311
|
}
|
|
1241
1312
|
});
|
|
1242
1313
|
return () => {
|
|
1243
1314
|
subscription.unsubscribe();
|
|
1244
1315
|
};
|
|
1245
|
-
}, [agent]);
|
|
1246
|
-
return nodeName;
|
|
1316
|
+
}, [agent, agentName]);
|
|
1317
|
+
return nodeNameState.nodeName;
|
|
1247
1318
|
}
|
|
1248
1319
|
|
|
1249
1320
|
//#endregion
|
|
@@ -1446,6 +1517,7 @@ function useCoAgent(options) {
|
|
|
1446
1517
|
agent?.threadId,
|
|
1447
1518
|
agent?.isRunning,
|
|
1448
1519
|
agent?.agentId,
|
|
1520
|
+
nodeName,
|
|
1449
1521
|
handleStateUpdate,
|
|
1450
1522
|
options.name
|
|
1451
1523
|
]);
|