vmlive 1.0.15 → 1.0.16

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/string-shim.js +39 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vmlive",
3
- "version": "1.0.15",
3
+ "version": "1.0.16",
4
4
  "description": "Local development VM for custom Serverless PaaS",
5
5
  "type": "module",
6
6
  "bin": {
@@ -109,6 +109,43 @@ export default {
109
109
  }
110
110
  };
111
111
 
112
+ const createRpcProxy = (serviceName) => new Proxy({}, {
113
+ get: (_, method) => async (...args) => {
114
+ console.log(\`\\x1b[35m[\${env.PROJECT_ID || '${projectId}'}]\\x1b[0m ☁️ \${serviceName}.\${method} proxied to vm.live edge\`);
115
+
116
+ let body;
117
+ let contentType = "application/json";
118
+
119
+ if (args.length === 1 && args[0] instanceof ArrayBuffer) {
120
+ body = args[0];
121
+ contentType = "application/octet-stream";
122
+ } else {
123
+ body = JSON.stringify({ args });
124
+ }
125
+
126
+ const req = new Request(\`https://api.vm.live/v1/internal/rpc/\${serviceName.toLowerCase()}/\${method}\`, {
127
+ method: "POST",
128
+ headers: {
129
+ "Authorization": \`Bearer \${safeEnv.BILLING_TOKEN || 'local'}\`,
130
+ "Content-Type": contentType
131
+ },
132
+ body
133
+ });
134
+ const res = await fetch(req);
135
+ if (!res.ok) throw new Error(\`vm.live RPC Error: \${await res.text()}\`);
136
+
137
+ const isStream = res.headers.get("Content-Type") === "text/event-stream";
138
+ if (isStream) return res.body;
139
+
140
+ const isBuffer = res.headers.get("Content-Type") === "application/octet-stream" || res.headers.get("Content-Type")?.includes("image/");
141
+ if (isBuffer) return await res.arrayBuffer();
142
+
143
+ return await res.json();
144
+ }
145
+ });
146
+
147
+ const AI = createRpcProxy("AI");
148
+
112
149
  // 3. Hydrate exact customEnv definition expected by the tenant code
113
150
  const customEnv = {
114
151
  ...safeEnv,
@@ -117,7 +154,8 @@ export default {
117
154
  Tasks,
118
155
  Channels,
119
156
  Discord,
120
- Slack
157
+ Slack,
158
+ AI
121
159
  };
122
160
 
123
161
  // 4. Secure boundary execution