From 9f5b4bf00d506eb5914e001773143e5408a35133 Mon Sep 17 00:00:00 2001 From: Nathan Arseneau Date: Tue, 1 Apr 2025 19:01:22 -0400 Subject: [PATCH] Add audio content --- src/types.ts | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/types.ts b/src/types.ts index d051d8f7..b9c0ab37 100644 --- a/src/types.ts +++ b/src/types.ts @@ -666,6 +666,23 @@ export const ImageContentSchema = z }) .passthrough(); +/** + * An Audio provided to or from an LLM. + */ +export const AudioContentSchema = z + .object({ + type: z.literal("audio"), + /** + * The base64-encoded audio data. + */ + data: z.string().base64(), + /** + * The MIME type of the audio. Different providers may support different audio types. + */ + mimeType: z.string(), + }) + .passthrough(); + /** * The contents of a resource, embedded into a prompt or tool call result. */ @@ -685,6 +702,7 @@ export const PromptMessageSchema = z content: z.union([ TextContentSchema, ImageContentSchema, + AudioContentSchema, EmbeddedResourceSchema, ]), }) @@ -753,7 +771,7 @@ export const ListToolsResultSchema = PaginatedResultSchema.extend({ */ export const CallToolResultSchema = ResultSchema.extend({ content: z.array( - z.union([TextContentSchema, ImageContentSchema, EmbeddedResourceSchema]), + z.union([TextContentSchema, ImageContentSchema, AudioContentSchema, EmbeddedResourceSchema]), ), isError: z.boolean().default(false).optional(), }); @@ -877,7 +895,7 @@ export const ModelPreferencesSchema = z export const SamplingMessageSchema = z .object({ role: z.enum(["user", "assistant"]), - content: z.union([TextContentSchema, ImageContentSchema]), + content: z.union([TextContentSchema, ImageContentSchema, AudioContentSchema]), }) .passthrough(); @@ -931,6 +949,7 @@ export const CreateMessageResultSchema = ResultSchema.extend({ content: z.discriminatedUnion("type", [ TextContentSchema, ImageContentSchema, + AudioContentSchema ]), }); @@ -1195,6 +1214,7 @@ export type ListPromptsResult = Infer; export type GetPromptRequest = Infer; export type TextContent = Infer; export type ImageContent = Infer; +export type AudioContent = Infer; export type EmbeddedResource = Infer; export type PromptMessage = Infer; export type GetPromptResult = Infer;