@copilotkit/react-core 1.6.0-next.1 → 1.6.0-next.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 +69 -0
- package/dist/{chunk-VMYLY5KI.mjs → chunk-ADTDNMYG.mjs} +58 -48
- package/dist/chunk-ADTDNMYG.mjs.map +1 -0
- package/dist/{chunk-2DPTBHGN.mjs → chunk-ALW2T2LL.mjs} +3 -5
- package/dist/chunk-ALW2T2LL.mjs.map +1 -0
- package/dist/{chunk-ZAU4EMBM.mjs → chunk-F7O6L7C3.mjs} +4 -5
- package/dist/chunk-F7O6L7C3.mjs.map +1 -0
- package/dist/{chunk-4ED56DQX.mjs → chunk-MPFP6ANM.mjs} +3 -4
- package/dist/chunk-MPFP6ANM.mjs.map +1 -0
- package/dist/{chunk-Z3U4UBG2.mjs → chunk-QJPWWVJQ.mjs} +2 -2
- package/dist/components/copilot-provider/copilotkit-props.d.ts +1 -2
- package/dist/components/copilot-provider/copilotkit.d.ts +1 -2
- package/dist/components/copilot-provider/index.d.ts +1 -2
- package/dist/components/index.d.ts +1 -2
- package/dist/context/copilot-context.d.ts +10 -148
- package/dist/context/index.d.ts +1 -2
- package/dist/copilot-context-9ae8990b.d.ts +183 -0
- package/dist/hooks/index.d.ts +1 -2
- package/dist/hooks/index.js +68 -62
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +5 -5
- package/dist/hooks/use-chat.d.ts +1 -2
- package/dist/hooks/use-chat.js +2 -4
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +1 -1
- package/dist/hooks/use-coagent.d.ts +1 -2
- package/dist/hooks/use-coagent.js +58 -50
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +3 -3
- package/dist/hooks/use-copilot-chat.d.ts +1 -2
- package/dist/hooks/use-copilot-chat.js +3 -5
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +2 -2
- package/dist/hooks/use-langgraph-interrupt-render.js +3 -4
- package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt-render.mjs +1 -1
- package/dist/hooks/use-langgraph-interrupt.d.ts +9 -2
- package/dist/hooks/use-langgraph-interrupt.js +6 -9
- package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt.mjs +3 -3
- package/dist/index.d.ts +1 -2
- package/dist/index.js +67 -61
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -5
- package/dist/lib/copilot-task.d.ts +1 -2
- package/dist/lib/index.d.ts +1 -2
- package/dist/types/interrupt-action.d.ts +10 -35
- package/dist/types/interrupt-action.js.map +1 -1
- package/dist/utils/extract.d.ts +1 -2
- package/dist/utils/index.d.ts +1 -2
- package/package.json +3 -3
- package/src/hooks/use-chat.ts +2 -4
- package/src/hooks/use-coagent.ts +70 -56
- package/src/hooks/use-langgraph-interrupt-render.ts +7 -3
- package/src/hooks/use-langgraph-interrupt.ts +1 -2
- package/src/types/interrupt-action.ts +16 -12
- package/dist/chunk-2DPTBHGN.mjs.map +0 -1
- package/dist/chunk-4ED56DQX.mjs.map +0 -1
- package/dist/chunk-VMYLY5KI.mjs.map +0 -1
- package/dist/chunk-ZAU4EMBM.mjs.map +0 -1
- /package/dist/{chunk-Z3U4UBG2.mjs.map → chunk-QJPWWVJQ.mjs.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -1591,6 +1591,7 @@ function processActionsForRuntimeRequest(actions) {
|
|
|
1591
1591
|
|
|
1592
1592
|
// src/hooks/use-chat.ts
|
|
1593
1593
|
var import_runtime_client_gql7 = require("@copilotkit/runtime-client-gql");
|
|
1594
|
+
var import_shared11 = require("@copilotkit/shared");
|
|
1594
1595
|
function useChat(options) {
|
|
1595
1596
|
const {
|
|
1596
1597
|
messages,
|
|
@@ -1735,10 +1736,7 @@ function useChat(options) {
|
|
|
1735
1736
|
((_i = (_h = value.generateCopilotResponse) == null ? void 0 : _h.metaEvents) != null ? _i : []).forEach((ev) => {
|
|
1736
1737
|
if (ev.name === import_runtime_client_gql7.MetaEventName.LangGraphInterruptEvent) {
|
|
1737
1738
|
let eventValue = (0, import_runtime_client_gql6.langGraphInterruptEvent)(ev).value;
|
|
1738
|
-
|
|
1739
|
-
eventValue = JSON.parse(eventValue);
|
|
1740
|
-
} catch (e) {
|
|
1741
|
-
}
|
|
1739
|
+
eventValue = (0, import_shared11.parseJson)(eventValue, eventValue);
|
|
1742
1740
|
setLangGraphInterruptAction({
|
|
1743
1741
|
event: __spreadProps(__spreadValues({}, (0, import_runtime_client_gql6.langGraphInterruptEvent)(ev)), {
|
|
1744
1742
|
value: eventValue
|
|
@@ -2241,11 +2239,11 @@ ${additionalInstructions}` : "");
|
|
|
2241
2239
|
}
|
|
2242
2240
|
|
|
2243
2241
|
// src/hooks/use-copilot-action.ts
|
|
2244
|
-
var
|
|
2242
|
+
var import_shared12 = require("@copilotkit/shared");
|
|
2245
2243
|
var import_react13 = require("react");
|
|
2246
2244
|
function useCopilotAction(action, dependencies) {
|
|
2247
2245
|
const { setAction, removeAction, actions, chatComponentsCache } = useCopilotContext();
|
|
2248
|
-
const idRef = (0, import_react13.useRef)((0,
|
|
2246
|
+
const idRef = (0, import_react13.useRef)((0, import_shared12.randomId)());
|
|
2249
2247
|
const renderAndWaitRef = (0, import_react13.useRef)(null);
|
|
2250
2248
|
const { addToast } = useToast();
|
|
2251
2249
|
action = __spreadValues({}, action);
|
|
@@ -2347,7 +2345,7 @@ function isFrontendAction(action) {
|
|
|
2347
2345
|
|
|
2348
2346
|
// src/hooks/use-coagent-state-render.ts
|
|
2349
2347
|
var import_react14 = require("react");
|
|
2350
|
-
var
|
|
2348
|
+
var import_shared13 = require("@copilotkit/shared");
|
|
2351
2349
|
function useCoAgentStateRender(action, dependencies) {
|
|
2352
2350
|
const {
|
|
2353
2351
|
setCoAgentStateRender,
|
|
@@ -2356,7 +2354,7 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
2356
2354
|
chatComponentsCache,
|
|
2357
2355
|
availableAgents
|
|
2358
2356
|
} = (0, import_react14.useContext)(CopilotContext);
|
|
2359
|
-
const idRef = (0, import_react14.useRef)((0,
|
|
2357
|
+
const idRef = (0, import_react14.useRef)((0, import_shared13.randomId)());
|
|
2360
2358
|
const { addToast } = useToast();
|
|
2361
2359
|
(0, import_react14.useEffect)(() => {
|
|
2362
2360
|
if ((availableAgents == null ? void 0 : availableAgents.length) && !availableAgents.some((a) => a.name === action.name)) {
|
|
@@ -2455,15 +2453,13 @@ function useCopilotReadable({ description, value, parentId, categories, convert
|
|
|
2455
2453
|
|
|
2456
2454
|
// src/hooks/use-coagent.ts
|
|
2457
2455
|
var import_react17 = require("react");
|
|
2456
|
+
var import_shared14 = require("@copilotkit/shared");
|
|
2458
2457
|
function useCoAgent(options) {
|
|
2459
2458
|
const generalContext = useCopilotContext();
|
|
2460
2459
|
const { availableAgents } = generalContext;
|
|
2461
2460
|
const { addToast } = useToast();
|
|
2462
2461
|
const lastLoadedThreadId = (0, import_react17.useRef)();
|
|
2463
2462
|
const lastLoadedState = (0, import_react17.useRef)();
|
|
2464
|
-
const isExternalStateManagement = (options2) => {
|
|
2465
|
-
return "state" in options2 && "setState" in options2;
|
|
2466
|
-
};
|
|
2467
2463
|
const { name } = options;
|
|
2468
2464
|
(0, import_react17.useEffect)(() => {
|
|
2469
2465
|
if ((availableAgents == null ? void 0 : availableAgents.length) && !availableAgents.some((a) => a.name === name)) {
|
|
@@ -2472,44 +2468,27 @@ function useCoAgent(options) {
|
|
|
2472
2468
|
addToast({ type: "warning", message });
|
|
2473
2469
|
}
|
|
2474
2470
|
}, [availableAgents]);
|
|
2475
|
-
const isInternalStateManagementWithInitial = (options2) => {
|
|
2476
|
-
return "initialState" in options2;
|
|
2477
|
-
};
|
|
2478
2471
|
const messagesContext = useCopilotMessagesContext();
|
|
2479
2472
|
const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
|
|
2480
2473
|
const { coagentStates, coagentStatesRef, setCoagentStatesWithRef, threadId, copilotApiConfig } = context;
|
|
2481
2474
|
const { appendMessage, runChatCompletion } = useCopilotChat();
|
|
2482
|
-
const getCoagentState = (coagentStates2, name2) => {
|
|
2483
|
-
var _a;
|
|
2484
|
-
if (coagentStates2[name2]) {
|
|
2485
|
-
return coagentStates2[name2];
|
|
2486
|
-
} else {
|
|
2487
|
-
return {
|
|
2488
|
-
name: name2,
|
|
2489
|
-
state: isInternalStateManagementWithInitial(options) ? options.initialState : {},
|
|
2490
|
-
configurable: (_a = options.configurable) != null ? _a : {},
|
|
2491
|
-
running: false,
|
|
2492
|
-
active: false,
|
|
2493
|
-
threadId: void 0,
|
|
2494
|
-
nodeName: void 0,
|
|
2495
|
-
runId: void 0
|
|
2496
|
-
};
|
|
2497
|
-
}
|
|
2498
|
-
};
|
|
2499
2475
|
const runtimeClient = useCopilotRuntimeClient({
|
|
2500
2476
|
url: copilotApiConfig.chatApiEndpoint,
|
|
2501
2477
|
publicApiKey: copilotApiConfig.publicApiKey,
|
|
2502
2478
|
credentials: copilotApiConfig.credentials
|
|
2503
2479
|
});
|
|
2504
|
-
const setState = (
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2480
|
+
const setState = (0, import_react17.useCallback)(
|
|
2481
|
+
(newState) => {
|
|
2482
|
+
let coagentState = getCoagentState({ coagentStates, name, options });
|
|
2483
|
+
const updatedState = typeof newState === "function" ? newState(coagentState.state) : newState;
|
|
2484
|
+
setCoagentStatesWithRef(__spreadProps(__spreadValues({}, coagentStatesRef.current), {
|
|
2485
|
+
[name]: __spreadProps(__spreadValues({}, coagentState), {
|
|
2486
|
+
state: updatedState
|
|
2487
|
+
})
|
|
2488
|
+
}));
|
|
2489
|
+
},
|
|
2490
|
+
[coagentStates, name]
|
|
2491
|
+
);
|
|
2513
2492
|
(0, import_react17.useEffect)(() => {
|
|
2514
2493
|
const fetchAgentState = () => __async(this, null, function* () {
|
|
2515
2494
|
var _a, _b, _c, _d;
|
|
@@ -2525,13 +2504,12 @@ function useCoAgent(options) {
|
|
|
2525
2504
|
if (((_d = (_c = result.data) == null ? void 0 : _c.loadAgentState) == null ? void 0 : _d.threadExists) && newState && newState != "{}") {
|
|
2526
2505
|
lastLoadedState.current = newState;
|
|
2527
2506
|
lastLoadedThreadId.current = threadId;
|
|
2528
|
-
const fetchedState =
|
|
2507
|
+
const fetchedState = (0, import_shared14.parseJson)(newState, {});
|
|
2529
2508
|
isExternalStateManagement(options) ? options.setState(fetchedState) : setState(fetchedState);
|
|
2530
2509
|
}
|
|
2531
2510
|
});
|
|
2532
2511
|
void fetchAgentState();
|
|
2533
2512
|
}, [threadId]);
|
|
2534
|
-
const coagentState = getCoagentState(coagentStates, name);
|
|
2535
2513
|
(0, import_react17.useEffect)(() => {
|
|
2536
2514
|
if (isExternalStateManagement(options)) {
|
|
2537
2515
|
setState(options.state);
|
|
@@ -2549,17 +2527,20 @@ function useCoAgent(options) {
|
|
|
2549
2527
|
}),
|
|
2550
2528
|
[name, context, appendMessage, runChatCompletion]
|
|
2551
2529
|
);
|
|
2552
|
-
return {
|
|
2553
|
-
name,
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2530
|
+
return (0, import_react17.useMemo)(() => {
|
|
2531
|
+
const coagentState = getCoagentState({ coagentStates, name, options });
|
|
2532
|
+
return {
|
|
2533
|
+
name,
|
|
2534
|
+
nodeName: coagentState.nodeName,
|
|
2535
|
+
threadId: coagentState.threadId,
|
|
2536
|
+
running: coagentState.running,
|
|
2537
|
+
state: coagentState.state,
|
|
2538
|
+
setState: isExternalStateManagement(options) ? options.setState : setState,
|
|
2539
|
+
start: () => startAgent(name, context),
|
|
2540
|
+
stop: () => stopAgent(name, context),
|
|
2541
|
+
run: runAgentCallback
|
|
2542
|
+
};
|
|
2543
|
+
}, [name, coagentStates, options, setState, runAgentCallback]);
|
|
2563
2544
|
}
|
|
2564
2545
|
function startAgent(name, context) {
|
|
2565
2546
|
const { setAgentSession } = context;
|
|
@@ -2615,6 +2596,33 @@ function runAgent(name, context, appendMessage, runChatCompletion, hint) {
|
|
|
2615
2596
|
}
|
|
2616
2597
|
});
|
|
2617
2598
|
}
|
|
2599
|
+
var isExternalStateManagement = (options) => {
|
|
2600
|
+
return "state" in options && "setState" in options;
|
|
2601
|
+
};
|
|
2602
|
+
var isInternalStateManagementWithInitial = (options) => {
|
|
2603
|
+
return "initialState" in options;
|
|
2604
|
+
};
|
|
2605
|
+
var getCoagentState = ({
|
|
2606
|
+
coagentStates,
|
|
2607
|
+
name,
|
|
2608
|
+
options
|
|
2609
|
+
}) => {
|
|
2610
|
+
var _a;
|
|
2611
|
+
if (coagentStates[name]) {
|
|
2612
|
+
return coagentStates[name];
|
|
2613
|
+
} else {
|
|
2614
|
+
return {
|
|
2615
|
+
name,
|
|
2616
|
+
state: isInternalStateManagementWithInitial(options) ? options.initialState : {},
|
|
2617
|
+
configurable: (_a = options.configurable) != null ? _a : {},
|
|
2618
|
+
running: false,
|
|
2619
|
+
active: false,
|
|
2620
|
+
threadId: void 0,
|
|
2621
|
+
nodeName: void 0,
|
|
2622
|
+
runId: void 0
|
|
2623
|
+
};
|
|
2624
|
+
}
|
|
2625
|
+
};
|
|
2618
2626
|
|
|
2619
2627
|
// src/hooks/use-copilot-authenticated-action.ts
|
|
2620
2628
|
var import_react18 = require("react");
|
|
@@ -2662,13 +2670,13 @@ function useCopilotAuthenticatedAction_c(action, dependencies) {
|
|
|
2662
2670
|
|
|
2663
2671
|
// src/hooks/use-langgraph-interrupt.ts
|
|
2664
2672
|
var import_react20 = require("react");
|
|
2665
|
-
var
|
|
2673
|
+
var import_shared15 = require("@copilotkit/shared");
|
|
2666
2674
|
function useLangGraphInterrupt(action, dependencies) {
|
|
2667
2675
|
var _a;
|
|
2668
2676
|
const { setLangGraphInterruptAction, removeLangGraphInterruptAction, langGraphInterruptAction } = (0, import_react20.useContext)(CopilotContext);
|
|
2669
2677
|
const { runChatCompletion } = useCopilotChat();
|
|
2670
2678
|
const { addToast } = useToast();
|
|
2671
|
-
const actionId = (0,
|
|
2679
|
+
const actionId = (0, import_shared15.dataToUUID)(JSON.stringify(action), "lgAction");
|
|
2672
2680
|
const hasAction = (0, import_react20.useMemo)(
|
|
2673
2681
|
() => Boolean(langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.id),
|
|
2674
2682
|
[langGraphInterruptAction]
|
|
@@ -2684,10 +2692,9 @@ function useLangGraphInterrupt(action, dependencies) {
|
|
|
2684
2692
|
}
|
|
2685
2693
|
}, [(_a = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event) == null ? void 0 : _a.response, runChatCompletion, hasAction, isCurrentAction]);
|
|
2686
2694
|
(0, import_react20.useEffect)(() => {
|
|
2687
|
-
var _a2;
|
|
2688
2695
|
if (!action)
|
|
2689
2696
|
return;
|
|
2690
|
-
if (hasAction && !isCurrentAction && !
|
|
2697
|
+
if (hasAction && !isCurrentAction && !action.enabled) {
|
|
2691
2698
|
addToast({
|
|
2692
2699
|
type: "warning",
|
|
2693
2700
|
message: "An action is already registered for the interrupt event"
|
|
@@ -2710,12 +2717,11 @@ function useLangGraphInterrupt(action, dependencies) {
|
|
|
2710
2717
|
|
|
2711
2718
|
// src/hooks/use-langgraph-interrupt-render.ts
|
|
2712
2719
|
var import_react21 = __toESM(require("react"));
|
|
2713
|
-
var import_shared14 = require("@copilotkit/shared");
|
|
2714
2720
|
var InterruptRenderer = ({ event, result, render, resolve }) => {
|
|
2715
2721
|
return render({ event, result, resolve });
|
|
2716
2722
|
};
|
|
2717
2723
|
function useLangGraphInterruptRender() {
|
|
2718
|
-
const { langGraphInterruptAction, setLangGraphInterruptAction } = useCopilotContext();
|
|
2724
|
+
const { langGraphInterruptAction, setLangGraphInterruptAction, agentSession } = useCopilotContext();
|
|
2719
2725
|
const responseRef = import_react21.default.useRef();
|
|
2720
2726
|
const resolveInterrupt = (0, import_react21.useCallback)(
|
|
2721
2727
|
(response) => {
|
|
@@ -2728,8 +2734,8 @@ function useLangGraphInterruptRender() {
|
|
|
2728
2734
|
);
|
|
2729
2735
|
if (!langGraphInterruptAction || !langGraphInterruptAction.event || !langGraphInterruptAction.render)
|
|
2730
2736
|
return null;
|
|
2731
|
-
const { render, handler, event,
|
|
2732
|
-
const conditionsMet =
|
|
2737
|
+
const { render, handler, event, enabled } = langGraphInterruptAction;
|
|
2738
|
+
const conditionsMet = !agentSession || !enabled ? true : enabled({ eventValue: event.value, agentMetadata: agentSession });
|
|
2733
2739
|
if (!conditionsMet) {
|
|
2734
2740
|
return null;
|
|
2735
2741
|
}
|