modelstat 0.0.13 → 0.0.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.
package/dist/cli.mjs CHANGED
@@ -4484,7 +4484,22 @@ var init_schemas = __esm({
4484
4484
  });
4485
4485
 
4486
4486
  // ../../packages/core/src/ids.ts
4487
- import { ulid } from "ulid";
4487
+ function ulid(seedTime) {
4488
+ const t = seedTime ?? Date.now();
4489
+ let timeStr = "";
4490
+ let ts = t;
4491
+ for (let i = 9; i >= 0; i--) {
4492
+ timeStr = ULID_ALPHABET[ts % 32] + timeStr;
4493
+ ts = Math.floor(ts / 32);
4494
+ }
4495
+ const bytes = new Uint8Array(16);
4496
+ globalThis.crypto.getRandomValues(bytes);
4497
+ let randStr = "";
4498
+ for (let i = 0; i < 16; i++) {
4499
+ randStr += ULID_ALPHABET[bytes[i] % 32];
4500
+ }
4501
+ return timeStr + randStr;
4502
+ }
4488
4503
  function sourceEventId(deviceId, sourceOrFilePath, byteOffsetMaybe) {
4489
4504
  let key;
4490
4505
  if (typeof sourceOrFilePath === "string") {
@@ -4513,10 +4528,11 @@ function segmentId(sessionId, startedAtMs, endedAtMs, sourceEventIds) {
4513
4528
  }
4514
4529
  return `seg_${h.toString(36)}`;
4515
4530
  }
4516
- var batchId;
4531
+ var ULID_ALPHABET, batchId;
4517
4532
  var init_ids = __esm({
4518
4533
  "../../packages/core/src/ids.ts"() {
4519
4534
  "use strict";
4535
+ ULID_ALPHABET = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
4520
4536
  batchId = () => ulid();
4521
4537
  }
4522
4538
  });
@@ -7748,7 +7764,7 @@ async function reportDiscovery(report) {
7748
7764
  }
7749
7765
  }
7750
7766
  async function fetchDeviceViewByClaim(claimCode) {
7751
- const res = await request(`${state.apiUrl}/v1/d/${encodeURIComponent(claimCode)}`, {
7767
+ const res = await request(`${state.apiUrl}/v1/device/${encodeURIComponent(claimCode)}`, {
7752
7768
  method: "GET"
7753
7769
  });
7754
7770
  if (res.statusCode === 404) return null;
@@ -7759,7 +7775,7 @@ async function fetchDeviceViewByClaim(claimCode) {
7759
7775
  }
7760
7776
  async function fetchDeviceViewJobsByClaim(claimCode) {
7761
7777
  const res = await request(
7762
- `${state.apiUrl}/v1/d/${encodeURIComponent(claimCode)}/jobs`,
7778
+ `${state.apiUrl}/v1/device/${encodeURIComponent(claimCode)}/jobs`,
7763
7779
  { method: "GET" }
7764
7780
  );
7765
7781
  if (res.statusCode === 404) return null;
@@ -7770,7 +7786,7 @@ async function fetchDeviceViewJobsByClaim(claimCode) {
7770
7786
  }
7771
7787
  async function fetchDeviceViewLedgerByClaim(claimCode) {
7772
7788
  const res = await request(
7773
- `${state.apiUrl}/v1/d/${encodeURIComponent(claimCode)}/ledger`,
7789
+ `${state.apiUrl}/v1/device/${encodeURIComponent(claimCode)}/ledger`,
7774
7790
  { method: "GET" }
7775
7791
  );
7776
7792
  if (res.statusCode === 404) return null;
@@ -8992,8 +9008,9 @@ async function cmdConnect(opts) {
8992
9008
  `);
8993
9009
  };
8994
9010
  const hasLegacyBearer = !!state.bearer && !state.bearer.startsWith("ds_live_");
8995
- const hasLegacyClaim = !!state.claimUrl && state.claimUrl.includes("/c/");
8996
- if (hasLegacyBearer || hasLegacyClaim) {
9011
+ const hasLegacyClaim = !!state.claimUrl && (state.claimUrl.includes("/c/") || /\/d\/[a-z]/.test(state.claimUrl) || !state.claimUrl.includes("/device/"));
9012
+ const hasLegacyCode = !!state.claimCode && !/^[0-9a-hjkmnp-tv-z]{32}$/.test(state.claimCode);
9013
+ if (hasLegacyBearer || hasLegacyClaim || hasLegacyCode) {
8997
9014
  step("Legacy state detected from an older version \u2014 wiping");
8998
9015
  state.setBearer(null);
8999
9016
  state.setDeviceId(null);
@@ -9010,8 +9027,8 @@ async function cmdConnect(opts) {
9010
9027
  ok(`device ${state.deviceId}`);
9011
9028
  }
9012
9029
  const claimCode = state.claimCode ?? "(unknown)";
9013
- const claimUrl = state.claimUrl ?? `https://modelstat.ai/d/${claimCode}`;
9014
- const agentUrl = `https://modelstat.ai/da/${claimCode}`;
9030
+ const claimUrl = state.claimUrl ?? `https://modelstat.ai/device/${claimCode}`;
9031
+ const agentUrl = `https://modelstat.ai/device-agent/${claimCode}`;
9015
9032
  emitEvent(opts, "registered", {
9016
9033
  device_uuid: state.deviceUuid,
9017
9034
  device_id: state.deviceId,