@celljs/ta-host 4.12.0 → 4.13.1
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 +3 -2
- package/README.md +3 -2
- package/esm/node/extension-data-notifier.d.ts +3 -0
- package/esm/node/extension-data-notifier.js +8 -2
- package/esm/node/extension-providers.js +1 -1
- package/esm/node/host-protocol.d.ts +20 -1
- package/esm/node/host-protocol.js +1 -0
- package/esm/node/index.d.ts +3 -0
- package/esm/node/index.js +3 -0
- package/esm/node/keep-awake.d.ts +44 -0
- package/esm/node/keep-awake.js +112 -0
- package/esm/node/package-host-extension.js +2 -0
- package/esm/node/package-hosts.d.ts +23 -1
- package/esm/node/package-hosts.js +61 -3
- package/esm/node/relay-bridge.d.ts +37 -3
- package/esm/node/relay-bridge.js +271 -10
- package/esm/node/rooms-bridge.d.ts +13 -2
- package/esm/node/rooms-bridge.js +34 -4
- package/esm/node/session-catalog.d.ts +1 -1
- package/esm/node/session-catalog.js +5 -0
- package/esm/node/session-list-feed.d.ts +11 -1
- package/esm/node/session-list-feed.js +17 -3
- package/esm/node/session-resume.d.ts +52 -0
- package/esm/node/session-resume.js +174 -0
- package/esm/node/settings-store.d.ts +3 -0
- package/esm/node/settings-store.js +22 -0
- package/esm/node/ta-errors.d.ts +1 -0
- package/esm/node/ta-errors.js +4 -0
- package/esm/node/ta-server-impl.d.ts +9 -0
- package/esm/node/ta-server-impl.js +52 -7
- package/esm/node/ta-session-factory.js +5 -2
- package/esm/node/ta-session-registry.d.ts +12 -1
- package/esm/node/ta-session-registry.js +30 -1
- package/esm/node/ta-session.d.ts +3 -0
- package/esm/node/ta-session.js +16 -0
- package/esm/node/team/authority.d.ts +19 -0
- package/esm/node/team/authority.js +79 -0
- package/esm/node/team/call-util.d.ts +23 -0
- package/esm/node/team/call-util.js +88 -0
- package/esm/node/team/connections.d.ts +15 -0
- package/esm/node/team/connections.js +81 -0
- package/esm/node/team/host-team.d.ts +13 -0
- package/esm/node/team/host-team.js +69 -0
- package/esm/node/team/index.d.ts +13 -0
- package/esm/node/team/index.js +14 -0
- package/esm/node/team/member-devices.d.ts +11 -0
- package/esm/node/team/member-devices.js +56 -0
- package/esm/node/team/package-permissions.d.ts +23 -0
- package/esm/node/team/package-permissions.js +75 -0
- package/esm/node/team/principals.d.ts +22 -0
- package/esm/node/team/principals.js +72 -0
- package/esm/node/team/run-actors.d.ts +21 -0
- package/esm/node/team/run-actors.js +100 -0
- package/esm/node/team/shared-data.d.ts +18 -0
- package/esm/node/team/shared-data.js +55 -0
- package/esm/node/team/team-calls.d.ts +33 -0
- package/esm/node/team/team-calls.js +266 -0
- package/esm/node/team/team-gate.d.ts +31 -0
- package/esm/node/team/team-gate.js +177 -0
- package/esm/node/team/team-protocol.d.ts +89 -0
- package/esm/node/team/team-protocol.js +27 -0
- package/esm/node/team/visibility.d.ts +13 -0
- package/esm/node/team/visibility.js +50 -0
- package/esm/node/terminal-service.d.ts +5 -0
- package/esm/node/terminal-service.js +11 -2
- package/lib/node/extension-data-notifier.d.ts +3 -0
- package/lib/node/extension-data-notifier.js +8 -2
- package/lib/node/extension-providers.js +1 -1
- package/lib/node/host-protocol.d.ts +20 -1
- package/lib/node/host-protocol.js +2 -1
- package/lib/node/index.d.ts +3 -0
- package/lib/node/index.js +3 -0
- package/lib/node/keep-awake.d.ts +45 -0
- package/lib/node/keep-awake.js +115 -0
- package/lib/node/package-host-extension.js +2 -0
- package/lib/node/package-hosts.d.ts +23 -1
- package/lib/node/package-hosts.js +60 -2
- package/lib/node/relay-bridge.d.ts +37 -3
- package/lib/node/relay-bridge.js +269 -8
- package/lib/node/rooms-bridge.d.ts +13 -2
- package/lib/node/rooms-bridge.js +34 -4
- package/lib/node/session-catalog.d.ts +1 -1
- package/lib/node/session-catalog.js +5 -0
- package/lib/node/session-list-feed.d.ts +11 -1
- package/lib/node/session-list-feed.js +17 -3
- package/lib/node/session-resume.d.ts +53 -0
- package/lib/node/session-resume.js +177 -0
- package/lib/node/settings-store.d.ts +3 -0
- package/lib/node/settings-store.js +22 -0
- package/lib/node/ta-errors.d.ts +1 -0
- package/lib/node/ta-errors.js +4 -0
- package/lib/node/ta-server-impl.d.ts +9 -0
- package/lib/node/ta-server-impl.js +52 -7
- package/lib/node/ta-session-factory.js +4 -1
- package/lib/node/ta-session-registry.d.ts +12 -1
- package/lib/node/ta-session-registry.js +30 -1
- package/lib/node/ta-session.d.ts +3 -0
- package/lib/node/ta-session.js +16 -0
- package/lib/node/team/authority.d.ts +20 -0
- package/lib/node/team/authority.js +82 -0
- package/lib/node/team/call-util.d.ts +24 -0
- package/lib/node/team/call-util.js +91 -0
- package/lib/node/team/connections.d.ts +16 -0
- package/lib/node/team/connections.js +84 -0
- package/lib/node/team/host-team.d.ts +14 -0
- package/lib/node/team/host-team.js +72 -0
- package/lib/node/team/index.d.ts +14 -0
- package/lib/node/team/index.js +30 -0
- package/lib/node/team/member-devices.d.ts +12 -0
- package/lib/node/team/member-devices.js +59 -0
- package/lib/node/team/package-permissions.d.ts +24 -0
- package/lib/node/team/package-permissions.js +78 -0
- package/lib/node/team/principals.d.ts +23 -0
- package/lib/node/team/principals.js +75 -0
- package/lib/node/team/run-actors.d.ts +22 -0
- package/lib/node/team/run-actors.js +103 -0
- package/lib/node/team/shared-data.d.ts +19 -0
- package/lib/node/team/shared-data.js +58 -0
- package/lib/node/team/team-calls.d.ts +34 -0
- package/lib/node/team/team-calls.js +270 -0
- package/lib/node/team/team-gate.d.ts +32 -0
- package/lib/node/team/team-gate.js +180 -0
- package/lib/node/team/team-protocol.d.ts +90 -0
- package/lib/node/team/team-protocol.js +30 -0
- package/lib/node/team/visibility.d.ts +14 -0
- package/lib/node/team/visibility.js +53 -0
- package/lib/node/terminal-service.d.ts +5 -0
- package/lib/node/terminal-service.js +11 -2
- package/package.json +14 -10
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.DefaultTaMemberDevices = void 0;
|
|
13
|
+
const core_1 = require("@celljs/core");
|
|
14
|
+
const ta_protocol_1 = require("@celljs/ta-protocol");
|
|
15
|
+
const node_1 = require("@celljs/ta-relay/lib/node");
|
|
16
|
+
const relay_bridge_1 = require("../relay-bridge");
|
|
17
|
+
const team_protocol_1 = require("./team-protocol");
|
|
18
|
+
/** The devices of those let in, kept with the owner's in relay.json (RelayDevice.member), each reaching ta serve end to end. */
|
|
19
|
+
let DefaultTaMemberDevices = class DefaultTaMemberDevices {
|
|
20
|
+
async pair(principal, name, expiresAt) {
|
|
21
|
+
if (!principal || principal === ta_protocol_1.TA_OWNER) {
|
|
22
|
+
throw new Error('A device of the owner is paired in Settings, not by a package.');
|
|
23
|
+
}
|
|
24
|
+
const relay = this.relay.relayFor('devices');
|
|
25
|
+
const pairing = this.relay.store.pair(relay, name || 'device', { member: principal, ...(expiresAt !== undefined ? { expiresAt } : {}) });
|
|
26
|
+
this.relay.refresh();
|
|
27
|
+
return { ...pairing, link: node_1.RelayPairingUtil.link(pairing) };
|
|
28
|
+
}
|
|
29
|
+
/** Only one of those let in: the owner's own devices are taken out in Settings. */
|
|
30
|
+
unpair(deviceId) {
|
|
31
|
+
var _a;
|
|
32
|
+
if ((_a = this.relay.store.device(deviceId, 0)) === null || _a === void 0 ? void 0 : _a.member) {
|
|
33
|
+
this.relay.store.remove(deviceId);
|
|
34
|
+
this.relay.refresh();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
list() {
|
|
38
|
+
return this.relay.store.read().devices.flatMap((device) => device.member
|
|
39
|
+
? [
|
|
40
|
+
{
|
|
41
|
+
id: device.id,
|
|
42
|
+
name: device.name,
|
|
43
|
+
member: device.member,
|
|
44
|
+
createdAt: device.createdAt,
|
|
45
|
+
...(device.expiresAt ? { expiresAt: device.expiresAt } : {}),
|
|
46
|
+
},
|
|
47
|
+
]
|
|
48
|
+
: []);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
exports.DefaultTaMemberDevices = DefaultTaMemberDevices;
|
|
52
|
+
__decorate([
|
|
53
|
+
(0, core_1.Autowired)({ id: relay_bridge_1.RELAY_BRIDGE, detached: true }),
|
|
54
|
+
__metadata("design:type", Function)
|
|
55
|
+
], DefaultTaMemberDevices.prototype, "relay", void 0);
|
|
56
|
+
exports.DefaultTaMemberDevices = DefaultTaMemberDevices = __decorate([
|
|
57
|
+
(0, core_1.Component)(team_protocol_1.TaMemberDevices)
|
|
58
|
+
], DefaultTaMemberDevices);
|
|
59
|
+
//# sourceMappingURL=member-devices.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type CodingAgentOptions } from '@celljs/ai-coding-agent';
|
|
2
|
+
import { type TaPermissionManifest } from '@celljs/ta-protocol';
|
|
3
|
+
import { TaPackagePermissions } from './team-protocol';
|
|
4
|
+
/**
|
|
5
|
+
* What the built-in packages that are on declare of their hosts and tools (`pi.permissions` of their package.json): the
|
|
6
|
+
* knowledge stays with each package, ta serve only reads it. A package of the user's declares nothing that counts: its
|
|
7
|
+
* host and tools need as much as installing one (TA_UNDECLARED), which only who may install extensions has.
|
|
8
|
+
*/
|
|
9
|
+
export declare class DefaultTaPackagePermissions implements TaPackagePermissions {
|
|
10
|
+
protected readonly codingAgentOptions?: CodingAgentOptions;
|
|
11
|
+
/** By the root of each package: read once, a package that comes with Ta does not change while it runs. */
|
|
12
|
+
protected readonly manifests: Map<string, TaPermissionManifest>;
|
|
13
|
+
/** Which are on, read again at most this often: only calls of those let in ask, and a package turned on is soon known. */
|
|
14
|
+
protected on?: {
|
|
15
|
+
at: number;
|
|
16
|
+
byName: Map<string, TaPermissionManifest>;
|
|
17
|
+
};
|
|
18
|
+
host(name: string, method: string, kind?: string): string;
|
|
19
|
+
tool(name: string): string | undefined;
|
|
20
|
+
/** The manifests of the built-in packages on now, by name. */
|
|
21
|
+
protected all(now?: number): Map<string, TaPermissionManifest>;
|
|
22
|
+
protected read(root: string): TaPermissionManifest;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=package-permissions.d.ts.map
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.DefaultTaPackagePermissions = void 0;
|
|
13
|
+
const node_fs_1 = require("node:fs");
|
|
14
|
+
const node_path_1 = require("node:path");
|
|
15
|
+
const ai_coding_agent_1 = require("@celljs/ai-coding-agent");
|
|
16
|
+
const core_1 = require("@celljs/core");
|
|
17
|
+
const ta_brand_1 = require("@celljs/ta-harness/lib/node/ta-brand");
|
|
18
|
+
const ta_packages_1 = require("@celljs/ta-harness/lib/node/ta-packages");
|
|
19
|
+
const ta_protocol_1 = require("@celljs/ta-protocol");
|
|
20
|
+
const team_protocol_1 = require("./team-protocol");
|
|
21
|
+
const ENABLED_MS = 5000;
|
|
22
|
+
/**
|
|
23
|
+
* What the built-in packages that are on declare of their hosts and tools (`pi.permissions` of their package.json): the
|
|
24
|
+
* knowledge stays with each package, ta serve only reads it. A package of the user's declares nothing that counts: its
|
|
25
|
+
* host and tools need as much as installing one (TA_UNDECLARED), which only who may install extensions has.
|
|
26
|
+
*/
|
|
27
|
+
let DefaultTaPackagePermissions = class DefaultTaPackagePermissions {
|
|
28
|
+
constructor() {
|
|
29
|
+
/** By the root of each package: read once, a package that comes with Ta does not change while it runs. */
|
|
30
|
+
this.manifests = new Map();
|
|
31
|
+
}
|
|
32
|
+
host(name, method, kind) {
|
|
33
|
+
return ta_protocol_1.TaPermissionUtil.host(this.all().get(name), method, kind);
|
|
34
|
+
}
|
|
35
|
+
tool(name) {
|
|
36
|
+
var _a;
|
|
37
|
+
for (const manifest of this.all().values()) {
|
|
38
|
+
// Own names only: `toString` is no tool of a package.
|
|
39
|
+
const declared = new Map(Object.entries((_a = manifest.tools) !== null && _a !== void 0 ? _a : {})).get(name);
|
|
40
|
+
if (declared !== undefined) {
|
|
41
|
+
return declared;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
/** The manifests of the built-in packages on now, by name. */
|
|
47
|
+
all(now = Date.now()) {
|
|
48
|
+
var _a;
|
|
49
|
+
var _b;
|
|
50
|
+
if (!this.on || now - this.on.at > ENABLED_MS) {
|
|
51
|
+
const agentDir = (_b = (_a = this.codingAgentOptions) === null || _a === void 0 ? void 0 : _a.agentDir) !== null && _b !== void 0 ? _b : ta_brand_1.TaBrand.agentDir();
|
|
52
|
+
this.on = { at: now, byName: new Map(ta_packages_1.TaPackages.enabled(agentDir).map(pkg => [pkg.name, this.read(pkg.root)])) };
|
|
53
|
+
}
|
|
54
|
+
return this.on.byName;
|
|
55
|
+
}
|
|
56
|
+
read(root) {
|
|
57
|
+
let manifest = this.manifests.get(root);
|
|
58
|
+
if (!manifest) {
|
|
59
|
+
try {
|
|
60
|
+
manifest = ta_protocol_1.TaPermissionUtil.read(JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.join)(root, 'package.json'), 'utf8')).pi);
|
|
61
|
+
}
|
|
62
|
+
catch (_a) {
|
|
63
|
+
manifest = {};
|
|
64
|
+
}
|
|
65
|
+
this.manifests.set(root, manifest);
|
|
66
|
+
}
|
|
67
|
+
return manifest;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
exports.DefaultTaPackagePermissions = DefaultTaPackagePermissions;
|
|
71
|
+
__decorate([
|
|
72
|
+
(0, core_1.Value)(ai_coding_agent_1.CODING_AGENT_OPTIONS),
|
|
73
|
+
__metadata("design:type", Object)
|
|
74
|
+
], DefaultTaPackagePermissions.prototype, "codingAgentOptions", void 0);
|
|
75
|
+
exports.DefaultTaPackagePermissions = DefaultTaPackagePermissions = __decorate([
|
|
76
|
+
(0, core_1.Component)(team_protocol_1.TaPackagePermissions)
|
|
77
|
+
], DefaultTaPackagePermissions);
|
|
78
|
+
//# sourceMappingURL=package-permissions.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
import type { IncomingMessage } from 'node:http';
|
|
3
|
+
import { type RpcConnection } from '@celljs/rpc/lib/node';
|
|
4
|
+
import { type RelayBridge } from '../relay-bridge';
|
|
5
|
+
import { type TaAccess } from '../ta-access';
|
|
6
|
+
import { TaPrincipals } from './team-protocol';
|
|
7
|
+
/**
|
|
8
|
+
* Who a connection is: the owner for the token of ta serve, a page signed in and the owner's own devices; the principal a
|
|
9
|
+
* device of one let in was paired for (the relay tells which device, RelayHostUtil.localUrl); an unknown device, removed
|
|
10
|
+
* since, is no one and may do nothing. Known once per connection.
|
|
11
|
+
*/
|
|
12
|
+
export declare class DefaultTaPrincipals implements TaPrincipals {
|
|
13
|
+
protected readonly access: TaAccess;
|
|
14
|
+
protected readonly relay: RelayBridge;
|
|
15
|
+
protected readonly known: WeakMap<object, string>;
|
|
16
|
+
protected readonly as: AsyncLocalStorage<string>;
|
|
17
|
+
of(connection: RpcConnection): string;
|
|
18
|
+
current(): string;
|
|
19
|
+
actAs<T>(principal: string, run: () => Promise<T>): Promise<T>;
|
|
20
|
+
acting(): boolean;
|
|
21
|
+
protected ofRequest(request: IncomingMessage): string;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=principals.d.ts.map
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.DefaultTaPrincipals = void 0;
|
|
13
|
+
const node_async_hooks_1 = require("node:async_hooks");
|
|
14
|
+
const core_1 = require("@celljs/core");
|
|
15
|
+
const node_1 = require("@celljs/rpc/lib/node");
|
|
16
|
+
const ta_protocol_1 = require("@celljs/ta-protocol");
|
|
17
|
+
const relay_bridge_1 = require("../relay-bridge");
|
|
18
|
+
const ta_access_1 = require("../ta-access");
|
|
19
|
+
const team_protocol_1 = require("./team-protocol");
|
|
20
|
+
/**
|
|
21
|
+
* Who a connection is: the owner for the token of ta serve, a page signed in and the owner's own devices; the principal a
|
|
22
|
+
* device of one let in was paired for (the relay tells which device, RelayHostUtil.localUrl); an unknown device, removed
|
|
23
|
+
* since, is no one and may do nothing. Known once per connection.
|
|
24
|
+
*/
|
|
25
|
+
let DefaultTaPrincipals = class DefaultTaPrincipals {
|
|
26
|
+
constructor() {
|
|
27
|
+
this.known = new WeakMap();
|
|
28
|
+
this.as = new node_async_hooks_1.AsyncLocalStorage();
|
|
29
|
+
}
|
|
30
|
+
of(connection) {
|
|
31
|
+
let principal = this.known.get(connection);
|
|
32
|
+
if (principal === undefined) {
|
|
33
|
+
principal = this.ofRequest(connection.request);
|
|
34
|
+
this.known.set(connection, principal);
|
|
35
|
+
}
|
|
36
|
+
return principal;
|
|
37
|
+
}
|
|
38
|
+
current() {
|
|
39
|
+
const acted = this.as.getStore();
|
|
40
|
+
if (acted) {
|
|
41
|
+
return acted;
|
|
42
|
+
}
|
|
43
|
+
const connection = node_1.RpcContext.connection();
|
|
44
|
+
return connection ? this.of(connection) : ta_protocol_1.TA_OWNER;
|
|
45
|
+
}
|
|
46
|
+
actAs(principal, run) {
|
|
47
|
+
return this.as.run(principal, run);
|
|
48
|
+
}
|
|
49
|
+
acting() {
|
|
50
|
+
return this.as.getStore() !== undefined;
|
|
51
|
+
}
|
|
52
|
+
ofRequest(request) {
|
|
53
|
+
var _a, _b;
|
|
54
|
+
const deviceId = new URL((_a = request.url) !== null && _a !== void 0 ? _a : '/', 'http://localhost').searchParams.get('device');
|
|
55
|
+
const token = ta_access_1.TaAccessUtil.tokenOf(request);
|
|
56
|
+
if (!deviceId || token === undefined || !ta_access_1.TaAccessUtil.equals(token, this.access.token)) {
|
|
57
|
+
return ta_protocol_1.TA_OWNER;
|
|
58
|
+
}
|
|
59
|
+
const device = this.relay.store.device(deviceId);
|
|
60
|
+
return device ? ((_b = device.member) !== null && _b !== void 0 ? _b : ta_protocol_1.TA_OWNER) : `device:${deviceId}`;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
exports.DefaultTaPrincipals = DefaultTaPrincipals;
|
|
64
|
+
__decorate([
|
|
65
|
+
(0, core_1.Autowired)({ id: ta_access_1.TA_ACCESS, detached: true }),
|
|
66
|
+
__metadata("design:type", Function)
|
|
67
|
+
], DefaultTaPrincipals.prototype, "access", void 0);
|
|
68
|
+
__decorate([
|
|
69
|
+
(0, core_1.Autowired)({ id: relay_bridge_1.RELAY_BRIDGE, detached: true }),
|
|
70
|
+
__metadata("design:type", Function)
|
|
71
|
+
], DefaultTaPrincipals.prototype, "relay", void 0);
|
|
72
|
+
exports.DefaultTaPrincipals = DefaultTaPrincipals = __decorate([
|
|
73
|
+
(0, core_1.Component)(team_protocol_1.TaPrincipals)
|
|
74
|
+
], DefaultTaPrincipals);
|
|
75
|
+
//# sourceMappingURL=principals.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { TaSessionRegistry } from '../host-protocol';
|
|
2
|
+
import { type TaRunActors as RunActors, TaAuthority, TaPrincipals } from './team-protocol';
|
|
3
|
+
/**
|
|
4
|
+
* Who asked the run going on in each session, until it ends (docs/design/ta-team.md 5): the owner is kept too, so that a
|
|
5
|
+
* run the owner asked is told from one nobody's page asked (a package, a scheduled task). A run of those let in starts
|
|
6
|
+
* within the owner's limit of runs at once (TaAuthorizer.mayRun).
|
|
7
|
+
*/
|
|
8
|
+
export declare class DefaultTaRunActors implements RunActors {
|
|
9
|
+
protected readonly principals: TaPrincipals;
|
|
10
|
+
protected readonly authority: TaAuthority;
|
|
11
|
+
protected readonly sessions: TaSessionRegistry;
|
|
12
|
+
/** By session id. */
|
|
13
|
+
protected readonly runs: Map<string, Set<string>>;
|
|
14
|
+
protected init(): void;
|
|
15
|
+
prompted(sessionId: string): void;
|
|
16
|
+
/** Only by a call of its own to TaServer, not one a package made while serving it (an agent's conversation stays the owner's). */
|
|
17
|
+
created(sessionFile: string | undefined, cwd: string): void;
|
|
18
|
+
actorsOf(sessionFile: string): string[];
|
|
19
|
+
actorsOfSession(sessionId: string): ReadonlySet<string> | undefined;
|
|
20
|
+
stopRunsOf(principal: string): void;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=run-actors.d.ts.map
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.DefaultTaRunActors = void 0;
|
|
13
|
+
const core_1 = require("@celljs/core");
|
|
14
|
+
const ta_protocol_1 = require("@celljs/ta-protocol");
|
|
15
|
+
const node_1 = require("@celljs/web/lib/node");
|
|
16
|
+
const host_protocol_1 = require("../host-protocol");
|
|
17
|
+
const ta_errors_1 = require("../ta-errors");
|
|
18
|
+
const team_protocol_1 = require("./team-protocol");
|
|
19
|
+
/**
|
|
20
|
+
* Who asked the run going on in each session, until it ends (docs/design/ta-team.md 5): the owner is kept too, so that a
|
|
21
|
+
* run the owner asked is told from one nobody's page asked (a package, a scheduled task). A run of those let in starts
|
|
22
|
+
* within the owner's limit of runs at once (TaAuthorizer.mayRun).
|
|
23
|
+
*/
|
|
24
|
+
let DefaultTaRunActors = class DefaultTaRunActors {
|
|
25
|
+
constructor() {
|
|
26
|
+
/** By session id. */
|
|
27
|
+
this.runs = new Map();
|
|
28
|
+
}
|
|
29
|
+
init() {
|
|
30
|
+
this.sessions.onSessionEvent((session, event) => {
|
|
31
|
+
if (event.type === 'agent_end') {
|
|
32
|
+
this.runs.delete(session.id);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
prompted(sessionId) {
|
|
37
|
+
const principal = this.principals.current();
|
|
38
|
+
if (principal !== ta_protocol_1.TA_OWNER) {
|
|
39
|
+
const running = [...this.runs].filter(([id, actors]) => id !== sessionId && [...actors].some(actor => actor !== ta_protocol_1.TA_OWNER)).length;
|
|
40
|
+
if (!this.authority.mayRun(principal, running)) {
|
|
41
|
+
throw ta_errors_1.TaErrors.limit(running);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
let actors = this.runs.get(sessionId);
|
|
45
|
+
if (!actors) {
|
|
46
|
+
actors = new Set();
|
|
47
|
+
this.runs.set(sessionId, actors);
|
|
48
|
+
}
|
|
49
|
+
actors.add(principal);
|
|
50
|
+
}
|
|
51
|
+
/** Only by a call of its own to TaServer, not one a package made while serving it (an agent's conversation stays the owner's). */
|
|
52
|
+
created(sessionFile, cwd) {
|
|
53
|
+
var _a, _b;
|
|
54
|
+
var _c;
|
|
55
|
+
const principal = this.principals.current();
|
|
56
|
+
const direct = this.principals.acting() ||
|
|
57
|
+
/\/TaServer$/.test(((_c = (_b = (_a = node_1.Context.getCurrent()) === null || _a === void 0 ? void 0 : _a.request) === null || _b === void 0 ? void 0 : _b.url) !== null && _c !== void 0 ? _c : '').split('?')[0]);
|
|
58
|
+
if (principal !== ta_protocol_1.TA_OWNER && sessionFile && direct) {
|
|
59
|
+
this.authority.created(principal, { kind: 'session', id: sessionFile, cwd });
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
actorsOf(sessionFile) {
|
|
63
|
+
var _a;
|
|
64
|
+
const session = this.sessions.list().find(one => one.pi.sessionFile === sessionFile);
|
|
65
|
+
return session ? [...((_a = this.runs.get(session.id)) !== null && _a !== void 0 ? _a : [])] : [];
|
|
66
|
+
}
|
|
67
|
+
actorsOfSession(sessionId) {
|
|
68
|
+
return this.runs.get(sessionId);
|
|
69
|
+
}
|
|
70
|
+
stopRunsOf(principal) {
|
|
71
|
+
var _a;
|
|
72
|
+
for (const [id, actors] of this.runs) {
|
|
73
|
+
if (actors.has(principal)) {
|
|
74
|
+
(_a = this.sessions
|
|
75
|
+
.list()
|
|
76
|
+
.find(one => one.id === id)) === null || _a === void 0 ? void 0 : _a.runtime.session.abort().catch(() => undefined);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
exports.DefaultTaRunActors = DefaultTaRunActors;
|
|
82
|
+
__decorate([
|
|
83
|
+
(0, core_1.Autowired)(team_protocol_1.TaPrincipals),
|
|
84
|
+
__metadata("design:type", Object)
|
|
85
|
+
], DefaultTaRunActors.prototype, "principals", void 0);
|
|
86
|
+
__decorate([
|
|
87
|
+
(0, core_1.Autowired)(team_protocol_1.TaAuthority),
|
|
88
|
+
__metadata("design:type", Object)
|
|
89
|
+
], DefaultTaRunActors.prototype, "authority", void 0);
|
|
90
|
+
__decorate([
|
|
91
|
+
(0, core_1.Autowired)({ id: host_protocol_1.TaSessionRegistry, detached: true }),
|
|
92
|
+
__metadata("design:type", Object)
|
|
93
|
+
], DefaultTaRunActors.prototype, "sessions", void 0);
|
|
94
|
+
__decorate([
|
|
95
|
+
(0, core_1.PostConstruct)(),
|
|
96
|
+
__metadata("design:type", Function),
|
|
97
|
+
__metadata("design:paramtypes", []),
|
|
98
|
+
__metadata("design:returntype", void 0)
|
|
99
|
+
], DefaultTaRunActors.prototype, "init", null);
|
|
100
|
+
exports.DefaultTaRunActors = DefaultTaRunActors = __decorate([
|
|
101
|
+
(0, core_1.Component)(team_protocol_1.TaRunActors)
|
|
102
|
+
], DefaultTaRunActors);
|
|
103
|
+
//# sourceMappingURL=run-actors.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { TaSharedData } from '@celljs/ta-protocol';
|
|
2
|
+
import { TaSharedDataRegistry } from './team-protocol';
|
|
3
|
+
/** The data the pages of one let in keep for themselves: under a package name of their own, never in the user's. */
|
|
4
|
+
export declare namespace MemberDataUtil {
|
|
5
|
+
/** `@ta-member.<hex of the principal>/<scope>__<name>`: a file of its own, not filling the 4 MB the user's has. */
|
|
6
|
+
function name(principal: string, name: unknown): unknown;
|
|
7
|
+
/** The principal and the package of a name of {@link name}; undefined for a name of the user's. */
|
|
8
|
+
function of(name: string): {
|
|
9
|
+
principal: string;
|
|
10
|
+
name: string;
|
|
11
|
+
} | undefined;
|
|
12
|
+
}
|
|
13
|
+
/** What packages declared is the Ta's of their data (TaHostTeam.shareData): read by those let in as `view` says, never written. */
|
|
14
|
+
export declare class DefaultTaSharedDataRegistry implements TaSharedDataRegistry {
|
|
15
|
+
protected readonly shared: Map<string, TaSharedData[]>;
|
|
16
|
+
add(name: string, data: TaSharedData): () => void;
|
|
17
|
+
of(name: string, key: unknown): TaSharedData | undefined;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=shared-data.d.ts.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.DefaultTaSharedDataRegistry = exports.MemberDataUtil = void 0;
|
|
10
|
+
const core_1 = require("@celljs/core");
|
|
11
|
+
const team_protocol_1 = require("./team-protocol");
|
|
12
|
+
/** The scope of the data of packages kept apart for one let in (MemberDataUtil.name). */
|
|
13
|
+
const MEMBER_SCOPE = '@ta-member.';
|
|
14
|
+
/** The data the pages of one let in keep for themselves: under a package name of their own, never in the user's. */
|
|
15
|
+
var MemberDataUtil;
|
|
16
|
+
(function (MemberDataUtil) {
|
|
17
|
+
/** `@ta-member.<hex of the principal>/<scope>__<name>`: a file of its own, not filling the 4 MB the user's has. */
|
|
18
|
+
function name(principal, name) {
|
|
19
|
+
if (typeof name !== 'string') {
|
|
20
|
+
return name;
|
|
21
|
+
}
|
|
22
|
+
return `${MEMBER_SCOPE}${Buffer.from(principal).toString('hex')}/${name.replace(/^@/, '').replace('/', '__')}`;
|
|
23
|
+
}
|
|
24
|
+
MemberDataUtil.name = name;
|
|
25
|
+
/** The principal and the package of a name of {@link name}; undefined for a name of the user's. */
|
|
26
|
+
function of(name) {
|
|
27
|
+
if (!name.startsWith(MEMBER_SCOPE)) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
const slash = name.indexOf('/');
|
|
31
|
+
const principal = Buffer.from(name.slice(MEMBER_SCOPE.length, slash), 'hex').toString();
|
|
32
|
+
const rest = name.slice(slash + 1);
|
|
33
|
+
return { principal, name: rest.includes('__') ? `@${rest.replace('__', '/')}` : rest };
|
|
34
|
+
}
|
|
35
|
+
MemberDataUtil.of = of;
|
|
36
|
+
})(MemberDataUtil || (exports.MemberDataUtil = MemberDataUtil = {}));
|
|
37
|
+
/** What packages declared is the Ta's of their data (TaHostTeam.shareData): read by those let in as `view` says, never written. */
|
|
38
|
+
let DefaultTaSharedDataRegistry = class DefaultTaSharedDataRegistry {
|
|
39
|
+
constructor() {
|
|
40
|
+
this.shared = new Map();
|
|
41
|
+
}
|
|
42
|
+
add(name, data) {
|
|
43
|
+
var _a;
|
|
44
|
+
this.shared.set(name, [...((_a = this.shared.get(name)) !== null && _a !== void 0 ? _a : []), data]);
|
|
45
|
+
return () => { var _a; return this.shared.set(name, ((_a = this.shared.get(name)) !== null && _a !== void 0 ? _a : []).filter(one => one !== data)); };
|
|
46
|
+
}
|
|
47
|
+
of(name, key) {
|
|
48
|
+
var _a;
|
|
49
|
+
return typeof key === 'string'
|
|
50
|
+
? ((_a = this.shared.get(name)) !== null && _a !== void 0 ? _a : []).find(data => data.keys.some(one => (one.endsWith('/') ? key.startsWith(one) : key === one)))
|
|
51
|
+
: undefined;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
exports.DefaultTaSharedDataRegistry = DefaultTaSharedDataRegistry;
|
|
55
|
+
exports.DefaultTaSharedDataRegistry = DefaultTaSharedDataRegistry = __decorate([
|
|
56
|
+
(0, core_1.Component)(team_protocol_1.TaSharedDataRegistry)
|
|
57
|
+
], DefaultTaSharedDataRegistry);
|
|
58
|
+
//# sourceMappingURL=shared-data.js.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { TaResource } from '@celljs/ta-protocol';
|
|
2
|
+
/** One action on one resource. */
|
|
3
|
+
export interface TaCallNeedOne {
|
|
4
|
+
action: string;
|
|
5
|
+
resource?: TaResource;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* What a call needs of one let in: an action (on a resource), several (all of them: a file URL needs its file and the
|
|
9
|
+
* directory it opens), nothing (`anyone`: any principal let in), or nothing either and open to one holding a link of
|
|
10
|
+
* invitation too (`invite`: asking to come in).
|
|
11
|
+
*/
|
|
12
|
+
export type TaCallNeed = TaCallNeedOne | TaCallNeedOne[] | 'anyone' | 'invite';
|
|
13
|
+
/** What finding the resource of a call needs: where a session is, the default directory, what packages declare. */
|
|
14
|
+
export interface TaCallLookup {
|
|
15
|
+
session(sessionId: string): {
|
|
16
|
+
sessionFile?: string;
|
|
17
|
+
cwd: string;
|
|
18
|
+
} | undefined;
|
|
19
|
+
defaultCwd(): Promise<string>;
|
|
20
|
+
/** What a method of the host of a package needs, as it declares (TaPackagePermissions.host). */
|
|
21
|
+
packageAction(name: string, method: string, kind?: string): string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A path made plain: `..` and `.` gone, the same for a path of this machine and an `ssh://host/path` location, so
|
|
25
|
+
* that `/shared/../etc` is `/etc` before anything compares it with a folder.
|
|
26
|
+
*/
|
|
27
|
+
export declare function plainPath(path: string): string;
|
|
28
|
+
export declare namespace TaCallPermissions {
|
|
29
|
+
/** What the call needs; undefined for a call of no rule, which only the owner makes. */
|
|
30
|
+
function need(service: string, method: string, params: unknown[], lookup: TaCallLookup): Promise<TaCallNeed | undefined>;
|
|
31
|
+
/** The methods with a rule, by service: for the spec. */
|
|
32
|
+
function methods(): Record<string, string[]>;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=team-calls.d.ts.map
|