@computesdk/blaxel 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.
Files changed (2) hide show
  1. package/README.md +70 -45
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -8,60 +8,52 @@ Blaxel provider for ComputeSDK - Execute code in secure Blaxel cloud sandboxes.
8
8
  npm install @computesdk/blaxel
9
9
  ```
10
10
 
11
- ## Usage
11
+ ## Quick Start
12
12
 
13
- ### With ComputeSDK
13
+ ### Gateway Mode (Recommended)
14
14
 
15
- ```typescript
16
- import { createCompute } from 'computesdk';
17
- import { blaxel } from '@computesdk/blaxel';
15
+ Use the gateway for zero-config auto-detection:
18
16
 
19
- // Set as default provider
20
- const compute = createCompute({
21
- provider: blaxel({ apiKey: process.env.BL_API_KEY })
22
- compute.setConfig({
23
- provider: blaxel({
24
- apiKey: process.env.BLAXEL_API_KEY,
25
- workspace: process.env.BLAXEL_WORKSPACE
26
- })
27
- });
17
+ ```typescript
18
+ import { compute } from 'computesdk';
28
19
 
29
- // Create sandbox
20
+ // Auto-detects Blaxel from BL_WORKSPACE/BL_API_KEY environment variables
30
21
  const sandbox = await compute.sandbox.create();
31
22
 
32
23
  // Execute code
33
24
  const result = await sandbox.runCode('console.log("Hello from Blaxel!")');
34
25
  console.log(result.stdout); // "Hello from Blaxel!"
35
26
 
36
- // Clean up
37
27
  await sandbox.destroy();
38
28
  ```
39
29
 
40
- ### Direct Usage
30
+ ### Direct Mode
31
+
32
+ For direct SDK usage without the gateway:
41
33
 
42
34
  ```typescript
43
35
  import { blaxel } from '@computesdk/blaxel';
44
36
 
45
- // Create provider with configuration
46
- const provider = blaxel({
47
- workspace: 'your-workspace',
48
- apiKey: 'your-api-key',
37
+ const compute = blaxel({
38
+ workspace: process.env.BL_WORKSPACE,
39
+ apiKey: process.env.BL_API_KEY,
49
40
  image: 'blaxel/prod-py-app:latest', // Python image
50
41
  memory: 8192, // 8GB RAM
51
42
  ports: [3000, 8080] // Exposed ports
52
43
  });
53
44
 
54
- // Use with compute singleton
55
- const sandbox = await compute.sandbox.create({
56
- provider,
57
- options: {
58
- runtime: 'python', // Runtime specified at creation time
59
- timeout: 3600000, // 1 hour timeout
60
- envs: {
61
- DEBUG: 'true'
62
- }
45
+ const sandbox = await compute.sandbox.create({
46
+ runtime: 'python', // Runtime specified at creation time
47
+ timeout: 3600000, // 1 hour timeout
48
+ envs: {
49
+ DEBUG: 'true'
63
50
  }
64
51
  });
52
+
53
+ const result = await sandbox.runCode('print("Hello from Blaxel!")');
54
+ console.log(result.stdout);
55
+
56
+ await sandbox.destroy();
65
57
  ```
66
58
 
67
59
  ## Configuration
@@ -380,7 +372,15 @@ The provider automatically detects the runtime based on code patterns:
380
372
  ## Error Handling
381
373
 
382
374
  ```typescript
375
+ import { blaxel } from '@computesdk/blaxel';
376
+
383
377
  try {
378
+ const compute = blaxel({
379
+ workspace: process.env.BL_WORKSPACE,
380
+ apiKey: process.env.BL_API_KEY
381
+ });
382
+ const sandbox = await compute.sandbox.create();
383
+
384
384
  const result = await sandbox.runCode('invalid code');
385
385
  } catch (error) {
386
386
  if (error.message.includes('Syntax error')) {
@@ -398,27 +398,19 @@ try {
398
398
  - `1` - General error or runtime error
399
399
  - `127` - Command not found
400
400
 
401
- ## Web Framework Integration
401
+ ## Examples
402
402
 
403
- Use with web frameworks via the request handler:
403
+ ### Data Processing
404
404
 
405
405
  ```typescript
406
- import { handleComputeRequest } from 'computesdk';
407
406
  import { blaxel } from '@computesdk/blaxel';
408
407
 
409
- export async function POST(request: Request) {
410
- return handleComputeRequest({
411
- request,
412
- provider: blaxel({ apiKey: process.env.BL_API_KEY })
413
- });
414
- }
415
- ```
416
-
417
- ## Examples
418
-
419
- ### Data Processing
408
+ const compute = blaxel({
409
+ workspace: process.env.BL_WORKSPACE,
410
+ apiKey: process.env.BL_API_KEY
411
+ });
412
+ const sandbox = await compute.sandbox.create();
420
413
 
421
- ```typescript
422
414
  const result = await sandbox.runCode(`
423
415
  import json
424
416
 
@@ -435,11 +427,21 @@ print(json.dumps(result))
435
427
 
436
428
  const output = JSON.parse(result.stdout);
437
429
  console.log(output); // { sum: 15, average: 3, max: 5 }
430
+
431
+ await sandbox.destroy();
438
432
  ```
439
433
 
440
434
  ### File Processing
441
435
 
442
436
  ```typescript
437
+ import { blaxel } from '@computesdk/blaxel';
438
+
439
+ const compute = blaxel({
440
+ workspace: process.env.BL_WORKSPACE,
441
+ apiKey: process.env.BL_API_KEY
442
+ });
443
+ const sandbox = await compute.sandbox.create();
444
+
443
445
  // Create data file
444
446
  await sandbox.filesystem.writeFile('/tmp/data.json',
445
447
  JSON.stringify({ users: ['Alice', 'Bob', 'Charlie'] })
@@ -465,11 +467,21 @@ with open('/tmp/result.json', 'w') as f:
465
467
  // Read result
466
468
  const resultData = await sandbox.filesystem.readFile('/tmp/result.json');
467
469
  console.log(JSON.parse(resultData));
470
+
471
+ await sandbox.destroy();
468
472
  ```
469
473
 
470
474
  ### Web Scraping Example
471
475
 
472
476
  ```typescript
477
+ import { blaxel } from '@computesdk/blaxel';
478
+
479
+ const compute = blaxel({
480
+ workspace: process.env.BL_WORKSPACE,
481
+ apiKey: process.env.BL_API_KEY
482
+ });
483
+ const sandbox = await compute.sandbox.create();
484
+
473
485
  // Install dependencies
474
486
  await sandbox.runCommand('pip', ['install', 'requests', 'beautifulsoup4']);
475
487
 
@@ -497,11 +509,22 @@ print(json.dumps(result))
497
509
  `);
498
510
 
499
511
  console.log(JSON.parse(result.stdout));
512
+
513
+ await sandbox.destroy();
500
514
  ```
501
515
 
502
516
  ### API Development
503
517
 
504
518
  ```typescript
519
+ import { blaxel } from '@computesdk/blaxel';
520
+
521
+ const compute = blaxel({
522
+ workspace: process.env.BL_WORKSPACE,
523
+ apiKey: process.env.BL_API_KEY,
524
+ ports: [3000]
525
+ });
526
+ const sandbox = await compute.sandbox.create();
527
+
505
528
  // Create a simple API server
506
529
  await sandbox.filesystem.writeFile('/tmp/server.js', `
507
530
  const http = require('http');
@@ -536,6 +559,8 @@ const privateUrl = await sandbox.getUrl({
536
559
  }
537
560
  });
538
561
  console.log(`Private API: ${privateUrl}`);
562
+
563
+ await sandbox.destroy();
539
564
  ```
540
565
 
541
566
  ## Authentication Methods
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@computesdk/blaxel",
3
- "version": "1.3.7",
3
+ "version": "1.3.8",
4
4
  "description": "Blaxel provider for ComputeSDK - lightweight cloud sandboxes for code execution",
5
5
  "author": "ComputeSDK",
6
6
  "license": "MIT",
@@ -19,8 +19,8 @@
19
19
  ],
20
20
  "dependencies": {
21
21
  "@blaxel/core": "^0.2.42",
22
- "@computesdk/provider": "1.0.1",
23
- "computesdk": "1.10.1"
22
+ "@computesdk/provider": "1.0.2",
23
+ "computesdk": "1.10.2"
24
24
  },
25
25
  "keywords": [
26
26
  "computesdk",