@copilotkit/react-core 1.50.0-beta.6 → 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/CHANGELOG.md +17 -0
- package/dist/{chunk-PQPWQ6GH.mjs → chunk-BLDHD6Q2.mjs} +2 -2
- package/dist/{chunk-ZCV3A2FP.mjs → chunk-EKDPRKZT.mjs} +7 -9
- package/dist/chunk-EKDPRKZT.mjs.map +1 -0
- package/dist/{chunk-OX2QTNTD.mjs → chunk-KYY2WZSR.mjs} +2 -2
- package/dist/chunk-RQ6LWR6S.mjs +37 -0
- package/dist/chunk-RQ6LWR6S.mjs.map +1 -0
- package/dist/hooks/index.js +64 -43
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +4 -4
- package/dist/hooks/use-copilot-chat-headless_c.js +6 -8
- package/dist/hooks/use-copilot-chat-headless_c.js.map +1 -1
- package/dist/hooks/use-copilot-chat-headless_c.mjs +2 -2
- package/dist/hooks/use-copilot-chat.js +6 -8
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +2 -2
- package/dist/hooks/use-copilot-chat_internal.js +6 -8
- package/dist/hooks/use-copilot-chat_internal.js.map +1 -1
- package/dist/hooks/use-copilot-chat_internal.mjs +1 -1
- package/dist/hooks/use-copilot-readable.d.ts +4 -3
- package/dist/hooks/use-copilot-readable.js +29 -6
- package/dist/hooks/use-copilot-readable.js.map +1 -1
- package/dist/hooks/use-copilot-readable.mjs +1 -1
- package/dist/index.js +64 -43
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -4
- package/package.json +7 -7
- package/src/hooks/use-copilot-readable.ts +34 -15
- package/dist/chunk-2CYJN455.mjs +0 -14
- package/dist/chunk-2CYJN455.mjs.map +0 -1
- package/dist/chunk-ZCV3A2FP.mjs.map +0 -1
- /package/dist/{chunk-PQPWQ6GH.mjs.map → chunk-BLDHD6Q2.mjs.map} +0 -0
- /package/dist/{chunk-OX2QTNTD.mjs.map → chunk-KYY2WZSR.mjs.map} +0 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
type DataType = object | number | string | boolean | null | undefined;
|
|
1
2
|
/**
|
|
2
3
|
* Options for the useCopilotReadable hook.
|
|
3
4
|
*/
|
|
@@ -9,7 +10,7 @@ interface UseCopilotReadableOptions {
|
|
|
9
10
|
/**
|
|
10
11
|
* The value to be added to the Copilot context. Object values are automatically stringified.
|
|
11
12
|
*/
|
|
12
|
-
value: any;
|
|
13
|
+
value: DataType | Record<string, any> | DataType[];
|
|
13
14
|
/**
|
|
14
15
|
* The ID of the parent context, if any.
|
|
15
16
|
*/
|
|
@@ -27,11 +28,11 @@ interface UseCopilotReadableOptions {
|
|
|
27
28
|
* A custom conversion function to use to serialize the value to a string. If not provided, the value
|
|
28
29
|
* will be serialized using `JSON.stringify`.
|
|
29
30
|
*/
|
|
30
|
-
convert?: (
|
|
31
|
+
convert?: (value: any) => string;
|
|
31
32
|
}
|
|
32
33
|
/**
|
|
33
34
|
* Adds the given information to the Copilot context to make it readable by Copilot.
|
|
34
35
|
*/
|
|
35
|
-
declare function useCopilotReadable({ description, value }: UseCopilotReadableOptions, dependencies?: any[]): undefined;
|
|
36
|
+
declare function useCopilotReadable({ description, value, convert, available }: UseCopilotReadableOptions, dependencies?: any[]): string | undefined;
|
|
36
37
|
|
|
37
38
|
export { UseCopilotReadableOptions, useCopilotReadable };
|
|
@@ -24,12 +24,35 @@ __export(use_copilot_readable_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(use_copilot_readable_exports);
|
|
26
26
|
var import_react = require("@copilotkitnext/react");
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
var import_react2 = require("react");
|
|
28
|
+
function useCopilotReadable({ description, value, convert, available }, dependencies) {
|
|
29
|
+
const { copilotkit } = (0, import_react.useCopilotKit)();
|
|
30
|
+
const ctxIdRef = (0, import_react2.useRef)(void 0);
|
|
31
|
+
(0, import_react2.useEffect)(() => {
|
|
32
|
+
if (!copilotkit)
|
|
33
|
+
return;
|
|
34
|
+
const found = Object.entries(copilotkit.context).find(([id, ctxItem]) => {
|
|
35
|
+
return JSON.stringify({ description, value }) == JSON.stringify(ctxItem);
|
|
36
|
+
});
|
|
37
|
+
if (found) {
|
|
38
|
+
ctxIdRef.current = found[0];
|
|
39
|
+
if (available === "disabled")
|
|
40
|
+
copilotkit.removeContext(ctxIdRef.current);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (!found && available === "disabled")
|
|
44
|
+
return;
|
|
45
|
+
ctxIdRef.current = copilotkit.addContext({
|
|
46
|
+
description,
|
|
47
|
+
value: (convert != null ? convert : JSON.stringify)(value)
|
|
48
|
+
});
|
|
49
|
+
return () => {
|
|
50
|
+
if (!ctxIdRef.current)
|
|
51
|
+
return;
|
|
52
|
+
copilotkit.removeContext(ctxIdRef.current);
|
|
53
|
+
};
|
|
54
|
+
}, [description, value, convert]);
|
|
55
|
+
return ctxIdRef.current;
|
|
33
56
|
}
|
|
34
57
|
// Annotate the CommonJS export names for ESM import in node:
|
|
35
58
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
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 {
|
|
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 { useCopilotKit } from \"@copilotkitnext/react\";\nimport { useEffect, useRef } from \"react\";\n\ntype DataType = object | number | string | boolean | null | undefined;\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: DataType | Record<string, any> | DataType[];\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?: (value: any) => string;\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, convert, available }: UseCopilotReadableOptions,\n dependencies?: any[],\n): string | undefined {\n const { copilotkit } = useCopilotKit();\n const ctxIdRef = useRef<string | undefined>(undefined);\n useEffect(() => {\n if (!copilotkit) return;\n\n const found = Object.entries(copilotkit.context).find(([id, ctxItem]) => {\n return JSON.stringify({ description, value }) == JSON.stringify(ctxItem);\n });\n if (found) {\n ctxIdRef.current = found[0];\n if (available === \"disabled\") copilotkit.removeContext(ctxIdRef.current);\n return;\n }\n if (!found && available === \"disabled\") return;\n\n ctxIdRef.current = copilotkit.addContext({\n description,\n value: (convert ?? JSON.stringify)(value),\n });\n\n return () => {\n if (!ctxIdRef.current) return;\n copilotkit.removeContext(ctxIdRef.current);\n };\n }, [description, value, convert]);\n\n return ctxIdRef.current;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA+DA,mBAA8B;AAC9B,IAAAA,gBAAkC;AAyC3B,SAAS,mBACd,EAAE,aAAa,OAAO,SAAS,UAAU,GACzC,cACoB;AACpB,QAAM,EAAE,WAAW,QAAI,4BAAc;AACrC,QAAM,eAAW,sBAA2B,MAAS;AACrD,+BAAU,MAAM;AACd,QAAI,CAAC;AAAY;AAEjB,UAAM,QAAQ,OAAO,QAAQ,WAAW,OAAO,EAAE,KAAK,CAAC,CAAC,IAAI,OAAO,MAAM;AACvE,aAAO,KAAK,UAAU,EAAE,aAAa,MAAM,CAAC,KAAK,KAAK,UAAU,OAAO;AAAA,IACzE,CAAC;AACD,QAAI,OAAO;AACT,eAAS,UAAU,MAAM,CAAC;AAC1B,UAAI,cAAc;AAAY,mBAAW,cAAc,SAAS,OAAO;AACvE;AAAA,IACF;AACA,QAAI,CAAC,SAAS,cAAc;AAAY;AAExC,aAAS,UAAU,WAAW,WAAW;AAAA,MACvC;AAAA,MACA,QAAQ,4BAAW,KAAK,WAAW,KAAK;AAAA,IAC1C,CAAC;AAED,WAAO,MAAM;AACX,UAAI,CAAC,SAAS;AAAS;AACvB,iBAAW,cAAc,SAAS,OAAO;AAAA,IAC3C;AAAA,EACF,GAAG,CAAC,aAAa,OAAO,OAAO,CAAC;AAEhC,SAAO,SAAS;AAClB;","names":["import_react"]}
|
package/dist/index.js
CHANGED
|
@@ -3337,7 +3337,7 @@ function useConfigureChatSuggestions(config, dependencies = []) {
|
|
|
3337
3337
|
return result;
|
|
3338
3338
|
}
|
|
3339
3339
|
|
|
3340
|
-
// ../../node_modules/.pnpm/@ag-ui+core@0.0.42
|
|
3340
|
+
// ../../node_modules/.pnpm/@ag-ui+core@0.0.42/node_modules/@ag-ui/core/dist/index.mjs
|
|
3341
3341
|
var import_zod = require("zod");
|
|
3342
3342
|
var import_zod2 = require("zod");
|
|
3343
3343
|
var FunctionCallSchema = import_zod.z.object({
|
|
@@ -3880,16 +3880,15 @@ function useCopilotChatInternal({
|
|
|
3880
3880
|
}),
|
|
3881
3881
|
[latestSendMessageFunc]
|
|
3882
3882
|
);
|
|
3883
|
-
const latestSetMessages = useUpdatedRef(agent == null ? void 0 : agent.setMessages);
|
|
3884
3883
|
const latestSetMessagesFunc = (0, import_react27.useCallback)(
|
|
3885
3884
|
(messages) => {
|
|
3886
3885
|
var _a2, _b2;
|
|
3887
3886
|
if (messages.every((message) => message instanceof import_runtime_client_gql2.Message)) {
|
|
3888
|
-
return (_a2 =
|
|
3887
|
+
return (_a2 = agent == null ? void 0 : agent.setMessages) == null ? void 0 : _a2.call(agent, (0, import_runtime_client_gql2.gqlToAGUI)(messages));
|
|
3889
3888
|
}
|
|
3890
|
-
return (_b2 =
|
|
3889
|
+
return (_b2 = agent == null ? void 0 : agent.setMessages) == null ? void 0 : _b2.call(agent, messages);
|
|
3891
3890
|
},
|
|
3892
|
-
[
|
|
3891
|
+
[agent == null ? void 0 : agent.setMessages, agent]
|
|
3893
3892
|
);
|
|
3894
3893
|
const latestReload = useUpdatedRef(reload);
|
|
3895
3894
|
const latestReloadFunc = useAsyncCallback(
|
|
@@ -3898,11 +3897,10 @@ function useCopilotChatInternal({
|
|
|
3898
3897
|
}),
|
|
3899
3898
|
[latestReload]
|
|
3900
3899
|
);
|
|
3901
|
-
const latestStop = useUpdatedRef(agent == null ? void 0 : agent.abortRun);
|
|
3902
3900
|
const latestStopFunc = (0, import_react27.useCallback)(() => {
|
|
3903
3901
|
var _a2;
|
|
3904
|
-
return (_a2 =
|
|
3905
|
-
}, [
|
|
3902
|
+
return (_a2 = agent == null ? void 0 : agent.abortRun) == null ? void 0 : _a2.call(agent);
|
|
3903
|
+
}, [agent == null ? void 0 : agent.abortRun]);
|
|
3906
3904
|
const latestReset = useUpdatedRef(reset);
|
|
3907
3905
|
const latestResetFunc = (0, import_react27.useCallback)(() => {
|
|
3908
3906
|
return latestReset.current();
|
|
@@ -4422,22 +4420,45 @@ function useMakeCopilotDocumentReadable(document2, categories, dependencies = []
|
|
|
4422
4420
|
|
|
4423
4421
|
// src/hooks/use-copilot-readable.ts
|
|
4424
4422
|
var import_react39 = require("@copilotkitnext/react");
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
|
|
4428
|
-
|
|
4429
|
-
|
|
4430
|
-
|
|
4423
|
+
var import_react40 = require("react");
|
|
4424
|
+
function useCopilotReadable({ description, value, convert, available }, dependencies) {
|
|
4425
|
+
const { copilotkit } = (0, import_react39.useCopilotKit)();
|
|
4426
|
+
const ctxIdRef = (0, import_react40.useRef)(void 0);
|
|
4427
|
+
(0, import_react40.useEffect)(() => {
|
|
4428
|
+
if (!copilotkit)
|
|
4429
|
+
return;
|
|
4430
|
+
const found = Object.entries(copilotkit.context).find(([id, ctxItem]) => {
|
|
4431
|
+
return JSON.stringify({ description, value }) == JSON.stringify(ctxItem);
|
|
4432
|
+
});
|
|
4433
|
+
if (found) {
|
|
4434
|
+
ctxIdRef.current = found[0];
|
|
4435
|
+
if (available === "disabled")
|
|
4436
|
+
copilotkit.removeContext(ctxIdRef.current);
|
|
4437
|
+
return;
|
|
4438
|
+
}
|
|
4439
|
+
if (!found && available === "disabled")
|
|
4440
|
+
return;
|
|
4441
|
+
ctxIdRef.current = copilotkit.addContext({
|
|
4442
|
+
description,
|
|
4443
|
+
value: (convert != null ? convert : JSON.stringify)(value)
|
|
4444
|
+
});
|
|
4445
|
+
return () => {
|
|
4446
|
+
if (!ctxIdRef.current)
|
|
4447
|
+
return;
|
|
4448
|
+
copilotkit.removeContext(ctxIdRef.current);
|
|
4449
|
+
};
|
|
4450
|
+
}, [description, value, convert]);
|
|
4451
|
+
return ctxIdRef.current;
|
|
4431
4452
|
}
|
|
4432
4453
|
|
|
4433
4454
|
// src/hooks/use-coagent.ts
|
|
4434
|
-
var
|
|
4435
|
-
var
|
|
4455
|
+
var import_react41 = require("react");
|
|
4456
|
+
var import_react42 = require("@copilotkitnext/react");
|
|
4436
4457
|
function useCoAgent(options) {
|
|
4437
|
-
const { agent } = (0,
|
|
4438
|
-
const { copilotkit } = (0,
|
|
4458
|
+
const { agent } = (0, import_react42.useAgent)({ agentId: options.name });
|
|
4459
|
+
const { copilotkit } = (0, import_react42.useCopilotKit)();
|
|
4439
4460
|
const nodeName = useAgentNodeName(options.name);
|
|
4440
|
-
const handleStateUpdate = (0,
|
|
4461
|
+
const handleStateUpdate = (0, import_react41.useCallback)(
|
|
4441
4462
|
(newState) => {
|
|
4442
4463
|
if (!agent)
|
|
4443
4464
|
return;
|
|
@@ -4450,7 +4471,7 @@ function useCoAgent(options) {
|
|
|
4450
4471
|
},
|
|
4451
4472
|
[agent == null ? void 0 : agent.state, agent == null ? void 0 : agent.setState]
|
|
4452
4473
|
);
|
|
4453
|
-
(0,
|
|
4474
|
+
(0, import_react41.useEffect)(() => {
|
|
4454
4475
|
var _a;
|
|
4455
4476
|
if (!options.config && !options.configurable)
|
|
4456
4477
|
return;
|
|
@@ -4462,22 +4483,22 @@ function useCoAgent(options) {
|
|
|
4462
4483
|
}
|
|
4463
4484
|
copilotkit.setProperties(config);
|
|
4464
4485
|
}, [options.config, options.configurable]);
|
|
4465
|
-
const externalStateStr = (0,
|
|
4486
|
+
const externalStateStr = (0, import_react41.useMemo)(
|
|
4466
4487
|
() => isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0,
|
|
4467
4488
|
[isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0]
|
|
4468
4489
|
);
|
|
4469
|
-
(0,
|
|
4490
|
+
(0, import_react41.useEffect)(() => {
|
|
4470
4491
|
if ((agent == null ? void 0 : agent.state) && isExternalStateManagement(options) && JSON.stringify(options.state) !== JSON.stringify(agent.state)) {
|
|
4471
4492
|
handleStateUpdate(options.state);
|
|
4472
4493
|
}
|
|
4473
4494
|
}, [agent, externalStateStr, handleStateUpdate]);
|
|
4474
|
-
const hasStateValues = (0,
|
|
4495
|
+
const hasStateValues = (0, import_react41.useCallback)((value) => {
|
|
4475
4496
|
return Boolean(value && Object.keys(value).length);
|
|
4476
4497
|
}, []);
|
|
4477
|
-
const initialStateRef = (0,
|
|
4498
|
+
const initialStateRef = (0, import_react41.useRef)(
|
|
4478
4499
|
isExternalStateManagement(options) ? options.state : "initialState" in options ? options.initialState : void 0
|
|
4479
4500
|
);
|
|
4480
|
-
(0,
|
|
4501
|
+
(0, import_react41.useEffect)(() => {
|
|
4481
4502
|
if (isExternalStateManagement(options)) {
|
|
4482
4503
|
initialStateRef.current = options.state;
|
|
4483
4504
|
} else if ("initialState" in options) {
|
|
@@ -4486,7 +4507,7 @@ function useCoAgent(options) {
|
|
|
4486
4507
|
}, [
|
|
4487
4508
|
isExternalStateManagement(options) ? JSON.stringify(options.state) : "initialState" in options ? JSON.stringify(options.initialState) : void 0
|
|
4488
4509
|
]);
|
|
4489
|
-
(0,
|
|
4510
|
+
(0, import_react41.useEffect)(() => {
|
|
4490
4511
|
if (!agent)
|
|
4491
4512
|
return;
|
|
4492
4513
|
const subscriber = {
|
|
@@ -4514,7 +4535,7 @@ function useCoAgent(options) {
|
|
|
4514
4535
|
subscription.unsubscribe();
|
|
4515
4536
|
};
|
|
4516
4537
|
}, [agent, handleStateUpdate, hasStateValues]);
|
|
4517
|
-
return (0,
|
|
4538
|
+
return (0, import_react41.useMemo)(() => {
|
|
4518
4539
|
var _a, _b, _c;
|
|
4519
4540
|
if (!agent) {
|
|
4520
4541
|
const noop = () => {
|
|
@@ -4570,12 +4591,12 @@ var isExternalStateManagement = (options) => {
|
|
|
4570
4591
|
|
|
4571
4592
|
// src/hooks/use-copilot-runtime-client.ts
|
|
4572
4593
|
var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
|
|
4573
|
-
var
|
|
4594
|
+
var import_react43 = require("react");
|
|
4574
4595
|
var import_shared22 = require("@copilotkit/shared");
|
|
4575
4596
|
var useCopilotRuntimeClient = (options) => {
|
|
4576
4597
|
const { setBannerError } = useToast();
|
|
4577
4598
|
const _a = options, { showDevConsole, onError } = _a, runtimeOptions = __objRest(_a, ["showDevConsole", "onError"]);
|
|
4578
|
-
const lastStructuredErrorRef = (0,
|
|
4599
|
+
const lastStructuredErrorRef = (0, import_react43.useRef)(null);
|
|
4579
4600
|
const traceUIError = (error, originalError) => __async(void 0, null, function* () {
|
|
4580
4601
|
try {
|
|
4581
4602
|
const errorEvent = {
|
|
@@ -4601,7 +4622,7 @@ var useCopilotRuntimeClient = (options) => {
|
|
|
4601
4622
|
console.error("Error in onError handler:", error2);
|
|
4602
4623
|
}
|
|
4603
4624
|
});
|
|
4604
|
-
const runtimeClient = (0,
|
|
4625
|
+
const runtimeClient = (0, import_react43.useMemo)(() => {
|
|
4605
4626
|
return new import_runtime_client_gql3.CopilotRuntimeClient(__spreadProps(__spreadValues({}, runtimeOptions), {
|
|
4606
4627
|
handleGQLErrors: (error) => {
|
|
4607
4628
|
var _a2;
|
|
@@ -4680,28 +4701,28 @@ function createStructuredError(gqlError) {
|
|
|
4680
4701
|
}
|
|
4681
4702
|
|
|
4682
4703
|
// src/hooks/use-copilot-authenticated-action.ts
|
|
4683
|
-
var
|
|
4684
|
-
var
|
|
4704
|
+
var import_react44 = require("react");
|
|
4705
|
+
var import_react45 = __toESM(require("react"));
|
|
4685
4706
|
function useCopilotAuthenticatedAction_c(action, dependencies) {
|
|
4686
4707
|
const { authConfig_c, authStates_c, setAuthStates_c } = useCopilotContext();
|
|
4687
|
-
const pendingActionRef = (0,
|
|
4688
|
-
const executeAction = (0,
|
|
4708
|
+
const pendingActionRef = (0, import_react44.useRef)(null);
|
|
4709
|
+
const executeAction = (0, import_react44.useCallback)(
|
|
4689
4710
|
(props) => {
|
|
4690
4711
|
if (typeof action.render === "function") {
|
|
4691
4712
|
return action.render(props);
|
|
4692
4713
|
}
|
|
4693
|
-
return action.render ||
|
|
4714
|
+
return action.render || import_react45.default.createElement(import_react44.Fragment);
|
|
4694
4715
|
},
|
|
4695
4716
|
[action]
|
|
4696
4717
|
);
|
|
4697
|
-
const wrappedRender = (0,
|
|
4718
|
+
const wrappedRender = (0, import_react44.useCallback)(
|
|
4698
4719
|
(props) => {
|
|
4699
4720
|
const isAuthenticated = Object.values(authStates_c || {}).some(
|
|
4700
4721
|
(state) => state.status === "authenticated"
|
|
4701
4722
|
);
|
|
4702
4723
|
if (!isAuthenticated) {
|
|
4703
4724
|
pendingActionRef.current = props;
|
|
4704
|
-
return (authConfig_c == null ? void 0 : authConfig_c.SignInComponent) ?
|
|
4725
|
+
return (authConfig_c == null ? void 0 : authConfig_c.SignInComponent) ? import_react45.default.createElement(authConfig_c.SignInComponent, {
|
|
4705
4726
|
onSignInComplete: (authState) => {
|
|
4706
4727
|
setAuthStates_c == null ? void 0 : setAuthStates_c((prev) => __spreadProps(__spreadValues({}, prev), { [action.name]: authState }));
|
|
4707
4728
|
if (pendingActionRef.current) {
|
|
@@ -4709,7 +4730,7 @@ function useCopilotAuthenticatedAction_c(action, dependencies) {
|
|
|
4709
4730
|
pendingActionRef.current = null;
|
|
4710
4731
|
}
|
|
4711
4732
|
}
|
|
4712
|
-
}) :
|
|
4733
|
+
}) : import_react45.default.createElement(import_react44.Fragment);
|
|
4713
4734
|
}
|
|
4714
4735
|
return executeAction(props);
|
|
4715
4736
|
},
|
|
@@ -4724,13 +4745,13 @@ function useCopilotAuthenticatedAction_c(action, dependencies) {
|
|
|
4724
4745
|
}
|
|
4725
4746
|
|
|
4726
4747
|
// src/hooks/use-langgraph-interrupt.ts
|
|
4727
|
-
var
|
|
4748
|
+
var import_react46 = require("react");
|
|
4728
4749
|
var import_shared23 = require("@copilotkit/shared");
|
|
4729
4750
|
function useLangGraphInterrupt(action, dependencies) {
|
|
4730
|
-
const { setInterruptAction, removeInterruptAction, interruptActions, threadId } = (0,
|
|
4751
|
+
const { setInterruptAction, removeInterruptAction, interruptActions, threadId } = (0, import_react46.useContext)(CopilotContext);
|
|
4731
4752
|
const { addToast } = useToast();
|
|
4732
4753
|
const actionId = (0, import_shared23.dataToUUID)(action, "lgAction");
|
|
4733
|
-
(0,
|
|
4754
|
+
(0, import_react46.useEffect)(() => {
|
|
4734
4755
|
if (!action)
|
|
4735
4756
|
return;
|
|
4736
4757
|
setInterruptAction(__spreadProps(__spreadValues({}, action), { id: actionId }));
|
|
@@ -4741,10 +4762,10 @@ function useLangGraphInterrupt(action, dependencies) {
|
|
|
4741
4762
|
}
|
|
4742
4763
|
|
|
4743
4764
|
// src/hooks/use-copilot-additional-instructions.ts
|
|
4744
|
-
var
|
|
4765
|
+
var import_react47 = require("react");
|
|
4745
4766
|
function useCopilotAdditionalInstructions({ instructions, available = "enabled" }, dependencies) {
|
|
4746
4767
|
const { setAdditionalInstructions } = useCopilotContext();
|
|
4747
|
-
(0,
|
|
4768
|
+
(0, import_react47.useEffect)(() => {
|
|
4748
4769
|
if (available === "disabled")
|
|
4749
4770
|
return;
|
|
4750
4771
|
setAdditionalInstructions((prevInstructions) => [...prevInstructions || [], instructions]);
|