@protobase/cli 0.96.0 → 0.96.1

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.96.0";
2
+ var version = "0.96.1";
3
3
  //#endregion
4
4
  export { version };
@@ -45,7 +45,25 @@ const chartShapes = (page, node, model) => {
45
45
  }
46
46
  }]];
47
47
  };
48
- /** The reads of a composed page: each block that lists records, with its filter and sort, and each chart's grouping. */
48
+ const callShapes = (page, node, models) => {
49
+ const calls = node.props.calls;
50
+ const model = models[calls.resource];
51
+ if (!model) return [];
52
+ const filter = configFilter(model, calls.filter);
53
+ const sort = configSort(model, threadSort(calls.time));
54
+ const params = [...calls.filter?.trim() ? [`filter=${calls.filter}`] : [], ...sort ? [`order_by=${sortText(sort)}`] : []];
55
+ const named = title(node);
56
+ return [{
57
+ resource: model.name,
58
+ request: `GET /${model.name}${params.length > 0 ? `?${params.join("&")}` : ""}`,
59
+ from: `page "${page.name}", <Thread${named ? ` "${named}"` : ""}> calls`,
60
+ query: {
61
+ ...filter && { filter },
62
+ ...sort && { sort }
63
+ }
64
+ }];
65
+ };
66
+ /** The reads of a composed page: each block that lists records, with its filter and sort, a thread's tool calls, and each chart's grouping. */
49
67
  const pageShapes = (page, models, views) => {
50
68
  const shapes = [];
51
69
  walkTree(page.tree, (node) => {
@@ -69,6 +87,7 @@ const pageShapes = (page, models, views) => {
69
87
  ...sort && { sort }
70
88
  }
71
89
  });
90
+ if (node.type === "Thread" && node.props.calls !== void 0) shapes.push(...callShapes(page, node, models));
72
91
  });
73
92
  return shapes;
74
93
  };
@@ -129,19 +129,23 @@ const recordChartShapes = (item, owner, models) => {
129
129
  }];
130
130
  };
131
131
  const threadShapes = (item, owner, models) => {
132
- const target = models[item.resource];
133
- const field = target?.fields[item.field];
134
- if (!target || !field || !target.fields[item.time]) return [];
135
- const sort = configSort(target, threadSort(item.time));
136
- return [{
137
- resource: target.name,
138
- request: request(target.name, `${field.name} = …`, sort),
139
- from: `thread "${item.title}" on the ${owner} record page`,
140
- query: {
141
- filter: compare(field),
142
- ...sort && { sort }
143
- }
144
- }];
132
+ const from = `thread "${item.title}" on the ${owner} record page`;
133
+ const latest = (source) => {
134
+ const target = models[source.resource];
135
+ const field = target?.fields[source.field];
136
+ if (!target || !field || !target.fields[source.time]) return [];
137
+ const sort = configSort(target, threadSort(source.time));
138
+ return [{
139
+ resource: target.name,
140
+ request: request(target.name, `${field.name} = …`, sort),
141
+ from,
142
+ query: {
143
+ filter: compare(field),
144
+ ...sort && { sort }
145
+ }
146
+ }];
147
+ };
148
+ return [...latest(item), ...item.calls ? latest(item.calls) : []];
145
149
  };
146
150
  const displayShapes = (model, view, models) => (view.list?.displays ?? []).flatMap((display) => {
147
151
  if (display.kind === "map") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.96.0",
3
+ "version": "0.96.1",
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.96.0",
47
- "@protobase/layout": "0.96.0",
48
- "@protobase/query": "0.96.0",
49
- "@protobase/schema": "0.96.0",
50
- "@protobase/server": "0.96.0",
51
- "@protobase/ui": "0.96.0",
52
- "@protobase/workflows": "0.96.0",
46
+ "@protobase/config": "0.96.1",
47
+ "@protobase/layout": "0.96.1",
48
+ "@protobase/query": "0.96.1",
49
+ "@protobase/schema": "0.96.1",
50
+ "@protobase/server": "0.96.1",
51
+ "@protobase/ui": "0.96.1",
52
+ "@protobase/workflows": "0.96.1",
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",
@@ -9,6 +9,7 @@ Pages of your own, built from blocks in a JSX layout.
9
9
  - [Conditions](../reference/layouts.md#conditions): Part of a page shows only while a condition on a record or a count holds.
10
10
  - [App addresses](../reference/layouts.md#addresses): Links to lists, records, create forms and pages are typed addresses that can carry filters and prefilled values.
11
11
  - [Component fallbacks](../reference/custom-components.md#fallbacks): A custom component declares what a client that cannot draw it shows instead, or nothing, and the web shows it too when the component is missing or throws.
12
+ - [Text form](../reference/layouts.md#text-form): Every layout block renders to Markdown text through one shared function, built up from its children, as the last-resort fallback and for MCP clients and LLMs.
12
13
  - [Per-user pages](../reference/layouts.md#access): Each user gets the page without the parts, fields and actions they cannot use.
13
14
  - [Layout blocks](../reference/blocks.md#layout): Pages, responsive grids, cards and links.
14
15
  - [Tailwind classes](../reference/layouts.md#tailwind-classes) (experimental): Layouts can carry Tailwind classes, on plain elements and on blocks, for pages too custom for blocks.
@@ -20,6 +21,7 @@ Pages of your own, built from blocks in a JSX layout.
20
21
  - [Image block](../reference/blocks.md#image): A picture one of the app's API functions draws for the reader, such as a system map, at the size and theme the client asks, refreshed on a timer; a client that draws no images shows its alt text, or nothing.
21
22
  - [Chart block](../reference/blocks.md#chart): Counts, sums or averages by value or by date, as bars, lines or a donut, and over time split by a second field.
22
23
  - [Conversations](../reference/blocks.md#conversation): A chat declared in the layout: a thread of a resource's messages under each sender's name and time, following new ones as they arrive, and a box that sends one as the signed-in user.
24
+ - [Tool calls in threads](../reference/blocks.md#tool-calls): Conversation threads show tool calls in time order, with a status and an expandable input and result.
23
25
  - [Buttons and forms](../reference/blocks.md#behaviour): Buttons for named actions, and create or edit forms in a dialog.
24
26
  - [Settings block](../reference/blocks.md#settings): Each person's own settings from a resource with one record per person, saved as they change, with defaults until the first save.
25
27
  - [Users block](../reference/blocks.md#users): User management on any page: find users, set roles, block them and invite by email.
@@ -98,7 +98,7 @@ bun install
98
98
 
99
99
  ## Run the ERP example
100
100
 
101
- `tests/apps/erp` is a sample ERP on a real Postgres database, seeded with three years of history. It needs Docker for the database: `bun run db:up` starts the Postgres container and gives each example its database and a `.env` from its `.env.example`. The databases listen on `127.0.0.1` only, so on Docker Engine 28.0.0 or later other machines on the network cannot reach them, unless the daemon's `allow-direct-routing` option, off by default, lets them reach containers by their own address; an older Docker Engine lets hosts on the same local network segment reach them, so it needs a firewall that blocks them. On Linux with firewalld, Docker Engine 28.2.0 to 28.3.2 lets other hosts reach them again after a firewalld reload, so it needs that firewall too, or an upgrade to 28.3.3 or later. A checkout or worktree on an older base publishes them on every interface again, so rebase it onto `main` before any `docker compose up` or `db:up`.
101
+ `tests/apps/erp` is a sample ERP on a real Postgres database, seeded with three years of history. `bun run db:up` starts the Postgres container and gives each example its database and a `.env` from its `.env.example`. Without Docker, `POSTGRES_RUNNER=local` in the repository's `.env` runs the machine's own Postgres 18 and PgBouncer as plain processes on the same ports instead, with their data in `.protobase/postgres`; `POSTGRES_BIN` names the folder of `initdb` and `pg_ctl` when they are not on PATH. Supabase's Postgres, which `bun run test:record` needs, runs only in Docker. The databases listen on `127.0.0.1` only, so on Docker Engine 28.0.0 or later other machines on the network cannot reach them, unless the daemon's `allow-direct-routing` option, off by default, lets them reach containers by their own address; an older Docker Engine lets hosts on the same local network segment reach them, so it needs a firewall that blocks them. On Linux with firewalld, Docker Engine 28.2.0 to 28.3.2 lets other hosts reach them again after a firewalld reload, so it needs that firewall too, or an upgrade to 28.3.3 or later. A checkout or worktree on an older base publishes them on every interface again, so rebase it onto `main` before any `docker compose up` or `db:up`.
102
102
 
103
103
  ```sh
104
104
  bun run db:up && bun run --cwd tests/apps/erp db:migrate && bun run --cwd tests/apps/erp db:seed --scale small # the ERP's tables and Better Auth's
@@ -131,7 +131,7 @@ bun run --cwd tests/apps/property-portal dev # http://localhost:517
131
131
 
132
132
  | Command | Purpose |
133
133
  | --- | --- |
134
- | `bun run db:up` / `bun run db:down` | start or stop the Postgres container; `db:up` also creates the examples' databases and `.env` files |
134
+ | `bun run db:up` / `bun run db:down` | start or stop the Postgres container, or with `POSTGRES_RUNNER=local` in `.env` the local Postgres and PgBouncer processes; `db:up` also creates the examples' databases and `.env` files |
135
135
  | `bun run test` | the unit tests and the snapshot tests in `packages/*/tests/` and `tests/` (Vitest projects `unit*` and `snapshot*`): no Postgres server, subprocess or network. A snapshot test replays the SQL recorded for it from Postgres in `<test>.sql.json` |
136
136
  | `bun run test:record` | runs the snapshot tests on the Postgres container instead and writes their recordings, after building their templates (`bun run test:db snapshots`); run it when a change makes a snapshot test fail with `stale snapshot` |
137
137
  | `bun run test:unit` | only the unit tests, next to the code (Vitest projects `unit`, whose files share their modules, and `unit-isolated`, for those that mock a module or change a global), fully parallel; starting a Postgres client there throws |
@@ -501,11 +501,40 @@ The latest messages that match `filter`, oldest first, each under its sender's n
501
501
  | `text` | The message; shown rendered when the message resource's view marks it [`.markdown()`](ui-config.md#names-and-columns). Required. |
502
502
  | `status` | A short line under each message, such as whether it was delivered: a text or enum field, shown with its view's value labels, in red for a value it colours `red`; a message without a value shows none. Left out for a user who cannot read it. Experimental, see [Message status and a working indicator](ui-config.md#message-status-and-a-working-indicator). |
503
503
  | `working` | A condition on the record around the thread, as [`Show`](#show) takes, such as `state = 'working'`: while it holds, the thread ends in a working indicator. Left out for a user who cannot read what it names. Experimental. |
504
- | `limit` | How many of the latest it shows at first, and how many each **Load earlier messages** adds: 1 to 500, the API's largest page; default 50. |
504
+ | `calls` | Tool calls shown between the messages in time order, from a resource of their own; see [Tool calls](#tool-calls). Left out for a user who cannot read their name, time or status. |
505
+ | `limit` | How many of the latest messages it shows at first, and of the latest tool calls, and how many each **Load earlier messages** adds: 1 to 500, the API's largest page; default 50. |
505
506
  | `title`, `description`, `actions` | The heading; no card is drawn around the thread, so it can sit in a `Card` with its composer. |
506
507
  | `empty` | Text while there are no messages. |
507
508
  | `span` | Width in a grid. |
508
509
 
510
+ #### Tool calls
511
+
512
+ A thread with an assistant in it can show what the assistant did between its messages: each tool call it made, in time order, with the tool's name and its status, which opens to what the tool was called with, what it gave back and why it failed. `calls` names the resource that holds the calls and the fields the thread reads of each:
513
+
514
+ ```tsx
515
+ <Thread
516
+ resource="messages"
517
+ filter="chat_id = 1"
518
+ sender="author_id"
519
+ time="sent_at"
520
+ text="body"
521
+ calls={{ resource: 'tool_calls', filter: 'chat_id = 1', name: 'tool', time: 'called_at', status: 'state', input: 'input', result: 'output', error: 'failure' }}
522
+ />
523
+ ```
524
+
525
+ | `calls` key | |
526
+ | --- | --- |
527
+ | `resource`, `filter` | Which calls. `resource` is required. |
528
+ | `name` | The tool's name: a text field. Required. |
529
+ | `time` | When it was called: a date or timestamp field the API can sort by, which places it among the messages. A call at the same time as a message shows after it. Required. |
530
+ | `status` | A text or enum field: `done` shows a check, `running` a spinner and `error` an alert icon in red, each beside the value's label from the view; any other value shows its label without a mark, and a call without a value shows none. Required. |
531
+ | `input`, `result` | What the tool was called with and what it gave back, shown as indented JSON; a text that holds JSON shows as the value it holds. |
532
+ | `error` | Why the call failed: a text field. |
533
+
534
+ Each call is a line under the messages before it, closed at first; a call with an input, result or error opens and closes with a click on its line. The thread reads the latest calls as it reads the latest messages, `limit` at a time, newest first by `time`, so that read needs an index on the filter's field and `time`, which [`protobase doctor`](cli.md#doctor) checks, and **Load earlier messages** loads the earlier calls with the earlier messages, keeping them in time order. A user who cannot read the calls' `name`, `time` or `status` gets the thread without its calls, and one who cannot read `input`, `result` or `error` gets the calls without that part.
535
+
536
+ Clients that cannot draw the calls get their simpler forms from `@protobase/layout`: `threadLines(items)` gives one short line per item, a message as its sender and first line and a call as its name and status, and `threadMarkdown(items, words)` gives the thread as Markdown, for clients that read text, such as an MCP client or a language model: each message under its sender in bold, each call as its name and status with its input and result as JSON and its error in fenced code blocks. <gap>A watch cannot show a thread's tool calls as lines because drawing a thread on a watch is not implemented.</gap> <gap>An MCP client cannot read a thread as Markdown because serving a page's blocks as text is not implemented.</gap>
537
+
509
538
  ### Composer
510
539
 
511
540
  A text box that grows with its text: Enter or the send button creates a record of `resource` with the text in `field` and the `values`, and Shift+Enter starts a new line. The text stays in the box until the server took it, so a message it refuses is still there to send again, under the reason. It is not shown to a user who may not create a record of `resource` or write its fields.
@@ -53,6 +53,46 @@ A custom component declared with a [fallback](custom-components.md#fallbacks) ca
53
53
 
54
54
  A client that cannot draw the component, such as one without React, draws the fallback instead, and the checks read it like the rest of the tree.
55
55
 
56
+ ## Text form
57
+
58
+ Every layout block renders to Markdown text through one shared function, `renderText`, built up from its children. It is the last-resort form of a page, for a client that draws no blocks and for MCP clients and LLMs. Each element's text is made from its children's text, already rendered: a container such as `Grid`, `Box` or `Tabs` reads as its children in order with a blank line between them, and text and links run on in one line as they do on the web.
59
+
60
+ ```tsx
61
+ import { Field, Page, renderText } from '@protobase/layout'
62
+
63
+ renderText(<Page title="Order"><Field name="status" /></Page>, {
64
+ record: { status: 'in_progress' },
65
+ fields: { status: { label: 'Status', valueLabels: { in_progress: 'In progress' } } },
66
+ })
67
+ // # Order
68
+ //
69
+ // **Status**: In progress
70
+ ```
71
+
72
+ | Option | |
73
+ | --- | --- |
74
+ | `record` | The record around the tree. `Field`, `Stat field`, `Progress`, `Show` conditions and the `{field}`s of addresses read it, through relations as nested objects (`plan.name`); a count a condition names, such as `billing_profiles.count`, is a key of its own. Without it, a field reads as its label alone, a `Show` reads as all it holds, and addresses keep their `{field}`s. |
75
+ | `fields` | Per field path, its `label` and the `valueLabels` its enum values read as; a field without a label reads under its path. |
76
+ | `basePath` | What links start with, such as `https://example.com/admin`. |
77
+ | `forms` | Text forms by block type, over the built-in ones. |
78
+
79
+ A heading reads at its level: a `Page` title as `#`, a `Tab` label as `##`, and the title of a `Card` and of a data block as `###`, the data block's linked to its records' list as it filters them. A field's value reads as its enum label, a list as its items, and JSON as a code block.
80
+
81
+ A text form of your own is a function from its element and its children's text to Markdown. It can use the default as it is (`childrenText`), wrap a built-in form from `textForms`, or rework the children's text, such as a horizontal line between them:
82
+
83
+ ```ts
84
+ import { childrenText, markdown, renderText, textForms, type TextForm } from '@protobase/layout'
85
+
86
+ const ruled: TextForm = ({ children }) => markdown.blocks(children, '\n\n---\n\n')
87
+ const noted: TextForm = (context) => `${textForms.Card!(context)}\n\nUpdated hourly.`
88
+
89
+ renderText(tree, { forms: { Grid: ruled, Card: noted, SeatChart: childrenText } })
90
+ ```
91
+
92
+ A custom component reads as its [fallback](custom-components.md#fallbacks) when it declares one, and otherwise as what it holds, unless `forms` names it.
93
+
94
+ <gap>A data block's text form cannot list its records, such as a table's rows, because reading records for the text form is not implemented.</gap> <gap>A field's text form cannot apply its `format`, such as a relative time, because formatting in the text form is not implemented.</gap> <gap>MCP clients cannot read a page's text form because a tool that serves it is not implemented.</gap>
95
+
56
96
  ## What a layout may hold
57
97
 
58
98
  A prop is a string, a finite number, a boolean, `null`, or an array or plain object of those (elements included). It is JSON in the end, so the rules are checked twice:
@@ -1204,6 +1204,7 @@ The thread shows the latest messages oldest first, each under its sender's name
1204
1204
  | `text` | The message, a text field. Required. |
1205
1205
  | `status` | A short line under each message, such as whether it was delivered: a text or enum field. See [Message status and a working indicator](#message-status-and-a-working-indicator). |
1206
1206
  | `working` | A condition on this record, such as `state = 'working'`, while which the thread ends in a working indicator. |
1207
+ | `calls` | Tool calls shown between the messages in time order: the `resource` that holds them, the filterable relation `field` of it that holds this record's key, and the fields the [Thread block's `calls`](blocks.md#tool-calls) names, `name`, `time`, `status`, `input`, `result` and `error`. A `field` that is no relation to this resource, a field the calls do not have or of the wrong type, or a sensitive one stops the server at startup. |
1207
1208
  | `limit` | How many of the latest it shows at first, and how many each **Load earlier messages** adds: 1 to 500, the API's largest page; default 50. |
1208
1209
  | `empty` | Text while there are no messages. |
1209
1210
  | `help`, `when` | A line under the title, and whether it shows on the form, the read view or both. |
@@ -1226,7 +1227,7 @@ view<typeof tasks>('tasks').layout((r) => [
1226
1227
  ])
1227
1228
  ```
1228
1229
 
1229
- The messages are read with `field = <this record's key>` as the filter, newest first by `time`, so the user's access applies as on the list. That read needs an index on `(field, time)`, such as `create index on task_messages (task_id, sent_at)`, which [`protobase doctor`](cli.md#doctor) checks. A user who cannot read `field`, `sender`, `time` or `text` gets no thread, and one who may not create a message with `field` and `text` gets no composer. A `field` that is no relation to this resource, a `time` that is no date or timestamp the API can sort by, a `sender` that is no relation or text field, a thread `text` that is no text field, a sensitive field in the thread, or a composer `text` that is no writable text field stops the server at startup. As with a related section, the record page's count of the records that point at it leaves out the messages its thread shows.
1230
+ The messages are read with `field = <this record's key>` as the filter, newest first by `time`, so the user's access applies as on the list. That read needs an index on `(field, time)`, such as `create index on task_messages (task_id, sent_at)`, which [`protobase doctor`](cli.md#doctor) checks. Tool calls are read the same way, by their own `field` and `time`. A user who cannot read `field`, `sender`, `time` or `text` gets no thread, and one who may not create a message with `field` and `text` gets no composer. A `field` that is no relation to this resource, a `time` that is no date or timestamp the API can sort by, a `sender` that is no relation or text field, a thread `text` that is no text field, a sensitive field in the thread, or a composer `text` that is no writable text field stops the server at startup. As with a related section, the record page's count of the records that point at it leaves out the messages and tool calls its thread shows.
1230
1231
 
1231
1232
  #### Message status and a working indicator
1232
1233