@celljs/ta-host 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/node/app-commands.d.ts +111 -0
- package/esm/node/app-commands.js +646 -0
- package/esm/node/credentials.d.ts +12 -0
- package/esm/node/credentials.js +35 -0
- package/esm/node/delegate-extension.d.ts +11 -0
- package/esm/node/delegate-extension.js +33 -0
- package/esm/node/directory-relocator.d.ts +49 -0
- package/esm/node/directory-relocator.js +267 -0
- package/esm/node/extension-providers.d.ts +16 -1
- package/esm/node/extension-providers.js +23 -3
- package/esm/node/index.d.ts +8 -0
- package/esm/node/index.js +8 -0
- package/esm/node/keep-awake.d.ts +8 -1
- package/esm/node/keep-awake.js +24 -3
- package/esm/node/message-page.d.ts +6 -1
- package/esm/node/message-page.js +50 -2
- package/esm/node/package-hosts.d.ts +8 -0
- package/esm/node/package-hosts.js +41 -0
- package/esm/node/package-webhooks.d.ts +26 -0
- package/esm/node/package-webhooks.js +101 -0
- package/esm/node/page-book.d.ts +48 -0
- package/esm/node/page-book.js +117 -0
- package/esm/node/relay-bridge.d.ts +2 -0
- package/esm/node/relay-bridge.js +35 -1
- package/esm/node/rooms-bridge.d.ts +13 -1
- package/esm/node/rooms-bridge.js +29 -0
- package/esm/node/screen-share/desktop-picture.d.ts +51 -0
- package/esm/node/screen-share/desktop-picture.js +133 -0
- package/esm/node/screen-share/desktop-session.d.ts +128 -0
- package/esm/node/screen-share/desktop-session.js +437 -0
- package/esm/node/screen-share/desktop-targets.d.ts +24 -0
- package/esm/node/screen-share/desktop-targets.js +80 -0
- package/esm/node/screen-share/desktop-viewer.d.ts +146 -0
- package/esm/node/screen-share/desktop-viewer.js +339 -0
- package/esm/node/screen-share/index.d.ts +8 -0
- package/esm/node/screen-share/index.js +9 -0
- package/esm/node/screen-share/rfb-client.d.ts +54 -0
- package/esm/node/screen-share/rfb-client.js +179 -0
- package/esm/node/screen-share/rfb-des.d.ts +11 -0
- package/esm/node/screen-share/rfb-des.js +143 -0
- package/esm/node/screen-share/rfb-encodings.d.ts +71 -0
- package/esm/node/screen-share/rfb-encodings.js +288 -0
- package/esm/node/screen-share/rfb-framebuffer.d.ts +16 -0
- package/esm/node/screen-share/rfb-framebuffer.js +53 -0
- package/esm/node/screen-share/rfb-protocol.d.ts +90 -0
- package/esm/node/screen-share/rfb-protocol.js +36 -0
- package/esm/node/screen-share/rfb-reader.d.ts +34 -0
- package/esm/node/screen-share/rfb-reader.js +110 -0
- package/esm/node/screen-share/rfb-security.d.ts +30 -0
- package/esm/node/screen-share/rfb-security.js +136 -0
- package/esm/node/screen-share/rfb-test-server.d.ts +37 -0
- package/esm/node/screen-share/rfb-test-server.js +116 -0
- package/esm/node/screen-share/screen-share-server-impl.d.ts +37 -0
- package/esm/node/screen-share/screen-share-server-impl.js +76 -0
- package/esm/node/screen-share/screen-shares.d.ts +123 -0
- package/esm/node/screen-share/screen-shares.js +463 -0
- package/esm/node/session-info-util.d.ts +10 -9
- package/esm/node/session-info-util.js +16 -68
- package/esm/node/settings-store.d.ts +1 -1
- package/esm/node/settings-store.js +7 -4
- package/esm/node/sign-in/access-store.d.ts +1 -1
- package/esm/node/sign-in/access-store.js +4 -1
- package/esm/node/sign-in/index.d.ts +2 -0
- package/esm/node/sign-in/index.js +2 -0
- package/esm/node/sign-in/polled-sign-in.d.ts +50 -0
- package/esm/node/sign-in/polled-sign-in.js +83 -0
- package/esm/node/sign-in/sign-in-devices.d.ts +55 -0
- package/esm/node/sign-in/sign-in-devices.js +113 -0
- package/esm/node/sign-in/sign-in-flow.d.ts +38 -4
- package/esm/node/sign-in/sign-in-flow.js +79 -4
- package/esm/node/sign-in/sign-in-pages.d.ts +8 -0
- package/esm/node/sign-in/sign-in-pages.js +137 -8
- package/esm/node/sign-in/sign-in-provider.d.ts +6 -0
- package/esm/node/sign-in/sign-in-provider.js +15 -0
- package/esm/node/sources-extension.d.ts +10 -0
- package/esm/node/sources-extension.js +18 -0
- package/esm/node/ta-server-impl.d.ts +5 -1
- package/esm/node/ta-server-impl.js +25 -3
- package/esm/node/ta-session-factory.d.ts +13 -1
- package/esm/node/ta-session-factory.js +41 -4
- package/esm/node/ta-session.d.ts +2 -0
- package/esm/node/ta-session.js +1 -0
- package/esm/node/team/team-calls.js +49 -0
- package/esm/node/voice-bridge.d.ts +70 -0
- package/esm/node/voice-bridge.js +280 -0
- package/esm/node/voices-file.d.ts +38 -0
- package/esm/node/voices-file.js +100 -0
- package/esm/node/working-directory.d.ts +8 -2
- package/esm/node/working-directory.js +7 -0
- package/lib/node/app-commands.d.ts +112 -0
- package/lib/node/app-commands.js +650 -0
- package/lib/node/credentials.d.ts +13 -0
- package/lib/node/credentials.js +38 -0
- package/lib/node/delegate-extension.d.ts +12 -0
- package/lib/node/delegate-extension.js +37 -0
- package/lib/node/directory-relocator.d.ts +50 -0
- package/lib/node/directory-relocator.js +270 -0
- package/lib/node/extension-providers.d.ts +16 -1
- package/lib/node/extension-providers.js +23 -3
- package/lib/node/index.d.ts +8 -0
- package/lib/node/index.js +8 -0
- package/lib/node/keep-awake.d.ts +8 -1
- package/lib/node/keep-awake.js +24 -3
- package/lib/node/message-page.d.ts +6 -1
- package/lib/node/message-page.js +50 -2
- package/lib/node/package-hosts.d.ts +8 -0
- package/lib/node/package-hosts.js +41 -0
- package/lib/node/package-webhooks.d.ts +27 -0
- package/lib/node/package-webhooks.js +104 -0
- package/lib/node/page-book.d.ts +49 -0
- package/lib/node/page-book.js +120 -0
- package/lib/node/relay-bridge.d.ts +2 -0
- package/lib/node/relay-bridge.js +34 -0
- package/lib/node/rooms-bridge.d.ts +13 -1
- package/lib/node/rooms-bridge.js +29 -0
- package/lib/node/screen-share/desktop-picture.d.ts +52 -0
- package/lib/node/screen-share/desktop-picture.js +136 -0
- package/lib/node/screen-share/desktop-session.d.ts +129 -0
- package/lib/node/screen-share/desktop-session.js +442 -0
- package/lib/node/screen-share/desktop-targets.d.ts +25 -0
- package/lib/node/screen-share/desktop-targets.js +84 -0
- package/lib/node/screen-share/desktop-viewer.d.ts +147 -0
- package/lib/node/screen-share/desktop-viewer.js +343 -0
- package/lib/node/screen-share/index.d.ts +9 -0
- package/lib/node/screen-share/index.js +25 -0
- package/lib/node/screen-share/rfb-client.d.ts +55 -0
- package/lib/node/screen-share/rfb-client.js +183 -0
- package/lib/node/screen-share/rfb-des.d.ts +12 -0
- package/lib/node/screen-share/rfb-des.js +146 -0
- package/lib/node/screen-share/rfb-encodings.d.ts +72 -0
- package/lib/node/screen-share/rfb-encodings.js +295 -0
- package/lib/node/screen-share/rfb-framebuffer.d.ts +17 -0
- package/lib/node/screen-share/rfb-framebuffer.js +57 -0
- package/lib/node/screen-share/rfb-protocol.d.ts +91 -0
- package/lib/node/screen-share/rfb-protocol.js +39 -0
- package/lib/node/screen-share/rfb-reader.d.ts +35 -0
- package/lib/node/screen-share/rfb-reader.js +115 -0
- package/lib/node/screen-share/rfb-security.d.ts +31 -0
- package/lib/node/screen-share/rfb-security.js +141 -0
- package/lib/node/screen-share/rfb-test-server.d.ts +38 -0
- package/lib/node/screen-share/rfb-test-server.js +120 -0
- package/lib/node/screen-share/screen-share-server-impl.d.ts +38 -0
- package/lib/node/screen-share/screen-share-server-impl.js +79 -0
- package/lib/node/screen-share/screen-shares.d.ts +124 -0
- package/lib/node/screen-share/screen-shares.js +464 -0
- package/lib/node/session-info-util.d.ts +10 -9
- package/lib/node/session-info-util.js +15 -67
- package/lib/node/settings-store.d.ts +1 -1
- package/lib/node/settings-store.js +6 -3
- package/lib/node/sign-in/access-store.d.ts +1 -1
- package/lib/node/sign-in/access-store.js +4 -1
- package/lib/node/sign-in/index.d.ts +2 -0
- package/lib/node/sign-in/index.js +2 -0
- package/lib/node/sign-in/polled-sign-in.d.ts +51 -0
- package/lib/node/sign-in/polled-sign-in.js +87 -0
- package/lib/node/sign-in/sign-in-devices.d.ts +56 -0
- package/lib/node/sign-in/sign-in-devices.js +117 -0
- package/lib/node/sign-in/sign-in-flow.d.ts +38 -4
- package/lib/node/sign-in/sign-in-flow.js +80 -5
- package/lib/node/sign-in/sign-in-pages.d.ts +8 -0
- package/lib/node/sign-in/sign-in-pages.js +136 -7
- package/lib/node/sign-in/sign-in-provider.d.ts +6 -0
- package/lib/node/sign-in/sign-in-provider.js +15 -0
- package/lib/node/sources-extension.d.ts +11 -0
- package/lib/node/sources-extension.js +22 -0
- package/lib/node/ta-server-impl.d.ts +5 -1
- package/lib/node/ta-server-impl.js +24 -2
- package/lib/node/ta-session-factory.d.ts +13 -1
- package/lib/node/ta-session-factory.js +40 -3
- package/lib/node/ta-session.d.ts +2 -0
- package/lib/node/ta-session.js +1 -0
- package/lib/node/team/team-calls.js +49 -0
- package/lib/node/voice-bridge.d.ts +71 -0
- package/lib/node/voice-bridge.js +281 -0
- package/lib/node/voices-file.d.ts +39 -0
- package/lib/node/voices-file.js +104 -0
- package/lib/node/working-directory.d.ts +8 -2
- package/lib/node/working-directory.js +7 -0
- package/package.json +14 -10
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { TaConversation, TaMessage, TaMessagePage } from '@celljs/ta-protocol';
|
|
1
|
+
import type { TaConversation, TaMessage, TaMessagePage, TaTurnHead } from '@celljs/ta-protocol';
|
|
2
2
|
/**
|
|
3
3
|
* The parts of a long conversation a client loads one at a time, the latest first: about so many bytes
|
|
4
4
|
* of JSON each, as the client gets them.
|
|
@@ -10,6 +10,11 @@ export declare namespace MessagePage {
|
|
|
10
10
|
* asked for their turn if that takes no more than twice the budget, so that a turn shows whole.
|
|
11
11
|
*/
|
|
12
12
|
function start(messages: readonly TaMessage[], end: number, budget: number): number;
|
|
13
|
+
/**
|
|
14
|
+
* When the messages from `from` start in the middle of a turn (the first of the user or the agent among them
|
|
15
|
+
* is a step of it): the message of the user that asked for the turn.
|
|
16
|
+
*/
|
|
17
|
+
function head(messages: readonly TaMessage[], from: number): TaTurnHead | undefined;
|
|
13
18
|
/** The latest part of a conversation, or all of it without a budget. */
|
|
14
19
|
function recent(conversation: TaConversation, budget: number | undefined): TaConversation;
|
|
15
20
|
/** The part before message `before`, found again by its timestamp if messages came or went before it. */
|
package/esm/node/message-page.js
CHANGED
|
@@ -42,13 +42,60 @@ export var MessagePage;
|
|
|
42
42
|
return start;
|
|
43
43
|
}
|
|
44
44
|
MessagePage.start = start;
|
|
45
|
+
/**
|
|
46
|
+
* A message of the user that the agent was given on the way, after the result of a tool it was written before:
|
|
47
|
+
* a step of the turn, not the start of another (as the web page reads it).
|
|
48
|
+
*/
|
|
49
|
+
function steered(messages, index) {
|
|
50
|
+
var _a;
|
|
51
|
+
if (role(messages[index]) !== 'user') {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
for (let before = index - 1; before >= 0; before--) {
|
|
55
|
+
const was = (_a = role(messages[before])) !== null && _a !== void 0 ? _a : '';
|
|
56
|
+
if (was === 'user') {
|
|
57
|
+
return steered(messages, before);
|
|
58
|
+
}
|
|
59
|
+
if (TURN_ROLES.has(was)) {
|
|
60
|
+
const at = timestamp(messages[index]);
|
|
61
|
+
const came = timestamp(messages[before]);
|
|
62
|
+
return was === 'toolResult' && at !== undefined && came !== undefined && at < came;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* When the messages from `from` start in the middle of a turn (the first of the user or the agent among them
|
|
69
|
+
* is a step of it): the message of the user that asked for the turn.
|
|
70
|
+
*/
|
|
71
|
+
function head(messages, from) {
|
|
72
|
+
var _a;
|
|
73
|
+
let first = from;
|
|
74
|
+
while (first < messages.length && role(messages[first]) !== 'user' && !TURN_ROLES.has((_a = role(messages[first])) !== null && _a !== void 0 ? _a : '')) {
|
|
75
|
+
first++;
|
|
76
|
+
}
|
|
77
|
+
if (from <= 0 || first >= messages.length || (role(messages[first]) === 'user' && !steered(messages, first))) {
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
for (let index = from - 1; index >= 0; index--) {
|
|
81
|
+
if (role(messages[index]) === 'user' && !steered(messages, index)) {
|
|
82
|
+
return { index, message: messages[index] };
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
MessagePage.head = head;
|
|
45
88
|
/** The latest part of a conversation, or all of it without a budget. */
|
|
46
89
|
function recent(conversation, budget) {
|
|
47
90
|
if (!budget || budget <= 0) {
|
|
48
91
|
return conversation;
|
|
49
92
|
}
|
|
50
93
|
const from = start(conversation.messages, conversation.messages.length, budget);
|
|
51
|
-
|
|
94
|
+
if (from === 0) {
|
|
95
|
+
return conversation;
|
|
96
|
+
}
|
|
97
|
+
const turn = head(conversation.messages, from);
|
|
98
|
+
return { ...conversation, messages: conversation.messages.slice(from), start: from, ...(turn ? { head: turn } : {}) };
|
|
52
99
|
}
|
|
53
100
|
MessagePage.recent = recent;
|
|
54
101
|
/** The part before message `before`, found again by its timestamp if messages came or went before it. */
|
|
@@ -64,7 +111,8 @@ export var MessagePage;
|
|
|
64
111
|
}
|
|
65
112
|
}
|
|
66
113
|
const from = start(messages, end, Math.max(1, budget));
|
|
67
|
-
|
|
114
|
+
const turn = head(messages, from);
|
|
115
|
+
return { messages: messages.slice(from, end), start: from, found: true, ...(turn ? { head: turn } : {}) };
|
|
68
116
|
}
|
|
69
117
|
MessagePage.before = before;
|
|
70
118
|
})(MessagePage || (MessagePage = {}));
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { type CodingAgentOptions } from '@celljs/ai-coding-agent';
|
|
2
2
|
import { type Application, ApplicationLifecycle } from '@celljs/core';
|
|
3
3
|
import { type TaExtensionHost, type TaHostAnswer, type TaHostSessionEvent, TaPackageServer, type TaPackageService, TaServer } from '@celljs/ta-protocol';
|
|
4
|
+
import { TaAppCommands } from './app-commands.js';
|
|
5
|
+
import { TaCredentials } from './credentials.js';
|
|
4
6
|
import { ExtensionDataStore } from './extension-data.js';
|
|
5
7
|
import { TaPresenceBook, TaSessionRegistry } from './host-protocol.js';
|
|
8
|
+
import { TaPageBook } from './page-book.js';
|
|
6
9
|
import { type RelayBridge } from './relay-bridge.js';
|
|
7
10
|
import { PiDirectories } from './remote/remote-protocol.js';
|
|
8
11
|
import { type RoomsBridge } from './rooms-bridge.js';
|
|
9
12
|
import { TaSettingsStore } from './settings-store.js';
|
|
10
13
|
import { TaHostTeamProvider } from './team/team-protocol.js';
|
|
14
|
+
import { type VoiceBridge } from './voice-bridge.js';
|
|
11
15
|
export declare const PackageHosts: unique symbol;
|
|
12
16
|
/**
|
|
13
17
|
* The server side of built-in packages under `ta serve`: the module a package names in `pi.host` of its
|
|
@@ -54,9 +58,13 @@ export declare class PackageHostsImpl implements PackageHosts, ApplicationLifecy
|
|
|
54
58
|
protected readonly packages: TaPackageServer;
|
|
55
59
|
protected readonly relay: RelayBridge;
|
|
56
60
|
protected readonly roomsBridge: RoomsBridge;
|
|
61
|
+
protected readonly voiceBridge: VoiceBridge;
|
|
62
|
+
protected readonly credentials: TaCredentials;
|
|
57
63
|
protected readonly settings: TaSettingsStore;
|
|
58
64
|
protected readonly sessions: TaSessionRegistry;
|
|
59
65
|
protected readonly presenceBook: TaPresenceBook;
|
|
66
|
+
protected readonly appCommands: TaAppCommands;
|
|
67
|
+
protected readonly pageBook: TaPageBook;
|
|
60
68
|
protected readonly teamProvider: TaHostTeamProvider;
|
|
61
69
|
protected readonly running: Map<string, Running>;
|
|
62
70
|
protected extensionHost?: TaExtensionHost;
|
|
@@ -16,14 +16,19 @@ import { ApplicationLifecycle, Autowired, Component, Value } from '@celljs/core'
|
|
|
16
16
|
import { TaBrand } from '@celljs/ta-harness/lib/node/ta-brand';
|
|
17
17
|
import { TaPackages } from '@celljs/ta-harness/lib/node/ta-packages';
|
|
18
18
|
import { TaMessageSource, TaPackageServer, TaServer, } from '@celljs/ta-protocol';
|
|
19
|
+
import { TaAppCommands } from './app-commands.js';
|
|
20
|
+
import { TaCredentials } from './credentials.js';
|
|
19
21
|
import { ExtensionDataStore } from './extension-data.js';
|
|
20
22
|
import { TaPresenceBook, TaSessionRegistry } from './host-protocol.js';
|
|
23
|
+
import { TaPageBook } from './page-book.js';
|
|
21
24
|
import { RELAY_BRIDGE } from './relay-bridge.js';
|
|
22
25
|
import { PiDirectories } from './remote/remote-protocol.js';
|
|
23
26
|
import { ROOMS_BRIDGE } from './rooms-bridge.js';
|
|
27
|
+
import { SessionCatalogUtil } from './session-catalog.js';
|
|
24
28
|
import { TaSettingsStore } from './settings-store.js';
|
|
25
29
|
import { TaErrors } from './ta-errors.js';
|
|
26
30
|
import { TaHostTeamProvider } from './team/team-protocol.js';
|
|
31
|
+
import { VOICE_BRIDGE } from './voice-bridge.js';
|
|
27
32
|
export const PackageHosts = Symbol('PackageHosts');
|
|
28
33
|
export var PackageHostUtil;
|
|
29
34
|
(function (PackageHostUtil) {
|
|
@@ -155,6 +160,7 @@ let PackageHostsImpl = class PackageHostsImpl {
|
|
|
155
160
|
var _a, _b;
|
|
156
161
|
const running = this.running.get(name);
|
|
157
162
|
this.running.delete(name);
|
|
163
|
+
this.appCommands.dropOwner(name);
|
|
158
164
|
try {
|
|
159
165
|
await ((_b = (_a = (await (running === null || running === void 0 ? void 0 : running.service))) === null || _a === void 0 ? void 0 : _a.dispose) === null || _b === void 0 ? void 0 : _b.call(_a));
|
|
160
166
|
}
|
|
@@ -168,6 +174,12 @@ let PackageHostsImpl = class PackageHostsImpl {
|
|
|
168
174
|
const mark = (input) => ({ ...input, message: TaMessageSource.mark(input.message, name) });
|
|
169
175
|
return {
|
|
170
176
|
...host,
|
|
177
|
+
commands: { ...host.commands, register: command => this.appCommands.registerOf(name, command) },
|
|
178
|
+
// A package asks the requests of its own web extension (`pi.ui.answer`), named after it.
|
|
179
|
+
pages: {
|
|
180
|
+
ask: (kind, payload, options = {}) => this.pageBook.ask(this.pageBook.principalOf(options), `${name}/${kind}`, payload, options.timeoutMs),
|
|
181
|
+
has: (kind, options = {}) => this.pageBook.has(this.pageBook.principalOf(options), `${name}/${kind}`),
|
|
182
|
+
},
|
|
171
183
|
prompt: (sessionId, input) => host.prompt(sessionId, mark(input)),
|
|
172
184
|
followUp: (sessionId, input) => host.followUp(sessionId, mark(input)),
|
|
173
185
|
};
|
|
@@ -188,7 +200,10 @@ let PackageHostsImpl = class PackageHostsImpl {
|
|
|
188
200
|
shares: this.relay.shares,
|
|
189
201
|
rooms: this.roomsBridge.rooms,
|
|
190
202
|
relays: this.relay.extensionRelays,
|
|
203
|
+
voices: this.voiceBridge.extensionVoices,
|
|
204
|
+
credentials: this.credentials.extension,
|
|
191
205
|
sessionMessages: file => this.sessionMessages(file),
|
|
206
|
+
sessionRole: async (file) => SessionCatalogUtil.roleOf((await PiSdkUtil.load()).SessionManager.open(file).getEntries()),
|
|
192
207
|
createSession: (cwd, messages, name) => this.createSession(cwd, messages, name),
|
|
193
208
|
getServerInfo: () => server.getServerInfo(),
|
|
194
209
|
listSessions: () => server.listSessions(),
|
|
@@ -200,6 +215,7 @@ let PackageHostsImpl = class PackageHostsImpl {
|
|
|
200
215
|
abort: sessionId => server.abort(sessionId),
|
|
201
216
|
getState: sessionId => server.getState(sessionId),
|
|
202
217
|
getLastAssistantText: sessionId => server.getLastAssistantText(sessionId),
|
|
218
|
+
relocateDirectory: (from, to) => server.relocateDirectory(from, to),
|
|
203
219
|
getExtensionData: (name, key, cwd) => packages.getExtensionData(name, key, cwd),
|
|
204
220
|
setExtensionData: (name, key, value, cwd) => packages.setExtensionData(name, key, value, cwd),
|
|
205
221
|
onExtensionData: listener => this.data.onChange(listener),
|
|
@@ -211,6 +227,15 @@ let PackageHostsImpl = class PackageHostsImpl {
|
|
|
211
227
|
}),
|
|
212
228
|
presence: () => ({ pages: this.sessions.watching, seenAt: this.sessions.watchedAt, people: this.presenceBook.everyone() }),
|
|
213
229
|
team: this.teamProvider.team,
|
|
230
|
+
commands: {
|
|
231
|
+
list: () => this.appCommands.list(),
|
|
232
|
+
run: (id, input, options) => this.appCommands.run(id, input, options),
|
|
233
|
+
register: command => this.appCommands.register(command),
|
|
234
|
+
},
|
|
235
|
+
pages: {
|
|
236
|
+
ask: () => Promise.reject(new Error('Only a package asks a page: through its own host.')),
|
|
237
|
+
has: () => false,
|
|
238
|
+
},
|
|
214
239
|
installPackage: (source, scope, cwd) => packages.installPackage(source, scope, cwd),
|
|
215
240
|
removePackage: (id, cwd) => packages.removePackage(id, cwd),
|
|
216
241
|
updateSettings: update => this.settings.rewriteUser(update),
|
|
@@ -273,6 +298,14 @@ __decorate([
|
|
|
273
298
|
Autowired({ id: ROOMS_BRIDGE, detached: true }),
|
|
274
299
|
__metadata("design:type", Function)
|
|
275
300
|
], PackageHostsImpl.prototype, "roomsBridge", void 0);
|
|
301
|
+
__decorate([
|
|
302
|
+
Autowired({ id: VOICE_BRIDGE, detached: true }),
|
|
303
|
+
__metadata("design:type", Function)
|
|
304
|
+
], PackageHostsImpl.prototype, "voiceBridge", void 0);
|
|
305
|
+
__decorate([
|
|
306
|
+
Autowired(TaCredentials),
|
|
307
|
+
__metadata("design:type", TaCredentials)
|
|
308
|
+
], PackageHostsImpl.prototype, "credentials", void 0);
|
|
276
309
|
__decorate([
|
|
277
310
|
Autowired({ id: TaSettingsStore, detached: true }),
|
|
278
311
|
__metadata("design:type", Object)
|
|
@@ -285,6 +318,14 @@ __decorate([
|
|
|
285
318
|
Autowired({ id: TaPresenceBook, detached: true }),
|
|
286
319
|
__metadata("design:type", Object)
|
|
287
320
|
], PackageHostsImpl.prototype, "presenceBook", void 0);
|
|
321
|
+
__decorate([
|
|
322
|
+
Autowired({ id: TaAppCommands, detached: true }),
|
|
323
|
+
__metadata("design:type", Object)
|
|
324
|
+
], PackageHostsImpl.prototype, "appCommands", void 0);
|
|
325
|
+
__decorate([
|
|
326
|
+
Autowired({ id: TaPageBook, detached: true }),
|
|
327
|
+
__metadata("design:type", Object)
|
|
328
|
+
], PackageHostsImpl.prototype, "pageBook", void 0);
|
|
288
329
|
__decorate([
|
|
289
330
|
Autowired({ id: TaHostTeamProvider, detached: true }),
|
|
290
331
|
__metadata("design:type", Object)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { IncomingMessage } from 'node:http';
|
|
2
|
+
import { type Context, Middleware } from '@celljs/web/lib/node';
|
|
3
|
+
import { PackageHosts } from './package-hosts.js';
|
|
4
|
+
/** Where ta serve takes the webhooks of packages: the directory name of a package, then its own path. */
|
|
5
|
+
export declare const WEBHOOK_PATH = "/api/hooks/";
|
|
6
|
+
export declare namespace PackageWebhookUtil {
|
|
7
|
+
/** The package and its path of a request to a webhook; undefined for another request. */
|
|
8
|
+
function target(request: Pick<IncomingMessage, 'url'>): {
|
|
9
|
+
name: string;
|
|
10
|
+
path: string;
|
|
11
|
+
} | undefined;
|
|
12
|
+
/** The body as text; undefined when it is larger than TA_WEBHOOK_MAX_BYTES. */
|
|
13
|
+
function body(request: IncomingMessage): Promise<string | undefined>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The webhooks of the packages that come with Ta (TaPackageService.webhook): a POST to `/api/hooks/<package>/<path>`
|
|
17
|
+
* goes to its host without the token of ta serve; the package checks the secret of its path. Anything else (another
|
|
18
|
+
* method, a package without a webhook, a secret it does not know) is a 404 that says nothing more.
|
|
19
|
+
*/
|
|
20
|
+
export declare class PackageWebhooks implements Middleware {
|
|
21
|
+
/** Before TaAccess, which would ask for the token. */
|
|
22
|
+
readonly priority: number;
|
|
23
|
+
protected readonly hosts: PackageHosts;
|
|
24
|
+
protected readonly host?: string;
|
|
25
|
+
handle(ctx: Context, next: () => Promise<void>): Promise<void>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { Autowired, Component, Value } from '@celljs/core';
|
|
11
|
+
import { TaPackages } from '@celljs/ta-harness/lib/node/ta-packages';
|
|
12
|
+
import { TA_WEBHOOK_MAX_BYTES } from '@celljs/ta-protocol';
|
|
13
|
+
import { Middleware } from '@celljs/web/lib/node';
|
|
14
|
+
import { PackageHosts } from './package-hosts.js';
|
|
15
|
+
import { ACCESS_MIDDLEWARE_PRIORITY, TaAccessUtil } from './ta-access.js';
|
|
16
|
+
/** Where ta serve takes the webhooks of packages: the directory name of a package, then its own path. */
|
|
17
|
+
export const WEBHOOK_PATH = '/api/hooks/';
|
|
18
|
+
export var PackageWebhookUtil;
|
|
19
|
+
(function (PackageWebhookUtil) {
|
|
20
|
+
/** The package and its path of a request to a webhook; undefined for another request. */
|
|
21
|
+
function target(request) {
|
|
22
|
+
var _a;
|
|
23
|
+
const path = ((_a = request.url) !== null && _a !== void 0 ? _a : '/').split('?')[0];
|
|
24
|
+
if (!path.startsWith(WEBHOOK_PATH)) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
const [directory, ...rest] = path.slice(WEBHOOK_PATH.length).split('/');
|
|
28
|
+
const name = TaPackages.BUILTIN.find(builtin => TaPackages.directoryName(builtin) === directory);
|
|
29
|
+
return name ? { name, path: rest.map(part => decodeURIComponent(part)).join('/') } : { name: '', path: '' };
|
|
30
|
+
}
|
|
31
|
+
PackageWebhookUtil.target = target;
|
|
32
|
+
/** The body as text; undefined when it is larger than TA_WEBHOOK_MAX_BYTES. */
|
|
33
|
+
async function body(request) {
|
|
34
|
+
const chunks = [];
|
|
35
|
+
let size = 0;
|
|
36
|
+
for await (const chunk of request) {
|
|
37
|
+
size += chunk.length;
|
|
38
|
+
if (size > TA_WEBHOOK_MAX_BYTES) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
chunks.push(chunk);
|
|
42
|
+
}
|
|
43
|
+
return Buffer.concat(chunks).toString('utf8');
|
|
44
|
+
}
|
|
45
|
+
PackageWebhookUtil.body = body;
|
|
46
|
+
})(PackageWebhookUtil || (PackageWebhookUtil = {}));
|
|
47
|
+
function end(response, status, value) {
|
|
48
|
+
response.statusCode = status;
|
|
49
|
+
response.setHeader('Content-Type', 'application/json; charset=utf-8');
|
|
50
|
+
response.end(JSON.stringify(value));
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The webhooks of the packages that come with Ta (TaPackageService.webhook): a POST to `/api/hooks/<package>/<path>`
|
|
54
|
+
* goes to its host without the token of ta serve; the package checks the secret of its path. Anything else (another
|
|
55
|
+
* method, a package without a webhook, a secret it does not know) is a 404 that says nothing more.
|
|
56
|
+
*/
|
|
57
|
+
let PackageWebhooks = class PackageWebhooks {
|
|
58
|
+
constructor() {
|
|
59
|
+
/** Before TaAccess, which would ask for the token. */
|
|
60
|
+
this.priority = ACCESS_MIDDLEWARE_PRIORITY + 2;
|
|
61
|
+
}
|
|
62
|
+
async handle(ctx, next) {
|
|
63
|
+
const request = ctx.request;
|
|
64
|
+
const target = PackageWebhookUtil.target(request);
|
|
65
|
+
if (!target) {
|
|
66
|
+
await next();
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const response = ctx.response;
|
|
70
|
+
// A page that rebinds its domain to a ta serve of 127.0.0.1 reaches nothing, as with TaAccess.
|
|
71
|
+
if (!target.name || request.method !== 'POST' || (TaAccessUtil.isLoopbackHost(this.host) && !TaAccessUtil.isLoopbackHost(request.headers.host))) {
|
|
72
|
+
end(response, 404, { error: 'Not found' });
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const body = await PackageWebhookUtil.body(request);
|
|
76
|
+
if (body === undefined) {
|
|
77
|
+
end(response, 413, { error: 'Too large' });
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
const answer = await this.hosts.call(target.name, 'webhook', [{ path: target.path, body, contentType: request.headers['content-type'] }]);
|
|
82
|
+
end(response, 202, answer !== null && answer !== void 0 ? answer : { ok: true });
|
|
83
|
+
}
|
|
84
|
+
catch (_a) {
|
|
85
|
+
end(response, 404, { error: 'Not found' });
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
__decorate([
|
|
90
|
+
Autowired(PackageHosts),
|
|
91
|
+
__metadata("design:type", Object)
|
|
92
|
+
], PackageWebhooks.prototype, "hosts", void 0);
|
|
93
|
+
__decorate([
|
|
94
|
+
Value('server.host'),
|
|
95
|
+
__metadata("design:type", String)
|
|
96
|
+
], PackageWebhooks.prototype, "host", void 0);
|
|
97
|
+
PackageWebhooks = __decorate([
|
|
98
|
+
Component(Middleware)
|
|
99
|
+
], PackageWebhooks);
|
|
100
|
+
export { PackageWebhooks };
|
|
101
|
+
//# sourceMappingURL=package-webhooks.js.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type RpcConnection } from '@celljs/rpc/lib/node';
|
|
2
|
+
import { type TaPageAskOptions, type TaPageInfo, TaPageServer } from '@celljs/ta-protocol';
|
|
3
|
+
import { TaHostTeamProvider, TaPrincipals } from './team/team-protocol.js';
|
|
4
|
+
export declare const TaPageBook: unique symbol;
|
|
5
|
+
/** The pages that answer requests (TaPageServer.attach), by connection, in memory only. */
|
|
6
|
+
export interface TaPageBook {
|
|
7
|
+
attach(connection: RpcConnection, info: TaPageInfo): void;
|
|
8
|
+
/** Asks the page of `principal` that answers `kind` (PageChoice.pick) and resolves to its answer. */
|
|
9
|
+
ask(principal: string, kind: string, payload: unknown, timeoutMs?: number): Promise<unknown>;
|
|
10
|
+
has(principal: string, kind: string): boolean;
|
|
11
|
+
/** Whom a package's request is for: who asked the run of the session file, or the principal given. */
|
|
12
|
+
principalOf(options: TaPageAskOptions): string;
|
|
13
|
+
}
|
|
14
|
+
/** A page as the book keeps it. */
|
|
15
|
+
export interface PageEntry {
|
|
16
|
+
principal: string;
|
|
17
|
+
info: TaPageInfo;
|
|
18
|
+
/** `Date.now()` time it was last said active, or attached. */
|
|
19
|
+
activeAt: number;
|
|
20
|
+
}
|
|
21
|
+
export declare namespace PageChoice {
|
|
22
|
+
/**
|
|
23
|
+
* The page to ask among those of one person that answer the kind: the one in front of them, the latest touched of
|
|
24
|
+
* those; else the window of Ta Desktop, kept while closed; else the latest touched.
|
|
25
|
+
*/
|
|
26
|
+
function pick<T extends PageEntry>(entries: readonly T[]): T | undefined;
|
|
27
|
+
/** What a page said of itself, made safe: only strings of kinds, a device it knows. */
|
|
28
|
+
function clean(info: TaPageInfo | undefined): TaPageInfo;
|
|
29
|
+
}
|
|
30
|
+
export declare class DefaultTaPageBook implements TaPageBook {
|
|
31
|
+
protected readonly principals: TaPrincipals;
|
|
32
|
+
protected readonly teamProvider: TaHostTeamProvider;
|
|
33
|
+
protected readonly entries: Map<RpcConnection, PageEntry & {
|
|
34
|
+
connection: RpcConnection;
|
|
35
|
+
}>;
|
|
36
|
+
attach(connection: RpcConnection, info: TaPageInfo): void;
|
|
37
|
+
ask(principal: string, kind: string, payload: unknown, timeoutMs?: number): Promise<unknown>;
|
|
38
|
+
has(principal: string, kind: string): boolean;
|
|
39
|
+
principalOf(options: TaPageAskOptions): string;
|
|
40
|
+
protected of(principal: string, kind: string): (PageEntry & {
|
|
41
|
+
connection: RpcConnection;
|
|
42
|
+
})[];
|
|
43
|
+
}
|
|
44
|
+
/** A page says which requests it answers (TaPageServer). */
|
|
45
|
+
export declare class TaPageServerImpl implements TaPageServer {
|
|
46
|
+
protected readonly book: TaPageBook;
|
|
47
|
+
attach(info: TaPageInfo): Promise<void>;
|
|
48
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { Autowired, Component } from '@celljs/core';
|
|
11
|
+
import { Rpc } from '@celljs/rpc';
|
|
12
|
+
import { RpcContext } from '@celljs/rpc/lib/node';
|
|
13
|
+
import { TA_OWNER, TA_PAGE_ASK_MS, TaClient, TaPageServer } from '@celljs/ta-protocol';
|
|
14
|
+
import { TaErrors } from './ta-errors.js';
|
|
15
|
+
import { TaHostTeamProvider, TaPrincipals } from './team/team-protocol.js';
|
|
16
|
+
export const TaPageBook = Symbol('TaPageBook');
|
|
17
|
+
export var PageChoice;
|
|
18
|
+
(function (PageChoice) {
|
|
19
|
+
/**
|
|
20
|
+
* The page to ask among those of one person that answer the kind: the one in front of them, the latest touched of
|
|
21
|
+
* those; else the window of Ta Desktop, kept while closed; else the latest touched.
|
|
22
|
+
*/
|
|
23
|
+
function pick(entries) {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
const latest = (list) => list.reduce((best, one) => (!best || one.activeAt > best.activeAt ? one : best), undefined);
|
|
26
|
+
return (_b = (_a = latest(entries.filter(entry => entry.info.visible))) !== null && _a !== void 0 ? _a : latest(entries.filter(entry => entry.info.desktop))) !== null && _b !== void 0 ? _b : latest(entries);
|
|
27
|
+
}
|
|
28
|
+
PageChoice.pick = pick;
|
|
29
|
+
/** What a page said of itself, made safe: only strings of kinds, a device it knows. */
|
|
30
|
+
function clean(info) {
|
|
31
|
+
const kinds = Array.isArray(info === null || info === void 0 ? void 0 : info.kinds) ? info.kinds.filter(kind => typeof kind === 'string' && kind.length <= 100).slice(0, 100) : [];
|
|
32
|
+
const device = (info === null || info === void 0 ? void 0 : info.device) === 'phone' || (info === null || info === void 0 ? void 0 : info.device) === 'tablet' ? info.device : 'computer';
|
|
33
|
+
return { kinds, device, ...((info === null || info === void 0 ? void 0 : info.desktop) === true ? { desktop: true } : {}), ...((info === null || info === void 0 ? void 0 : info.visible) === true ? { visible: true } : {}) };
|
|
34
|
+
}
|
|
35
|
+
PageChoice.clean = clean;
|
|
36
|
+
})(PageChoice || (PageChoice = {}));
|
|
37
|
+
let DefaultTaPageBook = class DefaultTaPageBook {
|
|
38
|
+
constructor() {
|
|
39
|
+
this.entries = new Map();
|
|
40
|
+
}
|
|
41
|
+
attach(connection, info) {
|
|
42
|
+
if (connection.closed) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const before = this.entries.get(connection);
|
|
46
|
+
const clean = PageChoice.clean(info);
|
|
47
|
+
this.entries.set(connection, {
|
|
48
|
+
connection,
|
|
49
|
+
principal: this.principals.of(connection),
|
|
50
|
+
info: clean,
|
|
51
|
+
activeAt: (info === null || info === void 0 ? void 0 : info.active) === true || !before ? Date.now() : before.activeAt,
|
|
52
|
+
});
|
|
53
|
+
if (!before) {
|
|
54
|
+
connection.onClose(() => this.entries.delete(connection));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async ask(principal, kind, payload, timeoutMs = TA_PAGE_ASK_MS) {
|
|
58
|
+
const page = PageChoice.pick(this.of(principal, kind));
|
|
59
|
+
if (!page) {
|
|
60
|
+
throw TaErrors.invalidArgument('No page of Ta is open for this.', 'The user opens Ta on a phone or a computer; meanwhile do it without the screen.');
|
|
61
|
+
}
|
|
62
|
+
let timer;
|
|
63
|
+
try {
|
|
64
|
+
return await Promise.race([
|
|
65
|
+
page.connection.client(TaClient).onPageAsk(kind, payload),
|
|
66
|
+
new Promise((_resolve, reject) => {
|
|
67
|
+
timer = setTimeout(() => reject(TaErrors.invalidArgument('The page of Ta did not answer in time.', 'Try again in a moment.')), timeoutMs);
|
|
68
|
+
}),
|
|
69
|
+
]);
|
|
70
|
+
}
|
|
71
|
+
finally {
|
|
72
|
+
clearTimeout(timer);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
has(principal, kind) {
|
|
76
|
+
return this.of(principal, kind).length > 0;
|
|
77
|
+
}
|
|
78
|
+
principalOf(options) {
|
|
79
|
+
var _a;
|
|
80
|
+
if (options.principal) {
|
|
81
|
+
return options.principal;
|
|
82
|
+
}
|
|
83
|
+
const team = this.teamProvider.team;
|
|
84
|
+
const actors = options.sessionFile ? team.actorsOf(options.sessionFile) : [team.current()];
|
|
85
|
+
return (_a = actors.find(actor => actor !== TA_OWNER)) !== null && _a !== void 0 ? _a : TA_OWNER;
|
|
86
|
+
}
|
|
87
|
+
of(principal, kind) {
|
|
88
|
+
return [...this.entries.values()].filter(entry => !entry.connection.closed && entry.principal === principal && entry.info.kinds.includes(kind));
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
__decorate([
|
|
92
|
+
Autowired(TaPrincipals),
|
|
93
|
+
__metadata("design:type", Object)
|
|
94
|
+
], DefaultTaPageBook.prototype, "principals", void 0);
|
|
95
|
+
__decorate([
|
|
96
|
+
Autowired({ id: TaHostTeamProvider, detached: true }),
|
|
97
|
+
__metadata("design:type", Object)
|
|
98
|
+
], DefaultTaPageBook.prototype, "teamProvider", void 0);
|
|
99
|
+
DefaultTaPageBook = __decorate([
|
|
100
|
+
Component(TaPageBook)
|
|
101
|
+
], DefaultTaPageBook);
|
|
102
|
+
export { DefaultTaPageBook };
|
|
103
|
+
/** A page says which requests it answers (TaPageServer). */
|
|
104
|
+
let TaPageServerImpl = class TaPageServerImpl {
|
|
105
|
+
async attach(info) {
|
|
106
|
+
this.book.attach(RpcContext.requireConnection(), info);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
__decorate([
|
|
110
|
+
Autowired(TaPageBook),
|
|
111
|
+
__metadata("design:type", Object)
|
|
112
|
+
], TaPageServerImpl.prototype, "book", void 0);
|
|
113
|
+
TaPageServerImpl = __decorate([
|
|
114
|
+
Rpc(TaPageServer)
|
|
115
|
+
], TaPageServerImpl);
|
|
116
|
+
export { TaPageServerImpl };
|
|
117
|
+
//# sourceMappingURL=page-book.js.map
|
|
@@ -80,6 +80,8 @@ export declare class TaRelayServerImpl implements TaRelayServer {
|
|
|
80
80
|
addStore(type: string, options: Record<string, unknown>, name?: string): Promise<string>;
|
|
81
81
|
removeRelay(id: string): Promise<void>;
|
|
82
82
|
chooseRelay(feature: TaRelayFeature, id: string | null): Promise<TaRelays>;
|
|
83
|
+
joinDeployment(url: string): Promise<TaRelays>;
|
|
84
|
+
leaveDeployment(): Promise<TaRelays>;
|
|
83
85
|
probeRelay(idOrUrl: string): Promise<TaRelayProbe>;
|
|
84
86
|
/** A change of relays.json; what it refuses is said as the errors of Ta. */
|
|
85
87
|
protected relaysCall<T>(change: () => T): T;
|
package/esm/node/relay-bridge.js
CHANGED
|
@@ -15,7 +15,7 @@ import { Rpc } from '@celljs/rpc';
|
|
|
15
15
|
import { ExecEnvironmentFactory } from '@celljs/ta-exec';
|
|
16
16
|
import { PackageArchive } from '@celljs/ta-harness/lib/node/package-archive';
|
|
17
17
|
import { TaBrand } from '@celljs/ta-harness/lib/node/ta-brand';
|
|
18
|
-
import { TA_WEBSOCKET_PATH, TaRelayServer, } from '@celljs/ta-protocol';
|
|
18
|
+
import { TA_WEBSOCKET_PATH, TaDeploymentUtil, TaRelayServer, } from '@celljs/ta-protocol';
|
|
19
19
|
import { RELAY_CONTENT_MAX_BYTES, RELAY_FEATURES, RELAY_SHARE_MAX_BYTES, RelayBlobClient, RelayBytes, RelayContentError, RelayContentUtil, RelayHost, RelayHubFiles, RelayHubs, RelayInfoUtil, RelayPairingUtil, RelayServiceUtil, RelayShareUtil, RelayStore, RelaysConfigError, RelaysFile, RelayTypes, } from '@celljs/ta-relay/lib/node';
|
|
20
20
|
import { ServerAware } from '@celljs/web/lib/node';
|
|
21
21
|
import { KeepAwake, WebExtensionCatalog } from './host-protocol.js';
|
|
@@ -238,6 +238,7 @@ let RelayBridge = RelayBridge_1 = class RelayBridge {
|
|
|
238
238
|
const url = RelayServiceUtil.isRelay(service) ? service.url : undefined;
|
|
239
239
|
return [feature, service.id || ((_a = services.find(each => each.type === 'ta-relay' && each.url === url)) === null || _a === void 0 ? void 0 : _a.id) || ''];
|
|
240
240
|
}));
|
|
241
|
+
const deployment = this.relays.deployment(config);
|
|
241
242
|
const drives = RelayServiceUtil.drives().filter(drive => !services.some(service => service.type === 'folder' && service.path === drive.path));
|
|
242
243
|
const types = [...this.types].map(([type, { title, hint, icon, options }]) => ({
|
|
243
244
|
type,
|
|
@@ -253,6 +254,7 @@ let RelayBridge = RelayBridge_1 = class RelayBridge {
|
|
|
253
254
|
...(drives.length ? { drives } : {}),
|
|
254
255
|
...(types.length ? { types } : {}),
|
|
255
256
|
...(error ? { error } : {}),
|
|
257
|
+
...(deployment ? { deployment } : {}),
|
|
256
258
|
};
|
|
257
259
|
}
|
|
258
260
|
/** The store of a service of a type a package registered. */
|
|
@@ -424,6 +426,38 @@ let TaRelayServerImpl = class TaRelayServerImpl {
|
|
|
424
426
|
return this.bridge.listRelays();
|
|
425
427
|
});
|
|
426
428
|
}
|
|
429
|
+
joinDeployment(url) {
|
|
430
|
+
return TaErrors.guard(async () => {
|
|
431
|
+
var _a, _b;
|
|
432
|
+
const address = TaDeploymentUtil.url(url);
|
|
433
|
+
if (!address) {
|
|
434
|
+
throw TaErrors.invalidArgument(`${url} is not an address of http or https.`, 'Pass the address of the gateway or the relay of the deployment, https://….');
|
|
435
|
+
}
|
|
436
|
+
let deployment;
|
|
437
|
+
try {
|
|
438
|
+
deployment = await TaDeploymentUtil.discover(address);
|
|
439
|
+
}
|
|
440
|
+
catch (error) {
|
|
441
|
+
throw TaErrors.invalidArgument(error instanceof Error ? error.message : String(error), 'Check the address: a service of a deployment answers /.well-known/ta. A relay alone is added as a relay.');
|
|
442
|
+
}
|
|
443
|
+
if (deployment.relay) {
|
|
444
|
+
const probe = await RelayInfoUtil.probe(deployment.relay);
|
|
445
|
+
if (!probe.online) {
|
|
446
|
+
throw TaErrors.invalidArgument(`The relay of ${(_a = deployment.name) !== null && _a !== void 0 ? _a : address}, ${deployment.relay}, does not answer: ${(_b = probe.error) !== null && _b !== void 0 ? _b : 'no answer'}.`, 'Ask whoever runs the deployment whether its relay runs.');
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
this.relaysCall(() => this.bridge.relays.join(address, deployment));
|
|
450
|
+
this.bridge.relaysChanged();
|
|
451
|
+
return this.bridge.listRelays();
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
leaveDeployment() {
|
|
455
|
+
return TaErrors.guard(async () => {
|
|
456
|
+
this.relaysCall(() => this.bridge.relays.leave());
|
|
457
|
+
this.bridge.relaysChanged();
|
|
458
|
+
return this.bridge.listRelays();
|
|
459
|
+
});
|
|
460
|
+
}
|
|
427
461
|
async probeRelay(idOrUrl) {
|
|
428
462
|
var _a, _b, _c;
|
|
429
463
|
const text = String(idOrUrl !== null && idOrUrl !== void 0 ? idOrUrl : '');
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Application, ApplicationLifecycle } from '@celljs/core';
|
|
2
2
|
import { type RpcConnection } from '@celljs/rpc/lib/node';
|
|
3
|
-
import { type TaFriend, type TaFriendRequest, type TaIdentity, type TaRoomEvent, type TaRoomInfo, type TaRoomRequest, TaRoomServer, type TaRooms, type TaRoomValue, type TaRoomWatch } from '@celljs/ta-protocol';
|
|
3
|
+
import { type TaFriend, type TaFriendRequest, type TaFriendShare, type TaGroupInvite, type TaIdentity, type TaRoomEvent, type TaRoomInfo, type TaRoomRequest, TaRoomServer, type TaRooms, type TaRoomValue, type TaRoomWatch } from '@celljs/ta-protocol';
|
|
4
4
|
import type { RelayHubs } from '@celljs/ta-relay/lib/node';
|
|
5
5
|
import { ExtensionDataStore } from './extension-data.js';
|
|
6
6
|
import { type RelayBridge } from './relay-bridge.js';
|
|
@@ -53,6 +53,9 @@ export declare class TaRoomServerImpl implements TaRoomServer {
|
|
|
53
53
|
listRequests(): Promise<TaRoomRequest[]>;
|
|
54
54
|
answer(room: string, ask: string, accept: boolean): Promise<void>;
|
|
55
55
|
removeMember(room: string, member: string): Promise<void>;
|
|
56
|
+
configureRoom(room: string, options: {
|
|
57
|
+
members?: number;
|
|
58
|
+
}): Promise<TaRoomInfo>;
|
|
56
59
|
leave(room: string): Promise<void>;
|
|
57
60
|
send(room: string, data: unknown, to?: string): Promise<void>;
|
|
58
61
|
getState(room: string, prefix?: string): Promise<Record<string, TaRoomValue>>;
|
|
@@ -67,6 +70,15 @@ export declare class TaRoomServerImpl implements TaRoomServer {
|
|
|
67
70
|
}>;
|
|
68
71
|
addFriend(link: string): Promise<void>;
|
|
69
72
|
offerFriend(room: string, member: string): Promise<void>;
|
|
73
|
+
inviteFriends(room: string, friends: string[]): Promise<number>;
|
|
74
|
+
listGroupInvites(): Promise<TaGroupInvite[]>;
|
|
75
|
+
answerGroupInvite(room: string, accept: boolean): Promise<void>;
|
|
76
|
+
sendToFriends(friends: string[], item: {
|
|
77
|
+
link: string;
|
|
78
|
+
title: string;
|
|
79
|
+
}): Promise<number>;
|
|
80
|
+
listFriendShares(): Promise<TaFriendShare[]>;
|
|
81
|
+
answerFriendShare(id: string, keep: boolean): Promise<void>;
|
|
70
82
|
listFriendRequests(): Promise<TaFriendRequest[]>;
|
|
71
83
|
answerFriend(id: string, accept: boolean): Promise<void>;
|
|
72
84
|
removeFriend(id: string): Promise<boolean>;
|