@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
47 lines • 3.16 kB
TypeScript
import type { AgentMessage } from "@earendil-works/pi-agent-core";
import { type AssistantMessage, type Message, type Model, type ProviderHeaders } from "@earendil-works/pi-ai";
import type { buildPrompt } from "./prompts.ts";
import type { SpeculativeCompactionContext, SpeculativeCompactionSnapshot } from "./speculative.ts";
type CompactionProgressCallback = (delta: string) => void;
/**
* Whether `summarizationReasoningOptions` pins anything for this model. The
* empty-stop retry drops that pin, so it is only worth a request when there is
* one to drop; otherwise the retry would replay the identical prompt.
*/
export declare function hasSummarizationReasoningOverride(model: Model<any>): boolean;
/**
* Estimated input of the request {@link generateSummaryMessage} sends for `messages`, which sizes its
* wall-clock budget. The request carries the agent's system prompt, its tool schemas and the transcript as
* native messages with their replayed reasoning, so the transcript's own chars/4 estimate sees only part of
* it: on large OpenAI sessions it measured a third of the provider-reported context, which kept the
* size-adaptive budget on its 120s floor. The last provider-reported usage inside the transcript already
* counts that whole prefix (system prompt, tools and opaque reasoning included); what follows it is
* estimated, plus the schemas of tools a later tool result activated (`addedToolNames`), which that usage
* never billed. `sourceMessages` is the transcript before pruning, input bounding or an overflow shrink cut
* it: the usage measured that transcript, so the estimated size of what was cut before it is subtracted.
* Without usage, or when the usage predates the branch's latest compaction or context edit (a message kept
* through an earlier compaction), the request is estimated whole, system prompt and tools included.
*/
export declare function estimateSummaryRequestTokens(snapshot: Pick<SpeculativeCompactionSnapshot, "systemPrompt" | "tools" | "branchEntries">, messages: AgentMessage[], prompt: ReturnType<typeof buildPrompt>, sourceMessages?: readonly AgentMessage[]): number;
export declare function getSummaryText(message: Message): string;
export declare function isAssistantMessage(message: Message): message is AssistantMessage;
export declare function generateSummaryMessage(options: {
context: SpeculativeCompactionContext;
forbidToolCalls?: boolean;
/** Skip the model's reasoning override (effort pin, or `thinkingEnabled: false` on Anthropic); retry path for relays that return empty text when it is pinned. */
omitReasoningOptions?: boolean;
/** Resolved per-attempt duration budget; falls back to the size-adaptive default. */
maxDurationMs?: number;
messages: AgentMessage[];
onProgress?: CompactionProgressCallback;
prompt: ReturnType<typeof buildPrompt>;
signal?: AbortSignal;
snapshot: SpeculativeCompactionSnapshot;
auth: {
apiKey?: string;
headers?: ProviderHeaders;
extraBody?: Record<string, unknown>;
};
}): Promise<Message | undefined>;
export {};
//# sourceMappingURL=speculative-summary.d.ts.map