UNPKG

@code-yeongyu/senpi

Version:

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

65 lines • 3.59 kB
import type { AgentMessage } from "@earendil-works/pi-agent-core"; import { type Api, type AssistantMessage, type Model, type ProviderDiagnostic, type ProviderDiagnosticCategory } from "@earendil-works/pi-ai"; import { type TransportTrustFailure } from "../engine-trust/transport-failure.ts"; import { type FallbackModelLookup } from "./retry-fallback/chains.ts"; /** * `request_refused`: an `auth` failure on a credential that served a response moments before, so the * provider refused this request rather than the key (senpi#2491). * `model_unavailable`: an `unknown` failure the provider answered with HTTP 404, the status a model * endpoint returns for a model id this account cannot use (senpi#4578). */ export type ProviderFailureCategory = ProviderDiagnosticCategory | "request_refused" | "model_unavailable"; /** * Structured failure of a turn that ended with a provider error, attached to `agent_end`. * Built only from the adapter-minted `ProviderDiagnostic`, the runtime's typed served-credential * mark, and the auth-miss sentinel auth resolution throws before any request (`PROVIDER_NOT_CONFIGURED_PREFIX`); * provider message text is never read. * Every category, `unknown` included, carries a reason and an action. */ export interface ProviderFailure { readonly category: ProviderFailureCategory; /** Provider id of the failing request. */ readonly provider: string; /** Model id of the failing request (senpi#4328). */ readonly model?: string; /** * The provider and model the user selected, present (both) only when the failing request ran on * another one: a fallback rung, or the route a virtual model picked (senpi#4328). */ readonly selectedProvider?: string; readonly selectedModel?: string; readonly httpStatus?: number; readonly code?: string; /** When the limit lifts (epoch ms), for a `quota` or `rate_limit` failure whose provider named it. */ readonly resetsAt?: number; readonly reason: string; readonly action: string; /** * Present when the request failed TLS chain verification while the engine runs on a fallback trust * generation: the fallback reason and its repair action id (senpi#5244). */ readonly trust?: TransportTrustFailure; } /** An `auth` failure on a credential that served a response moments before: the request was refused, not the key. */ export declare function isRequestLevelRefusal(message: AssistantMessage): boolean; /** The provider and model a turn was meant to run on. */ export interface SelectedModel { readonly provider: string; readonly model: string; } /** * The model the user selected for this turn: the original of an active fallback chain, else the * session model (which stays the virtual model when one routes the request). */ export declare function selectedModelOf(originalSelector: string | undefined, lookup: FallbackModelLookup, sessionModel: Model<Api> | undefined): SelectedModel | undefined; export declare function describeProviderFailure(diagnostic: ProviderDiagnostic | undefined, provider: string, options?: { readonly model?: string; readonly requestRefused?: boolean; }): ProviderFailure; /** * The failure of a turn whose last assistant message ended with `stopReason: "error"`. * Absent on success and on abort. */ export declare function providerFailureOf(messages: readonly AgentMessage[], selected?: SelectedModel): ProviderFailure | undefined; export declare function formatProviderFailure(failure: ProviderFailure): string; //# sourceMappingURL=provider-failure.d.ts.map