@blaxel/core 0.2.70 → 0.2.71-dev.105

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 (93) hide show
  1. package/dist/cjs/.tsbuildinfo +1 -1
  2. package/dist/cjs/agents/index.js +2 -19
  3. package/dist/cjs/common/autoload.js +64 -0
  4. package/dist/cjs/common/h2fetch.js +207 -0
  5. package/dist/cjs/common/h2pool.js +137 -0
  6. package/dist/cjs/common/h2warm.js +54 -0
  7. package/dist/cjs/common/settings.js +2 -2
  8. package/dist/cjs/jobs/jobs.js +10 -28
  9. package/dist/cjs/mcp/server.js +4 -65
  10. package/dist/cjs/sandbox/action.js +33 -0
  11. package/dist/cjs/sandbox/drive/drive.js +3 -3
  12. package/dist/cjs/sandbox/filesystem/filesystem.js +1 -2
  13. package/dist/cjs/sandbox/interpreter.js +12 -2
  14. package/dist/cjs/sandbox/process/process.js +2 -2
  15. package/dist/cjs/sandbox/sandbox.js +84 -10
  16. package/dist/cjs/tools/index.js +3 -1
  17. package/dist/cjs/tools/mcpTool.js +15 -43
  18. package/dist/cjs/types/agents/index.d.ts +1 -2
  19. package/dist/cjs/types/common/autoload.d.ts +5 -0
  20. package/dist/cjs/types/common/h2fetch.d.ts +22 -0
  21. package/dist/cjs/types/common/h2pool.d.ts +38 -0
  22. package/dist/cjs/types/common/h2warm.d.ts +2 -0
  23. package/dist/cjs/types/jobs/jobs.d.ts +1 -2
  24. package/dist/cjs/types/sandbox/action.d.ts +8 -1
  25. package/dist/cjs/types/sandbox/client/types.gen.d.ts +11 -0
  26. package/dist/cjs/types/sandbox/interpreter.d.ts +1 -0
  27. package/dist/cjs/types/sandbox/sandbox.d.ts +6 -0
  28. package/dist/cjs/types/sandbox/types.d.ts +2 -0
  29. package/dist/cjs/types/tools/index.d.ts +1 -0
  30. package/dist/cjs-browser/.tsbuildinfo +1 -1
  31. package/dist/cjs-browser/agents/index.js +2 -19
  32. package/dist/cjs-browser/common/autoload.js +64 -0
  33. package/dist/cjs-browser/common/h2fetch.js +4 -0
  34. package/dist/cjs-browser/common/h2pool.js +4 -0
  35. package/dist/cjs-browser/common/h2warm.js +2 -0
  36. package/dist/cjs-browser/common/settings.js +2 -2
  37. package/dist/cjs-browser/jobs/jobs.js +10 -28
  38. package/dist/cjs-browser/mcp/server.js +4 -65
  39. package/dist/cjs-browser/sandbox/action.js +33 -0
  40. package/dist/cjs-browser/sandbox/drive/drive.js +3 -3
  41. package/dist/cjs-browser/sandbox/filesystem/filesystem.js +1 -2
  42. package/dist/cjs-browser/sandbox/interpreter.js +12 -2
  43. package/dist/cjs-browser/sandbox/process/process.js +2 -2
  44. package/dist/cjs-browser/sandbox/sandbox.js +84 -10
  45. package/dist/cjs-browser/tools/index.js +3 -1
  46. package/dist/cjs-browser/tools/mcpTool.js +15 -43
  47. package/dist/cjs-browser/types/agents/index.d.ts +1 -2
  48. package/dist/cjs-browser/types/common/autoload.d.ts +5 -0
  49. package/dist/cjs-browser/types/common/h2fetch.d.ts +22 -0
  50. package/dist/cjs-browser/types/common/h2pool.d.ts +38 -0
  51. package/dist/cjs-browser/types/common/h2warm.d.ts +2 -0
  52. package/dist/cjs-browser/types/jobs/jobs.d.ts +1 -2
  53. package/dist/cjs-browser/types/sandbox/action.d.ts +8 -1
  54. package/dist/cjs-browser/types/sandbox/client/types.gen.d.ts +11 -0
  55. package/dist/cjs-browser/types/sandbox/interpreter.d.ts +1 -0
  56. package/dist/cjs-browser/types/sandbox/sandbox.d.ts +6 -0
  57. package/dist/cjs-browser/types/sandbox/types.d.ts +2 -0
  58. package/dist/cjs-browser/types/tools/index.d.ts +1 -0
  59. package/dist/esm/.tsbuildinfo +1 -1
  60. package/dist/esm/agents/index.js +1 -19
  61. package/dist/esm/common/autoload.js +30 -0
  62. package/dist/esm/common/h2fetch.js +202 -0
  63. package/dist/esm/common/h2pool.js +101 -0
  64. package/dist/esm/common/h2warm.js +48 -0
  65. package/dist/esm/common/settings.js +2 -2
  66. package/dist/esm/jobs/jobs.js +9 -28
  67. package/dist/esm/mcp/server.js +4 -65
  68. package/dist/esm/sandbox/action.js +33 -0
  69. package/dist/esm/sandbox/drive/drive.js +3 -3
  70. package/dist/esm/sandbox/filesystem/filesystem.js +1 -2
  71. package/dist/esm/sandbox/interpreter.js +12 -2
  72. package/dist/esm/sandbox/process/process.js +2 -2
  73. package/dist/esm/sandbox/sandbox.js +51 -10
  74. package/dist/esm/tools/index.js +1 -0
  75. package/dist/esm/tools/mcpTool.js +15 -43
  76. package/dist/esm-browser/.tsbuildinfo +1 -1
  77. package/dist/esm-browser/agents/index.js +1 -19
  78. package/dist/esm-browser/common/autoload.js +30 -0
  79. package/dist/esm-browser/common/h2fetch.js +4 -0
  80. package/dist/esm-browser/common/h2pool.js +4 -0
  81. package/dist/esm-browser/common/h2warm.js +2 -0
  82. package/dist/esm-browser/common/settings.js +2 -2
  83. package/dist/esm-browser/jobs/jobs.js +9 -28
  84. package/dist/esm-browser/mcp/server.js +4 -65
  85. package/dist/esm-browser/sandbox/action.js +33 -0
  86. package/dist/esm-browser/sandbox/drive/drive.js +3 -3
  87. package/dist/esm-browser/sandbox/filesystem/filesystem.js +1 -2
  88. package/dist/esm-browser/sandbox/interpreter.js +12 -2
  89. package/dist/esm-browser/sandbox/process/process.js +2 -2
  90. package/dist/esm-browser/sandbox/sandbox.js +51 -10
  91. package/dist/esm-browser/tools/index.js +1 -0
  92. package/dist/esm-browser/tools/mcpTool.js +15 -43
  93. package/package.json +1 -1
@@ -1,12 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAgentMetadata = exports.blAgent = void 0;
3
+ exports.getAgentMetadata = exports.blAgent = exports.BlAgent = void 0;
4
4
  const index_js_1 = require("../cache/index.js");
5
5
  const index_js_2 = require("../client/index.js");
6
6
  const internal_js_1 = require("../common/internal.js");
7
7
  const logger_js_1 = require("../common/logger.js");
8
8
  const settings_js_1 = require("../common/settings.js");
9
- const telemetry_js_1 = require("../telemetry/telemetry.js");
10
9
  class BlAgent {
11
10
  agentName;
12
11
  constructor(agentName) {
@@ -57,44 +56,28 @@ class BlAgent {
57
56
  }
58
57
  async run(input, headers = {}, params = {}) {
59
58
  logger_js_1.logger.debug(`Agent Calling: ${this.agentName}`);
60
- const span = (0, telemetry_js_1.startSpan)(this.agentName, {
61
- attributes: {
62
- "agent.name": this.agentName,
63
- "agent.args": JSON.stringify(input),
64
- "span.type": "agent.run",
65
- },
66
- isRoot: false,
67
- });
68
59
  try {
69
60
  const response = await this.call(this.url, input, headers, params);
70
- span.setAttribute("agent.run.result", await response.text());
71
61
  return await response.text();
72
62
  }
73
63
  catch (err) {
74
64
  if (err instanceof Error) {
75
65
  if (!this.fallbackUrl) {
76
- span.setAttribute("agent.run.error", err.stack);
77
66
  throw err;
78
67
  }
79
68
  try {
80
69
  const response = await this.call(this.fallbackUrl, input, headers, params);
81
- span.setAttribute("agent.run.result", await response.text());
82
70
  return await response.text();
83
71
  }
84
72
  catch (err) {
85
- if (err instanceof Error) {
86
- span.setAttribute("agent.run.error", err.stack);
87
- }
88
73
  throw err;
89
74
  }
90
75
  }
91
76
  throw err;
92
77
  }
93
- finally {
94
- span.end();
95
- }
96
78
  }
97
79
  }
80
+ exports.BlAgent = BlAgent;
98
81
  const blAgent = (agentName) => {
99
82
  return new BlAgent(agentName);
100
83
  };
@@ -1,7 +1,41 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  Object.defineProperty(exports, "__esModule", { value: true });
3
36
  exports.initialize = initialize;
4
37
  exports.authenticate = authenticate;
38
+ exports.closeConnections = closeConnections;
5
39
  const client_gen_js_1 = require("../client/client.gen.js");
6
40
  const interceptors_js_1 = require("../client/interceptors.js");
7
41
  const responseInterceptor_js_1 = require("../client/responseInterceptor.js");
@@ -25,6 +59,28 @@ for (const interceptor of responseInterceptor_js_1.responseInterceptors) {
25
59
  }
26
60
  // Initialize Sentry for SDK error tracking immediately when module loads
27
61
  (0, sentry_js_1.initSentry)();
62
+ // Background H2 connection warming (Node.js only)
63
+ const isNode = typeof process !== "undefined" && process.versions != null && process.versions.node != null;
64
+ /* eslint-disable */
65
+ const isBrowser = typeof globalThis !== "undefined" && globalThis?.window !== undefined;
66
+ if (isNode && !isBrowser) {
67
+ try {
68
+ // Pre-warm edge H2 for the configured region so the first
69
+ // SandboxInstance.create() gets an instant session via the pool.
70
+ // The control-plane client (api.blaxel.ai) stays on regular fetch
71
+ // which already benefits from undici's built-in connection pooling.
72
+ const region = settings_js_1.settings.region;
73
+ if (region) {
74
+ Promise.resolve().then(() => __importStar(require("./h2pool.js"))).then(({ h2Pool }) => {
75
+ const edgeSuffix = settings_js_1.settings.env === "prod" ? "bl.run" : "runv2.blaxel.dev";
76
+ h2Pool.warm(`any.${region}.${edgeSuffix}`);
77
+ }).catch(() => { });
78
+ }
79
+ }
80
+ catch {
81
+ // Silently ignore warming failures
82
+ }
83
+ }
28
84
  // Allow to set custom configuration for browser environment
29
85
  function initialize(config) {
30
86
  settings_js_1.settings.setConfig(config);
@@ -38,3 +94,11 @@ function initialize(config) {
38
94
  function authenticate() {
39
95
  return settings_js_1.settings.authenticate();
40
96
  }
97
+ /**
98
+ * Close all pooled H2 connections. Call this for explicit cleanup
99
+ * (e.g. in test teardown or before process exit).
100
+ */
101
+ async function closeConnections() {
102
+ const { h2Pool } = await Promise.resolve().then(() => __importStar(require("./h2pool.js")));
103
+ h2Pool.closeAll();
104
+ }
@@ -0,0 +1,207 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createH2Fetch = createH2Fetch;
4
+ exports.createPoolBackedH2Fetch = createPoolBackedH2Fetch;
5
+ exports.h2RequestDirect = h2RequestDirect;
6
+ const H2_REQUEST_TIMEOUT_MS = 10_000;
7
+ /**
8
+ * Creates a fetch()-compatible function that sends requests over an existing
9
+ * HTTP/2 session. Falls back to global fetch() if the session is closed,
10
+ * destroyed, or if the H2 request times out.
11
+ */
12
+ function createH2Fetch(session) {
13
+ return (input) => {
14
+ if (session.closed || session.destroyed) {
15
+ return globalThis.fetch(input);
16
+ }
17
+ return _h2Request(session, input);
18
+ };
19
+ }
20
+ /**
21
+ * Creates a fetch()-compatible function backed by the H2 session pool.
22
+ *
23
+ * Non-blocking: checks the pool cache synchronously. If a warm session is
24
+ * available it's used immediately; otherwise the request goes through
25
+ * regular fetch with zero delay (the pool keeps warming in the background
26
+ * so subsequent calls get H2).
27
+ */
28
+ function createPoolBackedH2Fetch(pool, domain) {
29
+ return (input) => {
30
+ const session = pool.tryGet(domain);
31
+ if (session) {
32
+ return _h2Request(session, input);
33
+ }
34
+ return globalThis.fetch(input);
35
+ };
36
+ }
37
+ /**
38
+ * Low-level H2 request that takes raw URL + init, skipping Request construction.
39
+ * Used by SandboxAction.h2Fetch() for direct calls from subsystems.
40
+ */
41
+ function h2RequestDirect(session, url, init) {
42
+ if (session.closed || session.destroyed) {
43
+ return globalThis.fetch(url, init);
44
+ }
45
+ const parsed = new URL(url);
46
+ const method = init?.method || "GET";
47
+ const h2Headers = {
48
+ ":method": method,
49
+ ":path": parsed.pathname + parsed.search,
50
+ ":authority": parsed.host,
51
+ };
52
+ if (init?.headers) {
53
+ const entries = init.headers instanceof Headers
54
+ ? init.headers.entries()
55
+ : Array.isArray(init.headers)
56
+ ? init.headers.values()
57
+ : Object.entries(init.headers).values();
58
+ for (const [key, value] of entries) {
59
+ const k = key.toLowerCase();
60
+ if (k === "host")
61
+ continue;
62
+ h2Headers[k] = value;
63
+ }
64
+ }
65
+ let body;
66
+ if (init?.body) {
67
+ if (typeof init.body === "string") {
68
+ body = Buffer.from(init.body);
69
+ }
70
+ else if (Buffer.isBuffer(init.body)) {
71
+ body = init.body;
72
+ }
73
+ else if (init.body instanceof ArrayBuffer) {
74
+ body = Buffer.from(init.body);
75
+ }
76
+ else if (init.body instanceof Uint8Array) {
77
+ body = Buffer.from(init.body.buffer, init.body.byteOffset, init.body.byteLength);
78
+ }
79
+ else {
80
+ // FormData, ReadableStream, Blob, etc. can't be serialized to Buffer
81
+ // for manual H2 framing — fall back to regular fetch.
82
+ return globalThis.fetch(url, init);
83
+ }
84
+ if (!h2Headers["content-length"]) {
85
+ h2Headers["content-length"] = body.byteLength;
86
+ }
87
+ }
88
+ return _h2Send(session, h2Headers, body, init?.signal ?? null, url, init);
89
+ }
90
+ async function _h2Request(session, input) {
91
+ const url = new URL(input.url);
92
+ const method = input.method || "GET";
93
+ const h2Headers = {
94
+ ":method": method,
95
+ ":path": url.pathname + url.search,
96
+ ":authority": url.host,
97
+ };
98
+ for (const [key, value] of input.headers.entries()) {
99
+ if (key === "host")
100
+ continue;
101
+ h2Headers[key] = value;
102
+ }
103
+ let body;
104
+ if (input.body) {
105
+ body = Buffer.from(await input.arrayBuffer());
106
+ if (!h2Headers["content-length"]) {
107
+ h2Headers["content-length"] = body.byteLength;
108
+ }
109
+ }
110
+ return _h2Send(session, h2Headers, body, input.signal, input.url, {
111
+ method,
112
+ headers: input.headers,
113
+ body,
114
+ });
115
+ }
116
+ function _h2Send(session, h2Headers, body, signal, fallbackUrl, fallbackInit) {
117
+ return new Promise((resolve, reject) => {
118
+ let req;
119
+ try {
120
+ req = session.request(h2Headers);
121
+ }
122
+ catch {
123
+ return globalThis.fetch(fallbackUrl, fallbackInit).then(resolve, reject);
124
+ }
125
+ const timer = setTimeout(() => {
126
+ if (settled)
127
+ return;
128
+ settled = true;
129
+ req.close();
130
+ globalThis.fetch(fallbackUrl, fallbackInit).then(resolve, reject);
131
+ }, H2_REQUEST_TIMEOUT_MS);
132
+ if (signal) {
133
+ if (signal.aborted) {
134
+ clearTimeout(timer);
135
+ req.close();
136
+ reject(new DOMException("The operation was aborted.", "AbortError"));
137
+ return;
138
+ }
139
+ signal.addEventListener("abort", () => {
140
+ clearTimeout(timer);
141
+ req.close();
142
+ if (!settled) {
143
+ settled = true;
144
+ reject(new DOMException("The operation was aborted.", "AbortError"));
145
+ }
146
+ }, { once: true });
147
+ }
148
+ let settled = false;
149
+ req.on("response", (headers) => {
150
+ clearTimeout(timer);
151
+ if (settled)
152
+ return;
153
+ settled = true;
154
+ const status = headers[":status"] ?? 200;
155
+ const resHeaders = new Headers();
156
+ for (const [k, v] of Object.entries(headers)) {
157
+ if (k.startsWith(":"))
158
+ continue;
159
+ if (v === undefined)
160
+ continue;
161
+ resHeaders.set(k, Array.isArray(v) ? v.join(", ") : String(v));
162
+ }
163
+ let streamClosed = false;
164
+ const readable = new ReadableStream({
165
+ start(controller) {
166
+ req.on("data", (chunk) => {
167
+ if (!streamClosed)
168
+ controller.enqueue(new Uint8Array(chunk));
169
+ });
170
+ req.on("end", () => {
171
+ if (!streamClosed) {
172
+ streamClosed = true;
173
+ controller.close();
174
+ }
175
+ });
176
+ req.on("error", (err) => {
177
+ if (!streamClosed) {
178
+ streamClosed = true;
179
+ controller.error(err);
180
+ }
181
+ });
182
+ signal?.addEventListener("abort", () => {
183
+ req.close();
184
+ if (!streamClosed) {
185
+ streamClosed = true;
186
+ controller.error(new DOMException("The operation was aborted.", "AbortError"));
187
+ }
188
+ }, { once: true });
189
+ },
190
+ });
191
+ resolve(new Response(readable, { status, headers: resHeaders }));
192
+ });
193
+ req.on("error", () => {
194
+ clearTimeout(timer);
195
+ if (settled)
196
+ return;
197
+ settled = true;
198
+ globalThis.fetch(fallbackUrl, fallbackInit).then(resolve, reject);
199
+ });
200
+ if (body) {
201
+ req.end(body);
202
+ }
203
+ else {
204
+ req.end();
205
+ }
206
+ });
207
+ }
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.h2Pool = void 0;
37
+ /**
38
+ * Singleton H2 session pool keyed by edge domain.
39
+ *
40
+ * - `warm(domain)` starts a background connection (fire-and-forget).
41
+ * - `get(domain)` returns a live session immediately if cached, or awaits
42
+ * an in-flight warming, or establishes a fresh one.
43
+ * - Closed / destroyed sessions are automatically evicted.
44
+ */
45
+ class H2Pool {
46
+ sessions = new Map();
47
+ inflight = new Map();
48
+ _establish = null;
49
+ /**
50
+ * Lazily resolve the establish function so the http2 / tls / dns modules
51
+ * are only imported in Node.js environments.
52
+ */
53
+ async establish(domain) {
54
+ if (!this._establish) {
55
+ const { establishH2 } = await Promise.resolve().then(() => __importStar(require("./h2warm.js")));
56
+ this._establish = establishH2;
57
+ }
58
+ return this._establish(domain);
59
+ }
60
+ /**
61
+ * Fire-and-forget background warming. Safe to call multiple times for
62
+ * the same domain — only one connection attempt per domain at a time.
63
+ */
64
+ warm(domain) {
65
+ const existing = this.sessions.get(domain);
66
+ if (existing && !existing.closed && !existing.destroyed)
67
+ return;
68
+ if (this.inflight.has(domain))
69
+ return;
70
+ const p = this.establish(domain)
71
+ .then((session) => {
72
+ this.sessions.set(domain, session);
73
+ return session;
74
+ })
75
+ .catch(() => null)
76
+ .finally(() => {
77
+ this.inflight.delete(domain);
78
+ });
79
+ this.inflight.set(domain, p);
80
+ }
81
+ /**
82
+ * Synchronous cache check. Returns a live cached session or `null`.
83
+ * Never blocks, never establishes — use for non-blocking fast paths.
84
+ */
85
+ tryGet(domain) {
86
+ const cached = this.sessions.get(domain);
87
+ if (cached && !cached.closed && !cached.destroyed)
88
+ return cached;
89
+ this.sessions.delete(domain);
90
+ return null;
91
+ }
92
+ /**
93
+ * Get a live H2 session for `domain`. Returns immediately from cache,
94
+ * joins an in-flight warming, or starts a new one.
95
+ */
96
+ async get(domain) {
97
+ const fast = this.tryGet(domain);
98
+ if (fast)
99
+ return fast;
100
+ // Join in-flight warming if one exists
101
+ const pending = this.inflight.get(domain);
102
+ if (pending) {
103
+ const session = await pending;
104
+ if (session && !session.closed && !session.destroyed)
105
+ return session;
106
+ }
107
+ // Start fresh, deduplicating concurrent callers via inflight
108
+ // Re-check: another caller may have started a fresh one while we awaited
109
+ const existingInflight = this.inflight.get(domain);
110
+ if (existingInflight)
111
+ return existingInflight;
112
+ const freshCached = this.tryGet(domain);
113
+ if (freshCached)
114
+ return freshCached;
115
+ const p = this.establish(domain)
116
+ .then((session) => {
117
+ this.sessions.set(domain, session);
118
+ return session;
119
+ })
120
+ .catch(() => null)
121
+ .finally(() => {
122
+ this.inflight.delete(domain);
123
+ });
124
+ this.inflight.set(domain, p);
125
+ return p;
126
+ }
127
+ /** Close all sessions (for cleanup). */
128
+ closeAll() {
129
+ for (const [, session] of this.sessions) {
130
+ if (!session.closed && !session.destroyed)
131
+ session.close();
132
+ }
133
+ this.sessions.clear();
134
+ this.inflight.clear();
135
+ }
136
+ }
137
+ exports.h2Pool = new H2Pool();
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.establishH2 = establishH2;
7
+ const promises_1 = __importDefault(require("dns/promises"));
8
+ const http2_1 = __importDefault(require("http2"));
9
+ const tls_1 = __importDefault(require("tls"));
10
+ async function establishH2(sniHostname) {
11
+ let timedOut = false;
12
+ let timer;
13
+ const timeout = new Promise((_, reject) => {
14
+ timer = setTimeout(() => {
15
+ timedOut = true;
16
+ reject(new Error("H2 warm-up timed out"));
17
+ }, 5000);
18
+ });
19
+ const attempt = _establishH2(sniHostname).then((session) => {
20
+ // If the timeout already fired, destroy the orphaned session immediately
21
+ if (timedOut) {
22
+ session.destroy();
23
+ }
24
+ return session;
25
+ });
26
+ return Promise.race([attempt, timeout]).finally(() => clearTimeout(timer));
27
+ }
28
+ async function _establishH2(sniHostname) {
29
+ const { address } = await promises_1.default.lookup(sniHostname);
30
+ const tlsSocket = tls_1.default.connect({
31
+ host: address,
32
+ port: 443,
33
+ servername: sniHostname,
34
+ ALPNProtocols: ["h2"],
35
+ });
36
+ const session = http2_1.default.connect(`https://${sniHostname}:443`, {
37
+ createConnection: () => tlsSocket,
38
+ });
39
+ await new Promise((resolve, reject) => {
40
+ session.on("connect", resolve);
41
+ session.on("error", (err) => {
42
+ // Ensure the TLS socket is cleaned up on connection error
43
+ if (!tlsSocket.destroyed)
44
+ tlsSocket.destroy();
45
+ reject(err);
46
+ });
47
+ });
48
+ // Complete the SETTINGS exchange so the first real request has zero
49
+ // protocol overhead. This RTT is hidden by the parallel createSandbox() call.
50
+ await new Promise((resolve) => session.ping(() => resolve()));
51
+ // Unref so the session doesn't prevent process exit
52
+ session.unref();
53
+ return session;
54
+ }
@@ -9,8 +9,8 @@ const index_js_1 = require("../authentication/index.js");
9
9
  const env_js_1 = require("../common/env.js");
10
10
  const node_js_1 = require("../common/node.js");
11
11
  // Build info - these placeholders are replaced at build time by build:replace-imports
12
- const BUILD_VERSION = "0.2.70";
13
- const BUILD_COMMIT = "a3bbb13aa4ec149d33f1662d30dfb10ce3683baf";
12
+ const BUILD_VERSION = "0.2.71-dev.105";
13
+ const BUILD_COMMIT = "cd4e249990c84664410df2d7158d13d6342300ed";
14
14
  const BUILD_SENTRY_DSN = "https://fd5e60e1c9820e1eef5ccebb84a07127@o4508714045276160.ingest.us.sentry.io/4510465864564736";
15
15
  // Cache for config.yaml tracking value
16
16
  let configTrackingValue = null;
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.blJob = void 0;
3
+ exports.blJob = exports.BlJob = void 0;
4
4
  const index_js_1 = require("../client/index.js");
5
5
  const logger_js_1 = require("../common/logger.js");
6
6
  const settings_js_1 = require("../common/settings.js");
7
- const telemetry_js_1 = require("../telemetry/telemetry.js");
8
7
  class BlJob {
9
8
  jobName;
10
9
  constructor(jobName) {
@@ -12,32 +11,14 @@ class BlJob {
12
11
  }
13
12
  async run(tasks, options) {
14
13
  logger_js_1.logger.debug(`Job Calling: ${this.jobName}`);
15
- const span = (0, telemetry_js_1.startSpan)(this.jobName, {
16
- attributes: {
17
- "job.name": this.jobName,
18
- "span.type": "job.run",
19
- },
20
- isRoot: false,
21
- });
22
- try {
23
- const request = {
24
- tasks,
25
- ...(options?.env && { env: options.env }),
26
- ...(options?.memory && { memory: options.memory }),
27
- ...(options?.executionId && { executionId: options.executionId }),
28
- };
29
- const executionId = await this.createExecution(request);
30
- return executionId;
31
- }
32
- catch (err) {
33
- if (err instanceof Error) {
34
- span.setAttribute("job.run.error", err.stack);
35
- }
36
- throw err;
37
- }
38
- finally {
39
- span.end();
40
- }
14
+ const request = {
15
+ tasks,
16
+ ...(options?.env && { env: options.env }),
17
+ ...(options?.memory && { memory: options.memory }),
18
+ ...(options?.executionId && { executionId: options.executionId }),
19
+ };
20
+ const executionId = await this.createExecution(request);
21
+ return executionId;
41
22
  }
42
23
  /**
43
24
  * Create a new execution for this job and return the execution ID
@@ -139,6 +120,7 @@ class BlJob {
139
120
  throw new Error(`Execution ${executionId} did not complete within ${maxWait}ms`);
140
121
  }
141
122
  }
123
+ exports.BlJob = BlJob;
142
124
  const blJob = (jobName) => {
143
125
  return new BlJob(jobName);
144
126
  };