@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
package/lib/node/keep-awake.js
CHANGED
|
@@ -14,6 +14,7 @@ const node_child_process_1 = require("node:child_process");
|
|
|
14
14
|
const core_1 = require("@celljs/core");
|
|
15
15
|
const host_protocol_1 = require("./host-protocol");
|
|
16
16
|
const relay_bridge_1 = require("./relay-bridge");
|
|
17
|
+
const screen_shares_1 = require("./screen-share/screen-shares");
|
|
17
18
|
var KeepAwakeUtil;
|
|
18
19
|
(function (KeepAwakeUtil) {
|
|
19
20
|
/** How long after a device left the computer stays awake: a phone put away a while comes back to a Ta that answers. */
|
|
@@ -30,10 +31,17 @@ var KeepAwakeUtil;
|
|
|
30
31
|
})(KeepAwakeUtil || (exports.KeepAwakeUtil = KeepAwakeUtil = {}));
|
|
31
32
|
/** How often what keeps the computer awake is looked at. */
|
|
32
33
|
const CHECK_MS = 15000;
|
|
34
|
+
/**
|
|
35
|
+
* How long the computer stays awake after ta serve stops while it held it: a restart of Ta (an update, Restart Ta)
|
|
36
|
+
* takes seconds, and a Mac idle past its sleep time falls asleep the moment the assertion goes, before the new one.
|
|
37
|
+
*/
|
|
38
|
+
const BRIDGE_S = 120;
|
|
33
39
|
/**
|
|
34
40
|
* Keeps the computer from sleeping while idle as long as a session runs or a paired device was connected of
|
|
35
41
|
* late: asleep, ta serve answers no phone, and a phone that cannot reach it cannot wake it. It holds
|
|
36
|
-
* `caffeinate -i
|
|
42
|
+
* `caffeinate -i -s`, which ends with ta serve: idle sleep, and on power any sleep but of a closed lid, since a Mac
|
|
43
|
+
* that slept wakes only in the dark for minutes, where an assertion of idle sleep does not keep it; the display
|
|
44
|
+
* still sleeps. Stopping while it held it, it leaves one of BRIDGE_S, for the Ta that starts after.
|
|
37
45
|
* Turned off in relay.json (TaRelayServer.setKeepAwake); nothing where it is not supported.
|
|
38
46
|
*/
|
|
39
47
|
let KeepAwakeImpl = class KeepAwakeImpl {
|
|
@@ -54,10 +62,15 @@ let KeepAwakeImpl = class KeepAwakeImpl {
|
|
|
54
62
|
}
|
|
55
63
|
this.timer = setInterval(() => this.check(), CHECK_MS);
|
|
56
64
|
(_b = (_a = this.timer).unref) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
65
|
+
this.check();
|
|
57
66
|
}
|
|
58
67
|
onStop() {
|
|
59
68
|
clearInterval(this.timer);
|
|
69
|
+
const held = this.held;
|
|
60
70
|
this.release();
|
|
71
|
+
if (held) {
|
|
72
|
+
this.spawnBridge().unref();
|
|
73
|
+
}
|
|
61
74
|
}
|
|
62
75
|
check(now = Date.now()) {
|
|
63
76
|
if (!this.supported) {
|
|
@@ -66,7 +79,7 @@ let KeepAwakeImpl = class KeepAwakeImpl {
|
|
|
66
79
|
if (this.bridge.devicesOpen > 0) {
|
|
67
80
|
this.deviceAt = now;
|
|
68
81
|
}
|
|
69
|
-
const running = this.sessions.list().some(session => session.pi.isStreaming);
|
|
82
|
+
const running = this.sessions.list().some(session => session.pi.isStreaming) || this.desktops.watched;
|
|
70
83
|
const enabled = this.bridge.store.read().keepAwake !== false;
|
|
71
84
|
if (KeepAwakeUtil.wanted({ enabled, running, deviceAt: this.deviceAt, now })) {
|
|
72
85
|
this.hold();
|
|
@@ -97,7 +110,11 @@ let KeepAwakeImpl = class KeepAwakeImpl {
|
|
|
97
110
|
}
|
|
98
111
|
/** `-w`: it ends when this process does, killed too. */
|
|
99
112
|
spawn() {
|
|
100
|
-
return (0, node_child_process_1.spawn)('/usr/bin/caffeinate', ['-i', '-w', String(process.pid)], { stdio: 'ignore' });
|
|
113
|
+
return (0, node_child_process_1.spawn)('/usr/bin/caffeinate', ['-i', '-s', '-w', String(process.pid)], { stdio: 'ignore' });
|
|
114
|
+
}
|
|
115
|
+
/** Awake for a while after this process, on its own. */
|
|
116
|
+
spawnBridge() {
|
|
117
|
+
return (0, node_child_process_1.spawn)('/usr/bin/caffeinate', ['-i', '-s', '-t', String(BRIDGE_S)], { stdio: 'ignore', detached: true });
|
|
101
118
|
}
|
|
102
119
|
};
|
|
103
120
|
exports.KeepAwakeImpl = KeepAwakeImpl;
|
|
@@ -109,6 +126,10 @@ __decorate([
|
|
|
109
126
|
(0, core_1.Autowired)(host_protocol_1.TaSessionRegistry),
|
|
110
127
|
__metadata("design:type", Object)
|
|
111
128
|
], KeepAwakeImpl.prototype, "sessions", void 0);
|
|
129
|
+
__decorate([
|
|
130
|
+
(0, core_1.Autowired)(screen_shares_1.ScreenShares),
|
|
131
|
+
__metadata("design:type", screen_shares_1.ScreenShares)
|
|
132
|
+
], KeepAwakeImpl.prototype, "desktops", void 0);
|
|
112
133
|
exports.KeepAwakeImpl = KeepAwakeImpl = __decorate([
|
|
113
134
|
(0, core_1.Component)([host_protocol_1.KeepAwake, core_1.ApplicationLifecycle])
|
|
114
135
|
], KeepAwakeImpl);
|
|
@@ -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/lib/node/message-page.js
CHANGED
|
@@ -45,13 +45,60 @@ var MessagePage;
|
|
|
45
45
|
return start;
|
|
46
46
|
}
|
|
47
47
|
MessagePage.start = start;
|
|
48
|
+
/**
|
|
49
|
+
* A message of the user that the agent was given on the way, after the result of a tool it was written before:
|
|
50
|
+
* a step of the turn, not the start of another (as the web page reads it).
|
|
51
|
+
*/
|
|
52
|
+
function steered(messages, index) {
|
|
53
|
+
var _a;
|
|
54
|
+
if (role(messages[index]) !== 'user') {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
for (let before = index - 1; before >= 0; before--) {
|
|
58
|
+
const was = (_a = role(messages[before])) !== null && _a !== void 0 ? _a : '';
|
|
59
|
+
if (was === 'user') {
|
|
60
|
+
return steered(messages, before);
|
|
61
|
+
}
|
|
62
|
+
if (TURN_ROLES.has(was)) {
|
|
63
|
+
const at = timestamp(messages[index]);
|
|
64
|
+
const came = timestamp(messages[before]);
|
|
65
|
+
return was === 'toolResult' && at !== undefined && came !== undefined && at < came;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* When the messages from `from` start in the middle of a turn (the first of the user or the agent among them
|
|
72
|
+
* is a step of it): the message of the user that asked for the turn.
|
|
73
|
+
*/
|
|
74
|
+
function head(messages, from) {
|
|
75
|
+
var _a;
|
|
76
|
+
let first = from;
|
|
77
|
+
while (first < messages.length && role(messages[first]) !== 'user' && !TURN_ROLES.has((_a = role(messages[first])) !== null && _a !== void 0 ? _a : '')) {
|
|
78
|
+
first++;
|
|
79
|
+
}
|
|
80
|
+
if (from <= 0 || first >= messages.length || (role(messages[first]) === 'user' && !steered(messages, first))) {
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
for (let index = from - 1; index >= 0; index--) {
|
|
84
|
+
if (role(messages[index]) === 'user' && !steered(messages, index)) {
|
|
85
|
+
return { index, message: messages[index] };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
MessagePage.head = head;
|
|
48
91
|
/** The latest part of a conversation, or all of it without a budget. */
|
|
49
92
|
function recent(conversation, budget) {
|
|
50
93
|
if (!budget || budget <= 0) {
|
|
51
94
|
return conversation;
|
|
52
95
|
}
|
|
53
96
|
const from = start(conversation.messages, conversation.messages.length, budget);
|
|
54
|
-
|
|
97
|
+
if (from === 0) {
|
|
98
|
+
return conversation;
|
|
99
|
+
}
|
|
100
|
+
const turn = head(conversation.messages, from);
|
|
101
|
+
return { ...conversation, messages: conversation.messages.slice(from), start: from, ...(turn ? { head: turn } : {}) };
|
|
55
102
|
}
|
|
56
103
|
MessagePage.recent = recent;
|
|
57
104
|
/** The part before message `before`, found again by its timestamp if messages came or went before it. */
|
|
@@ -67,7 +114,8 @@ var MessagePage;
|
|
|
67
114
|
}
|
|
68
115
|
}
|
|
69
116
|
const from = start(messages, end, Math.max(1, budget));
|
|
70
|
-
|
|
117
|
+
const turn = head(messages, from);
|
|
118
|
+
return { messages: messages.slice(from, end), start: from, found: true, ...(turn ? { head: turn } : {}) };
|
|
71
119
|
}
|
|
72
120
|
MessagePage.before = before;
|
|
73
121
|
})(MessagePage || (exports.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';
|
|
5
|
+
import { TaCredentials } from './credentials';
|
|
4
6
|
import { ExtensionDataStore } from './extension-data';
|
|
5
7
|
import { TaPresenceBook, TaSessionRegistry } from './host-protocol';
|
|
8
|
+
import { TaPageBook } from './page-book';
|
|
6
9
|
import { type RelayBridge } from './relay-bridge';
|
|
7
10
|
import { PiDirectories } from './remote/remote-protocol';
|
|
8
11
|
import { type RoomsBridge } from './rooms-bridge';
|
|
9
12
|
import { TaSettingsStore } from './settings-store';
|
|
10
13
|
import { TaHostTeamProvider } from './team/team-protocol';
|
|
14
|
+
import { type VoiceBridge } from './voice-bridge';
|
|
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;
|
|
@@ -19,14 +19,19 @@ const core_1 = require("@celljs/core");
|
|
|
19
19
|
const ta_brand_1 = require("@celljs/ta-harness/lib/node/ta-brand");
|
|
20
20
|
const ta_packages_1 = require("@celljs/ta-harness/lib/node/ta-packages");
|
|
21
21
|
const ta_protocol_1 = require("@celljs/ta-protocol");
|
|
22
|
+
const app_commands_1 = require("./app-commands");
|
|
23
|
+
const credentials_1 = require("./credentials");
|
|
22
24
|
const extension_data_1 = require("./extension-data");
|
|
23
25
|
const host_protocol_1 = require("./host-protocol");
|
|
26
|
+
const page_book_1 = require("./page-book");
|
|
24
27
|
const relay_bridge_1 = require("./relay-bridge");
|
|
25
28
|
const remote_protocol_1 = require("./remote/remote-protocol");
|
|
26
29
|
const rooms_bridge_1 = require("./rooms-bridge");
|
|
30
|
+
const session_catalog_1 = require("./session-catalog");
|
|
27
31
|
const settings_store_1 = require("./settings-store");
|
|
28
32
|
const ta_errors_1 = require("./ta-errors");
|
|
29
33
|
const team_protocol_1 = require("./team/team-protocol");
|
|
34
|
+
const voice_bridge_1 = require("./voice-bridge");
|
|
30
35
|
exports.PackageHosts = Symbol('PackageHosts');
|
|
31
36
|
var PackageHostUtil;
|
|
32
37
|
(function (PackageHostUtil) {
|
|
@@ -158,6 +163,7 @@ let PackageHostsImpl = class PackageHostsImpl {
|
|
|
158
163
|
var _a, _b;
|
|
159
164
|
const running = this.running.get(name);
|
|
160
165
|
this.running.delete(name);
|
|
166
|
+
this.appCommands.dropOwner(name);
|
|
161
167
|
try {
|
|
162
168
|
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));
|
|
163
169
|
}
|
|
@@ -171,6 +177,12 @@ let PackageHostsImpl = class PackageHostsImpl {
|
|
|
171
177
|
const mark = (input) => ({ ...input, message: ta_protocol_1.TaMessageSource.mark(input.message, name) });
|
|
172
178
|
return {
|
|
173
179
|
...host,
|
|
180
|
+
commands: { ...host.commands, register: command => this.appCommands.registerOf(name, command) },
|
|
181
|
+
// A package asks the requests of its own web extension (`pi.ui.answer`), named after it.
|
|
182
|
+
pages: {
|
|
183
|
+
ask: (kind, payload, options = {}) => this.pageBook.ask(this.pageBook.principalOf(options), `${name}/${kind}`, payload, options.timeoutMs),
|
|
184
|
+
has: (kind, options = {}) => this.pageBook.has(this.pageBook.principalOf(options), `${name}/${kind}`),
|
|
185
|
+
},
|
|
174
186
|
prompt: (sessionId, input) => host.prompt(sessionId, mark(input)),
|
|
175
187
|
followUp: (sessionId, input) => host.followUp(sessionId, mark(input)),
|
|
176
188
|
};
|
|
@@ -191,7 +203,10 @@ let PackageHostsImpl = class PackageHostsImpl {
|
|
|
191
203
|
shares: this.relay.shares,
|
|
192
204
|
rooms: this.roomsBridge.rooms,
|
|
193
205
|
relays: this.relay.extensionRelays,
|
|
206
|
+
voices: this.voiceBridge.extensionVoices,
|
|
207
|
+
credentials: this.credentials.extension,
|
|
194
208
|
sessionMessages: file => this.sessionMessages(file),
|
|
209
|
+
sessionRole: async (file) => session_catalog_1.SessionCatalogUtil.roleOf((await ai_coding_agent_1.PiSdkUtil.load()).SessionManager.open(file).getEntries()),
|
|
195
210
|
createSession: (cwd, messages, name) => this.createSession(cwd, messages, name),
|
|
196
211
|
getServerInfo: () => server.getServerInfo(),
|
|
197
212
|
listSessions: () => server.listSessions(),
|
|
@@ -203,6 +218,7 @@ let PackageHostsImpl = class PackageHostsImpl {
|
|
|
203
218
|
abort: sessionId => server.abort(sessionId),
|
|
204
219
|
getState: sessionId => server.getState(sessionId),
|
|
205
220
|
getLastAssistantText: sessionId => server.getLastAssistantText(sessionId),
|
|
221
|
+
relocateDirectory: (from, to) => server.relocateDirectory(from, to),
|
|
206
222
|
getExtensionData: (name, key, cwd) => packages.getExtensionData(name, key, cwd),
|
|
207
223
|
setExtensionData: (name, key, value, cwd) => packages.setExtensionData(name, key, value, cwd),
|
|
208
224
|
onExtensionData: listener => this.data.onChange(listener),
|
|
@@ -214,6 +230,15 @@ let PackageHostsImpl = class PackageHostsImpl {
|
|
|
214
230
|
}),
|
|
215
231
|
presence: () => ({ pages: this.sessions.watching, seenAt: this.sessions.watchedAt, people: this.presenceBook.everyone() }),
|
|
216
232
|
team: this.teamProvider.team,
|
|
233
|
+
commands: {
|
|
234
|
+
list: () => this.appCommands.list(),
|
|
235
|
+
run: (id, input, options) => this.appCommands.run(id, input, options),
|
|
236
|
+
register: command => this.appCommands.register(command),
|
|
237
|
+
},
|
|
238
|
+
pages: {
|
|
239
|
+
ask: () => Promise.reject(new Error('Only a package asks a page: through its own host.')),
|
|
240
|
+
has: () => false,
|
|
241
|
+
},
|
|
217
242
|
installPackage: (source, scope, cwd) => packages.installPackage(source, scope, cwd),
|
|
218
243
|
removePackage: (id, cwd) => packages.removePackage(id, cwd),
|
|
219
244
|
updateSettings: update => this.settings.rewriteUser(update),
|
|
@@ -277,6 +302,14 @@ __decorate([
|
|
|
277
302
|
(0, core_1.Autowired)({ id: rooms_bridge_1.ROOMS_BRIDGE, detached: true }),
|
|
278
303
|
__metadata("design:type", Function)
|
|
279
304
|
], PackageHostsImpl.prototype, "roomsBridge", void 0);
|
|
305
|
+
__decorate([
|
|
306
|
+
(0, core_1.Autowired)({ id: voice_bridge_1.VOICE_BRIDGE, detached: true }),
|
|
307
|
+
__metadata("design:type", Function)
|
|
308
|
+
], PackageHostsImpl.prototype, "voiceBridge", void 0);
|
|
309
|
+
__decorate([
|
|
310
|
+
(0, core_1.Autowired)(credentials_1.TaCredentials),
|
|
311
|
+
__metadata("design:type", credentials_1.TaCredentials)
|
|
312
|
+
], PackageHostsImpl.prototype, "credentials", void 0);
|
|
280
313
|
__decorate([
|
|
281
314
|
(0, core_1.Autowired)({ id: settings_store_1.TaSettingsStore, detached: true }),
|
|
282
315
|
__metadata("design:type", Object)
|
|
@@ -289,6 +322,14 @@ __decorate([
|
|
|
289
322
|
(0, core_1.Autowired)({ id: host_protocol_1.TaPresenceBook, detached: true }),
|
|
290
323
|
__metadata("design:type", Object)
|
|
291
324
|
], PackageHostsImpl.prototype, "presenceBook", void 0);
|
|
325
|
+
__decorate([
|
|
326
|
+
(0, core_1.Autowired)({ id: app_commands_1.TaAppCommands, detached: true }),
|
|
327
|
+
__metadata("design:type", Object)
|
|
328
|
+
], PackageHostsImpl.prototype, "appCommands", void 0);
|
|
329
|
+
__decorate([
|
|
330
|
+
(0, core_1.Autowired)({ id: page_book_1.TaPageBook, detached: true }),
|
|
331
|
+
__metadata("design:type", Object)
|
|
332
|
+
], PackageHostsImpl.prototype, "pageBook", void 0);
|
|
292
333
|
__decorate([
|
|
293
334
|
(0, core_1.Autowired)({ id: team_protocol_1.TaHostTeamProvider, detached: true }),
|
|
294
335
|
__metadata("design:type", Object)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { IncomingMessage } from 'node:http';
|
|
2
|
+
import { type Context, Middleware } from '@celljs/web/lib/node';
|
|
3
|
+
import { PackageHosts } from './package-hosts';
|
|
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
|
+
}
|
|
27
|
+
//# sourceMappingURL=package-webhooks.d.ts.map
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.PackageWebhooks = exports.PackageWebhookUtil = exports.WEBHOOK_PATH = void 0;
|
|
13
|
+
const core_1 = require("@celljs/core");
|
|
14
|
+
const ta_packages_1 = require("@celljs/ta-harness/lib/node/ta-packages");
|
|
15
|
+
const ta_protocol_1 = require("@celljs/ta-protocol");
|
|
16
|
+
const node_1 = require("@celljs/web/lib/node");
|
|
17
|
+
const package_hosts_1 = require("./package-hosts");
|
|
18
|
+
const ta_access_1 = require("./ta-access");
|
|
19
|
+
/** Where ta serve takes the webhooks of packages: the directory name of a package, then its own path. */
|
|
20
|
+
exports.WEBHOOK_PATH = '/api/hooks/';
|
|
21
|
+
var PackageWebhookUtil;
|
|
22
|
+
(function (PackageWebhookUtil) {
|
|
23
|
+
/** The package and its path of a request to a webhook; undefined for another request. */
|
|
24
|
+
function target(request) {
|
|
25
|
+
var _a;
|
|
26
|
+
const path = ((_a = request.url) !== null && _a !== void 0 ? _a : '/').split('?')[0];
|
|
27
|
+
if (!path.startsWith(exports.WEBHOOK_PATH)) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
const [directory, ...rest] = path.slice(exports.WEBHOOK_PATH.length).split('/');
|
|
31
|
+
const name = ta_packages_1.TaPackages.BUILTIN.find(builtin => ta_packages_1.TaPackages.directoryName(builtin) === directory);
|
|
32
|
+
return name ? { name, path: rest.map(part => decodeURIComponent(part)).join('/') } : { name: '', path: '' };
|
|
33
|
+
}
|
|
34
|
+
PackageWebhookUtil.target = target;
|
|
35
|
+
/** The body as text; undefined when it is larger than TA_WEBHOOK_MAX_BYTES. */
|
|
36
|
+
async function body(request) {
|
|
37
|
+
const chunks = [];
|
|
38
|
+
let size = 0;
|
|
39
|
+
for await (const chunk of request) {
|
|
40
|
+
size += chunk.length;
|
|
41
|
+
if (size > ta_protocol_1.TA_WEBHOOK_MAX_BYTES) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
chunks.push(chunk);
|
|
45
|
+
}
|
|
46
|
+
return Buffer.concat(chunks).toString('utf8');
|
|
47
|
+
}
|
|
48
|
+
PackageWebhookUtil.body = body;
|
|
49
|
+
})(PackageWebhookUtil || (exports.PackageWebhookUtil = PackageWebhookUtil = {}));
|
|
50
|
+
function end(response, status, value) {
|
|
51
|
+
response.statusCode = status;
|
|
52
|
+
response.setHeader('Content-Type', 'application/json; charset=utf-8');
|
|
53
|
+
response.end(JSON.stringify(value));
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The webhooks of the packages that come with Ta (TaPackageService.webhook): a POST to `/api/hooks/<package>/<path>`
|
|
57
|
+
* goes to its host without the token of ta serve; the package checks the secret of its path. Anything else (another
|
|
58
|
+
* method, a package without a webhook, a secret it does not know) is a 404 that says nothing more.
|
|
59
|
+
*/
|
|
60
|
+
let PackageWebhooks = class PackageWebhooks {
|
|
61
|
+
constructor() {
|
|
62
|
+
/** Before TaAccess, which would ask for the token. */
|
|
63
|
+
this.priority = ta_access_1.ACCESS_MIDDLEWARE_PRIORITY + 2;
|
|
64
|
+
}
|
|
65
|
+
async handle(ctx, next) {
|
|
66
|
+
const request = ctx.request;
|
|
67
|
+
const target = PackageWebhookUtil.target(request);
|
|
68
|
+
if (!target) {
|
|
69
|
+
await next();
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const response = ctx.response;
|
|
73
|
+
// A page that rebinds its domain to a ta serve of 127.0.0.1 reaches nothing, as with TaAccess.
|
|
74
|
+
if (!target.name || request.method !== 'POST' || (ta_access_1.TaAccessUtil.isLoopbackHost(this.host) && !ta_access_1.TaAccessUtil.isLoopbackHost(request.headers.host))) {
|
|
75
|
+
end(response, 404, { error: 'Not found' });
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const body = await PackageWebhookUtil.body(request);
|
|
79
|
+
if (body === undefined) {
|
|
80
|
+
end(response, 413, { error: 'Too large' });
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
const answer = await this.hosts.call(target.name, 'webhook', [{ path: target.path, body, contentType: request.headers['content-type'] }]);
|
|
85
|
+
end(response, 202, answer !== null && answer !== void 0 ? answer : { ok: true });
|
|
86
|
+
}
|
|
87
|
+
catch (_a) {
|
|
88
|
+
end(response, 404, { error: 'Not found' });
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
exports.PackageWebhooks = PackageWebhooks;
|
|
93
|
+
__decorate([
|
|
94
|
+
(0, core_1.Autowired)(package_hosts_1.PackageHosts),
|
|
95
|
+
__metadata("design:type", Object)
|
|
96
|
+
], PackageWebhooks.prototype, "hosts", void 0);
|
|
97
|
+
__decorate([
|
|
98
|
+
(0, core_1.Value)('server.host'),
|
|
99
|
+
__metadata("design:type", String)
|
|
100
|
+
], PackageWebhooks.prototype, "host", void 0);
|
|
101
|
+
exports.PackageWebhooks = PackageWebhooks = __decorate([
|
|
102
|
+
(0, core_1.Component)(node_1.Middleware)
|
|
103
|
+
], PackageWebhooks);
|
|
104
|
+
//# sourceMappingURL=package-webhooks.js.map
|
|
@@ -0,0 +1,49 @@
|
|
|
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';
|
|
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
|
+
}
|
|
49
|
+
//# sourceMappingURL=page-book.d.ts.map
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.TaPageServerImpl = exports.DefaultTaPageBook = exports.PageChoice = exports.TaPageBook = void 0;
|
|
13
|
+
const core_1 = require("@celljs/core");
|
|
14
|
+
const rpc_1 = require("@celljs/rpc");
|
|
15
|
+
const node_1 = require("@celljs/rpc/lib/node");
|
|
16
|
+
const ta_protocol_1 = require("@celljs/ta-protocol");
|
|
17
|
+
const ta_errors_1 = require("./ta-errors");
|
|
18
|
+
const team_protocol_1 = require("./team/team-protocol");
|
|
19
|
+
exports.TaPageBook = Symbol('TaPageBook');
|
|
20
|
+
var PageChoice;
|
|
21
|
+
(function (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(entries) {
|
|
27
|
+
var _a, _b;
|
|
28
|
+
const latest = (list) => list.reduce((best, one) => (!best || one.activeAt > best.activeAt ? one : best), undefined);
|
|
29
|
+
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);
|
|
30
|
+
}
|
|
31
|
+
PageChoice.pick = pick;
|
|
32
|
+
/** What a page said of itself, made safe: only strings of kinds, a device it knows. */
|
|
33
|
+
function clean(info) {
|
|
34
|
+
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) : [];
|
|
35
|
+
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';
|
|
36
|
+
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 } : {}) };
|
|
37
|
+
}
|
|
38
|
+
PageChoice.clean = clean;
|
|
39
|
+
})(PageChoice || (exports.PageChoice = PageChoice = {}));
|
|
40
|
+
let DefaultTaPageBook = class DefaultTaPageBook {
|
|
41
|
+
constructor() {
|
|
42
|
+
this.entries = new Map();
|
|
43
|
+
}
|
|
44
|
+
attach(connection, info) {
|
|
45
|
+
if (connection.closed) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const before = this.entries.get(connection);
|
|
49
|
+
const clean = PageChoice.clean(info);
|
|
50
|
+
this.entries.set(connection, {
|
|
51
|
+
connection,
|
|
52
|
+
principal: this.principals.of(connection),
|
|
53
|
+
info: clean,
|
|
54
|
+
activeAt: (info === null || info === void 0 ? void 0 : info.active) === true || !before ? Date.now() : before.activeAt,
|
|
55
|
+
});
|
|
56
|
+
if (!before) {
|
|
57
|
+
connection.onClose(() => this.entries.delete(connection));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async ask(principal, kind, payload, timeoutMs = ta_protocol_1.TA_PAGE_ASK_MS) {
|
|
61
|
+
const page = PageChoice.pick(this.of(principal, kind));
|
|
62
|
+
if (!page) {
|
|
63
|
+
throw ta_errors_1.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.');
|
|
64
|
+
}
|
|
65
|
+
let timer;
|
|
66
|
+
try {
|
|
67
|
+
return await Promise.race([
|
|
68
|
+
page.connection.client(ta_protocol_1.TaClient).onPageAsk(kind, payload),
|
|
69
|
+
new Promise((_resolve, reject) => {
|
|
70
|
+
timer = setTimeout(() => reject(ta_errors_1.TaErrors.invalidArgument('The page of Ta did not answer in time.', 'Try again in a moment.')), timeoutMs);
|
|
71
|
+
}),
|
|
72
|
+
]);
|
|
73
|
+
}
|
|
74
|
+
finally {
|
|
75
|
+
clearTimeout(timer);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
has(principal, kind) {
|
|
79
|
+
return this.of(principal, kind).length > 0;
|
|
80
|
+
}
|
|
81
|
+
principalOf(options) {
|
|
82
|
+
var _a;
|
|
83
|
+
if (options.principal) {
|
|
84
|
+
return options.principal;
|
|
85
|
+
}
|
|
86
|
+
const team = this.teamProvider.team;
|
|
87
|
+
const actors = options.sessionFile ? team.actorsOf(options.sessionFile) : [team.current()];
|
|
88
|
+
return (_a = actors.find(actor => actor !== ta_protocol_1.TA_OWNER)) !== null && _a !== void 0 ? _a : ta_protocol_1.TA_OWNER;
|
|
89
|
+
}
|
|
90
|
+
of(principal, kind) {
|
|
91
|
+
return [...this.entries.values()].filter(entry => !entry.connection.closed && entry.principal === principal && entry.info.kinds.includes(kind));
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
exports.DefaultTaPageBook = DefaultTaPageBook;
|
|
95
|
+
__decorate([
|
|
96
|
+
(0, core_1.Autowired)(team_protocol_1.TaPrincipals),
|
|
97
|
+
__metadata("design:type", Object)
|
|
98
|
+
], DefaultTaPageBook.prototype, "principals", void 0);
|
|
99
|
+
__decorate([
|
|
100
|
+
(0, core_1.Autowired)({ id: team_protocol_1.TaHostTeamProvider, detached: true }),
|
|
101
|
+
__metadata("design:type", Object)
|
|
102
|
+
], DefaultTaPageBook.prototype, "teamProvider", void 0);
|
|
103
|
+
exports.DefaultTaPageBook = DefaultTaPageBook = __decorate([
|
|
104
|
+
(0, core_1.Component)(exports.TaPageBook)
|
|
105
|
+
], DefaultTaPageBook);
|
|
106
|
+
/** A page says which requests it answers (TaPageServer). */
|
|
107
|
+
let TaPageServerImpl = class TaPageServerImpl {
|
|
108
|
+
async attach(info) {
|
|
109
|
+
this.book.attach(node_1.RpcContext.requireConnection(), info);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
exports.TaPageServerImpl = TaPageServerImpl;
|
|
113
|
+
__decorate([
|
|
114
|
+
(0, core_1.Autowired)(exports.TaPageBook),
|
|
115
|
+
__metadata("design:type", Object)
|
|
116
|
+
], TaPageServerImpl.prototype, "book", void 0);
|
|
117
|
+
exports.TaPageServerImpl = TaPageServerImpl = __decorate([
|
|
118
|
+
(0, rpc_1.Rpc)(ta_protocol_1.TaPageServer)
|
|
119
|
+
], TaPageServerImpl);
|
|
120
|
+
//# 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;
|