@vibe-cafe/vibe-usage 0.1.0 → 0.1.1

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/src/sync.js +19 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibe-cafe/vibe-usage",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Track your AI coding tool token usage and sync to vibecafe.ai",
5
5
  "type": "module",
6
6
  "bin": {
package/src/sync.js CHANGED
@@ -2,10 +2,12 @@ import { loadConfig, saveConfig } from './config.js';
2
2
  import { ingest } from './api.js';
3
3
  import { parsers } from './parsers/index.js';
4
4
 
5
+ const BATCH_SIZE = 500;
6
+
5
7
  export async function runSync() {
6
8
  const config = loadConfig();
7
9
  if (!config?.apiKey) {
8
- console.error('Not configured. Run `npx vibe-usage init` first.');
10
+ console.error('Not configured. Run `npx @vibe-cafe/vibe-usage init` first.');
9
11
  process.exit(1);
10
12
  }
11
13
 
@@ -28,19 +30,27 @@ export async function runSync() {
28
30
  return 0;
29
31
  }
30
32
 
33
+ const apiUrl = config.apiUrl || 'https://vibecafe.ai';
34
+ let totalIngested = 0;
35
+
31
36
  try {
32
- const result = await ingest(
33
- config.apiUrl || 'https://vibecafe.ai',
34
- config.apiKey,
35
- allBuckets
36
- );
37
+ for (let i = 0; i < allBuckets.length; i += BATCH_SIZE) {
38
+ const batch = allBuckets.slice(i, i + BATCH_SIZE);
39
+ const result = await ingest(apiUrl, config.apiKey, batch);
40
+ totalIngested += result.ingested ?? batch.length;
41
+
42
+ if (allBuckets.length > BATCH_SIZE) {
43
+ process.stdout.write(` ${Math.min(i + BATCH_SIZE, allBuckets.length)}/${allBuckets.length} buckets...\r`);
44
+ }
45
+ }
46
+
37
47
  config.lastSync = new Date().toISOString();
38
48
  saveConfig(config);
39
- console.log(`Synced ${result.ingested ?? allBuckets.length} buckets.`);
40
- return result.ingested ?? allBuckets.length;
49
+ console.log(`Synced ${totalIngested} buckets.`);
50
+ return totalIngested;
41
51
  } catch (err) {
42
52
  if (err.message === 'UNAUTHORIZED') {
43
- console.error('Invalid API key. Run `npx vibe-usage init` to reconfigure.');
53
+ console.error('Invalid API key. Run `npx @vibe-cafe/vibe-usage init` to reconfigure.');
44
54
  process.exit(1);
45
55
  }
46
56
  console.error(`Sync failed: ${err.message}`);