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.
147 lines • 8.66 kB
TypeScript
/**
* `functions` namespace — serverless function lifecycle.
*
* `deploy` routes through the unified apply engine (`/apply/v1`, a
* `functions.patch.set` release) — the legacy `POST /projects/v1/admin/:id/
* functions` route was removed gateway-side. invoke/logs/list/delete/update
* cover `/projects/v1/admin/:id/functions*` and `/functions/v1/:name`, plus
* the client-side `logsByRequestId` fan-out (no project-wide logs route
* exists) and the `origin` tagging/filter on every log entry, plus
* the opt-in runtime rebuild/rebuildAll against `/projects/v1/:id/functions*`
* (wallet-authed, capability `function-runtime-rebuild`).
*/
import type { Client } from "../kernel.js";
import type { DeleteFunctionResult, FunctionDeployOptions, FunctionDeployResult, FunctionInvokeOptions, FunctionInvokeResult, FunctionListResult, FunctionLogOrigin, FunctionLogsByRequestIdOptions, FunctionLogsByRequestIdResult, FunctionLogsOptions, FunctionLogsResult, FunctionRunCreateOptions, FunctionRunHandle, FunctionRunListOptions, FunctionRunListResult, FunctionRunLogsOptions, FunctionRunRedriveOptions, FunctionRunRetryPolicy, FunctionRunWaitOptions, FunctionRebuildBatchResult, FunctionRebuildResult, FunctionUpdateOptions, FunctionUpdateResult } from "./functions.types.js";
/**
* Classify one CloudWatch log line as a Lambda runtime control line
* (`platform`) or function output (`app`). Pure; safe on any string.
*/
export declare function classifyFunctionLogLine(message: string): FunctionLogOrigin;
export declare class FunctionRunTerminalError extends Error {
readonly run: FunctionRunHandle;
readonly code?: string;
constructor(run: FunctionRunHandle);
}
export declare class Functions {
private readonly client;
readonly runs: FunctionRuns;
readonly retry: {
standard: (opts?: {
maxAttempts?: number;
minDelaySeconds?: number;
maxDelaySeconds?: number;
}) => FunctionRunRetryPolicy;
};
constructor(client: Client);
/**
* Deploy a serverless function through the unified apply engine. Builds a
* one-function `functions.patch.set` {@link ReleaseSpec} (additive — never
* touches coexisting functions) and runs it through the same `/apply/v1`
* state machine as `r.project(id).apply`. The legacy
* `POST /projects/v1/admin/:id/functions` route was removed gateway-side.
*
* Deployed functions can `import { db, adminDb, email, ai } from
* "@run402/functions"` — the in-function helper library is auto-bundled by
* the platform.
*
* `opts.deps` lists additional npm packages to install and bundle (capability
* `apply-v1-function-deps`). Bare names resolve to the latest published
* version at deploy time; pinned or range specs (`"lodash@4.17.21"`,
* `"date-fns@^3.0.0"`) are honored verbatim. `@run402/functions` and native
* binary modules are rejected by the gateway. The actually-installed concrete
* versions land on the function record (read via {@link Functions.list}) —
* the apply/deploy result does not carry them, so
* {@link FunctionDeployResult.deps_resolved} and `runtime_version` are `null`.
*
* Authorizes through the standard apply credential — a SIWX wallet, or the
* write-approval `project.deploy` gate for a wallet-less person — NOT the
* project service key. Non-fatal deploy issues (bundle size warnings, esbuild
* advisories) surface in {@link FunctionDeployResult.warnings}.
*
* @throws {ProjectNotFound} when the project is absent from the local keystore.
* @throws {Run402DeployError} on any apply state-machine failure.
* @throws {PaymentRequired} when the project lease has expired.
*/
deploy(projectId: string, opts: FunctionDeployOptions): Promise<FunctionDeployResult>;
/**
* Invoke a deployed function via HTTP. Uses the project's service key as
* the API key. The returned `body` is parsed JSON when the response was
* JSON, otherwise the raw text.
*/
invoke(projectId: string, name: string, opts?: FunctionInvokeOptions): Promise<FunctionInvokeResult>;
/**
* Get recent logs for a function. Default tail 50; `since` accepts an ISO
* 8601 timestamp or epoch milliseconds for incremental polling. Pass
* `requestId` to retrieve logs correlated to a routed request failure.
*/
logs(projectId: string, name: string, opts?: FunctionLogsOptions): Promise<FunctionLogsResult>;
/**
* Project-wide request-id search. The gateway has no cross-function logs
* route, so this fans `logs()` out across every function in the project
* (or just `functionName`) and merges the matches oldest-first. A function
* whose read failed lands in `errors[]` by name; the others still answer.
* Accepts `req_…` (the `x-run402-request-id` response header), `fnrun_…`,
* and `fnatt_…` ids.
*/
logsByRequestId(projectId: string, requestId: string, opts?: FunctionLogsByRequestIdOptions): Promise<FunctionLogsByRequestIdResult>;
/** List deployed functions for a project. */
list(projectId: string): Promise<FunctionListResult>;
/** Delete a deployed function. */
delete(projectId: string, name: string): Promise<DeleteFunctionResult>;
/**
* Update a function's schedule / timeout / memory without re-deploying.
* Pass `schedule: null` to remove an existing schedule; `undefined`
* leaves it unchanged.
*/
update(projectId: string, name: string, opts: FunctionUpdateOptions): Promise<FunctionUpdateResult>;
/**
* Refresh a single runtime-stale function onto the gateway's current entry
* wrapper + bundled runtime, WITHOUT changing its source (capability
* `function-runtime-rebuild`, gateway v1.69+).
*
* A gateway-side fix to the function entry wrapper (e.g. the SSR `auth.*`
* fixes) only reaches a deployed function when it is re-bundled — a plain
* redeploy with unchanged source skips it (apply's release diff keys on the
* source `code_hash`, not the wrapper). This re-bundles from the function's
* STORED source with dependencies pinned to the recorded `deps_resolved`
* exact versions, so the only change is the wrapper/runtime: `code_hash` is
* unchanged and no new release is created. Strictly opt-in — the platform
* never auto-rebuilds.
*
* Wallet-authed (the caller must own the project) and allowed during billing
* grace (`past_due` / `frozen` / `dormant`); it adds no capacity. No service
* key is required — the gateway derives it from the wallet-owned project.
*
* @throws {ApiError} HTTP 404 when the function does not exist; HTTP 403 when
* the wallet does not own the project; HTTP 409 with code
* `CANNOT_REBUILD_UNLOCKED_DEPS` for functions deployed before dependency
* locking (`deps_resolved` is NULL) — redeploy from source to refresh.
*/
rebuild(projectId: string, name: string): Promise<FunctionRebuildResult>;
/**
* Refresh ALL of a project's functions onto the gateway's current entry
* wrapper + bundled runtime (capability `function-runtime-rebuild`). Same
* deterministic, deps-locked, release-agnostic semantics as
* {@link Functions.rebuild} applied per function.
*
* Per-function failures are isolated and never abort the batch: a function
* that fails to rebuild (bundle/upload error, or the
* `CANNOT_REBUILD_UNLOCKED_DEPS` refusal) keeps its previously-deployed
* artifact and is reported as `{ rebuilt: false, error, code? }` in
* `results`. Wallet-authed (project ownership) and allowed during billing
* grace.
*/
rebuildAll(projectId: string): Promise<FunctionRebuildBatchResult>;
}
export declare class FunctionRuns {
private readonly client;
constructor(client: Client);
create(projectId: string, functionName: string, opts: FunctionRunCreateOptions): Promise<FunctionRunHandle>;
list(projectId: string, functionName: string, opts?: FunctionRunListOptions): Promise<FunctionRunListResult>;
get(projectId: string, runId: string): Promise<FunctionRunHandle>;
logs(projectId: string, runId: string, opts?: FunctionRunLogsOptions): Promise<FunctionLogsResult>;
cancel(projectId: string, runId: string): Promise<FunctionRunHandle>;
redrive(projectId: string, runId: string, opts?: FunctionRunRedriveOptions): Promise<FunctionRunHandle>;
wait(projectId: string, runId: string, opts?: FunctionRunWaitOptions): Promise<FunctionRunHandle>;
}
//# sourceMappingURL=functions.d.ts.map