forked from MackDing/CodexClaw
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrouter.js
More file actions
70 lines (63 loc) · 1.38 KB
/
Copy pathrouter.js
File metadata and controls
70 lines (63 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const CODING_KEYWORDS = [
"code",
"bug",
"fix",
"refactor",
"function",
"class",
"typescript",
"javascript",
"node",
"npm",
"test",
"lint",
"build",
"部署",
"代码",
"修复",
"重构",
"单测",
"脚本"
];
function likelyCodingTask(text) {
const normalized = text.toLowerCase();
if (normalized.includes("```")) return true;
if (/\b(src|tests|package\.json|dockerfile)\b/i.test(text)) return true;
return CODING_KEYWORDS.some((keyword) => normalized.includes(keyword));
}
export class Router {
constructor({ skills, isSkillEnabled = () => true }) {
this.skills = skills;
this.isSkillEnabled = isSkillEnabled;
}
async routeMessage(text, options = {}) {
const raw = text.trim();
const chatId = options.chatId;
const githubSkill = this.skills.github;
const mcpSkill = this.skills.mcp;
if (githubSkill && this.isSkillEnabled(chatId, "github") && githubSkill.supports(raw)) {
return {
target: "skill",
skill: "github",
payload: raw
};
}
if (mcpSkill && this.isSkillEnabled(chatId, "mcp") && mcpSkill.supports(raw)) {
return {
target: "skill",
skill: "mcp",
payload: raw
};
}
if (likelyCodingTask(raw)) {
return {
target: "pty",
prompt: raw
};
}
return {
target: "pty",
prompt: raw
};
}
}