@celljs/ta-host 4.14.0 → 4.15.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.
- package/README.en.md +2 -1
- package/README.md +2 -1
- package/esm/node/auth-server-impl.d.ts +12 -2
- package/esm/node/auth-server-impl.js +102 -3
- package/esm/node/custom-providers.d.ts +50 -0
- package/esm/node/custom-providers.js +335 -0
- package/esm/node/sign-in/sign-in-provider.d.ts +44 -0
- package/esm/node/sign-in/sign-in-provider.js +74 -7
- package/esm/node/sign-in/ta-sign-in.d.ts +4 -1
- package/esm/node/sign-in/ta-sign-in.js +6 -2
- package/esm/node/team/host-team.js +1 -0
- package/esm/node/team/member-accounts.d.ts +25 -8
- package/esm/node/team/member-accounts.js +84 -4
- package/esm/node/team/team-calls.js +4 -0
- package/esm/node/web-extension-util.js +1 -0
- package/lib/node/auth-server-impl.d.ts +12 -2
- package/lib/node/auth-server-impl.js +101 -2
- package/lib/node/custom-providers.d.ts +51 -0
- package/lib/node/custom-providers.js +338 -0
- package/lib/node/sign-in/sign-in-provider.d.ts +44 -0
- package/lib/node/sign-in/sign-in-provider.js +77 -9
- package/lib/node/sign-in/ta-sign-in.d.ts +4 -1
- package/lib/node/sign-in/ta-sign-in.js +6 -2
- package/lib/node/team/host-team.js +1 -0
- package/lib/node/team/member-accounts.d.ts +25 -8
- package/lib/node/team/member-accounts.js +84 -4
- package/lib/node/team/team-calls.js +4 -0
- package/lib/node/web-extension-util.js +1 -0
- package/package.json +10 -10
|
@@ -10,22 +10,102 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.DefaultTaMemberAccounts = void 0;
|
|
13
|
+
const node_crypto_1 = require("node:crypto");
|
|
13
14
|
const core_1 = require("@celljs/core");
|
|
15
|
+
const sign_in_provider_1 = require("../sign-in/sign-in-provider");
|
|
14
16
|
const ta_sign_in_1 = require("../sign-in/ta-sign-in");
|
|
15
17
|
const team_protocol_1 = require("./team-protocol");
|
|
16
|
-
/**
|
|
18
|
+
/** Sign-ins by a code under way at once: anyone holding a link may start one. */
|
|
19
|
+
const MAX_TYPING = 200;
|
|
20
|
+
const WAIT_MS = 25000;
|
|
21
|
+
/**
|
|
22
|
+
* Who one asking to come in is, by an account of the providers ta serve signs in with (TaSignIn), or by a code typed at
|
|
23
|
+
* GitHub with Ta's own app when GitHub is not set up (TaSignIn.device): nothing let in by it.
|
|
24
|
+
*/
|
|
17
25
|
let DefaultTaMemberAccounts = class DefaultTaMemberAccounts {
|
|
26
|
+
constructor() {
|
|
27
|
+
this.typing = new Map();
|
|
28
|
+
}
|
|
18
29
|
providers() {
|
|
19
|
-
|
|
30
|
+
const own = this.flow.providers.map(({ id, name }) => ({ id, name }));
|
|
31
|
+
const device = this.device();
|
|
32
|
+
return device ? [...own, { id: device.id, name: device.name, device: true }] : own;
|
|
20
33
|
}
|
|
21
|
-
start(provider, redirectUri) {
|
|
34
|
+
async start(provider, redirectUri) {
|
|
35
|
+
const device = this.device();
|
|
36
|
+
if ((device === null || device === void 0 ? void 0 : device.id) === provider) {
|
|
37
|
+
return this.startTyping(device);
|
|
38
|
+
}
|
|
22
39
|
if (!/^https?:\/\/[^/?#]+\/[^?#]*$/.test(redirectUri)) {
|
|
23
40
|
throw new Error(`Not an address to come back to: ${redirectUri}`);
|
|
24
41
|
}
|
|
25
42
|
return this.flow.startVerify(provider, redirectUri);
|
|
26
43
|
}
|
|
27
44
|
async verify(state, code) {
|
|
28
|
-
|
|
45
|
+
return this.of(await this.flow.verify(state, code));
|
|
46
|
+
}
|
|
47
|
+
async typed(state, waitMs = WAIT_MS) {
|
|
48
|
+
const typing = this.typing.get(state);
|
|
49
|
+
if (!typing) {
|
|
50
|
+
throw new sign_in_provider_1.SignInError('The sign-in expired or was not started here');
|
|
51
|
+
}
|
|
52
|
+
const until = Date.now() + Math.min(Math.max(0, waitMs), WAIT_MS);
|
|
53
|
+
// Asked no more often than the provider says; one waiting already asks for both.
|
|
54
|
+
while (!typing.account) {
|
|
55
|
+
if (Date.now() >= typing.expiresAt) {
|
|
56
|
+
this.typing.delete(state);
|
|
57
|
+
throw new sign_in_provider_1.SignInError('The code ran out: sign in again');
|
|
58
|
+
}
|
|
59
|
+
const sleep = typing.next - Date.now();
|
|
60
|
+
if (Date.now() + Math.max(0, sleep) > until) {
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
if (sleep > 0) {
|
|
64
|
+
await new Promise(resolve => setTimeout(resolve, sleep));
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
typing.next = Date.now() + typing.interval;
|
|
68
|
+
let answer;
|
|
69
|
+
try {
|
|
70
|
+
answer = await typing.provider.poll(typing.deviceCode);
|
|
71
|
+
}
|
|
72
|
+
catch (failure) {
|
|
73
|
+
// Refused, or the code is no good: over. The network failing is not, and is asked again.
|
|
74
|
+
if (failure instanceof sign_in_provider_1.SignInError) {
|
|
75
|
+
this.typing.delete(state);
|
|
76
|
+
}
|
|
77
|
+
throw failure;
|
|
78
|
+
}
|
|
79
|
+
if (answer === 'slowDown') {
|
|
80
|
+
typing.interval += 5000;
|
|
81
|
+
typing.next = Date.now() + typing.interval;
|
|
82
|
+
}
|
|
83
|
+
else if (answer !== 'pending') {
|
|
84
|
+
typing.account = this.of(answer);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return typing.account;
|
|
88
|
+
}
|
|
89
|
+
/** GitHub by a code, when ta serve has no GitHub of its own. */
|
|
90
|
+
device() {
|
|
91
|
+
const device = this.flow.device;
|
|
92
|
+
return device && !this.flow.providers.some(one => one.id === device.id) ? device : undefined;
|
|
93
|
+
}
|
|
94
|
+
async startTyping(device) {
|
|
95
|
+
const now = Date.now();
|
|
96
|
+
for (const [state, typing] of this.typing) {
|
|
97
|
+
if (now >= typing.expiresAt || this.typing.size >= MAX_TYPING) {
|
|
98
|
+
this.typing.delete(state);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const code = await device.code();
|
|
102
|
+
const state = (0, node_crypto_1.randomBytes)(18).toString('base64url');
|
|
103
|
+
const interval = Math.max(0, code.interval) * 1000;
|
|
104
|
+
const expiresAt = now + code.expiresIn * 1000;
|
|
105
|
+
this.typing.set(state, { provider: device, deviceCode: code.deviceCode, interval, next: now + interval, expiresAt });
|
|
106
|
+
return { state, device: { code: code.userCode, uri: code.uri, expiresAt } };
|
|
107
|
+
}
|
|
108
|
+
of({ id, name, avatar }) {
|
|
29
109
|
return { id, ...(name ? { name } : {}), ...(avatar ? { avatar } : {}) };
|
|
30
110
|
}
|
|
31
111
|
};
|
|
@@ -233,6 +233,10 @@ const RULES = {
|
|
|
233
233
|
answer: fixed('models.manage'),
|
|
234
234
|
cancel: fixed('models.manage'),
|
|
235
235
|
logout: fixed('models.manage'),
|
|
236
|
+
listCustomProviders: fixed('models.manage'),
|
|
237
|
+
saveCustomProvider: fixed('models.manage'),
|
|
238
|
+
removeCustomProvider: fixed('models.manage'),
|
|
239
|
+
fetchCustomModels: fixed('models.manage'),
|
|
236
240
|
},
|
|
237
241
|
TaAccessServer: {
|
|
238
242
|
getSignInConfig: owner,
|
|
@@ -25,6 +25,7 @@ var WebExtensionUtil;
|
|
|
25
25
|
origin: pkg.origin,
|
|
26
26
|
enabled: (_e = pkg.enabled) !== null && _e !== void 0 ? _e : true,
|
|
27
27
|
source: pkg.source,
|
|
28
|
+
root: pkg.root,
|
|
28
29
|
entry,
|
|
29
30
|
hash: hash((0, node_fs_1.readFileSync)((0, node_path_1.join)(pkg.root, entry), 'utf8')),
|
|
30
31
|
title: text((_a = manifest === null || manifest === void 0 ? void 0 : manifest.pi) === null || _a === void 0 ? void 0 : _a.title),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celljs/ta-host",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.15.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.
|
|
38
|
-
"@celljs/ai-coding-agent": "4.
|
|
39
|
-
"@celljs/core": "4.
|
|
40
|
-
"@celljs/rpc": "4.
|
|
41
|
-
"@celljs/ta-exec": "4.
|
|
42
|
-
"@celljs/ta-harness": "4.
|
|
43
|
-
"@celljs/ta-protocol": "4.
|
|
44
|
-
"@celljs/ta-relay": "4.
|
|
45
|
-
"@celljs/web": "4.
|
|
37
|
+
"@celljs/ai-agent": "4.15.0",
|
|
38
|
+
"@celljs/ai-coding-agent": "4.15.0",
|
|
39
|
+
"@celljs/core": "4.15.0",
|
|
40
|
+
"@celljs/rpc": "4.15.0",
|
|
41
|
+
"@celljs/ta-exec": "4.15.0",
|
|
42
|
+
"@celljs/ta-harness": "4.15.0",
|
|
43
|
+
"@celljs/ta-protocol": "4.15.0",
|
|
44
|
+
"@celljs/ta-relay": "4.15.0",
|
|
45
|
+
"@celljs/web": "4.15.0",
|
|
46
46
|
"@earendil-works/pi-coding-agent": "^1.5.2"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|