@celljs/ta-host 4.19.0 → 4.21.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-profile.d.ts +82 -0
- package/esm/node/account-profile.js +190 -0
- package/esm/node/account-service.d.ts +15 -0
- package/esm/node/account-service.js +48 -2
- package/esm/node/index.d.ts +1 -0
- package/esm/node/index.js +1 -0
- package/esm/node/package-hosts.d.ts +8 -1
- package/esm/node/package-hosts.js +22 -5
- package/esm/node/rooms-bridge.d.ts +14 -3
- package/esm/node/rooms-bridge.js +35 -8
- package/esm/node/settings-store.js +4 -2
- package/esm/node/team/team-calls.js +4 -0
- package/lib/node/account-profile.d.ts +83 -0
- package/lib/node/account-profile.js +194 -0
- package/lib/node/account-service.d.ts +15 -0
- package/lib/node/account-service.js +48 -2
- package/lib/node/index.d.ts +1 -0
- package/lib/node/index.js +1 -0
- package/lib/node/package-hosts.d.ts +8 -1
- package/lib/node/package-hosts.js +22 -5
- package/lib/node/rooms-bridge.d.ts +14 -3
- package/lib/node/rooms-bridge.js +34 -7
- package/lib/node/settings-store.js +3 -1
- package/lib/node/team/team-calls.js +4 -0
- package/package.json +10 -10
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { type Application, ApplicationLifecycle } from '@celljs/core';
|
|
2
|
+
import type { TaIdentity } from '@celljs/ta-protocol';
|
|
3
|
+
import { TaAccountService } from './account-service';
|
|
4
|
+
import { type RoomsBridge } from './rooms-bridge';
|
|
5
|
+
/** What the computers of an account tell each other of the user (docs/design/ta-me.md 3). */
|
|
6
|
+
export declare const ACCOUNT_PROFILE_TOPIC = "ta.profile";
|
|
7
|
+
/** The user as others see them: their name and picture, and when they last changed it (0: never, by hand). */
|
|
8
|
+
export interface AccountProfileValue {
|
|
9
|
+
name: string;
|
|
10
|
+
picture: string | null;
|
|
11
|
+
at: number;
|
|
12
|
+
}
|
|
13
|
+
/** What this computer keeps of the profile: of which account, when it changed, and what each computer of it was told. */
|
|
14
|
+
export interface AccountProfileState {
|
|
15
|
+
account: string;
|
|
16
|
+
at: number;
|
|
17
|
+
/** Of the name and the picture, to tell a change made here. */
|
|
18
|
+
hash: string;
|
|
19
|
+
/** By computer: the `at` it was told last. */
|
|
20
|
+
told: Record<string, number>;
|
|
21
|
+
}
|
|
22
|
+
/** What the profile needs of ta serve: the identity, the account, and where to keep its state. */
|
|
23
|
+
export interface AccountProfileSide {
|
|
24
|
+
identity(): Promise<TaIdentity>;
|
|
25
|
+
setName(name: string): Promise<TaIdentity>;
|
|
26
|
+
setPicture(picture: string | null): Promise<TaIdentity>;
|
|
27
|
+
/** The name a new identity gets (the user's on this system): one never chosen. */
|
|
28
|
+
defaultName(): string;
|
|
29
|
+
/** The account this computer is in, once let in. */
|
|
30
|
+
account(): {
|
|
31
|
+
id: string;
|
|
32
|
+
name: string;
|
|
33
|
+
} | undefined;
|
|
34
|
+
computers(): {
|
|
35
|
+
id: string;
|
|
36
|
+
}[];
|
|
37
|
+
tell(to: string, value: AccountProfileValue): Promise<void>;
|
|
38
|
+
read(): AccountProfileState | undefined;
|
|
39
|
+
write(state: AccountProfileState | undefined): void;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The name and the picture of the user, shared by the computers of their account (docs/design/ta-me.md 3): the first
|
|
43
|
+
* sign-in names the user as the account does, unless they chose a name; then a change on one computer goes to the
|
|
44
|
+
* others, the latest kept. Only the name and the picture: the keys of each identity stay its own (ta-sync shares them).
|
|
45
|
+
*/
|
|
46
|
+
export declare class AccountProfile {
|
|
47
|
+
protected readonly side: AccountProfileSide;
|
|
48
|
+
protected readonly now: () => number;
|
|
49
|
+
protected running?: Promise<void>;
|
|
50
|
+
constructor(side: AccountProfileSide, now?: () => number);
|
|
51
|
+
static hash(identity: Pick<TaIdentity, 'name' | 'picture'>): string;
|
|
52
|
+
/** What the user is called in an account: its name, without the way it came by (`iam:su` is su). */
|
|
53
|
+
static nameOf(account: {
|
|
54
|
+
name: string;
|
|
55
|
+
}): string;
|
|
56
|
+
static valid(value: unknown): value is AccountProfileValue;
|
|
57
|
+
/** One look, one at a time: a change here noted, and told to the computers that have not heard it. */
|
|
58
|
+
round(): Promise<void>;
|
|
59
|
+
protected look(): Promise<void>;
|
|
60
|
+
/** In an account for the first time: named as the account, when the user never chose a name here. */
|
|
61
|
+
protected first(account: {
|
|
62
|
+
id: string;
|
|
63
|
+
name: string;
|
|
64
|
+
}, identity: TaIdentity): Promise<AccountProfileState>;
|
|
65
|
+
/** What another computer of the account told: taken when it is newer than what is here. */
|
|
66
|
+
heard(from: {
|
|
67
|
+
id: string;
|
|
68
|
+
}, value: unknown): Promise<void>;
|
|
69
|
+
}
|
|
70
|
+
/** AccountProfile for ta serve: TaAccountService and the identity of RoomsBridge; its state in `account-profile.json`. */
|
|
71
|
+
export declare class AccountProfileSync implements ApplicationLifecycle<Application> {
|
|
72
|
+
protected readonly account: TaAccountService;
|
|
73
|
+
protected readonly rooms: RoomsBridge;
|
|
74
|
+
protected profile?: AccountProfile;
|
|
75
|
+
protected timer?: ReturnType<typeof setInterval>;
|
|
76
|
+
protected stopTold?: () => void;
|
|
77
|
+
get file(): string;
|
|
78
|
+
onStart(): void;
|
|
79
|
+
onStop(): void;
|
|
80
|
+
protected read(): AccountProfileState | undefined;
|
|
81
|
+
protected write(state: AccountProfileState | undefined): void;
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=account-profile.d.ts.map
|
|
@@ -0,0 +1,194 @@
|
|
|
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.AccountProfileSync = exports.AccountProfile = exports.ACCOUNT_PROFILE_TOPIC = void 0;
|
|
13
|
+
const node_fs_1 = require("node:fs");
|
|
14
|
+
const node_path_1 = require("node:path");
|
|
15
|
+
const core_1 = require("@celljs/core");
|
|
16
|
+
const ta_brand_1 = require("@celljs/ta-harness/lib/node/ta-brand");
|
|
17
|
+
const node_1 = require("@celljs/ta-relay/lib/node");
|
|
18
|
+
const account_service_1 = require("./account-service");
|
|
19
|
+
const host_protocol_1 = require("./host-protocol");
|
|
20
|
+
const rooms_bridge_1 = require("./rooms-bridge");
|
|
21
|
+
/** What the computers of an account tell each other of the user (docs/design/ta-me.md 3). */
|
|
22
|
+
exports.ACCOUNT_PROFILE_TOPIC = 'ta.profile';
|
|
23
|
+
/**
|
|
24
|
+
* The name and the picture of the user, shared by the computers of their account (docs/design/ta-me.md 3): the first
|
|
25
|
+
* sign-in names the user as the account does, unless they chose a name; then a change on one computer goes to the
|
|
26
|
+
* others, the latest kept. Only the name and the picture: the keys of each identity stay its own (ta-sync shares them).
|
|
27
|
+
*/
|
|
28
|
+
class AccountProfile {
|
|
29
|
+
constructor(side, now = Date.now) {
|
|
30
|
+
this.side = side;
|
|
31
|
+
this.now = now;
|
|
32
|
+
}
|
|
33
|
+
static hash(identity) {
|
|
34
|
+
var _a;
|
|
35
|
+
const text = `${identity.name}\n${(_a = identity.picture) !== null && _a !== void 0 ? _a : ''}`;
|
|
36
|
+
let hash = 2166136261;
|
|
37
|
+
for (let index = 0; index < text.length; index++) {
|
|
38
|
+
hash = Math.imul(hash ^ text.charCodeAt(index), 16777619);
|
|
39
|
+
}
|
|
40
|
+
return `${text.length}:${(hash >>> 0).toString(36)}`;
|
|
41
|
+
}
|
|
42
|
+
/** What the user is called in an account: its name, without the way it came by (`iam:su` is su). */
|
|
43
|
+
static nameOf(account) {
|
|
44
|
+
return account.name.replace(/^[a-z][\w-]*:/i, '').trim();
|
|
45
|
+
}
|
|
46
|
+
static valid(value) {
|
|
47
|
+
const one = value;
|
|
48
|
+
return (typeof (one === null || one === void 0 ? void 0 : one.name) === 'string' &&
|
|
49
|
+
one.name.trim().length > 0 &&
|
|
50
|
+
(one.picture === null || typeof one.picture === 'string') &&
|
|
51
|
+
typeof one.at === 'number' &&
|
|
52
|
+
one.at > 0);
|
|
53
|
+
}
|
|
54
|
+
/** One look, one at a time: a change here noted, and told to the computers that have not heard it. */
|
|
55
|
+
round() {
|
|
56
|
+
var _a;
|
|
57
|
+
(_a = this.running) !== null && _a !== void 0 ? _a : (this.running = this.look().finally(() => {
|
|
58
|
+
this.running = undefined;
|
|
59
|
+
}));
|
|
60
|
+
return this.running;
|
|
61
|
+
}
|
|
62
|
+
async look() {
|
|
63
|
+
var _a;
|
|
64
|
+
const account = this.side.account();
|
|
65
|
+
let state = this.side.read();
|
|
66
|
+
if (!account) {
|
|
67
|
+
if (state) {
|
|
68
|
+
this.side.write(undefined);
|
|
69
|
+
}
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
let identity = await this.side.identity();
|
|
73
|
+
if ((state === null || state === void 0 ? void 0 : state.account) !== account.id) {
|
|
74
|
+
state = await this.first(account, identity);
|
|
75
|
+
identity = await this.side.identity();
|
|
76
|
+
}
|
|
77
|
+
else if (AccountProfile.hash(identity) !== state.hash) {
|
|
78
|
+
state = { ...state, at: this.now(), hash: AccountProfile.hash(identity) };
|
|
79
|
+
}
|
|
80
|
+
if (state.at > 0) {
|
|
81
|
+
const value = { name: identity.name, picture: (_a = identity.picture) !== null && _a !== void 0 ? _a : null, at: state.at };
|
|
82
|
+
for (const computer of this.side.computers()) {
|
|
83
|
+
if (state.told[computer.id] !== state.at) {
|
|
84
|
+
try {
|
|
85
|
+
await this.side.tell(computer.id, value);
|
|
86
|
+
state = { ...state, told: { ...state.told, [computer.id]: state.at } };
|
|
87
|
+
}
|
|
88
|
+
catch (_b) {
|
|
89
|
+
// Told on the next look.
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
this.side.write(state);
|
|
95
|
+
}
|
|
96
|
+
/** In an account for the first time: named as the account, when the user never chose a name here. */
|
|
97
|
+
async first(account, identity) {
|
|
98
|
+
const chosen = identity.name !== this.side.defaultName() || Boolean(identity.picture);
|
|
99
|
+
const name = AccountProfile.nameOf(account);
|
|
100
|
+
if (!chosen && name && name !== identity.name) {
|
|
101
|
+
identity = await this.side.setName(name).catch(() => identity);
|
|
102
|
+
}
|
|
103
|
+
return { account: account.id, at: chosen ? this.now() : 0, hash: AccountProfile.hash(identity), told: {} };
|
|
104
|
+
}
|
|
105
|
+
/** What another computer of the account told: taken when it is newer than what is here. */
|
|
106
|
+
async heard(from, value) {
|
|
107
|
+
var _a;
|
|
108
|
+
await this.running;
|
|
109
|
+
const account = this.side.account();
|
|
110
|
+
const state = this.side.read();
|
|
111
|
+
if (!account || !AccountProfile.valid(value) || ((state === null || state === void 0 ? void 0 : state.account) === account.id && value.at <= state.at)) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
let identity = await this.side.identity();
|
|
115
|
+
if (identity.name !== value.name.trim()) {
|
|
116
|
+
identity = await this.side.setName(value.name);
|
|
117
|
+
}
|
|
118
|
+
if (((_a = identity.picture) !== null && _a !== void 0 ? _a : null) !== value.picture) {
|
|
119
|
+
identity = await this.side.setPicture(value.picture);
|
|
120
|
+
}
|
|
121
|
+
const told = (state === null || state === void 0 ? void 0 : state.account) === account.id ? state.told : {};
|
|
122
|
+
this.side.write({ account: account.id, at: value.at, hash: AccountProfile.hash(identity), told: { ...told, [from.id]: value.at } });
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
exports.AccountProfile = AccountProfile;
|
|
126
|
+
/** How often the profile is looked at: a change here reaches the other computers within this. */
|
|
127
|
+
const LOOK_MS = 20000;
|
|
128
|
+
const FIRST_LOOK_MS = 5000;
|
|
129
|
+
/** AccountProfile for ta serve: TaAccountService and the identity of RoomsBridge; its state in `account-profile.json`. */
|
|
130
|
+
let AccountProfileSync = class AccountProfileSync {
|
|
131
|
+
get file() {
|
|
132
|
+
return (0, node_path_1.join)(ta_brand_1.TaBrand.agentDir(), 'account-profile.json');
|
|
133
|
+
}
|
|
134
|
+
onStart() {
|
|
135
|
+
var _a, _b, _c, _d;
|
|
136
|
+
const profile = new AccountProfile({
|
|
137
|
+
identity: () => this.rooms.rooms.getIdentity(),
|
|
138
|
+
setName: name => this.rooms.rooms.setName(name),
|
|
139
|
+
setPicture: picture => this.rooms.rooms.setPicture(picture),
|
|
140
|
+
defaultName: () => node_1.RelayHubFiles.userName(),
|
|
141
|
+
// A Ta in the cloud keeps its own: the user's computers share theirs.
|
|
142
|
+
account: () => (this.account.self() && !account_service_1.TaAccountService.cloud() ? this.account.account() : undefined),
|
|
143
|
+
computers: () => this.account.computers(),
|
|
144
|
+
tell: (to, value) => this.account.tell(to, exports.ACCOUNT_PROFILE_TOPIC, value),
|
|
145
|
+
read: () => this.read(),
|
|
146
|
+
write: state => this.write(state),
|
|
147
|
+
});
|
|
148
|
+
this.profile = profile;
|
|
149
|
+
const heard = (from, value) => void profile.heard(from, value).catch(() => undefined);
|
|
150
|
+
this.stopTold = this.account.onTold(exports.ACCOUNT_PROFILE_TOPIC, heard);
|
|
151
|
+
const look = () => void profile.round().catch(() => undefined);
|
|
152
|
+
this.timer = setInterval(look, LOOK_MS);
|
|
153
|
+
(_b = (_a = this.timer).unref) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
154
|
+
// Soon after start too: an account signed in to last time names the user without waiting.
|
|
155
|
+
(_d = (_c = setTimeout(look, FIRST_LOOK_MS)).unref) === null || _d === void 0 ? void 0 : _d.call(_c);
|
|
156
|
+
}
|
|
157
|
+
onStop() {
|
|
158
|
+
var _a;
|
|
159
|
+
clearInterval(this.timer);
|
|
160
|
+
(_a = this.stopTold) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
161
|
+
}
|
|
162
|
+
read() {
|
|
163
|
+
try {
|
|
164
|
+
return JSON.parse((0, node_fs_1.readFileSync)(this.file, 'utf8'));
|
|
165
|
+
}
|
|
166
|
+
catch (_a) {
|
|
167
|
+
return undefined;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
write(state) {
|
|
171
|
+
if (state) {
|
|
172
|
+
const temp = `${this.file}.${process.pid}.tmp`;
|
|
173
|
+
(0, node_fs_1.writeFileSync)(temp, `${JSON.stringify(state)}\n`, { mode: 0o600 });
|
|
174
|
+
(0, node_fs_1.chmodSync)(temp, 0o600);
|
|
175
|
+
(0, node_fs_1.renameSync)(temp, this.file);
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
(0, node_fs_1.rmSync)(this.file, { force: true });
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
exports.AccountProfileSync = AccountProfileSync;
|
|
183
|
+
__decorate([
|
|
184
|
+
(0, core_1.Autowired)(host_protocol_1.TA_ACCOUNT),
|
|
185
|
+
__metadata("design:type", account_service_1.TaAccountService)
|
|
186
|
+
], AccountProfileSync.prototype, "account", void 0);
|
|
187
|
+
__decorate([
|
|
188
|
+
(0, core_1.Autowired)(rooms_bridge_1.ROOMS_BRIDGE),
|
|
189
|
+
__metadata("design:type", Function)
|
|
190
|
+
], AccountProfileSync.prototype, "rooms", void 0);
|
|
191
|
+
exports.AccountProfileSync = AccountProfileSync = __decorate([
|
|
192
|
+
(0, core_1.Component)(core_1.ApplicationLifecycle)
|
|
193
|
+
], AccountProfileSync);
|
|
194
|
+
//# sourceMappingURL=account-profile.js.map
|
|
@@ -30,6 +30,15 @@ export declare class TaAccountService implements TaAccountServer, ApplicationLif
|
|
|
30
30
|
protected stopped: boolean;
|
|
31
31
|
protected readonly listeners: Map<string, Set<TaAccountListener>>;
|
|
32
32
|
get file(): string;
|
|
33
|
+
/**
|
|
34
|
+
* A Ta in the cloud (docs/design/ta-me.md 2): its gateway says so, with where the sandbox reaches the gateway's
|
|
35
|
+
* accounts (TA_ACCOUNT_URL) and the address the devices know it by (TA_ACCOUNT_SERVICE).
|
|
36
|
+
*/
|
|
37
|
+
static cloud(env?: Record<string, string | undefined>): {
|
|
38
|
+
url: string;
|
|
39
|
+
service?: string;
|
|
40
|
+
} | undefined;
|
|
41
|
+
protected get kind(): 'computer' | 'cloud';
|
|
33
42
|
/** The name this computer goes by in the account. */
|
|
34
43
|
static computerName(): string;
|
|
35
44
|
onStart(): void;
|
|
@@ -50,11 +59,17 @@ export declare class TaAccountService implements TaAccountServer, ApplicationLif
|
|
|
50
59
|
info(): Promise<TaAccountInfo>;
|
|
51
60
|
signIn(provider: string, service?: string): Promise<TaAccountInfo>;
|
|
52
61
|
protected begin(provider: string, service?: string): Promise<TaAccountInfo>;
|
|
62
|
+
joinAccount(service: string, token: string): Promise<TaAccountInfo>;
|
|
53
63
|
cancelSignIn(): Promise<TaAccountInfo>;
|
|
54
64
|
protected act(run: (agent: AccountAgent) => Promise<AccountView>): Promise<TaAccountInfo>;
|
|
55
65
|
approve(id: string): Promise<TaAccountInfo>;
|
|
56
66
|
remove(id: string): Promise<TaAccountInfo>;
|
|
57
67
|
signOut(): Promise<TaAccountInfo>;
|
|
68
|
+
/** The account this computer is signed in to. */
|
|
69
|
+
account(): {
|
|
70
|
+
id: string;
|
|
71
|
+
name: string;
|
|
72
|
+
} | undefined;
|
|
58
73
|
/** This computer in the account, once let in, for packages (TaExtensionHost.account). */
|
|
59
74
|
self(): {
|
|
60
75
|
id: string;
|
|
@@ -38,6 +38,18 @@ let TaAccountService = TaAccountService_1 = class TaAccountService {
|
|
|
38
38
|
get file() {
|
|
39
39
|
return (0, node_path_1.join)(ta_brand_1.TaBrand.agentDir(), 'account.json');
|
|
40
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* A Ta in the cloud (docs/design/ta-me.md 2): its gateway says so, with where the sandbox reaches the gateway's
|
|
43
|
+
* accounts (TA_ACCOUNT_URL) and the address the devices know it by (TA_ACCOUNT_SERVICE).
|
|
44
|
+
*/
|
|
45
|
+
static cloud(env = process.env) {
|
|
46
|
+
const trim = (value) => (value === null || value === void 0 ? void 0 : value.trim().replace(/\/+$/, '')) || undefined;
|
|
47
|
+
const url = env.TA_ACCOUNT_KIND === 'cloud' ? trim(env.TA_ACCOUNT_URL) : undefined;
|
|
48
|
+
return url ? { url, service: trim(env.TA_ACCOUNT_SERVICE) } : undefined;
|
|
49
|
+
}
|
|
50
|
+
get kind() {
|
|
51
|
+
return TaAccountService_1.cloud() ? 'cloud' : 'computer';
|
|
52
|
+
}
|
|
41
53
|
/** The name this computer goes by in the account. */
|
|
42
54
|
static computerName() {
|
|
43
55
|
return (0, node_os_1.hostname)().replace(/\.local$/, '');
|
|
@@ -177,7 +189,7 @@ let TaAccountService = TaAccountService_1 = class TaAccountService {
|
|
|
177
189
|
this.error = answer.error;
|
|
178
190
|
return SYNC_MS;
|
|
179
191
|
}
|
|
180
|
-
const kept = await ta_relay_1.AccountAgent.create(signing.way.service, answer.token, answer.account,
|
|
192
|
+
const kept = await ta_relay_1.AccountAgent.create(signing.way.service, answer.token, answer.account, this.kind, TaAccountService_1.computerName());
|
|
181
193
|
this.write(kept);
|
|
182
194
|
this.agent = this.agentOf(kept);
|
|
183
195
|
this.view = await this.agent.sync();
|
|
@@ -213,7 +225,7 @@ let TaAccountService = TaAccountService_1 = class TaAccountService {
|
|
|
213
225
|
const pairings = this.agent.state.pairings;
|
|
214
226
|
const devices = view.devices.map(({ trusted: _trusted, ...device }) => ({
|
|
215
227
|
...device,
|
|
216
|
-
...(device.kind === 'computer' && pairings[device.id] ? { pairing: pairings[device.id] } : {}),
|
|
228
|
+
...((device.kind === 'computer' || device.kind === 'cloud') && pairings[device.id] ? { pairing: pairings[device.id] } : {}),
|
|
217
229
|
}));
|
|
218
230
|
return { service, providers: [], account: view.account, waiting: view.waiting, code: view.code, devices, ...error };
|
|
219
231
|
}
|
|
@@ -235,6 +247,34 @@ let TaAccountService = TaAccountService_1 = class TaAccountService {
|
|
|
235
247
|
this.schedule(start.interval * 1000);
|
|
236
248
|
return this.info();
|
|
237
249
|
}
|
|
250
|
+
joinAccount(service, token) {
|
|
251
|
+
return ta_errors_1.TaErrors.guard(async () => {
|
|
252
|
+
var _a;
|
|
253
|
+
if (typeof service !== 'string' || !/^https?:\/\//.test(service) || typeof token !== 'string' || !token || token.length > 400) {
|
|
254
|
+
throw ta_errors_1.TaErrors.invalidArgument('A service and a token of the account are needed.', 'Scan the code of this computer again.');
|
|
255
|
+
}
|
|
256
|
+
const cloud = TaAccountService_1.cloud();
|
|
257
|
+
if ((cloud === null || cloud === void 0 ? void 0 : cloud.service) && cloud.service !== service.replace(/\/+$/, '')) {
|
|
258
|
+
throw ta_errors_1.TaErrors.invalidArgument('This Ta in the cloud joins the account of its gateway only.', 'Sign in with the account of its gateway.');
|
|
259
|
+
}
|
|
260
|
+
// A Ta in the cloud reaches its gateway's accounts from within the deployment.
|
|
261
|
+
const at = (_a = cloud === null || cloud === void 0 ? void 0 : cloud.url) !== null && _a !== void 0 ? _a : service.replace(/\/+$/, '');
|
|
262
|
+
if (this.agent) {
|
|
263
|
+
if (this.agent.state.service !== at) {
|
|
264
|
+
throw ta_errors_1.TaErrors.invalidArgument('This computer is signed in to another account.', 'Sign out of it on this computer first.');
|
|
265
|
+
}
|
|
266
|
+
return this.info();
|
|
267
|
+
}
|
|
268
|
+
this.signingIn = undefined;
|
|
269
|
+
const kept = await ta_relay_1.AccountAgent.create(at, token, { id: '', name: '' }, this.kind, TaAccountService_1.computerName());
|
|
270
|
+
this.agent = this.agentOf(kept);
|
|
271
|
+
this.view = await this.agent.sync();
|
|
272
|
+
this.write(this.agent.state);
|
|
273
|
+
this.error = undefined;
|
|
274
|
+
this.schedule(WAITING_SYNC_MS);
|
|
275
|
+
return this.info();
|
|
276
|
+
});
|
|
277
|
+
}
|
|
238
278
|
async cancelSignIn() {
|
|
239
279
|
this.signingIn = undefined;
|
|
240
280
|
return this.info();
|
|
@@ -265,6 +305,12 @@ let TaAccountService = TaAccountService_1 = class TaAccountService {
|
|
|
265
305
|
return this.info();
|
|
266
306
|
});
|
|
267
307
|
}
|
|
308
|
+
/** The account this computer is signed in to. */
|
|
309
|
+
account() {
|
|
310
|
+
var _a, _b;
|
|
311
|
+
var _c;
|
|
312
|
+
return (_c = (_a = this.view) === null || _a === void 0 ? void 0 : _a.account) !== null && _c !== void 0 ? _c : (_b = this.agent) === null || _b === void 0 ? void 0 : _b.state.account;
|
|
313
|
+
}
|
|
268
314
|
/** This computer in the account, once let in, for packages (TaExtensionHost.account). */
|
|
269
315
|
self() {
|
|
270
316
|
const me = this.view && !this.view.waiting ? this.view.devices.find(one => one.self) : undefined;
|
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-profile"), exports);
|
|
17
18
|
__exportStar(require("./account-service"), exports);
|
|
18
19
|
__exportStar(require("./app-commands"), exports);
|
|
19
20
|
__exportStar(require("./auth-server-impl"), exports);
|
|
@@ -70,7 +70,14 @@ export declare class PackageHostsImpl implements PackageHosts, ApplicationLifecy
|
|
|
70
70
|
protected readonly teamProvider: TaHostTeamProvider;
|
|
71
71
|
protected readonly running: Map<string, Running>;
|
|
72
72
|
protected extensionHost?: TaExtensionHost;
|
|
73
|
-
|
|
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;
|
|
74
81
|
onStop(): void;
|
|
75
82
|
sync(): Promise<void>;
|
|
76
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.');
|
|
@@ -220,11 +234,14 @@ let PackageHostsImpl = class PackageHostsImpl {
|
|
|
220
234
|
openSession: options => server.openSession(options),
|
|
221
235
|
closeSession: sessionId => server.closeSession(sessionId),
|
|
222
236
|
setSessionName: (sessionId, name) => server.setSessionName(sessionId, name),
|
|
237
|
+
setModel: (sessionId, provider, modelId) => server.setModel(sessionId, provider, modelId),
|
|
223
238
|
prompt: (sessionId, input) => server.prompt(sessionId, input),
|
|
224
239
|
followUp: (sessionId, input) => server.followUp(sessionId, input),
|
|
225
240
|
abort: sessionId => server.abort(sessionId),
|
|
226
241
|
getState: sessionId => server.getState(sessionId),
|
|
227
242
|
getLastAssistantText: sessionId => server.getLastAssistantText(sessionId),
|
|
243
|
+
getSessionStats: sessionId => server.getSessionStats(sessionId),
|
|
244
|
+
getEntries: (sessionId, since) => server.getEntries(sessionId, since),
|
|
228
245
|
relocateDirectory: (from, to) => server.relocateDirectory(from, to),
|
|
229
246
|
getExtensionData: (name, key, cwd) => packages.getExtensionData(name, key, cwd),
|
|
230
247
|
setExtensionData: (name, key, value, cwd) => packages.setExtensionData(name, key, value, cwd),
|
|
@@ -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;
|
|
@@ -55,6 +64,8 @@ export declare class TaRoomServerImpl implements TaRoomServer {
|
|
|
55
64
|
removeMember(room: string, member: string): Promise<void>;
|
|
56
65
|
configureRoom(room: string, options: {
|
|
57
66
|
members?: number;
|
|
67
|
+
admins?: string[];
|
|
68
|
+
rules?: Record<string, boolean>;
|
|
58
69
|
}): Promise<TaRoomInfo>;
|
|
59
70
|
leave(room: string): Promise<void>;
|
|
60
71
|
send(room: string, data: unknown, to?: string): Promise<void>;
|
package/lib/node/rooms-bridge.js
CHANGED
|
@@ -31,11 +31,13 @@ let RoomsBridge = RoomsBridge_1 = class RoomsBridge {
|
|
|
31
31
|
this.watchers = new Map();
|
|
32
32
|
this.rooms = {
|
|
33
33
|
getIdentity: async () => RoomsBridge_1.identity(await this.hubs.identity()),
|
|
34
|
-
setName: async (name) => RoomsBridge_1.identity(await this.hubs.setName(name)),
|
|
34
|
+
setName: async (name) => RoomsBridge_1.identity({ ...(await this.hubs.setName(name)), ...(await this.picture()) }),
|
|
35
|
+
setPicture: async (picture) => RoomsBridge_1.identity(await this.hubs.setPicture(picture)),
|
|
36
|
+
listPictures: () => this.hubs.pictures(),
|
|
35
37
|
listRooms: async () => this.hubs.list(),
|
|
36
38
|
createRoom: input => this.hubs.create(input),
|
|
37
39
|
invite: (room, options) => this.hubs.invite(room, options !== null && options !== void 0 ? options : {}),
|
|
38
|
-
configureRoom:
|
|
40
|
+
configureRoom: (room, options) => this.hubs.configure(room, options !== null && options !== void 0 ? options : {}),
|
|
39
41
|
join: link => this.hubs.join(link),
|
|
40
42
|
listRequests: () => this.hubs.requests(),
|
|
41
43
|
answer: (room, ask, accept) => this.hubs.answer(room, ask, accept),
|
|
@@ -85,10 +87,20 @@ let RoomsBridge = RoomsBridge_1 = class RoomsBridge {
|
|
|
85
87
|
(_a = this.stopLook) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
86
88
|
this.hubs.stop();
|
|
87
89
|
}
|
|
88
|
-
/**
|
|
90
|
+
/**
|
|
91
|
+
* 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
|
|
92
|
+
* kind its identity is given, kept there for the pages to draw the double as (setting it comes back here).
|
|
93
|
+
*/
|
|
89
94
|
async keepLook() {
|
|
90
95
|
const look = await this.data.get(ta_protocol_1.TA_DOUBLE_LOOK.name, ta_protocol_1.TA_DOUBLE_LOOK.key).catch(() => undefined);
|
|
91
|
-
|
|
96
|
+
if (typeof look === 'string' && look) {
|
|
97
|
+
await this.hubs.setLook(look).catch(() => undefined);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const identity = await this.hubs.identity().catch(() => undefined);
|
|
101
|
+
if (identity) {
|
|
102
|
+
await this.data.set(ta_protocol_1.TA_DOUBLE_LOOK.name, ta_protocol_1.TA_DOUBLE_LOOK.key, ta_protocol_1.TaDoubleLookUtil.given(identity.id)).catch(() => undefined);
|
|
103
|
+
}
|
|
92
104
|
}
|
|
93
105
|
/** `watch` undefined: no more. */
|
|
94
106
|
watch(connection, watch) {
|
|
@@ -111,8 +123,13 @@ let RoomsBridge = RoomsBridge_1 = class RoomsBridge {
|
|
|
111
123
|
}
|
|
112
124
|
}
|
|
113
125
|
}
|
|
114
|
-
|
|
115
|
-
|
|
126
|
+
/** The picture of this Ta, for what is said of it after a change that does not give it. */
|
|
127
|
+
async picture() {
|
|
128
|
+
const { picture } = await this.hubs.identity();
|
|
129
|
+
return picture ? { picture } : {};
|
|
130
|
+
}
|
|
131
|
+
static identity({ id, name, look, shared, picture }) {
|
|
132
|
+
return { id, name, ...(look ? { look } : {}), ...(shared ? { shared } : {}), ...(picture ? { picture } : {}) };
|
|
116
133
|
}
|
|
117
134
|
};
|
|
118
135
|
exports.RoomsBridge = RoomsBridge;
|
|
@@ -138,6 +155,12 @@ let TaRoomServerImpl = class TaRoomServerImpl {
|
|
|
138
155
|
setName(name) {
|
|
139
156
|
return ta_errors_1.TaErrors.guard(() => this.rooms.setName(name));
|
|
140
157
|
}
|
|
158
|
+
setPicture(picture) {
|
|
159
|
+
return ta_errors_1.TaErrors.guard(() => this.rooms.setPicture(picture));
|
|
160
|
+
}
|
|
161
|
+
listPictures() {
|
|
162
|
+
return ta_errors_1.TaErrors.guard(() => this.rooms.listPictures());
|
|
163
|
+
}
|
|
141
164
|
listRooms() {
|
|
142
165
|
return ta_errors_1.TaErrors.guard(() => this.rooms.listRooms());
|
|
143
166
|
}
|
|
@@ -160,7 +183,11 @@ let TaRoomServerImpl = class TaRoomServerImpl {
|
|
|
160
183
|
return ta_errors_1.TaErrors.guard(() => this.rooms.removeMember(room, member));
|
|
161
184
|
}
|
|
162
185
|
configureRoom(room, options) {
|
|
163
|
-
return ta_errors_1.TaErrors.guard(() => this.rooms.configureRoom(room, {
|
|
186
|
+
return ta_errors_1.TaErrors.guard(() => this.rooms.configureRoom(room, {
|
|
187
|
+
...((options === null || options === void 0 ? void 0 : options.members) === undefined ? {} : { members: options.members }),
|
|
188
|
+
...(Array.isArray(options === null || options === void 0 ? void 0 : options.admins) ? { admins: options.admins.map(String) } : {}),
|
|
189
|
+
...((options === null || options === void 0 ? void 0 : options.rules) && typeof options.rules === 'object' ? { rules: options.rules } : {}),
|
|
190
|
+
}));
|
|
164
191
|
}
|
|
165
192
|
leave(room) {
|
|
166
193
|
return ta_errors_1.TaErrors.guard(() => this.rooms.leave(room));
|
|
@@ -317,7 +317,9 @@ let TaSettingsStoreImpl = class TaSettingsStoreImpl {
|
|
|
317
317
|
}
|
|
318
318
|
}
|
|
319
319
|
const name = (model) => `${model.provider}/${model.id}`;
|
|
320
|
-
const agents = available
|
|
320
|
+
const agents = available
|
|
321
|
+
.filter(model => String(model.api).startsWith(ta_protocol_1.TA_AGENT_API_PREFIX) && !String(model.api).endsWith(ta_protocol_1.TA_AGENT_CONFINED_API_SUFFIX))
|
|
322
|
+
.map(name);
|
|
321
323
|
return { models: available.map(name), agents, modelNames, providerNames };
|
|
322
324
|
}
|
|
323
325
|
catch (_a) {
|
|
@@ -180,6 +180,8 @@ const RULES = {
|
|
|
180
180
|
getAccount: fixed('settings.view'),
|
|
181
181
|
signIn: fixed('settings.manage'),
|
|
182
182
|
cancelSignIn: fixed('settings.manage'),
|
|
183
|
+
// Gives the devices of the account a way into this computer: the owner's alone.
|
|
184
|
+
joinAccount: owner,
|
|
183
185
|
approve: fixed('settings.manage'),
|
|
184
186
|
remove: fixed('settings.manage'),
|
|
185
187
|
signOut: fixed('settings.manage'),
|
|
@@ -209,6 +211,8 @@ const RULES = {
|
|
|
209
211
|
TaRoomServer: Object.fromEntries([
|
|
210
212
|
'getIdentity',
|
|
211
213
|
'setName',
|
|
214
|
+
'setPicture',
|
|
215
|
+
'listPictures',
|
|
212
216
|
'listRooms',
|
|
213
217
|
'createRoom',
|
|
214
218
|
'invite',
|