@blaxel/core 0.2.61 → 0.2.62-preview.65

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 CHANGED
@@ -1,116 +1,372 @@
1
- # Blaxel Typescript SDK
1
+ # Blaxel TypeScript SDK
2
2
 
3
- <p align="center">
4
- <img src="https://blaxel.ai/logo-bg.png" alt="Blaxel"/>
5
- </p>
3
+ [Blaxel](https://blaxel.ai) is a perpetual sandbox platform that achieves near instant latency by keeping infinite secure sandboxes on automatic standby, while co-hosting your agent logic to cut network overhead.
6
4
 
7
- **Blaxel is a computing platform for AI agent builders, with all the services and infrastructure to build and deploy agents efficiently.** This repository contains the TypeScript SDK to create and manage resources on Blaxel.
5
+ This repository contains Blaxel's TypeScript SDK, which lets you create and manage sandboxes and other resources on Blaxel.
8
6
 
9
- ## Table of Contents
7
+ ## Installation
10
8
 
11
- - [Installation](#installation)
12
- - [Optional libraries](#optional-libraries)
13
- - [Authentication](#authentication)
14
- - [Features](#features)
15
- - [Quickstart](#quickstart)
16
- - [Contributing](#contributing)
17
- - [License](#license)
9
+ ```bash
10
+ # npm
11
+ npm install @blaxel/core
18
12
 
13
+ # yarn
14
+ yarn add @blaxel/core
19
15
 
16
+ # bun
17
+ bun add @blaxel/core
18
+ ```
20
19
 
21
- ## Installation
20
+ ## Authentication
21
+
22
+ The SDK authenticates with your Blaxel workspace using these sources (in priority order):
22
23
 
23
- Install Blaxel core SDK, which lets you manage Blaxel resources.
24
+ 1. Blaxel CLI, when logged in
25
+ 2. Environment variables in `.env` file (`BL_WORKSPACE`, `BL_API_KEY`)
26
+ 3. System environment variables
27
+ 4. Blaxel configuration file (`~/.blaxel/config.yaml`)
28
+
29
+ When developing locally, the recommended method is to just log in to your workspace with the Blaxel CLI:
24
30
 
25
31
  ```bash
26
- ## npm
27
- npm install @blaxel/core
32
+ bl login YOUR-WORKSPACE
33
+ ```
28
34
 
29
- ## pnpm
30
- pnpm i @blaxel/core
35
+ This allows you to run Blaxel SDK functions that will automatically connect to your workspace without additional setup. When you deploy on Blaxel, this connection persists automatically.
31
36
 
32
- ## yarn
33
- yarn add @blaxel/core
37
+ When running Blaxel SDK from a remote server that is not Blaxel-hosted, we recommend using environment variables as described in the third option above.
38
+
39
+ ## Usage
40
+
41
+ ### Sandboxes
42
+
43
+ Sandboxes are secure, instant-launching compute environments that scale to zero after inactivity and resume in under 25ms.
44
+
45
+ ```typescript
46
+ import { SandboxInstance } from "@blaxel/core";
47
+
48
+ // Create a new sandbox
49
+ const sandbox = await SandboxInstance.createIfNotExists({
50
+ name: "my-sandbox",
51
+ image: "blaxel/base-image:latest",
52
+ memory: 4096,
53
+ region: "us-pdx-1",
54
+ ports: [{ target: 3000, protocol: "HTTP" }],
55
+ labels: { env: "dev", project: "my-project" },
56
+ ttl: "24h"
57
+ });
58
+
59
+ // Get existing sandbox
60
+ const existing = await SandboxInstance.get("my-sandbox");
61
+
62
+ // Delete sandbox (using class)
63
+ await SandboxInstance.delete("my-sandbox");
64
+
65
+ // Delete sandbox (using instance)
66
+ await existing.delete();
34
67
  ```
35
68
 
69
+ #### Preview URLs
36
70
 
37
- ### Optional libraries
38
- Blaxel SDK is split between multiple packages. *core* is the minimal package to connect to Blaxel. You can find other packages to help you integrate with your favorite AI framework, or set up telemetry.
71
+ Generate public preview URLs to access services running in your sandbox:
39
72
 
40
- - [@blaxel/telemetry](@blaxel/telemetry/README.md)
41
- - [@blaxel/vercel](@blaxel/vercel/README.md)
42
- - [@blaxel/llamaindex](@blaxel/llamaindex/README.md)
43
- - [@blaxel/langgraph](@blaxel/langgraph/README.md)
44
- - [@blaxel/mastra](@blaxel/mastra/README.md)
73
+ ```typescript
74
+ import { SandboxInstance } from "@blaxel/core";
45
75
 
46
- Instrumentation happens automatically when workloads run on Blaxel. To enable telemetry, simply require the SDK in your project's entry point.
47
- ```ts
48
- import "@blaxel/telemetry";
76
+ // Get existing sandbox
77
+ const sandbox = await SandboxInstance.get("my-sandbox");
78
+
79
+ // Start a web server in the sandbox
80
+ await sandbox.process.exec({
81
+ command: "npm run dev -- --port 3000",
82
+ workingDir: "/app",
83
+ waitForPorts: [3000]
84
+ });
85
+
86
+ // Create a public preview URL
87
+ const preview = await sandbox.previews.createIfNotExists({
88
+ metadata: { name: "app-preview" },
89
+ spec: {
90
+ port: 3000,
91
+ public: true
92
+ }
93
+ });
94
+
95
+ console.log(preview.spec?.url); // https://xyz.preview.bl.run
96
+ ```
97
+
98
+ Previews can also be private, with or without a custom prefix. When you create a private preview URL, a [token](https://docs.blaxel.ai/Sandboxes/Preview-url#private-preview-urls) is required to access the URL, passed as a request parameter or request header.
99
+
100
+ ```typescript
101
+ // ...
102
+
103
+ // Create a private preview URL
104
+ const privatePreview = await sandbox.previews.createIfNotExists({
105
+ metadata: { name: "private-app-preview" },
106
+ spec: {
107
+ port: 3000,
108
+ public: false
109
+ }
110
+ });
111
+
112
+ // Create a public preview URL with a custom prefix
113
+ const customPreview = await sandbox.previews.createIfNotExists({
114
+ metadata: { name: "custom-app-preview" },
115
+ spec: {
116
+ port: 3000,
117
+ prefixUrl: "my-app",
118
+ public: true
119
+ }
120
+ });
49
121
  ```
50
122
 
123
+ #### Process execution
51
124
 
52
- ### Authentication
125
+ Execute and manage processes in your sandbox:
53
126
 
54
- The Blaxel SDK authenticates with your workspace using credentials from these sources, in priority order:
55
- 1. When running on Blaxel, authentication is handled automatically
56
- 2. Variables in your .env file (`BL_WORKSPACE` and `BL_API_KEY`, or see [this page](https://docs.blaxel.ai/Agents/Variables-and-secrets) for other authentication options).
57
- 3. Environment variables from your machine
58
- 4. Configuration file created locally when you log in through Blaxel CLI (or deploy on Blaxel)
127
+ ```typescript
128
+ import { SandboxInstance } from "@blaxel/core";
59
129
 
60
- When developing locally, the recommended method is to just log in to your workspace with Blaxel CLI. This allows you to run Blaxel SDK functions that will automatically connect to your workspace without additional setup. When you deploy on Blaxel, this connection persists automatically.
130
+ // Get existing sandbox
131
+ const sandbox = await SandboxInstance.get("my-sandbox");
61
132
 
62
- When running Blaxel SDK from a remote server that is not Blaxel-hosted, we recommend using environment variables as described in the third option above.
133
+ // Execute a command
134
+ const process = await sandbox.process.exec({
135
+ name: "build-process",
136
+ command: "npm run build",
137
+ workingDir: "/app",
138
+ waitForCompletion: true,
139
+ timeout: 60000 // 60 seconds
140
+ });
63
141
 
142
+ // Kill a running process
143
+ await sandbox.process.kill("build-process");
144
+ ```
64
145
 
146
+ Restart a process if it fails, up to a maximum number of restart attempts:
65
147
 
66
- ## Features
67
- - Agents & MCP servers
68
- - [Create MCP servers](https://docs.blaxel.ai/Functions/Create-MCP-server)
69
- - [Connect to MCP servers and model APIs hosted on Blaxel](https://docs.blaxel.ai/Agents/Develop-an-agent-ts)
70
- - [Call agents from another agent](https://docs.blaxel.ai/Agents/Develop-an-agent-ts#connect-to-another-agent-multi-agent-chaining)
71
- - [Deploy on Blaxel](https://docs.blaxel.ai/Agents/Deploy-an-agent)
72
- - Sandboxes
73
- - [Create and update sandboxes and sandbox previews](https://docs.blaxel.ai/Sandboxes/Overview)
74
- - [Run filesystem operations and processes on a sandbox](https://docs.blaxel.ai/Sandboxes/Processes)
75
- - [Use environment variables or secrets](https://docs.blaxel.ai/Agents/Variables-and-secrets)
148
+ ```typescript
149
+ // ...
76
150
 
151
+ // Run with auto-restart on failure
152
+ process = await sandbox.process.exec({
153
+ name: "web-server",
154
+ command: "npm run dev -- --host 0.0.0.0 --port 3000",
155
+ restartOnFailure: true,
156
+ maxRestarts: 5
157
+ });
158
+ ```
77
159
 
160
+ #### Filesystem operations
161
+
162
+ Manage files and directories within your sandbox:
163
+
164
+ ```typescript
165
+ import { SandboxInstance } from "@blaxel/core";
166
+ import * as fs from "fs";
167
+
168
+ // Get existing sandbox
169
+ const sandbox = await SandboxInstance.get("my-sandbox");
170
+
171
+ // Write and read text files
172
+ await sandbox.fs.write("/app/config.json", '{"key": "value"}');
173
+ const content = await sandbox.fs.read("/app/config.json");
174
+
175
+ // Write and read binary files
176
+ const binaryData = fs.readFileSync("./image.png");
177
+ await sandbox.fs.writeBinary("/app/image.png", binaryData);
178
+ const blob = await sandbox.fs.readBinary("/app/image.png");
179
+
180
+ // Create directories
181
+ await sandbox.fs.mkdir("/app/uploads");
182
+
183
+ // List files
184
+ const { subdirectories, files } = await sandbox.fs.ls("/app");
185
+
186
+ // Search for text within files
187
+ const matches = await sandbox.fs.grep("pattern", "/app", {
188
+ caseSensitive: true,
189
+ contextLines: 2,
190
+ maxResults: 5,
191
+ filePattern: "*.ts",
192
+ excludeDirs: ["node_modules"]
193
+ });
194
+
195
+ // Find files and directories matching specified patterns:
196
+ const results = await sandbox.fs.find("/app", {
197
+ type: "file",
198
+ patterns: ["*.md", "*.html"],
199
+ maxResults: 1000
200
+ });
201
+
202
+ // Watch for file changes
203
+ const handle = sandbox.fs.watch("/app", (event) => {
204
+ console.log(event.op, event.path);
205
+ }, {
206
+ withContent: true,
207
+ ignore: ["node_modules", ".git"]
208
+ });
209
+
210
+ // Close watcher
211
+ handle.close();
212
+ ```
78
213
 
79
- ## Quickstart
214
+ #### Volumes
80
215
 
81
- Blaxel CLI gives you a quick way to create new applications: agents, MCP servers, jobs, etc - and deploy them to Blaxel.
216
+ Persist data by attaching and using volumes:
82
217
 
83
- **Prerequisites**:
84
- - **Node.js:** v18 or later.
85
- - **Blaxel CLI:** Make sure you have Blaxel CLI installed. If not, [install it](https://docs.blaxel.ai/cli-reference/introduction):
86
- ```bash
87
- curl -fsSL \
88
- https://raw.githubusercontent.com/blaxel-ai/toolkit/main/install.sh \
89
- | BINDIR=/usr/local/bin sudo -E sh
90
- ```
91
- - **Blaxel login:** Login to Blaxel:
92
- ```bash
93
- bl login YOUR-WORKSPACE
94
- ```
218
+ ```typescript
219
+ import { VolumeInstance, SandboxInstance } from "@blaxel/core";
95
220
 
96
- ```bash
97
- bl create-agent-app myfolder
98
- cd myfolder
99
- bl deploy
221
+ // Create a volume
222
+ const volume = await VolumeInstance.createIfNotExists({
223
+ name: "my-volume",
224
+ size: 1024, // MB
225
+ region: "us-pdx-1",
226
+ labels: { env: "test", project: "12345" }
227
+ });
228
+
229
+ // Attach volume to sandbox
230
+ const sandbox = await SandboxInstance.createIfNotExists({
231
+ name: "my-sandbox",
232
+ image: "blaxel/base-image:latest",
233
+ volumes: [
234
+ { name: "my-volume", mountPath: "/data", readOnly: false }
235
+ ]
236
+ });
237
+
238
+ // List volumes
239
+ const volumes = await VolumeInstance.list();
240
+
241
+ // Delete volume (using class)
242
+ await VolumeInstance.delete("my-volume");
243
+
244
+ // Delete volume (using instance)
245
+ await volume.delete();
100
246
  ```
101
247
 
102
- Also available:
103
- - `bl create-mcp-server`
104
- - `bl create-job`
248
+ ### Batch jobs
105
249
 
250
+ Blaxel lets you support agentic workflows by offloading asynchronous batch processing tasks to its scalable infrastructure, where they can run in parallel. Jobs can run multiple times within a single execution and accept optional input parameters.
106
251
 
252
+ ```typescript
253
+ import { blJob } from "@blaxel/core";
107
254
 
108
- ## Contributing
255
+ // Create and run a job execution
256
+ const job = blJob("job-name");
109
257
 
110
- Contributions are welcome! Please feel free to submit a Pull Request.
258
+ const executionId = await job.createExecution({
259
+ tasks: [
260
+ { name: "John" },
261
+ { name: "Jane" },
262
+ { name: "Bob" }
263
+ ]
264
+ });
111
265
 
266
+ // Get execution status
267
+ // Returns: "pending" | "running" | "completed" | "failed"
268
+ const status = await job.getExecutionStatus(executionId);
269
+
270
+ // Get execution details
271
+ const execution = await job.getExecution(executionId);
272
+ console.log(execution.status, execution.metadata);
273
+
274
+ // Wait for completion
275
+ try {
276
+ const result = await job.waitForExecution(executionId, {
277
+ maxWait: 300000, // 5 minutes (milliseconds)
278
+ interval: 2000, // Poll every 2 seconds (milliseconds)
279
+ });
280
+ console.log(`Completed: ${result.status}`);
281
+ } catch (error) {
282
+ console.log(`Timeout: ${error.message}`);
283
+ }
284
+
285
+ // List all executions
286
+ const executions = await job.listExecutions();
287
+
288
+ // Delete an execution
289
+ await job.deleteExecution(executionId);
290
+ ```
291
+
292
+ ### Framework integrations
293
+
294
+ Blaxel provides additional packages for framework-specific integrations and telemetry:
295
+
296
+ - [`@blaxel/telemetry`](./@blaxel/telemetry/README.md) - OpenTelemetry instrumentation
297
+ - [`@blaxel/vercel`](./@blaxel/vercel/README.md) - Vercel AI SDK integration
298
+ - [`@blaxel/llamaindex`](./@blaxel/llamaindex/README.md) - LlamaIndex integration
299
+ - [`@blaxel/langgraph`](./@blaxel/langgraph/README.md) - LangGraph integration
300
+ - [`@blaxel/mastra`](./@blaxel/mastra/README.md) - Mastra integration
301
+
302
+ #### Model use
303
+
304
+ Blaxel acts as a unified gateway for model APIs, centralizing access credentials, tracing and telemetry. You can integrate with any model API provider, or deploy your own custom model. When a model is deployed on Blaxel, a global API endpoint is also created to call it.
305
+
306
+ The SDK includes a helper function that creates a reference to a model deployed on Blaxel and returns a framework-specific model client that routes API calls through Blaxel's unified gateway.
307
+
308
+ ```typescript
309
+ import { blModel } from "@blaxel/core";
310
+
311
+ // With Vercel AI SDK
312
+ import { blModel } from "@blaxel/vercel";
313
+ const model = await blModel("gpt-4o-mini");
314
+
315
+ // With LangChain
316
+ import { blModel } from "@blaxel/langgraph";
317
+ const model = await blModel("claude-3-5-sonnet");
318
+
319
+ // With LlamaIndex
320
+ import { blModel } from "@blaxel/llamaindex";
321
+ const model = await blModel("gpt-4o");
322
+
323
+ // With Mastra
324
+ import { blModel } from "@blaxel/mastra";
325
+ const model = await blModel("gpt-4o-mini");
326
+ ```
327
+
328
+ #### MCP tool use
329
+
330
+ Blaxel lets you deploy and host Model Context Protocol (MCP) servers, accessible at a global endpoint over streamable HTTP.
331
+
332
+ The SDK includes a helper function that retrieves and returns tool definitions from a Blaxel-hosted MCP server in the format required by specific frameworks.
333
+
334
+ ```typescript
335
+ // With Vercel AI SDK
336
+ import { blTools } from "@blaxel/vercel";
337
+ const tools = await blTools(['blaxel-search'])
338
+
339
+ // With Mastra
340
+ import { blTools } from "@blaxel/mastra";
341
+ const tools = await blTools(['blaxel-search'])
342
+
343
+ // With LlamaIndex
344
+ import { blTools } from "@blaxel/llamaindex";
345
+ const tools = await blTools(['blaxel-search'])
346
+
347
+ // With LangChain
348
+ import { blTools } from "@blaxel/langgraph";
349
+ const tools = await blTools(['blaxel-search'])
350
+ ```
351
+
352
+ ### Telemetry
353
+
354
+ Instrumentation happens automatically when workloads run on Blaxel.
355
+
356
+ Enable automatic telemetry by importing the `@blaxel/telemetry` package:
357
+
358
+ ```typescript
359
+ import "@blaxel/telemetry";
360
+ ```
361
+
362
+ ## Requirements
363
+
364
+ - Node.js v18 or later
365
+
366
+ ## Contributing
112
367
 
368
+ Contributions are welcome! Please feel free to [submit a pull request](https://github.com/blaxel-ai/sdk-typescript/pulls).
113
369
 
114
370
  ## License
115
371
 
116
- This project is licensed under the MIT License - see the LICENSE file for details.
372
+ This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
@@ -9,8 +9,8 @@ const index_js_1 = require("../authentication/index.js");
9
9
  const env_js_1 = require("../common/env.js");
10
10
  const node_js_1 = require("../common/node.js");
11
11
  // Build info - these placeholders are replaced at build time by build:replace-imports
12
- const BUILD_VERSION = "0.2.61";
13
- const BUILD_COMMIT = "8c2f991632d65ec7b5b36da932c4e60ab2476662";
12
+ const BUILD_VERSION = "0.2.62-preview.65";
13
+ const BUILD_COMMIT = "2658def5b7af94a41f1c1c03f3776f2c20ed5187";
14
14
  const BUILD_SENTRY_DSN = "https://fd5e60e1c9820e1eef5ccebb84a07127@o4508714045276160.ingest.us.sentry.io/4510465864564736";
15
15
  // Cache for config.yaml tracking value
16
16
  let configTrackingValue = null;
@@ -9,8 +9,8 @@ const index_js_1 = require("../authentication/index.js");
9
9
  const env_js_1 = require("../common/env.js");
10
10
  const node_js_1 = require("../common/node.js");
11
11
  // Build info - these placeholders are replaced at build time by build:replace-imports
12
- const BUILD_VERSION = "0.2.61";
13
- const BUILD_COMMIT = "8c2f991632d65ec7b5b36da932c4e60ab2476662";
12
+ const BUILD_VERSION = "0.2.62-preview.65";
13
+ const BUILD_COMMIT = "2658def5b7af94a41f1c1c03f3776f2c20ed5187";
14
14
  const BUILD_SENTRY_DSN = "https://fd5e60e1c9820e1eef5ccebb84a07127@o4508714045276160.ingest.us.sentry.io/4510465864564736";
15
15
  // Cache for config.yaml tracking value
16
16
  let configTrackingValue = null;
@@ -3,8 +3,8 @@ import { authentication } from "../authentication/index.js";
3
3
  import { env } from "../common/env.js";
4
4
  import { fs, os, path } from "../common/node.js";
5
5
  // Build info - these placeholders are replaced at build time by build:replace-imports
6
- const BUILD_VERSION = "0.2.61";
7
- const BUILD_COMMIT = "8c2f991632d65ec7b5b36da932c4e60ab2476662";
6
+ const BUILD_VERSION = "0.2.62-preview.65";
7
+ const BUILD_COMMIT = "2658def5b7af94a41f1c1c03f3776f2c20ed5187";
8
8
  const BUILD_SENTRY_DSN = "https://fd5e60e1c9820e1eef5ccebb84a07127@o4508714045276160.ingest.us.sentry.io/4510465864564736";
9
9
  // Cache for config.yaml tracking value
10
10
  let configTrackingValue = null;
@@ -3,8 +3,8 @@ import { authentication } from "../authentication/index.js";
3
3
  import { env } from "../common/env.js";
4
4
  import { fs, os, path } from "../common/node.js";
5
5
  // Build info - these placeholders are replaced at build time by build:replace-imports
6
- const BUILD_VERSION = "0.2.61";
7
- const BUILD_COMMIT = "8c2f991632d65ec7b5b36da932c4e60ab2476662";
6
+ const BUILD_VERSION = "0.2.62-preview.65";
7
+ const BUILD_COMMIT = "2658def5b7af94a41f1c1c03f3776f2c20ed5187";
8
8
  const BUILD_SENTRY_DSN = "https://fd5e60e1c9820e1eef5ccebb84a07127@o4508714045276160.ingest.us.sentry.io/4510465864564736";
9
9
  // Cache for config.yaml tracking value
10
10
  let configTrackingValue = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blaxel/core",
3
- "version": "0.2.61",
3
+ "version": "0.2.62-preview.65",
4
4
  "description": "Blaxel Core SDK for TypeScript",
5
5
  "license": "MIT",
6
6
  "author": "Blaxel, INC (https://blaxel.ai)",