@celljs/ta-gateway 4.15.1 → 4.16.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/esm/node/command-sandbox.d.ts +6 -2
- package/esm/node/command-sandbox.js +26 -4
- package/esm/node/docker-engine.d.ts +50 -0
- package/esm/node/docker-engine.js +98 -11
- package/esm/node/docker-sandbox.d.ts +6 -1
- package/esm/node/docker-sandbox.js +23 -3
- package/esm/node/environments.d.ts +36 -2
- package/esm/node/environments.js +192 -14
- package/esm/node/gateway-audit.d.ts +12 -0
- package/esm/node/gateway-audit.js +47 -0
- package/esm/node/gateway-cli.d.ts +2 -0
- package/esm/node/gateway-cli.js +1 -0
- package/esm/node/gateway-exec.d.ts +19 -0
- package/esm/node/gateway-exec.js +65 -0
- package/esm/node/gateway-policy.d.ts +47 -0
- package/esm/node/gateway-policy.js +152 -0
- package/esm/node/gateway-quotas.d.ts +40 -0
- package/esm/node/gateway-quotas.js +135 -0
- package/esm/node/gateway-server.d.ts +28 -2
- package/esm/node/gateway-server.js +112 -9
- package/esm/node/gateway-service.d.ts +99 -16
- package/esm/node/gateway-service.js +385 -45
- package/esm/node/gateway-socket.d.ts +7 -1
- package/esm/node/gateway-socket.js +40 -1
- package/esm/node/gateway-usage.d.ts +37 -0
- package/esm/node/gateway-usage.js +137 -0
- package/esm/node/local-sandbox.d.ts +13 -0
- package/esm/node/local-sandbox.js +38 -2
- package/esm/node/model-proxy.d.ts +105 -0
- package/esm/node/model-proxy.js +435 -0
- package/esm/node/sandbox-provider.d.ts +17 -0
- package/esm/node/tenant-store.d.ts +19 -1
- package/esm/node/tenant-store.js +10 -0
- package/lib/node/command-sandbox.d.ts +6 -2
- package/lib/node/command-sandbox.js +26 -4
- package/lib/node/docker-engine.d.ts +50 -0
- package/lib/node/docker-engine.js +98 -11
- package/lib/node/docker-sandbox.d.ts +6 -1
- package/lib/node/docker-sandbox.js +23 -3
- package/lib/node/environments.d.ts +36 -2
- package/lib/node/environments.js +191 -13
- package/lib/node/gateway-audit.d.ts +13 -0
- package/lib/node/gateway-audit.js +51 -0
- package/lib/node/gateway-cli.d.ts +2 -0
- package/lib/node/gateway-cli.js +1 -0
- package/lib/node/gateway-exec.d.ts +20 -0
- package/lib/node/gateway-exec.js +69 -0
- package/lib/node/gateway-policy.d.ts +48 -0
- package/lib/node/gateway-policy.js +157 -0
- package/lib/node/gateway-quotas.d.ts +41 -0
- package/lib/node/gateway-quotas.js +139 -0
- package/lib/node/gateway-server.d.ts +28 -2
- package/lib/node/gateway-server.js +112 -9
- package/lib/node/gateway-service.d.ts +99 -16
- package/lib/node/gateway-service.js +384 -44
- package/lib/node/gateway-socket.d.ts +7 -1
- package/lib/node/gateway-socket.js +40 -1
- package/lib/node/gateway-usage.d.ts +38 -0
- package/lib/node/gateway-usage.js +141 -0
- package/lib/node/local-sandbox.d.ts +13 -0
- package/lib/node/local-sandbox.js +40 -3
- package/lib/node/model-proxy.d.ts +106 -0
- package/lib/node/model-proxy.js +440 -0
- package/lib/node/sandbox-provider.d.ts +17 -0
- package/lib/node/tenant-store.d.ts +19 -1
- package/lib/node/tenant-store.js +10 -0
- package/package.json +4 -4
|
@@ -15,13 +15,21 @@ const ta_protocol_1 = require("@celljs/ta-protocol");
|
|
|
15
15
|
const command_sandbox_1 = require("./command-sandbox");
|
|
16
16
|
const docker_sandbox_1 = require("./docker-sandbox");
|
|
17
17
|
const environments_1 = require("./environments");
|
|
18
|
+
const gateway_audit_1 = require("./gateway-audit");
|
|
19
|
+
const gateway_exec_1 = require("./gateway-exec");
|
|
20
|
+
const gateway_policy_1 = require("./gateway-policy");
|
|
21
|
+
const gateway_quotas_1 = require("./gateway-quotas");
|
|
18
22
|
const gateway_service_1 = require("./gateway-service");
|
|
19
23
|
const gateway_socket_1 = require("./gateway-socket");
|
|
24
|
+
const gateway_usage_1 = require("./gateway-usage");
|
|
20
25
|
const local_sandbox_1 = require("./local-sandbox");
|
|
26
|
+
const model_proxy_1 = require("./model-proxy");
|
|
21
27
|
const sandbox_provider_1 = require("./sandbox-provider");
|
|
22
28
|
const sign_in_links_1 = require("./sign-in-links");
|
|
23
29
|
const ta_sandbox_1 = require("./ta-sandbox");
|
|
24
30
|
const tenant_store_1 = require("./tenant-store");
|
|
31
|
+
/** How often the minutes of running sandboxes are counted, and those out of them stopped. */
|
|
32
|
+
const TICK_MS = 30000;
|
|
25
33
|
/** The browser's token for `/api/files`, which pages load by URL, without the token of the WebSocket. */
|
|
26
34
|
const FILES_COOKIE = 'ta_gateway';
|
|
27
35
|
const TYPES = {
|
|
@@ -47,6 +55,34 @@ exports.SANDBOX_TYPES = {
|
|
|
47
55
|
};
|
|
48
56
|
var GatewayServerUtil;
|
|
49
57
|
(function (GatewayServerUtil) {
|
|
58
|
+
/**
|
|
59
|
+
* Where a sandbox reaches the gateway, by the type of its provider: a container the host (host.docker.internal,
|
|
60
|
+
* mapped on Linux too), a process of this machine 127.0.0.1, another the public address.
|
|
61
|
+
*/
|
|
62
|
+
function reach(type, port, publicUrl) {
|
|
63
|
+
if (type === 'docker') {
|
|
64
|
+
return `http://host.docker.internal:${port}`;
|
|
65
|
+
}
|
|
66
|
+
if (type === 'local' || !publicUrl) {
|
|
67
|
+
return `http://127.0.0.1:${port}`;
|
|
68
|
+
}
|
|
69
|
+
return publicUrl;
|
|
70
|
+
}
|
|
71
|
+
GatewayServerUtil.reach = reach;
|
|
72
|
+
/** Where another Ta reaches the exec server of its account's sandbox. */
|
|
73
|
+
GatewayServerUtil.EXEC_PATH = '/api/exec';
|
|
74
|
+
/** What a page is told when its Ta does not start for its account's limits; TaGatewayInfo.quota says it in the page's words. */
|
|
75
|
+
function blockedReason(block) {
|
|
76
|
+
switch (block) {
|
|
77
|
+
case 'suspended':
|
|
78
|
+
return 'Your account is suspended by an administrator of the gateway.';
|
|
79
|
+
case 'minutes':
|
|
80
|
+
return 'Your free minutes of this month are used up.';
|
|
81
|
+
default:
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
GatewayServerUtil.blockedReason = blockedReason;
|
|
50
86
|
/** A file of `root` for a path of the page, never outside it; the page for what is not a file. */
|
|
51
87
|
function file(root, urlPath) {
|
|
52
88
|
let path;
|
|
@@ -92,19 +128,21 @@ var GatewayServerUtil;
|
|
|
92
128
|
*/
|
|
93
129
|
class GatewayServer {
|
|
94
130
|
static async create(options) {
|
|
131
|
+
const models = model_proxy_1.ModelProxyUtil.read(options.dir);
|
|
95
132
|
(0, node_fs_1.mkdirSync)(options.dir, { recursive: true, mode: 0o700 });
|
|
96
133
|
const config = sandbox_provider_1.SandboxProviders.read(options.dir);
|
|
97
134
|
const context = { dir: options.dir, taCommand: options.taCommand };
|
|
98
135
|
const providers = await sandbox_provider_1.SandboxProviders.create(config, context, exports.SANDBOX_TYPES);
|
|
99
|
-
return new GatewayServer(options, providers, config);
|
|
136
|
+
return new GatewayServer(options, providers, config, models);
|
|
100
137
|
}
|
|
101
|
-
constructor(options, providers, config) {
|
|
138
|
+
constructor(options, providers, config, models = {}) {
|
|
102
139
|
var _a, _b;
|
|
103
140
|
this.options = options;
|
|
104
141
|
this.sockets = new Set();
|
|
105
142
|
const env = (_a = options.env) !== null && _a !== void 0 ? _a : process.env;
|
|
106
|
-
|
|
107
|
-
|
|
143
|
+
const owners = access_store_1.AccessUtil.parseList(env.TA_GATEWAY_ADMINS);
|
|
144
|
+
this.policy = new gateway_policy_1.GatewayPolicy(options.dir, owners);
|
|
145
|
+
const allowed = [...access_store_1.AccessUtil.parseList(env.TA_ALLOWED_USERS), ...owners];
|
|
108
146
|
this.flow = new sign_in_flow_1.SignInFlow(sign_in_provider_1.SignInProviders.fromEnv(env), new access_store_1.AccessStore((0, node_path_1.join)(options.dir, 'access.json'), allowed), sign_in_provider_1.SignInProviders.publicUrl(env));
|
|
109
147
|
this.tenants = new tenant_store_1.TenantStore(options.dir);
|
|
110
148
|
this.links = new sign_in_links_1.SignInLinks(options.dir);
|
|
@@ -113,25 +151,70 @@ class GatewayServer {
|
|
|
113
151
|
own: config.ownEnvironments !== false,
|
|
114
152
|
idleMinutes: (_b = config.idleMinutes) !== null && _b !== void 0 ? _b : 0,
|
|
115
153
|
});
|
|
116
|
-
this.
|
|
154
|
+
this.usage = new gateway_usage_1.GatewayUsage(options.dir);
|
|
155
|
+
this.audit = new gateway_audit_1.GatewayAudit(options.dir);
|
|
156
|
+
this.quotas = new gateway_quotas_1.GatewayQuotas(this.policy, this.tenants, this.usage, () => this.environments.settings.own, () => this.models.enabled);
|
|
157
|
+
this.environments.guard = tenant => GatewayServerUtil.blockedReason(this.quotas.blocked(tenant));
|
|
158
|
+
this.models = new model_proxy_1.ModelProxy(models, {
|
|
159
|
+
tenantOfKey: key => this.tenants.list().find(tenant => tenant.modelKey && model_proxy_1.ModelProxyUtil.sameKey(key, tenant.modelKey)),
|
|
160
|
+
refuse: id => {
|
|
161
|
+
const tenant = this.tenants.get(id);
|
|
162
|
+
return tenant ? this.quotas.refuseModels(tenant) : 'No such account.';
|
|
163
|
+
},
|
|
164
|
+
record: (id, usage, cost) => this.quotas.addTokens(id, model_proxy_1.ModelProxyUtil.total(usage), cost),
|
|
165
|
+
}, env);
|
|
166
|
+
this.environments.envOf = (tenant, provider) => {
|
|
167
|
+
var _a, _b, _c;
|
|
168
|
+
if (!this.models.enabled) {
|
|
169
|
+
return undefined;
|
|
170
|
+
}
|
|
171
|
+
const url = (_a = provider.gatewayUrl) !== null && _a !== void 0 ? _a : GatewayServerUtil.reach(provider.type, (_c = (_b = this.port) !== null && _b !== void 0 ? _b : options.port) !== null && _c !== void 0 ? _c : 4100, sandbox_provider_1.SandboxProviders.publicBase(env));
|
|
172
|
+
return { TA_MODEL_PROXY_URL: url.replace(/\/+$/, ''), TA_MODEL_PROXY_KEY: this.tenants.modelKey(tenant.id) };
|
|
173
|
+
};
|
|
174
|
+
this.service = new gateway_service_1.GatewayService({
|
|
175
|
+
flow: this.flow,
|
|
176
|
+
tenants: this.tenants,
|
|
177
|
+
environments: this.environments,
|
|
178
|
+
policy: this.policy,
|
|
179
|
+
quotas: this.quotas,
|
|
180
|
+
usage: this.usage,
|
|
181
|
+
audit: this.audit,
|
|
182
|
+
hooks: { cutOff: () => this.cutOff(), reset: id => this.reset(id) },
|
|
183
|
+
models: this.models,
|
|
184
|
+
meta: { links: this.links, startedAt: Date.now(), version: options.version, publicUrl: sandbox_provider_1.SandboxProviders.publicBase(env) },
|
|
185
|
+
});
|
|
117
186
|
}
|
|
118
187
|
isAdmin(account) {
|
|
119
|
-
return this.
|
|
188
|
+
return this.policy.role(account) !== 'member';
|
|
189
|
+
}
|
|
190
|
+
/** The minutes of the sandboxes that ran since the last time; those out of them, or suspended, stop. */
|
|
191
|
+
async tick(now = Date.now()) {
|
|
192
|
+
for (const tenant of this.quotas.tick(this.environments.runningIds(), now)) {
|
|
193
|
+
console.log(`ta gateway: ${tenant.account} used its free minutes of the month: its sandbox stops`);
|
|
194
|
+
await this.environments.stop(tenant.id).catch(() => undefined);
|
|
195
|
+
this.reset(tenant.id);
|
|
196
|
+
}
|
|
120
197
|
}
|
|
121
198
|
listen() {
|
|
199
|
+
var _a, _b;
|
|
122
200
|
const server = (0, node_http_1.createServer)((request, response) => void this.handle(request, response));
|
|
123
201
|
server.on('upgrade', (request, socket, head) => this.upgrade(request, socket, head));
|
|
124
202
|
this.server = server;
|
|
203
|
+
this.ticker = setInterval(() => void this.tick().catch(error => console.warn(`ta gateway: counting minutes failed: ${error.message}`)), TICK_MS);
|
|
204
|
+
(_b = (_a = this.ticker).unref) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
125
205
|
return new Promise((resolve, reject) => {
|
|
126
206
|
var _a, _b;
|
|
127
207
|
server.once('error', reject);
|
|
128
208
|
server.listen((_a = this.options.port) !== null && _a !== void 0 ? _a : 4100, (_b = this.options.host) !== null && _b !== void 0 ? _b : '127.0.0.1', () => {
|
|
129
209
|
const { address, port } = server.address();
|
|
210
|
+
this.port = port;
|
|
130
211
|
resolve(`http://${address.includes(':') ? `[${address}]` : address}:${port}`);
|
|
131
212
|
});
|
|
132
213
|
});
|
|
133
214
|
}
|
|
134
215
|
async close() {
|
|
216
|
+
clearInterval(this.ticker);
|
|
217
|
+
await this.tick().catch(() => undefined);
|
|
135
218
|
for (const socket of this.sockets) {
|
|
136
219
|
socket.close(1001, 'The gateway is stopping.');
|
|
137
220
|
}
|
|
@@ -165,7 +248,8 @@ class GatewayServer {
|
|
|
165
248
|
return undefined;
|
|
166
249
|
}
|
|
167
250
|
const tenant = this.tenants.ensure({ id: signIn.account, name: signIn.name, avatar: signIn.avatar });
|
|
168
|
-
|
|
251
|
+
const role = this.policy.role(signIn.account);
|
|
252
|
+
return { token, account: signIn.account, tenant, role, admin: role !== 'member' };
|
|
169
253
|
}
|
|
170
254
|
async handle(request, response) {
|
|
171
255
|
var _a;
|
|
@@ -180,6 +264,9 @@ class GatewayServer {
|
|
|
180
264
|
onSignedIn: (res, token, account, origin) => this.signedIn(res, token, account, origin),
|
|
181
265
|
});
|
|
182
266
|
}
|
|
267
|
+
else if (path === model_proxy_1.ModelProxyUtil.PATH || path.startsWith(`${model_proxy_1.ModelProxyUtil.PATH}/`)) {
|
|
268
|
+
await this.models.handle(request, response);
|
|
269
|
+
}
|
|
183
270
|
else if (path.startsWith(`${ta_protocol_1.TA_FILES_PATH}/`)) {
|
|
184
271
|
await this.files(request, response);
|
|
185
272
|
}
|
|
@@ -293,7 +380,7 @@ class GatewayServer {
|
|
|
293
380
|
upgrade(request, socket, head) {
|
|
294
381
|
var _a, _b;
|
|
295
382
|
const url = new URL((_a = request.url) !== null && _a !== void 0 ? _a : '/', 'http://gateway');
|
|
296
|
-
if (url.pathname !== ta_protocol_1.TA_WEBSOCKET_PATH) {
|
|
383
|
+
if (url.pathname !== ta_protocol_1.TA_WEBSOCKET_PATH && url.pathname !== GatewayServerUtil.EXEC_PATH) {
|
|
297
384
|
socket.destroy();
|
|
298
385
|
return;
|
|
299
386
|
}
|
|
@@ -309,9 +396,25 @@ class GatewayServer {
|
|
|
309
396
|
websocket_connection_1.WebSocketConnection.refuse(socket, 401, 'Not authorized.');
|
|
310
397
|
return;
|
|
311
398
|
}
|
|
399
|
+
const most = this.quotas.limits(caller.tenant).connections;
|
|
400
|
+
if (most !== undefined && this.environments.connections(caller.tenant.id) >= most) {
|
|
401
|
+
websocket_connection_1.WebSocketConnection.refuse(socket, 429, `At most ${most} pages of your account connect at once.`);
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
312
404
|
this.tenants.update(caller.tenant.id, { lastActiveAt: Date.now() });
|
|
405
|
+
if (url.pathname === GatewayServerUtil.EXEC_PATH) {
|
|
406
|
+
// Another Ta works in this account's sandbox: it counts as a page connected, and keeps the sandbox running.
|
|
407
|
+
const blocked = GatewayServerUtil.blockedReason(this.quotas.blocked(caller.tenant));
|
|
408
|
+
if (blocked) {
|
|
409
|
+
websocket_connection_1.WebSocketConnection.refuse(socket, 403, blocked);
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
const exec = websocket_connection_1.WebSocketConnection.open(socket, checked.key, head, { maxPayload: 64 * 1024 * 1024, heartbeat: 30000 });
|
|
413
|
+
new gateway_exec_1.GatewayExecProxy(exec, this.environments.ensure(caller.tenant), this.environments.connect(caller.tenant.id));
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
313
416
|
const connection = websocket_connection_1.WebSocketConnection.open(socket, checked.key, head, { maxPayload: 32 * 1024 * 1024, heartbeat: 30000, deflate: checked.deflate });
|
|
314
|
-
const gatewaySocket = new gateway_socket_1.GatewaySocket(connection, caller, this.environments, this.service);
|
|
417
|
+
const gatewaySocket = new gateway_socket_1.GatewaySocket(connection, caller, this.environments, this.service, this.quotas);
|
|
315
418
|
this.sockets.add(gatewaySocket);
|
|
316
419
|
connection.onClose(() => this.sockets.delete(gatewaySocket));
|
|
317
420
|
}
|
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
import type { SignInFlow } from '@celljs/ta-host/lib/node/sign-in/sign-in-flow';
|
|
2
|
-
import { type TaAccessInfo, type TaEnvironmentChoice, TaErrorCode, type TaGatewayInfo, type TaGatewayTenant } from '@celljs/ta-protocol';
|
|
2
|
+
import { type TaAccessInfo, type TaAgentActivity, type TaEnvironmentChoice, TaErrorCode, type TaGatewayConsole, type TaGatewayInfo, type TaGatewayLimits, type TaGatewayPolicy, type TaGatewayRole, type TaGatewayTenant, type TaUsageTrend } from '@celljs/ta-protocol';
|
|
3
3
|
import type { Environments } from './environments';
|
|
4
|
+
import type { GatewayAudit } from './gateway-audit';
|
|
5
|
+
import { type GatewayPolicy } from './gateway-policy';
|
|
6
|
+
import type { GatewayQuotas } from './gateway-quotas';
|
|
7
|
+
import { type GatewayUsage } from './gateway-usage';
|
|
8
|
+
import { type ModelProxy } from './model-proxy';
|
|
9
|
+
import type { SignInLinks } from './sign-in-links';
|
|
4
10
|
import type { Tenant, TenantStore } from './tenant-store';
|
|
5
|
-
/** Who calls: the browser signed in as `account`, with the token `token
|
|
11
|
+
/** Who calls: the browser signed in as `account`, with the token `token`, and what that account is on the gateway. */
|
|
6
12
|
export interface GatewayCaller {
|
|
7
13
|
token: string;
|
|
8
14
|
account: string;
|
|
9
15
|
tenant: Tenant;
|
|
16
|
+
role: TaGatewayRole;
|
|
17
|
+
/** An owner or an admin. */
|
|
10
18
|
admin: boolean;
|
|
11
19
|
}
|
|
12
20
|
export declare class GatewayCallError extends Error {
|
|
@@ -14,46 +22,121 @@ export declare class GatewayCallError extends Error {
|
|
|
14
22
|
readonly hint: string;
|
|
15
23
|
constructor(message: string, code: TaErrorCode, hint: string);
|
|
16
24
|
}
|
|
25
|
+
/** What the console says of the gateway itself. */
|
|
26
|
+
export interface GatewayMeta {
|
|
27
|
+
links: SignInLinks;
|
|
28
|
+
startedAt: number;
|
|
29
|
+
version?: string;
|
|
30
|
+
publicUrl?: string;
|
|
31
|
+
}
|
|
32
|
+
/** The parts of the gateway its calls use. */
|
|
33
|
+
export interface GatewayParts {
|
|
34
|
+
flow: SignInFlow;
|
|
35
|
+
tenants: TenantStore;
|
|
36
|
+
environments: Environments;
|
|
37
|
+
policy: GatewayPolicy;
|
|
38
|
+
quotas: GatewayQuotas;
|
|
39
|
+
usage: GatewayUsage;
|
|
40
|
+
audit: GatewayAudit;
|
|
41
|
+
hooks: {
|
|
42
|
+
cutOff(): void;
|
|
43
|
+
reset(tenantId: string): void;
|
|
44
|
+
};
|
|
45
|
+
meta: GatewayMeta;
|
|
46
|
+
models?: ModelProxy;
|
|
47
|
+
}
|
|
48
|
+
type Need = TaGatewayRole | 'anyone';
|
|
17
49
|
export declare namespace GatewayServiceUtil {
|
|
50
|
+
const DEFAULT_LOG_LINES = 200;
|
|
51
|
+
const MAX_LOG_LINES = 2000;
|
|
52
|
+
/**
|
|
53
|
+
* Who may call each method: `anyone` signed in (about their own Ta, their own sign-ins), `admin` (owners too),
|
|
54
|
+
* `owner`. A method not here is no method. What an admin may do to another account is checked again by its role
|
|
55
|
+
* (GatewayService.manage).
|
|
56
|
+
*/
|
|
57
|
+
const RULES: Record<string, Record<string, Need>>;
|
|
58
|
+
/** What an administrator did or looked at of others: kept in the audit. */
|
|
59
|
+
const AUDITED: Set<string>;
|
|
60
|
+
function need(service: string, name: string): Need | undefined;
|
|
61
|
+
function allowed(role: TaGatewayRole, need: Need): boolean;
|
|
62
|
+
/** As many lines as asked, within bounds. */
|
|
63
|
+
function lines(value: unknown): number;
|
|
64
|
+
/** Days of a trend, 1 to 31. */
|
|
65
|
+
function days(value: unknown): number;
|
|
18
66
|
/** The services the gateway answers itself, not the Ta of the tenant. */
|
|
19
67
|
const SERVICES: string[];
|
|
20
68
|
function owns(method: unknown): method is string;
|
|
21
69
|
/** Whether the text of a message may be a call of {@link SERVICES}: those that are not are not parsed. */
|
|
22
70
|
function mayOwn(text: string): boolean;
|
|
71
|
+
/** The calls that send the agents a message, which the limit of messages a minute counts. */
|
|
72
|
+
const PROMPTS: string[];
|
|
73
|
+
function mayPrompt(text: string): boolean;
|
|
23
74
|
/** The error of a JSON-RPC answer, as ta serve sends an ApplicationError: the client reads its code and hint. */
|
|
24
75
|
function error(id: unknown, message: string, code: TaErrorCode, hint: string): string;
|
|
25
76
|
function result(id: unknown, result: unknown): string;
|
|
77
|
+
function forbidden(message: string, hint: string): GatewayCallError;
|
|
26
78
|
function choice(value: unknown, own: boolean, providers: string[]): TaEnvironmentChoice | undefined;
|
|
79
|
+
/** What the audit says of the arguments of a call: its numbers, flags and roles, never more. */
|
|
80
|
+
function detail(method: string, params: unknown[]): string | undefined;
|
|
27
81
|
}
|
|
28
82
|
/**
|
|
29
83
|
* The calls the gateway answers on the WebSocket of a browser: TaGatewayServer, and TaAccessServer, whose
|
|
30
|
-
* accounts are those that may have a tenant here
|
|
31
|
-
*
|
|
84
|
+
* accounts are those that may have a tenant here. Each method needs a role (GatewayServiceUtil.RULES); what an
|
|
85
|
+
* admin does to another account needs a role above it; what administrators do is kept in the audit.
|
|
32
86
|
*/
|
|
33
87
|
export declare class GatewayService {
|
|
34
88
|
protected readonly flow: SignInFlow;
|
|
35
89
|
protected readonly tenants: TenantStore;
|
|
36
90
|
protected readonly environments: Environments;
|
|
37
|
-
protected readonly
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
91
|
+
protected readonly policy: GatewayPolicy;
|
|
92
|
+
protected readonly quotas: GatewayQuotas;
|
|
93
|
+
protected readonly usage: GatewayUsage;
|
|
94
|
+
protected readonly audit: GatewayAudit;
|
|
95
|
+
protected readonly hooks: GatewayParts['hooks'];
|
|
96
|
+
protected readonly meta: GatewayMeta;
|
|
97
|
+
protected readonly models?: ModelProxy;
|
|
98
|
+
constructor(parts: GatewayParts);
|
|
45
99
|
call(caller: GatewayCaller, method: string, params: unknown[]): Promise<unknown>;
|
|
100
|
+
protected handle(caller: GatewayCaller, service: string, name: string, params: unknown[]): Promise<unknown>;
|
|
101
|
+
protected record(caller: GatewayCaller, action: string, params: unknown[]): void;
|
|
46
102
|
info(caller: GatewayCaller): TaGatewayInfo;
|
|
47
|
-
protected ownAllowed(): boolean;
|
|
48
103
|
protected setEnvironment(caller: GatewayCaller, value: unknown): Promise<TaGatewayInfo>;
|
|
49
104
|
protected restart(caller: GatewayCaller): Promise<TaGatewayInfo>;
|
|
50
|
-
protected
|
|
105
|
+
protected tenantInfo(tenant: Tenant): TaGatewayTenant;
|
|
106
|
+
/** The tenants with what their sandboxes take and their agents do, read together: a slow one holds the console a second, not a second each. */
|
|
107
|
+
protected console(caller: GatewayCaller): Promise<TaGatewayConsole>;
|
|
108
|
+
protected policyView(): TaGatewayPolicy;
|
|
109
|
+
protected tenant(id: unknown): Tenant;
|
|
110
|
+
/** A tenant the caller may change: an owner any; an admin a member's only, not their own, nor another admin's or an owner's. */
|
|
111
|
+
protected manage(caller: GatewayCaller, id: unknown): Tenant;
|
|
112
|
+
protected startTenant(caller: GatewayCaller, id: unknown): Promise<void>;
|
|
51
113
|
protected stopTenant(caller: GatewayCaller, id: unknown): Promise<void>;
|
|
114
|
+
protected restartTenant(caller: GatewayCaller, id: unknown): Promise<void>;
|
|
115
|
+
/** What its sandbox wrote, its secrets hidden: tokens and keys printed by what ran there do not reach the page. */
|
|
116
|
+
protected logs(id: unknown, lines: unknown): Promise<string>;
|
|
117
|
+
protected activity(id: unknown, sessionId: unknown): Promise<TaAgentActivity[]>;
|
|
118
|
+
protected trend(daysValue: unknown, id: unknown): Promise<TaUsageTrend>;
|
|
119
|
+
protected limits(value: unknown, nullable: boolean): TaGatewayLimits;
|
|
120
|
+
protected setTenantLimits(caller: GatewayCaller, id: unknown, value: unknown): void;
|
|
121
|
+
protected grantMinutes(caller: GatewayCaller, id: unknown, minutes: unknown): void;
|
|
122
|
+
protected setSuspended(caller: GatewayCaller, id: unknown, suspended: unknown): Promise<void>;
|
|
123
|
+
protected setDefaultLimits(value: unknown): TaGatewayPolicy;
|
|
124
|
+
protected setRole(caller: GatewayCaller, account: unknown, role: unknown): TaGatewayPolicy;
|
|
125
|
+
/** A sign-in of the caller's own account, named for where it is used. */
|
|
126
|
+
protected accessToken(caller: GatewayCaller, label: unknown): {
|
|
127
|
+
token: string;
|
|
128
|
+
url?: string;
|
|
129
|
+
};
|
|
52
130
|
protected access(caller: GatewayCaller): TaAccessInfo;
|
|
53
131
|
protected allow(account: unknown, name: unknown): void;
|
|
54
132
|
/** The browsers of the account are cut off, and what reaches its Ta otherwise (paired phones) goes with its sandbox. */
|
|
55
|
-
protected disallow(account: string): Promise<void>;
|
|
133
|
+
protected disallow(caller: GatewayCaller, account: string): Promise<void>;
|
|
56
134
|
protected signOut(caller: GatewayCaller, id: string): Promise<void>;
|
|
57
|
-
|
|
135
|
+
/**
|
|
136
|
+
* A link that signs in once as an account that has never been here: one that has a tenant, or is an owner's or an
|
|
137
|
+
* admin's, would let whoever makes the link into another's Ta. `ta gateway link`, where the gateway runs, may.
|
|
138
|
+
*/
|
|
139
|
+
protected signInLink(account: unknown, name: unknown): string;
|
|
58
140
|
}
|
|
141
|
+
export {};
|
|
59
142
|
//# sourceMappingURL=gateway-service.d.ts.map
|