重构主控编排与运行时预热链路,统一工作区提示词/专家调度协议并补齐 wiki 记忆注入与写回闭环。

同时收敛启动与运维脚本默认行为(含 wiki worker)、更新 Admin 可观测性与相关测试,降低首轮时延并提高运行稳定性。

Made-with: Cursor
This commit is contained in:
oliver 2026-04-26 08:34:33 +08:00
parent 4a23b715a2
commit dbbe3add6a
14438 changed files with 2693620 additions and 2546 deletions

View file

@ -0,0 +1,252 @@
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/text-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",
}),
},
});
},
});

View file

@ -0,0 +1,82 @@
import {
createModelCatalogPresetAppliers,
type ModelProviderConfig,
type OpenClawConfig,
type ProviderOnboardPresetAppliers,
} from "openclaw/plugin-sdk/provider-onboard";
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";
export {
STEPFUN_DEFAULT_MODEL_REF,
STEPFUN_PLAN_CN_BASE_URL,
STEPFUN_PLAN_DEFAULT_MODEL_REF,
STEPFUN_PLAN_INTL_BASE_URL,
STEPFUN_STANDARD_CN_BASE_URL,
STEPFUN_STANDARD_INTL_BASE_URL,
};
function createStepFunPresetAppliers(params: {
providerId: string;
primaryModelRef: string;
alias: string;
buildProvider: (baseUrl: string) => ModelProviderConfig;
}): ProviderOnboardPresetAppliers<[string]> {
return createModelCatalogPresetAppliers<[string]>({
primaryModelRef: params.primaryModelRef,
resolveParams: (_cfg: OpenClawConfig, baseUrl: string) => {
const provider = params.buildProvider(baseUrl);
const models = provider.models ?? [];
return {
providerId: params.providerId,
api: provider.api ?? "openai-completions",
baseUrl,
catalogModels: models,
aliases: [
...models.map((model) => `${params.providerId}/${model.id}`),
{ modelRef: params.primaryModelRef, alias: params.alias },
],
};
},
});
}
const stepFunPresetAppliers = createStepFunPresetAppliers({
providerId: STEPFUN_PROVIDER_ID,
primaryModelRef: STEPFUN_DEFAULT_MODEL_REF,
alias: "StepFun",
buildProvider: buildStepFunProvider,
});
const stepFunPlanPresetAppliers = createStepFunPresetAppliers({
providerId: STEPFUN_PLAN_PROVIDER_ID,
primaryModelRef: STEPFUN_PLAN_DEFAULT_MODEL_REF,
alias: "StepFun Plan",
buildProvider: buildStepFunPlanProvider,
});
export function applyStepFunStandardConfigCn(cfg: OpenClawConfig): OpenClawConfig {
return stepFunPresetAppliers.applyConfig(cfg, STEPFUN_STANDARD_CN_BASE_URL);
}
export function applyStepFunStandardConfig(cfg: OpenClawConfig): OpenClawConfig {
return stepFunPresetAppliers.applyConfig(cfg, STEPFUN_STANDARD_INTL_BASE_URL);
}
export function applyStepFunPlanConfigCn(cfg: OpenClawConfig): OpenClawConfig {
return stepFunPlanPresetAppliers.applyConfig(cfg, STEPFUN_PLAN_CN_BASE_URL);
}
export function applyStepFunPlanConfig(cfg: OpenClawConfig): OpenClawConfig {
return stepFunPlanPresetAppliers.applyConfig(cfg, STEPFUN_PLAN_INTL_BASE_URL);
}

View file

@ -0,0 +1,73 @@
{
"id": "stepfun",
"enabledByDefault": true,
"providers": ["stepfun", "stepfun-plan"],
"autoEnableWhenConfiguredProviders": ["stepfun", "stepfun-plan"],
"providerAuthEnvVars": {
"stepfun": ["STEPFUN_API_KEY"],
"stepfun-plan": ["STEPFUN_API_KEY"]
},
"providerAuthChoices": [
{
"provider": "stepfun",
"method": "standard-api-key-cn",
"choiceId": "stepfun-standard-api-key-cn",
"choiceLabel": "StepFun Standard API key (China)",
"choiceHint": "Endpoint: api.stepfun.com/v1",
"groupId": "stepfun",
"groupLabel": "StepFun",
"groupHint": "Standard / Step Plan (China / Global)",
"optionKey": "stepfunApiKey",
"cliFlag": "--stepfun-api-key",
"cliOption": "--stepfun-api-key <key>",
"cliDescription": "StepFun API key"
},
{
"provider": "stepfun",
"method": "standard-api-key-intl",
"choiceId": "stepfun-standard-api-key-intl",
"choiceLabel": "StepFun Standard API key (Global/Intl)",
"choiceHint": "Endpoint: api.stepfun.ai/v1",
"groupId": "stepfun",
"groupLabel": "StepFun",
"groupHint": "Standard / Step Plan (China / Global)",
"optionKey": "stepfunApiKey",
"cliFlag": "--stepfun-api-key",
"cliOption": "--stepfun-api-key <key>",
"cliDescription": "StepFun API key"
},
{
"provider": "stepfun-plan",
"method": "plan-api-key-cn",
"choiceId": "stepfun-plan-api-key-cn",
"choiceLabel": "StepFun Step Plan API key (China)",
"choiceHint": "Endpoint: api.stepfun.com/step_plan/v1",
"groupId": "stepfun",
"groupLabel": "StepFun",
"groupHint": "Standard / Step Plan (China / Global)",
"optionKey": "stepfunApiKey",
"cliFlag": "--stepfun-api-key",
"cliOption": "--stepfun-api-key <key>",
"cliDescription": "StepFun API key"
},
{
"provider": "stepfun-plan",
"method": "plan-api-key-intl",
"choiceId": "stepfun-plan-api-key-intl",
"choiceLabel": "StepFun Step Plan API key (Global/Intl)",
"choiceHint": "Endpoint: api.stepfun.ai/step_plan/v1",
"groupId": "stepfun",
"groupLabel": "StepFun",
"groupHint": "Standard / Step Plan (China / Global)",
"optionKey": "stepfunApiKey",
"cliFlag": "--stepfun-api-key",
"cliOption": "--stepfun-api-key <key>",
"cliDescription": "StepFun API key"
}
],
"configSchema": {
"type": "object",
"additionalProperties": false,
"properties": {}
}
}

View file

@ -0,0 +1,15 @@
{
"name": "@openclaw/stepfun-provider",
"version": "2026.4.20",
"private": true,
"description": "OpenClaw StepFun provider plugin",
"type": "module",
"devDependencies": {
"@openclaw/plugin-sdk": "workspace:*"
},
"openclaw": {
"extensions": [
"./index.ts"
]
}
}

View file

@ -0,0 +1,69 @@
import type {
ModelDefinitionConfig,
ModelProviderConfig,
} from "openclaw/plugin-sdk/provider-model-shared";
export const STEPFUN_PROVIDER_ID = "stepfun";
export const STEPFUN_PLAN_PROVIDER_ID = "stepfun-plan";
export const STEPFUN_STANDARD_CN_BASE_URL = "https://api.stepfun.com/v1";
export const STEPFUN_STANDARD_INTL_BASE_URL = "https://api.stepfun.ai/v1";
export const STEPFUN_PLAN_CN_BASE_URL = "https://api.stepfun.com/step_plan/v1";
export const STEPFUN_PLAN_INTL_BASE_URL = "https://api.stepfun.ai/step_plan/v1";
export const STEPFUN_DEFAULT_MODEL_ID = "step-3.5-flash";
export const STEPFUN_FLASH_2603_MODEL_ID = "step-3.5-flash-2603";
export const STEPFUN_DEFAULT_MODEL_REF = `${STEPFUN_PROVIDER_ID}/${STEPFUN_DEFAULT_MODEL_ID}`;
export const STEPFUN_PLAN_DEFAULT_MODEL_REF = `${STEPFUN_PLAN_PROVIDER_ID}/${STEPFUN_DEFAULT_MODEL_ID}`;
const STEPFUN_DEFAULT_COST = {
input: 0,
output: 0,
cacheRead: 0,
cacheWrite: 0,
} as const;
function buildStepFunModel(id: string, name: string): ModelDefinitionConfig {
return {
id,
name,
reasoning: true,
input: ["text"],
cost: STEPFUN_DEFAULT_COST,
contextWindow: 262_144,
maxTokens: 65_536,
};
}
const STEPFUN_STANDARD_MODEL_CATALOG: ReadonlyArray<ModelDefinitionConfig> = [
buildStepFunModel(STEPFUN_DEFAULT_MODEL_ID, "Step 3.5 Flash"),
];
const STEPFUN_PLAN_MODEL_CATALOG: ReadonlyArray<ModelDefinitionConfig> = [
buildStepFunModel(STEPFUN_DEFAULT_MODEL_ID, "Step 3.5 Flash"),
buildStepFunModel(STEPFUN_FLASH_2603_MODEL_ID, "Step 3.5 Flash 2603"),
];
function cloneCatalog(models: ReadonlyArray<ModelDefinitionConfig>): ModelDefinitionConfig[] {
return models.map((model) => ({ ...model }));
}
export function buildStepFunProvider(
baseUrl: string = STEPFUN_STANDARD_INTL_BASE_URL,
): ModelProviderConfig {
return {
baseUrl,
api: "openai-completions",
models: cloneCatalog(STEPFUN_STANDARD_MODEL_CATALOG),
};
}
export function buildStepFunPlanProvider(
baseUrl: string = STEPFUN_PLAN_INTL_BASE_URL,
): ModelProviderConfig {
return {
baseUrl,
api: "openai-completions",
models: cloneCatalog(STEPFUN_PLAN_MODEL_CATALOG),
};
}

View file

@ -0,0 +1,16 @@
{
"extends": "../tsconfig.package-boundary.base.json",
"compilerOptions": {
"rootDir": "."
},
"include": ["./*.ts", "./src/**/*.ts"],
"exclude": [
"./**/*.test.ts",
"./dist/**",
"./node_modules/**",
"./src/test-support/**",
"./src/**/*test-helpers.ts",
"./src/**/*test-harness.ts",
"./src/**/*test-support.ts"
]
}