@daytona/sdk 0.171.0-alpha.3 → 0.171.0-alpha.5
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/package.json +9 -3
- package/cjs/CodeInterpreter.d.ts.map +0 -1
- package/cjs/ComputerUse.d.ts.map +0 -1
- package/cjs/Daytona.d.ts.map +0 -1
- package/cjs/FileSystem.d.ts.map +0 -1
- package/cjs/Git.d.ts.map +0 -1
- package/cjs/Image.d.ts.map +0 -1
- package/cjs/LspServer.d.ts.map +0 -1
- package/cjs/ObjectStorage.d.ts.map +0 -1
- package/cjs/Process.d.ts.map +0 -1
- package/cjs/PtyHandle.d.ts.map +0 -1
- package/cjs/Sandbox.d.ts.map +0 -1
- package/cjs/Snapshot.d.ts.map +0 -1
- package/cjs/Volume.d.ts.map +0 -1
- package/cjs/__tests__/helpers.d.ts +0 -6
- package/cjs/__tests__/helpers.d.ts.map +0 -1
- package/cjs/__tests__/helpers.js +0 -26
- package/cjs/__tests__/helpers.js.map +0 -1
- package/cjs/errors/DaytonaError.d.ts.map +0 -1
- package/cjs/index.d.ts.map +0 -1
- package/cjs/types/Charts.d.ts.map +0 -1
- package/cjs/types/CodeInterpreter.d.ts.map +0 -1
- package/cjs/types/ExecuteResponse.d.ts.map +0 -1
- package/cjs/types/Pty.d.ts.map +0 -1
- package/cjs/utils/Binary.d.ts.map +0 -1
- package/cjs/utils/FileTransfer.d.ts.map +0 -1
- package/cjs/utils/Import.d.ts.map +0 -1
- package/cjs/utils/Multipart.d.ts.map +0 -1
- package/cjs/utils/Runtime.d.ts.map +0 -1
- package/cjs/utils/Stream.d.ts.map +0 -1
- package/cjs/utils/WebSocket.d.ts.map +0 -1
- package/cjs/utils/otel.decorator.d.ts.map +0 -1
- package/esm/CodeInterpreter.d.ts.map +0 -1
- package/esm/ComputerUse.d.ts.map +0 -1
- package/esm/Daytona.d.ts.map +0 -1
- package/esm/FileSystem.d.ts.map +0 -1
- package/esm/Git.d.ts.map +0 -1
- package/esm/Image.d.ts.map +0 -1
- package/esm/LspServer.d.ts.map +0 -1
- package/esm/ObjectStorage.d.ts.map +0 -1
- package/esm/Process.d.ts.map +0 -1
- package/esm/PtyHandle.d.ts.map +0 -1
- package/esm/Sandbox.d.ts.map +0 -1
- package/esm/Snapshot.d.ts.map +0 -1
- package/esm/Volume.d.ts.map +0 -1
- package/esm/__tests__/helpers.d.ts +0 -6
- package/esm/__tests__/helpers.d.ts.map +0 -1
- package/esm/__tests__/helpers.js +0 -20
- package/esm/__tests__/helpers.js.map +0 -1
- package/esm/errors/DaytonaError.d.ts.map +0 -1
- package/esm/index.d.ts.map +0 -1
- package/esm/types/Charts.d.ts.map +0 -1
- package/esm/types/CodeInterpreter.d.ts.map +0 -1
- package/esm/types/ExecuteResponse.d.ts.map +0 -1
- package/esm/types/Pty.d.ts.map +0 -1
- package/esm/utils/Binary.d.ts.map +0 -1
- package/esm/utils/FileTransfer.d.ts.map +0 -1
- package/esm/utils/Import.d.ts.map +0 -1
- package/esm/utils/Multipart.d.ts.map +0 -1
- package/esm/utils/Runtime.d.ts.map +0 -1
- package/esm/utils/Stream.d.ts.map +0 -1
- package/esm/utils/WebSocket.d.ts.map +0 -1
- package/esm/utils/otel.decorator.d.ts.map +0 -1
- package/src/CodeInterpreter.d.ts +0 -94
- package/src/CodeInterpreter.js +0 -297
- package/src/CodeInterpreter.js.map +0 -1
- package/src/ComputerUse.d.ts +0 -538
- package/src/ComputerUse.js +0 -808
- package/src/ComputerUse.js.map +0 -1
- package/src/Daytona.d.ts +0 -353
- package/src/Daytona.js +0 -521
- package/src/Daytona.js.map +0 -1
- package/src/FileSystem.d.ts +0 -344
- package/src/FileSystem.js +0 -420
- package/src/FileSystem.js.map +0 -1
- package/src/Git.d.ts +0 -202
- package/src/Git.js +0 -326
- package/src/Git.js.map +0 -1
- package/src/Image.d.ts +0 -264
- package/src/Image.js +0 -586
- package/src/Image.js.map +0 -1
- package/src/LspServer.d.ts +0 -171
- package/src/LspServer.js +0 -259
- package/src/LspServer.js.map +0 -1
- package/src/ObjectStorage.d.ts +0 -78
- package/src/ObjectStorage.js +0 -199
- package/src/ObjectStorage.js.map +0 -1
- package/src/Process.d.ts +0 -489
- package/src/Process.js +0 -647
- package/src/Process.js.map +0 -1
- package/src/PtyHandle.d.ts +0 -154
- package/src/PtyHandle.js +0 -416
- package/src/PtyHandle.js.map +0 -1
- package/src/Sandbox.d.ts +0 -458
- package/src/Sandbox.js +0 -876
- package/src/Sandbox.js.map +0 -1
- package/src/Snapshot.d.ts +0 -139
- package/src/Snapshot.js +0 -248
- package/src/Snapshot.js.map +0 -1
- package/src/Volume.d.ts +0 -83
- package/src/Volume.js +0 -119
- package/src/Volume.js.map +0 -1
- package/src/__tests__/helpers.d.ts +0 -5
- package/src/__tests__/helpers.js +0 -24
- package/src/__tests__/helpers.js.map +0 -1
- package/src/errors/DaytonaError.d.ts +0 -170
- package/src/errors/DaytonaError.js +0 -258
- package/src/errors/DaytonaError.js.map +0 -1
- package/src/index.d.ts +0 -21
- package/src/index.js +0 -49
- package/src/index.js.map +0 -1
- package/src/types/Charts.d.ts +0 -37
- package/src/types/Charts.js +0 -37
- package/src/types/Charts.js.map +0 -1
- package/src/types/CodeInterpreter.d.ts +0 -76
- package/src/types/CodeInterpreter.js +0 -7
- package/src/types/CodeInterpreter.js.map +0 -1
- package/src/types/ExecuteResponse.d.ts +0 -25
- package/src/types/ExecuteResponse.js +0 -7
- package/src/types/ExecuteResponse.js.map +0 -1
- package/src/types/Pty.d.ts +0 -47
- package/src/types/Pty.js +0 -7
- package/src/types/Pty.js.map +0 -1
- package/src/utils/Binary.d.ts +0 -38
- package/src/utils/Binary.js +0 -168
- package/src/utils/Binary.js.map +0 -1
- package/src/utils/FileTransfer.d.ts +0 -14
- package/src/utils/FileTransfer.js +0 -258
- package/src/utils/FileTransfer.js.map +0 -1
- package/src/utils/Import.d.ts +0 -97
- package/src/utils/Import.js +0 -79
- package/src/utils/Import.js.map +0 -1
- package/src/utils/Multipart.d.ts +0 -28
- package/src/utils/Multipart.js +0 -115
- package/src/utils/Multipart.js.map +0 -1
- package/src/utils/Runtime.d.ts +0 -43
- package/src/utils/Runtime.js +0 -95
- package/src/utils/Runtime.js.map +0 -1
- package/src/utils/Stream.d.ts +0 -19
- package/src/utils/Stream.js +0 -364
- package/src/utils/Stream.js.map +0 -1
- package/src/utils/WebSocket.d.ts +0 -9
- package/src/utils/WebSocket.js +0 -26
- package/src/utils/WebSocket.js.map +0 -1
- package/src/utils/otel.decorator.d.ts +0 -82
- package/src/utils/otel.decorator.js +0 -141
- package/src/utils/otel.decorator.js.map +0 -1
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module code-interpreter
|
|
3
|
-
*/
|
|
4
|
-
import { InterpreterContext } from '@daytona/toolbox-api-client';
|
|
5
|
-
/**
|
|
6
|
-
* Represents stdout or stderr output from code execution.
|
|
7
|
-
*/
|
|
8
|
-
export interface OutputMessage {
|
|
9
|
-
/**
|
|
10
|
-
* Output content.
|
|
11
|
-
*/
|
|
12
|
-
output: string;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Represents an error that occurred during code execution.
|
|
16
|
-
*/
|
|
17
|
-
export interface ExecutionError {
|
|
18
|
-
/**
|
|
19
|
-
* Error type/class name (e.g., "ValueError", "SyntaxError").
|
|
20
|
-
*/
|
|
21
|
-
name: string;
|
|
22
|
-
/**
|
|
23
|
-
* Error value/message.
|
|
24
|
-
*/
|
|
25
|
-
value: string;
|
|
26
|
-
/**
|
|
27
|
-
* Full traceback for the error, if available.
|
|
28
|
-
*/
|
|
29
|
-
traceback?: string;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Result of code execution.
|
|
33
|
-
*/
|
|
34
|
-
export interface ExecutionResult {
|
|
35
|
-
/**
|
|
36
|
-
* Standard output captured during execution.
|
|
37
|
-
*/
|
|
38
|
-
stdout: string;
|
|
39
|
-
/**
|
|
40
|
-
* Standard error captured during execution.
|
|
41
|
-
*/
|
|
42
|
-
stderr: string;
|
|
43
|
-
/**
|
|
44
|
-
* Details about an execution error, if one occurred.
|
|
45
|
-
*/
|
|
46
|
-
error?: ExecutionError;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Options for executing code in the interpreter.
|
|
50
|
-
*/
|
|
51
|
-
export interface RunCodeOptions {
|
|
52
|
-
/**
|
|
53
|
-
* Interpreter context to run code in.
|
|
54
|
-
*/
|
|
55
|
-
context?: InterpreterContext;
|
|
56
|
-
/**
|
|
57
|
-
* Environment variables for this execution.
|
|
58
|
-
*/
|
|
59
|
-
envs?: Record<string, string>;
|
|
60
|
-
/**
|
|
61
|
-
* Timeout in seconds. Set to 0 for no timeout. Default is 10 minutes.
|
|
62
|
-
*/
|
|
63
|
-
timeout?: number;
|
|
64
|
-
/**
|
|
65
|
-
* Callback for stdout messages.
|
|
66
|
-
*/
|
|
67
|
-
onStdout?: (message: OutputMessage) => any | Promise<any>;
|
|
68
|
-
/**
|
|
69
|
-
* Callback for stderr messages.
|
|
70
|
-
*/
|
|
71
|
-
onStderr?: (message: OutputMessage) => any | Promise<any>;
|
|
72
|
-
/**
|
|
73
|
-
* Callback for execution errors (e.g., runtime exceptions).
|
|
74
|
-
*/
|
|
75
|
-
onError?: (error: ExecutionError) => any | Promise<any>;
|
|
76
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CodeInterpreter.js","sourceRoot":"","sources":["../../../../../libs/sdk-typescript/src/types/CodeInterpreter.ts"],"names":[],"mappings":";AAAA;;;GAGG"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { Chart } from './Charts';
|
|
2
|
-
/**
|
|
3
|
-
* Artifacts from the command execution.
|
|
4
|
-
*
|
|
5
|
-
* @interface
|
|
6
|
-
* @property stdout - Standard output from the command, same as `result` in `ExecuteResponse`
|
|
7
|
-
* @property charts - List of chart metadata from matplotlib
|
|
8
|
-
*/
|
|
9
|
-
export interface ExecutionArtifacts {
|
|
10
|
-
stdout: string;
|
|
11
|
-
charts?: Chart[];
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Response from the command execution.
|
|
15
|
-
*
|
|
16
|
-
* @interface
|
|
17
|
-
* @property exitCode - The exit code from the command execution
|
|
18
|
-
* @property result - The output from the command execution
|
|
19
|
-
* @property artifacts - Artifacts from the command execution
|
|
20
|
-
*/
|
|
21
|
-
export interface ExecuteResponse {
|
|
22
|
-
exitCode: number;
|
|
23
|
-
result: string;
|
|
24
|
-
artifacts?: ExecutionArtifacts;
|
|
25
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ExecuteResponse.js","sourceRoot":"","sources":["../../../../../libs/sdk-typescript/src/types/ExecuteResponse.ts"],"names":[],"mappings":";AAAA;;;GAGG"}
|
package/src/types/Pty.d.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Options for creating a PTY session
|
|
3
|
-
*/
|
|
4
|
-
export interface PtyCreateOptions {
|
|
5
|
-
/**
|
|
6
|
-
* The unique identifier for the PTY session
|
|
7
|
-
*/
|
|
8
|
-
id: string;
|
|
9
|
-
/**
|
|
10
|
-
* Starting directory for the PTY session, defaults to the sandbox's working directory
|
|
11
|
-
*/
|
|
12
|
-
cwd?: string;
|
|
13
|
-
/**
|
|
14
|
-
* Environment variables for the PTY session
|
|
15
|
-
*/
|
|
16
|
-
envs?: Record<string, string>;
|
|
17
|
-
/**
|
|
18
|
-
* Number of terminal columns
|
|
19
|
-
*/
|
|
20
|
-
cols?: number;
|
|
21
|
-
/**
|
|
22
|
-
* Number of terminal rows
|
|
23
|
-
*/
|
|
24
|
-
rows?: number;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Options for connecting to a PTY session
|
|
28
|
-
*/
|
|
29
|
-
export interface PtyConnectOptions {
|
|
30
|
-
/**
|
|
31
|
-
* Callback to handle PTY output data
|
|
32
|
-
*/
|
|
33
|
-
onData: (data: Uint8Array) => void | Promise<void>;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* PTY session result on exit
|
|
37
|
-
*/
|
|
38
|
-
export interface PtyResult {
|
|
39
|
-
/**
|
|
40
|
-
* Exit code when the PTY process ends
|
|
41
|
-
*/
|
|
42
|
-
exitCode?: number;
|
|
43
|
-
/**
|
|
44
|
-
* Error message if the PTY failed
|
|
45
|
-
*/
|
|
46
|
-
error?: string;
|
|
47
|
-
}
|
package/src/types/Pty.js
DELETED
package/src/types/Pty.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Pty.js","sourceRoot":"","sources":["../../../../../libs/sdk-typescript/src/types/Pty.ts"],"names":[],"mappings":";AAAA;;;GAGG"}
|
package/src/utils/Binary.d.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { Buffer } from 'buffer';
|
|
2
|
-
/**
|
|
3
|
-
* Converts various data types to Uint8Array
|
|
4
|
-
*/
|
|
5
|
-
export declare function toUint8Array(data: string | ArrayBuffer | ArrayBufferView): Uint8Array;
|
|
6
|
-
/**
|
|
7
|
-
* Concatenates multiple Uint8Array chunks into a single Uint8Array
|
|
8
|
-
*/
|
|
9
|
-
export declare function concatUint8Arrays(parts: Uint8Array[]): Uint8Array;
|
|
10
|
-
/**
|
|
11
|
-
* Converts Uint8Array to Buffer (uses polyfill in non-Node environments)
|
|
12
|
-
*/
|
|
13
|
-
export declare function toBuffer(data: Uint8Array): Buffer;
|
|
14
|
-
/**
|
|
15
|
-
* Decodes Uint8Array to UTF-8 string
|
|
16
|
-
*/
|
|
17
|
-
export declare function utf8Decode(data: Uint8Array): string;
|
|
18
|
-
/**
|
|
19
|
-
* Finds all occurrences of a pattern in a byte buffer
|
|
20
|
-
*/
|
|
21
|
-
export declare function findAllBytes(buffer: Uint8Array, pattern: Uint8Array): number[];
|
|
22
|
-
/**
|
|
23
|
-
* Finds the first occurrence of a pattern in a byte buffer within a range
|
|
24
|
-
*/
|
|
25
|
-
export declare function findBytesInRange(buffer: Uint8Array, start: number, end: number, pattern: Uint8Array): number;
|
|
26
|
-
/**
|
|
27
|
-
* Checks if a sequence starts at a given position in a byte buffer
|
|
28
|
-
* Returns the position after the sequence if found, -1 otherwise
|
|
29
|
-
*/
|
|
30
|
-
export declare function indexAfterSequence(buffer: Uint8Array, start: number, sequence: Uint8Array): number;
|
|
31
|
-
/**
|
|
32
|
-
* Collects all bytes from various stream types into a single Uint8Array
|
|
33
|
-
*/
|
|
34
|
-
export declare function collectStreamBytes(stream: any): Promise<Uint8Array>;
|
|
35
|
-
/**
|
|
36
|
-
* Checks if value is a File object (browser environment)
|
|
37
|
-
*/
|
|
38
|
-
export declare function isFile(value: any): boolean;
|
package/src/utils/Binary.js
DELETED
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright 2025 Daytona Platforms Inc.
|
|
4
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
-
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.toUint8Array = toUint8Array;
|
|
8
|
-
exports.concatUint8Arrays = concatUint8Arrays;
|
|
9
|
-
exports.toBuffer = toBuffer;
|
|
10
|
-
exports.utf8Decode = utf8Decode;
|
|
11
|
-
exports.findAllBytes = findAllBytes;
|
|
12
|
-
exports.findBytesInRange = findBytesInRange;
|
|
13
|
-
exports.indexAfterSequence = indexAfterSequence;
|
|
14
|
-
exports.collectStreamBytes = collectStreamBytes;
|
|
15
|
-
exports.isFile = isFile;
|
|
16
|
-
const buffer_1 = require("buffer");
|
|
17
|
-
const DaytonaError_1 = require("../errors/DaytonaError");
|
|
18
|
-
/**
|
|
19
|
-
* Converts various data types to Uint8Array
|
|
20
|
-
*/
|
|
21
|
-
function toUint8Array(data) {
|
|
22
|
-
if (typeof data === 'string') {
|
|
23
|
-
return new TextEncoder().encode(data);
|
|
24
|
-
}
|
|
25
|
-
if (data instanceof ArrayBuffer) {
|
|
26
|
-
return new Uint8Array(data);
|
|
27
|
-
}
|
|
28
|
-
if (ArrayBuffer.isView(data)) {
|
|
29
|
-
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
30
|
-
}
|
|
31
|
-
throw new DaytonaError_1.DaytonaError('Unsupported data type for byte conversion.');
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Concatenates multiple Uint8Array chunks into a single Uint8Array
|
|
35
|
-
*/
|
|
36
|
-
function concatUint8Arrays(parts) {
|
|
37
|
-
const size = parts.reduce((sum, part) => sum + part.byteLength, 0);
|
|
38
|
-
const result = new Uint8Array(size);
|
|
39
|
-
let offset = 0;
|
|
40
|
-
for (const part of parts) {
|
|
41
|
-
result.set(part, offset);
|
|
42
|
-
offset += part.byteLength;
|
|
43
|
-
}
|
|
44
|
-
return result;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Converts Uint8Array to Buffer (uses polyfill in non-Node environments)
|
|
48
|
-
*/
|
|
49
|
-
function toBuffer(data) {
|
|
50
|
-
return buffer_1.Buffer.from(data);
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Decodes Uint8Array to UTF-8 string
|
|
54
|
-
*/
|
|
55
|
-
function utf8Decode(data) {
|
|
56
|
-
return new TextDecoder('utf-8').decode(data);
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Finds all occurrences of a pattern in a byte buffer
|
|
60
|
-
*/
|
|
61
|
-
function findAllBytes(buffer, pattern) {
|
|
62
|
-
const results = [];
|
|
63
|
-
let i = 0;
|
|
64
|
-
while (i <= buffer.length - pattern.length) {
|
|
65
|
-
let match = true;
|
|
66
|
-
for (let j = 0; j < pattern.length; j++) {
|
|
67
|
-
if (buffer[i + j] !== pattern[j]) {
|
|
68
|
-
match = false;
|
|
69
|
-
break;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
if (match) {
|
|
73
|
-
results.push(i);
|
|
74
|
-
i += pattern.length;
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
i++;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return results;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Finds the first occurrence of a pattern in a byte buffer within a range
|
|
84
|
-
*/
|
|
85
|
-
function findBytesInRange(buffer, start, end, pattern) {
|
|
86
|
-
let i = start;
|
|
87
|
-
while (i <= end - pattern.length) {
|
|
88
|
-
let match = true;
|
|
89
|
-
for (let j = 0; j < pattern.length; j++) {
|
|
90
|
-
if (buffer[i + j] !== pattern[j]) {
|
|
91
|
-
match = false;
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
if (match)
|
|
96
|
-
return i;
|
|
97
|
-
i++;
|
|
98
|
-
}
|
|
99
|
-
return -1;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Checks if a sequence starts at a given position in a byte buffer
|
|
103
|
-
* Returns the position after the sequence if found, -1 otherwise
|
|
104
|
-
*/
|
|
105
|
-
function indexAfterSequence(buffer, start, sequence) {
|
|
106
|
-
for (let j = 0; j < sequence.length; j++) {
|
|
107
|
-
if (buffer[start + j] !== sequence[j])
|
|
108
|
-
return -1;
|
|
109
|
-
}
|
|
110
|
-
return start + sequence.length;
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Collects all bytes from various stream types into a single Uint8Array
|
|
114
|
-
*/
|
|
115
|
-
async function collectStreamBytes(stream) {
|
|
116
|
-
if (!stream)
|
|
117
|
-
return new Uint8Array(0);
|
|
118
|
-
// ReadableStream (WHATWG)
|
|
119
|
-
if (typeof stream.getReader === 'function') {
|
|
120
|
-
const reader = stream.getReader();
|
|
121
|
-
const chunks = [];
|
|
122
|
-
try {
|
|
123
|
-
while (true) {
|
|
124
|
-
const { done, value } = await reader.read();
|
|
125
|
-
if (done)
|
|
126
|
-
break;
|
|
127
|
-
if (value?.byteLength) {
|
|
128
|
-
chunks.push(value);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
finally {
|
|
133
|
-
await reader.cancel();
|
|
134
|
-
}
|
|
135
|
-
return concatUint8Arrays(chunks);
|
|
136
|
-
}
|
|
137
|
-
// AsyncIterable
|
|
138
|
-
if (stream?.[Symbol.asyncIterator]) {
|
|
139
|
-
const chunks = [];
|
|
140
|
-
for await (const chunk of stream) {
|
|
141
|
-
chunks.push(toUint8Array(chunk));
|
|
142
|
-
}
|
|
143
|
-
return concatUint8Arrays(chunks);
|
|
144
|
-
}
|
|
145
|
-
// Direct data types
|
|
146
|
-
if (typeof stream === 'string' || stream instanceof ArrayBuffer || ArrayBuffer.isView(stream)) {
|
|
147
|
-
return toUint8Array(stream);
|
|
148
|
-
}
|
|
149
|
-
// Blob
|
|
150
|
-
if (typeof Blob !== 'undefined' && stream instanceof Blob) {
|
|
151
|
-
const arrayBuffer = await stream.arrayBuffer();
|
|
152
|
-
return new Uint8Array(arrayBuffer);
|
|
153
|
-
}
|
|
154
|
-
// Response
|
|
155
|
-
if (typeof Response !== 'undefined' && stream instanceof Response) {
|
|
156
|
-
const arrayBuffer = await stream.arrayBuffer();
|
|
157
|
-
return new Uint8Array(arrayBuffer);
|
|
158
|
-
}
|
|
159
|
-
throw new DaytonaError_1.DaytonaError('Unsupported stream type for byte collection.');
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Checks if value is a File object (browser environment)
|
|
163
|
-
*/
|
|
164
|
-
function isFile(value) {
|
|
165
|
-
const FileConstructor = globalThis.File;
|
|
166
|
-
return typeof FileConstructor !== 'undefined' && value instanceof FileConstructor;
|
|
167
|
-
}
|
|
168
|
-
//# sourceMappingURL=Binary.js.map
|
package/src/utils/Binary.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Binary.js","sourceRoot":"","sources":["../../../../../libs/sdk-typescript/src/utils/Binary.ts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e,CAAA;AACnF,CAAC"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { DownloadMetadata } from '../FileSystem';
|
|
2
|
-
/**
|
|
3
|
-
* Safely aborts a stream
|
|
4
|
-
*/
|
|
5
|
-
export declare function abortStream(stream: any): void;
|
|
6
|
-
/**
|
|
7
|
-
* Normalizes response data to extract the actual stream
|
|
8
|
-
*/
|
|
9
|
-
export declare function normalizeResponseStream(responseData: any): any;
|
|
10
|
-
/**
|
|
11
|
-
* Processes multipart response using busboy (Node.js path)
|
|
12
|
-
*/
|
|
13
|
-
export declare function processDownloadFilesResponseWithBusboy(stream: any, headers: Record<string, string>, metadataMap: Map<string, DownloadMetadata>): Promise<void>;
|
|
14
|
-
export declare function processDownloadFilesResponseWithBuffered(stream: any, headers: Record<string, string>, metadataMap: Map<string, DownloadMetadata>): Promise<void>;
|
|
@@ -1,258 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright 2025 Daytona Platforms Inc.
|
|
4
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
-
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.abortStream = abortStream;
|
|
8
|
-
exports.normalizeResponseStream = normalizeResponseStream;
|
|
9
|
-
exports.processDownloadFilesResponseWithBusboy = processDownloadFilesResponseWithBusboy;
|
|
10
|
-
exports.processDownloadFilesResponseWithBuffered = processDownloadFilesResponseWithBuffered;
|
|
11
|
-
const tslib_1 = require("tslib");
|
|
12
|
-
const buffer_1 = require("buffer");
|
|
13
|
-
const busboy_1 = tslib_1.__importDefault(require("busboy"));
|
|
14
|
-
const DaytonaError_1 = require("../errors/DaytonaError");
|
|
15
|
-
const Import_1 = require("./Import");
|
|
16
|
-
const Binary_1 = require("./Binary");
|
|
17
|
-
const Multipart_1 = require("./Multipart");
|
|
18
|
-
const Multipart_2 = require("./Multipart");
|
|
19
|
-
/**
|
|
20
|
-
* Parses a bulk-download error part into the legacy message and structured metadata.
|
|
21
|
-
*/
|
|
22
|
-
function parseDownloadErrorPart(data, contentType) {
|
|
23
|
-
let message = new TextDecoder('utf-8').decode(data).trim();
|
|
24
|
-
if (!contentType || !/application\/json/i.test(contentType)) {
|
|
25
|
-
return { message };
|
|
26
|
-
}
|
|
27
|
-
try {
|
|
28
|
-
const payload = JSON.parse(message);
|
|
29
|
-
if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {
|
|
30
|
-
return { message };
|
|
31
|
-
}
|
|
32
|
-
const payloadObject = payload;
|
|
33
|
-
const structuredMessage = payloadObject.message;
|
|
34
|
-
const statusCode = payloadObject.statusCode ?? payloadObject.status_code;
|
|
35
|
-
const errorCode = payloadObject.code ?? payloadObject.error_code;
|
|
36
|
-
if (typeof structuredMessage === 'string') {
|
|
37
|
-
message = structuredMessage;
|
|
38
|
-
}
|
|
39
|
-
return {
|
|
40
|
-
message,
|
|
41
|
-
errorDetails: {
|
|
42
|
-
message,
|
|
43
|
-
statusCode: typeof statusCode === 'number' ? statusCode : undefined,
|
|
44
|
-
errorCode: typeof errorCode === 'string' ? errorCode : undefined,
|
|
45
|
-
},
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
catch {
|
|
49
|
-
return { message };
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Records a per-file error part on the corresponding download metadata entry.
|
|
54
|
-
*/
|
|
55
|
-
function assignDownloadErrorPart(metadata, data, contentType) {
|
|
56
|
-
const { message, errorDetails } = parseDownloadErrorPart(data, contentType);
|
|
57
|
-
metadata.error = message;
|
|
58
|
-
metadata.errorDetails = errorDetails;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Safely aborts a stream
|
|
62
|
-
*/
|
|
63
|
-
function abortStream(stream) {
|
|
64
|
-
if (stream && typeof stream.destroy === 'function') {
|
|
65
|
-
stream.destroy();
|
|
66
|
-
}
|
|
67
|
-
else if (stream && typeof stream.cancel === 'function') {
|
|
68
|
-
stream.cancel();
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Normalizes response data to extract the actual stream
|
|
73
|
-
*/
|
|
74
|
-
function normalizeResponseStream(responseData) {
|
|
75
|
-
if (!responseData || typeof responseData !== 'object') {
|
|
76
|
-
return responseData;
|
|
77
|
-
}
|
|
78
|
-
// WHATWG ReadableStream
|
|
79
|
-
if (responseData.body && typeof responseData.body.getReader === 'function') {
|
|
80
|
-
return responseData.body;
|
|
81
|
-
}
|
|
82
|
-
// Some adapters use .stream
|
|
83
|
-
if (responseData.stream) {
|
|
84
|
-
return responseData.stream;
|
|
85
|
-
}
|
|
86
|
-
return responseData;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Processes multipart response using busboy (Node.js path)
|
|
90
|
-
*/
|
|
91
|
-
async function processDownloadFilesResponseWithBusboy(stream, headers, metadataMap) {
|
|
92
|
-
const fileTasks = [];
|
|
93
|
-
await new Promise((resolve, reject) => {
|
|
94
|
-
const bb = (0, busboy_1.default)({
|
|
95
|
-
headers,
|
|
96
|
-
preservePath: true,
|
|
97
|
-
});
|
|
98
|
-
bb.on('file', (fieldName, fileStream, fileInfo) => {
|
|
99
|
-
const source = fileInfo?.filename;
|
|
100
|
-
if (!source) {
|
|
101
|
-
abortStream(stream);
|
|
102
|
-
reject(new DaytonaError_1.DaytonaError(`Received unexpected file "${fileInfo?.filename}".`));
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
const metadata = metadataMap.get(source);
|
|
106
|
-
if (!metadata) {
|
|
107
|
-
abortStream(stream);
|
|
108
|
-
reject(new DaytonaError_1.DaytonaError(`Target metadata missing for valid source: ${source}`));
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
if (fieldName === 'error') {
|
|
112
|
-
// Collect per-file error metadata.
|
|
113
|
-
const chunks = [];
|
|
114
|
-
fileStream.on('data', (chunk) => chunks.push(chunk));
|
|
115
|
-
fileStream.on('end', () => {
|
|
116
|
-
assignDownloadErrorPart(metadata, buffer_1.Buffer.concat(chunks), fileInfo?.mimeType);
|
|
117
|
-
});
|
|
118
|
-
fileStream.on('error', (err) => {
|
|
119
|
-
metadata.error = `Stream error: ${err.message}`;
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
else if (fieldName === 'file') {
|
|
123
|
-
if (metadata.destination) {
|
|
124
|
-
// Stream to file
|
|
125
|
-
fileTasks.push(new Promise((resolveTask) => {
|
|
126
|
-
(0, Import_1.dynamicImport)('fs', 'Downloading files to local files is not supported: ').then((fs) => {
|
|
127
|
-
const writeStream = fs.createWriteStream(metadata.destination, { autoClose: true });
|
|
128
|
-
fileStream.pipe(writeStream);
|
|
129
|
-
writeStream.on('finish', () => {
|
|
130
|
-
metadata.result = metadata.destination;
|
|
131
|
-
resolveTask();
|
|
132
|
-
});
|
|
133
|
-
writeStream.on('error', (err) => {
|
|
134
|
-
metadata.error = `Write stream failed: ${err.message}`;
|
|
135
|
-
resolveTask();
|
|
136
|
-
});
|
|
137
|
-
fileStream.on('error', (err) => {
|
|
138
|
-
metadata.error = `Read stream failed: ${err.message}`;
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
}));
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
// Collect to buffer
|
|
145
|
-
const chunks = [];
|
|
146
|
-
fileStream.on('data', (chunk) => {
|
|
147
|
-
chunks.push(buffer_1.Buffer.isBuffer(chunk) ? chunk : buffer_1.Buffer.from(chunk));
|
|
148
|
-
});
|
|
149
|
-
fileStream.on('end', () => {
|
|
150
|
-
metadata.result = buffer_1.Buffer.concat(chunks);
|
|
151
|
-
});
|
|
152
|
-
fileStream.on('error', (err) => {
|
|
153
|
-
metadata.error = `Read failed: ${err.message}`;
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
// Unknown field, drain it
|
|
159
|
-
fileStream.resume();
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
bb.on('error', (err) => {
|
|
163
|
-
abortStream(stream);
|
|
164
|
-
reject(err);
|
|
165
|
-
});
|
|
166
|
-
bb.on('finish', resolve);
|
|
167
|
-
// Feed stream into busboy
|
|
168
|
-
feedStreamToBusboy(stream, bb).catch((err) => bb.destroy(err));
|
|
169
|
-
});
|
|
170
|
-
await Promise.all(fileTasks);
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Feeds various stream types into busboy
|
|
174
|
-
*/
|
|
175
|
-
async function feedStreamToBusboy(stream, bb) {
|
|
176
|
-
// Node.js stream (piping)
|
|
177
|
-
if (typeof stream?.pipe === 'function') {
|
|
178
|
-
stream.pipe(bb);
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
// Direct buffer-like data
|
|
182
|
-
if (typeof stream === 'string' || stream instanceof ArrayBuffer || ArrayBuffer.isView(stream)) {
|
|
183
|
-
const data = (0, Binary_1.toUint8Array)(stream);
|
|
184
|
-
bb.write(buffer_1.Buffer.from(data));
|
|
185
|
-
bb.end();
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
// WHATWG ReadableStream
|
|
189
|
-
if (typeof stream?.getReader === 'function') {
|
|
190
|
-
const reader = stream.getReader();
|
|
191
|
-
while (true) {
|
|
192
|
-
const { done, value } = await reader.read();
|
|
193
|
-
if (done)
|
|
194
|
-
break;
|
|
195
|
-
bb.write(buffer_1.Buffer.from(value));
|
|
196
|
-
}
|
|
197
|
-
bb.end();
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
// AsyncIterable
|
|
201
|
-
if (stream?.[Symbol.asyncIterator]) {
|
|
202
|
-
for await (const chunk of stream) {
|
|
203
|
-
const buffer = buffer_1.Buffer.isBuffer(chunk) ? chunk : buffer_1.Buffer.from((0, Binary_1.toUint8Array)(chunk));
|
|
204
|
-
bb.write(buffer);
|
|
205
|
-
}
|
|
206
|
-
bb.end();
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
209
|
-
// Unsupported stream type
|
|
210
|
-
throw new DaytonaError_1.DaytonaError(`Unsupported stream type: ${stream?.constructor?.name || typeof stream}`);
|
|
211
|
-
}
|
|
212
|
-
async function processDownloadFilesResponseWithBuffered(stream, headers, metadataMap) {
|
|
213
|
-
const contentType = (0, Multipart_1.getHeader)(headers, 'content-type') || '';
|
|
214
|
-
const bodyBytes = await (0, Binary_1.collectStreamBytes)(stream);
|
|
215
|
-
// Try native FormData parsing for multipart/form-data
|
|
216
|
-
if (/^multipart\/form-data/i.test(contentType) && typeof Response !== 'undefined') {
|
|
217
|
-
try {
|
|
218
|
-
const formDataParts = await (0, Multipart_1.parseMultipartWithFormData)(bodyBytes, contentType);
|
|
219
|
-
for (const part of formDataParts) {
|
|
220
|
-
const metadata = metadataMap.get(part.filename);
|
|
221
|
-
if (!metadata) {
|
|
222
|
-
continue;
|
|
223
|
-
}
|
|
224
|
-
if (part.fieldName === 'error') {
|
|
225
|
-
assignDownloadErrorPart(metadata, part.data, part.contentType);
|
|
226
|
-
}
|
|
227
|
-
else {
|
|
228
|
-
metadata.result = (0, Binary_1.toBuffer)(part.data);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
return;
|
|
232
|
-
}
|
|
233
|
-
catch {
|
|
234
|
-
// Fall through to manual parsing
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
// Manual multipart parsing (handles multipart/mixed, etc.)
|
|
238
|
-
const boundary = (0, Multipart_1.extractBoundary)(contentType);
|
|
239
|
-
if (!boundary) {
|
|
240
|
-
throw new DaytonaError_1.DaytonaError(`Missing multipart boundary in Content-Type: "${contentType}"`);
|
|
241
|
-
}
|
|
242
|
-
const parts = (0, Multipart_2.parseMultipart)(bodyBytes, boundary);
|
|
243
|
-
for (const part of parts) {
|
|
244
|
-
if (!part.filename)
|
|
245
|
-
continue;
|
|
246
|
-
const metadata = metadataMap.get(part.filename);
|
|
247
|
-
if (!metadata)
|
|
248
|
-
continue;
|
|
249
|
-
if (part.name === 'error') {
|
|
250
|
-
assignDownloadErrorPart(metadata, part.data, part.headers['content-type']);
|
|
251
|
-
}
|
|
252
|
-
else if (part.name === 'file') {
|
|
253
|
-
metadata.result = (0, Binary_1.toBuffer)(part.data);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
return;
|
|
257
|
-
}
|
|
258
|
-
//# sourceMappingURL=FileTransfer.js.map
|