@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.
- package/dist/{chunk-R5FKQQMG.js → chunk-5JHQH7WH.js} +1 -1
- package/dist/{chunk-Y3NTKJLA.js → chunk-MQECNHD2.js} +16 -4
- package/dist/index.js +1112 -234
- package/dist/{trace-PMUETYJS.js → trace-IOARVWJ6.js} +1 -1
- package/dist/{trace-library-FIMBRED6.js → trace-library-K3NE26GH.js} +2 -2
- package/package.json +1 -1
|
@@ -3,9 +3,12 @@ import {
|
|
|
3
3
|
apiBase,
|
|
4
4
|
apiToken,
|
|
5
5
|
currentUniverse
|
|
6
|
-
} from "./chunk-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
176
|
+
downloadFileTo,
|
|
165
177
|
apiBytes,
|
|
166
178
|
resolveSessionRef,
|
|
167
179
|
streamEvents
|