@clawling/clawchat-plugin-openclaw 2026.5.12-28

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 (114) hide show
  1. package/INSTALL.md +64 -0
  2. package/README.md +227 -0
  3. package/dist/index.js +20 -0
  4. package/dist/setup-entry.js +3 -0
  5. package/dist/src/api-client.js +263 -0
  6. package/dist/src/api-types.js +17 -0
  7. package/dist/src/api-types.test-d.js +10 -0
  8. package/dist/src/buffered-stream.js +177 -0
  9. package/dist/src/channel.js +66 -0
  10. package/dist/src/channel.setup.js +119 -0
  11. package/dist/src/clawchat-memory.js +403 -0
  12. package/dist/src/clawchat-metadata.js +310 -0
  13. package/dist/src/client.js +35 -0
  14. package/dist/src/commands.js +35 -0
  15. package/dist/src/config.js +274 -0
  16. package/dist/src/group-message-coalescer.js +119 -0
  17. package/dist/src/inbound.js +170 -0
  18. package/dist/src/llm-context-debug.js +86 -0
  19. package/dist/src/login.runtime.js +204 -0
  20. package/dist/src/media-runtime.js +85 -0
  21. package/dist/src/message-mapper.js +146 -0
  22. package/dist/src/mock-transport.js +31 -0
  23. package/dist/src/outbound.js +628 -0
  24. package/dist/src/plugin-prompts.js +89 -0
  25. package/dist/src/profile-prompt.js +269 -0
  26. package/dist/src/profile-sync.js +110 -0
  27. package/dist/src/prompt-injection.js +25 -0
  28. package/dist/src/protocol-types.js +63 -0
  29. package/dist/src/protocol-types.typecheck.js +1 -0
  30. package/dist/src/protocol.js +33 -0
  31. package/dist/src/reply-dispatcher.js +422 -0
  32. package/dist/src/runtime.js +1254 -0
  33. package/dist/src/storage.js +525 -0
  34. package/dist/src/streaming.js +65 -0
  35. package/dist/src/terminal-send.js +36 -0
  36. package/dist/src/tools-schema.js +208 -0
  37. package/dist/src/tools.js +920 -0
  38. package/dist/src/ws-alignment.js +178 -0
  39. package/dist/src/ws-client.js +588 -0
  40. package/dist/src/ws-log.js +19 -0
  41. package/index.ts +24 -0
  42. package/openclaw.plugin.json +169 -0
  43. package/package.json +80 -0
  44. package/prompts/default-group-bio.md +19 -0
  45. package/prompts/default-owner-behavior.md +27 -0
  46. package/prompts/platform.md +13 -0
  47. package/setup-entry.ts +4 -0
  48. package/skills/clawchat/SKILL.md +91 -0
  49. package/src/api-client.test.ts +827 -0
  50. package/src/api-client.ts +414 -0
  51. package/src/api-types.ts +146 -0
  52. package/src/channel.outbound.test.ts +433 -0
  53. package/src/channel.setup.ts +145 -0
  54. package/src/channel.test.ts +262 -0
  55. package/src/channel.ts +81 -0
  56. package/src/clawchat-memory.test.ts +480 -0
  57. package/src/clawchat-memory.ts +533 -0
  58. package/src/clawchat-metadata.test.ts +477 -0
  59. package/src/clawchat-metadata.ts +429 -0
  60. package/src/client.test.ts +169 -0
  61. package/src/client.ts +56 -0
  62. package/src/commands.test.ts +39 -0
  63. package/src/commands.ts +41 -0
  64. package/src/config.test.ts +344 -0
  65. package/src/config.ts +404 -0
  66. package/src/group-message-coalescer.test.ts +237 -0
  67. package/src/group-message-coalescer.ts +171 -0
  68. package/src/inbound.test.ts +508 -0
  69. package/src/inbound.ts +278 -0
  70. package/src/llm-context-debug.test.ts +55 -0
  71. package/src/llm-context-debug.ts +139 -0
  72. package/src/login.runtime.test.ts +737 -0
  73. package/src/login.runtime.ts +277 -0
  74. package/src/manifest.test.ts +352 -0
  75. package/src/media-runtime.test.ts +207 -0
  76. package/src/media-runtime.ts +152 -0
  77. package/src/message-mapper.test.ts +201 -0
  78. package/src/message-mapper.ts +174 -0
  79. package/src/mock-transport.test.ts +35 -0
  80. package/src/mock-transport.ts +38 -0
  81. package/src/outbound.test.ts +1269 -0
  82. package/src/outbound.ts +803 -0
  83. package/src/plugin-entry.test.ts +38 -0
  84. package/src/plugin-prompts.test.ts +94 -0
  85. package/src/plugin-prompts.ts +107 -0
  86. package/src/profile-prompt.test.ts +274 -0
  87. package/src/profile-prompt.ts +351 -0
  88. package/src/profile-sync.test.ts +539 -0
  89. package/src/profile-sync.ts +191 -0
  90. package/src/prompt-injection.test.ts +39 -0
  91. package/src/prompt-injection.ts +45 -0
  92. package/src/protocol-types.test.ts +69 -0
  93. package/src/protocol-types.ts +296 -0
  94. package/src/protocol-types.typecheck.ts +89 -0
  95. package/src/protocol.test.ts +39 -0
  96. package/src/protocol.ts +42 -0
  97. package/src/reply-dispatcher.test.ts +1324 -0
  98. package/src/reply-dispatcher.ts +555 -0
  99. package/src/runtime.test.ts +4719 -0
  100. package/src/runtime.ts +1493 -0
  101. package/src/scripts.test.ts +85 -0
  102. package/src/storage.test.ts +560 -0
  103. package/src/storage.ts +807 -0
  104. package/src/terminal-send.test.ts +81 -0
  105. package/src/terminal-send.ts +56 -0
  106. package/src/tools-schema.ts +337 -0
  107. package/src/tools.test.ts +933 -0
  108. package/src/tools.ts +1185 -0
  109. package/src/ws-alignment.test.ts +103 -0
  110. package/src/ws-alignment.ts +275 -0
  111. package/src/ws-client.test.ts +1217 -0
  112. package/src/ws-client.ts +662 -0
  113. package/src/ws-log.test.ts +32 -0
  114. package/src/ws-log.ts +31 -0
@@ -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
+ }