@plosson/agentio 0.7.4 → 0.7.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plosson/agentio",
3
- "version": "0.7.4",
3
+ "version": "0.7.5",
4
4
  "description": "CLI for LLM agents to interact with communication and tracking services",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -93,6 +93,27 @@ function compareVersions(current: string, latest: string): number {
93
93
  return 0;
94
94
  }
95
95
 
96
+ function renderProgress(received: number, total: number, done = false): void {
97
+ const mb = (b: number) => (b / 1024 / 1024).toFixed(1);
98
+ const width = 30;
99
+ let line: string;
100
+ if (total > 0) {
101
+ const pct = Math.min(100, Math.floor((received / total) * 100));
102
+ const filled = Math.floor((pct / 100) * width);
103
+ const bar = '█'.repeat(filled) + '░'.repeat(width - filled);
104
+ line = ` [${bar}] ${pct}% (${mb(received)}/${mb(total)} MB)`;
105
+ } else {
106
+ line = ` Downloaded ${mb(received)} MB`;
107
+ }
108
+ process.stderr.write(`\r\x1b[K${line}`);
109
+ if (done) process.stderr.write('\n');
110
+ }
111
+
112
+ async function writeChunk(stream: fs.WriteStream, chunk: Uint8Array): Promise<void> {
113
+ if (stream.write(chunk)) return;
114
+ await new Promise<void>((resolve) => stream.once('drain', resolve));
115
+ }
116
+
96
117
  async function downloadBinary(url: string, dest: string): Promise<void> {
97
118
  const response = await fetch(url, {
98
119
  headers: {
@@ -100,12 +121,37 @@ async function downloadBinary(url: string, dest: string): Promise<void> {
100
121
  },
101
122
  });
102
123
 
103
- if (!response.ok) {
124
+ if (!response.ok || !response.body) {
104
125
  throw new CliError('API_ERROR', `Download failed: ${response.statusText}`);
105
126
  }
106
127
 
107
- const buffer = await response.arrayBuffer();
108
- fs.writeFileSync(dest, Buffer.from(buffer));
128
+ const total = Number(response.headers.get('content-length') || 0);
129
+ let received = 0;
130
+ let lastRender = 0;
131
+ const showProgress = process.stderr.isTTY;
132
+
133
+ const file = fs.createWriteStream(dest);
134
+ try {
135
+ const reader = response.body.getReader();
136
+ while (true) {
137
+ const { done, value } = await reader.read();
138
+ if (done) break;
139
+ await writeChunk(file, value);
140
+ received += value.length;
141
+ if (showProgress) {
142
+ const now = Date.now();
143
+ if (now - lastRender > 100) {
144
+ renderProgress(received, total);
145
+ lastRender = now;
146
+ }
147
+ }
148
+ }
149
+ if (showProgress) renderProgress(received, total, true);
150
+ } finally {
151
+ await new Promise<void>((resolve, reject) => {
152
+ file.end((err?: Error | null) => (err ? reject(err) : resolve()));
153
+ });
154
+ }
109
155
  }
110
156
 
111
157
  function moveFile(src: string, dest: string): void {