evolclaw 2.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.
@@ -0,0 +1,59 @@
1
+ /**
2
+ * MessageStream - Push-based async iterable for streaming user messages to the SDK.
3
+ * Based on HappyClaw's implementation.
4
+ */
5
+ import { logger } from '../utils/logger.js';
6
+ export class MessageStream {
7
+ queue = [];
8
+ waiting = null;
9
+ done = false;
10
+ push(text, images) {
11
+ let content;
12
+ if (images && images.length > 0) {
13
+ logger.debug('[MessageStream] Creating multimodal message with', images.length, 'images');
14
+ logger.debug('[MessageStream] Image sizes:', images.map(img => img.data.length).join(', '));
15
+ // 多模态消息:text + images
16
+ content = [
17
+ { type: 'text', text },
18
+ ...images.map((img) => ({
19
+ type: 'image',
20
+ source: {
21
+ type: 'base64',
22
+ media_type: img.mimeType || 'image/png',
23
+ data: img.data,
24
+ },
25
+ })),
26
+ ];
27
+ }
28
+ else {
29
+ // 纯文本消息
30
+ content = text;
31
+ }
32
+ const message = {
33
+ type: 'user',
34
+ message: { role: 'user', content },
35
+ parent_tool_use_id: null,
36
+ session_id: '',
37
+ };
38
+ logger.debug('[MessageStream] Pushing message, content type:', Array.isArray(content) ? 'array' : 'string');
39
+ this.queue.push(message);
40
+ this.waiting?.();
41
+ }
42
+ end() {
43
+ this.done = true;
44
+ this.waiting?.();
45
+ }
46
+ async *[Symbol.asyncIterator]() {
47
+ while (true) {
48
+ while (this.queue.length > 0) {
49
+ yield this.queue.shift();
50
+ }
51
+ if (this.done)
52
+ return;
53
+ await new Promise((r) => {
54
+ this.waiting = r;
55
+ });
56
+ this.waiting = null;
57
+ }
58
+ }
59
+ }