refactor(plugins): finish provider and whatsapp cleanup

This commit is contained in:
Vincent Koc
2026-03-22 19:13:14 -07:00
parent 2131981230
commit 042669d8c8
22 changed files with 156 additions and 1396 deletions

View File

@@ -4,10 +4,12 @@ import byteplusPlugin from "../../../extensions/byteplus/index.js";
import chutesPlugin from "../../../extensions/chutes/index.js";
import cloudflareAiGatewayPlugin from "../../../extensions/cloudflare-ai-gateway/index.js";
import copilotProxyPlugin from "../../../extensions/copilot-proxy/index.js";
import deepgramPlugin from "../../../extensions/deepgram/index.js";
import elevenLabsPlugin from "../../../extensions/elevenlabs/index.js";
import falPlugin from "../../../extensions/fal/index.js";
import githubCopilotPlugin from "../../../extensions/github-copilot/index.js";
import googlePlugin from "../../../extensions/google/index.js";
import groqPlugin from "../../../extensions/groq/index.js";
import huggingFacePlugin from "../../../extensions/huggingface/index.js";
import kilocodePlugin from "../../../extensions/kilocode/index.js";
import kimiCodingPlugin from "../../../extensions/kimi-coding/index.js";
@@ -36,7 +38,7 @@ import xiaomiPlugin from "../../../extensions/xiaomi/index.js";
import zaiPlugin from "../../../extensions/zai/index.js";
import { bundledWebSearchPluginRegistrations } from "../../bundled-web-search-registry.js";
import { createCapturedPluginRegistration } from "../captured-registration.js";
import { resolvePluginProviders } from "../providers.runtime.js";
import { resolvePluginProviders } from "../providers.js";
import type {
ImageGenerationProviderPlugin,
MediaUnderstandingProviderPlugin,
@@ -85,7 +87,9 @@ const bundledSpeechPlugins: RegistrablePlugin[] = [elevenLabsPlugin, microsoftPl
const bundledMediaUnderstandingPlugins: RegistrablePlugin[] = [
anthropicPlugin,
deepgramPlugin,
googlePlugin,
groqPlugin,
minimaxPlugin,
mistralPlugin,
moonshotPlugin,

View File

@@ -1,7 +1,7 @@
import { resolveOpenClawAgentDir } from "../agents/agent-paths.js";
import { upsertAuthProfile } from "../agents/auth-profiles.js";
import type { SecretInput } from "../config/types.secrets.js";
import { KILOCODE_DEFAULT_MODEL_REF } from "../providers/kilocode-shared.js";
import { KILOCODE_DEFAULT_MODEL_REF } from "../../extensions/kilocode/shared.js";
import {
buildApiKeyCredential,
type ApiKeyStorageOptions,

View File

@@ -1,18 +1,15 @@
import type { OpenClawConfig } from "../config/config.js";
import {
OPENAI_CODEX_DEFAULT_MODEL,
OPENAI_DEFAULT_AUDIO_TRANSCRIPTION_MODEL,
OPENAI_DEFAULT_MODEL,
} from "../providers/openai-defaults.js";
import { ensureModelAllowlistEntry } from "./provider-model-allowlist.js";
import { applyAgentDefaultPrimaryModel } from "./provider-model-primary.js";
export const OPENAI_DEFAULT_MODEL = "openai/gpt-5.4";
export const OPENAI_CODEX_DEFAULT_MODEL = "openai-codex/gpt-5.4";
export const OPENAI_DEFAULT_IMAGE_MODEL = "gpt-image-1";
export const OPENAI_DEFAULT_TTS_MODEL = "gpt-4o-mini-tts";
export const OPENAI_DEFAULT_TTS_VOICE = "alloy";
export const OPENAI_DEFAULT_AUDIO_TRANSCRIPTION_MODEL = "gpt-4o-mini-transcribe";
export const OPENAI_DEFAULT_EMBEDDING_MODEL = "text-embedding-3-small";
export const GOOGLE_GEMINI_DEFAULT_MODEL = "google/gemini-3.1-pro-preview";
export {
OPENAI_CODEX_DEFAULT_MODEL,
OPENAI_DEFAULT_AUDIO_TRANSCRIPTION_MODEL,
OPENAI_DEFAULT_MODEL,
} from "../providers/openai-defaults.js";
export const OPENCODE_GO_DEFAULT_MODEL_REF = "opencode-go/kimi-k2.5";
export const OPENCODE_ZEN_DEFAULT_MODEL = "opencode/claude-opus-4-6";

View File

@@ -5,7 +5,7 @@ import {
KILOCODE_DEFAULT_MAX_TOKENS,
KILOCODE_DEFAULT_MODEL_ID,
KILOCODE_DEFAULT_MODEL_NAME,
} from "../providers/kilocode-shared.js";
} from "../../extensions/kilocode/shared.js";
const KIMI_CODING_BASE_URL = "https://api.kimi.com/coding/";
const KIMI_CODING_MODEL_ID = "kimi-code";
@@ -16,15 +16,12 @@ const MINIMAX_API_BASE_URL = "https://api.minimax.io/anthropic";
const MINIMAX_CN_API_BASE_URL = "https://api.minimaxi.com/anthropic";
const MINIMAX_HOSTED_MODEL_ID = "MiniMax-M2.7";
const MINIMAX_HOSTED_MODEL_REF = `minimax/${MINIMAX_HOSTED_MODEL_ID}`;
const DEFAULT_MINIMAX_CONTEXT_WINDOW = 204800;
const DEFAULT_MINIMAX_MAX_TOKENS = 131072;
const MINIMAX_API_COST = { input: 0.3, output: 1.2, cacheRead: 0.06, cacheWrite: 0.375 };
const DEFAULT_MINIMAX_CONTEXT_WINDOW = 200000;
const DEFAULT_MINIMAX_MAX_TOKENS = 8192;
const MINIMAX_API_COST = { input: 0.3, output: 1.2, cacheRead: 0.03, cacheWrite: 0.12 };
const MINIMAX_HOSTED_COST = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 };
const MINIMAX_LM_STUDIO_COST = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 };
const MINIMAX_MODEL_CATALOG = {
"MiniMax-M2": { name: "MiniMax M2", reasoning: true },
"MiniMax-M2.1": { name: "MiniMax M2.1", reasoning: true },
"MiniMax-M2.1-highspeed": { name: "MiniMax M2.1 Highspeed", reasoning: true },
"MiniMax-M2.7": { name: "MiniMax M2.7", reasoning: true },
"MiniMax-M2.7-highspeed": { name: "MiniMax M2.7 Highspeed", reasoning: true },
"MiniMax-M2.5": { name: "MiniMax M2.5", reasoning: true },
@@ -36,7 +33,7 @@ const MISTRAL_DEFAULT_MODEL_ID = "mistral-large-latest";
const MISTRAL_DEFAULT_MODEL_REF = `mistral/${MISTRAL_DEFAULT_MODEL_ID}`;
const MISTRAL_DEFAULT_CONTEXT_WINDOW = 262144;
const MISTRAL_DEFAULT_MAX_TOKENS = 262144;
const MISTRAL_DEFAULT_COST = { input: 0.5, output: 1.5, cacheRead: 0, cacheWrite: 0 };
const MISTRAL_DEFAULT_COST = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 };
const MODELSTUDIO_CN_BASE_URL = "https://coding.dashscope.aliyuncs.com/v1";
const MODELSTUDIO_GLOBAL_BASE_URL = "https://coding-intl.dashscope.aliyuncs.com/v1";
@@ -106,8 +103,8 @@ const MOONSHOT_BASE_URL = "https://api.moonshot.ai/v1";
const MOONSHOT_CN_BASE_URL = "https://api.moonshot.cn/v1";
const MOONSHOT_DEFAULT_MODEL_ID = "kimi-k2.5";
const MOONSHOT_DEFAULT_MODEL_REF = `moonshot/${MOONSHOT_DEFAULT_MODEL_ID}`;
const MOONSHOT_DEFAULT_CONTEXT_WINDOW = 262144;
const MOONSHOT_DEFAULT_MAX_TOKENS = 262144;
const MOONSHOT_DEFAULT_CONTEXT_WINDOW = 256000;
const MOONSHOT_DEFAULT_MAX_TOKENS = 8192;
const MOONSHOT_DEFAULT_COST = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 };
const QIANFAN_BASE_URL = "https://qianfan.baidubce.com/v2";
@@ -117,105 +114,22 @@ const QIANFAN_DEFAULT_MODEL_REF = `qianfan/${QIANFAN_DEFAULT_MODEL_ID}`;
const XAI_BASE_URL = "https://api.x.ai/v1";
const XAI_DEFAULT_MODEL_ID = "grok-4";
const XAI_DEFAULT_MODEL_REF = `xai/${XAI_DEFAULT_MODEL_ID}`;
const XAI_DEFAULT_CONTEXT_WINDOW = 256000;
const XAI_DEFAULT_MAX_TOKENS = 64000;
const XAI_DEFAULT_COST = { input: 3, output: 15, cacheRead: 0.75, cacheWrite: 0 };
const XAI_DEFAULT_CONTEXT_WINDOW = 131072;
const XAI_DEFAULT_MAX_TOKENS = 8192;
const XAI_DEFAULT_COST = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 };
const ZAI_CODING_GLOBAL_BASE_URL = "https://api.z.ai/api/coding/paas/v4";
const ZAI_CODING_CN_BASE_URL = "https://open.bigmodel.cn/api/coding/paas/v4";
const ZAI_GLOBAL_BASE_URL = "https://api.z.ai/api/paas/v4";
const ZAI_CN_BASE_URL = "https://open.bigmodel.cn/api/paas/v4";
const ZAI_DEFAULT_MODEL_ID = "glm-5";
const ZAI_DEFAULT_COST = { input: 1, output: 3.2, cacheRead: 0.2, cacheWrite: 0 };
const ZAI_DEFAULT_COST = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 };
const ZAI_MODEL_CATALOG = {
"glm-5": {
name: "GLM-5",
reasoning: true,
input: ["text"],
contextWindow: 204800,
maxTokens: 131072,
cost: ZAI_DEFAULT_COST,
},
"glm-5-turbo": {
name: "GLM-5 Turbo",
reasoning: true,
input: ["text"],
contextWindow: 200000,
maxTokens: 131072,
cost: { input: 1.2, output: 4, cacheRead: 0.24, cacheWrite: 0 },
},
"glm-4.7": {
name: "GLM-4.7",
reasoning: true,
input: ["text"],
contextWindow: 204800,
maxTokens: 131072,
cost: { input: 0.6, output: 2.2, cacheRead: 0.11, cacheWrite: 0 },
},
"glm-4.7-flash": {
name: "GLM-4.7 Flash",
reasoning: true,
input: ["text"],
contextWindow: 200000,
maxTokens: 131072,
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
},
"glm-4.7-flashx": {
name: "GLM-4.7 FlashX",
reasoning: true,
input: ["text"],
contextWindow: 200000,
maxTokens: 131072,
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
},
"glm-4.6": {
name: "GLM-4.6",
reasoning: true,
input: ["text"],
contextWindow: 204800,
maxTokens: 131072,
cost: { input: 0.6, output: 2.2, cacheRead: 0.11, cacheWrite: 0 },
},
"glm-4.6v": {
name: "GLM-4.6V",
reasoning: true,
input: ["text", "image"],
contextWindow: 128000,
maxTokens: 32768,
cost: { input: 0.3, output: 0.9, cacheRead: 0, cacheWrite: 0 },
},
"glm-4.5": {
name: "GLM-4.5",
reasoning: true,
input: ["text"],
contextWindow: 131072,
maxTokens: 98304,
cost: { input: 0.6, output: 2.2, cacheRead: 0.11, cacheWrite: 0 },
},
"glm-4.5-air": {
name: "GLM-4.5 Air",
reasoning: true,
input: ["text"],
contextWindow: 131072,
maxTokens: 98304,
cost: { input: 0.2, output: 1.1, cacheRead: 0.03, cacheWrite: 0 },
},
"glm-4.5-flash": {
name: "GLM-4.5 Flash",
reasoning: true,
input: ["text"],
contextWindow: 131072,
maxTokens: 98304,
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
},
"glm-4.5v": {
name: "GLM-4.5V",
reasoning: true,
input: ["text", "image"],
contextWindow: 64000,
maxTokens: 16384,
cost: { input: 0.6, output: 1.8, cacheRead: 0, cacheWrite: 0 },
},
"glm-5": { name: "GLM-5", reasoning: true },
"glm-5-turbo": { name: "GLM-5 Turbo", reasoning: true },
"glm-4.7": { name: "GLM-4.7", reasoning: true },
"glm-4.7-flash": { name: "GLM-4.7 Flash", reasoning: true },
"glm-4.7-flashx": { name: "GLM-4.7 FlashX", reasoning: true },
} as const;
function buildMinimaxModelDefinition(params: {
@@ -329,7 +243,6 @@ function buildZaiModelDefinition(params: {
id: string;
name?: string;
reasoning?: boolean;
input?: ("text" | "image")[];
cost?: ModelDefinitionConfig["cost"];
contextWindow?: number;
maxTokens?: number;
@@ -339,11 +252,10 @@ function buildZaiModelDefinition(params: {
id: params.id,
name: params.name ?? catalog?.name ?? `GLM ${params.id}`,
reasoning: params.reasoning ?? catalog?.reasoning ?? true,
input:
params.input ?? (catalog?.input ? ([...catalog.input] as ("text" | "image")[]) : ["text"]),
cost: params.cost ?? catalog?.cost ?? ZAI_DEFAULT_COST,
contextWindow: params.contextWindow ?? catalog?.contextWindow ?? 204800,
maxTokens: params.maxTokens ?? catalog?.maxTokens ?? 131072,
input: ["text"],
cost: params.cost ?? ZAI_DEFAULT_COST,
contextWindow: params.contextWindow ?? 204800,
maxTokens: params.maxTokens ?? 131072,
};
}

View File

@@ -53,9 +53,18 @@ import {
normalizeAccountId as normalizeLineAccountId,
resolveDefaultLineAccountId,
resolveLineAccount,
} from "../../line/accounts.js";
import { createQuickReplyItems } from "../../line/quick-replies.js";
import { buildTemplateMessageFromPayload } from "../../line/template-messages.js";
buildTemplateMessageFromPayload,
createQuickReplyItems,
pushFlexMessage,
pushLocationMessage,
pushMessageLine,
pushMessagesLine,
pushTemplateMessage,
pushTextMessageWithQuickReplies,
monitorLineProvider,
probeLineBot,
sendMessageLine,
} from "../../../extensions/line/runtime-api.js";
import { convertMarkdownTables } from "../../markdown/tables.js";
import { fetchRemoteMedia } from "../../media/fetch.js";
import { saveMediaBuffer } from "../../media/store.js";
@@ -65,10 +74,6 @@ import {
upsertChannelPairingRequest,
} from "../../pairing/pairing-store.js";
import { buildAgentSessionKey, resolveAgentRoute } from "../../routing/resolve-route.js";
import {
createLazyRuntimeMethodBinder,
createLazyRuntimeModule,
} from "../../shared/lazy-runtime.js";
import { createRuntimeDiscord } from "./runtime-discord.js";
import { createRuntimeIMessage } from "./runtime-imessage.js";
import { createRuntimeMatrix } from "./runtime-matrix.js";
@@ -78,8 +83,6 @@ import { createRuntimeTelegram } from "./runtime-telegram.js";
import { createRuntimeWhatsApp } from "./runtime-whatsapp.js";
import type { PluginRuntime } from "./types.js";
const loadLineRuntime = createLazyRuntimeModule(() => import("./runtime-line.runtime.js"));
function defineCachedValue<T extends object, K extends PropertyKey>(
target: T,
key: K,
@@ -101,7 +104,6 @@ function defineCachedValue<T extends object, K extends PropertyKey>(
}
export function createRuntimeChannel(): PluginRuntime["channel"] {
const bindLineRuntime = createLazyRuntimeMethodBinder(loadLineRuntime);
const channelRuntime = {
text: {
chunkByNewline,
@@ -189,19 +191,17 @@ export function createRuntimeChannel(): PluginRuntime["channel"] {
resolveDefaultLineAccountId,
resolveLineAccount,
normalizeAccountId: normalizeLineAccountId,
probeLineBot: bindLineRuntime((runtime) => runtime.probeLineBot),
sendMessageLine: bindLineRuntime((runtime) => runtime.sendMessageLine),
pushMessageLine: bindLineRuntime((runtime) => runtime.pushMessageLine),
pushMessagesLine: bindLineRuntime((runtime) => runtime.pushMessagesLine),
pushFlexMessage: bindLineRuntime((runtime) => runtime.pushFlexMessage),
pushTemplateMessage: bindLineRuntime((runtime) => runtime.pushTemplateMessage),
pushLocationMessage: bindLineRuntime((runtime) => runtime.pushLocationMessage),
pushTextMessageWithQuickReplies: bindLineRuntime(
(runtime) => runtime.pushTextMessageWithQuickReplies,
),
probeLineBot,
sendMessageLine,
pushMessageLine,
pushMessagesLine,
pushFlexMessage,
pushTemplateMessage,
pushLocationMessage,
pushTextMessageWithQuickReplies,
createQuickReplyItems,
buildTemplateMessageFromPayload,
monitorLineProvider: bindLineRuntime((runtime) => runtime.monitorLineProvider),
monitorLineProvider,
},
} satisfies Omit<
PluginRuntime["channel"],

View File

@@ -178,9 +178,14 @@ export type PluginRuntimeChannel = {
clearReplyMarkup: (
chatIdInput: string | number,
messageIdInput: string | number,
opts?: Parameters<
typeof import("../../plugin-sdk/telegram.js").editMessageReplyMarkupTelegram
>[3],
opts?: {
token?: string;
accountId?: string;
verbose?: boolean;
api?: Partial<import("grammy").Bot["api"]>;
retry?: import("../../infra/retry.js").RetryConfig;
cfg?: ReturnType<typeof import("../../config/config.js").loadConfig>;
},
) => Promise<{ ok: true; messageId: string; chatId: string }>;
deleteMessage: typeof import("../../plugin-sdk/telegram.js").deleteMessageTelegram;
renameTopic: typeof import("../../plugin-sdk/telegram.js").renameForumTopicTelegram;
@@ -222,20 +227,28 @@ export type PluginRuntimeChannel = {
createLoginTool: typeof import("./runtime-whatsapp-login-tool.js").createRuntimeWhatsAppLoginTool;
};
line: {
listLineAccountIds: typeof import("../../line/accounts.js").listLineAccountIds;
resolveDefaultLineAccountId: typeof import("../../line/accounts.js").resolveDefaultLineAccountId;
resolveLineAccount: typeof import("../../line/accounts.js").resolveLineAccount;
normalizeAccountId: typeof import("../../line/accounts.js").normalizeAccountId;
probeLineBot: typeof import("../../line/probe.js").probeLineBot;
sendMessageLine: typeof import("../../line/send.js").sendMessageLine;
pushMessageLine: typeof import("../../line/send.js").pushMessageLine;
pushMessagesLine: typeof import("../../line/send.js").pushMessagesLine;
pushFlexMessage: typeof import("../../line/send.js").pushFlexMessage;
pushTemplateMessage: typeof import("../../line/send.js").pushTemplateMessage;
pushLocationMessage: typeof import("../../line/send.js").pushLocationMessage;
pushTextMessageWithQuickReplies: typeof import("../../line/send.js").pushTextMessageWithQuickReplies;
createQuickReplyItems: typeof import("../../line/send.js").createQuickReplyItems;
buildTemplateMessageFromPayload: typeof import("../../line/template-messages.js").buildTemplateMessageFromPayload;
monitorLineProvider: typeof import("../../line/monitor.js").monitorLineProvider;
listLineAccountIds: typeof import("../../../extensions/line/runtime-api.js").listLineAccountIds;
resolveDefaultLineAccountId: typeof import(
"../../../extensions/line/runtime-api.js"
).resolveDefaultLineAccountId;
resolveLineAccount: typeof import("../../../extensions/line/runtime-api.js").resolveLineAccount;
normalizeAccountId: typeof import("../../../extensions/line/runtime-api.js").normalizeAccountId;
probeLineBot: typeof import("../../../extensions/line/runtime-api.js").probeLineBot;
sendMessageLine: typeof import("../../../extensions/line/runtime-api.js").sendMessageLine;
pushMessageLine: typeof import("../../../extensions/line/runtime-api.js").pushMessageLine;
pushMessagesLine: typeof import("../../../extensions/line/runtime-api.js").pushMessagesLine;
pushFlexMessage: typeof import("../../../extensions/line/runtime-api.js").pushFlexMessage;
pushTemplateMessage: typeof import("../../../extensions/line/runtime-api.js").pushTemplateMessage;
pushLocationMessage: typeof import("../../../extensions/line/runtime-api.js").pushLocationMessage;
pushTextMessageWithQuickReplies: typeof import(
"../../../extensions/line/runtime-api.js"
).pushTextMessageWithQuickReplies;
createQuickReplyItems: typeof import(
"../../../extensions/line/runtime-api.js"
).createQuickReplyItems;
buildTemplateMessageFromPayload: typeof import(
"../../../extensions/line/runtime-api.js"
).buildTemplateMessageFromPayload;
monitorLineProvider: typeof import("../../../extensions/line/runtime-api.js").monitorLineProvider;
};
};