@clawzone/clawzone 1.2.0 → 1.3.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.
Files changed (3) hide show
  1. package/index.ts +25 -14
  2. package/package.json +1 -1
  3. package/src/types.ts +9 -2
package/index.ts CHANGED
@@ -10,18 +10,29 @@ export default {
10
10
  const state = new MatchStateManager();
11
11
  let wsClient: ClawZoneWSClient | null = null;
12
12
 
13
+ const config = api.pluginConfig as { apiKey?: string; serverUrl?: string };
14
+
13
15
  // Background service: maintains WebSocket connection
14
- const { apiKey, serverUrl } = api.config;
15
- if (apiKey && serverUrl) {
16
- const wsProtocol = serverUrl.startsWith("https") ? "wss" : "ws";
17
- const host = serverUrl.replace(/^https?:\/\//, "");
18
- const wsUrl = `${wsProtocol}://${host}/api/v1/ws?api_key=${apiKey}`;
16
+ api.registerService({
17
+ id: "clawzone-ws",
18
+ start: () => {
19
+ const { apiKey, serverUrl } = config;
20
+ if (!apiKey || !serverUrl) {
21
+ api.logger.warn("ClawZone plugin: missing apiKey or serverUrl in config");
22
+ return;
23
+ }
24
+
25
+ const wsProtocol = serverUrl.startsWith("https") ? "wss" : "ws";
26
+ const host = serverUrl.replace(/^https?:\/\//, "");
27
+ const wsUrl = `${wsProtocol}://${host}/api/v1/ws?api_key=${apiKey}`;
19
28
 
20
- wsClient = new ClawZoneWSClient(wsUrl, state, api.logger);
21
- wsClient.connect();
22
- } else {
23
- api.logger.warn("ClawZone plugin: missing apiKey or serverUrl in config");
24
- }
29
+ wsClient = new ClawZoneWSClient(wsUrl, state, api.logger);
30
+ wsClient.connect();
31
+ },
32
+ stop: () => {
33
+ wsClient?.disconnect();
34
+ },
35
+ });
25
36
 
26
37
  // Tool: List available games
27
38
  api.registerTool({
@@ -30,7 +41,7 @@ export default {
30
41
  "List all available games on ClawZone with their rules and settings",
31
42
  parameters: { type: "object", properties: {} },
32
43
  execute: async () => {
33
- const res = await fetch(`${api.config.serverUrl}/api/v1/games`);
44
+ const res = await fetch(`${config.serverUrl}/api/v1/games`);
34
45
  const data = await res.json();
35
46
  return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
36
47
  },
@@ -52,7 +63,7 @@ export default {
52
63
  },
53
64
  },
54
65
  execute: async (_id: string, params: Record<string, unknown>) => {
55
- const { serverUrl, apiKey } = api.config;
66
+ const { serverUrl, apiKey } = config;
56
67
 
57
68
  // Join queue via REST
58
69
  const joinRes = await fetch(`${serverUrl}/api/v1/matchmaking/join`, {
@@ -207,7 +218,7 @@ export default {
207
218
  }
208
219
 
209
220
  // Fallback: REST
210
- const { serverUrl, apiKey } = api.config;
221
+ const { serverUrl, apiKey } = config;
211
222
  const res = await fetch(
212
223
  `${serverUrl}/api/v1/matches/${matchId}/actions`,
213
224
  {
@@ -258,7 +269,7 @@ export default {
258
269
  },
259
270
  },
260
271
  execute: async (_id: string, params: Record<string, unknown>) => {
261
- const { serverUrl, apiKey } = api.config;
272
+ const { serverUrl, apiKey } = config;
262
273
  const res = await fetch(`${serverUrl}/api/v1/matchmaking/leave`, {
263
274
  method: "DELETE",
264
275
  headers: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clawzone/clawzone",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "OpenClaw plugin for ClawZone — real-time competitive AI gaming via WebSocket",
5
5
  "main": "index.ts",
6
6
  "openclaw": {
package/src/types.ts CHANGED
@@ -130,12 +130,19 @@ export interface ToolResult {
130
130
  }
131
131
 
132
132
  export interface PluginAPI {
133
- config: PluginConfig;
133
+ pluginConfig: Record<string, unknown>;
134
134
  logger: Logger;
135
135
  registerTool(tool: {
136
136
  name: string;
137
137
  description: string;
138
138
  parameters: Record<string, unknown>;
139
- execute: (id: string, params: Record<string, unknown>) => Promise<ToolResult>;
139
+ execute: (...args: unknown[]) => Promise<ToolResult>;
140
140
  }): void;
141
+ registerService(service: {
142
+ id: string;
143
+ start: () => void;
144
+ stop: () => void;
145
+ }): void;
146
+ registerCommand?(command: Record<string, unknown>): void;
147
+ on?(event: string, handler: (...args: unknown[]) => void): void;
141
148
  }