@stage-labs/metro 0.1.0-beta.324 → 0.1.0-beta.326
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/agent.js +1 -1
- package/dist/cli.js +1 -1
- package/dist/lock.js +15 -3
- package/dist/root-release-io.js +1 -2
- package/dist/root-release.js +2 -3
- package/dist/route.js +1 -1
- package/dist/service.js +4 -4
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/runtime/node_modules/@metro-labs/core/src/automation-store.ts +1 -1
- package/runtime/node_modules/@metro-labs/core/src/automation-types.ts +2 -2
- package/runtime/node_modules/@metro-labs/core/src/lines.ts +2 -8
- package/runtime/node_modules/@metro-labs/core/src/protocol.ts +0 -6
- package/runtime/node_modules/@metro-labs/core/src/skill-source.ts +1 -1
- package/runtime/node_modules/@metro-labs/core/src/stations/account-status.ts +1 -1
- package/runtime/node_modules/@metro-labs/core/src/stations/attachments.ts +5 -9
- package/runtime/node_modules/@metro-labs/core/src/stations/channel-directory.ts +1 -1
- package/runtime/node_modules/@metro-labs/core/src/stations/mail-text.ts +4 -4
- package/runtime/node_modules/@metro-labs/core/src/stations/mail.ts +3 -2
- package/runtime/node_modules/@metro-labs/core/src/stations/messaging-normalize.ts +1 -1
- package/runtime/node_modules/@metro-labs/core/src/stations/oauth.ts +1 -1
- package/runtime/node_modules/@metro-labs/core/src/stations/profile.ts +2 -2
- package/runtime/node_modules/@metro-labs/core/src/stations/types.ts +2 -2
- package/runtime/node_modules/@metro-labs/core/src/train-error.ts +4 -4
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/files.ts +2 -6
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/schedules.ts +6 -6
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/user.ts +0 -24
- package/runtime/node_modules/@metro-labs/daemon/src/agent-user/view.ts +3 -3
- package/runtime/node_modules/@metro-labs/daemon/src/agents/bundle.ts +3 -4
- package/runtime/node_modules/@metro-labs/daemon/src/agents/file-admin.ts +4 -9
- package/runtime/node_modules/@metro-labs/daemon/src/agents/files.ts +1 -6
- package/runtime/node_modules/@metro-labs/daemon/src/channels/inbound.ts +3 -3
- package/runtime/node_modules/@metro-labs/daemon/src/channels/pending.ts +2 -2
- package/runtime/node_modules/@metro-labs/daemon/src/claude/files.ts +1 -1
- package/runtime/node_modules/@metro-labs/daemon/src/claude/skills.ts +1 -1
- package/runtime/node_modules/@metro-labs/daemon/src/files/attach-grant.ts +3 -2
- package/runtime/node_modules/@metro-labs/daemon/src/files/attach-serve.ts +1 -1
- package/runtime/node_modules/@metro-labs/daemon/src/files/upload-api.ts +3 -7
- package/runtime/node_modules/@metro-labs/daemon/src/gateway/model-api.ts +2 -2
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/accounts.ts +10 -19
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/call-tools.ts +1 -5
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/event-store.ts +3 -4
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/group-tools.ts +1 -2
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/index.ts +2 -4
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/policy-gate.ts +5 -6
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/server-approvals.ts +2 -5
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/session.ts +1 -5
- package/runtime/node_modules/@metro-labs/daemon/src/mcp/tool-catalog.ts +2 -4
- package/runtime/node_modules/@metro-labs/daemon/src/mcp-server/announced.ts +1 -1
- package/runtime/node_modules/@metro-labs/daemon/src/metro-user/helper-script.ts +0 -1
- package/runtime/node_modules/@metro-labs/daemon/src/metro-user/install.ts +2 -0
- package/runtime/node_modules/@metro-labs/daemon/src/metro-user/tailscale-guard.ts +26 -0
- package/runtime/node_modules/@metro-labs/daemon/src/monitor/api.ts +1 -3
- package/runtime/node_modules/@metro-labs/daemon/src/routes/gmail-attach.ts +3 -3
- package/runtime/node_modules/@metro-labs/daemon/src/routes/http.ts +6 -21
- package/runtime/node_modules/@metro-labs/daemon/src/routes/local-mode.ts +1 -5
- package/runtime/node_modules/@metro-labs/daemon/src/stations/attach-resolve.ts +6 -6
- package/runtime/node_modules/@metro-labs/daemon/src/stations/attach.ts +0 -1
- package/runtime/node_modules/@metro-labs/daemon/src/stations/materialize.ts +12 -61
- package/runtime/node_modules/@metro-labs/daemon/src/stations/supervisor.ts +13 -25
- package/runtime/node_modules/@metro-labs/daemon/src/stations/threema-callbacks.ts +5 -5
- package/runtime/node_modules/@metro-labs/daemon/src/stations/webhook-endpoints.ts +2 -7
- package/runtime/node_modules/@metro-labs/daemon/src/voice/call.ts +2 -6
- package/runtime/node_modules/@metro-labs/daemon/src/voice/calls.ts +12 -12
- package/runtime/node_modules/@metro-labs/discord-bot/src/actions.ts +5 -23
- package/runtime/node_modules/@metro-labs/discord-bot/src/attachments.ts +1 -7
- package/runtime/node_modules/@metro-labs/discord-bot/src/channels.ts +2 -2
- package/runtime/node_modules/@metro-labs/discord-bot/src/group.ts +10 -35
- package/runtime/node_modules/@metro-labs/discord-bot/src/index.ts +5 -11
- package/runtime/node_modules/@metro-labs/discord-bot/src/members.ts +6 -34
- package/runtime/node_modules/@metro-labs/discord-bot/src/profile.ts +11 -14
- package/runtime/node_modules/@metro-labs/discord-bot/src/send-files.ts +1 -3
- package/runtime/node_modules/@metro-labs/discord-bot/src/verify.ts +2 -3
- package/runtime/node_modules/@metro-labs/gmail/src/accounts.ts +3 -3
- package/runtime/node_modules/@metro-labs/gmail/src/auth.ts +8 -8
- package/runtime/node_modules/@metro-labs/gmail/src/managed.ts +3 -2
- package/runtime/node_modules/@metro-labs/http/src/agent-signature.ts +1 -1
- package/runtime/node_modules/@metro-labs/http/src/api-http.ts +3 -4
- package/runtime/node_modules/@metro-labs/http/src/connector-discovery.ts +0 -113
- package/runtime/node_modules/@metro-labs/http/src/connector-input.ts +1 -1
- package/runtime/node_modules/@metro-labs/http/src/connector-mcp.ts +12 -13
- package/runtime/node_modules/@metro-labs/http/src/connector-oauth.ts +1 -1
- package/runtime/node_modules/@metro-labs/http/src/connector-policy.ts +1 -6
- package/runtime/node_modules/@metro-labs/http/src/connector-public-url.ts +4 -2
- package/runtime/node_modules/@metro-labs/http/src/connector-tools.ts +1 -11
- package/runtime/node_modules/@metro-labs/http/src/connector-url.ts +0 -6
- package/runtime/node_modules/@metro-labs/http/src/mcp-server-protocol.ts +1 -1
- package/runtime/node_modules/@metro-labs/http/src/mcp-server-tools.ts +0 -2
- package/runtime/node_modules/@metro-labs/http/src/mode-api.ts +1 -1
- package/runtime/node_modules/@metro-labs/http/src/return-to.ts +2 -2
- package/runtime/node_modules/@metro-labs/http/src/workos-token.ts +6 -7
- package/runtime/node_modules/@metro-labs/inference/package.json +1 -0
- package/runtime/node_modules/@metro-labs/inference/src/attempts.ts +3 -3
- package/runtime/node_modules/@metro-labs/inference/src/bedrock.ts +1 -1
- package/runtime/node_modules/@metro-labs/inference/src/codex-translate.ts +2 -2
- package/runtime/node_modules/@metro-labs/inference/src/delivered.ts +1 -1
- package/runtime/node_modules/@metro-labs/inference/src/effort.ts +0 -6
- package/runtime/node_modules/@metro-labs/inference/src/fallback.ts +7 -5
- package/runtime/node_modules/@metro-labs/inference/src/forward.ts +5 -5
- package/runtime/node_modules/@metro-labs/inference/src/measure.ts +2 -3
- package/runtime/node_modules/@metro-labs/inference/src/named.ts +3 -3
- package/runtime/node_modules/@metro-labs/inference/src/probes.ts +98 -0
- package/runtime/node_modules/@metro-labs/inference/src/usage.ts +5 -5
- package/runtime/node_modules/@metro-labs/outlook/src/accounts.ts +6 -8
- package/runtime/node_modules/@metro-labs/outlook/src/auth.ts +2 -1
- package/runtime/node_modules/@metro-labs/outlook/src/inbound.ts +3 -5
- package/runtime/node_modules/@metro-labs/outlook/src/me.ts +6 -6
- package/runtime/node_modules/@metro-labs/outlook/src/outbound.ts +10 -13
- package/runtime/node_modules/@metro-labs/telegram/src/actions.ts +7 -26
- package/runtime/node_modules/@metro-labs/telegram/src/attachments.ts +1 -1
- package/runtime/node_modules/@metro-labs/telegram/src/login.ts +3 -6
- package/runtime/node_modules/@metro-labs/telegram/src/profile.ts +3 -2
- package/runtime/node_modules/@metro-labs/telegram-bot/src/actions.ts +6 -20
- package/runtime/node_modules/@metro-labs/telegram-bot/src/attachments.ts +1 -7
- package/runtime/node_modules/@metro-labs/telegram-bot/src/format.ts +0 -2
- package/runtime/node_modules/@metro-labs/telegram-bot/src/media-actions.ts +1 -16
- package/runtime/node_modules/@metro-labs/telegram-bot/src/members.ts +1 -8
- package/runtime/node_modules/@metro-labs/telegram-bot/src/profile.ts +2 -1
- package/runtime/node_modules/@metro-labs/threema/src/actions.ts +1 -8
- package/runtime/node_modules/@metro-labs/threema/src/chats.ts +4 -3
- package/runtime/node_modules/@metro-labs/threema/src/format.ts +15 -17
- package/runtime/node_modules/@metro-labs/threema/src/groups.ts +2 -4
- package/runtime/node_modules/@metro-labs/threema/src/inbound.ts +2 -1
- package/runtime/node_modules/@metro-labs/threema/src/messages.ts +2 -1
- package/runtime/node_modules/@metro-labs/threema/src/outbound.ts +7 -7
- package/runtime/node_modules/@metro-labs/whatsapp/src/actions.ts +1 -3
- package/runtime/node_modules/@metro-labs/whatsapp/src/attachments.ts +0 -2
- package/runtime/node_modules/@metro-labs/whatsapp/src/client.ts +1 -1
- package/runtime/node_modules/@metro-labs/whatsapp/src/login.ts +1 -1
- package/runtime/node_modules/@metro-labs/xmtp/src/accounts.ts +7 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/actions-conv.ts +4 -10
- package/runtime/node_modules/@metro-labs/xmtp/src/actions-meta.ts +4 -5
- package/runtime/node_modules/@metro-labs/xmtp/src/actions.ts +14 -26
- package/runtime/node_modules/@metro-labs/xmtp/src/attachments.ts +1 -7
- package/runtime/node_modules/@metro-labs/xmtp/src/codecs.ts +17 -58
- package/runtime/node_modules/@metro-labs/xmtp/src/conv-helpers.ts +1 -6
- package/runtime/node_modules/@metro-labs/xmtp/src/emit-payloads.ts +10 -31
- package/runtime/node_modules/@metro-labs/xmtp/src/frames.ts +12 -14
- package/runtime/node_modules/@metro-labs/xmtp/src/group.ts +2 -3
- package/runtime/node_modules/@metro-labs/xmtp/src/identity.ts +3 -9
- package/runtime/node_modules/@metro-labs/xmtp/src/labels.ts +8 -9
- package/runtime/node_modules/@metro-labs/xmtp/src/names.ts +4 -2
- package/runtime/node_modules/@metro-labs/xmtp/src/network.ts +2 -3
- package/runtime/node_modules/@metro-labs/xmtp/src/profile.ts +2 -1
- package/runtime/node_modules/@metro-labs/xmtp/src/read-attachments.ts +2 -2
- package/runtime/node_modules/@metro-labs/xmtp/src/sender.ts +2 -1
- package/runtime/node_modules/@metro-labs/xmtp/src/transcribe.ts +23 -46
- package/runtime/node_modules/@metro-labs/xmtp/src/wallet.ts +5 -4
- package/runtime/node_modules/@metro-labs/xmtp/src/wire.ts +12 -15
- package/runtime/runtime.json +1 -1
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/automation-store.ts +1 -1
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/automation-types.ts +2 -2
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/lines.ts +2 -8
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/protocol.ts +0 -6
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/skill-source.ts +1 -1
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/stations/account-status.ts +1 -1
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/stations/attachments.ts +5 -9
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/stations/channel-directory.ts +1 -1
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/stations/mail-text.ts +4 -4
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/stations/mail.ts +3 -2
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/stations/messaging-normalize.ts +1 -1
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/stations/oauth.ts +1 -1
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/stations/profile.ts +2 -2
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/stations/types.ts +2 -2
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/train-error.ts +4 -4
- package/runtime/sdk-runner/runner.json +1 -1
- package/runtime/sdk-runner/src/approvals.ts +2 -2
- package/runtime/sdk-runner/src/automation-command.ts +2 -2
- package/runtime/sdk-runner/src/calls.ts +0 -6
- package/runtime/sdk-runner/src/errors.ts +1 -1
- package/runtime/sdk-runner/src/link.ts +1 -1
- package/runtime/sdk-runner/src/runner.ts +2 -2
- package/runtime/sdk-runner/src/session-watch.ts +5 -34
- package/runtime/sdk-runner/src/task-state.ts +1 -1
- package/runtime/sdk-runner/src/tool-proxy.ts +1 -1
- package/runtime/node_modules/@metro-labs/xmtp/src/member-args.ts +0 -40
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { TrainError } from '@metro-labs/core/train-error';
|
|
2
|
-
import {
|
|
3
|
-
makeStation,
|
|
4
|
-
respond,
|
|
5
|
-
type CallMsg,
|
|
6
|
-
} from '@metro-labs/core/stations/station-runtime';
|
|
2
|
+
import { makeStation, respond } from '@metro-labs/core/stations/station-runtime';
|
|
7
3
|
import { messagingAliases } from '@metro-labs/core/stations/messaging-normalize';
|
|
8
4
|
import { accountFor, accounts, publicKeyFor, targetOf, type Account } from './accounts.js';
|
|
9
5
|
import { hexToBytes, macMatches, open } from './crypto.js';
|
|
@@ -15,9 +11,6 @@ import { isThreemaId, normalizeThreemaId } from './ids.js';
|
|
|
15
11
|
import { decode } from './messages.js';
|
|
16
12
|
import { react, send } from './outbound.js';
|
|
17
13
|
|
|
18
|
-
export type { CallMsg };
|
|
19
|
-
export { MAX_TEXT_BYTES } from './outbound.js';
|
|
20
|
-
|
|
21
14
|
type Args = Record<string, unknown>;
|
|
22
15
|
|
|
23
16
|
const WEB_CHAT = 'https://web.threema.com/#!/messenger/conversation/contact/';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { dirname } from 'node:path';
|
|
3
3
|
import { randomUUID } from 'node:crypto';
|
|
4
|
+
import { isRecord } from '@metro-labs/core/is-record';
|
|
4
5
|
import { log } from '@metro-labs/core/log';
|
|
5
6
|
import { accountFiles } from '@metro-labs/core/stations/account-files';
|
|
6
7
|
import { DIRECTORY_LIMIT } from '@metro-labs/core/stations/channel-directory';
|
|
@@ -17,10 +18,10 @@ const nameOf = (name: unknown): string | undefined =>
|
|
|
17
18
|
typeof name === 'string' ? Array.from(name.trim()).slice(0, 256).join('') || undefined : undefined;
|
|
18
19
|
|
|
19
20
|
function directChat(entry: unknown): DirectChat | undefined {
|
|
20
|
-
if (!
|
|
21
|
+
if (!isRecord(entry) || typeof entry.id !== 'string') return undefined;
|
|
21
22
|
const id = normalizeThreemaId(entry.id);
|
|
22
23
|
if (!isThreemaId(id)) return undefined;
|
|
23
|
-
const name = nameOf(
|
|
24
|
+
const name = nameOf(entry.name);
|
|
24
25
|
return { id, ...(name ? { name } : {}) };
|
|
25
26
|
}
|
|
26
27
|
|
|
@@ -36,7 +37,7 @@ function readChats(path: string): Map<string, DirectChat> {
|
|
|
36
37
|
}
|
|
37
38
|
return chats;
|
|
38
39
|
} catch (err) {
|
|
39
|
-
if (!(err &&
|
|
40
|
+
if (!(isRecord(err) && err.code === 'ENOENT'))
|
|
40
41
|
log.warn({ err, path }, 'threema: could not load chat metadata');
|
|
41
42
|
return new Map();
|
|
42
43
|
}
|
|
@@ -118,13 +118,7 @@ export function receiptEnvelope(
|
|
|
118
118
|
return emoji === undefined ? null : reactionEnvelope(accountId, m, emoji, targetId, false, room, 'receipt');
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
|
|
122
|
-
accountId: string,
|
|
123
|
-
line: string,
|
|
124
|
-
messageId: string,
|
|
125
|
-
text: string,
|
|
126
|
-
replyTo?: string,
|
|
127
|
-
): void {
|
|
121
|
+
function emitOwn(accountId: string, line: string, messageId: string, fields: Record<string, unknown>): void {
|
|
128
122
|
emit({
|
|
129
123
|
id: mintId(),
|
|
130
124
|
ts: new Date().toISOString(),
|
|
@@ -133,10 +127,22 @@ export function emitOutbound(
|
|
|
133
127
|
from: selfUri(),
|
|
134
128
|
to: line,
|
|
135
129
|
message_id: messageId,
|
|
130
|
+
...fields,
|
|
131
|
+
payload: { account: accountId },
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function emitOutbound(
|
|
136
|
+
accountId: string,
|
|
137
|
+
line: string,
|
|
138
|
+
messageId: string,
|
|
139
|
+
text: string,
|
|
140
|
+
replyTo?: string,
|
|
141
|
+
): void {
|
|
142
|
+
emitOwn(accountId, line, messageId, {
|
|
136
143
|
text,
|
|
137
144
|
reply_to: replyTo,
|
|
138
145
|
...(replyTo ? { event: { type: 'reply', replyTo } } : {}),
|
|
139
|
-
payload: { account: accountId },
|
|
140
146
|
});
|
|
141
147
|
}
|
|
142
148
|
|
|
@@ -148,17 +154,9 @@ export function emitOutboundReaction(
|
|
|
148
154
|
targetId: string,
|
|
149
155
|
removed: boolean,
|
|
150
156
|
): void {
|
|
151
|
-
|
|
152
|
-
id: mintId(),
|
|
153
|
-
ts: new Date().toISOString(),
|
|
154
|
-
station: 'threema',
|
|
155
|
-
line,
|
|
156
|
-
from: selfUri(),
|
|
157
|
-
to: line,
|
|
158
|
-
message_id: messageId,
|
|
157
|
+
emitOwn(accountId, line, messageId, {
|
|
159
158
|
text: `[react ${emoji}${removed ? ' (removed)' : ''}]`,
|
|
160
159
|
emoji,
|
|
161
160
|
event: { type: 'react', emoji, targetId, ...(removed ? { removed: true } : {}) },
|
|
162
|
-
payload: { account: accountId },
|
|
163
161
|
});
|
|
164
162
|
}
|
|
@@ -21,11 +21,9 @@ export function parseGroupKey(resource: string): GroupRef | null {
|
|
|
21
21
|
|
|
22
22
|
export const groupFiles = accountFiles('THREEMA_GROUPS_DIR', 'threema-groups-');
|
|
23
23
|
|
|
24
|
-
const groupsFile = (accountId: string): string => groupFiles.path(accountId);
|
|
25
|
-
|
|
26
24
|
function readRosters(accountId: string): Map<string, GroupRoster> {
|
|
27
25
|
try {
|
|
28
|
-
const raw: unknown = JSON.parse(readFileSync(
|
|
26
|
+
const raw: unknown = JSON.parse(readFileSync(groupFiles.path(accountId), 'utf8'));
|
|
29
27
|
const out = new Map<string, GroupRoster>();
|
|
30
28
|
if (Array.isArray(raw))
|
|
31
29
|
for (const entry of raw) {
|
|
@@ -87,7 +85,7 @@ export class GroupStore {
|
|
|
87
85
|
}
|
|
88
86
|
|
|
89
87
|
private save(): void {
|
|
90
|
-
const path =
|
|
88
|
+
const path = groupFiles.path(this.accountId);
|
|
91
89
|
mkdirSync(dirname(path), { recursive: true });
|
|
92
90
|
const tmp = `${path}.${String(process.pid)}.tmp`;
|
|
93
91
|
writeFileSync(tmp, JSON.stringify(this.list()), { mode: 0o600 });
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { errMsg } from '@metro-labs/core/log';
|
|
1
2
|
import type { Account } from './accounts.js';
|
|
2
3
|
import { emitInbound } from '@metro-labs/core/stations/train-events';
|
|
3
4
|
import {
|
|
@@ -22,7 +23,7 @@ function askForRoster(acct: Account, group: GroupRef): void {
|
|
|
22
23
|
if (acct.groups.get(group) !== undefined || acct.requestedRosters.has(key)) return;
|
|
23
24
|
acct.requestedRosters.add(key);
|
|
24
25
|
requestSync(acct, group).catch((err: unknown) => {
|
|
25
|
-
process.stderr.write(`threema[${acct.cfg.id}]: could not ask ${group.creator} for the group roster: ${
|
|
26
|
+
process.stderr.write(`threema[${acct.cfg.id}]: could not ask ${group.creator} for the group roster: ${errMsg(err)}\n`);
|
|
26
27
|
});
|
|
27
28
|
}
|
|
28
29
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isRecord } from '@metro-labs/core/is-record';
|
|
1
2
|
import { bytesToHex, hexToBytes } from './crypto.js';
|
|
2
3
|
|
|
3
4
|
export const MSG_TEXT = 0x01;
|
|
@@ -118,7 +119,7 @@ const hexOf = (v: unknown, length: number): string | null => {
|
|
|
118
119
|
function parseJson(raw: Uint8Array): Record<string, unknown> | null {
|
|
119
120
|
try {
|
|
120
121
|
const parsed: unknown = JSON.parse(utf8(raw));
|
|
121
|
-
return
|
|
122
|
+
return isRecord(parsed) ? parsed : null;
|
|
122
123
|
} catch {
|
|
123
124
|
return null;
|
|
124
125
|
}
|
|
@@ -22,7 +22,7 @@ type Args = Record<string, unknown>;
|
|
|
22
22
|
|
|
23
23
|
const sentIds = new Set<string>();
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
function noteSent(messageId: string): void {
|
|
26
26
|
sentIds.add(messageId);
|
|
27
27
|
while (sentIds.size > SENT_MAX) {
|
|
28
28
|
const oldest = sentIds.values().next();
|
|
@@ -85,7 +85,12 @@ function textOf(a: SendArgs, files: OutgoingFile[]): string {
|
|
|
85
85
|
return text;
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
|
|
88
|
+
interface Sent {
|
|
89
|
+
ids: string[];
|
|
90
|
+
labels: string[];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function sendFiles(acct: Account, target: Target, files: OutgoingFile[], caption: string | null): Promise<Sent> {
|
|
89
94
|
const ids: string[] = [];
|
|
90
95
|
const labels: string[] = [];
|
|
91
96
|
for (const [i, file] of files.entries()) {
|
|
@@ -113,11 +118,6 @@ function bodyOf(text: string, replyTo: string | undefined): string {
|
|
|
113
118
|
return body;
|
|
114
119
|
}
|
|
115
120
|
|
|
116
|
-
interface Sent {
|
|
117
|
-
ids: string[];
|
|
118
|
-
labels: string[];
|
|
119
|
-
}
|
|
120
|
-
|
|
121
121
|
const resultOf = (acct: Account, sent: Sent): Record<string, unknown> => ({
|
|
122
122
|
messageId: sent.ids[0] ?? '',
|
|
123
123
|
account: acct.cfg.id,
|
|
@@ -70,9 +70,7 @@ async function sendMediaSet(
|
|
|
70
70
|
): Promise<{ messageId: string; labels: string[] }> {
|
|
71
71
|
const labels: string[] = [];
|
|
72
72
|
let messageId = '';
|
|
73
|
-
for (
|
|
74
|
-
const att = atts[i];
|
|
75
|
-
if (!att) continue;
|
|
73
|
+
for (const [i, att] of atts.entries()) {
|
|
76
74
|
const path = att.path;
|
|
77
75
|
const kind = att.kind ?? kindOf(att.mime ?? '', path);
|
|
78
76
|
messageId = await guard(() =>
|
|
@@ -8,8 +8,6 @@ import { TrainError } from '@metro-labs/core/train-error';
|
|
|
8
8
|
import { baileysLogger } from './logger.js';
|
|
9
9
|
import type { WAMediaRef } from './media.js';
|
|
10
10
|
|
|
11
|
-
export type { SavedAttachment };
|
|
12
|
-
|
|
13
11
|
const IDLE_TIMEOUT_MS = 60_000;
|
|
14
12
|
|
|
15
13
|
export type ReuploadRequest = (m: WAMessage) => Promise<WAMessage>;
|
|
@@ -121,7 +121,7 @@ function onClose(st: State, closed: Closed): void {
|
|
|
121
121
|
}
|
|
122
122
|
resetGate(st);
|
|
123
123
|
process.stderr.write(`whatsapp[${st.account.id}] reconnecting\n`);
|
|
124
|
-
|
|
124
|
+
connect(st).catch((e: unknown) => {
|
|
125
125
|
process.stderr.write(
|
|
126
126
|
`whatsapp[${st.account.id}] reconnect failed: ${errMsg(e)}\n`,
|
|
127
127
|
);
|
|
@@ -102,7 +102,7 @@ export class WhatsappLogin {
|
|
|
102
102
|
}
|
|
103
103
|
if (this.pairingRequested || this.auth.state.creds.registered) return;
|
|
104
104
|
this.pairingRequested = true;
|
|
105
|
-
|
|
105
|
+
sock
|
|
106
106
|
.requestPairingCode(this.phone)
|
|
107
107
|
.then((code) => {
|
|
108
108
|
if (!this.settled) this.events.onPairingCode(code);
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
resolveAccountId,
|
|
15
15
|
} from '@metro-labs/core/stations/account-store';
|
|
16
16
|
import { Line } from '@metro-labs/core/lines';
|
|
17
|
+
import { TrainError } from '@metro-labs/core/train-error';
|
|
17
18
|
|
|
18
19
|
export interface AccountConfig {
|
|
19
20
|
id: string;
|
|
@@ -101,3 +102,9 @@ export async function convOf(
|
|
|
101
102
|
conv: await acct.client.conversations.getConversationById(parsed.convId),
|
|
102
103
|
};
|
|
103
104
|
}
|
|
105
|
+
|
|
106
|
+
export async function openConv(line: string): Promise<{ acct: Account; conv: Conversation }> {
|
|
107
|
+
const { acct, conv } = await convOf(line);
|
|
108
|
+
if (!conv) throw new TrainError('NOT_FOUND', `conversation not found for ${line}`);
|
|
109
|
+
return { acct, conv };
|
|
110
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IdentifierKind, type DecodedMessage } from '@xmtp/node-sdk';
|
|
2
|
-
import { accountForCall,
|
|
2
|
+
import { accountForCall, lineOf, openConv, type Account } from './accounts.js';
|
|
3
3
|
import { respond } from '@metro-labs/core/stations/station-runtime';
|
|
4
4
|
import { resolveMsgId } from './wire.js';
|
|
5
5
|
import { serializeTrainError, TrainError } from '@metro-labs/core/train-error';
|
|
@@ -69,9 +69,7 @@ function messageOf(acct: Account, m: DecodedMessage, deleted: Set<string>): Reco
|
|
|
69
69
|
|
|
70
70
|
async function read(id: string, args: Args): Promise<void> {
|
|
71
71
|
const { line, limit, before, messageId } = args as { line: string; limit?: number; before?: string; messageId?: string };
|
|
72
|
-
const { acct, conv } = await
|
|
73
|
-
if (!conv)
|
|
74
|
-
throw new TrainError('NOT_FOUND', `conversation not found for ${line}`);
|
|
72
|
+
const { acct, conv } = await openConv(line);
|
|
75
73
|
await syncConversation(acct.client, conv);
|
|
76
74
|
const all = await conv.messages();
|
|
77
75
|
if (messageId) {
|
|
@@ -97,17 +95,13 @@ async function read(id: string, args: Args): Promise<void> {
|
|
|
97
95
|
|
|
98
96
|
async function groupInfo(id: string, args: Args): Promise<void> {
|
|
99
97
|
const { line } = args as { line: string };
|
|
100
|
-
const { acct, conv } = await
|
|
101
|
-
if (!conv)
|
|
102
|
-
throw new TrainError('NOT_FOUND', `conversation not found for ${line}`);
|
|
98
|
+
const { acct, conv } = await openConv(line);
|
|
103
99
|
respond(id, { result: await buildGroupInfo(line, acct, conv) });
|
|
104
100
|
}
|
|
105
101
|
|
|
106
102
|
async function listMembers(id: string, args: Args): Promise<void> {
|
|
107
103
|
const { line } = args as { line: string };
|
|
108
|
-
const { conv } = await
|
|
109
|
-
if (!conv)
|
|
110
|
-
throw new TrainError('NOT_FOUND', `conversation not found for ${line}`);
|
|
104
|
+
const { conv } = await openConv(line);
|
|
111
105
|
respond(id, { result: await buildMemberList(conv) });
|
|
112
106
|
}
|
|
113
107
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { accountForCall,
|
|
1
|
+
import { accountForCall, lineOf, openConv, parseLine } from './accounts.js';
|
|
2
|
+
import { isRecord } from '@metro-labs/core/is-record';
|
|
2
3
|
import { respond } from '@metro-labs/core/stations/station-runtime';
|
|
3
4
|
import { ethIdentifiers, warmGroupName } from './conv-helpers.js';
|
|
4
5
|
import { mergeAppData, normalizeAssigned, readAppDataObject, type GroupLike } from './labels.js';
|
|
@@ -50,7 +51,7 @@ async function applyMergedAppData(
|
|
|
50
51
|
group: GroupLike & { updateAppData: (s: string) => Promise<void> },
|
|
51
52
|
appData: Record<string, unknown> | undefined,
|
|
52
53
|
): Promise<Record<string, unknown>> {
|
|
53
|
-
if (
|
|
54
|
+
if (isRecord(appData)) {
|
|
54
55
|
const res = mergeAppData(group.appData, appData);
|
|
55
56
|
await group.updateAppData(res.blob);
|
|
56
57
|
return res.merged;
|
|
@@ -68,9 +69,7 @@ async function applyChannelMeta(
|
|
|
68
69
|
verb: string,
|
|
69
70
|
): Promise<Record<string, unknown>> {
|
|
70
71
|
const { line, name, description, appData } = args;
|
|
71
|
-
const { acct, conv } = await
|
|
72
|
-
if (!conv)
|
|
73
|
-
throw new TrainError('NOT_FOUND', `conversation not found for ${line}`);
|
|
72
|
+
const { acct, conv } = await openConv(line);
|
|
74
73
|
const group = conv as unknown as GroupLike;
|
|
75
74
|
if (typeof group.updateAppData !== 'function') {
|
|
76
75
|
throw new TrainError(
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
type Attachment,
|
|
11
11
|
} from '@xmtp/content-type-remote-attachment';
|
|
12
12
|
import type { EncodedContent } from '@xmtp/content-type-primitives';
|
|
13
|
-
import {
|
|
13
|
+
import { accounts, openConv, type Account } from './accounts.js';
|
|
14
14
|
import { resolveMsgId } from './wire.js';
|
|
15
15
|
import { emitOutbound } from './emit.js';
|
|
16
16
|
import { CallSignalCodec, FrameCodec, PollCodec, buildPollContent, encodeDeleteMessage } from './codecs.js';
|
|
@@ -25,12 +25,10 @@ import { claimNameAction, nameAction, setProfile } from './profile.js';
|
|
|
25
25
|
import { profileAction } from './sender.js';
|
|
26
26
|
import { resolveSenderAction } from './resolve.js';
|
|
27
27
|
import { listChannels } from './channels.js';
|
|
28
|
-
import { makeStation, respond
|
|
28
|
+
import { makeStation, respond } from '@metro-labs/core/stations/station-runtime';
|
|
29
29
|
|
|
30
30
|
type Args = Record<string, unknown>;
|
|
31
31
|
|
|
32
|
-
const noConv = (line: string): TrainError =>
|
|
33
|
-
new TrainError('NOT_FOUND', `conversation not found for ${line}`);
|
|
34
32
|
const badArgs = (message: string): TrainError =>
|
|
35
33
|
new TrainError('INVALID_ARGS', message);
|
|
36
34
|
|
|
@@ -45,8 +43,7 @@ async function send(id: string, args: Args): Promise<void> {
|
|
|
45
43
|
...(args.frame === undefined ? [] : [framePart(args.frame)]),
|
|
46
44
|
...(args.wallet === undefined ? [] : [buildWalletContent(args.wallet)]),
|
|
47
45
|
];
|
|
48
|
-
const { acct, conv } = await
|
|
49
|
-
if (!conv) throw noConv(line);
|
|
46
|
+
const { acct, conv } = await openConv(line);
|
|
50
47
|
let messageId: string | undefined;
|
|
51
48
|
if (text || parts.length === 0) {
|
|
52
49
|
messageId = await conv.sendText(text);
|
|
@@ -61,8 +58,7 @@ async function send(id: string, args: Args): Promise<void> {
|
|
|
61
58
|
|
|
62
59
|
async function ask(id: string, args: Args): Promise<void> {
|
|
63
60
|
const { line } = args as { line: string };
|
|
64
|
-
const { acct, conv } = await
|
|
65
|
-
if (!conv) throw noConv(line);
|
|
61
|
+
const { acct, conv } = await openConv(line);
|
|
66
62
|
const mintedId = crypto.randomUUID();
|
|
67
63
|
const { poll, title } = buildPollContent(args, mintedId);
|
|
68
64
|
const sentId = await conv.send(new PollCodec().encode(poll));
|
|
@@ -85,8 +81,7 @@ async function react(id: string, args: Args): Promise<void> {
|
|
|
85
81
|
emoji: string;
|
|
86
82
|
action?: 'added' | 'removed';
|
|
87
83
|
};
|
|
88
|
-
const { acct, conv } = await
|
|
89
|
-
if (!conv) throw noConv(line);
|
|
84
|
+
const { acct, conv } = await openConv(line);
|
|
90
85
|
const xmtpMsgId = resolveMsgId(messageId);
|
|
91
86
|
const removed = reactAction === 'removed';
|
|
92
87
|
const sentId = await conv.sendReaction({
|
|
@@ -112,8 +107,7 @@ async function reply(id: string, args: Args): Promise<void> {
|
|
|
112
107
|
replyTo: string;
|
|
113
108
|
text: string;
|
|
114
109
|
};
|
|
115
|
-
const { acct, conv } = await
|
|
116
|
-
if (!conv) throw noConv(line);
|
|
110
|
+
const { acct, conv } = await openConv(line);
|
|
117
111
|
const { encodeText } = await import('@xmtp/node-bindings');
|
|
118
112
|
const xmtpReplyTo = resolveMsgId(replyTo);
|
|
119
113
|
const sentId = await conv.sendReply({
|
|
@@ -147,8 +141,7 @@ function assertDeletable(acct: Account, conv: Conversation, messageId: string):
|
|
|
147
141
|
|
|
148
142
|
async function remove(id: string, args: Args): Promise<void> {
|
|
149
143
|
const { line, messageId } = args as { line: string; messageId: string };
|
|
150
|
-
const { acct, conv } = await
|
|
151
|
-
if (!conv) throw noConv(line);
|
|
144
|
+
const { acct, conv } = await openConv(line);
|
|
152
145
|
const target = resolveMsgId(messageId);
|
|
153
146
|
assertDeletable(acct, conv, target);
|
|
154
147
|
const sentId = await conv.send(encodeDeleteMessage(target), { shouldPush: false });
|
|
@@ -158,8 +151,7 @@ async function remove(id: string, args: Args): Promise<void> {
|
|
|
158
151
|
async function callSignal(id: string, args: Args): Promise<void> {
|
|
159
152
|
const { line, signal } = args as { line: string; signal?: unknown };
|
|
160
153
|
if (typeof signal !== 'object' || signal === null) throw badArgs('callSignal requires a signal object');
|
|
161
|
-
const { conv } = await
|
|
162
|
-
if (!conv) throw noConv(line);
|
|
154
|
+
const { conv } = await openConv(line);
|
|
163
155
|
const messageId = await conv.send(new CallSignalCodec().encode(signal as Record<string, unknown>), { shouldPush: false });
|
|
164
156
|
respond(id, { result: { messageId } });
|
|
165
157
|
}
|
|
@@ -171,8 +163,7 @@ async function sendAttachment(id: string, args: Args): Promise<void> {
|
|
|
171
163
|
mime: string;
|
|
172
164
|
dataB64: string;
|
|
173
165
|
};
|
|
174
|
-
const { acct, conv } = await
|
|
175
|
-
if (!conv) throw noConv(line);
|
|
166
|
+
const { acct, conv } = await openConv(line);
|
|
176
167
|
const sentId = await conv.sendAttachment({
|
|
177
168
|
filename: name,
|
|
178
169
|
mimeType: mime,
|
|
@@ -202,8 +193,7 @@ function imageFilename(path: string): string {
|
|
|
202
193
|
async function sendImage(id: string, args: Args): Promise<void> {
|
|
203
194
|
const { line, path } = args as { line: string; path?: string };
|
|
204
195
|
if (!path) throw badArgs('sendImage requires path');
|
|
205
|
-
const { acct, conv } = await
|
|
206
|
-
if (!conv) throw noConv(line);
|
|
196
|
+
const { acct, conv } = await openConv(line);
|
|
207
197
|
const { readFileSync } = await import('node:fs');
|
|
208
198
|
const mime = imageMime(path);
|
|
209
199
|
const fname = imageFilename(path);
|
|
@@ -217,8 +207,7 @@ async function sendImage(id: string, args: Args): Promise<void> {
|
|
|
217
207
|
respond(id, { result: { messageId: sentId } });
|
|
218
208
|
}
|
|
219
209
|
|
|
220
|
-
|
|
221
|
-
const { accounts } = await import('./accounts.js');
|
|
210
|
+
function accountsAction(id: string): Promise<void> {
|
|
222
211
|
respond(id, {
|
|
223
212
|
result: {
|
|
224
213
|
accounts: [...accounts.values()].map((a) => ({
|
|
@@ -231,10 +220,11 @@ async function accountsAction(id: string): Promise<void> {
|
|
|
231
220
|
})),
|
|
232
221
|
},
|
|
233
222
|
});
|
|
223
|
+
return Promise.resolve();
|
|
234
224
|
}
|
|
235
225
|
|
|
236
226
|
const handlers: Record<string, (id: string, args: Args) => Promise<void>> = {
|
|
237
|
-
accounts:
|
|
227
|
+
accounts: accountsAction,
|
|
238
228
|
listChannels,
|
|
239
229
|
set_profile: setProfile,
|
|
240
230
|
claim_name: claimNameAction,
|
|
@@ -247,14 +237,12 @@ const handlers: Record<string, (id: string, args: Args) => Promise<void>> = {
|
|
|
247
237
|
reply,
|
|
248
238
|
delete: remove,
|
|
249
239
|
callSignal,
|
|
250
|
-
callLeftovers
|
|
240
|
+
callLeftovers,
|
|
251
241
|
sendAttachment,
|
|
252
242
|
sendImage,
|
|
253
243
|
...convHandlers,
|
|
254
244
|
};
|
|
255
245
|
|
|
256
|
-
export type { CallMsg };
|
|
257
|
-
|
|
258
246
|
export const handleCall = makeStation({
|
|
259
247
|
handlers: Object.fromEntries(Object.entries(handlers).map(([action, handler]) => [
|
|
260
248
|
action,
|
|
@@ -3,15 +3,9 @@ import {
|
|
|
3
3
|
RemoteAttachmentCodec,
|
|
4
4
|
ContentTypeAttachment,
|
|
5
5
|
} from '@xmtp/content-type-remote-attachment';
|
|
6
|
-
import {
|
|
7
|
-
saveBufferToCache,
|
|
8
|
-
assertAttachmentSize,
|
|
9
|
-
} from '@metro-labs/core/stations/attachments';
|
|
10
|
-
import type { SavedAttachment } from '@metro-labs/core/stations/attachments';
|
|
6
|
+
import { assertAttachmentSize, saveBufferToCache, type SavedAttachment } from '@metro-labs/core/stations/attachments';
|
|
11
7
|
import { errMsg } from '@metro-labs/core/log';
|
|
12
8
|
|
|
13
|
-
export type { SavedAttachment };
|
|
14
|
-
|
|
15
9
|
interface FetchSchedule {
|
|
16
10
|
delaysMs: readonly number[];
|
|
17
11
|
requestTimeoutMs: number;
|
|
@@ -8,6 +8,12 @@ const enc = (o: unknown): Uint8Array =>
|
|
|
8
8
|
new TextEncoder().encode(JSON.stringify(o));
|
|
9
9
|
const dec = (e: EncodedContent): unknown =>
|
|
10
10
|
JSON.parse(new TextDecoder().decode(e.content));
|
|
11
|
+
const contentTypeId = (authorityId: string, typeId: string): ContentTypeId => ({
|
|
12
|
+
authorityId,
|
|
13
|
+
typeId,
|
|
14
|
+
versionMajor: 1,
|
|
15
|
+
versionMinor: 0,
|
|
16
|
+
});
|
|
11
17
|
|
|
12
18
|
const makeJsonCodec = <T>(
|
|
13
19
|
contentType: ContentTypeId,
|
|
@@ -38,12 +44,7 @@ const makeJsonCodec = <T>(
|
|
|
38
44
|
}
|
|
39
45
|
};
|
|
40
46
|
|
|
41
|
-
export const ContentTypePoll
|
|
42
|
-
authorityId: 'metro.box',
|
|
43
|
-
typeId: 'poll',
|
|
44
|
-
versionMajor: 1,
|
|
45
|
-
versionMinor: 0,
|
|
46
|
-
};
|
|
47
|
+
export const ContentTypePoll = contentTypeId('metro.box', 'poll');
|
|
47
48
|
export interface PollOption {
|
|
48
49
|
label: string;
|
|
49
50
|
description?: string;
|
|
@@ -127,12 +128,7 @@ export function buildPollContent(
|
|
|
127
128
|
};
|
|
128
129
|
}
|
|
129
130
|
|
|
130
|
-
export const ContentTypeSignatureRequest
|
|
131
|
-
authorityId: 'metro.box',
|
|
132
|
-
typeId: 'signatureRequest',
|
|
133
|
-
versionMajor: 1,
|
|
134
|
-
versionMinor: 0,
|
|
135
|
-
};
|
|
131
|
+
export const ContentTypeSignatureRequest = contentTypeId('metro.box', 'signatureRequest');
|
|
136
132
|
export interface SignatureRequestContent {
|
|
137
133
|
id?: string;
|
|
138
134
|
kind?: 'eip712' | 'personal';
|
|
@@ -149,12 +145,7 @@ export const SignatureRequestCodec = makeJsonCodec<SignatureRequestContent>(
|
|
|
149
145
|
: '[Signature request]',
|
|
150
146
|
);
|
|
151
147
|
|
|
152
|
-
export const ContentTypeSignatureReference
|
|
153
|
-
authorityId: 'metro.box',
|
|
154
|
-
typeId: 'signatureReference',
|
|
155
|
-
versionMajor: 1,
|
|
156
|
-
versionMinor: 0,
|
|
157
|
-
};
|
|
148
|
+
export const ContentTypeSignatureReference = contentTypeId('metro.box', 'signatureReference');
|
|
158
149
|
export interface SignatureReferenceContent {
|
|
159
150
|
requestId?: string;
|
|
160
151
|
signature: string;
|
|
@@ -166,30 +157,19 @@ export const SignatureReferenceCodec =
|
|
|
166
157
|
c.signature ? `[Signature] ${c.signature}` : '[Signature]',
|
|
167
158
|
);
|
|
168
159
|
|
|
169
|
-
const xmtpOrg = (typeId: string): ContentTypeId => ({
|
|
170
|
-
authorityId: 'xmtp.org',
|
|
171
|
-
typeId,
|
|
172
|
-
versionMajor: 1,
|
|
173
|
-
versionMinor: 0,
|
|
174
|
-
});
|
|
175
160
|
export const WalletSendCallsCodec = makeJsonCodec<{ calls?: { metadata?: { description?: string } }[] }>(
|
|
176
|
-
|
|
161
|
+
contentTypeId('xmtp.org', 'walletSendCalls'),
|
|
177
162
|
(c) => {
|
|
178
163
|
const desc = c.calls?.[0]?.metadata?.description;
|
|
179
164
|
return desc ? `[Transaction request] ${desc}` : '[Transaction request]';
|
|
180
165
|
},
|
|
181
166
|
);
|
|
182
167
|
export const TransactionReferenceCodec = makeJsonCodec<{ reference?: string }>(
|
|
183
|
-
|
|
168
|
+
contentTypeId('xmtp.org', 'transactionReference'),
|
|
184
169
|
(c) => (c.reference ? `[Transaction] ${c.reference}` : '[Transaction]'),
|
|
185
170
|
);
|
|
186
171
|
|
|
187
|
-
export const ContentTypeFrame
|
|
188
|
-
authorityId: 'stage.box',
|
|
189
|
-
typeId: 'frame',
|
|
190
|
-
versionMajor: 1,
|
|
191
|
-
versionMinor: 0,
|
|
192
|
-
};
|
|
172
|
+
export const ContentTypeFrame = contentTypeId('stage.box', 'frame');
|
|
193
173
|
export interface FrameContent {
|
|
194
174
|
title?: string;
|
|
195
175
|
description?: string;
|
|
@@ -204,12 +184,7 @@ export const frameFallback = (c: FrameContent): string => {
|
|
|
204
184
|
};
|
|
205
185
|
export const FrameCodec = makeJsonCodec<FrameContent>(ContentTypeFrame, frameFallback);
|
|
206
186
|
|
|
207
|
-
export const ContentTypeFrameAction
|
|
208
|
-
authorityId: 'stage.box',
|
|
209
|
-
typeId: 'frameAction',
|
|
210
|
-
versionMajor: 1,
|
|
211
|
-
versionMinor: 0,
|
|
212
|
-
};
|
|
187
|
+
export const ContentTypeFrameAction = contentTypeId('stage.box', 'frameAction');
|
|
213
188
|
export interface FrameActionContent {
|
|
214
189
|
frameId: string;
|
|
215
190
|
action: { type: string; payload?: Record<string, unknown> };
|
|
@@ -221,20 +196,10 @@ export const frameActionText = (c: FrameActionContent): string => {
|
|
|
221
196
|
};
|
|
222
197
|
const FrameActionCodec = makeJsonCodec<FrameActionContent>(ContentTypeFrameAction, frameActionText);
|
|
223
198
|
|
|
224
|
-
export const ContentTypeDeleteRequest
|
|
225
|
-
authorityId: 'stage.box',
|
|
226
|
-
typeId: 'deleteRequest',
|
|
227
|
-
versionMajor: 1,
|
|
228
|
-
versionMinor: 0,
|
|
229
|
-
};
|
|
199
|
+
export const ContentTypeDeleteRequest = contentTypeId('stage.box', 'deleteRequest');
|
|
230
200
|
const DeleteRequestCodec = makeJsonCodec<{ messageId: string }>(ContentTypeDeleteRequest, () => 'Message deleted');
|
|
231
201
|
|
|
232
|
-
const ContentTypeDeleteMessage
|
|
233
|
-
authorityId: 'xmtp.org',
|
|
234
|
-
typeId: 'deleteMessage',
|
|
235
|
-
versionMajor: 1,
|
|
236
|
-
versionMinor: 0,
|
|
237
|
-
};
|
|
202
|
+
const ContentTypeDeleteMessage = contentTypeId('xmtp.org', 'deleteMessage');
|
|
238
203
|
|
|
239
204
|
const varint = (value: number): number[] => {
|
|
240
205
|
const out: number[] = [];
|
|
@@ -257,18 +222,12 @@ export function encodeDeleteMessage(messageId: string): EncodedContent {
|
|
|
257
222
|
}
|
|
258
223
|
|
|
259
224
|
export const CALL_TYPES = new Set(['callInvite', 'callSignal']);
|
|
260
|
-
const
|
|
261
|
-
authorityId: 'stage.box',
|
|
262
|
-
typeId,
|
|
263
|
-
versionMajor: 1,
|
|
264
|
-
versionMinor: 0,
|
|
265
|
-
});
|
|
266
|
-
const CallInviteCodec = makeJsonCodec<{ video?: unknown }>(callContentType('callInvite'), (c) =>
|
|
225
|
+
const CallInviteCodec = makeJsonCodec<{ video?: unknown }>(contentTypeId('stage.box', 'callInvite'), (c) =>
|
|
267
226
|
c.video === true ? '📞 Video call' : '📞 Voice call',
|
|
268
227
|
);
|
|
269
228
|
export const isCallSignal = (m: { contentType?: ContentTypeId }): boolean =>
|
|
270
229
|
m.contentType?.authorityId === 'stage.box' && m.contentType.typeId === 'callSignal';
|
|
271
|
-
export const CallSignalCodec = makeJsonCodec<Record<string, unknown>>(
|
|
230
|
+
export const CallSignalCodec = makeJsonCodec<Record<string, unknown>>(contentTypeId('stage.box', 'callSignal'), () => undefined, false);
|
|
272
231
|
|
|
273
232
|
export const CODECS = (): ContentCodec[] => [
|
|
274
233
|
new PollCodec(),
|
|
@@ -6,8 +6,6 @@ import type { MemberList, MetroMember } from '@metro-labs/core/stations/types';
|
|
|
6
6
|
import { readAppData, readAppDataObject, type GroupLike } from './labels.js';
|
|
7
7
|
import { network, syncConversation } from './network.js';
|
|
8
8
|
|
|
9
|
-
export { parseMemberArgs, resolveMembers } from './member-args.js';
|
|
10
|
-
|
|
11
9
|
type Conv = Awaited<ReturnType<typeof convOf>>['conv'] & object;
|
|
12
10
|
export interface EthId {
|
|
13
11
|
identifier: string;
|
|
@@ -56,9 +54,7 @@ export async function resolveAddresses(
|
|
|
56
54
|
if (!missing.length) return addresses;
|
|
57
55
|
try {
|
|
58
56
|
const states = await acct.client.preferences.fetchInboxStates(missing);
|
|
59
|
-
for (
|
|
60
|
-
const key = missing[i];
|
|
61
|
-
if (key === undefined) continue;
|
|
57
|
+
for (const [i, key] of missing.entries()) {
|
|
62
58
|
const eth = states[i]?.identifiers.find(
|
|
63
59
|
(it: { identifierKind: IdentifierKind }) =>
|
|
64
60
|
it.identifierKind === IdentifierKind.Ethereum,
|
|
@@ -71,7 +67,6 @@ export async function resolveAddresses(
|
|
|
71
67
|
} catch (error) {
|
|
72
68
|
network.note(error);
|
|
73
69
|
if (network.remaining() > 0) throw error;
|
|
74
|
-
return addresses;
|
|
75
70
|
}
|
|
76
71
|
return addresses;
|
|
77
72
|
}
|