@ultrst-armada/kloks 2.2.6 → 2.2.7
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/.krusbl-release-attestation.json +3 -3
- package/package.json +1 -1
- package/packages/backend/dist/{chunk-5SKQBVYU.js → chunk-AMI5MY6E.js} +2 -2
- package/packages/backend/dist/{chunk-4LRMJIJ4.js → chunk-FFQJ4USX.js} +1 -1
- package/packages/backend/dist/chunk-G6FLQJS6.js +496 -0
- package/packages/backend/dist/{chunk-4NTZRTRY.js → chunk-GIUAFRAA.js} +1 -1
- package/packages/backend/dist/{chunk-OJCSPAFE.js → chunk-GZTZ376X.js} +1 -1
- package/packages/backend/dist/{chunk-4BCTI7BL.js → chunk-LAKCKX3I.js} +1 -1
- package/packages/backend/dist/{chunk-YTJTF7LS.js → chunk-LPM5E2A2.js} +2 -2
- package/packages/backend/dist/{chunk-5S5CDQXD.js → chunk-MQ6AHJ6X.js} +2 -2
- package/packages/backend/dist/{chunk-2DVRZKOK.js → chunk-QZDTABQX.js} +2 -2
- package/packages/backend/dist/{chunk-3V5B2BOP.js → chunk-RHW75K46.js} +1 -1
- package/packages/backend/dist/{chunk-FGZA6PDX.js → chunk-U5VPYALB.js} +4 -4
- package/packages/backend/dist/chunk-UI7AYFAU.js +364 -0
- package/packages/backend/dist/{client-S4R4MZ6K.js → client-R5FY5AP7.js} +2 -2
- package/packages/backend/dist/index.js +38 -12
- package/packages/backend/dist/krnl-services.js +2 -2
- package/packages/backend/dist/node.js +32 -32
- package/packages/backend/dist/provider-services/compute-routing.d.ts +65 -0
- package/packages/backend/dist/provider-services/compute-routing.test.d.ts +1 -0
- package/packages/backend/dist/provider-services/fly-machines.d.ts +52 -0
- package/packages/backend/dist/provider-services/fly-machines.test.d.ts +1 -0
- package/packages/backend/dist/provider-services/free-compute.d.ts +5 -0
- package/packages/backend/dist/provider-services/free-compute.test.d.ts +1 -0
- package/packages/backend/dist/provider-services/google/cloud-run.js +1 -1
- package/packages/backend/dist/provider-services/google/cloud-shell.js +1 -1
- package/packages/backend/dist/provider-services/google/cloud-storage.js +1 -1
- package/packages/backend/dist/provider-services/google/drive.js +1 -1
- package/packages/backend/dist/provider-services/google/gemini.js +3 -3
- package/packages/backend/dist/provider-services/google/index.js +3 -3
- package/packages/backend/dist/provider-services/google/vertex-ai.js +1 -1
- package/packages/backend/dist/provider-services/index.d.ts +3 -0
- package/packages/backend/dist/provider-services/index.js +39 -13
- package/packages/backend/dist/provider-services/node.js +11 -11
- package/packages/backend/dist/provider-services/storage/dropbox.js +4 -4
- package/packages/backend/dist/provider-services/storage/github.js +4 -4
- package/packages/backend/dist/provider-services/storage/node.js +7 -7
- package/packages/backend/dist/provider-services/storage.js +6 -6
- package/packages/backend/dist/provider-services/types.d.ts +16 -2
- package/packages/state-graph/dist/browser.js +24 -24
- package/packages/state-graph/dist/index.js +24 -24
- package/packages/backend/dist/chunk-FFYTCLFC.js +0 -93
- package/packages/backend/dist/chunk-LN274IE5.js +0 -414
- package/packages/backend/dist/{chunk-5CZUAEAD.js → chunk-R4B3KPHY.js} +5 -5
- package/packages/state-graph/dist/{chunk-YUJC367F.js → chunk-UKTICGGV.js} +3 -3
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
continueDropboxFolder,
|
|
3
3
|
listDropboxFolder
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-AMI5MY6E.js";
|
|
5
5
|
import {
|
|
6
6
|
normalizeStoragePath
|
|
7
7
|
} from "./chunk-HJE4CVKY.js";
|
|
@@ -59,7 +59,7 @@ function createDropboxStorageService(connection, transport = fetch) {
|
|
|
59
59
|
async delete(path) {
|
|
60
60
|
const target = toDropboxPath(path);
|
|
61
61
|
if (!target) throw new Error("Refusing to delete the Dropbox root");
|
|
62
|
-
const { createProviderClient } = await import("./client-
|
|
62
|
+
const { createProviderClient } = await import("./client-R5FY5AP7.js");
|
|
63
63
|
await createProviderClient(connection, transport).request({
|
|
64
64
|
path: "/2/files/delete_v2",
|
|
65
65
|
method: "POST",
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
fetchCloudflareCapacity,
|
|
3
3
|
fetchVercelCapacity
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-RHW75K46.js";
|
|
5
5
|
import {
|
|
6
6
|
getGeminiQuotaStatus,
|
|
7
7
|
listGeminiModels
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-GIUAFRAA.js";
|
|
9
9
|
import {
|
|
10
10
|
getGoogleAccountProfile,
|
|
11
11
|
listCloudflareAccounts,
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
listCloudflareWorkers,
|
|
14
14
|
listVercelDeployments,
|
|
15
15
|
listVercelProjects
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-LAKCKX3I.js";
|
|
17
17
|
import {
|
|
18
18
|
continueDropboxFolder,
|
|
19
19
|
listDropboxFolder,
|
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
listGitHubRepositoryContents,
|
|
22
22
|
listGitLabProjects,
|
|
23
23
|
listGitLabRepositoryTree
|
|
24
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-AMI5MY6E.js";
|
|
25
25
|
import {
|
|
26
26
|
b2ListBuckets,
|
|
27
27
|
b2ListFileNames
|
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createProviderClient
|
|
3
|
+
} from "./chunk-MQ6AHJ6X.js";
|
|
4
|
+
|
|
5
|
+
// src/provider-services/capacity.ts
|
|
6
|
+
function calculateProviderCapacity(snapshot, now = /* @__PURE__ */ new Date(), maxAgeMs = 10 * 6e4) {
|
|
7
|
+
const checkedAt = now.toISOString();
|
|
8
|
+
const unknown = (reason) => ({ status: "unknown", weight: 0, percentRemaining: null, bottleneck: null, reason, checkedAt });
|
|
9
|
+
const timestamp = Date.parse(snapshot.capturedAt);
|
|
10
|
+
if (!Number.isFinite(timestamp) || now.getTime() < timestamp - 3e4 || now.getTime() - timestamp > maxAgeMs) return unknown("Telemetry is stale or undated");
|
|
11
|
+
if (snapshot.error || snapshot.coverage === "unavailable") {
|
|
12
|
+
return unknown(snapshot.error || "Provider quota telemetry unavailable");
|
|
13
|
+
}
|
|
14
|
+
const enforced = snapshot.metrics.filter((m) => m.enforceable);
|
|
15
|
+
if (!enforced.length) return unknown("No provider-confirmed renewable quota windows");
|
|
16
|
+
if (snapshot.coverage !== "complete") return unknown("Required quota coverage is incomplete");
|
|
17
|
+
let bottleneck = null;
|
|
18
|
+
let minimum = 1;
|
|
19
|
+
for (const metric of enforced) {
|
|
20
|
+
if (metric.source !== "provider" || !validQuota(metric) || !metric.resetAt || Date.parse(metric.resetAt) <= now.getTime()) {
|
|
21
|
+
return unknown("Quota metric missing, estimated, or outside its reset window: " + metric.id);
|
|
22
|
+
}
|
|
23
|
+
const remaining = Math.max(0, Math.min(1, (metric.limit - metric.used) / metric.limit));
|
|
24
|
+
if (!bottleneck || remaining < minimum) {
|
|
25
|
+
minimum = remaining;
|
|
26
|
+
bottleneck = metric;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const status = minimum === 0 ? "exhausted" : "eligible";
|
|
30
|
+
return {
|
|
31
|
+
status,
|
|
32
|
+
weight: status === "eligible" ? Number(minimum.toFixed(4)) : 0,
|
|
33
|
+
percentRemaining: Math.round(minimum * 100),
|
|
34
|
+
bottleneck: bottleneck?.id ?? null,
|
|
35
|
+
reason: status === "eligible" ? "Provider-measured quota remaining" : "A required quota is exhausted",
|
|
36
|
+
checkedAt
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function validQuota(metric) {
|
|
40
|
+
return metric.used !== null && metric.limit !== null && Number.isFinite(metric.used) && Number.isFinite(metric.limit) && metric.used >= 0 && metric.limit > 0 && typeof metric.resetAt === "string" && Number.isFinite(Date.parse(metric.resetAt));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// src/provider-services/compute-operations.ts
|
|
44
|
+
function connectionFor(input, expected) {
|
|
45
|
+
if (input.providerId !== expected) throw new Error("Credential/provider mismatch");
|
|
46
|
+
return input;
|
|
47
|
+
}
|
|
48
|
+
function requiredProject(input, name, pattern) {
|
|
49
|
+
if (!pattern.test(input)) throw new Error("Invalid " + name);
|
|
50
|
+
return input;
|
|
51
|
+
}
|
|
52
|
+
async function getRailwayAccount(connection, transport = fetch) {
|
|
53
|
+
const client = createProviderClient(connectionFor(connection, "railway"), transport);
|
|
54
|
+
const { data } = await client.request({
|
|
55
|
+
path: "/graphql/v2",
|
|
56
|
+
method: "POST",
|
|
57
|
+
body: { query: "query FrnesIdentity { me { name email } }" }
|
|
58
|
+
});
|
|
59
|
+
if (data.errors?.length || !data.data?.me || typeof data.data.me !== "object" || !(typeof data.data.me.email === "string" && data.data.me.email.trim() || typeof data.data.me.name === "string" && data.data.me.name.trim()))
|
|
60
|
+
throw new Error("Railway account token could not be authorized");
|
|
61
|
+
return data.data.me;
|
|
62
|
+
}
|
|
63
|
+
async function listFlyApps(connection, transport = fetch) {
|
|
64
|
+
const client = createProviderClient(connectionFor(connection, "fly"), transport);
|
|
65
|
+
const { data } = await client.request({ path: "/v1/apps" });
|
|
66
|
+
if (!Array.isArray(data?.apps) || data.apps.some((item) => typeof item.name !== "string" || !item.name))
|
|
67
|
+
throw new Error("Invalid Fly Machines app listing");
|
|
68
|
+
return data.apps;
|
|
69
|
+
}
|
|
70
|
+
async function listRenderServices(connection, transport = fetch) {
|
|
71
|
+
const client = createProviderClient(connectionFor(connection, "render"), transport);
|
|
72
|
+
const { data } = await client.request({ path: "/v1/services", query: { limit: 20 } });
|
|
73
|
+
if (!Array.isArray(data) || data.some((item) => typeof item.service?.id !== "string" || !item.service.id || typeof item.service.name !== "string" || !item.service.name))
|
|
74
|
+
throw new Error("Invalid Render services response");
|
|
75
|
+
return data;
|
|
76
|
+
}
|
|
77
|
+
async function listGoogleCloudRunServices(connection, project, region, transport = fetch) {
|
|
78
|
+
connectionFor(connection, "google-cloud-run");
|
|
79
|
+
const projectId = requiredProject(project, "Google project ID", /^[a-z][a-z0-9-]{4,61}[a-z0-9]$/);
|
|
80
|
+
const location = requiredProject(region, "Google Cloud location", /^[a-z][a-z0-9-]{1,40}$/);
|
|
81
|
+
const { data } = await createProviderClient(connection, transport).request({ path: `/v2/projects/${projectId}/locations/${location}/services` });
|
|
82
|
+
if (!data || data.services !== void 0 && (!Array.isArray(data.services) || data.services.some((item) => typeof item.name !== "string" || !item.name)))
|
|
83
|
+
throw new Error("Invalid Cloud Run service listing");
|
|
84
|
+
return data.services || [];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// src/provider-services/compute-routing.ts
|
|
88
|
+
var COMPUTE_PROFILE_PRESETS = Object.freeze({
|
|
89
|
+
low: Object.freeze({ cpuVcpus: 1, memoryGiB: 1 }),
|
|
90
|
+
medium: Object.freeze({ cpuVcpus: 2, memoryGiB: 4 }),
|
|
91
|
+
high: Object.freeze({ cpuVcpus: 4, memoryGiB: 8 }),
|
|
92
|
+
ultra: Object.freeze({ cpuVcpus: 8, memoryGiB: 16 })
|
|
93
|
+
});
|
|
94
|
+
function validateComputeSpec(value) {
|
|
95
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
96
|
+
throw new Error("Compute spec must be an object");
|
|
97
|
+
const positive = (value2, name, min, max) => {
|
|
98
|
+
if (typeof value2 !== "number" || !Number.isFinite(value2) || value2 < min || value2 > max)
|
|
99
|
+
throw new Error("Invalid compute requirement: " + name);
|
|
100
|
+
return value2;
|
|
101
|
+
};
|
|
102
|
+
const cpuVcpus = positive(value.cpuVcpus, "cpuVcpus", 0.1, 4096);
|
|
103
|
+
const memoryGiB = positive(value.memoryGiB, "memoryGiB", 0.125, 65536);
|
|
104
|
+
const gpuCount = value.gpuCount === void 0 ? 0 : positive(value.gpuCount, "gpuCount", 0, 64);
|
|
105
|
+
if (!Number.isInteger(gpuCount)) throw new Error("GPU count must be an integer");
|
|
106
|
+
const gpuMemoryGiB = value.gpuMemoryGiB === void 0 ? 0 : positive(value.gpuMemoryGiB, "gpuMemoryGiB", 0, 4096);
|
|
107
|
+
if (gpuCount === 0 && gpuMemoryGiB > 0) throw new Error("GPU memory requires a GPU");
|
|
108
|
+
const diskGiB = value.diskGiB === void 0 ? 0 : positive(value.diskGiB, "diskGiB", 0, 1048576);
|
|
109
|
+
const workload = value.workload;
|
|
110
|
+
if (workload !== void 0 && !["vm", "container", "function", "gpu", "sandbox"].includes(workload))
|
|
111
|
+
throw new Error("Unsupported compute workload");
|
|
112
|
+
return { cpuVcpus, memoryGiB, gpuCount, gpuMemoryGiB, diskGiB, ...workload ? { workload } : {} };
|
|
113
|
+
}
|
|
114
|
+
function resolveComputeSpec(profile, custom) {
|
|
115
|
+
if (profile === "custom") {
|
|
116
|
+
if (!custom) throw new Error("Custom compute profile requires a specification");
|
|
117
|
+
return validateComputeSpec(custom);
|
|
118
|
+
}
|
|
119
|
+
if (!Object.prototype.hasOwnProperty.call(COMPUTE_PROFILE_PRESETS, profile))
|
|
120
|
+
throw new Error("Unknown compute profile");
|
|
121
|
+
return validateComputeSpec(COMPUTE_PROFILE_PRESETS[profile]);
|
|
122
|
+
}
|
|
123
|
+
function fit(required, available) {
|
|
124
|
+
let resource;
|
|
125
|
+
try {
|
|
126
|
+
resource = validateComputeSpec(available);
|
|
127
|
+
} catch {
|
|
128
|
+
return 0;
|
|
129
|
+
}
|
|
130
|
+
if (required.workload && resource.workload !== required.workload) return 0;
|
|
131
|
+
if (resource.cpuVcpus < required.cpuVcpus || resource.memoryGiB < required.memoryGiB || (resource.gpuCount ?? 0) < (required.gpuCount ?? 0) || (resource.gpuMemoryGiB ?? 0) < (required.gpuMemoryGiB ?? 0) || (resource.diskGiB ?? 0) < (required.diskGiB ?? 0)) return 0;
|
|
132
|
+
const cpuFit = required.cpuVcpus / resource.cpuVcpus;
|
|
133
|
+
const memFit = required.memoryGiB / resource.memoryGiB;
|
|
134
|
+
const gpuFit = !required.gpuCount && resource.gpuCount ? 0.5 : required.gpuCount ? required.gpuCount / (resource.gpuCount || 1) : 1;
|
|
135
|
+
return Math.max(0.01, Math.min(1, (cpuFit + memFit + gpuFit) / 3));
|
|
136
|
+
}
|
|
137
|
+
function rankComputeRoutes(request, resources, now = /* @__PURE__ */ new Date()) {
|
|
138
|
+
if (!request.ownerUserId?.trim() || !request.workspaceId?.trim())
|
|
139
|
+
throw new Error("An authenticated user and workspace are required");
|
|
140
|
+
if (!["exclude", "user-weight"].includes(request.missingUsage))
|
|
141
|
+
throw new Error("Missing-usage policy must be explicit");
|
|
142
|
+
if (request.exhaustedUsage !== void 0 && !["exclude", "user-weight"].includes(request.exhaustedUsage))
|
|
143
|
+
throw new Error("Invalid exhausted-quota policy");
|
|
144
|
+
if (request.allowAccountIds && (!Array.isArray(request.allowAccountIds) || request.allowAccountIds.some((id) => typeof id !== "string" || !id)))
|
|
145
|
+
throw new Error("Invalid account allowlist");
|
|
146
|
+
const requested = resolveComputeSpec(request.profile, request.customSpec);
|
|
147
|
+
const permittedIds = request.allowAccountIds && new Set(request.allowAccountIds);
|
|
148
|
+
const candidates = [];
|
|
149
|
+
const rejected = [];
|
|
150
|
+
const seen = /* @__PURE__ */ new Set();
|
|
151
|
+
for (const account of resources) {
|
|
152
|
+
if (account.ownerUserId !== request.ownerUserId || account.workspaceId !== request.workspaceId) continue;
|
|
153
|
+
if (permittedIds && !permittedIds.has(account.accountId)) continue;
|
|
154
|
+
const tag = { providerId: account.providerId, accountId: account.accountId, resourceId: account.resourceId };
|
|
155
|
+
const reject = (reason) => {
|
|
156
|
+
rejected.push({ ...tag, reason });
|
|
157
|
+
};
|
|
158
|
+
if (!account.providerId || !account.accountId || !account.resourceId || !account.enabled || !account.executable) {
|
|
159
|
+
reject("Provider runtime not available");
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
const key = [account.providerId, account.accountId, account.resourceId].join("\0");
|
|
163
|
+
if (seen.has(key)) {
|
|
164
|
+
reject("Duplicate resource");
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
seen.add(key);
|
|
168
|
+
const fitScore = fit(requested, account.capabilities);
|
|
169
|
+
if (!fitScore) {
|
|
170
|
+
reject("Compute capabilities below requested profile");
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
if (!Number.isFinite(account.preferenceWeight) || account.preferenceWeight < 0 || account.preferenceWeight > 100) {
|
|
174
|
+
reject("Invalid user account weight");
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
if (account.preferenceWeight === 0) {
|
|
178
|
+
reject("Disabled by user account weight");
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
let remainingFraction = null;
|
|
182
|
+
let exhaustedManualOverride = false;
|
|
183
|
+
let weightSource = "user-weight";
|
|
184
|
+
if (account.usage && account.usage.accountId === account.accountId && account.usage.providerId === account.providerId) {
|
|
185
|
+
const decision = calculateProviderCapacity(account.usage, now);
|
|
186
|
+
if (decision.status === "exhausted") {
|
|
187
|
+
if (request.exhaustedUsage !== "user-weight") {
|
|
188
|
+
reject("Provider-measured quota exhausted");
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
exhaustedManualOverride = true;
|
|
192
|
+
}
|
|
193
|
+
if (decision.status === "eligible") {
|
|
194
|
+
remainingFraction = decision.weight;
|
|
195
|
+
weightSource = "verified-usage";
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (remainingFraction === null && request.missingUsage === "exclude" && !exhaustedManualOverride) {
|
|
199
|
+
reject("Verified quota measurement unavailable");
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
const rawWeight = fitScore * account.preferenceWeight * (remainingFraction ?? 1);
|
|
203
|
+
if (!Number.isFinite(rawWeight) || rawWeight <= 0) {
|
|
204
|
+
reject("Account has no routing weight");
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
candidates.push({ ...tag, capabilityFit: fitScore, remainingFraction, weightSource, rawWeight, probability: 0 });
|
|
208
|
+
}
|
|
209
|
+
const sum = candidates.reduce((total, item) => total + item.rawWeight, 0);
|
|
210
|
+
const ranked = candidates.map(({ rawWeight, ...item }) => ({ ...item, probability: rawWeight / sum })).sort((a, b) => b.probability - a.probability || a.providerId.localeCompare(b.providerId) || a.accountId.localeCompare(b.accountId) || a.resourceId.localeCompare(b.resourceId));
|
|
211
|
+
return { requested, candidates: ranked, rejected };
|
|
212
|
+
}
|
|
213
|
+
function selectComputeRoute(ranking, selectionUnit) {
|
|
214
|
+
if (!Number.isFinite(selectionUnit) || selectionUnit < 0 || selectionUnit >= 1)
|
|
215
|
+
throw new Error("Selection unit must be between 0 inclusive and 1 exclusive");
|
|
216
|
+
let accumulated = 0;
|
|
217
|
+
for (const candidate of ranking.candidates) {
|
|
218
|
+
accumulated += candidate.probability;
|
|
219
|
+
if (selectionUnit < accumulated) return candidate;
|
|
220
|
+
}
|
|
221
|
+
return ranking.candidates.at(-1) ?? null;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// src/provider-services/fly-machines.ts
|
|
225
|
+
import { resolveTrustedApiUrl } from "@dinilmusick/gutts/urls/safety";
|
|
226
|
+
function flyConnection(connection) {
|
|
227
|
+
if (connection.providerId !== "fly") throw new Error("Fly machine credentials must belong to Fly");
|
|
228
|
+
return connection;
|
|
229
|
+
}
|
|
230
|
+
function identifier(value, label) {
|
|
231
|
+
if (typeof value !== "string" || !/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,62}$/.test(value))
|
|
232
|
+
throw new Error("Invalid Fly " + label);
|
|
233
|
+
return value;
|
|
234
|
+
}
|
|
235
|
+
function appPath(app) {
|
|
236
|
+
return "/v1/apps/" + identifier(app, "app name") + "/machines";
|
|
237
|
+
}
|
|
238
|
+
function machinePath(app, id) {
|
|
239
|
+
return appPath(app) + "/" + identifier(id, "machine ID");
|
|
240
|
+
}
|
|
241
|
+
function mapMachine(input, app) {
|
|
242
|
+
if (!input || typeof input !== "object") throw new Error("Invalid Fly Machine payload");
|
|
243
|
+
const data = input;
|
|
244
|
+
const guest = data.config?.guest;
|
|
245
|
+
if (typeof data.id !== "string" || !data.id || typeof data.state !== "string" || !data.state || !guest || !Number.isInteger(guest.cpus) || guest.cpus < 1 || guest.cpus > 4096 || !Number.isFinite(guest.memory_mb) || guest.memory_mb < 128 || guest.gpus !== void 0 && (!Number.isInteger(guest.gpus) || guest.gpus < 0))
|
|
246
|
+
throw new Error("Fly Machine configuration is incomplete");
|
|
247
|
+
return {
|
|
248
|
+
id: data.id,
|
|
249
|
+
app,
|
|
250
|
+
name: typeof data.name === "string" ? data.name : null,
|
|
251
|
+
state: data.state,
|
|
252
|
+
region: typeof data.region === "string" ? data.region : null,
|
|
253
|
+
cpuVcpus: guest.cpus,
|
|
254
|
+
memoryGiB: guest.memory_mb / 1024,
|
|
255
|
+
gpuCount: guest.gpus ?? 0
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
async function listFlyMachines(connection, app, transport = fetch) {
|
|
259
|
+
const { data } = await createProviderClient(flyConnection(connection), transport).request({ path: appPath(app) });
|
|
260
|
+
if (!Array.isArray(data)) throw new Error("Fly Machines inventory was not an array");
|
|
261
|
+
return data.map((item) => mapMachine(item, app));
|
|
262
|
+
}
|
|
263
|
+
async function getFlyMachine(connection, app, id, transport = fetch) {
|
|
264
|
+
const { data } = await createProviderClient(flyConnection(connection), transport).request({ path: machinePath(app, id) });
|
|
265
|
+
return mapMachine(data, app);
|
|
266
|
+
}
|
|
267
|
+
async function createFlyMachine(connection, input, transport = fetch) {
|
|
268
|
+
const path = appPath(input.app);
|
|
269
|
+
identifier(input.name, "machine name");
|
|
270
|
+
if (!/^[a-z]{3}$/.test(input.region) || !/^[A-Za-z0-9._/@:-]{3,240}$/.test(input.image) || !["shared", "performance"].includes(input.cpuKind) || !Number.isInteger(input.cpuVcpus) || input.cpuVcpus < 1 || input.cpuVcpus > 64 || !Number.isInteger(input.memoryMiB) || input.memoryMiB < 256 || input.memoryMiB > 262144)
|
|
271
|
+
throw new Error("Invalid Fly Machine resources or image");
|
|
272
|
+
const body = { name: input.name, region: input.region, config: {
|
|
273
|
+
image: input.image,
|
|
274
|
+
guest: {
|
|
275
|
+
cpu_kind: input.cpuKind,
|
|
276
|
+
cpus: input.cpuVcpus,
|
|
277
|
+
memory_mb: input.memoryMiB
|
|
278
|
+
}
|
|
279
|
+
} };
|
|
280
|
+
const { data } = await createProviderClient(flyConnection(connection), transport).request({ path, method: "POST", body });
|
|
281
|
+
return mapMachine(data, input.app);
|
|
282
|
+
}
|
|
283
|
+
async function mutateFlyMachine(connection, app, id, operation, transport = fetch) {
|
|
284
|
+
if (!["start", "stop", "delete"].includes(operation)) throw new Error("Invalid Fly operation");
|
|
285
|
+
const path = machinePath(app, id) + (operation === "delete" ? "" : "/" + operation);
|
|
286
|
+
await createProviderClient(flyConnection(connection), transport).request({
|
|
287
|
+
path,
|
|
288
|
+
method: operation === "delete" ? "DELETE" : "POST"
|
|
289
|
+
});
|
|
290
|
+
return { accepted: true, app, id, operation };
|
|
291
|
+
}
|
|
292
|
+
async function invokeFlyMachineHttp(input, transport = fetch) {
|
|
293
|
+
const app = identifier(input.app, "app name");
|
|
294
|
+
const machineId = identifier(input.machineId, "machine ID");
|
|
295
|
+
if (typeof input.path !== "string" || input.path.length > 512 || !input.path.startsWith("/") || input.path.startsWith("//") || !/^[\x20-\x7e]*$/.test(input.path))
|
|
296
|
+
throw new Error("Invalid Fly application path");
|
|
297
|
+
if (!["GET", "POST"].includes(input.method) || input.method === "GET" && input.payload !== void 0)
|
|
298
|
+
throw new Error("Invalid Fly HTTP method or request");
|
|
299
|
+
if (input.appAuthorization !== void 0 && (typeof input.appAuthorization !== "string" || input.appAuthorization.length > 4096 || /[\r\n]/.test(input.appAuthorization)))
|
|
300
|
+
throw new Error("Invalid application authorization");
|
|
301
|
+
const payload = input.payload === void 0 ? void 0 : JSON.stringify(input.payload);
|
|
302
|
+
if (payload !== void 0 && new TextEncoder().encode(payload).byteLength > 131072)
|
|
303
|
+
throw new Error("Fly request exceeds the allowed size");
|
|
304
|
+
const target = resolveTrustedApiUrl("https://" + app + ".fly.dev", input.path);
|
|
305
|
+
const headers = {
|
|
306
|
+
Accept: "application/json",
|
|
307
|
+
"Fly-Force-Instance-Id": machineId,
|
|
308
|
+
...payload === void 0 ? {} : { "Content-Type": "application/json" },
|
|
309
|
+
...input.appAuthorization ? { Authorization: input.appAuthorization } : {}
|
|
310
|
+
};
|
|
311
|
+
const response = await transport(target.toString(), {
|
|
312
|
+
method: input.method,
|
|
313
|
+
headers,
|
|
314
|
+
body: payload,
|
|
315
|
+
redirect: "error",
|
|
316
|
+
signal: AbortSignal.timeout(15e3)
|
|
317
|
+
});
|
|
318
|
+
const limit = 131072;
|
|
319
|
+
const reader = response.body?.getReader();
|
|
320
|
+
if (!reader) return { status: response.status, contentType: response.headers.get("content-type") || "", body: "" };
|
|
321
|
+
const chunks = [];
|
|
322
|
+
let size = 0;
|
|
323
|
+
try {
|
|
324
|
+
for (; ; ) {
|
|
325
|
+
const part = await reader.read();
|
|
326
|
+
if (part.done) break;
|
|
327
|
+
size += part.value.byteLength;
|
|
328
|
+
if (size > limit) throw new Error("Fly response exceeds the allowed size");
|
|
329
|
+
chunks.push(part.value);
|
|
330
|
+
}
|
|
331
|
+
} finally {
|
|
332
|
+
if (size > limit) await reader.cancel().catch(() => void 0);
|
|
333
|
+
reader.releaseLock();
|
|
334
|
+
}
|
|
335
|
+
const bytes = new Uint8Array(size);
|
|
336
|
+
let position = 0;
|
|
337
|
+
for (const chunk of chunks) {
|
|
338
|
+
bytes.set(chunk, position);
|
|
339
|
+
position += chunk.byteLength;
|
|
340
|
+
}
|
|
341
|
+
return {
|
|
342
|
+
status: response.status,
|
|
343
|
+
contentType: response.headers.get("content-type") || "",
|
|
344
|
+
body: new TextDecoder("utf-8", { fatal: true }).decode(bytes)
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
export {
|
|
349
|
+
calculateProviderCapacity,
|
|
350
|
+
getRailwayAccount,
|
|
351
|
+
listFlyApps,
|
|
352
|
+
listRenderServices,
|
|
353
|
+
listGoogleCloudRunServices,
|
|
354
|
+
COMPUTE_PROFILE_PRESETS,
|
|
355
|
+
validateComputeSpec,
|
|
356
|
+
resolveComputeSpec,
|
|
357
|
+
rankComputeRoutes,
|
|
358
|
+
selectComputeRoute,
|
|
359
|
+
listFlyMachines,
|
|
360
|
+
getFlyMachine,
|
|
361
|
+
createFlyMachine,
|
|
362
|
+
mutateFlyMachine,
|
|
363
|
+
invokeFlyMachineHttp
|
|
364
|
+
};
|
|
@@ -2,12 +2,22 @@ import "./chunk-GVMVYC6C.js";
|
|
|
2
2
|
import "./chunk-2Y2EXYDK.js";
|
|
3
3
|
import "./chunk-RABSY2JU.js";
|
|
4
4
|
import {
|
|
5
|
+
COMPUTE_PROFILE_PRESETS,
|
|
5
6
|
calculateProviderCapacity,
|
|
7
|
+
createFlyMachine,
|
|
8
|
+
getFlyMachine,
|
|
6
9
|
getRailwayAccount,
|
|
10
|
+
invokeFlyMachineHttp,
|
|
7
11
|
listFlyApps,
|
|
12
|
+
listFlyMachines,
|
|
8
13
|
listGoogleCloudRunServices,
|
|
9
|
-
listRenderServices
|
|
10
|
-
|
|
14
|
+
listRenderServices,
|
|
15
|
+
mutateFlyMachine,
|
|
16
|
+
rankComputeRoutes,
|
|
17
|
+
resolveComputeSpec,
|
|
18
|
+
selectComputeRoute,
|
|
19
|
+
validateComputeSpec
|
|
20
|
+
} from "./chunk-UI7AYFAU.js";
|
|
11
21
|
import "./chunk-DAG2L4RN.js";
|
|
12
22
|
import {
|
|
13
23
|
isSecretMasked,
|
|
@@ -23,11 +33,11 @@ import {
|
|
|
23
33
|
import {
|
|
24
34
|
fetchCloudflareCapacity,
|
|
25
35
|
fetchVercelCapacity
|
|
26
|
-
} from "./chunk-
|
|
36
|
+
} from "./chunk-RHW75K46.js";
|
|
27
37
|
import {
|
|
28
38
|
getGeminiQuotaStatus,
|
|
29
39
|
listGeminiModels
|
|
30
|
-
} from "./chunk-
|
|
40
|
+
} from "./chunk-GIUAFRAA.js";
|
|
31
41
|
import {
|
|
32
42
|
getGoogleAccountProfile,
|
|
33
43
|
listCloudflareAccounts,
|
|
@@ -35,21 +45,21 @@ import {
|
|
|
35
45
|
listCloudflareWorkers,
|
|
36
46
|
listVercelDeployments,
|
|
37
47
|
listVercelProjects
|
|
38
|
-
} from "./chunk-
|
|
48
|
+
} from "./chunk-LAKCKX3I.js";
|
|
39
49
|
import {
|
|
40
50
|
createCanonicalStorageService,
|
|
41
51
|
getCanonicalStorageCapabilities,
|
|
42
52
|
listCanonicalStorageProviders
|
|
43
|
-
} from "./chunk-
|
|
53
|
+
} from "./chunk-LPM5E2A2.js";
|
|
44
54
|
import {
|
|
45
55
|
createBackblazeB2StorageService
|
|
46
56
|
} from "./chunk-O25T5KCE.js";
|
|
47
57
|
import {
|
|
48
58
|
createDropboxStorageService
|
|
49
|
-
} from "./chunk-
|
|
59
|
+
} from "./chunk-QZDTABQX.js";
|
|
50
60
|
import {
|
|
51
61
|
createGitHubStorageService
|
|
52
|
-
} from "./chunk-
|
|
62
|
+
} from "./chunk-FFQJ4USX.js";
|
|
53
63
|
import {
|
|
54
64
|
continueDropboxFolder,
|
|
55
65
|
listDropboxFolder,
|
|
@@ -57,7 +67,7 @@ import {
|
|
|
57
67
|
listGitHubRepositoryContents,
|
|
58
68
|
listGitLabProjects,
|
|
59
69
|
listGitLabRepositoryTree
|
|
60
|
-
} from "./chunk-
|
|
70
|
+
} from "./chunk-AMI5MY6E.js";
|
|
61
71
|
import {
|
|
62
72
|
createGoogleDriveStorageService
|
|
63
73
|
} from "./chunk-CTBVXX5C.js";
|
|
@@ -69,16 +79,19 @@ import {
|
|
|
69
79
|
} from "./chunk-HJE4CVKY.js";
|
|
70
80
|
import {
|
|
71
81
|
createProviderClient
|
|
72
|
-
} from "./chunk-
|
|
82
|
+
} from "./chunk-MQ6AHJ6X.js";
|
|
73
83
|
import {
|
|
84
|
+
getFreeComputeOffer,
|
|
74
85
|
getProviderService,
|
|
75
86
|
getProviderServicePath,
|
|
87
|
+
listFreeComputeOffers,
|
|
76
88
|
listProviderServiceChildren,
|
|
77
89
|
listProviderServiceTree,
|
|
78
90
|
listProviderServices,
|
|
79
91
|
listRecognizedAccountServices,
|
|
80
|
-
resolveProviderServiceId
|
|
81
|
-
|
|
92
|
+
resolveProviderServiceId,
|
|
93
|
+
supplementalComputeProviders
|
|
94
|
+
} from "./chunk-G6FLQJS6.js";
|
|
82
95
|
import {
|
|
83
96
|
BaseApiRoute,
|
|
84
97
|
createSSEResponse,
|
|
@@ -144,6 +157,7 @@ export {
|
|
|
144
157
|
BackendResolver,
|
|
145
158
|
BaseApiRoute,
|
|
146
159
|
BaseStorageAdapter,
|
|
160
|
+
COMPUTE_PROFILE_PRESETS,
|
|
147
161
|
CallbackRegistry,
|
|
148
162
|
LuthAuthClient2 as CanonicalAuthClient,
|
|
149
163
|
ConcurrencyConflictError,
|
|
@@ -183,6 +197,7 @@ export {
|
|
|
183
197
|
createDropboxStorageService,
|
|
184
198
|
createEmptyContract,
|
|
185
199
|
createFacadeInvocationBoundary,
|
|
200
|
+
createFlyMachine,
|
|
186
201
|
createGitHubStorageService,
|
|
187
202
|
createGoogleDriveStorageService,
|
|
188
203
|
createLuthAuthClient,
|
|
@@ -192,11 +207,14 @@ export {
|
|
|
192
207
|
fetchCloudflareCapacity,
|
|
193
208
|
fetchVercelCapacity,
|
|
194
209
|
getCanonicalStorageCapabilities,
|
|
210
|
+
getFlyMachine,
|
|
211
|
+
getFreeComputeOffer,
|
|
195
212
|
getGeminiQuotaStatus,
|
|
196
213
|
getGoogleAccountProfile,
|
|
197
214
|
getProviderService,
|
|
198
215
|
getProviderServicePath,
|
|
199
216
|
getRailwayAccount,
|
|
217
|
+
invokeFlyMachineHttp,
|
|
200
218
|
isSecretMasked,
|
|
201
219
|
b2ListBuckets as listBackblazeB2Buckets,
|
|
202
220
|
b2ListFileNames as listBackblazeB2Files,
|
|
@@ -206,6 +224,8 @@ export {
|
|
|
206
224
|
listCloudflareWorkers,
|
|
207
225
|
listDropboxFolder,
|
|
208
226
|
listFlyApps,
|
|
227
|
+
listFlyMachines,
|
|
228
|
+
listFreeComputeOffers,
|
|
209
229
|
listGeminiModels,
|
|
210
230
|
listGitHubRepositories,
|
|
211
231
|
listGitHubRepositoryContents,
|
|
@@ -219,18 +239,24 @@ export {
|
|
|
219
239
|
listRenderServices,
|
|
220
240
|
listVercelDeployments,
|
|
221
241
|
listVercelProjects,
|
|
242
|
+
mutateFlyMachine,
|
|
222
243
|
normalizeBackblazeCredentials,
|
|
223
244
|
normalizeStoragePath,
|
|
224
245
|
normalizeSystemEnvironment,
|
|
246
|
+
rankComputeRoutes,
|
|
225
247
|
readOnlyService,
|
|
226
248
|
resolveBackblazeEndpoint,
|
|
227
249
|
resolveClientEnvironment,
|
|
228
250
|
resolveClientOrigin,
|
|
251
|
+
resolveComputeSpec,
|
|
229
252
|
resolveProviderServiceId,
|
|
230
253
|
resolveSystemDatabaseUrl,
|
|
231
254
|
resolveSystemDatabaseUrlCandidates,
|
|
255
|
+
selectComputeRoute,
|
|
256
|
+
supplementalComputeProviders,
|
|
232
257
|
tryResolveSystemDatabaseUrl,
|
|
233
258
|
b2UploadFile as uploadBackblazeB2File,
|
|
259
|
+
validateComputeSpec,
|
|
234
260
|
withAuth,
|
|
235
261
|
withCors
|
|
236
262
|
};
|
|
@@ -27,11 +27,11 @@ import {
|
|
|
27
27
|
krnlStorageServiceFacade,
|
|
28
28
|
krnlWorkspaceServiceDefinition,
|
|
29
29
|
krnlWorkspaceServiceFacade
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-R4B3KPHY.js";
|
|
31
31
|
import "./chunk-FZKBTF34.js";
|
|
32
|
-
import "./chunk-IRKJ6HKP.js";
|
|
33
32
|
import "./chunk-7XTURV44.js";
|
|
34
33
|
import "./chunk-GCVR257U.js";
|
|
34
|
+
import "./chunk-IRKJ6HKP.js";
|
|
35
35
|
import "./chunk-3ZL2DX73.js";
|
|
36
36
|
import "./chunk-3RTRATDJ.js";
|
|
37
37
|
import "./chunk-2COYZMUJ.js";
|