feat(coding-agent): expose dynamic provider refresh
This commit is contained in:
@@ -1677,7 +1677,7 @@ Register or override a model provider dynamically. Useful for proxies, custom en
|
||||
|
||||
Calls made during the extension factory function are queued and applied once the runner initialises. Calls made after that — for example from a command handler following a user setup flow — take effect immediately without requiring a `/reload`.
|
||||
|
||||
If you need to discover models from a remote endpoint, prefer an async extension factory over deferring the fetch to `session_start`. pi waits for the factory before startup continues, so the registered models are available immediately, including to `pi --list-models`.
|
||||
Dynamic providers can implement `refreshModels`. Pi calls it during model refresh, publishes the returned list synchronously through the provider, and passes the canonical credential/store/network/signal context. The extension decides whether to persist the catalog through `context.store`; live servers such as llama.cpp can ignore it.
|
||||
|
||||
```typescript
|
||||
// Register a new provider with custom models
|
||||
@@ -1699,6 +1699,26 @@ pi.registerProvider("my-proxy", {
|
||||
]
|
||||
});
|
||||
|
||||
// Register a live llama.cpp catalog without persisting discovered models
|
||||
pi.registerProvider("llama.cpp", {
|
||||
baseUrl: "http://localhost:8080/v1",
|
||||
apiKey: "local",
|
||||
api: "openai-completions",
|
||||
async refreshModels({ signal }) {
|
||||
const response = await fetch("http://localhost:8080/v1/models", { signal });
|
||||
const { data } = await response.json();
|
||||
return data.map(({ id }) => ({
|
||||
id,
|
||||
name: id,
|
||||
reasoning: false,
|
||||
input: ["text"],
|
||||
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
||||
contextWindow: 128000,
|
||||
maxTokens: 16384
|
||||
}));
|
||||
}
|
||||
});
|
||||
|
||||
// Override baseUrl for an existing provider (keeps all models)
|
||||
pi.registerProvider("anthropic", {
|
||||
baseUrl: "https://proxy.example.com"
|
||||
@@ -1736,6 +1756,7 @@ pi.registerProvider("corporate-ai", {
|
||||
- `headers` - Custom headers to include in requests.
|
||||
- `authHeader` - If true, adds `Authorization: Bearer` header automatically.
|
||||
- `models` - Array of model definitions. If provided, replaces all existing models for this provider. Model definitions can set `baseUrl` to override the provider endpoint for that model.
|
||||
- `refreshModels` - Async dynamic discovery callback. Its returned models replace extension-provided models. Use the scoped `context.store` only when results should persist.
|
||||
- `oauth` - OAuth provider config for `/login` support. When provided, the provider appears in the login menu.
|
||||
- `streamSimple` - Custom streaming implementation for non-standard APIs.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user