@ai-gui/plugin-sdk 0.4.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/CHANGELOG.md ADDED
@@ -0,0 +1,18 @@
1
+ # @ai-gui/plugin-sdk
2
+
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Add plugin authoring helpers, secure source citation blocks, revisioned artifacts, bounded declarative AI-generated UI trees, molecular structures, and interactive maps.
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+ - @ai-gui/core@0.4.0
13
+
14
+ ## 0.3.0
15
+
16
+ ### Minor Changes
17
+
18
+ - Add minimal plugin authoring exports and pure plugin test helpers.
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,48 @@
1
+ # @ai-gui/plugin-sdk
2
+
3
+ Minimal authoring and test helpers for AIGUI plugins. The package has no test-runner dependency and is safe to import in Node.js.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ pnpm add @ai-gui/core @ai-gui/plugin-sdk
9
+ ```
10
+
11
+ ## Author a plugin
12
+
13
+ ```ts
14
+ import { definePlugin } from "@ai-gui/plugin-sdk"
15
+
16
+ export const example = definePlugin({
17
+ name: "example",
18
+ nodeRenderers: {
19
+ example: (node) => ({ kind: "html", html: node.content ?? "" }),
20
+ },
21
+ })
22
+ ```
23
+
24
+ `definePlugin` is an identity helper: it validates the plugin shape while preserving its concrete inferred type.
25
+
26
+ ## Test a plugin
27
+
28
+ ```ts
29
+ import { createTestNode, renderPluginNode } from "@ai-gui/plugin-sdk"
30
+
31
+ const output = await renderPluginNode(example, createTestNode("example", { content: "Hello" }))
32
+ ```
33
+
34
+ For mount outputs, supply your own element and clean up safely:
35
+
36
+ ```ts
37
+ import { mountOutputForTest } from "@ai-gui/plugin-sdk"
38
+
39
+ const cleanup = mountOutputForTest(output, element, optionalMountContext)
40
+ cleanup()
41
+ cleanup() // harmless; an underlying disposer runs at most once
42
+ ```
43
+
44
+ ## Exports
45
+
46
+ - Core authoring types: `AIGuiPlugin`, `ASTNode`, `CardDef`, `CollectNodeRendererOptions`, `JSONSchema`, `NodeRenderer`, `PluginCommitContext`, `RenderOutput`.
47
+ - Core helpers: `collectNodeRenderers`, `pluginNodeTypes`.
48
+ - SDK helpers: `definePlugin`, `createTestNode`, `getPluginRenderer`, `renderPluginNode`, `mountOutputForTest`.
package/dist/index.cjs ADDED
@@ -0,0 +1,80 @@
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
+ /** Define a plugin while preserving the concrete type of its configuration. */
29
+ function definePlugin(plugin) {
30
+ return plugin;
31
+ }
32
+ /** Create a complete plugin node with deterministic defaults for tests. */
33
+ function createTestNode(type, overrides = {}) {
34
+ return {
35
+ key: `test:${type}`,
36
+ type,
37
+ complete: true,
38
+ ...overrides
39
+ };
40
+ }
41
+ /** Return a plugin renderer or throw when the node type is not registered. */
42
+ function getPluginRenderer(plugin, nodeType) {
43
+ const renderer = plugin.nodeRenderers?.[nodeType];
44
+ if (!renderer) throw new Error(`Plugin "${plugin.name}" does not define a renderer for node type "${nodeType}".`);
45
+ return renderer;
46
+ }
47
+ /** Render a node through its plugin renderer and normalize sync output to a promise. */
48
+ async function renderPluginNode(plugin, node) {
49
+ return getPluginRenderer(plugin, node.type)(node);
50
+ }
51
+ /** Mount a mount output into a supplied element and return an idempotent cleanup. */
52
+ function mountOutputForTest(output, element, context = {}) {
53
+ if (output.kind !== "mount") throw new Error(`Expected a "mount" render output, received "${output.kind}".`);
54
+ const dispose = output.mount(element, context);
55
+ let cleaned = false;
56
+ return () => {
57
+ if (cleaned) return;
58
+ cleaned = true;
59
+ dispose?.();
60
+ };
61
+ }
62
+
63
+ //#endregion
64
+ Object.defineProperty(exports, 'collectNodeRenderers', {
65
+ enumerable: true,
66
+ get: function () {
67
+ return __ai_gui_core.collectNodeRenderers;
68
+ }
69
+ });
70
+ exports.createTestNode = createTestNode
71
+ exports.definePlugin = definePlugin
72
+ exports.getPluginRenderer = getPluginRenderer
73
+ exports.mountOutputForTest = mountOutputForTest
74
+ Object.defineProperty(exports, 'pluginNodeTypes', {
75
+ enumerable: true,
76
+ get: function () {
77
+ return __ai_gui_core.pluginNodeTypes;
78
+ }
79
+ });
80
+ exports.renderPluginNode = renderPluginNode
@@ -0,0 +1,17 @@
1
+ import { AIGuiPlugin, AIGuiPlugin as AIGuiPlugin$1, ASTNode, ASTNode as ASTNode$1, CardDef, CollectNodeRendererOptions, JSONSchema, MountCardSlotRequest, MountedCardSlot, NodeRenderer, NodeRenderer as NodeRenderer$1, PluginCommitContext, RenderMountContext, RenderMountContext as RenderMountContext$1, RenderOutput, RenderOutput as RenderOutput$1, collectNodeRenderers, pluginNodeTypes } from "@ai-gui/core";
2
+
3
+ //#region src/index.d.ts
4
+ /** Define a plugin while preserving the concrete type of its configuration. */
5
+ /** Define a plugin while preserving the concrete type of its configuration. */
6
+ declare function definePlugin<const TPlugin extends AIGuiPlugin$1>(plugin: TPlugin): TPlugin;
7
+ /** Create a complete plugin node with deterministic defaults for tests. */
8
+ declare function createTestNode(type: string, overrides?: Omit<Partial<ASTNode$1>, "type">): ASTNode$1;
9
+ /** Return a plugin renderer or throw when the node type is not registered. */
10
+ declare function getPluginRenderer(plugin: AIGuiPlugin$1, nodeType: string): NodeRenderer$1;
11
+ /** Render a node through its plugin renderer and normalize sync output to a promise. */
12
+ declare function renderPluginNode(plugin: AIGuiPlugin$1, node: ASTNode$1): Promise<RenderOutput$1>;
13
+ /** Mount a mount output into a supplied element and return an idempotent cleanup. */
14
+ declare function mountOutputForTest(output: RenderOutput$1, element: HTMLElement, context?: RenderMountContext$1): () => void;
15
+
16
+ //#endregion
17
+ export { AIGuiPlugin, ASTNode, CardDef, CollectNodeRendererOptions, JSONSchema, MountCardSlotRequest, MountedCardSlot, NodeRenderer, PluginCommitContext, RenderMountContext, RenderOutput, collectNodeRenderers, createTestNode, definePlugin, getPluginRenderer, mountOutputForTest, pluginNodeTypes, renderPluginNode };
@@ -0,0 +1,17 @@
1
+ import { AIGuiPlugin, AIGuiPlugin as AIGuiPlugin$1, ASTNode, ASTNode as ASTNode$1, CardDef, CollectNodeRendererOptions, JSONSchema, MountCardSlotRequest, MountedCardSlot, NodeRenderer, NodeRenderer as NodeRenderer$1, PluginCommitContext, RenderMountContext, RenderMountContext as RenderMountContext$1, RenderOutput, RenderOutput as RenderOutput$1, collectNodeRenderers, pluginNodeTypes } from "@ai-gui/core";
2
+
3
+ //#region src/index.d.ts
4
+ /** Define a plugin while preserving the concrete type of its configuration. */
5
+ /** Define a plugin while preserving the concrete type of its configuration. */
6
+ declare function definePlugin<const TPlugin extends AIGuiPlugin$1>(plugin: TPlugin): TPlugin;
7
+ /** Create a complete plugin node with deterministic defaults for tests. */
8
+ declare function createTestNode(type: string, overrides?: Omit<Partial<ASTNode$1>, "type">): ASTNode$1;
9
+ /** Return a plugin renderer or throw when the node type is not registered. */
10
+ declare function getPluginRenderer(plugin: AIGuiPlugin$1, nodeType: string): NodeRenderer$1;
11
+ /** Render a node through its plugin renderer and normalize sync output to a promise. */
12
+ declare function renderPluginNode(plugin: AIGuiPlugin$1, node: ASTNode$1): Promise<RenderOutput$1>;
13
+ /** Mount a mount output into a supplied element and return an idempotent cleanup. */
14
+ declare function mountOutputForTest(output: RenderOutput$1, element: HTMLElement, context?: RenderMountContext$1): () => void;
15
+
16
+ //#endregion
17
+ export { AIGuiPlugin, ASTNode, CardDef, CollectNodeRendererOptions, JSONSchema, MountCardSlotRequest, MountedCardSlot, NodeRenderer, PluginCommitContext, RenderMountContext, RenderOutput, collectNodeRenderers, createTestNode, definePlugin, getPluginRenderer, mountOutputForTest, pluginNodeTypes, renderPluginNode };
package/dist/index.js ADDED
@@ -0,0 +1,40 @@
1
+ import { collectNodeRenderers, pluginNodeTypes } from "@ai-gui/core";
2
+
3
+ //#region src/index.ts
4
+ /** Define a plugin while preserving the concrete type of its configuration. */
5
+ function definePlugin(plugin) {
6
+ return plugin;
7
+ }
8
+ /** Create a complete plugin node with deterministic defaults for tests. */
9
+ function createTestNode(type, overrides = {}) {
10
+ return {
11
+ key: `test:${type}`,
12
+ type,
13
+ complete: true,
14
+ ...overrides
15
+ };
16
+ }
17
+ /** Return a plugin renderer or throw when the node type is not registered. */
18
+ function getPluginRenderer(plugin, nodeType) {
19
+ const renderer = plugin.nodeRenderers?.[nodeType];
20
+ if (!renderer) throw new Error(`Plugin "${plugin.name}" does not define a renderer for node type "${nodeType}".`);
21
+ return renderer;
22
+ }
23
+ /** Render a node through its plugin renderer and normalize sync output to a promise. */
24
+ async function renderPluginNode(plugin, node) {
25
+ return getPluginRenderer(plugin, node.type)(node);
26
+ }
27
+ /** Mount a mount output into a supplied element and return an idempotent cleanup. */
28
+ function mountOutputForTest(output, element, context = {}) {
29
+ if (output.kind !== "mount") throw new Error(`Expected a "mount" render output, received "${output.kind}".`);
30
+ const dispose = output.mount(element, context);
31
+ let cleaned = false;
32
+ return () => {
33
+ if (cleaned) return;
34
+ cleaned = true;
35
+ dispose?.();
36
+ };
37
+ }
38
+
39
+ //#endregion
40
+ export { collectNodeRenderers, createTestNode, definePlugin, getPluginRenderer, mountOutputForTest, pluginNodeTypes, renderPluginNode };
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@ai-gui/plugin-sdk",
3
+ "version": "0.4.0",
4
+ "description": "Minimal plugin authoring and testing helpers for AIGUI.",
5
+ "keywords": [
6
+ "llm",
7
+ "ai",
8
+ "streaming",
9
+ "plugin",
10
+ "testing",
11
+ "sdk",
12
+ "aigui"
13
+ ],
14
+ "license": "MIT",
15
+ "author": "Liang Li <ll_faw@hotmail.com>",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/liliang-cn/aigui.git",
19
+ "directory": "packages/plugin-sdk"
20
+ },
21
+ "homepage": "https://github.com/liliang-cn/aigui#readme",
22
+ "bugs": "https://github.com/liliang-cn/aigui/issues",
23
+ "type": "module",
24
+ "sideEffects": false,
25
+ "engines": {
26
+ "node": ">=18"
27
+ },
28
+ "main": "./dist/index.cjs",
29
+ "module": "./dist/index.js",
30
+ "types": "./dist/index.d.ts",
31
+ "exports": {
32
+ ".": {
33
+ "import": {
34
+ "types": "./dist/index.d.ts",
35
+ "default": "./dist/index.js"
36
+ },
37
+ "require": {
38
+ "types": "./dist/index.d.cts",
39
+ "default": "./dist/index.cjs"
40
+ }
41
+ }
42
+ },
43
+ "files": [
44
+ "dist",
45
+ "README.md",
46
+ "LICENSE",
47
+ "CHANGELOG.md"
48
+ ],
49
+ "publishConfig": {
50
+ "access": "public"
51
+ },
52
+ "dependencies": {
53
+ "@ai-gui/core": "0.4.0"
54
+ },
55
+ "scripts": {
56
+ "build": "tsdown",
57
+ "test": "pnpm --dir ../.. exec vitest run --project plugin-sdk",
58
+ "typecheck": "tsc --noEmit"
59
+ }
60
+ }