@celljs/ta-host 4.20.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.
@@ -0,0 +1,82 @@
1
+ import { type Application, ApplicationLifecycle } from '@celljs/core';
2
+ import type { TaIdentity } from '@celljs/ta-protocol';
3
+ import { TaAccountService } from './account-service.js';
4
+ import { type RoomsBridge } from './rooms-bridge.js';
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
+ }
@@ -0,0 +1,190 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { chmodSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
11
+ import { join } from 'node:path';
12
+ import { ApplicationLifecycle, Autowired, Component } from '@celljs/core';
13
+ import { TaBrand } from '@celljs/ta-harness/lib/node/ta-brand';
14
+ import { RelayHubFiles } from '@celljs/ta-relay/lib/node';
15
+ import { TaAccountService } from './account-service.js';
16
+ import { TA_ACCOUNT } from './host-protocol.js';
17
+ import { ROOMS_BRIDGE } from './rooms-bridge.js';
18
+ /** What the computers of an account tell each other of the user (docs/design/ta-me.md 3). */
19
+ export const ACCOUNT_PROFILE_TOPIC = 'ta.profile';
20
+ /**
21
+ * The name and the picture of the user, shared by the computers of their account (docs/design/ta-me.md 3): the first
22
+ * sign-in names the user as the account does, unless they chose a name; then a change on one computer goes to the
23
+ * others, the latest kept. Only the name and the picture: the keys of each identity stay its own (ta-sync shares them).
24
+ */
25
+ export class AccountProfile {
26
+ constructor(side, now = Date.now) {
27
+ this.side = side;
28
+ this.now = now;
29
+ }
30
+ static hash(identity) {
31
+ var _a;
32
+ const text = `${identity.name}\n${(_a = identity.picture) !== null && _a !== void 0 ? _a : ''}`;
33
+ let hash = 2166136261;
34
+ for (let index = 0; index < text.length; index++) {
35
+ hash = Math.imul(hash ^ text.charCodeAt(index), 16777619);
36
+ }
37
+ return `${text.length}:${(hash >>> 0).toString(36)}`;
38
+ }
39
+ /** What the user is called in an account: its name, without the way it came by (`iam:su` is su). */
40
+ static nameOf(account) {
41
+ return account.name.replace(/^[a-z][\w-]*:/i, '').trim();
42
+ }
43
+ static valid(value) {
44
+ const one = value;
45
+ return (typeof (one === null || one === void 0 ? void 0 : one.name) === 'string' &&
46
+ one.name.trim().length > 0 &&
47
+ (one.picture === null || typeof one.picture === 'string') &&
48
+ typeof one.at === 'number' &&
49
+ one.at > 0);
50
+ }
51
+ /** One look, one at a time: a change here noted, and told to the computers that have not heard it. */
52
+ round() {
53
+ var _a;
54
+ (_a = this.running) !== null && _a !== void 0 ? _a : (this.running = this.look().finally(() => {
55
+ this.running = undefined;
56
+ }));
57
+ return this.running;
58
+ }
59
+ async look() {
60
+ var _a;
61
+ const account = this.side.account();
62
+ let state = this.side.read();
63
+ if (!account) {
64
+ if (state) {
65
+ this.side.write(undefined);
66
+ }
67
+ return;
68
+ }
69
+ let identity = await this.side.identity();
70
+ if ((state === null || state === void 0 ? void 0 : state.account) !== account.id) {
71
+ state = await this.first(account, identity);
72
+ identity = await this.side.identity();
73
+ }
74
+ else if (AccountProfile.hash(identity) !== state.hash) {
75
+ state = { ...state, at: this.now(), hash: AccountProfile.hash(identity) };
76
+ }
77
+ if (state.at > 0) {
78
+ const value = { name: identity.name, picture: (_a = identity.picture) !== null && _a !== void 0 ? _a : null, at: state.at };
79
+ for (const computer of this.side.computers()) {
80
+ if (state.told[computer.id] !== state.at) {
81
+ try {
82
+ await this.side.tell(computer.id, value);
83
+ state = { ...state, told: { ...state.told, [computer.id]: state.at } };
84
+ }
85
+ catch (_b) {
86
+ // Told on the next look.
87
+ }
88
+ }
89
+ }
90
+ }
91
+ this.side.write(state);
92
+ }
93
+ /** In an account for the first time: named as the account, when the user never chose a name here. */
94
+ async first(account, identity) {
95
+ const chosen = identity.name !== this.side.defaultName() || Boolean(identity.picture);
96
+ const name = AccountProfile.nameOf(account);
97
+ if (!chosen && name && name !== identity.name) {
98
+ identity = await this.side.setName(name).catch(() => identity);
99
+ }
100
+ return { account: account.id, at: chosen ? this.now() : 0, hash: AccountProfile.hash(identity), told: {} };
101
+ }
102
+ /** What another computer of the account told: taken when it is newer than what is here. */
103
+ async heard(from, value) {
104
+ var _a;
105
+ await this.running;
106
+ const account = this.side.account();
107
+ const state = this.side.read();
108
+ if (!account || !AccountProfile.valid(value) || ((state === null || state === void 0 ? void 0 : state.account) === account.id && value.at <= state.at)) {
109
+ return;
110
+ }
111
+ let identity = await this.side.identity();
112
+ if (identity.name !== value.name.trim()) {
113
+ identity = await this.side.setName(value.name);
114
+ }
115
+ if (((_a = identity.picture) !== null && _a !== void 0 ? _a : null) !== value.picture) {
116
+ identity = await this.side.setPicture(value.picture);
117
+ }
118
+ const told = (state === null || state === void 0 ? void 0 : state.account) === account.id ? state.told : {};
119
+ this.side.write({ account: account.id, at: value.at, hash: AccountProfile.hash(identity), told: { ...told, [from.id]: value.at } });
120
+ }
121
+ }
122
+ /** How often the profile is looked at: a change here reaches the other computers within this. */
123
+ const LOOK_MS = 20000;
124
+ const FIRST_LOOK_MS = 5000;
125
+ /** AccountProfile for ta serve: TaAccountService and the identity of RoomsBridge; its state in `account-profile.json`. */
126
+ let AccountProfileSync = class AccountProfileSync {
127
+ get file() {
128
+ return join(TaBrand.agentDir(), 'account-profile.json');
129
+ }
130
+ onStart() {
131
+ var _a, _b, _c, _d;
132
+ const profile = new AccountProfile({
133
+ identity: () => this.rooms.rooms.getIdentity(),
134
+ setName: name => this.rooms.rooms.setName(name),
135
+ setPicture: picture => this.rooms.rooms.setPicture(picture),
136
+ defaultName: () => RelayHubFiles.userName(),
137
+ // A Ta in the cloud keeps its own: the user's computers share theirs.
138
+ account: () => (this.account.self() && !TaAccountService.cloud() ? this.account.account() : undefined),
139
+ computers: () => this.account.computers(),
140
+ tell: (to, value) => this.account.tell(to, ACCOUNT_PROFILE_TOPIC, value),
141
+ read: () => this.read(),
142
+ write: state => this.write(state),
143
+ });
144
+ this.profile = profile;
145
+ const heard = (from, value) => void profile.heard(from, value).catch(() => undefined);
146
+ this.stopTold = this.account.onTold(ACCOUNT_PROFILE_TOPIC, heard);
147
+ const look = () => void profile.round().catch(() => undefined);
148
+ this.timer = setInterval(look, LOOK_MS);
149
+ (_b = (_a = this.timer).unref) === null || _b === void 0 ? void 0 : _b.call(_a);
150
+ // Soon after start too: an account signed in to last time names the user without waiting.
151
+ (_d = (_c = setTimeout(look, FIRST_LOOK_MS)).unref) === null || _d === void 0 ? void 0 : _d.call(_c);
152
+ }
153
+ onStop() {
154
+ var _a;
155
+ clearInterval(this.timer);
156
+ (_a = this.stopTold) === null || _a === void 0 ? void 0 : _a.call(this);
157
+ }
158
+ read() {
159
+ try {
160
+ return JSON.parse(readFileSync(this.file, 'utf8'));
161
+ }
162
+ catch (_a) {
163
+ return undefined;
164
+ }
165
+ }
166
+ write(state) {
167
+ if (state) {
168
+ const temp = `${this.file}.${process.pid}.tmp`;
169
+ writeFileSync(temp, `${JSON.stringify(state)}\n`, { mode: 0o600 });
170
+ chmodSync(temp, 0o600);
171
+ renameSync(temp, this.file);
172
+ }
173
+ else {
174
+ rmSync(this.file, { force: true });
175
+ }
176
+ }
177
+ };
178
+ __decorate([
179
+ Autowired(TA_ACCOUNT),
180
+ __metadata("design:type", TaAccountService)
181
+ ], AccountProfileSync.prototype, "account", void 0);
182
+ __decorate([
183
+ Autowired(ROOMS_BRIDGE),
184
+ __metadata("design:type", Function)
185
+ ], AccountProfileSync.prototype, "rooms", void 0);
186
+ AccountProfileSync = __decorate([
187
+ Component(ApplicationLifecycle)
188
+ ], AccountProfileSync);
189
+ export { AccountProfileSync };
190
+ //# 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;
@@ -35,6 +35,18 @@ let TaAccountService = TaAccountService_1 = class TaAccountService {
35
35
  get file() {
36
36
  return join(TaBrand.agentDir(), 'account.json');
37
37
  }
38
+ /**
39
+ * A Ta in the cloud (docs/design/ta-me.md 2): its gateway says so, with where the sandbox reaches the gateway's
40
+ * accounts (TA_ACCOUNT_URL) and the address the devices know it by (TA_ACCOUNT_SERVICE).
41
+ */
42
+ static cloud(env = process.env) {
43
+ const trim = (value) => (value === null || value === void 0 ? void 0 : value.trim().replace(/\/+$/, '')) || undefined;
44
+ const url = env.TA_ACCOUNT_KIND === 'cloud' ? trim(env.TA_ACCOUNT_URL) : undefined;
45
+ return url ? { url, service: trim(env.TA_ACCOUNT_SERVICE) } : undefined;
46
+ }
47
+ get kind() {
48
+ return TaAccountService_1.cloud() ? 'cloud' : 'computer';
49
+ }
38
50
  /** The name this computer goes by in the account. */
39
51
  static computerName() {
40
52
  return hostname().replace(/\.local$/, '');
@@ -174,7 +186,7 @@ let TaAccountService = TaAccountService_1 = class TaAccountService {
174
186
  this.error = answer.error;
175
187
  return SYNC_MS;
176
188
  }
177
- const kept = await AccountAgent.create(signing.way.service, answer.token, answer.account, 'computer', TaAccountService_1.computerName());
189
+ const kept = await AccountAgent.create(signing.way.service, answer.token, answer.account, this.kind, TaAccountService_1.computerName());
178
190
  this.write(kept);
179
191
  this.agent = this.agentOf(kept);
180
192
  this.view = await this.agent.sync();
@@ -210,7 +222,7 @@ let TaAccountService = TaAccountService_1 = class TaAccountService {
210
222
  const pairings = this.agent.state.pairings;
211
223
  const devices = view.devices.map(({ trusted: _trusted, ...device }) => ({
212
224
  ...device,
213
- ...(device.kind === 'computer' && pairings[device.id] ? { pairing: pairings[device.id] } : {}),
225
+ ...((device.kind === 'computer' || device.kind === 'cloud') && pairings[device.id] ? { pairing: pairings[device.id] } : {}),
214
226
  }));
215
227
  return { service, providers: [], account: view.account, waiting: view.waiting, code: view.code, devices, ...error };
216
228
  }
@@ -232,6 +244,34 @@ let TaAccountService = TaAccountService_1 = class TaAccountService {
232
244
  this.schedule(start.interval * 1000);
233
245
  return this.info();
234
246
  }
247
+ joinAccount(service, token) {
248
+ return TaErrors.guard(async () => {
249
+ var _a;
250
+ if (typeof service !== 'string' || !/^https?:\/\//.test(service) || typeof token !== 'string' || !token || token.length > 400) {
251
+ throw TaErrors.invalidArgument('A service and a token of the account are needed.', 'Scan the code of this computer again.');
252
+ }
253
+ const cloud = TaAccountService_1.cloud();
254
+ if ((cloud === null || cloud === void 0 ? void 0 : cloud.service) && cloud.service !== service.replace(/\/+$/, '')) {
255
+ throw TaErrors.invalidArgument('This Ta in the cloud joins the account of its gateway only.', 'Sign in with the account of its gateway.');
256
+ }
257
+ // A Ta in the cloud reaches its gateway's accounts from within the deployment.
258
+ const at = (_a = cloud === null || cloud === void 0 ? void 0 : cloud.url) !== null && _a !== void 0 ? _a : service.replace(/\/+$/, '');
259
+ if (this.agent) {
260
+ if (this.agent.state.service !== at) {
261
+ throw TaErrors.invalidArgument('This computer is signed in to another account.', 'Sign out of it on this computer first.');
262
+ }
263
+ return this.info();
264
+ }
265
+ this.signingIn = undefined;
266
+ const kept = await AccountAgent.create(at, token, { id: '', name: '' }, this.kind, TaAccountService_1.computerName());
267
+ this.agent = this.agentOf(kept);
268
+ this.view = await this.agent.sync();
269
+ this.write(this.agent.state);
270
+ this.error = undefined;
271
+ this.schedule(WAITING_SYNC_MS);
272
+ return this.info();
273
+ });
274
+ }
235
275
  async cancelSignIn() {
236
276
  this.signingIn = undefined;
237
277
  return this.info();
@@ -262,6 +302,12 @@ let TaAccountService = TaAccountService_1 = class TaAccountService {
262
302
  return this.info();
263
303
  });
264
304
  }
305
+ /** The account this computer is signed in to. */
306
+ account() {
307
+ var _a, _b;
308
+ var _c;
309
+ 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;
310
+ }
265
311
  /** This computer in the account, once let in, for packages (TaExtensionHost.account). */
266
312
  self() {
267
313
  const me = this.view && !this.view.waiting ? this.view.devices.find(one => one.self) : undefined;
@@ -1,3 +1,4 @@
1
+ export * from './account-profile.js';
1
2
  export * from './account-service.js';
2
3
  export * from './app-commands.js';
3
4
  export * from './auth-server-impl.js';
package/esm/node/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './account-profile.js';
1
2
  export * from './account-service.js';
2
3
  export * from './app-commands.js';
3
4
  export * from './auth-server-impl.js';
@@ -64,6 +64,8 @@ export declare class TaRoomServerImpl implements TaRoomServer {
64
64
  removeMember(room: string, member: string): Promise<void>;
65
65
  configureRoom(room: string, options: {
66
66
  members?: number;
67
+ admins?: string[];
68
+ rules?: Record<string, boolean>;
67
69
  }): Promise<TaRoomInfo>;
68
70
  leave(room: string): Promise<void>;
69
71
  send(room: string, data: unknown, to?: string): Promise<void>;
@@ -34,7 +34,7 @@ let RoomsBridge = RoomsBridge_1 = class RoomsBridge {
34
34
  listRooms: async () => this.hubs.list(),
35
35
  createRoom: input => this.hubs.create(input),
36
36
  invite: (room, options) => this.hubs.invite(room, options !== null && options !== void 0 ? options : {}),
37
- configureRoom: async (room, options) => this.hubs.configure(room, options !== null && options !== void 0 ? options : {}),
37
+ configureRoom: (room, options) => this.hubs.configure(room, options !== null && options !== void 0 ? options : {}),
38
38
  join: link => this.hubs.join(link),
39
39
  listRequests: () => this.hubs.requests(),
40
40
  answer: (room, ask, accept) => this.hubs.answer(room, ask, accept),
@@ -180,7 +180,11 @@ let TaRoomServerImpl = class TaRoomServerImpl {
180
180
  return TaErrors.guard(() => this.rooms.removeMember(room, member));
181
181
  }
182
182
  configureRoom(room, options) {
183
- return TaErrors.guard(() => this.rooms.configureRoom(room, { members: options === null || options === void 0 ? void 0 : options.members }));
183
+ return TaErrors.guard(() => this.rooms.configureRoom(room, {
184
+ ...((options === null || options === void 0 ? void 0 : options.members) === undefined ? {} : { members: options.members }),
185
+ ...(Array.isArray(options === null || options === void 0 ? void 0 : options.admins) ? { admins: options.admins.map(String) } : {}),
186
+ ...((options === null || options === void 0 ? void 0 : options.rules) && typeof options.rules === 'object' ? { rules: options.rules } : {}),
187
+ }));
184
188
  }
185
189
  leave(room) {
186
190
  return TaErrors.guard(() => this.rooms.leave(room));
@@ -11,7 +11,7 @@ import { mkdir, readFile, rename, rmdir, stat, writeFile } from 'node:fs/promise
11
11
  import { dirname, join } from 'node:path';
12
12
  import { CODING_AGENT_OPTIONS, ModelRuntimeProvider, PiSdkUtil } from '@celljs/ai-coding-agent';
13
13
  import { Autowired, Component, Value } from '@celljs/core';
14
- import { TA_AGENT_API_PREFIX, TA_SETTINGS } from '@celljs/ta-protocol';
14
+ import { TA_AGENT_API_PREFIX, TA_AGENT_CONFINED_API_SUFFIX, TA_SETTINGS, } from '@celljs/ta-protocol';
15
15
  import { ExtensionProviders } from './extension-providers.js';
16
16
  import { TaSessionRegistry } from './host-protocol.js';
17
17
  import { PiDirectories } from './remote/remote-protocol.js';
@@ -314,7 +314,9 @@ let TaSettingsStoreImpl = class TaSettingsStoreImpl {
314
314
  }
315
315
  }
316
316
  const name = (model) => `${model.provider}/${model.id}`;
317
- const agents = available.filter(model => String(model.api).startsWith(TA_AGENT_API_PREFIX)).map(name);
317
+ const agents = available
318
+ .filter(model => String(model.api).startsWith(TA_AGENT_API_PREFIX) && !String(model.api).endsWith(TA_AGENT_CONFINED_API_SUFFIX))
319
+ .map(name);
318
320
  return { models: available.map(name), agents, modelNames, providerNames };
319
321
  }
320
322
  catch (_a) {
@@ -176,6 +176,8 @@ const RULES = {
176
176
  getAccount: fixed('settings.view'),
177
177
  signIn: fixed('settings.manage'),
178
178
  cancelSignIn: fixed('settings.manage'),
179
+ // Gives the devices of the account a way into this computer: the owner's alone.
180
+ joinAccount: owner,
179
181
  approve: fixed('settings.manage'),
180
182
  remove: fixed('settings.manage'),
181
183
  signOut: fixed('settings.manage'),
@@ -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, 'computer', TaAccountService_1.computerName());
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;
@@ -1,3 +1,4 @@
1
+ export * from './account-profile';
1
2
  export * from './account-service';
2
3
  export * from './app-commands';
3
4
  export * from './auth-server-impl';
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);
@@ -64,6 +64,8 @@ export declare class TaRoomServerImpl implements TaRoomServer {
64
64
  removeMember(room: string, member: string): Promise<void>;
65
65
  configureRoom(room: string, options: {
66
66
  members?: number;
67
+ admins?: string[];
68
+ rules?: Record<string, boolean>;
67
69
  }): Promise<TaRoomInfo>;
68
70
  leave(room: string): Promise<void>;
69
71
  send(room: string, data: unknown, to?: string): Promise<void>;
@@ -37,7 +37,7 @@ let RoomsBridge = RoomsBridge_1 = class RoomsBridge {
37
37
  listRooms: async () => this.hubs.list(),
38
38
  createRoom: input => this.hubs.create(input),
39
39
  invite: (room, options) => this.hubs.invite(room, options !== null && options !== void 0 ? options : {}),
40
- configureRoom: async (room, options) => this.hubs.configure(room, options !== null && options !== void 0 ? options : {}),
40
+ configureRoom: (room, options) => this.hubs.configure(room, options !== null && options !== void 0 ? options : {}),
41
41
  join: link => this.hubs.join(link),
42
42
  listRequests: () => this.hubs.requests(),
43
43
  answer: (room, ask, accept) => this.hubs.answer(room, ask, accept),
@@ -183,7 +183,11 @@ let TaRoomServerImpl = class TaRoomServerImpl {
183
183
  return ta_errors_1.TaErrors.guard(() => this.rooms.removeMember(room, member));
184
184
  }
185
185
  configureRoom(room, options) {
186
- return ta_errors_1.TaErrors.guard(() => this.rooms.configureRoom(room, { members: options === null || options === void 0 ? void 0 : options.members }));
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
+ }));
187
191
  }
188
192
  leave(room) {
189
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.filter(model => String(model.api).startsWith(ta_protocol_1.TA_AGENT_API_PREFIX)).map(name);
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'),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celljs/ta-host",
3
- "version": "4.20.0",
3
+ "version": "4.21.0",
4
4
  "description": "ta serve: pi sessions for many clients over WebSocket",
5
5
  "keywords": [
6
6
  "cell-component"
@@ -34,15 +34,15 @@
34
34
  "watch": "tsc -b -w --preserveWatchOutput"
35
35
  },
36
36
  "dependencies": {
37
- "@celljs/ai-agent": "4.20.0",
38
- "@celljs/ai-coding-agent": "4.20.0",
39
- "@celljs/core": "4.20.0",
40
- "@celljs/rpc": "4.20.0",
41
- "@celljs/ta-exec": "4.20.0",
42
- "@celljs/ta-harness": "4.20.0",
43
- "@celljs/ta-protocol": "4.20.0",
44
- "@celljs/ta-relay": "4.20.0",
45
- "@celljs/web": "4.20.0",
37
+ "@celljs/ai-agent": "4.21.0",
38
+ "@celljs/ai-coding-agent": "4.21.0",
39
+ "@celljs/core": "4.21.0",
40
+ "@celljs/rpc": "4.21.0",
41
+ "@celljs/ta-exec": "4.21.0",
42
+ "@celljs/ta-harness": "4.21.0",
43
+ "@celljs/ta-protocol": "4.21.0",
44
+ "@celljs/ta-relay": "4.21.0",
45
+ "@celljs/web": "4.21.0",
46
46
  "@earendil-works/pi-coding-agent": "^1.5.2"
47
47
  },
48
48
  "devDependencies": {