@gala-chain/launchpad-mcp-server 1.5.0 → 1.5.1
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/.eslintrc.json +9 -1
- package/dist/schemas/common-schemas.d.ts +121 -16
- package/dist/schemas/common-schemas.d.ts.map +1 -1
- package/dist/schemas/common-schemas.js +122 -17
- package/dist/schemas/common-schemas.js.map +1 -1
- package/dist/scripts/test-all-prompts.d.ts +6 -0
- package/dist/scripts/test-all-prompts.d.ts.map +1 -0
- package/dist/scripts/test-all-prompts.js +158 -0
- package/dist/scripts/test-all-prompts.js.map +1 -0
- package/dist/tools/balance/index.d.ts.map +1 -1
- package/dist/tools/balance/index.js +5 -4
- package/dist/tools/balance/index.js.map +1 -1
- package/dist/tools/creation/index.d.ts.map +1 -1
- package/dist/tools/creation/index.js +6 -11
- package/dist/tools/creation/index.js.map +1 -1
- package/dist/tools/index.d.ts +9 -2
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +58 -14
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/pools/fetchPoolDetailsForCalculation.d.ts +2 -3
- package/dist/tools/pools/fetchPoolDetailsForCalculation.d.ts.map +1 -1
- package/dist/tools/pools/fetchPoolDetailsForCalculation.js +5 -17
- package/dist/tools/pools/fetchPoolDetailsForCalculation.js.map +1 -1
- package/dist/tools/pools/index.d.ts.map +1 -1
- package/dist/tools/pools/index.js +51 -137
- package/dist/tools/pools/index.js.map +1 -1
- package/dist/tools/social/index.d.ts.map +1 -1
- package/dist/tools/social/index.js +4 -3
- package/dist/tools/social/index.js.map +1 -1
- package/dist/tools/trading/index.d.ts.map +1 -1
- package/dist/tools/trading/index.js +7 -21
- package/dist/tools/trading/index.js.map +1 -1
- package/dist/tools/utils/createWallet.d.ts +2 -3
- package/dist/tools/utils/createWallet.d.ts.map +1 -1
- package/dist/tools/utils/createWallet.js +8 -13
- package/dist/tools/utils/createWallet.js.map +1 -1
- package/dist/tools/utils/getAddress.d.ts +2 -3
- package/dist/tools/utils/getAddress.d.ts.map +1 -1
- package/dist/tools/utils/getAddress.js +6 -13
- package/dist/tools/utils/getAddress.js.map +1 -1
- package/dist/tools/utils/getConfig.d.ts +2 -3
- package/dist/tools/utils/getConfig.d.ts.map +1 -1
- package/dist/tools/utils/getConfig.js +5 -13
- package/dist/tools/utils/getConfig.js.map +1 -1
- package/dist/tools/utils/getEthereumAddress.d.ts +2 -3
- package/dist/tools/utils/getEthereumAddress.d.ts.map +1 -1
- package/dist/tools/utils/getEthereumAddress.js +6 -13
- package/dist/tools/utils/getEthereumAddress.js.map +1 -1
- package/dist/tools/utils/getUrlByTokenName.d.ts +2 -3
- package/dist/tools/utils/getUrlByTokenName.d.ts.map +1 -1
- package/dist/tools/utils/getUrlByTokenName.js +6 -20
- package/dist/tools/utils/getUrlByTokenName.js.map +1 -1
- package/dist/tools/utils/isTokenGraduated.d.ts +2 -3
- package/dist/tools/utils/isTokenGraduated.d.ts.map +1 -1
- package/dist/tools/utils/isTokenGraduated.js +6 -17
- package/dist/tools/utils/isTokenGraduated.js.map +1 -1
- package/dist/utils/default-values.d.ts +147 -0
- package/dist/utils/default-values.d.ts.map +1 -0
- package/dist/utils/default-values.js +177 -0
- package/dist/utils/default-values.js.map +1 -0
- package/dist/utils/error-handler.d.ts +9 -2
- package/dist/utils/error-handler.d.ts.map +1 -1
- package/dist/utils/error-handler.js +14 -59
- package/dist/utils/error-handler.js.map +1 -1
- package/dist/utils/error-templates.d.ts +96 -0
- package/dist/utils/error-templates.d.ts.map +1 -0
- package/dist/utils/error-templates.js +244 -0
- package/dist/utils/error-templates.js.map +1 -0
- package/dist/utils/tool-factory.d.ts +154 -0
- package/dist/utils/tool-factory.d.ts.map +1 -0
- package/dist/utils/tool-factory.js +194 -0
- package/dist/utils/tool-factory.js.map +1 -0
- package/dist/utils/tool-registry.d.ts +92 -0
- package/dist/utils/tool-registry.d.ts.map +1 -0
- package/dist/utils/tool-registry.js +227 -0
- package/dist/utils/tool-registry.js.map +1 -0
- package/jest.integration.config.js +70 -0
- package/package.json +9 -5
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error Message Templates
|
|
3
|
+
*
|
|
4
|
+
* Centralized error messages with AI-friendly tips for common error patterns.
|
|
5
|
+
* Eliminates duplication and ensures consistent error messaging.
|
|
6
|
+
*
|
|
7
|
+
* @see Phase 3.3 of refactoring plan
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Error template with AI-friendly tip
|
|
11
|
+
*/
|
|
12
|
+
export interface ErrorTemplate {
|
|
13
|
+
pattern: RegExp | string;
|
|
14
|
+
tip: string;
|
|
15
|
+
category: 'validation' | 'timeout' | 'format' | 'business-logic' | 'network';
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Limit validation errors
|
|
19
|
+
*/
|
|
20
|
+
export declare const LIMIT_ERRORS: {
|
|
21
|
+
readonly trade: {
|
|
22
|
+
readonly pattern: RegExp;
|
|
23
|
+
readonly tip: "💡 AI TIP: Trade and user operations have a maximum limit of 20. Use:\n- gala_launchpad_fetch_trades: limit ≤ 20\n- gala_launchpad_fetch_tokens_held: limit ≤ 20\n- gala_launchpad_fetch_tokens_created: limit ≤ 20\n\nSee docs/CONSTRAINTS-REFERENCE.md for details.";
|
|
24
|
+
readonly category: "validation";
|
|
25
|
+
};
|
|
26
|
+
readonly comment: {
|
|
27
|
+
readonly pattern: RegExp;
|
|
28
|
+
readonly tip: "💡 AI TIP: Comment operations have a maximum limit of 50. Use:\n- gala_launchpad_fetch_comments: limit ≤ 50\n\nSee docs/CONSTRAINTS-REFERENCE.md for details.";
|
|
29
|
+
readonly category: "validation";
|
|
30
|
+
};
|
|
31
|
+
readonly pool: {
|
|
32
|
+
readonly pattern: RegExp;
|
|
33
|
+
readonly tip: "💡 AI TIP: Pool operations have a maximum limit of 100. Use:\n- gala_launchpad_fetch_pools: limit ≤ 100\n\nSee docs/CONSTRAINTS-REFERENCE.md for details.";
|
|
34
|
+
readonly category: "validation";
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Token name validation errors
|
|
39
|
+
*/
|
|
40
|
+
export declare const TOKEN_NAME_ERROR: ErrorTemplate;
|
|
41
|
+
/**
|
|
42
|
+
* Token symbol validation errors
|
|
43
|
+
*/
|
|
44
|
+
export declare const TOKEN_SYMBOL_ERROR: ErrorTemplate;
|
|
45
|
+
/**
|
|
46
|
+
* Wallet address format errors
|
|
47
|
+
*/
|
|
48
|
+
export declare const ADDRESS_FORMAT_ERROR: ErrorTemplate;
|
|
49
|
+
/**
|
|
50
|
+
* WebSocket/trade timeout errors
|
|
51
|
+
*/
|
|
52
|
+
export declare const TRADE_TIMEOUT_ERROR: ErrorTemplate;
|
|
53
|
+
/**
|
|
54
|
+
* Slippage/amount errors
|
|
55
|
+
*/
|
|
56
|
+
export declare const SLIPPAGE_ERROR: ErrorTemplate;
|
|
57
|
+
/**
|
|
58
|
+
* Type parameter confusion
|
|
59
|
+
*/
|
|
60
|
+
export declare const TRADE_TYPE_ERROR: ErrorTemplate;
|
|
61
|
+
/**
|
|
62
|
+
* Social URL requirement errors
|
|
63
|
+
*/
|
|
64
|
+
export declare const SOCIAL_URL_ERROR: ErrorTemplate;
|
|
65
|
+
/**
|
|
66
|
+
* Generic validation error
|
|
67
|
+
*/
|
|
68
|
+
export declare const GENERIC_VALIDATION_ERROR: ErrorTemplate;
|
|
69
|
+
/**
|
|
70
|
+
* All error templates in priority order (checked sequentially)
|
|
71
|
+
*/
|
|
72
|
+
export declare const ERROR_TEMPLATES: ErrorTemplate[];
|
|
73
|
+
/**
|
|
74
|
+
* Finds the best matching error template for a message
|
|
75
|
+
*/
|
|
76
|
+
export declare function findErrorTemplate(message: string): ErrorTemplate | null;
|
|
77
|
+
/**
|
|
78
|
+
* Gets the AI-friendly tip for an error message
|
|
79
|
+
*/
|
|
80
|
+
export declare function getErrorTip(message: string): string | null;
|
|
81
|
+
/**
|
|
82
|
+
* Applies AI-friendly tip to error message
|
|
83
|
+
*/
|
|
84
|
+
export declare function enhanceErrorMessage(message: string): string;
|
|
85
|
+
/**
|
|
86
|
+
* Gets error category for an error message
|
|
87
|
+
*/
|
|
88
|
+
export declare function getErrorCategory(message: string): string;
|
|
89
|
+
export declare const errorTemplates: {
|
|
90
|
+
templates: ErrorTemplate[];
|
|
91
|
+
findTemplate: typeof findErrorTemplate;
|
|
92
|
+
getTip: typeof getErrorTip;
|
|
93
|
+
enhance: typeof enhanceErrorMessage;
|
|
94
|
+
getCategory: typeof getErrorCategory;
|
|
95
|
+
};
|
|
96
|
+
//# sourceMappingURL=error-templates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-templates.d.ts","sourceRoot":"","sources":["../../src/utils/error-templates.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,YAAY,GAAG,SAAS,GAAG,QAAQ,GAAG,gBAAgB,GAAG,SAAS,CAAC;CAC9E;AAMD;;GAEG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;CA2Bf,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,gBAAgB,EAAE,aAS9B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,aAShC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,oBAAoB,EAAE,aAOlC,CAAC;AAMF;;GAEG;AACH,eAAO,MAAM,mBAAmB,EAAE,aAcjC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,aAW5B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gBAAgB,EAAE,aAU9B,CAAC;AAMF;;GAEG;AACH,eAAO,MAAM,gBAAgB,EAAE,aAS9B,CAAC;AAMF;;GAEG;AACH,eAAO,MAAM,wBAAwB,EAAE,aAUtC,CAAC;AAMF;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,aAAa,EAe1C,CAAC;AAMF;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,aAAa,GAAG,IAAI,CAgBvE;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAG1D;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAG3D;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAGxD;AAMD,eAAO,MAAM,cAAc;;;;;;CAM1B,CAAC"}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Error Message Templates
|
|
4
|
+
*
|
|
5
|
+
* Centralized error messages with AI-friendly tips for common error patterns.
|
|
6
|
+
* Eliminates duplication and ensures consistent error messaging.
|
|
7
|
+
*
|
|
8
|
+
* @see Phase 3.3 of refactoring plan
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.errorTemplates = exports.ERROR_TEMPLATES = exports.GENERIC_VALIDATION_ERROR = exports.SOCIAL_URL_ERROR = exports.TRADE_TYPE_ERROR = exports.SLIPPAGE_ERROR = exports.TRADE_TIMEOUT_ERROR = exports.ADDRESS_FORMAT_ERROR = exports.TOKEN_SYMBOL_ERROR = exports.TOKEN_NAME_ERROR = exports.LIMIT_ERRORS = void 0;
|
|
12
|
+
exports.findErrorTemplate = findErrorTemplate;
|
|
13
|
+
exports.getErrorTip = getErrorTip;
|
|
14
|
+
exports.enhanceErrorMessage = enhanceErrorMessage;
|
|
15
|
+
exports.getErrorCategory = getErrorCategory;
|
|
16
|
+
// =============================================================================
|
|
17
|
+
// Validation Error Templates
|
|
18
|
+
// =============================================================================
|
|
19
|
+
/**
|
|
20
|
+
* Limit validation errors
|
|
21
|
+
*/
|
|
22
|
+
exports.LIMIT_ERRORS = {
|
|
23
|
+
trade: {
|
|
24
|
+
pattern: /Limit must be.*20/,
|
|
25
|
+
tip: `💡 AI TIP: Trade and user operations have a maximum limit of 20. Use:
|
|
26
|
+
- gala_launchpad_fetch_trades: limit ≤ 20
|
|
27
|
+
- gala_launchpad_fetch_tokens_held: limit ≤ 20
|
|
28
|
+
- gala_launchpad_fetch_tokens_created: limit ≤ 20
|
|
29
|
+
|
|
30
|
+
See docs/CONSTRAINTS-REFERENCE.md for details.`,
|
|
31
|
+
category: 'validation',
|
|
32
|
+
},
|
|
33
|
+
comment: {
|
|
34
|
+
pattern: /Limit must be.*50/,
|
|
35
|
+
tip: `💡 AI TIP: Comment operations have a maximum limit of 50. Use:
|
|
36
|
+
- gala_launchpad_fetch_comments: limit ≤ 50
|
|
37
|
+
|
|
38
|
+
See docs/CONSTRAINTS-REFERENCE.md for details.`,
|
|
39
|
+
category: 'validation',
|
|
40
|
+
},
|
|
41
|
+
pool: {
|
|
42
|
+
pattern: /Limit must be.*100/,
|
|
43
|
+
tip: `💡 AI TIP: Pool operations have a maximum limit of 100. Use:
|
|
44
|
+
- gala_launchpad_fetch_pools: limit ≤ 100
|
|
45
|
+
|
|
46
|
+
See docs/CONSTRAINTS-REFERENCE.md for details.`,
|
|
47
|
+
category: 'validation',
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Token name validation errors
|
|
52
|
+
*/
|
|
53
|
+
exports.TOKEN_NAME_ERROR = {
|
|
54
|
+
pattern: /token name.*(invalid|validation)/i,
|
|
55
|
+
tip: `💡 AI TIP: Token names must match pattern ^[a-z0-9_-]{2,20}$:
|
|
56
|
+
- Lowercase letters and numbers only
|
|
57
|
+
- Dashes and underscores allowed
|
|
58
|
+
- Length: 2-20 characters
|
|
59
|
+
- Valid examples: 'mytoken', 'test-token', 'token_123'
|
|
60
|
+
- Invalid: 'MyToken' (uppercase), 'a' (too short), 'my token' (space)`,
|
|
61
|
+
category: 'validation',
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Token symbol validation errors
|
|
65
|
+
*/
|
|
66
|
+
exports.TOKEN_SYMBOL_ERROR = {
|
|
67
|
+
pattern: /token symbol.*(invalid|validation)/i,
|
|
68
|
+
tip: `💡 AI TIP: Token symbols must match pattern ^[A-Z0-9]{2,10}$:
|
|
69
|
+
- Uppercase letters and numbers only
|
|
70
|
+
- No special characters
|
|
71
|
+
- Length: 2-10 characters
|
|
72
|
+
- Valid examples: 'MTK', 'TEST123', 'ABC'
|
|
73
|
+
- Invalid: 'mtk' (lowercase), 'A' (too short), 'MY-TOKEN' (dash)`,
|
|
74
|
+
category: 'validation',
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Wallet address format errors
|
|
78
|
+
*/
|
|
79
|
+
exports.ADDRESS_FORMAT_ERROR = {
|
|
80
|
+
pattern: /address.*(format|validation)/i,
|
|
81
|
+
tip: `💡 AI TIP: Wallet addresses must use format:
|
|
82
|
+
- Backend API: 'eth|{40-hex-chars}' (e.g., 'eth|abc123...')
|
|
83
|
+
- Convert from standard: address.startsWith('0x') ? \`eth|\${address.slice(2)}\` : address
|
|
84
|
+
- Most MCP tools expect 'eth|...' format`,
|
|
85
|
+
category: 'format',
|
|
86
|
+
};
|
|
87
|
+
// =============================================================================
|
|
88
|
+
// Trading Error Templates
|
|
89
|
+
// =============================================================================
|
|
90
|
+
/**
|
|
91
|
+
* WebSocket/trade timeout errors
|
|
92
|
+
*/
|
|
93
|
+
exports.TRADE_TIMEOUT_ERROR = {
|
|
94
|
+
pattern: /(timeout|WebSocket)/i,
|
|
95
|
+
tip: `💡 AI TIP: Trade execution timeouts often indicate incorrect expectedAmount parameter.
|
|
96
|
+
|
|
97
|
+
✅ CORRECT WORKFLOW:
|
|
98
|
+
1. Call calculate_buy_amount() or calculate_sell_amount()
|
|
99
|
+
2. Extract result.amount from response (e.g., "16843.7579794843252")
|
|
100
|
+
3. Use result.amount as expectedAmount in buy() or sell()
|
|
101
|
+
|
|
102
|
+
❌ WRONG: Using your input amount as expectedAmount
|
|
103
|
+
✅ RIGHT: Using calculated result.amount as expectedAmount
|
|
104
|
+
|
|
105
|
+
See docs/AI-AGENT-PATTERNS.md section "Gotcha #1" for examples.`,
|
|
106
|
+
category: 'timeout',
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Slippage/amount errors
|
|
110
|
+
*/
|
|
111
|
+
exports.SLIPPAGE_ERROR = {
|
|
112
|
+
pattern: /(slippage|amount.*expected)/i,
|
|
113
|
+
tip: `💡 AI TIP: expectedAmount must be the calculated output from calculate functions, NOT your input amount.
|
|
114
|
+
|
|
115
|
+
Example:
|
|
116
|
+
const calc = await calculateBuyAmount({ amount: '10', type: 'native', ... });
|
|
117
|
+
// calc.amount = "16843.7579794843252" <- Use THIS as expectedAmount
|
|
118
|
+
await buy({ amount: '10', expectedAmount: calc.amount, ... });
|
|
119
|
+
|
|
120
|
+
See docs/AI-AGENT-PATTERNS.md for complete trading workflow.`,
|
|
121
|
+
category: 'business-logic',
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* Type parameter confusion
|
|
125
|
+
*/
|
|
126
|
+
exports.TRADE_TYPE_ERROR = {
|
|
127
|
+
pattern: /type.*(native|token)/i,
|
|
128
|
+
tip: `💡 AI TIP: Trading type parameter:
|
|
129
|
+
- 'native': You specify GALA amount (most common)
|
|
130
|
+
Example: "I want to spend 10 GALA" → type: 'native', amount: '10'
|
|
131
|
+
- 'exact': You specify exact token amount
|
|
132
|
+
Example: "I want to buy exactly 1000 tokens" → type: 'exact', amount: '1000'
|
|
133
|
+
|
|
134
|
+
See docs/AI-AGENT-PATTERNS.md section "Gotcha #3" for details.`,
|
|
135
|
+
category: 'validation',
|
|
136
|
+
};
|
|
137
|
+
// =============================================================================
|
|
138
|
+
// Token Creation Error Templates
|
|
139
|
+
// =============================================================================
|
|
140
|
+
/**
|
|
141
|
+
* Social URL requirement errors
|
|
142
|
+
*/
|
|
143
|
+
exports.SOCIAL_URL_ERROR = {
|
|
144
|
+
pattern: /(social|URL.*required)/i,
|
|
145
|
+
tip: `💡 AI TIP: Token launch requires at least ONE social URL:
|
|
146
|
+
- websiteUrl (e.g., 'https://mytoken.com')
|
|
147
|
+
- twitterUrl (e.g., 'https://twitter.com/mytoken')
|
|
148
|
+
- telegramUrl (e.g., 'https://t.me/mytoken')
|
|
149
|
+
|
|
150
|
+
Provide at least one in launchToken() call.`,
|
|
151
|
+
category: 'validation',
|
|
152
|
+
};
|
|
153
|
+
// =============================================================================
|
|
154
|
+
// Generic Error Templates
|
|
155
|
+
// =============================================================================
|
|
156
|
+
/**
|
|
157
|
+
* Generic validation error
|
|
158
|
+
*/
|
|
159
|
+
exports.GENERIC_VALIDATION_ERROR = {
|
|
160
|
+
pattern: /(validation|invalid)/i,
|
|
161
|
+
tip: `💡 AI TIP: Check parameter formats in docs/AI-AGENT-PATTERNS.md
|
|
162
|
+
Common validation rules:
|
|
163
|
+
- tokenName: ^[a-z0-9_-]{2,20}$ (lowercase, 2-20 chars)
|
|
164
|
+
- tokenSymbol: ^[A-Z0-9]{2,10}$ (uppercase, 2-10 chars)
|
|
165
|
+
- address: 'eth|...' or '0x...' format (auto-normalized)
|
|
166
|
+
- amount: ^[0-9.]+$ (decimal string)
|
|
167
|
+
- limits: See CONSTRAINTS-REFERENCE.md`,
|
|
168
|
+
category: 'validation',
|
|
169
|
+
};
|
|
170
|
+
// =============================================================================
|
|
171
|
+
// Error Template Registry
|
|
172
|
+
// =============================================================================
|
|
173
|
+
/**
|
|
174
|
+
* All error templates in priority order (checked sequentially)
|
|
175
|
+
*/
|
|
176
|
+
exports.ERROR_TEMPLATES = [
|
|
177
|
+
// Specific errors first (higher priority)
|
|
178
|
+
exports.LIMIT_ERRORS.trade,
|
|
179
|
+
exports.LIMIT_ERRORS.comment,
|
|
180
|
+
exports.LIMIT_ERRORS.pool,
|
|
181
|
+
exports.TOKEN_NAME_ERROR,
|
|
182
|
+
exports.TOKEN_SYMBOL_ERROR,
|
|
183
|
+
exports.ADDRESS_FORMAT_ERROR,
|
|
184
|
+
exports.TRADE_TIMEOUT_ERROR,
|
|
185
|
+
exports.SLIPPAGE_ERROR,
|
|
186
|
+
exports.TRADE_TYPE_ERROR,
|
|
187
|
+
exports.SOCIAL_URL_ERROR,
|
|
188
|
+
// Generic errors last (lower priority)
|
|
189
|
+
exports.GENERIC_VALIDATION_ERROR,
|
|
190
|
+
];
|
|
191
|
+
// =============================================================================
|
|
192
|
+
// Template Matching Functions
|
|
193
|
+
// =============================================================================
|
|
194
|
+
/**
|
|
195
|
+
* Finds the best matching error template for a message
|
|
196
|
+
*/
|
|
197
|
+
function findErrorTemplate(message) {
|
|
198
|
+
for (const template of exports.ERROR_TEMPLATES) {
|
|
199
|
+
const pattern = template.pattern;
|
|
200
|
+
if (typeof pattern === 'string') {
|
|
201
|
+
if (message.includes(pattern)) {
|
|
202
|
+
return template;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
else if (pattern instanceof RegExp) {
|
|
206
|
+
if (pattern.test(message)) {
|
|
207
|
+
return template;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Gets the AI-friendly tip for an error message
|
|
215
|
+
*/
|
|
216
|
+
function getErrorTip(message) {
|
|
217
|
+
const template = findErrorTemplate(message);
|
|
218
|
+
return template ? template.tip : null;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Applies AI-friendly tip to error message
|
|
222
|
+
*/
|
|
223
|
+
function enhanceErrorMessage(message) {
|
|
224
|
+
const tip = getErrorTip(message);
|
|
225
|
+
return tip ? `${message}\n\n${tip}` : message;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Gets error category for an error message
|
|
229
|
+
*/
|
|
230
|
+
function getErrorCategory(message) {
|
|
231
|
+
const template = findErrorTemplate(message);
|
|
232
|
+
return template ? template.category : 'unknown';
|
|
233
|
+
}
|
|
234
|
+
// =============================================================================
|
|
235
|
+
// Export All
|
|
236
|
+
// =============================================================================
|
|
237
|
+
exports.errorTemplates = {
|
|
238
|
+
templates: exports.ERROR_TEMPLATES,
|
|
239
|
+
findTemplate: findErrorTemplate,
|
|
240
|
+
getTip: getErrorTip,
|
|
241
|
+
enhance: enhanceErrorMessage,
|
|
242
|
+
getCategory: getErrorCategory,
|
|
243
|
+
};
|
|
244
|
+
//# sourceMappingURL=error-templates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-templates.js","sourceRoot":"","sources":["../../src/utils/error-templates.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAqNH,8CAgBC;AAKD,kCAGC;AAKD,kDAGC;AAKD,4CAGC;AA9OD,gFAAgF;AAChF,6BAA6B;AAC7B,gFAAgF;AAEhF;;GAEG;AACU,QAAA,YAAY,GAAG;IAC1B,KAAK,EAAE;QACL,OAAO,EAAE,mBAAmB;QAC5B,GAAG,EAAE;;;;;+CAKsC;QAC3C,QAAQ,EAAE,YAAqB;KAChC;IACD,OAAO,EAAE;QACP,OAAO,EAAE,mBAAmB;QAC5B,GAAG,EAAE;;;+CAGsC;QAC3C,QAAQ,EAAE,YAAqB;KAChC;IACD,IAAI,EAAE;QACJ,OAAO,EAAE,oBAAoB;QAC7B,GAAG,EAAE;;;+CAGsC;QAC3C,QAAQ,EAAE,YAAqB;KAChC;CACO,CAAC;AAEX;;GAEG;AACU,QAAA,gBAAgB,GAAkB;IAC7C,OAAO,EAAE,mCAAmC;IAC5C,GAAG,EAAE;;;;;sEAK+D;IACpE,QAAQ,EAAE,YAAY;CACvB,CAAC;AAEF;;GAEG;AACU,QAAA,kBAAkB,GAAkB;IAC/C,OAAO,EAAE,qCAAqC;IAC9C,GAAG,EAAE;;;;;iEA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SAAS,CAAC;AAClD,CAAC;AAED,gFAAgF;AAChF,aAAa;AACb,gFAAgF;AAEnE,QAAA,cAAc,GAAG;IAC5B,SAAS,EAAE,uBAAe;IAC1B,YAAY,EAAE,iBAAiB;IAC/B,MAAM,EAAE,WAAW;IACnB,OAAO,EAAE,mBAAmB;IAC5B,WAAW,EAAE,gBAAgB;CAC9B,CAAC"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Factory Pattern Utilities
|
|
3
|
+
*
|
|
4
|
+
* DRY utilities for creating MCP tools with common patterns.
|
|
5
|
+
* Eliminates duplication across 47 tool definitions.
|
|
6
|
+
*
|
|
7
|
+
* @see Phase 2.1 of refactoring plan
|
|
8
|
+
*/
|
|
9
|
+
import type { MCPTool } from '../types/mcp.js';
|
|
10
|
+
import type { LaunchpadSDK } from '@gala-chain/launchpad-sdk';
|
|
11
|
+
/**
|
|
12
|
+
* Handler function that takes SDK and args, returns result
|
|
13
|
+
*/
|
|
14
|
+
type ToolHandler<T = any> = (sdk: LaunchpadSDK, args: any) => Promise<T>;
|
|
15
|
+
/**
|
|
16
|
+
* Simple handler that only needs SDK and tokenName
|
|
17
|
+
* Can return the result or null
|
|
18
|
+
*/
|
|
19
|
+
type SimpleTokenHandler<T = any> = (sdk: LaunchpadSDK, tokenName: string) => Promise<T | null>;
|
|
20
|
+
/**
|
|
21
|
+
* Boolean check handler that returns true/false
|
|
22
|
+
*/
|
|
23
|
+
type BooleanCheckHandler = (sdk: LaunchpadSDK, value: string) => Promise<boolean>;
|
|
24
|
+
/**
|
|
25
|
+
* No-parameter handler that only needs SDK, returns result
|
|
26
|
+
*/
|
|
27
|
+
type NoParamHandler<T = any> = (sdk: LaunchpadSDK) => T | Promise<T>;
|
|
28
|
+
/**
|
|
29
|
+
* Creates a simple fetch tool that takes tokenName and calls an SDK method
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* export const fetchPoolDetailsTool = createSimpleTokenFetchTool({
|
|
34
|
+
* name: 'gala_launchpad_fetch_pool_details',
|
|
35
|
+
* description: 'Get detailed pool state from GalaChain bonding curve',
|
|
36
|
+
* handler: (sdk, tokenName) => sdk.fetchPoolDetails(tokenName),
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare function createSimpleTokenFetchTool(config: {
|
|
41
|
+
name: string;
|
|
42
|
+
description: string;
|
|
43
|
+
handler: SimpleTokenHandler;
|
|
44
|
+
}): MCPTool;
|
|
45
|
+
/**
|
|
46
|
+
* Creates a boolean check tool (e.g., isTokenNameAvailable, isTokenSymbolAvailable)
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* export const checkTokenNameTool = createBooleanCheckTool({
|
|
51
|
+
* name: 'gala_launchpad_check_token_name',
|
|
52
|
+
* description: 'Check if token name is available',
|
|
53
|
+
* paramName: 'tokenName',
|
|
54
|
+
* paramSchema: TOKEN_NAME_SCHEMA,
|
|
55
|
+
* handler: (sdk, tokenName) => sdk.isTokenNameAvailable(tokenName),
|
|
56
|
+
* messages: {
|
|
57
|
+
* true: 'Token name is available',
|
|
58
|
+
* false: 'Token name is already taken',
|
|
59
|
+
* },
|
|
60
|
+
* });
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare function createBooleanCheckTool(config: {
|
|
64
|
+
name: string;
|
|
65
|
+
description: string;
|
|
66
|
+
paramName: string;
|
|
67
|
+
paramSchema: any;
|
|
68
|
+
handler: BooleanCheckHandler;
|
|
69
|
+
messages: {
|
|
70
|
+
true: string;
|
|
71
|
+
false: string;
|
|
72
|
+
};
|
|
73
|
+
}): MCPTool;
|
|
74
|
+
/**
|
|
75
|
+
* Creates a generic fetch tool with custom input schema and handler
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* export const fetchPoolsTool = createFetchTool({
|
|
80
|
+
* name: 'gala_launchpad_fetch_pools',
|
|
81
|
+
* description: 'Fetch token pools from Gala Launchpad',
|
|
82
|
+
* inputSchema: {
|
|
83
|
+
* type: 'object',
|
|
84
|
+
* properties: {
|
|
85
|
+
* type: { type: 'string', enum: ['recent', 'popular'] },
|
|
86
|
+
* page: PAGE_SCHEMA,
|
|
87
|
+
* limit: createLimitSchema('pool', 20),
|
|
88
|
+
* },
|
|
89
|
+
* },
|
|
90
|
+
* handler: (sdk, args) => sdk.fetchPools({
|
|
91
|
+
* type: args.type || 'recent',
|
|
92
|
+
* page: args.page || 1,
|
|
93
|
+
* limit: args.limit || 20,
|
|
94
|
+
* }),
|
|
95
|
+
* });
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
export declare function createFetchTool(config: {
|
|
99
|
+
name: string;
|
|
100
|
+
description: string;
|
|
101
|
+
inputSchema: {
|
|
102
|
+
type: 'object';
|
|
103
|
+
properties: Record<string, any>;
|
|
104
|
+
required?: string[];
|
|
105
|
+
};
|
|
106
|
+
handler: ToolHandler;
|
|
107
|
+
}): MCPTool;
|
|
108
|
+
/**
|
|
109
|
+
* Creates a resolution tool that maps tokenName to some resolved value
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* export const resolveVaultAddressTool = createResolutionTool({
|
|
114
|
+
* name: 'gala_launchpad_resolve_vault_address',
|
|
115
|
+
* description: 'Get GalaChain vault address for a token',
|
|
116
|
+
* resolver: (sdk, tokenName) => sdk.resolveVaultAddress(tokenName),
|
|
117
|
+
* resultKey: 'vaultAddress',
|
|
118
|
+
* });
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
export declare function createResolutionTool(config: {
|
|
122
|
+
name: string;
|
|
123
|
+
description: string;
|
|
124
|
+
resolver: SimpleTokenHandler<string | any>;
|
|
125
|
+
resultKey: string;
|
|
126
|
+
}): MCPTool;
|
|
127
|
+
/**
|
|
128
|
+
* Creates a no-parameter tool that only needs SDK instance
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```typescript
|
|
132
|
+
* export const getAddressTool = createNoParamTool({
|
|
133
|
+
* name: 'gala_launchpad_get_address',
|
|
134
|
+
* description: 'Get the GalaChain address format (eth|0x...) for the authenticated wallet.',
|
|
135
|
+
* handler: (sdk) => sdk.getAddress(),
|
|
136
|
+
* resultKey: 'address',
|
|
137
|
+
* });
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
export declare function createNoParamTool(config: {
|
|
141
|
+
name: string;
|
|
142
|
+
description: string;
|
|
143
|
+
handler: NoParamHandler;
|
|
144
|
+
resultKey?: string;
|
|
145
|
+
}): MCPTool;
|
|
146
|
+
export declare const toolFactory: {
|
|
147
|
+
createSimpleTokenFetchTool: typeof createSimpleTokenFetchTool;
|
|
148
|
+
createBooleanCheckTool: typeof createBooleanCheckTool;
|
|
149
|
+
createFetchTool: typeof createFetchTool;
|
|
150
|
+
createResolutionTool: typeof createResolutionTool;
|
|
151
|
+
createNoParamTool: typeof createNoParamTool;
|
|
152
|
+
};
|
|
153
|
+
export {};
|
|
154
|
+
//# sourceMappingURL=tool-factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-factory.d.ts","sourceRoot":"","sources":["../../src/utils/tool-factory.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAS9D;;GAEG;AACH,KAAK,WAAW,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;AAEzE;;;GAGG;AACH,KAAK,kBAAkB,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,KAAK,OAA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