@builder.io/ai-utils 0.59.0 → 0.60.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/src/mapping.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { z } from "zod";
1
2
  import type { ESMImport } from "./codegen";
2
3
  export interface RawFigmaJson {
3
4
  documents: any[];
@@ -7,18 +8,18 @@ export interface RawFigmaJson {
7
8
  componentSets?: Record<string, any>;
8
9
  schemaVersion?: number;
9
10
  }
10
- export interface UserContext {
11
- client: string;
12
- clientVersion: string;
13
- nodeVersion: string;
14
- systemPlatform: string;
15
- frameworks: string[];
16
- systemEOL: string;
17
- systemArch: string;
18
- systemShell?: string;
19
- inGitRepo?: boolean;
20
- [key: string]: string | string[] | boolean | undefined;
21
- }
11
+ export declare const UserContextSchema: z.ZodObject<{
12
+ client: z.ZodString;
13
+ clientVersion: z.ZodString;
14
+ nodeVersion: z.ZodString;
15
+ systemPlatform: z.ZodString;
16
+ frameworks: z.ZodArray<z.ZodString>;
17
+ systemEOL: z.ZodString;
18
+ systemArch: z.ZodString;
19
+ systemShell: z.ZodOptional<z.ZodString>;
20
+ inGitRepo: z.ZodOptional<z.ZodBoolean>;
21
+ }, z.core.$catchall<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>, z.ZodBoolean, z.ZodUndefined]>>>;
22
+ export type UserContext = z.infer<typeof UserContextSchema>;
22
23
  export type ExportType = "default" | "named";
23
24
  /**
24
25
  * Gets the latest component mappings for a space
package/src/mapping.js CHANGED
@@ -1 +1,15 @@
1
- export {};
1
+ import { z } from "zod";
2
+ export const UserContextSchema = z
3
+ .object({
4
+ client: z.string(),
5
+ clientVersion: z.string(),
6
+ nodeVersion: z.string(),
7
+ systemPlatform: z.string(),
8
+ frameworks: z.array(z.string()),
9
+ systemEOL: z.string(),
10
+ systemArch: z.string(),
11
+ systemShell: z.string().optional(),
12
+ inGitRepo: z.boolean().optional(),
13
+ })
14
+ .catchall(z.union([z.string(), z.array(z.string()), z.boolean(), z.undefined()]))
15
+ .meta({ title: "UserContext" });
package/src/messages.d.ts CHANGED
@@ -1,24 +1,10 @@
1
+ import { z } from "zod";
1
2
  import type { ContentUpdatePatch } from "./events.js";
2
3
  /**
3
4
  * Message param does not know the id of the message.
4
5
  * This is an input message.
5
6
  */
6
7
  export type MessageParam = SystemMessageParam | UserMessageParam | AssistantMessageParam;
7
- export interface ContentMessageItemText {
8
- type: "text";
9
- text: string;
10
- cache?: boolean;
11
- citations?: TextCitationParam[] | null;
12
- ephemeral?: boolean;
13
- thoughtSignature?: string;
14
- tag?: string;
15
- }
16
- export interface ContentMessageItemImage {
17
- type: "image";
18
- source: ImageBase64Source | ImageUrlSource;
19
- cache?: boolean;
20
- ephemeral?: boolean;
21
- }
22
8
  export interface ContentMessageItemDocument {
23
9
  type: "document";
24
10
  source: DocumentBase64Source | DocumentUrlSource | DocumentTextSource;
@@ -32,15 +18,6 @@ export interface ContentMessageItemVideo {
32
18
  cache?: boolean;
33
19
  ephemeral?: boolean;
34
20
  }
35
- export interface ContentMessageItemResource {
36
- type: "resource";
37
- resource: {
38
- uri: string;
39
- mimeType?: string;
40
- text?: string;
41
- blob?: string;
42
- };
43
- }
44
21
  export interface DocumentBase64Source {
45
22
  type: "base64";
46
23
  media_type: "application/pdf";
@@ -56,28 +33,6 @@ export interface DocumentTextSource {
56
33
  media_type: "text/plain";
57
34
  data: string;
58
35
  }
59
- export interface ContentMessageItemToolResult {
60
- type: "tool_result";
61
- tool_use_id: string;
62
- tool_name?: string;
63
- tool_input?: string;
64
- title?: string;
65
- content: string | (ContentMessageItemText | ContentMessageItemImage | ContentMessageItemResource)[];
66
- is_error?: boolean;
67
- cache?: boolean;
68
- ephemeral?: boolean;
69
- structured_result?: Record<string, any>;
70
- }
71
- export interface ImageBase64Source {
72
- type: "base64";
73
- media_type: "image/webp" | "image/png" | "image/jpeg" | "image/gif";
74
- data: string;
75
- original_url?: string;
76
- }
77
- export interface ImageUrlSource {
78
- type: "url";
79
- url: string;
80
- }
81
36
  export interface VideoUrlSource {
82
37
  type: "url";
83
38
  url: string;
@@ -105,38 +60,6 @@ export interface ContentMessageItemToolUse {
105
60
  thoughtSignature?: string;
106
61
  name: string;
107
62
  }
108
- export interface CitationCharLocationParam {
109
- cited_text: string;
110
- document_index: number;
111
- document_title: string | null;
112
- end_char_index: number;
113
- start_char_index: number;
114
- type: "char_location";
115
- }
116
- export interface CitationContentBlockLocationParam {
117
- cited_text: string;
118
- document_index: number;
119
- document_title: string | null;
120
- end_block_index: number;
121
- start_block_index: number;
122
- type: "content_block_location";
123
- }
124
- export interface CitationPageLocationParam {
125
- cited_text: string;
126
- document_index: number;
127
- document_title: string | null;
128
- end_page_number: number;
129
- start_page_number: number;
130
- type: "page_location";
131
- }
132
- export interface CitationWebSearchResultLocationParam {
133
- cited_text: string;
134
- encrypted_index: string;
135
- title: string | null;
136
- type: "web_search_result_location";
137
- url: string;
138
- }
139
- export type TextCitationParam = CitationCharLocationParam | CitationPageLocationParam | CitationContentBlockLocationParam | CitationWebSearchResultLocationParam;
140
63
  export interface ServerToolUseContent {
141
64
  type: "web_search_result";
142
65
  title: string;
@@ -300,33 +223,308 @@ export interface AssistantActionMessage {
300
223
  export type Message = SystemMessage | UserMessage | AssistantMessage;
301
224
  export type GeneratingMessage = null | Partial<AssistantActionMessage | AssistantMessage>;
302
225
  export declare function getContentText(message: string | ContentMessage): string;
303
- export declare function getContentAttachments(message: string | ContentMessage): (ImageBase64Source | ImageUrlSource)[];
304
- export type Attachment = FileUpload | Template | URL | BuilderContentAttachment | FigmaContentAttachment;
305
- export interface URL {
226
+ export declare function getContentAttachments(message: string | ContentMessage): ({
227
+ type: "base64";
228
+ media_type: "image/webp" | "image/png" | "image/jpeg" | "image/gif";
229
+ data: string;
230
+ original_url?: string | undefined;
231
+ } | {
306
232
  type: "url";
307
- value: string;
308
- }
309
- export interface FileUpload {
310
- type: "upload";
311
- contentType: "image/webp" | "image/png" | "image/jpeg" | "image/gif" | "application/pdf" | "application/json" | "text/plain";
312
- name: string;
313
- dataUrl: string;
314
- text?: string;
315
- size: number;
316
- id: string;
317
- originalUrl?: string;
318
- ephemeral?: boolean;
319
- }
320
- export interface Template {
321
- type: "template";
322
- name: string;
323
- id: number;
324
- }
325
- export interface BuilderContentAttachment {
326
- type: "builder";
327
- html: string;
328
- }
329
- export interface FigmaContentAttachment {
330
- type: "figma";
331
- html: string;
332
- }
233
+ url: string;
234
+ })[];
235
+ export declare const URLSchema: z.ZodObject<{
236
+ type: z.ZodLiteral<"url">;
237
+ value: z.ZodString;
238
+ }, z.core.$strip>;
239
+ export type URL = z.infer<typeof URLSchema>;
240
+ export declare const FileUploadSchema: z.ZodObject<{
241
+ type: z.ZodLiteral<"upload">;
242
+ contentType: z.ZodEnum<{
243
+ "image/webp": "image/webp";
244
+ "image/png": "image/png";
245
+ "image/jpeg": "image/jpeg";
246
+ "image/gif": "image/gif";
247
+ "application/pdf": "application/pdf";
248
+ "application/json": "application/json";
249
+ "text/plain": "text/plain";
250
+ }>;
251
+ name: z.ZodString;
252
+ dataUrl: z.ZodString;
253
+ text: z.ZodOptional<z.ZodString>;
254
+ size: z.ZodNumber;
255
+ id: z.ZodString;
256
+ originalUrl: z.ZodOptional<z.ZodString>;
257
+ ephemeral: z.ZodOptional<z.ZodBoolean>;
258
+ }, z.core.$strip>;
259
+ export type FileUpload = z.infer<typeof FileUploadSchema>;
260
+ export declare const TemplateSchema: z.ZodObject<{
261
+ type: z.ZodLiteral<"template">;
262
+ name: z.ZodString;
263
+ id: z.ZodNumber;
264
+ }, z.core.$strip>;
265
+ export type Template = z.infer<typeof TemplateSchema>;
266
+ export declare const BuilderContentAttachmentSchema: z.ZodObject<{
267
+ type: z.ZodLiteral<"builder">;
268
+ html: z.ZodString;
269
+ }, z.core.$strip>;
270
+ export type BuilderContentAttachment = z.infer<typeof BuilderContentAttachmentSchema>;
271
+ export declare const FigmaContentAttachmentSchema: z.ZodObject<{
272
+ type: z.ZodLiteral<"figma">;
273
+ html: z.ZodString;
274
+ }, z.core.$strip>;
275
+ export type FigmaContentAttachment = z.infer<typeof FigmaContentAttachmentSchema>;
276
+ export declare const AttachmentSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
277
+ type: z.ZodLiteral<"upload">;
278
+ contentType: z.ZodEnum<{
279
+ "image/webp": "image/webp";
280
+ "image/png": "image/png";
281
+ "image/jpeg": "image/jpeg";
282
+ "image/gif": "image/gif";
283
+ "application/pdf": "application/pdf";
284
+ "application/json": "application/json";
285
+ "text/plain": "text/plain";
286
+ }>;
287
+ name: z.ZodString;
288
+ dataUrl: z.ZodString;
289
+ text: z.ZodOptional<z.ZodString>;
290
+ size: z.ZodNumber;
291
+ id: z.ZodString;
292
+ originalUrl: z.ZodOptional<z.ZodString>;
293
+ ephemeral: z.ZodOptional<z.ZodBoolean>;
294
+ }, z.core.$strip>, z.ZodObject<{
295
+ type: z.ZodLiteral<"template">;
296
+ name: z.ZodString;
297
+ id: z.ZodNumber;
298
+ }, z.core.$strip>, z.ZodObject<{
299
+ type: z.ZodLiteral<"url">;
300
+ value: z.ZodString;
301
+ }, z.core.$strip>, z.ZodObject<{
302
+ type: z.ZodLiteral<"builder">;
303
+ html: z.ZodString;
304
+ }, z.core.$strip>, z.ZodObject<{
305
+ type: z.ZodLiteral<"figma">;
306
+ html: z.ZodString;
307
+ }, z.core.$strip>], "type">;
308
+ export type Attachment = z.infer<typeof AttachmentSchema>;
309
+ export declare const CitationCharLocationParamSchema: z.ZodObject<{
310
+ cited_text: z.ZodString;
311
+ document_index: z.ZodNumber;
312
+ document_title: z.ZodNullable<z.ZodString>;
313
+ end_char_index: z.ZodNumber;
314
+ start_char_index: z.ZodNumber;
315
+ type: z.ZodLiteral<"char_location">;
316
+ }, z.core.$strip>;
317
+ export type CitationCharLocationParam = z.infer<typeof CitationCharLocationParamSchema>;
318
+ export declare const CitationContentBlockLocationParamSchema: z.ZodObject<{
319
+ cited_text: z.ZodString;
320
+ document_index: z.ZodNumber;
321
+ document_title: z.ZodNullable<z.ZodString>;
322
+ end_block_index: z.ZodNumber;
323
+ start_block_index: z.ZodNumber;
324
+ type: z.ZodLiteral<"content_block_location">;
325
+ }, z.core.$strip>;
326
+ export type CitationContentBlockLocationParam = z.infer<typeof CitationContentBlockLocationParamSchema>;
327
+ export declare const CitationPageLocationParamSchema: z.ZodObject<{
328
+ cited_text: z.ZodString;
329
+ document_index: z.ZodNumber;
330
+ document_title: z.ZodNullable<z.ZodString>;
331
+ end_page_number: z.ZodNumber;
332
+ start_page_number: z.ZodNumber;
333
+ type: z.ZodLiteral<"page_location">;
334
+ }, z.core.$strip>;
335
+ export type CitationPageLocationParam = z.infer<typeof CitationPageLocationParamSchema>;
336
+ export declare const CitationWebSearchResultLocationParamSchema: z.ZodObject<{
337
+ cited_text: z.ZodString;
338
+ encrypted_index: z.ZodString;
339
+ title: z.ZodNullable<z.ZodString>;
340
+ type: z.ZodLiteral<"web_search_result_location">;
341
+ url: z.ZodString;
342
+ }, z.core.$strip>;
343
+ export type CitationWebSearchResultLocationParam = z.infer<typeof CitationWebSearchResultLocationParamSchema>;
344
+ export declare const TextCitationParamSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
345
+ cited_text: z.ZodString;
346
+ document_index: z.ZodNumber;
347
+ document_title: z.ZodNullable<z.ZodString>;
348
+ end_char_index: z.ZodNumber;
349
+ start_char_index: z.ZodNumber;
350
+ type: z.ZodLiteral<"char_location">;
351
+ }, z.core.$strip>, z.ZodObject<{
352
+ cited_text: z.ZodString;
353
+ document_index: z.ZodNumber;
354
+ document_title: z.ZodNullable<z.ZodString>;
355
+ end_page_number: z.ZodNumber;
356
+ start_page_number: z.ZodNumber;
357
+ type: z.ZodLiteral<"page_location">;
358
+ }, z.core.$strip>, z.ZodObject<{
359
+ cited_text: z.ZodString;
360
+ document_index: z.ZodNumber;
361
+ document_title: z.ZodNullable<z.ZodString>;
362
+ end_block_index: z.ZodNumber;
363
+ start_block_index: z.ZodNumber;
364
+ type: z.ZodLiteral<"content_block_location">;
365
+ }, z.core.$strip>, z.ZodObject<{
366
+ cited_text: z.ZodString;
367
+ encrypted_index: z.ZodString;
368
+ title: z.ZodNullable<z.ZodString>;
369
+ type: z.ZodLiteral<"web_search_result_location">;
370
+ url: z.ZodString;
371
+ }, z.core.$strip>], "type">;
372
+ export type TextCitationParam = z.infer<typeof TextCitationParamSchema>;
373
+ export declare const ImageBase64SourceSchema: z.ZodObject<{
374
+ type: z.ZodLiteral<"base64">;
375
+ media_type: z.ZodEnum<{
376
+ "image/webp": "image/webp";
377
+ "image/png": "image/png";
378
+ "image/jpeg": "image/jpeg";
379
+ "image/gif": "image/gif";
380
+ }>;
381
+ data: z.ZodString;
382
+ original_url: z.ZodOptional<z.ZodString>;
383
+ }, z.core.$strip>;
384
+ export type ImageBase64Source = z.infer<typeof ImageBase64SourceSchema>;
385
+ export declare const ImageUrlSourceSchema: z.ZodObject<{
386
+ type: z.ZodLiteral<"url">;
387
+ url: z.ZodString;
388
+ }, z.core.$strip>;
389
+ export type ImageUrlSource = z.infer<typeof ImageUrlSourceSchema>;
390
+ export declare const ContentMessageItemTextSchema: z.ZodObject<{
391
+ type: z.ZodLiteral<"text">;
392
+ text: z.ZodString;
393
+ cache: z.ZodOptional<z.ZodBoolean>;
394
+ citations: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
395
+ cited_text: z.ZodString;
396
+ document_index: z.ZodNumber;
397
+ document_title: z.ZodNullable<z.ZodString>;
398
+ end_char_index: z.ZodNumber;
399
+ start_char_index: z.ZodNumber;
400
+ type: z.ZodLiteral<"char_location">;
401
+ }, z.core.$strip>, z.ZodObject<{
402
+ cited_text: z.ZodString;
403
+ document_index: z.ZodNumber;
404
+ document_title: z.ZodNullable<z.ZodString>;
405
+ end_page_number: z.ZodNumber;
406
+ start_page_number: z.ZodNumber;
407
+ type: z.ZodLiteral<"page_location">;
408
+ }, z.core.$strip>, z.ZodObject<{
409
+ cited_text: z.ZodString;
410
+ document_index: z.ZodNumber;
411
+ document_title: z.ZodNullable<z.ZodString>;
412
+ end_block_index: z.ZodNumber;
413
+ start_block_index: z.ZodNumber;
414
+ type: z.ZodLiteral<"content_block_location">;
415
+ }, z.core.$strip>, z.ZodObject<{
416
+ cited_text: z.ZodString;
417
+ encrypted_index: z.ZodString;
418
+ title: z.ZodNullable<z.ZodString>;
419
+ type: z.ZodLiteral<"web_search_result_location">;
420
+ url: z.ZodString;
421
+ }, z.core.$strip>], "type">>>>;
422
+ ephemeral: z.ZodOptional<z.ZodBoolean>;
423
+ thoughtSignature: z.ZodOptional<z.ZodString>;
424
+ tag: z.ZodOptional<z.ZodString>;
425
+ }, z.core.$strip>;
426
+ export type ContentMessageItemText = z.infer<typeof ContentMessageItemTextSchema>;
427
+ export declare const ContentMessageItemImageSchema: z.ZodObject<{
428
+ type: z.ZodLiteral<"image">;
429
+ source: z.ZodDiscriminatedUnion<[z.ZodObject<{
430
+ type: z.ZodLiteral<"base64">;
431
+ media_type: z.ZodEnum<{
432
+ "image/webp": "image/webp";
433
+ "image/png": "image/png";
434
+ "image/jpeg": "image/jpeg";
435
+ "image/gif": "image/gif";
436
+ }>;
437
+ data: z.ZodString;
438
+ original_url: z.ZodOptional<z.ZodString>;
439
+ }, z.core.$strip>, z.ZodObject<{
440
+ type: z.ZodLiteral<"url">;
441
+ url: z.ZodString;
442
+ }, z.core.$strip>], "type">;
443
+ cache: z.ZodOptional<z.ZodBoolean>;
444
+ ephemeral: z.ZodOptional<z.ZodBoolean>;
445
+ }, z.core.$strip>;
446
+ export type ContentMessageItemImage = z.infer<typeof ContentMessageItemImageSchema>;
447
+ export declare const ContentMessageItemResourceSchema: z.ZodObject<{
448
+ type: z.ZodLiteral<"resource">;
449
+ resource: z.ZodObject<{
450
+ uri: z.ZodString;
451
+ mimeType: z.ZodOptional<z.ZodString>;
452
+ text: z.ZodOptional<z.ZodString>;
453
+ blob: z.ZodOptional<z.ZodString>;
454
+ }, z.core.$strip>;
455
+ }, z.core.$strip>;
456
+ export type ContentMessageItemResource = z.infer<typeof ContentMessageItemResourceSchema>;
457
+ export declare const ContentMessageItemToolResultSchema: z.ZodObject<{
458
+ type: z.ZodLiteral<"tool_result">;
459
+ tool_use_id: z.ZodString;
460
+ tool_name: z.ZodOptional<z.ZodString>;
461
+ tool_input: z.ZodOptional<z.ZodString>;
462
+ title: z.ZodOptional<z.ZodString>;
463
+ content: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
464
+ type: z.ZodLiteral<"text">;
465
+ text: z.ZodString;
466
+ cache: z.ZodOptional<z.ZodBoolean>;
467
+ citations: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
468
+ cited_text: z.ZodString;
469
+ document_index: z.ZodNumber;
470
+ document_title: z.ZodNullable<z.ZodString>;
471
+ end_char_index: z.ZodNumber;
472
+ start_char_index: z.ZodNumber;
473
+ type: z.ZodLiteral<"char_location">;
474
+ }, z.core.$strip>, z.ZodObject<{
475
+ cited_text: z.ZodString;
476
+ document_index: z.ZodNumber;
477
+ document_title: z.ZodNullable<z.ZodString>;
478
+ end_page_number: z.ZodNumber;
479
+ start_page_number: z.ZodNumber;
480
+ type: z.ZodLiteral<"page_location">;
481
+ }, z.core.$strip>, z.ZodObject<{
482
+ cited_text: z.ZodString;
483
+ document_index: z.ZodNumber;
484
+ document_title: z.ZodNullable<z.ZodString>;
485
+ end_block_index: z.ZodNumber;
486
+ start_block_index: z.ZodNumber;
487
+ type: z.ZodLiteral<"content_block_location">;
488
+ }, z.core.$strip>, z.ZodObject<{
489
+ cited_text: z.ZodString;
490
+ encrypted_index: z.ZodString;
491
+ title: z.ZodNullable<z.ZodString>;
492
+ type: z.ZodLiteral<"web_search_result_location">;
493
+ url: z.ZodString;
494
+ }, z.core.$strip>], "type">>>>;
495
+ ephemeral: z.ZodOptional<z.ZodBoolean>;
496
+ thoughtSignature: z.ZodOptional<z.ZodString>;
497
+ tag: z.ZodOptional<z.ZodString>;
498
+ }, z.core.$strip>, z.ZodObject<{
499
+ type: z.ZodLiteral<"image">;
500
+ source: z.ZodDiscriminatedUnion<[z.ZodObject<{
501
+ type: z.ZodLiteral<"base64">;
502
+ media_type: z.ZodEnum<{
503
+ "image/webp": "image/webp";
504
+ "image/png": "image/png";
505
+ "image/jpeg": "image/jpeg";
506
+ "image/gif": "image/gif";
507
+ }>;
508
+ data: z.ZodString;
509
+ original_url: z.ZodOptional<z.ZodString>;
510
+ }, z.core.$strip>, z.ZodObject<{
511
+ type: z.ZodLiteral<"url">;
512
+ url: z.ZodString;
513
+ }, z.core.$strip>], "type">;
514
+ cache: z.ZodOptional<z.ZodBoolean>;
515
+ ephemeral: z.ZodOptional<z.ZodBoolean>;
516
+ }, z.core.$strip>, z.ZodObject<{
517
+ type: z.ZodLiteral<"resource">;
518
+ resource: z.ZodObject<{
519
+ uri: z.ZodString;
520
+ mimeType: z.ZodOptional<z.ZodString>;
521
+ text: z.ZodOptional<z.ZodString>;
522
+ blob: z.ZodOptional<z.ZodString>;
523
+ }, z.core.$strip>;
524
+ }, z.core.$strip>], "type">>]>;
525
+ is_error: z.ZodOptional<z.ZodBoolean>;
526
+ cache: z.ZodOptional<z.ZodBoolean>;
527
+ ephemeral: z.ZodOptional<z.ZodBoolean>;
528
+ structured_result: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
529
+ }, z.core.$strip>;
530
+ export type ContentMessageItemToolResult = z.infer<typeof ContentMessageItemToolResultSchema>;
package/src/messages.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { z } from "zod";
1
2
  export function getContentText(message) {
2
3
  if (typeof message === "string") {
3
4
  return message;
@@ -14,3 +15,160 @@ export function getContentAttachments(message) {
14
15
  .filter((item) => item.type === "image")
15
16
  .map((item) => item.source);
16
17
  }
18
+ export const URLSchema = z
19
+ .object({ type: z.literal("url"), value: z.string() })
20
+ .meta({ title: "URL" });
21
+ export const FileUploadSchema = z
22
+ .object({
23
+ type: z.literal("upload"),
24
+ contentType: z.enum([
25
+ "image/webp",
26
+ "image/png",
27
+ "image/jpeg",
28
+ "image/gif",
29
+ "application/pdf",
30
+ "application/json",
31
+ "text/plain",
32
+ ]),
33
+ name: z.string(),
34
+ dataUrl: z.string(),
35
+ text: z.string().optional(),
36
+ size: z.number(),
37
+ id: z.string(),
38
+ originalUrl: z.string().optional(),
39
+ ephemeral: z.boolean().optional(),
40
+ })
41
+ .meta({ title: "FileUpload" });
42
+ export const TemplateSchema = z
43
+ .object({ type: z.literal("template"), name: z.string(), id: z.number() })
44
+ .meta({ title: "Template" });
45
+ export const BuilderContentAttachmentSchema = z
46
+ .object({ type: z.literal("builder"), html: z.string() })
47
+ .meta({ title: "BuilderContentAttachment" });
48
+ export const FigmaContentAttachmentSchema = z
49
+ .object({ type: z.literal("figma"), html: z.string() })
50
+ .meta({ title: "FigmaContentAttachment" });
51
+ export const AttachmentSchema = z
52
+ .discriminatedUnion("type", [
53
+ FileUploadSchema,
54
+ TemplateSchema,
55
+ URLSchema,
56
+ BuilderContentAttachmentSchema,
57
+ FigmaContentAttachmentSchema,
58
+ ])
59
+ .meta({ title: "Attachment" });
60
+ export const CitationCharLocationParamSchema = z
61
+ .object({
62
+ cited_text: z.string(),
63
+ document_index: z.number(),
64
+ document_title: z.string().nullable(),
65
+ end_char_index: z.number(),
66
+ start_char_index: z.number(),
67
+ type: z.literal("char_location"),
68
+ })
69
+ .meta({ title: "CitationCharLocationParam" });
70
+ export const CitationContentBlockLocationParamSchema = z
71
+ .object({
72
+ cited_text: z.string(),
73
+ document_index: z.number(),
74
+ document_title: z.string().nullable(),
75
+ end_block_index: z.number(),
76
+ start_block_index: z.number(),
77
+ type: z.literal("content_block_location"),
78
+ })
79
+ .meta({ title: "CitationContentBlockLocationParam" });
80
+ export const CitationPageLocationParamSchema = z
81
+ .object({
82
+ cited_text: z.string(),
83
+ document_index: z.number(),
84
+ document_title: z.string().nullable(),
85
+ end_page_number: z.number(),
86
+ start_page_number: z.number(),
87
+ type: z.literal("page_location"),
88
+ })
89
+ .meta({ title: "CitationPageLocationParam" });
90
+ export const CitationWebSearchResultLocationParamSchema = z
91
+ .object({
92
+ cited_text: z.string(),
93
+ encrypted_index: z.string(),
94
+ title: z.string().nullable(),
95
+ type: z.literal("web_search_result_location"),
96
+ url: z.string(),
97
+ })
98
+ .meta({ title: "CitationWebSearchResultLocationParam" });
99
+ export const TextCitationParamSchema = z
100
+ .discriminatedUnion("type", [
101
+ CitationCharLocationParamSchema,
102
+ CitationPageLocationParamSchema,
103
+ CitationContentBlockLocationParamSchema,
104
+ CitationWebSearchResultLocationParamSchema,
105
+ ])
106
+ .meta({ title: "TextCitationParam" });
107
+ export const ImageBase64SourceSchema = z
108
+ .object({
109
+ type: z.literal("base64"),
110
+ media_type: z.enum(["image/webp", "image/png", "image/jpeg", "image/gif"]),
111
+ data: z.string(),
112
+ original_url: z.string().optional(),
113
+ })
114
+ .meta({ title: "ImageBase64Source" });
115
+ export const ImageUrlSourceSchema = z
116
+ .object({
117
+ type: z.literal("url"),
118
+ url: z.string(),
119
+ })
120
+ .meta({ title: "ImageUrlSource" });
121
+ export const ContentMessageItemTextSchema = z
122
+ .object({
123
+ type: z.literal("text"),
124
+ text: z.string(),
125
+ cache: z.boolean().optional(),
126
+ citations: z.array(TextCitationParamSchema).nullish(),
127
+ ephemeral: z.boolean().optional(),
128
+ thoughtSignature: z.string().optional(),
129
+ tag: z.string().optional(),
130
+ })
131
+ .meta({ title: "ContentMessageItemText" });
132
+ export const ContentMessageItemImageSchema = z
133
+ .object({
134
+ type: z.literal("image"),
135
+ source: z.discriminatedUnion("type", [
136
+ ImageBase64SourceSchema,
137
+ ImageUrlSourceSchema,
138
+ ]),
139
+ cache: z.boolean().optional(),
140
+ ephemeral: z.boolean().optional(),
141
+ })
142
+ .meta({ title: "ContentMessageItemImage" });
143
+ export const ContentMessageItemResourceSchema = z
144
+ .object({
145
+ type: z.literal("resource"),
146
+ resource: z.object({
147
+ uri: z.string(),
148
+ mimeType: z.string().optional(),
149
+ text: z.string().optional(),
150
+ blob: z.string().optional(),
151
+ }),
152
+ })
153
+ .meta({ title: "ContentMessageItemResource" });
154
+ export const ContentMessageItemToolResultSchema = z
155
+ .object({
156
+ type: z.literal("tool_result"),
157
+ tool_use_id: z.string(),
158
+ tool_name: z.string().optional(),
159
+ tool_input: z.string().optional(),
160
+ title: z.string().optional(),
161
+ content: z.union([
162
+ z.string(),
163
+ z.array(z.discriminatedUnion("type", [
164
+ ContentMessageItemTextSchema,
165
+ ContentMessageItemImageSchema,
166
+ ContentMessageItemResourceSchema,
167
+ ])),
168
+ ]),
169
+ is_error: z.boolean().optional(),
170
+ cache: z.boolean().optional(),
171
+ ephemeral: z.boolean().optional(),
172
+ structured_result: z.record(z.string(), z.any()).optional(),
173
+ })
174
+ .meta({ title: "ContentMessageItemToolResult" });