@wu529778790/open-im 1.11.2-beta.21 → 1.11.2-beta.23
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.
|
@@ -20,7 +20,7 @@ export declare class CommandHandler {
|
|
|
20
20
|
private deps;
|
|
21
21
|
constructor(deps: CommandHandlerDeps);
|
|
22
22
|
private replySender;
|
|
23
|
-
dispatch(text: string, chatId: string, userId: string, platform: Platform,
|
|
23
|
+
dispatch(text: string, chatId: string, userId: string, platform: Platform, handleClaudeRequest: ClaudeRequestHandler,
|
|
24
24
|
/** 若提供,本条消息的斜杠命令回复走此 sender(须与 handleTextFlow 的 sendTextReply 一致,如带 msgId)。 */
|
|
25
25
|
senderOverride?: MessageSender): Promise<boolean>;
|
|
26
26
|
private handleHelp;
|
|
@@ -38,6 +38,12 @@ export declare class CommandHandler {
|
|
|
38
38
|
private handleModels;
|
|
39
39
|
private handleContext;
|
|
40
40
|
private getAiVersion;
|
|
41
|
+
/**
|
|
42
|
+
* 快捷命令 — 将预设 prompt 发送给 AI
|
|
43
|
+
*/
|
|
44
|
+
private handleQuickCommand;
|
|
45
|
+
/** 临时存储 dispatch 传入的 handler */
|
|
46
|
+
private quickCommandHandler;
|
|
41
47
|
}
|
|
42
48
|
/**
|
|
43
49
|
* 列出目录并返回目录信息
|
package/dist/commands/handler.js
CHANGED
|
@@ -65,9 +65,11 @@ export class CommandHandler {
|
|
|
65
65
|
replySender() {
|
|
66
66
|
return commandReplySender.getStore() ?? this.deps.sender;
|
|
67
67
|
}
|
|
68
|
-
async dispatch(text, chatId, userId, platform,
|
|
68
|
+
async dispatch(text, chatId, userId, platform, handleClaudeRequest,
|
|
69
69
|
/** 若提供,本条消息的斜杠命令回复走此 sender(须与 handleTextFlow 的 sendTextReply 一致,如带 msgId)。 */
|
|
70
70
|
senderOverride) {
|
|
71
|
+
// 存储 handler 供快捷命令使用
|
|
72
|
+
this.quickCommandHandler = handleClaudeRequest;
|
|
71
73
|
const runBody = async () => {
|
|
72
74
|
const t = normalizeSlashCommandForDispatch(text);
|
|
73
75
|
if (platform === 'telegram' && t === '/start') {
|
|
@@ -100,6 +102,21 @@ export class CommandHandler {
|
|
|
100
102
|
return this.handlePwd(chatId, userId);
|
|
101
103
|
if (t === '/status')
|
|
102
104
|
return this.handleStatus(chatId, userId, platform);
|
|
105
|
+
// 快捷命令 — 直接发送预设 prompt 给 AI
|
|
106
|
+
if (t === '/git commit')
|
|
107
|
+
return this.handleQuickCommand(chatId, userId, 'git commit -m "AI generated commit"', platform);
|
|
108
|
+
if (t === '/git push')
|
|
109
|
+
return this.handleQuickCommand(chatId, userId, 'git push origin main', platform);
|
|
110
|
+
if (t === '/git pull')
|
|
111
|
+
return this.handleQuickCommand(chatId, userId, 'git pull origin main', platform);
|
|
112
|
+
if (t === '/test')
|
|
113
|
+
return this.handleQuickCommand(chatId, userId, 'npm test', platform);
|
|
114
|
+
if (t === '/build')
|
|
115
|
+
return this.handleQuickCommand(chatId, userId, 'npm run build', platform);
|
|
116
|
+
if (t === '/review')
|
|
117
|
+
return this.handleQuickCommand(chatId, userId, '请审查当前代码,找出潜在问题和改进建议', platform);
|
|
118
|
+
if (t === '/explain')
|
|
119
|
+
return this.handleQuickCommand(chatId, userId, '请解释当前目录的项目结构和核心逻辑', platform);
|
|
103
120
|
if (t === '/cd' || t.startsWith('/cd ')) {
|
|
104
121
|
return this.handleCd(chatId, userId, t.slice(3).trim(), platform);
|
|
105
122
|
}
|
|
@@ -133,6 +150,15 @@ export class CommandHandler {
|
|
|
133
150
|
'/status - 显示状态',
|
|
134
151
|
'/cd <路径> - 切换工作目录',
|
|
135
152
|
'/pwd - 当前工作目录',
|
|
153
|
+
'',
|
|
154
|
+
'⚡ 快捷命令:',
|
|
155
|
+
'/git commit - 提交代码',
|
|
156
|
+
'/git push - 推送到远程',
|
|
157
|
+
'/git pull - 拉取远程更新',
|
|
158
|
+
'/test - 运行测试',
|
|
159
|
+
'/build - 构建项目',
|
|
160
|
+
'/review - 代码审查',
|
|
161
|
+
'/explain - 解释项目结构',
|
|
136
162
|
].join('\n');
|
|
137
163
|
await this.replySender().sendTextReply(chatId, help);
|
|
138
164
|
return true;
|
|
@@ -445,6 +471,18 @@ export class CommandHandler {
|
|
|
445
471
|
});
|
|
446
472
|
});
|
|
447
473
|
}
|
|
474
|
+
/**
|
|
475
|
+
* 快捷命令 — 将预设 prompt 发送给 AI
|
|
476
|
+
*/
|
|
477
|
+
async handleQuickCommand(chatId, userId, prompt, platform) {
|
|
478
|
+
const workDir = this.deps.sessionManager.getWorkDir(userId);
|
|
479
|
+
const convId = this.deps.sessionManager.getConvId(userId);
|
|
480
|
+
// 使用 dispatch 传入的 handleClaudeRequest
|
|
481
|
+
await this.quickCommandHandler(userId, chatId, prompt, workDir, convId);
|
|
482
|
+
return true;
|
|
483
|
+
}
|
|
484
|
+
/** 临时存储 dispatch 传入的 handler */
|
|
485
|
+
quickCommandHandler = async () => { };
|
|
448
486
|
}
|
|
449
487
|
/**
|
|
450
488
|
* 列出目录并返回目录信息
|
|
@@ -120,7 +120,15 @@ export async function sendFinalMessages(chatId, messageId, fullContent, note, to
|
|
|
120
120
|
export async function sendTextReply(chatId, text) {
|
|
121
121
|
const bot = getBot();
|
|
122
122
|
try {
|
|
123
|
-
|
|
123
|
+
const formatted = formatMessage(text, "done", undefined, OPEN_IM_SYSTEM_TITLE);
|
|
124
|
+
// 尝试 Markdown 模式,如果失败则回退到纯文本
|
|
125
|
+
try {
|
|
126
|
+
await bot.telegram.sendMessage(Number(chatId), formatted, { parse_mode: "Markdown" });
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
// Markdown 解析失败,回退到纯文本
|
|
130
|
+
await bot.telegram.sendMessage(Number(chatId), formatted);
|
|
131
|
+
}
|
|
124
132
|
}
|
|
125
133
|
catch (err) {
|
|
126
134
|
log.error("Failed to send text:", err);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wu529778790/open-im",
|
|
3
|
-
"version": "1.11.2-beta.
|
|
3
|
+
"version": "1.11.2-beta.23",
|
|
4
4
|
"description": "Your AI coding assistant, in every chat app. Multi-platform IM bridge for Claude Code, Codex, and CodeBuddy.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|