@lyy0709/contextweaver 1.0.4 → 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/{SearchService-P5C5QXMP.js → SearchService-XJK3QPME.js} +5 -5
- package/dist/{browser-BCGLGKKF.js → browser-KXAZ5XPA.js} +3 -3
- package/dist/{chunk-QCUCU74R.js → chunk-4UZ6HY4R.js} +2 -2
- package/dist/{chunk-BGKNHLHY.js → chunk-DFP44KR3.js} +4 -4
- package/dist/{chunk-7MWEWZ7J.js → chunk-DYDQ5MXJ.js} +5 -5
- package/dist/{chunk-YVMNY2OU.js → chunk-FTZUNP5A.js} +30 -13
- package/dist/chunk-GJDN3DU3.js +72 -0
- package/dist/{chunk-53ESQDZT.js → chunk-NBYBKXQM.js} +2 -2
- package/dist/chunk-TJH5L5ZP.js +312 -0
- package/dist/{chunk-CACJOY3O.js → chunk-VEHIYQIP.js} +7 -7
- package/dist/{claude-YONOS6YG.js → claude-7LFFSKWO.js} +17 -4
- package/dist/codebaseRetrieval-B4L6LZ2A.js +12 -0
- package/dist/{config-VZD37BMJ.js → config-63VM3EWD.js} +6 -2
- package/dist/enhancer-XRW4OV7P.js +13 -0
- package/dist/{gemini-54NRBSPH.js → gemini-IY5XGK3X.js} +17 -5
- package/dist/index.js +10 -10
- package/dist/{lock-AQIUW3N3.js → lock-IR2WY4LT.js} +3 -3
- package/dist/logger-VW3UIQPH.js +10 -0
- package/dist/mcp/main.js +2 -2
- package/dist/{openai-VRQNTJQZ.js → openai-OZ4QWGLQ.js} +17 -4
- package/dist/scanner-2JPKUPFO.js +11 -0
- package/dist/{server-TGCR7VVZ.js → server-MQ6ONERG.js} +14 -10
- package/dist/{server-JOJGOORY.js → server-PI2QNIYF.js} +9 -9
- package/package.json +1 -1
- package/dist/chunk-PZTRC7VF.js +0 -187
- package/dist/codebaseRetrieval-N6ABFZ24.js +0 -12
- package/dist/enhancer-PO6KKYUT.js +0 -9
- package/dist/logger-REOCZNEY.js +0 -10
- package/dist/scanner-QUWFCQUV.js +0 -11
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
codebaseRetrievalSchema,
|
|
3
|
+
handleCodebaseRetrieval
|
|
4
|
+
} from "./chunk-VEHIYQIP.js";
|
|
5
|
+
import "./chunk-NBYBKXQM.js";
|
|
6
|
+
import "./chunk-4UZ6HY4R.js";
|
|
7
|
+
import "./chunk-FTZUNP5A.js";
|
|
8
|
+
export {
|
|
9
|
+
codebaseRetrievalSchema,
|
|
10
|
+
handleCodebaseRetrieval
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=codebaseRetrieval-B4L6LZ2A.js.map
|
|
@@ -1,23 +1,27 @@
|
|
|
1
1
|
import {
|
|
2
|
+
ENHANCER_DEFAULTS,
|
|
2
3
|
checkEmbeddingEnv,
|
|
3
4
|
checkEnhancerEnv,
|
|
4
5
|
checkRerankerEnv,
|
|
5
6
|
getEmbeddingConfig,
|
|
6
7
|
getEnhancerConfig,
|
|
8
|
+
getEnhancerWebUiTimeoutMs,
|
|
7
9
|
getExcludePatterns,
|
|
8
10
|
getRerankerConfig,
|
|
9
11
|
isDev,
|
|
10
12
|
isMcpMode
|
|
11
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-FTZUNP5A.js";
|
|
12
14
|
export {
|
|
15
|
+
ENHANCER_DEFAULTS,
|
|
13
16
|
checkEmbeddingEnv,
|
|
14
17
|
checkEnhancerEnv,
|
|
15
18
|
checkRerankerEnv,
|
|
16
19
|
getEmbeddingConfig,
|
|
17
20
|
getEnhancerConfig,
|
|
21
|
+
getEnhancerWebUiTimeoutMs,
|
|
18
22
|
getExcludePatterns,
|
|
19
23
|
getRerankerConfig,
|
|
20
24
|
isDev,
|
|
21
25
|
isMcpMode
|
|
22
26
|
};
|
|
23
|
-
//# sourceMappingURL=config-
|
|
27
|
+
//# sourceMappingURL=config-63VM3EWD.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildEnhancerSystemPrompt,
|
|
3
|
+
enhancePrompt,
|
|
4
|
+
extractTechnicalTerms
|
|
5
|
+
} from "./chunk-TJH5L5ZP.js";
|
|
6
|
+
import "./chunk-4UZ6HY4R.js";
|
|
7
|
+
import "./chunk-FTZUNP5A.js";
|
|
8
|
+
export {
|
|
9
|
+
buildEnhancerSystemPrompt,
|
|
10
|
+
enhancePrompt,
|
|
11
|
+
extractTechnicalTerms
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=enhancer-XRW4OV7P.js.map
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import {
|
|
2
|
+
fetchWithRetry
|
|
3
|
+
} from "./chunk-GJDN3DU3.js";
|
|
4
|
+
import "./chunk-4UZ6HY4R.js";
|
|
5
|
+
import "./chunk-FTZUNP5A.js";
|
|
6
|
+
|
|
1
7
|
// src/enhancer/adapters/gemini.ts
|
|
2
8
|
var GeminiAdapter = class {
|
|
3
9
|
config;
|
|
@@ -13,21 +19,27 @@ var GeminiAdapter = class {
|
|
|
13
19
|
const baseUrl = this.config.baseUrl.replace(/\/+$/, "");
|
|
14
20
|
const withoutVersion = baseUrl.replace(/\/v1beta$/, "");
|
|
15
21
|
const url = `${withoutVersion}/v1beta/models/${encodeURIComponent(this.config.model)}:generateContent?key=${encodeURIComponent(this.config.apiKey)}`;
|
|
16
|
-
const response = await
|
|
22
|
+
const response = await fetchWithRetry(url, {
|
|
17
23
|
method: "POST",
|
|
18
24
|
headers: {
|
|
19
25
|
"Content-Type": "application/json"
|
|
20
26
|
},
|
|
21
27
|
body: JSON.stringify({
|
|
22
|
-
// Gemini accepts systemInstruction at top-level.
|
|
23
28
|
systemInstruction: systemInstruction ? { parts: [{ text: systemInstruction }] } : void 0,
|
|
24
29
|
contents,
|
|
25
30
|
generationConfig: {
|
|
26
|
-
temperature: 0.
|
|
31
|
+
temperature: 0.3,
|
|
32
|
+
stopSequences: ["<cw-end/>"]
|
|
27
33
|
}
|
|
28
34
|
})
|
|
29
35
|
});
|
|
30
|
-
const
|
|
36
|
+
const raw = await response.text();
|
|
37
|
+
let data;
|
|
38
|
+
try {
|
|
39
|
+
data = JSON.parse(raw);
|
|
40
|
+
} catch {
|
|
41
|
+
throw new Error(`Gemini API \u9519\u8BEF: HTTP ${response.status} - ${raw.slice(0, 200)}`);
|
|
42
|
+
}
|
|
31
43
|
if (!response.ok || data.error) {
|
|
32
44
|
const errorMsg = data.error?.message || `HTTP ${response.status}`;
|
|
33
45
|
throw new Error(`Gemini API \u9519\u8BEF: ${errorMsg}`);
|
|
@@ -42,4 +54,4 @@ var GeminiAdapter = class {
|
|
|
42
54
|
export {
|
|
43
55
|
GeminiAdapter
|
|
44
56
|
};
|
|
45
|
-
//# sourceMappingURL=gemini-
|
|
57
|
+
//# sourceMappingURL=gemini-IY5XGK3X.js.map
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
scan
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-DYDQ5MXJ.js";
|
|
5
|
+
import "./chunk-DFP44KR3.js";
|
|
6
6
|
import {
|
|
7
7
|
generateProjectId
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-NBYBKXQM.js";
|
|
9
9
|
import {
|
|
10
10
|
logger
|
|
11
|
-
} from "./chunk-
|
|
12
|
-
import "./chunk-
|
|
11
|
+
} from "./chunk-4UZ6HY4R.js";
|
|
12
|
+
import "./chunk-FTZUNP5A.js";
|
|
13
13
|
|
|
14
14
|
// src/index.ts
|
|
15
15
|
import { promises as fs } from "fs";
|
|
@@ -121,7 +121,7 @@ cli.command("index [path]", "\u626B\u63CF\u4EE3\u7801\u5E93\u5E76\u5EFA\u7ACB\u7
|
|
|
121
121
|
}
|
|
122
122
|
});
|
|
123
123
|
cli.command("mcp", "\u542F\u52A8 MCP \u670D\u52A1\u5668").action(async () => {
|
|
124
|
-
const { startMcpServer } = await import("./server-
|
|
124
|
+
const { startMcpServer } = await import("./server-PI2QNIYF.js");
|
|
125
125
|
try {
|
|
126
126
|
await startMcpServer();
|
|
127
127
|
} catch (err) {
|
|
@@ -138,7 +138,7 @@ cli.command("enhance <prompt>", "\u589E\u5F3A\u63D0\u793A\u8BCD").option("--no-b
|
|
|
138
138
|
const endpointRaw = options.endpoint?.toLowerCase();
|
|
139
139
|
const endpointOverride = endpointRaw === "openai" || endpointRaw === "claude" || endpointRaw === "gemini" ? endpointRaw : void 0;
|
|
140
140
|
if (options.browser === false) {
|
|
141
|
-
const { enhancePrompt } = await import("./enhancer-
|
|
141
|
+
const { enhancePrompt } = await import("./enhancer-XRW4OV7P.js");
|
|
142
142
|
try {
|
|
143
143
|
const result = await enhancePrompt({ prompt, endpointOverride });
|
|
144
144
|
process.stdout.write(`${result.enhanced}
|
|
@@ -153,8 +153,8 @@ cli.command("enhance <prompt>", "\u589E\u5F3A\u63D0\u793A\u8BCD").option("--no-b
|
|
|
153
153
|
}
|
|
154
154
|
return;
|
|
155
155
|
}
|
|
156
|
-
const { startEnhanceServer } = await import("./server-
|
|
157
|
-
const { openBrowser } = await import("./browser-
|
|
156
|
+
const { startEnhanceServer } = await import("./server-MQ6ONERG.js");
|
|
157
|
+
const { openBrowser } = await import("./browser-KXAZ5XPA.js");
|
|
158
158
|
try {
|
|
159
159
|
const result = await startEnhanceServer(prompt, {
|
|
160
160
|
endpointOverride,
|
|
@@ -184,7 +184,7 @@ cli.command("search", "\u672C\u5730\u68C0\u7D22\uFF08\u53C2\u6570\u5BF9\u9F50 MC
|
|
|
184
184
|
}
|
|
185
185
|
const technicalTerms = (options.technicalTerms || "").split(",").map((t) => t.trim()).filter(Boolean);
|
|
186
186
|
const useZen = options.zen !== false;
|
|
187
|
-
const { handleCodebaseRetrieval } = await import("./codebaseRetrieval-
|
|
187
|
+
const { handleCodebaseRetrieval } = await import("./codebaseRetrieval-B4L6LZ2A.js");
|
|
188
188
|
const response = await handleCodebaseRetrieval(
|
|
189
189
|
{
|
|
190
190
|
repo_path: repoPath,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
logger
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
3
|
+
} from "./chunk-4UZ6HY4R.js";
|
|
4
|
+
import "./chunk-FTZUNP5A.js";
|
|
5
5
|
|
|
6
6
|
// src/utils/lock.ts
|
|
7
7
|
import fs from "fs";
|
|
@@ -104,4 +104,4 @@ async function withLock(projectId, operation, fn, timeoutMs = 3e4) {
|
|
|
104
104
|
export {
|
|
105
105
|
withLock
|
|
106
106
|
};
|
|
107
|
-
//# sourceMappingURL=lock-
|
|
107
|
+
//# sourceMappingURL=lock-IR2WY4LT.js.map
|
package/dist/mcp/main.js
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
if (!process.argv.includes("mcp")) {
|
|
5
5
|
process.argv.push("mcp");
|
|
6
6
|
}
|
|
7
|
-
var { logger } = await import("../logger-
|
|
8
|
-
var { startMcpServer } = await import("../server-
|
|
7
|
+
var { logger } = await import("../logger-VW3UIQPH.js");
|
|
8
|
+
var { startMcpServer } = await import("../server-PI2QNIYF.js");
|
|
9
9
|
try {
|
|
10
10
|
await startMcpServer();
|
|
11
11
|
} catch (err) {
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import {
|
|
2
|
+
fetchWithRetry
|
|
3
|
+
} from "./chunk-GJDN3DU3.js";
|
|
4
|
+
import "./chunk-4UZ6HY4R.js";
|
|
5
|
+
import "./chunk-FTZUNP5A.js";
|
|
6
|
+
|
|
1
7
|
// src/enhancer/adapters/openai.ts
|
|
2
8
|
var OpenAiAdapter = class {
|
|
3
9
|
config;
|
|
@@ -5,7 +11,7 @@ var OpenAiAdapter = class {
|
|
|
5
11
|
this.config = config;
|
|
6
12
|
}
|
|
7
13
|
async chat(messages) {
|
|
8
|
-
const response = await
|
|
14
|
+
const response = await fetchWithRetry(this.config.baseUrl, {
|
|
9
15
|
method: "POST",
|
|
10
16
|
headers: {
|
|
11
17
|
Authorization: `Bearer ${this.config.apiKey}`,
|
|
@@ -14,10 +20,17 @@ var OpenAiAdapter = class {
|
|
|
14
20
|
body: JSON.stringify({
|
|
15
21
|
model: this.config.model,
|
|
16
22
|
messages,
|
|
17
|
-
temperature: 0.
|
|
23
|
+
temperature: 0.3,
|
|
24
|
+
stop: ["<cw-end/>"]
|
|
18
25
|
})
|
|
19
26
|
});
|
|
20
|
-
const
|
|
27
|
+
const raw = await response.text();
|
|
28
|
+
let data;
|
|
29
|
+
try {
|
|
30
|
+
data = JSON.parse(raw);
|
|
31
|
+
} catch {
|
|
32
|
+
throw new Error(`OpenAI API \u9519\u8BEF: HTTP ${response.status} - ${raw.slice(0, 200)}`);
|
|
33
|
+
}
|
|
21
34
|
if (!response.ok || data.error) {
|
|
22
35
|
const errorMsg = data.error?.message || `HTTP ${response.status}`;
|
|
23
36
|
throw new Error(`OpenAI API \u9519\u8BEF: ${errorMsg}`);
|
|
@@ -32,4 +45,4 @@ var OpenAiAdapter = class {
|
|
|
32
45
|
export {
|
|
33
46
|
OpenAiAdapter
|
|
34
47
|
};
|
|
35
|
-
//# sourceMappingURL=openai-
|
|
48
|
+
//# sourceMappingURL=openai-OZ4QWGLQ.js.map
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
enhancePrompt
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-TJH5L5ZP.js";
|
|
4
4
|
import {
|
|
5
5
|
logger
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import
|
|
6
|
+
} from "./chunk-4UZ6HY4R.js";
|
|
7
|
+
import {
|
|
8
|
+
getEnhancerWebUiTimeoutMs
|
|
9
|
+
} from "./chunk-FTZUNP5A.js";
|
|
8
10
|
|
|
9
11
|
// src/enhancer/server.ts
|
|
10
12
|
import { randomUUID } from "crypto";
|
|
@@ -12,7 +14,7 @@ import http from "http";
|
|
|
12
14
|
import net from "net";
|
|
13
15
|
|
|
14
16
|
// src/enhancer/ui.ts
|
|
15
|
-
function getEnhancePageHtml() {
|
|
17
|
+
function getEnhancePageHtml(timeoutMs = 8 * 60 * 1e3) {
|
|
16
18
|
return `<!DOCTYPE html>
|
|
17
19
|
<html lang="zh-CN">
|
|
18
20
|
<head>
|
|
@@ -350,7 +352,7 @@ function getEnhancePageHtml() {
|
|
|
350
352
|
const countdownEl = document.getElementById('countdown');
|
|
351
353
|
|
|
352
354
|
let baselineEnhanced = '';
|
|
353
|
-
const TIMEOUT_MS =
|
|
355
|
+
const TIMEOUT_MS = ${timeoutMs};
|
|
354
356
|
const startTime = Date.now();
|
|
355
357
|
let countdownTimer;
|
|
356
358
|
|
|
@@ -365,7 +367,8 @@ function getEnhancePageHtml() {
|
|
|
365
367
|
if (remaining <= 0) {
|
|
366
368
|
clearInterval(countdownTimer);
|
|
367
369
|
countdownEl.textContent = '\u5DF2\u8D85\u65F6';
|
|
368
|
-
setStatus('\u4F1A\u8BDD\u8D85\u65F6\uFF0C\u5DF2\u81EA\u52A8\u91C7\u7528\u589E\u5F3A\u7248\u7ED3\u679C\u3002', 'success');
|
|
370
|
+
setStatus('\u4F1A\u8BDD\u8D85\u65F6\uFF0C\u5DF2\u81EA\u52A8\u91C7\u7528\u589E\u5F3A\u7248\u7ED3\u679C\u3002\u9875\u9762\u5373\u5C06\u5173\u95ED\u2026', 'success');
|
|
371
|
+
setTimeout(() => window.close(), 1500);
|
|
369
372
|
}
|
|
370
373
|
}
|
|
371
374
|
|
|
@@ -431,7 +434,8 @@ function getEnhancePageHtml() {
|
|
|
431
434
|
setStatus('\u6B63\u5728\u63D0\u4EA4\u2026');
|
|
432
435
|
await jsonFetch('/api/submit', { action, text });
|
|
433
436
|
clearInterval(countdownTimer);
|
|
434
|
-
setStatus('\u5B8C\u6210\uFF01\
|
|
437
|
+
setStatus('\u5B8C\u6210\uFF01\u9875\u9762\u5373\u5C06\u5173\u95ED\u2026', 'success');
|
|
438
|
+
setTimeout(() => window.close(), 1500);
|
|
435
439
|
} catch (e) {
|
|
436
440
|
const message = e && e.message ? e.message : String(e);
|
|
437
441
|
setStatus(message, 'error');
|
|
@@ -581,6 +585,7 @@ async function startEnhanceServer(prompt, options = {}) {
|
|
|
581
585
|
resolveResult = resolve;
|
|
582
586
|
rejectResult = reject;
|
|
583
587
|
});
|
|
588
|
+
const timeoutMs = getEnhancerWebUiTimeoutMs();
|
|
584
589
|
const server = http.createServer(async (req, res) => {
|
|
585
590
|
try {
|
|
586
591
|
setCors(req, res);
|
|
@@ -593,7 +598,7 @@ async function startEnhanceServer(prompt, options = {}) {
|
|
|
593
598
|
if (req.method === "GET" && url2.pathname === "/enhance") {
|
|
594
599
|
res.statusCode = 200;
|
|
595
600
|
res.setHeader("Content-Type", "text/html; charset=utf-8");
|
|
596
|
-
res.end(getEnhancePageHtml());
|
|
601
|
+
res.end(getEnhancePageHtml(timeoutMs));
|
|
597
602
|
return;
|
|
598
603
|
}
|
|
599
604
|
if (req.method === "GET" && url2.pathname === "/api/session") {
|
|
@@ -668,7 +673,6 @@ async function startEnhanceServer(prompt, options = {}) {
|
|
|
668
673
|
json(res, 500, { error: error.message || "Internal error" });
|
|
669
674
|
}
|
|
670
675
|
});
|
|
671
|
-
const timeoutMs = 8 * 60 * 1e3;
|
|
672
676
|
const timeout = setTimeout(() => {
|
|
673
677
|
if (resolved) return;
|
|
674
678
|
logger.info("\u4F1A\u8BDD\u8D85\u65F6\uFF0C\u81EA\u52A8\u4F7F\u7528\u589E\u5F3A\u7248\u7ED3\u679C");
|
|
@@ -710,4 +714,4 @@ async function startEnhanceServer(prompt, options = {}) {
|
|
|
710
714
|
export {
|
|
711
715
|
startEnhanceServer
|
|
712
716
|
};
|
|
713
|
-
//# sourceMappingURL=server-
|
|
717
|
+
//# sourceMappingURL=server-MQ6ONERG.js.map
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
codebaseRetrievalSchema,
|
|
3
3
|
handleCodebaseRetrieval
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-VEHIYQIP.js";
|
|
5
|
+
import "./chunk-NBYBKXQM.js";
|
|
6
6
|
import {
|
|
7
7
|
logger
|
|
8
|
-
} from "./chunk-
|
|
9
|
-
import "./chunk-
|
|
8
|
+
} from "./chunk-4UZ6HY4R.js";
|
|
9
|
+
import "./chunk-FTZUNP5A.js";
|
|
10
10
|
|
|
11
11
|
// src/mcp/server.ts
|
|
12
12
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
@@ -64,7 +64,7 @@ async function handleEnhancePrompt(args) {
|
|
|
64
64
|
{ hasHistory: Boolean(args.conversation_history), webui: useWebUi },
|
|
65
65
|
"MCP enhance-prompt \u8C03\u7528\u5F00\u59CB"
|
|
66
66
|
);
|
|
67
|
-
const { checkEnhancerEnv } = await import("./config-
|
|
67
|
+
const { checkEnhancerEnv } = await import("./config-63VM3EWD.js");
|
|
68
68
|
const envCheck = checkEnhancerEnv();
|
|
69
69
|
if (!envCheck.isValid) {
|
|
70
70
|
logger.warn({ missingVars: envCheck.missingVars }, "Prompt Enhancer \u73AF\u5883\u53D8\u91CF\u672A\u914D\u7F6E");
|
|
@@ -72,8 +72,8 @@ async function handleEnhancePrompt(args) {
|
|
|
72
72
|
}
|
|
73
73
|
try {
|
|
74
74
|
if (useWebUi) {
|
|
75
|
-
const { startEnhanceServer } = await import("./server-
|
|
76
|
-
const { openBrowser } = await import("./browser-
|
|
75
|
+
const { startEnhanceServer } = await import("./server-MQ6ONERG.js");
|
|
76
|
+
const { openBrowser } = await import("./browser-KXAZ5XPA.js");
|
|
77
77
|
const result2 = await startEnhanceServer(args.prompt, {
|
|
78
78
|
conversationHistory: args.conversation_history,
|
|
79
79
|
projectRootPath: args.project_root_path,
|
|
@@ -90,7 +90,7 @@ async function handleEnhancePrompt(args) {
|
|
|
90
90
|
]
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
|
-
const { enhancePrompt } = await import("./enhancer-
|
|
93
|
+
const { enhancePrompt } = await import("./enhancer-XRW4OV7P.js");
|
|
94
94
|
const result = await enhancePrompt({
|
|
95
95
|
prompt: args.prompt,
|
|
96
96
|
conversationHistory: args.conversation_history,
|
|
@@ -292,4 +292,4 @@ async function startMcpServer() {
|
|
|
292
292
|
export {
|
|
293
293
|
startMcpServer
|
|
294
294
|
};
|
|
295
|
-
//# sourceMappingURL=server-
|
|
295
|
+
//# sourceMappingURL=server-PI2QNIYF.js.map
|
package/package.json
CHANGED
package/dist/chunk-PZTRC7VF.js
DELETED
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
logger
|
|
3
|
-
} from "./chunk-QCUCU74R.js";
|
|
4
|
-
import {
|
|
5
|
-
checkEnhancerEnv,
|
|
6
|
-
getEnhancerConfig
|
|
7
|
-
} from "./chunk-YVMNY2OU.js";
|
|
8
|
-
|
|
9
|
-
// src/enhancer/detect.ts
|
|
10
|
-
function detectLanguage(text) {
|
|
11
|
-
const matches = text.match(/[\u4e00-\u9fff]/g);
|
|
12
|
-
const count = matches?.length ?? 0;
|
|
13
|
-
return count >= 3 ? "zh" : "en";
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// src/enhancer/llmClient.ts
|
|
17
|
-
var clientCache = /* @__PURE__ */ new Map();
|
|
18
|
-
async function createLlmClient(config) {
|
|
19
|
-
const endpoint = config.endpoint;
|
|
20
|
-
const baseUrl = config.baseUrl;
|
|
21
|
-
const model = config.model || "";
|
|
22
|
-
const cacheKey = `${endpoint}:${baseUrl}:${model}`;
|
|
23
|
-
const cached = clientCache.get(cacheKey);
|
|
24
|
-
if (cached) {
|
|
25
|
-
return cached;
|
|
26
|
-
}
|
|
27
|
-
if (!config.model) {
|
|
28
|
-
throw new Error("Prompt enhancer model is required");
|
|
29
|
-
}
|
|
30
|
-
const clientConfig = {
|
|
31
|
-
baseUrl: config.baseUrl,
|
|
32
|
-
apiKey: config.apiKey,
|
|
33
|
-
model: config.model
|
|
34
|
-
};
|
|
35
|
-
let client;
|
|
36
|
-
if (endpoint === "openai") {
|
|
37
|
-
const { OpenAiAdapter } = await import("./openai-VRQNTJQZ.js");
|
|
38
|
-
client = new OpenAiAdapter(clientConfig);
|
|
39
|
-
} else if (endpoint === "claude") {
|
|
40
|
-
const { ClaudeAdapter } = await import("./claude-YONOS6YG.js");
|
|
41
|
-
client = new ClaudeAdapter(clientConfig);
|
|
42
|
-
} else {
|
|
43
|
-
const { GeminiAdapter } = await import("./gemini-54NRBSPH.js");
|
|
44
|
-
client = new GeminiAdapter(clientConfig);
|
|
45
|
-
}
|
|
46
|
-
clientCache.set(cacheKey, client);
|
|
47
|
-
return client;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// src/enhancer/parser.ts
|
|
51
|
-
function parseEnhancedPrompt(response) {
|
|
52
|
-
const patterns = [
|
|
53
|
-
/<enhanced-prompt>([\s\S]*?)<\/enhanced-prompt>/,
|
|
54
|
-
/<augment-enhanced-prompt(?:\s+[^>]*)?>\s*([\s\S]*?)\s*<\/augment-enhanced-prompt\s*>/
|
|
55
|
-
];
|
|
56
|
-
for (const pattern of patterns) {
|
|
57
|
-
const match = response.match(pattern);
|
|
58
|
-
const extracted = match?.[1]?.trim();
|
|
59
|
-
if (extracted) {
|
|
60
|
-
return extracted;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return response.trim();
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// src/enhancer/template.ts
|
|
67
|
-
import { promises as fs } from "fs";
|
|
68
|
-
var DEFAULT_TEMPLATE = `\u4F60\u662F\u4E00\u4E2A\u63D0\u793A\u8BCD\u4F18\u5316\u4E13\u5BB6\u3002
|
|
69
|
-
|
|
70
|
-
\u4F60\u7684\u4EFB\u52A1\uFF1A\u5C06\u7528\u6237\u7684\u539F\u59CB\u63D0\u793A\u8BCD\u8FDB\u884C\u589E\u5F3A\uFF0C\u4F7F\u5176\u66F4\u6E05\u6670\u3001\u66F4\u5177\u4F53\u3001\u66F4\u53EF\u6267\u884C\u3002
|
|
71
|
-
|
|
72
|
-
\u589E\u5F3A\u8981\u6C42\uFF1A
|
|
73
|
-
- \u4FDD\u7559\u539F\u59CB\u610F\u56FE\uFF0C\u4E0D\u8981\u6539\u53D8\u9700\u6C42\u65B9\u5411
|
|
74
|
-
- \u8865\u5168\u7F3A\u5931\u7684\u4E0A\u4E0B\u6587\u3001\u7EA6\u675F\u3001\u9A8C\u6536\u6807\u51C6\u4E0E\u8FB9\u754C\u6761\u4EF6
|
|
75
|
-
- \u7ED9\u51FA\u7ED3\u6784\u5316\u3001\u53EF\u76F4\u63A5\u6267\u884C\u7684\u6307\u4EE4\uFF08\u9002\u5F53\u4F7F\u7528\u5217\u8868/\u6B65\u9AA4\uFF09
|
|
76
|
-
- \u5982\u679C\u539F\u59CB\u63D0\u793A\u8BCD\u5305\u542B\u4E09\u5F15\u53F7\u4EE3\u7801\u5757\uFF0C\u8BF7\u5C3D\u91CF\u4FDD\u6301\u4EE3\u7801\u5757\u5185\u5BB9\u4E0D\u53D8
|
|
77
|
-
|
|
78
|
-
{{language_instruction}}
|
|
79
|
-
|
|
80
|
-
\u5BF9\u8BDD\u5386\u53F2\uFF08\u5982\u4E3A\u7A7A\u53EF\u5FFD\u7565\uFF09\uFF1A
|
|
81
|
-
{{conversation_history}}
|
|
82
|
-
|
|
83
|
-
\u8BF7\u53EA\u8F93\u51FA\u589E\u5F3A\u540E\u7684\u63D0\u793A\u8BCD\uFF0C\u5E76\u7528\u4EE5\u4E0B XML \u6807\u7B7E\u5305\u88F9\uFF1A
|
|
84
|
-
<enhanced-prompt>...</enhanced-prompt>
|
|
85
|
-
|
|
86
|
-
\u539F\u59CB\u63D0\u793A\u8BCD\uFF1A
|
|
87
|
-
{{original_prompt}}
|
|
88
|
-
`;
|
|
89
|
-
function getTemplatePathOrInline(templateValue) {
|
|
90
|
-
if (!templateValue) return void 0;
|
|
91
|
-
const trimmed = templateValue.trim();
|
|
92
|
-
if (!trimmed) return void 0;
|
|
93
|
-
if (trimmed.includes("\n") || trimmed.includes("{{")) {
|
|
94
|
-
return { kind: "inline", value: templateValue };
|
|
95
|
-
}
|
|
96
|
-
return { kind: "path", value: trimmed };
|
|
97
|
-
}
|
|
98
|
-
async function loadTemplate(templatePath) {
|
|
99
|
-
const templateValue = templatePath;
|
|
100
|
-
const resolved = getTemplatePathOrInline(templateValue);
|
|
101
|
-
if (!resolved) return DEFAULT_TEMPLATE;
|
|
102
|
-
if (resolved.kind === "inline") {
|
|
103
|
-
return resolved.value;
|
|
104
|
-
}
|
|
105
|
-
try {
|
|
106
|
-
return await fs.readFile(resolved.value, "utf-8");
|
|
107
|
-
} catch (err) {
|
|
108
|
-
const error = err;
|
|
109
|
-
logger.warn(
|
|
110
|
-
{ templatePath: resolved.value, error: error.message },
|
|
111
|
-
"\u8BFB\u53D6\u81EA\u5B9A\u4E49\u6A21\u677F\u5931\u8D25\uFF0C\u5DF2\u56DE\u9000\u5230\u9ED8\u8BA4\u6A21\u677F"
|
|
112
|
-
);
|
|
113
|
-
return DEFAULT_TEMPLATE;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
function renderPrompt(template, vars) {
|
|
117
|
-
const mapping = {
|
|
118
|
-
original_prompt: vars.originalPrompt,
|
|
119
|
-
conversation_history: vars.conversationHistory ?? "",
|
|
120
|
-
language_instruction: vars.languageInstruction
|
|
121
|
-
};
|
|
122
|
-
return template.replace(
|
|
123
|
-
/\{\{\s*(original_prompt|conversation_history|language_instruction)\s*\}\}/g,
|
|
124
|
-
(match, key) => mapping[key] ?? match
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// src/enhancer/index.ts
|
|
129
|
-
async function enhancePrompt(options) {
|
|
130
|
-
const envCheck = checkEnhancerEnv();
|
|
131
|
-
if (!envCheck.isValid) {
|
|
132
|
-
throw new Error(
|
|
133
|
-
`Prompt Enhancer \u73AF\u5883\u53D8\u91CF\u672A\u914D\u7F6E: ${envCheck.missingVars.join(", ")}`
|
|
134
|
-
);
|
|
135
|
-
}
|
|
136
|
-
const config = getEnhancerConfig();
|
|
137
|
-
const endpoint = options.endpointOverride ?? config.endpoint;
|
|
138
|
-
const defaultBaseUrlByEndpoint = {
|
|
139
|
-
openai: "https://api.openai.com/v1/chat/completions",
|
|
140
|
-
claude: "https://api.anthropic.com/v1/messages",
|
|
141
|
-
gemini: "https://generativelanguage.googleapis.com/v1beta"
|
|
142
|
-
};
|
|
143
|
-
const defaultModelByEndpoint = {
|
|
144
|
-
openai: "gpt-4o-mini",
|
|
145
|
-
claude: "claude-sonnet-4-20250514",
|
|
146
|
-
gemini: "gemini-2.0-flash"
|
|
147
|
-
};
|
|
148
|
-
const baseUrl = process.env.PROMPT_ENHANCER_BASE_URL || defaultBaseUrlByEndpoint[endpoint];
|
|
149
|
-
const model = process.env.PROMPT_ENHANCER_MODEL || defaultModelByEndpoint[endpoint];
|
|
150
|
-
const configWithOverride = {
|
|
151
|
-
...config,
|
|
152
|
-
endpoint,
|
|
153
|
-
baseUrl,
|
|
154
|
-
model
|
|
155
|
-
};
|
|
156
|
-
const language = detectLanguage(options.prompt);
|
|
157
|
-
const languageInstruction = language === "zh" ? "\u8BF7\u7528\u4E2D\u6587\u8F93\u51FA\u589E\u5F3A\u540E\u7684\u63D0\u793A\u8BCD\u3002" : "Please output the enhanced prompt in English.";
|
|
158
|
-
const template = await loadTemplate(configWithOverride.templatePath);
|
|
159
|
-
const rendered = renderPrompt(template, {
|
|
160
|
-
originalPrompt: options.prompt,
|
|
161
|
-
conversationHistory: options.conversationHistory,
|
|
162
|
-
languageInstruction
|
|
163
|
-
});
|
|
164
|
-
const client = await createLlmClient(configWithOverride);
|
|
165
|
-
const raw = await client.chat([
|
|
166
|
-
{
|
|
167
|
-
role: "system",
|
|
168
|
-
content: "You are a helpful prompt enhancement assistant."
|
|
169
|
-
},
|
|
170
|
-
{
|
|
171
|
-
role: "user",
|
|
172
|
-
content: rendered
|
|
173
|
-
}
|
|
174
|
-
]);
|
|
175
|
-
const enhanced = parseEnhancedPrompt(raw);
|
|
176
|
-
return {
|
|
177
|
-
original: options.prompt,
|
|
178
|
-
enhanced,
|
|
179
|
-
endpoint: configWithOverride.endpoint,
|
|
180
|
-
model: configWithOverride.model || ""
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
export {
|
|
185
|
-
enhancePrompt
|
|
186
|
-
};
|
|
187
|
-
//# sourceMappingURL=chunk-PZTRC7VF.js.map
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
codebaseRetrievalSchema,
|
|
3
|
-
handleCodebaseRetrieval
|
|
4
|
-
} from "./chunk-CACJOY3O.js";
|
|
5
|
-
import "./chunk-53ESQDZT.js";
|
|
6
|
-
import "./chunk-QCUCU74R.js";
|
|
7
|
-
import "./chunk-YVMNY2OU.js";
|
|
8
|
-
export {
|
|
9
|
-
codebaseRetrievalSchema,
|
|
10
|
-
handleCodebaseRetrieval
|
|
11
|
-
};
|
|
12
|
-
//# sourceMappingURL=codebaseRetrieval-N6ABFZ24.js.map
|
package/dist/logger-REOCZNEY.js
DELETED
package/dist/scanner-QUWFCQUV.js
DELETED