@celljs/ta-host 4.18.0 → 4.20.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/account-service.d.ts +73 -0
- package/esm/node/account-service.js +304 -0
- package/esm/node/host-protocol.d.ts +2 -0
- package/esm/node/host-protocol.js +2 -0
- package/esm/node/index.d.ts +1 -0
- package/esm/node/index.js +1 -0
- package/esm/node/package-hosts.d.ts +10 -1
- package/esm/node/package-hosts.js +34 -6
- package/esm/node/relay-bridge.js +1 -1
- package/esm/node/rooms-bridge.d.ts +12 -3
- package/esm/node/rooms-bridge.js +29 -6
- package/esm/node/team/team-calls.js +10 -0
- package/lib/node/account-service.d.ts +74 -0
- package/lib/node/account-service.js +307 -0
- package/lib/node/host-protocol.d.ts +2 -0
- package/lib/node/host-protocol.js +3 -1
- package/lib/node/index.d.ts +1 -0
- package/lib/node/index.js +1 -0
- package/lib/node/package-hosts.d.ts +10 -1
- package/lib/node/package-hosts.js +33 -5
- package/lib/node/relay-bridge.js +1 -1
- package/lib/node/rooms-bridge.d.ts +12 -3
- package/lib/node/rooms-bridge.js +28 -5
- package/lib/node/team/team-calls.js +10 -0
- package/package.json +10 -10
|
@@ -172,6 +172,14 @@ const RULES = {
|
|
|
172
172
|
closeTerminal: fixed('commands.terminal'),
|
|
173
173
|
listTerminals: fixed('commands.terminal'),
|
|
174
174
|
},
|
|
175
|
+
TaAccountServer: {
|
|
176
|
+
getAccount: fixed('settings.view'),
|
|
177
|
+
signIn: fixed('settings.manage'),
|
|
178
|
+
cancelSignIn: fixed('settings.manage'),
|
|
179
|
+
approve: fixed('settings.manage'),
|
|
180
|
+
remove: fixed('settings.manage'),
|
|
181
|
+
signOut: fixed('settings.manage'),
|
|
182
|
+
},
|
|
175
183
|
TaRelayServer: {
|
|
176
184
|
getRelay: fixed('settings.view'),
|
|
177
185
|
pair: fixed('settings.manage'),
|
|
@@ -197,6 +205,8 @@ const RULES = {
|
|
|
197
205
|
TaRoomServer: Object.fromEntries([
|
|
198
206
|
'getIdentity',
|
|
199
207
|
'setName',
|
|
208
|
+
'setPicture',
|
|
209
|
+
'listPictures',
|
|
200
210
|
'listRooms',
|
|
201
211
|
'createRoom',
|
|
202
212
|
'invite',
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { type Application, ApplicationLifecycle } from '@celljs/core';
|
|
2
|
+
import { type TaAccountInfo, TaAccountServer } from '@celljs/ta-protocol';
|
|
3
|
+
import { AccountAgent, type AccountKept, type AccountView, type AccountWay } from '@celljs/ta-relay';
|
|
4
|
+
import { type RelayBridge } from './relay-bridge';
|
|
5
|
+
/** What a package hears from the same package on another computer of the account (TaAccountService.tell). */
|
|
6
|
+
export type TaAccountListener = (from: {
|
|
7
|
+
id: string;
|
|
8
|
+
name: string;
|
|
9
|
+
}, value: unknown) => void;
|
|
10
|
+
/**
|
|
11
|
+
* The account of this computer (docs/design/ta-account.md): signed in, it is in the user's list of devices; it lets
|
|
12
|
+
* in the devices the user lets in, pairs each with this ta serve through the relay, and unpairs those removed. What it
|
|
13
|
+
* keeps (its own keys, whom it trusts, its token) is in `account.json` of the agent directory, for the user alone.
|
|
14
|
+
*/
|
|
15
|
+
export declare class TaAccountService implements TaAccountServer, ApplicationLifecycle<Application> {
|
|
16
|
+
protected readonly bridge: RelayBridge;
|
|
17
|
+
protected agent?: AccountAgent;
|
|
18
|
+
protected view?: AccountView;
|
|
19
|
+
protected signingIn?: {
|
|
20
|
+
way: AccountWay;
|
|
21
|
+
handle: string;
|
|
22
|
+
code: string;
|
|
23
|
+
url: string;
|
|
24
|
+
interval: number;
|
|
25
|
+
expiresAt: number;
|
|
26
|
+
};
|
|
27
|
+
protected error?: string;
|
|
28
|
+
protected timer?: ReturnType<typeof setTimeout>;
|
|
29
|
+
protected running?: Promise<void>;
|
|
30
|
+
protected stopped: boolean;
|
|
31
|
+
protected readonly listeners: Map<string, Set<TaAccountListener>>;
|
|
32
|
+
get file(): string;
|
|
33
|
+
/** The name this computer goes by in the account. */
|
|
34
|
+
static computerName(): string;
|
|
35
|
+
onStart(): void;
|
|
36
|
+
onStop(): void;
|
|
37
|
+
protected read(): AccountKept | undefined;
|
|
38
|
+
protected write(kept: AccountKept): void;
|
|
39
|
+
protected service(): string;
|
|
40
|
+
/** The gateways whose accounts this computer may sign in with: of the deployment joined, and of this build. */
|
|
41
|
+
protected gateways(): string[];
|
|
42
|
+
protected agentOf(kept: AccountKept): AccountAgent;
|
|
43
|
+
/** Signed out by the service (removed, or the token no longer works): the devices it paired lose their way in. */
|
|
44
|
+
protected forget(): void;
|
|
45
|
+
protected schedule(after: number): void;
|
|
46
|
+
/** One round at a time: a sign-in polled, or the account synced. */
|
|
47
|
+
protected round(): Promise<void>;
|
|
48
|
+
protected pollSignIn(): Promise<number>;
|
|
49
|
+
getAccount(): Promise<TaAccountInfo>;
|
|
50
|
+
info(): Promise<TaAccountInfo>;
|
|
51
|
+
signIn(provider: string, service?: string): Promise<TaAccountInfo>;
|
|
52
|
+
protected begin(provider: string, service?: string): Promise<TaAccountInfo>;
|
|
53
|
+
cancelSignIn(): Promise<TaAccountInfo>;
|
|
54
|
+
protected act(run: (agent: AccountAgent) => Promise<AccountView>): Promise<TaAccountInfo>;
|
|
55
|
+
approve(id: string): Promise<TaAccountInfo>;
|
|
56
|
+
remove(id: string): Promise<TaAccountInfo>;
|
|
57
|
+
signOut(): Promise<TaAccountInfo>;
|
|
58
|
+
/** This computer in the account, once let in, for packages (TaExtensionHost.account). */
|
|
59
|
+
self(): {
|
|
60
|
+
id: string;
|
|
61
|
+
name: string;
|
|
62
|
+
} | undefined;
|
|
63
|
+
/** The other computers of the account this one trusts, for packages (TaExtensionHost.account). */
|
|
64
|
+
computers(): {
|
|
65
|
+
id: string;
|
|
66
|
+
name: string;
|
|
67
|
+
online: boolean;
|
|
68
|
+
}[];
|
|
69
|
+
/** Says `value` to a package on another computer of the account, sealed for it: it hears it on its next look. */
|
|
70
|
+
tell(to: string, topic: string, value: unknown): Promise<void>;
|
|
71
|
+
/** Hears what the same package on other computers of the account tells, by `topic`. */
|
|
72
|
+
onTold(topic: string, listener: TaAccountListener): () => void;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=account-service.d.ts.map
|
|
@@ -0,0 +1,307 @@
|
|
|
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
|
+
var TaAccountService_1;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.TaAccountService = void 0;
|
|
14
|
+
const node_fs_1 = require("node:fs");
|
|
15
|
+
const node_os_1 = require("node:os");
|
|
16
|
+
const node_path_1 = require("node:path");
|
|
17
|
+
const core_1 = require("@celljs/core");
|
|
18
|
+
const rpc_1 = require("@celljs/rpc");
|
|
19
|
+
const ta_brand_1 = require("@celljs/ta-harness/lib/node/ta-brand");
|
|
20
|
+
const ta_protocol_1 = require("@celljs/ta-protocol");
|
|
21
|
+
const ta_relay_1 = require("@celljs/ta-relay");
|
|
22
|
+
const host_protocol_1 = require("./host-protocol");
|
|
23
|
+
const relay_bridge_1 = require("./relay-bridge");
|
|
24
|
+
const ta_errors_1 = require("./ta-errors");
|
|
25
|
+
/** How often a computer says it is there and looks at its account; quicker while a device waits to be let in. */
|
|
26
|
+
const SYNC_MS = 20000;
|
|
27
|
+
const WAITING_SYNC_MS = 4000;
|
|
28
|
+
/**
|
|
29
|
+
* The account of this computer (docs/design/ta-account.md): signed in, it is in the user's list of devices; it lets
|
|
30
|
+
* in the devices the user lets in, pairs each with this ta serve through the relay, and unpairs those removed. What it
|
|
31
|
+
* keeps (its own keys, whom it trusts, its token) is in `account.json` of the agent directory, for the user alone.
|
|
32
|
+
*/
|
|
33
|
+
let TaAccountService = TaAccountService_1 = class TaAccountService {
|
|
34
|
+
constructor() {
|
|
35
|
+
this.stopped = false;
|
|
36
|
+
this.listeners = new Map();
|
|
37
|
+
}
|
|
38
|
+
get file() {
|
|
39
|
+
return (0, node_path_1.join)(ta_brand_1.TaBrand.agentDir(), 'account.json');
|
|
40
|
+
}
|
|
41
|
+
/** The name this computer goes by in the account. */
|
|
42
|
+
static computerName() {
|
|
43
|
+
return (0, node_os_1.hostname)().replace(/\.local$/, '');
|
|
44
|
+
}
|
|
45
|
+
onStart() {
|
|
46
|
+
const kept = this.read();
|
|
47
|
+
if (kept) {
|
|
48
|
+
this.agent = this.agentOf(kept);
|
|
49
|
+
this.schedule(0);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
onStop() {
|
|
53
|
+
this.stopped = true;
|
|
54
|
+
clearTimeout(this.timer);
|
|
55
|
+
}
|
|
56
|
+
read() {
|
|
57
|
+
var _a;
|
|
58
|
+
try {
|
|
59
|
+
const kept = JSON.parse((0, node_fs_1.readFileSync)(this.file, 'utf8'));
|
|
60
|
+
return (kept === null || kept === void 0 ? void 0 : kept.token) && ((_a = kept.self) === null || _a === void 0 ? void 0 : _a.signKey) ? kept : undefined;
|
|
61
|
+
}
|
|
62
|
+
catch (_b) {
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
write(kept) {
|
|
67
|
+
const temp = `${this.file}.${process.pid}.tmp`;
|
|
68
|
+
(0, node_fs_1.writeFileSync)(temp, `${JSON.stringify(kept, undefined, 2)}\n`, { mode: 0o600 });
|
|
69
|
+
(0, node_fs_1.chmodSync)(temp, 0o600);
|
|
70
|
+
(0, node_fs_1.renameSync)(temp, this.file);
|
|
71
|
+
}
|
|
72
|
+
service() {
|
|
73
|
+
return this.bridge.relayFor('devices');
|
|
74
|
+
}
|
|
75
|
+
/** The gateways whose accounts this computer may sign in with: of the deployment joined, and of this build. */
|
|
76
|
+
gateways() {
|
|
77
|
+
var _a, _b;
|
|
78
|
+
const joined = (_b = (_a = this.bridge.relays.safeRead().config) === null || _a === void 0 ? void 0 : _a.deployment) === null || _b === void 0 ? void 0 : _b.gateway;
|
|
79
|
+
return [joined, process.env.TA_GATEWAY_URL].filter((one) => !!one);
|
|
80
|
+
}
|
|
81
|
+
agentOf(kept) {
|
|
82
|
+
const store = this.bridge.store;
|
|
83
|
+
return new ta_relay_1.AccountAgent(kept, {
|
|
84
|
+
save: next => this.write(next),
|
|
85
|
+
name: () => TaAccountService_1.computerName(),
|
|
86
|
+
host: () => {
|
|
87
|
+
var _a;
|
|
88
|
+
const config = store.read();
|
|
89
|
+
return config.host ? { relay: (_a = config.url) !== null && _a !== void 0 ? _a : this.service(), id: config.host.id } : undefined;
|
|
90
|
+
},
|
|
91
|
+
pair: async (device) => {
|
|
92
|
+
const pairing = store.pair(this.service(), device.name, { account: device.id });
|
|
93
|
+
this.bridge.refresh();
|
|
94
|
+
return ta_relay_1.RelayPairingUtil.link({ ...pairing, name: TaAccountService_1.computerName() });
|
|
95
|
+
},
|
|
96
|
+
paired: () => store.read().devices.flatMap(device => (device.account ? [device.account] : [])),
|
|
97
|
+
unpair: id => {
|
|
98
|
+
for (const device of store.read().devices.filter(one => one.account === id)) {
|
|
99
|
+
store.remove(device.id);
|
|
100
|
+
}
|
|
101
|
+
this.bridge.refresh();
|
|
102
|
+
},
|
|
103
|
+
told: (from, topic, value) => {
|
|
104
|
+
var _a;
|
|
105
|
+
for (const listener of (_a = this.listeners.get(topic)) !== null && _a !== void 0 ? _a : []) {
|
|
106
|
+
try {
|
|
107
|
+
listener({ id: from.id, name: from.name }, value);
|
|
108
|
+
}
|
|
109
|
+
catch (_b) {
|
|
110
|
+
// A package's listener is its own.
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
signedOut: () => this.forget(),
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
/** Signed out by the service (removed, or the token no longer works): the devices it paired lose their way in. */
|
|
118
|
+
forget() {
|
|
119
|
+
const store = this.bridge.store;
|
|
120
|
+
for (const device of store.read().devices.filter(one => one.account)) {
|
|
121
|
+
store.remove(device.id);
|
|
122
|
+
}
|
|
123
|
+
this.bridge.refresh();
|
|
124
|
+
(0, node_fs_1.rmSync)(this.file, { force: true });
|
|
125
|
+
this.agent = undefined;
|
|
126
|
+
this.view = undefined;
|
|
127
|
+
}
|
|
128
|
+
schedule(after) {
|
|
129
|
+
var _a, _b;
|
|
130
|
+
clearTimeout(this.timer);
|
|
131
|
+
if (this.stopped || (!this.agent && !this.signingIn)) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
this.timer = setTimeout(() => void this.round(), after);
|
|
135
|
+
(_b = (_a = this.timer).unref) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
136
|
+
}
|
|
137
|
+
/** One round at a time: a sign-in polled, or the account synced. */
|
|
138
|
+
round() {
|
|
139
|
+
var _a;
|
|
140
|
+
(_a = this.running) !== null && _a !== void 0 ? _a : (this.running = (async () => {
|
|
141
|
+
let next = SYNC_MS;
|
|
142
|
+
try {
|
|
143
|
+
if (this.signingIn) {
|
|
144
|
+
next = await this.pollSignIn();
|
|
145
|
+
}
|
|
146
|
+
else if (this.agent) {
|
|
147
|
+
this.view = await this.agent.sync();
|
|
148
|
+
this.error = undefined;
|
|
149
|
+
if (this.view.waiting || this.view.devices.some(one => one.waiting)) {
|
|
150
|
+
next = WAITING_SYNC_MS;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
this.error = error instanceof Error ? error.message : String(error);
|
|
156
|
+
}
|
|
157
|
+
finally {
|
|
158
|
+
this.running = undefined;
|
|
159
|
+
}
|
|
160
|
+
this.schedule(next);
|
|
161
|
+
})());
|
|
162
|
+
return this.running;
|
|
163
|
+
}
|
|
164
|
+
async pollSignIn() {
|
|
165
|
+
const signing = this.signingIn;
|
|
166
|
+
if (Date.now() > signing.expiresAt) {
|
|
167
|
+
this.signingIn = undefined;
|
|
168
|
+
this.error = 'The sign-in ran out of time: begin it again.';
|
|
169
|
+
return SYNC_MS;
|
|
170
|
+
}
|
|
171
|
+
const answer = await ta_relay_1.AccountService.check(signing.way, signing.handle);
|
|
172
|
+
if (answer.status === 'pending') {
|
|
173
|
+
return signing.interval * 1000;
|
|
174
|
+
}
|
|
175
|
+
this.signingIn = undefined;
|
|
176
|
+
if (answer.status === 'failed') {
|
|
177
|
+
this.error = answer.error;
|
|
178
|
+
return SYNC_MS;
|
|
179
|
+
}
|
|
180
|
+
const kept = await ta_relay_1.AccountAgent.create(signing.way.service, answer.token, answer.account, 'computer', TaAccountService_1.computerName());
|
|
181
|
+
this.write(kept);
|
|
182
|
+
this.agent = this.agentOf(kept);
|
|
183
|
+
this.view = await this.agent.sync();
|
|
184
|
+
this.error = undefined;
|
|
185
|
+
return this.view.waiting ? WAITING_SYNC_MS : SYNC_MS;
|
|
186
|
+
}
|
|
187
|
+
getAccount() {
|
|
188
|
+
return ta_errors_1.TaErrors.guard(() => this.info());
|
|
189
|
+
}
|
|
190
|
+
async info() {
|
|
191
|
+
var _a, _b;
|
|
192
|
+
var _c, _d;
|
|
193
|
+
const service = (_d = (_c = (_a = this.agent) === null || _a === void 0 ? void 0 : _a.state.service) !== null && _c !== void 0 ? _c : (_b = this.signingIn) === null || _b === void 0 ? void 0 : _b.way.service) !== null && _d !== void 0 ? _d : this.service();
|
|
194
|
+
const error = this.error ? { error: this.error } : {};
|
|
195
|
+
if (!this.agent) {
|
|
196
|
+
const providers = await ta_relay_1.AccountService.ways(service, this.gateways()).catch(() => []);
|
|
197
|
+
const signing = this.signingIn;
|
|
198
|
+
return {
|
|
199
|
+
service,
|
|
200
|
+
providers,
|
|
201
|
+
devices: [],
|
|
202
|
+
...(signing ? { signingIn: { provider: signing.way.id, code: signing.code, url: signing.url, expiresAt: signing.expiresAt } } : {}),
|
|
203
|
+
...error,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
if (!this.view) {
|
|
207
|
+
await this.round();
|
|
208
|
+
}
|
|
209
|
+
const view = this.view;
|
|
210
|
+
if (!view) {
|
|
211
|
+
return { service, providers: [], account: this.agent.state.account, devices: [], ...error };
|
|
212
|
+
}
|
|
213
|
+
const pairings = this.agent.state.pairings;
|
|
214
|
+
const devices = view.devices.map(({ trusted: _trusted, ...device }) => ({
|
|
215
|
+
...device,
|
|
216
|
+
...(device.kind === 'computer' && pairings[device.id] ? { pairing: pairings[device.id] } : {}),
|
|
217
|
+
}));
|
|
218
|
+
return { service, providers: [], account: view.account, waiting: view.waiting, code: view.code, devices, ...error };
|
|
219
|
+
}
|
|
220
|
+
signIn(provider, service) {
|
|
221
|
+
return ta_errors_1.TaErrors.guard(() => this.begin(String(provider !== null && provider !== void 0 ? provider : ''), typeof service === 'string' ? service : undefined));
|
|
222
|
+
}
|
|
223
|
+
async begin(provider, service) {
|
|
224
|
+
if (this.agent) {
|
|
225
|
+
return this.info();
|
|
226
|
+
}
|
|
227
|
+
const ways = await ta_relay_1.AccountService.ways(this.service(), this.gateways());
|
|
228
|
+
const way = ways.find(one => one.id === provider && (service === undefined || one.service === service));
|
|
229
|
+
if (!way) {
|
|
230
|
+
throw new ta_relay_1.AccountCallError(404, `No way to sign in with ${provider} here.`);
|
|
231
|
+
}
|
|
232
|
+
const start = await ta_relay_1.AccountService.begin(way, TaAccountService_1.computerName());
|
|
233
|
+
this.signingIn = { way, ...start, expiresAt: Date.now() + start.expiresIn * 1000 };
|
|
234
|
+
this.error = undefined;
|
|
235
|
+
this.schedule(start.interval * 1000);
|
|
236
|
+
return this.info();
|
|
237
|
+
}
|
|
238
|
+
async cancelSignIn() {
|
|
239
|
+
this.signingIn = undefined;
|
|
240
|
+
return this.info();
|
|
241
|
+
}
|
|
242
|
+
act(run) {
|
|
243
|
+
return ta_errors_1.TaErrors.guard(async () => {
|
|
244
|
+
if (!this.agent) {
|
|
245
|
+
throw ta_errors_1.TaErrors.invalidArgument('This computer is not signed in to an account.', 'Sign in first.');
|
|
246
|
+
}
|
|
247
|
+
this.view = await run(this.agent);
|
|
248
|
+
this.schedule(this.view.devices.some(one => one.waiting) ? WAITING_SYNC_MS : SYNC_MS);
|
|
249
|
+
return this.info();
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
approve(id) {
|
|
253
|
+
return this.act(agent => agent.approve(String(id !== null && id !== void 0 ? id : '')));
|
|
254
|
+
}
|
|
255
|
+
remove(id) {
|
|
256
|
+
return this.act(agent => agent.remove(String(id !== null && id !== void 0 ? id : '')));
|
|
257
|
+
}
|
|
258
|
+
signOut() {
|
|
259
|
+
return ta_errors_1.TaErrors.guard(async () => {
|
|
260
|
+
if (this.agent) {
|
|
261
|
+
await this.agent.signOut();
|
|
262
|
+
this.forget();
|
|
263
|
+
}
|
|
264
|
+
this.error = undefined;
|
|
265
|
+
return this.info();
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
/** This computer in the account, once let in, for packages (TaExtensionHost.account). */
|
|
269
|
+
self() {
|
|
270
|
+
const me = this.view && !this.view.waiting ? this.view.devices.find(one => one.self) : undefined;
|
|
271
|
+
return me ? { id: me.id, name: me.name } : undefined;
|
|
272
|
+
}
|
|
273
|
+
/** The other computers of the account this one trusts, for packages (TaExtensionHost.account). */
|
|
274
|
+
computers() {
|
|
275
|
+
var _a;
|
|
276
|
+
var _b;
|
|
277
|
+
return ((_b = (_a = this.view) === null || _a === void 0 ? void 0 : _a.devices) !== null && _b !== void 0 ? _b : [])
|
|
278
|
+
.filter(one => one.kind === 'computer' && one.trusted && !one.self)
|
|
279
|
+
.map(one => ({ id: one.id, name: one.name, online: one.online }));
|
|
280
|
+
}
|
|
281
|
+
/** Says `value` to a package on another computer of the account, sealed for it: it hears it on its next look. */
|
|
282
|
+
async tell(to, topic, value) {
|
|
283
|
+
if (!this.agent) {
|
|
284
|
+
throw new ta_relay_1.AccountCallError(401, 'Sign in to an account first.');
|
|
285
|
+
}
|
|
286
|
+
await this.agent.tell(to, topic, value);
|
|
287
|
+
}
|
|
288
|
+
/** Hears what the same package on other computers of the account tells, by `topic`. */
|
|
289
|
+
onTold(topic, listener) {
|
|
290
|
+
let set = this.listeners.get(topic);
|
|
291
|
+
if (!set) {
|
|
292
|
+
set = new Set();
|
|
293
|
+
this.listeners.set(topic, set);
|
|
294
|
+
}
|
|
295
|
+
set.add(listener);
|
|
296
|
+
return () => set.delete(listener);
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
exports.TaAccountService = TaAccountService;
|
|
300
|
+
__decorate([
|
|
301
|
+
(0, core_1.Autowired)(relay_bridge_1.RELAY_BRIDGE),
|
|
302
|
+
__metadata("design:type", Function)
|
|
303
|
+
], TaAccountService.prototype, "bridge", void 0);
|
|
304
|
+
exports.TaAccountService = TaAccountService = TaAccountService_1 = __decorate([
|
|
305
|
+
(0, rpc_1.Rpc)([ta_protocol_1.TaAccountServer, host_protocol_1.TA_ACCOUNT, core_1.ApplicationLifecycle])
|
|
306
|
+
], TaAccountService);
|
|
307
|
+
//# sourceMappingURL=account-service.js.map
|
|
@@ -123,4 +123,6 @@ export interface TaPresenceBook {
|
|
|
123
123
|
/** What `people` gives may have changed. */
|
|
124
124
|
onChange(listener: () => void): () => void;
|
|
125
125
|
}
|
|
126
|
+
/** TaAccountService (account-service.ts): the account of this computer, by this symbol so that the relay bridge needs no import of it. */
|
|
127
|
+
export declare const TA_ACCOUNT: unique symbol;
|
|
126
128
|
//# sourceMappingURL=host-protocol.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TA_EXEC_OPTIONS = exports.TA_HOST_OPTIONS = exports.TaPresenceBook = exports.KeepAwake = exports.WebExtensionCatalog = exports.TaSessionCatalog = exports.TaSessionRegistry = exports.TaSessionFactory = void 0;
|
|
3
|
+
exports.TA_ACCOUNT = exports.TA_EXEC_OPTIONS = exports.TA_HOST_OPTIONS = exports.TaPresenceBook = exports.KeepAwake = exports.WebExtensionCatalog = exports.TaSessionCatalog = exports.TaSessionRegistry = exports.TaSessionFactory = void 0;
|
|
4
4
|
exports.TaSessionFactory = Symbol('TaSessionFactory');
|
|
5
5
|
exports.TaSessionRegistry = Symbol('TaSessionRegistry');
|
|
6
6
|
exports.TaSessionCatalog = Symbol('TaSessionCatalog');
|
|
@@ -9,4 +9,6 @@ exports.KeepAwake = Symbol('KeepAwake');
|
|
|
9
9
|
exports.TaPresenceBook = Symbol('TaPresenceBook');
|
|
10
10
|
exports.TA_HOST_OPTIONS = 'ta.host';
|
|
11
11
|
exports.TA_EXEC_OPTIONS = 'ta.exec';
|
|
12
|
+
/** TaAccountService (account-service.ts): the account of this computer, by this symbol so that the relay bridge needs no import of it. */
|
|
13
|
+
exports.TA_ACCOUNT = Symbol('TaAccount');
|
|
12
14
|
//# sourceMappingURL=host-protocol.js.map
|
package/lib/node/index.d.ts
CHANGED
package/lib/node/index.js
CHANGED
|
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./account-service"), exports);
|
|
17
18
|
__exportStar(require("./app-commands"), exports);
|
|
18
19
|
__exportStar(require("./auth-server-impl"), exports);
|
|
19
20
|
__exportStar(require("./client-channel"), exports);
|
|
@@ -1,6 +1,7 @@
|
|
|
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 type { TaAccountService } from './account-service';
|
|
4
5
|
import { TaAppCommands } from './app-commands';
|
|
5
6
|
import { TaCredentials } from './credentials';
|
|
6
7
|
import { ExtensionDataStore } from './extension-data';
|
|
@@ -57,6 +58,7 @@ export declare class PackageHostsImpl implements PackageHosts, ApplicationLifecy
|
|
|
57
58
|
protected readonly server: TaServer;
|
|
58
59
|
protected readonly packages: TaPackageServer;
|
|
59
60
|
protected readonly relay: RelayBridge;
|
|
61
|
+
protected readonly account: TaAccountService;
|
|
60
62
|
protected readonly roomsBridge: RoomsBridge;
|
|
61
63
|
protected readonly voiceBridge: VoiceBridge;
|
|
62
64
|
protected readonly credentials: TaCredentials;
|
|
@@ -68,7 +70,14 @@ export declare class PackageHostsImpl implements PackageHosts, ApplicationLifecy
|
|
|
68
70
|
protected readonly teamProvider: TaHostTeamProvider;
|
|
69
71
|
protected readonly running: Map<string, Running>;
|
|
70
72
|
protected extensionHost?: TaExtensionHost;
|
|
71
|
-
|
|
73
|
+
/** The first {@link sync}, begun once the server listens: what asks a host waits for it. */
|
|
74
|
+
protected starting: Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Not awaited: importing two dozen hosts took half of the start of ta serve (60 of 115 ms), and nothing the server
|
|
77
|
+
* answers first needs them. They start after it listens, one a turn of the event loop, so that the first page comes
|
|
78
|
+
* between; {@link answer} and {@link call} wait for them.
|
|
79
|
+
*/
|
|
80
|
+
onStart(): void;
|
|
72
81
|
onStop(): void;
|
|
73
82
|
sync(): Promise<void>;
|
|
74
83
|
answer(name: string): Promise<Omit<TaHostAnswer, 'files'>>;
|
|
@@ -96,9 +96,18 @@ var PackageHostUtil;
|
|
|
96
96
|
let PackageHostsImpl = class PackageHostsImpl {
|
|
97
97
|
constructor() {
|
|
98
98
|
this.running = new Map();
|
|
99
|
+
/** The first {@link sync}, begun once the server listens: what asks a host waits for it. */
|
|
100
|
+
this.starting = Promise.resolve();
|
|
99
101
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
+
/**
|
|
103
|
+
* Not awaited: importing two dozen hosts took half of the start of ta serve (60 of 115 ms), and nothing the server
|
|
104
|
+
* answers first needs them. They start after it listens, one a turn of the event loop, so that the first page comes
|
|
105
|
+
* between; {@link answer} and {@link call} wait for them.
|
|
106
|
+
*/
|
|
107
|
+
onStart() {
|
|
108
|
+
this.starting = new Promise(resolve => setImmediate(resolve))
|
|
109
|
+
.then(() => this.sync())
|
|
110
|
+
.catch(error => console.error(`The hosts of the packages failed to start: ${error instanceof Error ? error.message : error}`));
|
|
102
111
|
}
|
|
103
112
|
onStop() {
|
|
104
113
|
for (const name of [...this.running.keys()]) {
|
|
@@ -112,18 +121,23 @@ let PackageHostsImpl = class PackageHostsImpl {
|
|
|
112
121
|
await this.stop(name);
|
|
113
122
|
}
|
|
114
123
|
}
|
|
115
|
-
|
|
124
|
+
const started = [];
|
|
125
|
+
for (const [name, file] of on) {
|
|
116
126
|
if (file && !this.running.has(name)) {
|
|
117
|
-
|
|
127
|
+
started.push(this.start(name, file).service);
|
|
128
|
+
await new Promise(resolve => setImmediate(resolve));
|
|
118
129
|
}
|
|
119
|
-
}
|
|
130
|
+
}
|
|
131
|
+
await Promise.all(started);
|
|
120
132
|
}
|
|
121
133
|
async answer(name) {
|
|
122
134
|
var _a;
|
|
135
|
+
await this.starting;
|
|
123
136
|
return { host: this.hostOf(name), service: await ((_a = this.running.get(name)) === null || _a === void 0 ? void 0 : _a.service) };
|
|
124
137
|
}
|
|
125
138
|
async call(name, method, params) {
|
|
126
139
|
var _a;
|
|
140
|
+
await this.starting;
|
|
127
141
|
const service = (await ((_a = this.running.get(name)) === null || _a === void 0 ? void 0 : _a.service));
|
|
128
142
|
if (!service) {
|
|
129
143
|
throw ta_errors_1.TaErrors.invalidArgument(`The package ${name} has no host running.`, 'Only packages that come with Ta and are on have one, under ta serve; turn it on, or see the log of ta serve for why it failed.');
|
|
@@ -185,6 +199,13 @@ let PackageHostsImpl = class PackageHostsImpl {
|
|
|
185
199
|
},
|
|
186
200
|
prompt: (sessionId, input) => host.prompt(sessionId, mark(input)),
|
|
187
201
|
followUp: (sessionId, input) => host.followUp(sessionId, mark(input)),
|
|
202
|
+
// A package speaks with itself on the user's other computers, under its own name.
|
|
203
|
+
account: {
|
|
204
|
+
self: async () => this.account.self(),
|
|
205
|
+
computers: async () => this.account.computers(),
|
|
206
|
+
tell: (to, value) => this.account.tell(to, name, value),
|
|
207
|
+
onTold: listener => this.account.onTold(name, listener),
|
|
208
|
+
},
|
|
188
209
|
};
|
|
189
210
|
}
|
|
190
211
|
host() {
|
|
@@ -213,11 +234,14 @@ let PackageHostsImpl = class PackageHostsImpl {
|
|
|
213
234
|
openSession: options => server.openSession(options),
|
|
214
235
|
closeSession: sessionId => server.closeSession(sessionId),
|
|
215
236
|
setSessionName: (sessionId, name) => server.setSessionName(sessionId, name),
|
|
237
|
+
setModel: (sessionId, provider, modelId) => server.setModel(sessionId, provider, modelId),
|
|
216
238
|
prompt: (sessionId, input) => server.prompt(sessionId, input),
|
|
217
239
|
followUp: (sessionId, input) => server.followUp(sessionId, input),
|
|
218
240
|
abort: sessionId => server.abort(sessionId),
|
|
219
241
|
getState: sessionId => server.getState(sessionId),
|
|
220
242
|
getLastAssistantText: sessionId => server.getLastAssistantText(sessionId),
|
|
243
|
+
getSessionStats: sessionId => server.getSessionStats(sessionId),
|
|
244
|
+
getEntries: (sessionId, since) => server.getEntries(sessionId, since),
|
|
221
245
|
relocateDirectory: (from, to) => server.relocateDirectory(from, to),
|
|
222
246
|
getExtensionData: (name, key, cwd) => packages.getExtensionData(name, key, cwd),
|
|
223
247
|
setExtensionData: (name, key, value, cwd) => packages.setExtensionData(name, key, value, cwd),
|
|
@@ -298,6 +322,10 @@ __decorate([
|
|
|
298
322
|
(0, core_1.Autowired)({ id: relay_bridge_1.RELAY_BRIDGE, detached: true }),
|
|
299
323
|
__metadata("design:type", Function)
|
|
300
324
|
], PackageHostsImpl.prototype, "relay", void 0);
|
|
325
|
+
__decorate([
|
|
326
|
+
(0, core_1.Autowired)({ id: host_protocol_1.TA_ACCOUNT, detached: true }),
|
|
327
|
+
__metadata("design:type", Function)
|
|
328
|
+
], PackageHostsImpl.prototype, "account", void 0);
|
|
301
329
|
__decorate([
|
|
302
330
|
(0, core_1.Autowired)({ id: rooms_bridge_1.ROOMS_BRIDGE, detached: true }),
|
|
303
331
|
__metadata("design:type", Function)
|
package/lib/node/relay-bridge.js
CHANGED
|
@@ -355,7 +355,7 @@ let TaRelayServerImpl = class TaRelayServerImpl {
|
|
|
355
355
|
defaultRelay: relay,
|
|
356
356
|
online: this.bridge.online,
|
|
357
357
|
// Those of people let in are theirs, not the user's: ta-team lists them.
|
|
358
|
-
devices: devices.filter(each => !each.member).map(each => device({ ...each, relay: node_1.RelayStore.relayOf(each, config) })),
|
|
358
|
+
devices: devices.filter(each => !each.member && !each.account).map(each => device({ ...each, relay: node_1.RelayStore.relayOf(each, config) })),
|
|
359
359
|
...(this.keepAwake.supported ? { keepAwake: keepAwake !== false } : {}),
|
|
360
360
|
};
|
|
361
361
|
}
|
|
@@ -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 TaFriendShare, type TaGroupInvite, 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 TaPictures, 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';
|
|
6
6
|
import { type RelayBridge } from './relay-bridge';
|
|
@@ -21,12 +21,19 @@ export declare class RoomsBridge implements ApplicationLifecycle<Application> {
|
|
|
21
21
|
readonly rooms: TaRooms;
|
|
22
22
|
onStart(): void;
|
|
23
23
|
onStop(): void;
|
|
24
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* The look of this Ta others see is the double's, as the user picked it on a page (TA_DOUBLE_LOOK); till then the
|
|
26
|
+
* kind its identity is given, kept there for the pages to draw the double as (setting it comes back here).
|
|
27
|
+
*/
|
|
25
28
|
protected keepLook(): Promise<void>;
|
|
26
29
|
/** `watch` undefined: no more. */
|
|
27
30
|
watch(connection: RpcConnection, watch: TaRoomWatch | undefined): void;
|
|
28
31
|
protected broadcast(event: TaRoomEvent): void;
|
|
29
|
-
|
|
32
|
+
/** The picture of this Ta, for what is said of it after a change that does not give it. */
|
|
33
|
+
protected picture(): Promise<{
|
|
34
|
+
picture?: string;
|
|
35
|
+
}>;
|
|
36
|
+
protected static identity({ id, name, look, shared, picture }: TaIdentity): TaIdentity;
|
|
30
37
|
}
|
|
31
38
|
/** The rooms for clients (TaRoomServer): those of RoomsBridge, what goes wrong said as the errors of Ta. */
|
|
32
39
|
export declare class TaRoomServerImpl implements TaRoomServer {
|
|
@@ -34,6 +41,8 @@ export declare class TaRoomServerImpl implements TaRoomServer {
|
|
|
34
41
|
protected get rooms(): TaRooms;
|
|
35
42
|
getIdentity(): Promise<TaIdentity>;
|
|
36
43
|
setName(name: string): Promise<TaIdentity>;
|
|
44
|
+
setPicture(picture: string | null): Promise<TaIdentity>;
|
|
45
|
+
listPictures(): Promise<TaPictures>;
|
|
37
46
|
listRooms(): Promise<TaRoomInfo[]>;
|
|
38
47
|
createRoom(input: {
|
|
39
48
|
kind: string;
|