UNPKG

@genkit-ai/ai

Version:

Genkit AI framework generative AI APIs.

725 lines (721 loc) 23.1 kB
import { z } from '@genkit-ai/core'; /** * Copyright 2025 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * Zod schema for a text part. */ declare const TextPartSchema: z.ZodObject<{ media: z.ZodOptional<z.ZodNever>; toolRequest: z.ZodOptional<z.ZodNever>; toolResponse: z.ZodOptional<z.ZodNever>; data: z.ZodOptional<z.ZodUnknown>; metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>; custom: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>; reasoning: z.ZodOptional<z.ZodNever>; resource: z.ZodOptional<z.ZodNever>; } & { text: z.ZodString; }, "strip", z.ZodTypeAny, { text: string; custom?: Record<string, unknown> | undefined; metadata?: Record<string, unknown> | undefined; media?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; }, { text: string; custom?: Record<string, unknown> | undefined; metadata?: Record<string, unknown> | undefined; media?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; }>; /** * Zod schema for a reasoning part. */ declare const ReasoningPartSchema: z.ZodObject<{ text: z.ZodOptional<z.ZodNever>; media: z.ZodOptional<z.ZodNever>; toolRequest: z.ZodOptional<z.ZodNever>; toolResponse: z.ZodOptional<z.ZodNever>; data: z.ZodOptional<z.ZodUnknown>; metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>; custom: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>; resource: z.ZodOptional<z.ZodNever>; } & { reasoning: z.ZodString; }, "strip", z.ZodTypeAny, { reasoning: string; custom?: Record<string, unknown> | undefined; metadata?: Record<string, unknown> | undefined; text?: undefined; media?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; resource?: undefined; }, { reasoning: string; custom?: Record<string, unknown> | undefined; metadata?: Record<string, unknown> | undefined; text?: undefined; media?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; resource?: undefined; }>; /** * Text part. */ type TextPart = z.infer<typeof TextPartSchema>; /** * Zod schema of media. */ declare const MediaSchema: z.ZodObject<{ /** The media content type. Inferred from data uri if not provided. */ contentType: z.ZodOptional<z.ZodString>; /** A `data:` or `https:` uri containing the media content. */ url: z.ZodString; }, "strip", z.ZodTypeAny, { url: string; contentType?: string | undefined; }, { url: string; contentType?: string | undefined; }>; /** * Zod schema of a media part. */ declare const MediaPartSchema: z.ZodObject<{ text: z.ZodOptional<z.ZodNever>; toolRequest: z.ZodOptional<z.ZodNever>; toolResponse: z.ZodOptional<z.ZodNever>; data: z.ZodOptional<z.ZodUnknown>; metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>; custom: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>; reasoning: z.ZodOptional<z.ZodNever>; resource: z.ZodOptional<z.ZodNever>; } & { media: z.ZodObject<{ /** The media content type. Inferred from data uri if not provided. */ contentType: z.ZodOptional<z.ZodString>; /** A `data:` or `https:` uri containing the media content. */ url: z.ZodString; }, "strip", z.ZodTypeAny, { url: string; contentType?: string | undefined; }, { url: string; contentType?: string | undefined; }>; }, "strip", z.ZodTypeAny, { media: { url: string; contentType?: string | undefined; }; custom?: Record<string, unknown> | undefined; metadata?: Record<string, unknown> | undefined; text?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; }, { media: { url: string; contentType?: string | undefined; }; custom?: Record<string, unknown> | undefined; metadata?: Record<string, unknown> | undefined; text?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; }>; /** * Media part. */ type MediaPart = z.infer<typeof MediaPartSchema>; /** * Zod schema of a tool request. */ declare const ToolRequestSchema: z.ZodObject<{ /** The call id or reference for a specific request. */ ref: z.ZodOptional<z.ZodString>; /** The name of the tool to call. */ name: z.ZodString; /** The input parameters for the tool, usually a JSON object. */ input: z.ZodOptional<z.ZodUnknown>; /** Whether the request is a partial chunk. */ partial: z.ZodOptional<z.ZodBoolean>; }, "strip", z.ZodTypeAny, { name: string; input?: unknown; ref?: string | undefined; partial?: boolean | undefined; }, { name: string; input?: unknown; ref?: string | undefined; partial?: boolean | undefined; }>; type ToolRequest = z.infer<typeof ToolRequestSchema>; /** * Zod schema of a tool request part. */ declare const ToolRequestPartSchema: z.ZodObject<{ text: z.ZodOptional<z.ZodNever>; media: z.ZodOptional<z.ZodNever>; toolResponse: z.ZodOptional<z.ZodNever>; data: z.ZodOptional<z.ZodUnknown>; metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>; custom: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>; reasoning: z.ZodOptional<z.ZodNever>; resource: z.ZodOptional<z.ZodNever>; } & { toolRequest: z.ZodObject<{ /** The call id or reference for a specific request. */ ref: z.ZodOptional<z.ZodString>; /** The name of the tool to call. */ name: z.ZodString; /** The input parameters for the tool, usually a JSON object. */ input: z.ZodOptional<z.ZodUnknown>; /** Whether the request is a partial chunk. */ partial: z.ZodOptional<z.ZodBoolean>; }, "strip", z.ZodTypeAny, { name: string; input?: unknown; ref?: string | undefined; partial?: boolean | undefined; }, { name: string; input?: unknown; ref?: string | undefined; partial?: boolean | undefined; }>; }, "strip", z.ZodTypeAny, { toolRequest: { name: string; input?: unknown; ref?: string | undefined; partial?: boolean | undefined; }; custom?: Record<string, unknown> | undefined; metadata?: Record<string, unknown> | undefined; text?: undefined; media?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; }, { toolRequest: { name: string; input?: unknown; ref?: string | undefined; partial?: boolean | undefined; }; custom?: Record<string, unknown> | undefined; metadata?: Record<string, unknown> | undefined; text?: undefined; media?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; }>; /** * Tool part. */ type ToolRequestPart = z.infer<typeof ToolRequestPartSchema>; /** * Zod schema of a tool response. */ declare const ToolResponseSchemaBase: z.ZodObject<{ /** The call id or reference for a specific request. */ ref: z.ZodOptional<z.ZodString>; /** The name of the tool. */ name: z.ZodString; /** The output data returned from the tool, usually a JSON object. */ output: z.ZodOptional<z.ZodUnknown>; }, "strip", z.ZodTypeAny, { name: string; ref?: string | undefined; output?: unknown; }, { name: string; ref?: string | undefined; output?: unknown; }>; /** * Tool response part. */ type ToolResponse = z.infer<typeof ToolResponseSchemaBase> & { content?: Part[]; }; declare const ToolResponseSchema: z.ZodType<ToolResponse>; /** * Zod schema of a tool response part. */ declare const ToolResponsePartSchema: z.ZodObject<{ text: z.ZodOptional<z.ZodNever>; media: z.ZodOptional<z.ZodNever>; toolRequest: z.ZodOptional<z.ZodNever>; data: z.ZodOptional<z.ZodUnknown>; metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>; custom: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>; reasoning: z.ZodOptional<z.ZodNever>; resource: z.ZodOptional<z.ZodNever>; } & { toolResponse: z.ZodType<ToolResponse, z.ZodTypeDef, ToolResponse>; }, "strip", z.ZodTypeAny, { toolResponse: { name: string; ref?: string | undefined; output?: unknown; } & { content?: ({ text: string; custom?: Record<string, unknown> | undefined; metadata?: Record<string, unknown> | undefined; media?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; } | { media: { url: string; contentType?: string | undefined; }; custom?: Record<string, unknown> | undefined; metadata?: Record<string, unknown> | undefined; text?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; })[] | undefined; }; custom?: Record<string, unknown> | undefined; metadata?: Record<string, unknown> | undefined; text?: undefined; media?: undefined; toolRequest?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; }, { toolResponse: { name: string; ref?: string | undefined; output?: unknown; } & { content?: ({ text: string; custom?: Record<string, unknown> | undefined; metadata?: Record<string, unknown> | undefined; media?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; } | { media: { url: string; contentType?: string | undefined; }; custom?: Record<string, unknown> | undefined; metadata?: Record<string, unknown> | undefined; text?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; })[] | undefined; }; custom?: Record<string, unknown> | undefined; metadata?: Record<string, unknown> | undefined; text?: undefined; media?: undefined; toolRequest?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; }>; /** * Tool response part. */ type ToolResponsePart = z.infer<typeof ToolResponsePartSchema>; /** * Zod schema of a data part. */ declare const DataPartSchema: z.ZodObject<{ text: z.ZodOptional<z.ZodNever>; media: z.ZodOptional<z.ZodNever>; toolRequest: z.ZodOptional<z.ZodNever>; toolResponse: z.ZodOptional<z.ZodNever>; metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>; custom: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>; reasoning: z.ZodOptional<z.ZodNever>; resource: z.ZodOptional<z.ZodNever>; } & { data: z.ZodUnknown; }, "strip", z.ZodTypeAny, { custom?: Record<string, unknown> | undefined; metadata?: Record<string, unknown> | undefined; text?: undefined; media?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; }, { custom?: Record<string, unknown> | undefined; metadata?: Record<string, unknown> | undefined; text?: undefined; media?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; }>; /** * Data part. */ type DataPart = z.infer<typeof DataPartSchema>; /** * Zod schema of a custom part. */ declare const CustomPartSchema: z.ZodObject<{ text: z.ZodOptional<z.ZodNever>; media: z.ZodOptional<z.ZodNever>; toolRequest: z.ZodOptional<z.ZodNever>; toolResponse: z.ZodOptional<z.ZodNever>; data: z.ZodOptional<z.ZodUnknown>; metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>; reasoning: z.ZodOptional<z.ZodNever>; resource: z.ZodOptional<z.ZodNever>; } & { custom: z.ZodRecord<z.ZodString, z.ZodAny>; }, "strip", z.ZodTypeAny, { custom: Record<string, any>; metadata?: Record<string, unknown> | undefined; text?: undefined; media?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; }, { custom: Record<string, any>; metadata?: Record<string, unknown> | undefined; text?: undefined; media?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; }>; /** * Custom part. */ type CustomPart = z.infer<typeof CustomPartSchema>; /** * Zod schema of a resource part. */ declare const ResourcePartSchema: z.ZodObject<{ text: z.ZodOptional<z.ZodNever>; media: z.ZodOptional<z.ZodNever>; toolRequest: z.ZodOptional<z.ZodNever>; toolResponse: z.ZodOptional<z.ZodNever>; data: z.ZodOptional<z.ZodUnknown>; metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>; custom: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>; reasoning: z.ZodOptional<z.ZodNever>; } & { resource: z.ZodObject<{ uri: z.ZodString; }, "strip", z.ZodTypeAny, { uri: string; }, { uri: string; }>; }, "strip", z.ZodTypeAny, { resource: { uri: string; }; custom?: Record<string, unknown> | undefined; metadata?: Record<string, unknown> | undefined; text?: undefined; media?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; }, { resource: { uri: string; }; custom?: Record<string, unknown> | undefined; metadata?: Record<string, unknown> | undefined; text?: undefined; media?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; }>; /** * Resource part. */ type ResourcePart = z.infer<typeof ResourcePartSchema>; declare const PartSchema: z.ZodUnion<[z.ZodObject<{ media: z.ZodOptional<z.ZodNever>; toolRequest: z.ZodOptional<z.ZodNever>; toolResponse: z.ZodOptional<z.ZodNever>; data: z.ZodOptional<z.ZodUnknown>; metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>; custom: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>; reasoning: z.ZodOptional<z.ZodNever>; resource: z.ZodOptional<z.ZodNever>; } & { text: z.ZodString; }, "strip", z.ZodTypeAny, { text: string; custom?: Record<string, unknown> | undefined; metadata?: Record<string, unknown> | undefined; media?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; }, { text: string; custom?: Record<string, unknown> | undefined; metadata?: Record<string, unknown> | undefined; media?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; }>, z.ZodObject<{ text: z.ZodOptional<z.ZodNever>; toolRequest: z.ZodOptional<z.ZodNever>; toolResponse: z.ZodOptional<z.ZodNever>; data: z.ZodOptional<z.ZodUnknown>; metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>; custom: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>; reasoning: z.ZodOptional<z.ZodNever>; resource: z.ZodOptional<z.ZodNever>; } & { media: z.ZodObject<{ /** The media content type. Inferred from data uri if not provided. */ contentType: z.ZodOptional<z.ZodString>; /** A `data:` or `https:` uri containing the media content. */ url: z.ZodString; }, "strip", z.ZodTypeAny, { url: string; contentType?: string | undefined; }, { url: string; contentType?: string | undefined; }>; }, "strip", z.ZodTypeAny, { media: { url: string; contentType?: string | undefined; }; custom?: Record<string, unknown> | undefined; metadata?: Record<string, unknown> | undefined; text?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; }, { media: { url: string; contentType?: string | undefined; }; custom?: Record<string, unknown> | undefined; metadata?: Record<string, unknown> | undefined; text?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; }>]>; type Part = z.infer<typeof PartSchema>; declare const MultipartToolResponseSchema: z.ZodObject<{ output: z.ZodOptional<z.ZodUnknown>; content: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodObject<{ media: z.ZodOptional<z.ZodNever>; toolRequest: z.ZodOptional<z.ZodNever>; toolResponse: z.ZodOptional<z.ZodNever>; data: z.ZodOptional<z.ZodUnknown>; metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>; custom: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>; reasoning: z.ZodOptional<z.ZodNever>; resource: z.ZodOptional<z.ZodNever>; } & { text: z.ZodString; }, "strip", z.ZodTypeAny, { text: string; custom?: Record<string, unknown> | undefined; metadata?: Record<string, unknown> | undefined; media?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; }, { text: string; custom?: Record<string, unknown> | undefined; metadata?: Record<string, unknown> | undefined; media?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; }>, z.ZodObject<{ text: z.ZodOptional<z.ZodNever>; toolRequest: z.ZodOptional<z.ZodNever>; toolResponse: z.ZodOptional<z.ZodNever>; data: z.ZodOptional<z.ZodUnknown>; metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>; custom: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>; reasoning: z.ZodOptional<z.ZodNever>; resource: z.ZodOptional<z.ZodNever>; } & { media: z.ZodObject<{ /** The media content type. Inferred from data uri if not provided. */ contentType: z.ZodOptional<z.ZodString>; /** A `data:` or `https:` uri containing the media content. */ url: z.ZodString; }, "strip", z.ZodTypeAny, { url: string; contentType?: string | undefined; }, { url: string; contentType?: string | undefined; }>; }, "strip", z.ZodTypeAny, { media: { url: string; contentType?: string | undefined; }; custom?: Record<string, unknown> | undefined; metadata?: Record<string, unknown> | undefined; text?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; }, { media: { url: string; contentType?: string | undefined; }; custom?: Record<string, unknown> | undefined; metadata?: Record<string, unknown> | undefined; text?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; }>]>, "many">>; }, "strip", z.ZodTypeAny, { content?: ({ text: string; custom?: Record<string, unknown> | undefined; metadata?: Record<string, unknown> | undefined; media?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; } | { media: { url: string; contentType?: string | undefined; }; custom?: Record<string, unknown> | undefined; metadata?: Record<string, unknown> | undefined; text?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; })[] | undefined; output?: unknown; }, { content?: ({ text: string; custom?: Record<string, unknown> | undefined; metadata?: Record<string, unknown> | undefined; media?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; } | { media: { url: string; contentType?: string | undefined; }; custom?: Record<string, unknown> | undefined; metadata?: Record<string, unknown> | undefined; text?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; })[] | undefined; output?: unknown; }>; type MultipartToolResponse = z.infer<typeof MultipartToolResponseSchema>; export { type CustomPart, CustomPartSchema, type DataPart, DataPartSchema, type MediaPart, MediaPartSchema, MediaSchema, type MultipartToolResponse, MultipartToolResponseSchema, type Part, PartSchema, ReasoningPartSchema, type ResourcePart, ResourcePartSchema, type TextPart, TextPartSchema, type ToolRequest, type ToolRequestPart, ToolRequestPartSchema, ToolRequestSchema, type ToolResponse, type ToolResponsePart, ToolResponsePartSchema, ToolResponseSchema };