@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.
Files changed (85) hide show
  1. package/INSTALL.md +64 -0
  2. package/README.md +121 -19
  3. package/dist/index.js +10 -19
  4. package/dist/setup-entry.js +3 -0
  5. package/dist/src/api-client.js +78 -10
  6. package/dist/src/api-types.test-d.js +10 -0
  7. package/dist/src/channel.js +25 -156
  8. package/dist/src/channel.setup.js +120 -0
  9. package/dist/src/client.js +37 -41
  10. package/dist/src/config.js +75 -17
  11. package/dist/src/inbound.js +79 -61
  12. package/dist/src/login.runtime.js +84 -19
  13. package/dist/src/media-runtime.js +8 -8
  14. package/dist/src/message-mapper.js +1 -1
  15. package/dist/src/mock-transport.js +31 -0
  16. package/dist/src/outbound.js +410 -26
  17. package/dist/src/protocol-types.js +63 -0
  18. package/dist/src/protocol-types.typecheck.js +1 -0
  19. package/dist/src/protocol.js +2 -7
  20. package/dist/src/reply-dispatcher.js +157 -54
  21. package/dist/src/runtime.js +795 -119
  22. package/dist/src/storage.js +689 -0
  23. package/dist/src/tools-schema.js +98 -16
  24. package/dist/src/tools.js +422 -135
  25. package/dist/src/ws-alignment.js +178 -0
  26. package/dist/src/ws-client.js +588 -0
  27. package/dist/src/ws-log.js +19 -0
  28. package/index.ts +10 -22
  29. package/openclaw.plugin.json +37 -2
  30. package/package.json +17 -4
  31. package/setup-entry.ts +4 -0
  32. package/skills/clawchat/SKILL.md +88 -0
  33. package/src/api-client.test.ts +274 -14
  34. package/src/api-client.ts +138 -23
  35. package/src/api-types.test-d.ts +12 -0
  36. package/src/api-types.ts +90 -4
  37. package/src/buffered-stream.test.ts +14 -12
  38. package/src/buffered-stream.ts +1 -1
  39. package/src/channel.outbound.test.ts +269 -60
  40. package/src/channel.setup.ts +146 -0
  41. package/src/channel.test.ts +130 -24
  42. package/src/channel.ts +30 -186
  43. package/src/client.test.ts +197 -11
  44. package/src/client.ts +50 -57
  45. package/src/config.test.ts +108 -6
  46. package/src/config.ts +95 -24
  47. package/src/inbound.test.ts +288 -37
  48. package/src/inbound.ts +96 -84
  49. package/src/login.runtime.test.ts +347 -13
  50. package/src/login.runtime.ts +105 -23
  51. package/src/manifest.test.ts +146 -74
  52. package/src/media-runtime.test.ts +57 -2
  53. package/src/media-runtime.ts +26 -17
  54. package/src/message-mapper.test.ts +2 -2
  55. package/src/message-mapper.ts +2 -2
  56. package/src/mock-transport.test.ts +35 -0
  57. package/src/mock-transport.ts +38 -0
  58. package/src/outbound.test.ts +694 -73
  59. package/src/outbound.ts +484 -31
  60. package/src/plugin-entry.test.ts +1 -0
  61. package/src/protocol-types.test.ts +69 -0
  62. package/src/protocol-types.ts +296 -0
  63. package/src/protocol-types.typecheck.ts +89 -0
  64. package/src/protocol.test.ts +1 -6
  65. package/src/protocol.ts +2 -7
  66. package/src/reply-dispatcher.test.ts +819 -119
  67. package/src/reply-dispatcher.ts +202 -60
  68. package/src/runtime.test.ts +2120 -41
  69. package/src/runtime.ts +935 -142
  70. package/src/scripts.test.ts +85 -0
  71. package/src/storage.test.ts +793 -0
  72. package/src/storage.ts +1095 -0
  73. package/src/streaming.test.ts +9 -8
  74. package/src/streaming.ts +1 -1
  75. package/src/tools-schema.ts +148 -20
  76. package/src/tools.test.ts +377 -50
  77. package/src/tools.ts +574 -154
  78. package/src/ws-alignment.test.ts +103 -0
  79. package/src/ws-alignment.ts +275 -0
  80. package/src/ws-client.test.ts +1218 -0
  81. package/src/ws-client.ts +662 -0
  82. package/src/ws-log.test.ts +32 -0
  83. package/src/ws-log.ts +31 -0
  84. package/skills/clawchat-account-tools/SKILL.md +0 -26
  85. 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
+ }