@zenera/cli 1.3.22 → 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 +37 -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
|
|
|
@@ -147,8 +151,8 @@ def delete_note(id: int):
|
|
|
147
151
|
- Store `.id` (an `owner` column), never the email or name: those can change.
|
|
148
152
|
- Check permissions in the function (`HttpError(403, ...)`); hiding a button
|
|
149
153
|
in the page is not a check.
|
|
150
|
-
- In the page: `const me =
|
|
151
|
-
`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.
|
|
152
156
|
- When it matters: a page in a chat's workspace already belongs to one user
|
|
153
157
|
(each has their own copy and `.data`). Identity matters for data shared
|
|
154
158
|
between users: an external database, or a page published in the project's
|
|
@@ -159,26 +163,30 @@ def delete_note(id: int):
|
|
|
159
163
|
|
|
160
164
|
## Calling them from the page
|
|
161
165
|
|
|
162
|
-
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
- `
|
|
166
|
-
object
|
|
167
|
-
|
|
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.
|
|
168
173
|
- Always pass **one object** of named arguments (or nothing). Each call
|
|
169
174
|
returns a promise of what the function returned.
|
|
170
175
|
- A failure rejects with an `ApiError`: `.message` is the `HttpError`
|
|
171
|
-
message, `.status` the HTTP status (0: not reachable).
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
|
181
|
-
|
|
|
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` |
|
|
182
190
|
|
|
183
191
|
A plain link works for reads too: `api/orders/list_orders?status=open`
|
|
184
192
|
(arguments as text, converted by their annotations).
|
|
@@ -196,8 +204,8 @@ python3 -m zenera.api api/items.api.py list_items
|
|
|
196
204
|
python3 -m zenera.api api/items.api.py set_done '{"id": 1, "done": true}'
|
|
197
205
|
python3 -m zenera.api api/items.api.py remove_item '{"id": 99}' # expect: 404: no item 99
|
|
198
206
|
rm -rf /tmp/todo-test; unset ZEN_APP_DATA
|
|
199
|
-
|
|
207
|
+
node /skills/html-page/scripts/build.ts . # checks each api('...') path and the page's calls
|
|
200
208
|
```
|
|
201
209
|
|
|
202
210
|
Every name the page calls must be a function the listing showed, with the
|
|
203
|
-
argument names it shows
|
|
211
|
+
argument names it shows - declare them so in the page's `ItemsApi`.
|