@harrylabsj/kiwi 0.6.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 (636) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +150 -0
  3. package/contracts/candidate-agent-dto-1.0.README.md +39 -0
  4. package/contracts/candidate-agent-dto-1.0.schema.json +172 -0
  5. package/contracts/interop/kiwi-buyer-message-send.json +43 -0
  6. package/contracts/interop/knp-data-part-examples.json +243 -0
  7. package/contracts/kiwi-catalog/1.0/agent-record.schema.json +78 -0
  8. package/contracts/kiwi-catalog/1.0/listing-record.schema.json +88 -0
  9. package/contracts/kiwi-catalog/1.0/listing-search-result.schema.json +60 -0
  10. package/contracts/negotiation/1.0/schema.json +501 -0
  11. package/contracts/shopping.negotiation/0.1/capabilities.schema.json +47 -0
  12. package/contracts/shopping.negotiation/0.1/decision.schema.json +120 -0
  13. package/contracts/shopping.negotiation/0.1/policy-result.schema.json +52 -0
  14. package/contracts/shopping.negotiation/0.1/snapshot.schema.json +172 -0
  15. package/dist/a2a/client/client.d.ts +33 -0
  16. package/dist/a2a/client/client.js +161 -0
  17. package/dist/a2a/client/client.js.map +1 -0
  18. package/dist/a2a/client/error.d.ts +35 -0
  19. package/dist/a2a/client/error.js +34 -0
  20. package/dist/a2a/client/error.js.map +1 -0
  21. package/dist/a2a/client/index.d.ts +29 -0
  22. package/dist/a2a/client/index.js +26 -0
  23. package/dist/a2a/client/index.js.map +1 -0
  24. package/dist/a2a/client/jsonrpc.d.ts +49 -0
  25. package/dist/a2a/client/jsonrpc.js +85 -0
  26. package/dist/a2a/client/jsonrpc.js.map +1 -0
  27. package/dist/a2a/client/parse.d.ts +18 -0
  28. package/dist/a2a/client/parse.js +134 -0
  29. package/dist/a2a/client/parse.js.map +1 -0
  30. package/dist/a2a/client/types.d.ts +102 -0
  31. package/dist/a2a/client/types.js +26 -0
  32. package/dist/a2a/client/types.js.map +1 -0
  33. package/dist/a2a/client/url-policy.d.ts +44 -0
  34. package/dist/a2a/client/url-policy.js +242 -0
  35. package/dist/a2a/client/url-policy.js.map +1 -0
  36. package/dist/a2a/negotiate.d.ts +68 -0
  37. package/dist/a2a/negotiate.js +288 -0
  38. package/dist/a2a/negotiate.js.map +1 -0
  39. package/dist/a2a/node.d.ts +37 -0
  40. package/dist/a2a/node.js +155 -0
  41. package/dist/a2a/node.js.map +1 -0
  42. package/dist/a2a/server/auth.d.ts +38 -0
  43. package/dist/a2a/server/auth.js +112 -0
  44. package/dist/a2a/server/auth.js.map +1 -0
  45. package/dist/a2a/server/card.d.ts +19 -0
  46. package/dist/a2a/server/card.js +81 -0
  47. package/dist/a2a/server/card.js.map +1 -0
  48. package/dist/a2a/server/errors.d.ts +109 -0
  49. package/dist/a2a/server/errors.js +178 -0
  50. package/dist/a2a/server/errors.js.map +1 -0
  51. package/dist/a2a/server/handler.d.ts +22 -0
  52. package/dist/a2a/server/handler.js +57 -0
  53. package/dist/a2a/server/handler.js.map +1 -0
  54. package/dist/a2a/server/inbound-message.d.ts +37 -0
  55. package/dist/a2a/server/inbound-message.js +104 -0
  56. package/dist/a2a/server/inbound-message.js.map +1 -0
  57. package/dist/a2a/server/index.d.ts +43 -0
  58. package/dist/a2a/server/index.js +42 -0
  59. package/dist/a2a/server/index.js.map +1 -0
  60. package/dist/a2a/server/merchant-handler.d.ts +69 -0
  61. package/dist/a2a/server/merchant-handler.js +316 -0
  62. package/dist/a2a/server/merchant-handler.js.map +1 -0
  63. package/dist/a2a/server/pipeline.d.ts +69 -0
  64. package/dist/a2a/server/pipeline.js +329 -0
  65. package/dist/a2a/server/pipeline.js.map +1 -0
  66. package/dist/a2a/server/server.d.ts +64 -0
  67. package/dist/a2a/server/server.js +420 -0
  68. package/dist/a2a/server/server.js.map +1 -0
  69. package/dist/a2a/server/task-registry.d.ts +31 -0
  70. package/dist/a2a/server/task-registry.js +67 -0
  71. package/dist/a2a/server/task-registry.js.map +1 -0
  72. package/dist/a2a/server/throttle.d.ts +154 -0
  73. package/dist/a2a/server/throttle.js +289 -0
  74. package/dist/a2a/server/throttle.js.map +1 -0
  75. package/dist/a2a/server/types.d.ts +191 -0
  76. package/dist/a2a/server/types.js +17 -0
  77. package/dist/a2a/server/types.js.map +1 -0
  78. package/dist/a2a/server/ucp.d.ts +49 -0
  79. package/dist/a2a/server/ucp.js +85 -0
  80. package/dist/a2a/server/ucp.js.map +1 -0
  81. package/dist/a2a/task/index.d.ts +24 -0
  82. package/dist/a2a/task/index.js +22 -0
  83. package/dist/a2a/task/index.js.map +1 -0
  84. package/dist/a2a/task/ledger.d.ts +48 -0
  85. package/dist/a2a/task/ledger.js +65 -0
  86. package/dist/a2a/task/ledger.js.map +1 -0
  87. package/dist/a2a/task/poller.d.ts +93 -0
  88. package/dist/a2a/task/poller.js +184 -0
  89. package/dist/a2a/task/poller.js.map +1 -0
  90. package/dist/a2a/task/state.d.ts +72 -0
  91. package/dist/a2a/task/state.js +119 -0
  92. package/dist/a2a/task/state.js.map +1 -0
  93. package/dist/a2a/ucp-agent.d.ts +49 -0
  94. package/dist/a2a/ucp-agent.js +78 -0
  95. package/dist/a2a/ucp-agent.js.map +1 -0
  96. package/dist/agent/agent-db.d.ts +31 -0
  97. package/dist/agent/agent-db.js +91 -0
  98. package/dist/agent/agent-db.js.map +1 -0
  99. package/dist/agent/buyer/buyer-tools.d.ts +70 -0
  100. package/dist/agent/buyer/buyer-tools.js +1353 -0
  101. package/dist/agent/buyer/buyer-tools.js.map +1 -0
  102. package/dist/agent/buyer/ranker.d.ts +53 -0
  103. package/dist/agent/buyer/ranker.js +153 -0
  104. package/dist/agent/buyer/ranker.js.map +1 -0
  105. package/dist/agent/buyer/scheduler.d.ts +58 -0
  106. package/dist/agent/buyer/scheduler.js +317 -0
  107. package/dist/agent/buyer/scheduler.js.map +1 -0
  108. package/dist/agent/buyer/search-loop.d.ts +42 -0
  109. package/dist/agent/buyer/search-loop.js +280 -0
  110. package/dist/agent/buyer/search-loop.js.map +1 -0
  111. package/dist/agent/buyer/task-store.d.ts +178 -0
  112. package/dist/agent/buyer/task-store.js +637 -0
  113. package/dist/agent/buyer/task-store.js.map +1 -0
  114. package/dist/agent/buyer/types.d.ts +222 -0
  115. package/dist/agent/buyer/types.js +124 -0
  116. package/dist/agent/buyer/types.js.map +1 -0
  117. package/dist/agent/chat-tools.d.ts +41 -0
  118. package/dist/agent/chat-tools.js +193 -0
  119. package/dist/agent/chat-tools.js.map +1 -0
  120. package/dist/agent/chat-tui.d.ts +49 -0
  121. package/dist/agent/chat-tui.js +314 -0
  122. package/dist/agent/chat-tui.js.map +1 -0
  123. package/dist/agent/connector/fake-connector.d.ts +50 -0
  124. package/dist/agent/connector/fake-connector.js +138 -0
  125. package/dist/agent/connector/fake-connector.js.map +1 -0
  126. package/dist/agent/connector/http-connector.d.ts +49 -0
  127. package/dist/agent/connector/http-connector.js +208 -0
  128. package/dist/agent/connector/http-connector.js.map +1 -0
  129. package/dist/agent/connector/types.d.ts +103 -0
  130. package/dist/agent/connector/types.js +97 -0
  131. package/dist/agent/connector/types.js.map +1 -0
  132. package/dist/agent/fake-chat-model.d.ts +22 -0
  133. package/dist/agent/fake-chat-model.js +134 -0
  134. package/dist/agent/fake-chat-model.js.map +1 -0
  135. package/dist/agent/kernel.d.ts +258 -0
  136. package/dist/agent/kernel.js +1099 -0
  137. package/dist/agent/kernel.js.map +1 -0
  138. package/dist/agent/memory/schema.d.ts +32 -0
  139. package/dist/agent/memory/schema.js +291 -0
  140. package/dist/agent/memory/schema.js.map +1 -0
  141. package/dist/agent/memory/store.d.ts +193 -0
  142. package/dist/agent/memory/store.js +881 -0
  143. package/dist/agent/memory/store.js.map +1 -0
  144. package/dist/agent/memory/types.d.ts +139 -0
  145. package/dist/agent/memory/types.js +119 -0
  146. package/dist/agent/memory/types.js.map +1 -0
  147. package/dist/agent/memory/vault.d.ts +49 -0
  148. package/dist/agent/memory/vault.js +125 -0
  149. package/dist/agent/memory/vault.js.map +1 -0
  150. package/dist/agent/merchant/action-candidate.d.ts +106 -0
  151. package/dist/agent/merchant/action-candidate.js +241 -0
  152. package/dist/agent/merchant/action-candidate.js.map +1 -0
  153. package/dist/agent/merchant/credential-broker.d.ts +67 -0
  154. package/dist/agent/merchant/credential-broker.js +76 -0
  155. package/dist/agent/merchant/credential-broker.js.map +1 -0
  156. package/dist/agent/merchant/fake-merchant-client.d.ts +47 -0
  157. package/dist/agent/merchant/fake-merchant-client.js +143 -0
  158. package/dist/agent/merchant/fake-merchant-client.js.map +1 -0
  159. package/dist/agent/merchant/merchant-client.d.ts +49 -0
  160. package/dist/agent/merchant/merchant-client.js +186 -0
  161. package/dist/agent/merchant/merchant-client.js.map +1 -0
  162. package/dist/agent/merchant/merchant-tools.d.ts +74 -0
  163. package/dist/agent/merchant/merchant-tools.js +582 -0
  164. package/dist/agent/merchant/merchant-tools.js.map +1 -0
  165. package/dist/agent/merchant/types.d.ts +119 -0
  166. package/dist/agent/merchant/types.js +133 -0
  167. package/dist/agent/merchant/types.js.map +1 -0
  168. package/dist/agent/mode.d.ts +32 -0
  169. package/dist/agent/mode.js +34 -0
  170. package/dist/agent/mode.js.map +1 -0
  171. package/dist/agent/negotiation-chat.d.ts +81 -0
  172. package/dist/agent/negotiation-chat.js +330 -0
  173. package/dist/agent/negotiation-chat.js.map +1 -0
  174. package/dist/agent/session.d.ts +22 -0
  175. package/dist/agent/session.js +164 -0
  176. package/dist/agent/session.js.map +1 -0
  177. package/dist/agent/system-prompt.d.ts +26 -0
  178. package/dist/agent/system-prompt.js +77 -0
  179. package/dist/agent/system-prompt.js.map +1 -0
  180. package/dist/agent/write-gate.d.ts +98 -0
  181. package/dist/agent/write-gate.js +76 -0
  182. package/dist/agent/write-gate.js.map +1 -0
  183. package/dist/cli.d.ts +18 -0
  184. package/dist/cli.js +1139 -0
  185. package/dist/cli.js.map +1 -0
  186. package/dist/commerce/data-source.d.ts +88 -0
  187. package/dist/commerce/data-source.js +25 -0
  188. package/dist/commerce/data-source.js.map +1 -0
  189. package/dist/commerce/erp-source.d.ts +51 -0
  190. package/dist/commerce/erp-source.js +184 -0
  191. package/dist/commerce/erp-source.js.map +1 -0
  192. package/dist/commerce/fake-client.d.ts +167 -0
  193. package/dist/commerce/fake-client.js +549 -0
  194. package/dist/commerce/fake-client.js.map +1 -0
  195. package/dist/commerce/http-client.d.ts +73 -0
  196. package/dist/commerce/http-client.js +284 -0
  197. package/dist/commerce/http-client.js.map +1 -0
  198. package/dist/commerce/local-db-source.d.ts +50 -0
  199. package/dist/commerce/local-db-source.js +162 -0
  200. package/dist/commerce/local-db-source.js.map +1 -0
  201. package/dist/commerce/shopping-cli-source.d.ts +57 -0
  202. package/dist/commerce/shopping-cli-source.js +206 -0
  203. package/dist/commerce/shopping-cli-source.js.map +1 -0
  204. package/dist/commerce/types.d.ts +146 -0
  205. package/dist/commerce/types.js +31 -0
  206. package/dist/commerce/types.js.map +1 -0
  207. package/dist/config/profile.d.ts +122 -0
  208. package/dist/config/profile.js +386 -0
  209. package/dist/config/profile.js.map +1 -0
  210. package/dist/contracts/negotiation-schema.d.ts +28 -0
  211. package/dist/contracts/negotiation-schema.js +101 -0
  212. package/dist/contracts/negotiation-schema.js.map +1 -0
  213. package/dist/contracts/schemas.d.ts +31 -0
  214. package/dist/contracts/schemas.js +122 -0
  215. package/dist/contracts/schemas.js.map +1 -0
  216. package/dist/counterparty/a2a-direct/index.d.ts +41 -0
  217. package/dist/counterparty/a2a-direct/index.js +330 -0
  218. package/dist/counterparty/a2a-direct/index.js.map +1 -0
  219. package/dist/counterparty/channel.d.ts +200 -0
  220. package/dist/counterparty/channel.js +61 -0
  221. package/dist/counterparty/channel.js.map +1 -0
  222. package/dist/counterparty/index.d.ts +28 -0
  223. package/dist/counterparty/index.js +24 -0
  224. package/dist/counterparty/index.js.map +1 -0
  225. package/dist/counterparty/platform-api/index.d.ts +41 -0
  226. package/dist/counterparty/platform-api/index.js +65 -0
  227. package/dist/counterparty/platform-api/index.js.map +1 -0
  228. package/dist/counterparty/registry.d.ts +51 -0
  229. package/dist/counterparty/registry.js +71 -0
  230. package/dist/counterparty/registry.js.map +1 -0
  231. package/dist/counterparty/shopping-cli-hosted/index.d.ts +36 -0
  232. package/dist/counterparty/shopping-cli-hosted/index.js +337 -0
  233. package/dist/counterparty/shopping-cli-hosted/index.js.map +1 -0
  234. package/dist/discovery/agent-card/error.d.ts +28 -0
  235. package/dist/discovery/agent-card/error.js +31 -0
  236. package/dist/discovery/agent-card/error.js.map +1 -0
  237. package/dist/discovery/agent-card/extensions.d.ts +20 -0
  238. package/dist/discovery/agent-card/extensions.js +59 -0
  239. package/dist/discovery/agent-card/extensions.js.map +1 -0
  240. package/dist/discovery/agent-card/index.d.ts +29 -0
  241. package/dist/discovery/agent-card/index.js +38 -0
  242. package/dist/discovery/agent-card/index.js.map +1 -0
  243. package/dist/discovery/agent-card/secrets.d.ts +30 -0
  244. package/dist/discovery/agent-card/secrets.js +240 -0
  245. package/dist/discovery/agent-card/secrets.js.map +1 -0
  246. package/dist/discovery/agent-card/types.d.ts +110 -0
  247. package/dist/discovery/agent-card/types.js +37 -0
  248. package/dist/discovery/agent-card/types.js.map +1 -0
  249. package/dist/discovery/agent-card/validate.d.ts +31 -0
  250. package/dist/discovery/agent-card/validate.js +210 -0
  251. package/dist/discovery/agent-card/validate.js.map +1 -0
  252. package/dist/discovery/capability/error.d.ts +23 -0
  253. package/dist/discovery/capability/error.js +28 -0
  254. package/dist/discovery/capability/error.js.map +1 -0
  255. package/dist/discovery/capability/index.d.ts +21 -0
  256. package/dist/discovery/capability/index.js +21 -0
  257. package/dist/discovery/capability/index.js.map +1 -0
  258. package/dist/discovery/capability/intersect.d.ts +56 -0
  259. package/dist/discovery/capability/intersect.js +137 -0
  260. package/dist/discovery/capability/intersect.js.map +1 -0
  261. package/dist/discovery/catalog-source/errors.d.ts +32 -0
  262. package/dist/discovery/catalog-source/errors.js +41 -0
  263. package/dist/discovery/catalog-source/errors.js.map +1 -0
  264. package/dist/discovery/catalog-source/index.d.ts +30 -0
  265. package/dist/discovery/catalog-source/index.js +29 -0
  266. package/dist/discovery/catalog-source/index.js.map +1 -0
  267. package/dist/discovery/catalog-source/kiwi-record.d.ts +183 -0
  268. package/dist/discovery/catalog-source/kiwi-record.js +72 -0
  269. package/dist/discovery/catalog-source/kiwi-record.js.map +1 -0
  270. package/dist/discovery/catalog-source/kiwi-schema.d.ts +33 -0
  271. package/dist/discovery/catalog-source/kiwi-schema.js +106 -0
  272. package/dist/discovery/catalog-source/kiwi-schema.js.map +1 -0
  273. package/dist/discovery/catalog-source/kiwi-source.d.ts +38 -0
  274. package/dist/discovery/catalog-source/kiwi-source.js +318 -0
  275. package/dist/discovery/catalog-source/kiwi-source.js.map +1 -0
  276. package/dist/discovery/catalog-source/register.d.ts +48 -0
  277. package/dist/discovery/catalog-source/register.js +83 -0
  278. package/dist/discovery/catalog-source/register.js.map +1 -0
  279. package/dist/discovery/catalog-source/schema.d.ts +21 -0
  280. package/dist/discovery/catalog-source/schema.js +63 -0
  281. package/dist/discovery/catalog-source/schema.js.map +1 -0
  282. package/dist/discovery/catalog-source/source.d.ts +45 -0
  283. package/dist/discovery/catalog-source/source.js +197 -0
  284. package/dist/discovery/catalog-source/source.js.map +1 -0
  285. package/dist/discovery/catalog-source/types.d.ts +122 -0
  286. package/dist/discovery/catalog-source/types.js +30 -0
  287. package/dist/discovery/catalog-source/types.js.map +1 -0
  288. package/dist/discovery/index.d.ts +25 -0
  289. package/dist/discovery/index.js +25 -0
  290. package/dist/discovery/index.js.map +1 -0
  291. package/dist/discovery/resolve.d.ts +175 -0
  292. package/dist/discovery/resolve.js +367 -0
  293. package/dist/discovery/resolve.js.map +1 -0
  294. package/dist/discovery/ucp/error.d.ts +25 -0
  295. package/dist/discovery/ucp/error.js +27 -0
  296. package/dist/discovery/ucp/error.js.map +1 -0
  297. package/dist/discovery/ucp/index.d.ts +33 -0
  298. package/dist/discovery/ucp/index.js +28 -0
  299. package/dist/discovery/ucp/index.js.map +1 -0
  300. package/dist/discovery/ucp/intersect.d.ts +148 -0
  301. package/dist/discovery/ucp/intersect.js +312 -0
  302. package/dist/discovery/ucp/intersect.js.map +1 -0
  303. package/dist/discovery/ucp/resolver.d.ts +62 -0
  304. package/dist/discovery/ucp/resolver.js +214 -0
  305. package/dist/discovery/ucp/resolver.js.map +1 -0
  306. package/dist/discovery/ucp/types.d.ts +97 -0
  307. package/dist/discovery/ucp/types.js +103 -0
  308. package/dist/discovery/ucp/types.js.map +1 -0
  309. package/dist/discovery/ucp/validate.d.ts +38 -0
  310. package/dist/discovery/ucp/validate.js +232 -0
  311. package/dist/discovery/ucp/validate.js.map +1 -0
  312. package/dist/discovery/ucp/vendor.d.ts +60 -0
  313. package/dist/discovery/ucp/vendor.js +61 -0
  314. package/dist/discovery/ucp/vendor.js.map +1 -0
  315. package/dist/doctor.d.ts +26 -0
  316. package/dist/doctor.js +113 -0
  317. package/dist/doctor.js.map +1 -0
  318. package/dist/exit-codes.d.ts +26 -0
  319. package/dist/exit-codes.js +27 -0
  320. package/dist/exit-codes.js.map +1 -0
  321. package/dist/fanout/disclosure.d.ts +138 -0
  322. package/dist/fanout/disclosure.js +188 -0
  323. package/dist/fanout/disclosure.js.map +1 -0
  324. package/dist/fanout/index.d.ts +32 -0
  325. package/dist/fanout/index.js +30 -0
  326. package/dist/fanout/index.js.map +1 -0
  327. package/dist/fanout/orchestrator.d.ts +153 -0
  328. package/dist/fanout/orchestrator.js +439 -0
  329. package/dist/fanout/orchestrator.js.map +1 -0
  330. package/dist/fanout/policy.d.ts +128 -0
  331. package/dist/fanout/policy.js +130 -0
  332. package/dist/fanout/policy.js.map +1 -0
  333. package/dist/handoff/acp-commerce.d.ts +58 -0
  334. package/dist/handoff/acp-commerce.js +69 -0
  335. package/dist/handoff/acp-commerce.js.map +1 -0
  336. package/dist/handoff/authorization.d.ts +127 -0
  337. package/dist/handoff/authorization.js +107 -0
  338. package/dist/handoff/authorization.js.map +1 -0
  339. package/dist/handoff/candidate.d.ts +94 -0
  340. package/dist/handoff/candidate.js +172 -0
  341. package/dist/handoff/candidate.js.map +1 -0
  342. package/dist/handoff/channel.d.ts +88 -0
  343. package/dist/handoff/channel.js +189 -0
  344. package/dist/handoff/channel.js.map +1 -0
  345. package/dist/handoff/completion.d.ts +44 -0
  346. package/dist/handoff/completion.js +136 -0
  347. package/dist/handoff/completion.js.map +1 -0
  348. package/dist/handoff/delivery.d.ts +59 -0
  349. package/dist/handoff/delivery.js +185 -0
  350. package/dist/handoff/delivery.js.map +1 -0
  351. package/dist/handoff/destination.d.ts +39 -0
  352. package/dist/handoff/destination.js +99 -0
  353. package/dist/handoff/destination.js.map +1 -0
  354. package/dist/handoff/errors.d.ts +34 -0
  355. package/dist/handoff/errors.js +47 -0
  356. package/dist/handoff/errors.js.map +1 -0
  357. package/dist/handoff/idempotency.d.ts +51 -0
  358. package/dist/handoff/idempotency.js +168 -0
  359. package/dist/handoff/idempotency.js.map +1 -0
  360. package/dist/handoff/index.d.ts +46 -0
  361. package/dist/handoff/index.js +48 -0
  362. package/dist/handoff/index.js.map +1 -0
  363. package/dist/handoff/ledger.d.ts +94 -0
  364. package/dist/handoff/ledger.js +195 -0
  365. package/dist/handoff/ledger.js.map +1 -0
  366. package/dist/handoff/lifecycle.d.ts +29 -0
  367. package/dist/handoff/lifecycle.js +102 -0
  368. package/dist/handoff/lifecycle.js.map +1 -0
  369. package/dist/handoff/metrics.d.ts +56 -0
  370. package/dist/handoff/metrics.js +78 -0
  371. package/dist/handoff/metrics.js.map +1 -0
  372. package/dist/handoff/operator-approval.d.ts +143 -0
  373. package/dist/handoff/operator-approval.js +287 -0
  374. package/dist/handoff/operator-approval.js.map +1 -0
  375. package/dist/handoff/order-record.d.ts +104 -0
  376. package/dist/handoff/order-record.js +235 -0
  377. package/dist/handoff/order-record.js.map +1 -0
  378. package/dist/handoff/package.d.ts +102 -0
  379. package/dist/handoff/package.js +132 -0
  380. package/dist/handoff/package.js.map +1 -0
  381. package/dist/handoff/transaction.d.ts +96 -0
  382. package/dist/handoff/transaction.js +263 -0
  383. package/dist/handoff/transaction.js.map +1 -0
  384. package/dist/handoff/ucp-checkout/cart-channel.d.ts +111 -0
  385. package/dist/handoff/ucp-checkout/cart-channel.js +370 -0
  386. package/dist/handoff/ucp-checkout/cart-channel.js.map +1 -0
  387. package/dist/handoff/ucp-checkout/cart-parse.d.ts +22 -0
  388. package/dist/handoff/ucp-checkout/cart-parse.js +102 -0
  389. package/dist/handoff/ucp-checkout/cart-parse.js.map +1 -0
  390. package/dist/handoff/ucp-checkout/cart-types.d.ts +93 -0
  391. package/dist/handoff/ucp-checkout/cart-types.js +38 -0
  392. package/dist/handoff/ucp-checkout/cart-types.js.map +1 -0
  393. package/dist/handoff/ucp-checkout/channel.d.ts +159 -0
  394. package/dist/handoff/ucp-checkout/channel.js +636 -0
  395. package/dist/handoff/ucp-checkout/channel.js.map +1 -0
  396. package/dist/handoff/ucp-checkout/client.d.ts +88 -0
  397. package/dist/handoff/ucp-checkout/client.js +228 -0
  398. package/dist/handoff/ucp-checkout/client.js.map +1 -0
  399. package/dist/handoff/ucp-checkout/endpoint.d.ts +36 -0
  400. package/dist/handoff/ucp-checkout/endpoint.js +145 -0
  401. package/dist/handoff/ucp-checkout/endpoint.js.map +1 -0
  402. package/dist/handoff/ucp-checkout/index.d.ts +35 -0
  403. package/dist/handoff/ucp-checkout/index.js +36 -0
  404. package/dist/handoff/ucp-checkout/index.js.map +1 -0
  405. package/dist/handoff/ucp-checkout/parse.d.ts +71 -0
  406. package/dist/handoff/ucp-checkout/parse.js +349 -0
  407. package/dist/handoff/ucp-checkout/parse.js.map +1 -0
  408. package/dist/handoff/ucp-checkout/totals.d.ts +41 -0
  409. package/dist/handoff/ucp-checkout/totals.js +36 -0
  410. package/dist/handoff/ucp-checkout/totals.js.map +1 -0
  411. package/dist/handoff/ucp-checkout/types.d.ts +149 -0
  412. package/dist/handoff/ucp-checkout/types.js +58 -0
  413. package/dist/handoff/ucp-checkout/types.js.map +1 -0
  414. package/dist/handoff/url-safety.d.ts +44 -0
  415. package/dist/handoff/url-safety.js +121 -0
  416. package/dist/handoff/url-safety.js.map +1 -0
  417. package/dist/i18n.d.ts +24 -0
  418. package/dist/i18n.js +27 -0
  419. package/dist/i18n.js.map +1 -0
  420. package/dist/negotiation/action-candidate.d.ts +97 -0
  421. package/dist/negotiation/action-candidate.js +160 -0
  422. package/dist/negotiation/action-candidate.js.map +1 -0
  423. package/dist/negotiation/condition/evaluator.d.ts +36 -0
  424. package/dist/negotiation/condition/evaluator.js +123 -0
  425. package/dist/negotiation/condition/evaluator.js.map +1 -0
  426. package/dist/negotiation/context-map/index.d.ts +23 -0
  427. package/dist/negotiation/context-map/index.js +22 -0
  428. package/dist/negotiation/context-map/index.js.map +1 -0
  429. package/dist/negotiation/context-map/store.d.ts +51 -0
  430. package/dist/negotiation/context-map/store.js +186 -0
  431. package/dist/negotiation/context-map/store.js.map +1 -0
  432. package/dist/negotiation/context-map/types.d.ts +29 -0
  433. package/dist/negotiation/context-map/types.js +57 -0
  434. package/dist/negotiation/context-map/types.js.map +1 -0
  435. package/dist/negotiation/domain/common.d.ts +95 -0
  436. package/dist/negotiation/domain/common.js +216 -0
  437. package/dist/negotiation/domain/common.js.map +1 -0
  438. package/dist/negotiation/domain/envelope.d.ts +55 -0
  439. package/dist/negotiation/domain/envelope.js +110 -0
  440. package/dist/negotiation/domain/envelope.js.map +1 -0
  441. package/dist/negotiation/domain/identifiers.d.ts +65 -0
  442. package/dist/negotiation/domain/identifiers.js +130 -0
  443. package/dist/negotiation/domain/identifiers.js.map +1 -0
  444. package/dist/negotiation/domain/objects.d.ts +149 -0
  445. package/dist/negotiation/domain/objects.js +335 -0
  446. package/dist/negotiation/domain/objects.js.map +1 -0
  447. package/dist/negotiation/idempotency/index.d.ts +26 -0
  448. package/dist/negotiation/idempotency/index.js +25 -0
  449. package/dist/negotiation/idempotency/index.js.map +1 -0
  450. package/dist/negotiation/idempotency/store.d.ts +52 -0
  451. package/dist/negotiation/idempotency/store.js +189 -0
  452. package/dist/negotiation/idempotency/store.js.map +1 -0
  453. package/dist/negotiation/idempotency/types.d.ts +102 -0
  454. package/dist/negotiation/idempotency/types.js +47 -0
  455. package/dist/negotiation/idempotency/types.js.map +1 -0
  456. package/dist/negotiation/jcs.d.ts +21 -0
  457. package/dist/negotiation/jcs.js +114 -0
  458. package/dist/negotiation/jcs.js.map +1 -0
  459. package/dist/negotiation/ledger/event.d.ts +142 -0
  460. package/dist/negotiation/ledger/event.js +206 -0
  461. package/dist/negotiation/ledger/event.js.map +1 -0
  462. package/dist/negotiation/ledger/index.d.ts +26 -0
  463. package/dist/negotiation/ledger/index.js +25 -0
  464. package/dist/negotiation/ledger/index.js.map +1 -0
  465. package/dist/negotiation/ledger/store.d.ts +97 -0
  466. package/dist/negotiation/ledger/store.js +338 -0
  467. package/dist/negotiation/ledger/store.js.map +1 -0
  468. package/dist/negotiation/prompt.d.ts +34 -0
  469. package/dist/negotiation/prompt.js +113 -0
  470. package/dist/negotiation/prompt.js.map +1 -0
  471. package/dist/negotiation/recovery/index.d.ts +26 -0
  472. package/dist/negotiation/recovery/index.js +24 -0
  473. package/dist/negotiation/recovery/index.js.map +1 -0
  474. package/dist/negotiation/recovery/outbound.d.ts +49 -0
  475. package/dist/negotiation/recovery/outbound.js +34 -0
  476. package/dist/negotiation/recovery/outbound.js.map +1 -0
  477. package/dist/negotiation/recovery/recover.d.ts +59 -0
  478. package/dist/negotiation/recovery/recover.js +486 -0
  479. package/dist/negotiation/recovery/recover.js.map +1 -0
  480. package/dist/negotiation/recovery/types.d.ts +85 -0
  481. package/dist/negotiation/recovery/types.js +17 -0
  482. package/dist/negotiation/recovery/types.js.map +1 -0
  483. package/dist/negotiation/state/phase.d.ts +70 -0
  484. package/dist/negotiation/state/phase.js +200 -0
  485. package/dist/negotiation/state/phase.js.map +1 -0
  486. package/dist/negotiation/types.d.ts +139 -0
  487. package/dist/negotiation/types.js +24 -0
  488. package/dist/negotiation/types.js.map +1 -0
  489. package/dist/net/safe-http.d.ts +54 -0
  490. package/dist/net/safe-http.js +116 -0
  491. package/dist/net/safe-http.js.map +1 -0
  492. package/dist/operator/controller.d.ts +181 -0
  493. package/dist/operator/controller.js +784 -0
  494. package/dist/operator/controller.js.map +1 -0
  495. package/dist/operator/runner.d.ts +128 -0
  496. package/dist/operator/runner.js +248 -0
  497. package/dist/operator/runner.js.map +1 -0
  498. package/dist/operator/store.d.ts +39 -0
  499. package/dist/operator/store.js +169 -0
  500. package/dist/operator/store.js.map +1 -0
  501. package/dist/operator/strategy.d.ts +54 -0
  502. package/dist/operator/strategy.js +249 -0
  503. package/dist/operator/strategy.js.map +1 -0
  504. package/dist/operator/tui.d.ts +27 -0
  505. package/dist/operator/tui.js +395 -0
  506. package/dist/operator/tui.js.map +1 -0
  507. package/dist/operator/types.d.ts +224 -0
  508. package/dist/operator/types.js +17 -0
  509. package/dist/operator/types.js.map +1 -0
  510. package/dist/product-buyer.d.ts +74 -0
  511. package/dist/product-buyer.js +161 -0
  512. package/dist/product-buyer.js.map +1 -0
  513. package/dist/product-cli.d.ts +56 -0
  514. package/dist/product-cli.js +175 -0
  515. package/dist/product-cli.js.map +1 -0
  516. package/dist/product-compat.d.ts +50 -0
  517. package/dist/product-compat.js +63 -0
  518. package/dist/product-compat.js.map +1 -0
  519. package/dist/product-init.d.ts +73 -0
  520. package/dist/product-init.js +203 -0
  521. package/dist/product-init.js.map +1 -0
  522. package/dist/product-publish.d.ts +85 -0
  523. package/dist/product-publish.js +216 -0
  524. package/dist/product-publish.js.map +1 -0
  525. package/dist/protocol/legacy-shopping-negotiation/adapter.d.ts +42 -0
  526. package/dist/protocol/legacy-shopping-negotiation/adapter.js +561 -0
  527. package/dist/protocol/legacy-shopping-negotiation/adapter.js.map +1 -0
  528. package/dist/protocol/legacy-shopping-negotiation/mapping.d.ts +78 -0
  529. package/dist/protocol/legacy-shopping-negotiation/mapping.js +321 -0
  530. package/dist/protocol/legacy-shopping-negotiation/mapping.js.map +1 -0
  531. package/dist/protocol/legacy-shopping-negotiation/money.d.ts +49 -0
  532. package/dist/protocol/legacy-shopping-negotiation/money.js +70 -0
  533. package/dist/protocol/legacy-shopping-negotiation/money.js.map +1 -0
  534. package/dist/protocol/legacy-shopping-negotiation/types.d.ts +107 -0
  535. package/dist/protocol/legacy-shopping-negotiation/types.js +34 -0
  536. package/dist/protocol/legacy-shopping-negotiation/types.js.map +1 -0
  537. package/dist/runtime/buyer-policy.d.ts +58 -0
  538. package/dist/runtime/buyer-policy.js +89 -0
  539. package/dist/runtime/buyer-policy.js.map +1 -0
  540. package/dist/runtime/fake-model.d.ts +77 -0
  541. package/dist/runtime/fake-model.js +307 -0
  542. package/dist/runtime/fake-model.js.map +1 -0
  543. package/dist/runtime/foreground.d.ts +56 -0
  544. package/dist/runtime/foreground.js +97 -0
  545. package/dist/runtime/foreground.js.map +1 -0
  546. package/dist/runtime/heartbeat.d.ts +36 -0
  547. package/dist/runtime/heartbeat.js +49 -0
  548. package/dist/runtime/heartbeat.js.map +1 -0
  549. package/dist/runtime/merchant-turn.d.ts +35 -0
  550. package/dist/runtime/merchant-turn.js +20 -0
  551. package/dist/runtime/merchant-turn.js.map +1 -0
  552. package/dist/runtime/model.d.ts +40 -0
  553. package/dist/runtime/model.js +86 -0
  554. package/dist/runtime/model.js.map +1 -0
  555. package/dist/runtime/negotiation-turn.d.ts +101 -0
  556. package/dist/runtime/negotiation-turn.js +317 -0
  557. package/dist/runtime/negotiation-turn.js.map +1 -0
  558. package/dist/runtime/tools.d.ts +64 -0
  559. package/dist/runtime/tools.js +236 -0
  560. package/dist/runtime/tools.js.map +1 -0
  561. package/dist/supervisor/init.d.ts +31 -0
  562. package/dist/supervisor/init.js +222 -0
  563. package/dist/supervisor/init.js.map +1 -0
  564. package/dist/supervisor/logs.d.ts +28 -0
  565. package/dist/supervisor/logs.js +101 -0
  566. package/dist/supervisor/logs.js.map +1 -0
  567. package/dist/supervisor/manage.d.ts +72 -0
  568. package/dist/supervisor/manage.js +419 -0
  569. package/dist/supervisor/manage.js.map +1 -0
  570. package/dist/supervisor/manifest.d.ts +69 -0
  571. package/dist/supervisor/manifest.js +209 -0
  572. package/dist/supervisor/manifest.js.map +1 -0
  573. package/dist/supervisor/stack-config.d.ts +79 -0
  574. package/dist/supervisor/stack-config.js +262 -0
  575. package/dist/supervisor/stack-config.js.map +1 -0
  576. package/dist/supervisor/wrapper.d.ts +17 -0
  577. package/dist/supervisor/wrapper.js +138 -0
  578. package/dist/supervisor/wrapper.js.map +1 -0
  579. package/dist/trust/identity/auth-verifier.d.ts +96 -0
  580. package/dist/trust/identity/auth-verifier.js +166 -0
  581. package/dist/trust/identity/auth-verifier.js.map +1 -0
  582. package/dist/trust/identity/identity-binding.d.ts +63 -0
  583. package/dist/trust/identity/identity-binding.js +59 -0
  584. package/dist/trust/identity/identity-binding.js.map +1 -0
  585. package/dist/trust/identity/index.d.ts +38 -0
  586. package/dist/trust/identity/index.js +31 -0
  587. package/dist/trust/identity/index.js.map +1 -0
  588. package/dist/trust/identity/jws.d.ts +64 -0
  589. package/dist/trust/identity/jws.js +178 -0
  590. package/dist/trust/identity/jws.js.map +1 -0
  591. package/dist/trust/identity/keys.d.ts +71 -0
  592. package/dist/trust/identity/keys.js +118 -0
  593. package/dist/trust/identity/keys.js.map +1 -0
  594. package/dist/trust/identity/message-signature.d.ts +105 -0
  595. package/dist/trust/identity/message-signature.js +297 -0
  596. package/dist/trust/identity/message-signature.js.map +1 -0
  597. package/dist/trust/identity/nonce.d.ts +45 -0
  598. package/dist/trust/identity/nonce.js +50 -0
  599. package/dist/trust/identity/nonce.js.map +1 -0
  600. package/dist/trust/identity/signature-base.d.ts +84 -0
  601. package/dist/trust/identity/signature-base.js +261 -0
  602. package/dist/trust/identity/signature-base.js.map +1 -0
  603. package/dist/trust/identity/trust-policy.d.ts +92 -0
  604. package/dist/trust/identity/trust-policy.js +95 -0
  605. package/dist/trust/identity/trust-policy.js.map +1 -0
  606. package/dist/trust/index.d.ts +21 -0
  607. package/dist/trust/index.js +22 -0
  608. package/dist/trust/index.js.map +1 -0
  609. package/dist/trust/records/evaluator.d.ts +76 -0
  610. package/dist/trust/records/evaluator.js +122 -0
  611. package/dist/trust/records/evaluator.js.map +1 -0
  612. package/dist/trust/records/index.d.ts +28 -0
  613. package/dist/trust/records/index.js +26 -0
  614. package/dist/trust/records/index.js.map +1 -0
  615. package/dist/trust/records/store.d.ts +75 -0
  616. package/dist/trust/records/store.js +339 -0
  617. package/dist/trust/records/store.js.map +1 -0
  618. package/dist/trust/records/types.d.ts +159 -0
  619. package/dist/trust/records/types.js +40 -0
  620. package/dist/trust/records/types.js.map +1 -0
  621. package/dist/tui/banner.d.ts +46 -0
  622. package/dist/tui/banner.js +99 -0
  623. package/dist/tui/banner.js.map +1 -0
  624. package/dist/tui/styles.d.ts +70 -0
  625. package/dist/tui/styles.js +197 -0
  626. package/dist/tui/styles.js.map +1 -0
  627. package/dist/tui/theme.d.ts +63 -0
  628. package/dist/tui/theme.js +136 -0
  629. package/dist/tui/theme.js.map +1 -0
  630. package/examples/profiles/buyer.deepseek.yaml +34 -0
  631. package/examples/profiles/buyer.fake.yaml +36 -0
  632. package/examples/profiles/buyer.local.yaml +40 -0
  633. package/examples/profiles/merchant.deepseek.yaml +32 -0
  634. package/examples/profiles/merchant.fake.yaml +31 -0
  635. package/examples/profiles/merchant.local.yaml +34 -0
  636. package/package.json +55 -0
@@ -0,0 +1,241 @@
1
+ /**
2
+ * Copyright 2026 harrylabsj
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * Approval WriteApprovalCandidates (design §16).
18
+ *
19
+ * The operator approves a specific argument set against a specific
20
+ * precondition state — never a free-form "agree". A candidate carries:
21
+ * candidate_id, tool, arguments_hash, preconditions_hash, risk, expires_at.
22
+ *
23
+ * Execution re-reads the preconditions (product / inventory / conversation /
24
+ * task state) and re-hashes them. If the state changed since the candidate
25
+ * was created, the old approval is invalid: the candidate is superseded and
26
+ * must be regenerated. The store is a plain SQLite-backed persistence layer;
27
+ * the lifecycle routing (mode -> pending_approval / auto-execute) lives in
28
+ * the tool layer.
29
+ *
30
+ * Privacy invariant: arguments_json / preconditions_json hold only public
31
+ * catalog/inventory/task facts. Restricted values (private floors, costs)
32
+ * never enter this table, the event log or model-visible output.
33
+ */
34
+ import { createHash } from "node:crypto";
35
+ import { uuidv7 } from "@earendil-works/pi-ai";
36
+ export const WRITE_APPROVAL_CANDIDATE_STATUSES = [
37
+ "pending_approval",
38
+ "approved",
39
+ "executed",
40
+ "rejected",
41
+ "superseded",
42
+ "expired",
43
+ ];
44
+ export class WriteApprovalCandidateError extends Error {
45
+ code;
46
+ constructor(code, message) {
47
+ super(message);
48
+ this.name = "WriteApprovalCandidateError";
49
+ this.code = code;
50
+ }
51
+ }
52
+ /**
53
+ * Deterministic canonical serialization (sorted keys, no undefined) so equal
54
+ * argument sets always hash identically — content addressing across retries
55
+ * and restarts.
56
+ */
57
+ export function stableStringify(value) {
58
+ if (Array.isArray(value))
59
+ return `[${value.map(stableStringify).join(",")}]`;
60
+ if (value !== null && typeof value === "object") {
61
+ const entries = Object.entries(value)
62
+ .filter(([, v]) => v !== undefined)
63
+ .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
64
+ .map(([k, v]) => `${JSON.stringify(k)}:${stableStringify(v)}`);
65
+ return `{${entries.join(",")}}`;
66
+ }
67
+ return JSON.stringify(value) ?? "null";
68
+ }
69
+ /** sha256 content hash of a structured value, prefixed for audit clarity. */
70
+ export function contentHash(value) {
71
+ return `sha256:${createHash("sha256").update(stableStringify(value)).digest("hex")}`;
72
+ }
73
+ export class WriteApprovalCandidateStore {
74
+ db;
75
+ principalId;
76
+ now;
77
+ constructor(options) {
78
+ this.db = options.db;
79
+ this.principalId = options.principalId;
80
+ const clock = options.now ?? (() => new Date().toISOString());
81
+ this.now = () => new Date(Date.parse(clock())).toISOString();
82
+ }
83
+ create(input) {
84
+ const candidateId = `act_${uuidv7()}`;
85
+ const now = this.now();
86
+ this.db
87
+ .prepare(`INSERT INTO action_candidates
88
+ (candidate_id, principal_id, task_id, tool, arguments_json, arguments_hash,
89
+ preconditions_json, preconditions_hash, risk, status, expires_at, created_at, updated_at)
90
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, 'pending_approval', ?, ?, ?)`)
91
+ .run(candidateId, this.principalId, input.task_id ?? null, input.tool, JSON.stringify(input.arguments), contentHash(input.arguments), JSON.stringify(input.preconditions), contentHash(input.preconditions), input.risk, input.expires_at, now, now);
92
+ return this.get(candidateId);
93
+ }
94
+ get(candidateId) {
95
+ const row = this.db
96
+ .prepare("SELECT * FROM action_candidates WHERE candidate_id = ? AND principal_id = ?")
97
+ .get(candidateId, this.principalId);
98
+ return row === undefined ? undefined : this.rowToCandidate(row);
99
+ }
100
+ listPending() {
101
+ this.expireDue();
102
+ const rows = this.db
103
+ .prepare("SELECT * FROM action_candidates WHERE principal_id = ? AND status = 'pending_approval' ORDER BY created_at, candidate_id")
104
+ .all(this.principalId);
105
+ return rows.map((r) => this.rowToCandidate(r));
106
+ }
107
+ /** Expire pending/approved candidates past their deadline. Returns count. */
108
+ expireDue() {
109
+ const now = this.now();
110
+ const due = this.db
111
+ .prepare(`SELECT candidate_id FROM action_candidates
112
+ WHERE principal_id = ? AND status IN ('pending_approval','approved') AND expires_at < ?`)
113
+ .all(this.principalId, now);
114
+ for (const { candidate_id } of due) {
115
+ this.db
116
+ .prepare("UPDATE action_candidates SET status = 'expired', updated_at = ? WHERE candidate_id = ?")
117
+ .run(now, candidate_id);
118
+ }
119
+ return due.length;
120
+ }
121
+ setStatus(candidateId, status) {
122
+ const existing = this.get(candidateId);
123
+ if (existing === undefined)
124
+ throw new WriteApprovalCandidateError("not_found", `no candidate ${candidateId}`);
125
+ this.db
126
+ .prepare("UPDATE action_candidates SET status = ?, updated_at = ? WHERE candidate_id = ?")
127
+ .run(status, this.now(), candidateId);
128
+ return this.get(candidateId);
129
+ }
130
+ /** Record operator approval (idempotent on already-approved/executed). */
131
+ markApproved(candidateId) {
132
+ this.expireDue();
133
+ const existing = this.get(candidateId);
134
+ if (existing === undefined)
135
+ throw new WriteApprovalCandidateError("not_found", `no candidate ${candidateId}`);
136
+ if (existing.status === "executed" || existing.status === "approved")
137
+ return existing;
138
+ if (existing.status === "expired")
139
+ throw new WriteApprovalCandidateError("expired", `candidate ${candidateId} expired`);
140
+ if (existing.status !== "pending_approval") {
141
+ throw new WriteApprovalCandidateError("conflict", `candidate ${candidateId} is ${existing.status}, not approvable`);
142
+ }
143
+ return this.setStatus(candidateId, "approved");
144
+ }
145
+ markExecuted(candidateId) {
146
+ return this.setStatus(candidateId, "executed");
147
+ }
148
+ reject(candidateId) {
149
+ return this.setStatus(candidateId, "rejected");
150
+ }
151
+ supersede(candidateId) {
152
+ return this.setStatus(candidateId, "superseded");
153
+ }
154
+ rowToCandidate(row) {
155
+ const candidate = {
156
+ candidate_id: row.candidate_id,
157
+ principal_id: row.principal_id,
158
+ tool: row.tool,
159
+ arguments: JSON.parse(row.arguments_json),
160
+ arguments_hash: row.arguments_hash,
161
+ preconditions: JSON.parse(row.preconditions_json),
162
+ preconditions_hash: row.preconditions_hash,
163
+ risk: row.risk,
164
+ status: row.status,
165
+ expires_at: row.expires_at,
166
+ created_at: row.created_at,
167
+ updated_at: row.updated_at,
168
+ };
169
+ if (row.task_id !== null)
170
+ candidate.task_id = row.task_id;
171
+ return candidate;
172
+ }
173
+ }
174
+ /**
175
+ * Execute an approved candidate after re-validating its preconditions (§16):
176
+ * 1. The candidate must be `approved` and not past its deadline.
177
+ * 2. Preconditions are re-read from the current marketplace/task state and
178
+ * re-hashed. A different hash means the old approval no longer applies —
179
+ * the candidate is superseded and nothing is executed.
180
+ * 3. Only the STORED arguments (what the operator approved) are executed,
181
+ * never anything re-read from the model.
182
+ */
183
+ export async function executeApprovedCandidate(store, candidateId, hooks) {
184
+ const candidate = store.get(candidateId);
185
+ if (candidate === undefined) {
186
+ throw new WriteApprovalCandidateError("not_found", `no candidate ${candidateId}`);
187
+ }
188
+ if (candidate.status === "expired")
189
+ return { kind: "expired", candidate };
190
+ if (candidate.status !== "approved") {
191
+ return {
192
+ kind: "not_approvable",
193
+ candidate,
194
+ reason: `候选 ${candidateId} 状态为 ${candidate.status},不是 approved;不会执行。`,
195
+ };
196
+ }
197
+ const freshPreconditions = await hooks.readPreconditions();
198
+ const freshHash = contentHash(freshPreconditions);
199
+ if (freshHash !== candidate.preconditions_hash) {
200
+ store.supersede(candidateId);
201
+ return {
202
+ kind: "stale",
203
+ candidate: store.get(candidateId),
204
+ reason: "前置状态已变化(preconditions_hash 不匹配),旧批准失效;已标记 superseded,请重新生成候选。",
205
+ };
206
+ }
207
+ let output;
208
+ try {
209
+ output = await hooks.execute(candidate.arguments);
210
+ }
211
+ catch (err) {
212
+ // 执行体抛错(评审项 P3-4):网络中断等异常会让候选停留在 approved——
213
+ // 操作者可再次 /approve,而执行体(如 start_consultation:先在外网创建
214
+ // 会话、再本地落账)可能在首次执行已完成外部副作用后抛错——重试会重复
215
+ // 创建外部会话(幂等键依赖新的 conversation_id,不构成防护)。标
216
+ // superseded 防重复批准,返回 stale 让调用方提示重新生成候选。
217
+ store.supersede(candidateId);
218
+ return {
219
+ kind: "stale",
220
+ candidate: store.get(candidateId),
221
+ reason: `执行抛错(${err instanceof Error ? err.message : String(err)}),候选已失效,请重新生成候选。`,
222
+ };
223
+ }
224
+ // 执行失败(如 handoff 候选已 stale/expired,execute 返回 {ok:false} 而非
225
+ // 抛错)→ 审批候选不标 executed:审计状态不得与 Ledger 矛盾(此前无条件
226
+ // markExecuted,/approve 显示"已执行"但链上实际无交付)。标 superseded
227
+ // 防重复批准,返回 stale 让调用方提示重新生成候选。
228
+ if (output !== null &&
229
+ typeof output === "object" &&
230
+ output.ok === false) {
231
+ store.supersede(candidateId);
232
+ return {
233
+ kind: "stale",
234
+ candidate: store.get(candidateId),
235
+ reason: "执行失败(execute 返回非成功结果),候选已失效,请重新生成候选。",
236
+ };
237
+ }
238
+ const executed = store.markExecuted(candidateId);
239
+ return { kind: "executed", candidate: executed, output };
240
+ }
241
+ //# sourceMappingURL=action-candidate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action-candidate.js","sourceRoot":"","sources":["../../../src/agent/merchant/action-candidate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE/C,MAAM,CAAC,MAAM,iCAAiC,GAAG;IAC/C,kBAAkB;IAClB,UAAU;IACV,UAAU;IACV,UAAU;IACV,YAAY;IACZ,SAAS;CACD,CAAC;AAmBX,MAAM,OAAO,2BAA4B,SAAQ,KAAK;IAC3C,IAAI,CAAuC;IACpD,YAAY,IAAyC,EAAE,OAAe;QACpE,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAC;QAC1C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,KAAc;IAC5C,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,KAAK,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IAC7E,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK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AClE,CAAC;IACJ,CAAC;IACD,IAAI,MAAe,CAAC;IACpB,IAAI,CAAC;QACH,MAAM,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,4CAA4C;QAC5C,mDAAmD;QACnD,qCAAqC;QACrC,0CAA0C;QAC1C,0CAA0C;QAC1C,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;QAC7B,OAAO;YACL,IAAI,EAAE,OAAO;YACb,SAAS,EAAE,KAAK,CAAC,GAAG,CAAC,WAAW,CAA2B;YAC3D,MAAM,EAAE,QAAQ,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,kBAAkB;SACnF,CAAC;IACJ,CAAC;IACD,4DAA4D;IAC5D,+CAA+C;IAC/C,sDAAsD;IACtD,+BAA+B;IAC/B,IACE,MAAM,KAAK,IAAI;QACf,OAAO,MAAM,KAAK,QAAQ;QACzB,MAA2B,CAAC,EAAE,KAAK,KAAK,EACzC,CAAC;QACD,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;QAC7B,OAAO;YACL,IAAI,EAAE,OAAO;YACb,SAAS,EAAE,KAAK,CAAC,GAAG,CAAC,WAAW,CAA2B;YAC3D,MAAM,EAAE,sCAAsC;SAC/C,CAAC;IACJ,CAAC;IACD,MAAM,QAAQ,GAAG,KAAK,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;IACjD,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AAC3D,CAAC"}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Copyright 2026 harrylabsj
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * Credential Broker (design §15.4).
18
+ *
19
+ * Negotiation / catalog / inventory credentials are held separately by scope.
20
+ * The model only ever sees tools — never tokens. A write tool whose scope has
21
+ * no credential configured fails closed: it refuses to touch the marketplace
22
+ * rather than degrading to an unauthenticated or mis-scoped call.
23
+ *
24
+ * The negotiation scope is the profile's primary `commerce.token_env`;
25
+ * catalog and inventory scopes come from the optional
26
+ * `commerce.credentials.<scope>.token_env` refs. Tokens are resolved lazily at
27
+ * call time via process.env, exactly like the negotiation token — nothing is
28
+ * ever stored in the profile or in logs.
29
+ */
30
+ import type { CommerceCredentialScope } from "../../config/profile.js";
31
+ import type { AgentProfile } from "../../config/profile.js";
32
+ /** The broker never logs or exposes token values; only scopes are queryable. */
33
+ export interface CredentialBroker {
34
+ /** Token for a scope, or undefined when that scope is not configured. */
35
+ resolve(scope: CommerceCredentialScope): string | undefined;
36
+ /** Whether a token is configured for the scope (not whether it is valid). */
37
+ has(scope: CommerceCredentialScope): boolean;
38
+ }
39
+ /** Fail-closed helper shared by write tools: no credential -> refuse. */
40
+ export declare function requireScopeCredential(broker: CredentialBroker, scope: CommerceCredentialScope): {
41
+ ok: true;
42
+ token: string;
43
+ } | {
44
+ ok: false;
45
+ reason: string;
46
+ };
47
+ /** Env-backed broker derived from a profile's commerce credential refs. */
48
+ export declare class ProfileCredentialBroker implements CredentialBroker {
49
+ private readonly profile;
50
+ constructor(profile: AgentProfile);
51
+ resolve(scope: CommerceCredentialScope): string | undefined;
52
+ has(scope: CommerceCredentialScope): boolean;
53
+ }
54
+ /** Explicit-map broker for tests and embedded use (keys are env-var names). */
55
+ export declare class EnvRefCredentialBroker implements CredentialBroker {
56
+ private readonly refs;
57
+ constructor(refs: Partial<Record<CommerceCredentialScope, string>>);
58
+ resolve(scope: CommerceCredentialScope): string | undefined;
59
+ has(scope: CommerceCredentialScope): boolean;
60
+ }
61
+ /** Literal-value broker for deterministic tests (values never logged). */
62
+ export declare class StaticCredentialBroker implements CredentialBroker {
63
+ private readonly tokens;
64
+ constructor(tokens: Partial<Record<CommerceCredentialScope, string>>);
65
+ resolve(scope: CommerceCredentialScope): string | undefined;
66
+ has(scope: CommerceCredentialScope): boolean;
67
+ }
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Copyright 2026 harrylabsj
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /** Fail-closed helper shared by write tools: no credential -> refuse. */
17
+ export function requireScopeCredential(broker, scope) {
18
+ const token = broker.resolve(scope);
19
+ if (token === undefined || token === "") {
20
+ return {
21
+ ok: false,
22
+ reason: `没有 ${scope} 作用域的凭据(commerce.credentials.${scope}.token_env 未配置),` +
23
+ `该写操作已安全拒绝(fail closed)。`,
24
+ };
25
+ }
26
+ return { ok: true, token };
27
+ }
28
+ /** Resolve a token from an env-var reference, never logging the value. */
29
+ function resolveEnv(envName) {
30
+ if (envName === undefined)
31
+ return undefined;
32
+ const value = process.env[envName];
33
+ return value === undefined || value === "" ? undefined : value;
34
+ }
35
+ /** Env-backed broker derived from a profile's commerce credential refs. */
36
+ export class ProfileCredentialBroker {
37
+ profile;
38
+ constructor(profile) {
39
+ this.profile = profile;
40
+ }
41
+ resolve(scope) {
42
+ if (scope === "negotiation")
43
+ return resolveEnv(this.profile.commerce.token_env);
44
+ return resolveEnv(this.profile.commerce.credentials?.[scope]?.token_env);
45
+ }
46
+ has(scope) {
47
+ return this.resolve(scope) !== undefined;
48
+ }
49
+ }
50
+ /** Explicit-map broker for tests and embedded use (keys are env-var names). */
51
+ export class EnvRefCredentialBroker {
52
+ refs;
53
+ constructor(refs) {
54
+ this.refs = refs;
55
+ }
56
+ resolve(scope) {
57
+ return resolveEnv(this.refs[scope]);
58
+ }
59
+ has(scope) {
60
+ return this.resolve(scope) !== undefined;
61
+ }
62
+ }
63
+ /** Literal-value broker for deterministic tests (values never logged). */
64
+ export class StaticCredentialBroker {
65
+ tokens;
66
+ constructor(tokens) {
67
+ this.tokens = tokens;
68
+ }
69
+ resolve(scope) {
70
+ return this.tokens[scope];
71
+ }
72
+ has(scope) {
73
+ return this.tokens[scope] !== undefined && this.tokens[scope] !== "";
74
+ }
75
+ }
76
+ //# sourceMappingURL=credential-broker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credential-broker.js","sourceRoot":"","sources":["../../../src/agent/merchant/credential-broker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AA4BH,yEAAyE;AACzE,MAAM,UAAU,sBAAsB,CACpC,MAAwB,EACxB,KAA8B;IAE9B,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACpC,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,EAAE,EAAE,CAAC;QACxC,OAAO;YACL,EAAE,EAAE,KAAK;YACT,MAAM,EACJ,MAAM,KAAK,gCAAgC,KAAK,kBAAkB;gBAClE,yBAAyB;SAC5B,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AAC7B,CAAC;AAED,0EAA0E;AAC1E,SAAS,UAAU,CAAC,OAA2B;IAC7C,IAAI,OAAO,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC5C,MAAM,KAAK,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AAC;IAC5B,CAAC;IAED,GAAG,CAAC,KAA8B;QAChC,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,SAAS,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACvE,CAAC;CACF"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Copyright 2026 harrylabsj
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { HumanReviewItem, IncomingConsultation, InventorySnapshot, MerchantCatalogProduct, MerchantClient, MerchantProductInput, MerchantProductPatch } from "./types.js";
17
+ export declare class FakeMerchantClient implements MerchantClient {
18
+ private readonly products;
19
+ private readonly consultations;
20
+ private readonly reviews;
21
+ private now;
22
+ constructor(options?: {
23
+ products?: MerchantCatalogProduct[];
24
+ consultations?: IncomingConsultation[];
25
+ reviews?: HumanReviewItem[];
26
+ now?: string;
27
+ });
28
+ /** Test helper: advance the fake clock. */
29
+ advanceTime(ms: number): void;
30
+ /** Test helper: add or replace a catalog product. */
31
+ put(product: MerchantCatalogProduct): void;
32
+ /** Test helper: push an incoming consultation. */
33
+ addConsultation(c: IncomingConsultation): void;
34
+ listProducts(merchantId: string): Promise<MerchantCatalogProduct[]>;
35
+ getProduct(sku: string): Promise<MerchantCatalogProduct>;
36
+ createProduct(input: MerchantProductInput): Promise<MerchantCatalogProduct>;
37
+ updateProduct(sku: string, patch: MerchantProductPatch): Promise<MerchantCatalogProduct>;
38
+ getInventorySnapshot(sku: string): Promise<InventorySnapshot>;
39
+ /** Inventory-scope write, always against a fresh read of the product. */
40
+ updateInventory(sku: string, stock: number): Promise<MerchantCatalogProduct>;
41
+ listIncomingConsultations(merchantId: string): Promise<IncomingConsultation[]>;
42
+ getHumanReviewQueue(merchantId: string): Promise<HumanReviewItem[]>;
43
+ pauseListing(sku: string, paused: boolean): Promise<MerchantCatalogProduct>;
44
+ private requireProduct;
45
+ }
46
+ /** A merchant catalog fixture with shopping-cli field shapes. */
47
+ export declare function fakeMerchantProduct(overrides?: Partial<MerchantCatalogProduct>): MerchantCatalogProduct;
@@ -0,0 +1,143 @@
1
+ /**
2
+ * Copyright 2026 harrylabsj
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * Deterministic in-memory MerchantClient for tests and offline smoke runs.
18
+ * Mirrors the shopping-cli catalog/consultation semantics closely enough that
19
+ * merchant capability tools can be exercised end-to-end without a gateway:
20
+ * catalog CRUD, inventory snapshot, incoming consultations, human-review queue
21
+ * and the paused listing flag. Private merchant values (floor/cost) are NOT
22
+ * here — they live in the Vault / profile and never enter this client.
23
+ */
24
+ import { MerchantClientError } from "./types.js";
25
+ export class FakeMerchantClient {
26
+ products = new Map();
27
+ consultations = [];
28
+ reviews = [];
29
+ now;
30
+ constructor(options = {}) {
31
+ for (const p of options.products ?? [])
32
+ this.products.set(p.sku, p);
33
+ this.consultations.push(...(options.consultations ?? []));
34
+ this.reviews.push(...(options.reviews ?? []));
35
+ this.now = options.now ?? "2026-08-03T15:00:00+08:00";
36
+ }
37
+ /** Test helper: advance the fake clock. */
38
+ advanceTime(ms) {
39
+ this.now = new Date(Date.parse(this.now) + ms).toISOString();
40
+ }
41
+ /** Test helper: add or replace a catalog product. */
42
+ put(product) {
43
+ this.products.set(product.sku, product);
44
+ }
45
+ /** Test helper: push an incoming consultation. */
46
+ addConsultation(c) {
47
+ this.consultations.push(c);
48
+ }
49
+ async listProducts(merchantId) {
50
+ return [...this.products.values()].filter((p) => p.merchant_id === merchantId);
51
+ }
52
+ async getProduct(sku) {
53
+ const product = this.products.get(sku);
54
+ if (product === undefined) {
55
+ throw new MerchantClientError("not_found", `no product ${sku}`);
56
+ }
57
+ return product;
58
+ }
59
+ async createProduct(input) {
60
+ if (this.products.has(input.sku)) {
61
+ throw new MerchantClientError("validation", `product ${input.sku} already exists`);
62
+ }
63
+ const product = {
64
+ sku: input.sku,
65
+ merchant_id: input.merchant_id,
66
+ title: input.title,
67
+ description: input.description ?? "",
68
+ category: input.category ?? "",
69
+ tags: input.tags ?? [],
70
+ price: input.price,
71
+ currency: input.currency ?? "CNY",
72
+ stock: input.stock,
73
+ delivery_attributes: input.delivery_attributes ?? [],
74
+ paused: false,
75
+ };
76
+ this.products.set(product.sku, product);
77
+ return product;
78
+ }
79
+ async updateProduct(sku, patch) {
80
+ const product = this.requireProduct(sku);
81
+ const updated = {
82
+ ...product,
83
+ ...(patch.title !== undefined ? { title: patch.title } : {}),
84
+ ...(patch.price !== undefined ? { price: patch.price } : {}),
85
+ ...(patch.stock !== undefined ? { stock: patch.stock } : {}),
86
+ ...(patch.currency !== undefined ? { currency: patch.currency } : {}),
87
+ ...(patch.category !== undefined ? { category: patch.category } : {}),
88
+ ...(patch.tags !== undefined ? { tags: patch.tags } : {}),
89
+ ...(patch.description !== undefined ? { description: patch.description } : {}),
90
+ ...(patch.delivery_attributes !== undefined
91
+ ? { delivery_attributes: patch.delivery_attributes }
92
+ : {}),
93
+ };
94
+ this.products.set(sku, updated);
95
+ return updated;
96
+ }
97
+ async getInventorySnapshot(sku) {
98
+ const product = await this.getProduct(sku);
99
+ return { sku: product.sku, stock: product.stock, observed_at: this.now };
100
+ }
101
+ /** Inventory-scope write, always against a fresh read of the product. */
102
+ async updateInventory(sku, stock) {
103
+ return this.updateProduct(sku, { stock });
104
+ }
105
+ async listIncomingConsultations(merchantId) {
106
+ return this.consultations.filter((c) => {
107
+ const product = this.products.get(c.sku ?? "");
108
+ return product === undefined || product.merchant_id === merchantId;
109
+ });
110
+ }
111
+ async getHumanReviewQueue(merchantId) {
112
+ const owned = new Set([...this.products.values()].filter((p) => p.merchant_id === merchantId).map((p) => p.sku));
113
+ return this.reviews.filter((r) => owned.has(r.sku));
114
+ }
115
+ async pauseListing(sku, paused) {
116
+ return this.updateProduct(sku, { paused });
117
+ }
118
+ requireProduct(sku) {
119
+ const product = this.products.get(sku);
120
+ if (product === undefined) {
121
+ throw new MerchantClientError("not_found", `no product ${sku}`);
122
+ }
123
+ return product;
124
+ }
125
+ }
126
+ /** A merchant catalog fixture with shopping-cli field shapes. */
127
+ export function fakeMerchantProduct(overrides = {}) {
128
+ return {
129
+ sku: "sku-001",
130
+ merchant_id: "merchant-001",
131
+ title: "手写陶瓷杯",
132
+ description: "手工拉坯,350ml",
133
+ category: "kitchenware",
134
+ tags: ["手工", "陶瓷"],
135
+ price: 99,
136
+ currency: "CNY",
137
+ stock: 12,
138
+ delivery_attributes: [],
139
+ paused: false,
140
+ ...overrides,
141
+ };
142
+ }
143
+ //# sourceMappingURL=fake-merchant-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fake-merchant-client.js","sourceRoot":"","sources":["../../../src/agent/merchant/fake-merchant-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;GAOG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAWjD,MAAM,OAAO,kBAAkB;IACZ,QAAQ,GAAG,IAAI,GAAG,EAAkC,CAAC;IACrD,aAAa,GAA2B,EAAE,CAAC;IAC3C,OAAO,GAAsB,EAAE,CAAC;IACzC,GAAG,CAAS;IAEp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,CAAC;IAC7C,CAAC;IAEO,cAAc,CAAC,GAAW;QAChC,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACvC,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC1B,MAAM,IAAI,mBAAmB,CAAC,WAAW,EAAE,cAAc,GAAG,EAAE,CAAC,CAAC;QAClE,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;CACF;AAED,iEAAiE;AACjE,MAAM,UAAU,mBAAmB,CAAC,YAA6C,EAAE;IACjF,OAAO;QACL,GAAG,EAAE,SAAS;QACd,WAAW,EAAE,cAAc;QAC3B,KAAK,EAAE,OAAO;QACd,WAAW,EAAE,YAAY;QACzB,QAAQ,EAAE,aAAa;QACvB,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC;QAClB,KAAK,EAAE,EAAE;QACT,QAAQ,EAAE,KAAK;QACf,KAAK,EAAE,EAAE;QACT,mBAAmB,EAAE,EAAE;QACvB,MAAM,EAAE,KAAK;QACb,GAAG,SAAS;KACb,CAAC;AACJ,CAAC"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Copyright 2026 harrylabsj
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * shopping-cli HTTP Merchant client (design §15.3/§15.4).
18
+ *
19
+ * Catalog/inventory/conversation reads and writes against the real gateway.
20
+ * Tokens come from the CredentialBroker per scope: catalog writes and
21
+ * merchant-scoped reads use the catalog credential, inventory writes use the
22
+ * inventory credential. Tokens are attached per-request and never stored.
23
+ *
24
+ * Trade-off (fail-closed): shopping-cli 2.x has no listing pause/resume
25
+ * endpoint (`active` is internal to the catalog), so pauseListing refuses
26
+ * here with a clear message — the approval machinery still runs, only the
27
+ * final write is refused.
28
+ */
29
+ import type { CredentialBroker } from "./credential-broker.js";
30
+ import type { HumanReviewItem, IncomingConsultation, InventorySnapshot, MerchantCatalogProduct, MerchantClient, MerchantProductInput, MerchantProductPatch } from "./types.js";
31
+ export declare class HttpMerchantClient implements MerchantClient {
32
+ private readonly baseUrl;
33
+ private readonly broker;
34
+ constructor(baseUrl: string, broker: CredentialBroker);
35
+ private request;
36
+ /** Catalog credential token; missing scope -> fail closed. */
37
+ private catalogToken;
38
+ listProducts(merchantId: string): Promise<MerchantCatalogProduct[]>;
39
+ getProduct(sku: string): Promise<MerchantCatalogProduct>;
40
+ createProduct(input: MerchantProductInput): Promise<MerchantCatalogProduct>;
41
+ updateProduct(sku: string, patch: MerchantProductPatch): Promise<MerchantCatalogProduct>;
42
+ getInventorySnapshot(sku: string): Promise<InventorySnapshot>;
43
+ /** Inventory-scope write: PATCH only the stock field with the inventory token. */
44
+ updateInventory(sku: string, stock: number): Promise<MerchantCatalogProduct>;
45
+ listIncomingConsultations(merchantId: string): Promise<IncomingConsultation[]>;
46
+ getHumanReviewQueue(merchantId: string): Promise<HumanReviewItem[]>;
47
+ /** shopping-cli 2.x has no listing pause endpoint — fail closed. */
48
+ pauseListing(_sku: string, _paused: boolean): Promise<MerchantCatalogProduct>;
49
+ }