@copilotkit/react-core 1.50.0-beta.0 → 1.50.0-beta.10
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 +93 -0
- package/dist/{chunk-UJBV5GAG.mjs → chunk-3775VM7Y.mjs} +32 -65
- package/dist/chunk-3775VM7Y.mjs.map +1 -0
- package/dist/{chunk-3GURHDG7.mjs → chunk-4HRUQH6U.mjs} +3 -3
- package/dist/{chunk-7BYHZLPL.mjs → chunk-4RRMC7L2.mjs} +4 -4
- package/dist/chunk-4RRMC7L2.mjs.map +1 -0
- package/dist/{chunk-D3QSYDJR.mjs → chunk-7IBF6RBW.mjs} +2 -2
- package/dist/{chunk-GMI4KO4X.mjs → chunk-7SHWECGN.mjs} +2 -2
- package/dist/{chunk-OVYFRPSN.mjs → chunk-ABWT4DRT.mjs} +2 -2
- package/dist/{chunk-WVLHXIFP.mjs → chunk-AFNWX62Q.mjs} +2 -2
- package/dist/{chunk-WVLHXIFP.mjs.map → chunk-AFNWX62Q.mjs.map} +1 -1
- package/dist/{chunk-JRT5BJF3.mjs → chunk-B5ELMVT7.mjs} +2 -2
- package/dist/{chunk-TXI72QHK.mjs → chunk-EG56H77V.mjs} +2 -2
- package/dist/{chunk-DCHSCK62.mjs → chunk-FYMZKPOL.mjs} +36 -42
- package/dist/chunk-FYMZKPOL.mjs.map +1 -0
- package/dist/{chunk-FBD24VEH.mjs → chunk-HE22TZMF.mjs} +2 -2
- package/dist/{chunk-FBD24VEH.mjs.map → chunk-HE22TZMF.mjs.map} +1 -1
- package/dist/chunk-I76HKHPJ.mjs +32 -0
- package/dist/chunk-I76HKHPJ.mjs.map +1 -0
- package/dist/{chunk-LHKZJ2ND.mjs → chunk-PMWUKW3Z.mjs} +3 -3
- package/dist/{chunk-NROJOTQP.mjs → chunk-QNUAXSDP.mjs} +9 -6
- package/dist/chunk-QNUAXSDP.mjs.map +1 -0
- package/dist/{chunk-NG26QEGF.mjs → chunk-T2VBHAAP.mjs} +9 -3
- package/dist/chunk-T2VBHAAP.mjs.map +1 -0
- package/dist/{chunk-QU6NONOD.mjs → chunk-U2ZRVVKT.mjs} +2 -2
- package/dist/{chunk-R4MR43UQ.mjs → chunk-VV56AVPB.mjs} +33 -9
- package/dist/chunk-VV56AVPB.mjs.map +1 -0
- package/dist/{chunk-5X5DJRQQ.mjs → chunk-WF65O6HX.mjs} +2 -7
- package/dist/chunk-WF65O6HX.mjs.map +1 -0
- package/dist/chunk-XDFVCQD3.mjs +27 -0
- package/dist/chunk-XDFVCQD3.mjs.map +1 -0
- package/dist/{chunk-WMJVBMUX.mjs → chunk-YCG6SNAU.mjs} +2 -2
- package/dist/{chunk-3R423LZT.mjs → chunk-YJGPIN3R.mjs} +3 -3
- package/dist/{chunk-BR5YEYZJ.mjs → chunk-YTQHRJUA.mjs} +2 -2
- package/dist/chunk-Z6JV2LRY.mjs +37 -0
- package/dist/chunk-Z6JV2LRY.mjs.map +1 -0
- package/dist/{chunk-24SCZAB4.mjs → chunk-ZYTXB6HH.mjs} +22 -14
- package/dist/chunk-ZYTXB6HH.mjs.map +1 -0
- package/dist/components/CopilotListeners.js +13 -146
- package/dist/components/CopilotListeners.js.map +1 -1
- package/dist/components/CopilotListeners.mjs +1 -6
- package/dist/components/copilot-provider/copilot-messages.js +1 -1
- package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
- package/dist/components/copilot-provider/copilot-messages.mjs +2 -2
- package/dist/components/copilot-provider/copilotkit-props.d.ts +1 -1
- package/dist/components/copilot-provider/copilotkit.d.ts +1 -1
- package/dist/components/copilot-provider/copilotkit.js +35 -40
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +9 -9
- package/dist/components/copilot-provider/index.d.ts +1 -1
- package/dist/components/copilot-provider/index.js +35 -40
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +9 -9
- package/dist/components/dev-console/console-trigger.js +1 -1
- package/dist/components/dev-console/console-trigger.js.map +1 -1
- package/dist/components/dev-console/console-trigger.mjs +3 -3
- package/dist/components/dev-console/developer-console-modal.js +1 -1
- package/dist/components/dev-console/developer-console-modal.js.map +1 -1
- package/dist/components/dev-console/developer-console-modal.mjs +2 -2
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.js +35 -40
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +9 -9
- package/dist/context/copilot-context.d.ts +1 -1
- package/dist/context/copilot-context.js +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 +1 -1
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +1 -1
- package/dist/{copilot-context-1cd70a3f.d.ts → copilot-context-ec77e921.d.ts} +3 -3
- package/dist/hooks/index.d.ts +2 -2
- package/dist/hooks/index.js +254 -219
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +24 -23
- package/dist/hooks/use-agent-nodename.d.ts +3 -0
- package/dist/hooks/use-agent-nodename.js +56 -0
- package/dist/hooks/use-agent-nodename.js.map +1 -0
- package/dist/hooks/use-agent-nodename.mjs +8 -0
- package/dist/hooks/use-coagent-state-render-bridge.js +8 -5
- package/dist/hooks/use-coagent-state-render-bridge.js.map +1 -1
- package/dist/hooks/use-coagent-state-render-bridge.mjs +2 -2
- package/dist/hooks/use-coagent-state-render.js +1 -1
- 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 +58 -21
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +2 -1
- package/dist/hooks/use-copilot-action.js +5 -1
- package/dist/hooks/use-copilot-action.js.map +1 -1
- package/dist/hooks/use-copilot-action.mjs +2 -2
- package/dist/hooks/use-copilot-additional-instructions.js +1 -1
- package/dist/hooks/use-copilot-additional-instructions.js.map +1 -1
- package/dist/hooks/use-copilot-additional-instructions.mjs +2 -2
- package/dist/hooks/use-copilot-authenticated-action.js +6 -2
- package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
- package/dist/hooks/use-copilot-authenticated-action.mjs +4 -4
- package/dist/hooks/use-copilot-chat-headless_c.js +128 -140
- package/dist/hooks/use-copilot-chat-headless_c.js.map +1 -1
- package/dist/hooks/use-copilot-chat-headless_c.mjs +6 -6
- package/dist/hooks/{use-configure-chat-suggestions.d.ts → use-copilot-chat-suggestions.d.ts} +2 -3
- package/dist/hooks/use-copilot-chat-suggestions.js +60 -0
- package/dist/hooks/use-copilot-chat-suggestions.js.map +1 -0
- package/dist/hooks/use-copilot-chat-suggestions.mjs +8 -0
- package/dist/hooks/use-copilot-chat-suggestions.mjs.map +1 -0
- package/dist/hooks/use-copilot-chat.js +126 -138
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +6 -6
- package/dist/hooks/use-copilot-chat_internal.d.ts +18 -1
- package/dist/hooks/use-copilot-chat_internal.js +126 -138
- package/dist/hooks/use-copilot-chat_internal.js.map +1 -1
- package/dist/hooks/use-copilot-chat_internal.mjs +5 -5
- package/dist/hooks/use-copilot-readable.d.ts +1 -1
- package/dist/hooks/use-copilot-readable.js +29 -5
- package/dist/hooks/use-copilot-readable.js.map +1 -1
- package/dist/hooks/use-copilot-readable.mjs +1 -1
- package/dist/hooks/use-default-tool.js +5 -1
- package/dist/hooks/use-default-tool.js.map +1 -1
- package/dist/hooks/use-default-tool.mjs +3 -3
- package/dist/hooks/use-frontend-tool.js +5 -1
- package/dist/hooks/use-frontend-tool.js.map +1 -1
- package/dist/hooks/use-frontend-tool.mjs +1 -1
- package/dist/hooks/use-langgraph-interrupt-render.js +77 -13
- package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt-render.mjs +3 -2
- package/dist/hooks/use-langgraph-interrupt.d.ts +1 -1
- package/dist/hooks/use-langgraph-interrupt.js +3 -3
- package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt.mjs +2 -2
- package/dist/hooks/use-make-copilot-document-readable.js +1 -1
- 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 +273 -246
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +34 -33
- package/dist/lib/copilot-task.d.ts +1 -1
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +10 -10
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +10 -10
- package/dist/types/index.d.ts +1 -1
- package/dist/types/interrupt-action.d.ts +1 -1
- package/dist/types/interrupt-action.js.map +1 -1
- package/dist/utils/index.mjs +3 -3
- package/dist/v2/index.css +4 -0
- package/dist/v2/index.css.map +1 -0
- package/dist/v2/index.js.map +1 -1
- package/dist/v2/index.mjs +2 -0
- package/dist/v2/index.mjs.map +1 -1
- package/jest.config.js +12 -0
- package/package.json +27 -24
- package/src/components/CopilotListeners.tsx +1 -2
- package/src/components/copilot-provider/copilot-messages.tsx +0 -41
- package/src/components/copilot-provider/copilotkit.tsx +31 -31
- package/src/context/copilot-context.tsx +2 -2
- package/src/hooks/__tests__/use-coagent-config.test.ts +189 -129
- package/src/hooks/index.ts +2 -2
- package/src/hooks/use-agent-nodename.ts +30 -0
- package/src/hooks/use-coagent-state-render-bridge.tsx +22 -22
- package/src/hooks/use-coagent.ts +22 -13
- package/src/hooks/use-copilot-chat-suggestions.tsx +124 -0
- package/src/hooks/use-copilot-chat_internal.ts +78 -78
- package/src/hooks/use-copilot-readable.ts +30 -12
- package/src/hooks/use-frontend-tool.ts +10 -2
- package/src/hooks/use-langgraph-interrupt-render.ts +25 -7
- package/src/hooks/use-langgraph-interrupt.ts +2 -3
- package/src/types/interrupt-action.ts +2 -5
- package/src/v2/index.ts +2 -0
- package/tsup.config.ts +1 -1
- package/dist/chunk-24SCZAB4.mjs.map +0 -1
- package/dist/chunk-5X5DJRQQ.mjs.map +0 -1
- package/dist/chunk-7BYHZLPL.mjs.map +0 -1
- package/dist/chunk-CB7CRBDG.mjs +0 -48
- package/dist/chunk-CB7CRBDG.mjs.map +0 -1
- package/dist/chunk-DCHSCK62.mjs.map +0 -1
- package/dist/chunk-IUSKVYUI.mjs +0 -13
- package/dist/chunk-IUSKVYUI.mjs.map +0 -1
- package/dist/chunk-NG26QEGF.mjs.map +0 -1
- package/dist/chunk-NROJOTQP.mjs.map +0 -1
- package/dist/chunk-R4MR43UQ.mjs.map +0 -1
- package/dist/chunk-UJBV5GAG.mjs.map +0 -1
- package/dist/hooks/use-configure-chat-suggestions.js +0 -210
- package/dist/hooks/use-configure-chat-suggestions.js.map +0 -1
- package/dist/hooks/use-configure-chat-suggestions.mjs +0 -13
- package/src/hooks/use-configure-chat-suggestions.tsx +0 -85
- /package/dist/{chunk-3GURHDG7.mjs.map → chunk-4HRUQH6U.mjs.map} +0 -0
- /package/dist/{chunk-D3QSYDJR.mjs.map → chunk-7IBF6RBW.mjs.map} +0 -0
- /package/dist/{chunk-GMI4KO4X.mjs.map → chunk-7SHWECGN.mjs.map} +0 -0
- /package/dist/{chunk-OVYFRPSN.mjs.map → chunk-ABWT4DRT.mjs.map} +0 -0
- /package/dist/{chunk-JRT5BJF3.mjs.map → chunk-B5ELMVT7.mjs.map} +0 -0
- /package/dist/{chunk-TXI72QHK.mjs.map → chunk-EG56H77V.mjs.map} +0 -0
- /package/dist/{chunk-LHKZJ2ND.mjs.map → chunk-PMWUKW3Z.mjs.map} +0 -0
- /package/dist/{chunk-QU6NONOD.mjs.map → chunk-U2ZRVVKT.mjs.map} +0 -0
- /package/dist/{chunk-WMJVBMUX.mjs.map → chunk-YCG6SNAU.mjs.map} +0 -0
- /package/dist/{chunk-3R423LZT.mjs.map → chunk-YJGPIN3R.mjs.map} +0 -0
- /package/dist/{chunk-BR5YEYZJ.mjs.map → chunk-YTQHRJUA.mjs.map} +0 -0
- /package/dist/hooks/{use-configure-chat-suggestions.mjs.map → use-agent-nodename.mjs.map} +0 -0
- /package/src/v2/{styles.css → index.css} +0 -0
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
2
|
useCopilotChatHeadless_c
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-YJGPIN3R.mjs";
|
|
4
4
|
import {
|
|
5
5
|
defaultSystemMessage
|
|
6
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-3775VM7Y.mjs";
|
|
7
7
|
import "../chunk-ZVF5Q6IH.mjs";
|
|
8
|
-
import "../chunk-
|
|
9
|
-
import "../chunk-
|
|
8
|
+
import "../chunk-VV56AVPB.mjs";
|
|
9
|
+
import "../chunk-I76HKHPJ.mjs";
|
|
10
10
|
import "../chunk-6PUNP7CD.mjs";
|
|
11
11
|
import "../chunk-O7ARI5CV.mjs";
|
|
12
|
-
import "../chunk-
|
|
12
|
+
import "../chunk-QNUAXSDP.mjs";
|
|
13
13
|
import "../chunk-NB2FKV2V.mjs";
|
|
14
14
|
import "../chunk-F555TVE4.mjs";
|
|
15
15
|
import "../chunk-EFL5OBKN.mjs";
|
|
16
16
|
import "../chunk-FDOMAPJY.mjs";
|
|
17
|
-
import "../chunk-
|
|
17
|
+
import "../chunk-AFNWX62Q.mjs";
|
|
18
18
|
import "../chunk-DMLQZG75.mjs";
|
|
19
19
|
import "../chunk-SKC7AJIV.mjs";
|
|
20
20
|
export {
|
package/dist/hooks/{use-configure-chat-suggestions.d.ts → use-copilot-chat-suggestions.d.ts}
RENAMED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { useSuggestions } from '@copilotkitnext/react';
|
|
2
1
|
import { StaticSuggestionsConfig, Suggestion } from '@copilotkitnext/core';
|
|
3
2
|
|
|
4
3
|
type StaticSuggestionInput = Omit<Suggestion, "isLoading"> & Partial<Pick<Suggestion, "isLoading">>;
|
|
@@ -31,6 +30,6 @@ type DynamicSuggestionsConfigInput = {
|
|
|
31
30
|
className?: string;
|
|
32
31
|
};
|
|
33
32
|
type UseCopilotChatSuggestionsConfiguration = DynamicSuggestionsConfigInput | StaticSuggestionsConfigInput;
|
|
34
|
-
declare function
|
|
33
|
+
declare function useCopilotChatSuggestions(config: UseCopilotChatSuggestionsConfiguration, dependencies?: any[]): void;
|
|
35
34
|
|
|
36
|
-
export { UseCopilotChatSuggestionsConfiguration,
|
|
35
|
+
export { UseCopilotChatSuggestionsConfiguration, useCopilotChatSuggestions };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
+
var __spreadValues = (a, b) => {
|
|
12
|
+
for (var prop in b || (b = {}))
|
|
13
|
+
if (__hasOwnProp.call(b, prop))
|
|
14
|
+
__defNormalProp(a, prop, b[prop]);
|
|
15
|
+
if (__getOwnPropSymbols)
|
|
16
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
17
|
+
if (__propIsEnum.call(b, prop))
|
|
18
|
+
__defNormalProp(a, prop, b[prop]);
|
|
19
|
+
}
|
|
20
|
+
return a;
|
|
21
|
+
};
|
|
22
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
23
|
+
var __export = (target, all) => {
|
|
24
|
+
for (var name in all)
|
|
25
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
26
|
+
};
|
|
27
|
+
var __copyProps = (to, from, except, desc) => {
|
|
28
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
29
|
+
for (let key of __getOwnPropNames(from))
|
|
30
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
31
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
32
|
+
}
|
|
33
|
+
return to;
|
|
34
|
+
};
|
|
35
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
36
|
+
|
|
37
|
+
// src/hooks/use-copilot-chat-suggestions.tsx
|
|
38
|
+
var use_copilot_chat_suggestions_exports = {};
|
|
39
|
+
__export(use_copilot_chat_suggestions_exports, {
|
|
40
|
+
useCopilotChatSuggestions: () => useCopilotChatSuggestions
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(use_copilot_chat_suggestions_exports);
|
|
43
|
+
var import_react = require("@copilotkitnext/react");
|
|
44
|
+
function useCopilotChatSuggestions(config, dependencies = []) {
|
|
45
|
+
var _a, _b;
|
|
46
|
+
const existingConfig = (0, import_react.useCopilotChatConfiguration)();
|
|
47
|
+
const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
|
|
48
|
+
const available = (_b = config.available === "enabled" ? "always" : config.available) != null ? _b : "before-first-message";
|
|
49
|
+
const finalSuggestionConfig = __spreadProps(__spreadValues({}, config), {
|
|
50
|
+
available,
|
|
51
|
+
consumerAgentId: resolvedAgentId
|
|
52
|
+
// Use chatConfig.agentId here
|
|
53
|
+
});
|
|
54
|
+
(0, import_react.useConfigureSuggestions)(finalSuggestionConfig, dependencies);
|
|
55
|
+
}
|
|
56
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
57
|
+
0 && (module.exports = {
|
|
58
|
+
useCopilotChatSuggestions
|
|
59
|
+
});
|
|
60
|
+
//# sourceMappingURL=use-copilot-chat-suggestions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/use-copilot-chat-suggestions.tsx"],"sourcesContent":["/**\n * <Callout type=\"warning\">\n * useCopilotChatSuggestions is experimental. The interface is not final and\n * can change without notice.\n * </Callout>\n *\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 * <br/>\n * <img src=\"https://cdn.copilotkit.ai/docs/copilotkit/images/use-copilot-chat-suggestions/use-copilot-chat-suggestions.gif\" width=\"500\" />\n *\n * ## Usage\n *\n * ### Install Dependencies\n *\n * This component is part of the [@copilotkit/react-ui](https://npmjs.com/package/@copilotkit/react-ui) package.\n *\n * ```shell npm2yarn \\\"@copilotkit/react-ui\"\\\n * npm install @copilotkit/react-core @copilotkit/react-ui\n * ```\n *\n * ### Simple Usage\n *\n * ```tsx\n * import { useCopilotChatSuggestions } from \"@copilotkit/react-ui\";\n *\n * export function MyComponent() {\n * const [employees, setEmployees] = useState([]);\n *\n * useCopilotChatSuggestions({\n * instructions: `The following employees are on duty: ${JSON.stringify(employees)}`,\n * });\n * }\n * ```\n *\n * ### Dependency Management\n *\n * ```tsx\n * import { useCopilotChatSuggestions } from \"@copilotkit/react-ui\";\n *\n * export function MyComponent() {\n * useCopilotChatSuggestions(\n * {\n * instructions: \"Suggest the most relevant next actions.\",\n * },\n * [appState],\n * );\n * }\n * ```\n *\n * In the example above, the suggestions are generated based on the given instructions.\n * The hook monitors `appState`, and updates suggestions accordingly whenever it changes.\n *\n * ### Behavior and Lifecycle\n *\n * The hook registers the configuration with the chat context upon component mount and\n * removes it on unmount, ensuring a clean and efficient lifecycle management.\n */\nimport {\n useConfigureSuggestions,\n useCopilotChatConfiguration,\n useCopilotKit,\n useSuggestions,\n} from \"@copilotkitnext/react\";\nimport { useEffect } from \"react\";\nimport { StaticSuggestionsConfig, Suggestion } from \"@copilotkitnext/core\";\n\ntype StaticSuggestionInput = Omit<Suggestion, \"isLoading\"> & Partial<Pick<Suggestion, \"isLoading\">>;\n\ntype StaticSuggestionsConfigInput = Omit<StaticSuggestionsConfig, \"suggestions\"> & {\n suggestions: StaticSuggestionInput[];\n};\n\ntype DynamicSuggestionsConfigInput = {\n /**\n * A prompt or instructions for the GPT to generate suggestions.\n */\n instructions: string;\n /**\n * The minimum number of suggestions to generate. Defaults to `1`.\n * @default 1\n */\n minSuggestions?: number;\n /**\n * The maximum number of suggestions to generate. Defaults to `3`.\n * @default 1\n */\n maxSuggestions?: number;\n\n /**\n * Whether the suggestions are available. Defaults to `enabled`.\n * @default enabled\n */\n available?: \"enabled\" | \"disabled\" | \"always\" | \"before-first-message\" | \"after-first-message\";\n\n /**\n * An optional class name to apply to the suggestions.\n */\n className?: string;\n};\n\nexport type UseCopilotChatSuggestionsConfiguration =\n | DynamicSuggestionsConfigInput\n | StaticSuggestionsConfigInput;\n\nexport function useCopilotChatSuggestions(\n config: UseCopilotChatSuggestionsConfiguration,\n dependencies: any[] = [],\n) {\n const existingConfig = useCopilotChatConfiguration();\n const resolvedAgentId = existingConfig?.agentId ?? \"default\";\n\n const available =\n (config.available === \"enabled\" ? \"always\" : config.available) ?? \"before-first-message\";\n\n const finalSuggestionConfig = {\n ...config,\n available,\n consumerAgentId: resolvedAgentId, // Use chatConfig.agentId here\n };\n useConfigureSuggestions(finalSuggestionConfig, dependencies);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA4DA,mBAKO;AA0CA,SAAS,0BACd,QACA,eAAsB,CAAC,GACvB;AA9GF;AA+GE,QAAM,qBAAiB,0CAA4B;AACnD,QAAM,mBAAkB,sDAAgB,YAAhB,YAA2B;AAEnD,QAAM,aACH,YAAO,cAAc,YAAY,WAAW,OAAO,cAAnD,YAAiE;AAEpE,QAAM,wBAAwB,iCACzB,SADyB;AAAA,IAE5B;AAAA,IACA,iBAAiB;AAAA;AAAA,EACnB;AACA,4CAAwB,uBAAuB,YAAY;AAC7D;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -84,7 +84,7 @@ __export(use_copilot_chat_exports, {
|
|
|
84
84
|
module.exports = __toCommonJS(use_copilot_chat_exports);
|
|
85
85
|
|
|
86
86
|
// src/hooks/use-copilot-chat_internal.ts
|
|
87
|
-
var
|
|
87
|
+
var import_react13 = require("react");
|
|
88
88
|
|
|
89
89
|
// src/context/copilot-context.tsx
|
|
90
90
|
var import_react = __toESM(require("react"));
|
|
@@ -162,7 +162,7 @@ var emptyCopilotContext = {
|
|
|
162
162
|
interruptEventQueue: {},
|
|
163
163
|
addInterruptEvent: () => {
|
|
164
164
|
},
|
|
165
|
-
|
|
165
|
+
resolveInterruptEvent: () => {
|
|
166
166
|
},
|
|
167
167
|
onError: () => {
|
|
168
168
|
},
|
|
@@ -333,24 +333,60 @@ function useCoAgentStateRenders() {
|
|
|
333
333
|
}
|
|
334
334
|
|
|
335
335
|
// src/hooks/use-langgraph-interrupt-render.ts
|
|
336
|
-
var
|
|
336
|
+
var import_react7 = __toESM(require("react"));
|
|
337
337
|
var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
|
|
338
338
|
var import_shared2 = require("@copilotkit/shared");
|
|
339
|
+
|
|
340
|
+
// src/hooks/use-agent-nodename.ts
|
|
341
|
+
var import_react5 = require("react");
|
|
342
|
+
var import_react6 = require("@copilotkitnext/react");
|
|
343
|
+
function useAgentNodeName(agentName) {
|
|
344
|
+
const { agent } = (0, import_react6.useAgent)({ agentId: agentName });
|
|
345
|
+
const nodeNameRef = (0, import_react5.useRef)("start");
|
|
346
|
+
(0, import_react5.useEffect)(() => {
|
|
347
|
+
if (!agent)
|
|
348
|
+
return;
|
|
349
|
+
const subscriber = {
|
|
350
|
+
onStepStartedEvent: ({ event }) => {
|
|
351
|
+
nodeNameRef.current = event.stepName;
|
|
352
|
+
},
|
|
353
|
+
onRunStartedEvent: () => {
|
|
354
|
+
nodeNameRef.current = "start";
|
|
355
|
+
},
|
|
356
|
+
onRunFinishedEvent: () => {
|
|
357
|
+
nodeNameRef.current = "end";
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
const subscription = agent.subscribe(subscriber);
|
|
361
|
+
return () => {
|
|
362
|
+
subscription.unsubscribe();
|
|
363
|
+
};
|
|
364
|
+
}, [agent]);
|
|
365
|
+
return nodeNameRef.current;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// src/hooks/use-langgraph-interrupt-render.ts
|
|
369
|
+
var import_react8 = require("@copilotkitnext/react");
|
|
339
370
|
var InterruptRenderer = ({ event, result, render, resolve }) => {
|
|
340
371
|
return render({ event, result, resolve });
|
|
341
372
|
};
|
|
342
373
|
function useLangGraphInterruptRender(agent) {
|
|
374
|
+
var _a;
|
|
343
375
|
const {
|
|
344
376
|
interruptActions,
|
|
345
377
|
agentSession,
|
|
346
378
|
threadId,
|
|
347
379
|
interruptEventQueue,
|
|
348
380
|
addInterruptEvent,
|
|
349
|
-
|
|
381
|
+
resolveInterruptEvent
|
|
350
382
|
} = useCopilotContext();
|
|
351
|
-
(0,
|
|
383
|
+
const existingConfig = (0, import_react8.useCopilotChatConfiguration)();
|
|
384
|
+
const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
|
|
385
|
+
const nodeName = useAgentNodeName(resolvedAgentId);
|
|
386
|
+
(0, import_react7.useEffect)(() => {
|
|
352
387
|
if (!agent)
|
|
353
388
|
return;
|
|
389
|
+
let localInterrupt = null;
|
|
354
390
|
const subscriber = {
|
|
355
391
|
onCustomEvent: ({ event }) => {
|
|
356
392
|
if (event.name === "on_interrupt") {
|
|
@@ -359,12 +395,21 @@ function useLangGraphInterruptRender(agent) {
|
|
|
359
395
|
type: event.type,
|
|
360
396
|
value: (0, import_shared2.parseJson)(event.value, event.value)
|
|
361
397
|
};
|
|
362
|
-
const eventId = (0, import_shared2.dataToUUID)(
|
|
363
|
-
|
|
398
|
+
const eventId = (0, import_shared2.dataToUUID)(eventData, "interruptEvents");
|
|
399
|
+
localInterrupt = {
|
|
364
400
|
eventId,
|
|
365
401
|
threadId,
|
|
366
402
|
event: eventData
|
|
367
|
-
}
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
},
|
|
406
|
+
onRunStartedEvent: () => {
|
|
407
|
+
localInterrupt = null;
|
|
408
|
+
},
|
|
409
|
+
onRunFinalized: () => {
|
|
410
|
+
if (localInterrupt) {
|
|
411
|
+
addInterruptEvent(localInterrupt);
|
|
412
|
+
localInterrupt = null;
|
|
368
413
|
}
|
|
369
414
|
}
|
|
370
415
|
};
|
|
@@ -373,7 +418,7 @@ function useLangGraphInterruptRender(agent) {
|
|
|
373
418
|
unsubscribe();
|
|
374
419
|
};
|
|
375
420
|
}, [agent, threadId]);
|
|
376
|
-
const handleResolve = (0,
|
|
421
|
+
const handleResolve = (0, import_react7.useCallback)(
|
|
377
422
|
(eventId, response) => {
|
|
378
423
|
agent == null ? void 0 : agent.runAgent({
|
|
379
424
|
forwardedProps: {
|
|
@@ -382,15 +427,15 @@ function useLangGraphInterruptRender(agent) {
|
|
|
382
427
|
}
|
|
383
428
|
}
|
|
384
429
|
});
|
|
385
|
-
|
|
430
|
+
resolveInterruptEvent(threadId, eventId, response != null ? response : "");
|
|
386
431
|
},
|
|
387
432
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
388
433
|
[agent, threadId]
|
|
389
434
|
);
|
|
390
|
-
return (0,
|
|
435
|
+
return (0, import_react7.useMemo)(() => {
|
|
391
436
|
const eventQueue = interruptEventQueue[threadId] || [];
|
|
392
437
|
const currentQueuedEvent = eventQueue.find((qe) => !qe.event.response);
|
|
393
|
-
if (!currentQueuedEvent)
|
|
438
|
+
if (!currentQueuedEvent || !agentSession)
|
|
394
439
|
return null;
|
|
395
440
|
const allActions = Object.values(interruptActions);
|
|
396
441
|
const matchingAction = allActions.find((action) => {
|
|
@@ -398,7 +443,9 @@ function useLangGraphInterruptRender(agent) {
|
|
|
398
443
|
return true;
|
|
399
444
|
return action.enabled({
|
|
400
445
|
eventValue: currentQueuedEvent.event.value,
|
|
401
|
-
agentMetadata: agentSession
|
|
446
|
+
agentMetadata: __spreadProps(__spreadValues({}, agentSession), {
|
|
447
|
+
nodeName
|
|
448
|
+
})
|
|
402
449
|
});
|
|
403
450
|
});
|
|
404
451
|
if (!matchingAction)
|
|
@@ -416,7 +463,7 @@ function useLangGraphInterruptRender(agent) {
|
|
|
416
463
|
}
|
|
417
464
|
if (!render)
|
|
418
465
|
return null;
|
|
419
|
-
return
|
|
466
|
+
return import_react7.default.createElement(InterruptRenderer, {
|
|
420
467
|
event: currentQueuedEvent.event,
|
|
421
468
|
result,
|
|
422
469
|
render,
|
|
@@ -426,14 +473,14 @@ function useLangGraphInterruptRender(agent) {
|
|
|
426
473
|
}
|
|
427
474
|
|
|
428
475
|
// src/hooks/use-copilot-chat_internal.ts
|
|
429
|
-
var
|
|
476
|
+
var import_react14 = require("@copilotkitnext/react");
|
|
430
477
|
|
|
431
478
|
// src/hooks/use-lazy-tool-renderer.tsx
|
|
432
|
-
var
|
|
433
|
-
var
|
|
479
|
+
var import_react9 = require("@copilotkitnext/react");
|
|
480
|
+
var import_react10 = require("react");
|
|
434
481
|
function useLazyToolRenderer() {
|
|
435
|
-
const renderToolCall = (0,
|
|
436
|
-
return (0,
|
|
482
|
+
const renderToolCall = (0, import_react9.useRenderToolCall)();
|
|
483
|
+
return (0, import_react10.useCallback)(
|
|
437
484
|
(message, messages) => {
|
|
438
485
|
var _a;
|
|
439
486
|
if (!((_a = message == null ? void 0 : message.toolCalls) == null ? void 0 : _a.length))
|
|
@@ -453,39 +500,7 @@ function useLazyToolRenderer() {
|
|
|
453
500
|
);
|
|
454
501
|
}
|
|
455
502
|
|
|
456
|
-
//
|
|
457
|
-
var import_react8 = require("@copilotkitnext/react");
|
|
458
|
-
var import_react9 = require("react");
|
|
459
|
-
function useConfigureChatSuggestions(config, dependencies = []) {
|
|
460
|
-
const { agentSession } = useCopilotContext();
|
|
461
|
-
const { copilotkit } = (0, import_react8.useCopilotKit)();
|
|
462
|
-
const available = config.available === "enabled" ? "always" : config.available;
|
|
463
|
-
const finalSuggestionConfig = __spreadProps(__spreadValues({}, config), {
|
|
464
|
-
available,
|
|
465
|
-
consumerAgentId: agentSession == null ? void 0 : agentSession.agentName
|
|
466
|
-
// Use chatConfig.agentId here
|
|
467
|
-
});
|
|
468
|
-
(0, import_react8.useConfigureSuggestions)(finalSuggestionConfig, { deps: dependencies });
|
|
469
|
-
const result = (0, import_react8.useSuggestions)({ agentId: agentSession == null ? void 0 : agentSession.agentName });
|
|
470
|
-
(0, import_react9.useEffect)(() => {
|
|
471
|
-
if (finalSuggestionConfig.available === "disabled")
|
|
472
|
-
return;
|
|
473
|
-
const subscription = copilotkit.subscribe({
|
|
474
|
-
onAgentsChanged: () => {
|
|
475
|
-
const agent = copilotkit.getAgent(agentSession == null ? void 0 : agentSession.agentName);
|
|
476
|
-
if (agent && !agent.isRunning && !result.suggestions.length) {
|
|
477
|
-
copilotkit.reloadSuggestions(agentSession == null ? void 0 : agentSession.agentName);
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
});
|
|
481
|
-
return () => {
|
|
482
|
-
subscription.unsubscribe();
|
|
483
|
-
};
|
|
484
|
-
}, []);
|
|
485
|
-
return result;
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
// ../../node_modules/.pnpm/@ag-ui+core@0.0.42-alpha.1/node_modules/@ag-ui/core/dist/index.mjs
|
|
503
|
+
// ../../node_modules/.pnpm/@ag-ui+core@0.0.42/node_modules/@ag-ui/core/dist/index.mjs
|
|
489
504
|
var import_zod = require("zod");
|
|
490
505
|
var import_zod2 = require("zod");
|
|
491
506
|
var FunctionCallSchema = import_zod.z.object({
|
|
@@ -891,10 +906,12 @@ var EventSchemas = import_zod2.z.discriminatedUnion("type", [
|
|
|
891
906
|
]);
|
|
892
907
|
|
|
893
908
|
// src/hooks/use-coagent-state-render-bridge.tsx
|
|
894
|
-
var
|
|
895
|
-
var
|
|
909
|
+
var import_react11 = require("@copilotkitnext/react");
|
|
910
|
+
var import_react12 = require("react");
|
|
896
911
|
var import_shared3 = require("@copilotkit/shared");
|
|
897
912
|
function getStateWithoutConstantKeys(state) {
|
|
913
|
+
if (!state)
|
|
914
|
+
return {};
|
|
898
915
|
const _a = state, { messages, tools, copilotkit } = _a, stateWithoutConstantKeys = __objRest(_a, ["messages", "tools", "copilotkit"]);
|
|
899
916
|
return stateWithoutConstantKeys;
|
|
900
917
|
}
|
|
@@ -917,11 +934,11 @@ function useCoagentStateRenderBridge(agentId, props) {
|
|
|
917
934
|
var _a;
|
|
918
935
|
const { stateSnapshot, messageIndexInRun, message } = props;
|
|
919
936
|
const { coAgentStateRenders, claimsRef } = useCoAgentStateRenders();
|
|
920
|
-
const { agent } = (0,
|
|
921
|
-
const [nodeName, setNodeName] = (0,
|
|
937
|
+
const { agent } = (0, import_react11.useAgent)({ agentId });
|
|
938
|
+
const [nodeName, setNodeName] = (0, import_react12.useState)(void 0);
|
|
922
939
|
const runId = (_a = props.runId) != null ? _a : message.runId;
|
|
923
940
|
const effectiveRunId = runId || "pending";
|
|
924
|
-
(0,
|
|
941
|
+
(0, import_react12.useEffect)(() => {
|
|
925
942
|
if (!agent)
|
|
926
943
|
return;
|
|
927
944
|
const subscriber = {
|
|
@@ -941,10 +958,7 @@ function useCoagentStateRenderBridge(agentId, props) {
|
|
|
941
958
|
unsubscribe();
|
|
942
959
|
};
|
|
943
960
|
}, [agentId, nodeName]);
|
|
944
|
-
|
|
945
|
-
return null;
|
|
946
|
-
}
|
|
947
|
-
const getStateRender = (0, import_react11.useCallback)(
|
|
961
|
+
const getStateRender = (0, import_react12.useCallback)(
|
|
948
962
|
(messageId) => {
|
|
949
963
|
return Object.entries(coAgentStateRenders).find(([stateRenderId, stateRender]) => {
|
|
950
964
|
if (claimsRef.current[messageId]) {
|
|
@@ -971,7 +985,7 @@ function useCoagentStateRenderBridge(agentId, props) {
|
|
|
971
985
|
return canRender;
|
|
972
986
|
}
|
|
973
987
|
const renderClaimedByOtherMessage = Object.values(claimsRef.current).find(
|
|
974
|
-
(c) => c.stateRenderId === stateRenderId && (0, import_shared3.dataToUUID)(
|
|
988
|
+
(c) => c.stateRenderId === stateRenderId && (0, import_shared3.dataToUUID)(getStateWithoutConstantKeys(c.stateSnapshot)) === (0, import_shared3.dataToUUID)(getStateWithoutConstantKeys(renderSnapshot))
|
|
975
989
|
);
|
|
976
990
|
if (renderClaimedByOtherMessage) {
|
|
977
991
|
if (renderSnapshot && renderClaimedByOtherMessage.stateSnapshot && !areStatesEquals(renderClaimedByOtherMessage.stateSnapshot, renderSnapshot)) {
|
|
@@ -986,8 +1000,11 @@ function useCoagentStateRenderBridge(agentId, props) {
|
|
|
986
1000
|
claimsRef.current[messageId] = { stateRenderId, runId: runId2 };
|
|
987
1001
|
return true;
|
|
988
1002
|
};
|
|
989
|
-
return (0,
|
|
1003
|
+
return (0, import_react12.useMemo)(() => {
|
|
990
1004
|
var _a2, _b, _c;
|
|
1005
|
+
if (messageIndexInRun !== 0) {
|
|
1006
|
+
return null;
|
|
1007
|
+
}
|
|
991
1008
|
const [stateRenderId, stateRender] = (_a2 = getStateRender(message.id)) != null ? _a2 : [];
|
|
992
1009
|
if (!stateRender || !stateRenderId) {
|
|
993
1010
|
return null;
|
|
@@ -1034,7 +1051,8 @@ function useCoagentStateRenderBridge(agentId, props) {
|
|
|
1034
1051
|
agent == null ? void 0 : agent.isRunning,
|
|
1035
1052
|
nodeName,
|
|
1036
1053
|
effectiveRunId,
|
|
1037
|
-
message.id
|
|
1054
|
+
message.id,
|
|
1055
|
+
messageIndexInRun
|
|
1038
1056
|
]);
|
|
1039
1057
|
}
|
|
1040
1058
|
function CoAgentStateRenderBridge(props) {
|
|
@@ -1042,35 +1060,17 @@ function CoAgentStateRenderBridge(props) {
|
|
|
1042
1060
|
}
|
|
1043
1061
|
|
|
1044
1062
|
// src/hooks/use-copilot-chat_internal.ts
|
|
1045
|
-
function useConfigureSuggestions2(suggestions) {
|
|
1046
|
-
let suggestionsConfig;
|
|
1047
|
-
if (Array.isArray(suggestions)) {
|
|
1048
|
-
suggestionsConfig = {
|
|
1049
|
-
suggestions,
|
|
1050
|
-
available: "always"
|
|
1051
|
-
};
|
|
1052
|
-
} else if (suggestions === "auto") {
|
|
1053
|
-
suggestionsConfig = {
|
|
1054
|
-
available: suggestions === "auto" ? "always" : "disabled",
|
|
1055
|
-
instructions: "Suggest what the user could say next. Provide clear, highly relevant suggestions. Do not literally suggest function calls."
|
|
1056
|
-
};
|
|
1057
|
-
} else {
|
|
1058
|
-
suggestionsConfig = { available: "disabled" };
|
|
1059
|
-
}
|
|
1060
|
-
useConfigureChatSuggestions(suggestionsConfig);
|
|
1061
|
-
}
|
|
1062
1063
|
function useCopilotChatInternal({
|
|
1063
1064
|
suggestions
|
|
1064
1065
|
} = {}) {
|
|
1065
|
-
var _a, _b, _c
|
|
1066
|
-
const { copilotkit } = (0,
|
|
1066
|
+
var _a, _b, _c;
|
|
1067
|
+
const { copilotkit } = (0, import_react14.useCopilotKit)();
|
|
1067
1068
|
const { threadId, agentSession } = useCopilotContext();
|
|
1068
|
-
const existingConfig = (0,
|
|
1069
|
-
const [agentAvailable, setAgentAvailable] = (0,
|
|
1070
|
-
|
|
1071
|
-
const
|
|
1072
|
-
|
|
1073
|
-
(0, import_react12.useEffect)(() => {
|
|
1069
|
+
const existingConfig = (0, import_react14.useCopilotChatConfiguration)();
|
|
1070
|
+
const [agentAvailable, setAgentAvailable] = (0, import_react13.useState)(false);
|
|
1071
|
+
const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
|
|
1072
|
+
const { agent } = (0, import_react14.useAgent)({ agentId: resolvedAgentId });
|
|
1073
|
+
(0, import_react13.useEffect)(() => {
|
|
1074
1074
|
const connect = (agent2) => __async(this, null, function* () {
|
|
1075
1075
|
setAgentAvailable(false);
|
|
1076
1076
|
try {
|
|
@@ -1095,7 +1095,7 @@ function useCopilotChatInternal({
|
|
|
1095
1095
|
agent == null ? void 0 : agent.setMessages([]);
|
|
1096
1096
|
agent == null ? void 0 : agent.setState(null);
|
|
1097
1097
|
};
|
|
1098
|
-
const deleteMessage = (0,
|
|
1098
|
+
const deleteMessage = (0, import_react13.useCallback)(
|
|
1099
1099
|
(messageId) => {
|
|
1100
1100
|
var _a2;
|
|
1101
1101
|
const filteredMessages = ((_a2 = agent == null ? void 0 : agent.messages) != null ? _a2 : []).filter(
|
|
@@ -1106,13 +1106,13 @@ function useCopilotChatInternal({
|
|
|
1106
1106
|
[agent == null ? void 0 : agent.setMessages, agent == null ? void 0 : agent.messages]
|
|
1107
1107
|
);
|
|
1108
1108
|
const latestDelete = useUpdatedRef(deleteMessage);
|
|
1109
|
-
const latestDeleteFunc = (0,
|
|
1109
|
+
const latestDeleteFunc = (0, import_react13.useCallback)(
|
|
1110
1110
|
(messageId) => {
|
|
1111
1111
|
return latestDelete.current(messageId);
|
|
1112
1112
|
},
|
|
1113
1113
|
[latestDelete]
|
|
1114
1114
|
);
|
|
1115
|
-
const currentSuggestions = (0,
|
|
1115
|
+
const currentSuggestions = (0, import_react14.useSuggestions)({ agentId: resolvedAgentId });
|
|
1116
1116
|
const reload = useAsyncCallback(
|
|
1117
1117
|
(reloadMessageId) => __async(this, null, function* () {
|
|
1118
1118
|
var _a2;
|
|
@@ -1179,16 +1179,15 @@ function useCopilotChatInternal({
|
|
|
1179
1179
|
}),
|
|
1180
1180
|
[latestSendMessageFunc]
|
|
1181
1181
|
);
|
|
1182
|
-
const
|
|
1183
|
-
const latestSetMessagesFunc = (0, import_react12.useCallback)(
|
|
1182
|
+
const latestSetMessagesFunc = (0, import_react13.useCallback)(
|
|
1184
1183
|
(messages) => {
|
|
1185
1184
|
var _a2, _b2;
|
|
1186
1185
|
if (messages.every((message) => message instanceof import_runtime_client_gql2.Message)) {
|
|
1187
|
-
return (_a2 =
|
|
1186
|
+
return (_a2 = agent == null ? void 0 : agent.setMessages) == null ? void 0 : _a2.call(agent, (0, import_runtime_client_gql2.gqlToAGUI)(messages));
|
|
1188
1187
|
}
|
|
1189
|
-
return (_b2 =
|
|
1188
|
+
return (_b2 = agent == null ? void 0 : agent.setMessages) == null ? void 0 : _b2.call(agent, messages);
|
|
1190
1189
|
},
|
|
1191
|
-
[
|
|
1190
|
+
[agent == null ? void 0 : agent.setMessages, agent]
|
|
1192
1191
|
);
|
|
1193
1192
|
const latestReload = useUpdatedRef(reload);
|
|
1194
1193
|
const latestReloadFunc = useAsyncCallback(
|
|
@@ -1197,25 +1196,24 @@ function useCopilotChatInternal({
|
|
|
1197
1196
|
}),
|
|
1198
1197
|
[latestReload]
|
|
1199
1198
|
);
|
|
1200
|
-
const
|
|
1201
|
-
const latestStopFunc = (0, import_react12.useCallback)(() => {
|
|
1199
|
+
const latestStopFunc = (0, import_react13.useCallback)(() => {
|
|
1202
1200
|
var _a2;
|
|
1203
|
-
return (_a2 =
|
|
1204
|
-
}, [
|
|
1201
|
+
return (_a2 = agent == null ? void 0 : agent.abortRun) == null ? void 0 : _a2.call(agent);
|
|
1202
|
+
}, [agent == null ? void 0 : agent.abortRun]);
|
|
1205
1203
|
const latestReset = useUpdatedRef(reset);
|
|
1206
|
-
const latestResetFunc = (0,
|
|
1204
|
+
const latestResetFunc = (0, import_react13.useCallback)(() => {
|
|
1207
1205
|
return latestReset.current();
|
|
1208
1206
|
}, [latestReset]);
|
|
1209
1207
|
const lazyToolRendered = useLazyToolRenderer();
|
|
1210
|
-
const renderCustomMessage = (0,
|
|
1208
|
+
const renderCustomMessage = (0, import_react14.useRenderCustomMessages)();
|
|
1211
1209
|
const legacyCustomMessageRenderer = useLegacyCoagentRenderer({
|
|
1212
1210
|
copilotkit,
|
|
1213
1211
|
agent,
|
|
1214
1212
|
agentId: resolvedAgentId,
|
|
1215
|
-
threadId: (
|
|
1213
|
+
threadId: (_b = existingConfig == null ? void 0 : existingConfig.threadId) != null ? _b : threadId
|
|
1216
1214
|
});
|
|
1217
|
-
const allMessages = (
|
|
1218
|
-
const resolvedMessages = (0,
|
|
1215
|
+
const allMessages = (_c = agent == null ? void 0 : agent.messages) != null ? _c : [];
|
|
1216
|
+
const resolvedMessages = (0, import_react13.useMemo)(() => {
|
|
1219
1217
|
let processedMessages = allMessages.map((message) => {
|
|
1220
1218
|
if (message.role !== "assistant") {
|
|
1221
1219
|
return message;
|
|
@@ -1243,33 +1241,24 @@ function useCopilotChatInternal({
|
|
|
1243
1241
|
return message;
|
|
1244
1242
|
});
|
|
1245
1243
|
const hasAssistantMessages = processedMessages.some((msg) => msg.role === "assistant");
|
|
1246
|
-
if (legacyCustomMessageRenderer && !hasAssistantMessages) {
|
|
1247
|
-
const placeholderId = `coagent-state-render-${resolvedAgentId}`;
|
|
1248
|
-
const placeholderMessage = {
|
|
1249
|
-
id: placeholderId,
|
|
1250
|
-
role: "assistant",
|
|
1251
|
-
content: "",
|
|
1252
|
-
name: "coagent-state-render"
|
|
1253
|
-
};
|
|
1254
|
-
processedMessages = [
|
|
1255
|
-
...processedMessages,
|
|
1256
|
-
__spreadProps(__spreadValues({}, placeholderMessage), {
|
|
1257
|
-
generativeUI: () => legacyCustomMessageRenderer({
|
|
1258
|
-
message: placeholderMessage,
|
|
1259
|
-
position: "before"
|
|
1260
|
-
})
|
|
1261
|
-
})
|
|
1262
|
-
];
|
|
1263
|
-
}
|
|
1264
1244
|
return processedMessages;
|
|
1265
1245
|
}, [
|
|
1266
1246
|
agent == null ? void 0 : agent.messages,
|
|
1267
1247
|
lazyToolRendered,
|
|
1268
1248
|
allMessages,
|
|
1269
1249
|
renderCustomMessage,
|
|
1270
|
-
legacyCustomMessageRenderer,
|
|
1250
|
+
// legacyCustomMessageRenderer,
|
|
1271
1251
|
resolvedAgentId
|
|
1272
1252
|
]);
|
|
1253
|
+
const renderedSuggestions = (0, import_react13.useMemo)(() => {
|
|
1254
|
+
if (Array.isArray(suggestions)) {
|
|
1255
|
+
return {
|
|
1256
|
+
suggestions: suggestions.map((s) => __spreadProps(__spreadValues({}, s), { isLoading: false })),
|
|
1257
|
+
isLoading: false
|
|
1258
|
+
};
|
|
1259
|
+
}
|
|
1260
|
+
return currentSuggestions;
|
|
1261
|
+
}, [suggestions, currentSuggestions]);
|
|
1273
1262
|
return {
|
|
1274
1263
|
messages: resolvedMessages,
|
|
1275
1264
|
sendMessage: latestSendMessageFunc,
|
|
@@ -1279,25 +1268,25 @@ function useCopilotChatInternal({
|
|
|
1279
1268
|
stopGeneration: latestStopFunc,
|
|
1280
1269
|
reset: latestResetFunc,
|
|
1281
1270
|
deleteMessage: latestDeleteFunc,
|
|
1282
|
-
isAvailable:
|
|
1271
|
+
isAvailable: agentAvailable,
|
|
1283
1272
|
isLoading: Boolean(agent == null ? void 0 : agent.isRunning),
|
|
1284
1273
|
// mcpServers,
|
|
1285
1274
|
// setMcpServers,
|
|
1286
|
-
suggestions:
|
|
1275
|
+
suggestions: renderedSuggestions.suggestions,
|
|
1287
1276
|
setSuggestions: (suggestions2) => copilotkit.addSuggestionsConfig({ suggestions: suggestions2 }),
|
|
1288
1277
|
generateSuggestions: () => __async(this, null, function* () {
|
|
1289
1278
|
return copilotkit.reloadSuggestions(resolvedAgentId);
|
|
1290
1279
|
}),
|
|
1291
1280
|
resetSuggestions: () => copilotkit.clearSuggestions(resolvedAgentId),
|
|
1292
|
-
isLoadingSuggestions:
|
|
1281
|
+
isLoadingSuggestions: renderedSuggestions.isLoading,
|
|
1293
1282
|
interrupt,
|
|
1294
1283
|
agent,
|
|
1295
1284
|
threadId
|
|
1296
1285
|
};
|
|
1297
1286
|
}
|
|
1298
1287
|
function useUpdatedRef(value) {
|
|
1299
|
-
const ref = (0,
|
|
1300
|
-
(0,
|
|
1288
|
+
const ref = (0, import_react13.useRef)(value);
|
|
1289
|
+
(0, import_react13.useEffect)(() => {
|
|
1301
1290
|
ref.current = value;
|
|
1302
1291
|
}, [value]);
|
|
1303
1292
|
return ref;
|
|
@@ -1308,20 +1297,19 @@ function useLegacyCoagentRenderer({
|
|
|
1308
1297
|
agentId,
|
|
1309
1298
|
threadId
|
|
1310
1299
|
}) {
|
|
1311
|
-
return (0,
|
|
1300
|
+
return (0, import_react13.useMemo)(() => {
|
|
1312
1301
|
if (!copilotkit || !agent) {
|
|
1313
1302
|
return null;
|
|
1314
1303
|
}
|
|
1315
1304
|
return ({ message, position }) => {
|
|
1316
1305
|
var _a;
|
|
1317
1306
|
const effectiveThreadId = (_a = threadId != null ? threadId : agent.threadId) != null ? _a : "default";
|
|
1318
|
-
const existingRunId = copilotkit.getRunIdForMessage(
|
|
1319
|
-
agentId,
|
|
1320
|
-
effectiveThreadId,
|
|
1321
|
-
message.id
|
|
1322
|
-
);
|
|
1307
|
+
const existingRunId = copilotkit.getRunIdForMessage(agentId, effectiveThreadId, message.id);
|
|
1323
1308
|
const runId = existingRunId || `pending:${message.id}`;
|
|
1324
|
-
const messageIndex = Math.max(
|
|
1309
|
+
const messageIndex = Math.max(
|
|
1310
|
+
agent.messages.findIndex((msg) => msg.id === message.id),
|
|
1311
|
+
0
|
|
1312
|
+
);
|
|
1325
1313
|
const bridgeProps = {
|
|
1326
1314
|
message,
|
|
1327
1315
|
position,
|
|
@@ -1332,7 +1320,7 @@ function useLegacyCoagentRenderer({
|
|
|
1332
1320
|
agentId,
|
|
1333
1321
|
stateSnapshot: message.state
|
|
1334
1322
|
};
|
|
1335
|
-
return (0,
|
|
1323
|
+
return (0, import_react13.createElement)(CoAgentStateRenderBridge, bridgeProps);
|
|
1336
1324
|
};
|
|
1337
1325
|
}, [agent, agentId, copilotkit, threadId]);
|
|
1338
1326
|
}
|