pi-ext bugabingas pi extensions
owned by bugabinga
README Source History Refs Compare Notes Search refactor: resolve stream auth through modelRegistry e4c9f4d9e7449e7e22541dea722f30903e937090
Oliver Jan Krylow <oliver@bugabinga.net > · 21 Sep 2026
SSH signature · not checked
Browse files Compare with HEAD
Drop manual getApiKeyAndHeaders and provider lookups in decay
summarize/classify in favor of modelRegistry.streamSimple, and remove
the action-summarizer auth pre-resolution now that registry complete
resolves authentication itself.
Changed files (3) extensions/decay/implementation.ts Modified 492 492 signal : AbortSignal,
493 493 callbacks : RunCallbacks,
494 494 ):
Promise < {
prose : string;
usage : Usage }
> {
495 - const auth
= await ctx.modelRegistry.
getApiKeyAndHeaders (model);
497 - throw new
Error (auth.error ||
"Decay model authentication failed" );
498 - const provider
= ctx.modelRegistry.
getProvider (model.provider);
499 - if (!provider) throw new
Error (
`Decay provider not found: ${model.provider}` );
500 - const stream
= provider.
streamSimple (
495 + const stream
= ctx.modelRegistry.
streamSimple (
502 497 normalizeContext (
buildSummarizerContext (atoms, manualInstructions)),
504 - apiKey: auth.apiKey,
505 - headers: auth.
headers ,
507 499 maxTokens: outputBudget,
509 501 cacheRetention:
"none" ,
593 585 signal : AbortSignal,
594 586 log : CanonicalRecordLog,
595 587 ):
Promise < Usage
> {
596 - const auth
= await ctx.modelRegistry.
getApiKeyAndHeaders (model);
598 - throw new
Error (auth.error ||
"Decay model authentication failed" );
599 - const provider
= ctx.modelRegistry.
getProvider (model.provider);
600 - if (!provider) throw new
Error (
`Decay provider not found: ${model.provider}` );
601 - const stream
= provider.
streamSimple (
588 + const stream
= ctx.modelRegistry.
streamSimple (
603 590 normalizeContext (
604 591 buildClassifierContext (chunks, priorAtoms, manualInstructions),
607 - apiKey: auth.apiKey,
608 - headers: auth.
headers ,
611 595 cacheRetention:
"none" ,
612 596 sessionId:
uuidv7 (),
extensions/ultra/__tests__/action-summarizer.test.ts Modified 4 4 import { describe, expect, it, vi }
from "vitest" ;
5 5 import { __test, createActionSummarizer }
from "../action-summarizer.ts" ;
8 8 const model
= { provider:
"fast" , id:
"tiny" };
9 9 const find
= vi.
fn (()
=> model);
10 - const getApiKeyAndHeaders
= vi.
fn (
async ()
=> ({
13 - headers: {
"x-test" :
"yes" },
15 10 const complete
= vi.
fn (
async ()
=> response (
"Routing through registry" ));
19 - getApiKeyAndHeaders,
21 - ctx: { modelRegistry: { find, getApiKeyAndHeaders, complete } },
15 + ctx: { modelRegistry: { find, complete } },
67 61 it (
"uses the configured cheap model with bounded low-latency options" ,
async ()
=> {
68 - const { ctx, model, find, getApiKeyAndHeaders }
= context ();
62 + const { ctx, model, find }
= context ();
69 63 const scheduler
= fakeScheduler ();
70 64 const generate
= vi.
fn (
async ()
=> response (
'"Reading Ultra settings."\n' ));
71 65 const summarize
= createActionSummarizer (ctx
as never ,
"fast/tiny" , {
82 76 await expect (pending).resolves.
toBe (
"Reading Ultra settings" );
83 77 expect (find).
toHaveBeenCalledWith (
"fast" ,
"tiny" );
84 - expect (getApiKeyAndHeaders).
toHaveBeenCalledTimes (
1 );
85 78 expect (generate).
toHaveBeenCalledTimes (
1 );
86 79 expect (generate.mock.calls[
0 ][
0 ]).
toBe (model);
87 80 expect (generate.mock.calls[
0 ][
1 ].systemPrompt).
toContain (
91 84 generate.mock.calls[
0 ][
1 ].messages[
0 ].
content [
0 ].
text .
length ,
92 85 ).
toBeLessThan (
1700 );
93 86 expect (generate.mock.calls[
0 ][
2 ]).
toMatchObject ({
95 - headers: {
"x-test" :
"yes" },
98 89 cacheRetention:
"none" ,
229 220 expect (generate).not.
toHaveBeenCalled ();
232 - it (
"fails silently when auth is unavailable" ,
async ()
=> {
223 + it (
"fails silently when generation rejects" ,
async ()
=> {
233 224 const { ctx }
= context ();
234 - ctx.modelRegistry.getApiKeyAndHeaders
= vi.
fn (
async ()
=> ({ ok:
false }));
225 + ctx.modelRegistry.
complete = vi.
fn (
async ()
=> {
226 + throw new Error (
"Provider is not configured" );
235 228 const scheduler
= fakeScheduler ();
236 229 const summarize
= createActionSummarizer (ctx
as never ,
"fast/tiny" , {
237 - generate: vi.
fn ()
as never ,
238 230 scheduler: scheduler.scheduler,
240 232 const pending
= summarize ?.(
input (
"a" ));
extensions/ultra/action-summarizer.ts Modified 5 - }
from "@earendil-works/pi-ai" ;
1 + import type { Model, UserMessage }
from "@earendil-works/pi-ai" ;
6 2 import type { ExtensionContext }
from "@earendil-works/pi-coding-agent" ;
8 4 export interface ActionSummaryInput {
28 24 clearTimeout (handle: unknown):
void ;
31 - type ActionSummarizerAuth = {
34 - headers
?: ProviderHeaders ;
38 28 input
: ActionSummaryInput ;
39 29 resolve (summary
: string | undefined )
: void ;
135 125 private disposed
= false ;
138 - private readonly auth: ()
=> Promise < ActionSummarizerAuth
| undefined > ,
128 + private readonly model: Model
< any
> ,
139 129 private readonly generate: GenerateActionSummary,
140 130 private readonly scheduler: TimerScheduler,
226 216 private async
run (job: Job):
Promise < string
| undefined > {
227 - const resolved
= await this.
auth ();
228 - if (!resolved || job.cancelled) return undefined;
217 + if (job.cancelled) return undefined;
229 218 const controller
= new AbortController ();
230 219 job.controller
= controller;
231 220 if (job.input.signal?.aborted) controller.
abort ();
236 225 const response
= await this.
generate (
238 227 { systemPrompt: SYSTEM_PROMPT, messages: [
prompt (job.
input )] },
240 - apiKey: resolved.apiKey,
241 - headers: resolved.
headers ,
242 229 maxTokens: MAX_TOKENS,
244 231 cacheRetention:
"none" ,
268 255 if (
! parsed)
return undefined ;
269 256 const model
= ctx.modelRegistry.
find (parsed.provider, parsed.
id );
270 257 if (
! model)
return undefined ;
272 - let auth
: Promise <
ActionSummarizerAuth | undefined >
| undefined ;
273 - const resolveAuth = ()
=> {
274 - auth
??= Promise .
resolve (ctx.modelRegistry.
getApiKeyAndHeaders (model)).
then (
279 - apiKey: result.apiKey,
280 - headers: result.
headers ,
287 259 options.generate
?? 288 260 ((model, context, options)
=> 289 261 ctx.modelRegistry.
complete (model, context, options));
290 262 const engine
= new ActionSummarizerEngine (
293 265 options.scheduler
?? defaultScheduler,