@zooid/transport-matrix 0.9.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 +77 -1
- package/dist/index.js +269 -171
- 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 +7 -1
- 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 +23 -0
- package/src/matrix-client.ts +32 -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.ts +275 -241
package/dist/index.d.ts
CHANGED
|
@@ -155,6 +155,22 @@ declare class MatrixClient {
|
|
|
155
155
|
display_name?: string;
|
|
156
156
|
}>;
|
|
157
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
|
+
}>;
|
|
158
174
|
fetchRoomName(roomId: string, asUserId: string): Promise<string | null>;
|
|
159
175
|
private sendEvent;
|
|
160
176
|
}
|
|
@@ -200,6 +216,17 @@ interface MatrixTransportConfig {
|
|
|
200
216
|
}
|
|
201
217
|
declare function renderRegistration(c: MatrixTransportConfig): string;
|
|
202
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
|
+
|
|
203
230
|
interface MaybeMessage {
|
|
204
231
|
content?: {
|
|
205
232
|
'm.mentions'?: {
|
|
@@ -287,6 +314,44 @@ declare function writeAttachment(input: WriteAttachmentInput): {
|
|
|
287
314
|
agentPath: string;
|
|
288
315
|
};
|
|
289
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
|
+
|
|
290
355
|
interface MediaClientLike {
|
|
291
356
|
download(input: {
|
|
292
357
|
mxcUri: string;
|
|
@@ -327,9 +392,20 @@ interface CreateMatrixTransportOptions {
|
|
|
327
392
|
* bindings this forms the set of "our bot users" whose ad-hoc invites are
|
|
328
393
|
* declined. */
|
|
329
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;
|
|
330
405
|
}
|
|
331
406
|
declare function createMatrixTransport(opts: CreateMatrixTransportOptions): {
|
|
332
407
|
app: Hono<hono_types.BlankEnv, hono_types.BlankSchema, "/">;
|
|
408
|
+
syncLoops: SyncLoop[] | undefined;
|
|
333
409
|
bootstrap: (bootstrapOpts?: {
|
|
334
410
|
spaceRoomId?: string;
|
|
335
411
|
asUserId?: string;
|
|
@@ -474,4 +550,4 @@ declare class PendingMediaStore {
|
|
|
474
550
|
drain(roomId: string, threadKey: string | undefined, sender: string): PendingMediaItem[];
|
|
475
551
|
}
|
|
476
552
|
|
|
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 };
|
|
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 };
|