@blaxel/core 0.2.79-preview.130 → 0.2.79-preview.131

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.
@@ -11,8 +11,8 @@ const index_js_1 = require("../authentication/index.js");
11
11
  const env_js_1 = require("../common/env.js");
12
12
  const node_js_1 = require("../common/node.js");
13
13
  // Build info - these placeholders are replaced at build time by build:replace-imports
14
- const BUILD_VERSION = "0.2.79-preview.130";
15
- const BUILD_COMMIT = "7f4924b21bd257cad5bdf35bd3a2db8d99876495";
14
+ const BUILD_VERSION = "0.2.79-preview.131";
15
+ const BUILD_COMMIT = "25ceae0c8e47c11fd966d9c692661180900bfd99";
16
16
  const BUILD_SENTRY_DSN = "https://fd5e60e1c9820e1eef5ccebb84a07127@o4508714045276160.ingest.us.sentry.io/4510465864564736";
17
17
  // Cache for config.yaml tracking value
18
18
  let configTrackingValue = null;
@@ -18,7 +18,24 @@ class SandboxProcess extends action_js_1.SandboxAction {
18
18
  console.error("Stream error:", err);
19
19
  }
20
20
  };
21
+ const processLine = (line) => {
22
+ if (line.startsWith("[keepalive]")) {
23
+ return;
24
+ }
25
+ if (line.startsWith('stdout:')) {
26
+ options.onStdout?.(line.slice(7));
27
+ options.onLog?.(line.slice(7));
28
+ }
29
+ else if (line.startsWith('stderr:')) {
30
+ options.onStderr?.(line.slice(7));
31
+ options.onLog?.(line.slice(7));
32
+ }
33
+ else {
34
+ options.onLog?.(line);
35
+ }
36
+ };
21
37
  const done = (async () => {
38
+ let buffer = '';
22
39
  try {
23
40
  const headers = this.sandbox.forceUrl ? this.sandbox.headers : settings_js_1.settings.headers;
24
41
  const stream = await this.h2Fetch(`${this.url}/process/${identifier}/logs/stream`, {
@@ -36,7 +53,6 @@ class SandboxProcess extends action_js_1.SandboxAction {
36
53
  }
37
54
  const reader = stream.body.getReader();
38
55
  const decoder = new TextDecoder();
39
- let buffer = '';
40
56
  while (true) {
41
57
  const result = await reader.read();
42
58
  if (result.done)
@@ -47,25 +63,21 @@ class SandboxProcess extends action_js_1.SandboxAction {
47
63
  const lines = buffer.split(/\r?\n/);
48
64
  buffer = lines.pop();
49
65
  for (const line of lines) {
50
- if (line.startsWith("[keepalive]")) {
51
- continue;
52
- }
53
- if (line.startsWith('stdout:')) {
54
- options.onStdout?.(line.slice(7));
55
- options.onLog?.(line.slice(7));
56
- }
57
- else if (line.startsWith('stderr:')) {
58
- options.onStderr?.(line.slice(7));
59
- options.onLog?.(line.slice(7));
60
- }
61
- else {
62
- options.onLog?.(line);
63
- }
66
+ processLine(line);
64
67
  }
65
68
  }
69
+ // Flush the TextDecoder and process any remaining buffered data
70
+ buffer += decoder.decode();
71
+ if (buffer.trim()) {
72
+ processLine(buffer);
73
+ }
66
74
  }
67
75
  catch (err) {
68
76
  if (err && typeof err === 'object' && 'name' in err && err.name === 'AbortError') {
77
+ // Process remaining buffer before returning on abort
78
+ if (buffer.trim()) {
79
+ processLine(buffer);
80
+ }
69
81
  return;
70
82
  }
71
83
  handleError(err instanceof Error ? err : new Error('Unknown stream error'));
@@ -215,15 +227,51 @@ class SandboxProcess extends action_js_1.SandboxAction {
215
227
  }
216
228
  }
217
229
  }
218
- // Process any remaining buffer
230
+ // Flush the TextDecoder and process any remaining buffered data
231
+ buffer += decoder.decode();
219
232
  if (buffer.trim()) {
220
- if (buffer.startsWith('result:')) {
221
- const jsonStr = buffer.slice(7);
222
- try {
223
- result = JSON.parse(jsonStr);
233
+ let parsed = null;
234
+ try {
235
+ parsed = JSON.parse(buffer.trim());
236
+ }
237
+ catch (e) {
238
+ // Not valid JSON — try legacy result: prefix format
239
+ if (buffer.startsWith('result:')) {
240
+ const jsonStr = buffer.slice(7);
241
+ try {
242
+ result = JSON.parse(jsonStr);
243
+ }
244
+ catch {
245
+ throw new Error(`Failed to parse result JSON: ${jsonStr}`);
246
+ }
247
+ }
248
+ else {
249
+ // Not a legacy result line — surface the original parse error
250
+ throw e;
224
251
  }
225
- catch {
226
- throw new Error(`Failed to parse result JSON: ${jsonStr}`);
252
+ }
253
+ if (parsed) {
254
+ switch (parsed.type) {
255
+ case 'stdout':
256
+ if (parsed.data) {
257
+ options.onStdout?.(parsed.data);
258
+ options.onLog?.(parsed.data);
259
+ }
260
+ break;
261
+ case 'stderr':
262
+ if (parsed.data) {
263
+ options.onStderr?.(parsed.data);
264
+ options.onLog?.(parsed.data);
265
+ }
266
+ break;
267
+ case 'result':
268
+ try {
269
+ result = JSON.parse(parsed.data);
270
+ }
271
+ catch {
272
+ throw new Error(`Failed to parse result JSON: ${parsed.data}`);
273
+ }
274
+ break;
227
275
  }
228
276
  }
229
277
  }