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

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.
Files changed (60) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/{chunk-EKDPRKZT.mjs → chunk-3775VM7Y.mjs} +14 -26
  3. package/dist/chunk-3775VM7Y.mjs.map +1 -0
  4. package/dist/{chunk-BLDHD6Q2.mjs → chunk-7SHWECGN.mjs} +2 -2
  5. package/dist/{chunk-Y2L7KDVW.mjs → chunk-B5ELMVT7.mjs} +2 -2
  6. package/dist/{chunk-ZU6ZBX4E.mjs → chunk-FYMZKPOL.mjs} +4 -4
  7. package/dist/chunk-XDFVCQD3.mjs +27 -0
  8. package/dist/chunk-XDFVCQD3.mjs.map +1 -0
  9. package/dist/{chunk-KYY2WZSR.mjs → chunk-YJGPIN3R.mjs} +2 -2
  10. package/dist/{chunk-RQ6LWR6S.mjs → chunk-Z6JV2LRY.mjs} +1 -1
  11. package/dist/chunk-Z6JV2LRY.mjs.map +1 -0
  12. package/dist/components/copilot-provider/copilotkit.mjs +4 -4
  13. package/dist/components/copilot-provider/index.mjs +4 -4
  14. package/dist/components/index.mjs +4 -4
  15. package/dist/hooks/index.d.ts +1 -1
  16. package/dist/hooks/index.js +121 -149
  17. package/dist/hooks/index.js.map +1 -1
  18. package/dist/hooks/index.mjs +24 -24
  19. package/dist/hooks/use-copilot-chat-headless_c.js +39 -82
  20. package/dist/hooks/use-copilot-chat-headless_c.js.map +1 -1
  21. package/dist/hooks/use-copilot-chat-headless_c.mjs +3 -4
  22. package/dist/hooks/{use-configure-chat-suggestions.d.ts → use-copilot-chat-suggestions.d.ts} +2 -3
  23. package/dist/hooks/{use-configure-chat-suggestions.js → use-copilot-chat-suggestions.js} +10 -29
  24. package/dist/hooks/use-copilot-chat-suggestions.js.map +1 -0
  25. package/dist/hooks/use-copilot-chat-suggestions.mjs +8 -0
  26. package/dist/hooks/use-copilot-chat.js +37 -80
  27. package/dist/hooks/use-copilot-chat.js.map +1 -1
  28. package/dist/hooks/use-copilot-chat.mjs +3 -4
  29. package/dist/hooks/use-copilot-chat_internal.d.ts +17 -0
  30. package/dist/hooks/use-copilot-chat_internal.js +37 -80
  31. package/dist/hooks/use-copilot-chat_internal.js.map +1 -1
  32. package/dist/hooks/use-copilot-chat_internal.mjs +2 -3
  33. package/dist/hooks/use-copilot-readable.d.ts +2 -3
  34. package/dist/hooks/use-copilot-readable.js.map +1 -1
  35. package/dist/hooks/use-copilot-readable.mjs +1 -1
  36. package/dist/index.d.ts +1 -1
  37. package/dist/index.js +114 -142
  38. package/dist/index.js.map +1 -1
  39. package/dist/index.mjs +32 -32
  40. package/dist/lib/copilot-task.mjs +5 -5
  41. package/dist/lib/index.mjs +5 -5
  42. package/dist/types/index.mjs +1 -1
  43. package/dist/utils/index.mjs +3 -3
  44. package/package.json +5 -5
  45. package/src/hooks/index.ts +2 -2
  46. package/src/hooks/use-copilot-chat-suggestions.tsx +124 -0
  47. package/src/hooks/use-copilot-chat_internal.ts +29 -29
  48. package/src/hooks/use-copilot-readable.ts +2 -4
  49. package/dist/chunk-EKDPRKZT.mjs.map +0 -1
  50. package/dist/chunk-FBVI3LQ6.mjs +0 -48
  51. package/dist/chunk-FBVI3LQ6.mjs.map +0 -1
  52. package/dist/chunk-RQ6LWR6S.mjs.map +0 -1
  53. package/dist/hooks/use-configure-chat-suggestions.js.map +0 -1
  54. package/dist/hooks/use-configure-chat-suggestions.mjs +0 -8
  55. package/src/hooks/use-configure-chat-suggestions.tsx +0 -86
  56. /package/dist/{chunk-BLDHD6Q2.mjs.map → chunk-7SHWECGN.mjs.map} +0 -0
  57. /package/dist/{chunk-Y2L7KDVW.mjs.map → chunk-B5ELMVT7.mjs.map} +0 -0
  58. /package/dist/{chunk-ZU6ZBX4E.mjs.map → chunk-FYMZKPOL.mjs.map} +0 -0
  59. /package/dist/{chunk-KYY2WZSR.mjs.map → chunk-YJGPIN3R.mjs.map} +0 -0
  60. /package/dist/hooks/{use-configure-chat-suggestions.mjs.map → use-copilot-chat-suggestions.mjs.map} +0 -0
package/dist/index.mjs CHANGED
@@ -1,22 +1,34 @@
1
1
  "use client";
2
2
  import "./chunk-FD6FGKYY.mjs";
3
- import "./chunk-6YOKPWQ7.mjs";
4
3
  import "./chunk-36KQV2NA.mjs";
4
+ import "./chunk-6YOKPWQ7.mjs";
5
5
  import "./chunk-LUGEI4YQ.mjs";
6
6
  import {
7
7
  CopilotTask
8
- } from "./chunk-Y2L7KDVW.mjs";
8
+ } from "./chunk-B5ELMVT7.mjs";
9
9
  import "./chunk-4CEQJ2X6.mjs";
10
10
  import "./chunk-A6NKSGH3.mjs";
11
- import {
12
- useDefaultTool
13
- } from "./chunk-U2ZRVVKT.mjs";
14
11
  import {
15
12
  useLangGraphInterrupt
16
13
  } from "./chunk-4RRMC7L2.mjs";
17
14
  import {
18
15
  useMakeCopilotDocumentReadable
19
16
  } from "./chunk-7IBF6RBW.mjs";
17
+ import {
18
+ useCopilotReadable
19
+ } from "./chunk-Z6JV2LRY.mjs";
20
+ import {
21
+ useCopilotRuntimeClient
22
+ } from "./chunk-6ESSSQ7Q.mjs";
23
+ import {
24
+ useDefaultTool
25
+ } from "./chunk-U2ZRVVKT.mjs";
26
+ import {
27
+ useCoAgentStateRender
28
+ } from "./chunk-YTQHRJUA.mjs";
29
+ import {
30
+ useCoAgent
31
+ } from "./chunk-ZYTXB6HH.mjs";
20
32
  import {
21
33
  useCopilotAdditionalInstructions
22
34
  } from "./chunk-ABWT4DRT.mjs";
@@ -37,56 +49,44 @@ import {
37
49
  } from "./chunk-7DTB7S5V.mjs";
38
50
  import {
39
51
  useCopilotChatHeadless_c
40
- } from "./chunk-KYY2WZSR.mjs";
52
+ } from "./chunk-YJGPIN3R.mjs";
53
+ import {
54
+ useCopilotChatSuggestions
55
+ } from "./chunk-XDFVCQD3.mjs";
41
56
  import {
42
57
  useCopilotChat
43
- } from "./chunk-BLDHD6Q2.mjs";
58
+ } from "./chunk-7SHWECGN.mjs";
44
59
  import {
45
60
  useCopilotChatInternal
46
- } from "./chunk-EKDPRKZT.mjs";
47
- import {
48
- useLangGraphInterruptRender
49
- } from "./chunk-VV56AVPB.mjs";
61
+ } from "./chunk-3775VM7Y.mjs";
50
62
  import {
51
63
  useLazyToolRenderer
52
64
  } from "./chunk-ZVF5Q6IH.mjs";
53
65
  import {
54
- useCopilotReadable
55
- } from "./chunk-RQ6LWR6S.mjs";
56
- import {
57
- useCopilotRuntimeClient
58
- } from "./chunk-6ESSSQ7Q.mjs";
59
- import {
60
- useCoAgentStateRender
61
- } from "./chunk-YTQHRJUA.mjs";
62
- import {
63
- useCoAgent
64
- } from "./chunk-ZYTXB6HH.mjs";
66
+ useLangGraphInterruptRender
67
+ } from "./chunk-VV56AVPB.mjs";
65
68
  import "./chunk-I76HKHPJ.mjs";
66
- import {
67
- useConfigureChatSuggestions
68
- } from "./chunk-FBVI3LQ6.mjs";
69
69
  import "./chunk-JD7BAH7U.mjs";
70
70
  import "./chunk-SPCZTZCY.mjs";
71
71
  import {
72
72
  CopilotKit,
73
73
  defaultCopilotContextCategories
74
- } from "./chunk-ZU6ZBX4E.mjs";
74
+ } from "./chunk-FYMZKPOL.mjs";
75
75
  import "./chunk-LHERIF3L.mjs";
76
76
  import "./chunk-HE22TZMF.mjs";
77
77
  import "./chunk-PMWUKW3Z.mjs";
78
78
  import "./chunk-YCG6SNAU.mjs";
79
79
  import "./chunk-PIF5KJYI.mjs";
80
+ import "./chunk-RKTVJRK7.mjs";
80
81
  import "./chunk-CYDWEPFL.mjs";
81
- import {
82
- SUGGESTION_RETRY_CONFIG
83
- } from "./chunk-2IDV5OHF.mjs";
84
82
  import {
85
83
  shouldShowDevConsole
86
84
  } from "./chunk-ICIK2BSB.mjs";
87
- import "./chunk-RKTVJRK7.mjs";
88
- import "./chunk-PMAFHQ7P.mjs";
85
+ import {
86
+ SUGGESTION_RETRY_CONFIG
87
+ } from "./chunk-2IDV5OHF.mjs";
89
88
  import "./chunk-YYN33GSG.mjs";
89
+ import "./chunk-PMAFHQ7P.mjs";
90
90
  import "./chunk-6PUNP7CD.mjs";
91
91
  import "./chunk-O7ARI5CV.mjs";
92
92
  import "./chunk-QNUAXSDP.mjs";
@@ -128,13 +128,13 @@ export {
128
128
  useCoAgent,
129
129
  useCoAgentStateRender,
130
130
  useCoAgentStateRenders,
131
- useConfigureChatSuggestions,
132
131
  useCopilotAction,
133
132
  useCopilotAdditionalInstructions,
134
133
  useCopilotAuthenticatedAction_c,
135
134
  useCopilotChat,
136
135
  useCopilotChatHeadless_c,
137
136
  useCopilotChatInternal,
137
+ useCopilotChatSuggestions,
138
138
  useCopilotContext,
139
139
  useCopilotMessagesContext,
140
140
  useCopilotReadable,
@@ -1,21 +1,21 @@
1
1
  import {
2
2
  CopilotTask
3
- } from "../chunk-Y2L7KDVW.mjs";
3
+ } from "../chunk-B5ELMVT7.mjs";
4
4
  import "../chunk-4CEQJ2X6.mjs";
5
5
  import "../chunk-JD7BAH7U.mjs";
6
6
  import "../chunk-SPCZTZCY.mjs";
7
- import "../chunk-ZU6ZBX4E.mjs";
7
+ import "../chunk-FYMZKPOL.mjs";
8
8
  import "../chunk-LHERIF3L.mjs";
9
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-RKTVJRK7.mjs";
13
14
  import "../chunk-CYDWEPFL.mjs";
14
- import "../chunk-2IDV5OHF.mjs";
15
15
  import "../chunk-ICIK2BSB.mjs";
16
- import "../chunk-RKTVJRK7.mjs";
17
- import "../chunk-PMAFHQ7P.mjs";
16
+ import "../chunk-2IDV5OHF.mjs";
18
17
  import "../chunk-YYN33GSG.mjs";
18
+ import "../chunk-PMAFHQ7P.mjs";
19
19
  import "../chunk-6PUNP7CD.mjs";
20
20
  import "../chunk-O7ARI5CV.mjs";
21
21
  import "../chunk-QNUAXSDP.mjs";
@@ -1,22 +1,22 @@
1
1
  import "../chunk-LUGEI4YQ.mjs";
2
2
  import {
3
3
  CopilotTask
4
- } from "../chunk-Y2L7KDVW.mjs";
4
+ } from "../chunk-B5ELMVT7.mjs";
5
5
  import "../chunk-4CEQJ2X6.mjs";
6
6
  import "../chunk-JD7BAH7U.mjs";
7
7
  import "../chunk-SPCZTZCY.mjs";
8
- import "../chunk-ZU6ZBX4E.mjs";
8
+ import "../chunk-FYMZKPOL.mjs";
9
9
  import "../chunk-LHERIF3L.mjs";
10
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-RKTVJRK7.mjs";
14
15
  import "../chunk-CYDWEPFL.mjs";
15
- import "../chunk-2IDV5OHF.mjs";
16
16
  import "../chunk-ICIK2BSB.mjs";
17
- import "../chunk-RKTVJRK7.mjs";
18
- import "../chunk-PMAFHQ7P.mjs";
17
+ import "../chunk-2IDV5OHF.mjs";
19
18
  import "../chunk-YYN33GSG.mjs";
19
+ import "../chunk-PMAFHQ7P.mjs";
20
20
  import "../chunk-6PUNP7CD.mjs";
21
21
  import "../chunk-O7ARI5CV.mjs";
22
22
  import "../chunk-QNUAXSDP.mjs";
@@ -1,4 +1,4 @@
1
1
  import "../chunk-FD6FGKYY.mjs";
2
- import "../chunk-6YOKPWQ7.mjs";
3
2
  import "../chunk-36KQV2NA.mjs";
3
+ import "../chunk-6YOKPWQ7.mjs";
4
4
  //# sourceMappingURL=index.mjs.map
@@ -1,10 +1,10 @@
1
1
  import "../chunk-CYDWEPFL.mjs";
2
- import {
3
- SUGGESTION_RETRY_CONFIG
4
- } from "../chunk-2IDV5OHF.mjs";
5
2
  import {
6
3
  shouldShowDevConsole
7
4
  } from "../chunk-ICIK2BSB.mjs";
5
+ import {
6
+ SUGGESTION_RETRY_CONFIG
7
+ } from "../chunk-2IDV5OHF.mjs";
8
8
  import "../chunk-SKC7AJIV.mjs";
9
9
  export {
10
10
  SUGGESTION_RETRY_CONFIG,
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "publishConfig": {
10
10
  "access": "public"
11
11
  },
12
- "version": "1.50.0-beta.8",
12
+ "version": "1.50.0-beta.9",
13
13
  "sideEffects": [
14
14
  "**/*.css"
15
15
  ],
@@ -52,8 +52,8 @@
52
52
  "tsup": "^6.7.0",
53
53
  "typescript": "^5.2.3",
54
54
  "zod": ">=3.0.0",
55
- "tsconfig": "1.4.6",
56
- "eslint-config-custom": "1.4.6"
55
+ "eslint-config-custom": "1.4.6",
56
+ "tsconfig": "1.4.6"
57
57
  },
58
58
  "dependencies": {
59
59
  "@copilotkitnext/core": "0.0.28",
@@ -61,8 +61,8 @@
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.8",
65
- "@copilotkit/shared": "1.50.0-beta.8"
64
+ "@copilotkit/runtime-client-gql": "1.50.0-beta.9",
65
+ "@copilotkit/shared": "1.50.0-beta.9"
66
66
  },
67
67
  "keywords": [
68
68
  "copilotkit",
@@ -24,6 +24,6 @@ export { useRenderToolCall } from "./use-render-tool-call";
24
24
  export { useDefaultTool } from "./use-default-tool";
25
25
  export { useLazyToolRenderer } from "./use-lazy-tool-renderer";
26
26
  export {
27
- useConfigureChatSuggestions,
27
+ useCopilotChatSuggestions,
28
28
  type UseCopilotChatSuggestionsConfiguration,
29
- } from "./use-configure-chat-suggestions";
29
+ } from "./use-copilot-chat-suggestions";
@@ -0,0 +1,124 @@
1
+ /**
2
+ * <Callout type="warning">
3
+ * useCopilotChatSuggestions is experimental. The interface is not final and
4
+ * can change without notice.
5
+ * </Callout>
6
+ *
7
+ * `useCopilotReadable` is a React hook that provides app-state and other information
8
+ * to the Copilot. Optionally, the hook can also handle hierarchical state within your
9
+ * application, passing these parent-child relationships to the Copilot.
10
+ *
11
+ * <br/>
12
+ * <img src="https://cdn.copilotkit.ai/docs/copilotkit/images/use-copilot-chat-suggestions/use-copilot-chat-suggestions.gif" width="500" />
13
+ *
14
+ * ## Usage
15
+ *
16
+ * ### Install Dependencies
17
+ *
18
+ * This component is part of the [@copilotkit/react-ui](https://npmjs.com/package/@copilotkit/react-ui) package.
19
+ *
20
+ * ```shell npm2yarn \"@copilotkit/react-ui"\
21
+ * npm install @copilotkit/react-core @copilotkit/react-ui
22
+ * ```
23
+ *
24
+ * ### Simple Usage
25
+ *
26
+ * ```tsx
27
+ * import { useCopilotChatSuggestions } from "@copilotkit/react-ui";
28
+ *
29
+ * export function MyComponent() {
30
+ * const [employees, setEmployees] = useState([]);
31
+ *
32
+ * useCopilotChatSuggestions({
33
+ * instructions: `The following employees are on duty: ${JSON.stringify(employees)}`,
34
+ * });
35
+ * }
36
+ * ```
37
+ *
38
+ * ### Dependency Management
39
+ *
40
+ * ```tsx
41
+ * import { useCopilotChatSuggestions } from "@copilotkit/react-ui";
42
+ *
43
+ * export function MyComponent() {
44
+ * useCopilotChatSuggestions(
45
+ * {
46
+ * instructions: "Suggest the most relevant next actions.",
47
+ * },
48
+ * [appState],
49
+ * );
50
+ * }
51
+ * ```
52
+ *
53
+ * In the example above, the suggestions are generated based on the given instructions.
54
+ * The hook monitors `appState`, and updates suggestions accordingly whenever it changes.
55
+ *
56
+ * ### Behavior and Lifecycle
57
+ *
58
+ * The hook registers the configuration with the chat context upon component mount and
59
+ * removes it on unmount, ensuring a clean and efficient lifecycle management.
60
+ */
61
+ import {
62
+ useConfigureSuggestions,
63
+ useCopilotChatConfiguration,
64
+ useCopilotKit,
65
+ useSuggestions,
66
+ } from "@copilotkitnext/react";
67
+ import { useEffect } from "react";
68
+ import { StaticSuggestionsConfig, Suggestion } from "@copilotkitnext/core";
69
+
70
+ type StaticSuggestionInput = Omit<Suggestion, "isLoading"> & Partial<Pick<Suggestion, "isLoading">>;
71
+
72
+ type StaticSuggestionsConfigInput = Omit<StaticSuggestionsConfig, "suggestions"> & {
73
+ suggestions: StaticSuggestionInput[];
74
+ };
75
+
76
+ type DynamicSuggestionsConfigInput = {
77
+ /**
78
+ * A prompt or instructions for the GPT to generate suggestions.
79
+ */
80
+ instructions: string;
81
+ /**
82
+ * The minimum number of suggestions to generate. Defaults to `1`.
83
+ * @default 1
84
+ */
85
+ minSuggestions?: number;
86
+ /**
87
+ * The maximum number of suggestions to generate. Defaults to `3`.
88
+ * @default 1
89
+ */
90
+ maxSuggestions?: number;
91
+
92
+ /**
93
+ * Whether the suggestions are available. Defaults to `enabled`.
94
+ * @default enabled
95
+ */
96
+ available?: "enabled" | "disabled" | "always" | "before-first-message" | "after-first-message";
97
+
98
+ /**
99
+ * An optional class name to apply to the suggestions.
100
+ */
101
+ className?: string;
102
+ };
103
+
104
+ export type UseCopilotChatSuggestionsConfiguration =
105
+ | DynamicSuggestionsConfigInput
106
+ | StaticSuggestionsConfigInput;
107
+
108
+ export function useCopilotChatSuggestions(
109
+ config: UseCopilotChatSuggestionsConfiguration,
110
+ dependencies: any[] = [],
111
+ ) {
112
+ const existingConfig = useCopilotChatConfiguration();
113
+ const resolvedAgentId = existingConfig?.agentId ?? "default";
114
+
115
+ const available =
116
+ (config.available === "enabled" ? "always" : config.available) ?? "before-first-message";
117
+
118
+ const finalSuggestionConfig = {
119
+ ...config,
120
+ available,
121
+ consumerAgentId: resolvedAgentId, // Use chatConfig.agentId here
122
+ };
123
+ useConfigureSuggestions(finalSuggestionConfig, dependencies);
124
+ }
@@ -14,10 +14,6 @@ import {
14
14
  } from "@copilotkitnext/react";
15
15
  import { Suggestion } from "@copilotkitnext/core";
16
16
  import { useLazyToolRenderer } from "./use-lazy-tool-renderer";
17
- import {
18
- useConfigureChatSuggestions,
19
- UseCopilotChatSuggestionsConfiguration,
20
- } from "./use-configure-chat-suggestions";
21
17
  import { AbstractAgent, AGUIConnectNotImplementedError } from "@ag-ui/client";
22
18
  import {
23
19
  CoAgentStateRenderBridge,
@@ -71,7 +67,23 @@ export interface UseCopilotChatOptions {
71
67
  * Disables inclusion of CopilotKit’s default system message. When true, no system message is sent (this also suppresses any custom message from <code>makeSystemMessage</code>).
72
68
  */
73
69
  disableSystemMessage?: boolean;
74
-
70
+ /**
71
+ * Controls the behavior of suggestions in the chat interface.
72
+ *
73
+ * `auto` (default) - Suggestions are generated automatically:
74
+ * - When the chat is first opened (empty state)
75
+ * - After each message exchange completes
76
+ * - Uses configuration from `useCopilotChatSuggestions` hooks
77
+ *
78
+ * `manual` - Suggestions are controlled programmatically:
79
+ * - Use `setSuggestions()` to set custom suggestions
80
+ * - Use `generateSuggestions()` to trigger AI generation
81
+ * - Access via `useCopilotChat` hook
82
+ *
83
+ * `SuggestionItem[]` - Static suggestions array:
84
+ * - Always shows the same suggestions
85
+ * - No AI generation involved
86
+ */
75
87
  suggestions?: ChatSuggestions;
76
88
  }
77
89
 
@@ -258,27 +270,6 @@ export interface UseCopilotChatReturn {
258
270
  threadId?: string;
259
271
  }
260
272
 
261
- function useConfigureSuggestions(suggestions?: UseCopilotChatOptions["suggestions"]) {
262
- let suggestionsConfig: UseCopilotChatSuggestionsConfiguration;
263
-
264
- if (Array.isArray(suggestions)) {
265
- suggestionsConfig = {
266
- suggestions,
267
- available: "always",
268
- };
269
- } else if (suggestions === "auto") {
270
- suggestionsConfig = {
271
- available: suggestions === "auto" ? "always" : "disabled",
272
- instructions:
273
- "Suggest what the user could say next. Provide clear, highly relevant suggestions. Do not literally suggest function calls.",
274
- };
275
- } else {
276
- suggestionsConfig = { available: "disabled" } as UseCopilotChatSuggestionsConfiguration;
277
- }
278
-
279
- useConfigureChatSuggestions(suggestionsConfig);
280
- }
281
-
282
273
  export function useCopilotChatInternal({
283
274
  suggestions,
284
275
  }: UseCopilotChatOptions = {}): UseCopilotChatReturn {
@@ -286,7 +277,6 @@ export function useCopilotChatInternal({
286
277
  const { threadId, agentSession } = useCopilotContext();
287
278
  const existingConfig = useCopilotChatConfiguration();
288
279
  const [agentAvailable, setAgentAvailable] = useState(false);
289
- useConfigureSuggestions(suggestions);
290
280
 
291
281
  // Apply priority: props > existing config > defaults
292
282
  const resolvedAgentId = existingConfig?.agentId ?? "default";
@@ -523,6 +513,16 @@ export function useCopilotChatInternal({
523
513
  resolvedAgentId,
524
514
  ]);
525
515
 
516
+ const renderedSuggestions = useMemo(() => {
517
+ if (Array.isArray(suggestions)) {
518
+ return {
519
+ suggestions: suggestions.map((s) => ({ ...s, isLoading: false })),
520
+ isLoading: false,
521
+ };
522
+ }
523
+ return currentSuggestions;
524
+ }, [suggestions, currentSuggestions]);
525
+
526
526
  // @ts-ignore
527
527
  return {
528
528
  messages: resolvedMessages,
@@ -537,12 +537,12 @@ export function useCopilotChatInternal({
537
537
  isLoading: Boolean(agent?.isRunning),
538
538
  // mcpServers,
539
539
  // setMcpServers,
540
- suggestions: currentSuggestions.suggestions,
540
+ suggestions: renderedSuggestions.suggestions,
541
541
  setSuggestions: (suggestions: Omit<Suggestion, "isLoading">[]) =>
542
542
  copilotkit.addSuggestionsConfig({ suggestions }),
543
543
  generateSuggestions: async () => copilotkit.reloadSuggestions(resolvedAgentId),
544
544
  resetSuggestions: () => copilotkit.clearSuggestions(resolvedAgentId),
545
- isLoadingSuggestions: currentSuggestions.isLoading,
545
+ isLoadingSuggestions: renderedSuggestions.isLoading,
546
546
  interrupt,
547
547
  agent,
548
548
  threadId,
@@ -64,8 +64,6 @@
64
64
  import { useCopilotKit } from "@copilotkitnext/react";
65
65
  import { useEffect, useRef } from "react";
66
66
 
67
- type DataType = object | number | string | boolean | null | undefined;
68
-
69
67
  /**
70
68
  * Options for the useCopilotReadable hook.
71
69
  */
@@ -77,7 +75,7 @@ export interface UseCopilotReadableOptions {
77
75
  /**
78
76
  * The value to be added to the Copilot context. Object values are automatically stringified.
79
77
  */
80
- value: DataType | Record<string, any> | DataType[];
78
+ value: any;
81
79
  /**
82
80
  * The ID of the parent context, if any.
83
81
  */
@@ -97,7 +95,7 @@ export interface UseCopilotReadableOptions {
97
95
  * A custom conversion function to use to serialize the value to a string. If not provided, the value
98
96
  * will be serialized using `JSON.stringify`.
99
97
  */
100
- convert?: (value: any) => string;
98
+ convert?: (description: string, value: any) => string;
101
99
  }
102
100
 
103
101
  /**
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/hooks/use-copilot-chat_internal.ts","../../../node_modules/.pnpm/@ag-ui+core@0.0.42/node_modules/@ag-ui/core/src/types.ts","../../../node_modules/.pnpm/@ag-ui+core@0.0.42/node_modules/@ag-ui/core/src/events.ts"],"sourcesContent":["import { useRef, useEffect, useCallback, useMemo, useState, createElement } from \"react\";\nimport { useCopilotContext } from \"../context/copilot-context\";\nimport { SystemMessageFunction } from \"../types\";\nimport { useAsyncCallback } from \"../components/error-boundary/error-utils\";\nimport { Message } from \"@copilotkit/shared\";\nimport { gqlToAGUI, Message as DeprecatedGqlMessage } from \"@copilotkit/runtime-client-gql\";\nimport { useLangGraphInterruptRender } from \"./use-langgraph-interrupt-render\";\nimport {\n useAgent,\n useCopilotChatConfiguration,\n useCopilotKit,\n useRenderCustomMessages,\n useSuggestions,\n} from \"@copilotkitnext/react\";\nimport { Suggestion } from \"@copilotkitnext/core\";\nimport { useLazyToolRenderer } from \"./use-lazy-tool-renderer\";\nimport {\n useConfigureChatSuggestions,\n UseCopilotChatSuggestionsConfiguration,\n} from \"./use-configure-chat-suggestions\";\nimport { AbstractAgent, AGUIConnectNotImplementedError } from \"@ag-ui/client\";\nimport {\n CoAgentStateRenderBridge,\n type CoAgentStateRenderBridgeProps,\n} from \"./use-coagent-state-render-bridge\";\n\n/**\n * The type of suggestions to use in the chat.\n *\n * `auto` - Suggestions are generated automatically.\n * `manual` - Suggestions are controlled programmatically.\n * `SuggestionItem[]` - Static suggestions array.\n */\nexport type ChatSuggestions = \"auto\" | \"manual\" | Omit<Suggestion, \"isLoading\">[];\n\nexport interface AppendMessageOptions {\n /**\n * Whether to run the chat completion after appending the message. Defaults to `true`.\n */\n followUp?: boolean;\n /**\n * Whether to clear the suggestions after appending the message. Defaults to `true`.\n */\n clearSuggestions?: boolean;\n}\n\nexport interface UseCopilotChatOptions {\n /**\n * A unique identifier for the chat. If not provided, a random one will be\n * generated. When provided, the `useChat` hook with the same `id` will\n * have shared states across components.\n */\n id?: string;\n\n /**\n * HTTP headers to be sent with the API request.\n */\n headers?: Record<string, string> | Headers;\n\n /**\n * Initial messages to populate the chat with.\n */\n initialMessages?: Message[];\n\n /**\n * A function to generate the system message. Defaults to `defaultSystemMessage`.\n */\n makeSystemMessage?: SystemMessageFunction;\n\n /**\n * Disables inclusion of CopilotKit’s default system message. When true, no system message is sent (this also suppresses any custom message from <code>makeSystemMessage</code>).\n */\n disableSystemMessage?: boolean;\n\n suggestions?: ChatSuggestions;\n}\n\nexport interface MCPServerConfig {\n endpoint: string;\n apiKey?: string;\n}\n\n// Old suggestion item interface, for returning from useCopilotChatInternal\ninterface SuggestionItem {\n title: string;\n message: string;\n partial?: boolean;\n className?: string;\n}\n\nexport interface UseCopilotChatReturn {\n /**\n * @deprecated use `messages` instead, this is an old non ag-ui version of the messages\n * Array of messages currently visible in the chat interface\n *\n * This is the visible messages, not the raw messages from the runtime client.\n */\n visibleMessages: DeprecatedGqlMessage[];\n\n /**\n * The messages that are currently in the chat in AG-UI format.\n */\n messages: Message[];\n\n /** @deprecated use `sendMessage` in `useCopilotChatHeadless_c` instead. This will be removed in a future major version. */\n appendMessage: (message: DeprecatedGqlMessage, options?: AppendMessageOptions) => Promise<void>;\n\n /**\n * Send a new message to the chat\n *\n * ```tsx\n * await sendMessage({\n * id: \"123\",\n * role: \"user\",\n * content: \"Hello, process this request\",\n * });\n * ```\n */\n sendMessage: (message: Message, options?: AppendMessageOptions) => Promise<void>;\n\n /**\n * Replace all messages in the chat\n *\n * ```tsx\n * setMessages([\n * { id: \"123\", role: \"user\", content: \"Hello, process this request\" },\n * { id: \"456\", role: \"assistant\", content: \"Hello, I'm the assistant\" },\n * ]);\n * ```\n *\n * **Deprecated** non-ag-ui version:\n *\n * ```tsx\n * setMessages([\n * new TextMessage({\n * content: \"Hello, process this request\",\n * role: gqlRole.User,\n * }),\n * new TextMessage({\n * content: \"Hello, I'm the assistant\",\n * role: gqlRole.Assistant,\n * ]);\n * ```\n *\n */\n setMessages: (messages: Message[] | DeprecatedGqlMessage[]) => void;\n\n /**\n * Remove a specific message by ID\n *\n * ```tsx\n * deleteMessage(\"123\");\n * ```\n */\n deleteMessage: (messageId: string) => void;\n\n /**\n * Regenerate the response for a specific message\n *\n * ```tsx\n * reloadMessages(\"123\");\n * ```\n */\n reloadMessages: (messageId: string) => Promise<void>;\n\n /**\n * Stop the current message generation\n *\n * ```tsx\n * if (isLoading) {\n * stopGeneration();\n * }\n * ```\n */\n stopGeneration: () => void;\n\n /**\n * Clear all messages and reset chat state\n *\n * ```tsx\n * reset();\n * console.log(messages); // []\n * ```\n */\n reset: () => void;\n\n /**\n * Whether the chat is currently generating a response\n *\n * ```tsx\n * if (isLoading) {\n * console.log(\"Loading...\");\n * } else {\n * console.log(\"Not loading\");\n * }\n */\n isLoading: boolean;\n\n /**\n * Whether the chat agent is available to generate responses\n *\n * ```tsx\n * if (isAvailable) {\n * console.log(\"Loading...\");\n * } else {\n * console.log(\"Not loading\");\n * }\n */\n isAvailable: boolean;\n\n /** Manually trigger chat completion (advanced usage) */\n runChatCompletion: () => Promise<Message[]>;\n\n /** MCP (Model Context Protocol) server configurations */\n mcpServers: MCPServerConfig[];\n\n /** Update MCP server configurations */\n setMcpServers: (mcpServers: MCPServerConfig[]) => void;\n\n /**\n * Current suggestions array\n * Use this to read the current suggestions or in conjunction with setSuggestions for manual control\n */\n suggestions: Suggestion[];\n\n /**\n * Manually set suggestions\n * Useful for manual mode or custom suggestion workflows\n */\n setSuggestions: (suggestions: Omit<Suggestion, \"isLoading\">[]) => void;\n\n /**\n * Trigger AI-powered suggestion generation\n * Uses configurations from useCopilotChatSuggestions hooks\n * Respects global debouncing - only one generation can run at a time\n *\n * ```tsx\n * generateSuggestions();\n * console.log(suggestions); // [suggestion1, suggestion2, suggestion3]\n * ```\n */\n generateSuggestions: () => Promise<void>;\n\n /**\n * Clear all current suggestions\n * Also resets suggestion generation state\n */\n resetSuggestions: () => void;\n\n /** Whether suggestions are currently being generated */\n isLoadingSuggestions: boolean;\n\n /** Interrupt content for human-in-the-loop workflows */\n interrupt: string | React.ReactElement | null;\n\n agent?: ReturnType<typeof useAgent>[\"agent\"];\n\n threadId?: string;\n}\n\nfunction useConfigureSuggestions(suggestions?: UseCopilotChatOptions[\"suggestions\"]) {\n let suggestionsConfig: UseCopilotChatSuggestionsConfiguration;\n\n if (Array.isArray(suggestions)) {\n suggestionsConfig = {\n suggestions,\n available: \"always\",\n };\n } else if (suggestions === \"auto\") {\n suggestionsConfig = {\n available: suggestions === \"auto\" ? \"always\" : \"disabled\",\n instructions:\n \"Suggest what the user could say next. Provide clear, highly relevant suggestions. Do not literally suggest function calls.\",\n };\n } else {\n suggestionsConfig = { available: \"disabled\" } as UseCopilotChatSuggestionsConfiguration;\n }\n\n useConfigureChatSuggestions(suggestionsConfig);\n}\n\nexport function useCopilotChatInternal({\n suggestions,\n}: UseCopilotChatOptions = {}): UseCopilotChatReturn {\n const { copilotkit } = useCopilotKit();\n const { threadId, agentSession } = useCopilotContext();\n const existingConfig = useCopilotChatConfiguration();\n const [agentAvailable, setAgentAvailable] = useState(false);\n useConfigureSuggestions(suggestions);\n\n // Apply priority: props > existing config > defaults\n const resolvedAgentId = existingConfig?.agentId ?? \"default\";\n const { agent } = useAgent({ agentId: resolvedAgentId });\n\n useEffect(() => {\n const connect = async (agent: AbstractAgent) => {\n setAgentAvailable(false);\n try {\n await copilotkit.connectAgent({ agent });\n setAgentAvailable(true);\n } catch (error) {\n if (error instanceof AGUIConnectNotImplementedError) {\n // connect not implemented, ignore\n } else {\n throw error;\n }\n }\n };\n if (agent && existingConfig?.threadId && agent.threadId !== existingConfig.threadId) {\n agent.threadId = existingConfig.threadId;\n connect(agent);\n }\n return () => {};\n }, [existingConfig?.threadId, agent, copilotkit, resolvedAgentId]);\n\n const interrupt = useLangGraphInterruptRender(agent);\n\n const reset = () => {\n agent?.setMessages([]);\n agent?.setState(null);\n };\n\n const deleteMessage = useCallback(\n (messageId: string) => {\n const filteredMessages = (agent?.messages ?? []).filter(\n (message) => message.id !== messageId,\n );\n agent?.setMessages(filteredMessages);\n },\n [agent?.setMessages, agent?.messages],\n );\n\n const latestDelete = useUpdatedRef(deleteMessage);\n const latestDeleteFunc = useCallback(\n (messageId: string) => {\n return latestDelete.current(messageId);\n },\n [latestDelete],\n );\n\n const currentSuggestions = useSuggestions({ agentId: resolvedAgentId });\n\n const reload = useAsyncCallback(\n async (reloadMessageId: string): Promise<void> => {\n const messages = agent?.messages ?? [];\n // TODO: get isLoading\n const isLoading = false;\n if (isLoading || messages.length === 0) {\n return;\n }\n\n const reloadMessageIndex = messages.findIndex((msg) => msg.id === reloadMessageId);\n if (reloadMessageIndex === -1) {\n console.warn(`Message with id ${reloadMessageId} not found`);\n return;\n }\n\n const reloadMessageRole = messages[reloadMessageIndex].role;\n if (reloadMessageRole !== \"assistant\") {\n console.warn(`Regenerate cannot be performed on ${reloadMessageRole} role`);\n return;\n }\n let historyCutoff: Message[] = [messages[0]];\n\n if (messages.length > 2 && reloadMessageIndex !== 0) {\n // message to regenerate from is now first.\n // Work backwards to find the first the closest user message\n const lastUserMessageBeforeRegenerate = messages\n .slice(0, reloadMessageIndex)\n .reverse()\n .find((msg) => msg.role === \"user\");\n\n if (!lastUserMessageBeforeRegenerate) {\n historyCutoff = [messages[0]];\n } else {\n const indexOfLastUserMessageBeforeRegenerate = messages.findIndex(\n (msg) => msg.id === lastUserMessageBeforeRegenerate.id,\n );\n // Include the user message, remove everything after it\n historyCutoff = messages.slice(0, indexOfLastUserMessageBeforeRegenerate + 1);\n }\n } else if (messages.length > 2 && reloadMessageIndex === 0) {\n historyCutoff = [messages[0], messages[1]];\n }\n\n agent?.setMessages(historyCutoff);\n\n if (agent) {\n copilotkit.runAgent({ agent });\n }\n return;\n },\n [agent?.setMessages, copilotkit?.runAgent],\n );\n\n const latestSendMessageFunc = useAsyncCallback(\n async (message: Message, options?: AppendMessageOptions) => {\n if (!agent) return;\n const followUp = options?.followUp ?? true;\n if (options?.clearSuggestions) {\n copilotkit.clearSuggestions(resolvedAgentId);\n }\n agent?.addMessage(message);\n if (followUp) {\n try {\n await copilotkit.runAgent({ agent });\n } catch (error) {\n console.error(\"CopilotChat: runAgent failed\", error);\n }\n }\n },\n [agent, copilotkit, resolvedAgentId],\n );\n\n const latestAppendFunc = useAsyncCallback(\n async (message: DeprecatedGqlMessage, options?: AppendMessageOptions) => {\n return latestSendMessageFunc(gqlToAGUI([message])[0], options);\n },\n [latestSendMessageFunc],\n );\n\n const latestSetMessagesFunc = useCallback(\n (messages: Message[] | DeprecatedGqlMessage[]) => {\n if (messages.every((message) => message instanceof DeprecatedGqlMessage)) {\n return agent?.setMessages?.(gqlToAGUI(messages));\n }\n return agent?.setMessages?.(messages);\n },\n [agent?.setMessages, agent],\n );\n\n const latestReload = useUpdatedRef(reload);\n const latestReloadFunc = useAsyncCallback(\n async (messageId: string) => {\n return await latestReload.current(messageId);\n },\n [latestReload],\n );\n\n const latestStopFunc = useCallback(() => {\n return agent?.abortRun?.();\n }, [agent?.abortRun]);\n\n const latestReset = useUpdatedRef(reset);\n const latestResetFunc = useCallback(() => {\n return latestReset.current();\n }, [latestReset]);\n\n const lazyToolRendered = useLazyToolRenderer();\n const renderCustomMessage = useRenderCustomMessages();\n const legacyCustomMessageRenderer = useLegacyCoagentRenderer({\n copilotkit,\n agent,\n agentId: resolvedAgentId,\n threadId: existingConfig?.threadId ?? threadId,\n });\n const allMessages = agent?.messages ?? [];\n const resolvedMessages = useMemo(() => {\n let processedMessages = allMessages.map((message) => {\n if (message.role !== \"assistant\") {\n return message;\n }\n\n const lazyRendered = lazyToolRendered(message, allMessages);\n if (lazyRendered) {\n const renderedGenUi = lazyRendered();\n if (renderedGenUi) {\n return { ...message, generativeUI: () => renderedGenUi };\n }\n }\n\n const bridgeRenderer =\n legacyCustomMessageRenderer || renderCustomMessage\n ? () => {\n const customRender = renderCustomMessage?.({\n message,\n position: \"before\",\n });\n if (customRender) {\n return customRender;\n }\n return legacyCustomMessageRenderer?.({ message, position: \"before\" });\n }\n : null;\n\n if (bridgeRenderer) {\n return { ...message, generativeUI: bridgeRenderer };\n }\n return message;\n });\n\n const hasAssistantMessages = processedMessages.some((msg) => msg.role === \"assistant\");\n\n // TODO: what is this?\n // if (legacyCustomMessageRenderer && !hasAssistantMessages) {\n // const placeholderId = `coagent-state-render-${resolvedAgentId}`;\n // const placeholderMessage: Message = {\n // id: placeholderId,\n // role: \"assistant\",\n // content: \"\",\n // name: \"coagent-state-render\",\n // };\n // processedMessages = [\n // ...processedMessages,\n // {\n // ...placeholderMessage,\n // generativeUI: () =>\n // legacyCustomMessageRenderer({\n // message: placeholderMessage,\n // position: \"before\",\n // }),\n // } as Message,\n // ];\n // }\n\n return processedMessages;\n }, [\n agent?.messages,\n lazyToolRendered,\n allMessages,\n renderCustomMessage,\n // legacyCustomMessageRenderer,\n resolvedAgentId,\n ]);\n\n // @ts-ignore\n return {\n messages: resolvedMessages,\n sendMessage: latestSendMessageFunc,\n appendMessage: latestAppendFunc,\n setMessages: latestSetMessagesFunc,\n reloadMessages: latestReloadFunc,\n stopGeneration: latestStopFunc,\n reset: latestResetFunc,\n deleteMessage: latestDeleteFunc,\n isAvailable: agentAvailable,\n isLoading: Boolean(agent?.isRunning),\n // mcpServers,\n // setMcpServers,\n suggestions: currentSuggestions.suggestions,\n setSuggestions: (suggestions: Omit<Suggestion, \"isLoading\">[]) =>\n copilotkit.addSuggestionsConfig({ suggestions }),\n generateSuggestions: async () => copilotkit.reloadSuggestions(resolvedAgentId),\n resetSuggestions: () => copilotkit.clearSuggestions(resolvedAgentId),\n isLoadingSuggestions: currentSuggestions.isLoading,\n interrupt,\n agent,\n threadId,\n };\n}\n\n// store `value` in a ref and update\n// it whenever it changes.\nfunction useUpdatedRef<T>(value: T) {\n const ref = useRef(value);\n\n useEffect(() => {\n ref.current = value;\n }, [value]);\n\n return ref;\n}\n\ntype LegacyRenderParams = {\n message: Message;\n position: \"before\" | \"after\";\n};\n\ntype LegacyRenderer = ((args: LegacyRenderParams) => any) | null;\n\nfunction useLegacyCoagentRenderer({\n copilotkit,\n agent,\n agentId,\n threadId,\n}: {\n copilotkit: ReturnType<typeof useCopilotKit>[\"copilotkit\"];\n agent?: AbstractAgent;\n agentId: string;\n threadId?: string;\n}): LegacyRenderer {\n return useMemo(() => {\n if (!copilotkit || !agent) {\n return null;\n }\n\n return ({ message, position }: LegacyRenderParams) => {\n const effectiveThreadId = threadId ?? agent.threadId ?? \"default\";\n const existingRunId = copilotkit.getRunIdForMessage(agentId, effectiveThreadId, message.id);\n const runId = existingRunId || `pending:${message.id}`;\n const messageIndex = Math.max(\n agent.messages.findIndex((msg) => msg.id === message.id),\n 0,\n );\n\n const bridgeProps: CoAgentStateRenderBridgeProps = {\n message: message as any,\n position,\n runId,\n messageIndex,\n messageIndexInRun: 0,\n numberOfMessagesInRun: 1,\n agentId,\n stateSnapshot: (message as any).state,\n };\n\n return createElement(CoAgentStateRenderBridge, bridgeProps) as any;\n };\n }, [agent, agentId, copilotkit, threadId]);\n}\n\nexport function defaultSystemMessage(\n contextString: string,\n additionalInstructions?: string,\n): string {\n return (\n `\nPlease act as an efficient, competent, conscientious, and industrious professional assistant.\n\nHelp the user achieve their goals, and you do so in a way that is as efficient as possible, without unnecessary fluff, but also without sacrificing professionalism.\nAlways be polite and respectful, and prefer brevity over verbosity.\n\nThe user has provided you with the following context:\n\\`\\`\\`\n${contextString}\n\\`\\`\\`\n\nThey have also provided you with functions you can call to initiate actions on their behalf, or functions you can call to receive more information.\n\nPlease assist them as best you can.\n\nYou can ask them for clarifying questions if needed, but don't be annoying about it. If you can reasonably 'fill in the blanks' yourself, do so.\n\nIf you would like to call a function, call it without saying anything else.\nIn case of a function error:\n- If this error stems from incorrect function parameters or syntax, you may retry with corrected arguments.\n- If the error's source is unclear or seems unrelated to your input, do not attempt further retries.\n` + (additionalInstructions ? `\\n\\n${additionalInstructions}` : \"\")\n );\n}\n","import { z } from \"zod\";\n\nexport const FunctionCallSchema = z.object({\n name: z.string(),\n arguments: z.string(),\n});\n\nexport const ToolCallSchema = z.object({\n id: z.string(),\n type: z.literal(\"function\"),\n function: FunctionCallSchema,\n});\n\nexport const BaseMessageSchema = z.object({\n id: z.string(),\n role: z.string(),\n content: z.string().optional(),\n name: z.string().optional(),\n});\n\nexport const TextInputContentSchema = z.object({\n type: z.literal(\"text\"),\n text: z.string(),\n});\n\nconst BinaryInputContentObjectSchema = z.object({\n type: z.literal(\"binary\"),\n mimeType: z.string(),\n id: z.string().optional(),\n url: z.string().optional(),\n data: z.string().optional(),\n filename: z.string().optional(),\n});\n\nconst ensureBinaryPayload = (\n value: { id?: string; url?: string; data?: string },\n ctx: z.RefinementCtx,\n) => {\n if (!value.id && !value.url && !value.data) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: \"BinaryInputContent requires at least one of id, url, or data.\",\n path: [\"id\"],\n });\n }\n};\n\nexport const BinaryInputContentSchema = BinaryInputContentObjectSchema.superRefine((value, ctx) => {\n ensureBinaryPayload(value, ctx);\n});\n\nconst InputContentBaseSchema = z.discriminatedUnion(\"type\", [\n TextInputContentSchema,\n BinaryInputContentObjectSchema,\n]);\n\nexport const InputContentSchema = InputContentBaseSchema.superRefine((value, ctx) => {\n if (value.type === \"binary\") {\n ensureBinaryPayload(value, ctx);\n }\n});\n\nexport const DeveloperMessageSchema = BaseMessageSchema.extend({\n role: z.literal(\"developer\"),\n content: z.string(),\n});\n\nexport const SystemMessageSchema = BaseMessageSchema.extend({\n role: z.literal(\"system\"),\n content: z.string(),\n});\n\nexport const AssistantMessageSchema = BaseMessageSchema.extend({\n role: z.literal(\"assistant\"),\n content: z.string().optional(),\n toolCalls: z.array(ToolCallSchema).optional(),\n});\n\nexport const UserMessageSchema = BaseMessageSchema.extend({\n role: z.literal(\"user\"),\n content: z.union([z.string(), z.array(InputContentSchema)]),\n});\n\nexport const ToolMessageSchema = z.object({\n id: z.string(),\n content: z.string(),\n role: z.literal(\"tool\"),\n toolCallId: z.string(),\n error: z.string().optional(),\n});\n\nexport const ActivityMessageSchema = z.object({\n id: z.string(),\n role: z.literal(\"activity\"),\n activityType: z.string(),\n content: z.record(z.any()),\n});\n\nexport const MessageSchema = z.discriminatedUnion(\"role\", [\n DeveloperMessageSchema,\n SystemMessageSchema,\n AssistantMessageSchema,\n UserMessageSchema,\n ToolMessageSchema,\n ActivityMessageSchema,\n]);\n\nexport const RoleSchema = z.union([\n z.literal(\"developer\"),\n z.literal(\"system\"),\n z.literal(\"assistant\"),\n z.literal(\"user\"),\n z.literal(\"tool\"),\n z.literal(\"activity\"),\n]);\n\nexport const ContextSchema = z.object({\n description: z.string(),\n value: z.string(),\n});\n\nexport const ToolSchema = z.object({\n name: z.string(),\n description: z.string(),\n parameters: z.any(), // JSON Schema for the tool parameters\n});\n\nexport const RunAgentInputSchema = z.object({\n threadId: z.string(),\n runId: z.string(),\n parentRunId: z.string().optional(),\n state: z.any(),\n messages: z.array(MessageSchema),\n tools: z.array(ToolSchema),\n context: z.array(ContextSchema),\n forwardedProps: z.any(),\n});\n\nexport const StateSchema = z.any();\n\nexport type ToolCall = z.infer<typeof ToolCallSchema>;\nexport type FunctionCall = z.infer<typeof FunctionCallSchema>;\nexport type TextInputContent = z.infer<typeof TextInputContentSchema>;\nexport type BinaryInputContent = z.infer<typeof BinaryInputContentSchema>;\nexport type InputContent = z.infer<typeof InputContentSchema>;\nexport type DeveloperMessage = z.infer<typeof DeveloperMessageSchema>;\nexport type SystemMessage = z.infer<typeof SystemMessageSchema>;\nexport type AssistantMessage = z.infer<typeof AssistantMessageSchema>;\nexport type UserMessage = z.infer<typeof UserMessageSchema>;\nexport type ToolMessage = z.infer<typeof ToolMessageSchema>;\nexport type ActivityMessage = z.infer<typeof ActivityMessageSchema>;\nexport type Message = z.infer<typeof MessageSchema>;\nexport type Context = z.infer<typeof ContextSchema>;\nexport type Tool = z.infer<typeof ToolSchema>;\nexport type RunAgentInput = z.infer<typeof RunAgentInputSchema>;\nexport type State = z.infer<typeof StateSchema>;\nexport type Role = z.infer<typeof RoleSchema>;\n\nexport class AGUIError extends Error {\n constructor(message: string) {\n super(message);\n }\n}\n\nexport class AGUIConnectNotImplementedError extends AGUIError {\n constructor() {\n super(\"Connect not implemented. This method is not supported by the current agent.\");\n }\n}\n","import { z } from \"zod\";\nimport { MessageSchema, StateSchema, RunAgentInputSchema } from \"./types\";\n\n// Text messages can have any role except \"tool\"\nconst TextMessageRoleSchema = z.union([\n z.literal(\"developer\"),\n z.literal(\"system\"),\n z.literal(\"assistant\"),\n z.literal(\"user\"),\n]);\n\nexport enum EventType {\n TEXT_MESSAGE_START = \"TEXT_MESSAGE_START\",\n TEXT_MESSAGE_CONTENT = \"TEXT_MESSAGE_CONTENT\",\n TEXT_MESSAGE_END = \"TEXT_MESSAGE_END\",\n TEXT_MESSAGE_CHUNK = \"TEXT_MESSAGE_CHUNK\",\n THINKING_TEXT_MESSAGE_START = \"THINKING_TEXT_MESSAGE_START\",\n THINKING_TEXT_MESSAGE_CONTENT = \"THINKING_TEXT_MESSAGE_CONTENT\",\n THINKING_TEXT_MESSAGE_END = \"THINKING_TEXT_MESSAGE_END\",\n TOOL_CALL_START = \"TOOL_CALL_START\",\n TOOL_CALL_ARGS = \"TOOL_CALL_ARGS\",\n TOOL_CALL_END = \"TOOL_CALL_END\",\n TOOL_CALL_CHUNK = \"TOOL_CALL_CHUNK\",\n TOOL_CALL_RESULT = \"TOOL_CALL_RESULT\",\n THINKING_START = \"THINKING_START\",\n THINKING_END = \"THINKING_END\",\n STATE_SNAPSHOT = \"STATE_SNAPSHOT\",\n STATE_DELTA = \"STATE_DELTA\",\n MESSAGES_SNAPSHOT = \"MESSAGES_SNAPSHOT\",\n ACTIVITY_SNAPSHOT = \"ACTIVITY_SNAPSHOT\",\n ACTIVITY_DELTA = \"ACTIVITY_DELTA\",\n RAW = \"RAW\",\n CUSTOM = \"CUSTOM\",\n RUN_STARTED = \"RUN_STARTED\",\n RUN_FINISHED = \"RUN_FINISHED\",\n RUN_ERROR = \"RUN_ERROR\",\n STEP_STARTED = \"STEP_STARTED\",\n STEP_FINISHED = \"STEP_FINISHED\",\n}\n\nexport const BaseEventSchema = z.object({\n type: z.nativeEnum(EventType),\n timestamp: z.number().optional(),\n rawEvent: z.any().optional(),\n});\n\nexport const TextMessageStartEventSchema = BaseEventSchema.extend({\n type: z.literal(EventType.TEXT_MESSAGE_START),\n messageId: z.string(),\n role: TextMessageRoleSchema.default(\"assistant\"),\n});\n\nexport const TextMessageContentEventSchema = BaseEventSchema.extend({\n type: z.literal(EventType.TEXT_MESSAGE_CONTENT),\n messageId: z.string(),\n delta: z.string().refine((s) => s.length > 0, \"Delta must not be an empty string\"),\n});\n\nexport const TextMessageEndEventSchema = BaseEventSchema.extend({\n type: z.literal(EventType.TEXT_MESSAGE_END),\n messageId: z.string(),\n});\n\nexport const TextMessageChunkEventSchema = BaseEventSchema.extend({\n type: z.literal(EventType.TEXT_MESSAGE_CHUNK),\n messageId: z.string().optional(),\n role: TextMessageRoleSchema.optional(),\n delta: z.string().optional(),\n});\n\nexport const ThinkingTextMessageStartEventSchema = BaseEventSchema.extend({\n type: z.literal(EventType.THINKING_TEXT_MESSAGE_START),\n});\n\nexport const ThinkingTextMessageContentEventSchema = TextMessageContentEventSchema.omit({\n messageId: true,\n type: true,\n}).extend({\n type: z.literal(EventType.THINKING_TEXT_MESSAGE_CONTENT),\n});\n\nexport const ThinkingTextMessageEndEventSchema = BaseEventSchema.extend({\n type: z.literal(EventType.THINKING_TEXT_MESSAGE_END),\n});\n\nexport const ToolCallStartEventSchema = BaseEventSchema.extend({\n type: z.literal(EventType.TOOL_CALL_START),\n toolCallId: z.string(),\n toolCallName: z.string(),\n parentMessageId: z.string().optional(),\n});\n\nexport const ToolCallArgsEventSchema = BaseEventSchema.extend({\n type: z.literal(EventType.TOOL_CALL_ARGS),\n toolCallId: z.string(),\n delta: z.string(),\n});\n\nexport const ToolCallEndEventSchema = BaseEventSchema.extend({\n type: z.literal(EventType.TOOL_CALL_END),\n toolCallId: z.string(),\n});\n\nexport const ToolCallResultEventSchema = BaseEventSchema.extend({\n messageId: z.string(),\n type: z.literal(EventType.TOOL_CALL_RESULT),\n toolCallId: z.string(),\n content: z.string(),\n role: z.literal(\"tool\").optional(),\n});\n\nexport const ToolCallChunkEventSchema = BaseEventSchema.extend({\n type: z.literal(EventType.TOOL_CALL_CHUNK),\n toolCallId: z.string().optional(),\n toolCallName: z.string().optional(),\n parentMessageId: z.string().optional(),\n delta: z.string().optional(),\n});\n\nexport const ThinkingStartEventSchema = BaseEventSchema.extend({\n type: z.literal(EventType.THINKING_START),\n title: z.string().optional(),\n});\n\nexport const ThinkingEndEventSchema = BaseEventSchema.extend({\n type: z.literal(EventType.THINKING_END),\n});\n\nexport const StateSnapshotEventSchema = BaseEventSchema.extend({\n type: z.literal(EventType.STATE_SNAPSHOT),\n snapshot: StateSchema,\n});\n\nexport const StateDeltaEventSchema = BaseEventSchema.extend({\n type: z.literal(EventType.STATE_DELTA),\n delta: z.array(z.any()), // JSON Patch (RFC 6902)\n});\n\nexport const MessagesSnapshotEventSchema = BaseEventSchema.extend({\n type: z.literal(EventType.MESSAGES_SNAPSHOT),\n messages: z.array(MessageSchema),\n});\n\nexport const ActivitySnapshotEventSchema = BaseEventSchema.extend({\n type: z.literal(EventType.ACTIVITY_SNAPSHOT),\n messageId: z.string(),\n activityType: z.string(),\n content: z.record(z.any()),\n replace: z.boolean().optional().default(true),\n});\n\nexport const ActivityDeltaEventSchema = BaseEventSchema.extend({\n type: z.literal(EventType.ACTIVITY_DELTA),\n messageId: z.string(),\n activityType: z.string(),\n patch: z.array(z.any()),\n});\n\nexport const RawEventSchema = BaseEventSchema.extend({\n type: z.literal(EventType.RAW),\n event: z.any(),\n source: z.string().optional(),\n});\n\nexport const CustomEventSchema = BaseEventSchema.extend({\n type: z.literal(EventType.CUSTOM),\n name: z.string(),\n value: z.any(),\n});\n\nexport const RunStartedEventSchema = BaseEventSchema.extend({\n type: z.literal(EventType.RUN_STARTED),\n threadId: z.string(),\n runId: z.string(),\n parentRunId: z.string().optional(),\n input: RunAgentInputSchema.optional(),\n});\n\nexport const RunFinishedEventSchema = BaseEventSchema.extend({\n type: z.literal(EventType.RUN_FINISHED),\n threadId: z.string(),\n runId: z.string(),\n result: z.any().optional(),\n});\n\nexport const RunErrorEventSchema = BaseEventSchema.extend({\n type: z.literal(EventType.RUN_ERROR),\n message: z.string(),\n code: z.string().optional(),\n});\n\nexport const StepStartedEventSchema = BaseEventSchema.extend({\n type: z.literal(EventType.STEP_STARTED),\n stepName: z.string(),\n});\n\nexport const StepFinishedEventSchema = BaseEventSchema.extend({\n type: z.literal(EventType.STEP_FINISHED),\n stepName: z.string(),\n});\n\nexport const EventSchemas = z.discriminatedUnion(\"type\", [\n TextMessageStartEventSchema,\n TextMessageContentEventSchema,\n TextMessageEndEventSchema,\n TextMessageChunkEventSchema,\n ThinkingStartEventSchema,\n ThinkingEndEventSchema,\n ThinkingTextMessageStartEventSchema,\n ThinkingTextMessageContentEventSchema,\n ThinkingTextMessageEndEventSchema,\n ToolCallStartEventSchema,\n ToolCallArgsEventSchema,\n ToolCallEndEventSchema,\n ToolCallChunkEventSchema,\n ToolCallResultEventSchema,\n StateSnapshotEventSchema,\n StateDeltaEventSchema,\n MessagesSnapshotEventSchema,\n ActivitySnapshotEventSchema,\n ActivityDeltaEventSchema,\n RawEventSchema,\n CustomEventSchema,\n RunStartedEventSchema,\n RunFinishedEventSchema,\n RunErrorEventSchema,\n StepStartedEventSchema,\n StepFinishedEventSchema,\n]);\n\nexport type BaseEvent = z.infer<typeof BaseEventSchema>;\nexport type TextMessageStartEvent = z.infer<typeof TextMessageStartEventSchema>;\nexport type TextMessageContentEvent = z.infer<typeof TextMessageContentEventSchema>;\nexport type TextMessageEndEvent = z.infer<typeof TextMessageEndEventSchema>;\nexport type TextMessageChunkEvent = z.infer<typeof TextMessageChunkEventSchema>;\nexport type ThinkingTextMessageStartEvent = z.infer<typeof ThinkingTextMessageStartEventSchema>;\nexport type ThinkingTextMessageContentEvent = z.infer<typeof ThinkingTextMessageContentEventSchema>;\nexport type ThinkingTextMessageEndEvent = z.infer<typeof ThinkingTextMessageEndEventSchema>;\nexport type ToolCallStartEvent = z.infer<typeof ToolCallStartEventSchema>;\nexport type ToolCallArgsEvent = z.infer<typeof ToolCallArgsEventSchema>;\nexport type ToolCallEndEvent = z.infer<typeof ToolCallEndEventSchema>;\nexport type ToolCallChunkEvent = z.infer<typeof ToolCallChunkEventSchema>;\nexport type ToolCallResultEvent = z.infer<typeof ToolCallResultEventSchema>;\nexport type ThinkingStartEvent = z.infer<typeof ThinkingStartEventSchema>;\nexport type ThinkingEndEvent = z.infer<typeof ThinkingEndEventSchema>;\nexport type StateSnapshotEvent = z.infer<typeof StateSnapshotEventSchema>;\nexport type StateDeltaEvent = z.infer<typeof StateDeltaEventSchema>;\nexport type MessagesSnapshotEvent = z.infer<typeof MessagesSnapshotEventSchema>;\nexport type ActivitySnapshotEvent = z.infer<typeof ActivitySnapshotEventSchema>;\nexport type ActivityDeltaEvent = z.infer<typeof ActivityDeltaEventSchema>;\nexport type RawEvent = z.infer<typeof RawEventSchema>;\nexport type CustomEvent = z.infer<typeof CustomEventSchema>;\nexport type RunStartedEvent = z.infer<typeof RunStartedEventSchema>;\nexport type RunFinishedEvent = z.infer<typeof RunFinishedEventSchema>;\nexport type RunErrorEvent = z.infer<typeof RunErrorEventSchema>;\nexport type StepStartedEvent = z.infer<typeof StepStartedEventSchema>;\nexport type StepFinishedEvent = z.infer<typeof StepFinishedEventSchema>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,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;AAAA,QACA,eAAgB,QAAgB;AAAA,MAClC;AAEA,aAAO,cAAc,0BAA0B,WAAW;AAAA,IAC5D;AAAA,EACF,GAAG,CAAC,OAAO,SAAS,YAAY,QAAQ,CAAC;AAC3C;AAEO,SAAS,qBACd,eACA,wBACQ;AACR,SACE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KAaG,yBAAyB;AAAA;AAAA,EAAO,2BAA2B;AAEhE;","names":["z","EventType","agent","_a","_b","suggestions"]}
@@ -1,48 +0,0 @@
1
- import {
2
- __spreadProps,
3
- __spreadValues
4
- } from "./chunk-SKC7AJIV.mjs";
5
-
6
- // src/hooks/use-configure-chat-suggestions.tsx
7
- import {
8
- useConfigureSuggestions,
9
- useCopilotChatConfiguration,
10
- useCopilotKit,
11
- useSuggestions
12
- } from "@copilotkitnext/react";
13
- import { useEffect } from "react";
14
- function useConfigureChatSuggestions(config, dependencies = []) {
15
- var _a;
16
- const existingConfig = useCopilotChatConfiguration();
17
- const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
18
- const { copilotkit } = useCopilotKit();
19
- const available = config.available === "enabled" ? "always" : config.available;
20
- const finalSuggestionConfig = __spreadProps(__spreadValues({}, config), {
21
- available,
22
- consumerAgentId: resolvedAgentId
23
- // Use chatConfig.agentId here
24
- });
25
- useConfigureSuggestions(finalSuggestionConfig, dependencies);
26
- const result = useSuggestions({ agentId: resolvedAgentId });
27
- useEffect(() => {
28
- if (finalSuggestionConfig.available === "disabled")
29
- return;
30
- const subscription = copilotkit.subscribe({
31
- onAgentsChanged: () => {
32
- const agent = copilotkit.getAgent(resolvedAgentId);
33
- if (agent && !agent.isRunning && !result.suggestions.length) {
34
- copilotkit.reloadSuggestions(resolvedAgentId);
35
- }
36
- }
37
- });
38
- return () => {
39
- subscription.unsubscribe();
40
- };
41
- }, [resolvedAgentId]);
42
- return result;
43
- }
44
-
45
- export {
46
- useConfigureChatSuggestions
47
- };
48
- //# sourceMappingURL=chunk-FBVI3LQ6.mjs.map