jeopi-agent-core 16.2.13 → 16.2.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,77 +0,0 @@
1
- import type { ImageContent, Message, MessageAttribution, ProviderPayload, TextContent } from "jeopi-ai";
2
- import type { AgentMessage } from "../types";
3
- export interface CustomMessage<T = unknown> {
4
- role: "custom";
5
- customType: string;
6
- content: string | (TextContent | ImageContent)[];
7
- display: boolean;
8
- details?: T;
9
- /** Who initiated this message for billing/attribution semantics. */
10
- attribution?: MessageAttribution;
11
- timestamp: number;
12
- }
13
- /** Legacy hook message type (pre-extensions). Kept for session migration. */
14
- export interface HookMessage<T = unknown> {
15
- role: "hookMessage";
16
- customType: string;
17
- content: string | (TextContent | ImageContent)[];
18
- display: boolean;
19
- details?: T;
20
- /** Who initiated this message for billing/attribution semantics. */
21
- attribution?: MessageAttribution;
22
- timestamp: number;
23
- }
24
- export interface BranchSummaryMessage {
25
- role: "branchSummary";
26
- summary: string;
27
- fromId: string;
28
- timestamp: number;
29
- }
30
- export interface CompactionSummaryMessage {
31
- role: "compactionSummary";
32
- summary: string;
33
- shortSummary?: string;
34
- tokensBefore: number;
35
- providerPayload?: ProviderPayload;
36
- /** Runtime-only ordered archive blocks for snapcompact: old text region,
37
- * imaged middle, then new text region. When present, `summary` is already
38
- * the final lead-in text (no legacy wrapper applied). */
39
- blocks?: (TextContent | ImageContent)[];
40
- /** Snapcompact image blocks, kept for display counts / legacy consumers. */
41
- images?: ImageContent[];
42
- timestamp: number;
43
- }
44
- export type CoreCompactionMessage = CustomMessage | HookMessage | BranchSummaryMessage | CompactionSummaryMessage;
45
- declare module "../types" {
46
- interface CustomAgentMessages {
47
- custom: CustomMessage;
48
- hookMessage: HookMessage;
49
- branchSummary: BranchSummaryMessage;
50
- compactionSummary: CompactionSummaryMessage;
51
- }
52
- }
53
- export type ConvertToLlm = (messages: AgentMessage[]) => Message[];
54
- export declare function renderBranchSummaryContext(summary: string): string;
55
- export declare function renderCompactionSummaryContext(summary: string): string;
56
- export declare function createBranchSummaryMessage(summary: string, fromId: string, timestamp: string): BranchSummaryMessage;
57
- export declare function createCompactionSummaryMessage(summary: string, tokensBefore: number, timestamp: string, shortSummary?: string, providerPayload?: ProviderPayload, images?: ImageContent[], blocks?: (TextContent | ImageContent)[]): CompactionSummaryMessage;
58
- export declare function createCustomMessage(customType: string, content: string | (TextContent | ImageContent)[], display: boolean, details: unknown | undefined, timestamp: string, attribution?: MessageAttribution): CustomMessage;
59
- /**
60
- * Transform a single core-domain agent message to its LLM form; `undefined`
61
- * drops it from the provider request.
62
- *
63
- * Single source of truth for the core roles (user/developer/assistant/
64
- * toolResult) and the compaction messages owned by this package. Embedders
65
- * with their own app messages (e.g. the coding agent) handle their custom
66
- * roles and delegate every core role here — duplicating these cases is how
67
- * snapcompact frames once silently fell off the provider request.
68
- */
69
- export declare function convertMessageToLlm(message: AgentMessage): Message | undefined;
70
- /**
71
- * Default compaction-domain transformer.
72
- *
73
- * Embedders with their own app messages should pass a richer transformer through
74
- * `SummaryOptions.convertToLlm`; this default intentionally preserves only the
75
- * core LLM roles and the compaction messages owned by this package.
76
- */
77
- export declare function defaultConvertToLlm(messages: AgentMessage[]): Message[];
@@ -1,77 +0,0 @@
1
- /**
2
- * Remote compaction utilities.
3
- *
4
- * Provider-side conversation summarization endpoints. Three flavors:
5
- *
6
- * - **OpenAI remote compaction V2** (Responses streaming): appends a
7
- * `compaction_trigger` input item to the normal stream and stores the returned
8
- * `compaction` item with retained real user messages in `preserveData`.
9
- * - **OpenAI remote compaction V1** (`/responses/compact`): preserves encrypted
10
- * reasoning across compactions by submitting the full responses-API native
11
- * history and storing the returned `compaction` / `compaction_summary`
12
- * item in `preserveData` so future turns can replay the encrypted state.
13
- * - **Generic remote compaction**: a thin POST helper for self-hosted
14
- * summarization endpoints that accept `{ systemPrompt, prompt }` and reply
15
- * with `{ summary, shortSummary? }`.
16
- */
17
- import type { FetchImpl, Message, Model } from "jeopi-ai/types";
18
- export * from "./compaction-v2-streaming";
19
- export declare const OPENAI_REMOTE_COMPACTION_PRESERVE_KEY = "openaiRemoteCompaction";
20
- /**
21
- * Hard ceiling on remote compaction HTTP requests. Unlike every provider
22
- * stream (guarded by first-event/idle watchdogs in pi-ai), these are raw
23
- * fetches awaiting one non-streamed JSON body — a connection silently dropped
24
- * by a middlebox would otherwise hang the whole compaction pipeline forever
25
- * (frozen "Auto context-full maintenance…" spinner, manual /compact queueing
26
- * behind it). On timeout the caller falls back to local summarization.
27
- */
28
- export declare const REMOTE_COMPACTION_TIMEOUT_MS = 180000;
29
- export type OpenAiRemoteCompactionItem = {
30
- type: "compaction" | "compaction_summary";
31
- encrypted_content?: string;
32
- summary?: string;
33
- };
34
- export interface OpenAiRemoteCompactionPreserveData {
35
- provider?: string;
36
- replacementHistory: Array<Record<string, unknown>>;
37
- compactionItem: OpenAiRemoteCompactionItem;
38
- }
39
- export interface OpenAiRemoteCompactionRequest {
40
- model: string;
41
- input: Array<Record<string, unknown>>;
42
- instructions: string;
43
- }
44
- export interface OpenAiRemoteCompactionResponse extends OpenAiRemoteCompactionPreserveData {
45
- }
46
- export interface RemoteCompactionRequest {
47
- systemPrompt: string;
48
- prompt: string;
49
- }
50
- export interface RemoteCompactionResponse {
51
- summary: string;
52
- shortSummary?: string;
53
- }
54
- export declare function shouldUseOpenAiRemoteCompaction(model: Model): boolean;
55
- export declare function getPreservedOpenAiRemoteCompactionData(preserveData: Record<string, unknown> | undefined): OpenAiRemoteCompactionPreserveData | undefined;
56
- export declare function withOpenAiRemoteCompactionPreserveData(preserveData: Record<string, unknown> | undefined, remoteCompaction: OpenAiRemoteCompactionPreserveData | undefined): Record<string, unknown> | undefined;
57
- /**
58
- * Build the OpenAI Responses-API native history array from LLM messages.
59
- *
60
- * Caller is responsible for converting any custom message types to
61
- * `Message[]` first (e.g. via the agent's `convertToLlm`); this function
62
- * operates purely on the LLM-domain shape.
63
- *
64
- * @param messages - LLM messages to encode.
65
- * @param model - Target model (used for provider gating + tool-call id rules).
66
- * @param previousReplacementHistory - History from a prior compaction whose
67
- * encrypted reasoning we want to preserve.
68
- */
69
- export declare function buildOpenAiNativeHistory(messages: Message[], model: Model, previousReplacementHistory?: Array<Record<string, unknown>>): Array<Record<string, unknown>>;
70
- export declare function requestOpenAiRemoteCompaction(model: Model, apiKey: string, compactInput: Array<Record<string, unknown>>, instructions: string, signal?: AbortSignal, opts?: {
71
- fetch?: FetchImpl;
72
- timeoutMs?: number;
73
- }): Promise<OpenAiRemoteCompactionResponse>;
74
- export declare function requestRemoteCompaction(endpoint: string, request: RemoteCompactionRequest, signal?: AbortSignal, opts?: {
75
- fetch?: FetchImpl;
76
- timeoutMs?: number;
77
- }): Promise<RemoteCompactionResponse>;
@@ -1,105 +0,0 @@
1
- /**
2
- * Tool output pruning utilities for compaction.
3
- */
4
- import type { SessionEntry } from "./entries";
5
- import { type ProtectedToolMatcher } from "./tool-protection";
6
- export interface PruneConfig {
7
- /** Keep the most recent tool output tokens intact. */
8
- protectTokens: number;
9
- /** Only prune if total savings meets this threshold. */
10
- minimumSavings: number;
11
- /** Tool-result protection matchers. String entries protect every result from that tool; predicates may inspect the paired tool call. */
12
- protectedTools: ProtectedToolMatcher[];
13
- /**
14
- * Optional supersede key function (see {@link SupersedePruneConfig.supersedeKey}).
15
- * When provided, superseded tool results are pruned first — even inside the
16
- * `protectTokens` window — before age-based victims. Absent, behavior is
17
- * unchanged.
18
- */
19
- supersedeKey?: SupersedeKeyFn;
20
- /** Useless-flagged results bypass the protect window (see {@link USELESS_NOTICE}). Default true. */
21
- pruneUseless?: boolean;
22
- /**
23
- * Compaction boundary: the `firstKeptEntryId` of the latest compaction on
24
- * the branch. Entries at indices BEFORE this id are summarized away and never
25
- * sent to the model, so mutating them only churns persisted history without
26
- * shrinking the prompt — they are skipped. Undefined = no compaction (the
27
- * whole branch is sent).
28
- */
29
- keepBoundaryId?: string;
30
- /**
31
- * Prompt-cache guard. When set, a tool result whose all-message suffix
32
- * (tokens of every message after it) EXCEEDS this is part of the warm,
33
- * already-sent cache prefix: mutating it forces the provider to re-write the
34
- * whole suffix (cacheWrite premium). Such results — including superseded and
35
- * useless ones, which otherwise bypass {@link protectTokens} — are left for
36
- * compaction/shake (which rebuild the cache anyway) to reclaim. Undefined =
37
- * no cache guard (legacy: superseded/useless prune at any depth).
38
- */
39
- cacheWarmSuffixTokens?: number;
40
- }
41
- export declare const DEFAULT_PRUNE_CONFIG: PruneConfig;
42
- export interface PruneResult {
43
- prunedCount: number;
44
- tokensSaved: number;
45
- }
46
- /** Exact placeholder written over a superseded tool result. */
47
- export declare const SUPERSEDED_NOTICE = "[Superseded by a newer read of this file]";
48
- /** Exact placeholder written over an elided useless tool result. */
49
- export declare const USELESS_NOTICE = "[Uneventful result elided]";
50
- /**
51
- * Maps a tool call to a supersede key. Results sharing a key form a group in
52
- * which every result except the newest is a supersede candidate. A key `K`
53
- * additionally supersedes keys with prefix `K + "\u0000"` (selector-free read
54
- * supersedes selector-carrying reads of the same base path). Return
55
- * `undefined` to exempt a call from supersede grouping.
56
- */
57
- export type SupersedeKeyFn = (toolName: string, args: Record<string, unknown>) => string | undefined;
58
- export interface SupersedePruneConfig {
59
- /** Supersede key function; results sharing a key supersede older ones. */
60
- supersedeKey?: SupersedeKeyFn;
61
- /** Also prune results flagged useless by their tool. Default false. */
62
- pruneUseless?: boolean;
63
- /** Prune a candidate now when all messages after it total at most this many estimated tokens. Default 8 000. */
64
- suffixTokenLimit?: number;
65
- /**
66
- * Prune all candidates when the last message is at least this old: the
67
- * provider prompt cache is then cold, so re-writing it is free. MUST exceed
68
- * the cache retention (Anthropic "long" = 1h) or a still-warm prefix is busted
69
- * by the flush. Default 30 min — callers on long retention override it.
70
- */
71
- idleFlushMs?: number;
72
- /** Clock override for tests. */
73
- now?: number;
74
- /**
75
- * Compaction boundary (`firstKeptEntryId` of the latest compaction). Entries
76
- * before it are summarized away and never sent, so they are skipped in every
77
- * path — including the idle flush — to avoid pointless history churn.
78
- * Undefined = no compaction (the whole branch is sent).
79
- */
80
- keepBoundaryId?: string;
81
- /** Tool-result protection matchers (same contract as {@link PruneConfig.protectedTools}). */
82
- protectedTools: ProtectedToolMatcher[];
83
- }
84
- /**
85
- * Prune superseded tool results (e.g. stale `read` outputs replaced by a newer
86
- * read of the same file) and, when `pruneUseless` is set, results their tool
87
- * flagged contextually useless. Cheap, incremental, and prompt-cache-aware: a
88
- * candidate is pruned now only when the suffix after it is small (tail case —
89
- * the read→edit→read loop) or when the context has been idle long enough that
90
- * the provider cache is cold anyway (then all still-sent candidates flush).
91
- * Never mutates entries before `keepBoundaryId` (summarized away — not sent).
92
- */
93
- export declare function pruneSupersededToolResults(entries: SessionEntry[], config: SupersedePruneConfig): PruneResult;
94
- export declare function pruneToolOutputs(entries: SessionEntry[], config?: PruneConfig): PruneResult;
95
- /**
96
- * Supersede key for the `read` tool: the file path with the trailing line/raw
97
- * selector stripped (the read tool's own splitter grammar via
98
- * {@link splitReadSelector}, e.g. `src/foo.ts:50-200`, `:2-4:raw`).
99
- * Internal/URL-scheme paths (`skill://…`, `https://…`) are exempt.
100
- * Selector-free reads key on the bare path; selector-carrying reads key on
101
- * `path + "\u0000" + selector`, so two reads collide only when the newer is
102
- * selector-free or the selectors are identical (the pass's prefix rule lets a
103
- * bare-path read supersede selector-carrying reads of the same file).
104
- */
105
- export declare function readToolSupersedeKey(toolName: string, args: Record<string, unknown>): string | undefined;
@@ -1,92 +0,0 @@
1
- /**
2
- * Context-reducing surgical compaction ("shake").
3
- *
4
- * `shake` drops heavy content out of the live context mechanically: whole
5
- * tool-call results and large fenced/XML blocks are replaced with short
6
- * placeholders. This module is the pure layer — region detection and in-place
7
- * mutation only. Artifact offload, persistence, and provider-session teardown
8
- * are orchestrated by the caller (`AgentSession.shake`).
9
- *
10
- * Layering mirrors `pruning.ts`: no I/O here.
11
- */
12
- import type { CustomMessageEntry, SessionEntry, SessionMessageEntry } from "./entries";
13
- import { type ProtectedToolMatcher } from "./tool-protection";
14
- export interface ShakeConfig {
15
- /** Keep the most recent context tokens (across all entries) intact. */
16
- protectTokens: number;
17
- /** Only shake when total estimated savings meets this threshold. */
18
- minSavings: number;
19
- /** Tool-result protection matchers. String entries protect every result from that tool; predicates may inspect the paired tool call. */
20
- protectedTools: ProtectedToolMatcher[];
21
- /** Minimum token size for a fenced/XML block to be eligible. */
22
- fenceMinTokens: number;
23
- /**
24
- * Compaction boundary (`firstKeptEntryId` of the latest compaction). Entries
25
- * before it are summarized away and never sent, so they are skipped — shaking
26
- * them only churns persisted history. Undefined = no compaction (whole branch
27
- * is sent). Note: shake still elides the warm cached prefix at/after the
28
- * boundary — that is its job as a compaction-class reducer.
29
- */
30
- keepBoundaryId?: string;
31
- }
32
- /** Auto-shake config: protects the live tail, conservative thresholds. */
33
- export declare const DEFAULT_SHAKE_CONFIG: ShakeConfig;
34
- /** Manual `/shake`: aggressive — drops every eligible region across history. */
35
- export declare const AGGRESSIVE_SHAKE_CONFIG: ShakeConfig;
36
- /** A located eligible region. */
37
- export interface ToolResultShakeRegion {
38
- kind: "toolResult";
39
- entry: SessionMessageEntry;
40
- tokens: number;
41
- originalText: string;
42
- /** Human label for the offload doc (tool name). */
43
- label: string;
44
- }
45
- export interface BlockShakeRegion {
46
- kind: "block";
47
- entry: SessionMessageEntry | CustomMessageEntry;
48
- /** Index into the content array, or -1 for string-form content. */
49
- blockIndex: number;
50
- /** Character offsets into the target text (start inclusive, end exclusive). */
51
- start: number;
52
- end: number;
53
- tokens: number;
54
- originalText: string;
55
- /** Human label for the offload doc (role / customType). */
56
- label: string;
57
- }
58
- export type ShakeRegion = ToolResultShakeRegion | BlockShakeRegion;
59
- /**
60
- * Pure detection: locate every eligible shake region on a branch.
61
- *
62
- * Walks the protect-recent window (most recent `protectTokens` of context is
63
- * kept intact), collects whole tool-result messages (honoring `protectedTools`
64
- * and skipping already-pruned results) and large fenced/XML blocks inside
65
- * user/developer/assistant/custom messages. Tool results flagged contextually
66
- * useless by their tool bypass the protect window — there is nothing recent
67
- * worth keeping in them. Returns regions in document order.
68
- *
69
- * `toolCall` blocks are never touched (tool-call/result pairing is preserved)
70
- * and regions never span a message boundary. When the combined estimated
71
- * savings is below `minSavings`, returns `[]` (no-op).
72
- */
73
- export declare function collectShakeRegions(entries: SessionEntry[], config: ShakeConfig): ShakeRegion[];
74
- /**
75
- * Pure mutation: replace a single region's content in place.
76
- *
77
- * Tool-result: replaces the message content with the placeholder text and
78
- * stamps `prunedAt`. Block: splices `replacement` over `[start, end)` of the
79
- * target text block. When several block regions share one text block they MUST
80
- * be applied highest-start-first so earlier offsets stay valid — use
81
- * {@link applyShakeRegions}, which orders them correctly.
82
- */
83
- export declare function applyShakeRegion(region: ShakeRegion, replacement: string): void;
84
- /**
85
- * Apply many regions at once. Block regions are applied highest-start-first so
86
- * that splicing one region never shifts the offsets of another in the same text
87
- * block; tool-result regions are independent.
88
- */
89
- export declare function applyShakeRegions(items: Array<{
90
- region: ShakeRegion;
91
- replacement: string;
92
- }>): void;
@@ -1,17 +0,0 @@
1
- import type { ToolResultMessage } from "jeopi-ai";
2
- import type { AgentToolCall } from "../types";
3
- import type { SessionEntry } from "./entries";
4
- export interface ProtectedToolContext {
5
- readonly toolResult: ToolResultMessage;
6
- readonly toolCall: AgentToolCall | undefined;
7
- }
8
- export type ProtectedToolMatcher = string | ((context: ProtectedToolContext) => boolean);
9
- export declare function collectToolCallsById(entries: readonly SessionEntry[]): Map<string, AgentToolCall>;
10
- /**
11
- * Extract the `path` argument from a paired `read` tool call, when the result
12
- * is a `read` result carrying a string path. Returns `undefined` otherwise.
13
- * Shared primitive for read-targeted protection matchers (skills, plans, …).
14
- */
15
- export declare function getReadToolPath({ toolResult, toolCall }: ProtectedToolContext): string | undefined;
16
- export declare function isSkillReadToolResult(context: ProtectedToolContext): boolean;
17
- export declare function isProtectedToolResult(toolResult: ToolResultMessage, toolCall: AgentToolCall | undefined, matchers: readonly ProtectedToolMatcher[]): boolean;
@@ -1,58 +0,0 @@
1
- /**
2
- * Shared utilities for compaction and branch summarization.
3
- */
4
- import type { Message } from "jeopi-ai";
5
- import { type Dialect } from "jeopi-ai/dialect";
6
- import type { AgentMessage } from "../types";
7
- export interface FileOperations {
8
- read: Set<string>;
9
- written: Set<string>;
10
- edited: Set<string>;
11
- }
12
- export declare function createFileOps(): FileOperations;
13
- /**
14
- * Split a read-tool path into its base path and trailing selector, mirroring the
15
- * read tool's own splitter. Single source of the grammar in this package: the
16
- * file-operations list strips selectors via {@link stripReadSelector}, and the
17
- * supersede-prune pass keys on both parts via `readToolSupersedeKey`.
18
- */
19
- export declare function splitReadSelector(path: string): {
20
- path: string;
21
- sel?: string;
22
- };
23
- /**
24
- * Strip a trailing read-tool selector (`:50-200`, `:raw`, `:1-50:raw`, `:conflicts`, …)
25
- * so the same file read with different line ranges dedupes to one `<files>` entry
26
- * and matches its write/edit path when computing Read/Write/RW markers.
27
- */
28
- export declare function stripReadSelector(path: string): string;
29
- /**
30
- * Whether `path` references a `scheme://` URL (internal URI or web URL) rather
31
- * than a filesystem path that belongs in the compaction `<files>` summary.
32
- */
33
- export declare function isUrlSchemePath(path: string): boolean;
34
- /**
35
- * Extract file operations from tool calls in an assistant message.
36
- */
37
- export declare function extractFileOpsFromMessage(message: AgentMessage, fileOps: FileOperations): void;
38
- /**
39
- * Compute final file lists from file operations.
40
- * Returns readFiles (files only read, not modified) and modifiedFiles.
41
- */
42
- export declare function computeFileLists(fileOps: FileOperations): {
43
- readFiles: string[];
44
- modifiedFiles: string[];
45
- };
46
- export declare function formatFileOperations(readFiles: string[], modifiedFiles: string[], readSet?: ReadonlySet<string>): string;
47
- export declare function upsertFileOperations(summary: string, readFiles: string[], modifiedFiles: string[], readSet?: ReadonlySet<string>): string;
48
- /**
49
- * Truncate tool results to the same representation used in summarization prompts.
50
- */
51
- export declare function truncateToolResultForSummary(text: string): string;
52
- /**
53
- * Serialize LLM messages to text for summarization.
54
- * This prevents the model from treating it as a conversation to continue.
55
- * Call convertToLlm() first to handle custom message types.
56
- */
57
- export declare function serializeConversation(messages: Message[], dialect?: Dialect): string;
58
- export declare const SUMMARIZATION_SYSTEM_PROMPT: string;
@@ -1 +0,0 @@
1
- export * from "./compaction/index";
@@ -1,12 +0,0 @@
1
- export * from "./agent";
2
- export * from "./agent-loop";
3
- export * from "./append-only-context";
4
- export * from "./compaction";
5
- export * from "./proxy";
6
- export * from "./replay-policy";
7
- export * from "./run-collector";
8
- export * from "./telemetry";
9
- export * from "./thinking";
10
- export * from "./tokenizer";
11
- export * from "./types";
12
- export * from "./utils/yield";
@@ -1,85 +0,0 @@
1
- /**
2
- * Proxy stream function for apps that route LLM calls through a server.
3
- * The server manages auth and proxies requests to LLM providers.
4
- */
5
- import { type AssistantMessage, type AssistantMessageEvent, type Context, EventStream, type FetchImpl, type Model, type SimpleStreamOptions, type StopReason } from "jeopi-ai";
6
- export declare class ProxyMessageEventStream extends EventStream<AssistantMessageEvent, AssistantMessage> {
7
- constructor();
8
- }
9
- /**
10
- * Proxy event types - server sends these with partial field stripped to reduce bandwidth.
11
- */
12
- export type ProxyAssistantMessageEvent = {
13
- type: "start";
14
- } | {
15
- type: "text_start";
16
- contentIndex: number;
17
- } | {
18
- type: "text_delta";
19
- contentIndex: number;
20
- delta: string;
21
- } | {
22
- type: "text_end";
23
- contentIndex: number;
24
- contentSignature?: string;
25
- } | {
26
- type: "thinking_start";
27
- contentIndex: number;
28
- } | {
29
- type: "thinking_delta";
30
- contentIndex: number;
31
- delta: string;
32
- } | {
33
- type: "thinking_end";
34
- contentIndex: number;
35
- contentSignature?: string;
36
- } | {
37
- type: "toolcall_start";
38
- contentIndex: number;
39
- id: string;
40
- toolName: string;
41
- } | {
42
- type: "toolcall_delta";
43
- contentIndex: number;
44
- delta: string;
45
- } | {
46
- type: "toolcall_end";
47
- contentIndex: number;
48
- } | {
49
- type: "done";
50
- reason: Extract<StopReason, "stop" | "length" | "toolUse">;
51
- usage: AssistantMessage["usage"];
52
- } | {
53
- type: "error";
54
- reason: Extract<StopReason, "aborted" | "error">;
55
- errorMessage?: string;
56
- usage: AssistantMessage["usage"];
57
- };
58
- export interface ProxyStreamOptions extends SimpleStreamOptions {
59
- /** Auth token for the proxy server */
60
- authToken: string;
61
- /** Proxy server URL (e.g., "https://genai.example.com") */
62
- proxyUrl: string;
63
- /** Optional fetch implementation; defaults to global fetch. */
64
- fetch?: FetchImpl;
65
- }
66
- /**
67
- * Stream function that proxies through a server instead of calling LLM providers directly.
68
- * The server strips the partial field from delta events to reduce bandwidth.
69
- * We reconstruct the partial message client-side.
70
- *
71
- * Use this as the `streamFn` option when creating an Agent that needs to go through a proxy.
72
- *
73
- * @example
74
- * ```typescript
75
- * const agent = new Agent({
76
- * streamFn: (model, context, options) =>
77
- * streamProxy(model, context, {
78
- * ...options,
79
- * authToken: await getAuthToken(),
80
- * proxyUrl: "https://genai.example.com",
81
- * }),
82
- * });
83
- * ```
84
- */
85
- export declare function streamProxy(model: Model, context: Context, options: ProxyStreamOptions): ProxyMessageEventStream;
@@ -1,5 +0,0 @@
1
- import type { AssistantMessage, Message } from "jeopi-ai";
2
- /** Detects API-level provider refusals that are terminal errors, not dialogue to replay. */
3
- export declare function isProviderRefusalMessage(message: AssistantMessage): boolean;
4
- /** Removes API-level provider refusals from live provider replay while preserving other messages. */
5
- export declare function filterProviderReplayMessages(messages: readonly Message[]): Message[];