ain-ui 0.2.3 → 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.
- package/NOTICE +37 -0
- package/README.md +179 -77
- package/dist/agent.d.ts +131 -0
- package/dist/agent.js +802 -0
- package/dist/ainui.d.ts +15 -1
- package/dist/ainui.js +48 -10
- package/dist/basic.d.ts +5 -47
- package/dist/basic.js +11 -25
- package/dist/catalog/standard.gen.d.ts +5 -0
- package/dist/catalog/standard.gen.js +6 -0
- package/dist/catalog-v1.json +2560 -0
- package/dist/catalog.json +19917 -2061
- package/dist/chat.js +6 -7
- package/dist/expression.d.ts +23 -0
- package/dist/expression.js +222 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/macros.d.ts +12 -0
- package/dist/macros.js +57 -0
- package/dist/payment.js +6 -7
- package/dist/pickers.d.ts +158 -0
- package/dist/pickers.js +110 -0
- package/dist/protocol.d.ts +100 -0
- package/dist/protocol.js +232 -0
- package/dist/react/ain.d.ts +1 -0
- package/dist/react/ain.js +225 -0
- package/dist/react/catalog.d.ts +9 -0
- package/dist/react/catalog.js +23 -0
- package/dist/react/core.d.ts +84 -0
- package/dist/react/core.js +158 -0
- package/dist/react/functions.d.ts +2 -0
- package/dist/react/functions.js +29 -0
- package/dist/react/standard/composites.d.ts +1 -0
- package/dist/react/standard/composites.js +110 -0
- package/dist/react/standard/data.d.ts +1 -0
- package/dist/react/standard/data.js +481 -0
- package/dist/react/standard/feedback.d.ts +11 -0
- package/dist/react/standard/feedback.js +111 -0
- package/dist/react/standard/inputs.d.ts +5 -0
- package/dist/react/standard/inputs.js +467 -0
- package/dist/react/standard/layout.d.ts +5 -0
- package/dist/react/standard/layout.js +104 -0
- package/dist/react/standard/media.d.ts +33 -0
- package/dist/react/standard/media.js +208 -0
- package/dist/react/standard/rich.d.ts +1 -0
- package/dist/react/standard/rich.js +146 -0
- package/dist/react/standard/text.d.ts +9 -0
- package/dist/react/standard/text.js +209 -0
- package/dist/react/surface.d.ts +44 -0
- package/dist/react/surface.js +134 -0
- package/dist/react.d.ts +3 -35
- package/dist/react.js +3 -272
- package/dist/renderer.d.ts +1 -1
- package/dist/renderer.js +299 -4
- package/dist/styles.css +805 -20
- 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
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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,117 +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
|
|
20
|
-
|
|
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
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
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
|
|
30
|
-
The existing ID is retained for compatibility with aindrive clients.
|
|
50
|
+
## Catalog
|
|
31
51
|
|
|
32
|
-
|
|
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
|
-
|
|
|
55
|
+
| Group | Components |
|
|
35
56
|
| --- | --- |
|
|
36
|
-
|
|
|
37
|
-
|
|
|
38
|
-
|
|
|
39
|
-
|
|
|
40
|
-
|
|
|
41
|
-
|
|
|
42
|
-
|
|
|
43
|
-
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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 })`.
|
|
48
136
|
|
|
49
137
|
## Producers and transports
|
|
50
138
|
|
|
51
|
-
The package exports `ainuiFolder`, `ainuiFile`, `ainuiEditor`, `ainuiPayment`,
|
|
52
|
-
`ainuiForSkill`, and `dispatchAinuiAction`. File action execution is
|
|
53
|
-
with `run`, `allowed`, and `env`; hosts enforce identity, roles and path bounds.
|
|
54
|
-
|
|
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.
|
|
55
143
|
|
|
56
144
|
```ts
|
|
57
|
-
import { ainuiActivity, messagesFromActivity } from "ain-ui";
|
|
145
|
+
import { ainuiActivity, messagesFromActivity, upgradeMessages } from "ain-ui";
|
|
58
146
|
const event = ainuiActivity("files", messages);
|
|
59
147
|
// ACTIVITY_SNAPSHOT / a2ui-surface / content.a2ui_operations
|
|
60
148
|
```
|
|
61
149
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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.
|
|
65
157
|
|
|
66
158
|
## Upload
|
|
67
159
|
|
|
68
|
-
`FileUpload` emits `aindrive.upload` with `{drive_id, path, name, content,
|
|
69
|
-
|
|
70
|
-
the
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
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.
|
|
74
165
|
|
|
75
166
|
## x402
|
|
76
167
|
|
|
77
|
-
`ainuiPayment` uses the exact requirements that produced `PAYMENT-REQUIRED`.
|
|
78
|
-
`
|
|
79
|
-
the
|
|
80
|
-
|
|
81
|
-
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.
|
|
82
172
|
|
|
83
173
|
```ts
|
|
84
174
|
import { signX402Payment } from "ain-ui/x402";
|
|
85
175
|
const { header } = await signX402Payment(action.context.paymentRequired, signer);
|
|
86
176
|
```
|
|
87
177
|
|
|
88
|
-
This adapter uses official `@x402/core` and `@x402/evm` SDKs. It supports EVM
|
|
89
|
-
|
|
90
|
-
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.
|
|
91
180
|
|
|
92
181
|
## Other hosts
|
|
93
182
|
|
|
94
|
-
`ain-ui/renderer` exports the dependency-free DOM renderer and its CSS for
|
|
95
|
-
|
|
96
|
-
|
|
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`.
|
|
97
201
|
|
|
98
202
|
## Development
|
|
99
203
|
|
|
100
204
|
```sh
|
|
101
205
|
npm ci
|
|
102
|
-
npm run build
|
|
206
|
+
npm run build # catalog → src/catalog/standard.gen.ts, tsc, styles, dist/catalog.json
|
|
103
207
|
npm test
|
|
104
|
-
npm pack --dry-run
|
|
105
208
|
```
|
|
106
209
|
|
|
107
|
-
|
|
108
|
-
|
|
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.
|
|
109
213
|
|
|
110
|
-
|
|
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.
|
|
111
233
|
|
|
112
|
-
`
|
|
113
|
-
render a `FileView` with the host's document, spreadsheet or other rich preview.
|
|
114
|
-
The URLs have already passed the renderer's URL checks and asset resolver.
|
|
115
|
-
Keep authentication and file permissions in the host's byte-serving routes.
|
|
116
|
-
Omit this callback to use the built-in media preview and download view.
|
|
117
|
-
|
|
118
|
-
## Folder chat
|
|
119
|
-
|
|
120
|
-
`ainuiFolderChat(state)` produces the `FolderChat` A2UI catalog component.
|
|
121
|
-
`AinuiFolderChat` from `ain-ui/react` hosts agent selection, progressive replies,
|
|
122
|
-
stop, errors and per-folder/per-agent conversation ids. Supply `onSend` to connect
|
|
123
|
-
the host's authenticated API; it receives an AbortSignal and `onUpdate`.
|
|
124
|
-
`readChatStream` reads AG-UI SSE, including `ainui.chat.snapshot` custom events;
|
|
125
|
-
`ainuiActivity` wraps full folder-chat surfaces for other A2UI hosts.
|
|
126
|
-
`A2aChatAccumulator` combines A2A status/task/artifact events without replaying
|
|
127
|
-
a failed request or duplicating snapshot text. Native agents without streaming
|
|
128
|
-
continue to return one final response.
|
|
129
|
-
|
|
130
|
-
`listFolderTree` lists descendants within the selected root, with entry, depth
|
|
131
|
-
and directory limits. It reports partial/error results instead of treating them
|
|
132
|
-
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.
|
package/dist/agent.d.ts
ADDED
|
@@ -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 {};
|