import { z } from 'zod';

type ToolCredentialScope = "business" | "personal" | "public";
interface ToolLogger {
    info: (msg: string, meta?: Record<string, unknown>) => void;
    warn: (msg: string, meta?: Record<string, unknown>) => void;
    error: (msg: string, meta?: Record<string, unknown>) => void;
}
interface ToolInvocationStartArgs {
    agentId: string;
    sessionId: string;
    toolName: string;
    input: unknown;
}
interface ToolInvocationSuccessArgs {
    agentId: string;
    sessionId: string;
    toolName: string;
    durationMs: number;
}
interface ToolInvocationErrorArgs {
    agentId: string;
    sessionId: string;
    toolName: string;
    durationMs: number;
    error: Record<string, unknown>;
}
/**
 * Thin abstraction over the AgentMemory write path. Consumers wire this
 * up — typically by wrapping the `writeEpisode` helper from
 * `@sentinel-ai-solutions/agent-kit/memory`, but any implementation works (a no-op
 * for tests, a custom telemetry sink, etc).
 */
interface AgentMemoryWriter {
    toolInvocationStart(args: ToolInvocationStartArgs): Promise<void> | void;
    toolInvocationSuccess(args: ToolInvocationSuccessArgs): Promise<void> | void;
    toolInvocationError(args: ToolInvocationErrorArgs): Promise<void> | void;
}
interface ToolDispatchContext {
    /** The agent invoking this tool (e.g. 'archer', 'franki'). */
    agentId: string;
    /** Scope this agent operates at — must match tool.scope (or tool.scope === 'public'). */
    agentScope: ToolCredentialScope;
    /** Conversation/session id for telemetry linking. */
    sessionId: string;
    /** Optional user id for personal-scope tools. */
    userId?: string;
    /** Hook to write AgentMemory EPISODE records. */
    memory: AgentMemoryWriter;
    /** Structured logger. */
    log: ToolLogger;
}
interface ToolDefinition<TInput = unknown, TOutput = unknown> {
    /** Tool name as Claude will reference it. Must be unique within an agent's tool registry. */
    name: string;
    /** Human-readable description Claude sees when deciding to call this tool. */
    description: string;
    /** Zod schema for validating input from Claude before invoking the handler. */
    inputSchema: z.ZodType<TInput>;
    /** Credential scope this tool needs. Dispatcher refuses to register if mismatched. */
    scope: ToolCredentialScope;
    /** The actual implementation. Receives validated input + dispatch context. */
    handler: (input: TInput, ctx: ToolDispatchContext) => Promise<TOutput> | TOutput;
}
interface AnthropicToolDefinition {
    name: string;
    description: string;
    input_schema: Record<string, unknown>;
}
interface AnthropicTextBlock {
    type: "text";
    text: string;
}
interface AnthropicToolUseBlock {
    type: "tool_use";
    id: string;
    name: string;
    input: unknown;
}
interface AnthropicToolResultBlock {
    type: "tool_result";
    tool_use_id: string;
    content: string;
    is_error?: boolean;
}
type AnthropicContentBlock = AnthropicTextBlock | AnthropicToolUseBlock | AnthropicToolResultBlock;
interface AnthropicMessage {
    role: "user" | "assistant";
    content: string | AnthropicContentBlock[];
}
type AnthropicStopReason = "end_turn" | "tool_use" | "max_tokens" | "stop_sequence" | (string & {});
interface AnthropicResponse {
    id: string;
    role: "assistant";
    content: AnthropicContentBlock[];
    stop_reason: AnthropicStopReason;
    usage?: Record<string, unknown>;
}
interface AnthropicMessagesCreateArgs {
    model: string;
    max_tokens: number;
    system?: string;
    messages: AnthropicMessage[];
    tools?: AnthropicToolDefinition[];
}
/**
 * Structural type for the subset of the Anthropic SDK that runWithTools
 * actually uses. A real `Anthropic` instance from `@anthropic-ai/sdk`
 * satisfies this — but mocks for testing satisfy it just as well.
 */
interface AnthropicMessagesClient {
    messages: {
        create(args: AnthropicMessagesCreateArgs): Promise<AnthropicResponse>;
    };
}

export type { AgentMemoryWriter as A, ToolCredentialScope as T, AnthropicContentBlock as a, AnthropicMessage as b, AnthropicMessagesClient as c, AnthropicMessagesCreateArgs as d, AnthropicResponse as e, AnthropicStopReason as f, AnthropicTextBlock as g, AnthropicToolDefinition as h, AnthropicToolResultBlock as i, AnthropicToolUseBlock as j, ToolDefinition as k, ToolDispatchContext as l, ToolInvocationErrorArgs as m, ToolInvocationStartArgs as n, ToolInvocationSuccessArgs as o, ToolLogger as p };
