feat(coding-agent): expose model resolution helpers

closes #6201
This commit is contained in:
Vegard Stikbakke
2026-07-01 10:22:35 +02:00
parent 1d061b3f45
commit 040f0a5197
5 changed files with 119 additions and 5 deletions
+28
View File
@@ -405,6 +405,32 @@ If no model is provided:
2. Uses default from settings
3. Falls back to first available model
To match CLI model parsing, use the exported resolver helpers:
```typescript
import {
resolveCliModel,
resolveModelScopeWithDiagnostics,
} from "@earendil-works/pi-coding-agent";
const cliModel = resolveCliModel({
cliModel: "anthropic/claude-opus-4-5:high",
modelRegistry,
});
if (cliModel.error) throw new Error(cliModel.error);
if (cliModel.warning) console.warn(cliModel.warning);
const { scopedModels, diagnostics } = await resolveModelScopeWithDiagnostics(
["anthropic/*:high", "gpt-5"],
modelRegistry,
);
for (const diagnostic of diagnostics) {
console.warn(diagnostic.message);
}
```
`resolveCliModel()` uses all registered models so `--api-key` style first-time setup can resolve a model before stored auth exists. `resolveModelScopeWithDiagnostics()` matches `--models` and `enabledModels` semantics while returning warnings instead of printing them.
> See [examples/sdk/02-custom-model.ts](../examples/sdk/02-custom-model.ts)
### API Keys and OAuth
@@ -1104,6 +1130,8 @@ AgentSessionRuntime
// Auth and Models
AuthStorage
ModelRegistry
resolveCliModel
resolveModelScopeWithDiagnostics
// Resource loading
DefaultResourceLoader