@zooid/transport-matrix 0.9.0 → 0.10.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 +85 -1
- package/dist/index.js +312 -197
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/bot-pool.test.ts +130 -1
- package/src/bot-pool.ts +27 -9
- 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 +66 -0
- package/src/matrix-client.ts +40 -1
- package/src/registration.test.ts +20 -0
- package/src/router.test.ts +117 -1
- package/src/router.ts +25 -7
- package/src/sync-loop.test.ts +113 -0
- package/src/sync-loop.ts +74 -0
- package/src/transport.test.ts +107 -1
- package/src/transport.ts +290 -251
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'?: {
|
|
@@ -236,6 +263,14 @@ interface ThreadState {
|
|
|
236
263
|
participants: string[];
|
|
237
264
|
/** Agent names @mentioned in the thread root event (or subsequently). */
|
|
238
265
|
rootMentions: string[];
|
|
266
|
+
/**
|
|
267
|
+
* Agent-to-agent call edges: sub-agent name → the agent that @mentioned
|
|
268
|
+
* (called) it in this thread. A sub's bare reply bubbles up to its caller;
|
|
269
|
+
* a caller never implicitly re-triggers its callee. Makes agent↔agent
|
|
270
|
+
* acknowledgement loops structurally impossible. See [[ZOD039]] §
|
|
271
|
+
* Implicit triggers → Directional continuation.
|
|
272
|
+
*/
|
|
273
|
+
callers: Record<string, string>;
|
|
239
274
|
}
|
|
240
275
|
interface MaybeEvent {
|
|
241
276
|
type?: string;
|
|
@@ -287,6 +322,44 @@ declare function writeAttachment(input: WriteAttachmentInput): {
|
|
|
287
322
|
agentPath: string;
|
|
288
323
|
};
|
|
289
324
|
|
|
325
|
+
interface SyncResponse {
|
|
326
|
+
next_batch: string;
|
|
327
|
+
rooms?: {
|
|
328
|
+
join?: Record<string, {
|
|
329
|
+
timeline?: {
|
|
330
|
+
events?: Record<string, unknown>[];
|
|
331
|
+
prev_batch?: string;
|
|
332
|
+
limited?: boolean;
|
|
333
|
+
};
|
|
334
|
+
}>;
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
interface SyncClient {
|
|
338
|
+
sync(opts: {
|
|
339
|
+
asUserId: string;
|
|
340
|
+
since: string | null;
|
|
341
|
+
timeoutMs: number;
|
|
342
|
+
}): Promise<SyncResponse>;
|
|
343
|
+
}
|
|
344
|
+
interface SyncLoopOptions {
|
|
345
|
+
client: SyncClient;
|
|
346
|
+
asUserId: string;
|
|
347
|
+
loadSince: () => string | null;
|
|
348
|
+
saveSince: (since: string) => void;
|
|
349
|
+
onEvent: (evt: Record<string, unknown>) => void | Promise<void>;
|
|
350
|
+
timeoutMs?: number;
|
|
351
|
+
/** Backoff after a failed tick before retrying. Default 5000ms. */
|
|
352
|
+
retryDelayMs?: number;
|
|
353
|
+
}
|
|
354
|
+
declare class SyncLoop {
|
|
355
|
+
private readonly opts;
|
|
356
|
+
private running;
|
|
357
|
+
constructor(opts: SyncLoopOptions);
|
|
358
|
+
tick(): Promise<void>;
|
|
359
|
+
run(): Promise<void>;
|
|
360
|
+
stop(): void;
|
|
361
|
+
}
|
|
362
|
+
|
|
290
363
|
interface MediaClientLike {
|
|
291
364
|
download(input: {
|
|
292
365
|
mxcUri: string;
|
|
@@ -327,9 +400,20 @@ interface CreateMatrixTransportOptions {
|
|
|
327
400
|
* bindings this forms the set of "our bot users" whose ad-hoc invites are
|
|
328
401
|
* declined. */
|
|
329
402
|
botUserId?: string;
|
|
403
|
+
/**
|
|
404
|
+
* Transport ingestion mode.
|
|
405
|
+
* - `'appservice'` (default): Tuwunel pushes events to the HTTP transaction endpoint.
|
|
406
|
+
* - `'client'`: daemon polls via impersonated `/sync` per agent (pull mode).
|
|
407
|
+
*/
|
|
408
|
+
mode?: 'appservice' | 'client';
|
|
409
|
+
/** Pull mode: load the persisted `since` cursor for an agent user ID. */
|
|
410
|
+
loadSince?: (agentUserId: string) => string | null;
|
|
411
|
+
/** Pull mode: persist the `since` cursor after each sync poll. */
|
|
412
|
+
saveSince?: (agentUserId: string, since: string) => void;
|
|
330
413
|
}
|
|
331
414
|
declare function createMatrixTransport(opts: CreateMatrixTransportOptions): {
|
|
332
415
|
app: Hono<hono_types.BlankEnv, hono_types.BlankSchema, "/">;
|
|
416
|
+
syncLoops: SyncLoop[] | undefined;
|
|
333
417
|
bootstrap: (bootstrapOpts?: {
|
|
334
418
|
spaceRoomId?: string;
|
|
335
419
|
asUserId?: string;
|
|
@@ -474,4 +558,4 @@ declare class PendingMediaStore {
|
|
|
474
558
|
drain(roomId: string, threadKey: string | undefined, sender: string): PendingMediaItem[];
|
|
475
559
|
}
|
|
476
560
|
|
|
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 };
|
|
561
|
+
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 };
|