@zenera/cli 1.3.21 → 1.3.23
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.
- package/package.json +6 -6
- package/templates/editor/.github/skills/zen-review/scripts/check-paths.sh +1 -1
- package/templates/project/agents/skills/html-page/SKILL.md +96 -51
- package/templates/project/agents/skills/html-page/assets/app/api/items.api.py +3 -2
- package/templates/project/agents/skills/html-page/assets/app/app.tsx +140 -0
- package/templates/project/agents/skills/html-page/assets/dashboard.tsx +162 -0
- package/templates/project/agents/skills/html-page/kit/Chart.tsx +79 -0
- package/templates/project/agents/skills/html-page/kit/Table.tsx +89 -0
- package/templates/project/agents/skills/html-page/kit/api.ts +93 -0
- package/templates/project/agents/skills/html-page/kit/components.tsx +266 -0
- package/templates/project/agents/skills/html-page/kit/format.ts +60 -0
- package/templates/project/agents/skills/html-page/kit/hooks.ts +159 -0
- package/templates/project/agents/skills/html-page/kit/index.ts +35 -0
- package/templates/project/agents/skills/html-page/kit/modules.d.ts +37 -0
- package/templates/project/agents/skills/html-page/kit/mount.tsx +62 -0
- package/templates/project/agents/skills/html-page/kit/shell.html +19 -0
- package/templates/project/agents/skills/html-page/kit/theme.css +326 -0
- package/templates/project/agents/skills/html-page/references/charts-and-tables.md +105 -53
- package/templates/project/agents/skills/html-page/references/python-functions.md +40 -29
- package/templates/project/agents/skills/html-page/scripts/build.ts +825 -0
- package/templates/project/agents/skills/html-page/assets/api.js +0 -87
- package/templates/project/agents/skills/html-page/assets/app/index.html +0 -278
- package/templates/project/agents/skills/html-page/assets/dashboard.html +0 -423
|
@@ -4,20 +4,24 @@ For a page that shows live data or saves changes. The core rules (where it
|
|
|
4
4
|
goes, the sandbox, adaptive layout, checks) are in `SKILL.md`.
|
|
5
5
|
|
|
6
6
|
Every **public function** in an `*.api.py` beside the page can be called from
|
|
7
|
-
the page
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
```
|
|
11
|
-
|
|
7
|
+
the page by name, with its arguments as an object, and returns JSON. No
|
|
8
|
+
server code, routes or framework: write plain Python functions.
|
|
9
|
+
|
|
10
|
+
```tsx
|
|
11
|
+
interface ItemsApi {
|
|
12
|
+
list_items(args: { show: string }): Promise<Item[]>; // list_items(show: str)
|
|
13
|
+
add_item(args: { title: string }): Promise<Item>; // add_item(title: str)
|
|
14
|
+
}
|
|
15
|
+
const items = api<ItemsApi>('api/items'); // api/items.api.py
|
|
12
16
|
const list = await items.list_items({ show: 'open' }); // list_items(show="open")
|
|
13
17
|
await items.add_item({ title: 'Milk' }); // add_item(title="Milk")
|
|
14
18
|
```
|
|
15
19
|
|
|
16
20
|
The app template (`/skills/html-page/assets/app`) is a working example: a
|
|
17
21
|
list in SQLite with add, check off, filter and delete. Rename
|
|
18
|
-
`api/items.api.py` to what it holds
|
|
19
|
-
(`orders.api.py`, `customers.api.py`),
|
|
20
|
-
beside them.
|
|
22
|
+
`api/items.api.py` to what it holds, and its interface in `app.tsx` with it;
|
|
23
|
+
one `*.api.py` per area of the app (`orders.api.py`, `customers.api.py`),
|
|
24
|
+
shared helpers in plain `.py` files beside them.
|
|
21
25
|
|
|
22
26
|
## Writing the functions
|
|
23
27
|
|
|
@@ -77,6 +81,9 @@ The rules:
|
|
|
77
81
|
fresh copy starts by itself.
|
|
78
82
|
- `data_path("exports/report.csv")`: a path in the same folder, for other
|
|
79
83
|
files it keeps.
|
|
84
|
+
- A page published with the project (under `/assets`, read-only) keeps each
|
|
85
|
+
user's data in their own workspace instead; `connect()` and `data_path()`
|
|
86
|
+
find it there by themselves.
|
|
80
87
|
- A file the page should download or show (a CSV export, a chart image):
|
|
81
88
|
write it next to the page instead, e.g. `../exports/orders.csv` from
|
|
82
89
|
`api/`, and return the relative name; the page links to it.
|
|
@@ -144,8 +151,8 @@ def delete_note(id: int):
|
|
|
144
151
|
- Store `.id` (an `owner` column), never the email or name: those can change.
|
|
145
152
|
- Check permissions in the function (`HttpError(403, ...)`); hiding a button
|
|
146
153
|
in the page is not a check.
|
|
147
|
-
- In the page: `const me =
|
|
148
|
-
`me.name` in the header, and hide what `me.role` may not do.
|
|
154
|
+
- In the page: `const me = useCall(() => users.me(), [])`, then show
|
|
155
|
+
`me.data?.name` in the header, and hide what `me.data?.role` may not do.
|
|
149
156
|
- When it matters: a page in a chat's workspace already belongs to one user
|
|
150
157
|
(each has their own copy and `.data`). Identity matters for data shared
|
|
151
158
|
between users: an external database, or a page published in the project's
|
|
@@ -156,26 +163,30 @@ def delete_note(id: int):
|
|
|
156
163
|
|
|
157
164
|
## Calling them from the page
|
|
158
165
|
|
|
159
|
-
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
- `
|
|
163
|
-
object
|
|
164
|
-
|
|
166
|
+
- `api<FileApi>('<path to the file, relative to the page, without .api.py>')`
|
|
167
|
+
from `@page/kit` gives an object whose methods are the file's functions:
|
|
168
|
+
`api<OrdersApi>('api/orders').set_status({ id: 7, status: 'paid' })`.
|
|
169
|
+
- Declare `FileApi` beside it: one method per function the page calls, its
|
|
170
|
+
arguments as one object named like the Python parameters, and what it
|
|
171
|
+
returns. Keep it in step with the Python - the build checks the page
|
|
172
|
+
against it, and that the `.api.py` exists.
|
|
165
173
|
- Always pass **one object** of named arguments (or nothing). Each call
|
|
166
174
|
returns a promise of what the function returned.
|
|
167
175
|
- A failure rejects with an `ApiError`: `.message` is the `HttpError`
|
|
168
|
-
message, `.status` the HTTP status (0: not reachable).
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
|
178
|
-
|
|
|
176
|
+
message, `.status` the HTTP status (0: not reachable).
|
|
177
|
+
- Reading: `useCall(() => orders.list_orders({ status }), [status])` calls
|
|
178
|
+
it when the page opens and when `status` changes, with `.data`, `.error`,
|
|
179
|
+
`.loading` and `.reload()`.
|
|
180
|
+
- Changing: `useAction((id: number) => orders.set_status({ id, status: 'paid' }), list.reload)`
|
|
181
|
+
runs the call, then loads the list again so the page shows what is really
|
|
182
|
+
saved; disable the button while `.busy`, and show `.error` in an
|
|
183
|
+
`ErrorBox`. The app template does all of this.
|
|
184
|
+
|
|
185
|
+
| TypeScript | Request | Python |
|
|
186
|
+
| ------------------------------------------------ | ----------------------------- | ---------------------------- |
|
|
187
|
+
| `api<OrdersApi>('api/orders').list_orders()` | `POST api/orders/list_orders` | `list_orders()` |
|
|
188
|
+
| `api<OrdersApi>('api/orders').set_status({...})` | `POST api/orders/set_status` | `set_status(id=7, ...)` |
|
|
189
|
+
| `api<UsersApi>('../api/users').me()` (`report/`) | `POST ../api/users/me` | `me()` in `api/users.api.py` |
|
|
179
190
|
|
|
180
191
|
A plain link works for reads too: `api/orders/list_orders?status=open`
|
|
181
192
|
(arguments as text, converted by their annotations).
|
|
@@ -193,8 +204,8 @@ python3 -m zenera.api api/items.api.py list_items
|
|
|
193
204
|
python3 -m zenera.api api/items.api.py set_done '{"id": 1, "done": true}'
|
|
194
205
|
python3 -m zenera.api api/items.api.py remove_item '{"id": 99}' # expect: 404: no item 99
|
|
195
206
|
rm -rf /tmp/todo-test; unset ZEN_APP_DATA
|
|
196
|
-
|
|
207
|
+
node /skills/html-page/scripts/build.ts . # checks each api('...') path and the page's calls
|
|
197
208
|
```
|
|
198
209
|
|
|
199
210
|
Every name the page calls must be a function the listing showed, with the
|
|
200
|
-
argument names it shows
|
|
211
|
+
argument names it shows - declare them so in the page's `ItemsApi`.
|