cc工作前备份
This commit is contained in:
211
plugins/zclaw-chinese-models/index.ts
Normal file
211
plugins/zclaw-chinese-models/index.ts
Normal file
@@ -0,0 +1,211 @@
|
||||
/**
|
||||
* ZCLAW Chinese Models Plugin
|
||||
*
|
||||
* Registers Chinese AI model providers for OpenClaw Gateway:
|
||||
* - Zhipu GLM (智谱)
|
||||
* - Qwen (通义千问)
|
||||
* - Kimi (月之暗面)
|
||||
* - MiniMax
|
||||
*
|
||||
* All providers use OpenAI-compatible API format.
|
||||
*/
|
||||
|
||||
interface PluginAPI {
|
||||
config: Record<string, any>;
|
||||
registerProvider(provider: ProviderDefinition): void;
|
||||
registerHook(event: string, handler: (...args: any[]) => any, meta?: Record<string, any>): void;
|
||||
}
|
||||
|
||||
interface ProviderDefinition {
|
||||
id: string;
|
||||
name: string;
|
||||
baseUrl: string;
|
||||
apiKeyEnvVar?: string;
|
||||
models: ProviderModel[];
|
||||
headers?: (apiKey: string) => Record<string, string>;
|
||||
}
|
||||
|
||||
interface ProviderModel {
|
||||
id: string;
|
||||
alias?: string;
|
||||
contextWindow?: number;
|
||||
maxOutputTokens?: number;
|
||||
supportsVision?: boolean;
|
||||
supportsStreaming?: boolean;
|
||||
}
|
||||
|
||||
// 智谱 GLM Provider
|
||||
const zhipuProvider: ProviderDefinition = {
|
||||
id: 'zhipu',
|
||||
name: 'Zhipu AI (智谱)',
|
||||
baseUrl: 'https://open.bigmodel.cn/api/paas/v4',
|
||||
apiKeyEnvVar: 'ZHIPU_API_KEY',
|
||||
models: [
|
||||
{
|
||||
id: 'glm-5',
|
||||
alias: 'GLM-5',
|
||||
contextWindow: 128000,
|
||||
maxOutputTokens: 4096,
|
||||
supportsVision: true,
|
||||
supportsStreaming: true,
|
||||
},
|
||||
{
|
||||
id: 'glm-4.7',
|
||||
alias: 'GLM-4.7',
|
||||
contextWindow: 128000,
|
||||
maxOutputTokens: 4096,
|
||||
supportsVision: true,
|
||||
supportsStreaming: true,
|
||||
},
|
||||
{
|
||||
id: 'glm-4-plus',
|
||||
alias: 'GLM-4-Plus',
|
||||
contextWindow: 128000,
|
||||
maxOutputTokens: 4096,
|
||||
supportsVision: false,
|
||||
supportsStreaming: true,
|
||||
},
|
||||
{
|
||||
id: 'glm-4-flash',
|
||||
alias: 'GLM-4-Flash',
|
||||
contextWindow: 128000,
|
||||
maxOutputTokens: 4096,
|
||||
supportsVision: false,
|
||||
supportsStreaming: true,
|
||||
},
|
||||
],
|
||||
headers: (apiKey: string) => ({
|
||||
'Authorization': `Bearer ${apiKey}`,
|
||||
'Content-Type': 'application/json',
|
||||
}),
|
||||
};
|
||||
|
||||
// 通义千问 Provider (OpenAI-compatible via DashScope)
|
||||
const qwenProvider: ProviderDefinition = {
|
||||
id: 'qwen',
|
||||
name: 'Qwen (通义千问)',
|
||||
baseUrl: 'https://dashscope.aliyuncs.com/compatible-mode/v1',
|
||||
apiKeyEnvVar: 'QWEN_API_KEY',
|
||||
models: [
|
||||
{
|
||||
id: 'qwen3.5-plus',
|
||||
alias: 'Qwen3.5+',
|
||||
contextWindow: 131072,
|
||||
maxOutputTokens: 8192,
|
||||
supportsVision: false,
|
||||
supportsStreaming: true,
|
||||
},
|
||||
{
|
||||
id: 'qwen-max',
|
||||
alias: 'Qwen-Max',
|
||||
contextWindow: 32768,
|
||||
maxOutputTokens: 8192,
|
||||
supportsVision: false,
|
||||
supportsStreaming: true,
|
||||
},
|
||||
{
|
||||
id: 'qwen-vl-max',
|
||||
alias: 'Qwen-VL-Max',
|
||||
contextWindow: 32768,
|
||||
maxOutputTokens: 4096,
|
||||
supportsVision: true,
|
||||
supportsStreaming: true,
|
||||
},
|
||||
],
|
||||
headers: (apiKey: string) => ({
|
||||
'Authorization': `Bearer ${apiKey}`,
|
||||
'Content-Type': 'application/json',
|
||||
}),
|
||||
};
|
||||
|
||||
// Kimi (月之暗面) Provider
|
||||
const kimiProvider: ProviderDefinition = {
|
||||
id: 'kimi',
|
||||
name: 'Kimi (月之暗面)',
|
||||
baseUrl: 'https://api.moonshot.cn/v1',
|
||||
apiKeyEnvVar: 'KIMI_API_KEY',
|
||||
models: [
|
||||
{
|
||||
id: 'kimi-k2.5',
|
||||
alias: 'Kimi-K2.5',
|
||||
contextWindow: 131072,
|
||||
maxOutputTokens: 8192,
|
||||
supportsVision: false,
|
||||
supportsStreaming: true,
|
||||
},
|
||||
{
|
||||
id: 'moonshot-v1-128k',
|
||||
alias: 'Moonshot-128K',
|
||||
contextWindow: 128000,
|
||||
maxOutputTokens: 4096,
|
||||
supportsVision: false,
|
||||
supportsStreaming: true,
|
||||
},
|
||||
],
|
||||
headers: (apiKey: string) => ({
|
||||
'Authorization': `Bearer ${apiKey}`,
|
||||
'Content-Type': 'application/json',
|
||||
}),
|
||||
};
|
||||
|
||||
// MiniMax Provider
|
||||
const minimaxProvider: ProviderDefinition = {
|
||||
id: 'minimax',
|
||||
name: 'MiniMax',
|
||||
baseUrl: 'https://api.minimax.chat/v1',
|
||||
apiKeyEnvVar: 'MINIMAX_API_KEY',
|
||||
models: [
|
||||
{
|
||||
id: 'minimax-m2.5',
|
||||
alias: 'MiniMax-M2.5',
|
||||
contextWindow: 245760,
|
||||
maxOutputTokens: 16384,
|
||||
supportsVision: false,
|
||||
supportsStreaming: true,
|
||||
},
|
||||
{
|
||||
id: 'abab6.5s-chat',
|
||||
alias: 'ABAB-6.5s',
|
||||
contextWindow: 245760,
|
||||
maxOutputTokens: 8192,
|
||||
supportsVision: false,
|
||||
supportsStreaming: true,
|
||||
},
|
||||
],
|
||||
headers: (apiKey: string) => ({
|
||||
'Authorization': `Bearer ${apiKey}`,
|
||||
'Content-Type': 'application/json',
|
||||
}),
|
||||
};
|
||||
|
||||
/**
|
||||
* Plugin entry point - registers all Chinese model providers
|
||||
*/
|
||||
export default function register(api: PluginAPI) {
|
||||
const pluginConfig = api.config?.plugins?.entries?.['zclaw-chinese-models']?.config ?? {};
|
||||
|
||||
// Register Zhipu GLM
|
||||
const zhipu = { ...zhipuProvider };
|
||||
if (pluginConfig.zhipuBaseUrl) zhipu.baseUrl = pluginConfig.zhipuBaseUrl;
|
||||
api.registerProvider(zhipu);
|
||||
|
||||
// Register Qwen
|
||||
const qwen = { ...qwenProvider };
|
||||
if (pluginConfig.qwenBaseUrl) qwen.baseUrl = pluginConfig.qwenBaseUrl;
|
||||
api.registerProvider(qwen);
|
||||
|
||||
// Register Kimi
|
||||
const kimi = { ...kimiProvider };
|
||||
if (pluginConfig.kimiBaseUrl) kimi.baseUrl = pluginConfig.kimiBaseUrl;
|
||||
api.registerProvider(kimi);
|
||||
|
||||
// Register MiniMax
|
||||
const minimax = { ...minimaxProvider };
|
||||
if (pluginConfig.minimaxBaseUrl) minimax.baseUrl = pluginConfig.minimaxBaseUrl;
|
||||
api.registerProvider(minimax);
|
||||
|
||||
// Log registration
|
||||
api.registerHook('gateway:startup', async () => {
|
||||
console.log('[ZCLAW] Chinese model providers registered: zhipu, qwen, kimi, minimax');
|
||||
}, { name: 'zclaw-chinese-models.startup', description: 'Log provider registration on startup' });
|
||||
}
|
||||
32
plugins/zclaw-chinese-models/plugin.json
Normal file
32
plugins/zclaw-chinese-models/plugin.json
Normal file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"id": "zclaw-chinese-models",
|
||||
"name": "ZCLAW Chinese Models",
|
||||
"version": "0.1.0",
|
||||
"description": "Chinese AI model providers for ZCLAW: Zhipu GLM, Qwen, Kimi, MiniMax",
|
||||
"author": "ZCLAW",
|
||||
"entry": "index.ts",
|
||||
"configSchema": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"zhipuApiKey": { "type": "string" },
|
||||
"zhipuBaseUrl": { "type": "string" },
|
||||
"qwenApiKey": { "type": "string" },
|
||||
"qwenBaseUrl": { "type": "string" },
|
||||
"kimiApiKey": { "type": "string" },
|
||||
"kimiBaseUrl": { "type": "string" },
|
||||
"minimaxApiKey": { "type": "string" },
|
||||
"minimaxBaseUrl": { "type": "string" }
|
||||
}
|
||||
},
|
||||
"uiHints": {
|
||||
"zhipuApiKey": { "label": "智谱 API Key", "sensitive": true },
|
||||
"zhipuBaseUrl": { "label": "智谱 Base URL", "placeholder": "https://open.bigmodel.cn/api/paas/v4" },
|
||||
"qwenApiKey": { "label": "通义千问 API Key", "sensitive": true },
|
||||
"qwenBaseUrl": { "label": "通义千问 Base URL", "placeholder": "https://dashscope.aliyuncs.com/compatible-mode/v1" },
|
||||
"kimiApiKey": { "label": "Kimi API Key", "sensitive": true },
|
||||
"kimiBaseUrl": { "label": "Kimi Base URL", "placeholder": "https://api.moonshot.cn/v1" },
|
||||
"minimaxApiKey": { "label": "MiniMax API Key", "sensitive": true },
|
||||
"minimaxBaseUrl": { "label": "MiniMax Base URL", "placeholder": "https://api.minimax.chat/v1" }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user