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"];
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>(type: ActionType, action: Action<I, O>, 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> {
    actionType?: ActionType;
    key?: string;
    name: string;
    description?: string;
    inputSchema?: I;
    inputJsonSchema?: JSONSchema7;
    outputSchema?: O;
    outputJsonSchema?: JSONSchema7;
    streamSchema?: S;
    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>;
    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;
    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;
    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> {
    /**
     * 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;
}
/**
 * Options (side channel) data to pass to the model.
 */
interface ActionFnArg<S> {
    /**
     * 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 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>>;
}
/**
 * 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>> = ActionRunOptions<z.infer<S>>> = ((input?: z.infer<I>, options?: RunOptions) => Promise<z.infer<O>>) & {
    __action: ActionMetadata<I, O, S>;
    __registry?: Registry;
    run(input?: z.infer<I>, options?: RunOptions): Promise<ActionResult<z.infer<O>>>;
    stream(input?: z.infer<I>, opts?: RunOptions): StreamingResponse<O, S>;
};
/**
 * Action factory params.
 */
type ActionParams<I extends z.ZodTypeAny, O extends z.ZodTypeAny, S extends z.ZodTypeAny = z.ZodTypeAny> = {
    name: string | {
        pluginId: string;
        actionId: string;
    };
    description?: string;
    inputSchema?: I;
    inputJsonSchema?: JSONSchema7;
    outputSchema?: O;
    outputJsonSchema?: JSONSchema7;
    metadata?: Record<string, any>;
    use?: Middleware<z.infer<I>, z.infer<O>, z.infer<S>>[];
    streamSchema?: S;
    actionType: ActionType;
};
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>>) => Promise<z.infer<O>>;
};
type SimpleMiddleware<I = any, O = any> = (req: I, next: (req?: I) => Promise<O>) => Promise<O>;
type MiddlewareWithOptions<I = any, O = any, S = any> = (req: I, options: ActionRunOptions<S> | undefined, next: (req?: I, options?: ActionRunOptions<S>) => 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>(action: Action<I, O, S>, middleware: Middleware<z.infer<I>, z.infer<O>, z.infer<S>>[]): Action<I, O, S>;
/**
 * Creates an action with the provided config.
 */
declare function action<I extends z.ZodTypeAny, O extends z.ZodTypeAny, S extends z.ZodTypeAny = z.ZodTypeAny>(config: ActionParams<I, O, S>, fn: (input: z.infer<I>, options: ActionFnArg<z.infer<S>>) => Promise<z.infer<O>>): Action<I, O, z.infer<S>>;
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>(registry: Registry, config: ActionParams<I, O, S>, fn: (input: z.infer<I>, options: ActionFnArg<z.infer<S>>) => Promise<z.infer<O>>): Action<I, O, S>;
/**
 * 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 { runWithStreamingCallback as $, type Action as A, type BackgroundAction as B, backgroundAction as C, defineAction as D, type ErrorResponseMetadata as E, defineActionAsync as F, GenkitError as G, defineBackgroundAction as H, InMemoryStreamManager as I, type JSONSchema as J, defineJsonSchema as K, defineSchema as L, type Middleware as M, getCallableJSON as N, type Operation as O, type Plugin as P, getHttpStatus as Q, type ResolvableAction as R, type SimpleMiddleware as S, getStreamingCallback as T, UnstableApiError as U, isAction as V, isBackgroundAction as W, isInRuntimeContext as X, registerBackgroundAction as Y, runInActionRuntimeContext as Z, runOutsideActionRuntimeContext as _, type ActionAsyncParams as a, sentinelNoopStreamingCallback as a0, toJsonSchema as a1, type ActionType as a2, type ActionMetadataRecord as a3, Registry as a4, type HasRegistry as a5, lookupBackgroundAction as a6, type HttpErrorWireFormat as a7, getErrorMessage as a8, getErrorStack as a9, type ProvidedSchema as aa, ValidationError as ab, type ValidationErrorDetail as ac, type ValidationResponse as ad, parseSchema as ae, validateSchema as af, type ActionsRecord as ag, type AsyncProvider as ah, type Schema as ai, isActionType as aj, parseRegistryKey as ak, 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 InitializedPlugin as m, type MiddlewareWithOptions as n, OperationSchema as o, type PluginProvider as p, type Provider as q, type StreamManager as r, StreamNotFoundError as s, type StreamingCallback as t, type StreamingResponse as u, UserFacingError as v, action as w, actionWithMiddleware as x, annotateSchema as y, assertUnstable as z };
