@blaxel/core 0.2.56-preview.28 → 0.2.57-dev.31

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 (39) hide show
  1. package/dist/cjs/.tsbuildinfo +1 -1
  2. package/dist/cjs/client/sdk.gen.js +2 -36
  3. package/dist/cjs/common/settings.js +2 -2
  4. package/dist/cjs/common/version.js +6 -0
  5. package/dist/cjs/sandbox/client/sdk.gen.js +1 -1
  6. package/dist/cjs/sandbox/process/process.js +135 -28
  7. package/dist/cjs/types/client/sdk.gen.d.ts +1 -11
  8. package/dist/cjs/types/client/types.gen.d.ts +0 -48
  9. package/dist/cjs/types/common/version.d.ts +2 -0
  10. package/dist/cjs/types/sandbox/client/sdk.gen.d.ts +1 -1
  11. package/dist/cjs/types/sandbox/client/types.gen.d.ts +2 -0
  12. package/dist/cjs/types/sandbox/process/process.d.ts +1 -0
  13. package/dist/cjs/types/sandbox/types.d.ts +2 -0
  14. package/dist/cjs-browser/.tsbuildinfo +1 -1
  15. package/dist/cjs-browser/client/sdk.gen.js +2 -36
  16. package/dist/cjs-browser/common/settings.js +2 -2
  17. package/dist/cjs-browser/common/version.js +6 -0
  18. package/dist/cjs-browser/sandbox/client/sdk.gen.js +1 -1
  19. package/dist/cjs-browser/sandbox/process/process.js +135 -28
  20. package/dist/cjs-browser/types/client/sdk.gen.d.ts +1 -11
  21. package/dist/cjs-browser/types/client/types.gen.d.ts +0 -48
  22. package/dist/cjs-browser/types/common/version.d.ts +2 -0
  23. package/dist/cjs-browser/types/sandbox/client/sdk.gen.d.ts +1 -1
  24. package/dist/cjs-browser/types/sandbox/client/types.gen.d.ts +2 -0
  25. package/dist/cjs-browser/types/sandbox/process/process.d.ts +1 -0
  26. package/dist/cjs-browser/types/sandbox/types.d.ts +2 -0
  27. package/dist/esm/.tsbuildinfo +1 -1
  28. package/dist/esm/client/sdk.gen.js +0 -32
  29. package/dist/esm/common/settings.js +2 -2
  30. package/dist/esm/common/version.js +3 -0
  31. package/dist/esm/sandbox/client/sdk.gen.js +1 -1
  32. package/dist/esm/sandbox/process/process.js +135 -28
  33. package/dist/esm-browser/.tsbuildinfo +1 -1
  34. package/dist/esm-browser/client/sdk.gen.js +0 -32
  35. package/dist/esm-browser/common/settings.js +2 -2
  36. package/dist/esm-browser/common/version.js +3 -0
  37. package/dist/esm-browser/sandbox/client/sdk.gen.js +1 -1
  38. package/dist/esm-browser/sandbox/process/process.js +135 -28
  39. package/package.json +2 -1
@@ -1206,38 +1206,6 @@ export const deleteSandboxPreviewToken = (options) => {
1206
1206
  ...options
1207
1207
  });
1208
1208
  };
1209
- /**
1210
- * Start Sandbox
1211
- * Starts a Sandbox by name.
1212
- */
1213
- export const startSandbox = (options) => {
1214
- return (options.client ?? _heyApiClient).put({
1215
- security: [
1216
- {
1217
- scheme: 'bearer',
1218
- type: 'http'
1219
- }
1220
- ],
1221
- url: '/sandboxes/{sandboxName}/start',
1222
- ...options
1223
- });
1224
- };
1225
- /**
1226
- * Stop Sandbox
1227
- * Stops a Sandbox by name.
1228
- */
1229
- export const stopSandbox = (options) => {
1230
- return (options.client ?? _heyApiClient).put({
1231
- security: [
1232
- {
1233
- scheme: 'bearer',
1234
- type: 'http'
1235
- }
1236
- ],
1237
- url: '/sandboxes/{sandboxName}/stop',
1238
- ...options
1239
- });
1240
- };
1241
1209
  /**
1242
1210
  * Get workspace service accounts
1243
1211
  * Returns a list of all service accounts in the workspace.
@@ -3,8 +3,8 @@ import { authentication } from "../authentication/index.js";
3
3
  import { env } from "../common/env.js";
4
4
  import { fs, os, path } from "../common/node.js";
5
5
  // Build info - these placeholders are replaced at build time by build:replace-imports
6
- const BUILD_VERSION = "0.2.56-preview.28";
7
- const BUILD_COMMIT = "d332a51ef561175a3dbf3d07dd2a79c5185679a4";
6
+ const BUILD_VERSION = "0.2.57-dev.31";
7
+ const BUILD_COMMIT = "68a090397bc0a76709b4179c59ee74c61a6edbd4";
8
8
  const BUILD_SENTRY_DSN = "https://fd5e60e1c9820e1eef5ccebb84a07127@o4508714045276160.ingest.us.sentry.io/4510465864564736";
9
9
  // Cache for config.yaml tracking value
10
10
  let configTrackingValue = null;
@@ -0,0 +1,3 @@
1
+ // This file is auto-generated during build. Do not edit manually.
2
+ export const PACKAGE_VERSION = "0.2.50";
3
+ export const PACKAGE_COMMIT = "4a74989dcb65a6ff8d826aed7976436c64554f6a";
@@ -495,7 +495,7 @@ export const getProcess = (options) => {
495
495
  };
496
496
  /**
497
497
  * Execute a command
498
- * Execute a command and return process information
498
+ * Execute a command and return process information. If Accept header is text/event-stream, streams logs in SSE format and returns the process response as a final event.
499
499
  */
500
500
  export const postProcess = (options) => {
501
501
  return (options.client ?? _heyApiClient).post({
@@ -74,41 +74,36 @@ export class SandboxProcess extends SandboxAction {
74
74
  }
75
75
  async exec(process) {
76
76
  let onLog;
77
+ let onStdout;
78
+ let onStderr;
77
79
  if ('onLog' in process && process.onLog) {
78
80
  onLog = process.onLog;
79
81
  delete process.onLog;
80
82
  }
83
+ if ('onStdout' in process && process.onStdout) {
84
+ onStdout = process.onStdout;
85
+ delete process.onStdout;
86
+ }
87
+ if ('onStderr' in process && process.onStderr) {
88
+ onStderr = process.onStderr;
89
+ delete process.onStderr;
90
+ }
81
91
  // Store original wait_for_completion setting
82
92
  const shouldWaitForCompletion = process.waitForCompletion;
83
- // Always start process without wait_for_completion to avoid server-side blocking
84
- if (shouldWaitForCompletion && onLog) {
85
- process.waitForCompletion = false;
86
- }
87
- const { response, data, error } = await postProcess({
88
- body: process,
89
- baseUrl: this.url,
90
- client: this.client,
91
- });
92
- this.handleResponseError(response, data, error);
93
- let result = data;
94
- // Handle wait_for_completion with parallel log streaming
95
- if (shouldWaitForCompletion && onLog) {
96
- const streamControl = this.streamLogs(result.pid, { onLog });
97
- try {
98
- // Wait for process completion
99
- result = await this.wait(result.pid, { interval: 500, maxWait: 1000 * 60 * 60 });
100
- }
101
- finally {
102
- // Clean up log streaming
103
- if (streamControl) {
104
- streamControl.close();
105
- }
106
- }
93
+ // When waiting for completion with streaming callbacks, use streaming endpoint
94
+ if (shouldWaitForCompletion && (onLog || onStdout || onStderr)) {
95
+ return await this.execWithStreaming(process, { onLog, onStdout, onStderr });
107
96
  }
108
97
  else {
109
- // For non-blocking execution, set up log streaming immediately if requested
110
- if (onLog) {
111
- const streamControl = this.streamLogs(result.pid, { onLog });
98
+ const { response, data, error } = await postProcess({
99
+ body: process,
100
+ baseUrl: this.url,
101
+ client: this.client,
102
+ });
103
+ this.handleResponseError(response, data, error);
104
+ const result = data;
105
+ if (onLog || onStdout || onStderr) {
106
+ const streamControl = this.streamLogs(result.pid, { onLog, onStdout, onStderr });
112
107
  return {
113
108
  ...result,
114
109
  close() {
@@ -118,8 +113,120 @@ export class SandboxProcess extends SandboxAction {
118
113
  },
119
114
  };
120
115
  }
116
+ return result;
117
+ }
118
+ }
119
+ async execWithStreaming(processRequest, options) {
120
+ const headers = this.sandbox.forceUrl ? this.sandbox.headers : settings.headers;
121
+ const controller = new AbortController();
122
+ const response = await fetch(`${this.url}/process`, {
123
+ method: 'POST',
124
+ signal: controller.signal,
125
+ headers: {
126
+ ...headers,
127
+ 'Content-Type': 'application/json',
128
+ 'Accept': 'text/event-stream',
129
+ },
130
+ body: JSON.stringify(processRequest),
131
+ });
132
+ if (!response.ok) {
133
+ const errorText = await response.text();
134
+ throw new Error(`Failed to execute process: ${errorText}`);
135
+ }
136
+ const contentType = response.headers.get('Content-Type') || '';
137
+ const isStreaming = contentType.includes('text/plain') || contentType.includes('text/event-stream');
138
+ // Fallback: server doesn't support streaming, use legacy approach
139
+ if (!isStreaming) {
140
+ const data = await response.json();
141
+ // If process already completed (server waited), just return with logs
142
+ if (data.status === 'completed' || data.status === 'failed') {
143
+ // Emit any captured logs through callbacks
144
+ if (data.stdout) {
145
+ for (const line of data.stdout.split('\n').filter(l => l)) {
146
+ options.onStdout?.(line);
147
+ }
148
+ }
149
+ if (data.stderr) {
150
+ for (const line of data.stderr.split('\n').filter(l => l)) {
151
+ options.onStderr?.(line);
152
+ }
153
+ }
154
+ if (data.logs) {
155
+ for (const line of data.logs.split('\n').filter(l => l)) {
156
+ options.onLog?.(line);
157
+ }
158
+ }
159
+ return {
160
+ ...data,
161
+ close: () => { },
162
+ };
163
+ }
164
+ return {
165
+ ...data,
166
+ close: () => { },
167
+ };
168
+ }
169
+ // Streaming response handling
170
+ if (!response.body) {
171
+ throw new Error('No response body for streaming');
172
+ }
173
+ const reader = response.body.getReader();
174
+ const decoder = new TextDecoder();
175
+ let buffer = '';
176
+ let result = null;
177
+ while (true) {
178
+ const readResult = await reader.read();
179
+ if (readResult.done)
180
+ break;
181
+ if (readResult.value && readResult.value instanceof Uint8Array) {
182
+ buffer += decoder.decode(readResult.value, { stream: true });
183
+ }
184
+ const lines = buffer.split(/\r?\n/);
185
+ buffer = lines.pop();
186
+ for (const line of lines) {
187
+ if (!line || line.startsWith('[keepalive]')) {
188
+ continue;
189
+ }
190
+ if (line.startsWith('stdout:')) {
191
+ const content = line.slice(7);
192
+ options.onStdout?.(content);
193
+ options.onLog?.(content);
194
+ }
195
+ else if (line.startsWith('stderr:')) {
196
+ const content = line.slice(7);
197
+ options.onStderr?.(content);
198
+ options.onLog?.(content);
199
+ }
200
+ else if (line.startsWith('result:')) {
201
+ const jsonStr = line.slice(7);
202
+ try {
203
+ result = JSON.parse(jsonStr);
204
+ }
205
+ catch {
206
+ throw new Error(`Failed to parse result JSON: ${jsonStr}`);
207
+ }
208
+ }
209
+ }
121
210
  }
122
- return { ...result, close: () => { } };
211
+ // Process any remaining buffer
212
+ if (buffer.trim()) {
213
+ if (buffer.startsWith('result:')) {
214
+ const jsonStr = buffer.slice(7);
215
+ try {
216
+ result = JSON.parse(jsonStr);
217
+ }
218
+ catch {
219
+ throw new Error(`Failed to parse result JSON: ${jsonStr}`);
220
+ }
221
+ }
222
+ }
223
+ if (!result) {
224
+ throw new Error('No result received from streaming response');
225
+ }
226
+ return {
227
+ ...result,
228
+ close: () => controller.abort(),
229
+ };
123
230
  }
124
231
  async wait(identifier, { maxWait = 60000, interval = 1000 } = {}) {
125
232
  const startTime = Date.now();