@occum-net/occumclaw 0.1.0 → 0.2.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 (2) hide show
  1. package/index.ts +58 -1
  2. package/package.json +4 -2
package/index.ts CHANGED
@@ -19,6 +19,37 @@
19
19
  import { OccumWsClient, type OccumEvent, type AuthOkData } from "./ws-client";
20
20
  import { apiRequest, type ToolConfig } from "./api";
21
21
  import { createSendMessageTool, createListChannelsTool, createGetEventsTool } from "./tools";
22
+ import { readFileSync } from "node:fs";
23
+ import { resolve, dirname } from "node:path";
24
+ import { fileURLToPath } from "node:url";
25
+
26
+ // Read own version from package.json at load time
27
+ const PLUGIN_VERSION = (() => {
28
+ try {
29
+ const dir = typeof __dirname !== "undefined" ? __dirname : dirname(fileURLToPath(import.meta.url));
30
+ const pkg = JSON.parse(readFileSync(resolve(dir, "package.json"), "utf-8"));
31
+ return pkg.version as string;
32
+ } catch {
33
+ return "unknown";
34
+ }
35
+ })();
36
+
37
+ const NPM_PACKAGE = "@occum-net/occumclaw";
38
+
39
+ /** Check npm registry for latest version; returns null on failure. */
40
+ async function checkLatestVersion(): Promise<string | null> {
41
+ try {
42
+ const res = await fetch(`https://registry.npmjs.org/${NPM_PACKAGE}/latest`, {
43
+ headers: { Accept: "application/json" },
44
+ signal: AbortSignal.timeout(5000),
45
+ });
46
+ if (!res.ok) return null;
47
+ const data = await res.json() as { version?: string };
48
+ return data.version ?? null;
49
+ } catch {
50
+ return null;
51
+ }
52
+ }
22
53
 
23
54
  // ─── OpenClaw Plugin SDK types (inline to avoid hard dependency) ────────────
24
55
 
@@ -262,7 +293,7 @@ function createOccumChannelPlugin(logger: PluginLogger) {
262
293
  agentToken: account.agentToken,
263
294
  log: (msg) => log?.info?.(`[ws] ${msg}`),
264
295
 
265
- onConnected: (data: AuthOkData) => {
296
+ onConnected: async (data: AuthOkData) => {
266
297
  agentId = data.agentId;
267
298
  log?.info?.(`Authenticated as agent ${data.agentId}`);
268
299
  log?.info?.(`Subscribed to ${data.channels.length} channel(s)`);
@@ -273,6 +304,32 @@ function createOccumChannelPlugin(logger: PluginLogger) {
273
304
  running: true,
274
305
  connected: true,
275
306
  });
307
+
308
+ // Send a greeting to the control channel on connect
309
+ if (controlChannelId) {
310
+ try {
311
+ await apiRequest(config, `/channels/${controlChannelId}/messages`, {
312
+ method: "POST",
313
+ body: JSON.stringify({ text: `Connected (v${PLUGIN_VERSION})` }),
314
+ });
315
+ log?.info?.(`[occum] Sent connect greeting to #${controlChannelId}`);
316
+ } catch (err) {
317
+ log?.warn?.(`[occum] Failed to send connect greeting: ${err}`);
318
+ }
319
+ }
320
+
321
+ // Check for updates in the background
322
+ checkLatestVersion().then((latest) => {
323
+ if (!latest || latest === PLUGIN_VERSION) return;
324
+ const msg = `Update available: v${PLUGIN_VERSION} → v${latest}. Run: openclaw plugins install ${NPM_PACKAGE}`;
325
+ log?.warn?.(msg);
326
+ if (controlChannelId) {
327
+ apiRequest(config, `/channels/${controlChannelId}/messages`, {
328
+ method: "POST",
329
+ body: JSON.stringify({ text: msg }),
330
+ }).catch(() => {});
331
+ }
332
+ });
276
333
  },
277
334
 
278
335
  onEvent: (event: OccumEvent) => {
package/package.json CHANGED
@@ -1,13 +1,15 @@
1
1
  {
2
2
  "name": "@occum-net/occumclaw",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
7
  "description": "OpenClaw plugin that connects to occum.net for bidirectional agent communication via WebSocket",
8
8
  "type": "module",
9
9
  "openclaw": {
10
- "extensions": ["./index.ts"]
10
+ "extensions": [
11
+ "./index.ts"
12
+ ]
11
13
  },
12
14
  "dependencies": {},
13
15
  "files": [