@rivalis/fleet 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +417 -0
- package/bin/rivalis-fleet.js +10 -0
- package/lib/AgentAuthenticator.js +56 -0
- package/lib/CommandEngine.js +258 -0
- package/lib/EventReconciler.js +90 -0
- package/lib/FleetAgent.js +1217 -0
- package/lib/FleetControl.js +139 -0
- package/lib/FleetState.js +865 -0
- package/lib/Orchestrator.js +2834 -0
- package/lib/Poller.js +113 -0
- package/lib/Snapshot.js +471 -0
- package/lib/canonical.js +82 -0
- package/lib/cli.js +3076 -0
- package/lib/domain.js +97 -0
- package/lib/env.js +99 -0
- package/lib/main.d.ts +592 -0
- package/lib/main.js +3618 -0
- package/lib/module.js +3582 -0
- package/lib/routers.js +598 -0
- package/lib/wire.js +507 -0
- package/package.json +78 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/orchestrator/FleetControl.ts
|
|
21
|
+
var FleetControl_exports = {};
|
|
22
|
+
__export(FleetControl_exports, {
|
|
23
|
+
FleetControl: () => FleetControl
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(FleetControl_exports);
|
|
26
|
+
|
|
27
|
+
// src/domain/roomId.ts
|
|
28
|
+
var ROOM_ID_PATTERN = /^[A-Za-z0-9_-]{1,64}$/;
|
|
29
|
+
|
|
30
|
+
// src/domain/roomCreate.ts
|
|
31
|
+
var roomCreateSchema = {
|
|
32
|
+
type: { type: "string", required: true, min: 1 },
|
|
33
|
+
roomId: { type: "string", pattern: ROOM_ID_PATTERN.source },
|
|
34
|
+
placement: { type: "object" }
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// src/domain/errors.ts
|
|
38
|
+
var import_node = require("@toolcase/node");
|
|
39
|
+
var CODE_TO_STATUS = {
|
|
40
|
+
VALIDATION: 400,
|
|
41
|
+
UNAUTHORIZED: 401,
|
|
42
|
+
INSTANCE_NOT_FOUND: 404,
|
|
43
|
+
ROOM_NOT_FOUND: 404,
|
|
44
|
+
NO_CANDIDATE: 409,
|
|
45
|
+
ROOM_EXISTS: 409,
|
|
46
|
+
INSTANCE_DRAINING: 409,
|
|
47
|
+
PAYLOAD_TOO_LARGE: 413,
|
|
48
|
+
INSTANCE_BUSY: 429,
|
|
49
|
+
AUTH_THROTTLED: 429,
|
|
50
|
+
SSE_LIMIT: 429,
|
|
51
|
+
COMMAND_FAILED: 502,
|
|
52
|
+
INSTANCE_DISCONNECTED: 502,
|
|
53
|
+
COMMAND_TIMEOUT: 504
|
|
54
|
+
};
|
|
55
|
+
var FleetError = class extends import_node.EndpointError {
|
|
56
|
+
constructor(code, message) {
|
|
57
|
+
super(CODE_TO_STATUS[code], code, message);
|
|
58
|
+
this.name = "FleetError";
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// src/orchestrator/FleetControl.ts
|
|
63
|
+
var FleetControl = class {
|
|
64
|
+
constructor(state, commands, getLink) {
|
|
65
|
+
this.state = state;
|
|
66
|
+
this.commands = commands;
|
|
67
|
+
this.getLink = getLink;
|
|
68
|
+
}
|
|
69
|
+
state;
|
|
70
|
+
commands;
|
|
71
|
+
getLink;
|
|
72
|
+
/** Place a new room and push an acknowledged `create` command (§9 command flow). */
|
|
73
|
+
async createRoom(request) {
|
|
74
|
+
const roomIdReservation = this.state.reserveRoomId(request.roomId);
|
|
75
|
+
let placement;
|
|
76
|
+
try {
|
|
77
|
+
placement = this.state.place({ type: request.type, ...request.placement ?? {} });
|
|
78
|
+
} catch (error) {
|
|
79
|
+
this.state.releaseRoomId(roomIdReservation);
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
const link = this.getLink(placement.instance.id);
|
|
83
|
+
if (link === void 0) {
|
|
84
|
+
this.state.release(placement.reservation);
|
|
85
|
+
this.state.releaseRoomId(roomIdReservation);
|
|
86
|
+
throw new FleetError("INSTANCE_DISCONNECTED", `instance ${placement.instance.id} is no longer connected`);
|
|
87
|
+
}
|
|
88
|
+
const cmd = {
|
|
89
|
+
cmdId: this.commands.nextCmdId(),
|
|
90
|
+
op: "create",
|
|
91
|
+
roomId: roomIdReservation.roomId,
|
|
92
|
+
roomType: request.type
|
|
93
|
+
};
|
|
94
|
+
await this.commands.send(link, cmd, placement.reservation, roomIdReservation);
|
|
95
|
+
return {
|
|
96
|
+
id: roomIdReservation.roomId,
|
|
97
|
+
type: request.type,
|
|
98
|
+
connections: 0,
|
|
99
|
+
instanceId: placement.instance.id,
|
|
100
|
+
endpointUrl: placement.instance.endpointUrl,
|
|
101
|
+
local: false
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/** Destroy a room by its fleet-unique public id; the orchestrator resolves the owner (§9, §10). */
|
|
105
|
+
async destroyRoom(roomId) {
|
|
106
|
+
const located = this.state.resolveRoom(roomId);
|
|
107
|
+
if (located === null) {
|
|
108
|
+
throw new FleetError("ROOM_NOT_FOUND", `room ${roomId} not found`);
|
|
109
|
+
}
|
|
110
|
+
const link = this.getLink(located.instanceId);
|
|
111
|
+
if (link === void 0) {
|
|
112
|
+
throw new FleetError("INSTANCE_DISCONNECTED", `instance ${located.instanceId} is no longer connected`);
|
|
113
|
+
}
|
|
114
|
+
await this.commands.send(link, { cmdId: this.commands.nextCmdId(), op: "destroy", roomId: located.rawRoomId });
|
|
115
|
+
}
|
|
116
|
+
/** Ask an instance to drain via `fleet/cmd {op:'drain'}` — the agent owns status (§7). */
|
|
117
|
+
drainInstance(instanceId) {
|
|
118
|
+
return this.sendStatusCommand(instanceId, "drain");
|
|
119
|
+
}
|
|
120
|
+
/** Reverse of {@link drainInstance}. */
|
|
121
|
+
undrainInstance(instanceId) {
|
|
122
|
+
return this.sendStatusCommand(instanceId, "undrain");
|
|
123
|
+
}
|
|
124
|
+
async sendStatusCommand(instanceId, op) {
|
|
125
|
+
if (this.state.getInstance(instanceId) === null) {
|
|
126
|
+
throw new FleetError("INSTANCE_NOT_FOUND", `instance ${instanceId} not found`);
|
|
127
|
+
}
|
|
128
|
+
const link = this.getLink(instanceId);
|
|
129
|
+
if (link === void 0) {
|
|
130
|
+
throw new FleetError("INSTANCE_DISCONNECTED", `instance ${instanceId} is no longer connected`);
|
|
131
|
+
}
|
|
132
|
+
await this.commands.send(link, { cmdId: this.commands.nextCmdId(), op });
|
|
133
|
+
this.state.setPendingStatus(instanceId, op === "drain" ? "draining" : "active");
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
137
|
+
0 && (module.exports = {
|
|
138
|
+
FleetControl
|
|
139
|
+
});
|