ain-ui 1.0.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/dist/agent.js +22 -2
- package/dist/ainui.js +7 -2
- package/dist/basic.js +11 -4
- package/dist/react/core.d.ts +7 -0
- package/dist/react/core.js +16 -1
- package/dist/react/surface.d.ts +3 -1
- package/dist/react/surface.js +3 -3
- package/package.json +1 -1
package/dist/agent.js
CHANGED
|
@@ -446,6 +446,24 @@ function hoistItemEvents(c, schema, notes) {
|
|
|
446
446
|
return c;
|
|
447
447
|
}
|
|
448
448
|
const CHECK_MESSAGES = { required: "Required", email: "Enter a valid email address", regex: "Check the format", length: "Check the length", numeric: "Enter a number in range" };
|
|
449
|
+
/** The name a function call is written with: `@call`, or `call` as models also write it. */
|
|
450
|
+
const callName = (x) => (isObj(x) && typeof (x["@call"] ?? x.call) === "string" ? String(x["@call"] ?? x.call) : null);
|
|
451
|
+
/** One `checks` entry as the catalog wants it: `{ condition, message }`, the condition a bare call or a path. */
|
|
452
|
+
function checkRule(x, where, notes) {
|
|
453
|
+
if (!isObj(x))
|
|
454
|
+
return x;
|
|
455
|
+
const name = callName(x);
|
|
456
|
+
if (name && !("condition" in x)) {
|
|
457
|
+
const { message, ...call } = x;
|
|
458
|
+
notes.push(`${where}: a check was written as the call itself; it became the check's condition`);
|
|
459
|
+
return { condition: call, message: typeof message === "string" && message.trim() ? message : CHECK_MESSAGES[name] ?? "Check this value" };
|
|
460
|
+
}
|
|
461
|
+
if (isObj(x.condition) && callName(x.condition) && "message" in x.condition) {
|
|
462
|
+
const { message, ...call } = x.condition;
|
|
463
|
+
return { ...x, condition: call, message: typeof x.message === "string" && x.message.trim() ? x.message : typeof message === "string" ? message : CHECK_MESSAGES[callName(call)] ?? "Check this value" };
|
|
464
|
+
}
|
|
465
|
+
return x;
|
|
466
|
+
}
|
|
449
467
|
/**
|
|
450
468
|
* A Table's cells may hold components (`{"componentId": "b"}` in rows or columns), and the renderer counts them as
|
|
451
469
|
* the table's only when they are also listed in `cellComponents`. Models list them in the rows and forget the list.
|
|
@@ -500,9 +518,11 @@ function tidyComponent(c, docs, notes) {
|
|
|
500
518
|
out[k] = v.map((x) => (isObj(x) && typeof (x.componentId ?? x.id) === "string" && Object.keys(x).length === 1 ? (x.componentId ?? x.id) : x));
|
|
501
519
|
continue;
|
|
502
520
|
}
|
|
503
|
-
//
|
|
521
|
+
// A validation check written as the bare function call — often with its message beside the call
|
|
522
|
+
// ({"@call": "email", args, message}) — is the condition; the message belongs to the check, not to the call,
|
|
523
|
+
// whose arguments the catalog checks strictly. A condition that itself carries the message is moved the same way.
|
|
504
524
|
if (k === "checks" && Array.isArray(v)) {
|
|
505
|
-
out[k] = v.map((x) => (
|
|
525
|
+
out[k] = v.map((x) => checkRule(x, `${c.component} "${c.id}"`, notes));
|
|
506
526
|
continue;
|
|
507
527
|
}
|
|
508
528
|
out[k] = tidy(v, prop, notes, `${c.component} "${c.id}".${k}`);
|
package/dist/ainui.js
CHANGED
|
@@ -110,8 +110,13 @@ export function asAinui(messages) {
|
|
|
110
110
|
const t = c.text;
|
|
111
111
|
const call = t && typeof t === "object" ? t : null;
|
|
112
112
|
const m = typeof t === "string" ? /^(#{1,5}) (.*)$/s.exec(t) : call?.["@call"] === "formatString" ? /^(#{1,5}) \$\{(.+)\}$/.exec(call.args?.value ?? "") : null;
|
|
113
|
-
if (!m)
|
|
114
|
-
|
|
113
|
+
if (!m) {
|
|
114
|
+
if (c.variant !== "caption")
|
|
115
|
+
return c;
|
|
116
|
+
// leave the key out: an own `variant: undefined` is still an unknown property to a strict validator
|
|
117
|
+
const { variant: _variant, ...rest } = c;
|
|
118
|
+
return { ...rest, component: "Caption" };
|
|
119
|
+
}
|
|
115
120
|
const size = ["2xl", "xl", "lg", "md", "sm"][m[1].length - 1];
|
|
116
121
|
return { ...c, component: "Title", size, text: typeof t === "string" ? m[2] : { "@path": m[2] } };
|
|
117
122
|
};
|
package/dist/basic.js
CHANGED
|
@@ -51,12 +51,19 @@ function listSurface(prefix, opts) {
|
|
|
51
51
|
const tb = ["search_field", "search_btn"];
|
|
52
52
|
if (opts.path)
|
|
53
53
|
tb.unshift("up_btn");
|
|
54
|
-
|
|
54
|
+
// ⬆ Up only below the top folder; its components go with it (1.0 refuses unreachable ones)
|
|
55
|
+
if (opts.path)
|
|
56
|
+
comps.push(button("up_btn", "up_label", "aindrive.open", { drive_id: { path: "/drive_id" }, path: { path: "/parent" }, is_dir: true }), text("up_label", "⬆ Up"));
|
|
57
|
+
comps.push(row("toolbar", tb, { align: "center" }), { id: "search_field", component: "TextField", label: "Search file names", value: { path: "/query" }, weight: 1 }, button("search_btn", "search_label", "aindrive.search", { drive_id: { path: "/drive_id" }, query: { path: "/query" }, path: { path: "/path" } }, "primary"), text("search_label", "Search"));
|
|
55
58
|
}
|
|
56
59
|
rootChildren.push(opts.items.length ? "list" : "empty");
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
+
// Only the branch the root shows: A2UI 1.0 refuses a surface with components the root cannot reach.
|
|
61
|
+
if (!opts.items.length)
|
|
62
|
+
comps.push(text("empty", "(empty)", "caption"));
|
|
63
|
+
else
|
|
64
|
+
comps.push({ id: "list", component: "List", children: { componentId: "item", path: "/items" } }, row("item", ["item_open", "item_meta"], { align: "center", justify: "spaceBetween" }), button("item_open", "item_label", open, open === "aindrive.open_drive"
|
|
65
|
+
? { drive_id: { path: "drive_id" } }
|
|
66
|
+
: { drive_id: { path: "drive_id" }, path: { path: "path" }, is_dir: { path: "is_dir" } }, "borderless"), text("item_label", { path: "label" }), text("item_meta", { path: "meta" }, "caption"));
|
|
60
67
|
if (opts.note) {
|
|
61
68
|
rootChildren.push("note");
|
|
62
69
|
comps.push(text("note", opts.note, "caption"));
|
package/dist/react/core.d.ts
CHANGED
|
@@ -24,6 +24,13 @@ export type ViewProps<P = Record<string, any>> = {
|
|
|
24
24
|
accessibilityRef?: (element: Element | null) => void;
|
|
25
25
|
validationErrorsRef?: (element: Element | null) => void;
|
|
26
26
|
};
|
|
27
|
+
/**
|
|
28
|
+
* Inspect mode (`<AinuiSurface inspect>`): every component is drawn inside an element that names it —
|
|
29
|
+
* `data-ainui-id` and `data-ainui-component` on a `display: contents` span, so it adds no box and moves nothing —
|
|
30
|
+
* letting a host find which component the pointer is over (`event.target.closest("[data-ainui-id]")`).
|
|
31
|
+
* Off by default: a surface drawn for people has no extra elements.
|
|
32
|
+
*/
|
|
33
|
+
export declare const InspectContext: React.Context<boolean>;
|
|
27
34
|
/** A view for one component of the catalog. The name must exist in standard.json or ain.json. */
|
|
28
35
|
export declare function standard<P = Record<string, any>>(name: string, View: React.FC<ViewProps<P>>): ReactComponentImplementation;
|
|
29
36
|
/** One child, by the reference the binder resolved: an id, or a template instance `{id, basePath}`. */
|
package/dist/react/core.js
CHANGED
|
@@ -13,13 +13,28 @@ import { createComponentImplementation } from "@a2ui/react";
|
|
|
13
13
|
import { AINUI_CATALOG_DOCUMENT } from "../catalog/standard.gen.js";
|
|
14
14
|
/** The AINUI catalog as published: names, props and descriptions. Views are attached in ./catalog.ts. */
|
|
15
15
|
export const STANDARD = Catalog.fromJson(AINUI_CATALOG_DOCUMENT, "1.0");
|
|
16
|
+
/**
|
|
17
|
+
* Inspect mode (`<AinuiSurface inspect>`): every component is drawn inside an element that names it —
|
|
18
|
+
* `data-ainui-id` and `data-ainui-component` on a `display: contents` span, so it adds no box and moves nothing —
|
|
19
|
+
* letting a host find which component the pointer is over (`event.target.closest("[data-ainui-id]")`).
|
|
20
|
+
* Off by default: a surface drawn for people has no extra elements.
|
|
21
|
+
*/
|
|
22
|
+
export const InspectContext = createContext(false);
|
|
16
23
|
/** A view for one component of the catalog. The name must exist in standard.json or ain.json. */
|
|
17
24
|
export function standard(name, View) {
|
|
18
25
|
const api = STANDARD.components.get(name);
|
|
19
26
|
if (!api)
|
|
20
27
|
throw new Error(`"${name}" is not in the AINUI catalog`);
|
|
21
28
|
View.displayName = name;
|
|
22
|
-
|
|
29
|
+
const Tagged = (props) => {
|
|
30
|
+
const inspect = useContext(InspectContext);
|
|
31
|
+
if (!inspect)
|
|
32
|
+
return _jsx(View, { ...props });
|
|
33
|
+
const id = props.context?.componentModel?.id;
|
|
34
|
+
return _jsx("span", { "data-ainui-id": id, "data-ainui-component": name, style: { display: "contents" }, children: _jsx(View, { ...props }) });
|
|
35
|
+
};
|
|
36
|
+
Tagged.displayName = name;
|
|
37
|
+
return createComponentImplementation(api, Tagged);
|
|
23
38
|
}
|
|
24
39
|
/** One child, by the reference the binder resolved: an id, or a template instance `{id, basePath}`. */
|
|
25
40
|
export const kid = (buildChild, ref) => ref == null || ref === "" ? null : typeof ref === "string" ? buildChild(ref) : buildChild(ref.id, ref.basePath);
|
package/dist/react/surface.d.ts
CHANGED
|
@@ -24,8 +24,10 @@ export type AinuiSurfaceProps = {
|
|
|
24
24
|
/** Design system: "ain" (default), "plain" or "material", or any name the host styles via `[data-ainui-theme]`. */
|
|
25
25
|
theme?: string;
|
|
26
26
|
className?: string;
|
|
27
|
+
/** Tag each drawn component with its id (`data-ainui-id`), for tools that show a component's source on hover. */
|
|
28
|
+
inspect?: boolean;
|
|
27
29
|
};
|
|
28
|
-
export declare function AinuiSurface({ messages, onAction, onMessage, onError, resolveAsset, renderFile, sendMessage, openUrl, theme, className }: AinuiSurfaceProps): React.JSX.Element;
|
|
30
|
+
export declare function AinuiSurface({ messages, onAction, onMessage, onError, resolveAsset, renderFile, sendMessage, openUrl, theme, className, inspect }: AinuiSurfaceProps): React.JSX.Element;
|
|
29
31
|
export type FolderChatSend = (turn: {
|
|
30
32
|
q: string;
|
|
31
33
|
agentId: string;
|
package/dist/react/surface.js
CHANGED
|
@@ -8,7 +8,7 @@ import { renderMarkdown } from "@a2ui/markdown-it";
|
|
|
8
8
|
import { upgradeMessages } from "../protocol.js";
|
|
9
9
|
import { ainuiFolderChat } from "../chat.js";
|
|
10
10
|
import { ainuiCatalog } from "./catalog.js";
|
|
11
|
-
import { HostContext } from "./core.js";
|
|
11
|
+
import { HostContext, InspectContext } from "./core.js";
|
|
12
12
|
const catalogs = [ainuiCatalog, basicCatalog];
|
|
13
13
|
/**
|
|
14
14
|
* What this renderer can draw, in the form an agent reads it (`a2uiRendererCapabilities`): the catalog ids, and
|
|
@@ -23,7 +23,7 @@ export function ainuiCapabilities(options = {}) {
|
|
|
23
23
|
p.dispose?.();
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
export function AinuiSurface({ messages, onAction, onMessage, onError, resolveAsset, renderFile, sendMessage, openUrl, theme, className }) {
|
|
26
|
+
export function AinuiSurface({ messages, onAction, onMessage, onError, resolveAsset, renderFile, sendMessage, openUrl, theme, className, inspect = false }) {
|
|
27
27
|
const handlers = useRef({ onAction, onMessage, onError });
|
|
28
28
|
handlers.current = { onAction, onMessage, onError };
|
|
29
29
|
const live = useRef(null);
|
|
@@ -78,7 +78,7 @@ export function AinuiSurface({ messages, onAction, onMessage, onError, resolveAs
|
|
|
78
78
|
return _jsx("div", { className: shell, "data-ainui-theme": theme, role: "alert", children: state.error });
|
|
79
79
|
if (!state.processor)
|
|
80
80
|
return _jsx("div", { className: shell, "data-ainui-theme": theme, "aria-busy": "true" });
|
|
81
|
-
return _jsx(MarkdownContext.Provider, { value: renderMarkdown, children: _jsx(HostContext.Provider, { value: host, children: _jsx("div", { className: shell, "data-ainui-theme": theme, children: Array.from(state.processor.model.surfacesMap.values()).map((surface) => _jsx(A2uiSurface, { surface: surface }, surface.id)) }) }) });
|
|
81
|
+
return _jsx(InspectContext.Provider, { value: inspect, children: _jsx(MarkdownContext.Provider, { value: renderMarkdown, children: _jsx(HostContext.Provider, { value: host, children: _jsx("div", { className: shell, "data-ainui-theme": theme, children: Array.from(state.processor.model.surfacesMap.values()).map((surface) => _jsx(A2uiSurface, { surface: surface }, surface.id)) }) }) }) });
|
|
82
82
|
}
|
|
83
83
|
/** Scope changes unmount the old chat, abort its request and drop its context ids. */
|
|
84
84
|
export function AinuiFolderChat(props) {
|