@celljs/ta-relay 4.22.0 → 4.24.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.
Files changed (80) hide show
  1. package/esm/common/index.d.ts +2 -0
  2. package/esm/common/index.js +2 -0
  3. package/esm/common/relay-blobs.d.ts +36 -2
  4. package/esm/common/relay-blobs.js +33 -5
  5. package/esm/common/relay-chat-store.d.ts +69 -0
  6. package/esm/common/relay-chat-store.js +50 -0
  7. package/esm/common/relay-hub-charter.d.ts +2 -0
  8. package/esm/common/relay-hub-charter.js +3 -0
  9. package/esm/common/relay-hub-log.d.ts +65 -0
  10. package/esm/common/relay-hub-log.js +147 -0
  11. package/esm/common/relay-hub.d.ts +3 -0
  12. package/esm/common/relay-hub.js +18 -0
  13. package/esm/common/relay-hubs-admins.d.ts +1 -0
  14. package/esm/common/relay-hubs-admins.js +10 -6
  15. package/esm/common/relay-hubs-chats.d.ts +73 -0
  16. package/esm/common/relay-hubs-chats.js +367 -0
  17. package/esm/common/relay-hubs-connection.d.ts +3 -1
  18. package/esm/common/relay-hubs-connection.js +7 -0
  19. package/esm/common/relay-hubs-protocol.d.ts +16 -0
  20. package/esm/common/relay-hubs.d.ts +2 -2
  21. package/esm/common/relay-hubs.js +14 -11
  22. package/esm/common/relay-info.d.ts +23 -1
  23. package/esm/common/relay-info.js +25 -2
  24. package/esm/common/relay-protocol.d.ts +60 -1
  25. package/esm/common/relay-protocol.js +15 -0
  26. package/esm/common/relay-room-chat.d.ts +126 -4
  27. package/esm/common/relay-room-chat.js +230 -6
  28. package/esm/guest/guest-i18n.d.ts +2 -0
  29. package/esm/guest/guest-i18n.js +8 -0
  30. package/esm/guest/guest.js +8 -5
  31. package/esm/node/index.d.ts +1 -0
  32. package/esm/node/index.js +1 -0
  33. package/esm/node/relay-chat-files.d.ts +52 -0
  34. package/esm/node/relay-chat-files.js +224 -0
  35. package/esm/node/relay-hub-files.d.ts +11 -1
  36. package/esm/node/relay-hub-files.js +8 -1
  37. package/esm/node/relay-server.d.ts +9 -1
  38. package/esm/node/relay-server.js +29 -18
  39. package/lib/common/index.d.ts +2 -0
  40. package/lib/common/index.js +2 -0
  41. package/lib/common/relay-blobs.d.ts +36 -2
  42. package/lib/common/relay-blobs.js +34 -6
  43. package/lib/common/relay-chat-store.d.ts +70 -0
  44. package/lib/common/relay-chat-store.js +54 -0
  45. package/lib/common/relay-hub-charter.d.ts +2 -0
  46. package/lib/common/relay-hub-charter.js +3 -0
  47. package/lib/common/relay-hub-log.d.ts +66 -0
  48. package/lib/common/relay-hub-log.js +151 -0
  49. package/lib/common/relay-hub.d.ts +3 -0
  50. package/lib/common/relay-hub.js +18 -0
  51. package/lib/common/relay-hubs-admins.d.ts +1 -0
  52. package/lib/common/relay-hubs-admins.js +9 -5
  53. package/lib/common/relay-hubs-chats.d.ts +74 -0
  54. package/lib/common/relay-hubs-chats.js +371 -0
  55. package/lib/common/relay-hubs-connection.d.ts +3 -1
  56. package/lib/common/relay-hubs-connection.js +7 -0
  57. package/lib/common/relay-hubs-protocol.d.ts +16 -0
  58. package/lib/common/relay-hubs.d.ts +2 -2
  59. package/lib/common/relay-hubs.js +14 -11
  60. package/lib/common/relay-info.d.ts +23 -1
  61. package/lib/common/relay-info.js +26 -3
  62. package/lib/common/relay-protocol.d.ts +60 -1
  63. package/lib/common/relay-protocol.js +16 -1
  64. package/lib/common/relay-room-chat.d.ts +126 -4
  65. package/lib/common/relay-room-chat.js +231 -7
  66. package/lib/guest/guest-i18n.d.ts +2 -0
  67. package/lib/guest/guest-i18n.js +8 -0
  68. package/lib/guest/guest.js +7 -4
  69. package/lib/node/index.d.ts +1 -0
  70. package/lib/node/index.js +1 -0
  71. package/lib/node/relay-chat-files.d.ts +53 -0
  72. package/lib/node/relay-chat-files.js +228 -0
  73. package/lib/node/relay-hub-files.d.ts +11 -1
  74. package/lib/node/relay-hub-files.js +8 -1
  75. package/lib/node/relay-server.d.ts +9 -1
  76. package/lib/node/relay-server.js +27 -16
  77. package/package.json +3 -3
  78. package/viewer/join.html +4 -4
  79. package/viewer/page.html +10 -10
  80. package/viewer/room.html +15 -15
@@ -1,3 +1,10 @@
1
+ /** The bytes of a file of each kind at most: what passes between members in a minute or two. */
2
+ export const RELAY_CHAT_FILE_BYTES = { file: 50 * 1024 * 1024, video: 30 * 1024 * 1024, voice: 2 * 1024 * 1024 };
3
+ /** How long a voice message and a video are at most. */
4
+ export const RELAY_CHAT_VOICE_MS = 60000;
5
+ export const RELAY_CHAT_VIDEO_MS = 3 * 60000;
6
+ /** The files of a line at most. */
7
+ export const RELAY_CHAT_FILES = 9;
1
8
  /** The keys of what is said, `chat:<member>:<n>`: each member writes only its own, so none can write as another. */
2
9
  export const RELAY_CHAT_KEY = 'chat:';
3
10
  /** The bytes of JSON of one part at most, well under what the relay takes of a value once sealed. */
@@ -5,6 +12,15 @@ export const RELAY_CHAT_PART_BYTES = 8 * 1024;
5
12
  /** The parts of each member kept: the oldest is cleared as a new one starts. */
6
13
  export const RELAY_CHAT_PARTS = 6;
7
14
  export const RELAY_CHAT_TEXT_MAX = 2000;
15
+ /** The pictures of a line at most, as WeChat sends nine at once. */
16
+ export const RELAY_CHAT_IMAGES = 9;
17
+ /** The bytes of a picture at most. */
18
+ export const RELAY_CHAT_IMAGE_BYTES = 2 * 1024 * 1024;
19
+ /** The characters of the data URL of a thumbnail at most. */
20
+ export const RELAY_CHAT_THUMB_CHARS = 900;
21
+ const IMAGE_TYPES = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'];
22
+ /** Lines a chat holds at once: the latest; older ones are read as the page asks (RelayRoomChat.older). */
23
+ export const RELAY_CHAT_WINDOW = 500;
8
24
  const TRIES = 6;
9
25
  export var RelayRoomChatUtil;
10
26
  (function (RelayRoomChatUtil) {
@@ -44,17 +60,141 @@ export var RelayRoomChatUtil;
44
60
  ...(line.person === true && to.length && line.double !== true && !line.agent ? { person: true } : {}),
45
61
  ...(typeof line.re === 'string' ? { re: line.re } : {}),
46
62
  ...(line.task === true && to.length ? { task: true } : {}),
63
+ ...images(line.images),
64
+ ...files(line.files),
47
65
  };
48
66
  }
49
67
  RelayRoomChatUtil.extra = extra;
68
+ /** The files of a stored line, as far as each is well formed. */
69
+ function files(value) {
70
+ if (!Array.isArray(value)) {
71
+ return {};
72
+ }
73
+ const files = [];
74
+ for (const file of value.slice(0, RELAY_CHAT_FILES)) {
75
+ const kind = file === null || file === void 0 ? void 0 : file.kind;
76
+ if (!file ||
77
+ (kind !== 'file' && kind !== 'voice' && kind !== 'video') ||
78
+ typeof file.id !== 'string' ||
79
+ !/^[a-f0-9]{24}$/.test(file.id) ||
80
+ typeof file.sha !== 'string' ||
81
+ !/^[0-9a-f]{64}$/.test(file.sha) ||
82
+ !Number.isInteger(file.bytes) ||
83
+ file.bytes <= 0 ||
84
+ file.bytes > RELAY_CHAT_FILE_BYTES[kind]) {
85
+ continue;
86
+ }
87
+ const name = [...(typeof file.name === 'string' ? file.name : '')]
88
+ .filter(char => char.charCodeAt(0) >= 32 && char !== '/' && char !== '\\')
89
+ .join('')
90
+ .slice(0, 120) || kind;
91
+ const type = typeof file.type === 'string' && /^[\w.+-]+\/[\w.+-]+$/.test(file.type) ? file.type.slice(0, 100) : 'application/octet-stream';
92
+ const most = kind === 'voice' ? RELAY_CHAT_VOICE_MS : RELAY_CHAT_VIDEO_MS;
93
+ const ms = kind !== 'file' && Number.isFinite(file.ms) ? Math.min(Math.max(Math.round(file.ms), 0), most) : undefined;
94
+ const size = kind === 'video' && Number.isInteger(file.w) && Number.isInteger(file.h) && file.w > 0 && file.h > 0;
95
+ const thumb = kind === 'video' &&
96
+ typeof file.thumb === 'string' &&
97
+ file.thumb.length <= RELAY_CHAT_THUMB_CHARS &&
98
+ /^data:image\/(jpeg|png|webp);base64,/.test(file.thumb)
99
+ ? file.thumb
100
+ : undefined;
101
+ files.push({
102
+ id: file.id,
103
+ kind,
104
+ name,
105
+ type,
106
+ bytes: file.bytes,
107
+ sha: file.sha,
108
+ ...(ms !== undefined ? { ms } : {}),
109
+ ...(size ? { w: file.w, h: file.h } : {}),
110
+ ...(thumb ? { thumb } : {}),
111
+ });
112
+ }
113
+ return files.length ? { files } : {};
114
+ }
115
+ RelayRoomChatUtil.files = files;
116
+ /** The pictures of a stored line, as far as each is well formed. */
117
+ function images(value) {
118
+ if (!Array.isArray(value)) {
119
+ return {};
120
+ }
121
+ const images = [];
122
+ for (const image of value.slice(0, RELAY_CHAT_IMAGES)) {
123
+ if (image &&
124
+ typeof image.id === 'string' &&
125
+ /^[A-Za-z0-9-]{8,64}$/.test(image.id) &&
126
+ typeof image.type === 'string' &&
127
+ IMAGE_TYPES.includes(image.type) &&
128
+ typeof image.sha === 'string' &&
129
+ /^[0-9a-f]{64}$/.test(image.sha) &&
130
+ Number.isInteger(image.w) &&
131
+ Number.isInteger(image.h) &&
132
+ Number.isInteger(image.bytes) &&
133
+ image.w > 0 &&
134
+ image.h > 0 &&
135
+ image.bytes > 0 &&
136
+ image.bytes <= RELAY_CHAT_IMAGE_BYTES) {
137
+ const thumb = typeof image.thumb === 'string' && image.thumb.length <= RELAY_CHAT_THUMB_CHARS && /^data:image\/(jpeg|png|webp);base64,/.test(image.thumb)
138
+ ? image.thumb
139
+ : undefined;
140
+ const blob = image.blob;
141
+ const ok = !!blob &&
142
+ typeof blob.id === 'string' &&
143
+ /^[A-Za-z0-9_-]{16,64}$/.test(blob.id) &&
144
+ typeof blob.read === 'string' &&
145
+ /^[A-Za-z0-9_-]{43}$/.test(blob.read) &&
146
+ typeof blob.key === 'string' &&
147
+ /^[A-Za-z0-9_-]{43}$/.test(blob.key) &&
148
+ Number.isFinite(blob.until);
149
+ images.push({
150
+ id: image.id,
151
+ type: image.type,
152
+ w: image.w,
153
+ h: image.h,
154
+ bytes: image.bytes,
155
+ sha: image.sha,
156
+ ...(thumb ? { thumb } : {}),
157
+ ...(ok && blob ? { blob: { id: blob.id, read: blob.read, key: blob.key, until: blob.until } } : {}),
158
+ });
159
+ }
160
+ }
161
+ return images.length ? { images } : {};
162
+ }
163
+ /** What a line says in a word where only text shows (the list of chats, a notice, a page of guests). */
164
+ function preview(line, picture, words = { file: '[file]', voice: '[voice]', video: '[video]' }) {
165
+ var _a;
166
+ var _b;
167
+ const pictures = ((_a = line.images) === null || _a === void 0 ? void 0 : _a.length) ? (line.images.length > 1 ? `${picture}×${line.images.length}` : picture) : '';
168
+ const files = ((_b = line.files) !== null && _b !== void 0 ? _b : []).map(file => (file.kind === 'file' ? `${words.file} ${file.name}` : words[file.kind]));
169
+ return [pictures, ...files, line.text].filter(Boolean).join(' ');
170
+ }
171
+ RelayRoomChatUtil.preview = preview;
50
172
  function stored(lines) {
51
- return lines.map(({ from: _from, ...line }) => line);
173
+ return lines.map(({ from: _from, seq: _seq, pending: _pending, failed: _failed, ...line }) => line);
52
174
  }
53
175
  RelayRoomChatUtil.stored = stored;
176
+ /** A line of the log, as its member signed it: well formed, or none. */
177
+ function signed(member, value, seq) {
178
+ const line = value;
179
+ if (!line || typeof line.id !== 'string' || typeof line.text !== 'string' || typeof line.at !== 'number') {
180
+ return undefined;
181
+ }
182
+ const name = typeof line.name === 'string' ? line.name.slice(0, 64) : '';
183
+ const text = line.text.slice(0, RELAY_CHAT_TEXT_MAX);
184
+ return { id: line.id.slice(0, 40), from: member, name, text, at: line.at, ...extra(line), ...(seq ? { seq } : {}) };
185
+ }
186
+ RelayRoomChatUtil.signed = signed;
54
187
  function bytes(lines) {
55
188
  return new TextEncoder().encode(JSON.stringify(lines)).length;
56
189
  }
57
190
  RelayRoomChatUtil.bytes = bytes;
191
+ /** An error of a call a Ta service of before does not know (JSON-RPC's method not found, or its words). */
192
+ function unknownMethod(error) {
193
+ var _a;
194
+ const found = error;
195
+ return (found === null || found === void 0 ? void 0 : found.code) === -32601 || /method not found|not a function|unknown method|no such method/i.test(String((_a = found === null || found === void 0 ? void 0 : found.message) !== null && _a !== void 0 ? _a : error));
196
+ }
197
+ RelayRoomChatUtil.unknownMethod = unknownMethod;
58
198
  function id() {
59
199
  return `${Date.now().toString(36)}${Math.random().toString(36).slice(2, 8)}`;
60
200
  }
@@ -72,6 +212,9 @@ export class RelayRoomChat {
72
212
  this.parts = new Map();
73
213
  this.listeners = new Set();
74
214
  this.all = [];
215
+ /** Older lines are kept than those read (the log, RelayRoomChatRooms.readChat). */
216
+ this.olderKept = false;
217
+ this.log = typeof rooms.readChat === 'function' && typeof rooms.say === 'function';
75
218
  }
76
219
  /** All that is said, the earliest first. */
77
220
  get lines() {
@@ -81,7 +224,26 @@ export class RelayRoomChat {
81
224
  this.listeners.add(listener);
82
225
  return () => this.listeners.delete(listener);
83
226
  }
227
+ /** Whether there are older lines than those read: `older` reads them. */
228
+ get more() {
229
+ return this.olderKept;
230
+ }
84
231
  async load() {
232
+ if (this.log && this.rooms.readChat) {
233
+ const read = await this.rooms.readChat(this.room, { limit: RELAY_CHAT_WINDOW }).catch((error) => {
234
+ if (!RelayRoomChatUtil.unknownMethod(error)) {
235
+ throw error;
236
+ }
237
+ this.log = false;
238
+ return undefined;
239
+ });
240
+ if (read) {
241
+ this.olderKept = read.more;
242
+ this.all = Array.isArray(read.lines) ? read.lines : [];
243
+ this.tell();
244
+ return;
245
+ }
246
+ }
85
247
  const state = await this.rooms.getState(this.room, RELAY_CHAT_KEY);
86
248
  this.parts.clear();
87
249
  for (const [key, value] of Object.entries(state)) {
@@ -89,8 +251,60 @@ export class RelayRoomChat {
89
251
  }
90
252
  this.changed();
91
253
  }
254
+ /** Lines before those read, a page of them: how many came. */
255
+ async older(limit = 100) {
256
+ const first = this.all[0];
257
+ if (!this.log || !this.rooms.readChat || !first || !this.olderKept) {
258
+ return 0;
259
+ }
260
+ const read = await this.rooms.readChat(this.room, { before: first.id, limit });
261
+ const known = new Set(this.all.map(line => line.id));
262
+ const lines = read.lines.filter(line => !known.has(line.id));
263
+ this.olderKept = read.more;
264
+ this.all = [...lines, ...this.all];
265
+ this.tell();
266
+ return lines.length;
267
+ }
268
+ /**
269
+ * What happened in the room, as its event tells: a line of the log (`chat`), or a key of the state set (`state`,
270
+ * the chat of a Ta service of before). Whether it was of the chat.
271
+ */
272
+ hear(event) {
273
+ if (event.room !== undefined && event.room !== this.room) {
274
+ return false;
275
+ }
276
+ if (event.type === 'chat' && event.line) {
277
+ this.heardLine(event.line);
278
+ return true;
279
+ }
280
+ return event.type === 'state' && typeof event.key === 'string' && this.heard(event.key, event);
281
+ }
282
+ /** A line said or taken: one of the same id is replaced (sent, refused), a new one comes last. */
283
+ heardLine(line) {
284
+ const index = this.all.findIndex(each => each.id === line.id);
285
+ if (index >= 0) {
286
+ const next = [...this.all];
287
+ next[index] = line;
288
+ this.all = next;
289
+ }
290
+ else {
291
+ const next = [...this.all, line];
292
+ // A line taken while one of this Ta waits goes before it: the pending come last.
293
+ const pending = next.findIndex(each => each.pending);
294
+ if (pending >= 0 && !line.pending) {
295
+ next.splice(next.length - 1, 1);
296
+ next.splice(pending, 0, line);
297
+ }
298
+ this.all = next.length > RELAY_CHAT_WINDOW * 2 ? next.slice(-RELAY_CHAT_WINDOW) : next;
299
+ this.olderKept || (this.olderKept = next.length > this.all.length);
300
+ }
301
+ this.tell();
302
+ }
92
303
  /** A key of the room set, as its event tells: whether it was of the chat. */
93
304
  heard(key, value) {
305
+ if (this.log) {
306
+ return !!RelayRoomChatUtil.parse(key);
307
+ }
94
308
  if (!RelayRoomChatUtil.parse(key)) {
95
309
  return false;
96
310
  }
@@ -107,17 +321,24 @@ export class RelayRoomChat {
107
321
  * again on what another client of the same Ta wrote first. The line said, or undefined when there was nothing to say.
108
322
  */
109
323
  async say(text, self, extra = {}) {
110
- var _a;
111
- var _b, _c;
324
+ var _a, _b, _c;
325
+ var _d, _e;
112
326
  const said = text.trim().slice(0, RELAY_CHAT_TEXT_MAX);
113
- if (!said) {
327
+ if (!said && !((_a = extra.images) === null || _a === void 0 ? void 0 : _a.length) && !((_b = extra.files) === null || _b === void 0 ? void 0 : _b.length)) {
114
328
  return undefined;
115
329
  }
330
+ if (this.log && this.rooms.say) {
331
+ const line = await this.rooms.say(this.room, said, RelayRoomChatUtil.extra(extra));
332
+ if (line) {
333
+ this.heardLine(line);
334
+ }
335
+ return line;
336
+ }
116
337
  for (let tries = 0; tries < TRIES; tries++) {
117
338
  const latest = this.latest(self.member);
118
339
  // After what it said last, even within the same millisecond: the lines of a member keep their order.
119
340
  const last = latest === null || latest === void 0 ? void 0 : latest.lines[latest.lines.length - 1];
120
- const at = Math.max(Date.now(), ((_b = last === null || last === void 0 ? void 0 : last.at) !== null && _b !== void 0 ? _b : 0) + 1);
341
+ const at = Math.max(Date.now(), ((_d = last === null || last === void 0 ? void 0 : last.at) !== null && _d !== void 0 ? _d : 0) + 1);
121
342
  const line = {
122
343
  id: RelayRoomChatUtil.id(),
123
344
  from: self.member,
@@ -131,7 +352,7 @@ export class RelayRoomChat {
131
352
  const lines = fits && latest ? [...latest.lines, line] : [line];
132
353
  const key = RelayRoomChatUtil.key(self.member, part);
133
354
  const value = RelayRoomChatUtil.stored(lines);
134
- const result = await this.rooms.setState(this.room, key, value, (_c = (_a = this.parts.get(key)) === null || _a === void 0 ? void 0 : _a.version) !== null && _c !== void 0 ? _c : 0);
355
+ const result = await this.rooms.setState(this.room, key, value, (_e = (_c = this.parts.get(key)) === null || _c === void 0 ? void 0 : _c.version) !== null && _e !== void 0 ? _e : 0);
135
356
  if (result.ok) {
136
357
  this.put(key, { value, version: result.version, by: self.member });
137
358
  this.changed();
@@ -170,6 +391,9 @@ export class RelayRoomChat {
170
391
  }
171
392
  changed() {
172
393
  this.all = [...this.parts.values()].flatMap(part => part.lines).sort((a, b) => a.at - b.at || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
394
+ this.tell();
395
+ }
396
+ tell() {
173
397
  for (const listener of this.listeners) {
174
398
  listener();
175
399
  }
@@ -10,6 +10,8 @@ declare const zh: {
10
10
  namePlaceholder: string;
11
11
  join: string;
12
12
  joining: string;
13
+ picture: string;
14
+ file: string;
13
15
  keep: string;
14
16
  haveTa: string;
15
17
  waiting: string;
@@ -10,6 +10,8 @@ const zh = {
10
10
  namePlaceholder: '大家看到的名字',
11
11
  join: '申请加入',
12
12
  joining: '正在申请…',
13
+ picture: '[图片,在 Ta 里看]',
14
+ file: '[文件、语音或视频,在 Ta 里看]',
13
15
  keep: '你的名字和一把只属于这个浏览器的钥匙保存在本机;清除浏览器数据后要重新申请。',
14
16
  haveTa: '装了 Ta?在 Ta 应用里扫码或粘贴这个链接,还能一起玩小镇等游戏。',
15
17
  waiting: '已向{by}申请',
@@ -58,6 +60,8 @@ const zhTw = {
58
60
  namePlaceholder: '大家看到的名字',
59
61
  join: '申請加入',
60
62
  joining: '正在申請…',
63
+ picture: '[圖片,在 Ta 裡看]',
64
+ file: '[檔案、語音或影片,在 Ta 裡看]',
61
65
  keep: '你的名字和一把只屬於這個瀏覽器的鑰匙儲存在本機;清除瀏覽器資料後要重新申請。',
62
66
  haveTa: '裝了 Ta?在 Ta 應用裡掃碼或貼上這個連結,還能一起玩小鎮等遊戲。',
63
67
  waiting: '已向{by}申請',
@@ -106,6 +110,8 @@ const en = {
106
110
  namePlaceholder: 'What everyone sees',
107
111
  join: 'Ask to join',
108
112
  joining: 'Asking…',
113
+ picture: '[Picture: see it in Ta]',
114
+ file: '[File, voice or video: see it in Ta]',
109
115
  keep: 'Your name and a key of this browser alone are kept on this device; clear its data and you ask again.',
110
116
  haveTa: 'Have Ta? Scan this link in the Ta app or paste it there, to play the Town and other games together too.',
111
117
  waiting: 'Asked {by}',
@@ -154,6 +160,8 @@ const ja = {
154
160
  namePlaceholder: 'みんなに見える名前',
155
161
  join: '参加をリクエスト',
156
162
  joining: 'リクエスト中…',
163
+ picture: '[画像:Ta で表示]',
164
+ file: '[ファイル・ボイス・動画:Ta で表示]',
157
165
  keep: 'あなたの名前とこのブラウザ専用のキーはこのデバイスに保存されます。ブラウザデータをクリアすると再度リクエストが必要です。',
158
166
  haveTa: 'Ta をインストール済みですか?Ta アプリでこのリンクをスキャンするかペーストして、タウンなどのゲームも一緒にプレイできます。',
159
167
  waiting: '{by}さんにリクエスト済み',
@@ -3,7 +3,7 @@ import { RelayHubUtil } from '../common/relay-hub-util.js';
3
3
  import { RelayHubs } from '../common/relay-hubs.js';
4
4
  import { RelayOpenInTa } from '../common/relay-open-in-ta.js';
5
5
  import { RELAY_BOARD_KEY, RelayBoardUtil } from '../common/relay-room-app.js';
6
- import { RelayRoomChat } from '../common/relay-room-chat.js';
6
+ import { RelayRoomChat, RelayRoomChatUtil } from '../common/relay-room-chat.js';
7
7
  import { ViewerMarkdown } from '../viewer/viewer-markdown.js';
8
8
  import { GuestI18n } from './guest-i18n.js';
9
9
  import { GUEST_STYLE } from './guest-style.js';
@@ -99,9 +99,12 @@ class GuestPage {
99
99
  }
100
100
  start() {
101
101
  this.hubs.onEvent(event => {
102
- var _a;
103
- if (event.type === 'state' && event.room === this.link.room) {
104
- (_a = this.chat) === null || _a === void 0 ? void 0 : _a.heard(event.key, event);
102
+ var _a, _b;
103
+ if (event.type === 'chat' && event.room === this.link.room) {
104
+ (_a = this.chat) === null || _a === void 0 ? void 0 : _a.hear(event);
105
+ }
106
+ else if (event.type === 'state' && event.room === this.link.room) {
107
+ (_b = this.chat) === null || _b === void 0 ? void 0 : _b.heard(event.key, event);
105
108
  if (event.key.startsWith(RELAY_BOARD_KEY)) {
106
109
  this.heardBoard(event.key, event.value, event.by);
107
110
  }
@@ -326,7 +329,7 @@ class GuestPage {
326
329
  if (separator) {
327
330
  nodes.push(div('when', GuestI18n.time(line.at)));
328
331
  }
329
- const bubble = div('bubble', ViewerMarkdown.render(line.text));
332
+ const bubble = div('bubble', ViewerMarkdown.render(RelayRoomChatUtil.preview(line, t('picture'), { file: t('file'), voice: t('file'), video: t('file') })));
330
333
  bubble.title = GuestI18n.time(line.at);
331
334
  if (line.from === self && !line.agent) {
332
335
  nodes.push(div('mine', bubble));
@@ -1,4 +1,5 @@
1
1
  export * from '../common/index.js';
2
+ export * from './relay-chat-files.js';
2
3
  export * from './relay-file-storage.js';
3
4
  export * from './relay-files-host.js';
4
5
  export * from './relay-host.js';
package/esm/node/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from '../common/index.js';
2
+ export * from './relay-chat-files.js';
2
3
  export * from './relay-file-storage.js';
3
4
  export * from './relay-files-host.js';
4
5
  export * from './relay-host.js';
@@ -0,0 +1,52 @@
1
+ import { type RelayChatState, type RelayChatStore } from '../common/relay-chat-store.js';
2
+ import type { RelayChatLine } from '../common/relay-room-chat.js';
3
+ /**
4
+ * The key what is said in the rooms is sealed with on this computer (docs/design/ta-chat-history.md 12): in the
5
+ * keychain of macOS (the service `Ta chats`, an account of the agent directory), elsewhere or with
6
+ * `TA_CHATS_KEY=file` in `chats/.key`, readable by the user alone. Made the first time.
7
+ */
8
+ export declare namespace RelayChatKeys {
9
+ const SERVICE = "Ta chats";
10
+ function local(agentDir: string, env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform): () => Promise<Uint8Array>;
11
+ }
12
+ /**
13
+ * What is said in the rooms, kept in `chats/<room>/` of the agent directory (docs/design/ta-chat-history.md 8): a
14
+ * file a month (`2026-11.log`), lines only added, each sealed on its own (AES-256-GCM), so that a line cut short by a
15
+ * crash loses that line alone; and the state of the log (`state`), sealed, written whole. A month goes as a file.
16
+ */
17
+ export declare class RelayChatFiles implements RelayChatStore {
18
+ readonly dir: string;
19
+ protected readonly key: () => Promise<Uint8Array>;
20
+ protected readonly now: () => number;
21
+ /** The lines of each room read, as long as nothing was added that is not in them. */
22
+ protected readonly cache: Map<string, {
23
+ lines: RelayChatLine[];
24
+ months: number;
25
+ all: boolean;
26
+ }>;
27
+ constructor(dir: string, key: () => Promise<Uint8Array>, now?: () => number);
28
+ read(room: string, options: {
29
+ before?: string;
30
+ limit: number;
31
+ }): Promise<{
32
+ lines: RelayChatLine[];
33
+ more: boolean;
34
+ }>;
35
+ append(room: string, lines: RelayChatLine[]): Promise<void>;
36
+ state(room: string): Promise<RelayChatState | undefined>;
37
+ setState(room: string, state: RelayChatState): Promise<void>;
38
+ forget(room: string): Promise<void>;
39
+ /** The bytes of what is kept of a room; with `before`, of the months `clear` would take (those wholly before it). */
40
+ usage(room: string, before?: number): Promise<number>;
41
+ /** All the months of a room, or those wholly before `before`; a month after it stays whole. */
42
+ clear(room: string, before?: number): Promise<void>;
43
+ /** When the month of a file (`2026-11.log`) ends, UTC. */
44
+ static monthEnd(month: string): number;
45
+ protected roomDir(room: string): string;
46
+ /** The months kept of a room, the earliest first. */
47
+ protected months(room: string): string[];
48
+ protected readMonth(room: string, month: string): Promise<RelayChatLine[]>;
49
+ /** base64url of a nonce of 12 bytes, the text sealed and its tag. */
50
+ static seal(key: Uint8Array, text: string): string;
51
+ static open(key: Uint8Array, sealed: string): string | undefined;
52
+ }