@copilotkit/react-core 1.50.0-beta.8 → 1.50.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 +192 -0
- package/dist/{chunk-KYY2WZSR.mjs → chunk-5J7RRLRO.mjs} +2 -2
- package/dist/{chunk-ZU6ZBX4E.mjs → chunk-CO6V4G7P.mjs} +17 -9
- package/dist/chunk-CO6V4G7P.mjs.map +1 -0
- package/dist/{chunk-Y2L7KDVW.mjs → chunk-HQTDDA6V.mjs} +2 -2
- package/dist/chunk-LDEWO5XH.mjs +328 -0
- package/dist/chunk-LDEWO5XH.mjs.map +1 -0
- package/dist/chunk-XDFVCQD3.mjs +27 -0
- package/dist/chunk-XDFVCQD3.mjs.map +1 -0
- package/dist/{chunk-RQ6LWR6S.mjs → chunk-Z6JV2LRY.mjs} +1 -1
- package/dist/chunk-Z6JV2LRY.mjs.map +1 -0
- package/dist/{chunk-BLDHD6Q2.mjs → chunk-ZE4JVTEP.mjs} +2 -2
- package/dist/components/copilot-provider/copilotkit-props.d.ts +6 -0
- package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.js +127 -1150
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +3 -6
- package/dist/components/copilot-provider/index.js +127 -1150
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +3 -6
- package/dist/components/dev-console/console-trigger.mjs +225 -5
- package/dist/components/dev-console/console-trigger.mjs.map +1 -1
- package/dist/components/index.js +127 -1150
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +3 -6
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +124 -554
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +19 -19
- package/dist/hooks/use-copilot-chat-headless_c.js +42 -487
- package/dist/hooks/use-copilot-chat-headless_c.js.map +1 -1
- package/dist/hooks/use-copilot-chat-headless_c.mjs +2 -3
- package/dist/hooks/{use-configure-chat-suggestions.d.ts → use-copilot-chat-suggestions.d.ts} +2 -3
- package/dist/hooks/{use-configure-chat-suggestions.js → use-copilot-chat-suggestions.js} +10 -29
- package/dist/hooks/use-copilot-chat-suggestions.js.map +1 -0
- package/dist/hooks/use-copilot-chat-suggestions.mjs +8 -0
- package/dist/hooks/use-copilot-chat.js +40 -485
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +2 -3
- package/dist/hooks/use-copilot-chat_internal.d.ts +17 -0
- package/dist/hooks/use-copilot-chat_internal.js +40 -485
- package/dist/hooks/use-copilot-chat_internal.js.map +1 -1
- package/dist/hooks/use-copilot-chat_internal.mjs +1 -2
- package/dist/hooks/use-copilot-readable.d.ts +2 -3
- package/dist/hooks/use-copilot-readable.js.map +1 -1
- package/dist/hooks/use-copilot-readable.mjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +300 -1746
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -27
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +4 -7
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +4 -7
- package/dist/types/index.mjs +1 -1
- package/package.json +8 -8
- package/src/components/copilot-provider/copilotkit-props.tsx +7 -0
- package/src/components/copilot-provider/copilotkit.tsx +13 -5
- package/src/hooks/index.ts +2 -2
- package/src/hooks/use-copilot-chat-suggestions.tsx +124 -0
- package/src/hooks/use-copilot-chat_internal.ts +29 -29
- package/src/hooks/use-copilot-readable.ts +2 -4
- package/dist/chunk-EKDPRKZT.mjs +0 -746
- package/dist/chunk-EKDPRKZT.mjs.map +0 -1
- package/dist/chunk-FBVI3LQ6.mjs +0 -48
- package/dist/chunk-FBVI3LQ6.mjs.map +0 -1
- package/dist/chunk-PMWUKW3Z.mjs +0 -231
- package/dist/chunk-PMWUKW3Z.mjs.map +0 -1
- package/dist/chunk-RQ6LWR6S.mjs.map +0 -1
- package/dist/chunk-ZU6ZBX4E.mjs.map +0 -1
- package/dist/hooks/use-configure-chat-suggestions.js.map +0 -1
- package/dist/hooks/use-configure-chat-suggestions.mjs +0 -8
- package/src/hooks/use-configure-chat-suggestions.tsx +0 -86
- /package/dist/{chunk-KYY2WZSR.mjs.map → chunk-5J7RRLRO.mjs.map} +0 -0
- /package/dist/{chunk-Y2L7KDVW.mjs.map → chunk-HQTDDA6V.mjs.map} +0 -0
- /package/dist/{chunk-BLDHD6Q2.mjs.map → chunk-ZE4JVTEP.mjs.map} +0 -0
- /package/dist/hooks/{use-configure-chat-suggestions.mjs.map → use-copilot-chat-suggestions.mjs.map} +0 -0
package/dist/chunk-EKDPRKZT.mjs
DELETED
|
@@ -1,746 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
useLangGraphInterruptRender
|
|
3
|
-
} from "./chunk-VV56AVPB.mjs";
|
|
4
|
-
import {
|
|
5
|
-
useLazyToolRenderer
|
|
6
|
-
} from "./chunk-ZVF5Q6IH.mjs";
|
|
7
|
-
import {
|
|
8
|
-
useConfigureChatSuggestions
|
|
9
|
-
} from "./chunk-FBVI3LQ6.mjs";
|
|
10
|
-
import {
|
|
11
|
-
useAsyncCallback
|
|
12
|
-
} from "./chunk-6PUNP7CD.mjs";
|
|
13
|
-
import {
|
|
14
|
-
CoAgentStateRenderBridge
|
|
15
|
-
} from "./chunk-QNUAXSDP.mjs";
|
|
16
|
-
import {
|
|
17
|
-
useCopilotContext
|
|
18
|
-
} from "./chunk-AFNWX62Q.mjs";
|
|
19
|
-
import {
|
|
20
|
-
__async,
|
|
21
|
-
__spreadProps,
|
|
22
|
-
__spreadValues
|
|
23
|
-
} from "./chunk-SKC7AJIV.mjs";
|
|
24
|
-
|
|
25
|
-
// src/hooks/use-copilot-chat_internal.ts
|
|
26
|
-
import { useRef, useEffect, useCallback, useMemo, useState, createElement } from "react";
|
|
27
|
-
import { gqlToAGUI, Message as DeprecatedGqlMessage } from "@copilotkit/runtime-client-gql";
|
|
28
|
-
import {
|
|
29
|
-
useAgent,
|
|
30
|
-
useCopilotChatConfiguration,
|
|
31
|
-
useCopilotKit,
|
|
32
|
-
useRenderCustomMessages,
|
|
33
|
-
useSuggestions
|
|
34
|
-
} from "@copilotkitnext/react";
|
|
35
|
-
|
|
36
|
-
// ../../node_modules/.pnpm/@ag-ui+core@0.0.42/node_modules/@ag-ui/core/dist/index.mjs
|
|
37
|
-
import { z } from "zod";
|
|
38
|
-
import { z as z2 } from "zod";
|
|
39
|
-
var FunctionCallSchema = z.object({
|
|
40
|
-
name: z.string(),
|
|
41
|
-
arguments: z.string()
|
|
42
|
-
});
|
|
43
|
-
var ToolCallSchema = z.object({
|
|
44
|
-
id: z.string(),
|
|
45
|
-
type: z.literal("function"),
|
|
46
|
-
function: FunctionCallSchema
|
|
47
|
-
});
|
|
48
|
-
var BaseMessageSchema = z.object({
|
|
49
|
-
id: z.string(),
|
|
50
|
-
role: z.string(),
|
|
51
|
-
content: z.string().optional(),
|
|
52
|
-
name: z.string().optional()
|
|
53
|
-
});
|
|
54
|
-
var TextInputContentSchema = z.object({
|
|
55
|
-
type: z.literal("text"),
|
|
56
|
-
text: z.string()
|
|
57
|
-
});
|
|
58
|
-
var BinaryInputContentObjectSchema = z.object({
|
|
59
|
-
type: z.literal("binary"),
|
|
60
|
-
mimeType: z.string(),
|
|
61
|
-
id: z.string().optional(),
|
|
62
|
-
url: z.string().optional(),
|
|
63
|
-
data: z.string().optional(),
|
|
64
|
-
filename: z.string().optional()
|
|
65
|
-
});
|
|
66
|
-
var ensureBinaryPayload = (value, ctx) => {
|
|
67
|
-
if (!value.id && !value.url && !value.data) {
|
|
68
|
-
ctx.addIssue({
|
|
69
|
-
code: z.ZodIssueCode.custom,
|
|
70
|
-
message: "BinaryInputContent requires at least one of id, url, or data.",
|
|
71
|
-
path: ["id"]
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
var BinaryInputContentSchema = BinaryInputContentObjectSchema.superRefine((value, ctx) => {
|
|
76
|
-
ensureBinaryPayload(value, ctx);
|
|
77
|
-
});
|
|
78
|
-
var InputContentBaseSchema = z.discriminatedUnion("type", [
|
|
79
|
-
TextInputContentSchema,
|
|
80
|
-
BinaryInputContentObjectSchema
|
|
81
|
-
]);
|
|
82
|
-
var InputContentSchema = InputContentBaseSchema.superRefine((value, ctx) => {
|
|
83
|
-
if (value.type === "binary") {
|
|
84
|
-
ensureBinaryPayload(value, ctx);
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
var DeveloperMessageSchema = BaseMessageSchema.extend({
|
|
88
|
-
role: z.literal("developer"),
|
|
89
|
-
content: z.string()
|
|
90
|
-
});
|
|
91
|
-
var SystemMessageSchema = BaseMessageSchema.extend({
|
|
92
|
-
role: z.literal("system"),
|
|
93
|
-
content: z.string()
|
|
94
|
-
});
|
|
95
|
-
var AssistantMessageSchema = BaseMessageSchema.extend({
|
|
96
|
-
role: z.literal("assistant"),
|
|
97
|
-
content: z.string().optional(),
|
|
98
|
-
toolCalls: z.array(ToolCallSchema).optional()
|
|
99
|
-
});
|
|
100
|
-
var UserMessageSchema = BaseMessageSchema.extend({
|
|
101
|
-
role: z.literal("user"),
|
|
102
|
-
content: z.union([z.string(), z.array(InputContentSchema)])
|
|
103
|
-
});
|
|
104
|
-
var ToolMessageSchema = z.object({
|
|
105
|
-
id: z.string(),
|
|
106
|
-
content: z.string(),
|
|
107
|
-
role: z.literal("tool"),
|
|
108
|
-
toolCallId: z.string(),
|
|
109
|
-
error: z.string().optional()
|
|
110
|
-
});
|
|
111
|
-
var ActivityMessageSchema = z.object({
|
|
112
|
-
id: z.string(),
|
|
113
|
-
role: z.literal("activity"),
|
|
114
|
-
activityType: z.string(),
|
|
115
|
-
content: z.record(z.any())
|
|
116
|
-
});
|
|
117
|
-
var MessageSchema = z.discriminatedUnion("role", [
|
|
118
|
-
DeveloperMessageSchema,
|
|
119
|
-
SystemMessageSchema,
|
|
120
|
-
AssistantMessageSchema,
|
|
121
|
-
UserMessageSchema,
|
|
122
|
-
ToolMessageSchema,
|
|
123
|
-
ActivityMessageSchema
|
|
124
|
-
]);
|
|
125
|
-
var RoleSchema = z.union([
|
|
126
|
-
z.literal("developer"),
|
|
127
|
-
z.literal("system"),
|
|
128
|
-
z.literal("assistant"),
|
|
129
|
-
z.literal("user"),
|
|
130
|
-
z.literal("tool"),
|
|
131
|
-
z.literal("activity")
|
|
132
|
-
]);
|
|
133
|
-
var ContextSchema = z.object({
|
|
134
|
-
description: z.string(),
|
|
135
|
-
value: z.string()
|
|
136
|
-
});
|
|
137
|
-
var ToolSchema = z.object({
|
|
138
|
-
name: z.string(),
|
|
139
|
-
description: z.string(),
|
|
140
|
-
parameters: z.any()
|
|
141
|
-
// JSON Schema for the tool parameters
|
|
142
|
-
});
|
|
143
|
-
var RunAgentInputSchema = z.object({
|
|
144
|
-
threadId: z.string(),
|
|
145
|
-
runId: z.string(),
|
|
146
|
-
parentRunId: z.string().optional(),
|
|
147
|
-
state: z.any(),
|
|
148
|
-
messages: z.array(MessageSchema),
|
|
149
|
-
tools: z.array(ToolSchema),
|
|
150
|
-
context: z.array(ContextSchema),
|
|
151
|
-
forwardedProps: z.any()
|
|
152
|
-
});
|
|
153
|
-
var StateSchema = z.any();
|
|
154
|
-
var AGUIError = class extends Error {
|
|
155
|
-
constructor(message) {
|
|
156
|
-
super(message);
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
var AGUIConnectNotImplementedError = class extends AGUIError {
|
|
160
|
-
constructor() {
|
|
161
|
-
super("Connect not implemented. This method is not supported by the current agent.");
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
var TextMessageRoleSchema = z2.union([
|
|
165
|
-
z2.literal("developer"),
|
|
166
|
-
z2.literal("system"),
|
|
167
|
-
z2.literal("assistant"),
|
|
168
|
-
z2.literal("user")
|
|
169
|
-
]);
|
|
170
|
-
var EventType = /* @__PURE__ */ ((EventType2) => {
|
|
171
|
-
EventType2["TEXT_MESSAGE_START"] = "TEXT_MESSAGE_START";
|
|
172
|
-
EventType2["TEXT_MESSAGE_CONTENT"] = "TEXT_MESSAGE_CONTENT";
|
|
173
|
-
EventType2["TEXT_MESSAGE_END"] = "TEXT_MESSAGE_END";
|
|
174
|
-
EventType2["TEXT_MESSAGE_CHUNK"] = "TEXT_MESSAGE_CHUNK";
|
|
175
|
-
EventType2["THINKING_TEXT_MESSAGE_START"] = "THINKING_TEXT_MESSAGE_START";
|
|
176
|
-
EventType2["THINKING_TEXT_MESSAGE_CONTENT"] = "THINKING_TEXT_MESSAGE_CONTENT";
|
|
177
|
-
EventType2["THINKING_TEXT_MESSAGE_END"] = "THINKING_TEXT_MESSAGE_END";
|
|
178
|
-
EventType2["TOOL_CALL_START"] = "TOOL_CALL_START";
|
|
179
|
-
EventType2["TOOL_CALL_ARGS"] = "TOOL_CALL_ARGS";
|
|
180
|
-
EventType2["TOOL_CALL_END"] = "TOOL_CALL_END";
|
|
181
|
-
EventType2["TOOL_CALL_CHUNK"] = "TOOL_CALL_CHUNK";
|
|
182
|
-
EventType2["TOOL_CALL_RESULT"] = "TOOL_CALL_RESULT";
|
|
183
|
-
EventType2["THINKING_START"] = "THINKING_START";
|
|
184
|
-
EventType2["THINKING_END"] = "THINKING_END";
|
|
185
|
-
EventType2["STATE_SNAPSHOT"] = "STATE_SNAPSHOT";
|
|
186
|
-
EventType2["STATE_DELTA"] = "STATE_DELTA";
|
|
187
|
-
EventType2["MESSAGES_SNAPSHOT"] = "MESSAGES_SNAPSHOT";
|
|
188
|
-
EventType2["ACTIVITY_SNAPSHOT"] = "ACTIVITY_SNAPSHOT";
|
|
189
|
-
EventType2["ACTIVITY_DELTA"] = "ACTIVITY_DELTA";
|
|
190
|
-
EventType2["RAW"] = "RAW";
|
|
191
|
-
EventType2["CUSTOM"] = "CUSTOM";
|
|
192
|
-
EventType2["RUN_STARTED"] = "RUN_STARTED";
|
|
193
|
-
EventType2["RUN_FINISHED"] = "RUN_FINISHED";
|
|
194
|
-
EventType2["RUN_ERROR"] = "RUN_ERROR";
|
|
195
|
-
EventType2["STEP_STARTED"] = "STEP_STARTED";
|
|
196
|
-
EventType2["STEP_FINISHED"] = "STEP_FINISHED";
|
|
197
|
-
return EventType2;
|
|
198
|
-
})(EventType || {});
|
|
199
|
-
var BaseEventSchema = z2.object({
|
|
200
|
-
type: z2.nativeEnum(EventType),
|
|
201
|
-
timestamp: z2.number().optional(),
|
|
202
|
-
rawEvent: z2.any().optional()
|
|
203
|
-
});
|
|
204
|
-
var TextMessageStartEventSchema = BaseEventSchema.extend({
|
|
205
|
-
type: z2.literal(
|
|
206
|
-
"TEXT_MESSAGE_START"
|
|
207
|
-
/* TEXT_MESSAGE_START */
|
|
208
|
-
),
|
|
209
|
-
messageId: z2.string(),
|
|
210
|
-
role: TextMessageRoleSchema.default("assistant")
|
|
211
|
-
});
|
|
212
|
-
var TextMessageContentEventSchema = BaseEventSchema.extend({
|
|
213
|
-
type: z2.literal(
|
|
214
|
-
"TEXT_MESSAGE_CONTENT"
|
|
215
|
-
/* TEXT_MESSAGE_CONTENT */
|
|
216
|
-
),
|
|
217
|
-
messageId: z2.string(),
|
|
218
|
-
delta: z2.string().refine((s) => s.length > 0, "Delta must not be an empty string")
|
|
219
|
-
});
|
|
220
|
-
var TextMessageEndEventSchema = BaseEventSchema.extend({
|
|
221
|
-
type: z2.literal(
|
|
222
|
-
"TEXT_MESSAGE_END"
|
|
223
|
-
/* TEXT_MESSAGE_END */
|
|
224
|
-
),
|
|
225
|
-
messageId: z2.string()
|
|
226
|
-
});
|
|
227
|
-
var TextMessageChunkEventSchema = BaseEventSchema.extend({
|
|
228
|
-
type: z2.literal(
|
|
229
|
-
"TEXT_MESSAGE_CHUNK"
|
|
230
|
-
/* TEXT_MESSAGE_CHUNK */
|
|
231
|
-
),
|
|
232
|
-
messageId: z2.string().optional(),
|
|
233
|
-
role: TextMessageRoleSchema.optional(),
|
|
234
|
-
delta: z2.string().optional()
|
|
235
|
-
});
|
|
236
|
-
var ThinkingTextMessageStartEventSchema = BaseEventSchema.extend({
|
|
237
|
-
type: z2.literal(
|
|
238
|
-
"THINKING_TEXT_MESSAGE_START"
|
|
239
|
-
/* THINKING_TEXT_MESSAGE_START */
|
|
240
|
-
)
|
|
241
|
-
});
|
|
242
|
-
var ThinkingTextMessageContentEventSchema = TextMessageContentEventSchema.omit({
|
|
243
|
-
messageId: true,
|
|
244
|
-
type: true
|
|
245
|
-
}).extend({
|
|
246
|
-
type: z2.literal(
|
|
247
|
-
"THINKING_TEXT_MESSAGE_CONTENT"
|
|
248
|
-
/* THINKING_TEXT_MESSAGE_CONTENT */
|
|
249
|
-
)
|
|
250
|
-
});
|
|
251
|
-
var ThinkingTextMessageEndEventSchema = BaseEventSchema.extend({
|
|
252
|
-
type: z2.literal(
|
|
253
|
-
"THINKING_TEXT_MESSAGE_END"
|
|
254
|
-
/* THINKING_TEXT_MESSAGE_END */
|
|
255
|
-
)
|
|
256
|
-
});
|
|
257
|
-
var ToolCallStartEventSchema = BaseEventSchema.extend({
|
|
258
|
-
type: z2.literal(
|
|
259
|
-
"TOOL_CALL_START"
|
|
260
|
-
/* TOOL_CALL_START */
|
|
261
|
-
),
|
|
262
|
-
toolCallId: z2.string(),
|
|
263
|
-
toolCallName: z2.string(),
|
|
264
|
-
parentMessageId: z2.string().optional()
|
|
265
|
-
});
|
|
266
|
-
var ToolCallArgsEventSchema = BaseEventSchema.extend({
|
|
267
|
-
type: z2.literal(
|
|
268
|
-
"TOOL_CALL_ARGS"
|
|
269
|
-
/* TOOL_CALL_ARGS */
|
|
270
|
-
),
|
|
271
|
-
toolCallId: z2.string(),
|
|
272
|
-
delta: z2.string()
|
|
273
|
-
});
|
|
274
|
-
var ToolCallEndEventSchema = BaseEventSchema.extend({
|
|
275
|
-
type: z2.literal(
|
|
276
|
-
"TOOL_CALL_END"
|
|
277
|
-
/* TOOL_CALL_END */
|
|
278
|
-
),
|
|
279
|
-
toolCallId: z2.string()
|
|
280
|
-
});
|
|
281
|
-
var ToolCallResultEventSchema = BaseEventSchema.extend({
|
|
282
|
-
messageId: z2.string(),
|
|
283
|
-
type: z2.literal(
|
|
284
|
-
"TOOL_CALL_RESULT"
|
|
285
|
-
/* TOOL_CALL_RESULT */
|
|
286
|
-
),
|
|
287
|
-
toolCallId: z2.string(),
|
|
288
|
-
content: z2.string(),
|
|
289
|
-
role: z2.literal("tool").optional()
|
|
290
|
-
});
|
|
291
|
-
var ToolCallChunkEventSchema = BaseEventSchema.extend({
|
|
292
|
-
type: z2.literal(
|
|
293
|
-
"TOOL_CALL_CHUNK"
|
|
294
|
-
/* TOOL_CALL_CHUNK */
|
|
295
|
-
),
|
|
296
|
-
toolCallId: z2.string().optional(),
|
|
297
|
-
toolCallName: z2.string().optional(),
|
|
298
|
-
parentMessageId: z2.string().optional(),
|
|
299
|
-
delta: z2.string().optional()
|
|
300
|
-
});
|
|
301
|
-
var ThinkingStartEventSchema = BaseEventSchema.extend({
|
|
302
|
-
type: z2.literal(
|
|
303
|
-
"THINKING_START"
|
|
304
|
-
/* THINKING_START */
|
|
305
|
-
),
|
|
306
|
-
title: z2.string().optional()
|
|
307
|
-
});
|
|
308
|
-
var ThinkingEndEventSchema = BaseEventSchema.extend({
|
|
309
|
-
type: z2.literal(
|
|
310
|
-
"THINKING_END"
|
|
311
|
-
/* THINKING_END */
|
|
312
|
-
)
|
|
313
|
-
});
|
|
314
|
-
var StateSnapshotEventSchema = BaseEventSchema.extend({
|
|
315
|
-
type: z2.literal(
|
|
316
|
-
"STATE_SNAPSHOT"
|
|
317
|
-
/* STATE_SNAPSHOT */
|
|
318
|
-
),
|
|
319
|
-
snapshot: StateSchema
|
|
320
|
-
});
|
|
321
|
-
var StateDeltaEventSchema = BaseEventSchema.extend({
|
|
322
|
-
type: z2.literal(
|
|
323
|
-
"STATE_DELTA"
|
|
324
|
-
/* STATE_DELTA */
|
|
325
|
-
),
|
|
326
|
-
delta: z2.array(z2.any())
|
|
327
|
-
// JSON Patch (RFC 6902)
|
|
328
|
-
});
|
|
329
|
-
var MessagesSnapshotEventSchema = BaseEventSchema.extend({
|
|
330
|
-
type: z2.literal(
|
|
331
|
-
"MESSAGES_SNAPSHOT"
|
|
332
|
-
/* MESSAGES_SNAPSHOT */
|
|
333
|
-
),
|
|
334
|
-
messages: z2.array(MessageSchema)
|
|
335
|
-
});
|
|
336
|
-
var ActivitySnapshotEventSchema = BaseEventSchema.extend({
|
|
337
|
-
type: z2.literal(
|
|
338
|
-
"ACTIVITY_SNAPSHOT"
|
|
339
|
-
/* ACTIVITY_SNAPSHOT */
|
|
340
|
-
),
|
|
341
|
-
messageId: z2.string(),
|
|
342
|
-
activityType: z2.string(),
|
|
343
|
-
content: z2.record(z2.any()),
|
|
344
|
-
replace: z2.boolean().optional().default(true)
|
|
345
|
-
});
|
|
346
|
-
var ActivityDeltaEventSchema = BaseEventSchema.extend({
|
|
347
|
-
type: z2.literal(
|
|
348
|
-
"ACTIVITY_DELTA"
|
|
349
|
-
/* ACTIVITY_DELTA */
|
|
350
|
-
),
|
|
351
|
-
messageId: z2.string(),
|
|
352
|
-
activityType: z2.string(),
|
|
353
|
-
patch: z2.array(z2.any())
|
|
354
|
-
});
|
|
355
|
-
var RawEventSchema = BaseEventSchema.extend({
|
|
356
|
-
type: z2.literal(
|
|
357
|
-
"RAW"
|
|
358
|
-
/* RAW */
|
|
359
|
-
),
|
|
360
|
-
event: z2.any(),
|
|
361
|
-
source: z2.string().optional()
|
|
362
|
-
});
|
|
363
|
-
var CustomEventSchema = BaseEventSchema.extend({
|
|
364
|
-
type: z2.literal(
|
|
365
|
-
"CUSTOM"
|
|
366
|
-
/* CUSTOM */
|
|
367
|
-
),
|
|
368
|
-
name: z2.string(),
|
|
369
|
-
value: z2.any()
|
|
370
|
-
});
|
|
371
|
-
var RunStartedEventSchema = BaseEventSchema.extend({
|
|
372
|
-
type: z2.literal(
|
|
373
|
-
"RUN_STARTED"
|
|
374
|
-
/* RUN_STARTED */
|
|
375
|
-
),
|
|
376
|
-
threadId: z2.string(),
|
|
377
|
-
runId: z2.string(),
|
|
378
|
-
parentRunId: z2.string().optional(),
|
|
379
|
-
input: RunAgentInputSchema.optional()
|
|
380
|
-
});
|
|
381
|
-
var RunFinishedEventSchema = BaseEventSchema.extend({
|
|
382
|
-
type: z2.literal(
|
|
383
|
-
"RUN_FINISHED"
|
|
384
|
-
/* RUN_FINISHED */
|
|
385
|
-
),
|
|
386
|
-
threadId: z2.string(),
|
|
387
|
-
runId: z2.string(),
|
|
388
|
-
result: z2.any().optional()
|
|
389
|
-
});
|
|
390
|
-
var RunErrorEventSchema = BaseEventSchema.extend({
|
|
391
|
-
type: z2.literal(
|
|
392
|
-
"RUN_ERROR"
|
|
393
|
-
/* RUN_ERROR */
|
|
394
|
-
),
|
|
395
|
-
message: z2.string(),
|
|
396
|
-
code: z2.string().optional()
|
|
397
|
-
});
|
|
398
|
-
var StepStartedEventSchema = BaseEventSchema.extend({
|
|
399
|
-
type: z2.literal(
|
|
400
|
-
"STEP_STARTED"
|
|
401
|
-
/* STEP_STARTED */
|
|
402
|
-
),
|
|
403
|
-
stepName: z2.string()
|
|
404
|
-
});
|
|
405
|
-
var StepFinishedEventSchema = BaseEventSchema.extend({
|
|
406
|
-
type: z2.literal(
|
|
407
|
-
"STEP_FINISHED"
|
|
408
|
-
/* STEP_FINISHED */
|
|
409
|
-
),
|
|
410
|
-
stepName: z2.string()
|
|
411
|
-
});
|
|
412
|
-
var EventSchemas = z2.discriminatedUnion("type", [
|
|
413
|
-
TextMessageStartEventSchema,
|
|
414
|
-
TextMessageContentEventSchema,
|
|
415
|
-
TextMessageEndEventSchema,
|
|
416
|
-
TextMessageChunkEventSchema,
|
|
417
|
-
ThinkingStartEventSchema,
|
|
418
|
-
ThinkingEndEventSchema,
|
|
419
|
-
ThinkingTextMessageStartEventSchema,
|
|
420
|
-
ThinkingTextMessageContentEventSchema,
|
|
421
|
-
ThinkingTextMessageEndEventSchema,
|
|
422
|
-
ToolCallStartEventSchema,
|
|
423
|
-
ToolCallArgsEventSchema,
|
|
424
|
-
ToolCallEndEventSchema,
|
|
425
|
-
ToolCallChunkEventSchema,
|
|
426
|
-
ToolCallResultEventSchema,
|
|
427
|
-
StateSnapshotEventSchema,
|
|
428
|
-
StateDeltaEventSchema,
|
|
429
|
-
MessagesSnapshotEventSchema,
|
|
430
|
-
ActivitySnapshotEventSchema,
|
|
431
|
-
ActivityDeltaEventSchema,
|
|
432
|
-
RawEventSchema,
|
|
433
|
-
CustomEventSchema,
|
|
434
|
-
RunStartedEventSchema,
|
|
435
|
-
RunFinishedEventSchema,
|
|
436
|
-
RunErrorEventSchema,
|
|
437
|
-
StepStartedEventSchema,
|
|
438
|
-
StepFinishedEventSchema
|
|
439
|
-
]);
|
|
440
|
-
|
|
441
|
-
// src/hooks/use-copilot-chat_internal.ts
|
|
442
|
-
function useConfigureSuggestions(suggestions) {
|
|
443
|
-
let suggestionsConfig;
|
|
444
|
-
if (Array.isArray(suggestions)) {
|
|
445
|
-
suggestionsConfig = {
|
|
446
|
-
suggestions,
|
|
447
|
-
available: "always"
|
|
448
|
-
};
|
|
449
|
-
} else if (suggestions === "auto") {
|
|
450
|
-
suggestionsConfig = {
|
|
451
|
-
available: suggestions === "auto" ? "always" : "disabled",
|
|
452
|
-
instructions: "Suggest what the user could say next. Provide clear, highly relevant suggestions. Do not literally suggest function calls."
|
|
453
|
-
};
|
|
454
|
-
} else {
|
|
455
|
-
suggestionsConfig = { available: "disabled" };
|
|
456
|
-
}
|
|
457
|
-
useConfigureChatSuggestions(suggestionsConfig);
|
|
458
|
-
}
|
|
459
|
-
function useCopilotChatInternal({
|
|
460
|
-
suggestions
|
|
461
|
-
} = {}) {
|
|
462
|
-
var _a, _b, _c;
|
|
463
|
-
const { copilotkit } = useCopilotKit();
|
|
464
|
-
const { threadId, agentSession } = useCopilotContext();
|
|
465
|
-
const existingConfig = useCopilotChatConfiguration();
|
|
466
|
-
const [agentAvailable, setAgentAvailable] = useState(false);
|
|
467
|
-
useConfigureSuggestions(suggestions);
|
|
468
|
-
const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
|
|
469
|
-
const { agent } = useAgent({ agentId: resolvedAgentId });
|
|
470
|
-
useEffect(() => {
|
|
471
|
-
const connect = (agent2) => __async(this, null, function* () {
|
|
472
|
-
setAgentAvailable(false);
|
|
473
|
-
try {
|
|
474
|
-
yield copilotkit.connectAgent({ agent: agent2 });
|
|
475
|
-
setAgentAvailable(true);
|
|
476
|
-
} catch (error) {
|
|
477
|
-
if (error instanceof AGUIConnectNotImplementedError) {
|
|
478
|
-
} else {
|
|
479
|
-
throw error;
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
});
|
|
483
|
-
if (agent && (existingConfig == null ? void 0 : existingConfig.threadId) && agent.threadId !== existingConfig.threadId) {
|
|
484
|
-
agent.threadId = existingConfig.threadId;
|
|
485
|
-
connect(agent);
|
|
486
|
-
}
|
|
487
|
-
return () => {
|
|
488
|
-
};
|
|
489
|
-
}, [existingConfig == null ? void 0 : existingConfig.threadId, agent, copilotkit, resolvedAgentId]);
|
|
490
|
-
const interrupt = useLangGraphInterruptRender(agent);
|
|
491
|
-
const reset = () => {
|
|
492
|
-
agent == null ? void 0 : agent.setMessages([]);
|
|
493
|
-
agent == null ? void 0 : agent.setState(null);
|
|
494
|
-
};
|
|
495
|
-
const deleteMessage = useCallback(
|
|
496
|
-
(messageId) => {
|
|
497
|
-
var _a2;
|
|
498
|
-
const filteredMessages = ((_a2 = agent == null ? void 0 : agent.messages) != null ? _a2 : []).filter(
|
|
499
|
-
(message) => message.id !== messageId
|
|
500
|
-
);
|
|
501
|
-
agent == null ? void 0 : agent.setMessages(filteredMessages);
|
|
502
|
-
},
|
|
503
|
-
[agent == null ? void 0 : agent.setMessages, agent == null ? void 0 : agent.messages]
|
|
504
|
-
);
|
|
505
|
-
const latestDelete = useUpdatedRef(deleteMessage);
|
|
506
|
-
const latestDeleteFunc = useCallback(
|
|
507
|
-
(messageId) => {
|
|
508
|
-
return latestDelete.current(messageId);
|
|
509
|
-
},
|
|
510
|
-
[latestDelete]
|
|
511
|
-
);
|
|
512
|
-
const currentSuggestions = useSuggestions({ agentId: resolvedAgentId });
|
|
513
|
-
const reload = useAsyncCallback(
|
|
514
|
-
(reloadMessageId) => __async(this, null, function* () {
|
|
515
|
-
var _a2;
|
|
516
|
-
const messages = (_a2 = agent == null ? void 0 : agent.messages) != null ? _a2 : [];
|
|
517
|
-
const isLoading = false;
|
|
518
|
-
if (isLoading || messages.length === 0) {
|
|
519
|
-
return;
|
|
520
|
-
}
|
|
521
|
-
const reloadMessageIndex = messages.findIndex((msg) => msg.id === reloadMessageId);
|
|
522
|
-
if (reloadMessageIndex === -1) {
|
|
523
|
-
console.warn(`Message with id ${reloadMessageId} not found`);
|
|
524
|
-
return;
|
|
525
|
-
}
|
|
526
|
-
const reloadMessageRole = messages[reloadMessageIndex].role;
|
|
527
|
-
if (reloadMessageRole !== "assistant") {
|
|
528
|
-
console.warn(`Regenerate cannot be performed on ${reloadMessageRole} role`);
|
|
529
|
-
return;
|
|
530
|
-
}
|
|
531
|
-
let historyCutoff = [messages[0]];
|
|
532
|
-
if (messages.length > 2 && reloadMessageIndex !== 0) {
|
|
533
|
-
const lastUserMessageBeforeRegenerate = messages.slice(0, reloadMessageIndex).reverse().find((msg) => msg.role === "user");
|
|
534
|
-
if (!lastUserMessageBeforeRegenerate) {
|
|
535
|
-
historyCutoff = [messages[0]];
|
|
536
|
-
} else {
|
|
537
|
-
const indexOfLastUserMessageBeforeRegenerate = messages.findIndex(
|
|
538
|
-
(msg) => msg.id === lastUserMessageBeforeRegenerate.id
|
|
539
|
-
);
|
|
540
|
-
historyCutoff = messages.slice(0, indexOfLastUserMessageBeforeRegenerate + 1);
|
|
541
|
-
}
|
|
542
|
-
} else if (messages.length > 2 && reloadMessageIndex === 0) {
|
|
543
|
-
historyCutoff = [messages[0], messages[1]];
|
|
544
|
-
}
|
|
545
|
-
agent == null ? void 0 : agent.setMessages(historyCutoff);
|
|
546
|
-
if (agent) {
|
|
547
|
-
copilotkit.runAgent({ agent });
|
|
548
|
-
}
|
|
549
|
-
return;
|
|
550
|
-
}),
|
|
551
|
-
[agent == null ? void 0 : agent.setMessages, copilotkit == null ? void 0 : copilotkit.runAgent]
|
|
552
|
-
);
|
|
553
|
-
const latestSendMessageFunc = useAsyncCallback(
|
|
554
|
-
(message, options) => __async(this, null, function* () {
|
|
555
|
-
var _a2;
|
|
556
|
-
if (!agent)
|
|
557
|
-
return;
|
|
558
|
-
const followUp = (_a2 = options == null ? void 0 : options.followUp) != null ? _a2 : true;
|
|
559
|
-
if (options == null ? void 0 : options.clearSuggestions) {
|
|
560
|
-
copilotkit.clearSuggestions(resolvedAgentId);
|
|
561
|
-
}
|
|
562
|
-
agent == null ? void 0 : agent.addMessage(message);
|
|
563
|
-
if (followUp) {
|
|
564
|
-
try {
|
|
565
|
-
yield copilotkit.runAgent({ agent });
|
|
566
|
-
} catch (error) {
|
|
567
|
-
console.error("CopilotChat: runAgent failed", error);
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
}),
|
|
571
|
-
[agent, copilotkit, resolvedAgentId]
|
|
572
|
-
);
|
|
573
|
-
const latestAppendFunc = useAsyncCallback(
|
|
574
|
-
(message, options) => __async(this, null, function* () {
|
|
575
|
-
return latestSendMessageFunc(gqlToAGUI([message])[0], options);
|
|
576
|
-
}),
|
|
577
|
-
[latestSendMessageFunc]
|
|
578
|
-
);
|
|
579
|
-
const latestSetMessagesFunc = useCallback(
|
|
580
|
-
(messages) => {
|
|
581
|
-
var _a2, _b2;
|
|
582
|
-
if (messages.every((message) => message instanceof DeprecatedGqlMessage)) {
|
|
583
|
-
return (_a2 = agent == null ? void 0 : agent.setMessages) == null ? void 0 : _a2.call(agent, gqlToAGUI(messages));
|
|
584
|
-
}
|
|
585
|
-
return (_b2 = agent == null ? void 0 : agent.setMessages) == null ? void 0 : _b2.call(agent, messages);
|
|
586
|
-
},
|
|
587
|
-
[agent == null ? void 0 : agent.setMessages, agent]
|
|
588
|
-
);
|
|
589
|
-
const latestReload = useUpdatedRef(reload);
|
|
590
|
-
const latestReloadFunc = useAsyncCallback(
|
|
591
|
-
(messageId) => __async(this, null, function* () {
|
|
592
|
-
return yield latestReload.current(messageId);
|
|
593
|
-
}),
|
|
594
|
-
[latestReload]
|
|
595
|
-
);
|
|
596
|
-
const latestStopFunc = useCallback(() => {
|
|
597
|
-
var _a2;
|
|
598
|
-
return (_a2 = agent == null ? void 0 : agent.abortRun) == null ? void 0 : _a2.call(agent);
|
|
599
|
-
}, [agent == null ? void 0 : agent.abortRun]);
|
|
600
|
-
const latestReset = useUpdatedRef(reset);
|
|
601
|
-
const latestResetFunc = useCallback(() => {
|
|
602
|
-
return latestReset.current();
|
|
603
|
-
}, [latestReset]);
|
|
604
|
-
const lazyToolRendered = useLazyToolRenderer();
|
|
605
|
-
const renderCustomMessage = useRenderCustomMessages();
|
|
606
|
-
const legacyCustomMessageRenderer = useLegacyCoagentRenderer({
|
|
607
|
-
copilotkit,
|
|
608
|
-
agent,
|
|
609
|
-
agentId: resolvedAgentId,
|
|
610
|
-
threadId: (_b = existingConfig == null ? void 0 : existingConfig.threadId) != null ? _b : threadId
|
|
611
|
-
});
|
|
612
|
-
const allMessages = (_c = agent == null ? void 0 : agent.messages) != null ? _c : [];
|
|
613
|
-
const resolvedMessages = useMemo(() => {
|
|
614
|
-
let processedMessages = allMessages.map((message) => {
|
|
615
|
-
if (message.role !== "assistant") {
|
|
616
|
-
return message;
|
|
617
|
-
}
|
|
618
|
-
const lazyRendered = lazyToolRendered(message, allMessages);
|
|
619
|
-
if (lazyRendered) {
|
|
620
|
-
const renderedGenUi = lazyRendered();
|
|
621
|
-
if (renderedGenUi) {
|
|
622
|
-
return __spreadProps(__spreadValues({}, message), { generativeUI: () => renderedGenUi });
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
const bridgeRenderer = legacyCustomMessageRenderer || renderCustomMessage ? () => {
|
|
626
|
-
const customRender = renderCustomMessage == null ? void 0 : renderCustomMessage({
|
|
627
|
-
message,
|
|
628
|
-
position: "before"
|
|
629
|
-
});
|
|
630
|
-
if (customRender) {
|
|
631
|
-
return customRender;
|
|
632
|
-
}
|
|
633
|
-
return legacyCustomMessageRenderer == null ? void 0 : legacyCustomMessageRenderer({ message, position: "before" });
|
|
634
|
-
} : null;
|
|
635
|
-
if (bridgeRenderer) {
|
|
636
|
-
return __spreadProps(__spreadValues({}, message), { generativeUI: bridgeRenderer });
|
|
637
|
-
}
|
|
638
|
-
return message;
|
|
639
|
-
});
|
|
640
|
-
const hasAssistantMessages = processedMessages.some((msg) => msg.role === "assistant");
|
|
641
|
-
return processedMessages;
|
|
642
|
-
}, [
|
|
643
|
-
agent == null ? void 0 : agent.messages,
|
|
644
|
-
lazyToolRendered,
|
|
645
|
-
allMessages,
|
|
646
|
-
renderCustomMessage,
|
|
647
|
-
// legacyCustomMessageRenderer,
|
|
648
|
-
resolvedAgentId
|
|
649
|
-
]);
|
|
650
|
-
return {
|
|
651
|
-
messages: resolvedMessages,
|
|
652
|
-
sendMessage: latestSendMessageFunc,
|
|
653
|
-
appendMessage: latestAppendFunc,
|
|
654
|
-
setMessages: latestSetMessagesFunc,
|
|
655
|
-
reloadMessages: latestReloadFunc,
|
|
656
|
-
stopGeneration: latestStopFunc,
|
|
657
|
-
reset: latestResetFunc,
|
|
658
|
-
deleteMessage: latestDeleteFunc,
|
|
659
|
-
isAvailable: agentAvailable,
|
|
660
|
-
isLoading: Boolean(agent == null ? void 0 : agent.isRunning),
|
|
661
|
-
// mcpServers,
|
|
662
|
-
// setMcpServers,
|
|
663
|
-
suggestions: currentSuggestions.suggestions,
|
|
664
|
-
setSuggestions: (suggestions2) => copilotkit.addSuggestionsConfig({ suggestions: suggestions2 }),
|
|
665
|
-
generateSuggestions: () => __async(this, null, function* () {
|
|
666
|
-
return copilotkit.reloadSuggestions(resolvedAgentId);
|
|
667
|
-
}),
|
|
668
|
-
resetSuggestions: () => copilotkit.clearSuggestions(resolvedAgentId),
|
|
669
|
-
isLoadingSuggestions: currentSuggestions.isLoading,
|
|
670
|
-
interrupt,
|
|
671
|
-
agent,
|
|
672
|
-
threadId
|
|
673
|
-
};
|
|
674
|
-
}
|
|
675
|
-
function useUpdatedRef(value) {
|
|
676
|
-
const ref = useRef(value);
|
|
677
|
-
useEffect(() => {
|
|
678
|
-
ref.current = value;
|
|
679
|
-
}, [value]);
|
|
680
|
-
return ref;
|
|
681
|
-
}
|
|
682
|
-
function useLegacyCoagentRenderer({
|
|
683
|
-
copilotkit,
|
|
684
|
-
agent,
|
|
685
|
-
agentId,
|
|
686
|
-
threadId
|
|
687
|
-
}) {
|
|
688
|
-
return useMemo(() => {
|
|
689
|
-
if (!copilotkit || !agent) {
|
|
690
|
-
return null;
|
|
691
|
-
}
|
|
692
|
-
return ({ message, position }) => {
|
|
693
|
-
var _a;
|
|
694
|
-
const effectiveThreadId = (_a = threadId != null ? threadId : agent.threadId) != null ? _a : "default";
|
|
695
|
-
const existingRunId = copilotkit.getRunIdForMessage(agentId, effectiveThreadId, message.id);
|
|
696
|
-
const runId = existingRunId || `pending:${message.id}`;
|
|
697
|
-
const messageIndex = Math.max(
|
|
698
|
-
agent.messages.findIndex((msg) => msg.id === message.id),
|
|
699
|
-
0
|
|
700
|
-
);
|
|
701
|
-
const bridgeProps = {
|
|
702
|
-
message,
|
|
703
|
-
position,
|
|
704
|
-
runId,
|
|
705
|
-
messageIndex,
|
|
706
|
-
messageIndexInRun: 0,
|
|
707
|
-
numberOfMessagesInRun: 1,
|
|
708
|
-
agentId,
|
|
709
|
-
stateSnapshot: message.state
|
|
710
|
-
};
|
|
711
|
-
return createElement(CoAgentStateRenderBridge, bridgeProps);
|
|
712
|
-
};
|
|
713
|
-
}, [agent, agentId, copilotkit, threadId]);
|
|
714
|
-
}
|
|
715
|
-
function defaultSystemMessage(contextString, additionalInstructions) {
|
|
716
|
-
return `
|
|
717
|
-
Please act as an efficient, competent, conscientious, and industrious professional assistant.
|
|
718
|
-
|
|
719
|
-
Help 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.
|
|
720
|
-
Always be polite and respectful, and prefer brevity over verbosity.
|
|
721
|
-
|
|
722
|
-
The user has provided you with the following context:
|
|
723
|
-
\`\`\`
|
|
724
|
-
${contextString}
|
|
725
|
-
\`\`\`
|
|
726
|
-
|
|
727
|
-
They have also provided you with functions you can call to initiate actions on their behalf, or functions you can call to receive more information.
|
|
728
|
-
|
|
729
|
-
Please assist them as best you can.
|
|
730
|
-
|
|
731
|
-
You 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.
|
|
732
|
-
|
|
733
|
-
If you would like to call a function, call it without saying anything else.
|
|
734
|
-
In case of a function error:
|
|
735
|
-
- If this error stems from incorrect function parameters or syntax, you may retry with corrected arguments.
|
|
736
|
-
- If the error's source is unclear or seems unrelated to your input, do not attempt further retries.
|
|
737
|
-
` + (additionalInstructions ? `
|
|
738
|
-
|
|
739
|
-
${additionalInstructions}` : "");
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
export {
|
|
743
|
-
useCopilotChatInternal,
|
|
744
|
-
defaultSystemMessage
|
|
745
|
-
};
|
|
746
|
-
//# sourceMappingURL=chunk-EKDPRKZT.mjs.map
|