@staff0rd/assist 0.116.0 → 0.118.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.js +31 -7
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import { Command } from "commander";
|
|
|
6
6
|
// package.json
|
|
7
7
|
var package_default = {
|
|
8
8
|
name: "@staff0rd/assist",
|
|
9
|
-
version: "0.
|
|
9
|
+
version: "0.118.0",
|
|
10
10
|
type: "module",
|
|
11
11
|
main: "dist/index.js",
|
|
12
12
|
bin: {
|
|
@@ -8266,23 +8266,47 @@ import chalk78 from "chalk";
|
|
|
8266
8266
|
function formatNumber(num) {
|
|
8267
8267
|
return num.toLocaleString("en-US");
|
|
8268
8268
|
}
|
|
8269
|
+
function formatTimeLeft(resetsAt) {
|
|
8270
|
+
const seconds = Math.max(0, resetsAt - Math.floor(Date.now() / 1e3));
|
|
8271
|
+
const days = Math.floor(seconds / 86400);
|
|
8272
|
+
const hours = Math.floor(seconds % 86400 / 3600);
|
|
8273
|
+
const minutes = Math.floor(seconds % 3600 / 60);
|
|
8274
|
+
if (days > 0) return `${days}d ${hours}h`;
|
|
8275
|
+
if (hours > 0) return `${hours}h ${minutes}m`;
|
|
8276
|
+
return `${minutes}m`;
|
|
8277
|
+
}
|
|
8269
8278
|
function colorizePercent(pct) {
|
|
8270
|
-
const label2 = `${pct}%`;
|
|
8279
|
+
const label2 = `${Math.round(pct)}%`;
|
|
8271
8280
|
if (pct > 80) return chalk78.red(label2);
|
|
8272
8281
|
if (pct > 40) return chalk78.yellow(label2);
|
|
8273
8282
|
return label2;
|
|
8274
8283
|
}
|
|
8284
|
+
function formatLimit(limit, fallbackLabel) {
|
|
8285
|
+
const label2 = limit.resets_at ? formatTimeLeft(limit.resets_at) : fallbackLabel;
|
|
8286
|
+
return `${colorizePercent(limit.used_percentage)} (${label2})`;
|
|
8287
|
+
}
|
|
8288
|
+
function buildLimitsSegment(rateLimits) {
|
|
8289
|
+
const fiveHrPct = rateLimits?.five_hour?.used_percentage;
|
|
8290
|
+
const sevenDayPct = rateLimits?.seven_day?.used_percentage;
|
|
8291
|
+
if (fiveHrPct == null || sevenDayPct == null) return "";
|
|
8292
|
+
const fiveHr = {
|
|
8293
|
+
used_percentage: fiveHrPct,
|
|
8294
|
+
resets_at: rateLimits?.five_hour?.resets_at
|
|
8295
|
+
};
|
|
8296
|
+
const sevenDay = {
|
|
8297
|
+
used_percentage: sevenDayPct,
|
|
8298
|
+
resets_at: rateLimits?.seven_day?.resets_at
|
|
8299
|
+
};
|
|
8300
|
+
return ` | Limits - ${formatLimit(fiveHr, "5h")}, ${formatLimit(sevenDay, "7d")}`;
|
|
8301
|
+
}
|
|
8275
8302
|
async function statusLine() {
|
|
8276
8303
|
const inputData = await readStdin();
|
|
8277
8304
|
const data = JSON.parse(inputData);
|
|
8278
8305
|
const model = data.model.display_name;
|
|
8279
|
-
const
|
|
8280
|
-
const totalOutput = data.context_window.total_output_tokens;
|
|
8306
|
+
const { total_input_tokens: totalIn, total_output_tokens: totalOut } = data.context_window;
|
|
8281
8307
|
const usedPct = data.context_window.used_percentage ?? 0;
|
|
8282
|
-
const formattedInput = formatNumber(totalInput);
|
|
8283
|
-
const formattedOutput = formatNumber(totalOutput);
|
|
8284
8308
|
console.log(
|
|
8285
|
-
`${model} | Tokens - ${
|
|
8309
|
+
`${model} | Tokens - ${formatNumber(totalOut)} \u2191 : ${formatNumber(totalIn)} \u2193 | Context - ${colorizePercent(usedPct)}${buildLimitsSegment(data.rate_limits)}`
|
|
8286
8310
|
);
|
|
8287
8311
|
}
|
|
8288
8312
|
|