@protobase/cli 0.100.23 → 0.100.24

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.23";
2
+ var version = "0.100.24";
3
3
  //#endregion
4
4
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.100.23",
3
+ "version": "0.100.24",
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.23",
47
- "@protobase/layout": "0.100.23",
48
- "@protobase/query": "0.100.23",
49
- "@protobase/schema": "0.100.23",
50
- "@protobase/server": "0.100.23",
51
- "@protobase/ui": "0.100.23",
52
- "@protobase/workflows": "0.100.23",
46
+ "@protobase/config": "0.100.24",
47
+ "@protobase/layout": "0.100.24",
48
+ "@protobase/query": "0.100.24",
49
+ "@protobase/schema": "0.100.24",
50
+ "@protobase/server": "0.100.24",
51
+ "@protobase/ui": "0.100.24",
52
+ "@protobase/workflows": "0.100.24",
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",
@@ -89,6 +89,7 @@ Reference:
89
89
  - When letting people without an account create records → read [Public forms](references/reference/forms.md)
90
90
  - When running background jobs → read [Jobs](references/reference/jobs.md)
91
91
  - When a value worked out from other records should stay current by itself, recomputed when what it read changes or a time rule flips → read [Derived values](references/reference/derived.md)
92
+ - When writing a workflow for the app, over MCP or the REST API, from its trigger to going live → read [Writing workflows](workflows.md)
92
93
  - When writing or running workflows, their steps and their runs → read [Workflows](references/reference/workflows.md)
93
94
  - When adding trigger or step types to workflows → read [Workflow plugins](references/reference/workflow-plugins.md)
94
95
  - When sending email → read [Email](references/reference/email.md)
@@ -46,7 +46,7 @@ Graphs of steps the server runs along their edges, written in a language a model
46
46
  - [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.
47
47
  - [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.
48
48
  - [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.
49
- - [Webhook trigger](../reference/workflows.md#appwebhook) (beta): A workflow starts from a signed call to a URL of its own, limited in size and rate.
49
+ - [Webhook trigger](../reference/workflows.md#appwebhook) (beta): A workflow starts from a signed call to a URL of its own, limited in size and rate; one call creates it, publishes it and issues its URL.
50
50
  - [Polling triggers](../reference/workflow-plugins.md#polling-and-webhook) (beta): A workflow starts once for each new item a plugin finds on a schedule, or at each time of a cron with `app:schedule`.
51
51
  - [Incoming Gmail mail](../reference/workflow-plugins.md#incoming-gmail-mail) (beta): A workflow starts once for each new mail on a label of a connected Gmail mailbox that passes optional sender, recipient and subject filters, read with read-only access within about a minute.
52
52
  - [Connected accounts](../reference/workflows.md#connecting-an-account) (beta): People connect their own accounts at other services through OAuth from the account page, see which workflows use each one, and MCP clients list them to bind. A workflow's steps and triggers sign in with one only once its owner turned the workflow on, with tokens encrypted and refreshed. Disconnecting deletes the token and revokes it at a provider that has a revocation endpoint, trying again for a few hours when the provider does not take it, and says which it did.
@@ -110,7 +110,7 @@ In an app with [workflows](workflows.md), the endpoint also offers tools to find
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. |
111
111
  | `get_workflow_run` | A run's status, input, output, error and cause, with its steps in the order they ran, each with its state, scope, try, status, input, output, assigned variables, logs, error and cause; `state` reads one state's steps, a page of 20 by default. |
112
112
  | `list_connections` | The person's own [connected accounts](workflows.md#connecting-an-account), by each connection the app's plugins declare: its key and label, and each account's `id`, scopes and `needs_sign_in`. A definition's `connections` binds an account by its `id`. It returns no token, and no one else's accounts. |
113
- | `create_workflow` | Creates a workflow from its `name`, `description` and `state_machine`, with its `trigger`, `execution_order` and `layout`, none by default, and returns its `id`, `version` and ETag. A state machine from Step Functions [imports](workflows.md#importing-from-step-functions) its HTTP tasks as `app:http` steps, with `connection_headers` naming each connection's header; `update_workflow` and `validate_workflow` import one the same way. |
113
+ | `create_workflow` | Creates a workflow from its `name`, `description` and `state_machine`, with its `trigger`, `execution_order` and `layout`, none by default, and returns its `id`, `version` and ETag. With `publish: true` it publishes version 1 in the same save and answers `enabled_version`, and for a [webhook trigger](workflows.md#appwebhook) also issues its URL, keeping a `webhook_secret` the sender makes, and answers `webhook: { url, secret }`, shown this once. A state machine from Step Functions [imports](workflows.md#importing-from-step-functions) its HTTP tasks as `app:http` steps, with `connection_headers` naming each connection's header; `update_workflow` and `validate_workflow` import one the same way. |
114
114
  | `update_workflow` | Changes a workflow's definition by an `edit` or whole, as `state_machine`, `trigger` and `execution_order`, and its `name`, `description` or `layout`, written whole, and returns its `id`, new `version` and ETag; a change of the layout alone keeps the version. With the `etag` that `get_workflow` gave, it fails when someone changed the workflow since; an edit without one is saved against the version it was applied to. |
115
115
  | `run_workflow` | Starts a run of a workflow's version saved last, or of the `version` it names, with an `input`, and returns its `run_id` and `status`. With `rerun_of`, a failed run's id, it [re-runs](workflows.md#re-running-a-failed-run) that run from its last checkpoint instead, on its input, and with `rerun_from` any ended run that kept its trace from that state; with `replay: true` too, it [replays](workflows.md#replaying-a-run) any ended run of the workflow on its current version, with that run's input, sending none of its outside writes. |
116
116
  | `enable_workflow` | Publishes the saved `version` it names (`enabled: true`), which puts the workflow's trigger on it, or turns the workflow off, and returns its `enabled_version`. A save never goes live by itself. One that uses a [connected account](workflows.md#connecting-an-account) is turned on only by the account's owner in the admin app: the tool answers `own-sign-in-only` and says so. |
@@ -186,7 +186,7 @@ A save checks a trigger's input against its type, and refuses a type the app doe
186
186
 
187
187
  ### Turning a trigger on
188
188
 
189
- A trigger starts runs only while its workflow is published: set `enabled_version` to any saved version through the API, in the admin app or with `enable_workflow` over MCP, and clear it to turn the workflow off. The trigger is registered at once on every server process, with no restart, and its status, `active` or `failing` with its last error, is the workflow's `workflow_triggers` record. A save makes a new version and changes nothing that is live, so a change can be run and tested first; publishing it moves `enabled_version`, and publishing an older version goes back to it. A published version whose trigger has the same type and input as the one before keeps the running trigger as it is, and any other change stops it and starts the new one. Runs in progress stay on their version. A trigger's runs run the enabled version and act as the user who saved it, as any run acts as its version's saver.
189
+ A trigger starts runs only while its workflow is published: set `enabled_version` to any saved version through the API, in the admin app or with `enable_workflow` over MCP, and clear it to turn the workflow off. A create may publish too, in the same write: `POST /api/v1/workflows` with `"enabled_version": 1`, `POST /api/workflows` or `create_workflow` with `"publish": true`, which for a [webhook trigger](#appwebhook) also issue its URL. The trigger is registered at once on every server process, with no restart, and its status, `active` or `failing` with its last error, is the workflow's `workflow_triggers` record. A save makes a new version and changes nothing that is live, so a change can be run and tested first; publishing it moves `enabled_version`, and publishing an older version goes back to it. A published version whose trigger has the same type and input as the one before keeps the running trigger as it is, and any other change stops it and starts the new one. Runs in progress stay on their version. A trigger's runs run the enabled version and act as the user who saved it, as any run acts as its version's saver.
190
190
 
191
191
  ### app:record
192
192
 
@@ -215,6 +215,8 @@ The rate limits count per server process, not across the app's processes, and `h
215
215
 
216
216
  Starts one run for each call of the workflow's own URL that proves it comes from the sender. Issue the URL with `POST /api/workflows/<id>/webhook`, or `new_webhook_url` over MCP: it answers `{ url, secret }` once, and the app keeps only a hash of the URL's key, so it cannot show them again. Send `{ "secret": "<secret>" }` to keep a secret the sender makes itself, such as a Standard Webhooks sender's `whsec_` secret. A new URL replaces the old one, which stops at once. Issuing needs the right to change that workflow in your tenant; anyone else gets 404.
217
217
 
218
+ A workflow goes live in one call, created, published and with its URL issued: `POST /api/workflows` takes the fields `POST /api/v1/workflows` takes, with `"publish": true` and an optional `"webhook_secret"`, the sender's own, and answers `201` with the saved workflow, `enabled_version` 1, and `webhook: { url, secret }`, shown this once (`Cache-Control: no-store`). `create_workflow` over MCP does the same with `publish` and `webhook_secret`. Without `publish` it only saves, and refuses `enabled_version` with `publish-required`. A secret for another trigger or one the auth mode cannot check, or a caller who may create workflows but not change them, is refused before anything is saved; a URL the app could not issue once the workflow was saved leaves it published without one, the answer's `webhook_error` saying why, and `POST /api/workflows/<id>/webhook` issues it. A workflow that [signs in through a connected account](#connecting-an-account) is published only by the account's owner, so `publish` refuses it and saves nothing.
219
+
218
220
  The sender POSTs to the URL. `auth.mode` says how a call proves it is theirs:
219
221
 
220
222
  | `auth.mode` | The call carries |
@@ -0,0 +1,173 @@
1
+ # Writing workflows
2
+
3
+ How to write a Protobase workflow that saves, runs and goes live, over MCP or the REST API. The full language, every
4
+ state, step type and trigger, is in [the workflows reference](references/reference/workflows.md); MCP's tools are in
5
+ [MCP](references/reference/mcp.md#workflows).
6
+
7
+ ## Before writing
8
+
9
+ 1. Call `list_workflow_types` (REST: `GET /api/workflows/types`). It names every step type and trigger this app has,
10
+ built-in, plugin and custom, with their arguments, results and errors. Use only those; a type it does not list is
11
+ refused on save.
12
+ 2. For a records step, find the resource and its fields first (`list_resources`, `describe_resource`). The save does
13
+ not check a resource's name or its fields: `"resource": "contact_messages"` saves and fails when it runs.
14
+ 3. Records steps act as the user who saved the workflow, with that user's roles now; mail always goes from the app's
15
+ own sender.
16
+
17
+ ## Sequence or data order
18
+
19
+ - `"execution_order": "sequence"` (the default) is the standard States Language: `StartAt`, each state's `Next` or
20
+ `End: true`, a `Choice` to branch.
21
+ - `"execution_order": "data"`: no `StartAt`, no `Next`, no `End`, no `Choice`. A state runs once every state it reads
22
+ from has ended, and states that read nothing of each other run at once. Use it when steps are mostly independent,
23
+ or to branch per step with a `Condition`; the editor draws a Condition as nodes (Equals, Not equals, Greater, Less,
24
+ And, Or, Not), any other expression as one Expression node.
25
+
26
+ Data order's rules, each checked against the save or a run:
27
+
28
+ - A step's result reaches later steps only through a variable it assigns: `"Assign": { "contact": "{% $states.result %}" }`,
29
+ read as `$contact.id`. Reading `$contact` with no state assigning it is refused on save, naming the state and field.
30
+ - `$states.context.Steps.<State>` is that state's `{ Status, Error, Cause }`, `Status` one of `SUCCEEDED`, `FAILED`,
31
+ `TIMED_OUT`, `ABORTED` and `SKIPPED`. It never holds the result: `$states.context.Steps.Save.result` saves, and is
32
+ empty at run time.
33
+ - `Condition` is an expression; when it is false the state is skipped. A state reading one that did not succeed is
34
+ skipped too, unless its Condition reads that state's Status: `{% $states.context.Steps.Save.Status = 'SUCCEEDED' %}`.
35
+ - Each variable is assigned by one state. An uncaught failure fails the run at once.
36
+ - A skipped state is not in the run's trace; read `$states.context.Steps.<State>.Status` or the run's graph instead.
37
+
38
+ ## Where the trigger's input arrives
39
+
40
+ Every state reads the run's input as `$states.context.Execution.Input`:
41
+
42
+ | Trigger | Input |
43
+ | --- | --- |
44
+ | `{ "manual": {} }` | what the start passed, such as `run_workflow`'s `input` |
45
+ | `app:webhook` | `{ method, query, headers, body, received_at }`: a form's fields are `...Input.body.<field>` |
46
+ | `app:record` | `{ resource, key, record }`: `...Input.record.<field>`; the resource must declare events |
47
+ | `app:schedule` | `{ scheduled_at }` |
48
+
49
+ ## From a definition to a live workflow
50
+
51
+ | Step | MCP | REST |
52
+ | --- | --- | --- |
53
+ | Check without saving | `validate_workflow` | (a create that does not fit saves nothing) |
54
+ | Save version 1 | `create_workflow` | `POST /api/v1/workflows` `{ name, description, trigger, execution_order, state_machine }` |
55
+ | Try it | `run_workflow` with an input shaped as the trigger gives it, such as `{ "body": { ... } }` for a webhook | `POST /api/v1/workflow_runs` `{ workflow_id, input }` |
56
+ | Read the run | `get_workflow_run`, again until `succeeded` or `failed` | `GET /api/v1/workflow_runs/<id>`, steps at `GET /api/workflows/runs/<id>/trace` |
57
+ | Fix | `update_workflow` (a JSON Merge Patch in `edit`), then run again | `PATCH /api/v1/workflows/<id>` with `If-Match` |
58
+ | Publish | `enable_workflow` `{ id, enabled: true, version }` | `PATCH /api/v1/workflows/<id>` `{ "enabled_version": 1 }` with `If-Match`, or `"enabled_version": 1` in the create itself |
59
+ | Webhook URL | `new_webhook_url` `{ id, secret? }` | `POST /api/workflows/<id>/webhook` `{ "secret": "..." }` |
60
+ | All at once | `create_workflow` with `"publish": true` (and `webhook_secret`) | `POST /api/workflows` with the create's fields and `"publish": true` (and `webhook_secret`) |
61
+
62
+ Once a definition validates and a test run did what it should, one call makes a workflow live: created, version 1
63
+ published, and for a webhook trigger its URL and secret in the answer, `webhook: { url, secret }`, shown once.
64
+
65
+ A REST `PATCH` needs `If-Match`: the ETag the record was read with, or `*`; without it the answer is 428. A save
66
+ never goes live: a trigger starts runs only of the published version. A refused save answers problems, each
67
+ naming the state, the field and what was expected; fix those and save again. The webhook URL and secret are shown once.
68
+ A test run does what its steps do: it sends the mail and writes the records.
69
+
70
+ ## Examples
71
+
72
+ A website contact form, in data order: the sender becomes a lead contact with the message as a note, sales or support
73
+ is mailed by the topic, and the sender gets an auto-reply when the address looks valid. The routing Conditions show as
74
+ Equals and Not equals nodes; the address check, a regular expression, as an Expression node.
75
+
76
+ ```json
77
+ {
78
+ "name": "Contact form",
79
+ "trigger": { "app:webhook": { "auth": { "mode": "bearer" }, "per_minute": 30 } },
80
+ "execution_order": "data",
81
+ "state_machine": {
82
+ "QueryLanguage": "JSONata",
83
+ "States": {
84
+ "SaveContact": {
85
+ "Type": "Task",
86
+ "Resource": "app:records.create",
87
+ "Arguments": { "resource": "contacts", "data": { "name": "{% $states.context.Execution.Input.body.name %}", "email": "{% $states.context.Execution.Input.body.email %}", "status": "lead" } },
88
+ "Assign": { "contact": "{% $states.result %}" }
89
+ },
90
+ "SaveMessage": {
91
+ "Type": "Task",
92
+ "Resource": "app:records.create",
93
+ "Arguments": { "resource": "notes", "data": { "contact_id": "{% $contact.id %}", "text": "{% '[' & $states.context.Execution.Input.body.topic & '] ' & $states.context.Execution.Input.body.message %}" } },
94
+ "Assign": { "note": "{% $states.result %}" }
95
+ },
96
+ "NotifySales": {
97
+ "Type": "Task",
98
+ "Resource": "app:mail.send",
99
+ "Condition": "{% $states.context.Execution.Input.body.topic = 'sales' %}",
100
+ "Arguments": { "to": "sales@example.com", "subject": "{% 'New sales enquiry from ' & $contact.name %}", "text": "{% $contact.name & ' <' & $contact.email & '> wrote:\n\n' & $states.context.Execution.Input.body.message & '\n\nNote ' & $note.id %}" }
101
+ },
102
+ "NotifySupport": {
103
+ "Type": "Task",
104
+ "Resource": "app:mail.send",
105
+ "Condition": "{% $states.context.Execution.Input.body.topic != 'sales' %}",
106
+ "Arguments": { "to": "support@example.com", "subject": "{% 'New support request from ' & $contact.name %}", "text": "{% $contact.name & ' <' & $contact.email & '> wrote:\n\n' & $states.context.Execution.Input.body.message & '\n\nNote ' & $note.id %}" }
107
+ },
108
+ "AutoReply": {
109
+ "Type": "Task",
110
+ "Resource": "app:mail.send",
111
+ "Condition": "{% $states.context.Steps.SaveMessage.Status = 'SUCCEEDED' and $type($states.context.Execution.Input.body.email) = 'string' and $contains($states.context.Execution.Input.body.email, /^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$/) %}",
112
+ "Arguments": { "to": "{% $states.context.Execution.Input.body.email %}", "subject": "We received your message", "text": "{% 'Hi ' & $states.context.Execution.Input.body.name & ',\n\nThanks for getting in touch; we will answer within one working day.' %}" }
113
+ }
114
+ }
115
+ }
116
+ }
117
+ ```
118
+
119
+ Send it to `POST /api/workflows` with `"publish": true` (or `create_workflow` with `publish: true`) and it is live: the
120
+ answer's `webhook.url` and `webhook.secret` are the form's. The form's server POSTs `{ "name", "email", "topic", "message" }` to it with
121
+ `Authorization: Bearer <secret>` and gets `202 { run_id }`.
122
+
123
+ A welcome mail to each new contact, in sequence, from a record trigger:
124
+
125
+ ```json
126
+ {
127
+ "name": "Welcome new contacts",
128
+ "trigger": { "app:record": { "resource": "contacts" } },
129
+ "execution_order": "sequence",
130
+ "state_machine": {
131
+ "QueryLanguage": "JSONata",
132
+ "StartAt": "HasEmail",
133
+ "States": {
134
+ "HasEmail": { "Type": "Choice", "Choices": [{ "Condition": "{% $type($states.context.Execution.Input.record.email) = 'string' %}", "Next": "Welcome" }], "Default": "NoEmail" },
135
+ "Welcome": {
136
+ "Type": "Task",
137
+ "Resource": "app:mail.send",
138
+ "Arguments": { "to": "{% $states.context.Execution.Input.record.email %}", "subject": "Welcome", "text": "{% 'Hi ' & $states.context.Execution.Input.record.name & ', welcome aboard.' %}" },
139
+ "Retry": [{ "ErrorEquals": ["States.ALL"], "IntervalSeconds": 60, "MaxAttempts": 3 }],
140
+ "End": true
141
+ },
142
+ "NoEmail": { "Type": "Succeed" }
143
+ }
144
+ }
145
+ }
146
+ ```
147
+
148
+ A weekday digest of new leads, in data order, mailed only when there are any:
149
+
150
+ ```json
151
+ {
152
+ "name": "Daily leads",
153
+ "trigger": { "app:schedule": { "cron": "0 8 * * 1-5", "timezone": "Europe/Amsterdam" } },
154
+ "execution_order": "data",
155
+ "state_machine": {
156
+ "QueryLanguage": "JSONata",
157
+ "States": {
158
+ "Leads": {
159
+ "Type": "Task",
160
+ "Resource": "app:records.list",
161
+ "Arguments": { "resource": "contacts", "filter": "status = 'lead'", "order_by": "created_at desc", "limit": 50 },
162
+ "Assign": { "leads": "{% $states.result.records %}" }
163
+ },
164
+ "Digest": {
165
+ "Type": "Task",
166
+ "Resource": "app:mail.send",
167
+ "Condition": "{% $count($leads) > 0 %}",
168
+ "Arguments": { "to": "sales@example.com", "subject": "{% $string($count($leads)) & ' open leads' %}", "text": "{% $join($leads.(name & ' <' & email & '>'), '\n') %}" }
169
+ }
170
+ }
171
+ }
172
+ }
173
+ ```