From dad69afc8451cdf16424fdfddc9d5f0b8a354344 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 18 Jan 2026 03:40:27 +0000 Subject: [PATCH] fix: align plugin runtime types --- src/plugins/runtime/types.ts | 108 ++++++++--------------------------- vitest.config.ts | 9 +++ 2 files changed, 33 insertions(+), 84 deletions(-) diff --git a/src/plugins/runtime/types.ts b/src/plugins/runtime/types.ts index 54494f222..93b652030 100644 --- a/src/plugins/runtime/types.ts +++ b/src/plugins/runtime/types.ts @@ -1,4 +1,4 @@ -import type { ClawdbotConfig } from "../../config/config.js"; +import type { LogLevel } from "../../logging/levels.js"; export type RuntimeLogger = { debug?: (message: string) => void; @@ -11,109 +11,49 @@ export type PluginRuntime = { version: string; channel: { text: { - chunkMarkdownText: (text: string, limit: number) => string[]; - resolveTextChunkLimit: (cfg: ClawdbotConfig, channel: string, accountId?: string) => number; - hasControlCommand: (text: string, cfg: ClawdbotConfig) => boolean; + chunkMarkdownText: typeof import("../../auto-reply/chunk.js").chunkMarkdownText; + resolveTextChunkLimit: typeof import("../../auto-reply/chunk.js").resolveTextChunkLimit; + hasControlCommand: typeof import("../../auto-reply/command-detection.js").hasControlCommand; }; reply: { - dispatchReplyWithBufferedBlockDispatcher: (params: { - ctx: unknown; - cfg: unknown; - dispatcherOptions: { - deliver: (payload: { text?: string; mediaUrls?: string[]; mediaUrl?: string }) => void | Promise; - onError?: (err: unknown, info: { kind: string }) => void; - }; - }) => Promise; - createReplyDispatcherWithTyping: (...args: unknown[]) => unknown; - resolveEffectiveMessagesConfig: ( - cfg: ClawdbotConfig, - agentId: string, - opts?: { hasAllowFrom?: boolean; fallbackMessagePrefix?: string }, - ) => { messagePrefix: string; responsePrefix?: string }; - resolveHumanDelayConfig: ( - cfg: ClawdbotConfig, - agentId: string, - ) => { mode?: string; minMs?: number; maxMs?: number } | undefined; + dispatchReplyWithBufferedBlockDispatcher: typeof import("../../auto-reply/reply/provider-dispatcher.js").dispatchReplyWithBufferedBlockDispatcher; + createReplyDispatcherWithTyping: typeof import("../../auto-reply/reply/reply-dispatcher.js").createReplyDispatcherWithTyping; + resolveEffectiveMessagesConfig: typeof import("../../agents/identity.js").resolveEffectiveMessagesConfig; + resolveHumanDelayConfig: typeof import("../../agents/identity.js").resolveHumanDelayConfig; }; routing: { - resolveAgentRoute: (params: { - cfg: unknown; - channel: string; - accountId: string; - peer: { kind: "dm" | "group" | "channel"; id: string }; - }) => { - agentId: string; - channel: string; - accountId: string; - sessionKey: string; - mainSessionKey: string; - matchedBy: string; - }; + resolveAgentRoute: typeof import("../../routing/resolve-route.js").resolveAgentRoute; }; pairing: { - buildPairingReply: (params: { channel: string; idLine: string; code: string }) => string; - readAllowFromStore: (channel: string) => Promise; - upsertPairingRequest: (params: { - channel: string; - id: string; - meta?: { name?: string }; - }) => Promise<{ code: string; created: boolean }>; + buildPairingReply: typeof import("../../pairing/pairing-messages.js").buildPairingReply; + readAllowFromStore: typeof import("../../pairing/pairing-store.js").readChannelAllowFromStore; + upsertPairingRequest: typeof import("../../pairing/pairing-store.js").upsertChannelPairingRequest; }; media: { - fetchRemoteMedia: (params: { url: string }) => Promise<{ buffer: Buffer; contentType?: string }>; - saveMediaBuffer: ( - buffer: Uint8Array, - contentType: string | undefined, - direction: "inbound" | "outbound", - maxBytes: number, - ) => Promise<{ path: string; contentType?: string }>; + fetchRemoteMedia: typeof import("../../media/fetch.js").fetchRemoteMedia; + saveMediaBuffer: typeof import("../../media/store.js").saveMediaBuffer; }; mentions: { - buildMentionRegexes: (cfg: ClawdbotConfig, agentId?: string) => RegExp[]; - matchesMentionPatterns: (text: string, regexes: RegExp[]) => boolean; + buildMentionRegexes: typeof import("../../auto-reply/reply/mentions.js").buildMentionRegexes; + matchesMentionPatterns: typeof import("../../auto-reply/reply/mentions.js").matchesMentionPatterns; }; groups: { - resolveGroupPolicy: ( - cfg: ClawdbotConfig, - channel: string, - accountId: string, - groupId: string, - ) => { - allowlistEnabled: boolean; - allowed: boolean; - groupConfig?: unknown; - defaultConfig?: unknown; - }; - resolveRequireMention: ( - cfg: ClawdbotConfig, - channel: string, - accountId: string, - groupId: string, - override?: boolean, - ) => boolean; + resolveGroupPolicy: typeof import("../../config/group-policy.js").resolveChannelGroupPolicy; + resolveRequireMention: typeof import("../../config/group-policy.js").resolveChannelGroupRequireMention; }; debounce: { - createInboundDebouncer: (opts: { - debounceMs: number; - buildKey: (value: T) => string | null; - shouldDebounce: (value: T) => boolean; - onFlush: (entries: T[]) => Promise; - onError?: (err: unknown) => void; - }) => { push: (value: T) => void; flush: () => Promise }; - resolveInboundDebounceMs: (cfg: ClawdbotConfig, channel: string) => number; + createInboundDebouncer: typeof import("../../auto-reply/inbound-debounce.js").createInboundDebouncer; + resolveInboundDebounceMs: typeof import("../../auto-reply/inbound-debounce.js").resolveInboundDebounceMs; }; commands: { - resolveCommandAuthorizedFromAuthorizers: (params: { - useAccessGroups: boolean; - authorizers: Array<{ configured: boolean; allowed: boolean }>; - }) => boolean; + resolveCommandAuthorizedFromAuthorizers: typeof import("../../channels/command-gating.js").resolveCommandAuthorizedFromAuthorizers; }; }; logging: { - shouldLogVerbose: () => boolean; - getChildLogger: (bindings?: Record, opts?: { level?: string }) => RuntimeLogger; + shouldLogVerbose: typeof import("../../globals.js").shouldLogVerbose; + getChildLogger: (bindings?: Record, opts?: { level?: LogLevel }) => RuntimeLogger; }; state: { - resolveStateDir: (cfg: ClawdbotConfig) => string; + resolveStateDir: typeof import("../../config/paths.js").resolveStateDir; }; }; diff --git a/vitest.config.ts b/vitest.config.ts index 407121f1e..28bc8ab70 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -1,6 +1,15 @@ +import path from "node:path"; +import { fileURLToPath } from "node:url"; import { defineConfig } from "vitest/config"; +const repoRoot = path.dirname(fileURLToPath(import.meta.url)); + export default defineConfig({ + resolve: { + alias: { + "clawdbot/plugin-sdk": path.join(repoRoot, "src", "plugin-sdk", "index.ts"), + }, + }, test: { testTimeout: 20_000, include: [