@computesdk/cloudflare 1.3.7 → 1.3.8
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 +36 -11
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -76,15 +76,38 @@ export default {
|
|
|
76
76
|
};
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
-
##
|
|
79
|
+
## Quick Start
|
|
80
|
+
|
|
81
|
+
### Gateway Mode (Recommended)
|
|
82
|
+
|
|
83
|
+
Use the gateway for zero-config auto-detection:
|
|
80
84
|
|
|
81
85
|
```typescript
|
|
82
|
-
import {
|
|
83
|
-
|
|
86
|
+
import { compute } from 'computesdk';
|
|
87
|
+
|
|
88
|
+
// Auto-detects from environment (when running in Cloudflare Workers)
|
|
89
|
+
const sandbox = await compute.sandbox.create();
|
|
90
|
+
|
|
91
|
+
// Execute Python code
|
|
92
|
+
const result = await sandbox.runCode(`
|
|
93
|
+
import sys
|
|
94
|
+
print(f"Python version: {sys.version}")
|
|
95
|
+
print("Hello from Cloudflare!")
|
|
96
|
+
`);
|
|
97
|
+
|
|
98
|
+
console.log(result.stdout);
|
|
99
|
+
await sandbox.destroy();
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Direct Mode
|
|
84
103
|
|
|
104
|
+
For direct SDK usage without the gateway:
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
import { cloudflare } from '@computesdk/cloudflare';
|
|
85
108
|
|
|
86
|
-
// Initialize
|
|
87
|
-
const
|
|
109
|
+
// Initialize with your Durable Object binding
|
|
110
|
+
const compute = cloudflare({
|
|
88
111
|
sandboxBinding: env.Sandbox, // Your Durable Object binding
|
|
89
112
|
runtime: 'python',
|
|
90
113
|
timeout: 300000,
|
|
@@ -93,10 +116,6 @@ const provider = cloudflare({
|
|
|
93
116
|
}
|
|
94
117
|
});
|
|
95
118
|
|
|
96
|
-
// Create a compute instance
|
|
97
|
-
const compute = createCompute({ provider });
|
|
98
|
-
|
|
99
|
-
// Create a sandbox
|
|
100
119
|
const sandbox = await compute.sandbox.create();
|
|
101
120
|
|
|
102
121
|
// Execute Python code
|
|
@@ -132,7 +151,6 @@ with socketserver.TCPServer(("", PORT), Handler) as httpd:
|
|
|
132
151
|
const url = await sandbox.getUrl({ port: 3000 });
|
|
133
152
|
console.log(`Service available at: ${url}`);
|
|
134
153
|
|
|
135
|
-
// Clean up
|
|
136
154
|
await sandbox.destroy();
|
|
137
155
|
```
|
|
138
156
|
|
|
@@ -156,7 +174,9 @@ await sandbox.runCode('print("Hello")', 'python');
|
|
|
156
174
|
### Environment Variables
|
|
157
175
|
|
|
158
176
|
```typescript
|
|
159
|
-
|
|
177
|
+
import { cloudflare } from '@computesdk/cloudflare';
|
|
178
|
+
|
|
179
|
+
const compute = cloudflare({
|
|
160
180
|
sandboxBinding: env.Sandbox,
|
|
161
181
|
envVars: {
|
|
162
182
|
API_KEY: 'your-api-key',
|
|
@@ -257,7 +277,12 @@ interface CloudflareConfig {
|
|
|
257
277
|
## Error Handling
|
|
258
278
|
|
|
259
279
|
```typescript
|
|
280
|
+
import { cloudflare } from '@computesdk/cloudflare';
|
|
281
|
+
|
|
260
282
|
try {
|
|
283
|
+
const compute = cloudflare({ sandboxBinding: env.Sandbox });
|
|
284
|
+
const sandbox = await compute.sandbox.create();
|
|
285
|
+
|
|
261
286
|
const result = await sandbox.runCode('invalid python syntax');
|
|
262
287
|
} catch (error) {
|
|
263
288
|
if (error.message.includes('Syntax error')) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@computesdk/cloudflare",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.8",
|
|
4
4
|
"description": "Cloudflare provider for ComputeSDK - edge code execution using Cloudflare Workers and Durable Objects",
|
|
5
5
|
"author": "Garrison",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@cloudflare/sandbox": "^0.3.0",
|
|
22
|
-
"@computesdk/provider": "1.0.
|
|
23
|
-
"computesdk": "1.10.
|
|
22
|
+
"@computesdk/provider": "1.0.2",
|
|
23
|
+
"computesdk": "1.10.2"
|
|
24
24
|
},
|
|
25
25
|
"keywords": [
|
|
26
26
|
"computesdk",
|