@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.
- package/index.ts +25 -14
- package/package.json +1 -1
- 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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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(`${
|
|
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 } =
|
|
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 } =
|
|
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 } =
|
|
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
package/src/types.ts
CHANGED
|
@@ -130,12 +130,19 @@ export interface ToolResult {
|
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
export interface PluginAPI {
|
|
133
|
-
|
|
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: (
|
|
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
|
}
|