@daytonaio/sdk 0.127.0 → 0.128.0-alpha.1

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 (277) hide show
  1. package/LICENSE +190 -0
  2. package/{src → cjs}/CodeInterpreter.d.ts +1 -0
  3. package/cjs/CodeInterpreter.d.ts.map +1 -0
  4. package/cjs/CodeInterpreter.js.map +1 -0
  5. package/{src → cjs}/ComputerUse.d.ts +1 -0
  6. package/cjs/ComputerUse.d.ts.map +1 -0
  7. package/cjs/ComputerUse.js.map +1 -0
  8. package/{src → cjs}/Daytona.d.ts +1 -0
  9. package/cjs/Daytona.d.ts.map +1 -0
  10. package/{src → cjs}/Daytona.js +1 -0
  11. package/cjs/Daytona.js.map +1 -0
  12. package/{src → cjs}/FileSystem.d.ts +1 -0
  13. package/cjs/FileSystem.d.ts.map +1 -0
  14. package/cjs/FileSystem.js.map +1 -0
  15. package/{src → cjs}/Git.d.ts +1 -0
  16. package/cjs/Git.d.ts.map +1 -0
  17. package/cjs/Git.js.map +1 -0
  18. package/{src → cjs}/Image.d.ts +21 -0
  19. package/cjs/Image.d.ts.map +1 -0
  20. package/{src → cjs}/Image.js +123 -91
  21. package/cjs/Image.js.map +1 -0
  22. package/{src → cjs}/LspServer.d.ts +1 -0
  23. package/cjs/LspServer.d.ts.map +1 -0
  24. package/cjs/LspServer.js.map +1 -0
  25. package/{src → cjs}/ObjectStorage.d.ts +1 -0
  26. package/cjs/ObjectStorage.d.ts.map +1 -0
  27. package/cjs/ObjectStorage.js.map +1 -0
  28. package/{src → cjs}/Process.d.ts +1 -0
  29. package/cjs/Process.d.ts.map +1 -0
  30. package/cjs/Process.js.map +1 -0
  31. package/{src → cjs}/PtyHandle.d.ts +1 -0
  32. package/cjs/PtyHandle.d.ts.map +1 -0
  33. package/cjs/PtyHandle.js.map +1 -0
  34. package/cjs/README.md +147 -0
  35. package/{src → cjs}/Sandbox.d.ts +2 -17
  36. package/cjs/Sandbox.d.ts.map +1 -0
  37. package/{src → cjs}/Sandbox.js +1 -27
  38. package/cjs/Sandbox.js.map +1 -0
  39. package/{src → cjs}/Snapshot.d.ts +2 -0
  40. package/cjs/Snapshot.d.ts.map +1 -0
  41. package/{src → cjs}/Snapshot.js +9 -1
  42. package/cjs/Snapshot.js.map +1 -0
  43. package/{src → cjs}/Volume.d.ts +1 -0
  44. package/cjs/Volume.d.ts.map +1 -0
  45. package/cjs/Volume.js.map +1 -0
  46. package/{src → cjs}/code-toolbox/SandboxJsCodeToolbox.d.ts +1 -0
  47. package/cjs/code-toolbox/SandboxJsCodeToolbox.d.ts.map +1 -0
  48. package/cjs/code-toolbox/SandboxJsCodeToolbox.js.map +1 -0
  49. package/{src → cjs}/code-toolbox/SandboxPythonCodeToolbox.d.ts +1 -0
  50. package/cjs/code-toolbox/SandboxPythonCodeToolbox.d.ts.map +1 -0
  51. package/cjs/code-toolbox/SandboxPythonCodeToolbox.js.map +1 -0
  52. package/{src → cjs}/code-toolbox/SandboxTsCodeToolbox.d.ts +1 -0
  53. package/cjs/code-toolbox/SandboxTsCodeToolbox.d.ts.map +1 -0
  54. package/cjs/code-toolbox/SandboxTsCodeToolbox.js.map +1 -0
  55. package/{src → cjs}/errors/DaytonaError.d.ts +1 -0
  56. package/cjs/errors/DaytonaError.d.ts.map +1 -0
  57. package/cjs/errors/DaytonaError.js.map +1 -0
  58. package/{src → cjs}/index.d.ts +1 -0
  59. package/cjs/index.d.ts.map +1 -0
  60. package/cjs/index.js.map +1 -0
  61. package/cjs/package.json +3 -0
  62. package/{src → cjs}/types/Charts.d.ts +1 -0
  63. package/cjs/types/Charts.d.ts.map +1 -0
  64. package/cjs/types/Charts.js.map +1 -0
  65. package/{src → cjs}/types/CodeInterpreter.d.ts +1 -0
  66. package/cjs/types/CodeInterpreter.d.ts.map +1 -0
  67. package/cjs/types/CodeInterpreter.js.map +1 -0
  68. package/{src → cjs}/types/ExecuteResponse.d.ts +1 -0
  69. package/cjs/types/ExecuteResponse.d.ts.map +1 -0
  70. package/cjs/types/ExecuteResponse.js.map +1 -0
  71. package/{src → cjs}/types/Pty.d.ts +1 -0
  72. package/cjs/types/Pty.d.ts.map +1 -0
  73. package/cjs/types/Pty.js.map +1 -0
  74. package/{src → cjs}/utils/ArtifactParser.d.ts +1 -0
  75. package/cjs/utils/ArtifactParser.d.ts.map +1 -0
  76. package/cjs/utils/ArtifactParser.js.map +1 -0
  77. package/{src → cjs}/utils/Binary.d.ts +1 -0
  78. package/cjs/utils/Binary.d.ts.map +1 -0
  79. package/cjs/utils/Binary.js.map +1 -0
  80. package/{src → cjs}/utils/FileTransfer.d.ts +1 -0
  81. package/cjs/utils/FileTransfer.d.ts.map +1 -0
  82. package/cjs/utils/FileTransfer.js.map +1 -0
  83. package/{src → cjs}/utils/Import.d.ts +2 -15
  84. package/cjs/utils/Import.d.ts.map +1 -0
  85. package/cjs/utils/Import.js +81 -0
  86. package/cjs/utils/Import.js.map +1 -0
  87. package/{src → cjs}/utils/Multipart.d.ts +1 -0
  88. package/cjs/utils/Multipart.d.ts.map +1 -0
  89. package/cjs/utils/Multipart.js.map +1 -0
  90. package/{src → cjs}/utils/Runtime.d.ts +1 -0
  91. package/cjs/utils/Runtime.d.ts.map +1 -0
  92. package/cjs/utils/Runtime.js.map +1 -0
  93. package/{src → cjs}/utils/Stream.d.ts +1 -0
  94. package/cjs/utils/Stream.d.ts.map +1 -0
  95. package/cjs/utils/Stream.js.map +1 -0
  96. package/{src → cjs}/utils/WebSocket.d.ts +1 -0
  97. package/cjs/utils/WebSocket.d.ts.map +1 -0
  98. package/cjs/utils/WebSocket.js.map +1 -0
  99. package/esm/CodeInterpreter.d.ts +96 -0
  100. package/esm/CodeInterpreter.d.ts.map +1 -0
  101. package/esm/CodeInterpreter.js +295 -0
  102. package/esm/CodeInterpreter.js.map +1 -0
  103. package/esm/ComputerUse.d.ts +443 -0
  104. package/esm/ComputerUse.d.ts.map +1 -0
  105. package/esm/ComputerUse.js +509 -0
  106. package/esm/ComputerUse.js.map +1 -0
  107. package/esm/Daytona.d.ts +354 -0
  108. package/esm/Daytona.d.ts.map +1 -0
  109. package/esm/Daytona.js +410 -0
  110. package/esm/Daytona.js.map +1 -0
  111. package/esm/FileSystem.d.ts +328 -0
  112. package/esm/FileSystem.d.ts.map +1 -0
  113. package/esm/FileSystem.js +331 -0
  114. package/esm/FileSystem.js.map +1 -0
  115. package/esm/Git.d.ts +203 -0
  116. package/esm/Git.d.ts.map +1 -0
  117. package/esm/Git.js +260 -0
  118. package/esm/Git.js.map +1 -0
  119. package/esm/Image.d.ts +285 -0
  120. package/esm/Image.d.ts.map +1 -0
  121. package/esm/Image.js +569 -0
  122. package/esm/Image.js.map +1 -0
  123. package/esm/LspServer.d.ts +172 -0
  124. package/esm/LspServer.d.ts.map +1 -0
  125. package/esm/LspServer.js +204 -0
  126. package/esm/LspServer.js.map +1 -0
  127. package/esm/ObjectStorage.d.ts +79 -0
  128. package/esm/ObjectStorage.d.ts.map +1 -0
  129. package/esm/ObjectStorage.js +187 -0
  130. package/esm/ObjectStorage.js.map +1 -0
  131. package/esm/Process.d.ts +442 -0
  132. package/esm/Process.d.ts.map +1 -0
  133. package/esm/Process.js +644 -0
  134. package/esm/Process.js.map +1 -0
  135. package/esm/PtyHandle.d.ts +155 -0
  136. package/esm/PtyHandle.d.ts.map +1 -0
  137. package/esm/PtyHandle.js +374 -0
  138. package/esm/PtyHandle.js.map +1 -0
  139. package/esm/README.md +147 -0
  140. package/esm/Sandbox.d.ts +359 -0
  141. package/esm/Sandbox.d.ts.map +1 -0
  142. package/esm/Sandbox.js +532 -0
  143. package/esm/Sandbox.js.map +1 -0
  144. package/esm/Snapshot.d.ts +138 -0
  145. package/esm/Snapshot.d.ts.map +1 -0
  146. package/esm/Snapshot.js +207 -0
  147. package/esm/Snapshot.js.map +1 -0
  148. package/esm/Volume.d.ts +84 -0
  149. package/esm/Volume.d.ts.map +1 -0
  150. package/esm/Volume.js +95 -0
  151. package/esm/Volume.js.map +1 -0
  152. package/esm/code-toolbox/SandboxJsCodeToolbox.d.ts +6 -0
  153. package/esm/code-toolbox/SandboxJsCodeToolbox.d.ts.map +1 -0
  154. package/esm/code-toolbox/SandboxJsCodeToolbox.js +13 -0
  155. package/esm/code-toolbox/SandboxJsCodeToolbox.js.map +1 -0
  156. package/esm/code-toolbox/SandboxPythonCodeToolbox.d.ts +12 -0
  157. package/esm/code-toolbox/SandboxPythonCodeToolbox.d.ts.map +1 -0
  158. package/esm/code-toolbox/SandboxPythonCodeToolbox.js +355 -0
  159. package/esm/code-toolbox/SandboxPythonCodeToolbox.js.map +1 -0
  160. package/esm/code-toolbox/SandboxTsCodeToolbox.d.ts +6 -0
  161. package/esm/code-toolbox/SandboxTsCodeToolbox.d.ts.map +1 -0
  162. package/esm/code-toolbox/SandboxTsCodeToolbox.js +14 -0
  163. package/esm/code-toolbox/SandboxTsCodeToolbox.js.map +1 -0
  164. package/esm/errors/DaytonaError.d.ts +32 -0
  165. package/esm/errors/DaytonaError.d.ts.map +1 -0
  166. package/esm/errors/DaytonaError.js +44 -0
  167. package/esm/errors/DaytonaError.js.map +1 -0
  168. package/esm/index.d.ts +22 -0
  169. package/esm/index.d.ts.map +1 -0
  170. package/esm/index.js +22 -0
  171. package/esm/index.js.map +1 -0
  172. package/esm/package.json +3 -0
  173. package/esm/types/Charts.d.ts +152 -0
  174. package/esm/types/Charts.d.ts.map +1 -0
  175. package/esm/types/Charts.js +42 -0
  176. package/esm/types/Charts.js.map +1 -0
  177. package/esm/types/CodeInterpreter.d.ts +77 -0
  178. package/esm/types/CodeInterpreter.d.ts.map +1 -0
  179. package/esm/types/CodeInterpreter.js +6 -0
  180. package/esm/types/CodeInterpreter.js.map +1 -0
  181. package/esm/types/ExecuteResponse.d.ts +26 -0
  182. package/esm/types/ExecuteResponse.d.ts.map +1 -0
  183. package/esm/types/ExecuteResponse.js +6 -0
  184. package/esm/types/ExecuteResponse.js.map +1 -0
  185. package/esm/types/Pty.d.ts +48 -0
  186. package/esm/types/Pty.d.ts.map +1 -0
  187. package/esm/types/Pty.js +6 -0
  188. package/esm/types/Pty.js.map +1 -0
  189. package/esm/utils/ArtifactParser.d.ts +14 -0
  190. package/esm/utils/ArtifactParser.d.ts.map +1 -0
  191. package/esm/utils/ArtifactParser.js +51 -0
  192. package/esm/utils/ArtifactParser.js.map +1 -0
  193. package/esm/utils/Binary.d.ts +39 -0
  194. package/esm/utils/Binary.d.ts.map +1 -0
  195. package/esm/utils/Binary.js +157 -0
  196. package/esm/utils/Binary.js.map +1 -0
  197. package/esm/utils/FileTransfer.d.ts +15 -0
  198. package/esm/utils/FileTransfer.d.ts.map +1 -0
  199. package/esm/utils/FileTransfer.js +209 -0
  200. package/esm/utils/FileTransfer.js.map +1 -0
  201. package/esm/utils/Import.d.ts +211 -0
  202. package/esm/utils/Import.d.ts.map +1 -0
  203. package/esm/utils/Import.js +45 -0
  204. package/esm/utils/Import.js.map +1 -0
  205. package/esm/utils/Multipart.d.ts +27 -0
  206. package/esm/utils/Multipart.d.ts.map +1 -0
  207. package/esm/utils/Multipart.js +107 -0
  208. package/esm/utils/Multipart.js.map +1 -0
  209. package/esm/utils/Runtime.d.ts +37 -0
  210. package/esm/utils/Runtime.d.ts.map +1 -0
  211. package/esm/utils/Runtime.js +57 -0
  212. package/esm/utils/Runtime.js.map +1 -0
  213. package/esm/utils/Stream.d.ts +20 -0
  214. package/esm/utils/Stream.d.ts.map +1 -0
  215. package/esm/utils/Stream.js +360 -0
  216. package/esm/utils/Stream.js.map +1 -0
  217. package/esm/utils/WebSocket.d.ts +10 -0
  218. package/esm/utils/WebSocket.d.ts.map +1 -0
  219. package/esm/utils/WebSocket.js +22 -0
  220. package/esm/utils/WebSocket.js.map +1 -0
  221. package/package.json +20 -8
  222. package/src/CodeInterpreter.js.map +0 -1
  223. package/src/ComputerUse.js.map +0 -1
  224. package/src/Daytona.js.map +0 -1
  225. package/src/FileSystem.js.map +0 -1
  226. package/src/Git.js.map +0 -1
  227. package/src/Image.js.map +0 -1
  228. package/src/LspServer.js.map +0 -1
  229. package/src/ObjectStorage.js.map +0 -1
  230. package/src/Process.js.map +0 -1
  231. package/src/PtyHandle.js.map +0 -1
  232. package/src/Sandbox.js.map +0 -1
  233. package/src/Snapshot.js.map +0 -1
  234. package/src/Volume.js.map +0 -1
  235. package/src/code-toolbox/SandboxJsCodeToolbox.js.map +0 -1
  236. package/src/code-toolbox/SandboxPythonCodeToolbox.js.map +0 -1
  237. package/src/code-toolbox/SandboxTsCodeToolbox.js.map +0 -1
  238. package/src/errors/DaytonaError.js.map +0 -1
  239. package/src/index.js.map +0 -1
  240. package/src/types/Charts.js.map +0 -1
  241. package/src/types/CodeInterpreter.js.map +0 -1
  242. package/src/types/ExecuteResponse.js.map +0 -1
  243. package/src/types/Pty.js.map +0 -1
  244. package/src/utils/ArtifactParser.js.map +0 -1
  245. package/src/utils/Binary.js.map +0 -1
  246. package/src/utils/FileTransfer.js.map +0 -1
  247. package/src/utils/Import.js +0 -77
  248. package/src/utils/Import.js.map +0 -1
  249. package/src/utils/Multipart.js.map +0 -1
  250. package/src/utils/Runtime.js.map +0 -1
  251. package/src/utils/Stream.js.map +0 -1
  252. package/src/utils/WebSocket.js.map +0 -1
  253. /package/{src → cjs}/CodeInterpreter.js +0 -0
  254. /package/{src → cjs}/ComputerUse.js +0 -0
  255. /package/{src → cjs}/FileSystem.js +0 -0
  256. /package/{src → cjs}/Git.js +0 -0
  257. /package/{src → cjs}/LspServer.js +0 -0
  258. /package/{src → cjs}/ObjectStorage.js +0 -0
  259. /package/{src → cjs}/Process.js +0 -0
  260. /package/{src → cjs}/PtyHandle.js +0 -0
  261. /package/{src → cjs}/Volume.js +0 -0
  262. /package/{src → cjs}/code-toolbox/SandboxJsCodeToolbox.js +0 -0
  263. /package/{src → cjs}/code-toolbox/SandboxPythonCodeToolbox.js +0 -0
  264. /package/{src → cjs}/code-toolbox/SandboxTsCodeToolbox.js +0 -0
  265. /package/{src → cjs}/errors/DaytonaError.js +0 -0
  266. /package/{src → cjs}/index.js +0 -0
  267. /package/{src → cjs}/types/Charts.js +0 -0
  268. /package/{src → cjs}/types/CodeInterpreter.js +0 -0
  269. /package/{src → cjs}/types/ExecuteResponse.js +0 -0
  270. /package/{src → cjs}/types/Pty.js +0 -0
  271. /package/{src → cjs}/utils/ArtifactParser.js +0 -0
  272. /package/{src → cjs}/utils/Binary.js +0 -0
  273. /package/{src → cjs}/utils/FileTransfer.js +0 -0
  274. /package/{src → cjs}/utils/Multipart.js +0 -0
  275. /package/{src → cjs}/utils/Runtime.js +0 -0
  276. /package/{src → cjs}/utils/Stream.js +0 -0
  277. /package/{src → cjs}/utils/WebSocket.js +0 -0
@@ -0,0 +1,172 @@
1
+ import { CompletionList, LspSymbol, LspApi } from '@daytonaio/toolbox-api-client';
2
+ /**
3
+ * Supported language server types.
4
+ */
5
+ export declare enum LspLanguageId {
6
+ PYTHON = "python",
7
+ TYPESCRIPT = "typescript",
8
+ JAVASCRIPT = "javascript"
9
+ }
10
+ /**
11
+ * Represents a zero-based position within a text document,
12
+ * specified by line number and character offset.
13
+ *
14
+ * @interface
15
+ * @property {number} line - Zero-based line number in the document
16
+ * @property {number} character - Zero-based character offset on the line
17
+ *
18
+ * @example
19
+ * const position: Position = {
20
+ * line: 10, // Line 11 (zero-based)
21
+ * character: 15 // Character 16 on the line (zero-based)
22
+ * };
23
+ */
24
+ export type Position = {
25
+ /** Zero-based line number */
26
+ line: number;
27
+ /** Zero-based character offset */
28
+ character: number;
29
+ };
30
+ /**
31
+ * Provides Language Server Protocol functionality for code intelligence to provide
32
+ * IDE-like features such as code completion, symbol search, and more.
33
+ *
34
+ * @property {LspLanguageId} languageId - The language server type (e.g., "typescript")
35
+ * @property {string} pathToProject - Path to the project root directory. Relative paths are resolved based on the sandbox working directory.
36
+ * @property {LspApi} apiClient - API client for Sandbox lsp operations
37
+ * @property {SandboxInstance} instance - The Sandbox instance this server belongs to
38
+ *
39
+ * @class
40
+ */
41
+ export declare class LspServer {
42
+ private readonly languageId;
43
+ private readonly pathToProject;
44
+ private readonly apiClient;
45
+ constructor(languageId: LspLanguageId, pathToProject: string, apiClient: LspApi);
46
+ /**
47
+ * Starts the language server, must be called before using any other LSP functionality.
48
+ * It initializes the language server for the specified language and project.
49
+ *
50
+ * @returns {Promise<void>}
51
+ *
52
+ * @example
53
+ * const lsp = await sandbox.createLspServer('typescript', 'workspace/project');
54
+ * await lsp.start(); // Initialize the server
55
+ * // Now ready for LSP operations
56
+ */
57
+ start(): Promise<void>;
58
+ /**
59
+ * Stops the language server, should be called when the LSP server is no longer needed to
60
+ * free up system resources.
61
+ *
62
+ * @returns {Promise<void>}
63
+ *
64
+ * @example
65
+ * // When done with LSP features
66
+ * await lsp.stop(); // Clean up resources
67
+ */
68
+ stop(): Promise<void>;
69
+ /**
70
+ * Notifies the language server that a file has been opened, enabling
71
+ * language features like diagnostics and completions for that file. The server
72
+ * will begin tracking the file's contents and providing language features.
73
+ *
74
+ * @param {string} path - Path to the opened file. Relative paths are resolved based on the sandbox working directory.
75
+ * @returns {Promise<void>}
76
+ *
77
+ * @example
78
+ * // When opening a file for editing
79
+ * await lsp.didOpen('workspace/project/src/index.ts');
80
+ * // Now can get completions, symbols, etc. for this file
81
+ */
82
+ didOpen(path: string): Promise<void>;
83
+ /**
84
+ * Notifies the language server that a file has been closed, should be called when a file is closed
85
+ * in the editor to allow the language server to clean up any resources associated with that file.
86
+ *
87
+ * @param {string} path - Path to the closed file. Relative paths are resolved based on the project path
88
+ * set in the LSP server constructor.
89
+ * @returns {Promise<void>}
90
+ *
91
+ * @example
92
+ * // When done editing a file
93
+ * await lsp.didClose('workspace/project/src/index.ts');
94
+ */
95
+ didClose(path: string): Promise<void>;
96
+ /**
97
+ * Get symbol information (functions, classes, variables, etc.) from a document.
98
+ *
99
+ * @param {string} path - Path to the file to get symbols from. Relative paths are resolved based on the project path
100
+ * set in the LSP server constructor.
101
+ * @returns {Promise<LspSymbol[]>} List of symbols in the document. Each symbol includes:
102
+ * - name: The symbol's name
103
+ * - kind: The symbol's kind (function, class, variable, etc.)
104
+ * - location: The location of the symbol in the file
105
+ *
106
+ * @example
107
+ * // Get all symbols in a file
108
+ * const symbols = await lsp.documentSymbols('workspace/project/src/index.ts');
109
+ * symbols.forEach(symbol => {
110
+ * console.log(`${symbol.kind} ${symbol.name}: ${symbol.location}`);
111
+ * });
112
+ */
113
+ documentSymbols(path: string): Promise<LspSymbol[]>;
114
+ /**
115
+ * Searches for symbols matching the query string across the entire Sandbox.
116
+ *
117
+ * @param {string} query - Search query to match against symbol names
118
+ * @returns {Promise<LspSymbol[]>} List of matching symbols from all files. Each symbol includes:
119
+ * - name: The symbol's name
120
+ * - kind: The symbol's kind (function, class, variable, etc.)
121
+ * - location: The location of the symbol in the file
122
+ *
123
+ * @deprecated Use `sandboxSymbols` instead. This method will be removed in a future version.
124
+ */
125
+ workspaceSymbols(query: string): Promise<LspSymbol[]>;
126
+ /**
127
+ * Searches for symbols matching the query string across the entire Sandbox.
128
+ *
129
+ * @param {string} query - Search query to match against symbol names
130
+ * @returns {Promise<LspSymbol[]>} List of matching symbols from all files. Each symbol includes:
131
+ * - name: The symbol's name
132
+ * - kind: The symbol's kind (function, class, variable, etc.)
133
+ * - location: The location of the symbol in the file
134
+ *
135
+ * @example
136
+ * // Search for all symbols containing "User"
137
+ * const symbols = await lsp.sandboxSymbols('User');
138
+ * symbols.forEach(symbol => {
139
+ * console.log(`${symbol.name} (${symbol.kind}) in ${symbol.location}`);
140
+ * });
141
+ */
142
+ sandboxSymbols(query: string): Promise<LspSymbol[]>;
143
+ /**
144
+ * Gets completion suggestions at a position in a file.
145
+ *
146
+ * @param {string} path - Path to the file. Relative paths are resolved based on the project path
147
+ * set in the LSP server constructor.
148
+ * @param {Position} position - The position in the file where completion was requested
149
+ * @returns {Promise<CompletionList>} List of completion suggestions. The list includes:
150
+ * - isIncomplete: Whether more items might be available
151
+ * - items: List of completion items, each containing:
152
+ * - label: The text to insert
153
+ * - kind: The kind of completion
154
+ * - detail: Additional details about the item
155
+ * - documentation: Documentation for the item
156
+ * - sortText: Text used to sort the item in the list
157
+ * - filterText: Text used to filter the item
158
+ * - insertText: The actual text to insert (if different from label)
159
+ *
160
+ * @example
161
+ * // Get completions at a specific position
162
+ * const completions = await lsp.completions('workspace/project/src/index.ts', {
163
+ * line: 10,
164
+ * character: 15
165
+ * });
166
+ * completions.items.forEach(item => {
167
+ * console.log(`${item.label} (${item.kind}): ${item.detail}`);
168
+ * });
169
+ */
170
+ completions(path: string, position: Position): Promise<CompletionList>;
171
+ }
172
+ //# sourceMappingURL=LspServer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LspServer.d.ts","sourceRoot":"","sources":["../../../../../libs/sdk-typescript/src/LspServer.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAA;AAEjF;;GAEG;AACH,oBAAY,aAAa;IACvB,MAAM,WAAW;IACjB,UAAU,eAAe;IACzB,UAAU,eAAe;CAC1B;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,QAAQ,GAAG;IACrB,6BAA6B;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,kCAAkC;IAClC,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED;;;;;;;;;;GAUG;AACH,qBAAa,SAAS;IAElB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,SAAS;gBAFT,UAAU,EAAE,aAAa,EACzB,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,MAAM;IASpC;;;;;;;;;;OAUG;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAOnC;;;;;;;;;OASG;IACU,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAOlC;;;;;;;;;;;;OAYG;IACU,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQjD;;;;;;;;;;;OAWG;IACU,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQlD;;;;;;;;;;;;;;;;OAgBG;IACU,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IAKhE;;;;;;;;;;OAUG;IACU,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IAIlE;;;;;;;;;;;;;;;OAeG;IACU,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IAKhE;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACU,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,cAAc,CAAC;CAYpF"}
@@ -0,0 +1,204 @@
1
+ /*
2
+ * Copyright 2025 Daytona Platforms Inc.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ /**
6
+ * Supported language server types.
7
+ */
8
+ export var LspLanguageId;
9
+ (function (LspLanguageId) {
10
+ LspLanguageId["PYTHON"] = "python";
11
+ LspLanguageId["TYPESCRIPT"] = "typescript";
12
+ LspLanguageId["JAVASCRIPT"] = "javascript";
13
+ })(LspLanguageId || (LspLanguageId = {}));
14
+ /**
15
+ * Provides Language Server Protocol functionality for code intelligence to provide
16
+ * IDE-like features such as code completion, symbol search, and more.
17
+ *
18
+ * @property {LspLanguageId} languageId - The language server type (e.g., "typescript")
19
+ * @property {string} pathToProject - Path to the project root directory. Relative paths are resolved based on the sandbox working directory.
20
+ * @property {LspApi} apiClient - API client for Sandbox lsp operations
21
+ * @property {SandboxInstance} instance - The Sandbox instance this server belongs to
22
+ *
23
+ * @class
24
+ */
25
+ export class LspServer {
26
+ languageId;
27
+ pathToProject;
28
+ apiClient;
29
+ constructor(languageId, pathToProject, apiClient) {
30
+ this.languageId = languageId;
31
+ this.pathToProject = pathToProject;
32
+ this.apiClient = apiClient;
33
+ if (!Object.values(LspLanguageId).includes(this.languageId)) {
34
+ throw new Error(`Invalid languageId: ${this.languageId}. Supported values are: ${Object.values(LspLanguageId).join(', ')}`);
35
+ }
36
+ }
37
+ /**
38
+ * Starts the language server, must be called before using any other LSP functionality.
39
+ * It initializes the language server for the specified language and project.
40
+ *
41
+ * @returns {Promise<void>}
42
+ *
43
+ * @example
44
+ * const lsp = await sandbox.createLspServer('typescript', 'workspace/project');
45
+ * await lsp.start(); // Initialize the server
46
+ * // Now ready for LSP operations
47
+ */
48
+ async start() {
49
+ await this.apiClient.start({
50
+ languageId: this.languageId,
51
+ pathToProject: this.pathToProject,
52
+ });
53
+ }
54
+ /**
55
+ * Stops the language server, should be called when the LSP server is no longer needed to
56
+ * free up system resources.
57
+ *
58
+ * @returns {Promise<void>}
59
+ *
60
+ * @example
61
+ * // When done with LSP features
62
+ * await lsp.stop(); // Clean up resources
63
+ */
64
+ async stop() {
65
+ await this.apiClient.stop({
66
+ languageId: this.languageId,
67
+ pathToProject: this.pathToProject,
68
+ });
69
+ }
70
+ /**
71
+ * Notifies the language server that a file has been opened, enabling
72
+ * language features like diagnostics and completions for that file. The server
73
+ * will begin tracking the file's contents and providing language features.
74
+ *
75
+ * @param {string} path - Path to the opened file. Relative paths are resolved based on the sandbox working directory.
76
+ * @returns {Promise<void>}
77
+ *
78
+ * @example
79
+ * // When opening a file for editing
80
+ * await lsp.didOpen('workspace/project/src/index.ts');
81
+ * // Now can get completions, symbols, etc. for this file
82
+ */
83
+ async didOpen(path) {
84
+ await this.apiClient.didOpen({
85
+ languageId: this.languageId,
86
+ pathToProject: this.pathToProject,
87
+ uri: 'file://' + path,
88
+ });
89
+ }
90
+ /**
91
+ * Notifies the language server that a file has been closed, should be called when a file is closed
92
+ * in the editor to allow the language server to clean up any resources associated with that file.
93
+ *
94
+ * @param {string} path - Path to the closed file. Relative paths are resolved based on the project path
95
+ * set in the LSP server constructor.
96
+ * @returns {Promise<void>}
97
+ *
98
+ * @example
99
+ * // When done editing a file
100
+ * await lsp.didClose('workspace/project/src/index.ts');
101
+ */
102
+ async didClose(path) {
103
+ await this.apiClient.didClose({
104
+ languageId: this.languageId,
105
+ pathToProject: this.pathToProject,
106
+ uri: 'file://' + path,
107
+ });
108
+ }
109
+ /**
110
+ * Get symbol information (functions, classes, variables, etc.) from a document.
111
+ *
112
+ * @param {string} path - Path to the file to get symbols from. Relative paths are resolved based on the project path
113
+ * set in the LSP server constructor.
114
+ * @returns {Promise<LspSymbol[]>} List of symbols in the document. Each symbol includes:
115
+ * - name: The symbol's name
116
+ * - kind: The symbol's kind (function, class, variable, etc.)
117
+ * - location: The location of the symbol in the file
118
+ *
119
+ * @example
120
+ * // Get all symbols in a file
121
+ * const symbols = await lsp.documentSymbols('workspace/project/src/index.ts');
122
+ * symbols.forEach(symbol => {
123
+ * console.log(`${symbol.kind} ${symbol.name}: ${symbol.location}`);
124
+ * });
125
+ */
126
+ async documentSymbols(path) {
127
+ const response = await this.apiClient.documentSymbols(this.languageId, this.pathToProject, 'file://' + path);
128
+ return response.data;
129
+ }
130
+ /**
131
+ * Searches for symbols matching the query string across the entire Sandbox.
132
+ *
133
+ * @param {string} query - Search query to match against symbol names
134
+ * @returns {Promise<LspSymbol[]>} List of matching symbols from all files. Each symbol includes:
135
+ * - name: The symbol's name
136
+ * - kind: The symbol's kind (function, class, variable, etc.)
137
+ * - location: The location of the symbol in the file
138
+ *
139
+ * @deprecated Use `sandboxSymbols` instead. This method will be removed in a future version.
140
+ */
141
+ async workspaceSymbols(query) {
142
+ return await this.sandboxSymbols(query);
143
+ }
144
+ /**
145
+ * Searches for symbols matching the query string across the entire Sandbox.
146
+ *
147
+ * @param {string} query - Search query to match against symbol names
148
+ * @returns {Promise<LspSymbol[]>} List of matching symbols from all files. Each symbol includes:
149
+ * - name: The symbol's name
150
+ * - kind: The symbol's kind (function, class, variable, etc.)
151
+ * - location: The location of the symbol in the file
152
+ *
153
+ * @example
154
+ * // Search for all symbols containing "User"
155
+ * const symbols = await lsp.sandboxSymbols('User');
156
+ * symbols.forEach(symbol => {
157
+ * console.log(`${symbol.name} (${symbol.kind}) in ${symbol.location}`);
158
+ * });
159
+ */
160
+ async sandboxSymbols(query) {
161
+ const response = await this.apiClient.workspaceSymbols(query, this.languageId, this.pathToProject);
162
+ return response.data;
163
+ }
164
+ /**
165
+ * Gets completion suggestions at a position in a file.
166
+ *
167
+ * @param {string} path - Path to the file. Relative paths are resolved based on the project path
168
+ * set in the LSP server constructor.
169
+ * @param {Position} position - The position in the file where completion was requested
170
+ * @returns {Promise<CompletionList>} List of completion suggestions. The list includes:
171
+ * - isIncomplete: Whether more items might be available
172
+ * - items: List of completion items, each containing:
173
+ * - label: The text to insert
174
+ * - kind: The kind of completion
175
+ * - detail: Additional details about the item
176
+ * - documentation: Documentation for the item
177
+ * - sortText: Text used to sort the item in the list
178
+ * - filterText: Text used to filter the item
179
+ * - insertText: The actual text to insert (if different from label)
180
+ *
181
+ * @example
182
+ * // Get completions at a specific position
183
+ * const completions = await lsp.completions('workspace/project/src/index.ts', {
184
+ * line: 10,
185
+ * character: 15
186
+ * });
187
+ * completions.items.forEach(item => {
188
+ * console.log(`${item.label} (${item.kind}): ${item.detail}`);
189
+ * });
190
+ */
191
+ async completions(path, position) {
192
+ const response = await this.apiClient.completions({
193
+ languageId: this.languageId,
194
+ pathToProject: this.pathToProject,
195
+ uri: 'file://' + path,
196
+ position: {
197
+ line: position.line,
198
+ character: position.character,
199
+ },
200
+ });
201
+ return response.data;
202
+ }
203
+ }
204
+ //# sourceMappingURL=LspServer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LspServer.js","sourceRoot":"","sources":["../../../../../libs/sdk-typescript/src/LspServer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;GAEG;AACH,MAAM,CAAN,IAAY,aAIX;AAJD,WAAY,aAAa;IACvB,kCAAiB,CAA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C9B;SACF,CAAC,CAAA;QACF,OAAO,QAAQ,CAAC,IAAI,CAAA;IACtB,CAAC;CACF"}
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Configuration for the ObjectStorage class.
3
+ *
4
+ * @interface
5
+ * @property {string} endpointUrl - The endpoint URL for the object storage service.
6
+ * @property {string} accessKeyId - The access key ID for the object storage service.
7
+ * @property {string} secretAccessKey - The secret access key for the object storage service.
8
+ * @property {string} [sessionToken] - The session token for the object storage service. Used for temporary credentials.
9
+ * @property {string} [bucketName] - The name of the bucket to use.
10
+ */
11
+ export interface ObjectStorageConfig {
12
+ endpointUrl: string;
13
+ accessKeyId: string;
14
+ secretAccessKey: string;
15
+ sessionToken?: string;
16
+ bucketName?: string;
17
+ }
18
+ /**
19
+ * ObjectStorage class for interacting with object storage services.
20
+ *
21
+ * @class
22
+ * @param {ObjectStorageConfig} config - The configuration for the object storage service.
23
+ */
24
+ export declare class ObjectStorage {
25
+ private bucketName;
26
+ private s3Client;
27
+ constructor(config: ObjectStorageConfig);
28
+ /**
29
+ * Upload a file or directory to object storage.
30
+ *
31
+ * @param {string} path - The path to the file or directory to upload.
32
+ * @param {string} organizationId - The organization ID to use for the upload.
33
+ * @param {string} archiveBasePath - The base path to use for the archive.
34
+ * @returns {Promise<string>} The hash of the uploaded file or directory.
35
+ */
36
+ upload(path: string, organizationId: string, archiveBasePath: string): Promise<string>;
37
+ /**
38
+ * Compute a hash for a file or directory.
39
+ *
40
+ * @param {string} pathStr - The path to the file or directory to hash.
41
+ * @param {string} archiveBasePath - The base path to use for the archive.
42
+ * @returns {Promise<string>} The hash of the file or directory.
43
+ */
44
+ private computeHashForPathMd5;
45
+ /**
46
+ * Recursively hash a directory and its contents.
47
+ *
48
+ * @param {string} dirPath - The path to the directory to hash.
49
+ * @param {string} basePath - The base path to use for the hash.
50
+ * @param {crypto.Hash} hasher - The hasher to use for the hash.
51
+ * @returns {Promise<void>} A promise that resolves when the directory has been hashed.
52
+ */
53
+ private hashDirectory;
54
+ /**
55
+ * Hash a file.
56
+ *
57
+ * @param {string} filePath - The path to the file to hash.
58
+ * @param {crypto.Hash} hasher - The hasher to use for the hash.
59
+ * @returns {Promise<void>} A promise that resolves when the file has been hashed.
60
+ */
61
+ private hashFile;
62
+ /**
63
+ * Check if a prefix (folder) exists in S3.
64
+ *
65
+ * @param {string} prefix - The prefix to check.
66
+ * @returns {Promise<boolean>} True if the prefix exists, false otherwise.
67
+ */
68
+ private folderExistsInS3;
69
+ /**
70
+ * Create a tar archive of the specified path and upload it to S3.
71
+ *
72
+ * @param {string} s3Key - The key to use for the uploaded file.
73
+ * @param {string} sourcePath - The path to the file or directory to upload.
74
+ * @param {string} archiveBasePath - The base path to use for the archive.
75
+ */
76
+ private uploadAsTar;
77
+ private extractAwsRegion;
78
+ }
79
+ //# sourceMappingURL=ObjectStorage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ObjectStorage.d.ts","sourceRoot":"","sources":["../../../../../libs/sdk-typescript/src/ObjectStorage.ts"],"names":[],"mappings":"AAYA;;;;;;;;;GASG;AACH,MAAM,WAAW,mBAAmB;IAClC,WAAW,EAAE,MAAM,CAAA;IACnB,WAAW,EAAE,MAAM,CAAA;IACnB,eAAe,EAAE,MAAM,CAAA;IACvB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED;;;;;GAKG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,UAAU,CAAQ;IAC1B,OAAO,CAAC,QAAQ,CAAU;gBAEd,MAAM,EAAE,mBAAmB;IAcvC;;;;;;;OAOG;IACG,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IA0B5F;;;;;;OAMG;YACW,qBAAqB;IAmBnC;;;;;;;OAOG;YACW,aAAa;IA2B3B;;;;;;OAMG;YACW,QAAQ;IAWtB;;;;;OAKG;YACW,gBAAgB;IAY9B;;;;;;OAMG;YACW,WAAW;IA2CzB,OAAO,CAAC,gBAAgB;CAIzB"}
@@ -0,0 +1,187 @@
1
+ /*
2
+ * Copyright 2025 Daytona Platforms Inc.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import { ListObjectsV2Command, S3Client } from '@aws-sdk/client-s3';
6
+ import { Upload } from '@aws-sdk/lib-storage';
7
+ import * as crypto from 'crypto';
8
+ import * as pathe from 'pathe';
9
+ import { DaytonaError } from './errors/DaytonaError.js';
10
+ import { dynamicImport } from './utils/Import.js';
11
+ /**
12
+ * ObjectStorage class for interacting with object storage services.
13
+ *
14
+ * @class
15
+ * @param {ObjectStorageConfig} config - The configuration for the object storage service.
16
+ */
17
+ export class ObjectStorage {
18
+ bucketName;
19
+ s3Client;
20
+ constructor(config) {
21
+ this.bucketName = config.bucketName || 'daytona-volume-builds';
22
+ this.s3Client = new S3Client({
23
+ region: this.extractAwsRegion(config.endpointUrl) || 'us-east-1',
24
+ endpoint: config.endpointUrl,
25
+ credentials: {
26
+ accessKeyId: config.accessKeyId,
27
+ secretAccessKey: config.secretAccessKey,
28
+ sessionToken: config.sessionToken,
29
+ },
30
+ forcePathStyle: true,
31
+ });
32
+ }
33
+ /**
34
+ * Upload a file or directory to object storage.
35
+ *
36
+ * @param {string} path - The path to the file or directory to upload.
37
+ * @param {string} organizationId - The organization ID to use for the upload.
38
+ * @param {string} archiveBasePath - The base path to use for the archive.
39
+ * @returns {Promise<string>} The hash of the uploaded file or directory.
40
+ */
41
+ async upload(path, organizationId, archiveBasePath) {
42
+ const fs = await dynamicImport('fs', '"upload" is not supported: ');
43
+ if (!fs.existsSync(path)) {
44
+ const errMsg = `Path does not exist: ${path}`;
45
+ throw new DaytonaError(errMsg);
46
+ }
47
+ // Compute hash for the path
48
+ const pathHash = await this.computeHashForPathMd5(path, archiveBasePath);
49
+ // Define the S3 prefix
50
+ const prefix = `${organizationId}/${pathHash}/`;
51
+ const s3Key = `${prefix}context.tar`;
52
+ // Check if it already exists in S3
53
+ if (await this.folderExistsInS3(prefix)) {
54
+ return pathHash;
55
+ }
56
+ // Upload to S3
57
+ await this.uploadAsTar(s3Key, path, archiveBasePath);
58
+ return pathHash;
59
+ }
60
+ /**
61
+ * Compute a hash for a file or directory.
62
+ *
63
+ * @param {string} pathStr - The path to the file or directory to hash.
64
+ * @param {string} archiveBasePath - The base path to use for the archive.
65
+ * @returns {Promise<string>} The hash of the file or directory.
66
+ */
67
+ async computeHashForPathMd5(pathStr, archiveBasePath) {
68
+ const fs = await dynamicImport('fs', '"computeHashForPathMd5" is not supported: ');
69
+ const md5Hasher = crypto.createHash('md5');
70
+ const absPathStr = pathe.resolve(pathStr);
71
+ md5Hasher.update(archiveBasePath);
72
+ if (fs.statSync(absPathStr).isFile()) {
73
+ // For files, hash the content
74
+ await this.hashFile(absPathStr, md5Hasher);
75
+ }
76
+ else {
77
+ // For directories, recursively hash all files and their paths
78
+ await this.hashDirectory(absPathStr, pathStr, md5Hasher);
79
+ }
80
+ return md5Hasher.digest('hex');
81
+ }
82
+ /**
83
+ * Recursively hash a directory and its contents.
84
+ *
85
+ * @param {string} dirPath - The path to the directory to hash.
86
+ * @param {string} basePath - The base path to use for the hash.
87
+ * @param {crypto.Hash} hasher - The hasher to use for the hash.
88
+ * @returns {Promise<void>} A promise that resolves when the directory has been hashed.
89
+ */
90
+ async hashDirectory(dirPath, basePath, hasher) {
91
+ const fs = await dynamicImport('fs', '"hashDirectory" is not supported: ');
92
+ const entries = fs.readdirSync(dirPath, { withFileTypes: true });
93
+ const hasSubdirs = entries.some((e) => e.isDirectory());
94
+ const hasFiles = entries.some((e) => e.isFile());
95
+ if (!hasSubdirs && !hasFiles) {
96
+ // Empty directory
97
+ const relDir = pathe.relative(basePath, dirPath);
98
+ hasher.update(relDir);
99
+ }
100
+ for (const entry of entries) {
101
+ const fullPath = pathe.join(dirPath, entry.name);
102
+ if (entry.isDirectory()) {
103
+ await this.hashDirectory(fullPath, basePath, hasher);
104
+ }
105
+ else if (entry.isFile()) {
106
+ const relPath = pathe.relative(basePath, fullPath);
107
+ hasher.update(relPath);
108
+ await this.hashFile(fullPath, hasher);
109
+ }
110
+ }
111
+ }
112
+ /**
113
+ * Hash a file.
114
+ *
115
+ * @param {string} filePath - The path to the file to hash.
116
+ * @param {crypto.Hash} hasher - The hasher to use for the hash.
117
+ * @returns {Promise<void>} A promise that resolves when the file has been hashed.
118
+ */
119
+ async hashFile(filePath, hasher) {
120
+ const fs = await dynamicImport('fs', '"hashFile" is not supported: ');
121
+ await new Promise((resolve, reject) => {
122
+ const stream = fs.createReadStream(filePath, { highWaterMark: 8192 });
123
+ stream.on('data', (chunk) => hasher.update(chunk));
124
+ stream.on('end', resolve);
125
+ stream.on('error', reject);
126
+ });
127
+ }
128
+ /**
129
+ * Check if a prefix (folder) exists in S3.
130
+ *
131
+ * @param {string} prefix - The prefix to check.
132
+ * @returns {Promise<boolean>} True if the prefix exists, false otherwise.
133
+ */
134
+ async folderExistsInS3(prefix) {
135
+ const response = await this.s3Client.send(new ListObjectsV2Command({
136
+ Bucket: this.bucketName,
137
+ Prefix: prefix,
138
+ MaxKeys: 1,
139
+ }));
140
+ return !!response.Contents && response.Contents.length > 0;
141
+ }
142
+ /**
143
+ * Create a tar archive of the specified path and upload it to S3.
144
+ *
145
+ * @param {string} s3Key - The key to use for the uploaded file.
146
+ * @param {string} sourcePath - The path to the file or directory to upload.
147
+ * @param {string} archiveBasePath - The base path to use for the archive.
148
+ */
149
+ async uploadAsTar(s3Key, sourcePath, archiveBasePath) {
150
+ const importErrorPrefix = '"uploadAsTar" is not supported: ';
151
+ const tar = await dynamicImport('tar', importErrorPrefix);
152
+ const stream = await dynamicImport('stream', importErrorPrefix);
153
+ sourcePath = pathe.resolve(sourcePath);
154
+ const normalizedSourcePath = pathe.normalize(sourcePath);
155
+ const normalizedArchiveBasePath = pathe.normalize(archiveBasePath);
156
+ let basePrefix;
157
+ if (normalizedArchiveBasePath === '.') {
158
+ // When archiveBasePath is empty (normalized to '.'), use the normalizedSourcePath as cwd and the '.' as target
159
+ basePrefix = normalizedSourcePath;
160
+ }
161
+ else {
162
+ // Normal case: extract the base prefix by removing archiveBasePath from the end
163
+ basePrefix = normalizedSourcePath.slice(0, normalizedSourcePath.length - normalizedArchiveBasePath.length);
164
+ }
165
+ const tarStream = tar.create({
166
+ cwd: basePrefix,
167
+ portable: true,
168
+ gzip: false,
169
+ }, [normalizedArchiveBasePath]);
170
+ const pass = new stream.PassThrough();
171
+ tarStream.pipe(pass);
172
+ const uploader = new Upload({
173
+ client: this.s3Client,
174
+ params: {
175
+ Bucket: this.bucketName,
176
+ Key: s3Key,
177
+ Body: pass,
178
+ },
179
+ });
180
+ await uploader.done();
181
+ }
182
+ extractAwsRegion(endpoint) {
183
+ const match = endpoint.match(/s3[.-]([a-z0-9-]+)\.amazonaws\.com/);
184
+ return match?.[1];
185
+ }
186
+ }
187
+ //# sourceMappingURL=ObjectStorage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ObjectStorage.js","sourceRoot":"","sources":["../../../../../libs/sdk-typescript/src/ObjectStorage.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,oBAAoB,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AACnE,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAC7C,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAA;AAChC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAoB9C;;;;;GAKG;AACH,MAAM,OAAO,aAAa;IAChB,UAAU,CAAQ;IAClB,QAAQ,CAAU;IAE1B,YAAY,MAA2B;QACrC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,IAAI,uBAAuB,CAAA;QAC9D,IAAI,CAAC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