@diogonzafe/tokenwatch 0.8.0 → 0.9.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/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { T as TrackerConfig, a as Tracker, L as LazyTracker, b as TrackingMeta } from './index-CFBI-1ab.cjs';
2
- export { A as AnomalyDetectionConfig, B as BudgetConfig, C as CostForecast, F as FeatureStats, c as ForecastOptions, I as IExporter, d as IStorage, M as ModelPrice, e as ModelStats, P as PriceMap, f as PricesFile, R as Report, g as ReportOptions, S as SessionStats, U as UsageEntry, h as UserStats } from './index-CFBI-1ab.cjs';
1
+ import { T as TrackerConfig, a as Tracker, L as LazyTracker, b as TrackingMeta } from './index-fD5QLTWg.cjs';
2
+ export { A as AnomalyDetectionConfig, B as BudgetConfig, C as CostForecast, F as FeatureStats, c as ForecastOptions, I as IExporter, d as IStorage, M as ModelPrice, e as ModelStats, P as PriceMap, f as PricesFile, R as Report, g as ReportOptions, S as SessionStats, U as UsageEntry, h as UserStats } from './index-fD5QLTWg.cjs';
3
3
 
4
4
  declare function createTracker(config?: TrackerConfig): Tracker;
5
5
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { T as TrackerConfig, a as Tracker, L as LazyTracker, b as TrackingMeta } from './index-CFBI-1ab.js';
2
- export { A as AnomalyDetectionConfig, B as BudgetConfig, C as CostForecast, F as FeatureStats, c as ForecastOptions, I as IExporter, d as IStorage, M as ModelPrice, e as ModelStats, P as PriceMap, f as PricesFile, R as Report, g as ReportOptions, S as SessionStats, U as UsageEntry, h as UserStats } from './index-CFBI-1ab.js';
1
+ import { T as TrackerConfig, a as Tracker, L as LazyTracker, b as TrackingMeta } from './index-fD5QLTWg.js';
2
+ export { A as AnomalyDetectionConfig, B as BudgetConfig, C as CostForecast, F as FeatureStats, c as ForecastOptions, I as IExporter, d as IStorage, M as ModelPrice, e as ModelStats, P as PriceMap, f as PricesFile, R as Report, g as ReportOptions, S as SessionStats, U as UsageEntry, h as UserStats } from './index-fD5QLTWg.js';
3
3
 
4
4
  declare function createTracker(config?: TrackerConfig): Tracker;
5
5
 
package/dist/index.js CHANGED
@@ -33,6 +33,40 @@ function calculateCost(inputTokens, outputTokens, price, cachedTokens = 0, cache
33
33
  return regularInputCost + cachedReadCost + cacheCreationCost + outputCost;
34
34
  }
35
35
 
36
+ // src/exporters/cloud.ts
37
+ var DEFAULT_ENDPOINT = "https://api.tokenwatch.dev/v1/ingest";
38
+ var CloudExporter = class {
39
+ constructor(apiKey, endpoint) {
40
+ this.apiKey = apiKey;
41
+ this.endpoint = endpoint ?? DEFAULT_ENDPOINT;
42
+ }
43
+ apiKey;
44
+ endpoint;
45
+ export(entry) {
46
+ fetch(this.endpoint, {
47
+ method: "POST",
48
+ headers: {
49
+ "Content-Type": "application/json",
50
+ Authorization: `Bearer ${this.apiKey}`
51
+ },
52
+ body: JSON.stringify({
53
+ model: entry.model,
54
+ inputTokens: entry.inputTokens,
55
+ outputTokens: entry.outputTokens,
56
+ reasoningTokens: entry.reasoningTokens ?? 0,
57
+ cachedTokens: entry.cachedTokens ?? 0,
58
+ cacheCreationTokens: entry.cacheCreationTokens ?? 0,
59
+ costUSD: entry.costUSD,
60
+ sessionId: entry.sessionId,
61
+ userId: entry.userId,
62
+ feature: entry.feature,
63
+ timestamp: entry.timestamp
64
+ })
65
+ }).catch(() => {
66
+ });
67
+ }
68
+ };
69
+
36
70
  // src/core/suggestions.ts
37
71
  var PROVIDER_PREFIXES = ["gpt-", "claude-", "gemini-", "deepseek-"];
38
72
  function getProviderPrefix(model) {
@@ -1693,7 +1727,9 @@ var TrackerConfigSchema = z.object({
1693
1727
  mode: z.enum(["once", "always"]).optional().default("once")
1694
1728
  }).optional(),
1695
1729
  exporter: z.custom((v) => v !== null && typeof v === "object" && typeof v.export === "function").optional(),
1696
- appId: z.string().optional()
1730
+ appId: z.string().optional(),
1731
+ cloudApiKey: z.string().optional(),
1732
+ cloudEndpoint: z.string().url().optional()
1697
1733
  });
1698
1734
  function createTracker(config = {}) {
1699
1735
  const parsed = TrackerConfigSchema.safeParse(config);
@@ -1713,9 +1749,12 @@ ${issues}`);
1713
1749
  suggestions,
1714
1750
  anomalyDetection,
1715
1751
  exporter,
1716
- appId
1752
+ appId,
1753
+ cloudApiKey,
1754
+ cloudEndpoint
1717
1755
  } = parsed.data;
1718
1756
  const storage = typeof storageOption === "object" ? storageOption : createStorage(storageOption);
1757
+ const cloudExporter = cloudApiKey ? new CloudExporter(cloudApiKey, cloudEndpoint) : null;
1719
1758
  let remotePrices;
1720
1759
  let pricesUpdatedAt = bundledUpdatedAt;
1721
1760
  if (syncPrices) {
@@ -1776,6 +1815,9 @@ ${issues}`);
1776
1815
  Promise.resolve(exporter.export(full)).catch(() => {
1777
1816
  });
1778
1817
  }
1818
+ if (cloudExporter) {
1819
+ cloudExporter.export(full);
1820
+ }
1779
1821
  maybeFireAlerts(full);
1780
1822
  if (anomalyDetection) maybeDetectAnomaly(full);
1781
1823
  if (suggestions) {