Skip to content

Commit a44a3f9

Browse files
committed
fix(auth): resolve plugin auth metadata cold
1 parent bbd9702 commit a44a3f9

3 files changed

Lines changed: 49 additions & 16 deletions

File tree

src/agents/model-auth-markers.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { SecretRefSource } from "../config/types.secrets.js";
2-
import { loadPluginManifestRegistry } from "../plugins/manifest-registry.js";
2+
import { loadPluginManifestRegistryForInstalledIndex } from "../plugins/manifest-registry-installed.js";
3+
import { loadPluginRegistrySnapshot } from "../plugins/plugin-registry.js";
34
import { listKnownProviderEnvApiKeyNames } from "./model-auth-env-vars.js";
45

56
export const MINIMAX_OAUTH_MARKER = "minimax-oauth";
@@ -44,14 +45,20 @@ function listKnownEnvApiKeyMarkers(): Set<string> {
4445
}
4546

4647
export function listKnownNonSecretApiKeyMarkers(): string[] {
47-
knownNonSecretApiKeyMarkersCache ??= [
48-
...new Set([
49-
...CORE_NON_SECRET_API_KEY_MARKERS,
50-
...loadPluginManifestRegistry({ cache: true }).plugins.flatMap((plugin) =>
51-
plugin.origin === "bundled" ? (plugin.nonSecretAuthMarkers ?? []) : [],
52-
),
53-
]),
54-
];
48+
knownNonSecretApiKeyMarkersCache ??= (() => {
49+
const index = loadPluginRegistrySnapshot({});
50+
return [
51+
...new Set([
52+
...CORE_NON_SECRET_API_KEY_MARKERS,
53+
...loadPluginManifestRegistryForInstalledIndex({
54+
index,
55+
includeDisabled: true,
56+
}).plugins.flatMap((plugin) =>
57+
plugin.origin === "bundled" ? (plugin.nonSecretAuthMarkers ?? []) : [],
58+
),
59+
]),
60+
];
61+
})();
5562
return [...knownNonSecretApiKeyMarkersCache];
5663
}
5764

src/plugins/provider-auth-choices.test.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1-
import { describe, expect, it, vi } from "vitest";
1+
import { beforeEach, describe, expect, it, vi } from "vitest";
22

3-
const loadPluginManifestRegistry = vi.hoisted(() => vi.fn());
3+
const pluginRegistryMocks = vi.hoisted(() => ({
4+
loadPluginManifestRegistryForInstalledIndex: vi.fn(),
5+
loadPluginRegistrySnapshot: vi.fn(() => ({ plugins: [] })),
6+
}));
7+
8+
vi.mock("./manifest-registry-installed.js", () => ({
9+
loadPluginManifestRegistryForInstalledIndex:
10+
pluginRegistryMocks.loadPluginManifestRegistryForInstalledIndex,
11+
}));
412

5-
vi.mock("./manifest-registry.js", () => ({
6-
loadPluginManifestRegistry,
13+
vi.mock("./plugin-registry.js", () => ({
14+
loadPluginRegistrySnapshot: pluginRegistryMocks.loadPluginRegistrySnapshot,
715
}));
816

917
import {
@@ -26,7 +34,7 @@ function createProviderAuthChoice(overrides: Record<string, unknown>) {
2634
}
2735

2836
function setManifestPlugins(plugins: Array<Record<string, unknown>>) {
29-
loadPluginManifestRegistry.mockReturnValue({
37+
pluginRegistryMocks.loadPluginManifestRegistryForInstalledIndex.mockReturnValue({
3038
plugins,
3139
});
3240
}
@@ -53,6 +61,15 @@ function setSingleManifestProviderAuthChoices(
5361
}
5462

5563
describe("provider auth choice manifest helpers", () => {
64+
beforeEach(() => {
65+
pluginRegistryMocks.loadPluginManifestRegistryForInstalledIndex.mockReset();
66+
pluginRegistryMocks.loadPluginManifestRegistryForInstalledIndex.mockReturnValue({
67+
plugins: [],
68+
});
69+
pluginRegistryMocks.loadPluginRegistrySnapshot.mockReset();
70+
pluginRegistryMocks.loadPluginRegistrySnapshot.mockReturnValue({ plugins: [] });
71+
});
72+
5673
it("flattens manifest auth choices", () => {
5774
setSingleManifestProviderAuthChoices("openai", [
5875
createProviderAuthChoice({

src/plugins/provider-auth-choices.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import { resolveProviderIdForAuth } from "../agents/provider-auth-aliases.js";
22
import type { OpenClawConfig } from "../config/types.openclaw.js";
33
import { sanitizeForLog } from "../terminal/ansi.js";
44
import { normalizePluginsConfig, resolveEffectiveEnableState } from "./config-state.js";
5-
import { loadPluginManifestRegistry, type PluginManifestRecord } from "./manifest-registry.js";
5+
import { loadPluginManifestRegistryForInstalledIndex } from "./manifest-registry-installed.js";
6+
import type { PluginManifestRecord } from "./manifest-registry.js";
67
import type { PluginOrigin } from "./plugin-origin.types.js";
8+
import { loadPluginRegistrySnapshot } from "./plugin-registry.js";
79

810
export type ProviderAuthChoiceMetadata = {
911
pluginId: string;
@@ -179,11 +181,18 @@ function resolveManifestProviderAuthChoiceCandidates(params?: {
179181
env?: NodeJS.ProcessEnv;
180182
includeUntrustedWorkspacePlugins?: boolean;
181183
}): ProviderAuthChoiceCandidate[] {
182-
const registry = loadPluginManifestRegistry({
184+
const index = loadPluginRegistrySnapshot({
183185
config: params?.config,
184186
workspaceDir: params?.workspaceDir,
185187
env: params?.env,
186188
});
189+
const registry = loadPluginManifestRegistryForInstalledIndex({
190+
index,
191+
config: params?.config,
192+
workspaceDir: params?.workspaceDir,
193+
env: params?.env,
194+
includeDisabled: true,
195+
});
187196
const normalizedConfig = normalizePluginsConfig(params?.config?.plugins);
188197
return registry.plugins.flatMap((plugin) => {
189198
if (

0 commit comments

Comments
 (0)