openzoo 0.51.4 → 0.51.6

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 (55) hide show
  1. package/README.md +12 -1
  2. package/bin/openzoo.js +21 -46
  3. package/lib/chatgpt-install.js +106 -0
  4. package/lib/chatgpt.js +108 -90
  5. package/lib/config.js +34 -0
  6. package/lib/modelcommand.js +443 -0
  7. package/lib/pay.js +60 -4
  8. package/lib/proxy.js +39 -0
  9. package/package.json +4 -7
  10. package/transmute/README.md +0 -385
  11. package/transmute/bin/openzoo-transmute.js +0 -7
  12. package/transmute/docs/OPENZOO_CLI_PATCH.md +0 -139
  13. package/transmute/docs/VERCEL_TO_SOLANA.md +0 -381
  14. package/transmute/lib/build.js +0 -381
  15. package/transmute/lib/cli.js +0 -293
  16. package/transmute/lib/compile/bytecode.js +0 -591
  17. package/transmute/lib/compile/hostids.js +0 -11
  18. package/transmute/lib/compile/index.js +0 -159
  19. package/transmute/lib/compile/ir.js +0 -1634
  20. package/transmute/lib/compile/parse.js +0 -753
  21. package/transmute/lib/compile/rust.js +0 -781
  22. package/transmute/lib/deploy.js +0 -357
  23. package/transmute/lib/eligibility.js +0 -211
  24. package/transmute/lib/gateway.js +0 -710
  25. package/transmute/lib/hub.js +0 -290
  26. package/transmute/lib/solana.js +0 -387
  27. package/transmute/lib/vercel.js +0 -296
  28. package/transmute/lib/wallet.js +0 -41
  29. package/transmute/lib/wire.js +0 -208
  30. package/transmute/prebuilt/zoo_vm.v0.so +0 -0
  31. package/transmute/runtime/zoo-host/Cargo.lock +0 -588
  32. package/transmute/runtime/zoo-host/Cargo.toml +0 -30
  33. package/transmute/runtime/zoo-host/examples/vmrun.rs +0 -43
  34. package/transmute/runtime/zoo-host/src/assets.rs +0 -214
  35. package/transmute/runtime/zoo-host/src/ctx.rs +0 -350
  36. package/transmute/runtime/zoo-host/src/fmt.rs +0 -188
  37. package/transmute/runtime/zoo-host/src/helpers.rs +0 -245
  38. package/transmute/runtime/zoo-host/src/json.rs +0 -263
  39. package/transmute/runtime/zoo-host/src/kv.rs +0 -206
  40. package/transmute/runtime/zoo-host/src/lib.rs +0 -137
  41. package/transmute/runtime/zoo-host/src/site.rs +0 -94
  42. package/transmute/runtime/zoo-host/src/val.rs +0 -1050
  43. package/transmute/runtime/zoo-host/src/vm.rs +0 -902
  44. package/transmute/runtime/zoo-host/src/wire.rs +0 -239
  45. package/transmute/runtime/zoo-vm/Cargo.lock +0 -596
  46. package/transmute/runtime/zoo-vm/Cargo.toml +0 -23
  47. package/transmute/runtime/zoo-vm/src/lib.rs +0 -92
  48. package/transmute/site/.env.production +0 -2
  49. package/transmute/site/api/echo.js +0 -10
  50. package/transmute/site/api/hello.js +0 -12
  51. package/transmute/site/api/hits.js +0 -13
  52. package/transmute/site/api/time.js +0 -5
  53. package/transmute/site/package.json +0 -6
  54. package/transmute/site/public/app.js +0 -16
  55. package/transmute/site/public/index.html +0 -96
@@ -1,239 +0,0 @@
1
- //! The Vercel node-bridge contract, as bytes.
2
- //!
3
- //! Vercel's Lambda launcher receives `{"Action":"Invoke","body":"{method,
4
- //! path, headers, encoding, body}"}` and answers `{statusCode, headers,
5
- //! encoding, body}`. `Req`/`Resp` are those two records in a compact
6
- //! little-endian layout that fits a Solana transaction.
7
- //!
8
- //! Instruction data (after the tag byte):
9
- //! ```text
10
- //! u8 route index into the program's ROUTES table
11
- //! u8 method 0 GET 1 POST 2 PUT 3 DELETE 4 PATCH 5 OPTIONS 6 HEAD
12
- //! u16 path_len + path bytes (e.g. "/api/hello/42")
13
- //! u16 query_len + query bytes (raw, no leading '?')
14
- //! u16 headers_len + headers ("name:value\n" per header, lowercase names)
15
- //! u32 body_len + body bytes
16
- //! ```
17
- //! Response bytes:
18
- //! ```text
19
- //! u16 status
20
- //! u16 headers_len + headers ("name:value\n")
21
- //! u32 body_len + body
22
- //! ```
23
- //! Emitted as `set_return_data` (first 1024 bytes) and as `sol_log_data`
24
- //! chunks `["ZOOR", u16 index, bytes]`; the gateway reassembles the chunks
25
- //! and falls back to return data.
26
- use crate::json;
27
- use crate::val::Val;
28
- use alloc::{string::String, vec::Vec};
29
- use pinocchio::Address;
30
-
31
- pub const METHODS: [&str; 7] = ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS", "HEAD"];
32
- pub const LOG_CHUNK: usize = 900;
33
- pub const MAX_RETURN_DATA: usize = 1024;
34
-
35
- pub struct Req {
36
- pub route: u8,
37
- pub method: u8,
38
- pub path: String,
39
- pub query: String,
40
- pub headers: String,
41
- pub body: Vec<u8>,
42
- }
43
-
44
- impl Req {
45
- pub fn method_str(&self) -> &'static str {
46
- METHODS.get(self.method as usize).copied().unwrap_or("GET")
47
- }
48
- /// Header lookup by lowercase name.
49
- pub fn header(&self, name: &str) -> Option<&str> {
50
- let name = name.to_ascii_lowercase();
51
- for line in self.headers.split('\n') {
52
- if let Some(i) = line.find(':') {
53
- if line[..i] == name {
54
- return Some(&line[i + 1..]);
55
- }
56
- }
57
- }
58
- None
59
- }
60
- pub fn headers_val(&self) -> Val {
61
- let mut o = Val::obj();
62
- for line in self.headers.split('\n') {
63
- if let Some(i) = line.find(':') {
64
- o.set_str(&line[..i], Val::str(&line[i + 1..]));
65
- }
66
- }
67
- o
68
- }
69
- }
70
-
71
- #[derive(Clone)]
72
- pub struct Resp {
73
- pub status: u16,
74
- pub headers: Vec<(String, String)>,
75
- pub body: Vec<u8>,
76
- }
77
-
78
- impl Default for Resp {
79
- fn default() -> Self {
80
- Resp { status: 200, headers: Vec::new(), body: Vec::new() }
81
- }
82
- }
83
-
84
- impl Resp {
85
- pub fn set_header(&mut self, name: &str, value: &str) {
86
- let name = name.to_ascii_lowercase();
87
- if let Some(h) = self.headers.iter_mut().find(|(n, _)| *n == name) {
88
- h.1 = String::from(value);
89
- } else {
90
- self.headers.push((name, String::from(value)));
91
- }
92
- }
93
- pub fn has_header(&self, name: &str) -> bool {
94
- let name = name.to_ascii_lowercase();
95
- self.headers.iter().any(|(n, _)| *n == name)
96
- }
97
- pub fn json(v: &Val, status: u16) -> Resp {
98
- let mut r = Resp { status, ..Default::default() };
99
- r.set_header("content-type", "application/json; charset=utf-8");
100
- r.body = json::stringify(v).into_bytes();
101
- r
102
- }
103
- pub fn json_error(status: u16, msg: &str) -> Resp {
104
- let mut o = Val::obj();
105
- o.set_str("error", Val::str(msg));
106
- Resp::json(&o, status)
107
- }
108
- }
109
-
110
- pub enum WireError {
111
- Short,
112
- Utf8,
113
- }
114
-
115
- fn take<'a>(b: &'a [u8], i: &mut usize, n: usize) -> Result<&'a [u8], WireError> {
116
- if *i + n > b.len() {
117
- return Err(WireError::Short);
118
- }
119
- let s = &b[*i..*i + n];
120
- *i += n;
121
- Ok(s)
122
- }
123
- fn u16_at(b: &[u8], i: &mut usize) -> Result<usize, WireError> {
124
- let s = take(b, i, 2)?;
125
- Ok(u16::from_le_bytes([s[0], s[1]]) as usize)
126
- }
127
- fn u32_at(b: &[u8], i: &mut usize) -> Result<usize, WireError> {
128
- let s = take(b, i, 4)?;
129
- Ok(u32::from_le_bytes([s[0], s[1], s[2], s[3]]) as usize)
130
- }
131
- fn str_at(b: &[u8], i: &mut usize, n: usize) -> Result<String, WireError> {
132
- let s = take(b, i, n)?;
133
- core::str::from_utf8(s).map(String::from).map_err(|_| WireError::Utf8)
134
- }
135
-
136
- pub fn parse_req(b: &[u8]) -> Result<Req, WireError> {
137
- let mut i = 0;
138
- let route = take(b, &mut i, 1)?[0];
139
- let method = take(b, &mut i, 1)?[0];
140
- let n = u16_at(b, &mut i)?;
141
- let path = str_at(b, &mut i, n)?;
142
- let n = u16_at(b, &mut i)?;
143
- let query = str_at(b, &mut i, n)?;
144
- let n = u16_at(b, &mut i)?;
145
- let headers = str_at(b, &mut i, n)?;
146
- let n = u32_at(b, &mut i)?;
147
- let body = take(b, &mut i, n)?.to_vec();
148
- Ok(Req { route, method, path, query, headers, body })
149
- }
150
-
151
- pub fn encode_req(r: &Req) -> Vec<u8> {
152
- let mut out = Vec::new();
153
- out.push(r.route);
154
- out.push(r.method);
155
- out.extend_from_slice(&(r.path.len() as u16).to_le_bytes());
156
- out.extend_from_slice(r.path.as_bytes());
157
- out.extend_from_slice(&(r.query.len() as u16).to_le_bytes());
158
- out.extend_from_slice(r.query.as_bytes());
159
- out.extend_from_slice(&(r.headers.len() as u16).to_le_bytes());
160
- out.extend_from_slice(r.headers.as_bytes());
161
- out.extend_from_slice(&(r.body.len() as u32).to_le_bytes());
162
- out.extend_from_slice(&r.body);
163
- out
164
- }
165
-
166
- pub fn encode_resp(r: &Resp) -> Vec<u8> {
167
- let mut hdr = String::new();
168
- for (k, v) in r.headers.iter() {
169
- hdr.push_str(k);
170
- hdr.push(':');
171
- hdr.push_str(v);
172
- hdr.push('\n');
173
- }
174
- let mut out = Vec::with_capacity(8 + hdr.len() + r.body.len());
175
- out.extend_from_slice(&r.status.to_le_bytes());
176
- out.extend_from_slice(&(hdr.len() as u16).to_le_bytes());
177
- out.extend_from_slice(hdr.as_bytes());
178
- out.extend_from_slice(&(r.body.len() as u32).to_le_bytes());
179
- out.extend_from_slice(&r.body);
180
- out
181
- }
182
-
183
- pub fn decode_resp(b: &[u8]) -> Result<Resp, WireError> {
184
- let mut i = 0;
185
- let status = u16_at(b, &mut i)? as u16;
186
- let n = u16_at(b, &mut i)?;
187
- let hdr = str_at(b, &mut i, n)?;
188
- let n = u32_at(b, &mut i)?;
189
- let body = take(b, &mut i, n)?.to_vec();
190
- let mut headers = Vec::new();
191
- for line in hdr.split('\n') {
192
- if let Some(c) = line.find(':') {
193
- headers.push((String::from(&line[..c]), String::from(&line[c + 1..])));
194
- }
195
- }
196
- Ok(Resp { status, headers, body })
197
- }
198
-
199
- /// Publish the response: return data (truncated at 1024) + log chunks.
200
- pub fn emit(bytes: &[u8]) {
201
- let head = &bytes[..bytes.len().min(MAX_RETURN_DATA)];
202
- pinocchio::cpi::set_return_data(head);
203
- let mut idx: u16 = 0;
204
- let mut off = 0;
205
- while off < bytes.len() {
206
- let end = (off + LOG_CHUNK).min(bytes.len());
207
- log_data(&[b"ZOOR", &idx.to_le_bytes(), &bytes[off..end]]);
208
- off = end;
209
- idx += 1;
210
- }
211
- if bytes.is_empty() {
212
- log_data(&[b"ZOOR", &0u16.to_le_bytes(), &[]]);
213
- }
214
- }
215
-
216
- pub fn log_kv_missing(pda: &Address) {
217
- log_data(&[b"ZOOK", pda.as_ref()]);
218
- }
219
-
220
- #[cfg(any(target_os = "solana", target_arch = "bpf"))]
221
- pub fn log_data(parts: &[&[u8]]) {
222
- unsafe {
223
- pinocchio::syscalls::sol_log_data(parts.as_ptr() as *const u8, parts.len() as u64);
224
- }
225
- }
226
-
227
- #[cfg(not(any(target_os = "solana", target_arch = "bpf")))]
228
- pub fn log_data(parts: &[&[u8]]) {
229
- core::hint::black_box(parts);
230
- }
231
-
232
- #[cfg(any(target_os = "solana", target_arch = "bpf"))]
233
- pub fn log_str(s: &str) {
234
- unsafe { pinocchio::syscalls::sol_log_(s.as_ptr(), s.len() as u64) }
235
- }
236
- #[cfg(not(any(target_os = "solana", target_arch = "bpf")))]
237
- pub fn log_str(s: &str) {
238
- core::hint::black_box(s);
239
- }