opencode-statboard 2.10.13 → 2.10.14

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 (2) hide show
  1. package/package.json +1 -1
  2. package/tui-dashboard.js +23 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-statboard",
3
- "version": "2.10.13",
3
+ "version": "2.10.14",
4
4
  "description": "Real-time dashboard for opencode token usage and cost statistics",
5
5
  "main": "server.js",
6
6
  "bin": {
package/tui-dashboard.js CHANGED
@@ -6,6 +6,7 @@
6
6
 
7
7
  const blessed = require('blessed');
8
8
  const http = require('http');
9
+ const zlib = require('zlib');
9
10
  const { spawn } = require('child_process');
10
11
  const path = require('path');
11
12
  const pkg = require('./package.json');
@@ -148,7 +149,16 @@ class TUIServer {
148
149
 
149
150
  async start() {
150
151
  this.startServer();
151
- await this.sleep(1500);
152
+ await this.sleep(3000);
153
+ // Health check: wait for server to be ready
154
+ for (let i = 0; i < 10; i++) {
155
+ try {
156
+ await this.fetchData('/api/stats?days=7');
157
+ break;
158
+ } catch {
159
+ await this.sleep(500);
160
+ }
161
+ }
152
162
  this.initTUI();
153
163
  this.startPolling();
154
164
  process.on('SIGINT', () => this.shutdown());
@@ -179,10 +189,15 @@ class TUIServer {
179
189
 
180
190
  async fetchData(endpoint) {
181
191
  return new Promise((resolve, reject) => {
182
- http.get('http://' + this.host + ':' + this.port + endpoint, (res) => {
192
+ const req = http.get('http://' + this.host + ':' + this.port + endpoint, (res) => {
193
+ const encoding = res.headers['content-encoding'];
194
+ let stream = res;
195
+ if (encoding && encoding.includes('gzip')) {
196
+ stream = res.pipe(zlib.createGunzip());
197
+ }
183
198
  let data = '';
184
- res.on('data', chunk => data += chunk);
185
- res.on('end', () => {
199
+ stream.on('data', chunk => data += chunk);
200
+ stream.on('end', () => {
186
201
  try {
187
202
  const raw = res.headers['content-type']?.includes('utf-16')
188
203
  ? Buffer.from(data, 'utf16le').toString('utf8')
@@ -192,7 +207,10 @@ class TUIServer {
192
207
  reject(e);
193
208
  }
194
209
  });
195
- }).on('error', reject);
210
+ stream.on('error', reject);
211
+ });
212
+ req.on('error', reject);
213
+ req.setTimeout(10000, () => req.destroy(new Error('Request timeout')));
196
214
  });
197
215
  }
198
216