import { JSONSchema7 } from 'json-schema';
import * as z from 'zod';
import { z as z$1 } from 'zod';
import { ActionContext } from './context.js';
import { StatusName } from './statusTypes.js';
import { Dotprompt } from 'dotprompt';
import { JSONSchemaType } from 'ajv';

/**
 * 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 an opration representing a background task.
 */
declare const OperationSchema: z.ZodObject<{
    action: z.ZodOptional<z.ZodString>;
    id: z.ZodString;
    done: z.ZodOptional<z.ZodBoolean>;
    output: z.ZodOptional<z.ZodAny>;
    error: z.ZodOptional<z.ZodObject<{
        message: z.ZodString;
    }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
        message: z.ZodString;
    }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
        message: z.ZodString;
    }, z.ZodTypeAny, "passthrough">>>;
    metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
}, "strip", z.ZodTypeAny, {
    id: string;
    metadata?: Record<string, any> | undefined;
    error?: z.objectOutputType<{
        message: z.ZodString;
    }, z.ZodTypeAny, "passthrough"> | undefined;
    output?: any;
    action?: string | undefined;
    done?: boolean | undefined;
}, {
    id: string;
    metadata?: Record<string, any> | undefined;
    error?: z.objectInputType<{
        message: z.ZodString;
    }, z.ZodTypeAny, "passthrough"> | undefined;
    output?: any;
    action?: string | undefined;
    done?: boolean | undefined;
}>;
/**
 * Background operation.
 */
interface Operation<O = any> {
    action?: string;
    id: string;
    done?: boolean;
    output?: O;
    error?: {
        message: string;
        [key: string]: unknown;
    };
    metadata?: Record<string, any>;
}
/**
 * Background action. Unlike regular action, background action can run for a long time in the background.
 * The returned operation can used to check the status of the background operation and retrieve the response.
 */
interface BackgroundAction<I extends z.ZodTypeAny = z.ZodTypeAny, O extends z.ZodTypeAny = z.ZodTypeAny, RunOptions extends BackgroundActionRunOptions = BackgroundActionRunOptions> {
    __action: ActionMetadata<I, O>;
    readonly startAction: Action<I, typeof OperationSchema>;
    readonly checkAction: Action<typeof OperationSchema, typeof OperationSchema>;
    readonly cancelAction?: Action<typeof OperationSchema, typeof OperationSchema>;
    readonly supportsCancel: boolean;
    start(input?: z.infer<I>, options?: RunOptions): Promise<Operation<z.infer<O>>>;
    check(operation: Operation<z.infer<O>>): Promise<Operation<z.infer<O>>>;
    cancel(operation: Operation<z.infer<O>>): Promise<Operation<z.infer<O>>>;
}
declare function lookupBackgroundAction<I extends z.ZodTypeAny = z.ZodTypeAny, O extends z.ZodTypeAny = z.ZodTypeAny>(registry: Registry, key: string): Promise<BackgroundAction<I, O> | undefined>;
/**
 * Options (side channel) data to pass to the model.
 */
interface BackgroundActionRunOptions {
    /**
     * Additional runtime context data (ex. auth context data).
     */
    context?: ActionContext;
    /**
     * Additional span attributes to apply to OT spans.
     */
    telemetryLabels?: Record<string, string>;
}
/**
 * Options (side channel) data to pass to the model.
 */
interface BackgroundActionFnArg<S> {
    /**
     * Additional runtime context data (ex. auth context data).
     */
    context?: ActionContext;
    /**
     * Trace context containing trace and span IDs.
     */
    trace: {
        traceId: string;
        spanId: string;
    };
}
/**
 * Action factory params.
 */
type BackgroundActionParams<I extends z.ZodTypeAny, O extends z.ZodTypeAny, S extends z.ZodTypeAny = z.ZodTypeAny> = {
    name: string;
    start: (input: z.infer<I>, options: BackgroundActionFnArg<z.infer<S>>) => Promise<Operation<z.infer<O>>>;
    check: (input: Operation<z.infer<O>>) => Promise<Operation<z.infer<O>>>;
    cancel?: (input: Operation<z.infer<O>>) => Promise<Operation<z.infer<O>>>;
    actionType: ActionType;
    description?: string;
    inputSchema?: I;
    inputJsonSchema?: JSONSchema7;
    outputSchema?: O;
    outputJsonSchema?: JSONSchema7;
    metadata?: Record<string, any>;
    use?: Middleware<z.infer<I>, z.infer<O>>[];
    streamSchema?: S;
};
/**
 * Defines an action with the given config and registers it in the registry.
 */
declare function defineBackgroundAction<I extends z.ZodTypeAny, O extends z.ZodTypeAny, S extends z.ZodTypeAny = z.ZodTypeAny>(registry: Registry, config: BackgroundActionParams<I, O, S>): BackgroundAction<I, O>;
declare function registerBackgroundAction(registry: Registry, act: BackgroundAction<any, any>, opts?: {
    namespace?: string;
}): void;
/**
 * Creates a background action with the given config.
 */
declare function backgroundAction<I extends z.ZodTypeAny, O extends z.ZodTypeAny, S extends z.ZodTypeAny = z.ZodTypeAny>(config: BackgroundActionParams<I, O, S>): BackgroundAction<I, O>;
declare function isBackgroundAction(a: unknown): a is BackgroundAction;

/**
 * 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 Provider<T> {
    id: string;
    value: T;
}
interface PluginProvider {
    name: string;
    initializer: () => InitializedPlugin | void | Promise<InitializedPlugin | void>;
    resolver?: (action: ActionType, target: string) => Promise<void>;
    listActions?: () => Promise<ActionMetadata[]>;
}
interface InitializedPlugin {
    models?: Action<z$1.ZodTypeAny, z$1.ZodTypeAny>[];
    retrievers?: Action<z$1.ZodTypeAny, z$1.ZodTypeAny>[];
    embedders?: Action<z$1.ZodTypeAny, z$1.ZodTypeAny>[];
    indexers?: Action<z$1.ZodTypeAny, z$1.ZodTypeAny>[];
    evaluators?: Action<z$1.ZodTypeAny, z$1.ZodTypeAny>[];
    /** @deprecated */
    flowStateStore?: Provider<any> | Provider<any>[];
    /** @deprecated */
    traceStore?: Provider<any> | Provider<any>[];
    /** @deprecated */
    telemetry?: any;
}
type Plugin<T extends any[]> = (...args: T) => PluginProvider;
type ResolvableAction = Action | BackgroundAction;

/**
 * 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 HttpErrorWireFormat {
    details?: unknown;
    message: string;
    status: StatusName;
}
/**
 * Metadata from the HTTP response that triggered this error.
 * This is not serialized into the wire format — it's only available
 * in-process for middleware (e.g. retry) to make informed decisions.
 */
interface ErrorResponseMetadata {
    /** Provider-suggested retry delay in milliseconds (parsed from Retry-After header). */
    retryAfterMs?: number;
    /** Raw HTTP response headers, if available. */
    headers?: Record<string, string>;
}
/**
 * Base error class for Genkit errors.
 */
declare class GenkitError extends Error {
    source?: string;
    status: StatusName;
    detail?: any;
    code: number;
    /**
     * Metadata from the HTTP response that triggered this error.
     * Not serialized into the wire format — only available in-process
     * for middleware (e.g. retry) to make informed decisions.
     */
    responseMetadata?: ErrorResponseMetadata;
    originalMessage: string;
    constructor({ status, message, detail, source, responseMetadata, }: {
        status: StatusName;
        message: string;
        detail?: any;
        source?: string;
        responseMetadata?: ErrorResponseMetadata;
    });
    /**
     * Returns a JSON-serializable representation of this object.
     */
    toJSON(): HttpErrorWireFormat;
}
declare class UnstableApiError extends GenkitError {
    constructor(level: 'beta', message?: string);
}
/**
 * assertUnstable allows features to raise exceptions when using Genkit from *more* stable initialized instances.
 *
 * @param level The maximum stability channel allowed.
 * @param message An optional message describing which feature is not allowed.
 */
declare function assertUnstable(registry: Registry, level: 'beta', message?: string): void;
/**
 * Creates a new class of Error for issues to be returned to users.
 * Using this error allows a web framework handler (e.g. express, next) to know it
 * is safe to return the message in a request. Other kinds of errors will
 * result in a generic 500 message to avoid the possibility of internal
 * exceptions being leaked to attackers.
 * In JSON requests, code will be an HTTP code and error will be a response body.
 * In streaming requests, { code, message } will be passed as the error message.
 */
declare class UserFacingError extends GenkitError {
    constructor(status: StatusName, message: string, details?: any);
}
declare function getHttpStatus(e: any): number;
declare function getCallableJSON(e: any): HttpErrorWireFormat;
/**
 * Extracts error message from the given error object, or if input is not an error then just turn the error into a string.
 */
declare function getErrorMessage(e: any): string;
/**
 * Extracts stack trace from the given error object, or if input is not an error then returns undefined.
 */
declare function getErrorStack(e: any): string | undefined;

/**
 * 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.
 */

/**
 * JSON schema.
 */
type JSONSchema = JSONSchemaType<any> | any;
/**
 * Annotates a Zod schema with UI-specific metadata.
 *
 * NOTE: It's typically recommended to use x-genkit-* (or similar) as the prefix.
 */
declare function annotateSchema<T extends z$1.ZodTypeAny>(schema: T, annotations: Record<string, any>): T;
/**
 * Wrapper object for various ways schema can be provided.
 */
interface ProvidedSchema {
    jsonSchema?: JSONSchema;
    schema?: z$1.ZodTypeAny;
}
/**
 * Schema validation error.
 */
declare class ValidationError extends GenkitError {
    constructor({ data, errors, schema, }: {
        data: any;
        errors: ValidationErrorDetail[];
        schema: JSONSchema;
    });
}
/**
 * Converts a Zod schema into a JSON schema, utilizing an in-memory cache for known objects.
 * @param options Provide a json schema and/or zod schema. JSON schema has priority.
 * @returns A JSON schema.
 */
declare function toJsonSchema({ jsonSchema, schema, }: ProvidedSchema): JSONSchema | undefined;
/**
 * Schema validation error details.
 */
interface ValidationErrorDetail {
    path: string;
    message: string;
}
/**
 * Validation response.
 */
type ValidationResponse = {
    valid: true;
    errors?: undefined;
    schema: JSONSchema;
} | {
    valid: false;
    errors: ValidationErrorDetail[];
    schema: JSONSchema;
};
/**
 * Validates the provided data against the provided schema.
 */
declare function validateSchema(data: unknown, options: ProvidedSchema): ValidationResponse;
/**
 * Parses raw data object against the provided schema.
 */
declare function parseSchema<T = unknown>(data: unknown, options: ProvidedSchema): T;
/**
 * Registers provided schema as a named schema object in the Genkit registry.
 *
 * @hidden
 */
declare function defineSchema<T extends z$1.ZodTypeAny>(registry: Registry, name: string, schema: T): T;
/**
 * Registers provided JSON schema as a named schema object in the Genkit registry.
 *
 * @hidden
 */
declare function defineJsonSchema(registry: Registry, name: string, jsonSchema: JSONSchema): any;

type AsyncProvider<T> = () => Promise<T>;
/**
 * Type of a runnable action.
 */
declare const ACTION_TYPES: readonly ["custom", "dynamic-action-provider", "embedder", "evaluator", "executable-prompt", "flow", "indexer", "model", "background-model", "check-operation", "cancel-operation", "prompt", "reranker", "retriever", "tool", "tool.v2", "util", "resource", "agent", "agent-snapshot", "agent-abort"];
type ActionType = (typeof ACTION_TYPES)[number];
declare function isActionType(value: string): value is ActionType;
/**
 * A schema is either a Zod schema or a JSON schema.
 */
interface Schema {
    schema?: z.ZodTypeAny;
    jsonSchema?: JSONSchema;
}
interface ParsedRegistryKey {
    dynamicActionHost?: string;
    actionType: ActionType;
    pluginName?: string;
    actionName: string;
}
/**
 * Parses the registry key into key parts as per the key format convention. Ex:
 *  - mcp-host:tool/my-tool
 *  - /model/googleai/gemini-2.5-flash
 *  - /prompt/my-plugin/folder/my-prompt
 *  - /util/generate
 */
declare function parseRegistryKey(registryKey: string): ParsedRegistryKey | undefined;
type ActionsRecord = Record<string, Action<z.ZodTypeAny, z.ZodTypeAny>>;
type ActionMetadataRecord = Record<string, ActionMetadata>;
/**
 * The registry is used to store and lookup actions, trace stores, flow state stores, plugins, and schemas.
 */
declare class Registry {
    private actionsById;
    private pluginsByName;
    private schemasByName;
    private valueByTypeAndName;
    private allPluginsInitialized;
    apiStability: 'stable' | 'beta';
    readonly dotprompt: Dotprompt;
    readonly parent?: Registry;
    /** Additional runtime context data for flows and tools. */
    context?: ActionContext;
    constructor(parent?: Registry);
    /**
     * Creates a new registry overlaid onto the provided registry.
     * @param parent The parent registry.
     * @returns The new overlaid registry.
     */
    static withParent(parent: Registry): Registry;
    resolveActionNames(key: string): Promise<string[]>;
    /**
     * Looks up an action in the registry.
     * @param key The key of the action to lookup.
     * @returns The action.
     */
    lookupAction<I extends z.ZodTypeAny, O extends z.ZodTypeAny, R extends Action<I, O>>(key: string): Promise<R>;
    /**
     * Looks up a background action from the registry.
     * @param key The key of the action to lookup.
     * @returns The action.
     */
    lookupBackgroundAction(key: string): Promise<BackgroundAction | undefined>;
    /**
     * Registers an action in the registry.
     * @param type The type of the action to register.
     * @param action The action to register.
     */
    registerAction<I extends z.ZodTypeAny, O extends z.ZodTypeAny, S extends z.ZodTypeAny, Init extends z.ZodTypeAny>(type: ActionType, action: Action<I, O, S, any, Init>, opts?: {
        namespace?: string;
    }): void;
    /**
     * Registers an action promise in the registry.
     */
    registerActionAsync<I extends z.ZodTypeAny, O extends z.ZodTypeAny>(type: ActionType, name: string, action: PromiseLike<Action<I, O>>, opts?: {
        namespace?: string;
    }): void;
    /**
     * Returns all actions that have been registered in the registry.
     * @returns All actions in the registry as a map of <key, action>.
     */
    listActions(): Promise<ActionsRecord>;
    /**
     * Returns all actions that are resolvable by plugins as well as those that are already
     * in the registry.
     *
     * NOTE: this method should not be used in latency sensitive code paths.
     * It may rely on "admin" API calls such as "list models", which may cause increased cold start latency.
     *
     * @returns All resolvable action metadata as a map of <key, action metadata>.
     */
    listResolvableActions(): Promise<ActionMetadataRecord>;
    /**
     * Initializes all plugins in the registry.
     */
    initializeAllPlugins(): Promise<void>;
    /**
     * Registers a plugin provider. This plugin must be initialized before it can be used by calling {@link initializePlugin} or {@link initializeAllPlugins}.
     * @param name The name of the plugin to register.
     * @param provider The plugin provider.
     */
    registerPluginProvider(name: string, provider: PluginProvider): void;
    /**
     * Looks up a plugin.
     * @param name The name of the plugin to lookup.
     * @returns The plugin provider.
     */
    lookupPlugin(name: string): PluginProvider | undefined;
    /**
     * Resolves a new Action dynamically by registering it.
     * @param pluginName The name of the plugin
     * @param actionType The type of the action
     * @param actionName The name of the action
     * @returns
     */
    resolvePluginAction(pluginName: string, actionType: ActionType, actionName: string): Promise<void>;
    getDynamicAction(key: ParsedRegistryKey): Promise<Action<z.ZodTypeAny, z.ZodTypeAny> | undefined>;
    /**
     * Initializes a plugin already registered with {@link registerPluginProvider}.
     * @param name The name of the plugin to initialize.
     * @returns The plugin.
     */
    initializePlugin(name: string): Promise<void | InitializedPlugin>;
    /**
     * Registers a schema.
     * @param name The name of the schema to register.
     * @param data The schema to register (either a Zod schema or a JSON schema).
     */
    registerSchema(name: string, data: Schema): void;
    registerValue(type: string, name: string, value: any): void;
    lookupValue<T = unknown>(type: string, key: string): Promise<T | undefined>;
    listValues<T>(type: string): Promise<Record<string, T>>;
    /**
     * Looks up a schema.
     * @param name The name of the schema to lookup.
     * @returns The schema.
     */
    lookupSchema(name: string): Schema | undefined;
}
/**
 * An object that has a reference to Genkit Registry.
 */
interface HasRegistry {
    get registry(): Registry;
}

/**
 * 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.
 */

/**
 * Error thrown when a stream cannot be found.
 */
declare class StreamNotFoundError extends GenkitError {
    constructor(message: string);
}
/**
 * Interface for writing content to a stream.
 * @template S The type of the stream chunks.
 * @template O The type of the final output.
 */
interface ActionStreamInput<S, O> {
    /**
     * Writes a chunk to the stream.
     * @param chunk The chunk data to write.
     */
    write(chunk: S): Promise<void>;
    /**
     * Closes the stream with a final output.
     * @param output The final output data.
     */
    done(output: O): Promise<void>;
    /**
     * Closes the stream with an error.
     * @param err The error that occurred.
     */
    error(err: any): Promise<void>;
}
/**
 * Subscriber callbacks for receiving stream events.
 * @template S The type of the stream chunks.
 * @template O The type of the final output.
 */
type ActionStreamSubscriber<S, O> = {
    /** Called when a chunk is received. */
    onChunk: (chunk: S) => void;
    /** Called when the stream completes successfully. */
    onDone: (output: O) => void;
    /** Called when the stream encounters an error. */
    onError: (error: any) => void;
};
/**
 * Interface for managing streaming actions, allowing creation and subscription to streams.
 * Implementations can provide different storage backends (e.g., in-memory, database, cache).
 */
interface StreamManager {
    /**
     * Opens a stream for writing.
     * @param streamId The unique identifier for the stream.
     * @returns An object to write to the stream.
     */
    open<S, O>(streamId: string): Promise<ActionStreamInput<S, O>>;
    /**
     * Subscribes to a stream to receive its events.
     * @param streamId The unique identifier for the stream.
     * @param options The subscriber callbacks.
     * @returns A promise resolving to an object containing an unsubscribe function.
     */
    subscribe<S, O>(streamId: string, options: ActionStreamSubscriber<S, O>): Promise<{
        unsubscribe: () => void;
    }>;
}
/**
 * An in-memory implementation of StreamManager.
 * Useful for testing or single-instance deployments where persistence is not required.
 */
declare class InMemoryStreamManager implements StreamManager {
    private options;
    private streams;
    /**
     * @param options Configuration options.
     * @param options.ttlSeconds Time-to-live for streams in seconds. Defaults to 5 minutes.
     */
    constructor(options?: {
        ttlSeconds?: number;
    });
    private _cleanup;
    open<S, O>(streamId: string): Promise<ActionStreamInput<S, O>>;
    subscribe<S, O>(streamId: string, subscriber: ActionStreamSubscriber<S, O>): Promise<{
        unsubscribe: () => void;
    }>;
}

/**
 * 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.
 */

/**
 * Action metadata.
 */
interface ActionMetadata<I extends z.ZodTypeAny = z.ZodTypeAny, O extends z.ZodTypeAny = z.ZodTypeAny, S extends z.ZodTypeAny = z.ZodTypeAny> {
    /** The type of action (e.g. 'prompt', 'flow'). */
    actionType?: ActionType;
    /** Registry key (unique identifier). */
    key?: string;
    /** The name of the action. */
    name: string;
    /** Description of the action. */
    description?: string;
    /** Input Zod schema. */
    inputSchema?: I;
    /** Input JSON schema. */
    inputJsonSchema?: JSONSchema7;
    /** Output Zod schema. */
    outputSchema?: O;
    /** Output JSON schema. */
    outputJsonSchema?: JSONSchema7;
    /** Stream Zod schema. */
    streamSchema?: S;
    /** Schema of the initialization data. */
    initSchema?: z.ZodTypeAny;
    /** JSON schema of the initialization data. */
    initJsonSchema?: JSONSchema7;
    /** Metadata for the action. */
    metadata?: Record<string, any>;
}
/** Zod schema for {@link ActionMetadata}. */
declare const ActionMetadataSchema: z.ZodObject<{
    key: z.ZodOptional<z.ZodString>;
    actionType: z.ZodOptional<z.ZodString>;
    name: z.ZodString;
    description: z.ZodOptional<z.ZodString>;
    inputSchema: z.ZodOptional<z.ZodUnknown>;
    inputJsonSchema: z.ZodOptional<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>>;
    outputSchema: z.ZodOptional<z.ZodUnknown>;
    outputJsonSchema: z.ZodOptional<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>>;
    streamSchema: z.ZodOptional<z.ZodUnknown>;
    initSchema: z.ZodOptional<z.ZodUnknown>;
    initJsonSchema: z.ZodOptional<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>>;
    metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
}, "strip", z.ZodTypeAny, {
    name: string;
    key?: string | undefined;
    actionType?: string | undefined;
    description?: string | undefined;
    inputSchema?: unknown;
    inputJsonSchema?: {} | undefined;
    outputSchema?: unknown;
    outputJsonSchema?: {} | undefined;
    streamSchema?: unknown;
    initSchema?: unknown;
    initJsonSchema?: {} | undefined;
    metadata?: Record<string, any> | undefined;
}, {
    name: string;
    key?: string | undefined;
    actionType?: string | undefined;
    description?: string | undefined;
    inputSchema?: unknown;
    inputJsonSchema?: {} | undefined;
    outputSchema?: unknown;
    outputJsonSchema?: {} | undefined;
    streamSchema?: unknown;
    initSchema?: unknown;
    initJsonSchema?: {} | undefined;
    metadata?: Record<string, any> | undefined;
}>;
/**
 * Results of an action run. Includes telemetry.
 */
interface ActionResult<O> {
    result: O;
    telemetry: {
        traceId: string;
        spanId: string;
    };
}
/**
 * Options (side channel) data to pass to the model.
 */
interface ActionRunOptions<S, Init = any> {
    /**
     * Streaming callback (optional).
     */
    onChunk?: StreamingCallback<S>;
    /**
     * Additional runtime context data (ex. auth context data).
     */
    context?: ActionContext;
    /**
     * Additional span attributes to apply to OT spans.
     */
    telemetryLabels?: Record<string, string>;
    /**
     * Abort signal for the action request.
     */
    abortSignal?: AbortSignal;
    /**
     * Callback that fires immediately when the root span is created for the action,
     * providing early access to telemetry data (trace ID, span ID).
     * This is useful for scenarios where telemetry needs to be available before the action completes.
     * Note: This only fires once for the root action span, not for nested spans.
     */
    onTraceStart?: (traceInfo: {
        traceId: string;
        spanId: string;
    }) => void;
    /**
     * Initialization data provided to the action.
     */
    init?: Init;
}
/**
 * Options (side channel) data to pass to the model for bi-directional actions.
 */
interface BidiActionRunOptions<S, I = any, Init = any> extends ActionRunOptions<S, Init> {
    /**
     * Streaming input (optional).
     */
    inputStream?: AsyncIterable<I>;
}
/**
 * Options (side channel) data to pass to the model.
 */
interface ActionFnArg<S, I = any, Init = any> {
    /**
     * Whether the caller of the action requested streaming.
     */
    streamingRequested: boolean;
    /**
     * Streaming callback (optional).
     */
    sendChunk: StreamingCallback<S>;
    /**
     * Additional runtime context data (ex. auth context data).
     */
    context?: ActionContext;
    /**
     * Trace context containing trace and span IDs.
     */
    trace: {
        traceId: string;
        spanId: string;
    };
    /**
     * Abort signal for the action request.
     */
    abortSignal: AbortSignal;
    registry?: Registry;
    /**
     * Streaming input.
     *
     * The action runtime always provides this. For single-input (unary) actions
     * it is a stream containing just the one input item.
     */
    inputStream: AsyncIterable<I>;
    /**
     * Initialization data provided to the action.
     */
    init: Init;
}
/**
 * Streaming response from an action.
 */
interface StreamingResponse<O extends z.ZodTypeAny = z.ZodTypeAny, S extends z.ZodTypeAny = z.ZodTypeAny> {
    /** Iterator over the streaming chunks. */
    stream: AsyncGenerator<z.infer<S>>;
    /** Final output of the action. */
    output: Promise<z.infer<O>>;
}
/**
 * Streaming response from a bi-directional action.
 */
interface BidiStreamingResponse<O extends z.ZodTypeAny = z.ZodTypeAny, S extends z.ZodTypeAny = z.ZodTypeAny, I extends z.ZodTypeAny = z.ZodTypeAny> extends StreamingResponse<O, S> {
    /**
     * Sends a chunk of data to the action (for bi-directional streaming).
     */
    send(chunk: z.infer<I>): void;
    /**
     * Closes the input stream to the action.
     */
    close(): void;
}
/**
 * Self-describing, validating, observable, locally and remotely callable function.
 */
type Action<I extends z.ZodTypeAny = z.ZodTypeAny, O extends z.ZodTypeAny = z.ZodTypeAny, S extends z.ZodTypeAny = z.ZodTypeAny, RunOptions extends ActionRunOptions<z.infer<S>, z.infer<Init>> = ActionRunOptions<z.infer<S>, any>, Init extends z.ZodTypeAny = z.ZodTypeAny> = ((input?: z.infer<I>, options?: RunOptions) => Promise<z.infer<O>>) & {
    /** @hidden */
    __action: ActionMetadata<I, O, S>;
    /** @hidden */
    __registry?: Registry;
    run(input?: z.infer<I>, options?: RunOptions): Promise<ActionResult<z.infer<O>>>;
    stream(input?: z.infer<I>, opts?: RunOptions): StreamingResponse<O, S>;
};
interface BidiAction<IS extends z.ZodTypeAny = z.ZodTypeAny, O extends z.ZodTypeAny = z.ZodTypeAny, OS extends z.ZodTypeAny = z.ZodTypeAny, Init extends z.ZodTypeAny = z.ZodTypeAny, RunOptions extends BidiActionRunOptions<z.infer<OS>, z.infer<IS>, z.infer<Init>> = BidiActionRunOptions<z.infer<OS>, z.infer<IS>, z.infer<Init>>> extends Action<IS, O, OS, RunOptions, Init> {
    streamBidi(init?: z.infer<Init>, opts?: RunOptions): BidiStreamingResponse<O, OS, IS>;
}
/**
 * Action factory params.
 */
type ActionParams<I extends z.ZodTypeAny, O extends z.ZodTypeAny, S extends z.ZodTypeAny = z.ZodTypeAny, Init extends z.ZodTypeAny = z.ZodTypeAny> = {
    /**
     * Name of the action, or an object with pluginId and actionId.
     */
    name: string | {
        pluginId: string;
        actionId: string;
    };
    /**
     * Description of the action.
     */
    description?: string;
    /**
     * Input Zod schema.
     */
    inputSchema?: I;
    /**
     * Input JSON schema.
     */
    inputJsonSchema?: JSONSchema7;
    /**
     * Output Zod schema.
     */
    outputSchema?: O;
    /**
     * Output JSON schema.
     */
    outputJsonSchema?: JSONSchema7;
    /**
     * Metadata for the action.
     */
    metadata?: Record<string, any>;
    /**
     * Middleware to apply to the action.
     */
    use?: Middleware<z.infer<I>, z.infer<O>, z.infer<S>>[];
    /**
     * Stream Zod schema.
     */
    streamSchema?: S;
    /**
     * The type of action.
     */
    actionType: ActionType;
    /**
     * Zod schema for the initialization data.
     */
    initSchema?: Init;
    /**
     * JSON schema for the initialization data.
     */
    initJsonSchema?: JSONSchema7;
};
/**
 * Configuration for an async action (lazy loaded).
 */
type ActionAsyncParams<I extends z.ZodTypeAny, O extends z.ZodTypeAny, S extends z.ZodTypeAny = z.ZodTypeAny> = ActionParams<I, O, S> & {
    fn: (input: z.infer<I>, options: ActionFnArg<z.infer<S>, z.infer<I>>) => Promise<z.infer<O>>;
};
/**
 * Simple middleware that only modifies request/response.
 */
type SimpleMiddleware<I = any, O = any> = (req: I, next: (req?: I) => Promise<O>) => Promise<O>;
/**
 * Middleware that has access to options (including streaming callback).
 */
type MiddlewareWithOptions<I = any, O = any, S = any> = (req: I, options: ActionRunOptions<S, I> | undefined, next: (req?: I, options?: ActionRunOptions<S, I>) => Promise<O>) => Promise<O>;
/**
 * Middleware function for actions.
 */
type Middleware<I = any, O = any, S = any> = SimpleMiddleware<I, O> | MiddlewareWithOptions<I, O, S>;
/**
 * Creates an action with provided middleware.
 */
declare function actionWithMiddleware<I extends z.ZodTypeAny, O extends z.ZodTypeAny, S extends z.ZodTypeAny = z.ZodTypeAny, Init extends z.ZodTypeAny = z.ZodTypeAny>(action: Action<I, O, S, any, Init>, middleware: Middleware<z.infer<I>, z.infer<O>, z.infer<S>>[]): Action<I, O, S, any, Init>;
/**
 * Creates an action with the provided config.
 */
declare function action<I extends z.ZodTypeAny, O extends z.ZodTypeAny, S extends z.ZodTypeAny = z.ZodTypeAny, Init extends z.ZodTypeAny = z.ZodTypeAny>(config: ActionParams<I, O, S, Init>, fn: (input: z.infer<I>, options: ActionFnArg<z.infer<S>, z.infer<Init>>) => Promise<z.infer<O>>): Action<I, O, z.infer<S>, any, Init>;
declare function isAction(a: unknown): a is Action;
/**
 * Defines an action with the given config and registers it in the registry.
 */
declare function defineAction<I extends z.ZodTypeAny, O extends z.ZodTypeAny, S extends z.ZodTypeAny = z.ZodTypeAny, Init extends z.ZodTypeAny = z.ZodTypeAny>(registry: Registry, config: ActionParams<I, O, S, Init>, fn: (input: z.infer<I>, options: ActionFnArg<z.infer<S>, z.infer<I>, z.infer<Init>>) => Promise<z.infer<O>>): Action<I, O, S, ActionRunOptions<z.infer<S>, z.infer<I>>, Init>;
/**
 * Defines a bi-directional action with the given config and registers it in the registry.
 */
declare function defineBidiAction<IS extends z.ZodTypeAny, O extends z.ZodTypeAny, OS extends z.ZodTypeAny = z.ZodTypeAny, Init extends z.ZodTypeAny = z.ZodTypeAny>(registry: Registry, config: ActionParams<IS, O, OS, Init>, fn: (input: ActionFnArg<z.infer<OS>, z.infer<IS>, z.infer<Init>>) => AsyncGenerator<z.infer<OS>, z.infer<O>, void>): BidiAction<IS, O, OS, Init>;
/**
 * Creates a bi-directional action with the given config.
 */
declare function bidiAction<IS extends z.ZodTypeAny, O extends z.ZodTypeAny, OS extends z.ZodTypeAny = z.ZodTypeAny, Init extends z.ZodTypeAny = z.ZodTypeAny>(config: ActionParams<IS, O, OS, Init>, fn: (input: ActionFnArg<z.infer<OS>, z.infer<IS>, z.infer<Init>>) => AsyncGenerator<z.infer<OS>, z.infer<O>, void>): BidiAction<IS, O, OS, Init>;
/**
 * Defines an action with the given config promise and registers it in the registry.
 */
declare function defineActionAsync<I extends z.ZodTypeAny, O extends z.ZodTypeAny, S extends z.ZodTypeAny = z.ZodTypeAny>(registry: Registry, actionType: ActionType, name: string | {
    pluginId: string;
    actionId: string;
}, config: PromiseLike<ActionAsyncParams<I, O, S>>, onInit?: (action: Action<I, O, S>) => void): PromiseLike<Action<I, O, S>>;
/** Callback function invoked with each streaming chunk during action execution. */
type StreamingCallback<T> = (chunk: T) => void;
declare const sentinelNoopStreamingCallback: () => null;
/**
 * Executes provided function with streaming callback in async local storage which can be retrieved
 * using {@link getStreamingCallback}.
 */
declare function runWithStreamingCallback<S, O>(streamingCallback: StreamingCallback<S> | undefined, fn: () => O): O;
/**
 * Retrieves the {@link StreamingCallback} previously set by {@link runWithStreamingCallback}
 *
 * @hidden
 */
declare function getStreamingCallback<S>(): StreamingCallback<S> | undefined;
/**
 * Checks whether the caller is currently in the runtime context of an action.
 */
declare function isInRuntimeContext(): boolean;
/**
 * Execute the provided function in the action runtime context.
 */
declare function runInActionRuntimeContext<R>(fn: () => R): R;
/**
 * Execute the provided function outside the action runtime context.
 */
declare function runOutsideActionRuntimeContext<R>(fn: () => R): R;

export { isBackgroundAction as $, type Action as A, type BackgroundAction as B, actionWithMiddleware as C, annotateSchema as D, type ErrorResponseMetadata as E, assertUnstable as F, GenkitError as G, backgroundAction as H, InMemoryStreamManager as I, type JSONSchema as J, bidiAction as K, defineAction as L, type Middleware as M, defineActionAsync as N, type Operation as O, type Plugin as P, defineBackgroundAction as Q, type ResolvableAction as R, type SimpleMiddleware as S, defineBidiAction as T, UnstableApiError as U, defineJsonSchema as V, defineSchema as W, getCallableJSON as X, getHttpStatus as Y, getStreamingCallback as Z, isAction as _, type ActionAsyncParams as a, isInRuntimeContext as a0, registerBackgroundAction as a1, runInActionRuntimeContext as a2, runOutsideActionRuntimeContext as a3, runWithStreamingCallback as a4, sentinelNoopStreamingCallback as a5, toJsonSchema as a6, type ActionType as a7, type ActionMetadataRecord as a8, Registry as a9, type HasRegistry as aa, lookupBackgroundAction as ab, type HttpErrorWireFormat as ac, getErrorMessage as ad, getErrorStack as ae, type ProvidedSchema as af, ValidationError as ag, type ValidationErrorDetail as ah, type ValidationResponse as ai, parseSchema as aj, validateSchema as ak, type ActionsRecord as al, type AsyncProvider as am, type Schema as an, isActionType as ao, parseRegistryKey as ap, type ActionFnArg as b, type ActionMetadata as c, ActionMetadataSchema as d, type ActionParams as e, type ActionResult as f, type ActionRunOptions as g, type ActionStreamInput as h, type ActionStreamSubscriber as i, type BackgroundActionFnArg as j, type BackgroundActionParams as k, type BackgroundActionRunOptions as l, type BidiAction as m, type BidiActionRunOptions as n, type BidiStreamingResponse as o, type InitializedPlugin as p, type MiddlewareWithOptions as q, OperationSchema as r, type PluginProvider as s, type Provider as t, type StreamManager as u, StreamNotFoundError as v, type StreamingCallback as w, type StreamingResponse as x, UserFacingError as y, action as z };
