@celljs/ta-relay 4.21.0 → 4.23.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/esm/common/index.d.ts +3 -0
- package/esm/common/index.js +3 -0
- package/esm/common/relay-blobs.d.ts +36 -2
- package/esm/common/relay-blobs.js +33 -5
- package/esm/common/relay-chat-store.d.ts +59 -0
- package/esm/common/relay-chat-store.js +40 -0
- package/esm/common/relay-hub-charter.d.ts +7 -1
- package/esm/common/relay-hub-charter.js +6 -0
- package/esm/common/relay-hub-log.d.ts +65 -0
- package/esm/common/relay-hub-log.js +147 -0
- package/esm/common/relay-hub.d.ts +3 -0
- package/esm/common/relay-hub.js +18 -0
- package/esm/common/relay-hubs-admins.d.ts +1 -0
- package/esm/common/relay-hubs-admins.js +10 -6
- package/esm/common/relay-hubs-chats.d.ts +66 -0
- package/esm/common/relay-hubs-chats.js +342 -0
- package/esm/common/relay-hubs-connection.d.ts +3 -1
- package/esm/common/relay-hubs-connection.js +7 -0
- package/esm/common/relay-hubs-protocol.d.ts +14 -0
- package/esm/common/relay-hubs.d.ts +5 -2
- package/esm/common/relay-hubs.js +31 -13
- package/esm/common/relay-info.d.ts +23 -1
- package/esm/common/relay-info.js +25 -2
- package/esm/common/relay-protocol.d.ts +60 -1
- package/esm/common/relay-protocol.js +15 -0
- package/esm/common/relay-room-app.d.ts +106 -0
- package/esm/common/relay-room-app.js +171 -0
- package/esm/common/relay-room-chat.d.ts +126 -4
- package/esm/common/relay-room-chat.js +230 -6
- package/esm/guest/guest-i18n.d.ts +5 -0
- package/esm/guest/guest-i18n.js +20 -0
- package/esm/guest/guest-style.d.ts +1 -1
- package/esm/guest/guest-style.js +11 -0
- package/esm/guest/guest.js +84 -11
- package/esm/node/index.d.ts +1 -0
- package/esm/node/index.js +1 -0
- package/esm/node/relay-chat-files.d.ts +46 -0
- package/esm/node/relay-chat-files.js +199 -0
- package/esm/node/relay-hub-files.d.ts +11 -1
- package/esm/node/relay-hub-files.js +8 -1
- package/esm/node/relay-server.d.ts +7 -1
- package/esm/node/relay-server.js +23 -13
- package/lib/common/index.d.ts +3 -0
- package/lib/common/index.js +3 -0
- package/lib/common/relay-blobs.d.ts +36 -2
- package/lib/common/relay-blobs.js +34 -6
- package/lib/common/relay-chat-store.d.ts +60 -0
- package/lib/common/relay-chat-store.js +44 -0
- package/lib/common/relay-hub-charter.d.ts +7 -1
- package/lib/common/relay-hub-charter.js +7 -1
- package/lib/common/relay-hub-log.d.ts +66 -0
- package/lib/common/relay-hub-log.js +151 -0
- package/lib/common/relay-hub.d.ts +3 -0
- package/lib/common/relay-hub.js +18 -0
- package/lib/common/relay-hubs-admins.d.ts +1 -0
- package/lib/common/relay-hubs-admins.js +9 -5
- package/lib/common/relay-hubs-chats.d.ts +67 -0
- package/lib/common/relay-hubs-chats.js +346 -0
- package/lib/common/relay-hubs-connection.d.ts +3 -1
- package/lib/common/relay-hubs-connection.js +7 -0
- package/lib/common/relay-hubs-protocol.d.ts +14 -0
- package/lib/common/relay-hubs.d.ts +5 -2
- package/lib/common/relay-hubs.js +30 -12
- package/lib/common/relay-info.d.ts +23 -1
- package/lib/common/relay-info.js +26 -3
- package/lib/common/relay-protocol.d.ts +60 -1
- package/lib/common/relay-protocol.js +16 -1
- package/lib/common/relay-room-app.d.ts +107 -0
- package/lib/common/relay-room-app.js +176 -0
- package/lib/common/relay-room-chat.d.ts +126 -4
- package/lib/common/relay-room-chat.js +231 -7
- package/lib/guest/guest-i18n.d.ts +5 -0
- package/lib/guest/guest-i18n.js +20 -0
- package/lib/guest/guest-style.d.ts +1 -1
- package/lib/guest/guest-style.js +11 -0
- package/lib/guest/guest.js +83 -10
- package/lib/node/index.d.ts +1 -0
- package/lib/node/index.js +1 -0
- package/lib/node/relay-chat-files.d.ts +47 -0
- package/lib/node/relay-chat-files.js +203 -0
- package/lib/node/relay-hub-files.d.ts +11 -1
- package/lib/node/relay-hub-files.js +8 -1
- package/lib/node/relay-server.d.ts +7 -1
- package/lib/node/relay-server.js +21 -11
- package/package.json +3 -3
- package/viewer/join.html +17 -6
- package/viewer/page.html +10 -10
- package/viewer/room.html +26 -15
|
@@ -19,7 +19,24 @@ export interface RelayInfo {
|
|
|
19
19
|
limits: RelayLimits;
|
|
20
20
|
/** Whether rooms and copies stay when the relay restarts. */
|
|
21
21
|
persistent: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Sealed copies of the pictures of chats its operator lets it keep (RELAY_MEDIA_PATH), for whoever comes while no
|
|
24
|
+
* member who has one is online: so many days, so many bytes each. None (the default): it keeps none.
|
|
25
|
+
*/
|
|
26
|
+
media?: RelayMedia;
|
|
22
27
|
}
|
|
28
|
+
/** What a relay keeps of the pictures of chats (RelayInfo.media), as its operator set it. */
|
|
29
|
+
export interface RelayMedia {
|
|
30
|
+
days: number;
|
|
31
|
+
bytes: number;
|
|
32
|
+
}
|
|
33
|
+
/** The most an operator may let a relay keep of a picture: as long and as large as a copy of content. */
|
|
34
|
+
export declare const RELAY_MEDIA_MAX: RelayMedia;
|
|
35
|
+
/**
|
|
36
|
+
* Days a relay keeps a picture of a chat unless its operator says otherwise: short, so that what it keeps stays small
|
|
37
|
+
* however many use it, long enough for the others to open a chat the sender left while away.
|
|
38
|
+
*/
|
|
39
|
+
export declare const RELAY_MEDIA_DEFAULT_DAYS = 1;
|
|
23
40
|
/** A relay that answers no RELAY_INFO_PATH, made before it: all it can do, with the limits of then. */
|
|
24
41
|
export declare const RELAY_LEGACY_INFO: RelayInfo;
|
|
25
42
|
/** What a probe of a relay found. */
|
|
@@ -33,7 +50,12 @@ export interface RelayProbe {
|
|
|
33
50
|
error?: string;
|
|
34
51
|
}
|
|
35
52
|
export declare namespace RelayInfoUtil {
|
|
36
|
-
function of(persistent: boolean): RelayInfo;
|
|
53
|
+
function of(persistent: boolean, media?: RelayMedia): RelayInfo;
|
|
54
|
+
/**
|
|
55
|
+
* What the operator of a relay lets it keep of the pictures of chats, from its settings (`TA_MEDIA_DAYS`,
|
|
56
|
+
* `TA_MEDIA_MAX_MB`): RELAY_MEDIA_DEFAULT_DAYS unless set, none with 0, within RELAY_MEDIA_MAX.
|
|
57
|
+
*/
|
|
58
|
+
function media(days: unknown, megabytes?: unknown): RelayMedia | undefined;
|
|
37
59
|
/** The answer of RELAY_INFO_PATH: JSON, readable by any page (it says nothing secret). */
|
|
38
60
|
function response(info: RelayInfo): Response;
|
|
39
61
|
/** The address of a relay as it is kept: http(s), its origin and path, no trailing slash. Throws on what is not one. */
|
package/lib/common/relay-info.js
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RelayInfoUtil = exports.RELAY_LEGACY_INFO = exports.RELAY_INFO_PATH = void 0;
|
|
3
|
+
exports.RelayInfoUtil = exports.RELAY_LEGACY_INFO = exports.RELAY_MEDIA_DEFAULT_DAYS = exports.RELAY_MEDIA_MAX = exports.RELAY_INFO_PATH = void 0;
|
|
4
4
|
const relay_protocol_1 = require("./relay-protocol");
|
|
5
5
|
/** What a relay says of itself (docs/design/ta-relays.md 3.1): GET RELAY_INFO_PATH. */
|
|
6
6
|
exports.RELAY_INFO_PATH = '/v1/info';
|
|
7
|
+
/** The most an operator may let a relay keep of a picture: as long and as large as a copy of content. */
|
|
8
|
+
exports.RELAY_MEDIA_MAX = { days: 30, bytes: 2 * 1024 * 1024 };
|
|
9
|
+
/**
|
|
10
|
+
* Days a relay keeps a picture of a chat unless its operator says otherwise: short, so that what it keeps stays small
|
|
11
|
+
* however many use it, long enough for the others to open a chat the sender left while away.
|
|
12
|
+
*/
|
|
13
|
+
exports.RELAY_MEDIA_DEFAULT_DAYS = 1;
|
|
7
14
|
/** A relay that answers no RELAY_INFO_PATH, made before it: all it can do, with the limits of then. */
|
|
8
15
|
exports.RELAY_LEGACY_INFO = {
|
|
9
16
|
v: 1,
|
|
@@ -21,10 +28,24 @@ exports.RELAY_LEGACY_INFO = {
|
|
|
21
28
|
};
|
|
22
29
|
var RelayInfoUtil;
|
|
23
30
|
(function (RelayInfoUtil) {
|
|
24
|
-
function of(persistent) {
|
|
25
|
-
return { ...exports.RELAY_LEGACY_INFO, persistent };
|
|
31
|
+
function of(persistent, media) {
|
|
32
|
+
return { ...exports.RELAY_LEGACY_INFO, persistent, ...(media ? { media } : {}) };
|
|
26
33
|
}
|
|
27
34
|
RelayInfoUtil.of = of;
|
|
35
|
+
/**
|
|
36
|
+
* What the operator of a relay lets it keep of the pictures of chats, from its settings (`TA_MEDIA_DAYS`,
|
|
37
|
+
* `TA_MEDIA_MAX_MB`): RELAY_MEDIA_DEFAULT_DAYS unless set, none with 0, within RELAY_MEDIA_MAX.
|
|
38
|
+
*/
|
|
39
|
+
function media(days, megabytes) {
|
|
40
|
+
const set = days !== undefined && days !== null && String(days).trim() !== '';
|
|
41
|
+
const kept = Math.min(Math.floor(set ? Number(days) || 0 : exports.RELAY_MEDIA_DEFAULT_DAYS), exports.RELAY_MEDIA_MAX.days);
|
|
42
|
+
if (!(kept > 0)) {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
const bytes = Number(megabytes) > 0 ? Math.floor(Number(megabytes) * 1024 * 1024) : exports.RELAY_MEDIA_MAX.bytes;
|
|
46
|
+
return { days: kept, bytes: Math.min(bytes, exports.RELAY_MEDIA_MAX.bytes) };
|
|
47
|
+
}
|
|
48
|
+
RelayInfoUtil.media = media;
|
|
28
49
|
/** The answer of RELAY_INFO_PATH: JSON, readable by any page (it says nothing secret). */
|
|
29
50
|
function response(info) {
|
|
30
51
|
return new Response(JSON.stringify(info), {
|
|
@@ -85,11 +106,13 @@ var RelayInfoUtil;
|
|
|
85
106
|
limits[key] = given;
|
|
86
107
|
}
|
|
87
108
|
}
|
|
109
|
+
const kept = info.media && media(info.media.days, (Number(info.media.bytes) || 0) / (1024 * 1024));
|
|
88
110
|
return {
|
|
89
111
|
v: 1,
|
|
90
112
|
capabilities: info.capabilities.filter((capability) => known.includes(capability)),
|
|
91
113
|
limits,
|
|
92
114
|
persistent: info.persistent !== false,
|
|
115
|
+
...(kept ? { media: kept } : {}),
|
|
93
116
|
};
|
|
94
117
|
}
|
|
95
118
|
RelayInfoUtil.parse = parse;
|
|
@@ -39,6 +39,11 @@ export declare const RELAY_VIEWER_HEADERS: {
|
|
|
39
39
|
};
|
|
40
40
|
/** The copies of content kept on the relay, sealed, for when the computer that shared it is off (RelayBlobs). */
|
|
41
41
|
export declare const RELAY_BLOB_PATH = "/v1/blob/";
|
|
42
|
+
/**
|
|
43
|
+
* Sealed copies of the pictures of chats (docs/design/ta-chat-history.md 7), only on a relay whose operator lets it
|
|
44
|
+
* (RelayInfo.media): none by default, what it keeps costing more the more people use it.
|
|
45
|
+
*/
|
|
46
|
+
export declare const RELAY_MEDIA_PATH = "/v1/media/";
|
|
42
47
|
/** The page a pairing link opens in a browser: the link is for the app, and the key in it stays in the fragment. */
|
|
43
48
|
export declare const RELAY_PAIR_PAGE = "<!doctype html><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width\"><title>Ta</title>\n<body style=\"font:16px system-ui;max-width:32em;margin:3em auto;padding:0 1em\">\n<h1>Ta</h1><p>Open this link in the Ta app, or paste it there, to reach your Ta from this device.</p>\n<p>\u6253\u5F00 Ta \u5E94\u7528\uFF0C\u7C98\u8D34\u8FD9\u4E2A\u94FE\u63A5\uFF0C\u5C31\u80FD\u4ECE\u8FD9\u53F0\u8BBE\u5907\u8FDE\u5230\u4F60\u7684 Ta\u3002</p><p><a id=\"open\" style=\"display:inline-block;padding:10px 18px;border-radius:20px;background:#111;color:#fff;text-decoration:none;font-weight:600\">Open in Ta \u00B7 \u5728 Ta \u4E2D\u6253\u5F00</a></p>\n<script>document.getElementById('open').href='ta://open?link='+encodeURIComponent(location.href)</script></body>";
|
|
44
49
|
/** The page a link of an extension opens in a browser. */
|
|
@@ -200,6 +205,26 @@ export declare const RELAY_HUB_ASK_DAYS = 7;
|
|
|
200
205
|
export declare const RELAY_HUB_IDLE_DAYS = 90;
|
|
201
206
|
/** Messages of a connection in a second. */
|
|
202
207
|
export declare const RELAY_HUB_RATE = 40;
|
|
208
|
+
/**
|
|
209
|
+
* One message of the log of a room (docs/design/ta-chat-history.md 5): its number in the room, the member who posted it,
|
|
210
|
+
* sealed and signed as a message is, and when the relay took it. What is said in a room goes here, not in the state.
|
|
211
|
+
*/
|
|
212
|
+
export interface RelayHubLogItem {
|
|
213
|
+
s: number;
|
|
214
|
+
m: string;
|
|
215
|
+
d: string;
|
|
216
|
+
at: number;
|
|
217
|
+
}
|
|
218
|
+
/** The log of a room keeps so many messages, so many characters at most: past them the oldest go, read or not. */
|
|
219
|
+
export declare const RELAY_HUB_LOG_MAX = 5000;
|
|
220
|
+
export declare const RELAY_HUB_LOG_CHARS: number;
|
|
221
|
+
/** Days a message is kept once every member has it, and at most. */
|
|
222
|
+
export declare const RELAY_HUB_LOG_KEEP_DAYS = 7;
|
|
223
|
+
export declare const RELAY_HUB_LOG_MAX_DAYS = 30;
|
|
224
|
+
/** Messages of the log in one answer to `sync`. */
|
|
225
|
+
export declare const RELAY_HUB_SYNC_PAGE = 200;
|
|
226
|
+
/** Messages from before they joined a newcomer may read at most, as the charter of the room says (history, 0 by default). */
|
|
227
|
+
export declare const RELAY_HUB_HISTORY_MAX = 500;
|
|
203
228
|
/**
|
|
204
229
|
* The sealed list of the members of a room, signed by its owner (or an admin); `v` grows with each change. After a
|
|
205
230
|
* member was taken out or left, `k` holds the keys of the room's epochs sealed for each member left
|
|
@@ -259,6 +284,24 @@ export type RelayHubRequest = {
|
|
|
259
284
|
d: string;
|
|
260
285
|
v?: number;
|
|
261
286
|
own?: true;
|
|
287
|
+
}
|
|
288
|
+
/** Adds to the log (`mid` the id of the line: the same again is the same message), answered by `done` with its number in `v`. */
|
|
289
|
+
| {
|
|
290
|
+
t: 'post';
|
|
291
|
+
id: number;
|
|
292
|
+
mid: string;
|
|
293
|
+
d: string;
|
|
294
|
+
}
|
|
295
|
+
/** The log after the number `after`, a page of it (RELAY_HUB_SYNC_PAGE at most), answered by `log`. */
|
|
296
|
+
| {
|
|
297
|
+
t: 'sync';
|
|
298
|
+
after: number;
|
|
299
|
+
limit?: number;
|
|
300
|
+
}
|
|
301
|
+
/** This member has the log up to `seq`: the relay may let go of what all have, once old enough. */
|
|
302
|
+
| {
|
|
303
|
+
t: 'ack';
|
|
304
|
+
seq: number;
|
|
262
305
|
} | {
|
|
263
306
|
t: 'invite';
|
|
264
307
|
hash: string;
|
|
@@ -266,11 +309,14 @@ export type RelayHubRequest = {
|
|
|
266
309
|
} | {
|
|
267
310
|
t: 'admins';
|
|
268
311
|
admins: string[];
|
|
269
|
-
}
|
|
312
|
+
}
|
|
313
|
+
/** `history`: messages from before they joined the newcomer may read (RELAY_HUB_HISTORY_MAX at most), 0 by default. */
|
|
314
|
+
| {
|
|
270
315
|
t: 'admit';
|
|
271
316
|
ask: string;
|
|
272
317
|
answer: string;
|
|
273
318
|
roster: RelayHubRoster;
|
|
319
|
+
history?: number;
|
|
274
320
|
} | {
|
|
275
321
|
t: 'refuse';
|
|
276
322
|
ask: string;
|
|
@@ -307,6 +353,19 @@ export type RelayHubEvent = {
|
|
|
307
353
|
t: 'msg';
|
|
308
354
|
from: string;
|
|
309
355
|
d: string;
|
|
356
|
+
}
|
|
357
|
+
/** A page of the log: `first` and `last` the numbers it holds now, `more` when there is more after the page. */
|
|
358
|
+
| {
|
|
359
|
+
t: 'log';
|
|
360
|
+
items: RelayHubLogItem[];
|
|
361
|
+
first: number;
|
|
362
|
+
last: number;
|
|
363
|
+
more: boolean;
|
|
364
|
+
}
|
|
365
|
+
/** Another member posted. */
|
|
366
|
+
| {
|
|
367
|
+
t: 'post';
|
|
368
|
+
item: RelayHubLogItem;
|
|
310
369
|
} | {
|
|
311
370
|
t: 'state';
|
|
312
371
|
entry: RelayHubEntry;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RELAY_HUB_RATE = exports.RELAY_HUB_IDLE_DAYS = exports.RELAY_HUB_ASK_DAYS = exports.RELAY_PICTURE_MAX_CHARS = exports.RELAY_PICTURE_KEY = exports.RELAY_HUB_MAX_ASKS = exports.RELAY_HUB_MAX_STATE = exports.RELAY_HUB_MAX_KEYS = exports.RELAY_HUB_MAX_VALUE = exports.RELAY_FRIENDS_MAX = exports.RELAY_INVITE_MAX_DAYS = exports.RELAY_ROOM_CAPACITY_MAX = exports.RELAY_ROOM_MAX_MEMBERS = exports.RELAY_HUB_MAX_MEMBERS = exports.RELAY_ROOM_PATH = exports.RELAY_HUB_PATH = exports.RELAY_PROOF = exports.RELAY_STALE_MS = exports.RELAY_PING_MS = exports.RELAY_PONG = exports.RELAY_PING = exports.RelayCloseCode = exports.RELAY_ID = exports.RELAY_BLOB_MAX_DAYS = exports.RELAY_CONTENT_MAX_BYTES = exports.RELAY_SHARE_DAYS = exports.RELAY_SHARE_CHUNK_BYTES = exports.RELAY_SHARE_MAX_BYTES = exports.RELAY_SHARE_PAGE = exports.RELAY_PAIR_PAGE = exports.RELAY_BLOB_PATH = exports.RELAY_VIEWER_HEADERS = exports.RELAY_FRAME_HEADER_CSP = exports.RELAY_FRAME_CSP = exports.RELAY_FRAME_PATH = exports.RELAY_CONTENT_PATH = exports.RELAY_SHARE_PATH = exports.RELAY_PAIR_PATH = exports.RELAY_CONNECT_PATH = exports.RELAY_HOST_PATH = exports.RELAY_DEFAULT_URL = void 0;
|
|
3
|
+
exports.RELAY_HUB_HISTORY_MAX = exports.RELAY_HUB_SYNC_PAGE = exports.RELAY_HUB_LOG_MAX_DAYS = exports.RELAY_HUB_LOG_KEEP_DAYS = exports.RELAY_HUB_LOG_CHARS = exports.RELAY_HUB_LOG_MAX = exports.RELAY_HUB_RATE = exports.RELAY_HUB_IDLE_DAYS = exports.RELAY_HUB_ASK_DAYS = exports.RELAY_PICTURE_MAX_CHARS = exports.RELAY_PICTURE_KEY = exports.RELAY_HUB_MAX_ASKS = exports.RELAY_HUB_MAX_STATE = exports.RELAY_HUB_MAX_KEYS = exports.RELAY_HUB_MAX_VALUE = exports.RELAY_FRIENDS_MAX = exports.RELAY_INVITE_MAX_DAYS = exports.RELAY_ROOM_CAPACITY_MAX = exports.RELAY_ROOM_MAX_MEMBERS = exports.RELAY_HUB_MAX_MEMBERS = exports.RELAY_ROOM_PATH = exports.RELAY_HUB_PATH = exports.RELAY_PROOF = exports.RELAY_STALE_MS = exports.RELAY_PING_MS = exports.RELAY_PONG = exports.RELAY_PING = exports.RelayCloseCode = exports.RELAY_ID = exports.RELAY_BLOB_MAX_DAYS = exports.RELAY_CONTENT_MAX_BYTES = exports.RELAY_SHARE_DAYS = exports.RELAY_SHARE_CHUNK_BYTES = exports.RELAY_SHARE_MAX_BYTES = exports.RELAY_SHARE_PAGE = exports.RELAY_PAIR_PAGE = exports.RELAY_MEDIA_PATH = exports.RELAY_BLOB_PATH = exports.RELAY_VIEWER_HEADERS = exports.RELAY_FRAME_HEADER_CSP = exports.RELAY_FRAME_CSP = exports.RELAY_FRAME_PATH = exports.RELAY_CONTENT_PATH = exports.RELAY_SHARE_PATH = exports.RELAY_PAIR_PATH = exports.RELAY_CONNECT_PATH = exports.RELAY_HOST_PATH = exports.RELAY_DEFAULT_URL = void 0;
|
|
4
4
|
exports.relayDefaultUrl = relayDefaultUrl;
|
|
5
5
|
/** The relay of Ta, on Cloudflare Workers (apps/ta-relay), when the user names none. */
|
|
6
6
|
exports.RELAY_DEFAULT_URL = 'https://relay.cellbang.com';
|
|
@@ -48,6 +48,11 @@ exports.RELAY_VIEWER_HEADERS = {
|
|
|
48
48
|
};
|
|
49
49
|
/** The copies of content kept on the relay, sealed, for when the computer that shared it is off (RelayBlobs). */
|
|
50
50
|
exports.RELAY_BLOB_PATH = '/v1/blob/';
|
|
51
|
+
/**
|
|
52
|
+
* Sealed copies of the pictures of chats (docs/design/ta-chat-history.md 7), only on a relay whose operator lets it
|
|
53
|
+
* (RelayInfo.media): none by default, what it keeps costing more the more people use it.
|
|
54
|
+
*/
|
|
55
|
+
exports.RELAY_MEDIA_PATH = '/v1/media/';
|
|
51
56
|
/** Open in Ta on the plain pages of the relay: the link of the page, its fragment too, to the Ta app (RelayOpenInTa). */
|
|
52
57
|
const OPEN_IN_TA = `<p><a id="open" style="display:inline-block;padding:10px 18px;border-radius:20px;background:#111;color:#fff;text-decoration:none;font-weight:600">Open in Ta · 在 Ta 中打开</a></p>
|
|
53
58
|
<script>document.getElementById('open').href='ta://open?link='+encodeURIComponent(location.href)</script>`;
|
|
@@ -137,4 +142,14 @@ exports.RELAY_HUB_ASK_DAYS = 7;
|
|
|
137
142
|
exports.RELAY_HUB_IDLE_DAYS = 90;
|
|
138
143
|
/** Messages of a connection in a second. */
|
|
139
144
|
exports.RELAY_HUB_RATE = 40;
|
|
145
|
+
/** The log of a room keeps so many messages, so many characters at most: past them the oldest go, read or not. */
|
|
146
|
+
exports.RELAY_HUB_LOG_MAX = 5000;
|
|
147
|
+
exports.RELAY_HUB_LOG_CHARS = 4 * 1024 * 1024;
|
|
148
|
+
/** Days a message is kept once every member has it, and at most. */
|
|
149
|
+
exports.RELAY_HUB_LOG_KEEP_DAYS = 7;
|
|
150
|
+
exports.RELAY_HUB_LOG_MAX_DAYS = 30;
|
|
151
|
+
/** Messages of the log in one answer to `sync`. */
|
|
152
|
+
exports.RELAY_HUB_SYNC_PAGE = 200;
|
|
153
|
+
/** Messages from before they joined a newcomer may read at most, as the charter of the room says (history, 0 by default). */
|
|
154
|
+
exports.RELAY_HUB_HISTORY_MAX = 500;
|
|
140
155
|
//# sourceMappingURL=relay-protocol.js.map
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type { RelayChatLine, RelayChatLineExtra } from './relay-room-chat';
|
|
2
|
+
/**
|
|
3
|
+
* What every app of a group chat that listens and speaks there needs (docs/design/ta-feedback.md 1): what others said
|
|
4
|
+
* since it last read, paced; who speaks for the user (their double or an agent of theirs in the room); what others wrote
|
|
5
|
+
* kept as theirs when a model reads it; and a board of how things go that every member, and those in a browser, see.
|
|
6
|
+
* Feedback is one such app; a vote, a rota or a help desk would be others.
|
|
7
|
+
*/
|
|
8
|
+
/** Under `agents:<member>` of the state of a room, each member lists the agents of theirs they invited to it. */
|
|
9
|
+
export declare const ROOM_AGENTS_KEY = "agents:";
|
|
10
|
+
/** A line older than this when an app reads it is left: Ta was off for days. */
|
|
11
|
+
export declare const ROOM_APP_STALE_MS: number;
|
|
12
|
+
export declare namespace RoomAppUtil {
|
|
13
|
+
/** What others wrote, which a model reads inside tags: no tags of its own. */
|
|
14
|
+
function quote(text: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* What others said to the room since `since`: not by the user, not too long ago, not to someone in particular (@ a
|
|
17
|
+
* person, a double or an agent: theirs to answer), not said by a double or an agent.
|
|
18
|
+
*/
|
|
19
|
+
function fresh(lines: readonly RelayChatLine[], self: string, since: number, now: number, staleMs?: number): RelayChatLine[];
|
|
20
|
+
/** Whether one more fits in the hour before `now`. */
|
|
21
|
+
function within(times: readonly number[], now: number, most: number): boolean;
|
|
22
|
+
/** People named with @, each once. */
|
|
23
|
+
function mentions(names: readonly string[]): string;
|
|
24
|
+
}
|
|
25
|
+
export interface RoomSpeaker {
|
|
26
|
+
name: string;
|
|
27
|
+
/** What the line it says carries (RelayRoomChat.say): the agent, or that it is the double. */
|
|
28
|
+
extra: RelayChatLineExtra;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Who speaks for the user in a room: the agent of theirs they chose, while it is in the room (as `agents:<member>` of
|
|
32
|
+
* its state lists it, written by them), else their double, named `doubleName`.
|
|
33
|
+
*/
|
|
34
|
+
export declare function roomSpeaker(rooms: {
|
|
35
|
+
getState(room: string, prefix?: string): Promise<Record<string, {
|
|
36
|
+
value: unknown;
|
|
37
|
+
by: string;
|
|
38
|
+
}>>;
|
|
39
|
+
}, room: string, self: string, agent: string | undefined, doubleName: string): Promise<RoomSpeaker>;
|
|
40
|
+
/**
|
|
41
|
+
* Paces the work of an app on what is said in rooms: once the room is quiet for `settleMs` (a few lines read as one), one
|
|
42
|
+
* run at a time per room, and no more runs that did something than `hourly` in an hour (past it, again after `laterMs`).
|
|
43
|
+
* `run` says whether it did something (a turn of a model, a line said).
|
|
44
|
+
*/
|
|
45
|
+
export declare class RoomPacer {
|
|
46
|
+
protected readonly run: (room: string) => Promise<boolean>;
|
|
47
|
+
protected readonly options: {
|
|
48
|
+
settleMs: number;
|
|
49
|
+
hourly: number;
|
|
50
|
+
laterMs: number;
|
|
51
|
+
now(): number;
|
|
52
|
+
failed(error: unknown): void;
|
|
53
|
+
};
|
|
54
|
+
protected readonly timers: Map<string, NodeJS.Timeout>;
|
|
55
|
+
protected readonly queues: Map<string, Promise<void>>;
|
|
56
|
+
protected readonly runs: Map<string, number[]>;
|
|
57
|
+
protected disposed: boolean;
|
|
58
|
+
constructor(run: (room: string) => Promise<boolean>, options: {
|
|
59
|
+
settleMs: number;
|
|
60
|
+
hourly: number;
|
|
61
|
+
laterMs: number;
|
|
62
|
+
now(): number;
|
|
63
|
+
failed(error: unknown): void;
|
|
64
|
+
});
|
|
65
|
+
/** Something was said in a room: it is read once it is quiet (`delay`, settleMs by default). */
|
|
66
|
+
heard(room: string, delay?: number): void;
|
|
67
|
+
/** What runs in a room now, done. */
|
|
68
|
+
idle(room: string): Promise<void>;
|
|
69
|
+
dispose(): void;
|
|
70
|
+
protected turn(room: string): Promise<void>;
|
|
71
|
+
}
|
|
72
|
+
/** Under `board:<app>:<member>` of the state of a room, its owner says how the things of an app go, for all in it. */
|
|
73
|
+
export declare const RELAY_BOARD_KEY = "board:";
|
|
74
|
+
/** Items of a board at most, the latest. */
|
|
75
|
+
export declare const RELAY_BOARD_MAX = 30;
|
|
76
|
+
/**
|
|
77
|
+
* How an item goes, for anyone to draw without knowing the app: being done, waiting (for the owner, or for more from
|
|
78
|
+
* those who said it), done, or closed without it.
|
|
79
|
+
*/
|
|
80
|
+
export type RelayBoardState = 'doing' | 'waiting' | 'done' | 'closed';
|
|
81
|
+
export interface RelayBoardItem {
|
|
82
|
+
/** Its number in the room, as people name it (#n). */
|
|
83
|
+
n: number;
|
|
84
|
+
title: string;
|
|
85
|
+
state: RelayBoardState;
|
|
86
|
+
/** How it goes in words of the owner's language: `Being fixed`, `Waiting for the owner`. */
|
|
87
|
+
label: string;
|
|
88
|
+
/** Who it came from, by name. */
|
|
89
|
+
people: string[];
|
|
90
|
+
at: number;
|
|
91
|
+
}
|
|
92
|
+
/** A board of an app in a room: its name (`Feedback`), and its items, the latest last. */
|
|
93
|
+
export interface RelayRoomBoard {
|
|
94
|
+
title: string;
|
|
95
|
+
items: RelayBoardItem[];
|
|
96
|
+
}
|
|
97
|
+
export declare namespace RelayBoardUtil {
|
|
98
|
+
function key(app: string, member: string): string;
|
|
99
|
+
/** The board under a key of the state, if the owner of the room wrote it under their own name and it is well formed. */
|
|
100
|
+
function read(key: string, value: unknown, by: string, owner: string | undefined): RelayRoomBoard | undefined;
|
|
101
|
+
/** How many are being done or wait, and how many are done: what a line over the chat says. */
|
|
102
|
+
function counts(board: RelayRoomBoard): {
|
|
103
|
+
open: number;
|
|
104
|
+
done: number;
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=relay-room-app.d.ts.map
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RelayBoardUtil = exports.RELAY_BOARD_MAX = exports.RELAY_BOARD_KEY = exports.RoomPacer = exports.RoomAppUtil = exports.ROOM_APP_STALE_MS = exports.ROOM_AGENTS_KEY = void 0;
|
|
4
|
+
exports.roomSpeaker = roomSpeaker;
|
|
5
|
+
/**
|
|
6
|
+
* What every app of a group chat that listens and speaks there needs (docs/design/ta-feedback.md 1): what others said
|
|
7
|
+
* since it last read, paced; who speaks for the user (their double or an agent of theirs in the room); what others wrote
|
|
8
|
+
* kept as theirs when a model reads it; and a board of how things go that every member, and those in a browser, see.
|
|
9
|
+
* Feedback is one such app; a vote, a rota or a help desk would be others.
|
|
10
|
+
*/
|
|
11
|
+
/** Under `agents:<member>` of the state of a room, each member lists the agents of theirs they invited to it. */
|
|
12
|
+
exports.ROOM_AGENTS_KEY = 'agents:';
|
|
13
|
+
/** A line older than this when an app reads it is left: Ta was off for days. */
|
|
14
|
+
exports.ROOM_APP_STALE_MS = 3 * 24 * 60 * 60 * 1000;
|
|
15
|
+
const HOUR_MS = 60 * 60 * 1000;
|
|
16
|
+
var RoomAppUtil;
|
|
17
|
+
(function (RoomAppUtil) {
|
|
18
|
+
/** What others wrote, which a model reads inside tags: no tags of its own. */
|
|
19
|
+
function quote(text) {
|
|
20
|
+
return text.replace(/</g, '<').replace(/>/g, '>');
|
|
21
|
+
}
|
|
22
|
+
RoomAppUtil.quote = quote;
|
|
23
|
+
/**
|
|
24
|
+
* What others said to the room since `since`: not by the user, not too long ago, not to someone in particular (@ a
|
|
25
|
+
* person, a double or an agent: theirs to answer), not said by a double or an agent.
|
|
26
|
+
*/
|
|
27
|
+
function fresh(lines, self, since, now, staleMs = exports.ROOM_APP_STALE_MS) {
|
|
28
|
+
return lines.filter(line => { var _a; return line.from !== self && line.at > since && now - line.at < staleMs && !((_a = line.to) === null || _a === void 0 ? void 0 : _a.length) && !line.double && !line.agent; });
|
|
29
|
+
}
|
|
30
|
+
RoomAppUtil.fresh = fresh;
|
|
31
|
+
/** Whether one more fits in the hour before `now`. */
|
|
32
|
+
function within(times, now, most) {
|
|
33
|
+
return times.filter(at => now - at < HOUR_MS).length < most;
|
|
34
|
+
}
|
|
35
|
+
RoomAppUtil.within = within;
|
|
36
|
+
/** People named with @, each once. */
|
|
37
|
+
function mentions(names) {
|
|
38
|
+
return [...new Set(names)].map(name => `@${name}`).join(' ');
|
|
39
|
+
}
|
|
40
|
+
RoomAppUtil.mentions = mentions;
|
|
41
|
+
})(RoomAppUtil || (exports.RoomAppUtil = RoomAppUtil = {}));
|
|
42
|
+
/**
|
|
43
|
+
* Who speaks for the user in a room: the agent of theirs they chose, while it is in the room (as `agents:<member>` of
|
|
44
|
+
* its state lists it, written by them), else their double, named `doubleName`.
|
|
45
|
+
*/
|
|
46
|
+
async function roomSpeaker(rooms, room, self, agent, doubleName) {
|
|
47
|
+
if (agent) {
|
|
48
|
+
const key = `${exports.ROOM_AGENTS_KEY}${self}`;
|
|
49
|
+
const listed = (await rooms.getState(room, key).catch(() => ({})))[key];
|
|
50
|
+
const found = (listed === null || listed === void 0 ? void 0 : listed.by) === self && Array.isArray(listed.value) ? listed.value.find(each => (each === null || each === void 0 ? void 0 : each.id) === agent) : undefined;
|
|
51
|
+
if (found && typeof found.name === 'string') {
|
|
52
|
+
return { name: found.name, extra: { agent: { id: found.id, name: found.name } } };
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return { name: doubleName, extra: { double: true } };
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Paces the work of an app on what is said in rooms: once the room is quiet for `settleMs` (a few lines read as one), one
|
|
59
|
+
* run at a time per room, and no more runs that did something than `hourly` in an hour (past it, again after `laterMs`).
|
|
60
|
+
* `run` says whether it did something (a turn of a model, a line said).
|
|
61
|
+
*/
|
|
62
|
+
class RoomPacer {
|
|
63
|
+
constructor(run, options) {
|
|
64
|
+
this.run = run;
|
|
65
|
+
this.options = options;
|
|
66
|
+
this.timers = new Map();
|
|
67
|
+
this.queues = new Map();
|
|
68
|
+
this.runs = new Map();
|
|
69
|
+
this.disposed = false;
|
|
70
|
+
}
|
|
71
|
+
/** Something was said in a room: it is read once it is quiet (`delay`, settleMs by default). */
|
|
72
|
+
heard(room, delay = this.options.settleMs) {
|
|
73
|
+
var _a, _b;
|
|
74
|
+
if (this.disposed) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
clearTimeout(this.timers.get(room));
|
|
78
|
+
const timer = setTimeout(() => {
|
|
79
|
+
var _a;
|
|
80
|
+
this.timers.delete(room);
|
|
81
|
+
const next = ((_a = this.queues.get(room)) !== null && _a !== void 0 ? _a : Promise.resolve())
|
|
82
|
+
.then(() => this.turn(room))
|
|
83
|
+
.catch(error => this.options.failed(error))
|
|
84
|
+
.finally(() => {
|
|
85
|
+
if (this.queues.get(room) === next) {
|
|
86
|
+
this.queues.delete(room);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
this.queues.set(room, next);
|
|
90
|
+
}, delay);
|
|
91
|
+
(_b = (_a = timer).unref) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
92
|
+
this.timers.set(room, timer);
|
|
93
|
+
}
|
|
94
|
+
/** What runs in a room now, done. */
|
|
95
|
+
idle(room) {
|
|
96
|
+
var _a;
|
|
97
|
+
return (_a = this.queues.get(room)) !== null && _a !== void 0 ? _a : Promise.resolve();
|
|
98
|
+
}
|
|
99
|
+
dispose() {
|
|
100
|
+
this.disposed = true;
|
|
101
|
+
for (const timer of this.timers.values()) {
|
|
102
|
+
clearTimeout(timer);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
async turn(room) {
|
|
106
|
+
var _a;
|
|
107
|
+
if (this.disposed) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const now = this.options.now();
|
|
111
|
+
const times = ((_a = this.runs.get(room)) !== null && _a !== void 0 ? _a : []).filter(at => now - at < HOUR_MS);
|
|
112
|
+
if (!RoomAppUtil.within(times, now, this.options.hourly)) {
|
|
113
|
+
this.heard(room, this.options.laterMs);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (await this.run(room)) {
|
|
117
|
+
this.runs.set(room, [...times, now]);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
exports.RoomPacer = RoomPacer;
|
|
122
|
+
/** Under `board:<app>:<member>` of the state of a room, its owner says how the things of an app go, for all in it. */
|
|
123
|
+
exports.RELAY_BOARD_KEY = 'board:';
|
|
124
|
+
/** Items of a board at most, the latest. */
|
|
125
|
+
exports.RELAY_BOARD_MAX = 30;
|
|
126
|
+
const STATES = ['doing', 'waiting', 'done', 'closed'];
|
|
127
|
+
var RelayBoardUtil;
|
|
128
|
+
(function (RelayBoardUtil) {
|
|
129
|
+
function key(app, member) {
|
|
130
|
+
return `${exports.RELAY_BOARD_KEY}${app}:${member}`;
|
|
131
|
+
}
|
|
132
|
+
RelayBoardUtil.key = key;
|
|
133
|
+
/** The board under a key of the state, if the owner of the room wrote it under their own name and it is well formed. */
|
|
134
|
+
function read(key, value, by, owner) {
|
|
135
|
+
if (!owner || by !== owner || !key.startsWith(exports.RELAY_BOARD_KEY) || !key.endsWith(`:${owner}`) || !value || typeof value !== 'object') {
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
138
|
+
const { title, items } = value;
|
|
139
|
+
if (typeof title !== 'string' || !Array.isArray(items)) {
|
|
140
|
+
return undefined;
|
|
141
|
+
}
|
|
142
|
+
return {
|
|
143
|
+
title: cut(title, 40),
|
|
144
|
+
items: items
|
|
145
|
+
.filter(item => item &&
|
|
146
|
+
Number.isInteger(item.n) &&
|
|
147
|
+
typeof item.title === 'string' &&
|
|
148
|
+
STATES.includes(item.state) &&
|
|
149
|
+
typeof item.label === 'string' &&
|
|
150
|
+
typeof item.at === 'number')
|
|
151
|
+
.slice(-exports.RELAY_BOARD_MAX)
|
|
152
|
+
.map(item => ({
|
|
153
|
+
n: item.n,
|
|
154
|
+
title: cut(item.title, 80),
|
|
155
|
+
state: item.state,
|
|
156
|
+
label: cut(item.label, 30),
|
|
157
|
+
people: Array.isArray(item.people) ? item.people.filter((name) => typeof name === 'string').slice(0, 5) : [],
|
|
158
|
+
at: item.at,
|
|
159
|
+
})),
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
RelayBoardUtil.read = read;
|
|
163
|
+
/** How many are being done or wait, and how many are done: what a line over the chat says. */
|
|
164
|
+
function counts(board) {
|
|
165
|
+
return {
|
|
166
|
+
open: board.items.filter(item => item.state === 'doing' || item.state === 'waiting').length,
|
|
167
|
+
done: board.items.filter(item => item.state === 'done').length,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
RelayBoardUtil.counts = counts;
|
|
171
|
+
function cut(text, max) {
|
|
172
|
+
const one = text.replace(/\s+/g, ' ').trim();
|
|
173
|
+
return one.length > max ? `${one.slice(0, max - 1)}…` : one;
|
|
174
|
+
}
|
|
175
|
+
})(RelayBoardUtil || (exports.RelayBoardUtil = RelayBoardUtil = {}));
|
|
176
|
+
//# sourceMappingURL=relay-room-app.js.map
|