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
@@ -7,7 +7,7 @@ It is not certification, a benchmark, or evidence of production adoption. Passin
7
7
  ## Scope
8
8
 
9
9
  - Target: the open-source BailingHub Docker demo;
10
- - Stable baseline: `v0.8.0`;
10
+ - Stable baseline: `v0.9.1`;
11
11
  - Data: the bundled demo orders, tickets, refunds, and failure probe;
12
12
  - Expected time: about 20 minutes after images and dependencies are available;
13
13
  - Not required: a real model key, production API, production credential, or real business data.
@@ -32,7 +32,7 @@ curl -fsSL https://www.bailinghub.com/install.sh | sh
32
32
  cd "$HOME/bailinghub"
33
33
  ```
34
34
 
35
- The installer pulls the official `v0.8.0` images by default, generates random tokens and an admin password, starts the services, and runs the smoke test. The initial administrator is created only when the administrator table is empty; restarting, upgrading, recreating containers, or reinstalling against the same persistent database does not overwrite a changed password. The optional `/metrics` endpoint remains disabled and does not affect core validation. Keep the reported version, install mode, elapsed time, and the commands printed under `常用命令`, but never include passwords or tokens in your report. After Docker is installed, the current non-root login usually still needs the printed `sudo docker compose ...` commands; Docker group membership may not take effect until the next login.
35
+ The installer pulls the official `v0.9.1` images by default, generates random tokens and an admin password, starts the services, and runs the smoke test. The initial administrator is created only when the administrator table is empty; restarting, upgrading, recreating containers, or reinstalling against the same persistent database does not overwrite a changed password. The optional `/metrics` endpoint remains disabled and does not affect core validation. Keep the reported version, install mode, elapsed time, and the commands printed under `常用命令`, but never include passwords or tokens in your report. After Docker is installed, the current non-root login usually still needs the printed `sudo docker compose ...` commands; Docker group membership may not take effect until the next login.
36
36
 
37
37
  If the default directory is already in use, choose a new empty directory instead of overwriting an existing deployment:
38
38
 
@@ -46,7 +46,7 @@ cd "$HOME/bailinghub-validation"
46
46
  ### Path B: local source reproduction
47
47
 
48
48
  ```bash
49
- git clone --depth 1 --branch v0.8.0 https://github.com/bailinghub/bailinghub.git
49
+ git clone --depth 1 --branch v0.9.1 https://github.com/bailinghub/bailinghub.git
50
50
  cd bailinghub
51
51
  git rev-parse HEAD
52
52
  export BAILING_TOKEN="$(openssl rand -hex 32)"
@@ -167,7 +167,7 @@ After the core task passes, you may continue with:
167
167
  - [Trusted rich rendering and chat reliability](RELEASE_NOTES_v0.1.15.en.md).
168
168
  - [Bounded tool runtime and resilient semantic retrieval](RELEASE_NOTES_v0.1.16.en.md).
169
169
  - [Composable Core and Kernel Host API v1](RELEASE_NOTES_v0.3.0.en.md).
170
- - [Current stable release notes](RELEASE_NOTES_v0.8.0.en.md).
170
+ - [Current stable release notes](RELEASE_NOTES_v0.9.1.en.md).
171
171
 
172
172
  Select the relevant track in the same Issue form and disclose whether you received direct maintainer assistance.
173
173
 
@@ -7,7 +7,7 @@
7
7
  ## 验证范围
8
8
 
9
9
  - 验证对象:BailingHub 开源版 Docker demo;
10
- - 稳定基线:`v0.8.0`;
10
+ - 稳定基线:`v0.9.1`;
11
11
  - 数据范围:仓库自带的 demo 订单、工单、退款和故障工具;
12
12
  - 预计用时:镜像和依赖下载完成后约 20 分钟;
13
13
  - 不需要:真实大模型 Key、生产 API、生产凭据或真实业务数据。
@@ -32,7 +32,7 @@ curl -fsSL https://www.bailinghub.com/install.sh | sh
32
32
  cd "$HOME/bailinghub"
33
33
  ```
34
34
 
35
- 脚本默认拉取 `v0.8.0` 官方镜像,生成随机 Token 与后台密码,启动服务并自动运行基础体检。首次管理员只在数据库管理员表为空时创建;对同一持久化数据库进行重启、升级、容器重建或重新安装,不会覆盖已经修改的管理员密码。可选 `/metrics` 端点默认关闭,不影响基础验证。请保留终端输出中的版本、安装模式、耗时和“常用命令”,但不要把密码或 Token 写入反馈。新安装 Docker 后,当前非 root 会话通常仍需使用脚本打印的 `sudo docker compose ...` 命令;重新登录后 Docker 组权限才可能生效。
35
+ 脚本默认拉取 `v0.9.1` 官方镜像,生成随机 Token 与后台密码,启动服务并自动运行基础体检。首次管理员只在数据库管理员表为空时创建;对同一持久化数据库进行重启、升级、容器重建或重新安装,不会覆盖已经修改的管理员密码。可选 `/metrics` 端点默认关闭,不影响基础验证。请保留终端输出中的版本、安装模式、耗时和“常用命令”,但不要把密码或 Token 写入反馈。新安装 Docker 后,当前非 root 会话通常仍需使用脚本打印的 `sudo docker compose ...` 命令;重新登录后 Docker 组权限才可能生效。
36
36
 
37
37
  如果默认目录已被占用,请使用一个新的空目录,不要覆盖现有部署:
38
38
 
@@ -46,7 +46,7 @@ cd "$HOME/bailinghub-validation"
46
46
  ### 路径 B:本地源码复现
47
47
 
48
48
  ```bash
49
- git clone --depth 1 --branch v0.8.0 https://github.com/bailinghub/bailinghub.git
49
+ git clone --depth 1 --branch v0.9.1 https://github.com/bailinghub/bailinghub.git
50
50
  cd bailinghub
51
51
  git rev-parse HEAD
52
52
  export BAILING_TOKEN="$(openssl rand -hex 32)"
@@ -167,7 +167,7 @@ docker compose exec -T bailinghub npm run demo:e2e
167
167
  - [可信富内容渲染与聊天可靠性](RELEASE_NOTES_v0.1.15.md)。
168
168
  - [工具运行时收敛与语义检索韧性](RELEASE_NOTES_v0.1.16.md)。
169
169
  - [可组合 Core 与 Kernel Host API v1](RELEASE_NOTES_v0.3.0.md)。
170
- - [当前稳定版发布说明](RELEASE_NOTES_v0.8.0.md)。
170
+ - [当前稳定版发布说明](RELEASE_NOTES_v0.9.1.md)。
171
171
 
172
172
  扩展验证请在同一 Issue 模板中选择对应路径,并说明是否获得过维护者的直接帮助。
173
173
 
@@ -46,6 +46,24 @@ await kernel.close(30_000);
46
46
 
47
47
  Managed mode does not create a full timer set per Kernel. The host must call `tick()` fairly and call `close()` during eviction, upgrade, or process shutdown. The 0-600000 ms `close(drainMs)` budget covers initialization, in-flight maintenance/ticks, HTTP, InHub, and execution-queue drain; after drain, Core also clears Kernel-owned transient credential caches such as WeCom access tokens. A timeout preserves the original instance dependencies and reports an error, so the host can retry on that same instance or alert. New `initialize()` and `tick()` calls cannot reopen resources after closing begins.
48
48
 
49
+ ### Usage background drain: Core v0.9.1
50
+
51
+ [Core v0.9.1](RELEASE_NOTES_v0.9.1.en.md) adds usage background work to that close budget. **The formal v0.9.0 Tag does not contain this shutdown fix**. Each Kernel's `UsageRepository` owns a separate [background-work tracker](../src/modules/usage/background-work.ts), covering model-tool completion, settlement, response cleanup, pending-usage reconciliation, and reference-price refresh through persistence.
52
+
53
+ `close()` first blocks new Kernel HTTP admission and waits for accepted HTTP handlers, InHub, and execution queues to finish registering work. It then stops new model requests and maintenance/price refresh for that repository, and dynamically waits for accepted background work. An accepted model-tool completion may register a settlement child after drain starts; that child must also finish before resources close. Asynchronous model tools still promptly return the original pending state/HTTP 202. This revision does not make the first response wait for image-provider completion.
54
+
55
+ All stages share the original `drainMs` deadline rather than receiving a fresh full budget each. A usage-drain timeout reports an error, keeps the Kernel closing and its dependencies intact, and skips subsequent resource closure. The host can wait for the original work and retry `close()` on **the same instance**. A timeout never authorizes a fresh model dispatch or business write. Successful drain establishes that registered work has ended, not that every billing record is settled; failed work may retain durable pending/unknown evidence for later reconciliation. Diagnostics report fixed work categories without provider bodies or raw SQL errors.
56
+
57
+ The [tracker unit tests](../src/modules/usage/background-work.test.ts) check registration before execution, late children, stopped maintenance, timeout/retry, isolation between two owners, and failure cleanup/fixed-category diagnostics. Those two unit-test owners are not two actual Kernels or databases. The public [Kernel + MySQL lifecycle tests](../src/app/kernel-usage-lifecycle.mysql.test.ts) use actual Kernels, separate test schemas, and synthetic providers to assert:
58
+
59
+ - delayed model-tool completion, late settlement, real SQL-lock waits, resource preservation on timeouts, and same-instance retry;
60
+ - ordinary text-model delivery before asynchronous settlement, close waiting for that settlement, and standalone shutdown draining before exit;
61
+ - work/resource isolation between two Kernels using the same original request ID, one original dispatch, and one settlement-ledger record;
62
+ - response cleanup and usage reconciliation each independently blocking close, reference-price refresh through SQL persistence, and stopped new maintenance;
63
+ - settlement failure retaining the original result and durable pending evidence, later reconciliation without provider redispatch, and diagnostics excluding raw errors.
64
+
65
+ The database tests explicitly require `BAILING_USAGE_TEST_MYSQL=1`. Their existence, or a default run that skips them, does not establish a passing database run or live-provider, process-crash recovery, or production-host acceptance. See the [capability/evidence index](IMPLEMENTATION_STATUS.en.md) for the historical v0.9.0 limitation.
66
+
49
67
  Multiple Kernels may share `KernelExecutionQueueV1` as a process-wide concurrency ceiling. This v1 wrapper exposes only `run()` to the Host; admission, statistics, and drain for each Kernel-local queue remain Core-owned. All Kernels in one process currently need the same `display_tz` and `display_tz_label`.
50
68
 
51
69
  ## Artifact And Schema Upgrades
@@ -46,6 +46,24 @@ await kernel.close(30_000);
46
46
 
47
47
  `managed` 模式不为每个 Kernel 创建完整定时器组;宿主必须公平调用 `tick()`,并在淘汰、升级或进程退出时调用 `close()`。`close(drainMs)` 的 0~600000 毫秒时限覆盖初始化、在途维护/tick、HTTP、InHub 与执行队列排空;排空后还会清理 Kernel 自己的企微令牌等瞬时凭证缓存。超时会保留原实例依赖并报错,宿主应在同一实例上重试或告警。`close()` 开始后的新 `initialize()` / `tick()` 不会重开资源。
48
48
 
49
+ ### usage 后台工作排空:Core v0.9.1
50
+
51
+ [Core v0.9.1](RELEASE_NOTES_v0.9.1.md) 在上述关闭时限内增加 usage 后台工作等待;**正式 v0.9.0 Tag 不包含这项关闭修复**。每个 Kernel 所使用的 `UsageRepository` 拥有独立的 [后台工作登记器](../src/modules/usage/background-work.ts),记录模型工具完成、结算、响应清理、待结算 usage 核对,以及参考价格刷新到持久化结束的工作。
52
+
53
+ `close()` 先阻止新的 Kernel HTTP 接入,并等待已接纳的 HTTP、InHub 与执行队列结束登记;随后停止该 repository 的新模型请求及新维护/价格刷新,再动态等待已有后台工作。已接纳的模型工具完成可以在关闭等待开始后登记其结算子工作,该子工作也须结束后才允许关闭资源。异步模型工具仍先返回原请求的 pending/HTTP 202;此修订不会让首次响应等待图片供应商完成。
54
+
55
+ 所有阶段共用原 `drainMs` 时限,而不是为每类工作增加新的完整时限。usage 排空超时会报错,保持 Kernel 的关闭状态并保留其依赖,不调用后续资源关闭。宿主可以等待原工作结束,再对**同一实例**重试 `close()`;不能把超时当作重新派发模型请求或业务写入的许可。成功排空只说明已登记工作已结束,不保证所有账本记录已经 settled;失败工作可保留 durable pending/unknown 证据供后续核对。日志只报告固定工作类别,不附供应商正文或原始 SQL 错误。
56
+
57
+ [登记器单元测试](../src/modules/usage/background-work.test.ts) 检查先登记后启动、晚登记子工作、维护停止、超时重试、两个 owner 的隔离,以及失败清理/固定类别诊断;这些单测的两个 owner 不是两个实际 Kernel 或数据库。[Kernel + MySQL 生命周期测试](../src/app/kernel-usage-lifecycle.mysql.test.ts) 则使用实际 Kernel、独立测试 schema 和模拟供应商,公开断言覆盖:
58
+
59
+ - 延迟模型工具完成、晚登记结算、真实 SQL 锁等待、超时保留资源与同实例重试;
60
+ - 普通文本模型先返回结果、关闭仍等待异步结算,以及 standalone shutdown 排空后才退出;
61
+ - 两个 Kernel 使用同一原请求标识时的工作/资源隔离,原请求单次派发和单条结算记录;
62
+ - 响应清理和 usage 核对分别单独阻挡关闭,以及参考价格刷新到 SQL 持久化、新维护停止;
63
+ - 结算失败仍保留原结果及 durable pending,后续核对不重派供应商请求,诊断不输出原始错误。
64
+
65
+ 数据库入口由 `BAILING_USAGE_TEST_MYSQL=1` 显式启用。测试源码存在或默认运行时被跳过,不代表实际数据库测试通过,也不代表真实供应商、进程崩溃恢复或生产宿主已完成验收。正式 v0.9.0 的历史限制另见 [能力与证据索引](IMPLEMENTATION_STATUS.md)。
66
+
49
67
  多个 Kernel 可以共享 `KernelExecutionQueueV1` 作为进程级并发上限。这个 v1 包装只向宿主暴露 `run()`;每个 Kernel 内部队列的接入、统计和排空仍由 Core 自己管理。当前同进程实例必须使用相同的 `display_tz` / `display_tz_label`。
50
68
 
51
69
  ## 制品与数据库升级
@@ -0,0 +1,123 @@
1
+ # Model services and plan billing
2
+
3
+ This optional lightweight model billing gateway is introduced in Core 0.9.0. Administrators configure provider connections, reference prices and plans, then grant them to accounts. Local agents continue to orchestrate reasoning, tool search, image generation and business actions. The Hub does not take over host orchestration or charge per user turn or task step. [简体中文](MODEL_BILLING.md).
4
+
5
+ ## One plan, one allowance
6
+
7
+ For example, a monthly plan may sell for 300 USD and provide a 100 USD allowance with a 1.5 multiplier, two conversation models and one image tool. A request costing 0.20 USD at reference prices deducts 0.30 USD and leaves an actual allowance ratio of 99.70%. Summaries expose precise values and separate display strings; percentage display may round down. Models and tools share the allowance.
8
+
9
+ - **Periodic plans:** `priceUsd` is the sale price; explicit positive `periodAllowanceUsd` is the USD allowance per day, week or month. Customers see a percentage using that allowance as its denominator.
10
+ - **Credit packs:** `priceUsd` is the one-time USD allowance; `periodAllowanceUsd` is rejected. Customer Credits use a fixed 1000 Credits per USD with no separate credit ledger.
11
+ - `duration` controls validity separately from reset periods. A final partial period still receives the full allowance. Expiration stops new requests; unused allowance does not roll over. Daily, weekly and monthly periods retain the original grant time and UTC anchor. Payment, exchange rates, refunds and product pricing belong to the business application.
12
+ - `multiplier` applies uniformly across a plan; there are no separate model multipliers within it.
13
+ - Existing grants read the current plan service set and multiplier by plan ID. Price, allowance, period and validity are fixed when granted. Template price changes apply to future grants and do not reset active account balances.
14
+ - Removing a service does not remove allowance. Plans may have no available models and return an empty catalog. A plan still used by an effective grant requires its use relationship to be resolved before removal. Historical settlement evidence is retained.
15
+
16
+ Input, output and total Tokens remain raw usage fields for administration and history. They are neither allowance limits nor percentage denominators. Image services that provide no Tokens do not receive invented counts.
17
+
18
+ ## Reference prices
19
+
20
+ The current reference source is OpenRouter's public model and image endpoint price catalog, bound to an exact `modelId + endpointId`. Actual calls use the administrator's credentials, URL and model identifier. A reference price does not represent another provider's paid price or invoice; operators must verify the mapping.
21
+
22
+ Access triggers a background refresh after the six-hour cache lifetime; administrators can also synchronize explicitly. A failed catalog fetch may retain an existing quote and expose its stale state. A successful refresh that identifies unsupported endpoint rules blocks new pricing requests rather than treating them as free. Each request saves its price and multiplier snapshot, so later changes never recalculate history.
23
+
24
+ Charge = actual provider metering × reference unit price × plan multiplier. Adapters map Token, image-count and supported image-pixel metering. Unreliable mappings keep `billing_state=pending` rather than guessing zero cost. An arbitrary provider `cost` field cannot replace the stored price snapshot.
25
+
26
+ Amounts use twelve-decimal fixed precision. Positive balances admit new requests and actual charges settle asynchronously; concurrency can create overage, which is recorded, while depleted balances block new requests. Settlement does not interrupt streaming, and an earlier pending settlement does not block every subsequent independent task.
27
+
28
+ ## Models and tools
29
+
30
+ Services have `chat` or `tool` purpose:
31
+
32
+ - Conversation models populate the model picker; responses and streaming chunks return directly to the local host.
33
+ - Model tools have a separate catalog of names, purpose, parameters, output and callable state. Hosts inject and execute those tools.
34
+ - Initial executable adapters support text-to-image through Aliyun OpenAI Images-compatible, native DashScope and OpenRouter Images APIs. Requests persist dispatch evidence, return `202/pending` and finish asynchronously.
35
+ - Video, voice and custom capabilities may be declared. Without an execution adapter they have `callable=false`; declarations do not imply generation support.
36
+ - Image results are URL or Base64. Hosts may reuse the existing attachment space for durable or business use. Image generation does not automatically change business data.
37
+
38
+ Image adapters accept only declared, supported text-to-image parameters. An attachment reference cannot stand in for a provider-accessible URL. Aliyun has two explicit adapters: `aliyun-image` uses OpenAI Images compatibility and `aliyun-image-native` uses native DashScope. Credentials may use the standard service root, `/api/v1` or `/compatible-mode/v1`; the native adapter maps parameters to a fixed native path on the same origin. Errors never trigger an automatic protocol, region or model switch and retry.
39
+
40
+ ## Client API
41
+
42
+ Discover `model_gateway.supported=true` in `GET /usage/v1/capabilities`. Its schema is `bailing.model-gateway.v1`, with `billing_unit=USD`, `orchestration=host` and `turn_required=false`.
43
+
44
+ | Endpoint | Purpose |
45
+ | --- | --- |
46
+ | `GET /usage/v1/model/models` | Conversation models in the account's plan, using configured labels |
47
+ | `GET /usage/v1/model/tools` | Plan tool declarations and callable state |
48
+ | `GET /usage/v1/model/summary` | Remaining allowance, period and customer presentation |
49
+ | `POST /usage/v1/model/requests` | One conversation-model request |
50
+ | `POST /usage/v1/model/requests/stream` | Streaming using the same request contract |
51
+ | `POST /usage/v1/model/tools/requests` | `{operation_id,service_id,arguments,conversation_id?,turn_id?}` |
52
+ | `GET /usage/v1/model/requests/{operation_id}` | Read the original result without calling or generating again |
53
+ | `POST /usage/v1/model/requests/{operation_id}/cancel` | Cancel further result use while retaining incurred usage |
54
+
55
+ Persist the original `operation_id` locally. Missing responses, offline reopening and uncertain outcomes require querying the original request, never generating again with another ID. The same ID and content dispatch only once; different content with the same ID conflicts. New actions are distinct from recovery. Late usage after cancellation remains recorded and cannot resume a finished host turn.
56
+
57
+ Responses expose `result_state`, `billing_state`, `response`, raw `usage` (possibly absent), `raw_usage`, `reference_cost_usd`, `billed_usd` and `overage_usd`. `billing_rate` includes plan revision, multiplier and price snapshot. Results have bounded retention; `response_expired` does not authorize re-dispatch.
58
+
59
+ Trusted backends retain the existing identity-exchange entry point. `model_access: token_gateway` identifies plan-scoped credentials, not a legacy Token allowance mode; `service` remains restricted to one model. Identity, business authority, fixed session scope, approvals and business-call archives remain independent and are not expanded by a plan.
60
+
61
+ Console endpoints use `/admin/api/usage/billing/`. Business backends can use `/usage/v1/external/billing/plans` and `/accounts/{id}/summary|grant|control`, retaining source ownership, permissions and idempotent grants.
62
+
63
+ ## Installation
64
+
65
+ From public Core 0.8.0, apply added `063_usage_model_billing.sql` and `064_period_plan_allowance.sql` through the official migrator. Fresh installations apply all outstanding files. Normal upgrades retain real data and require no old-schema purge. Instances already running a 063 billing preview follow the [period allowance migration](PERIOD_ALLOWANCE_UPGRADE.en.md) for their original snapshots. There are no legacy Token allowance, per-turn or per-model-multiplier interfaces. Maintenance of abandoned development schemas is not a customer upgrade requirement and test-data cleanup is not part of public SQL. See the [v0.9.0 upgrade guide](UPGRADE_v0.9.0.en.md).
66
+
67
+ ## Configuration readiness and discovery
68
+
69
+ A service being `active` is not sufficient to call it: executable services also need explicit reference-model/endpoint bindings and usable cached quotes. The console exposes `availability` with `state`, `code` and `message`, and validates the quote before saving an active executable service. A plan cannot newly select an unready service; existing selections can remain or be removed without recreating accounts or changing allowance. External provisioning can stage declarations, but staging never makes them callable.
70
+
71
+ Both `/usage/v1/model/models` and `/usage/v1/model/tools` return only ready entries in `items`. `unavailable_items` contains unavailable service IDs, labels, revisions and reasons within the current plan/credential scope, without provider credentials or tool schemas. The default conversation model is ready or `null`. Hosts must not automatically switch models or replay requests when a service becomes unavailable. Refresh the catalog after configuration is fixed; no reauthorization or allowance reset is required. Existing SDKs pass these additive fields through; `items` alone is sufficient for a safe picker and callable registry.
72
+
73
+ - `USAGE_PRICE_NOT_CONFIGURED`: missing or invalid reference binding.
74
+ - `USAGE_PRICE_UNAVAILABLE`: no synchronized quote, or the fixed endpoint disappeared.
75
+ - `USAGE_PRICE_UNSUPPORTED`: unsupported endpoint metering rules.
76
+ - `MODEL_TOOL_ADAPTER_NOT_READY`: declaration only, without an execution adapter.
77
+
78
+ Configuration failures precede admission or provider dispatch and use `next_action=contact_operator`, not automatic retry. Discovery uses the same cached quote as admission and neither generates content nor waits for remote price lookup. A valid stale quote can remain usable during a catalog outage with a background refresh. Readiness does not guarantee provider availability or complete metering; missing actual usage remains pending settlement, never an invented fee.
79
+
80
+ ## Generation and billing states are separate
81
+
82
+ - `result_state=pending`: work is ongoing; query the original ID without another generation.
83
+ - `complete`: use the result immediately even if `billing_state=pending`; settlement does not block it.
84
+ - `failed`: confirmed rejection, such as an absent API, invalid parameters or denied access. `dispatch=rejected`; stop waiting and show the safe error without automatic resubmission. Confirmed rejection without generation closes with zero charge.
85
+ - `unknown`: a disconnect, server error or incomplete result leaves execution uncertain. Stop the generating indicator and retain the ID for inspection; do not change ID or endpoint and retry. Other independent requests remain possible.
86
+ - `cancelled`: remain cancelled; late results and charges do not re-enable a tool or resume a finished turn.
87
+
88
+ Failure `error` contains only `code`, fixed safe `message`, optional `http_status / provider_code / provider_request_id`, `retryable=false` and `next_action`. Provider raw error bodies, prompts, secrets and URLs are not stored or returned as errors. HTTP 408, 409 and 5xx do not prove non-execution.
89
+
90
+ Hub asynchronous admission and provider task protocols are separate. Current native/compatible image adapters perform one provider request in the background; original-ID lookup reads persisted results. Without a provider task ID, provider-task recovery must not be claimed. Historical unknown outcomes are not guessed into failure; original evidence and price snapshots remain.
91
+
92
+ ## Removing plans and retaining history
93
+
94
+ Plans are soft-deleted with their original IDs. Removal checks active, unexpired grants currently referenced by active accounts, including future-start grants. Older grants, expired grants, disabled accounts and suspended grants do not prevent removal. Suspending a template stops new grants without terminating existing ones.
95
+
96
+ Historical grants, pools, ledger and request snapshots remain. Already-dispatched requests recover and settle against their original snapshots without moving to a new plan or re-dispatching. Restoring an account does not restore a removed plan; renewed use requires a valid grant.
97
+
98
+ ## Archiving and restoring accounts
99
+
100
+ Disabled personal and shared organization accounts can be archived. Default lists hide them while retaining the original account ID, trusted identity, member states, grants, allowance, requests and ledger associations. History does not block archiving; integrity problems must be repaired first. Source account scopes remain unchanged but cannot use archived accounts.
101
+
102
+ Archiving revokes existing usage credentials and blocks new requests, grants and membership/account-state changes. Already-dispatched requests still save results and settle idempotently under original snapshots. Logging in again under the same identity does not create a replacement account or replenish allowance.
103
+
104
+ Administrators restore an original account from Accounts and Members → Archived. Restoration returns it to disabled state, does not restore revoked members or credentials and does not reset allowance. Re-enable and log in again to use it; a removed or expired plan requires a valid grant. The legacy `deleted` marker is not revived through restoration.
105
+
106
+ - List: `GET /admin/api/usage/accounts?view=current|archived`, default `current`, with existing pagination. Client account lists omit archived accounts.
107
+ - Archive: existing `DELETE /admin/api/usage/accounts/:id` and preview, requiring a disabled account, current revision and `request_key`.
108
+ - Restore: `POST /admin/api/usage/accounts/:id/restore` with `expected_revision` and `request_key`, requiring administrator `usage:write`.
109
+ - Both operations replay the original receipt idempotently without overriding later management decisions.
110
+
111
+ These administration changes add no tables or SQL migration and independently require no SDK/DSH changes.
112
+
113
+ ## Manually resetting one account's allowance
114
+
115
+ Under Account Usage → Usage Details → Reset Allowance, administrators with `usage:write` and `usage:adjust` can reset an active account's effective Hub-managed plan. A periodic plan regains its original period allowance (100%) and starts a new period at the server-confirmed reset time. A credit pack regains original Credits without an automatic reset date. Remaining balances do not stack and expiration is not extended. If expiration ends the final period first, no later reset date is shown.
116
+
117
+ - `POST /admin/api/usage/billing/accounts/:id/reset` requires `request_key` and the current grant's `expected_revision`.
118
+ - Future, expired or suspended grants and disabled/archived accounts cannot reset. Backend-managed allowance must be adjusted by its owning source.
119
+ - A new current grant reuses the existing allowance terms and pool mechanism. Template price changes do not change its restored amount; service selection and the current multiplier keep their existing rules.
120
+ - Original grants, requests, usage and ledger remain. Late results from already-dispatched requests settle against the original pool without charging the new allowance. Undispatched old requests retain their original grant-revision checks and do not automatically re-dispatch.
121
+ - Idempotent replay returns the original receipt. Revision checks prevent duplicate concurrent resets. The receipt records `reset.previousGrantId`, `reset.actor` and `reset.at` to identify the original grant and operator.
122
+
123
+ Existing summaries return the new balance and next reset date. This feature adds no SQL migration and independently requires no SDK/DSH or backend changes.
@@ -0,0 +1,125 @@
1
+ # 模型服务与套餐计费
2
+
3
+ 本模块为可选的微型模型计费网关,从 Core 0.9.0 提供。[English](MODEL_BILLING.en.md)。管理员添加模型连接、选择参考价格,创建套餐并开通给账户;本地智能体继续决定如何思考、搜索工具、生成图片及执行业务动作。中枢不接管客户端编排,也不按用户轮次或任务步数扣费。
4
+
5
+ ## 一个套餐,一份额度
6
+
7
+ 例如,为团队开通一个售价 300 USD、每月额度 100 USD 的套餐,统一倍率为 1.5,勾选两个对话模型及一个图片工具。一次模型请求的参考费用为 0.20 USD,则套餐扣除 0.30 USD,实际剩余额度占比为 99.70%。摘要同时提供精确数值与用于界面的显示字符串;百分比显示可向下取整。不同模型和工具共用这份额度。
8
+
9
+ - **周期套餐**:`priceUsd` 是售价,`periodAllowanceUsd` 必须明确填写且大于零,是每个重置周期可用的美元额度;周期可为日、周、月。客户显示剩余百分比,分母为周期额度。
10
+ - **额度包**:`priceUsd` 是一次开通的美元额度,不接受 `periodAllowanceUsd`。客户显示积分,固定 1 USD = 1000 积分,无独立积分账本。
11
+ - `duration` 决定开通有效期,与重置周期分开;最后不足一个完整周期仍提供完整周期额度,到期停止,未用额度不结转。日、周、月继续按原开通时间及 UTC 锚点重置。支付、汇率、退款及商品定价归接入方负责。
12
+ - `multiplier` 是套餐统一倍率,不能为同一个套餐的不同模型配置另一套倍率。
13
+ - 已开通账户按套餐 ID 读取当前模型集合与倍率;售价、周期额度、周期和有效期在开通时固定。修改套餐金额用于以后开通,不会重置正在使用的账户余额。
14
+ - 删除套餐内某个模型不会删除账户额度。允许套餐没有可用模型,此时客户目录为空;删除套餐本身须先解除当前使用关系。已有真实结算的历史记录保留审计证据。
15
+
16
+ 输入、输出和总 Token 数仍是原始用量字段,可供后台和使用明细查看;它们不是额度上限或百分比分母。没有提供 Token 的生图服务不伪造 Token 值。
17
+
18
+ ## 参考价格
19
+
20
+ 当前参考来源为 OpenRouter 的公开模型及图片端点价格目录,绑定精确 `modelId + endpointId`。实际模型调用仍使用管理员配置的模型凭证、URL 与型号。参考价格不表示其他服务商的实际账单,管理员应核对模型对应关系。
21
+
22
+ 价格缓存六小时后由访问触发后台刷新,管理员也可以主动同步。暂时拉取失败时可使用已存价格并显示过期状态;成功刷新明确发现该端点规则不支持时拒绝新的计价请求,不能当作免费。每个请求保存自己的价格与套餐倍率快照;后来调价不会重算旧请求。
23
+
24
+ 费用 = 供应商返回的实际计量 × 参考单价 × 套餐倍率。Token 单价、图片数量和支持的图片像素计价由适配器映射;无法可靠对应的计量保持 `billing_state=pending`,不会猜测零成本。供应商响应里的任意 `cost` 字段不能覆盖已保存的价格快照。
25
+
26
+ 内部采用十二位小数定点金额。余额为正时允许新请求,实际费用异步结算;并发请求可能带来小额超出,记录超出金额并阻止余额耗尽后的新请求。不会为了实时结算打断正在输出的内容,也不会因上一笔待核算而禁止全部后续任务。
27
+
28
+ ## 模型与工具
29
+
30
+ 模型服务用途分为 `chat` 与 `tool`:
31
+
32
+ - 对话模型进入模型选择器,模型响应和流式片段直接交回本地宿主。
33
+ - 模型工具进入独立工具目录,包含名称、用途、参数、输出及可调用状态,由宿主注入并执行。
34
+ - 首批执行适配为阿里云 OpenAI Images 兼容接口、DashScope 原生接口及 OpenRouter Images 接口的文生图。图片请求先保存派发记录,返回 `202/pending` 后异步完成。
35
+ - 视频、语音及自定义能力可以保存声明,尚无执行适配时明确 `callable=false`;声明不代表已支持生成。
36
+ - 图片结果为 URL 或 Base64。若要长期使用或写入业务系统,宿主按需复用已有附件空间。生成图片不会自动修改商品或其他业务数据。
37
+
38
+ 当前图片适配只接受已声明并受支持的文生图参数。附件引用不能冒充供应商可访问的文件地址。阿里云提供两个显式适配:`aliyun-image` 使用 OpenAI Images 兼容协议,`aliyun-image-native` 使用 DashScope 原生协议。同一凭据可配置为标准服务根地址、`/api/v1` 或 `/compatible-mode/v1`;原生适配在同一 origin 下使用固定的原生路径,将文生图参数转换为该协议。不会遇到错误就自动切换协议、地区或模型重试。
39
+
40
+ ## 客户端接口
41
+
42
+ `GET /usage/v1/capabilities` 的 `model_gateway.supported=true` 为接入入口,schema 为 `bailing.model-gateway.v1`,`billing_unit=USD`、`orchestration=host`、`turn_required=false`。
43
+
44
+ | 接口 | 用途 |
45
+ | --- | --- |
46
+ | `GET /usage/v1/model/models` | 当前账户套餐中的对话模型;显示管理员配置的 label |
47
+ | `GET /usage/v1/model/tools` | 当前账户套餐中的工具声明、可调用状态 |
48
+ | `GET /usage/v1/model/summary` | 剩余金额、周期及客户展示 presentation |
49
+ | `POST /usage/v1/model/requests` | 单次对话模型请求 |
50
+ | `POST /usage/v1/model/requests/stream` | 同一协议的流式请求 |
51
+ | `POST /usage/v1/model/tools/requests` | `{operation_id,service_id,arguments,conversation_id?,turn_id?}` |
52
+ | `GET /usage/v1/model/requests/{operation_id}` | 查原结果,不重新调用模型或生成工具 |
53
+ | `POST /usage/v1/model/requests/{operation_id}/cancel` | 取消继续使用结果;保留已发生用量 |
54
+
55
+ 所有请求在本地持久保存原 `operation_id`。丢失回包、断网重开、结果不确定时只查询原请求,不能换 ID 重发生成。相同 ID、相同内容只派发一次;相同 ID 不同内容明确冲突。新动作和原调用恢复严格区分。取消的晚返回仍记录用量,不恢复已结束的本地轮次。
56
+
57
+ 响应分别提供 `result_state`、`billing_state`、`response`、原始 `usage`(可为空)、`raw_usage`、`reference_cost_usd`、`billed_usd`、`overage_usd`。`billing_rate` 包含套餐修订、统一倍率和参考价格快照。`response` 有限期保存,过期返回 `response_expired`,不能因此重发原操作。
58
+
59
+ 可信业务后端使用原身份交换接口。`model_access: token_gateway` 是套餐范围凭证的身份标记,不是旧 Token 额度模式;`service` 仍严格限制单个模型。身份、原业务授权、固定会话范围、审批和业务调用归档独立存在,不因套餐扩大授权。
60
+
61
+ 后台接口统一 `/admin/api/usage/billing/`;业务后端可使用 `/usage/v1/external/billing/plans` 及 `/accounts/{id}/summary|grant|control`,沿用来源所有权、权限和幂等开通规则。
62
+
63
+ ## 安装边界
64
+
65
+ 从公开 Core 0.8.0 升级时,通过正式迁移器应用新增的 `063_usage_model_billing.sql` 及 `064_period_plan_allowance.sql`;首次安装应用全部未执行文件。正常升级保留真实数据,无需清退旧结构。已经部署过 063 计费预览的实例按[周期额度升级说明](PERIOD_ALLOWANCE_UPGRADE.md)转换各自原快照。模块不提供旧 Token 额度、按轮收费或逐模型倍率接口。废弃开发结构的维护不属于客户升级要求,不将测试数据清理混入公共 SQL。参见 [v0.9.0 升级指南](UPGRADE_v0.9.0.md)。
66
+
67
+ 参考文档:[OpenRouter 图片接口](https://openrouter.ai/docs/guides/overview/multimodal/image-generation)、[阿里云图片接口](https://help.aliyun.com/zh/model-studio/qwen-image-generation-and-editing-api-reference)。
68
+
69
+ ## 配置就绪与能力发现
70
+
71
+ 服务状态为 `active` 不代表已经可调用:可执行服务还必须明确绑定参考模型与端点,并具有可用缓存报价。控制台服务列表的 `availability` 返回 `state`、`code` 和 `message`;保存启用的可执行服务前会验证报价。套餐不能新增选择未就绪服务,已有选择可以保留或移除,无需重建账户或改变额度。外部开通流程可以暂存声明,暂存服务不会因此变为可调用。
72
+
73
+ `/usage/v1/model/models` 与 `/usage/v1/model/tools` 的 `items` 只返回就绪项目。`unavailable_items` 提供当前套餐/凭证范围内未就绪服务的 ID、名称、修订和原因,不包含供应商凭据或工具 schema。默认对话模型必须是就绪项,否则为 `null`。选中模型不可用时,宿主不能自动切换模型或重放失败请求;管理员修复配置后刷新目录即可,无需重新授权或重置额度。旧 SDK 会传递这些新增字段;仅使用 `items` 也能构建安全的选择器与可调用工具目录。
74
+
75
+ - `USAGE_PRICE_NOT_CONFIGURED`:参考绑定缺失或不合法。
76
+ - `USAGE_PRICE_UNAVAILABLE`:无同步报价,或固定端点已消失。
77
+ - `USAGE_PRICE_UNSUPPORTED`:端点计量规则尚不支持。
78
+ - `MODEL_TOOL_ADAPTER_NOT_READY`:只有声明,没有执行适配。
79
+
80
+ 这些配置错误发生在准入或供应商派发前,使用 `next_action=contact_operator`,不能自动重试。目录检查与准入使用同一缓存报价,不生成内容,也不等待远程价格查询。价格目录暂时不可用时,合法的过期报价仍可使用,并触发后台刷新。就绪不保证供应商可用性或完整计量回执;缺少实际用量仍待结算,不编造费用。
81
+
82
+ ## 生成结果与计费状态分开
83
+
84
+ - `result_state=pending`:供应商请求仍在进行,宿主按原 ID 查询,不发起第二次生成。
85
+ - `complete`:立即使用图片,即使 `billing_state=pending`;结算不阻塞结果。
86
+ - `failed`:已获得明确拒绝(例如不存在的接口、无效参数、权限拒绝),`dispatch=rejected`,停止等待,显示安全错误;不自动重发。当前已确认拒绝无生成的请求以零扣费关闭。
87
+ - `unknown`:连接断开、服务器错误或无法解析完整结果,执行结果确实不确定。停止“正在生成”的展示,保留原 ID 供核对;不能自动换 ID 或切接口重发。不阻塞其他独立模型请求。
88
+ - `cancelled`:维持取消;晚到的结果和费用不重新启用宿主工具或恢复已结束轮次。
89
+
90
+ 失败回执的 `error` 仅包含 `code`、固定安全文案 `message`、可选的 `http_status / provider_code / provider_request_id`、`retryable=false` 及 `next_action`。不保存或返回供应商原始错误正文、提示词、密钥或地址。HTTP 408、409 与 5xx 不等于已证明没有执行。
91
+
92
+ 中枢异步受理与供应商异步任务协议是不同层次:当前原生/兼容图片适配都是单次供应商请求在后台完成;原 ID 查询只读取已持久化结果。没有供应商任务 ID 时不能宣称已具备供应商任务恢复。历史 unknown 不因本次修复被猜测改成失败。原记录和原价格快照保留。
93
+
94
+ ## 套餐移除与历史记录
95
+
96
+ 删除套餐采用保留原标识的软删除。只检查启用账户当前指向的、启用且未到期的开通记录(包括待生效记录);旧开通、已到期、已停用账户或已暂停开通不阻止移除。停用套餐模板仅停止新开通,不会终止现有账户的套餐。
97
+
98
+ 历史开通、原额度池、账本与请求快照继续保留。已派发原请求仍按原快照恢复和结算,不转移到新套餐或再次派发。恢复账户身份不会恢复已删除的套餐;重新使用需开通有效套餐。
99
+
100
+ ## 账户移除与恢复
101
+
102
+ 个人账户和组织共享账户均可在停用后移除(`archived`)。默认列表隐藏,原账户 ID、可信身份、成员状态、套餐开通、额度、请求及账本保持原关联。已有历史不阻止移除,完整性异常须先修复。来源配置中的账户范围保持不变,但不能使用已移除账户。
103
+
104
+ 移除撤销该账户现有使用凭证,阻止新请求、套餐开通、成员及账户状态修改。已派发请求仍按原快照保存结果并幂等结算。同一身份再次登录不会创建替代账户或补发额度。
105
+
106
+ 管理员在“账户与成员 → 已移除”查看并恢复原账户。恢复只改为停用状态,不恢复被撤销的成员或旧凭证,不重置额度。需要使用时再启用并重新登录;若原套餐已删除或到期,需开通有效套餐。原 `deleted` 删除标记不通过恢复接口复活。
107
+
108
+ - 管理列表:`GET /admin/api/usage/accounts?view=current|archived`,默认 `current`,支持原分页参数。客户端账户列表不包含已移除账户。
109
+ - 移除:沿用 `DELETE /admin/api/usage/accounts/:id` 及预览接口,要求账户停用、当前修订与 `request_key`。
110
+ - 恢复:`POST /admin/api/usage/accounts/:id/restore`,请求含 `expected_revision`、`request_key`,要求管理员 `usage:write`。
111
+ - 两项变更均按原请求幂等;旧回执重试不覆盖后续管理决定。
112
+
113
+ 不新增表或 SQL 迁移;SDK/DSH 无需调整。
114
+
115
+ ## 单账户手动重置额度
116
+
117
+ 控制台“账户用量 → 用量详情 → 重置额度”允许有 `usage:write` 与 `usage:adjust` 权限的管理员,为启用账户重置中枢维护的当前有效套餐。周期套餐恢复至原开通记录的周期额度(100%),从服务端确认重置的时刻重新起算周期;额度包恢复至原始积分,无自动重置时间。剩余额度不叠加,套餐到期时间不延长。最后一个周期若先到期,仍以到期时间结束,不显示到期后的下次重置时间。
118
+
119
+ - `POST /admin/api/usage/billing/accounts/:id/reset`,请求为 `request_key` 与当前开通记录的 `expected_revision`。
120
+ - 原套餐未生效、已到期、已暂停,或账户停用/移除时不能重置。业务后端维护的额度由原来源调整。
121
+ - 复用已有开通快照与额度池,创建新的当前开通记录;复制原额度条款,不因套餐模板后来改价而改变本次满额值。原模型目录和当前套餐倍率继续遵循既有规则。
122
+ - 原开通、请求、计量和账本保留;已派发请求晚到的结果仍归原额度池结算,不扣新额度。尚未派发的旧请求继续遵循原开通修订校验,不自动重新派发。
123
+ - 原请求幂等重试只返回原回执;并发变更通过修订号检查,避免重复重置。变更回执记录 `reset.previousGrantId`、`reset.actor`、`reset.at`,可关联原开通与操作人。
124
+
125
+ 沿用现有摘要接口返回新的剩余额度及下次重置时间,不新增 SQL 迁移,不需要客户端 SDK/DSH 或业务后端改造。
@@ -0,0 +1,31 @@
1
+ # Separating periodic plan price from allowance
2
+
3
+ This guide applies to Core 0.9.0 and explains periodic allowance terms and migration of existing billing snapshots. Public Core 0.8.0 did not include this billing module. Its normal upgrade adds 063/064 through the official migrator and requires no real-data purge. See the [v0.9.0 upgrade guide](UPGRADE_v0.9.0.en.md).
4
+
5
+ ## Period allowance contract
6
+
7
+ Periodic plans require both `priceUsd > 0` (sale price) and `periodAllowanceUsd > 0` (USD available per period), with at most twelve decimal places and a maximum of 1,000,000,000. Credit packs continue to use `priceUsd` as allowance and reject `periodAllowanceUsd`. Unknown fields remain rejected. There is no fallback to sale price, legacy field alias, turn limit or request-count limit.
8
+
9
+ For example, a weekly plan selling for 100 USD with a 20 USD allowance has 10 USD / 50% remaining after a 10 USD charge and regains 20 USD in the next week. A final partial week still receives the full allowance; expiration blocks new requests. Late settlement belongs to the original period, with its original multiplier, price and pool. Template edits affect future grant terms and do not automatically re-grant existing accounts.
10
+
11
+ `GET /admin/api/usage/billing/plans` provides `period_allowance_supported: true`. Without this marker, the frontend may preview the field but cannot save periodic plans. The marker describes code capability, not proof of database migration; verify the migration ledger and billing-structure readiness as well.
12
+
13
+ ## Instances that already deployed a billing preview
14
+
15
+ These data checks apply only when 063 billing data already exists and periodic snapshots lack the new field. Separate cleanup of abandoned test schemas is outside this process and must not be applied to real customer data.
16
+
17
+ 1. Coordinate all Core instances, frontends and plan writers sharing the state database on the new contract. Back up billing tables and migration ledger and retain previous artifacts. Stop old-version writes, including maintenance settlement and backend grant/control calls. Retain original IDs and evidence for dispatched requests; do not dispatch replacements.
18
+ 2. Apply the outstanding `064_period_plan_allowance.sql` through the official Core schema migrator (`npm run db:init` for source installations), keeping its ledger and checksum checks.
19
+ 3. Each periodic record missing the field receives its own original `priceUsd`, not the current template price. This covers plan `config_json`, grant snapshot `config_json`, request `grant_json` and grant/control replay `result_json.config`, including history. Original allowance semantics and cached request hashes remain unchanged. Explicit new allowances are never overwritten; credit packs are untouched. Original pools, ledger, charges, revisions and expiration are not rewritten.
20
+ 4. Confirm positive new fields in all four periodic JSON forms and no new field on credit packs. Compare record counts, original prices, pool allowances and ledger amounts. Start the new Core and UI, then check capability discovery, historical summaries, original-ID lookup and idempotent replay. Runtime does not infer missing fields; do not start it expecting automatic compatibility.
21
+ 5. Edit templates explicitly for later price or allowance changes. New terms apply to future grants; template edits are not migration of original grants. Use the normal provisioning flow if a new grant is needed.
22
+
23
+ The SQL converts only missing fields and retains explicit allowances. After interruption, keep writers stopped until the official migrator completes and checks pass. Do not manually change the migration ledger or replay recorded files.
24
+
25
+ ## Rollback and verification
26
+
27
+ Once the new fields exist, old Core's strict validation cannot read those configurations. Rollback requires stopped writers and coordinated backup/artifact restoration. If new requests or charges exist, retain them and repair forward instead of discarding the ledger through an older backup.
28
+
29
+ Check positive values and precision, rejection of periodic fields on credits, percentage calculations, month-end rules, independence of template edits and original snapshots, period renewal, late original-period settlement, final partial periods and expiration. Migration checks include differing template/grant amounts, original-request settlement, replay of original idempotency keys and preservation of explicit new allowances.
30
+
31
+ [Model billing contract](MODEL_BILLING.en.md) · [简体中文](PERIOD_ALLOWANCE_UPGRADE.md)
@@ -0,0 +1,31 @@
1
+ # 周期套餐售价与额度拆分
2
+
3
+ 本说明适用于 Core 0.9.0,解释周期额度契约及已存在计费快照的迁移。公开 Core 0.8.0 尚无此计费模块,正常升级通过正式迁移器新增 063/064,不要求清退真实数据。完整步骤见 [v0.9.0 升级指南](UPGRADE_v0.9.0.md)。
4
+
5
+ ## 周期额度契约
6
+
7
+ 周期套餐需同时提供 `priceUsd > 0`(售价)与 `periodAllowanceUsd > 0`(每周期 USD 额度),金额最多十二位小数、上限 1,000,000,000。额度包继续以 `priceUsd` 提供额度,拒绝 `periodAllowanceUsd`。未知字段继续拒绝,无售价回落、旧字段别名、轮次或请求次数限制。
8
+
9
+ 例如周套餐售价 100 USD、周期额度 20 USD,结算 10 USD 后剩余 10 USD / 50%;跨周重新获得 20 USD。有效期最后不足一周仍获得完整 20 USD,到期后停止新请求。原请求的晚结算归入原周期,原倍率、参考价格和额度池保持不变。套餐编辑只影响后续开通的额度条款,原账户不自动重新开通。
10
+
11
+ `GET /admin/api/usage/billing/plans` 提供 `period_allowance_supported: true`。旧 Core 不返回此标记时,前端只能预览周期额度,不能保存周期套餐。该标记表示代码能力,不能单独证明数据库已迁移;应同时核对迁移账本和计费结构就绪状态。
12
+
13
+ ## 已部署计费预览实例的迁移
14
+
15
+ 仅在实例已经存在 063 计费数据且周期快照缺少新字段时,需要以下数据核对。废弃测试结构的独立清理不属于本升级流程,不能用于真实客户数据。
16
+
17
+ 1. 确认所有共用状态库的 Core、前端及套餐配置调用方采用新契约。备份计费表与迁移账本,保留旧产物;停止旧版本写入,包括维护结算及业务侧开通/控制请求。已派发请求保留原 ID 与证据,不能重派。
18
+ 2. 使用官方 Core schema migrator(源码入口 `npm run db:init`)执行未应用的 `064_period_plan_allowance.sql`,按原迁移账本和摘要规则处理。
19
+ 3. 迁移为每条缺少新字段的周期记录写入其自身旧 `priceUsd`,不是当前套餐售价。范围为套餐 `config_json`、开通快照 `config_json`、原请求 `grant_json`、开通/控制幂等缓存 `result_json.config`,包括历史记录。原历史额度语义和缓存请求哈希不变;已有明确新额度不覆盖,credits 不修改。原额度池、账本、扣费、修订和有效期均不重写。
20
+ 4. 核对四类周期 JSON 均有合法正数新字段、credits 无新字段。比较迁移前后记录数、原价格、原池额度和账本金额;启动新 Core 与配套界面,验收能力位、历史摘要、原 ID 查询与幂等重放。运行时不会推断缺失字段,不能先启新版本再等待自动兼容。
21
+ 5. 后续调整售价或周期额度时显式编辑套餐;新条款用于以后开通,不能把模板编辑当作原开通迁移。需要重新开通时按正常开通流程处理。
22
+
23
+ SQL 只转换缺字段记录,不覆盖已有明确额度;中断后保持停写,按正式迁移器完成剩余步骤并核对后再恢复使用。不要手工修改迁移账本或重跑已记账文件。
24
+
25
+ ## 回退与验证
26
+
27
+ 新字段写入后,旧 Core 的严格校验不能读取新配置。回退需要停写并协调备份和旧产物;如已发生新请求或计费,保留新记录并修复,不能直接恢复旧备份丢弃账本。
28
+
29
+ 检查显式正数与金额精度、credits 拒收周期字段、周期百分比、月末规则、模板编辑与原快照独立、跨周期恢复、原周期晚结算以及最后短周期和到期行为。迁移核对包括模板与原开通金额不同、原请求结算、原幂等键重放及已有新额度不覆盖。
30
+
31
+ [模型计费契约](MODEL_BILLING.md) · [English](PERIOD_ALLOWANCE_UPGRADE.en.md)
package/docs/README.en.md CHANGED
@@ -6,6 +6,13 @@ This directory contains public documentation for the open-source BailingHub proj
6
6
 
7
7
  | Document | Purpose |
8
8
  |---|---|
9
+ | [IMPLEMENTATION_STATUS.en.md](IMPLEMENTATION_STATUS.en.md) · [Chinese](IMPLEMENTATION_STATUS.md) | Core ownership, formal releases versus main, public evidence, and uncovered scope. |
10
+ | [RELEASE_NOTES_v0.9.1.en.md](RELEASE_NOTES_v0.9.1.en.md) · [Chinese](RELEASE_NOTES_v0.9.1.md) | v0.9.1: asynchronous usage shutdown fix, public capability index, and general security governance. |
11
+ | [UPGRADE_v0.9.1.en.md](UPGRADE_v0.9.1.en.md) · [Chinese](UPGRADE_v0.9.1.md) | 0.9.0 patch upgrade, original requests, artifact manifests, and shutdown acceptance; no new SQL/APIs. |
12
+ | [RELEASE_NOTES_v0.9.0.en.md](RELEASE_NOTES_v0.9.0.en.md) · [Chinese](RELEASE_NOTES_v0.9.0.md) | v0.9.0: optional model billing, shared allowances and image tools. |
13
+ | [UPGRADE_v0.9.0.en.md](UPGRADE_v0.9.0.en.md) · [Chinese](UPGRADE_v0.9.0.md) | Upgrade from public 0.8.0, migrations 063/064 and optional host integration. |
14
+ | [MODEL_BILLING.en.md](MODEL_BILLING.en.md) · [Chinese](MODEL_BILLING.md) | Models/tools, reference prices, asynchronous settlement, archive and allowance reset contract. |
15
+ | [PERIOD_ALLOWANCE_UPGRADE.en.md](PERIOD_ALLOWANCE_UPGRADE.en.md) · [Chinese](PERIOD_ALLOWANCE_UPGRADE.md) | Separate periodic price/allowance and migrate existing preview snapshots. |
9
16
  | [RELEASE_NOTES_v0.8.0.md](RELEASE_NOTES_v0.8.0.md) · [English](RELEASE_NOTES_v0.8.0.en.md) | v0.8.0: long tasks, original receipts, attachments and upgrade boundaries. |
10
17
  | [RELEASE_NOTES_v0.7.0.md](RELEASE_NOTES_v0.7.0.md) · [English](RELEASE_NOTES_v0.7.0.en.md) | v0.7.0 shop/inventory scenarios, upgrade steps and limits. |
11
18
  | [user-guide/conversations.en.md](user-guide/conversations.en.md) | Multi-account conversations, full-text review and offline recovery for users. |
@@ -22,7 +29,7 @@ This directory contains public documentation for the open-source BailingHub proj
22
29
  | [AGENT_SUBJECT_DISPLAY.en.md](AGENT_SUBJECT_DISPLAY.en.md) | Business authorization display names: responsibilities, new approvals and existing-session synchronization. |
23
30
  | [AGENT_AUTH_API.en.md](AGENT_AUTH_API.en.md) | Agent Auth v1, PKCE, trusted business identity, and revocation. |
24
31
  | [AGENT_AUTH_API.md](AGENT_AUTH_API.md) | Chinese Agent Auth v1 protocol. |
25
- | [INVOCATION_RECEIPTS.md](INVOCATION_RECEIPTS.md) | Candidate: read an original receipt without continuing its business operation. |
32
+ | [INVOCATION_RECEIPTS.md](INVOCATION_RECEIPTS.md) | Read an original receipt without continuing its business operation. |
26
33
  | [AGENT_CLIENT_RUNTIME_API.en.md](AGENT_CLIENT_RUNTIME_API.en.md) | Agent Client Runtime v1 workspaces, turns, tools, and completion contract. |
27
34
  | [AGENT_TASK_CONTROL.en.md](AGENT_TASK_CONTROL.en.md) · [Chinese](AGENT_TASK_CONTROL.md) | Core 0.8.0: cumulative task budgets, actual dispatch, pause and SDK/DSH host integration. |
28
35
  | [AGENT_CLIENT_RUNTIME_API.md](AGENT_CLIENT_RUNTIME_API.md) | Chinese Agent Client Runtime v1 contract. |
package/docs/README.md CHANGED
@@ -8,6 +8,13 @@
8
8
 
9
9
  | 文档 | 用途 |
10
10
  |---|---|
11
+ | [IMPLEMENTATION_STATUS.md](IMPLEMENTATION_STATUS.md) · [English](IMPLEMENTATION_STATUS.en.md) | Core 能力归属、正式发行与主分支状态、公开证据和未覆盖范围。 |
12
+ | [RELEASE_NOTES_v0.9.1.md](RELEASE_NOTES_v0.9.1.md) · [English](RELEASE_NOTES_v0.9.1.en.md) | v0.9.1:异步 usage 关闭修复、公开能力索引与通用安全治理。 |
13
+ | [UPGRADE_v0.9.1.md](UPGRADE_v0.9.1.md) · [English](UPGRADE_v0.9.1.en.md) | 0.9.0 补丁升级、原请求核对、制品 manifest 与关闭验收;无新增 SQL/API。 |
14
+ | [RELEASE_NOTES_v0.9.0.md](RELEASE_NOTES_v0.9.0.md) · [English](RELEASE_NOTES_v0.9.0.en.md) | v0.9.0:可选模型计费、统一套餐额度与文生图工具。 |
15
+ | [UPGRADE_v0.9.0.md](UPGRADE_v0.9.0.md) · [English](UPGRADE_v0.9.0.en.md) | 从公开 0.8.0 升级、063/064 迁移及宿主按需接入。 |
16
+ | [MODEL_BILLING.md](MODEL_BILLING.md) · [English](MODEL_BILLING.en.md) | 模型与工具、参考价格、异步结算、账户归档和额度重置契约。 |
17
+ | [PERIOD_ALLOWANCE_UPGRADE.md](PERIOD_ALLOWANCE_UPGRADE.md) · [English](PERIOD_ALLOWANCE_UPGRADE.en.md) | 周期售价与额度拆分,以及已有计费预览快照的迁移。 |
11
18
  | [RELEASE_NOTES_v0.8.0.md](RELEASE_NOTES_v0.8.0.md) · [English](RELEASE_NOTES_v0.8.0.en.md) | v0.8.0: long tasks, original receipts, attachments and upgrade boundaries. |
12
19
  | [RELEASE_NOTES_v0.7.0.md](RELEASE_NOTES_v0.7.0.md) · [English](RELEASE_NOTES_v0.7.0.en.md) | v0.7.0:商城与库存场景、配套升级和限制。 |
13
20
  | [user-guide/conversations.md](user-guide/conversations.md) | 普通用户的多账户对话、完整沟通追溯和离线恢复指南。 |
@@ -1,3 +1,5 @@
1
- # Release notes
1
+ # Current release: Core 0.9.1
2
2
 
3
- [Core 0.8.0](RELEASE_NOTES_v0.8.0.en.md) · [Upgrade](UPGRADE_v0.8.0.en.md)
3
+ Core 0.9.1 fixes asynchronous usage shutdown, adds a public capability/evidence index, and includes general security governance. No new APIs, SQL, plan rules, or client features are introduced. SDK 0.7.0 / DSH 0.7.0 remain unchanged.
4
+
5
+ [Core 0.9.1 release notes](RELEASE_NOTES_v0.9.1.en.md) · [Upgrade guide](UPGRADE_v0.9.1.en.md) · [Billing contract](MODEL_BILLING.en.md) · [简体中文](RELEASE_NOTES_NEXT.md)
@@ -1,3 +1,5 @@
1
- # Release notes
1
+ # 当前版本:Core 0.9.1
2
2
 
3
- [Core 0.8.0](RELEASE_NOTES_v0.8.0.md) · [Upgrade](UPGRADE_v0.8.0.md)
3
+ Core 0.9.1 修复异步 usage 工作关闭等待,增加公开能力与证据索引,并纳入通用安全治理。没有新增 API、SQL、套餐或客户端功能;SDK 0.7.0 / DSH 0.7.0 不变。
4
+
5
+ [Core 0.9.1 版本说明](RELEASE_NOTES_v0.9.1.md) · [升级指南](UPGRADE_v0.9.1.md) · [计费契约](MODEL_BILLING.md) · [English](RELEASE_NOTES_NEXT.en.md)
@@ -0,0 +1,45 @@
1
+ # BailingHub v0.9.0: model services and shared plan allowances
2
+
3
+ Release pairing: **Core 0.9.0 / MCP and Agent Client SDK 0.7.0 / DSH 0.7.0**. These notes describe changes and upgrade impact relative to public Core 0.8.0.
4
+
5
+ An enterprise assistant may select a conversation model, generate a campaign image and then call an authorized business API. Administrators can now give those models and generation tools a shared allowance. The local host continues to orchestrate the conversation and task; the Hub records original requests, actual usage and settlement. Existing business permissions and approvals still apply.
6
+
7
+ ## An optional lightweight model billing gateway
8
+
9
+ Enable model billing when needed. Administrators configure a provider connection, actual model identifier, reference pricing model and endpoint, then grant a plan to a personal or shared organization account. Conversation models and model tools have separate discovery catalogs. Charges are not based on user turns or task steps.
10
+
11
+ The actual model identifier can differ from the reference catalog identifier; operators explicitly verify that mapping. OpenRouter supplies reference prices, **not the actual provider's paid price or invoice**. Each request retains its price and plan-multiplier snapshot, so later price changes do not recalculate history. Unready services stay out of callable catalog entries; hosts can show the reason and direct users to their administrator.
12
+
13
+ ## One plan, one USD allowance
14
+
15
+ Every model and tool in a plan shares its USD allowance and a single multiplier. For example, an Enterprise Assistant monthly plan may sell for 300 USD and provide 100 USD per month at a 1.5 multiplier. A request with a 0.20 USD reference cost deducts 0.30 USD, leaving an actual allowance ratio of 99.70%.
16
+
17
+ - **Periodic plans** separate sale price `priceUsd` from per-period allowance `periodAllowanceUsd`. Daily, weekly or monthly resets restore that allowance; customers see a remaining percentage whose denominator is the allowance.
18
+ - **Credit packs** use `priceUsd` as the one-time USD allowance. Customers see Credits at a fixed 1000 Credits per USD, with no separate credit ledger.
19
+ - Validity and reset periods are independent. A final partial period still provides the full allowance; expiration stops new requests and unused allowance does not roll over. Template price edits do not reset existing grant terms; the current service set and unified multiplier are read from the plan.
20
+ - The business application owns payment, currency conversion, refunds and product pricing. Raw Token counts remain usage evidence, not plan limits or percentage denominators.
21
+
22
+ ## Text-to-image tools and asynchronous settlement
23
+
24
+ Model tools declare their name, purpose, parameters and output; hosts choose and invoke them. Initial executable adapters support text-to-image through Aliyun's OpenAI Images-compatible API, native DashScope and OpenRouter Images. Video, voice and custom capabilities may be declared, but remain explicitly uncallable without an execution adapter. A saved declaration does not imply generation support.
25
+
26
+ Image requests persist dispatch evidence and finish asynchronously. Hosts query the original `operation_id`. A completed result can be used while billing awaits actual metering; missing reliable usage never becomes an invented fee or Token count. Positive balances admit requests; late concurrent settlements can create an overage, and depleted balances block new requests.
27
+
28
+ Connection loss, missing responses and unknown outcomes retain the original ID rather than creating another generation. Confirmed rejection and unknown results are distinct. Late usage after cancellation remains accountable and does not revive a finished turn. Hosts can reuse the existing attachment space for image URLs/Base64 when needed; generation does not automatically modify business data.
29
+
30
+ ## Everyday administration
31
+
32
+ - Removing a plan preserves its identity, grants, allowance pools, requests and ledger. A plan still used by an effective grant requires its use relationship to be resolved first. Suspending a template only stops new grants.
33
+ - Disabled personal and shared accounts can be archived. Restoration returns the original account to disabled state; revoked credentials and members are not restored and allowance is not replenished.
34
+ - Authorized administrators can reset an active account's effective Hub-managed plan. Periodic plans regain their original period allowance with a new period anchor; credit packs regain their original Credits. Expiration is unchanged and original in-flight requests settle against their original pool.
35
+ - Console examples use generic business-assistant and enterprise-service descriptions suitable for different business systems.
36
+
37
+ ## Upgrade impact and acceptance
38
+
39
+ From public Core 0.8.0, use the official migrator to apply `063_usage_model_billing.sql` and `064_period_plan_allowance.sql`, retaining existing data and the migration ledger. **Normal public-version upgrades require no real-data or test-data purge.** Instances that already deployed a billing preview separately follow the [period allowance guide](PERIOD_ALLOWANCE_UPGRADE.en.md) for original snapshots.
40
+
41
+ Hosts opt into model catalogs, tools, summaries and persistent original-request records. Business backends adopt provisioning or plan-scoped identity APIs only when needed. Existing business-tool deployments need not enable model billing. Identity, permissions, session scope, approvals, task controls and business-call archives remain independent.
42
+
43
+ Verify enabled service configuration, customer allowance display, actual usage, original-ID recovery and administration against the final matched artifacts. Automated checks do not establish provider, client or production acceptance.
44
+
45
+ [Paired upgrade guide](UPGRADE_v0.9.0.en.md) · [Model billing contract](MODEL_BILLING.en.md) · [简体中文](RELEASE_NOTES_v0.9.0.md)