ace-tool 0.1.5 → 0.2.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/README.md +64 -6
- package/dist/config.d.ts +16 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +31 -1
- package/dist/config.js.map +1 -1
- package/dist/enhancer/EnhancerServer.d.ts +59 -0
- package/dist/enhancer/EnhancerServer.d.ts.map +1 -0
- package/dist/enhancer/EnhancerServer.js +306 -0
- package/dist/enhancer/EnhancerServer.js.map +1 -0
- package/dist/enhancer/PromptEnhancer.d.ts +49 -0
- package/dist/enhancer/PromptEnhancer.d.ts.map +1 -0
- package/dist/enhancer/PromptEnhancer.js +243 -0
- package/dist/enhancer/PromptEnhancer.js.map +1 -0
- package/dist/enhancer/templates.d.ts +14 -0
- package/dist/enhancer/templates.d.ts.map +1 -0
- package/dist/enhancer/templates.js +673 -0
- package/dist/enhancer/templates.js.map +1 -0
- package/dist/index/manager.d.ts.map +1 -1
- package/dist/index/manager.js +21 -1
- package/dist/index/manager.js.map +1 -1
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -1
- package/dist/prompts/enhancePrompt.d.ts +26 -0
- package/dist/prompts/enhancePrompt.d.ts.map +1 -0
- package/dist/prompts/enhancePrompt.js +26 -0
- package/dist/prompts/enhancePrompt.js.map +1 -0
- package/dist/tools/enhancePrompt.d.ts +14 -0
- package/dist/tools/enhancePrompt.d.ts.map +1 -0
- package/dist/tools/enhancePrompt.js +86 -0
- package/dist/tools/enhancePrompt.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt Enhancer - 核心增强逻辑
|
|
3
|
+
* 基于 Augment VSCode 插件的实现
|
|
4
|
+
*/
|
|
5
|
+
import axios from 'axios';
|
|
6
|
+
import fs from 'fs';
|
|
7
|
+
import { exec } from 'child_process';
|
|
8
|
+
import { sendMcpLog } from '../mcpLogger.js';
|
|
9
|
+
/**
|
|
10
|
+
* Prompt Enhancer 类
|
|
11
|
+
*/
|
|
12
|
+
export class PromptEnhancer {
|
|
13
|
+
indexManager;
|
|
14
|
+
baseUrl;
|
|
15
|
+
token;
|
|
16
|
+
httpClient;
|
|
17
|
+
server;
|
|
18
|
+
constructor(indexManager, baseUrl, token, server) {
|
|
19
|
+
this.indexManager = indexManager;
|
|
20
|
+
this.baseUrl = baseUrl;
|
|
21
|
+
this.token = token;
|
|
22
|
+
this.baseUrl = baseUrl.replace(/\/$/, '');
|
|
23
|
+
this.server = server;
|
|
24
|
+
this.httpClient = axios.create({
|
|
25
|
+
timeout: 60000,
|
|
26
|
+
headers: {
|
|
27
|
+
Authorization: `Bearer ${this.token}`,
|
|
28
|
+
'Content-Type': 'application/json',
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* 增强 prompt
|
|
34
|
+
* @param originalPrompt 原始用户输入
|
|
35
|
+
* @param conversationHistory 对话历史(5-10轮)
|
|
36
|
+
* @returns 增强后的 prompt
|
|
37
|
+
*/
|
|
38
|
+
async enhance(originalPrompt, conversationHistory) {
|
|
39
|
+
sendMcpLog('info', '🎨 开始增强 prompt...');
|
|
40
|
+
try {
|
|
41
|
+
// 1. 加载已索引的 blob 列表
|
|
42
|
+
sendMcpLog('info', '📂 加载索引数据...');
|
|
43
|
+
const blobNames = this.loadBlobNames();
|
|
44
|
+
if (blobNames.length === 0) {
|
|
45
|
+
sendMcpLog('warning', '⚠️ 未找到索引数据,将在没有代码上下文的情况下增强');
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
sendMcpLog('info', `📊 已加载 ${blobNames.length} 个文件块`);
|
|
49
|
+
}
|
|
50
|
+
// 2. 设置增强回调函数(用于"继续增强"功能)
|
|
51
|
+
this.server.setEnhanceCallback(async (prompt, history, blobs) => {
|
|
52
|
+
return await this.callPromptEnhancerApi(prompt, history, blobs);
|
|
53
|
+
});
|
|
54
|
+
// 3. 调用 prompt-enhancer API 生成增强内容
|
|
55
|
+
sendMcpLog('info', '🤖 调用 prompt-enhancer API 生成增强内容...');
|
|
56
|
+
const enhancedPrompt = await this.callPromptEnhancerApi(originalPrompt, conversationHistory, blobNames);
|
|
57
|
+
sendMcpLog('info', '✅ 增强内容生成成功');
|
|
58
|
+
// 4. 启动 Web UI 交互
|
|
59
|
+
sendMcpLog('info', '🌐 启动 Web UI 等待用户确认...');
|
|
60
|
+
const finalPrompt = await this.interactWithUser(enhancedPrompt, originalPrompt, conversationHistory, blobNames);
|
|
61
|
+
sendMcpLog('info', '✅ Prompt 增强完成');
|
|
62
|
+
return finalPrompt;
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
66
|
+
sendMcpLog('error', `❌ Prompt 增强失败: ${errorMessage}`);
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 加载已索引的 blob 名称列表
|
|
72
|
+
*/
|
|
73
|
+
loadBlobNames() {
|
|
74
|
+
try {
|
|
75
|
+
// 使用 IndexManager 的私有��法需要通过反射或者添加公共方法
|
|
76
|
+
// 这里我们直接读取索引文件
|
|
77
|
+
const indexFilePath = this.indexManager.indexFilePath;
|
|
78
|
+
if (!fs.existsSync(indexFilePath)) {
|
|
79
|
+
return [];
|
|
80
|
+
}
|
|
81
|
+
const content = fs.readFileSync(indexFilePath, 'utf-8');
|
|
82
|
+
return JSON.parse(content);
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
sendMcpLog('warning', `⚠️ 加载索引失败: ${error}`);
|
|
86
|
+
return [];
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* 调用 prompt-enhancer API 生成增强内容
|
|
91
|
+
*/
|
|
92
|
+
async callPromptEnhancerApi(originalPrompt, conversationHistory, blobNames) {
|
|
93
|
+
// 解析对话历史
|
|
94
|
+
const chatHistory = this.parseChatHistory(conversationHistory);
|
|
95
|
+
// 检测原始 prompt 的语言
|
|
96
|
+
const isChinese = /[\u4e00-\u9fa5]/.test(originalPrompt);
|
|
97
|
+
const languageGuideline = isChinese
|
|
98
|
+
? 'Please respond in Chinese (Simplified Chinese). 请用中文回复。'
|
|
99
|
+
: '';
|
|
100
|
+
// 构造符合 Augment 格式的 payload
|
|
101
|
+
// nodes 包含用户的原始 prompt
|
|
102
|
+
const payload = {
|
|
103
|
+
nodes: [
|
|
104
|
+
{
|
|
105
|
+
id: 1,
|
|
106
|
+
type: 0, // text node type
|
|
107
|
+
text_node: {
|
|
108
|
+
content: originalPrompt
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
],
|
|
112
|
+
chat_history: chatHistory,
|
|
113
|
+
blobs: {
|
|
114
|
+
checkpoint_id: null,
|
|
115
|
+
added_blobs: blobNames,
|
|
116
|
+
deleted_blobs: [],
|
|
117
|
+
},
|
|
118
|
+
conversation_id: null,
|
|
119
|
+
model: 'claude-sonnet-4-5',
|
|
120
|
+
mode: 'CHAT',
|
|
121
|
+
user_guided_blobs: [],
|
|
122
|
+
external_source_ids: [],
|
|
123
|
+
user_guidelines: languageGuideline,
|
|
124
|
+
workspace_guidelines: '',
|
|
125
|
+
rules: []
|
|
126
|
+
};
|
|
127
|
+
try {
|
|
128
|
+
const response = await this.httpClient.post(`${this.baseUrl}/prompt-enhancer`, payload);
|
|
129
|
+
let enhancedText = response.data.text || '';
|
|
130
|
+
if (!enhancedText) {
|
|
131
|
+
throw new Error('Prompt enhancer API 返回空结果');
|
|
132
|
+
}
|
|
133
|
+
// 替换 Augment 特定的工具名称为 ace-tool 的工具名称
|
|
134
|
+
enhancedText = this.replaceToolNames(enhancedText);
|
|
135
|
+
return enhancedText;
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
if (error.response?.status === 401) {
|
|
139
|
+
throw new Error('Token 已失效或无效,请检查配置');
|
|
140
|
+
}
|
|
141
|
+
else if (error.response?.status === 403) {
|
|
142
|
+
throw new Error('访问被拒绝,Token 可能已被禁用');
|
|
143
|
+
}
|
|
144
|
+
else if (error.code === 'ECONNREFUSED') {
|
|
145
|
+
throw new Error('无法连接到服务器,请检查 base-url 配置');
|
|
146
|
+
}
|
|
147
|
+
throw new Error(`Prompt enhancer API 调用失败: ${error.message}`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* 替换 Augment 特定的工具名称为 ace-tool 的工具名称
|
|
152
|
+
*/
|
|
153
|
+
replaceToolNames(text) {
|
|
154
|
+
// 替换 codebase-retrieval 为 search_context
|
|
155
|
+
// 支持多种可能的格式:
|
|
156
|
+
// 1. 工具调用格式:codebase-retrieval 或 codebase_retrieval
|
|
157
|
+
// 2. 文本引用格式:`codebase-retrieval` 或 "codebase-retrieval"
|
|
158
|
+
let result = text;
|
|
159
|
+
// 替换各种格式的 codebase-retrieval
|
|
160
|
+
result = result.replace(/codebase-retrieval/g, 'search_context');
|
|
161
|
+
result = result.replace(/codebase_retrieval/g, 'search_context');
|
|
162
|
+
// 如果有其他 Augment 特定的工具需要替换,可以在这里添加
|
|
163
|
+
return result;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* 解析对话历史为 chat_history 格式
|
|
167
|
+
*/
|
|
168
|
+
parseChatHistory(conversationHistory) {
|
|
169
|
+
// 简单解析对话历史
|
|
170
|
+
// 格式示例: "User: xxx\nAI: yyy\nUser: zzz"
|
|
171
|
+
const lines = conversationHistory.split('\n');
|
|
172
|
+
const chatHistory = [];
|
|
173
|
+
for (const line of lines) {
|
|
174
|
+
const trimmed = line.trim();
|
|
175
|
+
if (trimmed.startsWith('User:') || trimmed.startsWith('用户:')) {
|
|
176
|
+
chatHistory.push({
|
|
177
|
+
role: 'user',
|
|
178
|
+
content: trimmed.replace(/^(User:|用户:)\s*/, '')
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
else if (trimmed.startsWith('AI:') || trimmed.startsWith('Assistant:') || trimmed.startsWith('助手:')) {
|
|
182
|
+
chatHistory.push({
|
|
183
|
+
role: 'assistant',
|
|
184
|
+
content: trimmed.replace(/^(AI:|Assistant:|助手:)\s*/, '')
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return chatHistory;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* 通过 Web UI 与用户交互
|
|
192
|
+
*/
|
|
193
|
+
async interactWithUser(enhancedPrompt, originalPrompt, conversationHistory, blobNames) {
|
|
194
|
+
// 确保服务器已启动
|
|
195
|
+
await this.server.start();
|
|
196
|
+
// 创建 session(传入所有必要的参数以支持"继续增强")
|
|
197
|
+
const sessionId = this.server.createSession(enhancedPrompt, originalPrompt, conversationHistory, blobNames);
|
|
198
|
+
// 打开浏览器
|
|
199
|
+
const url = `http://localhost:${this.server.getPort()}/enhance?session=${sessionId}`;
|
|
200
|
+
sendMcpLog('info', `🌐 请在浏览器中查看: ${url}`);
|
|
201
|
+
// 尝试自动打开浏览器
|
|
202
|
+
this.openBrowser(url);
|
|
203
|
+
// 等待用户操作
|
|
204
|
+
try {
|
|
205
|
+
const finalPrompt = await this.server.waitForSession(sessionId);
|
|
206
|
+
if (!finalPrompt || finalPrompt.trim() === '') {
|
|
207
|
+
sendMcpLog('info', '❌ 用户取消了增强');
|
|
208
|
+
throw new Error('User cancelled the enhancement');
|
|
209
|
+
}
|
|
210
|
+
return finalPrompt;
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
if (error instanceof Error && error.message.includes('timeout')) {
|
|
214
|
+
sendMcpLog('error', '⏱️ 用户交互超时(8分钟)');
|
|
215
|
+
throw new Error('User interaction timeout (8 minutes)');
|
|
216
|
+
}
|
|
217
|
+
throw error;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* 打开浏览器
|
|
222
|
+
*/
|
|
223
|
+
openBrowser(url) {
|
|
224
|
+
const platform = process.platform;
|
|
225
|
+
let command;
|
|
226
|
+
if (platform === 'darwin') {
|
|
227
|
+
command = `open "${url}"`;
|
|
228
|
+
}
|
|
229
|
+
else if (platform === 'win32') {
|
|
230
|
+
command = `start "${url}"`;
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
command = `xdg-open "${url}"`;
|
|
234
|
+
}
|
|
235
|
+
exec(command, (error) => {
|
|
236
|
+
if (error) {
|
|
237
|
+
sendMcpLog('warning', `⚠️ 无法自动打开浏览器: ${error.message}`);
|
|
238
|
+
sendMcpLog('info', `请手动打开: ${url}`);
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
//# sourceMappingURL=PromptEnhancer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PromptEnhancer.js","sourceRoot":"","sources":["../../src/enhancer/PromptEnhancer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAwB,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAGrC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C;;GAEG;AACH,MAAM,OAAO,cAAc;IAKf;IACA;IACA;IANF,UAAU,CAAgB;IAC1B,MAAM,CAAiB;IAE/B,YACU,YAA0B,EAC1B,OAAe,EACf,KAAa,EACrB,MAAsB;QAHd,iBAAY,GAAZ,YAAY,CAAc;QAC1B,YAAO,GAAP,OAAO,CAAQ;QACf,UAAK,GAAL,KAAK,CAAQ;QAGrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAC1C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC,MAAM,CAAC;YAC7B,OAAO,EAAE,KAAK;YAC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tC,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;YAC1D,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAED;;OAEG;IACK,WAAW,CAAC,GAAW;QAC7B,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QAElC,IAAI,OAAe,CAAC;QACpB,IAAI,QAAQ,KAAK,QAAQ,EAAE,CAAC;YAC1B,OAAO,GAAG,SAAS,GAAG,GAAG,CAAC;QAC5B,CAAC;aAAM,IAAI,QAAQ,KAAK,OAAO,EAAE,CAAC;YAChC,OAAO,GAAG,UAAU,GAAG,GAAG,CAAC;QAC7B,CAAC;aAAM,CAAC;YACN,OAAO,GAAG,aAAa,GAAG,GAAG,CAAC;QAChC,CAAC;QAED,IAAI,CAAC,OAAO,EAAE,CAAC,KAAU,EAAE,EAAE;YAC3B,IAAI,KAAK,EAAE,CAAC;gBACV,UAAU,CAAC,SAAS,EAAE,iBAAiB,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;gBACxD,UAAU,CAAC,MAAM,EAAE,UAAU,GAAG,EAAE,CAAC,CAAC;YACtC,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt Enhancer 模板
|
|
3
|
+
* 基于 Augment VSCode 插件的官方模板
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* 增强 Prompt 的模板
|
|
7
|
+
* 包含对话历史和原始 prompt 的占位符
|
|
8
|
+
*/
|
|
9
|
+
export declare const ENHANCE_PROMPT_TEMPLATE = "\u26A0\uFE0F NO TOOLS ALLOWED \u26A0\uFE0F\n\nHere is an instruction that I'd like to give you, but it needs to be improved.\nRewrite and enhance this instruction to make it clearer, more specific, less ambiguous,\nand correct any mistakes. Do not use any tools: reply immediately with your answer,\neven if you're not sure. Consider the context of our conversation history when enhancing\nthe prompt.\n\nConversation history:\n{conversation_history}\n\nReply with the following format:\n\n### BEGIN RESPONSE ###\nHere is an enhanced version of the original instruction that is more specific and clear:\n<augment-enhanced-prompt>enhanced prompt goes here</augment-enhanced-prompt>\n\n### END RESPONSE ###\n\nHere is my original instruction:\n\n{original_prompt}";
|
|
10
|
+
/**
|
|
11
|
+
* Web UI 的 HTML 模板
|
|
12
|
+
*/
|
|
13
|
+
export declare const ENHANCER_UI_HTML = "<!DOCTYPE html>\n<html lang=\"zh-CN\">\n<head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>Prompt Enhancer - ACE Tool</title>\n <style>\n * {\n margin: 0;\n padding: 0;\n box-sizing: border-box;\n }\n\n body {\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', sans-serif;\n background: #f5f5f5;\n min-height: 100vh;\n padding: 20px;\n display: flex;\n align-items: center;\n justify-content: center;\n }\n\n .container {\n background: white;\n border-radius: 8px;\n box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);\n border: 1px solid #e0e0e0;\n max-width: 1000px;\n width: 100%;\n overflow: hidden;\n }\n\n .header {\n background: white;\n color: #333;\n padding: 30px;\n text-align: center;\n border-bottom: 1px solid #e0e0e0;\n }\n\n .header h1 {\n font-size: 24px;\n font-weight: 600;\n margin-bottom: 8px;\n display: flex;\n align-items: center;\n justify-content: center;\n gap: 10px;\n color: #333;\n }\n\n .header p {\n font-size: 14px;\n color: #666;\n }\n\n .countdown {\n margin-top: 12px;\n padding: 8px 16px;\n background: #f0f0f0;\n border-radius: 6px;\n display: inline-block;\n font-size: 13px;\n font-weight: 500;\n color: #555;\n }\n\n .countdown.warning {\n background: #fff3cd;\n color: #856404;\n }\n\n .countdown.danger {\n background: #f8d7da;\n color: #721c24;\n animation: pulse 1s ease-in-out infinite;\n }\n\n @keyframes pulse {\n 0%, 100% { opacity: 1; }\n 50% { opacity: 0.7; }\n }\n\n .content {\n padding: 30px;\n }\n\n .section {\n margin-bottom: 25px;\n }\n\n .section-title {\n font-size: 14px;\n font-weight: 600;\n color: #333;\n margin-bottom: 10px;\n text-transform: uppercase;\n letter-spacing: 0.5px;\n }\n\n .editor-wrapper {\n position: relative;\n }\n\n textarea {\n width: 100%;\n min-height: 350px;\n padding: 16px;\n border: 2px solid #e0e0e0;\n border-radius: 8px;\n font-family: 'SF Mono', 'Monaco', 'Menlo', 'Consolas', monospace;\n font-size: 14px;\n line-height: 1.6;\n resize: vertical;\n transition: border-color 0.3s;\n background: #fafafa;\n }\n\n textarea:focus {\n outline: none;\n border-color: #333;\n background: white;\n }\n\n .char-count {\n position: absolute;\n bottom: 12px;\n right: 12px;\n background: rgba(255, 255, 255, 0.9);\n padding: 4px 10px;\n border-radius: 12px;\n font-size: 12px;\n color: #666;\n pointer-events: none;\n box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);\n }\n\n .info-box {\n background: #f9f9f9;\n border-left: 4px solid #333;\n padding: 15px;\n border-radius: 4px;\n margin-bottom: 20px;\n }\n\n .info-box p {\n font-size: 14px;\n color: #555;\n line-height: 1.6;\n }\n\n .buttons {\n display: flex;\n gap: 12px;\n justify-content: flex-end;\n margin-top: 25px;\n }\n\n button {\n padding: 12px 28px;\n border: none;\n border-radius: 8px;\n font-size: 15px;\n font-weight: 600;\n cursor: pointer;\n transition: all 0.3s;\n display: flex;\n align-items: center;\n gap: 8px;\n }\n\n .send-btn {\n background: #333;\n color: white;\n box-shadow: none;\n }\n\n .send-btn:hover:not(:disabled) {\n background: #000;\n }\n\n .send-btn:active:not(:disabled) {\n background: #000;\n }\n\n .send-btn:disabled {\n background: #ccc;\n cursor: not-allowed;\n box-shadow: none;\n }\n\n .cancel-btn {\n background: white;\n color: #666;\n border: 2px solid #e0e0e0;\n }\n\n .cancel-btn:hover {\n background: #f5f5f5;\n border-color: #ccc;\n }\n\n .re-enhance-btn {\n background: white;\n color: #333;\n border: 2px solid #333;\n }\n\n .re-enhance-btn:hover:not(:disabled) {\n background: #f5f5f5;\n border-color: #000;\n }\n\n .re-enhance-btn:disabled {\n background: #f5f5f5;\n color: #ccc;\n border-color: #e0e0e0;\n cursor: not-allowed;\n }\n\n .status {\n margin-top: 20px;\n padding: 15px;\n border-radius: 8px;\n display: none;\n animation: slideIn 0.3s ease;\n }\n\n @keyframes slideIn {\n from {\n opacity: 0;\n transform: translateY(-10px);\n }\n to {\n opacity: 1;\n transform: translateY(0);\n }\n }\n\n .status.success {\n background: #d4edda;\n color: #155724;\n border-left: 4px solid #28a745;\n display: block;\n }\n\n .status.error {\n background: #f8d7da;\n color: #721c24;\n border-left: 4px solid #dc3545;\n display: block;\n }\n\n .loading {\n display: none;\n text-align: center;\n padding: 40px;\n }\n\n .loading.active {\n display: block;\n }\n\n .spinner {\n border: 3px solid #f3f3f3;\n border-top: 3px solid #333;\n border-radius: 50%;\n width: 40px;\n height: 40px;\n animation: spin 1s linear infinite;\n margin: 0 auto 15px;\n }\n\n @keyframes spin {\n 0% { transform: rotate(0deg); }\n 100% { transform: rotate(360deg); }\n }\n\n .keyboard-hint {\n font-size: 12px;\n color: #999;\n text-align: center;\n margin-top: 15px;\n }\n\n .keyboard-hint kbd {\n background: #f5f5f5;\n border: 1px solid #ddd;\n border-radius: 4px;\n padding: 2px 6px;\n font-family: monospace;\n font-size: 11px;\n }\n\n @media (max-width: 768px) {\n body {\n padding: 10px;\n }\n\n .header {\n padding: 20px;\n }\n\n .header h1 {\n font-size: 22px;\n }\n\n .content {\n padding: 20px;\n }\n\n textarea {\n min-height: 250px;\n font-size: 13px;\n }\n\n .buttons {\n flex-direction: column-reverse;\n }\n\n button {\n width: 100%;\n justify-content: center;\n }\n }\n </style>\n</head>\n<body>\n <div class=\"container\">\n <div class=\"header\">\n <h1>\n <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\">\n <path d=\"M12 2L2 7l10 5 10-5-10-5z\"/>\n <path d=\"M2 17l10 5 10-5\"/>\n <path d=\"M2 12l10 5 10-5\"/>\n </svg>\n Prompt Enhancer\n </h1>\n <p>Review and refine your enhanced prompt</p>\n <div class=\"countdown\" id=\"countdown\">\u23F1\uFE0F \u52A0\u8F7D\u4E2D...</div>\n </div>\n\n <div class=\"content\">\n <div class=\"loading\" id=\"loading\">\n <div class=\"spinner\"></div>\n <p>Loading your enhanced prompt...</p>\n </div>\n\n <div id=\"mainContent\" style=\"display: none;\">\n <div class=\"info-box\">\n <p>\n <strong>\uD83D\uDCA1 \u63D0\u793A\uFF1A</strong>AI \u5DF2\u7ECF\u6839\u636E\u5BF9\u8BDD\u5386\u53F2\u548C\u4EE3\u7801\u4E0A\u4E0B\u6587\u589E\u5F3A\u4E86\u4F60\u7684 prompt\u3002\n \u4F60\u53EF\u4EE5\u5728\u4E0B\u65B9\u7F16\u8F91\u5668\u4E2D\u8FDB\u4E00\u6B65\u4FEE\u6539\uFF0C\u7136\u540E\u70B9\u51FB\"\u53D1\u9001\"\u7EE7\u7EED\u3002\n </p>\n </div>\n\n <div class=\"section\">\n <div class=\"section-title\">Enhanced Prompt</div>\n <div class=\"editor-wrapper\">\n <textarea\n id=\"promptText\"\n placeholder=\"Your enhanced prompt will appear here...\"\n spellcheck=\"false\"\n ></textarea>\n <div class=\"char-count\" id=\"charCount\">0 \u5B57\u7B26</div>\n </div>\n </div>\n\n <div class=\"buttons\">\n <button class=\"cancel-btn\" onclick=\"endConversation()\">\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\">\n <line x1=\"18\" y1=\"6\" x2=\"6\" y2=\"18\"/>\n <line x1=\"6\" y1=\"6\" x2=\"18\" y2=\"18\"/>\n </svg>\n \u7ED3\u675F\u5BF9\u8BDD\n </button>\n <button class=\"re-enhance-btn\" id=\"reEnhanceBtn\" onclick=\"reEnhance()\">\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\">\n <polyline points=\"23 4 23 10 17 10\"/>\n <path d=\"M20.49 15a9 9 0 1 1-2.12-9.36L23 10\"/>\n </svg>\n \u7EE7\u7EED\u589E\u5F3A\n </button>\n <button class=\"cancel-btn\" onclick=\"useOriginal()\">\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\">\n <path d=\"M3 12h18M3 6h18M3 18h18\"/>\n </svg>\n \u4F7F\u7528\u539F\u59CB\n </button>\n <button class=\"send-btn\" id=\"sendBtn\" onclick=\"sendPrompt()\">\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\">\n <line x1=\"22\" y1=\"2\" x2=\"11\" y2=\"13\"/>\n <polygon points=\"22 2 15 22 11 13 2 9 22 2\"/>\n </svg>\n \u53D1\u9001\u589E\u5F3A\n </button>\n </div>\n\n <div class=\"keyboard-hint\">\n \u5FEB\u6377\u952E: <kbd>Ctrl</kbd> + <kbd>Enter</kbd> \u53D1\u9001\u589E\u5F3A | <kbd>Esc</kbd> \u7ED3\u675F\u5BF9\u8BDD\n </div>\n\n <div id=\"status\" class=\"status\"></div>\n </div>\n </div>\n </div>\n\n <script>\n const urlParams = new URLSearchParams(window.location.search);\n const sessionId = urlParams.get('session');\n const promptText = document.getElementById('promptText');\n const charCount = document.getElementById('charCount');\n const loading = document.getElementById('loading');\n const mainContent = document.getElementById('mainContent');\n const countdownEl = document.getElementById('countdown');\n\n let countdownInterval = null;\n let sessionCreatedAt = null;\n let sessionTimeoutMs = null;\n\n // \u66F4\u65B0\u5B57\u7B26\u8BA1\u6570\n function updateCharCount() {\n const count = promptText.value.length;\n charCount.textContent = count + ' \u5B57\u7B26';\n }\n\n promptText.addEventListener('input', updateCharCount);\n\n // \u683C\u5F0F\u5316\u65F6\u95F4\u663E\u793A\n function formatTime(ms) {\n const totalSeconds = Math.floor(ms / 1000);\n const minutes = Math.floor(totalSeconds / 60);\n const seconds = totalSeconds % 60;\n return minutes + ':' + seconds.toString().padStart(2, '0');\n }\n\n // \u66F4\u65B0\u5012\u8BA1\u65F6\u663E\u793A\n function updateCountdown() {\n if (!sessionCreatedAt || !sessionTimeoutMs) return;\n\n const now = Date.now();\n const elapsed = now - sessionCreatedAt;\n const remaining = sessionTimeoutMs - elapsed;\n\n if (remaining <= 0) {\n countdownEl.textContent = '\u23F1\uFE0F \u5DF2\u8D85\u65F6';\n countdownEl.className = 'countdown danger';\n if (countdownInterval) {\n clearInterval(countdownInterval);\n countdownInterval = null;\n }\n return;\n }\n\n const remainingMinutes = remaining / 60000;\n\n // \u66F4\u65B0\u6837\u5F0F\n if (remainingMinutes <= 1) {\n countdownEl.className = 'countdown danger';\n } else if (remainingMinutes <= 3) {\n countdownEl.className = 'countdown warning';\n } else {\n countdownEl.className = 'countdown';\n }\n\n countdownEl.textContent = '\u23F1\uFE0F \u5269\u4F59\u65F6\u95F4: ' + formatTime(remaining);\n }\n\n // \u542F\u52A8\u5012\u8BA1\u65F6\n function startCountdown(createdAt, timeoutMs) {\n sessionCreatedAt = createdAt;\n sessionTimeoutMs = timeoutMs;\n\n updateCountdown();\n\n if (countdownInterval) {\n clearInterval(countdownInterval);\n }\n\n countdownInterval = setInterval(updateCountdown, 1000);\n }\n\n // \u952E\u76D8\u5FEB\u6377\u952E\n document.addEventListener('keydown', (e) => {\n if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') {\n e.preventDefault();\n sendPrompt();\n } else if (e.key === 'Escape') {\n e.preventDefault();\n endConversation();\n }\n });\n\n // \u52A0\u8F7D session \u6570\u636E\n if (!sessionId) {\n loading.style.display = 'none';\n mainContent.style.display = 'block';\n showStatus('\u9519\u8BEF: \u672A\u63D0\u4F9B session ID', 'error');\n } else {\n loading.classList.add('active');\n\n fetch('/api/session?session=' + encodeURIComponent(sessionId))\n .then(r => r.json())\n .then(data => {\n promptText.value = data.enhancedPrompt;\n updateCharCount();\n loading.classList.remove('active');\n mainContent.style.display = 'block';\n promptText.focus();\n\n // \u542F\u52A8\u5012\u8BA1\u65F6\n if (data.createdAt && data.timeoutMs) {\n startCountdown(data.createdAt, data.timeoutMs);\n }\n })\n .catch(err => {\n loading.classList.remove('active');\n mainContent.style.display = 'block';\n showStatus('\u52A0\u8F7D\u5931\u8D25: ' + err.message, 'error');\n });\n }\n\n function reEnhance() {\n const currentContent = promptText.value.trim();\n\n if (!currentContent) {\n showStatus('\u8BF7\u8F93\u5165\u5185\u5BB9\u540E\u518D\u589E\u5F3A', 'error');\n return;\n }\n\n const reEnhanceBtn = document.getElementById('reEnhanceBtn');\n const sendBtn = document.getElementById('sendBtn');\n\n reEnhanceBtn.disabled = true;\n sendBtn.disabled = true;\n reEnhanceBtn.innerHTML = '<div class=\"spinner\" style=\"width: 16px; height: 16px; border-width: 2px; margin: 0;\"></div> \u589E\u5F3A\u4E2D...';\n\n fetch('/api/re-enhance', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n sessionId: sessionId,\n currentPrompt: currentContent\n })\n })\n .then(r => r.json())\n .then(data => {\n if (data.error) {\n throw new Error(data.error);\n }\n\n promptText.value = data.enhancedPrompt;\n updateCharCount();\n showStatus('\u2705 \u589E\u5F3A\u6210\u529F\uFF01\u4F60\u53EF\u4EE5\u7EE7\u7EED\u7F16\u8F91\u6216\u53D1\u9001', 'success');\n\n reEnhanceBtn.disabled = false;\n sendBtn.disabled = false;\n reEnhanceBtn.innerHTML = '<svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"><polyline points=\"23 4 23 10 17 10\"/><path d=\"M20.49 15a9 9 0 1 1-2.12-9.36L23 10\"/></svg> \u7EE7\u7EED\u589E\u5F3A';\n })\n .catch(err => {\n showStatus('\u589E\u5F3A\u5931\u8D25: ' + err.message, 'error');\n reEnhanceBtn.disabled = false;\n sendBtn.disabled = false;\n reEnhanceBtn.innerHTML = '<svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"><polyline points=\"23 4 23 10 17 10\"/><path d=\"M20.49 15a9 9 0 1 1-2.12-9.36L23 10\"/></svg> \u7EE7\u7EED\u589E\u5F3A';\n });\n }\n\n function sendPrompt() {\n const content = promptText.value.trim();\n\n if (!content) {\n showStatus('\u8BF7\u8F93\u5165\u5185\u5BB9\u540E\u518D\u53D1\u9001', 'error');\n return;\n }\n\n const sendBtn = document.getElementById('sendBtn');\n const reEnhanceBtn = document.getElementById('reEnhanceBtn');\n\n sendBtn.disabled = true;\n reEnhanceBtn.disabled = true;\n sendBtn.innerHTML = '<div class=\"spinner\" style=\"width: 16px; height: 16px; border-width: 2px; margin: 0;\"></div> \u53D1\u9001\u4E2D...';\n\n fetch('/api/submit', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ sessionId: sessionId, content: content })\n })\n .then(r => r.json())\n .then(data => {\n showStatus('\u2705 \u53D1\u9001\u6210\u529F\uFF01\u7A97\u53E3\u5C06\u5728 2 \u79D2\u540E\u81EA\u52A8\u5173\u95ED...', 'success');\n setTimeout(() => window.close(), 2000);\n })\n .catch(err => {\n showStatus('\u53D1\u9001\u5931\u8D25: ' + err.message, 'error');\n sendBtn.disabled = false;\n reEnhanceBtn.disabled = false;\n sendBtn.innerHTML = '<svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"><line x1=\"22\" y1=\"2\" x2=\"11\" y2=\"13\"/><polygon points=\"22 2 15 22 11 13 2 9 22 2\"/></svg> \u53D1\u9001';\n });\n }\n\n function useOriginal() {\n if (confirm('\u786E\u5B9A\u4F7F\u7528\u539F\u59CB prompt \u7EE7\u7EED\u5BF9\u8BDD\u5417\uFF1F')) {\n fetch('/api/submit', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ sessionId: sessionId, content: '__USE_ORIGINAL__' })\n })\n .then(() => {\n showStatus('\u2705 \u5C06\u4F7F\u7528\u539F\u59CB prompt \u7EE7\u7EED...', 'success');\n setTimeout(() => window.close(), 1000);\n })\n .catch(() => window.close());\n }\n }\n\n function endConversation() {\n if (confirm('\u786E\u5B9A\u8981\u7ED3\u675F\u672C\u6B21\u5BF9\u8BDD\u5417\uFF1F')) {\n fetch('/api/submit', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ sessionId: sessionId, content: '__END_CONVERSATION__' })\n })\n .then(() => {\n showStatus('\u2705 \u5BF9\u8BDD\u5DF2\u7ED3\u675F', 'success');\n setTimeout(() => window.close(), 1000);\n })\n .catch(() => window.close());\n }\n }\n\n function showStatus(message, type) {\n const status = document.getElementById('status');\n status.textContent = message;\n status.className = 'status ' + type;\n }\n </script>\n</body>\n</html>";
|
|
14
|
+
//# sourceMappingURL=templates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../src/enhancer/templates.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;GAGG;AACH,eAAO,MAAM,uBAAuB,8vBAqBlB,CAAC;AAEnB;;GAEG;AACH,eAAO,MAAM,gBAAgB,qwkBA8nBrB,CAAC"}
|