@blaxel/core 0.2.49-dev.214 → 0.2.49-dev1

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 (247) hide show
  1. package/dist/agents/index.d.ts +15 -0
  2. package/dist/agents/index.js +109 -0
  3. package/dist/authentication/apikey.d.ts +10 -0
  4. package/dist/authentication/apikey.js +24 -0
  5. package/dist/authentication/clientcredentials.d.ts +17 -0
  6. package/dist/authentication/clientcredentials.js +85 -0
  7. package/dist/authentication/credentials.d.ts +6 -0
  8. package/dist/authentication/credentials.js +17 -0
  9. package/dist/authentication/deviceMode.d.ts +15 -0
  10. package/dist/authentication/deviceMode.js +70 -0
  11. package/dist/authentication/index.d.ts +3 -0
  12. package/dist/authentication/index.js +62 -0
  13. package/dist/authentication/types.d.ts +9 -0
  14. package/dist/authentication/types.js +2 -0
  15. package/dist/cache/index.d.ts +1 -0
  16. package/dist/cache/index.js +26 -0
  17. package/dist/cjs/.tsbuildinfo +1 -1
  18. package/dist/cjs/agents/index.js +2 -2
  19. package/dist/cjs/authentication/clientcredentials.js +1 -4
  20. package/dist/cjs/client/responseInterceptor.js +53 -0
  21. package/dist/cjs/client/sdk.gen.js +143 -3
  22. package/dist/cjs/common/autoload.js +7 -0
  23. package/dist/cjs/common/env.js +3 -0
  24. package/dist/cjs/common/internal.js +0 -40
  25. package/dist/cjs/common/settings.js +2 -5
  26. package/dist/cjs/common/version.js +6 -0
  27. package/dist/cjs/common/webhook.js +101 -0
  28. package/dist/cjs/jobs/executions.js +119 -0
  29. package/dist/cjs/jobs/jobs.js +2 -2
  30. package/dist/cjs/jobs/start.js +1 -32
  31. package/dist/cjs/sandbox/action.js +2 -1
  32. package/dist/cjs/sandbox/index.js +1 -0
  33. package/dist/cjs/sandbox/interpreter.js +400 -0
  34. package/dist/cjs/sandbox/sandbox.js +10 -67
  35. package/dist/cjs/tools/mcpTool.js +2 -6
  36. package/dist/cjs/types/client/responseInterceptor.d.ts +12 -0
  37. package/dist/cjs/types/client/sdk.gen.d.ts +41 -1
  38. package/dist/cjs/types/client/types.gen.d.ts +599 -16
  39. package/dist/cjs/types/common/internal.d.ts +0 -2
  40. package/dist/cjs/types/common/settings.d.ts +0 -1
  41. package/dist/cjs/types/common/version.d.ts +2 -0
  42. package/dist/cjs/types/common/webhook.d.ts +89 -0
  43. package/dist/cjs/types/jobs/executions.d.ts +42 -0
  44. package/dist/cjs/types/sandbox/client/sdk.gen.d.ts +1 -1
  45. package/dist/cjs/types/sandbox/index.d.ts +1 -0
  46. package/dist/cjs/types/sandbox/interpreter.d.ts +71 -0
  47. package/dist/cjs/types/sandbox/sandbox.d.ts +6 -12
  48. package/dist/cjs/types/sandbox/types.d.ts +0 -3
  49. package/dist/cjs-browser/.tsbuildinfo +1 -1
  50. package/dist/cjs-browser/agents/index.js +2 -2
  51. package/dist/cjs-browser/authentication/clientcredentials.js +1 -4
  52. package/dist/cjs-browser/client/responseInterceptor.js +53 -0
  53. package/dist/cjs-browser/client/sdk.gen.js +143 -3
  54. package/dist/cjs-browser/common/autoload.js +7 -0
  55. package/dist/cjs-browser/common/env.js +3 -0
  56. package/dist/cjs-browser/common/internal.js +0 -40
  57. package/dist/cjs-browser/common/settings.js +2 -5
  58. package/dist/cjs-browser/common/version.js +6 -0
  59. package/dist/cjs-browser/common/webhook.js +101 -0
  60. package/dist/cjs-browser/jobs/executions.js +119 -0
  61. package/dist/cjs-browser/jobs/jobs.js +2 -2
  62. package/dist/cjs-browser/jobs/start.js +1 -32
  63. package/dist/cjs-browser/sandbox/action.js +2 -1
  64. package/dist/cjs-browser/sandbox/index.js +1 -0
  65. package/dist/cjs-browser/sandbox/interpreter.js +400 -0
  66. package/dist/cjs-browser/sandbox/sandbox.js +10 -67
  67. package/dist/cjs-browser/tools/mcpTool.js +2 -6
  68. package/dist/cjs-browser/types/client/responseInterceptor.d.ts +12 -0
  69. package/dist/cjs-browser/types/client/sdk.gen.d.ts +41 -1
  70. package/dist/cjs-browser/types/client/types.gen.d.ts +599 -16
  71. package/dist/cjs-browser/types/common/internal.d.ts +0 -2
  72. package/dist/cjs-browser/types/common/settings.d.ts +0 -1
  73. package/dist/cjs-browser/types/common/version.d.ts +2 -0
  74. package/dist/cjs-browser/types/common/webhook.d.ts +89 -0
  75. package/dist/cjs-browser/types/jobs/executions.d.ts +42 -0
  76. package/dist/cjs-browser/types/sandbox/client/sdk.gen.d.ts +1 -1
  77. package/dist/cjs-browser/types/sandbox/index.d.ts +1 -0
  78. package/dist/cjs-browser/types/sandbox/interpreter.d.ts +71 -0
  79. package/dist/cjs-browser/types/sandbox/sandbox.d.ts +6 -12
  80. package/dist/cjs-browser/types/sandbox/types.d.ts +0 -3
  81. package/dist/client/authentication.d.ts +25 -0
  82. package/dist/client/authentication.js +15 -0
  83. package/dist/client/client.d.ts +2 -0
  84. package/dist/client/client.gen.d.ts +12 -0
  85. package/dist/client/client.gen.js +8 -0
  86. package/dist/{cjs/sandbox/websocket/index.js → client/client.js} +1 -1
  87. package/dist/client/index.d.ts +2 -0
  88. package/dist/client/index.js +19 -0
  89. package/dist/client/interceptors.d.ts +3 -0
  90. package/dist/client/interceptors.js +17 -0
  91. package/dist/client/sdk.gen.d.ts +499 -0
  92. package/dist/client/sdk.gen.js +1751 -0
  93. package/dist/client/types.gen.d.ts +4546 -0
  94. package/dist/client/types.gen.js +4 -0
  95. package/dist/common/autoload.d.ts +3 -0
  96. package/dist/common/autoload.js +27 -0
  97. package/dist/common/env.d.ts +5 -0
  98. package/dist/common/env.js +42 -0
  99. package/dist/common/errors.d.ts +1 -0
  100. package/dist/common/errors.js +17 -0
  101. package/dist/common/internal.d.ts +4 -0
  102. package/dist/common/internal.js +188 -0
  103. package/dist/common/internal.test.d.ts +1 -0
  104. package/dist/common/internal.test.js +39 -0
  105. package/dist/common/logger.d.ts +25 -0
  106. package/dist/common/logger.js +69 -0
  107. package/dist/common/node.d.ts +5 -0
  108. package/dist/common/node.js +26 -0
  109. package/dist/common/settings.d.ts +31 -0
  110. package/dist/common/settings.js +170 -0
  111. package/dist/esm/.tsbuildinfo +1 -1
  112. package/dist/esm/agents/index.js +3 -3
  113. package/dist/esm/authentication/clientcredentials.js +1 -4
  114. package/dist/esm/client/responseInterceptor.js +49 -0
  115. package/dist/esm/client/sdk.gen.js +132 -0
  116. package/dist/esm/common/autoload.js +7 -0
  117. package/dist/esm/common/env.js +3 -0
  118. package/dist/esm/common/internal.js +0 -38
  119. package/dist/esm/common/settings.js +2 -5
  120. package/dist/esm/common/version.js +3 -0
  121. package/dist/esm/common/webhook.js +97 -0
  122. package/dist/esm/jobs/executions.js +114 -0
  123. package/dist/esm/jobs/jobs.js +3 -3
  124. package/dist/esm/jobs/start.js +1 -32
  125. package/dist/esm/sandbox/action.js +3 -2
  126. package/dist/esm/sandbox/index.js +1 -0
  127. package/dist/esm/sandbox/interpreter.js +396 -0
  128. package/dist/esm/sandbox/sandbox.js +10 -67
  129. package/dist/esm/tools/mcpTool.js +3 -7
  130. package/dist/esm-browser/.tsbuildinfo +1 -1
  131. package/dist/esm-browser/agents/index.js +3 -3
  132. package/dist/esm-browser/authentication/clientcredentials.js +1 -4
  133. package/dist/esm-browser/client/responseInterceptor.js +49 -0
  134. package/dist/esm-browser/client/sdk.gen.js +132 -0
  135. package/dist/esm-browser/common/autoload.js +7 -0
  136. package/dist/esm-browser/common/env.js +3 -0
  137. package/dist/esm-browser/common/internal.js +0 -38
  138. package/dist/esm-browser/common/settings.js +2 -5
  139. package/dist/esm-browser/common/version.js +3 -0
  140. package/dist/esm-browser/common/webhook.js +97 -0
  141. package/dist/esm-browser/jobs/executions.js +114 -0
  142. package/dist/esm-browser/jobs/jobs.js +3 -3
  143. package/dist/esm-browser/jobs/start.js +1 -32
  144. package/dist/esm-browser/sandbox/action.js +3 -2
  145. package/dist/esm-browser/sandbox/index.js +1 -0
  146. package/dist/esm-browser/sandbox/interpreter.js +396 -0
  147. package/dist/esm-browser/sandbox/sandbox.js +10 -67
  148. package/dist/esm-browser/tools/mcpTool.js +3 -7
  149. package/dist/index.browser.test.d.ts +1 -0
  150. package/dist/index.browser.test.js +45 -0
  151. package/dist/index.d.ts +17 -0
  152. package/dist/index.js +33 -0
  153. package/dist/jobs/index.d.ts +3 -0
  154. package/dist/jobs/index.js +19 -0
  155. package/dist/jobs/jobs.d.ts +13 -0
  156. package/dist/jobs/jobs.js +90 -0
  157. package/dist/jobs/start.d.ts +1 -0
  158. package/dist/jobs/start.js +66 -0
  159. package/dist/jobs/types.d.ts +3 -0
  160. package/dist/jobs/types.js +2 -0
  161. package/dist/mcp/client.d.ts +28 -0
  162. package/dist/mcp/client.js +247 -0
  163. package/dist/{cjs-browser/types/sandbox/websocket → mcp}/index.d.ts +1 -0
  164. package/dist/{cjs-browser/sandbox/websocket → mcp}/index.js +1 -0
  165. package/dist/mcp/server.d.ts +24 -0
  166. package/dist/mcp/server.js +213 -0
  167. package/dist/models/index.d.ts +8 -0
  168. package/dist/models/index.js +31 -0
  169. package/dist/sandbox/action.d.ts +19 -0
  170. package/dist/sandbox/action.js +84 -0
  171. package/dist/sandbox/client/client.gen.d.ts +12 -0
  172. package/dist/sandbox/client/client.gen.js +6 -0
  173. package/dist/sandbox/client/index.d.ts +2 -0
  174. package/dist/sandbox/client/index.js +19 -0
  175. package/dist/sandbox/client/sdk.gen.d.ts +101 -0
  176. package/dist/sandbox/client/sdk.gen.js +289 -0
  177. package/dist/sandbox/client/types.gen.d.ts +578 -0
  178. package/dist/sandbox/client/types.gen.js +3 -0
  179. package/dist/{cjs/types/sandbox/filesystem/filesystem-ws.d.ts → sandbox/filesystem/filesystem.d.ts} +6 -18
  180. package/dist/sandbox/filesystem/filesystem.js +276 -0
  181. package/dist/sandbox/filesystem/index.d.ts +2 -0
  182. package/dist/sandbox/filesystem/index.js +18 -0
  183. package/dist/sandbox/filesystem/types.d.ts +15 -0
  184. package/dist/sandbox/filesystem/types.js +2 -0
  185. package/dist/sandbox/index.d.ts +4 -0
  186. package/dist/sandbox/index.js +36 -0
  187. package/dist/sandbox/network/index.d.ts +1 -0
  188. package/dist/sandbox/network/index.js +17 -0
  189. package/dist/sandbox/network/network.d.ts +5 -0
  190. package/dist/sandbox/network/network.js +10 -0
  191. package/dist/sandbox/preview.d.ts +37 -0
  192. package/dist/sandbox/preview.js +148 -0
  193. package/dist/sandbox/process/index.d.ts +1 -0
  194. package/dist/sandbox/process/index.js +17 -0
  195. package/dist/sandbox/process/process.d.ts +24 -0
  196. package/dist/sandbox/process/process.js +189 -0
  197. package/dist/sandbox/sandbox.d.ts +33 -0
  198. package/dist/sandbox/sandbox.js +178 -0
  199. package/dist/sandbox/session.d.ts +27 -0
  200. package/dist/sandbox/session.js +123 -0
  201. package/dist/sandbox/types.d.ts +51 -0
  202. package/dist/sandbox/types.js +81 -0
  203. package/dist/telemetry/telemetry.d.ts +62 -0
  204. package/dist/telemetry/telemetry.js +80 -0
  205. package/dist/tools/index.d.ts +11 -0
  206. package/dist/tools/index.js +52 -0
  207. package/dist/tools/mcpTool.d.ts +28 -0
  208. package/dist/tools/mcpTool.js +218 -0
  209. package/dist/tools/types.d.ts +8 -0
  210. package/dist/tools/types.js +2 -0
  211. package/dist/tools/zodSchema.d.ts +9 -0
  212. package/dist/tools/zodSchema.js +50 -0
  213. package/dist/volume/index.d.ts +23 -0
  214. package/dist/volume/index.js +113 -0
  215. package/package.json +2 -2
  216. package/dist/cjs/sandbox/codegen/codegen-ws.js +0 -30
  217. package/dist/cjs/sandbox/filesystem/filesystem-ws.js +0 -106
  218. package/dist/cjs/sandbox/network/network-ws.js +0 -12
  219. package/dist/cjs/sandbox/process/process-ws.js +0 -139
  220. package/dist/cjs/sandbox/websocket/client.js +0 -269
  221. package/dist/cjs/types/sandbox/codegen/codegen-ws.d.ts +0 -10
  222. package/dist/cjs/types/sandbox/network/network-ws.d.ts +0 -7
  223. package/dist/cjs/types/sandbox/process/process-ws.d.ts +0 -27
  224. package/dist/cjs/types/sandbox/websocket/client.d.ts +0 -48
  225. package/dist/cjs/types/sandbox/websocket/index.d.ts +0 -1
  226. package/dist/cjs-browser/sandbox/codegen/codegen-ws.js +0 -30
  227. package/dist/cjs-browser/sandbox/filesystem/filesystem-ws.js +0 -106
  228. package/dist/cjs-browser/sandbox/network/network-ws.js +0 -12
  229. package/dist/cjs-browser/sandbox/process/process-ws.js +0 -139
  230. package/dist/cjs-browser/sandbox/websocket/client.js +0 -269
  231. package/dist/cjs-browser/types/sandbox/codegen/codegen-ws.d.ts +0 -10
  232. package/dist/cjs-browser/types/sandbox/filesystem/filesystem-ws.d.ts +0 -35
  233. package/dist/cjs-browser/types/sandbox/network/network-ws.d.ts +0 -7
  234. package/dist/cjs-browser/types/sandbox/process/process-ws.d.ts +0 -27
  235. package/dist/cjs-browser/types/sandbox/websocket/client.d.ts +0 -48
  236. package/dist/esm/sandbox/codegen/codegen-ws.js +0 -26
  237. package/dist/esm/sandbox/filesystem/filesystem-ws.js +0 -102
  238. package/dist/esm/sandbox/network/network-ws.js +0 -8
  239. package/dist/esm/sandbox/process/process-ws.js +0 -135
  240. package/dist/esm/sandbox/websocket/client.js +0 -265
  241. package/dist/esm/sandbox/websocket/index.js +0 -1
  242. package/dist/esm-browser/sandbox/codegen/codegen-ws.js +0 -26
  243. package/dist/esm-browser/sandbox/filesystem/filesystem-ws.js +0 -102
  244. package/dist/esm-browser/sandbox/network/network-ws.js +0 -8
  245. package/dist/esm-browser/sandbox/process/process-ws.js +0 -135
  246. package/dist/esm-browser/sandbox/websocket/client.js +0 -265
  247. package/dist/esm-browser/sandbox/websocket/index.js +0 -1
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Response interceptor that enhances authentication error messages (401/403)
3
+ * with a link to the authentication documentation.
4
+ */
5
+ /**
6
+ * Intercepts HTTP responses and adds authentication documentation
7
+ * to 401/403 error responses
8
+ */
9
+ export const authenticationErrorInterceptor = async (response) => {
10
+ // Only process authentication errors (401/403)
11
+ if (response.status !== 401 && response.status !== 403) {
12
+ return response;
13
+ }
14
+ // Clone the response so we can modify it
15
+ const clonedResponse = response.clone();
16
+ try {
17
+ // Read the original response body
18
+ const bodyText = await clonedResponse.text();
19
+ // Try to parse as JSON
20
+ let enhancedBody;
21
+ try {
22
+ const originalError = JSON.parse(bodyText);
23
+ // Create enhanced error with authentication documentation
24
+ const authError = {
25
+ ...originalError,
26
+ documentation: "For more information on authentication, visit: https://docs.blaxel.ai/sdk-reference/introduction#how-authentication-works",
27
+ };
28
+ enhancedBody = JSON.stringify(authError);
29
+ }
30
+ catch {
31
+ // If not JSON, just append the documentation as text
32
+ enhancedBody = `${bodyText}\nFor more information on authentication, visit: https://docs.blaxel.ai/sdk-reference/introduction#how-authentication-works`;
33
+ }
34
+ // Create a new response with the enhanced body
35
+ return new Response(enhancedBody, {
36
+ status: response.status,
37
+ statusText: response.statusText,
38
+ headers: response.headers,
39
+ });
40
+ }
41
+ catch (error) {
42
+ // If anything fails, return the original response
43
+ console.error("Error processing authentication error response:", error);
44
+ return response;
45
+ }
46
+ };
47
+ export const responseInterceptors = [
48
+ authenticationErrorInterceptor,
49
+ ];
@@ -310,6 +310,70 @@ export const listFunctionRevisions = (options) => {
310
310
  ...options
311
311
  });
312
312
  };
313
+ /**
314
+ * List images
315
+ * Returns a list of all images in the workspace grouped by repository with tags.
316
+ */
317
+ export const listImages = (options) => {
318
+ return (options?.client ?? _heyApiClient).get({
319
+ security: [
320
+ {
321
+ scheme: 'bearer',
322
+ type: 'http'
323
+ }
324
+ ],
325
+ url: '/images',
326
+ ...options
327
+ });
328
+ };
329
+ /**
330
+ * Delete image by name
331
+ * Deletes an image by name.
332
+ */
333
+ export const deleteImage = (options) => {
334
+ return (options.client ?? _heyApiClient).delete({
335
+ security: [
336
+ {
337
+ scheme: 'bearer',
338
+ type: 'http'
339
+ }
340
+ ],
341
+ url: '/images/{resourceType}/{imageName}',
342
+ ...options
343
+ });
344
+ };
345
+ /**
346
+ * Get image by name
347
+ * Returns an image by name.
348
+ */
349
+ export const getImage = (options) => {
350
+ return (options.client ?? _heyApiClient).get({
351
+ security: [
352
+ {
353
+ scheme: 'bearer',
354
+ type: 'http'
355
+ }
356
+ ],
357
+ url: '/images/{resourceType}/{imageName}',
358
+ ...options
359
+ });
360
+ };
361
+ /**
362
+ * Delete image tag
363
+ * Deletes a specific tag from an image.
364
+ */
365
+ export const deleteImageTag = (options) => {
366
+ return (options.client ?? _heyApiClient).delete({
367
+ security: [
368
+ {
369
+ scheme: 'bearer',
370
+ type: 'http'
371
+ }
372
+ ],
373
+ url: '/images/{resourceType}/{imageName}/tags/{tagName}',
374
+ ...options
375
+ });
376
+ };
313
377
  /**
314
378
  * List integrations connections
315
379
  * Returns integration information by name.
@@ -550,6 +614,74 @@ export const updateJob = (options) => {
550
614
  }
551
615
  });
552
616
  };
617
+ /**
618
+ * List job executions
619
+ * Returns a list of all executions for a job by name.
620
+ */
621
+ export const listJobExecutions = (options) => {
622
+ return (options.client ?? _heyApiClient).get({
623
+ security: [
624
+ {
625
+ scheme: 'bearer',
626
+ type: 'http'
627
+ }
628
+ ],
629
+ url: '/jobs/{jobId}/executions',
630
+ ...options
631
+ });
632
+ };
633
+ /**
634
+ * Create job execution
635
+ * Creates a new execution for a job by name.
636
+ */
637
+ export const createJobExecution = (options) => {
638
+ return (options.client ?? _heyApiClient).post({
639
+ security: [
640
+ {
641
+ scheme: 'bearer',
642
+ type: 'http'
643
+ }
644
+ ],
645
+ url: '/jobs/{jobId}/executions',
646
+ ...options,
647
+ headers: {
648
+ 'Content-Type': 'application/json',
649
+ ...options?.headers
650
+ }
651
+ });
652
+ };
653
+ /**
654
+ * Delete job execution
655
+ * Stop an execution for a job by name.
656
+ */
657
+ export const deleteJobExecution = (options) => {
658
+ return (options.client ?? _heyApiClient).delete({
659
+ security: [
660
+ {
661
+ scheme: 'bearer',
662
+ type: 'http'
663
+ }
664
+ ],
665
+ url: '/jobs/{jobId}/executions/{executionId}',
666
+ ...options
667
+ });
668
+ };
669
+ /**
670
+ * Get job execution
671
+ * Returns an execution for a job by name.
672
+ */
673
+ export const getJobExecution = (options) => {
674
+ return (options.client ?? _heyApiClient).get({
675
+ security: [
676
+ {
677
+ scheme: 'bearer',
678
+ type: 'http'
679
+ }
680
+ ],
681
+ url: '/jobs/{jobId}/executions/{executionId}',
682
+ ...options
683
+ });
684
+ };
553
685
  /**
554
686
  * List job revisions
555
687
  * Returns revisions for a job by name.
@@ -1,16 +1,23 @@
1
1
  import { client } from "../client/client.gen.js";
2
2
  import { interceptors } from "../client/interceptors.js";
3
+ import { responseInterceptors } from "../client/responseInterceptor.js";
3
4
  import { client as clientSandbox } from "../sandbox/client/client.gen.js";
4
5
  import { settings } from "./settings.js";
5
6
  client.setConfig({
6
7
  baseUrl: settings.baseUrl,
7
8
  });
9
+ // Register request interceptors
8
10
  for (const interceptor of interceptors) {
9
11
  // @ts-expect-error - Interceptor is not typed
10
12
  client.interceptors.request.use(interceptor);
11
13
  // @ts-expect-error - Interceptor is not typed
12
14
  clientSandbox.interceptors.request.use(interceptor);
13
15
  }
16
+ // Register response interceptors for authentication error handling
17
+ for (const interceptor of responseInterceptors) {
18
+ client.interceptors.response.use(interceptor);
19
+ clientSandbox.interceptors.response.use(interceptor);
20
+ }
14
21
  // Allow to set custom configuration for browser environment
15
22
  export function initialize(config) {
16
23
  settings.setConfig(config);
@@ -8,6 +8,7 @@ if (fs !== null) {
8
8
  const configInfos = toml.parse(configFile);
9
9
  for (const key in configInfos.env) {
10
10
  configEnv[key] = configInfos.env[key];
11
+ process.env[key] = configInfos.env[key];
11
12
  }
12
13
  }
13
14
  catch {
@@ -18,6 +19,7 @@ if (fs !== null) {
18
19
  if (dotenv) {
19
20
  const parsed = dotenv.parse(secretFile);
20
21
  Object.assign(secretEnv, parsed);
22
+ Object.assign(process.env, parsed);
21
23
  }
22
24
  else {
23
25
  // Simple .env parsing fallback when dotenv is not available
@@ -26,6 +28,7 @@ if (fs !== null) {
26
28
  const match = line.match(/^([^=]+)=(.*)$/);
27
29
  if (match) {
28
30
  secretEnv[match[1].trim()] = match[2].trim();
31
+ process.env[match[1].trim()] = match[2].trim();
29
32
  }
30
33
  }
31
34
  }
@@ -180,41 +180,3 @@ export function getForcedUrl(type, name) {
180
180
  }
181
181
  return null;
182
182
  }
183
- export function getWorkloadTypeShort(type) {
184
- const lowerType = type.toLowerCase();
185
- switch (lowerType) {
186
- case 'agent':
187
- case 'agents':
188
- return 'agt';
189
- case 'mcp':
190
- case 'mcps':
191
- case 'function':
192
- case 'functions':
193
- return 'mcp';
194
- case 'sandbox':
195
- case 'sandboxes':
196
- return 'sbx';
197
- case 'job':
198
- case 'jobs':
199
- return 'job';
200
- case 'model':
201
- case 'models':
202
- return 'mdl';
203
- default:
204
- // fallback to first 3 letters of type
205
- return lowerType.substring(0, 3);
206
- }
207
- }
208
- export function generateInternalUrl(workspace, type, name, env, protocol, hostname, blCloud, workspaceId) {
209
- if (blCloud && workspaceId) {
210
- // New cloud format: bl-ENV-WORKLOAD_CALLED_NAME-WORKLOAD_TYPE_SHORT-WORKSPACE_ID
211
- const workloadTypeShort = getWorkloadTypeShort(type);
212
- const subdomain = `bl-${env}-${name}-${workloadTypeShort}-${workspaceId}`;
213
- return `${protocol}://${subdomain}.${hostname}`;
214
- }
215
- else {
216
- // Legacy format: bl-ENV-HASH.internalhostname
217
- const hash = getGlobalUniqueHash(workspace, type, name);
218
- return `${protocol}://bl-${env}-${hash}.${hostname}`;
219
- }
220
- }
@@ -7,7 +7,7 @@ function getPackageVersion() {
7
7
  if (typeof require !== "undefined") {
8
8
  // Try to require package.json (Node.js only, gracefully fails in browser)
9
9
  // eslint-disable-next-line @typescript-eslint/no-require-imports
10
- const packageJson = {"version":"0.2.49-dev.214","commit":"3cd25c395e498b34304684d4d76a906f2cef14a9"};
10
+ const packageJson = {"version":"0.2.49","commit":"3523e3d6b67057292fade1b12e304be6456fd2bc"};
11
11
  return packageJson.version || "unknown";
12
12
  }
13
13
  else {
@@ -59,7 +59,7 @@ function getCommitHash() {
59
59
  if (typeof require !== "undefined") {
60
60
  // Try to require package.json and look for commit field (set during build)
61
61
  // eslint-disable-next-line @typescript-eslint/no-require-imports
62
- const packageJson = {"version":"0.2.49-dev.214","commit":"3cd25c395e498b34304684d4d76a906f2cef14a9"};
62
+ const packageJson = {"version":"0.2.49","commit":"3523e3d6b67057292fade1b12e304be6456fd2bc"};
63
63
  // Check for commit in various possible locations
64
64
  const commit = packageJson.commit || packageJson.buildInfo?.commit;
65
65
  if (commit) {
@@ -162,9 +162,6 @@ class Settings {
162
162
  get blCloud() {
163
163
  return env.BL_CLOUD === "true";
164
164
  }
165
- get workspaceId() {
166
- return env.BL_WORKSPACE_ID || "";
167
- }
168
165
  get generation() {
169
166
  return env.BL_GENERATION || "";
170
167
  }
@@ -0,0 +1,3 @@
1
+ // This file is auto-generated during build. Do not edit manually.
2
+ export const PACKAGE_VERSION = "0.2.49";
3
+ export const PACKAGE_COMMIT = "4548518514109c742457451a6eb36fa8d054eb9b";
@@ -0,0 +1,97 @@
1
+ import { createHmac, timingSafeEqual } from 'crypto';
2
+ /**
3
+ * Verify the HMAC-SHA256 signature of a webhook callback from async-sidecar
4
+ *
5
+ * @example
6
+ * ```typescript
7
+ * import { verifyWebhookSignature } from '@blaxel/core';
8
+ *
9
+ * // In your Express endpoint
10
+ * app.post('/webhook', express.text({ type: 'application/json' }), (req, res) => {
11
+ * const isValid = verifyWebhookSignature({
12
+ * body: req.body,
13
+ * signature: req.headers['x-blaxel-signature'] as string,
14
+ * secret: process.env.CALLBACK_SECRET!
15
+ * });
16
+ *
17
+ * if (!isValid) {
18
+ * return res.status(401).json({ error: 'Invalid signature' });
19
+ * }
20
+ *
21
+ * const data = JSON.parse(req.body);
22
+ * // Process callback...
23
+ * });
24
+ * ```
25
+ *
26
+ * @param options - Verification options
27
+ * @returns true if the signature is valid, false otherwise
28
+ */
29
+ export function verifyWebhookSignature(options) {
30
+ const { body, signature, secret, timestamp, maxAge = 300 } = options;
31
+ if (!body || !signature || !secret) {
32
+ return false;
33
+ }
34
+ try {
35
+ // Verify timestamp if provided (prevents replay attacks)
36
+ if (timestamp) {
37
+ const requestTime = parseInt(timestamp, 10);
38
+ const currentTime = Math.floor(Date.now() / 1000);
39
+ const age = Math.abs(currentTime - requestTime);
40
+ if (isNaN(requestTime) || age > maxAge) {
41
+ return false;
42
+ }
43
+ }
44
+ // Extract hex signature from "sha256=<hex>" format
45
+ const expectedSignature = signature.replace('sha256=', '');
46
+ // Compute HMAC-SHA256 signature
47
+ const hmac = createHmac('sha256', secret);
48
+ hmac.update(body);
49
+ const computedSignature = hmac.digest('hex');
50
+ // Timing-safe comparison to prevent timing attacks
51
+ return timingSafeEqual(Buffer.from(expectedSignature, 'hex'), Buffer.from(computedSignature, 'hex'));
52
+ }
53
+ catch {
54
+ // Invalid signature format or other error
55
+ return false;
56
+ }
57
+ }
58
+ /**
59
+ * Helper to verify webhook from Express request object
60
+ *
61
+ * @example
62
+ * ```typescript
63
+ * import { verifyWebhookFromRequest } from '@blaxel/core';
64
+ * import express from 'express';
65
+ *
66
+ * app.use(express.text({ type: 'application/json' }));
67
+ *
68
+ * app.post('/webhook', (req, res) => {
69
+ * if (!verifyWebhookFromRequest(req, process.env.CALLBACK_SECRET!)) {
70
+ * return res.status(401).json({ error: 'Invalid signature' });
71
+ * }
72
+ *
73
+ * const data = JSON.parse(req.body);
74
+ * console.log('Received callback:', data);
75
+ * res.json({ received: true });
76
+ * });
77
+ * ```
78
+ *
79
+ * @param request - Express request object (must use express.text() middleware)
80
+ * @param secret - The callback secret
81
+ * @param maxAge - Optional maximum age in seconds (default: 300)
82
+ * @returns true if the signature is valid, false otherwise
83
+ */
84
+ export function verifyWebhookFromRequest(request, secret, maxAge) {
85
+ const signature = request.headers['x-blaxel-signature'];
86
+ const timestamp = request.headers['x-blaxel-timestamp'];
87
+ if (typeof signature !== 'string') {
88
+ return false;
89
+ }
90
+ return verifyWebhookSignature({
91
+ body: request.body,
92
+ signature,
93
+ secret,
94
+ timestamp: typeof timestamp === 'string' ? timestamp : undefined,
95
+ maxAge
96
+ });
97
+ }
@@ -0,0 +1,114 @@
1
+ import { createJobExecution, getJobExecution, listJobExecutions, deleteJobExecution } from "../client/sdk.gen.js";
2
+ import { logger } from "../common/logger.js";
3
+ import { settings } from "../common/settings.js";
4
+ /**
5
+ * JobExecutionHelper provides convenient methods for working with job executions
6
+ */
7
+ export class JobExecutionHelper {
8
+ jobName;
9
+ constructor(jobName) {
10
+ this.jobName = jobName;
11
+ }
12
+ /**
13
+ * Create a new job execution and return the execution ID
14
+ */
15
+ async create(request) {
16
+ logger.debug(`Creating execution for job: ${this.jobName}`);
17
+ const response = await createJobExecution({
18
+ path: {
19
+ jobId: this.jobName,
20
+ },
21
+ body: request,
22
+ headers: settings.headers,
23
+ });
24
+ if (!response.data) {
25
+ throw new Error("No response data returned from create job execution");
26
+ }
27
+ const execution = response.data;
28
+ if (!execution.metadata?.id) {
29
+ throw new Error("No execution ID returned from create job execution");
30
+ }
31
+ logger.debug(`Created execution: ${execution.metadata.id}`);
32
+ return execution.metadata.id;
33
+ }
34
+ /**
35
+ * Get a specific job execution by ID
36
+ */
37
+ async get(executionId) {
38
+ logger.debug(`Getting execution ${executionId} for job: ${this.jobName}`);
39
+ const response = await getJobExecution({
40
+ path: {
41
+ jobId: this.jobName,
42
+ executionId: executionId,
43
+ },
44
+ headers: settings.headers,
45
+ });
46
+ if (!response.data) {
47
+ throw new Error(`Execution '${executionId}' not found for job '${this.jobName}'`);
48
+ }
49
+ return response.data;
50
+ }
51
+ /**
52
+ * List all executions for the job
53
+ */
54
+ async list() {
55
+ logger.debug(`Listing executions for job: ${this.jobName}`);
56
+ const response = await listJobExecutions({
57
+ path: {
58
+ jobId: this.jobName,
59
+ },
60
+ headers: settings.headers,
61
+ });
62
+ return response.data ?? [];
63
+ }
64
+ /**
65
+ * Get the status of a specific execution
66
+ */
67
+ async getStatus(executionId) {
68
+ const execution = await this.get(executionId);
69
+ return execution.status ?? "UNKNOWN";
70
+ }
71
+ /**
72
+ * Delete a specific job execution
73
+ */
74
+ async delete(executionId) {
75
+ logger.debug(`Deleting execution ${executionId} for job: ${this.jobName}`);
76
+ await deleteJobExecution({
77
+ path: {
78
+ jobId: this.jobName,
79
+ executionId: executionId,
80
+ },
81
+ headers: settings.headers,
82
+ });
83
+ }
84
+ /**
85
+ * Wait for an execution to complete
86
+ * @param executionId The execution ID to wait for
87
+ * @param options.maxWait Maximum time to wait in milliseconds (default: 5 minutes)
88
+ * @param options.interval Polling interval in milliseconds (default: 2 seconds)
89
+ */
90
+ async waitForCompletion(executionId, options = {}) {
91
+ const maxWait = options.maxWait ?? 300000; // 5 minutes default
92
+ const interval = options.interval ?? 2000; // 2 seconds default
93
+ const startTime = Date.now();
94
+ logger.debug(`Waiting for execution ${executionId} to complete (max ${maxWait}ms)`);
95
+ while (Date.now() - startTime < maxWait) {
96
+ const execution = await this.get(executionId);
97
+ const status = execution.status;
98
+ // Terminal states
99
+ if (status === "COMPLETED" || status === "FAILED" || status === "CANCELLED") {
100
+ logger.debug(`Execution ${executionId} finished with status: ${status}`);
101
+ return execution;
102
+ }
103
+ // Wait before polling again
104
+ await new Promise(resolve => setTimeout(resolve, interval));
105
+ }
106
+ throw new Error(`Execution ${executionId} did not complete within ${maxWait}ms`);
107
+ }
108
+ }
109
+ /**
110
+ * Factory function to create a JobExecutionHelper
111
+ */
112
+ export const jobExecutions = (jobName) => {
113
+ return new JobExecutionHelper(jobName);
114
+ };
@@ -1,4 +1,4 @@
1
- import { generateInternalUrl, getForcedUrl } from "../common/internal.js";
1
+ import { getForcedUrl, getGlobalUniqueHash } from "../common/internal.js";
2
2
  import { logger } from "../common/logger.js";
3
3
  import { settings } from "../common/settings.js";
4
4
  import { startSpan } from '../telemetry/telemetry.js';
@@ -17,8 +17,8 @@ class BlJob {
17
17
  return new URL(`${settings.runUrl}/${settings.workspace}/jobs/${this.jobName}`);
18
18
  }
19
19
  get internalUrl() {
20
- const url = generateInternalUrl(settings.workspace, "job", this.jobName, settings.env, settings.runInternalProtocol, settings.runInternalHostname, settings.blCloud, settings.workspaceId);
21
- return new URL(url);
20
+ const hash = getGlobalUniqueHash(settings.workspace, "job", this.jobName);
21
+ return new URL(`${settings.runInternalProtocol}://bl-${settings.env}-${hash}.${settings.runInternalHostname}`);
22
22
  }
23
23
  get forcedUrl() {
24
24
  return getForcedUrl('job', this.jobName);
@@ -2,43 +2,12 @@ import { authenticate } from '../common/autoload.js';
2
2
  import { env } from '../common/env.js';
3
3
  import { flush } from '../telemetry/telemetry.js';
4
4
  class BlJobWrapper {
5
- async fetchWithRetry(url, maxRetries = 3) {
6
- let lastError;
7
- for (let attempt = 0; attempt <= maxRetries; attempt++) {
8
- try {
9
- const response = await fetch(url);
10
- // If the response is successful, return it
11
- if (response.ok) {
12
- return response;
13
- }
14
- // If it's not the last attempt and the status is retriable, retry
15
- if (attempt < maxRetries && (response.status >= 500 || response.status === 429)) {
16
- lastError = new Error(`HTTP ${response.status}: ${response.statusText}`);
17
- }
18
- else {
19
- // For non-retriable errors or last attempt, return the response
20
- return response;
21
- }
22
- }
23
- catch (error) {
24
- lastError = error instanceof Error ? error : new Error(String(error));
25
- // If this is the last attempt, throw the error
26
- if (attempt === maxRetries) {
27
- throw lastError;
28
- }
29
- }
30
- // Calculate exponential backoff delay: 2^attempt * 1000ms (1s, 2s, 4s)
31
- const delay = Math.pow(2, attempt) * 1000;
32
- await new Promise(resolve => setTimeout(resolve, delay));
33
- }
34
- throw lastError || new Error('Failed to fetch after retries');
35
- }
36
5
  async getArguments() {
37
6
  if (!env.BL_EXECUTION_DATA_URL) {
38
7
  const args = this.parseCommandLineArgs();
39
8
  return args;
40
9
  }
41
- const response = await this.fetchWithRetry(env.BL_EXECUTION_DATA_URL);
10
+ const response = await fetch(env.BL_EXECUTION_DATA_URL);
42
11
  const data = await response.json();
43
12
  return data.tasks[this.index] ?? {};
44
13
  }
@@ -1,5 +1,5 @@
1
1
  import { createClient } from "@hey-api/client-fetch";
2
- import { generateInternalUrl, getForcedUrl } from "../common/internal.js";
2
+ import { getForcedUrl, getGlobalUniqueHash } from "../common/internal.js";
3
3
  import { settings } from "../common/settings.js";
4
4
  import { client as defaultClient } from "./client/client.gen.js";
5
5
  export class ResponseError extends Error {
@@ -44,7 +44,8 @@ export class SandboxAction {
44
44
  return this.sandbox.metadata?.url ?? `${settings.runUrl}/${settings.workspace}/sandboxes/${this.name}`;
45
45
  }
46
46
  get internalUrl() {
47
- return generateInternalUrl(settings.workspace, "sandbox", this.name, settings.env, settings.runInternalProtocol, settings.runInternalHostname, settings.blCloud, settings.workspaceId);
47
+ const hash = getGlobalUniqueHash(settings.workspace, "sandbox", this.name);
48
+ return `${settings.runInternalProtocol}://bl-${settings.env}-${hash}.${settings.runInternalHostname}`;
48
49
  }
49
50
  get client() {
50
51
  if (this.sandbox.forceUrl) {
@@ -5,4 +5,5 @@ export * from "./filesystem/index.js";
5
5
  export * from "./codegen/index.js";
6
6
  export * from "./sandbox.js";
7
7
  export * from "./types.js";
8
+ export * from "./interpreter.js";
8
9
  // Re-export everything from client except ClientOptions to avoid conflict