import type { AgentMessage as KoiMessage } from "@mariozechner/pi-agent-core"; import type { Api, AssistantMessage, ImageContent, Model } from "@mariozechner/pi-ai"; import type { ReasoningLevel, ThinkLevel, VerboseLevel } from "../../../auto-reply/thinking.js"; import type { KoiStreamParams } from "../../../commands/koi/types.js"; import type { SKYKOIConfig } from "../../../config/config.js"; import type { SessionSystemPromptReport } from "../../../config/sessions/types.js"; import type { ExecElevatedDefaults, ExecToolDefaults } from "../../bash-tools.js"; import type { MessagingToolSend } from "../../pi-embedded-messaging.js"; import type { BlockReplyChunking, ToolResultFormat } from "../../pi-embedded-subscribe.js"; import type { AuthStorage, ModelRegistry } from "../../pi-model-discovery.js"; import type { SkillSnapshot } from "../../skills.js"; import type { ClientToolDefinition } from "./params.js"; export type EmbeddedRunAttemptParams = { sessionId: string; sessionKey?: string; koiId?: string; messageChannel?: string; messageProvider?: string; koiAccountId?: string; messageTo?: string; messageThreadId?: string | number; /** Group id for channel-level tool policy resolution. */ groupId?: string | null; /** Group channel label (e.g. #general) for channel-level tool policy resolution. */ groupChannel?: string | null; /** Group space label (e.g. guild/team id) for channel-level tool policy resolution. */ groupSpace?: string | null; /** Parent session key for subkoi policy inheritance. */ spawnedBy?: string | null; senderId?: string | null; senderName?: string | null; senderUsername?: string | null; senderE164?: string | null; /** Whether the sender is an owner (required for owner-only tools). */ senderIsOwner?: boolean; currentChannelId?: string; currentThreadTs?: string; replyToMode?: "off" | "first" | "all"; hasRepliedRef?: { value: boolean; }; sessionFile: string; workspaceDir: string; koiDir?: string; config?: SKYKOIConfig; skillsSnapshot?: SkillSnapshot; prompt: string; images?: ImageContent[]; /** Optional client-provided tools (OpenResponses hosted tools). */ clientTools?: ClientToolDefinition[]; /** Disable built-in tools for this run (LLM-only mode). */ disableTools?: boolean; provider: string; modelId: string; model: Model; authStorage: AuthStorage; modelRegistry: ModelRegistry; thinkLevel: ThinkLevel; verboseLevel?: VerboseLevel; reasoningLevel?: ReasoningLevel; toolResultFormat?: ToolResultFormat; execOverrides?: Pick; bashElevated?: ExecElevatedDefaults; timeoutMs: number; runId: string; abortSignal?: AbortSignal; shouldEmitToolResult?: () => boolean; shouldEmitToolOutput?: () => boolean; onPartialReply?: (payload: { text?: string; mediaUrls?: string[]; }) => void | Promise; onAssistantMessageStart?: () => void | Promise; onBlockReply?: (payload: { text?: string; mediaUrls?: string[]; audioAsVoice?: boolean; replyToId?: string; replyToTag?: boolean; replyToCurrent?: boolean; }) => void | Promise; onBlockReplyFlush?: () => void | Promise; blockReplyBreak?: "text_end" | "message_end"; blockReplyChunking?: BlockReplyChunking; onReasoningStream?: (payload: { text?: string; mediaUrls?: string[]; }) => void | Promise; onToolResult?: (payload: { text?: string; mediaUrls?: string[]; }) => void | Promise; onKoiEvent?: (evt: { stream: string; data: Record; }) => void; /** Require explicit message tool targets (no implicit last-route sends). */ requireExplicitMessageTarget?: boolean; /** If true, omit the message tool from the tool list. */ disableMessageTool?: boolean; extraSystemPrompt?: string; streamParams?: KoiStreamParams; ownerNumbers?: string[]; enforceFinalTag?: boolean; }; export type EmbeddedRunAttemptResult = { aborted: boolean; timedOut: boolean; promptError: unknown; sessionIdUsed: string; systemPromptReport?: SessionSystemPromptReport; messagesSnapshot: KoiMessage[]; assistantTexts: string[]; toolMetas: Array<{ toolName: string; meta?: string; }>; lastAssistant: AssistantMessage | undefined; lastToolError?: { toolName: string; meta?: string; error?: string; }; didSendViaMessagingTool: boolean; messagingToolSentTexts: string[]; messagingToolSentTargets: MessagingToolSend[]; cloudCodeAssistFormatError: boolean; /** Client tool call detected (OpenResponses hosted tools). */ clientToolCall?: { name: string; params: Record; }; };