@stage-labs/metro 0.1.0-beta.274 → 0.1.0-beta.276
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/core/src/stations/attachments.ts +9 -2
- package/runtime/node_modules/@metro-labs/xmtp/src/actions-conv.ts +30 -15
- package/runtime/node_modules/@metro-labs/xmtp/src/read-attachments.ts +37 -0
- package/runtime/node_modules/@metro-labs/xmtp/src/station.ts +1 -0
- package/runtime/runtime.json +1 -1
- package/runtime/sdk-runner/node_modules/@metro-labs/core/src/stations/attachments.ts +9 -2
- package/runtime/sdk-runner/runner.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.276",
|
|
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",
|
|
@@ -106,9 +106,16 @@ export const saveBufferToCache = async (
|
|
|
106
106
|
meta: { mime?: string; name?: string },
|
|
107
107
|
): Promise<SavedAttachment> => {
|
|
108
108
|
assertAttachmentSize(data.length);
|
|
109
|
-
const { writeFile } = await import('node:fs/promises');
|
|
109
|
+
const { writeFile, rename, rm } = await import('node:fs/promises');
|
|
110
|
+
const { randomUUID } = await import('node:crypto');
|
|
110
111
|
const path = await cachePathFor(messageId, index, meta);
|
|
111
|
-
await
|
|
112
|
+
const part = `${await cachePathFor(randomUUID(), index, meta)}.part`;
|
|
113
|
+
try {
|
|
114
|
+
await writeFile(part, data);
|
|
115
|
+
await rename(part, path);
|
|
116
|
+
} finally {
|
|
117
|
+
await rm(part, { force: true });
|
|
118
|
+
}
|
|
112
119
|
return { path, mime: meta.mime, name: meta.name, bytes: data.length };
|
|
113
120
|
};
|
|
114
121
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { IdentifierKind, type DecodedMessage } from '@xmtp/node-sdk';
|
|
2
|
-
import { accountForCall, convOf, lineOf,
|
|
2
|
+
import { accountForCall, convOf, lineOf, type Account } from './accounts.js';
|
|
3
3
|
import { respond } from '@metro-labs/core/stations/station-runtime';
|
|
4
4
|
import { resolveMsgId } from './wire.js';
|
|
5
|
-
import { TrainError } from '@metro-labs/core/train-error';
|
|
5
|
+
import { serializeTrainError, TrainError } from '@metro-labs/core/train-error';
|
|
6
6
|
import {
|
|
7
7
|
buildGroupInfo,
|
|
8
8
|
buildMemberList,
|
|
@@ -17,6 +17,7 @@ import { updateChannelMeta } from './actions-meta.js';
|
|
|
17
17
|
import { deletedByRequests, isDeleteRequest, superAdminCheck } from './delete-requests.js';
|
|
18
18
|
import { isCallSignal } from './codecs.js';
|
|
19
19
|
import { syncConversation } from './network.js';
|
|
20
|
+
import { readAttachments } from './read-attachments.js';
|
|
20
21
|
|
|
21
22
|
type Args = Record<string, unknown>;
|
|
22
23
|
type Handler = (id: string, args: Args) => Promise<void>;
|
|
@@ -56,27 +57,41 @@ function textOf(m: DecodedMessage): string {
|
|
|
56
57
|
|
|
57
58
|
const DELETED = { text: '[deletedMessage]', contentType: 'deletedMessage' };
|
|
58
59
|
|
|
60
|
+
function messageOf(acct: Account, m: DecodedMessage, deleted: Set<string>): Record<string, unknown> {
|
|
61
|
+
return {
|
|
62
|
+
id: m.id,
|
|
63
|
+
ts: new Date(Number(m.sentAtNs / 1_000_000n)).toISOString(),
|
|
64
|
+
from: `metro://xmtp/${acct.cfg.id}/user/${m.senderInboxId}`,
|
|
65
|
+
...(m.senderInboxId === acct.inboxId ? { self: true } : {}),
|
|
66
|
+
...(deleted.has(m.id) ? DELETED : { text: textOf(m), contentType: m.contentType?.typeId ?? 'unknown' }),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
59
70
|
async function read(id: string, args: Args): Promise<void> {
|
|
60
|
-
const { line, limit, before } = args as { line: string; limit?: number; before?: string };
|
|
71
|
+
const { line, limit, before, messageId } = args as { line: string; limit?: number; before?: string; messageId?: string };
|
|
61
72
|
const { acct, conv } = await convOf(line);
|
|
62
73
|
if (!conv)
|
|
63
74
|
throw new TrainError('NOT_FOUND', `conversation not found for ${line}`);
|
|
64
|
-
const lim = Math.min(Math.max(1, limit ?? 20), 200);
|
|
65
75
|
await syncConversation(acct.client, conv);
|
|
66
76
|
const all = await conv.messages();
|
|
77
|
+
if (messageId) {
|
|
78
|
+
const target = resolveMsgId(messageId);
|
|
79
|
+
const message = acct.client.conversations.getMessageById(target);
|
|
80
|
+
if (message?.conversationId !== conv.id || isDeleteRequest(message) || isCallSignal(message))
|
|
81
|
+
throw new TrainError('NOT_FOUND', `message ${messageId} is not in this conversation`);
|
|
82
|
+
const deleted = deletedByRequests([...all, message], superAdminCheck(conv));
|
|
83
|
+
try {
|
|
84
|
+
const attachments = deleted.has(message.id) ? [] : await readAttachments(message);
|
|
85
|
+
respond(id, { result: { line, account: acct.cfg.id, message: { ...messageOf(acct, message, deleted), attachments } } });
|
|
86
|
+
} catch (error) {
|
|
87
|
+
respond(id, serializeTrainError(error));
|
|
88
|
+
}
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const lim = Math.min(Math.max(1, limit ?? 20), 200);
|
|
67
92
|
const deleted = deletedByRequests(all, superAdminCheck(conv));
|
|
68
93
|
const slice = upTo(all.filter((m) => !isDeleteRequest(m) && !isCallSignal(m)), before).slice(-lim);
|
|
69
|
-
const
|
|
70
|
-
if (!parsed)
|
|
71
|
-
throw new TrainError('NOT_FOUND', `could not parse line ${line}`);
|
|
72
|
-
const acctId = parsed.accountId;
|
|
73
|
-
const messages = slice.map((m) => ({
|
|
74
|
-
id: m.id,
|
|
75
|
-
ts: new Date(Number(m.sentAtNs / 1_000_000n)).toISOString(),
|
|
76
|
-
from: `metro://xmtp/${acctId}/user/${m.senderInboxId}`,
|
|
77
|
-
...(m.senderInboxId === acct.inboxId ? { self: true } : {}),
|
|
78
|
-
...(deleted.has(m.id) ? DELETED : { text: textOf(m), contentType: m.contentType?.typeId ?? 'unknown' }),
|
|
79
|
-
}));
|
|
94
|
+
const messages = slice.map((m) => messageOf(acct, m, deleted));
|
|
80
95
|
respond(id, { result: { line, count: messages.length, messages } });
|
|
81
96
|
}
|
|
82
97
|
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { DecodedMessage } from '@xmtp/node-sdk';
|
|
2
|
+
import { kindOf } from '@metro-labs/core/stations/attachments';
|
|
3
|
+
import { saveInlineAttachment, saveRemoteAttachment, type RemoteEntry, type SavedAttachment } from './attachments.js';
|
|
4
|
+
|
|
5
|
+
interface ReadAttachment {
|
|
6
|
+
name?: string;
|
|
7
|
+
mime?: string;
|
|
8
|
+
kind: string;
|
|
9
|
+
size: number;
|
|
10
|
+
local_path: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function fileOf(saved: SavedAttachment): ReadAttachment {
|
|
14
|
+
return {
|
|
15
|
+
name: saved.name,
|
|
16
|
+
mime: saved.mime,
|
|
17
|
+
kind: kindOf(saved.mime ?? '', saved.path),
|
|
18
|
+
size: saved.bytes,
|
|
19
|
+
local_path: saved.path,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export async function readAttachments(message: DecodedMessage): Promise<ReadAttachment[]> {
|
|
24
|
+
const type = message.contentType?.typeId;
|
|
25
|
+
if (type === 'attachment') {
|
|
26
|
+
const content = message.content as { filename?: string; mimeType?: string; content: Uint8Array };
|
|
27
|
+
return [fileOf(await saveInlineAttachment(content, message.id))];
|
|
28
|
+
}
|
|
29
|
+
if (type === 'remoteStaticAttachment')
|
|
30
|
+
return [fileOf(await saveRemoteAttachment(message.content as RemoteEntry, message.id))];
|
|
31
|
+
if (type === 'multiRemoteStaticAttachment' || type === 'multiRemoteAttachment') {
|
|
32
|
+
const content = message.content as { attachments: RemoteEntry[] };
|
|
33
|
+
return Promise.all(content.attachments.map(async (entry, index) =>
|
|
34
|
+
fileOf(await saveRemoteAttachment(entry, message.id, index))));
|
|
35
|
+
}
|
|
36
|
+
return [];
|
|
37
|
+
}
|
|
@@ -7,6 +7,7 @@ export const xmtpStation: Station = {
|
|
|
7
7
|
hasAccounts: true,
|
|
8
8
|
hasTrain: true,
|
|
9
9
|
messageVerbs: new Set<Verb>(['send', 'reply', 'react', 'unreact', 'delete', 'read']),
|
|
10
|
+
readFilters: new Set(['message_id']),
|
|
10
11
|
groupOps: new Set<GroupOp>(['create_group', 'add_members', 'remove_members']),
|
|
11
12
|
attachmentMode: 'native',
|
|
12
13
|
profileFields: new Set<ProfileField>(PROFILE_FIELDS),
|
package/runtime/runtime.json
CHANGED
|
@@ -106,9 +106,16 @@ export const saveBufferToCache = async (
|
|
|
106
106
|
meta: { mime?: string; name?: string },
|
|
107
107
|
): Promise<SavedAttachment> => {
|
|
108
108
|
assertAttachmentSize(data.length);
|
|
109
|
-
const { writeFile } = await import('node:fs/promises');
|
|
109
|
+
const { writeFile, rename, rm } = await import('node:fs/promises');
|
|
110
|
+
const { randomUUID } = await import('node:crypto');
|
|
110
111
|
const path = await cachePathFor(messageId, index, meta);
|
|
111
|
-
await
|
|
112
|
+
const part = `${await cachePathFor(randomUUID(), index, meta)}.part`;
|
|
113
|
+
try {
|
|
114
|
+
await writeFile(part, data);
|
|
115
|
+
await rename(part, path);
|
|
116
|
+
} finally {
|
|
117
|
+
await rm(part, { force: true });
|
|
118
|
+
}
|
|
112
119
|
return { path, mime: meta.mime, name: meta.name, bytes: data.length };
|
|
113
120
|
};
|
|
114
121
|
|