@harrylabsj/kiwi 0.12.31 → 0.12.32

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 (307) hide show
  1. package/dist/a2a/node.d.ts +1 -0
  2. package/dist/a2a/node.js +170 -2
  3. package/dist/a2a/node.js.map +1 -1
  4. package/dist/a2a/reception/agent-runtime.d.ts +32 -1
  5. package/dist/a2a/reception/agent-runtime.js +420 -11
  6. package/dist/a2a/reception/agent-runtime.js.map +1 -1
  7. package/dist/a2a/reception/customer-memory-tools.d.ts +73 -0
  8. package/dist/a2a/reception/customer-memory-tools.js +17 -0
  9. package/dist/a2a/reception/customer-memory-tools.js.map +1 -0
  10. package/dist/a2a/reception/engine.d.ts +12 -0
  11. package/dist/a2a/reception/engine.js +42 -1
  12. package/dist/a2a/reception/engine.js.map +1 -1
  13. package/dist/a2a/reception/publish.d.ts +14 -1
  14. package/dist/a2a/reception/publish.js +62 -1
  15. package/dist/a2a/reception/publish.js.map +1 -1
  16. package/dist/a2a/reception/question-spec.d.ts +91 -0
  17. package/dist/a2a/reception/question-spec.js +260 -0
  18. package/dist/a2a/reception/question-spec.js.map +1 -0
  19. package/dist/a2a/reception/reply-outbox.d.ts +6 -0
  20. package/dist/a2a/reception/reply-outbox.js +44 -0
  21. package/dist/a2a/reception/reply-outbox.js.map +1 -1
  22. package/dist/a2a/reception/responder.d.ts +13 -1
  23. package/dist/a2a/reception/responder.js +26 -3
  24. package/dist/a2a/reception/responder.js.map +1 -1
  25. package/dist/a2a/reception/skill-catalog.d.ts +72 -0
  26. package/dist/a2a/reception/skill-catalog.js +85 -0
  27. package/dist/a2a/reception/skill-catalog.js.map +1 -0
  28. package/dist/a2a/reception/skill-contract.d.ts +70 -0
  29. package/dist/a2a/reception/skill-contract.js +183 -0
  30. package/dist/a2a/reception/skill-contract.js.map +1 -0
  31. package/dist/a2a/reception/types.d.ts +12 -0
  32. package/dist/a2a/server/customer-identity-gateway.d.ts +111 -0
  33. package/dist/a2a/server/customer-identity-gateway.js +441 -0
  34. package/dist/a2a/server/customer-identity-gateway.js.map +1 -0
  35. package/dist/a2a/server/merchant-handler.d.ts +34 -0
  36. package/dist/a2a/server/merchant-handler.js +439 -19
  37. package/dist/a2a/server/merchant-handler.js.map +1 -1
  38. package/dist/a2a/server/pipeline.js +74 -29
  39. package/dist/a2a/server/pipeline.js.map +1 -1
  40. package/dist/a2a/server/types.d.ts +2 -0
  41. package/dist/a2a/unit-alias.d.ts +3 -3
  42. package/dist/a2a/unit-alias.js +9 -5
  43. package/dist/a2a/unit-alias.js.map +1 -1
  44. package/dist/auth/merchant-sessions.d.ts +3 -0
  45. package/dist/auth/merchant-sessions.js +21 -5
  46. package/dist/auth/merchant-sessions.js.map +1 -1
  47. package/dist/buyer-core/a2a-knp.d.ts +4 -2
  48. package/dist/buyer-core/a2a-knp.js +5 -2
  49. package/dist/buyer-core/a2a-knp.js.map +1 -1
  50. package/dist/buyer-core/a2a-negotiator.d.ts +1 -0
  51. package/dist/buyer-core/a2a-negotiator.js +18 -11
  52. package/dist/buyer-core/a2a-negotiator.js.map +1 -1
  53. package/dist/buyer-core/a2a-quote-fetcher.d.ts +25 -0
  54. package/dist/buyer-core/a2a-quote-fetcher.js +82 -4
  55. package/dist/buyer-core/a2a-quote-fetcher.js.map +1 -1
  56. package/dist/buyer-core/a2a-quote-history.d.ts +94 -0
  57. package/dist/buyer-core/a2a-quote-history.js +149 -0
  58. package/dist/buyer-core/a2a-quote-history.js.map +1 -0
  59. package/dist/buyer-core/build-service.d.ts +19 -0
  60. package/dist/buyer-core/build-service.js +30 -1
  61. package/dist/buyer-core/build-service.js.map +1 -1
  62. package/dist/buyer-core/errors.d.ts +1 -1
  63. package/dist/buyer-core/errors.js +1 -0
  64. package/dist/buyer-core/errors.js.map +1 -1
  65. package/dist/buyer-core/open-inquiry-signer.d.ts +1 -0
  66. package/dist/buyer-core/open-inquiry-signer.js +5 -2
  67. package/dist/buyer-core/open-inquiry-signer.js.map +1 -1
  68. package/dist/buyer-core/protocol-recovery.d.ts +2 -1
  69. package/dist/buyer-core/protocol-recovery.js +14 -4
  70. package/dist/buyer-core/protocol-recovery.js.map +1 -1
  71. package/dist/buyer-core/service.d.ts +57 -5
  72. package/dist/buyer-core/service.js +275 -50
  73. package/dist/buyer-core/service.js.map +1 -1
  74. package/dist/buyer-core/store.d.ts +8 -0
  75. package/dist/buyer-core/store.js +37 -7
  76. package/dist/buyer-core/store.js.map +1 -1
  77. package/dist/cli.js +13 -2
  78. package/dist/cli.js.map +1 -1
  79. package/dist/cloud/bootstrap.js +141 -7
  80. package/dist/cloud/bootstrap.js.map +1 -1
  81. package/dist/commerce/receipt/dispatcher.d.ts +42 -0
  82. package/dist/commerce/receipt/dispatcher.js +68 -0
  83. package/dist/commerce/receipt/dispatcher.js.map +1 -0
  84. package/dist/commerce/receipt/receipts.d.ts +140 -0
  85. package/dist/commerce/receipt/receipts.js +247 -0
  86. package/dist/commerce/receipt/receipts.js.map +1 -0
  87. package/dist/config/profile.d.ts +2 -2
  88. package/dist/handoff/order-receipts.d.ts +62 -0
  89. package/dist/handoff/order-receipts.js +71 -0
  90. package/dist/handoff/order-receipts.js.map +1 -0
  91. package/dist/handoff/ucp-checkout/cart-channel.d.ts +2 -1
  92. package/dist/handoff/ucp-checkout/cart-channel.js +1 -0
  93. package/dist/handoff/ucp-checkout/cart-channel.js.map +1 -1
  94. package/dist/handoff/ucp-checkout/channel.d.ts +6 -0
  95. package/dist/handoff/ucp-checkout/channel.js +44 -0
  96. package/dist/handoff/ucp-checkout/channel.js.map +1 -1
  97. package/dist/http/cli.js +6 -0
  98. package/dist/http/cli.js.map +1 -1
  99. package/dist/http/merchant-management/api.d.ts +10 -0
  100. package/dist/http/merchant-management/api.js +443 -0
  101. package/dist/http/merchant-management/api.js.map +1 -1
  102. package/dist/http/merchant-management/draft-store.js +8 -6
  103. package/dist/http/merchant-management/draft-store.js.map +1 -1
  104. package/dist/http/merchant-management/page.js +2 -2
  105. package/dist/mcp/cli.js +6 -0
  106. package/dist/mcp/cli.js.map +1 -1
  107. package/dist/mcp/merchant-runtime-assembly.d.ts +20 -0
  108. package/dist/mcp/merchant-runtime-assembly.js +93 -3
  109. package/dist/mcp/merchant-runtime-assembly.js.map +1 -1
  110. package/dist/mcp/merchant-server.d.ts +5 -0
  111. package/dist/mcp/merchant-server.js +12 -0
  112. package/dist/mcp/merchant-server.js.map +1 -1
  113. package/dist/mcp/tools.js +7 -1
  114. package/dist/mcp/tools.js.map +1 -1
  115. package/dist/merchant/application/actor.d.ts +1 -1
  116. package/dist/merchant/application/actor.js +15 -0
  117. package/dist/merchant/application/actor.js.map +1 -1
  118. package/dist/merchant/workbench-server.d.ts +1 -0
  119. package/dist/merchant/workbench-server.js +176 -2
  120. package/dist/merchant/workbench-server.js.map +1 -1
  121. package/dist/merchant-core/budget/background-budget.d.ts +132 -0
  122. package/dist/merchant-core/budget/background-budget.js +308 -0
  123. package/dist/merchant-core/budget/background-budget.js.map +1 -0
  124. package/dist/merchant-core/context-governance/actor-context.d.ts +56 -0
  125. package/dist/merchant-core/context-governance/actor-context.js +76 -0
  126. package/dist/merchant-core/context-governance/actor-context.js.map +1 -0
  127. package/dist/merchant-core/context-governance/authority.d.ts +39 -0
  128. package/dist/merchant-core/context-governance/authority.js +28 -0
  129. package/dist/merchant-core/context-governance/authority.js.map +1 -0
  130. package/dist/merchant-core/context-governance/context-guard.d.ts +104 -0
  131. package/dist/merchant-core/context-governance/context-guard.js +194 -0
  132. package/dist/merchant-core/context-governance/context-guard.js.map +1 -0
  133. package/dist/merchant-core/context-governance/data-use-grant.d.ts +91 -0
  134. package/dist/merchant-core/context-governance/data-use-grant.js +211 -0
  135. package/dist/merchant-core/context-governance/data-use-grant.js.map +1 -0
  136. package/dist/merchant-core/context-governance/feature-flags.d.ts +32 -0
  137. package/dist/merchant-core/context-governance/feature-flags.js +83 -0
  138. package/dist/merchant-core/context-governance/feature-flags.js.map +1 -0
  139. package/dist/merchant-core/context-governance/pilot-readiness.d.ts +39 -0
  140. package/dist/merchant-core/context-governance/pilot-readiness.js +141 -0
  141. package/dist/merchant-core/context-governance/pilot-readiness.js.map +1 -0
  142. package/dist/merchant-core/context-governance/source-governance.d.ts +157 -0
  143. package/dist/merchant-core/context-governance/source-governance.js +492 -0
  144. package/dist/merchant-core/context-governance/source-governance.js.map +1 -0
  145. package/dist/merchant-core/context-governance/types.d.ts +62 -0
  146. package/dist/merchant-core/context-governance/types.js +92 -0
  147. package/dist/merchant-core/context-governance/types.js.map +1 -0
  148. package/dist/merchant-core/customer-delivery/binding.d.ts +55 -0
  149. package/dist/merchant-core/customer-delivery/binding.js +121 -0
  150. package/dist/merchant-core/customer-delivery/binding.js.map +1 -0
  151. package/dist/merchant-core/customer-delivery/channel.d.ts +75 -0
  152. package/dist/merchant-core/customer-delivery/channel.js +157 -0
  153. package/dist/merchant-core/customer-delivery/channel.js.map +1 -0
  154. package/dist/merchant-core/customer-delivery/consent-repository.d.ts +50 -0
  155. package/dist/merchant-core/customer-delivery/consent-repository.js +160 -0
  156. package/dist/merchant-core/customer-delivery/consent-repository.js.map +1 -0
  157. package/dist/merchant-core/customer-delivery/dispatcher-loop.d.ts +68 -0
  158. package/dist/merchant-core/customer-delivery/dispatcher-loop.js +132 -0
  159. package/dist/merchant-core/customer-delivery/dispatcher-loop.js.map +1 -0
  160. package/dist/merchant-core/customer-delivery/dispatcher.d.ts +118 -0
  161. package/dist/merchant-core/customer-delivery/dispatcher.js +166 -0
  162. package/dist/merchant-core/customer-delivery/dispatcher.js.map +1 -0
  163. package/dist/merchant-core/customer-delivery/email-adapter.d.ts +31 -0
  164. package/dist/merchant-core/customer-delivery/email-adapter.js +90 -0
  165. package/dist/merchant-core/customer-delivery/email-adapter.js.map +1 -0
  166. package/dist/merchant-core/customer-delivery/gate.d.ts +37 -0
  167. package/dist/merchant-core/customer-delivery/gate.js +196 -0
  168. package/dist/merchant-core/customer-delivery/gate.js.map +1 -0
  169. package/dist/merchant-core/customer-delivery/reconciliation.d.ts +13 -0
  170. package/dist/merchant-core/customer-delivery/reconciliation.js +70 -0
  171. package/dist/merchant-core/customer-delivery/reconciliation.js.map +1 -0
  172. package/dist/merchant-core/customer-delivery/repository.d.ts +55 -0
  173. package/dist/merchant-core/customer-delivery/repository.js +235 -0
  174. package/dist/merchant-core/customer-delivery/repository.js.map +1 -0
  175. package/dist/merchant-core/customer-delivery/smtp-adapter.d.ts +30 -0
  176. package/dist/merchant-core/customer-delivery/smtp-adapter.js +183 -0
  177. package/dist/merchant-core/customer-delivery/smtp-adapter.js.map +1 -0
  178. package/dist/merchant-core/customer-delivery/stream-gate.d.ts +45 -0
  179. package/dist/merchant-core/customer-delivery/stream-gate.js +123 -0
  180. package/dist/merchant-core/customer-delivery/stream-gate.js.map +1 -0
  181. package/dist/merchant-core/customer-delivery/types.d.ts +103 -0
  182. package/dist/merchant-core/customer-delivery/types.js +32 -0
  183. package/dist/merchant-core/customer-delivery/types.js.map +1 -0
  184. package/dist/merchant-core/customer-delivery/weixin-adapter.d.ts +35 -0
  185. package/dist/merchant-core/customer-delivery/weixin-adapter.js +56 -0
  186. package/dist/merchant-core/customer-delivery/weixin-adapter.js.map +1 -0
  187. package/dist/merchant-core/customer-memory/auto-identity.d.ts +43 -0
  188. package/dist/merchant-core/customer-memory/auto-identity.js +163 -0
  189. package/dist/merchant-core/customer-memory/auto-identity.js.map +1 -0
  190. package/dist/merchant-core/customer-memory/grants.d.ts +72 -0
  191. package/dist/merchant-core/customer-memory/grants.js +224 -0
  192. package/dist/merchant-core/customer-memory/grants.js.map +1 -0
  193. package/dist/merchant-core/customer-memory/history.d.ts +51 -0
  194. package/dist/merchant-core/customer-memory/history.js +252 -0
  195. package/dist/merchant-core/customer-memory/history.js.map +1 -0
  196. package/dist/merchant-core/customer-memory/identity.d.ts +66 -0
  197. package/dist/merchant-core/customer-memory/identity.js +249 -0
  198. package/dist/merchant-core/customer-memory/identity.js.map +1 -0
  199. package/dist/merchant-core/customer-memory/maintenance.d.ts +51 -0
  200. package/dist/merchant-core/customer-memory/maintenance.js +67 -0
  201. package/dist/merchant-core/customer-memory/maintenance.js.map +1 -0
  202. package/dist/merchant-core/customer-memory/memory.d.ts +119 -0
  203. package/dist/merchant-core/customer-memory/memory.js +502 -0
  204. package/dist/merchant-core/customer-memory/memory.js.map +1 -0
  205. package/dist/merchant-core/customer-memory/private-transport.d.ts +10 -0
  206. package/dist/merchant-core/customer-memory/private-transport.js +108 -0
  207. package/dist/merchant-core/customer-memory/private-transport.js.map +1 -0
  208. package/dist/merchant-core/customer-memory/quote-history.d.ts +160 -0
  209. package/dist/merchant-core/customer-memory/quote-history.js +392 -0
  210. package/dist/merchant-core/customer-memory/quote-history.js.map +1 -0
  211. package/dist/merchant-core/customer-memory/reception-provider.d.ts +69 -0
  212. package/dist/merchant-core/customer-memory/reception-provider.js +250 -0
  213. package/dist/merchant-core/customer-memory/reception-provider.js.map +1 -0
  214. package/dist/merchant-core/customer-memory/reception-writer.d.ts +19 -0
  215. package/dist/merchant-core/customer-memory/reception-writer.js +32 -0
  216. package/dist/merchant-core/customer-memory/reception-writer.js.map +1 -0
  217. package/dist/merchant-core/customer-memory/types.d.ts +111 -0
  218. package/dist/merchant-core/customer-memory/types.js +58 -0
  219. package/dist/merchant-core/customer-memory/types.js.map +1 -0
  220. package/dist/merchant-core/followup/repository.d.ts +2 -1
  221. package/dist/merchant-core/followup/repository.js +29 -23
  222. package/dist/merchant-core/followup/repository.js.map +1 -1
  223. package/dist/merchant-core/learning/evaluation-fixtures.d.ts +38 -0
  224. package/dist/merchant-core/learning/evaluation-fixtures.js +83 -0
  225. package/dist/merchant-core/learning/evaluation-fixtures.js.map +1 -0
  226. package/dist/merchant-core/learning/evaluation-suite-v1.d.ts +56 -0
  227. package/dist/merchant-core/learning/evaluation-suite-v1.js +129 -0
  228. package/dist/merchant-core/learning/evaluation-suite-v1.js.map +1 -0
  229. package/dist/merchant-core/learning/evaluation.d.ts +84 -0
  230. package/dist/merchant-core/learning/evaluation.js +581 -0
  231. package/dist/merchant-core/learning/evaluation.js.map +1 -0
  232. package/dist/merchant-core/learning/initial-skills.d.ts +36 -0
  233. package/dist/merchant-core/learning/initial-skills.js +67 -0
  234. package/dist/merchant-core/learning/initial-skills.js.map +1 -0
  235. package/dist/merchant-core/learning/precheck.d.ts +33 -0
  236. package/dist/merchant-core/learning/precheck.js +56 -0
  237. package/dist/merchant-core/learning/precheck.js.map +1 -0
  238. package/dist/merchant-core/learning/real-evaluation-runner.d.ts +52 -0
  239. package/dist/merchant-core/learning/real-evaluation-runner.js +167 -0
  240. package/dist/merchant-core/learning/real-evaluation-runner.js.map +1 -0
  241. package/dist/merchant-core/learning/reception-skill-catalog.d.ts +39 -0
  242. package/dist/merchant-core/learning/reception-skill-catalog.js +145 -0
  243. package/dist/merchant-core/learning/reception-skill-catalog.js.map +1 -0
  244. package/dist/merchant-core/learning/recovery-gateway.d.ts +27 -0
  245. package/dist/merchant-core/learning/recovery-gateway.js +106 -0
  246. package/dist/merchant-core/learning/recovery-gateway.js.map +1 -0
  247. package/dist/merchant-core/learning/repository.d.ts +130 -0
  248. package/dist/merchant-core/learning/repository.js +588 -0
  249. package/dist/merchant-core/learning/repository.js.map +1 -0
  250. package/dist/merchant-core/learning/service.d.ts +262 -0
  251. package/dist/merchant-core/learning/service.js +1498 -0
  252. package/dist/merchant-core/learning/service.js.map +1 -0
  253. package/dist/merchant-core/learning/test-dispatch-gateway.d.ts +43 -0
  254. package/dist/merchant-core/learning/test-dispatch-gateway.js +145 -0
  255. package/dist/merchant-core/learning/test-dispatch-gateway.js.map +1 -0
  256. package/dist/merchant-core/learning/types.d.ts +217 -0
  257. package/dist/merchant-core/learning/types.js +52 -0
  258. package/dist/merchant-core/learning/types.js.map +1 -0
  259. package/dist/merchant-core/migrations/ledgers.d.ts +40 -0
  260. package/dist/merchant-core/migrations/ledgers.js +824 -0
  261. package/dist/merchant-core/migrations/ledgers.js.map +1 -0
  262. package/dist/merchant-core/migrations/runner.d.ts +55 -0
  263. package/dist/merchant-core/migrations/runner.js +114 -0
  264. package/dist/merchant-core/migrations/runner.js.map +1 -0
  265. package/dist/merchant-core/operations-jobs/advice-runner.d.ts +63 -0
  266. package/dist/merchant-core/operations-jobs/advice-runner.js +199 -0
  267. package/dist/merchant-core/operations-jobs/advice-runner.js.map +1 -0
  268. package/dist/merchant-core/operations-jobs/pilot-evidence.d.ts +64 -0
  269. package/dist/merchant-core/operations-jobs/pilot-evidence.js +109 -0
  270. package/dist/merchant-core/operations-jobs/pilot-evidence.js.map +1 -0
  271. package/dist/merchant-core/operations-jobs/pilot-metrics.d.ts +70 -0
  272. package/dist/merchant-core/operations-jobs/pilot-metrics.js +98 -0
  273. package/dist/merchant-core/operations-jobs/pilot-metrics.js.map +1 -0
  274. package/dist/merchant-core/operations-jobs/projection.d.ts +41 -0
  275. package/dist/merchant-core/operations-jobs/projection.js +158 -0
  276. package/dist/merchant-core/operations-jobs/projection.js.map +1 -0
  277. package/dist/merchant-core/operations-jobs/scheduler.d.ts +68 -0
  278. package/dist/merchant-core/operations-jobs/scheduler.js +233 -0
  279. package/dist/merchant-core/operations-jobs/scheduler.js.map +1 -0
  280. package/dist/merchant-core/operations-jobs/service.d.ts +260 -0
  281. package/dist/merchant-core/operations-jobs/service.js +922 -0
  282. package/dist/merchant-core/operations-jobs/service.js.map +1 -0
  283. package/dist/merchant-core/ops/facade.d.ts +10 -0
  284. package/dist/merchant-core/ops/facade.js +52 -0
  285. package/dist/merchant-core/ops/facade.js.map +1 -1
  286. package/dist/merchant-core/ops/schema.d.ts +1 -1
  287. package/dist/merchant-core/ops/schema.js +119 -2
  288. package/dist/merchant-core/ops/schema.js.map +1 -1
  289. package/dist/merchant-core/ops/surface.d.ts +37 -0
  290. package/dist/merchant-core/ops/surface.js +240 -0
  291. package/dist/merchant-core/ops/surface.js.map +1 -1
  292. package/dist/merchant-core/ownership/instance-ownership.d.ts +122 -0
  293. package/dist/merchant-core/ownership/instance-ownership.js +236 -0
  294. package/dist/merchant-core/ownership/instance-ownership.js.map +1 -0
  295. package/dist/merchant-core/ownership/runtime.d.ts +175 -0
  296. package/dist/merchant-core/ownership/runtime.js +422 -0
  297. package/dist/merchant-core/ownership/runtime.js.map +1 -0
  298. package/dist/merchant-core/storage/transaction.d.ts +102 -7
  299. package/dist/merchant-core/storage/transaction.js +274 -3
  300. package/dist/merchant-core/storage/transaction.js.map +1 -1
  301. package/dist/merchant-credential-rotation.d.ts +4 -1
  302. package/dist/merchant-credential-rotation.js +12 -8
  303. package/dist/merchant-credential-rotation.js.map +1 -1
  304. package/dist/merchant-runtime/manager.d.ts +2 -0
  305. package/dist/merchant-runtime/manager.js +5 -0
  306. package/dist/merchant-runtime/manager.js.map +1 -1
  307. package/package.json +1 -1
@@ -64,6 +64,10 @@ import { OperatingPlanError } from "../../merchant-core/operating/types.js";
64
64
  import { OpportunityError } from "../../merchant-core/opportunity/types.js";
65
65
  import { ProposalError } from "../../merchant-core/proposal/types.js";
66
66
  import { FollowUpError } from "../../merchant-core/followup/types.js";
67
+ import { GovernanceRuntimeError } from "../../merchant-core/ownership/runtime.js";
68
+ import { InstanceOwnershipError } from "../../merchant-core/ownership/instance-ownership.js";
69
+ import { LearningError } from "../../merchant-core/learning/types.js";
70
+ import { OperationsJobsError } from "../../merchant-core/operations-jobs/service.js";
67
71
  import { parseExactMoney, WorkbenchMoneyError, WORKBENCH_CURRENCY_TABLE_VERSION, } from "../../merchant/application/money.js";
68
72
  import { CONNECTION_PAIRING_SAFE_CODES } from "../../cloud/connect-service.js";
69
73
  import { EXACT_PRODUCT_TOOLS } from "../../merchant/exact-product-executors.js";
@@ -113,6 +117,32 @@ async function resolvePlatformRules(options) {
113
117
  return normalizeTradePlatformRules(undefined);
114
118
  }
115
119
  }
120
+ function deliveryField(body, key) {
121
+ const value = body[key];
122
+ if (typeof value !== "string" || value.trim() === "") {
123
+ throw new ManagementError("invalid_input", `${key} must be a non-empty string`);
124
+ }
125
+ return value;
126
+ }
127
+ function deliveryNumber(body, key) {
128
+ const value = body[key];
129
+ if (!Number.isSafeInteger(value)) {
130
+ throw new ManagementError("invalid_input", `${key} must be an integer`);
131
+ }
132
+ return value;
133
+ }
134
+ function deliveryCall(work) {
135
+ try {
136
+ return work();
137
+ }
138
+ catch (err) {
139
+ const code = err?.code;
140
+ if (typeof code === "string" && code !== "") {
141
+ throw new ManagementError("invalid_input", err instanceof Error ? err.message : code);
142
+ }
143
+ throw err;
144
+ }
145
+ }
116
146
  export function createMerchantManagementApiHandler(options) {
117
147
  const log = options.log ??
118
148
  ((line) => {
@@ -180,6 +210,11 @@ export function createMerchantManagementApiHandler(options) {
180
210
  writeJson(res, 404, errorBody("not_found", "unknown management api path"));
181
211
  return;
182
212
  }
213
+ if (pathname === `${API_PREFIX}/internal/customer-identity` && method === "POST") {
214
+ const result = await options.receiveCustomerIdentity?.(req.headers["x-kiwi-identity-channel-token"], () => readJsonBody(req));
215
+ writeJson(res, result?.status ?? 404, result?.body ?? { ok: false });
216
+ return;
217
+ }
183
218
  if (pathname === WORKBENCH_API_PREFIX || pathname.startsWith(`${WORKBENCH_API_PREFIX}/`)) {
184
219
  const requestId = `req_${randomBytes(12).toString("hex")}`;
185
220
  const rest = pathname === WORKBENCH_API_PREFIX ? "/" : pathname.slice(WORKBENCH_API_PREFIX.length);
@@ -229,7 +264,56 @@ export function createMerchantManagementApiHandler(options) {
229
264
  }
230
265
  // ── 只读路由(认证即鉴权入口;业务授权在服务层逐次复核)────────────────
231
266
  /** Workbench v1 读取面复用同一应用服务;未实现路由明确失败,不返回假数据。 */
267
+ function governanceRouteDisabled(rest) {
268
+ if (rest.startsWith("/learning/"))
269
+ return options.governance?.flags.learning_enabled !== true;
270
+ if (rest.startsWith("/automation/"))
271
+ return options.governance?.flags.jobs_enabled !== true;
272
+ return false;
273
+ }
274
+ function writeGoverned(work) {
275
+ if (options.governance === undefined) {
276
+ throw new ManagementError("conflict", "governance runtime is not initialized");
277
+ }
278
+ try {
279
+ return options.governance.write(work);
280
+ }
281
+ catch (error) {
282
+ if (error instanceof GovernanceRuntimeError || error instanceof InstanceOwnershipError) {
283
+ throw new ManagementError("conflict", "governance ownership is not held by this process");
284
+ }
285
+ throw error;
286
+ }
287
+ }
232
288
  async function routeWorkbenchV1Get(req, res, url, rest, requestId) {
289
+ if (governanceRouteDisabled(rest)) {
290
+ writeWorkbenchProblem(res, "RESOURCE_NOT_FOUND", requestId, "资源不存在", "Workbench API 路由不存在或尚未实现。");
291
+ return;
292
+ }
293
+ if (options.customerDeliveries !== undefined && rest === "/delivery/unknown") {
294
+ const auth = requireActor(req);
295
+ authorizeOrThrow(auth.ctx, "followups:read");
296
+ writeJson(res, 200, {
297
+ deliveries: options.customerDeliveries.listByStatus(auth.ctx.merchantId, "UNKNOWN"),
298
+ reconciliation_audit: options.customerDeliveries.listReconciliationAudit(auth.ctx.merchantId),
299
+ }, { "x-request-id": requestId });
300
+ return;
301
+ }
302
+ if (options.deliveryConsent !== undefined && rest.startsWith("/delivery/")) {
303
+ const auth = requireActor(req);
304
+ authorizeOrThrow(auth.ctx, "followups:read");
305
+ if (rest === "/delivery/bindings") {
306
+ writeJson(res, 200, { bindings: options.deliveryConsent.listBindings(auth.ctx.merchantId) }, { "x-request-id": requestId });
307
+ return;
308
+ }
309
+ if (rest === "/delivery/subscriptions") {
310
+ const bindingId = url.searchParams.get("binding_id") ?? undefined;
311
+ writeJson(res, 200, {
312
+ subscriptions: options.deliveryConsent.listSubscriptions(auth.ctx.merchantId, bindingId),
313
+ }, { "x-request-id": requestId });
314
+ return;
315
+ }
316
+ }
233
317
  if (rest === "/products/publication-status") {
234
318
  const auth = requireActor(req);
235
319
  authorizeOrThrow(auth.ctx, "products:import");
@@ -710,10 +794,180 @@ export function createMerchantManagementApiHandler(options) {
710
794
  writeJson(res, 200, { orders: ops.listOrders() }, { "x-request-id": requestId });
711
795
  return;
712
796
  }
797
+ if (rest === "/learning/corrections") {
798
+ const auth = requireActor(req);
799
+ authorizeOrThrow(auth.ctx, "learning:read");
800
+ writeJson(res, 200, { corrections: ops.listCorrections() }, { "x-request-id": requestId });
801
+ return;
802
+ }
803
+ const recoveryMatch = /^\/learning\/evaluations\/([^/]+)\/recovery$/.exec(rest);
804
+ if (recoveryMatch !== null) {
805
+ const auth = requireActor(req);
806
+ authorizeOrThrow(auth.ctx, "learning:review");
807
+ writeJson(res, 200, ops.getEvaluationRecovery(pathSegment(recoveryMatch[1] ?? ""), {
808
+ actor_id: auth.ctx.actorId, merchant_id: auth.ctx.merchantId, auth_method: auth.ctx.authMethod, permissions: [...auth.ctx.permissions],
809
+ }), { "x-request-id": requestId });
810
+ return;
811
+ }
812
+ const correctionMatch = /^\/learning\/corrections\/([^/]+)$/.exec(rest);
813
+ if (correctionMatch !== null) {
814
+ const auth = requireActor(req);
815
+ authorizeOrThrow(auth.ctx, "learning:read");
816
+ writeJson(res, 200, ops.getCorrection(pathSegment(correctionMatch[1] ?? "")), {
817
+ "x-request-id": requestId,
818
+ });
819
+ return;
820
+ }
821
+ if (rest === "/learning/candidates") {
822
+ const auth = requireActor(req);
823
+ authorizeOrThrow(auth.ctx, "learning:read");
824
+ writeJson(res, 200, { candidates: ops.listCandidates() }, { "x-request-id": requestId });
825
+ return;
826
+ }
827
+ const candidateMatch = /^\/learning\/candidates\/([^/]+)$/.exec(rest);
828
+ if (candidateMatch !== null) {
829
+ const auth = requireActor(req);
830
+ authorizeOrThrow(auth.ctx, "learning:read");
831
+ writeJson(res, 200, ops.getCandidate(pathSegment(candidateMatch[1] ?? "")), {
832
+ "x-request-id": requestId,
833
+ });
834
+ return;
835
+ }
836
+ if (rest === "/learning/reviews") {
837
+ const auth = requireActor(req);
838
+ authorizeOrThrow(auth.ctx, "learning:read");
839
+ writeJson(res, 200, { reviews: ops.listReviews() }, { "x-request-id": requestId });
840
+ return;
841
+ }
842
+ const reviewMatch = /^\/learning\/reviews\/([^/]+)$/.exec(rest);
843
+ if (reviewMatch !== null) {
844
+ const auth = requireActor(req);
845
+ authorizeOrThrow(auth.ctx, "learning:read");
846
+ writeJson(res, 200, ops.getReview(pathSegment(reviewMatch[1] ?? "")), {
847
+ "x-request-id": requestId,
848
+ });
849
+ return;
850
+ }
851
+ if (rest === "/learning/releases/active") {
852
+ const auth = requireActor(req);
853
+ authorizeOrThrow(auth.ctx, "learning:read");
854
+ const skillKey = url.searchParams.get("skill_key");
855
+ if (skillKey === null || skillKey.trim() === "") {
856
+ throw new ManagementError("invalid_input", "skill_key query parameter is required");
857
+ }
858
+ writeJson(res, 200, ops.getActiveRelease(skillKey));
859
+ return;
860
+ }
861
+ if (rest === "/learning/releases") {
862
+ const auth = requireActor(req);
863
+ authorizeOrThrow(auth.ctx, "learning:read");
864
+ const skillKey = url.searchParams.get("skill_key") ?? undefined;
865
+ writeJson(res, 200, { releases: ops.listReleases(skillKey) }, {
866
+ "x-request-id": requestId,
867
+ });
868
+ return;
869
+ }
870
+ const releaseMatch = /^\/learning\/releases\/([^/]+)$/.exec(rest);
871
+ if (releaseMatch !== null) {
872
+ const auth = requireActor(req);
873
+ authorizeOrThrow(auth.ctx, "learning:read");
874
+ writeJson(res, 200, ops.getRelease(pathSegment(releaseMatch[1] ?? "")), {
875
+ "x-request-id": requestId,
876
+ });
877
+ return;
878
+ }
879
+ if (rest === "/automation/rules") {
880
+ const auth = requireActor(req);
881
+ authorizeOrThrow(auth.ctx, "followups:read");
882
+ writeJson(res, 200, { rules: ops.listRules() }, { "x-request-id": requestId });
883
+ return;
884
+ }
885
+ const ruleMatch = /^\/automation\/rules\/([^/]+)$/.exec(rest);
886
+ if (ruleMatch !== null) {
887
+ const auth = requireActor(req);
888
+ authorizeOrThrow(auth.ctx, "followups:read");
889
+ writeJson(res, 200, ops.getRule(pathSegment(ruleMatch[1] ?? "")), {
890
+ "x-request-id": requestId,
891
+ });
892
+ return;
893
+ }
894
+ if (rest === "/automation/artifacts") {
895
+ const auth = requireActor(req);
896
+ authorizeOrThrow(auth.ctx, "followups:read");
897
+ const taskId = url.searchParams.get("task_id") ?? undefined;
898
+ writeJson(res, 200, { artifacts: ops.listArtifacts(taskId) }, {
899
+ "x-request-id": requestId,
900
+ });
901
+ return;
902
+ }
713
903
  }
714
904
  writeWorkbenchProblem(res, "RESOURCE_NOT_FOUND", requestId, "资源不存在", "Workbench API 路由不存在或尚未实现。");
715
905
  }
716
906
  async function routeWorkbenchV1Post(req, res, rest, requestId, url) {
907
+ if (governanceRouteDisabled(rest)) {
908
+ writeWorkbenchProblem(res, "RESOURCE_NOT_FOUND", requestId, "资源不存在", "Workbench API 路由不存在或尚未实现。");
909
+ return;
910
+ }
911
+ if (options.deliveryConsent !== undefined && rest.startsWith("/delivery/")) {
912
+ const auth = requireActor(req);
913
+ assertWriteGuards(req, auth.sessionId);
914
+ authorizeOrThrow(auth.ctx, "followups:manage");
915
+ const body = await readJsonBody(req);
916
+ const fields = objectFields(body, [
917
+ "channel",
918
+ "address_ref",
919
+ "proof_ref",
920
+ "expected_epoch",
921
+ "binding_id",
922
+ "purpose",
923
+ "max_per_day",
924
+ "expires_at",
925
+ "consent_evidence_ref",
926
+ "verified_not_executed",
927
+ "channel_idempotent",
928
+ ]);
929
+ const retryMatch = /^\/delivery\/unknown\/([^/]+)\/retry$/.exec(rest);
930
+ if (retryMatch !== null) {
931
+ if (options.customerDeliveries === undefined) {
932
+ writeWorkbenchProblem(res, "RESOURCE_NOT_FOUND", requestId, "资源不存在", "投递记录不可用。");
933
+ return;
934
+ }
935
+ // The deployed SMTP adapter cannot prove non-execution or deduplicate a retry.
936
+ // Keep UNKNOWN available for inspection until a trusted reconciliation adapter exists.
937
+ throw new ManagementError("precondition_changed", "渠道尚未提供可验证的未发送回执,结果未知的通知不能重发");
938
+ }
939
+ if (rest === "/delivery/bindings") {
940
+ writeJson(res, 201, deliveryCall(() => options.deliveryConsent.createBinding({
941
+ merchant_id: auth.ctx.merchantId,
942
+ channel: deliveryField(fields, "channel"),
943
+ address_ref: deliveryField(fields, "address_ref"),
944
+ proof_ref: deliveryField(fields, "proof_ref"),
945
+ })), { "x-request-id": requestId });
946
+ return;
947
+ }
948
+ const revokeBindingMatch = /^\/delivery\/bindings\/([^/]+)\/revoke$/.exec(rest);
949
+ if (revokeBindingMatch !== null) {
950
+ writeJson(res, 200, deliveryCall(() => options.deliveryConsent.revokeBinding(auth.ctx.merchantId, pathSegment(revokeBindingMatch[1] ?? ""), deliveryNumber(fields, "expected_epoch"))), { "x-request-id": requestId });
951
+ return;
952
+ }
953
+ if (rest === "/delivery/subscriptions") {
954
+ const expiresAt = typeof fields["expires_at"] === "string" ? fields["expires_at"] : null;
955
+ writeJson(res, 201, deliveryCall(() => options.deliveryConsent.createSubscription({
956
+ merchant_id: auth.ctx.merchantId,
957
+ binding_id: deliveryField(fields, "binding_id"),
958
+ purpose: deliveryField(fields, "purpose"),
959
+ max_per_day: deliveryNumber(fields, "max_per_day"),
960
+ expires_at: expiresAt,
961
+ consent_evidence_ref: deliveryField(fields, "consent_evidence_ref"),
962
+ })), { "x-request-id": requestId });
963
+ return;
964
+ }
965
+ const unsubscribeMatch = /^\/delivery\/subscriptions\/([^/]+)\/unsubscribe$/.exec(rest);
966
+ if (unsubscribeMatch !== null) {
967
+ writeJson(res, 200, deliveryCall(() => options.deliveryConsent.unsubscribe(auth.ctx.merchantId, pathSegment(unsubscribeMatch[1] ?? ""), deliveryNumber(fields, "expected_epoch"))), { "x-request-id": requestId });
968
+ return;
969
+ }
970
+ }
717
971
  if (options.merchantOperations !== undefined) {
718
972
  const ops = options.merchantOperations;
719
973
  const readOpsBody = async () => {
@@ -859,6 +1113,163 @@ export function createMerchantManagementApiHandler(options) {
859
1113
  writeJson(res, 200, ops.assessOrderContribution(pathSegment(orderContributionMatch[1] ?? ""), body), { "x-request-id": requestId });
860
1114
  return;
861
1115
  }
1116
+ if (rest === "/learning/corrections") {
1117
+ const auth = requireActor(req);
1118
+ assertWriteGuards(req, auth.sessionId);
1119
+ authorizeOrThrow(auth.ctx, "learning:manage");
1120
+ const { body, idempotencyKey } = await readOpsBody();
1121
+ writeJson(res, 201, writeGoverned(() => ops.submitCorrection(body, {
1122
+ actor_id: auth.ctx.actorId,
1123
+ merchant_id: auth.ctx.merchantId,
1124
+ auth_method: auth.ctx.authMethod,
1125
+ permissions: [...auth.ctx.permissions],
1126
+ }, idempotencyKey)), { "x-request-id": requestId });
1127
+ return;
1128
+ }
1129
+ const recoveryMatch = /^\/learning\/evaluations\/([^/]+)\/recovery$/.exec(rest);
1130
+ if (recoveryMatch !== null) {
1131
+ const auth = requireActor(req);
1132
+ assertWriteGuards(req, auth.sessionId);
1133
+ authorizeOrThrow(auth.ctx, "learning:review");
1134
+ const { body } = await readOpsBody();
1135
+ let result;
1136
+ try {
1137
+ result = await ops.resolveEvaluationRecovery(pathSegment(recoveryMatch[1] ?? ""), body, {
1138
+ actor_id: auth.ctx.actorId, merchant_id: auth.ctx.merchantId, auth_method: auth.ctx.authMethod, permissions: [...auth.ctx.permissions],
1139
+ });
1140
+ }
1141
+ catch (error) {
1142
+ if (error instanceof GovernanceRuntimeError || error instanceof InstanceOwnershipError) {
1143
+ throw new ManagementError("conflict", "governance ownership is not held by this process");
1144
+ }
1145
+ throw error;
1146
+ }
1147
+ writeJson(res, 200, result, { "x-request-id": requestId });
1148
+ return;
1149
+ }
1150
+ const promoteCorrectionMatch = /^\/learning\/corrections\/([^/]+)\/promote$/.exec(rest);
1151
+ if (promoteCorrectionMatch !== null) {
1152
+ const auth = requireActor(req);
1153
+ assertWriteGuards(req, auth.sessionId);
1154
+ authorizeOrThrow(auth.ctx, "learning:manage");
1155
+ const { body, idempotencyKey } = await readOpsBody();
1156
+ writeJson(res, 200, writeGoverned(() => ops.promoteCorrection(pathSegment(promoteCorrectionMatch[1] ?? ""), body, {
1157
+ actor_id: auth.ctx.actorId,
1158
+ merchant_id: auth.ctx.merchantId,
1159
+ auth_method: auth.ctx.authMethod,
1160
+ permissions: [...auth.ctx.permissions],
1161
+ }, idempotencyKey)), { "x-request-id": requestId });
1162
+ return;
1163
+ }
1164
+ if (rest === "/learning/candidates") {
1165
+ const auth = requireActor(req);
1166
+ assertWriteGuards(req, auth.sessionId);
1167
+ authorizeOrThrow(auth.ctx, "learning:manage");
1168
+ const { body, idempotencyKey } = await readOpsBody();
1169
+ writeJson(res, 201, writeGoverned(() => ops.proposeCandidate(body, {
1170
+ actor_id: auth.ctx.actorId,
1171
+ merchant_id: auth.ctx.merchantId,
1172
+ auth_method: auth.ctx.authMethod,
1173
+ permissions: [...auth.ctx.permissions],
1174
+ }, idempotencyKey)), { "x-request-id": requestId });
1175
+ return;
1176
+ }
1177
+ const reviseCandidateMatch = /^\/learning\/candidates\/([^/]+)\/revise$/.exec(rest);
1178
+ if (reviseCandidateMatch !== null) {
1179
+ const auth = requireActor(req);
1180
+ assertWriteGuards(req, auth.sessionId);
1181
+ authorizeOrThrow(auth.ctx, "learning:manage");
1182
+ const { body, idempotencyKey } = await readOpsBody();
1183
+ writeJson(res, 200, writeGoverned(() => ops.reviseCandidate(pathSegment(reviseCandidateMatch[1] ?? ""), body, {
1184
+ actor_id: auth.ctx.actorId,
1185
+ merchant_id: auth.ctx.merchantId,
1186
+ auth_method: auth.ctx.authMethod,
1187
+ permissions: [...auth.ctx.permissions],
1188
+ }, idempotencyKey)), { "x-request-id": requestId });
1189
+ return;
1190
+ }
1191
+ const reviewCandidateMatch = /^\/learning\/candidates\/([^/]+)\/review$/.exec(rest);
1192
+ if (reviewCandidateMatch !== null) {
1193
+ const auth = requireActor(req);
1194
+ assertWriteGuards(req, auth.sessionId);
1195
+ authorizeOrThrow(auth.ctx, "learning:review");
1196
+ const { body, idempotencyKey } = await readOpsBody();
1197
+ writeJson(res, 200, writeGoverned(() => ops.reviewCandidate(pathSegment(reviewCandidateMatch[1] ?? ""), body, {
1198
+ actor_id: auth.ctx.actorId,
1199
+ merchant_id: auth.ctx.merchantId,
1200
+ auth_method: auth.ctx.authMethod,
1201
+ permissions: [...auth.ctx.permissions],
1202
+ }, idempotencyKey)), { "x-request-id": requestId });
1203
+ return;
1204
+ }
1205
+ if (rest === "/learning/releases/publish") {
1206
+ const auth = requireActor(req);
1207
+ assertWriteGuards(req, auth.sessionId);
1208
+ authorizeOrThrow(auth.ctx, "learning:publish");
1209
+ const { body, idempotencyKey } = await readOpsBody();
1210
+ writeJson(res, 201, writeGoverned(() => ops.publishRelease(body, {
1211
+ actor_id: auth.ctx.actorId,
1212
+ merchant_id: auth.ctx.merchantId,
1213
+ auth_method: auth.ctx.authMethod,
1214
+ permissions: [...auth.ctx.permissions],
1215
+ }, idempotencyKey)), { "x-request-id": requestId });
1216
+ return;
1217
+ }
1218
+ const rollbackReleaseMatch = /^\/learning\/releases\/([^/]+)\/rollback$/.exec(rest);
1219
+ if (rollbackReleaseMatch !== null) {
1220
+ const auth = requireActor(req);
1221
+ assertWriteGuards(req, auth.sessionId);
1222
+ authorizeOrThrow(auth.ctx, "learning:publish");
1223
+ const { body, idempotencyKey } = await readOpsBody();
1224
+ writeJson(res, 200, writeGoverned(() => ops.rollbackRelease(pathSegment(rollbackReleaseMatch[1] ?? ""), body, {
1225
+ actor_id: auth.ctx.actorId,
1226
+ merchant_id: auth.ctx.merchantId,
1227
+ auth_method: auth.ctx.authMethod,
1228
+ permissions: [...auth.ctx.permissions],
1229
+ }, idempotencyKey)), { "x-request-id": requestId });
1230
+ return;
1231
+ }
1232
+ const revokeReleaseMatch = /^\/learning\/releases\/([^/]+)\/revoke$/.exec(rest);
1233
+ if (revokeReleaseMatch !== null) {
1234
+ const auth = requireActor(req);
1235
+ assertWriteGuards(req, auth.sessionId);
1236
+ authorizeOrThrow(auth.ctx, "learning:publish");
1237
+ const { body, idempotencyKey } = await readOpsBody();
1238
+ writeJson(res, 200, writeGoverned(() => ops.revokeRelease(pathSegment(revokeReleaseMatch[1] ?? ""), body, {
1239
+ actor_id: auth.ctx.actorId,
1240
+ merchant_id: auth.ctx.merchantId,
1241
+ auth_method: auth.ctx.authMethod,
1242
+ permissions: [...auth.ctx.permissions],
1243
+ }, idempotencyKey)), { "x-request-id": requestId });
1244
+ return;
1245
+ }
1246
+ if (rest === "/automation/rules/prepare") {
1247
+ const auth = requireActor(req);
1248
+ assertWriteGuards(req, auth.sessionId);
1249
+ authorizeOrThrow(auth.ctx, "followups:manage");
1250
+ const { body } = await readOpsBody();
1251
+ writeJson(res, 201, writeGoverned(() => ops.prepareRule(body)), { "x-request-id": requestId });
1252
+ return;
1253
+ }
1254
+ if (rest === "/automation/rules/activate") {
1255
+ const auth = requireActor(req);
1256
+ assertWriteGuards(req, auth.sessionId);
1257
+ authorizeOrThrow(auth.ctx, "followups:manage");
1258
+ const { body } = await readOpsBody();
1259
+ writeJson(res, 201, writeGoverned(() => ops.activateRule(body)), { "x-request-id": requestId });
1260
+ return;
1261
+ }
1262
+ const pauseRuleMatch = /^\/automation\/rules\/([^/]+)\/pause$/.exec(rest);
1263
+ if (pauseRuleMatch !== null) {
1264
+ const auth = requireActor(req);
1265
+ assertWriteGuards(req, auth.sessionId);
1266
+ authorizeOrThrow(auth.ctx, "followups:manage");
1267
+ const { body } = await readOpsBody();
1268
+ writeJson(res, 200, writeGoverned(() => ops.pauseRule(pathSegment(pauseRuleMatch[1] ?? ""), body)), {
1269
+ "x-request-id": requestId,
1270
+ });
1271
+ return;
1272
+ }
862
1273
  }
863
1274
  const publicationCommitMatch = /^\/products\/publication-drafts\/(flp_[a-z0-9]+_[0-9a-f]{12})\/commit$/.exec(rest);
864
1275
  if (rest === "/products/publication-drafts" || publicationCommitMatch !== null) {
@@ -3085,6 +3496,11 @@ export function createMerchantManagementApiHandler(options) {
3085
3496
  try {
3086
3497
  // 落盘前再刷一次运营规则:运营新增平台后无需重启实例即可提交。
3087
3498
  await options.marketplacePlatforms?.();
3499
+ if (importChannel.currentTable().digest !== (draft.base_digest ?? "")) {
3500
+ operations.release(begun.operationId);
3501
+ respondError(res, new ManagementError("precondition_changed", "product table changed since draft creation"));
3502
+ return;
3503
+ }
3088
3504
  const written = importChannel.commit(table);
3089
3505
  const marked = options.drafts.markCommitted(auth.ctx.merchantId, draftId);
3090
3506
  if (!marked) {
@@ -3775,6 +4191,33 @@ function respondWorkbenchError(res, error, requestId) {
3775
4191
  writeWorkbenchProblem(res, code, requestId, "经营请求未完成", error instanceof Error ? error.message : "经营请求未完成");
3776
4192
  return;
3777
4193
  }
4194
+ if (error instanceof OperationsJobsError) {
4195
+ const mapping = {
4196
+ validation: "VALIDATION_ERROR",
4197
+ not_found: "RESOURCE_NOT_FOUND",
4198
+ conflict: "VERSION_CONFLICT",
4199
+ version_conflict: "VERSION_CONFLICT",
4200
+ invalid_transition: "VERSION_CONFLICT",
4201
+ budget_exhausted: "RATE_LIMITED",
4202
+ idempotency_conflict: "IDEMPOTENCY_KEY_REUSED",
4203
+ };
4204
+ writeWorkbenchProblem(res, mapping[error.code], requestId, "经营任务请求未完成", error.message);
4205
+ return;
4206
+ }
4207
+ if (error instanceof LearningError) {
4208
+ const mapping = {
4209
+ validation: "VALIDATION_ERROR",
4210
+ sensitive_content: "VALIDATION_ERROR",
4211
+ unsupported_capability: "VALIDATION_ERROR",
4212
+ access_denied: "PERMISSION_REVOKED",
4213
+ not_found: "RESOURCE_NOT_FOUND",
4214
+ version_conflict: "VERSION_CONFLICT",
4215
+ idempotency_conflict: "IDEMPOTENCY_KEY_REUSED",
4216
+ schema_unavailable: "DEPENDENCY_UNAVAILABLE",
4217
+ };
4218
+ writeWorkbenchProblem(res, mapping[error.code], requestId, "学习请求未完成", error.message);
4219
+ return;
4220
+ }
3778
4221
  if (error instanceof WorkbenchEventProjectionError) {
3779
4222
  writeWorkbenchProblem(res, "VALIDATION_ERROR", requestId, "事件游标无效", error.message);
3780
4223
  return;