@agenite/tool
Version:
Tool interface for Agenite
85 lines (81 loc) • 2.56 kB
text/typescript
import { ToolDefinition, TokenUsage } from '@agenite/llm';
import { z } from 'zod';
interface Tool$1<TInput = unknown> {
readonly name: string;
readonly description: string;
readonly version?: string;
readonly inputSchema?: ToolDefinition['inputSchema'];
execute(params: ToolExecuteParams<TInput>): Promise<ToolResponse>;
validate?(input: TInput): Promise<ValidationResult>;
}
type SchemaType<T> = z.ZodType<T> | JSONSchema;
interface JSONSchema {
type: string;
properties?: Record<string, unknown>;
required?: string[];
[k: string]: unknown;
}
interface ToolOptions<TInput> {
name: string;
description: string;
version?: string;
inputSchema?: SchemaType<TInput>;
execute: (params: ToolExecuteParams<TInput>) => Promise<ToolResponse>;
validate?: (input: TInput) => Promise<ValidationResult>;
}
interface ToolExecuteParams<TInput> {
input: TInput;
context?: ToolContext;
}
interface ToolContext {
agentId?: string;
executionId?: string;
parentToolExecutionId?: string;
extraContext?: Record<string, unknown>;
metadata?: Record<string, unknown>;
}
type ToolResponseData = string | Array<ToolResponseBlock>;
interface ToolResponseBlock {
type: 'text' | 'image';
text?: string;
image?: {
type: 'base64';
media_type: string;
data: string;
};
}
interface ToolResponse {
isError: boolean;
data: ToolResponseData;
error?: {
code: string;
message: string;
details?: unknown;
};
duration?: number;
tokenUsage?: TokenUsage;
}
interface ValidationResult {
isValid: boolean;
errors?: ValidationError[];
}
interface ValidationError {
field: string;
message: string;
}
declare class Tool<TInput = unknown> implements Tool$1<TInput> {
readonly name: string;
readonly description: string;
readonly version?: string;
readonly inputSchema?: ToolDefinition['inputSchema'];
private readonly executeImpl;
private readonly validateImpl?;
private readonly zodSchema?;
private readonly jsonSchema?;
constructor(options: ToolOptions<TInput>);
private createToolSchema;
execute(params: ToolExecuteParams<TInput>): Promise<ToolResponse>;
validate(input: TInput): Promise<ValidationResult>;
private validateJsonSchema;
}
export { type JSONSchema, type SchemaType, Tool, type ToolContext, type ToolExecuteParams, type ToolOptions, type ToolResponse, type ToolResponseBlock, type ToolResponseData, type ValidationError, type ValidationResult };