nanocodex-vite 0.6.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 +48 -0
- package/chatgpt-egress.mjs +298 -0
- package/chatgpt-subscription.mjs +451 -0
- package/cloudflare-plugin.mjs +80 -0
- package/cloudflare.d.mts +21 -0
- package/cloudflare.mjs +32 -0
- package/codex-auth-file.mjs +158 -0
- package/index.d.mts +36 -0
- package/index.mjs +6 -0
- package/oauth-relay-server.mjs +125 -0
- package/oauth-relay.d.mts +104 -0
- package/oauth-relay.mjs +313 -0
- package/package.json +65 -0
- package/plugin.mjs +525 -0
- package/scripts/build-js-package.sh +147 -0
- package/scripts/wasm-memory-views.mjs +39 -0
- package/tools.d.mts +8 -0
- package/tools.mjs +38 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
/** Normalize wasm-bindgen's byte views without changing the Rust/WASM ABI. */
|
|
6
|
+
export function rewriteWasmMemoryViews(source) {
|
|
7
|
+
// V8 subarray() checks its begin offset against the embedder's maximum
|
|
8
|
+
// ArrayBuffer allocation (128 MiB on Cloudflare). WASM memory.grow can exceed
|
|
9
|
+
// that address, so even a tiny, valid string then throws RangeError. A direct
|
|
10
|
+
// view checks the requested length and the actual memory bounds instead.
|
|
11
|
+
const replacements = [
|
|
12
|
+
["getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len)",
|
|
13
|
+
"new Uint8Array(wasm.memory.buffer, ptr, len)"],
|
|
14
|
+
["getUint8ArrayMemory0().subarray(ptr, ptr + len)",
|
|
15
|
+
"new Uint8Array(wasm.memory.buffer, ptr, len)"],
|
|
16
|
+
["getUint8ArrayMemory0().subarray(ptr, ptr + buf.length)",
|
|
17
|
+
"new Uint8Array(wasm.memory.buffer, ptr, buf.length)"],
|
|
18
|
+
["getUint8ArrayMemory0().subarray(ptr + offset, ptr + len)",
|
|
19
|
+
"new Uint8Array(wasm.memory.buffer, ptr + offset, len - offset)"],
|
|
20
|
+
];
|
|
21
|
+
for (const [before, after] of replacements) {
|
|
22
|
+
if (source.split(before).length !== 2) {
|
|
23
|
+
throw new Error(`unsupported wasm-bindgen memory view: expected exactly one ${before}`);
|
|
24
|
+
}
|
|
25
|
+
source = source.replace(before, after);
|
|
26
|
+
}
|
|
27
|
+
if (source.includes("getUint8ArrayMemory0().subarray(")) {
|
|
28
|
+
throw new Error("unsupported wasm-bindgen memory view remains");
|
|
29
|
+
}
|
|
30
|
+
return source;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
34
|
+
const paths = process.argv.slice(2);
|
|
35
|
+
if (paths.length === 0) throw new Error("expected generated wasm-bindgen JavaScript paths");
|
|
36
|
+
// Validate all targets before writing any, so generator drift fails the build.
|
|
37
|
+
const outputs = await Promise.all(paths.map(async (path) => [path, rewriteWasmMemoryViews(await readFile(path, "utf8"))]));
|
|
38
|
+
await Promise.all(outputs.map(([path, source]) => writeFile(path, source)));
|
|
39
|
+
}
|
package/tools.d.mts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type NanocodexToolsVitePlugin = Readonly<{
|
|
2
|
+
name: "nanocodex-tools";
|
|
3
|
+
enforce: "pre";
|
|
4
|
+
resolveId(source: string, importer?: string): string | null;
|
|
5
|
+
}>;
|
|
6
|
+
|
|
7
|
+
/** Keeps unreachable Node-only SSH fallbacks out of browser and Worker bundles. */
|
|
8
|
+
export function nanocodexTools(): NanocodexToolsVitePlugin;
|
package/tools.mjs
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { fileURLToPath } from "node:url";
|
|
2
|
+
|
|
3
|
+
const browserTools = new URL(import.meta.resolve("nanocodex/tools/browser"));
|
|
4
|
+
const browserSsh = fileURLToPath(
|
|
5
|
+
new URL("./devTunnelsSshBrowser.mjs", browserTools),
|
|
6
|
+
);
|
|
7
|
+
const unsupportedNodeRsa = fileURLToPath(
|
|
8
|
+
new URL("./unsupportedNodeRsa.mjs", browserTools),
|
|
9
|
+
);
|
|
10
|
+
const browserSprintf = fileURLToPath(
|
|
11
|
+
new URL("./browserSprintf.mjs", browserTools),
|
|
12
|
+
);
|
|
13
|
+
const browserZlib = fileURLToPath(
|
|
14
|
+
new URL("./browserZlib.mjs", browserTools),
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Keeps unreachable Node-only SSH fallbacks out of browser and Worker bundles.
|
|
19
|
+
* Add this before framework plugins so nested Worker builds inherit it.
|
|
20
|
+
*/
|
|
21
|
+
export function nanocodexTools() {
|
|
22
|
+
return {
|
|
23
|
+
name: "nanocodex-tools",
|
|
24
|
+
enforce: "pre",
|
|
25
|
+
resolveId(source, importer) {
|
|
26
|
+
if (source === "@microsoft/dev-tunnels-ssh") return browserSsh;
|
|
27
|
+
if (source === "node-rsa") return unsupportedNodeRsa;
|
|
28
|
+
if (source === "node:zlib") return browserZlib;
|
|
29
|
+
// Let the compatibility module's own default import reach Vite's normal
|
|
30
|
+
// CommonJS transform; every external named import resolves to this ESM
|
|
31
|
+
// boundary instead of relying on consumer optimizeDeps configuration.
|
|
32
|
+
if (source === "sprintf-js" && importer?.split("?", 1)[0] !== browserSprintf) {
|
|
33
|
+
return browserSprintf;
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|