adp-openclaw 0.0.2

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,506 @@
1
+ # ADP-OpenCraw WebSocket ๅ่ฎฎๆ–‡ๆกฃ
2
+
3
+ ## ๐Ÿ“‹ ๆฆ‚่ฟฐ
4
+
5
+ ๆœฌๆ–‡ๆกฃๆ่ฟฐไบ† adp-opencraw ้กน็›ฎไธญๆ’ไปถ็ซฏ๏ผˆTypeScript๏ผ‰ไธŽ Go Server ไน‹้—ด็š„ WebSocket ้€šไฟกๅ่ฎฎๅ’Œ Key ้ชŒ่ฏๆœบๅˆถใ€‚
6
+
7
+ ## ๐Ÿ—๏ธ ๆžถๆž„ๆฆ‚่งˆ
8
+
9
+ ```
10
+ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
11
+ โ”‚ โ”‚ WebSocket (ๅŒๅ‘้€šไฟก) โ”‚ โ”‚
12
+ โ”‚ ๆ’ไปถ็ซฏ โ”‚ โ—€โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ–ถ โ”‚ Go Server โ”‚
13
+ โ”‚ (TypeScript) โ”‚ โ”‚ โ”‚
14
+ โ”‚ โ”‚ โ”‚ โ”‚
15
+ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
16
+ โ”‚ โ”‚
17
+ โ”‚ โ”‚
18
+ โ–ผ โ–ผ
19
+ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
20
+ โ”‚ OpenClaw โ”‚ โ”‚ ็”จๆˆทๆถˆๆฏ โ”‚
21
+ โ”‚ Runtime โ”‚ โ”‚ HTTPๆŽฅๅฃ โ”‚
22
+ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
23
+ ```
24
+
25
+ ---
26
+
27
+ ## ๐Ÿ” Key ้ชŒ่ฏๆต็จ‹
28
+
29
+ ### 1. Token ็ฑปๅž‹
30
+
31
+ | Token ็ฑปๅž‹ | ็”จ้€” | ็”Ÿๆˆๆ–นๅผ | ้•ฟๅบฆ |
32
+ |-----------|------|---------|------|
33
+ | **Admin Token** | ็ฎก็†ๅ‘˜ๆ“ไฝœ๏ผˆๆณจๅ†Œๅฎขๆˆท็ซฏ๏ผ‰ | ๅฏๅŠจๆ—ถ็”Ÿๆˆๆˆ– `--admin-token` ๆŒ‡ๅฎš | 64 ๅญ—็ฌฆ hex |
34
+ | **Client Token** | ๅฎขๆˆท็ซฏ WebSocket ่ฎค่ฏ | ๆณจๅ†Œๅฎขๆˆท็ซฏๆ—ถ่‡ชๅŠจ็”Ÿๆˆ | 64 ๅญ—็ฌฆ hex |
35
+
36
+ ### 2. Token ็”Ÿๆˆ็ฎ—ๆณ•
37
+
38
+ ```go
39
+ // ็”Ÿๆˆ 32 ๅญ—่Š‚้šๆœบๆ•ฐ๏ผŒ่ฝฌๆขไธบ 64 ๅญ—็ฌฆ็š„ๅๅ…ญ่ฟ›ๅˆถๅญ—็ฌฆไธฒ
40
+ func generateToken() string {
41
+ bytes := make([]byte, 32)
42
+ rand.Read(bytes)
43
+ return hex.EncodeToString(bytes)
44
+ }
45
+ ```
46
+
47
+ ### 3. WebSocket ่ฎค่ฏๆต็จ‹
48
+
49
+ ```
50
+ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
51
+ โ”‚ Client โ”‚ โ”‚ Server โ”‚
52
+ โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜
53
+ โ”‚ โ”‚
54
+ โ”‚ 1. ๅปบ็ซ‹ WebSocket ่ฟžๆŽฅ โ”‚
55
+ โ”‚ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ถ โ”‚
56
+ โ”‚ โ”‚
57
+ โ”‚ 2. ๅ‘้€ Auth ๆถˆๆฏ (30็ง’่ถ…ๆ—ถ) โ”‚
58
+ โ”‚ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ถ โ”‚
59
+ โ”‚ { โ”‚
60
+ โ”‚ type: "auth", โ”‚
61
+ โ”‚ payload: { โ”‚
62
+ โ”‚ token: "client_api_token", โ”‚
63
+ โ”‚ nonce: "random_nonce", โ”‚ 3. ้ชŒ่ฏ Token
64
+ โ”‚ signature: "hmac_sha256" โ”‚ ้ชŒ่ฏ็ญพๅ
65
+ โ”‚ } โ”‚
66
+ โ”‚ } โ”‚
67
+ โ”‚ โ”‚
68
+ โ”‚ 4. ่ฟ”ๅ›ž่ฎค่ฏ็ป“ๆžœ โ”‚
69
+ โ”‚ โ—€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ โ”‚
70
+ โ”‚ { โ”‚
71
+ โ”‚ type: "auth_result", โ”‚
72
+ โ”‚ payload: { โ”‚
73
+ โ”‚ success: true, โ”‚
74
+ โ”‚ clientId: "client-xxx", โ”‚
75
+ โ”‚ message: "Authentication ok" โ”‚
76
+ โ”‚ } โ”‚
77
+ โ”‚ } โ”‚
78
+ โ”‚ โ”‚
79
+ โ”‚ 5. ๅผ€ๅง‹ๅŒๅ‘ๆถˆๆฏ้€šไฟก โ”‚
80
+ โ”‚ โ—€โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ–ถ โ”‚
81
+ โ”‚ โ”‚
82
+ ```
83
+
84
+ ### 4. ็ญพๅ้ชŒ่ฏ๏ผˆๅฏ้€‰ๅขžๅผบๅฎ‰ๅ…จ๏ผ‰
85
+
86
+ ```typescript
87
+ // ๅฎขๆˆท็ซฏ็”Ÿๆˆ็ญพๅ
88
+ function generateSignature(token: string, nonce: string): string {
89
+ return crypto.createHash("sha256")
90
+ .update(`${token}:${nonce}`)
91
+ .digest("hex");
92
+ }
93
+
94
+ // ็คบไพ‹
95
+ const token = "92527c1a...";
96
+ const nonce = "abc123def456";
97
+ const signature = sha256(token + ":" + nonce);
98
+ ```
99
+
100
+ ```go
101
+ // ๆœๅŠก็ซฏ้ชŒ่ฏ็ญพๅ
102
+ func verifySignature(token, nonce, signature string) bool {
103
+ h := sha256.New()
104
+ h.Write([]byte(token + ":" + nonce))
105
+ expected := hex.EncodeToString(h.Sum(nil))
106
+ return expected == signature
107
+ }
108
+ ```
109
+
110
+ ---
111
+
112
+ ## ๐Ÿ“ก WebSocket ๆถˆๆฏๅ่ฎฎ
113
+
114
+ ### ๅŸบ็ก€ๆถˆๆฏๆ ผๅผ
115
+
116
+ ๆ‰€ๆœ‰ WebSocket ๆถˆๆฏ้ƒฝ้ตๅพช็ปŸไธ€็š„ JSON ๆ ผๅผ๏ผš
117
+
118
+ ```typescript
119
+ interface WSMessage {
120
+ type: string; // ๆถˆๆฏ็ฑปๅž‹
121
+ requestId?: string; // ่ฏทๆฑ‚ID๏ผˆ็”จไบŽๅ…ณ่”่ฏทๆฑ‚/ๅ“ๅบ”๏ผ‰
122
+ payload?: any; // ๆถˆๆฏ่ฝฝ่ท
123
+ timestamp: number; // Unixๆฏซ็ง’ๆ—ถ้—ดๆˆณ
124
+ }
125
+ ```
126
+
127
+ ### ๆถˆๆฏ็ฑปๅž‹ไธ€่งˆ
128
+
129
+ | ็ฑปๅž‹ | ๆ–นๅ‘ | ่ฏดๆ˜Ž |
130
+ |------|------|------|
131
+ | `auth` | Client โ†’ Server | ่ฎค่ฏ่ฏทๆฑ‚ |
132
+ | `auth_result` | Server โ†’ Client | ่ฎค่ฏ็ป“ๆžœ |
133
+ | `ping` | Client โ†’ Server | ๅฟƒ่ทณ่ฏทๆฑ‚ |
134
+ | `pong` | Server โ†’ Client | ๅฟƒ่ทณๅ“ๅบ” |
135
+ | `inbound` | Server โ†’ Client | ็”จๆˆทๆถˆๆฏๆŽจ้€ |
136
+ | `outbound` | Client โ†’ Server | Bot ๅ›žๅคๆถˆๆฏ |
137
+ | `ack` | Server โ†’ Client | ๆถˆๆฏ็กฎ่ฎค |
138
+ | `error` | Server โ†’ Client | ้”™่ฏฏๆถˆๆฏ |
139
+ | `conv_history` | Client โ†’ Server | ่ฏทๆฑ‚ไผš่ฏๅކๅฒ |
140
+ | `conv_response` | Server โ†’ Client | ไผš่ฏๅކๅฒๅ“ๅบ” |
141
+
142
+ ---
143
+
144
+ ### ่ฏฆ็ป†ๆถˆๆฏๆ ผๅผ
145
+
146
+ #### 1. ่ฎค่ฏ่ฏทๆฑ‚ (auth)
147
+
148
+ **ๆ–นๅ‘**: Client โ†’ Server
149
+
150
+ ```json
151
+ {
152
+ "type": "auth",
153
+ "requestId": "req-1706951234567-abc123",
154
+ "payload": {
155
+ "token": "92527c1a861bb50bd1acc47180ef317369e97529c7a5491b2bc67839992cfbb8",
156
+ "nonce": "a1b2c3d4e5f6",
157
+ "signature": "sha256_hash_of_token_colon_nonce"
158
+ },
159
+ "timestamp": 1706951234567
160
+ }
161
+ ```
162
+
163
+ | ๅญ—ๆฎต | ็ฑปๅž‹ | ๅฟ…ๅกซ | ่ฏดๆ˜Ž |
164
+ |------|------|------|------|
165
+ | `token` | string | โœ… | ๅฎขๆˆท็ซฏ API Token |
166
+ | `nonce` | string | โŒ | ้šๆœบๆ•ฐ๏ผˆ็”จไบŽ็ญพๅ๏ผ‰ |
167
+ | `signature` | string | โŒ | HMAC-SHA256 ็ญพๅ |
168
+
169
+ #### 2. ่ฎค่ฏ็ป“ๆžœ (auth_result)
170
+
171
+ **ๆ–นๅ‘**: Server โ†’ Client
172
+
173
+ ```json
174
+ {
175
+ "type": "auth_result",
176
+ "requestId": "req-1706951234567-abc123",
177
+ "payload": {
178
+ "success": true,
179
+ "clientId": "client-abc123def456",
180
+ "message": "Authentication successful"
181
+ },
182
+ "timestamp": 1706951234890
183
+ }
184
+ ```
185
+
186
+ | ๅญ—ๆฎต | ็ฑปๅž‹ | ่ฏดๆ˜Ž |
187
+ |------|------|------|
188
+ | `success` | boolean | ่ฎค่ฏๆ˜ฏๅฆๆˆๅŠŸ |
189
+ | `clientId` | string | ๅˆ†้…็š„ๅฎขๆˆท็ซฏID |
190
+ | `message` | string | ็Šถๆ€ๆถˆๆฏ |
191
+
192
+ #### 3. ๅฟƒ่ทณ (ping/pong)
193
+
194
+ **ping** (Client โ†’ Server):
195
+ ```json
196
+ {
197
+ "type": "ping",
198
+ "requestId": "req-1706951234567-xyz",
199
+ "timestamp": 1706951234567
200
+ }
201
+ ```
202
+
203
+ **pong** (Server โ†’ Client):
204
+ ```json
205
+ {
206
+ "type": "pong",
207
+ "requestId": "req-1706951234567-xyz",
208
+ "timestamp": 1706951234890
209
+ }
210
+ ```
211
+
212
+ > ๐Ÿ’ก ๅปบ่ฎฎๅฟƒ่ทณ้—ด้š”๏ผš25-30 ็ง’
213
+
214
+ #### 4. ็”จๆˆทๆถˆๆฏๆŽจ้€ (inbound)
215
+
216
+ **ๆ–นๅ‘**: Server โ†’ Client
217
+
218
+ ๅฝ“ๆœ‰็”จๆˆทๅ‘้€ๆถˆๆฏๆ—ถ๏ผŒๆœๅŠกๅ™จๅฎžๆ—ถๆŽจ้€็ป™ๅฏนๅบ”ๅฎขๆˆท็ซฏ๏ผš
219
+
220
+ ```json
221
+ {
222
+ "type": "inbound",
223
+ "payload": {
224
+ "id": "msg-1",
225
+ "conversationId": "conv-abc123def456",
226
+ "clientId": "client-xyz789",
227
+ "from": "user123",
228
+ "to": "bot",
229
+ "text": "Hello, how are you?",
230
+ "timestamp": 1706951234567
231
+ },
232
+ "timestamp": 1706951234567
233
+ }
234
+ ```
235
+
236
+ #### 5. Bot ๅ›žๅคๆถˆๆฏ (outbound)
237
+
238
+ **ๆ–นๅ‘**: Client โ†’ Server
239
+
240
+ ```json
241
+ {
242
+ "type": "outbound",
243
+ "requestId": "req-1706951235000-reply",
244
+ "payload": {
245
+ "to": "user123",
246
+ "text": "I'm doing great! How can I help you today?",
247
+ "conversationId": "conv-abc123def456"
248
+ },
249
+ "timestamp": 1706951235000
250
+ }
251
+ ```
252
+
253
+ #### 6. ๆถˆๆฏ็กฎ่ฎค (ack)
254
+
255
+ **ๆ–นๅ‘**: Server โ†’ Client
256
+
257
+ ```json
258
+ {
259
+ "type": "ack",
260
+ "requestId": "req-1706951235000-reply",
261
+ "payload": {
262
+ "ok": true,
263
+ "message": {
264
+ "id": "msg-2",
265
+ "conversationId": "conv-abc123def456",
266
+ "clientId": "client-xyz789",
267
+ "from": "bot",
268
+ "to": "user123",
269
+ "text": "I'm doing great! How can I help you today?",
270
+ "timestamp": 1706951235123
271
+ }
272
+ },
273
+ "timestamp": 1706951235123
274
+ }
275
+ ```
276
+
277
+ #### 7. ้”™่ฏฏๆถˆๆฏ (error)
278
+
279
+ **ๆ–นๅ‘**: Server โ†’ Client
280
+
281
+ ```json
282
+ {
283
+ "type": "error",
284
+ "requestId": "req-xxx",
285
+ "payload": {
286
+ "error": "invalid_payload",
287
+ "message": "Missing required field: conversationId"
288
+ },
289
+ "timestamp": 1706951235000
290
+ }
291
+ ```
292
+
293
+ ๅธธ่ง้”™่ฏฏ็ ๏ผš
294
+
295
+ | ้”™่ฏฏ็  | ่ฏดๆ˜Ž |
296
+ |--------|------|
297
+ | `auth_timeout` | ่ฎค่ฏ่ถ…ๆ—ถ๏ผˆ30็ง’ๅ†…ๆœชๅ‘้€auth๏ผ‰ |
298
+ | `invalid_auth` | ้ฆ–ๆกๆถˆๆฏไธๆ˜ฏauth็ฑปๅž‹ |
299
+ | `invalid_token` | Token ๆ— ๆ•ˆ |
300
+ | `invalid_signature` | ็ญพๅ้ชŒ่ฏๅคฑ่ดฅ |
301
+ | `invalid_payload` | ๆถˆๆฏ่ฝฝ่ทๆ ผๅผ้”™่ฏฏ |
302
+ | `not_found` | ่ต„ๆบไธๅญ˜ๅœจ |
303
+
304
+ #### 8. ไผš่ฏๅކๅฒ่ฏทๆฑ‚/ๅ“ๅบ”
305
+
306
+ **่ฏทๆฑ‚** (Client โ†’ Server):
307
+ ```json
308
+ {
309
+ "type": "conv_history",
310
+ "requestId": "req-1706951236000-hist",
311
+ "payload": {
312
+ "conversationId": "conv-abc123def456"
313
+ },
314
+ "timestamp": 1706951236000
315
+ }
316
+ ```
317
+
318
+ **ๅ“ๅบ”** (Server โ†’ Client):
319
+ ```json
320
+ {
321
+ "type": "conv_response",
322
+ "requestId": "req-1706951236000-hist",
323
+ "payload": {
324
+ "id": "conv-abc123def456",
325
+ "userId": "user123",
326
+ "clientId": "client-xyz789",
327
+ "messages": [
328
+ {"id": "msg-1", "from": "user123", "text": "Hello", ...},
329
+ {"id": "msg-2", "from": "bot", "text": "Hi there!", ...}
330
+ ],
331
+ "createdAt": 1706951234000,
332
+ "updatedAt": 1706951235123
333
+ },
334
+ "timestamp": 1706951236123
335
+ }
336
+ ```
337
+
338
+ ---
339
+
340
+ ## ๐Ÿ“Š ๆ•ฐๆฎ็ป“ๆž„
341
+
342
+ ### Message๏ผˆๆถˆๆฏ๏ผ‰
343
+
344
+ ```typescript
345
+ interface Message {
346
+ id: string; // ๆถˆๆฏID๏ผŒๆ ผๅผ: "msg-{ๅบๅท}"
347
+ conversationId: string; // ไผš่ฏID๏ผŒๆ ผๅผ: "conv-{้šๆœบhex}"
348
+ clientId: string; // ๅฎขๆˆท็ซฏID๏ผŒๆ ผๅผ: "client-{้šๆœบhex}"
349
+ from: string; // ๅ‘้€่€…
350
+ to: string; // ๆŽฅๆ”ถ่€…
351
+ text: string; // ๆถˆๆฏๅ†…ๅฎน
352
+ timestamp: number; // Unixๆฏซ็ง’ๆ—ถ้—ดๆˆณ
353
+ }
354
+ ```
355
+
356
+ ### Conversation๏ผˆไผš่ฏ๏ผ‰
357
+
358
+ ```typescript
359
+ interface Conversation {
360
+ id: string; // ไผš่ฏID
361
+ userId: string; // ็”จๆˆทID
362
+ clientId: string; // ๅˆ†้…็š„ๅฎขๆˆท็ซฏID
363
+ messages: Message[];
364
+ createdAt: number;
365
+ updatedAt: number;
366
+ }
367
+ ```
368
+
369
+ ---
370
+
371
+ ## ๐ŸŒ HTTP API๏ผˆไฟ็•™๏ผ‰
372
+
373
+ ไปฅไธ‹ HTTP ๆŽฅๅฃไป็„ถๅฏ็”จ๏ผš
374
+
375
+ ### ๅ…ฌๅ…ฑ็ซฏ็‚น
376
+
377
+ | ๆ–นๆณ• | ่ทฏๅพ„ | ่ฏดๆ˜Ž |
378
+ |------|------|------|
379
+ | GET | `/health` | ๅฅๅบทๆฃ€ๆŸฅ |
380
+ | POST | `/inbound` | ๆจกๆ‹Ÿ็”จๆˆทๅ‘้€ๆถˆๆฏ๏ผˆไผš้€š่ฟ‡ WS ๆŽจ้€๏ผ‰ |
381
+ | GET | `/outbox` | ๆŸฅ็œ‹ๅทฒๅ‘้€็š„ๆถˆๆฏ |
382
+
383
+ ### ็ฎก็†็ซฏ็‚น๏ผˆ้œ€ Admin Token๏ผ‰
384
+
385
+ | ๆ–นๆณ• | ่ทฏๅพ„ | ่ฏดๆ˜Ž |
386
+ |------|------|------|
387
+ | POST | `/clients` | ๆณจๅ†Œๆ–ฐๅฎขๆˆท็ซฏ |
388
+ | GET | `/clients` | ๅˆ—ๅ‡บๆ‰€ๆœ‰ๅฎขๆˆท็ซฏ |
389
+ | GET | `/conversations` | ๅˆ—ๅ‡บๆ‰€ๆœ‰ไผš่ฏ |
390
+
391
+ ---
392
+
393
+ ## ๐Ÿ”„ ๅฎŒๆ•ด้€šไฟกๆต็จ‹
394
+
395
+ ```
396
+ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” POST /inbound โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” WebSocket โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
397
+ โ”‚ ็”จๆˆท็ซฏ โ”‚ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ถ โ”‚ Go Server โ”‚ โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ–ถ โ”‚ ๆ’ไปถ็ซฏ โ”‚
398
+ โ”‚ (ๆต่งˆๅ™จ) โ”‚ โ”‚ โ”‚ โ”‚ (OpenClaw) โ”‚
399
+ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ”‚ โ”‚
400
+ โ”‚ ๅฎžๆ—ถๆŽจ้€ โ”‚ โ”‚ โ”‚
401
+ โ”‚ inbound โ”‚ โ”‚ ๅค„็†ๆถˆๆฏ โ”‚
402
+ โ”‚ โ”‚ โ—€โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• โ”‚ โ”‚
403
+ โ”‚ โ”‚ outbound โ”‚ โ”‚
404
+ โ”‚ โ”‚ โ”‚ โ”‚
405
+ โ”‚ ่ฟ”ๅ›ž ack โ”‚ โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ–ถ โ”‚ โ”‚
406
+ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
407
+ ```
408
+
409
+ ---
410
+
411
+ ## ๐Ÿ› ๏ธ ้…็ฝฎ็คบไพ‹
412
+
413
+ ### ๆ’ไปถ็ซฏ้…็ฝฎ
414
+
415
+ ```typescript
416
+ {
417
+ serverUrl: "http://localhost:9876", // ไผš่‡ชๅŠจ่ฝฌๆขไธบ ws://localhost:9876/ws
418
+ apiToken: "your_client_token_here",
419
+ pollIntervalMs: 3000 // ไฝœไธบ้‡่ฟžๅปถ่ฟŸไฝฟ็”จ
420
+ }
421
+ ```
422
+
423
+ ### ็Žฏๅขƒๅ˜้‡
424
+
425
+ ```bash
426
+ SIMPLEGO_SERVER_URL=http://localhost:9876
427
+ SIMPLEGO_API_TOKEN=your_client_token
428
+ ```
429
+
430
+ ---
431
+
432
+ ## ๐Ÿš€ ๅฏๅŠจๆœๅŠก
433
+
434
+ ### Go Server
435
+
436
+ ```bash
437
+ cd server
438
+
439
+ # ๅฎ‰่ฃ…ไพ่ต–
440
+ go mod tidy
441
+
442
+ # ๅฏๅŠจๆœๅŠก
443
+ go run main.go -port 9876 -admin-token "your_admin_token"
444
+
445
+ # ๅฆ‚ๆžœไธๆŒ‡ๅฎš admin-token๏ผŒไผš่‡ชๅŠจ็”Ÿๆˆๅนถๆ‰“ๅฐๅˆฐๆŽงๅˆถๅฐ
446
+ ```
447
+
448
+ ### ๆณจๅ†Œๅฎขๆˆท็ซฏ
449
+
450
+ ```bash
451
+ # ไฝฟ็”จ admin token ๆณจๅ†Œๆ–ฐๅฎขๆˆท็ซฏ
452
+ curl -X POST http://localhost:9876/clients \
453
+ -H "Authorization: Bearer YOUR_ADMIN_TOKEN" \
454
+ -H "Content-Type: application/json" \
455
+ -d '{"name": "OpenClaw-Client-1"}'
456
+
457
+ # ่ฟ”ๅ›ž็คบไพ‹๏ผš
458
+ # {
459
+ # "clientId": "client-abc123",
460
+ # "token": "92527c1a861bb50bd1acc47180ef317369e97529c7a5491b2bc67839992cfbb8",
461
+ # "name": "OpenClaw-Client-1"
462
+ # }
463
+ ```
464
+
465
+ ---
466
+
467
+ ## ๐Ÿ“ ๆœ€ไฝณๅฎž่ทต
468
+
469
+ ### 1. ่ฟžๆŽฅ็ฎก็†
470
+
471
+ - ่ฟžๆŽฅๆ–ญๅผ€ๅŽ่‡ชๅŠจ้‡่ฟž๏ผˆๅปบ่ฎฎๅปถ่ฟŸ 3-5 ็ง’๏ผ‰
472
+ - ไฝฟ็”จๅฟƒ่ทณไฟๆŒ่ฟžๆŽฅๆดป่ทƒ๏ผˆ25-30 ็ง’้—ด้š”๏ผ‰
473
+ - ๅค„็†่ฎค่ฏ่ถ…ๆ—ถ๏ผˆ30 ็ง’ๅ†…ๅฟ…้กปๅฎŒๆˆ่ฎค่ฏ๏ผ‰
474
+
475
+ ### 2. ๅฎ‰ๅ…จๅปบ่ฎฎ
476
+
477
+ - ็”Ÿไบง็Žฏๅขƒไฝฟ็”จ WSS๏ผˆWebSocket Secure๏ผ‰
478
+ - ๅฏ็”จ็ญพๅ้ชŒ่ฏๅขžๅผบๅฎ‰ๅ…จๆ€ง
479
+ - ๅฎšๆœŸ่ฝฎๆข Token
480
+
481
+ ### 3. ้”™่ฏฏๅค„็†
482
+
483
+ - ็›‘ๅฌ `error` ็ฑปๅž‹ๆถˆๆฏ
484
+ - ไฝฟ็”จ `requestId` ๅ…ณ่”่ฏทๆฑ‚ๅ’Œๅ“ๅบ”
485
+ - ่ฎฐๅฝ•ๆ‰€ๆœ‰้”™่ฏฏๆ—ฅๅฟ—็”จไบŽๆŽ’ๆŸฅ
486
+
487
+ ---
488
+
489
+ ## ๐Ÿ“‹ ๆฃ€ๆŸฅๆธ…ๅ•
490
+
491
+ - [ ] Go Server ๅฏๅŠจๅนถๆ‰“ๅฐ admin token
492
+ - [ ] ไฝฟ็”จ admin token ๆณจๅ†Œๅฎขๆˆท็ซฏ่Žทๅ– client token
493
+ - [ ] ๆ’ไปถ้…็ฝฎๆญฃ็กฎ็š„ serverUrl ๅ’Œ apiToken
494
+ - [ ] WebSocket ่ฟžๆŽฅๆˆๅŠŸๅปบ็ซ‹
495
+ - [ ] ่ฎค่ฏๆต็จ‹้€š่ฟ‡
496
+ - [ ] ๅฟƒ่ทณไฟๆŒ่ฟžๆŽฅๆดป่ทƒ
497
+ - [ ] ๆถˆๆฏๆ”ถๅ‘ๆญฃๅธธ
498
+
499
+ ---
500
+
501
+ ## ๐Ÿ“š ็‰ˆๆœฌๅކๅฒ
502
+
503
+ | ็‰ˆๆœฌ | ๆ—ฅๆœŸ | ๅ˜ๆ›ด |
504
+ |------|------|------|
505
+ | 0.0.2 | 2026-02-05 | ๅ‡็บงไธบ WebSocket ๅ่ฎฎ |
506
+ | 0.0.1 | - | ๅˆๅง‹ HTTP ่ฝฎ่ฏข็‰ˆๆœฌ |
package/index.ts ADDED
@@ -0,0 +1,17 @@
1
+ import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
2
+ import { emptyPluginConfigSchema } from "openclaw/plugin-sdk";
3
+ import { simpleGoPlugin } from "./src/channel.js";
4
+ import { setSimpleGoRuntime } from "./src/runtime.js";
5
+
6
+ const plugin = {
7
+ id: "simplego",
8
+ name: "Simple Go",
9
+ description: "Demo channel plugin backed by a Go HTTP server",
10
+ configSchema: emptyPluginConfigSchema(),
11
+ register(api: OpenClawPluginApi) {
12
+ setSimpleGoRuntime(api.runtime);
13
+ api.registerChannel({ plugin: simpleGoPlugin });
14
+ },
15
+ };
16
+
17
+ export default plugin;
@@ -0,0 +1,22 @@
1
+ {
2
+ "id": "simplego",
3
+ "name": "@openclaw/simplego",
4
+ "version": "0.0.1",
5
+ "description": "OpenClaw demo channel plugin (Go HTTP backend)",
6
+ "configSchema": {
7
+ "type": "object",
8
+ "properties": {},
9
+ "additionalProperties": false
10
+ },
11
+ "extensions": [
12
+ "./index.ts"
13
+ ],
14
+ "channel": {
15
+ "id": "simplego",
16
+ "label": "Simple Go",
17
+ "selectionLabel": "Simple Go (demo)",
18
+ "docsPath": "/channels/simplego",
19
+ "blurb": "demo channel backed by a Go HTTP server.",
20
+ "order": 999
21
+ }
22
+ }
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "adp-openclaw",
3
+ "version": "0.0.2",
4
+ "description": "OpenClaw demo channel plugin (Go WebSocket backend)",
5
+ "type": "module",
6
+ "dependencies": {
7
+ "ws": "^8.16.0",
8
+ "zod": "^3.22.4"
9
+ },
10
+ "devDependencies": {
11
+ "@types/ws": "^8.5.10"
12
+ },
13
+ "openclaw": {
14
+ "extensions": [
15
+ "./index.ts"
16
+ ],
17
+ "channel": {
18
+ "id": "adp",
19
+ "label": "Simple Go",
20
+ "selectionLabel": "Simple Go (demo)",
21
+ "docsPath": "/channels/adp",
22
+ "blurb": "demo channel backed by a Go HTTP server.",
23
+ "order": 999
24
+ }
25
+ }
26
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(go run:*)",
5
+ "Bash(apt-get:*)",
6
+ "Bash(apt-get install:*)",
7
+ "Bash(yum install:*)",
8
+ "Bash(go version:*)",
9
+ "Bash(curl -OL https://go.dev/dl/go1.22.0.linux-amd64.tar.gz)",
10
+ "Bash(sudo rm -rf /usr/local/go)",
11
+ "Bash(sudo tar -C /usr/local -xzf go1.22.0.linux-amd64.tar.gz)",
12
+ "Bash(export PATH=$PATH:/usr/local/go/bin)",
13
+ "Bash(~/.bashrc)"
14
+ ]
15
+ }
16
+ }
package/server/go.mod ADDED
@@ -0,0 +1,5 @@
1
+ module simplego
2
+
3
+ go 1.21
4
+
5
+ require github.com/gorilla/websocket v1.5.1