@openclaw/xiaomi-provider 0.0.0 → 2026.8.1-beta.3
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/README.md +15 -2
- package/dist/api.js +3 -0
- package/dist/index.js +289 -0
- package/dist/onboard.js +63 -0
- package/dist/provider-catalog-B3wdBKTb.js +102 -0
- package/dist/provider-catalog.js +2 -0
- package/dist/speech-provider.js +253 -0
- package/dist/stream.js +12 -0
- package/dist/thinking.js +33 -0
- package/openclaw.plugin.json +171 -0
- package/package.json +43 -8
package/README.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
-
#
|
|
1
|
+
# OpenClaw Xiaomi Provider
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Official OpenClaw provider plugin for Xiaomi MiMo pay-as-you-go and Token Plan
|
|
4
|
+
models, usage tracking, and text-to-speech.
|
|
5
|
+
|
|
6
|
+
Install from OpenClaw:
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
openclaw plugins install @openclaw/xiaomi-provider
|
|
10
|
+
openclaw gateway restart
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Configure `XIAOMI_API_KEY` for `xiaomi/*` models and speech, or
|
|
14
|
+
`XIAOMI_TOKEN_PLAN_API_KEY` for `xiaomi-token-plan/*` models. See
|
|
15
|
+
https://docs.openclaw.ai/providers/xiaomi for regional Token Plan setup and
|
|
16
|
+
the full model and speech configuration.
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { a as buildXiaomiProvider, t as XIAOMI_DEFAULT_MODEL_ID } from "./provider-catalog-B3wdBKTb.js";
|
|
2
|
+
import { XIAOMI_DEFAULT_MODEL_REF, applyXiaomiConfig, applyXiaomiProviderConfig } from "./onboard.js";
|
|
3
|
+
export { XIAOMI_DEFAULT_MODEL_ID, XIAOMI_DEFAULT_MODEL_REF, applyXiaomiConfig, applyXiaomiProviderConfig, buildXiaomiProvider };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import { a as buildXiaomiProvider, i as XIAOMI_TOKEN_PLAN_PROVIDER_ID, n as XIAOMI_PROVIDER_ID, o as buildXiaomiTokenPlanProvider } from "./provider-catalog-B3wdBKTb.js";
|
|
2
|
+
import { XIAOMI_DEFAULT_MODEL_REF, XIAOMI_TOKEN_PLAN_DEFAULT_MODEL_REF, applyXiaomiConfig, applyXiaomiTokenPlanConfig } from "./onboard.js";
|
|
3
|
+
import { buildXiaomiSpeechProvider } from "./speech-provider.js";
|
|
4
|
+
import { resolveMiMoThinkingProfile } from "./thinking.js";
|
|
5
|
+
import { createMiMoThinkingWrapper } from "./stream.js";
|
|
6
|
+
import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
|
|
7
|
+
import { applyAuthProfileConfig, buildApiKeyCredential, ensureApiKeyFromOptionEnvOrPrompt, normalizeApiKeyInput, normalizeOptionalSecretInput, upsertAuthProfileWithLockOrThrow, validateApiKeyInput } from "openclaw/plugin-sdk/provider-auth-api-key";
|
|
8
|
+
import { buildOpenAICompatibleLiveModelProviderConfig } from "openclaw/plugin-sdk/provider-catalog-live-runtime";
|
|
9
|
+
import { applyModelCompatPatch, buildProviderReplayFamilyHooks } from "openclaw/plugin-sdk/provider-model-shared";
|
|
10
|
+
import { PROVIDER_LABELS } from "openclaw/plugin-sdk/provider-usage";
|
|
11
|
+
//#region extensions/xiaomi/index.ts
|
|
12
|
+
const PAYG_FLAG_NAME = "--xiaomi-api-key";
|
|
13
|
+
const PAYG_OPTION_KEY = "xiaomiApiKey";
|
|
14
|
+
const PAYG_ENV_VAR = "XIAOMI_API_KEY";
|
|
15
|
+
const TOKEN_PLAN_FLAG_NAME = "--xiaomi-token-plan-api-key";
|
|
16
|
+
const TOKEN_PLAN_OPTION_KEY = "xiaomiTokenPlanApiKey";
|
|
17
|
+
const TOKEN_PLAN_ENV_VAR = "XIAOMI_TOKEN_PLAN_API_KEY";
|
|
18
|
+
const XIAOMI_WIZARD_GROUP = {
|
|
19
|
+
groupId: "xiaomi",
|
|
20
|
+
groupLabel: "Xiaomi",
|
|
21
|
+
groupHint: "Pay-as-you-go / Token Plan"
|
|
22
|
+
};
|
|
23
|
+
const XIAOMI_PROVIDER_HOOKS = {
|
|
24
|
+
...buildProviderReplayFamilyHooks({
|
|
25
|
+
family: "openai-compatible",
|
|
26
|
+
dropReasoningFromHistory: false
|
|
27
|
+
}),
|
|
28
|
+
normalizeResolvedModel: ({ model }) => applyModelCompatPatch(model, { omitEmptyArrayItems: true }),
|
|
29
|
+
wrapStreamFn: (ctx) => createMiMoThinkingWrapper(ctx.streamFn, ctx.thinkingLevel),
|
|
30
|
+
resolveThinkingProfile: ({ modelId }) => resolveMiMoThinkingProfile(modelId),
|
|
31
|
+
isModernModelRef: ({ modelId }) => Boolean(resolveMiMoThinkingProfile(modelId))
|
|
32
|
+
};
|
|
33
|
+
function trimConfiguredBaseUrl(ctx, providerId) {
|
|
34
|
+
const configuredProvider = ctx.config.models?.providers?.[providerId];
|
|
35
|
+
return (typeof configuredProvider?.baseUrl === "string" ? configuredProvider.baseUrl.trim() : "") || void 0;
|
|
36
|
+
}
|
|
37
|
+
function hasConfiguredProviderEntry(ctx, providerId) {
|
|
38
|
+
const configuredProvider = ctx.config.models?.providers?.[providerId];
|
|
39
|
+
return Boolean(configuredProvider && typeof configuredProvider === "object");
|
|
40
|
+
}
|
|
41
|
+
async function resolveXiaomiCatalog(params) {
|
|
42
|
+
const auth = params.ctx.resolveProviderApiKey(params.providerId);
|
|
43
|
+
if (!auth.apiKey) return null;
|
|
44
|
+
if (params.requireConfiguredProvider === true && !hasConfiguredProviderEntry(params.ctx, params.providerId)) return null;
|
|
45
|
+
const explicitBaseUrl = trimConfiguredBaseUrl(params.ctx, params.providerId);
|
|
46
|
+
if (params.requireBaseUrl === true && !explicitBaseUrl) return null;
|
|
47
|
+
return { provider: await buildOpenAICompatibleLiveModelProviderConfig({
|
|
48
|
+
providerId: params.providerId,
|
|
49
|
+
providerConfig: {
|
|
50
|
+
...params.buildProvider(),
|
|
51
|
+
...explicitBaseUrl ? { baseUrl: explicitBaseUrl } : {}
|
|
52
|
+
},
|
|
53
|
+
apiKey: auth.apiKey,
|
|
54
|
+
discoveryApiKey: auth.discoveryApiKey
|
|
55
|
+
}) };
|
|
56
|
+
}
|
|
57
|
+
function buildXiaomiKeyMismatchMessage(params) {
|
|
58
|
+
const normalized = params.actualKey.trim().toLowerCase();
|
|
59
|
+
const expectedPrefix = params.expectedKind === "payg" ? "sk-" : "tp-";
|
|
60
|
+
const kindLabel = params.expectedKind === "payg" ? "pay-as-you-go" : "Token Plan";
|
|
61
|
+
if (normalized.startsWith(expectedPrefix)) return;
|
|
62
|
+
if (params.expectedKind === "payg" && normalized.startsWith("tp-")) return "This looks like a Xiaomi MiMo Token Plan key (tp-...). Re-run onboarding with one of: --auth-choice xiaomi-token-plan-cn, --auth-choice xiaomi-token-plan-sgp, or --auth-choice xiaomi-token-plan-ams.";
|
|
63
|
+
if (params.expectedKind === "token-plan" && normalized.startsWith("sk-")) return `This looks like a Xiaomi MiMo pay-as-you-go key (sk-...). Re-run onboarding with --auth-choice xiaomi-api-key or pass ${PAYG_FLAG_NAME}.`;
|
|
64
|
+
return `Xiaomi MiMo ${kindLabel} keys must start with "${expectedPrefix}". The entered key does not match the expected format.`;
|
|
65
|
+
}
|
|
66
|
+
function assertCompatibleXiaomiKey(params) {
|
|
67
|
+
const message = buildXiaomiKeyMismatchMessage(params);
|
|
68
|
+
if (message) throw new Error(message);
|
|
69
|
+
}
|
|
70
|
+
function resolveProfileId(providerId) {
|
|
71
|
+
return `${providerId}:default`;
|
|
72
|
+
}
|
|
73
|
+
async function runXiaomiApiKeyAuth(ctx, params) {
|
|
74
|
+
let capturedSecretInput;
|
|
75
|
+
let capturedCredential = false;
|
|
76
|
+
let capturedMode;
|
|
77
|
+
const profileId = resolveProfileId(params.providerId);
|
|
78
|
+
assertCompatibleXiaomiKey({
|
|
79
|
+
actualKey: await ensureApiKeyFromOptionEnvOrPrompt({
|
|
80
|
+
token: normalizeOptionalSecretInput(ctx.opts?.[params.optionKey]) ?? normalizeOptionalSecretInput(ctx.opts?.token),
|
|
81
|
+
tokenProvider: normalizeOptionalSecretInput(ctx.opts?.[params.optionKey]) ? params.providerId : normalizeOptionalSecretInput(ctx.opts?.tokenProvider),
|
|
82
|
+
secretInputMode: ctx.allowSecretRefPrompt === false ? ctx.secretInputMode ?? "plaintext" : ctx.secretInputMode,
|
|
83
|
+
config: ctx.config,
|
|
84
|
+
env: ctx.env,
|
|
85
|
+
workspaceDir: ctx.workspaceDir,
|
|
86
|
+
expectedProviders: [params.providerId],
|
|
87
|
+
provider: params.providerId,
|
|
88
|
+
envLabel: params.envVar,
|
|
89
|
+
promptMessage: params.promptMessage,
|
|
90
|
+
normalize: normalizeApiKeyInput,
|
|
91
|
+
validate: validateApiKeyInput,
|
|
92
|
+
prompter: ctx.prompter,
|
|
93
|
+
setCredential: async (key, mode) => {
|
|
94
|
+
capturedSecretInput = key;
|
|
95
|
+
capturedCredential = true;
|
|
96
|
+
capturedMode = mode;
|
|
97
|
+
}
|
|
98
|
+
}),
|
|
99
|
+
expectedKind: params.expectedKind
|
|
100
|
+
});
|
|
101
|
+
if (!capturedCredential) throw new Error(`Missing Xiaomi API key for provider "${params.providerId}".`);
|
|
102
|
+
const credentialInput = capturedSecretInput ?? "";
|
|
103
|
+
return {
|
|
104
|
+
profiles: [{
|
|
105
|
+
profileId,
|
|
106
|
+
credential: buildApiKeyCredential(params.providerId, credentialInput, void 0, capturedMode ? { secretInputMode: capturedMode } : void 0)
|
|
107
|
+
}],
|
|
108
|
+
configPatch: params.applyConfig(ctx.config),
|
|
109
|
+
defaultModel: params.defaultModel
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
async function runXiaomiApiKeyAuthNonInteractive(ctx, params) {
|
|
113
|
+
const resolved = await ctx.resolveApiKey({
|
|
114
|
+
provider: params.providerId,
|
|
115
|
+
flagValue: normalizeOptionalSecretInput(ctx.opts[params.optionKey]),
|
|
116
|
+
flagName: params.flagName,
|
|
117
|
+
envVar: params.envVar
|
|
118
|
+
});
|
|
119
|
+
if (!resolved) return null;
|
|
120
|
+
assertCompatibleXiaomiKey({
|
|
121
|
+
actualKey: resolved.key,
|
|
122
|
+
expectedKind: params.expectedKind
|
|
123
|
+
});
|
|
124
|
+
const profileId = resolveProfileId(params.providerId);
|
|
125
|
+
if (resolved.source !== "profile") {
|
|
126
|
+
const credential = ctx.toApiKeyCredential({
|
|
127
|
+
provider: params.providerId,
|
|
128
|
+
resolved
|
|
129
|
+
});
|
|
130
|
+
if (!credential) return null;
|
|
131
|
+
await upsertAuthProfileWithLockOrThrow({
|
|
132
|
+
profileId,
|
|
133
|
+
credential,
|
|
134
|
+
agentDir: ctx.agentDir
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
const next = applyAuthProfileConfig(ctx.config, {
|
|
138
|
+
profileId,
|
|
139
|
+
provider: params.providerId,
|
|
140
|
+
mode: "api_key"
|
|
141
|
+
});
|
|
142
|
+
return params.applyConfig(next);
|
|
143
|
+
}
|
|
144
|
+
function createPaygAuthMethod() {
|
|
145
|
+
return {
|
|
146
|
+
id: "api-key",
|
|
147
|
+
label: "Xiaomi API key (Pay-as-you-go)",
|
|
148
|
+
hint: "Endpoint: api.xiaomimimo.com/v1",
|
|
149
|
+
kind: "api_key",
|
|
150
|
+
wizard: {
|
|
151
|
+
choiceId: "xiaomi-api-key",
|
|
152
|
+
choiceLabel: "Xiaomi API key (Pay-as-you-go)",
|
|
153
|
+
choiceHint: "Endpoint: api.xiaomimimo.com/v1",
|
|
154
|
+
...XIAOMI_WIZARD_GROUP
|
|
155
|
+
},
|
|
156
|
+
run: async (ctx) => await runXiaomiApiKeyAuth(ctx, {
|
|
157
|
+
providerId: XIAOMI_PROVIDER_ID,
|
|
158
|
+
optionKey: PAYG_OPTION_KEY,
|
|
159
|
+
envVar: PAYG_ENV_VAR,
|
|
160
|
+
promptMessage: "Enter Xiaomi MiMo API key (pay-as-you-go, sk-...)",
|
|
161
|
+
expectedKind: "payg",
|
|
162
|
+
defaultModel: XIAOMI_DEFAULT_MODEL_REF,
|
|
163
|
+
applyConfig: applyXiaomiConfig
|
|
164
|
+
}),
|
|
165
|
+
runNonInteractive: async (ctx) => await runXiaomiApiKeyAuthNonInteractive(ctx, {
|
|
166
|
+
providerId: XIAOMI_PROVIDER_ID,
|
|
167
|
+
optionKey: PAYG_OPTION_KEY,
|
|
168
|
+
flagName: PAYG_FLAG_NAME,
|
|
169
|
+
envVar: PAYG_ENV_VAR,
|
|
170
|
+
expectedKind: "payg",
|
|
171
|
+
applyConfig: applyXiaomiConfig
|
|
172
|
+
})
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
function createTokenPlanAuthMethod(region) {
|
|
176
|
+
const regionLabel = region === "ams" ? "Europe" : region === "cn" ? "China" : "Singapore";
|
|
177
|
+
const choiceId = `xiaomi-token-plan-${region}`;
|
|
178
|
+
const choiceLabel = `Xiaomi Token Plan (${regionLabel})`;
|
|
179
|
+
const choiceHint = `Endpoint preset: token-plan-${region}.xiaomimimo.com/v1`;
|
|
180
|
+
return {
|
|
181
|
+
id: `token-plan-${region}`,
|
|
182
|
+
label: choiceLabel,
|
|
183
|
+
hint: choiceHint,
|
|
184
|
+
kind: "api_key",
|
|
185
|
+
wizard: {
|
|
186
|
+
choiceId,
|
|
187
|
+
choiceLabel,
|
|
188
|
+
choiceHint,
|
|
189
|
+
...XIAOMI_WIZARD_GROUP
|
|
190
|
+
},
|
|
191
|
+
run: async (ctx) => await runXiaomiApiKeyAuth(ctx, {
|
|
192
|
+
providerId: XIAOMI_TOKEN_PLAN_PROVIDER_ID,
|
|
193
|
+
optionKey: TOKEN_PLAN_OPTION_KEY,
|
|
194
|
+
envVar: TOKEN_PLAN_ENV_VAR,
|
|
195
|
+
promptMessage: `Enter Xiaomi MiMo Token Plan API key (tp-...) for ${regionLabel}`,
|
|
196
|
+
expectedKind: "token-plan",
|
|
197
|
+
defaultModel: XIAOMI_TOKEN_PLAN_DEFAULT_MODEL_REF,
|
|
198
|
+
applyConfig: (cfg) => applyXiaomiTokenPlanConfig(cfg, region)
|
|
199
|
+
}),
|
|
200
|
+
runNonInteractive: async (ctx) => await runXiaomiApiKeyAuthNonInteractive(ctx, {
|
|
201
|
+
providerId: XIAOMI_TOKEN_PLAN_PROVIDER_ID,
|
|
202
|
+
optionKey: TOKEN_PLAN_OPTION_KEY,
|
|
203
|
+
flagName: TOKEN_PLAN_FLAG_NAME,
|
|
204
|
+
envVar: TOKEN_PLAN_ENV_VAR,
|
|
205
|
+
expectedKind: "token-plan",
|
|
206
|
+
applyConfig: (cfg) => applyXiaomiTokenPlanConfig(cfg, region)
|
|
207
|
+
})
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
var xiaomi_default = definePluginEntry({
|
|
211
|
+
id: XIAOMI_PROVIDER_ID,
|
|
212
|
+
name: "Xiaomi Provider",
|
|
213
|
+
description: "Xiaomi provider plugin",
|
|
214
|
+
register(api) {
|
|
215
|
+
api.registerProvider({
|
|
216
|
+
id: XIAOMI_PROVIDER_ID,
|
|
217
|
+
label: "Xiaomi",
|
|
218
|
+
docsPath: "/providers/xiaomi",
|
|
219
|
+
envVars: [PAYG_ENV_VAR],
|
|
220
|
+
auth: [createPaygAuthMethod()],
|
|
221
|
+
catalog: {
|
|
222
|
+
order: "simple",
|
|
223
|
+
run: async (ctx) => resolveXiaomiCatalog({
|
|
224
|
+
ctx,
|
|
225
|
+
providerId: XIAOMI_PROVIDER_ID,
|
|
226
|
+
buildProvider: buildXiaomiProvider
|
|
227
|
+
})
|
|
228
|
+
},
|
|
229
|
+
staticCatalog: {
|
|
230
|
+
order: "simple",
|
|
231
|
+
run: async () => ({ provider: buildXiaomiProvider() })
|
|
232
|
+
},
|
|
233
|
+
...XIAOMI_PROVIDER_HOOKS,
|
|
234
|
+
resolveUsageAuth: async (ctx) => {
|
|
235
|
+
const apiKey = ctx.resolveApiKeyFromConfigAndStore({
|
|
236
|
+
providerIds: [XIAOMI_PROVIDER_ID],
|
|
237
|
+
envDirect: [ctx.env.XIAOMI_API_KEY]
|
|
238
|
+
});
|
|
239
|
+
return apiKey ? { token: apiKey } : null;
|
|
240
|
+
},
|
|
241
|
+
fetchUsageSnapshot: async () => ({
|
|
242
|
+
provider: XIAOMI_PROVIDER_ID,
|
|
243
|
+
displayName: PROVIDER_LABELS.xiaomi,
|
|
244
|
+
windows: []
|
|
245
|
+
})
|
|
246
|
+
});
|
|
247
|
+
api.registerProvider({
|
|
248
|
+
id: XIAOMI_TOKEN_PLAN_PROVIDER_ID,
|
|
249
|
+
label: "Xiaomi Token Plan",
|
|
250
|
+
docsPath: "/providers/xiaomi",
|
|
251
|
+
envVars: [TOKEN_PLAN_ENV_VAR],
|
|
252
|
+
auth: [
|
|
253
|
+
createTokenPlanAuthMethod("ams"),
|
|
254
|
+
createTokenPlanAuthMethod("cn"),
|
|
255
|
+
createTokenPlanAuthMethod("sgp")
|
|
256
|
+
],
|
|
257
|
+
catalog: {
|
|
258
|
+
order: "simple",
|
|
259
|
+
run: async (ctx) => resolveXiaomiCatalog({
|
|
260
|
+
ctx,
|
|
261
|
+
providerId: XIAOMI_TOKEN_PLAN_PROVIDER_ID,
|
|
262
|
+
buildProvider: buildXiaomiTokenPlanProvider,
|
|
263
|
+
requireConfiguredProvider: true,
|
|
264
|
+
requireBaseUrl: true
|
|
265
|
+
})
|
|
266
|
+
},
|
|
267
|
+
staticCatalog: {
|
|
268
|
+
order: "simple",
|
|
269
|
+
run: async () => ({ provider: buildXiaomiTokenPlanProvider() })
|
|
270
|
+
},
|
|
271
|
+
...XIAOMI_PROVIDER_HOOKS,
|
|
272
|
+
resolveUsageAuth: async (ctx) => {
|
|
273
|
+
const apiKey = ctx.resolveApiKeyFromConfigAndStore({
|
|
274
|
+
providerIds: [XIAOMI_TOKEN_PLAN_PROVIDER_ID],
|
|
275
|
+
envDirect: [ctx.env.XIAOMI_TOKEN_PLAN_API_KEY]
|
|
276
|
+
});
|
|
277
|
+
return apiKey ? { token: apiKey } : null;
|
|
278
|
+
},
|
|
279
|
+
fetchUsageSnapshot: async () => ({
|
|
280
|
+
provider: XIAOMI_TOKEN_PLAN_PROVIDER_ID,
|
|
281
|
+
displayName: "Xiaomi MiMo Token Plan",
|
|
282
|
+
windows: []
|
|
283
|
+
})
|
|
284
|
+
});
|
|
285
|
+
api.registerSpeechProvider(buildXiaomiSpeechProvider());
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
//#endregion
|
|
289
|
+
export { xiaomi_default as default };
|
package/dist/onboard.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { a as buildXiaomiProvider, i as XIAOMI_TOKEN_PLAN_PROVIDER_ID, n as XIAOMI_PROVIDER_ID, o as buildXiaomiTokenPlanProvider, r as XIAOMI_TOKEN_PLAN_DEFAULT_MODEL_ID, s as resolveXiaomiTokenPlanBaseUrl, t as XIAOMI_DEFAULT_MODEL_ID } from "./provider-catalog-B3wdBKTb.js";
|
|
2
|
+
import { createDefaultModelsPresetAppliers } from "openclaw/plugin-sdk/provider-onboard";
|
|
3
|
+
//#region extensions/xiaomi/onboard.ts
|
|
4
|
+
const XIAOMI_DEFAULT_MODEL_REF = `${XIAOMI_PROVIDER_ID}/${XIAOMI_DEFAULT_MODEL_ID}`;
|
|
5
|
+
const XIAOMI_TOKEN_PLAN_DEFAULT_MODEL_REF = `${XIAOMI_TOKEN_PLAN_PROVIDER_ID}/${XIAOMI_TOKEN_PLAN_DEFAULT_MODEL_ID}`;
|
|
6
|
+
const { applyConfig: applyXiaomiConfig, applyProviderConfig: applyXiaomiProviderConfig } = createDefaultModelsPresetAppliers({
|
|
7
|
+
primaryModelRef: XIAOMI_DEFAULT_MODEL_REF,
|
|
8
|
+
resolveParams: () => {
|
|
9
|
+
const defaultProvider = buildXiaomiProvider();
|
|
10
|
+
return {
|
|
11
|
+
providerId: XIAOMI_PROVIDER_ID,
|
|
12
|
+
api: defaultProvider.api ?? "openai-completions",
|
|
13
|
+
baseUrl: defaultProvider.baseUrl,
|
|
14
|
+
defaultModels: defaultProvider.models ?? [],
|
|
15
|
+
defaultModelId: XIAOMI_DEFAULT_MODEL_ID,
|
|
16
|
+
aliases: [{
|
|
17
|
+
modelRef: XIAOMI_DEFAULT_MODEL_REF,
|
|
18
|
+
alias: "Xiaomi"
|
|
19
|
+
}]
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
const xiaomiTokenPlanPresetAppliers = createDefaultModelsPresetAppliers({
|
|
24
|
+
primaryModelRef: XIAOMI_TOKEN_PLAN_DEFAULT_MODEL_REF,
|
|
25
|
+
resolveParams: () => {
|
|
26
|
+
const defaultProvider = buildXiaomiTokenPlanProvider();
|
|
27
|
+
return {
|
|
28
|
+
providerId: XIAOMI_TOKEN_PLAN_PROVIDER_ID,
|
|
29
|
+
api: defaultProvider.api ?? "openai-completions",
|
|
30
|
+
baseUrl: defaultProvider.baseUrl,
|
|
31
|
+
defaultModels: defaultProvider.models ?? [],
|
|
32
|
+
defaultModelId: XIAOMI_TOKEN_PLAN_DEFAULT_MODEL_ID,
|
|
33
|
+
aliases: (() => {
|
|
34
|
+
const defaultModel = defaultProvider.models?.find((m) => m.id === XIAOMI_TOKEN_PLAN_DEFAULT_MODEL_ID);
|
|
35
|
+
return [{
|
|
36
|
+
modelRef: XIAOMI_TOKEN_PLAN_DEFAULT_MODEL_REF,
|
|
37
|
+
alias: defaultModel?.name ?? "MiMo V2.5 Pro"
|
|
38
|
+
}];
|
|
39
|
+
})()
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
function withProviderBaseUrl(cfg, providerId, baseUrl) {
|
|
44
|
+
const providers = {
|
|
45
|
+
...cfg.models?.providers,
|
|
46
|
+
[providerId]: {
|
|
47
|
+
...cfg.models?.providers?.[providerId],
|
|
48
|
+
baseUrl
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
return {
|
|
52
|
+
...cfg,
|
|
53
|
+
models: {
|
|
54
|
+
...cfg.models,
|
|
55
|
+
providers
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function applyXiaomiTokenPlanConfig(cfg, region) {
|
|
60
|
+
return withProviderBaseUrl(xiaomiTokenPlanPresetAppliers.applyConfig(cfg), XIAOMI_TOKEN_PLAN_PROVIDER_ID, resolveXiaomiTokenPlanBaseUrl(region));
|
|
61
|
+
}
|
|
62
|
+
//#endregion
|
|
63
|
+
export { XIAOMI_DEFAULT_MODEL_REF, XIAOMI_TOKEN_PLAN_DEFAULT_MODEL_REF, applyXiaomiConfig, applyXiaomiProviderConfig, applyXiaomiTokenPlanConfig };
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { buildManifestModelProviderConfig } from "openclaw/plugin-sdk/provider-catalog-shared";
|
|
2
|
+
//#region extensions/xiaomi/openclaw.plugin.json
|
|
3
|
+
var modelCatalog = {
|
|
4
|
+
"providers": {
|
|
5
|
+
"xiaomi": {
|
|
6
|
+
"baseUrl": "https://api.xiaomimimo.com/v1",
|
|
7
|
+
"api": "openai-completions",
|
|
8
|
+
"models": [{
|
|
9
|
+
"id": "mimo-v2.5",
|
|
10
|
+
"name": "Xiaomi MiMo V2.5",
|
|
11
|
+
"input": ["text", "image"],
|
|
12
|
+
"reasoning": true,
|
|
13
|
+
"contextWindow": 1048576,
|
|
14
|
+
"maxTokens": 131072,
|
|
15
|
+
"cost": {
|
|
16
|
+
"input": .14,
|
|
17
|
+
"output": .28,
|
|
18
|
+
"cacheRead": .0028,
|
|
19
|
+
"cacheWrite": 0
|
|
20
|
+
},
|
|
21
|
+
"compat": { "codeMode": "preferred" }
|
|
22
|
+
}, {
|
|
23
|
+
"id": "mimo-v2.5-pro",
|
|
24
|
+
"name": "Xiaomi MiMo V2.5 Pro",
|
|
25
|
+
"input": ["text"],
|
|
26
|
+
"reasoning": true,
|
|
27
|
+
"contextWindow": 1048576,
|
|
28
|
+
"maxTokens": 131072,
|
|
29
|
+
"cost": {
|
|
30
|
+
"input": .435,
|
|
31
|
+
"output": .87,
|
|
32
|
+
"cacheRead": .0036,
|
|
33
|
+
"cacheWrite": 0
|
|
34
|
+
}
|
|
35
|
+
}]
|
|
36
|
+
},
|
|
37
|
+
"xiaomi-token-plan": {
|
|
38
|
+
"baseUrl": "https://token-plan-sgp.xiaomimimo.com/v1",
|
|
39
|
+
"api": "openai-completions",
|
|
40
|
+
"models": [{
|
|
41
|
+
"id": "mimo-v2.5-pro",
|
|
42
|
+
"name": "Xiaomi MiMo V2.5 Pro",
|
|
43
|
+
"input": ["text"],
|
|
44
|
+
"reasoning": true,
|
|
45
|
+
"contextWindow": 1048576,
|
|
46
|
+
"maxTokens": 131072,
|
|
47
|
+
"cost": {
|
|
48
|
+
"input": 0,
|
|
49
|
+
"output": 0,
|
|
50
|
+
"cacheRead": 0,
|
|
51
|
+
"cacheWrite": 0
|
|
52
|
+
}
|
|
53
|
+
}, {
|
|
54
|
+
"id": "mimo-v2.5",
|
|
55
|
+
"name": "Xiaomi MiMo V2.5",
|
|
56
|
+
"input": ["text", "image"],
|
|
57
|
+
"reasoning": true,
|
|
58
|
+
"contextWindow": 1048576,
|
|
59
|
+
"maxTokens": 131072,
|
|
60
|
+
"cost": {
|
|
61
|
+
"input": 0,
|
|
62
|
+
"output": 0,
|
|
63
|
+
"cacheRead": 0,
|
|
64
|
+
"cacheWrite": 0
|
|
65
|
+
},
|
|
66
|
+
"compat": { "codeMode": "preferred" }
|
|
67
|
+
}]
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"discovery": {
|
|
71
|
+
"xiaomi": "refreshable",
|
|
72
|
+
"xiaomi-token-plan": "refreshable"
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region extensions/xiaomi/provider-catalog.ts
|
|
77
|
+
const XIAOMI_PROVIDER_ID = "xiaomi";
|
|
78
|
+
const XIAOMI_TOKEN_PLAN_PROVIDER_ID = "xiaomi-token-plan";
|
|
79
|
+
const XIAOMI_DEFAULT_MODEL_ID = "mimo-v2.5";
|
|
80
|
+
const XIAOMI_TOKEN_PLAN_DEFAULT_MODEL_ID = "mimo-v2.5-pro";
|
|
81
|
+
const XIAOMI_TOKEN_PLAN_BASE_URLS = {
|
|
82
|
+
ams: "https://token-plan-ams.xiaomimimo.com/v1",
|
|
83
|
+
cn: "https://token-plan-cn.xiaomimimo.com/v1",
|
|
84
|
+
sgp: "https://token-plan-sgp.xiaomimimo.com/v1"
|
|
85
|
+
};
|
|
86
|
+
function buildXiaomiProvider() {
|
|
87
|
+
return buildManifestModelProviderConfig({
|
|
88
|
+
providerId: XIAOMI_PROVIDER_ID,
|
|
89
|
+
catalog: modelCatalog.providers.xiaomi
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
function buildXiaomiTokenPlanProvider() {
|
|
93
|
+
return buildManifestModelProviderConfig({
|
|
94
|
+
providerId: XIAOMI_TOKEN_PLAN_PROVIDER_ID,
|
|
95
|
+
catalog: modelCatalog.providers[XIAOMI_TOKEN_PLAN_PROVIDER_ID]
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
function resolveXiaomiTokenPlanBaseUrl(region) {
|
|
99
|
+
return XIAOMI_TOKEN_PLAN_BASE_URLS[region];
|
|
100
|
+
}
|
|
101
|
+
//#endregion
|
|
102
|
+
export { buildXiaomiProvider as a, XIAOMI_TOKEN_PLAN_PROVIDER_ID as i, XIAOMI_PROVIDER_ID as n, buildXiaomiTokenPlanProvider as o, XIAOMI_TOKEN_PLAN_DEFAULT_MODEL_ID as r, resolveXiaomiTokenPlanBaseUrl as s, XIAOMI_DEFAULT_MODEL_ID as t };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as buildXiaomiProvider, i as XIAOMI_TOKEN_PLAN_PROVIDER_ID, n as XIAOMI_PROVIDER_ID, o as buildXiaomiTokenPlanProvider, r as XIAOMI_TOKEN_PLAN_DEFAULT_MODEL_ID, s as resolveXiaomiTokenPlanBaseUrl, t as XIAOMI_DEFAULT_MODEL_ID } from "./provider-catalog-B3wdBKTb.js";
|
|
2
|
+
export { XIAOMI_DEFAULT_MODEL_ID, XIAOMI_PROVIDER_ID, XIAOMI_TOKEN_PLAN_DEFAULT_MODEL_ID, XIAOMI_TOKEN_PLAN_PROVIDER_ID, buildXiaomiProvider, buildXiaomiTokenPlanProvider, resolveXiaomiTokenPlanBaseUrl };
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { canonicalizeBase64, transcodeAudioBufferToOpus } from "openclaw/plugin-sdk/media-runtime";
|
|
2
|
+
import { resolveTimerTimeoutMs } from "openclaw/plugin-sdk/number-runtime";
|
|
3
|
+
import { assertOkOrThrowProviderError, readProviderJsonResponse } from "openclaw/plugin-sdk/provider-http";
|
|
4
|
+
import { normalizeResolvedSecretInputString } from "openclaw/plugin-sdk/secret-input";
|
|
5
|
+
import { resolveSpeechProviderApiKey, trimToUndefined } from "openclaw/plugin-sdk/speech-core";
|
|
6
|
+
import { fetchWithSsrFGuard, ssrfPolicyFromHttpBaseUrlAllowedHostname } from "openclaw/plugin-sdk/ssrf-runtime";
|
|
7
|
+
import { asOptionalRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
8
|
+
//#region extensions/xiaomi/speech-provider.ts
|
|
9
|
+
const DEFAULT_XIAOMI_TTS_BASE_URL = "https://api.xiaomimimo.com/v1";
|
|
10
|
+
const DEFAULT_XIAOMI_TTS_MODEL = "mimo-v2.5-tts";
|
|
11
|
+
const DEFAULT_XIAOMI_TTS_VOICE = "mimo_default";
|
|
12
|
+
const DEFAULT_XIAOMI_TTS_FORMAT = "mp3";
|
|
13
|
+
const XIAOMI_TTS_VOICE_DESIGN_MODEL = "mimo-v2.5-tts-voicedesign";
|
|
14
|
+
const DEFAULT_XIAOMI_TTS_VOICE_DESIGN_STYLE = "Warm, natural, and friendly voice with clear pronunciation and conversational pacing.";
|
|
15
|
+
const XIAOMI_TTS_MODELS = ["mimo-v2.5-tts", XIAOMI_TTS_VOICE_DESIGN_MODEL];
|
|
16
|
+
const XIAOMI_TTS_VOICES = [
|
|
17
|
+
"mimo_default",
|
|
18
|
+
"default_zh",
|
|
19
|
+
"default_en",
|
|
20
|
+
"Mia",
|
|
21
|
+
"Chloe",
|
|
22
|
+
"Milo",
|
|
23
|
+
"Dean"
|
|
24
|
+
];
|
|
25
|
+
const XIAOMI_TTS_FORMATS = ["mp3", "wav"];
|
|
26
|
+
function normalizeXiaomiTtsBaseUrl(baseUrl) {
|
|
27
|
+
return (baseUrl?.trim() || DEFAULT_XIAOMI_TTS_BASE_URL).replace(/\/+$/, "");
|
|
28
|
+
}
|
|
29
|
+
function normalizeXiaomiTtsFormat(value) {
|
|
30
|
+
const normalized = trimToUndefined(value)?.toLowerCase();
|
|
31
|
+
return XIAOMI_TTS_FORMATS.includes(normalized) ? normalized : void 0;
|
|
32
|
+
}
|
|
33
|
+
function resolveXiaomiTtsConfigRecord(rawConfig) {
|
|
34
|
+
const providers = asOptionalRecord(rawConfig.providers);
|
|
35
|
+
return asOptionalRecord(providers?.xiaomi) ?? asOptionalRecord(providers?.mimo) ?? asOptionalRecord(rawConfig.xiaomi);
|
|
36
|
+
}
|
|
37
|
+
function normalizeXiaomiTtsProviderConfig(rawConfig) {
|
|
38
|
+
const raw = resolveXiaomiTtsConfigRecord(rawConfig);
|
|
39
|
+
return {
|
|
40
|
+
apiKey: normalizeResolvedSecretInputString({
|
|
41
|
+
value: raw?.apiKey,
|
|
42
|
+
path: "tts.providers.xiaomi.apiKey"
|
|
43
|
+
}),
|
|
44
|
+
baseUrl: normalizeXiaomiTtsBaseUrl(trimToUndefined(raw?.baseUrl) ?? trimToUndefined(process.env.XIAOMI_BASE_URL)),
|
|
45
|
+
model: trimToUndefined(raw?.model) ?? trimToUndefined(raw?.modelId) ?? trimToUndefined(process.env.XIAOMI_TTS_MODEL) ?? DEFAULT_XIAOMI_TTS_MODEL,
|
|
46
|
+
voice: trimToUndefined(raw?.speakerVoice) ?? trimToUndefined(raw?.speakerVoiceId) ?? trimToUndefined(raw?.voice) ?? trimToUndefined(raw?.voiceId) ?? trimToUndefined(process.env.XIAOMI_TTS_VOICE) ?? DEFAULT_XIAOMI_TTS_VOICE,
|
|
47
|
+
format: normalizeXiaomiTtsFormat(raw?.format) ?? normalizeXiaomiTtsFormat(process.env.XIAOMI_TTS_FORMAT) ?? DEFAULT_XIAOMI_TTS_FORMAT,
|
|
48
|
+
style: trimToUndefined(raw?.style)
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function readXiaomiTtsProviderConfig(config) {
|
|
52
|
+
const normalized = normalizeXiaomiTtsProviderConfig({});
|
|
53
|
+
return {
|
|
54
|
+
apiKey: normalizeResolvedSecretInputString({
|
|
55
|
+
value: config.apiKey,
|
|
56
|
+
path: "tts.providers.xiaomi.apiKey"
|
|
57
|
+
}) ?? normalized.apiKey,
|
|
58
|
+
baseUrl: normalizeXiaomiTtsBaseUrl(trimToUndefined(config.baseUrl) ?? normalized.baseUrl),
|
|
59
|
+
model: trimToUndefined(config.model) ?? trimToUndefined(config.modelId) ?? normalized.model,
|
|
60
|
+
voice: trimToUndefined(config.speakerVoice) ?? trimToUndefined(config.speakerVoiceId) ?? trimToUndefined(config.voice) ?? trimToUndefined(config.voiceId) ?? normalized.voice,
|
|
61
|
+
format: normalizeXiaomiTtsFormat(config.format) ?? normalized.format,
|
|
62
|
+
style: trimToUndefined(config.style) ?? normalized.style
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function resolveXiaomiTtsProviderConfig(config) {
|
|
66
|
+
const providerConfig = readXiaomiTtsProviderConfig(config);
|
|
67
|
+
const resolvedKey = resolveSpeechProviderApiKey(providerConfig.apiKey, process.env.XIAOMI_API_KEY);
|
|
68
|
+
return {
|
|
69
|
+
...providerConfig,
|
|
70
|
+
apiKey: resolvedKey
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function readXiaomiTtsOverrides(overrides) {
|
|
74
|
+
if (!overrides) return {};
|
|
75
|
+
return {
|
|
76
|
+
model: trimToUndefined(overrides.model) ?? trimToUndefined(overrides.modelId),
|
|
77
|
+
voice: trimToUndefined(overrides.speakerVoice) ?? trimToUndefined(overrides.speakerVoiceId) ?? trimToUndefined(overrides.voice) ?? trimToUndefined(overrides.voiceId),
|
|
78
|
+
format: normalizeXiaomiTtsFormat(overrides.format),
|
|
79
|
+
style: trimToUndefined(overrides.style)
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function parseDirectiveToken(ctx) {
|
|
83
|
+
switch (ctx.key) {
|
|
84
|
+
case "voice":
|
|
85
|
+
case "voiceid":
|
|
86
|
+
case "voice_id":
|
|
87
|
+
case "mimo_voice":
|
|
88
|
+
case "xiaomi_voice":
|
|
89
|
+
if (!ctx.policy.allowVoice) return { handled: true };
|
|
90
|
+
return {
|
|
91
|
+
handled: true,
|
|
92
|
+
overrides: { voice: ctx.value }
|
|
93
|
+
};
|
|
94
|
+
case "model":
|
|
95
|
+
case "mimo_model":
|
|
96
|
+
case "xiaomi_model":
|
|
97
|
+
if (!ctx.policy.allowModelId) return { handled: true };
|
|
98
|
+
return {
|
|
99
|
+
handled: true,
|
|
100
|
+
overrides: { model: ctx.value }
|
|
101
|
+
};
|
|
102
|
+
case "style":
|
|
103
|
+
case "mimo_style":
|
|
104
|
+
case "xiaomi_style":
|
|
105
|
+
if (!ctx.policy.allowVoiceSettings) return { handled: true };
|
|
106
|
+
return {
|
|
107
|
+
handled: true,
|
|
108
|
+
overrides: { style: ctx.value }
|
|
109
|
+
};
|
|
110
|
+
case "format":
|
|
111
|
+
case "responseformat":
|
|
112
|
+
case "response_format": {
|
|
113
|
+
if (!ctx.policy.allowVoiceSettings) return { handled: true };
|
|
114
|
+
const format = normalizeXiaomiTtsFormat(ctx.value);
|
|
115
|
+
if (!format) return {
|
|
116
|
+
handled: true,
|
|
117
|
+
warnings: [`invalid Xiaomi TTS format "${ctx.value}"`]
|
|
118
|
+
};
|
|
119
|
+
return {
|
|
120
|
+
handled: true,
|
|
121
|
+
overrides: { format }
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
default: return { handled: false };
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function buildXiaomiTtsMessages(params) {
|
|
128
|
+
const style = trimToUndefined(params.style);
|
|
129
|
+
return [...style ? [{
|
|
130
|
+
role: "user",
|
|
131
|
+
content: style
|
|
132
|
+
}] : [], {
|
|
133
|
+
role: "assistant",
|
|
134
|
+
content: params.text
|
|
135
|
+
}];
|
|
136
|
+
}
|
|
137
|
+
function isXiaomiVoiceDesignModel(model) {
|
|
138
|
+
return model === XIAOMI_TTS_VOICE_DESIGN_MODEL;
|
|
139
|
+
}
|
|
140
|
+
function resolveXiaomiVoiceDesignStyle(style) {
|
|
141
|
+
return trimToUndefined(style) ?? DEFAULT_XIAOMI_TTS_VOICE_DESIGN_STYLE;
|
|
142
|
+
}
|
|
143
|
+
function buildXiaomiTtsAudio(params) {
|
|
144
|
+
if (isXiaomiVoiceDesignModel(params.model)) return { format: params.format };
|
|
145
|
+
return {
|
|
146
|
+
format: params.format,
|
|
147
|
+
voice: params.voice
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
function decodeXiaomiAudioData(body) {
|
|
151
|
+
const root = asOptionalRecord(body);
|
|
152
|
+
const audioData = trimToUndefined(asOptionalRecord(asOptionalRecord(asOptionalRecord((Array.isArray(root?.choices) ? root.choices : [])[0])?.message)?.audio)?.data);
|
|
153
|
+
if (!audioData) throw new Error("Xiaomi TTS API returned no audio data");
|
|
154
|
+
const canonicalAudio = canonicalizeBase64(audioData);
|
|
155
|
+
if (!canonicalAudio) throw new Error("Xiaomi TTS API returned malformed base64 audio data");
|
|
156
|
+
return Buffer.from(canonicalAudio, "base64");
|
|
157
|
+
}
|
|
158
|
+
async function xiaomiTTS(params) {
|
|
159
|
+
const { text, apiKey, baseUrl, model, voice, format, style, timeoutMs } = params;
|
|
160
|
+
const requestTimeoutMs = resolveTimerTimeoutMs(timeoutMs, 1);
|
|
161
|
+
const controller = new AbortController();
|
|
162
|
+
const timeout = setTimeout(() => controller.abort(), requestTimeoutMs);
|
|
163
|
+
const resolvedStyle = isXiaomiVoiceDesignModel(model) ? resolveXiaomiVoiceDesignStyle(style) : style;
|
|
164
|
+
try {
|
|
165
|
+
const { response, release } = await fetchWithSsrFGuard({
|
|
166
|
+
url: `${baseUrl}/chat/completions`,
|
|
167
|
+
init: {
|
|
168
|
+
method: "POST",
|
|
169
|
+
headers: {
|
|
170
|
+
"api-key": apiKey,
|
|
171
|
+
"Content-Type": "application/json"
|
|
172
|
+
},
|
|
173
|
+
body: JSON.stringify({
|
|
174
|
+
model,
|
|
175
|
+
messages: buildXiaomiTtsMessages({
|
|
176
|
+
text,
|
|
177
|
+
style: resolvedStyle
|
|
178
|
+
}),
|
|
179
|
+
audio: buildXiaomiTtsAudio({
|
|
180
|
+
model,
|
|
181
|
+
voice,
|
|
182
|
+
format
|
|
183
|
+
})
|
|
184
|
+
}),
|
|
185
|
+
signal: controller.signal
|
|
186
|
+
},
|
|
187
|
+
timeoutMs: requestTimeoutMs,
|
|
188
|
+
policy: ssrfPolicyFromHttpBaseUrlAllowedHostname(baseUrl),
|
|
189
|
+
auditContext: "xiaomi.tts"
|
|
190
|
+
});
|
|
191
|
+
try {
|
|
192
|
+
await assertOkOrThrowProviderError(response, "Xiaomi TTS API error");
|
|
193
|
+
return decodeXiaomiAudioData(await readProviderJsonResponse(response, "Xiaomi TTS API"));
|
|
194
|
+
} finally {
|
|
195
|
+
await release();
|
|
196
|
+
}
|
|
197
|
+
} finally {
|
|
198
|
+
clearTimeout(timeout);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
function buildXiaomiSpeechProvider() {
|
|
202
|
+
return {
|
|
203
|
+
id: "xiaomi",
|
|
204
|
+
label: "Xiaomi MiMo",
|
|
205
|
+
aliases: ["mimo"],
|
|
206
|
+
autoSelectOrder: 45,
|
|
207
|
+
defaultModel: DEFAULT_XIAOMI_TTS_MODEL,
|
|
208
|
+
models: XIAOMI_TTS_MODELS,
|
|
209
|
+
voices: XIAOMI_TTS_VOICES,
|
|
210
|
+
resolveConfig: ({ rawConfig }) => normalizeXiaomiTtsProviderConfig(rawConfig),
|
|
211
|
+
parseDirectiveToken,
|
|
212
|
+
listVoices: async () => XIAOMI_TTS_VOICES.map((voice) => ({
|
|
213
|
+
id: voice,
|
|
214
|
+
name: voice
|
|
215
|
+
})),
|
|
216
|
+
isConfigured: ({ providerConfig }) => Boolean(resolveXiaomiTtsProviderConfig(providerConfig).apiKey),
|
|
217
|
+
synthesize: async (req) => {
|
|
218
|
+
const config = resolveXiaomiTtsProviderConfig(req.providerConfig);
|
|
219
|
+
const overrides = readXiaomiTtsOverrides(req.providerOverrides);
|
|
220
|
+
if (!config.apiKey) throw new Error("Xiaomi API key missing");
|
|
221
|
+
const outputFormat = overrides.format ?? config.format;
|
|
222
|
+
const audioBuffer = await xiaomiTTS({
|
|
223
|
+
text: req.text,
|
|
224
|
+
apiKey: config.apiKey,
|
|
225
|
+
baseUrl: config.baseUrl,
|
|
226
|
+
model: overrides.model ?? config.model,
|
|
227
|
+
voice: overrides.voice ?? config.voice,
|
|
228
|
+
format: outputFormat,
|
|
229
|
+
style: overrides.style ?? config.style,
|
|
230
|
+
timeoutMs: req.timeoutMs
|
|
231
|
+
});
|
|
232
|
+
if (req.target === "voice-note") return {
|
|
233
|
+
audioBuffer: await transcodeAudioBufferToOpus({
|
|
234
|
+
audioBuffer,
|
|
235
|
+
inputExtension: outputFormat,
|
|
236
|
+
tempPrefix: "tts-xiaomi-",
|
|
237
|
+
timeoutMs: req.timeoutMs
|
|
238
|
+
}),
|
|
239
|
+
outputFormat: "opus",
|
|
240
|
+
fileExtension: ".opus",
|
|
241
|
+
voiceCompatible: true
|
|
242
|
+
};
|
|
243
|
+
return {
|
|
244
|
+
audioBuffer,
|
|
245
|
+
outputFormat,
|
|
246
|
+
fileExtension: `.${outputFormat}`,
|
|
247
|
+
voiceCompatible: false
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
//#endregion
|
|
253
|
+
export { buildXiaomiSpeechProvider };
|
package/dist/stream.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { isMiMoReasoningModelRef } from "./thinking.js";
|
|
2
|
+
import { createDeepSeekV4OpenAICompatibleThinkingWrapper } from "openclaw/plugin-sdk/provider-stream-shared";
|
|
3
|
+
//#region extensions/xiaomi/stream.ts
|
|
4
|
+
function createMiMoThinkingWrapper(baseStreamFn, thinkingLevel) {
|
|
5
|
+
return createDeepSeekV4OpenAICompatibleThinkingWrapper({
|
|
6
|
+
baseStreamFn,
|
|
7
|
+
thinkingLevel,
|
|
8
|
+
shouldPatchModel: isMiMoReasoningModelRef
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { createMiMoThinkingWrapper };
|
package/dist/thinking.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import "./provider-catalog-B3wdBKTb.js";
|
|
2
|
+
//#region extensions/xiaomi/thinking.ts
|
|
3
|
+
const MIMO_REASONING_MODEL_IDS = /* @__PURE__ */ new Set([
|
|
4
|
+
"mimo-v2.5",
|
|
5
|
+
"mimo-v2.5-pro",
|
|
6
|
+
"mimo-v2.6-pro"
|
|
7
|
+
]);
|
|
8
|
+
function isMiMoReasoningModelId(modelId) {
|
|
9
|
+
return MIMO_REASONING_MODEL_IDS.has(modelId.toLowerCase());
|
|
10
|
+
}
|
|
11
|
+
function isMiMoProviderId(providerId) {
|
|
12
|
+
return providerId === "xiaomi" || providerId === "xiaomi-token-plan";
|
|
13
|
+
}
|
|
14
|
+
function isMiMoReasoningModelRef(model) {
|
|
15
|
+
return isMiMoProviderId(model.provider) && typeof model.id === "string" && isMiMoReasoningModelId(model.id);
|
|
16
|
+
}
|
|
17
|
+
const MIMO_THINKING_PROFILE = {
|
|
18
|
+
levels: [
|
|
19
|
+
"off",
|
|
20
|
+
"minimal",
|
|
21
|
+
"low",
|
|
22
|
+
"medium",
|
|
23
|
+
"high",
|
|
24
|
+
"xhigh",
|
|
25
|
+
"max"
|
|
26
|
+
].map((id) => ({ id })),
|
|
27
|
+
defaultLevel: "high"
|
|
28
|
+
};
|
|
29
|
+
function resolveMiMoThinkingProfile(modelId) {
|
|
30
|
+
return isMiMoReasoningModelId(modelId) ? MIMO_THINKING_PROFILE : void 0;
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { isMiMoReasoningModelRef, resolveMiMoThinkingProfile };
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "xiaomi",
|
|
3
|
+
"icon": "https://cdn.simpleicons.org/xiaomi",
|
|
4
|
+
"activation": {
|
|
5
|
+
"onStartup": false
|
|
6
|
+
},
|
|
7
|
+
"enabledByDefault": true,
|
|
8
|
+
"providers": ["xiaomi", "xiaomi-token-plan"],
|
|
9
|
+
"autoEnableWhenConfiguredProviders": ["xiaomi", "xiaomi-token-plan"],
|
|
10
|
+
"setup": {
|
|
11
|
+
"providers": [
|
|
12
|
+
{
|
|
13
|
+
"id": "xiaomi",
|
|
14
|
+
"envVars": ["XIAOMI_API_KEY"]
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"id": "xiaomi-token-plan",
|
|
18
|
+
"envVars": ["XIAOMI_TOKEN_PLAN_API_KEY"]
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
|
+
},
|
|
22
|
+
"modelCatalog": {
|
|
23
|
+
"providers": {
|
|
24
|
+
"xiaomi": {
|
|
25
|
+
"baseUrl": "https://api.xiaomimimo.com/v1",
|
|
26
|
+
"api": "openai-completions",
|
|
27
|
+
"models": [
|
|
28
|
+
{
|
|
29
|
+
"id": "mimo-v2.5",
|
|
30
|
+
"name": "Xiaomi MiMo V2.5",
|
|
31
|
+
"input": ["text", "image"],
|
|
32
|
+
"reasoning": true,
|
|
33
|
+
"contextWindow": 1048576,
|
|
34
|
+
"maxTokens": 131072,
|
|
35
|
+
"cost": {
|
|
36
|
+
"input": 0.14,
|
|
37
|
+
"output": 0.28,
|
|
38
|
+
"cacheRead": 0.0028,
|
|
39
|
+
"cacheWrite": 0
|
|
40
|
+
},
|
|
41
|
+
"compat": { "codeMode": "preferred" }
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"id": "mimo-v2.5-pro",
|
|
45
|
+
"name": "Xiaomi MiMo V2.5 Pro",
|
|
46
|
+
"input": ["text"],
|
|
47
|
+
"reasoning": true,
|
|
48
|
+
"contextWindow": 1048576,
|
|
49
|
+
"maxTokens": 131072,
|
|
50
|
+
"cost": {
|
|
51
|
+
"input": 0.435,
|
|
52
|
+
"output": 0.87,
|
|
53
|
+
"cacheRead": 0.0036,
|
|
54
|
+
"cacheWrite": 0
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
},
|
|
59
|
+
"xiaomi-token-plan": {
|
|
60
|
+
"baseUrl": "https://token-plan-sgp.xiaomimimo.com/v1",
|
|
61
|
+
"api": "openai-completions",
|
|
62
|
+
"models": [
|
|
63
|
+
{
|
|
64
|
+
"id": "mimo-v2.5-pro",
|
|
65
|
+
"name": "Xiaomi MiMo V2.5 Pro",
|
|
66
|
+
"input": ["text"],
|
|
67
|
+
"reasoning": true,
|
|
68
|
+
"contextWindow": 1048576,
|
|
69
|
+
"maxTokens": 131072,
|
|
70
|
+
"cost": { "input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0 }
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"id": "mimo-v2.5",
|
|
74
|
+
"name": "Xiaomi MiMo V2.5",
|
|
75
|
+
"input": ["text", "image"],
|
|
76
|
+
"reasoning": true,
|
|
77
|
+
"contextWindow": 1048576,
|
|
78
|
+
"maxTokens": 131072,
|
|
79
|
+
"cost": { "input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0 },
|
|
80
|
+
"compat": { "codeMode": "preferred" }
|
|
81
|
+
}
|
|
82
|
+
]
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
"discovery": {
|
|
86
|
+
"xiaomi": "refreshable",
|
|
87
|
+
"xiaomi-token-plan": "refreshable"
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
"providerEndpoints": [
|
|
91
|
+
{
|
|
92
|
+
"endpointClass": "xiaomi-native",
|
|
93
|
+
"hosts": [
|
|
94
|
+
"api.xiaomimimo.com",
|
|
95
|
+
"token-plan-ams.xiaomimimo.com",
|
|
96
|
+
"token-plan-cn.xiaomimimo.com",
|
|
97
|
+
"token-plan-sgp.xiaomimimo.com"
|
|
98
|
+
]
|
|
99
|
+
}
|
|
100
|
+
],
|
|
101
|
+
"contracts": {
|
|
102
|
+
"speechProviders": ["xiaomi", "mimo"],
|
|
103
|
+
"usageProviders": ["xiaomi", "xiaomi-token-plan"]
|
|
104
|
+
},
|
|
105
|
+
"providerAuthChoices": [
|
|
106
|
+
{
|
|
107
|
+
"provider": "xiaomi",
|
|
108
|
+
"method": "api-key",
|
|
109
|
+
"choiceId": "xiaomi-api-key",
|
|
110
|
+
"appGuidedSecret": true,
|
|
111
|
+
"choiceLabel": "Xiaomi API key (Pay-as-you-go)",
|
|
112
|
+
"groupId": "xiaomi",
|
|
113
|
+
"groupLabel": "Xiaomi",
|
|
114
|
+
"groupHint": "Pay-as-you-go / Token Plan",
|
|
115
|
+
"optionKey": "xiaomiApiKey",
|
|
116
|
+
"cliFlag": "--xiaomi-api-key",
|
|
117
|
+
"cliOption": "--xiaomi-api-key <key>",
|
|
118
|
+
"cliDescription": "Xiaomi MiMo pay-as-you-go API key"
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
"provider": "xiaomi-token-plan",
|
|
122
|
+
"method": "token-plan-ams",
|
|
123
|
+
"choiceId": "xiaomi-token-plan-ams",
|
|
124
|
+
"appGuidedSecret": true,
|
|
125
|
+
"choiceLabel": "Xiaomi Token Plan (Europe)",
|
|
126
|
+
"choiceHint": "Endpoint preset: token-plan-ams.xiaomimimo.com/v1",
|
|
127
|
+
"groupId": "xiaomi",
|
|
128
|
+
"groupLabel": "Xiaomi",
|
|
129
|
+
"groupHint": "Pay-as-you-go / Token Plan",
|
|
130
|
+
"optionKey": "xiaomiTokenPlanApiKey",
|
|
131
|
+
"cliFlag": "--xiaomi-token-plan-api-key",
|
|
132
|
+
"cliOption": "--xiaomi-token-plan-api-key <key>",
|
|
133
|
+
"cliDescription": "Xiaomi MiMo Token Plan API key"
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
"provider": "xiaomi-token-plan",
|
|
137
|
+
"method": "token-plan-cn",
|
|
138
|
+
"choiceId": "xiaomi-token-plan-cn",
|
|
139
|
+
"appGuidedSecret": true,
|
|
140
|
+
"choiceLabel": "Xiaomi Token Plan (China)",
|
|
141
|
+
"choiceHint": "Endpoint preset: token-plan-cn.xiaomimimo.com/v1",
|
|
142
|
+
"groupId": "xiaomi",
|
|
143
|
+
"groupLabel": "Xiaomi",
|
|
144
|
+
"groupHint": "Pay-as-you-go / Token Plan",
|
|
145
|
+
"optionKey": "xiaomiTokenPlanApiKey",
|
|
146
|
+
"cliFlag": "--xiaomi-token-plan-api-key",
|
|
147
|
+
"cliOption": "--xiaomi-token-plan-api-key <key>",
|
|
148
|
+
"cliDescription": "Xiaomi MiMo Token Plan API key"
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
"provider": "xiaomi-token-plan",
|
|
152
|
+
"method": "token-plan-sgp",
|
|
153
|
+
"choiceId": "xiaomi-token-plan-sgp",
|
|
154
|
+
"appGuidedSecret": true,
|
|
155
|
+
"choiceLabel": "Xiaomi Token Plan (Singapore)",
|
|
156
|
+
"choiceHint": "Endpoint preset: token-plan-sgp.xiaomimimo.com/v1",
|
|
157
|
+
"groupId": "xiaomi",
|
|
158
|
+
"groupLabel": "Xiaomi",
|
|
159
|
+
"groupHint": "Pay-as-you-go / Token Plan",
|
|
160
|
+
"optionKey": "xiaomiTokenPlanApiKey",
|
|
161
|
+
"cliFlag": "--xiaomi-token-plan-api-key",
|
|
162
|
+
"cliOption": "--xiaomi-token-plan-api-key <key>",
|
|
163
|
+
"cliDescription": "Xiaomi MiMo Token Plan API key"
|
|
164
|
+
}
|
|
165
|
+
],
|
|
166
|
+
"configSchema": {
|
|
167
|
+
"type": "object",
|
|
168
|
+
"additionalProperties": false,
|
|
169
|
+
"properties": {}
|
|
170
|
+
}
|
|
171
|
+
}
|
package/package.json
CHANGED
|
@@ -1,14 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openclaw/xiaomi-provider",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
5
|
-
"license": "MIT",
|
|
3
|
+
"version": "2026.8.1-beta.3",
|
|
4
|
+
"description": "OpenClaw Xiaomi provider plugin.",
|
|
6
5
|
"repository": {
|
|
7
6
|
"type": "git",
|
|
8
|
-
"url": "
|
|
7
|
+
"url": "https://github.com/openclaw/openclaw"
|
|
9
8
|
},
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
"
|
|
13
|
-
|
|
9
|
+
"type": "module",
|
|
10
|
+
"openclaw": {
|
|
11
|
+
"extensions": [
|
|
12
|
+
"./index.ts"
|
|
13
|
+
],
|
|
14
|
+
"install": {
|
|
15
|
+
"clawhubSpec": "clawhub:@openclaw/xiaomi-provider",
|
|
16
|
+
"npmSpec": "@openclaw/xiaomi-provider",
|
|
17
|
+
"defaultChoice": "npm",
|
|
18
|
+
"minHostVersion": ">=2026.7.2"
|
|
19
|
+
},
|
|
20
|
+
"compat": {
|
|
21
|
+
"pluginApi": ">=2026.8.1-beta.3"
|
|
22
|
+
},
|
|
23
|
+
"build": {
|
|
24
|
+
"openclawVersion": "2026.8.1-beta.3",
|
|
25
|
+
"bundledDist": false
|
|
26
|
+
},
|
|
27
|
+
"release": {
|
|
28
|
+
"publishToClawHub": true,
|
|
29
|
+
"publishToNpm": true
|
|
30
|
+
},
|
|
31
|
+
"runtimeExtensions": [
|
|
32
|
+
"./dist/index.js"
|
|
33
|
+
]
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist/**",
|
|
37
|
+
"openclaw.plugin.json",
|
|
38
|
+
"README.md"
|
|
39
|
+
],
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"openclaw": ">=2026.8.1-beta.3"
|
|
42
|
+
},
|
|
43
|
+
"peerDependenciesMeta": {
|
|
44
|
+
"openclaw": {
|
|
45
|
+
"optional": true
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"bundledDependencies": []
|
|
14
49
|
}
|