@aeolus-fleet/trierarch-plugin 0.0.0 → 0.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.
- package/LICENSE +201 -0
- package/README.md +38 -1
- package/dist/adapters/crypto/idempotency-keys.d.ts +3 -0
- package/dist/adapters/crypto/idempotency-keys.js +4 -0
- package/dist/adapters/crypto/idempotency-keys.js.map +1 -0
- package/dist/adapters/crypto/request-hasher.d.ts +3 -0
- package/dist/adapters/crypto/request-hasher.js +4 -0
- package/dist/adapters/crypto/request-hasher.js.map +1 -0
- package/dist/adapters/fleet/console-sessions.d.ts +2 -0
- package/dist/adapters/fleet/console-sessions.js +23 -0
- package/dist/adapters/fleet/console-sessions.js.map +1 -0
- package/dist/adapters/fleet/rest-fleet-door.d.ts +2 -0
- package/dist/adapters/fleet/rest-fleet-door.js +103 -0
- package/dist/adapters/fleet/rest-fleet-door.js.map +1 -0
- package/dist/adapters/http/version.d.ts +6 -0
- package/dist/adapters/http/version.js +12 -0
- package/dist/adapters/http/version.js.map +1 -0
- package/dist/adapters/prisma/client.d.ts +10 -0
- package/dist/adapters/prisma/client.js +20 -0
- package/dist/adapters/prisma/client.js.map +1 -0
- package/dist/adapters/prisma/connection-store.d.ts +4 -0
- package/dist/adapters/prisma/connection-store.js +28 -0
- package/dist/adapters/prisma/connection-store.js.map +1 -0
- package/dist/adapters/prisma/fleet-forgetter.d.ts +4 -0
- package/dist/adapters/prisma/fleet-forgetter.js +10 -0
- package/dist/adapters/prisma/fleet-forgetter.js.map +1 -0
- package/dist/adapters/prisma/fleet-switches.d.ts +4 -0
- package/dist/adapters/prisma/fleet-switches.js +10 -0
- package/dist/adapters/prisma/fleet-switches.js.map +1 -0
- package/dist/adapters/prisma/generated/browser.d.ts +24 -0
- package/dist/adapters/prisma/generated/browser.js +18 -0
- package/dist/adapters/prisma/generated/browser.js.map +1 -0
- package/dist/adapters/prisma/generated/client.d.ts +43 -0
- package/dist/adapters/prisma/generated/client.js +38 -0
- package/dist/adapters/prisma/generated/client.js.map +1 -0
- package/dist/adapters/prisma/generated/commonInputTypes.d.ts +235 -0
- package/dist/adapters/prisma/generated/commonInputTypes.js +11 -0
- package/dist/adapters/prisma/generated/commonInputTypes.js.map +1 -0
- package/dist/adapters/prisma/generated/enums.d.ts +1 -0
- package/dist/adapters/prisma/generated/enums.js +12 -0
- package/dist/adapters/prisma/generated/enums.js.map +1 -0
- package/dist/adapters/prisma/generated/internal/class.d.ts +154 -0
- package/dist/adapters/prisma/generated/internal/class.js +50 -0
- package/dist/adapters/prisma/generated/internal/class.js.map +1 -0
- package/dist/adapters/prisma/generated/internal/prismaNamespace.d.ts +766 -0
- package/dist/adapters/prisma/generated/internal/prismaNamespace.js +117 -0
- package/dist/adapters/prisma/generated/internal/prismaNamespace.js.map +1 -0
- package/dist/adapters/prisma/generated/internal/prismaNamespaceBrowser.d.ts +78 -0
- package/dist/adapters/prisma/generated/internal/prismaNamespaceBrowser.js +87 -0
- package/dist/adapters/prisma/generated/internal/prismaNamespaceBrowser.js.map +1 -0
- package/dist/adapters/prisma/generated/models/Connection.d.ts +1011 -0
- package/dist/adapters/prisma/generated/models/Connection.js +2 -0
- package/dist/adapters/prisma/generated/models/Connection.js.map +1 -0
- package/dist/adapters/prisma/generated/models/FleetSwitch.d.ts +945 -0
- package/dist/adapters/prisma/generated/models/FleetSwitch.js +2 -0
- package/dist/adapters/prisma/generated/models/FleetSwitch.js.map +1 -0
- package/dist/adapters/prisma/generated/models/InstallationRequest.d.ts +1030 -0
- package/dist/adapters/prisma/generated/models/InstallationRequest.js +2 -0
- package/dist/adapters/prisma/generated/models/InstallationRequest.js.map +1 -0
- package/dist/adapters/prisma/generated/models.d.ts +4 -0
- package/dist/adapters/prisma/generated/models.js +2 -0
- package/dist/adapters/prisma/generated/models.js.map +1 -0
- package/dist/adapters/prisma/installation-requests.d.ts +4 -0
- package/dist/adapters/prisma/installation-requests.js +25 -0
- package/dist/adapters/prisma/installation-requests.js.map +1 -0
- package/dist/adapters/prisma/migrate.d.ts +5 -0
- package/dist/adapters/prisma/migrate.js +40 -0
- package/dist/adapters/prisma/migrate.js.map +1 -0
- package/dist/adapters/trpc/router.d.ts +244 -0
- package/dist/adapters/trpc/router.js +205 -0
- package/dist/adapters/trpc/router.js.map +1 -0
- package/dist/app.d.ts +42 -0
- package/dist/app.js +177 -0
- package/dist/app.js.map +1 -0
- package/dist/bin/aeolus-trierarch-plugin.d.ts +2 -0
- package/dist/bin/aeolus-trierarch-plugin.js +61 -0
- package/dist/bin/aeolus-trierarch-plugin.js.map +1 -0
- package/dist/config.d.ts +32 -0
- package/dist/config.js +49 -0
- package/dist/config.js.map +1 -0
- package/dist/core/assignment/assign-crews.d.ts +27 -0
- package/dist/core/assignment/assign-crews.js +72 -0
- package/dist/core/assignment/assign-crews.js.map +1 -0
- package/dist/core/assignment/placement.d.ts +37 -0
- package/dist/core/assignment/placement.js +86 -0
- package/dist/core/assignment/placement.js.map +1 -0
- package/dist/core/connection/connect.d.ts +26 -0
- package/dist/core/connection/connect.js +44 -0
- package/dist/core/connection/connect.js.map +1 -0
- package/dist/core/connection/ports.d.ts +139 -0
- package/dist/core/connection/ports.js +2 -0
- package/dist/core/connection/ports.js.map +1 -0
- package/dist/core/connection/read-connection.d.ts +14 -0
- package/dist/core/connection/read-connection.js +24 -0
- package/dist/core/connection/read-connection.js.map +1 -0
- package/dist/core/installation/delete-fleet.d.ts +21 -0
- package/dist/core/installation/delete-fleet.js +21 -0
- package/dist/core/installation/delete-fleet.js.map +1 -0
- package/dist/core/installation/ports.d.ts +46 -0
- package/dist/core/installation/ports.js +2 -0
- package/dist/core/installation/ports.js.map +1 -0
- package/dist/core/installation/read-fleet.d.ts +18 -0
- package/dist/core/installation/read-fleet.js +9 -0
- package/dist/core/installation/read-fleet.js.map +1 -0
- package/dist/core/installation/request-id.d.ts +8 -0
- package/dist/core/installation/request-id.js +10 -0
- package/dist/core/installation/request-id.js.map +1 -0
- package/dist/core/installation/served.d.ts +12 -0
- package/dist/core/installation/served.js +8 -0
- package/dist/core/installation/served.js.map +1 -0
- package/dist/core/installation/set-fleet-enabled.d.ts +24 -0
- package/dist/core/installation/set-fleet-enabled.js +21 -0
- package/dist/core/installation/set-fleet-enabled.js.map +1 -0
- package/dist/core/machines/join-machine.d.ts +40 -0
- package/dist/core/machines/join-machine.js +35 -0
- package/dist/core/machines/join-machine.js.map +1 -0
- package/dist/core/machines/list-machines.d.ts +34 -0
- package/dist/core/machines/list-machines.js +47 -0
- package/dist/core/machines/list-machines.js.map +1 -0
- package/dist/core/machines/ports.d.ts +4 -0
- package/dist/core/machines/ports.js +2 -0
- package/dist/core/machines/ports.js.map +1 -0
- package/dist/core/machines/silent.d.ts +9 -0
- package/dist/core/machines/silent.js +9 -0
- package/dist/core/machines/silent.js.map +1 -0
- package/dist/core/operator/authenticate-operator.d.ts +21 -0
- package/dist/core/operator/authenticate-operator.js +26 -0
- package/dist/core/operator/authenticate-operator.js.map +1 -0
- package/dist/core/operator/ports.d.ts +15 -0
- package/dist/core/operator/ports.js +2 -0
- package/dist/core/operator/ports.js.map +1 -0
- package/dist/core/shared/clock.d.ts +4 -0
- package/dist/core/shared/clock.js +2 -0
- package/dist/core/shared/clock.js.map +1 -0
- package/dist/core/shared/errors.d.ts +10 -0
- package/dist/core/shared/errors.js +6 -0
- package/dist/core/shared/errors.js.map +1 -0
- package/dist/core/shared/result.d.ts +16 -0
- package/dist/core/shared/result.js +7 -0
- package/dist/core/shared/result.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/package.json +47 -3
- package/prisma.config.ts +18 -0
- package/src/adapters/prisma/migrations/20261006220000_init/migration.sql +35 -0
- package/src/adapters/prisma/migrations/migration_lock.toml +3 -0
- package/src/adapters/prisma/schema.prisma +58 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { refuse } from '../shared/errors.js';
|
|
2
|
+
import { ok } from '../shared/result.js';
|
|
3
|
+
/** What the trierarch plugin's ship does (decision 0030): read the fleet, commission machines' ships and assign crew requests. */
|
|
4
|
+
const PLUGIN_SCOPES = ['fleet:read', 'fleet:manage', 'crew:assign'];
|
|
5
|
+
/**
|
|
6
|
+
* Use case: the operator connects the trierarch plugin, as squadrons is
|
|
7
|
+
* connected. The console's server hands it its ship's secret, server to
|
|
8
|
+
* server; the trierarch plugin registers with it as a server and keeps only
|
|
9
|
+
* the crew token. The ship must be of the operator's fleet and hold
|
|
10
|
+
* fleet:read, fleet:manage and crew:assign, or the trierarch plugin lets it go
|
|
11
|
+
* again and keeps nothing. Each fleet has its own connection: connect works
|
|
12
|
+
* only while the trierarch plugin is not connected to the operator's fleet,
|
|
13
|
+
* whatever other fleets it serves. The secret is never kept or logged.
|
|
14
|
+
*/
|
|
15
|
+
export function createConnect(deps) {
|
|
16
|
+
return async ({ operatorFleetId, shipId, secret }) => {
|
|
17
|
+
if (await deps.store.find(operatorFleetId)) {
|
|
18
|
+
return refuse('ALREADY_CONNECTED', 'The trierarch plugin is connected to this fleet already');
|
|
19
|
+
}
|
|
20
|
+
const registered = await deps.door.register({ shipId, secret });
|
|
21
|
+
if (!registered.isOk) {
|
|
22
|
+
return refuse('SECRET_REFUSED', `The fleet refused its ship's secret: ${registered.error.message}`);
|
|
23
|
+
}
|
|
24
|
+
const { crewToken } = registered.value;
|
|
25
|
+
const letGo = async (kind, message) => {
|
|
26
|
+
await deps.door.deregister(crewToken);
|
|
27
|
+
return refuse(kind, message);
|
|
28
|
+
};
|
|
29
|
+
const who = await deps.door.whoami(crewToken);
|
|
30
|
+
if (!who.isOk) {
|
|
31
|
+
return letGo('SECRET_REFUSED', `The fleet refused the new crew token: ${who.error.message}`);
|
|
32
|
+
}
|
|
33
|
+
if (who.value.fleetId !== operatorFleetId) {
|
|
34
|
+
return letGo('OTHER_FLEET', "The ship belongs to another fleet than the operator's");
|
|
35
|
+
}
|
|
36
|
+
const ship = await deps.door.getShip(crewToken, { shipId });
|
|
37
|
+
if (!ship.isOk || !PLUGIN_SCOPES.every((scope) => ship.value.scopes.includes(scope))) {
|
|
38
|
+
return letGo('MISSING_SCOPES', 'The ship needs fleet:read, fleet:manage and crew:assign');
|
|
39
|
+
}
|
|
40
|
+
await deps.store.save({ fleetId: who.value.fleetId, shipId, name: who.value.name, crewToken, crewedAt: deps.clock.now() });
|
|
41
|
+
return ok({ state: 'connected', ship: { shipId, name: who.value.name }, lastShipId: shipId });
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=connect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connect.js","sourceRoot":"","sources":["../../../src/core/connection/connect.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAoB,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,EAAE,EAAe,MAAM,qBAAqB,CAAC;AAOtD,kIAAkI;AAClI,MAAM,aAAa,GAAG,CAAC,YAAY,EAAE,cAAc,EAAE,aAAa,CAAC,CAAC;AAEpE;;;;;;;;;GASG;AACH,MAAM,UAAU,aAAa,CAAC,IAA+D;IAC3F,OAAO,KAAK,EAAE,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE;QACnD,IAAI,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC;YAC3C,OAAO,MAAM,CAAC,mBAAmB,EAAE,yDAAyD,CAAC,CAAC;QAChG,CAAC;QACD,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;QAChE,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;YACrB,OAAO,MAAM,CAAC,gBAAgB,EAAE,wCAAwC,UAAU,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACtG,CAAC;QACD,MAAM,EAAE,SAAS,EAAE,GAAG,UAAU,CAAC,KAAK,CAAC;QACvC,MAAM,KAAK,GAAG,KAAK,EAAoC,IAAO,EAAE,OAAe,EAAE,EAAE;YACjF,MAAM,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;YACtC,OAAO,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAC/B,CAAC,CAAC;QAEF,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAC9C,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;YACd,OAAO,KAAK,CAAC,gBAAgB,EAAE,yCAAyC,GAAG,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QAC/F,CAAC;QACD,IAAI,GAAG,CAAC,KAAK,CAAC,OAAO,KAAK,eAAe,EAAE,CAAC;YAC1C,OAAO,KAAK,CAAC,aAAa,EAAE,uDAAuD,CAAC,CAAC;QACvF,CAAC;QACD,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;QAC5D,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;YACrF,OAAO,KAAK,CAAC,gBAAgB,EAAE,yDAAyD,CAAC,CAAC;QAC5F,CAAC;QAED,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QAC3H,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC,CAAC;IAChG,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import type { CrewLine, FleetId, ShipId } from '@aeolus-fleet/common';
|
|
2
|
+
import type { Result } from '../shared/result.js';
|
|
3
|
+
/**
|
|
4
|
+
* Why the fleet refused a ship call: its code (CONFLICT, UNAUTHORIZED,
|
|
5
|
+
* LEASE_ENDED, ...) and its message. UNAVAILABLE: no answer came, so the call
|
|
6
|
+
* may or may not have been carried out.
|
|
7
|
+
*/
|
|
8
|
+
export interface FleetRefusal {
|
|
9
|
+
code: string;
|
|
10
|
+
message: string;
|
|
11
|
+
}
|
|
12
|
+
/** A ship's starting prompt as the fleet issues it once: the prompt, its crew lines and the secret they hold. */
|
|
13
|
+
export interface IssuedPrompt {
|
|
14
|
+
prompt: string;
|
|
15
|
+
crewLines: CrewLine[];
|
|
16
|
+
secret: string;
|
|
17
|
+
}
|
|
18
|
+
/** A ship as `fleet.list` lists it: what the trierarch plugin reads of it. */
|
|
19
|
+
export interface ListedShip {
|
|
20
|
+
shipId: ShipId;
|
|
21
|
+
name: string;
|
|
22
|
+
type: string;
|
|
23
|
+
status: 'awaitingCrew' | 'crewed' | 'retired';
|
|
24
|
+
/** When its session last called the fleet; null while no session crews it. */
|
|
25
|
+
lastSeenAt: Date | null;
|
|
26
|
+
/** Its crew request, without its settings; null when it holds none. */
|
|
27
|
+
crewRequest: {
|
|
28
|
+
requestedAt: Date;
|
|
29
|
+
assignedTo: ShipId | null;
|
|
30
|
+
reason: string | null;
|
|
31
|
+
} | null;
|
|
32
|
+
}
|
|
33
|
+
/** A ship as `fleet.ship` shows it: what the trierarch plugin reads of it. */
|
|
34
|
+
export interface FleetShip {
|
|
35
|
+
status: 'awaitingCrew' | 'crewed' | 'retired';
|
|
36
|
+
scopes: string[];
|
|
37
|
+
commissionedAt: Date;
|
|
38
|
+
/** Its crew's last report, details included as the fleet holds them; null until its crew reports. */
|
|
39
|
+
report: {
|
|
40
|
+
state: string;
|
|
41
|
+
note: string | null;
|
|
42
|
+
reportedAt: Date;
|
|
43
|
+
details: unknown;
|
|
44
|
+
} | null;
|
|
45
|
+
/** Its crew request's settings, unread; null when it holds no crew request. */
|
|
46
|
+
crewSettings: unknown;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Outbound port: the fleet's public ship calls, as the trierarch plugin makes
|
|
50
|
+
* them for its own ship. The trierarch plugin is a ship like any other
|
|
51
|
+
* (decision 0030).
|
|
52
|
+
*/
|
|
53
|
+
export interface FleetDoor {
|
|
54
|
+
register(claim: {
|
|
55
|
+
shipId: ShipId;
|
|
56
|
+
secret: string;
|
|
57
|
+
}): Promise<Result<{
|
|
58
|
+
crewToken: string;
|
|
59
|
+
}, FleetRefusal>>;
|
|
60
|
+
whoami(crewToken: string): Promise<Result<{
|
|
61
|
+
shipId: ShipId;
|
|
62
|
+
fleetId: FleetId;
|
|
63
|
+
name: string;
|
|
64
|
+
type: string;
|
|
65
|
+
}, FleetRefusal>>;
|
|
66
|
+
/** A ship of the fleet, retired ones included; needs fleet:read. */
|
|
67
|
+
getShip(crewToken: string, ship: {
|
|
68
|
+
shipId: ShipId;
|
|
69
|
+
}): Promise<Result<FleetShip, FleetRefusal>>;
|
|
70
|
+
/** Ends this session's crew of its ship: the lease and the secret it claimed with. */
|
|
71
|
+
deregister(crewToken: string): Promise<Result<undefined, FleetRefusal>>;
|
|
72
|
+
/**
|
|
73
|
+
* Commissions a ship as the crew token's ship (fleet:manage) under a new
|
|
74
|
+
* idempotency key, with the fleet scopes given beside the send and receive
|
|
75
|
+
* every agent ship has: its id and its starting prompt, issued once.
|
|
76
|
+
*/
|
|
77
|
+
commission(crewToken: string, ship: {
|
|
78
|
+
name: string;
|
|
79
|
+
type: string;
|
|
80
|
+
fleetScopes: string[];
|
|
81
|
+
idempotencyKey: string;
|
|
82
|
+
}): Promise<Result<{
|
|
83
|
+
shipId: ShipId;
|
|
84
|
+
} & IssuedPrompt, FleetRefusal>>;
|
|
85
|
+
/** Every ship of the fleet, retired ones included (fleet:read). */
|
|
86
|
+
listShips(crewToken: string): Promise<Result<ListedShip[], FleetRefusal>>;
|
|
87
|
+
/** Claims a ship's crew request for a trierarch (crew:assign), only while it is unassigned: a lost claim is CONFLICT. */
|
|
88
|
+
assignCrew(crewToken: string, claim: {
|
|
89
|
+
shipId: ShipId;
|
|
90
|
+
trierarchShipId: ShipId;
|
|
91
|
+
}): Promise<Result<undefined, FleetRefusal>>;
|
|
92
|
+
/** Writes why no trierarch can take a ship's unassigned crew request (crew:assign). */
|
|
93
|
+
explainCrewRequest(crewToken: string, explanation: {
|
|
94
|
+
shipId: ShipId;
|
|
95
|
+
reason: string | null;
|
|
96
|
+
}): Promise<Result<undefined, FleetRefusal>>;
|
|
97
|
+
}
|
|
98
|
+
/** The crew token the trierarch plugin holds for its ship in a fleet, and when it got it. */
|
|
99
|
+
export interface PluginCrew {
|
|
100
|
+
/** The fleet the ship belongs to: the fleet the trierarch plugin serves. */
|
|
101
|
+
fleetId: FleetId;
|
|
102
|
+
shipId: ShipId;
|
|
103
|
+
/** The ship's name when the trierarch plugin connected, shown while the fleet does not answer. */
|
|
104
|
+
name: string;
|
|
105
|
+
crewToken: string;
|
|
106
|
+
crewedAt: Date;
|
|
107
|
+
}
|
|
108
|
+
/** The fleet and ship the trierarch plugin was last connected as; kept when its crew token is dropped. */
|
|
109
|
+
export interface PluginBinding {
|
|
110
|
+
fleetId: FleetId;
|
|
111
|
+
shipId: ShipId;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Outbound port: where the trierarch plugin keeps each fleet's crew token
|
|
115
|
+
* across restarts. One install serves many fleets, one connection each.
|
|
116
|
+
*/
|
|
117
|
+
export interface ConnectionStore {
|
|
118
|
+
/** The fleet's crew, while the trierarch plugin holds a crew token for it: while it is connected to that fleet. */
|
|
119
|
+
find(fleetId: FleetId): Promise<PluginCrew | undefined>;
|
|
120
|
+
/** The fleet's last connection, with or without a crew token; none before its first. */
|
|
121
|
+
binding(fleetId: FleetId): Promise<PluginBinding | undefined>;
|
|
122
|
+
/** Every fleet's crew the trierarch plugin holds a crew token for: the fleets it is connected to. */
|
|
123
|
+
connected(): Promise<PluginCrew[]>;
|
|
124
|
+
save(crew: PluginCrew): Promise<void>;
|
|
125
|
+
/** Forgets the fleet's crew token, keeping its binding: the trierarch plugin is not connected to that fleet. */
|
|
126
|
+
drop(fleetId: FleetId): Promise<void>;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Whether the trierarch plugin holds a working crew token for its ship, as
|
|
130
|
+
* which ship, and the ship it was last connected as.
|
|
131
|
+
*/
|
|
132
|
+
export interface ConnectionStatus {
|
|
133
|
+
state: 'not-connected' | 'connected';
|
|
134
|
+
ship: {
|
|
135
|
+
shipId: ShipId;
|
|
136
|
+
name: string;
|
|
137
|
+
} | null;
|
|
138
|
+
lastShipId: ShipId | null;
|
|
139
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ports.js","sourceRoot":"","sources":["../../../src/core/connection/ports.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { FleetId } from '@aeolus-fleet/common';
|
|
2
|
+
import type { ConnectionStatus, FleetDoor, ConnectionStore } from './ports.js';
|
|
3
|
+
export type ReadConnection = (fleetId: FleetId) => Promise<ConnectionStatus>;
|
|
4
|
+
/**
|
|
5
|
+
* Use case: whether the trierarch plugin is connected to a fleet. The fleet's
|
|
6
|
+
* kept crew token is asked who it is: a token the fleet no longer takes (the
|
|
7
|
+
* ship was released, its session ended) is dropped, and the trierarch plugin
|
|
8
|
+
* is not connected to that fleet until its operator connects it again. When
|
|
9
|
+
* the fleet does not answer, the token is kept.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createReadConnection(deps: {
|
|
12
|
+
door: FleetDoor;
|
|
13
|
+
store: ConnectionStore;
|
|
14
|
+
}): ReadConnection;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** The codes with which the fleet says a crew token no longer crews its ship. */
|
|
2
|
+
const GONE = new Set(['LEASE_ENDED', 'UNAUTHORIZED']);
|
|
3
|
+
/**
|
|
4
|
+
* Use case: whether the trierarch plugin is connected to a fleet. The fleet's
|
|
5
|
+
* kept crew token is asked who it is: a token the fleet no longer takes (the
|
|
6
|
+
* ship was released, its session ended) is dropped, and the trierarch plugin
|
|
7
|
+
* is not connected to that fleet until its operator connects it again. When
|
|
8
|
+
* the fleet does not answer, the token is kept.
|
|
9
|
+
*/
|
|
10
|
+
export function createReadConnection(deps) {
|
|
11
|
+
return async (fleetId) => {
|
|
12
|
+
const crew = await deps.store.find(fleetId);
|
|
13
|
+
if (crew) {
|
|
14
|
+
const who = await deps.door.whoami(crew.crewToken);
|
|
15
|
+
if (who.isOk || !GONE.has(who.error.code)) {
|
|
16
|
+
return { state: 'connected', ship: { shipId: crew.shipId, name: who.isOk ? who.value.name : crew.name }, lastShipId: crew.shipId };
|
|
17
|
+
}
|
|
18
|
+
await deps.store.drop(fleetId);
|
|
19
|
+
}
|
|
20
|
+
const binding = await deps.store.binding(fleetId);
|
|
21
|
+
return { state: 'not-connected', ship: null, lastShipId: binding?.shipId ?? null };
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=read-connection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-connection.js","sourceRoot":"","sources":["../../../src/core/connection/read-connection.ts"],"names":[],"mappings":"AAMA,iFAAiF;AACjF,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,CAAC,aAAa,EAAE,cAAc,CAAC,CAAC,CAAC;AAEtD;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAAiD;IACpF,OAAO,KAAK,EAAE,OAAO,EAAE,EAAE;QACvB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC5C,IAAI,IAAI,EAAE,CAAC;YACT,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACnD,IAAI,GAAG,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC1C,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,UAAU,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC;YACrI,CAAC;YACD,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACjC,CAAC;QACD,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAClD,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,IAAI,IAAI,EAAE,CAAC;IACrF,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { FleetId } from '@aeolus-fleet/common';
|
|
2
|
+
import type { Clock } from '../shared/clock.js';
|
|
3
|
+
import type { DomainError } from '../shared/errors.js';
|
|
4
|
+
import { type Result } from '../shared/result.js';
|
|
5
|
+
import type { FleetForgetter, InstallationRequests, RequestHasher } from './ports.js';
|
|
6
|
+
export type DeleteFleet = (input: {
|
|
7
|
+
requestId: string;
|
|
8
|
+
fleetId: FleetId;
|
|
9
|
+
}) => Promise<Result<Record<string, never>, DomainError<'REQUEST_ID_USED'>>>;
|
|
10
|
+
/**
|
|
11
|
+
* Use case: the hosting service deletes a fleet from the trierarch plugin (decision
|
|
12
|
+
* 0021): it forgets everything it holds of the fleet, and tells the
|
|
13
|
+
* fleet nothing (its ships stay there). The request is kept as its hash
|
|
14
|
+
* only, so nothing of the fleet stays; a replay answers the first answer.
|
|
15
|
+
*/
|
|
16
|
+
export declare function createDeleteFleet(deps: {
|
|
17
|
+
forgetter: FleetForgetter;
|
|
18
|
+
requests: InstallationRequests;
|
|
19
|
+
hasher: RequestHasher;
|
|
20
|
+
clock: Clock;
|
|
21
|
+
}): DeleteFleet;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ok } from '../shared/result.js';
|
|
2
|
+
import { earlierAnswer } from './request-id.js';
|
|
3
|
+
/**
|
|
4
|
+
* Use case: the hosting service deletes a fleet from the trierarch plugin (decision
|
|
5
|
+
* 0021): it forgets everything it holds of the fleet, and tells the
|
|
6
|
+
* fleet nothing (its ships stay there). The request is kept as its hash
|
|
7
|
+
* only, so nothing of the fleet stays; a replay answers the first answer.
|
|
8
|
+
*/
|
|
9
|
+
export function createDeleteFleet(deps) {
|
|
10
|
+
return async ({ requestId, fleetId }) => {
|
|
11
|
+
const requestHash = deps.hasher.hash(`deleteFleet ${fleetId}`);
|
|
12
|
+
const earlier = await earlierAnswer(deps.requests, { requestId, requestHash });
|
|
13
|
+
if (earlier !== undefined) {
|
|
14
|
+
return 'isOk' in earlier ? earlier : ok({});
|
|
15
|
+
}
|
|
16
|
+
await deps.forgetter.forget(fleetId);
|
|
17
|
+
await deps.requests.record({ requestId, kind: 'deleteFleet', requestHash, fleetId: null, isEnabled: null, at: deps.clock.now() });
|
|
18
|
+
return ok({});
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=delete-fleet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete-fleet.js","sourceRoot":"","sources":["../../../src/core/installation/delete-fleet.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,EAAE,EAAe,MAAM,qBAAqB,CAAC;AAEtD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAIhD;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAwG;IACxI,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE,EAAE;QACtC,MAAM,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,eAAe,OAAO,EAAE,CAAC,CAAC;QAC/D,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC,CAAC;QAC/E,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC1B,OAAO,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QAC9C,CAAC;QACD,MAAM,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACrC,MAAM,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,aAAa,EAAE,WAAW,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QAClI,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { FleetId } from '@aeolus-fleet/common';
|
|
2
|
+
/**
|
|
3
|
+
* Whether the installation has an installation token (decision 0021): open
|
|
4
|
+
* without one, as a self-hosted trierarch plugin runs, and every fleet is served;
|
|
5
|
+
* enabled with one, and a fleet is served only once the hosting service
|
|
6
|
+
* switched it on.
|
|
7
|
+
*/
|
|
8
|
+
export type InstallationMode = 'open' | 'enabled';
|
|
9
|
+
/** Outbound port: each fleet's switch, as the hosting service set it. */
|
|
10
|
+
export interface FleetSwitches {
|
|
11
|
+
/** Whether the fleet was switched on; undefined when it never was switched. */
|
|
12
|
+
find(fleetId: FleetId): Promise<boolean | undefined>;
|
|
13
|
+
set(fleetId: FleetId, change: {
|
|
14
|
+
isEnabled: boolean;
|
|
15
|
+
at: Date;
|
|
16
|
+
}): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A request the installation answered, by the caller's request id. A switch
|
|
20
|
+
* names its fleet and what it set, and goes with its fleet; a delete names
|
|
21
|
+
* nothing of the fleet, only the request's hash.
|
|
22
|
+
*/
|
|
23
|
+
export interface InstallationRequest {
|
|
24
|
+
requestId: string;
|
|
25
|
+
kind: 'setEnabled' | 'deleteFleet';
|
|
26
|
+
requestHash: string;
|
|
27
|
+
fleetId: FleetId | null;
|
|
28
|
+
isEnabled: boolean | null;
|
|
29
|
+
at: Date;
|
|
30
|
+
}
|
|
31
|
+
/** Outbound port: the installation's requests, so a replay answers what the first call answered. */
|
|
32
|
+
export interface InstallationRequests {
|
|
33
|
+
find(requestId: string): Promise<InstallationRequest | undefined>;
|
|
34
|
+
record(request: InstallationRequest): Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Outbound port: forgets everything the trierarch plugin holds of a fleet,
|
|
38
|
+
* in one go: its connection, its switch and the requests that name it.
|
|
39
|
+
*/
|
|
40
|
+
export interface FleetForgetter {
|
|
41
|
+
forget(fleetId: FleetId): Promise<void>;
|
|
42
|
+
}
|
|
43
|
+
/** Outbound port: a one-way hash of a request's text, kept instead of the request. */
|
|
44
|
+
export interface RequestHasher {
|
|
45
|
+
hash(text: string): string;
|
|
46
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ports.js","sourceRoot":"","sources":["../../../src/core/installation/ports.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { FleetId } from '@aeolus-fleet/common';
|
|
2
|
+
import type { ConnectionStore } from '../connection/ports.js';
|
|
3
|
+
import type { IsServed } from './served.js';
|
|
4
|
+
export type ReadFleet = (input: {
|
|
5
|
+
fleetId: FleetId;
|
|
6
|
+
}) => Promise<{
|
|
7
|
+
isEnabled: boolean;
|
|
8
|
+
isConnected: boolean;
|
|
9
|
+
}>;
|
|
10
|
+
/**
|
|
11
|
+
* Use case: a fleet as the hosting service reads it: whether the trierarch plugin serves
|
|
12
|
+
* it, and whether the trierarch plugin holds a crew token for it. Off and connected is a
|
|
13
|
+
* fleet whose connection waits for it to be on again.
|
|
14
|
+
*/
|
|
15
|
+
export declare function createReadFleet(deps: {
|
|
16
|
+
isServed: IsServed;
|
|
17
|
+
connections: ConnectionStore;
|
|
18
|
+
}): ReadFleet;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Use case: a fleet as the hosting service reads it: whether the trierarch plugin serves
|
|
3
|
+
* it, and whether the trierarch plugin holds a crew token for it. Off and connected is a
|
|
4
|
+
* fleet whose connection waits for it to be on again.
|
|
5
|
+
*/
|
|
6
|
+
export function createReadFleet(deps) {
|
|
7
|
+
return async ({ fleetId }) => ({ isEnabled: await deps.isServed(fleetId), isConnected: (await deps.connections.find(fleetId)) !== undefined });
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=read-fleet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-fleet.js","sourceRoot":"","sources":["../../../src/core/installation/read-fleet.ts"],"names":[],"mappings":"AAOA;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,IAA0D;IACxF,OAAO,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,WAAW,EAAE,CAAC,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,SAAS,EAAE,CAAC,CAAC;AACjJ,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type DomainError } from '../shared/errors.js';
|
|
2
|
+
import type { Err } from '../shared/result.js';
|
|
3
|
+
import type { InstallationRequest, InstallationRequests } from './ports.js';
|
|
4
|
+
/** What a request id already answered: the earlier request when it is the same one, a refusal when it was another. */
|
|
5
|
+
export declare function earlierAnswer(requests: InstallationRequests, request: {
|
|
6
|
+
requestId: string;
|
|
7
|
+
requestHash: string;
|
|
8
|
+
}): Promise<InstallationRequest | Err<DomainError<'REQUEST_ID_USED'>> | undefined>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { refuse } from '../shared/errors.js';
|
|
2
|
+
/** What a request id already answered: the earlier request when it is the same one, a refusal when it was another. */
|
|
3
|
+
export async function earlierAnswer(requests, request) {
|
|
4
|
+
const earlier = await requests.find(request.requestId);
|
|
5
|
+
if (!earlier) {
|
|
6
|
+
return undefined;
|
|
7
|
+
}
|
|
8
|
+
return earlier.requestHash === request.requestHash ? earlier : refuse('REQUEST_ID_USED', `The request id ${request.requestId} was used for another request`);
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=request-id.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-id.js","sourceRoot":"","sources":["../../../src/core/installation/request-id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAoB,MAAM,qBAAqB,CAAC;AAI/D,sHAAsH;AACtH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,QAA8B,EAC9B,OAAmD;IAEnD,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACvD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,OAAO,CAAC,WAAW,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,iBAAiB,EAAE,kBAAkB,OAAO,CAAC,SAAS,+BAA+B,CAAC,CAAC;AAC/J,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { FleetId } from '@aeolus-fleet/common';
|
|
2
|
+
import type { FleetSwitches, InstallationMode } from './ports.js';
|
|
3
|
+
/** Whether the trierarch plugin serves the fleet now: off, it does nothing for that fleet. */
|
|
4
|
+
export type IsServed = (fleetId: FleetId) => Promise<boolean>;
|
|
5
|
+
/**
|
|
6
|
+
* Policy: the trierarch plugin serves every fleet of an open installation, and a fleet of
|
|
7
|
+
* an enabled one only once the hosting service switched it on (decision 0021).
|
|
8
|
+
*/
|
|
9
|
+
export declare function createIsServed(deps: {
|
|
10
|
+
installation: InstallationMode;
|
|
11
|
+
switches: FleetSwitches;
|
|
12
|
+
}): IsServed;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Policy: the trierarch plugin serves every fleet of an open installation, and a fleet of
|
|
3
|
+
* an enabled one only once the hosting service switched it on (decision 0021).
|
|
4
|
+
*/
|
|
5
|
+
export function createIsServed(deps) {
|
|
6
|
+
return async (fleetId) => deps.installation === 'open' || (await deps.switches.find(fleetId)) === true;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=served.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"served.js","sourceRoot":"","sources":["../../../src/core/installation/served.ts"],"names":[],"mappings":"AAOA;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,IAAiE;IAC9F,OAAO,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,KAAK,MAAM,IAAI,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,IAAI,CAAC;AACzG,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { FleetId } from '@aeolus-fleet/common';
|
|
2
|
+
import type { Clock } from '../shared/clock.js';
|
|
3
|
+
import type { DomainError } from '../shared/errors.js';
|
|
4
|
+
import { type Result } from '../shared/result.js';
|
|
5
|
+
import type { FleetSwitches, InstallationRequests, RequestHasher } from './ports.js';
|
|
6
|
+
export type SetFleetEnabled = (input: {
|
|
7
|
+
requestId: string;
|
|
8
|
+
fleetId: FleetId;
|
|
9
|
+
isEnabled: boolean;
|
|
10
|
+
}) => Promise<Result<{
|
|
11
|
+
fleetId: FleetId;
|
|
12
|
+
isEnabled: boolean;
|
|
13
|
+
}, DomainError<'REQUEST_ID_USED'>>>;
|
|
14
|
+
/**
|
|
15
|
+
* Use case: the hosting service switches the trierarch plugin on or off for a fleet
|
|
16
|
+
* (decision 0021). Off keeps everything of the fleet, so on again resumes. A
|
|
17
|
+
* replayed request id answers what it answered first and changes nothing.
|
|
18
|
+
*/
|
|
19
|
+
export declare function createSetFleetEnabled(deps: {
|
|
20
|
+
switches: FleetSwitches;
|
|
21
|
+
requests: InstallationRequests;
|
|
22
|
+
hasher: RequestHasher;
|
|
23
|
+
clock: Clock;
|
|
24
|
+
}): SetFleetEnabled;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ok } from '../shared/result.js';
|
|
2
|
+
import { earlierAnswer } from './request-id.js';
|
|
3
|
+
/**
|
|
4
|
+
* Use case: the hosting service switches the trierarch plugin on or off for a fleet
|
|
5
|
+
* (decision 0021). Off keeps everything of the fleet, so on again resumes. A
|
|
6
|
+
* replayed request id answers what it answered first and changes nothing.
|
|
7
|
+
*/
|
|
8
|
+
export function createSetFleetEnabled(deps) {
|
|
9
|
+
return async ({ requestId, fleetId, isEnabled }) => {
|
|
10
|
+
const requestHash = deps.hasher.hash(`setEnabled ${fleetId} ${String(isEnabled)}`);
|
|
11
|
+
const earlier = await earlierAnswer(deps.requests, { requestId, requestHash });
|
|
12
|
+
if (earlier !== undefined) {
|
|
13
|
+
return 'isOk' in earlier ? earlier : ok({ fleetId, isEnabled: earlier.isEnabled === true });
|
|
14
|
+
}
|
|
15
|
+
const at = deps.clock.now();
|
|
16
|
+
await deps.switches.set(fleetId, { isEnabled, at });
|
|
17
|
+
await deps.requests.record({ requestId, kind: 'setEnabled', requestHash, fleetId, isEnabled, at });
|
|
18
|
+
return ok({ fleetId, isEnabled });
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=set-fleet-enabled.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"set-fleet-enabled.js","sourceRoot":"","sources":["../../../src/core/installation/set-fleet-enabled.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,EAAE,EAAe,MAAM,qBAAqB,CAAC;AAEtD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAIhD;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAsG;IAC1I,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE;QACjD,MAAM,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,OAAO,IAAI,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;QACnF,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC,CAAC;QAC/E,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC1B,OAAO,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,KAAK,IAAI,EAAE,CAAC,CAAC;QAC9F,CAAC;QACD,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;QAC5B,MAAM,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC;QACpD,MAAM,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,YAAY,EAAE,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC;QACnG,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC;IACpC,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { CrewLine, FleetId, ShipId } from '@aeolus-fleet/common';
|
|
2
|
+
import type { ConnectionStore, FleetDoor } from '../connection/ports.js';
|
|
3
|
+
import { type DomainError } from '../shared/errors.js';
|
|
4
|
+
import { type Result } from '../shared/result.js';
|
|
5
|
+
import type { IdempotencyKeys } from './ports.js';
|
|
6
|
+
/** The type of every machine's ship: its trierarch's. */
|
|
7
|
+
export declare const TRIERARCH_TYPE = "trierarch";
|
|
8
|
+
export type JoinRefusal = DomainError<'NOT_CONNECTED' | 'NAME_TAKEN' | 'FLEET_UNAVAILABLE'>;
|
|
9
|
+
/**
|
|
10
|
+
* A joined machine: its trierarch's ship, its starting prompt as the fleet
|
|
11
|
+
* issued it (decision 0019), and the line that sets the machine up, shown
|
|
12
|
+
* once like the secret it holds.
|
|
13
|
+
*/
|
|
14
|
+
export interface JoinedMachine {
|
|
15
|
+
shipId: ShipId;
|
|
16
|
+
name: string;
|
|
17
|
+
prompt: string;
|
|
18
|
+
crewLines: CrewLine[];
|
|
19
|
+
secret: string;
|
|
20
|
+
setupLine: string;
|
|
21
|
+
}
|
|
22
|
+
export type JoinMachine = (input: {
|
|
23
|
+
fleetId: FleetId;
|
|
24
|
+
name: string;
|
|
25
|
+
}) => Promise<Result<JoinedMachine, JoinRefusal>>;
|
|
26
|
+
/**
|
|
27
|
+
* Use case: the operator brings a machine into the fleet. The trierarch
|
|
28
|
+
* plugin commissions its trierarch's ship, of type trierarch with crew:run
|
|
29
|
+
* beside the send and receive every agent ship has, under a new idempotency
|
|
30
|
+
* key, and answers its starting prompt with one ready-to-run setup line built
|
|
31
|
+
* from the fleet's URL, the ship's id and its secret: `aeolus-trierarch init`
|
|
32
|
+
* takes them as flags and never parses a prompt. The secret is never kept or
|
|
33
|
+
* logged.
|
|
34
|
+
*/
|
|
35
|
+
export declare function createJoinMachine(deps: {
|
|
36
|
+
door: FleetDoor;
|
|
37
|
+
connections: ConnectionStore;
|
|
38
|
+
keys: IdempotencyKeys;
|
|
39
|
+
fleetUrl: string;
|
|
40
|
+
}): JoinMachine;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { refuse } from '../shared/errors.js';
|
|
2
|
+
import { ok } from '../shared/result.js';
|
|
3
|
+
/** The type of every machine's ship: its trierarch's. */
|
|
4
|
+
export const TRIERARCH_TYPE = 'trierarch';
|
|
5
|
+
/** What a trierarch may do beyond sending and receiving: crew the ships assigned to it (decision 0030). */
|
|
6
|
+
const TRIERARCH_SCOPES = ['crew:run'];
|
|
7
|
+
/** The package a machine sets up its trierarch with. */
|
|
8
|
+
const TRIERARCH_PACKAGE = '@aeolus-fleet/trierarch';
|
|
9
|
+
/**
|
|
10
|
+
* Use case: the operator brings a machine into the fleet. The trierarch
|
|
11
|
+
* plugin commissions its trierarch's ship, of type trierarch with crew:run
|
|
12
|
+
* beside the send and receive every agent ship has, under a new idempotency
|
|
13
|
+
* key, and answers its starting prompt with one ready-to-run setup line built
|
|
14
|
+
* from the fleet's URL, the ship's id and its secret: `aeolus-trierarch init`
|
|
15
|
+
* takes them as flags and never parses a prompt. The secret is never kept or
|
|
16
|
+
* logged.
|
|
17
|
+
*/
|
|
18
|
+
export function createJoinMachine(deps) {
|
|
19
|
+
return async ({ fleetId, name }) => {
|
|
20
|
+
const crew = await deps.connections.find(fleetId);
|
|
21
|
+
if (!crew) {
|
|
22
|
+
return refuse('NOT_CONNECTED', 'The trierarch plugin is not connected to this fleet: connect it in the console');
|
|
23
|
+
}
|
|
24
|
+
const commissioned = await deps.door.commission(crew.crewToken, { name, type: TRIERARCH_TYPE, fleetScopes: TRIERARCH_SCOPES, idempotencyKey: deps.keys.next() });
|
|
25
|
+
if (!commissioned.isOk) {
|
|
26
|
+
return commissioned.error.code === 'CONFLICT'
|
|
27
|
+
? refuse('NAME_TAKEN', commissioned.error.message)
|
|
28
|
+
: refuse('FLEET_UNAVAILABLE', `The fleet did not commission the machine's ship: ${commissioned.error.message}`);
|
|
29
|
+
}
|
|
30
|
+
const { shipId, prompt, crewLines, secret } = commissioned.value;
|
|
31
|
+
const setupLine = `npx ${TRIERARCH_PACKAGE} init --fleet-url ${deps.fleetUrl} --ship-id ${shipId} --secret ${secret}`;
|
|
32
|
+
return ok({ shipId, name, prompt, crewLines, secret, setupLine });
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=join-machine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"join-machine.js","sourceRoot":"","sources":["../../../src/core/machines/join-machine.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAoB,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,EAAE,EAAe,MAAM,qBAAqB,CAAC;AAGtD,yDAAyD;AACzD,MAAM,CAAC,MAAM,cAAc,GAAG,WAAW,CAAC;AAE1C,2GAA2G;AAC3G,MAAM,gBAAgB,GAAG,CAAC,UAAU,CAAC,CAAC;AAEtC,wDAAwD;AACxD,MAAM,iBAAiB,GAAG,yBAAyB,CAAC;AAoBpD;;;;;;;;GAQG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAgG;IAChI,OAAO,KAAK,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE;QACjC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAClD,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,OAAO,MAAM,CAAC,eAAe,EAAE,gFAAgF,CAAC,CAAC;QACnH,CAAC;QACD,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,cAAc,EAAE,WAAW,EAAE,gBAAgB,EAAE,cAAc,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACjK,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;YACvB,OAAO,YAAY,CAAC,KAAK,CAAC,IAAI,KAAK,UAAU;gBAC3C,CAAC,CAAC,MAAM,CAAC,YAAY,EAAE,YAAY,CAAC,KAAK,CAAC,OAAO,CAAC;gBAClD,CAAC,CAAC,MAAM,CAAC,mBAAmB,EAAE,oDAAoD,YAAY,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACpH,CAAC;QACD,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,YAAY,CAAC,KAAK,CAAC;QACjE,MAAM,SAAS,GAAG,OAAO,iBAAiB,qBAAqB,IAAI,CAAC,QAAQ,cAAc,MAAM,aAAa,MAAM,EAAE,CAAC;QACtH,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;IACpE,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type FleetId, type ShipId, type TrierarchReportDetails } from '@aeolus-fleet/common';
|
|
2
|
+
import type { ConnectionStore, FleetDoor } from '../connection/ports.js';
|
|
3
|
+
import type { Clock } from '../shared/clock.js';
|
|
4
|
+
import { type DomainError } from '../shared/errors.js';
|
|
5
|
+
import { type Result } from '../shared/result.js';
|
|
6
|
+
/** A machine as the trierarch plugin reads it from the fleet: its trierarch's ship, its last report and what it reported it can do. */
|
|
7
|
+
export interface Machine {
|
|
8
|
+
shipId: ShipId;
|
|
9
|
+
name: string;
|
|
10
|
+
status: 'awaitingCrew' | 'crewed';
|
|
11
|
+
lastSeenAt: Date | null;
|
|
12
|
+
/** Its trierarch's last seen is older than the threshold: it gets no new requests, and keeps those it holds. */
|
|
13
|
+
isSilent: boolean;
|
|
14
|
+
report: {
|
|
15
|
+
state: string;
|
|
16
|
+
note: string | null;
|
|
17
|
+
reportedAt: Date;
|
|
18
|
+
} | null;
|
|
19
|
+
/** Null until its trierarch reports details, and for details that are not a trierarch's. */
|
|
20
|
+
details: TrierarchReportDetails | null;
|
|
21
|
+
}
|
|
22
|
+
export type ListMachines = (fleetId: FleetId) => Promise<Result<Machine[], DomainError<'NOT_CONNECTED' | 'FLEET_UNAVAILABLE'>>>;
|
|
23
|
+
/**
|
|
24
|
+
* Use case: the fleet's machines, read from the fleet each time: its active
|
|
25
|
+
* ships of type trierarch, each with its trierarch's last report and the
|
|
26
|
+
* details it reported (decision 0030), and whether it is silent. The
|
|
27
|
+
* trierarch plugin keeps none of it.
|
|
28
|
+
*/
|
|
29
|
+
export declare function createListMachines(deps: {
|
|
30
|
+
door: FleetDoor;
|
|
31
|
+
connections: ConnectionStore;
|
|
32
|
+
clock: Clock;
|
|
33
|
+
silentAfterMs: number;
|
|
34
|
+
}): ListMachines;
|