import type Database from "better-sqlite3"; import type { InboundTerminalStatus, OutboundKind, OutboundRequest } from "./types.js"; export type InboundStatus = "pending" | "dispatching" | "queued" | "processing" | "completed" | "failed" | "stopped" | "discarded" | "interrupted"; export type OutboundStatus = "pending" | "sending" | "sent" | "failed" | "unknown"; export type InboundRow = { id: number; botId: string; platform: string; platformMsgId: string; payloadJson: string; status: InboundStatus; messageId?: number; runId?: string; claimToken?: string; attemptCount: number; error?: string; }; export type OutboundRow = { id: number; requestId: string; botId: string; platform: string; kind: OutboundKind; chatId?: string; payloadJson: string; status: OutboundStatus; attemptCount: number; platformMsgId?: string; error?: string; }; export type InsertInboundResult = { inserted: boolean; row: InboundRow; }; export type TransportStatusCounts = { inbox: Record; outbox: Record; }; /** 首次发送 + 确认失败后再试一次。 */ export declare const OUTBOUND_MAX_SEND_ATTEMPTS = 2; export declare class TransportStore { private readonly db; private readonly botId; private readonly platform; constructor(db: Database.Database, botId: string, platform: string); insertInbound(platformMsgId: string, payloadJson: string): InsertInboundResult; getInbound(id: number): InboundRow | undefined; getInboundByPlatformMessageId(platformMsgId: string): InboundRow | undefined; claimInbound(id: number, claimToken: string): InboundRow | undefined; releaseInboundClaim(id: number, claimToken: string, error: unknown): InboundRow | undefined; markInboundQueued(id: number, claimToken: string, messageId: number): boolean; markInboundProcessing(id: number, claimToken: string, messageId: number): boolean; markInboundTerminal(id: number, claimToken: string, status: InboundTerminalStatus, error?: unknown): boolean; markInboundRunState(messageIds: number[], runId: string, stage: string, error?: unknown): number; discardInboundMessages(messageIds: number[]): number; prepareInboundRecovery(): { pending: InboundRow[]; interrupted: number; requeued: number; }; insertOutbound(requestId: string, request: OutboundRequest, payloadJson: string): OutboundRow; getOutbound(requestId: string): OutboundRow | undefined; markOutboundSending(requestId: string): boolean; markOutboundSent(requestId: string, platformMsgId?: string): boolean; markOutboundFailed(requestId: string, error: unknown): boolean; markOutboundUnknown(requestId: string, error: unknown): boolean; /** 发送失败后回到 pending,再试一次。超时当时先标 unknown,等确认失败后再走这里。 */ requeueOutbound(requestId: string): boolean; prepareOutboundRecovery(): { pending: OutboundRow[]; unknown: number; }; getExpiredUnknownFileRequests(cutoff: Date): OutboundRow[]; getStatusCounts(): TransportStatusCounts; }