@bolloon/bolloon-agent 0.4.10 → 0.4.11
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/agents/pi-sdk-tools.js +19 -0
- package/dist/pi-ecosystem-a2ui/index.js +81 -0
- package/dist/web/a2ui-client.js +32697 -0
- package/dist/web/mobile.html +4 -0
- package/dist/web/server.js +10 -0
- package/package.json +3 -1
- package/scripts/build-web.ts +15 -0
|
@@ -2243,6 +2243,25 @@ export function registerBuiltinTools(ctx) {
|
|
|
2243
2243
|
}
|
|
2244
2244
|
};
|
|
2245
2245
|
registerUiAgentTools().catch(() => { });
|
|
2246
|
+
// 2026-08-12: A2UI (Agent to UI) 工具 — agent 生成 A2UI 消息 (createSurface/updateComponents),
|
|
2247
|
+
// 经 SSE 广播, 前端用 @a2ui/react renderer 渲染. 见 src/pi-ecosystem-a2ui/.
|
|
2248
|
+
(async () => {
|
|
2249
|
+
try {
|
|
2250
|
+
const a2ui = await import('../pi-ecosystem-a2ui/index.js');
|
|
2251
|
+
for (const t of a2ui.A2UI_TOOL_DEFS) {
|
|
2252
|
+
ctx.tools.set(t.name, {
|
|
2253
|
+
name: t.name,
|
|
2254
|
+
description: t.description,
|
|
2255
|
+
parameters: t.params,
|
|
2256
|
+
execute: async (args) => {
|
|
2257
|
+
const r = a2ui.dispatchA2uiMessage(t.build(args));
|
|
2258
|
+
return r.success ? { success: true, output: r.output } : { success: false, error: r.output };
|
|
2259
|
+
},
|
|
2260
|
+
});
|
|
2261
|
+
}
|
|
2262
|
+
}
|
|
2263
|
+
catch { /* A2UI 工具注册失败静默 */ }
|
|
2264
|
+
})();
|
|
2246
2265
|
// ============================================================
|
|
2247
2266
|
// publish_did (2026-08-03) — 把当前 agent 的 DID 发布到 IPFS + IPNS
|
|
2248
2267
|
// 全自动: 自动安装/启动本地 Kubo → 上传 DID 文档 → 发布 IPNS name
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* a2ui.ts — A2UI (Agent to UI) 协议集成 (2026-08-12)
|
|
3
|
+
*
|
|
4
|
+
* bolloon agent 生成 A2UI 消息 (createSurface / updateComponents / updateDataModel / deleteSurface),
|
|
5
|
+
* 经 SSE 广播给前端 (web / 手机端 Capacitor), 前端用 @a2ui/react renderer 渲染.
|
|
6
|
+
*
|
|
7
|
+
* 参考: https://a2ui.org/specification/v1.0-a2ui/ + D:\AI\A2UI (本地 spec 源码)
|
|
8
|
+
*
|
|
9
|
+
* 机制:
|
|
10
|
+
* - agent 工具 (a2ui_create_surface 等) 生成 A2UI JSON 消息
|
|
11
|
+
* - dispatchA2uiMessage → broadcast({ type: 'a2ui', message }) 给前端
|
|
12
|
+
* - 前端 MessageProcessor 接收渲染 (A2uiSurface)
|
|
13
|
+
*/
|
|
14
|
+
/** broadcast 注入点 (server 调用 setA2uiBroadcast 注入, 关联 SSE /events) */
|
|
15
|
+
let a2uiBroadcast = null;
|
|
16
|
+
export function setA2uiBroadcast(fn) {
|
|
17
|
+
a2uiBroadcast = fn;
|
|
18
|
+
}
|
|
19
|
+
/** 广播一条 A2UI 消息给所有前端 */
|
|
20
|
+
export function broadcastA2uiMessage(message) {
|
|
21
|
+
if (!a2uiBroadcast)
|
|
22
|
+
return false;
|
|
23
|
+
a2uiBroadcast({ type: 'a2ui', message });
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
/** 校验 + 广播一条 A2UI 消息 (agent 工具 execute 调用) */
|
|
27
|
+
export function dispatchA2uiMessage(message) {
|
|
28
|
+
const type = message?.type;
|
|
29
|
+
const surfaceId = String(message?.surfaceId || '').trim();
|
|
30
|
+
if (!type || !['createSurface', 'updateComponents', 'updateDataModel', 'deleteSurface'].includes(type)) {
|
|
31
|
+
return { success: false, output: 'type 必须是 createSurface/updateComponents/updateDataModel/deleteSurface' };
|
|
32
|
+
}
|
|
33
|
+
if (!surfaceId)
|
|
34
|
+
return { success: false, output: 'surfaceId 必填' };
|
|
35
|
+
const ok = broadcastA2uiMessage({ type, surfaceId, ...message });
|
|
36
|
+
return { success: ok, output: ok ? `已广播 A2UI ${type} (surface=${surfaceId})` : 'A2UI 广播未连接' };
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* agent 工具注册表 (a2ui-* 工具定义). 由 pi-sdk-tools 注册为 agent 工具.
|
|
40
|
+
*/
|
|
41
|
+
export const A2UI_TOOL_DEFS = [
|
|
42
|
+
{
|
|
43
|
+
name: 'a2ui_create_surface',
|
|
44
|
+
description: '创建 A2UI surface (前端渲染区). surfaceId: 渲染区标识. 用户想要一个动态 UI 面板/表单/卡片时先创建 surface.',
|
|
45
|
+
params: { surfaceId: '渲染区 id (必填)', title: 'surface 标题 (可选)' },
|
|
46
|
+
build: (a) => ({ type: 'createSurface', surfaceId: String(a.surfaceId || ''), title: String(a.title || '') }),
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: 'a2ui_update_components',
|
|
50
|
+
description: '向 A2UI surface 添加/更新组件 (componentTree JSON). 前端用 @a2ui/react 渲染. components: 组件树 JSON 数组 (Text/Column/Button 等 basicCatalog 组件).',
|
|
51
|
+
params: { surfaceId: '渲染区 id (必填)', components: '组件树 JSON (必填, e.g. [{"type":"text","data":{"text":"你好"}}])' },
|
|
52
|
+
build: (a) => {
|
|
53
|
+
let components = a.components;
|
|
54
|
+
if (typeof components === 'string') {
|
|
55
|
+
try {
|
|
56
|
+
components = JSON.parse(components);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
components = [];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return { type: 'updateComponents', surfaceId: String(a.surfaceId || ''), components };
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
name: 'a2ui_update_data',
|
|
67
|
+
description: '更新 A2UI surface 的数据模型. path: 数据路径 (如 /user/name), value: 数据值.',
|
|
68
|
+
params: { surfaceId: '渲染区 id (必填)', path: '数据路径 (必填)', value: '数据值' },
|
|
69
|
+
build: (a) => ({ type: 'updateDataModel', surfaceId: String(a.surfaceId || ''), path: String(a.path || ''), value: a.value }),
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
name: 'a2ui_delete_surface',
|
|
73
|
+
description: '删除 A2UI surface (移除前端渲染区). surfaceId: 渲染区 id.',
|
|
74
|
+
params: { surfaceId: '渲染区 id (必填)' },
|
|
75
|
+
build: (a) => ({ type: 'deleteSurface', surfaceId: String(a.surfaceId || '') }),
|
|
76
|
+
},
|
|
77
|
+
];
|
|
78
|
+
/** 工具名 → build 函数 */
|
|
79
|
+
export function a2uiToolDef(name) {
|
|
80
|
+
return A2UI_TOOL_DEFS.find((t) => t.name === name);
|
|
81
|
+
}
|