You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
919 B
38 lines
919 B
import type { JSONSchema7 } from "json-schema";
|
|
|
|
export interface ToolExecutor<TConfig> {
|
|
buildInputSchema(config: TConfig): JSONSchema7;
|
|
buildDescription(config: TConfig): string;
|
|
execute(input: unknown, config: TConfig, ctx: ToolContext): Promise<ToolResult>;
|
|
}
|
|
|
|
export interface ToolContext {
|
|
toolId: string;
|
|
toolSlug: string;
|
|
userId: number | null;
|
|
}
|
|
|
|
export interface ToolResult {
|
|
success: boolean;
|
|
data?: unknown;
|
|
error?: string;
|
|
metadata?: {
|
|
statusCode?: number;
|
|
responseSize?: number;
|
|
durationMs: number;
|
|
};
|
|
}
|
|
|
|
const registry = new Map<string, ToolExecutor<any>>();
|
|
|
|
export function registerToolType(type: string, executor: ToolExecutor<any>): void {
|
|
registry.set(type, executor);
|
|
}
|
|
|
|
export function getExecutor(type: string): ToolExecutor<any> | undefined {
|
|
return registry.get(type);
|
|
}
|
|
|
|
export function listToolTypes(): string[] {
|
|
return Array.from(registry.keys());
|
|
}
|
|
|