@agentsky/sky 2.15.0 → 2.16.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.
@@ -38,7 +38,7 @@ function currentUniverse() {
38
38
  }
39
39
 
40
40
  // src/version.ts
41
- var CLI_VERSION = "2.15.0";
41
+ var CLI_VERSION = "2.16.0";
42
42
  var USER_AGENT = `sky-cli/${CLI_VERSION} (${process.platform}; node/${process.versions.node})`;
43
43
 
44
44
  export {
@@ -3,9 +3,12 @@ import {
3
3
  apiBase,
4
4
  apiToken,
5
5
  currentUniverse
6
- } from "./chunk-R5FKQQMG.js";
6
+ } from "./chunk-5JHQH7WH.js";
7
7
 
8
8
  // src/api.ts
9
+ import { createWriteStream, writeFileSync } from "fs";
10
+ import { Readable } from "stream";
11
+ import { pipeline } from "stream/promises";
9
12
  var ApiError = class extends Error {
10
13
  constructor(status, code, message) {
11
14
  super(message);
@@ -88,12 +91,21 @@ async function apiForm(method, path, form) {
88
91
  if (!res.ok) await parseError(res);
89
92
  return await res.json();
90
93
  }
91
- async function downloadFile(fileId) {
94
+ async function downloadFileTo(fileId, outPath) {
92
95
  const res = await fetch(`${apiBase()}/files/${encodeURIComponent(fileId)}/content`, {
93
96
  headers: { "user-agent": USER_AGENT, ...authHeaders() }
94
97
  });
95
98
  if (!res.ok) await parseError(res);
96
- return { bytes: new Uint8Array(await res.arrayBuffer()), mediaType: res.headers.get("content-type") ?? "application/octet-stream" };
99
+ if (!res.body) {
100
+ writeFileSync(outPath, new Uint8Array(0));
101
+ return 0;
102
+ }
103
+ let written = 0;
104
+ const counted = Readable.fromWeb(res.body).on("data", (chunk) => {
105
+ written += chunk.length;
106
+ });
107
+ await pipeline(counted, createWriteStream(outPath));
108
+ return written;
97
109
  }
98
110
  async function apiBytes(method, path, body) {
99
111
  const res = await fetch(`${apiBase()}${path}`, {
@@ -161,7 +173,7 @@ export {
161
173
  postEvents,
162
174
  uploadFile,
163
175
  apiForm,
164
- downloadFile,
176
+ downloadFileTo,
165
177
  apiBytes,
166
178
  resolveSessionRef,
167
179
  streamEvents