@axiom-lattice/client-sdk 4.1.0 → 4.2.0

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.
package/dist/index.mjs CHANGED
@@ -3618,25 +3618,59 @@ var _Client = class extends AbstractClient {
3618
3618
  const reader = res.body.getReader();
3619
3619
  const decoder = new TextDecoder();
3620
3620
  let buffer = "";
3621
+ let event = "";
3622
+ let dataLines = [];
3623
+ const processLine = (rawLine) => {
3624
+ const line = rawLine.endsWith("\r") ? rawLine.slice(0, -1) : rawLine;
3625
+ if (line === "") {
3626
+ if (dataLines.length === 0) {
3627
+ event = "";
3628
+ return null;
3629
+ }
3630
+ const data = dataLines.join("\n");
3631
+ const eventName = event;
3632
+ event = "";
3633
+ dataLines = [];
3634
+ try {
3635
+ return { event: eventName, data: JSON.parse(data) };
3636
+ } catch {
3637
+ return null;
3638
+ }
3639
+ }
3640
+ if (line.startsWith(":"))
3641
+ return null;
3642
+ const separator = line.indexOf(":");
3643
+ const field = separator === -1 ? line : line.slice(0, separator);
3644
+ let value = separator === -1 ? "" : line.slice(separator + 1);
3645
+ if (value.startsWith(" "))
3646
+ value = value.slice(1);
3647
+ if (field === "event")
3648
+ event = value;
3649
+ else if (field === "data")
3650
+ dataLines.push(value);
3651
+ return null;
3652
+ };
3621
3653
  while (true) {
3622
3654
  const { done, value } = await reader.read();
3623
- if (done)
3655
+ if (done) {
3656
+ buffer += decoder.decode();
3624
3657
  break;
3658
+ }
3625
3659
  buffer += decoder.decode(value, { stream: true });
3626
- const lines = buffer.split("\n");
3627
- buffer = lines.pop() || "";
3628
- let event = "";
3629
- for (const line of lines) {
3630
- if (line.startsWith("event: ")) {
3631
- event = line.slice(7);
3632
- } else if (line.startsWith("data: ")) {
3633
- try {
3634
- yield { event, data: JSON.parse(line.slice(6)) };
3635
- } catch {
3636
- }
3637
- }
3660
+ let newline = buffer.indexOf("\n");
3661
+ while (newline !== -1) {
3662
+ const parsed = processLine(buffer.slice(0, newline));
3663
+ buffer = buffer.slice(newline + 1);
3664
+ if (parsed)
3665
+ yield parsed;
3666
+ newline = buffer.indexOf("\n");
3638
3667
  }
3639
3668
  }
3669
+ if (buffer.length > 0)
3670
+ processLine(buffer);
3671
+ const finalEvent = processLine("");
3672
+ if (finalEvent)
3673
+ yield finalEvent;
3640
3674
  }
3641
3675
  /**
3642
3676
  * Get all headers including workspace context
@@ -4200,6 +4234,33 @@ var WorkspaceClient = class {
4200
4234
  }
4201
4235
  return `${this.baseURL}/api/workspaces/${workspaceId}/projects/${projectId}/downloadfile?${params}`;
4202
4236
  }
4237
+ /**
4238
+ * Download a project folder as an authenticated ZIP Blob.
4239
+ *
4240
+ * The request is scoped by this client's bearer token and tenant headers;
4241
+ * callers are responsible for triggering browser download behavior.
4242
+ *
4243
+ * @param workspaceId - Workspace identifier.
4244
+ * @param projectId - Project identifier.
4245
+ * @param folderPath - Backend folder path to archive.
4246
+ * @param assistantId - Optional sandbox assistant context.
4247
+ * @returns The ZIP response as a Blob.
4248
+ * @throws Error when the authenticated request fails.
4249
+ */
4250
+ async downloadFolder(workspaceId, projectId, folderPath, assistantId) {
4251
+ const params = new URLSearchParams({ path: folderPath, tenantId: this.tenantId });
4252
+ if (assistantId)
4253
+ params.set("assistantId", assistantId);
4254
+ const response = await fetch(
4255
+ `${this.baseURL}/api/workspaces/${workspaceId}/projects/${projectId}/downloadfolder?${params}`,
4256
+ { headers: this.headers }
4257
+ );
4258
+ if (!response.ok) {
4259
+ const error = await response.json().catch(() => ({}));
4260
+ throw new Error(error.error || error.message || `HTTP error! Status: ${response.status}`);
4261
+ }
4262
+ return response.blob();
4263
+ }
4203
4264
  /**
4204
4265
  * Get a URL for viewing a file inline in the browser (not download).
4205
4266
  * The file will be displayed in the browser rather than downloaded.