@ai-gui/plugin-primitives 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Liang Li
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,32 @@
1
+ # @ai-gui/plugin-primitives
2
+
3
+ Primitive UI-block plugin for [AIGUI](../../README.md). Adds four structured, data-driven blocks the model can emit as fenced JSON: `list`, `table`, `key-value`, and `layout`.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ pnpm add @ai-gui/plugin-primitives
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```tsx
14
+ import { primitives } from "@ai-gui/plugin-primitives"
15
+ import { AIRenderer } from "@ai-gui/react"
16
+
17
+ <AIRenderer plugins={[primitives()]} />
18
+ ```
19
+
20
+ The model emits, e.g.:
21
+
22
+ ```table {"headers":["City","°C"],"rows":[["Tokyo",24],["Oslo",9]]}```
23
+ ```list {"items":["one","two","three"]}```
24
+ ```key-value {"pairs":{"status":"ok","count":3}}```
25
+ ```layout {"direction":"row","items":[...]}```
26
+
27
+ ## Exports
28
+
29
+ - `primitives()` — the plugin.
30
+ - `primitivesPromptSpec()` — the prompt-spec string describing these blocks (also folded in automatically by `buildSystemPrompt` when the plugin is passed).
31
+
32
+ See the [root README](../../README.md) for the full plugin list.
package/dist/index.cjs ADDED
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ //#region rolldown:runtime
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
+ get: ((k) => from[k]).bind(null, key),
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
20
+ value: mod,
21
+ enumerable: true
22
+ }) : target, mod));
23
+
24
+ //#endregion
25
+ const __ai_gui_core = __toESM(require("@ai-gui/core"));
26
+
27
+ //#region src/index.ts
28
+ const el = (tag, props, children) => ({
29
+ kind: "element",
30
+ tag,
31
+ props,
32
+ children
33
+ });
34
+ const text = (s) => ({
35
+ kind: "html",
36
+ html: escapeHtml(s)
37
+ });
38
+ function escapeHtml(s) {
39
+ return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
40
+ }
41
+ function data(node) {
42
+ return (0, __ai_gui_core.parsePartialJSON)(node.content ?? "").data ?? {};
43
+ }
44
+ function renderList(node) {
45
+ const items = data(node).items ?? [];
46
+ return el("ul", { "data-aigui-primitive": "list" }, items.map((i) => el("li", void 0, [text(String(i))])));
47
+ }
48
+ function renderKeyValue(node) {
49
+ const pairs = data(node).pairs ?? {};
50
+ return el("dl", { "data-aigui-primitive": "key-value" }, Object.entries(pairs).flatMap(([k, v]) => [el("dt", void 0, [text(k)]), el("dd", void 0, [text(String(v))])]));
51
+ }
52
+ function renderTable(node) {
53
+ const d = data(node);
54
+ const headers = d.headers ?? [];
55
+ const rows = d.rows ?? [];
56
+ const thead = el("thead", void 0, [el("tr", void 0, headers.map((h) => el("th", void 0, [text(String(h))])))]);
57
+ const tbody = el("tbody", void 0, rows.map((r) => el("tr", void 0, (r ?? []).map((c) => el("td", void 0, [text(String(c))])))));
58
+ return el("table", { "data-aigui-primitive": "table" }, [thead, tbody]);
59
+ }
60
+ function renderLayout(node) {
61
+ const d = data(node);
62
+ const dir = d.direction === "row" ? "row" : "column";
63
+ const items = d.items ?? [];
64
+ return el("div", {
65
+ "data-aigui-primitive": "layout",
66
+ style: `display:flex;flex-direction:${dir}`
67
+ }, items.map((i) => el("div", void 0, [text(String(i))])));
68
+ }
69
+ function primitivesPromptSpec() {
70
+ return ["Primitive UI blocks (fenced): ```list {\"items\":[...]}```; ```table {\"headers\":[...],\"rows\":[[...]]}```;", "```key-value {\"pairs\":{\"k\":\"v\"}}```; ```layout {\"direction\":\"row|column\",\"items\":[...]}```."].join("\n");
71
+ }
72
+ function primitives() {
73
+ return {
74
+ name: "primitives",
75
+ nodeRenderers: {
76
+ list: renderList,
77
+ "key-value": renderKeyValue,
78
+ table: renderTable,
79
+ layout: renderLayout
80
+ },
81
+ promptSpec: primitivesPromptSpec()
82
+ };
83
+ }
84
+
85
+ //#endregion
86
+ exports.primitives = primitives
87
+ exports.primitivesPromptSpec = primitivesPromptSpec
@@ -0,0 +1,8 @@
1
+ import { AIGuiPlugin } from "@ai-gui/core";
2
+
3
+ //#region src/index.d.ts
4
+ declare function primitivesPromptSpec(): string;
5
+ declare function primitives(): AIGuiPlugin;
6
+
7
+ //#endregion
8
+ export { primitives, primitivesPromptSpec };
@@ -0,0 +1,8 @@
1
+ import { AIGuiPlugin } from "@ai-gui/core";
2
+
3
+ //#region src/index.d.ts
4
+ declare function primitivesPromptSpec(): string;
5
+ declare function primitives(): AIGuiPlugin;
6
+
7
+ //#endregion
8
+ export { primitives, primitivesPromptSpec };
package/dist/index.js ADDED
@@ -0,0 +1,62 @@
1
+ import { parsePartialJSON } from "@ai-gui/core";
2
+
3
+ //#region src/index.ts
4
+ const el = (tag, props, children) => ({
5
+ kind: "element",
6
+ tag,
7
+ props,
8
+ children
9
+ });
10
+ const text = (s) => ({
11
+ kind: "html",
12
+ html: escapeHtml(s)
13
+ });
14
+ function escapeHtml(s) {
15
+ return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
16
+ }
17
+ function data(node) {
18
+ return parsePartialJSON(node.content ?? "").data ?? {};
19
+ }
20
+ function renderList(node) {
21
+ const items = data(node).items ?? [];
22
+ return el("ul", { "data-aigui-primitive": "list" }, items.map((i) => el("li", void 0, [text(String(i))])));
23
+ }
24
+ function renderKeyValue(node) {
25
+ const pairs = data(node).pairs ?? {};
26
+ return el("dl", { "data-aigui-primitive": "key-value" }, Object.entries(pairs).flatMap(([k, v]) => [el("dt", void 0, [text(k)]), el("dd", void 0, [text(String(v))])]));
27
+ }
28
+ function renderTable(node) {
29
+ const d = data(node);
30
+ const headers = d.headers ?? [];
31
+ const rows = d.rows ?? [];
32
+ const thead = el("thead", void 0, [el("tr", void 0, headers.map((h) => el("th", void 0, [text(String(h))])))]);
33
+ const tbody = el("tbody", void 0, rows.map((r) => el("tr", void 0, (r ?? []).map((c) => el("td", void 0, [text(String(c))])))));
34
+ return el("table", { "data-aigui-primitive": "table" }, [thead, tbody]);
35
+ }
36
+ function renderLayout(node) {
37
+ const d = data(node);
38
+ const dir = d.direction === "row" ? "row" : "column";
39
+ const items = d.items ?? [];
40
+ return el("div", {
41
+ "data-aigui-primitive": "layout",
42
+ style: `display:flex;flex-direction:${dir}`
43
+ }, items.map((i) => el("div", void 0, [text(String(i))])));
44
+ }
45
+ function primitivesPromptSpec() {
46
+ return ["Primitive UI blocks (fenced): ```list {\"items\":[...]}```; ```table {\"headers\":[...],\"rows\":[[...]]}```;", "```key-value {\"pairs\":{\"k\":\"v\"}}```; ```layout {\"direction\":\"row|column\",\"items\":[...]}```."].join("\n");
47
+ }
48
+ function primitives() {
49
+ return {
50
+ name: "primitives",
51
+ nodeRenderers: {
52
+ list: renderList,
53
+ "key-value": renderKeyValue,
54
+ table: renderTable,
55
+ layout: renderLayout
56
+ },
57
+ promptSpec: primitivesPromptSpec()
58
+ };
59
+ }
60
+
61
+ //#endregion
62
+ export { primitives, primitivesPromptSpec };
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@ai-gui/plugin-primitives",
3
+ "version": "0.1.0",
4
+ "description": "Framework-neutral primitive UI cards (list/table/key-value/layout) for AIGUI.",
5
+ "keywords": [
6
+ "llm",
7
+ "ai",
8
+ "streaming",
9
+ "markdown",
10
+ "cards",
11
+ "table",
12
+ "list",
13
+ "primitives",
14
+ "plugin",
15
+ "aigui"
16
+ ],
17
+ "license": "MIT",
18
+ "author": "Liang Li <ll_faw@hotmail.com>",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/liliang-cn/aigui.git",
22
+ "directory": "packages/plugin-primitives"
23
+ },
24
+ "homepage": "https://github.com/liliang-cn/aigui#readme",
25
+ "bugs": "https://github.com/liliang-cn/aigui/issues",
26
+ "type": "module",
27
+ "main": "./dist/index.cjs",
28
+ "module": "./dist/index.js",
29
+ "types": "./dist/index.d.ts",
30
+ "exports": {
31
+ ".": {
32
+ "types": "./dist/index.d.ts",
33
+ "import": "./dist/index.js",
34
+ "require": "./dist/index.cjs"
35
+ }
36
+ },
37
+ "files": [
38
+ "dist",
39
+ "README.md",
40
+ "LICENSE"
41
+ ],
42
+ "publishConfig": {
43
+ "access": "public"
44
+ },
45
+ "dependencies": {
46
+ "@ai-gui/core": "0.1.0"
47
+ },
48
+ "scripts": {
49
+ "build": "tsdown",
50
+ "typecheck": "tsc --noEmit"
51
+ }
52
+ }