@cascivo/render 1.9.0 → 1.10.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.
- package/README.md +72 -0
- package/dist/a2ui-v0_9.d.ts +200 -0
- package/dist/a2ui-v0_9.js +2 -0
- package/dist/cascivo-view-4DY6JqQA.js +2 -0
- package/dist/index.js +1 -1
- package/dist/node-props-LGzuaTTg.js +1 -0
- package/dist/prop-schemas-7gVWDISz.js +1 -0
- package/dist/validate.d.ts +2 -1
- package/dist/validate.js +1 -1
- package/dist/view-text.js +1 -1
- package/package.json +14 -6
- package/readme.body.md +72 -0
- package/schema/a2ui/v0_9/catalog.json +5008 -0
- package/schema/catalog.v1.json +4751 -0
- package/schema/view.v1.json +16246 -2187
- package/dist/cascivo-view-CJJjyYmv.js +0 -2
- package/dist/validate-CbBCjijl.js +0 -1
package/dist/validate.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
interface ValidationError {
|
|
2
2
|
path: string;
|
|
3
3
|
message: string;
|
|
4
4
|
}
|
|
@@ -14,4 +14,5 @@ export declare function validateView(config: unknown, options?: ValidateViewOpti
|
|
|
14
14
|
valid: boolean;
|
|
15
15
|
errors: ValidationError[];
|
|
16
16
|
};
|
|
17
|
+
export type { ValidationError };
|
|
17
18
|
//# sourceMappingURL=validate.d.mts.map
|
package/dist/validate.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as
|
|
1
|
+
import{a as e,c as t,i as n,r,s as i,t as a}from"./prop-schemas-7gVWDISz.js";var o=/^\$data\./,s=/^\$state\./,c=/^\$actions\./,l=/^\$state\.set\./,u=/^\$state\.toggle\./;function validateProps(t,i,a,o,s,c){let l=new Map(i.map(e=>[e.name,e])),u=i.map(e=>e.name);for(let[i,d]of Object.entries(t)){if(a.has(i))continue;n(d,i,`${s}.props.${i}`,c);let t=l.get(i);if(!t){let t=e(i,u),n=t?` Did you mean "${t}"?`:``;c.push({path:`${s}.props.${i}`,message:`Unknown prop "${i}" for component "${o}".${n}`});continue}r(t,d,`${s}.props.${i}`,i,c)}}function validateNode(n,r,i,d,f){if(typeof n!=`object`||!n){i.push({path:r,message:`Expected a component node object`});return}let p=n;if(typeof p.component!=`string`){i.push({path:`${r}.component`,message:`component must be a string`});return}let m=p.component;if(!t.has(m)&&!f.has(m)){let n=e(m,[...t,...f]),a=n?` Did you mean "${n}"?`:``;i.push({path:`${r}.component`,message:`Unknown component "${m}".${a}`});return}let h=p.bind??{};for(let[e,t]of Object.entries(h))if(typeof t!=`string`||!o.test(t)&&!s.test(t))i.push({path:`${r}.bind.${e}`,message:`bind values must start with "$data." or "$state." — got "${t}"`});else if(s.test(t)){let n=t.slice(7);if(!d.keys.has(n)){let t=suggestKey(n,d.keys);i.push({path:`${r}.bind.${e}`,message:`Unknown state key "${n}" — declare it in the top-level "state" object.${t}`})}}let g=p.events??{};for(let[e,t]of Object.entries(g)){let n=l.test(t)||u.test(t);if(typeof t!=`string`||!c.test(t)&&!n)i.push({path:`${r}.events.${e}`,message:`events values must start with "$actions.", "$state.set." or "$state.toggle." — got "${t}"`});else if(n){let n=u.test(t),a=t.slice(n?14:11);if(d.keys.has(a))n&&!d.booleans.has(a)&&i.push({path:`${r}.events.${e}`,message:`"$state.toggle.${a}" requires a boolean initial value in "state".`});else{let t=suggestKey(a,d.keys);i.push({path:`${r}.events.${e}`,message:`Unknown state key "${a}" — declare it in the top-level "state" object.${t}`})}}}let _=f.has(m)?void 0:a[m],v=p.props;if(_&&typeof v==`object`&&v&&!Array.isArray(v)&&validateProps(v,_,/* @__PURE__ */ new Set([...Object.keys(h),...Object.keys(g)]),m,r,i),Array.isArray(p.children))for(let e=0;e<p.children.length;e++)validateNode(p.children[e],`${r}.children[${e}]`,i,d,f)}function suggestKey(t,n){let r=e(t,[...n]);return r?` Did you mean "${r}"?`:``}function validateView(e,t){let n=[],r=new Set(t?.components??[]);if(typeof e!=`object`||!e)return{valid:!1,errors:[{path:``,message:`Config must be an object`}]};let a=e,o={keys:/* @__PURE__ */ new Set,booleans:/* @__PURE__ */ new Set},s=a.state;if(s!==void 0){if(typeof s!=`object`||!s||Array.isArray(s))n.push({path:`state`,message:`state must be an object of primitive values`});else for(let[e,t]of Object.entries(s)){let r=i(t);if(r===`object`){n.push({path:`state.${e}`,message:`state values must be string, number, boolean, or null — got object.`});continue}o.keys.add(e),r===`boolean`&&o.booleans.add(e)}}let c=a.view;if(typeof c!=`object`||!c)return{valid:!1,errors:[...n,{path:`view`,message:`view must be an object`}]};let l=c.regions;if(typeof l!=`object`||!l)return n.push({path:`view.regions`,message:`view.regions must be an object`}),{valid:!1,errors:n};for(let[e,t]of Object.entries(l)){if(!Array.isArray(t)){n.push({path:`view.regions.${e}`,message:`Region "${e}" must be an array of component nodes`});continue}for(let i=0;i<t.length;i++)validateNode(t[i],`view.regions.${e}[${i}]`,n,o,r)}return{valid:n.length===0,errors:n}}export{validateView};
|
package/dist/view-text.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e}from"./cascivo-view-
|
|
1
|
+
import{n as e}from"./cascivo-view-4DY6JqQA.js";import{createElement as t}from"react";import{toMarkdown as n}from"@cascivo/text";import{renderToStaticMarkup as r}from"react-dom/server";function viewToMarkdown(i,a){let o=r(t(e,{config:i,...a?.data===void 0?{}:{data:a.data},...a?.components===void 0?{}:{components:a.components}}));return n(o,a?.text)}export{viewToMarkdown};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cascivo/render",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Render a JSON view config with real cascivo components — the runtime behind the MCP scaffold_view / validate_view tools, plus machine mode for views. Docs offline: npx @cascivo/docs",
|
|
6
6
|
"keywords": [
|
|
@@ -45,23 +45,31 @@
|
|
|
45
45
|
"import": "./dist/validate.js",
|
|
46
46
|
"default": "./dist/validate.js"
|
|
47
47
|
},
|
|
48
|
-
"./
|
|
48
|
+
"./a2ui/v0_9": {
|
|
49
|
+
"types": "./dist/a2ui-v0_9.d.ts",
|
|
50
|
+
"import": "./dist/a2ui-v0_9.js",
|
|
51
|
+
"default": "./dist/a2ui-v0_9.js"
|
|
52
|
+
},
|
|
53
|
+
"./schema/view.v1.json": "./schema/view.v1.json",
|
|
54
|
+
"./schema/catalog.v1.json": "./schema/catalog.v1.json",
|
|
55
|
+
"./schema/a2ui/v0_9/catalog.json": "./schema/a2ui/v0_9/catalog.json"
|
|
49
56
|
},
|
|
50
57
|
"publishConfig": {
|
|
51
58
|
"access": "public",
|
|
52
59
|
"provenance": true
|
|
53
60
|
},
|
|
54
61
|
"dependencies": {
|
|
55
|
-
"@cascivo/core": "^1.
|
|
56
|
-
"@cascivo/i18n": "^1.
|
|
57
|
-
"@cascivo/react": "^1.
|
|
58
|
-
"@cascivo/text": "^1.
|
|
62
|
+
"@cascivo/core": "^1.10.0",
|
|
63
|
+
"@cascivo/i18n": "^1.10.0",
|
|
64
|
+
"@cascivo/react": "^1.10.0",
|
|
65
|
+
"@cascivo/text": "^1.10.0"
|
|
59
66
|
},
|
|
60
67
|
"devDependencies": {
|
|
61
68
|
"@testing-library/react": "^16.3.2",
|
|
62
69
|
"@types/node": "^25",
|
|
63
70
|
"@types/react": "^19.2.17",
|
|
64
71
|
"@types/react-dom": "^19.2.3",
|
|
72
|
+
"ajv": "^8.20.0",
|
|
65
73
|
"jsdom": "^29",
|
|
66
74
|
"react": "^19.2.7",
|
|
67
75
|
"react-dom": "^19.2.7",
|
package/readme.body.md
CHANGED
|
@@ -83,3 +83,75 @@ const { valid, errors } = validateView(modelOutput)
|
|
|
83
83
|
`cascivo create --framework cloudflare --example agent` builds an assistant around exactly this: the Worker validates each view the model produces, and the page renders it with `<CascivoView>`.
|
|
84
84
|
|
|
85
85
|
Pair it with the MCP server's bound-vocabulary grammar (`get_view_grammar`) and `scaffold_view` for the full anti-hallucination loop: the model can only emit components and props that exist, and `validateView` is the enforcement backstop. `cascivo generate <config.json>` converts a validated `ViewConfig` into owned TSX when you want to graduate from JSON to source.
|
|
86
|
+
|
|
87
|
+
## Component catalog
|
|
88
|
+
|
|
89
|
+
The renderable vocabulary is also published as data, generated from the same manifests the validator uses, so other tools can target cascivo without importing React:
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
import catalog from '@cascivo/render/schema/catalog.v1.json' with { type: 'json' }
|
|
93
|
+
import a2ui from '@cascivo/render/schema/a2ui/v0_9/catalog.json' with { type: 'json' }
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
- `schema/catalog.v1.json` is the protocol-neutral catalog: one entry per renderable component.
|
|
97
|
+
- `schema/a2ui/v0_9/catalog.json` is the same catalog as an [A2UI](https://a2ui.org) v0.9 custom catalog. Its `catalogId` is `https://cascivo.com/a2ui/v0_9/catalog.json`, and the file is served there.
|
|
98
|
+
|
|
99
|
+
Every prop of a component is sorted into one of four kinds:
|
|
100
|
+
|
|
101
|
+
| Kind | Meaning |
|
|
102
|
+
| --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
103
|
+
| `props` | Data props, each with a JSON Schema |
|
|
104
|
+
| `slots` | Child content, with arity `one` or `many` (`text: true` when it also takes a string, as `children` does; `implicit: true` when inferred from source) |
|
|
105
|
+
| `events` | Callbacks an agent can wire to an action |
|
|
106
|
+
| `omitted` | Props that cannot cross the wire (functions, DOM refs), with the reason |
|
|
107
|
+
|
|
108
|
+
`validateView` also checks the shape of object and array props, such as `DataTable` `columns`: nested fields by presence and type, so an unknown nested field is allowed.
|
|
109
|
+
|
|
110
|
+
Regenerate both files with `pnpm regen` (or `pnpm schema:generate && vp check --fix`); CI fails when the committed files drift from the manifests. `pnpm schema:check` runs the generator unit tests.
|
|
111
|
+
|
|
112
|
+
## Render A2UI
|
|
113
|
+
|
|
114
|
+
`@cascivo/render/a2ui/v0_9` renders [A2UI](https://a2ui.org) v0.9 messages with cascivo components. It is our own renderer, not `@a2ui/react`: that package brings lit, zod, a second signals store and custom elements. The store holds messages as signals, so a data change re-renders only the nodes bound to it.
|
|
115
|
+
|
|
116
|
+
```tsx
|
|
117
|
+
import {
|
|
118
|
+
A2uiSurface,
|
|
119
|
+
createA2uiStore,
|
|
120
|
+
defaultCatalogs,
|
|
121
|
+
defaultCatalogSpecs,
|
|
122
|
+
} from '@cascivo/render/a2ui/v0_9'
|
|
123
|
+
|
|
124
|
+
const store = createA2uiStore({ catalogs: defaultCatalogSpecs })
|
|
125
|
+
|
|
126
|
+
// Feed it each message the agent sends, already parsed from JSON. `apply` never throws and
|
|
127
|
+
// returns the errors to send back to the agent.
|
|
128
|
+
export const feed = (raw: unknown) => store.apply(raw)
|
|
129
|
+
|
|
130
|
+
export function Agent({ send }: { send: (action: unknown) => void }) {
|
|
131
|
+
return <A2uiSurface store={store} surfaceId="main" catalogs={defaultCatalogs} onAction={send} />
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
The entry has no `'use client'`; in React Server Components apps import `A2uiSurface` from a client module.
|
|
136
|
+
|
|
137
|
+
### Catalogs
|
|
138
|
+
|
|
139
|
+
- The **cascivo catalog** (`cascivoCatalog`, spec `cascivoCatalogSpec`, id `A2UI_CATALOG_ID`) lets an agent target real cascivo components, the same vocabulary `validateView` checks.
|
|
140
|
+
- The **basic catalog** (`basicCatalog`, spec `basicCatalogSpec`, id `BASIC_CATALOG_ID`) is A2UI's standard set, drawn with cascivo components.
|
|
141
|
+
|
|
142
|
+
A surface uses the catalog its `createSurface` message names; the store only knows the catalogs passed to `createA2uiStore`, so inline catalogs are refused.
|
|
143
|
+
|
|
144
|
+
### Security and limits
|
|
145
|
+
|
|
146
|
+
- Every message is validated against the catalog spec before it reaches state; a bad one becomes an `A2uiErrorMessage`, never an exception.
|
|
147
|
+
- URLs that reach `href`, `src` or `window.open` are checked, and unsafe ones are dropped.
|
|
148
|
+
- A value bound in from the data model, or computed by a function, is checked against the prop's schema when it renders; one that does not fit is dropped and reported as `RENDER_ERROR`. `{$t}` translation refs are refused: an agent cannot know the host's i18n keys.
|
|
149
|
+
- `openUrl` runs only as an action's top-level `functionCall`, and only when its handler gets a trusted click, key or pointerup event on the control (and, where the browser has `navigator.userActivation`, while it is active). An action the agent triggers, such as closing a Modal by writing its `open`, cannot open a page, and nor can an `openUrl` nested in another call or an event's context; the spec refuses it anywhere else. A custom adapter passes `action(prop)` as the handler itself, so the event reaches it.
|
|
150
|
+
- Each component renders inside an error boundary: one that throws (an adapter of your own too) renders nothing and reports `RENDER_ERROR` once, and the rest of the surface and the host keep rendering. The next data-model write retries it. A cascivo component whose required prop has no data yet renders a Skeleton until it arrives.
|
|
151
|
+
- An action's `a2uiClientDataModel` carries only the acting surface's data model, never another agent's.
|
|
152
|
+
- `createA2uiStore({ limits })` overrides `DEFAULT_A2UI_LIMITS`: surfaces, components, id length, data nodes, render depth and `maxRenderNodes` (default 20000, so shared ids cannot fan a tree out exponentially).
|
|
153
|
+
- The `regex` function refuses patterns with more than 2 quantifiers (an exact `{n}` does not count), repeat counts above 99, backreferences, nested quantifiers, and values over 256 characters.
|
|
154
|
+
|
|
155
|
+
### Custom adapters
|
|
156
|
+
|
|
157
|
+
An `A2uiAdapter` receives an `AdapterInput` (`component`, `prop`, `slot`, `children`, `resolve`, `typeOf`, `componentOf`, `writer`, `action`, `failingChecks`, `report`). Call `slot()` and `children()` at most once each, synchronously while the adapter runs, and place each returned node once. Later calls render nothing, because the render-node budget counts every node.
|