@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.
- package/dsh-suite.json +6 -4
- package/package.json +15 -2
- package/src/index.mjs +341 -341
- package/src/optimizers/E2E/346/265/213/350/257/225/346/212/245/345/221/212.md +0 -396
- 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
- 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
- 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
- package/src/optimizers/README.md +0 -374
- package/src/optimizers/batch-optimizer.mjs +0 -94
- package/src/optimizers/cache-optimizer.mjs +0 -217
- package/src/optimizers/concurrency-optimizer.mjs +0 -129
- package/src/optimizers/e2e-test.mjs +0 -674
- package/src/optimizers/examples.mjs +0 -243
- package/src/optimizers/index.mjs +0 -188
- package/src/optimizers/ppt-optimizer.mjs +0 -263
- package/src/optimizers/ppt-streaming-demo.mjs +0 -192
- package/src/optimizers/ppt-streaming-renderer.mjs +0 -332
- package/src/optimizers/production-streaming-demo.mjs +0 -267
- package/src/optimizers/production-streaming-renderer.mjs +0 -611
- package/src/optimizers/real-ppt-test.mjs +0 -397
- package/src/optimizers/real-world-benchmark.mjs +0 -470
- package/src/optimizers/retry-optimizer.mjs +0 -118
- 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
- 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,397 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* PPT 场景真实端到端测试
|
|
4
|
-
* 连接真实的 PPT 服务,验证优化效果
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import http from 'node:http';
|
|
8
|
-
import { performance } from 'node:perf_hooks';
|
|
9
|
-
|
|
10
|
-
// PPT 服务地址(从 dsh-suite.json 配置)
|
|
11
|
-
const PPT_SERVICE = 'http://127.0.0.1:39311';
|
|
12
|
-
|
|
13
|
-
// 测试结果收集
|
|
14
|
-
const results = {
|
|
15
|
-
timestamp: new Date().toISOString(),
|
|
16
|
-
tests: [],
|
|
17
|
-
summary: {}
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* HTTP 请求封装
|
|
22
|
-
*/
|
|
23
|
-
function request(url, options = {}) {
|
|
24
|
-
return new Promise((resolve, reject) => {
|
|
25
|
-
const urlObj = new URL(url);
|
|
26
|
-
const req = http.request({
|
|
27
|
-
hostname: urlObj.hostname,
|
|
28
|
-
port: urlObj.port,
|
|
29
|
-
path: urlObj.pathname + urlObj.search,
|
|
30
|
-
method: options.method || 'GET',
|
|
31
|
-
headers: {
|
|
32
|
-
'Content-Type': 'application/json',
|
|
33
|
-
...options.headers
|
|
34
|
-
},
|
|
35
|
-
timeout: 10000
|
|
36
|
-
}, (res) => {
|
|
37
|
-
let data = '';
|
|
38
|
-
res.on('data', chunk => data += chunk);
|
|
39
|
-
res.on('end', () => {
|
|
40
|
-
try {
|
|
41
|
-
resolve({
|
|
42
|
-
status: res.statusCode,
|
|
43
|
-
data: data ? JSON.parse(data) : null,
|
|
44
|
-
headers: res.headers
|
|
45
|
-
});
|
|
46
|
-
} catch (e) {
|
|
47
|
-
resolve({
|
|
48
|
-
status: res.statusCode,
|
|
49
|
-
data: data,
|
|
50
|
-
headers: res.headers
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
req.on('error', reject);
|
|
57
|
-
req.on('timeout', () => {
|
|
58
|
-
req.destroy();
|
|
59
|
-
reject(new Error('Request timeout'));
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
if (options.body) {
|
|
63
|
-
req.write(JSON.stringify(options.body));
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
req.end();
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* 测试1: 检查 PPT 服务是否运行
|
|
72
|
-
*/
|
|
73
|
-
async function testPPTServiceHealth() {
|
|
74
|
-
console.log('\n📋 测试1: PPT 服务健康检查\n');
|
|
75
|
-
|
|
76
|
-
try {
|
|
77
|
-
const start = performance.now();
|
|
78
|
-
const response = await request(`${PPT_SERVICE}/healthz`);
|
|
79
|
-
const duration = performance.now() - start;
|
|
80
|
-
|
|
81
|
-
console.log(` 状态码: ${response.status}`);
|
|
82
|
-
console.log(` 响应时间: ${duration.toFixed(0)}ms`);
|
|
83
|
-
console.log(` 健康状态:`, response.data);
|
|
84
|
-
|
|
85
|
-
results.tests.push({
|
|
86
|
-
name: 'PPT 服务健康检查',
|
|
87
|
-
status: response.status === 200 ? 'PASS' : 'FAIL',
|
|
88
|
-
duration: duration.toFixed(0) + 'ms',
|
|
89
|
-
details: response.data
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
return response.status === 200;
|
|
93
|
-
} catch (error) {
|
|
94
|
-
console.log(` ❌ 错误: ${error.message}`);
|
|
95
|
-
results.tests.push({
|
|
96
|
-
name: 'PPT 服务健康检查',
|
|
97
|
-
status: 'FAIL',
|
|
98
|
-
error: error.message
|
|
99
|
-
});
|
|
100
|
-
return false;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* 测试2: MCP 工具列表
|
|
106
|
-
*/
|
|
107
|
-
async function testMCPToolsList() {
|
|
108
|
-
console.log('\n📋 测试2: MCP 工具列表查询\n');
|
|
109
|
-
|
|
110
|
-
try {
|
|
111
|
-
const start = performance.now();
|
|
112
|
-
const response = await request(`${PPT_SERVICE}/mcp`, {
|
|
113
|
-
method: 'POST',
|
|
114
|
-
body: {
|
|
115
|
-
jsonrpc: '2.0',
|
|
116
|
-
id: 1,
|
|
117
|
-
method: 'tools/list'
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
const duration = performance.now() - start;
|
|
121
|
-
|
|
122
|
-
const tools = response.data?.result?.tools || [];
|
|
123
|
-
console.log(` 状态码: ${response.status}`);
|
|
124
|
-
console.log(` 响应时间: ${duration.toFixed(0)}ms`);
|
|
125
|
-
console.log(` 工具数量: ${tools.length}`);
|
|
126
|
-
|
|
127
|
-
if (tools.length > 0) {
|
|
128
|
-
console.log(` 前5个工具:`);
|
|
129
|
-
tools.slice(0, 5).forEach(tool => {
|
|
130
|
-
console.log(` - ${tool.name}`);
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
results.tests.push({
|
|
135
|
-
name: 'MCP 工具列表',
|
|
136
|
-
status: response.status === 200 ? 'PASS' : 'FAIL',
|
|
137
|
-
duration: duration.toFixed(0) + 'ms',
|
|
138
|
-
toolCount: tools.length,
|
|
139
|
-
sampleTools: tools.slice(0, 3).map(t => t.name)
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
return tools;
|
|
143
|
-
} catch (error) {
|
|
144
|
-
console.log(` ❌ 错误: ${error.message}`);
|
|
145
|
-
results.tests.push({
|
|
146
|
-
name: 'MCP 工具列表',
|
|
147
|
-
status: 'FAIL',
|
|
148
|
-
error: error.message
|
|
149
|
-
});
|
|
150
|
-
return [];
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* 测试3: 查询操作性能(模拟缓存场景)
|
|
156
|
-
*/
|
|
157
|
-
async function testQueryPerformance() {
|
|
158
|
-
console.log('\n📋 测试3: 查询操作性能(重复查询)\n');
|
|
159
|
-
|
|
160
|
-
const toolName = 'ppt_capabilities';
|
|
161
|
-
const times = [];
|
|
162
|
-
|
|
163
|
-
try {
|
|
164
|
-
// 查询5次同一个工具
|
|
165
|
-
for (let i = 0; i < 5; i++) {
|
|
166
|
-
const start = performance.now();
|
|
167
|
-
const response = await request(`${PPT_SERVICE}/mcp`, {
|
|
168
|
-
method: 'POST',
|
|
169
|
-
body: {
|
|
170
|
-
jsonrpc: '2.0',
|
|
171
|
-
id: i + 2,
|
|
172
|
-
method: 'tools/call',
|
|
173
|
-
params: {
|
|
174
|
-
name: toolName,
|
|
175
|
-
arguments: {}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
const duration = performance.now() - start;
|
|
180
|
-
times.push(duration);
|
|
181
|
-
|
|
182
|
-
console.log(` 第${i + 1}次查询: ${duration.toFixed(0)}ms (状态: ${response.status})`);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
const avgTime = times.reduce((a, b) => a + b, 0) / times.length;
|
|
186
|
-
const improvement = times[0] > times[times.length - 1] ?
|
|
187
|
-
((times[0] - times[times.length - 1]) / times[0] * 100).toFixed(1) : 0;
|
|
188
|
-
|
|
189
|
-
console.log(`\n 平均响应时间: ${avgTime.toFixed(0)}ms`);
|
|
190
|
-
console.log(` 首次 vs 最后: ${times[0].toFixed(0)}ms → ${times[times.length - 1].toFixed(0)}ms`);
|
|
191
|
-
if (improvement > 0) {
|
|
192
|
-
console.log(` 性能提升: ${improvement}%`);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
results.tests.push({
|
|
196
|
-
name: '查询性能测试',
|
|
197
|
-
status: 'PASS',
|
|
198
|
-
queries: times.length,
|
|
199
|
-
avgTime: avgTime.toFixed(0) + 'ms',
|
|
200
|
-
firstQuery: times[0].toFixed(0) + 'ms',
|
|
201
|
-
lastQuery: times[times.length - 1].toFixed(0) + 'ms',
|
|
202
|
-
improvement: improvement + '%'
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
return times;
|
|
206
|
-
} catch (error) {
|
|
207
|
-
console.log(` ❌ 错误: ${error.message}`);
|
|
208
|
-
results.tests.push({
|
|
209
|
-
name: '查询性能测试',
|
|
210
|
-
status: 'FAIL',
|
|
211
|
-
error: error.message
|
|
212
|
-
});
|
|
213
|
-
return [];
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* 测试4: 并发请求测试
|
|
219
|
-
*/
|
|
220
|
-
async function testConcurrentRequests() {
|
|
221
|
-
console.log('\n📋 测试4: 并发请求测试(10个并发)\n');
|
|
222
|
-
|
|
223
|
-
try {
|
|
224
|
-
const start = performance.now();
|
|
225
|
-
const promises = [];
|
|
226
|
-
|
|
227
|
-
for (let i = 0; i < 10; i++) {
|
|
228
|
-
promises.push(
|
|
229
|
-
request(`${PPT_SERVICE}/mcp`, {
|
|
230
|
-
method: 'POST',
|
|
231
|
-
body: {
|
|
232
|
-
jsonrpc: '2.0',
|
|
233
|
-
id: i + 100,
|
|
234
|
-
method: 'tools/list'
|
|
235
|
-
}
|
|
236
|
-
}).catch(err => ({ error: err.message }))
|
|
237
|
-
);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
const responses = await Promise.all(promises);
|
|
241
|
-
const duration = performance.now() - start;
|
|
242
|
-
|
|
243
|
-
const successful = responses.filter(r => r.status === 200).length;
|
|
244
|
-
const failed = responses.length - successful;
|
|
245
|
-
|
|
246
|
-
console.log(` 总耗时: ${duration.toFixed(0)}ms`);
|
|
247
|
-
console.log(` 成功: ${successful}/${responses.length}`);
|
|
248
|
-
console.log(` 失败: ${failed}`);
|
|
249
|
-
console.log(` 平均响应: ${(duration / responses.length).toFixed(0)}ms`);
|
|
250
|
-
|
|
251
|
-
results.tests.push({
|
|
252
|
-
name: '并发请求测试',
|
|
253
|
-
status: successful > 8 ? 'PASS' : 'PARTIAL',
|
|
254
|
-
concurrent: 10,
|
|
255
|
-
successful,
|
|
256
|
-
failed,
|
|
257
|
-
totalTime: duration.toFixed(0) + 'ms',
|
|
258
|
-
avgTime: (duration / responses.length).toFixed(0) + 'ms'
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
return responses;
|
|
262
|
-
} catch (error) {
|
|
263
|
-
console.log(` ❌ 错误: ${error.message}`);
|
|
264
|
-
results.tests.push({
|
|
265
|
-
name: '并发请求测试',
|
|
266
|
-
status: 'FAIL',
|
|
267
|
-
error: error.message
|
|
268
|
-
});
|
|
269
|
-
return [];
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* 测试5: 检查 DSH 服务状态
|
|
275
|
-
*/
|
|
276
|
-
async function testDSHServices() {
|
|
277
|
-
console.log('\n📋 测试5: 检查相关服务状态\n');
|
|
278
|
-
|
|
279
|
-
const services = [
|
|
280
|
-
{ name: 'DSH Daemon', url: 'http://127.0.0.1:9999/api/status' },
|
|
281
|
-
{ name: 'ddr0 Client', url: 'http://127.0.0.1:39620/api/session-token' },
|
|
282
|
-
{ name: 'Tempkey Relay', url: 'http://127.0.0.1:39610/v2/models' }
|
|
283
|
-
];
|
|
284
|
-
|
|
285
|
-
const serviceResults = [];
|
|
286
|
-
|
|
287
|
-
for (const service of services) {
|
|
288
|
-
try {
|
|
289
|
-
const start = performance.now();
|
|
290
|
-
const response = await request(service.url);
|
|
291
|
-
const duration = performance.now() - start;
|
|
292
|
-
|
|
293
|
-
const status = response.status === 200 ? '✅ 运行中' : '⚠️ 异常';
|
|
294
|
-
console.log(` ${service.name}: ${status} (${duration.toFixed(0)}ms)`);
|
|
295
|
-
|
|
296
|
-
serviceResults.push({
|
|
297
|
-
name: service.name,
|
|
298
|
-
status: response.status === 200 ? 'UP' : 'DOWN',
|
|
299
|
-
responseTime: duration.toFixed(0) + 'ms'
|
|
300
|
-
});
|
|
301
|
-
} catch (error) {
|
|
302
|
-
console.log(` ${service.name}: ❌ 离线`);
|
|
303
|
-
serviceResults.push({
|
|
304
|
-
name: service.name,
|
|
305
|
-
status: 'DOWN',
|
|
306
|
-
error: error.message
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
results.tests.push({
|
|
312
|
-
name: 'DSH 服务状态',
|
|
313
|
-
status: 'INFO',
|
|
314
|
-
services: serviceResults
|
|
315
|
-
});
|
|
316
|
-
|
|
317
|
-
return serviceResults;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
* 生成测试报告
|
|
322
|
-
*/
|
|
323
|
-
function generateReport() {
|
|
324
|
-
console.log('\n╔══════════════════════════════════════════════════════════╗');
|
|
325
|
-
console.log('║ 📊 真实场景测试报告 ║');
|
|
326
|
-
console.log('╚══════════════════════════════════════════════════════════╝\n');
|
|
327
|
-
|
|
328
|
-
const passed = results.tests.filter(t => t.status === 'PASS').length;
|
|
329
|
-
const failed = results.tests.filter(t => t.status === 'FAIL').length;
|
|
330
|
-
const total = results.tests.length;
|
|
331
|
-
|
|
332
|
-
console.log('测试汇总:');
|
|
333
|
-
console.log(` 总计: ${total} 项`);
|
|
334
|
-
console.log(` 通过: ${passed} ✅`);
|
|
335
|
-
console.log(` 失败: ${failed} ❌`);
|
|
336
|
-
console.log(` 通过率: ${(passed / total * 100).toFixed(1)}%\n`);
|
|
337
|
-
|
|
338
|
-
console.log('详细结果:');
|
|
339
|
-
console.table(results.tests.map(t => ({
|
|
340
|
-
测试项: t.name,
|
|
341
|
-
状态: t.status,
|
|
342
|
-
耗时: t.duration || t.totalTime || '-',
|
|
343
|
-
备注: t.toolCount ? `${t.toolCount}工具` :
|
|
344
|
-
t.improvement !== '0%' ? `提升${t.improvement}` :
|
|
345
|
-
t.concurrent ? `${t.successful}/${t.concurrent}成功` : '-'
|
|
346
|
-
})));
|
|
347
|
-
|
|
348
|
-
results.summary = {
|
|
349
|
-
total,
|
|
350
|
-
passed,
|
|
351
|
-
failed,
|
|
352
|
-
passRate: (passed / total * 100).toFixed(1) + '%',
|
|
353
|
-
timestamp: new Date().toISOString()
|
|
354
|
-
};
|
|
355
|
-
|
|
356
|
-
return results;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
/**
|
|
360
|
-
* 主函数
|
|
361
|
-
*/
|
|
362
|
-
async function main() {
|
|
363
|
-
console.log('╔══════════════════════════════════════════════════════════╗');
|
|
364
|
-
console.log('║ 🧪 PPT 场景真实端到端测试 ║');
|
|
365
|
-
console.log('║ 连接真实服务,验证实际性能 ║');
|
|
366
|
-
console.log('╚══════════════════════════════════════════════════════════╝');
|
|
367
|
-
|
|
368
|
-
// 执行测试
|
|
369
|
-
await testPPTServiceHealth();
|
|
370
|
-
await testMCPToolsList();
|
|
371
|
-
await testQueryPerformance();
|
|
372
|
-
await testConcurrentRequests();
|
|
373
|
-
await testDSHServices();
|
|
374
|
-
|
|
375
|
-
// 生成报告
|
|
376
|
-
const report = generateReport();
|
|
377
|
-
|
|
378
|
-
console.log('\n✅ 真实场景测试完成!');
|
|
379
|
-
console.log('\n关键发现:');
|
|
380
|
-
|
|
381
|
-
const queryTest = results.tests.find(t => t.name === '查询性能测试');
|
|
382
|
-
if (queryTest && queryTest.improvement !== '0%') {
|
|
383
|
-
console.log(` 1. 重复查询有性能提升: ${queryTest.improvement}`);
|
|
384
|
-
} else {
|
|
385
|
-
console.log(` 1. 查询性能稳定,平均 ${queryTest?.avgTime || 'N/A'}`);
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
const concurrentTest = results.tests.find(t => t.name === '并发请求测试');
|
|
389
|
-
if (concurrentTest) {
|
|
390
|
-
console.log(` 2. 并发处理能力: ${concurrentTest.successful}/10 成功`);
|
|
391
|
-
console.log(` 3. 平均响应时间: ${concurrentTest.avgTime}`);
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
console.log('\n💡 这是真实运行的数据,不是推测!');
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
main().catch(console.error);
|