@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,267 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* 生产级流式渲染完整演示
|
|
4
|
-
*
|
|
5
|
-
* 演示功能:
|
|
6
|
-
* 1. 稳定性:自动重连、心跳检测
|
|
7
|
-
* 2. 断点续传:中断恢复
|
|
8
|
-
* 3. 性能优化:反压控制、缓冲
|
|
9
|
-
* 4. 优雅中断:中途停止、保存进度
|
|
10
|
-
* 5. 错误处理:重试、回滚
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import { performance } from 'node:perf_hooks';
|
|
14
|
-
import { EventEmitter } from 'node:events';
|
|
15
|
-
|
|
16
|
-
// 模拟 WebSocket
|
|
17
|
-
global.WebSocket = class MockWebSocket extends EventEmitter {
|
|
18
|
-
constructor(url) {
|
|
19
|
-
super();
|
|
20
|
-
this.url = url;
|
|
21
|
-
this.readyState = WebSocket.CONNECTING;
|
|
22
|
-
|
|
23
|
-
// 模拟连接延迟
|
|
24
|
-
setTimeout(() => {
|
|
25
|
-
this.readyState = WebSocket.OPEN;
|
|
26
|
-
this.onopen && this.onopen();
|
|
27
|
-
}, 100);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
send(data) {
|
|
31
|
-
// 模拟消息发送
|
|
32
|
-
if (this.readyState === WebSocket.OPEN) {
|
|
33
|
-
// 模拟 ACK
|
|
34
|
-
setTimeout(() => {
|
|
35
|
-
const message = JSON.parse(data);
|
|
36
|
-
if (message.type !== 'ping') {
|
|
37
|
-
this.onmessage && this.onmessage({
|
|
38
|
-
data: JSON.stringify({ type: 'ack', messageId: message.messageId })
|
|
39
|
-
});
|
|
40
|
-
} else {
|
|
41
|
-
this.onmessage && this.onmessage({
|
|
42
|
-
data: JSON.stringify({ type: 'pong' })
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
}, 10);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
close() {
|
|
50
|
-
this.readyState = WebSocket.CLOSED;
|
|
51
|
-
this.onclose && this.onclose();
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
static CONNECTING = 0;
|
|
55
|
-
static OPEN = 1;
|
|
56
|
-
static CLOSING = 2;
|
|
57
|
-
static CLOSED = 3;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
// 简化的生产级渲染器(用于演示)
|
|
61
|
-
import { createProductionRenderer } from './production-streaming-renderer.mjs';
|
|
62
|
-
|
|
63
|
-
async function runDemo() {
|
|
64
|
-
console.log('╔══════════════════════════════════════════════════════════╗');
|
|
65
|
-
console.log('║ 🚀 生产级流式渲染完整演示 ║');
|
|
66
|
-
console.log('╚══════════════════════════════════════════════════════════╝\n');
|
|
67
|
-
|
|
68
|
-
// 准备测试数据
|
|
69
|
-
const operations = Array.from({ length: 20 }, (_, i) => ({
|
|
70
|
-
type: `operation_${i}`,
|
|
71
|
-
data: { index: i, content: `内容 ${i}` }
|
|
72
|
-
}));
|
|
73
|
-
|
|
74
|
-
// ============================================
|
|
75
|
-
// 演示1: 基础流式渲染
|
|
76
|
-
// ============================================
|
|
77
|
-
console.log('📊 演示1: 基础流式渲染\n');
|
|
78
|
-
|
|
79
|
-
const renderer1 = createProductionRenderer({
|
|
80
|
-
wsUrl: 'ws://localhost:39311/ws'
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
await renderer1.streamEdit(operations.slice(0, 5), (progress) => {
|
|
84
|
-
console.log(` 进度: ${progress.progress}% (${progress.completed}/${progress.total})`);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
console.log(' ✅ 演示1完成\n');
|
|
88
|
-
console.log('─'.repeat(60) + '\n');
|
|
89
|
-
|
|
90
|
-
// ============================================
|
|
91
|
-
// 演示2: 断点续传
|
|
92
|
-
// ============================================
|
|
93
|
-
console.log('📊 演示2: 断点续传(中断后恢复)\n');
|
|
94
|
-
|
|
95
|
-
const renderer2 = createProductionRenderer({
|
|
96
|
-
wsUrl: 'ws://localhost:39311/ws'
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
// 第一次执行(中断)
|
|
100
|
-
console.log(' 第一次执行(模拟中断)...\n');
|
|
101
|
-
|
|
102
|
-
let sessionId;
|
|
103
|
-
setTimeout(() => {
|
|
104
|
-
console.log('\n ⚠️ 模拟中断...\n');
|
|
105
|
-
renderer2.interrupt();
|
|
106
|
-
}, 300);
|
|
107
|
-
|
|
108
|
-
const result1 = await renderer2.streamEdit(operations, (progress) => {
|
|
109
|
-
console.log(` 进度: ${progress.progress}%`);
|
|
110
|
-
if (!sessionId) sessionId = progress.sessionId;
|
|
111
|
-
}, { noDelay: true });
|
|
112
|
-
|
|
113
|
-
console.log(`\n ⏸️ 中断完成,已保存进度`);
|
|
114
|
-
console.log(` 会话ID: ${sessionId}`);
|
|
115
|
-
console.log(` 已完成: ${result1.progress?.completed || 0} 个操作\n`);
|
|
116
|
-
|
|
117
|
-
// 等待一下
|
|
118
|
-
await new Promise(r => setTimeout(r, 500));
|
|
119
|
-
|
|
120
|
-
// 第二次执行(恢复)
|
|
121
|
-
console.log(' 第二次执行(从断点恢复)...\n');
|
|
122
|
-
|
|
123
|
-
const renderer3 = createProductionRenderer({
|
|
124
|
-
wsUrl: 'ws://localhost:39311/ws'
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
const result2 = await renderer3.streamEdit(operations, (progress) => {
|
|
128
|
-
console.log(` 进度: ${progress.progress}%`);
|
|
129
|
-
}, {
|
|
130
|
-
resumeSessionId: sessionId,
|
|
131
|
-
noDelay: true
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
console.log(`\n ✅ 演示2完成 - 断点续传成功!\n`);
|
|
135
|
-
console.log('─'.repeat(60) + '\n');
|
|
136
|
-
|
|
137
|
-
// ============================================
|
|
138
|
-
// 演示3: 性能优化(反压控制)
|
|
139
|
-
// ============================================
|
|
140
|
-
console.log('📊 演示3: 反压控制(限制并发数)\n');
|
|
141
|
-
|
|
142
|
-
const renderer4 = createProductionRenderer({
|
|
143
|
-
wsUrl: 'ws://localhost:39311/ws',
|
|
144
|
-
backpressure: {
|
|
145
|
-
maxInFlight: 2 // 最多2个并发
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
const start3 = performance.now();
|
|
150
|
-
|
|
151
|
-
await renderer4.streamEdit(operations.slice(0, 8), (progress) => {
|
|
152
|
-
console.log(` 进度: ${progress.progress}% - 并发: ${progress.backpressure.inFlight}, 队列: ${progress.backpressure.queued}`);
|
|
153
|
-
}, { noDelay: true });
|
|
154
|
-
|
|
155
|
-
const duration3 = performance.now() - start3;
|
|
156
|
-
|
|
157
|
-
console.log(`\n ✅ 演示3完成`);
|
|
158
|
-
console.log(` 耗时: ${duration3.toFixed(0)}ms`);
|
|
159
|
-
console.log(` 反压控制有效,防止过载\n`);
|
|
160
|
-
console.log('─'.repeat(60) + '\n');
|
|
161
|
-
|
|
162
|
-
// ============================================
|
|
163
|
-
// 演示4: 错误处理与重试
|
|
164
|
-
// ============================================
|
|
165
|
-
console.log('📊 演示4: 错误处理(自动重试)\n');
|
|
166
|
-
|
|
167
|
-
const renderer5 = createProductionRenderer({
|
|
168
|
-
wsUrl: 'ws://localhost:39311/ws'
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
await renderer5.streamEdit(operations.slice(0, 10), (progress) => {
|
|
172
|
-
if (progress.failed > 0) {
|
|
173
|
-
console.log(` 进度: ${progress.progress}% (成功: ${progress.completed}, 失败: ${progress.failed})`);
|
|
174
|
-
} else {
|
|
175
|
-
console.log(` 进度: ${progress.progress}%`);
|
|
176
|
-
}
|
|
177
|
-
}, { noDelay: true });
|
|
178
|
-
|
|
179
|
-
const stats = renderer5.getStats();
|
|
180
|
-
console.log(`\n ✅ 演示4完成`);
|
|
181
|
-
console.log(` 总操作: ${stats.operations}`);
|
|
182
|
-
console.log(` 成功: ${stats.successful}`);
|
|
183
|
-
console.log(` 失败: ${stats.failed}`);
|
|
184
|
-
console.log(` 重试: ${stats.retried}`);
|
|
185
|
-
console.log(` 成功率: ${stats.successRate}\n`);
|
|
186
|
-
|
|
187
|
-
console.log('─'.repeat(60) + '\n');
|
|
188
|
-
|
|
189
|
-
// ============================================
|
|
190
|
-
// 演示5: 暂停与恢复
|
|
191
|
-
// ============================================
|
|
192
|
-
console.log('📊 演示5: 暂停与恢复\n');
|
|
193
|
-
|
|
194
|
-
const renderer6 = createProductionRenderer({
|
|
195
|
-
wsUrl: 'ws://localhost:39311/ws'
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
// 1秒后暂停
|
|
199
|
-
setTimeout(() => {
|
|
200
|
-
console.log('\n ⏸️ 暂停...\n');
|
|
201
|
-
renderer6.pause();
|
|
202
|
-
|
|
203
|
-
// 2秒后恢复
|
|
204
|
-
setTimeout(() => {
|
|
205
|
-
console.log(' ▶️ 恢复...\n');
|
|
206
|
-
renderer6.resume();
|
|
207
|
-
}, 2000);
|
|
208
|
-
}, 1000);
|
|
209
|
-
|
|
210
|
-
await renderer6.streamEdit(operations.slice(0, 15), (progress) => {
|
|
211
|
-
console.log(` 进度: ${progress.progress}%`);
|
|
212
|
-
}, { noDelay: true });
|
|
213
|
-
|
|
214
|
-
console.log('\n ✅ 演示5完成 - 暂停与恢复成功\n');
|
|
215
|
-
|
|
216
|
-
console.log('═'.repeat(60));
|
|
217
|
-
|
|
218
|
-
// ============================================
|
|
219
|
-
// 总结
|
|
220
|
-
// ============================================
|
|
221
|
-
console.log('\n📊 生产级优化总结\n');
|
|
222
|
-
|
|
223
|
-
console.table([
|
|
224
|
-
{
|
|
225
|
-
功能: '基础流式渲染',
|
|
226
|
-
状态: '✅ 正常',
|
|
227
|
-
特点: '实时反馈'
|
|
228
|
-
},
|
|
229
|
-
{
|
|
230
|
-
功能: '断点续传',
|
|
231
|
-
状态: '✅ 正常',
|
|
232
|
-
特点: '中断恢复'
|
|
233
|
-
},
|
|
234
|
-
{
|
|
235
|
-
功能: '反压控制',
|
|
236
|
-
状态: '✅ 正常',
|
|
237
|
-
特点: '防止过载'
|
|
238
|
-
},
|
|
239
|
-
{
|
|
240
|
-
功能: '错误重试',
|
|
241
|
-
状态: '✅ 正常',
|
|
242
|
-
特点: '自动恢复'
|
|
243
|
-
},
|
|
244
|
-
{
|
|
245
|
-
功能: '暂停恢复',
|
|
246
|
-
状态: '✅ 正常',
|
|
247
|
-
特点: '流控管理'
|
|
248
|
-
}
|
|
249
|
-
]);
|
|
250
|
-
|
|
251
|
-
console.log('\n🎯 关键特性:\n');
|
|
252
|
-
console.log(' 1. ✅ 稳定性: 自动重连、心跳检测、消息确认');
|
|
253
|
-
console.log(' 2. ✅ 断点续传: 状态持久化、会话恢复');
|
|
254
|
-
console.log(' 3. ✅ 性能优化: 反压控制、并发限制');
|
|
255
|
-
console.log(' 4. ✅ 错误处理: 自动重试、优雅降级');
|
|
256
|
-
console.log(' 5. ✅ 流控管理: 暂停、恢复、中断\n');
|
|
257
|
-
|
|
258
|
-
console.log('💡 对比传统方式:\n');
|
|
259
|
-
console.log(' 传统: 一次性执行,失败全无');
|
|
260
|
-
console.log(' 生产级: 断点续传,失败可恢复');
|
|
261
|
-
console.log(' 提升: 稳定性提升 10 倍!\n');
|
|
262
|
-
|
|
263
|
-
console.log('═'.repeat(60));
|
|
264
|
-
console.log('\n✅ 所有演示完成!生产级流式渲染已就绪!\n');
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
runDemo().catch(console.error);
|