@copilotkit/react-core 1.67.1 → 1.68.1
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/dist/{copilotkit-CmMYFfLV.cjs → copilotkit-8KSSmCH_.cjs} +143 -169
- package/dist/copilotkit-8KSSmCH_.cjs.map +1 -0
- package/dist/{copilotkit-CBCT7BlL.d.cts → copilotkit-BICg0AyJ.d.cts} +25 -7
- package/dist/{copilotkit-D0aAnD3i.d.mts.map → copilotkit-BICg0AyJ.d.cts.map} +1 -1
- package/dist/{copilotkit-D0aAnD3i.d.mts → copilotkit-BrfN8YeF.d.mts} +76 -70
- package/dist/copilotkit-BrfN8YeF.d.mts.map +1 -0
- package/dist/{copilotkit-DMmUbvpo.mjs → copilotkit-Ck0RL8hh.mjs} +127 -147
- package/dist/copilotkit-Ck0RL8hh.mjs.map +1 -0
- package/dist/index.cjs +52 -53
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +8 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +47 -49
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +46 -48
- package/dist/index.umd.js.map +1 -1
- package/dist/v2/headless.d.cts +1 -1
- package/dist/v2/headless.d.mts +1 -1
- package/dist/v2/index.cjs +14 -2
- package/dist/v2/index.d.cts +2 -2
- package/dist/v2/index.d.mts +2 -2
- package/dist/v2/index.mjs +2 -2
- package/dist/v2/index.umd.js +15 -5
- package/dist/v2/index.umd.js.map +1 -1
- package/package.json +10 -9
- package/skills/react-core/SKILL.md +1 -1
- package/dist/copilotkit-CBCT7BlL.d.cts.map +0 -1
- package/dist/copilotkit-CmMYFfLV.cjs.map +0 -1
- package/dist/copilotkit-DMmUbvpo.mjs.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_copilotkit = require('./copilotkit-
|
|
4
|
+
const require_copilotkit = require('./copilotkit-8KSSmCH_.cjs');
|
|
5
5
|
let react = require("react");
|
|
6
6
|
react = require_copilotkit.__toESM(react);
|
|
7
7
|
let _copilotkit_core = require("@copilotkit/core");
|
|
8
8
|
let _ag_ui_client = require("@ag-ui/client");
|
|
9
9
|
let _copilotkit_shared = require("@copilotkit/shared");
|
|
10
10
|
let _copilotkit_runtime_client_gql = require("@copilotkit/runtime-client-gql");
|
|
11
|
+
let _copilotkit_react_core_v2_context = require("@copilotkit/react-core/v2/context");
|
|
11
12
|
|
|
12
13
|
//#region src/utils/suggestions-constants.ts
|
|
13
14
|
/**
|
|
@@ -37,7 +38,7 @@ function useLazyToolRenderer() {
|
|
|
37
38
|
//#endregion
|
|
38
39
|
//#region src/hooks/use-copilot-chat_internal.ts
|
|
39
40
|
function useCopilotChatInternal({ suggestions, onInProgress, onSubmitMessage, onStopGeneration, onReloadMessages } = {}) {
|
|
40
|
-
const { copilotkit } =
|
|
41
|
+
const { copilotkit } = (0, _copilotkit_react_core_v2_context.useCopilotKit)();
|
|
41
42
|
const { threadId, agentSession } = require_copilotkit.useCopilotContext();
|
|
42
43
|
const existingConfig = require_copilotkit.useCopilotChatConfiguration();
|
|
43
44
|
const [agentAvailable, setAgentAvailable] = (0, react.useState)(false);
|
|
@@ -615,7 +616,7 @@ function useFrontendTool(tool, dependencies) {
|
|
|
615
616
|
//#endregion
|
|
616
617
|
//#region src/hooks/use-render-tool-call.ts
|
|
617
618
|
function useRenderToolCall(tool, dependencies) {
|
|
618
|
-
const { copilotkit } =
|
|
619
|
+
const { copilotkit } = (0, _copilotkit_react_core_v2_context.useCopilotKit)();
|
|
619
620
|
const hasAddedRef = (0, react.useRef)(false);
|
|
620
621
|
(0, react.useEffect)(() => {
|
|
621
622
|
const { name, parameters, render } = tool;
|
|
@@ -1041,8 +1042,7 @@ function useMakeCopilotDocumentReadable(document, categories, dependencies = [])
|
|
|
1041
1042
|
//#region src/hooks/use-copilot-readable.ts
|
|
1042
1043
|
/**
|
|
1043
1044
|
* `useCopilotReadable` is a React hook that provides app-state and other information
|
|
1044
|
-
* to the Copilot.
|
|
1045
|
-
* application, passing these parent-child relationships to the Copilot.
|
|
1045
|
+
* to the Copilot.
|
|
1046
1046
|
*
|
|
1047
1047
|
* ## Usage
|
|
1048
1048
|
*
|
|
@@ -1065,75 +1065,74 @@ function useMakeCopilotDocumentReadable(document, categories, dependencies = [])
|
|
|
1065
1065
|
* }
|
|
1066
1066
|
* ```
|
|
1067
1067
|
*
|
|
1068
|
-
* ###
|
|
1068
|
+
* ### Custom Serialization
|
|
1069
1069
|
*
|
|
1070
|
-
*
|
|
1071
|
-
*
|
|
1070
|
+
* By default the value is serialized with `JSON.stringify`. Pass `convert` to
|
|
1071
|
+
* control the string the Copilot sees. It is called with the description and the
|
|
1072
|
+
* value, in that order:
|
|
1072
1073
|
*
|
|
1073
|
-
* ```tsx
|
|
1074
|
-
*
|
|
1074
|
+
* ```tsx
|
|
1075
|
+
* useCopilotReadable({
|
|
1076
|
+
* description: "The current user",
|
|
1077
|
+
* value: user,
|
|
1078
|
+
* convert: (description, value) => `${description}: ${value.firstName} ${value.lastName}`,
|
|
1079
|
+
* });
|
|
1080
|
+
* ```
|
|
1075
1081
|
*
|
|
1076
|
-
*
|
|
1077
|
-
* const { employeeName, workProfile, metadata } = props;
|
|
1082
|
+
* ### Conditional Usage
|
|
1078
1083
|
*
|
|
1079
|
-
*
|
|
1080
|
-
*
|
|
1081
|
-
*
|
|
1082
|
-
* value: employeeName
|
|
1083
|
-
* });
|
|
1084
|
+
* Toggle `available` to add or remove the context as your app state changes.
|
|
1085
|
+
* Switching to `"disabled"` removes the entry from the Copilot context; switching
|
|
1086
|
+
* back to `"enabled"` re-adds it.
|
|
1084
1087
|
*
|
|
1085
|
-
*
|
|
1086
|
-
*
|
|
1087
|
-
*
|
|
1088
|
-
*
|
|
1089
|
-
*
|
|
1090
|
-
*
|
|
1091
|
-
*
|
|
1088
|
+
* ```tsx
|
|
1089
|
+
* useCopilotReadable({
|
|
1090
|
+
* description: "The list of employees",
|
|
1091
|
+
* value: employees,
|
|
1092
|
+
* available: showEmployees ? "enabled" : "disabled",
|
|
1093
|
+
* });
|
|
1094
|
+
* ```
|
|
1092
1095
|
*
|
|
1093
|
-
*
|
|
1094
|
-
* description: "Employee metadata",
|
|
1095
|
-
* value: metadata.description(),
|
|
1096
|
-
* parentId: employeeContextId
|
|
1097
|
-
* });
|
|
1096
|
+
* ### Re-running on Custom Dependencies
|
|
1098
1097
|
*
|
|
1099
|
-
*
|
|
1100
|
-
*
|
|
1101
|
-
*
|
|
1102
|
-
*
|
|
1098
|
+
* The context is refreshed whenever `description`, `value`, `convert` or
|
|
1099
|
+
* `available` change. Pass a second argument to add your own dependencies:
|
|
1100
|
+
*
|
|
1101
|
+
* ```tsx
|
|
1102
|
+
* useCopilotReadable(
|
|
1103
|
+
* {
|
|
1104
|
+
* description: "The selected employee",
|
|
1105
|
+
* value: employee,
|
|
1106
|
+
* },
|
|
1107
|
+
* [departmentId],
|
|
1108
|
+
* );
|
|
1103
1109
|
* ```
|
|
1104
1110
|
*/
|
|
1105
1111
|
/**
|
|
1106
1112
|
* Adds the given information to the Copilot context to make it readable by Copilot.
|
|
1107
1113
|
*/
|
|
1108
|
-
function useCopilotReadable({ description, value, convert, available }, dependencies) {
|
|
1109
|
-
const { copilotkit } =
|
|
1114
|
+
function useCopilotReadable({ description, value, convert, available = "enabled" }, dependencies) {
|
|
1115
|
+
const { copilotkit } = (0, _copilotkit_react_core_v2_context.useCopilotKit)();
|
|
1110
1116
|
const ctxIdRef = (0, react.useRef)(void 0);
|
|
1111
1117
|
(0, react.useEffect)(() => {
|
|
1112
1118
|
if (!copilotkit) return;
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
description,
|
|
1116
|
-
value
|
|
1117
|
-
}) == JSON.stringify(ctxItem);
|
|
1118
|
-
});
|
|
1119
|
-
if (found) {
|
|
1120
|
-
ctxIdRef.current = found[0];
|
|
1121
|
-
if (available === "disabled") copilotkit.removeContext(ctxIdRef.current);
|
|
1122
|
-
return;
|
|
1123
|
-
}
|
|
1124
|
-
if (!found && available === "disabled") return;
|
|
1125
|
-
ctxIdRef.current = copilotkit.addContext({
|
|
1119
|
+
if (available === "disabled") return;
|
|
1120
|
+
const id = copilotkit.addContext({
|
|
1126
1121
|
description,
|
|
1127
|
-
value:
|
|
1122
|
+
value: convert ? convert(description, value) : JSON.stringify(value)
|
|
1128
1123
|
});
|
|
1124
|
+
ctxIdRef.current = id;
|
|
1129
1125
|
return () => {
|
|
1130
|
-
|
|
1131
|
-
|
|
1126
|
+
copilotkit.removeContext(id);
|
|
1127
|
+
if (ctxIdRef.current === id) ctxIdRef.current = void 0;
|
|
1132
1128
|
};
|
|
1133
1129
|
}, [
|
|
1130
|
+
copilotkit,
|
|
1134
1131
|
description,
|
|
1135
1132
|
value,
|
|
1136
|
-
convert
|
|
1133
|
+
convert,
|
|
1134
|
+
available,
|
|
1135
|
+
...dependencies || []
|
|
1137
1136
|
]);
|
|
1138
1137
|
return ctxIdRef.current;
|
|
1139
1138
|
}
|
|
@@ -1268,7 +1267,7 @@ function useAgentNodeName(agentName) {
|
|
|
1268
1267
|
*/
|
|
1269
1268
|
function useCoAgent(options) {
|
|
1270
1269
|
const { agent } = require_copilotkit.useAgent({ agentId: options.name });
|
|
1271
|
-
const { copilotkit } =
|
|
1270
|
+
const { copilotkit } = (0, _copilotkit_react_core_v2_context.useCopilotKit)();
|
|
1272
1271
|
const nodeName = useAgentNodeName(options.name);
|
|
1273
1272
|
const handleStateUpdate = (0, react.useCallback)((newState) => {
|
|
1274
1273
|
if (!agent) return;
|