@protobase/cli 0.100.19 → 0.100.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "0.100.19";
2
+ var version = "0.100.21";
3
3
  //#endregion
4
4
  export { version };
@@ -0,0 +1,33 @@
1
+ //#region src/serve/close-server.ts
2
+ /**
3
+ * How `server` closes, given before it listens so it sees every request: it stops accepting connections and resolves
4
+ * once every open one ended. Each request open then, and each one that comes on an open connection meanwhile, is
5
+ * answered with `Connection: close`, and idle connections close at once; whatever is still open after `graceMs` is
6
+ * dropped. Node's `close` alone waits for busy keep-alive connections, which a client that asks again as each answer
7
+ * comes, as a runner's long poll does, never leaves idle.
8
+ */
9
+ const serverCloser = (server) => {
10
+ const open = /* @__PURE__ */ new Set();
11
+ let closing = false;
12
+ const last = (response) => {
13
+ if (!response.headersSent) response.setHeader("connection", "close");
14
+ };
15
+ server.on("request", (_request, response) => {
16
+ if (closing) last(response);
17
+ open.add(response);
18
+ response.once("close", () => open.delete(response));
19
+ });
20
+ return (graceMs) => new Promise((resolve, reject) => {
21
+ closing = true;
22
+ const dropping = setTimeout(() => server.closeAllConnections(), graceMs);
23
+ server.close((error) => {
24
+ clearTimeout(dropping);
25
+ if (error) reject(error);
26
+ else resolve();
27
+ });
28
+ for (const response of open) last(response);
29
+ server.closeIdleConnections();
30
+ });
31
+ };
32
+ //#endregion
33
+ export { serverCloser };
@@ -6,6 +6,7 @@ import { apiWebSocketServer } from "../project/api-websocket-server.js";
6
6
  import { withClientAddress } from "./client-address.js";
7
7
  import { createServeApp } from "./app.js";
8
8
  import { startCleanupTimer } from "./cleanup-timer.js";
9
+ import { serverCloser } from "./close-server.js";
9
10
  import { closeSockets } from "./close-sockets.js";
10
11
  import { servedRelease } from "./mobile-release.js";
11
12
  import pg from "pg";
@@ -19,8 +20,9 @@ const listen = (server, port, host) => new Promise((resolve, reject) => {
19
20
  resolve();
20
21
  });
21
22
  });
22
- const closeServer = (server) => new Promise((resolve, reject) => server.close((error) => error ? reject(error) : resolve()));
23
- const startServe = async ({ config, env, openDb = (url) => openAppDatabase(pg, url, env.dbConnections), site, ui, reporter }) => {
23
+ /** How long a closing server lets the requests open on it finish, as the jobs' shutdown lets running jobs, in ms. */
24
+ const closeGraceMs = 3e4;
25
+ const startServe = async ({ config, env, openDb = (url) => openAppDatabase(pg, url, env.dbConnections), site, ui, reporter, closeGraceMs: graceMs = closeGraceMs }) => {
24
26
  if (!env.databaseUrl) throw new Error("No database: set DATABASE_URL");
25
27
  const database = openDb(env.databaseUrl);
26
28
  const { db } = database;
@@ -87,12 +89,15 @@ const startServe = async ({ config, env, openDb = (url) => openAppDatabase(pg, u
87
89
  overrideGlobalObjects: false,
88
90
  websocket: { server: sockets }
89
91
  });
92
+ const closeServer = serverCloser(server);
90
93
  await listen(server, env.port, env.host).catch(async (error) => {
91
94
  await jobs?.stop();
92
95
  throw error;
93
96
  });
94
97
  return {
95
98
  server,
99
+ closeServer,
100
+ admin,
96
101
  sockets,
97
102
  jobs,
98
103
  prune: admin.startRealtimePrune(),
@@ -100,7 +105,7 @@ const startServe = async ({ config, env, openDb = (url) => openAppDatabase(pg, u
100
105
  files: project.files
101
106
  };
102
107
  };
103
- const { server, sockets, jobs, prune, resources, files } = await startJobsAndListen().catch(async (error) => {
108
+ const { server, closeServer, admin, sockets, jobs, prune, resources, files } = await startJobsAndListen().catch(async (error) => {
104
109
  await db.destroy();
105
110
  throw error;
106
111
  });
@@ -111,7 +116,8 @@ const startServe = async ({ config, env, openDb = (url) => openAppDatabase(pg, u
111
116
  });
112
117
  const timer = cleanup && env.filesCleanupMinutes > 0 ? startCleanupTimer(cleanup.run, env.filesCleanupMinutes, (error) => console.error(error)) : void 0;
113
118
  const close = async () => {
114
- const closed = closeServer(server);
119
+ const closed = closeServer(graceMs);
120
+ await admin.stopHolding();
115
121
  await closeSockets(sockets.clients);
116
122
  await closed;
117
123
  await backgroundSettled();
@@ -126,4 +132,4 @@ const startServe = async ({ config, env, openDb = (url) => openAppDatabase(pg, u
126
132
  };
127
133
  };
128
134
  //#endregion
129
- export { startServe };
135
+ export { closeGraceMs, startServe };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.100.19",
3
+ "version": "0.100.21",
4
4
  "description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -43,13 +43,13 @@
43
43
  "dependencies": {
44
44
  "@better-auth/core": "^1.7.12",
45
45
  "@hono/node-server": "^2.1.3",
46
- "@protobase/config": "0.100.19",
47
- "@protobase/layout": "0.100.19",
48
- "@protobase/query": "0.100.19",
49
- "@protobase/schema": "0.100.19",
50
- "@protobase/server": "0.100.19",
51
- "@protobase/ui": "0.100.19",
52
- "@protobase/workflows": "0.100.19",
46
+ "@protobase/config": "0.100.21",
47
+ "@protobase/layout": "0.100.21",
48
+ "@protobase/query": "0.100.21",
49
+ "@protobase/schema": "0.100.21",
50
+ "@protobase/server": "0.100.21",
51
+ "@protobase/ui": "0.100.21",
52
+ "@protobase/workflows": "0.100.21",
53
53
  "@react-email/render": "^2.1.0",
54
54
  "@scalar/hono-api-reference": "^0.12.10",
55
55
  "@sentry/vite-plugin": "^11.10.0",
@@ -37,8 +37,11 @@ Graphs of steps the server runs along their edges, written in a language a model
37
37
  - [Triggers turned on while the app runs](../reference/workflows.md#turning-a-trigger-on) (beta): Publishing a saved version registers its trigger on every server process, and turning the workflow off stops it, with no restart; a save goes live only once it is published.
38
38
  - [Workflow plugins](../reference/workflow-plugins.md) (beta): A file of the app or a package adds trigger and step types through the same public interface the built-in types use.
39
39
  - [Custom workflow steps](../reference/workflows.md#custom-workflow-steps) (in development): Keep a step type of your own as a record, a container built from a Dockerfile with its input and output as JSON Schema, each saved version a step type a workflow names and is checked against; a run hands it to one of your runners, which builds its image and runs it in a container with no network, taking and giving files through your storage configurations.
40
- - [Runners](../reference/workflows.md#runners) (in development): Install a runner on a Linux machine with one command and a one-time token; it claims your custom steps' jobs over HTTP and runs each in a hardened Docker or Podman container, each job placed with the runner that has its image, waiting a moment for one; revoking a runner puts its jobs back in the queue.
41
- - [Custom step builds](../reference/workflows.md#builds) (in development): Each runner builds the images of the custom step versions it runs from their Dockerfiles, listed on each version's page, and builds those of a workflow as you publish it, so its first run finds them ready.
40
+ - [Runners](../reference/workflows.md#runners) (in development): Install a runner on a Linux machine with one command and a one-time token, copied from its page; it claims your custom steps' jobs over HTTP and runs each in a hardened Docker or Podman container, each job placed with the runner that has its image, waiting a moment for one; revoking a runner puts its jobs back in the queue.
41
+ - [Custom step builds](../reference/workflows.md#builds) (in development): Each runner builds the images of the custom step versions it runs from their Dockerfiles, listed on each version's page, and builds a custom step's new version as you save it and those of a workflow as you publish it, so its first run finds them ready.
42
+ - [Testing a custom step](../reference/workflows.md#testing-a-custom-step) (in development): Run one job of a custom step version on a sample input without a workflow, and read its output, or its error with the end of its log.
43
+ - [Custom steps over MCP](../reference/mcp.md#workflows) (in development): An AI client saves a custom step, waits for its build, tests it on a sample file, lists the runners and makes one with its install command, each write after your approval.
44
+ - [From a Dockerfile to a workflow](../reference/workflows.md#from-a-dockerfile-to-a-workflow) (in development): Make a runner, save a custom step, wait for its build, test it and use it in a workflow, in the admin app or over MCP.
42
45
  - [Blocks](../reference/workflows.md#blocks) (beta): build your own step from other steps. A block runs once and is cached by what it reads, so a workflow that reaches it again, in this run or another, reuses its result, such as a file fetched from a link that expires.
43
46
  - [Step cache](../reference/workflow-plugins.md#caching-results) (beta): A plugin's step reuses the result of an identical earlier call from any run or workflow, as its plugin decides, while secrets always come in with their current value; a workflow can force it on, and the graph marks a step forced on against its plugin's advice.
44
47
  - [Guarded requests for plugins](../reference/workflow-plugins.md#sending-requests) (beta): A plugin's requests reach only public addresses, follow no redirect and read at most 10 MiB.
@@ -470,7 +470,7 @@ The app's address and secret are `PROTOBASE_URL` and `PROTOBASE_SECRET` unless i
470
470
  - **Manifest:** a config module needs its `protobase.bundle.json` beside it. The runtime checks no version: the host picks the runtime from the manifest's `protobase` (see [Versioning](versioning.md#bundles-and-runtimes)).
471
471
  - **Startup:** a config module that `protobase build` did not write, a config with an `apiPath` other than `/api/v1`, or one with sign-in on and no secret or URL, stops startup with a one-line error and exit code 1, as does a missing `DATABASE_URL`, an auth store that has not applied every migration of this version, or has a newer one (see [`auth migration`](#auth-migration)), a resource over a table of the auth store, a resource whose [events](events.md) or [history](history.md) lack their triggers or have out-of-date ones, or a missing history or [comments](comments.md#the-table) table, a [rollup or formula field](data-config.md#rollups-and-formulas) whose column or trigger is missing or out of date, a jobs schema that is missing or behind for a config with [jobs](jobs.md#the-jobs-schema) (see [`migration`](#migration)), an [AI field or action](ai.md#the-model) without a model key, [encrypted fields](data-config.md#encrypted-fields) without a key, or another resource over their column, or a taken port; `PROTOBASE_STARTUP_CHECKS=false` skips the checks of those schemas and the key. `protobase serve listening on port <port>` means it is ready.
472
472
  - **Jobs:** with [jobs](jobs.md) in the config it runs them beside the API, unless `PROTOBASE_JOBS=false`, and with `PROTOBASE_JOBS_DRAIN_TOKEN` it answers `POST /api/jobs/drain` for the operator.
473
- - **Shutdown:** the first SIGTERM or SIGINT stops accepting connections, closes open WebSockets with 1001 (dropping any still open after 5 seconds), waits for open requests, gives running jobs 30 seconds to finish, drains the pool `serve` created and exits with 0.
473
+ - **Shutdown:** the first SIGTERM or SIGINT stops accepting connections, answers the requests held open waiting at once (a [runner's](workflows.md#runners) claim gets no job), closes open WebSockets with 1001 (dropping any still open after 5 seconds), and waits for open requests, answering each with `Connection: close` so a client that polls on a kept-alive connection asks no more of this process; a request still open after 30 seconds has its connection dropped. It then gives running jobs 30 seconds to finish, drains the pool `serve` created and exits with 0.
474
474
  - **Host modules:** under Bun, the runtime registers [the modules it supplies](#the-config-module) as virtual modules, so the bundle needs no `node_modules` for them. `protobase serve` and `protobase worker` under Bun do the same with the CLI's own copies, whatever the project installed, so a bundle runs on the copies of the CLI that runs it. <gap>`protobase serve` and `protobase worker` on Node cannot give a bundle the CLI's own host modules because a module hook for Node is not implemented.</gap> On Node both resolve them from the `node_modules` next to the bundle, so there keep the bundle inside the project, whose installed versions it then runs on. Native packages load from the bundle's own `node_modules/` under both.
475
475
  - **Read-only hosts:** nothing is written: no install (`--no-install`), and for a bundle built with `--bun` no transpiling and so no transpiler cache. A bundle with `node_modules/` needs its folder mounted without `noexec`, since its add-ons are mapped as executable code.
476
476
 
@@ -104,7 +104,7 @@ In an app with [workflows](workflows.md), the endpoint also offers tools to find
104
104
 
105
105
  | Tool | What it does |
106
106
  | --- | --- |
107
- | `list_workflow_types` | The step types a Task names as its `Resource` and the triggers a definition holds, built-in and [plugin](workflow-plugins.md) ones alike, with the [custom steps](workflows.md#custom-workflow-steps) of the person's tenant, each by id with its label, description, input as JSON Schema and, when the type declares one, its output, the errors a step fails with, and whether the app can run it. |
107
+ | `list_workflow_types` | The step types a Task names as its `Resource` and the triggers a definition holds, built-in and [plugin](workflow-plugins.md) ones alike, with the [custom steps](workflows.md#custom-workflow-steps) of the person's tenant, each by id with its label, description, input as JSON Schema and, when the type declares one, its output, the errors a step fails with, and whether the app can run it. Each custom step version also says how its image's [build](workflows.md#builds) stands on the app's runners, `build`: `ready` once one built it, `building`, or `failed` on each that tried; none before a build began. |
108
108
  | `list_workflows` | A page of the workflows the person may read, newest change first, without their definitions: `filter` on `name`, `page_size` (20 by default, at most 100) and `page_token`. |
109
109
  | `get_workflow` | One workflow with its whole definition, its [layout](workflows.md#layout), the nodes moved by hand in each view, and its ETag. |
110
110
  | `validate_workflow` | Checks a `state_machine`, with its `trigger` and `execution_order`, or a workflow's `id` with an `edit` of its saved definition, as a save checks it, and saves nothing: `{ valid: true }`, or `{ valid: false, problems }`. A valid one may come with `warnings` in the same shape, which a save goes through with, such as a [Wait after a Block](workflows.md#blocks); `create_workflow` and `update_workflow` return them with what they saved. A record trigger is checked against the resources and fields the person may read, so a resource they cannot read is not a resource of the app. |
@@ -117,6 +117,18 @@ In an app with [workflows](workflows.md), the endpoint also offers tools to find
117
117
  | `new_webhook_url` | Issues a new URL and secret for a workflow that starts from a [webhook trigger](workflows.md#appwebhook), keeping a `secret` the sender makes when given one, and returns `{ url, secret }`, shown this once; the old URL stops. |
118
118
  | `send_task_success`, `send_task_failure`, `send_task_heartbeat` | Answer a Task that [waits for an outside result](workflows.md#waiting-for-an-outside-result) with the `task_token` it handed off: its result, `output`, a string of JSON; its failure, `error` and `cause`; or a heartbeat. Each returns `{ run }`, or `{ error, message }` with the error Step Functions gives, such as `TaskTimedOut`. Only a caller who may read the run can answer it; to anyone else the token is unknown. |
119
119
 
120
+ With [custom steps](workflows.md#custom-workflow-steps) on, the endpoint also offers the tools that make, build, test and run them, and its instructions describe a step's manifest and what its container gets and gives:
121
+
122
+ | Tool | What it does |
123
+ | --- | --- |
124
+ | `get_custom_step` | A custom step by its `name`: its manifest as saved last, the version that is, its ETag, and its latest 20 versions, or only `version`, newest first, each with its step type (`custom:<name>:<version>`), who saved it and when, and its builds, one per runner: the runner's id, `status`, the image's `digest`, how long it took in `seconds` and the last 30 lines of its log, `log_tail`. |
125
+ | `list_runners` | The [runners](workflows.md#runners) the person may read, each with its id, name, whether it is `online` (holding a claim for work now, or running a job), `revoked` and `registered`, its labels, platform, the kinds of work it does, its `free_slots` and the custom step versions whose `images` it holds, as it said with its last claim, and when that was, `polled_at`. |
126
+ | `save_custom_step` | Creates a custom step from its `name` and manifest, `label`, `description`, `container`, `input`, `output`, `error_prefix` and `errors`; or, with the `id` of one, changes the fields given, which saves its next version when the manifest changed. With the `etag` that `get_custom_step` gave, it fails when someone changed the step since. It returns `{ id, name, version, build }`, `build` the image's first build of that version: `{ status, runner, digest, seconds, log_tail }`, `status` `building`, `ready`, `failed`, or `no_runner` when no runner that builds images is online. With `wait_seconds`, at most 120, it waits that long for the build to end. A manifest the save check refuses comes back as `{ "error": "invalid-custom-step", "message", "problems" }`, each problem `{ field, message }`, such as `container.dockerfile`; nothing is saved. |
127
+ | `test_custom_step` | Runs one job of a custom step version, `name` and `version`, on an `input`, its arguments, with a `store` for the files it gives, without a workflow: a [custom step test](workflows.md#testing-a-custom-step). It returns `{ run_id, job_id, status, output, error, cause, log_tail, seconds }`: `status` `queued`, `running`, `succeeded` with its `output`, or `failed` or `timed_out` with its `error` and `cause`, the last 30 lines its container wrote and how long the job took from queued to done. With `wait_seconds`, at most 120, it waits that long for the job to end; `get_workflow_run` reads its run after. |
128
+ | `create_runner_token` | Makes a runner from its `name` and `labels`, and returns `{ id, name, labels, command, expires_at, endpoint }`: the one command that [installs](workflows.md#installing-a-runner) the runner on a Linux machine with a one-time token, shown this once, valid an hour. The client gives it to the person to run on the machine. It needs both `workflow_runners.create` and `workflow_runners.update`, as issuing a runner's token is a change to it; without update nothing is made. |
129
+
130
+ `save_custom_step`, `test_custom_step` and `create_runner_token` come with [writes](#writes), on `workflow_custom_steps`, `workflow_runs` and `workflow_runners` when writes name their resources, and the person approves each first: the save as any create or update of a record, the test showing its arguments, the runner saying the command it gives registers a machine. Each tool reads and writes the records as the person, so the [grants](workflows.md#who-may-do-what) of custom steps, their versions, builds and jobs, runs and runners apply: a test needs the right to start runs and to read jobs, a runner the right to make and change runners.
131
+
120
132
  An `edit` is a [JSON Merge Patch](https://www.rfc-editor.org/rfc/rfc7396) of the saved definition: only what changes, at its place in the document. An object merges into the object there, `null` removes a member, and any other value, a list included, replaces it. Changing one argument of one state:
121
133
 
122
134
  ```json
@@ -174,6 +174,10 @@ The create form and the record's form pick the members of the organization the s
174
174
 
175
175
  `workflow_run` is the field type the `workflow_runs` resource draws its own `id` with: the run's [trace](workflows.md#following-and-debugging-a-run) on its workflow's graph, with the chosen step's records under it. Another uuid field holding a run's id picks it as `r.run_id.widget('workflow_run')`. It takes the whole width, and a list's table shows the id. A plugin that registers a field type named `workflow_run` replaces it.
176
176
 
177
+ ### Custom steps and runners
178
+
179
+ `custom_step_container` is the field type the `workflow_custom_steps` resource draws its `container` with: the Dockerfile, each file beside it by its path and the command, shown as code and edited in boxes of their own, files added and removed by path and the command one argument a line, stored as `{ dockerfile, files, command }`. `runner_install` is the one the `workflow_runners` resource draws its own `id` with: *New install command*, which issues the runner a [one-time token](workflows.md#installing-a-runner) and shows the command that installs it, with a button to copy it. A plugin that registers a field type of either name replaces it.
180
+
177
181
  ## File viewers
178
182
 
179
183
  A file viewer shows files of one media type in the app, such as a report the app writes as JSON, instead of downloading them. `@protobase/image-viewer` and `@protobase/pdf-viewer` are two such plugins for images and PDFs (see [Image and PDF viewers](files.md#image-and-pdf-viewers)). A plugin registers it by the type, which the server must know: a built-in type, or one of the app's own in `files.types` (see [Your own types](files.md#your-own-types)).
@@ -727,7 +727,7 @@ view<typeof objectives>('objectives')
727
727
 
728
728
  ### A record page that opens another
729
729
 
730
- `.recordOpens(to)` sends a record's page to another address in its place, its `{{field}}`s, in the resource, the key and `run`, filled from the record, replacing the record's address in the history so Back skips it: a workflow run's page opens its workflow's page with the run on the graph. A caller who cannot follow it, such as one who may not read the resource it names or open the page it names, gets the record's own page. The record's own page stays at its address with `?standard=true`.
730
+ `.recordOpens(to)` sends a record's page to another address in its place, its `{{field}}`s, in the resource, the key and `run`, filled from the record, replacing the record's address in the history so Back skips it: a workflow run's page opens its workflow's page with the run on the graph. A caller who cannot follow it, such as one who may not read the resource it names or open the page it names, gets the record's own page, and so does a record whose field leaves the key empty, such as a custom step's test run, which has no workflow. The record's own page stays at its address with `?standard=true`.
731
731
 
732
732
  ```ts
733
733
  view<typeof workflowRuns>('workflow_runs').recordOpens({ kind: 'record', resource: 'workflows', key: '{{workflow_id}}', run: '{{id}}' })
@@ -547,7 +547,7 @@ A stored file is read from where its configuration points now. <gap>Changing a c
547
547
  ## Custom workflow steps
548
548
 
549
549
  :::caution[In development]
550
- A custom step is saved, listed and checked, and a run hands it to a registered [runner](#runners), which builds its image and runs its container. Each runner builds its own images, as there is no image registry; a job's container has no network; and a step cannot yet be tested on its own, or given limits on its resources in its manifest.
550
+ A custom step is saved, built, tested, listed and checked, and a run hands it to a registered [runner](#runners), which builds its image and runs its container. Each runner builds its own images, as there is no image registry; a job's container has no network; a step cannot yet be tested on its own in the admin app; and it cannot be given limits on its resources in its manifest.
551
551
  :::
552
552
 
553
553
  A **custom step** is a step type the app's authors keep as a record: a container built from a Dockerfile, with the input it takes and the output it gives as JSON Schema. Each save that changes its manifest is a new version, and every version is a step type of its own, `custom:<name>:<version>`, such as `custom:invoice_pdf:2`, so changing a custom step never changes a workflow that names an earlier version.
@@ -560,7 +560,7 @@ export default defineConfig({ workflows: { customSteps: true } })
560
560
 
561
561
  Their jobs' arguments are sealed with the app's secret, its sign-in's, else `PROTOBASE_SECRET`; without either, startup stops. Their tables, `workflows.custom_steps` and `workflows.custom_step_versions` with those of their runners, jobs and builds, come with the next [`protobase migration`](cli.md#migration) after you turn them on.
562
562
 
563
- A custom step is a record of `workflow_custom_steps`, which you create and change on its standard pages, linked from each workflow's page, through the API or over MCP. Each save is checked, and refused with a 400 problem whose `problems` name each field, such as `container.dockerfile`:
563
+ A custom step is a record of `workflow_custom_steps`, which you create and change on its standard pages, linked from each workflow's page, through the API or [over MCP](mcp.md#workflows). Its page shows its `container` as code: the Dockerfile in a box of its own, each file beside it by its path, with *Add a file* and a button that removes one, and the command, one argument a line, the image's own when empty. Each save is checked, and refused with a 400 problem whose `problems` name each field, such as `container.dockerfile`:
564
564
 
565
565
  | Field | |
566
566
  | --- | --- |
@@ -589,7 +589,7 @@ A custom step is a record of `workflow_custom_steps`, which you create and chang
589
589
  }
590
590
  ```
591
591
 
592
- Each version, its manifest whole with who saved it and when, is a record of `workflow_custom_step_versions`, read-only, listed on its custom step's page. Deleting a custom step keeps its versions, which are then no step types, and a custom step made again under its name goes on from its next version, so `custom:<name>:<version>` always names the one manifest it named first. A save whose version another write of its name took meanwhile, such as a custom step made again while its old one was changed and deleted, is refused with a 409 to send again, and goes on from the next version.
592
+ Each version, its manifest whole with who saved it and when, is a record of `workflow_custom_step_versions`, read-only, listed on its custom step's page; a version's page lists its [builds](#builds), one per runner, and the [jobs](#jobs) that ran it. Deleting a custom step keeps its versions, which are then no step types, and a custom step made again under its name goes on from its next version, so `custom:<name>:<version>` always names the one manifest it named first. A save whose version another write of its name took meanwhile, such as a custom step made again while its old one was changed and deleted, is refused with a 409 to send again, and goes on from the next version.
593
593
 
594
594
  A Task names a version in its `Resource`:
595
595
 
@@ -608,6 +608,26 @@ The editor's step picker lists each custom step at its latest version under *Cus
608
608
 
609
609
  A run hands a custom step to one of its tenant's [runners](#runners) as a [waiting Task](#waiting-for-an-outside-result) hands off its work: it queues a **job** with its arguments, then waits, holding no worker, until the runner that claimed the job completes it. So `Retry`, `Catch`, `HeartbeatSeconds` and the once-only answer work as for any waiting Task, and a retry queues a new job with a new token. Its `TimeoutSeconds` counts from the try's start, its time in the queue included, and is 300 by default, as for any step type, up to 366 days; past it the Task fails with `States.Timeout`. A custom step waits for its runner already, so `.waitForTaskToken` on its `Resource` is refused, naming the `Resource` to write, and so is `Cache`. A run of a custom step that was deleted meanwhile fails with `States.Runtime`.
610
610
 
611
+ ### Testing a custom step
612
+
613
+ A **custom step test** runs one job of a custom step version on an input, without a workflow: a run of no workflow whose one Task is that version, its arguments the run's input. It is a run as any other: it needs `workflow_runs.create`, takes the person's tenant, acts as them, its files read and stored through their [storage configurations](#storing-files), its step queues a job for one of the tenant's runners, and its Task waits 300 seconds, its time in the queue included. Its run reads as theirs, with no `workflow_id` and the version it tested as `test_step`, and no workflow's status counts it. It never leads to a workflow: the runs list names it by *Tested step*, its address `/workflow_runs/<id>` opens its own page with its one step's trace, error and output and the way to its job, and it offers no replay or re-run. The MCP tool `test_custom_step` starts one and gives the job's output or error, cause and the last lines its container wrote; only the server starts one, so the API's `POST /api/v1/workflow_runs` always names a workflow.
614
+
615
+ ### From a Dockerfile to a workflow
616
+
617
+ **For a person**, in the admin app:
618
+
619
+ 1. *Runners*, linked from a workflow's page: make a runner, then on its page *New install command* issues the command with a one-time token, valid an hour, to copy and run on a Linux machine with Docker or Podman. Once it registers, its list shows it with its platform, last claim, free slots and images.
620
+ 2. *Custom steps*: make one with its Dockerfile, files and command, and its input and output schemas. Each save that changes the manifest is the next version, which the runners that build images build at once; its version's page lists each build, ready with the image's digest or failed with the end of its log.
621
+ 3. Make a workflow with a Task of `custom:<name>:<version>`, which the step picker lists under *Custom steps*, and try it with *Test run*. The run's step links to its jobs, with the lines its container wrote; fix the manifest, save the next version, name it in the Task and run again.
622
+ 4. Publish the workflow once it gives what it should.
623
+
624
+ **For an LLM** over [MCP](mcp.md#workflows), whose instructions describe the manifest and the files a container gets and gives:
625
+
626
+ 1. `list_runners` says whether a runner is online; if none is, `create_runner_token` gives the install command, for the person to run.
627
+ 2. `save_custom_step` with the manifest and `wait_seconds` saves the step and waits for its build: `ready` with the digest, or `failed` with the end of the build's log to fix and save again.
628
+ 3. `test_custom_step` runs the version on a sample input, a stored file for a file argument, and gives its output, or its error with the end of its stderr and its log; fix, save the next version and test again.
629
+ 4. `update_workflow` or `create_workflow` names the version in a Task, `validate_workflow` checks its arguments and pins, `run_workflow` and `get_workflow_run` try it, and `enable_workflow` publishes it.
630
+
611
631
  ### Runners
612
632
 
613
633
  :::caution[In development]
@@ -623,12 +643,13 @@ A **runner** is a machine that runs custom steps' jobs: a record of `workflow_ru
623
643
  | `revoked` | Set to `true` to refuse the runner from its next call on: the jobs it holds go back to the queue, for another runner. It cannot be set back; register the machine again as a new runner. |
624
644
  | `registered_at`, `platform`, `kinds` | When it registered, and the platform and kinds of steps it gave then. Read-only. |
625
645
  | `state`, `polled_at`, `polling_until` | What it said of itself with its last claim, when it made it, and until when that claim is held open. Read-only. |
646
+ | `free_slots`, `images` | How many more jobs it could run at once, and the custom step versions whose images it holds, from its last claim's `state`: columns the database keeps, which the runners' list shows. Read-only. |
626
647
 
627
- Deleting a runner refuses its token as revoking it does.
648
+ Deleting a runner refuses its token as revoking it does. A runner's page offers *Revoke*, which asks first, while it is not revoked.
628
649
 
629
650
  #### Installing a runner
630
651
 
631
- Make the runner, then issue its one-time registration token with `POST /api/workflows/runners/<id>/registration`, which needs the right to change that runner in your tenant; anyone else gets 404. It answers `{ token, expires_at, command, endpoint }` once: a `pbr_once_...` token valid one hour, of which the app keeps only the SHA-256, so it cannot show it again, the one command that installs the runner with it, and the address of the runner's calls. Both are under the path of the app's system endpoints, `/api` unless its `basePath` moves them, as `/backend` for `/backend/v1`. A token issued again replaces the earlier one, until the runner registers. Run the command on the machine, as the user the runner runs as:
652
+ Make the runner, then issue its one-time registration token: on the runner's page, *New install command* shows the command with the token, to copy, until the runner registers; over MCP, `create_runner_token` makes the runner and gives the command; through the API, `POST /api/workflows/runners/<id>/registration`, `client.runnerRegistration(id)` of `@protobase/client`. It needs the right to change that runner in your tenant; anyone else gets 404. It answers `{ token, expires_at, command, endpoint }` once: a `pbr_once_...` token valid one hour, of which the app keeps only the SHA-256, so it cannot show it again, the one command that installs the runner with it, and the address of the runner's calls. Both are under the path of the app's system endpoints, `/api` unless its `basePath` moves them, as `/backend` for `/backend/v1`. A token issued again replaces the earlier one, until the runner registers. Run the command on the machine, as the user the runner runs as:
632
653
 
633
654
  ```sh
634
655
  curl -fsSL https://app.example.com/api/runners/install.sh | sh -s -- --token pbr_once_...
@@ -713,7 +734,7 @@ A runner builds a version's image from its `dockerfile` and `files` alone, in a
713
734
 
714
735
  Each build is a record of `workflow_custom_step_builds`, read-only, listed on its version's page: its runner and step version, its `status` (`building`, `ready` or `failed`), its image's `digest` once ready, the last 10,000 characters of its `log`, and when it started and finished. A job whose image does not build fails as `Custom.Failed`, the end of the log its cause.
715
736
 
716
- **Prepare on publish.** Publishing a workflow's version keeps the custom step versions it uses as wanted, until another version is published or the workflow is turned off. A claim that no job reaches is then answered `{ "order": "prepare", "step", "build" }` for a wanted version whose image the runner lacks, when the runner builds: it builds the image before it claims again, so the first run finds it ready. Each runner is sent it once per version, until it lists the image or its build failed.
737
+ **Prepare on save and publish.** Each custom step's current version, its last save, is wanted, so it is built before it is tested or used; and publishing a workflow's version keeps the custom step versions it uses as wanted, until another version is published or the workflow is turned off. A claim that no job reaches is then answered `{ "order": "prepare", "step", "build" }` for a wanted version whose image the runner lacks, when the runner builds: it builds the image before it claims again, so the first run finds it ready. Each runner is sent it once per version, until it lists the image or its build failed.
717
738
 
718
739
  #### The runner's calls
719
740
 
@@ -730,7 +751,7 @@ Every other call carries the runner's own token as `Authorization: Bearer pbr_..
730
751
 
731
752
  | Call | Body | Answer |
732
753
  | --- | --- | --- |
733
- | `POST /api/runners/v1/claim` | What the runner says of itself: `{ "platform": "linux/amd64", "kinds": ["container", "build"], "labels": [], "capacity": { "slots": 2 }, "images": [{ "step": "custom:ocr:4", "snapshot": true }], "instances": [{ "step": "custom:ocr:4", "free": 3 }] }` | Held open up to 50 seconds until a job is placed with the runner: `{ "order": "job", "job": { "id", "step", "input", "deadline", "heartbeat_seconds", "lease_seconds", "files", "output_files", "build", "command" } }`; `{ "order": "prepare", "step", "build" }`; or `{ "order": "none" }` when its time ran out. Claim again at once. |
754
+ | `POST /api/runners/v1/claim` | What the runner says of itself: `{ "platform": "linux/amd64", "kinds": ["container", "build"], "labels": [], "capacity": { "slots": 2 }, "images": [{ "step": "custom:ocr:4", "snapshot": true }], "instances": [{ "step": "custom:ocr:4", "free": 3 }] }` | Held open up to 50 seconds until a job is placed with the runner: `{ "order": "job", "job": { "id", "step", "input", "deadline", "heartbeat_seconds", "lease_seconds", "files", "output_files", "build", "command" } }`; `{ "order": "prepare", "step", "build" }`; or `{ "order": "none" }` when its time ran out or the process serving it stops, which ends the connection after it. Claim again at once. |
734
755
  | `POST /api/runners/v1/jobs/<id>/heartbeat` | `{}` | `{ "stop": false }`, extending the runner's hold of the job and counting as a heartbeat of its Task; `{ "stop": true }` once the runner no longer holds it, as when its try timed out, its run ended or its lease ran out: stop the job. |
735
756
  | `POST /api/runners/v1/jobs/<id>/log` | `{ "lines": ["..."] }`, at most 100 | `{}`; the job keeps its last 100 lines, each up to 1,000 characters, with the workflows' secrets and the token blanked out. |
736
757
  | `GET /api/runners/v1/jobs/<id>/inputs/<input>` | | The bytes of the job's input file `<input>`, streamed from its storage configuration or the run's files. |
@@ -761,15 +782,15 @@ Placing runs as a job is queued, as a claim comes, and every second while a serv
761
782
 
762
783
  ### Jobs
763
784
 
764
- Each job is a record of `workflow_custom_step_jobs`, read-only, listed on its runner's page: its run and state, its step and version, its `input` with the workflows' secrets blanked out, its `status` (`queued`, `running`, `succeeded`, `failed` or `timed_out`), the runner that holds or held it and until when (`lease_until`), how often it went back to the queue (`requeues`), when it was queued, claimed and finished, and its `output`, `error`, `cause` and `logs`. Its arguments as given are not among its fields: while it waits they are kept sealed with the app's secret, opened only into the claim answer, and dropped once it ends. Of its try's token it keeps only the hash. A job whose try ends without it, by its time or its run's end, is `timed_out`.
785
+ Each job is a record of `workflow_custom_step_jobs`, read-only, listed on its runner's and its version's page, and linked from its run's step, *Open this run's jobs*, for whoever may read jobs: its run and state, its step and version, its `input` with the workflows' secrets blanked out, its `status` (`queued`, `running`, `succeeded`, `failed` or `timed_out`), the runner that holds or held it and until when (`lease_until`), how often it went back to the queue (`requeues`), when it was queued, claimed and finished, and its `output`, `error`, `cause` and `logs`. Its arguments as given are not among its fields: while it waits they are kept sealed with the app's secret, opened only into the claim answer, and dropped once it ends. Of its try's token it keeps only the hash. A job whose try ends without it, by its time or its run's end, is `timed_out`.
765
786
 
766
787
  - <gap>A runner cannot pull a custom step's image another runner built because an image registry is not implemented; each runner builds the images it runs.</gap>
767
788
  - <gap>A custom step's container cannot reach the network because network access for jobs is not implemented.</gap>
768
789
  - <gap>A runner cannot keep warm instances of a custom step, or be told to drain or stop, because those orders are not implemented; a claim is answered with a job, `prepare` or none.</gap>
769
790
  - <gap>A runner cannot be installed on macOS or Windows because only Linux executables are built.</gap>
770
- - <gap>A runner's registration token cannot be issued in the admin app because its action is not implemented; `POST /api/workflows/runners/<id>/registration` issues it.</gap>
771
791
  - <gap>A custom step cannot set its own memory, CPU or disk because those fields of its manifest are not implemented; its runner's settings limit every job alike.</gap>
772
- - <gap>A custom step cannot be saved or tested over MCP with tools of its own because those tools are not implemented; `create_record` and `update_record` save it.</gap>
792
+ - <gap>A custom step version cannot be tested on its own in the admin app because a test action on its page is not implemented; a workflow's *Test run* runs it, and `test_custom_step` over MCP.</gap>
793
+ - <gap>A runner's list cannot say whether it is online because a column that follows the time is not implemented; its last claim says when it last asked for work, and `list_runners` over MCP says whether it is online.</gap>
773
794
 
774
795
  ## Runs and their steps
775
796
 
@@ -874,14 +895,14 @@ The workflow resources take only [named grants](access.md#resources-that-need-na
874
895
  | Grant | |
875
896
  | --- | --- |
876
897
  | `workflows.create`, `workflows.update`, `workflows.delete` | Make, change and delete workflows, and turn them on and off. Each save that changes the definition makes the saver the workflow's last editor, whom its records steps and its trigger act as. |
877
- | `workflow_runs.create` | Run a workflow, with any input. The API writes only the fields a caller reads, so it goes with `workflow_runs.read`, and the caller must read the workflow too. |
898
+ | `workflow_runs.create` | Run a workflow, with any input, and [test a custom step](#testing-a-custom-step). The API writes only the fields a caller reads, so it goes with `workflow_runs.read`, and the caller must read the workflow too. |
878
899
  | `workflows.read`, `workflow_versions.read`, `workflow_runs.read`, `workflow_triggers.read` | Read workflows, their versions, runs and triggers, the runs' traces with every step's input and output included. |
879
900
  | `workflow_resolutions.read` | Read who marked which workflow resolved and when. Marking one needs no grant of its own: whoever may change the workflow may. |
880
901
  | `storage_configurations.read` | Let workflows you save use the [storage configurations](#storing-files), and see them. Their keys are never shown. |
881
902
  | `storage_configurations.create`, `storage_configurations.update`, `storage_configurations.delete` | Make, change and delete storage configurations. |
882
903
  | `workflow_custom_steps.read`, `workflow_custom_step_versions.read` | Read the [custom steps](#custom-workflow-steps) and their versions. A workflow's author needs neither to use them: the step types are listed to whoever may read workflows. |
883
904
  | `workflow_custom_steps.create`, `workflow_custom_steps.update`, `workflow_custom_steps.delete` | Make, change and delete custom steps. Each change of a manifest is a new version. |
884
- | `workflow_runners.read`, `workflow_custom_step_jobs.read` | Read the [runners](#runners) and the jobs they claim, the jobs' input and output included. |
905
+ | `workflow_runners.read`, `workflow_custom_step_jobs.read`, `workflow_custom_step_builds.read` | Read the [runners](#runners), the jobs they claim, the jobs' input and output included, and the builds of custom step versions' images. |
885
906
  | `workflow_runners.create`, `workflow_runners.update`, `workflow_runners.delete` | Make, revoke and delete runners. Issuing a runner's registration token needs the right to change it. |
886
907
 
887
908
  ```ts