/** * Delegation context normalization — provider-agnostic replay identity fix. * * pi-ai transformMessages compares assistant message provider/api/model to the * target model. Foreign identities (virtual smart-router tags or any prior * provider such as OpenAI/Anthropic/GLM) break isSameModel and strip replay * state (thoughtSignature, thinkingSignature, etc.). */ import type { Api, AssistantMessage, Context, Message, Model } from '@earendil-works/pi-ai/compat'; import type { ExecutionModel } from './execution-ledger.js'; export declare const VIRTUAL_ROUTER_PROVIDER: "smart-router"; export declare const VIRTUAL_ROUTER_MODEL_ID: "auto"; /** * Google Gemini bypass sentinel for tool-call replay when no signature was captured. * * Semantic value (Google API / pi#1829): `skip_thought_signature_validator`. * Wire format (@earendil-works/pi-ai@0.80.3 google-shared): TYPE_BYTES — base64 * only. Plain string fails `isValidThoughtSignature`, so pi-ai strips it before * the request leaves the client. We store/send the base64 encoding of the literal * sentinel string so both Google validation and pi-ai serialization accept it. * * @see https://ai.google.dev/gemini-api/docs/thought-signatures */ export declare const GEMINI_SKIP_THOUGHT_SIGNATURE_SENTINEL: "c2tpcF90aG91Z2h0X3NpZ25hdHVyZV92YWxpZGF0b3I="; export declare function isVirtualRouterIdentity(provider: string, modelId: string): boolean; export declare function isGoogleDelegationTarget(model: Model): boolean; export declare function isGoogleOriginAssistantMessage(message: AssistantMessage): boolean; /** * Env gate for the Cursor lifecycle strip (SP-300, #180). Default on; * `SMART_ROUTER_STRIP_CURSOR_LIFECYCLE=0` disables the sanitizer. */ export declare const STRIP_CURSOR_LIFECYCLE_ENV: "SMART_ROUTER_STRIP_CURSOR_LIFECYCLE"; /** Whether the delegation target is a Cursor model (cursor/auto, composer-*). */ export declare function isCursorDelegationTarget(model: Model): boolean; /** * Whether an assistant message was produced by the Cursor provider (e.g. * `cursor/auto`). Cursor-origin thinking blocks carry pi-cursor-sdk lifecycle * progress lines (`Cursor shell: …`, `Cursor MCP: …`) rather than model * reasoning — replaying them cross-provider teaches the target to imitate * shell commands as prose (issue #180). */ export declare function isCursorOriginAssistantMessage(message: AssistantMessage): boolean; export declare function hasReplaySensitiveState(messages: readonly Message[]): boolean; export interface NormalizeDelegationContextOptions { readonly virtualProvider?: typeof VIRTUAL_ROUTER_PROVIDER; readonly sessionExecution?: ExecutionModel | null; } /** * Rewrite assistant messages tagged with the virtual router to the executing * model identity pi-ai expects for same-model replay. */ export declare function normalizeDelegationContext(context: Context, targetModel: Model, options?: NormalizeDelegationContextOptions): Context; /** * Repair Gemini tool-call replay for Google delegation targets. * * Call after {@link normalizeDelegationContext}. Aligns assistant identity to * the delegation target and injects the thought-signature sentinel on every * unsigned tool call, regardless of which provider produced the prior turn * (Google, OpenAI, Anthropic, GLM, …). Captured signatures are preserved. * * Cross-provider repair (SP-231, #158): pi-ai strips replay state from any * assistant message whose identity fails isSameModel, so a Gemini target * would receive unsigned tool calls from non-Google turns and the Google API * would reject the replay with a thought_signature error. */ export declare function repairGeminiReplayContext(context: Context, targetModel: Model, sessionExecution?: ExecutionModel | null): Context; export interface StripCursorLifecycleOptions { /** Env override for tests; defaults to `process.env`. */ readonly env?: Record; } export interface CursorLifecycleStripResult { readonly context: Context; /** Thinking blocks removed from Cursor-origin assistant messages. */ readonly strippedThinkingBlocks: number; /** Total characters of removed thinking text (observability for #180). */ readonly strippedThinkingChars: number; } /** * SP-300 (#180): drop Cursor lifecycle thinking from Cursor-origin assistant * messages before delegating to a non-Cursor target. * * The third-party pi-cursor-sdk provider emits tool progress as thinking lines * (`Cursor shell: …`). pi-ai's transformMessages converts foreign thinking * blocks to plain text when the provider/model differs, so a Cursor-origin * history handed to GLM/Gemini replays those progress lines as assistant * prose — the target then imitates shell commands as text instead of emitting * real toolCalls (2026-10-01 glm-5.3-flash runaway). * * Scope guardrails: * - Cursor targets are returned unchanged (Cursor→Cursor replay is native). * - Non-Cursor thinking (Gemini, Anthropic, …) is never touched. * - Text, toolCall, and other blocks are preserved; messages are never * dropped — a message left with an empty content array is kept so * tool-call/result pairing stays intact. * - Disabled via `SMART_ROUTER_STRIP_CURSOR_LIFECYCLE=0`. * * Call after {@link normalizeDelegationContext} so virtual-tagged messages * already resolved to a Cursor session execution are caught as Cursor-origin. */ export declare function stripCursorLifecycleThinking(context: Context, targetModel: Model, options?: StripCursorLifecycleOptions): CursorLifecycleStripResult; //# sourceMappingURL=delegation-context.d.ts.map