mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 18:10:45 +00:00
refactor: split models list row sources
This commit is contained in:
@@ -4,14 +4,8 @@ import type { RuntimeEnv } from "../../runtime.js";
|
||||
import { normalizeLowercaseStringOrEmpty } from "../../shared/string-coerce.js";
|
||||
import { resolveConfiguredEntries } from "./list.configured.js";
|
||||
import { formatErrorWithStack } from "./list.errors.js";
|
||||
import {
|
||||
appendCatalogSupplementRows,
|
||||
appendConfiguredProviderRows,
|
||||
appendConfiguredRows,
|
||||
appendDiscoveredRows,
|
||||
appendProviderCatalogRows,
|
||||
loadListModelRegistry,
|
||||
} from "./list.rows.js";
|
||||
import { loadListModelRegistry } from "./list.registry-load.js";
|
||||
import { appendAllModelRowSources, appendConfiguredModelRowSources } from "./list.row-sources.js";
|
||||
import { printModelTable } from "./list.table.js";
|
||||
import type { ModelRow } from "./list.types.js";
|
||||
import { loadModelsConfigWithSource } from "./load-config.js";
|
||||
@@ -98,32 +92,12 @@ export async function modelsListCommand(
|
||||
};
|
||||
|
||||
if (opts.all) {
|
||||
const seenKeys = appendDiscoveredRows({
|
||||
rows,
|
||||
models: modelRegistry?.getAll() ?? [],
|
||||
context: rowContext,
|
||||
});
|
||||
|
||||
appendConfiguredProviderRows({
|
||||
await appendAllModelRowSources({
|
||||
rows,
|
||||
context: rowContext,
|
||||
seenKeys,
|
||||
modelRegistry,
|
||||
useProviderCatalogFastPath,
|
||||
});
|
||||
|
||||
if (modelRegistry) {
|
||||
await appendCatalogSupplementRows({
|
||||
rows,
|
||||
modelRegistry,
|
||||
context: rowContext,
|
||||
seenKeys,
|
||||
});
|
||||
} else if (useProviderCatalogFastPath) {
|
||||
await appendProviderCatalogRows({
|
||||
rows,
|
||||
context: rowContext,
|
||||
seenKeys,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
const registry = modelRegistry;
|
||||
if (!registry) {
|
||||
@@ -131,7 +105,7 @@ export async function modelsListCommand(
|
||||
process.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
appendConfiguredRows({
|
||||
appendConfiguredModelRowSources({
|
||||
rows,
|
||||
entries,
|
||||
modelRegistry: registry,
|
||||
|
||||
14
src/commands/models/list.registry-load.ts
Normal file
14
src/commands/models/list.registry-load.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import type { OpenClawConfig } from "../../config/types.openclaw.js";
|
||||
import { loadModelRegistry } from "./list.registry.js";
|
||||
import { modelKey } from "./shared.js";
|
||||
|
||||
export async function loadListModelRegistry(
|
||||
cfg: OpenClawConfig,
|
||||
opts?: { providerFilter?: string },
|
||||
) {
|
||||
const loaded = await loadModelRegistry(cfg, opts);
|
||||
return {
|
||||
...loaded,
|
||||
discoveredKeys: new Set(loaded.models.map((model) => modelKey(model.provider, model.id))),
|
||||
};
|
||||
}
|
||||
58
src/commands/models/list.row-sources.ts
Normal file
58
src/commands/models/list.row-sources.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import type { ModelRegistry } from "@mariozechner/pi-coding-agent";
|
||||
import {
|
||||
appendCatalogSupplementRows,
|
||||
appendConfiguredProviderRows,
|
||||
appendConfiguredRows,
|
||||
appendDiscoveredRows,
|
||||
appendProviderCatalogRows,
|
||||
type RowBuilderContext,
|
||||
} from "./list.rows.js";
|
||||
import type { ConfiguredEntry, ModelRow } from "./list.types.js";
|
||||
|
||||
type AllModelRowSources = {
|
||||
rows: ModelRow[];
|
||||
context: RowBuilderContext;
|
||||
modelRegistry?: ModelRegistry;
|
||||
useProviderCatalogFastPath: boolean;
|
||||
};
|
||||
|
||||
export async function appendAllModelRowSources(params: AllModelRowSources): Promise<void> {
|
||||
const seenKeys = appendDiscoveredRows({
|
||||
rows: params.rows,
|
||||
models: params.modelRegistry?.getAll() ?? [],
|
||||
context: params.context,
|
||||
});
|
||||
|
||||
appendConfiguredProviderRows({
|
||||
rows: params.rows,
|
||||
context: params.context,
|
||||
seenKeys,
|
||||
});
|
||||
|
||||
if (params.modelRegistry) {
|
||||
await appendCatalogSupplementRows({
|
||||
rows: params.rows,
|
||||
modelRegistry: params.modelRegistry,
|
||||
context: params.context,
|
||||
seenKeys,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (params.useProviderCatalogFastPath) {
|
||||
await appendProviderCatalogRows({
|
||||
rows: params.rows,
|
||||
context: params.context,
|
||||
seenKeys,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function appendConfiguredModelRowSources(params: {
|
||||
rows: ModelRow[];
|
||||
entries: ConfiguredEntry[];
|
||||
modelRegistry: ModelRegistry;
|
||||
context: RowBuilderContext;
|
||||
}): void {
|
||||
appendConfiguredRows(params);
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import { normalizeProviderId } from "../../agents/provider-id.js";
|
||||
import type { ModelDefinitionConfig, ModelProviderConfig } from "../../config/types.models.js";
|
||||
import type { OpenClawConfig } from "../../config/types.openclaw.js";
|
||||
import type { ListRowModel } from "./list.model-row.js";
|
||||
import { loadModelRegistry, toModelRow } from "./list.registry.js";
|
||||
import { toModelRow } from "./list.registry.js";
|
||||
import {
|
||||
loadModelCatalog,
|
||||
loadProviderCatalogModelsForList,
|
||||
@@ -23,7 +23,7 @@ type RowFilter = {
|
||||
local?: boolean;
|
||||
};
|
||||
|
||||
type RowBuilderContext = {
|
||||
export type RowBuilderContext = {
|
||||
cfg: OpenClawConfig;
|
||||
agentDir: string;
|
||||
authStore: AuthProfileStore;
|
||||
@@ -114,17 +114,6 @@ function shouldListConfiguredProviderModel(params: {
|
||||
);
|
||||
}
|
||||
|
||||
export async function loadListModelRegistry(
|
||||
cfg: OpenClawConfig,
|
||||
opts?: { providerFilter?: string },
|
||||
) {
|
||||
const loaded = await loadModelRegistry(cfg, opts);
|
||||
return {
|
||||
...loaded,
|
||||
discoveredKeys: new Set(loaded.models.map((model) => modelKey(model.provider, model.id))),
|
||||
};
|
||||
}
|
||||
|
||||
export function appendDiscoveredRows(params: {
|
||||
rows: ModelRow[];
|
||||
models: Model<Api>[];
|
||||
|
||||
Reference in New Issue
Block a user