vite-plugin-ai-diagnostic 1.0.3 → 1.0.5

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/dist/index.js CHANGED
@@ -1,28 +1,53 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var fs = require('fs');
6
- var langgraph = require('@langchain/langgraph');
7
- var openai = require('@langchain/openai');
8
- var messages = require('@langchain/core/messages');
9
- var vitePluginAiShared = require('vite-plugin-ai-shared');
10
- var path = require('path');
11
-
12
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
13
-
14
- var fs__default = /*#__PURE__*/_interopDefault(fs);
15
- var path__default = /*#__PURE__*/_interopDefault(path);
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
29
 
17
30
  // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ default: () => index_default,
34
+ vitePluginAIDiagnostic: () => vitePluginAIDiagnostic
35
+ });
36
+ module.exports = __toCommonJS(index_exports);
37
+ var import_fs2 = __toESM(require("fs"));
38
+
39
+ // src/langgraph.ts
40
+ var import_langgraph = require("@langchain/langgraph");
41
+ var import_openai = require("@langchain/openai");
42
+ var import_messages = require("@langchain/core/messages");
18
43
  var DiagnosticGraph = class {
19
44
  constructor(apiKey, apiUrl, model = "gpt-4", maxRetries = 3) {
20
45
  this.maxRetries = maxRetries;
21
- console.log("\u{1F527} [LangGraph] \u521D\u59CB\u5316 LLM...");
22
- console.log("\u{1F4DD} [\u914D\u7F6E] \u6A21\u578B:", model);
23
- console.log("\u{1F4DD} [\u914D\u7F6E] API URL:", apiUrl);
24
- console.log("\u{1F4DD} [\u914D\u7F6E] API Key:", apiKey ? "\u5DF2\u914D\u7F6E" : "\u672A\u914D\u7F6E");
25
- this.llm = new openai.ChatOpenAI({
46
+ console.log("🔧 [LangGraph] 初始化 LLM...");
47
+ console.log("📝 [配置] 模型:", model);
48
+ console.log("📝 [配置] API URL:", apiUrl);
49
+ console.log("📝 [配置] API Key:", apiKey ? "已配置" : "未配置");
50
+ this.llm = new import_openai.ChatOpenAI({
26
51
  openAIApiKey: apiKey,
27
52
  configuration: {
28
53
  baseURL: apiUrl
@@ -34,7 +59,7 @@ var DiagnosticGraph = class {
34
59
  this.graph = this.buildGraph();
35
60
  }
36
61
  buildGraph() {
37
- const workflow = new langgraph.StateGraph({
62
+ const workflow = new import_langgraph.StateGraph({
38
63
  channels: {
39
64
  error: null,
40
65
  analysis: null,
@@ -48,27 +73,27 @@ var DiagnosticGraph = class {
48
73
  });
49
74
  workflow.addNode("analyze", this.analyzeNode.bind(this));
50
75
  workflow.addNode("suggest", this.suggestNode.bind(this));
51
- workflow.addEdge(langgraph.START, "analyze");
76
+ workflow.addEdge(import_langgraph.START, "analyze");
52
77
  workflow.addEdge("analyze", "suggest");
53
- workflow.addEdge("suggest", langgraph.END);
78
+ workflow.addEdge("suggest", import_langgraph.END);
54
79
  return workflow.compile();
55
80
  }
56
81
  async analyzeNode(state) {
57
- console.log("\u{1F50D} [LangGraph] \u6B63\u5728\u5206\u6790\u9519\u8BEF...");
58
- const systemPrompt = new messages.SystemMessage(
59
- "\u4F60\u662F\u4E00\u4E2A\u4E13\u4E1A\u7684\u524D\u7AEF\u4EE3\u7801\u8BCA\u65AD\u4E13\u5BB6\uFF0C\u7CBE\u901A Vue3\u3001TypeScript\u3001Vite \u548C uni-app\u3002\u8BF7\u7B80\u6D01\u660E\u4E86\u5730\u5206\u6790\u95EE\u9898\u3002"
82
+ console.log("🔍 [LangGraph] 正在分析错误...");
83
+ const systemPrompt = new import_messages.SystemMessage(
84
+ "你是一个专业的前端代码诊断专家,精通 Vue3、TypeScript、Vite uni-app。请简洁明了地分析问题。"
60
85
  );
61
- const userPrompt = new messages.HumanMessage(`
62
- \u8BF7\u5206\u6790\u4EE5\u4E0B\u6784\u5EFA\u9519\u8BEF\uFF1A
86
+ const userPrompt = new import_messages.HumanMessage(`
87
+ 请分析以下构建错误:
63
88
 
64
- \u9519\u8BEF\u7C7B\u578B: ${state.error.type}
65
- \u9519\u8BEF\u4FE1\u606F: ${state.error.message}
66
- \u6587\u4EF6\u8DEF\u5F84: ${state.error.file || "\u672A\u77E5"}
89
+ 错误类型: ${state.error.type}
90
+ 错误信息: ${state.error.message}
91
+ 文件路径: ${state.error.file || "未知"}
67
92
 
68
- \u8BF7\u7B80\u6D01\u5730\u8BF4\u660E\uFF083-5\u53E5\u8BDD\uFF09\uFF1A
69
- 1. \u9519\u8BEF\u7684\u6839\u672C\u539F\u56E0
70
- 2. \u5F71\u54CD\u8303\u56F4
71
- 3. \u4E25\u91CD\u7A0B\u5EA6
93
+ 请简洁地说明(3-5句话):
94
+ 1. 错误的根本原因
95
+ 2. 影响范围
96
+ 3. 严重程度
72
97
  `);
73
98
  const response = await this.llm.invoke([systemPrompt, userPrompt]);
74
99
  const analysis = response.content.toString();
@@ -78,25 +103,25 @@ var DiagnosticGraph = class {
78
103
  };
79
104
  }
80
105
  async suggestNode(state) {
81
- console.log("\u{1F4A1} [LangGraph] \u6B63\u5728\u751F\u6210\u4FEE\u590D\u5EFA\u8BAE...");
82
- const userPrompt = new messages.HumanMessage(`
83
- \u57FA\u4E8E\u4EE5\u4E0B\u9519\u8BEF\u5206\u6790\uFF0C\u8BF7\u63D0\u4F9B\u5177\u4F53\u7684\u4FEE\u590D\u5EFA\u8BAE\uFF1A
106
+ console.log("💡 [LangGraph] 正在生成修复建议...");
107
+ const userPrompt = new import_messages.HumanMessage(`
108
+ 基于以下错误分析,请提供具体的修复建议:
84
109
 
85
- \u9519\u8BEF\u5206\u6790\uFF1A
110
+ 错误分析:
86
111
  ${state.analysis}
87
112
 
88
- \u9519\u8BEF\u8BE6\u60C5\uFF1A
89
- - \u7C7B\u578B: ${state.error.type}
90
- - \u4FE1\u606F: ${state.error.message}
91
- - \u6587\u4EF6: ${state.error.file || "\u672A\u77E5"}
113
+ 错误详情:
114
+ - 类型: ${state.error.type}
115
+ - 信息: ${state.error.message}
116
+ - 文件: ${state.error.file || "未知"}
92
117
 
93
- \u8BF7\u7B80\u6D01\u5730\u63D0\u4F9B\uFF1A
94
- 1. \u5177\u4F53\u7684\u4FEE\u590D\u6B65\u9AA4\uFF083-5\u6B65\u5373\u53EF\uFF09
95
- 2. \u9700\u8981\u4FEE\u6539\u7684\u4EE3\u7801\u4F4D\u7F6E\uFF08\u884C\u53F7\uFF09
96
- 3. \u4FEE\u6539\u540E\u7684\u4EE3\u7801\u793A\u4F8B\uFF08\u53EA\u663E\u793A\u5173\u952E\u90E8\u5206\uFF09
97
- 4. \u4E00\u53E5\u8BDD\u9884\u9632\u5EFA\u8BAE
118
+ 请简洁地提供:
119
+ 1. 具体的修复步骤(3-5步即可)
120
+ 2. 需要修改的代码位置(行号)
121
+ 3. 修改后的代码示例(只显示关键部分)
122
+ 4. 一句话预防建议
98
123
 
99
- \u6CE8\u610F\uFF1A\u8BF7\u76F4\u63A5\u7ED9\u51FA\u5EFA\u8BAE\uFF0C\u4E0D\u8981\u91CD\u590D\u9519\u8BEF\u5206\u6790\u7684\u5185\u5BB9\u3002
124
+ 注意:请直接给出建议,不要重复错误分析的内容。
100
125
  `);
101
126
  const response = await this.llm.invoke([...state.messages, userPrompt]);
102
127
  const suggestion = response.content.toString();
@@ -186,12 +211,12 @@ ${state.analysis}
186
211
  messages: []
187
212
  };
188
213
  try {
189
- console.log("\u{1F680} [LangGraph] \u542F\u52A8\u8BCA\u65AD\u5DE5\u4F5C\u6D41...\n");
214
+ console.log("🚀 [LangGraph] 启动诊断工作流...\n");
190
215
  const result = await this.graph.invoke(initialState);
191
- console.log("\u2728 [LangGraph] \u8BCA\u65AD\u5DE5\u4F5C\u6D41\u5B8C\u6210\n");
216
+ console.log(" [LangGraph] 诊断工作流完成\n");
192
217
  return result;
193
218
  } catch (error2) {
194
- console.error("\u274C [LangGraph] \u5DE5\u4F5C\u6D41\u6267\u884C\u5931\u8D25:", error2.message);
219
+ console.error(" [LangGraph] 工作流执行失败:", error2.message);
195
220
  throw error2;
196
221
  }
197
222
  }
@@ -211,8 +236,8 @@ var AIErrorDiagnostic = class {
211
236
  async diagnose(error, autoFix = false) {
212
237
  if (!this.options.apiKey) {
213
238
  return {
214
- analysis: "\u672A\u914D\u7F6E API Key\uFF0C\u65E0\u6CD5\u4F7F\u7528 AI \u8BCA\u65AD\u529F\u80FD",
215
- suggestion: "\u8BF7\u5728 .env \u6587\u4EF6\u4E2D\u914D\u7F6E OPENAI_API_KEY",
239
+ analysis: "未配置 API Key,无法使用 AI 诊断功能",
240
+ suggestion: "请在 .env 文件中配置 OPENAI_API_KEY",
216
241
  fixedCode: void 0,
217
242
  filePath: void 0
218
243
  };
@@ -227,10 +252,10 @@ var AIErrorDiagnostic = class {
227
252
  filePath: void 0
228
253
  };
229
254
  } catch (error2) {
230
- console.error("\u274C AI \u8BCA\u65AD\u5931\u8D25\uFF1A", error2.message);
255
+ console.error(" AI 诊断失败:", error2.message);
231
256
  return {
232
- analysis: `\u8BCA\u65AD\u8FC7\u7A0B\u51FA\u9519: ${error2.message}`,
233
- suggestion: "\u8BF7\u68C0\u67E5 API \u914D\u7F6E\u548C\u7F51\u7EDC\u8FDE\u63A5",
257
+ analysis: `诊断过程出错: ${error2.message}`,
258
+ suggestion: "请检查 API 配置和网络连接",
234
259
  fixedCode: void 0,
235
260
  filePath: void 0
236
261
  };
@@ -252,6 +277,13 @@ var AIErrorDiagnostic = class {
252
277
  // }
253
278
  // }
254
279
  };
280
+
281
+ // src/index.ts
282
+ var import_vite_plugin_ai_shared = require("vite-plugin-ai-shared");
283
+
284
+ // src/reporter.ts
285
+ var import_fs = __toESM(require("fs"));
286
+ var import_path = __toESM(require("path"));
255
287
  var DiagnosticReporter = class {
256
288
  /**
257
289
  * 生成报告(根据配置生成多种格式)
@@ -277,7 +309,7 @@ var DiagnosticReporter = class {
277
309
  <head>
278
310
  <meta charset="UTF-8">
279
311
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
280
- <title>AI \u8BCA\u65AD\u62A5\u544A</title>
312
+ <title>AI 诊断报告</title>
281
313
  <style>
282
314
  * { margin: 0; padding: 0; box-sizing: border-box; }
283
315
  body {
@@ -436,48 +468,48 @@ var DiagnosticReporter = class {
436
468
  <body>
437
469
  <div class="container">
438
470
  <div class="header">
439
- <h1>\u{1F916} AI \u8BCA\u65AD\u62A5\u544A</h1>
440
- <div class="time">\u751F\u6210\u65F6\u95F4: ${report.timestamp}</div>
471
+ <h1>🤖 AI 诊断报告</h1>
472
+ <div class="time">生成时间: ${report.timestamp}</div>
441
473
  </div>
442
474
 
443
475
  <div class="content">
444
- <!-- \u9519\u8BEF\u4FE1\u606F -->
476
+ <!-- 错误信息 -->
445
477
  <div class="section">
446
- <div class="section-title">\u274C \u9519\u8BEF\u4FE1\u606F</div>
478
+ <div class="section-title">❌ 错误信息</div>
447
479
  <div class="error-box">
448
480
  <span class="error-type">${report.error.type}</span>
449
481
  <div class="error-message">${this.escapeHtml(
450
482
  report.error.message
451
483
  )}</div>
452
- <div class="error-file">\u{1F4C2} ${report.error.file}</div>
484
+ <div class="error-file">📂 ${report.error.file}</div>
453
485
  ${report.error.stack ? `<div class="stack-trace">${this.escapeHtml(
454
486
  report.error.stack
455
487
  )}</div>` : ""}
456
488
  </div>
457
489
  </div>
458
490
 
459
- <!-- AI \u5206\u6790 -->
491
+ <!-- AI 分析 -->
460
492
  <div class="section">
461
- <div class="section-title">\u{1F50D} AI \u5206\u6790</div>
493
+ <div class="section-title">🔍 AI 分析</div>
462
494
  <div class="analysis-box">
463
495
  ${this.formatText(report.analysis)}
464
496
  </div>
465
497
  </div>
466
498
 
467
- <!-- \u4FEE\u590D\u5EFA\u8BAE -->
499
+ <!-- 修复建议 -->
468
500
  <div class="section">
469
- <div class="section-title">\u{1F4A1} \u4FEE\u590D\u5EFA\u8BAE</div>
501
+ <div class="section-title">💡 修复建议</div>
470
502
  <div class="suggestion-box">
471
503
  ${this.formatText(report.suggestion)}
472
504
  </div>
473
505
  </div>
474
506
 
475
- <!-- \u4FEE\u590D\u72B6\u6001 -->
507
+ <!-- 修复状态 -->
476
508
  <div class="section">
477
- <div class="section-title">\u{1F527} \u4FEE\u590D\u72B6\u6001</div>
478
- ${report.fixed ? `<div class="fixed-badge">\u2705 \u5DF2\u81EA\u52A8\u4FEE\u590D</div>
479
- <div style="margin-top: 10px; color: #666;">\u4FEE\u590D\u6587\u4EF6: <code>${report.fixedFilePath}</code></div>` : `<div class="not-fixed-badge">\u26A0\uFE0F \u672A\u81EA\u52A8\u4FEE\u590D</div>
480
- <div style="margin-top: 10px; color: #666;">\u8BF7\u6839\u636E\u4E0A\u8FF0\u5EFA\u8BAE\u624B\u52A8\u4FEE\u590D</div>`}
509
+ <div class="section-title">🔧 修复状态</div>
510
+ ${report.fixed ? `<div class="fixed-badge">✅ 已自动修复</div>
511
+ <div style="margin-top: 10px; color: #666;">修复文件: <code>${report.fixedFilePath}</code></div>` : `<div class="not-fixed-badge">⚠️ 未自动修复</div>
512
+ <div style="margin-top: 10px; color: #666;">请根据上述建议手动修复</div>`}
481
513
  </div>
482
514
  </div>
483
515
 
@@ -489,14 +521,14 @@ var DiagnosticReporter = class {
489
521
  </body>
490
522
  </html>
491
523
  `.trim();
492
- const reportsDir = path__default.default.resolve(process.cwd(), "ai-reports");
493
- if (!fs__default.default.existsSync(reportsDir)) {
494
- fs__default.default.mkdirSync(reportsDir, { recursive: true });
524
+ const reportsDir = import_path.default.resolve(process.cwd(), "ai-reports");
525
+ if (!import_fs.default.existsSync(reportsDir)) {
526
+ import_fs.default.mkdirSync(reportsDir, { recursive: true });
495
527
  }
496
- const reportPath = path__default.default.resolve(reportsDir, "diagnostic-report.html");
497
- fs__default.default.writeFileSync(reportPath, html, "utf-8");
528
+ const reportPath = import_path.default.resolve(reportsDir, "diagnostic-report.html");
529
+ import_fs.default.writeFileSync(reportPath, html, "utf-8");
498
530
  console.log(`
499
- \u{1F4C4} \u8BCA\u65AD\u62A5\u544A\u5DF2\u751F\u6210: ${reportPath}
531
+ 📄 诊断报告已生成: ${reportPath}
500
532
  `);
501
533
  }
502
534
  /**
@@ -534,22 +566,22 @@ var DiagnosticReporter = class {
534
566
  * 生成 Markdown 报告
535
567
  */
536
568
  static async generateMarkdownReport(report) {
537
- const markdown = `# \u{1F916} AI \u8BCA\u65AD\u62A5\u544A
569
+ const markdown = `# 🤖 AI 诊断报告
538
570
 
539
- **\u751F\u6210\u65F6\u95F4**: ${report.timestamp}
571
+ **生成时间**: ${report.timestamp}
540
572
 
541
573
  ---
542
574
 
543
- ## \u274C \u9519\u8BEF\u4FE1\u606F
575
+ ## 错误信息
544
576
 
545
- **\u7C7B\u578B**: \`${report.error.type}\`
546
- **\u6587\u4EF6**: \`${report.error.file}\`
547
- **\u6D88\u606F**:
577
+ **类型**: \`${report.error.type}\`
578
+ **文件**: \`${report.error.file}\`
579
+ **消息**:
548
580
  \`\`\`
549
581
  ${report.error.message}
550
582
  \`\`\`
551
583
 
552
- ${report.error.stack ? `**\u5806\u6808\u8DDF\u8E2A**:
584
+ ${report.error.stack ? `**堆栈跟踪**:
553
585
  \`\`\`
554
586
  ${report.error.stack}
555
587
  \`\`\`
@@ -557,38 +589,38 @@ ${report.error.stack}
557
589
 
558
590
  ---
559
591
 
560
- ## \u{1F50D} AI \u5206\u6790
592
+ ## 🔍 AI 分析
561
593
 
562
594
  ${report.analysis}
563
595
 
564
596
  ---
565
597
 
566
- ## \u{1F4A1} \u4FEE\u590D\u5EFA\u8BAE
598
+ ## 💡 修复建议
567
599
 
568
600
  ${report.suggestion}
569
601
 
570
602
  ---
571
603
 
572
- ## \u{1F527} \u4FEE\u590D\u72B6\u6001
604
+ ## 🔧 修复状态
573
605
 
574
- ${report.fixed ? `\u2705 **\u5DF2\u81EA\u52A8\u4FEE\u590D**
606
+ ${report.fixed ? `✅ **已自动修复**
575
607
 
576
- \u4FEE\u590D\u6587\u4EF6: \`${report.fixedFilePath}\`` : `\u26A0\uFE0F **\u672A\u81EA\u52A8\u4FEE\u590D**
608
+ 修复文件: \`${report.fixedFilePath}\`` : `⚠️ **未自动修复**
577
609
 
578
- \u8BF7\u6839\u636E\u4E0A\u8FF0\u5EFA\u8BAE\u624B\u52A8\u4FEE\u590D`}
610
+ 请根据上述建议手动修复`}
579
611
 
580
612
  ---
581
613
 
582
614
  *AI Diagnostic Plugin v1.0.0*
583
615
  *Powered by LangGraph & OpenAI*
584
616
  `;
585
- const reportsDir = path__default.default.resolve(process.cwd(), "ai-reports");
586
- if (!fs__default.default.existsSync(reportsDir)) {
587
- fs__default.default.mkdirSync(reportsDir, { recursive: true });
617
+ const reportsDir = import_path.default.resolve(process.cwd(), "ai-reports");
618
+ if (!import_fs.default.existsSync(reportsDir)) {
619
+ import_fs.default.mkdirSync(reportsDir, { recursive: true });
588
620
  }
589
- const reportPath = path__default.default.resolve(reportsDir, "diagnostic-report.md");
590
- fs__default.default.writeFileSync(reportPath, markdown, "utf-8");
591
- console.log(`\u{1F4C4} Markdown \u62A5\u544A\u5DF2\u751F\u6210: ${reportPath}`);
621
+ const reportPath = import_path.default.resolve(reportsDir, "diagnostic-report.md");
622
+ import_fs.default.writeFileSync(reportPath, markdown, "utf-8");
623
+ console.log(`📄 Markdown 报告已生成: ${reportPath}`);
592
624
  }
593
625
  /**
594
626
  * 生成 JSON 报告
@@ -612,13 +644,13 @@ ${report.fixed ? `\u2705 **\u5DF2\u81EA\u52A8\u4FEE\u590D**
612
644
  filePath: report.fixedFilePath || null
613
645
  }
614
646
  };
615
- const reportsDir = path__default.default.resolve(process.cwd(), "ai-reports");
616
- if (!fs__default.default.existsSync(reportsDir)) {
617
- fs__default.default.mkdirSync(reportsDir, { recursive: true });
647
+ const reportsDir = import_path.default.resolve(process.cwd(), "ai-reports");
648
+ if (!import_fs.default.existsSync(reportsDir)) {
649
+ import_fs.default.mkdirSync(reportsDir, { recursive: true });
618
650
  }
619
- const reportPath = path__default.default.resolve(reportsDir, "diagnostic-report.json");
620
- fs__default.default.writeFileSync(reportPath, JSON.stringify(jsonReport, null, 2), "utf-8");
621
- console.log(`\u{1F4C4} JSON \u62A5\u544A\u5DF2\u751F\u6210: ${reportPath}`);
651
+ const reportPath = import_path.default.resolve(reportsDir, "diagnostic-report.json");
652
+ import_fs.default.writeFileSync(reportPath, JSON.stringify(jsonReport, null, 2), "utf-8");
653
+ console.log(`📄 JSON 报告已生成: ${reportPath}`);
622
654
  }
623
655
  };
624
656
 
@@ -649,38 +681,38 @@ function vitePluginAIDiagnostic(options = {}) {
649
681
  async function processError(error) {
650
682
  const errorKey = `${error.file}:${error.message}`;
651
683
  if (processedErrors.has(errorKey)) {
652
- console.log("\u{1F50D} [\u8C03\u8BD5] \u8DF3\u8FC7\u91CD\u590D\u9519\u8BEF:", errorKey);
684
+ console.log("🔍 [调试] 跳过重复错误:", errorKey);
653
685
  return;
654
686
  }
655
687
  processedErrors.add(errorKey);
656
688
  try {
657
- console.log("\n\u26A0\uFE0F \u68C0\u6D4B\u5230\u9519\u8BEF\uFF0C\u6B63\u5728\u4F7F\u7528 AI \u5206\u6790...\n");
658
- console.log(`\u{1F4DD} \u9519\u8BEF\u4FE1\u606F: ${error.message}`);
659
- console.log(`\u{1F4C2} \u6587\u4EF6\u8DEF\u5F84: ${error.file || "\u672A\u77E5"}`);
689
+ console.log("\n⚠️ 检测到错误,正在使用 AI 分析...\n");
690
+ console.log(`📝 错误信息: ${error.message}`);
691
+ console.log(`📂 文件路径: ${error.file || "未知"}`);
660
692
  console.log(
661
- `\u{1F4C4} \u4EE3\u7801\u957F\u5EA6: ${error.code ? error.code.length + " \u5B57\u7B26" : "\u65E0"}`
693
+ `📄 代码长度: ${error.code ? error.code.length + " 字符" : ""}`
662
694
  );
663
- console.log(`\u{1F527} \u81EA\u52A8\u4FEE\u590D: ${autoFix ? "\u662F" : "\u5426"}
695
+ console.log(`🔧 自动修复: ${autoFix ? "" : ""}
664
696
  `);
665
697
  if (!error.file || !error.code) {
666
- console.log("\u26A0\uFE0F \u8DF3\u8FC7\u6B64\u9519\u8BEF\uFF1A\u7F3A\u5C11\u6587\u4EF6\u8DEF\u5F84\u6216\u4EE3\u7801\u5185\u5BB9\n");
698
+ console.log("⚠️ 跳过此错误:缺少文件路径或代码内容\n");
667
699
  return;
668
700
  }
669
701
  const result = await diagnostic.diagnose(error, autoFix);
670
702
  if (output.console !== false) {
671
- console.log("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501");
672
- console.log("\u{1F50D} \u9519\u8BEF\u5206\u6790\uFF1A");
703
+ console.log("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
704
+ console.log("🔍 错误分析:");
673
705
  console.log(result.analysis);
674
- console.log("\n\u{1F4A1} \u4FEE\u590D\u5EFA\u8BAE\uFF1A");
706
+ console.log("\n💡 修复建议:");
675
707
  console.log(result.suggestion);
676
708
  if (result.fixedCode && result.filePath) {
677
- console.log("\n\u2705 \u5DF2\u81EA\u52A8\u4FEE\u590D\u4EE3\u7801");
678
- console.log("\u4FEE\u590D\u7684\u6587\u4EF6\uFF1A", result.filePath);
679
- console.log("\n\u{1F4A1} \u8BF7\u91CD\u65B0\u8FD0\u884C\u6784\u5EFA\u547D\u4EE4");
709
+ console.log("\n 已自动修复代码");
710
+ console.log("修复的文件:", result.filePath);
711
+ console.log("\n💡 请重新运行构建命令");
680
712
  } else if (autoFix) {
681
- console.log("\n\u26A0\uFE0F \u65E0\u6CD5\u81EA\u52A8\u4FEE\u590D\uFF1AAI \u672A\u751F\u6210\u4FEE\u590D\u4EE3\u7801");
713
+ console.log("\n⚠️ 无法自动修复:AI 未生成修复代码");
682
714
  }
683
- console.log("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\n");
715
+ console.log("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n");
684
716
  }
685
717
  const report = {
686
718
  timestamp: (/* @__PURE__ */ new Date()).toLocaleString("zh-CN"),
@@ -697,7 +729,7 @@ function vitePluginAIDiagnostic(options = {}) {
697
729
  };
698
730
  await DiagnosticReporter.generate(report, output);
699
731
  } catch (err) {
700
- console.error("\u274C AI \u8BCA\u65AD\u5931\u8D25\uFF1A", err.message);
732
+ console.error(" AI 诊断失败:", err.message);
701
733
  }
702
734
  }
703
735
  return {
@@ -705,18 +737,18 @@ function vitePluginAIDiagnostic(options = {}) {
705
737
  // 确保插件在其他插件之后执行,以捕获更多错误
706
738
  enforce: "post",
707
739
  configResolved(config) {
708
- console.log("\n\u{1F916} AI \u8BCA\u65AD\u52A9\u624B\u5DF2\u542F\u52A8...");
709
- console.log(`\u2699\uFE0F \u81EA\u52A8\u4FEE\u590D: ${autoFix ? "\u2705 \u5DF2\u542F\u7528" : "\u274C \u672A\u542F\u7528"}`);
710
- console.log(`\u{1F4DD} \u6839\u76EE\u5F55: ${config.root}`);
740
+ console.log("\n🤖 AI 诊断助手已启动...");
741
+ console.log(`⚙️ 自动修复: ${autoFix ? " 已启用" : " 未启用"}`);
742
+ console.log(`📝 根目录: ${config.root}`);
711
743
  console.log(
712
- `\u{1F4DD} \u5165\u53E3: ${config.build.rollupOptions?.input || "index.html"}
744
+ `📝 入口: ${config.build.rollupOptions?.input || "index.html"}
713
745
  `
714
746
  );
715
747
  },
716
748
  buildStart() {
717
749
  buildErrors = [];
718
750
  processedErrors.clear();
719
- console.log("\u{1F50D} [\u8C03\u8BD5] buildStart \u5DF2\u6267\u884C");
751
+ console.log("🔍 [调试] buildStart 已执行");
720
752
  },
721
753
  // 解析模块时捕获错误
722
754
  async resolveId(source, importer, options2) {
@@ -729,10 +761,10 @@ function vitePluginAIDiagnostic(options = {}) {
729
761
  // Rollup 钩子:模块解析完成后调用
730
762
  moduleParsed(moduleInfo) {
731
763
  if (moduleInfo.meta && moduleInfo.meta.error) {
732
- console.log("\n\u26A0\uFE0F moduleParsed \u68C0\u6D4B\u5230\u9519\u8BEF:", moduleInfo.id);
764
+ console.log("\n⚠️ moduleParsed 检测到错误:", moduleInfo.id);
733
765
  let code = void 0;
734
- if (moduleInfo.id && fs__default.default.existsSync(moduleInfo.id)) {
735
- code = fs__default.default.readFileSync(moduleInfo.id, "utf-8");
766
+ if (moduleInfo.id && import_fs2.default.existsSync(moduleInfo.id)) {
767
+ code = import_fs2.default.readFileSync(moduleInfo.id, "utf-8");
736
768
  }
737
769
  const errorInfo = {
738
770
  type: "module",
@@ -745,18 +777,18 @@ function vitePluginAIDiagnostic(options = {}) {
745
777
  }
746
778
  },
747
779
  buildEnd(error) {
748
- console.log("\u{1F50D} [\u8C03\u8BD5] buildEnd \u5DF2\u6267\u884C, \u6709\u9519\u8BEF:", !!error);
780
+ console.log("🔍 [调试] buildEnd 已执行, 有错误:", !!error);
749
781
  if (error) {
750
- console.log("\n\u26A0\uFE0F buildEnd \u6355\u83B7\u5230\u9519\u8BEF:", error.message);
751
- const realFilePath = vitePluginAiShared.extractSourceFile(error, lastTransformFile);
782
+ console.log("\n⚠️ buildEnd 捕获到错误:", error.message);
783
+ const realFilePath = (0, import_vite_plugin_ai_shared.extractSourceFile)(error, lastTransformFile);
752
784
  let code = void 0;
753
- if (realFilePath && fs__default.default.existsSync(realFilePath)) {
785
+ if (realFilePath && import_fs2.default.existsSync(realFilePath)) {
754
786
  try {
755
- code = fs__default.default.readFileSync(realFilePath, "utf-8");
756
- console.log(`\u{1F4C2} \u8BFB\u53D6\u6E90\u6587\u4EF6\u6210\u529F: ${realFilePath}`);
757
- console.log(`\u{1F4C4} \u6E90\u6587\u4EF6\u957F\u5EA6: ${code.length} \u5B57\u7B26`);
787
+ code = import_fs2.default.readFileSync(realFilePath, "utf-8");
788
+ console.log(`📂 读取源文件成功: ${realFilePath}`);
789
+ console.log(`📄 源文件长度: ${code.length} 字符`);
758
790
  } catch (e) {
759
- console.warn("\u26A0\uFE0F \u65E0\u6CD5\u8BFB\u53D6\u6587\u4EF6:", realFilePath);
791
+ console.warn("⚠️ 无法读取文件:", realFilePath);
760
792
  }
761
793
  }
762
794
  const errorInfo = {
@@ -771,21 +803,21 @@ function vitePluginAIDiagnostic(options = {}) {
771
803
  },
772
804
  // Rollup 输出生成阶段的钩子
773
805
  renderStart(outputOptions, inputOptions) {
774
- console.log("\u{1F50D} [\u8C03\u8BD5] renderStart \u5DF2\u6267\u884C");
806
+ console.log("🔍 [调试] renderStart 已执行");
775
807
  },
776
808
  renderError(error) {
777
- console.log("\u{1F50D} [\u8C03\u8BD5] renderError \u5DF2\u6267\u884C");
809
+ console.log("🔍 [调试] renderError 已执行");
778
810
  if (!error) return;
779
- console.log("\n\u26A0\uFE0F renderError \u6355\u83B7\u5230\u9519\u8BEF:", error.message);
780
- const realFilePath = vitePluginAiShared.extractSourceFile(error, lastTransformFile);
811
+ console.log("\n⚠️ renderError 捕获到错误:", error.message);
812
+ const realFilePath = (0, import_vite_plugin_ai_shared.extractSourceFile)(error, lastTransformFile);
781
813
  let code = void 0;
782
- if (realFilePath && fs__default.default.existsSync(realFilePath)) {
814
+ if (realFilePath && import_fs2.default.existsSync(realFilePath)) {
783
815
  try {
784
- code = fs__default.default.readFileSync(realFilePath, "utf-8");
785
- console.log(`\u{1F4C2} \u8BFB\u53D6\u6E90\u6587\u4EF6\u6210\u529F: ${realFilePath}`);
786
- console.log(`\u{1F4C4} \u6E90\u6587\u4EF6\u957F\u5EA6: ${code.length} \u5B57\u7B26`);
816
+ code = import_fs2.default.readFileSync(realFilePath, "utf-8");
817
+ console.log(`📂 读取源文件成功: ${realFilePath}`);
818
+ console.log(`📄 源文件长度: ${code.length} 字符`);
787
819
  } catch (e) {
788
- console.warn("\u26A0\uFE0F \u65E0\u6CD5\u8BFB\u53D6\u6587\u4EF6:", realFilePath);
820
+ console.warn("⚠️ 无法读取文件:", realFilePath);
789
821
  }
790
822
  }
791
823
  const errorInfo = {
@@ -799,20 +831,20 @@ function vitePluginAIDiagnostic(options = {}) {
799
831
  },
800
832
  // 监听所有阶段的错误
801
833
  watchChange(id, change) {
802
- console.log("\u{1F50D} [\u8C03\u8BD5] watchChange:", id);
834
+ console.log("🔍 [调试] watchChange:", id);
803
835
  },
804
836
  async closeBundle() {
805
837
  if (buildErrors.length > 0) {
806
838
  console.log(
807
839
  `
808
- \u{1F50D} [\u8C03\u8BD5] closeBundle \u68C0\u6D4B\u5230 ${buildErrors.length} \u4E2A\u9519\u8BEF
840
+ 🔍 [调试] closeBundle 检测到 ${buildErrors.length} 个错误
809
841
  `
810
842
  );
811
843
  for (const error of buildErrors) {
812
844
  await processError(error);
813
845
  }
814
846
  } else {
815
- console.log("\u2728 \u6784\u5EFA\u5B8C\u6210\uFF0C\u672A\u68C0\u6D4B\u5230\u9519\u8BEF\n");
847
+ console.log(" 构建完成,未检测到错误\n");
816
848
  }
817
849
  },
818
850
  transform(code, id) {
@@ -820,7 +852,7 @@ function vitePluginAIDiagnostic(options = {}) {
820
852
  try {
821
853
  return null;
822
854
  } catch (error) {
823
- console.log("\n\u26A0\uFE0F transform \u6355\u83B7\u5230\u9519\u8BEF:", error.message);
855
+ console.log("\n⚠️ transform 捕获到错误:", error.message);
824
856
  buildErrors.push({
825
857
  type: "transform",
826
858
  message: error.message,
@@ -834,8 +866,8 @@ function vitePluginAIDiagnostic(options = {}) {
834
866
  };
835
867
  }
836
868
  var index_default = vitePluginAIDiagnostic;
837
-
838
- exports.default = index_default;
839
- exports.vitePluginAIDiagnostic = vitePluginAIDiagnostic;
840
- //# sourceMappingURL=index.js.map
869
+ // Annotate the CommonJS export names for ESM import in node:
870
+ 0 && (module.exports = {
871
+ vitePluginAIDiagnostic
872
+ });
841
873
  //# sourceMappingURL=index.js.map