@celljs/ta-relay 4.17.0 → 4.19.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 (96) hide show
  1. package/esm/common/index.d.ts +4 -0
  2. package/esm/common/index.js +4 -0
  3. package/esm/common/relay-account-client.d.ts +138 -0
  4. package/esm/common/relay-account-client.js +338 -0
  5. package/esm/common/relay-account.d.ts +137 -0
  6. package/esm/common/relay-account.js +122 -0
  7. package/esm/common/relay-accounts.d.ts +107 -0
  8. package/esm/common/relay-accounts.js +393 -0
  9. package/esm/common/relay-faces.d.ts +1 -1
  10. package/esm/common/relay-faces.js +56 -1
  11. package/esm/common/relay-files.d.ts +14 -3
  12. package/esm/common/relay-files.js +41 -16
  13. package/esm/common/relay-friend-sends.d.ts +64 -0
  14. package/esm/common/relay-friend-sends.js +126 -0
  15. package/esm/common/relay-group-invites.d.ts +76 -0
  16. package/esm/common/relay-group-invites.js +163 -0
  17. package/esm/common/relay-hubs-protocol.d.ts +3 -1
  18. package/esm/common/relay-hubs.d.ts +19 -0
  19. package/esm/common/relay-hubs.js +58 -0
  20. package/esm/common/relay-open-in-ta.d.ts +11 -0
  21. package/esm/common/relay-open-in-ta.js +34 -0
  22. package/esm/common/relay-protocol.d.ts +2 -2
  23. package/esm/common/relay-protocol.js +5 -2
  24. package/esm/guest/guest-i18n.d.ts +1 -0
  25. package/esm/guest/guest-i18n.js +45 -41
  26. package/esm/guest/guest-style.d.ts +1 -1
  27. package/esm/guest/guest-style.js +2 -0
  28. package/esm/guest/guest.js +7 -2
  29. package/esm/join/join-i18n.d.ts +1 -0
  30. package/esm/join/join-i18n.js +4 -0
  31. package/esm/join/join.js +4 -1
  32. package/esm/node/index.d.ts +1 -0
  33. package/esm/node/index.js +1 -0
  34. package/esm/node/relay-files-host.d.ts +2 -0
  35. package/esm/node/relay-files-host.js +24 -5
  36. package/esm/node/relay-server-accounts.d.ts +16 -0
  37. package/esm/node/relay-server-accounts.js +54 -0
  38. package/esm/node/relay-server.d.ts +5 -0
  39. package/esm/node/relay-server.js +7 -0
  40. package/esm/node/relay-store.d.ts +3 -1
  41. package/esm/node/relay-store.js +1 -0
  42. package/esm/viewer/viewer-i18n.d.ts +1 -0
  43. package/esm/viewer/viewer-i18n.js +4 -0
  44. package/esm/viewer/viewer-style.d.ts +1 -1
  45. package/esm/viewer/viewer-style.js +2 -0
  46. package/esm/viewer/viewer.js +3 -1
  47. package/lib/common/index.d.ts +4 -0
  48. package/lib/common/index.js +4 -0
  49. package/lib/common/relay-account-client.d.ts +139 -0
  50. package/lib/common/relay-account-client.js +343 -0
  51. package/lib/common/relay-account.d.ts +138 -0
  52. package/lib/common/relay-account.js +125 -0
  53. package/lib/common/relay-accounts.d.ts +108 -0
  54. package/lib/common/relay-accounts.js +401 -0
  55. package/lib/common/relay-faces.d.ts +1 -1
  56. package/lib/common/relay-faces.js +56 -1
  57. package/lib/common/relay-files.d.ts +14 -3
  58. package/lib/common/relay-files.js +42 -17
  59. package/lib/common/relay-friend-sends.d.ts +65 -0
  60. package/lib/common/relay-friend-sends.js +130 -0
  61. package/lib/common/relay-group-invites.d.ts +77 -0
  62. package/lib/common/relay-group-invites.js +167 -0
  63. package/lib/common/relay-hubs-protocol.d.ts +3 -1
  64. package/lib/common/relay-hubs.d.ts +19 -0
  65. package/lib/common/relay-hubs.js +58 -0
  66. package/lib/common/relay-open-in-ta.d.ts +12 -0
  67. package/lib/common/relay-open-in-ta.js +37 -0
  68. package/lib/common/relay-protocol.d.ts +2 -2
  69. package/lib/common/relay-protocol.js +5 -2
  70. package/lib/guest/guest-i18n.d.ts +1 -0
  71. package/lib/guest/guest-i18n.js +45 -41
  72. package/lib/guest/guest-style.d.ts +1 -1
  73. package/lib/guest/guest-style.js +2 -0
  74. package/lib/guest/guest.js +7 -2
  75. package/lib/join/join-i18n.d.ts +1 -0
  76. package/lib/join/join-i18n.js +4 -0
  77. package/lib/join/join.js +4 -1
  78. package/lib/node/index.d.ts +1 -0
  79. package/lib/node/index.js +1 -0
  80. package/lib/node/relay-files-host.d.ts +2 -0
  81. package/lib/node/relay-files-host.js +23 -4
  82. package/lib/node/relay-server-accounts.d.ts +17 -0
  83. package/lib/node/relay-server-accounts.js +58 -0
  84. package/lib/node/relay-server.d.ts +5 -0
  85. package/lib/node/relay-server.js +7 -0
  86. package/lib/node/relay-store.d.ts +3 -1
  87. package/lib/node/relay-store.js +1 -0
  88. package/lib/viewer/viewer-i18n.d.ts +1 -0
  89. package/lib/viewer/viewer-i18n.js +4 -0
  90. package/lib/viewer/viewer-style.d.ts +1 -1
  91. package/lib/viewer/viewer-style.js +2 -0
  92. package/lib/viewer/viewer.js +3 -1
  93. package/package.json +3 -3
  94. package/viewer/join.html +12 -3
  95. package/viewer/page.html +18 -9
  96. package/viewer/room.html +19 -8
@@ -1,5 +1,5 @@
1
1
  import { RelayBytes } from '../common/relay-bytes.js';
2
- import { RELAY_FILE_CHUNK_BYTES, RELAY_FILE_MAX_BYTES, RELAY_FILES_MAX_PARALLEL, RELAY_FILES_PREFIX, RELAY_FILES_TIMEOUT_MS, } from '../common/relay-files.js';
2
+ import { RELAY_FILE_CHUNK_BYTES, RELAY_FILE_MAX_BYTES, RELAY_FILES_MAX_PARALLEL, RELAY_FILES_MAX_WAITING, RELAY_FILES_PREFIX, RELAY_FILES_TIMEOUT_MS, } from '../common/relay-files.js';
3
3
  /**
4
4
  * The files of the workspace on a channel of a device (RelayFiles): asks them of the ta serve of this
5
5
  * machine and sends them back sealed. It asks for nothing but a path of {@link RELAY_FILES_PREFIX}, with
@@ -11,6 +11,8 @@ export class RelayFilesHost {
11
11
  this.options = options;
12
12
  this.reading = 0;
13
13
  this.running = new Set();
14
+ /** Asked for past {@link RELAY_FILES_MAX_PARALLEL}: read in turn, not turned away (a page of an older Ta asks for all at once). */
15
+ this.waiting = [];
14
16
  // Only ever loopback, whatever the address of the socket says: what this reaches is one server.
15
17
  this.base = `http://127.0.0.1:${new URL(options.localUrl).port}`;
16
18
  }
@@ -30,6 +32,9 @@ export class RelayFilesHost {
30
32
  }
31
33
  /** The device went: what it asked for is not read to the end. */
32
34
  close() {
35
+ for (const go of this.waiting.splice(0)) {
36
+ go(false);
37
+ }
33
38
  for (const controller of this.running) {
34
39
  controller.abort();
35
40
  }
@@ -58,12 +63,20 @@ export class RelayFilesHost {
58
63
  return;
59
64
  }
60
65
  if (this.reading >= RELAY_FILES_MAX_PARALLEL) {
61
- this.options.send({ t: 'error', id, message: 'Too many files are loading at once.' });
62
- return;
66
+ if (this.waiting.length >= RELAY_FILES_MAX_WAITING) {
67
+ this.options.send({ t: 'error', id, message: 'Too many files are loading at once.' });
68
+ return;
69
+ }
70
+ // A read that ends hands its place to this one: no more than the most are read at once.
71
+ if (!(await new Promise(go => this.waiting.push(go)))) {
72
+ return;
73
+ }
74
+ }
75
+ else {
76
+ this.reading++;
63
77
  }
64
78
  const controller = new AbortController();
65
79
  this.running.add(controller);
66
- this.reading++;
67
80
  const timer = setTimeout(() => controller.abort(), RELAY_FILES_TIMEOUT_MS);
68
81
  try {
69
82
  const response = await fetch(target, { signal: controller.signal, redirect: 'error', headers: { accept: '*/*' } });
@@ -123,7 +136,13 @@ export class RelayFilesHost {
123
136
  finally {
124
137
  clearTimeout(timer);
125
138
  this.running.delete(controller);
126
- this.reading--;
139
+ const next = this.waiting.shift();
140
+ if (next) {
141
+ next(true);
142
+ }
143
+ else {
144
+ this.reading--;
145
+ }
127
146
  }
128
147
  }
129
148
  }
@@ -0,0 +1,16 @@
1
+ import type { IncomingMessage, ServerResponse } from 'node:http';
2
+ import { type RelayAccountProvider, RelayAccounts, type RelayAccountsOptions } from '../common/relay-accounts.js';
3
+ /**
4
+ * The account service of `ta relay` (docs/design/ta-account.md), as the Worker answers it: the book of each account in
5
+ * a directory of its own under `data`, or in memory without one.
6
+ */
7
+ export declare class RelayServerAccounts {
8
+ protected readonly accounts: RelayAccounts;
9
+ /** `authenticate`: a gateway's, whose sign-in gives the tokens (RelayAccountsOptions.authenticate). */
10
+ constructor(data: string | undefined, options?: Pick<RelayAccountsOptions, 'authenticate'> & {
11
+ providers?: RelayAccountProvider[];
12
+ });
13
+ /** Answers a request of RELAY_ACCOUNT_PATH; never throws, an unhandled rejection would end the relay. */
14
+ serve(request: IncomingMessage, response: ServerResponse): void;
15
+ protected answer(request: IncomingMessage, response: ServerResponse): Promise<void>;
16
+ }
@@ -0,0 +1,54 @@
1
+ import { join } from 'node:path';
2
+ import { RelayAccountBooks, RelayAccounts, RelayGitHubAccounts } from '../common/relay-accounts.js';
3
+ import { RelayBytes } from '../common/relay-bytes.js';
4
+ import { FileRelayStorage } from './relay-file-storage.js';
5
+ import { MemoryHubStorage } from './relay-memory-storage.js';
6
+ /** What a call of the account service may hold. */
7
+ const MAX_BYTES = 64 * 1024;
8
+ /**
9
+ * The account service of `ta relay` (docs/design/ta-account.md), as the Worker answers it: the book of each account in
10
+ * a directory of its own under `data`, or in memory without one.
11
+ */
12
+ export class RelayServerAccounts {
13
+ /** `authenticate`: a gateway's, whose sign-in gives the tokens (RelayAccountsOptions.authenticate). */
14
+ constructor(data, options = {}) {
15
+ var _a;
16
+ const books = new RelayAccountBooks(account => data ? new FileRelayStorage(join(data, 'accounts', RelayBytes.toBase64(new TextEncoder().encode(account)))) : new MemoryHubStorage());
17
+ const providers = (_a = options.providers) !== null && _a !== void 0 ? _a : (options.authenticate ? [] : [new RelayGitHubAccounts()]);
18
+ this.accounts = new RelayAccounts({ book: account => books.book(account), providers, authenticate: options.authenticate });
19
+ }
20
+ /** Answers a request of RELAY_ACCOUNT_PATH; never throws, an unhandled rejection would end the relay. */
21
+ serve(request, response) {
22
+ this.answer(request, response).catch(() => {
23
+ if (!response.headersSent) {
24
+ response.writeHead(400);
25
+ }
26
+ response.end();
27
+ });
28
+ }
29
+ async answer(request, response) {
30
+ var _a;
31
+ const chunks = [];
32
+ let size = 0;
33
+ for await (const chunk of request) {
34
+ size += chunk.length;
35
+ if (size > MAX_BYTES) {
36
+ response.writeHead(413, { connection: 'close' }).end('Too large.\n');
37
+ return;
38
+ }
39
+ chunks.push(chunk);
40
+ }
41
+ const headers = new Headers();
42
+ for (const [name, value] of Object.entries(request.headers)) {
43
+ if (typeof value === 'string') {
44
+ headers.set(name, value);
45
+ }
46
+ }
47
+ const method = (_a = request.method) !== null && _a !== void 0 ? _a : 'GET';
48
+ const body = chunks.length && method !== 'GET' && method !== 'HEAD' ? Buffer.concat(chunks) : undefined;
49
+ const answer = await this.accounts.handle(new Request(`http://relay${request.url}`, { method, headers, body }));
50
+ response.writeHead(answer.status, Object.fromEntries(answer.headers));
51
+ response.end(Buffer.from(await answer.arrayBuffer()));
52
+ }
53
+ }
54
+ //# sourceMappingURL=relay-server-accounts.js.map
@@ -2,12 +2,14 @@ import { type IncomingMessage, type Server, type ServerResponse } from 'node:htt
2
2
  import type { Duplex } from 'node:stream';
3
3
  import { WebSocketConnection } from '@celljs/rpc/lib/node/websocket/websocket-connection';
4
4
  import { type TaDeploymentEnv } from '@celljs/ta-protocol/lib/common/deployment-protocol';
5
+ import type { RelayAccountProvider } from '../common/relay-accounts.js';
5
6
  import { RelayBlobs } from '../common/relay-blobs.js';
6
7
  import { RelayHub, type RelayHubWho } from '../common/relay-hub.js';
7
8
  import { RelayRoom } from '../common/relay-room.js';
8
9
  import { RelaySpot, type RelaySpotSocket, type RelaySpotWho } from '../common/relay-spot.js';
9
10
  import { FileRelayStorage } from './relay-file-storage.js';
10
11
  import { MemoryBlobStorage, MemoryHubStorage } from './relay-memory-storage.js';
12
+ import { RelayServerAccounts } from './relay-server-accounts.js';
11
13
  export interface RelayServerOptions {
12
14
  host?: string;
13
15
  port?: number;
@@ -29,6 +31,8 @@ export interface RelayServerOptions {
29
31
  TA_PUBLIC_URL?: string;
30
32
  };
31
33
  version?: string;
34
+ /** The ways to sign in to accounts (docs/design/ta-account.md): GitHub with Ta's own app, unless given. */
35
+ accounts?: RelayAccountProvider[];
32
36
  }
33
37
  interface Room {
34
38
  secretHash: string;
@@ -71,6 +75,7 @@ export declare class RelayServer {
71
75
  /** The address each connection to a spot came from. */
72
76
  protected readonly spotAddresses: WeakMap<WebSocketConnection, string>;
73
77
  protected server?: Server;
78
+ protected readonly accounts: RelayServerAccounts;
74
79
  constructor(options?: RelayServerOptions);
75
80
  /** What it is part of, and whether it runs and can keep what it holds: for anyone, and the probes of a platform. */
76
81
  protected describe(path: string, request: IncomingMessage, response: ServerResponse): void;
@@ -4,6 +4,7 @@ import { createServer } from 'node:http';
4
4
  import { join } from 'node:path';
5
5
  import { WebSocketConnection } from '@celljs/rpc/lib/node/websocket/websocket-connection';
6
6
  import { TA_WELL_KNOWN_PATH, TaDeploymentUtil } from '@celljs/ta-protocol/lib/common/deployment-protocol';
7
+ import { RELAY_ACCOUNT_PATH } from '../common/relay-account.js';
7
8
  import { RelayBlobs } from '../common/relay-blobs.js';
8
9
  import { RelayHub } from '../common/relay-hub.js';
9
10
  import { RELAY_INFO_PATH, RelayInfoUtil } from '../common/relay-info.js';
@@ -14,6 +15,7 @@ import { RELAY_JOIN_PATH, RELAY_WEB_PATH } from '../common/relay-team.js';
14
15
  import { RelayWebUtil } from '../common/relay-web.js';
15
16
  import { FileRelayStorage } from './relay-file-storage.js';
16
17
  import { MemoryBlobStorage, MemoryHubStorage } from './relay-memory-storage.js';
18
+ import { RelayServerAccounts } from './relay-server-accounts.js';
17
19
  import { RelayViewer } from './relay-viewer.js';
18
20
  const WEBSOCKET = { maxPayload: 32 * 1024 * 1024, heartbeat: 30000 };
19
21
  const peer = (connection) => ({ send: text => connection.send(text), close: (code, reason) => connection.close(code, reason) });
@@ -35,6 +37,7 @@ export class RelayServer {
35
37
  this.spotTries = new Map();
36
38
  /** The address each connection to a spot came from. */
37
39
  this.spotAddresses = new WeakMap();
40
+ this.accounts = new RelayServerAccounts(options.data, { providers: options.accounts });
38
41
  if (options.data) {
39
42
  mkdirSync(options.data, { recursive: true, mode: 0o700 });
40
43
  try {
@@ -95,6 +98,10 @@ export class RelayServer {
95
98
  response.end(JSON.stringify(info));
96
99
  return;
97
100
  }
101
+ if (path.startsWith(RELAY_ACCOUNT_PATH)) {
102
+ this.accounts.serve(request, response);
103
+ return;
104
+ }
98
105
  if (path.startsWith(RELAY_BLOB_PATH)) {
99
106
  this.blob(path.slice(RELAY_BLOB_PATH.length), request, response).catch(() => {
100
107
  // A request aborted or that failed: an unhandled rejection would end the relay.
@@ -12,6 +12,8 @@ export interface RelayDevice {
12
12
  createdAt: number;
13
13
  /** One let in by the user, not the user's own device: the principal its calls are made as (docs/design/ta-team.md). */
14
14
  member?: string;
15
+ /** A device of the user's account (docs/design/ta-account.md), by its id there: paired by the account, unpaired with it. */
16
+ account?: string;
15
17
  /** No longer reaches this ta serve from then on: a link of invitation. */
16
18
  expiresAt?: number;
17
19
  }
@@ -152,7 +154,7 @@ export declare class RelayStore {
152
154
  * each relay that has one (docs/design/ta-relays.md). `member`: a device of one the user let in, not their own;
153
155
  * `expiresAt`: it reaches this ta serve until then. Devices expired are dropped as a new one is added.
154
156
  */
155
- pair(relay: string, deviceName: string, options?: Pick<RelayDevice, 'member' | 'expiresAt'>): RelayPairing;
157
+ pair(relay: string, deviceName: string, options?: Pick<RelayDevice, 'member' | 'expiresAt' | 'account'>): RelayPairing;
156
158
  /** Whether ta serve keeps the computer awake for the devices (RelayConfig.keepAwake). */
157
159
  setKeepAwake(on: boolean): void;
158
160
  /** False when there was no such device. */
@@ -218,6 +218,7 @@ export class RelayStore {
218
218
  key: randomBytes(32).toString('base64url'),
219
219
  createdAt: now,
220
220
  ...(options.member ? { member: options.member } : {}),
221
+ ...(options.account ? { account: options.account } : {}),
221
222
  ...(options.expiresAt !== undefined ? { expiresAt: options.expiresAt } : {}),
222
223
  };
223
224
  config.devices = [...config.devices.filter(one => one.expiresAt === undefined || one.expiresAt > now), device];
@@ -1,5 +1,6 @@
1
1
  import { type PageLanguage } from '../common/page-language.js';
2
2
  declare const zh: {
3
+ openInTa: string;
3
4
  title: string;
4
5
  loading: string;
5
6
  conversation: string;
@@ -1,5 +1,6 @@
1
1
  import { pageLanguage } from '../common/page-language.js';
2
2
  const zh = {
3
+ openInTa: '在 Ta 中打开',
3
4
  title: 'Ta 分享',
4
5
  loading: '正在打开…',
5
6
  conversation: '对话',
@@ -49,6 +50,7 @@ const zh = {
49
50
  use: '使用 {name}',
50
51
  };
51
52
  const zhTw = {
53
+ openInTa: '在 Ta 中開啟',
52
54
  title: 'Ta 分享',
53
55
  loading: '正在開啟…',
54
56
  conversation: '對話',
@@ -98,6 +100,7 @@ const zhTw = {
98
100
  use: '使用 {name}',
99
101
  };
100
102
  const en = {
103
+ openInTa: 'Open in Ta',
101
104
  title: 'Shared from Ta',
102
105
  loading: 'Opening…',
103
106
  conversation: 'Conversation',
@@ -147,6 +150,7 @@ const en = {
147
150
  use: 'Use {name}',
148
151
  };
149
152
  const ja = {
153
+ openInTa: 'Ta で開く',
150
154
  title: 'Ta から共有',
151
155
  loading: '開いています…',
152
156
  conversation: '会話',
@@ -1 +1 @@
1
- export declare const VIEWER_STYLE = "\n:root{color-scheme:light dark;--bg:#fff;--fg:#1f1f1f;--muted:#737373;--faint:#a3a3a3;--line:#ececec;--soft:#f5f5f5;--bubble:#f2f2f2;--code:#f6f6f6;--accent:#16a34a;--warn:#d97706;--radius:14px}\n@media (prefers-color-scheme:dark){:root{--bg:#191919;--fg:#ececec;--muted:#a3a3a3;--faint:#6b6b6b;--line:#2c2c2c;--soft:#222;--bubble:#2a2a2a;--code:#232323;--accent:#4ade80;--warn:#fbbf24}}\n*{box-sizing:border-box}\nhtml,body{margin:0;background:var(--bg);color:var(--fg);font:15px/1.65 -apple-system,BlinkMacSystemFont,\"Segoe UI\",\"PingFang SC\",\"Hiragino Sans GB\",\"Microsoft YaHei\",sans-serif;-webkit-font-smoothing:antialiased}\n.top{position:sticky;top:0;z-index:2;display:flex;align-items:center;gap:10px;padding:10px 16px;background:color-mix(in srgb,var(--bg) 88%,transparent);backdrop-filter:saturate(1.6) blur(12px);-webkit-backdrop-filter:saturate(1.6) blur(12px);border-bottom:1px solid var(--line)}\n.logo{width:26px;height:26px;border-radius:8px;background:var(--fg);color:var(--bg);display:grid;place-items:center;font-weight:700;font-size:13px;flex:none}\n.top .name{font-weight:600;font-size:14px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;flex:1;min-width:0}\n.top button{flex:none}\nmain{max-width:760px;margin:0 auto;padding:28px 18px 40px}\nmain.wide{max-width:none;padding:0}\nh1.title{font-size:22px;line-height:1.35;margin:0 0 6px;letter-spacing:-.01em;word-break:break-word}\n.meta{color:var(--muted);font-size:13px;margin:0 0 22px;display:flex;flex-wrap:wrap;gap:4px 12px}\n.notes{color:var(--muted);font-size:12.5px;margin:-10px 0 22px;display:flex;flex-direction:column;gap:2px}\n.msg{margin:0 0 18px}\n.msg.user{display:flex;justify-content:flex-end}\n.msg.user .bubble{background:var(--bubble);border-radius:var(--radius) var(--radius) 4px var(--radius);padding:9px 14px;max-width:85%;white-space:pre-wrap;word-break:break-word}\n.msg.ta .text>:first-child{margin-top:0}.msg.ta .text>:last-child{margin-bottom:0}\n.text{word-break:break-word}\n.text p{margin:0 0 .75em}\n.text h2,.text h3,.text h4,.text h5,.text h6{margin:1.2em 0 .5em;line-height:1.35}\n.text h2{font-size:1.25em}.text h3{font-size:1.1em}.text h4,.text h5,.text h6{font-size:1em}\n.text ul,.text ol{margin:0 0 .75em;padding-left:1.4em}.text li{margin:.2em 0}\n.text blockquote{margin:0 0 .75em;padding:2px 0 2px 12px;border-left:3px solid var(--line);color:var(--muted)}\n.text a{color:inherit;text-decoration:underline;text-decoration-color:var(--faint);text-underline-offset:2px}\n.text code{font:12.5px/1.5 ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;background:var(--code);padding:1px 5px;border-radius:5px}\n.text pre{background:var(--code);border-radius:10px;padding:12px 14px;overflow:auto;margin:0 0 .85em}\n.text pre code{background:none;padding:0;font-size:12.5px;white-space:pre}\n.text hr{border:0;border-top:1px solid var(--line);margin:1.2em 0}\n.text .table{overflow:auto;margin:0 0 .85em}\n.text table{border-collapse:collapse;font-size:14px}\n.text th,.text td{border:1px solid var(--line);padding:5px 10px;text-align:left;vertical-align:top}\n.text th{background:var(--soft);font-weight:600}\n.tools{margin:4px 0 10px;display:flex;flex-direction:column;gap:1px}\n.tool{display:flex;align-items:baseline;gap:8px;color:var(--muted);font-size:13.5px;min-width:0;padding:2px 0}\n.tool .dot{width:6px;height:6px;border-radius:50%;background:var(--accent);flex:none;transform:translateY(-2px)}\n.tool.failed .dot{background:var(--faint)}\n.tool .verb{flex:none}\n.tool .target{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--fg);opacity:.8}\n.tool .target.code{font:12.5px ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}\ndetails.out{margin:0 0 6px 14px}\ndetails.out summary{cursor:pointer;color:var(--faint);font-size:12.5px;list-style:none}\ndetails.out summary::-webkit-details-marker{display:none}\ndetails.out pre{margin:6px 0 0;background:var(--code);border-radius:8px;padding:10px 12px;max-height:280px;overflow:auto;font:12px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace;white-space:pre-wrap;word-break:break-word}\n.err{color:var(--warn);font-size:13.5px}\n.card{max-width:380px;margin:12vh auto 0;padding:28px 24px;border:1px solid var(--line);border-radius:18px;text-align:center}\n.card h2{font-size:17px;margin:12px 0 6px}\n.card p{color:var(--muted);font-size:13.5px;margin:0 0 16px}\n.card .icon{width:44px;height:44px;border-radius:50%;background:var(--soft);color:var(--muted);display:grid;place-items:center;margin:0 auto}\n.card form{display:flex;gap:8px}\n.card input{flex:1;min-width:0;font:inherit;padding:9px 12px;border-radius:10px;border:1px solid var(--line);background:var(--bg);color:var(--fg);outline:none}\n.card input:focus{border-color:var(--muted)}\n.card .error{color:var(--warn);font-size:13px;margin:10px 0 0;min-height:1em}\nbutton{font:inherit;font-size:13.5px;padding:8px 14px;border-radius:10px;border:1px solid var(--line);background:var(--bg);color:var(--fg);cursor:pointer}\nbutton.primary{background:var(--fg);color:var(--bg);border-color:var(--fg)}\nbutton:disabled{opacity:.5;cursor:default}\n.spin{width:22px;height:22px;border:2px solid var(--line);border-top-color:var(--muted);border-radius:50%;margin:0 auto;animation:spin .8s linear infinite}\n@keyframes spin{to{transform:rotate(360deg)}}\n@media (prefers-reduced-motion:reduce){.spin{animation-duration:3s}}\n.agent-head{display:flex;flex-direction:column;align-items:center;text-align:center;gap:4px;margin:8px 0 22px}\n.agent-face{width:64px;height:64px;border-radius:50%;background:var(--soft);color:#fff;display:grid;place-items:center;font-size:24px;font-weight:700;margin-bottom:8px;box-shadow:0 0 0 1px var(--line)}\n.agent-head h1.title{margin:0}.agent-head .meta{margin:0;justify-content:center}\n.agent-role{border:1px solid var(--line);border-radius:var(--radius);padding:14px 16px;background:var(--soft)}\n.agent-role>:first-child{margin-top:0}.agent-role>:last-child{margin-bottom:0}\n.agent .notes{margin:10px 0 0}\n.agent-hint{color:var(--muted);font-size:13.5px;text-align:center;margin:18px 0 0}\n.foot{max-width:760px;margin:0 auto;padding:18px 18px 40px;color:var(--faint);font-size:12.5px;border-top:1px solid var(--line);display:flex;flex-direction:column;gap:4px}\n.page{display:block;width:100%;height:calc(100vh - 48px);height:calc(100dvh - 48px);border:0;background:#fff}\n.file img{max-width:100%;border-radius:10px;display:block;margin:0 auto}\n.file pre{white-space:pre-wrap;word-break:break-word;background:var(--code);border-radius:10px;padding:14px;font:12.5px/1.55 ui-monospace,SFMono-Regular,Menlo,monospace}\n";
1
+ export declare const VIEWER_STYLE = "\n:root{color-scheme:light dark;--bg:#fff;--fg:#1f1f1f;--muted:#737373;--faint:#a3a3a3;--line:#ececec;--soft:#f5f5f5;--bubble:#f2f2f2;--code:#f6f6f6;--accent:#16a34a;--warn:#d97706;--radius:14px}\n@media (prefers-color-scheme:dark){:root{--bg:#191919;--fg:#ececec;--muted:#a3a3a3;--faint:#6b6b6b;--line:#2c2c2c;--soft:#222;--bubble:#2a2a2a;--code:#232323;--accent:#4ade80;--warn:#fbbf24}}\n*{box-sizing:border-box}\nhtml,body{margin:0;background:var(--bg);color:var(--fg);font:15px/1.65 -apple-system,BlinkMacSystemFont,\"Segoe UI\",\"PingFang SC\",\"Hiragino Sans GB\",\"Microsoft YaHei\",sans-serif;-webkit-font-smoothing:antialiased}\n.top{position:sticky;top:0;z-index:2;display:flex;align-items:center;gap:10px;padding:10px 16px;background:color-mix(in srgb,var(--bg) 88%,transparent);backdrop-filter:saturate(1.6) blur(12px);-webkit-backdrop-filter:saturate(1.6) blur(12px);border-bottom:1px solid var(--line)}\n.open-in-ta{flex:none;display:inline-flex;align-items:center;height:32px;padding:0 14px;border-radius:16px;background:var(--fg);color:var(--bg);font-size:13.5px;font-weight:600;text-decoration:none;white-space:nowrap;-webkit-tap-highlight-color:transparent}\n.open-in-ta:active{opacity:.8}\n.logo{width:26px;height:26px;border-radius:8px;background:var(--fg);color:var(--bg);display:grid;place-items:center;font-weight:700;font-size:13px;flex:none}\n.top .name{font-weight:600;font-size:14px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;flex:1;min-width:0}\n.top button{flex:none}\nmain{max-width:760px;margin:0 auto;padding:28px 18px 40px}\nmain.wide{max-width:none;padding:0}\nh1.title{font-size:22px;line-height:1.35;margin:0 0 6px;letter-spacing:-.01em;word-break:break-word}\n.meta{color:var(--muted);font-size:13px;margin:0 0 22px;display:flex;flex-wrap:wrap;gap:4px 12px}\n.notes{color:var(--muted);font-size:12.5px;margin:-10px 0 22px;display:flex;flex-direction:column;gap:2px}\n.msg{margin:0 0 18px}\n.msg.user{display:flex;justify-content:flex-end}\n.msg.user .bubble{background:var(--bubble);border-radius:var(--radius) var(--radius) 4px var(--radius);padding:9px 14px;max-width:85%;white-space:pre-wrap;word-break:break-word}\n.msg.ta .text>:first-child{margin-top:0}.msg.ta .text>:last-child{margin-bottom:0}\n.text{word-break:break-word}\n.text p{margin:0 0 .75em}\n.text h2,.text h3,.text h4,.text h5,.text h6{margin:1.2em 0 .5em;line-height:1.35}\n.text h2{font-size:1.25em}.text h3{font-size:1.1em}.text h4,.text h5,.text h6{font-size:1em}\n.text ul,.text ol{margin:0 0 .75em;padding-left:1.4em}.text li{margin:.2em 0}\n.text blockquote{margin:0 0 .75em;padding:2px 0 2px 12px;border-left:3px solid var(--line);color:var(--muted)}\n.text a{color:inherit;text-decoration:underline;text-decoration-color:var(--faint);text-underline-offset:2px}\n.text code{font:12.5px/1.5 ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;background:var(--code);padding:1px 5px;border-radius:5px}\n.text pre{background:var(--code);border-radius:10px;padding:12px 14px;overflow:auto;margin:0 0 .85em}\n.text pre code{background:none;padding:0;font-size:12.5px;white-space:pre}\n.text hr{border:0;border-top:1px solid var(--line);margin:1.2em 0}\n.text .table{overflow:auto;margin:0 0 .85em}\n.text table{border-collapse:collapse;font-size:14px}\n.text th,.text td{border:1px solid var(--line);padding:5px 10px;text-align:left;vertical-align:top}\n.text th{background:var(--soft);font-weight:600}\n.tools{margin:4px 0 10px;display:flex;flex-direction:column;gap:1px}\n.tool{display:flex;align-items:baseline;gap:8px;color:var(--muted);font-size:13.5px;min-width:0;padding:2px 0}\n.tool .dot{width:6px;height:6px;border-radius:50%;background:var(--accent);flex:none;transform:translateY(-2px)}\n.tool.failed .dot{background:var(--faint)}\n.tool .verb{flex:none}\n.tool .target{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--fg);opacity:.8}\n.tool .target.code{font:12.5px ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}\ndetails.out{margin:0 0 6px 14px}\ndetails.out summary{cursor:pointer;color:var(--faint);font-size:12.5px;list-style:none}\ndetails.out summary::-webkit-details-marker{display:none}\ndetails.out pre{margin:6px 0 0;background:var(--code);border-radius:8px;padding:10px 12px;max-height:280px;overflow:auto;font:12px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace;white-space:pre-wrap;word-break:break-word}\n.err{color:var(--warn);font-size:13.5px}\n.card{max-width:380px;margin:12vh auto 0;padding:28px 24px;border:1px solid var(--line);border-radius:18px;text-align:center}\n.card h2{font-size:17px;margin:12px 0 6px}\n.card p{color:var(--muted);font-size:13.5px;margin:0 0 16px}\n.card .icon{width:44px;height:44px;border-radius:50%;background:var(--soft);color:var(--muted);display:grid;place-items:center;margin:0 auto}\n.card form{display:flex;gap:8px}\n.card input{flex:1;min-width:0;font:inherit;padding:9px 12px;border-radius:10px;border:1px solid var(--line);background:var(--bg);color:var(--fg);outline:none}\n.card input:focus{border-color:var(--muted)}\n.card .error{color:var(--warn);font-size:13px;margin:10px 0 0;min-height:1em}\nbutton{font:inherit;font-size:13.5px;padding:8px 14px;border-radius:10px;border:1px solid var(--line);background:var(--bg);color:var(--fg);cursor:pointer}\nbutton.primary{background:var(--fg);color:var(--bg);border-color:var(--fg)}\nbutton:disabled{opacity:.5;cursor:default}\n.spin{width:22px;height:22px;border:2px solid var(--line);border-top-color:var(--muted);border-radius:50%;margin:0 auto;animation:spin .8s linear infinite}\n@keyframes spin{to{transform:rotate(360deg)}}\n@media (prefers-reduced-motion:reduce){.spin{animation-duration:3s}}\n.agent-head{display:flex;flex-direction:column;align-items:center;text-align:center;gap:4px;margin:8px 0 22px}\n.agent-face{width:64px;height:64px;border-radius:50%;background:var(--soft);color:#fff;display:grid;place-items:center;font-size:24px;font-weight:700;margin-bottom:8px;box-shadow:0 0 0 1px var(--line)}\n.agent-head h1.title{margin:0}.agent-head .meta{margin:0;justify-content:center}\n.agent-role{border:1px solid var(--line);border-radius:var(--radius);padding:14px 16px;background:var(--soft)}\n.agent-role>:first-child{margin-top:0}.agent-role>:last-child{margin-bottom:0}\n.agent .notes{margin:10px 0 0}\n.agent-hint{color:var(--muted);font-size:13.5px;text-align:center;margin:18px 0 0}\n.foot{max-width:760px;margin:0 auto;padding:18px 18px 40px;color:var(--faint);font-size:12.5px;border-top:1px solid var(--line);display:flex;flex-direction:column;gap:4px}\n.page{display:block;width:100%;height:calc(100vh - 48px);height:calc(100dvh - 48px);border:0;background:#fff}\n.file img{max-width:100%;border-radius:10px;display:block;margin:0 auto}\n.file pre{white-space:pre-wrap;word-break:break-word;background:var(--code);border-radius:10px;padding:14px;font:12.5px/1.55 ui-monospace,SFMono-Regular,Menlo,monospace}\n";
@@ -4,6 +4,8 @@ export const VIEWER_STYLE = `
4
4
  *{box-sizing:border-box}
5
5
  html,body{margin:0;background:var(--bg);color:var(--fg);font:15px/1.65 -apple-system,BlinkMacSystemFont,"Segoe UI","PingFang SC","Hiragino Sans GB","Microsoft YaHei",sans-serif;-webkit-font-smoothing:antialiased}
6
6
  .top{position:sticky;top:0;z-index:2;display:flex;align-items:center;gap:10px;padding:10px 16px;background:color-mix(in srgb,var(--bg) 88%,transparent);backdrop-filter:saturate(1.6) blur(12px);-webkit-backdrop-filter:saturate(1.6) blur(12px);border-bottom:1px solid var(--line)}
7
+ .open-in-ta{flex:none;display:inline-flex;align-items:center;height:32px;padding:0 14px;border-radius:16px;background:var(--fg);color:var(--bg);font-size:13.5px;font-weight:600;text-decoration:none;white-space:nowrap;-webkit-tap-highlight-color:transparent}
8
+ .open-in-ta:active{opacity:.8}
7
9
  .logo{width:26px;height:26px;border-radius:8px;background:var(--fg);color:var(--bg);display:grid;place-items:center;font-weight:700;font-size:13px;flex:none}
8
10
  .top .name{font-weight:600;font-size:14px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;flex:1;min-width:0}
9
11
  .top button{flex:none}
@@ -1,6 +1,7 @@
1
1
  import { RELAY_AGENT_KIND, RelayAgentCards } from '../common/relay-card.js';
2
2
  import { RelayContentError, RelayContentHandoff, RelayContentUtil } from '../common/relay-content.js';
3
3
  import { RELAY_CONVERSATION_KIND } from '../common/relay-conversation.js';
4
+ import { RelayOpenInTa } from '../common/relay-open-in-ta.js';
4
5
  import { RELAY_FRAME_PATH } from '../common/relay-protocol.js';
5
6
  import { RELAY_WEB_PATH } from '../common/relay-team.js';
6
7
  import { ViewerI18n } from './viewer-i18n.js';
@@ -316,7 +317,8 @@ function chrome(name) {
316
317
  });
317
318
  const title = el('span', name);
318
319
  title.className = 'name';
319
- top.append(Object.assign(el('span', 'Ta'), { className: 'logo' }), title, copy);
320
+ const open = Object.assign(el('a', t('openInTa')), { className: 'open-in-ta', href: RelayOpenInTa.link(location.href) });
321
+ top.append(Object.assign(el('span', 'Ta'), { className: 'logo' }), title, open, copy);
320
322
  const main = el('main');
321
323
  document.body.replaceChildren(top, main);
322
324
  return main;
@@ -1,4 +1,7 @@
1
1
  export * from './qr-code';
2
+ export * from './relay-account';
3
+ export * from './relay-account-client';
4
+ export * from './relay-accounts';
2
5
  export * from './relay-blobs';
3
6
  export * from './relay-bytes';
4
7
  export * from './relay-card';
@@ -8,6 +11,7 @@ export * from './relay-conversation';
8
11
  export * from './relay-faces';
9
12
  export * from './relay-files';
10
13
  export * from './relay-friends';
14
+ export * from './relay-group-invites';
11
15
  export * from './relay-host-calls';
12
16
  export * from './relay-hub';
13
17
  export * from './relay-hub-util';
@@ -15,6 +15,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./qr-code"), exports);
18
+ __exportStar(require("./relay-account"), exports);
19
+ __exportStar(require("./relay-account-client"), exports);
20
+ __exportStar(require("./relay-accounts"), exports);
18
21
  __exportStar(require("./relay-blobs"), exports);
19
22
  __exportStar(require("./relay-bytes"), exports);
20
23
  __exportStar(require("./relay-card"), exports);
@@ -24,6 +27,7 @@ __exportStar(require("./relay-conversation"), exports);
24
27
  __exportStar(require("./relay-faces"), exports);
25
28
  __exportStar(require("./relay-files"), exports);
26
29
  __exportStar(require("./relay-friends"), exports);
30
+ __exportStar(require("./relay-group-invites"), exports);
27
31
  __exportStar(require("./relay-host-calls"), exports);
28
32
  __exportStar(require("./relay-hub"), exports);
29
33
  __exportStar(require("./relay-hub-util"), exports);
@@ -0,0 +1,139 @@
1
+ import { type AccountCalls, type AccountCircleState, type AccountDevice, type AccountDeviceKind, type AccountName, type AccountRoster, type AccountSignInPoll, type AccountSignInStart } from './relay-account';
2
+ import { type RelayIdentity } from './relay-identity';
3
+ /** The service said no: `status` 401 is a token no longer good, 403 this device removed. */
4
+ export declare class AccountCallError extends Error {
5
+ readonly status: number;
6
+ constructor(status: number, message: string);
7
+ }
8
+ /** The account service of a relay or a gateway, over fetch: the same in ta serve and a page. */
9
+ export declare namespace AccountService {
10
+ /** How long the service is waited for: one out of reach (a company's network, away from it) answers nothing at all. */
11
+ const TIMEOUT_MS = 8000;
12
+ function base(service: string): string;
13
+ function providers(service: string): Promise<{
14
+ id: string;
15
+ name: string;
16
+ }[]>;
17
+ function start(service: string, provider: string): Promise<AccountSignInStart>;
18
+ function poll(service: string, provider: string, handle: string): Promise<AccountSignInPoll>;
19
+ /**
20
+ * The ways to sign in to an account: those of the relay (GitHub), and those of the gateways of deployments (a
21
+ * company's accounts), whose own sign-in gives the token; a gateway without the account service is left out.
22
+ */
23
+ function ways(relay: string, gateways?: string[]): Promise<AccountWay[]>;
24
+ /** Begins signing in by `way`: the code the user enters on the page of `url`. */
25
+ function begin(way: AccountWay, deviceName: string): Promise<AccountSignInStart>;
26
+ /** One look at a sign-in begun by `way`. */
27
+ function check(way: AccountWay, handle: string): Promise<AccountSignInPoll>;
28
+ /** The calls of an account, with a token of the service (or of the gateway it is part of). */
29
+ function calls(service: string, token: string): AccountCalls;
30
+ }
31
+ /** A way to sign in to an account: a provider of a relay, or of a gateway (`gateway`), whose token is the account's. */
32
+ export interface AccountWay {
33
+ id: string;
34
+ name: string;
35
+ service: string;
36
+ gateway?: true;
37
+ }
38
+ /** What a device keeps of its account (`account.json` of ta serve, localStorage of a page): its keys and whom it trusts. */
39
+ export interface AccountKept {
40
+ /** The relay or the gateway the account is on. */
41
+ service: string;
42
+ token: string;
43
+ account: AccountName;
44
+ kind: AccountDeviceKind;
45
+ /** This device's own keys, made for the account: not the identity others know the user by. */
46
+ self: RelayIdentity;
47
+ circle: AccountCircleState;
48
+ /** The computers that sent this device a way in: their account device id, the pairing link. */
49
+ pairings: Record<string, string>;
50
+ }
51
+ /** A device of the account as a device sees it. */
52
+ export interface AccountDeviceView {
53
+ id: string;
54
+ kind: AccountDeviceKind;
55
+ name: string;
56
+ self: boolean;
57
+ /** Let in, and trusted by this device. */
58
+ trusted: boolean;
59
+ /** Waiting to be let in: `code` is what it shows, for the user to compare. */
60
+ waiting: boolean;
61
+ code?: string;
62
+ online: boolean;
63
+ seenAt: number;
64
+ addedAt: number;
65
+ }
66
+ export interface AccountView {
67
+ account: AccountName;
68
+ service: string;
69
+ self: string;
70
+ /** This device waits to be let in: `code` is what the device that lets it in shows too. */
71
+ waiting: boolean;
72
+ code: string;
73
+ devices: AccountDeviceView[];
74
+ }
75
+ /** What a device of an account does on its side, besides keeping `AccountKept`. */
76
+ export interface AccountHooks {
77
+ save(kept: AccountKept): void | Promise<void>;
78
+ name(): string;
79
+ /** A computer: where it hangs on a relay, so that devices reach it. */
80
+ host?(): {
81
+ relay: string;
82
+ id: string;
83
+ } | undefined;
84
+ /** A computer: a way in for a trusted device of the account (a pairing link), made once. */
85
+ pair?(device: AccountDevice): Promise<string>;
86
+ /** A computer: the devices of the account it made a way in for. */
87
+ paired?(): string[];
88
+ /** A computer: no way in any more for this device of the account. */
89
+ unpair?(device: string): void | Promise<void>;
90
+ /** A way into a computer of the account came: `link` pairs with it. */
91
+ pairing?(from: AccountDevice, link: string): void | Promise<void>;
92
+ /** A computer that sent a way in is no longer trusted, or removed. */
93
+ unpaired?(from: string): void | Promise<void>;
94
+ /** What a package on another device of the account said (AccountAgent.tell), new or changed. */
95
+ told?(from: AccountDevice, topic: string, value: unknown): void | Promise<void>;
96
+ /** This device was removed from the account, or its token no longer works: it is signed out. */
97
+ signedOut?(reason: 'removed' | 'token'): void | Promise<void>;
98
+ }
99
+ /**
100
+ * A device of an account (docs/design/ta-account.md 4): says it is there, keeps whom it trusts, lets others in, makes and
101
+ * takes ways into computers through sealed mail. The same in ta serve and a page; what is particular comes in hooks.
102
+ */
103
+ export declare class AccountAgent {
104
+ protected kept: AccountKept;
105
+ protected readonly hooks: AccountHooks;
106
+ protected roster?: AccountRoster;
107
+ protected readonly calls: AccountCalls;
108
+ /** What was told last, by `<from>|<topic>`: a mail is kept until replaced, told once each time it changes. */
109
+ protected heard: Map<string, string>;
110
+ constructor(kept: AccountKept, hooks: AccountHooks, calls?: AccountCalls);
111
+ /** A new device of `account`: its own keys, trusting itself alone. */
112
+ static create(service: string, token: string, account: AccountName, kind: AccountDeviceKind, name: string): Promise<AccountKept>;
113
+ get state(): AccountKept;
114
+ protected save(next: AccountKept): Promise<void>;
115
+ protected guard<T>(run: () => Promise<T>): Promise<T>;
116
+ /** One round: be in the roster, trust whom to, let the trusted in to this computer, take ways into others. */
117
+ sync(): Promise<AccountView>;
118
+ /** Let in by `me.endorsement.by`: whom it trusts came sealed, signed by it; the device it let in trusts them too. */
119
+ protected joinCircle(roster: AccountRoster, me: AccountDevice): Promise<void>;
120
+ /**
121
+ * The trusted devices in the roster, with the keys this device trusts them by: the service may list other keys under
122
+ * a trusted id, and mail is sealed to and checked against what was trusted, never what the service says now.
123
+ */
124
+ protected trusted(roster: AccountRoster): AccountDevice[];
125
+ /** Ways in: made for the trusted (a computer), dropped for the rest; taken from trusted computers. */
126
+ protected ways(roster: AccountRoster): Promise<void>;
127
+ view(now?: number): Promise<AccountView>;
128
+ /** The devices of the account this one trusts, itself aside, as the service last listed them. */
129
+ devices(): AccountDevice[];
130
+ /** Says `value` to a trusted device of the account, sealed for it: a package on it hears it by `topic`. */
131
+ tell(to: string, topic: string, value: unknown): Promise<void>;
132
+ /** Lets a waiting device in: signs it, and sends it whom this device trusts. */
133
+ approve(id: string): Promise<AccountView>;
134
+ /** Removes a device (one waiting that is not the user's, or one lost): every device drops it. */
135
+ remove(id: string): Promise<AccountView>;
136
+ /** Leaves the account: removed from it, its token dropped. */
137
+ signOut(): Promise<void>;
138
+ }
139
+ //# sourceMappingURL=relay-account-client.d.ts.map