@celljs/ta-relay 4.16.0 → 4.18.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 (106) hide show
  1. package/esm/common/index.d.ts +2 -0
  2. package/esm/common/index.js +2 -0
  3. package/esm/common/relay-content.d.ts +13 -0
  4. package/esm/common/relay-content.js +42 -0
  5. package/esm/common/relay-conversation.d.ts +14 -0
  6. package/esm/common/relay-faces.d.ts +1 -1
  7. package/esm/common/relay-faces.js +56 -1
  8. package/esm/common/relay-files.d.ts +14 -3
  9. package/esm/common/relay-files.js +41 -16
  10. package/esm/common/relay-friend-sends.d.ts +64 -0
  11. package/esm/common/relay-friend-sends.js +126 -0
  12. package/esm/common/relay-group-invites.d.ts +76 -0
  13. package/esm/common/relay-group-invites.js +163 -0
  14. package/esm/common/relay-hub.js +2 -2
  15. package/esm/common/relay-hubs-identity.d.ts +36 -0
  16. package/esm/common/relay-hubs-identity.js +156 -0
  17. package/esm/common/relay-hubs-protocol.d.ts +7 -1
  18. package/esm/common/relay-hubs-util.d.ts +11 -0
  19. package/esm/common/relay-hubs-util.js +74 -0
  20. package/esm/common/relay-hubs.d.ts +36 -44
  21. package/esm/common/relay-hubs.js +95 -235
  22. package/esm/common/relay-open-in-ta.d.ts +11 -0
  23. package/esm/common/relay-open-in-ta.js +34 -0
  24. package/esm/common/relay-protocol.d.ts +11 -2
  25. package/esm/common/relay-protocol.js +18 -2
  26. package/esm/common/relay-spot.d.ts +15 -3
  27. package/esm/common/relay-spot.js +17 -5
  28. package/esm/guest/guest-i18n.d.ts +1 -0
  29. package/esm/guest/guest-i18n.js +45 -41
  30. package/esm/guest/guest-style.d.ts +1 -1
  31. package/esm/guest/guest-style.js +2 -0
  32. package/esm/guest/guest.js +7 -2
  33. package/esm/join/join-i18n.d.ts +1 -0
  34. package/esm/join/join-i18n.js +4 -0
  35. package/esm/join/join.js +4 -1
  36. package/esm/node/index.d.ts +1 -0
  37. package/esm/node/index.js +1 -0
  38. package/esm/node/relay-files-host.d.ts +2 -0
  39. package/esm/node/relay-files-host.js +24 -5
  40. package/esm/node/relay-memory-storage.d.ts +26 -0
  41. package/esm/node/relay-memory-storage.js +60 -0
  42. package/esm/node/relay-server.d.ts +14 -26
  43. package/esm/node/relay-server.js +33 -60
  44. package/esm/node/relay-store.js +4 -4
  45. package/esm/node/relays-file.d.ts +27 -0
  46. package/esm/node/relays-file.js +59 -4
  47. package/esm/viewer/viewer-i18n.d.ts +1 -0
  48. package/esm/viewer/viewer-i18n.js +4 -0
  49. package/esm/viewer/viewer-style.d.ts +1 -1
  50. package/esm/viewer/viewer-style.js +2 -0
  51. package/esm/viewer/viewer.js +36 -2
  52. package/lib/common/index.d.ts +2 -0
  53. package/lib/common/index.js +2 -0
  54. package/lib/common/relay-content.d.ts +13 -0
  55. package/lib/common/relay-content.js +43 -1
  56. package/lib/common/relay-conversation.d.ts +14 -0
  57. package/lib/common/relay-faces.d.ts +1 -1
  58. package/lib/common/relay-faces.js +56 -1
  59. package/lib/common/relay-files.d.ts +14 -3
  60. package/lib/common/relay-files.js +42 -17
  61. package/lib/common/relay-friend-sends.d.ts +65 -0
  62. package/lib/common/relay-friend-sends.js +130 -0
  63. package/lib/common/relay-group-invites.d.ts +77 -0
  64. package/lib/common/relay-group-invites.js +167 -0
  65. package/lib/common/relay-hub.js +1 -1
  66. package/lib/common/relay-hubs-identity.d.ts +37 -0
  67. package/lib/common/relay-hubs-identity.js +160 -0
  68. package/lib/common/relay-hubs-protocol.d.ts +7 -1
  69. package/lib/common/relay-hubs-util.d.ts +12 -0
  70. package/lib/common/relay-hubs-util.js +77 -0
  71. package/lib/common/relay-hubs.d.ts +36 -44
  72. package/lib/common/relay-hubs.js +94 -234
  73. package/lib/common/relay-open-in-ta.d.ts +12 -0
  74. package/lib/common/relay-open-in-ta.js +37 -0
  75. package/lib/common/relay-protocol.d.ts +11 -2
  76. package/lib/common/relay-protocol.js +20 -3
  77. package/lib/common/relay-spot.d.ts +15 -3
  78. package/lib/common/relay-spot.js +17 -5
  79. package/lib/guest/guest-i18n.d.ts +1 -0
  80. package/lib/guest/guest-i18n.js +45 -41
  81. package/lib/guest/guest-style.d.ts +1 -1
  82. package/lib/guest/guest-style.js +2 -0
  83. package/lib/guest/guest.js +7 -2
  84. package/lib/join/join-i18n.d.ts +1 -0
  85. package/lib/join/join-i18n.js +4 -0
  86. package/lib/join/join.js +4 -1
  87. package/lib/node/index.d.ts +1 -0
  88. package/lib/node/index.js +1 -0
  89. package/lib/node/relay-files-host.d.ts +2 -0
  90. package/lib/node/relay-files-host.js +23 -4
  91. package/lib/node/relay-memory-storage.d.ts +27 -0
  92. package/lib/node/relay-memory-storage.js +65 -0
  93. package/lib/node/relay-server.d.ts +14 -26
  94. package/lib/node/relay-server.js +34 -61
  95. package/lib/node/relay-store.js +3 -3
  96. package/lib/node/relays-file.d.ts +27 -0
  97. package/lib/node/relays-file.js +58 -3
  98. package/lib/viewer/viewer-i18n.d.ts +1 -0
  99. package/lib/viewer/viewer-i18n.js +4 -0
  100. package/lib/viewer/viewer-style.d.ts +1 -1
  101. package/lib/viewer/viewer-style.js +2 -0
  102. package/lib/viewer/viewer.js +35 -1
  103. package/package.json +3 -2
  104. package/viewer/join.html +12 -3
  105. package/viewer/page.html +18 -9
  106. package/viewer/room.html +21 -10
@@ -1,11 +1,13 @@
1
1
  import { type IncomingMessage, type Server, type ServerResponse } from 'node:http';
2
2
  import type { Duplex } from 'node:stream';
3
3
  import { WebSocketConnection } from '@celljs/rpc/lib/node/websocket/websocket-connection';
4
- import { type RelayBlobStorage, RelayBlobs } from '../common/relay-blobs';
5
- import { RelayHub, type RelayHubStorage, type RelayHubWho } from '../common/relay-hub';
4
+ import { type TaDeploymentEnv } from '@celljs/ta-protocol/lib/common/deployment-protocol';
5
+ import { RelayBlobs } from '../common/relay-blobs';
6
+ import { RelayHub, type RelayHubWho } from '../common/relay-hub';
6
7
  import { RelayRoom } from '../common/relay-room';
7
8
  import { RelaySpot, type RelaySpotSocket, type RelaySpotWho } from '../common/relay-spot';
8
9
  import { FileRelayStorage } from './relay-file-storage';
10
+ import { MemoryBlobStorage, MemoryHubStorage } from './relay-memory-storage';
9
11
  export interface RelayServerOptions {
10
12
  host?: string;
11
13
  port?: number;
@@ -19,6 +21,14 @@ export interface RelayServerOptions {
19
21
  * (`ta relay` gives its own); without it, a link that invites still asks from a browser, but leads nowhere.
20
22
  */
21
23
  web?: string;
24
+ /**
25
+ * What it says of the deployment it is part of (TA_WELL_KNOWN_PATH, docs/design/ta-deploy.md 2): its name, its
26
+ * gateway, and its own address (TA_PUBLIC_URL; else the one it was reached at).
27
+ */
28
+ deployment?: TaDeploymentEnv & {
29
+ TA_PUBLIC_URL?: string;
30
+ };
31
+ version?: string;
22
32
  }
23
33
  interface Room {
24
34
  secretHash: string;
@@ -26,30 +36,6 @@ interface Room {
26
36
  clients: Map<string, WebSocketConnection>;
27
37
  relay: RelayRoom;
28
38
  }
29
- /** A copy of content in memory, deleted when it runs out. */
30
- declare class MemoryBlobStorage implements RelayBlobStorage {
31
- protected readonly values: Map<string, unknown>;
32
- protected timer?: ReturnType<typeof setTimeout>;
33
- get<T>(key: string): Promise<T | undefined>;
34
- put(key: string, value: unknown): Promise<void>;
35
- deleteAll(): Promise<void>;
36
- /** No copy is kept: nothing of it need stay in the relay's memory. */
37
- get empty(): boolean;
38
- setAlarm(at: number): Promise<void>;
39
- }
40
- /** A room in memory, as a Durable Object keeps it. */
41
- declare class MemoryHubStorage implements RelayHubStorage {
42
- protected readonly values: Map<string, unknown>;
43
- get<T>(key: string): Promise<T | undefined>;
44
- put(key: string, value: unknown): Promise<void>;
45
- delete(key: string): Promise<boolean>;
46
- list<T>(options: {
47
- prefix: string;
48
- }): Promise<Map<string, T>>;
49
- deleteAll(): Promise<void>;
50
- /** No room was made, or it was closed. */
51
- get empty(): boolean;
52
- }
53
39
  interface Hub {
54
40
  hub: RelayHub;
55
41
  storage: MemoryHubStorage | FileRelayStorage;
@@ -86,6 +72,8 @@ export declare class RelayServer {
86
72
  protected readonly spotAddresses: WeakMap<WebSocketConnection, string>;
87
73
  protected server?: Server;
88
74
  constructor(options?: RelayServerOptions);
75
+ /** What it is part of, and whether it runs and can keep what it holds: for anyone, and the probes of a platform. */
76
+ protected describe(path: string, request: IncomingMessage, response: ServerResponse): void;
89
77
  listen(): Promise<string>;
90
78
  /** A file of Ta's web page (RelayWebUtil), from the directory of the options. */
91
79
  protected web(path: string, response: ServerResponse): void;
@@ -6,6 +6,7 @@ const node_fs_1 = require("node:fs");
6
6
  const node_http_1 = require("node:http");
7
7
  const node_path_1 = require("node:path");
8
8
  const websocket_connection_1 = require("@celljs/rpc/lib/node/websocket/websocket-connection");
9
+ const deployment_protocol_1 = require("@celljs/ta-protocol/lib/common/deployment-protocol");
9
10
  const relay_blobs_1 = require("../common/relay-blobs");
10
11
  const relay_hub_1 = require("../common/relay-hub");
11
12
  const relay_info_1 = require("../common/relay-info");
@@ -15,67 +16,9 @@ const relay_spot_1 = require("../common/relay-spot");
15
16
  const relay_team_1 = require("../common/relay-team");
16
17
  const relay_web_1 = require("../common/relay-web");
17
18
  const relay_file_storage_1 = require("./relay-file-storage");
19
+ const relay_memory_storage_1 = require("./relay-memory-storage");
18
20
  const relay_viewer_1 = require("./relay-viewer");
19
21
  const WEBSOCKET = { maxPayload: 32 * 1024 * 1024, heartbeat: 30000 };
20
- /** A copy of content in memory, deleted when it runs out. */
21
- class MemoryBlobStorage {
22
- constructor() {
23
- this.values = new Map();
24
- }
25
- async get(key) {
26
- return this.values.get(key);
27
- }
28
- async put(key, value) {
29
- this.values.set(key, value);
30
- }
31
- async deleteAll() {
32
- this.values.clear();
33
- clearTimeout(this.timer);
34
- }
35
- /** No copy is kept: nothing of it need stay in the relay's memory. */
36
- get empty() {
37
- return this.values.size === 0;
38
- }
39
- async setAlarm(at) {
40
- var _a, _b;
41
- clearTimeout(this.timer);
42
- // Past the 24 days of a timer, it is found run out on the next read.
43
- this.timer = setTimeout(() => this.values.clear(), Math.min(Math.max(at - Date.now(), 0), 2 ** 31 - 1));
44
- (_b = (_a = this.timer).unref) === null || _b === void 0 ? void 0 : _b.call(_a);
45
- }
46
- }
47
- /** A room in memory, as a Durable Object keeps it. */
48
- class MemoryHubStorage {
49
- constructor() {
50
- this.values = new Map();
51
- }
52
- async get(key) {
53
- const value = this.values.get(key);
54
- return value === undefined ? undefined : structuredClone(value);
55
- }
56
- async put(key, value) {
57
- this.values.set(key, structuredClone(value));
58
- }
59
- async delete(key) {
60
- return this.values.delete(key);
61
- }
62
- async list(options) {
63
- const found = new Map();
64
- for (const [key, value] of [...this.values].sort(([a], [b]) => a.localeCompare(b))) {
65
- if (key.startsWith(options.prefix)) {
66
- found.set(key, structuredClone(value));
67
- }
68
- }
69
- return found;
70
- }
71
- async deleteAll() {
72
- this.values.clear();
73
- }
74
- /** No room was made, or it was closed. */
75
- get empty() {
76
- return this.values.size === 0;
77
- }
78
- }
79
22
  const peer = (connection) => ({ send: text => connection.send(text), close: (code, reason) => connection.close(code, reason) });
80
23
  /**
81
24
  * `ta relay`: the relay on a machine of one's own, as the Cloudflare Worker is in the cloud. It forwards,
@@ -114,10 +57,40 @@ class RelayServer {
114
57
  }
115
58
  }
116
59
  }
60
+ /** What it is part of, and whether it runs and can keep what it holds: for anyone, and the probes of a platform. */
61
+ describe(path, request, response) {
62
+ var _a, _b;
63
+ const version = this.options.version;
64
+ let body = { ok: true, ...(version ? { version } : {}) };
65
+ let status = 200;
66
+ if (path === deployment_protocol_1.TA_WELL_KNOWN_PATH) {
67
+ const env = (_a = this.options.deployment) !== null && _a !== void 0 ? _a : {};
68
+ const forwarded = String((_b = request.headers['x-forwarded-proto']) !== null && _b !== void 0 ? _b : '')
69
+ .split(',')[0]
70
+ .trim();
71
+ const origin = request.headers.host ? `${forwarded === 'https' ? 'https' : 'http'}://${request.headers.host}` : undefined;
72
+ body = deployment_protocol_1.TaDeploymentUtil.describe(env, { relay: env.TA_PUBLIC_URL || origin }, version);
73
+ }
74
+ else if (path === '/readyz' && this.options.data) {
75
+ try {
76
+ (0, node_fs_1.accessSync)(this.options.data, node_fs_1.constants.W_OK);
77
+ }
78
+ catch (error) {
79
+ status = 503;
80
+ body = { ok: false, error: `${this.options.data} cannot be written: ${error.message}` };
81
+ }
82
+ }
83
+ response.writeHead(status, deployment_protocol_1.TaDeploymentUtil.HEADERS);
84
+ response.end(JSON.stringify(body));
85
+ }
117
86
  listen() {
118
87
  const server = (0, node_http_1.createServer)((request, response) => {
119
88
  var _a;
120
89
  const path = ((_a = request.url) !== null && _a !== void 0 ? _a : '/').split(/[?#]/)[0];
90
+ if (path === deployment_protocol_1.TA_WELL_KNOWN_PATH || path === '/healthz' || path === '/readyz') {
91
+ this.describe(path, request, response);
92
+ return;
93
+ }
121
94
  if (path === relay_info_1.RELAY_INFO_PATH) {
122
95
  // Without a directory for its data, rooms and copies live in memory: gone when the relay restarts.
123
96
  const info = relay_info_1.RelayInfoUtil.of(!!this.options.data);
@@ -263,7 +236,7 @@ class RelayServer {
263
236
  var _a;
264
237
  void ((_a = made.storage) === null || _a === void 0 ? void 0 : _a.deleteAll().then(() => this.blobs.get(id) === copy && this.blobs.delete(id)));
265
238
  })
266
- : new MemoryBlobStorage();
239
+ : new relay_memory_storage_1.MemoryBlobStorage();
267
240
  made.storage = storage;
268
241
  made.blobs = new relay_blobs_1.RelayBlobs(storage);
269
242
  copy = made;
@@ -503,7 +476,7 @@ class RelayServer {
503
476
  const made = { sockets };
504
477
  const storage = this.options.data
505
478
  ? new relay_file_storage_1.FileRelayStorage((0, node_path_1.join)(this.options.data, 'hubs', id), () => { var _a; return void ((_a = made.hub) === null || _a === void 0 ? void 0 : _a.alarm().then(() => this.dropHub(id, made))); })
506
- : new MemoryHubStorage();
479
+ : new relay_memory_storage_1.MemoryHubStorage();
507
480
  made.storage = storage;
508
481
  made.hub = new relay_hub_1.RelayHub(storage, () => [...sockets.keys()].map(socketOf));
509
482
  hub = made;
@@ -41,7 +41,7 @@ class RelayStore {
41
41
  /** The relay of a device, a link or content shared: its own, else the one of relay.json, else the official one. */
42
42
  static relayOf(item, config) {
43
43
  var _a, _b;
44
- return (_b = (_a = item.relay) !== null && _a !== void 0 ? _a : config.url) !== null && _b !== void 0 ? _b : relay_protocol_1.RELAY_DEFAULT_URL;
44
+ return (_b = (_a = item.relay) !== null && _a !== void 0 ? _a : config.url) !== null && _b !== void 0 ? _b : (0, relay_protocol_1.relayDefaultUrl)();
45
45
  }
46
46
  /** A share still on, by its id. */
47
47
  share(shareId, now = Date.now()) {
@@ -89,7 +89,7 @@ class RelayStore {
89
89
  const expiresAt = days ? now + days * 24 * 60 * 60 * 1000 : undefined;
90
90
  const offline = input.offline && input.access !== 'self' && input.access !== 'people';
91
91
  const before = this.read();
92
- const relay = ((_b = (_a = input.relay) !== null && _a !== void 0 ? _a : before.url) !== null && _b !== void 0 ? _b : relay_protocol_1.RELAY_DEFAULT_URL).replace(/\/+$/, '');
92
+ const relay = ((_b = (_a = input.relay) !== null && _a !== void 0 ? _a : before.url) !== null && _b !== void 0 ? _b : (0, relay_protocol_1.relayDefaultUrl)()).replace(/\/+$/, '');
93
93
  const content = {
94
94
  id,
95
95
  relay,
@@ -170,7 +170,7 @@ class RelayStore {
170
170
  shareRoot(root, name, now = Date.now(), relay) {
171
171
  var _a, _b, _c, _d;
172
172
  const before = this.read();
173
- const wanted = ((_a = relay !== null && relay !== void 0 ? relay : before.url) !== null && _a !== void 0 ? _a : relay_protocol_1.RELAY_DEFAULT_URL).replace(/\/+$/, '');
173
+ const wanted = ((_a = relay !== null && relay !== void 0 ? relay : before.url) !== null && _a !== void 0 ? _a : (0, relay_protocol_1.relayDefaultUrl)()).replace(/\/+$/, '');
174
174
  const url = (_b = before.url) !== null && _b !== void 0 ? _b : wanted;
175
175
  const host = (_c = before.host) !== null && _c !== void 0 ? _c : { id: id(), secret: (0, node_crypto_1.randomBytes)(32).toString('base64url') };
176
176
  const live = ((_d = before.shares) !== null && _d !== void 0 ? _d : []).filter(share => share.expiresAt > now);
@@ -49,12 +49,23 @@ export interface RelayStoreServiceEntry {
49
49
  options: Record<string, unknown>;
50
50
  builtin: false;
51
51
  }
52
+ /**
53
+ * A deployment of Ta the user joined (docs/design/ta-deploy.md 8): where it was found, what it said of itself, and the id
54
+ * of its relay in relays.json, which is then the default of new pairings, rooms and links.
55
+ */
56
+ export interface RelaysDeployment {
57
+ url: string;
58
+ name?: string;
59
+ gateway?: string;
60
+ relay?: string;
61
+ }
52
62
  /** relays.json in the agent directory: the relays, and which one each feature uses. Written by hand or by Ta. */
53
63
  export interface RelaysConfig {
54
64
  relays?: Record<string, RelayService>;
55
65
  use?: Record<string, string>;
56
66
  /** What a feature not in `use` takes. */
57
67
  default?: string;
68
+ deployment?: RelaysDeployment;
58
69
  }
59
70
  export type RelayServiceEntry = (({
60
71
  type: 'ta-relay';
@@ -131,6 +142,22 @@ export declare class RelaysFile {
131
142
  addStore(type: string, options: Record<string, unknown>, name?: string): string;
132
143
  /** Removes a relay that no feature uses; the official one stays. What is on it (devices, rooms, links) stays on it. */
133
144
  remove(id: string): void;
145
+ /**
146
+ * Joins a deployment, as it said of itself: its relay added and made the default (what a feature not in `use` takes),
147
+ * the deployment kept. What was made before (devices, rooms, links) stays on its relay; a choice in `use` stays too.
148
+ */
149
+ join(url: string, deployment: {
150
+ name?: string;
151
+ gateway?: string;
152
+ relay?: string;
153
+ }): RelaysDeployment;
154
+ /**
155
+ * Leaves the deployment joined: the default is the relay of this build again, and its relay goes from the list when
156
+ * no feature names it. What is on it (rooms, links) stays there, each remembering its relay.
157
+ */
158
+ leave(): void;
159
+ /** The deployment joined, as relays.json holds it: none when a hand wrote something else there. */
160
+ deployment(config?: RelaysConfig): RelaysDeployment | undefined;
134
161
  /** Which relay a feature uses from now on; `undefined` leaves it to the default. */
135
162
  use(feature: RelayFeature, id: string | undefined): void;
136
163
  /** Written whole, its other keys as they were, through a temporary file. */
@@ -170,7 +170,7 @@ class RelaysFile {
170
170
  const entries = [];
171
171
  const own = config.relays && typeof config.relays === 'object' ? config.relays : {};
172
172
  if (!own[exports.OFFICIAL_RELAY]) {
173
- entries.push({ id: exports.OFFICIAL_RELAY, type: 'ta-relay', url: relay_protocol_1.RELAY_DEFAULT_URL, name: 'relay.cellbang.com', builtin: true });
173
+ entries.push({ id: exports.OFFICIAL_RELAY, type: 'ta-relay', url: (0, relay_protocol_1.relayDefaultUrl)(), name: new URL((0, relay_protocol_1.relayDefaultUrl)()).host, builtin: true });
174
174
  }
175
175
  for (const [id, service] of Object.entries(own)) {
176
176
  if (!ID.test(id) || !service || typeof service !== 'object') {
@@ -204,7 +204,7 @@ class RelaysFile {
204
204
  if (service) {
205
205
  return service;
206
206
  }
207
- const url = fallback !== null && fallback !== void 0 ? fallback : relay_protocol_1.RELAY_DEFAULT_URL;
207
+ const url = fallback !== null && fallback !== void 0 ? fallback : (0, relay_protocol_1.relayDefaultUrl)();
208
208
  return (_a = this.services(config).find(entry => RelayServiceUtil.isRelay(entry) && entry.url === url)) !== null && _a !== void 0 ? _a : { id: '', type: 'ta-relay', url, builtin: false };
209
209
  }
210
210
  /**
@@ -222,7 +222,7 @@ class RelaysFile {
222
222
  /** The address a feature uses: its service, else `fallback` (the relay of relay.json), else the official one. */
223
223
  urlFor(feature, fallback) {
224
224
  const service = this.serviceFor(feature, fallback);
225
- return RelayServiceUtil.isRelay(service) ? service.url : (fallback !== null && fallback !== void 0 ? fallback : relay_protocol_1.RELAY_DEFAULT_URL);
225
+ return RelayServiceUtil.isRelay(service) ? service.url : (fallback !== null && fallback !== void 0 ? fallback : (0, relay_protocol_1.relayDefaultUrl)());
226
226
  }
227
227
  /** Adds a relay by its address: its id from its host name. The id, and the one before for the same address. */
228
228
  add(url, name) {
@@ -330,6 +330,61 @@ class RelaysFile {
330
330
  delete relays[id];
331
331
  this.write({ ...config, relays });
332
332
  }
333
+ /**
334
+ * Joins a deployment, as it said of itself: its relay added and made the default (what a feature not in `use` takes),
335
+ * the deployment kept. What was made before (devices, rooms, links) stays on its relay; a choice in `use` stays too.
336
+ */
337
+ join(url, deployment) {
338
+ var _a, _b;
339
+ const relay = deployment.relay ? this.add(deployment.relay, deployment.name) : undefined;
340
+ const config = this.read();
341
+ const name = (_a = deployment.name) === null || _a === void 0 ? void 0 : _a.trim().slice(0, 80);
342
+ const joined = {
343
+ url,
344
+ ...(name ? { name } : {}),
345
+ ...(deployment.gateway ? { gateway: deployment.gateway } : {}),
346
+ ...(relay ? { relay } : {}),
347
+ };
348
+ const { default: before, ...rest } = config;
349
+ const fallback = relay !== null && relay !== void 0 ? relay : (before === ((_b = config.deployment) === null || _b === void 0 ? void 0 : _b.relay) ? undefined : before);
350
+ this.write({ ...rest, ...(fallback ? { default: fallback } : {}), deployment: joined });
351
+ return joined;
352
+ }
353
+ /**
354
+ * Leaves the deployment joined: the default is the relay of this build again, and its relay goes from the list when
355
+ * no feature names it. What is on it (rooms, links) stays there, each remembering its relay.
356
+ */
357
+ leave() {
358
+ var _a, _b;
359
+ const config = this.read();
360
+ const joined = config.deployment;
361
+ if (!joined) {
362
+ return;
363
+ }
364
+ const { deployment: _left, default: before, ...rest } = config;
365
+ const relays = { ...((_a = rest.relays) !== null && _a !== void 0 ? _a : {}) };
366
+ const used = Object.values((_b = rest.use) !== null && _b !== void 0 ? _b : {});
367
+ if (joined.relay && joined.relay !== exports.OFFICIAL_RELAY && !used.includes(joined.relay)) {
368
+ delete relays[joined.relay];
369
+ }
370
+ const kept = before && before !== joined.relay ? before : undefined;
371
+ this.write({ ...rest, relays, ...(kept ? { default: kept } : {}) });
372
+ }
373
+ /** The deployment joined, as relays.json holds it: none when a hand wrote something else there. */
374
+ deployment(config = this.safeRead().config) {
375
+ const joined = config.deployment;
376
+ if (!joined || typeof joined !== 'object' || typeof joined.url !== 'string') {
377
+ return undefined;
378
+ }
379
+ const text = (value) => (typeof value === 'string' && value ? value : undefined);
380
+ const relay = text(joined.relay);
381
+ return {
382
+ url: joined.url,
383
+ ...(text(joined.name) ? { name: text(joined.name) } : {}),
384
+ ...(text(joined.gateway) ? { gateway: text(joined.gateway) } : {}),
385
+ ...(relay && this.services(config).some(service => service.id === relay) ? { relay } : {}),
386
+ };
387
+ }
333
388
  /** Which relay a feature uses from now on; `undefined` leaves it to the default. */
334
389
  use(feature, id) {
335
390
  var _a;
@@ -1,5 +1,6 @@
1
1
  import { type PageLanguage } from '../common/page-language';
2
2
  declare const zh: {
3
+ openInTa: string;
3
4
  title: string;
4
5
  loading: string;
5
6
  conversation: string;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ViewerI18n = exports.VIEWER_WORDS = void 0;
4
4
  const page_language_1 = require("../common/page-language");
5
5
  const zh = {
6
+ openInTa: '在 Ta 中打开',
6
7
  title: 'Ta 分享',
7
8
  loading: '正在打开…',
8
9
  conversation: '对话',
@@ -52,6 +53,7 @@ const zh = {
52
53
  use: '使用 {name}',
53
54
  };
54
55
  const zhTw = {
56
+ openInTa: '在 Ta 中開啟',
55
57
  title: 'Ta 分享',
56
58
  loading: '正在開啟…',
57
59
  conversation: '對話',
@@ -101,6 +103,7 @@ const zhTw = {
101
103
  use: '使用 {name}',
102
104
  };
103
105
  const en = {
106
+ openInTa: 'Open in Ta',
104
107
  title: 'Shared from Ta',
105
108
  loading: 'Opening…',
106
109
  conversation: 'Conversation',
@@ -150,6 +153,7 @@ const en = {
150
153
  use: 'Use {name}',
151
154
  };
152
155
  const ja = {
156
+ openInTa: 'Ta で開く',
153
157
  title: 'Ta から共有',
154
158
  loading: '開いています…',
155
159
  conversation: '会話',
@@ -1,2 +1,2 @@
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";
2
2
  //# sourceMappingURL=viewer-style.d.ts.map
@@ -7,6 +7,8 @@ exports.VIEWER_STYLE = `
7
7
  *{box-sizing:border-box}
8
8
  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}
9
9
  .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)}
10
+ .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}
11
+ .open-in-ta:active{opacity:.8}
10
12
  .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}
11
13
  .top .name{font-weight:600;font-size:14px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;flex:1;min-width:0}
12
14
  .top button{flex:none}
@@ -4,7 +4,9 @@ exports.ViewerTools = void 0;
4
4
  const relay_card_1 = require("../common/relay-card");
5
5
  const relay_content_1 = require("../common/relay-content");
6
6
  const relay_conversation_1 = require("../common/relay-conversation");
7
+ const relay_open_in_ta_1 = require("../common/relay-open-in-ta");
7
8
  const relay_protocol_1 = require("../common/relay-protocol");
9
+ const relay_team_1 = require("../common/relay-team");
8
10
  const viewer_i18n_1 = require("./viewer-i18n");
9
11
  const viewer_markdown_1 = require("./viewer-markdown");
10
12
  const viewer_style_1 = require("./viewer-style");
@@ -108,6 +110,19 @@ function conversation(main, item) {
108
110
  row.append(Object.assign(el('div', said), { className: 'bubble' }));
109
111
  main.append(row);
110
112
  }
113
+ else if (message.role === 'custom') {
114
+ // A card of an extension, as its words: Ta's page draws the card itself.
115
+ const { words } = text(message.content);
116
+ if (words.trim()) {
117
+ const row = el('div');
118
+ row.className = 'msg ta';
119
+ const block = el('div');
120
+ block.className = 'text';
121
+ block.append(viewer_markdown_1.ViewerMarkdown.render(words));
122
+ row.append(block);
123
+ main.append(row);
124
+ }
125
+ }
111
126
  else if (message.role === 'assistant') {
112
127
  const row = el('div');
113
128
  row.className = 'msg ta';
@@ -305,7 +320,8 @@ function chrome(name) {
305
320
  });
306
321
  const title = el('span', name);
307
322
  title.className = 'name';
308
- top.append(Object.assign(el('span', 'Ta'), { className: 'logo' }), title, copy);
323
+ const open = Object.assign(el('a', t('openInTa')), { className: 'open-in-ta', href: relay_open_in_ta_1.RelayOpenInTa.link(location.href) });
324
+ top.append(Object.assign(el('span', 'Ta'), { className: 'logo' }), title, open, copy);
309
325
  const main = el('main');
310
326
  document.body.replaceChildren(top, main);
311
327
  return main;
@@ -317,6 +333,17 @@ function footer(card) {
317
333
  foot.append(...(card ? [] : [el('span', t('footer'))]), el('span', t('secure')));
318
334
  document.body.append(foot);
319
335
  }
336
+ /** Whether the relay serves Ta's web page (apps/ta-relay with its assets, `ta relay` given its files). */
337
+ async function richPage() {
338
+ var _a;
339
+ try {
340
+ const response = await fetch(relay_team_1.RELAY_WEB_PATH, { method: 'HEAD', cache: 'no-store' });
341
+ return response.ok && ((_a = response.headers.get('content-type')) !== null && _a !== void 0 ? _a : '').startsWith('text/html');
342
+ }
343
+ catch (_b) {
344
+ return false;
345
+ }
346
+ }
320
347
  async function show() {
321
348
  var _a;
322
349
  const main = chrome(t('title'));
@@ -332,6 +359,8 @@ async function show() {
332
359
  card(main, 'self', t(link.access));
333
360
  return;
334
361
  }
362
+ // Ta's own page, where the relay has it (RELAY_WEB_PATH), draws a conversation as Ta does: its cards, plots and 3D.
363
+ const rich = new URLSearchParams(location.search).has('plain') ? Promise.resolve(false) : richPage();
335
364
  let password;
336
365
  let error;
337
366
  for (;;) {
@@ -344,6 +373,11 @@ async function show() {
344
373
  }
345
374
  try {
346
375
  const item = await relay_content_1.RelayContentUtil.fetch(link, { password });
376
+ if (item.kind === relay_conversation_1.RELAY_CONVERSATION_KIND && (await rich)) {
377
+ relay_content_1.RelayContentHandoff.keep(link.share, item, password);
378
+ location.replace(relay_team_1.RELAY_WEB_PATH + location.hash);
379
+ return;
380
+ }
347
381
  main.replaceChildren();
348
382
  const name = document.querySelector('.top .name');
349
383
  if (name) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celljs/ta-relay",
3
- "version": "4.16.0",
3
+ "version": "4.18.0",
4
4
  "description": "Ta from anywhere: a relay that only forwards, and end-to-end encryption between a paired device and ta serve",
5
5
  "homepage": "https://github.com/cellbang/ta",
6
6
  "bugs": {
@@ -30,7 +30,8 @@
30
30
  "watch": "tsc -b -w --preserveWatchOutput"
31
31
  },
32
32
  "dependencies": {
33
- "@celljs/rpc": "4.16.0"
33
+ "@celljs/rpc": "4.18.0",
34
+ "@celljs/ta-protocol": "4.18.0"
34
35
  },
35
36
  "publishConfig": {
36
37
  "access": "public"