@clawchatsai/connector 0.0.99 → 0.1.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.
package/dist/index.js CHANGED
@@ -18,6 +18,10 @@ import { dispatchRpc } from './shim.js';
18
18
  import { initAuth, handleAuthMessage, cleanupAuth } from './auth-handler.js';
19
19
  import { generateTotpSecret, verifyTotp, generateBackupCodes, buildOtpauthUri } from './totp.js';
20
20
  import { generateSessionSecret } from './session-token.js';
21
+ import { fileURLToPath } from 'node:url';
22
+ // ESM __dirname polyfill (package.json has "type":"module")
23
+ const __filename = fileURLToPath(import.meta.url);
24
+ const __dirname = path.dirname(__filename);
21
25
  // Inline from shared/api-version.ts to avoid rootDir conflict
22
26
  const CURRENT_API_VERSION = 1;
23
27
  export const PLUGIN_ID = 'connector';
@@ -45,7 +49,7 @@ let _uploadsDir = null;
45
49
  // ---------------------------------------------------------------------------
46
50
  // Config helpers
47
51
  // ---------------------------------------------------------------------------
48
- const CONFIG_DIR = path.join(process.env.HOME || '/root', '.openclaw', 'clawchats');
52
+ const CONFIG_DIR = path.join(os.homedir(), '.openclaw', 'clawchats');
49
53
  const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json');
50
54
  const RUNTIME_FILE = path.join(CONFIG_DIR, 'runtime.json');
51
55
  function loadConfig() {
@@ -267,12 +271,7 @@ async function startClawChats(ctx, api, mediaStash) {
267
271
  }
268
272
  });
269
273
  // 5. Connect to signaling server
270
- const _hostname = (() => { try {
271
- return require('os').hostname();
272
- }
273
- catch {
274
- return undefined;
275
- } })();
274
+ const _hostname = os.hostname();
276
275
  signaling = new SignalingClient(config.serverUrl, config.userId, config.apiKey, {
277
276
  gatewayId: config.gatewayId,
278
277
  hostname: _hostname,
@@ -811,7 +810,7 @@ async function handleSetup(token, options = {}) {
811
810
  // Read gateway token from OpenClaw config
812
811
  let gatewayToken = '';
813
812
  try {
814
- const openclawConfigPath = path.join(process.env.HOME || '/root', '.openclaw', 'openclaw.json');
813
+ const openclawConfigPath = path.join(os.homedir(), '.openclaw', 'openclaw.json');
815
814
  const openclawConfig = JSON.parse(fs.readFileSync(openclawConfigPath, 'utf8'));
816
815
  gatewayToken = openclawConfig.gateway?.auth?.token || openclawConfig.auth?.token || openclawConfig.token || '';
817
816
  }
@@ -833,12 +832,7 @@ async function handleSetup(token, options = {}) {
833
832
  reject(new Error('Setup timed out'));
834
833
  }, 30_000);
835
834
  ws.on('open', () => {
836
- const setupHostname = (() => { try {
837
- return require('os').hostname();
838
- }
839
- catch {
840
- return undefined;
841
- } })();
835
+ const setupHostname = os.hostname();
842
836
  ws.send(JSON.stringify({
843
837
  type: 'setup',
844
838
  setupSecret: tokenData.setupSecret,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clawchatsai/connector",
3
- "version": "0.0.99",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "description": "ClawChats OpenClaw plugin — P2P tunnel + local API bridge",
6
6
  "main": "dist/index.js",
package/server/index.js CHANGED
@@ -22,6 +22,7 @@ import { handleStatic } from './controllers/static.js';
22
22
  import { handleAgents } from './controllers/agents.js';
23
23
  import { createSettingsHandlers } from './controllers/settings.js';
24
24
  import { createWorkspaceStore } from './store/workspace-store.js';
25
+ import { cleanGatewaySession } from './gateway-cleanup.js';
25
26
  import { parseSessionKey } from './util/helpers.js';
26
27
  import { send, sendError, parseBody, uuid, matchRoute, setCors } from './util/http.js';
27
28
 
@@ -241,6 +242,13 @@ export function createApp(config = {}) {
241
242
  return send(res, 200, { ok: true });
242
243
  }
243
244
 
245
+ if (method === 'POST' && urlPath === '/api/incognito/cleanup') {
246
+ const { sessionKey, threadId } = await parseBody(req);
247
+ if (sessionKey) cleanGatewaySession(sessionKey);
248
+ if (threadId) { try { fs.rmSync(path.join(UPLOADS_DIR, threadId), { recursive: true }); } catch { /* ok */ } }
249
+ return send(res, 200, { ok: true });
250
+ }
251
+
244
252
  sendError(res, 404, `Not found: ${method} ${urlPath}`);
245
253
  } catch (err) {
246
254
  console.error(`Error handling ${method} ${urlPath}:`, err);