@daytonaio/sdk 0.10.0 → 0.10.2

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
@@ -2,33 +2,6 @@
2
2
 
3
3
  A TypeScript SDK for interacting with Daytona Server API, providing a simple interface for Daytona Workspace management, Git operations, file system operations, and language server protocol support.
4
4
 
5
- ## Prerequisites
6
-
7
- Before using the Daytona SDK, you need to have a running Daytona server instance and proper configuration.
8
-
9
- ### Server Installation
10
-
11
- For detailed instructions on installing and setting up the Daytona server, please refer to the official installation guide at:
12
- [https://github.com/daytonaio/daytona](https://github.com/daytonaio/daytona)
13
-
14
- ### Configuration
15
-
16
- To use the SDK, you'll need two essential pieces of information:
17
-
18
- 1. **Server Address**:
19
-
20
- - Run `daytona server config` to get your server's configuration
21
- - Look for the `API URL` value in the output
22
- - For testing and development, you can use the FRP address provided
23
- - For production environments, it's recommended to use a static address
24
-
25
- 2. **API Key**:
26
- - Generate a new API key by running:
27
- ```bash
28
- daytona api-key generate
29
- ```
30
- - Save this key securely as it will be needed to authenticate with the server
31
-
32
5
  ## Installation
33
6
 
34
7
  You can install the package using npm:
@@ -50,41 +23,33 @@ Here's a simple example of using the SDK:
50
23
  ```typescript
51
24
  import { Daytona } from '@daytonaio/sdk'
52
25
 
53
- // Initialize the Daytona client
26
+ // Initialize using environment variables
54
27
  const daytona = new Daytona()
55
28
 
56
- // Create the workspace instance
57
- const workspace = await daytona.create({
58
- language: 'typescript',
59
- })
29
+ // Create a workspace
30
+ const workspace = await daytona.create()
60
31
 
61
- // Run the code securely inside the workspace
62
- const response = await workspace.process.code_run('console.log("Hello World!")')
32
+ // Run code in the workspace
33
+ const response = await workspace.process.codeRun('console.log("Hello World!")')
63
34
  console.log(response.result)
64
- ```
65
-
66
- ## Features
67
35
 
68
- - **Workspace Management**: Create, manage and remove workspaces
69
- - **Git Operations**: Clone repositories, manage branches, and more
70
- - **File System Operations**: Upload, download, search and manipulate files
71
- - **Language Server Protocol**: Interact with language servers for code intelligence
72
- - **Process Management**: Execute code and commands in workspaces
36
+ // Clean up when done
37
+ await daytona.remove(workspace)
38
+ ```
73
39
 
74
40
  ## Configuration
75
41
 
76
42
  The SDK can be configured using environment variables or by passing a configuration object:
77
43
 
78
44
  ```typescript
79
- import { Daytona, DaytonaConfig } from '@daytonaio/sdk'
45
+ import { Daytona } from '@daytonaio/sdk'
80
46
 
81
- const config: DaytonaConfig = {
47
+ // Initialize with configuration
48
+ const daytona = new Daytona({
82
49
  apiKey: 'your-api-key',
83
- serverUrl: 'https://your-daytona-server',
84
- target: 'your-target',
85
- }
86
-
87
- const daytona = new Daytona(config)
50
+ serverUrl: 'your-server-url',
51
+ target: 'us',
52
+ })
88
53
  ```
89
54
 
90
55
  Or using environment variables:
@@ -93,26 +58,54 @@ Or using environment variables:
93
58
  - `DAYTONA_SERVER_URL`: The Daytona server URL
94
59
  - `DAYTONA_TARGET`: Your target environment
95
60
 
61
+ You can also customize workspace creation:
62
+
63
+ ```typescript
64
+ const workspace = await daytona.create({
65
+ language: 'typescript',
66
+ envVars: { NODE_ENV: 'development' },
67
+ autoStopInterval: 60, // Auto-stop after 1 hour of inactivity
68
+ })
69
+ ```
70
+
71
+ ## Features
72
+
73
+ - **Workspace Management**: Create, manage and remove workspaces
74
+ - **Git Operations**: Clone repositories, manage branches, and more
75
+ - **File System Operations**: Upload, download, search and manipulate files
76
+ - **Language Server Protocol**: Interact with language servers for code intelligence
77
+ - **Process Management**: Execute code and commands in workspaces
78
+
96
79
  ## Examples
97
80
 
98
- ### Execute command
81
+ ### Execute Commands
99
82
 
100
83
  ```typescript
101
- const response = await workspace.process.code_run(
102
- 'print("Sum of 3 and 4 is " + str(3 + 4))',
103
- )
104
- if (response.code !== 0) {
105
- console.log(`Error: ${response.code} ${response.result}`)
106
- } else {
107
- console.log(response.result)
108
- }
84
+ // Execute a shell command
85
+ const response = await workspace.process.executeCommand('echo "Hello, World!"')
86
+ console.log(response.result)
87
+
88
+ // Run TypeScript code
89
+ const response = await workspace.process.codeRun(`
90
+ const x = 10
91
+ const y = 20
92
+ console.log(\`Sum: \${x + y}\`)
93
+ `)
94
+ console.log(response.result)
109
95
  ```
110
96
 
111
97
  ### File Operations
112
98
 
113
99
  ```typescript
114
100
  // Upload a file
115
- await workspace.fs.uploadFile('/path/to/file.txt', new Blob(['Hello, World!']))
101
+ await workspace.fs.uploadFile(
102
+ '/path/to/file.txt',
103
+ new File(
104
+ [Buffer.from('Hello, World!')],
105
+ 'file.txt',
106
+ { type: 'text/plain' }
107
+ )
108
+ )
116
109
 
117
110
  // Download a file
118
111
  const content = await workspace.fs.downloadFile('/path/to/file.txt')
package/dist/Daytona.d.ts CHANGED
@@ -229,7 +229,7 @@ export declare class Daytona {
229
229
  * };
230
230
  * const workspace = await daytona.create(params, 40);
231
231
  */
232
- create(params: CreateWorkspaceParams, timeout?: number): Promise<Workspace>;
232
+ create(params?: CreateWorkspaceParams, timeout?: number): Promise<Workspace>;
233
233
  /**
234
234
  * Gets a Sandbox by its ID.
235
235
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@daytonaio/sdk",
3
- "version": "0.10.0",
3
+ "version": "0.10.2",
4
4
  "description": "Daytona client library for AI Agents",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,6 +0,0 @@
1
- import { AxiosInstance } from 'axios';
2
- export declare class Axios {
3
- private static instance;
4
- private constructor();
5
- static getInstance(): AxiosInstance;
6
- }
@@ -1,28 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Axios = void 0;
7
- const axios_1 = __importDefault(require("axios"));
8
- class Axios {
9
- constructor() { }
10
- static getInstance() {
11
- if (!Axios.instance) {
12
- Axios.instance = axios_1.default.create();
13
- Axios.instance.interceptors.response.use((response) => {
14
- return response;
15
- }, (error) => {
16
- var _a, _b, _c;
17
- const errorMessage = ((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.message) ||
18
- ((_c = error.response) === null || _c === void 0 ? void 0 : _c.data) ||
19
- error.message ||
20
- String(error);
21
- throw new Error(errorMessage);
22
- // return Promise.reject(errorMessage);
23
- });
24
- }
25
- return Axios.instance;
26
- }
27
- }
28
- exports.Axios = Axios;
@@ -1,10 +0,0 @@
1
- /**
2
- * Helper method to parse API errors and extract meaningful messages.
3
- * Checks if error is an AxiosError and has response data with a message field.
4
- * If it does, it will return the message from the response.
5
- * If it doesn't, it will return the original error message.
6
- *
7
- * @param error - The error to parse
8
- * @returns A formatted error message string
9
- */
10
- export declare function parseApiError(error: unknown): string;
@@ -1,36 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseApiError = parseApiError;
4
- const axios_1 = require("axios");
5
- /**
6
- * Helper method to parse API errors and extract meaningful messages.
7
- * Checks if error is an AxiosError and has response data with a message field.
8
- * If it does, it will return the message from the response.
9
- * If it doesn't, it will return the original error message.
10
- *
11
- * @param error - The error to parse
12
- * @returns A formatted error message string
13
- */
14
- function parseApiError(error) {
15
- var _a;
16
- try {
17
- // Handle Axios errors
18
- if (error instanceof axios_1.AxiosError) {
19
- // Check if we have response data
20
- if ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data) {
21
- const errorData = error.response.data;
22
- // If errorData is an object with a message field
23
- if (typeof errorData === 'object' && errorData !== null) {
24
- if ('message' in errorData && typeof errorData.message === 'string') {
25
- return errorData.message;
26
- }
27
- // If no message field, we can stringify the error data
28
- return JSON.stringify(errorData);
29
- }
30
- }
31
- return error.message;
32
- }
33
- }
34
- catch (_b) { }
35
- return String(error);
36
- }
@@ -1,35 +0,0 @@
1
- /**
2
- * Custom error class for timeout-related exceptions
3
- * @extends Error
4
- */
5
- declare class TimeoutError extends Error {
6
- constructor(message?: string);
7
- /**
8
- * Checks if an error is a TimeoutError
9
- * @param error - The error to check
10
- */
11
- static isTimeoutError(error: unknown): error is TimeoutError;
12
- }
13
- /**
14
- * Configuration options for timeout behavior
15
- */
16
- interface TimeoutOptions {
17
- /** Timeout duration in seconds */
18
- timeout: number;
19
- /** Whether the operation supports abortion */
20
- abortable?: boolean;
21
- /** Optional callback to execute on timeout */
22
- onTimeout?: () => void;
23
- /** Optional custom error message for TimeoutError */
24
- errorMessage?: string;
25
- }
26
- /**
27
- * Wraps a promise with a timeout mechanism
28
- * @template T - The type of the promise result
29
- * @param promise - The promise to wrap
30
- * @param options - Timeout configuration options
31
- * @returns A promise that will reject if the timeout is exceeded
32
- * @throws {TimeoutError} When the operation times out
33
- */
34
- declare function withTimeout<T>(promise: Promise<T>, options: TimeoutOptions): Promise<T>;
35
- export { withTimeout, TimeoutError };
@@ -1,73 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TimeoutError = void 0;
4
- exports.withTimeout = withTimeout;
5
- /**
6
- * Custom error class for timeout-related exceptions
7
- * @extends Error
8
- */
9
- class TimeoutError extends Error {
10
- constructor(message = "Operation timed out") {
11
- super(message);
12
- this.name = "TimeoutError";
13
- this.message = message;
14
- Object.setPrototypeOf(this, TimeoutError.prototype);
15
- }
16
- /**
17
- * Checks if an error is a TimeoutError
18
- * @param error - The error to check
19
- */
20
- static isTimeoutError(error) {
21
- return error instanceof TimeoutError;
22
- }
23
- }
24
- exports.TimeoutError = TimeoutError;
25
- /**
26
- * Wraps a promise with a timeout mechanism
27
- * @template T - The type of the promise result
28
- * @param promise - The promise to wrap
29
- * @param options - Timeout configuration options
30
- * @returns A promise that will reject if the timeout is exceeded
31
- * @throws {TimeoutError} When the operation times out
32
- */
33
- async function withTimeout(promise, options) {
34
- const { timeout, abortable = false, onTimeout, errorMessage } = options;
35
- if (timeout == null || timeout === 0) {
36
- return promise;
37
- }
38
- if (timeout <= 0) {
39
- throw new Error("Timeout must be a non-negative number");
40
- }
41
- const defaultErrorMessage = `Operation exceeded timeout of ${timeout} seconds.`;
42
- if (abortable) {
43
- const controller = new AbortController();
44
- const timeoutId = setTimeout(() => {
45
- console.log("timeout triggered, aborting operation...");
46
- controller.abort();
47
- onTimeout === null || onTimeout === void 0 ? void 0 : onTimeout();
48
- }, timeout * 1000);
49
- try {
50
- const result = await promise;
51
- clearTimeout(timeoutId);
52
- return result;
53
- }
54
- catch (error) {
55
- clearTimeout(timeoutId);
56
- if (error instanceof DOMException && error.name === "AbortError") {
57
- console.log("abort error caught");
58
- throw new TimeoutError(errorMessage || defaultErrorMessage);
59
- }
60
- throw error;
61
- }
62
- }
63
- else {
64
- return Promise.race([
65
- promise,
66
- new Promise((_, reject) => setTimeout(() => {
67
- console.log("timeout error thrown (no abort)");
68
- onTimeout === null || onTimeout === void 0 ? void 0 : onTimeout();
69
- reject(new TimeoutError(errorMessage || defaultErrorMessage));
70
- }, timeout * 1000)),
71
- ]);
72
- }
73
- }