@genkit-ai/ai
Version:
Genkit AI framework generative AI APIs.
92 lines • 2.92 kB
JavaScript
import { z } from "@genkit-ai/core";
const EmptyPartSchema = z.object({
text: z.never().optional(),
media: z.never().optional(),
toolRequest: z.never().optional(),
toolResponse: z.never().optional(),
data: z.unknown().optional(),
metadata: z.record(z.unknown()).optional(),
custom: z.record(z.unknown()).optional(),
reasoning: z.never().optional(),
resource: z.never().optional()
});
const TextPartSchema = EmptyPartSchema.extend({
/** The text of the message. */
text: z.string()
});
const ReasoningPartSchema = EmptyPartSchema.extend({
/** The reasoning text of the message. */
reasoning: z.string()
});
const MediaSchema = z.object({
/** The media content type. Inferred from data uri if not provided. */
contentType: z.string().optional(),
/** A `data:` or `https:` uri containing the media content. */
url: z.string()
});
const MediaPartSchema = EmptyPartSchema.extend({
media: MediaSchema
});
const ToolRequestSchema = z.object({
/** The call id or reference for a specific request. */
ref: z.string().optional(),
/** The name of the tool to call. */
name: z.string(),
/** The input parameters for the tool, usually a JSON object. */
input: z.unknown().optional(),
/** Whether the request is a partial chunk. */
partial: z.boolean().optional()
});
const ToolRequestPartSchema = EmptyPartSchema.extend({
/** A request for a tool to be executed, usually provided by a model. */
toolRequest: ToolRequestSchema
});
const ToolResponseSchemaBase = z.object({
/** The call id or reference for a specific request. */
ref: z.string().optional(),
/** The name of the tool. */
name: z.string(),
/** The output data returned from the tool, usually a JSON object. */
output: z.unknown().optional()
});
const ToolResponseSchema = ToolResponseSchemaBase.extend({
content: z.array(z.any()).optional()
// TODO: switch to this once we have effective recursive schema support across the board.
// content: z.array(z.lazy(() => PartSchema)).optional(),
});
const ToolResponsePartSchema = EmptyPartSchema.extend({
/** A provided response to a tool call. */
toolResponse: ToolResponseSchema
});
const DataPartSchema = EmptyPartSchema.extend({
data: z.unknown()
});
const CustomPartSchema = EmptyPartSchema.extend({
custom: z.record(z.any())
});
const ResourcePartSchema = EmptyPartSchema.extend({
resource: z.object({
uri: z.string()
})
});
const PartSchema = z.union([TextPartSchema, MediaPartSchema]);
const MultipartToolResponseSchema = z.object({
output: z.unknown().optional(),
content: z.array(PartSchema).optional()
});
export {
CustomPartSchema,
DataPartSchema,
MediaPartSchema,
MediaSchema,
MultipartToolResponseSchema,
PartSchema,
ReasoningPartSchema,
ResourcePartSchema,
TextPartSchema,
ToolRequestPartSchema,
ToolRequestSchema,
ToolResponsePartSchema,
ToolResponseSchema
};
//# sourceMappingURL=parts.mjs.map