@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,529 @@
1
+ import { z } from "zod";
2
+ import { proposalReviewModelSchema } from "../proposal/schemas.js";
3
+ import { suiAddressStringSchema } from "../suiAddress.js";
4
+ import { makeRawU64StringSchema } from "../numeric/rawU64.js";
5
+ import { normalizeCoinType } from "../read/coinMetadata.js";
6
+ import { BLOCKED_REASONS, FAILURE_REASONS, REFRESH_REASONS } from "./types.js";
7
+ import { ptbVisualizationArtifactSchema, walletReviewAdapterContractSchema } from "./signableAdapterContract.js";
8
+ export const unknownRecordSchema = z.record(z.string(), z.unknown());
9
+ export const failureReasonSchema = z.enum(FAILURE_REASONS);
10
+ export const blockedReasonSchema = z.enum(BLOCKED_REASONS);
11
+ export const refreshReasonSchema = z.enum(REFRESH_REASONS);
12
+ export const reviewStatusSchema = z.enum([
13
+ "ready_for_wallet_review",
14
+ "refresh_required",
15
+ "blocked"
16
+ ]);
17
+ export const internalSessionStatusSchema = z.enum([
18
+ "proposed",
19
+ "awaiting_wallet",
20
+ "wallet_connected",
21
+ "ready_for_wallet_review",
22
+ "refresh_required",
23
+ "blocked",
24
+ "signed_pending_result",
25
+ "success",
26
+ "failure",
27
+ "expired"
28
+ ]);
29
+ export const executionPollingStatusSchema = z.enum([
30
+ "pending",
31
+ "awaiting_wallet",
32
+ "awaiting_signature",
33
+ "refresh_required",
34
+ "signed_pending_result",
35
+ "success",
36
+ "failure",
37
+ "expired",
38
+ "blocked"
39
+ ]);
40
+ export const reviewCheckSchema = z.object({
41
+ id: z.string(),
42
+ label: z.string(),
43
+ status: z.enum(["pass", "warning", "fail"]),
44
+ message: z.string(),
45
+ source: z.enum(["registry", "quote", "wallet", "simulation", "adapter", "network", "proposal"])
46
+ });
47
+ const adapterLifecycleStageIdSchema = z.string().min(1);
48
+ const HUMAN_READABLE_REVIEW_STAGE = "human_readable_review";
49
+ const REVIEW_TIME_SIMULATION_STAGE = "review_time_simulation";
50
+ export const adapterLifecycleSchema = z.object({
51
+ stageCatalogId: z.string().min(1),
52
+ adapterId: z.string(),
53
+ protocol: z.string(),
54
+ actionKind: z.string(),
55
+ completedStages: z.array(adapterLifecycleStageIdSchema),
56
+ missingStages: z.array(adapterLifecycleStageIdSchema)
57
+ }).strict().superRefine((lifecycle, ctx) => {
58
+ const duplicateCompleted = findDuplicate(lifecycle.completedStages);
59
+ if (duplicateCompleted) {
60
+ ctx.addIssue({
61
+ code: "custom",
62
+ path: ["completedStages"],
63
+ message: `completedStages contains duplicate stage '${duplicateCompleted}'`
64
+ });
65
+ }
66
+ const duplicateMissing = findDuplicate(lifecycle.missingStages);
67
+ if (duplicateMissing) {
68
+ ctx.addIssue({
69
+ code: "custom",
70
+ path: ["missingStages"],
71
+ message: `missingStages contains duplicate stage '${duplicateMissing}'`
72
+ });
73
+ }
74
+ for (const stage of lifecycle.completedStages) {
75
+ if (lifecycle.missingStages.includes(stage)) {
76
+ ctx.addIssue({
77
+ code: "custom",
78
+ path: ["missingStages"],
79
+ message: `stage '${stage}' cannot be both completed and missing`
80
+ });
81
+ }
82
+ }
83
+ });
84
+ function findDuplicate(values) {
85
+ const seen = new Set();
86
+ for (const value of values) {
87
+ if (seen.has(value)) {
88
+ return value;
89
+ }
90
+ seen.add(value);
91
+ }
92
+ return undefined;
93
+ }
94
+ export const assetAmountSchema = z.object({
95
+ symbol: z.string(),
96
+ amount: z.string(),
97
+ coinType: z.string().optional(),
98
+ approx: z.boolean().optional()
99
+ }).strict();
100
+ export const displayIntentAssetAmountSchema = assetAmountSchema.extend({
101
+ amountKind: z.literal("display_intent").default("display_intent")
102
+ });
103
+ export const assetFlowPreviewSchema = z.object({
104
+ outgoing: z.array(displayIntentAssetAmountSchema),
105
+ expectedIncoming: z.array(displayIntentAssetAmountSchema),
106
+ minimumIncoming: z.array(displayIntentAssetAmountSchema).optional(),
107
+ fees: z.array(displayIntentAssetAmountSchema).optional()
108
+ });
109
+ export const assetFlowSchema = z.object({
110
+ outgoing: z.array(assetAmountSchema),
111
+ expectedIncoming: z.array(assetAmountSchema),
112
+ minimumIncoming: z.array(assetAmountSchema).optional(),
113
+ fees: z.array(assetAmountSchema).optional()
114
+ });
115
+ export const balanceChangeSchema = z.object({
116
+ before: z.array(assetAmountSchema),
117
+ after: z.array(assetAmountSchema),
118
+ delta: z.array(assetAmountSchema)
119
+ });
120
+ export const transactionSimulationGasCostSummarySchema = z.object({
121
+ computationCostRaw: makeRawU64StringSchema("computationCostRaw"),
122
+ storageCostRaw: makeRawU64StringSchema("storageCostRaw"),
123
+ storageRebateRaw: makeRawU64StringSchema("storageRebateRaw"),
124
+ nonRefundableStorageFeeRaw: makeRawU64StringSchema("nonRefundableStorageFeeRaw")
125
+ }).strict();
126
+ const transactionSimulationSummaryBaseSchema = z.object({
127
+ provider: z.literal("client.core.simulateTransaction"),
128
+ checksEnabled: z.boolean(),
129
+ success: z.boolean(),
130
+ gasCostSummary: transactionSimulationGasCostSummarySchema.optional(),
131
+ balanceChanges: z.array(unknownRecordSchema).optional(),
132
+ objectChanges: z.array(unknownRecordSchema).optional(),
133
+ error: z.string().optional()
134
+ });
135
+ export const transactionSimulationSummarySchema = transactionSimulationSummaryBaseSchema;
136
+ export const successfulTransactionSimulationSummarySchema = transactionSimulationSummaryBaseSchema.extend({
137
+ checksEnabled: z.literal(true),
138
+ success: z.literal(true),
139
+ gasCostSummary: transactionSimulationGasCostSummarySchema,
140
+ balanceChanges: z.array(unknownRecordSchema),
141
+ objectChanges: z.array(unknownRecordSchema),
142
+ error: z.never().optional()
143
+ }).strict();
144
+ const swapHumanReadableReviewAmountSchema = z.object({
145
+ role: z.enum(["input", "expected_output", "minimum_output", "fee"]),
146
+ symbol: z.string(),
147
+ coinType: z.string().min(1).max(512).refine((value) => {
148
+ try {
149
+ normalizeCoinType(value);
150
+ return true;
151
+ }
152
+ catch {
153
+ return false;
154
+ }
155
+ }, "Expected a Sui struct tag coin type"),
156
+ decimals: z.number().int().min(0).max(255),
157
+ rawAmount: makeRawU64StringSchema("rawAmount"),
158
+ rawAmountSource: z.literal("quote_policy_evidence"),
159
+ displayAmount: z.string().optional(),
160
+ displayAmountSource: z.literal("user_display_intent_not_signing_input").optional()
161
+ }).strict().superRefine((amount, ctx) => {
162
+ if (amount.displayAmount !== undefined && amount.displayAmountSource === undefined) {
163
+ ctx.addIssue({
164
+ code: "custom",
165
+ path: ["displayAmountSource"],
166
+ message: "displayAmountSource is required when displayAmount is present"
167
+ });
168
+ }
169
+ if (amount.displayAmount === undefined && amount.displayAmountSource !== undefined) {
170
+ ctx.addIssue({
171
+ code: "custom",
172
+ path: ["displayAmount"],
173
+ message: "displayAmount is required when displayAmountSource is present"
174
+ });
175
+ }
176
+ });
177
+ const humanReadableReviewPartySchema = z.object({
178
+ role: z.enum(["connected_account", "output_recipient"]),
179
+ address: suiAddressStringSchema
180
+ }).strict();
181
+ const swapHumanReadableReviewTargetSchema = z.object({
182
+ kind: z.literal("swap_output_asset"),
183
+ symbol: z.string(),
184
+ coinType: z.string().min(1).max(512).refine((value) => {
185
+ try {
186
+ normalizeCoinType(value);
187
+ return true;
188
+ }
189
+ catch {
190
+ return false;
191
+ }
192
+ }, "Expected a Sui struct tag coin type"),
193
+ protocol: z.string(),
194
+ poolKey: z.string(),
195
+ direction: z.enum(["base_to_quote", "quote_to_base"])
196
+ }).strict();
197
+ const humanReadableReviewFactSchema = z.object({
198
+ id: z.string(),
199
+ label: z.string(),
200
+ source: z.union([
201
+ z.enum(["registry", "quote", "wallet", "simulation", "adapter", "network", "proposal"]),
202
+ z.enum(["transaction_material", "digest_commitment"])
203
+ ]),
204
+ summary: z.string()
205
+ }).strict();
206
+ const humanReadableReviewGapSchema = z.object({
207
+ id: z.string(),
208
+ label: z.string(),
209
+ reason: z.string()
210
+ }).strict();
211
+ export const humanReadableReviewEnvelopeSchema = z.object({
212
+ proposedAction: z.object({
213
+ title: z.string(),
214
+ summary: z.string(),
215
+ actionKind: z.string(),
216
+ adapterId: z.string(),
217
+ protocol: z.string(),
218
+ network: z.literal("sui:mainnet")
219
+ }).strict(),
220
+ recipients: z.array(humanReadableReviewPartySchema),
221
+ evidenceUsed: z.array(humanReadableReviewFactSchema),
222
+ missingEvidence: z.array(humanReadableReviewGapSchema),
223
+ requiredUserChoices: z.array(humanReadableReviewGapSchema),
224
+ unsupportedClaims: z.array(humanReadableReviewGapSchema),
225
+ freshness: z.object({
226
+ status: z.literal("current"),
227
+ evaluatedAt: z.string(),
228
+ expiresAt: z.string(),
229
+ reason: z.string()
230
+ }).strict(),
231
+ blockingChecks: z.array(reviewCheckSchema)
232
+ }).strict();
233
+ export const swapHumanReadableReviewProjectionSchema = z.object({
234
+ assetFlow: z.object({
235
+ outgoing: z.array(swapHumanReadableReviewAmountSchema),
236
+ expectedIncoming: z.array(swapHumanReadableReviewAmountSchema),
237
+ minimumIncoming: z.array(swapHumanReadableReviewAmountSchema),
238
+ fees: z.array(swapHumanReadableReviewAmountSchema)
239
+ }).strict(),
240
+ targets: z.array(swapHumanReadableReviewTargetSchema)
241
+ }).strict();
242
+ export const swapHumanReadableReviewSummarySchema = humanReadableReviewEnvelopeSchema
243
+ .extend({ kind: z.literal("swap_human_readable_review") })
244
+ .merge(swapHumanReadableReviewProjectionSchema);
245
+ export const humanReadableReviewSummarySchema = z.discriminatedUnion("kind", [
246
+ swapHumanReadableReviewSummarySchema
247
+ ]);
248
+ export const actionPlanSchema = z.object({
249
+ id: z.string(),
250
+ actionKind: z.string(),
251
+ adapterId: z.string(),
252
+ protocol: z.string(),
253
+ title: z.string(),
254
+ summary: z.string(),
255
+ assetFlowPreview: assetFlowPreviewSchema,
256
+ reviewModel: proposalReviewModelSchema.optional(),
257
+ adapterData: unknownRecordSchema,
258
+ createdAt: z.string(),
259
+ expiresAt: z.string().optional(),
260
+ registryVersion: z.string().optional(),
261
+ preliminaryChecks: z.array(reviewCheckSchema).optional()
262
+ });
263
+ const reviewStateBaseSchema = z.object({
264
+ planId: z.string(),
265
+ reviewSessionId: z.string(),
266
+ account: suiAddressStringSchema,
267
+ checks: z.array(reviewCheckSchema),
268
+ assetFlowActual: assetFlowSchema.optional(),
269
+ beforeAfterBalance: balanceChangeSchema.optional(),
270
+ simulation: transactionSimulationSummarySchema.optional(),
271
+ humanReadableReview: humanReadableReviewSummarySchema.optional(),
272
+ walletReviewAdapterContract: walletReviewAdapterContractSchema.optional(),
273
+ ptbVisualization: ptbVisualizationArtifactSchema.optional(),
274
+ adapterLifecycle: adapterLifecycleSchema.optional(),
275
+ updatedAt: z.string()
276
+ });
277
+ export const reviewStateStructuralInvariantSchema = z.discriminatedUnion("status", [
278
+ reviewStateBaseSchema.extend({
279
+ status: z.literal("ready_for_wallet_review"),
280
+ blockedReason: z.never().optional(),
281
+ refreshReason: z.never().optional()
282
+ }),
283
+ reviewStateBaseSchema.extend({
284
+ status: z.literal("refresh_required"),
285
+ refreshReason: refreshReasonSchema,
286
+ blockedReason: z.never().optional()
287
+ }),
288
+ reviewStateBaseSchema.extend({
289
+ status: z.literal("blocked"),
290
+ blockedReason: blockedReasonSchema,
291
+ refreshReason: z.never().optional()
292
+ })
293
+ ]).superRefine((state, ctx) => {
294
+ const lifecycle = state.adapterLifecycle;
295
+ if (lifecycle !== undefined) {
296
+ validatePublicEvidenceStageBinding(state, ctx);
297
+ }
298
+ if (state.humanReadableReview !== undefined && lifecycle === undefined) {
299
+ ctx.addIssue({
300
+ code: "custom",
301
+ path: ["humanReadableReview"],
302
+ message: "humanReadableReview requires adapterLifecycle evidence stage provenance"
303
+ });
304
+ }
305
+ if (state.simulation !== undefined && lifecycle === undefined) {
306
+ ctx.addIssue({
307
+ code: "custom",
308
+ path: ["simulation"],
309
+ message: "simulation requires adapterLifecycle evidence stage provenance"
310
+ });
311
+ }
312
+ if (state.ptbVisualization !== undefined) {
313
+ const stages = lifecycle?.completedStages ?? [];
314
+ const hasMaterialBinding = stages.includes("transaction_material_build_or_verify") && stages.includes("digest_commitment");
315
+ if (!hasMaterialBinding) {
316
+ ctx.addIssue({
317
+ code: "custom",
318
+ path: ["ptbVisualization"],
319
+ message: "ptbVisualization requires completed transaction material and digest commitment lifecycle stages"
320
+ });
321
+ }
322
+ }
323
+ const contractCarryingState = state.status === "ready_for_wallet_review" ||
324
+ (state.status === "blocked" && state.blockedReason === "wallet_handoff_not_implemented");
325
+ if (state.walletReviewAdapterContract !== undefined && !contractCarryingState) {
326
+ ctx.addIssue({
327
+ code: "custom",
328
+ path: ["walletReviewAdapterContract"],
329
+ message: "walletReviewAdapterContract is only valid on ready_for_wallet_review or a stored wallet_handoff_not_implemented state"
330
+ });
331
+ }
332
+ if (state.status === "ready_for_wallet_review" && lifecycle !== undefined) {
333
+ if (state.walletReviewAdapterContract === undefined) {
334
+ ctx.addIssue({
335
+ code: "custom",
336
+ path: ["walletReviewAdapterContract"],
337
+ message: "ready_for_wallet_review requires an emitted wallet review contract"
338
+ });
339
+ }
340
+ if (lifecycle === undefined || lifecycle.missingStages.length !== 0) {
341
+ ctx.addIssue({
342
+ code: "custom",
343
+ path: ["adapterLifecycle"],
344
+ message: "ready_for_wallet_review requires a completed adapterLifecycle with no missing stages"
345
+ });
346
+ }
347
+ if (state.humanReadableReview === undefined) {
348
+ ctx.addIssue({
349
+ code: "custom",
350
+ path: ["humanReadableReview"],
351
+ message: "ready_for_wallet_review requires humanReadableReview public evidence"
352
+ });
353
+ }
354
+ if (state.simulation === undefined) {
355
+ ctx.addIssue({
356
+ code: "custom",
357
+ path: ["simulation"],
358
+ message: "ready_for_wallet_review requires successful simulation public evidence"
359
+ });
360
+ }
361
+ }
362
+ if (state.status !== "blocked") {
363
+ return;
364
+ }
365
+ if (state.blockedReason === "wallet_handoff_not_implemented") {
366
+ if (state.walletReviewAdapterContract === undefined) {
367
+ ctx.addIssue({
368
+ code: "custom",
369
+ path: ["walletReviewAdapterContract"],
370
+ message: "wallet_handoff_not_implemented requires an emitted wallet review contract"
371
+ });
372
+ }
373
+ if (lifecycle === undefined || lifecycle.missingStages.length !== 0) {
374
+ ctx.addIssue({
375
+ code: "custom",
376
+ path: ["adapterLifecycle"],
377
+ message: "wallet_handoff_not_implemented requires a completed adapterLifecycle with no missing stages"
378
+ });
379
+ }
380
+ if (state.humanReadableReview === undefined) {
381
+ ctx.addIssue({
382
+ code: "custom",
383
+ path: ["humanReadableReview"],
384
+ message: "wallet_handoff_not_implemented requires humanReadableReview public evidence"
385
+ });
386
+ }
387
+ if (state.simulation === undefined) {
388
+ ctx.addIssue({
389
+ code: "custom",
390
+ path: ["simulation"],
391
+ message: "wallet_handoff_not_implemented requires successful simulation public evidence"
392
+ });
393
+ }
394
+ }
395
+ if (state.blockedReason === "producer_stage_missing" &&
396
+ lifecycle === undefined) {
397
+ ctx.addIssue({
398
+ code: "custom",
399
+ path: ["adapterLifecycle"],
400
+ message: "producer_stage_missing requires adapterLifecycle with at least one missing stage"
401
+ });
402
+ }
403
+ if (state.blockedReason === "producer_stage_missing" &&
404
+ lifecycle !== undefined &&
405
+ lifecycle.missingStages.length === 0) {
406
+ ctx.addIssue({
407
+ code: "custom",
408
+ path: ["blockedReason"],
409
+ message: "producer_stage_missing requires at least one adapterLifecycle.missingStages entry"
410
+ });
411
+ }
412
+ if (state.blockedReason === "wallet_review_contract_emit_missing" &&
413
+ state.walletReviewAdapterContract !== undefined) {
414
+ ctx.addIssue({
415
+ code: "custom",
416
+ path: ["walletReviewAdapterContract"],
417
+ message: "wallet_review_contract_emit_missing requires the wallet review contract to be absent"
418
+ });
419
+ }
420
+ if (state.blockedReason === "wallet_review_contract_emit_missing" &&
421
+ lifecycle === undefined) {
422
+ ctx.addIssue({
423
+ code: "custom",
424
+ path: ["adapterLifecycle"],
425
+ message: "wallet_review_contract_emit_missing requires adapterLifecycle"
426
+ });
427
+ }
428
+ if (state.blockedReason === "wallet_review_contract_emit_missing" &&
429
+ lifecycle !== undefined &&
430
+ lifecycle.missingStages.length !== 0) {
431
+ ctx.addIssue({
432
+ code: "custom",
433
+ path: ["blockedReason"],
434
+ message: "wallet_review_contract_emit_missing requires a completed adapterLifecycle with no missing stages"
435
+ });
436
+ }
437
+ if (state.blockedReason === "wallet_review_contract_emit_missing" &&
438
+ state.humanReadableReview === undefined) {
439
+ ctx.addIssue({
440
+ code: "custom",
441
+ path: ["humanReadableReview"],
442
+ message: "wallet_review_contract_emit_missing requires humanReadableReview public evidence"
443
+ });
444
+ }
445
+ if (state.blockedReason === "wallet_review_contract_emit_missing" &&
446
+ state.simulation === undefined) {
447
+ ctx.addIssue({
448
+ code: "custom",
449
+ path: ["simulation"],
450
+ message: "wallet_review_contract_emit_missing requires simulation public evidence"
451
+ });
452
+ }
453
+ });
454
+ export const reviewStateOutputSchema = reviewStateStructuralInvariantSchema;
455
+ function validatePublicEvidenceStageBinding(state, ctx) {
456
+ const lifecycle = state.adapterLifecycle;
457
+ if (!lifecycle) {
458
+ return;
459
+ }
460
+ if (state.humanReadableReview !== undefined) {
461
+ requireLifecycleStageCompleted(ctx, lifecycle, HUMAN_READABLE_REVIEW_STAGE, ["humanReadableReview"]);
462
+ }
463
+ if (state.simulation !== undefined) {
464
+ requireLifecycleStageCompleted(ctx, lifecycle, REVIEW_TIME_SIMULATION_STAGE, ["simulation"]);
465
+ requireLifecycleStageCompleted(ctx, lifecycle, HUMAN_READABLE_REVIEW_STAGE, ["simulation"]);
466
+ requireSuccessfulSimulationProjection(ctx, state.simulation, ["simulation"]);
467
+ }
468
+ if (lifecycle.missingStages.includes(REVIEW_TIME_SIMULATION_STAGE) &&
469
+ state.simulation !== undefined) {
470
+ ctx.addIssue({
471
+ code: "custom",
472
+ path: ["simulation"],
473
+ message: "simulation public evidence cannot be present while review_time_simulation is missing"
474
+ });
475
+ }
476
+ if (lifecycle.missingStages.includes(HUMAN_READABLE_REVIEW_STAGE) &&
477
+ state.humanReadableReview !== undefined) {
478
+ ctx.addIssue({
479
+ code: "custom",
480
+ path: ["humanReadableReview"],
481
+ message: "humanReadableReview public evidence cannot be present while human_readable_review is missing"
482
+ });
483
+ }
484
+ }
485
+ function requireLifecycleStageCompleted(ctx, lifecycle, stage, path) {
486
+ if (!lifecycle.completedStages.includes(stage)) {
487
+ ctx.addIssue({
488
+ code: "custom",
489
+ path,
490
+ message: `${path.join(".")} requires completed adapterLifecycle stage '${stage}'`
491
+ });
492
+ }
493
+ if (lifecycle.missingStages.includes(stage)) {
494
+ ctx.addIssue({
495
+ code: "custom",
496
+ path,
497
+ message: `${path.join(".")} cannot be present while adapterLifecycle stage '${stage}' is missing`
498
+ });
499
+ }
500
+ }
501
+ function requireSuccessfulSimulationProjection(ctx, simulation, path) {
502
+ const parsed = successfulTransactionSimulationSummarySchema.safeParse(simulation);
503
+ if (!parsed.success) {
504
+ ctx.addIssue({
505
+ code: "custom",
506
+ path,
507
+ message: "simulation public evidence requires a successful checks-enabled review-time simulation projection"
508
+ });
509
+ }
510
+ }
511
+ const executionResultBaseSchema = z.object({
512
+ reviewSessionId: z.string(),
513
+ planId: z.string(),
514
+ explorerUrl: z.string().optional(),
515
+ summary: unknownRecordSchema.optional(),
516
+ recordedAt: z.string()
517
+ });
518
+ export const executionResultSchema = z.discriminatedUnion("status", [
519
+ executionResultBaseSchema.extend({
520
+ status: z.enum(["success", "signed_pending_result"]),
521
+ txDigest: z.string().min(1),
522
+ failureReason: z.never().optional()
523
+ }),
524
+ executionResultBaseSchema.extend({
525
+ status: z.literal("failure"),
526
+ txDigest: z.string().optional(),
527
+ failureReason: failureReasonSchema
528
+ })
529
+ ]);