ain-ui 0.1.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/LICENSE +21 -0
- package/README.md +107 -0
- package/dist/agui.d.ts +11 -0
- package/dist/agui.js +11 -0
- package/dist/ainui.d.ts +173 -0
- package/dist/ainui.js +462 -0
- package/dist/basic.d.ts +92 -0
- package/dist/basic.js +247 -0
- package/dist/catalog.json +2268 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +4 -0
- package/dist/payment.d.ts +13 -0
- package/dist/payment.js +23 -0
- package/dist/react.d.ts +13 -0
- package/dist/react.js +173 -0
- package/dist/renderer.d.ts +34 -0
- package/dist/renderer.js +602 -0
- package/dist/styles.css +6 -0
- package/dist/types.d.ts +9 -0
- package/dist/types.js +1 -0
- package/dist/x402.d.ts +8 -0
- package/dist/x402.js +16 -0
- package/package.json +74 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 AI Network
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# AIN-UI
|
|
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`.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
npm install ain-ui react react-dom
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
"use client";
|
|
16
|
+
import { AinuiSurface } from "ain-ui/react";
|
|
17
|
+
import "ain-ui/styles.css";
|
|
18
|
+
|
|
19
|
+
<AinuiSurface messages={messages} onAction={handleAction}
|
|
20
|
+
resolveAsset={(asset, options) => authorizedAssetUrl(asset, options)} />
|
|
21
|
+
```
|
|
22
|
+
|
|
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).
|
|
26
|
+
|
|
27
|
+
## Catalog
|
|
28
|
+
|
|
29
|
+
Catalog ID: `https://aindrive.ainetwork.ai/ainui/v1/catalog.json`.
|
|
30
|
+
The existing ID is retained for compatibility with aindrive clients.
|
|
31
|
+
|
|
32
|
+
All basic A2UI components are available, plus:
|
|
33
|
+
|
|
34
|
+
| Component | Purpose |
|
|
35
|
+
| --- | --- |
|
|
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.
|
|
47
|
+
|
|
48
|
+
## Producers and transports
|
|
49
|
+
|
|
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.
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import { ainuiActivity, messagesFromActivity } from "ain-ui";
|
|
57
|
+
const event = ainuiActivity("files", messages);
|
|
58
|
+
// ACTIVITY_SNAPSHOT / a2ui-surface / content.a2ui_operations
|
|
59
|
+
```
|
|
60
|
+
|
|
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.
|
|
64
|
+
|
|
65
|
+
## Upload
|
|
66
|
+
|
|
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.
|
|
73
|
+
|
|
74
|
+
## x402
|
|
75
|
+
|
|
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.
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
import { signX402Payment } from "ain-ui/x402";
|
|
84
|
+
const { header } = await signX402Payment(action.context.paymentRequired, signer);
|
|
85
|
+
```
|
|
86
|
+
|
|
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.
|
|
90
|
+
|
|
91
|
+
## Other hosts
|
|
92
|
+
|
|
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.
|
|
96
|
+
|
|
97
|
+
## Development
|
|
98
|
+
|
|
99
|
+
```sh
|
|
100
|
+
npm ci
|
|
101
|
+
npm run build
|
|
102
|
+
npm test
|
|
103
|
+
npm pack --dry-run
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Source extracted from aindrive's existing AINUI implementation. aindrive and
|
|
107
|
+
ainmem consume this package; protocol and component changes belong here.
|
package/dist/agui.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { A2uiMessage } from "./basic.js";
|
|
2
|
+
/** AIN-UI uses standard AG-UI activity events; no parallel event protocol. */
|
|
3
|
+
export declare function ainuiActivity(activityId: string, messages: A2uiMessage[]): {
|
|
4
|
+
type: "ACTIVITY_SNAPSHOT";
|
|
5
|
+
messageId: string;
|
|
6
|
+
activityType: string;
|
|
7
|
+
content: {
|
|
8
|
+
a2ui_operations: A2uiMessage[];
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export declare function messagesFromActivity(event: unknown): A2uiMessage[] | null;
|
package/dist/agui.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** AIN-UI uses standard AG-UI activity events; no parallel event protocol. */
|
|
2
|
+
export function ainuiActivity(activityId, messages) {
|
|
3
|
+
return { type: "ACTIVITY_SNAPSHOT", messageId: activityId, activityType: "a2ui-surface", content: { a2ui_operations: messages } };
|
|
4
|
+
}
|
|
5
|
+
export function messagesFromActivity(event) {
|
|
6
|
+
if (!event || typeof event !== "object")
|
|
7
|
+
return null;
|
|
8
|
+
const e = event;
|
|
9
|
+
return e.type === "ACTIVITY_SNAPSHOT" && e.activityType === "a2ui-surface" && Array.isArray(e.content?.a2ui_operations)
|
|
10
|
+
? e.content.a2ui_operations : null;
|
|
11
|
+
}
|
package/dist/ainui.d.ts
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AINUI v1 โ A2UI v0.9 with aindrive's custom catalog (spec: docs/AINUI.md).
|
|
3
|
+
*
|
|
4
|
+
* Same messages, component model, data binding and actions as ./index.ts; the
|
|
5
|
+
* surfaces declare AINUI_CATALOG and may use, besides every basic component,
|
|
6
|
+
* Grid, Tile, FileView, Breadcrumbs and Segmented. Private file bytes are never
|
|
7
|
+
* embedded: the data model carries asset references ({$asset: โฆ}) that each host
|
|
8
|
+
* resolves through its own authorized route.
|
|
9
|
+
*
|
|
10
|
+
* ainuiForSkill(skill, args, result, driveId, env) one skill result โ surface
|
|
11
|
+
* dispatchAinuiAction(action, deps) a click โ skill(s) โ surface
|
|
12
|
+
*
|
|
13
|
+
* Only clients that opt in get these (MCP `X-AINUI: 1`, AG-UI
|
|
14
|
+
* `forwardedProps.ainui`, A2A `metadata.ainui`); everyone else keeps the basic
|
|
15
|
+
* surfaces from ./index.ts, unchanged.
|
|
16
|
+
*
|
|
17
|
+
* Pure: no IO, no Node APIs. The server injects what needs IO โ the skill
|
|
18
|
+
* runner, the allow-list, the caller's write capability and lib/mime lookups โ
|
|
19
|
+
* through AinuiEnv / AinuiDeps (lib/ainui.ts), so the docs playground can use
|
|
20
|
+
* the same code with a fake drive.
|
|
21
|
+
*/
|
|
22
|
+
import type { SkillResult } from "./types.js";
|
|
23
|
+
import { type A2uiAction, type A2uiMessage } from "./basic.js";
|
|
24
|
+
export declare const AINUI_UPLOAD_MAX_BYTES: number;
|
|
25
|
+
export declare const AINUI_VERSION: "v1";
|
|
26
|
+
export declare const AINUI_CATALOG = "https://aindrive.ainetwork.ai/ainui/v1/catalog.json";
|
|
27
|
+
/** MCP request header a client sends to get AINUI surfaces. */
|
|
28
|
+
export declare const AINUI_HEADER = "x-ainui";
|
|
29
|
+
export type AinuiKind = "image" | "video" | "audio" | "pdf" | "folder" | "file";
|
|
30
|
+
export type AinuiView = "grid" | "list";
|
|
31
|
+
export type AssetVariant = "thumb" | "original";
|
|
32
|
+
/** A reference to private file bytes; hosts resolve it before drawing (spec ยง2). */
|
|
33
|
+
export type AssetRef = {
|
|
34
|
+
$asset: {
|
|
35
|
+
drive_id: string;
|
|
36
|
+
path: string;
|
|
37
|
+
variant: AssetVariant;
|
|
38
|
+
mime: string;
|
|
39
|
+
v?: number;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
export type AinuiItem = {
|
|
43
|
+
name: string;
|
|
44
|
+
path: string;
|
|
45
|
+
is_dir: boolean;
|
|
46
|
+
kind: AinuiKind;
|
|
47
|
+
mime: string;
|
|
48
|
+
size: number | null;
|
|
49
|
+
mtime: number | null;
|
|
50
|
+
meta: string;
|
|
51
|
+
drive_id: string;
|
|
52
|
+
thumb: AssetRef | null;
|
|
53
|
+
/** list-row label: kind emoji + name (+ ๐). Extra field; hosts may ignore it. */
|
|
54
|
+
label: string;
|
|
55
|
+
locked?: boolean;
|
|
56
|
+
};
|
|
57
|
+
/** What the builders need to know about the caller and the files (injected; pure defaults). */
|
|
58
|
+
export type AinuiEnv = {
|
|
59
|
+
/** write_file is on the caller's allow-list, scope and live role here โ new/edit buttons. */
|
|
60
|
+
canWrite?: boolean;
|
|
61
|
+
/** delete_path likewise โ the delete button. */
|
|
62
|
+
canDelete?: boolean;
|
|
63
|
+
/** Explicit folder view (aindrive.view); otherwise the grid rule decides. */
|
|
64
|
+
view?: AinuiView;
|
|
65
|
+
/** Label of the first breadcrumb (the drive name). Default "/". */
|
|
66
|
+
rootLabel?: string;
|
|
67
|
+
/** Mime by file name โ the server passes lib/mime lookupMime. */
|
|
68
|
+
mimeOf?: (path: string) => string | null;
|
|
69
|
+
/** Is this a text file the editor can open โ the server passes lib/mime classifyKind. */
|
|
70
|
+
isText?: (path: string, mime: string) => boolean;
|
|
71
|
+
};
|
|
72
|
+
/** Files larger than this open read-only (no edit button; aindrive.edit refuses). */
|
|
73
|
+
export declare const MAX_EDIT_BYTES: number;
|
|
74
|
+
/**
|
|
75
|
+
* The agent's per-entry mime (cli/src/rpc.js, mobile RpcHandler) wins unless it
|
|
76
|
+
* is missing or generic; then the file name decides.
|
|
77
|
+
*/
|
|
78
|
+
export declare function resolveMime(path: string, agentMime: unknown, env?: AinuiEnv): string;
|
|
79
|
+
export declare function kindOf(mime: string, isDir: boolean): AinuiKind;
|
|
80
|
+
export declare function assetRef(driveId: string, path: string, variant: AssetVariant, mime: string, v?: number | null): AssetRef;
|
|
81
|
+
type RawEntry = {
|
|
82
|
+
name: string;
|
|
83
|
+
isDir: boolean;
|
|
84
|
+
size?: number;
|
|
85
|
+
mtimeMs?: number;
|
|
86
|
+
mime?: string;
|
|
87
|
+
locked?: boolean;
|
|
88
|
+
};
|
|
89
|
+
export declare function toItem(driveId: string, path: string, e: RawEntry, env: AinuiEnv, meta?: string): AinuiItem;
|
|
90
|
+
/** Grid when at least half of the folder's FILES are images/videos (folders don't count). */
|
|
91
|
+
export declare function defaultView(items: AinuiItem[]): AinuiView;
|
|
92
|
+
/** A basic-catalog surface is a valid AINUI surface: only the declared catalog changes. */
|
|
93
|
+
export declare function asAinui(messages: A2uiMessage[]): A2uiMessage[];
|
|
94
|
+
export type Crumb = {
|
|
95
|
+
label: string;
|
|
96
|
+
path: string;
|
|
97
|
+
is_dir: boolean;
|
|
98
|
+
};
|
|
99
|
+
/** Root first; the last item is the current location (renderers draw it as plain text). */
|
|
100
|
+
export declare function crumbsFor(path: string, isDir: boolean, rootLabel?: string): Crumb[];
|
|
101
|
+
export declare function ainuiFolder(opts: {
|
|
102
|
+
driveId: string;
|
|
103
|
+
path: string;
|
|
104
|
+
items: AinuiItem[];
|
|
105
|
+
env?: AinuiEnv;
|
|
106
|
+
query?: string;
|
|
107
|
+
note?: string;
|
|
108
|
+
}): A2uiMessage[];
|
|
109
|
+
export declare function ainuiFile(opts: {
|
|
110
|
+
driveId: string;
|
|
111
|
+
path: string;
|
|
112
|
+
mime: string;
|
|
113
|
+
size: number | null;
|
|
114
|
+
mtime: number | null;
|
|
115
|
+
env?: AinuiEnv;
|
|
116
|
+
}): A2uiMessage[];
|
|
117
|
+
export declare function ainuiEditor(opts: {
|
|
118
|
+
driveId: string;
|
|
119
|
+
path: string;
|
|
120
|
+
content: string;
|
|
121
|
+
env?: AinuiEnv;
|
|
122
|
+
}): A2uiMessage[];
|
|
123
|
+
/**
|
|
124
|
+
* The AINUI surface for one skill call (tool result, AG-UI run, A2A reply).
|
|
125
|
+
* Folder skills get the folder surface, file skills the file surface; the
|
|
126
|
+
* rest (drive list, write/delete results, errors) are the basic surfaces
|
|
127
|
+
* relabelled with the AINUI catalog โ AINUI includes the basic catalog.
|
|
128
|
+
*/
|
|
129
|
+
export declare function ainuiForSkill(skill: string, args: Record<string, unknown>, result: SkillResult, driveId?: string, env?: AinuiEnv): A2uiMessage[];
|
|
130
|
+
/** Injected IO for dispatchAinuiAction (server: lib/ainui.ts). */
|
|
131
|
+
export type AinuiDeps = {
|
|
132
|
+
/** Run one skill as the caller (runSkill: scope, drive pin, live role, paid carve-out). */
|
|
133
|
+
run: (skill: string, args: Record<string, unknown>) => Promise<SkillResult>;
|
|
134
|
+
/** The SAME allow-list a direct tool call passes (MCP tools list, agent grant groups). */
|
|
135
|
+
allowed: (skill: string) => boolean;
|
|
136
|
+
/** Caller capabilities + mime lookups at a location. */
|
|
137
|
+
env: (driveId: string, path: string) => AinuiEnv | Promise<AinuiEnv>;
|
|
138
|
+
/** Drive for actions without context.drive_id (pinned endpoint). */
|
|
139
|
+
driveId?: string;
|
|
140
|
+
};
|
|
141
|
+
export type AinuiStep = {
|
|
142
|
+
skill: string;
|
|
143
|
+
args: Record<string, unknown>;
|
|
144
|
+
result: SkillResult;
|
|
145
|
+
};
|
|
146
|
+
export type AinuiReply =
|
|
147
|
+
/** `steps` = skills that ran, in order; `final` = the result to report (may be synthetic). */
|
|
148
|
+
{
|
|
149
|
+
kind: "done";
|
|
150
|
+
steps: AinuiStep[];
|
|
151
|
+
final: AinuiStep;
|
|
152
|
+
surface: A2uiMessage[];
|
|
153
|
+
}
|
|
154
|
+
/** A skill the action needs is not on the caller's allow-list: nothing ran. */
|
|
155
|
+
| {
|
|
156
|
+
kind: "refused";
|
|
157
|
+
skill: string;
|
|
158
|
+
}
|
|
159
|
+
/** Malformed or unknown action. */
|
|
160
|
+
| {
|
|
161
|
+
kind: "invalid";
|
|
162
|
+
error: string;
|
|
163
|
+
};
|
|
164
|
+
export declare const AINUI_ACTIONS: readonly ["aindrive.open_drive", "aindrive.open", "aindrive.search", "aindrive.view", "aindrive.edit", "aindrive.new_file", "aindrive.save", "aindrive.delete", "aindrive.upload"];
|
|
165
|
+
/**
|
|
166
|
+
* Answer an AINUI action. Multi-step actions run their follow-up server-side:
|
|
167
|
+
* new_file โ editor on the new file, save โ file view, delete โ parent folder.
|
|
168
|
+
* Every skill passes deps.allowed first (refused โ nothing runs) and runs
|
|
169
|
+
* through deps.run (runSkill's own checks). A follow-up the caller may not run
|
|
170
|
+
* falls back to the first skill's surface.
|
|
171
|
+
*/
|
|
172
|
+
export declare function dispatchAinuiAction(action: A2uiAction, deps: AinuiDeps): Promise<AinuiReply>;
|
|
173
|
+
export {};
|