@celljs/ta-host 4.17.0 → 4.19.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.
Files changed (153) hide show
  1. package/esm/node/account-service.d.ts +73 -0
  2. package/esm/node/account-service.js +304 -0
  3. package/esm/node/app-commands.d.ts +1 -1
  4. package/esm/node/app-commands.js +46 -29
  5. package/esm/node/credentials.d.ts +12 -0
  6. package/esm/node/credentials.js +35 -0
  7. package/esm/node/host-protocol.d.ts +2 -0
  8. package/esm/node/host-protocol.js +2 -0
  9. package/esm/node/index.d.ts +3 -0
  10. package/esm/node/index.js +3 -0
  11. package/esm/node/keep-awake.d.ts +3 -0
  12. package/esm/node/keep-awake.js +6 -1
  13. package/esm/node/package-hosts.d.ts +4 -0
  14. package/esm/node/package-hosts.js +18 -1
  15. package/esm/node/relay-bridge.js +1 -1
  16. package/esm/node/rooms-bridge.d.ts +10 -1
  17. package/esm/node/rooms-bridge.js +25 -0
  18. package/esm/node/screen-share/desktop-picture.d.ts +51 -0
  19. package/esm/node/screen-share/desktop-picture.js +133 -0
  20. package/esm/node/screen-share/desktop-session.d.ts +128 -0
  21. package/esm/node/screen-share/desktop-session.js +437 -0
  22. package/esm/node/screen-share/desktop-targets.d.ts +24 -0
  23. package/esm/node/screen-share/desktop-targets.js +80 -0
  24. package/esm/node/screen-share/desktop-viewer.d.ts +146 -0
  25. package/esm/node/screen-share/desktop-viewer.js +339 -0
  26. package/esm/node/screen-share/index.d.ts +8 -0
  27. package/esm/node/screen-share/index.js +9 -0
  28. package/esm/node/screen-share/rfb-client.d.ts +54 -0
  29. package/esm/node/screen-share/rfb-client.js +179 -0
  30. package/esm/node/screen-share/rfb-des.d.ts +11 -0
  31. package/esm/node/screen-share/rfb-des.js +143 -0
  32. package/esm/node/screen-share/rfb-encodings.d.ts +71 -0
  33. package/esm/node/screen-share/rfb-encodings.js +288 -0
  34. package/esm/node/screen-share/rfb-framebuffer.d.ts +16 -0
  35. package/esm/node/screen-share/rfb-framebuffer.js +53 -0
  36. package/esm/node/screen-share/rfb-protocol.d.ts +90 -0
  37. package/esm/node/screen-share/rfb-protocol.js +36 -0
  38. package/esm/node/screen-share/rfb-reader.d.ts +34 -0
  39. package/esm/node/screen-share/rfb-reader.js +110 -0
  40. package/esm/node/screen-share/rfb-security.d.ts +30 -0
  41. package/esm/node/screen-share/rfb-security.js +136 -0
  42. package/esm/node/screen-share/rfb-test-server.d.ts +37 -0
  43. package/esm/node/screen-share/rfb-test-server.js +116 -0
  44. package/esm/node/screen-share/screen-share-server-impl.d.ts +37 -0
  45. package/esm/node/screen-share/screen-share-server-impl.js +76 -0
  46. package/esm/node/screen-share/screen-shares.d.ts +123 -0
  47. package/esm/node/screen-share/screen-shares.js +463 -0
  48. package/esm/node/session-info-util.d.ts +10 -11
  49. package/esm/node/session-info-util.js +16 -94
  50. package/esm/node/settings-store.d.ts +1 -1
  51. package/esm/node/settings-store.js +7 -4
  52. package/esm/node/sign-in/access-store.d.ts +1 -1
  53. package/esm/node/sign-in/access-store.js +4 -1
  54. package/esm/node/sign-in/index.d.ts +2 -0
  55. package/esm/node/sign-in/index.js +2 -0
  56. package/esm/node/sign-in/polled-sign-in.d.ts +50 -0
  57. package/esm/node/sign-in/polled-sign-in.js +83 -0
  58. package/esm/node/sign-in/sign-in-devices.d.ts +55 -0
  59. package/esm/node/sign-in/sign-in-devices.js +113 -0
  60. package/esm/node/sign-in/sign-in-flow.d.ts +38 -4
  61. package/esm/node/sign-in/sign-in-flow.js +79 -4
  62. package/esm/node/sign-in/sign-in-pages.d.ts +8 -0
  63. package/esm/node/sign-in/sign-in-pages.js +137 -8
  64. package/esm/node/sign-in/sign-in-provider.d.ts +6 -0
  65. package/esm/node/sign-in/sign-in-provider.js +15 -0
  66. package/esm/node/sources-extension.d.ts +10 -0
  67. package/esm/node/sources-extension.js +18 -0
  68. package/esm/node/ta-server-impl.js +3 -3
  69. package/esm/node/ta-session-factory.js +2 -0
  70. package/esm/node/team/team-calls.js +35 -0
  71. package/esm/node/voice-bridge.d.ts +3 -1
  72. package/esm/node/voice-bridge.js +10 -3
  73. package/esm/node/voices-file.d.ts +5 -0
  74. package/esm/node/voices-file.js +14 -3
  75. package/esm/node/working-directory.d.ts +8 -2
  76. package/esm/node/working-directory.js +7 -0
  77. package/lib/node/account-service.d.ts +74 -0
  78. package/lib/node/account-service.js +307 -0
  79. package/lib/node/app-commands.d.ts +1 -1
  80. package/lib/node/app-commands.js +46 -29
  81. package/lib/node/credentials.d.ts +13 -0
  82. package/lib/node/credentials.js +38 -0
  83. package/lib/node/host-protocol.d.ts +2 -0
  84. package/lib/node/host-protocol.js +3 -1
  85. package/lib/node/index.d.ts +3 -0
  86. package/lib/node/index.js +3 -0
  87. package/lib/node/keep-awake.d.ts +3 -0
  88. package/lib/node/keep-awake.js +6 -1
  89. package/lib/node/package-hosts.d.ts +4 -0
  90. package/lib/node/package-hosts.js +17 -0
  91. package/lib/node/relay-bridge.js +1 -1
  92. package/lib/node/rooms-bridge.d.ts +10 -1
  93. package/lib/node/rooms-bridge.js +25 -0
  94. package/lib/node/screen-share/desktop-picture.d.ts +52 -0
  95. package/lib/node/screen-share/desktop-picture.js +136 -0
  96. package/lib/node/screen-share/desktop-session.d.ts +129 -0
  97. package/lib/node/screen-share/desktop-session.js +442 -0
  98. package/lib/node/screen-share/desktop-targets.d.ts +25 -0
  99. package/lib/node/screen-share/desktop-targets.js +84 -0
  100. package/lib/node/screen-share/desktop-viewer.d.ts +147 -0
  101. package/lib/node/screen-share/desktop-viewer.js +343 -0
  102. package/lib/node/screen-share/index.d.ts +9 -0
  103. package/lib/node/screen-share/index.js +25 -0
  104. package/lib/node/screen-share/rfb-client.d.ts +55 -0
  105. package/lib/node/screen-share/rfb-client.js +183 -0
  106. package/lib/node/screen-share/rfb-des.d.ts +12 -0
  107. package/lib/node/screen-share/rfb-des.js +146 -0
  108. package/lib/node/screen-share/rfb-encodings.d.ts +72 -0
  109. package/lib/node/screen-share/rfb-encodings.js +295 -0
  110. package/lib/node/screen-share/rfb-framebuffer.d.ts +17 -0
  111. package/lib/node/screen-share/rfb-framebuffer.js +57 -0
  112. package/lib/node/screen-share/rfb-protocol.d.ts +91 -0
  113. package/lib/node/screen-share/rfb-protocol.js +39 -0
  114. package/lib/node/screen-share/rfb-reader.d.ts +35 -0
  115. package/lib/node/screen-share/rfb-reader.js +115 -0
  116. package/lib/node/screen-share/rfb-security.d.ts +31 -0
  117. package/lib/node/screen-share/rfb-security.js +141 -0
  118. package/lib/node/screen-share/rfb-test-server.d.ts +38 -0
  119. package/lib/node/screen-share/rfb-test-server.js +120 -0
  120. package/lib/node/screen-share/screen-share-server-impl.d.ts +38 -0
  121. package/lib/node/screen-share/screen-share-server-impl.js +79 -0
  122. package/lib/node/screen-share/screen-shares.d.ts +124 -0
  123. package/lib/node/screen-share/screen-shares.js +464 -0
  124. package/lib/node/session-info-util.d.ts +10 -11
  125. package/lib/node/session-info-util.js +15 -93
  126. package/lib/node/settings-store.d.ts +1 -1
  127. package/lib/node/settings-store.js +6 -3
  128. package/lib/node/sign-in/access-store.d.ts +1 -1
  129. package/lib/node/sign-in/access-store.js +4 -1
  130. package/lib/node/sign-in/index.d.ts +2 -0
  131. package/lib/node/sign-in/index.js +2 -0
  132. package/lib/node/sign-in/polled-sign-in.d.ts +51 -0
  133. package/lib/node/sign-in/polled-sign-in.js +87 -0
  134. package/lib/node/sign-in/sign-in-devices.d.ts +56 -0
  135. package/lib/node/sign-in/sign-in-devices.js +117 -0
  136. package/lib/node/sign-in/sign-in-flow.d.ts +38 -4
  137. package/lib/node/sign-in/sign-in-flow.js +80 -5
  138. package/lib/node/sign-in/sign-in-pages.d.ts +8 -0
  139. package/lib/node/sign-in/sign-in-pages.js +136 -7
  140. package/lib/node/sign-in/sign-in-provider.d.ts +6 -0
  141. package/lib/node/sign-in/sign-in-provider.js +15 -0
  142. package/lib/node/sources-extension.d.ts +11 -0
  143. package/lib/node/sources-extension.js +22 -0
  144. package/lib/node/ta-server-impl.js +2 -2
  145. package/lib/node/ta-session-factory.js +2 -0
  146. package/lib/node/team/team-calls.js +35 -0
  147. package/lib/node/voice-bridge.d.ts +3 -1
  148. package/lib/node/voice-bridge.js +9 -2
  149. package/lib/node/voices-file.d.ts +5 -0
  150. package/lib/node/voices-file.js +14 -3
  151. package/lib/node/working-directory.d.ts +8 -2
  152. package/lib/node/working-directory.js +7 -0
  153. package/package.json +14 -10
@@ -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
@@ -21,7 +21,7 @@ export interface AppCommandAccess {
21
21
  * Whether `principal` agrees, on a screen of theirs, to a danger action asked for by the run of `sessionFile`;
22
22
  * undefined when they have no page open to ask on.
23
23
  */
24
- confirm?(principal: string, what: string, sessionFile?: string): Promise<boolean | undefined>;
24
+ confirm?(principal: string, what: string, sessionFile?: string, detail?: string): Promise<boolean | undefined>;
25
25
  }
26
26
  type Json = Record<string, unknown>;
27
27
  /** The actions by id, and who may run them: pure, for TaAppCommandsImpl and its tests. */
@@ -61,8 +61,8 @@ export class AppCommandRegistry {
61
61
  }
62
62
  }
63
63
  async run(id, input = {}, options = {}) {
64
- var _a, _b, _c;
65
- var _d, _e;
64
+ var _a, _b, _c, _d;
65
+ var _e, _f;
66
66
  const command = (_a = this.commands.get(id)) === null || _a === void 0 ? void 0 : _a.command;
67
67
  if (!command) {
68
68
  throw TaErrors.invalidArgument(`There is no action ${JSON.stringify(id)}.`, 'See app_commands for the actions there are.');
@@ -75,10 +75,12 @@ export class AppCommandRegistry {
75
75
  if (refused) {
76
76
  throw TaErrors.invalidArgument(`Who asked this may not do ${id} (${command.action}).`, 'Ask the owner of this Ta to let them, or to do it.');
77
77
  }
78
- const principal = (_d = principals.find(one => one !== TA_OWNER)) !== null && _d !== void 0 ? _d : TA_OWNER;
78
+ const principal = (_e = principals.find(one => one !== TA_OWNER)) !== null && _e !== void 0 ? _e : TA_OWNER;
79
+ const context = { principal, language: this.language(), ...(options.sessionFile ? { sessionFile: options.sessionFile } : {}) };
79
80
  // What cannot be undone, or acts for the user, waits for them to agree on their screen; a page's tap is theirs already.
80
81
  if (command.risk === 'danger' && !options.principal) {
81
- const agreed = await ((_c = (_b = this.access).confirm) === null || _c === void 0 ? void 0 : _c.call(_b, principal, (_e = command.title[this.language()]) !== null && _e !== void 0 ? _e : command.title['en-US'], options.sessionFile));
82
+ const detail = await ((_b = command.detail) === null || _b === void 0 ? void 0 : _b.call(command, input, context));
83
+ const agreed = await ((_d = (_c = this.access).confirm) === null || _d === void 0 ? void 0 : _d.call(_c, principal, (_f = command.title[context.language]) !== null && _f !== void 0 ? _f : command.title['en-US'], options.sessionFile, detail));
82
84
  if (agreed === undefined) {
83
85
  throw TaErrors.invalidArgument(`${id} needs the user to agree on their screen, and no page of Ta is open.`, 'Tell the user to open Ta, or to do it themselves.');
84
86
  }
@@ -86,11 +88,7 @@ export class AppCommandRegistry {
86
88
  throw TaErrors.invalidArgument(`The user did not agree to ${id}.`, 'Do not do it another way; ask them what they want instead.');
87
89
  }
88
90
  }
89
- return command.run(input, {
90
- principal,
91
- language: this.language(),
92
- ...(options.sessionFile ? { sessionFile: options.sessionFile } : {}),
93
- });
91
+ return command.run(input, context);
94
92
  }
95
93
  /** Each who asked: the principal given, or those of the run of the conversation; the owner for a run nobody asked. */
96
94
  principals(options) {
@@ -431,34 +429,53 @@ export var CoreAppCommands;
431
429
  return {
432
430
  id: 'asks.answer',
433
431
  title: words('Answer for you', '替你回答', '替你回答', 'あなたの代わりに回答'),
434
- description: "Answers what waits for the user (asks.list) with what the user said: file of the conversation; answer: one of a dialog's choices (or its number), yes or no for a confirmation, any text for an input or a question. Only what the user said: never decide for them.",
432
+ description: "Answers what waits for the user (asks.list) with what the user said: file of the conversation; answer: one of a dialog's choices (or its number), yes or no for a confirmation, any text for an input or a question. Only what the user said: never decide for them. The user agrees on their screen before it is answered.",
435
433
  input: { type: 'object', properties: { file: { type: 'string' }, answer: { type: 'string' } }, required: ['file', 'answer'] },
436
- risk: 'act',
434
+ // It may answer a confirmation of another conversation (delete, publish): the user agrees on their screen first.
435
+ risk: 'danger',
437
436
  action: 'chat.send',
437
+ detail: async (input, context) => {
438
+ const { ask, said } = await answering(deps, input, context.language);
439
+ return `${ask.name}:${ask.question} → ${said}`;
440
+ },
438
441
  run: async (input, context) => {
439
- const ask = (await asks(deps)).find(one => one.file === input.file);
440
- if (!ask) {
441
- throw TaErrors.invalidArgument('That conversation waits for nothing.', 'See asks.list for what waits.');
442
- }
442
+ const { ask, response, said } = await answering(deps, input, context.language);
443
443
  const notice = TaLanguageUtil.pick(context.language, words('Answered for you', '替你回答了', '替你回答了', 'あなたの代わりに回答しました'));
444
- if (ask.dialog && ask.sessionId) {
445
- const response = answerOf(ask.dialog, input.answer);
446
- if (!response) {
447
- throw TaErrors.invalidArgument(`"${String(input.answer)}" does not answer it${ask.choices ? `: it takes one of ${ask.choices.join(', ')}` : ''}.`, 'Ask the user again.');
448
- }
444
+ if (response && ask.dialog && ask.sessionId) {
449
445
  await deps.respondUi(ask.sessionId, { type: 'extension_ui_response', id: ask.dialog.id, ...response });
450
- const said = 'value' in response ? response.value : TaAppUtil.shown(response.confirmed, context.language);
451
446
  return { text: `Answered ${ask.name}: ${said}.`, notice, changes: [{ label: ask.question, after: said }] };
452
447
  }
453
- const text = typeof input.answer === 'string' ? input.answer.trim() : '';
454
- if (!text) {
455
- throw TaErrors.invalidArgument('answer is what the user said.', 'Pass their words.');
456
- }
457
- await deps.send(ask.file, ask.cwd, text);
458
- return { text: `Told ${ask.name}: ${text}`, notice, changes: [{ label: ask.question, after: text }] };
448
+ await deps.send(ask.file, ask.cwd, said);
449
+ return { text: `Told ${ask.name}: ${said}`, notice, changes: [{ label: ask.question, after: said }] };
459
450
  },
460
451
  };
461
452
  }
453
+ /** What asks.answer would answer, and how, as the user reads it; throws for what waits for nothing or no answer of it. */
454
+ async function answering(deps, input, language) {
455
+ const ask = (await asks(deps)).find(one => one.file === input.file);
456
+ if (!ask) {
457
+ throw TaErrors.invalidArgument('That conversation waits for nothing.', 'See asks.list for what waits.');
458
+ }
459
+ if (ask.dialog && ask.sessionId) {
460
+ const response = answerOf(ask.dialog, input.answer);
461
+ if (!response) {
462
+ throw TaErrors.invalidArgument(`"${String(input.answer)}" does not answer it${ask.choices ? `: it takes one of ${ask.choices.join(', ')}` : ''}.`, 'Ask the user again.');
463
+ }
464
+ if ('value' in response) {
465
+ return { ask, response, said: response.value };
466
+ }
467
+ return {
468
+ ask,
469
+ response,
470
+ said: TaLanguageUtil.pick(language, response.confirmed ? words('yes', '是', '是', 'はい') : words('no', '否', '否', 'いいえ')),
471
+ };
472
+ }
473
+ const text = typeof input.answer === 'string' ? input.answer.trim() : '';
474
+ if (!text) {
475
+ throw TaErrors.invalidArgument('answer is what the user said.', 'Pass their words.');
476
+ }
477
+ return { ask, said: text };
478
+ }
462
479
  function onOff(on, language) {
463
480
  return TaAppUtil.shown(on, language);
464
481
  }
@@ -557,12 +574,12 @@ let TaAppCommandsImpl = class TaAppCommandsImpl {
557
574
  can: (principal, action) => team().can(principal, action),
558
575
  actorsOf: file => team().actorsOf(file),
559
576
  current: () => team().current(),
560
- confirm: async (principal, what, sessionFile) => {
577
+ confirm: async (principal, what, sessionFile, detail) => {
561
578
  if (!this.pages.has(principal, TA_PAGE_CONFIRM)) {
562
579
  return undefined;
563
580
  }
564
581
  const session = sessionFile ? (await this.server.listSessions()).find(one => one.sessionFile === sessionFile) : undefined;
565
- const ask = { who: (session === null || session === void 0 ? void 0 : session.sessionName) || (session === null || session === void 0 ? void 0 : session.firstMessage) || 'Ta', what };
582
+ const ask = { who: (session === null || session === void 0 ? void 0 : session.sessionName) || (session === null || session === void 0 ? void 0 : session.firstMessage) || 'Ta', what, ...(detail ? { detail } : {}) };
566
583
  return (await this.pages.ask(principal, TA_PAGE_CONFIRM, ask, CONFIRM_MS)) === true;
567
584
  },
568
585
  });
@@ -0,0 +1,12 @@
1
+ import type { TaCredentialStore, TaExtensionCredentials } from '@celljs/ta-protocol';
2
+ /**
3
+ * The store of the sign-ins Ta gives by itself (TaExtensionHost.credentials): a package registers it (the vault of
4
+ * ta-secrets); without one, nothing is kept and every sign-in is asked.
5
+ */
6
+ export declare class TaCredentials {
7
+ protected registered?: TaCredentialStore;
8
+ /** The store there is now; undefined while no package keeps sign-ins. */
9
+ get store(): TaCredentialStore | undefined;
10
+ /** For the server side of packages (TaExtensionHost.credentials). */
11
+ readonly extension: TaExtensionCredentials;
12
+ }
@@ -0,0 +1,35 @@
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
+ import { Component } from '@celljs/core';
8
+ /**
9
+ * The store of the sign-ins Ta gives by itself (TaExtensionHost.credentials): a package registers it (the vault of
10
+ * ta-secrets); without one, nothing is kept and every sign-in is asked.
11
+ */
12
+ let TaCredentials = class TaCredentials {
13
+ constructor() {
14
+ /** For the server side of packages (TaExtensionHost.credentials). */
15
+ this.extension = {
16
+ register: store => {
17
+ this.registered = store;
18
+ return () => {
19
+ if (this.registered === store) {
20
+ this.registered = undefined;
21
+ }
22
+ };
23
+ },
24
+ };
25
+ }
26
+ /** The store there is now; undefined while no package keeps sign-ins. */
27
+ get store() {
28
+ return this.registered;
29
+ }
30
+ };
31
+ TaCredentials = __decorate([
32
+ Component()
33
+ ], TaCredentials);
34
+ export { TaCredentials };
35
+ //# sourceMappingURL=credentials.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,7 +1,9 @@
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';
4
5
  export * from './client-tool-broker.js';
6
+ export * from './credentials.js';
5
7
  export * from './directory-relocator.js';
6
8
  export * from './event-log.js';
7
9
  export * from './exec-endpoint.js';
@@ -24,6 +26,7 @@ export * from './relay-bridge.js';
24
26
  export * from './remote/index.js';
25
27
  export * from './remote-ui-context.js';
26
28
  export * from './rooms-bridge.js';
29
+ export * from './screen-share/index.js';
27
30
  export * from './serve-updates.js';
28
31
  export * from './session-catalog.js';
29
32
  export * from './session-files.js';
package/esm/node/index.js CHANGED
@@ -1,7 +1,9 @@
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';
4
5
  export * from './client-tool-broker.js';
6
+ export * from './credentials.js';
5
7
  export * from './directory-relocator.js';
6
8
  export * from './event-log.js';
7
9
  export * from './exec-endpoint.js';
@@ -24,6 +26,7 @@ export * from './relay-bridge.js';
24
26
  export * from './remote/index.js';
25
27
  export * from './remote-ui-context.js';
26
28
  export * from './rooms-bridge.js';
29
+ export * from './screen-share/index.js';
27
30
  export * from './serve-updates.js';
28
31
  export * from './session-catalog.js';
29
32
  export * from './session-files.js';
@@ -2,6 +2,7 @@ import { type ChildProcess } from 'node:child_process';
2
2
  import { type Application, ApplicationLifecycle } from '@celljs/core';
3
3
  import { KeepAwake, TaSessionRegistry } from './host-protocol.js';
4
4
  import { type RelayBridge } from './relay-bridge.js';
5
+ import { ScreenShares } from './screen-share/screen-shares.js';
5
6
  /** What KeepAwakeUtil.wanted weighs. */
6
7
  export interface KeepAwakeState {
7
8
  /** Not turned off (RelayConfig.keepAwake). */
@@ -30,6 +31,8 @@ export declare namespace KeepAwakeUtil {
30
31
  export declare class KeepAwakeImpl implements KeepAwake, ApplicationLifecycle<Application> {
31
32
  protected readonly bridge: RelayBridge;
32
33
  protected readonly sessions: TaSessionRegistry;
34
+ /** A page looking at a desktop keeps the computer awake as a session that runs does. */
35
+ protected readonly desktops: ScreenShares;
33
36
  protected deviceAt: number;
34
37
  protected timer?: ReturnType<typeof setInterval>;
35
38
  protected child?: ChildProcess;
@@ -11,6 +11,7 @@ import { spawn } from 'node:child_process';
11
11
  import { ApplicationLifecycle, Autowired, Component } from '@celljs/core';
12
12
  import { KeepAwake, TaSessionRegistry } from './host-protocol.js';
13
13
  import { RELAY_BRIDGE } from './relay-bridge.js';
14
+ import { ScreenShares } from './screen-share/screen-shares.js';
14
15
  export var KeepAwakeUtil;
15
16
  (function (KeepAwakeUtil) {
16
17
  /** How long after a device left the computer stays awake: a phone put away a while comes back to a Ta that answers. */
@@ -75,7 +76,7 @@ let KeepAwakeImpl = class KeepAwakeImpl {
75
76
  if (this.bridge.devicesOpen > 0) {
76
77
  this.deviceAt = now;
77
78
  }
78
- const running = this.sessions.list().some(session => session.pi.isStreaming);
79
+ const running = this.sessions.list().some(session => session.pi.isStreaming) || this.desktops.watched;
79
80
  const enabled = this.bridge.store.read().keepAwake !== false;
80
81
  if (KeepAwakeUtil.wanted({ enabled, running, deviceAt: this.deviceAt, now })) {
81
82
  this.hold();
@@ -121,6 +122,10 @@ __decorate([
121
122
  Autowired(TaSessionRegistry),
122
123
  __metadata("design:type", Object)
123
124
  ], KeepAwakeImpl.prototype, "sessions", void 0);
125
+ __decorate([
126
+ Autowired(ScreenShares),
127
+ __metadata("design:type", ScreenShares)
128
+ ], KeepAwakeImpl.prototype, "desktops", void 0);
124
129
  KeepAwakeImpl = __decorate([
125
130
  Component([KeepAwake, ApplicationLifecycle])
126
131
  ], KeepAwakeImpl);