import type { StandardSchemaV1 } from "./standard-schema"; export type JsonPrimitive = string | number | boolean | null; export type JsonValue = JsonPrimitive | JsonObject | readonly JsonValue[]; export interface JsonObject { readonly [key: string]: JsonValue; } export type ToolSchema = StandardSchemaV1 | JsonObject; export interface IntegrationDeclaration { readonly integration: Slug; } export type ToolHandlerContext< TIntegrations extends Readonly> | undefined, > = { readonly [K in keyof NonNullable]: unknown; }; type InferToolInput = TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput : unknown; type InferToolOutput = TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput : unknown; export interface DefineToolOptions< TInputSchema extends ToolSchema, TOutputSchema extends ToolSchema | undefined = undefined, TIntegrations extends Readonly> | undefined = undefined, > { readonly description: string; readonly integrations?: TIntegrations; readonly input: TInputSchema; readonly output?: TOutputSchema; readonly annotations?: { readonly readOnly?: boolean; readonly destructive?: boolean; readonly requiresApproval?: boolean; }; readonly handler: ( input: InferToolInput, context: ToolHandlerContext, ) => | Promise : unknown> | (TOutputSchema extends ToolSchema ? InferToolOutput : unknown); } export const integration = (slug: Slug): IntegrationDeclaration => ({ integration: slug, }); export const defineTool = < TInputSchema extends ToolSchema, TOutputSchema extends ToolSchema | undefined = undefined, TIntegrations extends Readonly> | undefined = undefined, >( definition: DefineToolOptions, ): DefineToolOptions => definition;