@celljs/ta-relay 4.9.1 → 4.11.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/README.en.md +29 -2
- package/README.md +29 -2
- package/esm/common/index.d.ts +10 -0
- package/esm/common/index.js +10 -0
- package/esm/common/relay-blobs.d.ts +54 -0
- package/esm/common/relay-blobs.js +153 -0
- package/esm/common/relay-card.d.ts +23 -0
- package/esm/common/relay-card.js +30 -0
- package/esm/common/relay-cipher.d.ts +15 -0
- package/esm/common/relay-cipher.js +62 -2
- package/esm/common/relay-content.d.ts +104 -0
- package/esm/common/relay-content.js +316 -0
- package/esm/common/relay-conversation.d.ts +59 -0
- package/esm/common/relay-conversation.js +9 -0
- package/esm/common/relay-files.d.ts +108 -0
- package/esm/common/relay-files.js +170 -0
- package/esm/common/relay-hub-util.d.ts +91 -0
- package/esm/common/relay-hub-util.js +164 -0
- package/esm/common/relay-hub.d.ts +125 -0
- package/esm/common/relay-hub.js +438 -0
- package/esm/common/relay-hubs.d.ts +271 -0
- package/esm/common/relay-hubs.js +844 -0
- package/esm/common/relay-identity.d.ts +46 -0
- package/esm/common/relay-identity.js +126 -0
- package/esm/common/relay-protocol.d.ts +217 -2
- package/esm/common/relay-protocol.js +53 -0
- package/esm/common/relay-room-chat.d.ts +80 -0
- package/esm/common/relay-room-chat.js +152 -0
- package/esm/common/relay-socket.d.ts +8 -0
- package/esm/common/relay-socket.js +33 -4
- package/esm/guest/guest-i18n.d.ts +47 -0
- package/esm/guest/guest-i18n.js +97 -0
- package/esm/guest/guest-style.d.ts +1 -0
- package/esm/guest/guest-style.js +78 -0
- package/esm/guest/guest.d.ts +1 -0
- package/esm/guest/guest.js +371 -0
- package/esm/node/index.d.ts +3 -0
- package/esm/node/index.js +3 -0
- package/esm/node/relay-files-host.d.ts +27 -0
- package/esm/node/relay-files-host.js +130 -0
- package/esm/node/relay-host.d.ts +35 -2
- package/esm/node/relay-host.js +150 -13
- package/esm/node/relay-hub-files.d.ts +12 -0
- package/esm/node/relay-hub-files.js +39 -0
- package/esm/node/relay-server.d.ts +46 -1
- package/esm/node/relay-server.js +227 -1
- package/esm/node/relay-store.d.ts +72 -0
- package/esm/node/relay-store.js +123 -2
- package/esm/node/relay-viewer.d.ts +7 -0
- package/esm/node/relay-viewer.js +33 -0
- package/esm/viewer/viewer-i18n.d.ts +56 -0
- package/esm/viewer/viewer-i18n.js +117 -0
- package/esm/viewer/viewer-markdown.d.ts +7 -0
- package/esm/viewer/viewer-markdown.js +198 -0
- package/esm/viewer/viewer-style.d.ts +1 -0
- package/esm/viewer/viewer-style.js +72 -0
- package/esm/viewer/viewer.d.ts +8 -0
- package/esm/viewer/viewer.js +378 -0
- package/lib/common/index.d.ts +10 -0
- package/lib/common/index.js +10 -0
- package/lib/common/relay-blobs.d.ts +55 -0
- package/lib/common/relay-blobs.js +157 -0
- package/lib/common/relay-card.d.ts +24 -0
- package/lib/common/relay-card.js +33 -0
- package/lib/common/relay-cipher.d.ts +15 -0
- package/lib/common/relay-cipher.js +63 -3
- package/lib/common/relay-content.d.ts +105 -0
- package/lib/common/relay-content.js +320 -0
- package/lib/common/relay-conversation.d.ts +60 -0
- package/lib/common/relay-conversation.js +12 -0
- package/lib/common/relay-files.d.ts +109 -0
- package/lib/common/relay-files.js +174 -0
- package/lib/common/relay-hub-util.d.ts +92 -0
- package/lib/common/relay-hub-util.js +167 -0
- package/lib/common/relay-hub.d.ts +126 -0
- package/lib/common/relay-hub.js +442 -0
- package/lib/common/relay-hubs.d.ts +272 -0
- package/lib/common/relay-hubs.js +848 -0
- package/lib/common/relay-identity.d.ts +47 -0
- package/lib/common/relay-identity.js +129 -0
- package/lib/common/relay-protocol.d.ts +217 -2
- package/lib/common/relay-protocol.js +54 -1
- package/lib/common/relay-room-chat.d.ts +81 -0
- package/lib/common/relay-room-chat.js +156 -0
- package/lib/common/relay-socket.d.ts +8 -0
- package/lib/common/relay-socket.js +32 -3
- package/lib/guest/guest-i18n.d.ts +48 -0
- package/lib/guest/guest-i18n.js +100 -0
- package/lib/guest/guest-style.d.ts +2 -0
- package/lib/guest/guest-style.js +81 -0
- package/lib/guest/guest.d.ts +2 -0
- package/lib/guest/guest.js +373 -0
- package/lib/node/index.d.ts +3 -0
- package/lib/node/index.js +3 -0
- package/lib/node/relay-files-host.d.ts +28 -0
- package/lib/node/relay-files-host.js +134 -0
- package/lib/node/relay-host.d.ts +35 -2
- package/lib/node/relay-host.js +149 -12
- package/lib/node/relay-hub-files.d.ts +13 -0
- package/lib/node/relay-hub-files.js +43 -0
- package/lib/node/relay-server.d.ts +46 -1
- package/lib/node/relay-server.js +226 -0
- package/lib/node/relay-store.d.ts +72 -0
- package/lib/node/relay-store.js +121 -0
- package/lib/node/relay-viewer.d.ts +8 -0
- package/lib/node/relay-viewer.js +32 -0
- package/lib/viewer/viewer-i18n.d.ts +57 -0
- package/lib/viewer/viewer-i18n.js +120 -0
- package/lib/viewer/viewer-markdown.d.ts +8 -0
- package/lib/viewer/viewer-markdown.js +201 -0
- package/lib/viewer/viewer-style.d.ts +2 -0
- package/lib/viewer/viewer-style.js +75 -0
- package/lib/viewer/viewer.d.ts +9 -0
- package/lib/viewer/viewer.js +381 -0
- package/package.json +5 -4
- package/viewer/frame.html +1 -0
- package/viewer/page.html +80 -0
- package/viewer/room.html +87 -0
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { type RelayHubAskBody, type RelayHubKeys, type RelayHubMember, type RelayHubRosterBody } from './relay-hub-util.js';
|
|
2
|
+
import { type RelayIdentity, type RelayPublicIdentity } from './relay-identity.js';
|
|
3
|
+
import { type RelayHubEntry, type RelayHubFailure, type RelayHubRequest } from './relay-protocol.js';
|
|
4
|
+
/** `member` in the room; `waiting` for the owner to answer; `refused` by the owner; `gone`: closed, removed, or the invitation no longer works. */
|
|
5
|
+
export type RelayRoomStatus = 'member' | 'waiting' | 'refused' | 'gone';
|
|
6
|
+
/** A room this Ta is in or asked to join, in `rooms.json` of the agent directory (docs/design/ta-link.md 3.5). */
|
|
7
|
+
export interface RelayRoomRecord {
|
|
8
|
+
id: string;
|
|
9
|
+
relay: string;
|
|
10
|
+
kind: string;
|
|
11
|
+
title: string;
|
|
12
|
+
view?: string;
|
|
13
|
+
/** This Ta's id in the room, and what the relay knows it by. */
|
|
14
|
+
member: string;
|
|
15
|
+
token: string;
|
|
16
|
+
/** base64url, 32 bytes: the key of the room, once admitted. */
|
|
17
|
+
key?: string;
|
|
18
|
+
/** The owner: all of it once admitted (its keys check the roster), its id and name from the link before. */
|
|
19
|
+
owner: Pick<RelayPublicIdentity, 'id' | 'name'> & Partial<RelayPublicIdentity>;
|
|
20
|
+
/** This Ta made the room. */
|
|
21
|
+
own: boolean;
|
|
22
|
+
status: RelayRoomStatus;
|
|
23
|
+
/** Why it is `gone`: `closed` by the owner, `removed` by the owner, the `invite` no longer works. */
|
|
24
|
+
reason?: 'closed' | 'removed' | 'invite';
|
|
25
|
+
/** Of the owner: the invitations of late, the latest last; an ask is sealed with one of them. */
|
|
26
|
+
invites?: {
|
|
27
|
+
secret: string;
|
|
28
|
+
expiresAt: number;
|
|
29
|
+
}[];
|
|
30
|
+
/** Of the owner: the relay has the room. */
|
|
31
|
+
made?: boolean;
|
|
32
|
+
/** Of one asking: the invitation, till the relay has the ask. */
|
|
33
|
+
invite?: string;
|
|
34
|
+
asked?: boolean;
|
|
35
|
+
createdAt: number;
|
|
36
|
+
joinedAt?: number;
|
|
37
|
+
}
|
|
38
|
+
export interface RelayRoomMember {
|
|
39
|
+
member: string;
|
|
40
|
+
/** The identity of its Ta. */
|
|
41
|
+
id: string;
|
|
42
|
+
name: string;
|
|
43
|
+
owner: boolean;
|
|
44
|
+
online: boolean;
|
|
45
|
+
self: boolean;
|
|
46
|
+
/** In a browser, without Ta: it only chats (docs/design/ta-link.md 3.8). */
|
|
47
|
+
guest?: boolean;
|
|
48
|
+
}
|
|
49
|
+
export interface RelayRoomInfo {
|
|
50
|
+
id: string;
|
|
51
|
+
kind: string;
|
|
52
|
+
title: string;
|
|
53
|
+
view?: string;
|
|
54
|
+
owner: boolean;
|
|
55
|
+
ownerName: string;
|
|
56
|
+
status: RelayRoomStatus;
|
|
57
|
+
reason?: RelayRoomRecord['reason'];
|
|
58
|
+
/** This Ta is connected to the room now. */
|
|
59
|
+
connected: boolean;
|
|
60
|
+
members: RelayRoomMember[];
|
|
61
|
+
createdAt: number;
|
|
62
|
+
joinedAt?: number;
|
|
63
|
+
}
|
|
64
|
+
/** One asking to join a room this Ta owns, till the user answers. */
|
|
65
|
+
export interface RelayRoomRequest {
|
|
66
|
+
room: string;
|
|
67
|
+
title: string;
|
|
68
|
+
ask: string;
|
|
69
|
+
/** Its identity, and the name it gives. */
|
|
70
|
+
id: string;
|
|
71
|
+
name: string;
|
|
72
|
+
/** Met before, in another room. */
|
|
73
|
+
friend: boolean;
|
|
74
|
+
/** Asks from a browser, without Ta: admitted, it only chats. */
|
|
75
|
+
guest?: boolean;
|
|
76
|
+
at: number;
|
|
77
|
+
}
|
|
78
|
+
/** One met in a room (docs/design/ta-link.md 3.1), in `friends.json`. */
|
|
79
|
+
export interface RelayFriend extends RelayPublicIdentity {
|
|
80
|
+
/** Titles of rooms shared, the latest last. */
|
|
81
|
+
rooms: string[];
|
|
82
|
+
metAt: number;
|
|
83
|
+
seenAt: number;
|
|
84
|
+
}
|
|
85
|
+
export interface RelayRoomValue {
|
|
86
|
+
value: unknown;
|
|
87
|
+
version: number;
|
|
88
|
+
/** The member who wrote it last. */
|
|
89
|
+
by: string;
|
|
90
|
+
}
|
|
91
|
+
export type RelayRoomEvent = {
|
|
92
|
+
type: 'rooms';
|
|
93
|
+
} | {
|
|
94
|
+
type: 'request';
|
|
95
|
+
request: RelayRoomRequest;
|
|
96
|
+
} | {
|
|
97
|
+
type: 'message';
|
|
98
|
+
room: string;
|
|
99
|
+
from: string;
|
|
100
|
+
name: string;
|
|
101
|
+
data: unknown;
|
|
102
|
+
} | {
|
|
103
|
+
type: 'state';
|
|
104
|
+
room: string;
|
|
105
|
+
key: string;
|
|
106
|
+
value: unknown;
|
|
107
|
+
version: number;
|
|
108
|
+
by: string;
|
|
109
|
+
};
|
|
110
|
+
/** Where a {@link RelayHubs} keeps what it knows: files of the agent directory for Ta, the storage of a browser for a guest. */
|
|
111
|
+
export interface RelayHubsStore {
|
|
112
|
+
read<T>(name: RelayHubsStoreName): T | undefined;
|
|
113
|
+
/** Holds keys: kept where the user alone reads it. */
|
|
114
|
+
write(name: RelayHubsStoreName, value: unknown): void;
|
|
115
|
+
}
|
|
116
|
+
/** The identity, the rooms (with their keys) and the friends. */
|
|
117
|
+
export type RelayHubsStoreName = 'identity' | 'rooms' | 'friends';
|
|
118
|
+
export interface RelayHubsOptions {
|
|
119
|
+
store: RelayHubsStore;
|
|
120
|
+
/** The name of a new identity: that of the user on the system. */
|
|
121
|
+
name?(): string;
|
|
122
|
+
/**
|
|
123
|
+
* A guest of rooms in a browser (docs/design/ta-link.md 3.8): its asks say so, its owner admits it as one, and the
|
|
124
|
+
* others hear only what it says (`chat:` of the state), not its messages or the rest of the state.
|
|
125
|
+
*/
|
|
126
|
+
guest?: boolean;
|
|
127
|
+
/** The relay new rooms are made on. */
|
|
128
|
+
relay(): string;
|
|
129
|
+
/** First wait before connecting again; it doubles up to 30 seconds. */
|
|
130
|
+
reconnectDelayMs?: number;
|
|
131
|
+
pingMs?: number;
|
|
132
|
+
}
|
|
133
|
+
/** What a member sends in a message, signed and sealed: data of an extension, or a word of Ta itself. */
|
|
134
|
+
interface MessageBody {
|
|
135
|
+
d?: unknown;
|
|
136
|
+
/** A member's new name, for the owner to put in the roster. */
|
|
137
|
+
name?: string;
|
|
138
|
+
}
|
|
139
|
+
/** A room as this Ta holds it while it runs: its connection and what it knows of the room. */
|
|
140
|
+
declare class Live {
|
|
141
|
+
record: RelayRoomRecord;
|
|
142
|
+
socket?: WebSocket;
|
|
143
|
+
keys?: RelayHubKeys;
|
|
144
|
+
synced: boolean;
|
|
145
|
+
online: Set<string>;
|
|
146
|
+
roster?: RelayHubRosterBody;
|
|
147
|
+
readonly state: Map<string, RelayRoomValue>;
|
|
148
|
+
/** Asks to join, with the invitation each came with. */
|
|
149
|
+
readonly asks: Map<string, {
|
|
150
|
+
body: RelayHubAskBody;
|
|
151
|
+
invite: string;
|
|
152
|
+
}>;
|
|
153
|
+
readonly done: Map<number, (result: {
|
|
154
|
+
ok: boolean;
|
|
155
|
+
v: number;
|
|
156
|
+
error?: RelayHubFailure;
|
|
157
|
+
}) => void>;
|
|
158
|
+
readonly ready: Array<() => void>;
|
|
159
|
+
attempts: number;
|
|
160
|
+
/** Connect again at once, whatever the close said. */
|
|
161
|
+
retry: boolean;
|
|
162
|
+
timer?: ReturnType<typeof setTimeout>;
|
|
163
|
+
pingTimer?: ReturnType<typeof setInterval>;
|
|
164
|
+
awaitingPong: boolean;
|
|
165
|
+
/** Events are handled one after another: opening them is async. */
|
|
166
|
+
chain: Promise<void>;
|
|
167
|
+
constructor(record: RelayRoomRecord);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* The rooms of this Ta (docs/design/ta-link.md 3): its identity and friends, the rooms it made or asked to join,
|
|
171
|
+
* and a connection to the hub of each while it runs, through which it sends, sets the shared state and hears
|
|
172
|
+
* the others; every message signed by its member and sealed with the key of the room.
|
|
173
|
+
*/
|
|
174
|
+
export declare class RelayHubs {
|
|
175
|
+
protected readonly options: RelayHubsOptions;
|
|
176
|
+
protected readonly live: Map<string, Live>;
|
|
177
|
+
protected readonly listeners: Set<(event: RelayRoomEvent) => void>;
|
|
178
|
+
protected own?: RelayIdentity;
|
|
179
|
+
/** Asks the user was told of while this runs: those the owner finds waiting when it connects are told once. */
|
|
180
|
+
protected readonly told: Set<string>;
|
|
181
|
+
protected stopped: boolean;
|
|
182
|
+
protected nextId: number;
|
|
183
|
+
constructor(options: RelayHubsOptions);
|
|
184
|
+
/** Connects to the rooms of rooms.json, and keeps connected. */
|
|
185
|
+
start(): void;
|
|
186
|
+
stop(): void;
|
|
187
|
+
onEvent(listener: (event: RelayRoomEvent) => void): () => void;
|
|
188
|
+
/** This Ta's identity, made the first time. */
|
|
189
|
+
identity(): Promise<RelayIdentity>;
|
|
190
|
+
/** The name others see; the owners of rooms this Ta is in hear it. */
|
|
191
|
+
setName(name: string): Promise<RelayPublicIdentity>;
|
|
192
|
+
list(): RelayRoomInfo[];
|
|
193
|
+
room(id: string): RelayRoomInfo | undefined;
|
|
194
|
+
create(input: {
|
|
195
|
+
kind: string;
|
|
196
|
+
title: string;
|
|
197
|
+
view?: string;
|
|
198
|
+
}): Promise<RelayRoomInfo>;
|
|
199
|
+
/**
|
|
200
|
+
* The link that lets others ask to join: the one of before while it has a day left, else (or with `renew`) a new
|
|
201
|
+
* one for `days` (7 by default, 30 at most), the links of before no longer working.
|
|
202
|
+
*/
|
|
203
|
+
invite(roomId: string, options?: {
|
|
204
|
+
days?: number;
|
|
205
|
+
renew?: boolean;
|
|
206
|
+
}): Promise<{
|
|
207
|
+
link: string;
|
|
208
|
+
expiresAt: number;
|
|
209
|
+
}>;
|
|
210
|
+
/** Asks to join the room of a link: the owner answers (`waiting` till then). The room of before, if this Ta has it. */
|
|
211
|
+
join(text: string): Promise<RelayRoomInfo>;
|
|
212
|
+
/** Those asking to join the rooms of this Ta, the earliest first. */
|
|
213
|
+
requests(): Promise<RelayRoomRequest[]>;
|
|
214
|
+
/** The user's answer to one asking to join: admitted, it gets the key of the room and is in the roster. */
|
|
215
|
+
answer(roomId: string, askId: string, accept: boolean): Promise<void>;
|
|
216
|
+
/** The owner takes a member out: the relay closes it at once. */
|
|
217
|
+
remove(roomId: string, member: string): Promise<void>;
|
|
218
|
+
/** Leaves the room; the owner closes it, for everyone. A room asked to join is forgotten. */
|
|
219
|
+
leave(roomId: string): Promise<void>;
|
|
220
|
+
/** To every other member, or to one (`to`, its member id). */
|
|
221
|
+
send(roomId: string, data: unknown, to?: string): Promise<void>;
|
|
222
|
+
/** The shared state, by its names. */
|
|
223
|
+
getState(roomId: string, prefix?: string): Promise<Record<string, RelayRoomValue>>;
|
|
224
|
+
/**
|
|
225
|
+
* Sets a key of the shared state (`null` clears it); with `version`, only if it is still that version (0: not
|
|
226
|
+
* set), else `ok` is false and `version` says what it is now: read it again, and set it again.
|
|
227
|
+
*/
|
|
228
|
+
setState(roomId: string, key: string, value: unknown, version?: number): Promise<{
|
|
229
|
+
ok: boolean;
|
|
230
|
+
version: number;
|
|
231
|
+
}>;
|
|
232
|
+
friends(): RelayFriend[];
|
|
233
|
+
removeFriend(id: string): boolean;
|
|
234
|
+
protected owned(roomId: string): Live;
|
|
235
|
+
protected member(roomId: string): Live;
|
|
236
|
+
protected info(live: Live): RelayRoomInfo;
|
|
237
|
+
protected requestOf(live: Live, ask: RelayHubAskBody, friends: Set<string>): RelayRoomRequest;
|
|
238
|
+
/** Resolves once the room is connected and has its state; rejects after a while. */
|
|
239
|
+
protected ready(live: Live): Promise<void>;
|
|
240
|
+
protected request(live: Live, request: RelayHubRequest): void;
|
|
241
|
+
protected sendBody(live: Live, body: MessageBody, to?: string): Promise<void>;
|
|
242
|
+
/** The roster with `change` made, its version one more, signed by the owner. */
|
|
243
|
+
protected nextRoster(live: Live, change: (members: RelayHubMember[]) => RelayHubMember[]): Promise<{
|
|
244
|
+
v: number;
|
|
245
|
+
d: string;
|
|
246
|
+
}>;
|
|
247
|
+
protected writeRoster(live: Live, change: (members: RelayHubMember[]) => RelayHubMember[]): Promise<void>;
|
|
248
|
+
protected connect(live: Live): void;
|
|
249
|
+
protected hello(live: Live, socket: WebSocket): Promise<void>;
|
|
250
|
+
protected closed(live: Live, code: number): void;
|
|
251
|
+
protected disconnect(live: Live): void;
|
|
252
|
+
protected receive(live: Live, text: string): Promise<void>;
|
|
253
|
+
protected failed(live: Live, code: RelayHubFailure): void;
|
|
254
|
+
protected setStatus(live: Live, status: RelayRoomStatus, reason?: RelayRoomRecord['reason']): void;
|
|
255
|
+
protected admitted(live: Live, answer: string): Promise<void>;
|
|
256
|
+
/** An ask to join: told as a request the first time this Ta hears it; `fresh` when it came now, not with the welcome. */
|
|
257
|
+
protected asked(live: Live, sealed: string, fresh: boolean): Promise<void>;
|
|
258
|
+
protected readRoster(live: Live, sealed: string): Promise<void>;
|
|
259
|
+
protected guestOf(live: Live, member: string): boolean;
|
|
260
|
+
protected signOf(live: Live): (member: string) => string | undefined;
|
|
261
|
+
protected readEntry(live: Live, entry: RelayHubEntry, tell: boolean): Promise<void>;
|
|
262
|
+
protected readMessage(live: Live, from: string, sealed: string): Promise<void>;
|
|
263
|
+
/** Those of a room are friends: kept with their keys and the rooms shared. */
|
|
264
|
+
protected meet(title: string, members: RelayPublicIdentity[]): void;
|
|
265
|
+
protected friendIds(): Set<string>;
|
|
266
|
+
protected readFriends(): RelayFriend[];
|
|
267
|
+
protected readRooms(): RelayRoomRecord[];
|
|
268
|
+
protected save(): void;
|
|
269
|
+
protected emit(event: RelayRoomEvent): void;
|
|
270
|
+
}
|
|
271
|
+
export {};
|