@zktx.io/sui-mcp 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/LICENSES/@mysten-bcs-2.0.5-Apache-2.0.txt +205 -0
- package/LICENSES/@mysten-sui-2.17.0-Apache-2.0.txt +201 -0
- package/LICENSES/@mysten-utils-0.3.3-Apache-2.0.txt +205 -0
- package/LICENSES/fancy-canvas-2.1.0-MIT.txt +7 -0
- package/LICENSES/lightweight-charts-5.2.0-NOTICE.txt +2 -0
- package/README.md +288 -0
- package/dist/adapters/adapterLifecycleValidators.js +5 -0
- package/dist/adapters/adapterPromptSurfaces.js +60 -0
- package/dist/adapters/deepbook/deepbookHumanReviewProducer.js +178 -0
- package/dist/adapters/deepbook/deepbookQuotePolicy.js +112 -0
- package/dist/adapters/deepbook/deepbookReviewEvidence.js +507 -0
- package/dist/adapters/deepbook/deepbookReviewLifecycle.js +85 -0
- package/dist/adapters/deepbook/deepbookSwapIntent.js +79 -0
- package/dist/adapters/deepbook/deepbookTransactionMaterialProducer.js +254 -0
- package/dist/adapters/intentPlanFactories.js +51 -0
- package/dist/adapters/reviewAdapters.js +47 -0
- package/dist/core/action/adapterLifecycleValidation.js +12 -0
- package/dist/core/action/contractNameRegistry.js +151 -0
- package/dist/core/action/forbiddenFields.js +43 -0
- package/dist/core/action/humanReadableReviewEvidence.js +193 -0
- package/dist/core/action/humanReadableReviewProjectionVerifier.js +29 -0
- package/dist/core/action/ptbVisualizationProducer.js +71 -0
- package/dist/core/action/receiptPtbGraph.js +29 -0
- package/dist/core/action/reviewCheckResults.js +6 -0
- package/dist/core/action/reviewStateValidation.js +11 -0
- package/dist/core/action/reviewTimeSimulationEvidence.js +470 -0
- package/dist/core/action/schemas.js +491 -0
- package/dist/core/action/signableAdapterContract.js +998 -0
- package/dist/core/action/suiChainReceiptEvidence.js +106 -0
- package/dist/core/action/suiChainReceiptMapping.js +107 -0
- package/dist/core/action/suiChainReceiptReader.js +211 -0
- package/dist/core/action/suiChainReceiptVerifier.js +178 -0
- package/dist/core/action/swapHumanReadableReviewProjection.js +130 -0
- package/dist/core/action/swapQuotePolicyEvidence.js +271 -0
- package/dist/core/action/transactionFunding.js +244 -0
- package/dist/core/action/transactionObjectOwnershipEvidence.js +256 -0
- package/dist/core/action/transactionObjectOwnershipProducer.js +323 -0
- package/dist/core/action/types.js +33 -0
- package/dist/core/action/walletReviewContractAssembler.js +286 -0
- package/dist/core/activity/accountAssetTimeline.js +157 -0
- package/dist/core/activity/accountAssetTimelineUsdcReferences.js +120 -0
- package/dist/core/activity/activityStore.js +16 -0
- package/dist/core/activity/externalActivityCoverage.js +76 -0
- package/dist/core/activity/externalActivityTransactionStream.js +82 -0
- package/dist/core/activity/localDataService.js +296 -0
- package/dist/core/activity/localDataTypes.js +11 -0
- package/dist/core/activity/localDataValidation.js +439 -0
- package/dist/core/activity/schemaVersion.js +2 -0
- package/dist/core/activity/sqliteActivityStore.js +1068 -0
- package/dist/core/activity/sqliteActivityStoreRows.js +389 -0
- package/dist/core/activity/sqliteActivityStoreSchema.js +367 -0
- package/dist/core/activity/sqliteActivityStoreTypes.js +5 -0
- package/dist/core/activity/suiFunctionTarget.js +43 -0
- package/dist/core/activity/transactionActivityAccountEffects.js +186 -0
- package/dist/core/activity/transactionActivityAnalysis.js +295 -0
- package/dist/core/activity/transactionActivityClassifier.js +306 -0
- package/dist/core/activity/transactionActivityDetails.js +229 -0
- package/dist/core/activity/transactionActivityProtocolRules.js +218 -0
- package/dist/core/activity/transactionActivityScanPolicy.js +170 -0
- package/dist/core/activity/transactionActivityService.js +379 -0
- package/dist/core/activity/transactionActivityTypes.js +18 -0
- package/dist/core/eventlog/sink.js +35 -0
- package/dist/core/evidence/settlementFamilies.js +85 -0
- package/dist/core/evidence/userAnswerUse.js +1 -0
- package/dist/core/numeric/rawU64.js +63 -0
- package/dist/core/preferences/preferencesStore.js +26 -0
- package/dist/core/preferences/sqlitePreferencesRepository.js +136 -0
- package/dist/core/proposal/externalProposalReview.js +347 -0
- package/dist/core/proposal/schemas.js +208 -0
- package/dist/core/proposal/types.js +35 -0
- package/dist/core/read/amounts.js +14 -0
- package/dist/core/read/coinMetadata.js +60 -0
- package/dist/core/read/deepbookOfficialIndexerSource.js +373 -0
- package/dist/core/read/deepbookRawQuoteClient.js +86 -0
- package/dist/core/read/deepbookReadHelpers.js +321 -0
- package/dist/core/read/deepbookRegistry.js +157 -0
- package/dist/core/read/deepbookSourceOwners.js +159 -0
- package/dist/core/read/deepbookUsdcChartService.js +342 -0
- package/dist/core/read/intentEvidenceResponseFormatting.js +228 -0
- package/dist/core/read/readCardInputs.js +19 -0
- package/dist/core/read/readCardResult.js +40 -0
- package/dist/core/read/readResponseGuidance.js +402 -0
- package/dist/core/read/readService.js +1639 -0
- package/dist/core/read/readServiceTypes.js +88 -0
- package/dist/core/read/settlementParityFormatting.js +82 -0
- package/dist/core/read/walletReadHelpers.js +99 -0
- package/dist/core/review/reviewChecks.js +45 -0
- package/dist/core/review/reviewComputation.js +38 -0
- package/dist/core/review/reviewComputationResult.js +87 -0
- package/dist/core/session/cardSession.js +31 -0
- package/dist/core/session/cardSessionStore.js +204 -0
- package/dist/core/session/keyedRecordStore.js +18 -0
- package/dist/core/session/liveReviewSessionContract.js +3 -0
- package/dist/core/session/localSession.js +31 -0
- package/dist/core/session/privateReviewArtifacts.js +75 -0
- package/dist/core/session/reviewValidity.js +49 -0
- package/dist/core/session/sessionErrors.js +9 -0
- package/dist/core/session/sessionRecordStore.js +40 -0
- package/dist/core/session/sessionStore.js +655 -0
- package/dist/core/session/settingsSession.js +1 -0
- package/dist/core/session/settingsSessions.js +45 -0
- package/dist/core/session/sqliteCardStore.js +88 -0
- package/dist/core/session/sqliteSessionStore.js +213 -0
- package/dist/core/session/sqliteTransactionMaterialStore.js +64 -0
- package/dist/core/session/sqliteWalletWorkflowStore.js +821 -0
- package/dist/core/session/status.js +60 -0
- package/dist/core/session/transactionMaterialStore.js +221 -0
- package/dist/core/session/transactionRequest.js +72 -0
- package/dist/core/session/wait.js +79 -0
- package/dist/core/session/walletConnection.js +92 -0
- package/dist/core/session/walletRuntime.js +38 -0
- package/dist/core/session/walletWorkflow.js +608 -0
- package/dist/core/session/workflowState.js +80 -0
- package/dist/core/session/workflowView.js +150 -0
- package/dist/core/suiAddress.js +18 -0
- package/dist/core/suiEndpoint.js +72 -0
- package/dist/mcp/activeAccountResponse.js +24 -0
- package/dist/mcp/prompts.js +146 -0
- package/dist/mcp/registerTool.js +19 -0
- package/dist/mcp/resources.js +72 -0
- package/dist/mcp/responseGuidance.js +326 -0
- package/dist/mcp/result.js +17 -0
- package/dist/mcp/schemas.js +11 -0
- package/dist/mcp/server.js +32 -0
- package/dist/mcp/serverInfo.js +131 -0
- package/dist/mcp/toolErrors.js +118 -0
- package/dist/mcp/toolNames.js +58 -0
- package/dist/mcp/tools/account/index.js +44 -0
- package/dist/mcp/tools/action/prepareSuiActionReview.js +126 -0
- package/dist/mcp/tools/read/commonSchemas.js +43 -0
- package/dist/mcp/tools/read/deepbookReadTools.js +686 -0
- package/dist/mcp/tools/read/index.js +14 -0
- package/dist/mcp/tools/read/readToolHelpers.js +97 -0
- package/dist/mcp/tools/read/reviewActivityTools.js +179 -0
- package/dist/mcp/tools/read/serverStatusTools.js +100 -0
- package/dist/mcp/tools/read/transactionActivityOutput.js +371 -0
- package/dist/mcp/tools/read/transactionActivityTools.js +858 -0
- package/dist/mcp/tools/read/walletReadTools.js +734 -0
- package/dist/mcp/tools/session/executionResultTools.js +44 -0
- package/dist/mcp/tools/session/index.js +8 -0
- package/dist/mcp/tools/session/shared.js +36 -0
- package/dist/mcp/tools/session/statusTools.js +69 -0
- package/dist/mcp/tools/session/walletConnectionTools.js +69 -0
- package/dist/mcp/tools/settings/index.js +66 -0
- package/dist/mcp-app/account.html +3133 -0
- package/dist/mcp-app/account.notices.txt +973 -0
- package/dist/mcp-app/chart.html +3354 -0
- package/dist/mcp-app/chart.notices.txt +1194 -0
- package/dist/mcp-app/connect.html +3179 -0
- package/dist/mcp-app/connect.notices.txt +1012 -0
- package/dist/mcp-app/receipt.html +8430 -0
- package/dist/mcp-app/receipt.notices.txt +3549 -0
- package/dist/mcp-app/review.html +8430 -0
- package/dist/mcp-app/review.notices.txt +3549 -0
- package/dist/mcp-ui/contracts.js +31 -0
- package/dist/mcp-ui/readCards.js +28 -0
- package/dist/mcp-ui/tools.js +134 -0
- package/dist/review-app/brand-dark.svg +1 -0
- package/dist/review-app/brand-light.svg +1 -0
- package/dist/review-app/favicon.svg +1 -0
- package/dist/review-app/settings.css +1 -0
- package/dist/review-app/settings.js +1 -0
- package/dist/review-app/ui.css +809 -0
- package/dist/review-server/assets.js +48 -0
- package/dist/review-server/html.js +45 -0
- package/dist/review-server/http.js +47 -0
- package/dist/review-server/middleware/hostOrigin.js +48 -0
- package/dist/review-server/middleware/reviewToken.js +7 -0
- package/dist/review-server/reviewServerPolicy.js +1 -0
- package/dist/review-server/server.js +72 -0
- package/dist/review-server/settingsApi.js +158 -0
- package/dist/runtime/application.js +203 -0
- package/dist/runtime/config.js +97 -0
- package/dist/runtime/localSettingsService.js +198 -0
- package/dist/runtime/logger.js +66 -0
- package/dist/runtime/reviewDependencies.js +58 -0
- package/dist/runtime/reviewServerAcquire.js +93 -0
- package/dist/runtime/runtimeTermination.js +60 -0
- package/dist/runtime/shared/authenticatedFetch.js +127 -0
- package/dist/runtime/shared/control.js +93 -0
- package/dist/runtime/shared/dataAccess.js +66 -0
- package/dist/runtime/shared/mcpHttp.js +84 -0
- package/dist/runtime/shared/ownerLease.js +50 -0
- package/dist/runtime/shared/server.js +98 -0
- package/dist/runtime/shared/stdio.js +113 -0
- package/dist/runtime/smokeMainnetRead.js +391 -0
- package/dist/runtime/smokeMainnetReadAssertions.js +306 -0
- package/dist/runtime/smokeReview.js +40 -0
- package/dist/runtime/start.js +90 -0
- package/dist/runtime/suiEndpoint.js +97 -0
- package/dist/runtime/suiTransactionGraphqlMapping.js +200 -0
- package/dist/runtime/suiTransactionGraphqlQueries.js +231 -0
- package/dist/runtime/suiTransactionGraphqlSource.js +148 -0
- package/dist/runtime/walletConnectConfig.js +3 -0
- package/dist/runtime/walletConnectStorage.js +99 -0
- package/dist/runtime/walletConnectTransport.js +128 -0
- package/dist/runtime/walletSdkChild.js +3 -0
- package/dist/runtime/walletSdkChildRuntime.js +160 -0
- package/dist/runtime/walletSdkIpc.js +26 -0
- package/dist/runtime/walletSdkProcess.js +358 -0
- package/docs/AGENT_BEHAVIOR.md +524 -0
- package/docs/AGENT_DEVELOPMENT_POLICY.md +815 -0
- package/docs/FRONTEND_POLICY.md +534 -0
- package/docs/LOCAL_DB_ARCHITECTURE.md +381 -0
- package/docs/MCP_SETUP.md +742 -0
- package/docs/MCP_TOOLS.md +1318 -0
- package/docs/SDK_API.md +206 -0
- package/docs/SIGNABLE_ADAPTER_CONTRACT.md +396 -0
- package/docs/TRANSACTION_ACTIVITY_LOG.md +194 -0
- package/docs/UTILITY_INDEX.md +275 -0
- package/docs/WALLET_CONNECTION.md +238 -0
- package/docs/golden-scenarios/BEHAVIOR_MATRIX.md +166 -0
- package/docs/golden-scenarios/INTENT_EVIDENCE_GOLDEN_ANSWERS.md +161 -0
- package/docs/golden-scenarios/INTENT_EVIDENCE_MATRIX.md +259 -0
- package/package.json +79 -0
- package/protocols/deepbook-margin.md +15 -0
- package/protocols/deepbook-v3.md +24 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export const TOOL_NAMES = {
|
|
2
|
+
uiOpenAccount: "ui.open_account",
|
|
3
|
+
uiOpenReceipt: "ui.open_receipt",
|
|
4
|
+
uiOpenChart: "ui.open_chart",
|
|
5
|
+
uiReadCard: "ui.read_card",
|
|
6
|
+
uiSubmitCard: "ui.submit_card",
|
|
7
|
+
uiActCard: "ui.act_card",
|
|
8
|
+
sessionOpenReviewManagement: "session.open_review_management",
|
|
9
|
+
readGetServerStatus: "read.get_server_status",
|
|
10
|
+
readListSupportedProtocols: "read.list_supported_protocols",
|
|
11
|
+
readListDeepbookPools: "read.list_deepbook_pools",
|
|
12
|
+
readListDeepbookTokens: "read.list_deepbook_tokens",
|
|
13
|
+
readInspectDeepbookOrderbook: "read.inspect_deepbook_orderbook",
|
|
14
|
+
readGetDeepbookMidPrice: "read.get_deepbook_mid_price",
|
|
15
|
+
readGetDeepbookUsdcPriceHistory: "read.get_deepbook_usdc_price_history",
|
|
16
|
+
readGetDeepbookUsdcPriceAtTime: "read.get_deepbook_usdc_price_at_time",
|
|
17
|
+
readQuoteDeepbookAction: "read.quote_deepbook_action",
|
|
18
|
+
readQuoteDeepbookDisplayAmount: "read.quote_deepbook_display_amount",
|
|
19
|
+
readSummarizeDeepbookAccountInventory: "read.summarize_deepbook_account_inventory",
|
|
20
|
+
readSummarizeWalletAssets: "read.summarize_wallet_assets",
|
|
21
|
+
readClassifyWalletAssets: "read.classify_wallet_assets",
|
|
22
|
+
readListSettlementAssetGroups: "read.list_settlement_asset_groups",
|
|
23
|
+
readSummarizeSettlementAssetGroupParity: "read.summarize_settlement_asset_group_parity",
|
|
24
|
+
readPreviewIntentEvidence: "read.preview_intent_evidence",
|
|
25
|
+
readListReviewActivity: "read.list_review_activity",
|
|
26
|
+
readSummarizeReviewFunnel: "read.summarize_review_funnel",
|
|
27
|
+
readGetReviewSessionDetail: "read.get_review_session_detail",
|
|
28
|
+
readInspectSuiTransaction: "read.inspect_sui_transaction",
|
|
29
|
+
readScanSuiAccountActivity: "read.scan_sui_account_activity",
|
|
30
|
+
readSummarizeSuiActivityScan: "read.summarize_sui_activity_scan",
|
|
31
|
+
readScanSuiFunctionActivity: "read.scan_sui_function_activity",
|
|
32
|
+
readSummarizeSuiFunctionActivityScan: "read.summarize_sui_function_activity_scan",
|
|
33
|
+
readSummarizeSuiAccountActivity: "read.summarize_sui_account_activity",
|
|
34
|
+
readGetAccountAssetTimeline: "read.get_account_asset_timeline",
|
|
35
|
+
settingsCreateLocalSettingsSession: "settings.create_local_settings_session",
|
|
36
|
+
settingsGetLocalSettings: "settings.get_local_settings",
|
|
37
|
+
actionPrepareSuiActionReview: "action.prepare_sui_action_review",
|
|
38
|
+
actionPrepareExternalProposalReview: "action.prepare_external_proposal_review",
|
|
39
|
+
sessionCreateWalletConnection: "session.create_wallet_connection",
|
|
40
|
+
sessionGetWalletConnection: "session.get_wallet_connection",
|
|
41
|
+
sessionWaitWalletConnection: "session.wait_wallet_connection",
|
|
42
|
+
sessionGetInteractionStatus: "session.get_interaction_status",
|
|
43
|
+
sessionGetReviewStatus: "session.get_review_status",
|
|
44
|
+
sessionGetExecutionResult: "session.get_execution_result",
|
|
45
|
+
sessionWaitExecutionResult: "session.wait_execution_result",
|
|
46
|
+
accountGetActiveAccount: "account.get_active_account",
|
|
47
|
+
accountClearActiveAccount: "account.clear_active_account"
|
|
48
|
+
};
|
|
49
|
+
export function assertValidToolName(name) {
|
|
50
|
+
if (!/^[A-Za-z0-9_.-]{1,128}$/.test(name)) {
|
|
51
|
+
throw new Error(`Invalid MCP tool name: ${name}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export function assertAllToolNamesValid() {
|
|
55
|
+
for (const name of Object.values(TOOL_NAMES)) {
|
|
56
|
+
assertValidToolName(name);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { activeAccountResponse, activeAccountResponseSchema } from "../../activeAccountResponse.js";
|
|
3
|
+
import { registerSuiMcpTool } from "../../registerTool.js";
|
|
4
|
+
import { okToolResult } from "../../result.js";
|
|
5
|
+
import { noParamsInputSchema, successOutputSchema } from "../../schemas.js";
|
|
6
|
+
import { activityStoreToolError } from "../../toolErrors.js";
|
|
7
|
+
import { TOOL_NAMES } from "../../toolNames.js";
|
|
8
|
+
export function registerAccountTools(server, deps) {
|
|
9
|
+
server.registerTool(TOOL_NAMES.accountGetActiveAccount, {
|
|
10
|
+
title: "Get active account read context",
|
|
11
|
+
description: "Return the active account address for wallet-account reads. Read context only; not signing authorization.",
|
|
12
|
+
inputSchema: noParamsInputSchema,
|
|
13
|
+
outputSchema: {
|
|
14
|
+
ok: z.literal(true),
|
|
15
|
+
data: activeAccountResponseSchema
|
|
16
|
+
},
|
|
17
|
+
annotations: { readOnlyHint: true, openWorldHint: false }
|
|
18
|
+
}, async () => {
|
|
19
|
+
try {
|
|
20
|
+
const active = await deps.activityStore.getActiveAccount();
|
|
21
|
+
return okToolResult(activeAccountResponse(active));
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
return activityStoreToolError(error, deps.logger);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
registerSuiMcpTool(server, TOOL_NAMES.accountClearActiveAccount, {
|
|
28
|
+
title: "Clear active account read context",
|
|
29
|
+
description: "Remove the active read context. Does not disconnect a wallet or revoke onchain permission.",
|
|
30
|
+
inputSchema: noParamsInputSchema,
|
|
31
|
+
outputSchema: successOutputSchema({
|
|
32
|
+
status: z.literal("cleared")
|
|
33
|
+
}),
|
|
34
|
+
annotations: { readOnlyHint: false, openWorldHint: false }
|
|
35
|
+
}, async () => {
|
|
36
|
+
try {
|
|
37
|
+
await deps.activityStore.clearActiveAccount();
|
|
38
|
+
return okToolResult({ status: "cleared" });
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
return activityStoreToolError(error, deps.logger);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { cardMetadata, createWorkflowCard, supportsCards } from "../../../mcp-ui/tools.js";
|
|
2
|
+
import { cardSnapshotSchema } from "../../../mcp-ui/contracts.js";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { INTENT_PLAN_FACTORIES, resolveIntentPlanFactory, swapIntentInputSchema } from "../../../adapters/intentPlanFactories.js";
|
|
5
|
+
import { actionPlanSchema, reviewCheckSchema } from "../../../core/action/schemas.js";
|
|
6
|
+
import { externalProposalToActionPlan } from "../../../core/proposal/externalProposalReview.js";
|
|
7
|
+
import { externalProposalSchema } from "../../../core/proposal/schemas.js";
|
|
8
|
+
import { prepareActionReviewUserAnswerUse, prepareExternalProposalReviewUserAnswerUse } from "../../responseGuidance.js";
|
|
9
|
+
import { registerSuiMcpTool } from "../../registerTool.js";
|
|
10
|
+
import { successOutputSchema } from "../../schemas.js";
|
|
11
|
+
import { errorToolResult } from "../../result.js";
|
|
12
|
+
import { activityStoreToolError, sessionStoreToolError } from "../../toolErrors.js";
|
|
13
|
+
import { TOOL_NAMES } from "../../toolNames.js";
|
|
14
|
+
import { userAnswerUseSchema } from "../read/commonSchemas.js";
|
|
15
|
+
export function registerActionTools(server, deps) {
|
|
16
|
+
server.registerTool(TOOL_NAMES.actionPrepareSuiActionReview, {
|
|
17
|
+
title: "Prepare swap review",
|
|
18
|
+
description: "Create a local swap review session on a supported protocol. Returns an internal review card.",
|
|
19
|
+
inputSchema: {
|
|
20
|
+
intent: swapIntentInputSchema
|
|
21
|
+
},
|
|
22
|
+
outputSchema: successOutputSchema({
|
|
23
|
+
reviewSessionId: z.string(),
|
|
24
|
+
card: cardSnapshotSchema,
|
|
25
|
+
plans: z.array(actionPlanSchema),
|
|
26
|
+
preliminaryChecks: z.array(reviewCheckSchema),
|
|
27
|
+
userAnswerUse: userAnswerUseSchema
|
|
28
|
+
}),
|
|
29
|
+
_meta: cardMetadata("review"),
|
|
30
|
+
annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: false }
|
|
31
|
+
}, async ({ intent }) => {
|
|
32
|
+
if (!supportsCards(server))
|
|
33
|
+
return errorToolResult({ kind: "ui_unavailable", details: { reason: "An internal review card is required." } });
|
|
34
|
+
const now = new Date();
|
|
35
|
+
// A swap review is account-bound: its evidence (balances, transaction
|
|
36
|
+
// material, digest, simulation) is computed for a specific sender, and
|
|
37
|
+
// no transaction can be built without that account. Refuse here when no
|
|
38
|
+
// wallet account is connected instead of creating a hollow proposal that
|
|
39
|
+
// can never be computed or signed. Connect first via
|
|
40
|
+
// session.create_wallet_connection.
|
|
41
|
+
let activeAccount;
|
|
42
|
+
try {
|
|
43
|
+
activeAccount = await deps.activityStore.getActiveAccount();
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
return activityStoreToolError(error, deps.logger);
|
|
47
|
+
}
|
|
48
|
+
if (!activeAccount) {
|
|
49
|
+
return errorToolResult({
|
|
50
|
+
kind: "active_account_not_set",
|
|
51
|
+
details: { action: "connect_wallet_connection" }
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
const { protocol: protocolSlug, ...swapIntent } = intent;
|
|
55
|
+
const resolution = resolveIntentPlanFactory(INTENT_PLAN_FACTORIES, swapIntent.type, protocolSlug);
|
|
56
|
+
if (resolution.status !== "resolved") {
|
|
57
|
+
return errorToolResult({
|
|
58
|
+
kind: resolution.status === "unsupported_action" ? "unsupported_action" : "input_invalid",
|
|
59
|
+
details: resolution.status === "unsupported_action"
|
|
60
|
+
? { reason: "unsupported_action", actionKind: resolution.actionKind }
|
|
61
|
+
: resolution.status === "unknown_protocol"
|
|
62
|
+
? {
|
|
63
|
+
reason: "unknown_protocol",
|
|
64
|
+
protocol: resolution.protocolSlug,
|
|
65
|
+
availableProtocols: resolution.available
|
|
66
|
+
}
|
|
67
|
+
: {
|
|
68
|
+
reason: "protocol_choice_required",
|
|
69
|
+
availableProtocols: resolution.available,
|
|
70
|
+
guidance: "Several protocols support this action; set intent.protocol to one of availableProtocols. Ask the user - do not pick a protocol silently."
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
const plan = resolution.factory.createPlan(swapIntent, now);
|
|
75
|
+
try {
|
|
76
|
+
const { session } = await deps.sessions.createReviewSession([plan], now);
|
|
77
|
+
const preliminaryChecks = plan.preliminaryChecks ?? [];
|
|
78
|
+
const hasBlockingPreliminaryChecks = preliminaryChecks.some((check) => check.status === "fail");
|
|
79
|
+
const payload = {
|
|
80
|
+
reviewSessionId: session.id,
|
|
81
|
+
plans: session.plans,
|
|
82
|
+
preliminaryChecks,
|
|
83
|
+
userAnswerUse: prepareActionReviewUserAnswerUse({ hasBlockingPreliminaryChecks })
|
|
84
|
+
};
|
|
85
|
+
return await createWorkflowCard(server, deps, "review", { reviewSessionId: session.id }, payload);
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
return sessionStoreToolError(error, deps.logger);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
registerSuiMcpTool(server, TOOL_NAMES.actionPrepareExternalProposalReview, {
|
|
92
|
+
title: "Prepare external proposal review",
|
|
93
|
+
description: "Create a local non-signable review session from an untrusted external Sui proposal.",
|
|
94
|
+
inputSchema: {
|
|
95
|
+
proposal: externalProposalSchema
|
|
96
|
+
},
|
|
97
|
+
outputSchema: successOutputSchema({
|
|
98
|
+
reviewSessionId: z.string(),
|
|
99
|
+
card: cardSnapshotSchema,
|
|
100
|
+
plans: z.array(actionPlanSchema),
|
|
101
|
+
preliminaryChecks: z.array(reviewCheckSchema),
|
|
102
|
+
userAnswerUse: userAnswerUseSchema
|
|
103
|
+
}),
|
|
104
|
+
_meta: cardMetadata("review"),
|
|
105
|
+
annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: false }
|
|
106
|
+
}, async ({ proposal }) => {
|
|
107
|
+
if (!supportsCards(server))
|
|
108
|
+
return errorToolResult({ kind: "ui_unavailable", details: { reason: "An internal review card is required." } });
|
|
109
|
+
const now = new Date();
|
|
110
|
+
const plan = externalProposalToActionPlan(proposal, now);
|
|
111
|
+
try {
|
|
112
|
+
const { session } = await deps.sessions.createReviewSession([plan], now);
|
|
113
|
+
const preliminaryChecks = plan.preliminaryChecks ?? [];
|
|
114
|
+
const payload = {
|
|
115
|
+
reviewSessionId: session.id,
|
|
116
|
+
plans: session.plans,
|
|
117
|
+
preliminaryChecks,
|
|
118
|
+
userAnswerUse: prepareExternalProposalReviewUserAnswerUse()
|
|
119
|
+
};
|
|
120
|
+
return await createWorkflowCard(server, deps, "review", { reviewSessionId: session.id }, payload);
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
return sessionStoreToolError(error, deps.logger);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { DEEPBOOK_MID_PRICE_PRECISION } from "../../../core/read/readService.js";
|
|
3
|
+
export const fetchedAtSchema = z.string().refine((value) => {
|
|
4
|
+
const parsed = new Date(value);
|
|
5
|
+
return !Number.isNaN(parsed.getTime()) && parsed.toISOString() === value;
|
|
6
|
+
}, "Expected ISO 8601 UTC timestamp");
|
|
7
|
+
export const readSourceSchema = z.object({
|
|
8
|
+
sdk: z.string(),
|
|
9
|
+
transport: z.literal("grpc"),
|
|
10
|
+
simulation: z.literal("client.core.simulateTransaction").optional(),
|
|
11
|
+
method: z.string().optional(),
|
|
12
|
+
methods: z.array(z.string()).optional(),
|
|
13
|
+
returnValueEncoding: z.string().optional(),
|
|
14
|
+
precision: z.literal(DEEPBOOK_MID_PRICE_PRECISION).optional()
|
|
15
|
+
});
|
|
16
|
+
export const reviewActivityAccountSourceSchema = z.enum(["active_account_context", "explicit_filter"]);
|
|
17
|
+
export const reviewActivityDataScopeSchema = z.object({
|
|
18
|
+
account: z.string(),
|
|
19
|
+
from: fetchedAtSchema.optional(),
|
|
20
|
+
to: fetchedAtSchema.optional(),
|
|
21
|
+
recordCount: z.number().int().nonnegative()
|
|
22
|
+
});
|
|
23
|
+
export const reviewActivityInputSchema = {
|
|
24
|
+
account: z.string().min(1).optional(),
|
|
25
|
+
from: fetchedAtSchema.optional(),
|
|
26
|
+
to: fetchedAtSchema.optional()
|
|
27
|
+
};
|
|
28
|
+
export const userAnswerUseSchema = z.object({
|
|
29
|
+
canAnswer: z.array(z.string()),
|
|
30
|
+
cannotAnswer: z.array(z.string()),
|
|
31
|
+
answerFields: z.array(z.string()),
|
|
32
|
+
preconditionFields: z.array(z.string()).optional(),
|
|
33
|
+
conclusionRuleFields: z.array(z.string()).optional(),
|
|
34
|
+
diagnosticOnlyFields: z.array(z.string()).optional(),
|
|
35
|
+
followUp: z
|
|
36
|
+
.object({
|
|
37
|
+
tool: z.string(),
|
|
38
|
+
inputFields: z.array(z.string()).optional(),
|
|
39
|
+
answerFields: z.array(z.string()),
|
|
40
|
+
reason: z.string()
|
|
41
|
+
})
|
|
42
|
+
.optional()
|
|
43
|
+
}).strict();
|