@tinyclaw/plugin-channel-friends 2.0.0-patch.ac44432 → 2.0.0-patch.cfae164

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
@@ -19,13 +19,13 @@
19
19
  *
20
20
  * userId format: "friend:<username>"
21
21
  */
22
- import { readFileSync } from 'node:fs';
23
- import { dirname, join } from 'node:path';
24
- import { fileURLToPath } from 'node:url';
22
+ import { readFileSync } from 'fs';
23
+ import { join, dirname } from 'path';
24
+ import { fileURLToPath } from 'url';
25
25
  import { logger } from '@tinyclaw/logger';
26
- import { createFriendsServer } from './server.js';
27
26
  import { InviteStore } from './store.js';
28
- import { createFriendsTools, FRIENDS_ENABLED_CONFIG_KEY, FRIENDS_PLUGIN_ID, FRIENDS_PORT_CONFIG_KEY, } from './tools.js';
27
+ import { createFriendsTools, FRIENDS_ENABLED_CONFIG_KEY, FRIENDS_PORT_CONFIG_KEY, FRIENDS_PLUGIN_ID, } from './tools.js';
28
+ import { createFriendsServer } from './server.js';
29
29
  // Resolve the directory of this source file for static asset paths
30
30
  const __filename = fileURLToPath(import.meta.url);
31
31
  const __dirname = dirname(__filename);
package/dist/server.js CHANGED
@@ -66,7 +66,7 @@ function authenticateFriend(request, store) {
66
66
  }
67
67
  export function createFriendsServer(config) {
68
68
  const { port, host, store, chatHtml, onMessage, onMessageStream } = config;
69
- const secure = config.secure ?? process.env.NODE_ENV === 'production';
69
+ const secure = config.secure ?? (process.env.NODE_ENV === 'production');
70
70
  const textEncoder = new TextEncoder();
71
71
  const pushClients = new Map();
72
72
  let server = null;
@@ -182,7 +182,7 @@ export function createFriendsServer(config) {
182
182
  if (!pushClients.has(username)) {
183
183
  pushClients.set(username, new Set());
184
184
  }
185
- pushClients.get(username)?.add(pushClient);
185
+ pushClients.get(username).add(pushClient);
186
186
  // Heartbeat to keep connection alive
187
187
  const heartbeat = setInterval(() => {
188
188
  try {
@@ -254,7 +254,9 @@ export function createFriendsServer(config) {
254
254
  if (isClosed)
255
255
  return;
256
256
  try {
257
- const data = typeof payload === 'string' ? payload : JSON.stringify(payload);
257
+ const data = typeof payload === 'string'
258
+ ? payload
259
+ : JSON.stringify(payload);
258
260
  controller.enqueue(textEncoder.encode(`data: ${data}\n\n`));
259
261
  if (typeof payload === 'object' &&
260
262
  payload &&
@@ -350,7 +352,7 @@ export function createFriendsServer(config) {
350
352
  for (const dc of dead) {
351
353
  clients.delete(dc);
352
354
  }
353
- return clients.size > 0 || dead.length < clients.size + dead.length;
355
+ return clients.size > 0 || dead.length < (clients.size + dead.length);
354
356
  },
355
357
  getPort() {
356
358
  return server?.port || port;
package/dist/store.js CHANGED
@@ -131,19 +131,13 @@ export class InviteStore {
131
131
  return null;
132
132
  const newCode = generateInviteCode();
133
133
  // New code, clear session so they must re-authenticate
134
- this.db.run(`UPDATE friends SET invite_code = ?, session_token = NULL WHERE username = ?`, [
135
- newCode,
136
- sanitized,
137
- ]);
134
+ this.db.run(`UPDATE friends SET invite_code = ?, session_token = NULL WHERE username = ?`, [newCode, sanitized]);
138
135
  return newCode;
139
136
  }
140
137
  /** Update a friend's nickname. */
141
138
  updateNickname(username, newNickname) {
142
139
  const sanitized = username.toLowerCase().replace(/[^a-z0-9_]/g, '_');
143
- const result = this.db.run(`UPDATE friends SET nickname = ? WHERE username = ?`, [
144
- newNickname,
145
- sanitized,
146
- ]);
140
+ const result = this.db.run(`UPDATE friends SET nickname = ? WHERE username = ?`, [newNickname, sanitized]);
147
141
  return result.changes > 0;
148
142
  }
149
143
  /** Touch last_seen timestamp. */
@@ -168,7 +162,9 @@ export class InviteStore {
168
162
  /** Check if a username already exists. */
169
163
  exists(username) {
170
164
  const sanitized = username.toLowerCase().replace(/[^a-z0-9_]/g, '_');
171
- const row = this.db.query(`SELECT 1 FROM friends WHERE username = ?`).get(sanitized);
165
+ const row = this.db
166
+ .query(`SELECT 1 FROM friends WHERE username = ?`)
167
+ .get(sanitized);
172
168
  return row !== null;
173
169
  }
174
170
  rowToFriend(row) {
package/dist/tools.d.ts CHANGED
@@ -7,8 +7,8 @@
7
7
  *
8
8
  * All tools are owner-only (checked by the agent loop's authority system).
9
9
  */
10
- import type { ConfigManagerInterface, Tool } from '@tinyclaw/types';
11
- import type { InviteStore } from './store.js';
10
+ import type { Tool, ConfigManagerInterface } from '@tinyclaw/types';
11
+ import { InviteStore } from './store.js';
12
12
  /** Config key for the enabled flag. */
13
13
  export declare const FRIENDS_ENABLED_CONFIG_KEY = "channels.friends.enabled";
14
14
  /** Config key for the plugin server port. */
package/dist/tools.js CHANGED
@@ -104,7 +104,7 @@ export function createFriendsTools(store, configManager) {
104
104
  },
105
105
  {
106
106
  name: 'friends_chat_revoke',
107
- description: "Revoke a friend's access to the Friends Web Chat. " +
107
+ description: 'Revoke a friend\'s access to the Friends Web Chat. ' +
108
108
  'Their session and any pending invite code are invalidated immediately. ' +
109
109
  'To restore access later, use friends_chat_reinvite.',
110
110
  parameters: {
@@ -148,11 +148,13 @@ export function createFriendsTools(store, configManager) {
148
148
  return 'No friends registered yet. Use friends_chat_invite to invite someone.';
149
149
  }
150
150
  const lines = friends.map((f) => {
151
- const status = f.sessionToken ? 'active' : f.inviteCode ? 'invite pending' : 'revoked';
151
+ const status = f.sessionToken
152
+ ? 'active'
153
+ : f.inviteCode
154
+ ? 'invite pending'
155
+ : 'revoked';
152
156
  const lastSeenDate = new Date(f.lastSeen);
153
- const lastSeen = f.lastSeen && !Number.isNaN(lastSeenDate.getTime())
154
- ? lastSeenDate.toLocaleString()
155
- : 'Unknown';
157
+ const lastSeen = f.lastSeen && !isNaN(lastSeenDate.getTime()) ? lastSeenDate.toLocaleString() : 'Unknown';
156
158
  return `- **${f.nickname}** (@${f.username}) — ${status}, last seen: ${lastSeen}`;
157
159
  });
158
160
  return `**Registered Friends (${friends.length})**\n\n${lines.join('\n')}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinyclaw/plugin-channel-friends",
3
- "version": "2.0.0-patch.ac44432",
3
+ "version": "2.0.0-patch.cfae164",
4
4
  "description": "Friends web chat channel plugin for Tiny Claw",
5
5
  "license": "GPL-3.0",
6
6
  "author": "Waren Gonzaga",