@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,284 @@
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
+ * HttpCommerceClient — CommerceClient over the shopping-cli 2.x
18
+ * shopping.negotiation/0.1 HTTP API (the authoritative Commerce Gateway).
19
+ *
20
+ * This is the only supported way Kiwi talks to a real marketplace. No Python
21
+ * imports, no SQLite, no subprocess calls into shopping-cli business
22
+ * commands. Auth is `Authorization: Bearer <token>`; the API answers with a
23
+ * uniform `{"ok": true, ...}` / `{"ok": false, "error": ...}` envelope.
24
+ *
25
+ * Protocol mapping (references/negotiation-api.md on the shopping-cli side):
26
+ * - GET /capabilities -> getCapabilities (inner `capabilities`
27
+ * object, frozen-schema validated)
28
+ * - GET /negotiation/pending-messages -> listPendingMessages (role/owner are
29
+ * derived from the token server-side;
30
+ * the client never sends them)
31
+ * - POST /negotiation/claims -> claimMessage
32
+ * - GET /negotiation/snapshot -> getNegotiationSnapshot (frozen-schema
33
+ * validated, fail closed)
34
+ * - POST /negotiation/decisions -> submitNegotiationDecision (inner
35
+ * `policy_result`, frozen-schema
36
+ * validated)
37
+ * - POST /negotiation/claims/{complete,fail,abandon} -> claim settlement
38
+ *
39
+ * Every gateway response that carries a frozen-contract object (capabilities,
40
+ * snapshot, policy_result) is validated with the Kiwi Ajv frozen schemas
41
+ * before use: a malformed envelope, a missing inner object, or a wrong field
42
+ * type is classified as a `validation` CommerceError and never trusted.
43
+ */
44
+ import { validateAgainst } from "../contracts/schemas.js";
45
+ import { readJsonBody, SafeHttpError } from "../net/safe-http.js";
46
+ import { CommerceError, } from "./types.js";
47
+ const PROCESS_STATUSES = [
48
+ "processing",
49
+ "processed",
50
+ "failed",
51
+ "abandoned",
52
+ ];
53
+ export class HttpCommerceClient {
54
+ baseUrl;
55
+ token;
56
+ fetchImpl;
57
+ timeoutMs;
58
+ constructor(options) {
59
+ this.baseUrl = options.baseUrl.replace(/\/+$/, "");
60
+ this.token = options.token;
61
+ this.fetchImpl = options.fetchImpl ?? globalThis.fetch;
62
+ this.timeoutMs = options.timeoutMs ?? 15_000;
63
+ }
64
+ async request(method, path, body) {
65
+ const controller = new AbortController();
66
+ const timer = setTimeout(() => controller.abort(), this.timeoutMs);
67
+ let response;
68
+ try {
69
+ response = await this.fetchImpl(`${this.baseUrl}${path}`, {
70
+ method,
71
+ // 出站加固:绝不跟随重定向(3xx 目标不经过校验,且会携带 Bearer 头)。
72
+ redirect: "manual",
73
+ headers: {
74
+ authorization: `Bearer ${this.token}`,
75
+ "content-type": "application/json",
76
+ accept: "application/json",
77
+ },
78
+ body: body === undefined ? undefined : JSON.stringify(body),
79
+ signal: controller.signal,
80
+ });
81
+ }
82
+ catch (err) {
83
+ throw new CommerceError("transient", `Commerce API request failed: ${err instanceof Error ? err.message : String(err)}`);
84
+ }
85
+ if (response.redirected ||
86
+ response.type === "opaqueredirect" ||
87
+ (response.status >= 300 && response.status < 400)) {
88
+ throw new CommerceError("transient", `Commerce API must not follow redirects (HTTP ${response.status})`);
89
+ }
90
+ let payload = {};
91
+ try {
92
+ // 响应体读取在超时覆盖内 + 大小上限(出站加固)。
93
+ payload = (await readJsonBody(response, { signal: controller.signal }));
94
+ }
95
+ catch (err) {
96
+ if (controller.signal.aborted) {
97
+ throw new CommerceError("transient", `Commerce API request timed out after ${this.timeoutMs}ms while reading response`);
98
+ }
99
+ if (err instanceof SafeHttpError && err.code === "response_too_large") {
100
+ throw new CommerceError("transient", err.message);
101
+ }
102
+ // Non-JSON body; handled via status mapping below.
103
+ }
104
+ finally {
105
+ clearTimeout(timer);
106
+ }
107
+ if (!response.ok || payload.ok === false) {
108
+ const message = typeof payload.error === "string" ? payload.error : `HTTP ${response.status}`;
109
+ const kind = response.status === 401 || response.status === 403
110
+ ? "auth"
111
+ : response.status === 404
112
+ ? "not_found"
113
+ : response.status === 409
114
+ ? "conflict"
115
+ : response.status === 429
116
+ ? "rate_limit"
117
+ : response.status >= 400 && response.status < 500
118
+ ? "validation"
119
+ : "transient";
120
+ throw new CommerceError(kind, message, response.status);
121
+ }
122
+ return payload;
123
+ }
124
+ /** Fail-closed shape check for envelope fields that carry typed data. */
125
+ static badShape(what, detail) {
126
+ return new CommerceError("validation", `Commerce API ${what} response invalid: ${detail}`);
127
+ }
128
+ static requireObject(value, what) {
129
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
130
+ throw HttpCommerceClient.badShape(what, "expected an object");
131
+ }
132
+ return value;
133
+ }
134
+ async health() {
135
+ const payload = await this.request("GET", "/health");
136
+ return {
137
+ ok: payload.ok === true,
138
+ service: typeof payload.service === "string" ? payload.service : undefined,
139
+ version: typeof payload.version === "string" ? payload.version : undefined,
140
+ details: typeof payload.checks === "object" && payload.checks !== null
141
+ ? payload.checks
142
+ : undefined,
143
+ };
144
+ }
145
+ async getCapabilities() {
146
+ const payload = await this.request("GET", "/capabilities");
147
+ const inner = HttpCommerceClient.requireObject(payload.capabilities, "capabilities");
148
+ const errors = validateAgainst("capabilities", inner);
149
+ if (errors.length > 0) {
150
+ throw HttpCommerceClient.badShape("capabilities", errors.join("; "));
151
+ }
152
+ return inner;
153
+ }
154
+ async listPendingMessages() {
155
+ const payload = await this.request("GET", "/negotiation/pending-messages");
156
+ if (!Array.isArray(payload.pending)) {
157
+ throw HttpCommerceClient.badShape("pending-messages", "pending must be an array");
158
+ }
159
+ return payload.pending.map((item, index) => {
160
+ const what = `pending-messages[${index}]`;
161
+ const m = HttpCommerceClient.requireObject(item, what);
162
+ if (typeof m.conversation_id !== "string" ||
163
+ !Number.isInteger(m.message_id) ||
164
+ typeof m.conversation_status !== "string" ||
165
+ (m.sender_role !== "buyer" && m.sender_role !== "merchant") ||
166
+ typeof m.preview !== "string" ||
167
+ typeof m.created_at !== "string") {
168
+ throw HttpCommerceClient.badShape(what, "field types do not match the protocol");
169
+ }
170
+ return {
171
+ conversation_id: m.conversation_id,
172
+ message_id: m.message_id,
173
+ conversation_status: m.conversation_status,
174
+ sender_role: m.sender_role,
175
+ preview: m.preview,
176
+ created_at: m.created_at,
177
+ };
178
+ });
179
+ }
180
+ async claimMessage(input) {
181
+ const payload = await this.request("POST", "/negotiation/claims", {
182
+ conversation_id: input.conversation_id,
183
+ message_id: input.message_id,
184
+ idempotency_key: input.idempotency_key,
185
+ });
186
+ const claim = HttpCommerceClient.requireObject(payload.claim, "claim");
187
+ if (typeof claim.claimed !== "boolean" ||
188
+ typeof claim.status !== "string" ||
189
+ typeof claim.attempts !== "number" ||
190
+ typeof claim.idempotency_key !== "string") {
191
+ throw HttpCommerceClient.badShape("claim", "field types do not match the protocol");
192
+ }
193
+ return {
194
+ claimed: claim.claimed,
195
+ status: claim.status,
196
+ attempts: claim.attempts,
197
+ idempotency_key: claim.idempotency_key,
198
+ };
199
+ }
200
+ async getNegotiationSnapshot(input) {
201
+ const query = `conversation_id=${encodeURIComponent(input.conversation_id)}` +
202
+ `&message_id=${encodeURIComponent(String(input.message_id))}`;
203
+ const payload = await this.request("GET", `/negotiation/snapshot?${query}`);
204
+ const inner = HttpCommerceClient.requireObject(payload.snapshot, "snapshot");
205
+ const errors = validateAgainst("snapshot", inner);
206
+ if (errors.length > 0) {
207
+ throw HttpCommerceClient.badShape("snapshot", errors.join("; "));
208
+ }
209
+ return inner;
210
+ }
211
+ async submitNegotiationDecision(input) {
212
+ const payload = await this.request("POST", "/negotiation/decisions", {
213
+ idempotency_key: input.idempotency_key,
214
+ decision: input.decision,
215
+ });
216
+ const inner = HttpCommerceClient.requireObject(payload.policy_result, "policy_result");
217
+ const errors = validateAgainst("policy-result", inner);
218
+ if (errors.length > 0) {
219
+ throw HttpCommerceClient.badShape("policy_result", errors.join("; "));
220
+ }
221
+ return inner;
222
+ }
223
+ async completeClaim(input) {
224
+ return this.processVerb("complete", input.message_id);
225
+ }
226
+ async failClaim(input) {
227
+ return this.processVerb("fail", input.message_id, input.error);
228
+ }
229
+ async abandonClaim(input) {
230
+ return this.processVerb("abandon", input.message_id, input.error);
231
+ }
232
+ async heartbeat(input) {
233
+ const body = {};
234
+ if (input?.message_id !== undefined)
235
+ body.message_id = input.message_id;
236
+ const payload = await this.request("POST", "/negotiation/claims/heartbeat", body);
237
+ const inner = HttpCommerceClient.requireObject(payload.heartbeat, "heartbeat");
238
+ if (typeof inner.status !== "string" ||
239
+ !Number.isInteger(inner.refreshed) ||
240
+ typeof inner.at !== "string") {
241
+ throw HttpCommerceClient.badShape("heartbeat", "field types do not match the protocol");
242
+ }
243
+ return { status: inner.status, refreshed: inner.refreshed, at: inner.at };
244
+ }
245
+ async abandonStaleClaims(input) {
246
+ const body = {};
247
+ if (input?.ttl_seconds !== undefined)
248
+ body.ttl_seconds = input.ttl_seconds;
249
+ const payload = await this.request("POST", "/negotiation/claims/abandon-stale", body);
250
+ const inner = HttpCommerceClient.requireObject(payload.stale, "abandon-stale");
251
+ if (!Number.isInteger(inner.abandoned) ||
252
+ !Array.isArray(inner.message_ids) ||
253
+ !inner.message_ids.every((id) => Number.isInteger(id)) ||
254
+ !Number.isInteger(inner.ttl_seconds) ||
255
+ typeof inner.at !== "string") {
256
+ throw HttpCommerceClient.badShape("abandon-stale", "field types do not match the protocol");
257
+ }
258
+ return {
259
+ abandoned: inner.abandoned,
260
+ message_ids: inner.message_ids,
261
+ ttl_seconds: inner.ttl_seconds,
262
+ at: inner.at,
263
+ };
264
+ }
265
+ async processVerb(verb, messageId, error) {
266
+ const payload = await this.request("POST", `/negotiation/claims/${verb}`, {
267
+ message_id: messageId,
268
+ ...(error !== undefined ? { error } : {}),
269
+ });
270
+ const process = HttpCommerceClient.requireObject(payload.process, `claims/${verb}`);
271
+ if (typeof process.status !== "string" ||
272
+ !PROCESS_STATUSES.includes(process.status)) {
273
+ throw HttpCommerceClient.badShape(`claims/${verb}`, "process.status invalid");
274
+ }
275
+ const result = {
276
+ status: process.status,
277
+ message_id: messageId,
278
+ };
279
+ if (typeof process.last_error === "string")
280
+ result.last_error = process.last_error;
281
+ return result;
282
+ }
283
+ }
284
+ //# sourceMappingURL=http-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-client.js","sourceRoot":"","sources":["../../src/commerce/http-client.ts"],"names":[],"mapp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OAAO,OAAO,CAAC,UAAU,KAAK,QAAQ;YAAE,MAAM,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QACnF,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
@@ -0,0 +1,50 @@
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 { DatabaseSync } from "node:sqlite";
17
+ import type { CommerceHealth } from "./types.js";
18
+ import { type CommerceDataSource, type CommerceField, type ProductFact, type ProductSearchQuery } from "./data-source.js";
19
+ declare const CTOR: unique symbol;
20
+ /** 本地商品库 CommerceDataSource(LOCAL_AUTHORITATIVE)。 */
21
+ export declare class LocalDatabaseCommerceDataSource implements CommerceDataSource {
22
+ private readonly db;
23
+ constructor(db: DatabaseSync, _token: typeof CTOR);
24
+ getProduct(sku: string): Promise<ProductFact | undefined>;
25
+ getProducts(query?: ProductSearchQuery): Promise<ProductFact[]>;
26
+ getInventory(sku: string): Promise<CommerceField<number> | undefined>;
27
+ getPrice(sku: string): Promise<CommerceField<{
28
+ currency: string;
29
+ amount_minor: number;
30
+ }> | undefined>;
31
+ getPublicListing(): Promise<Record<string, unknown>>;
32
+ health(): Promise<CommerceHealth>;
33
+ /** 写入商品事实(本地权威:录入即事实)。 */
34
+ upsertProduct(input: {
35
+ sku: string;
36
+ title?: string;
37
+ price_minor: number;
38
+ currency?: string;
39
+ stock?: number;
40
+ delivery_lead_days?: number;
41
+ updated_at?: string;
42
+ }): ProductFact;
43
+ close(): void;
44
+ private rowToFact;
45
+ }
46
+ /** 打开(必要时创建)本地商品库;目录 0700 / 文件 0600。 */
47
+ export declare function openLocalDatabaseCommerceDataSource(options: {
48
+ dbPath: string;
49
+ }): LocalDatabaseCommerceDataSource;
50
+ export {};
@@ -0,0 +1,162 @@
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
+ * LocalDatabaseCommerceDataSource —— 本地商品库(node:sqlite,
18
+ * shopping-cli data hub v0.2.1 §4/#6「至少一种本地数据库源」)。
19
+ *
20
+ * 全部字段 LOCAL_AUTHORITATIVE(本地规则/录入即权威);存储惯例对齐
21
+ * src/handoff/order-record.ts(目录 0700 / 文件 0600 / DatabaseSync)。
22
+ * public-only:成本/底价等私有字段不在本表。
23
+ */
24
+ import { chmodSync, existsSync, mkdirSync } from "node:fs";
25
+ import path from "node:path";
26
+ import { DatabaseSync } from "node:sqlite";
27
+ import { CommerceError, } from "./data-source.js";
28
+ const PRODUCT_SCHEMA = `
29
+ CREATE TABLE IF NOT EXISTS product_facts (
30
+ sku TEXT PRIMARY KEY,
31
+ title TEXT NOT NULL DEFAULT '',
32
+ price_minor INTEGER NOT NULL,
33
+ currency TEXT NOT NULL DEFAULT 'CNY',
34
+ stock INTEGER,
35
+ delivery_lead_days INTEGER,
36
+ updated_at TEXT NOT NULL
37
+ );
38
+ CREATE INDEX IF NOT EXISTS idx_product_title ON product_facts(title);
39
+ `;
40
+ const CTOR = Symbol("local-db-source.ctor");
41
+ /** LIKE 通配符转义(`%`/`_` 在用户输入里是字面量,不是通配符)。 */
42
+ function escapeLike(value) {
43
+ return value.replace(/[\\%_]/g, (ch) => `\\${ch}`);
44
+ }
45
+ /** 本地商品库 CommerceDataSource(LOCAL_AUTHORITATIVE)。 */
46
+ export class LocalDatabaseCommerceDataSource {
47
+ db;
48
+ constructor(db, _token) {
49
+ this.db = db;
50
+ }
51
+ async getProduct(sku) {
52
+ if (typeof sku !== "string" || sku.length === 0) {
53
+ throw new CommerceError("invalid_input", "sku must be a non-empty string");
54
+ }
55
+ const row = this.db
56
+ .prepare("SELECT * FROM product_facts WHERE sku = ?")
57
+ .get(sku);
58
+ return row === undefined ? undefined : this.rowToFact(row);
59
+ }
60
+ async getProducts(query = {}) {
61
+ const limit = Math.max(1, Math.min(Number(query.limit ?? 20) || 20, 100));
62
+ const q = (query.q ?? "").trim();
63
+ const rows = q
64
+ ? this.db
65
+ .prepare("SELECT * FROM product_facts WHERE sku LIKE ? ESCAPE '\\' OR title LIKE ? ESCAPE '\\' ORDER BY sku LIMIT ?")
66
+ .all(`%${escapeLike(q)}%`, `%${escapeLike(q)}%`, limit)
67
+ : this.db
68
+ .prepare("SELECT * FROM product_facts ORDER BY sku LIMIT ?")
69
+ .all(limit);
70
+ return rows.map((r) => this.rowToFact(r));
71
+ }
72
+ async getInventory(sku) {
73
+ const product = await this.getProduct(sku);
74
+ if (product?.stock === undefined)
75
+ return undefined;
76
+ return {
77
+ value: product.stock,
78
+ authority: "LOCAL_AUTHORITATIVE",
79
+ source: "local-db",
80
+ };
81
+ }
82
+ async getPrice(sku) {
83
+ const product = await this.getProduct(sku);
84
+ if (product?.price_minor === undefined || product.currency === undefined)
85
+ return undefined;
86
+ return {
87
+ value: { currency: product.currency, amount_minor: product.price_minor },
88
+ authority: "LOCAL_AUTHORITATIVE",
89
+ source: "local-db",
90
+ };
91
+ }
92
+ async getPublicListing() {
93
+ const rows = this.db
94
+ .prepare("SELECT sku, title, price_minor, currency FROM product_facts ORDER BY sku LIMIT 500")
95
+ .all();
96
+ return { source: "local-db", count: rows.length, products: rows.map((r) => this.rowToFact(r)) };
97
+ }
98
+ async health() {
99
+ try {
100
+ this.db.prepare("SELECT COUNT(*) AS n FROM product_facts").get();
101
+ return { ok: true, service: "local-db-commerce-data-source", version: "1" };
102
+ }
103
+ catch (err) {
104
+ return {
105
+ ok: false,
106
+ service: "local-db-commerce-data-source",
107
+ details: { error: err instanceof Error ? err.message : String(err) },
108
+ };
109
+ }
110
+ }
111
+ /** 写入商品事实(本地权威:录入即事实)。 */
112
+ upsertProduct(input) {
113
+ if (typeof input.sku !== "string" || input.sku.length === 0) {
114
+ throw new CommerceError("invalid_input", "sku must be a non-empty string");
115
+ }
116
+ if (!Number.isInteger(input.price_minor) || input.price_minor < 0) {
117
+ throw new CommerceError("invalid_input", "price_minor must be a non-negative integer");
118
+ }
119
+ const updatedAt = input.updated_at ?? new Date().toISOString();
120
+ this.db
121
+ .prepare(`INSERT INTO product_facts (sku, title, price_minor, currency, stock, delivery_lead_days, updated_at)
122
+ VALUES (?, ?, ?, ?, ?, ?, ?)
123
+ ON CONFLICT(sku) DO UPDATE SET
124
+ title=excluded.title, price_minor=excluded.price_minor, currency=excluded.currency,
125
+ stock=excluded.stock, delivery_lead_days=excluded.delivery_lead_days, updated_at=excluded.updated_at`)
126
+ .run(input.sku, input.title ?? "", input.price_minor, input.currency ?? "CNY", input.stock ?? null, input.delivery_lead_days ?? null, updatedAt);
127
+ const row = this.db.prepare("SELECT * FROM product_facts WHERE sku = ?").get(input.sku);
128
+ if (row === undefined)
129
+ throw new CommerceError("request_failed", "upsert did not persist");
130
+ return this.rowToFact(row);
131
+ }
132
+ close() {
133
+ this.db.close();
134
+ }
135
+ rowToFact(row) {
136
+ return {
137
+ sku: row.sku,
138
+ ...(row.title !== "" ? { title: row.title } : {}),
139
+ price_minor: row.price_minor,
140
+ currency: row.currency,
141
+ ...(row.stock !== null ? { stock: row.stock } : {}),
142
+ ...(row.delivery_lead_days !== null ? { delivery_lead_days: row.delivery_lead_days } : {}),
143
+ };
144
+ }
145
+ }
146
+ /** 打开(必要时创建)本地商品库;目录 0700 / 文件 0600。 */
147
+ export function openLocalDatabaseCommerceDataSource(options) {
148
+ if (options.dbPath === ":memory:") {
149
+ const db = new DatabaseSync(":memory:");
150
+ db.exec(PRODUCT_SCHEMA);
151
+ return new LocalDatabaseCommerceDataSource(db, CTOR);
152
+ }
153
+ const dir = path.dirname(options.dbPath);
154
+ mkdirSync(dir, { recursive: true, mode: 0o700 });
155
+ chmodSync(dir, 0o700);
156
+ const db = new DatabaseSync(options.dbPath);
157
+ if (existsSync(options.dbPath))
158
+ chmodSync(options.dbPath, 0o600);
159
+ db.exec(PRODUCT_SCHEMA);
160
+ return new LocalDatabaseCommerceDataSource(db, CTOR);
161
+ }
162
+ //# sourceMappingURL=local-db-source.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local-db-source.js","sourceRoot":"","sources":["../../src/commerce/local-db-source.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;GAOG;AAEH,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAC3D,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EACL,aAAa,GAKd,MAAM,kBAAkB,CAAC;AAE1B,MAAM,cAAc,GAAG;;;;;;;;;;;CAWtB,CAAC;AAYF,MAAM,IAAI,GAAG,MAAM,CAAC,sBAAsB,CAAC,CAAC;AAE5C,4CAA4C;AAC5C,SAAS,UAAU,CAAC,KAAa;IAC/B,OAAO,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AACrD,CAAC;AAED,qDAAqD;AACrD,MAAM,OAAO,+BAA+B;IACzB,EAAE,CAAe;IAElC,YAAY,EAAgB,EAAE,MAAmB;QAC/C,IAAI,CAAC,EAAE,G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I,EAAE,KAAK,EAAE,CAAC,CAAC;IACjD,SAAS,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACtB,MAAM,EAAE,GAAG,IAAI,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC5C,IAAI,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC;QAAE,SAAS,CAAC,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACjE,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IACxB,OAAO,IAAI,+BAA+B,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;AACvD,CAAC"}
@@ -0,0 +1,57 @@
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
+ * ShoppingCliCommerceDataSource —— shopping-cli 商品开放层 adapter
18
+ * (shopping-cli data hub v0.2.1 §3/#5:shopping-cli 可作为 Merchant
19
+ * CommerceDataSource,完成定义 #5)。
20
+ *
21
+ * 端点契约(shopping-cli 仓 route_registry):
22
+ * GET {baseUrl}/products/{sku} → {product: {...}}
23
+ * GET {baseUrl}/search/products?limit= → {results: [...]}
24
+ *
25
+ * 字段语义:
26
+ * - shopping-cli 的 `price` 以「元」为单位(float)→ 转换为
27
+ * `price_minor`(minor units,KNP Money 约定;两位小数假设,文档注明);
28
+ * - 权威语义 UPSTREAM_PROXY(数据权威在 shopping-cli 侧,Kiwi 只读)。
29
+ */
30
+ import { type CommerceDataSource, type CommerceField, type ProductFact, type ProductSearchQuery } from "./data-source.js";
31
+ import type { CommerceHealth } from "./types.js";
32
+ export interface ShoppingCliCommerceDataSourceDeps {
33
+ /** shopping-cli 服务根 URL(http/https,无 userinfo/query/fragment)。 */
34
+ baseUrl: string;
35
+ /** 可选的 bearer 凭证(merchants 角色只读 token)。 */
36
+ authToken?: string;
37
+ /** 拉取超时 ms(默认 15000)。 */
38
+ timeoutMs?: number;
39
+ /** 注入 fetch(测试)。 */
40
+ fetchImpl?: typeof fetch;
41
+ }
42
+ /** shopping-cli 商品开放层数据源(UPSTREAM_PROXY,source="shopping-cli")。 */
43
+ export declare class ShoppingCliCommerceDataSource implements CommerceDataSource {
44
+ private readonly baseUrl;
45
+ private readonly deps;
46
+ constructor(deps: ShoppingCliCommerceDataSourceDeps);
47
+ private getJson;
48
+ getProduct(sku: string): Promise<ProductFact | undefined>;
49
+ getProducts(query?: ProductSearchQuery): Promise<ProductFact[]>;
50
+ getInventory(sku: string): Promise<CommerceField<number> | undefined>;
51
+ getPrice(sku: string): Promise<CommerceField<{
52
+ currency: string;
53
+ amount_minor: number;
54
+ }> | undefined>;
55
+ getPublicListing(): Promise<Record<string, unknown>>;
56
+ health(): Promise<CommerceHealth>;
57
+ }