@zooid/transport-matrix 0.8.0 → 0.9.1
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 +84 -1
- package/dist/index.js +366 -194
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/bot-pool.test.ts +7 -1
- package/src/bot-pool.ts +8 -2
- package/src/context-provider.ts +1 -1
- package/src/event-encoders.test.ts +22 -0
- package/src/event-encoders.ts +13 -0
- package/src/identity.test.ts +52 -0
- package/src/identity.ts +27 -0
- package/src/index.ts +11 -0
- package/src/matrix-client.test.ts +58 -2
- package/src/matrix-client.ts +51 -0
- package/src/registration.test.ts +20 -0
- package/src/sync-loop.test.ts +113 -0
- package/src/sync-loop.ts +74 -0
- package/src/transport.test.ts +161 -32
- package/src/transport.ts +423 -280
- 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;
|
|
@@ -152,6 +155,22 @@ declare class MatrixClient {
|
|
|
152
155
|
display_name?: string;
|
|
153
156
|
}>;
|
|
154
157
|
}>;
|
|
158
|
+
sync(opts: {
|
|
159
|
+
asUserId: string;
|
|
160
|
+
since?: string | null;
|
|
161
|
+
timeoutMs?: number;
|
|
162
|
+
}): Promise<{
|
|
163
|
+
next_batch: string;
|
|
164
|
+
rooms: {
|
|
165
|
+
join: Record<string, {
|
|
166
|
+
timeline: {
|
|
167
|
+
events: Record<string, unknown>[];
|
|
168
|
+
prev_batch?: string;
|
|
169
|
+
limited?: boolean;
|
|
170
|
+
};
|
|
171
|
+
}>;
|
|
172
|
+
};
|
|
173
|
+
}>;
|
|
155
174
|
fetchRoomName(roomId: string, asUserId: string): Promise<string | null>;
|
|
156
175
|
private sendEvent;
|
|
157
176
|
}
|
|
@@ -197,6 +216,17 @@ interface MatrixTransportConfig {
|
|
|
197
216
|
}
|
|
198
217
|
declare function renderRegistration(c: MatrixTransportConfig): string;
|
|
199
218
|
|
|
219
|
+
declare const SLUG_RE: RegExp;
|
|
220
|
+
declare const AGENT_KEY_RE: RegExp;
|
|
221
|
+
declare const isValidWorkstation: (s: string) => boolean;
|
|
222
|
+
declare const isValidAgentKey: (s: string) => boolean;
|
|
223
|
+
declare function agentMxid(workstation: string, agent: string, serverName: string): string;
|
|
224
|
+
declare function splitAgentLocalpart(localpart: string): {
|
|
225
|
+
workstation: string;
|
|
226
|
+
agent: string;
|
|
227
|
+
};
|
|
228
|
+
declare function workstationUserNamespace(workstation: string, serverName: string): string;
|
|
229
|
+
|
|
200
230
|
interface MaybeMessage {
|
|
201
231
|
content?: {
|
|
202
232
|
'm.mentions'?: {
|
|
@@ -284,6 +314,44 @@ declare function writeAttachment(input: WriteAttachmentInput): {
|
|
|
284
314
|
agentPath: string;
|
|
285
315
|
};
|
|
286
316
|
|
|
317
|
+
interface SyncResponse {
|
|
318
|
+
next_batch: string;
|
|
319
|
+
rooms?: {
|
|
320
|
+
join?: Record<string, {
|
|
321
|
+
timeline?: {
|
|
322
|
+
events?: Record<string, unknown>[];
|
|
323
|
+
prev_batch?: string;
|
|
324
|
+
limited?: boolean;
|
|
325
|
+
};
|
|
326
|
+
}>;
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
interface SyncClient {
|
|
330
|
+
sync(opts: {
|
|
331
|
+
asUserId: string;
|
|
332
|
+
since: string | null;
|
|
333
|
+
timeoutMs: number;
|
|
334
|
+
}): Promise<SyncResponse>;
|
|
335
|
+
}
|
|
336
|
+
interface SyncLoopOptions {
|
|
337
|
+
client: SyncClient;
|
|
338
|
+
asUserId: string;
|
|
339
|
+
loadSince: () => string | null;
|
|
340
|
+
saveSince: (since: string) => void;
|
|
341
|
+
onEvent: (evt: Record<string, unknown>) => void | Promise<void>;
|
|
342
|
+
timeoutMs?: number;
|
|
343
|
+
/** Backoff after a failed tick before retrying. Default 5000ms. */
|
|
344
|
+
retryDelayMs?: number;
|
|
345
|
+
}
|
|
346
|
+
declare class SyncLoop {
|
|
347
|
+
private readonly opts;
|
|
348
|
+
private running;
|
|
349
|
+
constructor(opts: SyncLoopOptions);
|
|
350
|
+
tick(): Promise<void>;
|
|
351
|
+
run(): Promise<void>;
|
|
352
|
+
stop(): void;
|
|
353
|
+
}
|
|
354
|
+
|
|
287
355
|
interface MediaClientLike {
|
|
288
356
|
download(input: {
|
|
289
357
|
mxcUri: string;
|
|
@@ -320,9 +388,24 @@ interface CreateMatrixTransportOptions {
|
|
|
320
388
|
media?: MediaClientLike;
|
|
321
389
|
/** Injected attachment writer (defaults to the real writeAttachment). */
|
|
322
390
|
writeAttachmentFn?: typeof writeAttachment;
|
|
391
|
+
/** AS sender-bot MXID (@<sender_localpart>:<server>). Together with the agent
|
|
392
|
+
* bindings this forms the set of "our bot users" whose ad-hoc invites are
|
|
393
|
+
* declined. */
|
|
394
|
+
botUserId?: string;
|
|
395
|
+
/**
|
|
396
|
+
* Transport ingestion mode.
|
|
397
|
+
* - `'appservice'` (default): Tuwunel pushes events to the HTTP transaction endpoint.
|
|
398
|
+
* - `'client'`: daemon polls via impersonated `/sync` per agent (pull mode).
|
|
399
|
+
*/
|
|
400
|
+
mode?: 'appservice' | 'client';
|
|
401
|
+
/** Pull mode: load the persisted `since` cursor for an agent user ID. */
|
|
402
|
+
loadSince?: (agentUserId: string) => string | null;
|
|
403
|
+
/** Pull mode: persist the `since` cursor after each sync poll. */
|
|
404
|
+
saveSince?: (agentUserId: string, since: string) => void;
|
|
323
405
|
}
|
|
324
406
|
declare function createMatrixTransport(opts: CreateMatrixTransportOptions): {
|
|
325
407
|
app: Hono<hono_types.BlankEnv, hono_types.BlankSchema, "/">;
|
|
408
|
+
syncLoops: SyncLoop[] | undefined;
|
|
326
409
|
bootstrap: (bootstrapOpts?: {
|
|
327
410
|
spaceRoomId?: string;
|
|
328
411
|
asUserId?: string;
|
|
@@ -467,4 +550,4 @@ declare class PendingMediaStore {
|
|
|
467
550
|
drain(roomId: string, threadKey: string | undefined, sender: string): PendingMediaItem[];
|
|
468
551
|
}
|
|
469
552
|
|
|
470
|
-
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 };
|
|
553
|
+
export { AGENT_KEY_RE, 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, SLUG_RE, type SendCustomEventInput, type SendMessageInput, type StartOpts as StartWorkforcePublisherOpts, type SyncClient, SyncLoop, type SyncLoopOptions, type SyncResponse, type WorkforceRoster, type WriteAttachmentInput, agentMxid, buildWorkforceRoster, createMatrixTransport, ensureDefaultChannel, ensureWorkforceSpace, extractMentions, isMediaMsgtype, isValidAgentKey, isValidWorkstation, parseMxcUri, publishWorkforce, renderRegistration, route, serverNameFromMxid, splitAgentLocalpart, startWorkforcePublisher, workstationUserNamespace, writeAttachment };
|