import type { McpServerConfig } from "../../agent-mcp-config/dist/index.js";
import type { ObjectSchema, Static } from "../../toolcraft-schema/dist/index.js";
import type { LoggerOutput, RenderTableOptions, ThemePalette } from "../../toolcraft-design/dist/index.js";
import { ApprovalDeclinedError } from "./human-in-loop/types.js";
import type { HumanInLoopConfig, HumanInLoopPending, HumanInLoopRuntimeOptions } from "./human-in-loop/types.js";
import { ToolcraftBugError, UserError } from "./user-error.js";
type ScopeValue = "cli" | "mcp" | "sdk";
type AnyObjectSchema = ObjectSchema<Record<string, never>>;
type EmptyServices = Record<string, never>;
type ScopeInput = readonly Scope[] | undefined;
type HumanInLoopMode = "sync" | "async";
type HumanInLoopModeInput = HumanInLoopMode | null | undefined;
export type Scope = ScopeValue;
type ResolveOwnHumanInLoopMode<TValue> = 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<string, SecretDefinition>;
type OptionalSecretKeys<TSecrets extends SecretDeclarations> = {
    [TKey in keyof TSecrets]: TSecrets[TKey] extends {
        optional: true;
    } ? TKey : never;
}[keyof TSecrets];
type RequiredSecretKeys<TSecrets extends SecretDeclarations> = Exclude<keyof TSecrets, OptionalSecretKeys<TSecrets>>;
export type InferSecrets<TSecrets extends SecretDeclarations | undefined> = TSecrets extends SecretDeclarations ? {
    [TKey in RequiredSecretKeys<TSecrets>]: string;
} & {
    [TKey in OptionalSecretKeys<TSecrets>]?: string;
} : Record<string, never>;
export interface HandlerFs {
    readFile(path: string, encoding?: BufferEncoding): Promise<string>;
    writeFile(path: string, contents: string, options?: {
        encoding?: BufferEncoding;
        flag?: string;
        mode?: number;
    }): Promise<void>;
    exists(path: string): Promise<boolean>;
    lstat(path: string): Promise<{
        isSymbolicLink(): boolean;
    }>;
    rename(fromPath: string, toPath: string): Promise<void>;
    unlink(path: string): Promise<void>;
}
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;
}
export interface CheckResult {
    ok: boolean;
    message?: string;
}
export interface CommandExample {
    title: string;
    params: Record<string, unknown>;
}
export type GroupCheckContext<TServices extends object = EmptyServices> = TServices & {
    params?: unknown;
    secrets?: Record<string, string | undefined>;
    fetch: typeof globalThis.fetch;
    fs: HandlerFs;
    env: HandlerEnv;
    progress(message: string): void;
};
export type CommandCheckContext<TParamsSchema extends ObjectSchema<any> = AnyObjectSchema, TSecrets extends SecretDeclarations | undefined = undefined, TServices extends object = EmptyServices> = TServices & {
    params?: Static<TParamsSchema>;
    secrets?: InferSecrets<TSecrets>;
    fetch: typeof globalThis.fetch;
    fs: HandlerFs;
    env: HandlerEnv;
    progress(message: string): void;
};
export interface Requires<TContext = unknown> {
    auth?: boolean;
    apiVersion?: string;
    check?: (ctx: TContext) => Promise<CheckResult>;
}
export interface Renderers<TResult> {
    rich?: (result: TResult, primitives: RenderPrimitives) => void;
    markdown?: (result: TResult, primitives: RenderPrimitives) => string;
    json?: (result: TResult, primitives: RenderPrimitives) => unknown;
}
export type HandlerContext<TParamsSchema extends ObjectSchema<any> = AnyObjectSchema, TSecrets extends SecretDeclarations | undefined = undefined, TServices extends object = EmptyServices> = TServices & {
    params: Static<TParamsSchema>;
    secrets: InferSecrets<TSecrets>;
    fetch: typeof globalThis.fetch;
    fs: HandlerFs;
    env: HandlerEnv;
    progress(message: string): void;
};
export interface CommandConfig<TServices extends object, TParamsSchema extends ObjectSchema<any>, TSecrets extends SecretDeclarations | undefined, TResult> {
    name: string;
    description?: string;
    hidden?: boolean;
    examples?: CommandExample[];
    aliases?: string[];
    positional?: string[];
    params: TParamsSchema;
    result?: ObjectSchema<any>;
    secrets?: TSecrets;
    scope?: Scope[];
    confirm?: boolean;
    humanInLoop?: HumanInLoopConfig<TParamsSchema> | null;
    requires?: Requires<CommandCheckContext<TParamsSchema, TSecrets, TServices>>;
    handler: (ctx: HandlerContext<TParamsSchema, TSecrets, TServices>) => Promise<TResult>;
    render?: Renderers<TResult>;
}
export interface Command<TServices extends object = EmptyServices, TParamsSchema extends ObjectSchema<any> = AnyObjectSchema, TSecrets extends SecretDeclarations | undefined = undefined, TResult = unknown> {
    kind: "command";
    name: string;
    description?: string;
    hidden: boolean;
    examples: CommandExample[];
    aliases: string[];
    positional: string[];
    params: TParamsSchema;
    result?: ObjectSchema<any>;
    secrets: SecretDeclarations;
    scope: Scope[];
    confirm: boolean;
    humanInLoop?: HumanInLoopConfig<TParamsSchema> | null;
    requires?: Requires<any>;
    handler: (ctx: HandlerContext<TParamsSchema, TSecrets, TServices>) => Promise<TResult>;
    render?: Renderers<TResult>;
}
export interface GroupConfig<TServices extends object> {
    name: string;
    description?: string;
    aliases?: string[];
    mcp?: McpServerConfig;
    scope?: Scope[];
    humanInLoop?: HumanInLoopConfig<AnyObjectSchema> | null;
    secrets?: SecretDeclarations;
    tools?: string[];
    rename?: Record<string, string>;
    requires?: Requires<GroupCheckContext<TServices>>;
    children: Array<CommandNode<TServices>>;
    default?: Command<TServices, any, any, any>;
}
export interface Group<TServices extends object = EmptyServices> {
    kind: "group";
    name: string;
    description?: string;
    aliases: string[];
    scope?: Scope[];
    humanInLoop?: HumanInLoopConfig<AnyObjectSchema> | null;
    secrets: SecretDeclarations;
    requires?: Requires<any>;
    children: Array<CommandNode<TServices>>;
    default?: Command<TServices, any, any, any>;
}
export type CommandNode<TServices extends object = EmptyServices> = Command<TServices, any, any, any> | Group<TServices>;
export interface CommandTypeInfo<TName extends string = string, TParamsSchema extends ObjectSchema<any> = AnyObjectSchema, TResult = unknown, TOwnScope extends ScopeInput = ScopeInput, TOwnHumanInLoopMode extends HumanInLoopModeInput = undefined> {
    name: TName;
    params: TParamsSchema;
    result: TResult;
    ownScope: TOwnScope;
    ownHumanInLoopMode: TOwnHumanInLoopMode;
}
export interface GroupTypeInfo<TServices extends object = EmptyServices, TName extends string = string, TChildren extends readonly unknown[] = readonly CommandNode<TServices>[], TOwnScope extends ScopeInput = ScopeInput, TOwnHumanInLoopMode extends HumanInLoopModeInput = undefined> {
    name: TName;
    children: TChildren;
    ownScope: TOwnScope;
    ownHumanInLoopMode: TOwnHumanInLoopMode;
}
type TypedCommandMetadata<TName extends string, TParamsSchema extends ObjectSchema<any>, TResult, TOwnScope extends ScopeInput, TOwnHumanInLoopMode extends HumanInLoopModeInput> = {
    readonly __agentKitCommandTypeInfo: CommandTypeInfo<TName, TParamsSchema, TResult, TOwnScope, TOwnHumanInLoopMode>;
};
type TypedGroupMetadata<TServices extends object, TName extends string, TChildren extends readonly unknown[], TOwnScope extends ScopeInput, TOwnHumanInLoopMode extends HumanInLoopModeInput> = {
    readonly __agentKitGroupTypeInfo: GroupTypeInfo<TServices, TName, TChildren, TOwnScope, TOwnHumanInLoopMode>;
};
export interface CommandRequirementOptions {
    apiVersion?: string;
    authEnvVar?: string;
    env?: Record<string, string | undefined>;
}
export declare function resolveCommandSecrets(command: Command<any, any, any, any>, env?: Record<string, string | undefined>): Record<string, string | undefined>;
export declare function assertCommandRequirements(command: Command<any, any, any, any>, context: GroupCheckContext<any>, options?: CommandRequirementOptions): Promise<void>;
export declare function defineCommand<TServices extends object = EmptyServices, TName extends string = string, TParamsSchema extends ObjectSchema<any> = AnyObjectSchema, TSecrets extends SecretDeclarations | undefined = undefined, TResult = unknown, TOwnScope extends ScopeInput = undefined, TOwnHumanInLoop extends HumanInLoopConfig<TParamsSchema> | null | undefined = undefined>(config: Omit<CommandConfig<TServices, TParamsSchema, TSecrets, TResult>, "name" | "scope" | "humanInLoop"> & {
    name: TName;
    scope?: TOwnScope;
    humanInLoop?: TOwnHumanInLoop;
}): Command<TServices, TParamsSchema, TSecrets, TResult> & TypedCommandMetadata<TName, TParamsSchema, TResult, TOwnScope, ResolveOwnHumanInLoopMode<TOwnHumanInLoop>>;
export declare function defineGroup<TServices extends object = EmptyServices, TName extends string = string, TChildren extends readonly unknown[] = readonly CommandNode<TServices>[], TOwnScope extends ScopeInput = undefined, TOwnHumanInLoop extends HumanInLoopConfig<AnyObjectSchema> | null | undefined = undefined>(config: Omit<GroupConfig<TServices>, "name" | "children" | "scope" | "humanInLoop"> & {
    name: TName;
    children: TChildren & readonly CommandNode<TServices>[];
    scope?: TOwnScope;
    humanInLoop?: TOwnHumanInLoop;
}): Group<TServices> & TypedGroupMetadata<TServices, TName, TChildren, TOwnScope, ResolveOwnHumanInLoopMode<TOwnHumanInLoop>>;
export declare function getCommandSourcePath(command: Command<any, any, any, any>): string | undefined;
export { S, toJsonSchema } from "../../toolcraft-schema/dist/index.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 };
export { findPackageMetadata, packageMetadata } from "./package-metadata.js";
export type { PackageMetadata } from "./package-metadata.js";
export type { AnySchema, ArraySchema, BooleanSchema, EnumSchema, JsonSchema, NumberSchema, ObjectSchema, OptionalSchema, Static, StringSchema } from "../../toolcraft-schema/dist/index.js";
export type { HumanInLoopConfig, HumanInLoopPending, HumanInLoopRuntimeOptions };
