import { PlanFacetInput } from "@nullplatform/tracing"; /** * A component is what a plugin publishes: an entity of some kind, the API's * own resource type, named uniquely in the package, with the body that kind's * API takes exactly as its author wrote it. The core knows no kind: a kind's * sugar builds its components with `component`. */ /** Where a component lives on the API, when the convention does not hold, and who owns it. */ interface ComponentOptions { /** The component this one belongs to, created under it. */ parent?: Component; /** The collection it is created in. */ path?: string; /** Where it is found before it is created. */ list?: string; /** The field that identifies it in that listing. */ identity?: string; /** `platform`: the platform creates it; publish looks it up and pins it, never writes it. */ owner?: "platform"; } /** What publish registers: one manifest entry, the API's body as written. */ interface Component { readonly kind: string; readonly name: string; readonly body: Record; readonly parent?: Component; readonly children: Component[]; readonly path?: string; readonly list?: string; readonly identity?: string; readonly owner?: "platform"; } /** A component of `kind` named `name`, its `body` as written; it goes under its parent's children. Its options set only where it lives and who owns it, whatever else an object wider than their type carries. */ declare function component(kind: string, name: string, body: Record, options?: ComponentOptions): Component; /** What a body embeds to name another component, which the CLI resolves to its id at publish: `{ ref: "/" }`. */ declare function ref(declared: Component): { ref: string; }; /** How a handler fails, what any error says, and how a definition is refused. */ /** * What an ActionError says beside its code and message. `retryable` and * `details` are the failure's: the trace's error carries them (the tracing * SDK's `tracing.error`), and so does `RunResult.failure`; neither the answer * the worker prints, nor its gRPC result, nor what the lifecycle reports to the * platform carries them, and nothing runs the action again. */ interface ActionErrorOptions { /** Whether running the action again may succeed, as the trace tells it. Default false. */ retryable?: boolean; /** What the trace tells of the failure beside its message. */ details?: Record; /** What made it fail, as `Error`'s own `cause`. */ cause?: unknown; } /** * Fails the action with a named code. Any other throw is an EXECUTION_ERROR; * this one keeps the code the author chose, so tests, logs and traces all read * the same name. */ declare class ActionError extends Error { readonly code: string; readonly retryable: boolean; readonly details?: Record; constructor(code: string, message: string, options?: ActionErrorOptions); } /** How an answer failed: its code, its message, whether the platform may retry it, and its details. */ interface Failure { code: string; message: string; retryable: boolean; details?: Record; } /** * A plugin's package: what every plugin belongs to, declared by the project * (its name, version and description, which the project loads from its own * package.json). The library reads no package.json. */ /** What every plugin belongs to: the project, as publish registers it. */ interface Package { readonly name: string; readonly slug: string; readonly version: string; readonly description?: string; } /** A package as a define takes it: the slug is the name, slugified, unless given. */ interface PackageDeclaration { name: string; version: string; description?: string; slug?: string; } /** * The settings: what the library runs with, one parameter per row of * contract/settings.json, each a string with the default the table gives it. * A run resolves them once, from what its caller gives (`settingsOf`): a value * given in code wins, then what the caller fills in for the rest, then the * default. The library reads no file and no environment variable for them: * the agent's command line (`main`) reads the variables the agent sets on a * worker, the table's `agent` column, through `agentSettingsOf`, and hands * them over. A message about a setting names it with `describeSetting`. Where * a setting is used, a blank value is absent (`textOf`); the platform API URL * absent is its default (`textOrDefaultOf`). */ /** A setting the agent sets on a worker, in the variable contract/settings.json's `agent` column names. */ type AgentSettingName = "apiUrl" | "apiKey" | "actionContext" | "grpcListen" | "agentPlugin" | "workerTlsCa" | "workerTlsCaFile" | "workerTlsCert" | "workerTlsCertFile" | "workerTlsKey" | "workerTlsKeyFile"; /** The name of a setting: one per row of contract/settings.json. */ type SettingName = AgentSettingName | "tracingUrl"; /** A run's settings, resolved: one string per setting, empty when nothing gives it and the table gives it no default. */ type Settings = Readonly>; /** * The one logger every run takes (`log`) and every handler gets (`context.log`), * whatever the plugin's kind. It is a logger, not a trace: a handler's steps, * their outcomes and durations go to the tracing port. */ /** * Where a run says what it does, by level: pino, winston or a `Console` fit. * It writes to stderr: a worker's stdout is its answer (or the gRPC * handshake), and the global `console` writes `info` and `debug` there. */ interface Logger { debug(message: string): void; info(message: string): void; warn(message: string): void; error(message: string): void; } /** The default `log`: a `Console` on stderr for every level, since stdout is the answer. */ declare const stderrLogger: Logger; /** A message a run logged, at its level. */ interface RunLog { level: keyof Logger; message: string; } /** The platform port: what sends a request to the platform and answers its response. */ type Fetch = (request: Request) => Promise; /** A query string's values; an undefined or empty one is left out. */ type Query = Record; /** A request as the recording platform saw it: its method, its path and query under the API root, and its body. */ interface RecordedRequest { method: string; path: string; body?: unknown; } /** What a recording platform tells, how it answers, and where the API it stands for is. */ interface RecordingOptions { /** Told each request at debug; silent unless given. */ log?: Logger; /** What answers each request; `200 {}` unless given. */ respond?: (request: Request) => Response | Promise; /** The platform API URL each path is recorded under; the `apiUrl` setting's default unless given, or given blank. */ apiUrl?: string; } /** * A platform port that sends nothing: it records each request (`requests`), * its path under `apiUrl`, tells `log` of it at debug, and answers what * `respond` answers, `200 {}` unless given. A local run's port, and a test's. */ declare function recordingPlatform(options?: RecordingOptions): { fetch: Fetch; requests: RecordedRequest[]; }; /** The platform's credentials, as a run's settings give them: the platform API's URL, where the key is exchanged, and the key. */ type Credentials = Pick; /** What sends a request to a resource: JSON in, JSON out, the result typed by the caller. */ interface Verbs { /** `GET` the resource, with `query`. */ get(query?: Query): Promise; /** Every item of the resource's listing (`{ paging, results }`), page after page, with `query`. */ list(query?: Query): AsyncIterable; /** `POST` `body` to the resource. */ post(body?: unknown): Promise; /** `PUT` `body` to the resource. */ put(body?: unknown): Promise; /** `PATCH` the resource with `body`. */ patch(body?: unknown): Promise; /** `DELETE` the resource. */ delete(): Promise; } /** A path on the platform API: a property adds a segment, a call adds an id, a verb sends; read as text, it is its path. */ type Resource = Verbs & ((id: string | number) => Resource) & { readonly [segment: string]: Resource; } & { [Symbol.toPrimitive](): string; }; /** The platform API: each property its first path segment, and `fetch` the port every call goes through. */ type Api = { readonly [segment: string]: Resource; } & { fetch: Fetch; }; /** What `createApi` builds the API over. */ interface ApiOptions { /** The platform port every call goes through; the port `credentials` authorize (`authorizedFetch`) unless given. */ fetch?: Fetch; /** The platform's credentials, each its setting's default unless given: the API's URL (`apiUrl`), and the key its default port exchanges for a token (`apiKey`). */ credentials?: Partial; /** What cancels every call. */ signal?: AbortSignal; } /** * The platform API at the `apiUrl` its credentials give, over `fetch` (the * port they authorize unless given), each call cancelled by `signal`. Every * property but `fetch`, the port itself, is the first segment of a path. */ declare function createApi(options?: ApiOptions): Api; /** * The narrative: what a handler says about its work on the trace, in the words * the console leads with. A step's narrative reaches the handler as the * argument of its `context.trace.step` work; the run's own is `context.trace`. * * Everything here is best effort: with no tracing it is silent, and nothing a * narrative is told can fail a run. The console names a node from * `explain.title` first (the plan's title stands in when a handler leaves it * out), leads with `what`, and keeps `why`, `impact` and `next` under it: say * what happened with the facts in it, and why. */ interface Explanation { /** The node's display name: the plan's title for this step (or run) unless given. */ title?: string; /** What happened, in one sentence with the facts in it. */ what?: string; /** Why it was done, or why it went the way it did. */ why?: string; /** What it means for the reader. */ impact?: string; /** What to do now, when there is something to do. */ next?: string; severity?: "ok" | "warn" | "error"; } /** Somewhere to go from the node: the job run, the bundle folder, the commit. */ interface ExternalLink { rel: string; uri: string; label?: string; } interface Narrative { /** `tracing.explain`: the plain words the console leads with. A later call replaces an earlier one. */ explain(body: Explanation): void; /** `tracing.external_links`: a link out of the node. */ link(link: ExternalLink): void; /** `tracing.output`: a fact worth keeping as data (ids, hosts, versions). */ output(name: string, value: unknown): void; } type Plan = PlanFacetInput; interface StepOptions { /** Additional attempts after the first failure; none unless given (fail fast). */ retries?: number; /** Each attempt's time budget in milliseconds, none when absent, 0 or Infinity (`within`); an attempt over it fails. */ timeoutMs?: number; } /** The work of a step. Its argument narrates the step on the trace (what happened, why, links, outputs). */ type StepWork = (step: Narrative) => Promise | Result; interface Step { (name: string, run: StepWork): Promise; (name: string, options: StepOptions, run: StepWork): Promise; } /** Told how a step ended and how long it took, from its first attempt to its last: once per step that runs. */ type StepObserver = (name: string, outcome: { status: "completed" | "failed"; durationMs: number; }) => void; /** What a run is on the trace. */ interface RunSpec { /** Who reports the run: the package's slug. */ producer: string; /** The entity the run is scoped to; the tracing API refuses a run without one, so such a run is not traced. */ nrn?: string; /** The run's id in its trace. */ runId: string; /** The trace the run belongs to; the run starts one of its own when absent. */ traceId?: string; /** The run this one is a stage of, in the same trace. */ parentRunId?: string; /** The run's name on screen. */ title: string; /** What the run does: its narrative until the handler says more. */ description?: string; /** The steps the run is expected to run; `context.trace.step` names them by key. */ plan?: Plan; /** The job every run like this one is an instance of: it carries the plan. */ job?: { namespace: string; name: string; version: string; }; /** The run's labels; one whose value is undefined is left out. */ labels: Record; /** Who asked for the run. */ actor?: { kind: "user" | "service"; id: string; }; /** What the run consumed, by name. */ input?: Record; } /** What a route says of the run that answers a payload: the run, and what the run traces of a successful answer's data (a copy, its secrets redacted, say). */ interface RunDescription { run: RunSpec; result(data: unknown): unknown; } /** How a run ended: what it answered, or how it failed. */ type SpanOutcome = { status: "success"; result?: unknown; } | { status: "failed"; failure: Failure; }; /** A run on the trace, from its start to its end. */ interface Span { /** `step`, each of its calls a step of the run, its work handed the step's narrative. */ traced(step: Step): Step; /** The run's own narrative: what `context.trace` tells. */ narrative: Narrative; /** Ends the run with its outcome, once the trace has been told. */ end(outcome: SpanOutcome): Promise; } interface Tracer { /** Starts the run `spec` describes. */ run(spec: RunSpec): Span; } /** Tracing that records nothing: what tracing is when off, and what a local run passes. */ declare const noopTracing: Tracer; /** The run's step and its narrative. */ interface Trace extends Narrative { /** A unit of work, with retries and a timeout: a step of the run, keyed by its name. */ step: Step; } /** How a route prints its answer: the envelope (`{"success":…}`) unless it says `raw`, the handler's return as it is. */ type Output = "envelope" | "raw"; /** What every handler gets beside its input: the SDK's tools. */ interface Context { /** The run's logger, and the agent's stream when the transport has one. */ log: Logger; /** The run's step, a unit of work with retries and a timeout, and what the handler says on the trace; the step still runs and the rest is silent when tracing is off. */ trace: Trace; /** Aborted when the worker stops or the agent cancels. */ signal: AbortSignal; /** The platform API, at the run's `apiUrl`. */ api: Api; /** The run's platform credentials (`apiUrl`, `apiKey`), frozen: what the platform API and a kind's own client reach the platform with. */ credentials: Credentials; /** The project's own ports. */ ports: Ports; } /** A piece of the agent's stream: text on its stdout or its stderr. */ interface StreamChunk { stdout?: string; stderr?: string; } /** What a transport answers a payload with: the ports the handler's context is built from. */ interface AnswerPorts { /** The run's settings, resolved once and frozen: the transport's; a handler gets only their platform credentials (`context.credentials`). */ settings: Settings; /** The platform port every call of `context.api` goes through. */ fetch: Fetch; /** The run's logger: every level the handler logs. */ log: Logger; /** Aborted when the worker stops or the agent cancels. */ signal: AbortSignal; /** The project's own ports: `context.ports`. */ ports: Ports; /** The tracing port: where the core opens the run a route describes. */ tracer: Tracer; /** The agent's stream, when the transport has one (gRPC): the log, line by line. */ stream?: (chunk: StreamChunk) => void; /** Told how each step ended and how long it took. */ observeStep?: StepObserver; } /** * What the agent delivers: a document, a JSON object, and the payload in it. * The core reads nothing a payload says; this is the one place that knows * where a delivery puts it. */ /** What the agent delivered for a plugin to answer: a JSON object. */ type Payload = Record; /** * What a middleware calls to run the inner ones, the handler last, with the * input and the context it passes on; each call runs them again. One it * leaves out, or undefined, passes on as it was handed: `next()` passes both * on unchanged, `next(input)` replaces the input only. */ type Next = (input?: Input, context?: Context) => Promise; /** * Runs around the next one, `(input, context, next)` as a handler is * `(input, context)`, whoever wrote it: typed by the input it is handed, the * payload unless a kind's (a service's action's, a scope's), and by the input * it passes on, the same unless it builds another (a kind's own, which builds * its input from the payload it is handed). It may change the input and the * context it passes on, and sees what the inner ones returned or threw. */ type Middleware = (input: Input, context: Context, next: Next) => Promise; /** What answers a payload: its input the payload, or what a route's middleware passes on, and its context the run's tools. */ type Handler = (input: Payload, context: Context) => unknown; /** * A route's last word before its handler: handed what its middleware passed * on and the payload as delivered, it returns what the handler gets, or throws * to fail the answer. A kind's own: the core calls it, and reads neither. */ type Guard = (input: Payload, payload: Payload) => Payload; /** One thing the plugin answers. */ interface Route { /** Unique in the plugin: what a refusal lists and tooling offers. */ name: string; /** Whether the route answers `payload`; routes are tried in order. */ match(payload: Payload): boolean; /** Around the handler, outermost first, after the plugin's own. */ use?: readonly Middleware[]; /** What answers the payload: its return is the answer's data, what it throws the failure. */ handler: Handler; /** What the run that answers `payload` is on the trace, a kind's own description of it: opened before the middleware, ended with the answer; none, no run. */ describe?(payload: Payload): RunDescription | undefined; /** What the handler gets of what the middleware passed on, checked right before it (`Guard`); what the middleware passed on unless given. */ guard?: Guard; /** How the answer prints for `payload`; envelope unless it says. */ output?(payload: Payload): Output; /** What the package's agent channel lets through for it: a source and the filter on it. */ channel?: { source: string; filter: Record; }; /** What tooling offers to run it with, and tests start from. */ sample?: Payload; } /** The route that answers anything, its handler handed the payload as its input: it goes last. Tooling offers it with an empty payload. */ declare function execute(handler: Handler): Route; /** How the package's agent channel reaches the worker; each defaults from the package's slug and the routes. */ interface AgentOptions { /** The tags an agent carries to answer the package; `{ package: }` unless given. */ selector?: Record; /** What the agent execs in the worker image; contract/platform.json's `entrypoint` for the slug unless given. */ entrypoint?: string; /** The notification sources the channel subscribes to; the routes' channel sources unless given. */ sources?: string[]; /** Pins the channel's command to the version published (`${version}`). */ pinVersion?: boolean; /** Whether publish manages the channel; true unless false. */ manageChannel?: boolean; } /** One entry of what publish registers: the API's body as written, and where it lives when the convention does not hold. */ interface ManifestComponent { /** Unique in the package; a ref names it as `/`. */ name: string; /** The API's entity name. */ resource_type: string; /** The body the kind's API takes, as its author wrote it. */ resource?: Record; /** The component this one is created under, as `/`. */ parent?: string; /** Where it is created, when not `/`. */ path?: string; /** Where publish lists it to find an existing one. */ list?: string; /** The body's field that identifies an existing one, when not `name`. */ identity?: string; /** `platform`: the platform creates it; publish looks it up and pins it, never writes it. */ owner?: "platform"; } /** What tooling offers to run: a route's name, and the document the agent would deliver for it. */ interface ManifestRun { name: string; document: unknown; } /** What describe prints. */ interface Manifest { name: string; slug: string; version: string; description?: string; components: ManifestComponent[]; runs: ManifestRun[]; /** A tooling block a definition adds (a collector's `collector`); publish ignores it. */ [tooling: string]: unknown; } /** What a plugin's own serve is handed: the run's logger, its signal, its platform credentials (frozen) and the project's own ports. */ interface ServeContext extends Pick, "log" | "signal" | "credentials" | "ports"> {} /** What a plugin is defined by. */ interface PluginDefinition { /** The package it belongs to: its name, version and description (the slug is the name's unless given), the project's own. */ package: PackageDeclaration; /** How the package's agent channel reaches the worker. */ agent?: AgentOptions; /** What it publishes: values from `component()`, children reached through their parents. */ components?: Component[]; /** Around every route's middleware and handler, outermost first. */ use?: Middleware[]; /** What it answers, tried in order. */ routes: Route[]; /** How it serves itself, when it does (a collector's schedule and watch), in place of the agent's protocol. */ serve?: (context: ServeContext) => Promise; /** Blocks describe carries for tooling beside the manifest's own fields (a collector's `collector`); publish ignores them. */ tooling?: Record; } /** How a plugin answered a payload: the handler's return, or the failure, and how the answer prints. */ interface Answer { status: "success" | "failed"; data?: unknown; failure?: Failure; output: Output; } /** A plugin: what describe prints and what the transports answer with. */ interface Plugin { readonly package: Package; readonly routes: readonly Route[]; /** What publish registers and tooling offers. */ manifest(): Manifest; /** The answer to the document a transport delivered. */ answer(document: Record, ports: AnswerPorts): Promise; /** How it serves itself, when it does. */ readonly serve?: (context: ServeContext) => Promise; } /** * A plugin of its package, its components and its routes; a definition with a * problem is refused, naming every problem at once. What it is given is copied * when it is defined: a later change to the definition reaches neither its * answers nor its describe. */ declare function definePlugin(definition: PluginDefinition): Plugin; export { RunLog as A, createApi as C, RecordingOptions as D, RecordedRequest as E, ActionError as F, Failure as I, Component as L, Settings as M, Package as N, recordingPlatform as O, PackageDeclaration as P, component as R, Resource as S, Fetch as T, Plan as _, AgentOptions as a, Narrative as b, Route as c, Context as d, Trace as f, Step as g, noopTracing as h, definePlugin as i, stderrLogger as j, Logger as k, execute as l, Tracer as m, Plugin as n, Manifest as o, RunSpec as p, PluginDefinition as r, Middleware as s, Answer as t, Payload as u, Explanation as v, Credentials as w, Api as x, ExternalLink as y, ref as z }; //# sourceMappingURL=plugin-DYhXH7JX.d.mts.map