@celljs/ta-host 4.17.0 → 4.18.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 (143) hide show
  1. package/esm/node/app-commands.d.ts +1 -1
  2. package/esm/node/app-commands.js +46 -29
  3. package/esm/node/credentials.d.ts +12 -0
  4. package/esm/node/credentials.js +35 -0
  5. package/esm/node/index.d.ts +2 -0
  6. package/esm/node/index.js +2 -0
  7. package/esm/node/keep-awake.d.ts +3 -0
  8. package/esm/node/keep-awake.js +6 -1
  9. package/esm/node/package-hosts.d.ts +2 -0
  10. package/esm/node/package-hosts.js +6 -0
  11. package/esm/node/rooms-bridge.d.ts +10 -1
  12. package/esm/node/rooms-bridge.js +25 -0
  13. package/esm/node/screen-share/desktop-picture.d.ts +51 -0
  14. package/esm/node/screen-share/desktop-picture.js +133 -0
  15. package/esm/node/screen-share/desktop-session.d.ts +128 -0
  16. package/esm/node/screen-share/desktop-session.js +437 -0
  17. package/esm/node/screen-share/desktop-targets.d.ts +24 -0
  18. package/esm/node/screen-share/desktop-targets.js +80 -0
  19. package/esm/node/screen-share/desktop-viewer.d.ts +146 -0
  20. package/esm/node/screen-share/desktop-viewer.js +339 -0
  21. package/esm/node/screen-share/index.d.ts +8 -0
  22. package/esm/node/screen-share/index.js +9 -0
  23. package/esm/node/screen-share/rfb-client.d.ts +54 -0
  24. package/esm/node/screen-share/rfb-client.js +179 -0
  25. package/esm/node/screen-share/rfb-des.d.ts +11 -0
  26. package/esm/node/screen-share/rfb-des.js +143 -0
  27. package/esm/node/screen-share/rfb-encodings.d.ts +71 -0
  28. package/esm/node/screen-share/rfb-encodings.js +288 -0
  29. package/esm/node/screen-share/rfb-framebuffer.d.ts +16 -0
  30. package/esm/node/screen-share/rfb-framebuffer.js +53 -0
  31. package/esm/node/screen-share/rfb-protocol.d.ts +90 -0
  32. package/esm/node/screen-share/rfb-protocol.js +36 -0
  33. package/esm/node/screen-share/rfb-reader.d.ts +34 -0
  34. package/esm/node/screen-share/rfb-reader.js +110 -0
  35. package/esm/node/screen-share/rfb-security.d.ts +30 -0
  36. package/esm/node/screen-share/rfb-security.js +136 -0
  37. package/esm/node/screen-share/rfb-test-server.d.ts +37 -0
  38. package/esm/node/screen-share/rfb-test-server.js +116 -0
  39. package/esm/node/screen-share/screen-share-server-impl.d.ts +37 -0
  40. package/esm/node/screen-share/screen-share-server-impl.js +76 -0
  41. package/esm/node/screen-share/screen-shares.d.ts +123 -0
  42. package/esm/node/screen-share/screen-shares.js +463 -0
  43. package/esm/node/session-info-util.d.ts +10 -11
  44. package/esm/node/session-info-util.js +16 -94
  45. package/esm/node/settings-store.d.ts +1 -1
  46. package/esm/node/settings-store.js +7 -4
  47. package/esm/node/sign-in/access-store.d.ts +1 -1
  48. package/esm/node/sign-in/access-store.js +4 -1
  49. package/esm/node/sign-in/index.d.ts +2 -0
  50. package/esm/node/sign-in/index.js +2 -0
  51. package/esm/node/sign-in/polled-sign-in.d.ts +50 -0
  52. package/esm/node/sign-in/polled-sign-in.js +83 -0
  53. package/esm/node/sign-in/sign-in-devices.d.ts +55 -0
  54. package/esm/node/sign-in/sign-in-devices.js +113 -0
  55. package/esm/node/sign-in/sign-in-flow.d.ts +38 -4
  56. package/esm/node/sign-in/sign-in-flow.js +79 -4
  57. package/esm/node/sign-in/sign-in-pages.d.ts +8 -0
  58. package/esm/node/sign-in/sign-in-pages.js +137 -8
  59. package/esm/node/sign-in/sign-in-provider.d.ts +6 -0
  60. package/esm/node/sign-in/sign-in-provider.js +15 -0
  61. package/esm/node/sources-extension.d.ts +10 -0
  62. package/esm/node/sources-extension.js +18 -0
  63. package/esm/node/ta-server-impl.js +3 -3
  64. package/esm/node/ta-session-factory.js +2 -0
  65. package/esm/node/team/team-calls.js +27 -0
  66. package/esm/node/voice-bridge.d.ts +3 -1
  67. package/esm/node/voice-bridge.js +10 -3
  68. package/esm/node/voices-file.d.ts +5 -0
  69. package/esm/node/voices-file.js +14 -3
  70. package/esm/node/working-directory.d.ts +8 -2
  71. package/esm/node/working-directory.js +7 -0
  72. package/lib/node/app-commands.d.ts +1 -1
  73. package/lib/node/app-commands.js +46 -29
  74. package/lib/node/credentials.d.ts +13 -0
  75. package/lib/node/credentials.js +38 -0
  76. package/lib/node/index.d.ts +2 -0
  77. package/lib/node/index.js +2 -0
  78. package/lib/node/keep-awake.d.ts +3 -0
  79. package/lib/node/keep-awake.js +6 -1
  80. package/lib/node/package-hosts.d.ts +2 -0
  81. package/lib/node/package-hosts.js +6 -0
  82. package/lib/node/rooms-bridge.d.ts +10 -1
  83. package/lib/node/rooms-bridge.js +25 -0
  84. package/lib/node/screen-share/desktop-picture.d.ts +52 -0
  85. package/lib/node/screen-share/desktop-picture.js +136 -0
  86. package/lib/node/screen-share/desktop-session.d.ts +129 -0
  87. package/lib/node/screen-share/desktop-session.js +442 -0
  88. package/lib/node/screen-share/desktop-targets.d.ts +25 -0
  89. package/lib/node/screen-share/desktop-targets.js +84 -0
  90. package/lib/node/screen-share/desktop-viewer.d.ts +147 -0
  91. package/lib/node/screen-share/desktop-viewer.js +343 -0
  92. package/lib/node/screen-share/index.d.ts +9 -0
  93. package/lib/node/screen-share/index.js +25 -0
  94. package/lib/node/screen-share/rfb-client.d.ts +55 -0
  95. package/lib/node/screen-share/rfb-client.js +183 -0
  96. package/lib/node/screen-share/rfb-des.d.ts +12 -0
  97. package/lib/node/screen-share/rfb-des.js +146 -0
  98. package/lib/node/screen-share/rfb-encodings.d.ts +72 -0
  99. package/lib/node/screen-share/rfb-encodings.js +295 -0
  100. package/lib/node/screen-share/rfb-framebuffer.d.ts +17 -0
  101. package/lib/node/screen-share/rfb-framebuffer.js +57 -0
  102. package/lib/node/screen-share/rfb-protocol.d.ts +91 -0
  103. package/lib/node/screen-share/rfb-protocol.js +39 -0
  104. package/lib/node/screen-share/rfb-reader.d.ts +35 -0
  105. package/lib/node/screen-share/rfb-reader.js +115 -0
  106. package/lib/node/screen-share/rfb-security.d.ts +31 -0
  107. package/lib/node/screen-share/rfb-security.js +141 -0
  108. package/lib/node/screen-share/rfb-test-server.d.ts +38 -0
  109. package/lib/node/screen-share/rfb-test-server.js +120 -0
  110. package/lib/node/screen-share/screen-share-server-impl.d.ts +38 -0
  111. package/lib/node/screen-share/screen-share-server-impl.js +79 -0
  112. package/lib/node/screen-share/screen-shares.d.ts +124 -0
  113. package/lib/node/screen-share/screen-shares.js +464 -0
  114. package/lib/node/session-info-util.d.ts +10 -11
  115. package/lib/node/session-info-util.js +15 -93
  116. package/lib/node/settings-store.d.ts +1 -1
  117. package/lib/node/settings-store.js +6 -3
  118. package/lib/node/sign-in/access-store.d.ts +1 -1
  119. package/lib/node/sign-in/access-store.js +4 -1
  120. package/lib/node/sign-in/index.d.ts +2 -0
  121. package/lib/node/sign-in/index.js +2 -0
  122. package/lib/node/sign-in/polled-sign-in.d.ts +51 -0
  123. package/lib/node/sign-in/polled-sign-in.js +87 -0
  124. package/lib/node/sign-in/sign-in-devices.d.ts +56 -0
  125. package/lib/node/sign-in/sign-in-devices.js +117 -0
  126. package/lib/node/sign-in/sign-in-flow.d.ts +38 -4
  127. package/lib/node/sign-in/sign-in-flow.js +80 -5
  128. package/lib/node/sign-in/sign-in-pages.d.ts +8 -0
  129. package/lib/node/sign-in/sign-in-pages.js +136 -7
  130. package/lib/node/sign-in/sign-in-provider.d.ts +6 -0
  131. package/lib/node/sign-in/sign-in-provider.js +15 -0
  132. package/lib/node/sources-extension.d.ts +11 -0
  133. package/lib/node/sources-extension.js +22 -0
  134. package/lib/node/ta-server-impl.js +2 -2
  135. package/lib/node/ta-session-factory.js +2 -0
  136. package/lib/node/team/team-calls.js +27 -0
  137. package/lib/node/voice-bridge.d.ts +3 -1
  138. package/lib/node/voice-bridge.js +9 -2
  139. package/lib/node/voices-file.d.ts +5 -0
  140. package/lib/node/voices-file.js +14 -3
  141. package/lib/node/working-directory.d.ts +8 -2
  142. package/lib/node/working-directory.js +7 -0
  143. package/package.json +14 -10
@@ -1,4 +1,5 @@
1
- import { TA_SIGN_IN_PATH } from '@celljs/ta-protocol';
1
+ import { TA_DEVICE_SIGN_IN_PATH, TA_SIGN_IN_PATH } from '@celljs/ta-protocol';
2
+ import { DEVICE_POLL_MS, SignInDevicesUtil } from './sign-in-devices.js';
2
3
  import { SignInUtil } from './sign-in-flow.js';
3
4
  /** Ties the browser that comes back from the provider to the one that went: login CSRF. */
4
5
  const STATE_COOKIE = 'ta_sign_in';
@@ -26,6 +27,40 @@ export var SignInPageUtil;
26
27
  return `/#${params.toString()}`;
27
28
  }
28
29
  SignInPageUtil.back = back;
30
+ /**
31
+ * The page of the web client for the device of `code` (TA_DEVICE_SIGN_IN_PATH): where the user lets it in, and after
32
+ * the provider how it went (`done`: it gets its token; `waiting`: once the account is let in; `failed`).
33
+ */
34
+ function deviceBack(code, outcome, from) {
35
+ return `/#${new URLSearchParams({ device: code, ...(outcome ? { 'device-sign-in': outcome } : {}), ...(from ? { from } : {}) }).toString()}`;
36
+ }
37
+ SignInPageUtil.deviceBack = deviceBack;
38
+ function json(response, status, body) {
39
+ response.statusCode = status;
40
+ response.setHeader('Content-Type', 'application/json');
41
+ response.end(JSON.stringify(body));
42
+ }
43
+ SignInPageUtil.json = json;
44
+ /** A small JSON body; undefined for one too big or not JSON. */
45
+ async function body(request, max = 4096) {
46
+ const chunks = [];
47
+ let size = 0;
48
+ for await (const chunk of request) {
49
+ size += chunk.length;
50
+ if (size > max) {
51
+ return undefined;
52
+ }
53
+ chunks.push(chunk);
54
+ }
55
+ try {
56
+ const value = JSON.parse(Buffer.concat(chunks).toString('utf8') || '{}');
57
+ return value && typeof value === 'object' && !Array.isArray(value) ? value : undefined;
58
+ }
59
+ catch (_a) {
60
+ return undefined;
61
+ }
62
+ }
63
+ SignInPageUtil.body = body;
29
64
  function redirect(response, location) {
30
65
  response.statusCode = 302;
31
66
  response.setHeader('Location', location);
@@ -52,10 +87,14 @@ export var SignInPages;
52
87
  }
53
88
  SignInPages.matches = matches;
54
89
  async function handle(request, response, flow, options) {
55
- var _a, _b;
90
+ var _a, _b, _c, _d;
56
91
  const url = new URL((_a = request.url) !== null && _a !== void 0 ? _a : '/', 'http://localhost');
57
92
  response.setHeader('Cache-Control', 'no-store');
58
93
  response.setHeader('Referrer-Policy', 'no-referrer');
94
+ if (url.pathname === TA_DEVICE_SIGN_IN_PATH || url.pathname.startsWith(`${TA_DEVICE_SIGN_IN_PATH}/`)) {
95
+ await device(request, response, flow, url, options);
96
+ return;
97
+ }
59
98
  if (request.method !== 'GET' && request.method !== 'HEAD') {
60
99
  response.setHeader('Allow', 'GET, HEAD');
61
100
  SignInPageUtil.end(response, 405);
@@ -63,33 +102,56 @@ export var SignInPages;
63
102
  }
64
103
  const [providerId, step, ...rest] = url.pathname.slice(TA_SIGN_IN_PATH.length + 1).split('/');
65
104
  if (!providerId) {
66
- const ways = { providers: flow.providers.map(({ id, name }) => ({ id, name })) };
105
+ const ways = {
106
+ providers: [
107
+ ...flow.providers.map(({ id, name }) => ({ id, name })),
108
+ ...flow.polled.map(({ id, name }) => ({ id, name, polled: true })),
109
+ ],
110
+ };
67
111
  response.setHeader('Content-Type', 'application/json');
112
+ // Which ways there are is no secret: the app and Ta Desktop, of another origin, offer them on their sign-in.
113
+ response.setHeader('Access-Control-Allow-Origin', '*');
68
114
  SignInPageUtil.end(response, 200, JSON.stringify(ways));
69
115
  return;
70
116
  }
117
+ const polled = flow.polled.some(one => one.id === providerId);
118
+ if (polled && !step && rest.length === 0) {
119
+ await goPolled(response, flow, providerId, (_b = url.searchParams.get('device')) !== null && _b !== void 0 ? _b : '', options);
120
+ return;
121
+ }
71
122
  if (!flow.provider(providerId) || rest.length > 0 || (step && step !== 'callback')) {
72
123
  SignInPageUtil.end(response, 404);
73
124
  return;
74
125
  }
75
126
  if (!step) {
76
- await go(request, response, flow, providerId, (_b = url.searchParams.get('bind')) !== null && _b !== void 0 ? _b : undefined, options);
127
+ 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);
77
128
  return;
78
129
  }
79
130
  await back(request, response, flow, providerId, url.searchParams, options);
80
131
  }
81
132
  SignInPages.handle = handle;
82
- async function go(request, response, flow, providerId, bind, options) {
133
+ async function go(request, response, flow, providerId, bind, options, device) {
83
134
  const origin = SignInUtil.origin(request, flow.publicUrl);
84
135
  try {
85
- const { url, state } = await flow.start(providerId, origin, bind);
136
+ const { url, state } = await flow.start(providerId, origin, bind, Date.now(), device === undefined ? undefined : SignInDevicesUtil.normalize(device));
86
137
  const secure = origin.startsWith('https:') ? '; Secure' : '';
87
138
  response.setHeader('Set-Cookie', `${STATE_COOKIE}=${state}; Path=${TA_SIGN_IN_PATH}; Max-Age=600; HttpOnly; SameSite=Lax${secure}`);
88
139
  SignInPageUtil.redirect(response, url);
89
140
  }
90
141
  catch (error) {
91
142
  console.warn(`${options.name}: signing in with ${providerId} failed: ${error instanceof Error ? error.message : error}`);
92
- SignInPageUtil.redirect(response, SignInPageUtil.back({ outcome: 'failed' }));
143
+ SignInPageUtil.redirect(response, device === undefined ? SignInPageUtil.back({ outcome: 'failed' }) : SignInPageUtil.deviceBack(SignInDevicesUtil.normalize(device), 'failed'));
144
+ }
145
+ }
146
+ /** To a polled provider for the device of `code`; Ta asks it who agreed. Only for a device: a browser does not come back. */
147
+ async function goPolled(response, flow, providerId, given, options) {
148
+ const code = SignInDevicesUtil.normalize(given);
149
+ try {
150
+ SignInPageUtil.redirect(response, await flow.startPolled(providerId, code));
151
+ }
152
+ catch (error) {
153
+ console.warn(`${options.name}: signing in with ${providerId} failed: ${error instanceof Error ? error.message : error}`);
154
+ SignInPageUtil.redirect(response, SignInPageUtil.deviceBack(code, 'failed'));
93
155
  }
94
156
  }
95
157
  async function back(request, response, flow, providerId, params, options) {
@@ -105,7 +167,11 @@ export var SignInPages;
105
167
  }
106
168
  try {
107
169
  const result = await flow.finish(providerId, state, code, request.headers['user-agent']);
108
- if ('token' in result) {
170
+ if ('device' in result) {
171
+ console.log(`${options.name}: ${result.account.id} signed in for a device${result.allowed ? '' : ', which waits for the account to be let in'}`);
172
+ SignInPageUtil.redirect(response, SignInPageUtil.deviceBack(result.device, result.allowed ? 'done' : 'waiting'));
173
+ }
174
+ else if ('token' in result) {
109
175
  console.log(`${options.name}: ${result.account.id} signed in`);
110
176
  await ((_a = options.onSignedIn) === null || _a === void 0 ? void 0 : _a.call(options, response, result.token, result.account, SignInUtil.origin(request, flow.publicUrl)));
111
177
  SignInPageUtil.redirect(response, SignInPageUtil.back({ token: result.token }));
@@ -121,4 +187,67 @@ export var SignInPages;
121
187
  }
122
188
  }
123
189
  })(SignInPages || (SignInPages = {}));
190
+ /** Answers any origin: what these give goes to who holds the secret of the device, and no cookie is read. */
191
+ const DEVICE_CORS = {
192
+ 'Access-Control-Allow-Origin': '*',
193
+ 'Access-Control-Allow-Methods': 'POST, OPTIONS',
194
+ 'Access-Control-Allow-Headers': 'Content-Type',
195
+ 'Access-Control-Max-Age': '600',
196
+ };
197
+ /**
198
+ * TA_DEVICE_SIGN_IN_PATH: `POST` asks for a code, `POST /poll` takes the token once the user let the device in, from any
199
+ * origin; `GET ?code=` is where the user goes, the page of the web client; `POST /approve`, with the token of a browser
200
+ * signed in here, lets the device in as its account, with no provider (a sign-in by `ta gateway link` has none).
201
+ */
202
+ async function device(request, response, flow, url, options) {
203
+ var _a;
204
+ const step = url.pathname.slice(TA_DEVICE_SIGN_IN_PATH.length);
205
+ if (step !== '/approve') {
206
+ for (const [name, value] of Object.entries(DEVICE_CORS)) {
207
+ response.setHeader(name, value);
208
+ }
209
+ }
210
+ if (request.method === 'OPTIONS') {
211
+ SignInPageUtil.end(response, 204);
212
+ return;
213
+ }
214
+ if (step === '' && request.method === 'GET') {
215
+ const code = SignInDevicesUtil.normalize((_a = url.searchParams.get('code')) !== null && _a !== void 0 ? _a : '');
216
+ SignInPageUtil.redirect(response, SignInPageUtil.deviceBack(code, undefined, flow.devices.name(code)));
217
+ return;
218
+ }
219
+ if (request.method !== 'POST' || !['', '/poll', '/approve'].includes(step)) {
220
+ SignInPageUtil.end(response, step === '' || step === '/poll' || step === '/approve' ? 405 : 404);
221
+ return;
222
+ }
223
+ const body = await SignInPageUtil.body(request);
224
+ if (!body) {
225
+ SignInPageUtil.end(response, 400);
226
+ return;
227
+ }
228
+ if (step === '') {
229
+ const started = flow.devices.start(typeof body.name === 'string' ? body.name : undefined);
230
+ const origin = SignInUtil.origin(request, flow.publicUrl);
231
+ const answer = { ...started, url: `${origin}${TA_DEVICE_SIGN_IN_PATH}?code=${started.code}`, interval: DEVICE_POLL_MS };
232
+ SignInPageUtil.json(response, 200, answer);
233
+ return;
234
+ }
235
+ if (step === '/poll') {
236
+ const state = flow.devices.poll(typeof body.device === 'string' ? body.device : '');
237
+ if (state.status === 'done') {
238
+ console.log(`${options.name}: ${state.account} signed in on a device`);
239
+ }
240
+ SignInPageUtil.json(response, 200, state);
241
+ return;
242
+ }
243
+ const header = request.headers.authorization;
244
+ const signIn = (header === null || header === void 0 ? void 0 : header.startsWith('Bearer ')) ? flow.store.check(header.slice('Bearer '.length)) : undefined;
245
+ if (!signIn) {
246
+ SignInPageUtil.end(response, 401);
247
+ return;
248
+ }
249
+ const code = typeof body.code === 'string' ? body.code : '';
250
+ const ok = flow.devices.signedIn(code, { id: signIn.account, name: signIn.name, avatar: signIn.avatar });
251
+ SignInPageUtil.json(response, ok ? 200 : 404, { ok });
252
+ }
124
253
  //# 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.js';
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,3 +1,4 @@
1
+ import { PushedSignIn } from './polled-sign-in.js';
1
2
  /** A sign-in that failed with the provider (a code refused, an account without what it needs). */
2
3
  export class SignInError extends Error {
3
4
  }
@@ -382,6 +383,20 @@ export var SignInProviders;
382
383
  return new GitHubDeviceSignIn(clientId || GitHubDeviceSignIn.CLIENT_ID, GitHubSignIn.endpoints(url || undefined));
383
384
  }
384
385
  SignInProviders.device = device;
386
+ /**
387
+ * The polled providers of the environment (PushedSignIn): `TA_IAM_ISSUER` and `TA_IAM_CLIENT_ID`, a company's sign-in
388
+ * for CLIs, whose accounts are `iam:<sub>`; `TA_IAM_CLI_ID` and `TA_IAM_NAME` (what its button says) optional.
389
+ */
390
+ function polled(env) {
391
+ var _a, _b, _c, _d;
392
+ const issuer = (_a = env.TA_IAM_ISSUER) === null || _a === void 0 ? void 0 : _a.trim();
393
+ const clientId = (_b = env.TA_IAM_CLIENT_ID) === null || _b === void 0 ? void 0 : _b.trim();
394
+ if (!issuer || !clientId) {
395
+ return [];
396
+ }
397
+ return [new 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 })];
398
+ }
399
+ SignInProviders.polled = polled;
385
400
  /**
386
401
  * The providers the operator configured in the environment of ta serve: a provider is offered when it
387
402
  * has its id and its secret.
@@ -0,0 +1,10 @@
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
+ }
@@ -0,0 +1,18 @@
1
+ import { TaMessageSource } from '@celljs/ta-protocol';
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 class SourcesExtension {
8
+ constructor() {
9
+ this.name = 'ta-sources';
10
+ }
11
+ register(pi) {
12
+ pi.on('before_agent_start', event => {
13
+ const options = event.systemPromptOptions;
14
+ options.sections = { ...options.sections, [TaMessageSource.SECTION]: TaMessageSource.PROMPT };
15
+ });
16
+ }
17
+ }
18
+ //# sourceMappingURL=sources-extension.js.map
@@ -15,11 +15,10 @@ import { Rpc } from '@celljs/rpc';
15
15
  import { RpcContext } from '@celljs/rpc/lib/node';
16
16
  import { ExecEnvironmentFactory } from '@celljs/ta-exec';
17
17
  import { TaServeRestart } from '@celljs/ta-harness/lib/node/serve-restart';
18
- import { TA_OWNER, TaMessageAuthor, TaServer, } from '@celljs/ta-protocol';
18
+ import { TA_OWNER, TaMessageAuthor, TaSaid, TaServer, } from '@celljs/ta-protocol';
19
19
  import { TaDirectoryRelocator } from './directory-relocator.js';
20
20
  import { TaSessionCatalog, TaSessionFactory, TaSessionRegistry } from './host-protocol.js';
21
21
  import { TaServeUpdates } from './serve-updates.js';
22
- import { SessionInfoUtil } from './session-info-util.js';
23
22
  import { SlashCommandUtil } from './slash-command-util.js';
24
23
  import { TaErrors } from './ta-errors.js';
25
24
  import { TaAuthority, TaPrincipals, TaRunActors, TaVisibility } from './team/team-protocol.js';
@@ -302,7 +301,8 @@ let TaServerImpl = class TaServerImpl {
302
301
  if (!entry || (position === 'before' && !user)) {
303
302
  throw TaErrors.invalidArgument(`No entry to fork from has the id ${entryId}.`, 'Pass the id of a message of the user, or position "at".');
304
303
  }
305
- const text = position === 'before' && user ? SessionInfoUtil.text(user.content) : undefined;
304
+ // What the user typed, to edit again: the marks of the model are made again when it is sent.
305
+ const text = position === 'before' && user ? TaSaid.of(user) : undefined;
306
306
  const leafId = position === 'before' ? entry.parentId : entry.id;
307
307
  const file = manager.getSessionFile();
308
308
  if (!leafId || !file || !existsSync(file)) {
@@ -24,6 +24,7 @@ import { PiDirectories } from './remote/remote-protocol.js';
24
24
  import { SessionCatalogUtil } from './session-catalog.js';
25
25
  import { ExecSessionFiles } from './session-files.js';
26
26
  import { SlashCommandUtil } from './slash-command-util.js';
27
+ import { SourcesExtension } from './sources-extension.js';
27
28
  import { TaErrors } from './ta-errors.js';
28
29
  import { TaSession } from './ta-session.js';
29
30
  import { TaWorkingDirectory } from './working-directory.js';
@@ -212,6 +213,7 @@ let DefaultTaSessionFactory = class DefaultTaSessionFactory {
212
213
  new PackageHostExtension(this.packageHosts, new ExecSessionFiles(environment, piCwd)),
213
214
  new BrandExtension(sdk),
214
215
  new DelegateExtension(),
216
+ new SourcesExtension(),
215
217
  ...(environment.local ? [] : [new ExecExtension(environment, sdk, piCwd)]),
216
218
  ];
217
219
  return [
@@ -213,6 +213,12 @@ const RULES = {
213
213
  'friendLink',
214
214
  'addFriend',
215
215
  'offerFriend',
216
+ 'inviteFriends',
217
+ 'listGroupInvites',
218
+ 'answerGroupInvite',
219
+ 'sendToFriends',
220
+ 'listFriendShares',
221
+ 'answerFriendShare',
216
222
  'listFriendRequests',
217
223
  'answerFriend',
218
224
  'removeFriend',
@@ -227,6 +233,7 @@ const RULES = {
227
233
  updateVoice: fixed('settings.manage'),
228
234
  removeVoice: fixed('settings.manage'),
229
235
  chooseVoice: fixed('settings.manage'),
236
+ setBargeIn: fixed('settings.manage'),
230
237
  openVoice: fixed('models.use'),
231
238
  sendVoice: fixed('models.use'),
232
239
  sayVoice: fixed('models.use'),
@@ -285,6 +292,26 @@ const RULES = {
285
292
  answer: fixed('hosts.use'),
286
293
  disconnect: fixed('hosts.use'),
287
294
  },
295
+ // Remote desktops: seeing and working a screen is all the owner can do, and in the first stage only the owner does it
296
+ // (docs/design/ta-desktop-remote.md 6.2); no role or grant gives it.
297
+ TaScreenShareServer: {
298
+ listDesktops: owner,
299
+ listDesktopScreens: owner,
300
+ addDesktop: owner,
301
+ removeDesktop: owner,
302
+ openDesktop: owner,
303
+ closeDesktop: owner,
304
+ readDesktopFrames: owner,
305
+ setDesktopView: owner,
306
+ sendDesktopInput: owner,
307
+ pasteToDesktop: owner,
308
+ readDesktopClipboard: owner,
309
+ takeDesktopControl: owner,
310
+ releaseDesktopControl: owner,
311
+ endAllDesktops: owner,
312
+ watchDesktops: owner,
313
+ answerDesktop: owner,
314
+ },
288
315
  };
289
316
  /** By name, own keys only: a method such as `toString` is no rule. */
290
317
  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.js';
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>;
@@ -15,7 +15,7 @@ import { Autowired, Component, Value } from '@celljs/core';
15
15
  import { Rpc } from '@celljs/rpc';
16
16
  import { RpcContext } from '@celljs/rpc/lib/node';
17
17
  import { TaBrand } from '@celljs/ta-harness/lib/node/ta-brand';
18
- import { TaClient, TaVoiceServer, } from '@celljs/ta-protocol';
18
+ import { TaBargeIn, TaClient, TaVoiceServer, } from '@celljs/ta-protocol';
19
19
  import { TaErrors } from './ta-errors.js';
20
20
  import { VoicesFile } from './voices-file.js';
21
21
  export const VOICE_BRIDGE = Symbol('VoiceBridge');
@@ -75,7 +75,7 @@ let VoiceBridge = VoiceBridge_1 = class VoiceBridge {
75
75
  speaks,
76
76
  }));
77
77
  const use = config.use && services.some(service => service.id === config.use) ? { use: config.use } : {};
78
- return { services, types, file: this.file.file, ...use };
78
+ return { services, types, file: this.file.file, bargeIn: TaBargeIn.resolve(config.bargeIn), ...use };
79
79
  }
80
80
  /** Opens a service of the type once before it is kept, so that a wrong key is said now. */
81
81
  async add(type, options, name) {
@@ -130,6 +130,9 @@ let VoiceBridge = VoiceBridge_1 = class VoiceBridge {
130
130
  choose(id) {
131
131
  this.file.use(id !== null && id !== void 0 ? id : undefined);
132
132
  }
133
+ setBargeIn(bargeIn) {
134
+ this.file.setBargeIn(TaBargeIn.pick(bargeIn));
135
+ }
133
136
  async openFor(connection, language) {
134
137
  var _a;
135
138
  const service = this.file.inUse();
@@ -169,7 +172,8 @@ let VoiceBridge = VoiceBridge_1 = class VoiceBridge {
169
172
  const voice = { id, connection, engine, speaks: definition.speaks && !!engine.say, nextSay: 0, closed: false };
170
173
  this.open.set(id, voice);
171
174
  connection.onClose(() => this.close(connection, id));
172
- return { voiceId: id, inputRate: engine.inputRate, outputRate: engine.outputRate, speaks: voice.speaks };
175
+ const bargeIn = TaBargeIn.resolve(this.file.safeRead().config.bargeIn);
176
+ return { voiceId: id, inputRate: engine.inputRate, outputRate: engine.outputRate, speaks: voice.speaks, bargeIn };
173
177
  }
174
178
  send(connection, id, audio) {
175
179
  if (typeof audio !== 'string' || audio.length > MAX_AUDIO) {
@@ -246,6 +250,9 @@ let TaVoiceServerImpl = class TaVoiceServerImpl {
246
250
  chooseVoice(id) {
247
251
  return TaErrors.guard(() => this.bridge.choose(id !== null && id !== void 0 ? id : null));
248
252
  }
253
+ setBargeIn(bargeIn) {
254
+ return TaErrors.guard(() => this.bridge.setBargeIn(bargeIn !== null && bargeIn !== void 0 ? bargeIn : {}));
255
+ }
249
256
  openVoice(options) {
250
257
  return TaErrors.guard(() => this.bridge.openFor(RpcContext.requireConnection(), options === null || options === void 0 ? void 0 : options.language));
251
258
  }
@@ -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;
@@ -17,7 +17,11 @@ export class VoicesFile {
17
17
  const services = Array.isArray(config === null || config === void 0 ? void 0 : config.services)
18
18
  ? config.services.filter(service => service && typeof service.id === 'string' && typeof service.type === 'string' && typeof service.options === 'object')
19
19
  : [];
20
- return { services, ...(typeof (config === null || config === void 0 ? void 0 : config.use) === 'string' ? { use: config.use } : {}) };
20
+ return {
21
+ services,
22
+ ...(typeof (config === null || config === void 0 ? void 0 : config.use) === 'string' ? { use: config.use } : {}),
23
+ ...((config === null || config === void 0 ? void 0 : config.bargeIn) && typeof config.bargeIn === 'object' ? { bargeIn: config.bargeIn } : {}),
24
+ };
21
25
  }
22
26
  /** What reads, or nothing with why it does not parse. */
23
27
  safeRead() {
@@ -64,11 +68,17 @@ export class VoicesFile {
64
68
  services[at] = { ...kept, ...(name ? { name } : {}), options };
65
69
  this.write({ ...config, services });
66
70
  }
71
+ /** Sets keys of bargeIn, the others kept. */
72
+ setBargeIn(bargeIn) {
73
+ const config = this.read();
74
+ this.write({ ...config, bargeIn: { ...config.bargeIn, ...bargeIn } });
75
+ }
67
76
  remove(id) {
68
77
  var _a;
69
78
  const config = this.read();
70
79
  const services = ((_a = config.services) !== null && _a !== void 0 ? _a : []).filter(service => service.id !== id);
71
- this.write({ services, ...(config.use && config.use !== id ? { use: config.use } : {}) });
80
+ const { use, ...rest } = config;
81
+ this.write({ ...rest, services, ...(use && use !== id ? { use } : {}) });
72
82
  }
73
83
  use(id) {
74
84
  var _a, _b;
@@ -76,7 +86,8 @@ export class VoicesFile {
76
86
  if (id !== undefined && !((_a = config.services) !== null && _a !== void 0 ? _a : []).some(service => service.id === id)) {
77
87
  throw new Error(`There is no voice service ${id} in voices.json.`);
78
88
  }
79
- this.write({ services: (_b = config.services) !== null && _b !== void 0 ? _b : [], ...(id ? { use: id } : {}) });
89
+ const { use: _, ...rest } = config;
90
+ this.write({ ...rest, services: (_b = config.services) !== null && _b !== void 0 ? _b : [], ...(id ? { use: id } : {}) });
80
91
  }
81
92
  write(config) {
82
93
  mkdirSync(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
  }
@@ -40,6 +40,13 @@ let TaWorkingDirectoryImpl = class TaWorkingDirectoryImpl {
40
40
  this.write({ remoteHosts: hosts.filter(other => other !== host) });
41
41
  }
42
42
  }
43
+ desktops() {
44
+ const { desktops } = this.read();
45
+ return Array.isArray(desktops) ? desktops : [];
46
+ }
47
+ setDesktops(desktops) {
48
+ this.write({ desktops });
49
+ }
43
50
  write(changes) {
44
51
  writeFileSync(`${this.file}.tmp`, `${JSON.stringify({ ...this.read(), ...changes }, null, 2)}\n`);
45
52
  renameSync(`${this.file}.tmp`, this.file);
@@ -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. */