import { DetachedAction, z, ActionContext, Action } from '@genkit-ai/core'; import { Registry } from '@genkit-ai/core/registry'; /** * 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. */ /** * Options for defining a resource. */ interface ResourceOptions { /** * Resource name. If not specified, uri or template will be used as name. */ name?: string; /** * The URI of the resource. Can contain template variables. */ uri?: string; /** * The URI template (ex. `my://resource/{id}`). See RFC6570 for specification. */ template?: string; /** * A description of the resource. */ description?: string; /** * Resource metadata. */ metadata?: Record; } declare const ResourceInputSchema: z.ZodObject<{ uri: z.ZodString; }, "strip", z.ZodTypeAny, { uri: string; }, { uri: string; }>; type ResourceInput = z.infer; declare const ResourceOutputSchema: z.ZodObject<{ content: z.ZodArray; toolRequest: z.ZodOptional; toolResponse: z.ZodOptional; data: z.ZodOptional; metadata: z.ZodOptional>; custom: z.ZodOptional>; reasoning: z.ZodOptional; resource: z.ZodOptional; } & { text: z.ZodString; }, "strip", z.ZodTypeAny, { text: string; custom?: Record | undefined; metadata?: Record | undefined; media?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; }, { text: string; custom?: Record | undefined; metadata?: Record | undefined; media?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; }>, z.ZodObject<{ text: z.ZodOptional; toolRequest: z.ZodOptional; toolResponse: z.ZodOptional; data: z.ZodOptional; metadata: z.ZodOptional>; custom: z.ZodOptional>; reasoning: z.ZodOptional; resource: z.ZodOptional; } & { media: z.ZodObject<{ contentType: z.ZodOptional; 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 | undefined; metadata?: Record | undefined; text?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; }, { media: { url: string; contentType?: string | undefined; }; custom?: Record | undefined; metadata?: Record | undefined; text?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; }>, z.ZodObject<{ text: z.ZodOptional; media: z.ZodOptional; toolResponse: z.ZodOptional; data: z.ZodOptional; metadata: z.ZodOptional>; custom: z.ZodOptional>; reasoning: z.ZodOptional; resource: z.ZodOptional; } & { toolRequest: z.ZodObject<{ ref: z.ZodOptional; name: z.ZodString; input: z.ZodOptional; }, "strip", z.ZodTypeAny, { name: string; input?: unknown; ref?: string | undefined; }, { name: string; input?: unknown; ref?: string | undefined; }>; }, "strip", z.ZodTypeAny, { toolRequest: { name: string; input?: unknown; ref?: string | undefined; }; custom?: Record | undefined; metadata?: Record | undefined; text?: undefined; media?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; }, { toolRequest: { name: string; input?: unknown; ref?: string | undefined; }; custom?: Record | undefined; metadata?: Record | undefined; text?: undefined; media?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; }>, z.ZodObject<{ text: z.ZodOptional; media: z.ZodOptional; toolRequest: z.ZodOptional; data: z.ZodOptional; metadata: z.ZodOptional>; custom: z.ZodOptional>; reasoning: z.ZodOptional; resource: z.ZodOptional; } & { toolResponse: z.ZodObject<{ ref: z.ZodOptional; name: z.ZodString; output: z.ZodOptional; }, "strip", z.ZodTypeAny, { name: string; ref?: string | undefined; output?: unknown; }, { name: string; ref?: string | undefined; output?: unknown; }>; }, "strip", z.ZodTypeAny, { toolResponse: { name: string; ref?: string | undefined; output?: unknown; }; custom?: Record | undefined; metadata?: Record | undefined; text?: undefined; media?: undefined; toolRequest?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; }, { toolResponse: { name: string; ref?: string | undefined; output?: unknown; }; custom?: Record | undefined; metadata?: Record | undefined; text?: undefined; media?: undefined; toolRequest?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; }>, z.ZodObject<{ text: z.ZodOptional; media: z.ZodOptional; toolRequest: z.ZodOptional; toolResponse: z.ZodOptional; metadata: z.ZodOptional>; custom: z.ZodOptional>; reasoning: z.ZodOptional; resource: z.ZodOptional; } & { data: z.ZodUnknown; }, "strip", z.ZodTypeAny, { custom?: Record | undefined; metadata?: Record | undefined; text?: undefined; media?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; }, { custom?: Record | undefined; metadata?: Record | undefined; text?: undefined; media?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; }>, z.ZodObject<{ text: z.ZodOptional; media: z.ZodOptional; toolRequest: z.ZodOptional; toolResponse: z.ZodOptional; data: z.ZodOptional; metadata: z.ZodOptional>; reasoning: z.ZodOptional; resource: z.ZodOptional; } & { custom: z.ZodRecord; }, "strip", z.ZodTypeAny, { custom: Record; metadata?: Record | undefined; text?: undefined; media?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; }, { custom: Record; metadata?: Record | undefined; text?: undefined; media?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; }>, z.ZodObject<{ text: z.ZodOptional; media: z.ZodOptional; toolRequest: z.ZodOptional; toolResponse: z.ZodOptional; data: z.ZodOptional; metadata: z.ZodOptional>; custom: z.ZodOptional>; resource: z.ZodOptional; } & { reasoning: z.ZodString; }, "strip", z.ZodTypeAny, { reasoning: string; custom?: Record | undefined; metadata?: Record | undefined; text?: undefined; media?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; resource?: undefined; }, { reasoning: string; custom?: Record | undefined; metadata?: Record | undefined; text?: undefined; media?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; resource?: undefined; }>, z.ZodObject<{ text: z.ZodOptional; media: z.ZodOptional; toolRequest: z.ZodOptional; toolResponse: z.ZodOptional; data: z.ZodOptional; metadata: z.ZodOptional>; custom: z.ZodOptional>; reasoning: z.ZodOptional; } & { resource: z.ZodObject<{ /** * Defines a dynamic resource. Dynamic resources are just like regular resources but will not be * registered in the Genkit registry and can be defined dynamically at runtime. */ uri: z.ZodString; }, "strip", z.ZodTypeAny, { uri: string; }, { uri: string; }>; }, "strip", z.ZodTypeAny, { resource: { uri: string; }; custom?: Record | undefined; metadata?: Record | undefined; text?: undefined; media?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; }, { resource: { uri: string; }; custom?: Record | undefined; metadata?: Record | undefined; text?: undefined; media?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; }>]>, "many">; }, "strip", z.ZodTypeAny, { content: ({ text: string; custom?: Record | undefined; metadata?: Record | undefined; media?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; } | { media: { url: string; contentType?: string | undefined; }; custom?: Record | undefined; metadata?: Record | undefined; text?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; } | { reasoning: string; custom?: Record | undefined; metadata?: Record | undefined; text?: undefined; media?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; resource?: undefined; } | { toolRequest: { name: string; input?: unknown; ref?: string | undefined; }; custom?: Record | undefined; metadata?: Record | undefined; text?: undefined; media?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; } | { toolResponse: { name: string; ref?: string | undefined; output?: unknown; }; custom?: Record | undefined; metadata?: Record | undefined; text?: undefined; media?: undefined; toolRequest?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; } | { custom?: Record | undefined; metadata?: Record | undefined; text?: undefined; media?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; } | { custom: Record; metadata?: Record | undefined; text?: undefined; media?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; } | { resource: { uri: string; }; custom?: Record | undefined; metadata?: Record | undefined; text?: undefined; media?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; })[]; }, { content: ({ text: string; custom?: Record | undefined; metadata?: Record | undefined; media?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; } | { media: { url: string; contentType?: string | undefined; }; custom?: Record | undefined; metadata?: Record | undefined; text?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; } | { reasoning: string; custom?: Record | undefined; metadata?: Record | undefined; text?: undefined; media?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; resource?: undefined; } | { toolRequest: { name: string; input?: unknown; ref?: string | undefined; }; custom?: Record | undefined; metadata?: Record | undefined; text?: undefined; media?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; } | { toolResponse: { name: string; ref?: string | undefined; output?: unknown; }; custom?: Record | undefined; metadata?: Record | undefined; text?: undefined; media?: undefined; toolRequest?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; } | { custom?: Record | undefined; metadata?: Record | undefined; text?: undefined; media?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; } | { custom: Record; metadata?: Record | undefined; text?: undefined; media?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; resource?: undefined; } | { resource: { uri: string; }; custom?: Record | undefined; metadata?: Record | undefined; text?: undefined; media?: undefined; toolRequest?: undefined; toolResponse?: undefined; data?: unknown; reasoning?: undefined; })[]; }>; type ResourceOutput = z.infer; /** * A function that returns parts for a given resource. */ type ResourceFn = (input: ResourceInput, ctx: ActionContext) => ResourceOutput | Promise; /** * A resource action. */ interface ResourceAction extends Action { matches(input: ResourceInput): boolean; } /** * Defines a resource. * * @param registry The registry to register the resource with. * @param opts The resource options. * @param fn The resource function. * @returns The resource action. */ declare function defineResource(registry: Registry, opts: ResourceOptions, fn: ResourceFn): ResourceAction; /** * A dynamic action with a `resource` type. Dynamic resources are detached actions -- not associated with any registry. */ type DynamicResourceAction = DetachedAction & { __action: { metadata: { type: 'resource'; }; }; matches(input: ResourceInput): boolean; }; /** * Finds a matching resource in the registry. If not found returns undefined. */ declare function findMatchingResource(registry: Registry, input: ResourceInput): Promise; /** Checks whether provided object is a dynamic resource. */ declare function isDynamicResourceAction(t: unknown): t is DynamicResourceAction; /** * Defines a dynamic resource. Dynamic resources are just like regular resources but will not be * registered in the Genkit registry and can be defined dynamically at runtime. */ declare function dynamicResource(opts: ResourceOptions, fn: ResourceFn): DynamicResourceAction; export { type DynamicResourceAction, type ResourceAction, type ResourceFn, type ResourceInput, ResourceInputSchema, type ResourceOptions, type ResourceOutput, ResourceOutputSchema, defineResource, dynamicResource, findMatchingResource, isDynamicResourceAction };