@firtoz/chat-agent 2.0.0 → 2.1.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/README.md +9 -1
- package/dist/chat-agent-base.d.ts +253 -0
- package/dist/chat-agent-base.js +4 -0
- package/dist/chat-agent-base.js.map +1 -0
- package/dist/chat-messages.d.ts +481 -0
- package/dist/chat-messages.js +3 -0
- package/dist/chat-messages.js.map +1 -0
- package/dist/chunk-G5P5JXRF.js +1068 -0
- package/dist/chunk-G5P5JXRF.js.map +1 -0
- package/dist/chunk-OEX3D4WL.js +292 -0
- package/dist/chunk-OEX3D4WL.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/package.json +17 -12
|
@@ -0,0 +1,481 @@
|
|
|
1
|
+
import * as z from 'zod/v4';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* JSON Schema for tool parameters (subset of JSON Schema 7)
|
|
5
|
+
*/
|
|
6
|
+
declare const JSONSchemaSchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
7
|
+
type JSONSchema = z.infer<typeof JSONSchemaSchema>;
|
|
8
|
+
/**
|
|
9
|
+
* Tool definition following OpenAI/OpenRouter format
|
|
10
|
+
* The schema is for wire format (no execute function)
|
|
11
|
+
*/
|
|
12
|
+
declare const ToolDefinitionSchema: z.ZodObject<{
|
|
13
|
+
type: z.ZodLiteral<"function">;
|
|
14
|
+
function: z.ZodObject<{
|
|
15
|
+
name: z.ZodString;
|
|
16
|
+
description: z.ZodOptional<z.ZodString>;
|
|
17
|
+
parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
18
|
+
strict: z.ZodOptional<z.ZodBoolean>;
|
|
19
|
+
}, z.core.$strip>;
|
|
20
|
+
}, z.core.$strip>;
|
|
21
|
+
/**
|
|
22
|
+
* Execute function signature for server-side tools
|
|
23
|
+
* Takes parsed arguments, returns JSON-serializable result
|
|
24
|
+
*/
|
|
25
|
+
type ToolExecuteFunction = (args: any) => unknown | Promise<unknown>;
|
|
26
|
+
/**
|
|
27
|
+
* Tool definition with optional execute function for server-side execution
|
|
28
|
+
* - If `execute` is provided: server runs it automatically and continues
|
|
29
|
+
* - If `execute` is omitted: tool call is sent to client for execution
|
|
30
|
+
*/
|
|
31
|
+
type ToolNeedsApprovalFn = (args: Record<string, unknown>) => boolean | Promise<boolean>;
|
|
32
|
+
type ToolDefinition = z.infer<typeof ToolDefinitionSchema> & {
|
|
33
|
+
/** Optional server-side execute function. If omitted, tool call goes to client. */
|
|
34
|
+
execute?: ToolExecuteFunction;
|
|
35
|
+
/**
|
|
36
|
+
* When `execute` is set, if this returns true the server waits for a client
|
|
37
|
+
* `toolApprovalResponse` before running `execute` (human-in-the-loop).
|
|
38
|
+
*/
|
|
39
|
+
needsApproval?: ToolNeedsApprovalFn;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* A tool call from the AI (complete, after streaming)
|
|
43
|
+
*/
|
|
44
|
+
declare const ToolCallSchema: z.ZodObject<{
|
|
45
|
+
id: z.ZodString;
|
|
46
|
+
type: z.ZodLiteral<"function">;
|
|
47
|
+
function: z.ZodObject<{
|
|
48
|
+
name: z.ZodString;
|
|
49
|
+
arguments: z.ZodString;
|
|
50
|
+
}, z.core.$strip>;
|
|
51
|
+
providerMetadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
52
|
+
}, z.core.$strip>;
|
|
53
|
+
type ToolCall = z.infer<typeof ToolCallSchema>;
|
|
54
|
+
/**
|
|
55
|
+
* Tool call delta during streaming
|
|
56
|
+
*/
|
|
57
|
+
declare const ToolCallDeltaSchema: z.ZodObject<{
|
|
58
|
+
index: z.ZodNumber;
|
|
59
|
+
id: z.ZodOptional<z.ZodString>;
|
|
60
|
+
type: z.ZodOptional<z.ZodLiteral<"function">>;
|
|
61
|
+
function: z.ZodOptional<z.ZodObject<{
|
|
62
|
+
name: z.ZodOptional<z.ZodString>;
|
|
63
|
+
arguments: z.ZodOptional<z.ZodString>;
|
|
64
|
+
}, z.core.$strip>>;
|
|
65
|
+
providerMetadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
66
|
+
}, z.core.$strip>;
|
|
67
|
+
type ToolCallDelta = z.infer<typeof ToolCallDeltaSchema>;
|
|
68
|
+
/**
|
|
69
|
+
* Tool result from client-side execution
|
|
70
|
+
*/
|
|
71
|
+
declare const ToolResultSchema: z.ZodObject<{
|
|
72
|
+
toolCallId: z.ZodString;
|
|
73
|
+
output: z.ZodUnknown;
|
|
74
|
+
}, z.core.$strip>;
|
|
75
|
+
type ToolResult = z.infer<typeof ToolResultSchema>;
|
|
76
|
+
/**
|
|
77
|
+
* User message
|
|
78
|
+
*/
|
|
79
|
+
declare const UserMessageSchema: z.ZodObject<{
|
|
80
|
+
id: z.ZodString;
|
|
81
|
+
role: z.ZodLiteral<"user">;
|
|
82
|
+
content: z.ZodString;
|
|
83
|
+
createdAt: z.ZodNumber;
|
|
84
|
+
}, z.core.$strip>;
|
|
85
|
+
type UserMessage = z.infer<typeof UserMessageSchema>;
|
|
86
|
+
/**
|
|
87
|
+
* Assistant message - can have content, tool calls, or both
|
|
88
|
+
*/
|
|
89
|
+
declare const AssistantMessageSchema: z.ZodObject<{
|
|
90
|
+
id: z.ZodString;
|
|
91
|
+
role: z.ZodLiteral<"assistant">;
|
|
92
|
+
content: z.ZodNullable<z.ZodString>;
|
|
93
|
+
toolCalls: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
94
|
+
id: z.ZodString;
|
|
95
|
+
type: z.ZodLiteral<"function">;
|
|
96
|
+
function: z.ZodObject<{
|
|
97
|
+
name: z.ZodString;
|
|
98
|
+
arguments: z.ZodString;
|
|
99
|
+
}, z.core.$strip>;
|
|
100
|
+
providerMetadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
101
|
+
}, z.core.$strip>>>;
|
|
102
|
+
createdAt: z.ZodNumber;
|
|
103
|
+
}, z.core.$strip>;
|
|
104
|
+
type AssistantMessage = z.infer<typeof AssistantMessageSchema>;
|
|
105
|
+
/**
|
|
106
|
+
* Tool response message (sent back to AI after tool execution)
|
|
107
|
+
*/
|
|
108
|
+
declare const ToolMessageSchema: z.ZodObject<{
|
|
109
|
+
id: z.ZodString;
|
|
110
|
+
role: z.ZodLiteral<"tool">;
|
|
111
|
+
toolCallId: z.ZodString;
|
|
112
|
+
content: z.ZodString;
|
|
113
|
+
createdAt: z.ZodNumber;
|
|
114
|
+
}, z.core.$strip>;
|
|
115
|
+
type ToolMessage = z.infer<typeof ToolMessageSchema>;
|
|
116
|
+
/**
|
|
117
|
+
* Union of all chat message types
|
|
118
|
+
*/
|
|
119
|
+
declare const ChatMessageSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
120
|
+
id: z.ZodString;
|
|
121
|
+
role: z.ZodLiteral<"user">;
|
|
122
|
+
content: z.ZodString;
|
|
123
|
+
createdAt: z.ZodNumber;
|
|
124
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
125
|
+
id: z.ZodString;
|
|
126
|
+
role: z.ZodLiteral<"assistant">;
|
|
127
|
+
content: z.ZodNullable<z.ZodString>;
|
|
128
|
+
toolCalls: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
129
|
+
id: z.ZodString;
|
|
130
|
+
type: z.ZodLiteral<"function">;
|
|
131
|
+
function: z.ZodObject<{
|
|
132
|
+
name: z.ZodString;
|
|
133
|
+
arguments: z.ZodString;
|
|
134
|
+
}, z.core.$strip>;
|
|
135
|
+
providerMetadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
136
|
+
}, z.core.$strip>>>;
|
|
137
|
+
createdAt: z.ZodNumber;
|
|
138
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
139
|
+
id: z.ZodString;
|
|
140
|
+
role: z.ZodLiteral<"tool">;
|
|
141
|
+
toolCallId: z.ZodString;
|
|
142
|
+
content: z.ZodString;
|
|
143
|
+
createdAt: z.ZodNumber;
|
|
144
|
+
}, z.core.$strip>], "role">;
|
|
145
|
+
type ChatMessage = z.infer<typeof ChatMessageSchema>;
|
|
146
|
+
declare const TokenUsageSchema: z.ZodObject<{
|
|
147
|
+
prompt_tokens: z.ZodNumber;
|
|
148
|
+
completion_tokens: z.ZodNumber;
|
|
149
|
+
total_tokens: z.ZodNumber;
|
|
150
|
+
}, z.core.$strip>;
|
|
151
|
+
type TokenUsage = z.infer<typeof TokenUsageSchema>;
|
|
152
|
+
declare const SendMessageTriggerSchema: z.ZodEnum<{
|
|
153
|
+
"submit-message": "submit-message";
|
|
154
|
+
"regenerate-message": "regenerate-message";
|
|
155
|
+
}>;
|
|
156
|
+
type SendMessageTrigger = z.infer<typeof SendMessageTriggerSchema>;
|
|
157
|
+
declare const ClientMessageSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
158
|
+
type: z.ZodLiteral<"sendMessage">;
|
|
159
|
+
content: z.ZodOptional<z.ZodString>;
|
|
160
|
+
messages: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
161
|
+
id: z.ZodString;
|
|
162
|
+
role: z.ZodLiteral<"user">;
|
|
163
|
+
content: z.ZodString;
|
|
164
|
+
createdAt: z.ZodNumber;
|
|
165
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
166
|
+
id: z.ZodString;
|
|
167
|
+
role: z.ZodLiteral<"assistant">;
|
|
168
|
+
content: z.ZodNullable<z.ZodString>;
|
|
169
|
+
toolCalls: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
170
|
+
id: z.ZodString;
|
|
171
|
+
type: z.ZodLiteral<"function">;
|
|
172
|
+
function: z.ZodObject<{
|
|
173
|
+
name: z.ZodString;
|
|
174
|
+
arguments: z.ZodString;
|
|
175
|
+
}, z.core.$strip>;
|
|
176
|
+
providerMetadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
177
|
+
}, z.core.$strip>>>;
|
|
178
|
+
createdAt: z.ZodNumber;
|
|
179
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
180
|
+
id: z.ZodString;
|
|
181
|
+
role: z.ZodLiteral<"tool">;
|
|
182
|
+
toolCallId: z.ZodString;
|
|
183
|
+
content: z.ZodString;
|
|
184
|
+
createdAt: z.ZodNumber;
|
|
185
|
+
}, z.core.$strip>], "role">>>;
|
|
186
|
+
trigger: z.ZodOptional<z.ZodEnum<{
|
|
187
|
+
"submit-message": "submit-message";
|
|
188
|
+
"regenerate-message": "regenerate-message";
|
|
189
|
+
}>>;
|
|
190
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
191
|
+
type: z.ZodLiteral<"clearHistory">;
|
|
192
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
193
|
+
type: z.ZodLiteral<"getHistory">;
|
|
194
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
195
|
+
type: z.ZodLiteral<"resumeStream">;
|
|
196
|
+
streamId: z.ZodString;
|
|
197
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
198
|
+
type: z.ZodLiteral<"cancelRequest">;
|
|
199
|
+
id: z.ZodString;
|
|
200
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
201
|
+
type: z.ZodLiteral<"toolResult">;
|
|
202
|
+
toolCallId: z.ZodString;
|
|
203
|
+
toolName: z.ZodString;
|
|
204
|
+
output: z.ZodUnknown;
|
|
205
|
+
autoContinue: z.ZodOptional<z.ZodBoolean>;
|
|
206
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
207
|
+
type: z.ZodLiteral<"toolApprovalResponse">;
|
|
208
|
+
approvalId: z.ZodString;
|
|
209
|
+
approved: z.ZodBoolean;
|
|
210
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
211
|
+
type: z.ZodLiteral<"registerTools">;
|
|
212
|
+
tools: z.ZodArray<z.ZodObject<{
|
|
213
|
+
name: z.ZodString;
|
|
214
|
+
description: z.ZodOptional<z.ZodString>;
|
|
215
|
+
parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
216
|
+
}, z.core.$strip>>;
|
|
217
|
+
}, z.core.$strip>], "type">;
|
|
218
|
+
type ClientMessage = z.infer<typeof ClientMessageSchema>;
|
|
219
|
+
type SendMessagePayload = Extract<ClientMessage, {
|
|
220
|
+
type: "sendMessage";
|
|
221
|
+
}>;
|
|
222
|
+
type ClearHistoryPayload = Extract<ClientMessage, {
|
|
223
|
+
type: "clearHistory";
|
|
224
|
+
}>;
|
|
225
|
+
type GetHistoryPayload = Extract<ClientMessage, {
|
|
226
|
+
type: "getHistory";
|
|
227
|
+
}>;
|
|
228
|
+
type ResumeStreamPayload = Extract<ClientMessage, {
|
|
229
|
+
type: "resumeStream";
|
|
230
|
+
}>;
|
|
231
|
+
type CancelRequestPayload = Extract<ClientMessage, {
|
|
232
|
+
type: "cancelRequest";
|
|
233
|
+
}>;
|
|
234
|
+
type ToolResultPayload = Extract<ClientMessage, {
|
|
235
|
+
type: "toolResult";
|
|
236
|
+
}>;
|
|
237
|
+
type ToolApprovalResponsePayload = Extract<ClientMessage, {
|
|
238
|
+
type: "toolApprovalResponse";
|
|
239
|
+
}>;
|
|
240
|
+
type RegisterToolsPayload = Extract<ClientMessage, {
|
|
241
|
+
type: "registerTools";
|
|
242
|
+
}>;
|
|
243
|
+
declare const ServerMessageSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
244
|
+
type: z.ZodLiteral<"history">;
|
|
245
|
+
messages: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
246
|
+
id: z.ZodString;
|
|
247
|
+
role: z.ZodLiteral<"user">;
|
|
248
|
+
content: z.ZodString;
|
|
249
|
+
createdAt: z.ZodNumber;
|
|
250
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
251
|
+
id: z.ZodString;
|
|
252
|
+
role: z.ZodLiteral<"assistant">;
|
|
253
|
+
content: z.ZodNullable<z.ZodString>;
|
|
254
|
+
toolCalls: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
255
|
+
id: z.ZodString;
|
|
256
|
+
type: z.ZodLiteral<"function">;
|
|
257
|
+
function: z.ZodObject<{
|
|
258
|
+
name: z.ZodString;
|
|
259
|
+
arguments: z.ZodString;
|
|
260
|
+
}, z.core.$strip>;
|
|
261
|
+
providerMetadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
262
|
+
}, z.core.$strip>>>;
|
|
263
|
+
createdAt: z.ZodNumber;
|
|
264
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
265
|
+
id: z.ZodString;
|
|
266
|
+
role: z.ZodLiteral<"tool">;
|
|
267
|
+
toolCallId: z.ZodString;
|
|
268
|
+
content: z.ZodString;
|
|
269
|
+
createdAt: z.ZodNumber;
|
|
270
|
+
}, z.core.$strip>], "role">>;
|
|
271
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
272
|
+
type: z.ZodLiteral<"messageStart">;
|
|
273
|
+
id: z.ZodString;
|
|
274
|
+
streamId: z.ZodString;
|
|
275
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
276
|
+
type: z.ZodLiteral<"messageChunk">;
|
|
277
|
+
id: z.ZodString;
|
|
278
|
+
chunk: z.ZodString;
|
|
279
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
280
|
+
type: z.ZodLiteral<"toolCallDelta">;
|
|
281
|
+
id: z.ZodString;
|
|
282
|
+
delta: z.ZodObject<{
|
|
283
|
+
index: z.ZodNumber;
|
|
284
|
+
id: z.ZodOptional<z.ZodString>;
|
|
285
|
+
type: z.ZodOptional<z.ZodLiteral<"function">>;
|
|
286
|
+
function: z.ZodOptional<z.ZodObject<{
|
|
287
|
+
name: z.ZodOptional<z.ZodString>;
|
|
288
|
+
arguments: z.ZodOptional<z.ZodString>;
|
|
289
|
+
}, z.core.$strip>>;
|
|
290
|
+
providerMetadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
291
|
+
}, z.core.$strip>;
|
|
292
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
293
|
+
type: z.ZodLiteral<"toolCall">;
|
|
294
|
+
id: z.ZodString;
|
|
295
|
+
toolCall: z.ZodObject<{
|
|
296
|
+
id: z.ZodString;
|
|
297
|
+
type: z.ZodLiteral<"function">;
|
|
298
|
+
function: z.ZodObject<{
|
|
299
|
+
name: z.ZodString;
|
|
300
|
+
arguments: z.ZodString;
|
|
301
|
+
}, z.core.$strip>;
|
|
302
|
+
providerMetadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
303
|
+
}, z.core.$strip>;
|
|
304
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
305
|
+
type: z.ZodLiteral<"messageEnd">;
|
|
306
|
+
id: z.ZodString;
|
|
307
|
+
toolCalls: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
308
|
+
id: z.ZodString;
|
|
309
|
+
type: z.ZodLiteral<"function">;
|
|
310
|
+
function: z.ZodObject<{
|
|
311
|
+
name: z.ZodString;
|
|
312
|
+
arguments: z.ZodString;
|
|
313
|
+
}, z.core.$strip>;
|
|
314
|
+
providerMetadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
315
|
+
}, z.core.$strip>>>;
|
|
316
|
+
createdAt: z.ZodNumber;
|
|
317
|
+
usage: z.ZodOptional<z.ZodObject<{
|
|
318
|
+
prompt_tokens: z.ZodNumber;
|
|
319
|
+
completion_tokens: z.ZodNumber;
|
|
320
|
+
total_tokens: z.ZodNumber;
|
|
321
|
+
}, z.core.$strip>>;
|
|
322
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
323
|
+
type: z.ZodLiteral<"streamResume">;
|
|
324
|
+
streamId: z.ZodString;
|
|
325
|
+
chunks: z.ZodArray<z.ZodString>;
|
|
326
|
+
done: z.ZodBoolean;
|
|
327
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
328
|
+
type: z.ZodLiteral<"streamResuming">;
|
|
329
|
+
id: z.ZodString;
|
|
330
|
+
streamId: z.ZodString;
|
|
331
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
332
|
+
type: z.ZodLiteral<"messageUpdated">;
|
|
333
|
+
message: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
334
|
+
id: z.ZodString;
|
|
335
|
+
role: z.ZodLiteral<"user">;
|
|
336
|
+
content: z.ZodString;
|
|
337
|
+
createdAt: z.ZodNumber;
|
|
338
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
339
|
+
id: z.ZodString;
|
|
340
|
+
role: z.ZodLiteral<"assistant">;
|
|
341
|
+
content: z.ZodNullable<z.ZodString>;
|
|
342
|
+
toolCalls: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
343
|
+
id: z.ZodString;
|
|
344
|
+
type: z.ZodLiteral<"function">;
|
|
345
|
+
function: z.ZodObject<{
|
|
346
|
+
name: z.ZodString;
|
|
347
|
+
arguments: z.ZodString;
|
|
348
|
+
}, z.core.$strip>;
|
|
349
|
+
providerMetadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
350
|
+
}, z.core.$strip>>>;
|
|
351
|
+
createdAt: z.ZodNumber;
|
|
352
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
353
|
+
id: z.ZodString;
|
|
354
|
+
role: z.ZodLiteral<"tool">;
|
|
355
|
+
toolCallId: z.ZodString;
|
|
356
|
+
content: z.ZodString;
|
|
357
|
+
createdAt: z.ZodNumber;
|
|
358
|
+
}, z.core.$strip>], "role">;
|
|
359
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
360
|
+
type: z.ZodLiteral<"error">;
|
|
361
|
+
message: z.ZodString;
|
|
362
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
363
|
+
type: z.ZodLiteral<"toolError">;
|
|
364
|
+
errorType: z.ZodEnum<{
|
|
365
|
+
input: "input";
|
|
366
|
+
output: "output";
|
|
367
|
+
not_found: "not_found";
|
|
368
|
+
}>;
|
|
369
|
+
toolCallId: z.ZodString;
|
|
370
|
+
toolName: z.ZodString;
|
|
371
|
+
message: z.ZodString;
|
|
372
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
373
|
+
type: z.ZodLiteral<"toolApprovalRequest">;
|
|
374
|
+
approvalId: z.ZodString;
|
|
375
|
+
toolCallId: z.ZodString;
|
|
376
|
+
toolName: z.ZodString;
|
|
377
|
+
arguments: z.ZodString;
|
|
378
|
+
}, z.core.$strip>], "type">;
|
|
379
|
+
type ServerMessage = z.infer<typeof ServerMessageSchema>;
|
|
380
|
+
type HistoryMessage = Extract<ServerMessage, {
|
|
381
|
+
type: "history";
|
|
382
|
+
}>;
|
|
383
|
+
type MessageStartMessage = Extract<ServerMessage, {
|
|
384
|
+
type: "messageStart";
|
|
385
|
+
}>;
|
|
386
|
+
type MessageChunkMessage = Extract<ServerMessage, {
|
|
387
|
+
type: "messageChunk";
|
|
388
|
+
}>;
|
|
389
|
+
type ToolCallDeltaMessage = Extract<ServerMessage, {
|
|
390
|
+
type: "toolCallDelta";
|
|
391
|
+
}>;
|
|
392
|
+
type ToolCallMessage = Extract<ServerMessage, {
|
|
393
|
+
type: "toolCall";
|
|
394
|
+
}>;
|
|
395
|
+
type MessageEndMessage = Extract<ServerMessage, {
|
|
396
|
+
type: "messageEnd";
|
|
397
|
+
}>;
|
|
398
|
+
type StreamResumeMessage = Extract<ServerMessage, {
|
|
399
|
+
type: "streamResume";
|
|
400
|
+
}>;
|
|
401
|
+
type StreamResumingMessage = Extract<ServerMessage, {
|
|
402
|
+
type: "streamResuming";
|
|
403
|
+
}>;
|
|
404
|
+
type MessageUpdatedMessage = Extract<ServerMessage, {
|
|
405
|
+
type: "messageUpdated";
|
|
406
|
+
}>;
|
|
407
|
+
type ErrorMessage = Extract<ServerMessage, {
|
|
408
|
+
type: "error";
|
|
409
|
+
}>;
|
|
410
|
+
type ToolErrorMessage = Extract<ServerMessage, {
|
|
411
|
+
type: "toolError";
|
|
412
|
+
}>;
|
|
413
|
+
type ToolApprovalRequestMessage = Extract<ServerMessage, {
|
|
414
|
+
type: "toolApprovalRequest";
|
|
415
|
+
}>;
|
|
416
|
+
/**
|
|
417
|
+
* Parse and validate a client message from JSON string
|
|
418
|
+
* @throws ZodError if validation fails
|
|
419
|
+
*/
|
|
420
|
+
declare function parseClientMessage(json: string): ClientMessage;
|
|
421
|
+
/**
|
|
422
|
+
* Safely parse a client message, returning null on failure
|
|
423
|
+
*/
|
|
424
|
+
declare function safeParseClientMessage(json: string): ClientMessage | null;
|
|
425
|
+
/**
|
|
426
|
+
* Parse and validate a server message from JSON string
|
|
427
|
+
* @throws ZodError if validation fails
|
|
428
|
+
*/
|
|
429
|
+
declare function parseServerMessage(json: string): ServerMessage;
|
|
430
|
+
/**
|
|
431
|
+
* Safely parse a server message, returning null on failure
|
|
432
|
+
*/
|
|
433
|
+
declare function safeParseServerMessage(json: string): ServerMessage | null;
|
|
434
|
+
declare function isClientMessage(data: unknown): data is ClientMessage;
|
|
435
|
+
declare function isServerMessage(data: unknown): data is ServerMessage;
|
|
436
|
+
declare function isUserMessage(msg: ChatMessage): msg is UserMessage;
|
|
437
|
+
declare function isAssistantMessage(msg: ChatMessage): msg is AssistantMessage;
|
|
438
|
+
declare function isToolMessage(msg: ChatMessage): msg is ToolMessage;
|
|
439
|
+
declare function hasToolCalls(msg: AssistantMessage): boolean;
|
|
440
|
+
/**
|
|
441
|
+
* Parse tool call arguments from JSON string
|
|
442
|
+
*/
|
|
443
|
+
declare function parseToolArguments<T = unknown>(toolCall: ToolCall): T;
|
|
444
|
+
/**
|
|
445
|
+
* Create a tool definition helper
|
|
446
|
+
*
|
|
447
|
+
* @example Server-side tool (executes automatically on server)
|
|
448
|
+
* ```ts
|
|
449
|
+
* defineTool({
|
|
450
|
+
* name: "get_weather",
|
|
451
|
+
* description: "Get current weather",
|
|
452
|
+
* parameters: { type: "object", properties: { location: { type: "string" } } },
|
|
453
|
+
* execute: async (args) => {
|
|
454
|
+
* const weather = await fetchWeather(args.location);
|
|
455
|
+
* return { temp: weather.temp, conditions: weather.desc };
|
|
456
|
+
* }
|
|
457
|
+
* })
|
|
458
|
+
* ```
|
|
459
|
+
*
|
|
460
|
+
* @example Client-side tool (sent to client for execution)
|
|
461
|
+
* ```ts
|
|
462
|
+
* defineTool({
|
|
463
|
+
* name: "get_user_location",
|
|
464
|
+
* description: "Get user's current location",
|
|
465
|
+
* parameters: { type: "object", properties: {} },
|
|
466
|
+
* // No execute function - client handles this
|
|
467
|
+
* })
|
|
468
|
+
* ```
|
|
469
|
+
*/
|
|
470
|
+
declare function defineTool(config: {
|
|
471
|
+
name: string;
|
|
472
|
+
description?: string;
|
|
473
|
+
parameters?: JSONSchema;
|
|
474
|
+
strict?: boolean;
|
|
475
|
+
/** Server-side execute function. If omitted, tool call goes to client. */
|
|
476
|
+
execute?: ToolExecuteFunction;
|
|
477
|
+
/** If set with `execute`, client must approve before the server runs `execute`. */
|
|
478
|
+
needsApproval?: ToolNeedsApprovalFn;
|
|
479
|
+
}): ToolDefinition;
|
|
480
|
+
|
|
481
|
+
export { type AssistantMessage, AssistantMessageSchema, type CancelRequestPayload, type ChatMessage, ChatMessageSchema, type ClearHistoryPayload, type ClientMessage, ClientMessageSchema, type ErrorMessage, type GetHistoryPayload, type HistoryMessage, type JSONSchema, JSONSchemaSchema, type MessageChunkMessage, type MessageEndMessage, type MessageStartMessage, type MessageUpdatedMessage, type RegisterToolsPayload, type ResumeStreamPayload, type SendMessagePayload, type SendMessageTrigger, SendMessageTriggerSchema, type ServerMessage, ServerMessageSchema, type StreamResumeMessage, type StreamResumingMessage, type TokenUsage, TokenUsageSchema, type ToolApprovalRequestMessage, type ToolApprovalResponsePayload, type ToolCall, type ToolCallDelta, type ToolCallDeltaMessage, ToolCallDeltaSchema, type ToolCallMessage, ToolCallSchema, type ToolDefinition, ToolDefinitionSchema, type ToolErrorMessage, type ToolExecuteFunction, type ToolMessage, ToolMessageSchema, type ToolNeedsApprovalFn, type ToolResult, type ToolResultPayload, ToolResultSchema, type UserMessage, UserMessageSchema, defineTool, hasToolCalls, isAssistantMessage, isClientMessage, isServerMessage, isToolMessage, isUserMessage, parseClientMessage, parseServerMessage, parseToolArguments, safeParseClientMessage, safeParseServerMessage };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { AssistantMessageSchema, ChatMessageSchema, ClientMessageSchema, JSONSchemaSchema, SendMessageTriggerSchema, ServerMessageSchema, TokenUsageSchema, ToolCallDeltaSchema, ToolCallSchema, ToolDefinitionSchema, ToolMessageSchema, ToolResultSchema, UserMessageSchema, defineTool, hasToolCalls, isAssistantMessage, isClientMessage, isServerMessage, isToolMessage, isUserMessage, parseClientMessage, parseServerMessage, parseToolArguments, safeParseClientMessage, safeParseServerMessage } from './chunk-OEX3D4WL.js';
|
|
2
|
+
//# sourceMappingURL=chat-messages.js.map
|
|
3
|
+
//# sourceMappingURL=chat-messages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"chat-messages.js"}
|