ain-ui 0.2.1 → 1.0.3

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 (56) hide show
  1. package/NOTICE +37 -0
  2. package/README.md +179 -76
  3. package/dist/agent.d.ts +131 -0
  4. package/dist/agent.js +802 -0
  5. package/dist/ainui.d.ts +15 -1
  6. package/dist/ainui.js +59 -16
  7. package/dist/basic.d.ts +5 -47
  8. package/dist/basic.js +11 -25
  9. package/dist/catalog/standard.gen.d.ts +5 -0
  10. package/dist/catalog/standard.gen.js +6 -0
  11. package/dist/catalog-v1.json +2560 -0
  12. package/dist/catalog.json +19924 -2047
  13. package/dist/chat.js +6 -7
  14. package/dist/expression.d.ts +23 -0
  15. package/dist/expression.js +222 -0
  16. package/dist/index.d.ts +2 -0
  17. package/dist/index.js +2 -0
  18. package/dist/macros.d.ts +12 -0
  19. package/dist/macros.js +57 -0
  20. package/dist/payment.js +6 -7
  21. package/dist/pickers.d.ts +158 -0
  22. package/dist/pickers.js +110 -0
  23. package/dist/protocol.d.ts +100 -0
  24. package/dist/protocol.js +232 -0
  25. package/dist/react/ain.d.ts +1 -0
  26. package/dist/react/ain.js +225 -0
  27. package/dist/react/catalog.d.ts +9 -0
  28. package/dist/react/catalog.js +23 -0
  29. package/dist/react/core.d.ts +84 -0
  30. package/dist/react/core.js +158 -0
  31. package/dist/react/functions.d.ts +2 -0
  32. package/dist/react/functions.js +29 -0
  33. package/dist/react/standard/composites.d.ts +1 -0
  34. package/dist/react/standard/composites.js +110 -0
  35. package/dist/react/standard/data.d.ts +1 -0
  36. package/dist/react/standard/data.js +481 -0
  37. package/dist/react/standard/feedback.d.ts +11 -0
  38. package/dist/react/standard/feedback.js +111 -0
  39. package/dist/react/standard/inputs.d.ts +5 -0
  40. package/dist/react/standard/inputs.js +467 -0
  41. package/dist/react/standard/layout.d.ts +5 -0
  42. package/dist/react/standard/layout.js +104 -0
  43. package/dist/react/standard/media.d.ts +33 -0
  44. package/dist/react/standard/media.js +208 -0
  45. package/dist/react/standard/rich.d.ts +1 -0
  46. package/dist/react/standard/rich.js +146 -0
  47. package/dist/react/standard/text.d.ts +9 -0
  48. package/dist/react/standard/text.js +209 -0
  49. package/dist/react/surface.d.ts +44 -0
  50. package/dist/react/surface.js +134 -0
  51. package/dist/react.d.ts +3 -36
  52. package/dist/react.js +3 -240
  53. package/dist/renderer.d.ts +1 -1
  54. package/dist/renderer.js +307 -4
  55. package/dist/styles.css +850 -0
  56. package/package.json +28 -11
package/NOTICE ADDED
@@ -0,0 +1,37 @@
1
+ AIN-UI
2
+ Copyright (c) AI Network
3
+
4
+ This package includes material from other projects.
5
+
6
+ 1. CopilotKit — A2UI playground catalog
7
+ src/catalog/standard.json holds the names, props and descriptions of the 69 standard components and of the
8
+ catalog functions, and src/catalog/rich.json those of 13 of the playground's own components (Heading, Section,
9
+ Stat, …), taken from the catalog published by CopilotKit's A2UI playground
10
+ (https://github.com/CopilotKit/CopilotKit, examples/showcases/a2ui-playground; https://a2ui.open.bot/catalog.json),
11
+ so that surfaces written for that catalog are drawn by AIN-UI. The React views, styles and function
12
+ implementations in this package are AIN-UI's own.
13
+
14
+ The MIT License
15
+
16
+ Copyright (c) Atai Barkai
17
+
18
+ Permission is hereby granted, free of charge, to any person obtaining a copy
19
+ of this software and associated documentation files (the "Software"), to deal
20
+ in the Software without restriction, including without limitation the rights
21
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
22
+ copies of the Software, and to permit persons to whom the Software is
23
+ furnished to do so, subject to the following conditions:
24
+
25
+ The above copyright notice and this permission notice shall be included in
26
+ all copies or substantial portions of the Software.
27
+
28
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
29
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
30
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
31
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
32
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
33
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
34
+ THE SOFTWARE.
35
+
36
+ 2. A2UI — https://github.com/a2ui-project/a2ui (Apache-2.0)
37
+ Used as dependencies (@a2ui/web_core, @a2ui/react, @a2ui/agent, @a2ui/markdown-it), not copied.
package/README.md CHANGED
@@ -1,9 +1,18 @@
1
1
  # AIN-UI
2
2
 
3
- AIN-UI extends **A2UI v0.9** with grids, file tiles, private assets, file upload,
4
- and x402 payments. It carries these surfaces over standard **AG-UI** activity
5
- events, MCP metadata, or A2A DataParts. The React renderer extends the official
6
- `@a2ui/react` catalog; protocol state and bindings use `@a2ui/web_core`.
3
+ AIN-UI is an **A2UI 1.0** component library, renderer and agent toolkit.
4
+
5
+ - **One catalog, 79 components.** The 69 standard generative-UI components (the same names and props as
6
+ CopilotKit's Gen UI 2.0 standard catalog, so an agent written for one draws on the other) plus AIN's own for
7
+ files, upload, x402 payment, folder chat and pickers.
8
+ - **Two renderers.** React (`ain-ui/react`, on the official `@a2ui/react` + `@a2ui/web_core`) and a
9
+ dependency-free DOM renderer (`ain-ui/renderer`) for MCP Apps and non-React hosts.
10
+ - **The agent side.** `ain-ui/agent` gives a model the catalog, a `render_ui` tool, and checks and compiles what
11
+ the model writes — A2UI Express (one line per component) or JSON — before anything reaches a renderer.
12
+ - **A playground.** <https://ainui.ainetwork.xyz> — ask for a UI, see what the model wrote and what was drawn.
13
+
14
+ Surfaces travel over standard **AG-UI** activity events, MCP metadata, or A2A DataParts. v0.9 messages (and
15
+ AINUI v1 surfaces) are upgraded to 1.0 on the way in, so existing producers keep working.
7
16
 
8
17
  ## Install
9
18
 
@@ -16,116 +25,210 @@ npm install ain-ui react react-dom
16
25
  import { AinuiSurface } from "ain-ui/react";
17
26
  import "ain-ui/styles.css";
18
27
 
19
- <AinuiSurface messages={messages} onAction={handleAction}
20
- resolveAsset={(asset, options) => authorizedAssetUrl(asset, options)} />
28
+ <AinuiSurface
29
+ messages={messages}
30
+ onAction={handleAction}
31
+ sendMessage={(text) => sendUserMessage(text)}
32
+ resolveAsset={(asset, options) => authorizedAssetUrl(asset, options)}
33
+ theme="ain"
34
+ />
21
35
  ```
22
36
 
23
- `messages` is an A2UI v0.9 message array. `onAction` receives the resolved A2UI
24
- `{name, surfaceId, sourceComponentId, timestamp, context}` and can return a Promise.
25
- The component mounts in the browser (the upstream renderer does not support SSR).
37
+ - `messages` is an array of A2UI messages (1.0, or v0.9). **Appending** to the array updates the surfaces in
38
+ place — inputs keep their text, tabs their selection; any other change redraws.
39
+ - `onAction` receives the resolved action `{name, surfaceId, sourceComponentId, timestamp, context}` and can return
40
+ a Promise. `onMessage` receives every renderer→agent message as the 1.0 envelope; `onError` what was rejected.
41
+ - A message that does not match the catalog is **not drawn**: the surface shows the reason and `onError` is called.
42
+ - `sendMessage` is called when a `FollowUp` suggestion is chosen.
43
+ - `theme` picks a design system: `ain` (default), `plain`, `material`, `terminal`, or your own (below).
44
+ - The component mounts in the browser (the upstream renderer does not render on the server).
26
45
 
27
- ## Catalog
46
+ Tell the agent what this renderer draws with `ainuiCapabilities()` (catalog ids) or
47
+ `ainuiCapabilities({ inline: true })` (the catalog documents themselves), sent as
48
+ `a2uiRendererCapabilities` in the request metadata.
28
49
 
29
- Catalog ID: `https://aindrive.ainetwork.ai/ainui/v1/catalog.json`.
30
- The existing ID is retained for compatibility with aindrive clients.
50
+ ## Catalog
31
51
 
32
- All basic A2UI components are available, plus:
52
+ Catalog id: `https://ainui.ainetwork.xyz/catalogs/ainui/v2/catalog.json` (`AINUI_CATALOG`). The document is
53
+ `ain-ui/catalog.json`, and `AINUI_CATALOG_DOCUMENT` in code.
33
54
 
34
- | Component | Purpose |
55
+ | Group | Components |
35
56
  | --- | --- |
36
- | Grid | Responsive columns, including A2UI child templates |
37
- | Tile | File/folder thumbnail, label, caption and action |
38
- | FileView | Image, video, audio, PDF preview and download |
39
- | Breadcrumbs | Folder navigation |
40
- | Segmented | List/grid view selection |
41
- | FileUpload | Local file selection and upload action, up to 8 MiB per file |
42
- | X402Payment | Amount, currency, network, recipient and explicit payment action |
43
-
44
- Private files use `{$asset: {drive_id, path, variant, mime, v?}}` references.
45
- Hosts resolve them through their authenticated asset routes. Browser wallet
46
- keys and account credentials never belong in a surface.
57
+ | Layout | Box, Column, Row, Grid, GridItem, Card, Flow, FlowItem, Carousel, CarouselItem, CarouselMediaItem, Spacer, Divider, Tabs |
58
+ | Text | Title, Text, Caption, Label, Bold, Italic, Underline, Strikethrough, Badge, Blockquote, Code, Markdown, Math, ShimmerText, Link, Tooltip |
59
+ | Inputs | Button, Pressable, Form, TextField, TextArea, Select, CheckBox, Radio, RadioGroup, Slider, SegmentedControl, ChoicePicker, DateTimeInput |
60
+ | Data | Table, TableSection, TableRow, TableCell, List, ListItem, Chart, Map |
61
+ | Media | Image, Icon, Favicon, Svg, Video, AudioPlayer, HtmlView |
62
+ | Feedback | PulseIndicator, FlashcardFlip, Popover, PopoverTrigger, PopoverContent, Modal |
63
+ | Composites | LinkCard, Citation, FollowUp, EntityCard, ImageGrid |
64
+ | AIN | Toolbar, Tile, FileView, Breadcrumbs, Segmented, FileUpload, X402Payment, FolderChat, FilePicker, AgentPicker |
65
+
66
+ Functions: the A2UI basic ones (`required`, `regex`, `length`, `numeric`, `email`, `formatString`,
67
+ `formatNumber`, `formatCurrency`, `formatDate`, `pluralize`, `openUrl`, `and`, `or`, `not`) plus `calc`
68
+ (arithmetic over named values) and `series` (a generated list, for chart data). `calc` and `series` are evaluated
69
+ by a parser, never by `eval`.
70
+
71
+ Private files use `{$asset: {drive_id, path, variant, mime, v?}}` references. Hosts resolve them through their
72
+ authenticated asset routes (`resolveAsset`). Browser wallet keys and account credentials never belong in a surface.
73
+
74
+ Chart draws SVG itself; Map draws OpenStreetMap raster tiles (set `mapTileUrl` on the host to use another tile
75
+ server); Icon loads Lucide icons on demand; Math uses KaTeX when the host has it installed and shows the TeX
76
+ source otherwise.
77
+
78
+ ### Design systems
79
+
80
+ Every colour, radius and font is a CSS variable on `.ain-ui` (`src/styles/00-tokens.css`). Set them, or scope a
81
+ set under a theme name and pass it as `theme`:
82
+
83
+ ```css
84
+ .ain-ui[data-ainui-theme="mine"] {
85
+ --ainui-primary: #0f766e; --ainui-primary-fg: #fff;
86
+ --ainui-radius: 6px; --ainui-font: "Inter", sans-serif;
87
+ }
88
+ ```
89
+
90
+ `data-ainui-scheme="light" | "dark"` on the same element pins the colour scheme; without it the system setting decides.
91
+
92
+ ## Agents
93
+
94
+ ```ts
95
+ import { createUiAuthor, catalogsFor, rendererCapabilities } from "ain-ui/agent";
96
+ import { AINUI_MACROS } from "ain-ui/macros";
97
+
98
+ const capabilities = rendererCapabilities(request.metadata); // undefined → the client did not ask for A2UI
99
+ const author = createUiAuthor({ format: "json", catalogs: catalogsFor(capabilities), macros: AINUI_MACROS });
100
+
101
+ const reply = await openai.chat.completions.create({
102
+ model, tools: [author.tool],
103
+ messages: [{ role: "system", content: `${systemPrompt}\n\n${author.prompt}` }, ...history],
104
+ });
105
+ for (const call of reply.choices[0].message.tool_calls ?? []) {
106
+ try { send(author.fromToolCall(call.function.arguments)); } // validated A2UI 1.0 messages
107
+ catch (e) { if (e instanceof UiError) tellTheModel(call.id, e.message); else throw e; }
108
+ }
109
+ ```
110
+
111
+ - `format: "express"` — the model writes A2UI Express; `author.fromToolCall({ express })` compiles it.
112
+ `format: "json"` — the model passes `{ components, data }`; with `surfaceId` it updates an earlier surface.
113
+ - What a model usually gets wrong is forgiven rather than refused: a prop the component does not have is dropped,
114
+ a number written as a string is converted, an id that is not an identifier is renamed (references follow),
115
+ a component no parent uses is left out. Pass an array as the second argument to collect what was tidied.
116
+ Everything else comes back as a `UiError` whose message is written for the model.
117
+ - The prompt uses a compact catalog (containers without their twenty rarely used layout props); validation uses
118
+ the full one. `compact: false` lists everything.
119
+ - `author.fromText(text)` reads fenced blocks (`<a2ui>…</a2ui>`, `<a2ui-json>…</a2ui-json>`) for models without
120
+ tool calling. `toExpress(messages)` turns messages back into Express. `exportSkills({ format })` returns the
121
+ Markdown skill files that teach a coding agent this catalog.
122
+
123
+ ### As a service
124
+
125
+ The playground also serves the catalog guide and the checker to agent hosts that would rather not install this
126
+ package: `POST https://ainui.ainetwork.xyz/api/ui/author {capabilities, format?}` returns `{prompt, tool}` for the
127
+ catalogs the renderer draws, and `POST …/api/ui/render {capabilities, format?, args}` returns `{messages, notes}`
128
+ or `422 {error: {code: "ui_invalid", message}}` with a message to hand back to the model. No model is called.
129
+ ainize hosted agents use it for their `render_ui` tool.
130
+
131
+ ### Macros
132
+
133
+ A macro is one short call the model writes that the server expands into standard components before anything is
134
+ sent — the renderer never sees its name. `ain-ui/macros` has `FileCard`, `PaymentCard` and `AgentCard`; write your
135
+ own with `defineMacro({ name, description, props, expand })`.
47
136
 
48
137
  ## Producers and transports
49
138
 
50
- The package exports `ainuiFolder`, `ainuiFile`, `ainuiEditor`, `ainuiPayment`,
51
- `ainuiForSkill`, and `dispatchAinuiAction`. File action execution is injected
52
- with `run`, `allowed`, and `env`; hosts enforce identity, roles and path bounds.
53
- Aindrive's server adapters implement those callbacks.
139
+ The package exports `ainuiFolder`, `ainuiFile`, `ainuiEditor`, `ainuiPayment`, `ainuiFilePicker`,
140
+ `ainuiAgentPicker`, `ainuiForSkill`, and `dispatchAinuiAction`. They emit A2UI 1.0. File action execution is
141
+ injected with `run`, `allowed`, and `env`; hosts enforce identity, roles and path bounds. Aindrive's server
142
+ adapters implement those callbacks.
54
143
 
55
144
  ```ts
56
- import { ainuiActivity, messagesFromActivity } from "ain-ui";
145
+ import { ainuiActivity, messagesFromActivity, upgradeMessages } from "ain-ui";
57
146
  const event = ainuiActivity("files", messages);
58
147
  // ACTIVITY_SNAPSHOT / a2ui-surface / content.a2ui_operations
59
148
  ```
60
149
 
61
- Aindrive negotiation: MCP `X-AINUI: 1`, AG-UI `forwardedProps.ainui = true`,
62
- A2A `metadata.ainui = true`. Paid-share HTTP responses also accept `X-AINUI: 1`
63
- and include `messages` next to the unchanged x402 `PAYMENT-REQUIRED` header.
150
+ `upgradeMessages(messages)` converts v0.9 messages to 1.0 (bindings `{path}` → `{"@path"}`, `checks` →
151
+ `@checks`, heading `Text` → `Title`, the AINUI v1 catalog id → v2); `AinuiSurface` and the DOM renderer already
152
+ do it on input. MIME type: `application/a2ui+json` (`A2UI_MIME`).
153
+
154
+ Aindrive negotiation is unchanged: MCP `X-AINUI: 1`, AG-UI `forwardedProps.ainui = true`, A2A
155
+ `metadata.ainui = true`. Paid-share HTTP responses also accept `X-AINUI: 1` and include `messages` next to the
156
+ unchanged x402 `PAYMENT-REQUIRED` header.
64
157
 
65
158
  ## Upload
66
159
 
67
- `FileUpload` emits `aindrive.upload` with `{drive_id, path, name, content,
68
- encoding: "base64"}`. `path` is the destination folder. The dispatcher validates
69
- the name, encoding, decoded size, allow-list and write permission, then calls
70
- `write_file`. Existing names follow the storage host's overwrite policy.
71
- The 8 MiB limit keeps JSON transports bounded; larger files use the host's
72
- resumable upload endpoint. Do not put raw filesystem paths in client actions.
160
+ `FileUpload` emits `aindrive.upload` with `{drive_id, path, name, content, encoding: "base64"}`. `path` is the
161
+ destination folder. The dispatcher validates the name, encoding, decoded size, allow-list and write permission,
162
+ then calls `write_file`. Existing names follow the storage host's overwrite policy. The 8 MiB limit keeps JSON
163
+ transports bounded; larger files use the host's resumable upload endpoint. Do not put raw filesystem paths in
164
+ client actions.
73
165
 
74
166
  ## x402
75
167
 
76
- `ainuiPayment` uses the exact requirements that produced `PAYMENT-REQUIRED`.
77
- `X402Payment` emits `aindrive.x402.pay` only after a user click. The host obtains
78
- the user's wallet and handles signing locally, then sends `PAYMENT-SIGNATURE`
79
- to the original authorized resource. The server revalidates price, recipient
80
- and entitlement. No transfer is made by rendering a surface.
168
+ `ainuiPayment` uses the exact requirements that produced `PAYMENT-REQUIRED`. `X402Payment` emits
169
+ `aindrive.x402.pay` only after a user click. The host obtains the user's wallet and handles signing locally, then
170
+ sends `PAYMENT-SIGNATURE` to the original authorized resource. The server revalidates price, recipient and
171
+ entitlement. No transfer is made by rendering a surface.
81
172
 
82
173
  ```ts
83
174
  import { signX402Payment } from "ain-ui/x402";
84
175
  const { header } = await signX402Payment(action.context.paymentRequired, signer);
85
176
  ```
86
177
 
87
- This adapter uses official `@x402/core` and `@x402/evm` SDKs. It supports EVM
88
- exact EIP-3009 authorizations; Permit2 requires the host's approval flow.
89
- Aindrive's native checkout also supports Permit2 through its existing SDK flow.
178
+ This adapter uses official `@x402/core` and `@x402/evm` SDKs. It supports EVM exact EIP-3009 authorizations;
179
+ Permit2 requires the host's approval flow.
90
180
 
91
181
  ## Other hosts
92
182
 
93
- `ain-ui/renderer` exports the dependency-free DOM renderer and its CSS for
94
- MCP Apps and non-React hosts. Both renderers understand the same catalog.
95
- The pure protocol/builders are available from `ain-ui` without importing React.
183
+ `ain-ui/renderer` exports the dependency-free DOM renderer and its CSS for MCP Apps and non-React hosts. It
184
+ reads 1.0 and v0.9 messages and draws the A2UI basic components and the AIN components (files, payment,
185
+ pickers, folder chat); the rest of the standard catalog is React-only.
186
+
187
+ ### Host file previews
188
+
189
+ `AinuiSurface` accepts `renderFile({ src, download, name, mime, size })` to render a `FileView` with the host's
190
+ document, spreadsheet or other rich preview. The URLs have already passed the renderer's URL checks and asset
191
+ resolver. Keep authentication and file permissions in the host's byte-serving routes.
192
+
193
+ ## Moving from 0.x
194
+
195
+ - `AinuiSurface` takes the same props; `messages` may stay v0.9. Builders now return 1.0 messages
196
+ (`version: "1.0"`, `{"@path"}` bindings) — code that inspects their output must read the new shapes.
197
+ - `AINUI_CATALOG` is the v2 id; `AINUI_CATALOG_V1` is the old one. Surfaces naming v1 are upgraded.
198
+ - The React catalog replaces the A2UI basic components with the standard ones of the same name (a superset of
199
+ props). `Button` still accepts `action`, `confirm` and `tone`; `Grid` still accepts `minItemWidth`.
200
+ - `@a2ui/react` and `@a2ui/web_core` are now `^0.16.1`.
96
201
 
97
202
  ## Development
98
203
 
99
204
  ```sh
100
205
  npm ci
101
- npm run build
206
+ npm run build # catalog → src/catalog/standard.gen.ts, tsc, styles, dist/catalog.json
102
207
  npm test
103
- npm pack --dry-run
104
208
  ```
105
209
 
106
- Source extracted from aindrive's existing AINUI implementation. aindrive and
107
- ainmem consume this package; protocol and component changes belong here.
210
+ The playground is in `demo/` (`npm ci && npm run build && npm start` after building the library) and deploys to
211
+ ainize from the repository's `ainize.json`. `demo/evals/run.mjs` measures models and formats on a fixed set of
212
+ requests; `docs/PLAN-a2ui-1.0.md` is the plan this version followed.
108
213
 
109
- ### Host file previews
214
+ The standard components' names, props and descriptions come from CopilotKit's A2UI playground catalog (MIT);
215
+ see `NOTICE`.
216
+
217
+ ## AI Network integration versions
218
+
219
+ This repository takes part in the AI Network integration (shared files, shared agents, delegated access). It follows the version pins below. They are a **proposal** (plan item 20.4) and become final once all five products adopt them. PRs that change them use a `contract:` or `a2a:` title prefix.
220
+
221
+ | Component | Pinned version | Supported range | Deprecation schedule |
222
+ |---|---|---|---|
223
+ | Integration contract `@ain/integration-contracts` | **v1.1** (1.1.0); documents keep `contract: "1.0"` for all of 1.x | 1.x adds optional fields only; any change of meaning is 2.0 | After 2.0 ships, 1.x is still accepted for 6 months; a product may reject by the `contract` value |
224
+ | AIN-UI renderer (`ain-ui`) | **0.3.0** (catalog v1 URL unchanged; adds FilePicker/AgentPicker) | Consumers on 0.2.3 must move to 0.3.0 | Unknown components are skipped by the renderer (backward compatible) |
225
+ | A2A | **0.3.0** (Ainize cards advertise 1.0 and 0.3) | 0.3.0 required for product consumers; 1.0 optional | 0.3 support ends 3 months after all five products can negotiate 1.0 |
226
+ | A2A data parts | `ai.ain/file-refs`, `ai.ain/delegation` (`metadata.type`) | Names never change | Fields are only added |
227
+ | Delegation token | `ain-rdlg+jwt`, TTL ≤ 1 h | Verified with the SSO SDK `verifyResourceDelegation` | Claims are only added; removing one is 2.0 |
228
+ | aindrive file IDs | Phase A `p1:` | When Phase B `f1:` lands, `p1:` stays valid for 6 months with a `movedFrom` hint in listings | `legacy.path` is not a durable identifier |
229
+
230
+ Product routes (`/api/ain/shared-files`, `/api/ain/shared-agents`, `/api/ain/invoke`, `/api/ain/events`) sit behind the `AIN_INTEGRATION_ENABLED` flag.
231
+
232
+ This package is the renderer; its current version is 1.0.0 (A2UI 1.0, catalog v2; v0.9 and catalog v1 surfaces are still drawn). The renderer pin in the table above is the integration proposal's and has not been revisited for 1.0. Consumers still on 0.2.3 need to upgrade; see "Moving from 0.x" above.
110
233
 
111
- `AinuiSurface` accepts `renderFile({ src, download, name, mime, size })` to
112
- render a `FileView` with the host's document, spreadsheet or other rich preview.
113
- The URLs have already passed the renderer's URL checks and asset resolver.
114
- Keep authentication and file permissions in the host's byte-serving routes.
115
- Omit this callback to use the built-in media preview and download view.
116
-
117
- ## Folder chat
118
-
119
- `ainuiFolderChat(state)` produces the `FolderChat` A2UI catalog component.
120
- `AinuiFolderChat` from `ain-ui/react` hosts agent selection, progressive replies,
121
- stop, errors and per-folder/per-agent conversation ids. Supply `onSend` to connect
122
- the host's authenticated API; it receives an AbortSignal and `onUpdate`.
123
- `readChatStream` reads AG-UI SSE, including `ainui.chat.snapshot` custom events;
124
- `ainuiActivity` wraps full folder-chat surfaces for other A2UI hosts.
125
- `A2aChatAccumulator` combines A2A status/task/artifact events without replaying
126
- a failed request or duplicating snapshot text. Native agents without streaming
127
- continue to return one final response.
128
-
129
- `listFolderTree` lists descendants within the selected root, with entry, depth
130
- and directory limits. It reports partial/error results instead of treating them
131
- as an empty or complete folder. No host credentials belong in UI messages.
234
+ The source of record is the integration plan's versioning note (`docs/20-versioning.md` in the ain-integration workspace, not yet published). This line will link to it once it is published.
@@ -0,0 +1,131 @@
1
+ import { type A2uiComponent, type A2uiMessage } from "./protocol.js";
2
+ export type UiFormat = "express" | "json";
3
+ export declare const RENDER_UI_TOOL = "render_ui";
4
+ /** Where a renderer's capabilities travel in request metadata (A2A `metadata`, AG-UI `forwardedProps`, MCP `_meta`). */
5
+ export declare const RENDERER_CAPABILITIES_KEY = "a2uiRendererCapabilities";
6
+ type Doc = Record<string, any>;
7
+ /**
8
+ * A macro is one component the model writes that the server expands into several standard ones before anything is
9
+ * sent: `WeatherReport("Lisbon")` instead of twenty lines. The renderer never sees the macro's name.
10
+ */
11
+ export type Macro = {
12
+ name: string;
13
+ description: string;
14
+ /** JSON Schema `properties` of the macro's own props. */
15
+ props: Record<string, Doc>;
16
+ required?: string[];
17
+ /**
18
+ * The components that replace the macro. The first one returned is the root and takes the macro's id; name the
19
+ * others with `id(key)` — the same key gives the same id, so a parent can refer to a child it lists later.
20
+ */
21
+ expand: (props: Record<string, any>, id: (type: string) => string) => Array<Omit<A2uiComponent, "id"> & {
22
+ id?: string;
23
+ }>;
24
+ };
25
+ export declare const defineMacro: (macro: Macro) => Macro;
26
+ /** Replaces every macro in a component list with its expansion, repeatedly, so a macro may use another. */
27
+ export declare function expandMacros(components: A2uiComponent[], macros: readonly Macro[]): A2uiComponent[];
28
+ /** The AINUI catalog document, optionally narrowed to some components (a smaller prompt, a stricter check). */
29
+ export declare function ainuiCatalogDocument(options?: {
30
+ components?: readonly string[];
31
+ }): Doc;
32
+ /**
33
+ * What the renderer on the other end said it can draw, read from request metadata. `undefined` means it did not
34
+ * ask for A2UI: answer in text.
35
+ */
36
+ export declare function rendererCapabilities(metadata: unknown): Record<string, any> | undefined;
37
+ /**
38
+ * The catalog documents to write for, given a renderer's capabilities: the catalogs it sent inline (a browser that
39
+ * brings its own design system), else AIN-UI's own when the renderer lists its id.
40
+ */
41
+ export declare function catalogsFor(capabilities: Record<string, any> | undefined): Doc[];
42
+ /**
43
+ * The catalog as the model is told it: container components lose the twenty layout props almost no surface
44
+ * needs (the same list on fourteen components is a third of the prompt). The renderer's catalog is unchanged, so
45
+ * a surface that does use one of them is still valid.
46
+ */
47
+ export declare function compactCatalogDocument(doc: Doc): Doc;
48
+ /**
49
+ * Reads JSON a model wrote as a string, repairing the one mistake it makes most: a closing bracket that does
50
+ * not match (`…"/x"}}}}, {"id": …` inside an array, or `…}]}]` at the end). Such a closer is dropped and
51
+ * counted; closers missing at the end are added. Strings are never touched, and anything else that does not
52
+ * parse still fails.
53
+ */
54
+ export declare function leadingJson(text: string): {
55
+ value: unknown;
56
+ trailing: number;
57
+ } | undefined;
58
+ /**
59
+ * Messages that replace a surface the renderer already shows with a whole new one under the same id: delete it,
60
+ * then create it again (1.0 allows the id again once it was deleted).
61
+ */
62
+ export declare function replaceSurface(surfaceId: string, catalogId: string, components: A2uiComponent[], dataModel?: Record<string, unknown>): A2uiMessage[];
63
+ /** One line per component: name, what it is for, and its props with types. A fraction of the full JSON Schema. */
64
+ export declare function catalogGuide(doc: Doc): string;
65
+ export type UiAuthorOptions = {
66
+ format?: UiFormat;
67
+ /** Catalog documents to write for. Defaults to the AINUI catalog. Usually `catalogsFor(capabilities)`. */
68
+ catalogs?: Doc[];
69
+ macros?: readonly Macro[];
70
+ /** Short worked examples, by name, appended to the prompt after the built-in one. */
71
+ examples?: Record<string, string>;
72
+ /** Tell the model the compact catalog (default). `false` lists every prop of every component. */
73
+ compact?: boolean;
74
+ };
75
+ export type RenderUiCall = {
76
+ express?: unknown;
77
+ components?: unknown;
78
+ data?: unknown;
79
+ surfaceId?: unknown;
80
+ messages?: unknown;
81
+ ui?: unknown;
82
+ };
83
+ export type UiPart = {
84
+ type: "text";
85
+ text: string;
86
+ } | {
87
+ type: "a2ui";
88
+ messages: A2uiMessage[];
89
+ };
90
+ export declare class UiError extends Error {
91
+ readonly cause?: unknown | undefined;
92
+ /** Written for the model: what was wrong and how to say it again. */
93
+ constructor(message: string, cause?: unknown | undefined);
94
+ }
95
+ export type UiAuthor = {
96
+ format: UiFormat;
97
+ /** Append to the system prompt. */
98
+ prompt: string;
99
+ /** The `render_ui` tool in OpenAI function-calling shape. */
100
+ tool: {
101
+ type: "function";
102
+ function: {
103
+ name: string;
104
+ description: string;
105
+ parameters: Doc;
106
+ };
107
+ };
108
+ /**
109
+ * Validated A2UI 1.0 messages from a `render_ui` call. Throws `UiError` with a message to hand back to the model.
110
+ * `notes` collects what was forgiven on the way (an unknown prop dropped, a number written as a string).
111
+ */
112
+ fromToolCall(args: RenderUiCall | string, notes?: string[]): A2uiMessage[];
113
+ /** For models without tool calling: text with fenced UI blocks (`<a2ui>…</a2ui>`, `<a2ui-json>…</a2ui-json>`). */
114
+ fromText(text: string): UiPart[];
115
+ /** Ids of the catalogs this author writes for. */
116
+ catalogIds: string[];
117
+ };
118
+ /** Everything one agent turn needs to let a model show UI in the given catalogs and format. */
119
+ export declare function createUiAuthor(options?: UiAuthorOptions): UiAuthor;
120
+ /** The Express source that compiles to these messages — for showing both forms side by side. */
121
+ export declare function toExpress(messages: readonly A2uiMessage[], catalogs?: Doc[]): string;
122
+ /**
123
+ * Agent skill files (Markdown) that teach a coding agent or another model to write for these catalogs:
124
+ * `{ filename: content }`.
125
+ */
126
+ export declare function exportSkills(options?: {
127
+ format?: UiFormat;
128
+ catalogs?: Doc[];
129
+ macros?: readonly Macro[];
130
+ }): Record<string, string>;
131
+ export {};