bugxhunter 0.8.7 → 0.9.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.
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Diagrams for the Playground: a diagram spec a model wrote (drawgen's YAML/JSON format)
3
+ * becomes an editable .drawio.svg. The work happens in the separate `render` service
4
+ * (docker/render.Dockerfile), so model output is never parsed in the process that holds
5
+ * the vault key. Without OPEN_RUNNER_RENDER_URL (e.g. outside Docker) rendering is off
6
+ * and the UI shows the spec as code.
7
+ */
8
+ import { httpError } from "./errors.js";
9
+ export const RENDER_URL = (process.env.OPEN_RUNNER_RENDER_URL ?? "").replace(/\/+$/, "");
10
+ export const MAX_SPEC = 200 * 1024;
11
+ export const enabled = () => Boolean(RENDER_URL);
12
+ export async function status() {
13
+ if (!RENDER_URL)
14
+ return { enabled: false, ok: false };
15
+ try {
16
+ const r = await fetch(`${RENDER_URL}/health`, { signal: AbortSignal.timeout(3000) });
17
+ const j = (await r.json());
18
+ return { enabled: true, ok: r.ok, drawgen: j.drawgen };
19
+ }
20
+ catch {
21
+ return { enabled: true, ok: false };
22
+ }
23
+ }
24
+ /** Render one spec. Spec mistakes come back as 422 with drawgen's message (for the model to fix). */
25
+ export async function drawio(spec) {
26
+ if (!RENDER_URL)
27
+ throw httpError(503, "Diagram rendering is off: it needs the render service (part of the Docker setup).");
28
+ if (typeof spec !== "string" && (typeof spec !== "object" || spec === null || Array.isArray(spec))) {
29
+ throw httpError(400, "spec must be YAML/JSON text or an object");
30
+ }
31
+ const body = JSON.stringify({ spec });
32
+ if (Buffer.byteLength(body) > MAX_SPEC)
33
+ throw httpError(413, `The diagram spec is over ${MAX_SPEC / 1024} KB.`);
34
+ let r;
35
+ try {
36
+ r = await fetch(`${RENDER_URL}/drawio`, {
37
+ method: "POST",
38
+ headers: { "Content-Type": "application/json" },
39
+ body,
40
+ signal: AbortSignal.timeout(20_000),
41
+ });
42
+ }
43
+ catch {
44
+ throw httpError(503, "The render service is not answering.");
45
+ }
46
+ const j = (await r.json().catch(() => ({})));
47
+ if (!r.ok || !j.svg)
48
+ throw httpError(r.status === 200 ? 502 : r.status, j.error?.message || `Rendering failed (${r.status}).`);
49
+ return j;
50
+ }
51
+ export const MAX_DIAGRAM_FILE = 3 * 1024 * 1024 - 1024;
52
+ /** A .drawio / .drawio.svg file a person attached -> the outline a model reviews. */
53
+ export async function outline(file) {
54
+ if (!RENDER_URL)
55
+ throw httpError(503, "Reading draw.io files needs the render service (part of the Docker setup).");
56
+ if (typeof file !== "string" || !file.trim())
57
+ throw httpError(400, "file must be the text of a .drawio or .drawio.svg file");
58
+ const body = JSON.stringify({ file });
59
+ if (Buffer.byteLength(body) > MAX_DIAGRAM_FILE)
60
+ throw httpError(413, "The diagram file is over 3 MB.");
61
+ let r;
62
+ try {
63
+ r = await fetch(`${RENDER_URL}/drawio/outline`, {
64
+ method: "POST",
65
+ headers: { "Content-Type": "application/json" },
66
+ body,
67
+ signal: AbortSignal.timeout(20_000),
68
+ });
69
+ }
70
+ catch {
71
+ throw httpError(503, "The render service is not answering.");
72
+ }
73
+ const j = (await r.json().catch(() => ({})));
74
+ if (!r.ok || typeof j.outline !== "string")
75
+ throw httpError(r.status === 200 ? 502 : r.status, j.error?.message || `Reading the diagram failed (${r.status}).`);
76
+ return { outline: j.outline, pages: j.pages ?? [], chars: j.chars ?? j.outline.length };
77
+ }
78
+ //# sourceMappingURL=render.js.map
@@ -54,6 +54,13 @@ export class SCXClient {
54
54
  body: json !== undefined ? JSON.stringify(json) : rest.body,
55
55
  });
56
56
  }
57
+ catch (e) {
58
+ if (ctrl.signal.aborted) {
59
+ const host = new URL(this.baseUrl).host;
60
+ throw new SCXError(504, `${host} did not start answering within ${Math.round(this.timeoutMs / 1000)}s. The model may be busy or queued; try again or pick another model.`, "timeout");
61
+ }
62
+ throw e;
63
+ }
57
64
  finally {
58
65
  clearTimeout(t);
59
66
  }
@@ -272,6 +272,26 @@ export function setItem(name, value) {
272
272
  save({ ...v, items: { ...v.items, [name]: seal(dek, value, name) } });
273
273
  audit("vault.item.set", { name });
274
274
  }
275
+ /**
276
+ * Seal data for another at-rest store (Playground sessions) with the vault key, which never
277
+ * leaves this module. The AAD binds the ciphertext to its record, so a sealed blob can't be
278
+ * moved to another record and still open. Needs a vault that is set up and unlocked.
279
+ */
280
+ export function sealData(plaintext, aad) {
281
+ if (!load())
282
+ throw httpError(409, "Set up the vault (sidebar → keys) to save Playground sessions; they are encrypted with it.");
283
+ if (!dek)
284
+ throw httpError(503, "The vault is sealed (locked). Unlock it to save.");
285
+ touch();
286
+ return seal(dek, plaintext, aad);
287
+ }
288
+ /** Open data sealed by sealData(). Throws if sealed, or if the blob or its AAD was tampered with. */
289
+ export function openData(sealed, aad) {
290
+ if (!dek)
291
+ throw httpError(503, "The vault is sealed (locked). Unlock it to open saved sessions.");
292
+ touch();
293
+ return open(dek, sealed, aad).toString("utf8");
294
+ }
275
295
  export function deleteItem(name) {
276
296
  const v = load();
277
297
  if (!v)