@blaxel/core 0.2.36-dev.185 → 0.2.36-dev.190

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 (172) hide show
  1. package/dist/cjs/.tsbuildinfo +1 -0
  2. package/dist/{common → cjs/common}/settings.js +2 -2
  3. package/dist/{tools → cjs/types/tools}/index.d.ts +1 -0
  4. package/dist/esm/.tsbuildinfo +1 -0
  5. package/dist/esm/agents/index.js +104 -0
  6. package/dist/esm/authentication/apikey.js +20 -0
  7. package/dist/esm/authentication/clientcredentials.js +81 -0
  8. package/dist/esm/authentication/credentials.js +13 -0
  9. package/dist/esm/authentication/deviceMode.js +66 -0
  10. package/dist/esm/authentication/index.js +56 -0
  11. package/dist/esm/authentication/types.js +1 -0
  12. package/dist/esm/cache/index.js +20 -0
  13. package/dist/esm/client/authentication.js +11 -0
  14. package/dist/esm/client/client.gen.js +5 -0
  15. package/dist/esm/client/client.js +1 -0
  16. package/dist/esm/client/index.js +3 -0
  17. package/dist/esm/client/interceptors.js +14 -0
  18. package/dist/esm/client/sdk.gen.js +1649 -0
  19. package/dist/esm/client/types.gen.js +3 -0
  20. package/dist/esm/common/autoload.js +23 -0
  21. package/dist/esm/common/env.js +36 -0
  22. package/dist/esm/common/errors.js +14 -0
  23. package/dist/esm/common/internal.js +182 -0
  24. package/dist/esm/common/internal.test.js +37 -0
  25. package/dist/esm/common/logger.js +65 -0
  26. package/dist/esm/common/node.js +20 -0
  27. package/dist/esm/common/settings.js +167 -0
  28. package/dist/esm/index.browser.test.js +10 -0
  29. package/dist/esm/index.js +17 -0
  30. package/dist/esm/jobs/index.js +3 -0
  31. package/dist/esm/jobs/jobs.js +86 -0
  32. package/dist/esm/jobs/start.js +62 -0
  33. package/dist/esm/jobs/types.js +1 -0
  34. package/dist/esm/mcp/client.js +243 -0
  35. package/dist/esm/mcp/index.js +2 -0
  36. package/dist/esm/mcp/server.js +176 -0
  37. package/dist/esm/models/index.js +25 -0
  38. package/dist/esm/package.json +1 -0
  39. package/dist/esm/sandbox/action.js +79 -0
  40. package/dist/esm/sandbox/client/client.gen.js +3 -0
  41. package/dist/esm/sandbox/client/index.js +3 -0
  42. package/dist/esm/sandbox/client/sdk.gen.js +270 -0
  43. package/dist/esm/sandbox/client/types.gen.js +2 -0
  44. package/dist/esm/sandbox/filesystem/filesystem.js +272 -0
  45. package/dist/esm/sandbox/filesystem/index.js +2 -0
  46. package/dist/esm/sandbox/filesystem/types.js +1 -0
  47. package/dist/esm/sandbox/index.js +7 -0
  48. package/dist/esm/sandbox/network/index.js +1 -0
  49. package/dist/esm/sandbox/network/network.js +6 -0
  50. package/dist/esm/sandbox/preview.js +141 -0
  51. package/dist/esm/sandbox/process/index.js +1 -0
  52. package/dist/esm/sandbox/process/process.js +185 -0
  53. package/dist/esm/sandbox/sandbox.js +174 -0
  54. package/dist/esm/sandbox/session.js +119 -0
  55. package/dist/esm/sandbox/types.js +76 -0
  56. package/dist/esm/telemetry/telemetry.js +74 -0
  57. package/dist/esm/tools/index.js +44 -0
  58. package/dist/esm/tools/mcpTool.js +213 -0
  59. package/dist/esm/tools/types.js +1 -0
  60. package/dist/esm/tools/zodSchema.js +43 -0
  61. package/dist/esm/volume/index.js +109 -0
  62. package/package.json +17 -30
  63. /package/dist/{agents → cjs/agents}/index.js +0 -0
  64. /package/dist/{authentication → cjs/authentication}/apikey.js +0 -0
  65. /package/dist/{authentication → cjs/authentication}/clientcredentials.js +0 -0
  66. /package/dist/{authentication → cjs/authentication}/credentials.js +0 -0
  67. /package/dist/{authentication → cjs/authentication}/deviceMode.js +0 -0
  68. /package/dist/{authentication → cjs/authentication}/index.js +0 -0
  69. /package/dist/{authentication → cjs/authentication}/types.js +0 -0
  70. /package/dist/{cache → cjs/cache}/index.js +0 -0
  71. /package/dist/{client → cjs/client}/authentication.js +0 -0
  72. /package/dist/{client → cjs/client}/client.gen.js +0 -0
  73. /package/dist/{client → cjs/client}/client.js +0 -0
  74. /package/dist/{client → cjs/client}/index.js +0 -0
  75. /package/dist/{client → cjs/client}/interceptors.js +0 -0
  76. /package/dist/{client → cjs/client}/sdk.gen.js +0 -0
  77. /package/dist/{client → cjs/client}/types.gen.js +0 -0
  78. /package/dist/{common → cjs/common}/autoload.js +0 -0
  79. /package/dist/{common → cjs/common}/env.js +0 -0
  80. /package/dist/{common → cjs/common}/errors.js +0 -0
  81. /package/dist/{common → cjs/common}/internal.js +0 -0
  82. /package/dist/{common → cjs/common}/internal.test.js +0 -0
  83. /package/dist/{common → cjs/common}/logger.js +0 -0
  84. /package/dist/{common → cjs/common}/node.js +0 -0
  85. /package/dist/{index.browser.test.js → cjs/index.browser.test.js} +0 -0
  86. /package/dist/{index.js → cjs/index.js} +0 -0
  87. /package/dist/{jobs → cjs/jobs}/index.js +0 -0
  88. /package/dist/{jobs → cjs/jobs}/jobs.js +0 -0
  89. /package/dist/{jobs → cjs/jobs}/start.js +0 -0
  90. /package/dist/{jobs → cjs/jobs}/types.js +0 -0
  91. /package/dist/{mcp → cjs/mcp}/client.js +0 -0
  92. /package/dist/{mcp → cjs/mcp}/index.js +0 -0
  93. /package/dist/{mcp → cjs/mcp}/server.js +0 -0
  94. /package/dist/{models → cjs/models}/index.js +0 -0
  95. /package/dist/{sandbox → cjs/sandbox}/action.js +0 -0
  96. /package/dist/{sandbox → cjs/sandbox}/client/client.gen.js +0 -0
  97. /package/dist/{sandbox → cjs/sandbox}/client/index.js +0 -0
  98. /package/dist/{sandbox → cjs/sandbox}/client/sdk.gen.js +0 -0
  99. /package/dist/{sandbox → cjs/sandbox}/client/types.gen.js +0 -0
  100. /package/dist/{sandbox → cjs/sandbox}/filesystem/filesystem.js +0 -0
  101. /package/dist/{sandbox → cjs/sandbox}/filesystem/index.js +0 -0
  102. /package/dist/{sandbox → cjs/sandbox}/filesystem/types.js +0 -0
  103. /package/dist/{sandbox → cjs/sandbox}/index.js +0 -0
  104. /package/dist/{sandbox → cjs/sandbox}/network/index.js +0 -0
  105. /package/dist/{sandbox → cjs/sandbox}/network/network.js +0 -0
  106. /package/dist/{sandbox → cjs/sandbox}/preview.js +0 -0
  107. /package/dist/{sandbox → cjs/sandbox}/process/index.js +0 -0
  108. /package/dist/{sandbox → cjs/sandbox}/process/process.js +0 -0
  109. /package/dist/{sandbox → cjs/sandbox}/sandbox.js +0 -0
  110. /package/dist/{sandbox → cjs/sandbox}/session.js +0 -0
  111. /package/dist/{sandbox → cjs/sandbox}/types.js +0 -0
  112. /package/dist/{telemetry → cjs/telemetry}/telemetry.js +0 -0
  113. /package/dist/{tools → cjs/tools}/index.js +0 -0
  114. /package/dist/{tools → cjs/tools}/mcpTool.js +0 -0
  115. /package/dist/{tools → cjs/tools}/types.js +0 -0
  116. /package/dist/{tools → cjs/tools}/zodSchema.js +0 -0
  117. /package/dist/{agents → cjs/types/agents}/index.d.ts +0 -0
  118. /package/dist/{authentication → cjs/types/authentication}/apikey.d.ts +0 -0
  119. /package/dist/{authentication → cjs/types/authentication}/clientcredentials.d.ts +0 -0
  120. /package/dist/{authentication → cjs/types/authentication}/credentials.d.ts +0 -0
  121. /package/dist/{authentication → cjs/types/authentication}/deviceMode.d.ts +0 -0
  122. /package/dist/{authentication → cjs/types/authentication}/index.d.ts +0 -0
  123. /package/dist/{authentication → cjs/types/authentication}/types.d.ts +0 -0
  124. /package/dist/{cache → cjs/types/cache}/index.d.ts +0 -0
  125. /package/dist/{client → cjs/types/client}/authentication.d.ts +0 -0
  126. /package/dist/{client → cjs/types/client}/client.d.ts +0 -0
  127. /package/dist/{client → cjs/types/client}/client.gen.d.ts +0 -0
  128. /package/dist/{client → cjs/types/client}/index.d.ts +0 -0
  129. /package/dist/{client → cjs/types/client}/interceptors.d.ts +0 -0
  130. /package/dist/{client → cjs/types/client}/sdk.gen.d.ts +0 -0
  131. /package/dist/{client → cjs/types/client}/types.gen.d.ts +0 -0
  132. /package/dist/{common → cjs/types/common}/autoload.d.ts +0 -0
  133. /package/dist/{common → cjs/types/common}/env.d.ts +0 -0
  134. /package/dist/{common → cjs/types/common}/errors.d.ts +0 -0
  135. /package/dist/{common → cjs/types/common}/internal.d.ts +0 -0
  136. /package/dist/{common → cjs/types/common}/internal.test.d.ts +0 -0
  137. /package/dist/{common → cjs/types/common}/logger.d.ts +0 -0
  138. /package/dist/{common → cjs/types/common}/node.d.ts +0 -0
  139. /package/dist/{common → cjs/types/common}/settings.d.ts +0 -0
  140. /package/dist/{index.browser.test.d.ts → cjs/types/index.browser.test.d.ts} +0 -0
  141. /package/dist/{index.d.ts → cjs/types/index.d.ts} +0 -0
  142. /package/dist/{jobs → cjs/types/jobs}/index.d.ts +0 -0
  143. /package/dist/{jobs → cjs/types/jobs}/jobs.d.ts +0 -0
  144. /package/dist/{jobs → cjs/types/jobs}/start.d.ts +0 -0
  145. /package/dist/{jobs → cjs/types/jobs}/types.d.ts +0 -0
  146. /package/dist/{mcp → cjs/types/mcp}/client.d.ts +0 -0
  147. /package/dist/{mcp → cjs/types/mcp}/index.d.ts +0 -0
  148. /package/dist/{mcp → cjs/types/mcp}/server.d.ts +0 -0
  149. /package/dist/{models → cjs/types/models}/index.d.ts +0 -0
  150. /package/dist/{sandbox → cjs/types/sandbox}/action.d.ts +0 -0
  151. /package/dist/{sandbox → cjs/types/sandbox}/client/client.gen.d.ts +0 -0
  152. /package/dist/{sandbox → cjs/types/sandbox}/client/index.d.ts +0 -0
  153. /package/dist/{sandbox → cjs/types/sandbox}/client/sdk.gen.d.ts +0 -0
  154. /package/dist/{sandbox → cjs/types/sandbox}/client/types.gen.d.ts +0 -0
  155. /package/dist/{sandbox → cjs/types/sandbox}/filesystem/filesystem.d.ts +0 -0
  156. /package/dist/{sandbox → cjs/types/sandbox}/filesystem/index.d.ts +0 -0
  157. /package/dist/{sandbox → cjs/types/sandbox}/filesystem/types.d.ts +0 -0
  158. /package/dist/{sandbox → cjs/types/sandbox}/index.d.ts +0 -0
  159. /package/dist/{sandbox → cjs/types/sandbox}/network/index.d.ts +0 -0
  160. /package/dist/{sandbox → cjs/types/sandbox}/network/network.d.ts +0 -0
  161. /package/dist/{sandbox → cjs/types/sandbox}/preview.d.ts +0 -0
  162. /package/dist/{sandbox → cjs/types/sandbox}/process/index.d.ts +0 -0
  163. /package/dist/{sandbox → cjs/types/sandbox}/process/process.d.ts +0 -0
  164. /package/dist/{sandbox → cjs/types/sandbox}/sandbox.d.ts +0 -0
  165. /package/dist/{sandbox → cjs/types/sandbox}/session.d.ts +0 -0
  166. /package/dist/{sandbox → cjs/types/sandbox}/types.d.ts +0 -0
  167. /package/dist/{telemetry → cjs/types/telemetry}/telemetry.d.ts +0 -0
  168. /package/dist/{tools → cjs/types/tools}/mcpTool.d.ts +0 -0
  169. /package/dist/{tools → cjs/types/tools}/types.d.ts +0 -0
  170. /package/dist/{tools → cjs/types/tools}/zodSchema.d.ts +0 -0
  171. /package/dist/{volume → cjs/types/volume}/index.d.ts +0 -0
  172. /package/dist/{volume → cjs/volume}/index.js +0 -0
@@ -0,0 +1,3 @@
1
+ /* eslint-disable */
2
+ // This file is auto-generated by @hey-api/openapi-ts
3
+ export {};
@@ -0,0 +1,23 @@
1
+ import { client } from "../client/client.gen.js";
2
+ import { interceptors } from "../client/interceptors.js";
3
+ import { client as clientSandbox } from "../sandbox/client/client.gen.js";
4
+ import { settings } from "./settings.js";
5
+ client.setConfig({
6
+ baseUrl: settings.baseUrl,
7
+ });
8
+ for (const interceptor of interceptors) {
9
+ // @ts-expect-error - Interceptor is not typed
10
+ client.interceptors.request.use(interceptor);
11
+ // @ts-expect-error - Interceptor is not typed
12
+ clientSandbox.interceptors.request.use(interceptor);
13
+ }
14
+ // Allow to set custom configuration for browser environment
15
+ export function initialize(config) {
16
+ settings.setConfig(config);
17
+ client.setConfig({
18
+ baseUrl: settings.baseUrl,
19
+ });
20
+ }
21
+ export function authenticate() {
22
+ return settings.authenticate();
23
+ }
@@ -0,0 +1,36 @@
1
+ /* eslint-disable */
2
+ import toml from "toml";
3
+ import { dotenv, fs } from "./node.js";
4
+ const secretEnv = {};
5
+ const configEnv = {};
6
+ if (fs !== null && dotenv !== null) {
7
+ try {
8
+ const configFile = fs.readFileSync("blaxel.toml", "utf8");
9
+ const configInfos = toml.parse(configFile);
10
+ for (const key in configInfos.env) {
11
+ configEnv[key] = configInfos.env[key];
12
+ }
13
+ }
14
+ catch (error) { }
15
+ try {
16
+ const secretFile = fs.readFileSync(".env", "utf8");
17
+ const parsed = dotenv.parse(secretFile);
18
+ Object.assign(secretEnv, parsed);
19
+ }
20
+ catch (error) { }
21
+ }
22
+ const env = new Proxy({}, {
23
+ get: (target, prop) => {
24
+ if (secretEnv[prop]) {
25
+ return secretEnv[prop];
26
+ }
27
+ if (configEnv[prop]) {
28
+ return configEnv[prop];
29
+ }
30
+ if (typeof process !== "undefined" && process.env) {
31
+ return process.env[prop];
32
+ }
33
+ return undefined;
34
+ },
35
+ });
36
+ export { env };
@@ -0,0 +1,14 @@
1
+ export function handleDynamicImportError(err) {
2
+ if (err instanceof Error) {
3
+ // We check if it's module import error and retrieve package name from the error message with a regex
4
+ if (err.message.includes("Cannot find module")) {
5
+ const packageName = err.message.match(/Cannot find module '([^']+)'/)?.[1];
6
+ if (packageName) {
7
+ err.message = `Dependency not found. Please run one of the following commands to install it:
8
+ - npm: 'npm install ${packageName}'
9
+ - yarn: 'yarn add ${packageName}'
10
+ - pnpm: 'pnpm add ${packageName}'`;
11
+ }
12
+ }
13
+ }
14
+ }
@@ -0,0 +1,182 @@
1
+ /* eslint-disable */
2
+ import { env } from './env.js';
3
+ // Pure JS MD5 implementation that matches standard crypto MD5
4
+ function md5(input) {
5
+ function cmn(q, a, b, x, s, t) {
6
+ a = (((a + q) | 0) + ((x + t) | 0)) | 0;
7
+ return (((a << s) | (a >>> (32 - s))) + b) | 0;
8
+ }
9
+ function ff(a, b, c, d, x, s, t) {
10
+ return cmn((b & c) | (~b & d), a, b, x, s, t);
11
+ }
12
+ function gg(a, b, c, d, x, s, t) {
13
+ return cmn((b & d) | (c & ~d), a, b, x, s, t);
14
+ }
15
+ function hh(a, b, c, d, x, s, t) {
16
+ return cmn(b ^ c ^ d, a, b, x, s, t);
17
+ }
18
+ function ii(a, b, c, d, x, s, t) {
19
+ return cmn(c ^ (b | ~d), a, b, x, s, t);
20
+ }
21
+ function md5cycle(x, k) {
22
+ let [a, b, c, d] = x;
23
+ a = ff(a, b, c, d, k[0], 7, -680876936);
24
+ d = ff(d, a, b, c, k[1], 12, -389564586);
25
+ c = ff(c, d, a, b, k[2], 17, 606105819);
26
+ b = ff(b, c, d, a, k[3], 22, -1044525330);
27
+ a = ff(a, b, c, d, k[4], 7, -176418897);
28
+ d = ff(d, a, b, c, k[5], 12, 1200080426);
29
+ c = ff(c, d, a, b, k[6], 17, -1473231341);
30
+ b = ff(b, c, d, a, k[7], 22, -45705983);
31
+ a = ff(a, b, c, d, k[8], 7, 1770035416);
32
+ d = ff(d, a, b, c, k[9], 12, -1958414417);
33
+ c = ff(c, d, a, b, k[10], 17, -42063);
34
+ b = ff(b, c, d, a, k[11], 22, -1990404162);
35
+ a = ff(a, b, c, d, k[12], 7, 1804603682);
36
+ d = ff(d, a, b, c, k[13], 12, -40341101);
37
+ c = ff(c, d, a, b, k[14], 17, -1502002290);
38
+ b = ff(b, c, d, a, k[15], 22, 1236535329);
39
+ a = gg(a, b, c, d, k[1], 5, -165796510);
40
+ d = gg(d, a, b, c, k[6], 9, -1069501632);
41
+ c = gg(c, d, a, b, k[11], 14, 643717713);
42
+ b = gg(b, c, d, a, k[0], 20, -373897302);
43
+ a = gg(a, b, c, d, k[5], 5, -701558691);
44
+ d = gg(d, a, b, c, k[10], 9, 38016083);
45
+ c = gg(c, d, a, b, k[15], 14, -660478335);
46
+ b = gg(b, c, d, a, k[4], 20, -405537848);
47
+ a = gg(a, b, c, d, k[9], 5, 568446438);
48
+ d = gg(d, a, b, c, k[14], 9, -1019803690);
49
+ c = gg(c, d, a, b, k[3], 14, -187363961);
50
+ b = gg(b, c, d, a, k[8], 20, 1163531501);
51
+ a = gg(a, b, c, d, k[13], 5, -1444681467);
52
+ d = gg(d, a, b, c, k[2], 9, -51403784);
53
+ c = gg(c, d, a, b, k[7], 14, 1735328473);
54
+ b = gg(b, c, d, a, k[12], 20, -1926607734);
55
+ a = hh(a, b, c, d, k[5], 4, -378558);
56
+ d = hh(d, a, b, c, k[8], 11, -2022574463);
57
+ c = hh(c, d, a, b, k[11], 16, 1839030562);
58
+ b = hh(b, c, d, a, k[14], 23, -35309556);
59
+ a = hh(a, b, c, d, k[1], 4, -1530992060);
60
+ d = hh(d, a, b, c, k[4], 11, 1272893353);
61
+ c = hh(c, d, a, b, k[7], 16, -155497632);
62
+ b = hh(b, c, d, a, k[10], 23, -1094730640);
63
+ a = hh(a, b, c, d, k[13], 4, 681279174);
64
+ d = hh(d, a, b, c, k[0], 11, -358537222);
65
+ c = hh(c, d, a, b, k[3], 16, -722521979);
66
+ b = hh(b, c, d, a, k[6], 23, 76029189);
67
+ a = hh(a, b, c, d, k[9], 4, -640364487);
68
+ d = hh(d, a, b, c, k[12], 11, -421815835);
69
+ c = hh(c, d, a, b, k[15], 16, 530742520);
70
+ b = hh(b, c, d, a, k[2], 23, -995338651);
71
+ a = ii(a, b, c, d, k[0], 6, -198630844);
72
+ d = ii(d, a, b, c, k[7], 10, 1126891415);
73
+ c = ii(c, d, a, b, k[14], 15, -1416354905);
74
+ b = ii(b, c, d, a, k[5], 21, -57434055);
75
+ a = ii(a, b, c, d, k[12], 6, 1700485571);
76
+ d = ii(d, a, b, c, k[3], 10, -1894986606);
77
+ c = ii(c, d, a, b, k[10], 15, -1051523);
78
+ b = ii(b, c, d, a, k[1], 21, -2054922799);
79
+ a = ii(a, b, c, d, k[8], 6, 1873313359);
80
+ d = ii(d, a, b, c, k[15], 10, -30611744);
81
+ c = ii(c, d, a, b, k[6], 15, -1560198380);
82
+ b = ii(b, c, d, a, k[13], 21, 1309151649);
83
+ a = ii(a, b, c, d, k[4], 6, -145523070);
84
+ d = ii(d, a, b, c, k[11], 10, -1120210379);
85
+ c = ii(c, d, a, b, k[2], 15, 718787259);
86
+ b = ii(b, c, d, a, k[9], 21, -343485551);
87
+ x[0] = (a + x[0]) | 0;
88
+ x[1] = (b + x[1]) | 0;
89
+ x[2] = (c + x[2]) | 0;
90
+ x[3] = (d + x[3]) | 0;
91
+ }
92
+ function md5blk(s) {
93
+ const md5blks = [];
94
+ for (let i = 0; i < 64; i += 4) {
95
+ md5blks[i >> 2] =
96
+ s.charCodeAt(i) +
97
+ (s.charCodeAt(i + 1) << 8) +
98
+ (s.charCodeAt(i + 2) << 16) +
99
+ (s.charCodeAt(i + 3) << 24);
100
+ }
101
+ return md5blks;
102
+ }
103
+ function md51(s) {
104
+ let n = s.length, state = [1732584193, -271733879, -1732584194, 271733878], i;
105
+ for (i = 64; i <= n; i += 64) {
106
+ md5cycle(state, md5blk(s.substring(i - 64, i)));
107
+ }
108
+ s = s.substring(i - 64);
109
+ const tail = Array(16).fill(0);
110
+ for (i = 0; i < s.length; i++)
111
+ tail[i >> 2] |= s.charCodeAt(i) << ((i % 4) << 3);
112
+ tail[i >> 2] |= 0x80 << ((i % 4) << 3);
113
+ if (i > 55) {
114
+ md5cycle(state, tail);
115
+ tail.fill(0);
116
+ }
117
+ tail[14] = n * 8;
118
+ md5cycle(state, tail);
119
+ return state;
120
+ }
121
+ // Fixed hex conversion function
122
+ function rhex(n) {
123
+ let s = '';
124
+ for (let j = 0; j < 4; j++) {
125
+ s += ((n >> (j * 8)) & 0xFF).toString(16).padStart(2, '0');
126
+ }
127
+ return s;
128
+ }
129
+ return md51(input).map(rhex).join('');
130
+ }
131
+ export function getAlphanumericLimitedHash(input, maxSize = 48) {
132
+ const hash = md5(input);
133
+ return hash.length > maxSize ? hash.substring(0, maxSize) : hash;
134
+ }
135
+ export function getGlobalUniqueHash(workspace, type, name) {
136
+ const globalUniqueName = `${workspace}-${type}-${name}`;
137
+ return getAlphanumericLimitedHash(globalUniqueName, 48);
138
+ }
139
+ export function pluralize(type) {
140
+ const word = type.toLowerCase();
141
+ // Words ending in s, ss, sh, ch, x, z - add 'es'
142
+ if (word.endsWith('s') || word.endsWith('ss') || word.endsWith('sh') ||
143
+ word.endsWith('ch') || word.endsWith('x') || word.endsWith('z')) {
144
+ return type + 'es';
145
+ }
146
+ // Words ending in consonant + y - change y to ies
147
+ if (word.endsWith('y') && word.length > 1) {
148
+ const beforeY = word[word.length - 2];
149
+ if (!'aeiou'.includes(beforeY)) {
150
+ return type.slice(0, -1) + 'ies';
151
+ }
152
+ }
153
+ // Words ending in f or fe - change to ves
154
+ if (word.endsWith('f')) {
155
+ return type.slice(0, -1) + 'ves';
156
+ }
157
+ if (word.endsWith('fe')) {
158
+ return type.slice(0, -2) + 'ves';
159
+ }
160
+ // Words ending in consonant + o - add 'es'
161
+ if (word.endsWith('o') && word.length > 1) {
162
+ const beforeO = word[word.length - 2];
163
+ if (!'aeiou'.includes(beforeO)) {
164
+ return type + 'es';
165
+ }
166
+ }
167
+ // Default case - just add 's'
168
+ return type + 's';
169
+ }
170
+ export function getForcedUrl(type, name) {
171
+ const pluralType = pluralize(type);
172
+ const envVar = name.replace(/-/g, "_").toUpperCase();
173
+ // BL_FUNCTIONS_NAME_URL
174
+ if (env[`BL_${pluralType.toUpperCase()}_${envVar}_URL`]) {
175
+ return new URL(env[`BL_${pluralType.toUpperCase()}_${envVar}_URL`]);
176
+ }
177
+ // BL_FUNCTION_NAME_URL
178
+ if (env[`BL_${type.toUpperCase()}_${envVar}_URL`]) {
179
+ return new URL(env[`BL_${type.toUpperCase()}_${envVar}_URL`]);
180
+ }
181
+ return null;
182
+ }
@@ -0,0 +1,37 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { getAlphanumericLimitedHash, getGlobalUniqueHash } from "./internal.js";
3
+ describe('getAlphanumericLimitedHash', () => {
4
+ it('returns correct MD5 hash for a known string', () => {
5
+ // MD5 of 'hello' is 5d41402abc4b2a76b9719d911017c592
6
+ expect(getAlphanumericLimitedHash('hello')).toBe('5d41402abc4b2a76b9719d911017c592');
7
+ });
8
+ it('respects the maxSize parameter', () => {
9
+ const hash = getAlphanumericLimitedHash('hello', 8);
10
+ expect(hash.length).toBe(8);
11
+ expect(hash).toBe('5d41402a');
12
+ });
13
+ it('returns full hash if maxSize is larger than hash', () => {
14
+ const hash = getAlphanumericLimitedHash('hello', 64);
15
+ expect(hash).toBe('5d41402abc4b2a76b9719d911017c592');
16
+ });
17
+ });
18
+ const testCases = [
19
+ {
20
+ workspace: 'charlou-dev',
21
+ type: 'function',
22
+ name: 'blaxel-search',
23
+ expected: '594d9322779f4a07a55a7bf1050360c6'
24
+ }, {
25
+ workspace: 'charlou-dev',
26
+ type: 'agent',
27
+ name: 'toto',
28
+ expected: '1bb3a151bda194751b062df8edb59eaf',
29
+ }
30
+ ];
31
+ describe('getGlobalUniqueHash', () => {
32
+ testCases.forEach(({ workspace, type, name, expected }) => {
33
+ it(`returns ${expected} for ${workspace}-${type}-${name}`, () => {
34
+ expect(getGlobalUniqueHash(workspace, type, name)).toBe(expected);
35
+ });
36
+ });
37
+ });
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Stringify an object with a limited depth
3
+ * @param obj The object to stringify
4
+ * @param maxDepth Maximum depth (default: 1)
5
+ * @param depth Current depth (internal use)
6
+ */
7
+ export function stringify(obj, maxDepth = 1, depth = 0) {
8
+ if (obj instanceof Error)
9
+ return obj.stack || obj.message;
10
+ if (obj === null)
11
+ return 'null';
12
+ if (obj === undefined)
13
+ return 'undefined';
14
+ // If we've reached max depth or it's not an object
15
+ if (depth >= maxDepth || typeof obj !== 'object') {
16
+ return typeof obj === 'object' ? `[${Array.isArray(obj) ? 'Array' : 'object'}]` :
17
+ typeof obj === 'string' ? `"${obj}"` : String(obj);
18
+ }
19
+ // Handle arrays
20
+ if (Array.isArray(obj)) {
21
+ return `[${obj.map(item => stringify(item, maxDepth, depth + 1)).join(', ')}]`;
22
+ }
23
+ // Handle objects
24
+ const pairs = Object.entries(obj).map(([key, val]) => `"${key}": ${stringify(val, maxDepth, depth + 1)}`);
25
+ return `{${pairs.join(', ')}}`;
26
+ }
27
+ class Logger {
28
+ logger;
29
+ constructor() {
30
+ this.logger = null;
31
+ }
32
+ setLogger(logger) {
33
+ this.logger = logger;
34
+ }
35
+ parseArgs(args) {
36
+ return args.map((arg) => {
37
+ if (arg instanceof Error) {
38
+ return arg.stack ?? arg.message;
39
+ }
40
+ return arg;
41
+ }).join(" ");
42
+ }
43
+ info(...message) {
44
+ if (this.logger) {
45
+ this.logger.info(this.parseArgs(message));
46
+ }
47
+ }
48
+ debug(...message) {
49
+ if (this.logger) {
50
+ this.logger.debug(this.parseArgs(message));
51
+ }
52
+ }
53
+ warn(...message) {
54
+ if (this.logger) {
55
+ this.logger.warn(this.parseArgs(message));
56
+ }
57
+ }
58
+ error(...message) {
59
+ if (this.logger) {
60
+ this.logger.error(this.parseArgs(message));
61
+ }
62
+ }
63
+ }
64
+ const logger = new Logger();
65
+ export { logger };
@@ -0,0 +1,20 @@
1
+ /* eslint-disable */
2
+ const isNode = typeof process !== "undefined" &&
3
+ process.versions != null &&
4
+ process.versions.node != null;
5
+ let fs = null;
6
+ let os = null;
7
+ let path = null;
8
+ let dotenv = null;
9
+ if (isNode) {
10
+ try {
11
+ fs = eval("require")("fs");
12
+ os = eval("require")("os");
13
+ path = eval("require")("path");
14
+ dotenv = eval("require")("dotenv");
15
+ }
16
+ catch (e) {
17
+ console.warn("fs and os are not available in this environment");
18
+ }
19
+ }
20
+ export { dotenv, fs, os, path };
@@ -0,0 +1,167 @@
1
+ import { authentication } from "../authentication/index.js";
2
+ import { env } from "../common/env.js";
3
+ // Function to get package version
4
+ function getPackageVersion() {
5
+ try {
6
+ // Try to require package.json (Node.js only, gracefully fails in browser)
7
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
8
+ const packageJson = {"version":"0.2.36-dev.190","commit":"fcb44cfa2e6fc7b7cc20cf8bf70e3bf380d74146"};
9
+ return packageJson.version || "unknown";
10
+ }
11
+ catch {
12
+ // Fallback for browser environments or if require fails
13
+ return "unknown";
14
+ }
15
+ }
16
+ // Function to get OS and architecture
17
+ function getOsArch() {
18
+ try {
19
+ // Node.js environment
20
+ if (typeof process !== 'undefined' && process.platform && process.arch) {
21
+ const platform = process.platform === 'win32' ? 'windows' :
22
+ process.platform === 'darwin' ? 'darwin' :
23
+ process.platform === 'linux' ? 'linux' : process.platform;
24
+ return `${platform}/${process.arch}`;
25
+ }
26
+ }
27
+ catch {
28
+ // Fall through to browser detection
29
+ }
30
+ // Browser environment - use fixed detection
31
+ try {
32
+ // @ts-ignore - navigator is available in browser environments
33
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
34
+ if (typeof navigator !== 'undefined' && navigator?.platform) {
35
+ // @ts-ignore - navigator.platform is available in browser environments
36
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
37
+ const navPlatform = navigator.platform.toLowerCase();
38
+ const platform = navPlatform.includes('win') ? 'windows' :
39
+ navPlatform.includes('mac') ? 'darwin' :
40
+ navPlatform.includes('linux') ? 'linux' : 'browser';
41
+ const arch = navPlatform.includes('64') ? 'amd64' : 'unknown';
42
+ return `${platform}/${arch}`;
43
+ }
44
+ }
45
+ catch {
46
+ // Ignore errors
47
+ }
48
+ return "browser/unknown";
49
+ }
50
+ // Function to get commit hash
51
+ function getCommitHash() {
52
+ try {
53
+ // Try to require package.json and look for commit field (set during build)
54
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
55
+ const packageJson = {"version":"0.2.36-dev.190","commit":"fcb44cfa2e6fc7b7cc20cf8bf70e3bf380d74146"};
56
+ // Check for commit in various possible locations
57
+ const commit = packageJson.commit || packageJson.buildInfo?.commit;
58
+ if (commit) {
59
+ return commit.length > 7 ? commit.substring(0, 7) : commit;
60
+ }
61
+ }
62
+ catch {
63
+ // Fallback for browser environments or if require fails
64
+ }
65
+ return "unknown";
66
+ }
67
+ class Settings {
68
+ credentials;
69
+ config;
70
+ _version = null;
71
+ constructor() {
72
+ this.credentials = authentication();
73
+ this.config = {
74
+ proxy: "",
75
+ apikey: "",
76
+ workspace: "",
77
+ };
78
+ }
79
+ setConfig(config) {
80
+ this.config = config;
81
+ }
82
+ get env() {
83
+ return env.BL_ENV || "prod";
84
+ }
85
+ get baseUrl() {
86
+ if (this.config.proxy) {
87
+ return this.config.proxy + "/api";
88
+ }
89
+ if (env.BL_API_URL) {
90
+ return env.BL_API_URL;
91
+ }
92
+ if (this.env === "prod") {
93
+ return "https://api.blaxel.ai/v0";
94
+ }
95
+ return "https://api.blaxel.dev/v0";
96
+ }
97
+ get runUrl() {
98
+ if (this.config.proxy) {
99
+ return this.config.proxy + "/run";
100
+ }
101
+ if (env.BL_RUN_URL) {
102
+ return env.BL_RUN_URL;
103
+ }
104
+ if (this.env === "prod") {
105
+ return "https://run.blaxel.ai";
106
+ }
107
+ return "https://run.blaxel.dev";
108
+ }
109
+ get workspace() {
110
+ return this.config.workspace || this.credentials.workspace || "";
111
+ }
112
+ get authorization() {
113
+ if (this.config.apikey) {
114
+ return 'Bearer ' + this.token;
115
+ }
116
+ return this.credentials.authorization;
117
+ }
118
+ get token() {
119
+ if (this.config.apikey) {
120
+ return this.config.apikey;
121
+ }
122
+ return this.credentials.token;
123
+ }
124
+ get version() {
125
+ if (this._version === null) {
126
+ this._version = getPackageVersion();
127
+ }
128
+ return this._version;
129
+ }
130
+ get headers() {
131
+ const osArch = getOsArch();
132
+ const commitHash = getCommitHash();
133
+ return {
134
+ "x-blaxel-authorization": this.authorization,
135
+ "x-blaxel-workspace": this.workspace || "",
136
+ "User-Agent": `blaxel/sdk/typescript/${this.version} (${osArch}) blaxel/${commitHash}`,
137
+ };
138
+ }
139
+ get name() {
140
+ return env.BL_NAME || "";
141
+ }
142
+ get type() {
143
+ return env.BL_TYPE || "agents";
144
+ }
145
+ get runInternalHostname() {
146
+ if (!this.generation) {
147
+ return "";
148
+ }
149
+ return env.BL_RUN_INTERNAL_HOST || "";
150
+ }
151
+ get runInternalProtocol() {
152
+ return env.BL_RUN_INTERNAL_PROTOCOL || "https";
153
+ }
154
+ get blCloud() {
155
+ return env.BL_CLOUD === "true";
156
+ }
157
+ get generation() {
158
+ return env.BL_GENERATION || "";
159
+ }
160
+ get loggerType() {
161
+ return env.BL_LOGGER || "http";
162
+ }
163
+ async authenticate() {
164
+ await this.credentials.authenticate();
165
+ }
166
+ }
167
+ export const settings = new Settings();
@@ -0,0 +1,10 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ // Import your SDK entry point or a function to test
3
+ import * as sdk from "./index.js";
4
+ describe('SDK Browser Integration', () => {
5
+ it('should load the SDK without Node.js-only modules', () => {
6
+ // Example: check that SDK loads and a function exists
7
+ expect(typeof sdk).toBe('object');
8
+ // Add more specific tests for your SDK as needed
9
+ });
10
+ });
@@ -0,0 +1,17 @@
1
+ import "./common/autoload.js";
2
+ export * from "./agents/index.js";
3
+ export * from "./client/client.js";
4
+ export * from "./common/autoload.js";
5
+ export * from "./common/env.js";
6
+ export * from "./common/errors.js";
7
+ export * from "./common/internal.js";
8
+ export * from "./common/logger.js";
9
+ export * from "./common/settings.js";
10
+ export * from "./jobs/index.js";
11
+ export * from "./mcp/index.js";
12
+ export * from "./models/index.js";
13
+ export * from "./sandbox/index.js";
14
+ export * from "./telemetry/telemetry.js";
15
+ export * from "./tools/index.js";
16
+ export * from "./tools/types.js";
17
+ export * from "./volume/index.js";
@@ -0,0 +1,3 @@
1
+ export * from "./jobs.js";
2
+ export * from "./start.js";
3
+ export * from "./types.js";
@@ -0,0 +1,86 @@
1
+ import { getForcedUrl, getGlobalUniqueHash } from "../common/internal.js";
2
+ import { logger } from "../common/logger.js";
3
+ import { settings } from "../common/settings.js";
4
+ import { startSpan } from '../telemetry/telemetry.js';
5
+ class BlJob {
6
+ jobName;
7
+ constructor(jobName) {
8
+ this.jobName = jobName;
9
+ }
10
+ get fallbackUrl() {
11
+ if (this.externalUrl != this.url) {
12
+ return this.externalUrl;
13
+ }
14
+ return null;
15
+ }
16
+ get externalUrl() {
17
+ return new URL(`${settings.runUrl}/${settings.workspace}/jobs/${this.jobName}`);
18
+ }
19
+ get internalUrl() {
20
+ const hash = getGlobalUniqueHash(settings.workspace, "job", this.jobName);
21
+ return new URL(`${settings.runInternalProtocol}://bl-${settings.env}-${hash}.${settings.runInternalHostname}`);
22
+ }
23
+ get forcedUrl() {
24
+ return getForcedUrl('job', this.jobName);
25
+ }
26
+ get url() {
27
+ if (this.forcedUrl)
28
+ return this.forcedUrl;
29
+ if (settings.runInternalHostname)
30
+ return this.internalUrl;
31
+ return this.externalUrl;
32
+ }
33
+ async call(url, tasks) {
34
+ const body = {
35
+ tasks: tasks
36
+ };
37
+ const response = await fetch(url.toString() + "/executions", {
38
+ method: "POST",
39
+ headers: {
40
+ ...settings.headers,
41
+ "Content-Type": "application/json",
42
+ },
43
+ body: JSON.stringify(body),
44
+ });
45
+ return response;
46
+ }
47
+ async run(tasks) {
48
+ logger.debug(`Job Calling: ${this.jobName}`);
49
+ const span = startSpan(this.jobName, {
50
+ attributes: {
51
+ "job.name": this.jobName,
52
+ "span.type": "job.run",
53
+ },
54
+ isRoot: false,
55
+ });
56
+ try {
57
+ const response = await this.call(this.url, tasks);
58
+ return await response.text();
59
+ }
60
+ catch (err) {
61
+ if (err instanceof Error) {
62
+ if (!this.fallbackUrl) {
63
+ span.setAttribute("job.run.error", err.stack);
64
+ throw err;
65
+ }
66
+ try {
67
+ const response = await this.call(this.fallbackUrl, tasks);
68
+ return await response.text();
69
+ }
70
+ catch (err) {
71
+ if (err instanceof Error) {
72
+ span.setAttribute("job.run.error", err.stack);
73
+ }
74
+ throw err;
75
+ }
76
+ }
77
+ throw err;
78
+ }
79
+ finally {
80
+ span.end();
81
+ }
82
+ }
83
+ }
84
+ export const blJob = (jobName) => {
85
+ return new BlJob(jobName);
86
+ };