refactor: migrate extensions to plugin sdk

This commit is contained in:
Peter Steinberger
2026-01-18 02:51:42 +00:00
parent 5b4651d9ed
commit 1420d113d8
95 changed files with 380 additions and 208 deletions

View File

@@ -1,3 +1,6 @@
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { createJiti } from "jiti";
import type { ClawdbotConfig } from "../config/config.js";
@@ -92,6 +95,24 @@ const normalizePluginsConfig = (config?: ClawdbotConfig["plugins"]): NormalizedP
};
};
const resolvePluginSdkAlias = (): string | null => {
try {
let cursor = path.dirname(fileURLToPath(import.meta.url));
for (let i = 0; i < 6; i += 1) {
const distCandidate = path.join(cursor, "dist", "plugin-sdk", "index.js");
if (fs.existsSync(distCandidate)) return distCandidate;
const srcCandidate = path.join(cursor, "src", "plugin-sdk", "index.ts");
if (fs.existsSync(srcCandidate)) return srcCandidate;
const parent = path.dirname(cursor);
if (parent === cursor) break;
cursor = parent;
}
} catch {
// ignore
}
return null;
};
function buildCacheKey(params: {
workspaceDir?: string;
plugins: NormalizedPluginsConfig;
@@ -289,8 +310,10 @@ export function loadClawdbotPlugins(options: PluginLoadOptions = {}): PluginRegi
});
pushDiagnostics(registry.diagnostics, discovery.diagnostics);
const pluginSdkAlias = resolvePluginSdkAlias();
const jiti = createJiti(import.meta.url, {
interopDefault: true,
...(pluginSdkAlias ? { alias: { "clawdbot/plugin-sdk": pluginSdkAlias } } : {}),
});
const seenIds = new Map<string, PluginRecord["origin"]>();

View File

@@ -6,6 +6,7 @@ import { createInboundDebouncer, resolveInboundDebounceMs } from "../../auto-rep
import { buildMentionRegexes, matchesMentionPatterns } from "../../auto-reply/reply/mentions.js";
import { dispatchReplyWithBufferedBlockDispatcher } from "../../auto-reply/reply/provider-dispatcher.js";
import { createReplyDispatcherWithTyping } from "../../auto-reply/reply/reply-dispatcher.js";
import { resolveEffectiveMessagesConfig, resolveHumanDelayConfig } from "../../agents/identity.js";
import { resolveCommandAuthorizedFromAuthorizers } from "../../channels/command-gating.js";
import { resolveChannelGroupPolicy, resolveChannelGroupRequireMention } from "../../config/group-policy.js";
import { resolveStateDir } from "../../config/paths.js";
@@ -46,6 +47,8 @@ export function createPluginRuntime(): PluginRuntime {
reply: {
dispatchReplyWithBufferedBlockDispatcher,
createReplyDispatcherWithTyping,
resolveEffectiveMessagesConfig,
resolveHumanDelayConfig,
},
routing: {
resolveAgentRoute,

View File

@@ -25,6 +25,15 @@ export type PluginRuntime = {
};
}) => Promise<void>;
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;
};
routing: {
resolveAgentRoute: (params: {