@newbase-clawchat/openclaw-clawchat 2026.5.4 → 2026.5.12-13
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/INSTALL.md +64 -0
- package/README.md +121 -19
- package/dist/index.js +10 -19
- package/dist/setup-entry.js +3 -0
- package/dist/src/api-client.js +78 -10
- package/dist/src/api-types.test-d.js +10 -0
- package/dist/src/channel.js +25 -156
- package/dist/src/channel.setup.js +120 -0
- package/dist/src/client.js +37 -41
- package/dist/src/config.js +75 -17
- package/dist/src/inbound.js +79 -61
- package/dist/src/login.runtime.js +84 -19
- package/dist/src/media-runtime.js +8 -8
- package/dist/src/message-mapper.js +1 -1
- package/dist/src/mock-transport.js +31 -0
- package/dist/src/outbound.js +410 -26
- package/dist/src/protocol-types.js +63 -0
- package/dist/src/protocol-types.typecheck.js +1 -0
- package/dist/src/protocol.js +2 -7
- package/dist/src/reply-dispatcher.js +157 -54
- package/dist/src/runtime.js +795 -119
- package/dist/src/storage.js +689 -0
- package/dist/src/tools-schema.js +98 -16
- package/dist/src/tools.js +422 -135
- package/dist/src/ws-alignment.js +178 -0
- package/dist/src/ws-client.js +588 -0
- package/dist/src/ws-log.js +19 -0
- package/index.ts +10 -22
- package/openclaw.plugin.json +37 -2
- package/package.json +17 -4
- package/setup-entry.ts +4 -0
- package/skills/clawchat/SKILL.md +88 -0
- package/src/api-client.test.ts +274 -14
- package/src/api-client.ts +138 -23
- package/src/api-types.test-d.ts +12 -0
- package/src/api-types.ts +90 -4
- package/src/buffered-stream.test.ts +14 -12
- package/src/buffered-stream.ts +1 -1
- package/src/channel.outbound.test.ts +269 -60
- package/src/channel.setup.ts +146 -0
- package/src/channel.test.ts +130 -24
- package/src/channel.ts +30 -186
- package/src/client.test.ts +197 -11
- package/src/client.ts +50 -57
- package/src/config.test.ts +108 -6
- package/src/config.ts +95 -24
- package/src/inbound.test.ts +288 -37
- package/src/inbound.ts +96 -84
- package/src/login.runtime.test.ts +347 -13
- package/src/login.runtime.ts +105 -23
- package/src/manifest.test.ts +146 -74
- package/src/media-runtime.test.ts +57 -2
- package/src/media-runtime.ts +26 -17
- package/src/message-mapper.test.ts +2 -2
- package/src/message-mapper.ts +2 -2
- package/src/mock-transport.test.ts +35 -0
- package/src/mock-transport.ts +38 -0
- package/src/outbound.test.ts +694 -73
- package/src/outbound.ts +484 -31
- package/src/plugin-entry.test.ts +1 -0
- package/src/protocol-types.test.ts +69 -0
- package/src/protocol-types.ts +296 -0
- package/src/protocol-types.typecheck.ts +89 -0
- package/src/protocol.test.ts +1 -6
- package/src/protocol.ts +2 -7
- package/src/reply-dispatcher.test.ts +819 -119
- package/src/reply-dispatcher.ts +202 -60
- package/src/runtime.test.ts +2120 -41
- package/src/runtime.ts +935 -142
- package/src/scripts.test.ts +85 -0
- package/src/storage.test.ts +793 -0
- package/src/storage.ts +1095 -0
- package/src/streaming.test.ts +9 -8
- package/src/streaming.ts +1 -1
- package/src/tools-schema.ts +148 -20
- package/src/tools.test.ts +377 -50
- package/src/tools.ts +574 -154
- package/src/ws-alignment.test.ts +103 -0
- package/src/ws-alignment.ts +275 -0
- package/src/ws-client.test.ts +1218 -0
- package/src/ws-client.ts +662 -0
- package/src/ws-log.test.ts +32 -0
- package/src/ws-log.ts +31 -0
- package/skills/clawchat-account-tools/SKILL.md +0 -26
- package/skills/clawchat-activate/SKILL.md +0 -47
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { formatWsLog } from "./ws-log.js";
|
|
2
|
+
export const MAX_WS_QUEUE_SIZE = 128;
|
|
3
|
+
export function createAlignedWsQueue(options) {
|
|
4
|
+
const maxSize = options.maxSize ?? MAX_WS_QUEUE_SIZE;
|
|
5
|
+
const queue = [];
|
|
6
|
+
const context = () => options.context?.() ?? {
|
|
7
|
+
attempt: options.attempt ?? 1,
|
|
8
|
+
reconnectCount: options.reconnectCount ?? 0,
|
|
9
|
+
state: options.state ?? "ready",
|
|
10
|
+
};
|
|
11
|
+
const logFrame = (event, action, item, fields = [], logState) => {
|
|
12
|
+
const current = context();
|
|
13
|
+
options.log(formatWsLog({
|
|
14
|
+
event,
|
|
15
|
+
accountId: options.accountId,
|
|
16
|
+
attempt: current.attempt,
|
|
17
|
+
reconnectCount: current.reconnectCount,
|
|
18
|
+
state: logState ?? current.state,
|
|
19
|
+
action,
|
|
20
|
+
fields: [
|
|
21
|
+
["event_name", item.eventName],
|
|
22
|
+
["trace_id", item.traceId],
|
|
23
|
+
["chat_id", item.chatId],
|
|
24
|
+
...fields,
|
|
25
|
+
],
|
|
26
|
+
}));
|
|
27
|
+
};
|
|
28
|
+
return {
|
|
29
|
+
enqueue(item) {
|
|
30
|
+
if (queue.length >= maxSize) {
|
|
31
|
+
const dropped = queue.shift();
|
|
32
|
+
if (dropped) {
|
|
33
|
+
logFrame("send_queue_drop", "drop_oldest", dropped, [
|
|
34
|
+
["queue_size", queue.length],
|
|
35
|
+
["queue_max", maxSize],
|
|
36
|
+
], context().state);
|
|
37
|
+
dropped.onDrop?.();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
queue.push(item);
|
|
41
|
+
logFrame("send_queued", "queue", item, [["queue_size", queue.length]]);
|
|
42
|
+
},
|
|
43
|
+
flush(write) {
|
|
44
|
+
while (queue.length > 0) {
|
|
45
|
+
const item = queue[0];
|
|
46
|
+
try {
|
|
47
|
+
write(item.wire);
|
|
48
|
+
queue.shift();
|
|
49
|
+
item.onWrite?.();
|
|
50
|
+
logFrame("send_flush", "send", item, [["remaining", queue.length]], "ready");
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
logFrame("send_failed", "requeue_reconnect", item, [["queue_size", queue.length]]);
|
|
54
|
+
throw err;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
remove(item) {
|
|
59
|
+
const index = queue.indexOf(item);
|
|
60
|
+
if (index < 0)
|
|
61
|
+
return false;
|
|
62
|
+
queue.splice(index, 1);
|
|
63
|
+
return true;
|
|
64
|
+
},
|
|
65
|
+
snapshot() {
|
|
66
|
+
return [...queue];
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
export function createReconnectTracker(options) {
|
|
71
|
+
const stableResetMs = options.stableResetMs ?? 5000;
|
|
72
|
+
let attempt = 0;
|
|
73
|
+
let reconnectCount = 0;
|
|
74
|
+
let state = "idle";
|
|
75
|
+
let stableResetTimer;
|
|
76
|
+
const clearStableReset = () => {
|
|
77
|
+
if (!stableResetTimer)
|
|
78
|
+
return;
|
|
79
|
+
clearTimeout(stableResetTimer);
|
|
80
|
+
stableResetTimer = undefined;
|
|
81
|
+
};
|
|
82
|
+
return {
|
|
83
|
+
connectStart() {
|
|
84
|
+
clearStableReset();
|
|
85
|
+
attempt += 1;
|
|
86
|
+
state = "connecting";
|
|
87
|
+
return { attempt, reconnectCount };
|
|
88
|
+
},
|
|
89
|
+
scheduleReconnect(reason, details = {}) {
|
|
90
|
+
clearStableReset();
|
|
91
|
+
reconnectCount += 1;
|
|
92
|
+
state = "reconnecting";
|
|
93
|
+
if (details.delayMs !== undefined || details.maxDelayMs !== undefined) {
|
|
94
|
+
options.log(formatWsLog({
|
|
95
|
+
event: "reconnect_scheduled",
|
|
96
|
+
accountId: options.accountId,
|
|
97
|
+
attempt,
|
|
98
|
+
reconnectCount,
|
|
99
|
+
state: "reconnecting",
|
|
100
|
+
action: "wait",
|
|
101
|
+
fields: [
|
|
102
|
+
["delay_ms", details.delayMs],
|
|
103
|
+
["max_delay_ms", details.maxDelayMs ?? options.maxDelayMs],
|
|
104
|
+
["reason", reason],
|
|
105
|
+
],
|
|
106
|
+
}));
|
|
107
|
+
}
|
|
108
|
+
return { attempt, reconnectCount };
|
|
109
|
+
},
|
|
110
|
+
markReady() {
|
|
111
|
+
clearStableReset();
|
|
112
|
+
state = "ready";
|
|
113
|
+
stableResetTimer = setTimeout(() => {
|
|
114
|
+
reconnectCount = 0;
|
|
115
|
+
options.log(formatWsLog({
|
|
116
|
+
event: "reconnect_backoff_reset",
|
|
117
|
+
accountId: options.accountId,
|
|
118
|
+
attempt,
|
|
119
|
+
reconnectCount,
|
|
120
|
+
state: "ready",
|
|
121
|
+
action: "reset",
|
|
122
|
+
fields: [["stable_ms", stableResetMs]],
|
|
123
|
+
}));
|
|
124
|
+
stableResetTimer = undefined;
|
|
125
|
+
}, stableResetMs);
|
|
126
|
+
},
|
|
127
|
+
markClosed() {
|
|
128
|
+
clearStableReset();
|
|
129
|
+
state = "closed";
|
|
130
|
+
},
|
|
131
|
+
snapshot() {
|
|
132
|
+
return { attempt, reconnectCount, state };
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
export function createProtocolControlHandler(options) {
|
|
137
|
+
const context = () => options.context?.() ?? {
|
|
138
|
+
attempt: options.attempt ?? 1,
|
|
139
|
+
reconnectCount: options.reconnectCount ?? 0,
|
|
140
|
+
state: options.state ?? "ready",
|
|
141
|
+
};
|
|
142
|
+
const logControl = (event, action, fields) => {
|
|
143
|
+
const current = context();
|
|
144
|
+
options.log(formatWsLog({
|
|
145
|
+
event,
|
|
146
|
+
accountId: options.accountId,
|
|
147
|
+
attempt: current.attempt,
|
|
148
|
+
reconnectCount: current.reconnectCount,
|
|
149
|
+
state: current.state,
|
|
150
|
+
action,
|
|
151
|
+
fields,
|
|
152
|
+
}));
|
|
153
|
+
};
|
|
154
|
+
return {
|
|
155
|
+
handleInbound(env) {
|
|
156
|
+
if (env.event === "ping") {
|
|
157
|
+
logControl("protocol_ping_received", "send_pong", [["trace_id", env.trace_id]]);
|
|
158
|
+
options.send(JSON.stringify({
|
|
159
|
+
version: "2",
|
|
160
|
+
event: "pong",
|
|
161
|
+
trace_id: env.trace_id ?? "-",
|
|
162
|
+
emitted_at: Date.now(),
|
|
163
|
+
payload: {},
|
|
164
|
+
}));
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
if (env.event === "pong") {
|
|
168
|
+
logControl("protocol_pong_received", "ignore", [["trace_id", env.trace_id]]);
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
return false;
|
|
172
|
+
},
|
|
173
|
+
heartbeatTimeout(timeoutMs) {
|
|
174
|
+
logControl("heartbeat_timeout", "reconnect", [["timeout_ms", timeoutMs]]);
|
|
175
|
+
options.scheduleReconnect?.("heartbeat_timeout");
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
}
|