@celljs/ta-relay 4.10.0 → 4.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +13 -1
- package/README.md +13 -1
- package/esm/common/index.d.ts +11 -0
- package/esm/common/index.js +11 -0
- package/esm/common/relay-blobs.d.ts +54 -0
- package/esm/common/relay-blobs.js +153 -0
- package/esm/common/relay-card.d.ts +23 -0
- package/esm/common/relay-card.js +30 -0
- package/esm/common/relay-content.d.ts +104 -0
- package/esm/common/relay-content.js +316 -0
- package/esm/common/relay-conversation.d.ts +59 -0
- package/esm/common/relay-conversation.js +9 -0
- package/esm/common/relay-faces.d.ts +32 -0
- package/esm/common/relay-faces.js +208 -0
- package/esm/common/relay-hub-util.d.ts +91 -0
- package/esm/common/relay-hub-util.js +164 -0
- package/esm/common/relay-hub.d.ts +125 -0
- package/esm/common/relay-hub.js +438 -0
- package/esm/common/relay-hubs-connection.d.ts +98 -0
- package/esm/common/relay-hubs-connection.js +505 -0
- package/esm/common/relay-hubs-protocol.d.ts +130 -0
- package/esm/common/relay-hubs-protocol.js +2 -0
- package/esm/common/relay-hubs.d.ts +61 -0
- package/esm/common/relay-hubs.js +351 -0
- package/esm/common/relay-identity.d.ts +46 -0
- package/esm/common/relay-identity.js +126 -0
- package/esm/common/relay-protocol.d.ts +211 -2
- package/esm/common/relay-protocol.js +53 -0
- package/esm/common/relay-room-chat.d.ts +109 -0
- package/esm/common/relay-room-chat.js +176 -0
- package/esm/common/relay-socket.d.ts +8 -0
- package/esm/common/relay-socket.js +23 -2
- package/esm/guest/guest-i18n.d.ts +50 -0
- package/esm/guest/guest-i18n.js +103 -0
- package/esm/guest/guest-style.d.ts +1 -0
- package/esm/guest/guest-style.js +85 -0
- package/esm/guest/guest.d.ts +1 -0
- package/esm/guest/guest.js +384 -0
- package/esm/node/index.d.ts +2 -0
- package/esm/node/index.js +2 -0
- package/esm/node/relay-host.d.ts +25 -3
- package/esm/node/relay-host.js +115 -4
- package/esm/node/relay-hub-files.d.ts +12 -0
- package/esm/node/relay-hub-files.js +39 -0
- package/esm/node/relay-server.d.ts +46 -1
- package/esm/node/relay-server.js +227 -1
- package/esm/node/relay-store.d.ts +72 -0
- package/esm/node/relay-store.js +123 -2
- package/esm/node/relay-viewer.d.ts +7 -0
- package/esm/node/relay-viewer.js +33 -0
- package/esm/viewer/viewer-i18n.d.ts +56 -0
- package/esm/viewer/viewer-i18n.js +117 -0
- package/esm/viewer/viewer-markdown.d.ts +7 -0
- package/esm/viewer/viewer-markdown.js +198 -0
- package/esm/viewer/viewer-style.d.ts +1 -0
- package/esm/viewer/viewer-style.js +72 -0
- package/esm/viewer/viewer.d.ts +8 -0
- package/esm/viewer/viewer.js +378 -0
- package/lib/common/index.d.ts +11 -0
- package/lib/common/index.js +11 -0
- package/lib/common/relay-blobs.d.ts +55 -0
- package/lib/common/relay-blobs.js +157 -0
- package/lib/common/relay-card.d.ts +24 -0
- package/lib/common/relay-card.js +33 -0
- package/lib/common/relay-content.d.ts +105 -0
- package/lib/common/relay-content.js +320 -0
- package/lib/common/relay-conversation.d.ts +60 -0
- package/lib/common/relay-conversation.js +12 -0
- package/lib/common/relay-faces.d.ts +33 -0
- package/lib/common/relay-faces.js +211 -0
- package/lib/common/relay-hub-util.d.ts +92 -0
- package/lib/common/relay-hub-util.js +167 -0
- package/lib/common/relay-hub.d.ts +126 -0
- package/lib/common/relay-hub.js +442 -0
- package/lib/common/relay-hubs-connection.d.ts +99 -0
- package/lib/common/relay-hubs-connection.js +510 -0
- package/lib/common/relay-hubs-protocol.d.ts +131 -0
- package/lib/common/relay-hubs-protocol.js +3 -0
- package/lib/common/relay-hubs.d.ts +62 -0
- package/lib/common/relay-hubs.js +355 -0
- package/lib/common/relay-identity.d.ts +47 -0
- package/lib/common/relay-identity.js +129 -0
- package/lib/common/relay-protocol.d.ts +211 -2
- package/lib/common/relay-protocol.js +54 -1
- package/lib/common/relay-room-chat.d.ts +110 -0
- package/lib/common/relay-room-chat.js +180 -0
- package/lib/common/relay-socket.d.ts +8 -0
- package/lib/common/relay-socket.js +23 -2
- package/lib/guest/guest-i18n.d.ts +51 -0
- package/lib/guest/guest-i18n.js +106 -0
- package/lib/guest/guest-style.d.ts +2 -0
- package/lib/guest/guest-style.js +88 -0
- package/lib/guest/guest.d.ts +2 -0
- package/lib/guest/guest.js +386 -0
- package/lib/node/index.d.ts +2 -0
- package/lib/node/index.js +2 -0
- package/lib/node/relay-host.d.ts +25 -3
- package/lib/node/relay-host.js +115 -4
- package/lib/node/relay-hub-files.d.ts +13 -0
- package/lib/node/relay-hub-files.js +43 -0
- package/lib/node/relay-server.d.ts +46 -1
- package/lib/node/relay-server.js +226 -0
- package/lib/node/relay-store.d.ts +72 -0
- package/lib/node/relay-store.js +121 -0
- package/lib/node/relay-viewer.d.ts +8 -0
- package/lib/node/relay-viewer.js +32 -0
- package/lib/viewer/viewer-i18n.d.ts +57 -0
- package/lib/viewer/viewer-i18n.js +120 -0
- package/lib/viewer/viewer-markdown.d.ts +8 -0
- package/lib/viewer/viewer-markdown.js +201 -0
- package/lib/viewer/viewer-style.d.ts +2 -0
- package/lib/viewer/viewer-style.js +75 -0
- package/lib/viewer/viewer.d.ts +9 -0
- package/lib/viewer/viewer.js +381 -0
- package/package.json +5 -4
- package/viewer/frame.html +1 -0
- package/viewer/page.html +80 -0
- package/viewer/room.html +94 -0
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { type RelayContentAccess, type RelayContentHeader, type RelayContentLink } from '../common/relay-content.js';
|
|
2
|
+
import { type RelayIdentity, type RelayPublicIdentity } from '../common/relay-identity.js';
|
|
1
3
|
import type { RelayPairing } from '../common/relay-pairing.js';
|
|
2
4
|
import type { RelayShareLink } from '../common/relay-share.js';
|
|
3
5
|
export interface RelayDevice {
|
|
@@ -18,6 +20,47 @@ export interface RelayShare {
|
|
|
18
20
|
createdAt: number;
|
|
19
21
|
expiresAt: number;
|
|
20
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Content shared by a link (docs/design/ta-link.md): a conversation, a page, a file, as it was when shared. Its
|
|
25
|
+
* bytes are in `shares/<id>` of the agent directory; this ta serve hands them to whoever opens the link.
|
|
26
|
+
*/
|
|
27
|
+
export interface RelayContentShare extends RelayContentHeader {
|
|
28
|
+
id: string;
|
|
29
|
+
access: RelayContentAccess;
|
|
30
|
+
/** base64url, 32 bytes: what the content is sealed with (with a password, derived from it and the key of the link). */
|
|
31
|
+
key: string;
|
|
32
|
+
/** base64url, 32 bytes: the key of the link, for the link again; none for `self`. */
|
|
33
|
+
linkKey?: string;
|
|
34
|
+
size: number;
|
|
35
|
+
/** None: until stopped. */
|
|
36
|
+
expiresAt?: number;
|
|
37
|
+
/** A copy kept on the relay, sealed: the token that writes and deletes it there, and when it runs out. */
|
|
38
|
+
offline?: {
|
|
39
|
+
token: string;
|
|
40
|
+
expiresAt: number;
|
|
41
|
+
};
|
|
42
|
+
/** For `people`: the Ta friends it is shared with, each with the key made with it (RelayContentUtil.peopleKey). */
|
|
43
|
+
people?: {
|
|
44
|
+
id: string;
|
|
45
|
+
name: string;
|
|
46
|
+
key: string;
|
|
47
|
+
}[];
|
|
48
|
+
/** For `people`: this Ta's identity, which the link names. */
|
|
49
|
+
owner?: string;
|
|
50
|
+
}
|
|
51
|
+
/** What a share of content is made of (RelayStore.addContent). */
|
|
52
|
+
export interface RelayContentInput extends RelayContentHeader {
|
|
53
|
+
data: Uint8Array;
|
|
54
|
+
access: RelayContentAccess;
|
|
55
|
+
/** For `password`. */
|
|
56
|
+
password?: string;
|
|
57
|
+
/** None or 0: until stopped (not with `offline`, which is RELAY_BLOB_MAX_DAYS at most). */
|
|
58
|
+
days?: number;
|
|
59
|
+
offline?: boolean;
|
|
60
|
+
/** For `people`: the Ta friends it is shared with, and this Ta's identity. */
|
|
61
|
+
people?: RelayPublicIdentity[];
|
|
62
|
+
identity?: RelayIdentity;
|
|
63
|
+
}
|
|
21
64
|
/** relay.json in the agent directory. Without devices, ta serve does not connect to the relay. */
|
|
22
65
|
export interface RelayConfig {
|
|
23
66
|
/** The relay, without a trailing slash. */
|
|
@@ -30,6 +73,8 @@ export interface RelayConfig {
|
|
|
30
73
|
devices: RelayDevice[];
|
|
31
74
|
/** Packages handed on; those past their time are dropped when it is written. */
|
|
32
75
|
shares?: RelayShare[];
|
|
76
|
+
/** Content shared; those past their time are dropped, with their bytes, when it is written. */
|
|
77
|
+
contents?: RelayContentShare[];
|
|
33
78
|
}
|
|
34
79
|
/** The devices paired with this ta serve. Read again on every use: `ta pair` changes it while ta serve runs. */
|
|
35
80
|
export declare class RelayStore {
|
|
@@ -43,6 +88,33 @@ export declare class RelayStore {
|
|
|
43
88
|
share(shareId: string, now?: number): RelayShare | undefined;
|
|
44
89
|
/** The shares still on. */
|
|
45
90
|
shares(now?: number): RelayShare[];
|
|
91
|
+
/** Content shared, still on, by its id. */
|
|
92
|
+
content(contentId: string, now?: number): RelayContentShare | undefined;
|
|
93
|
+
/** Content shared, still on, the latest first. */
|
|
94
|
+
contents(now?: number): RelayContentShare[];
|
|
95
|
+
/** The bytes of content shared; undefined when they are gone. */
|
|
96
|
+
contentData(content: RelayContentShare): Uint8Array | undefined;
|
|
97
|
+
/**
|
|
98
|
+
* Shares content: its bytes kept here, a link for it on the relay of the devices (the default one when there is
|
|
99
|
+
* none), which this ta serve then connects to for any but `self`.
|
|
100
|
+
*/
|
|
101
|
+
addContent(input: RelayContentInput, now?: number): Promise<{
|
|
102
|
+
content: RelayContentShare;
|
|
103
|
+
link: RelayContentLink;
|
|
104
|
+
}>;
|
|
105
|
+
/** The link of content shared here. */
|
|
106
|
+
contentLink(content: RelayContentShare, config?: Pick<RelayConfig, 'url' | 'host'>): RelayContentLink;
|
|
107
|
+
/** Stops a share of content: its link no longer works, its bytes are deleted. The share, if there was one. */
|
|
108
|
+
removeContent(contentId: string): RelayContentShare | undefined;
|
|
109
|
+
/** The key of each Ta friend content is shared with, made with this Ta's identity for this share. */
|
|
110
|
+
protected static people(input: RelayContentInput, id: string): Promise<{
|
|
111
|
+
id: string;
|
|
112
|
+
name: string;
|
|
113
|
+
key: string;
|
|
114
|
+
}[]>;
|
|
115
|
+
protected contentFile(contentId: string): string;
|
|
116
|
+
protected static live(content: RelayContentShare, now: number): boolean;
|
|
117
|
+
protected static id(): string;
|
|
46
118
|
/**
|
|
47
119
|
* A link of the package in `root`: the one of before while it lasts, else a new one for RELAY_SHARE_DAYS,
|
|
48
120
|
* on the relay of the devices (the default one when there is none), which this ta serve then connects to.
|
package/esm/node/relay-store.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { createHash, randomBytes } from 'node:crypto';
|
|
2
|
-
import { chmodSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { chmodSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
3
|
import { hostname } from 'node:os';
|
|
4
4
|
import { dirname, join } from 'node:path';
|
|
5
|
-
import {
|
|
5
|
+
import { RelayBytes } from '../common/relay-bytes.js';
|
|
6
|
+
import { RelayContentUtil } from '../common/relay-content.js';
|
|
7
|
+
import { RelayIdentityUtil } from '../common/relay-identity.js';
|
|
8
|
+
import { RELAY_BLOB_MAX_DAYS, RELAY_DEFAULT_URL, RELAY_SHARE_DAYS } from '../common/relay-protocol.js';
|
|
6
9
|
const id = () => randomBytes(16).toString('base64url');
|
|
7
10
|
/** The devices paired with this ta serve. Read again on every use: `ta pair` changes it while ta serve runs. */
|
|
8
11
|
export class RelayStore {
|
|
@@ -20,6 +23,7 @@ export class RelayStore {
|
|
|
20
23
|
host: config.host,
|
|
21
24
|
devices: Array.isArray(config.devices) ? config.devices : [],
|
|
22
25
|
shares: Array.isArray(config.shares) ? config.shares : [],
|
|
26
|
+
contents: Array.isArray(config.contents) ? config.contents : [],
|
|
23
27
|
};
|
|
24
28
|
}
|
|
25
29
|
catch (_a) {
|
|
@@ -39,6 +43,114 @@ export class RelayStore {
|
|
|
39
43
|
var _a;
|
|
40
44
|
return ((_a = this.read().shares) !== null && _a !== void 0 ? _a : []).filter(share => share.expiresAt > now);
|
|
41
45
|
}
|
|
46
|
+
/** Content shared, still on, by its id. */
|
|
47
|
+
content(contentId, now = Date.now()) {
|
|
48
|
+
return this.contents(now).find(content => content.id === contentId);
|
|
49
|
+
}
|
|
50
|
+
/** Content shared, still on, the latest first. */
|
|
51
|
+
contents(now = Date.now()) {
|
|
52
|
+
var _a;
|
|
53
|
+
return ((_a = this.read().contents) !== null && _a !== void 0 ? _a : []).filter(content => RelayStore.live(content, now)).sort((a, b) => b.createdAt - a.createdAt);
|
|
54
|
+
}
|
|
55
|
+
/** The bytes of content shared; undefined when they are gone. */
|
|
56
|
+
contentData(content) {
|
|
57
|
+
try {
|
|
58
|
+
return new Uint8Array(readFileSync(this.contentFile(content.id)));
|
|
59
|
+
}
|
|
60
|
+
catch (_a) {
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Shares content: its bytes kept here, a link for it on the relay of the devices (the default one when there is
|
|
66
|
+
* none), which this ta serve then connects to for any but `self`.
|
|
67
|
+
*/
|
|
68
|
+
async addContent(input, now = Date.now()) {
|
|
69
|
+
var _a, _b, _c;
|
|
70
|
+
const linkKey = randomBytes(32);
|
|
71
|
+
const id = randomBytes(16).toString('base64url');
|
|
72
|
+
const password = input.access === 'password' ? input.password : undefined;
|
|
73
|
+
if (input.access === 'password' && !password) {
|
|
74
|
+
throw new Error('A share with a password needs the password.');
|
|
75
|
+
}
|
|
76
|
+
const people = input.access === 'people' ? await RelayStore.people(input, id) : undefined;
|
|
77
|
+
const key = await RelayContentUtil.contentKey(new Uint8Array(linkKey), id, password);
|
|
78
|
+
const days = input.offline ? Math.min(input.days || RELAY_BLOB_MAX_DAYS, RELAY_BLOB_MAX_DAYS) : input.days;
|
|
79
|
+
const expiresAt = days ? now + days * 24 * 60 * 60 * 1000 : undefined;
|
|
80
|
+
const offline = input.offline && input.access !== 'self' && input.access !== 'people';
|
|
81
|
+
const content = {
|
|
82
|
+
id,
|
|
83
|
+
kind: input.kind,
|
|
84
|
+
title: input.title,
|
|
85
|
+
createdAt: input.createdAt,
|
|
86
|
+
...(input.type ? { type: input.type } : {}),
|
|
87
|
+
access: input.access,
|
|
88
|
+
key: RelayBytes.toBase64(key),
|
|
89
|
+
...(input.access === 'self' || people ? {} : { linkKey: linkKey.toString('base64url') }),
|
|
90
|
+
...(people && input.identity ? { people, owner: input.identity.id } : {}),
|
|
91
|
+
size: input.data.length,
|
|
92
|
+
...(expiresAt ? { expiresAt } : {}),
|
|
93
|
+
...(offline && expiresAt ? { offline: { token: randomBytes(32).toString('base64url'), expiresAt } } : {}),
|
|
94
|
+
};
|
|
95
|
+
mkdirSync(dirname(this.contentFile(id)), { recursive: true, mode: 0o700 });
|
|
96
|
+
writeFileSync(this.contentFile(id), input.data, { mode: 0o600 });
|
|
97
|
+
const before = this.read();
|
|
98
|
+
const url = (_a = before.url) !== null && _a !== void 0 ? _a : RELAY_DEFAULT_URL;
|
|
99
|
+
const host = (_b = before.host) !== null && _b !== void 0 ? _b : { id: RelayStore.id(), secret: randomBytes(32).toString('base64url') };
|
|
100
|
+
this.write({ ...before, url, host, contents: [...((_c = before.contents) !== null && _c !== void 0 ? _c : []), content] });
|
|
101
|
+
return { content, link: this.contentLink(content, { url, host }) };
|
|
102
|
+
}
|
|
103
|
+
/** The link of content shared here. */
|
|
104
|
+
contentLink(content, config = this.read()) {
|
|
105
|
+
var _a;
|
|
106
|
+
var _b, _c;
|
|
107
|
+
return {
|
|
108
|
+
relay: (_b = config.url) !== null && _b !== void 0 ? _b : RELAY_DEFAULT_URL,
|
|
109
|
+
host: (_c = (_a = config.host) === null || _a === void 0 ? void 0 : _a.id) !== null && _c !== void 0 ? _c : '',
|
|
110
|
+
share: content.id,
|
|
111
|
+
key: content.linkKey,
|
|
112
|
+
access: content.access,
|
|
113
|
+
...(content.owner ? { owner: content.owner } : {}),
|
|
114
|
+
offline: !!content.offline,
|
|
115
|
+
kind: content.kind,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/** Stops a share of content: its link no longer works, its bytes are deleted. The share, if there was one. */
|
|
119
|
+
removeContent(contentId) {
|
|
120
|
+
var _a, _b;
|
|
121
|
+
const config = this.read();
|
|
122
|
+
const content = (_a = config.contents) === null || _a === void 0 ? void 0 : _a.find(candidate => candidate.id === contentId);
|
|
123
|
+
if (!content) {
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
this.write({ ...config, contents: (_b = config.contents) === null || _b === void 0 ? void 0 : _b.filter(candidate => candidate.id !== contentId) });
|
|
127
|
+
rmSync(this.contentFile(contentId), { force: true });
|
|
128
|
+
return content;
|
|
129
|
+
}
|
|
130
|
+
/** The key of each Ta friend content is shared with, made with this Ta's identity for this share. */
|
|
131
|
+
static async people(input, id) {
|
|
132
|
+
var _a;
|
|
133
|
+
const { identity } = input;
|
|
134
|
+
const people = (_a = input.people) !== null && _a !== void 0 ? _a : [];
|
|
135
|
+
if (!identity || people.length === 0) {
|
|
136
|
+
throw new Error('A share with Ta friends needs them, and this Ta.');
|
|
137
|
+
}
|
|
138
|
+
return Promise.all(people.map(async (person) => {
|
|
139
|
+
if (!(await RelayIdentityUtil.check(person))) {
|
|
140
|
+
throw new Error(`${person.name} is not a Ta friend whose keys check.`);
|
|
141
|
+
}
|
|
142
|
+
return { id: person.id, name: person.name, key: RelayBytes.toBase64(await RelayContentUtil.peopleKey(identity, person.box, id)) };
|
|
143
|
+
}));
|
|
144
|
+
}
|
|
145
|
+
contentFile(contentId) {
|
|
146
|
+
return join(this.agentDir, 'shares', contentId);
|
|
147
|
+
}
|
|
148
|
+
static live(content, now) {
|
|
149
|
+
return content.expiresAt === undefined || content.expiresAt > now;
|
|
150
|
+
}
|
|
151
|
+
static id() {
|
|
152
|
+
return id();
|
|
153
|
+
}
|
|
42
154
|
/**
|
|
43
155
|
* A link of the package in `root`: the one of before while it lasts, else a new one for RELAY_SHARE_DAYS,
|
|
44
156
|
* on the relay of the devices (the default one when there is none), which this ta serve then connects to.
|
|
@@ -100,6 +212,15 @@ export class RelayStore {
|
|
|
100
212
|
return createHash('sha256').update(secret).digest('base64url');
|
|
101
213
|
}
|
|
102
214
|
write(config) {
|
|
215
|
+
var _a;
|
|
216
|
+
var _b;
|
|
217
|
+
const now = Date.now();
|
|
218
|
+
for (const content of (_b = config.contents) !== null && _b !== void 0 ? _b : []) {
|
|
219
|
+
if (!RelayStore.live(content, now)) {
|
|
220
|
+
rmSync(this.contentFile(content.id), { force: true });
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
config = { ...config, contents: (_a = config.contents) === null || _a === void 0 ? void 0 : _a.filter(content => RelayStore.live(content, now)) };
|
|
103
224
|
mkdirSync(dirname(this.file), { recursive: true });
|
|
104
225
|
const temporary = `${this.file}.${process.pid}.tmp`;
|
|
105
226
|
writeFileSync(temporary, `${JSON.stringify(config, null, 2)}\n`, { mode: 0o600 });
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** The viewer of the relay as `ta relay` serves it: the pages scripts/build-viewer.ts built, next to lib/. */
|
|
2
|
+
export declare namespace RelayViewer {
|
|
3
|
+
/** The page of guests of rooms: a link that invites, opened in a browser. */
|
|
4
|
+
function room(): string;
|
|
5
|
+
function page(): string;
|
|
6
|
+
function frame(): string;
|
|
7
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { fileURLToPath as __cellFileURLToPath } from "node:url";
|
|
2
|
+
import { dirname as __cellDirname } from "node:path";
|
|
3
|
+
const __filename = __cellFileURLToPath(import.meta.url);
|
|
4
|
+
const __dirname = __cellDirname(__filename);
|
|
5
|
+
import { readFileSync } from 'node:fs';
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
/** The viewer of the relay as `ta relay` serves it: the pages scripts/build-viewer.ts built, next to lib/. */
|
|
8
|
+
export var RelayViewer;
|
|
9
|
+
(function (RelayViewer) {
|
|
10
|
+
let pages;
|
|
11
|
+
function read() {
|
|
12
|
+
if (!pages) {
|
|
13
|
+
const dir = join(__dirname, '../../viewer');
|
|
14
|
+
const file = (name) => readFileSync(join(dir, name), 'utf8');
|
|
15
|
+
pages = { page: file('page.html'), frame: file('frame.html'), room: file('room.html') };
|
|
16
|
+
}
|
|
17
|
+
return pages;
|
|
18
|
+
}
|
|
19
|
+
/** The page of guests of rooms: a link that invites, opened in a browser. */
|
|
20
|
+
function room() {
|
|
21
|
+
return read().room;
|
|
22
|
+
}
|
|
23
|
+
RelayViewer.room = room;
|
|
24
|
+
function page() {
|
|
25
|
+
return read().page;
|
|
26
|
+
}
|
|
27
|
+
RelayViewer.page = page;
|
|
28
|
+
function frame() {
|
|
29
|
+
return read().frame;
|
|
30
|
+
}
|
|
31
|
+
RelayViewer.frame = frame;
|
|
32
|
+
})(RelayViewer || (RelayViewer = {}));
|
|
33
|
+
//# sourceMappingURL=relay-viewer.js.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
declare const zh: {
|
|
2
|
+
title: string;
|
|
3
|
+
loading: string;
|
|
4
|
+
conversation: string;
|
|
5
|
+
file: string;
|
|
6
|
+
sharedAt: string;
|
|
7
|
+
messages: string;
|
|
8
|
+
passwordTitle: string;
|
|
9
|
+
passwordHint: string;
|
|
10
|
+
password: string;
|
|
11
|
+
open: string;
|
|
12
|
+
wrong: string;
|
|
13
|
+
busy: string;
|
|
14
|
+
gone: string;
|
|
15
|
+
offline: string;
|
|
16
|
+
self: string;
|
|
17
|
+
people: string;
|
|
18
|
+
invalid: string;
|
|
19
|
+
timeout: string;
|
|
20
|
+
large: string;
|
|
21
|
+
failed: string;
|
|
22
|
+
you: string;
|
|
23
|
+
ta: string;
|
|
24
|
+
outputsOmitted: string;
|
|
25
|
+
imagesOmitted: string;
|
|
26
|
+
redacted: string;
|
|
27
|
+
image: string;
|
|
28
|
+
download: string;
|
|
29
|
+
footer: string;
|
|
30
|
+
agentKind: string;
|
|
31
|
+
agentHint: string;
|
|
32
|
+
copy: string;
|
|
33
|
+
copied: string;
|
|
34
|
+
failedCall: string;
|
|
35
|
+
output: string;
|
|
36
|
+
error: string;
|
|
37
|
+
secure: string;
|
|
38
|
+
run: string;
|
|
39
|
+
read: string;
|
|
40
|
+
write: string;
|
|
41
|
+
edit: string;
|
|
42
|
+
search: string;
|
|
43
|
+
find: string;
|
|
44
|
+
list: string;
|
|
45
|
+
fetch: string;
|
|
46
|
+
webSearch: string;
|
|
47
|
+
script: string;
|
|
48
|
+
use: string;
|
|
49
|
+
};
|
|
50
|
+
export type ViewerText = keyof typeof zh;
|
|
51
|
+
export declare namespace ViewerI18n {
|
|
52
|
+
const chinese: boolean;
|
|
53
|
+
function t(id: ViewerText, values?: Record<string, string | number>): string;
|
|
54
|
+
function date(at: number): string;
|
|
55
|
+
}
|
|
56
|
+
export {};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
const zh = {
|
|
2
|
+
title: 'Ta 分享',
|
|
3
|
+
loading: '正在打开…',
|
|
4
|
+
conversation: '对话',
|
|
5
|
+
file: '文件',
|
|
6
|
+
sharedAt: '分享于 {date}',
|
|
7
|
+
messages: '{n} 条消息',
|
|
8
|
+
passwordTitle: '这个分享需要口令',
|
|
9
|
+
passwordHint: '口令不在链接里,请向分享的人要。',
|
|
10
|
+
password: '口令',
|
|
11
|
+
open: '打开',
|
|
12
|
+
wrong: '口令不对,再试一次。',
|
|
13
|
+
busy: '口令错得太多了,请过几分钟再试。',
|
|
14
|
+
gone: '这个链接已经失效:分享已停止或已过期。',
|
|
15
|
+
offline: '分享的人的电脑现在没有运行 Ta,请稍后再试。',
|
|
16
|
+
self: '这是仅自己可见的分享,只有分享的人能在自己的 Ta 里打开。',
|
|
17
|
+
people: '这条链接只给指定的 Ta 好友:请在你自己的 Ta 应用里扫码或粘贴打开。',
|
|
18
|
+
invalid: '这不是一个完整的 Ta 分享链接,请检查是否复制完整。',
|
|
19
|
+
timeout: '等了太久还没收到,请稍后再试。',
|
|
20
|
+
large: '内容太大,打不开。',
|
|
21
|
+
failed: '打不开这个分享。',
|
|
22
|
+
you: '你',
|
|
23
|
+
ta: 'Ta',
|
|
24
|
+
outputsOmitted: '分享时没有附上工具的输出。',
|
|
25
|
+
imagesOmitted: '分享时去掉了 {n} 张图片。',
|
|
26
|
+
redacted: '分享时隐去了 {n} 处疑似密钥。',
|
|
27
|
+
image: '[图片]',
|
|
28
|
+
download: '下载 {name}',
|
|
29
|
+
footer: '在 Ta 应用里扫码或粘贴这个链接,可以把它导入为你自己的对话接着聊。',
|
|
30
|
+
agentKind: '智能体名片',
|
|
31
|
+
agentHint: '在 Ta 里扫码或粘贴这个链接,就能把它加为你的智能体;加进来时,它会先看看你的项目,把职责调整得贴合你那边的情况。',
|
|
32
|
+
copy: '复制链接',
|
|
33
|
+
copied: '已复制',
|
|
34
|
+
failedCall: '失败',
|
|
35
|
+
output: '输出',
|
|
36
|
+
error: '出错了',
|
|
37
|
+
secure: '端到端加密:中继看不到内容',
|
|
38
|
+
run: '运行',
|
|
39
|
+
read: '读取',
|
|
40
|
+
write: '写入',
|
|
41
|
+
edit: '编辑',
|
|
42
|
+
search: '搜索',
|
|
43
|
+
find: '查找',
|
|
44
|
+
list: '列出',
|
|
45
|
+
fetch: '打开网页',
|
|
46
|
+
webSearch: '搜索网页',
|
|
47
|
+
script: '运行脚本',
|
|
48
|
+
use: '使用 {name}',
|
|
49
|
+
};
|
|
50
|
+
const en = {
|
|
51
|
+
title: 'Shared from Ta',
|
|
52
|
+
loading: 'Opening…',
|
|
53
|
+
conversation: 'Conversation',
|
|
54
|
+
file: 'File',
|
|
55
|
+
sharedAt: 'Shared {date}',
|
|
56
|
+
messages: '{n} messages',
|
|
57
|
+
passwordTitle: 'This share needs a password',
|
|
58
|
+
passwordHint: 'The password is not in the link: ask the one who shared it.',
|
|
59
|
+
password: 'Password',
|
|
60
|
+
open: 'Open',
|
|
61
|
+
wrong: 'That password is wrong. Try again.',
|
|
62
|
+
busy: 'Too many wrong passwords. Try again in a few minutes.',
|
|
63
|
+
gone: 'This link no longer works: the share was stopped or ran out.',
|
|
64
|
+
offline: 'The computer that shared it is not running Ta now. Try again later.',
|
|
65
|
+
self: 'Only the one who shared this opens it, in their own Ta.',
|
|
66
|
+
people: 'This link is for chosen Ta friends only: scan or paste it in your own Ta app to open it.',
|
|
67
|
+
invalid: 'This is not a whole link of Ta: check that it was copied in full.',
|
|
68
|
+
timeout: 'It took too long to come. Try again later.',
|
|
69
|
+
large: 'It is too large to open.',
|
|
70
|
+
failed: 'This share cannot be opened.',
|
|
71
|
+
you: 'You',
|
|
72
|
+
ta: 'Ta',
|
|
73
|
+
outputsOmitted: 'The outputs of the tools were not shared.',
|
|
74
|
+
imagesOmitted: '{n} images were left out when it was shared.',
|
|
75
|
+
redacted: '{n} things that looked like secrets were taken out.',
|
|
76
|
+
image: '[image]',
|
|
77
|
+
download: 'Download {name}',
|
|
78
|
+
footer: 'Scan or paste this link in the Ta app to import it as a conversation of your own and go on.',
|
|
79
|
+
agentKind: "An agent's card",
|
|
80
|
+
agentHint: 'Scan or paste this link in Ta to add it as an agent of yours: as it joins, it looks at your project first and fits its role to it.',
|
|
81
|
+
copy: 'Copy link',
|
|
82
|
+
copied: 'Copied',
|
|
83
|
+
failedCall: 'failed',
|
|
84
|
+
output: 'Output',
|
|
85
|
+
error: 'Error',
|
|
86
|
+
secure: 'End-to-end encrypted: the relay cannot read it',
|
|
87
|
+
run: 'Run',
|
|
88
|
+
read: 'Read',
|
|
89
|
+
write: 'Write',
|
|
90
|
+
edit: 'Edit',
|
|
91
|
+
search: 'Search',
|
|
92
|
+
find: 'Find',
|
|
93
|
+
list: 'List',
|
|
94
|
+
fetch: 'Open',
|
|
95
|
+
webSearch: 'Search the web',
|
|
96
|
+
script: 'Run a script',
|
|
97
|
+
use: 'Use {name}',
|
|
98
|
+
};
|
|
99
|
+
export var ViewerI18n;
|
|
100
|
+
(function (ViewerI18n) {
|
|
101
|
+
ViewerI18n.chinese = typeof navigator !== 'undefined' && /^zh\b/i.test(navigator.language);
|
|
102
|
+
function t(id, values = {}) {
|
|
103
|
+
return (ViewerI18n.chinese ? zh : en)[id].replace(/\{(\w+)\}/g, (_, name) => { var _a; return String((_a = values[name]) !== null && _a !== void 0 ? _a : ''); });
|
|
104
|
+
}
|
|
105
|
+
ViewerI18n.t = t;
|
|
106
|
+
function date(at) {
|
|
107
|
+
return new Date(at).toLocaleString(ViewerI18n.chinese ? 'zh-CN' : undefined, {
|
|
108
|
+
year: 'numeric',
|
|
109
|
+
month: 'short',
|
|
110
|
+
day: 'numeric',
|
|
111
|
+
hour: '2-digit',
|
|
112
|
+
minute: '2-digit',
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
ViewerI18n.date = date;
|
|
116
|
+
})(ViewerI18n || (ViewerI18n = {}));
|
|
117
|
+
//# sourceMappingURL=viewer-i18n.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Markdown of a reply, drawn as DOM: what it says is only ever text of nodes, never HTML, and links go only to the web. */
|
|
2
|
+
export declare namespace ViewerMarkdown {
|
|
3
|
+
function render(text: string): DocumentFragment;
|
|
4
|
+
/** Code, links, bold, italic and struck text of a line, into `parent`. */
|
|
5
|
+
function inline(parent: HTMLElement, text: string): HTMLElement;
|
|
6
|
+
function el(tag: string, text?: string): HTMLElement;
|
|
7
|
+
}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/** Markdown of a reply, drawn as DOM: what it says is only ever text of nodes, never HTML, and links go only to the web. */
|
|
2
|
+
export var ViewerMarkdown;
|
|
3
|
+
(function (ViewerMarkdown) {
|
|
4
|
+
function render(text) {
|
|
5
|
+
const fragment = document.createDocumentFragment();
|
|
6
|
+
const lines = text.replace(/\r\n?/g, '\n').split('\n');
|
|
7
|
+
let index = 0;
|
|
8
|
+
while (index < lines.length) {
|
|
9
|
+
const line = lines[index];
|
|
10
|
+
const fence = /^(\s*)(`{3,}|~{3,})\s*([\w+-]*)/.exec(line);
|
|
11
|
+
if (fence) {
|
|
12
|
+
const body = [];
|
|
13
|
+
index++;
|
|
14
|
+
while (index < lines.length && !lines[index].trimStart().startsWith(fence[2])) {
|
|
15
|
+
body.push(lines[index]);
|
|
16
|
+
index++;
|
|
17
|
+
}
|
|
18
|
+
index++;
|
|
19
|
+
const pre = el('pre');
|
|
20
|
+
const code = el('code', body.join('\n'));
|
|
21
|
+
if (fence[3]) {
|
|
22
|
+
code.dataset.lang = fence[3];
|
|
23
|
+
}
|
|
24
|
+
pre.append(code);
|
|
25
|
+
fragment.append(pre);
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (!line.trim()) {
|
|
29
|
+
index++;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
const heading = /^(#{1,6})\s+(.*)$/.exec(line);
|
|
33
|
+
if (heading) {
|
|
34
|
+
fragment.append(inline(el(`h${Math.min(heading[1].length + 1, 6)}`), heading[2].replace(/\s+#+\s*$/, '')));
|
|
35
|
+
index++;
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (/^\s*([-*_])(\s*\1){2,}\s*$/.test(line)) {
|
|
39
|
+
fragment.append(el('hr'));
|
|
40
|
+
index++;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (/^\s*>/.test(line)) {
|
|
44
|
+
const quoted = [];
|
|
45
|
+
while (index < lines.length && /^\s*>/.test(lines[index])) {
|
|
46
|
+
quoted.push(lines[index].replace(/^\s*>\s?/, ''));
|
|
47
|
+
index++;
|
|
48
|
+
}
|
|
49
|
+
const quote = el('blockquote');
|
|
50
|
+
quote.append(render(quoted.join('\n')));
|
|
51
|
+
fragment.append(quote);
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (isTableStart(lines, index)) {
|
|
55
|
+
const rows = [];
|
|
56
|
+
rows.push(cells(lines[index]));
|
|
57
|
+
index += 2;
|
|
58
|
+
while (index < lines.length && lines[index].includes('|') && lines[index].trim()) {
|
|
59
|
+
rows.push(cells(lines[index]));
|
|
60
|
+
index++;
|
|
61
|
+
}
|
|
62
|
+
fragment.append(table(rows));
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
const item = /^(\s*)([-*+]|\d+[.)])\s+(.*)$/.exec(line);
|
|
66
|
+
if (item) {
|
|
67
|
+
const ordered = /\d/.test(item[2]);
|
|
68
|
+
const list = el(ordered ? 'ol' : 'ul');
|
|
69
|
+
while (index < lines.length) {
|
|
70
|
+
const match = /^(\s*)([-*+]|\d+[.)])\s+(.*)$/.exec(lines[index]);
|
|
71
|
+
if (!match || /\d/.test(match[2]) !== ordered) {
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
const body = [match[3]];
|
|
75
|
+
index++;
|
|
76
|
+
// Its own lines, indented under it: more of it, or a nested list.
|
|
77
|
+
const nested = [];
|
|
78
|
+
while (index < lines.length && lines[index].trim() && lines[index].length - lines[index].trimStart().length > match[1].length) {
|
|
79
|
+
nested.push(lines[index].slice(Math.min(match[1].length + 2, lines[index].length - lines[index].trimStart().length)));
|
|
80
|
+
index++;
|
|
81
|
+
}
|
|
82
|
+
const li = el('li');
|
|
83
|
+
const task = /^\[([ xX])\]\s+(.*)$/.exec(body[0]);
|
|
84
|
+
if (task) {
|
|
85
|
+
const box = el('input');
|
|
86
|
+
box.type = 'checkbox';
|
|
87
|
+
box.disabled = true;
|
|
88
|
+
box.checked = task[1] !== ' ';
|
|
89
|
+
li.append(box, ' ');
|
|
90
|
+
body[0] = task[2];
|
|
91
|
+
}
|
|
92
|
+
inline(li, body.join(' '));
|
|
93
|
+
if (nested.length) {
|
|
94
|
+
li.append(render(nested.join('\n')));
|
|
95
|
+
}
|
|
96
|
+
list.append(li);
|
|
97
|
+
}
|
|
98
|
+
fragment.append(list);
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
const paragraph = [];
|
|
102
|
+
while (index < lines.length &&
|
|
103
|
+
lines[index].trim() &&
|
|
104
|
+
!/^(\s*)(`{3,}|~{3,})/.test(lines[index]) &&
|
|
105
|
+
!/^#{1,6}\s/.test(lines[index]) &&
|
|
106
|
+
!/^\s*>/.test(lines[index]) &&
|
|
107
|
+
!/^(\s*)([-*+]|\d+[.)])\s+/.test(lines[index]) &&
|
|
108
|
+
!isTableStart(lines, index)) {
|
|
109
|
+
paragraph.push(lines[index]);
|
|
110
|
+
index++;
|
|
111
|
+
}
|
|
112
|
+
const p = el('p');
|
|
113
|
+
paragraph.forEach((part, at) => {
|
|
114
|
+
if (at > 0) {
|
|
115
|
+
p.append(/ {2}$|\\$/.test(paragraph[at - 1]) ? el('br') : ' ');
|
|
116
|
+
}
|
|
117
|
+
inline(p, part.replace(/ {2}$|\\$/, ''));
|
|
118
|
+
});
|
|
119
|
+
fragment.append(p);
|
|
120
|
+
}
|
|
121
|
+
return fragment;
|
|
122
|
+
}
|
|
123
|
+
ViewerMarkdown.render = render;
|
|
124
|
+
/** Code, links, bold, italic and struck text of a line, into `parent`. */
|
|
125
|
+
function inline(parent, text) {
|
|
126
|
+
var _a, _b, _c;
|
|
127
|
+
const pattern = /(`+)([^`]|[^`][\s\S]*?[^`])\1|!?\[([^\]]*)\]\(([^)\s]+)(?:\s+"[^"]*")?\)|(https?:\/\/[^\s<>()]+[^\s<>().,;:!?'"])|\*\*([^*]+)\*\*|__([^_]+)__|~~([^~]+)~~|\*([^*\s][^*]*)\*|(?<![\w])_([^_\s][^_]*)_(?![\w])/g;
|
|
128
|
+
let at = 0;
|
|
129
|
+
for (const match of text.matchAll(pattern)) {
|
|
130
|
+
parent.append(text.slice(at, match.index));
|
|
131
|
+
at = ((_a = match.index) !== null && _a !== void 0 ? _a : 0) + match[0].length;
|
|
132
|
+
if (match[1]) {
|
|
133
|
+
parent.append(el('code', match[2]));
|
|
134
|
+
}
|
|
135
|
+
else if (match[4] !== undefined) {
|
|
136
|
+
parent.append(link(match[3] || match[4], match[4]));
|
|
137
|
+
}
|
|
138
|
+
else if (match[5]) {
|
|
139
|
+
parent.append(link(match[5], match[5]));
|
|
140
|
+
}
|
|
141
|
+
else if (match[6] || match[7]) {
|
|
142
|
+
parent.append(inline(el('strong'), (_b = match[6]) !== null && _b !== void 0 ? _b : match[7]));
|
|
143
|
+
}
|
|
144
|
+
else if (match[8]) {
|
|
145
|
+
parent.append(inline(el('del'), match[8]));
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
parent.append(inline(el('em'), (_c = match[9]) !== null && _c !== void 0 ? _c : match[10]));
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
parent.append(text.slice(at));
|
|
152
|
+
return parent;
|
|
153
|
+
}
|
|
154
|
+
ViewerMarkdown.inline = inline;
|
|
155
|
+
function link(text, href) {
|
|
156
|
+
if (!/^https?:\/\//i.test(href)) {
|
|
157
|
+
return document.createTextNode(text);
|
|
158
|
+
}
|
|
159
|
+
const a = el('a', text);
|
|
160
|
+
a.href = href;
|
|
161
|
+
a.target = '_blank';
|
|
162
|
+
a.rel = 'noopener noreferrer nofollow';
|
|
163
|
+
return a;
|
|
164
|
+
}
|
|
165
|
+
function isTableStart(lines, index) {
|
|
166
|
+
return lines[index].includes('|') && index + 1 < lines.length && /^\s*\|?\s*:?-{2,}:?\s*(\|\s*:?-{2,}:?\s*)*\|?\s*$/.test(lines[index + 1]);
|
|
167
|
+
}
|
|
168
|
+
function cells(line) {
|
|
169
|
+
return line
|
|
170
|
+
.trim()
|
|
171
|
+
.replace(/^\||\|$/g, '')
|
|
172
|
+
.split(/(?<!\\)\|/)
|
|
173
|
+
.map(cell => cell.trim().replace(/\\\|/g, '|'));
|
|
174
|
+
}
|
|
175
|
+
function table(rows) {
|
|
176
|
+
const wrap = el('div');
|
|
177
|
+
wrap.className = 'table';
|
|
178
|
+
const tableEl = el('table');
|
|
179
|
+
rows.forEach((row, at) => {
|
|
180
|
+
const tr = el('tr');
|
|
181
|
+
for (const cell of row) {
|
|
182
|
+
tr.append(inline(el(at === 0 ? 'th' : 'td'), cell));
|
|
183
|
+
}
|
|
184
|
+
tableEl.append(tr);
|
|
185
|
+
});
|
|
186
|
+
wrap.append(tableEl);
|
|
187
|
+
return wrap;
|
|
188
|
+
}
|
|
189
|
+
function el(tag, text) {
|
|
190
|
+
const node = document.createElement(tag);
|
|
191
|
+
if (text !== undefined) {
|
|
192
|
+
node.textContent = text;
|
|
193
|
+
}
|
|
194
|
+
return node;
|
|
195
|
+
}
|
|
196
|
+
ViewerMarkdown.el = el;
|
|
197
|
+
})(ViewerMarkdown || (ViewerMarkdown = {}));
|
|
198
|
+
//# sourceMappingURL=viewer-markdown.js.map
|