@copilotkit/react-core 1.4.2-tyler-reset-chat.0 → 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 -4
- package/dist/{chunk-SEPYQHH7.mjs → chunk-A5ZAEL2W.mjs} +22 -33
- package/dist/chunk-A5ZAEL2W.mjs.map +1 -0
- package/dist/{chunk-CZMEZR6F.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-6EN7J4V2.mjs → chunk-HZIY4NDC.mjs} +17 -38
- 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 -111
- 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 -37
- 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 -111
- 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 -79
- 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 -121
- 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 +19 -56
- package/src/hooks/use-coagent.ts +26 -35
- package/src/hooks/use-copilot-chat.ts +10 -37
- package/dist/chunk-6EN7J4V2.mjs.map +0 -1
- package/dist/chunk-CZMEZR6F.mjs.map +0 -1
- package/dist/chunk-SEPYQHH7.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,25 +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;
|
|
242
|
-
const
|
|
243
|
-
|
|
226
|
+
const abortControllerRef = (0, import_react5.useRef)();
|
|
227
|
+
const threadIdRef = (0, import_react5.useRef)(null);
|
|
228
|
+
const runIdRef = (0, import_react5.useRef)(null);
|
|
244
229
|
const { addGraphQLErrorsToast } = useToast();
|
|
245
230
|
const runChatCompletionRef = (0, import_react5.useRef)();
|
|
246
231
|
const coagentStatesRef = (0, import_react5.useRef)(coagentStates);
|
|
247
232
|
coagentStatesRef.current = coagentStates;
|
|
248
233
|
const agentSessionRef = (0, import_react5.useRef)(agentSession);
|
|
249
234
|
agentSessionRef.current = agentSession;
|
|
250
|
-
const threadIdRef = (0, import_react5.useRef)(threadId);
|
|
251
|
-
threadIdRef.current = threadId;
|
|
252
|
-
const runIdRef = (0, import_react5.useRef)(runId);
|
|
253
|
-
runIdRef.current = runId;
|
|
254
235
|
const publicApiKey = copilotConfig.publicApiKey;
|
|
255
236
|
const headers = __spreadValues(__spreadValues({}, copilotConfig.headers || {}), publicApiKey ? { [import_shared.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
|
|
256
237
|
const runtimeClient = useCopilotRuntimeClient({
|
|
@@ -268,7 +249,8 @@ function useChat(options) {
|
|
|
268
249
|
role: import_runtime_client_gql2.Role.Assistant
|
|
269
250
|
})
|
|
270
251
|
];
|
|
271
|
-
|
|
252
|
+
const abortController = new AbortController();
|
|
253
|
+
abortControllerRef.current = abortController;
|
|
272
254
|
setMessages([...previousMessages, ...newMessages]);
|
|
273
255
|
const systemMessage = makeSystemMessageCallback();
|
|
274
256
|
const messagesWithContext = [systemMessage, ...initialMessages || [], ...previousMessages];
|
|
@@ -321,7 +303,7 @@ function useChat(options) {
|
|
|
321
303
|
}))
|
|
322
304
|
}),
|
|
323
305
|
properties: copilotConfig.properties,
|
|
324
|
-
signal: (_d =
|
|
306
|
+
signal: (_d = abortControllerRef.current) == null ? void 0 : _d.signal
|
|
325
307
|
})
|
|
326
308
|
);
|
|
327
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;
|
|
@@ -340,9 +322,6 @@ function useChat(options) {
|
|
|
340
322
|
break;
|
|
341
323
|
}
|
|
342
324
|
if (done) {
|
|
343
|
-
if (chatAbortControllerRef.current.signal.aborted) {
|
|
344
|
-
return newMessages.slice();
|
|
345
|
-
}
|
|
346
325
|
break;
|
|
347
326
|
}
|
|
348
327
|
if (!(value == null ? void 0 : value.generateCopilotResponse)) {
|
|
@@ -350,8 +329,6 @@ function useChat(options) {
|
|
|
350
329
|
}
|
|
351
330
|
threadIdRef.current = value.generateCopilotResponse.threadId || null;
|
|
352
331
|
runIdRef.current = value.generateCopilotResponse.runId || null;
|
|
353
|
-
setThreadId(threadIdRef.current);
|
|
354
|
-
setRunId(runIdRef.current);
|
|
355
332
|
const messages2 = (0, import_runtime_client_gql2.convertGqlOutputToMessages)(
|
|
356
333
|
(0, import_runtime_client_gql2.filterAdjacentAgentStateMessages)(value.generateCopilotResponse.messages)
|
|
357
334
|
);
|
|
@@ -380,22 +357,12 @@ function useChat(options) {
|
|
|
380
357
|
if (action) {
|
|
381
358
|
followUp = action.followUp;
|
|
382
359
|
}
|
|
383
|
-
const result = yield
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
new Promise((_, reject) => {
|
|
390
|
-
var _a2;
|
|
391
|
-
return (_a2 = chatAbortControllerRef.current) == null ? void 0 : _a2.signal.addEventListener("abort", () => reject(new Error("Operation was aborted")));
|
|
392
|
-
})
|
|
393
|
-
]);
|
|
394
|
-
if (chatAbortControllerRef.current.signal.aborted) {
|
|
395
|
-
actionResults[message.id] = "";
|
|
396
|
-
} else {
|
|
397
|
-
actionResults[message.id] = result;
|
|
398
|
-
}
|
|
360
|
+
const result = yield onFunctionCall({
|
|
361
|
+
messages: previousMessages,
|
|
362
|
+
name: message.name,
|
|
363
|
+
args: message.arguments
|
|
364
|
+
});
|
|
365
|
+
actionResults[message.id] = result;
|
|
399
366
|
} catch (e) {
|
|
400
367
|
actionResults[message.id] = `Failed to execute action ${message.name}`;
|
|
401
368
|
console.error(`Failed to execute action ${message.name}: ${e}`);
|
|
@@ -490,12 +457,13 @@ function useChat(options) {
|
|
|
490
457
|
});
|
|
491
458
|
const stop = () => {
|
|
492
459
|
var _a;
|
|
493
|
-
(_a =
|
|
460
|
+
(_a = abortControllerRef.current) == null ? void 0 : _a.abort();
|
|
494
461
|
};
|
|
495
462
|
return {
|
|
496
463
|
append,
|
|
497
464
|
reload,
|
|
498
|
-
stop
|
|
465
|
+
stop,
|
|
466
|
+
runChatCompletion: () => runChatCompletionRef.current(messages)
|
|
499
467
|
};
|
|
500
468
|
}
|
|
501
469
|
|
|
@@ -525,13 +493,7 @@ function useCopilotChat(_a = {}) {
|
|
|
525
493
|
setCoagentStates,
|
|
526
494
|
coAgentStateRenders,
|
|
527
495
|
agentSession,
|
|
528
|
-
setAgentSession
|
|
529
|
-
agentLock,
|
|
530
|
-
threadId,
|
|
531
|
-
setThreadId,
|
|
532
|
-
runId,
|
|
533
|
-
setRunId,
|
|
534
|
-
chatAbortControllerRef
|
|
496
|
+
setAgentSession
|
|
535
497
|
} = useCopilotContext();
|
|
536
498
|
const { messages, setMessages } = useCopilotMessagesContext();
|
|
537
499
|
const latestGetContextString = useUpdatedRef(getContextString);
|
|
@@ -567,7 +529,7 @@ function useCopilotChat(_a = {}) {
|
|
|
567
529
|
}),
|
|
568
530
|
[coAgentStateRenders]
|
|
569
531
|
);
|
|
570
|
-
const { append, reload, stop } = useChat(__spreadProps(__spreadValues({}, options), {
|
|
532
|
+
const { append, reload, stop, runChatCompletion } = useChat(__spreadProps(__spreadValues({}, options), {
|
|
571
533
|
actions: Object.values(actions),
|
|
572
534
|
copilotConfig: copilotApiConfig,
|
|
573
535
|
initialMessages: options.initialMessages || [],
|
|
@@ -581,12 +543,7 @@ function useCopilotChat(_a = {}) {
|
|
|
581
543
|
coagentStates,
|
|
582
544
|
setCoagentStates,
|
|
583
545
|
agentSession,
|
|
584
|
-
setAgentSession
|
|
585
|
-
threadId,
|
|
586
|
-
setThreadId,
|
|
587
|
-
runId,
|
|
588
|
-
setRunId,
|
|
589
|
-
chatAbortControllerRef
|
|
546
|
+
setAgentSession
|
|
590
547
|
}));
|
|
591
548
|
const latestAppend = useUpdatedRef(append);
|
|
592
549
|
const latestAppendFunc = (0, import_react7.useCallback)(
|
|
@@ -617,32 +574,18 @@ function useCopilotChat(_a = {}) {
|
|
|
617
574
|
},
|
|
618
575
|
[latestSetMessages]
|
|
619
576
|
);
|
|
620
|
-
const
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
setRunId(null);
|
|
625
|
-
setCoagentStates({});
|
|
626
|
-
let initialAgentSession = null;
|
|
627
|
-
if (agentLock) {
|
|
628
|
-
initialAgentSession = {
|
|
629
|
-
agentName: agentLock
|
|
630
|
-
};
|
|
631
|
-
}
|
|
632
|
-
setAgentSession(initialAgentSession);
|
|
633
|
-
}, [latestStopFunc, setMessages, setThreadId, setCoagentStates, setAgentSession, agentLock]);
|
|
634
|
-
const latestReset = useUpdatedRef(reset);
|
|
635
|
-
const latestResetFunc = (0, import_react7.useCallback)(() => {
|
|
636
|
-
return latestReset.current();
|
|
637
|
-
}, [latestReset]);
|
|
577
|
+
const latestRunChatCompletion = useUpdatedRef(runChatCompletion);
|
|
578
|
+
const latestRunChatCompletionFunc = (0, import_react7.useCallback)(() => {
|
|
579
|
+
return latestRunChatCompletion.current();
|
|
580
|
+
}, [latestRunChatCompletion]);
|
|
638
581
|
return {
|
|
639
582
|
visibleMessages: messages,
|
|
640
583
|
appendMessage: latestAppendFunc,
|
|
641
584
|
setMessages: latestSetMessagesFunc,
|
|
642
585
|
reloadMessages: latestReloadFunc,
|
|
643
586
|
stopGeneration: latestStopFunc,
|
|
644
|
-
reset: latestResetFunc,
|
|
645
587
|
deleteMessage: latestDeleteFunc,
|
|
588
|
+
runChatCompletion: latestRunChatCompletionFunc,
|
|
646
589
|
isLoading
|
|
647
590
|
};
|
|
648
591
|
}
|
|
@@ -678,6 +621,7 @@ ${additionalInstructions}` : "");
|
|
|
678
621
|
}
|
|
679
622
|
|
|
680
623
|
// src/hooks/use-coagent.ts
|
|
624
|
+
var import_react_dom2 = require("react-dom");
|
|
681
625
|
function useCoAgent(options) {
|
|
682
626
|
const isExternalStateManagement = (options2) => {
|
|
683
627
|
return "state" in options2 && "setState" in options2;
|
|
@@ -690,7 +634,7 @@ function useCoAgent(options) {
|
|
|
690
634
|
const messagesContext = useCopilotMessagesContext();
|
|
691
635
|
const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
|
|
692
636
|
const { coagentStates, setCoagentStates } = context;
|
|
693
|
-
const { appendMessage } = useCopilotChat();
|
|
637
|
+
const { appendMessage, runChatCompletion } = useCopilotChat();
|
|
694
638
|
const getCoagentState = (coagentStates2, name2) => {
|
|
695
639
|
if (coagentStates2[name2]) {
|
|
696
640
|
return coagentStates2[name2];
|
|
@@ -707,13 +651,15 @@ function useCoAgent(options) {
|
|
|
707
651
|
}
|
|
708
652
|
};
|
|
709
653
|
const setState = (newState) => {
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
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
|
+
});
|
|
717
663
|
});
|
|
718
664
|
});
|
|
719
665
|
};
|
|
@@ -725,11 +671,7 @@ function useCoAgent(options) {
|
|
|
725
671
|
} else if (coagentStates[name] === void 0) {
|
|
726
672
|
setState(options.initialState === void 0 ? {} : options.initialState);
|
|
727
673
|
}
|
|
728
|
-
}, [
|
|
729
|
-
isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0,
|
|
730
|
-
// reset initialstate on reset
|
|
731
|
-
coagentStates === void 0
|
|
732
|
-
]);
|
|
674
|
+
}, [isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0]);
|
|
733
675
|
return {
|
|
734
676
|
name,
|
|
735
677
|
nodeName: coagentState.nodeName,
|
|
@@ -743,7 +685,7 @@ function useCoAgent(options) {
|
|
|
743
685
|
stopAgent(name, context);
|
|
744
686
|
},
|
|
745
687
|
run: (hint) => {
|
|
746
|
-
return runAgent(name, context, appendMessage, hint);
|
|
688
|
+
return runAgent(name, context, appendMessage, runChatCompletion, hint);
|
|
747
689
|
}
|
|
748
690
|
};
|
|
749
691
|
}
|
|
@@ -757,22 +699,11 @@ function stopAgent(name, context) {
|
|
|
757
699
|
const { agentSession, setAgentSession } = context;
|
|
758
700
|
if (agentSession && agentSession.agentName === name) {
|
|
759
701
|
setAgentSession(null);
|
|
760
|
-
context.setCoagentStates((prevAgentStates) => {
|
|
761
|
-
return __spreadProps(__spreadValues({}, prevAgentStates), {
|
|
762
|
-
[name]: __spreadProps(__spreadValues({}, prevAgentStates[name]), {
|
|
763
|
-
running: false,
|
|
764
|
-
active: false,
|
|
765
|
-
threadId: void 0,
|
|
766
|
-
nodeName: void 0,
|
|
767
|
-
runId: void 0
|
|
768
|
-
})
|
|
769
|
-
});
|
|
770
|
-
});
|
|
771
702
|
} else {
|
|
772
703
|
console.warn(`No agent session found for ${name}`);
|
|
773
704
|
}
|
|
774
705
|
}
|
|
775
|
-
function runAgent(name, context, appendMessage, hint) {
|
|
706
|
+
function runAgent(name, context, appendMessage, runChatCompletion, hint) {
|
|
776
707
|
return __async(this, null, function* () {
|
|
777
708
|
var _a, _b;
|
|
778
709
|
const { agentSession, setAgentSession } = context;
|
|
@@ -793,15 +724,16 @@ function runAgent(name, context, appendMessage, hint) {
|
|
|
793
724
|
const hintMessage = hint({ previousState, currentState: state });
|
|
794
725
|
if (hintMessage) {
|
|
795
726
|
yield appendMessage(hintMessage);
|
|
727
|
+
} else {
|
|
728
|
+
yield runChatCompletion();
|
|
796
729
|
}
|
|
730
|
+
} else {
|
|
731
|
+
yield runChatCompletion();
|
|
797
732
|
}
|
|
798
733
|
});
|
|
799
734
|
}
|
|
800
735
|
// Annotate the CommonJS export names for ESM import in node:
|
|
801
736
|
0 && (module.exports = {
|
|
802
|
-
runAgent,
|
|
803
|
-
startAgent,
|
|
804
|
-
stopAgent,
|
|
805
737
|
useCoAgent
|
|
806
738
|
});
|
|
807
739
|
//# sourceMappingURL=use-coagent.js.map
|