Refactor OAuth/API key handling: AuthStorage and ModelRegistry

- Add AuthStorage class for credential storage (auth.json)
- Add ModelRegistry class for model management with API key resolution
- Add discoverAuthStorage() and discoverModels() discovery functions
- Add migration from legacy oauth.json and settings.json apiKeys to auth.json
- Remove configureOAuthStorage, defaultGetApiKey, findModel, discoverAvailableModels
- Remove apiKeys from Settings type and SettingsManager methods
- Rename getOAuthPath to getAuthPath
- Update SDK, examples, docs, tests, and mom package

Fixes #296
This commit is contained in:
Mario Zechner 2025-12-25 03:48:36 +01:00
parent 9f97f0c8da
commit 54018b6cc0
29 changed files with 953 additions and 2017 deletions

View file

@ -13,8 +13,8 @@
* pi --hook examples/hooks/custom-compaction.ts
*/
import { complete } from "@mariozechner/pi-ai";
import { findModel, messageTransformer } from "@mariozechner/pi-coding-agent";
import { complete, getModel } from "@mariozechner/pi-ai";
import { messageTransformer } from "@mariozechner/pi-coding-agent";
import type { HookAPI } from "@mariozechner/pi-coding-agent/hooks";
export default function (pi: HookAPI) {
@ -27,10 +27,9 @@ export default function (pi: HookAPI) {
event;
// Use Gemini Flash for summarization (cheaper/faster than most conversation models)
// findModel searches both built-in models and custom models from models.json
const { model, error } = findModel("google", "gemini-2.5-flash");
if (error || !model) {
ctx.ui.notify(`Could not find Gemini Flash model: ${error}, using default compaction`, "warning");
const model = getModel("google", "gemini-2.5-flash");
if (!model) {
ctx.ui.notify(`Could not find Gemini Flash model, using default compaction`, "warning");
return;
}