@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
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SignInPages = exports.SignInPageUtil = void 0;
4
4
  const ta_protocol_1 = require("@celljs/ta-protocol");
5
+ const sign_in_devices_1 = require("./sign-in-devices");
5
6
  const sign_in_flow_1 = require("./sign-in-flow");
6
7
  /** Ties the browser that comes back from the provider to the one that went: login CSRF. */
7
8
  const STATE_COOKIE = 'ta_sign_in';
@@ -29,6 +30,40 @@ var SignInPageUtil;
29
30
  return `/#${params.toString()}`;
30
31
  }
31
32
  SignInPageUtil.back = back;
33
+ /**
34
+ * The page of the web client for the device of `code` (TA_DEVICE_SIGN_IN_PATH): where the user lets it in, and after
35
+ * the provider how it went (`done`: it gets its token; `waiting`: once the account is let in; `failed`).
36
+ */
37
+ function deviceBack(code, outcome, from) {
38
+ return `/#${new URLSearchParams({ device: code, ...(outcome ? { 'device-sign-in': outcome } : {}), ...(from ? { from } : {}) }).toString()}`;
39
+ }
40
+ SignInPageUtil.deviceBack = deviceBack;
41
+ function json(response, status, body) {
42
+ response.statusCode = status;
43
+ response.setHeader('Content-Type', 'application/json');
44
+ response.end(JSON.stringify(body));
45
+ }
46
+ SignInPageUtil.json = json;
47
+ /** A small JSON body; undefined for one too big or not JSON. */
48
+ async function body(request, max = 4096) {
49
+ const chunks = [];
50
+ let size = 0;
51
+ for await (const chunk of request) {
52
+ size += chunk.length;
53
+ if (size > max) {
54
+ return undefined;
55
+ }
56
+ chunks.push(chunk);
57
+ }
58
+ try {
59
+ const value = JSON.parse(Buffer.concat(chunks).toString('utf8') || '{}');
60
+ return value && typeof value === 'object' && !Array.isArray(value) ? value : undefined;
61
+ }
62
+ catch (_a) {
63
+ return undefined;
64
+ }
65
+ }
66
+ SignInPageUtil.body = body;
32
67
  function redirect(response, location) {
33
68
  response.statusCode = 302;
34
69
  response.setHeader('Location', location);
@@ -55,10 +90,14 @@ var SignInPages;
55
90
  }
56
91
  SignInPages.matches = matches;
57
92
  async function handle(request, response, flow, options) {
58
- var _a, _b;
93
+ var _a, _b, _c, _d;
59
94
  const url = new URL((_a = request.url) !== null && _a !== void 0 ? _a : '/', 'http://localhost');
60
95
  response.setHeader('Cache-Control', 'no-store');
61
96
  response.setHeader('Referrer-Policy', 'no-referrer');
97
+ if (url.pathname === ta_protocol_1.TA_DEVICE_SIGN_IN_PATH || url.pathname.startsWith(`${ta_protocol_1.TA_DEVICE_SIGN_IN_PATH}/`)) {
98
+ await device(request, response, flow, url, options);
99
+ return;
100
+ }
62
101
  if (request.method !== 'GET' && request.method !== 'HEAD') {
63
102
  response.setHeader('Allow', 'GET, HEAD');
64
103
  SignInPageUtil.end(response, 405);
@@ -66,33 +105,56 @@ var SignInPages;
66
105
  }
67
106
  const [providerId, step, ...rest] = url.pathname.slice(ta_protocol_1.TA_SIGN_IN_PATH.length + 1).split('/');
68
107
  if (!providerId) {
69
- const ways = { providers: flow.providers.map(({ id, name }) => ({ id, name })) };
108
+ const ways = {
109
+ providers: [
110
+ ...flow.providers.map(({ id, name }) => ({ id, name })),
111
+ ...flow.polled.map(({ id, name }) => ({ id, name, polled: true })),
112
+ ],
113
+ };
70
114
  response.setHeader('Content-Type', 'application/json');
115
+ // Which ways there are is no secret: the app and Ta Desktop, of another origin, offer them on their sign-in.
116
+ response.setHeader('Access-Control-Allow-Origin', '*');
71
117
  SignInPageUtil.end(response, 200, JSON.stringify(ways));
72
118
  return;
73
119
  }
120
+ const polled = flow.polled.some(one => one.id === providerId);
121
+ if (polled && !step && rest.length === 0) {
122
+ await goPolled(response, flow, providerId, (_b = url.searchParams.get('device')) !== null && _b !== void 0 ? _b : '', options);
123
+ return;
124
+ }
74
125
  if (!flow.provider(providerId) || rest.length > 0 || (step && step !== 'callback')) {
75
126
  SignInPageUtil.end(response, 404);
76
127
  return;
77
128
  }
78
129
  if (!step) {
79
- await go(request, response, flow, providerId, (_b = url.searchParams.get('bind')) !== null && _b !== void 0 ? _b : undefined, options);
130
+ await go(request, response, flow, providerId, (_c = url.searchParams.get('bind')) !== null && _c !== void 0 ? _c : undefined, options, (_d = url.searchParams.get('device')) !== null && _d !== void 0 ? _d : undefined);
80
131
  return;
81
132
  }
82
133
  await back(request, response, flow, providerId, url.searchParams, options);
83
134
  }
84
135
  SignInPages.handle = handle;
85
- async function go(request, response, flow, providerId, bind, options) {
136
+ async function go(request, response, flow, providerId, bind, options, device) {
86
137
  const origin = sign_in_flow_1.SignInUtil.origin(request, flow.publicUrl);
87
138
  try {
88
- const { url, state } = await flow.start(providerId, origin, bind);
139
+ const { url, state } = await flow.start(providerId, origin, bind, Date.now(), device === undefined ? undefined : sign_in_devices_1.SignInDevicesUtil.normalize(device));
89
140
  const secure = origin.startsWith('https:') ? '; Secure' : '';
90
141
  response.setHeader('Set-Cookie', `${STATE_COOKIE}=${state}; Path=${ta_protocol_1.TA_SIGN_IN_PATH}; Max-Age=600; HttpOnly; SameSite=Lax${secure}`);
91
142
  SignInPageUtil.redirect(response, url);
92
143
  }
93
144
  catch (error) {
94
145
  console.warn(`${options.name}: signing in with ${providerId} failed: ${error instanceof Error ? error.message : error}`);
95
- SignInPageUtil.redirect(response, SignInPageUtil.back({ outcome: 'failed' }));
146
+ SignInPageUtil.redirect(response, device === undefined ? SignInPageUtil.back({ outcome: 'failed' }) : SignInPageUtil.deviceBack(sign_in_devices_1.SignInDevicesUtil.normalize(device), 'failed'));
147
+ }
148
+ }
149
+ /** To a polled provider for the device of `code`; Ta asks it who agreed. Only for a device: a browser does not come back. */
150
+ async function goPolled(response, flow, providerId, given, options) {
151
+ const code = sign_in_devices_1.SignInDevicesUtil.normalize(given);
152
+ try {
153
+ SignInPageUtil.redirect(response, await flow.startPolled(providerId, code));
154
+ }
155
+ catch (error) {
156
+ console.warn(`${options.name}: signing in with ${providerId} failed: ${error instanceof Error ? error.message : error}`);
157
+ SignInPageUtil.redirect(response, SignInPageUtil.deviceBack(code, 'failed'));
96
158
  }
97
159
  }
98
160
  async function back(request, response, flow, providerId, params, options) {
@@ -108,7 +170,11 @@ var SignInPages;
108
170
  }
109
171
  try {
110
172
  const result = await flow.finish(providerId, state, code, request.headers['user-agent']);
111
- if ('token' in result) {
173
+ if ('device' in result) {
174
+ console.log(`${options.name}: ${result.account.id} signed in for a device${result.allowed ? '' : ', which waits for the account to be let in'}`);
175
+ SignInPageUtil.redirect(response, SignInPageUtil.deviceBack(result.device, result.allowed ? 'done' : 'waiting'));
176
+ }
177
+ else if ('token' in result) {
112
178
  console.log(`${options.name}: ${result.account.id} signed in`);
113
179
  await ((_a = options.onSignedIn) === null || _a === void 0 ? void 0 : _a.call(options, response, result.token, result.account, sign_in_flow_1.SignInUtil.origin(request, flow.publicUrl)));
114
180
  SignInPageUtil.redirect(response, SignInPageUtil.back({ token: result.token }));
@@ -124,4 +190,67 @@ var SignInPages;
124
190
  }
125
191
  }
126
192
  })(SignInPages || (exports.SignInPages = SignInPages = {}));
193
+ /** Answers any origin: what these give goes to who holds the secret of the device, and no cookie is read. */
194
+ const DEVICE_CORS = {
195
+ 'Access-Control-Allow-Origin': '*',
196
+ 'Access-Control-Allow-Methods': 'POST, OPTIONS',
197
+ 'Access-Control-Allow-Headers': 'Content-Type',
198
+ 'Access-Control-Max-Age': '600',
199
+ };
200
+ /**
201
+ * TA_DEVICE_SIGN_IN_PATH: `POST` asks for a code, `POST /poll` takes the token once the user let the device in, from any
202
+ * origin; `GET ?code=` is where the user goes, the page of the web client; `POST /approve`, with the token of a browser
203
+ * signed in here, lets the device in as its account, with no provider (a sign-in by `ta gateway link` has none).
204
+ */
205
+ async function device(request, response, flow, url, options) {
206
+ var _a;
207
+ const step = url.pathname.slice(ta_protocol_1.TA_DEVICE_SIGN_IN_PATH.length);
208
+ if (step !== '/approve') {
209
+ for (const [name, value] of Object.entries(DEVICE_CORS)) {
210
+ response.setHeader(name, value);
211
+ }
212
+ }
213
+ if (request.method === 'OPTIONS') {
214
+ SignInPageUtil.end(response, 204);
215
+ return;
216
+ }
217
+ if (step === '' && request.method === 'GET') {
218
+ const code = sign_in_devices_1.SignInDevicesUtil.normalize((_a = url.searchParams.get('code')) !== null && _a !== void 0 ? _a : '');
219
+ SignInPageUtil.redirect(response, SignInPageUtil.deviceBack(code, undefined, flow.devices.name(code)));
220
+ return;
221
+ }
222
+ if (request.method !== 'POST' || !['', '/poll', '/approve'].includes(step)) {
223
+ SignInPageUtil.end(response, step === '' || step === '/poll' || step === '/approve' ? 405 : 404);
224
+ return;
225
+ }
226
+ const body = await SignInPageUtil.body(request);
227
+ if (!body) {
228
+ SignInPageUtil.end(response, 400);
229
+ return;
230
+ }
231
+ if (step === '') {
232
+ const started = flow.devices.start(typeof body.name === 'string' ? body.name : undefined);
233
+ const origin = sign_in_flow_1.SignInUtil.origin(request, flow.publicUrl);
234
+ const answer = { ...started, url: `${origin}${ta_protocol_1.TA_DEVICE_SIGN_IN_PATH}?code=${started.code}`, interval: sign_in_devices_1.DEVICE_POLL_MS };
235
+ SignInPageUtil.json(response, 200, answer);
236
+ return;
237
+ }
238
+ if (step === '/poll') {
239
+ const state = flow.devices.poll(typeof body.device === 'string' ? body.device : '');
240
+ if (state.status === 'done') {
241
+ console.log(`${options.name}: ${state.account} signed in on a device`);
242
+ }
243
+ SignInPageUtil.json(response, 200, state);
244
+ return;
245
+ }
246
+ const header = request.headers.authorization;
247
+ const signIn = (header === null || header === void 0 ? void 0 : header.startsWith('Bearer ')) ? flow.store.check(header.slice('Bearer '.length)) : undefined;
248
+ if (!signIn) {
249
+ SignInPageUtil.end(response, 401);
250
+ return;
251
+ }
252
+ const code = typeof body.code === 'string' ? body.code : '';
253
+ const ok = flow.devices.signedIn(code, { id: signIn.account, name: signIn.name, avatar: signIn.avatar });
254
+ SignInPageUtil.json(response, ok ? 200 : 404, { ok });
255
+ }
127
256
  //# sourceMappingURL=sign-in-pages.js.map
@@ -1,4 +1,5 @@
1
1
  import type { TaSignInKind, TaSignInProvider, TaSignInSetup } from '@celljs/ta-protocol';
2
+ import { type PolledSignInProvider } from './polled-sign-in';
2
3
  /** Who signed in, as the provider says: `id` is the account as TA_ALLOWED_USERS names it (`github:<login>`). */
3
4
  export interface SignInAccount {
4
5
  id: string;
@@ -209,6 +210,11 @@ export declare namespace SignInProviders {
209
210
  * one's own with its device flow on; by default Ta's own, on GitHub.com.
210
211
  */
211
212
  function device(env: Record<string, string | undefined>): DeviceSignInProvider | undefined;
213
+ /**
214
+ * The polled providers of the environment (PushedSignIn): `TA_IAM_ISSUER` and `TA_IAM_CLIENT_ID`, a company's sign-in
215
+ * for CLIs, whose accounts are `iam:<sub>`; `TA_IAM_CLI_ID` and `TA_IAM_NAME` (what its button says) optional.
216
+ */
217
+ function polled(env: Record<string, string | undefined>): PolledSignInProvider[];
212
218
  /**
213
219
  * The providers the operator configured in the environment of ta serve: a provider is offered when it
214
220
  * has its id and its secret.
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SignInProviders = exports.WeChatSignIn = exports.OidcSignIn = exports.GitHubDeviceSignIn = exports.GitHubSignIn = exports.SignInHttp = exports.SignInError = void 0;
4
+ const polled_sign_in_1 = require("./polled-sign-in");
4
5
  /** A sign-in that failed with the provider (a code refused, an account without what it needs). */
5
6
  class SignInError extends Error {
6
7
  }
@@ -390,6 +391,20 @@ var SignInProviders;
390
391
  return new GitHubDeviceSignIn(clientId || GitHubDeviceSignIn.CLIENT_ID, GitHubSignIn.endpoints(url || undefined));
391
392
  }
392
393
  SignInProviders.device = device;
394
+ /**
395
+ * The polled providers of the environment (PushedSignIn): `TA_IAM_ISSUER` and `TA_IAM_CLIENT_ID`, a company's sign-in
396
+ * for CLIs, whose accounts are `iam:<sub>`; `TA_IAM_CLI_ID` and `TA_IAM_NAME` (what its button says) optional.
397
+ */
398
+ function polled(env) {
399
+ var _a, _b, _c, _d;
400
+ const issuer = (_a = env.TA_IAM_ISSUER) === null || _a === void 0 ? void 0 : _a.trim();
401
+ const clientId = (_b = env.TA_IAM_CLIENT_ID) === null || _b === void 0 ? void 0 : _b.trim();
402
+ if (!issuer || !clientId) {
403
+ return [];
404
+ }
405
+ return [new polled_sign_in_1.PushedSignIn({ id: 'iam', name: ((_c = env.TA_IAM_NAME) === null || _c === void 0 ? void 0 : _c.trim()) || 'SSO', issuer, clientId, cliId: ((_d = env.TA_IAM_CLI_ID) === null || _d === void 0 ? void 0 : _d.trim()) || undefined })];
406
+ }
407
+ SignInProviders.polled = polled;
393
408
  /**
394
409
  * The providers the operator configured in the environment of ta serve: a provider is offered when it
395
410
  * has its id and its secret.
@@ -0,0 +1,11 @@
1
+ import type { ExtensionAPI, TaExtension } from '@celljs/ta-harness';
2
+ /**
3
+ * Tells the model of every session who wrote a message (docs/design/ta-sources.md): the user, a part of Ta for them
4
+ * (`[ta:from …]`), or a notice of a part of Ta (`[ta:notice …]`), which it weighs below what the user said. A section
5
+ * of pi's system prompt of its own (`<ta-sources>`), which other coding agents get with Ta's other notes.
6
+ */
7
+ export declare class SourcesExtension implements TaExtension {
8
+ readonly name = "ta-sources";
9
+ register(pi: ExtensionAPI): void;
10
+ }
11
+ //# sourceMappingURL=sources-extension.d.ts.map
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SourcesExtension = void 0;
4
+ const ta_protocol_1 = require("@celljs/ta-protocol");
5
+ /**
6
+ * Tells the model of every session who wrote a message (docs/design/ta-sources.md): the user, a part of Ta for them
7
+ * (`[ta:from …]`), or a notice of a part of Ta (`[ta:notice …]`), which it weighs below what the user said. A section
8
+ * of pi's system prompt of its own (`<ta-sources>`), which other coding agents get with Ta's other notes.
9
+ */
10
+ class SourcesExtension {
11
+ constructor() {
12
+ this.name = 'ta-sources';
13
+ }
14
+ register(pi) {
15
+ pi.on('before_agent_start', event => {
16
+ const options = event.systemPromptOptions;
17
+ options.sections = { ...options.sections, [ta_protocol_1.TaMessageSource.SECTION]: ta_protocol_1.TaMessageSource.PROMPT };
18
+ });
19
+ }
20
+ }
21
+ exports.SourcesExtension = SourcesExtension;
22
+ //# sourceMappingURL=sources-extension.js.map
@@ -22,7 +22,6 @@ const ta_protocol_1 = require("@celljs/ta-protocol");
22
22
  const directory_relocator_1 = require("./directory-relocator");
23
23
  const host_protocol_1 = require("./host-protocol");
24
24
  const serve_updates_1 = require("./serve-updates");
25
- const session_info_util_1 = require("./session-info-util");
26
25
  const slash_command_util_1 = require("./slash-command-util");
27
26
  const ta_errors_1 = require("./ta-errors");
28
27
  const team_protocol_1 = require("./team/team-protocol");
@@ -305,7 +304,8 @@ let TaServerImpl = class TaServerImpl {
305
304
  if (!entry || (position === 'before' && !user)) {
306
305
  throw ta_errors_1.TaErrors.invalidArgument(`No entry to fork from has the id ${entryId}.`, 'Pass the id of a message of the user, or position "at".');
307
306
  }
308
- const text = position === 'before' && user ? session_info_util_1.SessionInfoUtil.text(user.content) : undefined;
307
+ // What the user typed, to edit again: the marks of the model are made again when it is sent.
308
+ const text = position === 'before' && user ? ta_protocol_1.TaSaid.of(user) : undefined;
309
309
  const leafId = position === 'before' ? entry.parentId : entry.id;
310
310
  const file = manager.getSessionFile();
311
311
  if (!leafId || !file || !(0, node_fs_1.existsSync)(file)) {
@@ -27,6 +27,7 @@ const remote_protocol_1 = require("./remote/remote-protocol");
27
27
  const session_catalog_1 = require("./session-catalog");
28
28
  const session_files_1 = require("./session-files");
29
29
  const slash_command_util_1 = require("./slash-command-util");
30
+ const sources_extension_1 = require("./sources-extension");
30
31
  const ta_errors_1 = require("./ta-errors");
31
32
  const ta_session_1 = require("./ta-session");
32
33
  const working_directory_1 = require("./working-directory");
@@ -215,6 +216,7 @@ let DefaultTaSessionFactory = class DefaultTaSessionFactory {
215
216
  new package_host_extension_1.PackageHostExtension(this.packageHosts, new session_files_1.ExecSessionFiles(environment, piCwd)),
216
217
  new ta_harness_1.BrandExtension(sdk),
217
218
  new delegate_extension_1.DelegateExtension(),
219
+ new sources_extension_1.SourcesExtension(),
218
220
  ...(environment.local ? [] : [new ta_harness_1.ExecExtension(environment, sdk, piCwd)]),
219
221
  ];
220
222
  return [
@@ -176,6 +176,14 @@ const RULES = {
176
176
  closeTerminal: fixed('commands.terminal'),
177
177
  listTerminals: fixed('commands.terminal'),
178
178
  },
179
+ TaAccountServer: {
180
+ getAccount: fixed('settings.view'),
181
+ signIn: fixed('settings.manage'),
182
+ cancelSignIn: fixed('settings.manage'),
183
+ approve: fixed('settings.manage'),
184
+ remove: fixed('settings.manage'),
185
+ signOut: fixed('settings.manage'),
186
+ },
179
187
  TaRelayServer: {
180
188
  getRelay: fixed('settings.view'),
181
189
  pair: fixed('settings.manage'),
@@ -217,6 +225,12 @@ const RULES = {
217
225
  'friendLink',
218
226
  'addFriend',
219
227
  'offerFriend',
228
+ 'inviteFriends',
229
+ 'listGroupInvites',
230
+ 'answerGroupInvite',
231
+ 'sendToFriends',
232
+ 'listFriendShares',
233
+ 'answerFriendShare',
220
234
  'listFriendRequests',
221
235
  'answerFriend',
222
236
  'removeFriend',
@@ -231,6 +245,7 @@ const RULES = {
231
245
  updateVoice: fixed('settings.manage'),
232
246
  removeVoice: fixed('settings.manage'),
233
247
  chooseVoice: fixed('settings.manage'),
248
+ setBargeIn: fixed('settings.manage'),
234
249
  openVoice: fixed('models.use'),
235
250
  sendVoice: fixed('models.use'),
236
251
  sayVoice: fixed('models.use'),
@@ -289,6 +304,26 @@ const RULES = {
289
304
  answer: fixed('hosts.use'),
290
305
  disconnect: fixed('hosts.use'),
291
306
  },
307
+ // Remote desktops: seeing and working a screen is all the owner can do, and in the first stage only the owner does it
308
+ // (docs/design/ta-desktop-remote.md 6.2); no role or grant gives it.
309
+ TaScreenShareServer: {
310
+ listDesktops: owner,
311
+ listDesktopScreens: owner,
312
+ addDesktop: owner,
313
+ removeDesktop: owner,
314
+ openDesktop: owner,
315
+ closeDesktop: owner,
316
+ readDesktopFrames: owner,
317
+ setDesktopView: owner,
318
+ sendDesktopInput: owner,
319
+ pasteToDesktop: owner,
320
+ readDesktopClipboard: owner,
321
+ takeDesktopControl: owner,
322
+ releaseDesktopControl: owner,
323
+ endAllDesktops: owner,
324
+ watchDesktops: owner,
325
+ answerDesktop: owner,
326
+ },
292
327
  };
293
328
  /** By name, own keys only: a method such as `toString` is no rule. */
294
329
  const BY_SERVICE = new Map(Object.entries(RULES).map(([service, rules]) => [service, new Map(Object.entries(rules))]));
@@ -1,6 +1,6 @@
1
1
  import { type CodingAgentOptions } from '@celljs/ai-coding-agent';
2
2
  import { type RpcConnection } from '@celljs/rpc/lib/node';
3
- import { type TaExtensionVoices, type TaVoiceEngine, TaVoiceServer, type TaVoiceSession, type TaVoices, type TaVoiceType } from '@celljs/ta-protocol';
3
+ import { TaBargeIn, type TaExtensionVoices, type TaVoiceEngine, TaVoiceServer, type TaVoiceSession, type TaVoices, type TaVoiceType } from '@celljs/ta-protocol';
4
4
  import { VoicesFile } from './voices-file';
5
5
  export declare const VOICE_BRIDGE: unique symbol;
6
6
  interface OpenVoice {
@@ -33,6 +33,7 @@ export declare class VoiceBridge {
33
33
  protected tried(type: string, options: Record<string, unknown>): Promise<Record<string, unknown>>;
34
34
  remove(id: string): void;
35
35
  choose(id: string | null): void;
36
+ setBargeIn(bargeIn: Partial<TaBargeIn>): void;
36
37
  openFor(connection: RpcConnection, language: string): Promise<TaVoiceSession>;
37
38
  send(connection: RpcConnection, id: string, audio: string): void;
38
39
  say(connection: RpcConnection, id: string, text: string): number;
@@ -57,6 +58,7 @@ export declare class TaVoiceServerImpl implements TaVoiceServer {
57
58
  updateVoice(id: string, options: Record<string, unknown>, name?: string): Promise<void>;
58
59
  removeVoice(id: string): Promise<void>;
59
60
  chooseVoice(id: string | null): Promise<void>;
61
+ setBargeIn(bargeIn: Partial<TaBargeIn>): Promise<void>;
60
62
  openVoice(options: {
61
63
  language: string;
62
64
  }): Promise<TaVoiceSession>;
@@ -76,7 +76,7 @@ let VoiceBridge = VoiceBridge_1 = class VoiceBridge {
76
76
  speaks,
77
77
  }));
78
78
  const use = config.use && services.some(service => service.id === config.use) ? { use: config.use } : {};
79
- return { services, types, file: this.file.file, ...use };
79
+ return { services, types, file: this.file.file, bargeIn: ta_protocol_1.TaBargeIn.resolve(config.bargeIn), ...use };
80
80
  }
81
81
  /** Opens a service of the type once before it is kept, so that a wrong key is said now. */
82
82
  async add(type, options, name) {
@@ -131,6 +131,9 @@ let VoiceBridge = VoiceBridge_1 = class VoiceBridge {
131
131
  choose(id) {
132
132
  this.file.use(id !== null && id !== void 0 ? id : undefined);
133
133
  }
134
+ setBargeIn(bargeIn) {
135
+ this.file.setBargeIn(ta_protocol_1.TaBargeIn.pick(bargeIn));
136
+ }
134
137
  async openFor(connection, language) {
135
138
  var _a;
136
139
  const service = this.file.inUse();
@@ -170,7 +173,8 @@ let VoiceBridge = VoiceBridge_1 = class VoiceBridge {
170
173
  const voice = { id, connection, engine, speaks: definition.speaks && !!engine.say, nextSay: 0, closed: false };
171
174
  this.open.set(id, voice);
172
175
  connection.onClose(() => this.close(connection, id));
173
- return { voiceId: id, inputRate: engine.inputRate, outputRate: engine.outputRate, speaks: voice.speaks };
176
+ const bargeIn = ta_protocol_1.TaBargeIn.resolve(this.file.safeRead().config.bargeIn);
177
+ return { voiceId: id, inputRate: engine.inputRate, outputRate: engine.outputRate, speaks: voice.speaks, bargeIn };
174
178
  }
175
179
  send(connection, id, audio) {
176
180
  if (typeof audio !== 'string' || audio.length > MAX_AUDIO) {
@@ -247,6 +251,9 @@ let TaVoiceServerImpl = class TaVoiceServerImpl {
247
251
  chooseVoice(id) {
248
252
  return ta_errors_1.TaErrors.guard(() => this.bridge.choose(id !== null && id !== void 0 ? id : null));
249
253
  }
254
+ setBargeIn(bargeIn) {
255
+ return ta_errors_1.TaErrors.guard(() => this.bridge.setBargeIn(bargeIn !== null && bargeIn !== void 0 ? bargeIn : {}));
256
+ }
250
257
  openVoice(options) {
251
258
  return ta_errors_1.TaErrors.guard(() => this.bridge.openFor(node_1.RpcContext.requireConnection(), options === null || options === void 0 ? void 0 : options.language));
252
259
  }
@@ -1,3 +1,4 @@
1
+ import type { TaBargeIn } from '@celljs/ta-protocol';
1
2
  /** A service of voices.json: a type a package registered, and the options of its form. */
2
3
  export interface VoiceServiceEntry {
3
4
  id: string;
@@ -9,6 +10,8 @@ export interface VoicesConfig {
9
10
  services?: VoiceServiceEntry[];
10
11
  /** The service calls use; none: the voice of the device. */
11
12
  use?: string;
13
+ /** When a sound stops what the service reads: any of it, over the defaults (TaBargeIn.resolve). */
14
+ bargeIn?: Partial<TaBargeIn>;
12
15
  }
13
16
  /** voices.json of the agent directory (docs/design/ta-voice.md 3): its keys stay there, written 0600. */
14
17
  export declare class VoicesFile {
@@ -27,6 +30,8 @@ export declare class VoicesFile {
27
30
  add(type: string, options: Record<string, unknown>, name?: string): string;
28
31
  /** Its options and name, the rest as it was; throws for one that is not there. */
29
32
  update(id: string, options: Record<string, unknown>, name?: string): void;
33
+ /** Sets keys of bargeIn, the others kept. */
34
+ setBargeIn(bargeIn: Partial<TaBargeIn>): void;
30
35
  remove(id: string): void;
31
36
  use(id: string | undefined): void;
32
37
  protected write(config: VoicesConfig): void;
@@ -20,7 +20,11 @@ class VoicesFile {
20
20
  const services = Array.isArray(config === null || config === void 0 ? void 0 : config.services)
21
21
  ? config.services.filter(service => service && typeof service.id === 'string' && typeof service.type === 'string' && typeof service.options === 'object')
22
22
  : [];
23
- return { services, ...(typeof (config === null || config === void 0 ? void 0 : config.use) === 'string' ? { use: config.use } : {}) };
23
+ return {
24
+ services,
25
+ ...(typeof (config === null || config === void 0 ? void 0 : config.use) === 'string' ? { use: config.use } : {}),
26
+ ...((config === null || config === void 0 ? void 0 : config.bargeIn) && typeof config.bargeIn === 'object' ? { bargeIn: config.bargeIn } : {}),
27
+ };
24
28
  }
25
29
  /** What reads, or nothing with why it does not parse. */
26
30
  safeRead() {
@@ -67,11 +71,17 @@ class VoicesFile {
67
71
  services[at] = { ...kept, ...(name ? { name } : {}), options };
68
72
  this.write({ ...config, services });
69
73
  }
74
+ /** Sets keys of bargeIn, the others kept. */
75
+ setBargeIn(bargeIn) {
76
+ const config = this.read();
77
+ this.write({ ...config, bargeIn: { ...config.bargeIn, ...bargeIn } });
78
+ }
70
79
  remove(id) {
71
80
  var _a;
72
81
  const config = this.read();
73
82
  const services = ((_a = config.services) !== null && _a !== void 0 ? _a : []).filter(service => service.id !== id);
74
- this.write({ services, ...(config.use && config.use !== id ? { use: config.use } : {}) });
83
+ const { use, ...rest } = config;
84
+ this.write({ ...rest, services, ...(use && use !== id ? { use } : {}) });
75
85
  }
76
86
  use(id) {
77
87
  var _a, _b;
@@ -79,7 +89,8 @@ class VoicesFile {
79
89
  if (id !== undefined && !((_a = config.services) !== null && _a !== void 0 ? _a : []).some(service => service.id === id)) {
80
90
  throw new Error(`There is no voice service ${id} in voices.json.`);
81
91
  }
82
- this.write({ services: (_b = config.services) !== null && _b !== void 0 ? _b : [], ...(id ? { use: id } : {}) });
92
+ const { use: _, ...rest } = config;
93
+ this.write({ ...rest, services: (_b = config.services) !== null && _b !== void 0 ? _b : [], ...(id ? { use: id } : {}) });
83
94
  }
84
95
  write(config) {
85
96
  (0, node_fs_1.mkdirSync)((0, node_path_1.dirname)(this.file), { recursive: true });
@@ -1,7 +1,8 @@
1
1
  export declare const TaWorkingDirectory: unique symbol;
2
2
  /**
3
- * The working directory the user chose for ta serve (TaServer.setWorkingDirectory), and the hosts of the
4
- * remote directories opened lately (TaRemoteServer), kept across restarts.
3
+ * The working directory the user chose for ta serve (TaServer.setWorkingDirectory), the hosts of the
4
+ * remote directories opened lately (TaRemoteServer) and the desktops added (TaScreenShareServer), kept across
5
+ * restarts.
5
6
  */
6
7
  export interface TaWorkingDirectory {
7
8
  get(): string | undefined;
@@ -10,6 +11,9 @@ export interface TaWorkingDirectory {
10
11
  recentHosts(): string[];
11
12
  addRecentHost(host: string): void;
12
13
  removeRecentHost(host: string): void;
14
+ /** The desktops the user added, as kept: checked by whoever reads them. */
15
+ desktops(): unknown[];
16
+ setDesktops(desktops: unknown[]): void;
13
17
  }
14
18
  /** In ta.json of the agent directory, beside Ta's other settings of its own; the file keeps its other keys. */
15
19
  export declare class TaWorkingDirectoryImpl implements TaWorkingDirectory {
@@ -19,6 +23,8 @@ export declare class TaWorkingDirectoryImpl implements TaWorkingDirectory {
19
23
  recentHosts(): string[];
20
24
  addRecentHost(host: string): void;
21
25
  removeRecentHost(host: string): void;
26
+ desktops(): unknown[];
27
+ setDesktops(desktops: unknown[]): void;
22
28
  protected write(changes: Record<string, unknown>): void;
23
29
  protected read(): Record<string, unknown>;
24
30
  }
@@ -43,6 +43,13 @@ let TaWorkingDirectoryImpl = class TaWorkingDirectoryImpl {
43
43
  this.write({ remoteHosts: hosts.filter(other => other !== host) });
44
44
  }
45
45
  }
46
+ desktops() {
47
+ const { desktops } = this.read();
48
+ return Array.isArray(desktops) ? desktops : [];
49
+ }
50
+ setDesktops(desktops) {
51
+ this.write({ desktops });
52
+ }
46
53
  write(changes) {
47
54
  (0, node_fs_1.writeFileSync)(`${this.file}.tmp`, `${JSON.stringify({ ...this.read(), ...changes }, null, 2)}\n`);
48
55
  (0, node_fs_1.renameSync)(`${this.file}.tmp`, this.file);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celljs/ta-host",
3
- "version": "4.17.0",
3
+ "version": "4.19.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.17.0",
38
- "@celljs/ai-coding-agent": "4.17.0",
39
- "@celljs/core": "4.17.0",
40
- "@celljs/rpc": "4.17.0",
41
- "@celljs/ta-exec": "4.17.0",
42
- "@celljs/ta-harness": "4.17.0",
43
- "@celljs/ta-protocol": "4.17.0",
44
- "@celljs/ta-relay": "4.17.0",
45
- "@celljs/web": "4.17.0",
37
+ "@celljs/ai-agent": "4.19.0",
38
+ "@celljs/ai-coding-agent": "4.19.0",
39
+ "@celljs/core": "4.19.0",
40
+ "@celljs/rpc": "4.19.0",
41
+ "@celljs/ta-exec": "4.19.0",
42
+ "@celljs/ta-harness": "4.19.0",
43
+ "@celljs/ta-protocol": "4.19.0",
44
+ "@celljs/ta-relay": "4.19.0",
45
+ "@celljs/web": "4.19.0",
46
46
  "@earendil-works/pi-coding-agent": "^1.5.2"
47
47
  },
48
48
  "devDependencies": {
@@ -75,6 +75,10 @@
75
75
  "import": "./esm/node/remote/index.js",
76
76
  "default": "./lib/node/remote/index.js"
77
77
  },
78
+ "./lib/node/screen-share": {
79
+ "import": "./esm/node/screen-share/index.js",
80
+ "default": "./lib/node/screen-share/index.js"
81
+ },
78
82
  "./lib/node/session-storage": {
79
83
  "import": "./esm/node/session-storage/index.js",
80
84
  "default": "./lib/node/session-storage/index.js"