mindwire 0.1.19 → 0.1.23
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/dist/binary-cache-CG52TXCZ.js +3 -0
- package/dist/binary-cache-CG52TXCZ.js.map +1 -0
- package/dist/binary-cache-ZTEYICUF.js +51 -0
- package/dist/binary-cache-ZTEYICUF.js.map +1 -0
- package/dist/binary-cache.d.ts +5 -0
- package/dist/chunk-PFYKJ6LX.js +103 -0
- package/dist/chunk-PFYKJ6LX.js.map +1 -0
- package/dist/chunk-T6TD76UA.js +57 -0
- package/dist/chunk-T6TD76UA.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +2395 -0
- package/dist/cli.js.map +1 -0
- package/dist/client.d.ts +4 -0
- package/dist/computer/cloudflare-binary.d.ts +9 -0
- package/dist/computer/lifecycle.d.ts +24 -0
- package/dist/computer/relay.d.ts +19 -0
- package/dist/computer.d.ts +80 -0
- package/dist/execution.d.ts +111 -0
- package/dist/index.cjs +323 -120
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +141 -81
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +5 -0
- package/dist/workspace.d.ts +36 -3
- package/package.json +7 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"binary-cache-CG52TXCZ.js"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { MindwireError } from './chunk-T6TD76UA.js';
|
|
2
|
+
|
|
3
|
+
// src/binary-cache.ts
|
|
4
|
+
async function binaryCacheDirectory(platform = process.platform) {
|
|
5
|
+
const path = await import('path');
|
|
6
|
+
const { homedir } = await import('os');
|
|
7
|
+
const homeDirectory = homedir();
|
|
8
|
+
return platform === "darwin" ? path.join(homeDirectory, "Library", "Caches", "mindwire") : platform === "win32" ? path.join(process.env.LOCALAPPDATA ?? homeDirectory, "mindwire", "Cache") : path.join(process.env.XDG_CACHE_HOME ?? path.join(homeDirectory, ".cache"), "mindwire");
|
|
9
|
+
}
|
|
10
|
+
async function executableChecksum(bytes) {
|
|
11
|
+
const { createHash } = await import('crypto');
|
|
12
|
+
return createHash("sha256").update(bytes).digest("hex");
|
|
13
|
+
}
|
|
14
|
+
async function verifyReleaseBytes(bytes, expected, name) {
|
|
15
|
+
if (!/^[a-f0-9]{64}$/i.test(expected) || await executableChecksum(bytes) !== expected.toLowerCase()) {
|
|
16
|
+
throw new MindwireError(`mindwire: checksum verification failed for ${name}`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
async function cachedExecutable(bin) {
|
|
20
|
+
const fs = await import('fs/promises');
|
|
21
|
+
try {
|
|
22
|
+
const [bytes, checksum] = await Promise.all([fs.readFile(bin), fs.readFile(`${bin}.sha256`, "utf8")]);
|
|
23
|
+
await verifyReleaseBytes(bytes, checksum.trim(), bin);
|
|
24
|
+
return bin;
|
|
25
|
+
} catch {
|
|
26
|
+
return void 0;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async function cacheExecutable(bin, bytes, expected) {
|
|
30
|
+
await verifyReleaseBytes(bytes, expected, bin);
|
|
31
|
+
const fs = await import('fs/promises');
|
|
32
|
+
const { dirname } = await import('path');
|
|
33
|
+
const { randomUUID } = await import('crypto');
|
|
34
|
+
await fs.mkdir(dirname(bin), { recursive: true, mode: 448 });
|
|
35
|
+
const temp = `${bin}.${randomUUID()}.tmp`;
|
|
36
|
+
try {
|
|
37
|
+
await fs.writeFile(temp, bytes, { mode: 493, flag: "wx" });
|
|
38
|
+
await fs.writeFile(`${temp}.sha256`, `${expected.toLowerCase()}
|
|
39
|
+
`, { mode: 384, flag: "wx" });
|
|
40
|
+
await fs.rename(temp, bin);
|
|
41
|
+
await fs.rename(`${temp}.sha256`, `${bin}.sha256`);
|
|
42
|
+
return bin;
|
|
43
|
+
} finally {
|
|
44
|
+
await fs.rm(temp, { force: true });
|
|
45
|
+
await fs.rm(`${temp}.sha256`, { force: true });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { binaryCacheDirectory, cacheExecutable, cachedExecutable, executableChecksum, verifyReleaseBytes };
|
|
50
|
+
//# sourceMappingURL=binary-cache-ZTEYICUF.js.map
|
|
51
|
+
//# sourceMappingURL=binary-cache-ZTEYICUF.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/binary-cache.ts"],"names":[],"mappings":";;;AAIA,eAAsB,oBAAA,CAAqB,QAAA,GAAW,OAAA,CAAQ,QAAA,EAA2B;AACvF,EAAA,MAAM,IAAA,GAAO,MAAM,OAAO,MAAW,CAAA;AACrC,EAAA,MAAM,EAAE,OAAA,EAAQ,GAAI,MAAM,OAAO,IAAS,CAAA;AAC1C,EAAA,MAAM,gBAAgB,OAAA,EAAQ;AAC9B,EAAA,OAAO,QAAA,KAAa,QAAA,GAAW,IAAA,CAAK,IAAA,CAAK,aAAA,EAAe,SAAA,EAAW,QAAA,EAAU,UAAU,CAAA,GACnF,QAAA,KAAa,OAAA,GAAU,IAAA,CAAK,KAAK,OAAA,CAAQ,GAAA,CAAI,YAAA,IAAgB,aAAA,EAAe,UAAA,EAAY,OAAO,CAAA,GAC/F,IAAA,CAAK,IAAA,CAAK,OAAA,CAAQ,GAAA,CAAI,cAAA,IAAkB,IAAA,CAAK,IAAA,CAAK,aAAA,EAAe,QAAQ,GAAG,UAAU,CAAA;AAC5F;AAEA,eAAsB,mBAAmB,KAAA,EAAoC;AAC3E,EAAA,MAAM,EAAE,UAAA,EAAW,GAAI,MAAM,OAAO,QAAa,CAAA;AACjD,EAAA,OAAO,WAAW,QAAQ,CAAA,CAAE,OAAO,KAAK,CAAA,CAAE,OAAO,KAAK,CAAA;AACxD;AAEA,eAAsB,kBAAA,CAAmB,KAAA,EAAmB,QAAA,EAAkB,IAAA,EAA6B;AACzG,EAAA,IAAI,CAAC,iBAAA,CAAkB,IAAA,CAAK,QAAQ,CAAA,IAA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,IAAA,MAAM,EAAA,CAAG,UAAU,IAAA,EAAM,KAAA,EAAO,EAAE,IAAA,EAAM,GAAA,EAAO,IAAA,EAAM,IAAA,EAAM,CAAA;AAC3D,IAAA,MAAM,EAAA,CAAG,UAAU,CAAA,EAAG,IAAI,WAAW,CAAA,EAAG,QAAA,CAAS,aAAa;AAAA,CAAA,EAAM,EAAE,IAAA,EAAM,GAAA,EAAO,IAAA,EAAM,MAAM,CAAA;AAC/F,IAAA,MAAM,EAAA,CAAG,MAAA,CAAO,IAAA,EAAM,GAAG,CAAA;AACzB,IAAA,MAAM,GAAG,MAAA,CAAO,CAAA,EAAG,IAAI,CAAA,OAAA,CAAA,EAAW,CAAA,EAAG,GAAG,CAAA,OAAA,CAAS,CAAA;AACjD,IAAA,OAAO,GAAA;AAAA,EACT,CAAA,SAAE;AACA,IAAA,MAAM,GAAG,EAAA,CAAG,IAAA,EAAM,EAAE,KAAA,EAAO,MAAM,CAAA;AACjC,IAAA,MAAM,EAAA,CAAG,GAAG,CAAA,EAAG,IAAI,WAAW,EAAE,KAAA,EAAO,MAAM,CAAA;AAAA,EAC/C;AACF","file":"binary-cache-ZTEYICUF.js","sourcesContent":["// Shared verified executable cache for the daemon and optional connection helpers.\n// Node modules stay lazy so importing the SDK in a browser remains supported.\nimport { MindwireError } from \"./errors.js\";\n\nexport async function binaryCacheDirectory(platform = process.platform): Promise<string> {\n const path = await import(\"node:path\");\n const { homedir } = await import(\"node:os\");\n const homeDirectory = homedir();\n return platform === \"darwin\" ? path.join(homeDirectory, \"Library\", \"Caches\", \"mindwire\")\n : platform === \"win32\" ? path.join(process.env.LOCALAPPDATA ?? homeDirectory, \"mindwire\", \"Cache\")\n : path.join(process.env.XDG_CACHE_HOME ?? path.join(homeDirectory, \".cache\"), \"mindwire\");\n}\n\nexport async function executableChecksum(bytes: Uint8Array): Promise<string> {\n const { createHash } = await import(\"node:crypto\");\n return createHash(\"sha256\").update(bytes).digest(\"hex\");\n}\n\nexport async function verifyReleaseBytes(bytes: Uint8Array, expected: string, name: string): Promise<void> {\n if (!/^[a-f0-9]{64}$/i.test(expected) || await executableChecksum(bytes) !== expected.toLowerCase()) {\n throw new MindwireError(`mindwire: checksum verification failed for ${name}`);\n }\n}\n\nexport async function cachedExecutable(bin: string): Promise<string | undefined> {\n const fs = await import(\"node:fs/promises\");\n try {\n const [bytes, checksum] = await Promise.all([fs.readFile(bin), fs.readFile(`${bin}.sha256`, \"utf8\")]);\n await verifyReleaseBytes(bytes, checksum.trim(), bin);\n return bin;\n } catch { return undefined; }\n}\n\nexport async function cacheExecutable(bin: string, bytes: Uint8Array, expected: string): Promise<string> {\n await verifyReleaseBytes(bytes, expected, bin);\n const fs = await import(\"node:fs/promises\");\n const { dirname } = await import(\"node:path\");\n const { randomUUID } = await import(\"node:crypto\");\n await fs.mkdir(dirname(bin), { recursive: true, mode: 0o700 });\n // Unique temporary names also cover concurrent acquisitions in the same process.\n const temp = `${bin}.${randomUUID()}.tmp`;\n try {\n await fs.writeFile(temp, bytes, { mode: 0o755, flag: \"wx\" });\n await fs.writeFile(`${temp}.sha256`, `${expected.toLowerCase()}\\n`, { mode: 0o600, flag: \"wx\" });\n await fs.rename(temp, bin);\n await fs.rename(`${temp}.sha256`, `${bin}.sha256`);\n return bin;\n } finally {\n await fs.rm(temp, { force: true });\n await fs.rm(`${temp}.sha256`, { force: true });\n }\n}\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function binaryCacheDirectory(platform?: NodeJS.Platform): Promise<string>;
|
|
2
|
+
export declare function executableChecksum(bytes: Uint8Array): Promise<string>;
|
|
3
|
+
export declare function verifyReleaseBytes(bytes: Uint8Array, expected: string, name: string): Promise<void>;
|
|
4
|
+
export declare function cachedExecutable(bin: string): Promise<string | undefined>;
|
|
5
|
+
export declare function cacheExecutable(bin: string, bytes: Uint8Array, expected: string): Promise<string>;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// src/errors.ts
|
|
2
|
+
var MindwireError = class extends Error {
|
|
3
|
+
constructor(message, options) {
|
|
4
|
+
super(message, options);
|
|
5
|
+
this.name = "MindwireError";
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
var ApiError = class _ApiError extends MindwireError {
|
|
9
|
+
status;
|
|
10
|
+
url;
|
|
11
|
+
method;
|
|
12
|
+
body;
|
|
13
|
+
constructor(args) {
|
|
14
|
+
super(_ApiError.messageFor(args));
|
|
15
|
+
this.name = "ApiError";
|
|
16
|
+
this.status = args.status;
|
|
17
|
+
this.url = args.url;
|
|
18
|
+
this.method = args.method;
|
|
19
|
+
this.body = args.body;
|
|
20
|
+
}
|
|
21
|
+
static messageFor({
|
|
22
|
+
status,
|
|
23
|
+
method,
|
|
24
|
+
url,
|
|
25
|
+
body
|
|
26
|
+
}) {
|
|
27
|
+
const detail = body && typeof body === "object" && "error" in body && typeof body.error === "string" ? body.error : typeof body === "string" && body.trim() !== "" ? body.trim() : "";
|
|
28
|
+
const base = `${method} ${url} failed with ${status}`;
|
|
29
|
+
return detail ? `${base}: ${detail}` : base;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
var RunFailedError = class extends MindwireError {
|
|
33
|
+
status;
|
|
34
|
+
runId;
|
|
35
|
+
constructor(runId, status, detail) {
|
|
36
|
+
super(detail ? `run ${runId} ${status}: ${detail}` : `run ${runId} ${status}`);
|
|
37
|
+
this.name = "RunFailedError";
|
|
38
|
+
this.runId = runId;
|
|
39
|
+
this.status = status;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var TimeoutError = class extends MindwireError {
|
|
43
|
+
method;
|
|
44
|
+
path;
|
|
45
|
+
timeoutMs;
|
|
46
|
+
constructor(method, path, timeoutMs) {
|
|
47
|
+
super(`mindwire: ${method} ${path} timed out after ${timeoutMs}ms`);
|
|
48
|
+
this.name = "TimeoutError";
|
|
49
|
+
this.method = method;
|
|
50
|
+
this.path = path;
|
|
51
|
+
this.timeoutMs = timeoutMs;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// src/binary-cache.ts
|
|
56
|
+
async function binaryCacheDirectory(platform = process.platform) {
|
|
57
|
+
const path = await import('path');
|
|
58
|
+
const { homedir } = await import('os');
|
|
59
|
+
const homeDirectory = homedir();
|
|
60
|
+
return platform === "darwin" ? path.join(homeDirectory, "Library", "Caches", "mindwire") : platform === "win32" ? path.join(process.env.LOCALAPPDATA ?? homeDirectory, "mindwire", "Cache") : path.join(process.env.XDG_CACHE_HOME ?? path.join(homeDirectory, ".cache"), "mindwire");
|
|
61
|
+
}
|
|
62
|
+
async function executableChecksum(bytes) {
|
|
63
|
+
const { createHash } = await import('crypto');
|
|
64
|
+
return createHash("sha256").update(bytes).digest("hex");
|
|
65
|
+
}
|
|
66
|
+
async function verifyReleaseBytes(bytes, expected, name) {
|
|
67
|
+
if (!/^[a-f0-9]{64}$/i.test(expected) || await executableChecksum(bytes) !== expected.toLowerCase()) {
|
|
68
|
+
throw new MindwireError(`mindwire: checksum verification failed for ${name}`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async function cachedExecutable(bin) {
|
|
72
|
+
const fs = await import('fs/promises');
|
|
73
|
+
try {
|
|
74
|
+
const [bytes, checksum] = await Promise.all([fs.readFile(bin), fs.readFile(`${bin}.sha256`, "utf8")]);
|
|
75
|
+
await verifyReleaseBytes(bytes, checksum.trim(), bin);
|
|
76
|
+
return bin;
|
|
77
|
+
} catch {
|
|
78
|
+
return void 0;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
async function cacheExecutable(bin, bytes, expected) {
|
|
82
|
+
await verifyReleaseBytes(bytes, expected, bin);
|
|
83
|
+
const fs = await import('fs/promises');
|
|
84
|
+
const { dirname } = await import('path');
|
|
85
|
+
const { randomUUID } = await import('crypto');
|
|
86
|
+
await fs.mkdir(dirname(bin), { recursive: true, mode: 448 });
|
|
87
|
+
const temp = `${bin}.${randomUUID()}.tmp`;
|
|
88
|
+
try {
|
|
89
|
+
await fs.writeFile(temp, bytes, { mode: 493, flag: "wx" });
|
|
90
|
+
await fs.writeFile(`${temp}.sha256`, `${expected.toLowerCase()}
|
|
91
|
+
`, { mode: 384, flag: "wx" });
|
|
92
|
+
await fs.rename(temp, bin);
|
|
93
|
+
await fs.rename(`${temp}.sha256`, `${bin}.sha256`);
|
|
94
|
+
return bin;
|
|
95
|
+
} finally {
|
|
96
|
+
await fs.rm(temp, { force: true });
|
|
97
|
+
await fs.rm(`${temp}.sha256`, { force: true });
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export { ApiError, MindwireError, RunFailedError, TimeoutError, binaryCacheDirectory, cacheExecutable, cachedExecutable, executableChecksum, verifyReleaseBytes };
|
|
102
|
+
//# sourceMappingURL=chunk-PFYKJ6LX.js.map
|
|
103
|
+
//# sourceMappingURL=chunk-PFYKJ6LX.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts","../src/binary-cache.ts"],"names":[],"mappings":";AACO,IAAM,aAAA,GAAN,cAA4B,KAAA,CAAM;AAAA,EACvC,WAAA,CAAY,SAAiB,OAAA,EAA+B;AAC1D,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA;AACtB,IAAA,IAAA,CAAK,IAAA,GAAO,eAAA;AAAA,EACd;AACF;AAMO,IAAM,QAAA,GAAN,MAAM,SAAA,SAAiB,aAAA,CAAc;AAAA,EACjC,MAAA;AAAA,EACA,GAAA;AAAA,EACA,MAAA;AAAA,EACA,IAAA;AAAA,EAET,YAAY,IAAA,EAAsE;AAChF,IAAA,KAAA,CAAM,SAAA,CAAS,UAAA,CAAW,IAAI,CAAC,CAAA;AAC/B,IAAA,IAAA,CAAK,IAAA,GAAO,UAAA;AACZ,IAAA,IAAA,CAAK,SAAS,IAAA,CAAK,MAAA;AACnB,IAAA,IAAA,CAAK,MAAM,IAAA,CAAK,GAAA;AAChB,IAAA,IAAA,CAAK,SAAS,IAAA,CAAK,MAAA;AACnB,I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,IAAI;AACF,IAAA,MAAM,EAAA,CAAG,UAAU,IAAA,EAAM,KAAA,EAAO,EAAE,IAAA,EAAM,GAAA,EAAO,IAAA,EAAM,IAAA,EAAM,CAAA;AAC3D,IAAA,MAAM,EAAA,CAAG,UAAU,CAAA,EAAG,IAAI,WAAW,CAAA,EAAG,QAAA,CAAS,aAAa;AAAA,CAAA,EAAM,EAAE,IAAA,EAAM,GAAA,EAAO,IAAA,EAAM,MAAM,CAAA;AAC/F,IAAA,MAAM,EAAA,CAAG,MAAA,CAAO,IAAA,EAAM,GAAG,CAAA;AACzB,IAAA,MAAM,GAAG,MAAA,CAAO,CAAA,EAAG,IAAI,CAAA,OAAA,CAAA,EAAW,CAAA,EAAG,GAAG,CAAA,OAAA,CAAS,CAAA;AACjD,IAAA,OAAO,GAAA;AAAA,EACT,CAAA,SAAE;AACA,IAAA,MAAM,GAAG,EAAA,CAAG,IAAA,EAAM,EAAE,KAAA,EAAO,MAAM,CAAA;AACjC,IAAA,MAAM,EAAA,CAAG,GAAG,CAAA,EAAG,IAAI,WAAW,EAAE,KAAA,EAAO,MAAM,CAAA;AAAA,EAC/C;AACF","file":"chunk-PFYKJ6LX.js","sourcesContent":["/** Base class for every error thrown by the SDK. */\nexport class MindwireError extends Error {\n constructor(message: string, options?: { cause?: unknown }) {\n super(message, options);\n this.name = \"MindwireError\";\n }\n}\n\n/**\n * A non-2xx HTTP response from the daemon. `body` is the parsed JSON error payload when the\n * daemon returned one (it uses `{ \"error\": \"...\" }`), otherwise the raw text.\n */\nexport class ApiError extends MindwireError {\n readonly status: number;\n readonly url: string;\n readonly method: string;\n readonly body: unknown;\n\n constructor(args: { status: number; url: string; method: string; body: unknown }) {\n super(ApiError.messageFor(args));\n this.name = \"ApiError\";\n this.status = args.status;\n this.url = args.url;\n this.method = args.method;\n this.body = args.body;\n }\n\n private static messageFor({\n status,\n method,\n url,\n body,\n }: {\n status: number;\n method: string;\n url: string;\n body: unknown;\n }): string {\n const detail =\n body && typeof body === \"object\" && \"error\" in body && typeof body.error === \"string\"\n ? body.error\n : typeof body === \"string\" && body.trim() !== \"\"\n ? body.trim()\n : \"\";\n const base = `${method} ${url} failed with ${status}`;\n return detail ? `${base}: ${detail}` : base;\n }\n}\n\n/**\n * Thrown by {@link import(\"./run.js\").Run.wait} when a run ends in a non-success terminal state\n * (`error`/`cancelled`), or when the event stream ends before the run reaches any terminal state —\n * a dropped/truncated stream. The `status` is whatever the run was in when `wait()` gave up, so a\n * truncated stream surfaces as e.g. `run <id> running: event stream ended …` rather than silently\n * returning a success-shaped result.\n */\nexport class RunFailedError extends MindwireError {\n readonly status: string;\n readonly runId: string;\n\n constructor(runId: string, status: string, detail?: string) {\n super(detail ? `run ${runId} ${status}: ${detail}` : `run ${runId} ${status}`);\n this.name = \"RunFailedError\";\n this.runId = runId;\n this.status = status;\n }\n}\n\n/**\n * Thrown when a unary request exceeds the client's `requestTimeoutMs` deadline. A hung daemon or a\n * dead tunnel would otherwise block the caller forever; this bounds every non-streaming call. SSE\n * streams are long-lived and are never subject to this timeout.\n */\nexport class TimeoutError extends MindwireError {\n readonly method: string;\n readonly path: string;\n readonly timeoutMs: number;\n\n constructor(method: string, path: string, timeoutMs: number) {\n super(`mindwire: ${method} ${path} timed out after ${timeoutMs}ms`);\n this.name = \"TimeoutError\";\n this.method = method;\n this.path = path;\n this.timeoutMs = timeoutMs;\n }\n}\n","// Shared verified executable cache for the daemon and optional connection helpers.\n// Node modules stay lazy so importing the SDK in a browser remains supported.\nimport { MindwireError } from \"./errors.js\";\n\nexport async function binaryCacheDirectory(platform = process.platform): Promise<string> {\n const path = await import(\"node:path\");\n const { homedir } = await import(\"node:os\");\n const homeDirectory = homedir();\n return platform === \"darwin\" ? path.join(homeDirectory, \"Library\", \"Caches\", \"mindwire\")\n : platform === \"win32\" ? path.join(process.env.LOCALAPPDATA ?? homeDirectory, \"mindwire\", \"Cache\")\n : path.join(process.env.XDG_CACHE_HOME ?? path.join(homeDirectory, \".cache\"), \"mindwire\");\n}\n\nexport async function executableChecksum(bytes: Uint8Array): Promise<string> {\n const { createHash } = await import(\"node:crypto\");\n return createHash(\"sha256\").update(bytes).digest(\"hex\");\n}\n\nexport async function verifyReleaseBytes(bytes: Uint8Array, expected: string, name: string): Promise<void> {\n if (!/^[a-f0-9]{64}$/i.test(expected) || await executableChecksum(bytes) !== expected.toLowerCase()) {\n throw new MindwireError(`mindwire: checksum verification failed for ${name}`);\n }\n}\n\nexport async function cachedExecutable(bin: string): Promise<string | undefined> {\n const fs = await import(\"node:fs/promises\");\n try {\n const [bytes, checksum] = await Promise.all([fs.readFile(bin), fs.readFile(`${bin}.sha256`, \"utf8\")]);\n await verifyReleaseBytes(bytes, checksum.trim(), bin);\n return bin;\n } catch { return undefined; }\n}\n\nexport async function cacheExecutable(bin: string, bytes: Uint8Array, expected: string): Promise<string> {\n await verifyReleaseBytes(bytes, expected, bin);\n const fs = await import(\"node:fs/promises\");\n const { dirname } = await import(\"node:path\");\n const { randomUUID } = await import(\"node:crypto\");\n await fs.mkdir(dirname(bin), { recursive: true, mode: 0o700 });\n // Unique temporary names also cover concurrent acquisitions in the same process.\n const temp = `${bin}.${randomUUID()}.tmp`;\n try {\n await fs.writeFile(temp, bytes, { mode: 0o755, flag: \"wx\" });\n await fs.writeFile(`${temp}.sha256`, `${expected.toLowerCase()}\\n`, { mode: 0o600, flag: \"wx\" });\n await fs.rename(temp, bin);\n await fs.rename(`${temp}.sha256`, `${bin}.sha256`);\n return bin;\n } finally {\n await fs.rm(temp, { force: true });\n await fs.rm(`${temp}.sha256`, { force: true });\n }\n}\n"]}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// src/errors.ts
|
|
2
|
+
var MindwireError = class extends Error {
|
|
3
|
+
constructor(message, options) {
|
|
4
|
+
super(message, options);
|
|
5
|
+
this.name = "MindwireError";
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
var ApiError = class _ApiError extends MindwireError {
|
|
9
|
+
status;
|
|
10
|
+
url;
|
|
11
|
+
method;
|
|
12
|
+
body;
|
|
13
|
+
constructor(args) {
|
|
14
|
+
super(_ApiError.messageFor(args));
|
|
15
|
+
this.name = "ApiError";
|
|
16
|
+
this.status = args.status;
|
|
17
|
+
this.url = args.url;
|
|
18
|
+
this.method = args.method;
|
|
19
|
+
this.body = args.body;
|
|
20
|
+
}
|
|
21
|
+
static messageFor({
|
|
22
|
+
status,
|
|
23
|
+
method,
|
|
24
|
+
url,
|
|
25
|
+
body
|
|
26
|
+
}) {
|
|
27
|
+
const detail = body && typeof body === "object" && "error" in body && typeof body.error === "string" ? body.error : typeof body === "string" && body.trim() !== "" ? body.trim() : "";
|
|
28
|
+
const base = `${method} ${url} failed with ${status}`;
|
|
29
|
+
return detail ? `${base}: ${detail}` : base;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
var RunFailedError = class extends MindwireError {
|
|
33
|
+
status;
|
|
34
|
+
runId;
|
|
35
|
+
constructor(runId, status, detail) {
|
|
36
|
+
super(detail ? `run ${runId} ${status}: ${detail}` : `run ${runId} ${status}`);
|
|
37
|
+
this.name = "RunFailedError";
|
|
38
|
+
this.runId = runId;
|
|
39
|
+
this.status = status;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var TimeoutError = class extends MindwireError {
|
|
43
|
+
method;
|
|
44
|
+
path;
|
|
45
|
+
timeoutMs;
|
|
46
|
+
constructor(method, path, timeoutMs) {
|
|
47
|
+
super(`mindwire: ${method} ${path} timed out after ${timeoutMs}ms`);
|
|
48
|
+
this.name = "TimeoutError";
|
|
49
|
+
this.method = method;
|
|
50
|
+
this.path = path;
|
|
51
|
+
this.timeoutMs = timeoutMs;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export { ApiError, MindwireError, RunFailedError, TimeoutError };
|
|
56
|
+
//# sourceMappingURL=chunk-T6TD76UA.js.map
|
|
57
|
+
//# sourceMappingURL=chunk-T6TD76UA.js.map
|
|
@@ -0,0 +1 @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AAA,GAAK,IAAA;AAAA,EACzC;AACF;AASO,IAAM,cAAA,GAAN,cAA6B,aAAA,CAAc;AAAA,EACvC,MAAA;AAAA,EACA,KAAA;AAAA,EAET,WAAA,CAAY,KAAA,EAAe,MAAA,EAAgB,MAAA,EAAiB;AAC1D,IAAA,KAAA,CAAM,MAAA,GAAS,CAAA,IAAA,EAAO,KAAK,CAAA,CAAA,EAAI,MAAM,CAAA,EAAA,EAAK,MAAM,CAAA,CAAA,GAAK,CAAA,IAAA,EAAO,KAAK,CAAA,CAAA,EAAI,MAAM,CAAA,CAAE,CAAA;AAC7E,IAAA,IAAA,CAAK,IAAA,GAAO,gBAAA;AACZ,IAAA,IAAA,CAAK,KAAA,GAAQ,KAAA;AACb,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AAAA,EAChB;AACF;AAOO,IAAM,YAAA,GAAN,cAA2B,aAAA,CAAc;AAAA,EACrC,MAAA;AAAA,EACA,IAAA;AAAA,EACA,SAAA;AAAA,EAET,WAAA,CAAY,MAAA,EAAgB,IAAA,EAAc,SAAA,EAAmB;AAC3D,IAAA,KAAA,CAAM,aAAa,MAAM,CAAA,CAAA,EAAI,IAAI,CAAA,iBAAA,EAAoB,SAAS,CAAA,EAAA,CAAI,CAAA;AAClE,IAAA,IAAA,CAAK,IAAA,GAAO,cAAA;AACZ,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AACd,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AACZ,IAAA,IAAA,CAAK,SAAA,GAAY,SAAA;AAAA,EACnB;AACF","file":"chunk-T6TD76UA.js","sourcesContent":["/** Base class for every error thrown by the SDK. */\nexport class MindwireError extends Error {\n constructor(message: string, options?: { cause?: unknown }) {\n super(message, options);\n this.name = \"MindwireError\";\n }\n}\n\n/**\n * A non-2xx HTTP response from the daemon. `body` is the parsed JSON error payload when the\n * daemon returned one (it uses `{ \"error\": \"...\" }`), otherwise the raw text.\n */\nexport class ApiError extends MindwireError {\n readonly status: number;\n readonly url: string;\n readonly method: string;\n readonly body: unknown;\n\n constructor(args: { status: number; url: string; method: string; body: unknown }) {\n super(ApiError.messageFor(args));\n this.name = \"ApiError\";\n this.status = args.status;\n this.url = args.url;\n this.method = args.method;\n this.body = args.body;\n }\n\n private static messageFor({\n status,\n method,\n url,\n body,\n }: {\n status: number;\n method: string;\n url: string;\n body: unknown;\n }): string {\n const detail =\n body && typeof body === \"object\" && \"error\" in body && typeof body.error === \"string\"\n ? body.error\n : typeof body === \"string\" && body.trim() !== \"\"\n ? body.trim()\n : \"\";\n const base = `${method} ${url} failed with ${status}`;\n return detail ? `${base}: ${detail}` : base;\n }\n}\n\n/**\n * Thrown by {@link import(\"./run.js\").Run.wait} when a run ends in a non-success terminal state\n * (`error`/`cancelled`), or when the event stream ends before the run reaches any terminal state —\n * a dropped/truncated stream. The `status` is whatever the run was in when `wait()` gave up, so a\n * truncated stream surfaces as e.g. `run <id> running: event stream ended …` rather than silently\n * returning a success-shaped result.\n */\nexport class RunFailedError extends MindwireError {\n readonly status: string;\n readonly runId: string;\n\n constructor(runId: string, status: string, detail?: string) {\n super(detail ? `run ${runId} ${status}: ${detail}` : `run ${runId} ${status}`);\n this.name = \"RunFailedError\";\n this.runId = runId;\n this.status = status;\n }\n}\n\n/**\n * Thrown when a unary request exceeds the client's `requestTimeoutMs` deadline. A hung daemon or a\n * dead tunnel would otherwise block the caller forever; this bounds every non-streaming call. SSE\n * streams are long-lived and are never subject to this timeout.\n */\nexport class TimeoutError extends MindwireError {\n readonly method: string;\n readonly path: string;\n readonly timeoutMs: number;\n\n constructor(method: string, path: string, timeoutMs: number) {\n super(`mindwire: ${method} ${path} timed out after ${timeoutMs}ms`);\n this.name = \"TimeoutError\";\n this.method = method;\n this.path = path;\n this.timeoutMs = timeoutMs;\n }\n}\n"]}
|
package/dist/cli.d.ts
ADDED