mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-18 20:51:10 +00:00
refactor: dedupe openai synthetic catalog helper
This commit is contained in:
@@ -24,6 +24,7 @@ import { buildOpenAICodexProvider } from "./openai-codex-catalog.js";
|
||||
import { CODEX_CLI_PROFILE_ID, readOpenAICodexCliOAuthProfile } from "./openai-codex-cli-auth.js";
|
||||
import { buildOpenAIReplayPolicy } from "./replay-policy.js";
|
||||
import {
|
||||
buildOpenAISyntheticCatalogEntry,
|
||||
cloneFirstTemplateModel,
|
||||
findCatalogTemplate,
|
||||
isOpenAIApiBaseUrl,
|
||||
@@ -233,30 +234,6 @@ function buildOpenAICodexAuthDoctorHint(ctx: { profileId?: string }) {
|
||||
return "Deprecated profile. Run `openclaw models auth login --provider openai-codex` or `openclaw configure`.";
|
||||
}
|
||||
|
||||
function buildSyntheticCatalogEntry(
|
||||
template: ReturnType<typeof findCatalogTemplate>,
|
||||
entry: {
|
||||
id: string;
|
||||
reasoning: boolean;
|
||||
input: readonly ("text" | "image")[];
|
||||
contextWindow: number;
|
||||
contextTokens?: number;
|
||||
},
|
||||
) {
|
||||
if (!template) {
|
||||
return undefined;
|
||||
}
|
||||
return {
|
||||
...template,
|
||||
id: entry.id,
|
||||
name: entry.id,
|
||||
reasoning: entry.reasoning,
|
||||
input: [...entry.input],
|
||||
contextWindow: entry.contextWindow,
|
||||
...(entry.contextTokens === undefined ? {} : { contextTokens: entry.contextTokens }),
|
||||
};
|
||||
}
|
||||
|
||||
export function buildOpenAICodexProviderPlugin(): ProviderPlugin {
|
||||
return {
|
||||
id: PROVIDER_ID,
|
||||
@@ -347,20 +324,20 @@ export function buildOpenAICodexProviderPlugin(): ProviderPlugin {
|
||||
templateIds: [OPENAI_CODEX_GPT_53_MODEL_ID, ...OPENAI_CODEX_TEMPLATE_MODEL_IDS],
|
||||
});
|
||||
return [
|
||||
buildSyntheticCatalogEntry(gpt54Template, {
|
||||
buildOpenAISyntheticCatalogEntry(gpt54Template, {
|
||||
id: OPENAI_CODEX_GPT_54_MODEL_ID,
|
||||
reasoning: true,
|
||||
input: ["text", "image"],
|
||||
contextWindow: OPENAI_CODEX_GPT_54_NATIVE_CONTEXT_TOKENS,
|
||||
contextTokens: OPENAI_CODEX_GPT_54_DEFAULT_CONTEXT_TOKENS,
|
||||
}),
|
||||
buildSyntheticCatalogEntry(gpt54MiniTemplate, {
|
||||
buildOpenAISyntheticCatalogEntry(gpt54MiniTemplate, {
|
||||
id: OPENAI_CODEX_GPT_54_MINI_MODEL_ID,
|
||||
reasoning: true,
|
||||
input: ["text", "image"],
|
||||
contextWindow: OPENAI_CODEX_GPT_54_MINI_CONTEXT_TOKENS,
|
||||
}),
|
||||
buildSyntheticCatalogEntry(sparkTemplate, {
|
||||
buildOpenAISyntheticCatalogEntry(sparkTemplate, {
|
||||
id: OPENAI_CODEX_GPT_53_SPARK_MODEL_ID,
|
||||
reasoning: true,
|
||||
input: ["text"],
|
||||
|
||||
@@ -13,6 +13,7 @@ import { buildProviderStreamFamilyHooks } from "openclaw/plugin-sdk/provider-str
|
||||
import { applyOpenAIConfig, OPENAI_DEFAULT_MODEL } from "./default-models.js";
|
||||
import { buildOpenAIReplayPolicy } from "./replay-policy.js";
|
||||
import {
|
||||
buildOpenAISyntheticCatalogEntry,
|
||||
cloneFirstTemplateModel,
|
||||
findCatalogTemplate,
|
||||
isOpenAIApiBaseUrl,
|
||||
@@ -179,28 +180,6 @@ function resolveOpenAIGpt54ForwardCompatModel(
|
||||
);
|
||||
}
|
||||
|
||||
function buildSyntheticCatalogEntry(
|
||||
template: ReturnType<typeof findCatalogTemplate>,
|
||||
entry: {
|
||||
id: string;
|
||||
reasoning: boolean;
|
||||
input: readonly ("text" | "image")[];
|
||||
contextWindow: number;
|
||||
},
|
||||
) {
|
||||
if (!template) {
|
||||
return undefined;
|
||||
}
|
||||
return {
|
||||
...template,
|
||||
id: entry.id,
|
||||
name: entry.id,
|
||||
reasoning: entry.reasoning,
|
||||
input: [...entry.input],
|
||||
contextWindow: entry.contextWindow,
|
||||
};
|
||||
}
|
||||
|
||||
export function buildOpenAIProvider(): ProviderPlugin {
|
||||
return {
|
||||
id: PROVIDER_ID,
|
||||
@@ -304,25 +283,25 @@ export function buildOpenAIProvider(): ProviderPlugin {
|
||||
templateIds: OPENAI_GPT_54_NANO_TEMPLATE_MODEL_IDS,
|
||||
});
|
||||
return [
|
||||
buildSyntheticCatalogEntry(openAiGpt54Template, {
|
||||
buildOpenAISyntheticCatalogEntry(openAiGpt54Template, {
|
||||
id: OPENAI_GPT_54_MODEL_ID,
|
||||
reasoning: true,
|
||||
input: ["text", "image"],
|
||||
contextWindow: OPENAI_GPT_54_CONTEXT_TOKENS,
|
||||
}),
|
||||
buildSyntheticCatalogEntry(openAiGpt54ProTemplate, {
|
||||
buildOpenAISyntheticCatalogEntry(openAiGpt54ProTemplate, {
|
||||
id: OPENAI_GPT_54_PRO_MODEL_ID,
|
||||
reasoning: true,
|
||||
input: ["text", "image"],
|
||||
contextWindow: OPENAI_GPT_54_PRO_CONTEXT_TOKENS,
|
||||
}),
|
||||
buildSyntheticCatalogEntry(openAiGpt54MiniTemplate, {
|
||||
buildOpenAISyntheticCatalogEntry(openAiGpt54MiniTemplate, {
|
||||
id: OPENAI_GPT_54_MINI_MODEL_ID,
|
||||
reasoning: true,
|
||||
input: ["text", "image"],
|
||||
contextWindow: OPENAI_GPT_54_MINI_CONTEXT_TOKENS,
|
||||
}),
|
||||
buildSyntheticCatalogEntry(openAiGpt54NanoTemplate, {
|
||||
buildOpenAISyntheticCatalogEntry(openAiGpt54NanoTemplate, {
|
||||
id: OPENAI_GPT_54_NANO_MODEL_ID,
|
||||
reasoning: true,
|
||||
input: ["text", "image"],
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-runtime";
|
||||
import type { ProviderRuntimeModel } from "openclaw/plugin-sdk/plugin-entry";
|
||||
import { findCatalogTemplate } from "openclaw/plugin-sdk/provider-catalog-shared";
|
||||
import {
|
||||
cloneFirstTemplateModel,
|
||||
@@ -31,4 +32,28 @@ export function isOpenAICodexBaseUrl(baseUrl?: string): boolean {
|
||||
return /^https?:\/\/chatgpt\.com\/backend-api\/?$/i.test(trimmed);
|
||||
}
|
||||
|
||||
export function buildOpenAISyntheticCatalogEntry(
|
||||
template: ReturnType<typeof findCatalogTemplate>,
|
||||
entry: {
|
||||
id: string;
|
||||
reasoning: boolean;
|
||||
input: readonly ("text" | "image")[];
|
||||
contextWindow: number;
|
||||
contextTokens?: number;
|
||||
},
|
||||
): ProviderRuntimeModel | undefined {
|
||||
if (!template) {
|
||||
return undefined;
|
||||
}
|
||||
return {
|
||||
...template,
|
||||
id: entry.id,
|
||||
name: entry.id,
|
||||
reasoning: entry.reasoning,
|
||||
input: [...entry.input],
|
||||
contextWindow: entry.contextWindow,
|
||||
...(entry.contextTokens === undefined ? {} : { contextTokens: entry.contextTokens }),
|
||||
};
|
||||
}
|
||||
|
||||
export { cloneFirstTemplateModel, findCatalogTemplate, matchesExactOrPrefix };
|
||||
|
||||
Reference in New Issue
Block a user