modelstat 0.0.16 → 0.0.17
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 +25 -2
- package/dist/cli.mjs.map +1 -1
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -7735,6 +7735,10 @@ async function fetchDeviceMe(secret) {
|
|
|
7735
7735
|
method: "GET",
|
|
7736
7736
|
headers: { authorization: `Bearer ${secret}` }
|
|
7737
7737
|
});
|
|
7738
|
+
if (res.statusCode === 401) {
|
|
7739
|
+
await res.body.dump();
|
|
7740
|
+
throw new DeviceMeUnauthorized();
|
|
7741
|
+
}
|
|
7738
7742
|
if (res.statusCode >= 300) {
|
|
7739
7743
|
throw new Error(`devices/me failed: ${res.statusCode} ${await res.body.text()}`);
|
|
7740
7744
|
}
|
|
@@ -7829,13 +7833,19 @@ async function uploadBatch(batch) {
|
|
|
7829
7833
|
batch_id: result.response.batch_id
|
|
7830
7834
|
};
|
|
7831
7835
|
}
|
|
7832
|
-
var _ingest;
|
|
7836
|
+
var DeviceMeUnauthorized, _ingest;
|
|
7833
7837
|
var init_api = __esm({
|
|
7834
7838
|
"src/api.ts"() {
|
|
7835
7839
|
"use strict";
|
|
7836
7840
|
init_http();
|
|
7837
7841
|
init_logger();
|
|
7838
7842
|
init_config2();
|
|
7843
|
+
DeviceMeUnauthorized = class extends Error {
|
|
7844
|
+
constructor() {
|
|
7845
|
+
super("devices/me returned 401: device_secret not recognised");
|
|
7846
|
+
this.name = "DeviceMeUnauthorized";
|
|
7847
|
+
}
|
|
7848
|
+
};
|
|
7839
7849
|
_ingest = null;
|
|
7840
7850
|
}
|
|
7841
7851
|
});
|
|
@@ -9007,6 +9017,15 @@ async function cmdConnect(opts) {
|
|
|
9007
9017
|
process.stdout.write(` \x1B[33m\u26A0\x1B[0m ${msg}
|
|
9008
9018
|
`);
|
|
9009
9019
|
};
|
|
9020
|
+
const wipeAndSelfRegister = async (reason) => {
|
|
9021
|
+
warn(`${reason} \u2014 re-registering this device`);
|
|
9022
|
+
state.setBearer(null);
|
|
9023
|
+
state.setDeviceId(null);
|
|
9024
|
+
state.setDeviceUuid(null);
|
|
9025
|
+
state.setClaimCode(null);
|
|
9026
|
+
state.setClaimUrl(null);
|
|
9027
|
+
await cmdSelfRegister();
|
|
9028
|
+
};
|
|
9010
9029
|
if (!state.deviceUuid || !state.bearer || !state.deviceId) {
|
|
9011
9030
|
step("Registering this device with modelstat.ai");
|
|
9012
9031
|
await cmdSelfRegister();
|
|
@@ -9023,7 +9042,11 @@ async function cmdConnect(opts) {
|
|
|
9023
9042
|
state.setClaimUrl(me.claim_url);
|
|
9024
9043
|
}
|
|
9025
9044
|
} catch (e) {
|
|
9026
|
-
|
|
9045
|
+
if (e instanceof DeviceMeUnauthorized) {
|
|
9046
|
+
await wipeAndSelfRegister("cached credentials no longer valid");
|
|
9047
|
+
} else {
|
|
9048
|
+
warn(`couldn't refresh device state: ${e.message}`);
|
|
9049
|
+
}
|
|
9027
9050
|
}
|
|
9028
9051
|
}
|
|
9029
9052
|
const claimCode = state.claimCode ?? "(unknown)";
|