@memrov2/pentcloud-tool-runtime 0.1.0 → 0.1.1-dev.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/package.json +1 -1
- package/src/worker.d.mts +2 -0
- package/src/worker.mjs +13 -8
package/package.json
CHANGED
package/src/worker.d.mts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { DurableObject } from "cloudflare:workers";
|
|
2
2
|
import type { ToolCommand, ToolResult, PackLock } from "./index.mjs";
|
|
3
3
|
declare class ToolRunner<I> extends DurableObject {
|
|
4
|
+
ready(): Promise<{ image: string; instance: "lite" | "standard-1"; readyMs: number }>;
|
|
4
5
|
run(input: I, files?: Record<string, Uint8Array>): Promise<ToolResult>;
|
|
6
|
+
retire(): Promise<{ stopped: boolean; retired: true }>;
|
|
5
7
|
stop(): Promise<{ stopped: boolean }>;
|
|
6
8
|
capabilities(): Promise<{
|
|
7
9
|
platform: string;
|
package/src/worker.mjs
CHANGED
|
@@ -34,6 +34,7 @@ export function createRunner(lock, buildCommand) {
|
|
|
34
34
|
return result;
|
|
35
35
|
}
|
|
36
36
|
async #ready() {
|
|
37
|
+
if (await this.ctx.storage.get("retired")) throw new Error("Owned tool runtime is retired");
|
|
37
38
|
const container = this.ctx.container,
|
|
38
39
|
image = container.images[lock.packId],
|
|
39
40
|
start = Date.now();
|
|
@@ -47,13 +48,7 @@ export function createRunner(lock, buildCommand) {
|
|
|
47
48
|
} else
|
|
48
49
|
container.start({
|
|
49
50
|
image,
|
|
50
|
-
instance:
|
|
51
|
-
vcpu: lock.runtime?.vcpu ?? 1,
|
|
52
|
-
memoryMib:
|
|
53
|
-
lock.runtime?.memoryMib ??
|
|
54
|
-
(lock.packId === "nuclei" ? 1024 : 512),
|
|
55
|
-
diskMb: lock.runtime?.diskMb ?? 2000,
|
|
56
|
-
},
|
|
51
|
+
instance: lock.packId === "password" ? "standard-1" : "lite",
|
|
57
52
|
enableInternet: lock.runtime?.enableInternet ?? true,
|
|
58
53
|
labels: { pack: lock.packId, version: lock.packVersion },
|
|
59
54
|
});
|
|
@@ -92,7 +87,10 @@ export function createRunner(lock, buildCommand) {
|
|
|
92
87
|
throw new Error("Pack image and SDK pins do not match");
|
|
93
88
|
if ((await container.inspect())?.image !== image)
|
|
94
89
|
throw new Error("Unable to verify pack image identity");
|
|
95
|
-
return { image, readyMs: Date.now() - start };
|
|
90
|
+
return { image, instance: lock.packId === "password" ? "standard-1" : "lite", readyMs: Date.now() - start };
|
|
91
|
+
}
|
|
92
|
+
ready() {
|
|
93
|
+
return this.#serialize(() => this.#ready());
|
|
96
94
|
}
|
|
97
95
|
run(input, files) {
|
|
98
96
|
const { requiredFiles = [], ...command } = buildCommand(input),
|
|
@@ -140,6 +138,13 @@ export function createRunner(lock, buildCommand) {
|
|
|
140
138
|
};
|
|
141
139
|
});
|
|
142
140
|
}
|
|
141
|
+
retire() {
|
|
142
|
+
return this.#serialize(async () => {
|
|
143
|
+
await this.ctx.storage.put("retired", true);
|
|
144
|
+
if (this.ctx.container.running) await this.ctx.container.destroy();
|
|
145
|
+
return { stopped: !this.ctx.container.running, retired: true };
|
|
146
|
+
});
|
|
147
|
+
}
|
|
143
148
|
stop() {
|
|
144
149
|
return this.#serialize(async () => {
|
|
145
150
|
if (this.ctx.container.running) await this.ctx.container.destroy();
|