fix: align plugin runtime and exec wiring
This commit is contained in:
@@ -74,19 +74,18 @@ function isApplyPatchAllowedForModel(params: {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveExecConfig(cfg: ClawdbotConfig | undefined, agentId?: string | null) {
|
function resolveExecConfig(cfg: ClawdbotConfig | undefined) {
|
||||||
const globalExec = cfg?.tools?.exec;
|
const globalExec = cfg?.tools?.exec;
|
||||||
const agentExec = cfg?.agents?.list?.find((entry) => entry.id === agentId)?.tools?.exec;
|
|
||||||
return {
|
return {
|
||||||
host: agentExec?.host ?? globalExec?.host,
|
host: globalExec?.host,
|
||||||
security: agentExec?.security ?? globalExec?.security,
|
security: globalExec?.security,
|
||||||
ask: agentExec?.ask ?? globalExec?.ask,
|
ask: globalExec?.ask,
|
||||||
node: agentExec?.node ?? globalExec?.node,
|
node: globalExec?.node,
|
||||||
backgroundMs: agentExec?.backgroundMs ?? globalExec?.backgroundMs,
|
backgroundMs: globalExec?.backgroundMs,
|
||||||
timeoutSec: agentExec?.timeoutSec ?? globalExec?.timeoutSec,
|
timeoutSec: globalExec?.timeoutSec,
|
||||||
cleanupMs: agentExec?.cleanupMs ?? globalExec?.cleanupMs,
|
cleanupMs: globalExec?.cleanupMs,
|
||||||
notifyOnExit: agentExec?.notifyOnExit ?? globalExec?.notifyOnExit,
|
notifyOnExit: globalExec?.notifyOnExit,
|
||||||
applyPatch: agentExec?.applyPatch ?? globalExec?.applyPatch,
|
applyPatch: globalExec?.applyPatch,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,7 +161,7 @@ export function createClawdbotCodingTools(options?: {
|
|||||||
sandbox?.tools,
|
sandbox?.tools,
|
||||||
subagentPolicy,
|
subagentPolicy,
|
||||||
]);
|
]);
|
||||||
const execConfig = resolveExecConfig(options?.config, agentId);
|
const execConfig = resolveExecConfig(options?.config);
|
||||||
const sandboxRoot = sandbox?.workspaceDir;
|
const sandboxRoot = sandbox?.workspaceDir;
|
||||||
const allowWorkspaceWrites = sandbox?.workspaceAccess !== "ro";
|
const allowWorkspaceWrites = sandbox?.workspaceAccess !== "ro";
|
||||||
const workspaceRoot = options?.workspaceDir ?? process.cwd();
|
const workspaceRoot = options?.workspaceDir ?? process.cwd();
|
||||||
@@ -199,8 +198,9 @@ export function createClawdbotCodingTools(options?: {
|
|||||||
}
|
}
|
||||||
return [tool as AnyAgentTool];
|
return [tool as AnyAgentTool];
|
||||||
});
|
});
|
||||||
|
const { cleanupMs: cleanupMsOverride, ...execDefaults } = options?.exec ?? {};
|
||||||
const execTool = createExecTool({
|
const execTool = createExecTool({
|
||||||
...options?.exec,
|
...execDefaults,
|
||||||
host: options?.exec?.host ?? execConfig.host,
|
host: options?.exec?.host ?? execConfig.host,
|
||||||
security: options?.exec?.security ?? execConfig.security,
|
security: options?.exec?.security ?? execConfig.security,
|
||||||
ask: options?.exec?.ask ?? execConfig.ask,
|
ask: options?.exec?.ask ?? execConfig.ask,
|
||||||
@@ -229,7 +229,7 @@ export function createClawdbotCodingTools(options?: {
|
|||||||
label: "bash",
|
label: "bash",
|
||||||
} satisfies AnyAgentTool;
|
} satisfies AnyAgentTool;
|
||||||
const processTool = createProcessTool({
|
const processTool = createProcessTool({
|
||||||
cleanupMs: options?.exec?.cleanupMs,
|
cleanupMs: cleanupMsOverride ?? execConfig.cleanupMs,
|
||||||
scopeKey,
|
scopeKey,
|
||||||
});
|
});
|
||||||
const applyPatchTool =
|
const applyPatchTool =
|
||||||
|
|||||||
@@ -11,10 +11,7 @@ import type { ClawdbotConfig } from "../config/config.js";
|
|||||||
import { resolveSessionTranscriptsDirForAgent } from "../config/sessions/paths.js";
|
import { resolveSessionTranscriptsDirForAgent } from "../config/sessions/paths.js";
|
||||||
import { createSubsystemLogger } from "../logging.js";
|
import { createSubsystemLogger } from "../logging.js";
|
||||||
import { onSessionTranscriptUpdate } from "../sessions/transcript-events.js";
|
import { onSessionTranscriptUpdate } from "../sessions/transcript-events.js";
|
||||||
import { resolveUserPath, truncateUtf16Safe } from "../utils.js";
|
import { resolveUserPath } from "../utils.js";
|
||||||
import { colorize, isRich, theme } from "../terminal/theme.js";
|
|
||||||
import { resolveUserPath, truncateUtf16Safe } from "../utils.js";
|
|
||||||
import { colorize, isRich, theme } from "../terminal/theme.js";
|
|
||||||
import {
|
import {
|
||||||
createEmbeddingProvider,
|
createEmbeddingProvider,
|
||||||
type EmbeddingProvider,
|
type EmbeddingProvider,
|
||||||
|
|||||||
@@ -7,14 +7,10 @@ import {
|
|||||||
resolveInboundDebounceMs,
|
resolveInboundDebounceMs,
|
||||||
} from "../../auto-reply/inbound-debounce.js";
|
} from "../../auto-reply/inbound-debounce.js";
|
||||||
import { buildMentionRegexes, matchesMentionPatterns } from "../../auto-reply/reply/mentions.js";
|
import { buildMentionRegexes, matchesMentionPatterns } from "../../auto-reply/reply/mentions.js";
|
||||||
import type { ReplyPayload } from "../../auto-reply/types.js";
|
import { dispatchReplyWithBufferedBlockDispatcher } from "../../auto-reply/reply/provider-dispatcher.js";
|
||||||
import type { ReplyDispatchKind, ReplyDispatcherWithTypingOptions } from "../../auto-reply/reply/reply-dispatcher.js";
|
|
||||||
import { dispatchReplyWithBufferedBlockDispatcher as dispatchReplyWithBufferedBlockDispatcherImpl } from "../../auto-reply/reply/provider-dispatcher.js";
|
|
||||||
import { createReplyDispatcherWithTyping } from "../../auto-reply/reply/reply-dispatcher.js";
|
import { createReplyDispatcherWithTyping } from "../../auto-reply/reply/reply-dispatcher.js";
|
||||||
import { resolveEffectiveMessagesConfig, resolveHumanDelayConfig } from "../../agents/identity.js";
|
import { resolveEffectiveMessagesConfig, resolveHumanDelayConfig } from "../../agents/identity.js";
|
||||||
import { resolveCommandAuthorizedFromAuthorizers } from "../../channels/command-gating.js";
|
import { resolveCommandAuthorizedFromAuthorizers } from "../../channels/command-gating.js";
|
||||||
import type { ClawdbotConfig } from "../../config/config.js";
|
|
||||||
import type { GroupPolicyChannel } from "../../config/group-policy.js";
|
|
||||||
import { resolveChannelGroupPolicy, resolveChannelGroupRequireMention } from "../../config/group-policy.js";
|
import { resolveChannelGroupPolicy, resolveChannelGroupRequireMention } from "../../config/group-policy.js";
|
||||||
import { resolveStateDir } from "../../config/paths.js";
|
import { resolveStateDir } from "../../config/paths.js";
|
||||||
import { shouldLogVerbose } from "../../globals.js";
|
import { shouldLogVerbose } from "../../globals.js";
|
||||||
@@ -28,7 +24,6 @@ import {
|
|||||||
upsertChannelPairingRequest,
|
upsertChannelPairingRequest,
|
||||||
} from "../../pairing/pairing-store.js";
|
} from "../../pairing/pairing-store.js";
|
||||||
import { resolveAgentRoute } from "../../routing/resolve-route.js";
|
import { resolveAgentRoute } from "../../routing/resolve-route.js";
|
||||||
import type { FinalizedMsgContext } from "../../auto-reply/templating.js";
|
|
||||||
|
|
||||||
import type { PluginRuntime } from "./types.js";
|
import type { PluginRuntime } from "./types.js";
|
||||||
|
|
||||||
@@ -57,41 +52,13 @@ export function createPluginRuntime(): PluginRuntime {
|
|||||||
hasControlCommand,
|
hasControlCommand,
|
||||||
},
|
},
|
||||||
reply: {
|
reply: {
|
||||||
dispatchReplyWithBufferedBlockDispatcher: async (params) => {
|
dispatchReplyWithBufferedBlockDispatcher,
|
||||||
const dispatcherOptions = params.dispatcherOptions;
|
createReplyDispatcherWithTyping,
|
||||||
const deliver = async (payload: ReplyPayload, _info: { kind: ReplyDispatchKind }) => {
|
|
||||||
await dispatcherOptions.deliver(payload);
|
|
||||||
};
|
|
||||||
const onError = dispatcherOptions.onError
|
|
||||||
? (err: unknown, info: { kind: ReplyDispatchKind }) => {
|
|
||||||
dispatcherOptions.onError?.(err, { kind: info.kind });
|
|
||||||
}
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
await dispatchReplyWithBufferedBlockDispatcherImpl({
|
|
||||||
ctx: params.ctx as FinalizedMsgContext,
|
|
||||||
cfg: params.cfg as ClawdbotConfig,
|
|
||||||
dispatcherOptions: {
|
|
||||||
deliver,
|
|
||||||
onError,
|
|
||||||
} satisfies ReplyDispatcherWithTypingOptions,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
createReplyDispatcherWithTyping: (...args) =>
|
|
||||||
createReplyDispatcherWithTyping(args[0] as ReplyDispatcherWithTypingOptions),
|
|
||||||
resolveEffectiveMessagesConfig,
|
resolveEffectiveMessagesConfig,
|
||||||
resolveHumanDelayConfig,
|
resolveHumanDelayConfig,
|
||||||
},
|
},
|
||||||
routing: {
|
routing: {
|
||||||
resolveAgentRoute: (params) => {
|
resolveAgentRoute,
|
||||||
const resolved = resolveAgentRoute({
|
|
||||||
cfg: params.cfg as ClawdbotConfig,
|
|
||||||
channel: params.channel,
|
|
||||||
accountId: params.accountId,
|
|
||||||
peer: params.peer,
|
|
||||||
});
|
|
||||||
return { sessionKey: resolved.sessionKey, accountId: resolved.accountId };
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
pairing: {
|
pairing: {
|
||||||
buildPairingReply,
|
buildPairingReply,
|
||||||
@@ -100,61 +67,19 @@ export function createPluginRuntime(): PluginRuntime {
|
|||||||
},
|
},
|
||||||
media: {
|
media: {
|
||||||
fetchRemoteMedia,
|
fetchRemoteMedia,
|
||||||
saveMediaBuffer: async (buffer, contentType, direction, maxBytes) => {
|
saveMediaBuffer,
|
||||||
const saved = await saveMediaBuffer(
|
|
||||||
Buffer.isBuffer(buffer) ? buffer : Buffer.from(buffer),
|
|
||||||
contentType,
|
|
||||||
direction,
|
|
||||||
maxBytes,
|
|
||||||
);
|
|
||||||
return { path: saved.path, contentType: saved.contentType };
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
mentions: {
|
mentions: {
|
||||||
buildMentionRegexes,
|
buildMentionRegexes,
|
||||||
matchesMentionPatterns,
|
matchesMentionPatterns,
|
||||||
},
|
},
|
||||||
groups: {
|
groups: {
|
||||||
resolveGroupPolicy: (cfg, channel, accountId, groupId) =>
|
resolveGroupPolicy: resolveChannelGroupPolicy,
|
||||||
resolveChannelGroupPolicy({
|
resolveRequireMention: resolveChannelGroupRequireMention,
|
||||||
cfg,
|
|
||||||
channel: channel as GroupPolicyChannel,
|
|
||||||
accountId,
|
|
||||||
groupId,
|
|
||||||
}),
|
|
||||||
resolveRequireMention: (cfg, channel, accountId, groupId, override) =>
|
|
||||||
resolveChannelGroupRequireMention({
|
|
||||||
cfg,
|
|
||||||
channel: channel as GroupPolicyChannel,
|
|
||||||
accountId,
|
|
||||||
groupId,
|
|
||||||
requireMentionOverride: override,
|
|
||||||
}),
|
|
||||||
},
|
},
|
||||||
debounce: {
|
debounce: {
|
||||||
createInboundDebouncer: (opts) => {
|
createInboundDebouncer,
|
||||||
const keys = new Set<string>();
|
resolveInboundDebounceMs,
|
||||||
const debouncer = createInboundDebouncer({
|
|
||||||
debounceMs: opts.debounceMs,
|
|
||||||
buildKey: opts.buildKey,
|
|
||||||
shouldDebounce: opts.shouldDebounce ?? (() => true),
|
|
||||||
onFlush: opts.onFlush,
|
|
||||||
onError: opts.onError ? (err: unknown) => opts.onError?.(err) : undefined,
|
|
||||||
});
|
|
||||||
return {
|
|
||||||
push: (value) => {
|
|
||||||
const key = opts.buildKey(value);
|
|
||||||
if (key) keys.add(key);
|
|
||||||
void debouncer.enqueue(value);
|
|
||||||
},
|
|
||||||
flush: async () => {
|
|
||||||
const flushKeys = Array.from(keys);
|
|
||||||
keys.clear();
|
|
||||||
for (const key of flushKeys) await debouncer.flushKey(key);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
},
|
|
||||||
resolveInboundDebounceMs: (cfg, channel) => resolveInboundDebounceMs({ cfg, channel }),
|
|
||||||
},
|
},
|
||||||
commands: {
|
commands: {
|
||||||
resolveCommandAuthorizedFromAuthorizers,
|
resolveCommandAuthorizedFromAuthorizers,
|
||||||
@@ -175,7 +100,7 @@ export function createPluginRuntime(): PluginRuntime {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
state: {
|
state: {
|
||||||
resolveStateDir: () => resolveStateDir(),
|
resolveStateDir,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user