bailinghub 0.3.4 → 0.5.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.
Files changed (169) hide show
  1. package/.gitignore +5 -0
  2. package/README.en.md +6 -1
  3. package/README.md +6 -0
  4. package/SECURITY.md +11 -0
  5. package/docker-compose.images.yml +2 -2
  6. package/docs/AGENT_AUTH_API.en.md +175 -0
  7. package/docs/AGENT_AUTH_API.md +190 -0
  8. package/docs/AGENT_CLIENT_QUICKSTART.en.md +212 -0
  9. package/docs/AGENT_CLIENT_QUICKSTART.md +206 -0
  10. package/docs/AGENT_CLIENT_RUNTIME_API.en.md +157 -0
  11. package/docs/AGENT_CLIENT_RUNTIME_API.md +107 -0
  12. package/docs/CHANGELOG.en.md +59 -1
  13. package/docs/CHANGELOG.md +27 -1
  14. package/docs/COMPATIBILITY.en.md +25 -0
  15. package/docs/CONTRACT.en.md +79 -8
  16. package/docs/CONTRACT.md +36 -6
  17. package/docs/INDEPENDENT_VALIDATION.en.md +4 -4
  18. package/docs/INDEPENDENT_VALIDATION.md +4 -4
  19. package/docs/QUICKSTART.en.md +6 -0
  20. package/docs/QUICKSTART.md +1 -1
  21. package/docs/README.en.md +8 -0
  22. package/docs/README.md +8 -0
  23. package/docs/RELEASE_NOTES_v0.4.0.en.md +39 -0
  24. package/docs/RELEASE_NOTES_v0.4.0.md +39 -0
  25. package/docs/RELEASE_NOTES_v0.5.0.en.md +41 -0
  26. package/docs/RELEASE_NOTES_v0.5.0.md +41 -0
  27. package/docs/STREAMING.en.md +32 -0
  28. package/docs/STREAMING.md +8 -2
  29. package/docs/WIDGET_RENDERERS.en.md +123 -6
  30. package/docs/WIDGET_RENDERERS.md +75 -6
  31. package/docs/user-guide/console-map.en.md +1 -2
  32. package/docs/user-guide/console-map.md +2 -2
  33. package/docs//345/205/274/345/256/271/346/200/247/344/270/216/345/215/207/347/272/247.md +9 -0
  34. package/package.json +3 -2
  35. package/schemas/config/chat-entry.schema.json +2 -1
  36. package/schemas/config/client.schema.json +7 -0
  37. package/schemas/config/common.schema.json +30 -0
  38. package/schemas/config/route.schema.json +11 -0
  39. package/scripts/check-doc-links.mjs +1 -0
  40. package/scripts/check-image-tags.sh +1 -1
  41. package/scripts/check-release-consistency.test.mjs +5 -5
  42. package/scripts/e2e-console.mjs +144 -0
  43. package/scripts/export-oss.mjs +5 -12
  44. package/scripts/install.sh +1 -1
  45. package/scripts/public-content-denylist.mjs +82 -0
  46. package/scripts/public-content-denylist.test.mjs +53 -0
  47. package/scripts/publish-images.sh +1 -1
  48. package/scripts/release-audit.mjs +8 -12
  49. package/scripts/sdk-runtime-test.mjs +171 -7
  50. package/scripts/security-scan.mjs +8 -5
  51. package/scripts/validate-examples.mjs +3 -1
  52. package/scripts/verify-github-repo.mjs +7 -11
  53. package/scripts/verify-oss-export.mjs +6 -12
  54. package/scripts/widget-renderer-test.mjs +244 -16
  55. package/sdk/php/README.md +27 -1
  56. package/sdk/php/src/AgentAuth.php +78 -0
  57. package/sdk/php/src/HubClient.php +3 -0
  58. package/sdk/php7/README.md +32 -2
  59. package/sdk/php7/src/AgentAuth.php +77 -0
  60. package/sdk/php7/src/HubClient.php +3 -0
  61. package/sql/055_agent_auth.sql +72 -0
  62. package/sql/056_agent_client_runtime.sql +60 -0
  63. package/src/adapters/channels/wecom-api.ts +1 -1
  64. package/src/app/agent-client-runtime.test.ts +221 -0
  65. package/src/app/agent-client-runtime.ts +408 -0
  66. package/src/app/agent-tool-invocations.test.ts +462 -0
  67. package/src/app/agent-tool-invocations.ts +795 -0
  68. package/src/app/agent-tool-job.test.ts +62 -0
  69. package/src/app/agent-tool-job.ts +41 -0
  70. package/src/app/auth.ts +2 -1
  71. package/src/app/kernel.ts +2 -0
  72. package/src/app/runtime-context.ts +8 -0
  73. package/src/app/tool-approvals.ts +5 -1
  74. package/src/app/tool-assembly.ts +19 -1
  75. package/src/app/tool-context.ts +2 -1
  76. package/src/core/config/config-codec.ts +2 -1
  77. package/src/core/config/config-models.test.ts +28 -1
  78. package/src/core/config/config-models.ts +46 -3
  79. package/src/core/config/config-schema.test.ts +8 -0
  80. package/src/core/config/route-config.test.ts +15 -0
  81. package/src/core/config/route-config.ts +36 -0
  82. package/src/core/config/tools-config.test.ts +58 -1
  83. package/src/core/config/tools-config.ts +84 -0
  84. package/src/core/contracts/tools.ts +162 -29
  85. package/src/core/contracts/types.ts +38 -1
  86. package/src/core/platform/chat-form.test.ts +147 -0
  87. package/src/core/platform/chat-form.ts +402 -0
  88. package/src/core/platform/version.ts +1 -1
  89. package/src/core/runtime/agent-client-trace.test.ts +154 -0
  90. package/src/core/runtime/agent-client-trace.ts +288 -0
  91. package/src/core/runtime/execution-runtime.test.ts +61 -0
  92. package/src/core/runtime/execution-runtime.ts +17 -0
  93. package/src/core/runtime/launch-runtime.ts +13 -0
  94. package/src/core/runtime/trace-runtime.test.ts +18 -1
  95. package/src/core/runtime/trace-runtime.ts +28 -3
  96. package/src/core/state/state-codec.ts +2 -0
  97. package/src/infrastructure/config/config-agent-auth-repository.test.ts +147 -0
  98. package/src/infrastructure/config/config-agent-auth-repository.ts +356 -0
  99. package/src/infrastructure/config/config-agent-client-runtime-repository.ts +253 -0
  100. package/src/infrastructure/config/config-approval-ledger.test.ts +32 -0
  101. package/src/infrastructure/config/config-approval-ledger.ts +16 -0
  102. package/src/infrastructure/config/config-client-repository.ts +3 -3
  103. package/src/infrastructure/config/config-conversation-ledger.test.ts +69 -0
  104. package/src/infrastructure/config/config-conversation-ledger.ts +8 -7
  105. package/src/infrastructure/config/config-observability-ledger.test.ts +50 -0
  106. package/src/infrastructure/config/config-observability-ledger.ts +65 -10
  107. package/src/infrastructure/config/config-route-repository.ts +4 -3
  108. package/src/infrastructure/config/configstore.ts +14 -3
  109. package/src/infrastructure/state/state-mysql.ts +2 -2
  110. package/src/kernel-api/v1/contracts.ts +8 -0
  111. package/src/routes/admin-runtime.test.ts +214 -0
  112. package/src/routes/admin-runtime.ts +82 -2
  113. package/src/routes/agent-api.test.ts +379 -0
  114. package/src/routes/agent-api.ts +251 -0
  115. package/src/routes/agent-auth.test.ts +276 -0
  116. package/src/routes/agent-auth.ts +395 -0
  117. package/src/routes/approvals.ts +4 -1
  118. package/src/routes/chat.test.ts +319 -7
  119. package/src/routes/chat.ts +166 -21
  120. package/src/routes/critical-routes.test.ts +235 -1
  121. package/src/routes/private-default.ts +2 -1
  122. package/src/routes/private.ts +16 -1
  123. package/src/routes/run.ts +79 -13
  124. package/web/connect/bailing-connect-php.tgz +0 -0
  125. package/web/connect/bailing-connect-php7.tgz +0 -0
  126. package/web/console/assets/{Accounts-CAwrtBiS.js → Accounts-D4RRm5D1.js} +1 -1
  127. package/web/console/assets/{Approvals-C2BZ86T3.js → Approvals-CsTTKb8o.js} +1 -1
  128. package/web/console/assets/{Audit-B-E4Y_Up.js → Audit-BzvZ7JZw.js} +1 -1
  129. package/web/console/assets/{BrandLockup-C18u8Lx5.js → BrandLockup-CYcA93wh.js} +1 -1
  130. package/web/console/assets/{Channels-DTy8ylH-.js → Channels-DRQZggqM.js} +1 -1
  131. package/web/console/assets/ChatEntries-BUB7BWKU.js +7 -0
  132. package/web/console/assets/ChatEntries-DsYtcXN6.css +1 -0
  133. package/web/console/assets/Clients-CQ_MonGL.css +1 -0
  134. package/web/console/assets/Clients-HhCyrxfz.js +3 -0
  135. package/web/console/assets/{Cost-2SSYs1AT.js → Cost-BZgFf1yM.js} +1 -1
  136. package/web/console/assets/{Credentials-B79LtxCE.js → Credentials-BTe2Q07j.js} +1 -1
  137. package/web/console/assets/{Diagnostics-BakcRYvb.js → Diagnostics-WL-buYli.js} +1 -1
  138. package/web/console/assets/{Executors-BXoyo28u.js → Executors-CGZ-7Xmp.js} +1 -1
  139. package/web/console/assets/{Kb-ISbzquab.js → Kb-VVw8oGsT.js} +1 -1
  140. package/web/console/assets/{Login-Dlu6Wgcf.js → Login-rwvmBBPl.js} +1 -1
  141. package/web/console/assets/{Projects-DFzmtnqg.js → Projects-CexaCEY1.js} +1 -1
  142. package/web/console/assets/Routes-B9ZHbQAp.js +124 -0
  143. package/web/console/assets/Routes-BbkFpi6Y.css +1 -0
  144. package/web/console/assets/Runs-4zDD9VOC.css +1 -0
  145. package/web/console/assets/Runs-BzFNPTwD.js +3 -0
  146. package/web/console/assets/{Setup-CrBAV-b9.js → Setup-Djh5yadQ.js} +1 -1
  147. package/web/console/assets/{Shell-B1a8DvXQ.js → Shell-kn763smL.js} +1 -1
  148. package/web/console/assets/{StorageBuckets-BRfL_eHb.js → StorageBuckets-CQBR41W1.js} +1 -1
  149. package/web/console/assets/{SystemSettings-CyirVLbq.js → SystemSettings-DgnopekD.js} +1 -1
  150. package/web/console/assets/{SystemStatus-DZ_OR7sk.js → SystemStatus-Bj8-kPt2.js} +1 -1
  151. package/web/console/assets/{Targets-CtIMa66c.js → Targets-BAfCt_nH.js} +1 -1
  152. package/web/console/assets/{Tools-BfDZHt01.js → Tools-xjd0NZdE.js} +1 -1
  153. package/web/console/assets/{index-DBiByFiO.js → index-DfJA7iJS.js} +2 -2
  154. package/web/console/assets/{request-DY2cxQqZ.js → request-DkNPOweH.js} +1 -1
  155. package/web/console/assets/{schema-6mCQ7rR5.js → schema-CgPWAu1_.js} +1 -1
  156. package/web/console/index.html +1 -1
  157. package/web/widget/widget.js +493 -14
  158. package/web-admin/src/pages/ChatEntries.vue +18 -6
  159. package/web-admin/src/pages/Clients.vue +11 -3
  160. package/web-admin/src/pages/Routes.vue +282 -16
  161. package/web-admin/src/pages/Runs.vue +159 -38
  162. package/web/console/assets/ChatEntries-9xbRiQov.css +0 -1
  163. package/web/console/assets/ChatEntries-DvD-4IeE.js +0 -7
  164. package/web/console/assets/Clients--D7NQJKk.css +0 -1
  165. package/web/console/assets/Clients-DWs9JFr0.js +0 -3
  166. package/web/console/assets/Routes-B-hm9HGY.js +0 -124
  167. package/web/console/assets/Routes-DWGQN5Pv.css +0 -1
  168. package/web/console/assets/Runs-CUtSsPW-.css +0 -1
  169. package/web/console/assets/Runs-hMRu1im3.js +0 -3
@@ -0,0 +1,39 @@
1
+ # BailingHub v0.4.0:原生对话表单与聊天入口控制
2
+
3
+ `v0.4.0` 为官方网页聊天组件增加受约束的原生对话表单,并补齐聊天入口的默认展开与浏览器 Origin 白名单配置。表单沿用现有展示能力协商与非阻塞会话模型,不建立第二套任务状态或审批协议。
4
+
5
+ ## 主要变化
6
+
7
+ - **原生对话表单**:官方零依赖 Widget 支持 `bailing-form` v1,可安全渲染文本、多行文本、数字、日期、布尔、单选和多选字段,并提供客户端/服务端双重校验、提交回执与历史恢复。
8
+ - **主动收集信息**:只有客户端明确声明支持 `bailing-form` 时,内置 LLM 才会收到受限表单输出指引。当上下文表明继续任务必须一次补齐多项信息时,模型可以主动输出表单,无需用户先要求“输出一个表单”。
9
+ - **非阻塞续聊**:源回答仍正常进入 `done`;提交、取消或跳过表单会在同一 thread 创建新的用户轮次和 job,不新增 `input_required`,也不改变既有 SSE 终态。
10
+ - **默认展开**:聊天入口外观新增默认关闭的 `default_open`。开启后现有官方嵌入脚本加载即展开,无需修改业务页面;原有 `data-open="1"` 强制展开方式继续兼容。
11
+ - **Origin 白名单防误配**:控制台只接受精确 `scheme://host[:port]`,保存时规范化并去重;非白名单浏览器 Origin 在创建任务前返回 403,非法或错误类型配置返回 400。
12
+ - **生态文档发现**:README 增加独立维护的 DeepSeek Harness 社区插件链接;该链接不进入 BailingHub Core,也不代表 DeepSeek 官方开发、认证、背书或采用。
13
+
14
+ ## 安全与信任边界
15
+
16
+ - 表单 Schema 从源 job 的权威最终回复重新读取;服务端同时核对入口、身份、thread 与 `submission_id`,客户端不能用自带 Schema 改写提交规则。
17
+ - 表单不能请求密码、Token、API Key、私钥或支付凭据,也不能改变身份、路由、工具白名单、审批、业务权限或副作用闸门。
18
+ - 普通表单值会按既有聊天语义进入对话总账和模型上下文,部署方仍需执行自己的数据保留、隐私告知与合规策略。
19
+ - Origin 白名单只防浏览器直接盗嵌,不是服务端鉴权。空数组仍表示不限制;不带 Origin 的小程序或服务端请求继续按既有契约放行,需要限制此类调用时应使用签名或业务票据。
20
+ - 自定义或外部 executor 不会自动获得内置 LLM 的表单提示,接入方需要自行遵守同一公开输出契约。
21
+
22
+ ## 兼容性与升级
23
+
24
+ - 公开契约增量到 `bailing.contract.v2.14`;`WIDGET_API` 与 `rendererApiVersion` 仍为 1。
25
+ - 没有新增数据库迁移,最新迁移仍为 `054_demo_dataset_state.sql`。
26
+ - Client API v1、Kernel Host API v1、Executor Protocol、ACC、SDK、工具签名、审批语义与业务系统最终授权保持不变。
27
+ - 既有聊天入口默认保持收起;既有 `allowed_origins: []` 继续表示不限制。需要限制网页嵌入时,应在控制台保存精确来源,不要填写路径、查询参数或通配符。
28
+
29
+ ## 验证
30
+
31
+ 发布门禁覆盖完整 `npm run release:check`、554 项 Core 测试、Widget 真实浏览器交互、控制台构建、双语文档、OSS 边界、安全扫描、Client API 契约与 npm 制品一致性检查。主动表单、提交续轮、刷新恢复、默认展开和非白名单浏览器拒绝也完成了真实端到端验证。
32
+
33
+ ## 相关文档
34
+
35
+ - [公开运行时契约](CONTRACT.md)
36
+ - [Widget 渲染与表单契约](WIDGET_RENDERERS.md)
37
+ - [流式协议](STREAMING.md)
38
+ - [兼容性与升级](兼容性与升级.md)
39
+ - [English release notes](RELEASE_NOTES_v0.4.0.en.md)
@@ -0,0 +1,41 @@
1
+ # BailingHub v0.5.0: Revocable Local-Agent Authorization and Governed Local Planning
2
+
3
+ `v0.5.0` adds Agent Auth v1 and Agent Client Runtime v1. A local Agent may now own understanding, planning, and multi-step tool selection while BailingHub continues to own revocable business identity, route and capability filtering, approvals, idempotency, business invocation, recovery, audit, and the visible conversation ledger. These are optional additive surfaces; they do not replace `/run`, chat entries, or the executor protocol.
4
+
5
+ ## Main changes
6
+
7
+ - **Agent Auth v1**: a local SDK starts browser authorization with PKCE S256 and a locked loopback callback. The business system continues to use its own authenticated session, user/tenant/role model, and permission tables when deciding whether to approve.
8
+ - **Revocable Agent Sessions**: access tokens are short-lived, refresh tokens rotate, and replay of an old refresh token fails closed. Core stores only SHA-256 token digests and supports user denial, local revocation, and business-backend session revocation.
9
+ - **Agent Client Runtime v1**: adds workspace discovery, bounded bootstrap, turn snapshots, authorized capability search, governed tool invocation, and visible completion reporting. Prompts, memory, knowledge, and capability configuration remain centrally managed by Core while planning runs locally.
10
+ - **Exact capability and approval semantics**: an effective workspace is the intersection of the client, Agent Session, route audience, and `tools.agent_direct` policies. `write_tools` explicitly exposes writable operation IDs. Approval continues to inherit business-side ACC by default, while `force_approval_tools` may only tighten the policy.
11
+ - **Visible conversation and governance trace**: user messages, visible final answers, tool requests, and governance outcomes enter the Core ledger. Hidden reasoning is neither accepted, synchronized, nor persisted.
12
+ - **Business-side SDKs**: both the PHP 8.1+ and PHP 7.3-compatible SDKs provide the same server-side `AgentAuth` thin client for context, approve, deny, and session revoke. Non-PHP systems may implement the same HTTP contract directly.
13
+ - **Console configuration**: the route page configures `tools.agent_direct` structurally and reads operation ID, scope, read-only status, and ACC approval metadata from the selected tool provider. Writable-tool allowlists cannot use `*`.
14
+
15
+ ## Security and responsibility boundaries
16
+
17
+ - The authorization page belongs to the business system. The BailingHub SDK provides server-side methods; it does not inject a universal UI or replace business login and final authorization.
18
+ - The Client Token is supplied only to the business backend. It must not enter browser JavaScript, URLs, local-plugin settings, logs, or screenshots. The local Agent also receives no Tool Provider Secret, business password, cookie, business API address, or model key.
19
+ - Agent Auth binds revocable business identity, device, and routes. It carries no plan, payment, entitlement, or usage semantics.
20
+ - Tool invocation still revalidates the session and policy in BailingHub and follows the existing idempotency, approval, uncertain-outcome freezing, and audit paths. Every business tool endpoint must still verify the request signature and current business permission.
21
+ - Host plugins, the generic Agent SDK/MCP package, and model providers are not bundled with BailingHub Core. Install them independently according to their public compatibility matrices.
22
+
23
+ ## Compatibility and upgrade
24
+
25
+ - This release adds `055_agent_auth.sql` and `056_agent_client_runtime.sql`. Back up the state database, upgrade code or images, run `npm run db:init`, and start or switch traffic only after every pending migration succeeds. Never edit an applied migration or copy a state database from another instance.
26
+ - Agent Auth v1 and Agent Client Runtime v1 are additive. Existing `/run`, chat entries, Client API v1, Kernel Host API v1, Executor Protocol, ACC, tickets, tool signatures, and final business authorization remain compatible.
27
+ - Deployments that do not use Agent Client need no authorization page or `tools.agent_direct` configuration. Existing chat-entry and executor flows keep their original behavior.
28
+ - The early private-candidate `unattended_write_tools` field remains read-compatible only. New configuration uses `force_approval_tools`; migrate it with the set-difference rule documented by the public Runtime contract.
29
+
30
+ ## Validation
31
+
32
+ The stable release gate requires the complete `npm run release:check`, type checks, focused Core and Agent Auth/Runtime coverage, console builds, database migration checks, bilingual documentation, OSS-boundary and security scans, npm artifact consistency, and a clean-host acceptance flow using only public dependencies. That acceptance covers browser authorization, a read-only invocation, a reversible write, and conversation/trace inspection. Before publication, both source and actual package artifacts must also be checked for private domains, local paths, credentials, and local dependencies.
33
+
34
+ ## Related documentation
35
+
36
+ - [Agent Client v1 Integration Guide](AGENT_CLIENT_QUICKSTART.en.md)
37
+ - [Agent Auth v1](AGENT_AUTH_API.en.md)
38
+ - [Agent Client Runtime v1](AGENT_CLIENT_RUNTIME_API.en.md)
39
+ - [Business-side PHP SDK](../sdk/php/README.md) / [PHP 7.3 SDK](../sdk/php7/README.md)
40
+ - [Compatibility and upgrade](COMPATIBILITY.en.md)
41
+ - [中文发布说明](RELEASE_NOTES_v0.5.0.md)
@@ -0,0 +1,41 @@
1
+ # BailingHub v0.5.0:可撤销本地 Agent 授权与受治理本地编排
2
+
3
+ `v0.5.0` 新增 Agent Auth v1 与 Agent Client Runtime v1,让本地智能体可以承担理解、规划和多步工具选择,同时继续由 BailingHub 负责可撤销业务身份、route 与能力裁剪、审批、幂等、业务调用、恢复、审计和可见会话总账。这是新增的可选接入面,不替代现有 `/run`、聊天入口或执行器协议。
4
+
5
+ ## 主要变化
6
+
7
+ - **Agent Auth v1**:本地 SDK 使用浏览器、PKCE S256 和锁定的 loopback callback 发起授权;业务系统继续使用自己的登录态、用户/租户/角色与权限表决定是否批准。
8
+ - **可撤销 Agent Session**:access token 短期有效,refresh token 逐次轮换,旧 token 重放失败关闭;Core 只持久化 token 的 SHA-256 摘要,并支持用户拒绝、本地撤销和业务后端按 session 撤销。
9
+ - **Agent Client Runtime v1**:提供 workspace 发现、受限 bootstrap、turn 快照、授权能力搜索、治理工具调用和可见结果回传。提示词、记忆、知识库与能力配置仍由 Core 统一管理,规划在本地完成。
10
+ - **精确能力和审批语义**:有效工作区取接入方、Agent Session、route 受众与 `tools.agent_direct` 的交集。`write_tools` 只精确开放可写 operationId;是否需审批默认继承业务侧 ACC,`force_approval_tools` 只能额外收紧。
11
+ - **可见会话与治理轨迹**:本地编排的用户消息、可见最终回复、工具申请与治理结果进入 Core 总账;不接收、不同步、不持久化 hidden reasoning。
12
+ - **业务侧 SDK**:PHP 8.1+ 与 PHP 7.3 兼容 SDK 都提供同语义的服务端 `AgentAuth` 薄客户端,用于 context、approve、deny 和 session revoke。非 PHP 系统可直接实现同一 HTTP 契约。
13
+ - **控制台配置**:路由页可结构化配置 `tools.agent_direct`,并从选定工具源读取 operationId、scope、只读与 ACC 审批元数据;不允许用 `*` 代替可写工具白名单。
14
+
15
+ ## 安全与责任边界
16
+
17
+ - 业务授权页属于业务系统。BailingHub SDK 只提供服务端方法,不自动注入通用 UI,也不代替业务登录和最终权限判定。
18
+ - Client Token 只交给业务后端;不进入浏览器 JavaScript、URL、本地插件配置、日志或截图。本地 Agent 也不获取 Tool Provider Secret、业务密码、Cookie、业务 API 地址或模型 Key。
19
+ - Agent Auth 只绑定可撤销业务身份、设备和 route,不承载套餐、付费、权益或用量语义。
20
+ - 工具调用仍由 BailingHub 重验会话和权限面,并经过现有幂等、审批、不确定结果冻结与审计路径;业务工具端点每次仍须验签并查当前权限。
21
+ - 本地宿主插件、通用 Agent SDK/MCP 包和模型提供方不包含在 BailingHub Core 制品中,应按各自公开兼容矩阵独立安装。
22
+
23
+ ## 兼容性与升级
24
+
25
+ - 新增 `055_agent_auth.sql` 和 `056_agent_client_runtime.sql`。升级前备份状态库,升级代码或镜像后运行 `npm run db:init`,确认所有未应用 migration 成功后再启动或切流。不得修改已应用 migration 或从其他实例复制状态库。
26
+ - Agent Auth v1 和 Agent Client Runtime v1 是增量接口。原有 `/run`、聊天入口、Client API v1、Kernel Host API v1、Executor Protocol、ACC、票据、工具签名和业务最终授权语义保持兼容。
27
+ - 不使用 Agent Client 的部署无需配置授权页或 `tools.agent_direct`;现有聊天入口和执行器继续按原路径运行。
28
+ - 早期私有候选的 `unattended_write_tools` 仅保留兼容读取。新配置使用 `force_approval_tools`,迁移时按公开 Runtime 文档的差集规则处理。
29
+
30
+ ## 验证
31
+
32
+ 稳定发布门禁要求完整 `npm run release:check`、类型检查、Core 与 Agent Auth/Runtime 定向测试、控制台构建、数据库迁移、双语文档、OSS 边界、安全扫描、npm 制品一致性,以及从干净宿主安装公开依赖后完成浏览器授权、只读调用、可回滚写入、会话与轨迹回查。发布前还必须检查源码与实际包制品不包含私有域名、本机路径、凭据或本地依赖。
33
+
34
+ ## 相关文档
35
+
36
+ - [Agent Client v1 接入指南](AGENT_CLIENT_QUICKSTART.md)
37
+ - [Agent Auth v1](AGENT_AUTH_API.md)
38
+ - [Agent Client Runtime v1](AGENT_CLIENT_RUNTIME_API.md)
39
+ - [业务侧 PHP SDK](../sdk/php/README.md) / [PHP 7.3 SDK](../sdk/php7/README.md)
40
+ - [兼容性与升级](兼容性与升级.md)
41
+ - [English release notes](RELEASE_NOTES_v0.5.0.en.md)
@@ -63,6 +63,38 @@ Reverse proxies and CDNs must disable response buffering, preserve `text/event-s
63
63
  - Existing clients may ignore `phase`, `reset`, and `delta` and wait for `done`.
64
64
  - New clients must treat `done`, not accumulated fragments, as the final authoritative value.
65
65
 
66
+ ### 7.1 Presentation capability negotiation
67
+
68
+ A custom client may advertise only the declarative renderers it has actually
69
+ installed and validated:
70
+
71
+ ```json
72
+ {
73
+ "client_capabilities": {
74
+ "renderers": ["bailing-chart", "bailing-form"]
75
+ }
76
+ }
77
+ ```
78
+
79
+ This affects optional model presentation guidance only. It is not an SSE
80
+ field and cannot change identity, authorization, approval, or tool access.
81
+ Charts and forms remain fenced content inside `done.reply`; never mount either
82
+ from provisional `delta` text. Apply the allowlist and fallback rules in
83
+ [WIDGET_RENDERERS.en.md](WIDGET_RENDERERS.en.md) only after `done`.
84
+
85
+ ### 7.2 A form response does not add stream states
86
+
87
+ A `bailing-form` is final declarative content in `done.reply`. Its source job
88
+ is already terminal; it never enters a waiting-for-input or `input_required`
89
+ state. Submit or cancel makes a new `POST /chat/:entry_key`, creating a new job
90
+ in the same thread. That new job uses the existing
91
+ `open/status/phase/reset/delta/ping/done/failed/timeout` event set.
92
+
93
+ Retain the source `done.job_id` as `source_job_id` and subscribe separately to
94
+ the new job. Do not keep or resume the closed source-job stream. Cross-device
95
+ receipt recovery comes from the durable `/thread` ledger, not the incremental
96
+ replay window.
97
+
66
98
  ## 8. Validation
67
99
 
68
100
  ```bash
package/docs/STREAMING.md CHANGED
@@ -87,12 +87,18 @@
87
87
  ```json
88
88
  {
89
89
  "client_capabilities": {
90
- "renderers": ["bailing-chart"]
90
+ "renderers": ["bailing-chart", "bailing-form"]
91
91
  }
92
92
  }
93
93
  ```
94
94
 
95
- 该字段只影响模型收到的可选展示提示,不进入 SSE 事件,不构成身份、授权、审批或工具权限。富内容仍属于 `done.reply` 的一部分;客户端不得在 `delta` 阶段挂载图表,应在 `done` 后按 [`WIDGET_RENDERERS.md`](WIDGET_RENDERERS.md) 的白名单与失败降级规则处理完整 fenced code block。
95
+ 该字段只影响模型收到的可选展示提示,不进入 SSE 事件,不构成身份、授权、审批或工具权限。富内容仍属于 `done.reply` 的一部分;客户端不得在 `delta` 阶段挂载图表或表单,应在 `done` 后按 [`WIDGET_RENDERERS.md`](WIDGET_RENDERERS.md) 的白名单与失败降级规则处理完整 fenced code block。
96
+
97
+ ### 7.2 表单回传不改变流式状态机
98
+
99
+ `bailing-form` 是 `done.reply` 中的最终声明式内容。源 job 输出表单后已经终态 `done`,不会进入“等待填写”或 `input_required`。用户提交/取消表单时,客户端向同一聊天入口发起新 `POST /chat/:entry_key`;服务端在同 thread 创建新 job,该 job 仍使用本文现有的 `open/status/phase/reset/delta/ping/done/failed/timeout` 集合。
100
+
101
+ 因此客户端要保留源 `done.job_id` 作为回传的 `source_job_id`,另外订阅新 job 的 SSE;不得继续占用或恢复源 job 的已关闭连接。表单回执的跨设备恢复来自 `/thread` 权威总账,不来自增量回放窗口。
96
102
 
97
103
  ## 8. 验证
98
104
 
@@ -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 an optional trusted renderer registry, keeping the core widget free of third-party runtime dependencies.
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
- - Renderers are installed and registered by the embedding application and are therefore trusted host code.
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.
@@ -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
-
@@ -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. 复制嵌入代码。
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bailinghub",
3
- "version": "0.3.4",
3
+ "version": "0.5.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Open-source ACC runtime and agent control plane for existing business systems.",
@@ -71,6 +71,7 @@
71
71
  "package:artifact:check": "node scripts/check-package-artifact.mjs",
72
72
  "prepack": "npm run package:build",
73
73
  "security:scan": "node scripts/security-scan.mjs",
74
+ "public-content:denylist:test": "node --test scripts/public-content-denylist.test.mjs",
74
75
  "notices:generate": "node scripts/generate-third-party-notices.mjs",
75
76
  "notices:check": "node scripts/generate-third-party-notices.mjs --check",
76
77
  "assets:generate": "node scripts/generate-readme-assets.mjs",
@@ -87,7 +88,7 @@
87
88
  "oss:verify": "node scripts/verify-oss-export.mjs",
88
89
  "release:consistency": "node scripts/check-release-consistency.mjs",
89
90
  "release:consistency:test": "node --test scripts/check-release-consistency.test.mjs",
90
- "release:audit": "npm run release:consistency && npm run release:consistency:test && npm run images:policy:test && npm run security:scan && npm run oss:guard && node scripts/release-audit.mjs && npm run package:artifact:check",
91
+ "release:audit": "npm run release:consistency && npm run release:consistency:test && npm run images:policy:test && npm run public-content:denylist:test && npm run security:scan && npm run oss:guard && node scripts/release-audit.mjs && npm run package:artifact:check",
91
92
  "github:verify": "node scripts/verify-github-repo.mjs",
92
93
  "release:check": "npm run notices:check && npm run assets:check && npm run audit:deps && npm run client-api:contract && npm run client-api:ecosystem:clone && npm run typecheck && npm test && npm run widget:renderer:test && npm run web-admin:check && npm run docs:check && npm run examples:check && npm run sdk:test && npm run sdk:test7 && npm run sdk:test-node && npm run sdk:test-python && npm run sdk:test-runtime && npm run sdk:test-p1 && npm run release:audit && npm run oss:verify && npm run github:verify",
93
94
  "images:build": "sh scripts/publish-images.sh",
@@ -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"] },
@@ -17,6 +17,13 @@
17
17
  "title": "名称",
18
18
  "description": "后台展示的人类可读名称。"
19
19
  },
20
+ "agent_authorize_url": {
21
+ "type": "string",
22
+ "format": "uri",
23
+ "maxLength": 2048,
24
+ "title": "Agent 授权页",
25
+ "description": "可选。本地 Agent 发起登录时打开的业务系统授权页 URL;未配置时不开放 Agent Auth。"
26
+ },
20
27
  "allowed_routes": {
21
28
  "type": "array",
22
29
  "items": { "type": "string", "minLength": 1 },