@copilotkit/react-core 1.3.2-pre.0 → 1.3.3-pre.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/CHANGELOG.md +24 -4
- package/dist/{chunk-5BC3DR3F.mjs → chunk-7NPU3J4E.mjs} +4 -4
- package/dist/{chunk-TCZBK3HZ.mjs → chunk-CTATHNXD.mjs} +2 -2
- package/dist/{chunk-4O5723ZO.mjs → chunk-FFV2GM3D.mjs} +14 -7
- package/dist/chunk-FFV2GM3D.mjs.map +1 -0
- package/dist/{chunk-A37GANOW.mjs → chunk-FTZZHEAW.mjs} +31 -5
- package/dist/chunk-FTZZHEAW.mjs.map +1 -0
- package/dist/{chunk-STUXJ3BN.mjs → chunk-JE7SHBT3.mjs} +5 -5
- package/dist/chunk-JE7SHBT3.mjs.map +1 -0
- package/dist/{chunk-326LK7LX.mjs → chunk-LCRACIIO.mjs} +2 -2
- package/dist/{chunk-TEIODURE.mjs → chunk-NFDOLACY.mjs} +8 -22
- package/dist/chunk-NFDOLACY.mjs.map +1 -0
- package/dist/{chunk-RBNULK3U.mjs → chunk-PDJXYJ5N.mjs} +2 -2
- package/dist/chunk-PDJXYJ5N.mjs.map +1 -0
- package/dist/{chunk-CODXG6KU.mjs → chunk-VAAJZGFF.mjs} +2 -2
- package/dist/{chunk-J2YXDQHR.mjs → chunk-VWJ3BWCJ.mjs} +1 -1
- package/dist/chunk-VWJ3BWCJ.mjs.map +1 -0
- package/dist/{chunk-3U22BXKC.mjs → chunk-ZTZEKOR7.mjs} +2 -2
- package/dist/components/copilot-provider/copilotkit-props.d.ts +1 -1
- package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
- 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.map +1 -1
- package/dist/components/copilot-provider/index.mjs +2 -2
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +2 -2
- package/dist/context/copilot-context.d.ts +1 -1
- package/dist/context/copilot-context.js.map +1 -1
- package/dist/context/copilot-context.mjs +1 -1
- package/dist/context/index.d.ts +1 -1
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +46 -31
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +11 -11
- package/dist/hooks/use-chat.js +13 -6
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +1 -1
- package/dist/hooks/use-coagent-state-render.d.ts +5 -0
- package/dist/hooks/{use-coagent-action.js → use-coagent-state-render.js} +9 -9
- package/dist/hooks/use-coagent-state-render.js.map +1 -0
- package/dist/hooks/use-coagent-state-render.mjs +9 -0
- package/dist/hooks/use-coagent.d.ts +9 -2
- package/dist/hooks/use-coagent.js +17 -24
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +5 -5
- package/dist/hooks/use-copilot-action.d.ts +10 -1
- package/dist/hooks/use-copilot-action.js +39 -3
- 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.js +13 -6
- 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.map +1 -1
- package/dist/hooks/use-copilot-readable.mjs +2 -2
- 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 +2 -2
- package/dist/index.js +46 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +13 -13
- 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/types/coagent-action.d.ts +1 -1
- package/dist/types/coagent-action.js.map +1 -1
- package/dist/types/frontend-action.d.ts +46 -2
- package/dist/types/frontend-action.js.map +1 -1
- package/dist/utils/extract.js.map +1 -1
- package/dist/utils/extract.mjs +3 -3
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +3 -3
- package/package.json +5 -5
- package/src/components/copilot-provider/copilotkit-props.tsx +1 -1
- package/src/components/copilot-provider/copilotkit.tsx +8 -24
- package/src/context/copilot-context.tsx +1 -1
- package/src/context/index.ts +5 -2
- package/src/hooks/index.ts +1 -1
- package/src/hooks/use-chat.ts +27 -10
- package/src/hooks/{use-coagent-action.ts → use-coagent-state-render.ts} +4 -1
- package/src/hooks/use-coagent.ts +14 -17
- package/src/hooks/use-copilot-action.ts +103 -4
- package/src/types/coagent-action.ts +3 -1
- package/src/types/frontend-action.ts +69 -6
- package/dist/chunk-4O5723ZO.mjs.map +0 -1
- package/dist/chunk-A37GANOW.mjs.map +0 -1
- package/dist/chunk-J2YXDQHR.mjs.map +0 -1
- package/dist/chunk-RBNULK3U.mjs.map +0 -1
- package/dist/chunk-STUXJ3BN.mjs.map +0 -1
- package/dist/chunk-TEIODURE.mjs.map +0 -1
- package/dist/hooks/use-coagent-action.d.ts +0 -5
- package/dist/hooks/use-coagent-action.js.map +0 -1
- package/dist/hooks/use-coagent-action.mjs +0 -9
- /package/dist/{chunk-5BC3DR3F.mjs.map → chunk-7NPU3J4E.mjs.map} +0 -0
- /package/dist/{chunk-TCZBK3HZ.mjs.map → chunk-CTATHNXD.mjs.map} +0 -0
- /package/dist/{chunk-326LK7LX.mjs.map → chunk-LCRACIIO.mjs.map} +0 -0
- /package/dist/{chunk-CODXG6KU.mjs.map → chunk-VAAJZGFF.mjs.map} +0 -0
- /package/dist/{chunk-3U22BXKC.mjs.map → chunk-ZTZEKOR7.mjs.map} +0 -0
- /package/dist/hooks/{use-coagent-action.mjs.map → use-coagent-state-render.mjs.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -87,7 +87,7 @@ __export(src_exports, {
|
|
|
87
87
|
defaultCopilotContextCategories: () => defaultCopilotContextCategories,
|
|
88
88
|
extract: () => extract,
|
|
89
89
|
useCoAgent: () => useCoAgent,
|
|
90
|
-
|
|
90
|
+
useCoagentStateRender: () => useCoagentStateRender,
|
|
91
91
|
useCopilotAction: () => useCopilotAction,
|
|
92
92
|
useCopilotChat: () => useCopilotChat,
|
|
93
93
|
useCopilotContext: () => useCopilotContext,
|
|
@@ -612,6 +612,11 @@ function useChat(options) {
|
|
|
612
612
|
const abortControllerRef = (0, import_react5.useRef)();
|
|
613
613
|
const threadIdRef = (0, import_react5.useRef)(null);
|
|
614
614
|
const runIdRef = (0, import_react5.useRef)(null);
|
|
615
|
+
const runChatCompletionRef = (0, import_react5.useRef)();
|
|
616
|
+
const coagentStatesRef = (0, import_react5.useRef)(coagentStates);
|
|
617
|
+
coagentStatesRef.current = coagentStates;
|
|
618
|
+
const agentSessionRef = (0, import_react5.useRef)(agentSession);
|
|
619
|
+
agentSessionRef.current = agentSession;
|
|
615
620
|
const publicApiKey = copilotConfig.publicApiKey;
|
|
616
621
|
const headers = __spreadValues(__spreadValues({}, copilotConfig.headers || {}), publicApiKey ? { [import_shared4.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
|
|
617
622
|
const runtimeClient = new import_runtime_client_gql.CopilotRuntimeClient({
|
|
@@ -638,7 +643,7 @@ function useChat(options) {
|
|
|
638
643
|
runtimeClient.generateCopilotResponse({
|
|
639
644
|
data: __spreadProps(__spreadValues(__spreadProps(__spreadValues({
|
|
640
645
|
frontend: {
|
|
641
|
-
actions: actions.map((action) => ({
|
|
646
|
+
actions: actions.filter((action) => !action.disabled).map((action) => ({
|
|
642
647
|
name: action.name,
|
|
643
648
|
description: action.description || "",
|
|
644
649
|
jsonSchema: JSON.stringify((0, import_shared4.actionParametersToJsonSchema)(action.parameters || []))
|
|
@@ -661,10 +666,10 @@ function useChat(options) {
|
|
|
661
666
|
metadata: {
|
|
662
667
|
requestType: import_runtime_client_gql.CopilotRequestType.Chat
|
|
663
668
|
}
|
|
664
|
-
}),
|
|
665
|
-
agentSession
|
|
669
|
+
}), agentSessionRef.current ? {
|
|
670
|
+
agentSession: agentSessionRef.current
|
|
666
671
|
} : {}), {
|
|
667
|
-
agentStates: Object.values(
|
|
672
|
+
agentStates: Object.values(coagentStatesRef.current).map((state) => ({
|
|
668
673
|
agentName: state.name,
|
|
669
674
|
state: JSON.stringify(state.state)
|
|
670
675
|
}))
|
|
@@ -711,6 +716,7 @@ function useChat(options) {
|
|
|
711
716
|
break;
|
|
712
717
|
}
|
|
713
718
|
try {
|
|
719
|
+
setMessages([...previousMessages, ...newMessages]);
|
|
714
720
|
const result = yield onFunctionCall({
|
|
715
721
|
messages: previousMessages,
|
|
716
722
|
name: message.name,
|
|
@@ -776,7 +782,7 @@ function useChat(options) {
|
|
|
776
782
|
newMessages.length && newMessages[newMessages.length - 1] instanceof import_runtime_client_gql.ResultMessage
|
|
777
783
|
) {
|
|
778
784
|
yield new Promise((resolve) => setTimeout(resolve, 10));
|
|
779
|
-
return yield
|
|
785
|
+
return yield runChatCompletionRef.current([...previousMessages, ...newMessages]);
|
|
780
786
|
} else {
|
|
781
787
|
return newMessages.slice();
|
|
782
788
|
}
|
|
@@ -784,8 +790,9 @@ function useChat(options) {
|
|
|
784
790
|
setIsLoading(false);
|
|
785
791
|
}
|
|
786
792
|
});
|
|
793
|
+
runChatCompletionRef.current = runChatCompletion;
|
|
787
794
|
const runChatCompletionAndHandleFunctionCall = (messages2) => __async(this, null, function* () {
|
|
788
|
-
yield
|
|
795
|
+
yield runChatCompletionRef.current(messages2);
|
|
789
796
|
});
|
|
790
797
|
const append = (message) => __async(this, null, function* () {
|
|
791
798
|
if (isLoading) {
|
|
@@ -966,6 +973,31 @@ var import_shared5 = require("@copilotkit/shared");
|
|
|
966
973
|
function useCopilotAction(action, dependencies) {
|
|
967
974
|
const { setAction, removeAction, actions, chatComponentsCache } = useCopilotContext();
|
|
968
975
|
const idRef = (0, import_react7.useRef)((0, import_shared5.randomId)());
|
|
976
|
+
const renderAndWaitRef = (0, import_react7.useRef)(null);
|
|
977
|
+
action = __spreadValues({}, action);
|
|
978
|
+
if (action.renderAndWait) {
|
|
979
|
+
const renderAndWait = action.renderAndWait;
|
|
980
|
+
action.renderAndWait = void 0;
|
|
981
|
+
action.handler = () => __async(this, null, function* () {
|
|
982
|
+
let resolve;
|
|
983
|
+
let reject;
|
|
984
|
+
const promise = new Promise((resolvePromise, rejectPromise) => {
|
|
985
|
+
resolve = resolvePromise;
|
|
986
|
+
reject = rejectPromise;
|
|
987
|
+
});
|
|
988
|
+
renderAndWaitRef.current = { promise, resolve, reject };
|
|
989
|
+
return yield promise;
|
|
990
|
+
});
|
|
991
|
+
action.render = (props) => {
|
|
992
|
+
const waitProps = {
|
|
993
|
+
status: props.status,
|
|
994
|
+
args: props.args,
|
|
995
|
+
result: props.result,
|
|
996
|
+
handler: props.status === "executing" ? renderAndWaitRef.current.resolve : void 0
|
|
997
|
+
};
|
|
998
|
+
return renderAndWait(waitProps);
|
|
999
|
+
};
|
|
1000
|
+
}
|
|
969
1001
|
if (dependencies === void 0) {
|
|
970
1002
|
if (actions[idRef.current]) {
|
|
971
1003
|
actions[idRef.current].handler = action.handler;
|
|
@@ -977,9 +1009,6 @@ function useCopilotAction(action, dependencies) {
|
|
|
977
1009
|
}
|
|
978
1010
|
}
|
|
979
1011
|
(0, import_react7.useEffect)(() => {
|
|
980
|
-
if (action.disabled) {
|
|
981
|
-
return;
|
|
982
|
-
}
|
|
983
1012
|
setAction(idRef.current, action);
|
|
984
1013
|
if (chatComponentsCache.current !== null && action.render !== void 0) {
|
|
985
1014
|
chatComponentsCache.current.actions[action.name] = action.render;
|
|
@@ -1003,10 +1032,10 @@ function useCopilotAction(action, dependencies) {
|
|
|
1003
1032
|
]);
|
|
1004
1033
|
}
|
|
1005
1034
|
|
|
1006
|
-
// src/hooks/use-coagent-
|
|
1035
|
+
// src/hooks/use-coagent-state-render.ts
|
|
1007
1036
|
var import_react8 = require("react");
|
|
1008
1037
|
var import_shared6 = require("@copilotkit/shared");
|
|
1009
|
-
function
|
|
1038
|
+
function useCoagentStateRender(action, dependencies) {
|
|
1010
1039
|
const { setCoagentAction, removeCoagentAction, coagentActions, chatComponentsCache } = (0, import_react8.useContext)(CopilotContext);
|
|
1011
1040
|
const idRef = (0, import_react8.useRef)((0, import_shared6.randomId)());
|
|
1012
1041
|
const key = `${action.name}-${action.nodeName || "global"}`;
|
|
@@ -1171,26 +1200,12 @@ function runAgent(name, context, appendMessage, hint) {
|
|
|
1171
1200
|
}
|
|
1172
1201
|
}
|
|
1173
1202
|
let state = ((_b = (_a = context.coagentStates) == null ? void 0 : _a[name]) == null ? void 0 : _b.state) || {};
|
|
1174
|
-
let content = "The state of the agent has been updated\n";
|
|
1175
|
-
if (previousState !== null) {
|
|
1176
|
-
content += `The previous state was:
|
|
1177
|
-
${JSON.stringify(previousState, null, 2)}
|
|
1178
|
-
|
|
1179
|
-
`;
|
|
1180
|
-
}
|
|
1181
|
-
content += `The current state is:
|
|
1182
|
-
${JSON.stringify(state, null, 2)}`;
|
|
1183
1203
|
if (hint) {
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1204
|
+
const hintMessage = hint({ previousState, currentState: state });
|
|
1205
|
+
if (hintMessage) {
|
|
1206
|
+
yield appendMessage(hintMessage);
|
|
1207
|
+
}
|
|
1187
1208
|
}
|
|
1188
|
-
return yield appendMessage(
|
|
1189
|
-
new import_runtime_client_gql3.TextMessage({
|
|
1190
|
-
role: import_runtime_client_gql3.Role.System,
|
|
1191
|
-
content
|
|
1192
|
-
})
|
|
1193
|
-
);
|
|
1194
1209
|
});
|
|
1195
1210
|
}
|
|
1196
1211
|
|
|
@@ -1434,7 +1449,7 @@ Any additional messages provided are for providing context only and should not b
|
|
|
1434
1449
|
defaultCopilotContextCategories,
|
|
1435
1450
|
extract,
|
|
1436
1451
|
useCoAgent,
|
|
1437
|
-
|
|
1452
|
+
useCoagentStateRender,
|
|
1438
1453
|
useCopilotAction,
|
|
1439
1454
|
useCopilotChat,
|
|
1440
1455
|
useCopilotContext,
|