bailinghub 0.7.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (263) hide show
  1. package/README.en.md +7 -9
  2. package/README.md +7 -9
  3. package/docker-compose.images.yml +2 -2
  4. package/docs/AGENT_CLIENT_RUNTIME_API.en.md +46 -0
  5. package/docs/AGENT_CLIENT_RUNTIME_API.md +34 -0
  6. package/docs/AGENT_TASK_CONTROL.en.md +25 -0
  7. package/docs/AGENT_TASK_CONTROL.md +94 -0
  8. package/docs/AGENT_TASK_CONTROL_FOUNDATION.md +134 -0
  9. package/docs/ARCHITECTURE.md +1 -1
  10. package/docs/CHANGELOG.en.md +22 -1
  11. package/docs/CHANGELOG.md +22 -1
  12. package/docs/COMPATIBILITY.en.md +6 -0
  13. package/docs/CONTRACT.en.md +2 -0
  14. package/docs/CONTRACT.md +2 -0
  15. package/docs/GENERATED_ARTIFACTS.en.md +46 -0
  16. package/docs/GENERATED_ARTIFACTS.md +108 -0
  17. package/docs/INDEPENDENT_VALIDATION.en.md +4 -4
  18. package/docs/INDEPENDENT_VALIDATION.md +4 -4
  19. package/docs/INVOCATION_RECEIPTS.md +111 -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 +7 -0
  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.8.0.en.md +40 -0
  29. package/docs/RELEASE_NOTES_v0.8.0.md +62 -0
  30. package/docs/RELEASE_NOTES_v0.9.0.en.md +45 -0
  31. package/docs/RELEASE_NOTES_v0.9.0.md +45 -0
  32. package/docs/TOOL_RATE_LIMITS.md +50 -0
  33. package/docs/UPGRADE_v0.8.0.en.md +71 -0
  34. package/docs/UPGRADE_v0.8.0.md +73 -0
  35. package/docs/UPGRADE_v0.9.0.en.md +54 -0
  36. package/docs/UPGRADE_v0.9.0.md +54 -0
  37. package/docs//345/205/274/345/256/271/346/200/247/344/270/216/345/215/207/347/272/247.md +6 -0
  38. package/package.json +1 -1
  39. package/schemas/config/route.schema.json +1 -0
  40. package/schemas/config/tool-provider.schema.json +2 -1
  41. package/scripts/check-doc-links.mjs +5 -0
  42. package/scripts/check-image-tags.sh +1 -1
  43. package/scripts/check-release-consistency.test.mjs +2 -2
  44. package/scripts/e2e-console.mjs +32 -2
  45. package/scripts/install.sh +1 -1
  46. package/scripts/publish-images.sh +1 -1
  47. package/scripts/release-audit.mjs +2 -0
  48. package/scripts/sdk-runtime-test.mjs +6 -0
  49. package/scripts/verify-billing-install-upgrade.mjs +225 -0
  50. package/scripts/verify-github-repo.mjs +2 -0
  51. package/sdk/node/README.md +17 -0
  52. package/sdk/node/examples/billing.mjs +21 -0
  53. package/sdk/node/package.json +5 -1
  54. package/sdk/node/src/index.mjs +2 -0
  55. package/sdk/node/src/usage.d.mts +74 -0
  56. package/sdk/node/src/usage.mjs +62 -0
  57. package/sdk/node/tests/usage-types.mts +23 -0
  58. package/sdk/node/tests/usage.test.mjs +81 -0
  59. package/sdk/php7/README.md +19 -2
  60. package/sdk/php7/examples/billing.php +27 -0
  61. package/sdk/php7/examples/well-known.php +1 -1
  62. package/sdk/php7/src/ToolSpec.php +1 -1
  63. package/sdk/php7/src/UsageClient.php +95 -0
  64. package/sdk/php7/src/UsageClientException.php +22 -0
  65. package/sdk/php7/tests/billing-core-http.php +59 -0
  66. package/sdk/php7/tests/usage-client.php +78 -0
  67. package/sql/060_agent_artifacts.sql +11 -0
  68. package/sql/061_tool_rate_limit_policies.sql +3 -0
  69. package/sql/062_agent_task_control.sql +92 -0
  70. package/sql/063_usage_model_billing.sql +153 -0
  71. package/sql/064_period_plan_allowance.sql +25 -0
  72. package/sql/README.en.md +12 -4
  73. package/sql/README.md +14 -6
  74. package/src/adapters/storage/object-storage.ts +15 -3
  75. package/src/adapters/storage/oss-signature.test.ts +40 -0
  76. package/src/adapters/storage/oss-signature.ts +21 -0
  77. package/src/app/agent-artifacts.test.ts +165 -0
  78. package/src/app/agent-artifacts.ts +85 -0
  79. package/src/app/agent-client-runtime.test.ts +76 -1
  80. package/src/app/agent-client-runtime.ts +13 -0
  81. package/src/app/agent-invocation-snapshot.ts +35 -0
  82. package/src/app/agent-task-control.ts +187 -0
  83. package/src/app/agent-task-runtime.ts +68 -0
  84. package/src/app/agent-tool-invocations.test.ts +329 -1
  85. package/src/app/agent-tool-invocations.ts +223 -10
  86. package/src/app/agent-tool-job.test.ts +11 -1
  87. package/src/app/agent-tool-job.ts +8 -1
  88. package/src/app/auth.ts +2 -0
  89. package/src/app/builtin-tools.ts +4 -0
  90. package/src/app/oss-edition.ts +2 -0
  91. package/src/app/tool-approvals.ts +4 -0
  92. package/src/app/tool-assembly.ts +5 -0
  93. package/src/core/config/artifact-config.ts +15 -0
  94. package/src/core/config/config-codec.ts +3 -1
  95. package/src/core/config/config-models.ts +11 -1
  96. package/src/core/config/route-config.ts +3 -2
  97. package/src/core/contracts/tool-rate-limits.test.ts +59 -0
  98. package/src/core/contracts/tool-rate-limits.ts +48 -0
  99. package/src/core/contracts/tools.ts +122 -43
  100. package/src/core/contracts/types.ts +3 -1
  101. package/src/core/runtime/agent-task-control.test.ts +114 -0
  102. package/src/core/runtime/agent-task-control.ts +227 -0
  103. package/src/infrastructure/config/config-agent-artifact-repository.ts +32 -0
  104. package/src/infrastructure/config/config-agent-client-runtime-repository.ts +7 -1
  105. package/src/infrastructure/config/config-agent-task-control-journal-mysql.test.ts +315 -0
  106. package/src/infrastructure/config/config-agent-task-control-mysql.test.ts +331 -0
  107. package/src/infrastructure/config/config-agent-task-control-repository.ts +640 -0
  108. package/src/infrastructure/config/config-rate-limit-ledger.integration.test.ts +52 -0
  109. package/src/infrastructure/config/config-rate-limit-ledger.ts +48 -0
  110. package/src/infrastructure/config/config-storage-bucket-repository.ts +2 -2
  111. package/src/infrastructure/config/config-tool-provider-repository.ts +4 -4
  112. package/src/infrastructure/config/configstore.ts +15 -1
  113. package/src/modules/usage/allowance-reset.mysql.test.ts +122 -0
  114. package/src/modules/usage/billing-contracts.ts +59 -0
  115. package/src/modules/usage/billing-decimal.test.ts +22 -0
  116. package/src/modules/usage/billing-decimal.ts +36 -0
  117. package/src/modules/usage/billing-external.ts +39 -0
  118. package/src/modules/usage/billing-gateway.mysql.test.ts +24 -0
  119. package/src/modules/usage/billing-ledger.test.ts +51 -0
  120. package/src/modules/usage/billing-ledger.ts +104 -0
  121. package/src/modules/usage/billing-presentation.mysql.test.ts +95 -0
  122. package/src/modules/usage/billing-presentation.test.ts +49 -0
  123. package/src/modules/usage/billing-presentation.ts +34 -0
  124. package/src/modules/usage/billing-prices.mysql.test.ts +88 -0
  125. package/src/modules/usage/billing-repository.mysql.test.ts +181 -0
  126. package/src/modules/usage/billing-repository.ts +463 -0
  127. package/src/modules/usage/contracts.ts +49 -0
  128. package/src/modules/usage/dynamic-plan-models.mysql.test.ts +221 -0
  129. package/src/modules/usage/errors.ts +19 -0
  130. package/src/modules/usage/http.ts +85 -0
  131. package/src/modules/usage/identity-revocation.mysql.test.ts +286 -0
  132. package/src/modules/usage/identity.mysql.test.ts +120 -0
  133. package/src/modules/usage/identity.ts +303 -0
  134. package/src/modules/usage/issuer-sdk-billing.mysql.test.ts +92 -0
  135. package/src/modules/usage/model-gateway.mysql.test.ts +207 -0
  136. package/src/modules/usage/model-gateway.ts +229 -0
  137. package/src/modules/usage/model-tool-gateway.mysql.test.ts +137 -0
  138. package/src/modules/usage/model-tool-provider.test.ts +37 -0
  139. package/src/modules/usage/model-tool-provider.ts +110 -0
  140. package/src/modules/usage/model-tools.test.ts +36 -0
  141. package/src/modules/usage/model-tools.ts +62 -0
  142. package/src/modules/usage/period-allowance.mysql.test.ts +97 -0
  143. package/src/modules/usage/period.test.ts +26 -0
  144. package/src/modules/usage/period.ts +96 -0
  145. package/src/modules/usage/pricing.test.ts +178 -0
  146. package/src/modules/usage/pricing.ts +228 -0
  147. package/src/modules/usage/provider-failure.ts +37 -0
  148. package/src/modules/usage/provider-stream.test.ts +85 -0
  149. package/src/modules/usage/provider-stream.ts +77 -0
  150. package/src/modules/usage/provider.test.ts +67 -0
  151. package/src/modules/usage/provider.ts +142 -0
  152. package/src/modules/usage/repository.ts +539 -0
  153. package/src/modules/usage/service-availability.mysql.test.ts +68 -0
  154. package/src/modules/usage/service-availability.ts +13 -0
  155. package/src/modules/usage/service-delete.mysql.test.ts +87 -0
  156. package/src/modules/usage/stream-http.ts +32 -0
  157. package/src/modules/usage/test-harness.ts +108 -0
  158. package/src/modules/usage/usage-deletion.mysql.test.ts +312 -0
  159. package/src/modules/usage/usage-deletion.ts +119 -0
  160. package/src/modules/usage/validation.test.ts +18 -0
  161. package/src/modules/usage/validation.ts +33 -0
  162. package/src/routes/admin-agent-tasks.ts +32 -0
  163. package/src/routes/admin-billing-usage.ts +73 -0
  164. package/src/routes/admin-tool-providers.test.ts +22 -0
  165. package/src/routes/admin-tool-providers.ts +9 -1
  166. package/src/routes/admin-usage.ts +147 -0
  167. package/src/routes/admin.ts +7 -0
  168. package/src/routes/agent-api.test.ts +76 -0
  169. package/src/routes/agent-api.ts +42 -1
  170. package/src/routes/agent-artifacts.ts +29 -0
  171. package/src/routes/agent-task-control-http-mysql.test.ts +246 -0
  172. package/src/routes/private.ts +9 -0
  173. package/src/routes/run.ts +2 -1
  174. package/src/test-support/agent-task-control-mysql-fixture.ts +75 -0
  175. package/web/connect/bailing-connect-php7.tgz +0 -0
  176. package/web/console/assets/Accounts-Bervi5JU.css +1 -0
  177. package/web/console/assets/Accounts-DnddhY6t.js +3 -0
  178. package/web/console/assets/AgentClients-VInbD7JS.js +1 -0
  179. package/web/console/assets/AgentClients-i52AI6YV.css +1 -0
  180. package/web/console/assets/AgentTasks-B-1XklBg.js +2 -0
  181. package/web/console/assets/AgentTasks-BsG850Il.css +1 -0
  182. package/web/console/assets/{Approvals-Bs6FGbp2.js → Approvals-34qUPHf0.js} +1 -1
  183. package/web/console/assets/{Audit-4WWYhkFM.js → Audit-BbVgkSm2.js} +1 -1
  184. package/web/console/assets/{BrandLockup-D2GhCipL.js → BrandLockup-DgscF28e.js} +1 -1
  185. package/web/console/assets/{Channels-CmoGpiCJ.js → Channels-Bp-yuk8d.js} +1 -1
  186. package/web/console/assets/{ChatEntries-BFRMtwta.js → ChatEntries-C9Ft60TS.js} +1 -1
  187. package/web/console/assets/{Clients-DGkkSXyA.js → Clients-NPldD-DD.js} +1 -1
  188. package/web/console/assets/{Cost-BmGt0MfS.js → Cost-DZcuB-EB.js} +1 -1
  189. package/web/console/assets/{Credentials-CR-sYINT.js → Credentials-RTT7N6zl.js} +1 -1
  190. package/web/console/assets/{Diagnostics-DAPbKSJp.js → Diagnostics-_LeK8cce.js} +1 -1
  191. package/web/console/assets/{Executors-CgpiT3o8.js → Executors-Bi7H8rIm.js} +1 -1
  192. package/web/console/assets/{HelpTip-i-KJhf5s.js → HelpTip-BfyWrxCE.js} +1 -1
  193. package/web/console/assets/{Kb-Cm9dVSQw.js → Kb-BHamz8NP.js} +2 -2
  194. package/web/console/assets/{Login-CyUcsTZ_.js → Login-C1rJR-6w.js} +1 -1
  195. package/web/console/assets/{Projects-DldFPgWg.js → Projects-BRA4a48v.js} +1 -1
  196. package/web/console/assets/Routes-CTC7U-fQ.js +124 -0
  197. package/web/console/assets/Routes-CyXV4Pba.css +1 -0
  198. package/web/console/assets/{Runs-1hxgkuR4.js → Runs-B_fa_BlD.js} +1 -1
  199. package/web/console/assets/{Setup-DBLOnI2_.js → Setup-C1_d0mFy.js} +1 -1
  200. package/web/console/assets/Shell-CHEV6RGC.js +1 -0
  201. package/web/console/assets/Shell-ykb-tUfo.css +1 -0
  202. package/web/console/assets/StorageBuckets-CVgpZRWY.css +1 -0
  203. package/web/console/assets/StorageBuckets-DlG3ojhA.js +1 -0
  204. package/web/console/assets/{SystemSettings-cDkudo2y.js → SystemSettings-DYo2gg6d.js} +1 -1
  205. package/web/console/assets/{SystemStatus-DZd6s8OX.js → SystemStatus-DKCoUZlq.js} +1 -1
  206. package/web/console/assets/{Targets-DYNGq1NU.js → Targets-CdkG6BPR.js} +1 -1
  207. package/web/console/assets/Tools-DU8ei6sd.css +1 -0
  208. package/web/console/assets/Tools-DVpCt0ox.js +2 -0
  209. package/web/console/assets/Usage-CAeDGjrb.css +1 -0
  210. package/web/console/assets/Usage-DWCpLugC.js +1 -0
  211. package/web/console/assets/UsageAccess-B_Xq7ARW.js +1 -0
  212. package/web/console/assets/UsageAccess-CGGaWTuj.css +1 -0
  213. package/web/console/assets/UsageHelp-CSM4xO0K.css +1 -0
  214. package/web/console/assets/UsageHelp-t5ZG_f-e.js +1 -0
  215. package/web/console/assets/{index-QnmD7N7F.js → index-C6W4LWVV.js} +1 -1
  216. package/web/console/assets/{index-Fi9gkGxV.css → index-Cxuc9OCj.css} +1 -1
  217. package/web/console/assets/index-H1kfa0Mj.js +2 -0
  218. package/web/console/assets/{request-B7MLvOqo.js → request-DLsP1_ot.js} +1 -1
  219. package/web/console/assets/{schema-CMuwjYdJ.js → schema-BLOHvAJQ.js} +1 -1
  220. package/web/console/assets/{util-4bN2dv7B.js → util-CGVh2Jvr.js} +1 -1
  221. package/web/console/assets/{vendor-element-CZoEjZr8.js → vendor-element-BD089KxE.js} +1 -1
  222. package/web/console/assets/{vendor-mammoth-BUEEDX6A.js → vendor-mammoth-Bv-CZhmH.js} +1 -1
  223. package/web/console/index.html +3 -3
  224. package/web-admin/README.md +17 -0
  225. package/web-admin/scripts/agent-task-control-smoke.mjs +120 -0
  226. package/web-admin/src/components/AgentSetupPanel.vue +13 -0
  227. package/web-admin/src/components/ToolRateLimitEditor.vue +28 -0
  228. package/web-admin/src/components/UsageDeletionPreview.vue +44 -0
  229. package/web-admin/src/components/UsageHelp.vue +72 -0
  230. package/web-admin/src/components/UsageServiceReferences.vue +169 -0
  231. package/web-admin/src/layout/Shell.vue +23 -6
  232. package/web-admin/src/pages/Accounts.vue +3 -3
  233. package/web-admin/src/pages/AgentClients.vue +3 -1
  234. package/web-admin/src/pages/AgentTasks.vue +281 -0
  235. package/web-admin/src/pages/Routes.vue +5 -1
  236. package/web-admin/src/pages/StorageBuckets.vue +6 -6
  237. package/web-admin/src/pages/Tools.vue +53 -4
  238. package/web-admin/src/pages/Usage.vue +2470 -0
  239. package/web-admin/src/pages/UsageAccess.vue +1147 -0
  240. package/web-admin/src/router.ts +10 -4
  241. package/web-admin/src/styles/base.css +57 -0
  242. package/web-admin/src/table-widths.ts +16 -1
  243. package/web-admin/src/usage-deletion.ts +40 -0
  244. package/web-admin/src/usage-management.ts +13 -0
  245. package/web-admin/src/usage-presentation.test.ts +21 -0
  246. package/web-admin/src/usage-presentation.ts +107 -0
  247. package/web-admin/src/usage-price-preview.test.ts +60 -0
  248. package/web-admin/src/usage-price-preview.ts +54 -0
  249. package/web-admin/tests/token-usage.browser.mjs +773 -0
  250. package/web-admin/tests/usage-access.browser.mjs +398 -0
  251. package/web/console/assets/Accounts-B4ePH5jp.css +0 -1
  252. package/web/console/assets/Accounts-ChL9k-XA.js +0 -3
  253. package/web/console/assets/AgentClients-Bs7UgVDj.js +0 -1
  254. package/web/console/assets/AgentClients-DkgPTEbq.css +0 -1
  255. package/web/console/assets/Routes-DkMIjMQA.css +0 -1
  256. package/web/console/assets/Routes-DubfjlBD.js +0 -124
  257. package/web/console/assets/Shell-D9Uw-fsa.css +0 -1
  258. package/web/console/assets/Shell-gJ5Vz_E7.js +0 -1
  259. package/web/console/assets/StorageBuckets-DkDW16tj.js +0 -1
  260. package/web/console/assets/StorageBuckets-GnXnVvF0.css +0 -1
  261. package/web/console/assets/Tools-A20oaMaQ.css +0 -1
  262. package/web/console/assets/Tools-DpWM59vV.js +0 -2
  263. package/web/console/assets/index-DGqs28gI.js +0 -2
@@ -0,0 +1,46 @@
1
+ # Local Agent attachment space: bring generated outputs into business workflows
2
+
3
+ This image-first extension is available in Core 0.8.0 with SDK/DSH 0.6.0 and an adapted host. Storage and uploads require explicit administrator configuration.
4
+
5
+ A local Agent can generate useful content, but another application usually cannot read a path on that computer. The attachment space connects an approved conversation image to a URL: the host registers it, the Agent selects its reference and authorization, and BailingHub stores it using the operator's configured storage.
6
+
7
+ Examples include campaign artwork for a content platform, PNG charts for a reporting system, and pictures for an online shop. The receiving application must already provide the relevant URL-based business action. The image generator remains a host choice.
8
+
9
+ ## What the first increment provides
10
+
11
+ - A host-managed catalog of approved images for the original conversation.
12
+ - PNG, JPEG and WebP uploads, up to 6 MiB per image; DSH batches contain 1–8 images. Administrators can lower the size limit or restrict MIME types.
13
+ - Explicit destination authorization and per-image ready, pending or blocked results.
14
+ - Original upload receipt recovery after an uncertain response or a reopened conversation.
15
+ - Ordinary COS, OSS or explicitly configured server-local storage. Returned URLs are publicly readable. Retention is managed by the deployment, without automatic conversation-expiry deletion.
16
+
17
+ The first increment does not accept documents or video. Hosts supply permitted file bytes; BailingHub cannot read the client's filesystem. Enabling the SDK does not automatically grant file access to every MCP application.
18
+
19
+ ## Upload and use are separate steps
20
+
21
+ Generate an image → register it in the conversation catalog → upload → receive a ready URL. Attachment delivery is complete at that point.
22
+
23
+ Use a ready URL directly with an existing business tool. Repeated receipt lookup is only needed for upload recovery, not for every use of the image. A business change keeps its own authorization, approvals and outcome. For example, a shop gallery update should wait for all required images and preserve any existing images the user did not ask to remove.
24
+
25
+ ## Configure and integrate
26
+
27
+ 1. Register a storage entry with its bucket, region, credentials, public address and write prefix.
28
+ 2. In Agent Clients → Setup → Tools and approvals, choose the workspace, enable the current image-upload setting and select that storage.
29
+ 3. Install matching Core, Agent Client SDK and DSH packages. SDK hosts supply bytes and retain original upload identities. DSH hosts supply artifactSource and a durable artifactStore.
30
+ 4. Apply outstanding Core migrations, including sql/060_agent_artifacts.sql. Existing URL-based business APIs need no change for attachment delivery.
31
+
32
+ The existing APIs remain uploadArtifact/getArtifact in the SDK and list_generated_artifacts/upload_generated_artifacts in DSH. Naming the user-facing feature an attachment space does not rename these compatible technical interfaces.
33
+
34
+ The [configuration and HTTP contract](GENERATED_ARTIFACTS.md) includes exact metadata, original-target validation and error handling.
35
+
36
+ ## Stale optional run links
37
+
38
+ Core returns `artifact_run_turn_mismatch` only when the referenced run is verified to belong to the same original Agent Session, client, workspace and conversation, but its valid turn differs from the upload turn. The request is rejected before reserving an upload or storing bytes. Missing runs, mismatched identity/route/conversation, or a legacy run without a valid turn retain `artifact_run_mismatch`. Neither error exposes another turn's identifiers or content.
39
+
40
+ The matching DSH release may repair this specific rejected link only after a lookup confirms that the original upload ID does not exist, while the original identity and file remain valid. It durably records the correction, retains the original local record, upload ID, content, destination, conversation and turn, and removes only the optional run link proven to belong to another turn. Ready or pending receipts, uncertain network outcomes, generic run mismatches and damaged recovery records do not allow this correction. Older SDKs that do not recognize the precise error must remain blocked until upgraded. Upload recovery never executes a business action.
41
+
42
+ ## Known issues tracked separately
43
+
44
+ The matching release adds [configurable tool limits and original-invocation recovery](TOOL_RATE_LIMITS.md). Hour/day windows retain their original duration; newly recorded pre-dispatch rejections retain encrypted arguments. Uncertain writes are never replayed, and missing arguments from historical calls are never reconstructed. Ready attachment URLs remain reusable independently.
45
+
46
+ DSH may simplify some artifact-list source errors to unknown_failure; hosts should preserve their own storage_error and recovery_gap diagnostics. Per-image upload results remain separate.
@@ -0,0 +1,108 @@
1
+ # 本地智能体附件空间:让生成结果进入业务流程
2
+
3
+ 配套版本:Core 0.8.0 / SDK 0.6.0 / DSH 0.6.0。新能力需部署方升级并按宿主契约接入;业务权限、审批和原身份约束保持。
4
+
5
+ ## 解决什么问题
6
+
7
+ 本地智能体已经能生成图片,但生成结果往往停留在客户端目录中。需要交给业务系统使用时,用户还要下载、上传,再把地址贴回对话。
8
+
9
+ 附件空间连接“本地生成结果”和“业务可用地址”:宿主登记当前会话获准使用的图片,智能体按引用选择附件和目标授权,中枢保存图片并返回 URL。智能体随后可把地址交给已经接入的业务工具,无需用户手动搬运。
10
+
11
+ 首期交付会话级图片登记、受控上传和原上传结果恢复,支持 PNG、JPEG、WebP。名称中的“附件”描述通用用途,不表示本期已支持 PDF、Word、视频或所有文件格式。
12
+
13
+ | 场景 | 附件空间解决的步骤 | 业务工具负责的步骤 |
14
+ | --- | --- | --- |
15
+ | 制作活动海报 | 保存海报并取得可用地址 | 把地址设为活动页或内容封面 |
16
+ | 生成经营图表 | 保存 PNG 图表并取得可用地址 | 将图表关联到报告或运营页面 |
17
+ | 维护商城商品 | 保存多张商品展示图并逐项返回结果 | 设置主图、轮播图或其他图片字段 |
18
+
19
+ 这些业务动作需要对应系统已经提供接收图片 URL 的能力,不是中枢内置的业务接口。图片生成服务仍由客户端选用。
20
+
21
+ ## 上传完成后发生什么
22
+
23
+ 流程为:生成图片 → 登记会话附件 → 上传到所选授权对应的存储 → 取得 ready URL。到这里附件上传已完成,后续业务操作可以直接使用这些 URL。
24
+
25
+ 正常成功后不需要为了每次使用而重复查询或上传。只有上传结果不确定、重新打开会话需要恢复回执时,才查询原上传记录。批量上传返回逐项结果,已成功项复用原地址,失败项按原记录恢复。
26
+
27
+ 业务工具调用是独立动作,沿用原授权和审批规则,是否完成以业务回执为准。例如设置完整图片列表前先确认所需图片全部 ready,并保留用户未要求删除的已有图片。
28
+
29
+ ## 管理员在哪里开启
30
+
31
+ 1. 在“媒体存储”登记普通 COS 或 OSS:桶名、地域、凭据、公开访问地址、写入前缀。OSS 使用 V4 签名,地域如 `cn-shanghai`;COS 如 `ap-shanghai`。自定义 endpoint 留空即可;填写时须为完整桶访问主机,包含桶名。
32
+ 2. 打开“智能体客户端 → 配置接入 → 工具与审批”,选择工作空间,在“生成图片上传”启用并选择已登记存储。
33
+ 3. 客户端安装配套 SDK/DSH,接入生成产物目录与持久恢复记录。业务工具自身仍在原工具源、scope、写操作清单和审批规则中配置。
34
+
35
+ 也支持显式登记服务器本地存储。用于本能力时填写能访问该实例 `/uploads` 的完整公开地址;不会因桶缺失或停用自动换到其他存储。
36
+
37
+ 文件保留由私有化部署方管理,本功能不设置到期时间,不随会话结束或授权撤销清理文件。没有额外“永久保存”判定。第一期用于公开展示图片;上传对象采用公开读取,不要用来上传私有文档。
38
+
39
+ 工作空间配置示例:
40
+
41
+ ```json
42
+ {
43
+ "agent_client": {
44
+ "enabled": true,
45
+ "artifact_upload": {
46
+ "enabled": true,
47
+ "bucket": "agent-attachments",
48
+ "max_bytes": 6291456,
49
+ "allowed_mimes": ["image/png", "image/jpeg", "image/webp"]
50
+ }
51
+ }
52
+ }
53
+ ```
54
+
55
+ 默认关闭。第一期 PNG/JPEG/WebP,单图不超过 6 MiB,客户端每批最多 8 张,可配置更小上限。实际文件头、摘要、字节数与声明不符会拒绝;不接收路径、任意远端 URL 或模型上下文中的 base64 文件。
56
+
57
+ ## 接口与恢复契约
58
+
59
+ 认证使用原 Agent Session Bearer。每次请求重新校验接入方、会话、workspace 与 audience;SDK/DSH 进一步固定并整组验证用户显式选定的授权,任何原成员失效都不切换默认或降级子集。
60
+
61
+ - `POST /agent-api/v1/workspaces/{workspace}/artifacts/{upload_id}`:原始图片字节;`Content-Type` 为 MIME。`x-bailing-artifact` 是下列 JSON 的 UTF-8 base64url 编码(只编码小型元数据,文件不编码进正文)。
62
+ - `GET` 同一路径:查询原上传结果。上传 ID 为 64 位小写十六进制。查询不创建业务 run,不执行业务操作。
63
+
64
+ ```json
65
+ {
66
+ "name": "campaign-banner.png",
67
+ "mime": "image/png",
68
+ "bytes": 12345,
69
+ "sha256": "<64位文件摘要>",
70
+ "client_conversation_id": "<原会话关联>",
71
+ "client_turn_id": "<原轮次关联>"
72
+ }
73
+ ```
74
+
75
+ 可附 `run_id`,必须属于同一原 Session、workspace、会话和轮次。没有业务 run 时可直接上传,以会话/轮次关联记录,上传不会向其他系统广播正文或创建业务 run。
76
+
77
+ `artifact_run_turn_mismatch` 是严格限定的拒绝原因:Core 已确认该 run 属于同一原 Agent Session、接入方、workspace 和会话,且 run 的轮次有效,但与上传轮次不同。此请求在上传记录预留和文件存储之前被拒绝;错误回执不会返回其他轮次的标识或正文。缺失 run、身份/路由/会话不符或旧 run 缺少有效轮次,仍返回 `artifact_run_mismatch`。
78
+
79
+ 配套 DSH 仅在收到这个精确错误、查询原 upload_id 明确不存在、原身份和文件仍有效时,才持久保存纠正记录:保留原上传 ID、内容、目标、会话与轮次,移除被确认属于另一轮的可选 run 关联,再补传同一上传。原本地记录仍保留。已有 ready/pending 回执、网络结果不明、泛化 `artifact_run_mismatch` 或恢复记录损坏均不能触发该纠正;上传成功不代表业务动作已执行。旧 SDK 未识别新错误时应保持阻断,升级配套候选后再恢复。
80
+
81
+ 返回 `schema_version=bailing.agent-artifact.v1`、原标识/元数据、`visibility=public`、`state=ready|pending`。ready 包含 URL 与 `next_action=use_url`;pending 为 `retry_same_upload`。资源记录不返回桶配置、密钥或服务端诊断正文。
82
+
83
+ 同一 Session 的同一 upload_id 固定元数据、内容与存储目标。相同请求重放返回原记录;更换内容或目标返回冲突。网络回包丢失先 GET;ready 直接使用原 URL,pending/未写入才补传原文件。若文件已保存但数据库确认失败,补传可能再次 PUT 同一对象键和相同字节,不生成另一条图片引用;若桶启用版本管理,可能留下存储版本,这是存储层行为。
84
+
85
+ | 错误 | 下一步 |
86
+ | --- | --- |
87
+ | artifact_upload_pending / 网络中断 | 查询原 upload_id;必要时补传同一文件到原授权 |
88
+ | artifact_content_mismatch / artifact_type_not_allowed / artifact_too_large | 修正文件或配置;不要把无效数据当成功 |
89
+ | artifact_conflict / artifact_storage_changed | 保留原记录,核对原文件或存储配置,不自动换桶 |
90
+ | artifact_run_turn_mismatch | 使用配套 DSH 的原记录纠正流程;不改文件名、不换授权或新建上传 ID |
91
+ | artifact_run_mismatch | 原执行关联无法确认;保持阻断,不根据错误猜测图片来源或移除关联 |
92
+ | artifact_upload_disabled / artifact_storage_unavailable | 在上述集中入口检查开关与存储 |
93
+ | artifact_unsupported | 安装配套版本;已有业务工具流程不受影响 |
94
+ | 授权失效 | 阻断本会话整组;不换授权重试 |
95
+
96
+ ## 升级边界
97
+
98
+ 新增 `sql/060_agent_artifacts.sql`,只增加图片上传记录表;工作空间开关保存在既有 agent_client JSON 中。自用实例部署时按原迁移流程应用 060。商业 Host 须单独评估配置仓储、租户迁移清单与版本 pin;旧宿主缺少可选 agentArtifacts 仓储时明确 unsupported,不自动部署或迁移其他环境。
99
+
100
+ 商城等业务后端如果已经接收图片 URL,无须为这条链路改变能力声明或审批规则。生成文件的识别、读取与目录持久化由客户端宿主负责,不能假定远端中枢能读取客户端电脑的路径。其他 MCP 宿主/执行器需要各自适配,不因 SDK 新增接口自动获得本地文件权限。
101
+
102
+ ## 与附件上传分开跟踪的已知问题
103
+
104
+ 本次配套候选已补齐[工具限额配置与原调用恢复](TOOL_RATE_LIMITS.md):按原时间窗口计数,支持继承、自定义或关闭中枢单工具限额;可重试的出站前拒绝保留原参数。恢复仍使用原 invocation,结果不确定的写操作不重发,旧调用丢失的参数也不会被猜补。这不改变 ready 附件的 URL。
105
+
106
+ DSH 的附件列表源错误目前也可能被通用分类简化为 unknown_failure;上传逐项回执不受该提示问题影响。对应候选仍按这两类结果分别验收,不承诺任意业务批量任务自动完成。
107
+
108
+ OSS V4 按[官方签名说明](https://www.alibabacloud.com/help/en/oss/developer-reference/recommend-to-use-signature-version-4)实现,并与官方 ali-oss 6.23.0 的合成签名向量交叉核验。真实桶连通性在部署方配置存储后验收。
@@ -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.7.0`;
10
+ - Stable baseline: `v0.9.0`;
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.7.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.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.
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.7.0 https://github.com/bailinghub/bailinghub.git
49
+ git clone --depth 1 --branch v0.9.0 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.7.0.en.md).
170
+ - [Current stable release notes](RELEASE_NOTES_v0.9.0.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.7.0`;
10
+ - 稳定基线:`v0.9.0`;
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.7.0` 官方镜像,生成随机 Token 与后台密码,启动服务并自动运行基础体检。首次管理员只在数据库管理员表为空时创建;对同一持久化数据库进行重启、升级、容器重建或重新安装,不会覆盖已经修改的管理员密码。可选 `/metrics` 端点默认关闭,不影响基础验证。请保留终端输出中的版本、安装模式、耗时和“常用命令”,但不要把密码或 Token 写入反馈。新安装 Docker 后,当前非 root 会话通常仍需使用脚本打印的 `sudo docker compose ...` 命令;重新登录后 Docker 组权限才可能生效。
35
+ 脚本默认拉取 `v0.9.0` 官方镜像,生成随机 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.7.0 https://github.com/bailinghub/bailinghub.git
49
+ git clone --depth 1 --branch v0.9.0 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.7.0.md)。
170
+ - [当前稳定版发布说明](RELEASE_NOTES_v0.9.0.md)。
171
171
 
172
172
  扩展验证请在同一 Issue 模板中选择对应路径,并说明是否获得过维护者的直接帮助。
173
173
 
@@ -0,0 +1,111 @@
1
+ # 原调用只读回执 / Read-only invocation receipts
2
+
3
+ ## 中文使用说明
4
+
5
+ 配套版本:Core 0.8.0 / SDK 0.6.0 / DSH 0.6.0。新能力需部署方升级并按宿主契约接入;业务权限、审批和原身份约束保持。
6
+
7
+ 比如,智能体为商城商品提交了上架请求,用户已批准,但客户端还没有继续执行。此时“看看进度”应只显示“已批准,尚未执行”。另一个常见场景是修改商品后连接中断,智能体需要查看原记录,判断中枢是否已经收到了结果。
8
+
9
+ 本接口只查看原调用的结果、当前审批和执行日志。查询不执行上架、不消耗审批,也不改变原调用状态。`resume` 仍可能继续原操作,不能用来替代只读查询。回执中的 `business_operation_performed: false` 只表示这次查询没有执行业务,不表示原操作从未执行。
10
+
11
+ 调用方必须保留原调用 ID 与原授权,查询时仍需通过当前权限校验。中枢全局暂停期间可以查询;授权撤销后不能换另一把授权读取。网络临时故障可以重试同一次查询;原记录找不到或结果仍未知时,应保留原 ID 核对,不能重新创建一次业务操作。
12
+
13
+ 这一片无需数据库迁移,需使用配套 Core 和 SDK 候选。它提供后续任务视图需要的查询基础;任务累计预算、任务暂停按钮和 DSH 模型工具另行接入。下面给出具体请求、返回字段与兼容规则。
14
+
15
+ ## Contract overview
16
+
17
+ An assistant may lose the confirmation for a product update, or reopen a conversation while a write is waiting for approval. Reading what the Hub already knows must not silently send the update again.
18
+
19
+ Invocation inspection reads the original Hub record, execution journal and approval state. It does not create a run, invoke a tool, consume an approval, decrypt frozen arguments, reserve a dispatch attempt, or change the original invocation state. This is a separate operation from `POST .../resume`, which may perform the original operation's first dispatch after approval or a confirmed rejection before dispatch.
20
+
21
+ ## Negotiate support
22
+
23
+ Use the original Agent Session's Bearer token:
24
+
25
+ ```http
26
+ GET /agent-api/v1/tool-invocations/inspection-capabilities
27
+ Authorization: Bearer <agent-access-token>
28
+ ```
29
+
30
+ ```json
31
+ {
32
+ "schema_version": "bailing.agent-invocation-inspection-capabilities.v1",
33
+ "receipt_schema": "bailing.agent-invocation-receipt.v1",
34
+ "read_only": true
35
+ }
36
+ ```
37
+
38
+ An older Hub that does not advertise this exact contract is unsupported. Do not substitute `resume`, invoke a replacement operation, or infer support from a package version. Negotiation authenticates the Agent Session without creating a business run or loading a tool catalog.
39
+
40
+ ## Read the original receipt
41
+
42
+ ```http
43
+ GET /agent-api/v1/tool-invocations/<original-64-hex-invocation-id>/receipt
44
+ Authorization: Bearer <original-agent-access-token>
45
+ ```
46
+
47
+ Both GET endpoints accept no query parameters and return `Cache-Control: no-store`. The receipt endpoint accepts the original identifier only; it does not accept replacement arguments, a new target, a tool name, or a task identifier.
48
+
49
+ Example: an original update is waiting for its explicit continuation after approval:
50
+
51
+ ```json
52
+ {
53
+ "schema_version": "bailing.agent-invocation-receipt.v1",
54
+ "read_only": true,
55
+ "business_operation_performed": false,
56
+ "invocation_id": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
57
+ "agent_run_id": "22222222-2222-4222-8222-222222222222",
58
+ "route": "catalog-agent",
59
+ "tool": "product_update",
60
+ "observed_at": "2026-09-15T00:00:00.000Z",
61
+ "result": {
62
+ "schema_version": "bailing.agent-tool-invocation.v1",
63
+ "invocation_id": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
64
+ "route": "catalog-agent",
65
+ "tool": "product_update",
66
+ "state": "awaiting_approval",
67
+ "ok": false,
68
+ "auto_retry_allowed": false,
69
+ "text": "The governed tool invocation is awaiting approval.",
70
+ "approval_id": 1
71
+ },
72
+ "result_source": "job",
73
+ "dispatch_state": "not_dispatched",
74
+ "approval": { "status": "approved", "approval_id": 1 },
75
+ "journal_state": "absent"
76
+ }
77
+ ```
78
+
79
+ The saved result and the latest approval observation intentionally remain distinct. Approval becoming `approved` does not make the business operation successful and inspection does not continue it.
80
+
81
+ ## Interpret the observations
82
+
83
+ | Field | Meaning |
84
+ | --- | --- |
85
+ | `read_only`, `business_operation_performed` | This request only inspected records. These fields do not claim that the original operation never ran. |
86
+ | `invocation_id`, `agent_run_id`, `route`, `tool` | Original verified coordinates. A new user turn must not replace the original run or target. |
87
+ | `observed_at` | Observation time, not a dispatch permit or an atomic policy decision. |
88
+ | `result` | An allowlisted original invocation result, a projection of journal evidence, or `null` when no valid result is available. Raw job metadata and frozen arguments are excluded. |
89
+ | `result_source` | `job`, `journal`, or `none`. A completed journal can reveal a saved result even when the job still has an older prefix; inspection does not persist this projection. |
90
+ | `dispatch_state` | `not_dispatched` means existing evidence confirms a rejection or wait before dispatch; `attempted` means an execution attempt may have reached the business system; `unknown` means that distinction cannot be verified. `attempted` is not proof that the business system received or completed it. |
91
+ | `approval.status` | `none`, `pending`, `approved`, or `denied`; the latter three include the original `approval_id`. |
92
+ | `journal_state` | `absent`, `dispatching`, `response_recorded`, `completed`, `uncertain`, `evidence_degraded`, or `unknown`. `response_recorded` alone does not promise completion of the original execution evidence. |
93
+
94
+ Unresolved journal evidence projects `reconciliation_required` with `auto_retry_allowed: false`. Inspecting a malformed stored result returns `result: null`, not a fabricated success. A journal whose completion cannot be verified also remains unresolved.
95
+
96
+ The nested result preserves the existing invocation result contract. In particular, an old `auto_retry_allowed: true` describes that original result; it does not authorize the receipt consumer to automatically invoke or resume anything. Explicit continuation remains a distinct governed operation using the original invocation and original parameters.
97
+
98
+ These are observations of separately persisted records. A concurrent operation or approval can progress while they are read. Refresh the receipt to observe later evidence; never convert this read into a claim that it atomically grants or denies a future dispatch.
99
+
100
+ ## Authorization and boundaries
101
+
102
+ - The original Agent Session must still be valid, the Client enabled, and the original route and specific tool currently authorized. Historical parameter schemas and execution fingerprints need not stay unchanged merely to inspect existing evidence.
103
+ - The Hub verifies the original job marker, Agent Session, Client, principal, subject and invocation coordinates. If the original runtime run exists, its session, client, route and thread association must also match. A missing historical runtime row is not reconstructed from conversation text.
104
+ - The host must retain and validate its complete original selected authorization set before using the original connection. This receipt API does not independently claim to implement a task's multi-member authorization ledger, cross-Hub access, or administrator audit permissions.
105
+ - Inspection works while the global Hub execution pause is enabled. Pause still blocks invoke and resume. Authentication can update the existing session `last_seen_at`; this does not update business data, invocation state, approval use, or the dispatch journal.
106
+ - Current authorization failure remains a failure. Do not fall back to another Agent Session, default authorization, remaining subset, or an administrator credential.
107
+ - An authenticated `invocation_not_found` is absence of a verifiable original record, not proof that a previous business write did not happen. Keep the original identifiers and inspect the original evidence through an authorized operator; do not issue a replacement write.
108
+
109
+ ## Integration scope
110
+
111
+ The standalone receipt addition requires no migration. The later [paired task-control candidate](AGENT_TASK_CONTROL.en.md) builds on it with migration 062, whole-group verification for managed calls, budgets, pause/cancel and host integration. It still does not automatically reconcile unknown outcomes with a business provider. Non-enrolled original invocation behavior remains unchanged.
@@ -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 或业务后端改造。