Skip to content

Commit 990fdcf

Browse files
authored
fix(providers): recognize configured media credentials across provider boundaries (#118761)
* fix(providers): honor configured media credentials across owner boundaries * test(providers): align configured auth fixtures and derived SDK surfaces * fix(providers): enforce shared DashScope media credential policy
1 parent 25aa29d commit 990fdcf

41 files changed

Lines changed: 1255 additions & 178 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎docs/.generated/plugin-sdk-api-baseline.sha256‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ dea96213010cbc816345b1229534f1acb8b0bcfdbd7814c62eefc77030fa9cd8 module/core
6363
f70c93d28053ca2e8353e45e6515ce7acef188097c6117d1545965d0699c8004 module/device-bootstrap
6464
68c726280f6585af96c071758ba383e55480b4fc913eae7c26aea1af331dedf3 module/diagnostic-runtime
6565
ea81ef06956c1bc0853fa00afbbc2b5a4019116aaf8a436e1b27d06f7a2c9e88 module/directory-runtime
66-
e8adcff47c1b677cd2c01a2130fe4d226ac30ab3c88a3ceb4df5a8660316c4a9 module/discord
66+
086bb46f97cb1f4a040b602444daf2c47ac2c24aca150a0d238933956a8100fc module/discord
6767
f65408d85477bb362ebe6ed9148c1bb6b9eb7839733e5e3119f4ff8f1cfd0567 module/error-runtime
6868
b013053a61e7d9be3d0c683c02baf57fa7e4393ec54e0df6a46ab0f2fe2348fd module/extension-shared
6969
ceacad83db01c66e7be6aa21a291597020f13f737b697690eae7d47098e6499a module/gateway-method-runtime
@@ -100,7 +100,7 @@ ea56ea0455c62f292e1c7b3e56cac6eb3fea00e548f9ab2f4a69e0b41b0a2d96 module/memory-
100100
987648ebe317cc4d6c0505a52d344b12ce9c3a8261a5bd969cee3423c0c53529 module/plugin-config-runtime
101101
d7dd3c82a4b1df9e4144b078caf0e6ab95e7b11c5046b53a38f01143a7fa0eec module/plugin-entry
102102
8bc85c9f7df434c87cd7d35cc33080e2577a1893353f92bff8a0cc63d2c4eb0e module/plugin-runtime
103-
9c9670596f6dee29ec7cdcb0616cefbcd50facbf71413bec4f7c63de8f4d5469 module/provider-auth
103+
de508df6d9cfa9d21c4524989dd8bd142fb60cb4ae980193e0907767d76e6022 module/provider-auth
104104
71bebeac51e701cd7c8e63d22754b9bcbd82b024aced303aa055d229781129d7 module/provider-catalog-runtime
105105
56151035047a69e6163d5578023d00f51a2413b777f3784af88e06261c039345 module/proxy-capture
106106
aa2a56b4448c8ebdec9d06aac95d809995f533093d42fa32cd75e1d852967245 module/question-gateway-runtime

‎extensions/alibaba/video-generation-provider.test.ts‎

Lines changed: 202 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
// Alibaba tests cover video generation provider plugin behavior.
2+
import fs from "node:fs/promises";
3+
import os from "node:os";
4+
import path from "node:path";
5+
import {
6+
clearRuntimeAuthProfileStoreSnapshots,
7+
saveAuthProfileStore,
8+
} from "openclaw/plugin-sdk/agent-runtime";
29
import {
310
getProviderHttpMocks,
411
installProviderHttpMockCleanup,
@@ -13,9 +20,10 @@ import {
1320
DASHSCOPE_WAN_VIDEO_MODELS,
1421
DEFAULT_DASHSCOPE_WAN_VIDEO_MODEL,
1522
} from "openclaw/plugin-sdk/video-generation";
16-
import { beforeAll, describe, expect, it } from "vitest";
23+
import { afterEach, beforeAll, describe, expect, it, vi } from "vitest";
1724

1825
const {
26+
resolveApiKeyForProviderMock,
1927
postJsonRequestMock,
2028
fetchWithTimeoutMock,
2129
fetchWithTimeoutGuardedMock,
@@ -31,6 +39,17 @@ beforeAll(async () => {
3139

3240
installProviderHttpMockCleanup();
3341

42+
afterEach(() => {
43+
clearRuntimeAuthProfileStoreSnapshots();
44+
vi.unstubAllEnvs();
45+
});
46+
47+
function clearAlibabaAuthEnvironment(): void {
48+
for (const name of ["MODELSTUDIO_API_KEY", "DASHSCOPE_API_KEY", "QWEN_API_KEY"]) {
49+
vi.stubEnv(name, "");
50+
}
51+
}
52+
3453
function requireRecord(value: unknown, label: string): Record<string, unknown> {
3554
if (value === null || typeof value !== "object" || Array.isArray(value)) {
3655
throw new Error(`expected ${label} to be a record`);
@@ -57,6 +76,188 @@ describe("alibaba video generation provider", () => {
5776
});
5877
});
5978

79+
it.each(["sk-ws-alibaba-standard-key", "sk-alibaba-legacy-standard-key"])(
80+
"advertises Wan video generation with config-only Standard API key %s",
81+
(apiKey) => {
82+
clearAlibabaAuthEnvironment();
83+
84+
expect(
85+
alibabaVideoGenerationProvider.isConfigured?.({
86+
cfg: {
87+
models: {
88+
providers: {
89+
alibaba: {
90+
apiKey,
91+
baseUrl: "https://dashscope-intl.aliyuncs.com",
92+
models: [],
93+
},
94+
},
95+
},
96+
},
97+
}),
98+
).toBe(true);
99+
},
100+
);
101+
102+
it("does not use Qwen Coding Plan credentials for Alibaba video discovery", () => {
103+
clearAlibabaAuthEnvironment();
104+
105+
expect(
106+
alibabaVideoGenerationProvider.isConfigured?.({
107+
cfg: {
108+
models: {
109+
providers: {
110+
qwen: {
111+
apiKey: "qwen-coding-plan-key",
112+
baseUrl: "https://coding-intl.dashscope.aliyuncs.com/v1",
113+
models: [],
114+
},
115+
},
116+
},
117+
},
118+
}),
119+
).toBe(false);
120+
});
121+
122+
it.each(["", "oauth:alibaba", "custom-local", "secretref-managed"])(
123+
"does not advertise a non-secret Alibaba credential marker %j",
124+
(apiKey) => {
125+
clearAlibabaAuthEnvironment();
126+
127+
expect(
128+
alibabaVideoGenerationProvider.isConfigured?.({
129+
cfg: {
130+
models: {
131+
providers: {
132+
alibaba: {
133+
apiKey,
134+
baseUrl: "https://dashscope-intl.aliyuncs.com",
135+
models: [],
136+
},
137+
},
138+
},
139+
},
140+
}),
141+
).toBe(false);
142+
},
143+
);
144+
145+
it("tracks whether an allowed Alibaba API-key SecretRef resolves", () => {
146+
clearAlibabaAuthEnvironment();
147+
vi.stubEnv("ALIBABA_QA_CONFIG_KEY", "resolved-alibaba-config-key");
148+
149+
const cfg = {
150+
models: {
151+
providers: {
152+
alibaba: {
153+
apiKey: {
154+
source: "env" as const,
155+
provider: "alibaba-test-env",
156+
id: "ALIBABA_QA_CONFIG_KEY",
157+
},
158+
baseUrl: "https://dashscope-intl.aliyuncs.com",
159+
models: [],
160+
},
161+
},
162+
},
163+
secrets: {
164+
defaults: { env: "alibaba-test-env" },
165+
providers: {
166+
"alibaba-test-env": {
167+
source: "env" as const,
168+
allowlist: ["ALIBABA_QA_CONFIG_KEY"],
169+
},
170+
},
171+
},
172+
};
173+
174+
expect(alibabaVideoGenerationProvider.isConfigured?.({ cfg })).toBe(true);
175+
vi.stubEnv("ALIBABA_QA_CONFIG_KEY", "");
176+
expect(alibabaVideoGenerationProvider.isConfigured?.({ cfg })).toBe(false);
177+
});
178+
179+
it("preserves Alibaba environment API-key discovery", () => {
180+
clearAlibabaAuthEnvironment();
181+
vi.stubEnv("MODELSTUDIO_API_KEY", "alibaba-environment-key");
182+
183+
expect(alibabaVideoGenerationProvider.isConfigured?.({ cfg: {} })).toBe(true);
184+
});
185+
186+
it("does not advertise an inherited Qwen Coding Plan API key", () => {
187+
clearAlibabaAuthEnvironment();
188+
vi.stubEnv("QWEN_API_KEY", "sk-sp-qwen-coding-plan-key");
189+
190+
expect(alibabaVideoGenerationProvider.isConfigured?.({ cfg: {} })).toBe(false);
191+
});
192+
193+
it("keeps explicit Standard config above an inherited Coding Plan environment key", () => {
194+
clearAlibabaAuthEnvironment();
195+
vi.stubEnv("QWEN_API_KEY", "sk-sp-qwen-coding-plan-key");
196+
197+
expect(
198+
alibabaVideoGenerationProvider.isConfigured?.({
199+
cfg: {
200+
models: {
201+
providers: {
202+
alibaba: {
203+
auth: "api-key",
204+
apiKey: "sk-ws-alibaba-standard-key",
205+
baseUrl: "https://dashscope-intl.aliyuncs.com",
206+
models: [],
207+
},
208+
},
209+
},
210+
},
211+
}),
212+
).toBe(true);
213+
});
214+
215+
it.each([
216+
["sk-ws-alibaba-profile", "sk-sp-qwen-environment", true],
217+
["sk-sp-alibaba-profile", "sk-ws-qwen-environment", false],
218+
])("preserves actual profile precedence for %s", async (profileKey, envKey, expected) => {
219+
clearAlibabaAuthEnvironment();
220+
vi.stubEnv("QWEN_API_KEY", envKey);
221+
const agentDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-alibaba-wan-auth-"));
222+
223+
try {
224+
saveAuthProfileStore(
225+
{
226+
version: 1,
227+
profiles: {
228+
"alibaba:standard": {
229+
type: "api_key",
230+
provider: "alibaba",
231+
key: profileKey,
232+
},
233+
},
234+
},
235+
agentDir,
236+
{ filterExternalAuthProfiles: false, syncExternalCli: false },
237+
);
238+
239+
expect(alibabaVideoGenerationProvider.isConfigured?.({ cfg: {}, agentDir })).toBe(expected);
240+
} finally {
241+
clearRuntimeAuthProfileStoreSnapshots();
242+
await fs.rm(agentDir, { force: true, recursive: true });
243+
}
244+
});
245+
246+
it("rejects a resolved Coding Plan API key before submitting a Wan request", async () => {
247+
resolveApiKeyForProviderMock.mockResolvedValueOnce({ apiKey: "sk-sp-qwen-coding-plan-key" });
248+
249+
await expect(
250+
alibabaVideoGenerationProvider.generateVideo({
251+
provider: "alibaba",
252+
model: "wan2.6-t2v",
253+
prompt: "animate this shot",
254+
cfg: {},
255+
}),
256+
).rejects.toThrow(/Standard DashScope endpoint.*same-region Standard API key/i);
257+
258+
expect(postJsonRequestMock).not.toHaveBeenCalled();
259+
});
260+
60261
it("submits async Wan generation, polls task status, and downloads the resulting video", async () => {
61262
mockSuccessfulDashscopeVideoTask({ postJsonRequestMock, fetchWithTimeoutMock });
62263

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
11
import { buildDashscopeVideoGenerationProvider } from "openclaw/plugin-sdk/video-generation";
22

33
const DEFAULT_ALIBABA_VIDEO_BASE_URL = "https://dashscope-intl.aliyuncs.com";
4+
5+
function isAlibabaVideoEndpointSupported(baseUrl: string | undefined): boolean {
6+
try {
7+
const hostname = new URL(baseUrl ?? DEFAULT_ALIBABA_VIDEO_BASE_URL).hostname;
8+
return !/^(?:coding(?:-intl)?\.dashscope|token-plan\..+\.maas)\.aliyuncs\.com\.?$/iu.test(
9+
hostname,
10+
);
11+
} catch {
12+
return true;
13+
}
14+
}
15+
416
export const alibabaVideoGenerationProvider = buildDashscopeVideoGenerationProvider({
517
providerId: "alibaba",
618
label: "Alibaba Model Studio",
719
taskLabel: "Alibaba Wan",
820
defaultBaseUrl: DEFAULT_ALIBABA_VIDEO_BASE_URL,
21+
credentialPolicy: {
22+
// Coding/Token Plan keys share Alibaba's env aliases but cannot authenticate Wan requests.
23+
acceptsApiKey: (apiKey) => !apiKey.trim().startsWith("sk-sp-"),
24+
acceptsBaseUrl: isAlibabaVideoEndpointSupported,
25+
unsupportedMessage:
26+
"Alibaba Wan video generation requires a Standard DashScope endpoint and a same-region Standard API key; Coding Plan and Token Plan credentials are not supported.",
27+
},
928
});

‎extensions/byteplus/video-generation-provider.ts‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,7 @@ export function buildBytePlusVideoGenerationProvider(): VideoGenerationProvider
231231
label: "BytePlus",
232232
defaultModel: DEFAULT_BYTEPLUS_VIDEO_MODEL,
233233
models: [DEFAULT_BYTEPLUS_VIDEO_MODEL, "seedance-1-5-pro-251215"],
234-
isConfigured: ({ agentDir }) =>
235-
isProviderApiKeyConfigured({
236-
provider: "byteplus",
237-
agentDir,
238-
}),
234+
isConfigured: (ctx) => isProviderApiKeyConfigured({ provider: "byteplus", ...ctx }),
239235
capabilities: {
240236
providerOptions: {
241237
seed: "number",

‎extensions/comfy/image-generation-provider.test.ts‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,65 @@ describe("comfy image-generation provider", () => {
293293
).toBe(true);
294294
});
295295

296+
it("uses provider-owned config auth for a complete Comfy Cloud workflow", () => {
297+
const cfg = buildComfyConfig({
298+
mode: "cloud",
299+
image: {
300+
workflow: { "6": { inputs: { text: "" } } },
301+
promptNodeId: "6",
302+
},
303+
});
304+
cfg.models = {
305+
providers: {
306+
comfy: {
307+
apiKey: "comfy-provider-config-key",
308+
baseUrl: "https://cloud.comfy.org",
309+
models: [],
310+
},
311+
},
312+
};
313+
314+
expect(buildComfyImageGenerationProvider().isConfigured?.({ cfg })).toBe(true);
315+
});
316+
317+
it("does not let provider config auth bypass incomplete Comfy Cloud workflows", () => {
318+
const cfg = buildComfyConfig({ mode: "cloud" });
319+
cfg.models = {
320+
providers: {
321+
comfy: {
322+
apiKey: "comfy-provider-config-key",
323+
baseUrl: "https://cloud.comfy.org",
324+
models: [],
325+
},
326+
},
327+
};
328+
329+
expect(buildComfyImageGenerationProvider().isConfigured?.({ cfg })).toBe(false);
330+
});
331+
332+
it("preserves an unavailable plugin-secret veto even with provider config auth", () => {
333+
vi.stubEnv("COMFY_MISSING_PLUGIN_SECRET", "");
334+
const cfg = buildComfyConfig({
335+
mode: "cloud",
336+
apiKey: { source: "env", provider: "default", id: "COMFY_MISSING_PLUGIN_SECRET" },
337+
image: {
338+
workflow: { "6": { inputs: { text: "" } } },
339+
promptNodeId: "6",
340+
},
341+
});
342+
cfg.models = {
343+
providers: {
344+
comfy: {
345+
apiKey: "comfy-provider-config-key",
346+
baseUrl: "https://cloud.comfy.org",
347+
models: [],
348+
},
349+
},
350+
};
351+
352+
expect(buildComfyImageGenerationProvider().isConfigured?.({ cfg })).toBe(false);
353+
});
354+
296355
it("submits a local workflow, waits for history, and downloads images", async () => {
297356
setComfyFetchGuardForTesting(fetchWithSsrFGuardMock);
298357
fetchWithSsrFGuardMock

‎extensions/comfy/workflow-runtime.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,7 @@ export function isComfyCapabilityConfigured(params: {
637637
}
638638
return isProviderApiKeyConfigured({
639639
provider: "comfy",
640+
cfg: params.cfg,
640641
agentDir: params.agentDir,
641642
});
642643
}

‎extensions/deepinfra/video-generation-provider.ts‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,7 @@ export function buildDeepInfraVideoGenerationProvider(options?: {
182182
defaultModel,
183183
models: ids,
184184
resolveModelCapabilities: resolveDeepInfraVideoModelCapabilities,
185-
isConfigured: ({ agentDir }) =>
186-
isProviderApiKeyConfigured({
187-
provider: "deepinfra",
188-
agentDir,
189-
}),
185+
isConfigured: (ctx) => isProviderApiKeyConfigured({ provider: "deepinfra", ...ctx }),
190186
capabilities: {
191187
generate: {
192188
maxVideos: 1,

‎extensions/fal/image-generation-provider.ts‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -644,11 +644,7 @@ export function buildFalImageGenerationProvider(): ImageGenerationProvider {
644644
FAL_KREA_2_MEDIUM_MODEL,
645645
FAL_KREA_2_LARGE_MODEL,
646646
],
647-
isConfigured: ({ agentDir }) =>
648-
isProviderApiKeyConfigured({
649-
provider: "fal",
650-
agentDir,
651-
}),
647+
isConfigured: (ctx) => isProviderApiKeyConfigured({ provider: "fal", ...ctx }),
652648
capabilities: {
653649
generate: {
654650
maxCount: 4,

0 commit comments

Comments
 (0)