import type { AgentMessage } from "@mariozechner/pi-agent-core";
import type { Api, AssistantMessage, Model } from "@mariozechner/pi-ai";
import type { createAgentSession } from "@mariozechner/pi-coding-agent";
import type { ThinkLevel } from "../../../auto-reply/thinking.js";
import type { SessionSystemPromptReport } from "../../../config/sessions/types.js";
import type { KnowledgeGraphSession } from "../../../memory/knowledge-graph.js";
import type { AnthropicPayloadLogger } from "../../api-infra/anthropic-payload-log.js";
import type { CacheTrace } from "../../api-infra/cache-trace.js";
import type { TranscriptPolicy } from "../../bootstrap/transcript-policy.js";
import type { AuthStorage, ModelRegistry } from "../../models/pi-model-discovery.js";
import type { MessagingToolSend } from "../../pi-embedded/pi-embedded-messaging.js";
import type { AnyAgentTool } from "../../pi-tools/pi-tools.types.js";
import type { SandboxContext } from "../../sandbox.js";
import type { GuardedSessionManager } from "../../sessions/session-tool-result-guard-wrapper.js";
import type { NormalizedUsage } from "../../sessions/usage.js";
import type { RunEmbeddedPiAgentParams } from "./params.js";
type EmbeddedRunAttemptBase = Omit<RunEmbeddedPiAgentParams, "provider" | "model" | "authProfileId" | "authProfileIdSource" | "thinkLevel" | "lane" | "enqueue">;
export type EmbeddedRunAttemptParams = EmbeddedRunAttemptBase & {
    provider: string;
    modelId: string;
    model: Model<Api>;
    authStorage: AuthStorage;
    modelRegistry: ModelRegistry;
    thinkLevel: ThinkLevel;
};
/**
 * Output of the environment resolution phase: skills, tools, system prompt,
 * channel capabilities, sandbox info, etc.
 */
export type ResolvedRunEnvironment = {
    effectiveWorkspace: string;
    sandbox: SandboxContext | null;
    tools: AnyAgentTool[];
    skillEnvOverrides: Record<string, string>;
    systemPromptText: string;
    systemPromptReport: SessionSystemPromptReport;
    effectiveThinkLevel: ThinkLevel;
    sessionAgentId: string;
    defaultAgentId: string;
    kgSession: KnowledgeGraphSession | undefined;
    agentDir: string;
};
/**
 * Output of the session creation phase: lock, session manager, SDK agent session,
 * transcript policy, diagnostics, client tool state.
 */
export type RunSessionContext = {
    sessionLock: {
        release: () => Promise<void>;
    };
    sessionManager: GuardedSessionManager;
    session: Awaited<ReturnType<typeof createAgentSession>>["session"];
    transcriptPolicy: TranscriptPolicy;
    cacheTrace: CacheTrace | null;
    anthropicPayloadLogger: AnthropicPayloadLogger | null;
    clientToolCallRef: {
        value: {
            name: string;
            params: Record<string, unknown>;
        } | null;
    };
};
export type EmbeddedRunAttemptResult = {
    aborted: boolean;
    timedOut: boolean;
    /** True if the timeout occurred while compaction was in progress or pending. */
    timedOutDuringCompaction: boolean;
    promptError: unknown;
    sessionIdUsed: string;
    systemPromptReport?: SessionSystemPromptReport;
    messagesSnapshot: AgentMessage[];
    assistantTexts: string[];
    toolMetas: Array<{
        toolName: string;
        meta?: string;
    }>;
    lastAssistant: AssistantMessage | undefined;
    lastToolError?: {
        toolName: string;
        meta?: string;
        error?: string;
        mutatingAction?: boolean;
        actionFingerprint?: string;
    };
    didSendViaMessagingTool: boolean;
    messagingToolSentTexts: string[];
    messagingToolSentMediaUrls: string[];
    messagingToolSentTargets: MessagingToolSend[];
    successfulCronAdds?: number;
    cloudCodeAssistFormatError: boolean;
    attemptUsage?: NormalizedUsage;
    compactionCount?: number;
    /** Client tool call detected (OpenResponses hosted tools). */
    clientToolCall?: {
        name: string;
        params: Record<string, unknown>;
    };
};
export {};
