UNPKG

run402-mcp

Version:

MCP server for Run402 — full-stack backend infrastructure for AI agents: Postgres, auth, storage, serverless functions and atomic deploys. Paid with x402/MPP. Includes $0.03 image generation.

286 lines • 13.3 kB
/** * Request/response types for the `errors` namespace — the release-error-rollup * query surface (`GET /projects/v1/:project_id/errors` and * `GET /projects/v1/:project_id/errors/:fingerprint_id`) and the status * actions (`POST …/errors/:fingerprint_id/resolve|ignore|reopen`). * * The platform keeps a durable, grouped error memory: every 5xx at the * gateway's invoke choke points is fingerprinted (normalization-first, so the * identity is deploy-stable) and collapsed into one hot row per distinct * failure. The read is **verdict-first**: the page leads with a computed * promote-vs-revert verdict for the release you name, then the grouped rows. * * The verdict math is the GATEWAY'S — never recomputed client-side. The SDK * never fingerprints, never re-baselines, never re-counts `new_fingerprints`. * It passes the envelope through untouched (index signatures keep unknown * future fields), and `watch` polls this surface and reads * `verdict.new_fingerprints` as the truth. * * Baseline semantics: `baseline_release_id` is the previous ACTIVE release by * ACTIVATION HISTORY (`releases.activated_at`, re-stamped on every activation), * NOT lineage — so after A→B→(rollback)→A→C, C's baseline is A and fingerprints * first seen under B are not misattributed to C. Cursors are OPAQUE keyset * tokens: store `next_cursor` and pass it back as `{ cursor }`, never parse it. */ /** The choke point that produced an error identity. */ export type ErrorKind = "uncaught" | "boot_crash" | "invoke_failed" | "handled_5xx"; /** * How much signal a fingerprint's identity carries. * - `frame_names` — full fidelity: ≥1 stable stack frame name survived. * - `message_only` — normalized message template, no stable frames. * - `coarse` — no error detail: the function answered 500 or above and * reported no error (it neither threw nor called `errors.report` from * `@run402/functions`), or its bundle predates the error side-channel. Which one * is the row's `coarse_reason`. A coarse row is keyed by its `method` and * `route_pattern` when a route is known. */ export type FingerprintQuality = "frame_names" | "message_only" | "coarse"; /** * A group's status. `open` when first seen; `resolved` and `ignored` are set * by a caller with deploy authority ({@link Errors.resolve}, * {@link Errors.ignore}, {@link Errors.reopen}). The platform changes it only * by reopening a `resolved` group the next time its error is seen; it never * resolves a group from quiet time. An `ignored` group keeps counting. */ export type ErrorGroupStatus = "open" | "resolved" | "ignored"; /** * Why a `coarse` row has no error detail, computed by the gateway when the row * is read: `no_error_thrown` (the function's bundle carries the side-channel, * so it answered the status itself) or `function_predates_side_channel` * (redeploying the function upgrades its future occurrences). Null on other rows. */ export type CoarseReason = "no_error_thrown" | "function_predates_side_channel"; /** * A platform-synthesized drill-down attached to a fingerprint. Today the only * type is `fetch_logs`, carrying the exact `run402 logs <fn> --request-id * <sample_id>` command for a sample occurrence. Rendering an action must never * execute it. Unknown future fields pass through via the index signature. */ export interface ErrorNextAction { type: string; command?: string; why?: string; [key: string]: unknown; } /** * One occurrence pointer. The `id` is a fetchable request/run id * (`req_…` / `fnrun_…` / `fnatt_…`) accepted by the function-diagnostics logs * surface; `release_id` is the release the occurrence was attributed to (null * when the platform had no release context at ingest). */ export interface ErrorSample { id: string; at: string; release_id: string | null; /** The route the request matched (`/api/threads/[id]`, never the path), when one is known. */ route_pattern?: string; /** * True when the occurrence was test traffic: a request made with a Run402 * test session, or one the function marked with `errors.markTest()`. */ test: boolean; [key: string]: unknown; } /** * The sample set for a fingerprint. `first` is the pinned first occurrence * (diagnostic gold — never overwritten); `recent` is a newest-first ring * capped at 10. The list view carries this trimmed set; {@link Errors.get} * returns the full ring. */ export interface ErrorSamples { first: ErrorSample; recent: ErrorSample[]; [key: string]: unknown; } /** One grouped error identity — a hot row that collapses an error storm. */ export interface ErrorFingerprint { /** Stable identity hash (`fp_…`). Also the `fingerprint` filter/param value. */ fingerprint_id: string; /** The function the error surfaced in. */ function: string; kind: ErrorKind; fingerprint_quality: FingerprintQuality; /** Error class/type name (a JS builtin kept verbatim, else `CustomError`, or the Lambda errorType). */ error_name: string; /** Normalized, low-cardinality message template (high-cardinality tokens scrubbed). */ message_template: string; /** Up to 3 stable stack frame NAMES — never line/column, wrapper, or minified frames. */ stable_frames: string[]; /** Total occurrences collapsed into this row. */ count: number; first_seen: string; last_seen: string; first_seen_release_id: string | null; last_seen_release_id: string | null; status: ErrorGroupStatus; /** When the status last changed (a caller's action or a reopening); null while it never has. */ status_changed_at: string | null; /** The project's live release when the group was last resolved. */ resolved_in_release_id: string | null; /** When the group last reopened because its error was seen after a resolve. */ reopened_at: string | null; /** The release the reopening occurrence was attributed to. */ reopened_in_release_id: string | null; reopen_count: number; /** A coarse row's method (part of its identity); null on other rows, whose samples carry the route. */ method: string | null; /** A coarse row's route pattern (part of its identity); null when no route is known. */ route_pattern: string | null; coarse_reason: CoarseReason | null; /** * True while every occurrence since the group last opened (its first * sighting, or its latest reopening) was test traffic. Such a group is * announced on the feed as `error_fingerprints_observed_in_tests`, never to * the owner, until an ordinary request meets it. */ test_only: boolean; samples: ErrorSamples; next_actions: ErrorNextAction[]; [key: string]: unknown; } /** * The detail row from {@link Errors.get}: the same shape as a list row with the * FULL sample ring, a per-sample `fetch_logs` next action, and — when the same * fingerprint hash surfaced under more than one function — the sibling function * names in `also_seen_in_functions`. */ export interface ErrorFingerprintDetail extends ErrorFingerprint { also_seen_in_functions?: string[]; } /** * The response of {@link Errors.resolve} / {@link Errors.ignore} / * {@link Errors.reopen}: the fingerprint detail after the write, plus * `changed`, the number of rows whose status changed (0 when the group was * already in the requested status; the same error in two functions is two rows). */ export interface ErrorStatusChange extends ErrorFingerprintDetail { changed: number; } /** The window the verdict + listing were computed over (resolved gateway-side). */ export interface ErrorsWindow { since: string; until: string; [key: string]: unknown; } /** Fingerprint-quality coverage across the project's functions. */ export interface ErrorsCoverage { /** Functions emitting the full-fidelity error side-channel. */ full_fidelity_functions: number; /** Functions still fingerprinting coarsely (redeploy to upgrade). */ coarse_functions: number; [key: string]: unknown; } /** Row-cap disclosure so at-cap eviction is never silent. */ export interface ErrorsRowCap { limit: number; at_cap: boolean; [key: string]: unknown; } /** * The computed promote-vs-revert verdict — the head of every errors page. * * With a `new_in` release, `new_fingerprints` counts error IDENTITIES first * seen UNDER that release (the promote-gate signal); without one it counts * identities first seen within the window. `invocations_in_window` pairs the * counts with real traffic so "0 errors over 0 traffic" is distinguishable * from a healthy release. Every number here is the gateway's — the SDK never * recomputes them. */ export interface ErrorsVerdict { window: ErrorsWindow; /** The `new_in` release (the resolved id when `new_in="active"`); null when no `new_in` was given. */ compared_release_id: string | null; /** Previous ACTIVE release by activation history (rollback-safe); null when none / no `new_in`. */ baseline_release_id: string | null; new_fingerprints: number; recurring_fingerprints: number; /** With `new_in`, groups reopened under that release; otherwise groups reopened inside the window. */ reopened_fingerprints: number; /** Groups seen inside the window, per status (whatever the `status` filter). */ by_status: Record<ErrorGroupStatus, number>; invocations_in_window: number; coverage: ErrorsCoverage; row_cap: ErrorsRowCap; [key: string]: unknown; } /** One page of grouped errors, verdict-first. */ export interface ErrorsPage { verdict: ErrorsVerdict; errors: ErrorFingerprint[]; has_more: boolean; /** Opaque keyset cursor for the next page. Present only when `has_more`. */ next_cursor?: string; [key: string]: unknown; } /** Options for {@link Errors.list}. All filters map 1:1 to wire query params except `newIn` → `new_in`. */ export interface ListErrorsOptions { /** ISO-8601 window start. Default (gateway-side): `until` − 24h. */ since?: string; /** ISO-8601 window end. Default (gateway-side): now. */ until?: string; /** Restrict to one function by name. */ function?: string; /** Restrict to one choke-point class. */ kind?: ErrorKind; /** Restrict to one fingerprint identity (`fp_…`). */ fingerprint?: string; /** Restrict to one status. Every status is listed when absent. */ status?: ErrorGroupStatus; /** * A release id, or the literal `"active"` (resolves to the live release * gateway-side). Selects rows first seen UNDER that release, or reopened * under it, and drives the verdict's `new_fingerprints`, * `reopened_fingerprints` and baseline. Wire param: `new_in`. */ newIn?: string; /** Page size (server default 50, max 200). */ limit?: number; /** Opaque keyset cursor from a prior page's `next_cursor`. */ cursor?: string; } /** * Options for {@link Errors.watch} — the promote-gate poll loop. `newIn` is * REQUIRED (the release under scrutiny). The loop polls immediately, then every * `intervalMs`, and does one final poll when the window elapses. */ export interface WatchErrorsOptions { /** The release to watch — a release id, or `"active"`. Required. */ newIn: string; /** Total watch window in ms before returning the last verdict. Default 600_000 (10 min). */ durationMs?: number; /** Poll cadence in ms. NOT clamped by the SDK (callers/tests may go fast). Default 15_000. */ intervalMs?: number; /** Abort the watch cleanly. If ≥1 poll succeeded, returns the result-so-far with `aborted: true`. */ signal?: AbortSignal; /** Called after each SUCCESSFUL poll with the page and progress metadata. Throwing from it never breaks the loop. */ onPoll?: (page: ErrorsPage, meta: { poll: number; elapsedMs: number; }) => void; /** Stop the moment a poll reports `verdict.new_fingerprints > 0` or `verdict.reopened_fingerprints > 0`. Default true. */ failFast?: boolean; } /** * Result of {@link Errors.watch}. `clean` is `verdict.new_fingerprints === 0` * and `verdict.reopened_fingerprints === 0` on the last observed page — the * gateway's numbers, never a client recount. `new_errors` and * `reopened_errors` split the final/triggering page's `errors[]` by the * compared release: first seen under it, or reopened under it. */ export interface WatchErrorsResult { /** True iff the last verdict reported no new and no reopened groups. The promote-gate pass/fail. */ clean: boolean; /** The last verdict observed (final poll, or the fail-fast triggering poll). */ verdict: ErrorsVerdict; /** The groups first seen under the watched release. */ new_errors: ErrorFingerprint[]; /** The resolved groups the watched release brought back. */ reopened_errors: ErrorFingerprint[]; /** Number of successful polls performed. */ polls: number; /** Wall-clock ms the watch ran. */ elapsed_ms: number; /** Present and true only when the watch ended because its `signal` aborted. */ aborted?: boolean; } //# sourceMappingURL=errors.types.d.ts.map