Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Adolf is a fork/vendored clone of github.com/openclaw/openclaw (v2026.6.11), free to diverge. Tree copied sans upstream .git; upstream remote added for future syncs. Node pinned to 24 (.nvmrc); engines already require >=22.19. Preserves docs/ARCHITECTURE.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LeqyaxJF2nbRXJtae2kNB2
254 lines
7.2 KiB
TypeScript
254 lines
7.2 KiB
TypeScript
// Pixverse setup module handles plugin onboarding behavior.
|
|
import type {
|
|
ProviderAuthContext,
|
|
ProviderAuthMethod,
|
|
ProviderAuthMethodNonInteractiveContext,
|
|
} from "openclaw/plugin-sdk/plugin-entry";
|
|
import {
|
|
applyAuthProfileConfig,
|
|
buildApiKeyCredential,
|
|
ensureApiKeyFromOptionEnvOrPrompt,
|
|
normalizeApiKeyInput,
|
|
normalizeOptionalSecretInput,
|
|
type OpenClawConfig,
|
|
type SecretInput,
|
|
upsertAuthProfileWithLock,
|
|
validateApiKeyInput,
|
|
} from "openclaw/plugin-sdk/provider-auth-api-key";
|
|
import type { ModelProviderConfig } from "openclaw/plugin-sdk/provider-onboard";
|
|
import { normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
import {
|
|
DEFAULT_PIXVERSE_REGION,
|
|
PIXVERSE_BASE_URL_BY_REGION,
|
|
PIXVERSE_DEFAULT_VIDEO_MODEL_REF,
|
|
PIXVERSE_PROVIDER_ID,
|
|
type PixVerseApiRegion,
|
|
} from "./constants.js";
|
|
|
|
const PROFILE_ID = `${PIXVERSE_PROVIDER_ID}:default`;
|
|
|
|
type PixVerseAuthResult = {
|
|
profiles: Array<{ profileId: string; credential: ReturnType<typeof buildApiKeyCredential> }>;
|
|
configPatch: OpenClawConfig;
|
|
notes: string[];
|
|
};
|
|
|
|
type UpsertAuthProfileParams = Parameters<typeof upsertAuthProfileWithLock>[0];
|
|
|
|
async function upsertAuthProfileWithLockOrThrow(params: UpsertAuthProfileParams): Promise<void> {
|
|
const updated = await upsertAuthProfileWithLock(params);
|
|
if (!updated) {
|
|
throw new Error(
|
|
"Failed to update auth profile store; the auth store lock may be busy. Wait a moment and retry.",
|
|
);
|
|
}
|
|
}
|
|
|
|
function normalizePixVerseRegion(value: unknown): PixVerseApiRegion | undefined {
|
|
const region = normalizeOptionalString(value)?.toLowerCase();
|
|
switch (region) {
|
|
case "cn":
|
|
case "china":
|
|
case "mainland":
|
|
case "pai":
|
|
return "cn";
|
|
case "global":
|
|
case "intl":
|
|
case "international":
|
|
return "international";
|
|
default:
|
|
return undefined;
|
|
}
|
|
}
|
|
|
|
function pixVerseRegionNote(region: PixVerseApiRegion): string {
|
|
const label = region === "cn" ? "CN" : "International";
|
|
return `PixVerse endpoint: ${label} (${PIXVERSE_BASE_URL_BY_REGION[region]})`;
|
|
}
|
|
|
|
export function applyPixVerseProviderConfig(
|
|
cfg: OpenClawConfig,
|
|
region: PixVerseApiRegion,
|
|
options?: { resetBaseUrl?: boolean },
|
|
): OpenClawConfig {
|
|
const existingProvider: Partial<ModelProviderConfig> =
|
|
cfg.models?.providers?.[PIXVERSE_PROVIDER_ID] ?? {};
|
|
const selectedBaseUrl = PIXVERSE_BASE_URL_BY_REGION[region];
|
|
const baseUrl = options?.resetBaseUrl
|
|
? selectedBaseUrl
|
|
: (normalizeOptionalString(existingProvider.baseUrl) ?? selectedBaseUrl);
|
|
return {
|
|
...cfg,
|
|
models: {
|
|
...cfg.models,
|
|
providers: {
|
|
...cfg.models?.providers,
|
|
[PIXVERSE_PROVIDER_ID]: {
|
|
...existingProvider,
|
|
baseUrl,
|
|
models: existingProvider.models ?? [],
|
|
region,
|
|
},
|
|
},
|
|
},
|
|
};
|
|
}
|
|
|
|
export function applyPixVerseConfig(
|
|
cfg: OpenClawConfig,
|
|
region: PixVerseApiRegion,
|
|
options?: { resetBaseUrl?: boolean },
|
|
): OpenClawConfig {
|
|
const next = applyPixVerseProviderConfig(cfg, region, options);
|
|
if (next.agents?.defaults?.videoGenerationModel) {
|
|
return next;
|
|
}
|
|
return {
|
|
...next,
|
|
agents: {
|
|
...next.agents,
|
|
defaults: {
|
|
...next.agents?.defaults,
|
|
videoGenerationModel: {
|
|
primary: PIXVERSE_DEFAULT_VIDEO_MODEL_REF,
|
|
},
|
|
},
|
|
},
|
|
};
|
|
}
|
|
|
|
async function promptForPixVerseRegion(ctx: ProviderAuthContext): Promise<PixVerseApiRegion> {
|
|
return await ctx.prompter.select<PixVerseApiRegion>({
|
|
message: "Select PixVerse API region",
|
|
initialValue: DEFAULT_PIXVERSE_REGION,
|
|
options: [
|
|
{
|
|
value: "international",
|
|
label: "International",
|
|
hint: PIXVERSE_BASE_URL_BY_REGION.international,
|
|
},
|
|
{
|
|
value: "cn",
|
|
label: "CN",
|
|
hint: PIXVERSE_BASE_URL_BY_REGION.cn,
|
|
},
|
|
],
|
|
});
|
|
}
|
|
|
|
async function runPixVerseApiKeyAuth(ctx: ProviderAuthContext): Promise<PixVerseAuthResult> {
|
|
let capturedSecretInput: SecretInput | undefined;
|
|
let capturedCredential = false;
|
|
let capturedMode: "plaintext" | "ref" | undefined;
|
|
|
|
await ensureApiKeyFromOptionEnvOrPrompt({
|
|
token:
|
|
normalizeOptionalSecretInput(ctx.opts?.pixverseApiKey) ??
|
|
normalizeOptionalSecretInput(ctx.opts?.token),
|
|
tokenProvider: normalizeOptionalSecretInput(ctx.opts?.pixverseApiKey)
|
|
? PIXVERSE_PROVIDER_ID
|
|
: normalizeOptionalSecretInput(ctx.opts?.tokenProvider),
|
|
secretInputMode:
|
|
ctx.allowSecretRefPrompt === false
|
|
? (ctx.secretInputMode ?? "plaintext")
|
|
: ctx.secretInputMode,
|
|
config: ctx.config,
|
|
env: ctx.env,
|
|
expectedProviders: [PIXVERSE_PROVIDER_ID],
|
|
provider: PIXVERSE_PROVIDER_ID,
|
|
envLabel: "PIXVERSE_API_KEY",
|
|
promptMessage: "Enter PixVerse API key",
|
|
normalize: normalizeApiKeyInput,
|
|
validate: validateApiKeyInput,
|
|
prompter: ctx.prompter,
|
|
setCredential: async (apiKey, mode) => {
|
|
capturedSecretInput = apiKey;
|
|
capturedCredential = true;
|
|
capturedMode = mode;
|
|
},
|
|
});
|
|
|
|
if (!capturedCredential) {
|
|
throw new Error("Missing PixVerse API key.");
|
|
}
|
|
|
|
const region = await promptForPixVerseRegion(ctx);
|
|
return {
|
|
profiles: [
|
|
{
|
|
profileId: PROFILE_ID,
|
|
credential: buildApiKeyCredential(
|
|
PIXVERSE_PROVIDER_ID,
|
|
capturedSecretInput ?? "",
|
|
undefined,
|
|
capturedMode
|
|
? {
|
|
secretInputMode: capturedMode,
|
|
config: ctx.config,
|
|
}
|
|
: undefined,
|
|
),
|
|
},
|
|
],
|
|
configPatch: applyPixVerseConfig(ctx.config, region, { resetBaseUrl: true }),
|
|
notes: [pixVerseRegionNote(region)],
|
|
};
|
|
}
|
|
|
|
async function runPixVerseApiKeyAuthNonInteractive(ctx: ProviderAuthMethodNonInteractiveContext) {
|
|
const resolved = await ctx.resolveApiKey({
|
|
provider: PIXVERSE_PROVIDER_ID,
|
|
flagValue: normalizeOptionalSecretInput(ctx.opts.pixverseApiKey),
|
|
flagName: "--pixverse-api-key",
|
|
envVar: "PIXVERSE_API_KEY",
|
|
});
|
|
if (!resolved) {
|
|
return null;
|
|
}
|
|
|
|
if (resolved.source !== "profile") {
|
|
const credential = ctx.toApiKeyCredential({
|
|
provider: PIXVERSE_PROVIDER_ID,
|
|
resolved,
|
|
});
|
|
if (!credential) {
|
|
return null;
|
|
}
|
|
await upsertAuthProfileWithLockOrThrow({
|
|
profileId: PROFILE_ID,
|
|
credential,
|
|
agentDir: ctx.agentDir,
|
|
});
|
|
}
|
|
|
|
const next = applyAuthProfileConfig(ctx.config, {
|
|
profileId: PROFILE_ID,
|
|
provider: PIXVERSE_PROVIDER_ID,
|
|
mode: "api_key",
|
|
});
|
|
const explicitRegion = normalizePixVerseRegion(ctx.opts.pixverseRegion);
|
|
return applyPixVerseConfig(next, explicitRegion ?? DEFAULT_PIXVERSE_REGION, {
|
|
resetBaseUrl: explicitRegion !== undefined,
|
|
});
|
|
}
|
|
|
|
export function buildPixVerseApiKeyAuthMethod(): ProviderAuthMethod {
|
|
return {
|
|
id: "api-key",
|
|
label: "PixVerse API key",
|
|
hint: "Video generation API key",
|
|
kind: "api_key",
|
|
wizard: {
|
|
choiceId: "pixverse-api-key",
|
|
choiceLabel: "PixVerse API key",
|
|
choiceHint: "Prompts for International or CN endpoint",
|
|
groupId: "pixverse",
|
|
groupLabel: "PixVerse",
|
|
groupHint: "Video generation",
|
|
onboardingScopes: ["image-generation"],
|
|
},
|
|
run: runPixVerseApiKeyAuth,
|
|
runNonInteractive: runPixVerseApiKeyAuthNonInteractive,
|
|
};
|
|
}
|