bailinghub 0.3.3 → 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/README.en.md +3 -1
- package/README.md +4 -0
- package/docker-compose.images.yml +2 -2
- package/docs/CHANGELOG.en.md +58 -1
- package/docs/CHANGELOG.md +26 -1
- package/docs/COMPATIBILITY.en.md +25 -0
- package/docs/CONTRACT.en.md +91 -8
- package/docs/CONTRACT.md +39 -7
- package/docs/DEMO.en.md +6 -0
- package/docs/DEMO.md +2 -0
- package/docs/INDEPENDENT_VALIDATION.en.md +9 -6
- package/docs/INDEPENDENT_VALIDATION.md +9 -6
- package/docs/QUICKSTART.en.md +20 -0
- package/docs/QUICKSTART.md +2 -2
- package/docs/README.en.md +4 -0
- package/docs/README.md +4 -0
- package/docs/RELEASE_NOTES_v0.3.4.en.md +38 -0
- package/docs/RELEASE_NOTES_v0.3.4.md +38 -0
- package/docs/RELEASE_NOTES_v0.4.0.en.md +39 -0
- package/docs/RELEASE_NOTES_v0.4.0.md +39 -0
- package/docs/STREAMING.en.md +32 -0
- package/docs/STREAMING.md +8 -2
- package/docs/WIDGET_RENDERERS.en.md +123 -6
- package/docs/WIDGET_RENDERERS.md +75 -6
- package/docs/user-guide/concepts.en.md +8 -1
- package/docs/user-guide/concepts.md +3 -1
- package/docs/user-guide/console-map.en.md +1 -2
- package/docs/user-guide/console-map.md +3 -3
- package/docs//345/205/274/345/256/271/346/200/247/344/270/216/345/215/207/347/272/247.md +9 -0
- package/package.json +1 -1
- package/schemas/config/chat-entry.schema.json +2 -1
- package/scripts/check-doc-links.mjs +2 -0
- package/scripts/check-image-tags.sh +1 -1
- package/scripts/check-release-consistency.test.mjs +5 -5
- package/scripts/e2e-console.mjs +38 -10
- package/scripts/install.sh +1 -1
- package/scripts/publish-images.sh +1 -1
- package/scripts/release-audit.mjs +2 -0
- package/scripts/verify-github-repo.mjs +2 -0
- package/scripts/widget-renderer-test.mjs +244 -16
- package/src/core/config/config-models.test.ts +18 -1
- package/src/core/config/config-models.ts +25 -3
- package/src/core/config/config-schema.test.ts +2 -0
- package/src/core/contracts/types.ts +2 -1
- package/src/core/platform/chat-form.test.ts +147 -0
- package/src/core/platform/chat-form.ts +402 -0
- package/src/core/platform/version.ts +1 -1
- package/src/core/runtime/execution-runtime.test.ts +73 -4
- package/src/core/runtime/execution-runtime.ts +18 -1
- package/src/routes/chat-mount.test.ts +9 -1
- package/src/routes/chat.test.ts +319 -7
- package/src/routes/chat.ts +179 -28
- package/web/console/assets/{Accounts-08VltF2i.js → Accounts-DuUY2UJU.js} +1 -1
- package/web/console/assets/{Approvals-CqgmsMau.js → Approvals-B11mo1dy.js} +1 -1
- package/web/console/assets/{Audit-bPlpSQt3.js → Audit-CQwJRIJT.js} +1 -1
- package/web/console/assets/{BrandLockup-DhX07g3G.js → BrandLockup-BIF-h1pi.js} +1 -1
- package/web/console/assets/{Channels-BZe0pLgx.js → Channels-BIploUT-.js} +1 -1
- package/web/console/assets/ChatEntries-Cpg_WV-o.js +7 -0
- package/web/console/assets/ChatEntries-DsYtcXN6.css +1 -0
- package/web/console/assets/Clients--D7NQJKk.css +1 -0
- package/web/console/assets/{Clients-BVVZfX3r.js → Clients-DS29eUi2.js} +2 -2
- package/web/console/assets/{Cost-DANcjr_p.js → Cost-BF52tfU2.js} +1 -1
- package/web/console/assets/{Credentials-D_8tP2Xa.js → Credentials-SwfmQAv6.js} +1 -1
- package/web/console/assets/{Diagnostics-Bw1WImFe.js → Diagnostics-CJfbI_8p.js} +1 -1
- package/web/console/assets/{Executors-fuieN2Sl.js → Executors-CzlZlznA.js} +1 -1
- package/web/console/assets/{Kb-BaMi_7xf.js → Kb-CVX22U4k.js} +1 -1
- package/web/console/assets/{Login-Cmz2ppY8.js → Login-PoUVsBI-.js} +1 -1
- package/web/console/assets/{Projects-D6xIgFB3.js → Projects-DYlbjLQy.js} +1 -1
- package/web/console/assets/{Routes-B90i3ZNa.js → Routes-DSEvGujN.js} +1 -1
- package/web/console/assets/{Runs-9qpwotOj.js → Runs-B-TsYZEt.js} +1 -1
- package/web/console/assets/Setup-D7nxgn-9.css +1 -0
- package/web/console/assets/Setup-xiPXit_b.js +1 -0
- package/web/console/assets/{Shell-Dm6eFcl1.js → Shell-DNiWZOYB.js} +1 -1
- package/web/console/assets/{StorageBuckets-DY8WuJlM.js → StorageBuckets-Bjsc3pLd.js} +1 -1
- package/web/console/assets/{SystemSettings-O_NMPzq_.js → SystemSettings-CcKF2lJ9.js} +1 -1
- package/web/console/assets/{SystemStatus-Cok3S7S3.js → SystemStatus-Oj1xjxJn.js} +1 -1
- package/web/console/assets/{Targets-YWBoxqvy.js → Targets-y1KllVXT.js} +1 -1
- package/web/console/assets/{Tools-BgXDw7Mg.js → Tools-DoEP_y9x.js} +1 -1
- package/web/console/assets/{index-S_J0I0Zh.js → index-CxPIS6G7.js} +2 -2
- package/web/console/assets/{request-FM608Kfz.js → request-CBLNpLth.js} +1 -1
- package/web/console/assets/{schema-DWnFqTkB.js → schema-DzwLpuOy.js} +1 -1
- package/web/console/index.html +1 -1
- package/web/widget/widget.js +493 -14
- package/web-admin/src/pages/ChatEntries.vue +46 -23
- package/web-admin/src/pages/Clients.vue +2 -2
- package/web-admin/src/pages/Setup.vue +12 -8
- package/web/console/assets/ChatEntries-BweMx_CU.css +0 -1
- package/web/console/assets/ChatEntries-Ca0lcGqn.js +0 -7
- package/web/console/assets/Clients-DcTYN-Js.css +0 -1
- package/web/console/assets/Setup-BIjCiA2i.js +0 -1
- package/web/console/assets/Setup-BuyKFofL.css +0 -1
|
@@ -290,8 +290,8 @@
|
|
|
290
290
|
|
|
291
291
|
1. 新建聊天入口。
|
|
292
292
|
2. 绑定一条触发路由。
|
|
293
|
-
3.
|
|
294
|
-
4. 设置 Origin
|
|
293
|
+
3. 设置标题、开场白、外观(包括是否加载即展开)。
|
|
294
|
+
4. 设置 Origin 白名单(一行一个 `scheme://host[:port]`,不带业务路径)。
|
|
295
295
|
5. 如需登录身份,配置票据签发方。
|
|
296
296
|
6. 如需上传附件,配置媒体存储和路由输入策略。
|
|
297
297
|
7. 复制嵌入代码。
|
|
@@ -300,7 +300,7 @@
|
|
|
300
300
|
|
|
301
301
|
- `entry_key`
|
|
302
302
|
- `<script>` 嵌入代码
|
|
303
|
-
-
|
|
303
|
+
- 匿名预览地址(不继承中枢后台登录态,也没有独立业务登录入口)
|
|
304
304
|
- 票据签发说明
|
|
305
305
|
- 评价记录
|
|
306
306
|
|
|
@@ -74,6 +74,15 @@
|
|
|
74
74
|
|
|
75
75
|
富内容渲染扩展单独使用 `rendererApiVersion` 演进。新增一种可选渲染类型、提高内部容错且旧页面仍能降级为代码块,属于兼容变更;修改既有类型的载荷语义、生命周期或安全边界,必须升级渲染器契约主版本,或使用新的类型名并保留旧类型过渡。核心组件不内置图表库,注册、挂载、销毁与失败回退规则见 [WIDGET_RENDERERS.md](WIDGET_RENDERERS.md)。
|
|
76
76
|
|
|
77
|
+
`bailing.contract.v2.14` 新增的 `bailing-form` v1 遵循上述兼容约定:
|
|
78
|
+
|
|
79
|
+
- 原有 `{message,...}` 聊天请求不变,`interaction_response` 只是 `POST /chat/:entry` 的可选替代输入;这个新增公开 Chat 契约不属于 `bailing.client-api.v1`,不改 Client API、Kernel Host API、ACC 或 SDK 版本。
|
|
80
|
+
- 官方 Widget 新增原生 `bailing-form` 类型;不识别它的旧/自建客户端仍可安全显示 fenced 代码块。只有已实现完整校验和回传的自建客户端才能声明 `client_capabilities.renderers:["bailing-form"]`。
|
|
81
|
+
- 渲染器 `mount` 上下文只新增可选 `message` / `respond`;JavaScript 对象的额外属性可被旧解构忽略,所以 `WIDGET_API` 和 `rendererApiVersion` 仍为 1。
|
|
82
|
+
- 表单提交创建同 thread 的新 job,不修改原 job 终态、`bailing.chat.stream.v1` 事件集或数据库结构;既有反向代理、SSE 客户端和升级流程无需新增等待状态。
|
|
83
|
+
|
|
84
|
+
官方 `widget.js` 与 Chat 端点由同一 Hub 制品提供,正常升级会同时获得渲染和回传能力。如果部署方单独缓存了旧 Widget,应在发布时清除该静态缓存,不要让自建客户端在旧 Hub 上预先宣告新能力。
|
|
85
|
+
|
|
77
86
|
> **会话是一等公民,历史 UX 由你定。** 每段对话在中枢都是可寻址的 thread(组件携带 `thread_id` 分区,「开启新对话」=换一个),全量留存在对话总账。中枢只给原语、不强加形态:默认气泡只提供「开启新对话」,**不内置历史会话列表**——因为客服问答气泡多半不需要,而真正想要历史的登录态工作台,通常更愿意用自己的设计在自己的 app 外壳里呈现。需要历史列表时,可基于 `/chat/:entry/thread`(按身份+`thread_id` 拉某条线程总账)的模式自行扩展你那侧的 UI;如需「列出某身份的全部会话」,这是一层薄读视图(数据已在总账),按需提 issue 即可加为可选端点。
|
|
78
87
|
|
|
79
88
|
## 七、部署方升级清单(贴在运维手册里)
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"enabled": { "type": "boolean" },
|
|
16
16
|
"allowed_origins": {
|
|
17
17
|
"type": "array",
|
|
18
|
-
"items": { "type": "string", "minLength": 1 },
|
|
18
|
+
"items": { "type": "string", "minLength": 1, "maxLength": 255, "pattern": "^[Hh][Tt][Tt][Pp][Ss]?://[^/?#@]+/?$" },
|
|
19
19
|
"uniqueItems": true
|
|
20
20
|
},
|
|
21
21
|
"rate_limit_per_min": { "type": "integer", "minimum": 1, "maximum": 600 },
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"type": "object",
|
|
29
29
|
"additionalProperties": false,
|
|
30
30
|
"properties": {
|
|
31
|
+
"default_open": { "type": "boolean", "default": false },
|
|
31
32
|
"width": { "type": "integer", "minimum": 280, "maximum": 720 },
|
|
32
33
|
"height": { "type": "integer", "minimum": 360, "maximum": 900 },
|
|
33
34
|
"title_align": { "type": "string", "enum": ["center", "left"] },
|
|
@@ -100,6 +100,8 @@ const englishCompanions = {
|
|
|
100
100
|
'docs/RELEASE_NOTES_v0.3.1.md': 'docs/RELEASE_NOTES_v0.3.1.en.md',
|
|
101
101
|
'docs/RELEASE_NOTES_v0.3.2.md': 'docs/RELEASE_NOTES_v0.3.2.en.md',
|
|
102
102
|
'docs/RELEASE_NOTES_v0.3.3.md': 'docs/RELEASE_NOTES_v0.3.3.en.md',
|
|
103
|
+
'docs/RELEASE_NOTES_v0.3.4.md': 'docs/RELEASE_NOTES_v0.3.4.en.md',
|
|
104
|
+
'docs/RELEASE_NOTES_v0.4.0.md': 'docs/RELEASE_NOTES_v0.4.0.en.md',
|
|
103
105
|
'docs/TOOLS_DESIGN.md': 'docs/TOOLS_DESIGN.en.md',
|
|
104
106
|
'docs/TOOLS_MODEL.md': 'docs/TOOLS_MODEL.en.md',
|
|
105
107
|
'docs/AI友好工具设计指南.md': 'docs/AI_FRIENDLY_TOOLS.en.md',
|
|
@@ -9,7 +9,7 @@ REGISTRY="${BAILING_IMAGE_REGISTRY:-$DEFAULT_REGISTRY}"
|
|
|
9
9
|
NAMESPACE="${BAILING_IMAGE_NAMESPACE:-$DEFAULT_NAMESPACE}"
|
|
10
10
|
PACKAGE_VERSION="$(sed -n 's/.*"version"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' package.json | head -1)"
|
|
11
11
|
TAG="${BAILING_IMAGE_TAG:-$PACKAGE_VERSION}"
|
|
12
|
-
[ -n "$TAG" ] || TAG="0.
|
|
12
|
+
[ -n "$TAG" ] || TAG="0.4.0"
|
|
13
13
|
MYSQL_TAG="${BAILING_MYSQL_IMAGE_TAG:-8.4}"
|
|
14
14
|
MYSQL_IMAGE="${BAILING_MYSQL_IMAGE:-$REGISTRY/$NAMESPACE/bailing-mysql:$MYSQL_TAG}"
|
|
15
15
|
PLATFORM="${BAILING_IMAGE_PLATFORM:-linux/amd64}"
|
|
@@ -38,8 +38,8 @@ function updateJson(root, relativePath, update) {
|
|
|
38
38
|
test('current release surface is internally consistent', () => {
|
|
39
39
|
const result = checkReleaseConsistency({ root: repoRoot });
|
|
40
40
|
assert.deepEqual(result.findings, []);
|
|
41
|
-
assert.equal(result.version, '0.
|
|
42
|
-
assert.equal(result.stableVersion, '0.
|
|
41
|
+
assert.equal(result.version, '0.4.0');
|
|
42
|
+
assert.equal(result.stableVersion, '0.4.0');
|
|
43
43
|
assert.equal(result.publishTag, 'latest');
|
|
44
44
|
});
|
|
45
45
|
|
|
@@ -51,13 +51,13 @@ for (const [label, tag] of [
|
|
|
51
51
|
const root = createFixture();
|
|
52
52
|
try {
|
|
53
53
|
updateJson(root, 'package.json', (pkg) => {
|
|
54
|
-
pkg.version = '0.
|
|
54
|
+
pkg.version = '0.4.0-rc.1';
|
|
55
55
|
if (tag === undefined) delete pkg.publishConfig;
|
|
56
56
|
else pkg.publishConfig = { tag };
|
|
57
57
|
});
|
|
58
58
|
updateJson(root, 'package-lock.json', (lock) => {
|
|
59
|
-
lock.version = '0.
|
|
60
|
-
lock.packages[''].version = '0.
|
|
59
|
+
lock.version = '0.4.0-rc.1';
|
|
60
|
+
lock.packages[''].version = '0.4.0-rc.1';
|
|
61
61
|
});
|
|
62
62
|
|
|
63
63
|
const result = checkReleaseConsistency({ root });
|
package/scripts/e2e-console.mjs
CHANGED
|
@@ -60,6 +60,16 @@ const fixtures = {
|
|
|
60
60
|
}],
|
|
61
61
|
clients: [{ app_id: 'demo-app', name: 'Demo 业务系统', token: '****oken', allowed_routes: ['demo_support'], allowed_channels: [], rate_limit_per_min: 60, enabled: true }],
|
|
62
62
|
routes: [{ route_key: 'demo_support', name: 'Demo 售后助手', target: 'demo-agent', enabled: true, tools: { sources: [{ provider: 'demo-business', allow: ['demo.*'] }], max_calls: 5 } }],
|
|
63
|
+
demoStatus: { available: true, imported: true, empty: false },
|
|
64
|
+
chatEntries: [{
|
|
65
|
+
entry_key: 'demo-chat',
|
|
66
|
+
name: 'Demo 在线助手',
|
|
67
|
+
route_key: 'demo_support',
|
|
68
|
+
allowed_origins: ['https://example.com'],
|
|
69
|
+
ticket_client: 'demo-app',
|
|
70
|
+
rate_limit_per_min: 20,
|
|
71
|
+
enabled: true,
|
|
72
|
+
}],
|
|
63
73
|
runs: [{ job_id: '00000000-0000-4000-8000-000000000001', request_id: 'demo-e2e', status: 'done', route: 'demo_support', created_at: new Date().toISOString(), updated_at: new Date().toISOString() }],
|
|
64
74
|
threads: [{
|
|
65
75
|
thread_id: 1,
|
|
@@ -74,6 +84,8 @@ const fixtures = {
|
|
|
74
84
|
}],
|
|
75
85
|
};
|
|
76
86
|
|
|
87
|
+
let smokeRequests = 0;
|
|
88
|
+
|
|
77
89
|
function tracePayload() {
|
|
78
90
|
return {
|
|
79
91
|
job: { ...fixtures.runs[0], target: 'demo-agent', usage: { duration_ms: 1200, tokens: 0 }, dispatch: { tools: { sources: [{ provider: 'demo-business', allow: ['demo.*'] }] } } },
|
|
@@ -93,8 +105,9 @@ async function mockApi(context) {
|
|
|
93
105
|
await context.route('**/health', (route) => route.fulfill({ json: { status: 'ok', paused: false, queue: { running: 0, waiting: 0 }, backend: 'mysql', configBackend: true } }));
|
|
94
106
|
await context.route('**/admin/api/me', (route) => route.fulfill({ json: { username: 'admin', role: 'admin', perms: ['*'] } }));
|
|
95
107
|
await context.route('**/admin/api/status', (route) => route.fulfill({ json: { executors: [{ executor_id: 'demo-exec', online: true, targets: ['demo-agent'] }] } }));
|
|
96
|
-
await context.route('**/admin/api/smoke', (route) =>
|
|
97
|
-
|
|
108
|
+
await context.route('**/admin/api/smoke', (route) => {
|
|
109
|
+
smokeRequests += 1;
|
|
110
|
+
return route.fulfill({ json: {
|
|
98
111
|
hub: 'http://127.0.0.1',
|
|
99
112
|
pass: 3,
|
|
100
113
|
fail: 0,
|
|
@@ -105,16 +118,17 @@ async function mockApi(context) {
|
|
|
105
118
|
{ name: 'trace', status: 'pass', detail: 'trace ok' },
|
|
106
119
|
],
|
|
107
120
|
run: { route: 'demo_support', request_id: 'demo-e2e', job_id: fixtures.runs[0].job_id, status: 'done' },
|
|
108
|
-
}
|
|
109
|
-
})
|
|
121
|
+
} });
|
|
122
|
+
});
|
|
110
123
|
await context.route('**/admin/api/config-schemas/*', (route) => route.fulfill({ json: { required: [], properties: {} } }));
|
|
111
124
|
await context.route('**/admin/api/tool-providers/*/tools', (route) => route.fulfill({ json: { tools: [{ name: 'list_demo_orders', scope: 'demo.order.read' }] } }));
|
|
112
125
|
await context.route('**/admin/api/runs/*/trace', (route) => route.fulfill({ json: tracePayload() }));
|
|
113
126
|
await context.route('**/admin/api/**', (route) => {
|
|
114
127
|
const url = new URL(route.request().url());
|
|
115
128
|
if (url.pathname === '/admin/api/me') return route.fulfill({ json: { username: 'admin', role: 'admin', perms: ['*'] } });
|
|
116
|
-
if (url.pathname === '/admin/api/smoke')
|
|
117
|
-
|
|
129
|
+
if (url.pathname === '/admin/api/smoke') {
|
|
130
|
+
smokeRequests += 1;
|
|
131
|
+
return route.fulfill({ json: {
|
|
118
132
|
hub: 'http://127.0.0.1',
|
|
119
133
|
pass: 3,
|
|
120
134
|
fail: 0,
|
|
@@ -125,8 +139,8 @@ async function mockApi(context) {
|
|
|
125
139
|
{ name: 'trace', status: 'pass', detail: 'trace ok' },
|
|
126
140
|
],
|
|
127
141
|
run: { route: 'demo_support', request_id: 'demo-e2e', job_id: fixtures.runs[0].job_id, status: 'done' },
|
|
128
|
-
}
|
|
129
|
-
}
|
|
142
|
+
} });
|
|
143
|
+
}
|
|
130
144
|
if (url.pathname === '/admin/api/credentials') return route.fulfill({ json: fixtures.credentials });
|
|
131
145
|
if (url.pathname === '/admin/api/targets') return route.fulfill({ json: fixtures.targets });
|
|
132
146
|
if (url.pathname === '/admin/api/tool-providers') return route.fulfill({ json: fixtures.providers });
|
|
@@ -146,7 +160,8 @@ async function mockApi(context) {
|
|
|
146
160
|
});
|
|
147
161
|
if (url.pathname === '/admin/api/executors') return route.fulfill({ json: [{ executor_id: 'demo-exec', online: true, targets: ['demo-agent'] }] });
|
|
148
162
|
if (url.pathname === '/admin/api/projects') return route.fulfill({ json: [] });
|
|
149
|
-
if (url.pathname === '/admin/api/
|
|
163
|
+
if (url.pathname === '/admin/api/demo-dataset/status') return route.fulfill({ json: fixtures.demoStatus });
|
|
164
|
+
if (url.pathname === '/admin/api/chat-entries') return route.fulfill({ json: fixtures.chatEntries });
|
|
150
165
|
if (url.pathname === '/admin/api/channels') return route.fulfill({ json: [] });
|
|
151
166
|
if (url.pathname === '/admin/api/kb') return route.fulfill({ json: [] });
|
|
152
167
|
return route.fulfill({ status: 404, json: { error: `unmocked ${url.pathname}` } });
|
|
@@ -174,9 +189,22 @@ try {
|
|
|
174
189
|
await expectVisible(page, '配置完成度');
|
|
175
190
|
await expectVisible(page, '模型凭证');
|
|
176
191
|
await expectVisible(page, '触发路由');
|
|
177
|
-
await page
|
|
192
|
+
await expectVisible(page, '演示数据已导入,运行演示主体 Smoke');
|
|
193
|
+
if (smokeRequests !== 0) throw new Error('导入演示数据后不应自动运行 Smoke');
|
|
194
|
+
const demoSmokeButton = page.getByRole('button', { name: '运行演示主体 Smoke' }).first();
|
|
195
|
+
if (!(await demoSmokeButton.getAttribute('class'))?.includes('el-button--primary')) {
|
|
196
|
+
throw new Error('演示数据已导入时,运行演示主体 Smoke 应是主 CTA');
|
|
197
|
+
}
|
|
198
|
+
await demoSmokeButton.click();
|
|
199
|
+
if (smokeRequests !== 1) throw new Error('Smoke 应只在用户点击后运行一次');
|
|
178
200
|
await expectVisible(page, '通过 3');
|
|
179
201
|
|
|
202
|
+
await page.getByRole('menuitem', { name: '聊天入口' }).click();
|
|
203
|
+
await expectVisible(page, '“匿名预览”不会继承中枢后台登录状态');
|
|
204
|
+
await expectVisible(page, '包括只读查询和写操作');
|
|
205
|
+
await expectVisible(page, '支持业务身份票据:demo-app');
|
|
206
|
+
await expectVisible(page, '匿名预览');
|
|
207
|
+
|
|
180
208
|
await page.getByRole('menuitem', { name: '触发路由' }).click();
|
|
181
209
|
await expectVisible(page, 'Demo 售后助手');
|
|
182
210
|
|
package/scripts/install.sh
CHANGED
|
@@ -275,7 +275,7 @@ write_env() {
|
|
|
275
275
|
TOOL_SECRET="${DEMO_TOOL_SECRET:-$(secret)}"
|
|
276
276
|
CLIENT_TOKEN="${DEMO_CLIENT_TOKEN:-$(secret)}"
|
|
277
277
|
IMAGE_TAG="${BAILING_IMAGE_TAG:-$(sed -n 's/.*"version"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' "$APP_DIR/package.json" | head -1)}"
|
|
278
|
-
[ -n "$IMAGE_TAG" ] || IMAGE_TAG="0.
|
|
278
|
+
[ -n "$IMAGE_TAG" ] || IMAGE_TAG="0.4.0"
|
|
279
279
|
IMAGE_REGISTRY="${BAILING_IMAGE_REGISTRY:-$DEFAULT_IMAGE_REGISTRY}"
|
|
280
280
|
IMAGE_NAMESPACE="${BAILING_IMAGE_NAMESPACE:-$DEFAULT_IMAGE_NAMESPACE}"
|
|
281
281
|
cat > "$ENV_FILE" <<EOF
|
|
@@ -9,7 +9,7 @@ REGISTRY="${BAILING_IMAGE_REGISTRY:-$DEFAULT_REGISTRY}"
|
|
|
9
9
|
NAMESPACE="${BAILING_IMAGE_NAMESPACE:-$DEFAULT_NAMESPACE}"
|
|
10
10
|
PACKAGE_VERSION="$(sed -n 's/.*"version"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' package.json | head -1)"
|
|
11
11
|
TAG="${BAILING_IMAGE_TAG:-$PACKAGE_VERSION}"
|
|
12
|
-
[ -n "$TAG" ] || TAG="0.
|
|
12
|
+
[ -n "$TAG" ] || TAG="0.4.0"
|
|
13
13
|
NODE_IMAGE="${BAILING_NODE_IMAGE:-node:22-bookworm-slim}"
|
|
14
14
|
PLATFORM="${BAILING_IMAGE_PLATFORM:-linux/amd64}"
|
|
15
15
|
PUSH="${BAILING_PUSH_IMAGES:-0}"
|
|
@@ -31,6 +31,8 @@ const requiredRepoFiles = [
|
|
|
31
31
|
'docs/RELEASE_NOTES_v0.3.0.md',
|
|
32
32
|
'docs/RELEASE_NOTES_v0.3.2.md',
|
|
33
33
|
'docs/RELEASE_NOTES_v0.3.3.md',
|
|
34
|
+
'docs/RELEASE_NOTES_v0.3.4.md',
|
|
35
|
+
'docs/RELEASE_NOTES_v0.4.0.md',
|
|
34
36
|
'docs/CHANGELOG.md',
|
|
35
37
|
'docs/CLIENT_API.md',
|
|
36
38
|
'config.example.json',
|
|
@@ -123,6 +123,8 @@ const requiredFiles = [
|
|
|
123
123
|
'docs/RELEASE_NOTES_v0.3.0.md',
|
|
124
124
|
'docs/RELEASE_NOTES_v0.3.2.md',
|
|
125
125
|
'docs/RELEASE_NOTES_v0.3.3.md',
|
|
126
|
+
'docs/RELEASE_NOTES_v0.3.4.md',
|
|
127
|
+
'docs/RELEASE_NOTES_v0.4.0.md',
|
|
126
128
|
'docs/CHANGELOG.md',
|
|
127
129
|
];
|
|
128
130
|
for (const file of requiredFiles) requireFile(file);
|
|
@@ -10,15 +10,73 @@ const validPayload = {
|
|
|
10
10
|
kind: 'bar',
|
|
11
11
|
data: [{ label: '已完成', value: 12 }],
|
|
12
12
|
};
|
|
13
|
+
const formPayload = {
|
|
14
|
+
version: 1,
|
|
15
|
+
form_id: 'refund_info',
|
|
16
|
+
title: '请补充退款信息',
|
|
17
|
+
description: '这些内容会作为下一轮用户消息提交。',
|
|
18
|
+
schema: {
|
|
19
|
+
customer: { type: 'text', label: '联系人', required: true, minLength: 2, maxLength: 20, placeholder: '请输入姓名' },
|
|
20
|
+
reason: { type: 'textarea', label: '退款原因', required: true, maxLength: 200 },
|
|
21
|
+
amount: { type: 'number', label: '退款金额', required: true, min: 0, max: 1000 },
|
|
22
|
+
apply_date: { type: 'date', label: '申请日期', required: true, min: '2026-01-01', max: '2026-12-31' },
|
|
23
|
+
confirmed: { type: 'boolean', label: '已确认信息', required: true },
|
|
24
|
+
method: { type: 'single_select', label: '退款方式', required: true, options: [{ label: '原路退回', value: 'original' }, { label: '余额', value: 'balance' }] },
|
|
25
|
+
tags: { type: 'multi_select', label: '需求标记', required: true, options: [{ label: '加急', value: 'urgent' }, { label: '回访', value: 'callback' }] },
|
|
26
|
+
note: { type: 'text', label: '备注 <img src=x onerror="window.__formInjected=1">', maxLength: 80 },
|
|
27
|
+
},
|
|
28
|
+
submit_label: '提交信息',
|
|
29
|
+
};
|
|
30
|
+
const cancelFormPayload = {
|
|
31
|
+
version: 1,
|
|
32
|
+
form_id: 'cancel_form',
|
|
33
|
+
title: '可取消的表单',
|
|
34
|
+
schema: { note: { type: 'text', label: '备注', maxLength: 40 } },
|
|
35
|
+
cancel_label: '暂不填写',
|
|
36
|
+
};
|
|
37
|
+
const invalidFormPayload = {
|
|
38
|
+
version: 1,
|
|
39
|
+
form_id: 'unsafe_remote',
|
|
40
|
+
title: '不应渲染',
|
|
41
|
+
schema: { source: { type: 'remote_select', label: '远程数据', endpoint: 'https://evil.example/data' } },
|
|
42
|
+
};
|
|
43
|
+
const strictInvalidPayloads = [
|
|
44
|
+
{ ...cancelFormPayload, form_id: 'extra_top', unexpected: true },
|
|
45
|
+
{ version: 1, form_id: 'required_string', title: '非法 required', schema: { value: { type: 'text', label: '值', required: 'true' } } },
|
|
46
|
+
{ version: 1, form_id: 'text_over_cap', title: '超限文本', schema: { value: { type: 'text', label: '值', maxLength: 501 } } },
|
|
47
|
+
{ version: 1, form_id: 'number_string', title: '非法数字边界', schema: { value: { type: 'number', label: '值', min: '0' } } },
|
|
48
|
+
{ version: 1, form_id: 'bad_date', title: '非法日期边界', schema: { value: { type: 'date', label: '日期', min: '2026-02-30' } } },
|
|
49
|
+
{ version: 1, form_id: 'sensitive_copy', title: '补充信息', description: '请输入 API Key', schema: { value: { type: 'text', label: '值' } } },
|
|
50
|
+
{ version: 1, form_id: 'option_extra', title: '非法选项', schema: { value: { type: 'single_select', label: '值', options: [{ label: 'A', value: 'a', endpoint: 'https://evil.example' }] } } },
|
|
51
|
+
{ version: 1, form_id: 'control_copy', title: '含\n换行', schema: { value: { type: 'text', label: '值' } } },
|
|
52
|
+
];
|
|
53
|
+
const formBlock = (payload) => `\`\`\`bailing-form\n${JSON.stringify(payload)}\n\`\`\``;
|
|
13
54
|
const history = [
|
|
14
55
|
{ r: 'a', t: `\`\`\`bailing-chart\n${JSON.stringify(validPayload)}\n\`\`\`` },
|
|
15
56
|
{ r: 'a', t: '```unknown-chart\n{"value":1}\n```' },
|
|
16
57
|
{ r: 'a', t: '```bailing-chart\n{"broken":\n```' },
|
|
17
58
|
{ r: 'a', t: '```bailing-chart\n"scalar"\n```' },
|
|
59
|
+
{ r: 'a', t: formBlock(formPayload), j: 'source-form-1' },
|
|
60
|
+
{ r: 'a', t: formBlock(cancelFormPayload), j: 'source-form-2' },
|
|
61
|
+
{ r: 'a', t: formBlock(invalidFormPayload), j: 'source-form-invalid' },
|
|
62
|
+
...strictInvalidPayloads.map((payload, index) => ({ r: 'a', t: formBlock(payload), j: `source-form-strict-invalid-${index}` })),
|
|
63
|
+
{ r: 'a', t: formBlock(cancelFormPayload) },
|
|
18
64
|
];
|
|
19
65
|
|
|
20
|
-
|
|
21
|
-
const
|
|
66
|
+
const submissions = [];
|
|
67
|
+
const submissionWaiters = [];
|
|
68
|
+
function recordSubmission(body) {
|
|
69
|
+
const waiter = submissionWaiters.shift();
|
|
70
|
+
if (waiter) waiter(body);
|
|
71
|
+
else submissions.push(body);
|
|
72
|
+
}
|
|
73
|
+
function nextSubmission() {
|
|
74
|
+
if (submissions.length) return Promise.resolve(submissions.shift());
|
|
75
|
+
return new Promise((resolve) => { submissionWaiters.push(resolve); });
|
|
76
|
+
}
|
|
77
|
+
let serverMessages = [];
|
|
78
|
+
let cancelAttempts = 0;
|
|
79
|
+
let jobSeq = 0;
|
|
22
80
|
|
|
23
81
|
const server = createServer((req, res) => {
|
|
24
82
|
if (req.url === '/widget.js') {
|
|
@@ -28,12 +86,35 @@ const server = createServer((req, res) => {
|
|
|
28
86
|
}
|
|
29
87
|
if (req.url === '/chat/pub_test/config') {
|
|
30
88
|
res.writeHead(200, { 'content-type': 'application/json; charset=utf-8' });
|
|
31
|
-
res.end(JSON.stringify({ enabled: true, title: 'Renderer Test', greeting: '', powered_by_visible: false }));
|
|
89
|
+
res.end(JSON.stringify({ enabled: true, title: 'Renderer Test', greeting: '', default_open: false, powered_by_visible: false }));
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (req.url === '/chat/pub_default_open/config') {
|
|
93
|
+
res.writeHead(200, { 'content-type': 'application/json; charset=utf-8' });
|
|
94
|
+
res.end(JSON.stringify({ enabled: true, title: 'Default Open Test', greeting: '', default_open: true, powered_by_visible: false }));
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (req.url === '/chat/pub_default_closed/config') {
|
|
98
|
+
res.writeHead(200, { 'content-type': 'application/json; charset=utf-8' });
|
|
99
|
+
res.end(JSON.stringify({ enabled: true, title: 'Default Closed Test', greeting: '', default_open: false, powered_by_visible: false }));
|
|
32
100
|
return;
|
|
33
101
|
}
|
|
34
102
|
if (req.url?.startsWith('/chat/pub_test/thread')) {
|
|
35
103
|
res.writeHead(200, { 'content-type': 'application/json; charset=utf-8' });
|
|
36
|
-
res.end(JSON.stringify({ messages:
|
|
104
|
+
res.end(JSON.stringify({ messages: serverMessages }));
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (req.url?.startsWith('/chat/pub_test/events/job-refund_info-')) {
|
|
108
|
+
const jobId = req.url.split('/events/')[1].split('?')[0];
|
|
109
|
+
res.writeHead(200, {
|
|
110
|
+
'content-type': 'text/event-stream; charset=utf-8',
|
|
111
|
+
'cache-control': 'no-cache',
|
|
112
|
+
connection: 'keep-alive',
|
|
113
|
+
});
|
|
114
|
+
setTimeout(() => {
|
|
115
|
+
res.write(`event: done\ndata: ${JSON.stringify({ done: true, job_id: jobId, reply: 'ok:refund_info' })}\n\n`);
|
|
116
|
+
res.end();
|
|
117
|
+
}, 500);
|
|
37
118
|
return;
|
|
38
119
|
}
|
|
39
120
|
if (req.url === '/chat/pub_test' && req.method === 'POST') {
|
|
@@ -41,13 +122,28 @@ const server = createServer((req, res) => {
|
|
|
41
122
|
req.on('data', (chunk) => { chunks.push(chunk); });
|
|
42
123
|
req.on('end', () => {
|
|
43
124
|
const body = JSON.parse(Buffer.concat(chunks).toString('utf8'));
|
|
44
|
-
|
|
125
|
+
recordSubmission(body);
|
|
126
|
+
if (body.interaction_response?.form_id === 'cancel_form' && cancelAttempts++ === 0) {
|
|
127
|
+
res.writeHead(503, { 'content-type': 'application/json; charset=utf-8' });
|
|
128
|
+
res.end(JSON.stringify({ error: '模拟提交失败' }));
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
45
131
|
res.writeHead(200, { 'content-type': 'application/json; charset=utf-8' });
|
|
46
|
-
|
|
132
|
+
const suffix = body.interaction_response?.form_id || 'message';
|
|
133
|
+
const jobId = `job-${suffix}-${++jobSeq}`;
|
|
134
|
+
res.end(JSON.stringify({ done: suffix !== 'refund_info', job_id: jobId, visitor_id: 'visitor-12345678', ...(suffix === 'refund_info' ? {} : { reply: `ok:${suffix}` }) }));
|
|
47
135
|
});
|
|
48
136
|
return;
|
|
49
137
|
}
|
|
50
138
|
res.writeHead(200, { 'content-type': 'text/html; charset=utf-8' });
|
|
139
|
+
if (req.url === '/default-open.html') {
|
|
140
|
+
res.end('<!doctype html><html><body><script src="/widget.js" data-entry="pub_default_open"></script></body></html>');
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if (req.url === '/default-closed.html') {
|
|
144
|
+
res.end('<!doctype html><html><body><script src="/widget.js" data-entry="pub_default_closed"></script></body></html>');
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
51
147
|
res.end('<!doctype html><html><body><script src="/widget.js" data-entry="pub_test" data-open="1"></script></body></html>');
|
|
52
148
|
});
|
|
53
149
|
|
|
@@ -72,6 +168,18 @@ const executablePath = existsSync(bundledExecutable)
|
|
|
72
168
|
: systemExecutables.find((candidate) => existsSync(candidate));
|
|
73
169
|
const browser = await chromium.launch({ headless: true, ...(executablePath ? { executablePath } : {}) });
|
|
74
170
|
try {
|
|
171
|
+
const defaultOpenPage = await browser.newPage();
|
|
172
|
+
await defaultOpenPage.goto(`http://127.0.0.1:${address.port}/default-open.html`);
|
|
173
|
+
await defaultOpenPage.locator('.panel').waitFor();
|
|
174
|
+
assert.equal(await defaultOpenPage.locator('.panel').evaluate((panel) => panel.classList.contains('open')), true);
|
|
175
|
+
await defaultOpenPage.close();
|
|
176
|
+
|
|
177
|
+
const defaultClosedPage = await browser.newPage();
|
|
178
|
+
await defaultClosedPage.goto(`http://127.0.0.1:${address.port}/default-closed.html`);
|
|
179
|
+
await defaultClosedPage.locator('.panel').waitFor({ state: 'attached' });
|
|
180
|
+
assert.equal(await defaultClosedPage.locator('.panel').evaluate((panel) => panel.classList.contains('open')), false);
|
|
181
|
+
await defaultClosedPage.close();
|
|
182
|
+
|
|
75
183
|
const page = await browser.newPage();
|
|
76
184
|
await page.addInitScript(({ seededHistory }) => {
|
|
77
185
|
window.__rendererMounts = 0;
|
|
@@ -82,10 +190,11 @@ try {
|
|
|
82
190
|
label: 'Test chart',
|
|
83
191
|
contentType: 'application/json',
|
|
84
192
|
mount(context) {
|
|
85
|
-
const { container, payload, signal, theme } = context;
|
|
193
|
+
const { container, payload, signal, theme, message, respond } = context;
|
|
86
194
|
window.__rendererMounts += 1;
|
|
87
195
|
window.__rendererContextKeys = Object.keys(context).sort();
|
|
88
|
-
window.__rendererContextFrozen = Object.isFrozen(context) && Object.isFrozen(theme);
|
|
196
|
+
window.__rendererContextFrozen = Object.isFrozen(context) && Object.isFrozen(theme) && Object.isFrozen(message) && Object.isFrozen(message.responses);
|
|
197
|
+
window.__rendererHasRespond = typeof respond === 'function';
|
|
89
198
|
container.textContent = `${payload.kind}:${payload.data[0].value}`;
|
|
90
199
|
const onAbort = () => { container.dataset.aborted = '1'; };
|
|
91
200
|
signal.addEventListener('abort', onAbort, { once: true });
|
|
@@ -96,11 +205,15 @@ try {
|
|
|
96
205
|
},
|
|
97
206
|
}],
|
|
98
207
|
};
|
|
99
|
-
|
|
208
|
+
if (!sessionStorage.getItem('renderer_test_seeded')) {
|
|
209
|
+
localStorage.setItem('bailing_chat_pub_test', JSON.stringify(seededHistory));
|
|
210
|
+
sessionStorage.setItem('renderer_test_seeded', '1');
|
|
211
|
+
}
|
|
100
212
|
}, { seededHistory: history });
|
|
101
213
|
|
|
102
214
|
await page.goto(`http://127.0.0.1:${address.port}/`, { waitUntil: 'networkidle' });
|
|
103
215
|
await page.waitForFunction(() => window.__rendererMounts - window.__rendererDestroys === 1);
|
|
216
|
+
await page.locator('.rich-renderer[data-renderer="bailing-form"][data-form-id="refund_info"] .bailing-form').waitFor();
|
|
104
217
|
|
|
105
218
|
const result = await page.evaluate(() => {
|
|
106
219
|
const host = Array.from(document.body.children).find((node) => node.shadowRoot);
|
|
@@ -118,23 +231,40 @@ try {
|
|
|
118
231
|
destroys: window.__rendererDestroys,
|
|
119
232
|
contextKeys: window.__rendererContextKeys,
|
|
120
233
|
contextFrozen: window.__rendererContextFrozen,
|
|
234
|
+
hasRespond: window.__rendererHasRespond,
|
|
121
235
|
richMessageCount: root?.querySelectorAll('.m.rich').length || 0,
|
|
236
|
+
formCount: root?.querySelectorAll('.rich-renderer[data-renderer="bailing-form"] .bailing-form').length || 0,
|
|
237
|
+
formImageCount: root?.querySelectorAll('.rich-renderer[data-form-id="refund_info"] img').length || 0,
|
|
238
|
+
formInjected: window.__formInjected || 0,
|
|
239
|
+
dateMin: root?.querySelector('[data-form-id="refund_info"] input[name="apply_date"]')?.min || '',
|
|
240
|
+
dateMax: root?.querySelector('[data-form-id="refund_info"] input[name="apply_date"]')?.max || '',
|
|
241
|
+
booleanRequired: root?.querySelector('[data-form-id="refund_info"] input[name="confirmed"]')?.required,
|
|
122
242
|
panelWidth: root?.querySelector('.panel')?.getBoundingClientRect().width || 0,
|
|
123
243
|
fallbacks,
|
|
244
|
+
bailingFormFallbackCount: fallbacks.filter((item) => item.language === 'bailing-form').length,
|
|
124
245
|
};
|
|
125
246
|
});
|
|
126
247
|
|
|
127
248
|
assert.equal(result.rendererApiVersion, '1');
|
|
128
|
-
assert.equal(result.activeCount,
|
|
249
|
+
assert.equal(result.activeCount, 3);
|
|
129
250
|
assert.equal(result.activeText, 'bar:12');
|
|
130
251
|
assert.equal(result.mounts - result.destroys, 1);
|
|
131
|
-
assert.deepEqual(result.contextKeys, ['container', 'payload', 'signal', 'source', 'theme', 'type', 'version']);
|
|
252
|
+
assert.deepEqual(result.contextKeys, ['container', 'message', 'payload', 'respond', 'signal', 'source', 'theme', 'type', 'version']);
|
|
132
253
|
assert.equal(result.contextFrozen, true);
|
|
133
|
-
assert.equal(result.
|
|
254
|
+
assert.equal(result.hasRespond, true);
|
|
255
|
+
assert.ok(result.richMessageCount >= 3);
|
|
256
|
+
assert.equal(result.formCount, 2);
|
|
257
|
+
assert.equal(result.formImageCount, 0);
|
|
258
|
+
assert.equal(result.formInjected, 0);
|
|
259
|
+
assert.equal(result.dateMin, '2026-01-01');
|
|
260
|
+
assert.equal(result.dateMax, '2026-12-31');
|
|
261
|
+
assert.equal(result.booleanRequired, false, 'required boolean must still allow submitting false');
|
|
134
262
|
assert.ok(result.panelWidth >= 640, `expected rich content to widen the panel, got ${result.panelWidth}`);
|
|
135
263
|
assert.ok(result.fallbacks.some((item) => item.language === 'unknown-chart' && item.text.includes('{"value":1}')));
|
|
136
264
|
assert.ok(result.fallbacks.some((item) => item.language === 'bailing-chart' && item.text.includes('{"broken":')));
|
|
137
265
|
assert.ok(result.fallbacks.some((item) => item.language === 'bailing-chart' && item.text === '"scalar"'));
|
|
266
|
+
assert.ok(result.fallbacks.some((item) => item.language === 'bailing-form' && item.text.includes('remote_select')));
|
|
267
|
+
assert.equal(result.bailingFormFallbackCount, 2 + strictInvalidPayloads.length, 'invalid and source-less forms must stay inert code blocks');
|
|
138
268
|
|
|
139
269
|
await page.locator('.maximize').click();
|
|
140
270
|
const maximized = await page.evaluate(() => {
|
|
@@ -173,15 +303,89 @@ try {
|
|
|
173
303
|
await page.locator('.bubble').click();
|
|
174
304
|
assert.equal(await page.locator('.panel').evaluate((panel) => panel.classList.contains('open')), true);
|
|
175
305
|
|
|
176
|
-
|
|
306
|
+
const refundForm = page.locator('.rich-renderer[data-form-id="refund_info"]');
|
|
307
|
+
await refundForm.locator('input[name="customer"]').fill('张三');
|
|
308
|
+
await refundForm.locator('textarea[name="reason"]').fill('商品与描述不符');
|
|
309
|
+
await refundForm.locator('input[name="amount"]').fill('88.5');
|
|
310
|
+
await refundForm.locator('input[name="apply_date"]').fill('2026-08-24');
|
|
311
|
+
// required boolean 是 yes/no 数据而非强制同意;故意保持 false 也应可提交。
|
|
312
|
+
await refundForm.locator('select[name="method"]').selectOption('original');
|
|
313
|
+
await refundForm.locator('input[name="tags"][value="urgent"]').check();
|
|
314
|
+
await refundForm.locator('button.primary').click();
|
|
315
|
+
const formSubmitted = await nextSubmission();
|
|
316
|
+
assert.equal(formSubmitted.message, undefined);
|
|
317
|
+
assert.deepEqual(formSubmitted.client_capabilities, { renderers: ['bailing-form', 'bailing-chart'] });
|
|
318
|
+
assert.deepEqual({ ...formSubmitted.interaction_response, submission_id: '<dynamic>' }, {
|
|
319
|
+
type: 'bailing-form',
|
|
320
|
+
version: 1,
|
|
321
|
+
source_job_id: 'source-form-1',
|
|
322
|
+
form_id: 'refund_info',
|
|
323
|
+
submission_id: '<dynamic>',
|
|
324
|
+
action: 'submit',
|
|
325
|
+
values: {
|
|
326
|
+
customer: '张三',
|
|
327
|
+
reason: '商品与描述不符',
|
|
328
|
+
amount: 88.5,
|
|
329
|
+
apply_date: '2026-08-24',
|
|
330
|
+
confirmed: false,
|
|
331
|
+
method: 'original',
|
|
332
|
+
tags: ['urgent'],
|
|
333
|
+
},
|
|
334
|
+
});
|
|
335
|
+
assert.match(formSubmitted.interaction_response.submission_id, /^[a-zA-Z0-9_-]{8,64}$/);
|
|
336
|
+
await refundForm.locator('.bf-status.receipt').waitFor();
|
|
337
|
+
const acknowledgedBeforeDone = await page.evaluate(() => {
|
|
338
|
+
const host = Array.from(document.body.children).find((node) => node.shadowRoot);
|
|
339
|
+
const root = host?.shadowRoot;
|
|
340
|
+
return {
|
|
341
|
+
sendDisabled: root?.querySelector('.send')?.disabled,
|
|
342
|
+
hasFinalReply: Array.from(root?.querySelectorAll('.m.a') || []).some((node) => node.textContent?.includes('ok:refund_info')),
|
|
343
|
+
};
|
|
344
|
+
});
|
|
345
|
+
assert.equal(acknowledgedBeforeDone.sendDisabled, true, 'global send stays pending while the next answer streams');
|
|
346
|
+
assert.equal(acknowledgedBeforeDone.hasFinalReply, false, 'form receipt must not wait for the delayed SSE answer');
|
|
347
|
+
await page.waitForFunction(() => {
|
|
348
|
+
const host = Array.from(document.body.children).find((node) => node.shadowRoot);
|
|
349
|
+
return host?.shadowRoot?.querySelector('.send')?.disabled === false;
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
const cancelForm = page.locator('.rich-renderer[data-form-id="cancel_form"]');
|
|
353
|
+
await cancelForm.getByRole('button', { name: '暂不填写' }).click();
|
|
354
|
+
const rejectedCancel = await nextSubmission();
|
|
355
|
+
assert.equal(rejectedCancel.interaction_response.action, 'cancel');
|
|
356
|
+
assert.deepEqual(rejectedCancel.interaction_response.values, {});
|
|
357
|
+
await cancelForm.locator('.bf-status.error').waitFor();
|
|
358
|
+
assert.equal(await cancelForm.getByRole('button', { name: '暂不填写' }).isEnabled(), true, 'HTTP rejection must re-enable form controls');
|
|
359
|
+
await cancelForm.getByRole('button', { name: '暂不填写' }).click();
|
|
360
|
+
const acceptedCancel = await nextSubmission();
|
|
361
|
+
assert.equal(acceptedCancel.interaction_response.submission_id, rejectedCancel.interaction_response.submission_id, 'retry keeps one idempotency key');
|
|
362
|
+
assert.equal(acceptedCancel.interaction_response.source_job_id, 'source-form-2');
|
|
363
|
+
await cancelForm.locator('.bf-status.receipt').waitFor();
|
|
364
|
+
await page.waitForFunction(() => {
|
|
365
|
+
const host = Array.from(document.body.children).find((node) => node.shadowRoot);
|
|
366
|
+
return host?.shadowRoot?.querySelector('.send')?.disabled === false;
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
await page.locator('.foot textarea').fill('请分析这组数据');
|
|
177
370
|
await page.locator('.send').click();
|
|
178
|
-
const submitted = await
|
|
179
|
-
assert.
|
|
371
|
+
const submitted = await nextSubmission();
|
|
372
|
+
assert.equal(submitted.message, '请分析这组数据');
|
|
373
|
+
assert.deepEqual(submitted.client_capabilities, { renderers: ['bailing-form', 'bailing-chart'] });
|
|
180
374
|
await page.waitForFunction(() => {
|
|
181
375
|
const host = Array.from(document.body.children).find((node) => node.shadowRoot);
|
|
182
376
|
return host?.shadowRoot?.querySelector('.send')?.disabled === false;
|
|
183
377
|
});
|
|
184
378
|
|
|
379
|
+
const localInteractions = await page.evaluate(() => JSON.parse(localStorage.getItem('bailing_chat_pub_test') || '[]').filter((item) => item.i).map((item) => item.i));
|
|
380
|
+
assert.equal(localInteractions.length, 2);
|
|
381
|
+
assert.deepEqual(localInteractions.map((item) => item.form_id).sort(), ['cancel_form', 'refund_info']);
|
|
382
|
+
assert.ok(localInteractions.every((item) => !Object.hasOwn(item, 'values')), 'local interaction metadata must not duplicate submitted values');
|
|
383
|
+
await page.reload({ waitUntil: 'networkidle' });
|
|
384
|
+
await page.waitForFunction(() => {
|
|
385
|
+
const host = Array.from(document.body.children).find((node) => node.shadowRoot);
|
|
386
|
+
return host?.shadowRoot?.querySelectorAll('.bailing-form .bf-status.receipt').length === 2;
|
|
387
|
+
});
|
|
388
|
+
|
|
185
389
|
await page.evaluate(() => {
|
|
186
390
|
const host = Array.from(document.body.children).find((node) => node.shadowRoot);
|
|
187
391
|
host?.shadowRoot?.querySelector('.restart')?.click();
|
|
@@ -199,7 +403,31 @@ try {
|
|
|
199
403
|
assert.equal(afterRestart.activeCount, 0);
|
|
200
404
|
assert.equal(afterRestart.mounts, afterRestart.destroys);
|
|
201
405
|
|
|
202
|
-
|
|
406
|
+
serverMessages = [
|
|
407
|
+
{ r: 'a', t: formBlock(formPayload), j: 'server-source-form' },
|
|
408
|
+
{
|
|
409
|
+
r: 'u',
|
|
410
|
+
t: '用户提交了结构化表单。',
|
|
411
|
+
j: 'server-followup-job',
|
|
412
|
+
interaction: {
|
|
413
|
+
type: 'bailing-form', version: 1, source_job_id: 'server-source-form', form_id: 'refund_info', submission_id: 'sub_server_1234', action: 'submit',
|
|
414
|
+
},
|
|
415
|
+
},
|
|
416
|
+
];
|
|
417
|
+
const historyPage = await browser.newPage();
|
|
418
|
+
await historyPage.addInitScript(() => {
|
|
419
|
+
localStorage.removeItem('bailing_chat_pub_test');
|
|
420
|
+
localStorage.setItem('bailing_visitor_pub_test', 'visitor-server-history');
|
|
421
|
+
});
|
|
422
|
+
await historyPage.goto(`http://127.0.0.1:${address.port}/`, { waitUntil: 'networkidle' });
|
|
423
|
+
await historyPage.waitForFunction(() => {
|
|
424
|
+
const host = Array.from(document.body.children).find((node) => node.shadowRoot);
|
|
425
|
+
return host?.shadowRoot?.querySelector('[data-form-id="refund_info"] .bf-status.receipt')?.textContent?.includes('已提交');
|
|
426
|
+
});
|
|
427
|
+
assert.equal(await historyPage.locator('[data-form-id="refund_info"] button.primary').isDisabled(), true);
|
|
428
|
+
await historyPage.close();
|
|
429
|
+
|
|
430
|
+
console.log('✓ widget renderers expose safe forms, non-blocking acknowledgements, idempotent recovery, history receipts, capabilities, fallbacks, and cleanup');
|
|
203
431
|
} finally {
|
|
204
432
|
await browser.close();
|
|
205
433
|
await new Promise((resolve) => server.close(resolve));
|