tokenmax-collector 0.3.0 → 0.3.2

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": "tokenmax-collector",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "Report local ccusage token usage to a tokenmax instance",
5
5
  "type": "module",
6
6
  "bin": {
package/src/collect.ts CHANGED
@@ -55,6 +55,9 @@ const messageOf = (error: unknown): string =>
55
55
  const reportUrl = (baseUrl: string): string =>
56
56
  `${baseUrl.replace(/\/+$/, "")}/api/report`;
57
57
 
58
+ const providerDay = (day: UsageDay): string =>
59
+ `${day.date}\u0000${day.provider}`;
60
+
58
61
  function acceptedCount(body: string): number | null {
59
62
  let payload: unknown;
60
63
  try {
@@ -212,7 +215,12 @@ export async function collect(options: CollectOptions): Promise<CollectResult> {
212
215
  };
213
216
  const antigravity = await localDays(antigravitySource, window);
214
217
  const devin = await localDays(devinSource, window);
215
- days.push(...antigravity.days, ...devin.days);
218
+ const covered = new Set(days.map(providerDay));
219
+ days.push(
220
+ ...[...antigravity.days, ...devin.days].filter(
221
+ (day) => !covered.has(providerDay(day)),
222
+ ),
223
+ );
216
224
  const warnings = [...antigravity.warnings, ...devin.warnings];
217
225
  if (days.length === 0) {
218
226
  return { kind: "empty", warnings };
package/src/machine.ts CHANGED
@@ -11,12 +11,13 @@ const disallowed = /[^A-Za-z0-9._-]/g;
11
11
 
12
12
  const platformUuidPattern = /"IOPlatformUUID"\s*=\s*"([^"]+)"/;
13
13
 
14
+ /** The hostname changes with the network, and every spelling of it used to open
15
+ * a new machine on the server, so the platform identifier travels alone. */
14
16
  export function machineId(
15
17
  hostnameValue: string,
16
18
  platformUuid: string | null,
17
19
  ): string {
18
- const raw =
19
- platformUuid === null ? hostnameValue : `${hostnameValue}-${platformUuid}`;
20
+ const raw = platformUuid ?? hostnameValue;
20
21
  return raw.replace(disallowed, "-").slice(0, 64);
21
22
  }
22
23