/** * 类型定义 */ /** 媒体附件 */ export interface MediaItem { /** URL 或 base64 data URI (data:image/png;base64,...) */ url: string; /** 文件名(可选) */ name?: string; } /** 聊天请求 */ export interface ChatRequest { session?: string; message: string; from?: string; agentId?: string; messageId?: string; chatType?: "direct" | "group"; /** 会话级模型路由 provider(可选) */ provider?: string; /** 会话级模型 ID(可选) */ model?: string; /** 会话级模型 API 类型(可选) */ apiType?: "openai-responses" | "chat.completions" | "anthropic-messages" | "ollama"; /** 会话级模型 baseUrl(可选) */ baseUrl?: string; /** 会话级采样参数(可选) */ temperature?: number; topP?: number; /** 会话级 maxTokens(可选) */ maxTokens?: number; /** 会话级上下文条数(可选) */ maxContextMessages?: number; /** 会话级 system prompt(可选) */ systemPrompt?: string; /** 请求方期望是否流式(可选) */ stream?: boolean; /** 可选:关联的 Team Run ID(用于插件向平台回传执行事件) */ teamRunId?: string; /** 可选:关联的 Team Run Task ID(用于插件向平台回传执行事件) */ teamTaskId?: string; /** 图片列表(URL 或 base64 data URI) */ images?: string[]; /** 语音(base64 data URI 或 URL,支持 mp3/wav/ogg/webm) */ audio?: string; /** 文件列表 */ files?: MediaItem[]; } /** 聊天响应 */ export interface ChatResponse { ok: boolean; reply?: string; session: string; error?: string; deduplicated?: boolean; /** AI 回复中包含的媒体 URL 列表 */ mediaUrls?: string[]; /** 超长回复的分块列表(围栏感知分块) */ replyParts?: string[]; /** 命令名(当消息为 /command 时) */ command?: string; } /** SSE 事件数据 */ export interface SSEChunkData { text: string; session: string; } export interface SSEDoneData { session: string; fullText: string; mediaUrls?: string[]; } export interface SSEErrorData { error: string; session: string; } export interface SSETypingData { session: string; status: "thinking" | "generating"; } /** Deliver 回调 payload */ export interface DeliverPayload { text?: string; mediaUrl?: string; [key: string]: unknown; } /** Deliver 回调 info */ export interface DeliverInfo { final?: boolean; [key: string]: unknown; } /** OpenClaw 配置对象 */ export interface ChannelConfig { channels?: Record>; [key: string]: unknown; } /** OpenClaw RuntimeEnv 的最小兼容形态 */ export type RuntimeEnvLike = Record; /** 账号运行时快照(供 gateway/status 使用) */ export interface ChannelAccountSnapshot { accountId?: string; name?: string; enabled?: boolean; configured?: boolean; running?: boolean; connected?: boolean; lastStartAt?: number | null; lastStopAt?: number | null; lastInboundAt?: number | null; lastOutboundAt?: number | null; lastError?: string | null; mode?: string; [key: string]: unknown; } /** Gateway context */ export interface GatewayContext { accountId: string; account: HttpApiAccount; cfg: ChannelConfig; runtime: PluginRuntime; abortSignal: AbortSignal; log: Logger; getStatus: () => ChannelAccountSnapshot; setStatus: (status: ChannelAccountSnapshot) => void; channelRuntime?: PluginRuntime["channel"]; } /** Logger interface */ export interface Logger { info: (...args: unknown[]) => void; warn: (...args: unknown[]) => void; error: (...args: unknown[]) => void; } /** 会话信息 */ export interface SessionInfo { session: string; accountId: string; chatType: "direct" | "group"; from: string; participants?: string[]; lastMessageAt: number; messageCount: number; createdAt: number; } /** 文件上传响应 */ export interface UploadResponse { ok: boolean; id?: string; url?: string; contentType?: string; error?: string; } /** 聊天命令 */ export interface ChatCommand { name: string; args: string; originalMessage: string; } /** HTTP API 账号配置 */ export interface HttpApiAccount { accountId: string; name?: string; enabled: boolean; port: number; clientId: string; clientSecret: string; clientSecretFile?: string; rateLimitWindowMs?: number; rateLimitMax?: number; rateLimitBurst?: number; dedupTtlMs?: number; allowFrom?: string[]; webhookUrl?: string; allowOrigins?: string[]; /** 对外公开访问地址(用于回填媒体绝对 URL),例如 https://xiaozhu.example.com */ publicBaseUrl?: string; /** SSE 合并参数 */ coalesce?: { sizeThreshold?: number; idleTimeoutMs?: number; }; /** Per-IP 速率限制 */ perIpRateLimit?: { windowMs?: number; max?: number; }; /** Webhook HMAC 签名密钥 */ webhookSecret?: string; /** Webhook Authorization Bearer token(可选) */ webhookAuthToken?: string; /** OAuth2 access_token TTL(秒) */ accessTokenTtlSec?: number; /** Webhook 重试配置 */ webhookRetry?: { maxAttempts?: number; baseDelayMs?: number; }; /** SSE 心跳间隔(毫秒),0 禁用 */ heartbeatIntervalMs?: number; /** 同步响应文本分块上限 */ textChunkLimit?: number; /** 是否启用聊天命令 */ commandsEnabled?: boolean; /** 网络模式:webhook(有公网 IP,直连)或 cloud(无公网 IP,通过云端中继) */ networkMode?: "webhook" | "cloud"; /** 自定义中继服务器地址(cloud 模式下,不配则用官方默认 relay.xiaozhu.ai) */ relayUrl?: string; /** 中继鉴权密钥(不配则复用 clientSecret) */ relayToken?: string; /** 群聊是否需要 @提及 才响应 */ requireMention?: boolean; /** 群聊介绍提示语 */ groupIntroHint?: string; /** 回复模式:off=不引用, first=引用首条, all=引用所有 */ replyToMode?: "off" | "first" | "all"; /** DM 安全策略:open=任何人可发, allowlist=仅 allowFrom 中的用户 */ dmPolicy?: "open" | "allowlist"; /** 群聊工具策略(allow/alsoAllow/deny) */ groupToolPolicy?: GroupToolPolicyConfig; /** 工具审批策略(allow/require/deny) */ toolApproval?: ToolApprovalPolicyConfig; } /** 插件运行时(从 api.runtime 获取) */ export interface PluginRuntime { channel: { reply: { dispatchReplyWithBufferedBlockDispatcher(opts: unknown): Promise; }; text?: { chunkMarkdownText?(text: string, limit: number): string[]; }; session?: { resolveStorePath(): string; }; }; config?: { loadConfig(): Promise>; writeConfigFile?(cfg: Record): Promise; }; system?: { requestHeartbeatNow?(opts?: { reason?: string; agentId?: string; sessionKey?: string; }): void; runHeartbeatOnce?(opts?: { reason?: string; agentId?: string; sessionKey?: string; heartbeat?: { target?: string; }; }): Promise; }; tts?: { textToSpeechTelephony?(opts: { text: string; baseUrl?: string; model?: string; voice?: string; }): Promise<{ buffer?: Buffer | ArrayBuffer; contentType?: string; } | null>; }; [key: string]: unknown; } export interface ChannelSecurityDmPolicy { policy: string; allowFrom?: Array | null; policyPath?: string; allowFromPath: string; approveHint: string; normalizeEntry?: (raw: string) => string; } export interface ChannelSecurityContext { cfg: ChannelConfig; accountId?: string | null; account: ResolvedAccount; } export interface ChannelStatusIssue { channel: string; accountId: string; kind: "intent" | "permissions" | "config" | "auth" | "runtime"; message: string; fix?: string; } export type ChannelAccountState = "linked" | "not linked" | "configured" | "not configured" | "enabled" | "disabled"; export interface GroupToolPolicyConfig { allow?: string[]; alsoAllow?: string[]; deny?: string[]; } export interface ToolApprovalPolicyConfig { enabled?: boolean; allow?: string[]; require?: string[]; deny?: string[]; timeoutMs?: number; timeoutBehavior?: "allow" | "deny"; severity?: "info" | "warning" | "critical"; } export interface ChannelGroupContext { cfg: ChannelConfig; groupId?: string | null; groupChannel?: string | null; groupSpace?: string | null; accountId?: string | null; senderId?: string | null; senderName?: string | null; senderUsername?: string | null; senderE164?: string | null; } export interface ChannelAuthLoginParams { cfg: ChannelConfig; accountId?: string | null; runtime: RuntimeEnvLike; verbose?: boolean; channelInput?: string | null; } export type ChannelResolveKind = "user" | "group"; export interface ChannelResolverParams { cfg: ChannelConfig; accountId?: string | null; inputs: string[]; kind: ChannelResolveKind; runtime: RuntimeEnvLike; } export type ChannelDirectoryEntryKind = "user" | "group" | "channel"; export interface ChannelDirectoryEntry { kind: ChannelDirectoryEntryKind; id: string; name?: string; handle?: string; avatarUrl?: string; rank?: number; raw?: unknown; } export interface ChannelDirectorySelfParams { cfg: ChannelConfig; accountId?: string | null; runtime: RuntimeEnvLike; } export interface ChannelDirectoryListParams { cfg: ChannelConfig; accountId?: string | null; query?: string | null; limit?: number | null; runtime: RuntimeEnvLike; } export interface ChannelDirectoryListGroupMembersParams { cfg: ChannelConfig; accountId?: string | null; groupId: string; limit?: number | null; runtime: RuntimeEnvLike; } export interface ChannelHeartbeatRecipientsParams { cfg: ChannelConfig; opts?: { to?: string; all?: boolean; }; } export type ChannelOutboundTargetMode = "explicit" | "implicit" | "heartbeat"; export interface ChannelResolveTargetParams { cfg?: ChannelConfig; to?: string; allowFrom?: string[]; accountId?: string | null; mode?: ChannelOutboundTargetMode; } export interface PollInput { question: string; options: string[]; maxSelections?: number; durationSeconds?: number; durationHours?: number; } export interface ChannelPollContext { cfg: ChannelConfig; to: string; poll: PollInput; accountId?: string | null; threadId?: string | null; silent?: boolean; isAnonymous?: boolean; } export interface ChannelPollResult { messageId: string; toJid?: string; channelId?: string; conversationId?: string; pollId?: string; } export interface ChannelThreadingContext { Channel?: string; From?: string; To?: string; ChatType?: string; CurrentMessageId?: string | number; ReplyToId?: string; ReplyToIdFull?: string; ThreadLabel?: string; MessageThreadId?: string | number; } export interface ChannelThreadingToolContext { currentChannelId?: string; currentChannelProvider?: string; currentThreadTs?: string; currentMessageId?: string | number; replyToMode?: "off" | "first" | "all"; hasRepliedRef?: { value: boolean; }; skipCrossContextDecoration?: boolean; } export interface ChannelToolSend { to: string; accountId?: string | null; } export interface ChannelMessageActionContext { channel: string; action: string; cfg: ChannelConfig; params: Record; mediaLocalRoots?: readonly string[]; accountId?: string | null; requesterSenderId?: string | null; gateway?: { url?: string; token?: string; timeoutMs?: number; clientName: string; clientDisplayName?: string; mode: string; }; toolContext?: ChannelThreadingToolContext; dryRun?: boolean; } export interface AgentToolTextItem { type: "text"; text: string; } export interface AgentToolResultLike { content: AgentToolTextItem[]; details?: unknown; isError?: boolean; } /** 插件 API */ export interface PluginApi { runtime: PluginRuntime; config: unknown; logger: Logger; registerChannel(opts: { plugin: unknown; }): void; registerContextEngine?(id: string, factory: (runtimeContext?: Record) => unknown): void; on?(eventName: string, handler: (event?: Record, ctx?: Record) => unknown | Promise, options?: { priority?: number; }): void; } //# sourceMappingURL=types.d.ts.map