@copilotkit/react-core 1.50.0-beta.7 → 1.50.0-beta.8

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/index.mjs CHANGED
@@ -5,7 +5,7 @@ import "./chunk-36KQV2NA.mjs";
5
5
  import "./chunk-LUGEI4YQ.mjs";
6
6
  import {
7
7
  CopilotTask
8
- } from "./chunk-QSNZUI5G.mjs";
8
+ } from "./chunk-Y2L7KDVW.mjs";
9
9
  import "./chunk-4CEQJ2X6.mjs";
10
10
  import "./chunk-A6NKSGH3.mjs";
11
11
  import {
@@ -52,7 +52,7 @@ import {
52
52
  } from "./chunk-ZVF5Q6IH.mjs";
53
53
  import {
54
54
  useCopilotReadable
55
- } from "./chunk-2CYJN455.mjs";
55
+ } from "./chunk-RQ6LWR6S.mjs";
56
56
  import {
57
57
  useCopilotRuntimeClient
58
58
  } from "./chunk-6ESSSQ7Q.mjs";
@@ -71,16 +71,16 @@ import "./chunk-SPCZTZCY.mjs";
71
71
  import {
72
72
  CopilotKit,
73
73
  defaultCopilotContextCategories
74
- } from "./chunk-WV57GREG.mjs";
74
+ } from "./chunk-ZU6ZBX4E.mjs";
75
+ import "./chunk-LHERIF3L.mjs";
76
+ import "./chunk-HE22TZMF.mjs";
77
+ import "./chunk-PMWUKW3Z.mjs";
78
+ import "./chunk-YCG6SNAU.mjs";
79
+ import "./chunk-PIF5KJYI.mjs";
75
80
  import "./chunk-CYDWEPFL.mjs";
76
81
  import {
77
82
  SUGGESTION_RETRY_CONFIG
78
83
  } from "./chunk-2IDV5OHF.mjs";
79
- import "./chunk-PMWUKW3Z.mjs";
80
- import "./chunk-YCG6SNAU.mjs";
81
- import "./chunk-PIF5KJYI.mjs";
82
- import "./chunk-LHERIF3L.mjs";
83
- import "./chunk-HE22TZMF.mjs";
84
84
  import {
85
85
  shouldShowDevConsole
86
86
  } from "./chunk-ICIK2BSB.mjs";
@@ -1,17 +1,17 @@
1
1
  import {
2
2
  CopilotTask
3
- } from "../chunk-QSNZUI5G.mjs";
3
+ } from "../chunk-Y2L7KDVW.mjs";
4
4
  import "../chunk-4CEQJ2X6.mjs";
5
5
  import "../chunk-JD7BAH7U.mjs";
6
6
  import "../chunk-SPCZTZCY.mjs";
7
- import "../chunk-WV57GREG.mjs";
8
- import "../chunk-CYDWEPFL.mjs";
9
- import "../chunk-2IDV5OHF.mjs";
7
+ import "../chunk-ZU6ZBX4E.mjs";
8
+ import "../chunk-LHERIF3L.mjs";
9
+ import "../chunk-HE22TZMF.mjs";
10
10
  import "../chunk-PMWUKW3Z.mjs";
11
11
  import "../chunk-YCG6SNAU.mjs";
12
12
  import "../chunk-PIF5KJYI.mjs";
13
- import "../chunk-LHERIF3L.mjs";
14
- import "../chunk-HE22TZMF.mjs";
13
+ import "../chunk-CYDWEPFL.mjs";
14
+ import "../chunk-2IDV5OHF.mjs";
15
15
  import "../chunk-ICIK2BSB.mjs";
16
16
  import "../chunk-RKTVJRK7.mjs";
17
17
  import "../chunk-PMAFHQ7P.mjs";
@@ -1,18 +1,18 @@
1
1
  import "../chunk-LUGEI4YQ.mjs";
2
2
  import {
3
3
  CopilotTask
4
- } from "../chunk-QSNZUI5G.mjs";
4
+ } from "../chunk-Y2L7KDVW.mjs";
5
5
  import "../chunk-4CEQJ2X6.mjs";
6
6
  import "../chunk-JD7BAH7U.mjs";
7
7
  import "../chunk-SPCZTZCY.mjs";
8
- import "../chunk-WV57GREG.mjs";
9
- import "../chunk-CYDWEPFL.mjs";
10
- import "../chunk-2IDV5OHF.mjs";
8
+ import "../chunk-ZU6ZBX4E.mjs";
9
+ import "../chunk-LHERIF3L.mjs";
10
+ import "../chunk-HE22TZMF.mjs";
11
11
  import "../chunk-PMWUKW3Z.mjs";
12
12
  import "../chunk-YCG6SNAU.mjs";
13
13
  import "../chunk-PIF5KJYI.mjs";
14
- import "../chunk-LHERIF3L.mjs";
15
- import "../chunk-HE22TZMF.mjs";
14
+ import "../chunk-CYDWEPFL.mjs";
15
+ import "../chunk-2IDV5OHF.mjs";
16
16
  import "../chunk-ICIK2BSB.mjs";
17
17
  import "../chunk-RKTVJRK7.mjs";
18
18
  import "../chunk-PMAFHQ7P.mjs";
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "publishConfig": {
10
10
  "access": "public"
11
11
  },
12
- "version": "1.50.0-beta.7",
12
+ "version": "1.50.0-beta.8",
13
13
  "sideEffects": [
14
14
  "**/*.css"
15
15
  ],
@@ -52,17 +52,17 @@
52
52
  "tsup": "^6.7.0",
53
53
  "typescript": "^5.2.3",
54
54
  "zod": ">=3.0.0",
55
- "eslint-config-custom": "1.4.6",
56
- "tsconfig": "1.4.6"
55
+ "tsconfig": "1.4.6",
56
+ "eslint-config-custom": "1.4.6"
57
57
  },
58
58
  "dependencies": {
59
- "@copilotkitnext/core": "0.0.25",
60
- "@copilotkitnext/react": "0.0.25",
59
+ "@copilotkitnext/core": "0.0.28",
60
+ "@copilotkitnext/react": "0.0.28",
61
61
  "@scarf/scarf": "^1.3.0",
62
62
  "react-markdown": "^8.0.7",
63
63
  "untruncate-json": "^0.0.1",
64
- "@copilotkit/runtime-client-gql": "1.50.0-beta.7",
65
- "@copilotkit/shared": "1.50.0-beta.7"
64
+ "@copilotkit/runtime-client-gql": "1.50.0-beta.8",
65
+ "@copilotkit/shared": "1.50.0-beta.8"
66
66
  },
67
67
  "keywords": [
68
68
  "copilotkit",
@@ -61,9 +61,10 @@
61
61
  * }
62
62
  * ```
63
63
  */
64
+ import { useCopilotKit } from "@copilotkitnext/react";
64
65
  import { useEffect, useRef } from "react";
65
- import { useCopilotContext } from "../context/copilot-context";
66
- import { useAgentContext } from "@copilotkitnext/react";
66
+
67
+ type DataType = object | number | string | boolean | null | undefined;
67
68
 
68
69
  /**
69
70
  * Options for the useCopilotReadable hook.
@@ -76,7 +77,7 @@ export interface UseCopilotReadableOptions {
76
77
  /**
77
78
  * The value to be added to the Copilot context. Object values are automatically stringified.
78
79
  */
79
- value: any;
80
+ value: DataType | Record<string, any> | DataType[];
80
81
  /**
81
82
  * The ID of the parent context, if any.
82
83
  */
@@ -96,23 +97,41 @@ export interface UseCopilotReadableOptions {
96
97
  * A custom conversion function to use to serialize the value to a string. If not provided, the value
97
98
  * will be serialized using `JSON.stringify`.
98
99
  */
99
- convert?: (description: string, value: any) => string;
100
- }
101
-
102
- function convertToJSON(description: string, value: any): string {
103
- return `${description}: ${typeof value === "string" ? value : JSON.stringify(value)}`;
100
+ convert?: (value: any) => string;
104
101
  }
105
102
 
106
103
  /**
107
104
  * Adds the given information to the Copilot context to make it readable by Copilot.
108
105
  */
109
106
  export function useCopilotReadable(
110
- { description, value }: UseCopilotReadableOptions,
107
+ { description, value, convert, available }: UseCopilotReadableOptions,
111
108
  dependencies?: any[],
112
- ): undefined {
113
- useAgentContext({
114
- description,
115
- value,
116
- });
117
- return;
109
+ ): string | undefined {
110
+ const { copilotkit } = useCopilotKit();
111
+ const ctxIdRef = useRef<string | undefined>(undefined);
112
+ useEffect(() => {
113
+ if (!copilotkit) return;
114
+
115
+ const found = Object.entries(copilotkit.context).find(([id, ctxItem]) => {
116
+ return JSON.stringify({ description, value }) == JSON.stringify(ctxItem);
117
+ });
118
+ if (found) {
119
+ ctxIdRef.current = found[0];
120
+ if (available === "disabled") copilotkit.removeContext(ctxIdRef.current);
121
+ return;
122
+ }
123
+ if (!found && available === "disabled") return;
124
+
125
+ ctxIdRef.current = copilotkit.addContext({
126
+ description,
127
+ value: (convert ?? JSON.stringify)(value),
128
+ });
129
+
130
+ return () => {
131
+ if (!ctxIdRef.current) return;
132
+ copilotkit.removeContext(ctxIdRef.current);
133
+ };
134
+ }, [description, value, convert]);
135
+
136
+ return ctxIdRef.current;
118
137
  }
@@ -1,14 +0,0 @@
1
- // src/hooks/use-copilot-readable.ts
2
- import { useAgentContext } from "@copilotkitnext/react";
3
- function useCopilotReadable({ description, value }, dependencies) {
4
- useAgentContext({
5
- description,
6
- value
7
- });
8
- return;
9
- }
10
-
11
- export {
12
- useCopilotReadable
13
- };
14
- //# sourceMappingURL=chunk-2CYJN455.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/hooks/use-copilot-readable.ts"],"sourcesContent":["/**\n * `useCopilotReadable` is a React hook that provides app-state and other information\n * to the Copilot. Optionally, the hook can also handle hierarchical state within your\n * application, passing these parent-child relationships to the Copilot.\n *\n * ## Usage\n *\n * ### Simple Usage\n *\n * In its most basic usage, useCopilotReadable accepts a single string argument\n * representing any piece of app state, making it available for the Copilot to use\n * as context when responding to user input.\n *\n * ```tsx\n * import { useCopilotReadable } from \"@copilotkit/react-core\";\n *\n * export function MyComponent() {\n * const [employees, setEmployees] = useState([]);\n *\n * useCopilotReadable({\n * description: \"The list of employees\",\n * value: employees,\n * });\n * }\n * ```\n *\n * ### Nested Components\n *\n * Optionally, you can maintain the hierarchical structure of information by passing\n * `parentId`. This allows you to use `useCopilotReadable` in nested components:\n *\n * ```tsx /employeeContextId/1 {17,23}\n * import { useCopilotReadable } from \"@copilotkit/react-core\";\n *\n * function Employee(props: EmployeeProps) {\n * const { employeeName, workProfile, metadata } = props;\n *\n * // propagate any information to copilot\n * const employeeContextId = useCopilotReadable({\n * description: \"Employee name\",\n * value: employeeName\n * });\n *\n * // Pass a parentID to maintain a hierarchical structure.\n * // Especially useful with child React components, list elements, etc.\n * useCopilotReadable({\n * description: \"Work profile\",\n * value: workProfile.description(),\n * parentId: employeeContextId\n * });\n *\n * useCopilotReadable({\n * description: \"Employee metadata\",\n * value: metadata.description(),\n * parentId: employeeContextId\n * });\n *\n * return (\n * // Render as usual...\n * );\n * }\n * ```\n */\nimport { useEffect, useRef } from \"react\";\nimport { useCopilotContext } from \"../context/copilot-context\";\nimport { useAgentContext } from \"@copilotkitnext/react\";\n\n/**\n * Options for the useCopilotReadable hook.\n */\nexport interface UseCopilotReadableOptions {\n /**\n * The description of the information to be added to the Copilot context.\n */\n description: string;\n /**\n * The value to be added to the Copilot context. Object values are automatically stringified.\n */\n value: any;\n /**\n * The ID of the parent context, if any.\n */\n parentId?: string;\n /**\n * An array of categories to control which context are visible where. Particularly useful\n * with CopilotTextarea (see `useMakeAutosuggestionFunction`)\n */\n categories?: string[];\n\n /**\n * Whether the context is available to the Copilot.\n */\n available?: \"enabled\" | \"disabled\";\n\n /**\n * A custom conversion function to use to serialize the value to a string. If not provided, the value\n * will be serialized using `JSON.stringify`.\n */\n convert?: (description: string, value: any) => string;\n}\n\nfunction convertToJSON(description: string, value: any): string {\n return `${description}: ${typeof value === \"string\" ? value : JSON.stringify(value)}`;\n}\n\n/**\n * Adds the given information to the Copilot context to make it readable by Copilot.\n */\nexport function useCopilotReadable(\n { description, value }: UseCopilotReadableOptions,\n dependencies?: any[],\n): undefined {\n useAgentContext({\n description,\n value,\n });\n return;\n}\n"],"mappings":";AAiEA,SAAS,uBAAuB;AA2CzB,SAAS,mBACd,EAAE,aAAa,MAAM,GACrB,cACW;AACX,kBAAgB;AAAA,IACd;AAAA,IACA;AAAA,EACF,CAAC;AACD;AACF;","names":[]}