mirror of
https://github.com/teamchong/pxpipe.git
synced 2026-07-22 02:02:51 +02:00
f91c149d05
Runtime is pure Web Standard APIs (fetch, Request, Response, Uint8Array,
CompressionStream, crypto.subtle, btoa) — zero runtime dependencies.
Core (src/core/, runs identically on Node 18+ and Workers):
- atlas.ts auto-generated 9x15 JBM glyph atlas, base64-inlined (17KB)
- png.ts minimal grayscale PNG encoder via CompressionStream
- render.ts text → packed PNG, soft-wraps at 100 cols, ≤1568px tall
- transform.ts request body rewriter (system + tool docs → image blocks)
- proxy.ts fetch-handler that transforms then forwards to Anthropic
- types.ts Anthropic Messages API types we touch
Adapters:
- src/node.ts node:http server + CLI flag parsing
- src/worker.ts export default { fetch } for wrangler dev/deploy
Build tooling:
- scripts/gen-atlas.ts @napi-rs/canvas → atlas.ts (build-time only)
- scripts/build.mjs esbuild Node bundle; wrangler handles Worker
- tsconfig.json strict, ES2022, Workers types
Tests (vitest): 8 passing — PNG signature, base64 round-trip, single +
multi-image renders, transform no-op + compress paths, billing-line strip,
tool fold + stub.
E2E smoke: 16K char system → 2 PNGs (36KB) → mock upstream, 34ms.
Next: replace docs, then verify byte-output parity against legacy/python.
24 lines
687 B
JavaScript
24 lines
687 B
JavaScript
// Build the Node bundle. The Worker target is built by wrangler directly
|
|
// from src/worker.ts (no separate build step needed).
|
|
import { build } from 'esbuild';
|
|
import { mkdir, copyFile } from 'node:fs/promises';
|
|
import { existsSync } from 'node:fs';
|
|
|
|
const OUT = 'dist';
|
|
if (!existsSync(OUT)) await mkdir(OUT, { recursive: true });
|
|
|
|
await build({
|
|
entryPoints: ['src/node.ts'],
|
|
outfile: 'dist/node.js',
|
|
bundle: true,
|
|
platform: 'node',
|
|
target: 'node18',
|
|
format: 'esm',
|
|
sourcemap: true,
|
|
// Atlas is inlined as a base64 string in src/core/atlas.ts, so no external assets.
|
|
external: [],
|
|
banner: { js: '#!/usr/bin/env node' },
|
|
});
|
|
|
|
console.log('✓ built dist/node.js');
|