diff --git a/src/agents/llm-proxy.ts b/src/agents/llm-proxy.ts index 16e62c6be..09371610e 100644 --- a/src/agents/llm-proxy.ts +++ b/src/agents/llm-proxy.ts @@ -7,7 +7,7 @@ */ import { ProxyAgent, setGlobalDispatcher, getGlobalDispatcher, type Dispatcher } from "undici"; -import type { ClawdbotConfig } from "../config/config.js"; +import type { MoltbotConfig } from "../config/config.js"; let originalDispatcher: Dispatcher | null = null; let currentProxyUrl: string | null = null; @@ -18,7 +18,7 @@ let currentProxyUrl: string | null = null; * * Safe to call multiple times - only reconfigures if the proxy URL changes. */ -export function setupLlmProxy(cfg: ClawdbotConfig | undefined): void { +export function setupLlmProxy(cfg: MoltbotConfig | undefined): void { const proxyUrl = cfg?.models?.proxy?.trim(); // No proxy configured - restore original dispatcher if we changed it diff --git a/src/agents/tools/qveris-tools.ts b/src/agents/tools/qveris-tools.ts index d5b5ad070..44a9b9383 100644 --- a/src/agents/tools/qveris-tools.ts +++ b/src/agents/tools/qveris-tools.ts @@ -1,6 +1,6 @@ import { Type } from "@sinclair/typebox"; -import type { ClawdbotConfig } from "../../config/config.js"; +import type { MoltbotConfig } from "../../config/config.js"; import type { AnyAgentTool } from "./common.js"; import { jsonResult, readNumberParam, readStringParam } from "./common.js"; @@ -18,7 +18,7 @@ const DEFAULT_PRE_SEARCH_BYTE_THRESHOLD = 100; // Types // ============================================================================ -type QverisConfig = NonNullable["qveris"]; +type QverisConfig = NonNullable["qveris"]; /** Search result parameter from QVeris API */ interface QverisSearchResultParam { @@ -83,7 +83,7 @@ interface QverisToolMapping { // Config Resolution // ============================================================================ -function resolveQverisConfig(cfg?: ClawdbotConfig): QverisConfig { +function resolveQverisConfig(cfg?: MoltbotConfig): QverisConfig { return cfg?.tools?.qveris; } @@ -386,7 +386,7 @@ function sanitizeToolName(toolId: string): string { // ============================================================================ export function createQverisTools(options?: { - config?: ClawdbotConfig; + config?: MoltbotConfig; sandboxed?: boolean; agentSessionKey?: string; }): AnyAgentTool[] { @@ -408,7 +408,8 @@ export function createQverisTools(options?: { const searchLimit = resolveSearchLimit(config); // Generate a session ID tied to clawdbot session key - const sessionId = options?.agentSessionKey ?? `clawdbot-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`; + const sessionId = + options?.agentSessionKey ?? `clawdbot-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`; const searchTool: AnyAgentTool = { label: "QVeris Search", @@ -508,9 +509,12 @@ export function createQverisTools(options?: { * Check if QVeris tools are enabled/available */ export function isQverisEnabled(options?: { - config?: ClawdbotConfig; + config?: MoltbotConfig; sandboxed?: boolean; }): boolean { const config = resolveQverisConfig(options?.config); - return resolveQverisEnabled({ config, sandboxed: options?.sandboxed }) && Boolean(resolveQverisApiKey(config)); + return ( + resolveQverisEnabled({ config, sandboxed: options?.sandboxed }) && + Boolean(resolveQverisApiKey(config)) + ); } diff --git a/src/feishu/accounts.ts b/src/feishu/accounts.ts index 514163b16..21e50f39a 100644 --- a/src/feishu/accounts.ts +++ b/src/feishu/accounts.ts @@ -1,4 +1,4 @@ -import type { ClawdbotConfig } from "../config/config.js"; +import type { MoltbotConfig } from "../config/config.js"; import type { FeishuAccountConfig } from "../config/types.feishu.js"; import { isTruthyEnvValue } from "../infra/env.js"; import { listBoundAccountIds, resolveDefaultAgentBoundAccountId } from "../routing/bindings.js"; @@ -19,7 +19,7 @@ export type ResolvedFeishuAccount = { config: FeishuAccountConfig; }; -function listConfiguredAccountIds(cfg: ClawdbotConfig): string[] { +function listConfiguredAccountIds(cfg: MoltbotConfig): string[] { const accounts = cfg.channels?.feishu?.accounts; if (!accounts || typeof accounts !== "object") return []; const ids = new Set(); @@ -30,7 +30,7 @@ function listConfiguredAccountIds(cfg: ClawdbotConfig): string[] { return [...ids]; } -export function listFeishuAccountIds(cfg: ClawdbotConfig): string[] { +export function listFeishuAccountIds(cfg: MoltbotConfig): string[] { const ids = Array.from( new Set([...listConfiguredAccountIds(cfg), ...listBoundAccountIds(cfg, "feishu")]), ); @@ -39,7 +39,7 @@ export function listFeishuAccountIds(cfg: ClawdbotConfig): string[] { return ids.sort((a, b) => a.localeCompare(b)); } -export function resolveDefaultFeishuAccountId(cfg: ClawdbotConfig): string { +export function resolveDefaultFeishuAccountId(cfg: MoltbotConfig): string { const boundDefault = resolveDefaultAgentBoundAccountId(cfg, "feishu"); if (boundDefault) return boundDefault; const ids = listFeishuAccountIds(cfg); @@ -48,7 +48,7 @@ export function resolveDefaultFeishuAccountId(cfg: ClawdbotConfig): string { } function resolveAccountConfig( - cfg: ClawdbotConfig, + cfg: MoltbotConfig, accountId: string, ): FeishuAccountConfig | undefined { const accounts = cfg.channels?.feishu?.accounts; @@ -60,7 +60,7 @@ function resolveAccountConfig( return matchKey ? (accounts[matchKey] as FeishuAccountConfig | undefined) : undefined; } -function mergeFeishuAccountConfig(cfg: ClawdbotConfig, accountId: string): FeishuAccountConfig { +function mergeFeishuAccountConfig(cfg: MoltbotConfig, accountId: string): FeishuAccountConfig { const { accounts: _ignored, ...base } = (cfg.channels?.feishu ?? {}) as FeishuAccountConfig & { accounts?: unknown; }; @@ -69,7 +69,7 @@ function mergeFeishuAccountConfig(cfg: ClawdbotConfig, accountId: string): Feish } export function resolveFeishuAccount(params: { - cfg: ClawdbotConfig; + cfg: MoltbotConfig; accountId?: string | null; }): ResolvedFeishuAccount { const hasExplicitAccountId = Boolean(params.accountId?.trim()); @@ -108,7 +108,7 @@ export function resolveFeishuAccount(params: { return fallback; } -export function listEnabledFeishuAccounts(cfg: ClawdbotConfig): ResolvedFeishuAccount[] { +export function listEnabledFeishuAccounts(cfg: MoltbotConfig): ResolvedFeishuAccount[] { return listFeishuAccountIds(cfg) .map((accountId) => resolveFeishuAccount({ cfg, accountId })) .filter((account) => account.enabled); diff --git a/src/feishu/bot.ts b/src/feishu/bot.ts index 3ebe2774d..97d512c12 100644 --- a/src/feishu/bot.ts +++ b/src/feishu/bot.ts @@ -4,7 +4,7 @@ * Processes incoming messages and generates responses using the agent system. */ -import type { ClawdbotConfig } from "../config/config.js"; +import type { MoltbotConfig } from "../config/config.js"; import { loadConfig } from "../config/config.js"; import { resolveDefaultAgentId } from "../agents/agent-scope.js"; import { DEFAULT_GROUP_HISTORY_LIMIT, type HistoryEntry } from "../auto-reply/reply/history.js"; @@ -22,7 +22,7 @@ import type { FeishuMessageContext } from "./monitor.js"; export type FeishuBotOptions = { accountId?: string; runtime?: RuntimeEnv; - config?: ClawdbotConfig; + config?: MoltbotConfig; /** Whether to require @mention in group chats */ requireMention?: boolean; /** Allowlist for DM senders */ @@ -42,7 +42,7 @@ export type FeishuBotContext = { export class FeishuBot { readonly account: ResolvedFeishuAccount; readonly client: FeishuClient; - readonly cfg: ClawdbotConfig; + readonly cfg: MoltbotConfig; readonly runtime: RuntimeEnv; private readonly historyLimit: number; @@ -276,7 +276,7 @@ export function buildFeishuSessionKey(params: { agentId?: string; chatId: string; chatType: "p2p" | "group"; - cfg?: ClawdbotConfig; + cfg?: MoltbotConfig; }): string { const cfg = params.cfg ?? loadConfig(); const agentId = params.agentId ?? resolveDefaultAgentId(cfg); diff --git a/src/feishu/message-dispatch.ts b/src/feishu/message-dispatch.ts index 069dc410e..937df3ca1 100644 --- a/src/feishu/message-dispatch.ts +++ b/src/feishu/message-dispatch.ts @@ -5,7 +5,7 @@ * similar to how Telegram messages are handled. */ -import type { ClawdbotConfig } from "../config/config.js"; +import type { MoltbotConfig } from "../config/config.js"; import type { RuntimeEnv } from "../runtime.js"; import type { ResolvedFeishuAccount } from "./accounts.js"; import type { FeishuMessageContext } from "./monitor.js"; @@ -32,7 +32,7 @@ const feishuMessageDedupe = createDedupeCache({ export type DispatchFeishuMessageParams = { ctx: FeishuMessageContext; - cfg: ClawdbotConfig; + cfg: MoltbotConfig; runtime?: RuntimeEnv; account: ResolvedFeishuAccount; }; @@ -49,7 +49,7 @@ function buildFeishuPeerId(chatId: string, threadId?: string): string { */ function isFeishuSenderAllowed( ctx: FeishuMessageContext, - cfg: ClawdbotConfig, + cfg: MoltbotConfig, account: ResolvedFeishuAccount, ): { allowed: boolean; reason?: string } { const isGroup = ctx.chatType === "group"; @@ -104,7 +104,7 @@ function isFeishuSenderAllowed( */ function requiresFeishuMention( ctx: FeishuMessageContext, - cfg: ClawdbotConfig, + cfg: MoltbotConfig, account: ResolvedFeishuAccount, ): boolean { if (ctx.chatType !== "group") return false; diff --git a/src/feishu/monitor.ts b/src/feishu/monitor.ts index 5878c4dc2..357d609fb 100644 --- a/src/feishu/monitor.ts +++ b/src/feishu/monitor.ts @@ -9,7 +9,7 @@ import { createServer, type IncomingMessage, type ServerResponse } from "node:http"; import os from "node:os"; -import type { ClawdbotConfig } from "../config/config.js"; +import type { MoltbotConfig } from "../config/config.js"; import { loadConfig } from "../config/config.js"; import { computeBackoff, sleepWithAbort } from "../infra/backoff.js"; import { formatErrorMessage } from "../infra/errors.js"; @@ -31,7 +31,7 @@ import { resolveFeishuEncryptKey, resolveFeishuVerificationToken } from "./token export type MonitorFeishuOpts = { accountId?: string; - config?: ClawdbotConfig; + config?: MoltbotConfig; runtime?: RuntimeEnv; abortSignal?: AbortSignal; /** Override event mode (webhook or websocket) */ @@ -59,7 +59,7 @@ export type FeishuMessageContext = { threadId?: string; client: FeishuClient; account: ResolvedFeishuAccount; - cfg: ClawdbotConfig; + cfg: MoltbotConfig; runtime?: RuntimeEnv; /** Reply to this message */ reply: (text: string) => Promise; @@ -97,7 +97,7 @@ function createMessageContext( event: FeishuMessageReceiveEvent, client: FeishuClient, account: ResolvedFeishuAccount, - cfg: ClawdbotConfig, + cfg: MoltbotConfig, runtime?: RuntimeEnv, ): FeishuMessageContext { const msg = event.event.message; diff --git a/src/feishu/send.ts b/src/feishu/send.ts index 562ae83e8..bbb3f3889 100644 --- a/src/feishu/send.ts +++ b/src/feishu/send.ts @@ -2,7 +2,7 @@ * Feishu message sending utilities */ -import type { ClawdbotConfig } from "../config/config.js"; +import type { MoltbotConfig } from "../config/config.js"; import { loadConfig } from "../config/config.js"; import { formatErrorMessage } from "../infra/errors.js"; import type { RuntimeEnv } from "../runtime.js"; @@ -17,7 +17,7 @@ export type SendFeishuMessageParams = { to: string; text: string; accountId?: string | null; - config?: ClawdbotConfig; + config?: MoltbotConfig; runtime?: RuntimeEnv; /** Receive ID type: chat_id (default), open_id, user_id, union_id, email */ receiveIdType?: "chat_id" | "open_id" | "user_id" | "union_id" | "email"; @@ -118,7 +118,7 @@ export async function reactMessageFeishu(params: { messageId: string; emoji: string; accountId?: string | null; - config?: ClawdbotConfig; + config?: MoltbotConfig; runtime?: RuntimeEnv; }): Promise<{ success: boolean; error?: string }> { const cfg = params.config ?? loadConfig(); @@ -160,7 +160,7 @@ export async function reactMessageFeishu(params: { export async function deleteMessageFeishu(params: { messageId: string; accountId?: string | null; - config?: ClawdbotConfig; + config?: MoltbotConfig; runtime?: RuntimeEnv; }): Promise<{ success: boolean; error?: string }> { const cfg = params.config ?? loadConfig(); @@ -195,7 +195,7 @@ export async function editMessageFeishu(params: { messageId: string; text: string; accountId?: string | null; - config?: ClawdbotConfig; + config?: MoltbotConfig; runtime?: RuntimeEnv; msgType?: "text" | "post"; postContent?: FeishuPostContent; diff --git a/src/feishu/token.ts b/src/feishu/token.ts index 7d22d4336..0c38654b5 100644 --- a/src/feishu/token.ts +++ b/src/feishu/token.ts @@ -1,6 +1,6 @@ import fs from "node:fs"; -import type { ClawdbotConfig } from "../config/config.js"; +import type { MoltbotConfig } from "../config/config.js"; import type { FeishuAccountConfig } from "../config/types.feishu.js"; import { resolveUserPath } from "../utils.js"; @@ -13,7 +13,7 @@ export type FeishuCredentials = { }; function resolveAccountConfig( - cfg: ClawdbotConfig, + cfg: MoltbotConfig, accountId: string, ): FeishuAccountConfig | undefined { const accounts = cfg.channels?.feishu?.accounts; @@ -25,7 +25,7 @@ function resolveAccountConfig( return matchKey ? (accounts[matchKey] as FeishuAccountConfig | undefined) : undefined; } -function mergeFeishuAccountConfig(cfg: ClawdbotConfig, accountId: string): FeishuAccountConfig { +function mergeFeishuAccountConfig(cfg: MoltbotConfig, accountId: string): FeishuAccountConfig { const { accounts: _ignored, ...base } = (cfg.channels?.feishu ?? {}) as FeishuAccountConfig & { accounts?: unknown; }; @@ -44,7 +44,7 @@ function readSecretFile(filePath: string): string | undefined { } export function resolveFeishuCredentials( - cfg: ClawdbotConfig, + cfg: MoltbotConfig, opts?: { accountId?: string | null }, ): FeishuCredentials { const accountId = opts?.accountId?.trim() || "default"; @@ -74,7 +74,7 @@ export function resolveFeishuCredentials( } export function resolveFeishuVerificationToken( - cfg: ClawdbotConfig, + cfg: MoltbotConfig, opts?: { accountId?: string | null }, ): string | undefined { const accountId = opts?.accountId?.trim() || "default"; @@ -88,7 +88,7 @@ export function resolveFeishuVerificationToken( } export function resolveFeishuEncryptKey( - cfg: ClawdbotConfig, + cfg: MoltbotConfig, opts?: { accountId?: string | null }, ): string | undefined { const accountId = opts?.accountId?.trim() || "default";