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