UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

50 lines • 2.19 kB
// Request-local metadata: Symbols survive hook-to-hook object spreads, but are // omitted by JSON.stringify and never reach the provider or stored transcript. export const SERVER_SEARCH_FALLBACK = Symbol.for("senpi.serverSearchFallback"); export const SERVER_SEARCH_DISABLED = Symbol.for("senpi.serverSearchDisabled"); const failedModels = new WeakMap(); function modelKey(model) { return JSON.stringify([model.api, model.provider, model.id, model.baseUrl]); } export function resetServerSearchFailures(session) { failedModels.delete(session); } export function rememberServerSearchFailure(session, model) { let failures = failedModels.get(session); if (!failures) { failures = new Set(); failedModels.set(session, failures); } failures.add(modelKey(model)); } export function hasServerSearchFailed(session, model) { return model !== undefined && failedModels.get(session)?.has(modelKey(model)) === true; } export function markServerSearchFallback(payload) { return payload !== null && typeof payload === "object" ? { ...payload, [SERVER_SEARCH_FALLBACK]: true } : payload; } export function disableServerSearch(payload) { return payload !== null && typeof payload === "object" ? { ...payload, [SERVER_SEARCH_DISABLED]: true } : payload; } export function withoutServerSearch(onPayload, cacheRetention = "none") { // Cache-friendly summaries must keep the main-turn hook and tool prefix verbatim. if (cacheRetention !== "none") return onPayload; return async (payload, model, request) => { const disabled = disableServerSearch(payload); return (await onPayload?.(disabled, model, request)) ?? disabled; }; } export function isServerSearchDisabled(payload) { return (payload !== null && typeof payload === "object" && SERVER_SEARCH_DISABLED in payload && payload[SERVER_SEARCH_DISABLED] === true); } export function isServerSearchFallback(payload) { return (payload !== null && typeof payload === "object" && SERVER_SEARCH_FALLBACK in payload && payload[SERVER_SEARCH_FALLBACK] === true); } //# sourceMappingURL=server-search-fallback.js.map