@relaycore/sdk 1.0.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/tsconfig.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "moduleResolution": "node",
5
+ "baseUrl": ".",
6
+ "paths": {
7
+ "*": [
8
+ "*"
9
+ ]
10
+ },
11
+ "composite": true,
12
+ "declaration": true,
13
+ "emitDeclarationOnly": false,
14
+ "outDir": "dist"
15
+ },
16
+ "include": [
17
+ "**/*.ts"
18
+ ],
19
+ "exclude": [
20
+ "node_modules",
21
+ "dist"
22
+ ]
23
+ }
package/tsup.config.ts ADDED
@@ -0,0 +1,19 @@
1
+ import { defineConfig } from 'tsup';
2
+
3
+ export default defineConfig({
4
+ entry: ['index.ts'],
5
+ format: ['cjs', 'esm'],
6
+ platform: 'node',
7
+ target: 'node18',
8
+ dts: true,
9
+ splitting: false,
10
+ sourcemap: true,
11
+ clean: true,
12
+ // Exclude test files
13
+ ignoreWatch: ['**/*.test.ts'],
14
+ skipNodeModulesBundle: true,
15
+ external: ['fsevents', 'express', 'ethers', '@crypto.com/facilitator-client', 'siwe', '@reown/appkit'],
16
+ loader: {
17
+ '.node': 'empty',
18
+ },
19
+ });
@@ -0,0 +1,146 @@
1
+ /**
2
+ * Chat Service Types
3
+ *
4
+ * Defines the chat API contract per the In-App Chat Architecture specification.
5
+ * Chat is a control plane + explainer + orchestrator, NOT an executor.
6
+ */
7
+
8
+ export type ChatMode = 'explain' | 'simulate' | 'plan' | 'observe';
9
+
10
+ export type ChatResponseType = 'explanation' | 'simulation' | 'plan' | 'observation' | 'error';
11
+
12
+ /**
13
+ * Chat request structure
14
+ */
15
+ export interface ChatRequest {
16
+ /** User's query */
17
+ query: string;
18
+ /** Operating mode */
19
+ mode: ChatMode;
20
+ /** Context for the request */
21
+ context?: {
22
+ sessionId?: string;
23
+ agentId?: string;
24
+ taskId?: string;
25
+ walletAddress?: string;
26
+ };
27
+ /** Conversation history */
28
+ history?: Array<{
29
+ role: 'user' | 'assistant';
30
+ content: string;
31
+ }>;
32
+ }
33
+
34
+ /**
35
+ * Proposed action that requires user approval
36
+ */
37
+ export interface ChatAction {
38
+ /** Human-readable label */
39
+ label: string;
40
+ /** API endpoint to call */
41
+ endpoint: string;
42
+ /** HTTP method */
43
+ method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
44
+ /** Request body */
45
+ body: Record<string, unknown>;
46
+ /** Whether this action requires explicit user approval */
47
+ requiresApproval: boolean;
48
+ /** Estimated cost if applicable */
49
+ estimatedCost?: {
50
+ amount: string;
51
+ currency: string;
52
+ };
53
+ /** Risk level */
54
+ riskLevel?: 'low' | 'medium' | 'high';
55
+ }
56
+
57
+ /**
58
+ * Simulation result for dry-run operations
59
+ */
60
+ export interface SimulationResult {
61
+ /** What would happen */
62
+ description: string;
63
+ /** Expected outcome */
64
+ expectedOutcome: {
65
+ success: boolean;
66
+ estimatedResult?: Record<string, unknown>;
67
+ };
68
+ /** Potential risks */
69
+ risks?: string[];
70
+ /** Required confirmations */
71
+ confirmations?: string[];
72
+ /** Gas/fee estimate */
73
+ estimatedFees?: {
74
+ gas?: string;
75
+ payment?: string;
76
+ total?: string;
77
+ };
78
+ }
79
+
80
+ /**
81
+ * Chat response structure
82
+ */
83
+ export interface ChatResponse {
84
+ /** Response type */
85
+ type: ChatResponseType;
86
+ /** Main content (human-readable) */
87
+ content: string;
88
+ /** Structured data */
89
+ data?: Record<string, unknown>;
90
+ /** Actions user can take (require approval) */
91
+ actions?: ChatAction[];
92
+ /** Simulation results (for simulate mode) */
93
+ simulation?: SimulationResult;
94
+ /** Data sources used */
95
+ sources?: Array<{
96
+ name: string;
97
+ type: 'indexer' | 'api' | 'contract' | 'database';
98
+ latencyMs?: number;
99
+ }>;
100
+ /** Processing metadata */
101
+ meta?: {
102
+ processingTimeMs: number;
103
+ tokensUsed?: number;
104
+ mode: ChatMode;
105
+ };
106
+ }
107
+
108
+ /**
109
+ * Chat capabilities per mode
110
+ */
111
+ export const CHAT_CAPABILITIES = {
112
+ explain: {
113
+ description: 'Explain agent decisions, transactions, and system state',
114
+ canExecute: false,
115
+ canModify: false,
116
+ },
117
+ simulate: {
118
+ description: 'Dry-run operations before committing',
119
+ canExecute: false,
120
+ canModify: false,
121
+ },
122
+ plan: {
123
+ description: 'Create execution plans for user approval',
124
+ canExecute: false,
125
+ canModify: false,
126
+ },
127
+ observe: {
128
+ description: 'Summarize trends, anomalies, and system health',
129
+ canExecute: false,
130
+ canModify: false,
131
+ },
132
+ } as const;
133
+
134
+ /**
135
+ * Prohibited chat operations
136
+ * Chat should NEVER do these directly - they require SDK/MCP
137
+ */
138
+ export const PROHIBITED_OPERATIONS = [
139
+ 'send_transaction',
140
+ 'sign_message',
141
+ 'approve_token',
142
+ 'execute_trade',
143
+ 'release_payment',
144
+ 'create_session',
145
+ 'fund_session',
146
+ ] as const;
@@ -0,0 +1,114 @@
1
+ /**
2
+ * X402 Types - Based on Cronos x402-examples reference implementation
3
+ *
4
+ * These types match the official Cronos x402 protocol specification.
5
+ */
6
+
7
+ import type { CronosNetwork, PaymentRequirements, X402OutputSchema } from '@crypto.com/facilitator-client';
8
+
9
+ /**
10
+ * Accepted payment scheme for x402 challenges.
11
+ * Base-compatible format for x402scan and Base-schema consumers.
12
+ */
13
+ export interface X402Accepts {
14
+ /** Payment scheme type - always 'exact' for Cronos x402 */
15
+ scheme: 'exact';
16
+ /** Target Cronos network for settlement */
17
+ network: CronosNetwork;
18
+ /** Maximum amount required in base units (e.g., 1000000 = 1 USDC) */
19
+ maxAmountRequired: string;
20
+ /** Canonical resource identifier being protected */
21
+ resource: string;
22
+ /** Human-readable description of the protected resource */
23
+ description: string;
24
+ /** MIME type of the protected resource response */
25
+ mimeType: string;
26
+ /** Destination address that receives the payment */
27
+ payTo: string;
28
+ /** Maximum time in seconds to fulfill payment */
29
+ maxTimeoutSeconds: number;
30
+ /** Asset contract address for payment */
31
+ asset: string;
32
+ /** Optional schema describing successful output */
33
+ outputSchema?: X402OutputSchema;
34
+ /** Extra implementation-specific metadata */
35
+ extra?: {
36
+ paymentId?: string;
37
+ [key: string]: unknown;
38
+ };
39
+ }
40
+
41
+ /**
42
+ * Standard x402 402-response body.
43
+ * Returned when a client must complete an x402 payment challenge.
44
+ */
45
+ export interface X402Response {
46
+ /** X402 protocol version */
47
+ x402Version: number;
48
+ /** Optional error message */
49
+ error?: string;
50
+ /** List of accepted payment options */
51
+ accepts?: X402Accepts[];
52
+ /** Optional payer identifier */
53
+ payer?: string;
54
+ }
55
+
56
+ /**
57
+ * Parameters required to settle an x402 payment.
58
+ */
59
+ export interface X402PayParams {
60
+ /** Unique identifier for the payment attempt */
61
+ paymentId: string;
62
+ /** Encoded payment header from client */
63
+ paymentHeader: string;
64
+ /** Payment requirements from prior 402 challenge */
65
+ paymentRequirements: PaymentRequirements;
66
+ }
67
+
68
+ /**
69
+ * Stored record for settled payments.
70
+ */
71
+ export interface X402PaidRecord {
72
+ /** Whether settlement succeeded */
73
+ settled: boolean;
74
+ /** Settlement transaction hash */
75
+ txHash?: string;
76
+ /** Unix timestamp when recorded */
77
+ at: number;
78
+ /** Payer address */
79
+ payer?: string;
80
+ }
81
+
82
+ /**
83
+ * Result of a payment settlement attempt.
84
+ */
85
+ export type X402PayResult =
86
+ | { ok: true; txHash?: string }
87
+ | { ok: false; error: 'verify_failed'; details: unknown }
88
+ | { ok: false; error: 'settle_failed'; details: unknown };
89
+
90
+ /**
91
+ * Options for configuring x402 protection middleware.
92
+ */
93
+ export interface X402ProtectionOptions {
94
+ /** Cronos network for verification */
95
+ network: CronosNetwork;
96
+ /** Destination address for payment */
97
+ payTo: string;
98
+ /** Asset contract address */
99
+ asset: string;
100
+ /** Maximum amount required in base units */
101
+ maxAmountRequired: string;
102
+ /** Maximum timeout in seconds */
103
+ maxTimeoutSeconds?: number;
104
+ /** Description of protected resource */
105
+ description: string;
106
+ /** MIME type of response */
107
+ mimeType?: string;
108
+ /** Resource identifier */
109
+ resource: string;
110
+ /** Output schema */
111
+ outputSchema?: X402OutputSchema;
112
+ /** Custom entitlement key extractor */
113
+ getEntitlementKey?: (req: unknown) => string | undefined;
114
+ }