@capyclaw/tool-host 0.1.0 → 0.1.1

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.
Files changed (24) hide show
  1. package/dsh-suite.json +6 -4
  2. package/package.json +15 -2
  3. package/src/index.mjs +341 -341
  4. package/src/optimizers/E2E/346/265/213/350/257/225/346/212/245/345/221/212.md +0 -396
  5. package/src/optimizers/PPT/345/234/272/346/231/257/344/274/230/345/214/226/346/226/271/346/241/210.md +0 -607
  6. package/src/optimizers/PPT/345/256/236/346/227/266/346/270/262/346/237/223/346/226/271/346/241/210.md +0 -456
  7. package/src/optimizers/PPT/346/265/201/345/274/217/346/270/262/346/237/223-/347/224/237/344/272/247/347/272/247/344/274/230/345/214/226.md +0 -874
  8. package/src/optimizers/README.md +0 -374
  9. package/src/optimizers/batch-optimizer.mjs +0 -94
  10. package/src/optimizers/cache-optimizer.mjs +0 -217
  11. package/src/optimizers/concurrency-optimizer.mjs +0 -129
  12. package/src/optimizers/e2e-test.mjs +0 -674
  13. package/src/optimizers/examples.mjs +0 -243
  14. package/src/optimizers/index.mjs +0 -188
  15. package/src/optimizers/ppt-optimizer.mjs +0 -263
  16. package/src/optimizers/ppt-streaming-demo.mjs +0 -192
  17. package/src/optimizers/ppt-streaming-renderer.mjs +0 -332
  18. package/src/optimizers/production-streaming-demo.mjs +0 -267
  19. package/src/optimizers/production-streaming-renderer.mjs +0 -611
  20. package/src/optimizers/real-ppt-test.mjs +0 -397
  21. package/src/optimizers/real-world-benchmark.mjs +0 -470
  22. package/src/optimizers/retry-optimizer.mjs +0 -118
  23. package/src/optimizers//347/224/237/344/272/247/347/272/247/344/274/230/345/214/226/346/200/273/347/273/223.md +0 -110
  24. package/src/optimizers//347/234/237/345/256/236/346/200/247/350/203/275/346/217/220/345/215/207/351/252/214/350/257/201/346/212/245/345/221/212.md +0 -331
@@ -1,129 +0,0 @@
1
- /**
2
- * MCP 2.0 并发控制优化器
3
- *
4
- * 防止过载,支持动态调整
5
- * 提升 30-50% 的稳定性
6
- */
7
-
8
- export class ConcurrencyLimiter {
9
- constructor(maxConcurrent = 5) {
10
- this.maxConcurrent = maxConcurrent;
11
- this.running = 0;
12
- this.queue = [];
13
- }
14
-
15
- /**
16
- * 执行任务,自动排队和限流
17
- */
18
- async run(fn) {
19
- // 等待空位
20
- while (this.running >= this.maxConcurrent) {
21
- await new Promise(resolve => this.queue.push(resolve));
22
- }
23
-
24
- this.running++;
25
-
26
- try {
27
- return await fn();
28
- } finally {
29
- this.running--;
30
-
31
- // 唤醒下一个等待的任务
32
- const next = this.queue.shift();
33
- if (next) next();
34
- }
35
- }
36
-
37
- /**
38
- * 并行执行(Promise.all 的限流版本)
39
- */
40
- async parallel(tasks) {
41
- return Promise.all(
42
- tasks.map(task => this.run(task))
43
- );
44
- }
45
-
46
- /**
47
- * 获取当前状态
48
- */
49
- getStatus() {
50
- return {
51
- running: this.running,
52
- queued: this.queue.length,
53
- maxConcurrent: this.maxConcurrent
54
- };
55
- }
56
- }
57
-
58
- /**
59
- * 智能并发管理器
60
- * 根据系统负载自动调整并发数
61
- */
62
- export class AdaptiveConcurrencyManager {
63
- constructor(options = {}) {
64
- this.minConcurrent = options.min || 1;
65
- this.maxConcurrent = options.max || 20;
66
- this.currentConcurrent = options.initial || 5;
67
-
68
- this.successCount = 0;
69
- this.errorCount = 0;
70
- this.adjustInterval = options.adjustInterval || 10;
71
-
72
- this.limiter = new ConcurrencyLimiter(this.currentConcurrent);
73
- }
74
-
75
- /**
76
- * 执行任务,动态调整并发
77
- */
78
- async execute(fn) {
79
- try {
80
- const result = await this.limiter.run(fn);
81
- this.successCount++;
82
- this.adjustConcurrency();
83
- return result;
84
- } catch (error) {
85
- this.errorCount++;
86
- this.adjustConcurrency();
87
- throw error;
88
- }
89
- }
90
-
91
- adjustConcurrency() {
92
- const total = this.successCount + this.errorCount;
93
- if (total % this.adjustInterval !== 0) return;
94
-
95
- const errorRate = this.errorCount / total;
96
- const oldConcurrent = this.currentConcurrent;
97
-
98
- // 错误率高,降低并发
99
- if (errorRate > 0.1) {
100
- this.currentConcurrent = Math.max(
101
- this.minConcurrent,
102
- Math.floor(this.currentConcurrent * 0.8)
103
- );
104
- }
105
- // 错误率低,提升并发
106
- else if (errorRate < 0.01) {
107
- this.currentConcurrent = Math.min(
108
- this.maxConcurrent,
109
- Math.ceil(this.currentConcurrent * 1.2)
110
- );
111
- }
112
-
113
- // 更新 limiter
114
- if (this.currentConcurrent !== oldConcurrent) {
115
- this.limiter.maxConcurrent = this.currentConcurrent;
116
- console.log(`[AdaptiveConcurrency] Adjusted from ${oldConcurrent} to ${this.currentConcurrent} (error rate: ${(errorRate * 100).toFixed(1)}%)`);
117
- }
118
- }
119
-
120
- getStats() {
121
- return {
122
- currentConcurrent: this.currentConcurrent,
123
- successCount: this.successCount,
124
- errorCount: this.errorCount,
125
- errorRate: this.errorCount / (this.successCount + this.errorCount),
126
- ...this.limiter.getStatus()
127
- };
128
- }
129
- }