Skip to content

Commit 521d05f

Browse files
authored
fix(cli): harden infer provider workflows (#115054)
1 parent 97c19a9 commit 521d05f

7 files changed

Lines changed: 184 additions & 6 deletions

File tree

‎docs/cli/infer.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ Speech synthesis and TTS provider/persona state.
214214
```bash
215215
openclaw infer tts convert --text "hello from openclaw" --output ./hello.mp3 --json
216216
openclaw infer tts convert --text "Your build is complete" --output ./build-complete.mp3 --json
217+
openclaw infer tts convert --provider xiaomi --text "Provider-only selection" --output ./xiaomi.mp3 --json
217218
openclaw infer tts providers --json
218219
openclaw infer tts personas --json
219220
openclaw infer tts status --json
@@ -222,6 +223,7 @@ openclaw infer tts status --json
222223
Notes:
223224

224225
- `tts status` only supports `--gateway` (it reflects gateway-managed TTS state).
226+
- Use `tts convert --provider <id>` when selecting a provider without overriding its model.
225227
- Use `tts providers`, `tts voices`, `tts personas`, `tts set-provider`, and `tts set-persona` to inspect and configure TTS behavior.
226228

227229
## Video

‎src/agents/embedded-agent-runner/model.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,7 @@ describe("resolveModel", () => {
834834
modelId: "mistral-medium-3-5",
835835
cfg: undefined,
836836
workspaceDir: undefined,
837+
includeRuntimeDiscovery: true,
837838
});
838839
expect(resolveBundledProviderStaticCatalogModelMock).not.toHaveBeenCalled();
839840
expect(discoverAuthStorage).not.toHaveBeenCalled();
@@ -880,6 +881,7 @@ describe("resolveModel", () => {
880881
modelId: "gemini-3.1-pro-preview",
881882
cfg: undefined,
882883
workspaceDir: undefined,
884+
includeRuntimeDiscovery: true,
883885
});
884886
expect(resolveBundledProviderStaticCatalogModelMock).toHaveBeenCalledWith({
885887
provider: "google",
@@ -1180,12 +1182,14 @@ describe("resolveModel", () => {
11801182
modelId: "claude-haiku-4-5",
11811183
cfg: undefined,
11821184
workspaceDir: undefined,
1185+
includeRuntimeDiscovery: true,
11831186
});
11841187
expect(resolveBundledStaticCatalogModelMock).toHaveBeenCalledWith({
11851188
provider: "openai",
11861189
modelId: "gpt-4o",
11871190
cfg: undefined,
11881191
workspaceDir: undefined,
1192+
includeRuntimeDiscovery: true,
11891193
});
11901194
expect(resolveBundledStaticCatalogModelMock).not.toHaveBeenCalledWith(
11911195
expect.objectContaining({
@@ -1305,6 +1309,7 @@ describe("resolveModel", () => {
13051309
modelId: "gpt-5.5-pro",
13061310
cfg: undefined,
13071311
workspaceDir: undefined,
1312+
includeRuntimeDiscovery: true,
13081313
});
13091314
});
13101315

‎src/agents/embedded-agent-runner/model.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ export async function resolveModelAsync(
305305
modelId: normalizedRef.model,
306306
cfg,
307307
workspaceDir,
308+
includeRuntimeDiscovery: true,
308309
});
309310
if (manifestModel) {
310311
return manifestModel;

‎src/cli/capability-cli.test.ts‎

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ const mocks = vi.hoisted(() => ({
3535
loadAuthProfileStoreForRuntime: vi.fn(() => ({ profiles: {}, order: {} })),
3636
listProfilesForProvider: vi.fn(() => []),
3737
resolveApiKeyForProvider: vi.fn(),
38+
loadManifestMetadataSnapshot: vi.fn(() => ({ manifestRegistry: { plugins: [] } })),
39+
planEffectiveModelCatalogRows: vi.fn<
40+
typeof import("../model-catalog/index.js").planEffectiveModelCatalogRows
41+
>(() => ({ rows: [], entries: [], conflicts: [] })),
3842
resolveAgentDir: vi.fn((_cfg: unknown, agentId: string) => `/tmp/agent-${agentId}`),
3943
updateAuthProfileStoreWithLock: vi.fn(
4044
async ({ updater }: { updater: (store: any) => boolean }) => {
@@ -233,6 +237,14 @@ vi.mock("../config/config.js", () => ({
233237
mocks.setRuntimeConfigSnapshot as typeof import("../config/config.js").setRuntimeConfigSnapshot,
234238
}));
235239

240+
vi.mock("../model-catalog/index.js", () => ({
241+
planEffectiveModelCatalogRows: mocks.planEffectiveModelCatalogRows,
242+
}));
243+
244+
vi.mock("../plugins/manifest-contract-eligibility.js", () => ({
245+
loadManifestMetadataSnapshot: mocks.loadManifestMetadataSnapshot,
246+
}));
247+
236248
vi.mock("./command-config-resolution.js", () => ({
237249
resolveCommandConfigWithSecrets: mocks.resolveCommandConfigWithSecrets,
238250
}));
@@ -385,6 +397,9 @@ vi.mock("../tts/tts.js", () => ({
385397
vi.mock("../tts/provider-registry.js", () => ({
386398
canonicalizeSpeechProviderId: vi.fn((provider: string) => provider),
387399
listSpeechProviders: vi.fn(() => []),
400+
normalizeSpeechProviderId: vi.fn(
401+
(provider: string | undefined) => provider?.trim().toLowerCase() || undefined,
402+
),
388403
}));
389404

390405
vi.mock("../web-search/runtime.js", () => ({
@@ -494,6 +509,12 @@ describe("capability cli", () => {
494509
mocks.loadAuthProfileStoreForRuntime.mockReset().mockReturnValue({ profiles: {}, order: {} });
495510
mocks.listProfilesForProvider.mockReset().mockReturnValue([]);
496511
mocks.resolveApiKeyForProvider.mockReset().mockRejectedValue(new Error("no auth profile"));
512+
mocks.loadManifestMetadataSnapshot
513+
.mockReset()
514+
.mockReturnValue({ manifestRegistry: { plugins: [] } });
515+
mocks.planEffectiveModelCatalogRows
516+
.mockReset()
517+
.mockReturnValue({ rows: [], entries: [], conflicts: [] });
497518
mocks.resolveAgentDir.mockClear();
498519
mocks.resolveTtsConfig.mockReset().mockReturnValue({});
499520
mocks.getRuntimeConfigSourceSnapshot.mockReset().mockReturnValue(null);
@@ -752,6 +773,61 @@ describe("capability cli", () => {
752773
expect(ids).toContain("image.describe");
753774
});
754775

776+
it.each([
777+
["list", []],
778+
["inspect", ["--model", "openai/gpt-5.4"]],
779+
["providers", []],
780+
] as const)("keeps model %s catalog inspection read-only", async (command, args) => {
781+
await runCap("capability", "model", command, ...args, "--json");
782+
783+
expect(mocks.loadModelCatalog).toHaveBeenCalledWith({
784+
config: mocks.loadConfig(),
785+
readOnly: true,
786+
});
787+
});
788+
789+
it("reports model providers configured through their environment key", async () => {
790+
vi.stubEnv("OPENAI_API_KEY", "test-openai-key");
791+
792+
await runCap("capability", "model", "providers", "--json");
793+
794+
const providers = firstJsonOutput() as unknown as Array<{
795+
configured?: boolean;
796+
provider?: string;
797+
}>;
798+
expect(providers).toContainEqual(
799+
expect.objectContaining({ provider: "openai", configured: true }),
800+
);
801+
expect(mocks.getProviderEnvVars).toHaveBeenCalledWith("openai");
802+
});
803+
804+
it("inspects runtime-declared manifest models without live discovery", async () => {
805+
mocks.loadModelCatalog.mockResolvedValueOnce([] as never);
806+
mocks.planEffectiveModelCatalogRows.mockReturnValueOnce({
807+
rows: [
808+
{
809+
provider: "openai",
810+
id: "gpt-5.6-sol",
811+
name: "GPT-5.6 Sol",
812+
ref: "openai/gpt-5.6-sol",
813+
mergeKey: "openai/gpt-5.6-sol",
814+
source: "manifest",
815+
input: ["text"],
816+
reasoning: true,
817+
status: "available",
818+
},
819+
],
820+
entries: [],
821+
conflicts: [],
822+
});
823+
824+
await runCap("capability", "model", "inspect", "--model", "openai/gpt-5.6-sol", "--json");
825+
826+
expect(firstJsonOutput()).toEqual(
827+
expect.objectContaining({ provider: "openai", id: "gpt-5.6-sol" }),
828+
);
829+
});
830+
755831
it("defaults model run to local transport", async () => {
756832
await runCap("capability", "model", "run", "--prompt", "hello", "--json");
757833

@@ -2674,6 +2750,62 @@ describe("capability cli", () => {
26742750
expect(firstTextToSpeechCall()?.disableFallback).toBe(true);
26752751
});
26762752

2753+
it("selects a TTS provider without inventing a model override", async () => {
2754+
await runCap(
2755+
"capability",
2756+
"tts",
2757+
"convert",
2758+
"--text",
2759+
"hello",
2760+
"--provider",
2761+
"xiaomi",
2762+
"--json",
2763+
);
2764+
2765+
expect(mocks.resolveExplicitTtsOverrides).toHaveBeenCalledWith(
2766+
expect.objectContaining({ provider: "xiaomi", modelId: undefined }),
2767+
);
2768+
expect(firstTextToSpeechCall()?.disableFallback).toBe(true);
2769+
});
2770+
2771+
it("rejects conflicting TTS provider and model selections", async () => {
2772+
await expect(
2773+
runCap(
2774+
"capability",
2775+
"tts",
2776+
"convert",
2777+
"--text",
2778+
"hello",
2779+
"--provider",
2780+
"xiaomi",
2781+
"--model",
2782+
"openai/gpt-4o-mini-tts",
2783+
"--json",
2784+
),
2785+
).rejects.toThrow("exit 1");
2786+
2787+
expectRuntimeErrorContains("TTS --provider must match the provider in --model.");
2788+
});
2789+
2790+
it("accepts equivalent TTS provider casing with a model selection", async () => {
2791+
await runCap(
2792+
"capability",
2793+
"tts",
2794+
"convert",
2795+
"--text",
2796+
"hello",
2797+
"--provider",
2798+
"OpenAI",
2799+
"--model",
2800+
"openai/gpt-4o-mini-tts",
2801+
"--json",
2802+
);
2803+
2804+
expect(mocks.resolveExplicitTtsOverrides).toHaveBeenCalledWith(
2805+
expect.objectContaining({ provider: "openai", modelId: "gpt-4o-mini-tts" }),
2806+
);
2807+
});
2808+
26772809
it("does not infer and forward a local provider guess for gateway TTS overrides", async () => {
26782810
await runCap(
26792811
"capability",

‎src/cli/capability-cli/metadata.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ export const CAPABILITY_METADATA: CapabilityMetadata[] = [
159159
"--text",
160160
"--channel",
161161
"--voice",
162+
"--provider",
162163
"--model",
163164
"--output",
164165
"--local",

‎src/cli/capability-cli/model.ts‎

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ import type { OpenClawConfig } from "../../config/types.openclaw.js";
3232
import { callGateway, randomIdempotencyKey } from "../../gateway/call.js";
3333
import { ADMIN_SCOPE } from "../../gateway/operator-scopes.js";
3434
import { convertHeicToJpeg } from "../../media/media-services.js";
35+
import { planEffectiveModelCatalogRows } from "../../model-catalog/index.js";
36+
import { loadManifestMetadataSnapshot } from "../../plugins/manifest-contract-eligibility.js";
3537
import { defaultRuntime } from "../../runtime.js";
38+
import { getProviderEnvVars } from "../../secrets/provider-env-vars.js";
3639
import { runCommandWithRuntime } from "../cli-utils.js";
3740
import { getModelsCommandSecretTargetIds } from "../command-secret-targets.js";
3841
import { collectOption } from "../program/helpers.js";
@@ -51,6 +54,25 @@ import {
5154
const LOCAL_MODEL_RUN_SYSTEM_PROMPT = "You are a personal assistant running inside OpenClaw.";
5255
const HEIC_MODEL_RUN_MIMES = new Set(["image/heic", "image/heif"]);
5356

57+
async function loadModelCatalogForInspection(cfg: OpenClawConfig) {
58+
const prepared = await loadPreparedModelCatalog({ config: cfg, readOnly: true });
59+
const metadataSnapshot = loadManifestMetadataSnapshot({ config: cfg, env: process.env });
60+
const manifest = planEffectiveModelCatalogRows({
61+
registry: metadataSnapshot.manifestRegistry,
62+
config: cfg,
63+
}).rows;
64+
const entries = new Map<string, (typeof prepared)[number] | (typeof manifest)[number]>();
65+
for (const entry of manifest) {
66+
entries.set(`${entry.provider}\0${entry.id}`, entry);
67+
}
68+
for (const entry of prepared) {
69+
entries.set(`${entry.provider}\0${entry.id}`, entry);
70+
}
71+
return [...entries.values()].toSorted(
72+
(a, b) => a.provider.localeCompare(b.provider) || a.id.localeCompare(b.id),
73+
);
74+
}
75+
5476
async function canonicalizeModelRunRef(params: {
5577
raw: string | undefined;
5678
cfg: OpenClawConfig;
@@ -324,7 +346,7 @@ async function runModelRun(params: {
324346

325347
async function buildModelProviders() {
326348
const cfg = getRuntimeConfig();
327-
const catalog = await loadPreparedModelCatalog({ config: cfg });
349+
const catalog = await loadModelCatalogForInspection(cfg);
328350
const selectedProvider = resolveSelectedProviderFromModelRef(
329351
resolveAgentModelPrimaryValue(cfg.agents?.defaults?.model),
330352
);
@@ -345,7 +367,11 @@ async function buildModelProviders() {
345367
count: 0,
346368
defaults: [],
347369
available: true,
348-
configured: providerHasGenericConfig({ cfg, providerId: entry.provider }),
370+
configured: providerHasGenericConfig({
371+
cfg,
372+
providerId: entry.provider,
373+
envVars: getProviderEnvVars(entry.provider),
374+
}),
349375
selected: selectedProvider === entry.provider,
350376
};
351377
current.count += 1;
@@ -458,7 +484,7 @@ export function registerModelCapabilityCommands(capability: Command): void {
458484
.option("--json", "Output JSON", false)
459485
.action(async (opts) => {
460486
await runCommandWithRuntime(defaultRuntime, async () => {
461-
const result = await loadPreparedModelCatalog({ config: getRuntimeConfig() });
487+
const result = await loadModelCatalogForInspection(getRuntimeConfig());
462488
emitJsonOrText(defaultRuntime, Boolean(opts.json), result, providerSummaryText);
463489
});
464490
});
@@ -471,7 +497,7 @@ export function registerModelCapabilityCommands(capability: Command): void {
471497
.action(async (opts) => {
472498
await runCommandWithRuntime(defaultRuntime, async () => {
473499
const target = normalizeStringifiedOptionalString(opts.model) ?? "";
474-
const catalog = await loadPreparedModelCatalog({ config: getRuntimeConfig() });
500+
const catalog = await loadModelCatalogForInspection(getRuntimeConfig());
475501
const entry =
476502
catalog.find((candidate) => `${candidate.provider}/${candidate.id}` === target) ??
477503
catalog.find((candidate) => candidate.id === target);

‎src/cli/capability-cli/tts.ts‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Command } from "commander";
22
import { callGateway } from "../../gateway/call.js";
33
import { defaultRuntime } from "../../runtime.js";
4+
import { normalizeSpeechProviderId } from "../../tts/provider-registry.js";
45
import { runCommandWithRuntime } from "../cli-utils.js";
56
import {
67
emitJsonOrText,
@@ -26,6 +27,7 @@ export function registerTtsCapabilityCommands(capability: Command): void {
2627
.requiredOption("--text <text>", "Input text")
2728
.option("--channel <id>", "Channel hint")
2829
.option("--voice <id>", "Voice hint")
30+
.option("--provider <id>", "Speech provider id")
2931
.option("--model <provider/model>", "Model override")
3032
.option("--output <path>", "Output path")
3133
.option("--local", "Force local execution", false)
@@ -43,11 +45,20 @@ export function registerTtsCapabilityCommands(capability: Command): void {
4345
if (opts.model && !modelRef.provider) {
4446
throw new Error("TTS model overrides must use the form <provider/model>.");
4547
}
48+
const provider = normalizeSpeechProviderId(
49+
typeof opts.provider === "string" && opts.provider.trim()
50+
? opts.provider.trim()
51+
: modelRef.provider,
52+
);
53+
const modelProvider = normalizeSpeechProviderId(modelRef.provider);
54+
if (provider && modelProvider && provider !== modelProvider) {
55+
throw new Error("TTS --provider must match the provider in --model.");
56+
}
4657
const result = await runTtsConvert({
4758
text: String(opts.text),
4859
channel: opts.channel as string | undefined,
49-
provider: modelRef.provider,
50-
modelId: modelRef.provider ? modelRef.model : undefined,
60+
provider,
61+
modelId: modelProvider ? modelRef.model : undefined,
5162
voiceId: opts.voice as string | undefined,
5263
output: opts.output as string | undefined,
5364
transport,

0 commit comments

Comments
 (0)