import type { AgentTool } from "@mariozechner/pi-agent-core"; import type { TSchema } from "typebox"; export type AgentRuntimeTransport = "sse" | "websocket" | "auto"; export type AgentRuntimeThinkLevel = "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "adaptive" | "max"; export type AgentRuntimePromptMode = "full" | "minimal" | "none"; export type AgentRuntimePromptTrigger = "cron" | "heartbeat" | "manual" | "memory" | "overflow" | "user"; export type AgentRuntimeFailoverReason = "auth" | "auth_permanent" | "format" | "rate_limit" | "overloaded" | "billing" | "timeout" | "model_not_found" | "session_expired" | "empty_response" | "no_error_details" | "unclassified" | "unknown"; export type AgentRuntimeConfig = unknown; export type AgentRuntimeModel = { id?: string; name?: string; api?: string; provider?: string; baseUrl?: string; reasoning?: boolean; input?: string[]; cost?: { input: number; output: number; cacheRead: number; cacheWrite: number; }; contextWindow?: number; maxTokens?: number; contextTokens?: number; compat?: unknown; }; export type AgentRuntimeInteractiveButtonStyle = "primary" | "secondary" | "success" | "danger"; export type AgentRuntimeInteractiveReplyButton = { label: string; value?: string; url?: string; style?: AgentRuntimeInteractiveButtonStyle; }; export type AgentRuntimeInteractiveReplyOption = { label: string; value: string; }; export type AgentRuntimeInteractiveReplyBlock = { type: "text"; text: string; } | { type: "buttons"; buttons: AgentRuntimeInteractiveReplyButton[]; } | { type: "select"; placeholder?: string; options: AgentRuntimeInteractiveReplyOption[]; }; export type AgentRuntimeInteractiveReply = { blocks: AgentRuntimeInteractiveReplyBlock[]; }; export type AgentRuntimeMessagePresentationTone = "info" | "success" | "warning" | "danger" | "neutral"; export type AgentRuntimeMessagePresentationBlock = { type: "text"; text: string; } | { type: "context"; text: string; } | { type: "divider"; } | { type: "buttons"; buttons: AgentRuntimeInteractiveReplyButton[]; } | { type: "select"; placeholder?: string; options: AgentRuntimeInteractiveReplyOption[]; }; export type AgentRuntimeMessagePresentation = { title?: string; tone?: AgentRuntimeMessagePresentationTone; blocks: AgentRuntimeMessagePresentationBlock[]; }; export type AgentRuntimeReplyPayloadDeliveryPin = { enabled: boolean; notify?: boolean; required?: boolean; }; export type AgentRuntimeReplyPayloadDelivery = { pin?: boolean | AgentRuntimeReplyPayloadDeliveryPin; }; export type AgentRuntimeReplyPayload = { text?: string; mediaUrl?: string; mediaUrls?: string[]; trustedLocalMedia?: boolean; sensitiveMedia?: boolean; presentation?: AgentRuntimeMessagePresentation; delivery?: AgentRuntimeReplyPayloadDelivery; interactive?: AgentRuntimeInteractiveReply; btw?: { question: string; }; replyToId?: string; replyToTag?: boolean; replyToCurrent?: boolean; audioAsVoice?: boolean; spokenText?: string; isError?: boolean; isReasoning?: boolean; isCompactionNotice?: boolean; channelData?: Record; }; export type AgentRuntimeSystemPromptSectionId = "interaction_style" | "tool_call_style" | "execution_bias"; export type AgentRuntimeSystemPromptContribution = { stablePrefix?: string; dynamicSuffix?: string; sectionOverrides?: Partial>; }; export type AgentRuntimeSystemPromptContributionContext = { config?: AgentRuntimeConfig; agentDir?: string; workspaceDir?: string; provider: string; modelId: string; promptMode: AgentRuntimePromptMode; runtimeChannel?: string; runtimeCapabilities?: string[]; agentId?: string; trigger?: AgentRuntimePromptTrigger; }; export type AgentRuntimeFollowupFallbackRouteResult = { route?: "origin" | "dispatcher" | "drop"; reason?: string; }; export type AgentRuntimeToolCallIdMode = "strict" | "strict9"; export type AgentRuntimeTranscriptPolicy = { sanitizeMode: "full" | "images-only"; sanitizeToolCallIds: boolean; toolCallIdMode?: AgentRuntimeToolCallIdMode; preserveNativeAnthropicToolUseIds: boolean; repairToolUseResultPairing: boolean; preserveSignatures: boolean; sanitizeThoughtSignatures?: { allowBase64Only?: boolean; includeCamelCase?: boolean; }; sanitizeThinkingSignatures: boolean; dropThinkingBlocks: boolean; dropReasoningFromHistory?: boolean; applyGoogleTurnOrdering: boolean; validateGeminiTurns: boolean; validateAnthropicTurns: boolean; allowSyntheticToolResults: boolean; }; export type AgentRuntimeOutcomeClassification = { message: string; reason?: AgentRuntimeFailoverReason; status?: number; code?: string; rawError?: string; } | { error: unknown; } | null | undefined; export type AgentRuntimeOutcomeClassifier = (params: { provider: string; model: string; result: unknown; hasDirectlySentBlockReply?: boolean; hasBlockReplyPipelineOutput?: boolean; }) => AgentRuntimeOutcomeClassification; export type AgentRuntimeResolvedRef = { provider: string; modelId: string; modelApi?: string; harnessId?: string; transport?: AgentRuntimeTransport; }; export type AgentRuntimeAuthPlan = { providerForAuth: string; authProfileProviderForAuth: string; harnessAuthProvider?: string; forwardedAuthProfileId?: string; }; export type AgentRuntimePromptPlan = { provider: string; modelId: string; resolveSystemPromptContribution(context: AgentRuntimeSystemPromptContributionContext): AgentRuntimeSystemPromptContribution | undefined; }; export type AgentRuntimeToolPlan = { normalize(tools: AgentTool[], params?: { workspaceDir?: string; modelApi?: string; model?: AgentRuntimeModel; }): AgentTool[]; logDiagnostics(tools: AgentTool[], params?: { workspaceDir?: string; modelApi?: string; model?: AgentRuntimeModel; }): void; }; export type AgentRuntimeDeliveryPlan = { isSilentPayload(payload: Pick): boolean; resolveFollowupRoute(params: { payload: AgentRuntimeReplyPayload; originatingChannel?: string; originatingTo?: string; originRoutable: boolean; dispatcherAvailable: boolean; }): AgentRuntimeFollowupFallbackRouteResult | undefined; }; export type AgentRuntimeOutcomePlan = { classifyRunResult: AgentRuntimeOutcomeClassifier; }; export type AgentRuntimeTransportPlan = { extraParams: Record; resolveExtraParams(params?: { extraParamsOverride?: Record; thinkingLevel?: AgentRuntimeThinkLevel; agentId?: string; workspaceDir?: string; model?: AgentRuntimeModel; resolvedTransport?: AgentRuntimeTransport; }): Record; }; export type AgentRuntimePlan = { resolvedRef: AgentRuntimeResolvedRef; auth: AgentRuntimeAuthPlan; prompt: AgentRuntimePromptPlan; tools: AgentRuntimeToolPlan; transcript: { policy: AgentRuntimeTranscriptPolicy; resolvePolicy(params?: { workspaceDir?: string; modelApi?: string; model?: AgentRuntimeModel; }): AgentRuntimeTranscriptPolicy; }; delivery: AgentRuntimeDeliveryPlan; outcome: AgentRuntimeOutcomePlan; transport: AgentRuntimeTransportPlan; observability: { resolvedRef: string; provider: string; modelId: string; modelApi?: string; harnessId?: string; authProfileId?: string; transport?: AgentRuntimeTransport; }; }; export type BuildAgentRuntimeDeliveryPlanParams = { config?: AgentRuntimeConfig; workspaceDir?: string; agentDir?: string; provider: string; modelId: string; }; export type BuildAgentRuntimePlanParams = { config?: AgentRuntimeConfig; workspaceDir?: string; agentDir?: string; provider: string; modelId: string; model?: AgentRuntimeModel; modelApi?: string | null; harnessId?: string; harnessRuntime?: string; allowHarnessAuthProfileForwarding?: boolean; authProfileProvider?: string; sessionAuthProfileId?: string; agentId?: string; thinkingLevel?: AgentRuntimeThinkLevel; extraParamsOverride?: Record; resolvedTransport?: AgentRuntimeTransport; };