

























@@ -2131,6 +2131,51 @@ function createStaticLiveModelRegistry(models: Array<Model>): LiveModelRegistry
21312131};
21322132}
213321332134+async function loadAuthBackedLiveModelRegistry(params: {
2135+agentDir: string;
2136+cfg: OpenClawConfig;
2137+providerList: string[] | undefined;
2138+}): Promise<{
2139+authProfileStore: AuthProfileStore;
2140+modelRegistry: LiveModelRegistry;
2141+all: Array<Model>;
2142+}> {
2143+const authProfileStore = await withGatewayLiveSetupTimeout(
2144+Promise.resolve().then(() =>
2145+params.providerList
2146+ ? ensureAuthProfileStoreWithoutExternalProfiles(params.agentDir, {
2147+allowKeychainPrompt: false,
2148+})
2149+ : ensureAuthProfileStore(params.agentDir, {
2150+allowKeychainPrompt: false,
2151+}),
2152+),
2153+"[all-models] load auth profiles",
2154+);
2155+const authStorage = await withGatewayLiveSetupTimeout(
2156+Promise.resolve().then(() =>
2157+discoverAuthStorage(params.agentDir, {
2158+config: params.cfg,
2159+env: process.env,
2160+ ...(params.providerList
2161+ ? {
2162+skipExternalAuthProfiles: true,
2163+syntheticAuthProviderRefs: [],
2164+}
2165+ : {}),
2166+}),
2167+),
2168+"[all-models] load auth storage",
2169+);
2170+logProgress("[all-models] loading model registry");
2171+const modelRegistry = discoverModels(authStorage, params.agentDir);
2172+const all = await withGatewayLiveSetupTimeout(
2173+Promise.resolve().then(() => modelRegistry.getAll()),
2174+"[all-models] load model registry",
2175+);
2176+return { authProfileStore, modelRegistry, all };
2177+}
2178+21342179function toLiveModelConfig(model: Model): NonNullable<ModelProviderConfig["models"]>[number] {
21352180return {
21362181id: model.id,
@@ -3280,42 +3325,25 @@ describeLive("gateway live (dev agent, profile keys)", () => {
32803325loadProviderScopedModels({ agentDir, providerList: providerScopedModelProviders }),
32813326"[all-models] load provider-scoped model refs",
32823327);
3283-modelRegistry = createStaticLiveModelRegistry(all);
3328+if (all.length > 0) {
3329+modelRegistry = createStaticLiveModelRegistry(all);
3330+} else {
3331+logProgress("[all-models] provider-scoped model refs empty; loading auth profiles");
3332+const authBacked = await loadAuthBackedLiveModelRegistry({
3333+ agentDir,
3334+ cfg,
3335+providerList: providerScopedModelProviders,
3336+});
3337+authProfileStore = authBacked.authProfileStore;
3338+modelRegistry = authBacked.modelRegistry;
3339+all = authBacked.all;
3340+}
32843341} else {
32853342logProgress("[all-models] loading auth profiles");
3286-authProfileStore = await withGatewayLiveSetupTimeout(
3287-Promise.resolve().then(() =>
3288-providerList
3289- ? ensureAuthProfileStoreWithoutExternalProfiles(agentDir, {
3290-allowKeychainPrompt: false,
3291-})
3292- : ensureAuthProfileStore(agentDir, {
3293-allowKeychainPrompt: false,
3294-}),
3295-),
3296-"[all-models] load auth profiles",
3297-);
3298-const authStorage = await withGatewayLiveSetupTimeout(
3299-Promise.resolve().then(() =>
3300-discoverAuthStorage(agentDir, {
3301-config: cfg,
3302-env: process.env,
3303- ...(providerList
3304- ? {
3305-skipExternalAuthProfiles: true,
3306-syntheticAuthProviderRefs: [],
3307-}
3308- : {}),
3309-}),
3310-),
3311-"[all-models] load auth storage",
3312-);
3313-logProgress("[all-models] loading model registry");
3314-modelRegistry = discoverModels(authStorage, agentDir);
3315-all = await withGatewayLiveSetupTimeout(
3316-Promise.resolve().then(() => modelRegistry.getAll()),
3317-"[all-models] load model registry",
3318-);
3343+const authBacked = await loadAuthBackedLiveModelRegistry({ agentDir, cfg, providerList });
3344+authProfileStore = authBacked.authProfileStore;
3345+modelRegistry = authBacked.modelRegistry;
3346+all = authBacked.all;
33193347}
33203348const maxModels = GATEWAY_LIVE_MAX_MODELS;
33213349const targetMatcher = createLiveTargetMatcher({
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。