@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
75 lines • 3.65 kB
TypeScript
/**
* Bounded `get_entries` answers (senpi#3534). One response line rides the connection's event queue,
* which fails the whole connection closed past 64 MiB (`socket-event-fanout.ts`), so a history read
* is cut into pages a client walks with `since`, and an unpaged read that would not fit is refused
* with `response_too_large` instead of taking the connection (and every session on it) down.
*/
/** The largest answer one unpaged read may produce: well under the 64 MiB connection queue bound. */
export declare const RPC_RESPONSE_BYTE_BUDGET: number;
export declare const DEFAULT_ENTRY_PAGE_BYTES: number;
/** How long a page walk may pause before the full-history view it holds is let go. */
export declare const ENTRY_WALK_HOLD_MS = 30000;
/** The byte budget one answer may use; tests lower it to reach the refusal without a 48 MiB history. */
export declare function currentResponseByteBudget(): number;
export declare function setResponseByteBudgetForTesting(bytes: number): () => void;
export interface EntryPageRequest {
readonly limit?: number;
/** The newest `tail` entries of the range, read backwards (senpi#4267); never combined with `limit`. */
readonly tail?: number;
readonly maxBytes?: number;
}
export interface EntryPage<T> {
readonly entries: T[];
readonly hasMore: boolean;
readonly nextSince?: string;
/** Serialized size of the page's first entry (0 for an empty page): one entry past the budget cannot be sent. */
readonly firstEntryBytes: number;
}
export type EntryPageBounds = {
readonly ok: true;
readonly paged: boolean;
readonly limit?: number;
readonly tail?: number;
readonly maxBytes: number;
} | {
readonly ok: false;
readonly message: string;
};
export declare function entryPageBounds(request: EntryPageRequest): EntryPageBounds;
/**
* Takes entries in order until the count or the serialized byte size would pass the bounds. The first
* entry is always taken, so a page always moves the cursor forward even when one entry alone is larger
* than `maxBytes`. Only the page is projected, so a large history never builds one giant answer.
*/
export declare function pageEntries<S extends {
readonly id: string;
}, T>(entries: readonly S[], project: (entry: S) => T, bounds: {
readonly limit?: number;
readonly maxBytes: number;
}): EntryPage<T>;
export interface TailEntryPage<T> {
/** In append order: the oldest of the page first. */
readonly entries: T[];
readonly hasMore: boolean;
/** The oldest entry id the page returned, while older entries remain: pass it as the next `before`. */
readonly nextBefore?: string;
/** Serialized size of the page's newest entry (0 for an empty page). */
readonly firstEntryBytes: number;
}
/**
* The newest entries first, until the count or the byte size would pass the bounds, answered in append order. The
* newest entry is always taken, so a backward walk always moves even when one entry alone is larger than `maxBytes`.
*/
export declare function pageEntriesFromEnd<S extends {
readonly id: string;
}, T>(entries: readonly S[], project: (entry: S) => T, bounds: {
readonly tail?: number;
readonly maxBytes: number;
}): TailEntryPage<T>;
/**
* Keeps a page walk's full-history view for the next page, and lets it go after `ENTRY_WALK_HOLD_MS` without
* one: a client that stops mid-walk must not pin the whole history of a session that is already idle.
*/
export declare function holdEntryWalk(owner: object, release: () => void): void;
export declare function endEntryWalk(owner: object): void;
//# sourceMappingURL=get-entries-page.d.ts.map