@zooid/transport-matrix 0.7.4 → 0.9.0
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.d.ts +116 -1
- package/dist/index.js +387 -51
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/attachments.test.ts +58 -0
- package/src/attachments.ts +30 -0
- package/src/bot-pool.ts +1 -1
- package/src/context-provider.test.ts +33 -0
- package/src/context-provider.ts +22 -4
- package/src/event-encoders.test.ts +22 -0
- package/src/event-encoders.ts +13 -0
- package/src/index.ts +8 -2
- package/src/matrix-client.test.ts +35 -2
- package/src/matrix-client.ts +19 -0
- package/src/media-client.test.ts +102 -0
- package/src/media-client.ts +69 -0
- package/src/pending-media.test.ts +51 -0
- package/src/pending-media.ts +37 -0
- package/src/router.test.ts +22 -1
- package/src/router.ts +11 -0
- package/src/space-provisioner.test.ts +26 -1
- package/src/space-provisioner.ts +15 -4
- package/src/transport.test.ts +401 -30
- package/src/transport.ts +402 -70
- package/src/workforce-publisher.test.ts +2 -2
- package/src/workforce-publisher.ts +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -92,6 +92,9 @@ declare class MatrixClient {
|
|
|
92
92
|
asUserId: string;
|
|
93
93
|
targetUserId: string;
|
|
94
94
|
}): Promise<void>;
|
|
95
|
+
leaveRoom(roomId: string, asUserId: string, opts?: {
|
|
96
|
+
reason?: string;
|
|
97
|
+
}): Promise<void>;
|
|
95
98
|
joinRoom(roomIdOrAlias: string, asUserId: string): Promise<void>;
|
|
96
99
|
sendMessage(input: SendMessageInput): Promise<{
|
|
97
100
|
event_id: string;
|
|
@@ -221,7 +224,13 @@ interface AgentBinding {
|
|
|
221
224
|
*/
|
|
222
225
|
rooms: RoomBinding[];
|
|
223
226
|
trigger: 'mention' | 'any';
|
|
227
|
+
/** Host path of the agent's workspace (resolved agent.workdir). Media files land here. */
|
|
228
|
+
workspaceDir?: string;
|
|
229
|
+
/** Path prefix as the agent sees it: '/workspace' for containers, = workspaceDir for local. */
|
|
230
|
+
agentWorkspacePath?: string;
|
|
224
231
|
}
|
|
232
|
+
declare const MEDIA_MSGTYPES: Set<string>;
|
|
233
|
+
declare function isMediaMsgtype(t: string | undefined): boolean;
|
|
225
234
|
interface ThreadState {
|
|
226
235
|
/** Agent names that have posted in this thread, in order. */
|
|
227
236
|
participants: string[];
|
|
@@ -266,6 +275,36 @@ declare class BotPool {
|
|
|
266
275
|
findByName(name: string): AgentBinding | undefined;
|
|
267
276
|
}
|
|
268
277
|
|
|
278
|
+
interface WriteAttachmentInput {
|
|
279
|
+
workspaceDir: string;
|
|
280
|
+
agentWorkspacePath: string;
|
|
281
|
+
eventId: string;
|
|
282
|
+
filename: string;
|
|
283
|
+
data: Uint8Array;
|
|
284
|
+
}
|
|
285
|
+
declare function writeAttachment(input: WriteAttachmentInput): {
|
|
286
|
+
hostPath: string;
|
|
287
|
+
agentPath: string;
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
interface MediaClientLike {
|
|
291
|
+
download(input: {
|
|
292
|
+
mxcUri: string;
|
|
293
|
+
asUserId: string;
|
|
294
|
+
maxBytes?: number;
|
|
295
|
+
}): Promise<{
|
|
296
|
+
data: Uint8Array;
|
|
297
|
+
contentType: string;
|
|
298
|
+
}>;
|
|
299
|
+
upload(input: {
|
|
300
|
+
data: Uint8Array;
|
|
301
|
+
contentType: string;
|
|
302
|
+
filename?: string;
|
|
303
|
+
asUserId: string;
|
|
304
|
+
}): Promise<{
|
|
305
|
+
content_uri: string;
|
|
306
|
+
}>;
|
|
307
|
+
}
|
|
269
308
|
interface CreateMatrixTransportOptions {
|
|
270
309
|
agents: AcpRegistry;
|
|
271
310
|
approvals: ApprovalCorrelator;
|
|
@@ -280,6 +319,14 @@ interface CreateMatrixTransportOptions {
|
|
|
280
319
|
drainQuietMs?: number;
|
|
281
320
|
/** Hard cap on the post-turn drain. Defaults to `DRAIN_MAX_MS`. */
|
|
282
321
|
drainMaxMs?: number;
|
|
322
|
+
/** Injected media client for downloading/uploading Matrix media. */
|
|
323
|
+
media?: MediaClientLike;
|
|
324
|
+
/** Injected attachment writer (defaults to the real writeAttachment). */
|
|
325
|
+
writeAttachmentFn?: typeof writeAttachment;
|
|
326
|
+
/** AS sender-bot MXID (@<sender_localpart>:<server>). Together with the agent
|
|
327
|
+
* bindings this forms the set of "our bot users" whose ad-hoc invites are
|
|
328
|
+
* declined. */
|
|
329
|
+
botUserId?: string;
|
|
283
330
|
}
|
|
284
331
|
declare function createMatrixTransport(opts: CreateMatrixTransportOptions): {
|
|
285
332
|
app: Hono<hono_types.BlankEnv, hono_types.BlankSchema, "/">;
|
|
@@ -304,6 +351,15 @@ interface EnsureSpaceOpts {
|
|
|
304
351
|
* if the alias already resolves we return the existing room untouched.
|
|
305
352
|
*/
|
|
306
353
|
admins?: string[];
|
|
354
|
+
/**
|
|
355
|
+
* Join rule pinned on the space at creation. Defaults to `invite`: a
|
|
356
|
+
* workspace is joined by invitation, not self-service, so it can't be walked
|
|
357
|
+
* into (which would otherwise satisfy every restricted child room's `allow`).
|
|
358
|
+
* `zooid dev` passes `public` so a self-service-registered local account can
|
|
359
|
+
* join `#<space>` straight from the web client without an invite — acceptable
|
|
360
|
+
* because the dev homeserver is local-only and never deployed.
|
|
361
|
+
*/
|
|
362
|
+
joinRule?: 'invite' | 'public';
|
|
307
363
|
}
|
|
308
364
|
declare function ensureWorkforceSpace(opts: EnsureSpaceOpts): Promise<string>;
|
|
309
365
|
interface EnsureDefaultChannelOpts {
|
|
@@ -359,4 +415,63 @@ interface StartOpts {
|
|
|
359
415
|
}
|
|
360
416
|
declare function startWorkforcePublisher(opts: StartOpts): Promise<PublisherHandle>;
|
|
361
417
|
|
|
362
|
-
|
|
418
|
+
/** Limits are routing policy, not enforcement — see ZOD057 (enforcement lives
|
|
419
|
+
* in Tuwunel config + the Zoon composer). */
|
|
420
|
+
declare const MAX_INLINE_IMAGE_BYTES = 524288;
|
|
421
|
+
declare const INLINE_IMAGE_MIMES: string[];
|
|
422
|
+
declare const MAX_DOWNLOAD_BYTES = 33554432;
|
|
423
|
+
interface MediaClientOptions {
|
|
424
|
+
homeserver: string;
|
|
425
|
+
asToken: string;
|
|
426
|
+
fetch?: typeof globalThis.fetch;
|
|
427
|
+
}
|
|
428
|
+
declare function parseMxcUri(uri: string): {
|
|
429
|
+
serverName: string;
|
|
430
|
+
mediaId: string;
|
|
431
|
+
} | null;
|
|
432
|
+
declare class MediaClient {
|
|
433
|
+
private readonly homeserver;
|
|
434
|
+
private readonly asToken;
|
|
435
|
+
private readonly fetch;
|
|
436
|
+
constructor(opts: MediaClientOptions);
|
|
437
|
+
download(input: {
|
|
438
|
+
mxcUri: string;
|
|
439
|
+
asUserId: string;
|
|
440
|
+
maxBytes?: number;
|
|
441
|
+
}): Promise<{
|
|
442
|
+
data: Uint8Array;
|
|
443
|
+
contentType: string;
|
|
444
|
+
}>;
|
|
445
|
+
upload(input: {
|
|
446
|
+
data: Uint8Array;
|
|
447
|
+
contentType: string;
|
|
448
|
+
filename?: string;
|
|
449
|
+
asUserId: string;
|
|
450
|
+
}): Promise<{
|
|
451
|
+
content_uri: string;
|
|
452
|
+
}>;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
declare const MAX_MEDIA_PER_TURN = 8;
|
|
456
|
+
interface PendingMediaItem {
|
|
457
|
+
eventId: string;
|
|
458
|
+
sender: string;
|
|
459
|
+
msgtype: string;
|
|
460
|
+
body: string;
|
|
461
|
+
filename?: string;
|
|
462
|
+
url: string;
|
|
463
|
+
info?: {
|
|
464
|
+
mimetype?: string;
|
|
465
|
+
size?: number;
|
|
466
|
+
w?: number;
|
|
467
|
+
h?: number;
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
declare class PendingMediaStore {
|
|
471
|
+
private readonly queues;
|
|
472
|
+
private key;
|
|
473
|
+
add(roomId: string, threadKey: string | undefined, item: PendingMediaItem): void;
|
|
474
|
+
drain(roomId: string, threadKey: string | undefined, sender: string): PendingMediaItem[];
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
export { type AgentBinding, BotPool, type CreateMatrixTransportOptions, type EnsureDefaultChannelOpts, type EnsureSpaceOpts, INLINE_IMAGE_MIMES, MAX_DOWNLOAD_BYTES, MAX_INLINE_IMAGE_BYTES, MAX_MEDIA_PER_TURN, MEDIA_MSGTYPES, MatrixClient, type MatrixClientOptions, MatrixContextProvider, type MatrixContextProviderOpts, type MatrixTransportConfig, type MaybeMessage, MediaClient, type MediaClientLike, type MediaClientOptions, type PendingMediaItem, PendingMediaStore, type PublishOpts, type PublisherHandle, type RouteMatch, type SendCustomEventInput, type SendMessageInput, type StartOpts as StartWorkforcePublisherOpts, type WorkforceRoster, type WriteAttachmentInput, buildWorkforceRoster, createMatrixTransport, ensureDefaultChannel, ensureWorkforceSpace, extractMentions, isMediaMsgtype, parseMxcUri, publishWorkforce, renderRegistration, route, serverNameFromMxid, startWorkforcePublisher, writeAttachment };
|