@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.
- package/esm/common/index.d.ts +2 -0
- package/esm/common/index.js +2 -0
- package/esm/common/relay-content.d.ts +13 -0
- package/esm/common/relay-content.js +42 -0
- package/esm/common/relay-conversation.d.ts +14 -0
- package/esm/common/relay-faces.d.ts +1 -1
- package/esm/common/relay-faces.js +56 -1
- package/esm/common/relay-files.d.ts +14 -3
- package/esm/common/relay-files.js +41 -16
- package/esm/common/relay-friend-sends.d.ts +64 -0
- package/esm/common/relay-friend-sends.js +126 -0
- package/esm/common/relay-group-invites.d.ts +76 -0
- package/esm/common/relay-group-invites.js +163 -0
- package/esm/common/relay-hub.js +2 -2
- package/esm/common/relay-hubs-identity.d.ts +36 -0
- package/esm/common/relay-hubs-identity.js +156 -0
- package/esm/common/relay-hubs-protocol.d.ts +7 -1
- package/esm/common/relay-hubs-util.d.ts +11 -0
- package/esm/common/relay-hubs-util.js +74 -0
- package/esm/common/relay-hubs.d.ts +36 -44
- package/esm/common/relay-hubs.js +95 -235
- package/esm/common/relay-open-in-ta.d.ts +11 -0
- package/esm/common/relay-open-in-ta.js +34 -0
- package/esm/common/relay-protocol.d.ts +11 -2
- package/esm/common/relay-protocol.js +18 -2
- package/esm/common/relay-spot.d.ts +15 -3
- package/esm/common/relay-spot.js +17 -5
- package/esm/guest/guest-i18n.d.ts +1 -0
- package/esm/guest/guest-i18n.js +45 -41
- package/esm/guest/guest-style.d.ts +1 -1
- package/esm/guest/guest-style.js +2 -0
- package/esm/guest/guest.js +7 -2
- package/esm/join/join-i18n.d.ts +1 -0
- package/esm/join/join-i18n.js +4 -0
- package/esm/join/join.js +4 -1
- package/esm/node/index.d.ts +1 -0
- package/esm/node/index.js +1 -0
- package/esm/node/relay-files-host.d.ts +2 -0
- package/esm/node/relay-files-host.js +24 -5
- package/esm/node/relay-memory-storage.d.ts +26 -0
- package/esm/node/relay-memory-storage.js +60 -0
- package/esm/node/relay-server.d.ts +14 -26
- package/esm/node/relay-server.js +33 -60
- package/esm/node/relay-store.js +4 -4
- package/esm/node/relays-file.d.ts +27 -0
- package/esm/node/relays-file.js +59 -4
- package/esm/viewer/viewer-i18n.d.ts +1 -0
- package/esm/viewer/viewer-i18n.js +4 -0
- package/esm/viewer/viewer-style.d.ts +1 -1
- package/esm/viewer/viewer-style.js +2 -0
- package/esm/viewer/viewer.js +36 -2
- package/lib/common/index.d.ts +2 -0
- package/lib/common/index.js +2 -0
- package/lib/common/relay-content.d.ts +13 -0
- package/lib/common/relay-content.js +43 -1
- package/lib/common/relay-conversation.d.ts +14 -0
- package/lib/common/relay-faces.d.ts +1 -1
- package/lib/common/relay-faces.js +56 -1
- package/lib/common/relay-files.d.ts +14 -3
- package/lib/common/relay-files.js +42 -17
- package/lib/common/relay-friend-sends.d.ts +65 -0
- package/lib/common/relay-friend-sends.js +130 -0
- package/lib/common/relay-group-invites.d.ts +77 -0
- package/lib/common/relay-group-invites.js +167 -0
- package/lib/common/relay-hub.js +1 -1
- package/lib/common/relay-hubs-identity.d.ts +37 -0
- package/lib/common/relay-hubs-identity.js +160 -0
- package/lib/common/relay-hubs-protocol.d.ts +7 -1
- package/lib/common/relay-hubs-util.d.ts +12 -0
- package/lib/common/relay-hubs-util.js +77 -0
- package/lib/common/relay-hubs.d.ts +36 -44
- package/lib/common/relay-hubs.js +94 -234
- package/lib/common/relay-open-in-ta.d.ts +12 -0
- package/lib/common/relay-open-in-ta.js +37 -0
- package/lib/common/relay-protocol.d.ts +11 -2
- package/lib/common/relay-protocol.js +20 -3
- package/lib/common/relay-spot.d.ts +15 -3
- package/lib/common/relay-spot.js +17 -5
- package/lib/guest/guest-i18n.d.ts +1 -0
- package/lib/guest/guest-i18n.js +45 -41
- package/lib/guest/guest-style.d.ts +1 -1
- package/lib/guest/guest-style.js +2 -0
- package/lib/guest/guest.js +7 -2
- package/lib/join/join-i18n.d.ts +1 -0
- package/lib/join/join-i18n.js +4 -0
- package/lib/join/join.js +4 -1
- package/lib/node/index.d.ts +1 -0
- package/lib/node/index.js +1 -0
- package/lib/node/relay-files-host.d.ts +2 -0
- package/lib/node/relay-files-host.js +23 -4
- package/lib/node/relay-memory-storage.d.ts +27 -0
- package/lib/node/relay-memory-storage.js +65 -0
- package/lib/node/relay-server.d.ts +14 -26
- package/lib/node/relay-server.js +34 -61
- package/lib/node/relay-store.js +3 -3
- package/lib/node/relays-file.d.ts +27 -0
- package/lib/node/relays-file.js +58 -3
- package/lib/viewer/viewer-i18n.d.ts +1 -0
- package/lib/viewer/viewer-i18n.js +4 -0
- package/lib/viewer/viewer-style.d.ts +1 -1
- package/lib/viewer/viewer-style.js +2 -0
- package/lib/viewer/viewer.js +35 -1
- package/package.json +3 -2
- package/viewer/join.html +12 -3
- package/viewer/page.html +18 -9
- 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
|
|
5
|
-
import {
|
|
4
|
+
import { type TaDeploymentEnv } from '@celljs/ta-protocol/lib/common/deployment-protocol';
|
|
5
|
+
import { RelayBlobs } from '../common/relay-blobs.js';
|
|
6
|
+
import { RelayHub, type RelayHubWho } from '../common/relay-hub.js';
|
|
6
7
|
import { RelayRoom } from '../common/relay-room.js';
|
|
7
8
|
import { RelaySpot, type RelaySpotSocket, type RelaySpotWho } from '../common/relay-spot.js';
|
|
8
9
|
import { FileRelayStorage } from './relay-file-storage.js';
|
|
10
|
+
import { MemoryBlobStorage, MemoryHubStorage } from './relay-memory-storage.js';
|
|
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;
|
package/esm/node/relay-server.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { createHash, randomBytes, timingSafeEqual } from 'node:crypto';
|
|
2
|
-
import { mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { accessSync, constants, mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from 'node:fs';
|
|
3
3
|
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
|
+
import { TA_WELL_KNOWN_PATH, TaDeploymentUtil } from '@celljs/ta-protocol/lib/common/deployment-protocol';
|
|
6
7
|
import { RelayBlobs } from '../common/relay-blobs.js';
|
|
7
8
|
import { RelayHub } from '../common/relay-hub.js';
|
|
8
9
|
import { RELAY_INFO_PATH, RelayInfoUtil } from '../common/relay-info.js';
|
|
@@ -12,67 +13,9 @@ import { RELAY_SPOT_PATH, RelaySpot, RelaySpotCloseCode, RelaySpotTries } from '
|
|
|
12
13
|
import { RELAY_JOIN_PATH, RELAY_WEB_PATH } from '../common/relay-team.js';
|
|
13
14
|
import { RelayWebUtil } from '../common/relay-web.js';
|
|
14
15
|
import { FileRelayStorage } from './relay-file-storage.js';
|
|
16
|
+
import { MemoryBlobStorage, MemoryHubStorage } from './relay-memory-storage.js';
|
|
15
17
|
import { RelayViewer } from './relay-viewer.js';
|
|
16
18
|
const WEBSOCKET = { maxPayload: 32 * 1024 * 1024, heartbeat: 30000 };
|
|
17
|
-
/** A copy of content in memory, deleted when it runs out. */
|
|
18
|
-
class MemoryBlobStorage {
|
|
19
|
-
constructor() {
|
|
20
|
-
this.values = new Map();
|
|
21
|
-
}
|
|
22
|
-
async get(key) {
|
|
23
|
-
return this.values.get(key);
|
|
24
|
-
}
|
|
25
|
-
async put(key, value) {
|
|
26
|
-
this.values.set(key, value);
|
|
27
|
-
}
|
|
28
|
-
async deleteAll() {
|
|
29
|
-
this.values.clear();
|
|
30
|
-
clearTimeout(this.timer);
|
|
31
|
-
}
|
|
32
|
-
/** No copy is kept: nothing of it need stay in the relay's memory. */
|
|
33
|
-
get empty() {
|
|
34
|
-
return this.values.size === 0;
|
|
35
|
-
}
|
|
36
|
-
async setAlarm(at) {
|
|
37
|
-
var _a, _b;
|
|
38
|
-
clearTimeout(this.timer);
|
|
39
|
-
// Past the 24 days of a timer, it is found run out on the next read.
|
|
40
|
-
this.timer = setTimeout(() => this.values.clear(), Math.min(Math.max(at - Date.now(), 0), 2 ** 31 - 1));
|
|
41
|
-
(_b = (_a = this.timer).unref) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
/** A room in memory, as a Durable Object keeps it. */
|
|
45
|
-
class MemoryHubStorage {
|
|
46
|
-
constructor() {
|
|
47
|
-
this.values = new Map();
|
|
48
|
-
}
|
|
49
|
-
async get(key) {
|
|
50
|
-
const value = this.values.get(key);
|
|
51
|
-
return value === undefined ? undefined : structuredClone(value);
|
|
52
|
-
}
|
|
53
|
-
async put(key, value) {
|
|
54
|
-
this.values.set(key, structuredClone(value));
|
|
55
|
-
}
|
|
56
|
-
async delete(key) {
|
|
57
|
-
return this.values.delete(key);
|
|
58
|
-
}
|
|
59
|
-
async list(options) {
|
|
60
|
-
const found = new Map();
|
|
61
|
-
for (const [key, value] of [...this.values].sort(([a], [b]) => a.localeCompare(b))) {
|
|
62
|
-
if (key.startsWith(options.prefix)) {
|
|
63
|
-
found.set(key, structuredClone(value));
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return found;
|
|
67
|
-
}
|
|
68
|
-
async deleteAll() {
|
|
69
|
-
this.values.clear();
|
|
70
|
-
}
|
|
71
|
-
/** No room was made, or it was closed. */
|
|
72
|
-
get empty() {
|
|
73
|
-
return this.values.size === 0;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
19
|
const peer = (connection) => ({ send: text => connection.send(text), close: (code, reason) => connection.close(code, reason) });
|
|
77
20
|
/**
|
|
78
21
|
* `ta relay`: the relay on a machine of one's own, as the Cloudflare Worker is in the cloud. It forwards,
|
|
@@ -111,10 +54,40 @@ export class RelayServer {
|
|
|
111
54
|
}
|
|
112
55
|
}
|
|
113
56
|
}
|
|
57
|
+
/** What it is part of, and whether it runs and can keep what it holds: for anyone, and the probes of a platform. */
|
|
58
|
+
describe(path, request, response) {
|
|
59
|
+
var _a, _b;
|
|
60
|
+
const version = this.options.version;
|
|
61
|
+
let body = { ok: true, ...(version ? { version } : {}) };
|
|
62
|
+
let status = 200;
|
|
63
|
+
if (path === TA_WELL_KNOWN_PATH) {
|
|
64
|
+
const env = (_a = this.options.deployment) !== null && _a !== void 0 ? _a : {};
|
|
65
|
+
const forwarded = String((_b = request.headers['x-forwarded-proto']) !== null && _b !== void 0 ? _b : '')
|
|
66
|
+
.split(',')[0]
|
|
67
|
+
.trim();
|
|
68
|
+
const origin = request.headers.host ? `${forwarded === 'https' ? 'https' : 'http'}://${request.headers.host}` : undefined;
|
|
69
|
+
body = TaDeploymentUtil.describe(env, { relay: env.TA_PUBLIC_URL || origin }, version);
|
|
70
|
+
}
|
|
71
|
+
else if (path === '/readyz' && this.options.data) {
|
|
72
|
+
try {
|
|
73
|
+
accessSync(this.options.data, constants.W_OK);
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
status = 503;
|
|
77
|
+
body = { ok: false, error: `${this.options.data} cannot be written: ${error.message}` };
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
response.writeHead(status, TaDeploymentUtil.HEADERS);
|
|
81
|
+
response.end(JSON.stringify(body));
|
|
82
|
+
}
|
|
114
83
|
listen() {
|
|
115
84
|
const server = createServer((request, response) => {
|
|
116
85
|
var _a;
|
|
117
86
|
const path = ((_a = request.url) !== null && _a !== void 0 ? _a : '/').split(/[?#]/)[0];
|
|
87
|
+
if (path === TA_WELL_KNOWN_PATH || path === '/healthz' || path === '/readyz') {
|
|
88
|
+
this.describe(path, request, response);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
118
91
|
if (path === RELAY_INFO_PATH) {
|
|
119
92
|
// Without a directory for its data, rooms and copies live in memory: gone when the relay restarts.
|
|
120
93
|
const info = RelayInfoUtil.of(!!this.options.data);
|
package/esm/node/relay-store.js
CHANGED
|
@@ -5,7 +5,7 @@ import { dirname, join } from 'node:path';
|
|
|
5
5
|
import { RelayBytes } from '../common/relay-bytes.js';
|
|
6
6
|
import { RelayContentUtil } from '../common/relay-content.js';
|
|
7
7
|
import { RelayIdentityUtil } from '../common/relay-identity.js';
|
|
8
|
-
import { RELAY_BLOB_MAX_DAYS,
|
|
8
|
+
import { RELAY_BLOB_MAX_DAYS, RELAY_SHARE_DAYS, relayDefaultUrl } from '../common/relay-protocol.js';
|
|
9
9
|
const id = () => randomBytes(16).toString('base64url');
|
|
10
10
|
/** The devices paired with this ta serve. Read again on every use: `ta pair` changes it while ta serve runs. */
|
|
11
11
|
export class RelayStore {
|
|
@@ -38,7 +38,7 @@ export class RelayStore {
|
|
|
38
38
|
/** The relay of a device, a link or content shared: its own, else the one of relay.json, else the official one. */
|
|
39
39
|
static relayOf(item, config) {
|
|
40
40
|
var _a, _b;
|
|
41
|
-
return (_b = (_a = item.relay) !== null && _a !== void 0 ? _a : config.url) !== null && _b !== void 0 ? _b :
|
|
41
|
+
return (_b = (_a = item.relay) !== null && _a !== void 0 ? _a : config.url) !== null && _b !== void 0 ? _b : relayDefaultUrl();
|
|
42
42
|
}
|
|
43
43
|
/** A share still on, by its id. */
|
|
44
44
|
share(shareId, now = Date.now()) {
|
|
@@ -86,7 +86,7 @@ export class RelayStore {
|
|
|
86
86
|
const expiresAt = days ? now + days * 24 * 60 * 60 * 1000 : undefined;
|
|
87
87
|
const offline = input.offline && input.access !== 'self' && input.access !== 'people';
|
|
88
88
|
const before = this.read();
|
|
89
|
-
const relay = ((_b = (_a = input.relay) !== null && _a !== void 0 ? _a : before.url) !== null && _b !== void 0 ? _b :
|
|
89
|
+
const relay = ((_b = (_a = input.relay) !== null && _a !== void 0 ? _a : before.url) !== null && _b !== void 0 ? _b : relayDefaultUrl()).replace(/\/+$/, '');
|
|
90
90
|
const content = {
|
|
91
91
|
id,
|
|
92
92
|
relay,
|
|
@@ -167,7 +167,7 @@ export class RelayStore {
|
|
|
167
167
|
shareRoot(root, name, now = Date.now(), relay) {
|
|
168
168
|
var _a, _b, _c, _d;
|
|
169
169
|
const before = this.read();
|
|
170
|
-
const wanted = ((_a = relay !== null && relay !== void 0 ? relay : before.url) !== null && _a !== void 0 ? _a :
|
|
170
|
+
const wanted = ((_a = relay !== null && relay !== void 0 ? relay : before.url) !== null && _a !== void 0 ? _a : relayDefaultUrl()).replace(/\/+$/, '');
|
|
171
171
|
const url = (_b = before.url) !== null && _b !== void 0 ? _b : wanted;
|
|
172
172
|
const host = (_c = before.host) !== null && _c !== void 0 ? _c : { id: id(), secret: randomBytes(32).toString('base64url') };
|
|
173
173
|
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. */
|
package/esm/node/relays-file.js
CHANGED
|
@@ -2,7 +2,7 @@ import { accessSync, chmodSync, constants, mkdirSync, readdirSync, readFileSync,
|
|
|
2
2
|
import { homedir } from 'node:os';
|
|
3
3
|
import { dirname, isAbsolute, join, resolve } from 'node:path';
|
|
4
4
|
import { RelayInfoUtil } from '../common/relay-info.js';
|
|
5
|
-
import {
|
|
5
|
+
import { relayDefaultUrl } from '../common/relay-protocol.js';
|
|
6
6
|
export const RELAY_FEATURES = ['devices', 'share', 'rooms', 'sync'];
|
|
7
7
|
/** The relay that comes with Ta, by its id in relays.json. */
|
|
8
8
|
export const OFFICIAL_RELAY = 'cellbang';
|
|
@@ -166,7 +166,7 @@ export class RelaysFile {
|
|
|
166
166
|
const entries = [];
|
|
167
167
|
const own = config.relays && typeof config.relays === 'object' ? config.relays : {};
|
|
168
168
|
if (!own[OFFICIAL_RELAY]) {
|
|
169
|
-
entries.push({ id: OFFICIAL_RELAY, type: 'ta-relay', url:
|
|
169
|
+
entries.push({ id: OFFICIAL_RELAY, type: 'ta-relay', url: relayDefaultUrl(), name: new URL(relayDefaultUrl()).host, builtin: true });
|
|
170
170
|
}
|
|
171
171
|
for (const [id, service] of Object.entries(own)) {
|
|
172
172
|
if (!ID.test(id) || !service || typeof service !== 'object') {
|
|
@@ -200,7 +200,7 @@ export class RelaysFile {
|
|
|
200
200
|
if (service) {
|
|
201
201
|
return service;
|
|
202
202
|
}
|
|
203
|
-
const url = fallback !== null && fallback !== void 0 ? fallback :
|
|
203
|
+
const url = fallback !== null && fallback !== void 0 ? fallback : relayDefaultUrl();
|
|
204
204
|
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 };
|
|
205
205
|
}
|
|
206
206
|
/**
|
|
@@ -218,7 +218,7 @@ export class RelaysFile {
|
|
|
218
218
|
/** The address a feature uses: its service, else `fallback` (the relay of relay.json), else the official one. */
|
|
219
219
|
urlFor(feature, fallback) {
|
|
220
220
|
const service = this.serviceFor(feature, fallback);
|
|
221
|
-
return RelayServiceUtil.isRelay(service) ? service.url : (fallback !== null && fallback !== void 0 ? fallback :
|
|
221
|
+
return RelayServiceUtil.isRelay(service) ? service.url : (fallback !== null && fallback !== void 0 ? fallback : relayDefaultUrl());
|
|
222
222
|
}
|
|
223
223
|
/** Adds a relay by its address: its id from its host name. The id, and the one before for the same address. */
|
|
224
224
|
add(url, name) {
|
|
@@ -326,6 +326,61 @@ export class RelaysFile {
|
|
|
326
326
|
delete relays[id];
|
|
327
327
|
this.write({ ...config, relays });
|
|
328
328
|
}
|
|
329
|
+
/**
|
|
330
|
+
* Joins a deployment, as it said of itself: its relay added and made the default (what a feature not in `use` takes),
|
|
331
|
+
* the deployment kept. What was made before (devices, rooms, links) stays on its relay; a choice in `use` stays too.
|
|
332
|
+
*/
|
|
333
|
+
join(url, deployment) {
|
|
334
|
+
var _a, _b;
|
|
335
|
+
const relay = deployment.relay ? this.add(deployment.relay, deployment.name) : undefined;
|
|
336
|
+
const config = this.read();
|
|
337
|
+
const name = (_a = deployment.name) === null || _a === void 0 ? void 0 : _a.trim().slice(0, 80);
|
|
338
|
+
const joined = {
|
|
339
|
+
url,
|
|
340
|
+
...(name ? { name } : {}),
|
|
341
|
+
...(deployment.gateway ? { gateway: deployment.gateway } : {}),
|
|
342
|
+
...(relay ? { relay } : {}),
|
|
343
|
+
};
|
|
344
|
+
const { default: before, ...rest } = config;
|
|
345
|
+
const fallback = relay !== null && relay !== void 0 ? relay : (before === ((_b = config.deployment) === null || _b === void 0 ? void 0 : _b.relay) ? undefined : before);
|
|
346
|
+
this.write({ ...rest, ...(fallback ? { default: fallback } : {}), deployment: joined });
|
|
347
|
+
return joined;
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Leaves the deployment joined: the default is the relay of this build again, and its relay goes from the list when
|
|
351
|
+
* no feature names it. What is on it (rooms, links) stays there, each remembering its relay.
|
|
352
|
+
*/
|
|
353
|
+
leave() {
|
|
354
|
+
var _a, _b;
|
|
355
|
+
const config = this.read();
|
|
356
|
+
const joined = config.deployment;
|
|
357
|
+
if (!joined) {
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
const { deployment: _left, default: before, ...rest } = config;
|
|
361
|
+
const relays = { ...((_a = rest.relays) !== null && _a !== void 0 ? _a : {}) };
|
|
362
|
+
const used = Object.values((_b = rest.use) !== null && _b !== void 0 ? _b : {});
|
|
363
|
+
if (joined.relay && joined.relay !== OFFICIAL_RELAY && !used.includes(joined.relay)) {
|
|
364
|
+
delete relays[joined.relay];
|
|
365
|
+
}
|
|
366
|
+
const kept = before && before !== joined.relay ? before : undefined;
|
|
367
|
+
this.write({ ...rest, relays, ...(kept ? { default: kept } : {}) });
|
|
368
|
+
}
|
|
369
|
+
/** The deployment joined, as relays.json holds it: none when a hand wrote something else there. */
|
|
370
|
+
deployment(config = this.safeRead().config) {
|
|
371
|
+
const joined = config.deployment;
|
|
372
|
+
if (!joined || typeof joined !== 'object' || typeof joined.url !== 'string') {
|
|
373
|
+
return undefined;
|
|
374
|
+
}
|
|
375
|
+
const text = (value) => (typeof value === 'string' && value ? value : undefined);
|
|
376
|
+
const relay = text(joined.relay);
|
|
377
|
+
return {
|
|
378
|
+
url: joined.url,
|
|
379
|
+
...(text(joined.name) ? { name: text(joined.name) } : {}),
|
|
380
|
+
...(text(joined.gateway) ? { gateway: text(joined.gateway) } : {}),
|
|
381
|
+
...(relay && this.services(config).some(service => service.id === relay) ? { relay } : {}),
|
|
382
|
+
};
|
|
383
|
+
}
|
|
329
384
|
/** Which relay a feature uses from now on; `undefined` leaves it to the default. */
|
|
330
385
|
use(feature, id) {
|
|
331
386
|
var _a;
|
|
@@ -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}
|
package/esm/viewer/viewer.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { RELAY_AGENT_KIND, RelayAgentCards } from '../common/relay-card.js';
|
|
2
|
-
import { RelayContentError, RelayContentUtil } from '../common/relay-content.js';
|
|
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';
|
|
6
|
+
import { RELAY_WEB_PATH } from '../common/relay-team.js';
|
|
5
7
|
import { ViewerI18n } from './viewer-i18n.js';
|
|
6
8
|
import { ViewerMarkdown } from './viewer-markdown.js';
|
|
7
9
|
import { VIEWER_STYLE } from './viewer-style.js';
|
|
@@ -105,6 +107,19 @@ function conversation(main, item) {
|
|
|
105
107
|
row.append(Object.assign(el('div', said), { className: 'bubble' }));
|
|
106
108
|
main.append(row);
|
|
107
109
|
}
|
|
110
|
+
else if (message.role === 'custom') {
|
|
111
|
+
// A card of an extension, as its words: Ta's page draws the card itself.
|
|
112
|
+
const { words } = text(message.content);
|
|
113
|
+
if (words.trim()) {
|
|
114
|
+
const row = el('div');
|
|
115
|
+
row.className = 'msg ta';
|
|
116
|
+
const block = el('div');
|
|
117
|
+
block.className = 'text';
|
|
118
|
+
block.append(ViewerMarkdown.render(words));
|
|
119
|
+
row.append(block);
|
|
120
|
+
main.append(row);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
108
123
|
else if (message.role === 'assistant') {
|
|
109
124
|
const row = el('div');
|
|
110
125
|
row.className = 'msg ta';
|
|
@@ -302,7 +317,8 @@ function chrome(name) {
|
|
|
302
317
|
});
|
|
303
318
|
const title = el('span', name);
|
|
304
319
|
title.className = 'name';
|
|
305
|
-
|
|
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);
|
|
306
322
|
const main = el('main');
|
|
307
323
|
document.body.replaceChildren(top, main);
|
|
308
324
|
return main;
|
|
@@ -314,6 +330,17 @@ function footer(card) {
|
|
|
314
330
|
foot.append(...(card ? [] : [el('span', t('footer'))]), el('span', t('secure')));
|
|
315
331
|
document.body.append(foot);
|
|
316
332
|
}
|
|
333
|
+
/** Whether the relay serves Ta's web page (apps/ta-relay with its assets, `ta relay` given its files). */
|
|
334
|
+
async function richPage() {
|
|
335
|
+
var _a;
|
|
336
|
+
try {
|
|
337
|
+
const response = await fetch(RELAY_WEB_PATH, { method: 'HEAD', cache: 'no-store' });
|
|
338
|
+
return response.ok && ((_a = response.headers.get('content-type')) !== null && _a !== void 0 ? _a : '').startsWith('text/html');
|
|
339
|
+
}
|
|
340
|
+
catch (_b) {
|
|
341
|
+
return false;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
317
344
|
async function show() {
|
|
318
345
|
var _a;
|
|
319
346
|
const main = chrome(t('title'));
|
|
@@ -329,6 +356,8 @@ async function show() {
|
|
|
329
356
|
card(main, 'self', t(link.access));
|
|
330
357
|
return;
|
|
331
358
|
}
|
|
359
|
+
// Ta's own page, where the relay has it (RELAY_WEB_PATH), draws a conversation as Ta does: its cards, plots and 3D.
|
|
360
|
+
const rich = new URLSearchParams(location.search).has('plain') ? Promise.resolve(false) : richPage();
|
|
332
361
|
let password;
|
|
333
362
|
let error;
|
|
334
363
|
for (;;) {
|
|
@@ -341,6 +370,11 @@ async function show() {
|
|
|
341
370
|
}
|
|
342
371
|
try {
|
|
343
372
|
const item = await RelayContentUtil.fetch(link, { password });
|
|
373
|
+
if (item.kind === RELAY_CONVERSATION_KIND && (await rich)) {
|
|
374
|
+
RelayContentHandoff.keep(link.share, item, password);
|
|
375
|
+
location.replace(RELAY_WEB_PATH + location.hash);
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
344
378
|
main.replaceChildren();
|
|
345
379
|
const name = document.querySelector('.top .name');
|
|
346
380
|
if (name) {
|
package/lib/common/index.d.ts
CHANGED
|
@@ -8,11 +8,13 @@ export * from './relay-conversation';
|
|
|
8
8
|
export * from './relay-faces';
|
|
9
9
|
export * from './relay-files';
|
|
10
10
|
export * from './relay-friends';
|
|
11
|
+
export * from './relay-group-invites';
|
|
11
12
|
export * from './relay-host-calls';
|
|
12
13
|
export * from './relay-hub';
|
|
13
14
|
export * from './relay-hub-util';
|
|
14
15
|
export * from './relay-hubs';
|
|
15
16
|
export * from './relay-hubs-protocol';
|
|
17
|
+
export * from './relay-hubs-util';
|
|
16
18
|
export * from './relay-identity';
|
|
17
19
|
export * from './relay-info';
|
|
18
20
|
export * from './relay-pairing';
|
package/lib/common/index.js
CHANGED
|
@@ -24,11 +24,13 @@ __exportStar(require("./relay-conversation"), exports);
|
|
|
24
24
|
__exportStar(require("./relay-faces"), exports);
|
|
25
25
|
__exportStar(require("./relay-files"), exports);
|
|
26
26
|
__exportStar(require("./relay-friends"), exports);
|
|
27
|
+
__exportStar(require("./relay-group-invites"), exports);
|
|
27
28
|
__exportStar(require("./relay-host-calls"), exports);
|
|
28
29
|
__exportStar(require("./relay-hub"), exports);
|
|
29
30
|
__exportStar(require("./relay-hub-util"), exports);
|
|
30
31
|
__exportStar(require("./relay-hubs"), exports);
|
|
31
32
|
__exportStar(require("./relay-hubs-protocol"), exports);
|
|
33
|
+
__exportStar(require("./relay-hubs-util"), exports);
|
|
32
34
|
__exportStar(require("./relay-identity"), exports);
|
|
33
35
|
__exportStar(require("./relay-info"), exports);
|
|
34
36
|
__exportStar(require("./relay-pairing"), exports);
|
|
@@ -102,4 +102,17 @@ export declare namespace RelayContentUtil {
|
|
|
102
102
|
*/
|
|
103
103
|
function fetch(text: string | RelayContentLink, options?: RelayContentFetchOptions): Promise<RelayContentItem>;
|
|
104
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* What the viewer of the relay opened, handed to Ta's web page of the same relay (RELAY_WEB_PATH), which draws a
|
|
107
|
+
* conversation as Ta does: kept in the session of the tab, by the share, for the page that comes next and for it
|
|
108
|
+
* loaded again; the password alone when the whole is too large to keep, so that it is not asked again.
|
|
109
|
+
*/
|
|
110
|
+
export declare namespace RelayContentHandoff {
|
|
111
|
+
function keep(share: string, item: RelayContentItem, password?: string): void;
|
|
112
|
+
/** What was kept for `share`: the content opened, or its password. */
|
|
113
|
+
function take(share: string): {
|
|
114
|
+
item?: RelayContentItem;
|
|
115
|
+
password?: string;
|
|
116
|
+
};
|
|
117
|
+
}
|
|
105
118
|
//# sourceMappingURL=relay-content.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RelayContentUtil = exports.RelayContentError = void 0;
|
|
3
|
+
exports.RelayContentHandoff = exports.RelayContentUtil = exports.RelayContentError = void 0;
|
|
4
4
|
const relay_bytes_1 = require("./relay-bytes");
|
|
5
5
|
const relay_identity_1 = require("./relay-identity");
|
|
6
6
|
const relay_protocol_1 = require("./relay-protocol");
|
|
@@ -317,4 +317,46 @@ var RelayContentUtil;
|
|
|
317
317
|
return new Uint8Array(bits);
|
|
318
318
|
}
|
|
319
319
|
})(RelayContentUtil || (exports.RelayContentUtil = RelayContentUtil = {}));
|
|
320
|
+
/**
|
|
321
|
+
* What the viewer of the relay opened, handed to Ta's web page of the same relay (RELAY_WEB_PATH), which draws a
|
|
322
|
+
* conversation as Ta does: kept in the session of the tab, by the share, for the page that comes next and for it
|
|
323
|
+
* loaded again; the password alone when the whole is too large to keep, so that it is not asked again.
|
|
324
|
+
*/
|
|
325
|
+
var RelayContentHandoff;
|
|
326
|
+
(function (RelayContentHandoff) {
|
|
327
|
+
const KEY = 'ta.shared';
|
|
328
|
+
function keep(share, item, password) {
|
|
329
|
+
const { data, ...header } = item;
|
|
330
|
+
const store = (kept) => { var _a; return (_a = globalThis.sessionStorage) === null || _a === void 0 ? void 0 : _a.setItem(KEY, JSON.stringify(kept)); };
|
|
331
|
+
try {
|
|
332
|
+
store({ share, ...(password === undefined ? {} : { password }), item: { ...header, data: relay_bytes_1.RelayBytes.toBase64(data) } });
|
|
333
|
+
}
|
|
334
|
+
catch (_a) {
|
|
335
|
+
try {
|
|
336
|
+
store({ share, ...(password === undefined ? {} : { password }) });
|
|
337
|
+
}
|
|
338
|
+
catch (_b) {
|
|
339
|
+
// Kept nowhere: the page asks again.
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
RelayContentHandoff.keep = keep;
|
|
344
|
+
/** What was kept for `share`: the content opened, or its password. */
|
|
345
|
+
function take(share) {
|
|
346
|
+
var _a;
|
|
347
|
+
var _b;
|
|
348
|
+
try {
|
|
349
|
+
const kept = JSON.parse((_b = (_a = globalThis.sessionStorage) === null || _a === void 0 ? void 0 : _a.getItem(KEY)) !== null && _b !== void 0 ? _b : 'null');
|
|
350
|
+
if ((kept === null || kept === void 0 ? void 0 : kept.share) !== share) {
|
|
351
|
+
return {};
|
|
352
|
+
}
|
|
353
|
+
const item = kept.item && { ...kept.item, data: relay_bytes_1.RelayBytes.fromBase64(kept.item.data) };
|
|
354
|
+
return { ...(item ? { item } : {}), ...(kept.password === undefined ? {} : { password: kept.password }) };
|
|
355
|
+
}
|
|
356
|
+
catch (_c) {
|
|
357
|
+
return {};
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
RelayContentHandoff.take = take;
|
|
361
|
+
})(RelayContentHandoff || (exports.RelayContentHandoff = RelayContentHandoff = {}));
|
|
320
362
|
//# sourceMappingURL=relay-content.js.map
|