import type { OpenAICompletionsCompat } from "@earendil-works/pi-ai"; import type { OAuthCredentials, OAuthLoginCallbacks, } from "@earendil-works/pi-ai"; import type { ExtensionAPI, ProviderModelConfig, } from "@earendil-works/pi-coding-agent"; const compat: OpenAICompletionsCompat = { supportsStore: false, supportsDeveloperRole: false, supportsReasoningEffort: false, supportsUsageInStreaming: false, maxTokensField: "max_tokens", supportsStrictMode: false, supportsLongCacheRetention: false, }; const models: ProviderModelConfig[] = [{ id: "step-3.7-flash", name: "Step 3.7 Flash", reasoning: true, thinkingLevelMap: { off: null, minimal: null, low: "low", medium: "medium", high: "high", xhigh: null, }, input: ["text", "image"], cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 }, contextWindow: 256_000, maxTokens: 256_000, compat: { ...compat, supportsReasoningEffort: true }, }, { id: "step-3.5-flash-2603", name: "Step 3.5 Flash 2603", reasoning: true, thinkingLevelMap: { off: null, minimal: null, low: "low", medium: null, high: "high", xhigh: null, }, input: ["text"], cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 }, contextWindow: 256_000, maxTokens: 256_000, compat: { ...compat, supportsReasoningEffort: true }, }, { id: "step-3.5-flash", name: "Step 3.5 Flash", reasoning: true, thinkingLevelMap: { off: null, minimal: null, low: null, medium: null, high: "high", xhigh: null, }, input: ["text"], cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 }, contextWindow: 256_000, maxTokens: 256_000, compat, }, { id: "step-router-v1", name: "Step Router V1", reasoning: true, thinkingLevelMap: { off: null, minimal: null, low: "low", medium: "medium", high: "high", xhigh: null, }, input: ["text"], cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 }, contextWindow: 384_000, maxTokens: 384_000, compat: { ...compat, supportsReasoningEffort: true }, }]; // 10 年(毫秒) const TEN_YEARS_MS = 10 * 365 * 24 * 60 * 60 * 1000; async function loginStepFunCN( callbacks: OAuthLoginCallbacks, ): Promise { const apiKey = (await callbacks.onPrompt({ message: "请输入 StepFun 中国区 Step Plan API Key:", })).trim(); if (!apiKey) { throw new Error("未输入 StepFun API Key"); } return { access: apiKey, refresh: "", expires: Date.now() + TEN_YEARS_MS, }; } async function refreshStepFunCN( credentials: OAuthCredentials, ): Promise { return credentials; } function getStepFunAPIKey( credentials: OAuthCredentials, ): string { return credentials.access; } export default function registerStepFunCN(pi: ExtensionAPI): void { pi.registerProvider("stepfun-cn", { name: "StepFun 中国区 Step Plan", baseUrl: "https://api.stepfun.com/step_plan/v1", apiKey: "$STEPFUN_API_KEY", api: "openai-completions", oauth: { name: "StepFun 中国区 Step Plan", login: loginStepFunCN, refreshToken: refreshStepFunCN, getApiKey: getStepFunAPIKey, }, models, }); }