@plitzi/sdk-mcp 0.38.24 → 0.39.0

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.
Files changed (58) hide show
  1. package/CHANGELOG.md +156 -1
  2. package/dist/createServer.js +1 -0
  3. package/dist/modules/mcp/catalogs/index.d.ts +1 -1
  4. package/dist/modules/mcp/catalogs/index.js +2 -2
  5. package/dist/modules/mcp/catalogs/pluginCatalog.js +5 -1
  6. package/dist/modules/mcp/handler.d.ts +3 -1
  7. package/dist/modules/mcp/handler.js +32 -2
  8. package/dist/modules/mcp/helpers/guide/index.d.ts +3 -0
  9. package/dist/modules/mcp/helpers/guide/index.js +19 -0
  10. package/dist/modules/mcp/helpers/{guide.d.ts → guide/instructions.d.ts} +0 -1
  11. package/dist/modules/mcp/helpers/guide/instructions.js +106 -0
  12. package/dist/modules/mcp/helpers/guide/logic.d.ts +2 -0
  13. package/dist/modules/mcp/helpers/guide/logic.js +166 -0
  14. package/dist/modules/mcp/helpers/guide/practice.d.ts +2 -0
  15. package/dist/modules/mcp/helpers/guide/practice.js +123 -0
  16. package/dist/modules/mcp/helpers/guide/reference.d.ts +2 -0
  17. package/dist/modules/mcp/helpers/guide/reference.js +249 -0
  18. package/dist/modules/mcp/helpers/guide/server.d.ts +2 -0
  19. package/dist/modules/mcp/helpers/guide/server.js +252 -0
  20. package/dist/modules/mcp/helpers/guide/structure.d.ts +2 -0
  21. package/dist/modules/mcp/helpers/guide/structure.js +187 -0
  22. package/dist/modules/mcp/helpers/guide/styling.d.ts +2 -0
  23. package/dist/modules/mcp/helpers/guide/styling.js +118 -0
  24. package/dist/modules/mcp/helpers/guide/values.d.ts +2 -0
  25. package/dist/modules/mcp/helpers/guide/values.js +6 -0
  26. package/dist/modules/mcp/helpers/space.d.ts +5 -2
  27. package/dist/modules/mcp/helpers/space.js +5 -4
  28. package/dist/modules/mcp/resources/core.js +1 -1
  29. package/dist/modules/mcp/resources/index.d.ts +1 -1
  30. package/dist/modules/mcp/resources/primer.d.ts +0 -11
  31. package/dist/modules/mcp/resources/primer.js +46 -1
  32. package/dist/modules/mcp/resources/register.js +1 -1
  33. package/dist/modules/mcp/server.js +17 -8
  34. package/dist/modules/mcp/tools/apply/index.d.ts +19 -0
  35. package/dist/modules/mcp/tools/index.js +2 -0
  36. package/dist/modules/mcp/tools/operations/actions/document.d.ts +3 -0
  37. package/dist/modules/mcp/tools/operations/actions/document.js +5 -2
  38. package/dist/modules/mcp/tools/operations/actions/index.d.ts +6 -0
  39. package/dist/modules/mcp/tools/operations/actions/patchAction.d.ts +3 -0
  40. package/dist/modules/mcp/tools/operations/actions/upsertAction.d.ts +3 -0
  41. package/dist/modules/mcp/tools/operations/index.d.ts +64 -0
  42. package/dist/modules/mcp/tools/operations/schema/operations.d.ts +13 -0
  43. package/dist/modules/mcp/tools/operations/schema/settings/patchSettings.d.ts +13 -0
  44. package/dist/modules/mcp/tools/operations/schema/settings/patchSettings.js +25 -1
  45. package/dist/modules/mcp/tools/render.d.ts +13 -0
  46. package/dist/modules/mcp/tools/renderWidget.d.ts +13 -0
  47. package/dist/modules/mcp/tools/shared/lintDraft.js +5 -0
  48. package/dist/modules/mcp/tools/shared/tool.d.ts +6 -0
  49. package/dist/modules/mcp/tools/shared/validator/connectors.js +0 -1
  50. package/dist/modules/mcp/tools/shared/validator/css.js +6 -1
  51. package/dist/modules/mcp/tools/test.d.ts +23 -0
  52. package/dist/modules/mcp/tools/test.js +85 -0
  53. package/dist/modules/mcp/types/aiSchema.d.ts +2 -0
  54. package/dist/modules/mcp/types/previewTypes.d.ts +3 -2
  55. package/dist/modules/mcp/types/toolTypes.d.ts +5 -0
  56. package/dist/preview/createPreview.js +4 -2
  57. package/package.json +8 -8
  58. package/dist/modules/mcp/helpers/guide.js +0 -1139
@@ -0,0 +1,252 @@
1
+ //#region src/modules/mcp/helpers/guide/server.ts
2
+ /** The space's server side: connectors, server actions, functions, data, realtime channels and feature flags. */
3
+ var serverGuide = `## Connectors — CMS and API integrations
4
+ A **connector** is how a space reads real content from Strapi, WordPress, Contentful, Directus or any REST service.
5
+ It is **a manifest, not code**: you declare the base URL, the endpoints, the auth template and the filter operators,
6
+ and the **server** executes it during the render. Integrating a new CMS never means shipping an adapter — it means
7
+ writing one document, which you can do here with \`upsertConnector\`.
8
+
9
+ Why the server and not the browser: the request (and the token behind it) never reaches the visitor, and the content
10
+ is in the HTML search engines see. That is also the one hard rule below — a provider element that is not
11
+ server-rendered ignores its connector entirely.
12
+
13
+ **Read these two first:**
14
+ - \`plitzi://connector-presets\` — **working manifests** for Strapi v5, WordPress, Directus, Contentful and a plain
15
+ REST API, each with the \`credentialKeys\` that provider needs, **plus every template token** the engine binds.
16
+ Start from the preset for the user's provider and edit it; do not invent a shape from memory.
17
+ - \`plitzi://connectors/{env}\` — the connectors **this space already has**, each with its read/write endpoint names,
18
+ its filter operators and its published fields. \`plitzi://connectors/{env}/{ref}\` opens one manifest in full.
19
+
20
+ ### Credentials are NOT yours to write
21
+ You never create, see or transmit a secret. Author the manifest with the token in place
22
+ (\`"value": "Bearer {{credential.token}}"\`) and **leave \`connection.credential\` unset** unless the user hands you an
23
+ identifier. The connector **saves fine that way** — validation reports it as a *warning*, not an error — and its
24
+ requests go unauthenticated until the space owner creates the credential in the builder and attaches it. Say that to
25
+ the user as the last step of any integration you build, naming the keys the preset lists (e.g. Strapi needs \`token\`).
26
+
27
+ ### The manifest
28
+ Every string is a template the server renders per request. \`{{resource}}\` is the collection the element asked for;
29
+ \`{{limit}}\`/\`{{offset}}\`/\`{{page}}\`/\`{{cursor}}\` the window; \`{{routeParams.x}}\`/\`{{queryParams.x}}\` the
30
+ visitor's URL; \`{{credential.x}}\` the secret; \`{{field}}\`/\`{{value}}\` inside an operator; \`{{id}}\`/\`{{values}}\`
31
+ inside a write. The op splits it in two, exactly as the engine does:
32
+ - **\`connection\`** — what applies to every call: \`credential\`, \`auth\`, \`headers\`, \`pagination\`, \`operators\`,
33
+ \`mediaBaseUrl\`, \`fields\`, \`projection\`.
34
+ - **\`endpoints\`** — the individual calls: \`read\` (named; **\`list\` is the one an element addresses when it names
35
+ none**) and \`write\` (named; **omit for read-only** — an undeclared write can never be executed).
36
+
37
+ A read endpoint says where things live in *that* provider's response: \`itemsPath\` (the array), \`totalPath\` (the
38
+ count), \`idPath\` (the record's id), \`valuesPath\` (its fields). Strapi's \`data\` + \`meta.pagination.total\` and
39
+ Contentful's \`items\` + \`fields\` are the same manifest with different paths.
40
+
41
+ Two traps the validator will catch for you, both silent at runtime otherwise:
42
+ - An **operator template must render a whole \`key=value\` entry** (\`"eq": "filters[{{field}}][$eq]={{value}}"\`). A
43
+ filter naming an operator the manifest does not declare is **dropped** — the query then returns *unfiltered*
44
+ records, not none.
45
+ - **Paging must appear in the request.** Declaring \`pagination: "page"\` without \`{{page}}\` in the query makes every
46
+ page resolve to the first one.
47
+
48
+ Example — Strapi, from the preset:
49
+ \`\`\`json
50
+ { "type": "upsertConnector", "ref": "strapi-blog", "name": "Blog CMS",
51
+ "baseUrl": "https://cms.example.com",
52
+ "connection": {
53
+ "auth": { "in": "header", "name": "Authorization", "value": "Bearer {{credential.token}}" },
54
+ "pagination": "offset",
55
+ "operators": { "eq": "filters[{{field}}][$eq]={{value}}", "contains": "filters[{{field}}][$containsi]={{value}}" },
56
+ "mediaBaseUrl": "https://cms.example.com" },
57
+ "endpoints": { "read": { "list": {
58
+ "path": "/api/{{resource}}",
59
+ "query": { "pagination[start]": "{{offset}}", "pagination[limit]": "{{limit}}", "populate": "*" },
60
+ "itemsPath": "data", "totalPath": "meta.pagination.total", "idPath": "documentId" } } } }
61
+ \`\`\`
62
+ \`patchConnector\` changes part of one (endpoints merge **by name**; \`null\` removes one) — that is how you add a
63
+ \`detail\` read to a large manifest without resending it. \`deleteConnector\` is destructive: every element pointing
64
+ at it stops resolving, so confirm first.
65
+
66
+ ### Using a connector on a page
67
+ The provider element is \`apiContainer\`, and it needs **both halves**:
68
+ 1. \`runtime: "server"\` — set it on \`upsertElement\`/\`patchElement\`. **Without it the connector is ignored** and the
69
+ element falls back to fetching its own \`query\` URL from the browser. This is the single most common mistake; the
70
+ validator warns when it sees one half without the other.
71
+ 2. props: \`connector\` (the ref), \`resource\` (the collection → \`{{resource}}\`), and optionally \`endpoint\` (a read
72
+ other than \`list\`), \`filters\`, \`limit\`, \`singleRecord\`, \`pagination\`, \`pageParam\`.
73
+
74
+ It then publishes one source **to its descendants only** (like any provider — bind *inside* its subtree):
75
+ \`apiContainer_<name>.records\` (an array of \`{ id, values }\` — a record's fields are under \`values\`, so a row
76
+ reads \`list_<name>.item.values.<field>\`), \`.pageInfo\` (\`page\`, \`pageCount\`, \`total\`, \`hasNextPage\`…),
77
+ \`.isEmpty\`, \`.hasError\`, \`.errorMessage\`, \`.isLoading\`. With \`singleRecord: true\` it publishes \`.record\`
78
+ instead of \`.records\` — that is what a **detail page** uses. Bind an empty-state block's visibility to \`.isEmpty\`
79
+ and an error block's to \`.hasError\`; they are ordinary bindings, no special mechanism.
80
+
81
+ **A list page** — provider, then a \`list\` inside it bound to the records, then the row template reading the item
82
+ (a \`list\` is a \`<ul>\`, or \`<ol>\` by \`subType\`; its row a \`listItem\`, an \`<li>\` — any other row is warned
83
+ \`list-row-not-li\`):
84
+ \`\`\`json
85
+ { "operations": [
86
+ { "type": "upsertElement", "pageRef": "blog", "element": {
87
+ "ref": "posts-api", "type": "apiContainer", "runtime": "server",
88
+ "props": { "connector": "strapi-blog", "resource": "articles", "limit": "9", "pagination": "url" },
89
+ "children": [ { "ref": "posts", "type": "list", "children": [
90
+ { "ref": "post-row", "type": "listItem", "children": [
91
+ { "ref": "post-title", "type": "text" } ] } ] } ] } },
92
+ { "type": "upsertBinding", "pageRef": "blog", "ref": "posts", "category": "attributes",
93
+ "binding": { "to": "items", "source": "apiContainer_posts-api.records" } },
94
+ { "type": "upsertBinding", "pageRef": "blog", "ref": "post-title", "category": "attributes",
95
+ "binding": { "to": "content", "source": "list_posts.item.values.title" } } ] }
96
+ \`\`\`
97
+
98
+ **A detail page** is the same provider with \`singleRecord\` and a filter resolved from the URL. Create the page with a
99
+ route param (\`"slug": "blog/:postSlug"\`), then filter on it — the filter \`value\` is a template the server resolves:
100
+ \`\`\`json
101
+ { "type": "upsertElement", "pageRef": "post-detail", "element": {
102
+ "ref": "post-api", "type": "apiContainer", "runtime": "server",
103
+ "props": { "connector": "strapi-blog", "resource": "articles", "singleRecord": true,
104
+ "filters": [ { "field": "slug", "operator": "eq", "value": "{{routeParams.postSlug}}" } ] } } }
105
+ \`\`\`
106
+ Its children then bind to \`apiContainer_post-api.record.values.<field>\`. A filter whose template resolves to nothing
107
+ returns **no records** rather than the whole collection — a URL that addressed one post never renders a different one.
108
+
109
+ **Paging** is the \`pagination\` prop: \`"none"\`, \`"url"\` (the page number rides the query string, so pages are
110
+ shareable and indexable — prefer it) or \`"append"\` (a "load more" list). Give each list on a page its own
111
+ \`pageParam\` so two lists page independently. The provider also offers the \`loadMore\` and \`goToPage\` callbacks to
112
+ interaction flows, \`performQuery\` to refetch, and \`cancelQuery\` to drop a request in flight (a STOP).
113
+
114
+ **Writing back** (a form, a "delete" button): declare the endpoint under \`endpoints.write\`, then call the provider's
115
+ **\`writeRecord\`** callback from an interaction flow — nodeType \`callback\`, \`elementId\` the apiContainer's ref,
116
+ params \`action\` (the write endpoint's name) and \`recordId\`. The write goes through the server, which owns the
117
+ credential and refuses any action the manifest does not declare. Writes exist **only** on a server-rendered provider.
118
+
119
+ **Connectors need a server.** A space published without server rendering has nowhere to resolve one: it works in the
120
+ builder and renders empty when published. If the user has no SSR deployment, say so rather than leaving them to
121
+ discover it — the alternative is a browser-side \`query\`, which cannot keep a secret.
122
+
123
+ ## Server actions
124
+ Work a page cannot do in the browser — charge a card, send mail, read a system only the server reaches. An action
125
+ is a stored flow the SERVER runs; a page names it and never learns what it does. Write one with
126
+ \`upsertAction\` / \`patchAction\`, then call it from a page flow with the \`runServerAction\` step (mode
127
+ \`await\` to use the result, \`detached\` to fire and carry on).
128
+
129
+ Four rules worth knowing before you write:
130
+
131
+ - **Steps are server tasks.** \`plitzi://actions/{env}/tasks\` lists what this deployment can run — a browser step
132
+ (\`setState\`, \`navigate\`) has nothing to act on here, and the reverse is true too: a task cannot run in a page
133
+ flow.
134
+ - **The contracts.** \`input\` is coerced and anything undeclared is DROPPED. The OUTPUT is whatever the final
135
+ \`flow.output\` step names — there is no separate list to keep in step with it — and that step must be LAST,
136
+ since only the last one that runs is answered. Everything else a step produced stays on the server.
137
+ - **Whether it runs lives on its TRIGGERS.** Each trigger step carries \`enabled\`, and the action is on when any
138
+ way into it is — there is no switch beside the flow. So "pause this action" means disabling its trigger step(s),
139
+ never deleting them.
140
+ - **A step names the credential it uses**, and sees no other. \`credentials\` on the document says which ones the
141
+ action may ask for at all; the secret itself is never yours to see, exactly as with a connector.
142
+
143
+ \`deleteAction { ref }\` removes one; every \`runServerAction\` step that names it stops resolving, so confirm first.
144
+
145
+ ## Functions
146
+ When no server task does what a flow needs — parse a feed, call an API with its own shape, compute something — the
147
+ space can have its own: **functions**, TypeScript the platform builds and runs in a sandbox. Their tasks are steps like
148
+ any other (\`<namespace>.<action>\`), listed in \`plitzi://actions/{env}/tasks\` once saved.
149
+
150
+ - **Write** files with \`upsertFunctionFile { path, content }\` (whole files; \`deleteFunctionFile { path }\` removes
151
+ one). \`index.ts\` default-exports the definition:
152
+ \`export default defineFunctions({ allow: { hosts: ["api.example.com"] }, tasks: [{ namespace, action, title, params, run: async (params, ctx) => … }] })\`,
153
+ \`defineFunctions\` from \`@plitzi/sdk-server/functions\`. Files import each other by relative path — no package,
154
+ no Node built-in.
155
+ - **\`ctx\` is all a function reaches:** \`ctx.kv\` (the space's store), \`ctx.fetch(url, init)\` to the hosts
156
+ \`allow.hosts\` names (\`*.example.com\` for subdomains), \`ctx.publish/grant/revoke\` (channels),
157
+ \`ctx.data("products.json")\` (one file of the space's data, parsed — never imported), \`ctx.log\`, \`ctx.user\` (who
158
+ asked, never their session). A secret is NAMED, never read: \`ctx.fetch(url, { credential: "stripe",
159
+ headers: { authorization: "Bearer {{ credential.apiKey }}" } })\`. \`signal\` in the init cuts a slow request short
160
+ (\`AbortSignal.timeout(12000)\`).
161
+ - **Refuse with \`ActionRefusal\`** (from \`@plitzi/sdk-server/functions\`): its message is written for whoever asked and
162
+ reaches them (\`{{ step.error }}\`, a route's \`400 { error }\`); anything else thrown stays in the run's record.
163
+ \`new ActionRefusal(message, { code })\` names it for code that catches it — compare \`error.code\`, never the message.
164
+ - **An API on behalf of a visitor** (their calendar, their music) is an OAuth connection declared as data:
165
+ \`defineFunctions({ oauth: { calendar: { issuer, credential, scopes } } })\` — \`issuer\` for OpenID, or
166
+ \`authorizeUrl\`/\`tokenUrl\`; the credential holds the app's \`clientId\`/\`clientSecret\`. A route redirects to
167
+ \`(await ctx.oauth.connect("calendar", { returnTo: "/settings" })).url\` (\`authorizeParams\` adds to that one consent:
168
+ \`{ prompt: "select_account" }\`), and \`ctx.oauth.fetch("calendar", url)\` calls the API with the token written in;
169
+ \`status\`, \`disconnect\` beside them. The platform keeps the token sealed and renews it — never put one in \`kv\`. The
170
+ user registers \`/fn/oauth/callback\` on the space's host with the provider (\`ctx.oauth.callbackUrl()\` says the
171
+ exact address, for a page that shows it). Not connected yet is a refusal with
172
+ \`code: "oauth-not-connected"\`. \`token\` hands the access token only to a connection declaring \`exposeToken: true\`.
173
+ - **Stateless:** nothing a function keeps in memory outlives the call — a module-level cache or counter starts empty
174
+ every time, on whichever instance runs it. What must last goes in \`ctx.kv\`. A call gets 100 ms of CPU and 10 s;
175
+ a task that needs more says so — \`limits: { cpuMs: 1000, wallMs: 20000 }\`, or \`defineFunctions({ limits })\` for
176
+ all — up to the plan's ceiling. Asking above it is refused at save, never quietly cut.
177
+ - **Routes** answer HTTP on the space's own host under \`/fn/\`: \`routes: { "GET /boards/:board": (request, ctx) =>
178
+ Response.json(…) }\` answers \`/fn/boards/kanban\` (\`ctx.params.board\`). No page may live under \`/fn\`.
179
+ - **Saving builds and checks** the files: the batch is refused with each problem where it is (file and line). A
180
+ namespace the platform uses (\`kv\`, \`http\`, \`flow\`…) is refused.
181
+ - **Try it** with \`plitzi_try_function { task, params }\` before a page relies on it: the value, the logs, the error.
182
+ The live site runs what the space was last published with, never the draft. Running functions is part of the paid
183
+ plans: on another plan they save, and a run answers why it did not start — tell the user rather than work around it.
184
+
185
+ ## Data
186
+ JSON the space's pages read on the server and never serve — a catalog, prices, a menu: what a page needs whole and
187
+ nobody edits element by element.
188
+
189
+ - **Read** it as a provider does: \`apiContainer\` with \`runtime: "server"\` and \`query: "/data/products.json"\` reads
190
+ \`products.json\` of \`plitzi://data/{env}\`, and the page arrives with it. A browser provider reading \`/data/…\` is
191
+ refused — the data is the server's.
192
+ - **Write** it with \`upsertDataFile { path, content }\` (the whole file, as JSON text; \`deleteDataFile { path }\`
193
+ removes one): a path of plain segments ending in \`.json\`. Saved whole, with the batch: a newer copy (somebody saved
194
+ since you read it) refuses it — read it again.
195
+ - **What a provider reads is in the page it renders**: data a page must not carry belongs in a server action, which
196
+ answers only what is shown. The live site reads what the space was last published with, never the draft.
197
+
198
+ ## Realtime channels
199
+ Pages that see each other — cursors, presence, a shared board, a game. Three parts, all needed:
200
+
201
+ 1. **Declare** the topic pattern with \`patchSettings { channels: { "board:{id}": { access: { mode: "public" }, publish: "server" } } }\`.
202
+ \`publish: "server"\` is for what must be validated and saved first; \`"clients"\` (the default) for what pages send
203
+ directly — add \`presence: true\` for who-is-here.
204
+ 2. **Subscribe** with a \`channel\` element whose \`topic\` a pattern matches (\`board:{{ id }}\`, a route param).
205
+ Its descendants bind \`channel_<id>\`: \`connected\`, \`members\`, \`messages\`, \`last\`, \`retained\`; flows use its \`onMessage\`,
206
+ \`onJoin\`, \`onLeave\` triggers (\`from\`, \`user\` and the \`state\` the member announced — \`onJoin\` only for who
207
+ came after this page) and its \`publish\` / \`setPresence\` callbacks.
208
+ 3. **Announce from the server**: an action whose last step is the \`realtime.publish\` task — validate, save, then say so.
209
+
210
+ A topic no pattern matches is refused by the server and reported by the linter (\`channel-topic\`).
211
+
212
+ **Private topics** (a room behind a password, a customer's order): declare the pattern \`grant: true\`. The action that
213
+ decides the visitor may be there ends with \`realtime.grant { topic }\` and answers its \`grant\`; the \`channel\`
214
+ element binds \`grant\` to it. Without one the topic is refused however well its name is known (\`channel-grant\`).
215
+ \`realtime.revoke { topic, grant }\` takes one back — or all, naming none — and lets go whoever is on it with it.
216
+
217
+ **State every screen shares** (a dashboard's lists, a board's settings): declare the pattern \`retain: true\` with
218
+ \`publish: "server"\`. The server keeps the latest message of each type it says (\`realtime.publish\`) and hands them to
219
+ every page that joins — and to its \`onMessage\` flows, as if just said; the page binds \`desk.retained.lists\`, with no
220
+ read of its own and no copy in \`state\`. \`data: null\` forgets a type; a topic keeps at most 64 types and 512 KB.
221
+
222
+ **Two writers at once**: read-change-write with \`kv.setIf\` (written only if the value is still the one read — empty
223
+ \`expected\` = only if nothing is there yet), ordered lists with \`list.put\` / \`list.range\`, and put
224
+ \`flow.rateLimit\` first in any public action that writes.
225
+
226
+ ## Feature flags
227
+ A flag turns a part of the space on or off without anyone editing it: a feature still being built, a version for
228
+ beta users, the old checkout kept until the new one ships. **Not a visibility** — visibility hides an element that is
229
+ still rendered; a flag decides whether it exists at all.
230
+
231
+ - **Declare** with \`upsertFlag { name, description?, value, rules? }\`. \`value\` is its answer when no rule matches;
232
+ \`rules\` are \`[{ when, value }]\` read top to bottom, the first match deciding. A rule's \`when\` is a rule group over
233
+ \`environment\` (\`main\`, \`development\`, \`staging\`, \`production\`), \`hostname\`, \`routeParams.<name>\`,
234
+ \`queryParams.<name>\` and the visitor: \`user.authenticated\`, \`user.email\`, \`user.username\`, \`user.roles\` (with
235
+ \`contains\`). A group with no rules is skipped, never read as "always". \`deleteFlag { name }\` removes one.
236
+ - **Gate** an element with \`flag\` on \`upsertElement\` / \`patchElement\`: \`"newCheckout"\` exists only while the flag is
237
+ on, \`"!newCheckout"\` only while it is off — put both side by side for a rollout. On \`upsertPage\` a gated-off page
238
+ answers 404. \`null\` on a patch removes the gate. Gated off, it is not rendered and its server data is not
239
+ resolved — but the space's document, gated elements included, still reaches the browser: a flag is not a secret.
240
+ - **Read** it anywhere a source is read: \`{{ flags.newCheckout }}\` in a binding, a \`when\` of a flow step, a computed
241
+ value — and in a server action's steps, where it is resolved on the server.
242
+
243
+ A gate or a read naming a flag the space does not declare is an error (\`flag-undeclared\`, \`flag-unknown\`): an
244
+ undeclared flag is off. A declared flag nothing reads is a warning (\`flag-unused\`) — remove it once the feature
245
+ ships. The draft applies flags at once. Flags are not part of a snapshot: each environment has one set, shared by every
246
+ snapshot it serves — publishing a snapshot sends the draft's with it (and the snapshot keeps a copy, as a fallback), the
247
+ builder's *Publish flags* sends only them, and a rollback keeps them. Above the space, the server rendering it, the SDK embedding it and a tester with the dev tools
248
+ may each override a flag; you only ever write the space's own.
249
+
250
+ `;
251
+ //#endregion
252
+ export { serverGuide };
@@ -0,0 +1,2 @@
1
+ /** How a space is put together: shared layouts, components, pages and folders, and its settings. */
2
+ export declare const structureGuide = "## Shared layouts \u2014 the chrome a page does NOT contain\nA page's tree is usually **not the whole page**. The header, the sidebar and the footer normally live in a **layout\ncontainer**: a shell several pages are rendered inside, so the navigation is authored once instead of once per page.\n\nIt is a **root of its own** \u2014 a `layoutContainer` element that no page owns and that is not in the page list \u2014 and\na page points at it with two attributes:\n- `layout` \u2014 the shell's ref. This is the whole of \"which chrome do I render inside\".\n- `layoutContainer` \u2014 the **slot**: the ref of a container INSIDE that shell where this page's own body is placed.\n\nSo a page with `layout: \"main-layout\"` renders `main-layout`'s whole tree, with its own elements dropped into the\none container it named. Two pages naming the same shell share every element of it \u2014 **editing the shell changes\nevery page that uses it**, which is the point and also the thing to say out loud before you touch one.\n\n**Reading them.**\n- `plitzi://schema/{env}/layouts` lists the shells: `ref`, `label`, `usedBy` (the pages), `slots`, `elementCount`.\n- Every page in `plitzi://schema/{env}/pages` carries `layout` and `layoutSlot` when it has them.\n- Read a shell exactly like a page: `plitzi://schema/{env}/pages/{layoutRef}` for its skeleton,\n `.../pages/{layoutRef}/styles` for its classes. `plitzi_search` reports a layout's elements with the layout as\n their `pageRef`.\n\n**Writing them.** Every element/binding/interaction op takes the shell's ref as its `pageRef` \u2014 there is no separate\nvocabulary:\n```json\n{ \"type\": \"upsertElement\", \"pageRef\": \"main-layout\", \"parentRef\": \"sidebar\",\n \"element\": { \"ref\": \"upgrade-card\", \"type\": \"container\", \"children\": [ \u2026 ] } }\n```\n- `upsertLayout` creates a shell (`ref`, `label`, `subType`). Put the chrome in it with `upsertElement`, including\n an empty container to serve as the slot.\n- `upsertPage { layout, layoutContainer }` attaches a page to it; `layout: null` detaches. A `layoutContainer` that\n is not an element of that shell is refused \u2014 stored, it would render the page's body where nobody sees it.\n- `deleteLayout` removes a shell and everything in it, and is **refused while any page still renders inside it**\n (the refusal names them). Destructive: what it deletes is on every page that uses it, so confirm first.\n\n**Only some pages?** A block that only some of a layout's pages carry (a newsletter band on two of ten) is not\nchrome: make it a **component** and place it on those pages.\n\n**Where does this element belong?** If the user asks for something \"on every page\" \u2014 a nav item, a banner, a footer\nlink, an upgrade prompt in the sidebar \u2014 it belongs in the LAYOUT, not in the page you happen to have open. Check\nthe page's `layout` first; if the element you are looking for is not in the page's own tree, it is in the shell.\n\n## Components \u2014 a subtree written once, placed anywhere\nA **component** is a reusable subtree: a product card, a pricing tier, a testimonial \u2014 written once and placed on\nany page as an **instance**. It is part of the space, so it is published, versioned and copied with it. Its tree is\nnot inside any page: it is a root of its own, like a layout, and **editing it changes every instance** \u2014 say so\nbefore you touch one.\n\nIt is not a **snippet**. The builder's *Save as snippet* keeps a copy of a block as a file people drop onto pages, and\neach drop is the page's own from then on. No operation here writes one: when someone wants a block that stays the same\neverywhere, that is a component.\n\nIt is **closed**. Inside, a binding or a template reads **`props`** \u2014 what each instance hands in \u2014 and the globals\n(`state`, `auth`, `navigation`, `theme`, `variables`, `computed`), never the page an instance sits on. A\ncomponent that needs a list row's record gets it as a prop: the INSTANCE binds it (`item: \"{{ list_rows.item }}\"`),\nthe component reads `{{ props.item.name }}`.\n\n**Reading them.** `plitzi://schema/{env}/components` lists them: `ref`, `label`, `props`, `slots`, `rootRef`,\n`instances`. Read one like a page: `plitzi://schema/{env}/pages/{componentRef}` (and `/styles`).\n\n**Writing them.**\n- `upsertComponent { ref, label?, props?, slots? }` declares one \u2014 with nothing in it but its root, `{ref}-root`, a\n container \u2014 or updates the declaration of one that exists (`props` is REPLACED whole). Fill it with every\n element/binding/interaction op you already know, with **`pageRef: \"<componentRef>\"`**:\n ```json\n { \"type\": \"upsertElement\", \"pageRef\": \"product-card\", \"parentRef\": \"product-card-root\",\n \"element\": { \"ref\": \"product-card-title\", \"type\": \"heading\" } }\n ```\n- `upsertComponent { ref, fromRef, instanceRef }` makes a component OF an element that already exists: the element\n and everything inside it become the component, and an instance named `instanceRef` takes its place, so the page\n renders what it did. The way to turn a repeated block into one.\n- A **prop** is `{ type, description, required?, default?, options? }`, `type` one of `text`, `textarea`,\n `number`, `boolean`, `select` (with `options`), `scalar`, `json`. Its name is read as `{{ props.<name> }}`, so\n letters, digits and `_` \u2014 and never one an instance already has (`referenceId`, `referenceType`, `slot`\u2026).\n- A **slot** is an element of the component's tree (usually an empty container) an instance fills with children.\n- `deleteComponent { ref }` removes one nothing places; while instances remain it is refused, naming them.\n\n**Placing one** is an element: a `reference` whose props say which component and hand in its props, one attribute each:\n```json\n{ \"type\": \"upsertElement\", \"pageRef\": \"shop\", \"parentRef\": \"grid\",\n \"element\": { \"ref\": \"lamp-card\", \"type\": \"reference\",\n \"props\": { \"referenceType\": \"component\", \"referenceId\": \"product-card\", \"title\": \"Lamp\" },\n \"children\": [ { \"ref\": \"lamp-buy\", \"type\": \"button\", \"props\": { \"content\": \"Buy\", \"slot\": \"product-card-actions\" } } ] } }\n```\nA required prop left out, a prop the component does not declare, a value of the wrong kind or a child naming a slot\nthe component does not have is reported by `plitzi_apply`'s `dryRun` \u2014 fix it before applying.\n\n## Pages & folders\n- **A page behind a feature flag**: `upsertPage { flag: \"labs\" }` answers 404 while the flag is off (see **Feature\n flags**); `flag: null` removes it.\n- **Always set a `slug` when creating a page** (`upsertPage`) \u2014 it is the page's URL path and good practice for a\n clean, stable route (e.g. `\"pricing\"` or `\"posts/:postId\"`). Omit it and the page ref is used as the slug,\n and `plitzi_apply` warns so you remember to set a meaningful one.\n- **A page slug is RELATIVE \u2014 do NOT start it with `/`.** The runtime prepends the leading slash (and any folder\n path) itself, so a leading slash doubles it. Write `\"pricing\"`, not `\"/pricing\"`. (upsertPage strips a leading\n slash for you, but write it relative.)\n- **Dynamic pages \u2014 route params.** A slug segment written `:name` (e.g. `\"posts/:postId\"`) is a **route param**,\n exactly like React Router. On that page it is readable **two ways**: as `{{name}}` inside a prop, and as the\n data-binding source **`navigation.routeParams.name`** (the `navigation` module source, global \u2014 bindable\n anywhere). So a blog is a `\"posts\"` list page plus a `\"posts/:postId\"` detail page whose `apiContainer` query\n binds `navigation.routeParams.postId` to fetch that one post. (`navigation.queryParams.<name>` exposes `?query=`\n string params the same way.)\n- **Navigate with the `Link` element, not an interaction.** `link` is a **container** \u2014 it wraps any children and\n navigates on click, so it is the default way to move between pages. Its `mode`: `\"page\"` links to another space\n page (set `href` to the target page, folder path resolved for you); `\"internal\"` takes a path inside the space and\n resolves `{{token}}` templates in it, so a row's \"view\" link is `mode:\"internal\", href:\"posts/{{postId}}\"`;\n `\"external\"` is a full URL. `target` is `self`/`blank`/`parent`/`top`. Reach for the `navigate` globalCallback\n only when navigation must be **one step inside a larger interaction flow** (e.g. save, then go) \u2014 for a plain link,\n use `link`.\n- **A link's words are its `content`, and an icon beside them its `icon`** \u2014 `{ \"type\": \"link\", \"props\": { \"mode\":\n \"page\", \"href\": \"pricing\", \"content\": \"Pricing\", \"icon\": \"fa-solid fa-arrow-right\", \"iconPlacement\": \"after\" } }`\n (a `button` takes the same two). The icon's class goes in the element's `icon` slot (`style.slots.icon`). With\n children too, `contentPlacement` puts the words `before` or `after` them. A `text` or `fontAwesome` inside is\n one element more, and a text keeps a colour of its own instead of the link's (and its hover).\n- **The link to the page being shown marks itself**: it carries `aria-current=\"page\"`, and its class's `current`\n state says how it looks \u2014 `{ \"type\": \"patchDefinition\", \"ref\": \"nav-link\", \"states\": { \"current\": { \"desktop\": {\n \"color\": \"var(--primary)\" } } } }`. So a header written once in a layout lights the right item on every page; never\n copy the header per page to style one item. A link for a section \u2014 a journal and its articles \u2014 takes\n `\"current\": \"section\"` in its props: current on every page under its path too (`aria-current=\"true\"`), the same\n state dressing it. The same state dresses any chosen one of a set: a pressed toggle (`aria-pressed` \u2014 a theme\n toggle's option slot) and a selected tab.\n- **A section of a page** is an element with an `anchor` (its `id` in the DOM: lowercase, digits, `-`; one per\n page, layouts included; not inside a list row or a component). A link lands on it with `hash`:\n `{ \"mode\": \"page\", \"href\": \"home\", \"hash\": \"plans\" }` goes to `/#plans` and scrolls there, from any page.\n\nPages can be grouped into **folders** (the sidebar tree). A folder is `{ ref, name, slug, parentId? }`; its `ref`\n**is its id**, and that id is what a page and a nested folder reference.\n- **Folder slugs PREPEND to the page URL \u2014 this is how nested URLs are built.** The full path is each ancestor\n folder's slug plus the page slug, joined by `/`: a page at slug `\"1-1-1\"` inside `folder-1` > `folder-1-1`\n resolves to `/folder-1/folder-1-1/1-1-1`. So a folder slug is part of the route; keep folder slugs relative too.\n- Create/rename/move a folder with `upsertFolder` (the `ref` you pass on create becomes its id \u2014 pick a stable one\n like `\"blog\"`). Nest it under another with `parentId` (a folder ref); `parentId: null` moves it back to the root.\n- Put a page in a folder with `upsertPage`'s `folder` (a folder ref). A page's `folder` is always either **empty\n (root)** or an **existing folder id**: `folder: null` or `folder: \"\"` moves it to the root, and any other value\n must resolve to a folder that already exists or is created earlier in the same batch \u2014 an unknown folder is\n rejected, never stored.\n- `deleteFolder` removes a folder and **promotes its contents up one level** \u2014 its child folders and its pages move\n to its parent (or the root). A folder cannot be nested under itself or one of its descendants.\n- **Disable a page** with `upsertPage`'s `enabled: false`; `enabled: true` re-enables it (defaults to enabled, and\n a page read reports its current `enabled`). Disabling only affects the **published SDK runtime** \u2014 the page stops\n being routable/accessible to end users. It stays fully **editable here**: you can still read it and apply any op to\n a disabled page. This does not delete it \u2014 `deletePage` does.\n- **A page that fills the window** (a dashboard, a board) takes `upsertPage`'s `documentScroll: \"locked\"`: the\n document holds still and only parts with `overflow: auto` scroll, so a finger on a tablet no longer drags and\n bounces the page. `\"noBounce\"` keeps the scroll without the rubber band; `null` undoes either. Never an\n `html, body` rule in `customCss`: that holds every page, and the site the space is a widget on.\n\n## Settings\nSpace-level configuration lives in `plitzi://settings/{env}` and is edited with a single **`patchSettings`** op\n(merge \u2014 only the fields you pass change):\n- `customCss` \u2014 **raw global CSS** injected for the whole space. Use it only for genuinely site-wide rules\n (`@keyframes`, `@font-face`, resets). To style an element, write a **definition** and attach it \u2014 never customCss.\n- `notifications` \u2014 how the toasts an `addNotification` step shows look: colours (`background`, `text`,\n `success`, `danger`, `warning`, `info`), shape (`radius`, `font`, `fontSize`, `fontWeight`, `lineHeight`,\n `minHeight`, `border`, `shadow`, `padding`) and the parts inside (`iconSize`, `iconGap`, `closeColor`,\n `closeOpacity`, `progressHeight`), one CSS value each \u2014 a token follows the theme: `{ \"type\": \"patchSettings\",\n \"notifications\": { \"background\": \"var(--card)\", \"iconSize\": \"18px\" } }`. Merged field by field, `null` removes one.\n It is stored as rules inside `customCss` but reads and changes apart from it: never write a `.Toastify__*` rule\n yourself.\n- `keepState` / `stateStorage` \u2014 keep the runtime state (`state.<key>`, what `setState` writes) across reloads,\n in `localStorage`/`sessionStorage`, filed under whoever is signed in. It is the space's setting \u2014 pages do not\n take one. `transientState` lists the top-level keys never kept (a filter, a demo, a panel left open) \u2014 or\n `keptState` the only ones kept, when few are (a dismissed notice); one of the two. Do not\n reset kept state from `onPageLoad` instead \u2014 it is restored later than that and undoes half of the reset.\n `paintedState` lists the kept keys the FIRST PAINT shows (the tool a toolbar shows, a name in an avatar): they go\n in a cookie too, so the server draws with them instead of the page swapping them in after load. Small values only.\n- **User provider / auth**: `userProvider` \u2014 `basic` for any HTTP+JSON backend, the name of a provider registered\n in the page, or `\"\"` for none \u2014 plus `tokenStorage`, the `loginUrl`/`userUrl`/`refreshUrl`/`logoutUrl`\n endpoints and the `detailsPath`/`tokenPath`/`refreshTokenPath`/`expirationTimePath` mapping that says where the\n values sit in their responses. `sessionHintCookie` is worth setting whenever the backend can: it names a readable\n cookie carrying only expiries, which is what lets a page answer \"nobody is signed in\" without a request.\n A space served by a self-hosted `createServer({ auth })` declares none of these: that server tells its pages where\n they sign in, and only what the space declares overrides it.\n On the Plitzi platform, `userProvider: \"server\"` signs visitors in with their Plitzi account on the space's own\n host: a `link` with `mode: \"external\"` to `/auth/sign-in?return=/` starts it, `authLogout` ends it.\n- `visitorRoles` \u2014 what each visitor role gives, `{ \"author\": [\"postPublish\"] }`: the permissions an action's\n `access: { mode: \"role\" }` and a page's `can()` ask for. A visitor holds ONLY the permissions of their roles here,\n never their account's. Who holds a role is given by email in the builder's Settings \u2192 Visitors \u2014 never in the\n space's `settings`.\n- `channels` \u2014 the realtime channels, by topic pattern (see **Realtime channels**). Merged pattern by pattern;\n `null` removes one.\n Example \u2014 inject a keyframe globally:\n `{ \"type\": \"patchSettings\", \"customCss\": \"@keyframes spin { to { transform: rotate(360deg); } }\" }`.\n\n";
@@ -0,0 +1,187 @@
1
+ //#region src/modules/mcp/helpers/guide/structure.ts
2
+ /** How a space is put together: shared layouts, components, pages and folders, and its settings. */
3
+ var structureGuide = `## Shared layouts — the chrome a page does NOT contain
4
+ A page's tree is usually **not the whole page**. The header, the sidebar and the footer normally live in a **layout
5
+ container**: a shell several pages are rendered inside, so the navigation is authored once instead of once per page.
6
+
7
+ It is a **root of its own** — a \`layoutContainer\` element that no page owns and that is not in the page list — and
8
+ a page points at it with two attributes:
9
+ - \`layout\` — the shell's ref. This is the whole of "which chrome do I render inside".
10
+ - \`layoutContainer\` — the **slot**: the ref of a container INSIDE that shell where this page's own body is placed.
11
+
12
+ So a page with \`layout: "main-layout"\` renders \`main-layout\`'s whole tree, with its own elements dropped into the
13
+ one container it named. Two pages naming the same shell share every element of it — **editing the shell changes
14
+ every page that uses it**, which is the point and also the thing to say out loud before you touch one.
15
+
16
+ **Reading them.**
17
+ - \`plitzi://schema/{env}/layouts\` lists the shells: \`ref\`, \`label\`, \`usedBy\` (the pages), \`slots\`, \`elementCount\`.
18
+ - Every page in \`plitzi://schema/{env}/pages\` carries \`layout\` and \`layoutSlot\` when it has them.
19
+ - Read a shell exactly like a page: \`plitzi://schema/{env}/pages/{layoutRef}\` for its skeleton,
20
+ \`.../pages/{layoutRef}/styles\` for its classes. \`plitzi_search\` reports a layout's elements with the layout as
21
+ their \`pageRef\`.
22
+
23
+ **Writing them.** Every element/binding/interaction op takes the shell's ref as its \`pageRef\` — there is no separate
24
+ vocabulary:
25
+ \`\`\`json
26
+ { "type": "upsertElement", "pageRef": "main-layout", "parentRef": "sidebar",
27
+ "element": { "ref": "upgrade-card", "type": "container", "children": [ … ] } }
28
+ \`\`\`
29
+ - \`upsertLayout\` creates a shell (\`ref\`, \`label\`, \`subType\`). Put the chrome in it with \`upsertElement\`, including
30
+ an empty container to serve as the slot.
31
+ - \`upsertPage { layout, layoutContainer }\` attaches a page to it; \`layout: null\` detaches. A \`layoutContainer\` that
32
+ is not an element of that shell is refused — stored, it would render the page's body where nobody sees it.
33
+ - \`deleteLayout\` removes a shell and everything in it, and is **refused while any page still renders inside it**
34
+ (the refusal names them). Destructive: what it deletes is on every page that uses it, so confirm first.
35
+
36
+ **Only some pages?** A block that only some of a layout's pages carry (a newsletter band on two of ten) is not
37
+ chrome: make it a **component** and place it on those pages.
38
+
39
+ **Where does this element belong?** If the user asks for something "on every page" — a nav item, a banner, a footer
40
+ link, an upgrade prompt in the sidebar — it belongs in the LAYOUT, not in the page you happen to have open. Check
41
+ the page's \`layout\` first; if the element you are looking for is not in the page's own tree, it is in the shell.
42
+
43
+ ## Components — a subtree written once, placed anywhere
44
+ A **component** is a reusable subtree: a product card, a pricing tier, a testimonial — written once and placed on
45
+ any page as an **instance**. It is part of the space, so it is published, versioned and copied with it. Its tree is
46
+ not inside any page: it is a root of its own, like a layout, and **editing it changes every instance** — say so
47
+ before you touch one.
48
+
49
+ It is not a **snippet**. The builder's *Save as snippet* keeps a copy of a block as a file people drop onto pages, and
50
+ each drop is the page's own from then on. No operation here writes one: when someone wants a block that stays the same
51
+ everywhere, that is a component.
52
+
53
+ It is **closed**. Inside, a binding or a template reads **\`props\`** — what each instance hands in — and the globals
54
+ (\`state\`, \`auth\`, \`navigation\`, \`theme\`, \`variables\`, \`computed\`), never the page an instance sits on. A
55
+ component that needs a list row's record gets it as a prop: the INSTANCE binds it (\`item: "{{ list_rows.item }}"\`),
56
+ the component reads \`{{ props.item.name }}\`.
57
+
58
+ **Reading them.** \`plitzi://schema/{env}/components\` lists them: \`ref\`, \`label\`, \`props\`, \`slots\`, \`rootRef\`,
59
+ \`instances\`. Read one like a page: \`plitzi://schema/{env}/pages/{componentRef}\` (and \`/styles\`).
60
+
61
+ **Writing them.**
62
+ - \`upsertComponent { ref, label?, props?, slots? }\` declares one — with nothing in it but its root, \`{ref}-root\`, a
63
+ container — or updates the declaration of one that exists (\`props\` is REPLACED whole). Fill it with every
64
+ element/binding/interaction op you already know, with **\`pageRef: "<componentRef>"\`**:
65
+ \`\`\`json
66
+ { "type": "upsertElement", "pageRef": "product-card", "parentRef": "product-card-root",
67
+ "element": { "ref": "product-card-title", "type": "heading" } }
68
+ \`\`\`
69
+ - \`upsertComponent { ref, fromRef, instanceRef }\` makes a component OF an element that already exists: the element
70
+ and everything inside it become the component, and an instance named \`instanceRef\` takes its place, so the page
71
+ renders what it did. The way to turn a repeated block into one.
72
+ - A **prop** is \`{ type, description, required?, default?, options? }\`, \`type\` one of \`text\`, \`textarea\`,
73
+ \`number\`, \`boolean\`, \`select\` (with \`options\`), \`scalar\`, \`json\`. Its name is read as \`{{ props.<name> }}\`, so
74
+ letters, digits and \`_\` — and never one an instance already has (\`referenceId\`, \`referenceType\`, \`slot\`…).
75
+ - A **slot** is an element of the component's tree (usually an empty container) an instance fills with children.
76
+ - \`deleteComponent { ref }\` removes one nothing places; while instances remain it is refused, naming them.
77
+
78
+ **Placing one** is an element: a \`reference\` whose props say which component and hand in its props, one attribute each:
79
+ \`\`\`json
80
+ { "type": "upsertElement", "pageRef": "shop", "parentRef": "grid",
81
+ "element": { "ref": "lamp-card", "type": "reference",
82
+ "props": { "referenceType": "component", "referenceId": "product-card", "title": "Lamp" },
83
+ "children": [ { "ref": "lamp-buy", "type": "button", "props": { "content": "Buy", "slot": "product-card-actions" } } ] } }
84
+ \`\`\`
85
+ A required prop left out, a prop the component does not declare, a value of the wrong kind or a child naming a slot
86
+ the component does not have is reported by \`plitzi_apply\`'s \`dryRun\` — fix it before applying.
87
+
88
+ ## Pages & folders
89
+ - **A page behind a feature flag**: \`upsertPage { flag: "labs" }\` answers 404 while the flag is off (see **Feature
90
+ flags**); \`flag: null\` removes it.
91
+ - **Always set a \`slug\` when creating a page** (\`upsertPage\`) — it is the page's URL path and good practice for a
92
+ clean, stable route (e.g. \`"pricing"\` or \`"posts/:postId"\`). Omit it and the page ref is used as the slug,
93
+ and \`plitzi_apply\` warns so you remember to set a meaningful one.
94
+ - **A page slug is RELATIVE — do NOT start it with \`/\`.** The runtime prepends the leading slash (and any folder
95
+ path) itself, so a leading slash doubles it. Write \`"pricing"\`, not \`"/pricing"\`. (upsertPage strips a leading
96
+ slash for you, but write it relative.)
97
+ - **Dynamic pages — route params.** A slug segment written \`:name\` (e.g. \`"posts/:postId"\`) is a **route param**,
98
+ exactly like React Router. On that page it is readable **two ways**: as \`{{name}}\` inside a prop, and as the
99
+ data-binding source **\`navigation.routeParams.name\`** (the \`navigation\` module source, global — bindable
100
+ anywhere). So a blog is a \`"posts"\` list page plus a \`"posts/:postId"\` detail page whose \`apiContainer\` query
101
+ binds \`navigation.routeParams.postId\` to fetch that one post. (\`navigation.queryParams.<name>\` exposes \`?query=\`
102
+ string params the same way.)
103
+ - **Navigate with the \`Link\` element, not an interaction.** \`link\` is a **container** — it wraps any children and
104
+ navigates on click, so it is the default way to move between pages. Its \`mode\`: \`"page"\` links to another space
105
+ page (set \`href\` to the target page, folder path resolved for you); \`"internal"\` takes a path inside the space and
106
+ resolves \`{{token}}\` templates in it, so a row's "view" link is \`mode:"internal", href:"posts/{{postId}}"\`;
107
+ \`"external"\` is a full URL. \`target\` is \`self\`/\`blank\`/\`parent\`/\`top\`. Reach for the \`navigate\` globalCallback
108
+ only when navigation must be **one step inside a larger interaction flow** (e.g. save, then go) — for a plain link,
109
+ use \`link\`.
110
+ - **A link's words are its \`content\`, and an icon beside them its \`icon\`** — \`{ "type": "link", "props": { "mode":
111
+ "page", "href": "pricing", "content": "Pricing", "icon": "fa-solid fa-arrow-right", "iconPlacement": "after" } }\`
112
+ (a \`button\` takes the same two). The icon's class goes in the element's \`icon\` slot (\`style.slots.icon\`). With
113
+ children too, \`contentPlacement\` puts the words \`before\` or \`after\` them. A \`text\` or \`fontAwesome\` inside is
114
+ one element more, and a text keeps a colour of its own instead of the link's (and its hover).
115
+ - **The link to the page being shown marks itself**: it carries \`aria-current="page"\`, and its class's \`current\`
116
+ state says how it looks — \`{ "type": "patchDefinition", "ref": "nav-link", "states": { "current": { "desktop": {
117
+ "color": "var(--primary)" } } } }\`. So a header written once in a layout lights the right item on every page; never
118
+ copy the header per page to style one item. A link for a section — a journal and its articles — takes
119
+ \`"current": "section"\` in its props: current on every page under its path too (\`aria-current="true"\`), the same
120
+ state dressing it. The same state dresses any chosen one of a set: a pressed toggle (\`aria-pressed\` — a theme
121
+ toggle's option slot) and a selected tab.
122
+ - **A section of a page** is an element with an \`anchor\` (its \`id\` in the DOM: lowercase, digits, \`-\`; one per
123
+ page, layouts included; not inside a list row or a component). A link lands on it with \`hash\`:
124
+ \`{ "mode": "page", "href": "home", "hash": "plans" }\` goes to \`/#plans\` and scrolls there, from any page.
125
+
126
+ Pages can be grouped into **folders** (the sidebar tree). A folder is \`{ ref, name, slug, parentId? }\`; its \`ref\`
127
+ **is its id**, and that id is what a page and a nested folder reference.
128
+ - **Folder slugs PREPEND to the page URL — this is how nested URLs are built.** The full path is each ancestor
129
+ folder's slug plus the page slug, joined by \`/\`: a page at slug \`"1-1-1"\` inside \`folder-1\` > \`folder-1-1\`
130
+ resolves to \`/folder-1/folder-1-1/1-1-1\`. So a folder slug is part of the route; keep folder slugs relative too.
131
+ - Create/rename/move a folder with \`upsertFolder\` (the \`ref\` you pass on create becomes its id — pick a stable one
132
+ like \`"blog"\`). Nest it under another with \`parentId\` (a folder ref); \`parentId: null\` moves it back to the root.
133
+ - Put a page in a folder with \`upsertPage\`'s \`folder\` (a folder ref). A page's \`folder\` is always either **empty
134
+ (root)** or an **existing folder id**: \`folder: null\` or \`folder: ""\` moves it to the root, and any other value
135
+ must resolve to a folder that already exists or is created earlier in the same batch — an unknown folder is
136
+ rejected, never stored.
137
+ - \`deleteFolder\` removes a folder and **promotes its contents up one level** — its child folders and its pages move
138
+ to its parent (or the root). A folder cannot be nested under itself or one of its descendants.
139
+ - **Disable a page** with \`upsertPage\`'s \`enabled: false\`; \`enabled: true\` re-enables it (defaults to enabled, and
140
+ a page read reports its current \`enabled\`). Disabling only affects the **published SDK runtime** — the page stops
141
+ being routable/accessible to end users. It stays fully **editable here**: you can still read it and apply any op to
142
+ a disabled page. This does not delete it — \`deletePage\` does.
143
+ - **A page that fills the window** (a dashboard, a board) takes \`upsertPage\`'s \`documentScroll: "locked"\`: the
144
+ document holds still and only parts with \`overflow: auto\` scroll, so a finger on a tablet no longer drags and
145
+ bounces the page. \`"noBounce"\` keeps the scroll without the rubber band; \`null\` undoes either. Never an
146
+ \`html, body\` rule in \`customCss\`: that holds every page, and the site the space is a widget on.
147
+
148
+ ## Settings
149
+ Space-level configuration lives in \`plitzi://settings/{env}\` and is edited with a single **\`patchSettings\`** op
150
+ (merge — only the fields you pass change):
151
+ - \`customCss\` — **raw global CSS** injected for the whole space. Use it only for genuinely site-wide rules
152
+ (\`@keyframes\`, \`@font-face\`, resets). To style an element, write a **definition** and attach it — never customCss.
153
+ - \`notifications\` — how the toasts an \`addNotification\` step shows look: colours (\`background\`, \`text\`,
154
+ \`success\`, \`danger\`, \`warning\`, \`info\`), shape (\`radius\`, \`font\`, \`fontSize\`, \`fontWeight\`, \`lineHeight\`,
155
+ \`minHeight\`, \`border\`, \`shadow\`, \`padding\`) and the parts inside (\`iconSize\`, \`iconGap\`, \`closeColor\`,
156
+ \`closeOpacity\`, \`progressHeight\`), one CSS value each — a token follows the theme: \`{ "type": "patchSettings",
157
+ "notifications": { "background": "var(--card)", "iconSize": "18px" } }\`. Merged field by field, \`null\` removes one.
158
+ It is stored as rules inside \`customCss\` but reads and changes apart from it: never write a \`.Toastify__*\` rule
159
+ yourself.
160
+ - \`keepState\` / \`stateStorage\` — keep the runtime state (\`state.<key>\`, what \`setState\` writes) across reloads,
161
+ in \`localStorage\`/\`sessionStorage\`, filed under whoever is signed in. It is the space's setting — pages do not
162
+ take one. \`transientState\` lists the top-level keys never kept (a filter, a demo, a panel left open) — or
163
+ \`keptState\` the only ones kept, when few are (a dismissed notice); one of the two. Do not
164
+ reset kept state from \`onPageLoad\` instead — it is restored later than that and undoes half of the reset.
165
+ \`paintedState\` lists the kept keys the FIRST PAINT shows (the tool a toolbar shows, a name in an avatar): they go
166
+ in a cookie too, so the server draws with them instead of the page swapping them in after load. Small values only.
167
+ - **User provider / auth**: \`userProvider\` — \`basic\` for any HTTP+JSON backend, the name of a provider registered
168
+ in the page, or \`""\` for none — plus \`tokenStorage\`, the \`loginUrl\`/\`userUrl\`/\`refreshUrl\`/\`logoutUrl\`
169
+ endpoints and the \`detailsPath\`/\`tokenPath\`/\`refreshTokenPath\`/\`expirationTimePath\` mapping that says where the
170
+ values sit in their responses. \`sessionHintCookie\` is worth setting whenever the backend can: it names a readable
171
+ cookie carrying only expiries, which is what lets a page answer "nobody is signed in" without a request.
172
+ A space served by a self-hosted \`createServer({ auth })\` declares none of these: that server tells its pages where
173
+ they sign in, and only what the space declares overrides it.
174
+ On the Plitzi platform, \`userProvider: "server"\` signs visitors in with their Plitzi account on the space's own
175
+ host: a \`link\` with \`mode: "external"\` to \`/auth/sign-in?return=/\` starts it, \`authLogout\` ends it.
176
+ - \`visitorRoles\` — what each visitor role gives, \`{ "author": ["postPublish"] }\`: the permissions an action's
177
+ \`access: { mode: "role" }\` and a page's \`can()\` ask for. A visitor holds ONLY the permissions of their roles here,
178
+ never their account's. Who holds a role is given by email in the builder's Settings → Visitors — never in the
179
+ space's \`settings\`.
180
+ - \`channels\` — the realtime channels, by topic pattern (see **Realtime channels**). Merged pattern by pattern;
181
+ \`null\` removes one.
182
+ Example — inject a keyframe globally:
183
+ \`{ "type": "patchSettings", "customCss": "@keyframes spin { to { transform: rotate(360deg); } }" }\`.
184
+
185
+ `;
186
+ //#endregion
187
+ export { structureGuide };
@@ -0,0 +1,2 @@
1
+ /** Styling: classes and selectors, variants and state, variables, tokens and fonts. */
2
+ export declare const stylingGuide = "## Styling (crosses both schemas)\n- **Mind the type's intrinsic default style.** A type renders with a base CSS *before* any class is attached \u2014 read\n it from `defaultStyle` on the type in `plitzi://types` (the primer includes it). Do not assume `display: block`:\n `text`, for one, defaults to `display: inline`, so margins/width/vertical padding behave differently. If you need\n block/flex layout on such an element, set `display` explicitly in your definition rather than relying on a default.\n- **Images: preserve aspect ratio.** Setting only `width` and `height` (or forcing both) distorts an image. Change\n one dimension and let the other be `auto`, or set `aspect-ratio` with `object-fit: cover`/`contain`, so the\n image scales without stretching.\n- **Font size and line height move together.** When you change `font-size`, set `line-height` in the same edit\n (prefer a unitless ratio like `1.5`, which tracks the font size). Changing one without the other leaves cramped or\n loosely-spaced text \u2014 they are a joint change, not two separate ones.\n- A definition lives in the **style schema**; an element's `style.base` (element schema) is the link that applies\n it. Styling an element = upsertDefinitions + upsertElement with that ref in `style.base`, in one batch.\n- **Repeating siblings**: when a set of siblings shares a shape and differs only in data (a list, cards, rows,\n steps), use `repeatElement` \u2014 the template once with `{{item.field}}` placeholders plus `items`, which\n creates the wrapper and numbers each row's refs (`step-1`, `step-2`\u2026). A list inside each row is the same op:\n the wrapping node carries `repeat: { items: \"{{item.<list>}}\", template: \u2026 }` and its refs number both levels\n (`blk-2-3`). Copy-pasting the subtree N times costs N times the tokens and drifts.\n- CSS keys are **kebab-case** (`background-color`). camelCase is rejected \u2014 read `plitzi://css-properties`.\n- **Write normal CSS \u2014 shorthands are accepted and expanded for you.** `border`, `border-{side}`,\n `border-width`/`-color`/`-style`, `border-radius`, `padding`, `margin`, `inset`, `gap`, `overflow`,\n `flex`, `flex-flow`, `background`, `font`, `transition`, `animation`, `grid`, `grid-template`,\n `grid-area`, `grid-row`, `grid-column`, `place-content`, `place-items`, `place-self`, `outline`,\n `columns`, `list-style`, `text-decoration` \u2014 the full list is in `plitzi://css-properties` under\n `shorthands`. They **persist as longhand keys** (that is what a read gives back), so a breakpoint/state/variant\n can still override one property at a time.\n - `border: 1px solid red` \u2192 `border-top-width: 1px`, `border-top-style: solid`, `border-top-color: red`, \u2026\n for all four sides. A shorthand also RESETS what it omits, so `border: none` clears a width a previous\n definition set.\n - Comma-separated layers are kept per longhand: `transition: opacity 200ms, transform 300ms` \u2192\n `transition-property: opacity, transform` + `transition-duration: 200ms, 300ms`.\n - A `background` with a bare `var(--x)` part is refused: what the variable holds decides the longhand \u2014\n `background-color` for a colour, `background-image` for a gradient or a picture. A var() inside one\n (`linear-gradient(\u2026, var(--x))`) is read as it is.\n - In a **patch**, a shorthand replaces the longhands it controls (`padding: 8px` overwrites a previous\n `padding-left`), and `\"border\": null` removes all twelve border longhands.\n- **Flex layout is not a `flex` value**: set `display: flex` **plus** `flex-direction`, `align-items`,\n `justify-content` as separate properties.\n- CSS is grouped by breakpoint: `desktop`, `tablet`, `mobile`.\n- Reference a style variable in CSS as `var(--name)`; a schema variable in a prop as `{{name}}`.\n- `element.style.base` is a **list** of definition refs; other slots go under `element.style.slots` \u2014 the slots\n `plitzi://explain/{type}` lists, never custom CSS on the SDK's own class names. A `markdown` or a `richText`\n has a slot per part of the document it writes (`heading`, `heading2`, `paragraph`, `link`, `code`,\n `codeBlockFrame`\u2026); a `formControl` its `input` box, the `field` inside it, `label`, `requiredMark`, `error`;\n a `pagination` its `previous`, `page`, `next` (the page shown is the class's `current` state).\n- **An element can attach SEVERAL classes at once, and they all apply.** `style.base` holds a list, and each\n non-base slot holds its own \u2014 every attached definition contributes CSS, and they **cascade** (a later class, then a\n global/id rule, overrides an earlier one on the same property). So when a style looks wrong, the culprit may be\n ANY attached class, not the one you just edited: read the element's `resolvedStyle` (it inlines the CSS of every\n class it attaches, keyed by ref) together with its `globalStyles`/`idStyle` and the type's `defaultStyle`, and\n fix the class that actually sets the property \u2014 do not just pile another class on top.\n- **Three kinds of style live in the style schema \u2014 do not confuse them:**\n - **Definitions** = reusable CSS **classes** (`upsertDefinition`/`patchDefinition`/`deleteDefinition`, keyed by a\n class `ref`). Attach one to an element via `style.base` to style **that** element (and anything else that opts in).\n This is the **default** way to style one element. Declaring MORE than one class in a batch? Use\n `upsertDefinitions` \u2014 one op carrying `{ \"<class>\": { desktop: \u2026 }, \u2026 }`, same result as the run of\n `upsertDefinition` it replaces, without repeating the envelope once per class.\n - **Global styles** = the CSS equivalent of a bare element selector like `button { \u2026 }`\n (`upsertGlobalStyle`/`patchGlobalStyle`/`deleteGlobalStyle`, keyed by `componentType`). They style **every**\n element of that type at once. Use these for site-wide intent \u2014 e.g. \"all buttons rounded\":\n `{ \"type\": \"upsertGlobalStyle\", \"componentType\": \"button\", \"desktop\": { \"border-radius\": \"9999px\" } }`.\n - **Id styles** = the CSS equivalent of an id selector like `#hero { \u2026 }`\n (`upsertIdStyle`/`patchIdStyle`/`deleteIdStyle`, keyed by `targetId`). They style the **single** element whose\n DOM `id` attribute equals `targetId` \u2014 so the element must carry that `id` (set it in its props). Prefer a\n **definition** for one element; reach for an id style only when a specific, uniquely-identified node must be\n targeted by id: `{ \"type\": \"upsertIdStyle\", \"targetId\": \"hero\", \"desktop\": { \"min-height\": \"100vh\" } }`.\n - The three share one name space, so an op refuses a name held by another kind (guards against a typo silently\n rewriting every element of a type, or converting a class into an id rule). If refused, you targeted the wrong\n kind \u2014 switch tools or rename.\n\n## Style variants & element state\nA **variant** is a named CSS override on a definition (e.g. a button class with a `primary` variant). It takes two\nsteps across the two schemas:\n- **Declare** the variant CSS on the class (style schema): `upsertDefinition`/`patchDefinition` with\n `variants: { \"primary\": { \"desktop\": { \"background-color\": \"#111\" } } }` (per slot under `slots.<slot>.variants`).\n- **Apply** it to an element (element schema): `initialState.styleVariant` =\n `{ \"<class-ref>\": { \"base\": \"primary\" } }` \u2014 a slot name instead of `base` targets that slot; an array applies\n several. Set it via `upsertElement`/`patchElement`.\nAn element read reports `availableVariants` (which variant each attached class offers) and the element's current\n`initialState`, so you can see a button **has** a `primary` variant and whether it uses it. If the user asks for a\nvariant that does not exist yet, **create it (upsertDefinition variants) and apply it in the same batch**.\n- `initialState.visibility` (boolean) sets whether the element starts shown or hidden.\n- The `hidden` state of a class is how it looks while hidden \u2014 where it goes and where it comes from. With a\n `transition` that includes `display 200ms allow-discrete`, it fades or slides in and out instead of blinking.\n\n**Ancestor conditions** \u2014 a class that changes inside an ANCESTOR (`.toolbar .icon`), or while that ancestor is\nhovered or in a variant (`.card:hover .icon`, a collapsed sidebar hiding its labels) is `ancestors` on that class,\nkeyed by a class the ancestor wears: `ancestors: { \"toolbar\": { \"desktop\": { \u2026 } }, \"card\": { \"states\": { \"hover\":\n{ \"desktop\": { \u2026 } } } }, \"sidebar\": { \"variants\": { \"collapsed\": \u2026 } } }`.\nAny ancestor counts, not only the parent; the class's own states and variants win over these. Never customCss for it.\n`\">\"` keys the parent, whatever it wears \u2014 a component's part reacting to what it sits in.\n\n**Pseudo-elements and conditions** sit beside `states` in a definition and in each of its variants:\n`pseudos: { \"after\": { \"desktop\": { \"content\": \"\\\"\u2192\\\"\" }, \"states\": { \"hover\": { \"desktop\": { \u2026 } } } } }`\n(`before`/`after` are drawn only with a quoted `content`; also `selection`, `marker`, `placeholder`,\n`first-letter`, `first-line`), and `conditions: { \"motion-reduce\": { \"desktop\": { \u2026 } }, \"container (max-width:\n30rem)\": { \u2026 } }` (the nearest ancestor whose class sets `container-type`). A patch keeps the ones it does not name;\n`null` removes one. A state beyond `hover`/`focus-visible`/`current`: `expanded` (an open trigger), `first`,\n`last`, `odd`, `even`.\n\n## Variables, design tokens and fonts\n- **Schema variables** are space-wide values a prop reads as `{{name}}`: `upsertVariable { name, variableType,\n value, category?, subValues? }` (`variableType` is the runtime type \u2014 `text`, `number`, \u2026 \u2014 not the op's\n `type`), `deleteVariable { name }`.\n- **Design tokens** are CSS values a definition reads as `var(--name)`: `upsertStyleVariable { category, name,\n value }` with `category` one of `color`, `spacing`, `shadow`, `custom` and `name` without the `--`. A\n `value` may be one string or `{ light, dark }`, so a colour follows the theme. `deleteStyleVariable` removes one.\n Reach for a token whenever a value repeats across classes \u2014 a hardcoded colour is a colour the theme cannot change.\n- **Fonts**: a `font-family` only renders in its face when the space loads that family. `upsertFont { family,\n source, fallback, weights? }` declares one \u2014 `source` `google` needs nothing else, `remote` a `stylesheet` or\n `files` URL, `system` loads nothing. `deleteFont { family }` stops loading it; rules that still name it render\n in their fallback.\n\n";