@staff0rd/assist 0.289.0 → 0.291.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/commands/sessions/web/bundle.js +59 -59
- package/dist/index.js +64 -18
- 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.291.0",
|
|
10
10
|
type: "module",
|
|
11
11
|
main: "dist/index.js",
|
|
12
12
|
bin: {
|
|
@@ -18300,6 +18300,20 @@ function broadcastSessions(sessions, clients, windowsSessions = []) {
|
|
|
18300
18300
|
});
|
|
18301
18301
|
}
|
|
18302
18302
|
|
|
18303
|
+
// src/commands/sessions/daemon/ClientHub.ts
|
|
18304
|
+
var ClientHub = class extends Set {
|
|
18305
|
+
latestLimits;
|
|
18306
|
+
updateLimits(rateLimits) {
|
|
18307
|
+
this.latestLimits = rateLimits;
|
|
18308
|
+
broadcast(this, { type: "limits", rateLimits });
|
|
18309
|
+
}
|
|
18310
|
+
greet(client) {
|
|
18311
|
+
if (this.latestLimits) {
|
|
18312
|
+
sendTo(client, { type: "limits", rateLimits: this.latestLimits });
|
|
18313
|
+
}
|
|
18314
|
+
}
|
|
18315
|
+
};
|
|
18316
|
+
|
|
18303
18317
|
// src/commands/sessions/daemon/spawnPty.ts
|
|
18304
18318
|
import * as pty from "node-pty";
|
|
18305
18319
|
|
|
@@ -19397,7 +19411,7 @@ var SessionManager = class {
|
|
|
19397
19411
|
this.onIdleChange = onIdleChange;
|
|
19398
19412
|
}
|
|
19399
19413
|
sessions = /* @__PURE__ */ new Map();
|
|
19400
|
-
clients =
|
|
19414
|
+
clients = new ClientHub();
|
|
19401
19415
|
nextId = 1;
|
|
19402
19416
|
shuttingDown = false;
|
|
19403
19417
|
// why: dispatch calls windowsProxy.route() to forward windows-origin sessions
|
|
@@ -19641,6 +19655,7 @@ var handlers = {
|
|
|
19641
19655
|
history: handleHistory,
|
|
19642
19656
|
"fetch-transcript": handleFetchTranscript,
|
|
19643
19657
|
shutdown: handleShutdown,
|
|
19658
|
+
limits: (_client, m, d) => m.clients.updateLimits(d.rateLimits),
|
|
19644
19659
|
input: routed(
|
|
19645
19660
|
(_client, m, d) => m.writeToSession(d.sessionId, d.data)
|
|
19646
19661
|
),
|
|
@@ -19669,6 +19684,7 @@ function handleConnection(socket, manager) {
|
|
|
19669
19684
|
}
|
|
19670
19685
|
};
|
|
19671
19686
|
manager.addClient(client);
|
|
19687
|
+
manager.clients.greet(client);
|
|
19672
19688
|
const lines = createInterface7({ input: socket });
|
|
19673
19689
|
lines.on("error", () => {
|
|
19674
19690
|
});
|
|
@@ -20014,10 +20030,12 @@ import chalk165 from "chalk";
|
|
|
20014
20030
|
|
|
20015
20031
|
// src/commands/buildLimitsSegment.ts
|
|
20016
20032
|
import chalk164 from "chalk";
|
|
20033
|
+
|
|
20034
|
+
// src/shared/rateLimitLevel.ts
|
|
20017
20035
|
var FIVE_HOUR_SECONDS = 5 * 3600;
|
|
20018
20036
|
var SEVEN_DAY_SECONDS = 7 * 86400;
|
|
20019
|
-
function
|
|
20020
|
-
const seconds = Math.max(0, resetsAt -
|
|
20037
|
+
function formatRateLimitTimeLeft(resetsAt, now) {
|
|
20038
|
+
const seconds = Math.max(0, resetsAt - now);
|
|
20021
20039
|
const days = Math.floor(seconds / 86400);
|
|
20022
20040
|
const hours = Math.floor(seconds % 86400 / 3600);
|
|
20023
20041
|
const minutes = Math.floor(seconds % 3600 / 60);
|
|
@@ -20025,45 +20043,72 @@ function formatTimeLeft(resetsAt) {
|
|
|
20025
20043
|
if (hours > 0) return `${hours}h ${minutes}m`;
|
|
20026
20044
|
return `${minutes}m`;
|
|
20027
20045
|
}
|
|
20028
|
-
function projectUsage(pct, resetsAt, windowSeconds) {
|
|
20046
|
+
function projectUsage(pct, resetsAt, windowSeconds, now) {
|
|
20029
20047
|
if (resetsAt == null) return void 0;
|
|
20030
|
-
const now = Math.floor(Date.now() / 1e3);
|
|
20031
20048
|
const timeRemaining = Math.max(0, resetsAt - now);
|
|
20032
20049
|
const elapsed = Math.max(0, windowSeconds - timeRemaining) / windowSeconds;
|
|
20033
20050
|
if (elapsed < 0.05) return void 0;
|
|
20034
20051
|
return pct / elapsed;
|
|
20035
20052
|
}
|
|
20036
|
-
function
|
|
20037
|
-
const
|
|
20038
|
-
|
|
20039
|
-
if (projected
|
|
20040
|
-
if (projected >
|
|
20041
|
-
|
|
20042
|
-
return chalk164.green(label2);
|
|
20053
|
+
function rateLimitLevel(pct, resetsAt, windowSeconds, now) {
|
|
20054
|
+
const projected = projectUsage(pct, resetsAt, windowSeconds, now);
|
|
20055
|
+
if (projected == null) return "ok";
|
|
20056
|
+
if (projected > 100) return "over";
|
|
20057
|
+
if (projected > 75) return "warn";
|
|
20058
|
+
return "ok";
|
|
20043
20059
|
}
|
|
20044
|
-
|
|
20045
|
-
|
|
20046
|
-
|
|
20060
|
+
|
|
20061
|
+
// src/commands/buildLimitsSegment.ts
|
|
20062
|
+
var LEVEL_COLOR = {
|
|
20063
|
+
ok: chalk164.green,
|
|
20064
|
+
warn: chalk164.yellow,
|
|
20065
|
+
over: chalk164.red
|
|
20066
|
+
};
|
|
20067
|
+
function formatLimit(pct, resetsAt, windowSeconds, fallbackLabel, now) {
|
|
20068
|
+
const level = rateLimitLevel(pct, resetsAt, windowSeconds, now);
|
|
20069
|
+
const label2 = LEVEL_COLOR[level](`${Math.round(pct)}%`);
|
|
20070
|
+
const timeLabel = resetsAt ? formatRateLimitTimeLeft(resetsAt, now) : fallbackLabel;
|
|
20071
|
+
return `${label2} (${timeLabel})`;
|
|
20047
20072
|
}
|
|
20048
20073
|
function buildLimitsSegment(rateLimits) {
|
|
20049
20074
|
const fiveHrPct = rateLimits?.five_hour?.used_percentage;
|
|
20050
20075
|
const sevenDayPct = rateLimits?.seven_day?.used_percentage;
|
|
20051
20076
|
if (fiveHrPct == null || sevenDayPct == null) return "";
|
|
20077
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
20052
20078
|
const fiveHr = formatLimit(
|
|
20053
20079
|
fiveHrPct,
|
|
20054
20080
|
rateLimits?.five_hour?.resets_at,
|
|
20055
20081
|
FIVE_HOUR_SECONDS,
|
|
20056
|
-
"5h"
|
|
20082
|
+
"5h",
|
|
20083
|
+
now
|
|
20057
20084
|
);
|
|
20058
20085
|
const sevenDay = formatLimit(
|
|
20059
20086
|
sevenDayPct,
|
|
20060
20087
|
rateLimits?.seven_day?.resets_at,
|
|
20061
20088
|
SEVEN_DAY_SECONDS,
|
|
20062
|
-
"7d"
|
|
20089
|
+
"7d",
|
|
20090
|
+
now
|
|
20063
20091
|
);
|
|
20064
20092
|
return ` | Limits - ${fiveHr}, ${sevenDay}`;
|
|
20065
20093
|
}
|
|
20066
20094
|
|
|
20095
|
+
// src/commands/relayRateLimits.ts
|
|
20096
|
+
async function relayRateLimits(rateLimits) {
|
|
20097
|
+
if (!rateLimits) return;
|
|
20098
|
+
try {
|
|
20099
|
+
const socket = await connectToDaemon();
|
|
20100
|
+
const timer = setTimeout(() => socket.destroy(), 500);
|
|
20101
|
+
socket.on("error", () => {
|
|
20102
|
+
});
|
|
20103
|
+
socket.write(`${JSON.stringify({ type: "limits", rateLimits })}
|
|
20104
|
+
`, () => {
|
|
20105
|
+
clearTimeout(timer);
|
|
20106
|
+
socket.end();
|
|
20107
|
+
});
|
|
20108
|
+
} catch {
|
|
20109
|
+
}
|
|
20110
|
+
}
|
|
20111
|
+
|
|
20067
20112
|
// src/commands/statusLine.ts
|
|
20068
20113
|
chalk165.level = 3;
|
|
20069
20114
|
function formatNumber(num) {
|
|
@@ -20084,6 +20129,7 @@ async function statusLine() {
|
|
|
20084
20129
|
console.log(
|
|
20085
20130
|
`${model} | Tokens - ${formatNumber(totalOut)} \u2191 : ${formatNumber(totalIn)} \u2193 | Context - ${colorizePercent(usedPct)}${buildLimitsSegment(data.rate_limits)}`
|
|
20086
20131
|
);
|
|
20132
|
+
await relayRateLimits(data.rate_limits);
|
|
20087
20133
|
}
|
|
20088
20134
|
|
|
20089
20135
|
// src/commands/sync.ts
|