mycohive-claw 4.0.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/LICENSE +21 -0
- package/README.md +222 -0
- package/dist/circuit-breaker.d.ts +82 -0
- package/dist/circuit-breaker.d.ts.map +1 -0
- package/dist/circuit-breaker.js +214 -0
- package/dist/circuit-breaker.js.map +1 -0
- package/dist/context-tree.d.ts +94 -0
- package/dist/context-tree.d.ts.map +1 -0
- package/dist/context-tree.js +624 -0
- package/dist/context-tree.js.map +1 -0
- package/dist/event-bus.d.ts +174 -0
- package/dist/event-bus.d.ts.map +1 -0
- package/dist/event-bus.js +750 -0
- package/dist/event-bus.js.map +1 -0
- package/dist/i18n.d.ts +91 -0
- package/dist/i18n.d.ts.map +1 -0
- package/dist/i18n.js +150 -0
- package/dist/i18n.js.map +1 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +301 -0
- package/dist/index.js.map +1 -0
- package/dist/intent-analyzer.d.ts +119 -0
- package/dist/intent-analyzer.d.ts.map +1 -0
- package/dist/intent-analyzer.js +563 -0
- package/dist/intent-analyzer.js.map +1 -0
- package/dist/logger.d.ts +46 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +126 -0
- package/dist/logger.js.map +1 -0
- package/dist/metrics.d.ts +98 -0
- package/dist/metrics.d.ts.map +1 -0
- package/dist/metrics.js +192 -0
- package/dist/metrics.js.map +1 -0
- package/dist/openclaw-api.d.ts +122 -0
- package/dist/openclaw-api.d.ts.map +1 -0
- package/dist/openclaw-api.js +8 -0
- package/dist/openclaw-api.js.map +1 -0
- package/dist/rate-limiter.d.ts +46 -0
- package/dist/rate-limiter.d.ts.map +1 -0
- package/dist/rate-limiter.js +134 -0
- package/dist/rate-limiter.js.map +1 -0
- package/dist/result-cache.d.ts +76 -0
- package/dist/result-cache.d.ts.map +1 -0
- package/dist/result-cache.js +158 -0
- package/dist/result-cache.js.map +1 -0
- package/dist/router.d.ts +90 -0
- package/dist/router.d.ts.map +1 -0
- package/dist/router.js +447 -0
- package/dist/router.js.map +1 -0
- package/dist/setup-entry.d.ts +18 -0
- package/dist/setup-entry.d.ts.map +1 -0
- package/dist/setup-entry.js +64 -0
- package/dist/setup-entry.js.map +1 -0
- package/dist/token-counter.d.ts +57 -0
- package/dist/token-counter.d.ts.map +1 -0
- package/dist/token-counter.js +125 -0
- package/dist/token-counter.js.map +1 -0
- package/dist/tool-handlers.d.ts +52 -0
- package/dist/tool-handlers.d.ts.map +1 -0
- package/dist/tool-handlers.js +317 -0
- package/dist/tool-handlers.js.map +1 -0
- package/dist/tools/mycohive-tools.d.ts +11 -0
- package/dist/tools/mycohive-tools.d.ts.map +1 -0
- package/dist/tools/mycohive-tools.js +160 -0
- package/dist/tools/mycohive-tools.js.map +1 -0
- package/dist/types.d.ts +58 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +57 -0
- package/dist/types.js.map +1 -0
- package/dist/workspace-loader.d.ts +67 -0
- package/dist/workspace-loader.d.ts.map +1 -0
- package/dist/workspace-loader.js +175 -0
- package/dist/workspace-loader.js.map +1 -0
- package/package.json +52 -0
- package/workspaces/api_dev/CONFIG.md +31 -0
- package/workspaces/api_dev/RULES.md +8 -0
- package/workspaces/api_dev/SKILL.md +69 -0
- package/workspaces/api_dev/SOUL.md +19 -0
- package/workspaces/architect/CONFIG.md +32 -0
- package/workspaces/architect/RULES.md +8 -0
- package/workspaces/architect/SKILL.md +63 -0
- package/workspaces/architect/SOUL.md +19 -0
- package/workspaces/backend_dev/CONFIG.md +42 -0
- package/workspaces/backend_dev/RULES.md +8 -0
- package/workspaces/backend_dev/SKILL.md +41 -0
- package/workspaces/backend_dev/SOUL.md +19 -0
- package/workspaces/browser/CONFIG.md +42 -0
- package/workspaces/browser/RULES.md +8 -0
- package/workspaces/browser/SKILL.md +57 -0
- package/workspaces/browser/SOUL.md +19 -0
- package/workspaces/builder/CONFIG.md +31 -0
- package/workspaces/builder/RULES.md +8 -0
- package/workspaces/builder/SKILL.md +39 -0
- package/workspaces/builder/SOUL.md +18 -0
- package/workspaces/coder/CONFIG.md +44 -0
- package/workspaces/coder/RULES.md +9 -0
- package/workspaces/coder/SKILL.md +53 -0
- package/workspaces/coder/SOUL.md +19 -0
- package/workspaces/coordinator/CONFIG.md +62 -0
- package/workspaces/coordinator/RULES.md +8 -0
- package/workspaces/coordinator/SKILL.md +77 -0
- package/workspaces/coordinator/SOUL.md +20 -0
- package/workspaces/data_engineer/CONFIG.md +32 -0
- package/workspaces/data_engineer/RULES.md +8 -0
- package/workspaces/data_engineer/SKILL.md +44 -0
- package/workspaces/data_engineer/SOUL.md +19 -0
- package/workspaces/deployer/CONFIG.md +45 -0
- package/workspaces/deployer/RULES.md +8 -0
- package/workspaces/deployer/SKILL.md +74 -0
- package/workspaces/deployer/SOUL.md +19 -0
- package/workspaces/dreamer/CONFIG.md +34 -0
- package/workspaces/dreamer/RULES.md +8 -0
- package/workspaces/dreamer/SKILL.md +48 -0
- package/workspaces/dreamer/SOUL.md +19 -0
- package/workspaces/evaluator/CONFIG.md +40 -0
- package/workspaces/evaluator/RULES.md +21 -0
- package/workspaces/evaluator/SKILL.md +65 -0
- package/workspaces/evaluator/SOUL.md +20 -0
- package/workspaces/front_director/CONFIG.md +54 -0
- package/workspaces/front_director/RULES.md +8 -0
- package/workspaces/front_director/SKILL.md +52 -0
- package/workspaces/front_director/SOUL.md +20 -0
- package/workspaces/frontend_dev/CONFIG.md +33 -0
- package/workspaces/frontend_dev/RULES.md +8 -0
- package/workspaces/frontend_dev/SKILL.md +42 -0
- package/workspaces/frontend_dev/SOUL.md +19 -0
- package/workspaces/observer/CONFIG.md +60 -0
- package/workspaces/observer/RULES.md +7 -0
- package/workspaces/observer/SKILL.md +77 -0
- package/workspaces/observer/SOUL.md +19 -0
- package/workspaces/planner/CONFIG.md +43 -0
- package/workspaces/planner/RULES.md +8 -0
- package/workspaces/planner/SKILL.md +65 -0
- package/workspaces/planner/SOUL.md +20 -0
- package/workspaces/qa/CONFIG.md +32 -0
- package/workspaces/qa/RULES.md +8 -0
- package/workspaces/qa/SKILL.md +52 -0
- package/workspaces/qa/SOUL.md +19 -0
- package/workspaces/researcher/CONFIG.md +32 -0
- package/workspaces/researcher/RULES.md +8 -0
- package/workspaces/researcher/SKILL.md +58 -0
- package/workspaces/researcher/SOUL.md +20 -0
- package/workspaces/reviewer/CONFIG.md +41 -0
- package/workspaces/reviewer/RULES.md +17 -0
- package/workspaces/reviewer/SKILL.md +56 -0
- package/workspaces/reviewer/SOUL.md +20 -0
- package/workspaces/router/CONFIG.md +58 -0
- package/workspaces/router/RULES.md +8 -0
- package/workspaces/router/SKILL.md +97 -0
- package/workspaces/router/SOUL.md +20 -0
- package/workspaces/scraper/CONFIG.md +41 -0
- package/workspaces/scraper/RULES.md +8 -0
- package/workspaces/scraper/SKILL.md +51 -0
- package/workspaces/scraper/SOUL.md +19 -0
- package/workspaces/scripter/CONFIG.md +42 -0
- package/workspaces/scripter/RULES.md +8 -0
- package/workspaces/scripter/SKILL.md +54 -0
- package/workspaces/scripter/SOUL.md +18 -0
- package/workspaces/security/CONFIG.md +47 -0
- package/workspaces/security/RULES.md +8 -0
- package/workspaces/security/SKILL.md +50 -0
- package/workspaces/security/SOUL.md +19 -0
- package/workspaces/translator/CONFIG.md +43 -0
- package/workspaces/translator/RULES.md +8 -0
- package/workspaces/translator/SKILL.md +35 -0
- package/workspaces/translator/SOUL.md +19 -0
- package/workspaces/writer/CONFIG.md +31 -0
- package/workspaces/writer/RULES.md +8 -0
- package/workspaces/writer/SKILL.md +40 -0
- package/workspaces/writer/SOUL.md +19 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token Counter 模块
|
|
3
|
+
* 版本: v4.0.0
|
|
4
|
+
*
|
|
5
|
+
* 本地 Token 计数,支持主流模型。
|
|
6
|
+
* 用于 prompt 工程优化和消耗监控。
|
|
7
|
+
*/
|
|
8
|
+
import { getLogger } from "./logger.js";
|
|
9
|
+
// Claude token count approximation (claude tokenizer)
|
|
10
|
+
const CLAUDE_TOKEN_RATIO = 0.75; // ~4 chars per token for Chinese/English mix
|
|
11
|
+
// GPT tokenization approximation
|
|
12
|
+
const GPT_TOKEN_RATIO = 0.25; // ~4 chars per token for English
|
|
13
|
+
export class TokenCounter {
|
|
14
|
+
logger = getLogger().child("[TokenCounter]");
|
|
15
|
+
/**
|
|
16
|
+
* 计算文本的 token 数量
|
|
17
|
+
* 使用估算公式,实际使用需考虑模型分词器
|
|
18
|
+
*/
|
|
19
|
+
count(text, options = { model: "claude-sonnet-4-6" }) {
|
|
20
|
+
if (!text)
|
|
21
|
+
return 0;
|
|
22
|
+
const model = options.model.toLowerCase();
|
|
23
|
+
if (model.includes("claude")) {
|
|
24
|
+
return this.countClaude(text);
|
|
25
|
+
}
|
|
26
|
+
else if (model.includes("gpt") || model.includes("4o") || model.includes("o1")) {
|
|
27
|
+
return this.countGPT(text);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
// 默认使用 Claude 估算
|
|
31
|
+
return this.countClaude(text);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Claude 系列模型 token 估算
|
|
36
|
+
* 公式:中文 ~2 chars/token,英文 ~4 chars/token
|
|
37
|
+
*/
|
|
38
|
+
countClaude(text) {
|
|
39
|
+
let charCount = 0;
|
|
40
|
+
for (const char of text) {
|
|
41
|
+
// 中文字符和特殊字符占 2-3 tokens
|
|
42
|
+
if (/[\u4e00-\u9fff]/.test(char)) {
|
|
43
|
+
charCount += 2; // 中文
|
|
44
|
+
}
|
|
45
|
+
else if (/[^\x00-\x7F]/.test(char)) {
|
|
46
|
+
charCount += 2; // 其他非ASCII
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
charCount += 1; // ASCII
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return Math.ceil(charCount / CLAUDE_TOKEN_RATIO);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* GPT 系列模型 token 估算
|
|
56
|
+
* 公式:约 4 chars per token(英文为主)
|
|
57
|
+
*/
|
|
58
|
+
countGPT(text) {
|
|
59
|
+
let charCount = 0;
|
|
60
|
+
for (const char of text) {
|
|
61
|
+
if (/[\u4e00-\u9fff]/.test(char)) {
|
|
62
|
+
charCount += 2.5; // 中文
|
|
63
|
+
}
|
|
64
|
+
else if (/[^\x00-\x7F]/.test(char)) {
|
|
65
|
+
charCount += 2;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
charCount += 1;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return Math.ceil(charCount / GPT_TOKEN_RATIO);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* 计算消息数组的总 token 数
|
|
75
|
+
*/
|
|
76
|
+
countMessages(messages, options) {
|
|
77
|
+
let total = 0;
|
|
78
|
+
// 添加消息格式 overhead
|
|
79
|
+
const formatOverhead = options.model.includes("claude") ? 10 : 5;
|
|
80
|
+
for (const msg of messages) {
|
|
81
|
+
total += this.count(msg.content, options);
|
|
82
|
+
total += formatOverhead; // role + content wrapper tokens
|
|
83
|
+
}
|
|
84
|
+
// 添加 messages overhead
|
|
85
|
+
total += formatOverhead * 2; // messages 数组 wrapper
|
|
86
|
+
return total;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* 计算 prompt 模板的 token 数(带变量替换)
|
|
90
|
+
*/
|
|
91
|
+
countPromptTemplate(template, variables, options) {
|
|
92
|
+
let resolved = template;
|
|
93
|
+
for (const [key, value] of Object.entries(variables)) {
|
|
94
|
+
resolved = resolved.replace(new RegExp(`\\{${key}\\}`, "g"), value);
|
|
95
|
+
}
|
|
96
|
+
return this.count(resolved, options);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* 估算剩余 context window
|
|
100
|
+
*/
|
|
101
|
+
getRemainingContext(text, maxTokens, options) {
|
|
102
|
+
const used = this.count(text, options);
|
|
103
|
+
const remaining = Math.max(0, maxTokens - used);
|
|
104
|
+
const percentage = Math.round((remaining / maxTokens) * 100);
|
|
105
|
+
if (remaining < maxTokens * 0.1) {
|
|
106
|
+
this.logger.warn(`Context usage at ${100 - percentage}%, only ${remaining} tokens remaining`);
|
|
107
|
+
}
|
|
108
|
+
return { remaining, percentage };
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* 估算能否在 context 内完成
|
|
112
|
+
*/
|
|
113
|
+
canFit(text, maxTokens, options) {
|
|
114
|
+
return this.count(text, options) <= maxTokens;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
// 全局单例
|
|
118
|
+
let globalCounter = null;
|
|
119
|
+
export function getTokenCounter() {
|
|
120
|
+
if (!globalCounter) {
|
|
121
|
+
globalCounter = new TokenCounter();
|
|
122
|
+
}
|
|
123
|
+
return globalCounter;
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=token-counter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-counter.js","sourceRoot":"","sources":["../src/token-counter.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAYxC,sDAAsD;AACtD,MAAM,kBAAkB,GAAG,IAAI,CAAC,CAAC,6CAA6C;AAE9E,iCAAiC;AACjC,MAAM,eAAe,GAAG,IAAI,CAAC,CAAC,iCAAiC;AAE/D,MAAM,OAAO,YAAY;IACf,MAAM,GAAG,SAAS,EAAE,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;IAErD;;;OAGG;IACH,KAAK,CAAC,IAAY,EAAE,UAA6B,EAAE,KAAK,EAAE,mBAAmB,EAAE;QAC7E,IAAI,CAAC,IAAI;YAAE,OAAO,CAAC,CAAC;QAEpB,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;QAE1C,IAAI,KAAK,CAA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1B,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACvC,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,GAAG,IAAI,CAAC,CAAC;QAChD,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,SAAS,GAAG,SAAS,CAAC,GAAG,GAAG,CAAC,CAAC;QAE7D,IAAI,SAAS,GAAG,SAAS,GAAG,GAAG,EAAE,CAAC;YAChC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,oBAAoB,GAAG,GAAG,UAAU,WAAW,SAAS,mBAAmB,CAAC,CAAC;QAChG,CAAC;QAED,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;IACnC,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,IAAY,EAAE,SAAiB,EAAE,OAA0B;QAChE,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,SAAS,CAAC;IAChD,CAAC;CACF;AAED,OAAO;AACP,IAAI,aAAa,GAAwB,IAAI,CAAC;AAE9C,MAAM,UAAU,eAAe;IAC7B,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,aAAa,GAAG,IAAI,YAAY,EAAE,CAAC;IACrC,CAAC;IACD,OAAO,aAAa,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Handlers 模块
|
|
3
|
+
* 版本: v4.0.0
|
|
4
|
+
*
|
|
5
|
+
* 实现 mycohive_* 工具的实际处理逻辑
|
|
6
|
+
* 特性:请求超时、并发控制、结果缓存
|
|
7
|
+
*/
|
|
8
|
+
import { Router } from "./router.js";
|
|
9
|
+
export interface ToolHandlerContext {
|
|
10
|
+
tool: string;
|
|
11
|
+
args: Record<string, unknown>;
|
|
12
|
+
sessionKey: string;
|
|
13
|
+
}
|
|
14
|
+
export interface ToolHandlerConfig {
|
|
15
|
+
timeoutMs?: number;
|
|
16
|
+
maxConcurrency?: number;
|
|
17
|
+
}
|
|
18
|
+
export declare class ToolHandlers {
|
|
19
|
+
private router;
|
|
20
|
+
private intentAnalyzer;
|
|
21
|
+
private contextTree;
|
|
22
|
+
private eventBus;
|
|
23
|
+
private intentCache;
|
|
24
|
+
private concurrencySemaphore;
|
|
25
|
+
private config;
|
|
26
|
+
constructor(config?: ToolHandlerConfig);
|
|
27
|
+
setRouter(router: Router): void;
|
|
28
|
+
/**
|
|
29
|
+
* 带超时的处理
|
|
30
|
+
*/
|
|
31
|
+
handleWithTimeout(tool: string, args: Record<string, unknown>, sessionKey?: string): Promise<{
|
|
32
|
+
handled: boolean;
|
|
33
|
+
result?: unknown;
|
|
34
|
+
error?: string;
|
|
35
|
+
cached?: boolean;
|
|
36
|
+
timedOut?: boolean;
|
|
37
|
+
}>;
|
|
38
|
+
/**
|
|
39
|
+
* 处理 mycohive_* 工具调用
|
|
40
|
+
* 返回 { handled: true, result: ... } 如果已处理
|
|
41
|
+
* 返回 { handled: false } 如果未处理
|
|
42
|
+
*/
|
|
43
|
+
handle(tool: string, args: Record<string, unknown>, sessionKey?: string): Promise<{
|
|
44
|
+
handled: boolean;
|
|
45
|
+
result?: unknown;
|
|
46
|
+
error?: string;
|
|
47
|
+
cached?: boolean;
|
|
48
|
+
}>;
|
|
49
|
+
private generateRecommendations;
|
|
50
|
+
}
|
|
51
|
+
export declare function getToolHandlers(config?: ToolHandlerConfig): ToolHandlers;
|
|
52
|
+
//# sourceMappingURL=tool-handlers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-handlers.d.ts","sourceRoot":"","sources":["../src/tool-handlers.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,MAAM,EAAiB,MAAM,aAAa,CAAC;AAMpD,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC,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YAAY,CAKxE"}
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Handlers 模块
|
|
3
|
+
* 版本: v4.0.0
|
|
4
|
+
*
|
|
5
|
+
* 实现 mycohive_* 工具的实际处理逻辑
|
|
6
|
+
* 特性:请求超时、并发控制、结果缓存
|
|
7
|
+
*/
|
|
8
|
+
import { getContextTree } from "./context-tree.js";
|
|
9
|
+
import { getEventBus } from "./event-bus.js";
|
|
10
|
+
import { IntentAnalyzer } from "./intent-analyzer.js";
|
|
11
|
+
import { ResultCache } from "./result-cache.js";
|
|
12
|
+
export class ToolHandlers {
|
|
13
|
+
router = null;
|
|
14
|
+
intentAnalyzer;
|
|
15
|
+
contextTree;
|
|
16
|
+
eventBus;
|
|
17
|
+
intentCache;
|
|
18
|
+
// 并发控制
|
|
19
|
+
concurrencySemaphore;
|
|
20
|
+
config;
|
|
21
|
+
constructor(config) {
|
|
22
|
+
this.intentAnalyzer = new IntentAnalyzer();
|
|
23
|
+
this.contextTree = getContextTree();
|
|
24
|
+
this.eventBus = getEventBus();
|
|
25
|
+
this.intentCache = new ResultCache({
|
|
26
|
+
maxSize: 500,
|
|
27
|
+
maxAgeMs: 5 * 60 * 1000, // 5 分钟缓存
|
|
28
|
+
});
|
|
29
|
+
this.config = {
|
|
30
|
+
timeoutMs: config?.timeoutMs || 30000, // 默认 30 秒超时
|
|
31
|
+
maxConcurrency: config?.maxConcurrency || 10, // 默认最多 10 并发
|
|
32
|
+
};
|
|
33
|
+
this.concurrencySemaphore = new Semaphore(this.config.maxConcurrency);
|
|
34
|
+
}
|
|
35
|
+
setRouter(router) {
|
|
36
|
+
this.router = router;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* 带超时的处理
|
|
40
|
+
*/
|
|
41
|
+
async handleWithTimeout(tool, args, sessionKey) {
|
|
42
|
+
// 获取并发令牌
|
|
43
|
+
const release = await this.concurrencySemaphore.acquire();
|
|
44
|
+
try {
|
|
45
|
+
// 使用 Promise.race 实现超时
|
|
46
|
+
const result = await Promise.race([
|
|
47
|
+
this.handle(tool, args, sessionKey),
|
|
48
|
+
new Promise((_, reject) => setTimeout(() => reject({ handled: true, error: `Tool handler timeout after ${this.config.timeoutMs}ms`, timedOut: true }), this.config.timeoutMs)),
|
|
49
|
+
]);
|
|
50
|
+
if (result.timedOut) {
|
|
51
|
+
return { handled: true, error: result.error, timedOut: true };
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
if (error.timedOut) {
|
|
57
|
+
return { handled: true, error: error.error, timedOut: true };
|
|
58
|
+
}
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
release();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* 处理 mycohive_* 工具调用
|
|
67
|
+
* 返回 { handled: true, result: ... } 如果已处理
|
|
68
|
+
* 返回 { handled: false } 如果未处理
|
|
69
|
+
*/
|
|
70
|
+
async handle(tool, args, sessionKey) {
|
|
71
|
+
switch (tool) {
|
|
72
|
+
// === Context Tree Tools ===
|
|
73
|
+
case "mycohive_topic_create": {
|
|
74
|
+
const { topicId, label } = args;
|
|
75
|
+
if (!topicId || !label) {
|
|
76
|
+
return { handled: false, error: "topicId and label required" };
|
|
77
|
+
}
|
|
78
|
+
const topic = this.contextTree.addTopic(topicId, label);
|
|
79
|
+
this.eventBus.publish({
|
|
80
|
+
id: "",
|
|
81
|
+
type: "topic.created",
|
|
82
|
+
source: "tool-handler",
|
|
83
|
+
data: { topicId, label },
|
|
84
|
+
timestamp: Date.now(),
|
|
85
|
+
});
|
|
86
|
+
return { handled: true, result: topic };
|
|
87
|
+
}
|
|
88
|
+
case "mycohive_topic_list": {
|
|
89
|
+
const topics = this.contextTree.getActiveTopics();
|
|
90
|
+
return {
|
|
91
|
+
handled: true,
|
|
92
|
+
result: topics.map((t) => ({
|
|
93
|
+
id: t.id,
|
|
94
|
+
label: t.label,
|
|
95
|
+
state: t.state,
|
|
96
|
+
})),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
case "mycohive_task_create": {
|
|
100
|
+
const { topicId, taskId, agent, taskDesc } = args;
|
|
101
|
+
if (!topicId || !taskId || !agent || !taskDesc) {
|
|
102
|
+
return { handled: false, error: "topicId, taskId, agent, taskDesc required" };
|
|
103
|
+
}
|
|
104
|
+
const task = this.contextTree.addTask(topicId, taskId, agent, taskDesc);
|
|
105
|
+
this.eventBus.emitTaskCreated(taskId, agent);
|
|
106
|
+
return { handled: true, result: task };
|
|
107
|
+
}
|
|
108
|
+
case "mycohive_task_update": {
|
|
109
|
+
const { taskId, state, taskStatus } = args;
|
|
110
|
+
if (!taskId) {
|
|
111
|
+
return { handled: false, error: "taskId required" };
|
|
112
|
+
}
|
|
113
|
+
if (state) {
|
|
114
|
+
this.contextTree.updateTaskState(taskId, state, {
|
|
115
|
+
task_status: taskStatus,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
return { handled: true, result: { success: true } };
|
|
119
|
+
}
|
|
120
|
+
case "mycohive_context_tree_stats": {
|
|
121
|
+
const stats = this.contextTree.getStats();
|
|
122
|
+
return { handled: true, result: stats };
|
|
123
|
+
}
|
|
124
|
+
// === Event Bus Tools ===
|
|
125
|
+
case "mycohive_event_publish": {
|
|
126
|
+
const { type, source, data } = args;
|
|
127
|
+
if (!type || !source) {
|
|
128
|
+
return { handled: false, error: "type and source required" };
|
|
129
|
+
}
|
|
130
|
+
this.eventBus.publish({
|
|
131
|
+
id: "",
|
|
132
|
+
type,
|
|
133
|
+
source,
|
|
134
|
+
data: data || {},
|
|
135
|
+
timestamp: Date.now(),
|
|
136
|
+
});
|
|
137
|
+
return { handled: true, result: { success: true } };
|
|
138
|
+
}
|
|
139
|
+
case "mycohive_event_history": {
|
|
140
|
+
const { eventType, limit } = args;
|
|
141
|
+
const history = this.eventBus.getHistory(eventType, limit || 100);
|
|
142
|
+
return { handled: true, result: history };
|
|
143
|
+
}
|
|
144
|
+
// === Router Tools ===
|
|
145
|
+
case "mycohive_route": {
|
|
146
|
+
const { message, sessionKey: sk } = args;
|
|
147
|
+
if (!message) {
|
|
148
|
+
return { handled: false, error: "message required" };
|
|
149
|
+
}
|
|
150
|
+
const skToUse = sk || sessionKey || "default";
|
|
151
|
+
if (!this.router) {
|
|
152
|
+
return { handled: false, error: "Router not initialized" };
|
|
153
|
+
}
|
|
154
|
+
try {
|
|
155
|
+
const result = await this.router.route(message, skToUse);
|
|
156
|
+
return { handled: true, result };
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
return { handled: false, error: String(error) };
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
case "mycohive_intent_analyze": {
|
|
163
|
+
const { message } = args;
|
|
164
|
+
if (!message) {
|
|
165
|
+
return { handled: false, error: "message required" };
|
|
166
|
+
}
|
|
167
|
+
// 生成缓存 key(基于消息内容 hash)
|
|
168
|
+
const cacheKey = ResultCache.generateKey(message);
|
|
169
|
+
// 尝试从缓存获取
|
|
170
|
+
const cached = this.intentCache.get(cacheKey);
|
|
171
|
+
if (cached) {
|
|
172
|
+
return { handled: true, result: cached, cached: true };
|
|
173
|
+
}
|
|
174
|
+
try {
|
|
175
|
+
const intent = await this.intentAnalyzer.analyze(message);
|
|
176
|
+
// 缓存结果
|
|
177
|
+
this.intentCache.set(cacheKey, intent);
|
|
178
|
+
return { handled: true, result: intent };
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
return { handled: true, result: { error: String(error) } };
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
// === System Tools ===
|
|
185
|
+
case "mycohive_health": {
|
|
186
|
+
const stats = this.contextTree.getStats();
|
|
187
|
+
const eventHistoryCount = this.eventBus.getHistory().length;
|
|
188
|
+
const circuitBreakerStats = this.router ? this.router.getCircuitBreakerStats() : null;
|
|
189
|
+
return {
|
|
190
|
+
handled: true,
|
|
191
|
+
result: {
|
|
192
|
+
status: "healthy",
|
|
193
|
+
contextTree: stats,
|
|
194
|
+
eventBus: { historySize: eventHistoryCount },
|
|
195
|
+
router: this.router ? "initialized" : "not initialized",
|
|
196
|
+
circuitBreaker: circuitBreakerStats,
|
|
197
|
+
timestamp: Date.now(),
|
|
198
|
+
},
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
case "mycohive_diagnose": {
|
|
202
|
+
const stats = this.contextTree.getStats();
|
|
203
|
+
const topics = this.contextTree.getActiveTopics();
|
|
204
|
+
const staleTasks = this.contextTree.findTasksByState("stale");
|
|
205
|
+
return {
|
|
206
|
+
handled: true,
|
|
207
|
+
result: {
|
|
208
|
+
issues: [
|
|
209
|
+
...(staleTasks.length > 0
|
|
210
|
+
? [{ type: "stale_tasks", count: staleTasks.length, taskIds: staleTasks.map((t) => t.id) }]
|
|
211
|
+
: []),
|
|
212
|
+
...(stats.topics === 0 && stats.tasks === 0
|
|
213
|
+
? [{ type: "no_activity", message: "No recent activity" }]
|
|
214
|
+
: []),
|
|
215
|
+
],
|
|
216
|
+
stats,
|
|
217
|
+
recommendations: this.generateRecommendations(stats),
|
|
218
|
+
timestamp: Date.now(),
|
|
219
|
+
},
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
case "mycohive_health_check": {
|
|
223
|
+
// 写入健康状态到文件,供外部监控轮询
|
|
224
|
+
const stats = this.contextTree.getStats();
|
|
225
|
+
const healthStatus = {
|
|
226
|
+
status: "healthy",
|
|
227
|
+
version: "4.0.0",
|
|
228
|
+
uptime: process.uptime(),
|
|
229
|
+
pid: process.pid,
|
|
230
|
+
memory: process.memoryUsage(),
|
|
231
|
+
contextTree: stats,
|
|
232
|
+
eventBus: { historySize: this.eventBus.getHistory().length },
|
|
233
|
+
router: this.router ? "initialized" : "not initialized",
|
|
234
|
+
concurrency: this.concurrencySemaphore.getStats(),
|
|
235
|
+
timestamp: Date.now(),
|
|
236
|
+
};
|
|
237
|
+
// 尝试写入健康状态文件
|
|
238
|
+
try {
|
|
239
|
+
const healthFilePath = "data/health.json";
|
|
240
|
+
const fs = await import("fs");
|
|
241
|
+
const dir = "data";
|
|
242
|
+
if (!fs.existsSync(dir)) {
|
|
243
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
244
|
+
}
|
|
245
|
+
fs.writeFileSync(healthFilePath, JSON.stringify(healthStatus, null, 2), "utf-8");
|
|
246
|
+
}
|
|
247
|
+
catch {
|
|
248
|
+
// 忽略文件写入错误
|
|
249
|
+
}
|
|
250
|
+
return {
|
|
251
|
+
handled: true,
|
|
252
|
+
result: healthStatus,
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
default:
|
|
256
|
+
return { handled: false };
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
generateRecommendations(stats) {
|
|
260
|
+
const recs = [];
|
|
261
|
+
if (stats.activeTasks > 10) {
|
|
262
|
+
recs.push("High number of active tasks, consider consolidating");
|
|
263
|
+
}
|
|
264
|
+
if (stats.topics > 50) {
|
|
265
|
+
recs.push("Many topics, consider archiving old ones");
|
|
266
|
+
}
|
|
267
|
+
if (stats.activeTopics === 0) {
|
|
268
|
+
recs.push("No active topics, system may be idle");
|
|
269
|
+
}
|
|
270
|
+
return recs;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* 信号量 - 用于并发控制
|
|
275
|
+
*/
|
|
276
|
+
class Semaphore {
|
|
277
|
+
permits;
|
|
278
|
+
queue = [];
|
|
279
|
+
constructor(permits) {
|
|
280
|
+
this.permits = permits;
|
|
281
|
+
}
|
|
282
|
+
async acquire() {
|
|
283
|
+
if (this.permits > 0) {
|
|
284
|
+
this.permits--;
|
|
285
|
+
return () => this.release();
|
|
286
|
+
}
|
|
287
|
+
// 需要等待
|
|
288
|
+
return new Promise((resolve) => {
|
|
289
|
+
this.queue.push(() => resolve(() => this.release()));
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
release() {
|
|
293
|
+
const next = this.queue.shift();
|
|
294
|
+
if (next) {
|
|
295
|
+
// 让等待者自己调用 release
|
|
296
|
+
next();
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
this.permits++;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
getStats() {
|
|
303
|
+
return {
|
|
304
|
+
permits: this.permits,
|
|
305
|
+
waiting: this.queue.length,
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
// 全局实例
|
|
310
|
+
let globalHandlers = null;
|
|
311
|
+
export function getToolHandlers(config) {
|
|
312
|
+
if (!globalHandlers) {
|
|
313
|
+
globalHandlers = new ToolHandlers(config);
|
|
314
|
+
}
|
|
315
|
+
return globalHandlers;
|
|
316
|
+
}
|
|
317
|
+
//# sourceMappingURL=tool-handlers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-handlers.js","sourceRoot":"","sources":["../src/tool-handlers.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,cAAc,EAAe,MAAM,mBAAmB,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAahD,MAAM,OAAO,YAAY;IACf,MAAM,GAAkB,IAAI,CAAC;IAC7B,cAAc,CAAiB;IAC/B,WAAW,CAAC;IACZ,QAAQ,CAAC;IACT,WAAW,CAAuB;IAC1C,OAAO;IACC,oBAAoB,CAAY;IAChC,MAAM,CAA8B;IAE5C,YAAY,MAA0B;QACpC,IAAI,CAAC,cAAc,GAAG,IAAI,cAAc,EAAE,CAAC;QAC3C,IAAI,CAAC,WAAW,GAAG,cAAc,EAAE,CAAC;QACpC,IAAI,CAAC,QAAQ,GAAG,WAAW,EAAE,CAAC;QAC9B,IAAI,CAAC,WAAW,GAAG,IAAI,W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I,CAAC,cAAc,EAAE,CAAC;QACpB,cAAc,GAAG,IAAI,YAAY,CAAC,MAAM,CAAC,CAAC;IAC5C,CAAC;IACD,OAAO,cAAc,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MycoHive Tools 注册
|
|
3
|
+
* 版本: v4.0.0
|
|
4
|
+
*
|
|
5
|
+
* 注册自定义工具供 Agent 使用
|
|
6
|
+
*/
|
|
7
|
+
import type { OpenClawAPI } from "../openclaw-api.js";
|
|
8
|
+
import type { Router } from "../router.js";
|
|
9
|
+
export declare function registerTools(api: OpenClawAPI, router: Router): void;
|
|
10
|
+
export declare function registerToolHandlers(api: OpenClawAPI, router: Router): void;
|
|
11
|
+
//# sourceMappingURL=mycohive-tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mycohive-tools.d.ts","sourceRoot":"","sources":["../../src/tools/mycohive-tools.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGtD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE3C,wBAAgB,aAAa,CAAC,GAAG,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAiKpE;AAED,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAM3E"}
|