openzoo 0.50.99 → 0.51.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.
Files changed (39) hide show
  1. package/bin/openzoo.js +33 -0
  2. package/lib/cursorbackend.js +6 -1
  3. package/lib/cursorbackend.js.bak-hiddenbots +4072 -0
  4. package/lib/models.js +6 -1
  5. package/package.json +7 -4
  6. package/transmute/README.md +352 -0
  7. package/transmute/bin/openzoo-transmute.js +7 -0
  8. package/transmute/docs/OPENZOO_CLI_PATCH.md +139 -0
  9. package/transmute/docs/VERCEL_TO_SOLANA.md +381 -0
  10. package/transmute/lib/build.js +311 -0
  11. package/transmute/lib/cli.js +231 -0
  12. package/transmute/lib/compile/index.js +146 -0
  13. package/transmute/lib/compile/ir.js +1634 -0
  14. package/transmute/lib/compile/parse.js +753 -0
  15. package/transmute/lib/compile/rust.js +777 -0
  16. package/transmute/lib/deploy.js +209 -0
  17. package/transmute/lib/eligibility.js +211 -0
  18. package/transmute/lib/gateway.js +704 -0
  19. package/transmute/lib/hub.js +249 -0
  20. package/transmute/lib/solana.js +339 -0
  21. package/transmute/lib/vercel.js +296 -0
  22. package/transmute/lib/wallet.js +41 -0
  23. package/transmute/lib/wire.js +167 -0
  24. package/transmute/runtime/zoo-host/Cargo.lock +588 -0
  25. package/transmute/runtime/zoo-host/Cargo.toml +28 -0
  26. package/transmute/runtime/zoo-host/src/assets.rs +170 -0
  27. package/transmute/runtime/zoo-host/src/ctx.rs +322 -0
  28. package/transmute/runtime/zoo-host/src/json.rs +257 -0
  29. package/transmute/runtime/zoo-host/src/kv.rs +182 -0
  30. package/transmute/runtime/zoo-host/src/lib.rs +123 -0
  31. package/transmute/runtime/zoo-host/src/val.rs +1044 -0
  32. package/transmute/runtime/zoo-host/src/wire.rs +239 -0
  33. package/transmute/site/.env.production +2 -0
  34. package/transmute/site/api/echo.js +10 -0
  35. package/transmute/site/api/hello.js +12 -0
  36. package/transmute/site/api/hits.js +13 -0
  37. package/transmute/site/api/time.js +5 -0
  38. package/transmute/site/public/app.js +16 -0
  39. package/transmute/site/public/index.html +62 -0
@@ -0,0 +1,146 @@
1
+ // The transmuter: VercelDeployment → Rust crate + manifest + report.
2
+ //
3
+ // transmute(deployment, opts) → { crate: { 'Cargo.toml', 'src/lib.rs' }, manifest, report }
4
+ // compileFunction(fn, source, opts) → { rust, ir, eligible, reason, ... } (one Lambda, for tests/tools)
5
+ import fs from 'node:fs';
6
+ import path from 'node:path';
7
+ import { Ineligible, functionMetaReason, deploymentWarnings, displayFile } from '../eligibility.js';
8
+ import { readModule } from './parse.js';
9
+ import { lowerRoute } from './ir.js';
10
+ import { emitRoute, emitCrate, RustPrinter, DEFAULT_RUNTIME_PATH, sanitizeCrateName } from './rust.js';
11
+
12
+ export { readModule, parseModule, stripTypes } from './parse.js';
13
+ export { lowerRoute, IR } from './ir.js';
14
+ export { emitRoute, emitCrate, RustPrinter, DEFAULT_RUNTIME_PATH, sanitizeCrateName, rustStr } from './rust.js';
15
+ export { Ineligible } from '../eligibility.js';
16
+
17
+ export const MANIFEST_VERSION = 1;
18
+
19
+ /**
20
+ * Compile one Lambda.
21
+ * @param {object} fn VercelFunction-like: { name, routePath, pattern, params, style, sourceFile, methods }
22
+ * @param {string} source handler source text
23
+ * @param {{ index?: number, file?: string }} opts
24
+ */
25
+ export function compileFunction(fn, source, opts = {}) {
26
+ const file = opts.file || fn.sourceFile || fn.name || 'handler.js';
27
+ const index = opts.index ?? 0;
28
+ const out = { name: fn.name, file, eligible: false, reason: null, line: null, rust: null, ir: null, kv: false, env: [], envDynamic: false, methods: null, style: null, warnings: [] };
29
+ try {
30
+ const meta = functionMetaReason(fn);
31
+ if (meta) throw new Ineligible(meta, { file });
32
+ const mod = readModule(source, { file });
33
+ const lowered = lowerRoute(mod, fn, { index, file });
34
+ out.ir = lowered.ir;
35
+ out.kv = lowered.kv;
36
+ out.env = lowered.env;
37
+ out.envDynamic = lowered.envDynamic;
38
+ out.methods = lowered.methods;
39
+ out.style = lowered.style;
40
+ out.warnings = lowered.warnings;
41
+ out.rust = emitRoute(lowered.ir, { printer: opts.printer || new RustPrinter() });
42
+ out.eligible = true;
43
+ } catch (e) {
44
+ if (e instanceof Ineligible) {
45
+ out.reason = e.reason;
46
+ out.line = e.line;
47
+ out.file = e.file || file;
48
+ } else {
49
+ out.reason = `transmuter error: ${e.message}`;
50
+ out.internalError = e;
51
+ }
52
+ }
53
+ return out;
54
+ }
55
+
56
+ /**
57
+ * Transmute a deployment.
58
+ * @param {import('../vercel.js').VercelDeployment} deployment
59
+ * @param {{ name?: string, runtimePath?: string, readSource?: (fn) => string }} opts
60
+ */
61
+ export function transmute(deployment, opts = {}) {
62
+ const name = sanitizeCrateName(opts.name || 'zoo_site');
63
+ const runtimePath = path.resolve(opts.runtimePath || DEFAULT_RUNTIME_PATH);
64
+ const readSource = opts.readSource || ((fn) => fs.readFileSync(fn.sourceFile, 'utf8'));
65
+ const report = { eligible: [], ineligible: [], warnings: deploymentWarnings(deployment) };
66
+ const routes = [];
67
+ const routeSources = [];
68
+ const mergedEnv = {};
69
+ const referencedEnv = new Set();
70
+ let envDynamic = false;
71
+ const printer = new RustPrinter();
72
+
73
+ for (const fn of deployment.functions || []) {
74
+ const file = displayFile(fn, deployment.root);
75
+ let source;
76
+ try {
77
+ const meta = functionMetaReason(fn);
78
+ if (meta) throw new Ineligible(meta, { file });
79
+ source = readSource(fn);
80
+ } catch (e) {
81
+ if (e instanceof Ineligible) { report.ineligible.push({ name: fn.name, reason: e.reason, file: e.file || file, line: e.line }); continue; }
82
+ report.ineligible.push({ name: fn.name, reason: `cannot read source: ${e.message}`, file, line: null });
83
+ continue;
84
+ }
85
+ const index = routes.length;
86
+ // one shared printer keeps temp names unique across the crate
87
+ const c = compileFunction(fn, source, { index, file, printer });
88
+ for (const w of c.warnings) report.warnings.push(`${fn.name}: ${w}`);
89
+ if (!c.eligible) {
90
+ report.ineligible.push({ name: fn.name, reason: c.reason, file: c.file, line: c.line });
91
+ if (c.internalError) report.warnings.push(`${fn.name}: ${c.internalError.stack?.split('\n').slice(0, 2).join(' ') || c.internalError.message}`);
92
+ continue;
93
+ }
94
+ routeSources.push(c.rust);
95
+ for (const k of c.env) referencedEnv.add(k);
96
+ if (c.envDynamic) envDynamic = true;
97
+ Object.assign(mergedEnv, fn.environment || {});
98
+ report.eligible.push(fn.name);
99
+ routes.push({
100
+ index,
101
+ name: fn.name,
102
+ routePath: fn.routePath,
103
+ pattern: fn.pattern,
104
+ params: fn.params || [],
105
+ methods: c.methods, // null = any method (Node-style handler); list = web-standard method exports
106
+ style: fn.style || (c.style === 'node' ? 'pages' : 'app'),
107
+ kv: c.kv,
108
+ });
109
+ }
110
+
111
+ // Environment: only what handlers read, unless one reads process.env dynamically.
112
+ const envNames = envDynamic ? Object.keys(mergedEnv) : [...referencedEnv].filter((k) => k in mergedEnv);
113
+ for (const k of referencedEnv) if (!(k in mergedEnv)) report.warnings.push(`process.env.${k} is read by a handler but not defined in .env/.env.production: it will be undefined on chain`);
114
+ if (envNames.length) report.warnings.push(`environment baked into the program (public on chain): ${envNames.join(', ')}`);
115
+ const env = envNames.map((k) => [k, String(mergedEnv[k])]);
116
+
117
+ const header = [
118
+ `${deployment.source || 'deployment'}${deployment.framework ? ` (${deployment.framework})` : ''} — ${routes.length} route(s), ${(deployment.staticFiles || []).length} static file(s)`,
119
+ ...routes.map((r) => `route ${r.index}: ${r.routePath}${r.methods ? ' [' + r.methods.join(',') + ']' : ''} ← ${r.name}`),
120
+ ].join('\n');
121
+ const crateFiles = emitCrate({ name, runtimePath, env, routes: routeSources, routeCount: routes.length, header });
122
+ const crate = { 'Cargo.toml': crateFiles['Cargo.toml'], 'src/lib.rs': crateFiles['src/lib.rs'] };
123
+
124
+ const manifest = {
125
+ version: MANIFEST_VERSION,
126
+ framework: deployment.framework || null,
127
+ routes,
128
+ static: (deployment.staticFiles || []).map((f) => ({ path: f.path, contentType: f.contentType, size: f.size })),
129
+ env: envNames,
130
+ config: deployment.config,
131
+ };
132
+ return { crate, manifest, report, crateName: crateFiles.crateName };
133
+ }
134
+
135
+ /** Write a transmuted crate to `dir` (creates src/). Returns the paths written. */
136
+ export function writeCrate(crate, dir) {
137
+ fs.mkdirSync(path.join(dir, 'src'), { recursive: true });
138
+ const written = [];
139
+ for (const [rel, text] of Object.entries(crate)) {
140
+ const p = path.join(dir, rel);
141
+ fs.mkdirSync(path.dirname(p), { recursive: true });
142
+ fs.writeFileSync(p, text);
143
+ written.push(p);
144
+ }
145
+ return written;
146
+ }