import type { ReplyPayload } from "../../auto-reply/reply-payload.js"; import type { ReplyToMode } from "../../config/types.js"; import type { OpenClawConfig } from "../../config/types.openclaw.js"; import type { OutboundSendDeps } from "../../infra/outbound/send-deps.js"; import type { OutboundMediaAccess } from "../../media/load-options.js"; import type { PollInput } from "../../polls.js"; export type MessageDurabilityPolicy = "required" | "best_effort" | "disabled"; export declare const durableFinalDeliveryCapabilities: readonly ["text", "media", "poll", "payload", "silent", "replyTo", "thread", "nativeQuote", "messageSendingHooks", "batch", "reconcileUnknownSend", "afterSendSuccess", "afterCommit"]; export type DurableFinalDeliveryCapability = (typeof durableFinalDeliveryCapabilities)[number]; export type DurableFinalDeliveryRequirementMap = Partial>; export type DurableFinalDeliveryPayloadShape = { text?: string | null; replyToId?: string | null; mediaUrl?: string | null; mediaUrls?: readonly (string | null | undefined)[] | null; }; export type MessageReceiptSourceResult = { channel?: string; messageId?: string; chatId?: string; channelId?: string; roomId?: string; conversationId?: string; toJid?: string; pollId?: string; timestamp?: number; meta?: Record; }; export type MessageReceiptPartKind = "text" | "media" | "voice" | "poll" | "card" | "preview" | "unknown"; export type MessageReceiptPart = { platformMessageId: string; kind: MessageReceiptPartKind; index: number; threadId?: string; replyToId?: string; raw?: MessageReceiptSourceResult; }; export type MessageReceipt = { primaryPlatformMessageId?: string; platformMessageIds: string[]; parts: MessageReceiptPart[]; threadId?: string; replyToId?: string; editToken?: string; deleteToken?: string; sentAt: number; raw?: readonly MessageReceiptSourceResult[]; }; export type RenderedMessageBatchPlanKind = "text" | "media" | "voice" | "presentation" | "interactive" | "channelData" | "empty"; export type RenderedMessageBatchPlanItem = { index: number; kinds: readonly RenderedMessageBatchPlanKind[]; text?: string; mediaUrls: readonly string[]; audioAsVoice?: boolean; presentationBlockCount?: number; hasInteractive?: boolean; hasChannelData?: boolean; }; export type RenderedMessageBatchPlan = { payloadCount: number; textCount: number; mediaCount: number; voiceCount: number; presentationCount: number; interactiveCount: number; channelDataCount: number; items: readonly RenderedMessageBatchPlanItem[]; }; export type RenderedMessageBatch = { payloads: TPayload[]; plan: RenderedMessageBatchPlan; }; export type LiveMessagePhase = "idle" | "previewing" | "finalizing" | "finalized" | "cancelled"; export type LiveMessageState = { phase: LiveMessagePhase; canFinalizeInPlace: boolean; receipt?: MessageReceipt; lastRendered?: RenderedMessageBatch; }; export type MessageSendContext = { id: string; channel: string; to: string; accountId?: string; durability: Exclude; attempt: number; signal: AbortSignal; intent?: DurableMessageSendIntent; previousReceipt?: MessageReceipt; preview?: LiveMessageState; render(): Promise>; previewUpdate(rendered: RenderedMessageBatch): Promise>; send(rendered: RenderedMessageBatch): Promise; edit(receipt: MessageReceipt, rendered: RenderedMessageBatch): Promise; delete(receipt: MessageReceipt): Promise; commit(receipt: MessageReceipt): Promise; fail(error: unknown): Promise; }; export type ChannelMessageSendTextContext = { cfg: TConfig; to: string; text: string; accountId?: string | null; deps?: OutboundSendDeps; replyToId?: string | null; replyToIdSource?: "explicit" | "implicit"; replyToMode?: ReplyToMode; threadId?: string | number | null; silent?: boolean; signal?: AbortSignal; gatewayClientScopes?: readonly string[]; }; export type ChannelMessageSendMediaContext = ChannelMessageSendTextContext & { mediaUrl: string; mediaAccess?: OutboundMediaAccess; mediaLocalRoots?: readonly string[]; mediaReadFile?: (filePath: string) => Promise; audioAsVoice?: boolean; gifPlayback?: boolean; forceDocument?: boolean; }; export type ChannelMessageSendPayloadContext = ChannelMessageSendTextContext & { payload: ReplyPayload; mediaUrl?: string; mediaAccess?: OutboundMediaAccess; mediaLocalRoots?: readonly string[]; mediaReadFile?: (filePath: string) => Promise; audioAsVoice?: boolean; gifPlayback?: boolean; forceDocument?: boolean; }; export type ChannelMessageSendPollContext = Omit, "text" | "threadId"> & { poll: PollInput; threadId?: string | null; isAnonymous?: boolean; }; export type ChannelMessageSendResult = { receipt: MessageReceipt; messageId?: string; }; export type ChannelMessageSendAttemptKind = "text" | "media" | "payload" | "poll"; export type ChannelMessageSendAttemptContext = (ChannelMessageSendTextContext & { kind: "text"; }) | (ChannelMessageSendMediaContext & { kind: "media"; }) | (ChannelMessageSendPayloadContext & { kind: "payload"; }) | (ChannelMessageSendPollContext & { kind: "poll"; }); export type ChannelMessageSendSuccessContext = ChannelMessageSendAttemptContext & { result: TSendResult; attemptToken?: unknown; }; export type ChannelMessageSendFailureContext = ChannelMessageSendAttemptContext & { error: unknown; attemptToken?: unknown; }; export type ChannelMessageSendCommitContext = ChannelMessageSendSuccessContext; export type ChannelMessageUnknownSendContext = { cfg: TConfig; queueId: string; channel: string; to: string; accountId?: string | null; enqueuedAt: number; retryCount: number; platformSendStartedAt?: number; payloads: readonly ReplyPayload[]; renderedBatchPlan?: RenderedMessageBatchPlan; replyToId?: string | null; replyToMode?: ReplyToMode; threadId?: string | number | null; silent?: boolean; }; export type ChannelMessageUnknownSendReconciliationResult = { status: "sent"; receipt: MessageReceipt; messageId?: string; } | { status: "not_sent"; } | { status: "unresolved"; error?: string; retryable?: boolean; }; export type ChannelMessageSendLifecycleAdapter = { beforeSendAttempt?: (ctx: ChannelMessageSendAttemptContext) => unknown; afterSendSuccess?: (ctx: ChannelMessageSendSuccessContext) => Promise | void; afterSendFailure?: (ctx: ChannelMessageSendFailureContext) => Promise | void; afterCommit?: (ctx: ChannelMessageSendCommitContext) => Promise | void; }; export type ChannelMessageSendAdapter = { text?: (ctx: ChannelMessageSendTextContext) => Promise; media?: (ctx: ChannelMessageSendMediaContext) => Promise; payload?: (ctx: ChannelMessageSendPayloadContext) => Promise; poll?: (ctx: ChannelMessageSendPollContext) => Promise; lifecycle?: ChannelMessageSendLifecycleAdapter; }; export type ChannelMessageDurableFinalAdapter = { capabilities?: DurableFinalDeliveryRequirementMap; reconcileUnknownSend?: (ctx: ChannelMessageUnknownSendContext) => Promise | ChannelMessageUnknownSendReconciliationResult | null; }; export type ChannelMessageLiveCapability = "draftPreview" | "previewFinalization" | "progressUpdates" | "nativeStreaming" | "quietFinalization"; export declare const channelMessageLiveCapabilities: readonly ["draftPreview", "previewFinalization", "progressUpdates", "nativeStreaming", "quietFinalization"]; export declare const livePreviewFinalizerCapabilities: readonly ["finalEdit", "normalFallback", "discardPending", "previewReceipt", "retainOnAmbiguousFailure"]; export type LivePreviewFinalizerCapability = (typeof livePreviewFinalizerCapabilities)[number]; export type LivePreviewFinalizerCapabilityMap = Partial>; export type ChannelMessageLiveFinalizerAdapterShape = { capabilities?: LivePreviewFinalizerCapabilityMap; }; export type ChannelMessageLiveAdapterShape = { capabilities?: Partial>; finalizer?: ChannelMessageLiveFinalizerAdapterShape; }; export type ChannelMessageReceiveAckPolicy = "after_receive_record" | "after_agent_dispatch" | "after_durable_send" | "manual"; export declare const channelMessageReceiveAckPolicies: readonly ["after_receive_record", "after_agent_dispatch", "after_durable_send", "manual"]; export type ChannelMessageReceiveAdapterShape = { defaultAckPolicy?: ChannelMessageReceiveAckPolicy; supportedAckPolicies?: readonly ChannelMessageReceiveAckPolicy[]; }; export type ChannelMessageAdapterShape = { id?: string; durableFinal?: ChannelMessageDurableFinalAdapter; send?: ChannelMessageSendAdapter; live?: ChannelMessageLiveAdapterShape; receive?: ChannelMessageReceiveAdapterShape; }; export type ChannelMessageAdapter = TAdapter; export type DurableFinalRequirementExtras = DurableFinalDeliveryRequirementMap; export type DeriveDurableFinalDeliveryRequirementsParams = { payload: DurableFinalDeliveryPayloadShape; replyToId?: string | null; threadId?: string | number | null; silent?: boolean; messageSendingHooks?: boolean; payloadTransport?: boolean; batch?: boolean; reconcileUnknownSend?: boolean; afterSendSuccess?: boolean; afterCommit?: boolean; extraCapabilities?: DurableFinalRequirementExtras; }; export type DurableMessageSendIntent = { id: string; channel: string; to: string; accountId?: string; durability: Exclude; renderedBatch?: RenderedMessageBatch; };