@stage-labs/metro 0.1.0-beta.205 → 0.1.0-beta.206
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/package.json +1 -1
- package/runtime/marketplace/plugin/.claude-plugin/plugin.json +1 -1
- package/runtime/node_modules/@metro-labs/daemon/src/agents/sender-cards.ts +3 -0
- package/runtime/node_modules/@metro-labs/whatsapp/src/client.ts +2 -2
- package/runtime/node_modules/@metro-labs/whatsapp/src/names.ts +37 -3
- package/runtime/node_modules/@metro-labs/whatsapp/src/station.ts +9 -2
- package/runtime/runtime.json +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "metro",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.206",
|
|
4
4
|
"description": "Metro for Claude Code, installed by the metro daemon on this machine: every connector the agent holds as its own MCP server relayed through the daemon, the orchestrator-only guard on the main thread, and the standing rules loaded at each session start. No vendor credential ever sits in a config file.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Bonustrack",
|
|
@@ -11,6 +11,7 @@ export interface SenderCard {
|
|
|
11
11
|
id: string;
|
|
12
12
|
name?: string;
|
|
13
13
|
handle?: string;
|
|
14
|
+
avatar?: string;
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
export interface SenderCardDeps {
|
|
@@ -28,10 +29,12 @@ function cardOf(id: string, profile: unknown, seenName: string | undefined): Sen
|
|
|
28
29
|
const display = filled(p.display_name);
|
|
29
30
|
const handle = filled(p.name);
|
|
30
31
|
const name = display ?? seenName ?? handle;
|
|
32
|
+
const avatar = filled(p.avatar);
|
|
31
33
|
return {
|
|
32
34
|
id,
|
|
33
35
|
...(name === undefined ? {} : { name }),
|
|
34
36
|
...(handle === undefined || handle === name ? {} : { handle }),
|
|
37
|
+
...(avatar?.startsWith('https://') === true ? { avatar } : {}),
|
|
35
38
|
};
|
|
36
39
|
}
|
|
37
40
|
|
|
@@ -17,7 +17,7 @@ import type { ProfileChange } from '@metro-labs/core/stations/profile';
|
|
|
17
17
|
import { makeProfileCache, nonEmpty, type SenderProfile } from '@metro-labs/core/stations/sender-profile';
|
|
18
18
|
import { toInbound, toReaction, type ReactionEvent, type SelfRef } from './parse.js';
|
|
19
19
|
import { baileysLogger } from './logger.js';
|
|
20
|
-
import { makeNameBook, phoneOf, type NameBook } from './names.js';
|
|
20
|
+
import { makeNameBook, nameFiles, phoneOf, type NameBook } from './names.js';
|
|
21
21
|
import { useAccountAuthState } from './auth-state.js';
|
|
22
22
|
import { knownKey, makeKeyCache, targetKey, type KeyCache } from './keys.js';
|
|
23
23
|
import { makeOutbox, type Outbox } from './outbox.js';
|
|
@@ -301,7 +301,7 @@ export function createClient(account: WhatsAppAccount): WAClient {
|
|
|
301
301
|
keys: makeKeyCache(),
|
|
302
302
|
outbox: makeOutbox(),
|
|
303
303
|
acks: makeAckWatch(),
|
|
304
|
-
names: makeNameBook(),
|
|
304
|
+
names: makeNameBook(nameFiles.path(account.id)),
|
|
305
305
|
};
|
|
306
306
|
resetGate(st);
|
|
307
307
|
const senders = makeProfileCache<SenderProfile>((jid) => readProfile(st, jid), {
|
|
@@ -1,22 +1,56 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { accountFiles } from '@metro-labs/core/stations/account-files';
|
|
3
|
+
import { writeSecure } from '@metro-labs/core/secure-fs';
|
|
4
|
+
import { isRecord } from '@metro-labs/core/is-record';
|
|
5
|
+
import { errMsg } from '@metro-labs/core/log';
|
|
6
|
+
|
|
1
7
|
const MAX_NAMES = 2000;
|
|
8
|
+
const SAVE_DELAY_MS = 2000;
|
|
9
|
+
|
|
10
|
+
export const nameFiles = accountFiles('WHATSAPP_TOKEN_DIR', 'whatsapp-names-');
|
|
2
11
|
|
|
3
12
|
export interface NameBook {
|
|
4
13
|
note(jid: string | null | undefined, name: string | null | undefined): void;
|
|
5
14
|
get(jid: string): string | undefined;
|
|
6
15
|
}
|
|
7
16
|
|
|
8
|
-
|
|
9
|
-
|
|
17
|
+
function loaded(file: string | undefined): Map<string, string> {
|
|
18
|
+
if (file === undefined) return new Map();
|
|
19
|
+
try {
|
|
20
|
+
const raw: unknown = JSON.parse(readFileSync(file, 'utf8'));
|
|
21
|
+
if (!isRecord(raw)) return new Map();
|
|
22
|
+
return new Map(Object.entries(raw).filter((e): e is [string, string] => typeof e[1] === 'string' && e[1] !== ''));
|
|
23
|
+
} catch {
|
|
24
|
+
return new Map();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function makeNameBook(file?: string): NameBook {
|
|
29
|
+
const names = loaded(file);
|
|
30
|
+
let timer: ReturnType<typeof setTimeout> | null = null;
|
|
31
|
+
const save = (): void => {
|
|
32
|
+
timer = null;
|
|
33
|
+
if (file === undefined) return;
|
|
34
|
+
try {
|
|
35
|
+
writeSecure(file, JSON.stringify(Object.fromEntries(names)));
|
|
36
|
+
} catch (err) {
|
|
37
|
+
process.stderr.write(`whatsapp: could not save the names: ${errMsg(err)}\n`);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
10
40
|
return {
|
|
11
41
|
note(jid, name) {
|
|
12
42
|
const clean = name?.trim() ?? '';
|
|
13
|
-
if (!jid || clean === '') return;
|
|
43
|
+
if (!jid || clean === '' || names.get(jid) === clean) return;
|
|
14
44
|
names.delete(jid);
|
|
15
45
|
names.set(jid, clean);
|
|
16
46
|
if (names.size > MAX_NAMES) {
|
|
17
47
|
const oldest = names.keys().next().value;
|
|
18
48
|
if (oldest !== undefined) names.delete(oldest);
|
|
19
49
|
}
|
|
50
|
+
if (file !== undefined && timer === null) {
|
|
51
|
+
timer = setTimeout(save, SAVE_DELAY_MS);
|
|
52
|
+
timer.unref();
|
|
53
|
+
}
|
|
20
54
|
},
|
|
21
55
|
get: (jid) => names.get(jid),
|
|
22
56
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Station, Verb } from '@metro-labs/core/stations/types';
|
|
2
2
|
import { PROFILE_FIELDS, type ProfileField } from '@metro-labs/core/stations/profile';
|
|
3
3
|
import { tokenFiles } from './token-store.js';
|
|
4
|
+
import { nameFiles } from './names.js';
|
|
4
5
|
|
|
5
6
|
export const whatsappStation: Station = {
|
|
6
7
|
name: 'whatsapp',
|
|
@@ -19,7 +20,13 @@ export const whatsappStation: Station = {
|
|
|
19
20
|
profileFields: new Set<ProfileField>(PROFILE_FIELDS),
|
|
20
21
|
readsProfiles: true,
|
|
21
22
|
resolvesSenders: true,
|
|
22
|
-
forget:
|
|
23
|
-
|
|
23
|
+
forget: (accountId) => {
|
|
24
|
+
tokenFiles.forget(accountId);
|
|
25
|
+
nameFiles.forget(accountId);
|
|
26
|
+
},
|
|
27
|
+
forgetExcept: (kept) => {
|
|
28
|
+
tokenFiles.forgetExcept(kept);
|
|
29
|
+
nameFiles.forgetExcept(kept);
|
|
30
|
+
},
|
|
24
31
|
tools: [],
|
|
25
32
|
};
|
package/runtime/runtime.json
CHANGED