import type { McpServerConfig } from "@poe-code/agent-mcp-config"; import type { AnySchema, ObjectSchema, Static } from "toolcraft-schema"; import type { LoggerOutput, RenderTableOptions, ThemePalette } from "toolcraft-design"; import { ApprovalDeclinedError } from "./human-in-loop/types.js"; import type { HumanInLoopConfig, HumanInLoopPending, HumanInLoopRuntime } from "./human-in-loop/types.js"; import { ToolcraftBugError, UserError, isUserError } from "./user-error.js"; import type { RuntimeLogger } from "./runtime-logging.js"; import type { StreamStatusEvent, ToolcraftStream } from "./stream.js"; export { createManagedStream } from "./stream.js"; export type { StreamConsumerOptions, StreamStatusEvent, StreamStatusType, ToolcraftStream } from "./stream.js"; type ScopeValue = "cli" | "mcp" | "sdk"; type AnyObjectSchema = ObjectSchema>; type EmptyServices = Record; type ScopeInput = readonly Scope[] | undefined; type HumanInLoopMode = "sync" | "async"; type HumanInLoopModeInput = HumanInLoopMode | null | undefined; export type Scope = ScopeValue; type ResolveOwnHumanInLoopMode = TValue extends { mode: infer TMode extends HumanInLoopMode; } ? TMode : TValue extends null ? null : undefined; export interface SecretDefinition { env: string; description?: string; optional?: boolean; } export type SecretDeclarations = Record; type OptionalSecretKeys = { [TKey in keyof TSecrets]: TSecrets[TKey] extends { optional: true; } ? TKey : never; }[keyof TSecrets]; type RequiredSecretKeys = Exclude>; export type InferSecrets = TSecrets extends SecretDeclarations ? { [TKey in RequiredSecretKeys]: string; } & { [TKey in OptionalSecretKeys]?: string; } : Record; export interface HandlerFs { readFile(path: string, encoding?: BufferEncoding): Promise; writeFile(path: string, contents: string, options?: { encoding?: BufferEncoding; flag?: string; mode?: number; }): Promise; exists(path: string): Promise; lstat(path: string): Promise<{ isSymbolicLink(): boolean; }>; rename(fromPath: string, toPath: string): Promise; unlink(path: string): Promise; } export interface HandlerEnv { get(key: string): string | undefined; } export interface RenderPrimitives { logger: LoggerOutput; renderTable(options: RenderTableOptions): string; getTheme(): ThemePalette; note(message: string, title?: string): void; outputFormat: string; } export interface CheckResult { ok: boolean; message?: string; } export interface CommandExample { title: string; params: Record; } export type GroupCheckContext = TServices & { params?: unknown; secrets?: Record; fetch: typeof globalThis.fetch; fs: HandlerFs; env: HandlerEnv; diagnostics: RuntimeLogger; progress(message: string): void; }; export type CommandCheckContext = AnyObjectSchema, TSecrets extends SecretDeclarations | undefined = undefined, TServices extends object = EmptyServices> = TServices & { params?: Static; secrets?: InferSecrets; fetch: typeof globalThis.fetch; fs: HandlerFs; env: HandlerEnv; diagnostics: RuntimeLogger; progress(message: string): void; }; export interface Requires { auth?: boolean; apiVersion?: string; check?: (ctx: TContext) => Promise; } export interface Renderers { rich?: (result: TResult, primitives: RenderPrimitives) => void; markdown?: (result: TResult, primitives: RenderPrimitives) => string; json?: (result: TResult, primitives: RenderPrimitives) => unknown; } /** Standard MCP hints that describe a tool's behavior to clients. */ export interface ToolAnnotations { title?: string; readOnlyHint?: boolean; destructiveHint?: boolean; idempotentHint?: boolean; openWorldHint?: boolean; } export type HandlerContext = AnyObjectSchema, TSecrets extends SecretDeclarations | undefined = undefined, TServices extends object = EmptyServices> = TServices & { params: Static; secrets: InferSecrets; fetch: typeof globalThis.fetch; fs: HandlerFs; env: HandlerEnv; diagnostics: RuntimeLogger; progress(message: string): void; }; export interface CommandConfig, TSecrets extends SecretDeclarations | undefined, TResult> { name: string; title?: string; description?: string; annotations?: ToolAnnotations; hidden?: boolean; examples?: CommandExample[]; aliases?: string[]; positional?: string[]; params: TParamsSchema; result?: ObjectSchema; mcpResult?: (result: TResult) => Record; secrets?: TSecrets; scope?: Scope[]; confirm?: boolean; humanInLoop?: HumanInLoopConfig | null; requires?: Requires>; handler: (ctx: HandlerContext) => Promise | TResult; render?: Renderers; } export interface StreamDefinition { event: TEventSchema; bufferSize: number; } export type StreamHandlerContext, TSecrets extends SecretDeclarations | undefined, TServices extends object> = HandlerContext & { signal: AbortSignal; status(event: StreamStatusEvent): void; refreshSecrets(): Promise>; }; export interface StreamCommandConfig, TSecrets extends SecretDeclarations | undefined, TEventSchema extends AnySchema> extends Omit>>, "handler" | "render" | "result" | "mcpResult" | "humanInLoop" | "confirm"> { event: TEventSchema; handler: (ctx: StreamHandlerContext) => AsyncIterable> | Promise>>; render?: Renderers>; } export interface Command = AnyObjectSchema, TSecrets extends SecretDeclarations | undefined = undefined, TResult = unknown> { kind: "command"; name: string; title?: string; description?: string; annotations?: ToolAnnotations; hidden: boolean; examples: CommandExample[]; aliases: string[]; positional: string[]; params: TParamsSchema; result?: ObjectSchema; mcpResult?: (result: TResult) => Record; stream?: StreamDefinition; secrets: SecretDeclarations; scope: Scope[]; confirm: boolean; humanInLoop?: HumanInLoopConfig | null; requires?: Requires; handler: (ctx: HandlerContext) => Promise | TResult; render?: Renderers; } export interface GroupConfig { name: string; description?: string; aliases?: string[]; mcp?: McpServerConfig; scope?: Scope[]; humanInLoop?: HumanInLoopConfig | null; secrets?: SecretDeclarations; tools?: string[]; rename?: Record; requires?: Requires>; children: Array>; default?: Command; } export interface Group { kind: "group"; name: string; description?: string; aliases: string[]; scope?: Scope[]; humanInLoop?: HumanInLoopConfig | null; secrets: SecretDeclarations; requires?: Requires; children: Array>; default?: Command; } export type CommandNode = Command | Group; export interface CommandTypeInfo = AnyObjectSchema, TResult = unknown, TOwnScope extends ScopeInput = ScopeInput, TOwnHumanInLoopMode extends HumanInLoopModeInput = undefined> { name: TName; params: TParamsSchema; result: TResult; ownScope: TOwnScope; ownHumanInLoopMode: TOwnHumanInLoopMode; } export interface GroupTypeInfo[], TOwnScope extends ScopeInput = ScopeInput, TOwnHumanInLoopMode extends HumanInLoopModeInput = undefined> { name: TName; children: TChildren; ownScope: TOwnScope; ownHumanInLoopMode: TOwnHumanInLoopMode; } type TypedCommandMetadata, TResult, TOwnScope extends ScopeInput, TOwnHumanInLoopMode extends HumanInLoopModeInput> = { readonly __agentKitCommandTypeInfo: CommandTypeInfo; }; type TypedGroupMetadata = { readonly __agentKitGroupTypeInfo: GroupTypeInfo; }; export interface CommandRequirementOptions { apiVersion?: string; authEnvVar?: string; env?: Record; } export declare function resolveCommandSecrets(command: Command, env?: Record): Record; export declare function assertCommandRequirements(command: Command, context: GroupCheckContext, options?: CommandRequirementOptions): Promise; export declare function defineCommand = AnyObjectSchema, TSecrets extends SecretDeclarations | undefined = undefined, TResult = unknown, TOwnScope extends ScopeInput = undefined, TOwnHumanInLoop extends HumanInLoopConfig | null | undefined = undefined>(config: Omit, "name" | "scope" | "humanInLoop"> & { name: TName; scope?: TOwnScope; humanInLoop?: TOwnHumanInLoop; }): Command & TypedCommandMetadata>; export declare function defineStreamCommand = AnyObjectSchema, TSecrets extends SecretDeclarations | undefined = undefined, TEventSchema extends AnySchema = AnySchema, TOwnScope extends ScopeInput = undefined>(config: Omit, "name" | "scope"> & { name: TName; scope?: TOwnScope; }): Command>> & TypedCommandMetadata>, TOwnScope, undefined>; export declare function defineGroup[], TOwnScope extends ScopeInput = undefined, TOwnHumanInLoop extends HumanInLoopConfig | null | undefined = undefined>(config: Omit, "name" | "children" | "scope" | "humanInLoop"> & { name: TName; children: TChildren & readonly CommandNode[]; scope?: TOwnScope; humanInLoop?: TOwnHumanInLoop; }): Group & TypedGroupMetadata>; export declare function getCommandSourcePath(command: Command): string | undefined; export declare function hasMcpProxyConfig(group: Group): boolean; export { S, toJsonSchema } from "./schema.js"; export { AuthenticationError, BadRequestError, ClientError, ConflictError, HttpError, InternalServerError, NotFoundError, PermissionDeniedError, RateLimitError, ServerError, ServiceUnavailableError, UnprocessableEntityError, createHttpError } from "./http-errors.js"; export type { HttpErrorRequest, HttpErrorResponse } from "./http-errors.js"; export { ApprovalDeclinedError, ToolcraftBugError, UserError, isUserError }; export { suggest } from "./suggest.js"; export { createRuntimeLogger, isLogLevel, shouldEmitDiagnostic } from "./runtime-logging.js"; export { findPackageMetadata, packageMetadata } from "./package-metadata.js"; export type { PackageMetadata } from "./package-metadata.js"; export type { FileChangeRendererOptions, FileChangeResult } from "./file-change-renderer.js"; export type { FileChange, FileChangeDisplayMode, FileChangeKind } from "toolcraft-design"; export type { DiagnosticLogEvent, LogLevel, RuntimeLogger, RuntimeLoggerInput } from "./runtime-logging.js"; export type { AnySchema, ArraySchema, BooleanSchema, CliMissingParameterChoice, CliMissingParameterContext, CliMissingParameterResolution, CliOutputMode, CliSchemaOptions, EnumSchema, JsonSchema, JsonSchemaDocument, JsonSchemaDocumentOptions, JsonValue, JsonValueSchema, NumberSchema, ObjectSchema, OneOfSchema, OptionalSchema, RecordSchema, SchemaBase, Static, StringSchema, UnionSchema, ValidationIssue, ValidationResult } from "./schema.js"; export type { HumanInLoopConfig, HumanInLoopPending, HumanInLoopRuntime };