@copilotkit/react-core 1.10.0-next.9 → 1.10.0
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 +104 -0
- package/dist/{chunk-VH45SC6Z.mjs → chunk-2GRWTU7W.mjs} +2 -2
- package/dist/chunk-3BASANUO.mjs +170 -0
- package/dist/chunk-3BASANUO.mjs.map +1 -0
- package/dist/{chunk-PHIMGB3K.mjs → chunk-5P46WS5M.mjs} +25 -19
- package/dist/chunk-5P46WS5M.mjs.map +1 -0
- package/dist/{chunk-AWFAFFO5.mjs → chunk-6ZLPNY7X.mjs} +7 -3
- package/dist/chunk-6ZLPNY7X.mjs.map +1 -0
- package/dist/{chunk-TTI4Z6GK.mjs → chunk-BEFEBKKI.mjs} +7 -7
- package/dist/chunk-BEFEBKKI.mjs.map +1 -0
- package/dist/{chunk-VSH4JSN3.mjs → chunk-F26O2HTO.mjs} +13 -7
- package/dist/chunk-F26O2HTO.mjs.map +1 -0
- package/dist/{chunk-GRCHDHC4.mjs → chunk-JY3STRON.mjs} +22 -4
- package/dist/chunk-JY3STRON.mjs.map +1 -0
- package/dist/{chunk-ZTZJIDRJ.mjs → chunk-N4VN2B5S.mjs} +2 -2
- package/dist/{chunk-FTP6FDYS.mjs → chunk-NTH42BY5.mjs} +2 -2
- package/dist/chunk-PIF5KJYI.mjs +103 -0
- package/dist/chunk-PIF5KJYI.mjs.map +1 -0
- package/dist/chunk-WSXTUD36.mjs +759 -0
- package/dist/chunk-WSXTUD36.mjs.map +1 -0
- package/dist/chunk-YIBUNEBN.mjs +34 -0
- package/dist/chunk-YIBUNEBN.mjs.map +1 -0
- package/dist/components/copilot-provider/copilotkit-props.d.ts +9 -1
- package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.js +1052 -72
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +6 -3
- package/dist/components/copilot-provider/index.js +1052 -72
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +6 -3
- package/dist/components/dev-console/console-trigger.d.ts +8 -0
- package/dist/components/dev-console/console-trigger.js +1131 -0
- package/dist/components/dev-console/console-trigger.js.map +1 -0
- package/dist/components/dev-console/console-trigger.mjs +13 -0
- package/dist/components/dev-console/developer-console-modal.d.ts +10 -0
- package/dist/components/dev-console/developer-console-modal.js +977 -0
- package/dist/components/dev-console/developer-console-modal.js.map +1 -0
- package/dist/components/dev-console/developer-console-modal.mjs +12 -0
- package/dist/components/dev-console/developer-console-modal.mjs.map +1 -0
- package/dist/components/dev-console/icons.d.ts +9 -0
- package/dist/components/dev-console/icons.js +131 -0
- package/dist/components/dev-console/icons.js.map +1 -0
- package/dist/components/dev-console/icons.mjs +16 -0
- package/dist/components/dev-console/icons.mjs.map +1 -0
- package/dist/components/error-boundary/error-boundary.js +6 -2
- package/dist/components/error-boundary/error-boundary.js.map +1 -1
- package/dist/components/error-boundary/error-boundary.mjs +2 -2
- package/dist/components/index.js +1052 -72
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +6 -3
- package/dist/components/usage-banner.d.ts +2 -1
- package/dist/components/usage-banner.js +6 -2
- package/dist/components/usage-banner.js.map +1 -1
- package/dist/components/usage-banner.mjs +1 -1
- package/dist/hooks/index.d.ts +5 -5
- package/dist/hooks/index.js +58 -26
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +13 -10
- package/dist/hooks/use-coagent.d.ts +1 -1
- package/dist/hooks/use-coagent.js +18 -6
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +8 -5
- package/dist/hooks/use-copilot-chat-headless_c.d.ts +33 -0
- package/dist/hooks/{use-copilot-chat-light.js → use-copilot-chat-headless_c.js} +88 -19
- package/dist/hooks/use-copilot-chat-headless_c.js.map +1 -0
- package/dist/hooks/{use-copilot-chat-light.mjs → use-copilot-chat-headless_c.mjs} +14 -8
- package/dist/hooks/use-copilot-chat-headless_c.mjs.map +1 -0
- package/dist/hooks/use-copilot-chat.d.ts +85 -4
- package/dist/hooks/use-copilot-chat.js +38 -61
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +8 -8
- package/dist/hooks/use-copilot-chat_internal.d.ts +98 -12
- package/dist/hooks/use-copilot-chat_internal.js +13 -1
- package/dist/hooks/use-copilot-chat_internal.js.map +1 -1
- package/dist/hooks/use-copilot-chat_internal.mjs +7 -4
- package/dist/hooks/use-langgraph-interrupt.js +13 -1
- package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt.mjs +8 -5
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1203 -200
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +14 -11
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +7 -4
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +7 -4
- package/dist/utils/extract.js.map +1 -1
- package/dist/utils/extract.mjs +6 -3
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +6 -3
- package/dist/utils/suggestions.js.map +1 -1
- package/dist/utils/suggestions.mjs +6 -3
- package/package.json +3 -3
- package/src/components/copilot-provider/copilotkit-props.tsx +10 -1
- package/src/components/copilot-provider/copilotkit.tsx +25 -16
- package/src/components/dev-console/console-trigger.tsx +190 -0
- package/src/components/dev-console/developer-console-modal.tsx +866 -0
- package/src/components/dev-console/icons.tsx +101 -0
- package/src/components/usage-banner.tsx +8 -3
- package/src/hooks/index.ts +6 -7
- package/src/hooks/use-coagent.ts +6 -11
- package/src/hooks/use-copilot-chat-headless_c.ts +257 -0
- package/src/hooks/use-copilot-chat.ts +103 -154
- package/src/hooks/use-copilot-chat_internal.ts +122 -15
- package/dist/chunk-AWFAFFO5.mjs.map +0 -1
- package/dist/chunk-GRCHDHC4.mjs.map +0 -1
- package/dist/chunk-MWHILKQH.mjs +0 -18
- package/dist/chunk-MWHILKQH.mjs.map +0 -1
- package/dist/chunk-PHIMGB3K.mjs.map +0 -1
- package/dist/chunk-TTI4Z6GK.mjs.map +0 -1
- package/dist/chunk-VSH4JSN3.mjs.map +0 -1
- package/dist/hooks/use-copilot-chat-light.d.ts +0 -211
- package/dist/hooks/use-copilot-chat-light.js.map +0 -1
- package/src/hooks/use-copilot-chat-light.ts +0 -219
- /package/dist/{chunk-VH45SC6Z.mjs.map → chunk-2GRWTU7W.mjs.map} +0 -0
- /package/dist/{chunk-ZTZJIDRJ.mjs.map → chunk-N4VN2B5S.mjs.map} +0 -0
- /package/dist/{chunk-FTP6FDYS.mjs.map → chunk-NTH42BY5.mjs.map} +0 -0
- /package/dist/{hooks/use-copilot-chat-light.mjs.map → components/dev-console/console-trigger.mjs.map} +0 -0
|
@@ -1,178 +1,127 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `useCopilotChat` is a React hook
|
|
3
|
-
*
|
|
4
|
-
* programmatically interact with the Copilot instance managed by the default
|
|
5
|
-
* UI.
|
|
2
|
+
* `useCopilotChat` is a lightweight React hook for headless chat interactions.
|
|
3
|
+
* Perfect for controlling the prebuilt chat components programmatically.
|
|
6
4
|
*
|
|
7
|
-
* **
|
|
8
|
-
* to get your API key with generous usage limits.
|
|
5
|
+
* **Open Source Friendly** - Works without requiring a free public license key.
|
|
9
6
|
*
|
|
10
|
-
*
|
|
7
|
+
* <Callout title="Looking for fully headless UI?">
|
|
8
|
+
* Get started with [useCopilotChatHeadless_c](https://docs.copilotkit.ai/reference/hooks/useCopilotChatHeadless_c).
|
|
9
|
+
* </Callout>
|
|
10
|
+
*
|
|
11
|
+
* ## Use Cases
|
|
11
12
|
*
|
|
12
|
-
*
|
|
13
|
+
* - **Programmatic Messaging**: Send messages without displaying chat UI
|
|
14
|
+
* - **Programmatic control**: Control prebuilt component programmatically
|
|
15
|
+
* - **Background Operations**: Trigger AI interactions in the background
|
|
16
|
+
* - **Fire-and-Forget**: Send messages without needing to read responses
|
|
17
|
+
*
|
|
18
|
+
* ## Usage
|
|
13
19
|
*
|
|
14
20
|
* ```tsx
|
|
15
|
-
* import {
|
|
16
|
-
* import { useCopilotChat } from "@copilotkit/react-core";
|
|
17
|
-
* import { Role, TextMessage } from "@copilotkit/runtime-client-gql";
|
|
18
|
-
*
|
|
19
|
-
* export function App() {
|
|
20
|
-
* return (
|
|
21
|
-
* <CopilotKit publicApiKey="your-public-api-key">
|
|
22
|
-
* <YourComponent />
|
|
23
|
-
* </CopilotKit>
|
|
24
|
-
* );
|
|
25
|
-
* }
|
|
21
|
+
* import { TextMessage, MessageRole } from "@copilotkit/runtime-client-gql";
|
|
26
22
|
*
|
|
27
|
-
*
|
|
28
|
-
* const { appendMessage } = useCopilotChat();
|
|
23
|
+
* const { appendMessage } = useCopilotChat();
|
|
29
24
|
*
|
|
30
|
-
*
|
|
25
|
+
* // Example usage without naming conflicts
|
|
26
|
+
* const handleSendMessage = async (content: string) => {
|
|
27
|
+
* await appendMessage(
|
|
31
28
|
* new TextMessage({
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* })
|
|
29
|
+
* role: MessageRole.User,
|
|
30
|
+
* content,
|
|
31
|
+
* })
|
|
35
32
|
* );
|
|
36
|
-
*
|
|
37
|
-
* // optionally, you can append a message without running chat completion
|
|
38
|
-
* appendMessage(yourMessage, { followUp: false });
|
|
39
|
-
* }
|
|
33
|
+
* };
|
|
40
34
|
* ```
|
|
41
35
|
*
|
|
42
|
-
*
|
|
36
|
+
* ## Return Values
|
|
37
|
+
* The following properties are returned from the hook:
|
|
43
38
|
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* export function App() {
|
|
49
|
-
* return (
|
|
50
|
-
* <CopilotKit publicApiKey="your-public-api-key">
|
|
51
|
-
* <YourComponent />
|
|
52
|
-
* </CopilotKit>
|
|
53
|
-
* );
|
|
54
|
-
* }
|
|
55
|
-
*
|
|
56
|
-
* export function YourComponent() {
|
|
57
|
-
* const {
|
|
58
|
-
* suggestions,
|
|
59
|
-
* setSuggestions,
|
|
60
|
-
* generateSuggestions,
|
|
61
|
-
* isLoadingSuggestions
|
|
62
|
-
* } = useCopilotChat();
|
|
63
|
-
*
|
|
64
|
-
* // Configure AI suggestion generation
|
|
65
|
-
* useCopilotChatSuggestions({
|
|
66
|
-
* instructions: "Suggest helpful actions based on the current context",
|
|
67
|
-
* maxSuggestions: 3
|
|
68
|
-
* });
|
|
69
|
-
*
|
|
70
|
-
* // Manual suggestion control
|
|
71
|
-
* const handleCustomSuggestion = () => {
|
|
72
|
-
* setSuggestions([{ title: "Custom Action", message: "Perform custom action" }]);
|
|
73
|
-
* };
|
|
74
|
-
*
|
|
75
|
-
* // Trigger AI generation
|
|
76
|
-
* const handleGenerateSuggestions = async () => {
|
|
77
|
-
* await generateSuggestions();
|
|
78
|
-
* };
|
|
79
|
-
* }
|
|
80
|
-
* ```
|
|
39
|
+
* <PropertyReference name="visibleMessages" type="DeprecatedGqlMessage[]" deprecated>
|
|
40
|
+
* Array of messages in old non-AG-UI format, use for compatibility only
|
|
41
|
+
* </PropertyReference>
|
|
81
42
|
*
|
|
82
|
-
*
|
|
43
|
+
* <PropertyReference name="appendMessage" type="(message: DeprecatedGqlMessage, options?) => Promise<void>" deprecated>
|
|
44
|
+
* Append message using old format, use `sendMessage` instead
|
|
45
|
+
* </PropertyReference>
|
|
83
46
|
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
47
|
+
* <PropertyReference name="reloadMessages" type="(messageId: string) => Promise<void>">
|
|
48
|
+
* Regenerate the response for a specific message by ID
|
|
49
|
+
* </PropertyReference>
|
|
50
|
+
*
|
|
51
|
+
* <PropertyReference name="stopGeneration" type="() => void">
|
|
52
|
+
* Stop the current message generation process
|
|
53
|
+
* </PropertyReference>
|
|
54
|
+
*
|
|
55
|
+
* <PropertyReference name="reset" type="() => void">
|
|
56
|
+
* Clear all messages and reset chat state completely
|
|
57
|
+
* </PropertyReference>
|
|
58
|
+
*
|
|
59
|
+
* <PropertyReference name="isLoading" type="boolean">
|
|
60
|
+
* Whether the chat is currently generating a response
|
|
61
|
+
* </PropertyReference>
|
|
62
|
+
*
|
|
63
|
+
* <PropertyReference name="runChatCompletion" type="() => Promise<Message[]>">
|
|
64
|
+
* Manually trigger chat completion for advanced usage
|
|
65
|
+
* </PropertyReference>
|
|
66
|
+
*
|
|
67
|
+
* <PropertyReference name="mcpServers" type="MCPServerConfig[]">
|
|
68
|
+
* Array of Model Context Protocol server configurations
|
|
69
|
+
* </PropertyReference>
|
|
70
|
+
*
|
|
71
|
+
* <PropertyReference name="setMcpServers" type="(servers: MCPServerConfig[]) => void">
|
|
72
|
+
* Update MCP server configurations for enhanced context
|
|
73
|
+
* </PropertyReference>
|
|
103
74
|
*/
|
|
104
|
-
import { useEffect } from "react";
|
|
105
|
-
import { useCopilotContext } from "../context/copilot-context";
|
|
106
75
|
|
|
107
76
|
import {
|
|
108
|
-
useCopilotChat as useCopilotChatInternal,
|
|
109
|
-
defaultSystemMessage,
|
|
110
77
|
UseCopilotChatOptions,
|
|
111
|
-
|
|
112
|
-
|
|
78
|
+
useCopilotChat as useCopilotChatInternal,
|
|
79
|
+
UseCopilotChatReturn as UseCopilotChatReturnInternal,
|
|
113
80
|
} from "./use-copilot-chat_internal";
|
|
114
|
-
import {
|
|
115
|
-
ErrorVisibility,
|
|
116
|
-
Severity,
|
|
117
|
-
CopilotKitError,
|
|
118
|
-
CopilotKitErrorCode,
|
|
119
|
-
styledConsole,
|
|
120
|
-
} from "@copilotkit/shared";
|
|
121
|
-
|
|
122
|
-
// Non-functional fallback implementation
|
|
123
|
-
const createNonFunctionalReturn = (): UseCopilotChatReturn => ({
|
|
124
|
-
visibleMessages: [],
|
|
125
|
-
appendMessage: async () => {},
|
|
126
|
-
setMessages: () => {},
|
|
127
|
-
deleteMessage: () => {},
|
|
128
|
-
reloadMessages: async () => {},
|
|
129
|
-
stopGeneration: () => {},
|
|
130
|
-
reset: () => {},
|
|
131
|
-
isLoading: false,
|
|
132
|
-
runChatCompletion: async () => [],
|
|
133
|
-
mcpServers: [],
|
|
134
|
-
setMcpServers: () => {},
|
|
135
|
-
suggestions: [],
|
|
136
|
-
setSuggestions: () => {},
|
|
137
|
-
generateSuggestions: async () => {},
|
|
138
|
-
resetSuggestions: () => {},
|
|
139
|
-
isLoadingSuggestions: false,
|
|
140
|
-
interrupt: null,
|
|
141
|
-
});
|
|
142
|
-
function useCopilotChat(options: UseCopilotChatOptions = {}): UseCopilotChatReturn {
|
|
143
|
-
const { copilotApiConfig, setBannerError } = useCopilotContext();
|
|
144
81
|
|
|
145
|
-
|
|
146
|
-
|
|
82
|
+
// Create a type that excludes message-related properties from the internal type
|
|
83
|
+
export type UseCopilotChatReturn = Omit<
|
|
84
|
+
UseCopilotChatReturnInternal,
|
|
85
|
+
| "messages"
|
|
86
|
+
| "sendMessage"
|
|
87
|
+
| "suggestions"
|
|
88
|
+
| "setSuggestions"
|
|
89
|
+
| "generateSuggestions"
|
|
90
|
+
| "isLoadingSuggestions"
|
|
91
|
+
| "resetSuggestions"
|
|
92
|
+
| "interrupt"
|
|
93
|
+
| "setMessages"
|
|
94
|
+
| "deleteMessage"
|
|
95
|
+
>;
|
|
147
96
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}, [hasPublicApiKey]); // Removed setBannerError dependency
|
|
167
|
-
|
|
168
|
-
// Return internal result if publicApiKey is available, otherwise return fallback
|
|
169
|
-
if (hasPublicApiKey) {
|
|
170
|
-
return internalResult;
|
|
171
|
-
}
|
|
97
|
+
/**
|
|
98
|
+
* A lightweight React hook for headless chat interactions.
|
|
99
|
+
* Perfect for programmatic messaging, background operations, and custom UI implementations.
|
|
100
|
+
*
|
|
101
|
+
* **Open Source Friendly** - Works without requiring a `publicApiKey`.
|
|
102
|
+
*/
|
|
103
|
+
export function useCopilotChat(options: UseCopilotChatOptions = {}): UseCopilotChatReturn {
|
|
104
|
+
const {
|
|
105
|
+
visibleMessages,
|
|
106
|
+
appendMessage,
|
|
107
|
+
reloadMessages,
|
|
108
|
+
stopGeneration,
|
|
109
|
+
reset,
|
|
110
|
+
isLoading,
|
|
111
|
+
runChatCompletion,
|
|
112
|
+
mcpServers,
|
|
113
|
+
setMcpServers,
|
|
114
|
+
} = useCopilotChatInternal(options);
|
|
172
115
|
|
|
173
|
-
|
|
174
|
-
|
|
116
|
+
return {
|
|
117
|
+
visibleMessages,
|
|
118
|
+
appendMessage,
|
|
119
|
+
reloadMessages,
|
|
120
|
+
stopGeneration,
|
|
121
|
+
reset,
|
|
122
|
+
isLoading,
|
|
123
|
+
runChatCompletion,
|
|
124
|
+
mcpServers,
|
|
125
|
+
setMcpServers,
|
|
126
|
+
};
|
|
175
127
|
}
|
|
176
|
-
|
|
177
|
-
export { defaultSystemMessage, useCopilotChat };
|
|
178
|
-
export type { UseCopilotChatOptions, UseCopilotChatReturn, MCPServerConfig };
|
|
@@ -10,7 +10,13 @@ import { reloadSuggestions as generateSuggestions } from "../utils";
|
|
|
10
10
|
import type { SuggestionItem } from "../utils";
|
|
11
11
|
|
|
12
12
|
import { Message } from "@copilotkit/shared";
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
Role as gqlRole,
|
|
15
|
+
TextMessage,
|
|
16
|
+
aguiToGQL,
|
|
17
|
+
gqlToAGUI,
|
|
18
|
+
Message as DeprecatedGqlMessage,
|
|
19
|
+
} from "@copilotkit/runtime-client-gql";
|
|
14
20
|
import { useLangGraphInterruptRender } from "./use-langgraph-interrupt-render";
|
|
15
21
|
|
|
16
22
|
export interface UseCopilotChatOptions {
|
|
@@ -43,28 +49,111 @@ export interface MCPServerConfig {
|
|
|
43
49
|
}
|
|
44
50
|
|
|
45
51
|
export interface UseCopilotChatReturn {
|
|
46
|
-
/**
|
|
47
|
-
|
|
52
|
+
/**
|
|
53
|
+
* @deprecated use `messages` instead, this is an old non ag-ui version of the messages
|
|
54
|
+
* Array of messages currently visible in the chat interface
|
|
55
|
+
*
|
|
56
|
+
* This is the visible messages, not the raw messages from the runtime client.
|
|
57
|
+
*/
|
|
58
|
+
visibleMessages: DeprecatedGqlMessage[];
|
|
48
59
|
|
|
49
|
-
/**
|
|
50
|
-
|
|
60
|
+
/**
|
|
61
|
+
* The messages that are currently in the chat in AG-UI format.
|
|
62
|
+
*/
|
|
63
|
+
messages: Message[];
|
|
51
64
|
|
|
52
|
-
/**
|
|
53
|
-
|
|
65
|
+
/** @deprecated use `sendMessage` instead */
|
|
66
|
+
appendMessage: (message: DeprecatedGqlMessage, options?: AppendMessageOptions) => Promise<void>;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Send a new message to the chat
|
|
70
|
+
*
|
|
71
|
+
* ```tsx
|
|
72
|
+
* await sendMessage({
|
|
73
|
+
* id: "123",
|
|
74
|
+
* role: "user",
|
|
75
|
+
* content: "Hello, process this request",
|
|
76
|
+
* });
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
sendMessage: (message: Message, options?: AppendMessageOptions) => Promise<void>;
|
|
54
80
|
|
|
55
|
-
/**
|
|
81
|
+
/**
|
|
82
|
+
* Replace all messages in the chat
|
|
83
|
+
*
|
|
84
|
+
* ```tsx
|
|
85
|
+
* setMessages([
|
|
86
|
+
* { id: "123", role: "user", content: "Hello, process this request" },
|
|
87
|
+
* { id: "456", role: "assistant", content: "Hello, I'm the assistant" },
|
|
88
|
+
* ]);
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* **Deprecated** non-ag-ui version:
|
|
92
|
+
*
|
|
93
|
+
* ```tsx
|
|
94
|
+
* setMessages([
|
|
95
|
+
* new TextMessage({
|
|
96
|
+
* content: "Hello, process this request",
|
|
97
|
+
* role: gqlRole.User,
|
|
98
|
+
* }),
|
|
99
|
+
* new TextMessage({
|
|
100
|
+
* content: "Hello, I'm the assistant",
|
|
101
|
+
* role: gqlRole.Assistant,
|
|
102
|
+
* ]);
|
|
103
|
+
* ```
|
|
104
|
+
*
|
|
105
|
+
*/
|
|
106
|
+
setMessages: (messages: Message[] | DeprecatedGqlMessage[]) => void;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Remove a specific message by ID
|
|
110
|
+
*
|
|
111
|
+
* ```tsx
|
|
112
|
+
* deleteMessage("123");
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
56
115
|
deleteMessage: (messageId: string) => void;
|
|
57
116
|
|
|
58
|
-
/**
|
|
117
|
+
/**
|
|
118
|
+
* Regenerate the response for a specific message
|
|
119
|
+
*
|
|
120
|
+
* ```tsx
|
|
121
|
+
* reloadMessages("123");
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
59
124
|
reloadMessages: (messageId: string) => Promise<void>;
|
|
60
125
|
|
|
61
|
-
/**
|
|
126
|
+
/**
|
|
127
|
+
* Stop the current message generation
|
|
128
|
+
*
|
|
129
|
+
* ```tsx
|
|
130
|
+
* if (isLoading) {
|
|
131
|
+
* stopGeneration();
|
|
132
|
+
* }
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
62
135
|
stopGeneration: () => void;
|
|
63
136
|
|
|
64
|
-
/**
|
|
137
|
+
/**
|
|
138
|
+
* Clear all messages and reset chat state
|
|
139
|
+
*
|
|
140
|
+
* ```tsx
|
|
141
|
+
* reset();
|
|
142
|
+
* console.log(messages); // []
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
65
145
|
reset: () => void;
|
|
66
146
|
|
|
67
|
-
/**
|
|
147
|
+
/**
|
|
148
|
+
* Whether the chat is currently generating a response
|
|
149
|
+
*
|
|
150
|
+
* ```tsx
|
|
151
|
+
* if (isLoading) {
|
|
152
|
+
* console.log("Loading...");
|
|
153
|
+
* } else {
|
|
154
|
+
* console.log("Not loading");
|
|
155
|
+
* }
|
|
156
|
+
*/
|
|
68
157
|
isLoading: boolean;
|
|
69
158
|
|
|
70
159
|
/** Manually trigger chat completion (advanced usage) */
|
|
@@ -92,6 +181,11 @@ export interface UseCopilotChatReturn {
|
|
|
92
181
|
* Trigger AI-powered suggestion generation
|
|
93
182
|
* Uses configurations from useCopilotChatSuggestions hooks
|
|
94
183
|
* Respects global debouncing - only one generation can run at a time
|
|
184
|
+
*
|
|
185
|
+
* ```tsx
|
|
186
|
+
* generateSuggestions();
|
|
187
|
+
* console.log(suggestions); // [suggestion1, suggestion2, suggestion3]
|
|
188
|
+
* ```
|
|
95
189
|
*/
|
|
96
190
|
generateSuggestions: () => Promise<void>;
|
|
97
191
|
|
|
@@ -300,9 +394,17 @@ export function useCopilotChat(options: UseCopilotChatOptions = {}): UseCopilotC
|
|
|
300
394
|
|
|
301
395
|
const latestAppend = useUpdatedRef(append);
|
|
302
396
|
const latestAppendFunc = useAsyncCallback(
|
|
397
|
+
async (message: DeprecatedGqlMessage, options?: AppendMessageOptions) => {
|
|
398
|
+
abortSuggestions(options?.clearSuggestions);
|
|
399
|
+
return await latestAppend.current(message, options);
|
|
400
|
+
},
|
|
401
|
+
[latestAppend],
|
|
402
|
+
);
|
|
403
|
+
|
|
404
|
+
const latestSendMessageFunc = useAsyncCallback(
|
|
303
405
|
async (message: Message, options?: AppendMessageOptions) => {
|
|
304
406
|
abortSuggestions(options?.clearSuggestions);
|
|
305
|
-
return await latestAppend.current(aguiToGQL([message])[0], options);
|
|
407
|
+
return await latestAppend.current(aguiToGQL([message])[0] as DeprecatedGqlMessage, options);
|
|
306
408
|
},
|
|
307
409
|
[latestAppend],
|
|
308
410
|
);
|
|
@@ -330,7 +432,10 @@ export function useCopilotChat(options: UseCopilotChatOptions = {}): UseCopilotC
|
|
|
330
432
|
|
|
331
433
|
const latestSetMessages = useUpdatedRef(setMessages);
|
|
332
434
|
const latestSetMessagesFunc = useCallback(
|
|
333
|
-
(messages: Message[]) => {
|
|
435
|
+
(messages: Message[] | DeprecatedGqlMessage[]) => {
|
|
436
|
+
if (messages.every((message) => message instanceof DeprecatedGqlMessage)) {
|
|
437
|
+
return latestSetMessages.current(messages as DeprecatedGqlMessage[]);
|
|
438
|
+
}
|
|
334
439
|
return latestSetMessages.current(aguiToGQL(messages));
|
|
335
440
|
},
|
|
336
441
|
[latestSetMessages],
|
|
@@ -373,7 +478,9 @@ export function useCopilotChat(options: UseCopilotChatOptions = {}): UseCopilotC
|
|
|
373
478
|
const interrupt = useLangGraphInterruptRender();
|
|
374
479
|
|
|
375
480
|
return {
|
|
376
|
-
visibleMessages:
|
|
481
|
+
visibleMessages: messages,
|
|
482
|
+
messages: gqlToAGUI(messages, actions, coAgentStateRenders),
|
|
483
|
+
sendMessage: latestSendMessageFunc,
|
|
377
484
|
appendMessage: latestAppendFunc,
|
|
378
485
|
setMessages: latestSetMessagesFunc,
|
|
379
486
|
reloadMessages: latestReloadFunc,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/usage-banner.tsx"],"sourcesContent":["import {\n Severity,\n CopilotKitError,\n ErrorVisibility,\n CopilotKitErrorCode,\n} from \"@copilotkit/shared\";\n\ninterface UsageBannerProps {\n severity?: Severity;\n message?: string;\n onClose?: () => void;\n actions?: {\n primary?: {\n label: string;\n onClick: () => void;\n };\n secondary?: {\n label: string;\n onClick: () => void;\n };\n };\n}\n\nexport function UsageBanner({\n severity = Severity.CRITICAL,\n message = \"\",\n onClose,\n actions,\n}: UsageBannerProps) {\n if (!message || !severity) {\n return null;\n }\n\n const themes = {\n [Severity.INFO]: {\n bg: \"#f8fafc\",\n border: \"#e2e8f0\",\n text: \"#475569\",\n accent: \"#3b82f6\",\n },\n [Severity.WARNING]: {\n bg: \"#fffbeb\",\n border: \"#fbbf24\",\n text: \"#92400e\",\n accent: \"#f59e0b\",\n },\n [Severity.CRITICAL]: {\n bg: \"#fef2f2\",\n border: \"#fecaca\",\n text: \"#dc2626\",\n accent: \"#ef4444\",\n },\n };\n\n const theme = themes[severity];\n\n return (\n <>\n <style>\n {`\n @keyframes slideUp {\n from { opacity: 0; transform: translateX(-50%) translateY(8px); }\n to { opacity: 1; transform: translateX(-50%) translateY(0); }\n }\n \n .usage-banner {\n position: fixed;\n bottom: 24px;\n left: 50%;\n transform: translateX(-50%);\n width: min(600px, calc(100vw - 32px));\n z-index: 10000;\n animation: slideUp 0.2s cubic-bezier(0.16, 1, 0.3, 1);\n }\n \n .banner-content {\n background: linear-gradient(135deg, ${theme.bg} 0%, ${theme.bg}f5 100%);\n border: 1px solid ${theme.border};\n border-radius: 12px;\n padding: 18px 20px;\n box-shadow: \n 0 4px 24px rgba(0, 0, 0, 0.08),\n 0 2px 8px rgba(0, 0, 0, 0.04),\n inset 0 1px 0 rgba(255, 255, 255, 0.7);\n display: flex;\n align-items: center;\n gap: 16px;\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;\n backdrop-filter: blur(12px);\n position: relative;\n overflow: hidden;\n }\n \n .banner-content::before {\n content: '';\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n height: 1px;\n background: linear-gradient(90deg, transparent, ${theme.accent}40, transparent);\n }\n \n .banner-message {\n color: ${theme.text};\n font-size: 14px;\n line-height: 1.5;\n font-weight: 500;\n flex: 1;\n letter-spacing: -0.01em;\n }\n \n .close-btn {\n background: rgba(0, 0, 0, 0.05);\n border: none;\n color: ${theme.text};\n cursor: pointer;\n padding: 0;\n border-radius: 6px;\n opacity: 0.6;\n transition: all 0.15s cubic-bezier(0.16, 1, 0.3, 1);\n font-size: 14px;\n line-height: 1;\n flex-shrink: 0;\n width: 24px;\n height: 24px;\n display: flex;\n align-items: center;\n justify-content: center;\n }\n \n .close-btn:hover {\n opacity: 1;\n background: rgba(0, 0, 0, 0.08);\n transform: scale(1.05);\n }\n \n .btn-primary {\n background: linear-gradient(135deg, ${theme.accent} 0%, ${theme.accent}e6 100%);\n color: white;\n border: none;\n border-radius: 8px;\n padding: 10px 18px;\n font-size: 13px;\n font-weight: 600;\n cursor: pointer;\n transition: all 0.15s cubic-bezier(0.16, 1, 0.3, 1);\n font-family: inherit;\n flex-shrink: 0;\n box-shadow: \n 0 2px 8px ${theme.accent}30,\n inset 0 1px 0 rgba(255, 255, 255, 0.2);\n letter-spacing: -0.01em;\n }\n \n .btn-primary:hover {\n transform: translateY(-1px) scale(1.02);\n box-shadow: \n 0 4px 12px ${theme.accent}40,\n inset 0 1px 0 rgba(255, 255, 255, 0.25);\n }\n \n .btn-primary:active {\n transform: translateY(0) scale(0.98);\n transition: all 0.08s cubic-bezier(0.16, 1, 0.3, 1);\n }\n \n @media (max-width: 640px) {\n .usage-banner {\n width: calc(100vw - 24px);\n }\n \n .banner-content {\n padding: 16px;\n gap: 12px;\n }\n \n .banner-message {\n font-size: 13px;\n line-height: 1.45;\n }\n \n .btn-primary {\n padding: 8px 14px;\n font-size: 12px;\n }\n \n .close-btn {\n width: 22px;\n height: 22px;\n font-size: 12px;\n }\n }\n `}\n </style>\n\n <div className=\"usage-banner\">\n <div className=\"banner-content\">\n <div className=\"banner-message\">{message}</div>\n {actions?.primary && (\n <button className=\"btn-primary\" onClick={actions.primary.onClick}>\n {actions.primary.label}\n </button>\n )}\n {onClose && (\n <button className=\"close-btn\" onClick={onClose} title=\"Close\">\n ×\n </button>\n )}\n </div>\n </div>\n </>\n );\n}\n\n// Get action button based on error type\nexport const getErrorActions = (error: CopilotKitError) => {\n switch (error.code) {\n case CopilotKitErrorCode.MISSING_PUBLIC_API_KEY_ERROR:\n return {\n primary: {\n label: \"Get Free API Key\",\n onClick: () =>\n window.open(\"https://cloud.copilotkit.ai\", \"_blank\", \"noopener,noreferrer\"),\n },\n };\n case CopilotKitErrorCode.UPGRADE_REQUIRED_ERROR:\n return {\n primary: {\n label: \"Upgrade\",\n onClick: () =>\n window.open(\"https://cloud.copilotkit.ai\", \"_blank\", \"noopener,noreferrer\"),\n },\n };\n default:\n return undefined;\n }\n};\n\nexport function renderCopilotKitUsage(error: CopilotKitError, onClose?: () => void) {\n // Route based on error visibility level\n if (error.visibility !== ErrorVisibility.BANNER) {\n return null;\n }\n\n return (\n <UsageBanner\n severity={error.severity || Severity.CRITICAL}\n message={error.message}\n onClose={onClose}\n actions={getErrorActions(error)}\n />\n );\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,OACK;AAoDH,mBACE,KA2IE,YA5IJ;AAlCG,SAAS,YAAY;AAAA,EAC1B,WAAW,SAAS;AAAA,EACpB,UAAU;AAAA,EACV;AAAA,EACA;AACF,GAAqB;AACnB,MAAI,CAAC,WAAW,CAAC,UAAU;AACzB,WAAO;AAAA,EACT;AAEA,QAAM,SAAS;AAAA,IACb,CAAC,SAAS,IAAI,GAAG;AAAA,MACf,IAAI;AAAA,MACJ,QAAQ;AAAA,MACR,MAAM;AAAA,MACN,QAAQ;AAAA,IACV;AAAA,IACA,CAAC,SAAS,OAAO,GAAG;AAAA,MAClB,IAAI;AAAA,MACJ,QAAQ;AAAA,MACR,MAAM;AAAA,MACN,QAAQ;AAAA,IACV;AAAA,IACA,CAAC,SAAS,QAAQ,GAAG;AAAA,MACnB,IAAI;AAAA,MACJ,QAAQ;AAAA,MACR,MAAM;AAAA,MACN,QAAQ;AAAA,IACV;AAAA,EACF;AAEA,QAAM,QAAQ,OAAO,QAAQ;AAE7B,SACE,iCACE;AAAA,wBAAC,WACE;AAAA;AAAA;AAAA;AAA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KACF;AAEJ;AAGO,IAAM,kBAAkB,CAAC,UAA2B;AACzD,UAAQ,MAAM,MAAM;AAAA,IAClB,KAAK,oBAAoB;AACvB,aAAO;AAAA,QACL,SAAS;AAAA,UACP,OAAO;AAAA,UACP,SAAS,MACP,OAAO,KAAK,+BAA+B,UAAU,qBAAqB;AAAA,QAC9E;AAAA,MACF;AAAA,IACF,KAAK,oBAAoB;AACvB,aAAO;AAAA,QACL,SAAS;AAAA,UACP,OAAO;AAAA,UACP,SAAS,MACP,OAAO,KAAK,+BAA+B,UAAU,qBAAqB;AAAA,QAC9E;AAAA,MACF;AAAA,IACF;AACE,aAAO;AAAA,EACX;AACF;AAEO,SAAS,sBAAsB,OAAwB,SAAsB;AAElF,MAAI,MAAM,eAAe,gBAAgB,QAAQ;AAC/C,WAAO;AAAA,EACT;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACC,UAAU,MAAM,YAAY,SAAS;AAAA,MACrC,SAAS,MAAM;AAAA,MACf;AAAA,MACA,SAAS,gBAAgB,KAAK;AAAA;AAAA,EAChC;AAEJ;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/use-copilot-chat_internal.ts"],"sourcesContent":["import { useRef, useEffect, useCallback, useState, useMemo } from \"react\";\nimport { AgentSession, useCopilotContext, CopilotContextParams } from \"../context/copilot-context\";\nimport { useCopilotMessagesContext, CopilotMessagesContextParams } from \"../context\";\nimport { SystemMessageFunction } from \"../types\";\nimport { useChat, AppendMessageOptions } from \"./use-chat\";\nimport { defaultCopilotContextCategories } from \"../components\";\nimport { CoAgentStateRenderHandlerArguments } from \"@copilotkit/shared\";\nimport { useAsyncCallback } from \"../components/error-boundary/error-utils\";\nimport { reloadSuggestions as generateSuggestions } from \"../utils\";\nimport type { SuggestionItem } from \"../utils\";\n\nimport { Message } from \"@copilotkit/shared\";\nimport { Role as gqlRole, TextMessage, aguiToGQL, gqlToAGUI } from \"@copilotkit/runtime-client-gql\";\nimport { useLangGraphInterruptRender } from \"./use-langgraph-interrupt-render\";\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\nexport interface MCPServerConfig {\n endpoint: string;\n apiKey?: string;\n}\n\nexport interface UseCopilotChatReturn {\n /** Array of messages currently visible in the chat interface */\n visibleMessages: Message[];\n\n /** Send a new message to the chat */\n appendMessage: (message: Message, options?: AppendMessageOptions) => Promise<void>;\n\n /** Replace all messages in the chat */\n setMessages: (messages: Message[]) => void;\n\n /** Remove a specific message by ID */\n deleteMessage: (messageId: string) => void;\n\n /** Regenerate the response for a specific message */\n reloadMessages: (messageId: string) => Promise<void>;\n\n /** Stop the current message generation */\n stopGeneration: () => void;\n\n /** Clear all messages and reset chat state */\n reset: () => void;\n\n /** Whether the chat is currently generating a response */\n isLoading: 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: SuggestionItem[];\n\n /**\n * Manually set suggestions\n * Useful for manual mode or custom suggestion workflows\n */\n setSuggestions: (suggestions: SuggestionItem[]) => 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 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\nlet globalSuggestionPromise: Promise<void> | null = null;\n\nexport function useCopilotChat(options: UseCopilotChatOptions = {}): UseCopilotChatReturn {\n const makeSystemMessage = options.makeSystemMessage ?? defaultSystemMessage;\n const {\n getContextString,\n getFunctionCallHandler,\n copilotApiConfig,\n isLoading,\n setIsLoading,\n chatInstructions,\n actions,\n coagentStatesRef,\n setCoagentStatesWithRef,\n coAgentStateRenders,\n agentSession,\n setAgentSession,\n forwardedParameters,\n agentLock,\n threadId,\n setThreadId,\n runId,\n setRunId,\n chatAbortControllerRef,\n extensions,\n setExtensions,\n langGraphInterruptAction,\n setLangGraphInterruptAction,\n chatSuggestionConfiguration,\n\n runtimeClient,\n } = useCopilotContext();\n const { messages, setMessages, suggestions, setSuggestions } = useCopilotMessagesContext();\n\n // Simple state for MCP servers (keep for interface compatibility)\n const [mcpServers, setLocalMcpServers] = useState<MCPServerConfig[]>([]);\n\n // Basic suggestion state for programmatic control\n const suggestionsAbortControllerRef = useRef<AbortController | null>(null);\n const isLoadingSuggestionsRef = useRef<boolean>(false);\n\n const abortSuggestions = useCallback(\n (clear: boolean = true) => {\n suggestionsAbortControllerRef.current?.abort(\"suggestions aborted by user\");\n suggestionsAbortControllerRef.current = null;\n if (clear) {\n setSuggestions([]);\n }\n },\n [setSuggestions],\n );\n\n // Memoize context with stable dependencies only\n const stableContext = useMemo(() => {\n return {\n actions,\n copilotApiConfig,\n chatSuggestionConfiguration,\n messages,\n setMessages,\n getContextString,\n runtimeClient,\n };\n }, [\n JSON.stringify(Object.keys(actions)),\n copilotApiConfig.chatApiEndpoint,\n messages.length,\n Object.keys(chatSuggestionConfiguration).length,\n ]);\n\n // Programmatic suggestion generation function\n const generateSuggestionsFunc = useCallback(async () => {\n // If a global suggestion is running, ignore this call\n if (globalSuggestionPromise) {\n return globalSuggestionPromise;\n }\n\n globalSuggestionPromise = (async () => {\n try {\n abortSuggestions();\n isLoadingSuggestionsRef.current = true;\n suggestionsAbortControllerRef.current = new AbortController();\n\n setSuggestions([]);\n\n await generateSuggestions(\n stableContext as CopilotContextParams & CopilotMessagesContextParams,\n chatSuggestionConfiguration,\n setSuggestions,\n suggestionsAbortControllerRef,\n );\n } catch (error) {\n // Re-throw to allow caller to handle the error\n throw error;\n } finally {\n isLoadingSuggestionsRef.current = false;\n globalSuggestionPromise = null;\n }\n })();\n\n return globalSuggestionPromise;\n }, [stableContext, chatSuggestionConfiguration, setSuggestions, abortSuggestions]);\n\n const resetSuggestions = useCallback(() => {\n setSuggestions([]);\n }, [setSuggestions]);\n\n // MCP servers logic\n useEffect(() => {\n if (mcpServers.length > 0) {\n const serversCopy = [...mcpServers];\n copilotApiConfig.mcpServers = serversCopy;\n if (!copilotApiConfig.properties) {\n copilotApiConfig.properties = {};\n }\n copilotApiConfig.properties.mcpServers = serversCopy;\n }\n }, [mcpServers, copilotApiConfig]);\n\n const setMcpServers = useCallback((servers: MCPServerConfig[]) => {\n setLocalMcpServers(servers);\n }, []);\n\n // Move these function declarations above the useChat call\n const onCoAgentStateRender = useAsyncCallback(\n async (args: CoAgentStateRenderHandlerArguments) => {\n const { name, nodeName, state } = args;\n let action = Object.values(coAgentStateRenders).find(\n (action) => action.name === name && action.nodeName === nodeName,\n );\n if (!action) {\n action = Object.values(coAgentStateRenders).find(\n (action) => action.name === name && !action.nodeName,\n );\n }\n if (action) {\n await action.handler?.({ state, nodeName });\n }\n },\n [coAgentStateRenders],\n );\n\n const makeSystemMessageCallback = useCallback(() => {\n const systemMessageMaker = makeSystemMessage || defaultSystemMessage;\n // this always gets the latest context string\n const contextString = getContextString([], defaultCopilotContextCategories); // TODO: make the context categories configurable\n\n return new TextMessage({\n content: systemMessageMaker(contextString, chatInstructions),\n role: gqlRole.System,\n });\n }, [getContextString, makeSystemMessage, chatInstructions]);\n\n const deleteMessage = useCallback(\n (messageId: string) => {\n setMessages((prev) => prev.filter((message) => message.id !== messageId));\n },\n [setMessages],\n );\n\n // Get chat helpers with updated config\n const { append, reload, stop, runChatCompletion } = useChat({\n ...options,\n actions: Object.values(actions),\n copilotConfig: copilotApiConfig,\n initialMessages: aguiToGQL(options.initialMessages || []),\n onFunctionCall: getFunctionCallHandler(),\n onCoAgentStateRender,\n messages,\n setMessages,\n makeSystemMessageCallback,\n isLoading,\n setIsLoading,\n coagentStatesRef,\n setCoagentStatesWithRef,\n agentSession,\n setAgentSession,\n forwardedParameters,\n threadId,\n setThreadId,\n runId,\n setRunId,\n chatAbortControllerRef,\n agentLock,\n extensions,\n setExtensions,\n langGraphInterruptAction,\n setLangGraphInterruptAction,\n });\n\n const latestAppend = useUpdatedRef(append);\n const latestAppendFunc = useAsyncCallback(\n async (message: Message, options?: AppendMessageOptions) => {\n abortSuggestions(options?.clearSuggestions);\n return await latestAppend.current(aguiToGQL([message])[0], options);\n },\n [latestAppend],\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 latestStop = useUpdatedRef(stop);\n const latestStopFunc = useCallback(() => {\n return latestStop.current();\n }, [latestStop]);\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 latestSetMessages = useUpdatedRef(setMessages);\n const latestSetMessagesFunc = useCallback(\n (messages: Message[]) => {\n return latestSetMessages.current(aguiToGQL(messages));\n },\n [latestSetMessages],\n );\n\n const latestRunChatCompletion = useUpdatedRef(runChatCompletion);\n const latestRunChatCompletionFunc = useAsyncCallback(async () => {\n return await latestRunChatCompletion.current!();\n }, [latestRunChatCompletion]);\n\n const reset = useCallback(() => {\n latestStopFunc();\n setMessages([]);\n setRunId(null);\n setCoagentStatesWithRef({});\n let initialAgentSession: AgentSession | null = null;\n if (agentLock) {\n initialAgentSession = {\n agentName: agentLock,\n };\n }\n setAgentSession(initialAgentSession);\n // Reset suggestions when chat is reset\n resetSuggestions();\n }, [\n latestStopFunc,\n setMessages,\n setThreadId,\n setCoagentStatesWithRef,\n setAgentSession,\n agentLock,\n resetSuggestions,\n ]);\n\n const latestReset = useUpdatedRef(reset);\n const latestResetFunc = useCallback(() => {\n return latestReset.current();\n }, [latestReset]);\n\n const interrupt = useLangGraphInterruptRender();\n\n return {\n visibleMessages: gqlToAGUI(messages, actions, coAgentStateRenders),\n appendMessage: latestAppendFunc,\n setMessages: latestSetMessagesFunc,\n reloadMessages: latestReloadFunc,\n stopGeneration: latestStopFunc,\n reset: latestResetFunc,\n deleteMessage: latestDeleteFunc,\n runChatCompletion: latestRunChatCompletionFunc,\n isLoading,\n mcpServers,\n setMcpServers,\n suggestions,\n setSuggestions,\n generateSuggestions: generateSuggestionsFunc,\n resetSuggestions,\n isLoadingSuggestions: isLoadingSuggestionsRef.current,\n interrupt,\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\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 ret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B,GAAG;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAED,QAAM,cAAc,cAAc,KAAK;AACvC,QAAM,kBAAkB,YAAY,MAAM;AACxC,WAAO,YAAY,QAAQ;AAAA,EAC7B,GAAG,CAAC,WAAW,CAAC;AAEhB,QAAM,YAAY,4BAA4B;AAE9C,SAAO;AAAA,IACL,iBAAiB,UAAU,UAAU,SAAS,mBAAmB;AAAA,IACjE,eAAe;AAAA,IACf,aAAa;AAAA,IACb,gBAAgB;AAAA,IAChB,gBAAgB;AAAA,IAChB,OAAO;AAAA,IACP,eAAe;AAAA,IACf,mBAAmB;AAAA,IACnB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,qBAAqB;AAAA,IACrB;AAAA,IACA,sBAAsB,wBAAwB;AAAA,IAC9C;AAAA,EACF;AACF;AAIA,SAAS,cAAiB,OAAU;AAClC,QAAM,MAAM,OAAO,KAAK;AAExB,YAAU,MAAM;AACd,QAAI,UAAU;AAAA,EAChB,GAAG,CAAC,KAAK,CAAC;AAEV,SAAO;AACT;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":["_a","action","options","messages"]}
|
package/dist/chunk-MWHILKQH.mjs
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
useCopilotChat
|
|
3
|
-
} from "./chunk-GRCHDHC4.mjs";
|
|
4
|
-
|
|
5
|
-
// src/hooks/use-copilot-chat-light.ts
|
|
6
|
-
function useCopilotChatLight(options = {}) {
|
|
7
|
-
const { appendMessage, setSuggestions, generateSuggestions } = useCopilotChat(options);
|
|
8
|
-
return {
|
|
9
|
-
appendMessage,
|
|
10
|
-
setSuggestions,
|
|
11
|
-
generateSuggestions
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export {
|
|
16
|
-
useCopilotChatLight
|
|
17
|
-
};
|
|
18
|
-
//# sourceMappingURL=chunk-MWHILKQH.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/use-copilot-chat-light.ts"],"sourcesContent":["/**\n * `useCopilotChatLight` is a lightweight React hook for headless chat interactions.\n * Perfect for programmatic messaging, background operations, and custom UI implementations.\n *\n * **Open Source Friendly** - Works without requiring a `publicApiKey`.\n *\n * ## Use Cases:\n *\n * - **Programmatic Messaging**: Send messages without displaying chat UI\n * - **Background Operations**: Trigger AI interactions in the background\n * - **Custom UI**: Build your own chat interface using CopilotKit's messaging infrastructure\n * - **Testing & Automation**: Programmatic chat interactions for testing\n * - **Fire-and-Forget**: Send messages without needing to read responses\n * - **Suggestion Management**: Control chat suggestions programmatically\n *\n * ## What's Included:\n *\n * - `appendMessage` - Send messages to the chat\n * - `setSuggestions` - Manually control suggestions\n * - `generateSuggestions` - Trigger AI-powered suggestion generation\n *\n * ## What's NOT Included:\n *\n * - Message reading (`visibleMessages`)\n * - Loading states (`isLoading`, `isLoadingSuggestions`)\n * - Message management (`setMessages`, `deleteMessage`, `reloadMessages`)\n * - Chat controls (`reset`, `stopGeneration`)\n * - Advanced features (`mcpServers`, `runChatCompletion`, `interrupt`)\n *\n * ## Usage:\n *\n * ### Basic Messaging\n *\n * ```tsx\n * import { useCopilotChatLite } from \"@copilotkit/react-core\";\n * import { TextMessage, Role } from \"@copilotkit/runtime-client-gql\";\n *\n * export function BackgroundMessaging() {\n * const { appendMessage } = useCopilotChatLite();\n *\n * const sendBackgroundMessage = async () => {\n * await appendMessage(new TextMessage({\n * content: \"Process this data in the background\",\n * role: Role.User,\n * }));\n * };\n *\n * return <button onClick={sendBackgroundMessage}>Process Data</button>;\n * }\n * ```\n *\n * ### Suggestion Management\n *\n * ```tsx\n * import { useCopilotChatLight } from \"@copilotkit/react-core\";\n *\n * export function SuggestionController() {\n * const { setSuggestions, generateSuggestions } = useCopilotChatLight();\n *\n * const setCustomSuggestions = () => {\n * setSuggestions([\n * { title: \"Analyze Data\", message: \"Analyze the current dataset\" },\n * { title: \"Generate Report\", message: \"Create a summary report\" }\n * ]);\n * };\n *\n * const triggerAISuggestions = async () => {\n * await generateSuggestions();\n * };\n *\n * return (\n * <div>\n * <button onClick={setCustomSuggestions}>Set Custom Suggestions</button>\n * <button onClick={triggerAISuggestions}>Generate AI Suggestions</button>\n * </div>\n * );\n * }\n * ```\n *\n * ### Automated Workflows\n *\n * ```tsx\n * import { useCopilotChatLight } from \"@copilotkit/react-core\";\n *\n * export function AutomatedWorkflow() {\n * const { appendMessage, setSuggestions } = useCopilotChatLight();\n *\n * const runWorkflow = async () => {\n * // Step 1: Send initial message\n * await appendMessage(new TextMessage({\n * content: \"Start workflow analysis\",\n * role: Role.User,\n * }));\n *\n * // Step 2: Set contextual suggestions\n * setSuggestions([\n * { title: \"Continue\", message: \"Continue to next step\" },\n * { title: \"Stop\", message: \"Stop the workflow\" }\n * ]);\n * };\n *\n * return <button onClick={runWorkflow}>Run Automated Workflow</button>;\n * }\n * ```\n *\n * ## Return Type:\n *\n * ```tsx\n * const {\n * appendMessage, // Send messages programmatically\n * setSuggestions, // Set custom suggestions array\n * generateSuggestions, // Trigger AI suggestion generation\n * } = useCopilotChatLight();\n * ```\n */\n\nimport { Message } from \"@copilotkit/shared\";\nimport { AppendMessageOptions } from \"./use-chat\";\nimport { useCopilotChat as useCopilotChatInternal } from \"./use-copilot-chat_internal\";\nimport type { SuggestionItem } from \"../utils\";\n\nexport interface UseCopilotChatLightOptions {\n /**\n * A unique identifier for the chat. If not provided, a random one will be\n * generated. When provided, the chat instance with the same `id` will\n * have shared state 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?: (contextString: string, additionalInstructions?: string) => string;\n}\n\nexport interface UseCopilotChatLightReturn {\n /**\n * Send a new message to the chat programmatically.\n *\n * @param message - The message to send\n * @param options - Optional configuration for the message\n *\n * @example\n * ```tsx\n * await appendMessage(new TextMessage({\n * content: \"Hello, process this request\",\n * role: Role.User,\n * }));\n * ```\n */\n appendMessage: (message: Message, options?: AppendMessageOptions) => Promise<void>;\n\n /**\n * Manually set the suggestions array.\n * Useful for custom suggestion workflows and manual control.\n *\n * @param suggestions - Array of suggestion items to display\n *\n * @example\n * ```tsx\n * setSuggestions([\n * { title: \"Continue\", message: \"Continue the process\" },\n * { title: \"Stop\", message: \"Stop the current operation\" }\n * ]);\n * ```\n */\n setSuggestions: (suggestions: SuggestionItem[]) => 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 * @returns Promise that resolves when suggestions are generated\n *\n * @example\n * ```tsx\n * await generateSuggestions();\n * ```\n */\n generateSuggestions: () => Promise<void>;\n}\n\n/**\n * A lightweight React hook for headless chat interactions.\n * Perfect for programmatic messaging, background operations, and custom UI implementations.\n *\n * **Open Source Friendly** - Works without requiring a `publicApiKey`.\n *\n * @param options - Configuration options for the chat\n * @returns Object containing appendMessage, setSuggestions, and generateSuggestions functions\n *\n * @example\n * ```tsx\n * const { appendMessage, setSuggestions, generateSuggestions } = useCopilotChatLite();\n * ```\n */\nexport function useCopilotChatLight(\n options: UseCopilotChatLightOptions = {},\n): UseCopilotChatLightReturn {\n // Use the internal implementation (no API key required)\n const { appendMessage, setSuggestions, generateSuggestions } = useCopilotChatInternal(options);\n\n return {\n appendMessage,\n setSuggestions,\n generateSuggestions,\n };\n}\n"],"mappings":";;;;;AA+MO,SAAS,oBACd,UAAsC,CAAC,GACZ;AAE3B,QAAM,EAAE,eAAe,gBAAgB,oBAAoB,IAAI,eAAuB,OAAO;AAE7F,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|