@genkit-ai/ai
Version:
Genkit AI framework generative AI APIs.
1,369 lines (1,358 loc) • 327 kB
text/typescript
import { JSONSchema, Action, z, SimpleMiddleware, StreamingCallback } from '@genkit-ai/core';
import { Registry } from '@genkit-ai/core/registry';
import { M as MediaPart, D as Document, l as ToolResponsePart, k as ToolRequestPart } from './document-bWESTgsa.mjs';
/**
* 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.
*/
interface MessageParser<T = unknown> {
(message: Message): T;
}
/**
* Message represents a single role's contribution to a generation. Each message
* can contain multiple parts (for example text and an image), and each generation
* can contain multiple messages.
*/
declare class Message<T = unknown> implements MessageData {
role: MessageData['role'];
content: Part[];
metadata?: Record<string, any>;
parser?: MessageParser<T>;
static parseData(lenientMessage: string | (MessageData & {
content: string | Part | Part[];
role: string;
}) | MessageData, defaultRole?: MessageData['role']): MessageData;
static parse(lenientMessage: string | (MessageData & {
content: string;
}) | MessageData): Message;
static parseContent(lenientPart: string | Part | (string | Part)[]): Part[];
constructor(message: MessageData, options?: {
parser?: MessageParser<T>;
});
/**
* Attempts to parse the content of the message according to the supplied
* output parser. Without a parser, returns `data` contained in the message or
* tries to parse JSON from the text of the message.
*
* @returns The structured output contained in the message.
*/
get output(): T;
toolResponseParts(): ToolResponsePart[];
/**
* Concatenates all `text` parts present in the message with no delimiter.
* @returns A string of all concatenated text parts.
*/
get text(): string;
/**
* Returns the first media part detected in the message. Useful for extracting
* (for example) an image from a generation expected to create one.
* @returns The first detected `media` part in the message.
*/
get media(): {
url: string;
contentType?: string;
} | null;
/**
* Returns the first detected `data` part of a message.
* @returns The first `data` part detected in the message (if any).
*/
get data(): T | null;
/**
* Returns all tool request found in this message.
* @returns Array of all tool request found in this message.
*/
get toolRequests(): ToolRequestPart[];
/**
* Returns all tool requests annotated with interrupt metadata.
* @returns Array of all interrupt tool requests.
*/
get interrupts(): ToolRequestPart[];
/**
* Converts the Message to a plain JS object.
* @returns Plain JS object representing the data contained in the message.
*/
toJSON(): MessageData;
}
/**
* 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 OutputContentTypes = 'application/json' | 'text/plain';
interface Formatter<O = unknown, CO = unknown> {
name: string;
config: ModelRequest['output'] & {
defaultInstructions?: false;
};
handler: (schema?: JSONSchema) => {
parseMessage(message: Message): O;
parseChunk?: (chunk: GenerateResponseChunk) => CO;
instructions?: string;
};
}
/**
* 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 shouldInjectFormatInstructions(formatConfig?: Formatter['config'], rawRequestConfig?: z.infer<typeof GenerateActionOutputConfig>): string | boolean | undefined;
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 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>>;
}, {
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<{
contentType: z.ZodOptional<z.ZodString>;
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>>;
}, {
toolRequest: z.ZodObject<{
ref: z.ZodOptional<z.ZodString>;
name: z.ZodString;
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>>;
}, {
toolResponse: z.ZodObject<{
ref: z.ZodOptional<z.ZodString>;
name: z.ZodString;
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>>;
}, {
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<{
contentType: z.ZodOptional<z.ZodString>;
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>>;
}, {
toolRequest: z.ZodObject<{
ref: z.ZodOptional<z.ZodString>;
name: z.ZodString;
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>>;
}, {
toolResponse: z.ZodObject<{
ref: z.ZodOptional<z.ZodString>;
name: z.ZodString;
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>>;
}, {
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<{
contentType: z.ZodOptional<z.ZodString>;
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>>;
}, {
toolRequest: z.ZodObject<{
ref: z.ZodOptional<z.ZodString>;
name: z.ZodString;
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>>;
}, {
toolResponse: z.ZodObject<{
ref: z.ZodOptional<z.ZodString>;
name: z.ZodString;
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;
}>, "many">;
config: z.ZodOptional<z.ZodAny>;
tools: z.ZodOptional<z.ZodArray<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;
}>, "many">>;
toolChoice: z.ZodOptional<z.ZodEnum<["auto", "required", "none"]>>;
output: z.ZodOptional<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;
}>>;
docs: z.ZodOptional<z.ZodArray<z.ZodObject<{
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>>;
}, {
text: z.ZodString;
}>, "strip", z.ZodTypeAny, {