import { EventEmitter } from "node:events"; import { Account } from "./account.js"; import { Adapter } from "./adapter.js"; import { Dict } from "./types.js"; import { Router } from "./router.js"; import { type EventFilters } from "./event-filter.js"; /** * Base Protocol class * Represents a communication protocol (e.g., OneBot, Milky, Satori) */ export declare abstract class Protocol extends EventEmitter { #private; adapter: Adapter; account: Account; config: Protocol.FullConfig; /** 由 Account 生命周期编排维护,供 readiness 与运维诊断使用。 */ lifecycleStatus: ProtocolLifecycleStatus; abstract readonly name: string; abstract readonly version: V; get app(): import("./base-app.js").BaseApp; get router(): Router; get logger(): import("log4js").Logger; constructor(adapter: Adapter, account: Account, config: Protocol.FullConfig); /** * Get the URL path for this protocol */ get path(): string; /** * Filter function to determine if event should be processed */ filterFn(event: Dict): boolean; /** * Start the protocol service */ /** 启动协议出口;账号启动超时时 signal 会被中止,协议应据此尽快释放未完成工作。 */ abstract start(signal?: AbortSignal): void | Promise; /** * Stop the protocol service */ abstract stop(force?: boolean): void | Promise; /** * Dispatch an event through this protocol */ abstract dispatch(event: unknown): void | Promise; /** * Format event data according to protocol specifications */ abstract format(event: string, payload: unknown): unknown; /** * Apply an action (call an API method) */ abstract apply(action: string, params?: unknown): Promise; } export type ProtocolLifecycleStatus = "pending" | "starting" | "ready" | "stopping" | "stopped" | "failed"; export declare namespace Protocol { /** * Base configuration for protocols */ type Config> = T & { filters?: Filters; }; type FullConfig> = Config & { protocol: string; version: string; }; interface Configs { } /** * Filter configuration */ type Filters = EventFilters; /** 所有协议共享的事件过滤器表单契约。 */ const FilterSchema: { type: "object"; default: {}; label: string; description: string; ui: { widget: "event-filter"; section: "filter"; eventFields: ({ path: string; label: string; choices: { value: string; label: string; }[]; } | { path: string; label: string; choices?: undefined; })[]; }; }; /** * Protocol metadata */ interface Metadata { name: string; displayName: string; description: string; versions: string[]; } type Creator = (adapter: Adapter, account: Account, config: Record) => T; type Construct = { new (adapter: Adapter, account: Account, config: Record): T; }; /** * Protocol factory function */ type Factory = Creator | Construct; function isClassFactory(factory: Factory): factory is Construct; }