@stelis/say-ur-intent 0.0.0 → 0.0.2

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 (234) hide show
  1. package/README.md +4 -39
  2. package/dist/adapters/adapterLifecycleValidators.js +7 -0
  3. package/dist/adapters/adapterPromptSurfaces.js +71 -0
  4. package/dist/adapters/deepbook/deepbookHumanReviewProducer.js +175 -0
  5. package/dist/adapters/deepbook/deepbookQuotePolicy.js +112 -0
  6. package/dist/adapters/deepbook/deepbookReviewEvidence.js +507 -0
  7. package/dist/adapters/deepbook/deepbookReviewLifecycle.js +85 -0
  8. package/dist/adapters/deepbook/deepbookSwapIntent.js +79 -0
  9. package/dist/adapters/deepbook/deepbookTransactionMaterialProducer.js +269 -0
  10. package/dist/adapters/flowx/flowxSwapHumanReviewProducer.js +176 -0
  11. package/dist/adapters/flowx/flowxSwapIntent.js +79 -0
  12. package/dist/adapters/flowx/flowxSwapQuotePolicy.js +104 -0
  13. package/dist/adapters/flowx/flowxSwapReviewEvidence.js +468 -0
  14. package/dist/adapters/flowx/flowxSwapReviewLifecycle.js +85 -0
  15. package/dist/adapters/flowx/flowxSwapTransactionMaterialProducer.js +362 -0
  16. package/dist/adapters/intentPlanFactories.js +59 -0
  17. package/dist/adapters/reviewAdapters.js +81 -0
  18. package/dist/core/action/adapterLifecycleValidation.js +12 -0
  19. package/dist/core/action/forbiddenFields.js +43 -0
  20. package/dist/core/action/humanReadableReviewEvidence.js +203 -0
  21. package/dist/core/action/humanReadableReviewProjectionVerifier.js +29 -0
  22. package/dist/core/action/ptbVisualizationProducer.js +66 -0
  23. package/dist/core/action/reviewCheckResults.js +6 -0
  24. package/dist/core/action/reviewStateValidation.js +11 -0
  25. package/dist/core/action/reviewTimeSimulationEvidence.js +471 -0
  26. package/dist/core/action/schemas.js +529 -0
  27. package/dist/core/action/signableAdapterContract.js +993 -0
  28. package/dist/core/action/swapHumanReadableReviewProjection.js +124 -0
  29. package/dist/core/action/swapQuotePolicyEvidence.js +278 -0
  30. package/dist/core/action/transactionObjectOwnershipEvidence.js +247 -0
  31. package/dist/core/action/transactionObjectOwnershipProducer.js +329 -0
  32. package/dist/core/action/types.js +35 -0
  33. package/dist/core/action/walletReviewContractAssembler.js +282 -0
  34. package/dist/core/activity/activityStore.js +15 -0
  35. package/dist/core/activity/localDataService.js +258 -0
  36. package/dist/core/activity/localDataTypes.js +11 -0
  37. package/dist/core/activity/localDataValidation.js +396 -0
  38. package/dist/core/activity/schemaVersion.js +1 -0
  39. package/dist/core/activity/sqliteActivityStore.js +820 -0
  40. package/dist/core/activity/sqliteActivityStoreRows.js +430 -0
  41. package/dist/core/activity/sqliteActivityStoreSchema.js +258 -0
  42. package/dist/core/activity/sqliteActivityStoreTypes.js +5 -0
  43. package/dist/core/activity/suiFunctionTarget.js +43 -0
  44. package/dist/core/activity/transactionActivityAccountEffects.js +189 -0
  45. package/dist/core/activity/transactionActivityAnalysis.js +295 -0
  46. package/dist/core/activity/transactionActivityClassifier.js +306 -0
  47. package/dist/core/activity/transactionActivityDetails.js +229 -0
  48. package/dist/core/activity/transactionActivityProtocolRules.js +218 -0
  49. package/dist/core/activity/transactionActivityScanPolicy.js +170 -0
  50. package/dist/core/activity/transactionActivityService.js +379 -0
  51. package/dist/core/activity/transactionActivityTypes.js +18 -0
  52. package/dist/core/eventlog/sink.js +35 -0
  53. package/dist/core/evidence/settlementFamilies.js +87 -0
  54. package/dist/core/evidence/userAnswerUse.js +1 -0
  55. package/dist/core/numeric/rawU64.js +63 -0
  56. package/dist/core/preferences/preferencesStore.js +26 -0
  57. package/dist/core/preferences/sqlitePreferencesRepository.js +136 -0
  58. package/dist/core/proposal/externalProposalReview.js +347 -0
  59. package/dist/core/proposal/schemas.js +208 -0
  60. package/dist/core/proposal/types.js +35 -0
  61. package/dist/core/read/amounts.js +14 -0
  62. package/dist/core/read/coinMetadata.js +60 -0
  63. package/dist/core/read/deepbookRawQuoteClient.js +86 -0
  64. package/dist/core/read/deepbookReadHelpers.js +265 -0
  65. package/dist/core/read/deepbookRegistry.js +133 -0
  66. package/dist/core/read/flowxQuoteClient.js +117 -0
  67. package/dist/core/read/flowxReadHelpers.js +145 -0
  68. package/dist/core/read/flowxRegistry.js +174 -0
  69. package/dist/core/read/intentEvidenceResponseFormatting.js +228 -0
  70. package/dist/core/read/readResponseGuidance.js +451 -0
  71. package/dist/core/read/readService.js +1164 -0
  72. package/dist/core/read/readServiceTypes.js +59 -0
  73. package/dist/core/read/settlementParityFormatting.js +82 -0
  74. package/dist/core/read/walletReadHelpers.js +99 -0
  75. package/dist/core/review/reviewChecks.js +54 -0
  76. package/dist/core/review/reviewComputation.js +38 -0
  77. package/dist/core/review/reviewComputationResult.js +87 -0
  78. package/dist/core/session/localSession.js +31 -0
  79. package/dist/core/session/privateReviewArtifacts.js +73 -0
  80. package/dist/core/session/sessionErrors.js +9 -0
  81. package/dist/core/session/sessionStore.js +821 -0
  82. package/dist/core/session/settingsSession.js +1 -0
  83. package/dist/core/session/settingsSessions.js +43 -0
  84. package/dist/core/session/status.js +86 -0
  85. package/dist/core/session/transactionMaterialStore.js +205 -0
  86. package/dist/core/session/wait.js +102 -0
  87. package/dist/core/session/walletIdentity.js +103 -0
  88. package/dist/core/session/walletIdentitySessions.js +189 -0
  89. package/dist/core/suiAddress.js +18 -0
  90. package/dist/core/suiEndpoint.js +72 -0
  91. package/dist/mcp/activeAccountResponse.js +24 -0
  92. package/dist/mcp/prompts.js +146 -0
  93. package/dist/mcp/registerTool.js +19 -0
  94. package/dist/mcp/resources.js +72 -0
  95. package/dist/mcp/responseGuidance.js +381 -0
  96. package/dist/mcp/result.js +17 -0
  97. package/dist/mcp/schemas.js +8 -0
  98. package/dist/mcp/server.js +30 -0
  99. package/dist/mcp/serverInfo.js +123 -0
  100. package/dist/mcp/toolErrors.js +105 -0
  101. package/dist/mcp/toolNames.js +50 -0
  102. package/dist/mcp/tools/account/index.js +44 -0
  103. package/dist/mcp/tools/action/prepareSuiActionReview.js +120 -0
  104. package/dist/mcp/tools/read/commonSchemas.js +43 -0
  105. package/dist/mcp/tools/read/deepbookReadTools.js +453 -0
  106. package/dist/mcp/tools/read/flowxReadTools.js +135 -0
  107. package/dist/mcp/tools/read/index.js +16 -0
  108. package/dist/mcp/tools/read/readToolHelpers.js +68 -0
  109. package/dist/mcp/tools/read/reviewActivityTools.js +176 -0
  110. package/dist/mcp/tools/read/serverStatusTools.js +103 -0
  111. package/dist/mcp/tools/read/transactionActivityOutput.js +300 -0
  112. package/dist/mcp/tools/read/transactionActivityTools.js +544 -0
  113. package/dist/mcp/tools/read/walletReadTools.js +733 -0
  114. package/dist/mcp/tools/session/executionResultTools.js +92 -0
  115. package/dist/mcp/tools/session/index.js +8 -0
  116. package/dist/mcp/tools/session/shared.js +79 -0
  117. package/dist/mcp/tools/session/statusTools.js +134 -0
  118. package/dist/mcp/tools/session/walletIdentityTools.js +119 -0
  119. package/dist/mcp/tools/settings/index.js +64 -0
  120. package/dist/review-app/analysis.css +1 -0
  121. package/dist/review-app/analysis.js +1 -0
  122. package/dist/review-app/arc-BjIacwQm.js +1 -0
  123. package/dist/review-app/architecture-U656AL7Q-aSB9x1OK.js +1 -0
  124. package/dist/review-app/architectureDiagram-VXUJARFQ-C5W6re2I.js +36 -0
  125. package/dist/review-app/array-BmXUUrU6.js +1 -0
  126. package/dist/review-app/blockDiagram-VD42YOAC-20MLNcUm.js +122 -0
  127. package/dist/review-app/c4Diagram-YG6GDRKO-BZXRrcck.js +10 -0
  128. package/dist/review-app/channel-lk2p_CUu.js +1 -0
  129. package/dist/review-app/chunk-4BX2VUAB-BPITOdjX.js +1 -0
  130. package/dist/review-app/chunk-55IACEB6-Dz-pyw5k.js +1 -0
  131. package/dist/review-app/chunk-76Q3JFCE-cK_X1P_l.js +1 -0
  132. package/dist/review-app/chunk-ABZYJK2D-Dt4W53JI.js +81 -0
  133. package/dist/review-app/chunk-ATLVNIR6-fZHLXURb.js +1 -0
  134. package/dist/review-app/chunk-B4BG7PRW-BbgcjusC.js +165 -0
  135. package/dist/review-app/chunk-BJD4TVEz.js +1 -0
  136. package/dist/review-app/chunk-CVBHYZKI-CViawAKX.js +1 -0
  137. package/dist/review-app/chunk-DI55MBZ5-C5aoul-d.js +220 -0
  138. package/dist/review-app/chunk-FMBD7UC4-Chxmw62A.js +15 -0
  139. package/dist/review-app/chunk-FPAJGGOC-DDHjQ09H.js +80 -0
  140. package/dist/review-app/chunk-FWNWRKHM-CVVQUptk.js +1 -0
  141. package/dist/review-app/chunk-HN2XXSSU-yzNpjaSZ.js +1 -0
  142. package/dist/review-app/chunk-JA3XYJ7Z-C5ZJdU01.js +70 -0
  143. package/dist/review-app/chunk-JZLCHNYA-BBST4Cnk.js +54 -0
  144. package/dist/review-app/chunk-LBM3YZW2-CdwAPuHr.js +1 -0
  145. package/dist/review-app/chunk-LHMN2FUI-BtB5uDcp.js +1 -0
  146. package/dist/review-app/chunk-O7ZBX7Z2-pxdK4Sa3.js +1 -0
  147. package/dist/review-app/chunk-QN33PNHL-CbVv3uGK.js +1 -0
  148. package/dist/review-app/chunk-QXUST7PY-DKM2-t2c.js +7 -0
  149. package/dist/review-app/chunk-QZHKN3VN-C5ni2pN_.js +1 -0
  150. package/dist/review-app/chunk-S3R3BYOJ-BWvOhDs0.js +2 -0
  151. package/dist/review-app/chunk-S6J4BHB3-D9Fk0YeD.js +1 -0
  152. package/dist/review-app/chunk-T53DSG4Q-C1qEyzyV.js +1 -0
  153. package/dist/review-app/chunk-TZMSLE5B-B--7eU69.js +1 -0
  154. package/dist/review-app/classDiagram-2ON5EDUG-DlL1m2bp.js +1 -0
  155. package/dist/review-app/classDiagram-v2-WZHVMYZB-FXRskT1j.js +1 -0
  156. package/dist/review-app/clone-BZZb7gpZ.js +1 -0
  157. package/dist/review-app/cose-bilkent-S5V4N54A-CRIb8XEO.js +1 -0
  158. package/dist/review-app/cytoscape.esm-C7jYqDP5.js +321 -0
  159. package/dist/review-app/dagre-6UL2VRFP-FNCAXbdE.js +4 -0
  160. package/dist/review-app/dagre-Be46QtUd.js +1 -0
  161. package/dist/review-app/defaultLocale-BaWNtAUL.js +1 -0
  162. package/dist/review-app/diagram-PSM6KHXK-ylLWjiNM.js +24 -0
  163. package/dist/review-app/diagram-QEK2KX5R-BCDcESxs.js +43 -0
  164. package/dist/review-app/diagram-S2PKOQOG-Vdrc-vrO.js +24 -0
  165. package/dist/review-app/dist-WPc74x_f.js +1 -0
  166. package/dist/review-app/erDiagram-Q2GNP2WA-E5ZsUbDF.js +60 -0
  167. package/dist/review-app/flatten-DHf9IeNI.js +1 -0
  168. package/dist/review-app/flowDiagram-NV44I4VS-DBSQuj6x.js +162 -0
  169. package/dist/review-app/ganttDiagram-LVOFAZNH-CKUOsqwl.js +267 -0
  170. package/dist/review-app/gitGraph-F6HP7TQM-DsAD6qK1.js +1 -0
  171. package/dist/review-app/gitGraphDiagram-NY62KEGX-BCeIMWdl.js +65 -0
  172. package/dist/review-app/graphlib-CiX5CXxR.js +1 -0
  173. package/dist/review-app/http-DMvwuuFk.js +1 -0
  174. package/dist/review-app/identity-DY8PXc6t.js +1 -0
  175. package/dist/review-app/info-NVLQJR56-Dlx1nZic.js +1 -0
  176. package/dist/review-app/infoDiagram-F6ZHWCRC-CAuANIrz.js +2 -0
  177. package/dist/review-app/init-BvqephKz.js +1 -0
  178. package/dist/review-app/journeyDiagram-XKPGCS4Q-C-Z9phnx.js +139 -0
  179. package/dist/review-app/kanban-definition-3W4ZIXB7-DufgZABq.js +89 -0
  180. package/dist/review-app/katex-B-Z-NXXN.js +257 -0
  181. package/dist/review-app/line-DiIv3Jgw.js +1 -0
  182. package/dist/review-app/linear-Cv-UPvo1.js +1 -0
  183. package/dist/review-app/math-kmyYrkHL.js +1 -0
  184. package/dist/review-app/mermaid-parser.core-DkwUYTPl.js +4 -0
  185. package/dist/review-app/mindmap-definition-VGOIOE7T-TM_CqdmV.js +68 -0
  186. package/dist/review-app/ordinal-BliTlkoG.js +1 -0
  187. package/dist/review-app/packet-BFZMPI3H-DqbnU92v.js +1 -0
  188. package/dist/review-app/path-AEo9W6mQ.js +1 -0
  189. package/dist/review-app/pie-7BOR55EZ-LJzaLkgr.js +1 -0
  190. package/dist/review-app/pieDiagram-ADFJNKIX-BAs8OfRS.js +30 -0
  191. package/dist/review-app/quadrantDiagram-AYHSOK5B-CyUDZP5S.js +7 -0
  192. package/dist/review-app/radar-NHE76QYJ-DBpHc8_Y.js +1 -0
  193. package/dist/review-app/reduce-B-HuPpdd.js +1 -0
  194. package/dist/review-app/requirementDiagram-UZGBJVZJ-BEHix78P.js +64 -0
  195. package/dist/review-app/review.css +1 -0
  196. package/dist/review-app/review.js +43 -0
  197. package/dist/review-app/sankeyDiagram-TZEHDZUN-B2bKbmsm.js +10 -0
  198. package/dist/review-app/sequenceDiagram-WL72ISMW-DVLOORFJ.js +145 -0
  199. package/dist/review-app/settings.css +1 -0
  200. package/dist/review-app/settings.js +1 -0
  201. package/dist/review-app/src-Buml7cM5.js +1 -0
  202. package/dist/review-app/stateDiagram-FKZM4ZOC-sFGGp2kV.js +1 -0
  203. package/dist/review-app/stateDiagram-v2-4FDKWEC3-BHfCF4dX.js +1 -0
  204. package/dist/review-app/timeline-definition-IT6M3QCI-BESnBijC.js +61 -0
  205. package/dist/review-app/treemap-KMMF4GRG-wnVLBDeQ.js +1 -0
  206. package/dist/review-app/walletStatus-CcojOdGy.js +7 -0
  207. package/dist/review-app/xychartDiagram-PRI3JC2R-BGWVfCx4.js +7 -0
  208. package/dist/review-server/assets.js +48 -0
  209. package/dist/review-server/html.js +66 -0
  210. package/dist/review-server/http.js +47 -0
  211. package/dist/review-server/middleware/hostOrigin.js +48 -0
  212. package/dist/review-server/middleware/reviewToken.js +7 -0
  213. package/dist/review-server/reviewServerPolicy.js +10 -0
  214. package/dist/review-server/server.js +568 -0
  215. package/dist/review-server/settingsApi.js +182 -0
  216. package/dist/review-server/walletIdentityResponse.js +13 -0
  217. package/dist/runtime/config.js +103 -0
  218. package/dist/runtime/localSettingsService.js +198 -0
  219. package/dist/runtime/logger.js +50 -0
  220. package/dist/runtime/reviewServerAcquire.js +128 -0
  221. package/dist/runtime/smokeMainnetRead.js +529 -0
  222. package/dist/runtime/smokeMainnetReadAssertions.js +308 -0
  223. package/dist/runtime/start.js +295 -0
  224. package/dist/runtime/suiEndpoint.js +97 -0
  225. package/dist/runtime/suiTransactionGraphqlMapping.js +200 -0
  226. package/dist/runtime/suiTransactionGraphqlQueries.js +231 -0
  227. package/dist/runtime/suiTransactionGraphqlSource.js +148 -0
  228. package/docs/AGENT_BEHAVIOR.md +1 -1
  229. package/docs/AGENT_DEVELOPMENT_POLICY.md +20 -0
  230. package/docs/FRONTEND_POLICY.md +4 -3
  231. package/docs/MCP_SETUP.md +59 -7
  232. package/docs/MCP_TOOLS.md +1 -1
  233. package/docs/SDK_API.md +5 -1
  234. package/package.json +3 -2
@@ -0,0 +1,59 @@
1
+ export const MAX_DEEPBOOK_ORDERBOOK_TICKS = 50;
2
+ export const MAX_DEEPBOOK_ACCOUNT_OPEN_ORDER_IDS = 100;
3
+ export const DEEPBOOK_MID_PRICE_TYPE = "deepbook_mid_price";
4
+ export const DEEPBOOK_MID_PRICE_DIRECTION = "quote_per_base";
5
+ export const DEEPBOOK_MID_PRICE_PRECISION = "deepbook_v3_to_fixed_9_js_number";
6
+ export const DEEPBOOK_MID_PRICE_SEMANTICS_KIND = "deepbook_mid_price_snapshot";
7
+ export const WALLET_BALANCE_QUANTITY_KIND = "sui_wallet_balance_snapshot";
8
+ export const DEEPBOOK_ACCOUNT_QUANTITY_KIND = "deepbook_display_number";
9
+ export const DEEPBOOK_QUOTE_QUANTITY_KIND = "deepbook_quote_display_amount";
10
+ export const DEEPBOOK_RAW_QUOTE_QUANTITY_KIND = "deepbook_quote_raw_u64";
11
+ export const INTENT_EVIDENCE_QUANTITY_KIND = "sui_intent_evidence_report";
12
+ export const SETTLEMENT_ASSET_GROUP_PARITY_QUANTITY_KIND = "settlement_asset_group_parity_snapshot";
13
+ export const SUI_USD_SETTLEMENT_ASSET_GROUP_ID = "SUI_USD_SETTLEMENT_ASSETS";
14
+ export const MAX_WALLET_BALANCE_SCAN_PAGES = 20;
15
+ // Internal placeholder for sender-independent DeepBook market reads. The pinned Sui gRPC
16
+ // resolver uses the same dummy sender when no transaction sender is provided.
17
+ export const DEFAULT_DEEPBOOK_SIMULATION_SENDER = "0x0000000000000000000000000000000000000000000000000000000000000000";
18
+ export const NOT_INSPECTED_ASSET_CLASSES = [
19
+ {
20
+ assetClass: "staked_or_locked_asset",
21
+ reason: "requires_separate_stake_read_not_inspected"
22
+ },
23
+ {
24
+ assetClass: "deepbook_balance_manager_or_open_order",
25
+ reason: "requires_separate_deepbook_account_read_not_inspected"
26
+ },
27
+ {
28
+ assetClass: "lp_vault_or_position",
29
+ reason: "requires_separate_protocol_read_not_inspected"
30
+ },
31
+ {
32
+ assetClass: "nft_or_object_asset",
33
+ reason: "requires_separate_object_read_not_inspected"
34
+ }
35
+ ];
36
+ export const INTENT_EVIDENCE_TARGET_ASSET_SELECTION_SOURCES = [
37
+ "user_explicit",
38
+ "prior_user_explicit_context"
39
+ ];
40
+ export const FLOWX_SWAP_QUOTE_QUANTITY_KIND = "flowx_swap_quote";
41
+ export class ReadServiceInputError extends Error {
42
+ kind;
43
+ details;
44
+ constructor(kind, message, details) {
45
+ super(message);
46
+ this.kind = kind;
47
+ this.details = details;
48
+ }
49
+ }
50
+ export class ReadServiceCacheError extends Error {
51
+ kind = "metadata_cache_unavailable";
52
+ details;
53
+ cause;
54
+ constructor(operation, cause) {
55
+ super("Coin metadata cache is unavailable");
56
+ this.details = { resource: "coin_metadata_cache", operation };
57
+ this.cause = cause;
58
+ }
59
+ }
@@ -0,0 +1,82 @@
1
+ import { SETTLEMENT_ASSET_GROUP_PARITY_QUANTITY_KIND } from "./readServiceTypes.js";
2
+ export function settlementAssetGroupParityQuantitySemantics() {
3
+ return {
4
+ kind: SETTLEMENT_ASSET_GROUP_PARITY_QUANTITY_KIND,
5
+ allowedUse: "settlement_asset_group_internal_parity_evidence",
6
+ referenceAssetRole: "measurement_reference_not_settlement_choice",
7
+ priceSource: "deepbook_mid_price_snapshot",
8
+ fiatUsdCashOutAvailable: false,
9
+ externalMarketPriceConversionAvailable: false,
10
+ externalMarketLookupAvailable: false,
11
+ usdPegAssumptionAvailable: false,
12
+ settlementTokenSelectionAvailable: false,
13
+ paymentExecutionReadinessAvailable: false,
14
+ routeRecommendationAvailable: false,
15
+ profitAndLossAvailable: false,
16
+ costBasisAvailable: false,
17
+ notFor: [
18
+ "settlement_token_selection",
19
+ "fiat_usd_cash_out",
20
+ "external_market_price_conversion",
21
+ "external_market_lookup",
22
+ "usd_peg_assumption",
23
+ "bank_cash_out_estimate",
24
+ "payment_execution_readiness",
25
+ "route_recommendation",
26
+ "best_route",
27
+ "transaction_building",
28
+ "signing_readiness",
29
+ "profit_or_pnl",
30
+ "cost_basis"
31
+ ]
32
+ };
33
+ }
34
+ export function settlementAssetGroupParityStatistics(samples, unavailableAssetCount) {
35
+ const sorted = [...samples].sort((left, right) => left.parityPrice - right.parityPrice);
36
+ const min = sorted[0];
37
+ const max = sorted[sorted.length - 1];
38
+ const middle = Math.floor(sorted.length / 2);
39
+ const median = sorted.length % 2 === 1
40
+ ? sorted[middle].parityPrice
41
+ : (sorted[middle - 1].parityPrice + sorted[middle].parityPrice) / 2;
42
+ const mean = samples.reduce((sum, sample) => sum + sample.parityPrice, 0) / samples.length;
43
+ return {
44
+ status: "available",
45
+ sampleCount: samples.length,
46
+ unavailableAssetCount,
47
+ parityDirection: "reference_asset_per_group_asset",
48
+ calculation: "computed_from_available_direct_deepbook_mid_price_snapshots",
49
+ min: { symbol: min.symbol, parityPrice: roundDerivedParityPrice(min.parityPrice) },
50
+ max: { symbol: max.symbol, parityPrice: roundDerivedParityPrice(max.parityPrice) },
51
+ mean: { parityPrice: roundDerivedParityPrice(mean) },
52
+ median: { parityPrice: roundDerivedParityPrice(median) }
53
+ };
54
+ }
55
+ export function settlementAssetGroupParityResponseSummary(input) {
56
+ return {
57
+ questionKind: "settlement_asset_group_parity",
58
+ conclusionKind: "parity_statistics_available",
59
+ assetGroupId: input.assetGroupId,
60
+ referenceAssetSymbol: input.referenceAssetSymbol,
61
+ referenceAssetRole: "measurement_reference_not_settlement_choice",
62
+ parityDirection: input.statistics.parityDirection,
63
+ min: input.statistics.min,
64
+ max: input.statistics.max,
65
+ mean: input.statistics.mean,
66
+ median: input.statistics.median,
67
+ excludedFromConclusion: [
68
+ "settlement_token_selection",
69
+ "fiat_usd_cash_out",
70
+ "payment_execution_readiness",
71
+ "route_recommendation",
72
+ "best_route",
73
+ "transaction_building",
74
+ "signing_readiness",
75
+ "profit_or_pnl",
76
+ "cost_basis"
77
+ ]
78
+ };
79
+ }
80
+ export function roundDerivedParityPrice(price) {
81
+ return Number(price.toFixed(9));
82
+ }
@@ -0,0 +1,99 @@
1
+ import { DEEPBOOK_SCALAR_UNIT_SOURCE, DISPLAY_AMOUNT_SOURCE, SUI_METADATA_UNIT_SOURCE, formatRawAmount, normalizeCoinType } from "./coinMetadata.js";
2
+ import { findDeepbookCoinEntry } from "./deepbookRegistry.js";
3
+ import { WALLET_BALANCE_QUANTITY_KIND } from "./readServiceTypes.js";
4
+ export const SUI_COIN_TYPE = normalizeCoinType("0x2::sui::SUI");
5
+ export function walletBalanceQuantitySemantics() {
6
+ return {
7
+ kind: WALLET_BALANCE_QUANTITY_KIND,
8
+ allowedUse: "current_coin_balance_snapshot",
9
+ currentBalanceSnapshot: true,
10
+ transactionHistoryAvailable: false,
11
+ transactionReceiptProofAvailable: false,
12
+ transactionBalanceDeltaAvailable: false,
13
+ acquisitionSourceAvailable: false,
14
+ objectProvenanceAvailable: false,
15
+ fiatUsdCashOutAvailable: false,
16
+ profitAndLossAvailable: false,
17
+ costBasisAvailable: false,
18
+ notFor: [
19
+ "transaction_history",
20
+ "transaction_receipt_proof",
21
+ "specific_transaction_balance_delta",
22
+ "acquisition_source",
23
+ "object_provenance",
24
+ "fiat_usd_cash_out",
25
+ "profit_or_pnl",
26
+ "cost_basis",
27
+ "signing_data"
28
+ ]
29
+ };
30
+ }
31
+ export function classifyWalletBalance(balance, coins) {
32
+ const roles = [];
33
+ let normalizedCoinType;
34
+ try {
35
+ normalizedCoinType = normalizeCoinType(balance.coinType);
36
+ }
37
+ catch {
38
+ normalizedCoinType = undefined;
39
+ }
40
+ if (normalizedCoinType === SUI_COIN_TYPE) {
41
+ roles.push("gas_candidate");
42
+ }
43
+ if (normalizedCoinType && findDeepbookCoinEntry(normalizedCoinType, coins)) {
44
+ roles.push("deepbook_registered");
45
+ }
46
+ return {
47
+ balance,
48
+ classification: {
49
+ assetClass: "coin_balance",
50
+ spendability: balance.balance === "0" ? "zero_balance" : "spendable",
51
+ roles
52
+ }
53
+ };
54
+ }
55
+ export function unitFromMetadataRecord(record, cacheStatus) {
56
+ return {
57
+ status: "available",
58
+ source: SUI_METADATA_UNIT_SOURCE,
59
+ decimals: record.decimals,
60
+ symbol: record.symbol,
61
+ name: record.name,
62
+ cacheStatus
63
+ };
64
+ }
65
+ export function unitFromDeepbook(unit) {
66
+ return {
67
+ status: "available",
68
+ source: DEEPBOOK_SCALAR_UNIT_SOURCE,
69
+ decimals: unit.decimals,
70
+ symbol: unit.symbol,
71
+ name: unit.name
72
+ };
73
+ }
74
+ export function withUnavailableUnit(balance, reason) {
75
+ return withResolvedUnit(balance, unavailableUnit(reason));
76
+ }
77
+ export function unavailableUnit(reason) {
78
+ return {
79
+ status: "unavailable",
80
+ reason
81
+ };
82
+ }
83
+ export function withResolvedUnit(balance, unit) {
84
+ if (unit.status === "unavailable") {
85
+ return {
86
+ ...balance,
87
+ unit
88
+ };
89
+ }
90
+ return {
91
+ ...balance,
92
+ unit,
93
+ display: {
94
+ amount: formatRawAmount(balance.balance, unit.decimals),
95
+ symbol: unit.symbol,
96
+ source: DISPLAY_AMOUNT_SOURCE
97
+ }
98
+ };
99
+ }
@@ -0,0 +1,54 @@
1
+ export function adapterNotImplementedCheck() {
2
+ return {
3
+ id: "adapter_not_implemented",
4
+ label: "Adapter review",
5
+ status: "fail",
6
+ message: "No review adapter is registered for this action plan; the review fails closed and signing remains blocked for this session.",
7
+ source: "adapter"
8
+ };
9
+ }
10
+ export function accountBoundReviewRequiredCheck() {
11
+ return {
12
+ id: "account_bound_review_required",
13
+ label: "Account-bound review",
14
+ status: "warning",
15
+ message: "Connect a wallet account to compute DeepBook review evidence and adapter lifecycle stages. This does not provide signing data, signing readiness, wallet handoff, or execution.",
16
+ source: "adapter"
17
+ };
18
+ }
19
+ export function signingViaLocalReviewOnlyCheck() {
20
+ return {
21
+ id: "signing_via_local_review_only",
22
+ label: "Wallet signing",
23
+ status: "warning",
24
+ message: "Wallet signing happens only on the local review page after every review evidence stage completes and the digest-gated handoff succeeds. MCP responses never contain signing data, transaction bytes, or signing readiness.",
25
+ source: "adapter"
26
+ };
27
+ }
28
+ export function unsupportedDeepbookSwapPlanIdentityCheck() {
29
+ return {
30
+ id: "deepbook_swap_plan_identity_invalid",
31
+ label: "DeepBook plan identity",
32
+ status: "fail",
33
+ message: "This action plan is labelled for the DeepBook swap adapter but does not match the DeepBookV3 swap review identity.",
34
+ source: "adapter"
35
+ };
36
+ }
37
+ export function unsupportedFlowxSwapPlanIdentityCheck() {
38
+ return {
39
+ id: "flowx_swap_plan_identity_invalid",
40
+ label: "FlowX plan identity",
41
+ status: "fail",
42
+ message: "This action plan is labelled for the FlowX swap adapter but does not match the FlowXCLMM swap review identity.",
43
+ source: "adapter"
44
+ };
45
+ }
46
+ export function externalProposalReviewOnlyCheck() {
47
+ return {
48
+ id: "external_proposal_review_only",
49
+ label: "Non-signable review",
50
+ status: "fail",
51
+ message: "External proposal ingestion is read-only; it does not build transactions, request signatures, or create wallet actions.",
52
+ source: "adapter"
53
+ };
54
+ }
@@ -0,0 +1,38 @@
1
+ import { rejectAdapterLifecycle } from "../action/adapterLifecycleValidation.js";
2
+ import { adapterNotImplementedCheck, externalProposalReviewOnlyCheck } from "./reviewChecks.js";
3
+ import { blockedReviewResult, mapReviewComputationResultToState } from "./reviewComputationResult.js";
4
+ export async function computeReviewState(input, deps = {}) {
5
+ const computed = await computeReviewStateWithPrivateArtifacts(input, deps);
6
+ return computed.state;
7
+ }
8
+ export async function computeReviewStateWithPrivateArtifacts(input, deps = {}) {
9
+ const computed = await computeReviewOutput(input, deps);
10
+ const state = mapReviewComputationResultToState({
11
+ reviewSessionId: input.reviewSessionId,
12
+ planId: input.plan.id,
13
+ account: input.account,
14
+ now: input.now
15
+ }, computed.result, deps.validateAdapterLifecycle ?? rejectAdapterLifecycle);
16
+ return {
17
+ state,
18
+ ...(computed.privateArtifacts ? { privateArtifacts: computed.privateArtifacts } : {})
19
+ };
20
+ }
21
+ export async function computeReviewResult(input, deps = {}) {
22
+ return (await computeReviewOutput(input, deps)).result;
23
+ }
24
+ async function computeReviewOutput(input, deps = {}) {
25
+ if (input.plan.adapterId === "external-proposal-review") {
26
+ return {
27
+ result: blockedReviewResult("proposal_review_only", input.plan.reviewModel?.blockingChecks ?? [externalProposalReviewOnlyCheck()])
28
+ };
29
+ }
30
+ const computeAdapterEvidence = deps.adapters?.[input.plan.adapterId];
31
+ if (computeAdapterEvidence) {
32
+ return computeAdapterEvidence(input);
33
+ }
34
+ return {
35
+ result: blockedReviewResult("adapter_not_implemented", [adapterNotImplementedCheck()])
36
+ };
37
+ }
38
+ export { adapterNotImplementedCheck, externalProposalReviewOnlyCheck };
@@ -0,0 +1,87 @@
1
+ import { parseLifecycleValidatedReviewState } from "../action/reviewStateValidation.js";
2
+ export function mapReviewComputationResultToState(identity, result, validateAdapterLifecycle) {
3
+ const base = {
4
+ planId: identity.planId,
5
+ reviewSessionId: identity.reviewSessionId,
6
+ account: identity.account,
7
+ checks: result.checks,
8
+ updatedAt: result.updatedAt ?? (identity.now ?? new Date()).toISOString(),
9
+ ...(result.assetFlowActual ? { assetFlowActual: result.assetFlowActual } : {}),
10
+ ...(result.beforeAfterBalance ? { beforeAfterBalance: result.beforeAfterBalance } : {}),
11
+ ...(result.simulation ? { simulation: result.simulation } : {}),
12
+ ...(result.humanReadableReview ? { humanReadableReview: result.humanReadableReview } : {}),
13
+ ...(result.walletReviewAdapterContract
14
+ ? { walletReviewAdapterContract: result.walletReviewAdapterContract }
15
+ : {}),
16
+ ...(result.ptbVisualization ? { ptbVisualization: result.ptbVisualization } : {}),
17
+ ...(result.adapterLifecycle ? { adapterLifecycle: result.adapterLifecycle } : {})
18
+ };
19
+ if (result.status === "ready_for_wallet_review") {
20
+ return parseMappedReviewState({
21
+ ...base,
22
+ status: "ready_for_wallet_review"
23
+ }, validateAdapterLifecycle);
24
+ }
25
+ if (result.status === "refresh_required") {
26
+ return parseMappedReviewState({
27
+ ...base,
28
+ status: "refresh_required",
29
+ refreshReason: result.refreshReason
30
+ }, validateAdapterLifecycle);
31
+ }
32
+ return parseMappedReviewState({
33
+ ...base,
34
+ status: "blocked",
35
+ blockedReason: result.blockedReason
36
+ }, validateAdapterLifecycle);
37
+ }
38
+ function parseMappedReviewState(state, validateAdapterLifecycle) {
39
+ return parseLifecycleValidatedReviewState(state, validateAdapterLifecycle);
40
+ }
41
+ export function blockedReviewResult(blockedReason, checks, fields = {}) {
42
+ return {
43
+ status: "blocked",
44
+ blockedReason,
45
+ checks,
46
+ ...fields
47
+ };
48
+ }
49
+ export function blockedAdapterLifecycleReviewResult(blockedReason, checks, adapterLifecycle) {
50
+ return blockedReviewResult(blockedReason, checks, { adapterLifecycle });
51
+ }
52
+ export function producerStageMissingReviewResult(checks, adapterLifecycle, fields = {}) {
53
+ return blockedReviewResult("producer_stage_missing", checks, {
54
+ adapterLifecycle,
55
+ ...fields
56
+ });
57
+ }
58
+ export function walletReviewContractEmitMissingResult(checks, adapterLifecycle, humanReadableReview, simulation) {
59
+ return blockedReviewResult("wallet_review_contract_emit_missing", checks, {
60
+ adapterLifecycle,
61
+ humanReadableReview,
62
+ simulation
63
+ });
64
+ }
65
+ export function walletReviewContractEmittedResult(checks, adapterLifecycle, humanReadableReview, simulation, walletReviewAdapterContract, ptbVisualization) {
66
+ return {
67
+ status: "ready_for_wallet_review",
68
+ checks,
69
+ adapterLifecycle,
70
+ humanReadableReview,
71
+ simulation,
72
+ walletReviewAdapterContract,
73
+ ...(ptbVisualization ? { ptbVisualization } : {})
74
+ };
75
+ }
76
+ export function refreshRequiredReviewResult(refreshReason, checks, fields = {}) {
77
+ return {
78
+ status: "refresh_required",
79
+ refreshReason,
80
+ checks,
81
+ ...fields
82
+ };
83
+ }
84
+ export function refreshRequiredAdapterLifecycleReviewResult(refreshReason, checks, adapterLifecycle) {
85
+ return refreshRequiredReviewResult(refreshReason, checks, { adapterLifecycle });
86
+ }
87
+ export { failReviewCheck, passReviewCheck } from "../action/reviewCheckResults.js";
@@ -0,0 +1,31 @@
1
+ import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
2
+ export const DEFAULT_SESSION_TTL_MS = 30 * 60 * 1000;
3
+ export function createLocalSessionBase(now, ttlMs) {
4
+ const id = randomBytes(18).toString("base64url");
5
+ const token = randomBytes(32).toString("base64url");
6
+ const createdAt = now.toISOString();
7
+ return {
8
+ base: {
9
+ id,
10
+ tokenHash: hashToken(token),
11
+ createdAt,
12
+ expiresAt: new Date(now.getTime() + ttlMs).toISOString(),
13
+ lastActivityAt: createdAt
14
+ },
15
+ token
16
+ };
17
+ }
18
+ export function hashToken(token) {
19
+ return createHash("sha256").update(token).digest("hex");
20
+ }
21
+ export function tokenMatchesHash(tokenHash, token) {
22
+ const expected = Buffer.from(tokenHash, "hex");
23
+ const actual = Buffer.from(hashToken(token), "hex");
24
+ return expected.length === actual.length && timingSafeEqual(expected, actual);
25
+ }
26
+ export function isLocalSessionExpired(session, now) {
27
+ return new Date(session.expiresAt).getTime() <= now.getTime();
28
+ }
29
+ export function cloneLocalSession(value) {
30
+ return structuredClone(value);
31
+ }
@@ -0,0 +1,73 @@
1
+ import { parseHumanReadableReviewEvidence } from "../action/humanReadableReviewEvidence.js";
2
+ import { parseReviewTimeSimulationEvidence } from "../action/reviewTimeSimulationEvidence.js";
3
+ export function clonePrivateReviewArtifacts(artifacts) {
4
+ return {
5
+ ...(artifacts.transactionMaterial
6
+ ? { transactionMaterial: { ...artifacts.transactionMaterial } }
7
+ : {}),
8
+ ...(artifacts.transactionMaterialDigest
9
+ ? { transactionMaterialDigest: { ...artifacts.transactionMaterialDigest } }
10
+ : {}),
11
+ ...(artifacts.swapQuotePolicy
12
+ ? {
13
+ swapQuotePolicy: {
14
+ ...artifacts.swapQuotePolicy,
15
+ quoteSource: { ...artifacts.swapQuotePolicy.quoteSource },
16
+ sourceAmount: {
17
+ ...artifacts.swapQuotePolicy.sourceAmount,
18
+ asset: { ...artifacts.swapQuotePolicy.sourceAmount.asset }
19
+ },
20
+ expectedOutput: {
21
+ ...artifacts.swapQuotePolicy.expectedOutput,
22
+ asset: { ...artifacts.swapQuotePolicy.expectedOutput.asset }
23
+ },
24
+ minimumOutput: {
25
+ ...artifacts.swapQuotePolicy.minimumOutput,
26
+ asset: { ...artifacts.swapQuotePolicy.minimumOutput.asset }
27
+ },
28
+ protocolFee: {
29
+ ...artifacts.swapQuotePolicy.protocolFee,
30
+ asset: { ...artifacts.swapQuotePolicy.protocolFee.asset }
31
+ }
32
+ }
33
+ }
34
+ : {}),
35
+ ...(artifacts.transactionObjectOwnership
36
+ ? {
37
+ transactionObjectOwnership: {
38
+ ...artifacts.transactionObjectOwnership,
39
+ objects: artifacts.transactionObjectOwnership.objects.map((object) => ({
40
+ ...object,
41
+ roles: [...object.roles]
42
+ }))
43
+ }
44
+ }
45
+ : {}),
46
+ ...(artifacts.humanReadableReview
47
+ ? {
48
+ humanReadableReview: parseHumanReadableReviewEvidence(structuredClone(artifacts.humanReadableReview))
49
+ }
50
+ : {}),
51
+ ...(artifacts.reviewTimeSimulation
52
+ ? {
53
+ reviewTimeSimulation: parseReviewTimeSimulationEvidence(structuredClone(artifacts.reviewTimeSimulation))
54
+ }
55
+ : {})
56
+ };
57
+ }
58
+ export class InMemoryPrivateReviewArtifactStore {
59
+ artifacts = new Map();
60
+ get(reviewSessionId) {
61
+ const artifacts = this.artifacts.get(reviewSessionId);
62
+ return artifacts ? clonePrivateReviewArtifacts(artifacts) : undefined;
63
+ }
64
+ set(reviewSessionId, artifacts) {
65
+ this.artifacts.set(reviewSessionId, clonePrivateReviewArtifacts(artifacts));
66
+ }
67
+ delete(reviewSessionId) {
68
+ this.artifacts.delete(reviewSessionId);
69
+ }
70
+ clear() {
71
+ this.artifacts.clear();
72
+ }
73
+ }
@@ -0,0 +1,9 @@
1
+ export class SessionStoreError extends Error {
2
+ code;
3
+ details;
4
+ constructor(code, message, details = {}) {
5
+ super(message);
6
+ this.code = code;
7
+ this.details = details;
8
+ }
9
+ }