@tinyclaw/plugin-channel-friends 2.0.0-staging.a343b3d → 2.0.0-staging.aecdd41

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 'fs';
23
- import { join, dirname } from 'path';
24
- import { fileURLToPath } from 'url';
22
+ import { readFileSync } from 'node:fs';
23
+ import { dirname, join } from 'node:path';
24
+ import { fileURLToPath } from 'node:url';
25
25
  import { logger } from '@tinyclaw/logger';
26
- import { InviteStore } from './store.js';
27
- import { createFriendsTools, FRIENDS_ENABLED_CONFIG_KEY, FRIENDS_PORT_CONFIG_KEY, FRIENDS_PLUGIN_ID, } from './tools.js';
28
26
  import { createFriendsServer } from './server.js';
27
+ import { InviteStore } from './store.js';
28
+ import { createFriendsTools, FRIENDS_ENABLED_CONFIG_KEY, FRIENDS_PLUGIN_ID, FRIENDS_PORT_CONFIG_KEY, } from './tools.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,8 @@ 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
+ const clients = pushClients.get(username);
186
+ clients.add(pushClient);
186
187
  // Heartbeat to keep connection alive
187
188
  const heartbeat = setInterval(() => {
188
189
  try {
@@ -254,9 +255,7 @@ export function createFriendsServer(config) {
254
255
  if (isClosed)
255
256
  return;
256
257
  try {
257
- const data = typeof payload === 'string'
258
- ? payload
259
- : JSON.stringify(payload);
258
+ const data = typeof payload === 'string' ? payload : JSON.stringify(payload);
260
259
  controller.enqueue(textEncoder.encode(`data: ${data}\n\n`));
261
260
  if (typeof payload === 'object' &&
262
261
  payload &&
@@ -352,7 +351,7 @@ export function createFriendsServer(config) {
352
351
  for (const dc of dead) {
353
352
  clients.delete(dc);
354
353
  }
355
- return clients.size > 0 || dead.length < (clients.size + dead.length);
354
+ return clients.size > 0 || dead.length < clients.size + dead.length;
356
355
  },
357
356
  getPort() {
358
357
  return server?.port || port;
package/dist/store.js CHANGED
@@ -131,13 +131,19 @@ 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 = ?`, [newCode, sanitized]);
134
+ this.db.run(`UPDATE friends SET invite_code = ?, session_token = NULL WHERE username = ?`, [
135
+ newCode,
136
+ sanitized,
137
+ ]);
135
138
  return newCode;
136
139
  }
137
140
  /** Update a friend's nickname. */
138
141
  updateNickname(username, newNickname) {
139
142
  const sanitized = username.toLowerCase().replace(/[^a-z0-9_]/g, '_');
140
- const result = this.db.run(`UPDATE friends SET nickname = ? WHERE username = ?`, [newNickname, sanitized]);
143
+ const result = this.db.run(`UPDATE friends SET nickname = ? WHERE username = ?`, [
144
+ newNickname,
145
+ sanitized,
146
+ ]);
141
147
  return result.changes > 0;
142
148
  }
143
149
  /** Touch last_seen timestamp. */
@@ -162,9 +168,7 @@ export class InviteStore {
162
168
  /** Check if a username already exists. */
163
169
  exists(username) {
164
170
  const sanitized = username.toLowerCase().replace(/[^a-z0-9_]/g, '_');
165
- const row = this.db
166
- .query(`SELECT 1 FROM friends WHERE username = ?`)
167
- .get(sanitized);
171
+ const row = this.db.query(`SELECT 1 FROM friends WHERE username = ?`).get(sanitized);
168
172
  return row !== null;
169
173
  }
170
174
  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 { Tool, ConfigManagerInterface } from '@tinyclaw/types';
11
- import { InviteStore } from './store.js';
10
+ import type { ConfigManagerInterface, Tool } from '@tinyclaw/types';
11
+ import type { 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,13 +148,11 @@ 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
152
- ? 'active'
153
- : f.inviteCode
154
- ? 'invite pending'
155
- : 'revoked';
151
+ const status = f.sessionToken ? 'active' : f.inviteCode ? 'invite pending' : 'revoked';
156
152
  const lastSeenDate = new Date(f.lastSeen);
157
- const lastSeen = f.lastSeen && !isNaN(lastSeenDate.getTime()) ? lastSeenDate.toLocaleString() : 'Unknown';
153
+ const lastSeen = f.lastSeen && !Number.isNaN(lastSeenDate.getTime())
154
+ ? lastSeenDate.toLocaleString()
155
+ : 'Unknown';
158
156
  return `- **${f.nickname}** (@${f.username}) — ${status}, last seen: ${lastSeen}`;
159
157
  });
160
158
  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-staging.a343b3d",
3
+ "version": "2.0.0-staging.aecdd41",
4
4
  "description": "Friends web chat channel plugin for Tiny Claw",
5
5
  "license": "GPL-3.0",
6
6
  "author": "Waren Gonzaga",