chore: pi family 0.85.1 -> 0.87.1 (finishTurn, transcript contexts, typebox 1.3.27)

Mechanical fallout only; semantic deltas flagged in the wave report:
- shouldStopAfterTurn -> finishTurn ({action:'end'} wrap; loop order verified
  equivalent for Wave C stranding)
- transcript rework: seeded leading SystemMessage filtered at both
  state.messages read seams (ui-stream settleWith, pi-run slice); prompt
  and tool declarations now ride the transcript
- streamOnce sites normalizeContext() (Context -> TranscriptContext)
- AgentToolResult details / ToolCall.arguments JsonValue narrowing (casts)
- AUTH_PROVIDER_KEYS regenerated (meta added); glm-5.3-flash price pin
  follows the 0.87.1 catalog (0.15/0.5/0.05)
- vanish probe: 0/12 vs 2/6 baseline; live smoke green on PORT=3004
This commit is contained in:
amosblomqvist
2026-09-26 21:45:51 +03:00
parent 9853075331
commit 876185eb6e
12 changed files with 329 additions and 850 deletions
+5 -1
View File
@@ -1,4 +1,5 @@
import type { AssistantMessage, Message, ToolResultMessage, Usage, Tool } from "@earendil-works/pi-ai";
import { normalizeContext } from "@earendil-works/pi-ai";
import { Type } from "typebox";
import { piEngineFor, type PiEngine, type ThinkingLevel } from "../models.ts";
import type { PdfResult, PdfToolInput } from "../../core/contracts.ts";
@@ -392,7 +393,10 @@ async function streamOnce(
reasoning: ThinkingLevel | undefined,
abortSignal?: AbortSignal,
): Promise<AssistantMessage> {
const stream = engine.streamFn(engine.model, { systemPrompt, messages, tools }, {
// 0.87.1: provider-facing contexts are TranscriptContexts — the prompt
// and tool declarations fold into a leading system message.
// normalizeContext is the library's only Context→TranscriptContext entry.
const stream = engine.streamFn(engine.model, normalizeContext({ systemPrompt, messages, tools }), {
reasoning: reasoning && reasoning !== "off" ? reasoning : undefined,
apiKey: process.env.OPENROUTER_API_KEY || undefined,
signal: abortSignal,
+12 -3
View File
@@ -65,9 +65,13 @@ export async function runSubagent(tools: AgentTool<any, any>[], opts: SubagentRu
messages: opts.messages ?? [],
},
streamFn: engine.streamFn,
shouldStopAfterTurn: (context) => {
// 0.87.1: shouldStopAfterTurn → finishTurn (same call point; "end"
// exits before the steering poll, exactly the old boolean-true).
finishTurn: (turn) => {
turns++;
return turns >= opts.maxTurns || opts.shouldStop?.(context.message, context.toolResults) === true;
return turns >= opts.maxTurns || opts.shouldStop?.(turn.message, turn.toolResults) === true
? { action: "end" }
: undefined;
},
});
@@ -119,7 +123,12 @@ export async function runSubagent(tools: AgentTool<any, any>[], opts: SubagentRu
}
if (errorMessage !== undefined) throw new Error(errorMessage);
const newMessages = agent.state.messages.slice(before);
// 0.87.1: drop the seeded leading SystemMessage (transcript rework —
// see ui-stream's settleWith) before slicing past the input count, or
// the seed displaces the slice and the last INPUT message leaks in.
const newMessages = agent.state.messages
.filter((m) => (m as { role?: string }).role !== "system")
.slice(before);
const assistants = newMessages.filter((m) => (m as { role?: string }).role === "assistant") as AssistantMessage[];
const last = assistants[assistants.length - 1];
const text = last
+5 -1
View File
@@ -1,4 +1,5 @@
import type { AssistantMessage, Message, Tool, ToolResultMessage, Usage } from "@earendil-works/pi-ai";
import { normalizeContext } from "@earendil-works/pi-ai";
import { Type } from "typebox";
import { piEngineFor, type PiEngine, type ThinkingLevel } from "../models.ts";
import type { VisualResult } from "../../core/contracts.ts";
@@ -307,7 +308,10 @@ async function streamOnce(
reasoning: ThinkingLevel | undefined,
abortSignal?: AbortSignal,
): Promise<AssistantMessage> {
const stream = engine.streamFn(engine.model, { systemPrompt, messages, tools }, {
// 0.87.1: provider-facing contexts are TranscriptContexts — the prompt
// and tool declarations fold into a leading system message.
// normalizeContext is the library's only Context→TranscriptContext entry.
const stream = engine.streamFn(engine.model, normalizeContext({ systemPrompt, messages, tools }), {
reasoning: reasoning && reasoning !== "off" ? reasoning : undefined,
apiKey: process.env.OPENROUTER_API_KEY || undefined,
signal: abortSignal,
+8 -2
View File
@@ -122,7 +122,8 @@ export interface AgentBuildOptions {
*
* Question results also carry terminate: true (tool-execute's
* questionResult), so single-question batches stop natively at the pi
* loop's own batch check; this shouldStopAfterTurn hook is the
* loop's own batch check; this finishTurn hook (0.87.1 rename of
* shouldStopAfterTurn) is the
* belt-and-suspenders HALF for the mixed batch (a question + other calls
* in one message) that terminate-only semantics would let run on — the
* learner cannot answer while a turn is in flight (per-chat 409), so a
@@ -164,7 +165,12 @@ function baseAgentOptions(kind: AgentKind, opts: AgentBuildOptions, tools: Agent
messages: opts.messages ?? [],
},
streamFn: engine.streamFn,
shouldStopAfterTurn: stopper,
// 0.87.1: shouldStopAfterTurn → finishTurn. Same call point (after
// tool results attach, before turn_end) and `{ action: "end" }` still
// exits BEFORE the steering poll — the parked-marker stranding our
// Wave C registerLiveAgent-before-runPiTurn design depends on.
// undefined preserves normal scheduling (the old boolean false).
finishTurn: (turn) => (stopper(turn) ? { action: "end" } : undefined),
// Wave C (2026-09-26, owner correction same day): markers handed to a
// live run drain from pi's STEERING queue — the lesson loop is one
// continuous teach→quiz→teach run, so delivery must inject at turn