@daytona/sdk 0.196.0 → 0.198.0
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/cjs/Daytona.d.ts +25 -2
- package/cjs/Daytona.js +60 -7
- package/cjs/Daytona.js.map +1 -1
- package/cjs/Process.js +52 -12
- package/cjs/Process.js.map +1 -1
- package/cjs/PtyHandle.d.ts +14 -0
- package/cjs/PtyHandle.js +100 -34
- package/cjs/PtyHandle.js.map +1 -1
- package/cjs/Sandbox.d.ts +128 -4
- package/cjs/Sandbox.js +493 -136
- package/cjs/Sandbox.js.map +1 -1
- package/cjs/index.d.ts +1 -1
- package/cjs/utils/EventDispatcher.d.ts +85 -0
- package/cjs/utils/EventDispatcher.js +398 -0
- package/cjs/utils/EventDispatcher.js.map +1 -0
- package/cjs/utils/EventSubscriptionManager.d.ts +14 -0
- package/cjs/utils/EventSubscriptionManager.js +98 -0
- package/cjs/utils/EventSubscriptionManager.js.map +1 -0
- package/cjs/utils/WebSocket.d.ts +2 -1
- package/cjs/utils/WebSocket.js +10 -3
- package/cjs/utils/WebSocket.js.map +1 -1
- package/esm/Daytona.d.ts +25 -2
- package/esm/Daytona.js +60 -7
- package/esm/Daytona.js.map +1 -1
- package/esm/Process.js +52 -12
- package/esm/Process.js.map +1 -1
- package/esm/PtyHandle.d.ts +14 -0
- package/esm/PtyHandle.js +100 -34
- package/esm/PtyHandle.js.map +1 -1
- package/esm/Sandbox.d.ts +128 -4
- package/esm/Sandbox.js +494 -137
- package/esm/Sandbox.js.map +1 -1
- package/esm/index.d.ts +1 -1
- package/esm/utils/EventDispatcher.d.ts +85 -0
- package/esm/utils/EventDispatcher.js +394 -0
- package/esm/utils/EventDispatcher.js.map +1 -0
- package/esm/utils/EventSubscriptionManager.d.ts +14 -0
- package/esm/utils/EventSubscriptionManager.js +94 -0
- package/esm/utils/EventSubscriptionManager.js.map +1 -0
- package/esm/utils/Import.js +1 -1
- package/esm/utils/WebSocket.d.ts +2 -1
- package/esm/utils/WebSocket.js +10 -3
- package/esm/utils/WebSocket.js.map +1 -1
- package/package.json +5 -3
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Daytona Platforms Inc.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
function createSubscriptionId() {
|
|
6
|
+
// Browser-safe UUID generation.
|
|
7
|
+
if (typeof globalThis.crypto?.randomUUID === 'function') {
|
|
8
|
+
return globalThis.crypto.randomUUID();
|
|
9
|
+
}
|
|
10
|
+
const randomHex = () => Math.floor(Math.random() * 0xffffffff)
|
|
11
|
+
.toString(16)
|
|
12
|
+
.padStart(8, '0');
|
|
13
|
+
return `${randomHex()}${randomHex()}${randomHex()}${randomHex()}`;
|
|
14
|
+
}
|
|
15
|
+
export class EventSubscriptionManager {
|
|
16
|
+
dispatcher;
|
|
17
|
+
static SUBSCRIPTION_TTL = 300;
|
|
18
|
+
subscriptions = new Map();
|
|
19
|
+
_closed = false;
|
|
20
|
+
constructor(dispatcher) {
|
|
21
|
+
this.dispatcher = dispatcher;
|
|
22
|
+
}
|
|
23
|
+
subscribe(resourceId, handler, events) {
|
|
24
|
+
// No-op when shut down or when streaming is disabled (no dispatcher) — callers poll.
|
|
25
|
+
if (this._closed || !this.dispatcher) {
|
|
26
|
+
return '';
|
|
27
|
+
}
|
|
28
|
+
const subId = createSubscriptionId();
|
|
29
|
+
const unsubscribe = this.dispatcher.subscribe(resourceId, handler, events);
|
|
30
|
+
try {
|
|
31
|
+
if (this._closed) {
|
|
32
|
+
throw new Error('EventSubscriptionManager is closed');
|
|
33
|
+
}
|
|
34
|
+
this.subscriptions.set(subId, {
|
|
35
|
+
unsubscribe,
|
|
36
|
+
timer: this.createTimer(subId),
|
|
37
|
+
});
|
|
38
|
+
return subId;
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
// Rollback dispatcher subscription on failure.
|
|
42
|
+
unsubscribe();
|
|
43
|
+
if (this._closed) {
|
|
44
|
+
return '';
|
|
45
|
+
}
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
refresh(subId) {
|
|
50
|
+
// Reject operations after shutdown to prevent use-after-close.
|
|
51
|
+
if (this._closed) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
const subscription = this.subscriptions.get(subId);
|
|
55
|
+
if (!subscription) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
clearTimeout(subscription.timer);
|
|
59
|
+
subscription.timer = this.createTimer(subId);
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
unsubscribe(subId) {
|
|
63
|
+
const subscription = this.subscriptions.get(subId);
|
|
64
|
+
if (!subscription) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
clearTimeout(subscription.timer);
|
|
68
|
+
this.subscriptions.delete(subId);
|
|
69
|
+
subscription.unsubscribe();
|
|
70
|
+
}
|
|
71
|
+
shutdown() {
|
|
72
|
+
this._closed = true;
|
|
73
|
+
for (const [subId, subscription] of this.subscriptions) {
|
|
74
|
+
clearTimeout(subscription.timer);
|
|
75
|
+
this.subscriptions.delete(subId);
|
|
76
|
+
subscription.unsubscribe();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
createTimer(subId) {
|
|
80
|
+
const timer = setTimeout(() => {
|
|
81
|
+
const subscription = this.subscriptions.get(subId);
|
|
82
|
+
if (!subscription || subscription.timer !== timer) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
this.subscriptions.delete(subId);
|
|
86
|
+
subscription.unsubscribe();
|
|
87
|
+
}, EventSubscriptionManager.SUBSCRIPTION_TTL * 1000);
|
|
88
|
+
if (typeof timer.unref === 'function') {
|
|
89
|
+
timer.unref();
|
|
90
|
+
}
|
|
91
|
+
return timer;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=EventSubscriptionManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventSubscriptionManager.js","sourceRoot":"","sources":["../../../../../sdk-typescript/src/utils/EventSubscriptionManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH,SAAS,oBAAoB;IAC3B,gCAAgC;IAChC,IAAI,OAAO,UAAU,CAAC,MAAM,EAAE,UAAU,KAAK,UAAU,EAAE,CAAC;QACxD,OAAO,UAAU,CAAC,MAAM,CAAC,UAAU,EAAE,CAAA;IACvC,CAAC;IAED,MAAM,SAAS,GAAG,GAAG,EAAE,CACrB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,UAAU,CAAC;SACnC,QAAQ,CAAC,EAAE,CAAC;SACZ,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;IACrB,OAAO,GAAG,SAAS,EAAE,GAAG,SAAS,EAAE,GAAG,SAAS,EAAE,GAAG,SAAS,EAAE,EAAE,CAAA;AACnE,CAAC;AAED,MAAM,OAAO,wBAAwB;IAKN;IAJrB,MAAM,CAAU,gBAAgB,GAAG,GAAG,CAAA;IAC7B,aAAa,GAAG,IAAI,GAAG,EAA+B,CAAA;IAC/D,OAAO,GAAG,KAAK,CAAA;IAEvB,YAA6B,UAAkC;QAAlC,eAAU,GAAV,UAAU,CAAwB;IAAG,CAAC;IAEnE,SAAS,CAAC,UAAkB,EAAE,OAAqB,EAAE,MAAgB;QACnE,qFAAqF;QACrF,IAAI,IAAI,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACrC,OAAO,EAAE,CAAA;QACX,CAAC;QAED,MAAM,KAAK,GAAG,oBAAoB,EAAE,CAAA;QACpC,MAAM,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,UAAU,EAAE,OAAO,EAAE,MAAM,CAAC,CAAA;QAE1E,IAAI,CAAC;YACH,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;gBACjB,MAAM,IAA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AAE,YAAY,CAAC,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YACvD,YAAY,CAAC,YAAY,CAAC,KAAK,CAAC,CAAA;YAChC,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;YAChC,YAAY,CAAC,WAAW,EAAE,CAAA;QAC5B,CAAC;IACH,CAAC;IAEO,WAAW,CAAC,KAAa;QAC/B,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;YAC5B,MAAM,YAAY,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;YAClD,IAAI,CAAC,YAAY,IAAI,YAAY,CAAC,KAAK,KAAK,KAAK,EAAE,CAAC;gBAClD,OAAM;YACR,CAAC;YAED,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;YAChC,YAAY,CAAC,WAAW,EAAE,CAAA;QAC5B,CAAC,EAAE,wBAAwB,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAA;QAEpD,IAAI,OAAO,KAAK,CAAC,KAAK,KAAK,UAAU,EAAE,CAAC;YACtC,KAAK,CAAC,KAAK,EAAE,CAAA;QACf,CAAC;QAED,OAAO,KAAK,CAAA;IACd,CAAC"}
|
package/esm/utils/Import.js
CHANGED
|
@@ -113,7 +113,7 @@ export function getPackageInfo() {
|
|
|
113
113
|
if (_packageInfo)
|
|
114
114
|
return _packageInfo;
|
|
115
115
|
try {
|
|
116
|
-
const pkg = {"name":"@daytona/sdk","version":"0.
|
|
116
|
+
const pkg = {"name":"@daytona/sdk","version":"0.198.0"};
|
|
117
117
|
_packageInfo = { name: pkg.name, version: pkg.version };
|
|
118
118
|
}
|
|
119
119
|
catch {
|
package/esm/utils/WebSocket.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import WebSocket from 'isomorphic-ws';
|
|
|
5
5
|
* @param url - The websocket URL (ws[s]://...)
|
|
6
6
|
* @param headers - Headers to forward when running in Node environments
|
|
7
7
|
* @param getPreviewToken - Lazy getter for preview tokens (required for browser/serverless runtimes)
|
|
8
|
+
* @param subprotocols - Additional WebSocket subprotocol tokens to negotiate (forwarded uniformly across runtimes)
|
|
8
9
|
*/
|
|
9
|
-
export declare function createSandboxWebSocket(url: string, headers: Record<string, any>, getPreviewToken: () => Promise<string
|
|
10
|
+
export declare function createSandboxWebSocket(url: string, headers: Record<string, any>, getPreviewToken: () => Promise<string>, subprotocols?: string[]): Promise<WebSocket>;
|
|
10
11
|
//# sourceMappingURL=WebSocket.d.ts.map
|
package/esm/utils/WebSocket.js
CHANGED
|
@@ -10,13 +10,20 @@ import { RUNTIME, Runtime } from './Runtime.js';
|
|
|
10
10
|
* @param url - The websocket URL (ws[s]://...)
|
|
11
11
|
* @param headers - Headers to forward when running in Node environments
|
|
12
12
|
* @param getPreviewToken - Lazy getter for preview tokens (required for browser/serverless runtimes)
|
|
13
|
+
* @param subprotocols - Additional WebSocket subprotocol tokens to negotiate (forwarded uniformly across runtimes)
|
|
13
14
|
*/
|
|
14
|
-
export async function createSandboxWebSocket(url, headers, getPreviewToken) {
|
|
15
|
+
export async function createSandboxWebSocket(url, headers, getPreviewToken, subprotocols) {
|
|
15
16
|
if (RUNTIME === Runtime.BROWSER || RUNTIME === Runtime.DENO || RUNTIME === Runtime.SERVERLESS) {
|
|
16
17
|
const previewToken = await getPreviewToken();
|
|
17
18
|
const separator = url.includes('?') ? '&' : '?';
|
|
18
|
-
return new WebSocket(`${url}${separator}DAYTONA_SANDBOX_AUTH_KEY=${previewToken}`,
|
|
19
|
+
return new WebSocket(`${url}${separator}DAYTONA_SANDBOX_AUTH_KEY=${previewToken}`, [
|
|
20
|
+
`X-Daytona-SDK-Version~${String(headers['X-Daytona-SDK-Version'] ?? '')}`,
|
|
21
|
+
...(subprotocols ?? []),
|
|
22
|
+
]);
|
|
19
23
|
}
|
|
20
|
-
|
|
24
|
+
// Node/Bun send the SDK version in the X-Daytona-SDK-Version request header, and the
|
|
25
|
+
// daemon echoes back one of the offered subprotocols, so forward the caller's tokens
|
|
26
|
+
// as-is (empty when none were provided).
|
|
27
|
+
return new WebSocket(url, subprotocols ?? [], { headers });
|
|
21
28
|
}
|
|
22
29
|
//# sourceMappingURL=WebSocket.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebSocket.js","sourceRoot":"","sources":["../../../../../sdk-typescript/src/utils/WebSocket.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,SAAS,MAAM,eAAe,CAAA;AACrC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAE5C
|
|
1
|
+
{"version":3,"file":"WebSocket.js","sourceRoot":"","sources":["../../../../../sdk-typescript/src/utils/WebSocket.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,SAAS,MAAM,eAAe,CAAA;AACrC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAE5C;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,GAAW,EACX,OAA4B,EAC5B,eAAsC,EACtC,YAAuB;IAEvB,IAAI,OAAO,KAAK,OAAO,CAAC,OAAO,IAAI,OAAO,KAAK,OAAO,CAAC,IAAI,IAAI,OAAO,KAAK,OAAO,CAAC,UAAU,EAAE,CAAC;QAC9F,MAAM,YAAY,GAAG,MAAM,eAAe,EAAE,CAAA;QAC5C,MAAM,SAAS,GAAG,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAA;QAC/C,OAAO,IAAI,SAAS,CAAC,GAAG,GAAG,GAAG,SAAS,4BAA4B,YAAY,EAAE,EAAE;YACjF,yBAAyB,MAAM,CAAC,OAAO,CAAC,uBAAuB,CAAC,IAAI,EAAE,CAAC,EAAE;YACzE,GAAG,CAAC,YAAY,IAAI,EAAE,CAAC;SACxB,CAAC,CAAA;IACJ,CAAC;IAED,qFAAqF;IACrF,qFAAqF;IACrF,yCAAyC;IACzC,OAAO,IAAI,SAAS,CAAC,GAAG,EAAE,YAAY,IAAI,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,CAAA;AAC5D,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@daytona/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.198.0",
|
|
4
4
|
"description": "Daytona TypeScript SDK for sandbox management and code execution",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -89,8 +89,10 @@
|
|
|
89
89
|
"isomorphic-ws": "^5.0.0",
|
|
90
90
|
"pathe": "^2.0.3",
|
|
91
91
|
"shell-quote": "^1.8.2",
|
|
92
|
+
"socket.io-client": "^4.8.1",
|
|
92
93
|
"tar": "^7.5.11",
|
|
93
|
-
"@daytona/api-client": "0.
|
|
94
|
-
"@daytona/toolbox-api-client": "0.
|
|
94
|
+
"@daytona/api-client": "0.198.0",
|
|
95
|
+
"@daytona/toolbox-api-client": "0.198.0",
|
|
96
|
+
"@daytona/analytics-api-client": "0.198.0"
|
|
95
97
|
}
|
|
96
98
|
}
|