@copilotkit/react-core 1.4.2-tyler-reset-chat.1 → 1.4.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 +5 -13
- package/dist/{chunk-4Z7QCC6V.mjs → chunk-A5ZAEL2W.mjs} +22 -33
- package/dist/chunk-A5ZAEL2W.mjs.map +1 -0
- package/dist/{chunk-RGZ6GR2B.mjs → chunk-BUWNIMNK.mjs} +12 -37
- package/dist/chunk-BUWNIMNK.mjs.map +1 -0
- package/dist/{chunk-XUPO37VH.mjs → chunk-H4VZMKR6.mjs} +2 -2
- package/dist/{chunk-HECZOHST.mjs → chunk-HZIY4NDC.mjs} +17 -36
- package/dist/chunk-HZIY4NDC.mjs.map +1 -0
- package/dist/{chunk-JR55I3FL.mjs → chunk-LMFSB5D5.mjs} +2 -2
- package/dist/{chunk-2JP64U3A.mjs → chunk-LODRWFMB.mjs} +2 -10
- package/dist/{chunk-2JP64U3A.mjs.map → chunk-LODRWFMB.mjs.map} +1 -1
- package/dist/{chunk-3R4J2TPH.mjs → chunk-MWZO6TUR.mjs} +2 -2
- package/dist/{chunk-6QKA3SNN.mjs → chunk-P6VS7ST4.mjs} +3 -12
- package/dist/{chunk-6QKA3SNN.mjs.map → chunk-P6VS7ST4.mjs.map} +1 -1
- package/dist/{chunk-USL3EHJB.mjs → chunk-QDGDXRRJ.mjs} +2 -2
- package/dist/{chunk-3AYELZJS.mjs → chunk-XINZBP3J.mjs} +2 -2
- package/dist/components/copilot-provider/copilotkit.js +2 -19
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +2 -2
- package/dist/components/copilot-provider/index.js +2 -19
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +2 -2
- package/dist/components/index.js +2 -19
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +2 -2
- package/dist/context/copilot-context.d.ts +0 -6
- package/dist/context/copilot-context.js +1 -9
- package/dist/context/copilot-context.js.map +1 -1
- package/dist/context/copilot-context.mjs +1 -1
- package/dist/context/index.js +1 -9
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +1 -1
- package/dist/hooks/index.d.ts +1 -2
- package/dist/hooks/index.js +43 -109
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +9 -15
- package/dist/hooks/use-chat.d.ts +4 -20
- package/dist/hooks/use-chat.js +16 -35
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +1 -1
- package/dist/hooks/use-coagent-state-render.js +1 -9
- 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.d.ts +1 -14
- package/dist/hooks/use-coagent.js +43 -109
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +5 -11
- package/dist/hooks/use-copilot-action.js +1 -9
- package/dist/hooks/use-copilot-action.js.map +1 -1
- package/dist/hooks/use-copilot-action.mjs +2 -2
- package/dist/hooks/use-copilot-chat.d.ts +1 -1
- package/dist/hooks/use-copilot-chat.js +25 -77
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +4 -4
- package/dist/hooks/use-copilot-readable.js +1 -9
- package/dist/hooks/use-copilot-readable.js.map +1 -1
- package/dist/hooks/use-copilot-readable.mjs +2 -2
- package/dist/hooks/use-make-copilot-document-readable.js +1 -9
- 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 +1 -1
- package/dist/index.js +44 -119
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -16
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +3 -3
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +3 -3
- package/dist/utils/extract.js.map +1 -1
- package/dist/utils/extract.mjs +2 -2
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +2 -2
- package/package.json +5 -5
- package/src/components/copilot-provider/copilotkit.tsx +0 -10
- package/src/context/copilot-context.tsx +0 -22
- package/src/hooks/index.ts +1 -1
- package/src/hooks/use-chat.ts +21 -53
- package/src/hooks/use-coagent.ts +26 -35
- package/src/hooks/use-copilot-chat.ts +10 -37
- package/dist/chunk-4Z7QCC6V.mjs.map +0 -1
- package/dist/chunk-HECZOHST.mjs.map +0 -1
- package/dist/chunk-RGZ6GR2B.mjs.map +0 -1
- /package/dist/{chunk-XUPO37VH.mjs.map → chunk-H4VZMKR6.mjs.map} +0 -0
- /package/dist/{chunk-JR55I3FL.mjs.map → chunk-LMFSB5D5.mjs.map} +0 -0
- /package/dist/{chunk-3R4J2TPH.mjs.map → chunk-MWZO6TUR.mjs.map} +0 -0
- /package/dist/{chunk-USL3EHJB.mjs.map → chunk-QDGDXRRJ.mjs.map} +0 -0
- /package/dist/{chunk-3AYELZJS.mjs.map → chunk-XINZBP3J.mjs.map} +0 -0
|
@@ -79,9 +79,6 @@ var __async = (__this, __arguments, generator) => {
|
|
|
79
79
|
// src/hooks/use-coagent.ts
|
|
80
80
|
var use_coagent_exports = {};
|
|
81
81
|
__export(use_coagent_exports, {
|
|
82
|
-
runAgent: () => runAgent,
|
|
83
|
-
startAgent: () => startAgent,
|
|
84
|
-
stopAgent: () => stopAgent,
|
|
85
82
|
useCoAgent: () => useCoAgent
|
|
86
83
|
});
|
|
87
84
|
module.exports = __toCommonJS(use_coagent_exports);
|
|
@@ -138,15 +135,7 @@ var emptyCopilotContext = {
|
|
|
138
135
|
},
|
|
139
136
|
agentSession: null,
|
|
140
137
|
setAgentSession: () => {
|
|
141
|
-
}
|
|
142
|
-
agentLock: null,
|
|
143
|
-
threadId: null,
|
|
144
|
-
setThreadId: () => {
|
|
145
|
-
},
|
|
146
|
-
runId: null,
|
|
147
|
-
setRunId: () => {
|
|
148
|
-
},
|
|
149
|
-
chatAbortControllerRef: { current: null }
|
|
138
|
+
}
|
|
150
139
|
};
|
|
151
140
|
var CopilotContext = import_react.default.createContext(emptyCopilotContext);
|
|
152
141
|
function useCopilotContext() {
|
|
@@ -232,23 +221,17 @@ function useChat(options) {
|
|
|
232
221
|
setCoagentStates,
|
|
233
222
|
coagentStates,
|
|
234
223
|
agentSession,
|
|
235
|
-
setAgentSession
|
|
236
|
-
threadId,
|
|
237
|
-
setThreadId,
|
|
238
|
-
runId,
|
|
239
|
-
setRunId,
|
|
240
|
-
chatAbortControllerRef
|
|
224
|
+
setAgentSession
|
|
241
225
|
} = options;
|
|
226
|
+
const abortControllerRef = (0, import_react5.useRef)();
|
|
227
|
+
const threadIdRef = (0, import_react5.useRef)(null);
|
|
228
|
+
const runIdRef = (0, import_react5.useRef)(null);
|
|
242
229
|
const { addGraphQLErrorsToast } = useToast();
|
|
243
230
|
const runChatCompletionRef = (0, import_react5.useRef)();
|
|
244
231
|
const coagentStatesRef = (0, import_react5.useRef)(coagentStates);
|
|
245
232
|
coagentStatesRef.current = coagentStates;
|
|
246
233
|
const agentSessionRef = (0, import_react5.useRef)(agentSession);
|
|
247
234
|
agentSessionRef.current = agentSession;
|
|
248
|
-
const threadIdRef = (0, import_react5.useRef)(threadId);
|
|
249
|
-
threadIdRef.current = threadId;
|
|
250
|
-
const runIdRef = (0, import_react5.useRef)(runId);
|
|
251
|
-
runIdRef.current = runId;
|
|
252
235
|
const publicApiKey = copilotConfig.publicApiKey;
|
|
253
236
|
const headers = __spreadValues(__spreadValues({}, copilotConfig.headers || {}), publicApiKey ? { [import_shared.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
|
|
254
237
|
const runtimeClient = useCopilotRuntimeClient({
|
|
@@ -266,7 +249,8 @@ function useChat(options) {
|
|
|
266
249
|
role: import_runtime_client_gql2.Role.Assistant
|
|
267
250
|
})
|
|
268
251
|
];
|
|
269
|
-
|
|
252
|
+
const abortController = new AbortController();
|
|
253
|
+
abortControllerRef.current = abortController;
|
|
270
254
|
setMessages([...previousMessages, ...newMessages]);
|
|
271
255
|
const systemMessage = makeSystemMessageCallback();
|
|
272
256
|
const messagesWithContext = [systemMessage, ...initialMessages || [], ...previousMessages];
|
|
@@ -319,7 +303,7 @@ function useChat(options) {
|
|
|
319
303
|
}))
|
|
320
304
|
}),
|
|
321
305
|
properties: copilotConfig.properties,
|
|
322
|
-
signal: (_d =
|
|
306
|
+
signal: (_d = abortControllerRef.current) == null ? void 0 : _d.signal
|
|
323
307
|
})
|
|
324
308
|
);
|
|
325
309
|
const guardrailsEnabled = ((_g = (_f = (_e = copilotConfig.cloud) == null ? void 0 : _e.guardrails) == null ? void 0 : _f.input) == null ? void 0 : _g.restrictToTopic.enabled) || false;
|
|
@@ -338,9 +322,6 @@ function useChat(options) {
|
|
|
338
322
|
break;
|
|
339
323
|
}
|
|
340
324
|
if (done) {
|
|
341
|
-
if (chatAbortControllerRef.current.signal.aborted) {
|
|
342
|
-
return newMessages.slice();
|
|
343
|
-
}
|
|
344
325
|
break;
|
|
345
326
|
}
|
|
346
327
|
if (!(value == null ? void 0 : value.generateCopilotResponse)) {
|
|
@@ -348,8 +329,6 @@ function useChat(options) {
|
|
|
348
329
|
}
|
|
349
330
|
threadIdRef.current = value.generateCopilotResponse.threadId || null;
|
|
350
331
|
runIdRef.current = value.generateCopilotResponse.runId || null;
|
|
351
|
-
setThreadId(threadIdRef.current);
|
|
352
|
-
setRunId(runIdRef.current);
|
|
353
332
|
const messages2 = (0, import_runtime_client_gql2.convertGqlOutputToMessages)(
|
|
354
333
|
(0, import_runtime_client_gql2.filterAdjacentAgentStateMessages)(value.generateCopilotResponse.messages)
|
|
355
334
|
);
|
|
@@ -378,22 +357,12 @@ function useChat(options) {
|
|
|
378
357
|
if (action) {
|
|
379
358
|
followUp = action.followUp;
|
|
380
359
|
}
|
|
381
|
-
const result = yield
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
new Promise((_, reject) => {
|
|
388
|
-
var _a2;
|
|
389
|
-
return (_a2 = chatAbortControllerRef.current) == null ? void 0 : _a2.signal.addEventListener("abort", () => reject(new Error("Operation was aborted")));
|
|
390
|
-
})
|
|
391
|
-
]);
|
|
392
|
-
if (chatAbortControllerRef.current.signal.aborted) {
|
|
393
|
-
actionResults[message.id] = "";
|
|
394
|
-
} else {
|
|
395
|
-
actionResults[message.id] = result;
|
|
396
|
-
}
|
|
360
|
+
const result = yield onFunctionCall({
|
|
361
|
+
messages: previousMessages,
|
|
362
|
+
name: message.name,
|
|
363
|
+
args: message.arguments
|
|
364
|
+
});
|
|
365
|
+
actionResults[message.id] = result;
|
|
397
366
|
} catch (e) {
|
|
398
367
|
actionResults[message.id] = `Failed to execute action ${message.name}`;
|
|
399
368
|
console.error(`Failed to execute action ${message.name}: ${e}`);
|
|
@@ -488,12 +457,13 @@ function useChat(options) {
|
|
|
488
457
|
});
|
|
489
458
|
const stop = () => {
|
|
490
459
|
var _a;
|
|
491
|
-
(_a =
|
|
460
|
+
(_a = abortControllerRef.current) == null ? void 0 : _a.abort();
|
|
492
461
|
};
|
|
493
462
|
return {
|
|
494
463
|
append,
|
|
495
464
|
reload,
|
|
496
|
-
stop
|
|
465
|
+
stop,
|
|
466
|
+
runChatCompletion: () => runChatCompletionRef.current(messages)
|
|
497
467
|
};
|
|
498
468
|
}
|
|
499
469
|
|
|
@@ -523,13 +493,7 @@ function useCopilotChat(_a = {}) {
|
|
|
523
493
|
setCoagentStates,
|
|
524
494
|
coAgentStateRenders,
|
|
525
495
|
agentSession,
|
|
526
|
-
setAgentSession
|
|
527
|
-
agentLock,
|
|
528
|
-
threadId,
|
|
529
|
-
setThreadId,
|
|
530
|
-
runId,
|
|
531
|
-
setRunId,
|
|
532
|
-
chatAbortControllerRef
|
|
496
|
+
setAgentSession
|
|
533
497
|
} = useCopilotContext();
|
|
534
498
|
const { messages, setMessages } = useCopilotMessagesContext();
|
|
535
499
|
const latestGetContextString = useUpdatedRef(getContextString);
|
|
@@ -565,7 +529,7 @@ function useCopilotChat(_a = {}) {
|
|
|
565
529
|
}),
|
|
566
530
|
[coAgentStateRenders]
|
|
567
531
|
);
|
|
568
|
-
const { append, reload, stop } = useChat(__spreadProps(__spreadValues({}, options), {
|
|
532
|
+
const { append, reload, stop, runChatCompletion } = useChat(__spreadProps(__spreadValues({}, options), {
|
|
569
533
|
actions: Object.values(actions),
|
|
570
534
|
copilotConfig: copilotApiConfig,
|
|
571
535
|
initialMessages: options.initialMessages || [],
|
|
@@ -579,12 +543,7 @@ function useCopilotChat(_a = {}) {
|
|
|
579
543
|
coagentStates,
|
|
580
544
|
setCoagentStates,
|
|
581
545
|
agentSession,
|
|
582
|
-
setAgentSession
|
|
583
|
-
threadId,
|
|
584
|
-
setThreadId,
|
|
585
|
-
runId,
|
|
586
|
-
setRunId,
|
|
587
|
-
chatAbortControllerRef
|
|
546
|
+
setAgentSession
|
|
588
547
|
}));
|
|
589
548
|
const latestAppend = useUpdatedRef(append);
|
|
590
549
|
const latestAppendFunc = (0, import_react7.useCallback)(
|
|
@@ -615,32 +574,18 @@ function useCopilotChat(_a = {}) {
|
|
|
615
574
|
},
|
|
616
575
|
[latestSetMessages]
|
|
617
576
|
);
|
|
618
|
-
const
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
setRunId(null);
|
|
623
|
-
setCoagentStates({});
|
|
624
|
-
let initialAgentSession = null;
|
|
625
|
-
if (agentLock) {
|
|
626
|
-
initialAgentSession = {
|
|
627
|
-
agentName: agentLock
|
|
628
|
-
};
|
|
629
|
-
}
|
|
630
|
-
setAgentSession(initialAgentSession);
|
|
631
|
-
}, [latestStopFunc, setMessages, setThreadId, setCoagentStates, setAgentSession, agentLock]);
|
|
632
|
-
const latestReset = useUpdatedRef(reset);
|
|
633
|
-
const latestResetFunc = (0, import_react7.useCallback)(() => {
|
|
634
|
-
return latestReset.current();
|
|
635
|
-
}, [latestReset]);
|
|
577
|
+
const latestRunChatCompletion = useUpdatedRef(runChatCompletion);
|
|
578
|
+
const latestRunChatCompletionFunc = (0, import_react7.useCallback)(() => {
|
|
579
|
+
return latestRunChatCompletion.current();
|
|
580
|
+
}, [latestRunChatCompletion]);
|
|
636
581
|
return {
|
|
637
582
|
visibleMessages: messages,
|
|
638
583
|
appendMessage: latestAppendFunc,
|
|
639
584
|
setMessages: latestSetMessagesFunc,
|
|
640
585
|
reloadMessages: latestReloadFunc,
|
|
641
586
|
stopGeneration: latestStopFunc,
|
|
642
|
-
reset: latestResetFunc,
|
|
643
587
|
deleteMessage: latestDeleteFunc,
|
|
588
|
+
runChatCompletion: latestRunChatCompletionFunc,
|
|
644
589
|
isLoading
|
|
645
590
|
};
|
|
646
591
|
}
|
|
@@ -676,6 +621,7 @@ ${additionalInstructions}` : "");
|
|
|
676
621
|
}
|
|
677
622
|
|
|
678
623
|
// src/hooks/use-coagent.ts
|
|
624
|
+
var import_react_dom2 = require("react-dom");
|
|
679
625
|
function useCoAgent(options) {
|
|
680
626
|
const isExternalStateManagement = (options2) => {
|
|
681
627
|
return "state" in options2 && "setState" in options2;
|
|
@@ -688,7 +634,7 @@ function useCoAgent(options) {
|
|
|
688
634
|
const messagesContext = useCopilotMessagesContext();
|
|
689
635
|
const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
|
|
690
636
|
const { coagentStates, setCoagentStates } = context;
|
|
691
|
-
const { appendMessage } = useCopilotChat();
|
|
637
|
+
const { appendMessage, runChatCompletion } = useCopilotChat();
|
|
692
638
|
const getCoagentState = (coagentStates2, name2) => {
|
|
693
639
|
if (coagentStates2[name2]) {
|
|
694
640
|
return coagentStates2[name2];
|
|
@@ -705,13 +651,15 @@ function useCoAgent(options) {
|
|
|
705
651
|
}
|
|
706
652
|
};
|
|
707
653
|
const setState = (newState) => {
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
654
|
+
(0, import_react_dom2.flushSync)(() => {
|
|
655
|
+
setCoagentStates((prevAgentStates) => {
|
|
656
|
+
let coagentState2 = getCoagentState(prevAgentStates, name);
|
|
657
|
+
const updatedState = typeof newState === "function" ? newState(coagentState2.state) : newState;
|
|
658
|
+
return __spreadProps(__spreadValues({}, prevAgentStates), {
|
|
659
|
+
[name]: __spreadProps(__spreadValues({}, coagentState2), {
|
|
660
|
+
state: updatedState
|
|
661
|
+
})
|
|
662
|
+
});
|
|
715
663
|
});
|
|
716
664
|
});
|
|
717
665
|
};
|
|
@@ -723,11 +671,7 @@ function useCoAgent(options) {
|
|
|
723
671
|
} else if (coagentStates[name] === void 0) {
|
|
724
672
|
setState(options.initialState === void 0 ? {} : options.initialState);
|
|
725
673
|
}
|
|
726
|
-
}, [
|
|
727
|
-
isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0,
|
|
728
|
-
// reset initialstate on reset
|
|
729
|
-
coagentStates[name] === void 0
|
|
730
|
-
]);
|
|
674
|
+
}, [isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0]);
|
|
731
675
|
return {
|
|
732
676
|
name,
|
|
733
677
|
nodeName: coagentState.nodeName,
|
|
@@ -741,7 +685,7 @@ function useCoAgent(options) {
|
|
|
741
685
|
stopAgent(name, context);
|
|
742
686
|
},
|
|
743
687
|
run: (hint) => {
|
|
744
|
-
return runAgent(name, context, appendMessage, hint);
|
|
688
|
+
return runAgent(name, context, appendMessage, runChatCompletion, hint);
|
|
745
689
|
}
|
|
746
690
|
};
|
|
747
691
|
}
|
|
@@ -755,22 +699,11 @@ function stopAgent(name, context) {
|
|
|
755
699
|
const { agentSession, setAgentSession } = context;
|
|
756
700
|
if (agentSession && agentSession.agentName === name) {
|
|
757
701
|
setAgentSession(null);
|
|
758
|
-
context.setCoagentStates((prevAgentStates) => {
|
|
759
|
-
return __spreadProps(__spreadValues({}, prevAgentStates), {
|
|
760
|
-
[name]: __spreadProps(__spreadValues({}, prevAgentStates[name]), {
|
|
761
|
-
running: false,
|
|
762
|
-
active: false,
|
|
763
|
-
threadId: void 0,
|
|
764
|
-
nodeName: void 0,
|
|
765
|
-
runId: void 0
|
|
766
|
-
})
|
|
767
|
-
});
|
|
768
|
-
});
|
|
769
702
|
} else {
|
|
770
703
|
console.warn(`No agent session found for ${name}`);
|
|
771
704
|
}
|
|
772
705
|
}
|
|
773
|
-
function runAgent(name, context, appendMessage, hint) {
|
|
706
|
+
function runAgent(name, context, appendMessage, runChatCompletion, hint) {
|
|
774
707
|
return __async(this, null, function* () {
|
|
775
708
|
var _a, _b;
|
|
776
709
|
const { agentSession, setAgentSession } = context;
|
|
@@ -791,15 +724,16 @@ function runAgent(name, context, appendMessage, hint) {
|
|
|
791
724
|
const hintMessage = hint({ previousState, currentState: state });
|
|
792
725
|
if (hintMessage) {
|
|
793
726
|
yield appendMessage(hintMessage);
|
|
727
|
+
} else {
|
|
728
|
+
yield runChatCompletion();
|
|
794
729
|
}
|
|
730
|
+
} else {
|
|
731
|
+
yield runChatCompletion();
|
|
795
732
|
}
|
|
796
733
|
});
|
|
797
734
|
}
|
|
798
735
|
// Annotate the CommonJS export names for ESM import in node:
|
|
799
736
|
0 && (module.exports = {
|
|
800
|
-
runAgent,
|
|
801
|
-
startAgent,
|
|
802
|
-
stopAgent,
|
|
803
737
|
useCoAgent
|
|
804
738
|
});
|
|
805
739
|
//# sourceMappingURL=use-coagent.js.map
|