import type { AgentEvent, AgentMessage, AgentToolResult, ThinkingLevel } from '@earendil-works/pi-agent-core'; import type { AssistantMessageEvent, Model, Api, ImageContent } from '@earendil-works/pi-ai'; import type { TurnOutcome } from '@xopcai/gateway-contract'; import type { SessionStore } from '../../session/store.js'; import type { EmbeddedTranscriptRuntime } from './transcript-runtime.js'; import type { AgentTurnPolicy } from '../orchestration/agent-turn-policy.js'; export type EmbeddedStreamEvent = { type: 'agent_start'; runId?: string; } | { type: 'agent_end'; runId?: string; aborted?: boolean; } | { type: 'message_start'; runId?: string; message: AgentMessage; } | { type: 'message_update'; runId?: string; message: AgentMessage; assistantMessageEvent?: AssistantMessageEvent; } | { type: 'message_end'; runId?: string; message: AgentMessage; } | { type: 'tool_execution_start'; runId?: string; toolCallId: string; parentToolCallId?: string; toolName: string; args: unknown; } | { type: 'tool_execution_update'; parentToolCallId?: string; runId?: string; toolCallId: string; toolName: string; args: unknown; partialResult: AgentToolResult; } | { type: 'tool_execution_end'; parentToolCallId?: string; runId?: string; toolCallId: string; toolName: string; result: AgentToolResult; isError: boolean; durationMs?: number; } | { type: 'progress'; runId?: string; stage: string; message: string; completed?: number; total?: number; } | { type: 'error'; runId?: string; content: string; } | { type: 'turn_outcome'; runId?: string; outcome: TurnOutcome; } | { type: 'compaction'; runId?: string; status: 'started' | 'completed' | 'skipped'; tokensBefore?: number; tokensAfter?: number; summary?: string; }; export type RunXopcEmbeddedTurnParams = { conversationId: string; /** Host-owned parent identity for ephemeral runs that inherit its tools. */ toolPolicyConversationId?: string; runId: string; gatewayRunStartedMonotonic?: number; preparationTimings?: Record; userMessage: AgentMessage; model: Model; modelRef: string; tools: import('@earendil-works/pi-agent-core').AgentTool[]; systemPrompt: string; thinkingLevel?: ThinkingLevel; compactionPolicy?: import('../memory/compaction-policy.js').ResolvedCompactionPolicy; promptCachePolicy?: import('../../providers/prompt-cache-plan.js').PromptCachePolicy; codemode?: import('./codemode-extension.js').CodemodePolicy; mcp?: import('@earendil-works/pi-coding-agent').LoadedMcpConfig; workspaceDir: string; /** Host-owned temporary trust; persisted project decisions always take precedence. */ isWorkspaceTrusted?: (workspaceDir: string) => boolean | null | undefined; sessionStore?: SessionStore; transcriptRuntime?: EmbeddedTranscriptRuntime; timeoutMs: number; /** One bounded deadline extension for an already-dispatched budget handoff. */ timeoutExtensionMs?: () => number; turnPolicy?: AgentTurnPolicy; abortSignal?: AbortSignal; onEvent?: (event: EmbeddedStreamEvent) => void; onAgentEvent?: (event: AgentEvent) => void; /** Synchronizes post-turn transcript messages back to the host session holder. */ onTurnMessagesSynced?: (messages: AgentMessage[]) => void; images?: ImageContent[]; /** Continue from the persisted trailing user row instead of appending it again. */ resumeLastUserMessage?: boolean; recoveryMessage?: string; recoveryReason?: string; verifyChanges?: boolean; requireVisibleReply?: boolean; }; export type RunXopcEmbeddedTurnResult = { terminationReason?: import('../orchestration/run-termination.js').AgentTerminationReason; ok: boolean; stopReason?: 'browser_assistance_required' | 'connection_required' | 'clarification_required' | 'secret_request_required' | 'policy_limit' | 'response_truncated'; /** False for harness failures that must not trigger another model attempt. */ retryable?: boolean; errorMessage?: string; lastAssistantText?: string; };