Skip to content

Commit b17cac3

Browse files
committed
refactor(openai): overlay auth hooks in place
1 parent 31f1f2e commit b17cac3

2 files changed

Lines changed: 17 additions & 24 deletions

File tree

‎extensions/openai/openai-provider.ts‎

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Openai provider module implements model/runtime integration.
22
import type {
3-
ProviderAuthMethod,
43
ProviderResolveDynamicModelContext,
54
ProviderRuntimeModel,
65
} from "openclaw/plugin-sdk/plugin-entry";
@@ -893,8 +892,8 @@ function resolveOpenAIGptForwardCompatModel(ctx: ProviderResolveDynamicModelCont
893892
}
894893

895894
export function buildOpenAIProvider(): ProviderPlugin {
896-
const provider = createOpenAIProvider();
897-
const apiKeyDefinition = provider.auth.find((method) => method.id === "api-key");
895+
const providerDefinition = createOpenAIProvider();
896+
const apiKeyDefinition = providerDefinition.auth.find((method) => method.id === "api-key");
898897
if (!apiKeyDefinition) {
899898
throw new Error("OpenAI provider contract is missing API-key auth");
900899
}
@@ -915,27 +914,24 @@ export function buildOpenAIProvider(): ProviderPlugin {
915914
applyConfig: (cfg) => applyOpenAIConfig(cfg),
916915
wizard: apiKeyDefinition.wizard,
917916
});
918-
const auth = provider.auth.map((method): ProviderAuthMethod => {
917+
for (const method of providerDefinition.auth) {
919918
if (method.id === "oauth" || method.id === "device-code") {
920-
return { ...method, run: chatGPTAuthRuns[method.id] };
919+
method.run = chatGPTAuthRuns[method.id];
920+
continue;
921921
}
922-
if (method.id === "api-key") {
923-
return {
924-
...method,
925-
starterModel: apiKeyRuntime.starterModel,
926-
run: apiKeyRuntime.run,
927-
runNonInteractive: apiKeyRuntime.runNonInteractive,
928-
validateNonInteractive: apiKeyRuntime.validateNonInteractive,
929-
};
922+
if (method.id !== "api-key") {
923+
throw new Error(`OpenAI provider contract has unknown auth method: ${method.id}`);
930924
}
931-
throw new Error(`OpenAI provider contract has unknown auth method: ${method.id}`);
932-
});
925+
method.starterModel = apiKeyRuntime.starterModel;
926+
method.run = apiKeyRuntime.run;
927+
method.runNonInteractive = apiKeyRuntime.runNonInteractive;
928+
method.validateNonInteractive = apiKeyRuntime.validateNonInteractive;
929+
}
933930
const codexHooks = buildOpenAICodexProviderHooks();
934931
const nativeResponsesHooks = buildOpenAIResponsesProviderHooks();
935932
const responsesHooks = buildOpenAIResponsesProviderHooks({ transport: "sse" });
936933
return {
937-
...provider,
938-
auth,
934+
...providerDefinition,
939935
catalog: {
940936
order: "simple",
941937
run: async (ctx) => {

‎extensions/openai/setup-api.ts‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,10 @@ async function runOpenAIProviderAuthMethod(
1818

1919
export function buildOpenAISetupProvider(): ProviderPlugin {
2020
const provider = createOpenAIProvider();
21-
return {
22-
...provider,
23-
auth: provider.auth.map((method) => ({
24-
...method,
25-
run: async (ctx) => runOpenAIProviderAuthMethod(method.id, ctx),
26-
})),
27-
};
21+
for (const method of provider.auth) {
22+
method.run = async (ctx) => runOpenAIProviderAuthMethod(method.id, ctx);
23+
}
24+
return provider;
2825
}
2926

3027
export default definePluginEntry({

0 commit comments

Comments
 (0)