ain-ui 0.2.3 → 1.0.4
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 +822 -0
- package/dist/ainui.d.ts +15 -1
- package/dist/ainui.js +53 -10
- package/dist/basic.d.ts +5 -47
- package/dist/basic.js +22 -29
- 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 +91 -0
- package/dist/react/core.js +173 -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 +46 -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/dist/chat.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AINUI_CATALOG } from './ainui.js';
|
|
1
|
+
import { A2UI_V09, AINUI_CATALOG_V1, emitMessages } from './basic.js';
|
|
3
2
|
export function ainuiFolderChat(state) {
|
|
4
3
|
const surfaceId = 'ainui-folder-chat';
|
|
5
|
-
return [
|
|
6
|
-
{ version:
|
|
7
|
-
{ version:
|
|
8
|
-
{ version:
|
|
9
|
-
];
|
|
4
|
+
return emitMessages([
|
|
5
|
+
{ version: A2UI_V09, createSurface: { surfaceId, catalogId: AINUI_CATALOG_V1 } },
|
|
6
|
+
{ version: A2UI_V09, updateComponents: { surfaceId, components: [{ id: 'root', component: 'FolderChat', value: { path: '/chat' }, action: { event: { name: 'aindrive.chat', context: { drive_id: state.driveId, path: state.path } } } }] } },
|
|
7
|
+
{ version: A2UI_V09, updateDataModel: { surfaceId, path: '/', value: { chat: state } } },
|
|
8
|
+
]);
|
|
10
9
|
}
|
|
11
10
|
function textOf(parts) {
|
|
12
11
|
if (!Array.isArray(parts))
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The arithmetic behind the catalog's `calc` and `series` functions: a small expression language evaluated by a
|
|
3
|
+
* parser, never by `eval`.
|
|
4
|
+
*
|
|
5
|
+
* + - * / % ( ) x ^ y < <= > >= == != && || ! cond ? a : b
|
|
6
|
+
* min max round floor ceil abs pow sqrt exp ln log10 pi e 'text' + name
|
|
7
|
+
*
|
|
8
|
+
* Names are looked up in the variables passed in; an unknown name is an error, not undefined.
|
|
9
|
+
*/
|
|
10
|
+
type Value = number | string | boolean | null;
|
|
11
|
+
/** Evaluates `expression` with the given variables. Throws with a short reason when it cannot. */
|
|
12
|
+
export declare function evaluate(expression: string, variables?: Record<string, unknown>): Value;
|
|
13
|
+
/** Fills `${expression}` pieces in a value. A string that is one whole expression keeps the result's type. */
|
|
14
|
+
export declare function fill(template: unknown, variables: Record<string, unknown>): unknown;
|
|
15
|
+
export declare const SERIES_LIMIT = 1000;
|
|
16
|
+
/** `count` copies of `item`, with the loop variable (default `i`, from `start`, default 1) filled in. */
|
|
17
|
+
export declare function series(args: {
|
|
18
|
+
count?: unknown;
|
|
19
|
+
item?: unknown;
|
|
20
|
+
variable?: unknown;
|
|
21
|
+
start?: unknown;
|
|
22
|
+
} & Record<string, unknown>): unknown[];
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
const OPS = ["&&", "||", "<=", ">=", "==", "!=", "+", "-", "*", "/", "%", "^", "(", ")", "<", ">", "!", "?", ":", ","];
|
|
2
|
+
const MAX_LENGTH = 2000;
|
|
3
|
+
function tokenize(src) {
|
|
4
|
+
const out = [];
|
|
5
|
+
let i = 0;
|
|
6
|
+
while (i < src.length) {
|
|
7
|
+
const ch = src[i];
|
|
8
|
+
if (/\s/.test(ch)) {
|
|
9
|
+
i++;
|
|
10
|
+
continue;
|
|
11
|
+
}
|
|
12
|
+
const num = /^(?:\d+\.?\d*(?:[eE][+-]?\d+)?|\.\d+)/.exec(src.slice(i));
|
|
13
|
+
if (num) {
|
|
14
|
+
out.push({ t: "num", v: Number(num[0]) });
|
|
15
|
+
i += num[0].length;
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
if (ch === "'" || ch === '"') {
|
|
19
|
+
let j = i + 1, s = "";
|
|
20
|
+
while (j < src.length && src[j] !== ch) {
|
|
21
|
+
if (src[j] === "\\" && j + 1 < src.length)
|
|
22
|
+
j++;
|
|
23
|
+
s += src[j++];
|
|
24
|
+
}
|
|
25
|
+
if (j >= src.length)
|
|
26
|
+
throw new Error("unterminated string");
|
|
27
|
+
out.push({ t: "str", v: s });
|
|
28
|
+
i = j + 1;
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const id = /^[A-Za-z_][A-Za-z0-9_.]*/.exec(src.slice(i));
|
|
32
|
+
if (id) {
|
|
33
|
+
out.push({ t: "id", v: id[0] });
|
|
34
|
+
i += id[0].length;
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
const op = OPS.find((o) => src.startsWith(o, i));
|
|
38
|
+
if (!op)
|
|
39
|
+
throw new Error(`unexpected "${ch}"`);
|
|
40
|
+
out.push({ t: "op", v: op });
|
|
41
|
+
i += op.length;
|
|
42
|
+
}
|
|
43
|
+
return out;
|
|
44
|
+
}
|
|
45
|
+
const FUNCTIONS = {
|
|
46
|
+
min: Math.min, max: Math.max, round: (x, digits = 0) => { const f = 10 ** digits; return Math.round(x * f) / f; },
|
|
47
|
+
floor: Math.floor, ceil: Math.ceil, abs: Math.abs, pow: Math.pow, sqrt: Math.sqrt, exp: Math.exp, ln: Math.log, log10: Math.log10,
|
|
48
|
+
};
|
|
49
|
+
const CONSTANTS = { pi: Math.PI, e: Math.E };
|
|
50
|
+
const num = (v) => { const n = typeof v === "number" ? v : typeof v === "boolean" ? Number(v) : Number(v); if (Number.isNaN(n))
|
|
51
|
+
throw new Error(`"${String(v)}" is not a number`); return n; };
|
|
52
|
+
const truthy = (v) => !!v;
|
|
53
|
+
/** Evaluates `expression` with the given variables. Throws with a short reason when it cannot. */
|
|
54
|
+
export function evaluate(expression, variables = {}) {
|
|
55
|
+
if (typeof expression !== "string")
|
|
56
|
+
throw new Error("expression must be a string");
|
|
57
|
+
if (expression.length > MAX_LENGTH)
|
|
58
|
+
throw new Error("expression too long");
|
|
59
|
+
const tokens = tokenize(expression);
|
|
60
|
+
let pos = 0;
|
|
61
|
+
const peek = (v) => { const t = tokens[pos]; return t && t.t === "op" && (v === undefined || t.v === v) ? t : undefined; };
|
|
62
|
+
const take = (v) => { if (!peek(v))
|
|
63
|
+
throw new Error(`expected "${v}"`); pos++; };
|
|
64
|
+
const lookup = (name) => {
|
|
65
|
+
if (Object.prototype.hasOwnProperty.call(variables, name)) {
|
|
66
|
+
const v = variables[name];
|
|
67
|
+
return v === undefined ? null : v;
|
|
68
|
+
}
|
|
69
|
+
// a.b reads a property of a variable that is an object
|
|
70
|
+
if (name.includes(".")) {
|
|
71
|
+
let cur = variables;
|
|
72
|
+
for (const part of name.split(".")) {
|
|
73
|
+
if (cur && typeof cur === "object" && Object.prototype.hasOwnProperty.call(cur, part))
|
|
74
|
+
cur = cur[part];
|
|
75
|
+
else
|
|
76
|
+
throw new Error(`unknown name "${name}"`);
|
|
77
|
+
}
|
|
78
|
+
return cur;
|
|
79
|
+
}
|
|
80
|
+
if (Object.prototype.hasOwnProperty.call(CONSTANTS, name))
|
|
81
|
+
return CONSTANTS[name];
|
|
82
|
+
if (name === "true")
|
|
83
|
+
return true;
|
|
84
|
+
if (name === "false")
|
|
85
|
+
return false;
|
|
86
|
+
if (name === "null")
|
|
87
|
+
return null;
|
|
88
|
+
throw new Error(`unknown name "${name}"`);
|
|
89
|
+
};
|
|
90
|
+
const primary = () => {
|
|
91
|
+
const t = tokens[pos];
|
|
92
|
+
if (!t)
|
|
93
|
+
throw new Error("unexpected end");
|
|
94
|
+
if (t.t === "num") {
|
|
95
|
+
pos++;
|
|
96
|
+
return t.v;
|
|
97
|
+
}
|
|
98
|
+
if (t.t === "str") {
|
|
99
|
+
pos++;
|
|
100
|
+
return t.v;
|
|
101
|
+
}
|
|
102
|
+
if (t.t === "id") {
|
|
103
|
+
pos++;
|
|
104
|
+
if (peek("(")) {
|
|
105
|
+
const fn = Object.prototype.hasOwnProperty.call(FUNCTIONS, t.v) ? FUNCTIONS[t.v] : undefined;
|
|
106
|
+
if (!fn)
|
|
107
|
+
throw new Error(`unknown function "${t.v}"`);
|
|
108
|
+
pos++;
|
|
109
|
+
const args = [];
|
|
110
|
+
if (!peek(")")) {
|
|
111
|
+
do {
|
|
112
|
+
args.push(num(ternary()));
|
|
113
|
+
} while (peek(",") && ++pos);
|
|
114
|
+
}
|
|
115
|
+
take(")");
|
|
116
|
+
return fn(...args);
|
|
117
|
+
}
|
|
118
|
+
return lookup(t.v);
|
|
119
|
+
}
|
|
120
|
+
if (t.v === "(") {
|
|
121
|
+
pos++;
|
|
122
|
+
const v = ternary();
|
|
123
|
+
take(")");
|
|
124
|
+
return v;
|
|
125
|
+
}
|
|
126
|
+
throw new Error(`unexpected "${t.v}"`);
|
|
127
|
+
};
|
|
128
|
+
const unary = () => {
|
|
129
|
+
if (peek("-")) {
|
|
130
|
+
pos++;
|
|
131
|
+
return -num(unary());
|
|
132
|
+
}
|
|
133
|
+
if (peek("+")) {
|
|
134
|
+
pos++;
|
|
135
|
+
return num(unary());
|
|
136
|
+
}
|
|
137
|
+
if (peek("!")) {
|
|
138
|
+
pos++;
|
|
139
|
+
return !truthy(unary());
|
|
140
|
+
}
|
|
141
|
+
return primary();
|
|
142
|
+
};
|
|
143
|
+
const power = () => { const base = unary(); if (peek("^")) {
|
|
144
|
+
pos++;
|
|
145
|
+
return num(base) ** num(power());
|
|
146
|
+
} return base; };
|
|
147
|
+
const product = () => {
|
|
148
|
+
let v = power();
|
|
149
|
+
for (let op = peek(); op && ["*", "/", "%"].includes(op.v); op = peek()) {
|
|
150
|
+
pos++;
|
|
151
|
+
const r = num(power());
|
|
152
|
+
v = op.v === "*" ? num(v) * r : op.v === "/" ? num(v) / r : num(v) % r;
|
|
153
|
+
}
|
|
154
|
+
return v;
|
|
155
|
+
};
|
|
156
|
+
const sum = () => {
|
|
157
|
+
let v = product();
|
|
158
|
+
for (let op = peek(); op && ["+", "-"].includes(op.v); op = peek()) {
|
|
159
|
+
pos++;
|
|
160
|
+
const r = product();
|
|
161
|
+
v = op.v === "-" ? num(v) - num(r) : typeof v === "string" || typeof r === "string" ? `${v ?? ""}${r ?? ""}` : num(v) + num(r);
|
|
162
|
+
}
|
|
163
|
+
return v;
|
|
164
|
+
};
|
|
165
|
+
const compare = () => {
|
|
166
|
+
let v = sum();
|
|
167
|
+
for (let op = peek(); op && ["<", "<=", ">", ">=", "==", "!="].includes(op.v); op = peek()) {
|
|
168
|
+
pos++;
|
|
169
|
+
const r = sum();
|
|
170
|
+
v = op.v === "==" ? v === r : op.v === "!=" ? v !== r : op.v === "<" ? num(v) < num(r) : op.v === "<=" ? num(v) <= num(r) : op.v === ">" ? num(v) > num(r) : num(v) >= num(r);
|
|
171
|
+
}
|
|
172
|
+
return v;
|
|
173
|
+
};
|
|
174
|
+
const and = () => { let v = compare(); while (peek("&&")) {
|
|
175
|
+
pos++;
|
|
176
|
+
const r = compare();
|
|
177
|
+
v = truthy(v) && truthy(r);
|
|
178
|
+
} return v; };
|
|
179
|
+
const or = () => { let v = and(); while (peek("||")) {
|
|
180
|
+
pos++;
|
|
181
|
+
const r = and();
|
|
182
|
+
v = truthy(v) || truthy(r);
|
|
183
|
+
} return v; };
|
|
184
|
+
function ternary() {
|
|
185
|
+
const c = or();
|
|
186
|
+
if (!peek("?"))
|
|
187
|
+
return c;
|
|
188
|
+
pos++;
|
|
189
|
+
const a = ternary();
|
|
190
|
+
take(":");
|
|
191
|
+
const b = ternary();
|
|
192
|
+
return truthy(c) ? a : b;
|
|
193
|
+
}
|
|
194
|
+
const value = ternary();
|
|
195
|
+
if (pos < tokens.length)
|
|
196
|
+
throw new Error("unexpected input after the expression");
|
|
197
|
+
return value;
|
|
198
|
+
}
|
|
199
|
+
const WHOLE = /^\$\{([^}]*)\}$/;
|
|
200
|
+
/** Fills `${expression}` pieces in a value. A string that is one whole expression keeps the result's type. */
|
|
201
|
+
export function fill(template, variables) {
|
|
202
|
+
if (typeof template === "string") {
|
|
203
|
+
const whole = WHOLE.exec(template);
|
|
204
|
+
if (whole)
|
|
205
|
+
return evaluate(whole[1], variables);
|
|
206
|
+
return template.replace(/\$\{([^}]*)\}/g, (_, expr) => String(evaluate(expr, variables) ?? ""));
|
|
207
|
+
}
|
|
208
|
+
if (Array.isArray(template))
|
|
209
|
+
return template.map((x) => fill(x, variables));
|
|
210
|
+
if (template && typeof template === "object")
|
|
211
|
+
return Object.fromEntries(Object.entries(template).map(([k, v]) => [k, fill(v, variables)]));
|
|
212
|
+
return template;
|
|
213
|
+
}
|
|
214
|
+
export const SERIES_LIMIT = 1000;
|
|
215
|
+
/** `count` copies of `item`, with the loop variable (default `i`, from `start`, default 1) filled in. */
|
|
216
|
+
export function series(args) {
|
|
217
|
+
const { count, item, variable, start, ...rest } = args;
|
|
218
|
+
const n = Math.max(0, Math.min(SERIES_LIMIT, Math.floor(Number(count) || 0)));
|
|
219
|
+
const name = typeof variable === "string" && /^[A-Za-z_][A-Za-z0-9_]*$/.test(variable) ? variable : "i";
|
|
220
|
+
const first = Number.isFinite(Number(start)) && start !== undefined && start !== null ? Number(start) : 1;
|
|
221
|
+
return Array.from({ length: n }, (_, k) => fill(item, { ...rest, [name]: first + k }));
|
|
222
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,3 +4,5 @@ export * from "./payment.js";
|
|
|
4
4
|
export type { SkillResult } from "./types.js";
|
|
5
5
|
export * from "./agui.js";
|
|
6
6
|
export * from "./chat.js";
|
|
7
|
+
export * from "./pickers.js";
|
|
8
|
+
export { AINUI_CATALOG_DOCUMENT, STANDARD_COMPONENT_NAMES, RICH_COMPONENT_NAMES } from "./catalog/standard.gen.js";
|
package/dist/index.js
CHANGED
package/dist/macros.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AIN-UI's own macros: one short call the model writes, expanded on the server into standard components
|
|
3
|
+
* (see `defineMacro` in ./agent.ts). They keep the model's output small where the layout never varies.
|
|
4
|
+
*/
|
|
5
|
+
import { type Macro } from "./agent.js";
|
|
6
|
+
/** One file: name, a line of detail, and Open / Download. */
|
|
7
|
+
export declare const FileCard: Macro;
|
|
8
|
+
/** x402 payment terms with the pay button. The terms must be the ones the paid resource quoted. */
|
|
9
|
+
export declare const PaymentCard: Macro;
|
|
10
|
+
/** One agent: name, what it does, its skills, and a button to use it. */
|
|
11
|
+
export declare const AgentCard: Macro;
|
|
12
|
+
export declare const AINUI_MACROS: readonly Macro[];
|
package/dist/macros.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AIN-UI's own macros: one short call the model writes, expanded on the server into standard components
|
|
3
|
+
* (see `defineMacro` in ./agent.ts). They keep the model's output small where the layout never varies.
|
|
4
|
+
*/
|
|
5
|
+
import { defineMacro } from "./agent.js";
|
|
6
|
+
const str = (description) => ({ type: "string", description });
|
|
7
|
+
/** One file: name, a line of detail, and Open / Download. */
|
|
8
|
+
export const FileCard = defineMacro({
|
|
9
|
+
name: "FileCard",
|
|
10
|
+
description: "One file as a card with its name, a detail line (size, date) and an Open button. Sends \"aindrive.open\" with the path.",
|
|
11
|
+
props: { name: str("File name"), path: str("Path of the file in the drive"), detail: str("Size, date or another short note"), driveId: str("The drive id"), kind: { type: "string", enum: ["image", "video", "audio", "pdf", "folder", "file"], description: "What the entry is" } },
|
|
12
|
+
required: ["name", "path"],
|
|
13
|
+
expand: (p, id) => [
|
|
14
|
+
{ component: "Card", variant: "outline", children: [id("row")] },
|
|
15
|
+
{ id: id("row"), component: "Row", justify: "spaceBetween", children: [id("text"), id("open")] },
|
|
16
|
+
{ id: id("text"), component: "Column", gap: 1, children: [id("name"), ...(p.detail ? [id("detail")] : [])] },
|
|
17
|
+
{ id: id("name"), component: "Row", gap: 2, children: [id("icon"), id("title")] },
|
|
18
|
+
{ id: id("icon"), component: "Icon", name: p.kind === "folder" ? "folder" : p.kind === "image" ? "image" : p.kind === "video" ? "film" : p.kind === "audio" ? "music" : "file-text" },
|
|
19
|
+
{ id: id("title"), component: "Text", text: p.name, strong: true, truncate: true },
|
|
20
|
+
...(p.detail ? [{ id: id("detail"), component: "Caption", text: p.detail }] : []),
|
|
21
|
+
{ id: id("open"), component: "Button", label: "Open", variant: "soft", onClick: { event: { name: "aindrive.open", context: { drive_id: p.driveId ?? "", path: p.path, is_dir: p.kind === "folder" } } } },
|
|
22
|
+
],
|
|
23
|
+
});
|
|
24
|
+
/** x402 payment terms with the pay button. The terms must be the ones the paid resource quoted. */
|
|
25
|
+
export const PaymentCard = defineMacro({
|
|
26
|
+
name: "PaymentCard",
|
|
27
|
+
description: "What is being bought and its x402 payment terms, with a pay button. Use the exact amount, currency, network and recipient you were given; rendering it moves no money.",
|
|
28
|
+
props: { title: str("What is being bought"), amount: str("Amount as a decimal string"), currency: str("Currency symbol, for example USDC"), network: str("Network, for example eip155:8453"), payTo: str("Recipient address"), shareToken: str("The paid share's token"), paymentRequired: str("The PAYMENT-REQUIRED header value that produced these terms") },
|
|
29
|
+
required: ["title", "amount", "currency", "network", "payTo"],
|
|
30
|
+
expand: (p, id) => [
|
|
31
|
+
{ component: "Card", children: [id("title"), id("pay")] },
|
|
32
|
+
{ id: id("title"), component: "Title", text: p.title, size: "md" },
|
|
33
|
+
{ id: id("pay"), component: "X402Payment", amount: p.amount, currency: p.currency, network: p.network, payTo: p.payTo,
|
|
34
|
+
action: { event: { name: "aindrive.x402.pay", context: { share_token: p.shareToken ?? "", paymentRequired: p.paymentRequired ?? "" } } } },
|
|
35
|
+
],
|
|
36
|
+
});
|
|
37
|
+
/** One agent: name, what it does, its skills, and a button to use it. */
|
|
38
|
+
export const AgentCard = defineMacro({
|
|
39
|
+
name: "AgentCard",
|
|
40
|
+
description: "One agent as a card: name, description, up to four skills as badges, status, and a button that sends \"ainui.picker.pick\" with the agent's key.",
|
|
41
|
+
props: { name: str("Display name"), description: str("What the agent does"), agentKey: str("registryIssuer#agentId"), status: { type: "string", enum: ["active", "disabled", "stopped", "deleted"], description: "Default active" }, skills: { type: "array", items: { type: "string" }, description: "Skill names" } },
|
|
42
|
+
required: ["name", "agentKey"],
|
|
43
|
+
expand: (p, id) => {
|
|
44
|
+
const skills = Array.isArray(p.skills) ? p.skills.slice(0, 4) : [];
|
|
45
|
+
const active = !p.status || p.status === "active";
|
|
46
|
+
return [
|
|
47
|
+
{ component: "Card", variant: "outline", children: [id("head"), ...(p.description ? [id("desc")] : []), ...(skills.length ? [id("skills")] : []), id("use")] },
|
|
48
|
+
{ id: id("head"), component: "Row", justify: "spaceBetween", children: [id("name"), id("status")] },
|
|
49
|
+
{ id: id("name"), component: "Title", text: p.name, size: "sm" },
|
|
50
|
+
{ id: id("status"), component: "Badge", label: p.status ?? "active", color: active ? "success" : "secondary" },
|
|
51
|
+
...(p.description ? [{ id: id("desc"), component: "Text", text: p.description, color: "muted" }] : []),
|
|
52
|
+
...(skills.length ? [{ id: id("skills"), component: "Row", gap: 2, children: skills.map((_, i) => id(`skill${i}`)) }, ...skills.map((s, i) => ({ id: id(`skill${i}`), component: "Badge", label: s, variant: "outline" }))] : []),
|
|
53
|
+
{ id: id("use"), component: "Button", label: "Use this agent", variant: "primary", disabled: !active, onClick: { event: { name: "ainui.picker.pick", context: { kind: "agent", agentKey: p.agentKey } } } },
|
|
54
|
+
];
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
export const AINUI_MACROS = [FileCard, PaymentCard, AgentCard];
|
package/dist/payment.js
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { A2UI_VERSION } from "./basic.js";
|
|
1
|
+
import { A2UI_V09, AINUI_CATALOG_V1, emitMessages } from "./basic.js";
|
|
3
2
|
export const X402_PAY_ACTION = "aindrive.x402.pay";
|
|
4
3
|
export function ainuiPayment(input) {
|
|
5
4
|
const surfaceId = `aindrive-payment-${input.shareToken}`;
|
|
6
5
|
const req = input.required.accepts[0];
|
|
7
6
|
const digits = req.amount.padStart(input.decimals + 1, "0");
|
|
8
7
|
const amount = input.decimals ? `${digits.slice(0, -input.decimals)}.${digits.slice(-input.decimals)}`.replace(/\.?0+$/, "") : digits;
|
|
9
|
-
return [
|
|
10
|
-
{ version:
|
|
11
|
-
{ version:
|
|
8
|
+
return emitMessages([
|
|
9
|
+
{ version: A2UI_V09, createSurface: { surfaceId, catalogId: AINUI_CATALOG_V1 } },
|
|
10
|
+
{ version: A2UI_V09, updateComponents: { surfaceId, components: [
|
|
12
11
|
{ id: "root", component: "Column", children: ["title", "payment"] },
|
|
13
12
|
{ id: "title", component: "Text", variant: "h3", text: { path: "/title" } },
|
|
14
13
|
{ id: "payment", component: "X402Payment", amount: { path: "/amount" }, currency: { path: "/currency" },
|
|
15
14
|
network: { path: "/network" }, payTo: { path: "/payTo" },
|
|
16
15
|
action: { event: { name: X402_PAY_ACTION, context: { share_token: { path: "/share_token" }, paymentRequired: { path: "/paymentRequired" } } } } },
|
|
17
16
|
] } },
|
|
18
|
-
{ version:
|
|
17
|
+
{ version: A2UI_V09, updateDataModel: { surfaceId, path: "/", value: {
|
|
19
18
|
title: input.title, share_token: input.shareToken, paymentRequired: input.paymentRequired,
|
|
20
19
|
amount, currency: input.symbol, network: req.network, payTo: req.payTo,
|
|
21
20
|
} } },
|
|
22
|
-
];
|
|
21
|
+
]);
|
|
23
22
|
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Common file / agent pickers (integration plan task 09).
|
|
3
|
+
*
|
|
4
|
+
* Two AINUI catalog components, `FilePicker` and `AgentPicker`, draw the
|
|
5
|
+
* cross-product listing contract (`@ain/integration-contracts` list.ts):
|
|
6
|
+
* scope tabs, search, paged rows and a pick action that returns the FULL
|
|
7
|
+
* reference object — never bytes, tokens or signed URLs. The builders below
|
|
8
|
+
* put the listing in the surface's data model (like ainuiFolder) and bind the
|
|
9
|
+
* component to it, so a host can page or re-scope by updating the model.
|
|
10
|
+
*
|
|
11
|
+
* The renderer decides nothing about permissions: a row the origin marked
|
|
12
|
+
* offline / deleted / not entitled / not invocable is shown greyed with the
|
|
13
|
+
* reason, its pick control is disabled, and `open`/`card` still work. What
|
|
14
|
+
* happens after `ainui.picker.pick` is the host's business.
|
|
15
|
+
*
|
|
16
|
+
* The contract shapes are re-declared here minimally (no dependency on the
|
|
17
|
+
* contracts package); a consumer validates with the real zod schemas.
|
|
18
|
+
*/
|
|
19
|
+
import { type A2uiMessage } from "./basic.js";
|
|
20
|
+
import { PICKER_ACTIONS } from "./ainui.js";
|
|
21
|
+
export { PICKER_ACTIONS };
|
|
22
|
+
export type OwnerRef = {
|
|
23
|
+
kind: "account" | "org" | "wallet" | "principal";
|
|
24
|
+
issuer: string;
|
|
25
|
+
subject: string;
|
|
26
|
+
displayName?: string;
|
|
27
|
+
};
|
|
28
|
+
export type FileAvailability = {
|
|
29
|
+
state: "online" | "offline" | "deleted" | "unknown";
|
|
30
|
+
lastSeenAt?: string;
|
|
31
|
+
};
|
|
32
|
+
/** Identity = issuer + driveId + fileId. Carries `sourceUrl` only — no token, signed URL or secret. */
|
|
33
|
+
export type FileRef = {
|
|
34
|
+
contract: "1.0";
|
|
35
|
+
issuer: string;
|
|
36
|
+
driveId: string;
|
|
37
|
+
fileId: string;
|
|
38
|
+
revision: string;
|
|
39
|
+
kind: "file" | "folder";
|
|
40
|
+
mimeType?: string;
|
|
41
|
+
displayName: string;
|
|
42
|
+
ownerRef: OwnerRef;
|
|
43
|
+
availability: FileAvailability;
|
|
44
|
+
sourceUrl?: string;
|
|
45
|
+
legacy?: {
|
|
46
|
+
path: string;
|
|
47
|
+
};
|
|
48
|
+
size?: number;
|
|
49
|
+
sha256?: string;
|
|
50
|
+
};
|
|
51
|
+
export type FileAccessRole = "owner" | "editor" | "viewer" | "none";
|
|
52
|
+
export type ShareOrigin = "own" | "direct" | "org" | "link" | "paid";
|
|
53
|
+
export type FileListItem = {
|
|
54
|
+
ref: FileRef;
|
|
55
|
+
role: FileAccessRole;
|
|
56
|
+
shareOrigin: ShareOrigin;
|
|
57
|
+
paid?: {
|
|
58
|
+
entitled: boolean;
|
|
59
|
+
pricingRef?: string;
|
|
60
|
+
};
|
|
61
|
+
modifiedAt?: string;
|
|
62
|
+
sharedAt?: string;
|
|
63
|
+
};
|
|
64
|
+
export type FileListScope = "mine" | "shared_with_me" | "shared_with_org" | "recent";
|
|
65
|
+
export type AgentVisibility = "public" | "org" | "private" | "unlisted";
|
|
66
|
+
export type AgentStatus = "active" | "disabled" | "stopped" | "deleted";
|
|
67
|
+
export type UiCapability = "streaming" | "cancel" | "image_in" | "image_out" | "audio_in" | "audio_out" | "ainui" | "a2ui_basic" | "file_refs_out";
|
|
68
|
+
export type AgentSkill = {
|
|
69
|
+
id: string;
|
|
70
|
+
name: string;
|
|
71
|
+
description?: string;
|
|
72
|
+
examples?: string[];
|
|
73
|
+
};
|
|
74
|
+
/** Identity = registryIssuer + agentId. Seeing a card grants neither execution nor file access. */
|
|
75
|
+
export type AgentRef = {
|
|
76
|
+
contract: "1.0";
|
|
77
|
+
registryIssuer: string;
|
|
78
|
+
agentId: string;
|
|
79
|
+
releaseId: string;
|
|
80
|
+
ownerRef: OwnerRef;
|
|
81
|
+
visibility: AgentVisibility;
|
|
82
|
+
orgRef?: OwnerRef;
|
|
83
|
+
agentCardUrl: string;
|
|
84
|
+
endpoint: string;
|
|
85
|
+
supportedProtocolVersions: string[];
|
|
86
|
+
skills: AgentSkill[];
|
|
87
|
+
inputModes: string[];
|
|
88
|
+
outputModes: string[];
|
|
89
|
+
uiCapabilities: UiCapability[];
|
|
90
|
+
pricingRef?: string;
|
|
91
|
+
status: AgentStatus;
|
|
92
|
+
displayName: string;
|
|
93
|
+
description?: string;
|
|
94
|
+
updatedAt: string;
|
|
95
|
+
};
|
|
96
|
+
export type AgentListItem = {
|
|
97
|
+
ref: AgentRef;
|
|
98
|
+
canInvoke: boolean;
|
|
99
|
+
};
|
|
100
|
+
export type AgentListScope = "mine" | "shared_with_me" | "shared_with_org" | "public";
|
|
101
|
+
type ListResponseBase = {
|
|
102
|
+
contract: "1.0";
|
|
103
|
+
asOf: string;
|
|
104
|
+
nextCursor: string | null;
|
|
105
|
+
cursorExpired?: boolean;
|
|
106
|
+
};
|
|
107
|
+
export type FileListResponse = ListResponseBase & {
|
|
108
|
+
items: FileListItem[];
|
|
109
|
+
};
|
|
110
|
+
export type AgentListResponse = ListResponseBase & {
|
|
111
|
+
items: AgentListItem[];
|
|
112
|
+
};
|
|
113
|
+
export declare const fileKey: (r: Pick<FileRef, "issuer" | "driveId" | "fileId">) => string;
|
|
114
|
+
export declare const agentKey: (r: Pick<AgentRef, "registryIssuer" | "agentId">) => string;
|
|
115
|
+
export declare const FILE_SCOPES: ReadonlyArray<{
|
|
116
|
+
value: FileListScope;
|
|
117
|
+
label: string;
|
|
118
|
+
}>;
|
|
119
|
+
export declare const AGENT_SCOPES: ReadonlyArray<{
|
|
120
|
+
value: AgentListScope;
|
|
121
|
+
label: string;
|
|
122
|
+
}>;
|
|
123
|
+
export declare const SHARE_ORIGIN_LABEL: Record<ShareOrigin, string>;
|
|
124
|
+
export declare const ROLE_LABEL: Record<FileAccessRole, string>;
|
|
125
|
+
export declare const AVAILABILITY_LABEL: Record<FileAvailability["state"], string>;
|
|
126
|
+
export declare const AGENT_STATUS_LABEL: Record<AgentStatus, string>;
|
|
127
|
+
export declare const VISIBILITY_LABEL: Record<AgentVisibility, string>;
|
|
128
|
+
export declare const PAID_BADGE = "\uAD6C\uB9E4 \uD544\uC694";
|
|
129
|
+
export declare const MORE_LABEL = "\uB354 \uBCF4\uAE30";
|
|
130
|
+
/** Why a file row cannot be picked (null = pickable). `open` is still allowed: the origin's page explains itself. */
|
|
131
|
+
export declare function filePickReason(item: FileListItem): string | null;
|
|
132
|
+
/** Why an agent row cannot be selected for invocation (null = selectable). Viewing its card is always allowed. */
|
|
133
|
+
export declare function agentPickReason(item: AgentListItem): string | null;
|
|
134
|
+
/** Enabled = the agent offers it and the consumer renders it; the rest fall back (contract capability.ts). */
|
|
135
|
+
export declare function capabilityLines(agent: Pick<AgentRef, "uiCapabilities">, renders: readonly string[] | undefined): {
|
|
136
|
+
enabled: UiCapability[];
|
|
137
|
+
fallbacks: UiCapability[];
|
|
138
|
+
};
|
|
139
|
+
type PickerOpts = {
|
|
140
|
+
/** Search text the listing was made with (echoed in the field). */
|
|
141
|
+
query?: string;
|
|
142
|
+
/** Extra fields merged into every `ainui.picker.*` action (a host correlation id, a target slot). No secrets. */
|
|
143
|
+
context?: Record<string, unknown>;
|
|
144
|
+
};
|
|
145
|
+
export type FilePickerOpts = PickerOpts & {
|
|
146
|
+
scope: FileListScope;
|
|
147
|
+
selection?: "single" | "multiple";
|
|
148
|
+
selected?: string[];
|
|
149
|
+
};
|
|
150
|
+
export type AgentPickerOpts = PickerOpts & {
|
|
151
|
+
scope: AgentListScope;
|
|
152
|
+
selected?: string;
|
|
153
|
+
renders?: UiCapability[];
|
|
154
|
+
};
|
|
155
|
+
/** A `FilePicker` surface over one page of a file listing. Refs are passed through as the origin sent them. */
|
|
156
|
+
export declare function ainuiFilePicker(surfaceId: string, response: FileListResponse, opts: FilePickerOpts): A2uiMessage[];
|
|
157
|
+
/** An `AgentPicker` surface over one page of an agent listing. */
|
|
158
|
+
export declare function ainuiAgentPicker(surfaceId: string, response: AgentListResponse, opts: AgentPickerOpts): A2uiMessage[];
|
package/dist/pickers.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Common file / agent pickers (integration plan task 09).
|
|
3
|
+
*
|
|
4
|
+
* Two AINUI catalog components, `FilePicker` and `AgentPicker`, draw the
|
|
5
|
+
* cross-product listing contract (`@ain/integration-contracts` list.ts):
|
|
6
|
+
* scope tabs, search, paged rows and a pick action that returns the FULL
|
|
7
|
+
* reference object — never bytes, tokens or signed URLs. The builders below
|
|
8
|
+
* put the listing in the surface's data model (like ainuiFolder) and bind the
|
|
9
|
+
* component to it, so a host can page or re-scope by updating the model.
|
|
10
|
+
*
|
|
11
|
+
* The renderer decides nothing about permissions: a row the origin marked
|
|
12
|
+
* offline / deleted / not entitled / not invocable is shown greyed with the
|
|
13
|
+
* reason, its pick control is disabled, and `open`/`card` still work. What
|
|
14
|
+
* happens after `ainui.picker.pick` is the host's business.
|
|
15
|
+
*
|
|
16
|
+
* The contract shapes are re-declared here minimally (no dependency on the
|
|
17
|
+
* contracts package); a consumer validates with the real zod schemas.
|
|
18
|
+
*/
|
|
19
|
+
import { A2UI_V09, AINUI_CATALOG_V1, emitMessages } from "./basic.js";
|
|
20
|
+
import { PICKER_ACTIONS } from "./ainui.js";
|
|
21
|
+
export { PICKER_ACTIONS };
|
|
22
|
+
export const fileKey = (r) => `${r.issuer}#${r.driveId}#${r.fileId}`;
|
|
23
|
+
export const agentKey = (r) => `${r.registryIssuer}#${r.agentId}`;
|
|
24
|
+
// ── labels and row rules (shared by the React renderer; renderer.js mirrors them) ──
|
|
25
|
+
export const FILE_SCOPES = [
|
|
26
|
+
{ value: "mine", label: "내 파일" }, { value: "shared_with_me", label: "나에게 공유됨" },
|
|
27
|
+
{ value: "shared_with_org", label: "조직 공유" }, { value: "recent", label: "최근" },
|
|
28
|
+
];
|
|
29
|
+
export const AGENT_SCOPES = [
|
|
30
|
+
{ value: "mine", label: "내 에이전트" }, { value: "shared_with_me", label: "나에게 공유됨" },
|
|
31
|
+
{ value: "shared_with_org", label: "조직 공유" }, { value: "public", label: "공개" },
|
|
32
|
+
];
|
|
33
|
+
export const SHARE_ORIGIN_LABEL = { own: "내 파일", direct: "직접 공유", org: "조직 공유", link: "링크 공유", paid: "유료 공유" };
|
|
34
|
+
export const ROLE_LABEL = { owner: "소유자", editor: "편집 가능", viewer: "보기 전용", none: "권한 없음" };
|
|
35
|
+
export const AVAILABILITY_LABEL = { online: "온라인", offline: "오프라인", deleted: "삭제됨", unknown: "확인 안 됨" };
|
|
36
|
+
export const AGENT_STATUS_LABEL = { active: "활성", disabled: "비활성", stopped: "중지됨", deleted: "삭제됨" };
|
|
37
|
+
export const VISIBILITY_LABEL = { public: "공개", org: "조직", private: "비공개", unlisted: "링크 공개" };
|
|
38
|
+
export const PAID_BADGE = "구매 필요";
|
|
39
|
+
export const MORE_LABEL = "더 보기";
|
|
40
|
+
/** Why a file row cannot be picked (null = pickable). `open` is still allowed: the origin's page explains itself. */
|
|
41
|
+
export function filePickReason(item) {
|
|
42
|
+
const state = item.ref.availability?.state;
|
|
43
|
+
if (state === "offline")
|
|
44
|
+
return "오프라인: 보관 기기가 연결되어 있지 않아 지금은 사용할 수 없습니다";
|
|
45
|
+
if (state === "deleted")
|
|
46
|
+
return "삭제됨: 원본이 더 이상 존재하지 않습니다";
|
|
47
|
+
if (item.paid && !item.paid.entitled)
|
|
48
|
+
return "구매 필요: 구매 후 사용할 수 있습니다";
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
/** Why an agent row cannot be selected for invocation (null = selectable). Viewing its card is always allowed. */
|
|
52
|
+
export function agentPickReason(item) {
|
|
53
|
+
if (item.ref.status !== "active")
|
|
54
|
+
return `${AGENT_STATUS_LABEL[item.ref.status] ?? item.ref.status}: 새 호출을 받지 않습니다`;
|
|
55
|
+
if (!item.canInvoke)
|
|
56
|
+
return "호출 권한이 없습니다";
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
/** Enabled = the agent offers it and the consumer renders it; the rest fall back (contract capability.ts). */
|
|
60
|
+
export function capabilityLines(agent, renders) {
|
|
61
|
+
const r = new Set(renders ?? []);
|
|
62
|
+
const caps = agent.uiCapabilities ?? [];
|
|
63
|
+
return { enabled: caps.filter((c) => r.has(c)), fallbacks: caps.filter((c) => !r.has(c)) };
|
|
64
|
+
}
|
|
65
|
+
function pickerSurface(surfaceId, component, data) {
|
|
66
|
+
return emitMessages([
|
|
67
|
+
{ version: A2UI_V09, createSurface: { surfaceId, catalogId: AINUI_CATALOG_V1 } },
|
|
68
|
+
{ version: A2UI_V09, updateComponents: { surfaceId, components: [component] } },
|
|
69
|
+
{ version: A2UI_V09, updateDataModel: { surfaceId, path: "/", value: data } },
|
|
70
|
+
]);
|
|
71
|
+
}
|
|
72
|
+
const bind = (name) => ({ path: `/${name}` });
|
|
73
|
+
/** A `FilePicker` surface over one page of a file listing. Refs are passed through as the origin sent them. */
|
|
74
|
+
export function ainuiFilePicker(surfaceId, response, opts) {
|
|
75
|
+
const component = {
|
|
76
|
+
id: "root", component: "FilePicker",
|
|
77
|
+
items: bind("items"), scope: bind("scope"), query: bind("query"), cursor: bind("cursor"), asOf: bind("asOf"),
|
|
78
|
+
cursorExpired: bind("cursorExpired"), selection: bind("selection"), selected: bind("selected"), context: bind("context"),
|
|
79
|
+
};
|
|
80
|
+
return pickerSurface(surfaceId, component, {
|
|
81
|
+
items: response.items,
|
|
82
|
+
scope: opts.scope,
|
|
83
|
+
query: opts.query ?? "",
|
|
84
|
+
cursor: response.nextCursor ?? null,
|
|
85
|
+
asOf: response.asOf,
|
|
86
|
+
cursorExpired: response.cursorExpired === true,
|
|
87
|
+
selection: opts.selection ?? "single",
|
|
88
|
+
selected: opts.selected ?? [],
|
|
89
|
+
context: opts.context ?? {},
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
/** An `AgentPicker` surface over one page of an agent listing. */
|
|
93
|
+
export function ainuiAgentPicker(surfaceId, response, opts) {
|
|
94
|
+
const component = {
|
|
95
|
+
id: "root", component: "AgentPicker",
|
|
96
|
+
items: bind("items"), scope: bind("scope"), query: bind("query"), cursor: bind("cursor"), asOf: bind("asOf"),
|
|
97
|
+
cursorExpired: bind("cursorExpired"), selected: bind("selected"), renders: bind("renders"), context: bind("context"),
|
|
98
|
+
};
|
|
99
|
+
return pickerSurface(surfaceId, component, {
|
|
100
|
+
items: response.items,
|
|
101
|
+
scope: opts.scope,
|
|
102
|
+
query: opts.query ?? "",
|
|
103
|
+
cursor: response.nextCursor ?? null,
|
|
104
|
+
asOf: response.asOf,
|
|
105
|
+
cursorExpired: response.cursorExpired === true,
|
|
106
|
+
selected: opts.selected ?? "",
|
|
107
|
+
renders: opts.renders ?? [],
|
|
108
|
+
context: opts.context ?? {},
|
|
109
|
+
});
|
|
110
|
+
}
|