|
| 1 | +import type { ImageContent } from "@mariozechner/pi-ai"; |
| 2 | +import type { PromptImageOrderEntry } from "../media/prompt-image-order.js"; |
| 3 | +import type { ReplyPayload } from "./reply-payload.js"; |
| 4 | +import type { TypingController } from "./reply/typing.js"; |
| 5 | + |
| 6 | +export type BlockReplyContext = { |
| 7 | + abortSignal?: AbortSignal; |
| 8 | + timeoutMs?: number; |
| 9 | + /** Source assistant message index from the upstream stream, when available. */ |
| 10 | + assistantMessageIndex?: number; |
| 11 | +}; |
| 12 | + |
| 13 | +/** Context passed to onModelSelected callback with actual model used. */ |
| 14 | +export type ModelSelectedContext = { |
| 15 | + provider: string; |
| 16 | + model: string; |
| 17 | + thinkLevel: string | undefined; |
| 18 | +}; |
| 19 | + |
| 20 | +export type TypingPolicy = |
| 21 | + | "auto" |
| 22 | + | "user_message" |
| 23 | + | "system_event" |
| 24 | + | "internal_webchat" |
| 25 | + | "heartbeat"; |
| 26 | + |
| 27 | +export type ReplyThreadingPolicy = { |
| 28 | + /** Override implicit reply-to-current behavior for the current turn. */ |
| 29 | + implicitCurrentMessage?: "default" | "allow" | "deny"; |
| 30 | +}; |
| 31 | + |
| 32 | +export type GetReplyOptions = { |
| 33 | + /** Override run id for agent events (defaults to random UUID). */ |
| 34 | + runId?: string; |
| 35 | + /** Abort signal for the underlying agent run. */ |
| 36 | + abortSignal?: AbortSignal; |
| 37 | + /** Optional inbound images (used for webchat attachments). */ |
| 38 | + images?: ImageContent[]; |
| 39 | + /** Original inline/offloaded attachment order for inbound images. */ |
| 40 | + imageOrder?: PromptImageOrderEntry[]; |
| 41 | + /** Notifies when an agent run actually starts (useful for webchat command handling). */ |
| 42 | + onAgentRunStart?: (runId: string) => void; |
| 43 | + onReplyStart?: () => Promise<void> | void; |
| 44 | + /** Called when the typing controller cleans up (e.g., run ended with NO_REPLY). */ |
| 45 | + onTypingCleanup?: () => void; |
| 46 | + onTypingController?: (typing: TypingController) => void; |
| 47 | + isHeartbeat?: boolean; |
| 48 | + /** Policy-level typing control for run classes (user/system/internal/heartbeat). */ |
| 49 | + typingPolicy?: TypingPolicy; |
| 50 | + /** Force-disable typing indicators for this run (system/internal/cross-channel routes). */ |
| 51 | + suppressTyping?: boolean; |
| 52 | + /** Resolved heartbeat model override (provider/model string from merged per-agent config). */ |
| 53 | + heartbeatModelOverride?: string; |
| 54 | + /** Controls bootstrap workspace context injection (default: full). */ |
| 55 | + bootstrapContextMode?: "full" | "lightweight"; |
| 56 | + /** If true, suppress tool error warning payloads for this run. */ |
| 57 | + suppressToolErrorWarnings?: boolean; |
| 58 | + onPartialReply?: (payload: ReplyPayload) => Promise<void> | void; |
| 59 | + onReasoningStream?: (payload: ReplyPayload) => Promise<void> | void; |
| 60 | + /** Called when a thinking/reasoning block ends. */ |
| 61 | + onReasoningEnd?: () => Promise<void> | void; |
| 62 | + /** Called when a new assistant message starts (e.g., after tool call or thinking block). */ |
| 63 | + onAssistantMessageStart?: () => Promise<void> | void; |
| 64 | + /** Called synchronously when a block reply is logically emitted, before async |
| 65 | + * delivery drains. Useful for channels that need to rotate preview state at |
| 66 | + * block boundaries without waiting for transport acks. */ |
| 67 | + onBlockReplyQueued?: (payload: ReplyPayload, context?: BlockReplyContext) => Promise<void> | void; |
| 68 | + onBlockReply?: (payload: ReplyPayload, context?: BlockReplyContext) => Promise<void> | void; |
| 69 | + onToolResult?: (payload: ReplyPayload) => Promise<void> | void; |
| 70 | + /** Called when a tool phase starts/updates, before summary payloads are emitted. */ |
| 71 | + onToolStart?: (payload: { name?: string; phase?: string }) => Promise<void> | void; |
| 72 | + /** Called when a concrete work item starts, updates, or completes. */ |
| 73 | + onItemEvent?: (payload: { |
| 74 | + itemId?: string; |
| 75 | + kind?: string; |
| 76 | + title?: string; |
| 77 | + name?: string; |
| 78 | + phase?: string; |
| 79 | + status?: string; |
| 80 | + summary?: string; |
| 81 | + progressText?: string; |
| 82 | + approvalId?: string; |
| 83 | + approvalSlug?: string; |
| 84 | + }) => Promise<void> | void; |
| 85 | + /** Called when the agent emits a structured plan update. */ |
| 86 | + onPlanUpdate?: (payload: { |
| 87 | + phase?: string; |
| 88 | + title?: string; |
| 89 | + explanation?: string; |
| 90 | + steps?: string[]; |
| 91 | + source?: string; |
| 92 | + }) => Promise<void> | void; |
| 93 | + /** Called when an approval becomes pending or resolves. */ |
| 94 | + onApprovalEvent?: (payload: { |
| 95 | + phase?: string; |
| 96 | + kind?: string; |
| 97 | + status?: string; |
| 98 | + title?: string; |
| 99 | + itemId?: string; |
| 100 | + toolCallId?: string; |
| 101 | + approvalId?: string; |
| 102 | + approvalSlug?: string; |
| 103 | + command?: string; |
| 104 | + host?: string; |
| 105 | + reason?: string; |
| 106 | + message?: string; |
| 107 | + }) => Promise<void> | void; |
| 108 | + /** Called when command output streams or completes. */ |
| 109 | + onCommandOutput?: (payload: { |
| 110 | + itemId?: string; |
| 111 | + phase?: string; |
| 112 | + title?: string; |
| 113 | + toolCallId?: string; |
| 114 | + name?: string; |
| 115 | + output?: string; |
| 116 | + status?: string; |
| 117 | + exitCode?: number | null; |
| 118 | + durationMs?: number; |
| 119 | + cwd?: string; |
| 120 | + }) => Promise<void> | void; |
| 121 | + /** Called when a patch completes with a file summary. */ |
| 122 | + onPatchSummary?: (payload: { |
| 123 | + itemId?: string; |
| 124 | + phase?: string; |
| 125 | + title?: string; |
| 126 | + toolCallId?: string; |
| 127 | + name?: string; |
| 128 | + added?: string[]; |
| 129 | + modified?: string[]; |
| 130 | + deleted?: string[]; |
| 131 | + summary?: string; |
| 132 | + }) => Promise<void> | void; |
| 133 | + /** Called when context auto-compaction starts (allows UX feedback during the pause). */ |
| 134 | + onCompactionStart?: () => Promise<void> | void; |
| 135 | + /** Called when context auto-compaction completes. */ |
| 136 | + onCompactionEnd?: () => Promise<void> | void; |
| 137 | + /** Called when the actual model is selected (including after fallback). |
| 138 | + * Use this to get model/provider/thinkLevel for responsePrefix template interpolation. */ |
| 139 | + onModelSelected?: (ctx: ModelSelectedContext) => void; |
| 140 | + disableBlockStreaming?: boolean; |
| 141 | + /** Timeout for block reply delivery (ms). */ |
| 142 | + blockReplyTimeoutMs?: number; |
| 143 | + /** If provided, only load these skills for this session (empty = no skills). */ |
| 144 | + skillFilter?: string[]; |
| 145 | + /** Mutable ref to track if a reply was sent (for Slack "first" threading mode). */ |
| 146 | + hasRepliedRef?: { value: boolean }; |
| 147 | + /** Override agent timeout in seconds (0 = no timeout). Threads through to resolveAgentTimeoutMs. */ |
| 148 | + timeoutOverrideSeconds?: number; |
| 149 | +}; |
0 commit comments