Files
oh-my-pi/packages/coding-agent/src/extensibility/extensions/model-api.ts
T
can1357 ef7636805b feat(coding-agent): removed canonical model variant selection and tracking
- Removed the canonical model variant indexing, selection, and tracking logic from the model registry and resolver.
- Eliminated the `canonical` sub-command, tab view, search tokens, and equivalence configuration structures from the CLI and model selector components.
- Refined model identification, lookup, and provider fallback resolution to bind exclusively to standard, raw model IDs.
- Relocated the equivalence utility script within the catalog package to support script-only policy generation.
2026-07-01 05:22:42 +02:00

40 lines
1.7 KiB
TypeScript

/**
* Model query facade exposed to extensions as `ctx.models`.
*
* Read-only: lets an extension select a model the same way core does — list
* authenticated models, read the session model, resolve a model string or role
* alias, and compare model families — without touching the mutable registry or
* duplicating resolution/family heuristics.
*/
import type { Api, Model } from "@oh-my-pi/pi-ai";
import { modelFamilyToken } from "@oh-my-pi/pi-catalog/identity";
import type { ModelRegistry } from "../../config/model-registry";
import { getModelMatchPreferences, resolveModelRoleValue } from "../../config/model-resolver";
import type { Settings } from "../../config/settings";
import type { ExtensionModelQuery } from "./types";
/**
* Build the `ctx.models` facade. `getModel` is read lazily so `current()` always
* reflects the live session model (it can change mid-session via `/model`).
*/
export function createExtensionModelQuery(
modelRegistry: ModelRegistry,
settings: Settings | undefined,
getModel: () => Model | undefined,
): ExtensionModelQuery {
return {
list: () => modelRegistry.getAvailable(),
current: () => getModel(),
// resolveModelRoleValue expands a role alias (`pi/slow`) to its full configured
// priority list and tries each pattern — the same path core selection uses — so a
// fallback model lower in the list still resolves. Plain model strings pass through
// as a single pattern.
resolve: (spec: string): Model<Api> | undefined =>
resolveModelRoleValue(spec, modelRegistry.getAvailable(), {
settings,
matchPreferences: getModelMatchPreferences(settings),
}).model,
family: (model: Model<Api>): string => modelFamilyToken(model.id) || model.provider.toLowerCase(),
};
}