mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 18:40:44 +00:00
refactor: rename clawdbot to moltbot with legacy compat
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import type { ClawdbotConfig } from "../config/config.js";
|
||||
import type { MoltbotConfig } from "../config/config.js";
|
||||
import type { SlackAccountConfig } from "../config/types.js";
|
||||
import { normalizeChatType } from "../channels/chat-type.js";
|
||||
import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "../routing/session-key.js";
|
||||
@@ -28,26 +28,26 @@ export type ResolvedSlackAccount = {
|
||||
channels?: SlackAccountConfig["channels"];
|
||||
};
|
||||
|
||||
function listConfiguredAccountIds(cfg: ClawdbotConfig): string[] {
|
||||
function listConfiguredAccountIds(cfg: MoltbotConfig): string[] {
|
||||
const accounts = cfg.channels?.slack?.accounts;
|
||||
if (!accounts || typeof accounts !== "object") return [];
|
||||
return Object.keys(accounts).filter(Boolean);
|
||||
}
|
||||
|
||||
export function listSlackAccountIds(cfg: ClawdbotConfig): string[] {
|
||||
export function listSlackAccountIds(cfg: MoltbotConfig): string[] {
|
||||
const ids = listConfiguredAccountIds(cfg);
|
||||
if (ids.length === 0) return [DEFAULT_ACCOUNT_ID];
|
||||
return ids.sort((a, b) => a.localeCompare(b));
|
||||
}
|
||||
|
||||
export function resolveDefaultSlackAccountId(cfg: ClawdbotConfig): string {
|
||||
export function resolveDefaultSlackAccountId(cfg: MoltbotConfig): string {
|
||||
const ids = listSlackAccountIds(cfg);
|
||||
if (ids.includes(DEFAULT_ACCOUNT_ID)) return DEFAULT_ACCOUNT_ID;
|
||||
return ids[0] ?? DEFAULT_ACCOUNT_ID;
|
||||
}
|
||||
|
||||
function resolveAccountConfig(
|
||||
cfg: ClawdbotConfig,
|
||||
cfg: MoltbotConfig,
|
||||
accountId: string,
|
||||
): SlackAccountConfig | undefined {
|
||||
const accounts = cfg.channels?.slack?.accounts;
|
||||
@@ -55,7 +55,7 @@ function resolveAccountConfig(
|
||||
return accounts[accountId] as SlackAccountConfig | undefined;
|
||||
}
|
||||
|
||||
function mergeSlackAccountConfig(cfg: ClawdbotConfig, accountId: string): SlackAccountConfig {
|
||||
function mergeSlackAccountConfig(cfg: MoltbotConfig, accountId: string): SlackAccountConfig {
|
||||
const { accounts: _ignored, ...base } = (cfg.channels?.slack ?? {}) as SlackAccountConfig & {
|
||||
accounts?: unknown;
|
||||
};
|
||||
@@ -64,7 +64,7 @@ function mergeSlackAccountConfig(cfg: ClawdbotConfig, accountId: string): SlackA
|
||||
}
|
||||
|
||||
export function resolveSlackAccount(params: {
|
||||
cfg: ClawdbotConfig;
|
||||
cfg: MoltbotConfig;
|
||||
accountId?: string | null;
|
||||
}): ResolvedSlackAccount {
|
||||
const accountId = normalizeAccountId(params.accountId);
|
||||
@@ -105,7 +105,7 @@ export function resolveSlackAccount(params: {
|
||||
};
|
||||
}
|
||||
|
||||
export function listEnabledSlackAccounts(cfg: ClawdbotConfig): ResolvedSlackAccount[] {
|
||||
export function listEnabledSlackAccounts(cfg: MoltbotConfig): ResolvedSlackAccount[] {
|
||||
return listSlackAccountIds(cfg)
|
||||
.map((accountId) => resolveSlackAccount({ cfg, accountId }))
|
||||
.filter((account) => account.enabled);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { ClawdbotConfig } from "../config/config.js";
|
||||
import type { MoltbotConfig } from "../config/config.js";
|
||||
import type { SlackChannelConfig } from "../config/types.slack.js";
|
||||
import { normalizeAccountId } from "../routing/session-key.js";
|
||||
|
||||
@@ -13,7 +13,7 @@ export type SlackChannelMigrationResult = {
|
||||
};
|
||||
|
||||
function resolveAccountChannels(
|
||||
cfg: ClawdbotConfig,
|
||||
cfg: MoltbotConfig,
|
||||
accountId?: string | null,
|
||||
): { channels?: SlackChannels } {
|
||||
if (!accountId) return {};
|
||||
@@ -43,7 +43,7 @@ export function migrateSlackChannelsInPlace(
|
||||
}
|
||||
|
||||
export function migrateSlackChannelConfig(params: {
|
||||
cfg: ClawdbotConfig;
|
||||
cfg: MoltbotConfig;
|
||||
accountId?: string | null;
|
||||
oldChannelId: string;
|
||||
newChannelId: string;
|
||||
|
||||
@@ -94,7 +94,7 @@ vi.mock("../pairing/pairing-store.js", () => ({
|
||||
}));
|
||||
|
||||
vi.mock("../config/sessions.js", () => ({
|
||||
resolveStorePath: vi.fn(() => "/tmp/clawdbot-sessions.json"),
|
||||
resolveStorePath: vi.fn(() => "/tmp/moltbot-sessions.json"),
|
||||
updateLastRoute: (...args: unknown[]) => slackTestState.updateLastRouteMock(...args),
|
||||
resolveSessionKey: vi.fn(),
|
||||
readSessionUpdatedAt: vi.fn(() => undefined),
|
||||
|
||||
@@ -51,7 +51,7 @@ vi.mock("../pairing/pairing-store.js", () => ({
|
||||
}));
|
||||
|
||||
vi.mock("../config/sessions.js", () => ({
|
||||
resolveStorePath: vi.fn(() => "/tmp/clawdbot-sessions.json"),
|
||||
resolveStorePath: vi.fn(() => "/tmp/moltbot-sessions.json"),
|
||||
updateLastRoute: (...args: unknown[]) => updateLastRouteMock(...args),
|
||||
resolveSessionKey: vi.fn(),
|
||||
readSessionUpdatedAt: vi.fn(() => undefined),
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import type { App } from "@slack/bolt";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import type { ClawdbotConfig } from "../../config/config.js";
|
||||
import type { MoltbotConfig } from "../../config/config.js";
|
||||
import type { RuntimeEnv } from "../../runtime.js";
|
||||
import { createSlackMonitorContext, normalizeSlackChannelType } from "./context.js";
|
||||
|
||||
const baseParams = () => ({
|
||||
cfg: {} as ClawdbotConfig,
|
||||
cfg: {} as MoltbotConfig,
|
||||
accountId: "default",
|
||||
botToken: "token",
|
||||
app: { client: {} } as App,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { App } from "@slack/bolt";
|
||||
import type { HistoryEntry } from "../../auto-reply/reply/history.js";
|
||||
import type { ClawdbotConfig, SlackReactionNotificationMode } from "../../config/config.js";
|
||||
import type { MoltbotConfig, SlackReactionNotificationMode } from "../../config/config.js";
|
||||
import { resolveSessionKey, type SessionScope } from "../../config/sessions.js";
|
||||
import type { DmPolicy, GroupPolicy } from "../../config/types.js";
|
||||
import { logVerbose } from "../../globals.js";
|
||||
@@ -42,7 +42,7 @@ export function normalizeSlackChannelType(
|
||||
}
|
||||
|
||||
export type SlackMonitorContext = {
|
||||
cfg: ClawdbotConfig;
|
||||
cfg: MoltbotConfig;
|
||||
accountId: string;
|
||||
botToken: string;
|
||||
app: App;
|
||||
@@ -115,7 +115,7 @@ export type SlackMonitorContext = {
|
||||
};
|
||||
|
||||
export function createSlackMonitorContext(params: {
|
||||
cfg: ClawdbotConfig;
|
||||
cfg: MoltbotConfig;
|
||||
accountId: string;
|
||||
botToken: string;
|
||||
app: App;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { App } from "@slack/bolt";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import type { ClawdbotConfig } from "../../../config/config.js";
|
||||
import type { MoltbotConfig } from "../../../config/config.js";
|
||||
import type { RuntimeEnv } from "../../../runtime.js";
|
||||
import { expectInboundContextContract } from "../../../../test/helpers/inbound-contract.js";
|
||||
import type { ResolvedSlackAccount } from "../../accounts.js";
|
||||
@@ -14,7 +14,7 @@ describe("slack prepareSlackMessage inbound contract", () => {
|
||||
const slackCtx = createSlackMonitorContext({
|
||||
cfg: {
|
||||
channels: { slack: { enabled: true } },
|
||||
} as ClawdbotConfig,
|
||||
} as MoltbotConfig,
|
||||
accountId: "default",
|
||||
botToken: "token",
|
||||
app: { client: {} } as App,
|
||||
@@ -82,7 +82,7 @@ describe("slack prepareSlackMessage inbound contract", () => {
|
||||
const slackCtx = createSlackMonitorContext({
|
||||
cfg: {
|
||||
channels: { slack: { enabled: true, replyToMode: "all" } },
|
||||
} as ClawdbotConfig,
|
||||
} as MoltbotConfig,
|
||||
accountId: "default",
|
||||
botToken: "token",
|
||||
app: { client: {} } as App,
|
||||
|
||||
@@ -126,7 +126,7 @@ describe("Slack native command argument menus", () => {
|
||||
const { actions, ctx, account } = createHarness();
|
||||
registerSlackMonitorSlashCommands({ ctx: ctx as never, account: account as never });
|
||||
|
||||
const handler = actions.get("clawdbot_cmdarg");
|
||||
const handler = actions.get("moltbot_cmdarg");
|
||||
if (!handler) throw new Error("Missing arg-menu action handler");
|
||||
|
||||
const respond = vi.fn().mockResolvedValue(undefined);
|
||||
@@ -152,7 +152,7 @@ describe("Slack native command argument menus", () => {
|
||||
const { actions, ctx, account } = createHarness();
|
||||
registerSlackMonitorSlashCommands({ ctx: ctx as never, account: account as never });
|
||||
|
||||
const handler = actions.get("clawdbot_cmdarg");
|
||||
const handler = actions.get("moltbot_cmdarg");
|
||||
if (!handler) throw new Error("Missing arg-menu action handler");
|
||||
|
||||
const respond = vi.fn().mockResolvedValue(undefined);
|
||||
@@ -180,7 +180,7 @@ describe("Slack native command argument menus", () => {
|
||||
const { actions, postEphemeral, ctx, account } = createHarness();
|
||||
registerSlackMonitorSlashCommands({ ctx: ctx as never, account: account as never });
|
||||
|
||||
const handler = actions.get("clawdbot_cmdarg");
|
||||
const handler = actions.get("moltbot_cmdarg");
|
||||
if (!handler) throw new Error("Missing arg-menu action handler");
|
||||
|
||||
await handler({
|
||||
@@ -202,7 +202,7 @@ describe("Slack native command argument menus", () => {
|
||||
const { actions, postEphemeral, ctx, account } = createHarness();
|
||||
registerSlackMonitorSlashCommands({ ctx: ctx as never, account: account as never });
|
||||
|
||||
const handler = actions.get("clawdbot_cmdarg");
|
||||
const handler = actions.get("moltbot_cmdarg");
|
||||
if (!handler) throw new Error("Missing arg-menu action handler");
|
||||
|
||||
await handler({
|
||||
|
||||
@@ -41,7 +41,7 @@ import { deliverSlackSlashReplies } from "./replies.js";
|
||||
|
||||
type SlackBlock = { type: string; [key: string]: unknown };
|
||||
|
||||
const SLACK_COMMAND_ARG_ACTION_ID = "clawdbot_cmdarg";
|
||||
const SLACK_COMMAND_ARG_ACTION_ID = "moltbot_cmdarg";
|
||||
const SLACK_COMMAND_ARG_VALUE_PREFIX = "cmdarg";
|
||||
|
||||
function chunkItems<T>(items: T[], size: number): T[][] {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { ClawdbotConfig, SlackSlashCommandConfig } from "../../config/config.js";
|
||||
import type { MoltbotConfig, SlackSlashCommandConfig } from "../../config/config.js";
|
||||
import type { RuntimeEnv } from "../../runtime.js";
|
||||
import type { SlackFile, SlackMessageEvent } from "../types.js";
|
||||
|
||||
@@ -7,7 +7,7 @@ export type MonitorSlackOpts = {
|
||||
appToken?: string;
|
||||
accountId?: string;
|
||||
mode?: "socket" | "http";
|
||||
config?: ClawdbotConfig;
|
||||
config?: MoltbotConfig;
|
||||
runtime?: RuntimeEnv;
|
||||
abortSignal?: AbortSignal;
|
||||
mediaMaxMb?: number;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import type { ClawdbotConfig } from "../config/config.js";
|
||||
import type { MoltbotConfig } from "../config/config.js";
|
||||
import { buildSlackThreadingToolContext } from "./threading-tool-context.js";
|
||||
|
||||
const emptyCfg = {} as ClawdbotConfig;
|
||||
const emptyCfg = {} as MoltbotConfig;
|
||||
|
||||
describe("buildSlackThreadingToolContext", () => {
|
||||
it("uses top-level replyToMode by default", () => {
|
||||
@@ -11,7 +11,7 @@ describe("buildSlackThreadingToolContext", () => {
|
||||
channels: {
|
||||
slack: { replyToMode: "first" },
|
||||
},
|
||||
} as ClawdbotConfig;
|
||||
} as MoltbotConfig;
|
||||
const result = buildSlackThreadingToolContext({
|
||||
cfg,
|
||||
accountId: null,
|
||||
@@ -28,7 +28,7 @@ describe("buildSlackThreadingToolContext", () => {
|
||||
replyToModeByChatType: { direct: "all" },
|
||||
},
|
||||
},
|
||||
} as ClawdbotConfig;
|
||||
} as MoltbotConfig;
|
||||
const result = buildSlackThreadingToolContext({
|
||||
cfg,
|
||||
accountId: null,
|
||||
@@ -45,7 +45,7 @@ describe("buildSlackThreadingToolContext", () => {
|
||||
replyToModeByChatType: { direct: "all" },
|
||||
},
|
||||
},
|
||||
} as ClawdbotConfig;
|
||||
} as MoltbotConfig;
|
||||
const result = buildSlackThreadingToolContext({
|
||||
cfg,
|
||||
accountId: null,
|
||||
@@ -61,7 +61,7 @@ describe("buildSlackThreadingToolContext", () => {
|
||||
replyToMode: "first",
|
||||
},
|
||||
},
|
||||
} as ClawdbotConfig;
|
||||
} as MoltbotConfig;
|
||||
const result = buildSlackThreadingToolContext({
|
||||
cfg,
|
||||
accountId: null,
|
||||
@@ -78,7 +78,7 @@ describe("buildSlackThreadingToolContext", () => {
|
||||
dm: { replyToMode: "all" },
|
||||
},
|
||||
},
|
||||
} as ClawdbotConfig;
|
||||
} as MoltbotConfig;
|
||||
const result = buildSlackThreadingToolContext({
|
||||
cfg,
|
||||
accountId: null,
|
||||
@@ -92,7 +92,7 @@ describe("buildSlackThreadingToolContext", () => {
|
||||
channels: {
|
||||
slack: { replyToMode: "off" },
|
||||
},
|
||||
} as ClawdbotConfig;
|
||||
} as MoltbotConfig;
|
||||
const result = buildSlackThreadingToolContext({
|
||||
cfg,
|
||||
accountId: null,
|
||||
|
||||
@@ -2,11 +2,11 @@ import type {
|
||||
ChannelThreadingContext,
|
||||
ChannelThreadingToolContext,
|
||||
} from "../channels/plugins/types.js";
|
||||
import type { ClawdbotConfig } from "../config/config.js";
|
||||
import type { MoltbotConfig } from "../config/config.js";
|
||||
import { resolveSlackAccount, resolveSlackReplyToMode } from "./accounts.js";
|
||||
|
||||
export function buildSlackThreadingToolContext(params: {
|
||||
cfg: ClawdbotConfig;
|
||||
cfg: MoltbotConfig;
|
||||
accountId?: string | null;
|
||||
context: ChannelThreadingContext;
|
||||
hasRepliedRef?: { value: boolean };
|
||||
|
||||
Reference in New Issue
Block a user