one-more-token 0.5.1 → 0.5.2
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/main.js +60 -49
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -152,9 +152,9 @@ function nullish(input2) {
|
|
|
152
152
|
return input2 === null || input2 === void 0;
|
|
153
153
|
}
|
|
154
154
|
function cleanRegex(source3) {
|
|
155
|
-
const
|
|
155
|
+
const start2 = source3.startsWith("^") ? 1 : 0;
|
|
156
156
|
const end = source3.endsWith("$") ? source3.length - 1 : source3.length;
|
|
157
|
-
return source3.slice(
|
|
157
|
+
return source3.slice(start2, end);
|
|
158
158
|
}
|
|
159
159
|
function floatSafeRemainder(val, step) {
|
|
160
160
|
const ratio = val / step;
|
|
@@ -543,9 +543,9 @@ function sizeCaps(defChecks) {
|
|
|
543
543
|
}
|
|
544
544
|
return caps;
|
|
545
545
|
}
|
|
546
|
-
function attachSchema(issues,
|
|
546
|
+
function attachSchema(issues, start2, inst) {
|
|
547
547
|
var _a3;
|
|
548
|
-
for (let i =
|
|
548
|
+
for (let i = start2; i < issues.length; i++) {
|
|
549
549
|
(_a3 = issues[i]).schema ?? (_a3.schema = inst);
|
|
550
550
|
}
|
|
551
551
|
}
|
|
@@ -2279,10 +2279,10 @@ function capSize(inst, size) {
|
|
|
2279
2279
|
if (n > cap && !ctx?.skipChecks && ctx?.direction !== "backward") {
|
|
2280
2280
|
for (const [max, ch] of sizeCaps(inst._zod.def.checks)) {
|
|
2281
2281
|
if (n > max && ch._zod.def.when(payload)) {
|
|
2282
|
-
const
|
|
2282
|
+
const start2 = payload.issues.length;
|
|
2283
2283
|
ch._zod.check(payload);
|
|
2284
|
-
payload.issues[
|
|
2285
|
-
attachSchema(payload.issues,
|
|
2284
|
+
payload.issues[start2].continue = false;
|
|
2285
|
+
attachSchema(payload.issues, start2, inst);
|
|
2286
2286
|
return payload;
|
|
2287
2287
|
}
|
|
2288
2288
|
}
|
|
@@ -20901,8 +20901,8 @@ async function readSentAlertKeys(db) {
|
|
|
20901
20901
|
);
|
|
20902
20902
|
return new Set(
|
|
20903
20903
|
rows.map((row) => {
|
|
20904
|
-
const
|
|
20905
|
-
return alertKey(String(row.alert_id),
|
|
20904
|
+
const start2 = new Date(Number(row.ms)).toISOString();
|
|
20905
|
+
return alertKey(String(row.alert_id), start2);
|
|
20906
20906
|
})
|
|
20907
20907
|
);
|
|
20908
20908
|
}
|
|
@@ -21015,8 +21015,8 @@ var init_files = __esm({
|
|
|
21015
21015
|
const sorted = [...list].sort((a, b) => a.validFrom.localeCompare(b.validFrom));
|
|
21016
21016
|
for (let i = 1; i < sorted.length; i++) {
|
|
21017
21017
|
const previousEnd = sorted[i - 1]?.validTo;
|
|
21018
|
-
const
|
|
21019
|
-
if (previousEnd === null || previousEnd !== void 0 && previousEnd >=
|
|
21018
|
+
const start2 = sorted[i]?.validFrom ?? "";
|
|
21019
|
+
if (previousEnd === null || previousEnd !== void 0 && previousEnd >= start2) {
|
|
21020
21020
|
ctx.addIssue({ code: "custom", message: `overlapping validity for ${key2}` });
|
|
21021
21021
|
}
|
|
21022
21022
|
}
|
|
@@ -22070,11 +22070,11 @@ function rollingSpans(turns, length) {
|
|
|
22070
22070
|
function monthlySpans(turns, anchor2, now, active) {
|
|
22071
22071
|
const byStart = /* @__PURE__ */ new Map();
|
|
22072
22072
|
const add2 = (ms3) => {
|
|
22073
|
-
const { start, end } = monthlySpanAt(anchor2, ms3);
|
|
22074
|
-
let span = byStart.get(
|
|
22073
|
+
const { start: start2, end } = monthlySpanAt(anchor2, ms3);
|
|
22074
|
+
let span = byStart.get(start2);
|
|
22075
22075
|
if (!span) {
|
|
22076
|
-
span = { start, end, turns: [] };
|
|
22077
|
-
byStart.set(
|
|
22076
|
+
span = { start: start2, end, turns: [] };
|
|
22077
|
+
byStart.set(start2, span);
|
|
22078
22078
|
}
|
|
22079
22079
|
return span;
|
|
22080
22080
|
};
|
|
@@ -22247,17 +22247,17 @@ function computeQuotas(input2) {
|
|
|
22247
22247
|
now
|
|
22248
22248
|
);
|
|
22249
22249
|
});
|
|
22250
|
-
const
|
|
22250
|
+
const start2 = Math.max(from, activeFrom ?? from);
|
|
22251
22251
|
const end = Math.min(to, activeTo ?? to);
|
|
22252
22252
|
let apiEquivalentUsd = 0;
|
|
22253
22253
|
let unpricedTurns = 0;
|
|
22254
22254
|
for (const turn of own2) {
|
|
22255
|
-
if (turn.ms <
|
|
22255
|
+
if (turn.ms < start2 || turn.ms >= end) continue;
|
|
22256
22256
|
if (turn.computedCostUsd === null) unpricedTurns++;
|
|
22257
22257
|
else apiEquivalentUsd += turn.computedCostUsd;
|
|
22258
22258
|
}
|
|
22259
22259
|
const price2 = plan.monthlyPriceUsd ?? null;
|
|
22260
|
-
const paidUsd = price2 === null ? null : price2 * Math.max(0, end -
|
|
22260
|
+
const paidUsd = price2 === null ? null : price2 * Math.max(0, end - start2) / AVERAGE_MONTH;
|
|
22261
22261
|
return [
|
|
22262
22262
|
{
|
|
22263
22263
|
id: subscription.id,
|
|
@@ -23223,7 +23223,7 @@ var init_db_queue = __esm({
|
|
|
23223
23223
|
function summaryPeriod(params, now = Date.now()) {
|
|
23224
23224
|
const froms = params.getAll("from");
|
|
23225
23225
|
const tos = params.getAll("to");
|
|
23226
|
-
let
|
|
23226
|
+
let start2 = now - 7 * DAY3;
|
|
23227
23227
|
let end = now;
|
|
23228
23228
|
if (froms.length || tos.length) {
|
|
23229
23229
|
if (froms.length !== 1 || tos.length !== 1) return null;
|
|
@@ -23232,12 +23232,12 @@ function summaryPeriod(params, now = Date.now()) {
|
|
|
23232
23232
|
if (/\.\d{4,}/.test(value2)) return NaN;
|
|
23233
23233
|
return Date.parse(value2);
|
|
23234
23234
|
};
|
|
23235
|
-
|
|
23235
|
+
start2 = parse4(froms[0]);
|
|
23236
23236
|
end = parse4(tos[0]);
|
|
23237
23237
|
}
|
|
23238
|
-
if (!Number.isFinite(
|
|
23239
|
-
if ((utcDay(end - 1) - utcDay(
|
|
23240
|
-
const from = new Date(
|
|
23238
|
+
if (!Number.isFinite(start2) || !Number.isFinite(end) || start2 >= end) return null;
|
|
23239
|
+
if ((utcDay(end - 1) - utcDay(start2)) / DAY3 + 1 > 366) return null;
|
|
23240
|
+
const from = new Date(start2).toISOString();
|
|
23241
23241
|
const to = new Date(end).toISOString();
|
|
23242
23242
|
if (from.length !== 24 || to.length !== 24) return null;
|
|
23243
23243
|
return { from, to };
|
|
@@ -23727,19 +23727,19 @@ var init_url = __esm({
|
|
|
23727
23727
|
tryDecodeURI = (str) => tryDecode(str, decodeURI);
|
|
23728
23728
|
getPath = (request) => {
|
|
23729
23729
|
const url2 = request.url;
|
|
23730
|
-
const
|
|
23731
|
-
let i =
|
|
23730
|
+
const start2 = url2.indexOf("/", url2.indexOf(":") + 4);
|
|
23731
|
+
let i = start2;
|
|
23732
23732
|
for (; i < url2.length; i++) {
|
|
23733
23733
|
const charCode = url2.charCodeAt(i);
|
|
23734
23734
|
if (charCode === 37) {
|
|
23735
23735
|
const queryIndex = url2.indexOf("?", i);
|
|
23736
23736
|
const hashIndex = url2.indexOf("#", i);
|
|
23737
23737
|
const end = queryIndex === -1 ? hashIndex === -1 ? void 0 : hashIndex : hashIndex === -1 ? queryIndex : Math.min(queryIndex, hashIndex);
|
|
23738
|
-
const path = url2.slice(
|
|
23738
|
+
const path = url2.slice(start2, end);
|
|
23739
23739
|
return tryDecodeURI(path.includes("%25") ? path.replace(/%25/g, "%2525") : path);
|
|
23740
23740
|
} else if (charCode === 63 || charCode === 35) break;
|
|
23741
23741
|
}
|
|
23742
|
-
return url2.slice(
|
|
23742
|
+
return url2.slice(start2, i);
|
|
23743
23743
|
};
|
|
23744
23744
|
getPathNoStrict = (request) => {
|
|
23745
23745
|
const result = getPath(request);
|
|
@@ -29676,8 +29676,8 @@ async function monthlyData(db, period, options) {
|
|
|
29676
29676
|
};
|
|
29677
29677
|
}
|
|
29678
29678
|
function monthPeriodBefore(period) {
|
|
29679
|
-
const
|
|
29680
|
-
const date8 = new Date(
|
|
29679
|
+
const start2 = Date.parse(period.from);
|
|
29680
|
+
const date8 = new Date(start2);
|
|
29681
29681
|
const previous = Date.UTC(date8.getUTCFullYear(), date8.getUTCMonth() - 1, 1);
|
|
29682
29682
|
return { from: new Date(previous).toISOString(), to: period.from };
|
|
29683
29683
|
}
|
|
@@ -29878,11 +29878,11 @@ var init_dist2 = __esm({
|
|
|
29878
29878
|
isHttpWhitespace = (code) => code === 9 || code === 10 || code === 13 || code === 32;
|
|
29879
29879
|
normalizeHeaderValue = (value2) => {
|
|
29880
29880
|
if (!isHttpWhitespace(value2.charCodeAt(0)) && !isHttpWhitespace(value2.charCodeAt(value2.length - 1))) return value2;
|
|
29881
|
-
let
|
|
29881
|
+
let start2 = 0;
|
|
29882
29882
|
let end = value2.length;
|
|
29883
|
-
while (
|
|
29884
|
-
while (end >
|
|
29885
|
-
return value2.slice(
|
|
29883
|
+
while (start2 < end && isHttpWhitespace(value2.charCodeAt(start2))) start2++;
|
|
29884
|
+
while (end > start2 && isHttpWhitespace(value2.charCodeAt(end - 1))) end--;
|
|
29885
|
+
return value2.slice(start2, end);
|
|
29886
29886
|
};
|
|
29887
29887
|
forbiddenHeaderValue = /[\0\r\n]/;
|
|
29888
29888
|
GlobalHeaders = globalThis.Headers;
|
|
@@ -31154,9 +31154,9 @@ var init_server = __esm({
|
|
|
31154
31154
|
|
|
31155
31155
|
// src/start.ts
|
|
31156
31156
|
import { exec } from "node:child_process";
|
|
31157
|
-
import { existsSync } from "node:fs";
|
|
31157
|
+
import { existsSync, mkdirSync } from "node:fs";
|
|
31158
31158
|
import { homedir as homedir4 } from "node:os";
|
|
31159
|
-
import { join as join13 } from "node:path";
|
|
31159
|
+
import { dirname as dirname3, join as join13 } from "node:path";
|
|
31160
31160
|
function defaultOpenBrowser(url2) {
|
|
31161
31161
|
return new Promise((resolve) => {
|
|
31162
31162
|
const command = process.platform === "darwin" ? `open ${JSON.stringify(url2)}` : process.platform === "win32" ? `start "" ${JSON.stringify(url2)}` : `xdg-open ${JSON.stringify(url2)}`;
|
|
@@ -31211,6 +31211,7 @@ ${detected.join("\n")}
|
|
|
31211
31211
|
let db;
|
|
31212
31212
|
let server;
|
|
31213
31213
|
try {
|
|
31214
|
+
if (options.db !== ":memory:") mkdirSync(dirname3(options.db), { recursive: true });
|
|
31214
31215
|
db = await openDatabase(options.db);
|
|
31215
31216
|
await migrate(db);
|
|
31216
31217
|
const home = io.env.HOME ?? homedir4();
|
|
@@ -31254,7 +31255,6 @@ var init_start = __esm({
|
|
|
31254
31255
|
init_src();
|
|
31255
31256
|
init_app();
|
|
31256
31257
|
init_service7();
|
|
31257
|
-
init_options();
|
|
31258
31258
|
init_server();
|
|
31259
31259
|
init_static();
|
|
31260
31260
|
EXIT_OK = 0;
|
|
@@ -31275,26 +31275,28 @@ __export(cli_exports, {
|
|
|
31275
31275
|
USAGE: () => USAGE,
|
|
31276
31276
|
run: () => run2
|
|
31277
31277
|
});
|
|
31278
|
-
import { mkdirSync } from "node:fs";
|
|
31278
|
+
import { mkdirSync as mkdirSync2 } from "node:fs";
|
|
31279
31279
|
import { homedir as homedir5 } from "node:os";
|
|
31280
|
-
import { dirname as
|
|
31280
|
+
import { dirname as dirname4 } from "node:path";
|
|
31281
31281
|
async function run2(argv, io, deps = { waitForShutdown: () => waitForSignal() }) {
|
|
31282
31282
|
const [command, ...args] = argv;
|
|
31283
|
-
if (command === void 0
|
|
31283
|
+
if (command === void 0) return start([], io, deps);
|
|
31284
|
+
if (command === "--help" || command === "-h") {
|
|
31284
31285
|
io.stdout(USAGE);
|
|
31285
31286
|
return EXIT_OK2;
|
|
31286
31287
|
}
|
|
31287
31288
|
if (command.startsWith("-")) {
|
|
31288
|
-
|
|
31289
|
+
if (argv.includes("--help") || argv.includes("-h")) {
|
|
31290
|
+
io.stdout(USAGE);
|
|
31291
|
+
return EXIT_OK2;
|
|
31292
|
+
}
|
|
31293
|
+
return start(argv, io, deps);
|
|
31289
31294
|
}
|
|
31290
31295
|
switch (command) {
|
|
31291
31296
|
case "serve":
|
|
31292
31297
|
return serveCommand(args, io, deps);
|
|
31293
31298
|
case "start":
|
|
31294
|
-
return
|
|
31295
|
-
waitForShutdown: deps.waitForShutdown ?? (() => waitForSignal()),
|
|
31296
|
-
...deps.openBrowser ? { openBrowser: deps.openBrowser } : {}
|
|
31297
|
-
});
|
|
31299
|
+
return start(args, io, deps);
|
|
31298
31300
|
case "ingest":
|
|
31299
31301
|
return ingestCommand(args, io, deps);
|
|
31300
31302
|
case "watch":
|
|
@@ -31313,6 +31315,12 @@ ${HELP_HINT}
|
|
|
31313
31315
|
`);
|
|
31314
31316
|
return EXIT_USAGE2;
|
|
31315
31317
|
}
|
|
31318
|
+
function start(args, io, deps) {
|
|
31319
|
+
return startCommand(args, io, {
|
|
31320
|
+
waitForShutdown: deps.waitForShutdown ?? (() => waitForSignal()),
|
|
31321
|
+
...deps.openBrowser ? { openBrowser: deps.openBrowser } : {}
|
|
31322
|
+
});
|
|
31323
|
+
}
|
|
31316
31324
|
async function ingestCommand(args, io, deps) {
|
|
31317
31325
|
const parsed = parseIngestOptions(args);
|
|
31318
31326
|
if (!parsed.ok) return usageError(io, "omt ingest", parsed.error);
|
|
@@ -31405,7 +31413,7 @@ async function serveCommand(args, io, deps) {
|
|
|
31405
31413
|
}
|
|
31406
31414
|
}
|
|
31407
31415
|
async function openMigratedDatabase(options) {
|
|
31408
|
-
if (options.db !== ":memory:")
|
|
31416
|
+
if (options.db !== ":memory:") mkdirSync2(dirname4(options.db), { recursive: true });
|
|
31409
31417
|
const db = await openDatabase(options.db);
|
|
31410
31418
|
try {
|
|
31411
31419
|
await migrate(db);
|
|
@@ -31439,7 +31447,10 @@ var init_cli = __esm({
|
|
|
31439
31447
|
HELP_HINT = "Run `omt --help` for usage.";
|
|
31440
31448
|
USAGE = `One More Token: local dashboard for AI coding agent usage.
|
|
31441
31449
|
|
|
31442
|
-
Usage: omt <command> [options]
|
|
31450
|
+
Usage: omt [<command>] [options]
|
|
31451
|
+
|
|
31452
|
+
With no command, omt runs "start": ingest local metrics, serve the dashboard
|
|
31453
|
+
and open it in the browser.
|
|
31443
31454
|
|
|
31444
31455
|
Commands:
|
|
31445
31456
|
start Ingest local agent metrics, serve the dashboard and open it in the browser
|
|
@@ -31494,10 +31505,10 @@ Global options:
|
|
|
31494
31505
|
});
|
|
31495
31506
|
|
|
31496
31507
|
// src/entry-npm.ts
|
|
31497
|
-
import { dirname as
|
|
31508
|
+
import { dirname as dirname5, join as join14 } from "node:path";
|
|
31498
31509
|
import { fileURLToPath as fileURLToPath4 } from "node:url";
|
|
31499
|
-
var here =
|
|
31500
|
-
var root =
|
|
31510
|
+
var here = dirname5(fileURLToPath4(import.meta.url));
|
|
31511
|
+
var root = dirname5(here);
|
|
31501
31512
|
process.env.OMT_DATA_DIR ??= join14(root, "data");
|
|
31502
31513
|
process.env.OMT_WEB_DIST ??= join14(root, "web-dist");
|
|
31503
31514
|
process.env.OMT_MIGRATIONS_DIR ??= join14(root, "migrations");
|