Skip to content

Commit 742801a

Browse files
authored
perf(plugin-sdk): narrow provider auth imports (#134626)
1 parent e910f86 commit 742801a

9 files changed

Lines changed: 42 additions & 25 deletions

File tree

‎docs/plugins/sdk-provider-plugins.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,13 @@ catalog, API-key auth, and dynamic model resolution.
206206
`openclaw onboard --acme-ai-api-key <key>` and select
207207
`acme-ai/acme-large` as their model.
208208

209+
For provider-key lookup and selection from an already loaded auth store,
210+
import `findNormalizedProviderValue` and `resolveAuthProfileOrder` from
211+
`openclaw/plugin-sdk/provider-auth`. This keeps provider entrypoints from
212+
loading the full agent runtime just to select a credential. The deprecated
213+
`agent-runtime` exports remain available for compatibility; use the narrower
214+
`provider-auth` route in new code.
215+
209216
A custom interactive auth method that mints a static token or API key can
210217
request protected persistence on its returned profile:
211218

‎extensions/codex/src/app-server/auth-bridge.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
findPersistedAuthProfileCredential,
1313
loadAuthProfileStoreForSecretsRuntime,
1414
refreshOAuthCredentialForRuntime,
15-
resolveAuthProfileOrder,
1615
resolveProviderIdForAuth,
1716
resolveApiKeyForProfile,
1817
resolveDefaultAgentDir,
@@ -23,6 +22,7 @@ import {
2322
} from "openclaw/plugin-sdk/agent-runtime";
2423
import {
2524
hasUsableOAuthCredential,
25+
resolveAuthProfileOrder,
2626
resolveOpenAICodexAuthIdentity,
2727
} from "openclaw/plugin-sdk/provider-auth";
2828
import { readSecretFile } from "openclaw/plugin-sdk/secret-file";

‎extensions/codex/src/command-account.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
// Codex plugin module implements command account behavior.
22
import {
33
ensureAuthProfileStore,
4-
findNormalizedProviderValue,
54
resolveAuthProfileEligibility,
6-
resolveAuthProfileOrder,
75
resolveProfileUnusableUntilForDisplay,
86
type AuthProfileCredential,
97
type AuthProfileFailureReason,
108
type AuthProfileStore,
119
} from "openclaw/plugin-sdk/agent-runtime";
1210
import type { PluginCommandContext } from "openclaw/plugin-sdk/plugin-entry";
11+
import {
12+
findNormalizedProviderValue,
13+
resolveAuthProfileOrder,
14+
} from "openclaw/plugin-sdk/provider-auth";
1315
import {
1416
normalizeOptionalString,
1517
normalizeUniqueStringEntries,

‎extensions/codex/src/conversation-binding.test.ts‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ const agentRuntimeMocks = vi.hoisted(() => ({
4141
ensureAuthProfileStore: vi.fn(),
4242
loadAuthProfileStoreForSecretsRuntime: vi.fn(),
4343
resolveApiKeyForProfile: vi.fn(),
44-
resolveAuthProfileOrder: vi.fn(),
4544
resolveDefaultAgentDir: vi.fn(() => "/agent"),
4645
resolveAgentWorkspaceDir: vi.fn(() => "/agent/workspace"),
4746
resolvePersistedAuthProfileOwnerAgentDir: vi.fn(),
@@ -50,6 +49,10 @@ const agentRuntimeMocks = vi.hoisted(() => ({
5049
saveAuthProfileStore: vi.fn(),
5150
}));
5251

52+
const providerAuthMocks = vi.hoisted(() => ({
53+
resolveAuthProfileOrder: vi.fn(),
54+
}));
55+
5356
const codexRequirementsTomlMock = vi.hoisted(() => vi.fn<() => string | undefined>());
5457
const resolveSandboxContextMock = vi.hoisted(() =>
5558
vi.fn<(...args: unknown[]) => Promise<{ enabled: boolean } | null>>(async () => null),
@@ -131,6 +134,10 @@ vi.mock("openclaw/plugin-sdk/exec-approvals-runtime", async (importOriginal) =>
131134
};
132135
});
133136
vi.mock("openclaw/plugin-sdk/agent-runtime", () => agentRuntimeMocks);
137+
vi.mock("openclaw/plugin-sdk/provider-auth", async (importOriginal) => ({
138+
...(await importOriginal<typeof import("openclaw/plugin-sdk/provider-auth")>()),
139+
resolveAuthProfileOrder: providerAuthMocks.resolveAuthProfileOrder,
140+
}));
134141
vi.mock("openclaw/plugin-sdk/agent-scope-runtime", async (importOriginal) => ({
135142
...(await importOriginal<typeof import("openclaw/plugin-sdk/agent-scope-runtime")>()),
136143
resolveSessionAgentIdsStrict: agentRuntimeMocks.resolveSessionAgentIdsStrict,
@@ -426,7 +433,7 @@ describe("codex conversation binding", () => {
426433
agentRuntimeMocks.ensureAuthProfileStore.mockReset();
427434
agentRuntimeMocks.loadAuthProfileStoreForSecretsRuntime.mockReset();
428435
agentRuntimeMocks.resolveApiKeyForProfile.mockReset();
429-
agentRuntimeMocks.resolveAuthProfileOrder.mockReset();
436+
providerAuthMocks.resolveAuthProfileOrder.mockReset();
430437
agentRuntimeMocks.resolveDefaultAgentDir.mockClear();
431438
agentRuntimeMocks.resolvePersistedAuthProfileOwnerAgentDir.mockReset();
432439
agentRuntimeMocks.resolveProviderIdForAuth.mockClear();
@@ -443,7 +450,7 @@ describe("codex conversation binding", () => {
443450
version: 1,
444451
profiles: {},
445452
});
446-
agentRuntimeMocks.resolveAuthProfileOrder.mockReturnValue([]);
453+
providerAuthMocks.resolveAuthProfileOrder.mockReturnValue([]);
447454
agentRuntimeMocks.resolveDefaultAgentDir.mockReturnValue("/agent");
448455
agentRuntimeMocks.resolveProviderIdForAuth.mockImplementation(
449456
(provider: string, _lookup?: { config?: unknown }) => provider,
@@ -720,7 +727,7 @@ describe("codex conversation binding", () => {
720727
},
721728
},
722729
});
723-
agentRuntimeMocks.resolveAuthProfileOrder.mockReturnValue(["openai:default"]);
730+
providerAuthMocks.resolveAuthProfileOrder.mockReturnValue(["openai:default"]);
724731
sharedClientMocks.getSharedCodexAppServerClient.mockResolvedValue({
725732
request: vi.fn(async (method: string, requestParams: Record<string, unknown>) => {
726733
requests.push({ method, params: requestParams });
@@ -740,7 +747,7 @@ describe("codex conversation binding", () => {
740747
modelProvider: "openai",
741748
});
742749

743-
const authOrderParams = mockCallArg(agentRuntimeMocks.resolveAuthProfileOrder) as {
750+
const authOrderParams = mockCallArg(providerAuthMocks.resolveAuthProfileOrder) as {
744751
cfg?: unknown;
745752
provider?: unknown;
746753
};

‎extensions/github-copilot/auth.test.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@ const coerceSecretRefMock = vi.hoisted(() => vi.fn());
88
const resolveConfiguredSecretInputWithFallbackMock = vi.hoisted(() => vi.fn());
99
const resolveRequiredConfiguredSecretRefInputStringMock = vi.hoisted(() => vi.fn());
1010

11-
vi.mock("openclaw/plugin-sdk/provider-auth", async () => {
11+
vi.mock("openclaw/plugin-sdk/provider-auth", async (importOriginal) => {
12+
const { findNormalizedProviderValue, resolveAuthProfileOrder } =
13+
await importOriginal<typeof import("openclaw/plugin-sdk/provider-auth")>();
1214
const { normalizeOptionalString } = await import("openclaw/plugin-sdk/string-coerce-runtime");
1315
return {
1416
coerceSecretRef: coerceSecretRefMock,
1517
ensureAuthProfileStore: ensureAuthProfileStoreMock,
18+
findNormalizedProviderValue,
1619
listProfilesForProvider: listProfilesForProviderMock,
1720
normalizeOptionalSecretInput: normalizeOptionalString,
21+
resolveAuthProfileOrder,
1822
};
1923
});
2024

‎extensions/github-copilot/auth.ts‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
// Github Copilot plugin module implements auth behavior.
2-
import {
3-
findNormalizedProviderValue,
4-
resolveAuthProfileOrder,
5-
} from "openclaw/plugin-sdk/agent-runtime";
62
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
73
import type { ProviderPrepareDynamicModelContext } from "openclaw/plugin-sdk/plugin-entry";
84
import {
95
coerceSecretRef,
106
ensureAuthProfileStore,
7+
findNormalizedProviderValue,
118
listProfilesForProvider,
129
normalizeOptionalSecretInput,
10+
resolveAuthProfileOrder,
1311
} from "openclaw/plugin-sdk/provider-auth";
1412
import {
1513
resolveConfiguredSecretInputWithFallback,

‎scripts/plugin-sdk-surface-report.mts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,8 @@ export function readPluginSdkSurfaceBudgets(env: NodeJS.ProcessEnv = process.env
329329
// +2: strict session-agent resolution aliases preserve shipped Plugin SDK behavior.
330330
// +1: manifest-owned plugin capability secret availability guard.
331331
// +1: canonical diagnostic flag checker through its focused subpath.
332-
4353,
332+
// +2: focused provider-auth routes for shipped auth ordering and provider-map lookup.
333+
4355,
333334
env,
334335
),
335336
publicFunctionExports: readPluginSdkSurfaceBudgetEnv(
@@ -435,7 +436,8 @@ export function readPluginSdkSurfaceBudgets(env: NodeJS.ProcessEnv = process.env
435436
// +2: strict session-agent resolution aliases preserve shipped Plugin SDK behavior.
436437
// +1: manifest-owned plugin capability secret availability guard.
437438
// +1: canonical diagnostic flag checker through its focused subpath.
438-
2591,
439+
// +2: focused provider-auth routes for shipped auth ordering and provider-map lookup.
440+
2593,
439441
env,
440442
),
441443
publicDeprecatedExports: readPluginSdkSurfaceBudgetEnv(

‎src/plugin-sdk/provider-auth.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ export type { ProviderAuthResult } from "../plugins/types.js";
5454
export type { ProviderAuthContext } from "../plugins/types.js";
5555
export type { AuthProfileStore, OAuthCredential } from "../agents/auth-profiles/types.js";
5656

57-
export { normalizeGithubCopilotDomain };
57+
export { findNormalizedProviderValue } from "@openclaw/model-catalog-core/provider-id";
58+
export { normalizeGithubCopilotDomain, resolveAuthProfileOrder };
5859
export { CLAUDE_CLI_PROFILE_ID, CODEX_CLI_PROFILE_ID } from "../agents/auth-profiles/constants.js";
5960
export {
6061
ensureAuthProfileStore,

‎src/plugin-sdk/test-helpers/provider-discovery-contract.ts‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,9 @@ function providerModelIds(provider: Record<string, unknown>): Array<unknown> {
138138
function installDiscoveryHooks(state: DiscoveryState, options: DiscoveryContractOptions) {
139139
beforeAll(async () => {
140140
vi.resetModules();
141-
vi.doMock("openclaw/plugin-sdk/agent-runtime", async (importOriginal) => {
142-
const actual = await importOriginal<typeof import("../agent-runtime.js")>();
143-
return {
144-
...actual,
145-
ensureAuthProfileStore: ensureAuthProfileStoreMock,
146-
listProfilesForProvider: listProfilesForProviderMock,
147-
};
148-
});
149-
vi.doMock("openclaw/plugin-sdk/provider-auth", () => {
141+
vi.doMock("openclaw/plugin-sdk/provider-auth", async (importOriginal) => {
142+
const { findNormalizedProviderValue, resolveAuthProfileOrder } =
143+
await importOriginal<typeof import("../provider-auth.js")>();
150144
return {
151145
DEFAULT_COPILOT_API_BASE_URL: "https://api.individual.githubcopilot.com",
152146
MINIMAX_OAUTH_MARKER: "minimax-oauth",
@@ -169,6 +163,7 @@ function installDiscoveryHooks(state: DiscoveryState, options: DiscoveryContract
169163
coerceSecretRef: asNullableRecord,
170164
ensureApiKeyFromOptionEnvOrPrompt: vi.fn(),
171165
ensureAuthProfileStore: ensureAuthProfileStoreMock,
166+
findNormalizedProviderValue,
172167
listProfilesForProvider: listProfilesForProviderMock,
173168
normalizeApiKeyInput: (value: unknown) => (typeof value === "string" ? value.trim() : ""),
174169
normalizeGithubCopilotDomain: (raw: unknown) => {
@@ -178,6 +173,7 @@ function installDiscoveryHooks(state: DiscoveryState, options: DiscoveryContract
178173
: "github.com";
179174
},
180175
normalizeOptionalSecretInput: normalizeOptionalString,
176+
resolveAuthProfileOrder,
181177
resolveNonEnvSecretRefApiKeyMarker: (source: unknown) =>
182178
typeof source === "string" ? source : "",
183179
upsertAuthProfile: vi.fn(),

0 commit comments

Comments
 (0)