import * as ajv from 'ajv'; import { ErrorObject } from 'ajv'; import { Run, GetRunContext, RunContext } from '../context.js'; import { FrameworkError } from '../errors.js'; import { Serializable } from '../internals/serializable.js'; import { Task } from 'promise-based-task'; import { BaseCache } from '../cache/base.js'; import { AnyToolSchemaLike, FromSchemaLikeRaw, FromSchemaLike } from '../internals/helpers/schema.js'; import { ZodSchema, z } from 'zod'; import { E as Emitter, C as Callback } from '../emitter-l0W9gC1A.js'; import '../internals/helpers/promise.js'; import '../internals/types.js'; import '../internals/helpers/guards.js'; import 'zod-to-json-schema'; declare class ToolError extends FrameworkError { } declare class ToolInputValidationError extends ToolError { validationErrors: ErrorObject[]; constructor(message: string, validationErrors?: ErrorObject[]); } interface RetryOptions { maxRetries?: number; factor?: number; } interface BaseToolOptions { retryOptions?: RetryOptions; fatalErrors?: ErrorConstructor[]; cache?: BaseCache> | false; } interface BaseToolRunOptions { retryOptions?: RetryOptions; signal?: AbortSignal; } declare abstract class ToolOutput extends Serializable { abstract getTextContent(): string; abstract isEmpty(): boolean; toString(): string; } declare class StringToolOutput extends ToolOutput { readonly result: string; readonly ctx?: Record | undefined; constructor(result?: string, ctx?: Record | undefined); isEmpty(): boolean; getTextContent(): string; createSnapshot(): { result: string; ctx: Record | undefined; }; loadSnapshot(snapshot: ReturnType): void; } declare class JSONToolOutput extends ToolOutput { readonly result: T; readonly ctx?: Record | undefined; constructor(result: T, ctx?: Record | undefined); isEmpty(): boolean; getTextContent(): string; createSnapshot(): { result: T; ctx: Record | undefined; }; loadSnapshot(snapshot: ReturnType): void; } interface ToolSnapshot { name: string; description: string; options: TOptions; cache: BaseCache>; emitter: Emitter; } type InferToolOutput = T extends Tool ? A : never; type ToolInput = FromSchemaLike>>; type ToolInputRaw = FromSchemaLikeRaw>>; type ToolConstructorParameters = Partial extends TOptions ? [options?: TOptions] : [options: TOptions]; interface ToolEvents = Record, TOutput extends ToolOutput = ToolOutput> { start: Callback<{ input: TInput; options: unknown; }>; success: Callback<{ output: TOutput; input: TInput; options: unknown; }>; error: Callback<{ input: TInput; error: ToolError | ToolInputValidationError; options: unknown; }>; retry: Callback<{ error: ToolError | ToolInputValidationError; input: TInput; options: unknown; }>; finish: Callback; } /** * @deprecated Use ToolEmitter instead */ type CustomToolEmitter, B extends ToolOutput, C = Record> = Emitter & Omit>; type ToolEmitter, B extends ToolOutput, C = Record> = Emitter & Omit>; declare abstract class Tool extends Serializable { abstract name: string; abstract description: string; readonly cache: BaseCache>; readonly options: TOptions; static contextKeys: { readonly Memory: symbol; }; abstract readonly emitter: Emitter>; abstract inputSchema(): Promise | AnyToolSchemaLike; constructor(...args: ToolConstructorParameters); protected toError(e: Error, context: any): ToolError; run(input: ToolInputRaw, options?: Partial): Run>>, Partial]>; protected _runCached(input: ToolInput, options: Partial, run: GetRunContext): Promise; clearCache(): Promise; protected abstract _run(arg: ToolInput, options: Partial, run: GetRunContext): Promise; getInputJsonSchema(): Promise; static isTool(value: unknown): value is Tool; private _createRetryOptions; parse(input: unknown | ToolInputRaw | ToolInput): Promise>; protected preprocessInput(rawInput: unknown): void; protected validateInput(schema: AnyToolSchemaLike, rawInput: unknown): asserts rawInput is ToolInput; createSnapshot(): ToolSnapshot; loadSnapshot(snapshot: ToolSnapshot): void; pipe(this: S, tool: T, mapper: (input: ToolInputRaw, output: TOutput, options: Partial, run: RunContext>, TOptions, TRunOptions, ToolInput>>) => ToolInputRaw): DynamicTool>>, z.ZodTypeDef, FromSchemaLike>>>, TOptions, TRunOptions, FromSchemaLike>>>; extend(this: S, schema: TS, mapper: (input: z.output, options: Partial, run: RunContext>>) => ToolInputRaw, overrides?: { name?: string; description?: string; }): DynamicTool>; } type AnyTool = Tool; declare class DynamicTool> extends Tool { name: string; description: string; private readonly _inputSchema; readonly emitter: Emitter, TOutput>>; private readonly handler; inputSchema(): TInputSchema; constructor(fields: { name: string; description: string; inputSchema: TInputSchema; handler: (input: TInput, options: Partial, run: GetRunContext>) => Promise; options?: TOptions; }); protected _run(arg: TInput, options: Partial, run: GetRunContext>): Promise; createSnapshot(): { handler: ((input: TInput, options: Partial, run: GetRunContext>) => Promise) & ((...args: unknown[]) => unknown); _inputSchema: TInputSchema; name: string; description: string; options: TOptions; cache: BaseCache>; emitter: Emitter; }; loadSnapshot({ handler, ...snapshot }: ReturnType): void; } export { type AnyTool, type BaseToolOptions, type BaseToolRunOptions, type CustomToolEmitter, DynamicTool, type InferToolOutput, JSONToolOutput, type RetryOptions, StringToolOutput, Tool, type ToolEmitter, ToolError, type ToolEvents, type ToolInput, type ToolInputRaw, ToolInputValidationError, ToolOutput, type ToolSnapshot };