mcp-probe-kit 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/LICENSE +22 -0
- package/README.md +607 -0
- package/build/index.d.ts +2 -0
- package/build/index.js +553 -0
- package/build/tools/check_deps.d.ts +13 -0
- package/build/tools/check_deps.js +204 -0
- package/build/tools/code_review.d.ts +13 -0
- package/build/tools/code_review.js +138 -0
- package/build/tools/convert.d.ts +13 -0
- package/build/tools/convert.js +575 -0
- package/build/tools/debug.d.ts +13 -0
- package/build/tools/debug.js +78 -0
- package/build/tools/detect_shell.d.ts +6 -0
- package/build/tools/detect_shell.js +138 -0
- package/build/tools/explain.d.ts +13 -0
- package/build/tools/explain.js +369 -0
- package/build/tools/fix.d.ts +13 -0
- package/build/tools/fix.js +290 -0
- package/build/tools/genapi.d.ts +13 -0
- package/build/tools/genapi.js +152 -0
- package/build/tools/genchangelog.d.ts +13 -0
- package/build/tools/genchangelog.js +227 -0
- package/build/tools/gencommit.d.ts +13 -0
- package/build/tools/gencommit.js +95 -0
- package/build/tools/gendoc.d.ts +13 -0
- package/build/tools/gendoc.js +208 -0
- package/build/tools/genpr.d.ts +13 -0
- package/build/tools/genpr.js +173 -0
- package/build/tools/genreadme.d.ts +13 -0
- package/build/tools/genreadme.js +613 -0
- package/build/tools/gensql.d.ts +13 -0
- package/build/tools/gensql.js +307 -0
- package/build/tools/gentest.d.ts +13 -0
- package/build/tools/gentest.js +155 -0
- package/build/tools/genui.d.ts +13 -0
- package/build/tools/genui.js +781 -0
- package/build/tools/index.d.ts +22 -0
- package/build/tools/index.js +22 -0
- package/build/tools/init_project.d.ts +13 -0
- package/build/tools/init_project.js +142 -0
- package/build/tools/init_setting.d.ts +13 -0
- package/build/tools/init_setting.js +47 -0
- package/build/tools/perf.d.ts +13 -0
- package/build/tools/perf.js +359 -0
- package/build/tools/refactor.d.ts +13 -0
- package/build/tools/refactor.js +318 -0
- package/build/tools/resolve_conflict.d.ts +13 -0
- package/build/tools/resolve_conflict.js +338 -0
- package/build/tools/split.d.ts +13 -0
- package/build/tools/split.js +577 -0
- package/package.json +66 -0
|
@@ -0,0 +1,575 @@
|
|
|
1
|
+
// convert 工具实现
|
|
2
|
+
export async function convert(args) {
|
|
3
|
+
try {
|
|
4
|
+
const code = args?.code || "";
|
|
5
|
+
const from = args?.from || "";
|
|
6
|
+
const to = args?.to || "";
|
|
7
|
+
const message = `请转换以下代码:
|
|
8
|
+
|
|
9
|
+
📝 **源代码**:
|
|
10
|
+
${code || "请提供需要转换的代码"}
|
|
11
|
+
|
|
12
|
+
🔄 **转换类型**:${from} → ${to}
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## 代码转换指南
|
|
17
|
+
|
|
18
|
+
### 支持的转换类型
|
|
19
|
+
|
|
20
|
+
#### 语言转换
|
|
21
|
+
- JavaScript → TypeScript
|
|
22
|
+
- TypeScript → JavaScript
|
|
23
|
+
- Python → JavaScript
|
|
24
|
+
- CommonJS → ESM
|
|
25
|
+
|
|
26
|
+
#### 框架转换
|
|
27
|
+
- Class Component → Hooks
|
|
28
|
+
- Vue 2 → Vue 3
|
|
29
|
+
- AngularJS → React
|
|
30
|
+
- jQuery → Vanilla JS
|
|
31
|
+
|
|
32
|
+
#### 样式转换
|
|
33
|
+
- CSS → Tailwind CSS
|
|
34
|
+
- SCSS → CSS-in-JS
|
|
35
|
+
- Styled-components → Emotion
|
|
36
|
+
|
|
37
|
+
#### 数据格式转换
|
|
38
|
+
- JSON → TypeScript Interface
|
|
39
|
+
- GraphQL → REST
|
|
40
|
+
- XML → JSON
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## 转换示例
|
|
45
|
+
|
|
46
|
+
### 1️⃣ JavaScript → TypeScript
|
|
47
|
+
|
|
48
|
+
**JavaScript (Before):**
|
|
49
|
+
\`\`\`javascript
|
|
50
|
+
function calculateTotal(items, discount) {
|
|
51
|
+
const subtotal = items.reduce((sum, item) => {
|
|
52
|
+
return sum + item.price * item.quantity;
|
|
53
|
+
}, 0);
|
|
54
|
+
|
|
55
|
+
return discount ? subtotal * (1 - discount) : subtotal;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const order = {
|
|
59
|
+
id: '123',
|
|
60
|
+
items: [
|
|
61
|
+
{ name: 'Book', price: 29.99, quantity: 2 },
|
|
62
|
+
{ name: 'Pen', price: 1.99, quantity: 5 }
|
|
63
|
+
],
|
|
64
|
+
discount: 0.1
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const total = calculateTotal(order.items, order.discount);
|
|
68
|
+
\`\`\`
|
|
69
|
+
|
|
70
|
+
**TypeScript (After):**
|
|
71
|
+
\`\`\`typescript
|
|
72
|
+
interface Item {
|
|
73
|
+
name: string;
|
|
74
|
+
price: number;
|
|
75
|
+
quantity: number;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
interface Order {
|
|
79
|
+
id: string;
|
|
80
|
+
items: Item[];
|
|
81
|
+
discount?: number;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function calculateTotal(items: Item[], discount?: number): number {
|
|
85
|
+
const subtotal = items.reduce((sum, item) => {
|
|
86
|
+
return sum + item.price * item.quantity;
|
|
87
|
+
}, 0);
|
|
88
|
+
|
|
89
|
+
return discount ? subtotal * (1 - discount) : subtotal;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const order: Order = {
|
|
93
|
+
id: '123',
|
|
94
|
+
items: [
|
|
95
|
+
{ name: 'Book', price: 29.99, quantity: 2 },
|
|
96
|
+
{ name: 'Pen', price: 1.99, quantity: 5 }
|
|
97
|
+
],
|
|
98
|
+
discount: 0.1
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const total: number = calculateTotal(order.items, order.discount);
|
|
102
|
+
\`\`\`
|
|
103
|
+
|
|
104
|
+
**✅ 转换要点**:
|
|
105
|
+
1. 添加类型接口定义
|
|
106
|
+
2. 函数参数和返回值添加类型注解
|
|
107
|
+
3. 变量添加类型声明(可选)
|
|
108
|
+
4. 可选属性用 \`?\` 标记
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
### 2️⃣ Class Component → React Hooks
|
|
113
|
+
|
|
114
|
+
**Class Component (Before):**
|
|
115
|
+
\`\`\`jsx
|
|
116
|
+
import React, { Component } from 'react';
|
|
117
|
+
|
|
118
|
+
class UserProfile extends Component {
|
|
119
|
+
constructor(props) {
|
|
120
|
+
super(props);
|
|
121
|
+
this.state = {
|
|
122
|
+
user: null,
|
|
123
|
+
loading: true,
|
|
124
|
+
error: null
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
componentDidMount() {
|
|
129
|
+
this.fetchUser();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
componentDidUpdate(prevProps) {
|
|
133
|
+
if (prevProps.userId !== this.props.userId) {
|
|
134
|
+
this.fetchUser();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
componentWillUnmount() {
|
|
139
|
+
this.abortController?.abort();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
async fetchUser() {
|
|
143
|
+
this.setState({ loading: true });
|
|
144
|
+
this.abortController = new AbortController();
|
|
145
|
+
|
|
146
|
+
try {
|
|
147
|
+
const response = await fetch(\`/api/users/\${this.props.userId}\`, {
|
|
148
|
+
signal: this.abortController.signal
|
|
149
|
+
});
|
|
150
|
+
const user = await response.json();
|
|
151
|
+
this.setState({ user, loading: false });
|
|
152
|
+
} catch (error) {
|
|
153
|
+
if (error.name !== 'AbortError') {
|
|
154
|
+
this.setState({ error: error.message, loading: false });
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
render() {
|
|
160
|
+
const { user, loading, error } = this.state;
|
|
161
|
+
|
|
162
|
+
if (loading) return <div>Loading...</div>;
|
|
163
|
+
if (error) return <div>Error: {error}</div>;
|
|
164
|
+
if (!user) return null;
|
|
165
|
+
|
|
166
|
+
return (
|
|
167
|
+
<div>
|
|
168
|
+
<h1>{user.name}</h1>
|
|
169
|
+
<p>{user.email}</p>
|
|
170
|
+
</div>
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export default UserProfile;
|
|
176
|
+
\`\`\`
|
|
177
|
+
|
|
178
|
+
**Hooks (After):**
|
|
179
|
+
\`\`\`tsx
|
|
180
|
+
import React, { useState, useEffect } from 'react';
|
|
181
|
+
|
|
182
|
+
interface User {
|
|
183
|
+
name: string;
|
|
184
|
+
email: string;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
interface UserProfileProps {
|
|
188
|
+
userId: string;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const UserProfile: React.FC<UserProfileProps> = ({ userId }) => {
|
|
192
|
+
const [user, setUser] = useState<User | null>(null);
|
|
193
|
+
const [loading, setLoading] = useState(true);
|
|
194
|
+
const [error, setError] = useState<string | null>(null);
|
|
195
|
+
|
|
196
|
+
useEffect(() => {
|
|
197
|
+
const abortController = new AbortController();
|
|
198
|
+
|
|
199
|
+
async function fetchUser() {
|
|
200
|
+
setLoading(true);
|
|
201
|
+
setError(null);
|
|
202
|
+
|
|
203
|
+
try {
|
|
204
|
+
const response = await fetch(\`/api/users/\${userId}\`, {
|
|
205
|
+
signal: abortController.signal
|
|
206
|
+
});
|
|
207
|
+
const userData = await response.json();
|
|
208
|
+
setUser(userData);
|
|
209
|
+
} catch (err) {
|
|
210
|
+
if (err instanceof Error && err.name !== 'AbortError') {
|
|
211
|
+
setError(err.message);
|
|
212
|
+
}
|
|
213
|
+
} finally {
|
|
214
|
+
setLoading(false);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
fetchUser();
|
|
219
|
+
|
|
220
|
+
return () => {
|
|
221
|
+
abortController.abort();
|
|
222
|
+
};
|
|
223
|
+
}, [userId]); // userId 变化时重新获取
|
|
224
|
+
|
|
225
|
+
if (loading) return <div>Loading...</div>;
|
|
226
|
+
if (error) return <div>Error: {error}</div>;
|
|
227
|
+
if (!user) return null;
|
|
228
|
+
|
|
229
|
+
return (
|
|
230
|
+
<div>
|
|
231
|
+
<h1>{user.name}</h1>
|
|
232
|
+
<p>{user.email}</p>
|
|
233
|
+
</div>
|
|
234
|
+
);
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
export default UserProfile;
|
|
238
|
+
\`\`\`
|
|
239
|
+
|
|
240
|
+
**✅ 转换要点**:
|
|
241
|
+
1. \`constructor\` + \`this.state\` → \`useState\`
|
|
242
|
+
2. \`componentDidMount\` + \`componentDidUpdate\` → \`useEffect\`
|
|
243
|
+
3. \`componentWillUnmount\` → \`useEffect\` 清理函数
|
|
244
|
+
4. \`this.props\` → 函数参数
|
|
245
|
+
5. \`this.setState\` → \`setState\` 函数
|
|
246
|
+
6. 类方法 → 函数内部函数或自定义 Hook
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
### 3️⃣ Promises → Async/Await
|
|
251
|
+
|
|
252
|
+
**Promises (Before):**
|
|
253
|
+
\`\`\`javascript
|
|
254
|
+
function getUserData(userId) {
|
|
255
|
+
return fetch(\`/api/users/\${userId}\`)
|
|
256
|
+
.then(response => {
|
|
257
|
+
if (!response.ok) {
|
|
258
|
+
throw new Error('User not found');
|
|
259
|
+
}
|
|
260
|
+
return response.json();
|
|
261
|
+
})
|
|
262
|
+
.then(user => {
|
|
263
|
+
return fetch(\`/api/posts?userId=\${user.id}\`);
|
|
264
|
+
})
|
|
265
|
+
.then(response => response.json())
|
|
266
|
+
.then(posts => {
|
|
267
|
+
return { user, posts };
|
|
268
|
+
})
|
|
269
|
+
.catch(error => {
|
|
270
|
+
console.error('Error:', error);
|
|
271
|
+
throw error;
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// 使用
|
|
276
|
+
getUserData('123')
|
|
277
|
+
.then(data => console.log(data))
|
|
278
|
+
.catch(error => console.error(error));
|
|
279
|
+
\`\`\`
|
|
280
|
+
|
|
281
|
+
**Async/Await (After):**
|
|
282
|
+
\`\`\`javascript
|
|
283
|
+
async function getUserData(userId) {
|
|
284
|
+
try {
|
|
285
|
+
const userResponse = await fetch(\`/api/users/\${userId}\`);
|
|
286
|
+
|
|
287
|
+
if (!userResponse.ok) {
|
|
288
|
+
throw new Error('User not found');
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
const user = await userResponse.json();
|
|
292
|
+
const postsResponse = await fetch(\`/api/posts?userId=\${user.id}\`);
|
|
293
|
+
const posts = await postsResponse.json();
|
|
294
|
+
|
|
295
|
+
return { user, posts };
|
|
296
|
+
} catch (error) {
|
|
297
|
+
console.error('Error:', error);
|
|
298
|
+
throw error;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// 使用
|
|
303
|
+
try {
|
|
304
|
+
const data = await getUserData('123');
|
|
305
|
+
console.log(data);
|
|
306
|
+
} catch (error) {
|
|
307
|
+
console.error(error);
|
|
308
|
+
}
|
|
309
|
+
\`\`\`
|
|
310
|
+
|
|
311
|
+
**✅ 转换要点**:
|
|
312
|
+
1. 函数前加 \`async\` 关键字
|
|
313
|
+
2. \`.then()\` → \`await\`
|
|
314
|
+
3. \`.catch()\` → \`try/catch\`
|
|
315
|
+
4. Promise 链条变为顺序执行
|
|
316
|
+
5. 代码更易读,像同步代码
|
|
317
|
+
|
|
318
|
+
---
|
|
319
|
+
|
|
320
|
+
### 4️⃣ CSS → Tailwind CSS
|
|
321
|
+
|
|
322
|
+
**CSS (Before):**
|
|
323
|
+
\`\`\`css
|
|
324
|
+
.button {
|
|
325
|
+
display: inline-flex;
|
|
326
|
+
align-items: center;
|
|
327
|
+
justify-content: center;
|
|
328
|
+
padding: 0.5rem 1rem;
|
|
329
|
+
font-size: 0.875rem;
|
|
330
|
+
font-weight: 500;
|
|
331
|
+
border-radius: 0.375rem;
|
|
332
|
+
background-color: #3b82f6;
|
|
333
|
+
color: white;
|
|
334
|
+
transition: background-color 0.2s;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
.button:hover {
|
|
338
|
+
background-color: #2563eb;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
.button:disabled {
|
|
342
|
+
opacity: 0.5;
|
|
343
|
+
cursor: not-allowed;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
.button-lg {
|
|
347
|
+
padding: 0.75rem 1.5rem;
|
|
348
|
+
font-size: 1rem;
|
|
349
|
+
}
|
|
350
|
+
\`\`\`
|
|
351
|
+
|
|
352
|
+
**Tailwind CSS (After):**
|
|
353
|
+
\`\`\`jsx
|
|
354
|
+
// 基础按钮
|
|
355
|
+
<button className="inline-flex items-center justify-center px-4 py-2 text-sm font-medium rounded-md bg-blue-600 text-white transition-colors hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed">
|
|
356
|
+
Button
|
|
357
|
+
</button>
|
|
358
|
+
|
|
359
|
+
// 大按钮
|
|
360
|
+
<button className="inline-flex items-center justify-center px-6 py-3 text-base font-medium rounded-md bg-blue-600 text-white transition-colors hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed">
|
|
361
|
+
Large Button
|
|
362
|
+
</button>
|
|
363
|
+
|
|
364
|
+
// 或使用组件抽象
|
|
365
|
+
const Button = ({ size = 'default', children, ...props }) => {
|
|
366
|
+
const sizeClasses = {
|
|
367
|
+
default: 'px-4 py-2 text-sm',
|
|
368
|
+
lg: 'px-6 py-3 text-base'
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
return (
|
|
372
|
+
<button
|
|
373
|
+
className={\`
|
|
374
|
+
inline-flex items-center justify-center font-medium rounded-md
|
|
375
|
+
bg-blue-600 text-white transition-colors
|
|
376
|
+
hover:bg-blue-700
|
|
377
|
+
disabled:opacity-50 disabled:cursor-not-allowed
|
|
378
|
+
\${sizeClasses[size]}
|
|
379
|
+
\`}
|
|
380
|
+
{...props}
|
|
381
|
+
>
|
|
382
|
+
{children}
|
|
383
|
+
</button>
|
|
384
|
+
);
|
|
385
|
+
};
|
|
386
|
+
\`\`\`
|
|
387
|
+
|
|
388
|
+
**✅ Tailwind 类名对照表**:
|
|
389
|
+
|
|
390
|
+
| CSS 属性 | Tailwind 类名 |
|
|
391
|
+
|----------|---------------|
|
|
392
|
+
| \`display: flex\` | \`flex\` |
|
|
393
|
+
| \`align-items: center\` | \`items-center\` |
|
|
394
|
+
| \`justify-content: center\` | \`justify-center\` |
|
|
395
|
+
| \`padding: 0.5rem 1rem\` | \`px-4 py-2\` |
|
|
396
|
+
| \`font-size: 0.875rem\` | \`text-sm\` |
|
|
397
|
+
| \`font-weight: 500\` | \`font-medium\` |
|
|
398
|
+
| \`border-radius: 0.375rem\` | \`rounded-md\` |
|
|
399
|
+
| \`background-color: #3b82f6\` | \`bg-blue-600\` |
|
|
400
|
+
| \`color: white\` | \`text-white\` |
|
|
401
|
+
|
|
402
|
+
---
|
|
403
|
+
|
|
404
|
+
### 5️⃣ CommonJS → ESM
|
|
405
|
+
|
|
406
|
+
**CommonJS (Before):**
|
|
407
|
+
\`\`\`javascript
|
|
408
|
+
// math.js
|
|
409
|
+
function add(a, b) {
|
|
410
|
+
return a + b;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
function multiply(a, b) {
|
|
414
|
+
return a * b;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
module.exports = {
|
|
418
|
+
add,
|
|
419
|
+
multiply
|
|
420
|
+
};
|
|
421
|
+
|
|
422
|
+
// main.js
|
|
423
|
+
const { add, multiply } = require('./math');
|
|
424
|
+
const lodash = require('lodash');
|
|
425
|
+
|
|
426
|
+
console.log(add(2, 3));
|
|
427
|
+
\`\`\`
|
|
428
|
+
|
|
429
|
+
**ESM (After):**
|
|
430
|
+
\`\`\`javascript
|
|
431
|
+
// math.js
|
|
432
|
+
export function add(a, b) {
|
|
433
|
+
return a + b;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
export function multiply(a, b) {
|
|
437
|
+
return a * b;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
// 或默认导出
|
|
441
|
+
// export default { add, multiply };
|
|
442
|
+
|
|
443
|
+
// main.js
|
|
444
|
+
import { add, multiply } from './math.js';
|
|
445
|
+
import lodash from 'lodash';
|
|
446
|
+
|
|
447
|
+
console.log(add(2, 3));
|
|
448
|
+
\`\`\`
|
|
449
|
+
|
|
450
|
+
**✅ 转换要点**:
|
|
451
|
+
1. \`module.exports\` → \`export\` / \`export default\`
|
|
452
|
+
2. \`require()\` → \`import\`
|
|
453
|
+
3. 文件扩展名:ESM 中通常需要 \`.js\`
|
|
454
|
+
4. \`package.json\` 需要设置 \`"type": "module"\`
|
|
455
|
+
|
|
456
|
+
---
|
|
457
|
+
|
|
458
|
+
### 6️⃣ JSON → TypeScript Interface
|
|
459
|
+
|
|
460
|
+
**JSON (Before):**
|
|
461
|
+
\`\`\`json
|
|
462
|
+
{
|
|
463
|
+
"id": "123",
|
|
464
|
+
"name": "John Doe",
|
|
465
|
+
"email": "john@example.com",
|
|
466
|
+
"age": 30,
|
|
467
|
+
"isActive": true,
|
|
468
|
+
"roles": ["admin", "user"],
|
|
469
|
+
"address": {
|
|
470
|
+
"street": "123 Main St",
|
|
471
|
+
"city": "New York",
|
|
472
|
+
"zipCode": "10001"
|
|
473
|
+
},
|
|
474
|
+
"metadata": {
|
|
475
|
+
"createdAt": "2024-01-01T00:00:00Z",
|
|
476
|
+
"updatedAt": "2024-01-15T00:00:00Z"
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
\`\`\`
|
|
480
|
+
|
|
481
|
+
**TypeScript Interface (After):**
|
|
482
|
+
\`\`\`typescript
|
|
483
|
+
interface Address {
|
|
484
|
+
street: string;
|
|
485
|
+
city: string;
|
|
486
|
+
zipCode: string;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
interface Metadata {
|
|
490
|
+
createdAt: string; // 或 Date
|
|
491
|
+
updatedAt: string; // 或 Date
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
interface User {
|
|
495
|
+
id: string;
|
|
496
|
+
name: string;
|
|
497
|
+
email: string;
|
|
498
|
+
age: number;
|
|
499
|
+
isActive: boolean;
|
|
500
|
+
roles: string[];
|
|
501
|
+
address: Address;
|
|
502
|
+
metadata: Metadata;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
// 使用
|
|
506
|
+
const user: User = {
|
|
507
|
+
id: "123",
|
|
508
|
+
name: "John Doe",
|
|
509
|
+
email: "john@example.com",
|
|
510
|
+
age: 30,
|
|
511
|
+
isActive: true,
|
|
512
|
+
roles: ["admin", "user"],
|
|
513
|
+
address: {
|
|
514
|
+
street: "123 Main St",
|
|
515
|
+
city: "New York",
|
|
516
|
+
zipCode: "10001"
|
|
517
|
+
},
|
|
518
|
+
metadata: {
|
|
519
|
+
createdAt: "2024-01-01T00:00:00Z",
|
|
520
|
+
updatedAt: "2024-01-15T00:00:00Z"
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
\`\`\`
|
|
524
|
+
|
|
525
|
+
---
|
|
526
|
+
|
|
527
|
+
## 转换注意事项
|
|
528
|
+
|
|
529
|
+
### ⚠️ 潜在问题
|
|
530
|
+
|
|
531
|
+
1. **类型安全**
|
|
532
|
+
- 转换后需要添加类型检查
|
|
533
|
+
- 注意 null/undefined 处理
|
|
534
|
+
|
|
535
|
+
2. **API 差异**
|
|
536
|
+
- 不同框架的生命周期不同
|
|
537
|
+
- 状态管理方式不同
|
|
538
|
+
|
|
539
|
+
3. **性能影响**
|
|
540
|
+
- 某些转换可能影响性能
|
|
541
|
+
- 需要测试和优化
|
|
542
|
+
|
|
543
|
+
4. **依赖更新**
|
|
544
|
+
- 检查依赖包兼容性
|
|
545
|
+
- 更新 package.json
|
|
546
|
+
|
|
547
|
+
---
|
|
548
|
+
|
|
549
|
+
现在请根据需求进行代码转换,提供:
|
|
550
|
+
1. 转换后的完整代码
|
|
551
|
+
2. 关键变更说明
|
|
552
|
+
3. 潜在问题提示
|
|
553
|
+
4. 迁移步骤(如需要)`;
|
|
554
|
+
return {
|
|
555
|
+
content: [
|
|
556
|
+
{
|
|
557
|
+
type: "text",
|
|
558
|
+
text: message,
|
|
559
|
+
},
|
|
560
|
+
],
|
|
561
|
+
};
|
|
562
|
+
}
|
|
563
|
+
catch (error) {
|
|
564
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
565
|
+
return {
|
|
566
|
+
content: [
|
|
567
|
+
{
|
|
568
|
+
type: "text",
|
|
569
|
+
text: `❌ 代码转换失败: ${errorMessage}`,
|
|
570
|
+
},
|
|
571
|
+
],
|
|
572
|
+
isError: true,
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// debug 工具实现
|
|
2
|
+
export async function debug(args) {
|
|
3
|
+
try {
|
|
4
|
+
const error = args?.error || "";
|
|
5
|
+
const context = args?.context || "";
|
|
6
|
+
const message = `请分析以下错误并提供调试策略:
|
|
7
|
+
|
|
8
|
+
❌ **错误信息**:
|
|
9
|
+
${error || "请提供错误信息(错误消息、堆栈跟踪等)"}
|
|
10
|
+
|
|
11
|
+
📋 **上下文**:
|
|
12
|
+
${context || "请提供相关代码或场景描述"}
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
🔍 **调试分析步骤**:
|
|
17
|
+
|
|
18
|
+
**第一步:错误分类**
|
|
19
|
+
- 确定错误类型(语法错误、运行时错误、逻辑错误)
|
|
20
|
+
- 评估错误严重程度(崩溃、功能异常、性能问题)
|
|
21
|
+
|
|
22
|
+
**第二步:问题定位**
|
|
23
|
+
1. 分析错误堆栈,确定出错位置
|
|
24
|
+
2. 识别可能的原因(至少列出 3 个)
|
|
25
|
+
3. 检查相关代码上下文
|
|
26
|
+
|
|
27
|
+
**第三步:调试策略**
|
|
28
|
+
按优先级列出调试步骤:
|
|
29
|
+
1. 快速验证:最可能的原因
|
|
30
|
+
2. 添加日志:关键变量和执行路径
|
|
31
|
+
3. 断点调试:问题代码段
|
|
32
|
+
4. 单元测试:隔离问题
|
|
33
|
+
5. 回归测试:确认修复
|
|
34
|
+
|
|
35
|
+
**第四步:解决方案**
|
|
36
|
+
- 临时方案(Quick Fix)
|
|
37
|
+
- 根本方案(Root Cause Fix)
|
|
38
|
+
- 预防措施(Prevention)
|
|
39
|
+
|
|
40
|
+
**第五步:验证清单**
|
|
41
|
+
- [ ] 错误已修复
|
|
42
|
+
- [ ] 测试通过
|
|
43
|
+
- [ ] 无副作用
|
|
44
|
+
- [ ] 添加防御性代码
|
|
45
|
+
- [ ] 更新文档
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
💡 **常见错误模式**:
|
|
50
|
+
- NullPointerException → 检查空值处理
|
|
51
|
+
- ReferenceError → 检查变量声明和作用域
|
|
52
|
+
- TypeError → 检查类型转换和数据结构
|
|
53
|
+
- TimeoutError → 检查异步操作和网络请求
|
|
54
|
+
- MemoryError → 检查内存泄漏和资源释放
|
|
55
|
+
|
|
56
|
+
现在请按照上述步骤分析错误并提供具体的调试方案。`;
|
|
57
|
+
return {
|
|
58
|
+
content: [
|
|
59
|
+
{
|
|
60
|
+
type: "text",
|
|
61
|
+
text: message,
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
68
|
+
return {
|
|
69
|
+
content: [
|
|
70
|
+
{
|
|
71
|
+
type: "text",
|
|
72
|
+
text: `❌ 生成调试策略失败: ${errorMessage}`,
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
isError: true,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|