@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
@@ -1,11 +1,14 @@
1
1
  import { createHash, randomBytes } from 'node:crypto';
2
2
  import { TA_SIGN_IN_PATH } from '@celljs/ta-protocol';
3
+ import { SignInDevices } from './sign-in-devices.js';
3
4
  import { SignInError } from './sign-in-provider.js';
4
5
  /** How long the browser has with the provider, and a link of {@link SignInFlow.bindUrl}. */
5
6
  const PENDING_TTL_MS = 10 * 60 * 1000;
6
7
  const BIND_TTL_MS = 5 * 60 * 1000;
7
8
  /** Sign-ins under way at most: anyone may start one without a token, and each is kept until it ends or expires. */
8
9
  export const MAX_PENDING_SIGN_INS = 1000;
10
+ /** How often a polled provider is asked whether the user agreed. */
11
+ export const POLL_MS = 2000;
9
12
  export var SignInUtil;
10
13
  (function (SignInUtil) {
11
14
  /**
@@ -39,12 +42,75 @@ export var SignInUtil;
39
42
  * gateway (`ta gateway`) use it alike.
40
43
  */
41
44
  export class SignInFlow {
42
- constructor(providers, store, publicUrl) {
45
+ constructor(providers, store, publicUrl,
46
+ /** Those the browser signs in at without coming back (PolledSignInProvider): for devices, whose code they sign in for. */
47
+ polled = []) {
43
48
  this.providers = providers;
44
49
  this.store = store;
45
50
  this.publicUrl = publicUrl;
51
+ this.polled = polled;
52
+ /** What Ta asks each polled provider for, by the code of the device it is for: one at a time for a code. */
53
+ this.polling = new Map();
54
+ this.pollMs = POLL_MS;
46
55
  this.pending = new Map();
47
56
  this.binds = new Map();
57
+ this.devices = new SignInDevices(store);
58
+ }
59
+ /**
60
+ * Signs in with a polled provider for the device of `code`: where the browser goes; Ta asks the provider until it says
61
+ * who agreed, and lets the device in as them (SignInDevices.signedIn), or until it is too late or the code taken.
62
+ */
63
+ async startPolled(providerId, code, now = Date.now()) {
64
+ const provider = this.polled.find(one => one.id === providerId);
65
+ if (!provider) {
66
+ throw new SignInError(`No provider ${providerId}`);
67
+ }
68
+ if (!this.devices.open(code, now)) {
69
+ throw new SignInError('The code of the device expired or is not known here');
70
+ }
71
+ if (!this.polling.has(code) && this.polling.size >= MAX_PENDING_SIGN_INS) {
72
+ throw new SignInError('Too many sign-ins under way');
73
+ }
74
+ const signIn = await provider.begin();
75
+ const previous = this.polling.get(code);
76
+ if (previous) {
77
+ previous.stopped = true;
78
+ }
79
+ const run = { stopped: false };
80
+ this.polling.set(code, run);
81
+ void this.pollUntil(provider, signIn, code, run, now + signIn.expiresIn * 1000);
82
+ return signIn.url;
83
+ }
84
+ async pollUntil(provider, signIn, code, run, deadline) {
85
+ try {
86
+ while (!run.stopped && Date.now() < deadline && this.devices.open(code)) {
87
+ await new Promise(resolve => setTimeout(resolve, this.pollMs));
88
+ if (run.stopped) {
89
+ return;
90
+ }
91
+ const answer = await signIn.poll().catch(error => (error instanceof SignInError ? error : 'pending'));
92
+ if (answer instanceof SignInError) {
93
+ console.warn(`signing in with ${provider.id} failed: ${answer.message}`);
94
+ return;
95
+ }
96
+ if (answer !== 'pending') {
97
+ this.devices.signedIn(code, answer);
98
+ return;
99
+ }
100
+ }
101
+ }
102
+ finally {
103
+ if (this.polling.get(code) === run) {
104
+ this.polling.delete(code);
105
+ }
106
+ }
107
+ }
108
+ /** Stops what is asked of polled providers: the server closes. */
109
+ stopPolling() {
110
+ for (const run of this.polling.values()) {
111
+ run.stopped = true;
112
+ }
113
+ this.polling.clear();
48
114
  }
49
115
  provider(id) {
50
116
  return this.providers.find(provider => provider.id === id);
@@ -55,14 +121,17 @@ export class SignInFlow {
55
121
  this.binds.set(nonce, { provider, at: now });
56
122
  return `${TA_SIGN_IN_PATH}/${provider}?bind=${nonce}`;
57
123
  }
58
- /** Where the browser goes, and the state that comes back with it. */
59
- async start(providerId, origin, bind, now = Date.now()) {
124
+ /** Where the browser goes, and the state that comes back with it; with `device`, it signs in for the device of that code. */
125
+ async start(providerId, origin, bind, now = Date.now(), device) {
60
126
  this.prune(now);
61
127
  const binding = bind ? this.binds.get(bind) : undefined;
62
128
  if (bind) {
63
129
  this.binds.delete(bind);
64
130
  }
65
- return this.begin(providerId, SignInUtil.redirectUri(origin, providerId), { bind: (binding === null || binding === void 0 ? void 0 : binding.provider) === providerId }, now);
131
+ if (device !== undefined && !this.devices.open(device, now)) {
132
+ throw new SignInError('The code of the device expired or is not known here');
133
+ }
134
+ return this.begin(providerId, SignInUtil.redirectUri(origin, providerId), { bind: (binding === null || binding === void 0 ? void 0 : binding.provider) === providerId, ...(device !== undefined ? { device } : {}) }, now);
66
135
  }
67
136
  /** A sign-in that only says who it is ({@link verify}), coming back to `redirectUri`: the page of a relay, say. */
68
137
  startVerify(providerId, redirectUri, now = Date.now()) {
@@ -108,6 +177,12 @@ export class SignInFlow {
108
177
  if (pending.bind) {
109
178
  this.store.allow(account.id, account.name, now);
110
179
  }
180
+ if (pending.device !== undefined) {
181
+ if (!this.devices.signedIn(pending.device, account, now)) {
182
+ throw new SignInError('The code of the device expired or was used');
183
+ }
184
+ return { device: pending.device, account, allowed: this.store.allows(account.id) };
185
+ }
111
186
  if (!this.store.allows(account.id)) {
112
187
  this.store.request(account, now);
113
188
  return { denied: account };
@@ -11,6 +11,14 @@ export declare namespace SignInPageUtil {
11
11
  outcome: TaSignInOutcome;
12
12
  account?: string;
13
13
  }): string;
14
+ /**
15
+ * The page of the web client for the device of `code` (TA_DEVICE_SIGN_IN_PATH): where the user lets it in, and after
16
+ * the provider how it went (`done`: it gets its token; `waiting`: once the account is let in; `failed`).
17
+ */
18
+ function deviceBack(code: string, outcome?: 'done' | 'waiting' | 'failed', from?: string): string;
19
+ function json(response: ServerResponse, status: number, body: unknown): void;
20
+ /** A small JSON body; undefined for one too big or not JSON. */
21
+ function body(request: IncomingMessage, max?: number): Promise<Record<string, unknown> | undefined>;
14
22
  function redirect(response: ServerResponse, location: string): void;
15
23
  function end(response: ServerResponse, status: number, body?: string): void;
16
24
  }
@@ -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 [
@@ -172,6 +172,14 @@ const RULES = {
172
172
  closeTerminal: fixed('commands.terminal'),
173
173
  listTerminals: fixed('commands.terminal'),
174
174
  },
175
+ TaAccountServer: {
176
+ getAccount: fixed('settings.view'),
177
+ signIn: fixed('settings.manage'),
178
+ cancelSignIn: fixed('settings.manage'),
179
+ approve: fixed('settings.manage'),
180
+ remove: fixed('settings.manage'),
181
+ signOut: fixed('settings.manage'),
182
+ },
175
183
  TaRelayServer: {
176
184
  getRelay: fixed('settings.view'),
177
185
  pair: fixed('settings.manage'),
@@ -213,6 +221,12 @@ const RULES = {
213
221
  'friendLink',
214
222
  'addFriend',
215
223
  'offerFriend',
224
+ 'inviteFriends',
225
+ 'listGroupInvites',
226
+ 'answerGroupInvite',
227
+ 'sendToFriends',
228
+ 'listFriendShares',
229
+ 'answerFriendShare',
216
230
  'listFriendRequests',
217
231
  'answerFriend',
218
232
  'removeFriend',
@@ -227,6 +241,7 @@ const RULES = {
227
241
  updateVoice: fixed('settings.manage'),
228
242
  removeVoice: fixed('settings.manage'),
229
243
  chooseVoice: fixed('settings.manage'),
244
+ setBargeIn: fixed('settings.manage'),
230
245
  openVoice: fixed('models.use'),
231
246
  sendVoice: fixed('models.use'),
232
247
  sayVoice: fixed('models.use'),
@@ -285,6 +300,26 @@ const RULES = {
285
300
  answer: fixed('hosts.use'),
286
301
  disconnect: fixed('hosts.use'),
287
302
  },
303
+ // Remote desktops: seeing and working a screen is all the owner can do, and in the first stage only the owner does it
304
+ // (docs/design/ta-desktop-remote.md 6.2); no role or grant gives it.
305
+ TaScreenShareServer: {
306
+ listDesktops: owner,
307
+ listDesktopScreens: owner,
308
+ addDesktop: owner,
309
+ removeDesktop: owner,
310
+ openDesktop: owner,
311
+ closeDesktop: owner,
312
+ readDesktopFrames: owner,
313
+ setDesktopView: owner,
314
+ sendDesktopInput: owner,
315
+ pasteToDesktop: owner,
316
+ readDesktopClipboard: owner,
317
+ takeDesktopControl: owner,
318
+ releaseDesktopControl: owner,
319
+ endAllDesktops: owner,
320
+ watchDesktops: owner,
321
+ answerDesktop: owner,
322
+ },
288
323
  };
289
324
  /** By name, own keys only: a method such as `toString` is no rule. */
290
325
  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;