Skip to content

Commit ee3e984

Browse files
committed
feat:所有functioncall调用的时候发消息
1 parent 9f37628 commit ee3e984

File tree

1 file changed

+125
-115
lines changed

1 file changed

+125
-115
lines changed

src/apiTools.ts

Lines changed: 125 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ export const searchTool: Tool = {
302302
required: ['query'],
303303
},
304304
function: async (args: { query: string }) => {
305+
vscode.window.showInformationMessage('CodeReDesign 正在搜索网络');
305306
try {
306307
const links = await getLinksWithBrowser(args.query);
307308
if (!links.length) {
@@ -335,6 +336,7 @@ export const getCurrentDateTime: Tool = {
335336
required: [],
336337
},
337338
function: async () => {
339+
vscode.window.showInformationMessage('CodeReDesign 正在获取当前日期');
338340
const now = new Date();
339341
return now.toLocaleString();
340342
},
@@ -382,6 +384,7 @@ export const queryMySQL: Tool = {
382384
required: ['host', 'user', 'password', 'database', 'query'],
383385
},
384386
function: async (args: { host: string; user: string; password: string; database: string; query: string }) => {
387+
vscode.window.showInformationMessage('CodeReDesign 正在连接MySQL');
385388
try {
386389
const connection = await mysql.createConnection({
387390
host: args.host,
@@ -460,103 +463,104 @@ export const getSVNLog: Tool = {
460463
required: ['path'],
461464
},
462465
function: async (args): Promise<string> => {
463-
try {
464-
const params: string[] = [];
465-
let repoPath = args.path;
466-
467-
// 时间处理函数
468-
const parseTime = (timeStr?: string, isEndTime = false): string => {
469-
if (!timeStr) { return isEndTime ? 'HEAD' : '1'; }
470-
471-
const relativeMatch = timeStr.match(/^(\d+)([hd])$/);
472-
if (relativeMatch) {
473-
const now = new Date();
474-
const [, value, unit] = relativeMatch;
475-
const ms = parseInt(value) * (unit === 'h' ? 3600 : 86400) * 1000;
476-
return `{${new Date(now.getTime() - ms).toISOString().slice(0, 19)}}`;
477-
}
478-
479-
if (/^\d{4}-\d{2}-\d{2}$/.test(timeStr)) {
480-
return isEndTime
481-
? `{${timeStr} 23:59:59}`
482-
: `{${timeStr} 00:00:00}`;
483-
}
484-
485-
throw new Error(`Invalid time format: ${timeStr}`);
486-
};
487-
488-
// 构建查询参数
489-
if (args.author) { params.push(`--search "author:${args.author}"`); }
490-
if (args.keyword) { params.push(`--search "message:${args.keyword}"`); }
491-
492-
const startRev = parseTime(args.startDate);
493-
const endRev = parseTime(args.endDate, true);
494-
if (startRev !== '1' || endRev !== 'HEAD') {
495-
params.push(`--revision ${startRev}:${endRev}`);
496-
}
497-
498-
if (args.revisionStart || args.revisionEnd) {
499-
const start = args.revisionStart ?? 1;
500-
const end = args.revisionEnd ?? 'HEAD';
501-
params.push(`--revision ${start}:${end}`);
502-
}
503-
504-
if (args.limit) { params.push(`-l ${args.limit}`); }
505-
506-
// 获取仓库根地址
507-
if (!/^(http|https|svn):\/\//.test(repoPath)) {
508-
const { stdout } = await execAsync(
509-
`svn info "${repoPath}" --show-item repos-root-url`,
510-
{ encoding: 'utf8' }
511-
);
512-
repoPath = stdout.trim();
466+
vscode.window.showInformationMessage('CodeReDesign 正在查询svn提交日志');
467+
try {
468+
const params: string[] = [];
469+
let repoPath = args.path;
470+
471+
// 时间处理函数
472+
const parseTime = (timeStr?: string, isEndTime = false): string => {
473+
if (!timeStr) { return isEndTime ? 'HEAD' : '1'; }
474+
475+
const relativeMatch = timeStr.match(/^(\d+)([hd])$/);
476+
if (relativeMatch) {
477+
const now = new Date();
478+
const [, value, unit] = relativeMatch;
479+
const ms = parseInt(value) * (unit === 'h' ? 3600 : 86400) * 1000;
480+
return `{${new Date(now.getTime() - ms).toISOString().slice(0, 19)}}`;
481+
}
482+
483+
if (/^\d{4}-\d{2}-\d{2}$/.test(timeStr)) {
484+
return isEndTime
485+
? `{${timeStr} 23:59:59}`
486+
: `{${timeStr} 00:00:00}`;
487+
}
488+
489+
throw new Error(`Invalid time format: ${timeStr}`);
490+
};
491+
492+
// 构建查询参数
493+
if (args.author) { params.push(`--search "author:${args.author}"`); }
494+
if (args.keyword) { params.push(`--search "message:${args.keyword}"`); }
495+
496+
const startRev = parseTime(args.startDate);
497+
const endRev = parseTime(args.endDate, true);
498+
if (startRev !== '1' || endRev !== 'HEAD') {
499+
params.push(`--revision ${startRev}:${endRev}`);
500+
}
501+
502+
if (args.revisionStart || args.revisionEnd) {
503+
const start = args.revisionStart ?? 1;
504+
const end = args.revisionEnd ?? 'HEAD';
505+
params.push(`--revision ${start}:${end}`);
506+
}
507+
508+
if (args.limit) { params.push(`-l ${args.limit}`); }
509+
510+
// 获取仓库根地址
511+
if (!/^(http|https|svn):\/\//.test(repoPath)) {
512+
const { stdout } = await execAsync(
513+
`svn info "${repoPath}" --show-item repos-root-url`,
514+
{ encoding: 'utf8' }
515+
);
516+
repoPath = stdout.trim();
517+
}
518+
519+
// 执行命令
520+
const { stdout } = await execAsync(
521+
`svn log "${repoPath}" --xml ${params.join(' ')}`,
522+
{ encoding: 'gbk' as BufferEncoding, maxBuffer: 1024 * 1024 * 10 }
523+
);
524+
525+
// 解析XML
526+
const parsed = await new Promise<any>((resolve, reject) => {
527+
parseString(stdout, (err, result) => {
528+
err ? reject(err) : resolve(result);
529+
});
530+
});
531+
532+
// 转换为LogEntry数组
533+
const entries: LogEntry[] = (parsed.log.logentry || []).map(
534+
(entry: any) => ({
535+
revision: entry.$.revision,
536+
author: entry.author?.[0],
537+
date: entry.date?.[0],
538+
message: entry.msg?.[0]?.trim(),
539+
paths: (entry.paths?.[0]?.path || []).map((p: any) => ({
540+
action: p.$.action,
541+
path: p._
542+
}))
543+
})
544+
);
545+
546+
return JSON.stringify(entries, null, 2);
547+
548+
} catch (error) {
549+
const err = error as SVNError;
550+
const errorMapping: Record<string, string> = {
551+
'175002': '认证失败',
552+
'160013': '路径不存在',
553+
'200009': '无效时间格式',
554+
'205000': '无效版本号'
555+
};
556+
557+
const errorCode = err.stderr?.match(/svn: E(\d+):/)?.[1] || '';
558+
const message = errorCode in errorMapping
559+
? `SVN错误 [E${errorCode}]: ${errorMapping[errorCode]}`
560+
: `操作失败: ${err.message?.replace(/^svn: E\d+: /, '') || '未知错误'}`;
561+
562+
return message;
513563
}
514-
515-
// 执行命令
516-
const { stdout } = await execAsync(
517-
`svn log "${repoPath}" --xml ${params.join(' ')}`,
518-
{ encoding: 'gbk' as BufferEncoding, maxBuffer: 1024 * 1024 * 10 }
519-
);
520-
521-
// 解析XML
522-
const parsed = await new Promise<any>((resolve, reject) => {
523-
parseString(stdout, (err, result) => {
524-
err ? reject(err) : resolve(result);
525-
});
526-
});
527-
528-
// 转换为LogEntry数组
529-
const entries: LogEntry[] = (parsed.log.logentry || []).map(
530-
(entry: any) => ({
531-
revision: entry.$.revision,
532-
author: entry.author?.[0],
533-
date: entry.date?.[0],
534-
message: entry.msg?.[0]?.trim(),
535-
paths: (entry.paths?.[0]?.path || []).map((p: any) => ({
536-
action: p.$.action,
537-
path: p._
538-
}))
539-
})
540-
);
541-
542-
return JSON.stringify(entries, null, 2);
543-
544-
} catch (error) {
545-
const err = error as SVNError;
546-
const errorMapping: Record<string, string> = {
547-
'175002': '认证失败',
548-
'160013': '路径不存在',
549-
'200009': '无效时间格式',
550-
'205000': '无效版本号'
551-
};
552-
553-
const errorCode = err.stderr?.match(/svn: E(\d+):/)?.[1] || '';
554-
const message = errorCode in errorMapping
555-
? `SVN错误 [E${errorCode}]: ${errorMapping[errorCode]}`
556-
: `操作失败: ${err.message?.replace(/^svn: E\d+: /, '') || '未知错误'}`;
557-
558-
return message;
559-
}
560564
}
561565
};
562566

@@ -574,6 +578,7 @@ export const getSVNDiff: Tool = {
574578
required: ['repoPath'],
575579
},
576580
function: async (args: { repoPath: string }) => {
581+
vscode.window.showInformationMessage('CodeReDesign 正在获取svn本地差异');
577582
try {
578583
const exec = promisify(childProcess.exec);
579584
const { stdout } = await exec(`svn diff "${args.repoPath}"`);
@@ -597,6 +602,7 @@ export const getGitDiff: Tool = {
597602
required: ['repoPath'],
598603
},
599604
function: async (args: { repoPath: string }) => {
605+
vscode.window.showInformationMessage('CodeReDesign 正在查询git本地差异');
600606
try {
601607
const exec = promisify(childProcess.exec);
602608
const { stdout } = await exec(`git -C "${args.repoPath}" diff`);
@@ -621,6 +627,7 @@ export const grepSearch: Tool = {
621627
required: ['directory', 'pattern'],
622628
},
623629
function: async (args: { directory: string; pattern: string }) => {
630+
vscode.window.showInformationMessage('CodeReDesign 正在使用grep搜索');
624631
try {
625632
const exec = promisify(childProcess.exec);
626633
const { stdout } = await exec(`findstr /s /i /m /c:"${args.pattern}" "${args.directory}\\*"`);
@@ -655,6 +662,7 @@ export const findFiles: Tool = {
655662
required: ['directory', 'pattern', 'useRegex'],
656663
},
657664
function: async (args: { directory: string; pattern: string; useRegex: boolean }) => {
665+
vscode.window.showInformationMessage('CodeReDesign 正在查找文件');
658666
try {
659667
const { directory, pattern, useRegex } = args;
660668
const queue: string[] = [directory];
@@ -714,26 +722,27 @@ export const writeMemory: Tool = {
714722
required: ['content'],
715723
},
716724
function: async (args: { content: string }) => {
717-
try {
718-
// 调用FastAPI的/add_knowledge端点
719-
const response = await fetch(`http://localhost:${RAG_CONFIG.PORT}/add_knowledge`, {
720-
method: 'POST',
721-
headers: { 'Content-Type': 'application/json' },
722-
body: JSON.stringify([args.content]),
723-
});
724-
725-
if (!response.ok) {
726-
const errorText = await response.text();
727-
throw new Error(`API request failed: ${response.status} - ${errorText}`);
725+
vscode.window.showInformationMessage('CodeReDesign 正在写入记忆');
726+
try {
727+
// 调用FastAPI的/add_knowledge端点
728+
const response = await fetch(`http://localhost:${RAG_CONFIG.PORT}/add_knowledge`, {
729+
method: 'POST',
730+
headers: { 'Content-Type': 'application/json' },
731+
body: JSON.stringify([args.content]),
732+
});
733+
734+
if (!response.ok) {
735+
const errorText = await response.text();
736+
throw new Error(`API request failed: ${response.status} - ${errorText}`);
737+
}
738+
739+
const result = await response.json() as { status: string };
740+
return result.status === 'added'
741+
? `Memory saved: ${args.content.slice(0, 50)}...`
742+
: "Failed to save memory";
743+
} catch (error: any) {
744+
return `保存记忆失败: ${error.message}`;
728745
}
729-
730-
const result = await response.json() as { status: string };
731-
return result.status === 'added'
732-
? `Memory saved: ${args.content.slice(0, 50)}...`
733-
: "Failed to save memory";
734-
} catch (error: any) {
735-
return `保存记忆失败: ${error.message}`;
736-
}
737746
},
738747
};
739748

@@ -749,6 +758,7 @@ export const readMemory: Tool = {
749758
required: ['query'],
750759
},
751760
function: async (args: { query: string }) => {
761+
vscode.window.showInformationMessage('CodeReDesign 正在读取记忆');
752762
try {
753763
// 调用FastAPI的/query端点
754764
const response = await fetch(`http://localhost:${RAG_CONFIG.PORT}/query?query_text=${encodeURIComponent(args.query)}`, {

0 commit comments

Comments
 (0)