@honor-claw/yoyo 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -6,6 +6,7 @@ import type { OpenClawConfig } from "openclaw/plugin-sdk";
|
|
|
6
6
|
import { getYoyoRuntime } from "../../runtime.js";
|
|
7
7
|
import { isBetaVersion } from "../../utils/version.js";
|
|
8
8
|
import type { GatewayAuthConfig, UserConfig } from "./types.js";
|
|
9
|
+
import { detectProvidersToRename, updateProviderReferences } from "./provider.js";
|
|
9
10
|
|
|
10
11
|
const PLUGIN_YOYO_ID = "yoyo";
|
|
11
12
|
const YOYO_ALLOW_COMMANDS = ["mobile-data", "hotspot", "volume.operate", "no-disturb", "screen-record", "quiet-mode", "ringing-mode", "vibration-mode", "capture-screenshot", "app.open", "app.close", "contact.search", "call.phone", "message.send", "local-search", "alarm.create"]
|
|
@@ -324,8 +325,17 @@ export class ConfigManager {
|
|
|
324
325
|
? { ...pluginConfig, env: defaultEnv }
|
|
325
326
|
: pluginConfig;
|
|
326
327
|
|
|
327
|
-
//
|
|
328
|
-
const
|
|
328
|
+
// 检测并重命名包含"minimax"的provider
|
|
329
|
+
const renameMap = detectProvidersToRename(currentConfig);
|
|
330
|
+
if (Object.keys(renameMap).length > 0) {
|
|
331
|
+
console.log(
|
|
332
|
+
`[claw-configs] Found ${Object.keys(renameMap).length} providers to rename:`,
|
|
333
|
+
Object.entries(renameMap).map(([old, newName]) => `${old} -> ${newName}`).join(", ")
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// 一次性更新所有配置(包括provider重命名)
|
|
338
|
+
let updatedConfig: OpenClawConfig = {
|
|
329
339
|
...currentConfig,
|
|
330
340
|
plugins: {
|
|
331
341
|
...currentConfig.plugins,
|
|
@@ -348,6 +358,12 @@ export class ConfigManager {
|
|
|
348
358
|
},
|
|
349
359
|
};
|
|
350
360
|
|
|
361
|
+
// 如果需要重命名provider,更新所有引用
|
|
362
|
+
if (Object.keys(renameMap).length > 0) {
|
|
363
|
+
updatedConfig = updateProviderReferences(updatedConfig, renameMap);
|
|
364
|
+
console.log("[claw-configs] Provider renaming completed");
|
|
365
|
+
}
|
|
366
|
+
|
|
351
367
|
await this.saveConfig(updatedConfig);
|
|
352
368
|
} catch (error) {
|
|
353
369
|
throw new Error(
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import type { OpenClawConfig } from "openclaw/plugin-sdk";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 检测需要改名的provider
|
|
5
|
+
*/
|
|
6
|
+
export function detectProvidersToRename(config: OpenClawConfig): Record<string, string> {
|
|
7
|
+
const renameMap: Record<string, string> = {};
|
|
8
|
+
|
|
9
|
+
if (!config.models?.providers) {
|
|
10
|
+
return renameMap;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const providers = Object.keys(config.models.providers);
|
|
14
|
+
for (const provider of providers) {
|
|
15
|
+
const lowerProvider = provider.trim().toLowerCase();
|
|
16
|
+
if (lowerProvider.includes("minimax")) {
|
|
17
|
+
// 使用下划线分隔:minimax -> mini_max, minimax-pro -> mini_max-pro
|
|
18
|
+
const newName = lowerProvider.replace("minimax", "mini_max");
|
|
19
|
+
renameMap[provider] = newName;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return renameMap;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 更新所有provider引用
|
|
28
|
+
*/
|
|
29
|
+
export function updateProviderReferences(
|
|
30
|
+
config: OpenClawConfig,
|
|
31
|
+
renameMap: Record<string, string>
|
|
32
|
+
): OpenClawConfig {
|
|
33
|
+
const updatedConfig = { ...config };
|
|
34
|
+
|
|
35
|
+
// 1. 更新 models.providers 本身
|
|
36
|
+
if (updatedConfig.models?.providers) {
|
|
37
|
+
const newProviders: Record<string, any> = {};
|
|
38
|
+
for (const [provider, providerConfig] of Object.entries(updatedConfig.models.providers)) {
|
|
39
|
+
const newName = renameMap[provider];
|
|
40
|
+
if (newName) {
|
|
41
|
+
newProviders[newName] = providerConfig;
|
|
42
|
+
} else {
|
|
43
|
+
newProviders[provider] = providerConfig;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
updatedConfig.models = {
|
|
47
|
+
...updatedConfig.models,
|
|
48
|
+
providers: newProviders,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// 2. 更新 agents 配置
|
|
53
|
+
if (updatedConfig.agents) {
|
|
54
|
+
updatedConfig.agents = updateAgentsProviderReferences(
|
|
55
|
+
updatedConfig.agents,
|
|
56
|
+
renameMap
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return updatedConfig;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 更新 agents 配置中的 provider 引用
|
|
65
|
+
*/
|
|
66
|
+
function updateAgentsProviderReferences(
|
|
67
|
+
agents: any,
|
|
68
|
+
renameMap: Record<string, string>
|
|
69
|
+
): any {
|
|
70
|
+
const updatedAgents = { ...agents };
|
|
71
|
+
|
|
72
|
+
// 更新 defaults 配置
|
|
73
|
+
if (updatedAgents.defaults) {
|
|
74
|
+
updatedAgents.defaults = updateAgentDefaultsProviderReferences(
|
|
75
|
+
updatedAgents.defaults,
|
|
76
|
+
renameMap
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// 更新 list 配置
|
|
81
|
+
if (updatedAgents.list) {
|
|
82
|
+
updatedAgents.list = updatedAgents.list.map((agent: any) =>
|
|
83
|
+
updateAgentConfigProviderReferences(agent, renameMap)
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return updatedAgents;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* 更新 agent defaults 配置中的 provider 引用
|
|
92
|
+
*/
|
|
93
|
+
function updateAgentDefaultsProviderReferences(
|
|
94
|
+
defaults: any,
|
|
95
|
+
renameMap: Record<string, string>
|
|
96
|
+
): any {
|
|
97
|
+
const updatedDefaults = { ...defaults };
|
|
98
|
+
|
|
99
|
+
// 更新 model 配置
|
|
100
|
+
if (updatedDefaults.model) {
|
|
101
|
+
updatedDefaults.model = updateAgentModelConfig(
|
|
102
|
+
updatedDefaults.model,
|
|
103
|
+
renameMap
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// 更新 imageModel 配置
|
|
108
|
+
if (updatedDefaults.imageModel) {
|
|
109
|
+
updatedDefaults.imageModel = updateAgentModelConfig(
|
|
110
|
+
updatedDefaults.imageModel,
|
|
111
|
+
renameMap
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// 更新 pdfModel 配置
|
|
116
|
+
if (updatedDefaults.pdfModel) {
|
|
117
|
+
updatedDefaults.pdfModel = updateAgentModelConfig(
|
|
118
|
+
updatedDefaults.pdfModel,
|
|
119
|
+
renameMap
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// 更新 models 目录(key可能是"provider/model"格式)
|
|
124
|
+
if (updatedDefaults.models) {
|
|
125
|
+
const newModels: Record<string, any> = {};
|
|
126
|
+
for (const [key, value] of Object.entries(updatedDefaults.models)) {
|
|
127
|
+
const newKey = updateStringModelReference(key, renameMap);
|
|
128
|
+
newModels[newKey] = value;
|
|
129
|
+
}
|
|
130
|
+
updatedDefaults.models = newModels;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// 更新 subagents.model 配置
|
|
134
|
+
if (updatedDefaults.subagents?.model) {
|
|
135
|
+
updatedDefaults.subagents = {
|
|
136
|
+
...updatedDefaults.subagents,
|
|
137
|
+
model: updateAgentModelConfig(
|
|
138
|
+
updatedDefaults.subagents.model,
|
|
139
|
+
renameMap
|
|
140
|
+
),
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return updatedDefaults;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* 更新单个 agent 配置中的 provider 引用
|
|
149
|
+
*/
|
|
150
|
+
function updateAgentConfigProviderReferences(
|
|
151
|
+
agent: any,
|
|
152
|
+
renameMap: Record<string, string>
|
|
153
|
+
): any {
|
|
154
|
+
const updatedAgent = { ...agent };
|
|
155
|
+
|
|
156
|
+
// 更新 model 配置
|
|
157
|
+
if (updatedAgent.model) {
|
|
158
|
+
updatedAgent.model = updateAgentModelConfig(
|
|
159
|
+
updatedAgent.model,
|
|
160
|
+
renameMap
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// 更新 subagents.model 配置
|
|
165
|
+
if (updatedAgent.subagents?.model) {
|
|
166
|
+
updatedAgent.subagents = {
|
|
167
|
+
...updatedAgent.subagents,
|
|
168
|
+
model: updateAgentModelConfig(
|
|
169
|
+
updatedAgent.subagents.model,
|
|
170
|
+
renameMap
|
|
171
|
+
),
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return updatedAgent;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* 更新 AgentModelConfig 类型(可能是 string 或 {primary, fallbacks})
|
|
180
|
+
*/
|
|
181
|
+
function updateAgentModelConfig(
|
|
182
|
+
modelConfig: any,
|
|
183
|
+
renameMap: Record<string, string>
|
|
184
|
+
): any {
|
|
185
|
+
if (typeof modelConfig === "string") {
|
|
186
|
+
return updateStringModelReference(modelConfig, renameMap);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (typeof modelConfig === "object" && modelConfig !== null) {
|
|
190
|
+
const updatedModelConfig = { ...modelConfig };
|
|
191
|
+
|
|
192
|
+
if (updatedModelConfig.primary) {
|
|
193
|
+
updatedModelConfig.primary = updateStringModelReference(
|
|
194
|
+
updatedModelConfig.primary,
|
|
195
|
+
renameMap
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (updatedModelConfig.fallbacks && Array.isArray(updatedModelConfig.fallbacks)) {
|
|
200
|
+
updatedModelConfig.fallbacks = updatedModelConfig.fallbacks.map((fallback: string) =>
|
|
201
|
+
updateStringModelReference(fallback, renameMap)
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return updatedModelConfig;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return modelConfig;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* 更新 "provider/model" 格式的字符串
|
|
213
|
+
*/
|
|
214
|
+
function updateStringModelReference(
|
|
215
|
+
modelString: string,
|
|
216
|
+
renameMap: Record<string, string>
|
|
217
|
+
): string {
|
|
218
|
+
const parts = modelString.split("/");
|
|
219
|
+
if (parts.length > 0) {
|
|
220
|
+
const provider = parts[0];
|
|
221
|
+
const newProvider = renameMap[provider];
|
|
222
|
+
if (newProvider) {
|
|
223
|
+
parts[0] = newProvider;
|
|
224
|
+
return parts.join("/");
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return modelString;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
|