bailinghub 0.3.4 → 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 +3 -0
- package/docker-compose.images.yml +2 -2
- package/docs/CHANGELOG.en.md +46 -1
- package/docs/CHANGELOG.md +14 -1
- package/docs/COMPATIBILITY.en.md +25 -0
- package/docs/CONTRACT.en.md +79 -8
- package/docs/CONTRACT.md +36 -6
- package/docs/INDEPENDENT_VALIDATION.en.md +4 -4
- package/docs/INDEPENDENT_VALIDATION.md +4 -4
- package/docs/QUICKSTART.en.md +6 -0
- package/docs/QUICKSTART.md +1 -1
- package/docs/README.en.md +2 -0
- package/docs/README.md +2 -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/console-map.en.md +1 -2
- package/docs/user-guide/console-map.md +2 -2
- 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 +1 -0
- package/scripts/check-image-tags.sh +1 -1
- package/scripts/check-release-consistency.test.mjs +5 -5
- package/scripts/install.sh +1 -1
- package/scripts/publish-images.sh +1 -1
- package/scripts/release-audit.mjs +1 -0
- package/scripts/verify-github-repo.mjs +1 -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 +61 -0
- package/src/core/runtime/execution-runtime.ts +17 -0
- package/src/routes/chat.test.ts +319 -7
- package/src/routes/chat.ts +166 -21
- package/web/console/assets/{Accounts-CAwrtBiS.js → Accounts-DuUY2UJU.js} +1 -1
- package/web/console/assets/{Approvals-C2BZ86T3.js → Approvals-B11mo1dy.js} +1 -1
- package/web/console/assets/{Audit-B-E4Y_Up.js → Audit-CQwJRIJT.js} +1 -1
- package/web/console/assets/{BrandLockup-C18u8Lx5.js → BrandLockup-BIF-h1pi.js} +1 -1
- package/web/console/assets/{Channels-DTy8ylH-.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-DWs9JFr0.js → Clients-DS29eUi2.js} +1 -1
- package/web/console/assets/{Cost-2SSYs1AT.js → Cost-BF52tfU2.js} +1 -1
- package/web/console/assets/{Credentials-B79LtxCE.js → Credentials-SwfmQAv6.js} +1 -1
- package/web/console/assets/{Diagnostics-BakcRYvb.js → Diagnostics-CJfbI_8p.js} +1 -1
- package/web/console/assets/{Executors-BXoyo28u.js → Executors-CzlZlznA.js} +1 -1
- package/web/console/assets/{Kb-ISbzquab.js → Kb-CVX22U4k.js} +1 -1
- package/web/console/assets/{Login-Dlu6Wgcf.js → Login-PoUVsBI-.js} +1 -1
- package/web/console/assets/{Projects-DFzmtnqg.js → Projects-DYlbjLQy.js} +1 -1
- package/web/console/assets/{Routes-B-hm9HGY.js → Routes-DSEvGujN.js} +1 -1
- package/web/console/assets/{Runs-hMRu1im3.js → Runs-B-TsYZEt.js} +1 -1
- package/web/console/assets/{Setup-CrBAV-b9.js → Setup-xiPXit_b.js} +1 -1
- package/web/console/assets/{Shell-B1a8DvXQ.js → Shell-DNiWZOYB.js} +1 -1
- package/web/console/assets/{StorageBuckets-BRfL_eHb.js → StorageBuckets-Bjsc3pLd.js} +1 -1
- package/web/console/assets/{SystemSettings-CyirVLbq.js → SystemSettings-CcKF2lJ9.js} +1 -1
- package/web/console/assets/{SystemStatus-DZ_OR7sk.js → SystemStatus-Oj1xjxJn.js} +1 -1
- package/web/console/assets/{Targets-CtIMa66c.js → Targets-y1KllVXT.js} +1 -1
- package/web/console/assets/{Tools-BfDZHt01.js → Tools-DoEP_y9x.js} +1 -1
- package/web/console/assets/{index-DBiByFiO.js → index-CxPIS6G7.js} +2 -2
- package/web/console/assets/{request-DY2cxQqZ.js → request-CBLNpLth.js} +1 -1
- package/web/console/assets/{schema-6mCQ7rR5.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 +18 -6
- package/web/console/assets/ChatEntries-9xbRiQov.css +0 -1
- package/web/console/assets/ChatEntries-DvD-4IeE.js +0 -7
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
# Rich Content Renderers for the Embedded Chat Widget
|
|
2
2
|
|
|
3
|
-
The BailingHub widget natively renders Markdown text, tables, images, and file links. Charts and interactive reports use
|
|
3
|
+
The BailingHub widget natively renders Markdown text, tables, images, and file links. Charts and interactive reports use a trusted renderer registry. The constrained `bailing-form` v1 renderer is built into the official widget. Both consume declarative fenced payloads while the core widget remains free of third-party runtime dependencies.
|
|
4
4
|
|
|
5
5
|
## Trust Boundary
|
|
6
6
|
|
|
7
7
|
- The model emits declarative data only. It cannot supply or select JavaScript, HTML, remote script URLs, or component code.
|
|
8
|
-
-
|
|
8
|
+
- Custom renderers are installed and registered by the embedding application and are therefore trusted host code. The built-in `bailing-form` follows the same allowlist and fallback boundary.
|
|
9
9
|
- A renderer never receives chat tickets, business credentials, acting-subject identity, or full page context.
|
|
10
10
|
- Unknown types, invalid JSON, oversized payloads, and renderer failures fall back to a code block rendered through `textContent`.
|
|
11
11
|
- Rich content mounts only after a complete, closed fenced code block arrives. Incremental streaming output does not repeatedly create charts.
|
|
@@ -24,7 +24,7 @@ const unregister = window.BailingChat.registerRenderer({
|
|
|
24
24
|
label: 'Business chart',
|
|
25
25
|
contentType: 'application/json', // or text/plain
|
|
26
26
|
maxPayloadBytes: 64 * 1024,
|
|
27
|
-
mount({ container, payload, source, type, version, theme, signal }) {
|
|
27
|
+
mount({ container, payload, source, type, version, theme, signal, message, respond }) {
|
|
28
28
|
// payload is untrusted input; validate fields, counts, and ranges here.
|
|
29
29
|
const chart = createMyChart(container, payload, theme);
|
|
30
30
|
return () => chart.destroy();
|
|
@@ -36,6 +36,25 @@ unregister();
|
|
|
36
36
|
|
|
37
37
|
`mount` may return a cleanup function, an object with `destroy()`, a Promise, or nothing. Async renderers should stop work when `signal` is aborted.
|
|
38
38
|
|
|
39
|
+
Widget API v1 adds two optional, backward-compatible context values for an
|
|
40
|
+
interactive renderer:
|
|
41
|
+
|
|
42
|
+
- `message` contains the current assistant message `jobId` and known
|
|
43
|
+
`responses`. Each response summary contains only
|
|
44
|
+
`type/version/source_job_id/form_id/submission_id/action`, never form values.
|
|
45
|
+
- `respond(response, presentation?)` returns a Promise and creates the next
|
|
46
|
+
user message in the same thread. A form response is
|
|
47
|
+
`{form_id, submission_id, action:"submit"|"cancel", values?}`;
|
|
48
|
+
`submission_id` matches `[A-Za-z0-9_-]{8,64}` and serialized `values` is at
|
|
49
|
+
most 32 KiB. The widget forces `type:"bailing-form"`, `version:1`, and
|
|
50
|
+
`source_job_id` from the current message closure. A renderer cannot select an
|
|
51
|
+
endpoint, method, or arbitrary source job. The optional `{displayText}`
|
|
52
|
+
presentation is local user-bubble copy and is never sent to the server.
|
|
53
|
+
|
|
54
|
+
Existing renderers may ignore the new properties, so
|
|
55
|
+
`rendererApiVersion === "1"` is unchanged. Neither `message` nor `respond`
|
|
56
|
+
exposes the ticket, visitor id, thread id, or other identity material.
|
|
57
|
+
|
|
39
58
|
## Reply Format
|
|
40
59
|
|
|
41
60
|
After `bailing-chart` is registered, a complete reply can include:
|
|
@@ -55,6 +74,93 @@ After `bailing-chart` is registered, a complete reply can include:
|
|
|
55
74
|
|
|
56
75
|
Type names start with a lowercase letter and contain only letters, numbers, dots, underscores, plus signs, and hyphens, up to 64 characters. JSON renderers accept objects or arrays; scalar payloads should use `text/plain`.
|
|
57
76
|
|
|
77
|
+
## Built-in `bailing-form` v1
|
|
78
|
+
|
|
79
|
+
The official widget advertises and renders `bailing-form` without React, Vue,
|
|
80
|
+
a JSON Schema runtime, or a form library. The model emits data only; the widget
|
|
81
|
+
owns controls, validation, submission, and receipts.
|
|
82
|
+
|
|
83
|
+
A host may preload its own `bailing-form` renderer before an asynchronous
|
|
84
|
+
widget script to explicitly replace the built-in UI. That trusted host code
|
|
85
|
+
must implement this section's complete validation, response, and cleanup
|
|
86
|
+
contract. The server still reloads and validates the source reply, so a host
|
|
87
|
+
override never relaxes the authoritative boundary.
|
|
88
|
+
|
|
89
|
+
````markdown
|
|
90
|
+
```bailing-form
|
|
91
|
+
{
|
|
92
|
+
"version": 1,
|
|
93
|
+
"form_id": "refund_info",
|
|
94
|
+
"title": "Refund information",
|
|
95
|
+
"description": "The conversation will continue after submission",
|
|
96
|
+
"schema": {
|
|
97
|
+
"reason": {
|
|
98
|
+
"type": "textarea",
|
|
99
|
+
"label": "Reason",
|
|
100
|
+
"required": true,
|
|
101
|
+
"maxLength": 200
|
|
102
|
+
},
|
|
103
|
+
"method": {
|
|
104
|
+
"type": "single_select",
|
|
105
|
+
"label": "Refund method",
|
|
106
|
+
"required": true,
|
|
107
|
+
"options": [
|
|
108
|
+
{ "label": "Original payment method", "value": "original" },
|
|
109
|
+
{ "label": "Account balance", "value": "balance" }
|
|
110
|
+
]
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
"submit_label": "Submit",
|
|
114
|
+
"cancel_label": "Cancel"
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
````
|
|
118
|
+
|
|
119
|
+
Top-level keys are limited to `version:1`, `form_id`, `title`, optional
|
|
120
|
+
`description`, `schema`, optional `submit_label`, and optional `cancel_label`.
|
|
121
|
+
Form and field ids match `[a-z][a-z0-9_-]{0,63}`. A fenced JSON payload is at
|
|
122
|
+
most 32 KiB and contains 1–12 fields. Titles and labels are at most 80
|
|
123
|
+
characters, form descriptions 300, field descriptions 200, placeholders 120,
|
|
124
|
+
and button labels 32.
|
|
125
|
+
|
|
126
|
+
| `type` | Additional keys and limits |
|
|
127
|
+
|---|---|
|
|
128
|
+
| `text` | optional `minLength` / `maxLength`; maximum cap 500 |
|
|
129
|
+
| `textarea` | optional `minLength` / `maxLength`; maximum cap 2000 |
|
|
130
|
+
| `number` | optional finite numeric `min` / `max` |
|
|
131
|
+
| `date` | optional `min` / `max` in fixed `YYYY-MM-DD` format |
|
|
132
|
+
| `boolean` | no additional keys |
|
|
133
|
+
| `single_select` | required `options`, 1–50 entries, one choice |
|
|
134
|
+
| `multi_select` | required `options`, 1–50 entries, multiple choices |
|
|
135
|
+
|
|
136
|
+
All fields use `label` and may use `description`, `placeholder`, and
|
|
137
|
+
`required`. An option contains only `{label,value}`; labels are at most 80
|
|
138
|
+
characters, values at most 120, and values are unique within the field.
|
|
139
|
+
Unknown keys, nested objects, files, regular expressions, HTML/JavaScript/CSS,
|
|
140
|
+
remote scripts/data sources, and values containing triple backticks are
|
|
141
|
+
rejected.
|
|
142
|
+
|
|
143
|
+
### Submission, receipts, and history recovery
|
|
144
|
+
|
|
145
|
+
1. The form mounts only after the source reply is complete and `done`; the
|
|
146
|
+
source job never enters a waiting state.
|
|
147
|
+
2. Submit or cancel posts an `interaction_response` to the original entry. The
|
|
148
|
+
server creates a new job in the same thread and uses the existing SSE flow.
|
|
149
|
+
3. Controls are disabled while sending. Once job creation succeeds, the source
|
|
150
|
+
form becomes a read-only Submitted or Cancelled receipt. A failed request
|
|
151
|
+
restores the controls and is not presented as success.
|
|
152
|
+
4. A user history message may include an `interaction` summary. The widget uses
|
|
153
|
+
`source_job_id + form_id` to restore replied state after reload or on another
|
|
154
|
+
device, without making the source form submit again.
|
|
155
|
+
|
|
156
|
+
Forms collect ordinary information or choices. They are not approvals,
|
|
157
|
+
authorization credentials, or tool-execution confirmations. Credential- or
|
|
158
|
+
payment-like text in the form title/description or a field's name, label,
|
|
159
|
+
description, or placeholder is rejected, including passwords, API keys, tokens,
|
|
160
|
+
private keys, card numbers, and CVV. Non-secret submitted values become
|
|
161
|
+
conversation-ledger and model-context data, so deployments must apply their own
|
|
162
|
+
retention and compliance rules.
|
|
163
|
+
|
|
58
164
|
## Loading Order
|
|
59
165
|
|
|
60
166
|
Register after the widget loads:
|
|
@@ -99,7 +205,7 @@ Content-Type: application/json
|
|
|
99
205
|
"message": "Analyze revenue for the last seven days",
|
|
100
206
|
"visitor_id": "visitor_01HXYZ",
|
|
101
207
|
"client_capabilities": {
|
|
102
|
-
"renderers": ["bailing-chart"]
|
|
208
|
+
"renderers": ["bailing-chart", "bailing-form"]
|
|
103
209
|
}
|
|
104
210
|
}
|
|
105
211
|
```
|
|
@@ -107,7 +213,7 @@ Content-Type: application/json
|
|
|
107
213
|
`client_capabilities` is presentation-only negotiation:
|
|
108
214
|
|
|
109
215
|
- when it is absent, BailingHub does not assume that the client can render charts;
|
|
110
|
-
- declaring `bailing-chart` does not change identity, permissions, approval, routing, tool allowlists, or final business authorization;
|
|
216
|
+
- declaring `bailing-chart` or `bailing-form` does not change identity, permissions, approval, routing, tool allowlists, or final business authorization;
|
|
111
217
|
- do not advertise a renderer that the client has not installed; the server accepts at most 16 valid type names;
|
|
112
218
|
- a capable client does not require a chart in every answer, and missing data must never be fabricated to produce one.
|
|
113
219
|
|
|
@@ -116,11 +222,19 @@ After creating the job, connect to `GET /chat/:entry_key/events/:job_id` and fol
|
|
|
116
222
|
1. append `delta` events to a provisional text bubble without mounting rich content;
|
|
117
223
|
2. discard the provisional buffer and render state on `reset`;
|
|
118
224
|
3. replace the provisional bubble with the authoritative `done.reply`;
|
|
119
|
-
4. only after `done`, parse complete fenced blocks with a mature Markdown parser and dispatch allowlisted types to trusted renderers;
|
|
225
|
+
4. only after `done`, parse complete fenced blocks with a mature Markdown parser and dispatch allowlisted types to trusted renderers; retain that `done.job_id` as the form `source_job_id`;
|
|
120
226
|
5. never present provisional text from `failed` or `timeout` as a final business result.
|
|
121
227
|
|
|
122
228
|
See [`docs/examples/custom-streaming-chat-client.mjs`](examples/custom-streaming-chat-client.mjs) for the transport lifecycle. It intentionally omits a Markdown parser and chart library. Integrators should consume fenced-code AST/tokens from their existing Markdown parser rather than interpreting model output with `eval`, `innerHTML`, or remote scripts.
|
|
123
229
|
|
|
230
|
+
To submit a form, a custom client posts
|
|
231
|
+
`{interaction_response:{type:"bailing-form",version:1,source_job_id,form_id,submission_id,action,values?}, visitor_id?, ticket?, thread_id?}`
|
|
232
|
+
to the same `POST /chat/:entry_key`. The server checks the source
|
|
233
|
+
job/entry/identity/thread, reloads the authoritative schema, validates values,
|
|
234
|
+
and deduplicates by `submission_id`. Do not send `message` in the same request
|
|
235
|
+
or send a client-side schema as authority. See
|
|
236
|
+
[CONTRACT.en.md](CONTRACT.en.md#non-blocking-bailing-form-responses).
|
|
237
|
+
|
|
124
238
|
### Minimum Requirements for a Custom Renderer
|
|
125
239
|
|
|
126
240
|
- match the type against a local allowlist such as `bailing-chart`;
|
|
@@ -129,5 +243,8 @@ See [`docs/examples/custom-streaming-chat-client.mjs`](examples/custom-streaming
|
|
|
129
243
|
- fall back to plain text or a code block on unknown types, invalid JSON, limits, or renderer errors;
|
|
130
244
|
- destroy chart instances and listeners when the final message is replaced, the route changes, or the component unmounts;
|
|
131
245
|
- keep attachments, references, charts, and business execution results as separate contracts.
|
|
246
|
+
- for `bailing-form`, implement this document's field allowlist, range checks,
|
|
247
|
+
unique submission id, failure recovery, and history receipt; never pass an
|
|
248
|
+
arbitrary JSON Schema directly into a dynamic form runtime.
|
|
132
249
|
|
|
133
250
|
In short: the official widget is the batteries-included path. A custom client owns capability advertisement, SSE lifecycle handling, final-reply parsing, and trusted rendering; BailingHub does not silently assume those host responsibilities.
|
package/docs/WIDGET_RENDERERS.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
# 嵌入聊天组件富内容渲染器
|
|
2
2
|
|
|
3
|
-
BailingHub 的嵌入聊天组件原生支持 Markdown
|
|
3
|
+
BailingHub 的嵌入聊天组件原生支持 Markdown 文本、表格、图片和文件链接。图表、动态报表等展示内容通过可信渲染器注册表扩展;受限的 `bailing-form` v1 则由官方 Widget 原生渲染。两者都消费声明式 fenced payload,核心组件继续保持零第三方运行时依赖。
|
|
4
4
|
|
|
5
5
|
## 适用边界
|
|
6
6
|
|
|
7
7
|
- 模型只能输出声明式数据,不能输出或选择要执行的 JavaScript、HTML、远程脚本地址或组件代码。
|
|
8
|
-
-
|
|
8
|
+
- 自定义渲染器由嵌入页面的开发者预先安装并注册,属于宿主应用的可信代码;官方 `bailing-form` 实现使用同一白名单和失败回退边界。
|
|
9
9
|
- 渲染器不会收到聊天票据、业务凭证、会话身份或完整页面上下文。
|
|
10
10
|
- 未注册类型、非法 JSON、超限载荷和渲染异常都会降级成使用 `textContent` 展示的代码块。
|
|
11
11
|
- 富内容只在完整闭合的 fenced code block 到达后挂载;流式增量阶段不会反复创建图表。
|
|
@@ -24,7 +24,7 @@ const unregister = window.BailingChat.registerRenderer({
|
|
|
24
24
|
label: '业务图表',
|
|
25
25
|
contentType: 'application/json', // 或 text/plain
|
|
26
26
|
maxPayloadBytes: 64 * 1024,
|
|
27
|
-
mount({ container, payload, source, type, version, theme, signal }) {
|
|
27
|
+
mount({ container, payload, source, type, version, theme, signal, message, respond }) {
|
|
28
28
|
// payload 是不可信输入,适配器必须校验字段、数量和取值范围。
|
|
29
29
|
const chart = createMyChart(container, payload, theme);
|
|
30
30
|
return () => chart.destroy();
|
|
@@ -37,6 +37,13 @@ unregister();
|
|
|
37
37
|
|
|
38
38
|
`mount` 可以返回销毁函数、带 `destroy()` 的对象、Promise,或不返回值。`signal` 在消息离开视图时触发 abort,异步渲染器应及时停止工作。
|
|
39
39
|
|
|
40
|
+
Widget API v1 为需要交互回传的渲染器兼容新增了两个可选上下文:
|
|
41
|
+
|
|
42
|
+
- `message` 提供当前助手消息的 `jobId` 和已知 `responses`。`responses` 每项只含 `type/version/source_job_id/form_id/submission_id/action`,不含表单值。
|
|
43
|
+
- `respond(response, presentation?)` 返回 Promise,用于发起同 thread 的下一条用户消息。表单 response 体为 `{form_id, submission_id, action:"submit"|"cancel", values?}`,`submission_id` 匹配 `[A-Za-z0-9_-]{8,64}`,`values` 最大 32 KiB;Widget 从当前消息闭包强制补入 `type:"bailing-form"` / `version:1` / `source_job_id`,渲染器不能指定任意端点、方法或源 job。`presentation` 目前只支持本地用户气泡文案 `{displayText}`,不发往服务端。
|
|
44
|
+
|
|
45
|
+
旧渲染器可继续只解构原有参数;增加 `message/respond` 不改变 `rendererApiVersion === "1"`。`respond` 不会向渲染器暴露 `ticket`、`visitor_id`、`thread_id` 或其他身份材料。
|
|
46
|
+
|
|
40
47
|
## 输出格式
|
|
41
48
|
|
|
42
49
|
注册 `bailing-chart` 后,完整回复中的以下代码块会交给对应渲染器:
|
|
@@ -56,6 +63,65 @@ unregister();
|
|
|
56
63
|
|
|
57
64
|
类型名只接受小写字母开头的字母、数字、点、下划线、加号和连字符组合,最长 64 个字符。JSON 渲染器只接受对象或数组;字符串等标量请使用 `text/plain`。
|
|
58
65
|
|
|
66
|
+
## 官方 `bailing-form` v1
|
|
67
|
+
|
|
68
|
+
官方 Widget 自动声明并渲染 `bailing-form`,不需要宿主引入 React、Vue、JSON Schema 运行时或表单库。模型只能输出数据,字段控件、校验、提交和回执由 Widget 固定实现。
|
|
69
|
+
|
|
70
|
+
宿主可在异步 Widget 加载前预注册同名 `bailing-form` 渲染器以显式覆盖内置 UI;这是宿主可信代码的责任,必须完整实现本节的校验、回传和销毁契约。服务端无论如何都会重读源回复验值,宿主覆盖不会放宽权威边界。
|
|
71
|
+
|
|
72
|
+
````markdown
|
|
73
|
+
```bailing-form
|
|
74
|
+
{
|
|
75
|
+
"version": 1,
|
|
76
|
+
"form_id": "refund_info",
|
|
77
|
+
"title": "请补充退款信息",
|
|
78
|
+
"description": "提交后将在当前会话继续处理",
|
|
79
|
+
"schema": {
|
|
80
|
+
"reason": {
|
|
81
|
+
"type": "textarea",
|
|
82
|
+
"label": "退款原因",
|
|
83
|
+
"required": true,
|
|
84
|
+
"maxLength": 200
|
|
85
|
+
},
|
|
86
|
+
"method": {
|
|
87
|
+
"type": "single_select",
|
|
88
|
+
"label": "退款方式",
|
|
89
|
+
"required": true,
|
|
90
|
+
"options": [
|
|
91
|
+
{ "label": "原路退回", "value": "original" },
|
|
92
|
+
{ "label": "余额退回", "value": "balance" }
|
|
93
|
+
]
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
"submit_label": "提交信息",
|
|
97
|
+
"cancel_label": "取消"
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
````
|
|
101
|
+
|
|
102
|
+
顶层只接受 `version:1`、`form_id`、`title`、`description?`、`schema`、`submit_label?`、`cancel_label?`。`form_id` 和字段名匹配 `[a-z][a-z0-9_-]{0,63}`;单个 fenced JSON 最大 32 KiB,`schema` 包含 1–12 个字段。标题和字段标签最长 80 字符,顶层说明 300,字段说明 200,占位文字 120,按钮文字 32。
|
|
103
|
+
|
|
104
|
+
| `type` | 额外字段与限制 |
|
|
105
|
+
|---|---|
|
|
106
|
+
| `text` | `minLength?` / `maxLength?`,最长上限 500 |
|
|
107
|
+
| `textarea` | `minLength?` / `maxLength?`,最长上限 2000 |
|
|
108
|
+
| `number` | 可选有限数值 `min?` / `max?` |
|
|
109
|
+
| `date` | 可选 `min?` / `max?`,格式固定为 `YYYY-MM-DD` |
|
|
110
|
+
| `boolean` | 无额外字段 |
|
|
111
|
+
| `single_select` | 必填 `options`,1–50 项,单选 |
|
|
112
|
+
| `multi_select` | 必填 `options`,1–50 项,多选 |
|
|
113
|
+
|
|
114
|
+
所有字段可使用 `label`、`description?`、`placeholder?`、`required?`。选项只包含 `{label,value}`,label 最长 80、value 最长 120,且同一字段的 value 唯一。未声明字段、嵌套对象、文件、正则表达式、HTML/JavaScript/CSS、远程脚本/数据源和内含三反引号的值会被拒绝。
|
|
115
|
+
|
|
116
|
+
### 提交、回执与历史恢复
|
|
117
|
+
|
|
118
|
+
1. 表单只在源回答完整 `done` 后挂载,源 job 不会进入等待状态。
|
|
119
|
+
2. 用户提交或取消后,Widget 将 `interaction_response` 发往原入口,服务端在同 thread 创建新 job,再走既有 SSE 流。
|
|
120
|
+
3. 发送中控件禁用;创建新 job 成功后,源表单变为只读的“已提交”或“已取消”回执。请求失败时恢复控件,不把本地点击冒充成功。
|
|
121
|
+
4. `/thread` 返回的用户消息可带 `interaction` 摘要;Widget 用 `source_job_id + form_id` 重建已回复状态,跨设备/刷新后不会再显示可重复提交的表单。
|
|
122
|
+
|
|
123
|
+
表单只用来收集普通信息或选择,不是审批单、授权凭据或工具执行确认。表单标题/说明、字段名/标签/说明/占位文字如疑似密码、API Key、Token、私钥、银行卡号或 CVV 会被拒绝;部署方还应注意,用户提交的非秘密值会作为对话消息进入总账和模型上下文,须按自己的数据保留与合规规则使用。
|
|
124
|
+
|
|
59
125
|
## 加载顺序
|
|
60
126
|
|
|
61
127
|
### Widget 加载后注册
|
|
@@ -105,7 +171,7 @@ Content-Type: application/json
|
|
|
105
171
|
"message": "分析近七日营业额",
|
|
106
172
|
"visitor_id": "visitor_01HXYZ",
|
|
107
173
|
"client_capabilities": {
|
|
108
|
-
"renderers": ["bailing-chart"]
|
|
174
|
+
"renderers": ["bailing-chart", "bailing-form"]
|
|
109
175
|
}
|
|
110
176
|
}
|
|
111
177
|
```
|
|
@@ -113,7 +179,7 @@ Content-Type: application/json
|
|
|
113
179
|
`client_capabilities` 只用于回答呈现提示:
|
|
114
180
|
|
|
115
181
|
- 不提供时,中枢不会因为客户端“可能支持图表”而主动要求模型输出图表;
|
|
116
|
-
- 声明 `bailing-chart` 只表示客户端能安全展示该声明,不改变身份、权限、审批、路由、工具白名单或业务授权;
|
|
182
|
+
- 声明 `bailing-chart` 或 `bailing-form` 只表示客户端能安全展示该声明,不改变身份、权限、审批、路由、工具白名单或业务授权;
|
|
117
183
|
- 不要把尚未安装的渲染器写进能力列表;服务端最多接受 16 个符合命名规则的类型;
|
|
118
184
|
- 运行时是否输出图表仍由真实数据和表达需要决定,不能用图表填补缺失数据。
|
|
119
185
|
|
|
@@ -122,11 +188,13 @@ Content-Type: application/json
|
|
|
122
188
|
1. `delta` 只追加到临时文本气泡,不在增量阶段执行富内容渲染;
|
|
123
189
|
2. `reset` 立即清空临时文本和对应渲染状态;
|
|
124
190
|
3. `done.reply` 是权威最终文本,必须替换临时气泡;
|
|
125
|
-
4. 只有 `done` 到达后,才用成熟 Markdown 解析器读取完整 fenced code block
|
|
191
|
+
4. 只有 `done` 到达后,才用成熟 Markdown 解析器读取完整 fenced code block,并把白名单类型交给可信渲染器;表单回传必须保留此 `done.job_id` 作为 `source_job_id`;
|
|
126
192
|
5. `failed` 或 `timeout` 不得把临时文本冒充成最终业务结果。
|
|
127
193
|
|
|
128
194
|
最小传输范例见 [`docs/examples/custom-streaming-chat-client.mjs`](examples/custom-streaming-chat-client.mjs)。它故意不包含 Markdown 解析器和图表库:业务前端应复用自己的 Markdown AST/token 流,在 fenced code token 层识别渲染类型,不要用 `eval`、`innerHTML` 或远程脚本解释模型输出。
|
|
129
195
|
|
|
196
|
+
自建客户端提交表单时,向同一 `POST /chat/:entry_key` 发送 `{interaction_response:{type:"bailing-form",version:1,source_job_id,form_id,submission_id,action,values?}, visitor_id?, ticket?, thread_id?}`。服务端会核对源 job/入口/身份/thread,从权威回复重新取 schema 验值,并以 `submission_id` 幂等去重;客户端不得同时发 `message`,也不得把自己的 schema 当作权威传回。完整 HTTP 契约见 [CONTRACT.md §1.1.1](CONTRACT.md#111-bailing-form-非阻塞交互回传)。
|
|
197
|
+
|
|
130
198
|
### 自建渲染器的最低门槛
|
|
131
199
|
|
|
132
200
|
- 类型必须命中本地白名单,例如只接受 `bailing-chart`;
|
|
@@ -135,5 +203,6 @@ Content-Type: application/json
|
|
|
135
203
|
- 未知类型、解析失败、超限或渲染异常必须回退成普通代码块/文本,不得放宽校验重试;
|
|
136
204
|
- 最终消息替换、路由切换和组件卸载时,应销毁图表实例与监听器;
|
|
137
205
|
- 附件、引用、图表和业务执行结果是不同契约,不能互相推断。
|
|
206
|
+
- `bailing-form` 须实现本文的字段白名单、范围验证、唯一提交标识、失败恢复和历史回执;不得把任意 JSON Schema 直接交给动态表单引擎。
|
|
138
207
|
|
|
139
208
|
一句话判断:官方 Widget 负责开箱即用;自建客户端负责能力自报、SSE 生命周期、最终文本解析和可信渲染,BailingHub 不会把宿主前端的安全责任隐式接管。
|
|
@@ -30,7 +30,7 @@ Create a base, select an embedding credential, ingest documents or data sources,
|
|
|
30
30
|
|
|
31
31
|
## Web Chat Entries
|
|
32
32
|
|
|
33
|
-
Bind a widget to a route, configure origins, appearance, welcome text, identity ticket behavior, AI disclosure, and embed code.
|
|
33
|
+
Bind a widget to a route, configure exact HTTP(S) origins in `scheme://host[:port]` form, appearance (including optional default-open behavior), welcome text, identity ticket behavior, AI disclosure, and embed code.
|
|
34
34
|
|
|
35
35
|
## Inbound Channels
|
|
36
36
|
|
|
@@ -55,4 +55,3 @@ Review build version, contract versions, migration state, runtime backend, and c
|
|
|
55
55
|
## Accounts And Change Audit
|
|
56
56
|
|
|
57
57
|
Accounts control console RBAC. Change Audit records who changed configuration and when. These are administrative controls for the single organization operating the open-source instance.
|
|
58
|
-
|
|
@@ -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"] },
|
|
@@ -101,6 +101,7 @@ const englishCompanions = {
|
|
|
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
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',
|
|
104
105
|
'docs/TOOLS_DESIGN.md': 'docs/TOOLS_DESIGN.en.md',
|
|
105
106
|
'docs/TOOLS_MODEL.md': 'docs/TOOLS_MODEL.en.md',
|
|
106
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/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}"
|
|
@@ -124,6 +124,7 @@ const requiredFiles = [
|
|
|
124
124
|
'docs/RELEASE_NOTES_v0.3.2.md',
|
|
125
125
|
'docs/RELEASE_NOTES_v0.3.3.md',
|
|
126
126
|
'docs/RELEASE_NOTES_v0.3.4.md',
|
|
127
|
+
'docs/RELEASE_NOTES_v0.4.0.md',
|
|
127
128
|
'docs/CHANGELOG.md',
|
|
128
129
|
];
|
|
129
130
|
for (const file of requiredFiles) requireFile(file);
|