-
Notifications
You must be signed in to change notification settings - Fork 11
fix(pi-coding-agent): support streamFn -> streamFunction rename #2392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "braintrust": patch | ||
| --- | ||
|
|
||
| fix(pi-coding-agent): Support `agent.streamFunction` rename in `@earendil-works/pi-coding-agent` >= 0.81 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,6 +68,7 @@ type PiToolSpanState = { | |
|
|
||
| type PiAgentPatchState = { | ||
| originalStreamFn: PiStreamFn; | ||
| streamFnKey: "streamFn" | "streamFunction"; | ||
| wrappedStreamFn: PiStreamFn; | ||
| }; | ||
|
|
||
|
|
@@ -228,11 +229,23 @@ function extractSession( | |
| function isPiAgent(value: unknown): value is PiAgent { | ||
| return ( | ||
| isObject(value) && | ||
| typeof value.streamFn === "function" && | ||
| (typeof value.streamFn === "function" || | ||
| typeof value.streamFunction === "function") && | ||
| typeof value.subscribe === "function" | ||
| ); | ||
| } | ||
|
|
||
| // @earendil-works/pi-coding-agent renamed `agent.streamFn` to | ||
| // `agent.streamFunction` starting in v0.81.0. Resolve whichever property | ||
| // actually exists so both the pre- and post-rename shapes are patchable. | ||
|
Comment on lines
+239
to
+240
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For the reported 0.84.2 auto-hook case, this resolver is never reached: AGENTS.md reference: AGENTS.md:L28-L30 Useful? React with 👍 / 👎. |
||
| function resolveStreamFnKey( | ||
| agent: PiAgent, | ||
| ): "streamFn" | "streamFunction" | undefined { | ||
| if (typeof agent.streamFn === "function") return "streamFn"; | ||
| if (typeof agent.streamFunction === "function") return "streamFunction"; | ||
| return undefined; | ||
| } | ||
|
|
||
| function promptContextStore(): IsoAsyncLocalStorage<PiPromptState | undefined> { | ||
| piPromptContextStore ??= iso.newAsyncLocalStorage< | ||
| PiPromptState | undefined | ||
|
|
@@ -245,17 +258,28 @@ function currentPiPromptState(): PiPromptState | undefined { | |
| } | ||
|
|
||
| function installPiAgentInstrumentation(agent: PiAgent): void { | ||
| const streamFnKey = resolveStreamFnKey(agent); | ||
| if (!streamFnKey) { | ||
| // isPiAgent() already validated that one of these exists; this should be | ||
| // unreachable, but stay defensive rather than patching the wrong property. | ||
| throw new Error( | ||
| "Pi Coding Agent: unable to resolve streamFn/streamFunction property", | ||
| ); | ||
| } | ||
|
|
||
| const existing = piAgentPatchStates.get(agent); | ||
| if (!existing || agent.streamFn !== existing.wrappedStreamFn) { | ||
| if (!existing || agent[streamFnKey] !== existing.wrappedStreamFn) { | ||
| const originalStreamFn = agent[streamFnKey]; | ||
| const patchState = { | ||
| originalStreamFn: agent.streamFn, | ||
| wrappedStreamFn: agent.streamFn, | ||
| originalStreamFn, | ||
| streamFnKey, | ||
| wrappedStreamFn: originalStreamFn, | ||
| } satisfies PiAgentPatchState; | ||
| patchState.wrappedStreamFn = makeInstrumentedStreamFn( | ||
| agent, | ||
| patchState.originalStreamFn, | ||
| ); | ||
| agent.streamFn = patchState.wrappedStreamFn; | ||
| agent[streamFnKey] = patchState.wrappedStreamFn; | ||
| piAgentPatchStates.set(agent, patchState); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This synthetic-agent unit test is the only new verification, while the Pi e2e scenario remains pinned to 0.79.1 and 0.79.10, so neither the real 0.81+ package shape nor its wrapped and auto-hook paths are exercised. Add pinned and separately named latest dependency variants for the renamed API and include both in the CI e2e summary as required for newly supported instrumentation versions.
AGENTS.md reference: AGENTS.md:L60-L60
Useful? React with 👍 / 👎.