pi-open-agents 0.1.11 → 0.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-open-agents",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "description": "Unified agent and subagent management for pi coding agent, with OpenCode-compatible agent definitions.",
5
5
  "keywords": [
6
6
  "pi-package",
@@ -339,6 +339,45 @@ function buildTaskArgument(task: string, taskFilePath: string | undefined): stri
339
339
  return taskFilePath ? `Task: @${taskFilePath}` : `Task: ${task}`;
340
340
  }
341
341
 
342
+ // ─── Model Registry (best-effort) ───────────────────────────────────────────
343
+
344
+ interface AuthFactory {
345
+ create(authPath?: string): unknown;
346
+ }
347
+ interface RegistryFactory {
348
+ create(authStore: unknown, modelsPath: string | undefined): ContextWindowLookup;
349
+ }
350
+
351
+ /**
352
+ * Build a model registry for cost/context-window enrichment — best-effort and
353
+ * resilient.
354
+ *
355
+ * AuthStorage/ModelRegistry availability and signatures vary across
356
+ * pi-coding-agent host versions (AuthStorage was removed in newer releases;
357
+ * ModelRegistry's create() signature also changed). The registry is purely
358
+ * cosmetic — downstream usage enrichment tolerates a missing registry (see the
359
+ * contextWindowFromMessage / usageFromMessage guards). This must never throw, or
360
+ * subagent delegation breaks entirely. Factories are injectable for testing;
361
+ * pass `{ auth: undefined, model: undefined }` to simulate a host that lacks
362
+ * these symbols.
363
+ */
364
+ export function buildModelRegistry(
365
+ agentDir: string | undefined,
366
+ factories: { auth?: AuthFactory; model?: RegistryFactory } = {},
367
+ ): ContextWindowLookup | undefined {
368
+ const auth = ("auth" in factories ? factories.auth : AuthStorage) as AuthFactory | undefined;
369
+ const model = ("model" in factories ? factories.model : ModelRegistry) as RegistryFactory | undefined;
370
+ try {
371
+ if (!auth || typeof auth.create !== "function") return undefined;
372
+ if (!model || typeof model.create !== "function") return undefined;
373
+ const authPath = agentDir ? path.join(agentDir, "auth.json") : undefined;
374
+ const modelsPath = agentDir ? path.join(agentDir, "models.json") : undefined;
375
+ return model.create(auth.create(authPath), modelsPath);
376
+ } catch {
377
+ return undefined;
378
+ }
379
+ }
380
+
342
381
  // ─── Main Executor ───────────────────────────────────────────────────────────
343
382
 
344
383
  /**
@@ -413,13 +452,8 @@ export async function runSubagent(options: RunSubagentOptions): Promise<AgentRes
413
452
  // ── Resolve pi CLI entry point ──
414
453
  const pi = await resolvePi();
415
454
 
416
- // ── Build model registry for cost lookups ──
417
- const modelRegistry = ModelRegistry.create(
418
- AuthStorage.create(
419
- options.agentDir ? path.join(options.agentDir, "auth.json") : undefined,
420
- ),
421
- options.agentDir ? path.join(options.agentDir, "models.json") : undefined,
422
- );
455
+ // ── Build model registry for cost lookups (best-effort) ──
456
+ const modelRegistry = buildModelRegistry(options.agentDir);
423
457
 
424
458
  // ── Build CLI args ──
425
459
  const args = [