chitin-openclaw-plugin 0.3.0 → 0.3.1

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 (2) hide show
  1. package/dist/index.js +39 -21
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -127,6 +127,7 @@ function connectToTable(gameServerUrl, roomCode, playerId, name, walletAddress,
127
127
  ws?.close();
128
128
  };
129
129
  }
130
+ var otelInitialized = false;
130
131
  var plugin = {
131
132
  id: "chitin-openclaw-plugin",
132
133
  name: "Chitin Casino",
@@ -139,7 +140,8 @@ var plugin = {
139
140
  register(api) {
140
141
  api.logger.info("[chitin] Chitin Casino plugin loaded");
141
142
  let tracer = trace.getTracer("chitin-plugin");
142
- try {
143
+ if (!otelInitialized) try {
144
+ otelInitialized = true;
143
145
  const endpoint = process.env.OTEL_EXPORTER_OTLP_ENDPOINT;
144
146
  const headers = process.env.OTEL_EXPORTER_OTLP_HEADERS;
145
147
  if (endpoint) {
@@ -173,6 +175,22 @@ var plugin = {
173
175
  } catch (err) {
174
176
  api.logger.warn(`[chitin] OTel init failed (non-fatal): ${err.message}`);
175
177
  }
178
+ function withSpan(spanName, attrs, fn) {
179
+ const span = tracer.startSpan(spanName, { attributes: attrs });
180
+ return fn().then(
181
+ (result) => {
182
+ span.setStatus({ code: SpanStatusCode.OK });
183
+ span.end();
184
+ return result;
185
+ },
186
+ (err) => {
187
+ span.setStatus({ code: SpanStatusCode.ERROR, message: err.message });
188
+ span.recordException(err);
189
+ span.end();
190
+ throw err;
191
+ }
192
+ );
193
+ }
176
194
  const gameServerUrl = process.env.GAME_SERVER_URL || "http://localhost:3665";
177
195
  const adminServerUrl = process.env.ADMIN_SERVER_URL || "http://localhost:3667";
178
196
  const activeConnections = /* @__PURE__ */ new Map();
@@ -181,11 +199,11 @@ var plugin = {
181
199
  name: "chitin_wallet_address",
182
200
  description: "Get your Chitin Casino wallet address",
183
201
  parameters: {},
184
- execute: async () => {
202
+ execute: async () => withSpan("plugin.tool.wallet_address", {}, async () => {
185
203
  const { account } = getWalletClients();
186
204
  api.logger.info(`[chitin] wallet_address: ${account.address}`);
187
205
  return { address: account.address };
188
- }
206
+ })
189
207
  });
190
208
  api.registerTool({
191
209
  name: "chitin_wallet_balance",
@@ -196,7 +214,7 @@ var plugin = {
196
214
  tokenAddress: { type: "string", description: "Token address (auto-fetched if omitted)" }
197
215
  }
198
216
  },
199
- execute: async (_toolCallId, params) => {
217
+ execute: async (_toolCallId, params) => withSpan("plugin.tool.wallet_balance", {}, async () => {
200
218
  const { account, publicClient } = getWalletClients();
201
219
  api.logger.info(`[chitin] wallet_balance: checking ${account.address}`);
202
220
  const ethBalance = await publicClient.getBalance({ address: account.address });
@@ -227,13 +245,13 @@ var plugin = {
227
245
  ethBalance: formatEther(ethBalance),
228
246
  tokenBalance: formatEther(tokenBalance)
229
247
  };
230
- }
248
+ })
231
249
  });
232
250
  api.registerTool({
233
251
  name: "chitin_faucet_claim",
234
252
  description: "Claim NUMERO tokens from the faucet. Free \u2014 no gas needed.",
235
253
  parameters: {},
236
- execute: async () => {
254
+ execute: async () => withSpan("plugin.tool.faucet_claim", {}, async () => {
237
255
  const { account } = getWalletClients();
238
256
  api.logger.info(`[chitin] faucet_claim: wallet=${account.address} server=${adminServerUrl}`);
239
257
  const res = await fetch(`${adminServerUrl}/faucet/claim`, {
@@ -245,7 +263,7 @@ var plugin = {
245
263
  api.logger.info(`[chitin] faucet_claim: status=${res.status} response=${JSON.stringify(data)}`);
246
264
  if (!res.ok) throw new Error(data.error || "Faucet claim failed");
247
265
  return data;
248
- }
266
+ })
249
267
  });
250
268
  api.registerTool({
251
269
  name: "chitin_deposit",
@@ -259,7 +277,7 @@ var plugin = {
259
277
  },
260
278
  required: ["amount", "tableId", "gameId"]
261
279
  },
262
- execute: async (_toolCallId, params) => {
280
+ execute: async (_toolCallId, params) => withSpan("plugin.tool.deposit", { "deposit.amount": params.amount, "deposit.table_id": params.tableId }, async () => {
263
281
  api.logger.info(`[chitin] deposit: amount=${params.amount} tableId=${params.tableId} gameId=${params.gameId}`);
264
282
  const { publicClient, walletClient } = getWalletClients();
265
283
  api.logger.info(`[chitin] deposit: fetching contracts from ${gameServerUrl}/contracts`);
@@ -282,31 +300,31 @@ var plugin = {
282
300
  const receipt = await publicClient.waitForTransactionReceipt({ hash });
283
301
  api.logger.info(`[chitin] deposit: confirmed block=${receipt.blockNumber} status=${receipt.status}`);
284
302
  return { txHash: hash, blockNumber: Number(receipt.blockNumber) };
285
- }
303
+ })
286
304
  });
287
305
  api.registerTool({
288
306
  name: "chitin_discover",
289
307
  description: "Discover Chitin Casino \u2014 games, contracts, faucet info",
290
308
  parameters: {},
291
- execute: async () => {
309
+ execute: async () => withSpan("plugin.tool.discover", {}, async () => {
292
310
  api.logger.info(`[chitin] discover: ${gameServerUrl}/discover`);
293
311
  const res = await fetch(`${gameServerUrl}/discover`);
294
312
  const data = await res.json();
295
313
  api.logger.info(`[chitin] discover: status=${res.status}`);
296
314
  return data;
297
- }
315
+ })
298
316
  });
299
317
  api.registerTool({
300
318
  name: "chitin_lobby",
301
319
  description: "List poker tables with open seats",
302
320
  parameters: {},
303
- execute: async () => {
321
+ execute: async () => withSpan("plugin.tool.lobby", {}, async () => {
304
322
  api.logger.info(`[chitin] lobby: ${gameServerUrl}/parties/pokerlobby/main/tables`);
305
323
  const res = await fetch(`${gameServerUrl}/parties/pokerlobby/main/tables`);
306
324
  const data = await res.json();
307
325
  api.logger.info(`[chitin] lobby: status=${res.status} tables=${Array.isArray(data) ? data.length : "?"}`);
308
326
  return data;
309
- }
327
+ })
310
328
  });
311
329
  api.registerTool({
312
330
  name: "chitin_create_table",
@@ -320,7 +338,7 @@ var plugin = {
320
338
  maxBuyIn: { type: "number" }
321
339
  }
322
340
  },
323
- execute: async (_toolCallId, params) => {
341
+ execute: async (_toolCallId, params) => withSpan("plugin.tool.create_table", {}, async () => {
324
342
  const settings = {
325
343
  smallBlind: params.smallBlind || 1,
326
344
  bigBlind: params.bigBlind || 2,
@@ -336,7 +354,7 @@ var plugin = {
336
354
  const data = await res.json();
337
355
  api.logger.info(`[chitin] create_table: status=${res.status} response=${JSON.stringify(data)}`);
338
356
  return data;
339
- }
357
+ })
340
358
  });
341
359
  api.registerTool({
342
360
  name: "chitin_register",
@@ -350,7 +368,7 @@ var plugin = {
350
368
  },
351
369
  required: ["roomCode"]
352
370
  },
353
- execute: async (_toolCallId, params) => {
371
+ execute: async (_toolCallId, params) => withSpan("plugin.tool.register", { "register.room": params.roomCode }, async () => {
354
372
  const { account } = getWalletClients();
355
373
  const botName = params.name || "ClawBot";
356
374
  api.logger.info(`[chitin] register: room=${params.roomCode} name=${botName} buyIn=${params.buyIn || 200} wallet=${account.address}`);
@@ -377,7 +395,7 @@ var plugin = {
377
395
  );
378
396
  activeConnections.set(params.roomCode, { cleanup });
379
397
  return { ...result, wsConnected: true };
380
- }
398
+ })
381
399
  });
382
400
  api.registerTool({
383
401
  name: "chitin_poker_action",
@@ -391,7 +409,7 @@ var plugin = {
391
409
  },
392
410
  required: ["roomCode", "action"]
393
411
  },
394
- execute: async (_toolCallId, params) => {
412
+ execute: async (_toolCallId, params) => withSpan("plugin.tool.poker_action", { "action.room": params.roomCode, "action.type": params.action, "action.amount": params.amount ?? 0 }, async () => {
395
413
  api.logger.info(`[chitin] poker_action: room=${params.roomCode} action=${params.action} amount=${params.amount ?? "n/a"}`);
396
414
  const ws = wsInstances.get(params.roomCode);
397
415
  if (!ws || ws.readyState !== WebSocket.OPEN) {
@@ -403,7 +421,7 @@ var plugin = {
403
421
  ws.send(JSON.stringify({ type: "action", action }));
404
422
  api.logger.info(`[chitin] poker_action: sent ${JSON.stringify(action)}`);
405
423
  return { ok: true, sent: action };
406
- }
424
+ })
407
425
  });
408
426
  api.registerTool({
409
427
  name: "chitin_leave_table",
@@ -416,7 +434,7 @@ var plugin = {
416
434
  },
417
435
  required: ["roomCode", "token"]
418
436
  },
419
- execute: async (_toolCallId, params) => {
437
+ execute: async (_toolCallId, params) => withSpan("plugin.tool.leave_table", { "leave.room": params.roomCode }, async () => {
420
438
  api.logger.info(`[chitin] leave_table: room=${params.roomCode}`);
421
439
  const ws = wsInstances.get(params.roomCode);
422
440
  if (ws?.readyState === WebSocket.OPEN) {
@@ -438,7 +456,7 @@ var plugin = {
438
456
  return await res.json();
439
457
  }
440
458
  return { ok: true };
441
- }
459
+ })
442
460
  });
443
461
  }
444
462
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chitin-openclaw-plugin",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "OpenClaw plugin for Chitin Casino — wallet management and poker game connection",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",