{"version":3,"sources":["../src/parts.ts"],"sourcesContent":["/**\n * Copyright 2025 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { z } from '@genkit-ai/core';\n\nconst EmptyPartSchema = z.object({\n  text: z.never().optional(),\n  media: z.never().optional(),\n  toolRequest: z.never().optional(),\n  toolResponse: z.never().optional(),\n  data: z.unknown().optional(),\n  metadata: z.record(z.unknown()).optional(),\n  custom: z.record(z.unknown()).optional(),\n  reasoning: z.never().optional(),\n  resource: z.never().optional(),\n});\n\n/**\n * Zod schema for a text part.\n */\nexport const TextPartSchema = EmptyPartSchema.extend({\n  /** The text of the message. */\n  text: z.string(),\n});\n\n/**\n * Text part.\n */\nexport type TextPart = z.infer<typeof TextPartSchema>;\n\n/**\n * Zod schema for a reasoning part.\n */\nexport const ReasoningPartSchema = EmptyPartSchema.extend({\n  /** The reasoning text of the message. */\n  reasoning: z.string(),\n});\n\n/**\n * Reasoning part.\n */\nexport type ReasoningPart = z.infer<typeof ReasoningPartSchema>;\n\n/**\n * Zod schema of media.\n */\nexport const MediaSchema = z.object({\n  /** The media content type. Inferred from data uri if not provided. */\n  contentType: z.string().optional(),\n  /** A `data:` or `https:` uri containing the media content.  */\n  url: z.string(),\n});\n\n/**\n * Zod schema of a media part.\n */\nexport const MediaPartSchema = EmptyPartSchema.extend({\n  media: MediaSchema,\n});\n\n/**\n * Media part.\n */\nexport type MediaPart = z.infer<typeof MediaPartSchema>;\n\n/**\n * Zod schema of a tool request.\n */\nexport const ToolRequestSchema = z.object({\n  /** The call id or reference for a specific request. */\n  ref: z.string().optional(),\n  /** The name of the tool to call. */\n  name: z.string(),\n  /** The input parameters for the tool, usually a JSON object. */\n  input: z.unknown().optional(),\n  /** Whether the request is a partial chunk. */\n  partial: z.boolean().optional(),\n});\nexport type ToolRequest = z.infer<typeof ToolRequestSchema>;\n\n/**\n * Zod schema of a tool request part.\n */\nexport const ToolRequestPartSchema = EmptyPartSchema.extend({\n  /** A request for a tool to be executed, usually provided by a model. */\n  toolRequest: ToolRequestSchema,\n});\n\n/**\n * Tool part.\n */\nexport type ToolRequestPart = z.infer<typeof ToolRequestPartSchema>;\n\n/**\n * Zod schema of a tool response.\n */\nconst ToolResponseSchemaBase = z.object({\n  /** The call id or reference for a specific request. */\n  ref: z.string().optional(),\n  /** The name of the tool. */\n  name: z.string(),\n  /** The output data returned from the tool, usually a JSON object. */\n  output: z.unknown().optional(),\n});\n\n/**\n * Tool response part.\n */\nexport type ToolResponse = z.infer<typeof ToolResponseSchemaBase> & {\n  content?: Part[];\n};\n\nexport const ToolResponseSchema: z.ZodType<ToolResponse> =\n  ToolResponseSchemaBase.extend({\n    content: z.array(z.any()).optional(),\n    // TODO: switch to this once we have effective recursive schema support across the board.\n    // content: z.array(z.lazy(() => PartSchema)).optional(),\n  });\n\n/**\n * Zod schema of a tool response part.\n */\nexport const ToolResponsePartSchema = EmptyPartSchema.extend({\n  /** A provided response to a tool call. */\n  toolResponse: ToolResponseSchema,\n});\n\n/**\n * Tool response part.\n */\nexport type ToolResponsePart = z.infer<typeof ToolResponsePartSchema>;\n\n/**\n * Zod schema of a data part.\n */\nexport const DataPartSchema = EmptyPartSchema.extend({\n  data: z.unknown(),\n});\n\n/**\n * Data part.\n */\nexport type DataPart = z.infer<typeof DataPartSchema>;\n\n/**\n * Zod schema of a custom part.\n */\nexport const CustomPartSchema = EmptyPartSchema.extend({\n  custom: z.record(z.any()),\n});\n\n/**\n * Custom part.\n */\nexport type CustomPart = z.infer<typeof CustomPartSchema>;\n\n/**\n * Zod schema of a resource part.\n */\nexport const ResourcePartSchema = EmptyPartSchema.extend({\n  resource: z.object({\n    uri: z.string(),\n  }),\n});\n\n/**\n * Resource part.\n */\nexport type ResourcePart = z.infer<typeof ResourcePartSchema>;\n\n/**\n * Zod schema of a message part.\n */\nexport const PartSchema = z.union([\n  TextPartSchema,\n  MediaPartSchema,\n  ToolRequestPartSchema,\n  ToolResponsePartSchema,\n  DataPartSchema,\n  CustomPartSchema,\n  ReasoningPartSchema,\n  ResourcePartSchema,\n]);\n\n/**\n * Message part.\n */\nexport type Part = z.infer<typeof PartSchema>;\n\nexport const MultipartToolResponseSchema = z.object({\n  output: z.unknown().optional(),\n  content: z.array(PartSchema).optional(),\n  metadata: z.record(z.unknown()).optional(),\n});\n\nexport type MultipartToolResponse = z.infer<typeof MultipartToolResponseSchema>;\n"],"mappings":"AAgBA,SAAS,SAAS;AAElB,MAAM,kBAAkB,EAAE,OAAO;AAAA,EAC/B,MAAM,EAAE,MAAM,EAAE,SAAS;AAAA,EACzB,OAAO,EAAE,MAAM,EAAE,SAAS;AAAA,EAC1B,aAAa,EAAE,MAAM,EAAE,SAAS;AAAA,EAChC,cAAc,EAAE,MAAM,EAAE,SAAS;AAAA,EACjC,MAAM,EAAE,QAAQ,EAAE,SAAS;AAAA,EAC3B,UAAU,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,SAAS;AAAA,EACzC,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,SAAS;AAAA,EACvC,WAAW,EAAE,MAAM,EAAE,SAAS;AAAA,EAC9B,UAAU,EAAE,MAAM,EAAE,SAAS;AAC/B,CAAC;AAKM,MAAM,iBAAiB,gBAAgB,OAAO;AAAA;AAAA,EAEnD,MAAM,EAAE,OAAO;AACjB,CAAC;AAUM,MAAM,sBAAsB,gBAAgB,OAAO;AAAA;AAAA,EAExD,WAAW,EAAE,OAAO;AACtB,CAAC;AAUM,MAAM,cAAc,EAAE,OAAO;AAAA;AAAA,EAElC,aAAa,EAAE,OAAO,EAAE,SAAS;AAAA;AAAA,EAEjC,KAAK,EAAE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