bailinghub 0.8.0 → 0.9.1

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 (209) hide show
  1. package/.dockerignore +6 -0
  2. package/.npmignore +6 -0
  3. package/CONTRIBUTING.md +4 -0
  4. package/GOVERNANCE.md +9 -0
  5. package/README.en.md +8 -6
  6. package/README.md +8 -6
  7. package/SECURITY.md +8 -2
  8. package/THIRD_PARTY_NOTICES.md +17 -17
  9. package/docker-compose.images.yml +2 -2
  10. package/docs/ARCHITECTURE.md +1 -1
  11. package/docs/CHANGELOG.en.md +22 -1
  12. package/docs/CHANGELOG.md +22 -1
  13. package/docs/COMPATIBILITY.en.md +8 -0
  14. package/docs/IMPLEMENTATION_STATUS.en.md +73 -0
  15. package/docs/IMPLEMENTATION_STATUS.md +73 -0
  16. package/docs/INDEPENDENT_VALIDATION.en.md +4 -4
  17. package/docs/INDEPENDENT_VALIDATION.md +4 -4
  18. package/docs/KERNEL_HOST_API.en.md +18 -0
  19. package/docs/KERNEL_HOST_API.md +18 -0
  20. package/docs/MODEL_BILLING.en.md +123 -0
  21. package/docs/MODEL_BILLING.md +125 -0
  22. package/docs/PERIOD_ALLOWANCE_UPGRADE.en.md +31 -0
  23. package/docs/PERIOD_ALLOWANCE_UPGRADE.md +31 -0
  24. package/docs/README.en.md +8 -1
  25. package/docs/README.md +7 -0
  26. package/docs/RELEASE_NOTES_NEXT.en.md +4 -2
  27. package/docs/RELEASE_NOTES_NEXT.md +4 -2
  28. package/docs/RELEASE_NOTES_v0.9.0.en.md +45 -0
  29. package/docs/RELEASE_NOTES_v0.9.0.md +45 -0
  30. package/docs/RELEASE_NOTES_v0.9.1.en.md +38 -0
  31. package/docs/RELEASE_NOTES_v0.9.1.md +38 -0
  32. package/docs/UPGRADE_v0.9.0.en.md +54 -0
  33. package/docs/UPGRADE_v0.9.0.md +54 -0
  34. package/docs/UPGRADE_v0.9.1.en.md +39 -0
  35. package/docs/UPGRADE_v0.9.1.md +39 -0
  36. package/docs//345/205/274/345/256/271/346/200/247/344/270/216/345/215/207/347/272/247.md +8 -0
  37. package/package.json +5 -4
  38. package/scripts/check-doc-links.mjs +6 -0
  39. package/scripts/check-image-tags.sh +1 -1
  40. package/scripts/check-release-consistency.test.mjs +2 -2
  41. package/scripts/dependency-audit.mjs +134 -0
  42. package/scripts/dependency-audit.test.mjs +125 -0
  43. package/scripts/install.sh +1 -1
  44. package/scripts/osps-results.py +114 -0
  45. package/scripts/publish-images.sh +1 -1
  46. package/scripts/release-audit.mjs +2 -0
  47. package/scripts/sdk-runtime-test.mjs +6 -0
  48. package/scripts/verify-billing-install-upgrade.mjs +225 -0
  49. package/scripts/verify-github-repo.mjs +2 -0
  50. package/sdk/node/README.md +17 -0
  51. package/sdk/node/examples/billing.mjs +21 -0
  52. package/sdk/node/package.json +5 -1
  53. package/sdk/node/src/index.mjs +2 -0
  54. package/sdk/node/src/usage.d.mts +74 -0
  55. package/sdk/node/src/usage.mjs +62 -0
  56. package/sdk/node/tests/usage-types.mts +23 -0
  57. package/sdk/node/tests/usage.test.mjs +81 -0
  58. package/sdk/php7/README.md +19 -2
  59. package/sdk/php7/examples/billing.php +27 -0
  60. package/sdk/php7/examples/well-known.php +1 -1
  61. package/sdk/php7/src/ToolSpec.php +1 -1
  62. package/sdk/php7/src/UsageClient.php +95 -0
  63. package/sdk/php7/src/UsageClientException.php +22 -0
  64. package/sdk/php7/tests/billing-core-http.php +59 -0
  65. package/sdk/php7/tests/usage-client.php +78 -0
  66. package/security/dependency-audit-exceptions.json +192 -0
  67. package/sql/063_usage_model_billing.sql +153 -0
  68. package/sql/064_period_plan_allowance.sql +25 -0
  69. package/sql/README.en.md +12 -4
  70. package/sql/README.md +14 -6
  71. package/src/app/auth.ts +2 -0
  72. package/src/app/kernel-usage-lifecycle.mysql.test.ts +325 -0
  73. package/src/app/kernel.ts +10 -0
  74. package/src/app/oss-edition.ts +1 -0
  75. package/src/infrastructure/config/configstore.ts +6 -0
  76. package/src/modules/usage/allowance-reset.mysql.test.ts +122 -0
  77. package/src/modules/usage/background-work.test.ts +144 -0
  78. package/src/modules/usage/background-work.ts +50 -0
  79. package/src/modules/usage/billing-contracts.ts +59 -0
  80. package/src/modules/usage/billing-decimal.test.ts +22 -0
  81. package/src/modules/usage/billing-decimal.ts +36 -0
  82. package/src/modules/usage/billing-external.ts +39 -0
  83. package/src/modules/usage/billing-gateway.mysql.test.ts +24 -0
  84. package/src/modules/usage/billing-ledger.test.ts +51 -0
  85. package/src/modules/usage/billing-ledger.ts +104 -0
  86. package/src/modules/usage/billing-presentation.mysql.test.ts +95 -0
  87. package/src/modules/usage/billing-presentation.test.ts +49 -0
  88. package/src/modules/usage/billing-presentation.ts +34 -0
  89. package/src/modules/usage/billing-prices.mysql.test.ts +88 -0
  90. package/src/modules/usage/billing-repository.mysql.test.ts +181 -0
  91. package/src/modules/usage/billing-repository.ts +465 -0
  92. package/src/modules/usage/contracts.ts +49 -0
  93. package/src/modules/usage/dynamic-plan-models.mysql.test.ts +221 -0
  94. package/src/modules/usage/errors.ts +19 -0
  95. package/src/modules/usage/http.ts +85 -0
  96. package/src/modules/usage/identity-revocation.mysql.test.ts +286 -0
  97. package/src/modules/usage/identity.mysql.test.ts +120 -0
  98. package/src/modules/usage/identity.ts +303 -0
  99. package/src/modules/usage/issuer-sdk-billing.mysql.test.ts +92 -0
  100. package/src/modules/usage/model-gateway.mysql.test.ts +207 -0
  101. package/src/modules/usage/model-gateway.ts +236 -0
  102. package/src/modules/usage/model-tool-gateway.mysql.test.ts +137 -0
  103. package/src/modules/usage/model-tool-provider.test.ts +37 -0
  104. package/src/modules/usage/model-tool-provider.ts +110 -0
  105. package/src/modules/usage/model-tools.test.ts +36 -0
  106. package/src/modules/usage/model-tools.ts +62 -0
  107. package/src/modules/usage/period-allowance.mysql.test.ts +97 -0
  108. package/src/modules/usage/period.test.ts +26 -0
  109. package/src/modules/usage/period.ts +96 -0
  110. package/src/modules/usage/pricing.test.ts +178 -0
  111. package/src/modules/usage/pricing.ts +229 -0
  112. package/src/modules/usage/provider-failure.ts +37 -0
  113. package/src/modules/usage/provider-stream.test.ts +85 -0
  114. package/src/modules/usage/provider-stream.ts +77 -0
  115. package/src/modules/usage/provider.test.ts +67 -0
  116. package/src/modules/usage/provider.ts +142 -0
  117. package/src/modules/usage/repository.ts +541 -0
  118. package/src/modules/usage/service-availability.mysql.test.ts +68 -0
  119. package/src/modules/usage/service-availability.ts +13 -0
  120. package/src/modules/usage/service-delete.mysql.test.ts +87 -0
  121. package/src/modules/usage/stream-http.ts +32 -0
  122. package/src/modules/usage/test-harness.ts +109 -0
  123. package/src/modules/usage/usage-deletion.mysql.test.ts +312 -0
  124. package/src/modules/usage/usage-deletion.ts +119 -0
  125. package/src/modules/usage/validation.test.ts +18 -0
  126. package/src/modules/usage/validation.ts +33 -0
  127. package/src/routes/admin-billing-usage.ts +73 -0
  128. package/src/routes/admin-usage.ts +147 -0
  129. package/src/routes/admin.ts +4 -0
  130. package/src/routes/private.ts +8 -0
  131. package/web/connect/bailing-connect-php7.tgz +0 -0
  132. package/web/console/assets/Accounts-Bervi5JU.css +1 -0
  133. package/web/console/assets/Accounts-DKhw_QLr.js +3 -0
  134. package/web/console/assets/{AgentClients-Bf7sUUs_.js → AgentClients-CM4_5HaA.js} +1 -1
  135. package/web/console/assets/AgentTasks-BsG850Il.css +1 -0
  136. package/web/console/assets/AgentTasks-CkQgZTU5.js +2 -0
  137. package/web/console/assets/{Approvals-BIbZvInm.js → Approvals-B9O9TkbO.js} +1 -1
  138. package/web/console/assets/{Audit-KyPSmBdZ.js → Audit-2vDC1SPu.js} +1 -1
  139. package/web/console/assets/{BrandLockup-Sv5DU2G6.js → BrandLockup-BgASiRSE.js} +1 -1
  140. package/web/console/assets/{Channels-B9n4fbxg.js → Channels-A-GvkNBt.js} +1 -1
  141. package/web/console/assets/{ChatEntries-xsOCUXi_.js → ChatEntries-BLxymI67.js} +1 -1
  142. package/web/console/assets/{Clients-CI3DBDHf.js → Clients-DeNlmvS6.js} +1 -1
  143. package/web/console/assets/{Cost-JgNXQPlN.js → Cost-CBq_L4Kz.js} +1 -1
  144. package/web/console/assets/{Credentials-B5UUUdt0.js → Credentials-DmtbctNj.js} +1 -1
  145. package/web/console/assets/{Diagnostics-BMGciWQb.js → Diagnostics-BbcRDiA-.js} +1 -1
  146. package/web/console/assets/{Executors-CRbboOCZ.js → Executors-gGgmQrDt.js} +1 -1
  147. package/web/console/assets/{HelpTip-i-KJhf5s.js → HelpTip-Dtdt2tKR.js} +1 -1
  148. package/web/console/assets/{Kb-CgLNGjRp.js → Kb-lgY6OXUz.js} +2 -2
  149. package/web/console/assets/{Login-C52JmXzx.js → Login-DA6BASZd.js} +1 -1
  150. package/web/console/assets/{Projects-CDOvHPVS.js → Projects-DEbmB_sT.js} +1 -1
  151. package/web/console/assets/Routes-CyXV4Pba.css +1 -0
  152. package/web/console/assets/Routes-qS6LLoyS.js +124 -0
  153. package/web/console/assets/{Runs-DYNDXsqk.js → Runs-DG-VLRSc.js} +1 -1
  154. package/web/console/assets/{Setup-B91P6i1x.js → Setup-DEpVF5uw.js} +1 -1
  155. package/web/console/assets/Shell-DgoPgK1E.js +1 -0
  156. package/web/console/assets/Shell-ykb-tUfo.css +1 -0
  157. package/web/console/assets/{StorageBuckets-DkuDM0oX.js → StorageBuckets-DJtNN769.js} +1 -1
  158. package/web/console/assets/{SystemSettings-B7Mqj3k1.js → SystemSettings-0DEUgeTR.js} +1 -1
  159. package/web/console/assets/{SystemStatus-Db93b6dc.js → SystemStatus-CR1phiPE.js} +1 -1
  160. package/web/console/assets/{Targets-CuuIYeZO.js → Targets-D65l-IMB.js} +1 -1
  161. package/web/console/assets/{Tools-CHiqz9XZ.js → Tools-DqtrINrN.js} +1 -1
  162. package/web/console/assets/Usage-B5njXNjx.js +1 -0
  163. package/web/console/assets/Usage-CAeDGjrb.css +1 -0
  164. package/web/console/assets/UsageAccess-CGGaWTuj.css +1 -0
  165. package/web/console/assets/UsageAccess-ChnB4pjb.js +1 -0
  166. package/web/console/assets/UsageHelp-BBKIvbQ5.js +1 -0
  167. package/web/console/assets/UsageHelp-CSM4xO0K.css +1 -0
  168. package/web/console/assets/{index-QnmD7N7F.js → index-65JiiUr4.js} +1 -1
  169. package/web/console/assets/{index-Fi9gkGxV.css → index-Cxuc9OCj.css} +1 -1
  170. package/web/console/assets/index-sLKrJd_p.js +2 -0
  171. package/web/console/assets/{request-DeGya810.js → request-BpaimqEb.js} +1 -1
  172. package/web/console/assets/{schema-BqlqLw1R.js → schema-D0Z4kFCZ.js} +1 -1
  173. package/web/console/assets/{util-4bN2dv7B.js → util-DZYfJ5Zo.js} +1 -1
  174. package/web/console/assets/{vendor-element-CZoEjZr8.js → vendor-element-8cVcdt5T.js} +2 -2
  175. package/web/console/assets/{vendor-mammoth-BUEEDX6A.js → vendor-mammoth-CnDA23N0.js} +1 -1
  176. package/web/console/assets/vendor-vue-Co7x2FW6.js +29 -0
  177. package/web/console/index.html +4 -4
  178. package/web-admin/README.md +17 -0
  179. package/web-admin/package-lock.json +83 -85
  180. package/web-admin/src/components/UsageDeletionPreview.vue +44 -0
  181. package/web-admin/src/components/UsageHelp.vue +72 -0
  182. package/web-admin/src/components/UsageServiceReferences.vue +169 -0
  183. package/web-admin/src/layout/Shell.vue +22 -5
  184. package/web-admin/src/pages/Accounts.vue +3 -3
  185. package/web-admin/src/pages/AgentTasks.vue +2 -2
  186. package/web-admin/src/pages/Routes.vue +5 -1
  187. package/web-admin/src/pages/Usage.vue +2470 -0
  188. package/web-admin/src/pages/UsageAccess.vue +1147 -0
  189. package/web-admin/src/router.ts +8 -4
  190. package/web-admin/src/styles/base.css +57 -0
  191. package/web-admin/src/table-widths.ts +16 -1
  192. package/web-admin/src/usage-deletion.ts +40 -0
  193. package/web-admin/src/usage-management.ts +13 -0
  194. package/web-admin/src/usage-presentation.test.ts +21 -0
  195. package/web-admin/src/usage-presentation.ts +107 -0
  196. package/web-admin/src/usage-price-preview.test.ts +60 -0
  197. package/web-admin/src/usage-price-preview.ts +54 -0
  198. package/web-admin/tests/token-usage.browser.mjs +773 -0
  199. package/web-admin/tests/usage-access.browser.mjs +398 -0
  200. package/web/console/assets/Accounts-B4ePH5jp.css +0 -1
  201. package/web/console/assets/Accounts-BRCR3O0P.js +0 -3
  202. package/web/console/assets/AgentTasks--bqL_QKg.js +0 -2
  203. package/web/console/assets/AgentTasks-C8ox3TyS.css +0 -1
  204. package/web/console/assets/Routes-DkMIjMQA.css +0 -1
  205. package/web/console/assets/Routes-X9vHLpKW.js +0 -124
  206. package/web/console/assets/Shell-Bj6C8Hgo.css +0 -1
  207. package/web/console/assets/Shell-BsRa7bQQ.js +0 -1
  208. package/web/console/assets/index-UGvfF3Xr.js +0 -2
  209. package/web/console/assets/vendor-vue-B2uhHUfE.js +0 -29
@@ -0,0 +1,45 @@
1
+ # 百灵中枢 v0.9.0:模型服务与统一套餐额度
2
+
3
+ 版本:**Core 0.9.0 / MCP 与 Agent Client SDK 0.7.0 / DSH 0.7.0**。本页说明相对公开 Core 0.8.0 的变化与升级影响。
4
+
5
+ 企业业务助手需要在对话中选择模型、生成活动图片,再调用已获授权的业务接口。管理员现在可以为这些模型与生成工具配置一份共享额度;本地宿主继续负责对话和任务编排,中枢记录原请求、计量及结算,原业务权限与审批继续生效。
6
+
7
+ ## 可选的微型模型计费网关
8
+
9
+ 模型计费按需启用。管理员配置模型连接、实际调用型号、参考计价模型与端点,再创建套餐并开通给个人或组织共享账户。对话模型与模型工具进入独立目录,宿主按能力发现接入;中枢不按用户轮次或任务步数收费。
10
+
11
+ 实际调用型号可以与参考目录中的型号不同,管理员需要显式核对映射。参考价格来自 OpenRouter,**不代表实际模型供应商的实付价格或账单**。每个请求保留参考价格和套餐倍率快照,后续调价不重算历史请求。配置未就绪的服务不会进入可调用目录,宿主可读取原因并提示联系管理员。
12
+
13
+ ## 一个套餐、一份 USD 额度
14
+
15
+ 套餐统一使用 USD 计量,同一套餐内所有模型与工具共用额度与一个倍率。例如“企业服务助手”月套餐售价 300 USD,每月额度 100 USD,倍率 1.5;一次请求参考费用 0.20 USD,结算扣除 0.30 USD,实际剩余额度占比为 99.70%。
16
+
17
+ - **周期套餐**:售价 `priceUsd` 与每周期额度 `periodAllowanceUsd` 分开设置。按日、周或月恢复额度,客户显示剩余百分比;分母是周期额度。
18
+ - **额度包**:`priceUsd` 提供一次性 USD 额度,客户显示 Credits(积分),固定 1 USD = 1000 Credits。没有独立积分账本。
19
+ - 有效期与重置周期分开,最后不足一个完整周期仍提供完整额度,到期停止新请求,未用额度不结转。模板改价不会重置已开通账户的原额度条款;当前模型集合和统一倍率按套餐读取。
20
+ - 支付、汇率、退款及商品定价由业务侧处理。原始 Token 是用量记录,不是套餐上限或百分比分母。
21
+
22
+ ## 文生图与异步结算
23
+
24
+ 模型工具声明名称、用途、参数及输出,宿主负责选择并调用。首批可执行适配为阿里云 OpenAI Images 兼容接口、DashScope 原生接口和 OpenRouter Images 接口的文生图。视频、语音与自定义能力可以保存声明;没有执行适配时明确不可调用,不表示已支持生成。
25
+
26
+ 图片请求保存派发记录后异步完成,宿主用原 `operation_id` 查询结果。结果完成即可使用,计费可能仍在等待实际计量;缺少可信计量不猜测费用或伪造 Token。余额为正时允许新请求,并发晚结算可能产生超额,余额耗尽后阻止新请求。
27
+
28
+ 断网、回包丢失或结果未知时保持原 ID,不另建生成请求。明确拒绝与结果未知分开展示;取消后的晚到结果仍可记录用量,不恢复已结束轮次。图片 URL/Base64 可由宿主按需写入已有附件空间,生成成功不会自动修改业务数据。
29
+
30
+ ## 后台日常管理
31
+
32
+ - 套餐移除保留原 ID、历史开通、额度池、请求及账本;仍被有效开通使用的套餐需要先处理使用关系。停用模板只停止新开通。
33
+ - 个人账户和组织共享账户停用后可移除归档;恢复回原账户的停用状态,旧凭证与被撤销成员不恢复,额度不补发。
34
+ - 有权限的管理员可为启用账户手动重置中枢维护的有效套餐:周期套餐恢复到原周期额度并重新起算周期,额度包恢复原始积分。到期时间不延长;原在途请求仍向原额度池结算。
35
+ - 控制台的接入示例使用通用业务助手和企业服务描述,便于各类业务系统复用。
36
+
37
+ ## 升级影响与验收
38
+
39
+ 从公开 Core 0.8.0 升级时,通过正式迁移器应用新增的 `063_usage_model_billing.sql` 和 `064_period_plan_allowance.sql`,保留原数据和迁移账本。**正常公开版升级不要求清退真实数据或旧测试数据。** 已部署过计费预览的实例另按[周期额度说明](PERIOD_ALLOWANCE_UPGRADE.md)核对原快照。
40
+
41
+ 客户端宿主按需接入模型目录、工具、摘要与原请求持久记录;业务后端仅在需要开通套餐或提供套餐范围身份时接入对应接口。只使用既有业务工具的部署无需开启模型计费。原身份、权限、会话范围、审批、长任务控制与业务调用归档保持独立。
42
+
43
+ 验收应覆盖所启用的服务配置、额度展示、实际计量、原 ID 查询及管理操作,并核对最终制品与配套版本。自动化通过不等于供应商、客户端或生产环境的实际验收。
44
+
45
+ [配套升级指南](UPGRADE_v0.9.0.md) · [模型服务与套餐计费](MODEL_BILLING.md) · [English](RELEASE_NOTES_v0.9.0.en.md)
@@ -0,0 +1,38 @@
1
+ # v0.9.1: asynchronous model shutdown and public capability evidence
2
+
3
+ [中文版](RELEASE_NOTES_v0.9.1.md)
4
+
5
+ After an assistant requests an image, the Hub promptly returns the original request's pending state. Provider completion and usage settlement follow later. If a host evicts an instance, upgrades, or exits at that point, a finished HTTP request does not mean its background work is finished.
6
+
7
+ Core 0.9.1 fixes that shutdown boundary by waiting for the original instance's usage background work and subsequent settlement before closing resources. It also includes a public capability index and general security governance already on main. This is a patch release with **no new HTTP/API, SQL migration, plan rule, client feature, or SDK/DSH release**.
8
+
9
+ ## Shutdown fix
10
+
11
+ - Each `UsageRepository` separately registers model-tool completion, settlement after ordinary model responses, response cleanup, pending-usage reconciliation, and reference-price refresh through persistence.
12
+ - Kernel stops new HTTP admission and waits for foreground handlers, InHub, and execution queues to finish registering work. It then stops new usage work/maintenance and dynamically drains accepted completion and late settlement children before resource closure.
13
+ - All stages share the original `close(drainMs)` deadline. A usage-drain timeout preserves the original dependencies and closing state for same-instance retry; it does not redispatch a model request or business write.
14
+ - Image requests still promptly return HTTP 202. Ordinary text results also arrive before financial settlement. Original `operation_id` values, separate result/billing states, business authority, approvals, and unknown-outcome handling remain unchanged.
15
+ - Failed background work can retain durable pending/unknown evidence. Completed drain does not guarantee every record is settled or provide process-crash recovery or provider-task recovery.
16
+
17
+ The formal v0.9.0 close path did not explicitly register these usage continuations. Its Tag and existing artifacts remain unchanged; this fix does not rewrite their historical guarantees. See the [Kernel Host API](KERNEL_HOST_API.en.md) and [capability/evidence index](IMPLEMENTATION_STATUS.en.md).
18
+
19
+ ## Public documentation and general security governance
20
+
21
+ The new Chinese/English capability index separates Core, business-system, local-host, and independent-adapter responsibilities, release facts, public test/reproduction paths, and uncovered scope. Thread context, visible conversation audits, and complete user-level long-term memory remain distinct. Existing tests are not presented as production adoption.
22
+
23
+ This release also includes dependency auditing with explicit exception checks, pinned GitHub Actions sources and minimal permissions, dependency-update and repository scanning configuration, plus public security self-assessments and Security Insights metadata. Assessments/metadata are repository governance and excluded from npm runtime packages and Docker build contents. Their existence does not establish that every control passes or that no residual risks remain.
24
+
25
+ ## Upgrade impact
26
+
27
+ - Upgrading public Core 0.9.0 adds no SQL files and changes no existing migrations. Earlier versions still require their outstanding migrations; see the [upgrade guide](UPGRADE_v0.9.1.en.md).
28
+ - USD allowances, the uniform multiplier, periodic price/allowance, model catalogs, and business-governance contracts remain unchanged. This patch does not require new plan grants or replacement request IDs.
29
+ - Continue using **MCP / Agent Client SDK 0.7.0 and DSH 0.7.0**. Independent packages are not republished solely for this patch. Business declarations, signatures, authorization, and approval code need no patch-specific rewrite.
30
+ - Embedded hosts should read the new Core artifact's version and complete manifest, and continue using its public tick/close entry points. A Core artifact upgrade does not establish that hosts or clients have been upgraded, deployed, or accepted.
31
+
32
+ ## Validation scope
33
+
34
+ [Tracker unit tests](../src/modules/usage/background-work.test.ts) check registration/drain mechanisms. [Actual Kernel + MySQL lifecycle tests](../src/app/kernel-usage-lifecycle.mysql.test.ts) check real Kernels, database transactions, and HTTP/standalone shutdown wiring. They cover delayed completion, late settlement, SQL locks, same-instance retry, two-Kernel isolation, ordinary text asynchronous settlement, independent cleanup/reconciliation, price persistence, and failed settlement retaining original results without redispatch.
35
+
36
+ Database cases require `BAILING_USAGE_TEST_MYSQL=1` and their dedicated test MySQL; providers and business data are synthetic. Test source or skipped tests are not passing runs. Real providers, business APIs, and deployments require their own acceptance. This page makes no production-adoption, comprehensive model-quality, or complete failure-recovery claim.
37
+
38
+ [Upgrade guide](UPGRADE_v0.9.1.en.md) · [Changelog](CHANGELOG.en.md) · [Previous release](RELEASE_NOTES_v0.9.0.en.md)
@@ -0,0 +1,38 @@
1
+ # v0.9.1:异步模型工作关闭与公开能力证据
2
+
3
+ [English](RELEASE_NOTES_v0.9.1.en.md)
4
+
5
+ 业务助手请求生成图片后,中枢会先返回原请求的 pending 状态,供应商响应和用量结算随后完成。如果宿主此时淘汰实例、升级或退出进程,不能把 HTTP 请求已经结束当成后台工作也已结束。
6
+
7
+ Core 0.9.1 修复这一关闭边界:在关闭资源前,等待属于原实例的 usage 后台工作及其后续结算。它还纳入公开能力索引和此前主分支的通用安全治理。本版是补丁版本,**没有新增 HTTP/API、SQL 迁移、套餐规则、客户端功能或 SDK/DSH 发行**。
8
+
9
+ ## 关闭修复
10
+
11
+ - 每个 `UsageRepository` 独立登记模型工具完成、普通模型响应后的结算、响应清理、待结算 usage 核对,以及参考价格刷新到持久化结束的工作。
12
+ - Kernel 先停止新 HTTP 接入,等待前台、InHub 和执行队列完成登记,再停止新 usage 工作和维护;动态排空已接纳的完成及晚登记的结算子工作后才关闭资源。
13
+ - 所有阶段共用原 `close(drainMs)` 时限。usage 排空超时会保留原实例依赖和关闭状态,供宿主在同一实例重试;不因此重新派发模型或业务写入。
14
+ - 图片首次响应仍及时返回 HTTP 202;普通文本结果也不等待财务结算再交付。原 `operation_id`、结果/计费状态分离、业务权限、审批和未知结果处理不变。
15
+ - 失败后台工作仍可能留下 durable pending/unknown 证据。排空结束不保证所有记录已经 settled,也不提供进程崩溃恢复或供应商任务恢复保证。
16
+
17
+ 正式 v0.9.0 的关闭路径没有显式登记这些 usage continuation;该 Tag 和已有制品保持原样。修复不回写其历史保证。完整语义见 [Kernel Host API](KERNEL_HOST_API.md) 和 [能力与证据索引](IMPLEMENTATION_STATUS.md)。
18
+
19
+ ## 公开文档与通用安全治理
20
+
21
+ 新增中英能力与证据索引,分别说明 Core、业务系统、本地宿主和独立适配层的职责,以及发行事实、公开测试/复现路径和未覆盖范围。线程上下文、可见对话审计与完整用户级长期记忆分别说明,不把已有测试扩展为生产采用证明。
22
+
23
+ 本版同时纳入依赖审计与显式例外检查、固定 GitHub Actions 来源和最小权限、依赖更新及仓库安全扫描配置,以及公开安全自评和 Security Insights 元数据。自评/元数据属于仓库治理,排除在 npm 运行包和 Docker 构建内容之外;治理资料存在不意味着全部安全控制通过或没有残余风险。
24
+
25
+ ## 升级影响
26
+
27
+ - 从公开 Core 0.9.0 升级,没有新增 SQL 文件,不改变已有迁移内容。更早版本仍须应用其未执行迁移,见 [升级指南](UPGRADE_v0.9.1.md)。
28
+ - 原有 USD 额度、统一倍率、周期售价/额度、模型目录和业务治理契约保持。无需为本补丁重新开通套餐或改变原请求标识。
29
+ - 使用既有 **MCP / Agent Client SDK 0.7.0、DSH 0.7.0**;不机械重发独立包。业务后端的声明、验签、授权和审批代码无须为本补丁改写。
30
+ - 嵌入式宿主应读取新 Core 制品的版本及完整 manifest,并继续调用其公开 tick/close 入口。Core 制品升级不证明宿主或客户端已经升级、部署或验收。
31
+
32
+ ## 验证范围
33
+
34
+ [登记器单元测试](../src/modules/usage/background-work.test.ts) 与 [实际 Kernel + MySQL 生命周期测试](../src/app/kernel-usage-lifecycle.mysql.test.ts) 分别检查内部登记/排空机制和真实 Kernel、数据库事务、HTTP/standalone 关闭接线。后者覆盖延迟完成、晚结算、SQL 锁、同实例重试、双 Kernel 隔离、普通文本异步结算、单独清理/核对、价格持久化,以及失败保留原结果而不重派。
35
+
36
+ 数据库用例需 `BAILING_USAGE_TEST_MYSQL=1` 和其专用测试 MySQL;供应商及业务数据为合成数据。测试源码或被跳过的测试不等于通过记录;真实供应商、业务接口和部署仍各自验收。本页不声称生产采用、全量模型质量或完整故障恢复。
37
+
38
+ [升级指南](UPGRADE_v0.9.1.md) · [版本记录](CHANGELOG.md) · [上一版本](RELEASE_NOTES_v0.9.0.md)
@@ -0,0 +1,54 @@
1
+ # v0.9.0 model billing: paired upgrade guide
2
+
3
+ Upgrade public Core 0.8.0 / SDK 0.6.0 / DSH 0.6.0 to Core 0.9.0 / SDK 0.7.0 / DSH 0.7.0. Verify versions, Tags and artifact digests when downloading or deploying, and retain original configuration and durable records.
4
+
5
+ ## Choose what to enable
6
+
7
+ | Need | Console and Core | Host or business backend |
8
+ | --- | --- | --- |
9
+ | Retain business tools, approvals and long tasks | Upgrade Core and retain configuration/state | Existing workflows continue without enabling model billing |
10
+ | Offer a shared model plan | Configure provider connections, reference mappings and USD plans; grant accounts access | Hosts adopt discovery, model catalogs and summaries; trusted backends provide plan-scoped identity when needed |
11
+ | Generate images from a local assistant | Configure a supported adapter and price, then include it in the plan | Adopt tool discovery, durable original requests and asynchronous lookup; using images in business data remains a separate action |
12
+ | Provision plans from the business application | Configure source ownership and permissions | Trusted backends use external billing APIs with idempotency keys; payment, currency conversion and refunds remain application responsibilities |
13
+ | Remove/restore accounts or manually reset allowance | Administrators act under the required permissions and account state | Existing summaries suffice; these management features do not independently require SDK/DSH or backend changes |
14
+
15
+ ## Backup and migration
16
+
17
+ Retain the database, instance configuration and keys, object storage, previous artifacts, and host credentials, sessions and durable records. Coordinate all Core instances and writers sharing the state database. Preserve IDs and evidence for dispatched requests; do not replace recovery with another request.
18
+
19
+ From public 0.8.0, apply all outstanding files through the official migrator (`npm run db:init` for source installations), then start the new Core. Startup does not migrate implicitly.
20
+
21
+ | Added file | Purpose |
22
+ | --- | --- |
23
+ | `063_usage_model_billing.sql` | Creates 14 model-billing tables for identity, accounts, services, USD plans, original requests, ledger and reference-price cache |
24
+ | `064_period_plan_allowance.sql` | Fills missing periodic allowances from each existing configuration/snapshot's own original allowance; empty fresh billing tables have nothing to backfill |
25
+
26
+ Migration retains existing business and real customer data. Public 0.8.0 did not include this billing module and requires no old-schema purge or table clearing. Incompatible abandoned schemas from unpublished test instances require separate maintenance; their cleanup must not become customer upgrade instructions or public migrations.
27
+
28
+ Instances that already deployed the 063 billing preview must follow the [period allowance guide](PERIOD_ALLOWANCE_UPGRADE.en.md): stop old writers, apply 064, verify original snapshots and ledger, then start the new runtime. The migrator skips recorded files; do not manually alter its ledger or replay applied SQL. Older public versions also need their outstanding preceding migrations.
29
+
30
+ ## Configuration and host integration
31
+
32
+ 1. **Model service:** configure actual credentials, URL and model identifier, with `chat` or `tool` purpose. Explicitly bind an OpenRouter reference model and endpoint; confirm that its metering maps to the actual service. The quote is not the provider's paid cost.
33
+ 2. **Plan:** use USD and one multiplier. Periodic plans require both sale price and period allowance; credit packs use only the one-time allowance. Set validity, day/week/month period and services before granting a test account.
34
+ 3. **Discovery:** inspect `model_gateway` in `GET /usage/v1/capabilities`. Use ready `items`; show configuration reasons from `unavailable_items`. Missing support stays explicit and must not trigger an automatic model switch.
35
+ 4. **Identity and persistence:** trusted backends explicitly exchange `model_access: token_gateway` when plan-wide scope is needed. Single-model `service` scope remains restricted. Persist every original `operation_id` locally and query that request after reopening. Provider credentials must not be passed to browsers or models.
36
+ 5. **Results and allowance:** handle `result_state`, `billing_state` and summary `presentation` separately. Complete results are usable; missing actual usage stays pending settlement. Display Credits or percentage from the summary, not inferred Token balances. Percentage strings may be rounded down; precise numeric values and display strings are separate fields.
37
+
38
+ Verify the actual installed and resolved SDK/DSH pairing, including packaged host dependencies. Changing a version declaration does not implement host UI, persistence or execution integration. Hosts that do not enable the gateway retain their existing business contract.
39
+
40
+ ## Acceptance after enablement
41
+
42
+ - A test account discovers its ready models and tools; unavailable entries explain their state and no provider credentials enter catalogs.
43
+ - With explicit sale price, allowance and multiplier, check one controlled request's actual usage, reference cost, billed amount and presentation. Image services without Tokens leave them absent.
44
+ - Original-ID lookup and same-content replay do not dispatch again. Known failures, unknown outcomes, cancellation and pending settlement remain distinct. Expired results do not trigger regeneration.
45
+ - Plan edits preserve original grant allowances. Archiving blocks new use and restoration does not replenish allowance. A reset retains expiration, and already-dispatched requests settle against their original pool. Check only the administrative actions being enabled.
46
+ - Verify artifacts, migration ledger and client versions while retaining approvals, original-call rules and task restrictions.
47
+
48
+ Video/voice declarations are not execution acceptance. Current image adapters do not implement provider-task recovery through a provider task ID; original-ID lookup reads the Hub's persisted result.
49
+
50
+ ## Rollback
51
+
52
+ Once new structures and snapshots exist, do not assume an older version can read or enforce them correctly. Stop new dispatches, inspect original in-flight requests and settlement, and retain ledger and rollback evidence. Restoring an older backup also requires accounting for subsequent requests and business effects. Do not roll back by dropping tables, discarding ledger entries or resending operations. Existing 0.8.0 task-enforcement markers still require compatible runtimes.
53
+
54
+ [Release notes](RELEASE_NOTES_v0.9.0.en.md) · [Complete billing contract](MODEL_BILLING.en.md) · [简体中文](UPGRADE_v0.9.0.md)
@@ -0,0 +1,54 @@
1
+ # v0.9.0 模型计费:配套升级指南
2
+
3
+ 从公开 Core 0.8.0 / SDK 0.6.0 / DSH 0.6.0 升级到 Core 0.9.0 / SDK 0.7.0 / DSH 0.7.0。下载与部署时核对版本、Tag 和制品摘要,保留原配置与持久记录。
4
+
5
+ ## 选择需要启用的能力
6
+
7
+ | 需求 | 管理端与 Core | 宿主或业务后端 |
8
+ | --- | --- | --- |
9
+ | 保持原业务工具、审批与长任务 | 升级 Core,保留原配置与状态 | 原流程继续使用,无需开启模型计费 |
10
+ | 提供统一模型套餐 | 配置模型连接、参考计价映射、USD 套餐并开通账户 | 宿主接入能力发现、模型目录与额度摘要;可信后端按需提供套餐范围身份 |
11
+ | 让本地助手生成图片 | 配置已支持的图片适配、参考价格并加入套餐 | 接入工具目录、原请求持久记录与异步查询;业务使用图片仍单独调用业务接口 |
12
+ | 自动开通业务套餐 | 配置来源所有权与权限 | 可信后端使用外部计费接口,保留幂等开通标识;支付、汇率和退款仍由业务侧处理 |
13
+ | 移除、恢复账户或手动重置额度 | 管理员按账户状态与权限操作 | 使用已有摘要;这些管理功能不单独要求 SDK/DSH 或业务后端改造 |
14
+
15
+ ## 备份与迁移
16
+
17
+ 保留数据库、实例配置和密钥、对象存储、原制品及客户端的安全凭据、会话和持久记录。升级时协调所有共用状态库的 Core 与写入方;已经派发的请求保留原 ID 和证据,不以重发替代恢复。
18
+
19
+ 从公开 0.8.0 升级,通过正式迁移器(源码安装入口为 `npm run db:init`)应用全部未执行文件,再启动新 Core。运行时启动不自动迁移。
20
+
21
+ | 新增文件 | 作用 |
22
+ | --- | --- |
23
+ | `063_usage_model_billing.sql` | 新建模型计费所需身份、账户、模型服务、USD 套餐、原请求账本及参考价格缓存,共 14 张表 |
24
+ | `064_period_plan_allowance.sql` | 为已存在且缺字段的周期配置和快照补入各自原额度;新安装的空计费表无数据回填 |
25
+
26
+ 迁移保留原业务与真实客户数据。公开 0.8.0 没有这一计费模块,无需先清退旧结构或清空表。早期未公开测试实例如有不兼容废弃结构,属于独立维护问题,不能把其清理步骤用于客户升级或混入公共迁移。
27
+
28
+ 已部署过 063 计费预览的实例,先看[周期售价与额度拆分](PERIOD_ALLOWANCE_UPGRADE.md):停止旧版本写入,再应用 064,核对原快照与账本后启动新版本。已记账文件由迁移器跳过;不手工改写账本或重跑已应用 SQL。更早公开版本还需应用缺少的前序迁移。
29
+
30
+ ## 配置与宿主接入
31
+
32
+ 1. **模型服务**:配置实际凭据、地址及型号,选择 `chat` 或 `tool` 用途。显式绑定 OpenRouter 参考模型与端点,核对价格计量与真实服务能否对应。参考报价不是供应商实付成本。
33
+ 2. **套餐**:统一 USD 与一个倍率。周期套餐同时填写售价和周期额度;额度包只填写一次性额度。确定有效期、日/周/月周期和服务集合,再为测试账户开通。
34
+ 3. **能力发现**:读取 `GET /usage/v1/capabilities` 中 `model_gateway`。宿主使用当前目录的 ready `items`,对 `unavailable_items` 显示配置原因;缺少支持时明确不可用,不自动换模型。
35
+ 4. **身份与持久化**:需要整个套餐范围时,可信后端显式交换 `model_access: token_gateway` 身份;单模型 `service` 范围仍保持。每个模型或工具请求在本地持久保存原 `operation_id`,重开后查询原请求。不要将服务端凭据传给浏览器或模型。
36
+ 5. **结果与额度**:分别处理 `result_state`、`billing_state` 与摘要的 `presentation`。结果 complete 即可使用;缺少实际计量保持待结算。Credits 与百分比使用摘要,不从 Token 数猜余额。控制台可能向下取整显示百分比,精确数值与显示字符串分别提供。
37
+
38
+ 配套 SDK/DSH 应核对实际安装与解析版本,包括打包宿主内的依赖。仅修改版本声明不会自动完成宿主 UI、持久化或工具执行接入;不启用模型网关的宿主继续遵循原业务契约。
39
+
40
+ ## 启用后的验收
41
+
42
+ - 一个测试账户能看到套餐中已就绪的模型与工具,未就绪项有可理解的原因,供应商凭据不进入目录。
43
+ - 采用明确的售价、周期额度和倍率,核对一次受控请求的实际用量、参考费用、扣费及客户展示。图片服务没有 Token 时保持为空。
44
+ - 原 ID 查询和同内容重试不会再次派发;已知失败、未知结果、取消和待结算分开展示。结果过期不触发自动重发。
45
+ - 套餐编辑不改写原开通额度。归档后阻止新使用,恢复不补发额度;重置维持原有效期,已派发请求向原池结算。只检查本次启用的管理动作。
46
+ - 验证新制品、迁移账本和客户端版本,同时保留既有审批、原调用与长任务约束。
47
+
48
+ 视频、语音声明不作为执行验收;当前图片适配不提供供应商任务 ID 的异步任务恢复,原 ID 查询读取中枢保存的结果。
49
+
50
+ ## 回退
51
+
52
+ 新结构与新快照落库后,不能假定旧版本能读取或正确约束它们。出现问题先停止新增派发,核对原在途请求及结算,保留账本与回滚材料。恢复旧备份必须同时处理备份后的请求和业务效果,不能通过删表、丢弃账本或重发原操作回退。已启用的 0.8.0 任务强制标记仍须由兼容版本执行。
53
+
54
+ [版本说明](RELEASE_NOTES_v0.9.0.md) · [完整计费契约](MODEL_BILLING.md) · [English](UPGRADE_v0.9.0.en.md)
@@ -0,0 +1,39 @@
1
+ # Core v0.9.1 patch upgrade guide
2
+
3
+ [中文版](UPGRADE_v0.9.1.md)
4
+
5
+ Upgrade public Core 0.9.0 to 0.9.1 to include usage background work in shutdown drain and receive the public capability index and general security-governance updates. There are no new APIs, SQL migrations, plan rules, or client features. MCP / Agent Client SDK and DSH remain at their existing 0.7.0 versions.
6
+
7
+ ## Preserve data and original calls
8
+
9
+ Retain databases, instance configuration/credentials, attachment storage, previous artifacts, and host session/original-call records. Stop new work for the target instance, coordinate writers sharing its state, and reconcile dispatched requests. Do not replace recovery with a new `operation_id`.
10
+
11
+ The 0.9.0 `close()` did not explicitly drain usage background continuations. A finished old-version HTTP request or a returned old `close()` does not establish that image completion, settlement, or price persistence has finished. Reconcile in-flight work using original requests before replacing artifacts.
12
+
13
+ ## Versions and database
14
+
15
+ - Use formal `v0.9.1` source, npm packages, or images. Verify the actual version, source Tag/commit, and artifact digest. Installer and prebuilt-image Compose defaults are updated to 0.9.1.
16
+ - Compared with 0.9.0, there are no new migrations, changes to existing SQL, table clears, or required plan/allowance resets. Earlier versions still apply all outstanding files through the official migrator; see the [0.9.0 upgrade guide](UPGRADE_v0.9.0.en.md).
17
+ - Embedded hosts recheck the complete `BAILINGHUB_CORE_ARTIFACT_V1` manifest. A version change changes artifact identity even when active SQL filenames/checksums are unchanged. Comparing only the latest migration is insufficient.
18
+ - This patch does not require SDK/DSH version bumps or changes to business declarations, signatures, permissions, or approvals.
19
+
20
+ ## Shutdown and acceptance
21
+
22
+ For an ordinary deployment, check `/health`, the console, and existing business smoke paths. Deployments using the usage gateway also check original request results, billing states, and allowance. A complete result is not necessarily settled billing.
23
+
24
+ Embedded hosts continue fair `tick()` calls and use `close(drainMs)` for eviction, upgrades, and shutdown. Within the original budget, 0.9.1 waits for model completion, settlement, cleanup/reconciliation, and price refresh. A **usage-drain-stage timeout** retains the original dependencies and closing state. Wait for original work and retry on the same instance or alert; do not forcibly close its database or treat timeout as permission to redispatch. This does not imply that every subsequent resource-close failure leaves all resources untouched.
25
+
26
+ Public regressions can be reproduced in a dedicated test environment:
27
+
28
+ ```bash
29
+ node --import tsx --test src/modules/usage/background-work.test.ts
30
+ BAILING_USAGE_TEST_MYSQL=1 node --import tsx --test src/app/kernel-usage-lifecycle.mysql.test.ts
31
+ ```
32
+
33
+ The database cases use the fixture's isolated test MySQL, synthetic providers, and synthetic data. Without that environment, or when cases are skipped, record database validation as unexecuted. The cases need no live model calls and do not replace live-provider or deployment acceptance. See the [Kernel Host API](KERNEL_HOST_API.en.md) and [capability index](IMPLEMENTATION_STATUS.en.md) for coverage and limitations.
34
+
35
+ ## Rollback boundary
36
+
37
+ No new schema is introduced, but returning to 0.9.0 removes the usage background-drain fix. Stop new work, retain original results, ledger, configuration, and rollback artifacts, and reconcile in-flight operations before deciding to roll back. Do not delete ledgers, replay original requests, or treat backup restoration as undoing later business effects.
38
+
39
+ [Release notes](RELEASE_NOTES_v0.9.1.en.md) · [Compatibility policy](COMPATIBILITY.en.md)
@@ -0,0 +1,39 @@
1
+ # Core v0.9.1 补丁升级指南
2
+
3
+ [English](UPGRADE_v0.9.1.en.md)
4
+
5
+ 从公开 Core 0.9.0 升级到 0.9.1,目标是补齐 usage 后台工作关闭等待,并取得公开能力索引与通用安全治理更新。没有新增 API、SQL、套餐规则或客户端功能;MCP / Agent Client SDK 与 DSH 继续使用既有 0.7.0。
6
+
7
+ ## 保留数据与原调用
8
+
9
+ 保留数据库、实例配置和凭据、附件存储、旧制品以及宿主的会话/原调用持久记录。停止目标实例的新工作,协调共享状态库的写入方,核对已经派发的原请求;不要通过新 `operation_id` 代替结果恢复。
10
+
11
+ 0.9.0 的 `close()` 没有显式排空 usage 后台 continuation。因此,升级前不能只凭旧版 HTTP 已结束或旧 `close()` 已返回,就认定图片完成、结算或价格写入已经结束。应按原请求核对在途工作,再替换制品。
12
+
13
+ ## 版本与数据库
14
+
15
+ - 使用正式 `v0.9.1` 源码、npm 包或镜像,核对实际版本、来源 Tag/提交和制品摘要;安装器与预构建镜像 Compose 的默认版本同步为 0.9.1。
16
+ - 相对 0.9.0 没有新增迁移,不修改已有 SQL,也不要求清表或重置套餐/额度。更早版本按正式迁移器应用其全部未执行文件,仍可参考 [0.9.0 升级指南](UPGRADE_v0.9.0.md)。
17
+ - 嵌入式宿主使用 `BAILINGHUB_CORE_ARTIFACT_V1` 重新核对完整制品 manifest。版本变更会改变 manifest 身份,即使活动 SQL 名称与摘要不变;不要只比较最后一个迁移文件。
18
+ - 本补丁不要求升级 SDK/DSH 的版本声明,也不改变业务后端的声明、验签、权限或审批。
19
+
20
+ ## 关闭与验收
21
+
22
+ 正常部署先验证 `/health`、控制台和原有业务 smoke。使用 usage 网关的部署另核对原请求结果、计费状态和额度,不把结果 complete 等同于已 settled。
23
+
24
+ 嵌入式宿主继续公平调用 `tick()`,在淘汰、升级或退出时调用 `close(drainMs)`。0.9.1 在原关闭预算内等待模型完成、结算、清理/核对和价格刷新。**usage 排空阶段超时**会保留原实例依赖和 closing 状态;等待原工作后,在同一实例重试或告警,不强行关闭其数据库,也不把超时解释为重派许可。该描述不扩大为任何资源关闭失败都能原封不动回退。
25
+
26
+ 可在专用测试环境复现公开回归:
27
+
28
+ ```bash
29
+ node --import tsx --test src/modules/usage/background-work.test.ts
30
+ BAILING_USAGE_TEST_MYSQL=1 node --import tsx --test src/app/kernel-usage-lifecycle.mysql.test.ts
31
+ ```
32
+
33
+ 数据库用例使用 fixture 要求的隔离测试 MySQL、合成供应商和数据。没有该环境或用例被跳过时,应明确记录数据库验证未执行;这些用例不需要真实模型调用,也不替代真实供应商或部署验收。完整覆盖与限制见 [Kernel Host API](KERNEL_HOST_API.md) 和 [能力索引](IMPLEMENTATION_STATUS.md)。
34
+
35
+ ## 回退边界
36
+
37
+ 本版没有新增 schema,但回退到 0.9.0 会重新失去 usage 后台关闭等待。先停止新工作并保留原结果、账本、配置和回滚制品,核对在途操作后再决定回退。不要删账本、重发原请求或把备份恢复当作撤销备份后业务效果的办法。
38
+
39
+ [版本说明](RELEASE_NOTES_v0.9.1.md) · [兼容策略](兼容性与升级.md)
@@ -1,5 +1,13 @@
1
1
  # 百灵中枢 · 兼容性与升级策略
2
2
 
3
+ ## Core 0.9.1 补丁升级
4
+
5
+ 相对 0.9.0 仅修复异步 usage 工作关闭等待并更新公开文档/通用安全治理,没有新增 API、SQL、套餐规则或客户端功能。SDK 0.7.0 / DSH 0.7.0 不变。旧版关闭返回不能证明 usage 后台工作已结束;替换制品前核对原请求,新版 usage 排空超时在原实例重试。见 [0.9.1 升级指南](UPGRADE_v0.9.1.md)。
6
+
7
+ ## Core 0.9.0 配套升级
8
+
9
+ Core 0.9.0 配套 SDK 0.7.0 / DSH 0.7.0,新增可选模型计费网关;本地宿主继续编排,既有业务权限、审批与原调用恢复保持。从公开 0.8.0 升级应用未执行的 063/064,保留真实数据,不需要清退测试结构。周期套餐的售价与额度独立,原开通快照和账本保留。启用模型套餐的宿主需要显式接入;只使用原业务工具的宿主不必开启计费。详见 [0.9.0 升级指南](UPGRADE_v0.9.0.md)。
10
+
3
11
  > Core 0.8.0 task enrollment persists on original Agent Sessions. Do not downgrade an enrolled deployment to a version that ignores enforcement markers. See [upgrade boundaries](UPGRADE_v0.8.0.md).
4
12
 
5
13
  > 这份策略用于公开发布后的版本演进。目标是让绝大多数升级都能平滑完成:拉新版、执行数据库结构同步、重启 hub;已配置的路由、凭证、工具源、聊天入口不需要重配。破坏性变更必须显式说明,并提供过渡窗口。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bailinghub",
3
- "version": "0.8.0",
3
+ "version": "0.9.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Open-source ACC runtime and agent control plane for existing business systems.",
@@ -81,8 +81,8 @@
81
81
  "client-api:contract": "tsx scripts/client-api-contract-test.ts",
82
82
  "client-api:ecosystem:local": "node scripts/check-client-api-ecosystem.mjs --mode local",
83
83
  "client-api:ecosystem:clone": "node scripts/check-client-api-ecosystem.mjs --mode clone",
84
- "audit:deps": "npm audit --audit-level=low && npm --prefix web-admin audit --audit-level=low",
85
- "web-admin:check": "npm --prefix web-admin run build && npm --prefix web-admin audit --audit-level=low",
84
+ "audit:deps": "node scripts/dependency-audit.mjs",
85
+ "web-admin:check": "npm --prefix web-admin run build && node scripts/dependency-audit.mjs --scope web-admin",
86
86
  "oss:guard": "node scripts/oss-boundary-check.mjs",
87
87
  "oss:export": "node scripts/export-oss.mjs",
88
88
  "oss:verify": "node scripts/verify-oss-export.mjs",
@@ -104,7 +104,8 @@
104
104
  "sdk:test-runtime": "node scripts/sdk-runtime-test.mjs",
105
105
  "sdk:test-p1": "node scripts/sdk-p1-check.mjs",
106
106
  "sdk:pack": "COPYFILE_DISABLE=1 tar --no-xattrs -czf web/connect/bailing-connect-php.tgz -s '|^php|bailing-connect-php|' -C sdk php",
107
- "sdk:pack7": "COPYFILE_DISABLE=1 tar --no-xattrs -czf web/connect/bailing-connect-php7.tgz -s '|^php7|bailing-connect-php7|' -C sdk php7"
107
+ "sdk:pack7": "COPYFILE_DISABLE=1 tar --no-xattrs -czf web/connect/bailing-connect-php7.tgz -s '|^php7|bailing-connect-php7|' -C sdk php7",
108
+ "audit:deps:test": "node --test scripts/dependency-audit.test.mjs"
108
109
  },
109
110
  "dependencies": {
110
111
  "mammoth": "^1.12.0",
@@ -104,6 +104,12 @@ const englishCompanions = {
104
104
  'docs/RELEASE_NOTES_v0.5.0.md': 'docs/RELEASE_NOTES_v0.5.0.en.md',
105
105
  'docs/RELEASE_NOTES_v0.5.1.md': 'docs/RELEASE_NOTES_v0.5.1.en.md',
106
106
  'docs/RELEASE_NOTES_v0.8.0.md': 'docs/RELEASE_NOTES_v0.8.0.en.md',
107
+ 'docs/RELEASE_NOTES_v0.9.0.md': 'docs/RELEASE_NOTES_v0.9.0.en.md',
108
+ 'docs/UPGRADE_v0.9.0.md': 'docs/UPGRADE_v0.9.0.en.md',
109
+ 'docs/RELEASE_NOTES_v0.9.1.md': 'docs/RELEASE_NOTES_v0.9.1.en.md',
110
+ 'docs/UPGRADE_v0.9.1.md': 'docs/UPGRADE_v0.9.1.en.md',
111
+ 'docs/MODEL_BILLING.md': 'docs/MODEL_BILLING.en.md',
112
+ 'docs/PERIOD_ALLOWANCE_UPGRADE.md': 'docs/PERIOD_ALLOWANCE_UPGRADE.en.md',
107
113
  'docs/RELEASE_NOTES_v0.7.0.md': 'docs/RELEASE_NOTES_v0.7.0.en.md',
108
114
  'docs/RELEASE_NOTES_v0.6.1.md': 'docs/RELEASE_NOTES_v0.6.1.en.md',
109
115
  'docs/RELEASE_NOTES_v0.6.0.md': 'docs/RELEASE_NOTES_v0.6.0.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.8.0"
12
+ [ -n "$TAG" ] || TAG="0.9.1"
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.8.0');
42
- assert.equal(result.stableVersion, '0.8.0');
41
+ assert.equal(result.version, '0.9.1');
42
+ assert.equal(result.stableVersion, '0.9.1');
43
43
  assert.equal(result.publishTag, 'latest');
44
44
  });
45
45
 
@@ -0,0 +1,134 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { existsSync, readFileSync, readdirSync, lstatSync } from 'node:fs';
3
+ import { resolve, relative, join } from 'node:path';
4
+ import { pathToFileURL } from 'node:url';
5
+ import { spawnSync } from 'node:child_process';
6
+
7
+ const affectedNames = ['mammoth', 'argparse', 'sprintf-js'];
8
+ const approvedAdvisory = 'https://github.com/advisories/GHSA-hp3w-g68c-fv3c';
9
+ const usagePattern = /\b(?:mammoth|argparse|sprintf-js)\b/i;
10
+ const levels = ['info', 'low', 'moderate', 'high', 'critical'];
11
+ const json = path => JSON.parse(readFileSync(path, 'utf8'));
12
+ const hash = source => createHash('sha256').update(source).digest('hex');
13
+ const stable = value => JSON.stringify(value, (_key, item) => item && typeof item === 'object' && !Array.isArray(item)
14
+ ? Object.fromEntries(Object.keys(item).sort().map(key => [key, item[key]])) : item);
15
+
16
+ function reviewedRowsAreExact(rows) {
17
+ if (!rows || Array.isArray(rows) || typeof rows !== 'object' ||
18
+ stable(Object.keys(rows).sort()) !== stable([...affectedNames].sort())) return false;
19
+ const chain = { mammoth: ['argparse'], argparse: ['sprintf-js'] };
20
+ const effects = { mammoth: [], argparse: ['mammoth'], 'sprintf-js': ['argparse'] };
21
+ for (const name of affectedNames) {
22
+ const row = rows[name];
23
+ if (!row || row.name !== name || row.severity !== 'moderate' ||
24
+ stable(row.nodes) !== stable([`node_modules/${name}`]) ||
25
+ stable(row.effects) !== stable(effects[name])) return false;
26
+ if (name !== 'sprintf-js') {
27
+ if (stable(row.via) !== stable(chain[name])) return false;
28
+ } else {
29
+ if (!Array.isArray(row.via) || row.via.length !== 1) return false;
30
+ const advisory = row.via[0];
31
+ if (!advisory || typeof advisory !== 'object' || Array.isArray(advisory) ||
32
+ advisory.name !== name || advisory.dependency !== name ||
33
+ advisory.severity !== 'moderate' || advisory.url !== approvedAdvisory) return false;
34
+ }
35
+ }
36
+ return true;
37
+ }
38
+
39
+ export function dependencyState(lock) {
40
+ const versions = {}, references = [];
41
+ for (const [path, entry] of Object.entries(lock.packages ?? {})) {
42
+ if (affectedNames.some(name => path === `node_modules/${name}` || path.endsWith(`/node_modules/${name}`))) versions[path] = entry.version;
43
+ for (const kind of ['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies']) {
44
+ for (const [name, range] of Object.entries(entry[kind] ?? {})) {
45
+ if (affectedNames.includes(name)) references.push(`${path || '<root>'}|${kind}|${name}|${range}`);
46
+ }
47
+ }
48
+ }
49
+ return { versions, references: references.sort() };
50
+ }
51
+
52
+ export function collectUsage(root, scope) {
53
+ const inventory = {};
54
+ const directories = scope === 'core' ? ['src', 'scripts', '.github'] : ['web-admin/src', 'web-admin/scripts'];
55
+ const excluded = new Set(['scripts/dependency-audit.mjs', 'scripts/dependency-audit.test.mjs']);
56
+ function visit(path) {
57
+ const local = relative(root, path).replaceAll('\\', '/');
58
+ if (excluded.has(local)) return;
59
+ const stat = lstatSync(path);
60
+ if (stat.isSymbolicLink()) throw new Error(`Source symlink requires review: ${local}`);
61
+ if (stat.isDirectory()) {
62
+ for (const entry of readdirSync(path).sort()) visit(join(path, entry));
63
+ } else if (stat.isFile() && /\.(?:[cm]?js|[cm]?ts|jsx|tsx|vue|html|ya?ml|json|sh)$/.test(path)) {
64
+ const source = readFileSync(path);
65
+ if (usagePattern.test(source.toString('utf8'))) inventory[local] = hash(source);
66
+ }
67
+ }
68
+ for (const directory of directories) if (existsSync(join(root, directory))) visit(join(root, directory));
69
+ const manifestPath = scope === 'core' ? 'package.json' : 'web-admin/package.json';
70
+ const scripts = json(join(root, manifestPath)).scripts ?? {};
71
+ for (const [name, command] of Object.entries(scripts)) {
72
+ if (usagePattern.test(String(command))) inventory[`${manifestPath}#scripts.${name}`] = hash(String(command));
73
+ }
74
+ return inventory;
75
+ }
76
+
77
+ export function evaluateScope({ scope, audit, lock, usage, policy, now = new Date() }) {
78
+ const reasons = [], counts = Object.fromEntries(levels.map(level => [level, 0]));
79
+ const exception = policy.scopes?.[scope];
80
+ const from = Date.parse(policy.approvedFrom), until = Date.parse(policy.expiresAt), time = +now;
81
+ if (policy.version !== 1 || policy.owner !== 'Jingchuan Nie' || policy.advisory !== approvedAdvisory) reasons.push('Unknown exception policy');
82
+ if (![from, until, time].every(Number.isFinite) || until <= from || until - from > 30 * 86400000) reasons.push('Invalid exception period');
83
+ else if (time < from || time >= until) reasons.push('Exception is not active or has expired');
84
+ if (!exception) reasons.push(`Unknown scope: ${scope}`);
85
+ else if (!reviewedRowsAreExact(exception.knownAuditRows)) reasons.push('Exception policy must contain only the reviewed Mammoth/argparse/sprintf-js chain and advisory');
86
+ const rows = audit?.vulnerabilities;
87
+ if (audit?.auditReportVersion !== 2 || audit?.error || !rows || Array.isArray(rows) || typeof rows !== 'object') {
88
+ reasons.push('Invalid or failed npm audit response');
89
+ return { scope, pass: false, rawCounts: null, exceptedRows: 0, reasons };
90
+ }
91
+ let exceptedRows = 0;
92
+ for (const [name, row] of Object.entries(rows)) {
93
+ if (levels.includes(row.severity)) counts[row.severity]++;
94
+ else reasons.push(`Unknown vulnerability severity: ${name}`);
95
+ if (!exception?.knownAuditRows?.[name] || stable(row) !== stable(exception.knownAuditRows[name])) reasons.push(`Unreviewed vulnerability or changed advisory/dependency path: ${name}`);
96
+ else exceptedRows++;
97
+ }
98
+ counts.total = Object.keys(rows).length;
99
+ if (stable(counts) !== stable(audit.metadata?.vulnerabilities)) reasons.push('Audit counts do not match vulnerability rows');
100
+ if (exception) {
101
+ const state = dependencyState(lock);
102
+ if (stable(state.versions) !== stable(exception.packageVersions)) reasons.push('Reviewed dependency versions or installed locations changed');
103
+ if (stable(state.references) !== stable(exception.dependencyReferences)) reasons.push('New or changed dependency consumer/path requires review');
104
+ if (stable(usage) !== stable(exception.reviewedUsageFiles)) reasons.push('New/changed source or CLI usage requires review');
105
+ }
106
+ return { scope, pass: reasons.length === 0, rawCounts: counts, exceptedRows, unexceptedRows: counts.total - exceptedRows, exceptionExpiresAt: policy.expiresAt, reasons };
107
+ }
108
+
109
+ export function runScope(root, scope, policy) {
110
+ const directory = scope === 'core' ? root : join(root, 'web-admin');
111
+ const run = spawnSync('npm', ['audit', '--json'], { cwd: directory, encoding: 'utf8', timeout: 120000, maxBuffer: 8 * 1024 * 1024 });
112
+ if (run.error || run.signal || ![0, 1].includes(run.status)) throw new Error(`npm audit failed in ${scope}; exit=${run.status}`);
113
+ return evaluateScope({ scope, audit: JSON.parse(run.stdout), lock: json(join(directory, 'package-lock.json')), usage: collectUsage(root, scope), policy });
114
+ }
115
+
116
+ if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) {
117
+ try {
118
+ const options = { root: process.cwd(), scope: 'all' };
119
+ for (let index = 2; index < process.argv.length; index += 2) {
120
+ const flag = process.argv[index], value = process.argv[index + 1];
121
+ if (!['--root', '--scope', '--policy'].includes(flag) || !value) throw new Error('Usage: dependency-audit.mjs [--root PATH] [--scope core|web-admin|all] [--policy PATH]');
122
+ options[flag.slice(2)] = value;
123
+ }
124
+ if (!['core', 'web-admin', 'all'].includes(options.scope)) throw new Error('Unknown scope');
125
+ const root = resolve(options.root), policy = json(options.policy ?? join(root, 'security/dependency-audit-exceptions.json'));
126
+ const scopes = options.scope === 'all' ? ['core', 'web-admin'] : [options.scope];
127
+ const results = scopes.map(scope => runScope(root, scope, policy));
128
+ console.log(JSON.stringify({ results, note: 'Raw findings remain open; an exact temporary exception is not a vulnerability fix.' }, null, 2));
129
+ process.exitCode = results.every(result => result.pass) ? 0 : 1;
130
+ } catch (error) {
131
+ console.error(`Dependency audit blocked: ${error.message}`);
132
+ process.exitCode = 1;
133
+ }
134
+ }