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
8.2 KiB
TypeScript
254 lines
8.2 KiB
TypeScript
// Stepfun plugin entrypoint registers its OpenClaw integration.
|
|
import {
|
|
definePluginEntry,
|
|
type OpenClawConfig,
|
|
type ProviderCatalogContext,
|
|
} from "openclaw/plugin-sdk/plugin-entry";
|
|
import { createProviderApiKeyAuthMethod } from "openclaw/plugin-sdk/provider-auth-api-key";
|
|
import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
import {
|
|
applyStepFunPlanConfig,
|
|
applyStepFunPlanConfigCn,
|
|
applyStepFunStandardConfig,
|
|
applyStepFunStandardConfigCn,
|
|
} from "./onboard.js";
|
|
import {
|
|
buildStepFunPlanProvider,
|
|
buildStepFunProvider,
|
|
STEPFUN_DEFAULT_MODEL_REF,
|
|
STEPFUN_PLAN_CN_BASE_URL,
|
|
STEPFUN_PLAN_DEFAULT_MODEL_REF,
|
|
STEPFUN_PLAN_INTL_BASE_URL,
|
|
STEPFUN_PLAN_PROVIDER_ID,
|
|
STEPFUN_PROVIDER_ID,
|
|
STEPFUN_STANDARD_CN_BASE_URL,
|
|
STEPFUN_STANDARD_INTL_BASE_URL,
|
|
} from "./provider-catalog.js";
|
|
|
|
type StepFunRegion = "cn" | "intl";
|
|
type StepFunSurface = "standard" | "plan";
|
|
|
|
function trimExplicitBaseUrl(ctx: ProviderCatalogContext, providerId: string): string | undefined {
|
|
const explicitProvider = ctx.config.models?.providers?.[providerId];
|
|
const baseUrl =
|
|
typeof explicitProvider?.baseUrl === "string" ? explicitProvider.baseUrl.trim() : "";
|
|
return baseUrl || undefined;
|
|
}
|
|
|
|
function inferRegionFromBaseUrl(baseUrl: string | undefined): StepFunRegion | undefined {
|
|
if (!baseUrl) {
|
|
return undefined;
|
|
}
|
|
try {
|
|
const host = normalizeLowercaseStringOrEmpty(new URL(baseUrl).hostname);
|
|
if (host === "api.stepfun.com") {
|
|
return "cn";
|
|
}
|
|
if (host === "api.stepfun.ai") {
|
|
return "intl";
|
|
}
|
|
} catch {
|
|
return undefined;
|
|
}
|
|
return undefined;
|
|
}
|
|
|
|
function inferRegionFromProfileId(profileId: string | undefined): StepFunRegion | undefined {
|
|
if (!profileId) {
|
|
return undefined;
|
|
}
|
|
if (profileId.includes(":cn")) {
|
|
return "cn";
|
|
}
|
|
if (profileId.includes(":intl")) {
|
|
return "intl";
|
|
}
|
|
return undefined;
|
|
}
|
|
|
|
function inferRegionFromEnv(env: NodeJS.ProcessEnv): StepFunRegion | undefined {
|
|
// Shared env-only setup needs one stable fallback region.
|
|
if (env.STEPFUN_API_KEY?.trim()) {
|
|
return "intl";
|
|
}
|
|
return undefined;
|
|
}
|
|
|
|
function inferRegionFromExplicitBaseUrls(ctx: ProviderCatalogContext): StepFunRegion | undefined {
|
|
return (
|
|
inferRegionFromBaseUrl(trimExplicitBaseUrl(ctx, STEPFUN_PROVIDER_ID)) ??
|
|
inferRegionFromBaseUrl(trimExplicitBaseUrl(ctx, STEPFUN_PLAN_PROVIDER_ID))
|
|
);
|
|
}
|
|
|
|
function resolveDefaultBaseUrl(surface: StepFunSurface, region: StepFunRegion): string {
|
|
if (surface === "plan") {
|
|
return region === "cn" ? STEPFUN_PLAN_CN_BASE_URL : STEPFUN_PLAN_INTL_BASE_URL;
|
|
}
|
|
return region === "cn" ? STEPFUN_STANDARD_CN_BASE_URL : STEPFUN_STANDARD_INTL_BASE_URL;
|
|
}
|
|
|
|
function resolveStepFunCatalog(
|
|
ctx: ProviderCatalogContext,
|
|
params: { providerId: string; surface: StepFunSurface },
|
|
) {
|
|
const auth = ctx.resolveProviderAuth(params.providerId);
|
|
const apiKey = auth.apiKey ?? ctx.resolveProviderApiKey(params.providerId).apiKey;
|
|
if (!apiKey) {
|
|
return null;
|
|
}
|
|
|
|
const explicitBaseUrl = trimExplicitBaseUrl(ctx, params.providerId);
|
|
const region =
|
|
inferRegionFromBaseUrl(explicitBaseUrl) ??
|
|
inferRegionFromExplicitBaseUrls(ctx) ??
|
|
inferRegionFromProfileId(auth.profileId) ??
|
|
inferRegionFromEnv(ctx.env);
|
|
// Keep discovery working for legacy/manual auth profiles that resolved a
|
|
// key but do not encode region in the profile id.
|
|
const baseUrl = explicitBaseUrl ?? resolveDefaultBaseUrl(params.surface, region ?? "intl");
|
|
return {
|
|
provider:
|
|
params.surface === "plan"
|
|
? { ...buildStepFunPlanProvider(baseUrl), apiKey }
|
|
: { ...buildStepFunProvider(baseUrl), apiKey },
|
|
};
|
|
}
|
|
|
|
function resolveProfileIds(region: StepFunRegion): [string, string] {
|
|
return region === "cn"
|
|
? ["stepfun:cn", "stepfun-plan:cn"]
|
|
: ["stepfun:intl", "stepfun-plan:intl"];
|
|
}
|
|
|
|
function createStepFunApiKeyMethod(params: {
|
|
providerId: string;
|
|
methodId: string;
|
|
label: string;
|
|
hint: string;
|
|
region: StepFunRegion;
|
|
promptMessage: string;
|
|
defaultModel: string;
|
|
choiceId: string;
|
|
choiceLabel: string;
|
|
choiceHint: string;
|
|
applyConfig: (cfg: OpenClawConfig) => OpenClawConfig;
|
|
}) {
|
|
return createProviderApiKeyAuthMethod({
|
|
providerId: params.providerId,
|
|
methodId: params.methodId,
|
|
label: params.label,
|
|
hint: params.hint,
|
|
optionKey: "stepfunApiKey",
|
|
flagName: "--stepfun-api-key",
|
|
envVar: "STEPFUN_API_KEY",
|
|
promptMessage: params.promptMessage,
|
|
profileIds: resolveProfileIds(params.region),
|
|
allowProfile: false,
|
|
defaultModel: params.defaultModel,
|
|
expectedProviders: [STEPFUN_PROVIDER_ID, STEPFUN_PLAN_PROVIDER_ID],
|
|
applyConfig: params.applyConfig,
|
|
wizard: {
|
|
choiceId: params.choiceId,
|
|
choiceLabel: params.choiceLabel,
|
|
choiceHint: params.choiceHint,
|
|
groupId: "stepfun",
|
|
groupLabel: "StepFun",
|
|
groupHint: "Standard / Step Plan (China / Global)",
|
|
},
|
|
});
|
|
}
|
|
|
|
export default definePluginEntry({
|
|
id: STEPFUN_PROVIDER_ID,
|
|
name: "StepFun",
|
|
description: "Bundled StepFun standard and Step Plan provider plugin",
|
|
register(api) {
|
|
api.registerProvider({
|
|
id: STEPFUN_PROVIDER_ID,
|
|
label: "StepFun",
|
|
docsPath: "/providers/stepfun",
|
|
envVars: ["STEPFUN_API_KEY"],
|
|
auth: [
|
|
createStepFunApiKeyMethod({
|
|
providerId: STEPFUN_PROVIDER_ID,
|
|
methodId: "standard-api-key-cn",
|
|
label: "StepFun Standard API key (China)",
|
|
hint: "Endpoint: api.stepfun.com/v1",
|
|
region: "cn",
|
|
promptMessage: "Enter StepFun API key for China endpoints",
|
|
defaultModel: STEPFUN_DEFAULT_MODEL_REF,
|
|
choiceId: "stepfun-standard-api-key-cn",
|
|
choiceLabel: "StepFun Standard API key (China)",
|
|
choiceHint: "Endpoint: api.stepfun.com/v1",
|
|
applyConfig: applyStepFunStandardConfigCn,
|
|
}),
|
|
createStepFunApiKeyMethod({
|
|
providerId: STEPFUN_PROVIDER_ID,
|
|
methodId: "standard-api-key-intl",
|
|
label: "StepFun Standard API key (Global/Intl)",
|
|
hint: "Endpoint: api.stepfun.ai/v1",
|
|
region: "intl",
|
|
promptMessage: "Enter StepFun API key for global endpoints",
|
|
defaultModel: STEPFUN_DEFAULT_MODEL_REF,
|
|
choiceId: "stepfun-standard-api-key-intl",
|
|
choiceLabel: "StepFun Standard API key (Global/Intl)",
|
|
choiceHint: "Endpoint: api.stepfun.ai/v1",
|
|
applyConfig: applyStepFunStandardConfig,
|
|
}),
|
|
],
|
|
catalog: {
|
|
order: "paired",
|
|
run: async (ctx) =>
|
|
resolveStepFunCatalog(ctx, {
|
|
providerId: STEPFUN_PROVIDER_ID,
|
|
surface: "standard",
|
|
}),
|
|
},
|
|
});
|
|
|
|
api.registerProvider({
|
|
id: STEPFUN_PLAN_PROVIDER_ID,
|
|
label: "StepFun Step Plan",
|
|
docsPath: "/providers/stepfun",
|
|
envVars: ["STEPFUN_API_KEY"],
|
|
auth: [
|
|
createStepFunApiKeyMethod({
|
|
providerId: STEPFUN_PLAN_PROVIDER_ID,
|
|
methodId: "plan-api-key-cn",
|
|
label: "StepFun Step Plan API key (China)",
|
|
hint: "Endpoint: api.stepfun.com/step_plan/v1",
|
|
region: "cn",
|
|
promptMessage: "Enter StepFun API key for China endpoints",
|
|
defaultModel: STEPFUN_PLAN_DEFAULT_MODEL_REF,
|
|
choiceId: "stepfun-plan-api-key-cn",
|
|
choiceLabel: "StepFun Step Plan API key (China)",
|
|
choiceHint: "Endpoint: api.stepfun.com/step_plan/v1",
|
|
applyConfig: applyStepFunPlanConfigCn,
|
|
}),
|
|
createStepFunApiKeyMethod({
|
|
providerId: STEPFUN_PLAN_PROVIDER_ID,
|
|
methodId: "plan-api-key-intl",
|
|
label: "StepFun Step Plan API key (Global/Intl)",
|
|
hint: "Endpoint: api.stepfun.ai/step_plan/v1",
|
|
region: "intl",
|
|
promptMessage: "Enter StepFun API key for global endpoints",
|
|
defaultModel: STEPFUN_PLAN_DEFAULT_MODEL_REF,
|
|
choiceId: "stepfun-plan-api-key-intl",
|
|
choiceLabel: "StepFun Step Plan API key (Global/Intl)",
|
|
choiceHint: "Endpoint: api.stepfun.ai/step_plan/v1",
|
|
applyConfig: applyStepFunPlanConfig,
|
|
}),
|
|
],
|
|
catalog: {
|
|
order: "paired",
|
|
run: async (ctx) =>
|
|
resolveStepFunCatalog(ctx, {
|
|
providerId: STEPFUN_PLAN_PROVIDER_ID,
|
|
surface: "plan",
|
|
}),
|
|
},
|
|
});
|
|
},
|
|
});
|