bailinghub 0.9.4 → 0.10.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 (334) hide show
  1. package/README.en.md +6 -6
  2. package/README.md +6 -6
  3. package/THIRD_PARTY_NOTICES.md +2 -2
  4. package/docker-compose.images.yml +2 -2
  5. package/docs/AGENT_CLIENT_QUICKSTART.en.md +1 -3
  6. package/docs/AGENT_CLIENT_QUICKSTART.md +1 -1
  7. package/docs/AGENT_CLIENT_RUNTIME_API.en.md +87 -2
  8. package/docs/AGENT_CLIENT_RUNTIME_API.md +36 -2
  9. package/docs/AGENT_KNOWLEDGE_API.en.md +77 -0
  10. package/docs/AGENT_KNOWLEDGE_API.md +86 -0
  11. package/docs/AGENT_TASK_CONTROL.md +4 -4
  12. package/docs/AGENT_TASK_CONTROL_FOUNDATION.md +1 -1
  13. package/docs/ARCHITECTURE.md +4 -0
  14. package/docs/CHANGELOG.en.md +24 -1
  15. package/docs/CHANGELOG.md +24 -1
  16. package/docs/COMPATIBILITY.en.md +27 -1
  17. package/docs/CONTRACT.en.md +1 -1
  18. package/docs/CONTRACT.md +1 -1
  19. package/docs/IMPLEMENTATION_STATUS.en.md +28 -15
  20. package/docs/IMPLEMENTATION_STATUS.md +28 -15
  21. package/docs/INDEPENDENT_VALIDATION.en.md +6 -4
  22. package/docs/INDEPENDENT_VALIDATION.md +6 -4
  23. package/docs/INTEGRATION_WALKTHROUGH.md +65 -0
  24. package/docs/MODEL_BILLING.en.md +2 -0
  25. package/docs/MODEL_BILLING.md +6 -2
  26. package/docs/MODEL_CONTINUATION.en.md +54 -0
  27. package/docs/MODEL_CONTINUATION.md +54 -0
  28. package/docs/MODEL_OUTPUT_BUDGET.en.md +69 -0
  29. package/docs/MODEL_OUTPUT_BUDGET.md +69 -0
  30. package/docs/OPERATIONS.en.md +16 -4
  31. package/docs/OPERATIONS.md +16 -4
  32. package/docs/QUICKSTART.md +1 -1
  33. package/docs/README.en.md +7 -0
  34. package/docs/README.md +7 -0
  35. package/docs/RELEASE_NOTES_NEXT.en.md +3 -3
  36. package/docs/RELEASE_NOTES_NEXT.md +3 -3
  37. package/docs/RELEASE_NOTES_v0.10.0.en.md +58 -0
  38. package/docs/RELEASE_NOTES_v0.10.0.md +58 -0
  39. package/docs/RELEASE_NOTES_v0.10.1.en.md +41 -0
  40. package/docs/RELEASE_NOTES_v0.10.1.md +41 -0
  41. package/docs/UPGRADE_PLAN.en.md +118 -0
  42. package/docs/UPGRADE_PLAN.md +124 -0
  43. package/docs/UPGRADE_v0.10.0.en.md +47 -0
  44. package/docs/UPGRADE_v0.10.0.md +47 -0
  45. package/docs/UPGRADE_v0.10.1.en.md +66 -0
  46. package/docs/UPGRADE_v0.10.1.md +66 -0
  47. package/docs//345/205/274/345/256/271/346/200/247/344/270/216/345/215/207/347/272/247.md +38 -22
  48. package/package.json +10 -5
  49. package/schemas/tool-definition.schema.json +13 -0
  50. package/scripts/check-doc-links.mjs +6 -0
  51. package/scripts/check-image-tags.sh +1 -1
  52. package/scripts/check-php-sdk-artifacts.mjs +152 -0
  53. package/scripts/check-php-sdk-artifacts.test.mjs +99 -0
  54. package/scripts/check-release-consistency.test.mjs +2 -2
  55. package/scripts/doctor-upgrade-plan.test.ts +205 -0
  56. package/scripts/doctor-upgrade-plan.ts +276 -0
  57. package/scripts/doctor.ts +4 -1
  58. package/scripts/e2e-console-approval-details.mjs +134 -0
  59. package/scripts/e2e-console-config-races.mjs +180 -0
  60. package/scripts/e2e-console-kb-audit.mjs +170 -0
  61. package/scripts/e2e-console-operations-audit.mjs +152 -0
  62. package/scripts/e2e-console-runtime-audit.mjs +179 -0
  63. package/scripts/e2e-console-settings-audit.mjs +125 -0
  64. package/scripts/e2e-console-troubleshooting-extra.mjs +267 -0
  65. package/scripts/e2e-console.mjs +476 -7
  66. package/scripts/install.sh +1 -1
  67. package/scripts/publish-images.sh +1 -1
  68. package/scripts/release-audit.mjs +9 -1
  69. package/scripts/sdk-declaration-contract-test.ts +34 -0
  70. package/scripts/sdk-p1-check.mjs +62 -26
  71. package/scripts/verify-github-repo.mjs +8 -0
  72. package/sdk/dotnet/Bailing.Connect/BailingConnect.cs +4 -4
  73. package/sdk/dotnet/README.md +8 -0
  74. package/sdk/dotnet/tests/Declaration/Declaration.csproj +11 -0
  75. package/sdk/dotnet/tests/Declaration/Program.cs +74 -0
  76. package/sdk/go/README.md +8 -0
  77. package/sdk/go/bailingconnect/connect.go +5 -5
  78. package/sdk/go/bailingconnect/declaration_test.go +107 -0
  79. package/sdk/java/README.md +13 -0
  80. package/sdk/java/src/main/java/com/bailing/connect/BailingConnect.java +4 -4
  81. package/sdk/java/tests/DeclarationTest.java +70 -0
  82. package/sdk/node/README.md +8 -0
  83. package/sdk/node/src/index.mjs +4 -4
  84. package/sdk/node/tests/declaration.test.mjs +41 -0
  85. package/sdk/php/README.md +16 -0
  86. package/sdk/php/src/Attributes/AiTool.php +4 -4
  87. package/sdk/php/src/SpecBuilder.php +8 -8
  88. package/sdk/php/tests/declaration-serialization.php +103 -0
  89. package/sdk/php7/README.md +14 -0
  90. package/sdk/php7/src/ToolDef.php +3 -3
  91. package/sdk/php7/src/ToolSpec.php +8 -13
  92. package/sdk/php7/tests/declaration-serialization.php +103 -0
  93. package/sdk/python/README.md +8 -0
  94. package/sdk/python/bailing_connect/__init__.py +6 -6
  95. package/sdk/python/tests/test_declaration.py +61 -0
  96. package/src/app/agent-client-runtime.test.ts +115 -2
  97. package/src/app/agent-client-runtime.ts +40 -11
  98. package/src/app/agent-knowledge.test.ts +171 -0
  99. package/src/app/agent-knowledge.ts +233 -0
  100. package/src/app/agent-tool-catalog-revision.test.ts +31 -0
  101. package/src/app/agent-tool-invocations.test.ts +7 -2
  102. package/src/app/agent-tool-invocations.ts +67 -7
  103. package/src/app/approval-continuations.test.ts +49 -1
  104. package/src/app/http.test.ts +16 -1
  105. package/src/app/http.ts +3 -3
  106. package/src/app/kernel-boot-recovery.mysql.test.ts +132 -0
  107. package/src/app/kernel-boot-recovery.test.ts +157 -0
  108. package/src/app/kernel.ts +12 -8
  109. package/src/app/readiness.mysql.test.ts +120 -0
  110. package/src/app/readiness.test.ts +111 -26
  111. package/src/app/readiness.ts +26 -22
  112. package/src/app/runtime-lifecycle.ts +34 -3
  113. package/src/app/tool-approvals.test.ts +83 -0
  114. package/src/app/tool-approvals.ts +25 -7
  115. package/src/app/tool-proxy-payload.test.ts +81 -0
  116. package/src/app/tool-proxy.ts +24 -2
  117. package/src/core/config/console-diagnostic-location.test.ts +36 -0
  118. package/src/core/config/console-form-guard.test.ts +69 -0
  119. package/src/core/config/console-task-location.test.ts +64 -0
  120. package/src/core/contracts/explicit-capability-values.test.ts +62 -0
  121. package/src/core/contracts/openapi-tools.ts +18 -7
  122. package/src/core/contracts/schema-readiness.ts +11 -0
  123. package/src/core/contracts/tool-annotations.ts +4 -4
  124. package/src/core/contracts/tool-definition.ts +26 -0
  125. package/src/core/contracts/tool-guidance.test.ts +77 -0
  126. package/src/core/contracts/tool-guidance.ts +31 -0
  127. package/src/core/contracts/tool-input-limits.ts +15 -0
  128. package/src/core/contracts/tools-idempotency.test.ts +90 -0
  129. package/src/core/contracts/tools.ts +52 -9
  130. package/src/core/runtime/agent-execution-memory.test.ts +64 -0
  131. package/src/core/runtime/agent-execution-memory.ts +63 -0
  132. package/src/core/state/state-contracts.ts +3 -0
  133. package/src/infrastructure/config/config-observability-ledger.ts +2 -0
  134. package/src/infrastructure/schema/schema-readiness.ts +29 -0
  135. package/src/infrastructure/state/state-mysql.ts +3 -0
  136. package/src/modules/usage/contracts.ts +7 -0
  137. package/src/modules/usage/http.ts +2 -0
  138. package/src/modules/usage/model-continuation.test.ts +109 -0
  139. package/src/modules/usage/model-gateway.ts +5 -1
  140. package/src/modules/usage/output-budget.mysql.test.ts +84 -0
  141. package/src/modules/usage/output-budget.test.ts +167 -0
  142. package/src/modules/usage/output-budget.ts +73 -0
  143. package/src/modules/usage/provider-stream.test.ts +22 -0
  144. package/src/modules/usage/provider.ts +2 -3
  145. package/src/modules/usage/repository.ts +6 -0
  146. package/src/modules/usage/test-harness.ts +4 -2
  147. package/src/routes/admin-approval-view.test.ts +109 -0
  148. package/src/routes/admin-approval-view.ts +36 -0
  149. package/src/routes/admin-readiness.test.ts +52 -0
  150. package/src/routes/admin-runtime-ux.test.ts +51 -0
  151. package/src/routes/admin-runtime-ux.ts +25 -0
  152. package/src/routes/admin-runtime.ts +36 -8
  153. package/src/routes/admin.ts +9 -0
  154. package/src/routes/agent-api.test.ts +80 -1
  155. package/src/routes/agent-api.ts +63 -4
  156. package/src/routes/agent-tool-detail.test.ts +140 -0
  157. package/src/routes/public-default.ts +1 -1
  158. package/src/services/kb-agent.test.ts +84 -0
  159. package/src/services/kb.ts +73 -0
  160. package/web/connect/bailing-connect-php.tgz +0 -0
  161. package/web/connect/bailing-connect-php7.tgz +0 -0
  162. package/web/console/assets/Accounts-CjIBO3sU.css +1 -0
  163. package/web/console/assets/Accounts-Dhyw-7wF.js +3 -0
  164. package/web/console/assets/AgentClients-BA0M26-I.css +1 -0
  165. package/web/console/assets/AgentClients-DWxb8-ko.js +1 -0
  166. package/web/console/assets/AgentTasks-DOyxANnx.css +1 -0
  167. package/web/console/assets/AgentTasks-DUHD4dzr.js +2 -0
  168. package/web/console/assets/Approvals-Brl-2uJq.css +1 -0
  169. package/web/console/assets/Approvals-CQx1YWxW.js +1 -0
  170. package/web/console/assets/Audit--QcdVlMh.js +1 -0
  171. package/web/console/assets/Audit-DAdmOnIs.css +1 -0
  172. package/web/console/assets/{BrandLockup-CffORQse.js → BrandLockup-DQcaW4Nt.js} +1 -1
  173. package/web/console/assets/Channels-DJJU3ksE.css +1 -0
  174. package/web/console/assets/Channels-cGS5WfQ-.js +105 -0
  175. package/web/console/assets/ChatEntries-BYpji27B.css +1 -0
  176. package/web/console/assets/ChatEntries-nh23Iz5O.js +7 -0
  177. package/web/console/assets/Clients-CX5EeYio.js +3 -0
  178. package/web/console/assets/Clients-CbZAou8E.css +1 -0
  179. package/web/console/assets/Cost-C6oQvz9P.css +1 -0
  180. package/web/console/assets/Cost-DOZfdNS9.js +1 -0
  181. package/web/console/assets/Credentials--aHs57yV.css +1 -0
  182. package/web/console/assets/Credentials-sy6W9Sac.js +1 -0
  183. package/web/console/assets/Diagnostics-CKs27Dnv.css +1 -0
  184. package/web/console/assets/Diagnostics-CyoM1XrZ.js +1 -0
  185. package/web/console/assets/Executors-2Upi6bOS.css +1 -0
  186. package/web/console/assets/Executors-BQqqiFwt.js +1 -0
  187. package/web/console/assets/HelpTip-DLlhaGQp.js +1 -0
  188. package/web/console/assets/HelpTip-bbDEyuqV.css +1 -0
  189. package/web/console/assets/Kb-5R3ce4UU.js +5 -0
  190. package/web/console/assets/Kb-BM_PYi11.css +1 -0
  191. package/web/console/assets/{Login-CGgLGTE1.js → Login-YKeUwdgo.js} +1 -1
  192. package/web/console/assets/Projects-DHwHrPT9.css +1 -0
  193. package/web/console/assets/Projects-Grgb6fOv.js +1 -0
  194. package/web/console/assets/Routes-DR_Yf02e.css +1 -0
  195. package/web/console/assets/Routes-DYgrXlRJ.js +138 -0
  196. package/web/console/assets/Runs-CwTddJJj.js +3 -0
  197. package/web/console/assets/Runs-D4FOvNfu.css +1 -0
  198. package/web/console/assets/Setup-Ca0b1d1-.css +1 -0
  199. package/web/console/assets/Setup-D_xUPNDq.js +1 -0
  200. package/web/console/assets/Shell-BTg8Vw_L.css +1 -0
  201. package/web/console/assets/Shell-Dfam2Uoj.js +1 -0
  202. package/web/console/assets/StorageBuckets-7QLBpV4a.css +1 -0
  203. package/web/console/assets/StorageBuckets-CP6e50wI.js +1 -0
  204. package/web/console/assets/SystemSettings-BRYKyJNa.js +1 -0
  205. package/web/console/assets/SystemSettings-HsXGx0aH.css +1 -0
  206. package/web/console/assets/SystemStatus-B-VfRsQd.css +1 -0
  207. package/web/console/assets/SystemStatus-CbPsDsGt.js +1 -0
  208. package/web/console/assets/Targets-1j4-g6rC.css +1 -0
  209. package/web/console/assets/Targets-C2LkR2AF.js +1 -0
  210. package/web/console/assets/Tools-C9HPJqJb.css +1 -0
  211. package/web/console/assets/Tools-C9JNJUS0.js +2 -0
  212. package/web/console/assets/Usage-D1Mv6vGY.js +1 -0
  213. package/web/console/assets/Usage-DMOzUsqh.css +1 -0
  214. package/web/console/assets/UsageAccess-77LmGCm6.js +1 -0
  215. package/web/console/assets/UsageAccess-C6ZGxEgJ.css +1 -0
  216. package/web/console/assets/{UsageHelp-CzS2gI40.js → UsageHelp-BmuiE1Ew.js} +1 -1
  217. package/web/console/assets/client-route-draft-DxZRxKPT.js +1 -0
  218. package/web/console/assets/console-location-Csv-xsnl.js +1 -0
  219. package/web/console/assets/form-guard-8GrFpry0.js +1 -0
  220. package/web/console/assets/{index-65JiiUr4.js → index-B_5UfiTw.js} +1 -1
  221. package/web/console/assets/index-MjZJEFIN.js +2 -0
  222. package/web/console/assets/{request-DKycpD7z.js → request-rqm6MT0s.js} +1 -1
  223. package/web/console/assets/runtime-feedback-gPfZVNvY.js +1 -0
  224. package/web/console/assets/{schema-SCiNxBlR.js → schema-o3mK4mid.js} +1 -1
  225. package/web/console/assets/task-page-location-DWiGtAln.js +1 -0
  226. package/web/console/assets/use-list-location-FvLFt0Tq.css +1 -0
  227. package/web/console/assets/use-list-location-cIPy2cKM.js +1 -0
  228. package/web/console/assets/use-unsaved-form-DScKD0h9.js +1 -0
  229. package/web/console/assets/{util-DZYfJ5Zo.js → util-B40VqOwl.js} +1 -1
  230. package/web/console/assets/{vendor-element-8cVcdt5T.js → vendor-element-BT8tHCFk.js} +1 -1
  231. package/web/console/assets/{vendor-mammoth-CnDA23N0.js → vendor-mammoth-CVIXVxTN.js} +1 -1
  232. package/web/console/assets/{vendor-vue-Co7x2FW6.js → vendor-vue-DhbG0vd4.js} +7 -7
  233. package/web/console/index.html +3 -3
  234. package/web-admin/package-lock.json +4 -4
  235. package/web-admin/package.json +1 -1
  236. package/web-admin/src/client-route-draft.ts +25 -0
  237. package/web-admin/src/components/AgentSetupPanel.vue +54 -41
  238. package/web-admin/src/components/HelpTip.vue +4 -1
  239. package/web-admin/src/components/ListLocationBar.vue +22 -0
  240. package/web-admin/src/components/NotificationOutboxPanel.vue +35 -7
  241. package/web-admin/src/console-entry.test.ts +26 -0
  242. package/web-admin/src/console-entry.ts +20 -0
  243. package/web-admin/src/console-location.ts +35 -0
  244. package/web-admin/src/form-guard.ts +35 -0
  245. package/web-admin/src/layout/Shell.vue +18 -65
  246. package/web-admin/src/onboarding-state.test.ts +174 -0
  247. package/web-admin/src/onboarding-state.ts +122 -0
  248. package/web-admin/src/pages/Accounts.vue +44 -24
  249. package/web-admin/src/pages/AgentClients.vue +47 -29
  250. package/web-admin/src/pages/AgentTasks.vue +57 -12
  251. package/web-admin/src/pages/Approvals.vue +105 -25
  252. package/web-admin/src/pages/Audit.vue +15 -6
  253. package/web-admin/src/pages/Channels.vue +136 -43
  254. package/web-admin/src/pages/ChatEntries.vue +96 -41
  255. package/web-admin/src/pages/Clients.vue +87 -26
  256. package/web-admin/src/pages/Cost.vue +15 -4
  257. package/web-admin/src/pages/Credentials.vue +63 -32
  258. package/web-admin/src/pages/Diagnostics.vue +103 -54
  259. package/web-admin/src/pages/Executors.vue +103 -40
  260. package/web-admin/src/pages/Kb.vue +278 -128
  261. package/web-admin/src/pages/Projects.vue +44 -16
  262. package/web-admin/src/pages/Routes.vue +168 -247
  263. package/web-admin/src/pages/Runs.vue +163 -91
  264. package/web-admin/src/pages/Setup.vue +182 -291
  265. package/web-admin/src/pages/StorageBuckets.vue +61 -25
  266. package/web-admin/src/pages/SystemSettings.vue +76 -51
  267. package/web-admin/src/pages/SystemStatus.vue +54 -30
  268. package/web-admin/src/pages/Targets.vue +45 -17
  269. package/web-admin/src/pages/Tools.vue +133 -68
  270. package/web-admin/src/pages/Usage.vue +64 -25
  271. package/web-admin/src/pages/UsageAccess.vue +11 -8
  272. package/web-admin/src/route-call-snippets.test.ts +82 -0
  273. package/web-admin/src/route-call-snippets.ts +178 -0
  274. package/web-admin/src/router.ts +11 -29
  275. package/web-admin/src/runtime-feedback.ts +43 -0
  276. package/web-admin/src/task-page-location.ts +66 -0
  277. package/web-admin/src/usage-output-budget.test.ts +26 -0
  278. package/web-admin/src/usage-output-budget.ts +46 -0
  279. package/web-admin/src/use-list-location.ts +24 -0
  280. package/web-admin/src/use-unsaved-form.ts +38 -0
  281. package/web-admin/tests/model-output-budget.browser.mjs +69 -0
  282. package/web/console/assets/Accounts-Bervi5JU.css +0 -1
  283. package/web/console/assets/Accounts-Dhj6PjXP.js +0 -3
  284. package/web/console/assets/AgentClients-CMy8StAH.js +0 -1
  285. package/web/console/assets/AgentClients-i52AI6YV.css +0 -1
  286. package/web/console/assets/AgentTasks-BsG850Il.css +0 -1
  287. package/web/console/assets/AgentTasks-DA1xZdmP.js +0 -2
  288. package/web/console/assets/Approvals-DIsd7R8N.js +0 -1
  289. package/web/console/assets/Approvals-DlTSHl_7.css +0 -1
  290. package/web/console/assets/Audit-AUDABLTX.js +0 -1
  291. package/web/console/assets/Audit-CSu6_3oD.css +0 -1
  292. package/web/console/assets/Channels-B8rjsM0S.js +0 -105
  293. package/web/console/assets/Channels-CCn0L1jg.css +0 -1
  294. package/web/console/assets/ChatEntries-DsYtcXN6.css +0 -1
  295. package/web/console/assets/ChatEntries-iZjJMEUZ.js +0 -7
  296. package/web/console/assets/Clients-CSHIsaWU.css +0 -1
  297. package/web/console/assets/Clients-CwgpGCSD.js +0 -3
  298. package/web/console/assets/Cost-B2tNxu71.js +0 -1
  299. package/web/console/assets/Cost-CjT39DSZ.css +0 -1
  300. package/web/console/assets/Credentials-BuwFB-fV.js +0 -1
  301. package/web/console/assets/Credentials-ioLP0qYN.css +0 -1
  302. package/web/console/assets/Diagnostics-Ya05PTDp.css +0 -1
  303. package/web/console/assets/Diagnostics-z5glms11.js +0 -1
  304. package/web/console/assets/Executors-Bc4SvjeH.js +0 -1
  305. package/web/console/assets/Executors-CjhEM54c.css +0 -1
  306. package/web/console/assets/HelpTip-CA6Bm7Nx.css +0 -1
  307. package/web/console/assets/HelpTip-Dtdt2tKR.js +0 -1
  308. package/web/console/assets/Kb-BRbRHxLy.js +0 -5
  309. package/web/console/assets/Kb-CzIzd9xr.css +0 -1
  310. package/web/console/assets/Projects-Bm8AjsNx.css +0 -1
  311. package/web/console/assets/Projects-CPWw3con.js +0 -1
  312. package/web/console/assets/Routes-CMIaE0Bx.js +0 -124
  313. package/web/console/assets/Routes-CyXV4Pba.css +0 -1
  314. package/web/console/assets/Runs-B8HuE700.js +0 -3
  315. package/web/console/assets/Runs-Bv6CV_Hk.css +0 -1
  316. package/web/console/assets/Setup-D7nxgn-9.css +0 -1
  317. package/web/console/assets/Setup-G8RKzliR.js +0 -1
  318. package/web/console/assets/Shell-DimHgraJ.js +0 -1
  319. package/web/console/assets/Shell-ykb-tUfo.css +0 -1
  320. package/web/console/assets/StorageBuckets-CVgpZRWY.css +0 -1
  321. package/web/console/assets/StorageBuckets-CiVYXIE2.js +0 -1
  322. package/web/console/assets/SystemSettings-BjiHyrXO.css +0 -1
  323. package/web/console/assets/SystemSettings-DF8sZNen.js +0 -1
  324. package/web/console/assets/SystemStatus-BlHywK13.js +0 -1
  325. package/web/console/assets/SystemStatus-I11I67rw.css +0 -1
  326. package/web/console/assets/Targets-BXaoPoAJ.js +0 -1
  327. package/web/console/assets/Targets-DTb5tn6z.css +0 -1
  328. package/web/console/assets/Tools-B22lNHXq.js +0 -2
  329. package/web/console/assets/Tools-DU8ei6sd.css +0 -1
  330. package/web/console/assets/Usage-C02EzoI2.js +0 -1
  331. package/web/console/assets/Usage-CAeDGjrb.css +0 -1
  332. package/web/console/assets/UsageAccess-CGGaWTuj.css +0 -1
  333. package/web/console/assets/UsageAccess-DOb-cyPE.js +0 -1
  334. package/web/console/assets/index-CK0ZCTZv.js +0 -2
@@ -38,17 +38,17 @@ final class AiTool
38
38
  public string $method = 'GET',
39
39
  /** 工具名(operationId),缺省 = 蛇形(类名去Controller)_蛇形(方法名),如 StaffController::list → staff_list。建议显式指定;定了就别改:改名会让 AI 认为这是另一个新工具 */
40
40
  public ?string $name = null,
41
- /** 风险级:low(默认,直接放行)/ medium(放行留痕)/ high(先进人工审批) */
42
- public string $risk = 'low',
41
+ /** 显式风险级 low / medium / high;null 表示省略,由 ACC 及 binding 缺省规则推导。 */
42
+ public ?string $risk = null,
43
43
  /** true = 不论风险级一律先人工审批(批准后任务自动重跑执行) */
44
44
  public bool $confirm = false,
45
45
  /** 参数级确认规则,如 [['param' => 'amount', 'op' => '>', 'value' => 500, 'label' => '大额退款需确认']] */
46
46
  public array $confirmWhen = [],
47
- /** 语义只读声明:GET 默认只读;POST 实现的查询接口务必标 true,AI 才敢放心调用 */
47
+ /** 显式只读声明,true/false 均保留;null 表示省略,由 binding 解释 GET 等缺省信号。 */
48
48
  public ?bool $readonly = null,
49
49
  /** true = 必须有操作主体(X-Bailing-On-Behalf-Of)才有意义;匿名任务(网页访客)直接看不到该工具 */
50
50
  public bool $requiresSubject = false,
51
- /** 可安全重试(GET 默认 true);网络抖动时大脑可凭此决定是否自动重发 */
51
+ /** 显式幂等提示,true/false 均保留;null 表示省略,不替运行时决定重试。 */
52
52
  public ?bool $idempotent = null,
53
53
  /** true = 参数含敏感数据(手机号/身份证等):中枢审计只记参数键名不记值 */
54
54
  public bool $sensitive = false,
@@ -101,7 +101,7 @@ final class SpecBuilder
101
101
  if (trim($t->scope) === '') {
102
102
  throw new InvalidArgumentException("{$where}: scope 不能为空(中枢会直接跳过该接口)");
103
103
  }
104
- if (!in_array($t->risk, ['low', 'medium', 'high'], true)) {
104
+ if ($t->risk !== null && !in_array($t->risk, ['low', 'medium', 'high'], true)) {
105
105
  throw new InvalidArgumentException("{$where}: risk 仅支持 low/medium/high,收到 {$t->risk}");
106
106
  }
107
107
  if ($t->rateLimit !== null && self::parseRateLimit($t->rateLimit) === null) {
@@ -194,10 +194,10 @@ final class SpecBuilder
194
194
  }
195
195
 
196
196
  /** @return array<string,mixed> */
197
- private function buildCapability(AiTool $t, string $method): array
197
+ private function buildCapability(AiTool $t): array
198
198
  {
199
199
  $capability = ['version' => 1, 'enabled' => true, 'scope' => $t->scope];
200
- if ($t->risk !== 'low') {
200
+ if ($t->risk !== null) {
201
201
  $capability['risk'] = ['level' => $t->risk];
202
202
  }
203
203
  if ($t->confirm || $t->confirmWhen || $t->confirmPrompt !== null) {
@@ -217,11 +217,11 @@ final class SpecBuilder
217
217
  $capability['subject'] = ['required' => true];
218
218
  }
219
219
  $execution = [];
220
- if (($t->readonly ?? ($method === 'GET')) && $method !== 'GET') {
221
- $execution['readonly'] = true;
220
+ if ($t->readonly !== null) {
221
+ $execution['readonly'] = $t->readonly;
222
222
  }
223
- if (($t->idempotent ?? ($method === 'GET')) && $method !== 'GET') {
224
- $execution['idempotent'] = true;
223
+ if ($t->idempotent !== null) {
224
+ $execution['idempotent'] = $t->idempotent;
225
225
  }
226
226
  $rateLimit = self::parseRateLimit($t->rateLimit);
227
227
  if ($rateLimit !== null) {
@@ -261,7 +261,7 @@ final class SpecBuilder
261
261
  $op = [
262
262
  'operationId' => $name,
263
263
  'summary' => $t->description,
264
- 'x-agent-capability' => $this->buildCapability($t, $method),
264
+ 'x-agent-capability' => $this->buildCapability($t),
265
265
  ];
266
266
  // 非核心 OpenAPI 字段才继续落到 operation 顶层;治理字段统一放入 ACC。
267
267
  if ($t->tags) {
@@ -0,0 +1,103 @@
1
+ <?php
2
+
3
+ declare(strict_types=1);
4
+
5
+ // An optional SDK root verifies the same cases against an extracted distribution.
6
+ $sdkRoot = isset($argv[1]) ? rtrim($argv[1], '/\\') : dirname(__DIR__);
7
+ require_once $sdkRoot . '/src/Attributes/AiTool.php';
8
+ require_once $sdkRoot . '/src/Attributes/AiParam.php';
9
+ require_once $sdkRoot . '/src/SpecBuilder.php';
10
+
11
+ use Bailing\Connect\SpecBuilder;
12
+
13
+ $checks = 0;
14
+ $errors = [];
15
+ $matrix = [];
16
+ $idempotence = [];
17
+
18
+ function serializationCheck(bool $condition, string $label): void
19
+ {
20
+ global $checks, $errors;
21
+ $checks++;
22
+ if (!$condition) $errors[] = $label;
23
+ }
24
+
25
+ function generatedCapability(string $method, ?bool $readonly, ?string $risk, ?bool $idempotent = null, bool $governance = false): array
26
+ {
27
+ static $case = 0;
28
+ $class = 'SyntheticDeclarationCase' . ++$case;
29
+ $arguments = [
30
+ 'description' => 'Synthetic declaration regression case',
31
+ 'scope' => 'example.record.read', 'path' => '/serialization-case',
32
+ 'method' => $method, 'name' => 'serialization_case',
33
+ ];
34
+ if ($readonly !== null) $arguments['readonly'] = $readonly;
35
+ if ($risk !== null) $arguments['risk'] = $risk;
36
+ if ($idempotent !== null) $arguments['idempotent'] = $idempotent;
37
+ if ($governance) {
38
+ $arguments['requiresSubject'] = true;
39
+ $arguments['confirm'] = true;
40
+ $arguments['confirmPrompt'] = 'Approve {record_id}';
41
+ $arguments['confirmWhen'] = [['param' => 'record_id', 'op' => '>', 'value' => 100]];
42
+ }
43
+ $attributeArguments = [];
44
+ foreach ($arguments as $key => $value) $attributeArguments[] = $key . ': ' . var_export($value, true);
45
+ // Only fixed synthetic values are evaluated. SpecBuilder must discover and
46
+ // instantiate the real attributes through ReflectionClass/ReflectionMethod.
47
+ eval('class ' . $class . ' {' .
48
+ '#[\\Bailing\\Connect\\Attributes\\AiTool(' . implode(', ', $attributeArguments) . ')]' .
49
+ '#[\\Bailing\\Connect\\Attributes\\AiParam("record_id", type: "integer", required: true)]' .
50
+ 'public function execute(): void {} }');
51
+ $spec = json_decode((new SpecBuilder('Synthetic declaration regression'))->addClass($class)->buildJson(false), true, 512, JSON_THROW_ON_ERROR);
52
+ return $spec['paths']['/serialization-case'][strtolower($method)]['x-agent-capability'];
53
+ }
54
+
55
+ foreach (['GET', 'POST'] as $method) {
56
+ foreach ([null, false, true] as $readonly) {
57
+ foreach ([null, 'low', 'medium', 'high'] as $risk) {
58
+ $capability = generatedCapability($method, $readonly, $risk);
59
+ $execution = $capability['execution'] ?? [];
60
+ $label = $method . '/readonly=' . json_encode($readonly) . '/risk=' . json_encode($risk);
61
+ serializationCheck($capability['version'] === 1 && $capability['enabled'] === true && $capability['scope'] === 'example.record.read', $label . ': declaration identity');
62
+ serializationCheck(array_key_exists('risk', $capability) === ($risk !== null), $label . ': risk presence');
63
+ if ($risk !== null) serializationCheck(($capability['risk']['level'] ?? null) === $risk, $label . ': risk value');
64
+ serializationCheck(array_key_exists('readonly', $execution) === ($readonly !== null), $label . ': readonly presence');
65
+ if ($readonly !== null) serializationCheck(array_key_exists('readonly', $execution) && $execution['readonly'] === $readonly, $label . ': readonly value');
66
+ serializationCheck(!array_key_exists('idempotent', $execution), $label . ': unset idempotent remains omitted');
67
+
68
+ // ACC v1 + OpenAPI binding: explicit values win; GET is only a fallback.
69
+ $expectedReadonly = $readonly === null ? $method === 'GET' : $readonly;
70
+ $expectedRisk = $risk ?? ($expectedReadonly ? 'low' : 'medium');
71
+ $wireReadonly = array_key_exists('readonly', $execution) ? $execution['readonly'] : $method === 'GET';
72
+ $effectiveRisk = $capability['risk']['level'] ?? ($wireReadonly ? 'low' : 'medium');
73
+ serializationCheck($effectiveRisk === $expectedRisk, $label . ': effective risk');
74
+ $matrix[] = ['method' => $method, 'readonly' => $readonly, 'risk' => $risk, 'capability' => $capability, 'expectedRisk' => $expectedRisk, 'effectiveRisk' => $effectiveRisk];
75
+ }
76
+ }
77
+ foreach ([null, false, true] as $idempotent) {
78
+ $capability = generatedCapability($method, null, null, $idempotent);
79
+ $execution = $capability['execution'] ?? [];
80
+ $label = $method . '/idempotent=' . json_encode($idempotent);
81
+ serializationCheck(array_key_exists('idempotent', $execution) === ($idempotent !== null), $label . ': presence');
82
+ if ($idempotent !== null) serializationCheck(array_key_exists('idempotent', $execution) && $execution['idempotent'] === $idempotent, $label . ': value');
83
+ serializationCheck(!array_key_exists('risk', $capability) && !array_key_exists('readonly', $execution), $label . ': unrelated unset fields remain omitted');
84
+ $idempotence[] = ['method' => $method, 'idempotent' => $idempotent, 'capability' => $capability];
85
+ }
86
+ }
87
+
88
+ $governance = generatedCapability('POST', false, 'low', false, true);
89
+ serializationCheck($governance === [
90
+ 'version' => 1, 'enabled' => true, 'scope' => 'example.record.read',
91
+ 'risk' => ['level' => 'low'],
92
+ 'approval' => ['required' => true, 'when' => [['param' => 'record_id', 'op' => '>', 'value' => 100]], 'prompt' => 'Approve {record_id}'],
93
+ 'subject' => ['required' => true],
94
+ 'execution' => ['readonly' => false, 'idempotent' => false],
95
+ ], 'explicit low and false do not remove approval or subject requirements');
96
+
97
+ echo json_encode([
98
+ 'sdk' => 'php', 'phpVersion' => PHP_VERSION,
99
+ 'matrixCases' => count($matrix), 'idempotenceCases' => count($idempotence),
100
+ 'checks' => $checks, 'passed' => !$errors, 'errors' => $errors,
101
+ 'matrix' => $matrix, 'idempotence' => $idempotence,
102
+ ], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR) . "\n";
103
+ exit($errors ? 1 : 0);
@@ -67,6 +67,20 @@ $spec = ToolSpec::create('示例业务系统') // 标题随便填
67
67
 
68
68
  构建期即体检:scope 缺失、写接口无参数、工具名/路由重复、risk 非法等会**直接抛 `InvalidArgumentException`**,CI 跑构建即完成体检,不会等发布后才在控制台"被跳过"列表里发现。
69
69
 
70
+ ### 显式声明与缺省值
71
+
72
+ `readonly(false)` / `readonly(true)`、`idempotent(false)` / `idempotent(true)` 和显式 `risk('low'|'medium'|'high')` 都会原样写入 ACC。未调用相应方法时保持省略,由 ACC v1 及 OpenAPI binding 的缺省规则推导:GET + `readonly(false)` 且未设置 risk 为 `medium`;非只读 POST 显式 `risk('low')` 仍为 `low`。风险值不取消既有审批与最终业务授权要求。
73
+
74
+ 升级后请重新生成、核对并刷新工具源声明。过去被省略的显式值现在会出现,JSON/ETag 可能变化,方法签名与 ACC 的 `version: 1` 不变。不需要批量给写接口添加 `risk('low')`。
75
+
76
+ 实际生成器回归兼容 PHP 7.3,覆盖 24 种 readonly/risk 组合、6 种幂等声明组合及审批/主体保留检查:
77
+
78
+ ```bash
79
+ php tests/declaration-serialization.php
80
+ # 用同一套测试检查另一个解包目录:
81
+ php tests/declaration-serialization.php /path/to/bailing-connect-php7
82
+ ```
83
+
70
84
  ## 第二步:发布 spec
71
85
 
72
86
  把 `buildJson()` 的产物挂到中枢「工具源」登记的 `spec_url`。裸 PHP 单文件:
@@ -35,7 +35,7 @@ final class ToolDef
35
35
  }
36
36
 
37
37
  // ---- 治理面 ----
38
- /** 风险级 low(默认)/ medium(放行留痕)/ high(先进人工审批) */
38
+ /** 显式风险级 low / medium / high;不调用时省略,由 ACC 及 binding 缺省规则推导。 */
39
39
  public function risk($level)
40
40
  {
41
41
  $this->opt['risk'] = $level;
@@ -68,13 +68,13 @@ final class ToolDef
68
68
  $this->opt['sensitive'] = (bool) $v;
69
69
  return $this;
70
70
  }
71
- /** 语义只读声明:POST 实现的查询接口务必标,AI 才敢放心调用(GET 默认即只读) */
71
+ /** 显式只读声明,true/false 均保留;不调用时由 binding 解释 GET 等缺省信号。 */
72
72
  public function readonly($v = true)
73
73
  {
74
74
  $this->opt['readonly'] = (bool) $v;
75
75
  return $this;
76
76
  }
77
- /** 可安全重试(GET 默认 true):网络抖动时大脑可凭此自动重发 */
77
+ /** 显式幂等提示,true/false 均保留;未设置时省略,不替运行时决定重试。 */
78
78
  public function idempotent($v = true)
79
79
  {
80
80
  $this->opt['idempotent'] = (bool) $v;
@@ -110,9 +110,8 @@ final class ToolSpec
110
110
  if (trim((string) $d->name) === '') {
111
111
  throw new InvalidArgumentException("path {$d->path}: 工具名(第 1 个参数)不能为空");
112
112
  }
113
- $risk = isset($d->opt['risk']) ? $d->opt['risk'] : 'low';
114
- if (!in_array($risk, array('low', 'medium', 'high'), true)) {
115
- throw new InvalidArgumentException("{$where}: risk 仅支持 low/medium/high,收到 {$risk}");
113
+ if (isset($d->opt['risk']) && !in_array($d->opt['risk'], array('low', 'medium', 'high'), true)) {
114
+ throw new InvalidArgumentException("{$where}: risk 仅支持 low/medium/high,收到 {$d->opt['risk']}");
116
115
  }
117
116
  if (isset($d->opt['rateLimit']) && self::parseRateLimit($d->opt['rateLimit']) === null) {
118
117
  throw new InvalidArgumentException("{$where}: rateLimit 格式应为 \"30/min\"、\"600/hour\"、\"10/s\" 或 \"1000/day\",收到 {$d->opt['rateLimit']}");
@@ -195,11 +194,9 @@ final class ToolSpec
195
194
  private function buildCapability(ToolDef $d)
196
195
  {
197
196
  $o = $d->opt;
198
- $method = $d->method;
199
197
  $capability = array('version' => 1, 'enabled' => true, 'scope' => $d->scope);
200
- $risk = isset($o['risk']) ? $o['risk'] : 'low';
201
- if ($risk !== 'low') {
202
- $capability['risk'] = array('level' => $risk);
198
+ if (isset($o['risk'])) {
199
+ $capability['risk'] = array('level' => $o['risk']);
203
200
  }
204
201
  if (!empty($o['confirm']) || !empty($o['confirmWhen']) || isset($o['confirmPrompt'])) {
205
202
  $approval = array();
@@ -218,13 +215,11 @@ final class ToolSpec
218
215
  $capability['subject'] = array('required' => true);
219
216
  }
220
217
  $execution = array();
221
- $readonly = array_key_exists('readonly', $o) ? $o['readonly'] : ($method === 'GET');
222
- if ($readonly && $method !== 'GET') {
223
- $execution['readonly'] = true;
218
+ if (array_key_exists('readonly', $o)) {
219
+ $execution['readonly'] = $o['readonly'];
224
220
  }
225
- $idempotent = array_key_exists('idempotent', $o) ? $o['idempotent'] : ($method === 'GET');
226
- if ($idempotent && $method !== 'GET') {
227
- $execution['idempotent'] = true;
221
+ if (array_key_exists('idempotent', $o)) {
222
+ $execution['idempotent'] = $o['idempotent'];
228
223
  }
229
224
  if (isset($o['rateLimit'])) {
230
225
  $rateLimit = self::parseRateLimit($o['rateLimit']);
@@ -0,0 +1,103 @@
1
+ <?php
2
+
3
+ // Run with PHP >= 7.3. An optional SDK root verifies an extracted distribution:
4
+ // php tests/declaration-serialization.php /path/to/bailing-connect-php7
5
+ $sdkRoot = isset($argv[1]) ? rtrim($argv[1], '/\\') : dirname(__DIR__);
6
+ require_once $sdkRoot . '/src/ToolDef.php';
7
+ require_once $sdkRoot . '/src/ToolSpec.php';
8
+
9
+ use Bailing\Connect\ToolDef;
10
+ use Bailing\Connect\ToolSpec;
11
+
12
+ $checks = 0;
13
+ $errors = array();
14
+ $matrix = array();
15
+ $idempotence = array();
16
+
17
+ function serializationCheck($condition, $label)
18
+ {
19
+ global $checks, $errors;
20
+ $checks++;
21
+ if (!$condition) {
22
+ $errors[] = $label;
23
+ }
24
+ }
25
+
26
+ function generatedCapability($method, $readonly, $risk, $idempotent = null, $governance = false)
27
+ {
28
+ $builder = ToolSpec::create('Synthetic declaration regression')->tool(
29
+ 'serialization_case', $method, '/serialization-case', 'example.record.read',
30
+ 'Synthetic declaration regression case',
31
+ function (ToolDef $tool) use ($method, $readonly, $risk, $idempotent, $governance) {
32
+ if ($method === 'GET') {
33
+ $tool->query('record_id', 'integer', true);
34
+ } else {
35
+ $tool->body('record_id', 'integer', true);
36
+ }
37
+ if ($readonly !== null) $tool->readonly($readonly);
38
+ if ($risk !== null) $tool->risk($risk);
39
+ if ($idempotent !== null) $tool->idempotent($idempotent);
40
+ if ($governance) {
41
+ $tool->requiresSubject()->confirm('Approve {record_id}')->confirmWhen(array(
42
+ array('param' => 'record_id', 'op' => '>', 'value' => 100),
43
+ ));
44
+ }
45
+ }
46
+ );
47
+ // Test the actual JSON wire output, not a copied private serialization function.
48
+ $spec = json_decode($builder->buildJson(false), true);
49
+ if (!is_array($spec) || !isset($spec['paths']['/serialization-case'][strtolower($method)]['x-agent-capability'])) {
50
+ throw new RuntimeException('Generator did not emit a valid ACC operation');
51
+ }
52
+ return $spec['paths']['/serialization-case'][strtolower($method)]['x-agent-capability'];
53
+ }
54
+
55
+ foreach (array('GET', 'POST') as $method) {
56
+ foreach (array(null, false, true) as $readonly) {
57
+ foreach (array(null, 'low', 'medium', 'high') as $risk) {
58
+ $capability = generatedCapability($method, $readonly, $risk);
59
+ $execution = isset($capability['execution']) ? $capability['execution'] : array();
60
+ $label = $method . '/readonly=' . json_encode($readonly) . '/risk=' . json_encode($risk);
61
+ serializationCheck($capability['version'] === 1 && $capability['enabled'] === true && $capability['scope'] === 'example.record.read', $label . ': declaration identity');
62
+ serializationCheck(array_key_exists('risk', $capability) === ($risk !== null), $label . ': risk presence');
63
+ if ($risk !== null) serializationCheck(isset($capability['risk']['level']) && $capability['risk']['level'] === $risk, $label . ': risk value');
64
+ serializationCheck(array_key_exists('readonly', $execution) === ($readonly !== null), $label . ': readonly presence');
65
+ if ($readonly !== null) serializationCheck(array_key_exists('readonly', $execution) && $execution['readonly'] === $readonly, $label . ': readonly value');
66
+ serializationCheck(!array_key_exists('idempotent', $execution), $label . ': unset idempotent remains omitted');
67
+
68
+ // ACC v1 + OpenAPI binding: explicit values win; GET is only a fallback.
69
+ $expectedReadonly = $readonly === null ? $method === 'GET' : $readonly;
70
+ $expectedRisk = $risk === null ? ($expectedReadonly ? 'low' : 'medium') : $risk;
71
+ $wireReadonly = array_key_exists('readonly', $execution) ? $execution['readonly'] : $method === 'GET';
72
+ $effectiveRisk = isset($capability['risk']['level']) ? $capability['risk']['level'] : ($wireReadonly ? 'low' : 'medium');
73
+ serializationCheck($effectiveRisk === $expectedRisk, $label . ': effective risk');
74
+ $matrix[] = array('method' => $method, 'readonly' => $readonly, 'risk' => $risk, 'capability' => $capability, 'expectedRisk' => $expectedRisk, 'effectiveRisk' => $effectiveRisk);
75
+ }
76
+ }
77
+ foreach (array(null, false, true) as $idempotent) {
78
+ $capability = generatedCapability($method, null, null, $idempotent);
79
+ $execution = isset($capability['execution']) ? $capability['execution'] : array();
80
+ $label = $method . '/idempotent=' . json_encode($idempotent);
81
+ serializationCheck(array_key_exists('idempotent', $execution) === ($idempotent !== null), $label . ': presence');
82
+ if ($idempotent !== null) serializationCheck(array_key_exists('idempotent', $execution) && $execution['idempotent'] === $idempotent, $label . ': value');
83
+ serializationCheck(!array_key_exists('risk', $capability) && !array_key_exists('readonly', $execution), $label . ': unrelated unset fields remain omitted');
84
+ $idempotence[] = array('method' => $method, 'idempotent' => $idempotent, 'capability' => $capability);
85
+ }
86
+ }
87
+
88
+ $governance = generatedCapability('POST', false, 'low', false, true);
89
+ serializationCheck($governance === array(
90
+ 'version' => 1, 'enabled' => true, 'scope' => 'example.record.read',
91
+ 'risk' => array('level' => 'low'),
92
+ 'approval' => array('required' => true, 'when' => array(array('param' => 'record_id', 'op' => '>', 'value' => 100)), 'prompt' => 'Approve {record_id}'),
93
+ 'subject' => array('required' => true),
94
+ 'execution' => array('readonly' => false, 'idempotent' => false),
95
+ ), 'explicit low and false do not remove approval or subject requirements');
96
+
97
+ echo json_encode(array(
98
+ 'sdk' => 'php7', 'phpVersion' => PHP_VERSION,
99
+ 'matrixCases' => count($matrix), 'idempotenceCases' => count($idempotence),
100
+ 'checks' => $checks, 'passed' => !$errors, 'errors' => $errors,
101
+ 'matrix' => $matrix, 'idempotence' => $idempotence,
102
+ ), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n";
103
+ exit($errors ? 1 : 0);
@@ -105,3 +105,11 @@ job = hub.run(
105
105
  result = hub.get_job(job["job_id"])
106
106
  hub.send("notice_1001", "team-im", "user_001", "任务已完成")
107
107
  ```
108
+
109
+ ## 声明字段的省略与显式值
110
+
111
+ 未设置的 `risk`、`readonly`、`idempotent` 不会写入 ACC 声明。显式的 `risk: low/medium/high` 和布尔值 `false/true` 都会保留,包括 GET 上的 `false`。省略风险时,按 ACC OpenAPI binding:显式只读优先于 HTTP 方法;未声明只读的 GET 默认 low,其余非只读操作默认 medium。风险声明不代替审批或业务最终授权。
112
+
113
+ 升级后应重新生成声明并比较差异;不要把以前省略的字段一律补成 low。 `tool()["risk"]` 在未设置时现在为 `None`,不再是 `"low"`;直接读取构建中间对象的调用方需兼容未设置状态。
114
+
115
+ 回归:`python3 sdk/python/tests/test_declaration.py`(24种只读/风险组合及6种幂等组合)。
@@ -85,7 +85,7 @@ def tool(**opts):
85
85
  "path": opts["path"],
86
86
  "method": str(opts.get("method", "GET")).upper(),
87
87
  "name": opts.get("name"),
88
- "risk": opts.get("risk", "low"),
88
+ "risk": opts.get("risk"),
89
89
  "confirm": bool(opts.get("confirm", False)),
90
90
  "confirmWhen": opts.get("confirmWhen", []),
91
91
  "readonly": opts.get("readonly"),
@@ -130,7 +130,7 @@ def _normalize_rate_limit(value: Any) -> Optional[Dict[str, Any]]:
130
130
 
131
131
  def _build_capability(t: Dict[str, Any], method: str) -> Dict[str, Any]:
132
132
  capability: Dict[str, Any] = {"version": 1, "enabled": True, "scope": t["scope"]}
133
- if t.get("risk") and t["risk"] != "low":
133
+ if t.get("risk") is not None:
134
134
  capability["risk"] = {"level": t["risk"]}
135
135
  if t.get("confirm") or t.get("confirmWhen") or t.get("confirmPrompt"):
136
136
  approval: Dict[str, Any] = {}
@@ -144,10 +144,10 @@ def _build_capability(t: Dict[str, Any], method: str) -> Dict[str, Any]:
144
144
  if t.get("requiresSubject"):
145
145
  capability["subject"] = {"required": True}
146
146
  execution: Dict[str, Any] = {}
147
- if t.get("readonly") is True and method != "GET":
148
- execution["readonly"] = True
149
- if t.get("idempotent") is True and method != "GET":
150
- execution["idempotent"] = True
147
+ if isinstance(t.get("readonly"), bool):
148
+ execution["readonly"] = t["readonly"]
149
+ if isinstance(t.get("idempotent"), bool):
150
+ execution["idempotent"] = t["idempotent"]
151
151
  rate_limit = _normalize_rate_limit(t.get("rateLimit"))
152
152
  if rate_limit:
153
153
  execution["rate_limit"] = rate_limit
@@ -0,0 +1,61 @@
1
+ """Exercise the public builder and its actual JSON output, without business calls."""
2
+ import json
3
+ from pathlib import Path
4
+ import sys
5
+ import unittest
6
+
7
+ sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
8
+ from bailing_connect import build_openapi_spec, param, tool
9
+
10
+
11
+ def capability(method, options):
12
+ spec = build_openapi_spec(tools=[tool(
13
+ name="serialization_fixture", description="Declaration serialization fixture",
14
+ path="/fixture", scope="fixture.write", method=method,
15
+ params=[param("fixture", type="string")], **options)])
16
+ return json.loads(json.dumps(spec))["paths"]["/fixture"][method.lower()]["x-agent-capability"]
17
+
18
+
19
+ class DeclarationTests(unittest.TestCase):
20
+ def test_readonly_risk_matrix(self):
21
+ combinations = 0
22
+ for method in ("GET", "POST"):
23
+ for readonly in (None, False, True):
24
+ for risk in (None, "low", "medium", "high"):
25
+ combinations += 1
26
+ with self.subTest(method=method, readonly=readonly, risk=risk):
27
+ options = {}
28
+ if readonly is not None:
29
+ options["readonly"] = readonly
30
+ if risk is not None:
31
+ options["risk"] = risk
32
+ cap = capability(method, options)
33
+ self.assertEqual("readonly" in cap.get("execution", {}), readonly is not None)
34
+ if readonly is not None:
35
+ self.assertIs(cap["execution"]["readonly"], readonly)
36
+ self.assertEqual("risk" in cap, risk is not None)
37
+ if risk is not None:
38
+ self.assertEqual(cap["risk"]["level"], risk)
39
+ expected_readonly = readonly if readonly is not None else method == "GET"
40
+ expected_risk = risk if risk is not None else ("low" if expected_readonly else "medium")
41
+ actual_readonly = cap.get("execution", {}).get("readonly", method == "GET")
42
+ actual_risk = cap.get("risk", {}).get("level", "low" if actual_readonly else "medium")
43
+ self.assertEqual(actual_risk, expected_risk)
44
+ self.assertEqual(cap["version"], 1)
45
+ self.assertEqual(combinations, 24)
46
+
47
+ def test_idempotent_presence_and_value(self):
48
+ combinations = 0
49
+ for method in ("GET", "POST"):
50
+ for value in (None, False, True):
51
+ combinations += 1
52
+ with self.subTest(method=method, idempotent=value):
53
+ cap = capability(method, {} if value is None else {"idempotent": value})
54
+ self.assertEqual("idempotent" in cap.get("execution", {}), value is not None)
55
+ if value is not None:
56
+ self.assertIs(cap["execution"]["idempotent"], value)
57
+ self.assertEqual(combinations, 6)
58
+
59
+
60
+ if __name__ == "__main__":
61
+ unittest.main()