import { JSONSchema7 } from 'json-schema'; type MaybePromise = T | Promise; type DataRegion = 'eu' | 'us' | 'apac'; /** * Provider-neutral multi-modal content parts. A single `Message.content` * is a string (classic path); multi-modal messages populate `parts` * alongside — adapters that understand parts read them, the rest fall * back to `content` (which we keep as a text projection via * `partsToText`). */ interface TextPart { type: 'text'; text: string; } interface ImagePart { type: 'image'; /** Data URL, http(s) URL, or provider-hosted reference id. */ source: string; mimeType?: string; /** Provider-neutral hint, e.g. 'low' / 'high'. */ detail?: 'low' | 'high' | 'auto'; } interface AudioPart { type: 'audio'; source: string; mimeType?: string; /** Duration in seconds, if known. */ durationSec?: number; } interface VideoPart { type: 'video'; source: string; mimeType?: string; durationSec?: number; } interface FilePart { type: 'file'; source: string; mimeType?: string; /** Original filename, when available. */ filename?: string; } type ContentPart = TextPart | ImagePart | AudioPart | VideoPart | FilePart; type PartKind = ContentPart['type']; /** Build a text part. */ declare function textPart(text: string): TextPart; /** Build an image part from a URL / data URI / hosted id. */ declare function imagePart(source: string, opts?: Omit): ImagePart; declare function audioPart(source: string, opts?: Omit): AudioPart; declare function videoPart(source: string, opts?: Omit): VideoPart; declare function filePart(source: string, opts?: Omit): FilePart; /** * Collapse a parts array into a text-only projection. Non-text parts * are rendered as `[image: url]` / `[audio: url]` etc. so plain-text * adapters see *something* meaningful. */ declare function partsToText(parts: ContentPart[]): string; /** * Normalize any of (string | ContentPart[] | undefined) into * `{ text, parts }`. Callers that have both the legacy `content` * string and the new `parts` array use this to pick the right one. */ declare function normalizeContent(content: string | undefined, parts: ContentPart[] | undefined): { text: string; parts: ContentPart[]; }; /** Filter parts by kind. */ declare function filterParts(parts: ContentPart[], kind: T): Extract[]; type ToolCallStatus = 'pending' | 'running' | 'complete' | 'error' | 'requires_confirmation'; interface ToolCall { id: string; name: string; args: Record; result?: string; error?: string; status: ToolCallStatus; } interface ToolExecutionContext { messages: Message[]; call: ToolCall; } interface ArgsValidationError { /** JSON pointer / dotted path to the offending field, or '' for root. */ path: string; message: string; } interface ArgsValidationResult { valid: boolean; errors?: ArgsValidationError[]; /** Optional pre-built human summary; used verbatim in the thrown error. */ message?: string; } /** * Validate parsed tool-call args against the tool's JSON Schema. * Returns `{ valid: true }` to allow execution, or `{ valid: false, errors }` * to reject it with `AK_TOOL_INVALID_INPUT`. */ type ArgsValidator = (schema: JSONSchema7, args: Record) => ArgsValidationResult; /** Map JSON Schema `type` strings to TypeScript types. */ type JSONSchemaTypeMap = { string: string; number: number; integer: number; boolean: boolean; null: null; object: Record; array: unknown[]; }; /** Resolve a single JSON Schema property to a TypeScript type. */ type InferJSONSchemaProperty = T extends { type: 'object'; properties: infer P; } ? InferJSONSchemaObject : T extends { type: 'array'; items: infer I; } ? Array> : T extends { type: infer U; } ? U extends keyof JSONSchemaTypeMap ? JSONSchemaTypeMap[U] : unknown : unknown; /** Resolve an object schema to a mapped type with required/optional handling. */ type InferJSONSchemaObject = T extends { properties: infer P; required: infer R; } ? R extends readonly string[] ? { [K in keyof P & string as K extends R[number] ? K : never]: InferJSONSchemaProperty; } & { [K in keyof P & string as K extends R[number] ? never : K]?: InferJSONSchemaProperty; } : { [K in keyof P & string]?: InferJSONSchemaProperty; } : T extends { properties: infer P; } ? { [K in keyof P & string]?: InferJSONSchemaProperty; } : Record; /** Top-level inference: extract args type from a JSON Schema definition. */ type InferSchemaType = T extends { type: 'object'; properties: infer _P; } ? InferJSONSchemaObject : Record; interface ToolDefinition> { name: string; description?: string; schema?: JSONSchema7; requiresConfirmation?: boolean; execute?: (args: TArgs, context: ToolExecutionContext) => MaybePromise | AsyncIterable; init?: () => MaybePromise; dispose?: () => MaybePromise; tags?: string[]; category?: string; } /** Config for defineTool: schema is narrowed to a const type for inference. */ interface DefineToolConfig { name: string; description?: string; schema?: TSchema; requiresConfirmation?: boolean; execute?: (args: InferSchemaType, context: ToolExecutionContext) => MaybePromise | AsyncIterable; init?: () => MaybePromise; dispose?: () => MaybePromise; tags?: string[]; category?: string; } /** Create a ToolDefinition with automatic type inference from the JSON schema. */ declare function defineTool(config: DefineToolConfig): ToolDefinition>; interface ToolCallHandlerContext { messages: Message[]; tool?: ToolDefinition; } type ToolAuthorizationPhase = 'propose' | 'execute'; interface ToolAuthorizationContext extends ToolCallHandlerContext { phase: ToolAuthorizationPhase; } interface ToolAuthorizationDecision { allowed: boolean; reason?: string; } type ToolAuthorizer = (toolCall: ToolCall, context: ToolAuthorizationContext) => MaybePromise; type MessageRole = 'user' | 'assistant' | 'system' | 'tool'; type MessageStatus = 'pending' | 'streaming' | 'complete' | 'error'; interface Message { id: string; role: MessageRole; /** Text projection of the message. Always populated, even for multi-modal. */ content: string; /** * Multi-modal parts. When provided, `content` is a text projection * of these parts (see `partsToText`). Adapters that support the * relevant modality should prefer `parts` over `content`. */ parts?: ContentPart[]; status: MessageStatus; toolCalls?: ToolCall[]; toolCallId?: string; metadata?: Record; createdAt: Date; } interface MemoryRecord { version: 1; messages: Array & { createdAt: string; }>; } export { type ArgsValidator as A, videoPart as B, type ContentPart as C, type DataRegion as D, type FilePart as F, type ImagePart as I, type Message as M, type PartKind as P, type ToolDefinition as T, type VideoPart as V, type MemoryRecord as a, type MessageRole as b, type MessageStatus as c, type ToolExecutionContext as d, type ToolCall as e, type MaybePromise as f, type ToolAuthorizer as g, type ArgsValidationError as h, type ArgsValidationResult as i, type AudioPart as j, type DefineToolConfig as k, type InferSchemaType as l, type TextPart as m, type ToolAuthorizationContext as n, type ToolAuthorizationDecision as o, type ToolAuthorizationPhase as p, type ToolCallHandlerContext as q, type ToolCallStatus as r, audioPart as s, defineTool as t, filePart as u, filterParts as v, imagePart as w, normalizeContent as x, partsToText as y, textPart as z };