@staff0rd/assist 0.290.0 → 0.291.1
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 +71 -21
- 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.1",
|
|
10
10
|
type: "module",
|
|
11
11
|
main: "dist/index.js",
|
|
12
12
|
bin: {
|
|
@@ -15855,12 +15855,16 @@ function filterToSql(filter) {
|
|
|
15855
15855
|
}
|
|
15856
15856
|
|
|
15857
15857
|
// src/commands/seq/fetchSeqData.ts
|
|
15858
|
-
|
|
15858
|
+
function buildDataParams(filter, count6, from, to) {
|
|
15859
15859
|
const sqlFilter = filterToSql(filter);
|
|
15860
15860
|
const sql4 = `select @Timestamp, @Level, @Exception, @Message from stream where ${sqlFilter} order by @Timestamp desc limit ${count6}`;
|
|
15861
15861
|
const params = new URLSearchParams({ q: sql4 });
|
|
15862
|
-
if (from) params.set("
|
|
15863
|
-
if (to) params.set("
|
|
15862
|
+
if (from) params.set("rangeStartUtc", from);
|
|
15863
|
+
if (to) params.set("rangeEndUtc", to);
|
|
15864
|
+
return params;
|
|
15865
|
+
}
|
|
15866
|
+
async function fetchSeqData(conn, filter, count6, from, to) {
|
|
15867
|
+
const params = buildDataParams(filter, count6, from, to);
|
|
15864
15868
|
const response = await fetchSeq(conn, "/api/data", params);
|
|
15865
15869
|
const data = await response.json();
|
|
15866
15870
|
return mapDataToEvents(data);
|
|
@@ -18300,6 +18304,20 @@ function broadcastSessions(sessions, clients, windowsSessions = []) {
|
|
|
18300
18304
|
});
|
|
18301
18305
|
}
|
|
18302
18306
|
|
|
18307
|
+
// src/commands/sessions/daemon/ClientHub.ts
|
|
18308
|
+
var ClientHub = class extends Set {
|
|
18309
|
+
latestLimits;
|
|
18310
|
+
updateLimits(rateLimits) {
|
|
18311
|
+
this.latestLimits = rateLimits;
|
|
18312
|
+
broadcast(this, { type: "limits", rateLimits });
|
|
18313
|
+
}
|
|
18314
|
+
greet(client) {
|
|
18315
|
+
if (this.latestLimits) {
|
|
18316
|
+
sendTo(client, { type: "limits", rateLimits: this.latestLimits });
|
|
18317
|
+
}
|
|
18318
|
+
}
|
|
18319
|
+
};
|
|
18320
|
+
|
|
18303
18321
|
// src/commands/sessions/daemon/spawnPty.ts
|
|
18304
18322
|
import * as pty from "node-pty";
|
|
18305
18323
|
|
|
@@ -19397,7 +19415,7 @@ var SessionManager = class {
|
|
|
19397
19415
|
this.onIdleChange = onIdleChange;
|
|
19398
19416
|
}
|
|
19399
19417
|
sessions = /* @__PURE__ */ new Map();
|
|
19400
|
-
clients =
|
|
19418
|
+
clients = new ClientHub();
|
|
19401
19419
|
nextId = 1;
|
|
19402
19420
|
shuttingDown = false;
|
|
19403
19421
|
// why: dispatch calls windowsProxy.route() to forward windows-origin sessions
|
|
@@ -19641,6 +19659,7 @@ var handlers = {
|
|
|
19641
19659
|
history: handleHistory,
|
|
19642
19660
|
"fetch-transcript": handleFetchTranscript,
|
|
19643
19661
|
shutdown: handleShutdown,
|
|
19662
|
+
limits: (_client, m, d) => m.clients.updateLimits(d.rateLimits),
|
|
19644
19663
|
input: routed(
|
|
19645
19664
|
(_client, m, d) => m.writeToSession(d.sessionId, d.data)
|
|
19646
19665
|
),
|
|
@@ -19669,6 +19688,7 @@ function handleConnection(socket, manager) {
|
|
|
19669
19688
|
}
|
|
19670
19689
|
};
|
|
19671
19690
|
manager.addClient(client);
|
|
19691
|
+
manager.clients.greet(client);
|
|
19672
19692
|
const lines = createInterface7({ input: socket });
|
|
19673
19693
|
lines.on("error", () => {
|
|
19674
19694
|
});
|
|
@@ -20014,10 +20034,12 @@ import chalk165 from "chalk";
|
|
|
20014
20034
|
|
|
20015
20035
|
// src/commands/buildLimitsSegment.ts
|
|
20016
20036
|
import chalk164 from "chalk";
|
|
20037
|
+
|
|
20038
|
+
// src/shared/rateLimitLevel.ts
|
|
20017
20039
|
var FIVE_HOUR_SECONDS = 5 * 3600;
|
|
20018
20040
|
var SEVEN_DAY_SECONDS = 7 * 86400;
|
|
20019
|
-
function
|
|
20020
|
-
const seconds = Math.max(0, resetsAt -
|
|
20041
|
+
function formatRateLimitTimeLeft(resetsAt, now) {
|
|
20042
|
+
const seconds = Math.max(0, resetsAt - now);
|
|
20021
20043
|
const days = Math.floor(seconds / 86400);
|
|
20022
20044
|
const hours = Math.floor(seconds % 86400 / 3600);
|
|
20023
20045
|
const minutes = Math.floor(seconds % 3600 / 60);
|
|
@@ -20025,45 +20047,72 @@ function formatTimeLeft(resetsAt) {
|
|
|
20025
20047
|
if (hours > 0) return `${hours}h ${minutes}m`;
|
|
20026
20048
|
return `${minutes}m`;
|
|
20027
20049
|
}
|
|
20028
|
-
function projectUsage(pct, resetsAt, windowSeconds) {
|
|
20050
|
+
function projectUsage(pct, resetsAt, windowSeconds, now) {
|
|
20029
20051
|
if (resetsAt == null) return void 0;
|
|
20030
|
-
const now = Math.floor(Date.now() / 1e3);
|
|
20031
20052
|
const timeRemaining = Math.max(0, resetsAt - now);
|
|
20032
20053
|
const elapsed = Math.max(0, windowSeconds - timeRemaining) / windowSeconds;
|
|
20033
20054
|
if (elapsed < 0.05) return void 0;
|
|
20034
20055
|
return pct / elapsed;
|
|
20035
20056
|
}
|
|
20036
|
-
function
|
|
20037
|
-
const
|
|
20038
|
-
|
|
20039
|
-
if (projected
|
|
20040
|
-
if (projected >
|
|
20041
|
-
|
|
20042
|
-
return chalk164.green(label2);
|
|
20057
|
+
function rateLimitLevel(pct, resetsAt, windowSeconds, now) {
|
|
20058
|
+
const projected = projectUsage(pct, resetsAt, windowSeconds, now);
|
|
20059
|
+
if (projected == null) return "ok";
|
|
20060
|
+
if (projected > 100) return "over";
|
|
20061
|
+
if (projected > 75) return "warn";
|
|
20062
|
+
return "ok";
|
|
20043
20063
|
}
|
|
20044
|
-
|
|
20045
|
-
|
|
20046
|
-
|
|
20064
|
+
|
|
20065
|
+
// src/commands/buildLimitsSegment.ts
|
|
20066
|
+
var LEVEL_COLOR = {
|
|
20067
|
+
ok: chalk164.green,
|
|
20068
|
+
warn: chalk164.yellow,
|
|
20069
|
+
over: chalk164.red
|
|
20070
|
+
};
|
|
20071
|
+
function formatLimit(pct, resetsAt, windowSeconds, fallbackLabel, now) {
|
|
20072
|
+
const level = rateLimitLevel(pct, resetsAt, windowSeconds, now);
|
|
20073
|
+
const label2 = LEVEL_COLOR[level](`${Math.round(pct)}%`);
|
|
20074
|
+
const timeLabel = resetsAt ? formatRateLimitTimeLeft(resetsAt, now) : fallbackLabel;
|
|
20075
|
+
return `${label2} (${timeLabel})`;
|
|
20047
20076
|
}
|
|
20048
20077
|
function buildLimitsSegment(rateLimits) {
|
|
20049
20078
|
const fiveHrPct = rateLimits?.five_hour?.used_percentage;
|
|
20050
20079
|
const sevenDayPct = rateLimits?.seven_day?.used_percentage;
|
|
20051
20080
|
if (fiveHrPct == null || sevenDayPct == null) return "";
|
|
20081
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
20052
20082
|
const fiveHr = formatLimit(
|
|
20053
20083
|
fiveHrPct,
|
|
20054
20084
|
rateLimits?.five_hour?.resets_at,
|
|
20055
20085
|
FIVE_HOUR_SECONDS,
|
|
20056
|
-
"5h"
|
|
20086
|
+
"5h",
|
|
20087
|
+
now
|
|
20057
20088
|
);
|
|
20058
20089
|
const sevenDay = formatLimit(
|
|
20059
20090
|
sevenDayPct,
|
|
20060
20091
|
rateLimits?.seven_day?.resets_at,
|
|
20061
20092
|
SEVEN_DAY_SECONDS,
|
|
20062
|
-
"7d"
|
|
20093
|
+
"7d",
|
|
20094
|
+
now
|
|
20063
20095
|
);
|
|
20064
20096
|
return ` | Limits - ${fiveHr}, ${sevenDay}`;
|
|
20065
20097
|
}
|
|
20066
20098
|
|
|
20099
|
+
// src/commands/relayRateLimits.ts
|
|
20100
|
+
async function relayRateLimits(rateLimits) {
|
|
20101
|
+
if (!rateLimits) return;
|
|
20102
|
+
try {
|
|
20103
|
+
const socket = await connectToDaemon();
|
|
20104
|
+
const timer = setTimeout(() => socket.destroy(), 500);
|
|
20105
|
+
socket.on("error", () => {
|
|
20106
|
+
});
|
|
20107
|
+
socket.write(`${JSON.stringify({ type: "limits", rateLimits })}
|
|
20108
|
+
`, () => {
|
|
20109
|
+
clearTimeout(timer);
|
|
20110
|
+
socket.end();
|
|
20111
|
+
});
|
|
20112
|
+
} catch {
|
|
20113
|
+
}
|
|
20114
|
+
}
|
|
20115
|
+
|
|
20067
20116
|
// src/commands/statusLine.ts
|
|
20068
20117
|
chalk165.level = 3;
|
|
20069
20118
|
function formatNumber(num) {
|
|
@@ -20084,6 +20133,7 @@ async function statusLine() {
|
|
|
20084
20133
|
console.log(
|
|
20085
20134
|
`${model} | Tokens - ${formatNumber(totalOut)} \u2191 : ${formatNumber(totalIn)} \u2193 | Context - ${colorizePercent(usedPct)}${buildLimitsSegment(data.rate_limits)}`
|
|
20086
20135
|
);
|
|
20136
|
+
await relayRateLimits(data.rate_limits);
|
|
20087
20137
|
}
|
|
20088
20138
|
|
|
20089
20139
|
// src/commands/sync.ts
|