mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-24 10:58:37 +00:00
fix(openai): route spark through codex runtime
This commit is contained in:
@@ -849,6 +849,20 @@ describe("buildOpenAIProvider", () => {
|
||||
auth: "api-key",
|
||||
},
|
||||
} as never);
|
||||
const runtimeModel = provider.resolveDynamicModel?.({
|
||||
provider: "openai",
|
||||
modelId: "gpt-5.3-codex-spark",
|
||||
modelRegistry: { find: () => null },
|
||||
agentRuntimeId: "codex",
|
||||
} as never);
|
||||
const apiKeyRuntimeModel = provider.resolveDynamicModel?.({
|
||||
provider: "openai",
|
||||
modelId: "gpt-5.3-codex-spark",
|
||||
modelRegistry: { find: () => null },
|
||||
agentRuntimeId: "codex",
|
||||
authProfileId: "openai:api-key",
|
||||
authProfileMode: "api_key",
|
||||
} as never);
|
||||
const unknownModelHint = provider.buildUnknownModelHint?.({
|
||||
provider: "openai",
|
||||
modelId: "gpt-5.3-codex-spark",
|
||||
@@ -864,7 +878,18 @@ describe("buildOpenAIProvider", () => {
|
||||
contextTokens: 128_000,
|
||||
maxTokens: 128_000,
|
||||
});
|
||||
expectFields(runtimeModel, {
|
||||
provider: "openai",
|
||||
id: "gpt-5.3-codex-spark",
|
||||
api: "openai-chatgpt-responses",
|
||||
baseUrl: "https://chatgpt.com/backend-api/codex",
|
||||
input: ["text"],
|
||||
contextWindow: 128_000,
|
||||
contextTokens: 128_000,
|
||||
maxTokens: 128_000,
|
||||
});
|
||||
expect(apiKeyModel).toBeUndefined();
|
||||
expect(apiKeyRuntimeModel).toBeUndefined();
|
||||
expect(unknownModelHint).toContain("ChatGPT/Codex OAuth");
|
||||
expect(unknownModelHint).toContain("OpenAI API-key auth cannot use this model");
|
||||
});
|
||||
|
||||
@@ -515,7 +515,11 @@ function shouldResolveDynamicModelThroughCodex(ctx: ProviderResolveDynamicModelC
|
||||
if (ctx.providerConfig?.baseUrl && !isOpenAIApiBaseUrl(ctx.providerConfig.baseUrl)) {
|
||||
return false;
|
||||
}
|
||||
return resolveConfiguredAuthTransport(ctx) === "codex";
|
||||
const authTransport = resolveConfiguredAuthTransport(ctx);
|
||||
if (authTransport) {
|
||||
return authTransport === "codex";
|
||||
}
|
||||
return ctx.agentRuntimeId === "codex";
|
||||
}
|
||||
|
||||
function buildOpenAIUnknownModelHint(modelId: string): string | undefined {
|
||||
|
||||
@@ -213,6 +213,58 @@ describe("resolveModel forward-compat errors and overrides", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("resolves suppressed openai gpt-5.3-codex-spark through model-scoped Codex runtime", () => {
|
||||
mockOpenAICodexTemplateModel(discoverModels);
|
||||
|
||||
const cfg: OpenClawConfig = {
|
||||
agents: {
|
||||
defaults: {
|
||||
models: {
|
||||
"openai/gpt-5.3-codex-spark": {
|
||||
agentRuntime: { id: "codex" },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const result = resolveModelForTest("openai", "gpt-5.3-codex-spark", "/tmp/agent", cfg);
|
||||
|
||||
expect(result.error).toBeUndefined();
|
||||
expect(result.model).toMatchObject(
|
||||
buildOpenAICodexForwardCompatExpectation("gpt-5.3-codex-spark"),
|
||||
);
|
||||
});
|
||||
|
||||
it("keeps model-scoped Codex runtime blocked for explicit OpenAI API-key provider config", () => {
|
||||
mockOpenAICodexTemplateModel(discoverModels);
|
||||
|
||||
const cfg: OpenClawConfig = {
|
||||
agents: {
|
||||
defaults: {
|
||||
models: {
|
||||
"openai/gpt-5.3-codex-spark": {
|
||||
agentRuntime: { id: "codex" },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
models: {
|
||||
providers: {
|
||||
openai: {
|
||||
auth: "api-key",
|
||||
api: "openai-responses",
|
||||
baseUrl: "https://api.openai.com/v1",
|
||||
models: [],
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const result = resolveModelForTest("openai", "gpt-5.3-codex-spark", "/tmp/agent", cfg);
|
||||
|
||||
expect(result.model).toBeUndefined();
|
||||
expect(result.error).toContain("OpenAI API-key auth cannot use this model");
|
||||
});
|
||||
|
||||
it("keeps suppressed stale direct openai gpt-5.3-codex-spark catalog rows blocked", () => {
|
||||
mockDiscoveredModel(discoverModels, {
|
||||
provider: "openai",
|
||||
|
||||
@@ -39,7 +39,13 @@ type DynamicModelContext = {
|
||||
provider: string;
|
||||
modelId: string;
|
||||
modelRegistry: ModelRegistryLike;
|
||||
providerConfig?: { api?: string | null; baseUrl?: string };
|
||||
agentRuntimeId?: string;
|
||||
authProfileMode?: "api_key" | "aws-sdk" | "oauth" | "token";
|
||||
providerConfig?: {
|
||||
api?: string | null;
|
||||
auth?: "api-key" | "aws-sdk" | "oauth" | "token";
|
||||
baseUrl?: string;
|
||||
};
|
||||
};
|
||||
|
||||
type ResolvedModelLike = Record<string, unknown>;
|
||||
@@ -296,9 +302,22 @@ function buildDynamicModel(
|
||||
const isLegacyGpt54Alias = lower === "gpt-5.4-codex";
|
||||
const isSparkModel = lower === "gpt-5.3-codex-spark";
|
||||
const exactModel = params.modelRegistry.find("openai", modelId) as ResolvedModelLike | null;
|
||||
const explicitResponsesAuth =
|
||||
params.authProfileMode === "api_key" ||
|
||||
params.authProfileMode === "aws-sdk" ||
|
||||
params.providerConfig?.auth === "api-key" ||
|
||||
params.providerConfig?.auth === "aws-sdk";
|
||||
const explicitCodexAuth =
|
||||
params.authProfileMode === "oauth" ||
|
||||
params.authProfileMode === "token" ||
|
||||
params.providerConfig?.auth === "oauth" ||
|
||||
params.providerConfig?.auth === "token";
|
||||
const providerConfigSelectsChatGpt =
|
||||
params.providerConfig?.api === "openai-chatgpt-responses" ||
|
||||
isNativeOpenAICodexBaseUrl(params.providerConfig?.baseUrl);
|
||||
!explicitResponsesAuth &&
|
||||
(explicitCodexAuth ||
|
||||
params.providerConfig?.api === "openai-chatgpt-responses" ||
|
||||
isNativeOpenAICodexBaseUrl(params.providerConfig?.baseUrl) ||
|
||||
params.agentRuntimeId === "codex");
|
||||
if (
|
||||
lower === "gpt-5.5" &&
|
||||
(providerConfigSelectsChatGpt || isOpenAIChatGptModelTemplate(exactModel))
|
||||
@@ -695,7 +714,13 @@ export function createProviderRuntimeTestMock(options: ProviderRuntimeTestMockOp
|
||||
context: {
|
||||
modelId: string;
|
||||
modelRegistry: ModelRegistryLike;
|
||||
providerConfig?: { api?: string | null; baseUrl?: string };
|
||||
agentRuntimeId?: string;
|
||||
authProfileMode?: "api_key" | "aws-sdk" | "oauth" | "token";
|
||||
providerConfig?: {
|
||||
api?: string | null;
|
||||
auth?: "api-key" | "aws-sdk" | "oauth" | "token";
|
||||
baseUrl?: string;
|
||||
};
|
||||
};
|
||||
}) =>
|
||||
handledDynamicProviders.has(params.provider)
|
||||
@@ -704,6 +729,8 @@ export function createProviderRuntimeTestMock(options: ProviderRuntimeTestMockOp
|
||||
provider: params.provider,
|
||||
modelId: params.context.modelId,
|
||||
modelRegistry: params.context.modelRegistry,
|
||||
agentRuntimeId: params.context.agentRuntimeId,
|
||||
authProfileMode: params.context.authProfileMode,
|
||||
providerConfig: params.context.providerConfig,
|
||||
},
|
||||
{
|
||||
|
||||
@@ -22,6 +22,7 @@ import { resolveDefaultAgentDir } from "../agent-scope.js";
|
||||
import { ensureAuthProfileStore, resolveAuthProfileOrder } from "../auth-profiles.js";
|
||||
import type { AuthProfileCredential } from "../auth-profiles/types.js";
|
||||
import { DEFAULT_CONTEXT_TOKENS } from "../defaults.js";
|
||||
import { resolveAgentHarnessPolicy } from "../harness/policy.js";
|
||||
import { buildModelAliasLines } from "../model-alias-lines.js";
|
||||
import { resolveModelWorkspaceDir } from "../model-discovery-context.js";
|
||||
import { modelKey, normalizeStaticProviderModelId } from "../model-ref-shared.js";
|
||||
@@ -1134,6 +1135,12 @@ function resolvePluginDynamicModelWithRegistry(params: {
|
||||
const { provider, modelId, modelRegistry, cfg, agentDir, workspaceDir } = params;
|
||||
const runtimeHooks = params.runtimeHooks ?? DEFAULT_PROVIDER_RUNTIME_HOOKS;
|
||||
const providerConfig = resolveConfiguredProviderConfig(cfg, provider);
|
||||
const agentHarnessPolicy = resolveAgentHarnessPolicy({ provider, modelId, config: cfg });
|
||||
const agentRuntimeId =
|
||||
agentHarnessPolicy.runtimeSource !== "implicit" ||
|
||||
cfg?.plugins?.entries?.codex?.enabled === true
|
||||
? agentHarnessPolicy.runtime
|
||||
: undefined;
|
||||
const authProfile = resolveDynamicModelAuthProfile({
|
||||
provider,
|
||||
cfg,
|
||||
@@ -1157,6 +1164,7 @@ function resolvePluginDynamicModelWithRegistry(params: {
|
||||
config: cfg,
|
||||
agentDir,
|
||||
workspaceDir,
|
||||
...(agentRuntimeId ? { agentRuntimeId } : {}),
|
||||
provider,
|
||||
modelId,
|
||||
modelRegistry,
|
||||
|
||||
@@ -510,6 +510,7 @@ export type ProviderResolveDynamicModelContext = {
|
||||
config?: OpenClawConfig;
|
||||
agentDir?: string;
|
||||
workspaceDir?: string;
|
||||
agentRuntimeId?: string;
|
||||
provider: string;
|
||||
modelId: string;
|
||||
modelRegistry: ModelRegistry;
|
||||
|
||||
Reference in New Issue
Block a user