@copilotkit/react-core 1.4.2 → 1.4.3
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 +23 -0
- package/dist/{chunk-QDGDXRRJ.mjs → chunk-AG7FH7OD.mjs} +2 -2
- package/dist/{chunk-P6VS7ST4.mjs → chunk-DHGXL5PC.mjs} +15 -2
- package/dist/{chunk-P6VS7ST4.mjs.map → chunk-DHGXL5PC.mjs.map} +1 -1
- package/dist/{chunk-HZIY4NDC.mjs → chunk-EUIBVFV6.mjs} +4 -6
- package/dist/chunk-EUIBVFV6.mjs.map +1 -0
- package/dist/{chunk-XINZBP3J.mjs → chunk-JHEAUB3Z.mjs} +2 -2
- package/dist/{chunk-A5ZAEL2W.mjs → chunk-O22KGHOQ.mjs} +12 -17
- package/dist/{chunk-A5ZAEL2W.mjs.map → chunk-O22KGHOQ.mjs.map} +1 -1
- package/dist/{chunk-LMFSB5D5.mjs → chunk-OT67R4NB.mjs} +2 -2
- package/dist/{chunk-H4VZMKR6.mjs → chunk-UOVONDR6.mjs} +2 -2
- package/dist/{chunk-BUWNIMNK.mjs → chunk-XBVKTDXP.mjs} +8 -8
- package/dist/chunk-XBVKTDXP.mjs.map +1 -0
- package/dist/{chunk-LODRWFMB.mjs → chunk-XQFVXX6R.mjs} +4 -1
- package/dist/{chunk-LODRWFMB.mjs.map → chunk-XQFVXX6R.mjs.map} +1 -1
- package/dist/{chunk-MWZO6TUR.mjs → chunk-Y7MI4PBB.mjs} +2 -2
- package/dist/components/copilot-provider/copilotkit.js +16 -0
- 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 +16 -0
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +2 -2
- package/dist/components/index.js +16 -0
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +2 -2
- package/dist/context/copilot-context.d.ts +2 -0
- package/dist/context/copilot-context.js +3 -0
- package/dist/context/copilot-context.js.map +1 -1
- package/dist/context/copilot-context.mjs +1 -1
- package/dist/context/index.js +3 -0
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +1 -1
- package/dist/hooks/index.js +19 -23
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +9 -9
- package/dist/hooks/use-chat.d.ts +2 -2
- package/dist/hooks/use-chat.js +3 -5
- 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 +3 -0
- 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.js +19 -23
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +5 -5
- package/dist/hooks/use-copilot-action.js +3 -0
- 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 +10 -9
- 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 +3 -0
- 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 +3 -0
- 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.js +32 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -10
- 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 +18 -0
- package/src/context/copilot-context.tsx +9 -0
- package/src/hooks/use-chat.ts +7 -9
- package/src/hooks/use-coagent.ts +11 -16
- package/src/hooks/use-copilot-chat.ts +4 -4
- package/dist/chunk-BUWNIMNK.mjs.map +0 -1
- package/dist/chunk-HZIY4NDC.mjs.map +0 -1
- /package/dist/{chunk-QDGDXRRJ.mjs.map → chunk-AG7FH7OD.mjs.map} +0 -0
- /package/dist/{chunk-XINZBP3J.mjs.map → chunk-JHEAUB3Z.mjs.map} +0 -0
- /package/dist/{chunk-LMFSB5D5.mjs.map → chunk-OT67R4NB.mjs.map} +0 -0
- /package/dist/{chunk-H4VZMKR6.mjs.map → chunk-UOVONDR6.mjs.map} +0 -0
- /package/dist/{chunk-MWZO6TUR.mjs.map → chunk-Y7MI4PBB.mjs.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -152,6 +152,9 @@ var emptyCopilotContext = {
|
|
|
152
152
|
coagentStates: {},
|
|
153
153
|
setCoagentStates: () => {
|
|
154
154
|
},
|
|
155
|
+
coagentStatesRef: { current: {} },
|
|
156
|
+
setCoagentStatesWithRef: () => {
|
|
157
|
+
},
|
|
155
158
|
agentSession: null,
|
|
156
159
|
setAgentSession: () => {
|
|
157
160
|
}
|
|
@@ -946,6 +949,17 @@ ${nonDocumentStrings}`;
|
|
|
946
949
|
});
|
|
947
950
|
};
|
|
948
951
|
const [coagentStates, setCoagentStates] = (0, import_react8.useState)({});
|
|
952
|
+
const coagentStatesRef = (0, import_react8.useRef)({});
|
|
953
|
+
const setCoagentStatesWithRef = (0, import_react8.useCallback)(
|
|
954
|
+
(value) => {
|
|
955
|
+
const newValue = typeof value === "function" ? value(coagentStatesRef.current) : value;
|
|
956
|
+
coagentStatesRef.current = newValue;
|
|
957
|
+
setCoagentStates((prev) => {
|
|
958
|
+
return newValue;
|
|
959
|
+
});
|
|
960
|
+
},
|
|
961
|
+
[]
|
|
962
|
+
);
|
|
949
963
|
let initialAgentSession = null;
|
|
950
964
|
if (props.agent) {
|
|
951
965
|
initialAgentSession = {
|
|
@@ -983,6 +997,8 @@ ${nonDocumentStrings}`;
|
|
|
983
997
|
showDevConsole,
|
|
984
998
|
coagentStates,
|
|
985
999
|
setCoagentStates,
|
|
1000
|
+
coagentStatesRef,
|
|
1001
|
+
setCoagentStatesWithRef,
|
|
986
1002
|
agentSession,
|
|
987
1003
|
setAgentSession,
|
|
988
1004
|
runtimeClient
|
|
@@ -1038,8 +1054,8 @@ function useChat(options) {
|
|
|
1038
1054
|
actions,
|
|
1039
1055
|
onFunctionCall,
|
|
1040
1056
|
onCoAgentStateRender,
|
|
1041
|
-
|
|
1042
|
-
|
|
1057
|
+
setCoagentStatesWithRef,
|
|
1058
|
+
coagentStatesRef,
|
|
1043
1059
|
agentSession,
|
|
1044
1060
|
setAgentSession
|
|
1045
1061
|
} = options;
|
|
@@ -1048,8 +1064,6 @@ function useChat(options) {
|
|
|
1048
1064
|
const runIdRef = (0, import_react9.useRef)(null);
|
|
1049
1065
|
const { addGraphQLErrorsToast } = useToast();
|
|
1050
1066
|
const runChatCompletionRef = (0, import_react9.useRef)();
|
|
1051
|
-
const coagentStatesRef = (0, import_react9.useRef)(coagentStates);
|
|
1052
|
-
coagentStatesRef.current = coagentStates;
|
|
1053
1067
|
const agentSessionRef = (0, import_react9.useRef)(agentSession);
|
|
1054
1068
|
agentSessionRef.current = agentSession;
|
|
1055
1069
|
const publicApiKey = copilotConfig.publicApiKey;
|
|
@@ -1210,7 +1224,7 @@ function useChat(options) {
|
|
|
1210
1224
|
}
|
|
1211
1225
|
const lastAgentStateMessage = [...messages2].reverse().find((message) => message.isAgentStateMessage());
|
|
1212
1226
|
if (lastAgentStateMessage) {
|
|
1213
|
-
|
|
1227
|
+
setCoagentStatesWithRef((prevAgentStates) => __spreadProps(__spreadValues({}, prevAgentStates), {
|
|
1214
1228
|
[lastAgentStateMessage.agentName]: {
|
|
1215
1229
|
name: lastAgentStateMessage.agentName,
|
|
1216
1230
|
state: lastAgentStateMessage.state,
|
|
@@ -1302,8 +1316,8 @@ function useCopilotChat(_a = {}) {
|
|
|
1302
1316
|
setIsLoading,
|
|
1303
1317
|
chatInstructions,
|
|
1304
1318
|
actions,
|
|
1305
|
-
|
|
1306
|
-
|
|
1319
|
+
coagentStatesRef,
|
|
1320
|
+
setCoagentStatesWithRef,
|
|
1307
1321
|
coAgentStateRenders,
|
|
1308
1322
|
agentSession,
|
|
1309
1323
|
setAgentSession
|
|
@@ -1353,8 +1367,8 @@ function useCopilotChat(_a = {}) {
|
|
|
1353
1367
|
makeSystemMessageCallback,
|
|
1354
1368
|
isLoading,
|
|
1355
1369
|
setIsLoading,
|
|
1356
|
-
|
|
1357
|
-
|
|
1370
|
+
coagentStatesRef,
|
|
1371
|
+
setCoagentStatesWithRef,
|
|
1358
1372
|
agentSession,
|
|
1359
1373
|
setAgentSession
|
|
1360
1374
|
}));
|
|
@@ -1590,7 +1604,6 @@ function useCopilotReadable({ description, value, parentId, categories, convert
|
|
|
1590
1604
|
|
|
1591
1605
|
// src/hooks/use-coagent.ts
|
|
1592
1606
|
var import_react15 = require("react");
|
|
1593
|
-
var import_react_dom2 = require("react-dom");
|
|
1594
1607
|
function useCoAgent(options) {
|
|
1595
1608
|
const isExternalStateManagement = (options2) => {
|
|
1596
1609
|
return "state" in options2 && "setState" in options2;
|
|
@@ -1602,7 +1615,7 @@ function useCoAgent(options) {
|
|
|
1602
1615
|
const generalContext = useCopilotContext();
|
|
1603
1616
|
const messagesContext = useCopilotMessagesContext();
|
|
1604
1617
|
const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
|
|
1605
|
-
const { coagentStates,
|
|
1618
|
+
const { coagentStates, coagentStatesRef, setCoagentStatesWithRef } = context;
|
|
1606
1619
|
const { appendMessage, runChatCompletion } = useCopilotChat();
|
|
1607
1620
|
const getCoagentState = (coagentStates2, name2) => {
|
|
1608
1621
|
if (coagentStates2[name2]) {
|
|
@@ -1620,17 +1633,13 @@ function useCoAgent(options) {
|
|
|
1620
1633
|
}
|
|
1621
1634
|
};
|
|
1622
1635
|
const setState = (newState) => {
|
|
1623
|
-
(
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
})
|
|
1631
|
-
});
|
|
1632
|
-
});
|
|
1633
|
-
});
|
|
1636
|
+
let coagentState2 = getCoagentState(coagentStatesRef.current || {}, name);
|
|
1637
|
+
const updatedState = typeof newState === "function" ? newState(coagentState2.state) : newState;
|
|
1638
|
+
setCoagentStatesWithRef(__spreadProps(__spreadValues({}, coagentStatesRef.current), {
|
|
1639
|
+
[name]: __spreadProps(__spreadValues({}, coagentState2), {
|
|
1640
|
+
state: updatedState
|
|
1641
|
+
})
|
|
1642
|
+
}));
|
|
1634
1643
|
};
|
|
1635
1644
|
const coagentState = getCoagentState(coagentStates, name);
|
|
1636
1645
|
const state = isExternalStateManagement(options) ? options.state : coagentState.state;
|
|
@@ -1688,7 +1697,7 @@ function runAgent(name, context, appendMessage, runChatCompletion, hint) {
|
|
|
1688
1697
|
previousState = message.state;
|
|
1689
1698
|
}
|
|
1690
1699
|
}
|
|
1691
|
-
let state = ((_b = (_a = context.
|
|
1700
|
+
let state = ((_b = (_a = context.coagentStatesRef.current) == null ? void 0 : _a[name]) == null ? void 0 : _b.state) || {};
|
|
1692
1701
|
if (hint) {
|
|
1693
1702
|
const hintMessage = hint({ previousState, currentState: state });
|
|
1694
1703
|
if (hintMessage) {
|