@celljs/ta-relay 4.10.0 → 4.12.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 (118) hide show
  1. package/README.en.md +13 -1
  2. package/README.md +13 -1
  3. package/esm/common/index.d.ts +11 -0
  4. package/esm/common/index.js +11 -0
  5. package/esm/common/relay-blobs.d.ts +54 -0
  6. package/esm/common/relay-blobs.js +153 -0
  7. package/esm/common/relay-card.d.ts +23 -0
  8. package/esm/common/relay-card.js +30 -0
  9. package/esm/common/relay-content.d.ts +104 -0
  10. package/esm/common/relay-content.js +316 -0
  11. package/esm/common/relay-conversation.d.ts +59 -0
  12. package/esm/common/relay-conversation.js +9 -0
  13. package/esm/common/relay-faces.d.ts +32 -0
  14. package/esm/common/relay-faces.js +208 -0
  15. package/esm/common/relay-hub-util.d.ts +91 -0
  16. package/esm/common/relay-hub-util.js +164 -0
  17. package/esm/common/relay-hub.d.ts +125 -0
  18. package/esm/common/relay-hub.js +438 -0
  19. package/esm/common/relay-hubs-connection.d.ts +98 -0
  20. package/esm/common/relay-hubs-connection.js +505 -0
  21. package/esm/common/relay-hubs-protocol.d.ts +130 -0
  22. package/esm/common/relay-hubs-protocol.js +2 -0
  23. package/esm/common/relay-hubs.d.ts +61 -0
  24. package/esm/common/relay-hubs.js +351 -0
  25. package/esm/common/relay-identity.d.ts +46 -0
  26. package/esm/common/relay-identity.js +126 -0
  27. package/esm/common/relay-protocol.d.ts +211 -2
  28. package/esm/common/relay-protocol.js +53 -0
  29. package/esm/common/relay-room-chat.d.ts +109 -0
  30. package/esm/common/relay-room-chat.js +176 -0
  31. package/esm/common/relay-socket.d.ts +8 -0
  32. package/esm/common/relay-socket.js +23 -2
  33. package/esm/guest/guest-i18n.d.ts +50 -0
  34. package/esm/guest/guest-i18n.js +103 -0
  35. package/esm/guest/guest-style.d.ts +1 -0
  36. package/esm/guest/guest-style.js +85 -0
  37. package/esm/guest/guest.d.ts +1 -0
  38. package/esm/guest/guest.js +384 -0
  39. package/esm/node/index.d.ts +2 -0
  40. package/esm/node/index.js +2 -0
  41. package/esm/node/relay-host.d.ts +25 -3
  42. package/esm/node/relay-host.js +115 -4
  43. package/esm/node/relay-hub-files.d.ts +12 -0
  44. package/esm/node/relay-hub-files.js +39 -0
  45. package/esm/node/relay-server.d.ts +46 -1
  46. package/esm/node/relay-server.js +227 -1
  47. package/esm/node/relay-store.d.ts +72 -0
  48. package/esm/node/relay-store.js +123 -2
  49. package/esm/node/relay-viewer.d.ts +7 -0
  50. package/esm/node/relay-viewer.js +33 -0
  51. package/esm/viewer/viewer-i18n.d.ts +56 -0
  52. package/esm/viewer/viewer-i18n.js +117 -0
  53. package/esm/viewer/viewer-markdown.d.ts +7 -0
  54. package/esm/viewer/viewer-markdown.js +198 -0
  55. package/esm/viewer/viewer-style.d.ts +1 -0
  56. package/esm/viewer/viewer-style.js +72 -0
  57. package/esm/viewer/viewer.d.ts +8 -0
  58. package/esm/viewer/viewer.js +378 -0
  59. package/lib/common/index.d.ts +11 -0
  60. package/lib/common/index.js +11 -0
  61. package/lib/common/relay-blobs.d.ts +55 -0
  62. package/lib/common/relay-blobs.js +157 -0
  63. package/lib/common/relay-card.d.ts +24 -0
  64. package/lib/common/relay-card.js +33 -0
  65. package/lib/common/relay-content.d.ts +105 -0
  66. package/lib/common/relay-content.js +320 -0
  67. package/lib/common/relay-conversation.d.ts +60 -0
  68. package/lib/common/relay-conversation.js +12 -0
  69. package/lib/common/relay-faces.d.ts +33 -0
  70. package/lib/common/relay-faces.js +211 -0
  71. package/lib/common/relay-hub-util.d.ts +92 -0
  72. package/lib/common/relay-hub-util.js +167 -0
  73. package/lib/common/relay-hub.d.ts +126 -0
  74. package/lib/common/relay-hub.js +442 -0
  75. package/lib/common/relay-hubs-connection.d.ts +99 -0
  76. package/lib/common/relay-hubs-connection.js +510 -0
  77. package/lib/common/relay-hubs-protocol.d.ts +131 -0
  78. package/lib/common/relay-hubs-protocol.js +3 -0
  79. package/lib/common/relay-hubs.d.ts +62 -0
  80. package/lib/common/relay-hubs.js +355 -0
  81. package/lib/common/relay-identity.d.ts +47 -0
  82. package/lib/common/relay-identity.js +129 -0
  83. package/lib/common/relay-protocol.d.ts +211 -2
  84. package/lib/common/relay-protocol.js +54 -1
  85. package/lib/common/relay-room-chat.d.ts +110 -0
  86. package/lib/common/relay-room-chat.js +180 -0
  87. package/lib/common/relay-socket.d.ts +8 -0
  88. package/lib/common/relay-socket.js +23 -2
  89. package/lib/guest/guest-i18n.d.ts +51 -0
  90. package/lib/guest/guest-i18n.js +106 -0
  91. package/lib/guest/guest-style.d.ts +2 -0
  92. package/lib/guest/guest-style.js +88 -0
  93. package/lib/guest/guest.d.ts +2 -0
  94. package/lib/guest/guest.js +386 -0
  95. package/lib/node/index.d.ts +2 -0
  96. package/lib/node/index.js +2 -0
  97. package/lib/node/relay-host.d.ts +25 -3
  98. package/lib/node/relay-host.js +115 -4
  99. package/lib/node/relay-hub-files.d.ts +13 -0
  100. package/lib/node/relay-hub-files.js +43 -0
  101. package/lib/node/relay-server.d.ts +46 -1
  102. package/lib/node/relay-server.js +226 -0
  103. package/lib/node/relay-store.d.ts +72 -0
  104. package/lib/node/relay-store.js +121 -0
  105. package/lib/node/relay-viewer.d.ts +8 -0
  106. package/lib/node/relay-viewer.js +32 -0
  107. package/lib/viewer/viewer-i18n.d.ts +57 -0
  108. package/lib/viewer/viewer-i18n.js +120 -0
  109. package/lib/viewer/viewer-markdown.d.ts +8 -0
  110. package/lib/viewer/viewer-markdown.js +201 -0
  111. package/lib/viewer/viewer-style.d.ts +2 -0
  112. package/lib/viewer/viewer-style.js +75 -0
  113. package/lib/viewer/viewer.d.ts +9 -0
  114. package/lib/viewer/viewer.js +381 -0
  115. package/package.json +5 -4
  116. package/viewer/frame.html +1 -0
  117. package/viewer/page.html +80 -0
  118. package/viewer/room.html +94 -0
@@ -0,0 +1,316 @@
1
+ import { RelayBytes } from './relay-bytes.js';
2
+ import { RelayIdentityUtil } from './relay-identity.js';
3
+ import { RELAY_BLOB_PATH, RELAY_CONTENT_MAX_BYTES, RELAY_CONTENT_PATH, RELAY_ID, RelayCloseCode } from './relay-protocol.js';
4
+ import { RelaySocket } from './relay-socket.js';
5
+ const encoder = new TextEncoder();
6
+ const decoder = new TextDecoder();
7
+ export class RelayContentError extends Error {
8
+ constructor(reason, message) {
9
+ super(message);
10
+ this.reason = reason;
11
+ this.name = 'RelayContentError';
12
+ }
13
+ }
14
+ const PBKDF2_ITERATIONS = 600000;
15
+ /** Kinds the links of before carry no `c` for. */
16
+ const PLAIN_KINDS = new Set(['ta-conversation', 'file']);
17
+ const KIND = /^[a-z0-9][a-z0-9-]{0,31}$/;
18
+ /**
19
+ * Content shared by a link (docs/design/ta-link.md): its link, its keys, and how it is fetched, from the
20
+ * computer that shared it through the relay, or from the copy the relay keeps sealed. Runs the same in a
21
+ * browser (the viewer of the relay), in ta serve and in a Worker: WebCrypto, fetch and WebSocket only.
22
+ */
23
+ export var RelayContentUtil;
24
+ (function (RelayContentUtil) {
25
+ /**
26
+ * `https://<relay>/s#v=1&h=<host>&s=<share>&k=<key>`, with `p=1` for a password, `m=self`, `o=1` for a copy on the relay,
27
+ * `c=<kind>` for what is no conversation or file.
28
+ */
29
+ function link(content) {
30
+ var _a;
31
+ const fragment = new URLSearchParams({ v: '1', h: content.host, s: content.share });
32
+ if (content.access === 'self') {
33
+ fragment.set('m', 'self');
34
+ }
35
+ else if (content.access === 'people') {
36
+ fragment.set('m', 'people');
37
+ fragment.set('o', (_a = content.owner) !== null && _a !== void 0 ? _a : '');
38
+ }
39
+ else if (content.key) {
40
+ fragment.set('k', content.key);
41
+ }
42
+ if (content.access === 'password') {
43
+ fragment.set('p', '1');
44
+ }
45
+ if (content.offline && content.access !== 'self' && content.access !== 'people') {
46
+ fragment.set('o', '1');
47
+ }
48
+ if (content.kind && !PLAIN_KINDS.has(content.kind) && KIND.test(content.kind)) {
49
+ fragment.set('c', content.kind);
50
+ }
51
+ return `${content.relay}${RELAY_CONTENT_PATH}#${fragment}`;
52
+ }
53
+ RelayContentUtil.link = link;
54
+ function is(text) {
55
+ try {
56
+ parse(text);
57
+ return true;
58
+ }
59
+ catch (_a) {
60
+ return false;
61
+ }
62
+ }
63
+ RelayContentUtil.is = is;
64
+ /** Throws on what is not a link of {@link link}. */
65
+ function parse(text) {
66
+ var _a, _b;
67
+ const url = new URL(text.trim());
68
+ const fragment = new URLSearchParams(url.hash.slice(1));
69
+ const [host, share, key] = ['h', 's', 'k'].map(name => { var _a; return (_a = fragment.get(name)) !== null && _a !== void 0 ? _a : ''; });
70
+ const self = fragment.get('m') === 'self';
71
+ const people = fragment.get('m') === 'people';
72
+ const owner = (_a = fragment.get('o')) !== null && _a !== void 0 ? _a : '';
73
+ if (!/^https?:$/.test(url.protocol) ||
74
+ url.pathname !== RELAY_CONTENT_PATH ||
75
+ fragment.get('v') !== '1' ||
76
+ !RELAY_ID.test(host) ||
77
+ !RELAY_ID.test(share) ||
78
+ (people ? !/^[A-Za-z0-9_-]{22}$/.test(owner) : !self && !/^[A-Za-z0-9_-]{43}$/.test(key))) {
79
+ throw new RelayContentError('invalid', 'Not a link of something shared from Ta.');
80
+ }
81
+ const kind = (_b = fragment.get('c')) !== null && _b !== void 0 ? _b : '';
82
+ if (people) {
83
+ return { relay: url.origin, host, share, access: 'people', owner, offline: false, ...(KIND.test(kind) ? { kind } : {}) };
84
+ }
85
+ return {
86
+ relay: url.origin,
87
+ host,
88
+ share,
89
+ key: self ? undefined : key,
90
+ access: self ? 'self' : fragment.get('p') === '1' ? 'password' : 'link',
91
+ offline: !self && fragment.get('o') === '1',
92
+ ...(KIND.test(kind) ? { kind } : {}),
93
+ };
94
+ }
95
+ RelayContentUtil.parse = parse;
96
+ /**
97
+ * The key the content is sealed with: the key of the link, or with a password, one derived from both
98
+ * (PBKDF2 of the password, then HKDF with the key of the link), so that neither alone opens it.
99
+ */
100
+ async function contentKey(linkKey, share, password) {
101
+ if (password === undefined) {
102
+ return linkKey;
103
+ }
104
+ const subtle = globalThis.crypto.subtle;
105
+ const secret = await subtle.importKey('raw', encoder.encode(password.normalize('NFC')), 'PBKDF2', false, ['deriveBits']);
106
+ const stretched = await subtle.deriveBits({ name: 'PBKDF2', hash: 'SHA-256', salt: encoder.encode(`ta-share:${share}`), iterations: PBKDF2_ITERATIONS }, secret, 256);
107
+ return hkdf(linkKey, new Uint8Array(stretched), 'ta-share/1 password');
108
+ }
109
+ RelayContentUtil.contentKey = contentKey;
110
+ /**
111
+ * The key of content shared with a Ta friend (`people`): only the two make it, each with its own private key and the
112
+ * other's public one, for this share alone.
113
+ */
114
+ function peopleKey(identity, otherBox, share) {
115
+ return RelayIdentityUtil.agree(identity, otherBox, share, 'ta-share/1 people');
116
+ }
117
+ RelayContentUtil.peopleKey = peopleKey;
118
+ /** What reads the copy on the relay, which keeps only its SHA-256 (`x-ta-auth`). */
119
+ async function authToken(key) {
120
+ return RelayBytes.toBase64(await hkdf(key, new Uint8Array(0), 'ta-share/1 auth'));
121
+ }
122
+ RelayContentUtil.authToken = authToken;
123
+ async function sha256(text) {
124
+ return RelayBytes.toBase64(new Uint8Array(await globalThis.crypto.subtle.digest('SHA-256', encoder.encode(text))));
125
+ }
126
+ RelayContentUtil.sha256 = sha256;
127
+ /** The bytes of the copy on the relay: a random IV, then AES-256-GCM of {@link encode}. */
128
+ async function seal(key, item) {
129
+ const iv = RelayBytes.random(12);
130
+ const sealed = await globalThis.crypto.subtle.encrypt({ name: 'AES-GCM', iv: iv }, await blobKey(key), encode(item));
131
+ return RelayBytes.concat(iv, new Uint8Array(sealed));
132
+ }
133
+ RelayContentUtil.seal = seal;
134
+ /** Throws when it was not sealed with this key. */
135
+ async function open(key, bytes) {
136
+ const opened = await globalThis.crypto.subtle.decrypt({ name: 'AES-GCM', iv: bytes.subarray(0, 12) }, await blobKey(key), bytes.subarray(12));
137
+ return decode(new Uint8Array(opened));
138
+ }
139
+ RelayContentUtil.open = open;
140
+ /** The header as JSON behind its length (4 bytes), then the data. */
141
+ function encode(item) {
142
+ const { data, ...header } = item;
143
+ const head = encoder.encode(JSON.stringify(header));
144
+ const length = new Uint8Array(4);
145
+ new DataView(length.buffer).setUint32(0, head.length);
146
+ return RelayBytes.concat(length, head, data);
147
+ }
148
+ RelayContentUtil.encode = encode;
149
+ function decode(bytes) {
150
+ const length = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength).getUint32(0);
151
+ const header = JSON.parse(decoder.decode(bytes.subarray(4, 4 + length)));
152
+ return {
153
+ kind: String(header.kind),
154
+ title: String(header.title),
155
+ createdAt: Number(header.createdAt),
156
+ type: header.type,
157
+ data: bytes.slice(4 + length),
158
+ };
159
+ }
160
+ RelayContentUtil.decode = decode;
161
+ /**
162
+ * What a link shares: from the copy on the relay when it has one, else from the computer that shared it,
163
+ * end to end through the relay. Rejects with a RelayContentError that says why it cannot.
164
+ */
165
+ async function fetch(text, options = {}) {
166
+ const link = typeof text === 'string' ? parse(text) : text;
167
+ if (link.access === 'people') {
168
+ if (!options.people) {
169
+ throw new RelayContentError('people', 'Only the Ta friends it was shared with open it, in their own Ta.');
170
+ }
171
+ return fromHost(link, await peopleKey(options.people.identity, options.people.ownerBox, link.share), options);
172
+ }
173
+ if (link.access === 'self' || !link.key) {
174
+ throw new RelayContentError('self', 'Only the one who shared it opens it, in their own Ta.');
175
+ }
176
+ if (link.access === 'password' && !options.password) {
177
+ throw new RelayContentError('password', 'It is shared with a password.');
178
+ }
179
+ const key = await contentKey(RelayBytes.fromBase64(link.key), link.share, link.access === 'password' ? options.password : undefined);
180
+ if (link.offline) {
181
+ const copy = await fromRelay(link, key);
182
+ if (copy) {
183
+ return copy;
184
+ }
185
+ }
186
+ return fromHost(link, key, options);
187
+ }
188
+ RelayContentUtil.fetch = fetch;
189
+ /** The copy on the relay; undefined when there is none (any more), to ask the computer instead. */
190
+ async function fromRelay(link, key) {
191
+ let response;
192
+ try {
193
+ response = await globalThis.fetch(`${link.relay}${RELAY_BLOB_PATH}${link.share}`, { headers: { 'x-ta-auth': await authToken(key) } });
194
+ }
195
+ catch (_a) {
196
+ return undefined;
197
+ }
198
+ if (response.status === 403) {
199
+ throw link.access === 'password'
200
+ ? new RelayContentError('wrong', 'The password is wrong.')
201
+ : new RelayContentError('gone', 'This link no longer works.');
202
+ }
203
+ if (response.status === 429) {
204
+ throw new RelayContentError('busy', 'Too many wrong passwords: try again in a few minutes.');
205
+ }
206
+ if (!response.ok) {
207
+ return undefined;
208
+ }
209
+ try {
210
+ return await open(key, new Uint8Array(await response.arrayBuffer()));
211
+ }
212
+ catch (_b) {
213
+ throw new RelayContentError('wrong', 'The password is wrong.');
214
+ }
215
+ }
216
+ function fromHost(link, key, options) {
217
+ var _a;
218
+ const max = (_a = options.maxBytes) !== null && _a !== void 0 ? _a : RELAY_CONTENT_MAX_BYTES;
219
+ const pairing = { relay: link.relay, host: link.host, device: link.share, key: RelayBytes.toBase64(key) };
220
+ return new Promise((resolve, reject) => {
221
+ var _a;
222
+ const socket = new RelaySocket(pairing, { proveFirst: true });
223
+ const chunks = [];
224
+ let received = 0;
225
+ let header;
226
+ let done = false;
227
+ const finish = (error, item) => {
228
+ if (done) {
229
+ return;
230
+ }
231
+ done = true;
232
+ clearTimeout(timer);
233
+ socket.onclose = null;
234
+ socket.close();
235
+ if (item) {
236
+ resolve(item);
237
+ }
238
+ else {
239
+ reject(error);
240
+ }
241
+ };
242
+ const timer = setTimeout(() => finish(new RelayContentError('timeout', 'The computer that shared it took too long to send it.')), (_a = options.timeoutMs) !== null && _a !== void 0 ? _a : 60000);
243
+ socket.onmessage = ({ data }) => {
244
+ let message;
245
+ try {
246
+ message = JSON.parse(data);
247
+ }
248
+ catch (_a) {
249
+ finish(new RelayContentError('invalid', 'The computer that shared it sent what is not content.'));
250
+ return;
251
+ }
252
+ if (message.t === 'error') {
253
+ finish(new RelayContentError('gone', message.message));
254
+ }
255
+ else if (message.t === 'content') {
256
+ if (!(message.size >= 0) || message.size > max) {
257
+ finish(new RelayContentError('large', `It is larger than ${Math.round(max / 1024 / 1024)} MB.`));
258
+ return;
259
+ }
260
+ header = {
261
+ kind: String(message.kind),
262
+ title: String(message.title),
263
+ createdAt: Number(message.createdAt),
264
+ type: message.type,
265
+ size: message.size,
266
+ };
267
+ }
268
+ else if (message.t === 'chunk' && header) {
269
+ const bytes = RelayBytes.fromBase64(message.d);
270
+ received += bytes.length;
271
+ if (received > header.size) {
272
+ finish(new RelayContentError('invalid', 'It is larger than it said.'));
273
+ return;
274
+ }
275
+ chunks.push(bytes);
276
+ }
277
+ else if (message.t === 'end' && header) {
278
+ if (received !== header.size) {
279
+ finish(new RelayContentError('invalid', 'It came short.'));
280
+ return;
281
+ }
282
+ const { size: _size, ...rest } = header;
283
+ finish(undefined, { ...rest, data: RelayBytes.concat(...chunks) });
284
+ }
285
+ };
286
+ socket.onclose = ({ code, reason }) => finish(closed(code, reason, link));
287
+ });
288
+ }
289
+ function closed(code, reason, link) {
290
+ if (code === RelaySocket.REFUSED) {
291
+ if (reason === 'key') {
292
+ return link.access === 'password'
293
+ ? new RelayContentError('wrong', 'The password is wrong.')
294
+ : new RelayContentError('gone', 'This link no longer works.');
295
+ }
296
+ if (reason === 'busy') {
297
+ return new RelayContentError('busy', 'Too many wrong passwords: try again in a few minutes.');
298
+ }
299
+ return new RelayContentError('gone', 'This link no longer works: the share was stopped or ran out.');
300
+ }
301
+ return code === RelayCloseCode.HOST_OFFLINE || code === RelayCloseCode.TIMEOUT
302
+ ? new RelayContentError('offline', 'The computer that shared it is not running Ta now. Try again later.')
303
+ : new RelayContentError('offline', 'The computer that shared it cannot be reached now. Try again later.');
304
+ }
305
+ async function blobKey(key) {
306
+ const bytes = await hkdf(key, new Uint8Array(0), 'ta-share/1 blob');
307
+ return globalThis.crypto.subtle.importKey('raw', bytes, 'AES-GCM', false, ['encrypt', 'decrypt']);
308
+ }
309
+ async function hkdf(key, salt, info) {
310
+ const subtle = globalThis.crypto.subtle;
311
+ const secret = await subtle.importKey('raw', key, 'HKDF', false, ['deriveBits']);
312
+ const bits = await subtle.deriveBits({ name: 'HKDF', hash: 'SHA-256', salt: salt, info: encoder.encode(info) }, secret, 256);
313
+ return new Uint8Array(bits);
314
+ }
315
+ })(RelayContentUtil || (RelayContentUtil = {}));
316
+ //# sourceMappingURL=relay-content.js.map
@@ -0,0 +1,59 @@
1
+ /**
2
+ * A conversation shared by a link (RelayContentHeader.kind `ta-conversation`): pi's messages of its branch, as
3
+ * the one who shared it chose to hand on (docs/design/ta-link.md 2.8). The viewer of the relay draws it; Ta
4
+ * draws it too, and imports it as a conversation of its own.
5
+ */
6
+ export declare const RELAY_CONVERSATION_KIND = "ta-conversation";
7
+ /** A file or a page: its bytes, with RelayContentHeader.type. */
8
+ export declare const RELAY_FILE_KIND = "file";
9
+ export type RelayConversationPart = {
10
+ type: 'text';
11
+ text: string;
12
+ } | {
13
+ type: 'thinking';
14
+ thinking: string;
15
+ } | {
16
+ type: 'image';
17
+ data?: string;
18
+ mimeType?: string;
19
+ } | {
20
+ type: 'toolCall';
21
+ id: string;
22
+ name: string;
23
+ arguments: Record<string, unknown>;
24
+ };
25
+ /** pi's AgentMessage, the parts a conversation shows; the rest of what pi keeps passes through untouched. */
26
+ export type RelayConversationMessage = {
27
+ role: 'user';
28
+ content: string | RelayConversationPart[];
29
+ timestamp?: number;
30
+ } | {
31
+ role: 'assistant';
32
+ content: RelayConversationPart[];
33
+ model?: string;
34
+ provider?: string;
35
+ stopReason?: string;
36
+ errorMessage?: string;
37
+ timestamp?: number;
38
+ } | {
39
+ role: 'toolResult';
40
+ toolCallId: string;
41
+ toolName: string;
42
+ content: RelayConversationPart[];
43
+ isError?: boolean;
44
+ timestamp?: number;
45
+ };
46
+ export interface RelayConversation {
47
+ v: 1;
48
+ title: string;
49
+ /** The name of its directory, for a line under the title. */
50
+ place?: string;
51
+ messages: RelayConversationMessage[];
52
+ /** What was left out when it was shared: the outputs of its tools, and how many images. */
53
+ omitted?: {
54
+ outputs?: boolean;
55
+ images?: number;
56
+ };
57
+ /** How many places looked like a secret, and were taken out. */
58
+ redacted?: number;
59
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * A conversation shared by a link (RelayContentHeader.kind `ta-conversation`): pi's messages of its branch, as
3
+ * the one who shared it chose to hand on (docs/design/ta-link.md 2.8). The viewer of the relay draws it; Ta
4
+ * draws it too, and imports it as a conversation of its own.
5
+ */
6
+ export const RELAY_CONVERSATION_KIND = 'ta-conversation';
7
+ /** A file or a page: its bytes, with RelayContentHeader.type. */
8
+ export const RELAY_FILE_KIND = 'file';
9
+ //# sourceMappingURL=relay-conversation.js.map
@@ -0,0 +1,32 @@
1
+ /** How many faces there are. */
2
+ export declare const FACE_COUNT = 16;
3
+ /** An element of SVG: its tag, its attributes as written in SVG (`stroke-width`, `class`), what is in it. */
4
+ export interface FaceNode {
5
+ tag: string;
6
+ attrs: Record<string, string | number>;
7
+ children?: FaceNode[];
8
+ }
9
+ export interface Look {
10
+ color: string;
11
+ /** Eyes and mouth. */
12
+ eye: string;
13
+ cheek: string;
14
+ /** A second colour of the shape: ears, a stem, an antenna. */
15
+ accent?: string;
16
+ /** The height of the eyes and how far apart they are. */
17
+ eyeY: number;
18
+ gap: number;
19
+ mouth?: string;
20
+ /** Brows pressed in, a grin. */
21
+ brows?: boolean;
22
+ }
23
+ export declare namespace FaceUtil {
24
+ /** The face of an id: the same for the same id, on every device. */
25
+ function of(seed: string): number;
26
+ /** The face given, if it is one, else that of `seed`. */
27
+ function pick(face: number | undefined, seed?: string): number;
28
+ /** Its colour, for what draws no faces. */
29
+ function color(face: number): string;
30
+ /** What is in the `<svg viewBox="0 0 40 40">` of a face: its shape, then its cheeks, brows, eyes and mouth. */
31
+ function art(face: number): FaceNode;
32
+ }
@@ -0,0 +1,208 @@
1
+ /*
2
+ * The faces of those who are not Ta (agents, the people of rooms), framework-free so that Ta Web (ui.Face, React) and
3
+ * the page of web guests of the relay (src/guest, the DOM) draw the same: a small coloured shape with two eyes, cheeks
4
+ * and a mouth, one of FACE_COUNT, on a 40 × 40 grid. Their styles (`ta-face-eyes` blinks, `ta-face-look` looks
5
+ * about while at work) are those of the page that draws them.
6
+ */
7
+ /** How many faces there are. */
8
+ export const FACE_COUNT = 16;
9
+ const BLUE = '#4285F4';
10
+ const RED = '#EA4335';
11
+ const YELLOW = '#FBBC05';
12
+ const GREEN = '#34A853';
13
+ const MINT = '#5CC27F';
14
+ const ORANGE = '#EE7B3B';
15
+ const VIOLET = '#8C5CF0';
16
+ const CREAM = '#F1DFC0';
17
+ const TEAL = '#26B0A9';
18
+ const PINK = '#F27BA6';
19
+ const LILAC = '#B49CF5';
20
+ const SKY = '#45B5E8';
21
+ const INDIGO = '#5C6BC0';
22
+ const MIST = '#DCE3F0';
23
+ const INK = '#202124';
24
+ const WHITE = '#FFFFFF';
25
+ const CHEEK = 'rgba(255, 160, 185, 0.55)';
26
+ /** The edge of a light face. */
27
+ const EDGE = 'rgba(0, 0, 0, 0.14)';
28
+ const CHEEK_DEEP = 'rgba(120, 10, 30, 0.35)';
29
+ const CHEEK_WARM = 'rgba(234, 67, 53, 0.4)';
30
+ /** By face: the order is that of the shapes drawn in {@link shape}. */
31
+ const LOOKS = [
32
+ { color: MINT, eye: '#1D3B27', cheek: CHEEK, eyeY: 21, gap: 8 }, // round
33
+ { color: BLUE, eye: WHITE, cheek: CHEEK, eyeY: 23, gap: 8 }, // cat
34
+ { color: RED, eye: WHITE, cheek: CHEEK_DEEP, eyeY: 22, gap: 8 }, // pentagon
35
+ { color: CREAM, eye: '#4A3420', cheek: 'rgba(240, 120, 120, 0.5)', accent: '#DDBF8E', eyeY: 22, gap: 7.6 }, // bear
36
+ { color: GREEN, eye: WHITE, cheek: CHEEK, eyeY: 19, gap: 7.2 }, // capsule
37
+ { color: INDIGO, eye: WHITE, cheek: CHEEK, eyeY: 20, gap: 7.4 }, // diamond
38
+ { color: YELLOW, eye: INK, cheek: CHEEK_WARM, accent: '#F29900', eyeY: 24, gap: 8.4 }, // bun
39
+ { color: VIOLET, eye: '#22134A', cheek: CHEEK, eyeY: 20, gap: 8 }, // hexagon
40
+ { color: MIST, eye: '#2B3245', cheek: CHEEK, eyeY: 19, gap: 7.6 }, // ghost
41
+ { color: SKY, eye: WHITE, cheek: CHEEK, eyeY: 21, gap: 6.4 }, // star
42
+ { color: ORANGE, eye: '#3D1C08', cheek: CHEEK, accent: GREEN, eyeY: 22, gap: 8.6, brows: true }, // pumpkin
43
+ { color: WHITE, eye: WHITE, cheek: CHEEK, accent: INK, mouth: INK, eyeY: 22, gap: 10 }, // panda
44
+ { color: TEAL, eye: WHITE, cheek: CHEEK, accent: '#1B8A84', eyeY: 22.5, gap: 8.4 }, // screen
45
+ { color: PINK, eye: '#4A1428', cheek: 'rgba(160, 20, 70, 0.3)', eyeY: 24, gap: 7.4 }, // drop
46
+ { color: LILAC, eye: '#2A1A5E', cheek: CHEEK, eyeY: 25, gap: 8 }, // rabbit
47
+ { color: YELLOW, eye: INK, cheek: CHEEK_WARM, eyeY: 25, gap: 7.4 }, // triangle
48
+ ];
49
+ /** The corners of a polygon of `count` sides around (cx, cy), the first straight up; `inner` makes it a star. */
50
+ function corners(count, radius, cx, cy, inner) {
51
+ const points = [];
52
+ const steps = inner ? count * 2 : count;
53
+ for (let index = 0; index < steps; index++) {
54
+ const r = inner && index % 2 === 1 ? inner : radius;
55
+ const angle = -Math.PI / 2 + (index * 2 * Math.PI) / steps;
56
+ points.push(`${(cx + r * Math.cos(angle)).toFixed(2)},${(cy + r * Math.sin(angle)).toFixed(2)}`);
57
+ }
58
+ return points.join(' ');
59
+ }
60
+ const PENTAGON = corners(5, 13.5, 20, 21.5);
61
+ const HEXAGON = corners(6, 14, 20, 20);
62
+ const STAR = corners(5, 15.5, 20, 21.5, 8.6);
63
+ function node(tag, attrs, children) {
64
+ return children ? { tag, attrs, children } : { tag, attrs };
65
+ }
66
+ /** A polygon with round corners: filled and stroked in the same colour. */
67
+ function rounded(points, color, width = 5) {
68
+ return node('polygon', { points, fill: color, stroke: color, 'stroke-width': width, 'stroke-linejoin': 'round' });
69
+ }
70
+ function shape(face, look) {
71
+ const { color, accent = color } = look;
72
+ switch (face) {
73
+ case 1:
74
+ return node('g', {}, [
75
+ rounded('7.5,6.5 17,12 8.5,18', color, 4),
76
+ rounded('32.5,6.5 23,12 31.5,18', color, 4),
77
+ node('ellipse', { cx: 20, cy: 23, rx: 14.5, ry: 12.5, fill: color }),
78
+ ]);
79
+ case 2:
80
+ return rounded(PENTAGON, color);
81
+ case 3:
82
+ return node('g', {}, [
83
+ node('circle', { cx: 9.5, cy: 10.5, r: 5.5, fill: color }),
84
+ node('circle', { cx: 30.5, cy: 10.5, r: 5.5, fill: color }),
85
+ node('circle', { cx: 9.5, cy: 10.5, r: 2.6, fill: accent }),
86
+ node('circle', { cx: 30.5, cy: 10.5, r: 2.6, fill: accent }),
87
+ node('ellipse', { cx: 20, cy: 22.5, rx: 14.5, ry: 13, fill: color }),
88
+ ]);
89
+ case 4:
90
+ return node('rect', { x: 8.5, y: 4, width: 23, height: 32, rx: 11.5, fill: color });
91
+ case 5:
92
+ return rounded('20,5.5 34.5,20 20,34.5 5.5,20', color, 5.5);
93
+ case 6:
94
+ return node('g', {}, [
95
+ node('ellipse', { cx: 20, cy: 11, rx: 3.2, ry: 3.6, fill: accent }),
96
+ node('path', { d: 'M20 12.5c9.2 0 15.5 5.6 15.5 12.4 0 6.4-6.9 10.1-15.5 10.1S4.5 31.3 4.5 24.9C4.5 18.1 10.8 12.5 20 12.5Z', fill: color }),
97
+ ]);
98
+ case 7:
99
+ return rounded(HEXAGON, color);
100
+ case 8:
101
+ return node('path', {
102
+ d: 'M8 19a12 12 0 0 1 24 0v14l-4-3-4 3-4-3-4 3-4-3-4 3Z',
103
+ fill: color,
104
+ stroke: EDGE,
105
+ 'stroke-width': 0.8,
106
+ 'stroke-linejoin': 'round',
107
+ });
108
+ case 9:
109
+ return rounded(STAR, color, 4.5);
110
+ case 10:
111
+ return node('g', {}, [
112
+ node('rect', { x: 18.6, y: 4.5, width: 2.8, height: 7, rx: 1.4, fill: accent }),
113
+ node('ellipse', { cx: 12.5, cy: 23, rx: 8.5, ry: 11, fill: color }),
114
+ node('ellipse', { cx: 27.5, cy: 23, rx: 8.5, ry: 11, fill: color }),
115
+ node('ellipse', { cx: 20, cy: 22.5, rx: 9.5, ry: 12, fill: color }),
116
+ ]);
117
+ case 11:
118
+ return node('g', {}, [
119
+ node('circle', { cx: 9.5, cy: 10, r: 5, fill: accent }),
120
+ node('circle', { cx: 30.5, cy: 10, r: 5, fill: accent }),
121
+ node('ellipse', { cx: 20, cy: 22.5, rx: 14.5, ry: 13, fill: color, stroke: EDGE, 'stroke-width': 0.8 }),
122
+ node('ellipse', { cx: 14.6, cy: 22, rx: 3.6, ry: 4.4, transform: 'rotate(20 14.6 22)', fill: accent }),
123
+ node('ellipse', { cx: 25.4, cy: 22, rx: 3.6, ry: 4.4, transform: 'rotate(-20 25.4 22)', fill: accent }),
124
+ ]);
125
+ case 12:
126
+ return node('g', {}, [
127
+ node('rect', { x: 19.1, y: 6, width: 1.8, height: 7, fill: accent }),
128
+ node('circle', { cx: 20, cy: 5, r: 2.2, fill: accent }),
129
+ node('rect', { x: 5.5, y: 12, width: 29, height: 22.5, rx: 6.5, fill: color }),
130
+ ]);
131
+ case 13:
132
+ return node('path', { d: 'M20 4.5c2 0 13 11.6 13 20.2 0 6.4-5.8 10.8-13 10.8S7 31.1 7 24.7C7 16.1 18 4.5 20 4.5Z', fill: color });
133
+ case 14:
134
+ return node('g', {}, [
135
+ node('ellipse', { cx: 14, cy: 10.5, rx: 3.6, ry: 8, transform: 'rotate(-8 14 10.5)', fill: color }),
136
+ node('ellipse', { cx: 26, cy: 10.5, rx: 3.6, ry: 8, transform: 'rotate(8 26 10.5)', fill: color }),
137
+ node('ellipse', { cx: 20, cy: 25, rx: 14, ry: 11, fill: color }),
138
+ ]);
139
+ case 15:
140
+ return rounded('20,7 35,33 5,33', color, 6);
141
+ default:
142
+ return node('circle', { cx: 20, cy: 21, r: 14.5, fill: color });
143
+ }
144
+ }
145
+ export var FaceUtil;
146
+ (function (FaceUtil) {
147
+ /** The face of an id: the same for the same id, on every device. */
148
+ function of(seed) {
149
+ let hash = 0;
150
+ for (const char of seed) {
151
+ hash = (hash * 31 + char.charCodeAt(0)) | 0;
152
+ }
153
+ return Math.abs(hash) % FACE_COUNT;
154
+ }
155
+ FaceUtil.of = of;
156
+ /** The face given, if it is one, else that of `seed`. */
157
+ function pick(face, seed = '') {
158
+ return face !== undefined && face >= 0 && face < FACE_COUNT ? Math.floor(face) : of(seed);
159
+ }
160
+ FaceUtil.pick = pick;
161
+ /** Its colour, for what draws no faces. */
162
+ function color(face) {
163
+ var _a;
164
+ return ((_a = LOOKS[face]) !== null && _a !== void 0 ? _a : LOOKS[0]).color;
165
+ }
166
+ FaceUtil.color = color;
167
+ /** What is in the `<svg viewBox="0 0 40 40">` of a face: its shape, then its cheeks, brows, eyes and mouth. */
168
+ function art(face) {
169
+ var _a, _b;
170
+ const look = (_a = LOOKS[face]) !== null && _a !== void 0 ? _a : LOOKS[0];
171
+ const half = look.gap / 2;
172
+ const eyeW = 4.1;
173
+ const eyeH = 4.9;
174
+ const top = look.eyeY - eyeH / 2;
175
+ const cheekY = look.eyeY + 3.6;
176
+ const cheekX = half + 2.2;
177
+ const mouthY = look.eyeY + 3.4;
178
+ const features = [
179
+ node('g', { fill: look.cheek }, [
180
+ node('ellipse', { cx: 20 - cheekX, cy: cheekY, rx: 2.2, ry: 1.25 }),
181
+ node('ellipse', { cx: 20 + cheekX, cy: cheekY, rx: 2.2, ry: 1.25 }),
182
+ ]),
183
+ ];
184
+ if (look.brows) {
185
+ features.push(node('path', {
186
+ d: `M${20 - half - 3.4} ${top - 2.6}l3.6 1.6M${20 + half + 3.4} ${top - 2.6}l-3.6 1.6`,
187
+ stroke: look.eye,
188
+ 'stroke-width': 1.4,
189
+ 'stroke-linecap': 'round',
190
+ fill: 'none',
191
+ }));
192
+ }
193
+ features.push(node('g', { class: 'ta-face-eyes', fill: look.eye }, [
194
+ node('rect', { x: 20 - half - eyeW / 2, y: top, width: eyeW, height: eyeH, rx: eyeW / 2 }),
195
+ node('rect', { x: 20 + half - eyeW / 2, y: top, width: eyeW, height: eyeH, rx: eyeW / 2 }),
196
+ ]), node('path', {
197
+ d: `M18.1 ${mouthY}q.95 1.25 1.9 0q.95 1.25 1.9 0`,
198
+ fill: 'none',
199
+ stroke: (_b = look.mouth) !== null && _b !== void 0 ? _b : look.eye,
200
+ 'stroke-width': 1.1,
201
+ 'stroke-linecap': 'round',
202
+ 'stroke-linejoin': 'round',
203
+ }));
204
+ return node('g', { class: 'ta-face-body' }, [shape(face, look), node('g', { class: 'ta-face-look' }, features)]);
205
+ }
206
+ FaceUtil.art = art;
207
+ })(FaceUtil || (FaceUtil = {}));
208
+ //# sourceMappingURL=relay-faces.js.map