@harrylabsj/kiwi 0.12.32 → 0.12.33

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 (221) hide show
  1. package/README.md +8 -0
  2. package/dist/a2a/inquiry-nonce-store.d.ts +12 -1
  3. package/dist/a2a/inquiry-nonce-store.js +49 -17
  4. package/dist/a2a/inquiry-nonce-store.js.map +1 -1
  5. package/dist/a2a/negotiate.d.ts +30 -1
  6. package/dist/a2a/negotiate.js +121 -32
  7. package/dist/a2a/negotiate.js.map +1 -1
  8. package/dist/a2a/node.d.ts +3 -0
  9. package/dist/a2a/node.js +13 -3
  10. package/dist/a2a/node.js.map +1 -1
  11. package/dist/a2a/open-inquiry-session.d.ts +1 -0
  12. package/dist/a2a/open-inquiry-session.js +3 -1
  13. package/dist/a2a/open-inquiry-session.js.map +1 -1
  14. package/dist/a2a/open-inquiry-verifier.js +2 -2
  15. package/dist/a2a/open-inquiry-verifier.js.map +1 -1
  16. package/dist/a2a/server/errors.d.ts +4 -3
  17. package/dist/a2a/server/errors.js +10 -2
  18. package/dist/a2a/server/errors.js.map +1 -1
  19. package/dist/a2a/server/merchant-handler.d.ts +41 -1
  20. package/dist/a2a/server/merchant-handler.js +259 -89
  21. package/dist/a2a/server/merchant-handler.js.map +1 -1
  22. package/dist/a2a/server/merchant-procurement.d.ts +90 -0
  23. package/dist/a2a/server/merchant-procurement.js +75 -0
  24. package/dist/a2a/server/merchant-procurement.js.map +1 -0
  25. package/dist/a2a/server/merchant-product-facts.d.ts +2 -0
  26. package/dist/a2a/server/merchant-product-facts.js.map +1 -1
  27. package/dist/a2a/server/negotiation-approvals.d.ts +11 -0
  28. package/dist/a2a/server/negotiation-approvals.js +43 -0
  29. package/dist/a2a/server/negotiation-approvals.js.map +1 -1
  30. package/dist/a2a/server/pipeline.js +4 -1
  31. package/dist/a2a/server/pipeline.js.map +1 -1
  32. package/dist/a2a/server/server.js +4 -3
  33. package/dist/a2a/server/server.js.map +1 -1
  34. package/dist/a2a/server/types.d.ts +2 -1
  35. package/dist/agent/alipay-native-view.d.ts +27 -0
  36. package/dist/agent/alipay-native-view.js +113 -0
  37. package/dist/agent/alipay-native-view.js.map +1 -0
  38. package/dist/agent/buyer/buyer-tools.d.ts +20 -0
  39. package/dist/agent/buyer/buyer-tools.js +241 -48
  40. package/dist/agent/buyer/buyer-tools.js.map +1 -1
  41. package/dist/agent/buyer/types.d.ts +1 -1
  42. package/dist/agent/buyer/types.js.map +1 -1
  43. package/dist/agent/chat-tui.js +16 -1
  44. package/dist/agent/chat-tui.js.map +1 -1
  45. package/dist/agent/kernel-builder.d.ts +2 -0
  46. package/dist/agent/kernel-builder.js +14 -0
  47. package/dist/agent/kernel-builder.js.map +1 -1
  48. package/dist/agent/kernel.d.ts +8 -0
  49. package/dist/agent/kernel.js +67 -1
  50. package/dist/agent/kernel.js.map +1 -1
  51. package/dist/buyer-core/a2a-accept-terms.d.ts +11 -0
  52. package/dist/buyer-core/a2a-accept-terms.js +28 -0
  53. package/dist/buyer-core/a2a-accept-terms.js.map +1 -0
  54. package/dist/buyer-core/a2a-knp.d.ts +3 -0
  55. package/dist/buyer-core/a2a-knp.js +3 -3
  56. package/dist/buyer-core/a2a-knp.js.map +1 -1
  57. package/dist/buyer-core/a2a-negotiator.d.ts +16 -0
  58. package/dist/buyer-core/a2a-negotiator.js +53 -16
  59. package/dist/buyer-core/a2a-negotiator.js.map +1 -1
  60. package/dist/buyer-core/a2a-quote-fetcher.d.ts +0 -15
  61. package/dist/buyer-core/a2a-quote-fetcher.js +10 -15
  62. package/dist/buyer-core/a2a-quote-fetcher.js.map +1 -1
  63. package/dist/buyer-core/merchant-index.d.ts +2 -2
  64. package/dist/buyer-core/merchant-index.js +23 -5
  65. package/dist/buyer-core/merchant-index.js.map +1 -1
  66. package/dist/buyer-core/procurement/cases.d.ts +441 -0
  67. package/dist/buyer-core/procurement/cases.js +457 -0
  68. package/dist/buyer-core/procurement/cases.js.map +1 -0
  69. package/dist/buyer-core/procurement/quote-comparison.d.ts +137 -0
  70. package/dist/buyer-core/procurement/quote-comparison.js +106 -0
  71. package/dist/buyer-core/procurement/quote-comparison.js.map +1 -0
  72. package/dist/buyer-core/procurement/quote-normalizer.d.ts +45 -0
  73. package/dist/buyer-core/procurement/quote-normalizer.js +153 -0
  74. package/dist/buyer-core/procurement/quote-normalizer.js.map +1 -0
  75. package/dist/buyer-core/procurement/requirements.d.ts +50 -0
  76. package/dist/buyer-core/procurement/requirements.js +43 -0
  77. package/dist/buyer-core/procurement/requirements.js.map +1 -0
  78. package/dist/buyer-core/procurement/source-observation.d.ts +57 -0
  79. package/dist/buyer-core/procurement/source-observation.js +54 -0
  80. package/dist/buyer-core/procurement/source-observation.js.map +1 -0
  81. package/dist/buyer-core/procurement/store.d.ts +21 -0
  82. package/dist/buyer-core/procurement/store.js +68 -0
  83. package/dist/buyer-core/procurement/store.js.map +1 -0
  84. package/dist/buyer-core/protocol-recovery.d.ts +8 -0
  85. package/dist/buyer-core/protocol-recovery.js +17 -2
  86. package/dist/buyer-core/protocol-recovery.js.map +1 -1
  87. package/dist/buyer-core/quote-quantity.d.ts +5 -0
  88. package/dist/buyer-core/quote-quantity.js +15 -0
  89. package/dist/buyer-core/quote-quantity.js.map +1 -0
  90. package/dist/buyer-core/service.d.ts +71 -3
  91. package/dist/buyer-core/service.js +271 -28
  92. package/dist/buyer-core/service.js.map +1 -1
  93. package/dist/buyer-core/store.d.ts +13 -0
  94. package/dist/buyer-core/store.js +25 -3
  95. package/dist/buyer-core/store.js.map +1 -1
  96. package/dist/cli.js +13 -17
  97. package/dist/cli.js.map +1 -1
  98. package/dist/cloud/alipay-collection-http.d.ts +44 -0
  99. package/dist/cloud/alipay-collection-http.js +111 -0
  100. package/dist/cloud/alipay-collection-http.js.map +1 -0
  101. package/dist/cloud/bootstrap.js +77 -12
  102. package/dist/cloud/bootstrap.js.map +1 -1
  103. package/dist/cloud/http-router.d.ts +2 -0
  104. package/dist/cloud/http-router.js +5 -0
  105. package/dist/cloud/http-router.js.map +1 -1
  106. package/dist/commerce/receipt/dispatcher.d.ts +2 -1
  107. package/dist/commerce/receipt/dispatcher.js +18 -0
  108. package/dist/commerce/receipt/dispatcher.js.map +1 -1
  109. package/dist/commerce/receipt/receipts.d.ts +7 -0
  110. package/dist/commerce/receipt/receipts.js +43 -5
  111. package/dist/commerce/receipt/receipts.js.map +1 -1
  112. package/dist/discovery/catalog-source/buyer-follows.d.ts +3 -3
  113. package/dist/discovery/catalog-source/buyer-follows.js +6 -3
  114. package/dist/discovery/catalog-source/buyer-follows.js.map +1 -1
  115. package/dist/discovery/catalog-source/kiwi-record.d.ts +2 -0
  116. package/dist/discovery/catalog-source/kiwi-record.js.map +1 -1
  117. package/dist/discovery/catalog-source/kiwi-source.js +4 -0
  118. package/dist/discovery/catalog-source/kiwi-source.js.map +1 -1
  119. package/dist/handoff/alipay-collection.d.ts +23 -0
  120. package/dist/handoff/alipay-collection.js +70 -0
  121. package/dist/handoff/alipay-collection.js.map +1 -0
  122. package/dist/handoff/order-receipts.js +2 -1
  123. package/dist/handoff/order-receipts.js.map +1 -1
  124. package/dist/handoff/ucp-checkout/channel.d.ts +1 -0
  125. package/dist/handoff/ucp-checkout/channel.js +42 -17
  126. package/dist/handoff/ucp-checkout/channel.js.map +1 -1
  127. package/dist/http/merchant-management/api.d.ts +8 -0
  128. package/dist/http/merchant-management/api.js +309 -3
  129. package/dist/http/merchant-management/api.js.map +1 -1
  130. package/dist/http/merchant-management/page.d.ts +1 -0
  131. package/dist/http/merchant-management/page.js +333 -3
  132. package/dist/http/merchant-management/page.js.map +1 -1
  133. package/dist/http/server.js +9 -2
  134. package/dist/http/server.js.map +1 -1
  135. package/dist/mcp/cli.d.ts +3 -1
  136. package/dist/mcp/cli.js +12 -2
  137. package/dist/mcp/cli.js.map +1 -1
  138. package/dist/mcp/merchant-runtime-assembly.js +1 -8
  139. package/dist/mcp/merchant-runtime-assembly.js.map +1 -1
  140. package/dist/mcp/procurement-tools.d.ts +10 -0
  141. package/dist/mcp/procurement-tools.js +173 -0
  142. package/dist/mcp/procurement-tools.js.map +1 -0
  143. package/dist/mcp/server.d.ts +4 -0
  144. package/dist/mcp/server.js +63 -9
  145. package/dist/mcp/server.js.map +1 -1
  146. package/dist/mcp/tools.d.ts +4 -1
  147. package/dist/mcp/tools.js +76 -27
  148. package/dist/mcp/tools.js.map +1 -1
  149. package/dist/mcp/types.d.ts +1 -0
  150. package/dist/mcp/types.js.map +1 -1
  151. package/dist/merchant/application/actor.d.ts +2 -0
  152. package/dist/merchant/application/actor.js +6 -0
  153. package/dist/merchant/application/actor.js.map +1 -1
  154. package/dist/merchant/negotiation-ops.d.ts +2 -0
  155. package/dist/merchant/negotiation-ops.js +4 -0
  156. package/dist/merchant/negotiation-ops.js.map +1 -1
  157. package/dist/merchant/weixin-channel.d.ts +68 -0
  158. package/dist/merchant/weixin-channel.js +313 -0
  159. package/dist/merchant/weixin-channel.js.map +1 -0
  160. package/dist/merchant/workbench-server.js +13 -0
  161. package/dist/merchant/workbench-server.js.map +1 -1
  162. package/dist/merchant-core/collection/alipay-store.d.ts +22 -0
  163. package/dist/merchant-core/collection/alipay-store.js +125 -0
  164. package/dist/merchant-core/collection/alipay-store.js.map +1 -0
  165. package/dist/merchant-core/commercial/calculate.js +6 -6
  166. package/dist/merchant-core/commercial/calculate.js.map +1 -1
  167. package/dist/merchant-core/operating/repository.d.ts +0 -1
  168. package/dist/merchant-core/operating/repository.js +2 -17
  169. package/dist/merchant-core/operating/repository.js.map +1 -1
  170. package/dist/merchant-core/opportunity/repository.d.ts +0 -1
  171. package/dist/merchant-core/opportunity/repository.js +2 -17
  172. package/dist/merchant-core/opportunity/repository.js.map +1 -1
  173. package/dist/merchant-core/orders/model.d.ts +1 -8
  174. package/dist/merchant-core/orders/model.js +10 -2
  175. package/dist/merchant-core/orders/model.js.map +1 -1
  176. package/dist/merchant-core/orders/repository.d.ts +0 -1
  177. package/dist/merchant-core/orders/repository.js +3 -18
  178. package/dist/merchant-core/orders/repository.js.map +1 -1
  179. package/dist/merchant-core/orders/service.js +34 -8
  180. package/dist/merchant-core/orders/service.js.map +1 -1
  181. package/dist/merchant-core/proposal/engine.js +2 -0
  182. package/dist/merchant-core/proposal/engine.js.map +1 -1
  183. package/dist/merchant-core/proposal/publish.d.ts +0 -6
  184. package/dist/merchant-core/proposal/publish.js +37 -3
  185. package/dist/merchant-core/proposal/publish.js.map +1 -1
  186. package/dist/merchant-core/proposal/repository.d.ts +0 -7
  187. package/dist/merchant-core/proposal/repository.js +8 -17
  188. package/dist/merchant-core/proposal/repository.js.map +1 -1
  189. package/dist/merchant-core/proposal/types.d.ts +1 -0
  190. package/dist/merchant-core/proposal/types.js.map +1 -1
  191. package/dist/merchant-core/rfq/policy.d.ts +1 -0
  192. package/dist/merchant-core/rfq/policy.js +6 -7
  193. package/dist/merchant-core/rfq/policy.js.map +1 -1
  194. package/dist/merchant-core/rfq/repository.d.ts +0 -1
  195. package/dist/merchant-core/rfq/repository.js +2 -17
  196. package/dist/merchant-core/rfq/repository.js.map +1 -1
  197. package/dist/merchant-core/rfq/service.d.ts +2 -1
  198. package/dist/merchant-core/rfq/service.js +2 -4
  199. package/dist/merchant-core/rfq/service.js.map +1 -1
  200. package/dist/merchant-core/storage/transaction.d.ts +4 -11
  201. package/dist/merchant-core/storage/transaction.js +43 -65
  202. package/dist/merchant-core/storage/transaction.js.map +1 -1
  203. package/dist/negotiation/domain/objects.d.ts +2 -0
  204. package/dist/negotiation/domain/objects.js +3 -0
  205. package/dist/negotiation/domain/objects.js.map +1 -1
  206. package/dist/negotiation/ledger/store.d.ts +4 -0
  207. package/dist/negotiation/ledger/store.js +20 -0
  208. package/dist/negotiation/ledger/store.js.map +1 -1
  209. package/dist/product-init.d.ts +1 -0
  210. package/dist/product-init.js +4 -1
  211. package/dist/product-init.js.map +1 -1
  212. package/dist/trust/identity/message-signature.d.ts +1 -1
  213. package/dist/trust/identity/message-signature.js +6 -1
  214. package/dist/trust/identity/message-signature.js.map +1 -1
  215. package/dist/trust/identity/nonce.d.ts +5 -0
  216. package/dist/trust/identity/nonce.js +2 -0
  217. package/dist/trust/identity/nonce.js.map +1 -1
  218. package/dist/weixin/ilink-client.d.ts +3 -2
  219. package/dist/weixin/ilink-client.js +9 -2
  220. package/dist/weixin/ilink-client.js.map +1 -1
  221. package/package.json +2 -2
@@ -0,0 +1 @@
1
+ {"version":3,"file":"alipay-native-view.js","sourceRoot":"","sources":["../../src/agent/alipay-native-view.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAExE,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAoC,MAAM,oCAAoC,CAAC;AAmB3G,MAAM,OAAO,gCAAiC,SAAQ,KAAK;IACpC;IAArB,YAAqB,iBAAqC;QACxD,KAAK,CAAC,yBAAyB,CAAC,CAAC;QADd,sBAAiB,GAAjB,iBAAiB,CAAoB;IAE1D,CAAC;CACF;AAED,MAAM,UAAU,wBAAwB,CAAC,QAA4B,EAAE,MAAuC;IAC5G,MAAM,WAAW,GAAG,iBAAiB,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,gBAAgB,EAAE,GAAG,GAAG,IAAI,EAAE,CAAC,CAAC;IACzF,OAAO,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,EAAE,EAAE;QAC1D,MAAM,GAAG,GAAG,mBAAmB,CAAC,GAAG,MAAM,GAAG,mBAAmB,EAAE,EAAE,EAAE,CAAC,CA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B,CAAC,GAAW;IACrC,MAAM,OAAO,GAAG,OAAO,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,mBAAmB,CAAC;IACtF,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,QAAQ,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC,CAAC,CAAC;IAC/H,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -15,6 +15,8 @@
15
15
  */
16
16
  import type { KiwiTool } from "../kiwi-tool.js";
17
17
  import { HandoffIdempotencyStore, HandoffEventStore } from "../../handoff/index.js";
18
+ import { type AlipayCollectionLink, type AlipayCollectionTerms } from "../../handoff/alipay-collection.js";
19
+ import type { A2AOutboundSignerLike } from "../../a2a/signing-key.js";
18
20
  import type { AgentProfile } from "../../config/profile.js";
19
21
  import type { CommerceClient } from "../../commerce/types.js";
20
22
  import type { KiwiCatalogSource } from "../../discovery/catalog-source/index.js";
@@ -25,6 +27,7 @@ import type { CredentialBroker } from "../merchant/credential-broker.js";
25
27
  import { type WriteGateDeps } from "../write-gate.js";
26
28
  import { type BuyerTaskStore } from "./task-store.js";
27
29
  import type { SupplierRelationshipStore } from "../supplier/store.js";
30
+ import type { TaskEvent } from "./types.js";
28
31
  type Tool = KiwiTool;
29
32
  export interface BuyerToolDeps {
30
33
  store: BuyerTaskStore;
@@ -71,6 +74,10 @@ export interface BuyerToolDeps {
71
74
  ledger: HandoffEventStore;
72
75
  idempotency: HandoffIdempotencyStore;
73
76
  };
77
+ /** Native host assertion: independent buyer signer AND dedicated private display. Never a tool input. */
78
+ alipayCollectionAvailable?: boolean;
79
+ /** Trusted host signer; when absent, negotiation resolves its native env signer. */
80
+ outboundSigner?: A2AOutboundSignerLike;
74
81
  /**
75
82
  * 供应商关系存储(pull-relationship 设计 v0.1 §13 M0;kernel 注入)。提供时
76
83
  * RFQ 成功后写 `supplier_save_suggested` 本地建议事件;缺失时不建议。
@@ -78,5 +85,18 @@ export interface BuyerToolDeps {
78
85
  */
79
86
  supplierStore?: SupplierRelationshipStore;
80
87
  }
88
+ /** Human-only local action: stop resuming without sending anything to the merchant. */
89
+ export declare function abandonMerchantApprovalResume(store: BuyerTaskStore, taskId: string): boolean;
81
90
  export declare function buildBuyerTools(deps: BuyerToolDeps): Tool[];
91
+ type TaskAlipayCollection = {
92
+ kind: "ordinary" | "invalid" | "expired";
93
+ } | {
94
+ kind: "collection";
95
+ link: AlipayCollectionLink;
96
+ metadata: AlipayCollectionTerms;
97
+ agreementId: string;
98
+ termsDigest: string;
99
+ };
100
+ /** Derive the collection only from the accepted KNP snapshot in the owned task. */
101
+ export declare function resolveTaskAlipayCollection(events: readonly TaskEvent[], nowMs: number): TaskAlipayCollection;
82
102
  export {};
@@ -23,20 +23,29 @@ import { fenceModelPayload } from "../context/fencing.js";
23
23
  import { HandoffIdempotencyStore, HandoffEventStore, createHandoffCandidate, executeHandoff, validateDestination, validateExternalDestinationUrl, } from "../../handoff/index.js";
24
24
  import { buildMarketplaceSourceBinding, MarketplaceLaunchPolicyError, parseMarketplaceTradeUrl, sameMarketplaceTarget, } from "../../handoff/launch-marketplace-policy.js";
25
25
  import { isUrlDestinationType } from "../../handoff/destination.js";
26
+ import { ALIPAY_COLLECTION_NOTICE, ALIPAY_PRIVATE_DISPLAY_REQUIRED, isAlipayCollectionAgreement, isAlipayCollectionDestination, parseAlipayCollectionLink, parseAlipayCollectionTerms, } from "../../handoff/alipay-collection.js";
26
27
  import { CatalogSourceError } from "../../discovery/catalog-source/errors.js";
27
28
  import { CommerceError } from "../../commerce/data-source.js";
28
29
  import { toMinorUnits as losslessToMinorUnits } from "../../protocol/legacy-shopping-negotiation/money.js";
29
30
  import { contentDigest } from "../../negotiation/jcs.js";
31
+ import { VaultKeyError } from "../memory/vault.js";
30
32
  import { requireScopeCredential } from "../merchant/credential-broker.js";
31
- import { NEGOTIATE_DEAL_PRICE_MINOR, defaultNegotiateDeliveryBefore, NEGOTIATE_SKU, negotiateWithAgent, summarizeNegotiation, } from "../../a2a/negotiate.js";
33
+ import { NEGOTIATE_DEAL_PRICE_MINOR, NEGOTIATE_SKU, negotiateWithAgent, summarizeNegotiation, } from "../../a2a/negotiate.js";
32
34
  import { buildNegotiationChatTools, writeGateText } from "../negotiation-chat.js";
33
- import { routeWriteCandidate } from "../write-gate.js";
35
+ import { APPROVAL_TTL_MS, routeWriteCandidate } from "../write-gate.js";
34
36
  import { runSearchCycle } from "./search-loop.js";
35
37
  import { assertTrackingRuleType } from "./task-store.js";
36
38
  import { BuyerTaskError } from "./types.js";
37
39
  function textResult(text, details) {
38
40
  return { content: [{ type: "text", text }], details };
39
41
  }
42
+ function alipayDeliveryResult(status, handoffId, negotiationId) {
43
+ const prefix = status === "delivered" ? "支付宝交接已记录" : "该支付宝协议已交付,未重复交接";
44
+ return {
45
+ ok: true, status, handoff_id: handoffId, negotiation_id: negotiationId,
46
+ text: `${prefix};请在原生终端输入 /alipay ${handoffId} ${negotiationId} 查看。${ALIPAY_COLLECTION_NOTICE}`,
47
+ };
48
+ }
40
49
  function errorText(err) {
41
50
  if (err instanceof BuyerTaskError)
42
51
  return `任务操作被拒绝(${err.code}):${err.message}`;
@@ -220,6 +229,27 @@ const NEGOTIABLE_TASK_STATUSES = new Set([
220
229
  "shortlist_ready",
221
230
  "awaiting_user",
222
231
  ]);
232
+ function pendingMerchantApproval(store, taskId) {
233
+ // Resume data comes from the merchant channel with an independent buyer signer, never a tool parameter.
234
+ const events = store.taskEvents(taskId);
235
+ const pending = [...events].reverse().find((event) => event.type === "a2a_negotiated" && event.payload.merchant_approval_resume !== undefined);
236
+ const resume = pending?.payload.merchant_approval_resume;
237
+ return resume !== undefined && !events.some((event) => event.type === "merchant_approval_resume_closed" &&
238
+ event.payload.negotiation_id === resume.negotiationId) ? resume : undefined;
239
+ }
240
+ function closeMerchantApprovalResume(store, taskId, negotiationId, reason, origin) {
241
+ return store.appendEvent(taskId, "merchant_approval_resume_closed", {
242
+ negotiation_id: negotiationId, reason,
243
+ }, origin, `a2a-neg:${taskId}:${negotiationId}:merchant-approval-closed`);
244
+ }
245
+ /** Human-only local action: stop resuming without sending anything to the merchant. */
246
+ export function abandonMerchantApprovalResume(store, taskId) {
247
+ const task = store.getTask(taskId);
248
+ if (task === undefined || !NEGOTIABLE_TASK_STATUSES.has(task.status))
249
+ return false;
250
+ const resume = pendingMerchantApproval(store, taskId);
251
+ return resume !== undefined && closeMerchantApprovalResume(store, taskId, resume.negotiationId, "abandoned", "user");
252
+ }
223
253
  /** 磋商前置快照(审批候选 + 执行前重读用,§16)。 */
224
254
  function negotiationPreconditions(store, catalogConfigured, taskId) {
225
255
  const task = store.getTask(taskId);
@@ -227,6 +257,7 @@ function negotiationPreconditions(store, catalogConfigured, taskId) {
227
257
  task_status: task?.status ?? null,
228
258
  task_version: task?.version ?? null,
229
259
  catalog_configured: catalogConfigured,
260
+ merchant_pending_negotiation_id: pendingMerchantApproval(store, taskId)?.negotiationId ?? null,
230
261
  };
231
262
  }
232
263
  /**
@@ -255,8 +286,24 @@ async function executeNegotiateBuyerTask(deps, args) {
255
286
  .listCandidates(a.task_id)
256
287
  .find((c) => c.candidate_status === "shortlisted" || c.candidate_status === "selected")?.sku;
257
288
  const sku = candidateSku ?? intent.category ?? intent.query_text ?? NEGOTIATE_SKU;
289
+ const resume = pendingMerchantApproval(store, a.task_id);
290
+ let maxTotal;
291
+ try {
292
+ maxTotal = store.resolveBudget(task.constraints);
293
+ if (maxTotal === undefined && task.constraints.max_total_price_vault_ref !== undefined) {
294
+ throw new BuyerTaskError("validation", "invalid vaulted budget");
295
+ }
296
+ }
297
+ catch (error) {
298
+ const code = error instanceof BuyerTaskError ? error.code
299
+ : error instanceof VaultKeyError ? "vault_decryption_failed" : "vault_unavailable";
300
+ throw new BuyerTaskError(code, `无法读取任务的私有总预算(${code});未发送磋商请求`);
301
+ }
258
302
  const result = await negotiateWithAgent({
259
303
  catalog: deps.catalog,
304
+ allowMerchantApprovalResume: true,
305
+ alipayCollectionAvailable: deps.alipayCollectionAvailable === true,
306
+ ...(resume === undefined ? {} : { resume }),
260
307
  allowLoopback: deps.allowLoopback === true,
261
308
  // CD #27:listing → owner_agent_id → getRecord → fresh verify 全链,
262
309
  // 与 search_listings 同一注入源(历史教训:只注入 search 面不注入磋商面)。
@@ -274,26 +321,47 @@ async function executeNegotiateBuyerTask(deps, args) {
274
321
  return converted.lossless ? converted.amount_minor : NEGOTIATE_DEAL_PRICE_MINOR;
275
322
  })()
276
323
  : NEGOTIATE_DEAL_PRICE_MINOR,
277
- deliveryBefore: intent.needed_by ?? defaultNegotiateDeliveryBefore(),
324
+ ...(intent.needed_by !== undefined ? { deliveryBefore: intent.needed_by } : {}),
278
325
  senderIdentity: deps.profile.agent_id,
279
- // 预算硬约束(单价上限):成交价超此值即拒绝。优先 constraints.max_unit_price;
280
- // 只有总预算时按数量折算单价。
281
- maxPriceMinor: (() => {
282
- const perUnit = task.constraints.max_unit_price;
283
- if (perUnit !== undefined && Number.isFinite(perUnit) && perUnit > 0) {
284
- const c = losslessToMinorUnits(perUnit, 2);
285
- return c.lossless ? c.amount_minor : undefined;
286
- }
287
- const total = task.constraints.max_total_price;
288
- const qty = intent.quantity ?? 1;
289
- if (total !== undefined && Number.isFinite(total) && qty > 0) {
290
- const c = losslessToMinorUnits(total / qty, 2);
291
- return c.lossless ? c.amount_minor : undefined;
292
- }
293
- return undefined;
294
- })(),
326
+ ...(deps.outboundSigner !== undefined ? { outboundSigner: deps.outboundSigner } : {}),
327
+ // Convert the private limits separately; the negotiator enforces both before AcceptNonbinding.
328
+ // An unrepresentable explicit budget is rejected, not ignored in favor of a default.
329
+ ...(task.constraints.max_unit_price === undefined ? {} : {
330
+ maxPriceMinor: losslessToMinorUnits(task.constraints.max_unit_price, 2).amount_minor,
331
+ }),
332
+ ...(maxTotal === undefined ? {} : { maxTotalMinor: losslessToMinorUnits(maxTotal, 2).amount_minor }),
295
333
  });
296
334
  const eventKey = `a2a-neg:${a.task_id}:${result.negotiationId}`;
335
+ if (result.merchantApprovalResume !== undefined) {
336
+ store.appendEvent(a.task_id, "a2a_negotiated", {
337
+ ok: false,
338
+ negotiation_id: result.negotiationId,
339
+ catalog_agent_id: result.catalogAgentId,
340
+ merchant_approval_resume: result.merchantApprovalResume,
341
+ }, "model", `${eventKey}:merchant-approval`);
342
+ return {
343
+ ok: true,
344
+ status: "merchant_approval_pending",
345
+ task_id: a.task_id,
346
+ negotiation_id: result.negotiationId,
347
+ text: `商家需要人工确认本次报价。商家确认后,请使用同一任务继续磋商;请勿自动反复重试。如需改价或换商家,可在终端输入 /abandon-quote ${a.task_id}。`,
348
+ };
349
+ }
350
+ const resolution = result.merchantApprovalResolution;
351
+ if (resume !== undefined && resolution !== undefined) {
352
+ closeMerchantApprovalResume(store, a.task_id, resume.negotiationId, resolution, "model");
353
+ }
354
+ if (resolution !== undefined && resolution !== "quoted") {
355
+ const notice = {
356
+ rejected: "商家已拒绝上一轮报价",
357
+ expired: "上一轮报价的商家审批已过期",
358
+ consumed: "上一轮报价的商家授权已使用,无法再次续接",
359
+ }[resolution];
360
+ return {
361
+ ok: true, status: `merchant_approval_${resolution}`, task_id: a.task_id, negotiation_id: result.negotiationId,
362
+ text: `${notice}。未重新提交,也未达成协议;如需重新报价,请先与用户确认,再用同一任务发起新磋商。`,
363
+ };
364
+ }
297
365
  if (!result.ok) {
298
366
  store.appendEvent(a.task_id, "a2a_negotiated", {
299
367
  ok: false,
@@ -343,10 +411,14 @@ async function executeNegotiateBuyerTask(deps, args) {
343
411
  negotiation_id: result.negotiationId,
344
412
  agreement_id: result.agreement?.agreement_id ?? null,
345
413
  deal_price_minor: facts?.dealPriceMinor ?? null,
414
+ ...(facts?.payableTotalMinor === undefined ? {} : { payable_total_minor: facts.payableTotalMinor }),
346
415
  // v0.7.0 KTH:agreement 快照落任务记录——handoff_agreement 的
347
416
  // agreementReader 以此做 pre-execution revalidation(§10)。
348
417
  agreed_terms: result.agreement?.agreed_terms ?? null,
349
418
  terms_digest: result.agreement?.terms_digest ?? null,
419
+ accepted_offer_id: result.agreement?.accepted_offer_id ?? null,
420
+ handoff_destination: result.agreement?.handoff_destination ?? null,
421
+ accepted_channel_url: result.acceptedChannelUrl ?? null,
350
422
  merchant_identity_ref: `merchant:${result.catalogAgentId}`,
351
423
  },
352
424
  origin: "model",
@@ -363,6 +435,7 @@ async function executeNegotiateBuyerTask(deps, args) {
363
435
  quantity: facts?.quantity ?? intent.quantity ?? 1,
364
436
  offer_price_minor: facts?.offerPriceMinor ?? null,
365
437
  deal_price_minor: facts?.dealPriceMinor ?? null,
438
+ ...(facts?.payableTotalMinor === undefined ? {} : { payable_total_minor: facts.payableTotalMinor }),
366
439
  delivery_before: facts?.deliveryBefore ?? null,
367
440
  agreement_id: result.agreement?.agreement_id ?? null,
368
441
  steps: result.steps,
@@ -1061,7 +1134,8 @@ export function buildBuyerTools(deps) {
1061
1134
  "SKU/数量/目标单价/交期取自任务 intent(category 或 query_text 视为 SKU)。" +
1062
1135
  "结果是非绑定协议(不创建订单、不锁库存、不授权支付)。写操作:supervised 模式" +
1063
1136
  "需 /approve 批准后才真正发送消息;任务须处于 ready/tracking/shortlist_ready/awaiting_user。" +
1064
- "达成协议后任务进入 selected_nonbinding。",
1137
+ "达成协议后任务进入 selected_nonbinding。原生签名终端若收到 merchant_approval_pending," +
1138
+ "在商家确认后用同一 task_id 继续;不得换商家或自动轮询。",
1065
1139
  parameters: {
1066
1140
  type: "object",
1067
1141
  properties: {
@@ -1146,7 +1220,8 @@ export function buildBuyerTools(deps) {
1146
1220
  "目的地**只取商家在协议里直传的成交入口**(merchant 从 shopping-cli 读的 handoff_destination)," +
1147
1221
  "不允许 LLM 自编、也不读 catalog 投影——协议未带成交入口则拒绝交接。" +
1148
1222
  "经审批门(supervised 需 /approve)后执行:重验 agreement/terms/destination/expiry," +
1149
- "安全交付到 external checkout URL。不创建订单、不授权支付、不预留库存。",
1223
+ "安全交付到 external checkout URL。不创建订单、不授权支付、不预留库存。" +
1224
+ "支付宝收款必须由具备私有显示能力的原生终端人工批准,只传 task_id;请勿覆盖收款摘要、有效期或目的地。",
1150
1225
  parameters: {
1151
1226
  type: "object",
1152
1227
  properties: {
@@ -1184,9 +1259,22 @@ export function buildBuyerTools(deps) {
1184
1259
  if (agreement === undefined) {
1185
1260
  return textResult("任务记录缺少 agreement 快照(磋商未完成或 terms 未持久化)。");
1186
1261
  }
1187
- // 成交入口**只取商家在协议里直传的** handoff_destination——不经 catalog、
1188
- // 不允许 LLM 现编。协议未携带则拒绝交接(fail-closed)。
1189
- const agreementDestination = agreementDestinationFromTerms(agreement.agreed_terms);
1262
+ const collection = resolveAlipayCollection(agreement, Date.parse(deps.now()));
1263
+ if (collection.kind !== "ordinary") {
1264
+ if (deps.alipayCollectionAvailable !== true || deps.registerPending === undefined) {
1265
+ return textResult(ALIPAY_PRIVATE_DISPLAY_REQUIRED, { status: "authorization_denied" });
1266
+ }
1267
+ if (Object.keys(p).some((key) => key !== "task_id")) {
1268
+ return textResult("支付宝交接仅接受 task_id;不得覆盖商家声明的目的地、收款摘要或有效期。", { status: "invalid_params" });
1269
+ }
1270
+ if (collection.kind !== "collection") {
1271
+ return textResult(collection.kind === "expired" ? "支付宝收款指引已过期。" : "支付宝收款指引未绑定同源的签名磋商与已接受协议。", { status: collection.kind });
1272
+ }
1273
+ }
1274
+ // Use the exact merchant declaration; never derive a collection from model input.
1275
+ const agreementDestination = collection.kind === "collection"
1276
+ ? { type: "external_checkout_url", ref: collection.link.url }
1277
+ : agreementDestinationFromTerms(agreement.agreed_terms);
1190
1278
  if (agreementDestination === undefined) {
1191
1279
  return textResult("商家未在协议中声明成交入口(handoff_destination),无法交接。");
1192
1280
  }
@@ -1200,6 +1288,14 @@ export function buildBuyerTools(deps) {
1200
1288
  e.destination?.ref === destination.ref &&
1201
1289
  e.destination?.type === destination.type);
1202
1290
  if (priorDelivery !== undefined) {
1291
+ if (collection.kind === "collection") {
1292
+ const handoffId = priorDelivery.handoff_id;
1293
+ if (handoffId === undefined) {
1294
+ return textResult("该支付宝协议已交付过,但缺少交接 ID;请核对本机交接记录。", { status: "already_delivered" });
1295
+ }
1296
+ const result = alipayDeliveryResult("already_delivered", handoffId, collection.link.negotiationId);
1297
+ return textResult(result.text, result);
1298
+ }
1203
1299
  return textResult(`该协议已交付过(handoff ${priorDelivery.handoff_id ?? "unknown"},` +
1204
1300
  `目的地 ${destination.type} ${destination.ref}),同一目的地不重复交接。`);
1205
1301
  }
@@ -1228,6 +1324,12 @@ export function buildBuyerTools(deps) {
1228
1324
  const lastStale = [...handoff.ledger.events(agreement.negotiation_id).map((event) => handoff.ledger.resolvePayload(event))]
1229
1325
  .reverse()
1230
1326
  .find((e) => e.event_kind === "handoff_candidate_stale");
1327
+ const now = deps.now();
1328
+ const nowMs = Date.parse(now);
1329
+ const expiresAtMs = collection.kind === "collection"
1330
+ ? Math.min(nowMs + expiresInHours * 3_600_000, Date.parse(collection.metadata.expires_at))
1331
+ : nowMs + expiresInHours * 3_600_000;
1332
+ const collectionSummary = collection.kind === "collection" ? alipayDisplaySummary(collection.metadata) : undefined;
1231
1333
  const candidate = createHandoffCandidate({
1232
1334
  agreement_id: agreement.agreement_id,
1233
1335
  negotiation_id: agreement.negotiation_id,
@@ -1236,14 +1338,14 @@ export function buildBuyerTools(deps) {
1236
1338
  merchant_identity_ref: agreement.merchant_identity_ref,
1237
1339
  destination: { type: destination.type, ref: destination.ref },
1238
1340
  display_summary: {
1239
- merchant: p.display_summary_merchant ?? agreement.merchant_identity_ref,
1240
- summary: p.display_summary_text ?? `negotiation ${agreement.negotiation_id}`,
1341
+ merchant: collection.kind === "collection" ? agreement.merchant_identity_ref : (p.display_summary_merchant ?? agreement.merchant_identity_ref),
1342
+ summary: collectionSummary ?? p.display_summary_text ?? `negotiation ${agreement.negotiation_id}`,
1241
1343
  },
1242
1344
  policy_version: "handoff-policy/1",
1243
1345
  // 时钟统一用注入的 deps.now()(此前 created_at 走墙钟、事件走注入时钟,
1244
1346
  // time_to_handoff 指标掺入偏差)。
1245
- created_at: deps.now(),
1246
- expires_at: new Date(Date.parse(deps.now()) + expiresInHours * 3_600_000).toISOString(),
1347
+ created_at: now,
1348
+ expires_at: new Date(expiresAtMs).toISOString(),
1247
1349
  ...(lastStale?.handoff_candidate_id !== undefined
1248
1350
  ? { supersedes_candidate_id: lastStale.handoff_candidate_id }
1249
1351
  : {}),
@@ -1294,6 +1396,10 @@ export function buildBuyerTools(deps) {
1294
1396
  },
1295
1397
  preconditions: { agreement_bound: true },
1296
1398
  risk: "handoff_delivery",
1399
+ ...(collection.kind === "collection" ? {
1400
+ force_pending: true,
1401
+ ttl_ms: Math.min(APPROVAL_TTL_MS, expiresAtMs - nowMs),
1402
+ } : {}),
1297
1403
  execute: (approvedArgs) => executeHandoffForCandidate(deps, approvedArgs),
1298
1404
  // §16 stale 检测的真实重读:approval 与执行之间协议被重磋商改写
1299
1405
  //(agreement 消失 / 身份变化 / terms_digest 不匹配)→ 候选 supersede。
@@ -1305,6 +1411,12 @@ export function buildBuyerTools(deps) {
1305
1411
  current.agreement_id === agreement.agreement_id &&
1306
1412
  current.negotiation_id === agreement.negotiation_id &&
1307
1413
  contentDigest(current.agreed_terms) === candidate.terms_digest;
1414
+ if (collection.kind === "collection") {
1415
+ const fresh = resolveAlipayCollection(current, Date.parse(deps.now()));
1416
+ return { agreement_bound: stillBound && fresh.kind === "collection" &&
1417
+ fresh.link.url === collection.link.url && deps.alipayCollectionAvailable === true &&
1418
+ deps.store.getTask(p.task_id)?.status === "selected_nonbinding" };
1419
+ }
1308
1420
  return { agreement_bound: stillBound };
1309
1421
  },
1310
1422
  // autopilot 政策闸:handoff 把买家送向真实成交入口(外部结账/PO/联系
@@ -1316,7 +1428,11 @@ export function buildBuyerTools(deps) {
1316
1428
  ? "buyer 未授权自动交接(auto_negotiate=false),需要人工确认。"
1317
1429
  : "handoff 交付默认需要人工确认;如确需自动执行,请在 profile 设置 buyer_policy.auto_handoff: true。",
1318
1430
  });
1319
- return writeGateText(outcome);
1431
+ const rendered = writeGateText(outcome);
1432
+ if (collectionSummary !== undefined && (outcome.kind === "pending_approval" || outcome.kind === "advice_only")) {
1433
+ return textResult(`商家 ${agreement.merchant_identity_ref};${collectionSummary}\n${rendered.content[0]?.type === "text" ? rendered.content[0].text : ""}`, rendered.details);
1434
+ }
1435
+ return rendered;
1320
1436
  }
1321
1437
  catch (err) {
1322
1438
  return textResult(errorText(err));
@@ -1750,10 +1866,48 @@ function agreementFromTask(events) {
1750
1866
  ? payload.merchant_identity_ref
1751
1867
  : "merchant:unknown",
1752
1868
  ...(merchantDomain !== undefined ? { merchant_domain: merchantDomain } : {}),
1869
+ ...(typeof payload.accepted_offer_id === "string" ? { accepted_offer_id: payload.accepted_offer_id } : {}),
1870
+ handoff_destination: payload.handoff_destination,
1871
+ ...(typeof payload.accepted_channel_url === "string" ? { accepted_channel_url: payload.accepted_channel_url } : {}),
1872
+ ...(typeof payload.terms_digest === "string" ? { terms_digest: payload.terms_digest } : {}),
1753
1873
  };
1754
1874
  }
1755
1875
  return undefined;
1756
1876
  }
1877
+ /** Derive the collection only from the accepted KNP snapshot in the owned task. */
1878
+ export function resolveTaskAlipayCollection(events, nowMs) {
1879
+ return resolveAlipayCollection(agreementFromTask(events), nowMs);
1880
+ }
1881
+ function resolveAlipayCollection(agreement, nowMs) {
1882
+ if (agreement === undefined || !isAlipayCollectionAgreement(agreement.agreed_terms, agreement.handoff_destination)) {
1883
+ return { kind: "ordinary" };
1884
+ }
1885
+ const terms = agreement.agreed_terms;
1886
+ const declared = agreement.handoff_destination;
1887
+ const link = typeof declared === "string" ? parseAlipayCollectionLink(declared) : null;
1888
+ const metadata = parseAlipayCollectionTerms(terms);
1889
+ if (link === null || metadata === null || declared !== terms?.handoff_destination ||
1890
+ link.negotiationId !== agreement.negotiation_id || link.offerId !== agreement.accepted_offer_id ||
1891
+ link.version !== metadata.version || agreement.terms_digest !== contentDigest(terms) ||
1892
+ agreement.accepted_channel_url === undefined || !Number.isFinite(nowMs))
1893
+ return { kind: "invalid" };
1894
+ try {
1895
+ const channel = new URL(agreement.accepted_channel_url);
1896
+ if (channel.origin !== link.origin || channel.username !== "" || channel.password !== "")
1897
+ return { kind: "invalid" };
1898
+ }
1899
+ catch {
1900
+ return { kind: "invalid" };
1901
+ }
1902
+ if (Date.parse(metadata.expires_at) <= nowMs)
1903
+ return { kind: "expired" };
1904
+ return { kind: "collection", link, metadata, agreementId: agreement.agreement_id, termsDigest: agreement.terms_digest };
1905
+ }
1906
+ function alipayDisplaySummary(metadata) {
1907
+ const whole = Math.floor(metadata.total_minor / 100);
1908
+ const fraction = String(metadata.total_minor % 100).padStart(2, "0");
1909
+ return `支付宝收款方 ${metadata.recipient_summary};金额 CNY ${whole}.${fraction};有效期 ${metadata.expires_at}。${ALIPAY_COLLECTION_NOTICE}`;
1910
+ }
1757
1911
  function handoffResultText(result) {
1758
1912
  switch (result.kind) {
1759
1913
  case "delivered": {
@@ -1800,6 +1954,18 @@ async function executeHandoffForCandidate(deps, args) {
1800
1954
  error: "任务记录缺少 agreement 快照,交接中止(fail-closed)",
1801
1955
  };
1802
1956
  }
1957
+ const collection = resolveAlipayCollection(agreement, Date.parse(deps.now()));
1958
+ const collectionLink = collection.kind === "collection" ? collection.link : undefined;
1959
+ if (collection.kind !== "ordinary" || isAlipayCollectionDestination(a.candidate.destination_ref)) {
1960
+ if (deps.alipayCollectionAvailable !== true || collectionLink === undefined ||
1961
+ deps.store.getTask(a.task_id)?.status !== "selected_nonbinding" ||
1962
+ a.candidate.agreement_id !== agreement.agreement_id || a.candidate.negotiation_id !== agreement.negotiation_id ||
1963
+ a.candidate.terms_digest !== agreement.terms_digest ||
1964
+ a.candidate.merchant_identity_ref !== agreement.merchant_identity_ref ||
1965
+ a.candidate.destination_type !== "external_checkout_url" || a.candidate.destination_ref !== collectionLink.url) {
1966
+ return { ok: false, status: "stale", error: "支付宝交接不再匹配当前协议、目的地或终端能力。" };
1967
+ }
1968
+ }
1803
1969
  // ── A651 包四:三平台市场形态 URL 目的地的强制交易门输入 ─────────────
1804
1970
  // 审批链带回的 sidecar + 执行期 configured CatalogSource 新鲜重读;市场
1805
1971
  // 形态目的地无 sidecar(或不配置来源)→ executeHandoff 固定
@@ -1879,30 +2045,57 @@ async function executeHandoffForCandidate(deps, args) {
1879
2045
  negotiation_id: agreement.negotiation_id,
1880
2046
  agreed_terms: agreement.agreed_terms,
1881
2047
  }),
1882
- urlSafety: (url) => validateExternalDestinationUrl(url, {
1883
- ...(agreement.merchant_domain !== undefined ? { expectedHost: agreement.merchant_domain } : {}),
1884
- ...(declaredHost !== undefined ? { allowlist: [declaredHost] } : {}),
1885
- allowHttp: false,
1886
- ...(launchTarget !== undefined
1887
- ? {
1888
- onHop: (hopUrl) => {
1889
- let parsed;
1890
- try {
1891
- parsed = parseMarketplaceTradeUrl(hopUrl);
1892
- }
1893
- catch {
1894
- throw new CommerceError("invalid_input", "destination hop left the marketplace trade form (same platform, same product id required)");
1895
- }
1896
- if (!sameMarketplaceTarget(parsed, launchTarget)) {
1897
- throw new CommerceError("invalid_input", "destination redirect changed platform product identity");
1898
- }
2048
+ urlSafety: async (url) => {
2049
+ if (collection.kind === "collection") {
2050
+ const safe = await validateExternalDestinationUrl(url, {
2051
+ expectedHost: new URL(collection.link.origin).hostname,
2052
+ maxRedirects: 0,
2053
+ onHop: (hop) => {
2054
+ if (hop !== collection.link.url)
2055
+ throw new CommerceError("invalid_input", "collection destination changed");
1899
2056
  },
2057
+ });
2058
+ const fresh = resolveTaskAlipayCollection(deps.store.taskEvents(a.task_id), Date.parse(deps.now()));
2059
+ if (safe.finalUrl !== collection.link.url || fresh.kind !== "collection" ||
2060
+ fresh.link.url !== collection.link.url || fresh.agreementId !== collection.agreementId ||
2061
+ fresh.termsDigest !== collection.termsDigest || deps.store.getTask(a.task_id)?.status !== "selected_nonbinding") {
2062
+ throw new CommerceError("invalid_input", "collection agreement no longer matches the approved destination");
1900
2063
  }
1901
- : {}),
1902
- }),
2064
+ return safe;
2065
+ }
2066
+ return validateExternalDestinationUrl(url, {
2067
+ ...(agreement.merchant_domain !== undefined ? { expectedHost: agreement.merchant_domain } : {}),
2068
+ ...(declaredHost !== undefined ? { allowlist: [declaredHost] } : {}),
2069
+ allowHttp: false,
2070
+ onHop: (hopUrl) => {
2071
+ if (isAlipayCollectionDestination(hopUrl)) {
2072
+ throw new CommerceError("invalid_input", "ordinary handoff cannot redirect to an Alipay collection destination");
2073
+ }
2074
+ if (launchTarget === undefined)
2075
+ return;
2076
+ let parsed;
2077
+ try {
2078
+ parsed = parseMarketplaceTradeUrl(hopUrl);
2079
+ }
2080
+ catch {
2081
+ throw new CommerceError("invalid_input", "destination hop left the marketplace trade form (same platform, same product id required)");
2082
+ }
2083
+ if (!sameMarketplaceTarget(parsed, launchTarget)) {
2084
+ throw new CommerceError("invalid_input", "destination redirect changed platform product identity");
2085
+ }
2086
+ },
2087
+ });
2088
+ },
1903
2089
  ...(launchContext !== undefined ? { launchContext } : {}),
1904
2090
  now: deps.now,
1905
2091
  });
2092
+ if (collection.kind === "collection") {
2093
+ if (result.kind === "delivered" || result.kind === "already_delivered") {
2094
+ const handoffId = result.kind === "delivered" ? result.handoff.handoff_id : result.handoff_id;
2095
+ return alipayDeliveryResult(result.kind, handoffId, collection.link.negotiationId);
2096
+ }
2097
+ return { ok: false, status: result.kind, text: "支付宝收款入口未交付;请重新核对协议及其有效期。" };
2098
+ }
1906
2099
  const rendered = handoffResultText(result);
1907
2100
  return {
1908
2101
  ok: result.kind === "delivered" || result.kind === "already_delivered",