@genkit-ai/ai
Version:
Genkit AI framework generative AI APIs.
1,398 lines (1,391 loc) • 319 kB
TypeScript
import { Action, z, SimpleMiddleware, StreamingCallback } from '@genkit-ai/core';
import { Registry } from '@genkit-ai/core/registry';
import { D as Document } from './document-kyHrg88I.js';
/**
* Copyright 2024 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.
*/
/**
* Preprocess a GenerateRequest to download referenced http(s) media URLs and
* inline them as data URIs.
*/
declare function downloadRequestMedia(options?: {
maxBytes?: number;
filter?: (part: MediaPart) => boolean;
}): ModelMiddleware;
/**
* Validates that a GenerateRequest does not include unsupported features.
*/
declare function validateSupport(options: {
name: string;
supports?: ModelInfo['supports'];
}): ModelMiddleware;
/**
* Provide a simulated system prompt for models that don't support it natively.
*/
declare function simulateSystemPrompt(options?: {
preface: string;
acknowledgement: string;
}): ModelMiddleware;
interface AugmentWithContextOptions {
/** Preceding text to place before the rendered context documents. */
preface?: string | null;
/** A function to render a document into a text part to be included in the message. */
itemTemplate?: (d: Document, options?: AugmentWithContextOptions) => string;
/** The metadata key to use for citation reference. Pass `null` to provide no citations. */
citationKey?: string | null;
}
declare const CONTEXT_PREFACE = "\n\nUse the following information to complete your task:\n\n";
declare function augmentWithContext(options?: AugmentWithContextOptions): ModelMiddleware;
interface SimulatedConstrainedGenerationOptions {
instructionsRenderer?: (schema: Record<string, any>) => string;
}
/**
* Model middleware that simulates constrained generation by injecting generation
* instructions into the user message.
*/
declare function simulateConstrainedGeneration(options?: SimulatedConstrainedGenerationOptions): ModelMiddleware;
/**
* Copyright 2024 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.
*/
type GenerateAction = Action<typeof GenerateActionOptionsSchema, typeof GenerateResponseSchema, typeof GenerateResponseChunkSchema>;
/** Defines (registers) a utilty generate action. */
declare function defineGenerateAction(registry: Registry): GenerateAction;
/**
* Encapsulates all generate logic. This is similar to `generateAction` except not an action and can take middleware.
*/
declare function generateHelper(registry: Registry, options: {
rawRequest: GenerateActionOptions;
middleware?: ModelMiddleware[];
currentTurn?: number;
messageIndex?: number;
}): Promise<GenerateResponseData>;
declare function inferRoleFromParts(parts: Part[]): Role;
/**
* Copyright 2024 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<z.objectUtil.extendShape<{
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>>;
}, {
/** The text of the message. */
text: z.ZodString;
}>, "strip", z.ZodTypeAny, {
text: string;
custom?: Record<string, unknown> | undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}, {
text: string;
custom?: Record<string, unknown> | undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}>;
/**
* Text part.
*/
type TextPart = z.infer<typeof TextPartSchema>;
/**
* Zod schema of a media part.
*/
declare const MediaPartSchema: z.ZodObject<z.objectUtil.extendShape<{
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>>;
}, {
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;
text?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}, {
media: {
url: string;
contentType?: string | undefined;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}>;
/**
* Media part.
*/
type MediaPart = z.infer<typeof MediaPartSchema>;
/**
* Zod schema of a tool request part.
*/
declare const ToolRequestPartSchema: z.ZodObject<z.objectUtil.extendShape<{
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>>;
}, {
/** A request for a tool to be executed, usually provided by a model. */
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>;
}, "strip", z.ZodTypeAny, {
name: string;
ref?: string | undefined;
input?: unknown;
}, {
name: string;
ref?: string | undefined;
input?: unknown;
}>;
}>, "strip", z.ZodTypeAny, {
toolRequest: {
name: string;
ref?: string | undefined;
input?: unknown;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
media?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}, {
toolRequest: {
name: string;
ref?: string | undefined;
input?: unknown;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
media?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}>;
/**
* Tool part.
*/
type ToolRequestPart = z.infer<typeof ToolRequestPartSchema>;
/**
* Zod schema of a tool response part.
*/
declare const ToolResponsePartSchema: z.ZodObject<z.objectUtil.extendShape<{
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>>;
}, {
/** A provided response to a tool call. */
toolResponse: 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;
output?: unknown;
ref?: string | undefined;
}, {
name: string;
output?: unknown;
ref?: string | undefined;
}>;
}>, "strip", z.ZodTypeAny, {
toolResponse: {
name: string;
output?: unknown;
ref?: string | undefined;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
media?: undefined;
toolRequest?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}, {
toolResponse: {
name: string;
output?: unknown;
ref?: string | undefined;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
media?: undefined;
toolRequest?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}>;
/**
* Tool response part.
*/
type ToolResponsePart = z.infer<typeof ToolResponsePartSchema>;
/**
* Zod schema of a data part.
*/
declare const DataPartSchema: z.ZodObject<z.objectUtil.extendShape<{
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>>;
}, {
data: z.ZodUnknown;
}>, "strip", z.ZodTypeAny, {
custom?: Record<string, unknown> | undefined;
text?: undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}, {
custom?: Record<string, unknown> | undefined;
text?: undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}>;
/**
* Data part.
*/
type DataPart = z.infer<typeof DataPartSchema>;
/**
* Zod schema of a custom part.
*/
declare const CustomPartSchema: z.ZodObject<z.objectUtil.extendShape<{
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>>;
}, {
custom: z.ZodRecord<z.ZodString, z.ZodAny>;
}>, "strip", z.ZodTypeAny, {
custom: Record<string, any>;
text?: undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}, {
custom: Record<string, any>;
text?: undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}>;
/**
* Custom part.
*/
type CustomPart = z.infer<typeof CustomPartSchema>;
/**
* Zod schema of message part.
*/
declare const PartSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
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>>;
}, {
/** The text of the message. */
text: z.ZodString;
}>, "strip", z.ZodTypeAny, {
text: string;
custom?: Record<string, unknown> | undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}, {
text: string;
custom?: Record<string, unknown> | undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}>, z.ZodObject<z.objectUtil.extendShape<{
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>>;
}, {
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;
text?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}, {
media: {
url: string;
contentType?: string | undefined;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}>, z.ZodObject<z.objectUtil.extendShape<{
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>>;
}, {
/** A request for a tool to be executed, usually provided by a model. */
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>;
}, "strip", z.ZodTypeAny, {
name: string;
ref?: string | undefined;
input?: unknown;
}, {
name: string;
ref?: string | undefined;
input?: unknown;
}>;
}>, "strip", z.ZodTypeAny, {
toolRequest: {
name: string;
ref?: string | undefined;
input?: unknown;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
media?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}, {
toolRequest: {
name: string;
ref?: string | undefined;
input?: unknown;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
media?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}>, z.ZodObject<z.objectUtil.extendShape<{
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>>;
}, {
/** A provided response to a tool call. */
toolResponse: 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;
output?: unknown;
ref?: string | undefined;
}, {
name: string;
output?: unknown;
ref?: string | undefined;
}>;
}>, "strip", z.ZodTypeAny, {
toolResponse: {
name: string;
output?: unknown;
ref?: string | undefined;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
media?: undefined;
toolRequest?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}, {
toolResponse: {
name: string;
output?: unknown;
ref?: string | undefined;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
media?: undefined;
toolRequest?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}>, z.ZodObject<z.objectUtil.extendShape<{
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>>;
}, {
data: z.ZodUnknown;
}>, "strip", z.ZodTypeAny, {
custom?: Record<string, unknown> | undefined;
text?: undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}, {
custom?: Record<string, unknown> | undefined;
text?: undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}>, z.ZodObject<z.objectUtil.extendShape<{
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>>;
}, {
custom: z.ZodRecord<z.ZodString, z.ZodAny>;
}>, "strip", z.ZodTypeAny, {
custom: Record<string, any>;
text?: undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}, {
custom: Record<string, any>;
text?: undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}>]>;
/**
* Message part.
*/
type Part = z.infer<typeof PartSchema>;
/**
* Zod schema of a message role.
*/
declare const RoleSchema: z.ZodEnum<["system", "user", "model", "tool"]>;
/**
* Message role.
*/
type Role = z.infer<typeof RoleSchema>;
/**
* Zod schema of a message.
*/
declare const MessageSchema: z.ZodObject<{
role: z.ZodEnum<["system", "user", "model", "tool"]>;
content: z.ZodArray<z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
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>>;
}, {
/** The text of the message. */
text: z.ZodString;
}>, "strip", z.ZodTypeAny, {
text: string;
custom?: Record<string, unknown> | undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}, {
text: string;
custom?: Record<string, unknown> | undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}>, z.ZodObject<z.objectUtil.extendShape<{
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>>;
}, {
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;
text?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}, {
media: {
url: string;
contentType?: string | undefined;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}>, z.ZodObject<z.objectUtil.extendShape<{
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>>;
}, {
/** A request for a tool to be executed, usually provided by a model. */
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>;
}, "strip", z.ZodTypeAny, {
name: string;
ref?: string | undefined;
input?: unknown;
}, {
name: string;
ref?: string | undefined;
input?: unknown;
}>;
}>, "strip", z.ZodTypeAny, {
toolRequest: {
name: string;
ref?: string | undefined;
input?: unknown;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
media?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}, {
toolRequest: {
name: string;
ref?: string | undefined;
input?: unknown;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
media?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}>, z.ZodObject<z.objectUtil.extendShape<{
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>>;
}, {
/** A provided response to a tool call. */
toolResponse: 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;
output?: unknown;
ref?: string | undefined;
}, {
name: string;
output?: unknown;
ref?: string | undefined;
}>;
}>, "strip", z.ZodTypeAny, {
toolResponse: {
name: string;
output?: unknown;
ref?: string | undefined;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
media?: undefined;
toolRequest?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}, {
toolResponse: {
name: string;
output?: unknown;
ref?: string | undefined;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
media?: undefined;
toolRequest?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}>, z.ZodObject<z.objectUtil.extendShape<{
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>>;
}, {
data: z.ZodUnknown;
}>, "strip", z.ZodTypeAny, {
custom?: Record<string, unknown> | undefined;
text?: undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}, {
custom?: Record<string, unknown> | undefined;
text?: undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}>, z.ZodObject<z.objectUtil.extendShape<{
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>>;
}, {
custom: z.ZodRecord<z.ZodString, z.ZodAny>;
}>, "strip", z.ZodTypeAny, {
custom: Record<string, any>;
text?: undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}, {
custom: Record<string, any>;
text?: undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}>]>, "many">;
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
}, "strip", z.ZodTypeAny, {
role: "model" | "system" | "user" | "tool";
content: ({
text: string;
custom?: Record<string, unknown> | undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
} | {
media: {
url: string;
contentType?: string | undefined;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
} | {
toolRequest: {
name: string;
ref?: string | undefined;
input?: unknown;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
media?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
} | {
toolResponse: {
name: string;
output?: unknown;
ref?: string | undefined;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
media?: undefined;
toolRequest?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
} | {
custom?: Record<string, unknown> | undefined;
text?: undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
} | {
custom: Record<string, any>;
text?: undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
})[];
metadata?: Record<string, unknown> | undefined;
}, {
role: "model" | "system" | "user" | "tool";
content: ({
text: string;
custom?: Record<string, unknown> | undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
} | {
media: {
url: string;
contentType?: string | undefined;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
} | {
toolRequest: {
name: string;
ref?: string | undefined;
input?: unknown;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
media?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
} | {
toolResponse: {
name: string;
output?: unknown;
ref?: string | undefined;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
media?: undefined;
toolRequest?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
} | {
custom?: Record<string, unknown> | undefined;
text?: undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
} | {
custom: Record<string, any>;
text?: undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
})[];
metadata?: Record<string, unknown> | undefined;
}>;
/**
* Model message data.
*/
type MessageData = z.infer<typeof MessageSchema>;
/**
* Zod schema of model info metadata.
*/
declare const ModelInfoSchema: z.ZodObject<{
/** Acceptable names for this model (e.g. different versions). */
versions: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
/** Friendly label for this model (e.g. "Google AI - Gemini Pro") */
label: z.ZodOptional<z.ZodString>;
/** Supported model capabilities. */
supports: z.ZodOptional<z.ZodObject<{
/** Model can process historical messages passed with a prompt. */
multiturn: z.ZodOptional<z.ZodBoolean>;
/** Model can process media as part of the prompt (multimodal input). */
media: z.ZodOptional<z.ZodBoolean>;
/** Model can perform tool calls. */
tools: z.ZodOptional<z.ZodBoolean>;
/** Model can accept messages with role "system". */
systemRole: z.ZodOptional<z.ZodBoolean>;
/** Model can output this type of data. */
output: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
/** Model supports output in these content types. */
contentType: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
/** Model can natively support document-based context grounding. */
context: z.ZodOptional<z.ZodBoolean>;
/** Model can natively support constrained generation. */
constrained: z.ZodOptional<z.ZodEnum<["none", "all", "no-tools"]>>;
/** Model supports controlling tool choice, e.g. forced tool calling. */
toolChoice: z.ZodOptional<z.ZodBoolean>;
}, "strip", z.ZodTypeAny, {
tools?: boolean | undefined;
toolChoice?: boolean | undefined;
output?: string[] | undefined;
context?: boolean | undefined;
media?: boolean | undefined;
contentType?: string[] | undefined;
constrained?: "none" | "all" | "no-tools" | undefined;
multiturn?: boolean | undefined;
systemRole?: boolean | undefined;
}, {
tools?: boolean | undefined;
toolChoice?: boolean | undefined;
output?: string[] | undefined;
context?: boolean | undefined;
media?: boolean | undefined;
contentType?: string[] | undefined;
constrained?: "none" | "all" | "no-tools" | undefined;
multiturn?: boolean | undefined;
systemRole?: boolean | undefined;
}>>;
/** At which stage of development this model is.
* - `featured` models are recommended for general use.
* - `stable` models are well-tested and reliable.
* - `unstable` models are experimental and may change.
* - `legacy` models are no longer recommended for new projects.
* - `deprecated` models are deprecated by the provider and may be removed in future versions.
*/
stage: z.ZodOptional<z.ZodEnum<["featured", "stable", "unstable", "legacy", "deprecated"]>>;
}, "strip", z.ZodTypeAny, {
versions?: string[] | undefined;
label?: string | undefined;
supports?: {
tools?: boolean | undefined;
toolChoice?: boolean | undefined;
output?: string[] | undefined;
context?: boolean | undefined;
media?: boolean | undefined;
contentType?: string[] | undefined;
constrained?: "none" | "all" | "no-tools" | undefined;
multiturn?: boolean | undefined;
systemRole?: boolean | undefined;
} | undefined;
stage?: "featured" | "stable" | "unstable" | "legacy" | "deprecated" | undefined;
}, {
versions?: string[] | undefined;
label?: string | undefined;
supports?: {
tools?: boolean | undefined;
toolChoice?: boolean | undefined;
output?: string[] | undefined;
context?: boolean | undefined;
media?: boolean | undefined;
contentType?: string[] | undefined;
constrained?: "none" | "all" | "no-tools" | undefined;
multiturn?: boolean | undefined;
systemRole?: boolean | undefined;
} | undefined;
stage?: "featured" | "stable" | "unstable" | "legacy" | "deprecated" | undefined;
}>;
/**
* Model info metadata.
*/
type ModelInfo = z.infer<typeof ModelInfoSchema>;
/**
* Zod schema of a tool definition.
*/
declare const ToolDefinitionSchema: z.ZodObject<{
name: z.ZodString;
description: z.ZodString;
inputSchema: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodAny>>>;
outputSchema: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodAny>>>;
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
}, "strip", z.ZodTypeAny, {
name: string;
description: string;
metadata?: Record<string, any> | undefined;
inputSchema?: Record<string, any> | null | undefined;
outputSchema?: Record<string, any> | null | undefined;
}, {
name: string;
description: string;
metadata?: Record<string, any> | undefined;
inputSchema?: Record<string, any> | null | undefined;
outputSchema?: Record<string, any> | null | undefined;
}>;
/**
* Tool definition.
*/
type ToolDefinition = z.infer<typeof ToolDefinitionSchema>;
/**
* Zod schema of a common config object.
*/
declare const GenerationCommonConfigSchema: z.ZodObject<{
/** A specific version of a model family, e.g. `gemini-1.0-pro-001` for the `gemini-1.0-pro` family. */
version: z.ZodOptional<z.ZodString>;
temperature: z.ZodOptional<z.ZodNumber>;
maxOutputTokens: z.ZodOptional<z.ZodNumber>;
topK: z.ZodOptional<z.ZodNumber>;
topP: z.ZodOptional<z.ZodNumber>;
stopSequences: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
}, "strip", z.ZodTypeAny, {
version?: string | undefined;
temperature?: number | undefined;
maxOutputTokens?: number | undefined;
topK?: number | undefined;
topP?: number | undefined;
stopSequences?: string[] | undefined;
}, {
version?: string | undefined;
temperature?: number | undefined;
maxOutputTokens?: number | undefined;
topK?: number | undefined;
topP?: number | undefined;
stopSequences?: string[] | undefined;
}>;
/**
* Common config object.
*/
type GenerationCommonConfig = typeof GenerationCommonConfigSchema;
/**
* Zod schema of output config.
*/
declare const OutputConfigSchema: z.ZodObject<{
format: z.ZodOptional<z.ZodString>;
schema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
constrained: z.ZodOptional<z.ZodBoolean>;
instructions: z.ZodOptional<z.ZodString>;
contentType: z.ZodOptional<z.ZodString>;
}, "strip", z.ZodTypeAny, {
contentType?: string | undefined;
format?: string | undefined;
schema?: Record<string, any> | undefined;
constrained?: boolean | undefined;
instructions?: string | undefined;
}, {
contentType?: string | undefined;
format?: string | undefined;
schema?: Record<string, any> | undefined;
constrained?: boolean | undefined;
instructions?: string | undefined;
}>;
/**
* Output config.
*/
type OutputConfig = z.infer<typeof OutputConfigSchema>;
/** ModelRequestSchema represents the parameters that are passed to a model when generating content. */
declare const ModelRequestSchema: z.ZodObject<{
messages: z.ZodArray<z.ZodObject<{
role: z.ZodEnum<["system", "user", "model", "tool"]>;
content: z.ZodArray<z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
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>>;
}, {
/** The text of the message. */
text: z.ZodString;
}>, "strip", z.ZodTypeAny, {
text: string;
custom?: Record<string, unknown> | undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}, {
text: string;
custom?: Record<string, unknown> | undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}>, z.ZodObject<z.objectUtil.extendShape<{
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>>;
}, {
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;
text?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}, {
media: {
url: string;
contentType?: string | undefined;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}>, z.ZodObject<z.objectUtil.extendShape<{
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>>;
}, {
/** A request for a tool to be executed, usually provided by a model. */
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>;
}, "strip", z.ZodTypeAny, {
name: string;
ref?: string | undefined;
input?: unknown;
}, {
name: string;
ref?: string | undefined;
input?: unknown;
}>;
}>, "strip", z.ZodTypeAny, {
toolRequest: {
name: string;
ref?: string | undefined;
input?: unknown;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
media?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}, {
toolRequest: {
name: string;
ref?: string | undefined;
input?: unknown;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
media?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}>, z.ZodObject<z.objectUtil.extendShape<{
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>>;
}, {
/** A provided response to a tool call. */
toolResponse: 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;
output?: unknown;
ref?: string | undefined;
}, {
name: string;
output?: unknown;
ref?: string | undefined;
}>;
}>, "strip", z.ZodTypeAny, {
toolResponse: {
name: string;
output?: unknown;
ref?: string | undefined;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
media?: undefined;
toolRequest?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}, {
toolResponse: {
name: string;
output?: unknown;
ref?: string | undefined;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
media?: undefined;
toolRequest?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}>, z.ZodObject<z.objectUtil.extendShape<{
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>>;
}, {
data: z.ZodUnknown;
}>, "strip", z.ZodTypeAny, {
custom?: Record<string, unknown> | undefined;
text?: undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}, {
custom?: Record<string, unknown> | undefined;
text?: undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}>, z.ZodObject<z.objectUtil.extendShape<{
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>>;
}, {
custom: z.ZodRecord<z.ZodString, z.ZodAny>;
}>, "strip", z.ZodTypeAny, {
custom: Record<string, any>;
text?: undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}, {
custom: Record<string, any>;
text?: undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}>]>, "many">;
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
}, "strip", z.ZodTypeAny, {
role: "model" | "system" | "user" | "tool";
content: ({
text: string;
custom?: Record<string, unknown> | undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
} | {
media: {
url: string;
contentType?: string | undefined;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;