whoburnedmore 0.9.12 → 0.9.15
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 +1998 -1681
- package/package.json +3 -4
package/dist/index.js
CHANGED
|
@@ -8,10 +8,10 @@ var __export = (target, all) => {
|
|
|
8
8
|
// src/index.ts
|
|
9
9
|
import { spawn } from "node:child_process";
|
|
10
10
|
import { createHash } from "node:crypto";
|
|
11
|
-
import { mkdirSync as
|
|
11
|
+
import { mkdirSync as mkdirSync5, writeFileSync as writeFileSync5 } from "node:fs";
|
|
12
12
|
import { createRequire as createRequire4 } from "node:module";
|
|
13
13
|
import { platform as platform3 } from "node:os";
|
|
14
|
-
import { join as
|
|
14
|
+
import { join as join12 } from "node:path";
|
|
15
15
|
import { createInterface } from "node:readline/promises";
|
|
16
16
|
import pc2 from "picocolors";
|
|
17
17
|
|
|
@@ -46,22 +46,25 @@ function parseValueFlag(args, name) {
|
|
|
46
46
|
return void 0;
|
|
47
47
|
}
|
|
48
48
|
function resolveCommand(args) {
|
|
49
|
-
if (args.includes("--help") || args.includes("-h") || args.includes("help")) {
|
|
50
|
-
return "help";
|
|
51
|
-
}
|
|
52
|
-
if (args.includes("--version") || args.includes("-v") || args.includes("version")) {
|
|
53
|
-
return "version";
|
|
54
|
-
}
|
|
55
49
|
const valueFlags = /* @__PURE__ */ new Set(["--board", "--org", "--token", "--pass", "--code"]);
|
|
50
|
+
const flags = [];
|
|
51
|
+
const words = [];
|
|
56
52
|
for (let i = 0; i < args.length; i++) {
|
|
57
53
|
const a = args[i];
|
|
58
54
|
if (a.startsWith("-")) {
|
|
55
|
+
flags.push(a);
|
|
59
56
|
if (valueFlags.has(a)) i++;
|
|
60
57
|
continue;
|
|
61
58
|
}
|
|
62
|
-
|
|
59
|
+
words.push(a);
|
|
60
|
+
}
|
|
61
|
+
if (flags.includes("--help") || flags.includes("-h") || words.includes("help")) {
|
|
62
|
+
return "help";
|
|
63
|
+
}
|
|
64
|
+
if (flags.includes("--version") || flags.includes("-v") || words.includes("version")) {
|
|
65
|
+
return "version";
|
|
63
66
|
}
|
|
64
|
-
return "run";
|
|
67
|
+
return words[0] ?? "run";
|
|
65
68
|
}
|
|
66
69
|
|
|
67
70
|
// src/api.ts
|
|
@@ -786,1500 +789,981 @@ async function daemonLoop(deps) {
|
|
|
786
789
|
// src/collect.ts
|
|
787
790
|
import { execFile } from "node:child_process";
|
|
788
791
|
import { createRequire as createRequire3 } from "node:module";
|
|
789
|
-
import { dirname as
|
|
792
|
+
import { dirname as dirname6, join as join11 } from "node:path";
|
|
790
793
|
import { promisify } from "node:util";
|
|
791
794
|
|
|
792
795
|
// src/attribution.ts
|
|
793
|
-
import {
|
|
796
|
+
import { readdirSync, statSync as statSync2 } from "node:fs";
|
|
797
|
+
import { homedir as homedir4 } from "node:os";
|
|
798
|
+
import { join as join5 } from "node:path";
|
|
799
|
+
|
|
800
|
+
// src/native/claude.ts
|
|
801
|
+
import { readdir, readFile as readFile2 } from "node:fs/promises";
|
|
794
802
|
import { homedir as homedir3 } from "node:os";
|
|
795
|
-
import { join as
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
var
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
803
|
+
import { join as join4 } from "node:path";
|
|
804
|
+
|
|
805
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/external.js
|
|
806
|
+
var external_exports = {};
|
|
807
|
+
__export(external_exports, {
|
|
808
|
+
BRAND: () => BRAND,
|
|
809
|
+
DIRTY: () => DIRTY,
|
|
810
|
+
EMPTY_PATH: () => EMPTY_PATH,
|
|
811
|
+
INVALID: () => INVALID,
|
|
812
|
+
NEVER: () => NEVER,
|
|
813
|
+
OK: () => OK,
|
|
814
|
+
ParseStatus: () => ParseStatus,
|
|
815
|
+
Schema: () => ZodType,
|
|
816
|
+
ZodAny: () => ZodAny,
|
|
817
|
+
ZodArray: () => ZodArray,
|
|
818
|
+
ZodBigInt: () => ZodBigInt,
|
|
819
|
+
ZodBoolean: () => ZodBoolean,
|
|
820
|
+
ZodBranded: () => ZodBranded,
|
|
821
|
+
ZodCatch: () => ZodCatch,
|
|
822
|
+
ZodDate: () => ZodDate,
|
|
823
|
+
ZodDefault: () => ZodDefault,
|
|
824
|
+
ZodDiscriminatedUnion: () => ZodDiscriminatedUnion,
|
|
825
|
+
ZodEffects: () => ZodEffects,
|
|
826
|
+
ZodEnum: () => ZodEnum,
|
|
827
|
+
ZodError: () => ZodError,
|
|
828
|
+
ZodFirstPartyTypeKind: () => ZodFirstPartyTypeKind,
|
|
829
|
+
ZodFunction: () => ZodFunction,
|
|
830
|
+
ZodIntersection: () => ZodIntersection,
|
|
831
|
+
ZodIssueCode: () => ZodIssueCode,
|
|
832
|
+
ZodLazy: () => ZodLazy,
|
|
833
|
+
ZodLiteral: () => ZodLiteral,
|
|
834
|
+
ZodMap: () => ZodMap,
|
|
835
|
+
ZodNaN: () => ZodNaN,
|
|
836
|
+
ZodNativeEnum: () => ZodNativeEnum,
|
|
837
|
+
ZodNever: () => ZodNever,
|
|
838
|
+
ZodNull: () => ZodNull,
|
|
839
|
+
ZodNullable: () => ZodNullable,
|
|
840
|
+
ZodNumber: () => ZodNumber,
|
|
841
|
+
ZodObject: () => ZodObject,
|
|
842
|
+
ZodOptional: () => ZodOptional,
|
|
843
|
+
ZodParsedType: () => ZodParsedType,
|
|
844
|
+
ZodPipeline: () => ZodPipeline,
|
|
845
|
+
ZodPromise: () => ZodPromise,
|
|
846
|
+
ZodReadonly: () => ZodReadonly,
|
|
847
|
+
ZodRecord: () => ZodRecord,
|
|
848
|
+
ZodSchema: () => ZodType,
|
|
849
|
+
ZodSet: () => ZodSet,
|
|
850
|
+
ZodString: () => ZodString,
|
|
851
|
+
ZodSymbol: () => ZodSymbol,
|
|
852
|
+
ZodTransformer: () => ZodEffects,
|
|
853
|
+
ZodTuple: () => ZodTuple,
|
|
854
|
+
ZodType: () => ZodType,
|
|
855
|
+
ZodUndefined: () => ZodUndefined,
|
|
856
|
+
ZodUnion: () => ZodUnion,
|
|
857
|
+
ZodUnknown: () => ZodUnknown,
|
|
858
|
+
ZodVoid: () => ZodVoid,
|
|
859
|
+
addIssueToContext: () => addIssueToContext,
|
|
860
|
+
any: () => anyType,
|
|
861
|
+
array: () => arrayType,
|
|
862
|
+
bigint: () => bigIntType,
|
|
863
|
+
boolean: () => booleanType,
|
|
864
|
+
coerce: () => coerce,
|
|
865
|
+
custom: () => custom,
|
|
866
|
+
date: () => dateType,
|
|
867
|
+
datetimeRegex: () => datetimeRegex,
|
|
868
|
+
defaultErrorMap: () => en_default,
|
|
869
|
+
discriminatedUnion: () => discriminatedUnionType,
|
|
870
|
+
effect: () => effectsType,
|
|
871
|
+
enum: () => enumType,
|
|
872
|
+
function: () => functionType,
|
|
873
|
+
getErrorMap: () => getErrorMap,
|
|
874
|
+
getParsedType: () => getParsedType,
|
|
875
|
+
instanceof: () => instanceOfType,
|
|
876
|
+
intersection: () => intersectionType,
|
|
877
|
+
isAborted: () => isAborted,
|
|
878
|
+
isAsync: () => isAsync,
|
|
879
|
+
isDirty: () => isDirty,
|
|
880
|
+
isValid: () => isValid,
|
|
881
|
+
late: () => late,
|
|
882
|
+
lazy: () => lazyType,
|
|
883
|
+
literal: () => literalType,
|
|
884
|
+
makeIssue: () => makeIssue,
|
|
885
|
+
map: () => mapType,
|
|
886
|
+
nan: () => nanType,
|
|
887
|
+
nativeEnum: () => nativeEnumType,
|
|
888
|
+
never: () => neverType,
|
|
889
|
+
null: () => nullType,
|
|
890
|
+
nullable: () => nullableType,
|
|
891
|
+
number: () => numberType,
|
|
892
|
+
object: () => objectType,
|
|
893
|
+
objectUtil: () => objectUtil,
|
|
894
|
+
oboolean: () => oboolean,
|
|
895
|
+
onumber: () => onumber,
|
|
896
|
+
optional: () => optionalType,
|
|
897
|
+
ostring: () => ostring,
|
|
898
|
+
pipeline: () => pipelineType,
|
|
899
|
+
preprocess: () => preprocessType,
|
|
900
|
+
promise: () => promiseType,
|
|
901
|
+
quotelessJson: () => quotelessJson,
|
|
902
|
+
record: () => recordType,
|
|
903
|
+
set: () => setType,
|
|
904
|
+
setErrorMap: () => setErrorMap,
|
|
905
|
+
strictObject: () => strictObjectType,
|
|
906
|
+
string: () => stringType,
|
|
907
|
+
symbol: () => symbolType,
|
|
908
|
+
transformer: () => effectsType,
|
|
909
|
+
tuple: () => tupleType,
|
|
910
|
+
undefined: () => undefinedType,
|
|
911
|
+
union: () => unionType,
|
|
912
|
+
unknown: () => unknownType,
|
|
913
|
+
util: () => util,
|
|
914
|
+
void: () => voidType
|
|
915
|
+
});
|
|
916
|
+
|
|
917
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/util.js
|
|
918
|
+
var util;
|
|
919
|
+
(function(util2) {
|
|
920
|
+
util2.assertEqual = (_) => {
|
|
832
921
|
};
|
|
833
|
-
|
|
834
|
-
if (!Array.isArray(content)) return false;
|
|
835
|
-
return content.some(
|
|
836
|
-
(b) => b !== null && typeof b === "object" && b.type === "text" && typeof b.text === "string" && isHuman(b.text)
|
|
837
|
-
);
|
|
838
|
-
}
|
|
839
|
-
function processRecord(rec, acc, ctx) {
|
|
840
|
-
if (!rec || typeof rec !== "object") return;
|
|
841
|
-
const r = rec;
|
|
842
|
-
const recTokens = recordTokens(r.message?.usage);
|
|
843
|
-
if ((r.type === "user" || r.message?.role === "user") && r.isSidechain !== true && r.isMeta !== true && hasHumanText(r.message?.content)) {
|
|
844
|
-
acc.agent.userMessageCount += 1;
|
|
922
|
+
function assertIs(_arg) {
|
|
845
923
|
}
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
sk.count += 1;
|
|
850
|
-
sk.tokens += recTokens;
|
|
851
|
-
acc.skills.set(s, sk);
|
|
924
|
+
util2.assertIs = assertIs;
|
|
925
|
+
function assertNever(_x) {
|
|
926
|
+
throw new Error();
|
|
852
927
|
}
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
const toolUses = [];
|
|
859
|
-
for (const block of content) {
|
|
860
|
-
if (block && typeof block === "object" && block.type === "tool_use" && typeof block.name === "string") {
|
|
861
|
-
const name = block.name.slice(0, 128);
|
|
862
|
-
if (!name) continue;
|
|
863
|
-
const id = block.id;
|
|
864
|
-
toolUses.push({ name, id: typeof id === "string" ? id : void 0 });
|
|
865
|
-
}
|
|
866
|
-
}
|
|
867
|
-
const perToolTokens = toolUses.length > 0 ? Math.floor(recTokens / toolUses.length) : 0;
|
|
868
|
-
for (const tu of toolUses) {
|
|
869
|
-
const t = acc.tools.get(tu.name) ?? { count: 0, errors: 0, tokens: 0 };
|
|
870
|
-
t.count += 1;
|
|
871
|
-
t.tokens += perToolTokens;
|
|
872
|
-
acc.tools.set(tu.name, t);
|
|
873
|
-
if (tu.id) ctx.toolNames.set(tu.id, tu.name);
|
|
874
|
-
}
|
|
875
|
-
const tokens = recTokens;
|
|
876
|
-
acc.agent.messageCount += 1;
|
|
877
|
-
acc.agent.totalTokens += tokens;
|
|
878
|
-
const sidechain = r.isSidechain === true;
|
|
879
|
-
if (sidechain) {
|
|
880
|
-
acc.agent.subagentMessages += 1;
|
|
881
|
-
acc.agent.subagentTokens += tokens;
|
|
928
|
+
util2.assertNever = assertNever;
|
|
929
|
+
util2.arrayToEnum = (items) => {
|
|
930
|
+
const obj = {};
|
|
931
|
+
for (const item of items) {
|
|
932
|
+
obj[item] = item;
|
|
882
933
|
}
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
934
|
+
return obj;
|
|
935
|
+
};
|
|
936
|
+
util2.getValidEnumValues = (obj) => {
|
|
937
|
+
const validKeys = util2.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
|
|
938
|
+
const filtered = {};
|
|
939
|
+
for (const k of validKeys) {
|
|
940
|
+
filtered[k] = obj[k];
|
|
888
941
|
}
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
942
|
+
return util2.objectValues(filtered);
|
|
943
|
+
};
|
|
944
|
+
util2.objectValues = (obj) => {
|
|
945
|
+
return util2.objectKeys(obj).map(function(e) {
|
|
946
|
+
return obj[e];
|
|
947
|
+
});
|
|
948
|
+
};
|
|
949
|
+
util2.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
|
|
950
|
+
const keys = [];
|
|
951
|
+
for (const key in object) {
|
|
952
|
+
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
953
|
+
keys.push(key);
|
|
899
954
|
}
|
|
900
955
|
}
|
|
901
|
-
|
|
902
|
-
}
|
|
903
|
-
function toSkillStats(map) {
|
|
904
|
-
return [...map.entries()].map(([name, v]) => ({ name, count: v.count, tokens: v.tokens })).filter((s) => s.count > 0).sort((a, b) => b.tokens - a.tokens || b.count - a.count).slice(0, MAX_STATS).map((s) => s.tokens > 0 ? s : { name: s.name, count: s.count });
|
|
905
|
-
}
|
|
906
|
-
function toToolStats(map) {
|
|
907
|
-
return [...map.entries()].map(([name, v]) => ({ name, count: v.count, errors: v.errors, tokens: v.tokens })).filter((s) => s.count > 0).sort((a, b) => b.tokens - a.tokens || b.count - a.count).slice(0, MAX_STATS).map((s) => {
|
|
908
|
-
const base = { name: s.name, count: s.count };
|
|
909
|
-
if (s.errors > 0) base.errors = s.errors;
|
|
910
|
-
if (s.tokens > 0) base.tokens = s.tokens;
|
|
911
|
-
return base;
|
|
912
|
-
});
|
|
913
|
-
}
|
|
914
|
-
function accumulatorToResult(acc) {
|
|
915
|
-
return {
|
|
916
|
-
tools: toToolStats(acc.tools),
|
|
917
|
-
skills: toSkillStats(acc.skills),
|
|
918
|
-
agent: { ...acc.agent },
|
|
919
|
-
sessionMessages: acc.sessionMessages,
|
|
920
|
-
complete: true
|
|
956
|
+
return keys;
|
|
921
957
|
};
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
}
|
|
927
|
-
function createCodexContext() {
|
|
928
|
-
return { pending: [] };
|
|
929
|
-
}
|
|
930
|
-
function processCodexRecord(rec, acc, ctx) {
|
|
931
|
-
if (!rec || typeof rec !== "object") return;
|
|
932
|
-
const r = rec;
|
|
933
|
-
if (!r.payload || typeof r.payload !== "object") return;
|
|
934
|
-
const pl = r.payload;
|
|
935
|
-
const ptype = pl.type;
|
|
936
|
-
if (r.type === "session_meta" || r.type === "turn_context") return;
|
|
937
|
-
if (ptype === "function_call" || ptype === "custom_tool_call" || ptype === "local_shell_call") {
|
|
938
|
-
const raw = typeof pl.name === "string" ? pl.name : ptype === "local_shell_call" ? "local_shell" : "";
|
|
939
|
-
const name = raw.slice(0, 128);
|
|
940
|
-
if (!name) return;
|
|
941
|
-
const id = typeof pl.call_id === "string" ? pl.call_id : void 0;
|
|
942
|
-
ctx.pending.push({ name, id });
|
|
943
|
-
const t = acc.tools.get(name) ?? { count: 0, errors: 0, tokens: 0 };
|
|
944
|
-
t.count += 1;
|
|
945
|
-
acc.tools.set(name, t);
|
|
946
|
-
return;
|
|
947
|
-
}
|
|
948
|
-
if (ptype === "token_count") {
|
|
949
|
-
const info = pl.info;
|
|
950
|
-
const last = info?.last_token_usage;
|
|
951
|
-
if (!last) return;
|
|
952
|
-
const inputTokens = numTok(last.input_tokens);
|
|
953
|
-
const cacheReadTokens = numTok(last.cached_input_tokens);
|
|
954
|
-
const outputTokens = numTok(last.output_tokens) + numTok(last.reasoning_output_tokens);
|
|
955
|
-
const tokens = numTok(last.total_tokens) || inputTokens + cacheReadTokens + outputTokens;
|
|
956
|
-
if (tokens <= 0) {
|
|
957
|
-
ctx.pending = [];
|
|
958
|
-
return;
|
|
959
|
-
}
|
|
960
|
-
acc.agent.messageCount += 1;
|
|
961
|
-
acc.agent.totalTokens += tokens;
|
|
962
|
-
const per = ctx.pending.length > 0 ? Math.floor(tokens / ctx.pending.length) : 0;
|
|
963
|
-
for (const tu of ctx.pending) {
|
|
964
|
-
const t = acc.tools.get(tu.name);
|
|
965
|
-
if (t) t.tokens += per;
|
|
958
|
+
util2.find = (arr, checker) => {
|
|
959
|
+
for (const item of arr) {
|
|
960
|
+
if (checker(item))
|
|
961
|
+
return item;
|
|
966
962
|
}
|
|
967
|
-
|
|
968
|
-
}
|
|
969
|
-
|
|
970
|
-
function
|
|
971
|
-
|
|
972
|
-
try {
|
|
973
|
-
size = statSync2(file).size;
|
|
974
|
-
} catch {
|
|
975
|
-
return [];
|
|
976
|
-
}
|
|
977
|
-
if (size > MAX_FILE_BYTES) return [];
|
|
978
|
-
try {
|
|
979
|
-
return readFileSync3(file, "utf8").split("\n");
|
|
980
|
-
} catch {
|
|
981
|
-
return [];
|
|
963
|
+
return void 0;
|
|
964
|
+
};
|
|
965
|
+
util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
|
|
966
|
+
function joinValues(array, separator = " | ") {
|
|
967
|
+
return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
|
|
982
968
|
}
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
if (cfg) dirs.push(join3(cfg, "projects"));
|
|
988
|
-
dirs.push(join3(homedir3(), ".config", "claude", "projects"));
|
|
989
|
-
return [...new Set(dirs)];
|
|
990
|
-
}
|
|
991
|
-
function listTranscripts(dir) {
|
|
992
|
-
const out = [];
|
|
993
|
-
const walk = (d) => {
|
|
994
|
-
if (out.length >= MAX_FILES) return;
|
|
995
|
-
let entries;
|
|
996
|
-
try {
|
|
997
|
-
entries = readdirSync(d, { withFileTypes: true });
|
|
998
|
-
} catch {
|
|
999
|
-
return;
|
|
1000
|
-
}
|
|
1001
|
-
for (const e of entries) {
|
|
1002
|
-
if (out.length >= MAX_FILES) return;
|
|
1003
|
-
const p = join3(d, e.name);
|
|
1004
|
-
if (e.isDirectory()) walk(p);
|
|
1005
|
-
else if (e.isFile() && e.name.endsWith(".jsonl")) {
|
|
1006
|
-
try {
|
|
1007
|
-
out.push({ path: p, mtime: statSync2(p).mtimeMs });
|
|
1008
|
-
} catch {
|
|
1009
|
-
}
|
|
1010
|
-
}
|
|
969
|
+
util2.joinValues = joinValues;
|
|
970
|
+
util2.jsonStringifyReplacer = (_, value) => {
|
|
971
|
+
if (typeof value === "bigint") {
|
|
972
|
+
return value.toString();
|
|
1011
973
|
}
|
|
974
|
+
return value;
|
|
1012
975
|
};
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
if (++sinceYield >= 8) {
|
|
1023
|
-
sinceYield = 0;
|
|
1024
|
-
await new Promise((r) => setImmediate(r));
|
|
1025
|
-
}
|
|
976
|
+
})(util || (util = {}));
|
|
977
|
+
var objectUtil;
|
|
978
|
+
(function(objectUtil2) {
|
|
979
|
+
objectUtil2.mergeShapes = (first, second) => {
|
|
980
|
+
return {
|
|
981
|
+
...first,
|
|
982
|
+
...second
|
|
983
|
+
// second overwrites first
|
|
984
|
+
};
|
|
1026
985
|
};
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
986
|
+
})(objectUtil || (objectUtil = {}));
|
|
987
|
+
var ZodParsedType = util.arrayToEnum([
|
|
988
|
+
"string",
|
|
989
|
+
"nan",
|
|
990
|
+
"number",
|
|
991
|
+
"integer",
|
|
992
|
+
"float",
|
|
993
|
+
"boolean",
|
|
994
|
+
"date",
|
|
995
|
+
"bigint",
|
|
996
|
+
"symbol",
|
|
997
|
+
"function",
|
|
998
|
+
"undefined",
|
|
999
|
+
"null",
|
|
1000
|
+
"array",
|
|
1001
|
+
"object",
|
|
1002
|
+
"unknown",
|
|
1003
|
+
"promise",
|
|
1004
|
+
"void",
|
|
1005
|
+
"never",
|
|
1006
|
+
"map",
|
|
1007
|
+
"set"
|
|
1008
|
+
]);
|
|
1009
|
+
var getParsedType = (data) => {
|
|
1010
|
+
const t = typeof data;
|
|
1011
|
+
switch (t) {
|
|
1012
|
+
case "undefined":
|
|
1013
|
+
return ZodParsedType.undefined;
|
|
1014
|
+
case "string":
|
|
1015
|
+
return ZodParsedType.string;
|
|
1016
|
+
case "number":
|
|
1017
|
+
return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
|
|
1018
|
+
case "boolean":
|
|
1019
|
+
return ZodParsedType.boolean;
|
|
1020
|
+
case "function":
|
|
1021
|
+
return ZodParsedType.function;
|
|
1022
|
+
case "bigint":
|
|
1023
|
+
return ZodParsedType.bigint;
|
|
1024
|
+
case "symbol":
|
|
1025
|
+
return ZodParsedType.symbol;
|
|
1026
|
+
case "object":
|
|
1027
|
+
if (Array.isArray(data)) {
|
|
1028
|
+
return ZodParsedType.array;
|
|
1043
1029
|
}
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
if (Date.now() > deadline) {
|
|
1047
|
-
complete = false;
|
|
1048
|
-
break;
|
|
1030
|
+
if (data === null) {
|
|
1031
|
+
return ZodParsedType.null;
|
|
1049
1032
|
}
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
if (!line) continue;
|
|
1053
|
-
try {
|
|
1054
|
-
processCodexRecord(JSON.parse(line), acc, ctx);
|
|
1055
|
-
} catch {
|
|
1056
|
-
}
|
|
1033
|
+
if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
|
|
1034
|
+
return ZodParsedType.promise;
|
|
1057
1035
|
}
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1036
|
+
if (typeof Map !== "undefined" && data instanceof Map) {
|
|
1037
|
+
return ZodParsedType.map;
|
|
1038
|
+
}
|
|
1039
|
+
if (typeof Set !== "undefined" && data instanceof Set) {
|
|
1040
|
+
return ZodParsedType.set;
|
|
1041
|
+
}
|
|
1042
|
+
if (typeof Date !== "undefined" && data instanceof Date) {
|
|
1043
|
+
return ZodParsedType.date;
|
|
1044
|
+
}
|
|
1045
|
+
return ZodParsedType.object;
|
|
1046
|
+
default:
|
|
1047
|
+
return ZodParsedType.unknown;
|
|
1062
1048
|
}
|
|
1063
|
-
|
|
1064
|
-
}
|
|
1065
|
-
|
|
1066
|
-
// src/cursor.ts
|
|
1067
|
-
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
1068
|
-
import { existsSync as existsSync3 } from "node:fs";
|
|
1069
|
-
import { createRequire as createRequire2 } from "node:module";
|
|
1070
|
-
import { homedir as homedir4, platform as platform2 } from "node:os";
|
|
1071
|
-
import { join as join5 } from "node:path";
|
|
1049
|
+
};
|
|
1072
1050
|
|
|
1073
|
-
//
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
date,
|
|
1100
|
-
tool: "cursor",
|
|
1101
|
-
model: typeof e.model === "string" && e.model ? e.model : "cursor",
|
|
1102
|
-
inputTokens,
|
|
1103
|
-
outputTokens,
|
|
1104
|
-
cacheCreationTokens,
|
|
1105
|
-
cacheReadTokens,
|
|
1106
|
-
costUSD,
|
|
1107
|
-
origin: "cli",
|
|
1108
|
-
verified: false
|
|
1109
|
-
});
|
|
1110
|
-
}
|
|
1111
|
-
return out;
|
|
1112
|
-
}
|
|
1113
|
-
function resolveTokscaleBin() {
|
|
1114
|
-
try {
|
|
1115
|
-
const require3 = createRequire(import.meta.url);
|
|
1116
|
-
const pkgPath = require3.resolve("tokscale/package.json");
|
|
1117
|
-
const pkg = require3("tokscale/package.json");
|
|
1118
|
-
const rel = typeof pkg.bin === "string" ? pkg.bin : pkg.bin?.tokscale ?? "";
|
|
1119
|
-
if (!rel) return null;
|
|
1120
|
-
const binPath = join4(dirname2(pkgPath), rel);
|
|
1121
|
-
if (/\.(c|m)?js$/.test(binPath)) {
|
|
1122
|
-
return { cmd: process.execPath, prefixArgs: [binPath] };
|
|
1123
|
-
}
|
|
1124
|
-
return { cmd: binPath, prefixArgs: [] };
|
|
1125
|
-
} catch {
|
|
1126
|
-
return null;
|
|
1127
|
-
}
|
|
1128
|
-
}
|
|
1129
|
-
function runTokscaleDay(bin, day) {
|
|
1130
|
-
const res = spawnSync2(
|
|
1131
|
-
bin.cmd,
|
|
1132
|
-
[
|
|
1133
|
-
...bin.prefixArgs,
|
|
1134
|
-
"--client",
|
|
1135
|
-
"cursor",
|
|
1136
|
-
"--json",
|
|
1137
|
-
"--since",
|
|
1138
|
-
day,
|
|
1139
|
-
"--until",
|
|
1140
|
-
day,
|
|
1141
|
-
"--group-by",
|
|
1142
|
-
"model",
|
|
1143
|
-
"--no-spinner"
|
|
1144
|
-
],
|
|
1145
|
-
{ encoding: "utf8", maxBuffer: 32 * 1024 * 1024, timeout: 6e4 }
|
|
1146
|
-
);
|
|
1147
|
-
if (res.status !== 0 || !res.stdout) return null;
|
|
1148
|
-
try {
|
|
1149
|
-
return JSON.parse(res.stdout);
|
|
1150
|
-
} catch {
|
|
1151
|
-
return null;
|
|
1051
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/ZodError.js
|
|
1052
|
+
var ZodIssueCode = util.arrayToEnum([
|
|
1053
|
+
"invalid_type",
|
|
1054
|
+
"invalid_literal",
|
|
1055
|
+
"custom",
|
|
1056
|
+
"invalid_union",
|
|
1057
|
+
"invalid_union_discriminator",
|
|
1058
|
+
"invalid_enum_value",
|
|
1059
|
+
"unrecognized_keys",
|
|
1060
|
+
"invalid_arguments",
|
|
1061
|
+
"invalid_return_type",
|
|
1062
|
+
"invalid_date",
|
|
1063
|
+
"invalid_string",
|
|
1064
|
+
"too_small",
|
|
1065
|
+
"too_big",
|
|
1066
|
+
"invalid_intersection_types",
|
|
1067
|
+
"not_multiple_of",
|
|
1068
|
+
"not_finite"
|
|
1069
|
+
]);
|
|
1070
|
+
var quotelessJson = (obj) => {
|
|
1071
|
+
const json = JSON.stringify(obj, null, 2);
|
|
1072
|
+
return json.replace(/"([^"]+)":/g, "$1:");
|
|
1073
|
+
};
|
|
1074
|
+
var ZodError = class _ZodError extends Error {
|
|
1075
|
+
get errors() {
|
|
1076
|
+
return this.issues;
|
|
1152
1077
|
}
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1078
|
+
constructor(issues) {
|
|
1079
|
+
super();
|
|
1080
|
+
this.issues = [];
|
|
1081
|
+
this.addIssue = (sub) => {
|
|
1082
|
+
this.issues = [...this.issues, sub];
|
|
1083
|
+
};
|
|
1084
|
+
this.addIssues = (subs = []) => {
|
|
1085
|
+
this.issues = [...this.issues, ...subs];
|
|
1086
|
+
};
|
|
1087
|
+
const actualProto = new.target.prototype;
|
|
1088
|
+
if (Object.setPrototypeOf) {
|
|
1089
|
+
Object.setPrototypeOf(this, actualProto);
|
|
1090
|
+
} else {
|
|
1091
|
+
this.__proto__ = actualProto;
|
|
1162
1092
|
}
|
|
1093
|
+
this.name = "ZodError";
|
|
1094
|
+
this.issues = issues;
|
|
1163
1095
|
}
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1096
|
+
format(_mapper) {
|
|
1097
|
+
const mapper = _mapper || function(issue) {
|
|
1098
|
+
return issue.message;
|
|
1099
|
+
};
|
|
1100
|
+
const fieldErrors = { _errors: [] };
|
|
1101
|
+
const processError = (error) => {
|
|
1102
|
+
for (const issue of error.issues) {
|
|
1103
|
+
if (issue.code === "invalid_union") {
|
|
1104
|
+
issue.unionErrors.map(processError);
|
|
1105
|
+
} else if (issue.code === "invalid_return_type") {
|
|
1106
|
+
processError(issue.returnTypeError);
|
|
1107
|
+
} else if (issue.code === "invalid_arguments") {
|
|
1108
|
+
processError(issue.argumentsError);
|
|
1109
|
+
} else if (issue.path.length === 0) {
|
|
1110
|
+
fieldErrors._errors.push(mapper(issue));
|
|
1111
|
+
} else {
|
|
1112
|
+
let curr = fieldErrors;
|
|
1113
|
+
let i = 0;
|
|
1114
|
+
while (i < issue.path.length) {
|
|
1115
|
+
const el = issue.path[i];
|
|
1116
|
+
const terminal = i === issue.path.length - 1;
|
|
1117
|
+
if (!terminal) {
|
|
1118
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
1119
|
+
} else {
|
|
1120
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
1121
|
+
curr[el]._errors.push(mapper(issue));
|
|
1122
|
+
}
|
|
1123
|
+
curr = curr[el];
|
|
1124
|
+
i++;
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
};
|
|
1129
|
+
processError(this);
|
|
1130
|
+
return fieldErrors;
|
|
1168
1131
|
}
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
var EVENTS_URL = "https://cursor.com/api/dashboard/get-filtered-usage-events";
|
|
1174
|
-
function cursorDbPath() {
|
|
1175
|
-
const home = homedir4();
|
|
1176
|
-
const os = platform2();
|
|
1177
|
-
const p = os === "darwin" ? join5(home, "Library", "Application Support", "Cursor", "User", "globalStorage", "state.vscdb") : os === "win32" ? join5(process.env.APPDATA ?? join5(home, "AppData", "Roaming"), "Cursor", "User", "globalStorage", "state.vscdb") : join5(process.env.XDG_CONFIG_HOME ?? join5(home, ".config"), "Cursor", "User", "globalStorage", "state.vscdb");
|
|
1178
|
-
return existsSync3(p) ? p : null;
|
|
1179
|
-
}
|
|
1180
|
-
function readCursorToken(db) {
|
|
1181
|
-
const require3 = createRequire2(import.meta.url);
|
|
1182
|
-
try {
|
|
1183
|
-
const { DatabaseSync } = require3("node:sqlite");
|
|
1184
|
-
const d = new DatabaseSync(db, { readOnly: true });
|
|
1185
|
-
const row = d.prepare("SELECT value FROM ItemTable WHERE key = ?").get("cursorAuth/accessToken");
|
|
1186
|
-
d.close();
|
|
1187
|
-
if (row?.value) return String(row.value);
|
|
1188
|
-
} catch {
|
|
1132
|
+
static assert(value) {
|
|
1133
|
+
if (!(value instanceof _ZodError)) {
|
|
1134
|
+
throw new Error(`Not a ZodError: ${value}`);
|
|
1135
|
+
}
|
|
1189
1136
|
}
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
"sqlite3",
|
|
1193
|
-
[db, "SELECT value FROM ItemTable WHERE key='cursorAuth/accessToken';"],
|
|
1194
|
-
{ encoding: "utf8", timeout: 1e4 }
|
|
1195
|
-
);
|
|
1196
|
-
const out = res.stdout?.trim();
|
|
1197
|
-
if (res.status === 0 && out) return out;
|
|
1198
|
-
} catch {
|
|
1137
|
+
toString() {
|
|
1138
|
+
return this.message;
|
|
1199
1139
|
}
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
function cursorCookie(token) {
|
|
1203
|
-
try {
|
|
1204
|
-
const part = token.split(".")[1];
|
|
1205
|
-
if (!part) return null;
|
|
1206
|
-
const json = JSON.parse(
|
|
1207
|
-
Buffer.from(part, "base64url").toString("utf8")
|
|
1208
|
-
);
|
|
1209
|
-
if (!json.sub) return null;
|
|
1210
|
-
return `WorkosCursorSessionToken=${json.sub}%3A%3A${token}`;
|
|
1211
|
-
} catch {
|
|
1212
|
-
return null;
|
|
1140
|
+
get message() {
|
|
1141
|
+
return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
|
|
1213
1142
|
}
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
const v = Math.round(Number(n));
|
|
1217
|
-
return Number.isFinite(v) && v > 0 ? v : 0;
|
|
1218
|
-
}
|
|
1219
|
-
function mapCursorEvents(events) {
|
|
1220
|
-
const byDay = /* @__PURE__ */ new Map();
|
|
1221
|
-
const byHour = /* @__PURE__ */ new Map();
|
|
1222
|
-
for (const e of events) {
|
|
1223
|
-
const tu = e.tokenUsage;
|
|
1224
|
-
const ms = Number(e.timestamp);
|
|
1225
|
-
if (!tu || !Number.isFinite(ms)) continue;
|
|
1226
|
-
const d = new Date(ms);
|
|
1227
|
-
const date = d.toISOString().slice(0, 10);
|
|
1228
|
-
const model = e.model || "cursor";
|
|
1229
|
-
const input = num2(tu.inputTokens);
|
|
1230
|
-
const output = num2(tu.outputTokens);
|
|
1231
|
-
const cacheWrite = num2(tu.cacheWriteTokens);
|
|
1232
|
-
const cacheRead = num2(tu.cacheReadTokens);
|
|
1233
|
-
const cost = Math.max(0, (Number(tu.totalCents) || 0) / 100);
|
|
1234
|
-
const total = input + output + cacheWrite + cacheRead;
|
|
1235
|
-
if (total === 0 && cost === 0) continue;
|
|
1236
|
-
const key = `${date}|${model}`;
|
|
1237
|
-
const day = byDay.get(key) ?? {
|
|
1238
|
-
date,
|
|
1239
|
-
tool: "cursor",
|
|
1240
|
-
model,
|
|
1241
|
-
inputTokens: 0,
|
|
1242
|
-
outputTokens: 0,
|
|
1243
|
-
cacheCreationTokens: 0,
|
|
1244
|
-
cacheReadTokens: 0,
|
|
1245
|
-
costUSD: 0,
|
|
1246
|
-
origin: "cli",
|
|
1247
|
-
verified: false
|
|
1248
|
-
};
|
|
1249
|
-
day.inputTokens += input;
|
|
1250
|
-
day.outputTokens += output;
|
|
1251
|
-
day.cacheCreationTokens += cacheWrite;
|
|
1252
|
-
day.cacheReadTokens += cacheRead;
|
|
1253
|
-
day.costUSD += cost;
|
|
1254
|
-
byDay.set(key, day);
|
|
1255
|
-
const hour = new Date(
|
|
1256
|
-
Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate(), d.getUTCHours())
|
|
1257
|
-
).toISOString();
|
|
1258
|
-
const blk = byHour.get(hour) ?? { startTime: hour, totalTokens: 0, costUSD: 0 };
|
|
1259
|
-
blk.totalTokens += total;
|
|
1260
|
-
blk.costUSD += cost;
|
|
1261
|
-
byHour.set(hour, blk);
|
|
1143
|
+
get isEmpty() {
|
|
1144
|
+
return this.issues.length === 0;
|
|
1262
1145
|
}
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
const all = [];
|
|
1275
|
-
for (let page = 1; page <= maxPages; page++) {
|
|
1276
|
-
const res = await fetch(EVENTS_URL, {
|
|
1277
|
-
method: "POST",
|
|
1278
|
-
headers: {
|
|
1279
|
-
"Content-Type": "application/json",
|
|
1280
|
-
Origin: "https://cursor.com",
|
|
1281
|
-
Cookie: cookie
|
|
1282
|
-
},
|
|
1283
|
-
body: JSON.stringify({ page, pageSize }),
|
|
1284
|
-
signal: AbortSignal.timeout(2e4)
|
|
1285
|
-
});
|
|
1286
|
-
if (!res.ok) {
|
|
1287
|
-
throw new Error(`cursor usage page ${page} failed (HTTP ${res.status})`);
|
|
1146
|
+
flatten(mapper = (issue) => issue.message) {
|
|
1147
|
+
const fieldErrors = {};
|
|
1148
|
+
const formErrors = [];
|
|
1149
|
+
for (const sub of this.issues) {
|
|
1150
|
+
if (sub.path.length > 0) {
|
|
1151
|
+
const firstEl = sub.path[0];
|
|
1152
|
+
fieldErrors[firstEl] = fieldErrors[firstEl] || [];
|
|
1153
|
+
fieldErrors[firstEl].push(mapper(sub));
|
|
1154
|
+
} else {
|
|
1155
|
+
formErrors.push(mapper(sub));
|
|
1156
|
+
}
|
|
1288
1157
|
}
|
|
1289
|
-
|
|
1290
|
-
const batch = body.usageEventsDisplay ?? [];
|
|
1291
|
-
all.push(...batch);
|
|
1292
|
-
if (batch.length < pageSize) break;
|
|
1158
|
+
return { formErrors, fieldErrors };
|
|
1293
1159
|
}
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
async function collectCursor() {
|
|
1297
|
-
try {
|
|
1298
|
-
const db = cursorDbPath();
|
|
1299
|
-
const token = db ? readCursorToken(db) : null;
|
|
1300
|
-
const cookie = token ? cursorCookie(token) : null;
|
|
1301
|
-
if (cookie) {
|
|
1302
|
-
const events = await fetchCursorEvents(cookie);
|
|
1303
|
-
const { entries, blocks } = mapCursorEvents(events);
|
|
1304
|
-
if (entries.length > 0) return { entries, blocks, found: true };
|
|
1305
|
-
}
|
|
1306
|
-
} catch {
|
|
1307
|
-
}
|
|
1308
|
-
try {
|
|
1309
|
-
const entries = collectCursorViaTokscale();
|
|
1310
|
-
if (entries.length > 0) return { entries, blocks: [], found: true };
|
|
1311
|
-
} catch {
|
|
1160
|
+
get formErrors() {
|
|
1161
|
+
return this.flatten();
|
|
1312
1162
|
}
|
|
1313
|
-
|
|
1314
|
-
|
|
1163
|
+
};
|
|
1164
|
+
ZodError.create = (issues) => {
|
|
1165
|
+
const error = new ZodError(issues);
|
|
1166
|
+
return error;
|
|
1167
|
+
};
|
|
1315
1168
|
|
|
1316
|
-
//
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1169
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/locales/en.js
|
|
1170
|
+
var errorMap = (issue, _ctx) => {
|
|
1171
|
+
let message;
|
|
1172
|
+
switch (issue.code) {
|
|
1173
|
+
case ZodIssueCode.invalid_type:
|
|
1174
|
+
if (issue.received === ZodParsedType.undefined) {
|
|
1175
|
+
message = "Required";
|
|
1176
|
+
} else {
|
|
1177
|
+
message = `Expected ${issue.expected}, received ${issue.received}`;
|
|
1178
|
+
}
|
|
1179
|
+
break;
|
|
1180
|
+
case ZodIssueCode.invalid_literal:
|
|
1181
|
+
message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util.jsonStringifyReplacer)}`;
|
|
1182
|
+
break;
|
|
1183
|
+
case ZodIssueCode.unrecognized_keys:
|
|
1184
|
+
message = `Unrecognized key(s) in object: ${util.joinValues(issue.keys, ", ")}`;
|
|
1185
|
+
break;
|
|
1186
|
+
case ZodIssueCode.invalid_union:
|
|
1187
|
+
message = `Invalid input`;
|
|
1188
|
+
break;
|
|
1189
|
+
case ZodIssueCode.invalid_union_discriminator:
|
|
1190
|
+
message = `Invalid discriminator value. Expected ${util.joinValues(issue.options)}`;
|
|
1191
|
+
break;
|
|
1192
|
+
case ZodIssueCode.invalid_enum_value:
|
|
1193
|
+
message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`;
|
|
1194
|
+
break;
|
|
1195
|
+
case ZodIssueCode.invalid_arguments:
|
|
1196
|
+
message = `Invalid function arguments`;
|
|
1197
|
+
break;
|
|
1198
|
+
case ZodIssueCode.invalid_return_type:
|
|
1199
|
+
message = `Invalid function return type`;
|
|
1200
|
+
break;
|
|
1201
|
+
case ZodIssueCode.invalid_date:
|
|
1202
|
+
message = `Invalid date`;
|
|
1203
|
+
break;
|
|
1204
|
+
case ZodIssueCode.invalid_string:
|
|
1205
|
+
if (typeof issue.validation === "object") {
|
|
1206
|
+
if ("includes" in issue.validation) {
|
|
1207
|
+
message = `Invalid input: must include "${issue.validation.includes}"`;
|
|
1208
|
+
if (typeof issue.validation.position === "number") {
|
|
1209
|
+
message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
|
|
1210
|
+
}
|
|
1211
|
+
} else if ("startsWith" in issue.validation) {
|
|
1212
|
+
message = `Invalid input: must start with "${issue.validation.startsWith}"`;
|
|
1213
|
+
} else if ("endsWith" in issue.validation) {
|
|
1214
|
+
message = `Invalid input: must end with "${issue.validation.endsWith}"`;
|
|
1215
|
+
} else {
|
|
1216
|
+
util.assertNever(issue.validation);
|
|
1217
|
+
}
|
|
1218
|
+
} else if (issue.validation !== "regex") {
|
|
1219
|
+
message = `Invalid ${issue.validation}`;
|
|
1220
|
+
} else {
|
|
1221
|
+
message = "Invalid";
|
|
1222
|
+
}
|
|
1223
|
+
break;
|
|
1224
|
+
case ZodIssueCode.too_small:
|
|
1225
|
+
if (issue.type === "array")
|
|
1226
|
+
message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
|
|
1227
|
+
else if (issue.type === "string")
|
|
1228
|
+
message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
|
|
1229
|
+
else if (issue.type === "number")
|
|
1230
|
+
message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
|
|
1231
|
+
else if (issue.type === "bigint")
|
|
1232
|
+
message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
|
|
1233
|
+
else if (issue.type === "date")
|
|
1234
|
+
message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
|
|
1235
|
+
else
|
|
1236
|
+
message = "Invalid input";
|
|
1237
|
+
break;
|
|
1238
|
+
case ZodIssueCode.too_big:
|
|
1239
|
+
if (issue.type === "array")
|
|
1240
|
+
message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
|
|
1241
|
+
else if (issue.type === "string")
|
|
1242
|
+
message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
|
|
1243
|
+
else if (issue.type === "number")
|
|
1244
|
+
message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
|
|
1245
|
+
else if (issue.type === "bigint")
|
|
1246
|
+
message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
|
|
1247
|
+
else if (issue.type === "date")
|
|
1248
|
+
message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`;
|
|
1249
|
+
else
|
|
1250
|
+
message = "Invalid input";
|
|
1251
|
+
break;
|
|
1252
|
+
case ZodIssueCode.custom:
|
|
1253
|
+
message = `Invalid input`;
|
|
1254
|
+
break;
|
|
1255
|
+
case ZodIssueCode.invalid_intersection_types:
|
|
1256
|
+
message = `Intersection results could not be merged`;
|
|
1257
|
+
break;
|
|
1258
|
+
case ZodIssueCode.not_multiple_of:
|
|
1259
|
+
message = `Number must be a multiple of ${issue.multipleOf}`;
|
|
1260
|
+
break;
|
|
1261
|
+
case ZodIssueCode.not_finite:
|
|
1262
|
+
message = "Number must be finite";
|
|
1263
|
+
break;
|
|
1264
|
+
default:
|
|
1265
|
+
message = _ctx.defaultError;
|
|
1266
|
+
util.assertNever(issue);
|
|
1267
|
+
}
|
|
1268
|
+
return { message };
|
|
1269
|
+
};
|
|
1270
|
+
var en_default = errorMap;
|
|
1320
1271
|
|
|
1321
|
-
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/
|
|
1322
|
-
var
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
OK: () => OK,
|
|
1330
|
-
ParseStatus: () => ParseStatus,
|
|
1331
|
-
Schema: () => ZodType,
|
|
1332
|
-
ZodAny: () => ZodAny,
|
|
1333
|
-
ZodArray: () => ZodArray,
|
|
1334
|
-
ZodBigInt: () => ZodBigInt,
|
|
1335
|
-
ZodBoolean: () => ZodBoolean,
|
|
1336
|
-
ZodBranded: () => ZodBranded,
|
|
1337
|
-
ZodCatch: () => ZodCatch,
|
|
1338
|
-
ZodDate: () => ZodDate,
|
|
1339
|
-
ZodDefault: () => ZodDefault,
|
|
1340
|
-
ZodDiscriminatedUnion: () => ZodDiscriminatedUnion,
|
|
1341
|
-
ZodEffects: () => ZodEffects,
|
|
1342
|
-
ZodEnum: () => ZodEnum,
|
|
1343
|
-
ZodError: () => ZodError,
|
|
1344
|
-
ZodFirstPartyTypeKind: () => ZodFirstPartyTypeKind,
|
|
1345
|
-
ZodFunction: () => ZodFunction,
|
|
1346
|
-
ZodIntersection: () => ZodIntersection,
|
|
1347
|
-
ZodIssueCode: () => ZodIssueCode,
|
|
1348
|
-
ZodLazy: () => ZodLazy,
|
|
1349
|
-
ZodLiteral: () => ZodLiteral,
|
|
1350
|
-
ZodMap: () => ZodMap,
|
|
1351
|
-
ZodNaN: () => ZodNaN,
|
|
1352
|
-
ZodNativeEnum: () => ZodNativeEnum,
|
|
1353
|
-
ZodNever: () => ZodNever,
|
|
1354
|
-
ZodNull: () => ZodNull,
|
|
1355
|
-
ZodNullable: () => ZodNullable,
|
|
1356
|
-
ZodNumber: () => ZodNumber,
|
|
1357
|
-
ZodObject: () => ZodObject,
|
|
1358
|
-
ZodOptional: () => ZodOptional,
|
|
1359
|
-
ZodParsedType: () => ZodParsedType,
|
|
1360
|
-
ZodPipeline: () => ZodPipeline,
|
|
1361
|
-
ZodPromise: () => ZodPromise,
|
|
1362
|
-
ZodReadonly: () => ZodReadonly,
|
|
1363
|
-
ZodRecord: () => ZodRecord,
|
|
1364
|
-
ZodSchema: () => ZodType,
|
|
1365
|
-
ZodSet: () => ZodSet,
|
|
1366
|
-
ZodString: () => ZodString,
|
|
1367
|
-
ZodSymbol: () => ZodSymbol,
|
|
1368
|
-
ZodTransformer: () => ZodEffects,
|
|
1369
|
-
ZodTuple: () => ZodTuple,
|
|
1370
|
-
ZodType: () => ZodType,
|
|
1371
|
-
ZodUndefined: () => ZodUndefined,
|
|
1372
|
-
ZodUnion: () => ZodUnion,
|
|
1373
|
-
ZodUnknown: () => ZodUnknown,
|
|
1374
|
-
ZodVoid: () => ZodVoid,
|
|
1375
|
-
addIssueToContext: () => addIssueToContext,
|
|
1376
|
-
any: () => anyType,
|
|
1377
|
-
array: () => arrayType,
|
|
1378
|
-
bigint: () => bigIntType,
|
|
1379
|
-
boolean: () => booleanType,
|
|
1380
|
-
coerce: () => coerce,
|
|
1381
|
-
custom: () => custom,
|
|
1382
|
-
date: () => dateType,
|
|
1383
|
-
datetimeRegex: () => datetimeRegex,
|
|
1384
|
-
defaultErrorMap: () => en_default,
|
|
1385
|
-
discriminatedUnion: () => discriminatedUnionType,
|
|
1386
|
-
effect: () => effectsType,
|
|
1387
|
-
enum: () => enumType,
|
|
1388
|
-
function: () => functionType,
|
|
1389
|
-
getErrorMap: () => getErrorMap,
|
|
1390
|
-
getParsedType: () => getParsedType,
|
|
1391
|
-
instanceof: () => instanceOfType,
|
|
1392
|
-
intersection: () => intersectionType,
|
|
1393
|
-
isAborted: () => isAborted,
|
|
1394
|
-
isAsync: () => isAsync,
|
|
1395
|
-
isDirty: () => isDirty,
|
|
1396
|
-
isValid: () => isValid,
|
|
1397
|
-
late: () => late,
|
|
1398
|
-
lazy: () => lazyType,
|
|
1399
|
-
literal: () => literalType,
|
|
1400
|
-
makeIssue: () => makeIssue,
|
|
1401
|
-
map: () => mapType,
|
|
1402
|
-
nan: () => nanType,
|
|
1403
|
-
nativeEnum: () => nativeEnumType,
|
|
1404
|
-
never: () => neverType,
|
|
1405
|
-
null: () => nullType,
|
|
1406
|
-
nullable: () => nullableType,
|
|
1407
|
-
number: () => numberType,
|
|
1408
|
-
object: () => objectType,
|
|
1409
|
-
objectUtil: () => objectUtil,
|
|
1410
|
-
oboolean: () => oboolean,
|
|
1411
|
-
onumber: () => onumber,
|
|
1412
|
-
optional: () => optionalType,
|
|
1413
|
-
ostring: () => ostring,
|
|
1414
|
-
pipeline: () => pipelineType,
|
|
1415
|
-
preprocess: () => preprocessType,
|
|
1416
|
-
promise: () => promiseType,
|
|
1417
|
-
quotelessJson: () => quotelessJson,
|
|
1418
|
-
record: () => recordType,
|
|
1419
|
-
set: () => setType,
|
|
1420
|
-
setErrorMap: () => setErrorMap,
|
|
1421
|
-
strictObject: () => strictObjectType,
|
|
1422
|
-
string: () => stringType,
|
|
1423
|
-
symbol: () => symbolType,
|
|
1424
|
-
transformer: () => effectsType,
|
|
1425
|
-
tuple: () => tupleType,
|
|
1426
|
-
undefined: () => undefinedType,
|
|
1427
|
-
union: () => unionType,
|
|
1428
|
-
unknown: () => unknownType,
|
|
1429
|
-
util: () => util,
|
|
1430
|
-
void: () => voidType
|
|
1431
|
-
});
|
|
1272
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/errors.js
|
|
1273
|
+
var overrideErrorMap = en_default;
|
|
1274
|
+
function setErrorMap(map) {
|
|
1275
|
+
overrideErrorMap = map;
|
|
1276
|
+
}
|
|
1277
|
+
function getErrorMap() {
|
|
1278
|
+
return overrideErrorMap;
|
|
1279
|
+
}
|
|
1432
1280
|
|
|
1433
|
-
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/
|
|
1434
|
-
var
|
|
1435
|
-
|
|
1436
|
-
|
|
1281
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.js
|
|
1282
|
+
var makeIssue = (params) => {
|
|
1283
|
+
const { data, path, errorMaps, issueData } = params;
|
|
1284
|
+
const fullPath = [...path, ...issueData.path || []];
|
|
1285
|
+
const fullIssue = {
|
|
1286
|
+
...issueData,
|
|
1287
|
+
path: fullPath
|
|
1437
1288
|
};
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1289
|
+
if (issueData.message !== void 0) {
|
|
1290
|
+
return {
|
|
1291
|
+
...issueData,
|
|
1292
|
+
path: fullPath,
|
|
1293
|
+
message: issueData.message
|
|
1294
|
+
};
|
|
1443
1295
|
}
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1296
|
+
let errorMessage = "";
|
|
1297
|
+
const maps = errorMaps.filter((m) => !!m).slice().reverse();
|
|
1298
|
+
for (const map of maps) {
|
|
1299
|
+
errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
|
|
1300
|
+
}
|
|
1301
|
+
return {
|
|
1302
|
+
...issueData,
|
|
1303
|
+
path: fullPath,
|
|
1304
|
+
message: errorMessage
|
|
1451
1305
|
};
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1306
|
+
};
|
|
1307
|
+
var EMPTY_PATH = [];
|
|
1308
|
+
function addIssueToContext(ctx, issueData) {
|
|
1309
|
+
const overrideMap = getErrorMap();
|
|
1310
|
+
const issue = makeIssue({
|
|
1311
|
+
issueData,
|
|
1312
|
+
data: ctx.data,
|
|
1313
|
+
path: ctx.path,
|
|
1314
|
+
errorMaps: [
|
|
1315
|
+
ctx.common.contextualErrorMap,
|
|
1316
|
+
// contextual error map is first priority
|
|
1317
|
+
ctx.schemaErrorMap,
|
|
1318
|
+
// then schema-bound map if available
|
|
1319
|
+
overrideMap,
|
|
1320
|
+
// then global override map
|
|
1321
|
+
overrideMap === en_default ? void 0 : en_default
|
|
1322
|
+
// then global default map
|
|
1323
|
+
].filter((x) => !!x)
|
|
1324
|
+
});
|
|
1325
|
+
ctx.common.issues.push(issue);
|
|
1326
|
+
}
|
|
1327
|
+
var ParseStatus = class _ParseStatus {
|
|
1328
|
+
constructor() {
|
|
1329
|
+
this.value = "valid";
|
|
1330
|
+
}
|
|
1331
|
+
dirty() {
|
|
1332
|
+
if (this.value === "valid")
|
|
1333
|
+
this.value = "dirty";
|
|
1334
|
+
}
|
|
1335
|
+
abort() {
|
|
1336
|
+
if (this.value !== "aborted")
|
|
1337
|
+
this.value = "aborted";
|
|
1338
|
+
}
|
|
1339
|
+
static mergeArray(status, results) {
|
|
1340
|
+
const arrayValue = [];
|
|
1341
|
+
for (const s of results) {
|
|
1342
|
+
if (s.status === "aborted")
|
|
1343
|
+
return INVALID;
|
|
1344
|
+
if (s.status === "dirty")
|
|
1345
|
+
status.dirty();
|
|
1346
|
+
arrayValue.push(s.value);
|
|
1457
1347
|
}
|
|
1458
|
-
return
|
|
1459
|
-
}
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1348
|
+
return { status: status.value, value: arrayValue };
|
|
1349
|
+
}
|
|
1350
|
+
static async mergeObjectAsync(status, pairs) {
|
|
1351
|
+
const syncPairs = [];
|
|
1352
|
+
for (const pair of pairs) {
|
|
1353
|
+
const key = await pair.key;
|
|
1354
|
+
const value = await pair.value;
|
|
1355
|
+
syncPairs.push({
|
|
1356
|
+
key,
|
|
1357
|
+
value
|
|
1358
|
+
});
|
|
1359
|
+
}
|
|
1360
|
+
return _ParseStatus.mergeObjectSync(status, syncPairs);
|
|
1361
|
+
}
|
|
1362
|
+
static mergeObjectSync(status, pairs) {
|
|
1363
|
+
const finalObject = {};
|
|
1364
|
+
for (const pair of pairs) {
|
|
1365
|
+
const { key, value } = pair;
|
|
1366
|
+
if (key.status === "aborted")
|
|
1367
|
+
return INVALID;
|
|
1368
|
+
if (value.status === "aborted")
|
|
1369
|
+
return INVALID;
|
|
1370
|
+
if (key.status === "dirty")
|
|
1371
|
+
status.dirty();
|
|
1372
|
+
if (value.status === "dirty")
|
|
1373
|
+
status.dirty();
|
|
1374
|
+
if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
|
|
1375
|
+
finalObject[key.value] = value.value;
|
|
1470
1376
|
}
|
|
1471
1377
|
}
|
|
1472
|
-
return
|
|
1473
|
-
}
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1378
|
+
return { status: status.value, value: finalObject };
|
|
1379
|
+
}
|
|
1380
|
+
};
|
|
1381
|
+
var INVALID = Object.freeze({
|
|
1382
|
+
status: "aborted"
|
|
1383
|
+
});
|
|
1384
|
+
var DIRTY = (value) => ({ status: "dirty", value });
|
|
1385
|
+
var OK = (value) => ({ status: "valid", value });
|
|
1386
|
+
var isAborted = (x) => x.status === "aborted";
|
|
1387
|
+
var isDirty = (x) => x.status === "dirty";
|
|
1388
|
+
var isValid = (x) => x.status === "valid";
|
|
1389
|
+
var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
|
|
1390
|
+
|
|
1391
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/errorUtil.js
|
|
1392
|
+
var errorUtil;
|
|
1393
|
+
(function(errorUtil2) {
|
|
1394
|
+
errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
|
|
1395
|
+
errorUtil2.toString = (message) => typeof message === "string" ? message : message?.message;
|
|
1396
|
+
})(errorUtil || (errorUtil = {}));
|
|
1397
|
+
|
|
1398
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/types.js
|
|
1399
|
+
var ParseInputLazyPath = class {
|
|
1400
|
+
constructor(parent, value, path, key) {
|
|
1401
|
+
this._cachedPath = [];
|
|
1402
|
+
this.parent = parent;
|
|
1403
|
+
this.data = value;
|
|
1404
|
+
this._path = path;
|
|
1405
|
+
this._key = key;
|
|
1406
|
+
}
|
|
1407
|
+
get path() {
|
|
1408
|
+
if (!this._cachedPath.length) {
|
|
1409
|
+
if (Array.isArray(this._key)) {
|
|
1410
|
+
this._cachedPath.push(...this._path, ...this._key);
|
|
1411
|
+
} else {
|
|
1412
|
+
this._cachedPath.push(...this._path, this._key);
|
|
1413
|
+
}
|
|
1478
1414
|
}
|
|
1479
|
-
return
|
|
1480
|
-
};
|
|
1481
|
-
util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
|
|
1482
|
-
function joinValues(array, separator = " | ") {
|
|
1483
|
-
return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
|
|
1415
|
+
return this._cachedPath;
|
|
1484
1416
|
}
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1417
|
+
};
|
|
1418
|
+
var handleResult = (ctx, result) => {
|
|
1419
|
+
if (isValid(result)) {
|
|
1420
|
+
return { success: true, data: result.value };
|
|
1421
|
+
} else {
|
|
1422
|
+
if (!ctx.common.issues.length) {
|
|
1423
|
+
throw new Error("Validation failed but no issues detected.");
|
|
1489
1424
|
}
|
|
1490
|
-
return value;
|
|
1491
|
-
};
|
|
1492
|
-
})(util || (util = {}));
|
|
1493
|
-
var objectUtil;
|
|
1494
|
-
(function(objectUtil2) {
|
|
1495
|
-
objectUtil2.mergeShapes = (first, second) => {
|
|
1496
1425
|
return {
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
"string",
|
|
1505
|
-
"nan",
|
|
1506
|
-
"number",
|
|
1507
|
-
"integer",
|
|
1508
|
-
"float",
|
|
1509
|
-
"boolean",
|
|
1510
|
-
"date",
|
|
1511
|
-
"bigint",
|
|
1512
|
-
"symbol",
|
|
1513
|
-
"function",
|
|
1514
|
-
"undefined",
|
|
1515
|
-
"null",
|
|
1516
|
-
"array",
|
|
1517
|
-
"object",
|
|
1518
|
-
"unknown",
|
|
1519
|
-
"promise",
|
|
1520
|
-
"void",
|
|
1521
|
-
"never",
|
|
1522
|
-
"map",
|
|
1523
|
-
"set"
|
|
1524
|
-
]);
|
|
1525
|
-
var getParsedType = (data) => {
|
|
1526
|
-
const t = typeof data;
|
|
1527
|
-
switch (t) {
|
|
1528
|
-
case "undefined":
|
|
1529
|
-
return ZodParsedType.undefined;
|
|
1530
|
-
case "string":
|
|
1531
|
-
return ZodParsedType.string;
|
|
1532
|
-
case "number":
|
|
1533
|
-
return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
|
|
1534
|
-
case "boolean":
|
|
1535
|
-
return ZodParsedType.boolean;
|
|
1536
|
-
case "function":
|
|
1537
|
-
return ZodParsedType.function;
|
|
1538
|
-
case "bigint":
|
|
1539
|
-
return ZodParsedType.bigint;
|
|
1540
|
-
case "symbol":
|
|
1541
|
-
return ZodParsedType.symbol;
|
|
1542
|
-
case "object":
|
|
1543
|
-
if (Array.isArray(data)) {
|
|
1544
|
-
return ZodParsedType.array;
|
|
1545
|
-
}
|
|
1546
|
-
if (data === null) {
|
|
1547
|
-
return ZodParsedType.null;
|
|
1548
|
-
}
|
|
1549
|
-
if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
|
|
1550
|
-
return ZodParsedType.promise;
|
|
1551
|
-
}
|
|
1552
|
-
if (typeof Map !== "undefined" && data instanceof Map) {
|
|
1553
|
-
return ZodParsedType.map;
|
|
1554
|
-
}
|
|
1555
|
-
if (typeof Set !== "undefined" && data instanceof Set) {
|
|
1556
|
-
return ZodParsedType.set;
|
|
1557
|
-
}
|
|
1558
|
-
if (typeof Date !== "undefined" && data instanceof Date) {
|
|
1559
|
-
return ZodParsedType.date;
|
|
1426
|
+
success: false,
|
|
1427
|
+
get error() {
|
|
1428
|
+
if (this._error)
|
|
1429
|
+
return this._error;
|
|
1430
|
+
const error = new ZodError(ctx.common.issues);
|
|
1431
|
+
this._error = error;
|
|
1432
|
+
return this._error;
|
|
1560
1433
|
}
|
|
1561
|
-
|
|
1562
|
-
default:
|
|
1563
|
-
return ZodParsedType.unknown;
|
|
1434
|
+
};
|
|
1564
1435
|
}
|
|
1565
1436
|
};
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
"invalid_union",
|
|
1573
|
-
"invalid_union_discriminator",
|
|
1574
|
-
"invalid_enum_value",
|
|
1575
|
-
"unrecognized_keys",
|
|
1576
|
-
"invalid_arguments",
|
|
1577
|
-
"invalid_return_type",
|
|
1578
|
-
"invalid_date",
|
|
1579
|
-
"invalid_string",
|
|
1580
|
-
"too_small",
|
|
1581
|
-
"too_big",
|
|
1582
|
-
"invalid_intersection_types",
|
|
1583
|
-
"not_multiple_of",
|
|
1584
|
-
"not_finite"
|
|
1585
|
-
]);
|
|
1586
|
-
var quotelessJson = (obj) => {
|
|
1587
|
-
const json = JSON.stringify(obj, null, 2);
|
|
1588
|
-
return json.replace(/"([^"]+)":/g, "$1:");
|
|
1589
|
-
};
|
|
1590
|
-
var ZodError = class _ZodError extends Error {
|
|
1591
|
-
get errors() {
|
|
1592
|
-
return this.issues;
|
|
1437
|
+
function processCreateParams(params) {
|
|
1438
|
+
if (!params)
|
|
1439
|
+
return {};
|
|
1440
|
+
const { errorMap: errorMap2, invalid_type_error, required_error, description } = params;
|
|
1441
|
+
if (errorMap2 && (invalid_type_error || required_error)) {
|
|
1442
|
+
throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
|
|
1593
1443
|
}
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
this.addIssues = (subs = []) => {
|
|
1601
|
-
this.issues = [...this.issues, ...subs];
|
|
1602
|
-
};
|
|
1603
|
-
const actualProto = new.target.prototype;
|
|
1604
|
-
if (Object.setPrototypeOf) {
|
|
1605
|
-
Object.setPrototypeOf(this, actualProto);
|
|
1606
|
-
} else {
|
|
1607
|
-
this.__proto__ = actualProto;
|
|
1444
|
+
if (errorMap2)
|
|
1445
|
+
return { errorMap: errorMap2, description };
|
|
1446
|
+
const customMap = (iss, ctx) => {
|
|
1447
|
+
const { message } = params;
|
|
1448
|
+
if (iss.code === "invalid_enum_value") {
|
|
1449
|
+
return { message: message ?? ctx.defaultError };
|
|
1608
1450
|
}
|
|
1609
|
-
|
|
1610
|
-
|
|
1451
|
+
if (typeof ctx.data === "undefined") {
|
|
1452
|
+
return { message: message ?? required_error ?? ctx.defaultError };
|
|
1453
|
+
}
|
|
1454
|
+
if (iss.code !== "invalid_type")
|
|
1455
|
+
return { message: ctx.defaultError };
|
|
1456
|
+
return { message: message ?? invalid_type_error ?? ctx.defaultError };
|
|
1457
|
+
};
|
|
1458
|
+
return { errorMap: customMap, description };
|
|
1459
|
+
}
|
|
1460
|
+
var ZodType = class {
|
|
1461
|
+
get description() {
|
|
1462
|
+
return this._def.description;
|
|
1611
1463
|
}
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1464
|
+
_getType(input) {
|
|
1465
|
+
return getParsedType(input.data);
|
|
1466
|
+
}
|
|
1467
|
+
_getOrReturnCtx(input, ctx) {
|
|
1468
|
+
return ctx || {
|
|
1469
|
+
common: input.parent.common,
|
|
1470
|
+
data: input.data,
|
|
1471
|
+
parsedType: getParsedType(input.data),
|
|
1472
|
+
schemaErrorMap: this._def.errorMap,
|
|
1473
|
+
path: input.path,
|
|
1474
|
+
parent: input.parent
|
|
1615
1475
|
};
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
} else {
|
|
1628
|
-
let curr = fieldErrors;
|
|
1629
|
-
let i = 0;
|
|
1630
|
-
while (i < issue.path.length) {
|
|
1631
|
-
const el = issue.path[i];
|
|
1632
|
-
const terminal = i === issue.path.length - 1;
|
|
1633
|
-
if (!terminal) {
|
|
1634
|
-
curr[el] = curr[el] || { _errors: [] };
|
|
1635
|
-
} else {
|
|
1636
|
-
curr[el] = curr[el] || { _errors: [] };
|
|
1637
|
-
curr[el]._errors.push(mapper(issue));
|
|
1638
|
-
}
|
|
1639
|
-
curr = curr[el];
|
|
1640
|
-
i++;
|
|
1641
|
-
}
|
|
1642
|
-
}
|
|
1476
|
+
}
|
|
1477
|
+
_processInputParams(input) {
|
|
1478
|
+
return {
|
|
1479
|
+
status: new ParseStatus(),
|
|
1480
|
+
ctx: {
|
|
1481
|
+
common: input.parent.common,
|
|
1482
|
+
data: input.data,
|
|
1483
|
+
parsedType: getParsedType(input.data),
|
|
1484
|
+
schemaErrorMap: this._def.errorMap,
|
|
1485
|
+
path: input.path,
|
|
1486
|
+
parent: input.parent
|
|
1643
1487
|
}
|
|
1644
1488
|
};
|
|
1645
|
-
processError(this);
|
|
1646
|
-
return fieldErrors;
|
|
1647
1489
|
}
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1490
|
+
_parseSync(input) {
|
|
1491
|
+
const result = this._parse(input);
|
|
1492
|
+
if (isAsync(result)) {
|
|
1493
|
+
throw new Error("Synchronous parse encountered promise.");
|
|
1651
1494
|
}
|
|
1495
|
+
return result;
|
|
1652
1496
|
}
|
|
1653
|
-
|
|
1654
|
-
|
|
1497
|
+
_parseAsync(input) {
|
|
1498
|
+
const result = this._parse(input);
|
|
1499
|
+
return Promise.resolve(result);
|
|
1655
1500
|
}
|
|
1656
|
-
|
|
1657
|
-
|
|
1501
|
+
parse(data, params) {
|
|
1502
|
+
const result = this.safeParse(data, params);
|
|
1503
|
+
if (result.success)
|
|
1504
|
+
return result.data;
|
|
1505
|
+
throw result.error;
|
|
1658
1506
|
}
|
|
1659
|
-
|
|
1660
|
-
|
|
1507
|
+
safeParse(data, params) {
|
|
1508
|
+
const ctx = {
|
|
1509
|
+
common: {
|
|
1510
|
+
issues: [],
|
|
1511
|
+
async: params?.async ?? false,
|
|
1512
|
+
contextualErrorMap: params?.errorMap
|
|
1513
|
+
},
|
|
1514
|
+
path: params?.path || [],
|
|
1515
|
+
schemaErrorMap: this._def.errorMap,
|
|
1516
|
+
parent: null,
|
|
1517
|
+
data,
|
|
1518
|
+
parsedType: getParsedType(data)
|
|
1519
|
+
};
|
|
1520
|
+
const result = this._parseSync({ data, path: ctx.path, parent: ctx });
|
|
1521
|
+
return handleResult(ctx, result);
|
|
1661
1522
|
}
|
|
1662
|
-
|
|
1663
|
-
const
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1523
|
+
"~validate"(data) {
|
|
1524
|
+
const ctx = {
|
|
1525
|
+
common: {
|
|
1526
|
+
issues: [],
|
|
1527
|
+
async: !!this["~standard"].async
|
|
1528
|
+
},
|
|
1529
|
+
path: [],
|
|
1530
|
+
schemaErrorMap: this._def.errorMap,
|
|
1531
|
+
parent: null,
|
|
1532
|
+
data,
|
|
1533
|
+
parsedType: getParsedType(data)
|
|
1534
|
+
};
|
|
1535
|
+
if (!this["~standard"].async) {
|
|
1536
|
+
try {
|
|
1537
|
+
const result = this._parseSync({ data, path: [], parent: ctx });
|
|
1538
|
+
return isValid(result) ? {
|
|
1539
|
+
value: result.value
|
|
1540
|
+
} : {
|
|
1541
|
+
issues: ctx.common.issues
|
|
1542
|
+
};
|
|
1543
|
+
} catch (err) {
|
|
1544
|
+
if (err?.message?.toLowerCase()?.includes("encountered")) {
|
|
1545
|
+
this["~standard"].async = true;
|
|
1546
|
+
}
|
|
1547
|
+
ctx.common = {
|
|
1548
|
+
issues: [],
|
|
1549
|
+
async: true
|
|
1550
|
+
};
|
|
1672
1551
|
}
|
|
1673
1552
|
}
|
|
1674
|
-
return {
|
|
1553
|
+
return this._parseAsync({ data, path: [], parent: ctx }).then((result) => isValid(result) ? {
|
|
1554
|
+
value: result.value
|
|
1555
|
+
} : {
|
|
1556
|
+
issues: ctx.common.issues
|
|
1557
|
+
});
|
|
1675
1558
|
}
|
|
1676
|
-
|
|
1677
|
-
|
|
1559
|
+
async parseAsync(data, params) {
|
|
1560
|
+
const result = await this.safeParseAsync(data, params);
|
|
1561
|
+
if (result.success)
|
|
1562
|
+
return result.data;
|
|
1563
|
+
throw result.error;
|
|
1678
1564
|
}
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1565
|
+
async safeParseAsync(data, params) {
|
|
1566
|
+
const ctx = {
|
|
1567
|
+
common: {
|
|
1568
|
+
issues: [],
|
|
1569
|
+
contextualErrorMap: params?.errorMap,
|
|
1570
|
+
async: true
|
|
1571
|
+
},
|
|
1572
|
+
path: params?.path || [],
|
|
1573
|
+
schemaErrorMap: this._def.errorMap,
|
|
1574
|
+
parent: null,
|
|
1575
|
+
data,
|
|
1576
|
+
parsedType: getParsedType(data)
|
|
1577
|
+
};
|
|
1578
|
+
const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
|
|
1579
|
+
const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
|
|
1580
|
+
return handleResult(ctx, result);
|
|
1581
|
+
}
|
|
1582
|
+
refine(check, message) {
|
|
1583
|
+
const getIssueProperties = (val) => {
|
|
1584
|
+
if (typeof message === "string" || typeof message === "undefined") {
|
|
1585
|
+
return { message };
|
|
1586
|
+
} else if (typeof message === "function") {
|
|
1587
|
+
return message(val);
|
|
1692
1588
|
} else {
|
|
1693
|
-
message
|
|
1589
|
+
return message;
|
|
1694
1590
|
}
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`;
|
|
1710
|
-
break;
|
|
1711
|
-
case ZodIssueCode.invalid_arguments:
|
|
1712
|
-
message = `Invalid function arguments`;
|
|
1713
|
-
break;
|
|
1714
|
-
case ZodIssueCode.invalid_return_type:
|
|
1715
|
-
message = `Invalid function return type`;
|
|
1716
|
-
break;
|
|
1717
|
-
case ZodIssueCode.invalid_date:
|
|
1718
|
-
message = `Invalid date`;
|
|
1719
|
-
break;
|
|
1720
|
-
case ZodIssueCode.invalid_string:
|
|
1721
|
-
if (typeof issue.validation === "object") {
|
|
1722
|
-
if ("includes" in issue.validation) {
|
|
1723
|
-
message = `Invalid input: must include "${issue.validation.includes}"`;
|
|
1724
|
-
if (typeof issue.validation.position === "number") {
|
|
1725
|
-
message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
|
|
1591
|
+
};
|
|
1592
|
+
return this._refinement((val, ctx) => {
|
|
1593
|
+
const result = check(val);
|
|
1594
|
+
const setError = () => ctx.addIssue({
|
|
1595
|
+
code: ZodIssueCode.custom,
|
|
1596
|
+
...getIssueProperties(val)
|
|
1597
|
+
});
|
|
1598
|
+
if (typeof Promise !== "undefined" && result instanceof Promise) {
|
|
1599
|
+
return result.then((data) => {
|
|
1600
|
+
if (!data) {
|
|
1601
|
+
setError();
|
|
1602
|
+
return false;
|
|
1603
|
+
} else {
|
|
1604
|
+
return true;
|
|
1726
1605
|
}
|
|
1727
|
-
}
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
util.assertNever(issue.validation);
|
|
1733
|
-
}
|
|
1734
|
-
} else if (issue.validation !== "regex") {
|
|
1735
|
-
message = `Invalid ${issue.validation}`;
|
|
1606
|
+
});
|
|
1607
|
+
}
|
|
1608
|
+
if (!result) {
|
|
1609
|
+
setError();
|
|
1610
|
+
return false;
|
|
1736
1611
|
} else {
|
|
1737
|
-
|
|
1612
|
+
return true;
|
|
1738
1613
|
}
|
|
1739
|
-
|
|
1740
|
-
case ZodIssueCode.too_small:
|
|
1741
|
-
if (issue.type === "array")
|
|
1742
|
-
message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
|
|
1743
|
-
else if (issue.type === "string")
|
|
1744
|
-
message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
|
|
1745
|
-
else if (issue.type === "number")
|
|
1746
|
-
message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
|
|
1747
|
-
else if (issue.type === "bigint")
|
|
1748
|
-
message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
|
|
1749
|
-
else if (issue.type === "date")
|
|
1750
|
-
message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
|
|
1751
|
-
else
|
|
1752
|
-
message = "Invalid input";
|
|
1753
|
-
break;
|
|
1754
|
-
case ZodIssueCode.too_big:
|
|
1755
|
-
if (issue.type === "array")
|
|
1756
|
-
message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
|
|
1757
|
-
else if (issue.type === "string")
|
|
1758
|
-
message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
|
|
1759
|
-
else if (issue.type === "number")
|
|
1760
|
-
message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
|
|
1761
|
-
else if (issue.type === "bigint")
|
|
1762
|
-
message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
|
|
1763
|
-
else if (issue.type === "date")
|
|
1764
|
-
message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`;
|
|
1765
|
-
else
|
|
1766
|
-
message = "Invalid input";
|
|
1767
|
-
break;
|
|
1768
|
-
case ZodIssueCode.custom:
|
|
1769
|
-
message = `Invalid input`;
|
|
1770
|
-
break;
|
|
1771
|
-
case ZodIssueCode.invalid_intersection_types:
|
|
1772
|
-
message = `Intersection results could not be merged`;
|
|
1773
|
-
break;
|
|
1774
|
-
case ZodIssueCode.not_multiple_of:
|
|
1775
|
-
message = `Number must be a multiple of ${issue.multipleOf}`;
|
|
1776
|
-
break;
|
|
1777
|
-
case ZodIssueCode.not_finite:
|
|
1778
|
-
message = "Number must be finite";
|
|
1779
|
-
break;
|
|
1780
|
-
default:
|
|
1781
|
-
message = _ctx.defaultError;
|
|
1782
|
-
util.assertNever(issue);
|
|
1614
|
+
});
|
|
1783
1615
|
}
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
}
|
|
1793
|
-
function getErrorMap() {
|
|
1794
|
-
return overrideErrorMap;
|
|
1795
|
-
}
|
|
1796
|
-
|
|
1797
|
-
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.js
|
|
1798
|
-
var makeIssue = (params) => {
|
|
1799
|
-
const { data, path, errorMaps, issueData } = params;
|
|
1800
|
-
const fullPath = [...path, ...issueData.path || []];
|
|
1801
|
-
const fullIssue = {
|
|
1802
|
-
...issueData,
|
|
1803
|
-
path: fullPath
|
|
1804
|
-
};
|
|
1805
|
-
if (issueData.message !== void 0) {
|
|
1806
|
-
return {
|
|
1807
|
-
...issueData,
|
|
1808
|
-
path: fullPath,
|
|
1809
|
-
message: issueData.message
|
|
1810
|
-
};
|
|
1616
|
+
refinement(check, refinementData) {
|
|
1617
|
+
return this._refinement((val, ctx) => {
|
|
1618
|
+
if (!check(val)) {
|
|
1619
|
+
ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
|
|
1620
|
+
return false;
|
|
1621
|
+
} else {
|
|
1622
|
+
return true;
|
|
1623
|
+
}
|
|
1624
|
+
});
|
|
1811
1625
|
}
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1626
|
+
_refinement(refinement) {
|
|
1627
|
+
return new ZodEffects({
|
|
1628
|
+
schema: this,
|
|
1629
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
1630
|
+
effect: { type: "refinement", refinement }
|
|
1631
|
+
});
|
|
1816
1632
|
}
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
path: fullPath,
|
|
1820
|
-
message: errorMessage
|
|
1821
|
-
};
|
|
1822
|
-
};
|
|
1823
|
-
var EMPTY_PATH = [];
|
|
1824
|
-
function addIssueToContext(ctx, issueData) {
|
|
1825
|
-
const overrideMap = getErrorMap();
|
|
1826
|
-
const issue = makeIssue({
|
|
1827
|
-
issueData,
|
|
1828
|
-
data: ctx.data,
|
|
1829
|
-
path: ctx.path,
|
|
1830
|
-
errorMaps: [
|
|
1831
|
-
ctx.common.contextualErrorMap,
|
|
1832
|
-
// contextual error map is first priority
|
|
1833
|
-
ctx.schemaErrorMap,
|
|
1834
|
-
// then schema-bound map if available
|
|
1835
|
-
overrideMap,
|
|
1836
|
-
// then global override map
|
|
1837
|
-
overrideMap === en_default ? void 0 : en_default
|
|
1838
|
-
// then global default map
|
|
1839
|
-
].filter((x) => !!x)
|
|
1840
|
-
});
|
|
1841
|
-
ctx.common.issues.push(issue);
|
|
1842
|
-
}
|
|
1843
|
-
var ParseStatus = class _ParseStatus {
|
|
1844
|
-
constructor() {
|
|
1845
|
-
this.value = "valid";
|
|
1633
|
+
superRefine(refinement) {
|
|
1634
|
+
return this._refinement(refinement);
|
|
1846
1635
|
}
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1636
|
+
constructor(def) {
|
|
1637
|
+
this.spa = this.safeParseAsync;
|
|
1638
|
+
this._def = def;
|
|
1639
|
+
this.parse = this.parse.bind(this);
|
|
1640
|
+
this.safeParse = this.safeParse.bind(this);
|
|
1641
|
+
this.parseAsync = this.parseAsync.bind(this);
|
|
1642
|
+
this.safeParseAsync = this.safeParseAsync.bind(this);
|
|
1643
|
+
this.spa = this.spa.bind(this);
|
|
1644
|
+
this.refine = this.refine.bind(this);
|
|
1645
|
+
this.refinement = this.refinement.bind(this);
|
|
1646
|
+
this.superRefine = this.superRefine.bind(this);
|
|
1647
|
+
this.optional = this.optional.bind(this);
|
|
1648
|
+
this.nullable = this.nullable.bind(this);
|
|
1649
|
+
this.nullish = this.nullish.bind(this);
|
|
1650
|
+
this.array = this.array.bind(this);
|
|
1651
|
+
this.promise = this.promise.bind(this);
|
|
1652
|
+
this.or = this.or.bind(this);
|
|
1653
|
+
this.and = this.and.bind(this);
|
|
1654
|
+
this.transform = this.transform.bind(this);
|
|
1655
|
+
this.brand = this.brand.bind(this);
|
|
1656
|
+
this.default = this.default.bind(this);
|
|
1657
|
+
this.catch = this.catch.bind(this);
|
|
1658
|
+
this.describe = this.describe.bind(this);
|
|
1659
|
+
this.pipe = this.pipe.bind(this);
|
|
1660
|
+
this.readonly = this.readonly.bind(this);
|
|
1661
|
+
this.isNullable = this.isNullable.bind(this);
|
|
1662
|
+
this.isOptional = this.isOptional.bind(this);
|
|
1663
|
+
this["~standard"] = {
|
|
1664
|
+
version: 1,
|
|
1665
|
+
vendor: "zod",
|
|
1666
|
+
validate: (data) => this["~validate"](data)
|
|
1667
|
+
};
|
|
1850
1668
|
}
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
this.value = "aborted";
|
|
1669
|
+
optional() {
|
|
1670
|
+
return ZodOptional.create(this, this._def);
|
|
1854
1671
|
}
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
for (const s of results) {
|
|
1858
|
-
if (s.status === "aborted")
|
|
1859
|
-
return INVALID;
|
|
1860
|
-
if (s.status === "dirty")
|
|
1861
|
-
status.dirty();
|
|
1862
|
-
arrayValue.push(s.value);
|
|
1863
|
-
}
|
|
1864
|
-
return { status: status.value, value: arrayValue };
|
|
1672
|
+
nullable() {
|
|
1673
|
+
return ZodNullable.create(this, this._def);
|
|
1865
1674
|
}
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
for (const pair of pairs) {
|
|
1869
|
-
const key = await pair.key;
|
|
1870
|
-
const value = await pair.value;
|
|
1871
|
-
syncPairs.push({
|
|
1872
|
-
key,
|
|
1873
|
-
value
|
|
1874
|
-
});
|
|
1875
|
-
}
|
|
1876
|
-
return _ParseStatus.mergeObjectSync(status, syncPairs);
|
|
1675
|
+
nullish() {
|
|
1676
|
+
return this.nullable().optional();
|
|
1877
1677
|
}
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
for (const pair of pairs) {
|
|
1881
|
-
const { key, value } = pair;
|
|
1882
|
-
if (key.status === "aborted")
|
|
1883
|
-
return INVALID;
|
|
1884
|
-
if (value.status === "aborted")
|
|
1885
|
-
return INVALID;
|
|
1886
|
-
if (key.status === "dirty")
|
|
1887
|
-
status.dirty();
|
|
1888
|
-
if (value.status === "dirty")
|
|
1889
|
-
status.dirty();
|
|
1890
|
-
if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
|
|
1891
|
-
finalObject[key.value] = value.value;
|
|
1892
|
-
}
|
|
1893
|
-
}
|
|
1894
|
-
return { status: status.value, value: finalObject };
|
|
1678
|
+
array() {
|
|
1679
|
+
return ZodArray.create(this);
|
|
1895
1680
|
}
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
status: "aborted"
|
|
1899
|
-
});
|
|
1900
|
-
var DIRTY = (value) => ({ status: "dirty", value });
|
|
1901
|
-
var OK = (value) => ({ status: "valid", value });
|
|
1902
|
-
var isAborted = (x) => x.status === "aborted";
|
|
1903
|
-
var isDirty = (x) => x.status === "dirty";
|
|
1904
|
-
var isValid = (x) => x.status === "valid";
|
|
1905
|
-
var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
|
|
1906
|
-
|
|
1907
|
-
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/errorUtil.js
|
|
1908
|
-
var errorUtil;
|
|
1909
|
-
(function(errorUtil2) {
|
|
1910
|
-
errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
|
|
1911
|
-
errorUtil2.toString = (message) => typeof message === "string" ? message : message?.message;
|
|
1912
|
-
})(errorUtil || (errorUtil = {}));
|
|
1913
|
-
|
|
1914
|
-
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/types.js
|
|
1915
|
-
var ParseInputLazyPath = class {
|
|
1916
|
-
constructor(parent, value, path, key) {
|
|
1917
|
-
this._cachedPath = [];
|
|
1918
|
-
this.parent = parent;
|
|
1919
|
-
this.data = value;
|
|
1920
|
-
this._path = path;
|
|
1921
|
-
this._key = key;
|
|
1922
|
-
}
|
|
1923
|
-
get path() {
|
|
1924
|
-
if (!this._cachedPath.length) {
|
|
1925
|
-
if (Array.isArray(this._key)) {
|
|
1926
|
-
this._cachedPath.push(...this._path, ...this._key);
|
|
1927
|
-
} else {
|
|
1928
|
-
this._cachedPath.push(...this._path, this._key);
|
|
1929
|
-
}
|
|
1930
|
-
}
|
|
1931
|
-
return this._cachedPath;
|
|
1681
|
+
promise() {
|
|
1682
|
+
return ZodPromise.create(this, this._def);
|
|
1932
1683
|
}
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
if (isValid(result)) {
|
|
1936
|
-
return { success: true, data: result.value };
|
|
1937
|
-
} else {
|
|
1938
|
-
if (!ctx.common.issues.length) {
|
|
1939
|
-
throw new Error("Validation failed but no issues detected.");
|
|
1940
|
-
}
|
|
1941
|
-
return {
|
|
1942
|
-
success: false,
|
|
1943
|
-
get error() {
|
|
1944
|
-
if (this._error)
|
|
1945
|
-
return this._error;
|
|
1946
|
-
const error = new ZodError(ctx.common.issues);
|
|
1947
|
-
this._error = error;
|
|
1948
|
-
return this._error;
|
|
1949
|
-
}
|
|
1950
|
-
};
|
|
1684
|
+
or(option) {
|
|
1685
|
+
return ZodUnion.create([this, option], this._def);
|
|
1951
1686
|
}
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
if (!params)
|
|
1955
|
-
return {};
|
|
1956
|
-
const { errorMap: errorMap2, invalid_type_error, required_error, description } = params;
|
|
1957
|
-
if (errorMap2 && (invalid_type_error || required_error)) {
|
|
1958
|
-
throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
|
|
1687
|
+
and(incoming) {
|
|
1688
|
+
return ZodIntersection.create(this, incoming, this._def);
|
|
1959
1689
|
}
|
|
1960
|
-
|
|
1961
|
-
return {
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
}
|
|
1967
|
-
if (typeof ctx.data === "undefined") {
|
|
1968
|
-
return { message: message ?? required_error ?? ctx.defaultError };
|
|
1969
|
-
}
|
|
1970
|
-
if (iss.code !== "invalid_type")
|
|
1971
|
-
return { message: ctx.defaultError };
|
|
1972
|
-
return { message: message ?? invalid_type_error ?? ctx.defaultError };
|
|
1973
|
-
};
|
|
1974
|
-
return { errorMap: customMap, description };
|
|
1975
|
-
}
|
|
1976
|
-
var ZodType = class {
|
|
1977
|
-
get description() {
|
|
1978
|
-
return this._def.description;
|
|
1690
|
+
transform(transform) {
|
|
1691
|
+
return new ZodEffects({
|
|
1692
|
+
...processCreateParams(this._def),
|
|
1693
|
+
schema: this,
|
|
1694
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
1695
|
+
effect: { type: "transform", transform }
|
|
1696
|
+
});
|
|
1979
1697
|
}
|
|
1980
|
-
|
|
1981
|
-
|
|
1698
|
+
default(def) {
|
|
1699
|
+
const defaultValueFunc = typeof def === "function" ? def : () => def;
|
|
1700
|
+
return new ZodDefault({
|
|
1701
|
+
...processCreateParams(this._def),
|
|
1702
|
+
innerType: this,
|
|
1703
|
+
defaultValue: defaultValueFunc,
|
|
1704
|
+
typeName: ZodFirstPartyTypeKind.ZodDefault
|
|
1705
|
+
});
|
|
1982
1706
|
}
|
|
1983
|
-
|
|
1984
|
-
return
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
path: input.path,
|
|
1990
|
-
parent: input.parent
|
|
1991
|
-
};
|
|
1707
|
+
brand() {
|
|
1708
|
+
return new ZodBranded({
|
|
1709
|
+
typeName: ZodFirstPartyTypeKind.ZodBranded,
|
|
1710
|
+
type: this,
|
|
1711
|
+
...processCreateParams(this._def)
|
|
1712
|
+
});
|
|
1992
1713
|
}
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
path: input.path,
|
|
2002
|
-
parent: input.parent
|
|
2003
|
-
}
|
|
2004
|
-
};
|
|
1714
|
+
catch(def) {
|
|
1715
|
+
const catchValueFunc = typeof def === "function" ? def : () => def;
|
|
1716
|
+
return new ZodCatch({
|
|
1717
|
+
...processCreateParams(this._def),
|
|
1718
|
+
innerType: this,
|
|
1719
|
+
catchValue: catchValueFunc,
|
|
1720
|
+
typeName: ZodFirstPartyTypeKind.ZodCatch
|
|
1721
|
+
});
|
|
2005
1722
|
}
|
|
2006
|
-
|
|
2007
|
-
const
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
1723
|
+
describe(description) {
|
|
1724
|
+
const This = this.constructor;
|
|
1725
|
+
return new This({
|
|
1726
|
+
...this._def,
|
|
1727
|
+
description
|
|
1728
|
+
});
|
|
2012
1729
|
}
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
return Promise.resolve(result);
|
|
1730
|
+
pipe(target) {
|
|
1731
|
+
return ZodPipeline.create(this, target);
|
|
2016
1732
|
}
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
if (result.success)
|
|
2020
|
-
return result.data;
|
|
2021
|
-
throw result.error;
|
|
1733
|
+
readonly() {
|
|
1734
|
+
return ZodReadonly.create(this);
|
|
2022
1735
|
}
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
common: {
|
|
2026
|
-
issues: [],
|
|
2027
|
-
async: params?.async ?? false,
|
|
2028
|
-
contextualErrorMap: params?.errorMap
|
|
2029
|
-
},
|
|
2030
|
-
path: params?.path || [],
|
|
2031
|
-
schemaErrorMap: this._def.errorMap,
|
|
2032
|
-
parent: null,
|
|
2033
|
-
data,
|
|
2034
|
-
parsedType: getParsedType(data)
|
|
2035
|
-
};
|
|
2036
|
-
const result = this._parseSync({ data, path: ctx.path, parent: ctx });
|
|
2037
|
-
return handleResult(ctx, result);
|
|
1736
|
+
isOptional() {
|
|
1737
|
+
return this.safeParse(void 0).success;
|
|
2038
1738
|
}
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
common: {
|
|
2042
|
-
issues: [],
|
|
2043
|
-
async: !!this["~standard"].async
|
|
2044
|
-
},
|
|
2045
|
-
path: [],
|
|
2046
|
-
schemaErrorMap: this._def.errorMap,
|
|
2047
|
-
parent: null,
|
|
2048
|
-
data,
|
|
2049
|
-
parsedType: getParsedType(data)
|
|
2050
|
-
};
|
|
2051
|
-
if (!this["~standard"].async) {
|
|
2052
|
-
try {
|
|
2053
|
-
const result = this._parseSync({ data, path: [], parent: ctx });
|
|
2054
|
-
return isValid(result) ? {
|
|
2055
|
-
value: result.value
|
|
2056
|
-
} : {
|
|
2057
|
-
issues: ctx.common.issues
|
|
2058
|
-
};
|
|
2059
|
-
} catch (err) {
|
|
2060
|
-
if (err?.message?.toLowerCase()?.includes("encountered")) {
|
|
2061
|
-
this["~standard"].async = true;
|
|
2062
|
-
}
|
|
2063
|
-
ctx.common = {
|
|
2064
|
-
issues: [],
|
|
2065
|
-
async: true
|
|
2066
|
-
};
|
|
2067
|
-
}
|
|
2068
|
-
}
|
|
2069
|
-
return this._parseAsync({ data, path: [], parent: ctx }).then((result) => isValid(result) ? {
|
|
2070
|
-
value: result.value
|
|
2071
|
-
} : {
|
|
2072
|
-
issues: ctx.common.issues
|
|
2073
|
-
});
|
|
1739
|
+
isNullable() {
|
|
1740
|
+
return this.safeParse(null).success;
|
|
2074
1741
|
}
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
if (typeof message === "string" || typeof message === "undefined") {
|
|
2101
|
-
return { message };
|
|
2102
|
-
} else if (typeof message === "function") {
|
|
2103
|
-
return message(val);
|
|
2104
|
-
} else {
|
|
2105
|
-
return message;
|
|
2106
|
-
}
|
|
2107
|
-
};
|
|
2108
|
-
return this._refinement((val, ctx) => {
|
|
2109
|
-
const result = check(val);
|
|
2110
|
-
const setError = () => ctx.addIssue({
|
|
2111
|
-
code: ZodIssueCode.custom,
|
|
2112
|
-
...getIssueProperties(val)
|
|
2113
|
-
});
|
|
2114
|
-
if (typeof Promise !== "undefined" && result instanceof Promise) {
|
|
2115
|
-
return result.then((data) => {
|
|
2116
|
-
if (!data) {
|
|
2117
|
-
setError();
|
|
2118
|
-
return false;
|
|
2119
|
-
} else {
|
|
2120
|
-
return true;
|
|
2121
|
-
}
|
|
2122
|
-
});
|
|
2123
|
-
}
|
|
2124
|
-
if (!result) {
|
|
2125
|
-
setError();
|
|
2126
|
-
return false;
|
|
2127
|
-
} else {
|
|
2128
|
-
return true;
|
|
2129
|
-
}
|
|
2130
|
-
});
|
|
2131
|
-
}
|
|
2132
|
-
refinement(check, refinementData) {
|
|
2133
|
-
return this._refinement((val, ctx) => {
|
|
2134
|
-
if (!check(val)) {
|
|
2135
|
-
ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
|
|
2136
|
-
return false;
|
|
2137
|
-
} else {
|
|
2138
|
-
return true;
|
|
2139
|
-
}
|
|
2140
|
-
});
|
|
2141
|
-
}
|
|
2142
|
-
_refinement(refinement) {
|
|
2143
|
-
return new ZodEffects({
|
|
2144
|
-
schema: this,
|
|
2145
|
-
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
2146
|
-
effect: { type: "refinement", refinement }
|
|
2147
|
-
});
|
|
2148
|
-
}
|
|
2149
|
-
superRefine(refinement) {
|
|
2150
|
-
return this._refinement(refinement);
|
|
2151
|
-
}
|
|
2152
|
-
constructor(def) {
|
|
2153
|
-
this.spa = this.safeParseAsync;
|
|
2154
|
-
this._def = def;
|
|
2155
|
-
this.parse = this.parse.bind(this);
|
|
2156
|
-
this.safeParse = this.safeParse.bind(this);
|
|
2157
|
-
this.parseAsync = this.parseAsync.bind(this);
|
|
2158
|
-
this.safeParseAsync = this.safeParseAsync.bind(this);
|
|
2159
|
-
this.spa = this.spa.bind(this);
|
|
2160
|
-
this.refine = this.refine.bind(this);
|
|
2161
|
-
this.refinement = this.refinement.bind(this);
|
|
2162
|
-
this.superRefine = this.superRefine.bind(this);
|
|
2163
|
-
this.optional = this.optional.bind(this);
|
|
2164
|
-
this.nullable = this.nullable.bind(this);
|
|
2165
|
-
this.nullish = this.nullish.bind(this);
|
|
2166
|
-
this.array = this.array.bind(this);
|
|
2167
|
-
this.promise = this.promise.bind(this);
|
|
2168
|
-
this.or = this.or.bind(this);
|
|
2169
|
-
this.and = this.and.bind(this);
|
|
2170
|
-
this.transform = this.transform.bind(this);
|
|
2171
|
-
this.brand = this.brand.bind(this);
|
|
2172
|
-
this.default = this.default.bind(this);
|
|
2173
|
-
this.catch = this.catch.bind(this);
|
|
2174
|
-
this.describe = this.describe.bind(this);
|
|
2175
|
-
this.pipe = this.pipe.bind(this);
|
|
2176
|
-
this.readonly = this.readonly.bind(this);
|
|
2177
|
-
this.isNullable = this.isNullable.bind(this);
|
|
2178
|
-
this.isOptional = this.isOptional.bind(this);
|
|
2179
|
-
this["~standard"] = {
|
|
2180
|
-
version: 1,
|
|
2181
|
-
vendor: "zod",
|
|
2182
|
-
validate: (data) => this["~validate"](data)
|
|
2183
|
-
};
|
|
2184
|
-
}
|
|
2185
|
-
optional() {
|
|
2186
|
-
return ZodOptional.create(this, this._def);
|
|
2187
|
-
}
|
|
2188
|
-
nullable() {
|
|
2189
|
-
return ZodNullable.create(this, this._def);
|
|
2190
|
-
}
|
|
2191
|
-
nullish() {
|
|
2192
|
-
return this.nullable().optional();
|
|
2193
|
-
}
|
|
2194
|
-
array() {
|
|
2195
|
-
return ZodArray.create(this);
|
|
2196
|
-
}
|
|
2197
|
-
promise() {
|
|
2198
|
-
return ZodPromise.create(this, this._def);
|
|
2199
|
-
}
|
|
2200
|
-
or(option) {
|
|
2201
|
-
return ZodUnion.create([this, option], this._def);
|
|
2202
|
-
}
|
|
2203
|
-
and(incoming) {
|
|
2204
|
-
return ZodIntersection.create(this, incoming, this._def);
|
|
2205
|
-
}
|
|
2206
|
-
transform(transform) {
|
|
2207
|
-
return new ZodEffects({
|
|
2208
|
-
...processCreateParams(this._def),
|
|
2209
|
-
schema: this,
|
|
2210
|
-
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
2211
|
-
effect: { type: "transform", transform }
|
|
2212
|
-
});
|
|
2213
|
-
}
|
|
2214
|
-
default(def) {
|
|
2215
|
-
const defaultValueFunc = typeof def === "function" ? def : () => def;
|
|
2216
|
-
return new ZodDefault({
|
|
2217
|
-
...processCreateParams(this._def),
|
|
2218
|
-
innerType: this,
|
|
2219
|
-
defaultValue: defaultValueFunc,
|
|
2220
|
-
typeName: ZodFirstPartyTypeKind.ZodDefault
|
|
2221
|
-
});
|
|
2222
|
-
}
|
|
2223
|
-
brand() {
|
|
2224
|
-
return new ZodBranded({
|
|
2225
|
-
typeName: ZodFirstPartyTypeKind.ZodBranded,
|
|
2226
|
-
type: this,
|
|
2227
|
-
...processCreateParams(this._def)
|
|
2228
|
-
});
|
|
2229
|
-
}
|
|
2230
|
-
catch(def) {
|
|
2231
|
-
const catchValueFunc = typeof def === "function" ? def : () => def;
|
|
2232
|
-
return new ZodCatch({
|
|
2233
|
-
...processCreateParams(this._def),
|
|
2234
|
-
innerType: this,
|
|
2235
|
-
catchValue: catchValueFunc,
|
|
2236
|
-
typeName: ZodFirstPartyTypeKind.ZodCatch
|
|
2237
|
-
});
|
|
2238
|
-
}
|
|
2239
|
-
describe(description) {
|
|
2240
|
-
const This = this.constructor;
|
|
2241
|
-
return new This({
|
|
2242
|
-
...this._def,
|
|
2243
|
-
description
|
|
2244
|
-
});
|
|
2245
|
-
}
|
|
2246
|
-
pipe(target) {
|
|
2247
|
-
return ZodPipeline.create(this, target);
|
|
2248
|
-
}
|
|
2249
|
-
readonly() {
|
|
2250
|
-
return ZodReadonly.create(this);
|
|
2251
|
-
}
|
|
2252
|
-
isOptional() {
|
|
2253
|
-
return this.safeParse(void 0).success;
|
|
2254
|
-
}
|
|
2255
|
-
isNullable() {
|
|
2256
|
-
return this.safeParse(null).success;
|
|
2257
|
-
}
|
|
2258
|
-
};
|
|
2259
|
-
var cuidRegex = /^c[^\s-]{8,}$/i;
|
|
2260
|
-
var cuid2Regex = /^[0-9a-z]+$/;
|
|
2261
|
-
var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
|
|
2262
|
-
var uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i;
|
|
2263
|
-
var nanoidRegex = /^[a-z0-9_-]{21}$/i;
|
|
2264
|
-
var jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
|
|
2265
|
-
var durationRegex = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/;
|
|
2266
|
-
var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
|
|
2267
|
-
var _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
|
2268
|
-
var emojiRegex;
|
|
2269
|
-
var ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
|
|
2270
|
-
var ipv4CidrRegex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/;
|
|
2271
|
-
var ipv6Regex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;
|
|
2272
|
-
var ipv6CidrRegex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
|
|
2273
|
-
var base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
|
|
2274
|
-
var base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
|
|
2275
|
-
var dateRegexSource = `((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))`;
|
|
2276
|
-
var dateRegex = new RegExp(`^${dateRegexSource}$`);
|
|
2277
|
-
function timeRegexSource(args) {
|
|
2278
|
-
let secondsRegexSource = `[0-5]\\d`;
|
|
2279
|
-
if (args.precision) {
|
|
2280
|
-
secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}`;
|
|
2281
|
-
} else if (args.precision == null) {
|
|
2282
|
-
secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`;
|
|
1742
|
+
};
|
|
1743
|
+
var cuidRegex = /^c[^\s-]{8,}$/i;
|
|
1744
|
+
var cuid2Regex = /^[0-9a-z]+$/;
|
|
1745
|
+
var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
|
|
1746
|
+
var uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i;
|
|
1747
|
+
var nanoidRegex = /^[a-z0-9_-]{21}$/i;
|
|
1748
|
+
var jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
|
|
1749
|
+
var durationRegex = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/;
|
|
1750
|
+
var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
|
|
1751
|
+
var _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
|
1752
|
+
var emojiRegex;
|
|
1753
|
+
var ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
|
|
1754
|
+
var ipv4CidrRegex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/;
|
|
1755
|
+
var ipv6Regex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;
|
|
1756
|
+
var ipv6CidrRegex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
|
|
1757
|
+
var base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
|
|
1758
|
+
var base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
|
|
1759
|
+
var dateRegexSource = `((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))`;
|
|
1760
|
+
var dateRegex = new RegExp(`^${dateRegexSource}$`);
|
|
1761
|
+
function timeRegexSource(args) {
|
|
1762
|
+
let secondsRegexSource = `[0-5]\\d`;
|
|
1763
|
+
if (args.precision) {
|
|
1764
|
+
secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}`;
|
|
1765
|
+
} else if (args.precision == null) {
|
|
1766
|
+
secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`;
|
|
2283
1767
|
}
|
|
2284
1768
|
const secondsQuantifier = args.precision ? "+" : "?";
|
|
2285
1769
|
return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
|
|
@@ -6761,7 +6245,8 @@ var ConnectorProvider = external_exports.enum([
|
|
|
6761
6245
|
"openai-api",
|
|
6762
6246
|
"openrouter",
|
|
6763
6247
|
"google-api",
|
|
6764
|
-
"cursor"
|
|
6248
|
+
"cursor",
|
|
6249
|
+
"azure-foundry"
|
|
6765
6250
|
]);
|
|
6766
6251
|
var UsageOrigin = external_exports.enum([
|
|
6767
6252
|
"cli",
|
|
@@ -6770,6 +6255,7 @@ var UsageOrigin = external_exports.enum([
|
|
|
6770
6255
|
"openrouter",
|
|
6771
6256
|
"google-api",
|
|
6772
6257
|
"cursor",
|
|
6258
|
+
"azure-foundry",
|
|
6773
6259
|
"import"
|
|
6774
6260
|
]);
|
|
6775
6261
|
var DailyUsageEntry = external_exports.object({
|
|
@@ -6988,270 +6474,960 @@ function isCleanOrgText(input) {
|
|
|
6988
6474
|
const runs = String(input).toLowerCase().split(/[^a-z0-9@$]+/).map((run2) => run2.replace(/[0-9@$]/g, (c) => ORG_TEXT_LEET[c] ?? c).replace(/[^a-z]/g, ""));
|
|
6989
6475
|
return !runs.some((run2) => run2.length > 0 && ORG_TEXT_BLOCKLIST.has(run2));
|
|
6990
6476
|
}
|
|
6991
|
-
var SLUG_RE = /^[a-z0-9](?:[a-z0-9-]{0,30}[a-z0-9])?$/;
|
|
6992
|
-
function isValidSlug(slug) {
|
|
6993
|
-
return typeof slug === "string" && slug.length >= 2 && slug.length <= 32 && SLUG_RE.test(slug) && // Reject consecutive hyphens — the regex above permits "a--b", which makes
|
|
6994
|
-
// for confusing subdomains and is never a deliberate slug.
|
|
6995
|
-
!slug.includes("--") && !RESERVED_SLUGS.has(slug);
|
|
6477
|
+
var SLUG_RE = /^[a-z0-9](?:[a-z0-9-]{0,30}[a-z0-9])?$/;
|
|
6478
|
+
function isValidSlug(slug) {
|
|
6479
|
+
return typeof slug === "string" && slug.length >= 2 && slug.length <= 32 && SLUG_RE.test(slug) && // Reject consecutive hyphens — the regex above permits "a--b", which makes
|
|
6480
|
+
// for confusing subdomains and is never a deliberate slug.
|
|
6481
|
+
!slug.includes("--") && !RESERVED_SLUGS.has(slug);
|
|
6482
|
+
}
|
|
6483
|
+
var OrgSlug = external_exports.string().min(2).max(32).refine(isValidSlug, "invalid or reserved slug").refine(isCleanOrgText, "invalid or reserved slug");
|
|
6484
|
+
var OrgWindow = external_exports.object({
|
|
6485
|
+
startDate: DateString.nullable().optional(),
|
|
6486
|
+
endDate: DateString.nullable().optional()
|
|
6487
|
+
}).refine((w) => !(w.startDate && w.endDate) || w.endDate >= w.startDate, { message: "endDate must be on or after startDate", path: ["endDate"] });
|
|
6488
|
+
var OrgJoinPolicy = external_exports.object({
|
|
6489
|
+
allowCodeJoin: external_exports.boolean().default(true),
|
|
6490
|
+
allowDomainJoin: external_exports.boolean().default(false),
|
|
6491
|
+
/** Verified email domains that auto-join, e.g. ["acme.com"]. */
|
|
6492
|
+
emailDomains: external_exports.array(external_exports.string().min(3).max(253).toLowerCase()).max(20).default([])
|
|
6493
|
+
});
|
|
6494
|
+
var OrgApplicationInput = external_exports.object({
|
|
6495
|
+
type: OrgType,
|
|
6496
|
+
orgName: external_exports.string().min(1).max(120),
|
|
6497
|
+
desiredSlug: external_exports.string().min(2).max(32).optional(),
|
|
6498
|
+
contactName: external_exports.string().min(1).max(120),
|
|
6499
|
+
contactEmail: external_exports.string().email().max(254),
|
|
6500
|
+
website: external_exports.string().url().max(300).optional(),
|
|
6501
|
+
/** Rough headcount / attendee estimate, free text. */
|
|
6502
|
+
size: external_exports.string().max(60).optional(),
|
|
6503
|
+
message: external_exports.string().max(2e3).optional()
|
|
6504
|
+
});
|
|
6505
|
+
var OrgProvisionInput = external_exports.object({
|
|
6506
|
+
/** When provisioning straight from an application. */
|
|
6507
|
+
applicationId: external_exports.string().min(1).max(64).optional(),
|
|
6508
|
+
slug: OrgSlug,
|
|
6509
|
+
name: external_exports.string().min(1).max(120),
|
|
6510
|
+
type: OrgType,
|
|
6511
|
+
/** Handle (or email) of the user who becomes Owner. */
|
|
6512
|
+
ownerHandle: external_exports.string().min(1).max(120).optional(),
|
|
6513
|
+
ownerEmail: external_exports.string().email().max(254).optional(),
|
|
6514
|
+
description: external_exports.string().max(2e3).optional(),
|
|
6515
|
+
boardVisibility: OrgBoardVisibility.optional(),
|
|
6516
|
+
window: OrgWindow.optional(),
|
|
6517
|
+
/** Brand accent applied to the org homepage theming. */
|
|
6518
|
+
accentColor: HexColor.optional(),
|
|
6519
|
+
/**
|
|
6520
|
+
* Create the org UNOWNED and mint a one-time owner-claim ("admin sign-in")
|
|
6521
|
+
* token in the same call. The first person to open the link + sign in becomes
|
|
6522
|
+
* the owner; the token is then consumed. When set, an owner email/handle is
|
|
6523
|
+
* NOT required — the link is how the first admin is assigned.
|
|
6524
|
+
*/
|
|
6525
|
+
issueClaimLink: external_exports.boolean().optional()
|
|
6526
|
+
});
|
|
6527
|
+
var OrgSelfServeInput = external_exports.object({
|
|
6528
|
+
slug: OrgSlug,
|
|
6529
|
+
name: external_exports.string().min(1).max(120).refine(isCleanOrgText, "name not allowed"),
|
|
6530
|
+
type: OrgType,
|
|
6531
|
+
description: external_exports.string().max(2e3).optional(),
|
|
6532
|
+
accentColor: HexColor.optional(),
|
|
6533
|
+
/** Who can view the board — defaults to the type's default when omitted. */
|
|
6534
|
+
boardVisibility: OrgBoardVisibility.optional(),
|
|
6535
|
+
/** Optional event window (mainly for hackathons). */
|
|
6536
|
+
window: OrgWindow.optional()
|
|
6537
|
+
});
|
|
6538
|
+
var OrgSettingsInput = external_exports.object({
|
|
6539
|
+
name: external_exports.string().min(1).max(120).optional(),
|
|
6540
|
+
description: external_exports.string().max(2e3).nullable().optional(),
|
|
6541
|
+
accentColor: HexColor.optional(),
|
|
6542
|
+
boardVisibility: OrgBoardVisibility.optional(),
|
|
6543
|
+
window: OrgWindow.optional(),
|
|
6544
|
+
joinPolicy: OrgJoinPolicy.partial().optional()
|
|
6545
|
+
});
|
|
6546
|
+
var OrgJoinInput = external_exports.object({
|
|
6547
|
+
/** Required only when joining via a code; domain/admin joins omit it. */
|
|
6548
|
+
code: external_exports.string().min(1).max(64).optional()
|
|
6549
|
+
});
|
|
6550
|
+
|
|
6551
|
+
// src/native/file-cache.ts
|
|
6552
|
+
import { mkdirSync as mkdirSync3, renameSync as renameSync3, writeFileSync as writeFileSync3 } from "node:fs";
|
|
6553
|
+
import { readFile, stat } from "node:fs/promises";
|
|
6554
|
+
import { dirname as dirname2, join as join3 } from "node:path";
|
|
6555
|
+
function nativeCachePath(reader, env = process.env) {
|
|
6556
|
+
const override = env.WHOBURNEDMORE_CONFIG_DIR?.trim();
|
|
6557
|
+
const dir = override || defaultConfigDir();
|
|
6558
|
+
return join3(dir, `native-cache-${reader}.json`);
|
|
6559
|
+
}
|
|
6560
|
+
async function loadCache(path, version) {
|
|
6561
|
+
try {
|
|
6562
|
+
const raw = await readFile(path, "utf8");
|
|
6563
|
+
const parsed = JSON.parse(raw);
|
|
6564
|
+
if (parsed && parsed.v === version && parsed.files && typeof parsed.files === "object") {
|
|
6565
|
+
return parsed.files;
|
|
6566
|
+
}
|
|
6567
|
+
} catch {
|
|
6568
|
+
}
|
|
6569
|
+
return {};
|
|
6570
|
+
}
|
|
6571
|
+
function saveCache(path, version, files) {
|
|
6572
|
+
try {
|
|
6573
|
+
mkdirSync3(dirname2(path), { recursive: true });
|
|
6574
|
+
const tmp = `${path}.tmp-${process.pid}`;
|
|
6575
|
+
writeFileSync3(tmp, JSON.stringify({ v: version, files }));
|
|
6576
|
+
renameSync3(tmp, path);
|
|
6577
|
+
} catch {
|
|
6578
|
+
}
|
|
6579
|
+
}
|
|
6580
|
+
async function readFilesWithCache(opts) {
|
|
6581
|
+
const now = opts.now ?? Date.now;
|
|
6582
|
+
const cached = await loadCache(opts.cachePath, opts.version);
|
|
6583
|
+
const fresh = {};
|
|
6584
|
+
const itemsByFile = [];
|
|
6585
|
+
let filesRead = 0;
|
|
6586
|
+
for (const f of opts.files) {
|
|
6587
|
+
let size;
|
|
6588
|
+
let mtimeMs;
|
|
6589
|
+
try {
|
|
6590
|
+
const s = await stat(f);
|
|
6591
|
+
size = s.size;
|
|
6592
|
+
mtimeMs = s.mtimeMs;
|
|
6593
|
+
} catch {
|
|
6594
|
+
continue;
|
|
6595
|
+
}
|
|
6596
|
+
const hit = cached[f];
|
|
6597
|
+
if (hit && hit.size === size && hit.mtimeMs === mtimeMs) {
|
|
6598
|
+
fresh[f] = hit;
|
|
6599
|
+
itemsByFile.push(hit.items);
|
|
6600
|
+
continue;
|
|
6601
|
+
}
|
|
6602
|
+
if (now() > opts.deadline) {
|
|
6603
|
+
saveCache(opts.cachePath, opts.version, { ...cached, ...fresh });
|
|
6604
|
+
return { itemsByFile: null, filesRead, timedOut: true };
|
|
6605
|
+
}
|
|
6606
|
+
let content;
|
|
6607
|
+
try {
|
|
6608
|
+
content = await readFile(f, "utf8");
|
|
6609
|
+
} catch {
|
|
6610
|
+
continue;
|
|
6611
|
+
}
|
|
6612
|
+
const items = opts.parseFile(content, f);
|
|
6613
|
+
fresh[f] = { size, mtimeMs, items };
|
|
6614
|
+
itemsByFile.push(items);
|
|
6615
|
+
filesRead += 1;
|
|
6616
|
+
}
|
|
6617
|
+
saveCache(opts.cachePath, opts.version, fresh);
|
|
6618
|
+
return { itemsByFile, filesRead, timedOut: false };
|
|
6619
|
+
}
|
|
6620
|
+
|
|
6621
|
+
// src/native/claude.ts
|
|
6622
|
+
function num(n) {
|
|
6623
|
+
const v = Math.round(Number(n));
|
|
6624
|
+
return Number.isFinite(v) && v > 0 ? v : 0;
|
|
6625
|
+
}
|
|
6626
|
+
function reqTokens(r) {
|
|
6627
|
+
return r.inputTokens + r.outputTokens + r.cacheCreationTokens + r.cacheReadTokens;
|
|
6628
|
+
}
|
|
6629
|
+
function localDate(iso) {
|
|
6630
|
+
const t = Date.parse(iso);
|
|
6631
|
+
if (!Number.isFinite(t)) return null;
|
|
6632
|
+
const d = new Date(t);
|
|
6633
|
+
const y = d.getFullYear();
|
|
6634
|
+
const m = String(d.getMonth() + 1).padStart(2, "0");
|
|
6635
|
+
const day = String(d.getDate()).padStart(2, "0");
|
|
6636
|
+
return `${y}-${m}-${day}`;
|
|
6637
|
+
}
|
|
6638
|
+
var syntheticCounter = 0;
|
|
6639
|
+
function parseClaudeLine(raw) {
|
|
6640
|
+
const trimmed = raw.trim();
|
|
6641
|
+
if (!trimmed) return null;
|
|
6642
|
+
let obj;
|
|
6643
|
+
try {
|
|
6644
|
+
obj = JSON.parse(trimmed);
|
|
6645
|
+
} catch {
|
|
6646
|
+
return null;
|
|
6647
|
+
}
|
|
6648
|
+
const message = obj.message;
|
|
6649
|
+
if (!message || typeof message !== "object") return null;
|
|
6650
|
+
const usage = message.usage;
|
|
6651
|
+
if (!usage || typeof usage !== "object") return null;
|
|
6652
|
+
if (message.role !== void 0 && message.role !== "assistant") return null;
|
|
6653
|
+
const date = localDate(String(obj.timestamp ?? ""));
|
|
6654
|
+
if (!date) return null;
|
|
6655
|
+
const tsParsed = Date.parse(String(obj.timestamp ?? ""));
|
|
6656
|
+
const ts = Number.isFinite(tsParsed) ? tsParsed : 0;
|
|
6657
|
+
const messageId = typeof message.id === "string" ? message.id : "";
|
|
6658
|
+
const requestId = typeof obj.requestId === "string" ? obj.requestId : "";
|
|
6659
|
+
const hasRealId = messageId !== "" || requestId !== "";
|
|
6660
|
+
const key = hasRealId ? `${messageId}|${requestId}` : `synthetic|${date}|${syntheticCounter += 1}`;
|
|
6661
|
+
return {
|
|
6662
|
+
key,
|
|
6663
|
+
hasRealId,
|
|
6664
|
+
date,
|
|
6665
|
+
ts,
|
|
6666
|
+
model: typeof message.model === "string" ? message.model : "unknown",
|
|
6667
|
+
inputTokens: num(usage.input_tokens),
|
|
6668
|
+
outputTokens: num(usage.output_tokens),
|
|
6669
|
+
cacheCreationTokens: num(usage.cache_creation_input_tokens),
|
|
6670
|
+
cacheReadTokens: num(usage.cache_read_input_tokens)
|
|
6671
|
+
};
|
|
6672
|
+
}
|
|
6673
|
+
function accumulateClaudeLines(acc, lines) {
|
|
6674
|
+
for (const line of lines) {
|
|
6675
|
+
const r = parseClaudeLine(line);
|
|
6676
|
+
if (!r) continue;
|
|
6677
|
+
const prev = acc.get(r.key);
|
|
6678
|
+
if (!prev || reqTokens(r) > reqTokens(prev)) acc.set(r.key, r);
|
|
6679
|
+
}
|
|
6680
|
+
}
|
|
6681
|
+
function finalizeClaudeEntries(acc) {
|
|
6682
|
+
const byDayModel = /* @__PURE__ */ new Map();
|
|
6683
|
+
for (const r of acc.values()) {
|
|
6684
|
+
const k = `${r.date}|${r.model}`;
|
|
6685
|
+
let b = byDayModel.get(k);
|
|
6686
|
+
if (!b) {
|
|
6687
|
+
b = {
|
|
6688
|
+
date: r.date,
|
|
6689
|
+
model: r.model,
|
|
6690
|
+
inputTokens: 0,
|
|
6691
|
+
outputTokens: 0,
|
|
6692
|
+
cacheCreationTokens: 0,
|
|
6693
|
+
cacheReadTokens: 0,
|
|
6694
|
+
requestCount: 0
|
|
6695
|
+
};
|
|
6696
|
+
byDayModel.set(k, b);
|
|
6697
|
+
}
|
|
6698
|
+
b.inputTokens += r.inputTokens;
|
|
6699
|
+
b.outputTokens += r.outputTokens;
|
|
6700
|
+
b.cacheCreationTokens += r.cacheCreationTokens;
|
|
6701
|
+
b.cacheReadTokens += r.cacheReadTokens;
|
|
6702
|
+
if (r.hasRealId) b.requestCount += 1;
|
|
6703
|
+
}
|
|
6704
|
+
const entries = [];
|
|
6705
|
+
for (const b of byDayModel.values()) {
|
|
6706
|
+
const tokens = b.inputTokens + b.outputTokens + b.cacheCreationTokens + b.cacheReadTokens;
|
|
6707
|
+
if (tokens === 0) continue;
|
|
6708
|
+
entries.push({
|
|
6709
|
+
date: b.date,
|
|
6710
|
+
tool: "claude",
|
|
6711
|
+
model: b.model,
|
|
6712
|
+
inputTokens: b.inputTokens,
|
|
6713
|
+
outputTokens: b.outputTokens,
|
|
6714
|
+
cacheCreationTokens: b.cacheCreationTokens,
|
|
6715
|
+
cacheReadTokens: b.cacheReadTokens,
|
|
6716
|
+
costUSD: estimateCostUSD(b.model, b),
|
|
6717
|
+
origin: "cli",
|
|
6718
|
+
verified: false,
|
|
6719
|
+
requestCount: b.requestCount
|
|
6720
|
+
});
|
|
6721
|
+
}
|
|
6722
|
+
return entries;
|
|
6723
|
+
}
|
|
6724
|
+
function resolveClaudeConfigRoots(env = process.env) {
|
|
6725
|
+
const override = env.CLAUDE_CONFIG_DIR;
|
|
6726
|
+
return override ? override.split(",").map((s) => s.trim()).filter(Boolean) : [join4(homedir3(), ".claude"), join4(homedir3(), ".config", "claude")];
|
|
6727
|
+
}
|
|
6728
|
+
function resolveClaudeProjectDirs(env = process.env) {
|
|
6729
|
+
return resolveClaudeConfigRoots(env).map((r) => join4(r, "projects"));
|
|
6730
|
+
}
|
|
6731
|
+
async function listJsonl(dir) {
|
|
6732
|
+
let dirents;
|
|
6733
|
+
try {
|
|
6734
|
+
dirents = await readdir(dir, { withFileTypes: true });
|
|
6735
|
+
} catch {
|
|
6736
|
+
return [];
|
|
6737
|
+
}
|
|
6738
|
+
const out = [];
|
|
6739
|
+
for (const d of dirents) {
|
|
6740
|
+
const full = join4(dir, d.name);
|
|
6741
|
+
if (d.isDirectory()) {
|
|
6742
|
+
out.push(...await listJsonl(full));
|
|
6743
|
+
} else if (d.isFile() && d.name.endsWith(".jsonl")) {
|
|
6744
|
+
out.push(full);
|
|
6745
|
+
}
|
|
6746
|
+
}
|
|
6747
|
+
return out;
|
|
6748
|
+
}
|
|
6749
|
+
var NATIVE_READ_BUDGET_MS = 45e3;
|
|
6750
|
+
var CLAUDE_CACHE_VERSION = 1;
|
|
6751
|
+
function toCached(r) {
|
|
6752
|
+
return [
|
|
6753
|
+
r.key,
|
|
6754
|
+
r.hasRealId ? 1 : 0,
|
|
6755
|
+
r.date,
|
|
6756
|
+
r.model,
|
|
6757
|
+
r.inputTokens,
|
|
6758
|
+
r.outputTokens,
|
|
6759
|
+
r.cacheCreationTokens,
|
|
6760
|
+
r.cacheReadTokens
|
|
6761
|
+
];
|
|
6762
|
+
}
|
|
6763
|
+
function fromCached(t) {
|
|
6764
|
+
return {
|
|
6765
|
+
key: t[0],
|
|
6766
|
+
hasRealId: t[1] === 1,
|
|
6767
|
+
date: t[2],
|
|
6768
|
+
ts: 0,
|
|
6769
|
+
model: t[3],
|
|
6770
|
+
inputTokens: t[4],
|
|
6771
|
+
outputTokens: t[5],
|
|
6772
|
+
cacheCreationTokens: t[6],
|
|
6773
|
+
cacheReadTokens: t[7]
|
|
6774
|
+
};
|
|
6775
|
+
}
|
|
6776
|
+
function parseFileToCache(content, path) {
|
|
6777
|
+
const acc = /* @__PURE__ */ new Map();
|
|
6778
|
+
accumulateClaudeLines(acc, splitLines(content));
|
|
6779
|
+
let synIndex = 0;
|
|
6780
|
+
return [...acc.values()].map(
|
|
6781
|
+
(r) => toCached(
|
|
6782
|
+
r.hasRealId ? r : { ...r, key: `synthetic|${path}|${synIndex += 1}` }
|
|
6783
|
+
)
|
|
6784
|
+
);
|
|
6785
|
+
}
|
|
6786
|
+
function* splitLines(content) {
|
|
6787
|
+
let start = 0;
|
|
6788
|
+
for (let i = 0; i < content.length; i++) {
|
|
6789
|
+
if (content[i] === "\n") {
|
|
6790
|
+
yield content.slice(start, i);
|
|
6791
|
+
start = i + 1;
|
|
6792
|
+
}
|
|
6793
|
+
}
|
|
6794
|
+
if (start < content.length) yield content.slice(start);
|
|
6795
|
+
}
|
|
6796
|
+
async function collectClaudeNative(env = process.env, opts = {}) {
|
|
6797
|
+
const dirs = resolveClaudeProjectDirs(env);
|
|
6798
|
+
const files = [];
|
|
6799
|
+
for (const dir of dirs) files.push(...await listJsonl(dir));
|
|
6800
|
+
if (files.length === 0) return { entries: [], found: false, filesScanned: 0 };
|
|
6801
|
+
const now = opts.now ?? Date.now;
|
|
6802
|
+
const res = await readFilesWithCache({
|
|
6803
|
+
files,
|
|
6804
|
+
cachePath: opts.cachePath ?? nativeCachePath("claude", env),
|
|
6805
|
+
version: CLAUDE_CACHE_VERSION,
|
|
6806
|
+
parseFile: parseFileToCache,
|
|
6807
|
+
deadline: now() + (opts.budgetMs ?? NATIVE_READ_BUDGET_MS),
|
|
6808
|
+
now
|
|
6809
|
+
});
|
|
6810
|
+
if (!res.itemsByFile) {
|
|
6811
|
+
return {
|
|
6812
|
+
entries: [],
|
|
6813
|
+
found: false,
|
|
6814
|
+
filesScanned: res.filesRead,
|
|
6815
|
+
timedOut: true
|
|
6816
|
+
};
|
|
6817
|
+
}
|
|
6818
|
+
const acc = /* @__PURE__ */ new Map();
|
|
6819
|
+
for (const items of res.itemsByFile) {
|
|
6820
|
+
for (const t of items) {
|
|
6821
|
+
const r = fromCached(t);
|
|
6822
|
+
const prev = acc.get(r.key);
|
|
6823
|
+
if (!prev || reqTokens(r) > reqTokens(prev)) acc.set(r.key, r);
|
|
6824
|
+
}
|
|
6825
|
+
}
|
|
6826
|
+
return {
|
|
6827
|
+
entries: finalizeClaudeEntries(acc),
|
|
6828
|
+
found: true,
|
|
6829
|
+
filesScanned: res.filesRead
|
|
6830
|
+
};
|
|
6831
|
+
}
|
|
6832
|
+
async function collectClaudeRequests(env = process.env, opts = {}) {
|
|
6833
|
+
const dirs = resolveClaudeProjectDirs(env);
|
|
6834
|
+
const files = [];
|
|
6835
|
+
for (const dir of dirs) files.push(...await listJsonl(dir));
|
|
6836
|
+
if (files.length === 0) return { requests: [], found: false };
|
|
6837
|
+
const now = opts.now ?? Date.now;
|
|
6838
|
+
const deadline = now() + (opts.budgetMs ?? NATIVE_READ_BUDGET_MS);
|
|
6839
|
+
const acc = /* @__PURE__ */ new Map();
|
|
6840
|
+
for (const f of files) {
|
|
6841
|
+
if (now() > deadline) {
|
|
6842
|
+
return { requests: [...acc.values()], found: true, timedOut: true };
|
|
6843
|
+
}
|
|
6844
|
+
let content;
|
|
6845
|
+
try {
|
|
6846
|
+
content = await readFile2(f, "utf8");
|
|
6847
|
+
} catch {
|
|
6848
|
+
continue;
|
|
6849
|
+
}
|
|
6850
|
+
accumulateClaudeLines(acc, splitLines(content));
|
|
6851
|
+
}
|
|
6852
|
+
return { requests: [...acc.values()], found: true };
|
|
6853
|
+
}
|
|
6854
|
+
|
|
6855
|
+
// src/attribution.ts
|
|
6856
|
+
var CLAUDE_PROJECTS = join5(homedir4(), ".claude", "projects");
|
|
6857
|
+
var CODEX_SESSIONS = join5(homedir4(), ".codex", "sessions");
|
|
6858
|
+
var MAX_FILES = 5e3;
|
|
6859
|
+
var TIME_BUDGET_MS = NATIVE_READ_BUDGET_MS;
|
|
6860
|
+
var ATTRIBUTION_CACHE_VERSION = 1;
|
|
6861
|
+
var MAX_STATS = 300;
|
|
6862
|
+
function createAccumulator() {
|
|
6863
|
+
return {
|
|
6864
|
+
tools: /* @__PURE__ */ new Map(),
|
|
6865
|
+
skills: /* @__PURE__ */ new Map(),
|
|
6866
|
+
agent: {
|
|
6867
|
+
messageCount: 0,
|
|
6868
|
+
subagentMessages: 0,
|
|
6869
|
+
subagentTokens: 0,
|
|
6870
|
+
totalTokens: 0,
|
|
6871
|
+
userMessageCount: 0
|
|
6872
|
+
},
|
|
6873
|
+
sessionMessages: /* @__PURE__ */ new Map()
|
|
6874
|
+
};
|
|
6875
|
+
}
|
|
6876
|
+
function createFileContext() {
|
|
6877
|
+
return { toolNames: /* @__PURE__ */ new Map() };
|
|
6878
|
+
}
|
|
6879
|
+
function recordTokens(usage) {
|
|
6880
|
+
if (!usage || typeof usage !== "object") return 0;
|
|
6881
|
+
const u = usage;
|
|
6882
|
+
const n = (v) => {
|
|
6883
|
+
const x = Math.round(Number(v));
|
|
6884
|
+
return Number.isFinite(x) && x > 0 ? x : 0;
|
|
6885
|
+
};
|
|
6886
|
+
return n(u.input_tokens) + n(u.output_tokens) + n(u.cache_creation_input_tokens) + n(u.cache_read_input_tokens);
|
|
6887
|
+
}
|
|
6888
|
+
function hasHumanText(content) {
|
|
6889
|
+
const isHuman = (t) => {
|
|
6890
|
+
const s = t.trim();
|
|
6891
|
+
return s.length > 0 && !s.startsWith("<system-reminder") && !s.startsWith("<command-") && !s.startsWith("Caveat:");
|
|
6892
|
+
};
|
|
6893
|
+
if (typeof content === "string") return isHuman(content);
|
|
6894
|
+
if (!Array.isArray(content)) return false;
|
|
6895
|
+
return content.some(
|
|
6896
|
+
(b) => b !== null && typeof b === "object" && b.type === "text" && typeof b.text === "string" && isHuman(b.text)
|
|
6897
|
+
);
|
|
6898
|
+
}
|
|
6899
|
+
function processRecord(rec, acc, ctx) {
|
|
6900
|
+
if (!rec || typeof rec !== "object") return;
|
|
6901
|
+
const r = rec;
|
|
6902
|
+
const recTokens = recordTokens(r.message?.usage);
|
|
6903
|
+
if ((r.type === "user" || r.message?.role === "user") && r.isSidechain !== true && r.isMeta !== true && hasHumanText(r.message?.content)) {
|
|
6904
|
+
acc.agent.userMessageCount += 1;
|
|
6905
|
+
}
|
|
6906
|
+
if (typeof r.attributionSkill === "string" && r.attributionSkill) {
|
|
6907
|
+
const s = r.attributionSkill.slice(0, 128);
|
|
6908
|
+
const sk = acc.skills.get(s) ?? { count: 0, tokens: 0 };
|
|
6909
|
+
sk.count += 1;
|
|
6910
|
+
sk.tokens += recTokens;
|
|
6911
|
+
acc.skills.set(s, sk);
|
|
6912
|
+
}
|
|
6913
|
+
const content = r.message?.content;
|
|
6914
|
+
if (!Array.isArray(content)) return;
|
|
6915
|
+
const isAssistant = r.type === "assistant" || r.message?.role === "assistant";
|
|
6916
|
+
const isUser = r.type === "user" || r.message?.role === "user";
|
|
6917
|
+
if (isAssistant) {
|
|
6918
|
+
const toolUses = [];
|
|
6919
|
+
for (const block of content) {
|
|
6920
|
+
if (block && typeof block === "object" && block.type === "tool_use" && typeof block.name === "string") {
|
|
6921
|
+
const name = block.name.slice(0, 128);
|
|
6922
|
+
if (!name) continue;
|
|
6923
|
+
const id = block.id;
|
|
6924
|
+
toolUses.push({ name, id: typeof id === "string" ? id : void 0 });
|
|
6925
|
+
}
|
|
6926
|
+
}
|
|
6927
|
+
const perToolTokens = toolUses.length > 0 ? Math.floor(recTokens / toolUses.length) : 0;
|
|
6928
|
+
for (const tu of toolUses) {
|
|
6929
|
+
const t = acc.tools.get(tu.name) ?? { count: 0, errors: 0, tokens: 0 };
|
|
6930
|
+
t.count += 1;
|
|
6931
|
+
t.tokens += perToolTokens;
|
|
6932
|
+
acc.tools.set(tu.name, t);
|
|
6933
|
+
if (tu.id) ctx.toolNames.set(tu.id, tu.name);
|
|
6934
|
+
}
|
|
6935
|
+
const tokens = recTokens;
|
|
6936
|
+
acc.agent.messageCount += 1;
|
|
6937
|
+
acc.agent.totalTokens += tokens;
|
|
6938
|
+
const sidechain = r.isSidechain === true;
|
|
6939
|
+
if (sidechain) {
|
|
6940
|
+
acc.agent.subagentMessages += 1;
|
|
6941
|
+
acc.agent.subagentTokens += tokens;
|
|
6942
|
+
}
|
|
6943
|
+
if (typeof r.sessionId === "string" && r.sessionId) {
|
|
6944
|
+
acc.sessionMessages.set(
|
|
6945
|
+
r.sessionId,
|
|
6946
|
+
(acc.sessionMessages.get(r.sessionId) ?? 0) + 1
|
|
6947
|
+
);
|
|
6948
|
+
}
|
|
6949
|
+
} else if (isUser) {
|
|
6950
|
+
for (const block of content) {
|
|
6951
|
+
if (block && typeof block === "object" && block.type === "tool_result" && block.is_error === true) {
|
|
6952
|
+
const id = block.tool_use_id;
|
|
6953
|
+
const name = typeof id === "string" ? ctx.toolNames.get(id) : void 0;
|
|
6954
|
+
if (name) {
|
|
6955
|
+
const t = acc.tools.get(name) ?? { count: 0, errors: 0, tokens: 0 };
|
|
6956
|
+
t.errors += 1;
|
|
6957
|
+
acc.tools.set(name, t);
|
|
6958
|
+
}
|
|
6959
|
+
}
|
|
6960
|
+
}
|
|
6961
|
+
}
|
|
6962
|
+
}
|
|
6963
|
+
function toSkillStats(map) {
|
|
6964
|
+
return [...map.entries()].map(([name, v]) => ({ name, count: v.count, tokens: v.tokens })).filter((s) => s.count > 0).sort((a, b) => b.tokens - a.tokens || b.count - a.count).slice(0, MAX_STATS).map((s) => s.tokens > 0 ? s : { name: s.name, count: s.count });
|
|
6965
|
+
}
|
|
6966
|
+
function toToolStats(map) {
|
|
6967
|
+
return [...map.entries()].map(([name, v]) => ({ name, count: v.count, errors: v.errors, tokens: v.tokens })).filter((s) => s.count > 0).sort((a, b) => b.tokens - a.tokens || b.count - a.count).slice(0, MAX_STATS).map((s) => {
|
|
6968
|
+
const base = { name: s.name, count: s.count };
|
|
6969
|
+
if (s.errors > 0) base.errors = s.errors;
|
|
6970
|
+
if (s.tokens > 0) base.tokens = s.tokens;
|
|
6971
|
+
return base;
|
|
6972
|
+
});
|
|
6973
|
+
}
|
|
6974
|
+
function accumulatorToResult(acc) {
|
|
6975
|
+
return {
|
|
6976
|
+
tools: toToolStats(acc.tools),
|
|
6977
|
+
skills: toSkillStats(acc.skills),
|
|
6978
|
+
agent: { ...acc.agent },
|
|
6979
|
+
sessionMessages: acc.sessionMessages,
|
|
6980
|
+
complete: true
|
|
6981
|
+
};
|
|
6982
|
+
}
|
|
6983
|
+
function numTok(v) {
|
|
6984
|
+
const x = Math.round(Number(v));
|
|
6985
|
+
return Number.isFinite(x) && x > 0 ? x : 0;
|
|
6986
|
+
}
|
|
6987
|
+
function createCodexContext() {
|
|
6988
|
+
return { pending: [] };
|
|
6989
|
+
}
|
|
6990
|
+
function processCodexRecord(rec, acc, ctx) {
|
|
6991
|
+
if (!rec || typeof rec !== "object") return;
|
|
6992
|
+
const r = rec;
|
|
6993
|
+
if (!r.payload || typeof r.payload !== "object") return;
|
|
6994
|
+
const pl = r.payload;
|
|
6995
|
+
const ptype = pl.type;
|
|
6996
|
+
if (r.type === "session_meta" || r.type === "turn_context") return;
|
|
6997
|
+
if (ptype === "function_call" || ptype === "custom_tool_call" || ptype === "local_shell_call") {
|
|
6998
|
+
const raw = typeof pl.name === "string" ? pl.name : ptype === "local_shell_call" ? "local_shell" : "";
|
|
6999
|
+
const name = raw.slice(0, 128);
|
|
7000
|
+
if (!name) return;
|
|
7001
|
+
const id = typeof pl.call_id === "string" ? pl.call_id : void 0;
|
|
7002
|
+
ctx.pending.push({ name, id });
|
|
7003
|
+
const t = acc.tools.get(name) ?? { count: 0, errors: 0, tokens: 0 };
|
|
7004
|
+
t.count += 1;
|
|
7005
|
+
acc.tools.set(name, t);
|
|
7006
|
+
return;
|
|
7007
|
+
}
|
|
7008
|
+
if (ptype === "token_count") {
|
|
7009
|
+
const info = pl.info;
|
|
7010
|
+
const last = info?.last_token_usage;
|
|
7011
|
+
if (!last) return;
|
|
7012
|
+
const inputTokens = numTok(last.input_tokens);
|
|
7013
|
+
const cacheReadTokens = numTok(last.cached_input_tokens);
|
|
7014
|
+
const outputTokens = numTok(last.output_tokens) + numTok(last.reasoning_output_tokens);
|
|
7015
|
+
const tokens = numTok(last.total_tokens) || inputTokens + cacheReadTokens + outputTokens;
|
|
7016
|
+
if (tokens <= 0) {
|
|
7017
|
+
ctx.pending = [];
|
|
7018
|
+
return;
|
|
7019
|
+
}
|
|
7020
|
+
acc.agent.messageCount += 1;
|
|
7021
|
+
acc.agent.totalTokens += tokens;
|
|
7022
|
+
const per = ctx.pending.length > 0 ? Math.floor(tokens / ctx.pending.length) : 0;
|
|
7023
|
+
for (const tu of ctx.pending) {
|
|
7024
|
+
const t = acc.tools.get(tu.name);
|
|
7025
|
+
if (t) t.tokens += per;
|
|
7026
|
+
}
|
|
7027
|
+
ctx.pending = [];
|
|
7028
|
+
}
|
|
7029
|
+
}
|
|
7030
|
+
function* splitLines2(content) {
|
|
7031
|
+
let start = 0;
|
|
7032
|
+
for (let i = 0; i < content.length; i++) {
|
|
7033
|
+
if (content[i] === "\n") {
|
|
7034
|
+
yield content.slice(start, i);
|
|
7035
|
+
start = i + 1;
|
|
7036
|
+
}
|
|
7037
|
+
}
|
|
7038
|
+
if (start < content.length) yield content.slice(start);
|
|
7039
|
+
}
|
|
7040
|
+
function serializeAcc(acc) {
|
|
7041
|
+
return {
|
|
7042
|
+
tools: [...acc.tools].map(([n, v]) => [n, v.count, v.errors, v.tokens]),
|
|
7043
|
+
skills: [...acc.skills].map(([n, v]) => [n, v.count, v.tokens]),
|
|
7044
|
+
agent: [
|
|
7045
|
+
acc.agent.messageCount,
|
|
7046
|
+
acc.agent.subagentMessages,
|
|
7047
|
+
acc.agent.subagentTokens,
|
|
7048
|
+
acc.agent.totalTokens,
|
|
7049
|
+
acc.agent.userMessageCount
|
|
7050
|
+
],
|
|
7051
|
+
sessions: [...acc.sessionMessages].map(([s, c]) => [s, c])
|
|
7052
|
+
};
|
|
7053
|
+
}
|
|
7054
|
+
function mergeAgg(acc, agg) {
|
|
7055
|
+
for (const [n, count, errors, tokens] of agg.tools) {
|
|
7056
|
+
const cur = acc.tools.get(n) ?? { count: 0, errors: 0, tokens: 0 };
|
|
7057
|
+
cur.count += count;
|
|
7058
|
+
cur.errors += errors;
|
|
7059
|
+
cur.tokens += tokens;
|
|
7060
|
+
acc.tools.set(n, cur);
|
|
7061
|
+
}
|
|
7062
|
+
for (const [n, count, tokens] of agg.skills) {
|
|
7063
|
+
const cur = acc.skills.get(n) ?? { count: 0, tokens: 0 };
|
|
7064
|
+
cur.count += count;
|
|
7065
|
+
cur.tokens += tokens;
|
|
7066
|
+
acc.skills.set(n, cur);
|
|
7067
|
+
}
|
|
7068
|
+
acc.agent.messageCount += agg.agent[0];
|
|
7069
|
+
acc.agent.subagentMessages += agg.agent[1];
|
|
7070
|
+
acc.agent.subagentTokens += agg.agent[2];
|
|
7071
|
+
acc.agent.totalTokens += agg.agent[3];
|
|
7072
|
+
acc.agent.userMessageCount += agg.agent[4];
|
|
7073
|
+
for (const [s, c] of agg.sessions) {
|
|
7074
|
+
acc.sessionMessages.set(s, (acc.sessionMessages.get(s) ?? 0) + c);
|
|
7075
|
+
}
|
|
7076
|
+
}
|
|
7077
|
+
function parseClaudeAttrFile(content) {
|
|
7078
|
+
const acc = createAccumulator();
|
|
7079
|
+
const ctx = createFileContext();
|
|
7080
|
+
for (const line of splitLines2(content)) {
|
|
7081
|
+
if (!line) continue;
|
|
7082
|
+
try {
|
|
7083
|
+
processRecord(JSON.parse(line), acc, ctx);
|
|
7084
|
+
} catch {
|
|
7085
|
+
}
|
|
7086
|
+
}
|
|
7087
|
+
return [serializeAcc(acc)];
|
|
7088
|
+
}
|
|
7089
|
+
function parseCodexAttrFile(content) {
|
|
7090
|
+
const acc = createAccumulator();
|
|
7091
|
+
const ctx = createCodexContext();
|
|
7092
|
+
for (const line of splitLines2(content)) {
|
|
7093
|
+
if (!line) continue;
|
|
7094
|
+
try {
|
|
7095
|
+
processCodexRecord(JSON.parse(line), acc, ctx);
|
|
7096
|
+
} catch {
|
|
7097
|
+
}
|
|
7098
|
+
}
|
|
7099
|
+
return [serializeAcc(acc)];
|
|
7100
|
+
}
|
|
7101
|
+
function claudeProjectDirs() {
|
|
7102
|
+
const dirs = [CLAUDE_PROJECTS];
|
|
7103
|
+
const cfg = process.env.CLAUDE_CONFIG_DIR;
|
|
7104
|
+
if (cfg) dirs.push(join5(cfg, "projects"));
|
|
7105
|
+
dirs.push(join5(homedir4(), ".config", "claude", "projects"));
|
|
7106
|
+
return [...new Set(dirs)];
|
|
7107
|
+
}
|
|
7108
|
+
function listTranscripts(dir) {
|
|
7109
|
+
const out = [];
|
|
7110
|
+
const walk = (d) => {
|
|
7111
|
+
if (out.length >= MAX_FILES) return;
|
|
7112
|
+
let entries;
|
|
7113
|
+
try {
|
|
7114
|
+
entries = readdirSync(d, { withFileTypes: true });
|
|
7115
|
+
} catch {
|
|
7116
|
+
return;
|
|
7117
|
+
}
|
|
7118
|
+
for (const e of entries) {
|
|
7119
|
+
if (out.length >= MAX_FILES) return;
|
|
7120
|
+
const p = join5(d, e.name);
|
|
7121
|
+
if (e.isDirectory()) walk(p);
|
|
7122
|
+
else if (e.isFile() && e.name.endsWith(".jsonl")) {
|
|
7123
|
+
try {
|
|
7124
|
+
out.push({ path: p, mtime: statSync2(p).mtimeMs });
|
|
7125
|
+
} catch {
|
|
7126
|
+
}
|
|
7127
|
+
}
|
|
7128
|
+
}
|
|
7129
|
+
};
|
|
7130
|
+
walk(dir);
|
|
7131
|
+
return out.sort((a, b) => b.mtime - a.mtime).slice(0, MAX_FILES).map((f) => f.path);
|
|
7132
|
+
}
|
|
7133
|
+
async function collectAttribution(env = process.env) {
|
|
7134
|
+
const acc = createAccumulator();
|
|
7135
|
+
const deadline = Date.now() + TIME_BUDGET_MS;
|
|
7136
|
+
let complete = true;
|
|
7137
|
+
const mergeInto = (items) => {
|
|
7138
|
+
if (!items) {
|
|
7139
|
+
complete = false;
|
|
7140
|
+
return;
|
|
7141
|
+
}
|
|
7142
|
+
for (const perFile of items) for (const agg of perFile) mergeAgg(acc, agg);
|
|
7143
|
+
};
|
|
7144
|
+
try {
|
|
7145
|
+
const claudeFiles = [];
|
|
7146
|
+
for (const dir of claudeProjectDirs()) claudeFiles.push(...listTranscripts(dir));
|
|
7147
|
+
if (claudeFiles.length > 0) {
|
|
7148
|
+
const res = await readFilesWithCache({
|
|
7149
|
+
files: claudeFiles,
|
|
7150
|
+
cachePath: nativeCachePath("attribution-claude", env),
|
|
7151
|
+
version: ATTRIBUTION_CACHE_VERSION,
|
|
7152
|
+
parseFile: parseClaudeAttrFile,
|
|
7153
|
+
deadline
|
|
7154
|
+
});
|
|
7155
|
+
mergeInto(res.itemsByFile);
|
|
7156
|
+
}
|
|
7157
|
+
const codexFiles = listTranscripts(CODEX_SESSIONS);
|
|
7158
|
+
if (codexFiles.length > 0) {
|
|
7159
|
+
const res = await readFilesWithCache({
|
|
7160
|
+
files: codexFiles,
|
|
7161
|
+
cachePath: nativeCachePath("attribution-codex", env),
|
|
7162
|
+
version: ATTRIBUTION_CACHE_VERSION,
|
|
7163
|
+
parseFile: parseCodexAttrFile,
|
|
7164
|
+
deadline
|
|
7165
|
+
});
|
|
7166
|
+
mergeInto(res.itemsByFile);
|
|
7167
|
+
}
|
|
7168
|
+
} catch {
|
|
7169
|
+
complete = false;
|
|
7170
|
+
}
|
|
7171
|
+
return { ...accumulatorToResult(acc), complete };
|
|
6996
7172
|
}
|
|
6997
|
-
var OrgSlug = external_exports.string().min(2).max(32).refine(isValidSlug, "invalid or reserved slug").refine(isCleanOrgText, "invalid or reserved slug");
|
|
6998
|
-
var OrgWindow = external_exports.object({
|
|
6999
|
-
startDate: DateString.nullable().optional(),
|
|
7000
|
-
endDate: DateString.nullable().optional()
|
|
7001
|
-
}).refine((w) => !(w.startDate && w.endDate) || w.endDate >= w.startDate, { message: "endDate must be on or after startDate", path: ["endDate"] });
|
|
7002
|
-
var OrgJoinPolicy = external_exports.object({
|
|
7003
|
-
allowCodeJoin: external_exports.boolean().default(true),
|
|
7004
|
-
allowDomainJoin: external_exports.boolean().default(false),
|
|
7005
|
-
/** Verified email domains that auto-join, e.g. ["acme.com"]. */
|
|
7006
|
-
emailDomains: external_exports.array(external_exports.string().min(3).max(253).toLowerCase()).max(20).default([])
|
|
7007
|
-
});
|
|
7008
|
-
var OrgApplicationInput = external_exports.object({
|
|
7009
|
-
type: OrgType,
|
|
7010
|
-
orgName: external_exports.string().min(1).max(120),
|
|
7011
|
-
desiredSlug: external_exports.string().min(2).max(32).optional(),
|
|
7012
|
-
contactName: external_exports.string().min(1).max(120),
|
|
7013
|
-
contactEmail: external_exports.string().email().max(254),
|
|
7014
|
-
website: external_exports.string().url().max(300).optional(),
|
|
7015
|
-
/** Rough headcount / attendee estimate, free text. */
|
|
7016
|
-
size: external_exports.string().max(60).optional(),
|
|
7017
|
-
message: external_exports.string().max(2e3).optional()
|
|
7018
|
-
});
|
|
7019
|
-
var OrgProvisionInput = external_exports.object({
|
|
7020
|
-
/** When provisioning straight from an application. */
|
|
7021
|
-
applicationId: external_exports.string().min(1).max(64).optional(),
|
|
7022
|
-
slug: OrgSlug,
|
|
7023
|
-
name: external_exports.string().min(1).max(120),
|
|
7024
|
-
type: OrgType,
|
|
7025
|
-
/** Handle (or email) of the user who becomes Owner. */
|
|
7026
|
-
ownerHandle: external_exports.string().min(1).max(120).optional(),
|
|
7027
|
-
ownerEmail: external_exports.string().email().max(254).optional(),
|
|
7028
|
-
description: external_exports.string().max(2e3).optional(),
|
|
7029
|
-
boardVisibility: OrgBoardVisibility.optional(),
|
|
7030
|
-
window: OrgWindow.optional(),
|
|
7031
|
-
/** Brand accent applied to the org homepage theming. */
|
|
7032
|
-
accentColor: HexColor.optional(),
|
|
7033
|
-
/**
|
|
7034
|
-
* Create the org UNOWNED and mint a one-time owner-claim ("admin sign-in")
|
|
7035
|
-
* token in the same call. The first person to open the link + sign in becomes
|
|
7036
|
-
* the owner; the token is then consumed. When set, an owner email/handle is
|
|
7037
|
-
* NOT required — the link is how the first admin is assigned.
|
|
7038
|
-
*/
|
|
7039
|
-
issueClaimLink: external_exports.boolean().optional()
|
|
7040
|
-
});
|
|
7041
|
-
var OrgSelfServeInput = external_exports.object({
|
|
7042
|
-
slug: OrgSlug,
|
|
7043
|
-
name: external_exports.string().min(1).max(120).refine(isCleanOrgText, "name not allowed"),
|
|
7044
|
-
type: OrgType,
|
|
7045
|
-
description: external_exports.string().max(2e3).optional(),
|
|
7046
|
-
accentColor: HexColor.optional(),
|
|
7047
|
-
/** Who can view the board — defaults to the type's default when omitted. */
|
|
7048
|
-
boardVisibility: OrgBoardVisibility.optional(),
|
|
7049
|
-
/** Optional event window (mainly for hackathons). */
|
|
7050
|
-
window: OrgWindow.optional()
|
|
7051
|
-
});
|
|
7052
|
-
var OrgSettingsInput = external_exports.object({
|
|
7053
|
-
name: external_exports.string().min(1).max(120).optional(),
|
|
7054
|
-
description: external_exports.string().max(2e3).nullable().optional(),
|
|
7055
|
-
accentColor: HexColor.optional(),
|
|
7056
|
-
boardVisibility: OrgBoardVisibility.optional(),
|
|
7057
|
-
window: OrgWindow.optional(),
|
|
7058
|
-
joinPolicy: OrgJoinPolicy.partial().optional()
|
|
7059
|
-
});
|
|
7060
|
-
var OrgJoinInput = external_exports.object({
|
|
7061
|
-
/** Required only when joining via a code; domain/admin joins omit it. */
|
|
7062
|
-
code: external_exports.string().min(1).max(64).optional()
|
|
7063
|
-
});
|
|
7064
7173
|
|
|
7065
|
-
// src/
|
|
7066
|
-
|
|
7174
|
+
// src/cursor.ts
|
|
7175
|
+
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
7176
|
+
import { existsSync as existsSync3 } from "node:fs";
|
|
7177
|
+
import { createRequire as createRequire2 } from "node:module";
|
|
7178
|
+
import { homedir as homedir5, platform as platform2 } from "node:os";
|
|
7179
|
+
import { join as join7 } from "node:path";
|
|
7180
|
+
|
|
7181
|
+
// src/tokscale.ts
|
|
7182
|
+
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
7183
|
+
import { createRequire } from "node:module";
|
|
7184
|
+
import { dirname as dirname3, join as join6 } from "node:path";
|
|
7185
|
+
var LOOKBACK_DAYS = 30;
|
|
7186
|
+
function num2(n) {
|
|
7067
7187
|
const v = Math.round(Number(n));
|
|
7068
7188
|
return Number.isFinite(v) && v > 0 ? v : 0;
|
|
7069
7189
|
}
|
|
7070
|
-
function
|
|
7071
|
-
|
|
7190
|
+
function numCost(n) {
|
|
7191
|
+
const v = Number(n);
|
|
7192
|
+
return Number.isFinite(v) && v > 0 ? v : 0;
|
|
7072
7193
|
}
|
|
7073
|
-
function
|
|
7074
|
-
const
|
|
7075
|
-
if (!
|
|
7076
|
-
const
|
|
7077
|
-
const
|
|
7078
|
-
|
|
7079
|
-
|
|
7080
|
-
|
|
7194
|
+
function mapTokscaleDay(date, json) {
|
|
7195
|
+
const entries = json?.entries;
|
|
7196
|
+
if (!Array.isArray(entries)) return [];
|
|
7197
|
+
const out = [];
|
|
7198
|
+
for (const e of entries) {
|
|
7199
|
+
const inputTokens = num2(e.input);
|
|
7200
|
+
const outputTokens = num2(e.output) + num2(e.reasoning);
|
|
7201
|
+
const cacheCreationTokens = num2(e.cacheWrite);
|
|
7202
|
+
const cacheReadTokens = num2(e.cacheRead);
|
|
7203
|
+
const costUSD = numCost(e.cost);
|
|
7204
|
+
const total = inputTokens + outputTokens + cacheCreationTokens + cacheReadTokens;
|
|
7205
|
+
if (total === 0 && costUSD === 0) continue;
|
|
7206
|
+
out.push({
|
|
7207
|
+
date,
|
|
7208
|
+
tool: "cursor",
|
|
7209
|
+
model: typeof e.model === "string" && e.model ? e.model : "cursor",
|
|
7210
|
+
inputTokens,
|
|
7211
|
+
outputTokens,
|
|
7212
|
+
cacheCreationTokens,
|
|
7213
|
+
cacheReadTokens,
|
|
7214
|
+
costUSD,
|
|
7215
|
+
origin: "cli",
|
|
7216
|
+
verified: false
|
|
7217
|
+
});
|
|
7218
|
+
}
|
|
7219
|
+
return out;
|
|
7081
7220
|
}
|
|
7082
|
-
|
|
7083
|
-
function parseClaudeLine(raw) {
|
|
7084
|
-
const trimmed = raw.trim();
|
|
7085
|
-
if (!trimmed) return null;
|
|
7086
|
-
let obj;
|
|
7221
|
+
function resolveTokscaleBin() {
|
|
7087
7222
|
try {
|
|
7088
|
-
|
|
7223
|
+
const require3 = createRequire(import.meta.url);
|
|
7224
|
+
const pkgPath = require3.resolve("tokscale/package.json");
|
|
7225
|
+
const pkg = require3("tokscale/package.json");
|
|
7226
|
+
const rel = typeof pkg.bin === "string" ? pkg.bin : pkg.bin?.tokscale ?? "";
|
|
7227
|
+
if (!rel) return null;
|
|
7228
|
+
const binPath = join6(dirname3(pkgPath), rel);
|
|
7229
|
+
if (/\.(c|m)?js$/.test(binPath)) {
|
|
7230
|
+
return { cmd: process.execPath, prefixArgs: [binPath] };
|
|
7231
|
+
}
|
|
7232
|
+
return { cmd: binPath, prefixArgs: [] };
|
|
7089
7233
|
} catch {
|
|
7090
7234
|
return null;
|
|
7091
7235
|
}
|
|
7092
|
-
const message = obj.message;
|
|
7093
|
-
if (!message || typeof message !== "object") return null;
|
|
7094
|
-
const usage = message.usage;
|
|
7095
|
-
if (!usage || typeof usage !== "object") return null;
|
|
7096
|
-
if (message.role !== void 0 && message.role !== "assistant") return null;
|
|
7097
|
-
const date = localDate(String(obj.timestamp ?? ""));
|
|
7098
|
-
if (!date) return null;
|
|
7099
|
-
const tsParsed = Date.parse(String(obj.timestamp ?? ""));
|
|
7100
|
-
const ts = Number.isFinite(tsParsed) ? tsParsed : 0;
|
|
7101
|
-
const messageId = typeof message.id === "string" ? message.id : "";
|
|
7102
|
-
const requestId = typeof obj.requestId === "string" ? obj.requestId : "";
|
|
7103
|
-
const hasRealId = messageId !== "" || requestId !== "";
|
|
7104
|
-
const key = hasRealId ? `${messageId}|${requestId}` : `synthetic|${date}|${syntheticCounter += 1}`;
|
|
7105
|
-
return {
|
|
7106
|
-
key,
|
|
7107
|
-
hasRealId,
|
|
7108
|
-
date,
|
|
7109
|
-
ts,
|
|
7110
|
-
model: typeof message.model === "string" ? message.model : "unknown",
|
|
7111
|
-
inputTokens: num3(usage.input_tokens),
|
|
7112
|
-
outputTokens: num3(usage.output_tokens),
|
|
7113
|
-
cacheCreationTokens: num3(usage.cache_creation_input_tokens),
|
|
7114
|
-
cacheReadTokens: num3(usage.cache_read_input_tokens)
|
|
7115
|
-
};
|
|
7116
7236
|
}
|
|
7117
|
-
function
|
|
7118
|
-
|
|
7119
|
-
|
|
7120
|
-
|
|
7121
|
-
|
|
7122
|
-
|
|
7237
|
+
function runTokscaleDay(bin, day) {
|
|
7238
|
+
const res = spawnSync2(
|
|
7239
|
+
bin.cmd,
|
|
7240
|
+
[
|
|
7241
|
+
...bin.prefixArgs,
|
|
7242
|
+
"--client",
|
|
7243
|
+
"cursor",
|
|
7244
|
+
"--json",
|
|
7245
|
+
"--since",
|
|
7246
|
+
day,
|
|
7247
|
+
"--until",
|
|
7248
|
+
day,
|
|
7249
|
+
"--group-by",
|
|
7250
|
+
"model",
|
|
7251
|
+
"--no-spinner"
|
|
7252
|
+
],
|
|
7253
|
+
{ encoding: "utf8", maxBuffer: 32 * 1024 * 1024, timeout: 6e4 }
|
|
7254
|
+
);
|
|
7255
|
+
if (res.status !== 0 || !res.stdout) return null;
|
|
7256
|
+
try {
|
|
7257
|
+
return JSON.parse(res.stdout);
|
|
7258
|
+
} catch {
|
|
7259
|
+
return null;
|
|
7123
7260
|
}
|
|
7124
7261
|
}
|
|
7125
|
-
function
|
|
7126
|
-
const
|
|
7127
|
-
|
|
7128
|
-
|
|
7129
|
-
|
|
7130
|
-
|
|
7131
|
-
|
|
7132
|
-
|
|
7133
|
-
|
|
7134
|
-
|
|
7135
|
-
|
|
7136
|
-
|
|
7137
|
-
cacheReadTokens: 0,
|
|
7138
|
-
requestCount: 0
|
|
7139
|
-
};
|
|
7140
|
-
byDayModel.set(k, b);
|
|
7141
|
-
}
|
|
7142
|
-
b.inputTokens += r.inputTokens;
|
|
7143
|
-
b.outputTokens += r.outputTokens;
|
|
7144
|
-
b.cacheCreationTokens += r.cacheCreationTokens;
|
|
7145
|
-
b.cacheReadTokens += r.cacheReadTokens;
|
|
7146
|
-
if (r.hasRealId) b.requestCount += 1;
|
|
7147
|
-
}
|
|
7148
|
-
const entries = [];
|
|
7149
|
-
for (const b of byDayModel.values()) {
|
|
7150
|
-
const tokens = b.inputTokens + b.outputTokens + b.cacheCreationTokens + b.cacheReadTokens;
|
|
7151
|
-
if (tokens === 0) continue;
|
|
7152
|
-
entries.push({
|
|
7153
|
-
date: b.date,
|
|
7154
|
-
tool: "claude",
|
|
7155
|
-
model: b.model,
|
|
7156
|
-
inputTokens: b.inputTokens,
|
|
7157
|
-
outputTokens: b.outputTokens,
|
|
7158
|
-
cacheCreationTokens: b.cacheCreationTokens,
|
|
7159
|
-
cacheReadTokens: b.cacheReadTokens,
|
|
7160
|
-
costUSD: estimateCostUSD(b.model, b),
|
|
7161
|
-
origin: "cli",
|
|
7162
|
-
verified: false,
|
|
7163
|
-
requestCount: b.requestCount
|
|
7164
|
-
});
|
|
7262
|
+
function collectCursorViaTokscale(lookbackDays = LOOKBACK_DAYS) {
|
|
7263
|
+
const bin = resolveTokscaleBin();
|
|
7264
|
+
if (!bin) return [];
|
|
7265
|
+
const today = /* @__PURE__ */ new Date();
|
|
7266
|
+
const day = (offset) => {
|
|
7267
|
+
const d = new Date(today.getTime() - offset * 864e5);
|
|
7268
|
+
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
|
|
7269
|
+
};
|
|
7270
|
+
if (mapTokscaleDay(day(0), runTokscaleDay(bin, day(0))).length === 0) {
|
|
7271
|
+
if (mapTokscaleDay(day(1), runTokscaleDay(bin, day(1))).length === 0) {
|
|
7272
|
+
return [];
|
|
7273
|
+
}
|
|
7165
7274
|
}
|
|
7166
|
-
|
|
7167
|
-
|
|
7168
|
-
|
|
7169
|
-
|
|
7170
|
-
|
|
7275
|
+
const out = [];
|
|
7276
|
+
for (let i = 0; i < lookbackDays; i++) {
|
|
7277
|
+
const d = day(i);
|
|
7278
|
+
out.push(...mapTokscaleDay(d, runTokscaleDay(bin, d)));
|
|
7279
|
+
}
|
|
7280
|
+
return out;
|
|
7171
7281
|
}
|
|
7172
|
-
|
|
7173
|
-
|
|
7282
|
+
|
|
7283
|
+
// src/cursor.ts
|
|
7284
|
+
var EVENTS_URL = "https://cursor.com/api/dashboard/get-filtered-usage-events";
|
|
7285
|
+
function cursorDbPath() {
|
|
7286
|
+
const home = homedir5();
|
|
7287
|
+
const os = platform2();
|
|
7288
|
+
const p = os === "darwin" ? join7(home, "Library", "Application Support", "Cursor", "User", "globalStorage", "state.vscdb") : os === "win32" ? join7(process.env.APPDATA ?? join7(home, "AppData", "Roaming"), "Cursor", "User", "globalStorage", "state.vscdb") : join7(process.env.XDG_CONFIG_HOME ?? join7(home, ".config"), "Cursor", "User", "globalStorage", "state.vscdb");
|
|
7289
|
+
return existsSync3(p) ? p : null;
|
|
7174
7290
|
}
|
|
7175
|
-
|
|
7176
|
-
|
|
7291
|
+
function readCursorToken(db) {
|
|
7292
|
+
const require3 = createRequire2(import.meta.url);
|
|
7177
7293
|
try {
|
|
7178
|
-
|
|
7294
|
+
const { DatabaseSync } = require3("node:sqlite");
|
|
7295
|
+
const d = new DatabaseSync(db, { readOnly: true });
|
|
7296
|
+
const row = d.prepare("SELECT value FROM ItemTable WHERE key = ?").get("cursorAuth/accessToken");
|
|
7297
|
+
d.close();
|
|
7298
|
+
if (row?.value) return String(row.value);
|
|
7179
7299
|
} catch {
|
|
7180
|
-
return [];
|
|
7181
7300
|
}
|
|
7182
|
-
|
|
7183
|
-
|
|
7184
|
-
|
|
7185
|
-
|
|
7186
|
-
|
|
7187
|
-
|
|
7188
|
-
|
|
7189
|
-
|
|
7301
|
+
try {
|
|
7302
|
+
const res = spawnSync3(
|
|
7303
|
+
"sqlite3",
|
|
7304
|
+
[db, "SELECT value FROM ItemTable WHERE key='cursorAuth/accessToken';"],
|
|
7305
|
+
{ encoding: "utf8", timeout: 1e4 }
|
|
7306
|
+
);
|
|
7307
|
+
const out = res.stdout?.trim();
|
|
7308
|
+
if (res.status === 0 && out) return out;
|
|
7309
|
+
} catch {
|
|
7190
7310
|
}
|
|
7191
|
-
return
|
|
7311
|
+
return null;
|
|
7192
7312
|
}
|
|
7193
|
-
|
|
7194
|
-
|
|
7195
|
-
|
|
7196
|
-
|
|
7197
|
-
|
|
7198
|
-
|
|
7199
|
-
|
|
7200
|
-
|
|
7313
|
+
function cursorCookie(token) {
|
|
7314
|
+
try {
|
|
7315
|
+
const part = token.split(".")[1];
|
|
7316
|
+
if (!part) return null;
|
|
7317
|
+
const json = JSON.parse(
|
|
7318
|
+
Buffer.from(part, "base64url").toString("utf8")
|
|
7319
|
+
);
|
|
7320
|
+
if (!json.sub) return null;
|
|
7321
|
+
return `WorkosCursorSessionToken=${json.sub}%3A%3A${token}`;
|
|
7322
|
+
} catch {
|
|
7323
|
+
return null;
|
|
7201
7324
|
}
|
|
7202
|
-
if (start < content.length) yield content.slice(start);
|
|
7203
7325
|
}
|
|
7204
|
-
|
|
7205
|
-
const
|
|
7206
|
-
|
|
7207
|
-
|
|
7208
|
-
|
|
7209
|
-
const
|
|
7210
|
-
const
|
|
7211
|
-
const
|
|
7212
|
-
|
|
7213
|
-
|
|
7214
|
-
if (
|
|
7215
|
-
|
|
7216
|
-
}
|
|
7217
|
-
|
|
7218
|
-
|
|
7219
|
-
|
|
7220
|
-
|
|
7221
|
-
|
|
7222
|
-
|
|
7223
|
-
|
|
7224
|
-
|
|
7326
|
+
function num3(n) {
|
|
7327
|
+
const v = Math.round(Number(n));
|
|
7328
|
+
return Number.isFinite(v) && v > 0 ? v : 0;
|
|
7329
|
+
}
|
|
7330
|
+
function mapCursorEvents(events) {
|
|
7331
|
+
const byDay = /* @__PURE__ */ new Map();
|
|
7332
|
+
const byHour = /* @__PURE__ */ new Map();
|
|
7333
|
+
for (const e of events) {
|
|
7334
|
+
const tu = e.tokenUsage;
|
|
7335
|
+
const ms = Number(e.timestamp);
|
|
7336
|
+
if (!tu || !Number.isFinite(ms)) continue;
|
|
7337
|
+
const d = new Date(ms);
|
|
7338
|
+
const date = `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
|
|
7339
|
+
const model = e.model || "cursor";
|
|
7340
|
+
const input = num3(tu.inputTokens);
|
|
7341
|
+
const output = num3(tu.outputTokens);
|
|
7342
|
+
const cacheWrite = num3(tu.cacheWriteTokens);
|
|
7343
|
+
const cacheRead = num3(tu.cacheReadTokens);
|
|
7344
|
+
const cost = Math.max(0, (Number(tu.totalCents) || 0) / 100);
|
|
7345
|
+
const total = input + output + cacheWrite + cacheRead;
|
|
7346
|
+
if (total === 0 && cost === 0) continue;
|
|
7347
|
+
const key = `${date}|${model}`;
|
|
7348
|
+
const day = byDay.get(key) ?? {
|
|
7349
|
+
date,
|
|
7350
|
+
tool: "cursor",
|
|
7351
|
+
model,
|
|
7352
|
+
inputTokens: 0,
|
|
7353
|
+
outputTokens: 0,
|
|
7354
|
+
cacheCreationTokens: 0,
|
|
7355
|
+
cacheReadTokens: 0,
|
|
7356
|
+
costUSD: 0,
|
|
7357
|
+
origin: "cli",
|
|
7358
|
+
verified: false
|
|
7359
|
+
};
|
|
7360
|
+
day.inputTokens += input;
|
|
7361
|
+
day.outputTokens += output;
|
|
7362
|
+
day.cacheCreationTokens += cacheWrite;
|
|
7363
|
+
day.cacheReadTokens += cacheRead;
|
|
7364
|
+
day.costUSD += cost;
|
|
7365
|
+
byDay.set(key, day);
|
|
7366
|
+
const hour = new Date(
|
|
7367
|
+
Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate(), d.getUTCHours())
|
|
7368
|
+
).toISOString();
|
|
7369
|
+
const blk = byHour.get(hour) ?? { startTime: hour, totalTokens: 0, costUSD: 0 };
|
|
7370
|
+
blk.totalTokens += total;
|
|
7371
|
+
blk.costUSD += cost;
|
|
7372
|
+
byHour.set(hour, blk);
|
|
7225
7373
|
}
|
|
7226
|
-
|
|
7374
|
+
const entries = [...byDay.values()].map((e) => ({
|
|
7375
|
+
...e,
|
|
7376
|
+
costUSD: Number(e.costUSD.toFixed(4))
|
|
7377
|
+
}));
|
|
7378
|
+
const blocks = [...byHour.values()].map((b) => ({
|
|
7379
|
+
...b,
|
|
7380
|
+
costUSD: Number(b.costUSD.toFixed(4))
|
|
7381
|
+
}));
|
|
7382
|
+
return { entries, blocks };
|
|
7227
7383
|
}
|
|
7228
|
-
async function
|
|
7229
|
-
const
|
|
7230
|
-
|
|
7231
|
-
|
|
7232
|
-
|
|
7233
|
-
|
|
7234
|
-
|
|
7235
|
-
|
|
7236
|
-
|
|
7237
|
-
|
|
7238
|
-
|
|
7384
|
+
async function fetchCursorEvents(cookie, maxPages = 30, pageSize = 500) {
|
|
7385
|
+
const all = [];
|
|
7386
|
+
for (let page = 1; page <= maxPages; page++) {
|
|
7387
|
+
const res = await fetch(EVENTS_URL, {
|
|
7388
|
+
method: "POST",
|
|
7389
|
+
headers: {
|
|
7390
|
+
"Content-Type": "application/json",
|
|
7391
|
+
Origin: "https://cursor.com",
|
|
7392
|
+
Cookie: cookie
|
|
7393
|
+
},
|
|
7394
|
+
body: JSON.stringify({ page, pageSize }),
|
|
7395
|
+
signal: AbortSignal.timeout(2e4)
|
|
7396
|
+
});
|
|
7397
|
+
if (!res.ok) {
|
|
7398
|
+
throw new Error(`cursor usage page ${page} failed (HTTP ${res.status})`);
|
|
7239
7399
|
}
|
|
7240
|
-
|
|
7241
|
-
|
|
7242
|
-
|
|
7243
|
-
|
|
7244
|
-
|
|
7400
|
+
const body = await res.json();
|
|
7401
|
+
const batch = body.usageEventsDisplay ?? [];
|
|
7402
|
+
all.push(...batch);
|
|
7403
|
+
if (batch.length < pageSize) break;
|
|
7404
|
+
}
|
|
7405
|
+
return all;
|
|
7406
|
+
}
|
|
7407
|
+
async function collectCursor() {
|
|
7408
|
+
try {
|
|
7409
|
+
const db = cursorDbPath();
|
|
7410
|
+
const token = db ? readCursorToken(db) : null;
|
|
7411
|
+
const cookie = token ? cursorCookie(token) : null;
|
|
7412
|
+
if (cookie) {
|
|
7413
|
+
const events = await fetchCursorEvents(cookie);
|
|
7414
|
+
const { entries, blocks } = mapCursorEvents(events);
|
|
7415
|
+
if (entries.length > 0) return { entries, blocks, found: true };
|
|
7245
7416
|
}
|
|
7246
|
-
|
|
7417
|
+
} catch {
|
|
7247
7418
|
}
|
|
7248
|
-
|
|
7419
|
+
try {
|
|
7420
|
+
const entries = collectCursorViaTokscale();
|
|
7421
|
+
if (entries.length > 0) return { entries, blocks: [], found: true };
|
|
7422
|
+
} catch {
|
|
7423
|
+
}
|
|
7424
|
+
return { entries: [], blocks: [], found: false };
|
|
7249
7425
|
}
|
|
7250
7426
|
|
|
7251
7427
|
// src/native/codex.ts
|
|
7252
|
-
import { readdir as readdir2
|
|
7428
|
+
import { readdir as readdir2 } from "node:fs/promises";
|
|
7253
7429
|
import { homedir as homedir6 } from "node:os";
|
|
7254
|
-
import { join as
|
|
7430
|
+
import { join as join8 } from "node:path";
|
|
7255
7431
|
function num4(n) {
|
|
7256
7432
|
const v = Math.round(Number(n));
|
|
7257
7433
|
return Number.isFinite(v) && v > 0 ? v : 0;
|
|
@@ -7340,8 +7516,8 @@ function parseCodexRollout(lines) {
|
|
|
7340
7516
|
}
|
|
7341
7517
|
return out;
|
|
7342
7518
|
}
|
|
7343
|
-
function
|
|
7344
|
-
for (const s of
|
|
7519
|
+
function foldCodexSessions(acc, sessions) {
|
|
7520
|
+
for (const s of sessions) {
|
|
7345
7521
|
const k = `${s.date}|${s.model}`;
|
|
7346
7522
|
let b = acc.get(k);
|
|
7347
7523
|
if (!b) {
|
|
@@ -7383,8 +7559,8 @@ function finalizeCodexEntries(acc) {
|
|
|
7383
7559
|
return entries;
|
|
7384
7560
|
}
|
|
7385
7561
|
function resolveCodexSessionsDir(env = process.env) {
|
|
7386
|
-
const home = env.CODEX_HOME && env.CODEX_HOME.trim() ? env.CODEX_HOME.trim() :
|
|
7387
|
-
return
|
|
7562
|
+
const home = env.CODEX_HOME && env.CODEX_HOME.trim() ? env.CODEX_HOME.trim() : join8(homedir6(), ".codex");
|
|
7563
|
+
return join8(home, "sessions");
|
|
7388
7564
|
}
|
|
7389
7565
|
async function listJsonl2(dir) {
|
|
7390
7566
|
let dirents;
|
|
@@ -7395,13 +7571,13 @@ async function listJsonl2(dir) {
|
|
|
7395
7571
|
}
|
|
7396
7572
|
const out = [];
|
|
7397
7573
|
for (const d of dirents) {
|
|
7398
|
-
const full =
|
|
7574
|
+
const full = join8(dir, d.name);
|
|
7399
7575
|
if (d.isDirectory()) out.push(...await listJsonl2(full));
|
|
7400
7576
|
else if (d.isFile() && d.name.endsWith(".jsonl")) out.push(full);
|
|
7401
7577
|
}
|
|
7402
7578
|
return out;
|
|
7403
7579
|
}
|
|
7404
|
-
function*
|
|
7580
|
+
function* splitLines3(content) {
|
|
7405
7581
|
let start = 0;
|
|
7406
7582
|
for (let i = 0; i < content.length; i++) {
|
|
7407
7583
|
if (content[i] === "\n") {
|
|
@@ -7411,38 +7587,69 @@ function* splitLines2(content) {
|
|
|
7411
7587
|
}
|
|
7412
7588
|
if (start < content.length) yield content.slice(start);
|
|
7413
7589
|
}
|
|
7414
|
-
var NATIVE_READ_BUDGET_MS2 =
|
|
7590
|
+
var NATIVE_READ_BUDGET_MS2 = 45e3;
|
|
7591
|
+
var CODEX_CACHE_VERSION = 1;
|
|
7592
|
+
function toCachedSession(s) {
|
|
7593
|
+
return [
|
|
7594
|
+
s.date,
|
|
7595
|
+
s.model,
|
|
7596
|
+
s.inputTokens,
|
|
7597
|
+
s.outputTokens,
|
|
7598
|
+
s.cacheCreationTokens,
|
|
7599
|
+
s.cacheReadTokens,
|
|
7600
|
+
s.turnCount
|
|
7601
|
+
];
|
|
7602
|
+
}
|
|
7603
|
+
function fromCachedSession(t) {
|
|
7604
|
+
return {
|
|
7605
|
+
date: t[0],
|
|
7606
|
+
model: t[1],
|
|
7607
|
+
inputTokens: t[2],
|
|
7608
|
+
outputTokens: t[3],
|
|
7609
|
+
cacheCreationTokens: t[4],
|
|
7610
|
+
cacheReadTokens: t[5],
|
|
7611
|
+
turnCount: t[6]
|
|
7612
|
+
};
|
|
7613
|
+
}
|
|
7415
7614
|
async function collectCodexNative(env = process.env, opts = {}) {
|
|
7416
7615
|
const dir = resolveCodexSessionsDir(env);
|
|
7417
7616
|
const files = await listJsonl2(dir);
|
|
7418
7617
|
if (files.length === 0) return { entries: [], found: false, filesScanned: 0 };
|
|
7419
7618
|
const now = opts.now ?? Date.now;
|
|
7420
|
-
const
|
|
7619
|
+
const res = await readFilesWithCache({
|
|
7620
|
+
files,
|
|
7621
|
+
cachePath: opts.cachePath ?? nativeCachePath("codex", env),
|
|
7622
|
+
version: CODEX_CACHE_VERSION,
|
|
7623
|
+
parseFile: (content) => parseCodexRollout(splitLines3(content)).map(toCachedSession),
|
|
7624
|
+
deadline: now() + (opts.budgetMs ?? NATIVE_READ_BUDGET_MS2),
|
|
7625
|
+
now
|
|
7626
|
+
});
|
|
7627
|
+
if (!res.itemsByFile) {
|
|
7628
|
+
return {
|
|
7629
|
+
entries: [],
|
|
7630
|
+
found: false,
|
|
7631
|
+
filesScanned: res.filesRead,
|
|
7632
|
+
timedOut: true
|
|
7633
|
+
};
|
|
7634
|
+
}
|
|
7421
7635
|
const acc = /* @__PURE__ */ new Map();
|
|
7422
|
-
|
|
7423
|
-
|
|
7424
|
-
if (now() > deadline) {
|
|
7425
|
-
return { entries: [], found: false, filesScanned: scanned, timedOut: true };
|
|
7426
|
-
}
|
|
7427
|
-
let content;
|
|
7428
|
-
try {
|
|
7429
|
-
content = await readFile2(f, "utf8");
|
|
7430
|
-
} catch {
|
|
7431
|
-
continue;
|
|
7432
|
-
}
|
|
7433
|
-
accumulateCodexSession(acc, splitLines2(content));
|
|
7434
|
-
scanned += 1;
|
|
7636
|
+
for (const items of res.itemsByFile) {
|
|
7637
|
+
foldCodexSessions(acc, items.map(fromCachedSession));
|
|
7435
7638
|
}
|
|
7436
|
-
return {
|
|
7639
|
+
return {
|
|
7640
|
+
entries: finalizeCodexEntries(acc),
|
|
7641
|
+
found: true,
|
|
7642
|
+
filesScanned: res.filesRead
|
|
7643
|
+
};
|
|
7437
7644
|
}
|
|
7438
7645
|
|
|
7439
7646
|
// src/pricing-live.ts
|
|
7440
7647
|
import { mkdir, readFile as readFile3, rename, writeFile } from "node:fs/promises";
|
|
7441
|
-
import { dirname as
|
|
7648
|
+
import { dirname as dirname4, join as join9 } from "node:path";
|
|
7442
7649
|
var CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
7443
7650
|
var FETCH_TIMEOUT_MS = 5e3;
|
|
7444
7651
|
function pricingCachePath(dir = defaultConfigDir()) {
|
|
7445
|
-
return
|
|
7652
|
+
return join9(dir, "pricing-cache.json");
|
|
7446
7653
|
}
|
|
7447
7654
|
async function readCache(path) {
|
|
7448
7655
|
try {
|
|
@@ -7478,7 +7685,7 @@ async function loadLivePricing(env = process.env, now = Date.now, cachePath = pr
|
|
|
7478
7685
|
if (live) {
|
|
7479
7686
|
setLivePricing(live);
|
|
7480
7687
|
try {
|
|
7481
|
-
await mkdir(
|
|
7688
|
+
await mkdir(dirname4(path), { recursive: true });
|
|
7482
7689
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
7483
7690
|
await writeFile(tmp, JSON.stringify({ fetchedAt: now(), table: live }));
|
|
7484
7691
|
await rename(tmp, path);
|
|
@@ -7493,6 +7700,93 @@ async function loadLivePricing(env = process.env, now = Date.now, cachePath = pr
|
|
|
7493
7700
|
return "baked";
|
|
7494
7701
|
}
|
|
7495
7702
|
|
|
7703
|
+
// src/provenance-store.ts
|
|
7704
|
+
import { mkdirSync as mkdirSync4, readFileSync as readFileSync3, renameSync as renameSync4, writeFileSync as writeFileSync4 } from "node:fs";
|
|
7705
|
+
import { dirname as dirname5, join as join10 } from "node:path";
|
|
7706
|
+
var PROVENANCE_STORE_VERSION = 1;
|
|
7707
|
+
var KEY_SEP = "|";
|
|
7708
|
+
var keyOf = (date, tool) => `${date}${KEY_SEP}${tool}`;
|
|
7709
|
+
function entryTokens(e) {
|
|
7710
|
+
return e.inputTokens + e.outputTokens + e.cacheCreationTokens + e.cacheReadTokens;
|
|
7711
|
+
}
|
|
7712
|
+
function provenanceStorePath(env = process.env) {
|
|
7713
|
+
const override = env.WHOBURNEDMORE_CONFIG_DIR?.trim();
|
|
7714
|
+
const dir = override || defaultConfigDir();
|
|
7715
|
+
return join10(dir, "native-cache-provenance.json");
|
|
7716
|
+
}
|
|
7717
|
+
function loadProvenanceStore(path) {
|
|
7718
|
+
try {
|
|
7719
|
+
const parsed = JSON.parse(readFileSync3(path, "utf8"));
|
|
7720
|
+
if (parsed && parsed.v === PROVENANCE_STORE_VERSION && parsed.req && typeof parsed.req === "object") {
|
|
7721
|
+
return {
|
|
7722
|
+
v: PROVENANCE_STORE_VERSION,
|
|
7723
|
+
req: parsed.req,
|
|
7724
|
+
agent: parsed.agent
|
|
7725
|
+
};
|
|
7726
|
+
}
|
|
7727
|
+
} catch {
|
|
7728
|
+
}
|
|
7729
|
+
return null;
|
|
7730
|
+
}
|
|
7731
|
+
function saveProvenanceStore(path, store) {
|
|
7732
|
+
try {
|
|
7733
|
+
mkdirSync4(dirname5(path), { recursive: true });
|
|
7734
|
+
const tmp = `${path}.tmp-${process.pid}`;
|
|
7735
|
+
writeFileSync4(tmp, JSON.stringify(store));
|
|
7736
|
+
renameSync4(tmp, path);
|
|
7737
|
+
} catch {
|
|
7738
|
+
}
|
|
7739
|
+
}
|
|
7740
|
+
function reconcileProvenance(entries, agent, complete, store) {
|
|
7741
|
+
const prevReq = store?.req ?? {};
|
|
7742
|
+
const prevAgent = store?.agent;
|
|
7743
|
+
const curReq = /* @__PURE__ */ new Map();
|
|
7744
|
+
for (const e of entries) {
|
|
7745
|
+
if (e.requestCount === void 0) continue;
|
|
7746
|
+
const k = keyOf(e.date, e.tool);
|
|
7747
|
+
curReq.set(k, (curReq.get(k) ?? 0) + e.requestCount);
|
|
7748
|
+
}
|
|
7749
|
+
const nextReq = { ...prevReq };
|
|
7750
|
+
let outEntries = entries;
|
|
7751
|
+
if (complete) {
|
|
7752
|
+
for (const [k, v] of curReq) nextReq[k] = v;
|
|
7753
|
+
} else {
|
|
7754
|
+
for (const [k, v] of curReq) nextReq[k] = Math.max(prevReq[k] ?? 0, v);
|
|
7755
|
+
const heaviest = /* @__PURE__ */ new Map();
|
|
7756
|
+
for (const e of entries) {
|
|
7757
|
+
const k = keyOf(e.date, e.tool);
|
|
7758
|
+
const cur = heaviest.get(k);
|
|
7759
|
+
if (!cur || entryTokens(e) > entryTokens(cur)) heaviest.set(k, e);
|
|
7760
|
+
}
|
|
7761
|
+
let cloned = null;
|
|
7762
|
+
for (const [k, stored] of Object.entries(prevReq)) {
|
|
7763
|
+
const cur = curReq.get(k) ?? 0;
|
|
7764
|
+
if (stored <= cur) continue;
|
|
7765
|
+
const target = heaviest.get(k);
|
|
7766
|
+
if (!target) continue;
|
|
7767
|
+
if (!cloned) cloned = [...entries];
|
|
7768
|
+
const idx = cloned.indexOf(target);
|
|
7769
|
+
cloned[idx] = {
|
|
7770
|
+
...target,
|
|
7771
|
+
requestCount: (target.requestCount ?? 0) + (stored - cur)
|
|
7772
|
+
};
|
|
7773
|
+
}
|
|
7774
|
+
if (cloned) outEntries = cloned;
|
|
7775
|
+
}
|
|
7776
|
+
let outAgent = agent;
|
|
7777
|
+
let nextAgent = prevAgent;
|
|
7778
|
+
if (complete && agent.messageCount > 0) {
|
|
7779
|
+
nextAgent = agent;
|
|
7780
|
+
} else if (!complete && prevAgent && prevAgent.totalTokens > agent.totalTokens) {
|
|
7781
|
+
outAgent = prevAgent;
|
|
7782
|
+
}
|
|
7783
|
+
return {
|
|
7784
|
+
entries: outEntries,
|
|
7785
|
+
agent: outAgent,
|
|
7786
|
+
store: { v: PROVENANCE_STORE_VERSION, req: nextReq, agent: nextAgent }
|
|
7787
|
+
};
|
|
7788
|
+
}
|
|
7789
|
+
|
|
7496
7790
|
// src/collect.ts
|
|
7497
7791
|
var execFileAsync = promisify(execFile);
|
|
7498
7792
|
var SOURCES = [
|
|
@@ -7633,7 +7927,7 @@ function resolveCcusageBin() {
|
|
|
7633
7927
|
const pkgPath = require3.resolve("ccusage/package.json");
|
|
7634
7928
|
const pkg = require3("ccusage/package.json");
|
|
7635
7929
|
const rel = typeof pkg.bin === "string" ? pkg.bin : pkg.bin?.ccusage ?? "ccusage";
|
|
7636
|
-
const binPath =
|
|
7930
|
+
const binPath = join11(dirname6(pkgPath), rel);
|
|
7637
7931
|
if (/\.(c|m)?js$/.test(binPath)) {
|
|
7638
7932
|
return { cmd: process.execPath, prefixArgs: [binPath] };
|
|
7639
7933
|
}
|
|
@@ -7660,7 +7954,7 @@ function dedupeDaily(entries) {
|
|
|
7660
7954
|
}
|
|
7661
7955
|
return [...byKey.values()];
|
|
7662
7956
|
}
|
|
7663
|
-
function
|
|
7957
|
+
function entryTokens2(e) {
|
|
7664
7958
|
return e.inputTokens + e.outputTokens + e.cacheCreationTokens + e.cacheReadTokens;
|
|
7665
7959
|
}
|
|
7666
7960
|
function capByTokens(rows, max, tokens) {
|
|
@@ -7729,6 +8023,9 @@ async function runCcusage(cmd, args, env) {
|
|
|
7729
8023
|
return (await runCcusageOnce(cmd, args, env)).json;
|
|
7730
8024
|
}
|
|
7731
8025
|
var COLLECT_STAGES = SOURCES.length + 4;
|
|
8026
|
+
function isAuthoritativeScan(attributionComplete, nativeClaude, nativeCodex) {
|
|
8027
|
+
return attributionComplete && nativeClaude.timedOut !== true && nativeCodex.timedOut !== true;
|
|
8028
|
+
}
|
|
7732
8029
|
async function collectAll(onProgress) {
|
|
7733
8030
|
await loadLivePricing().catch(() => {
|
|
7734
8031
|
});
|
|
@@ -7736,10 +8033,10 @@ async function collectAll(onProgress) {
|
|
|
7736
8033
|
let done = 0;
|
|
7737
8034
|
const tick = () => onProgress?.(++done, COLLECT_STAGES, "");
|
|
7738
8035
|
const nativeClaudeTask = collectClaudeNative().catch(
|
|
7739
|
-
() => ({ entries: [], found: false, filesScanned: 0 })
|
|
8036
|
+
() => ({ entries: [], found: false, filesScanned: 0, timedOut: true })
|
|
7740
8037
|
);
|
|
7741
8038
|
const nativeCodexTask = collectCodexNative().catch(
|
|
7742
|
-
() => ({ entries: [], found: false, filesScanned: 0 })
|
|
8039
|
+
() => ({ entries: [], found: false, filesScanned: 0, timedOut: true })
|
|
7743
8040
|
);
|
|
7744
8041
|
const sourceTasks = SOURCES.map(async (source) => {
|
|
7745
8042
|
const env = source === "claude" ? ccusageClaudeEnv() : void 0;
|
|
@@ -7804,19 +8101,28 @@ async function collectAll(onProgress) {
|
|
|
7804
8101
|
...messageCount ? { messageCount } : {}
|
|
7805
8102
|
};
|
|
7806
8103
|
});
|
|
8104
|
+
const scanComplete = isAuthoritativeScan(complete, nativeClaude, nativeCodex);
|
|
8105
|
+
const storePath = provenanceStorePath();
|
|
8106
|
+
const reconciled = reconcileProvenance(
|
|
8107
|
+
dedupeDaily(entries),
|
|
8108
|
+
agent,
|
|
8109
|
+
scanComplete,
|
|
8110
|
+
loadProvenanceStore(storePath)
|
|
8111
|
+
);
|
|
8112
|
+
saveProvenanceStore(storePath, reconciled.store);
|
|
7807
8113
|
return {
|
|
7808
8114
|
// Cap each array to the server's accepted maximum (the shared SubmitPayload
|
|
7809
8115
|
// schema: entries ≤ 20000, sessions/blocks ≤ 10000), keeping the
|
|
7810
8116
|
// highest-token rows. Without this, a power user with >10000 distinct sessions
|
|
7811
8117
|
// would have their ENTIRE submit rejected with a 400 instead of a capped one.
|
|
7812
8118
|
// tools/skills are already bounded upstream (attribution caps).
|
|
7813
|
-
entries: capByTokens(
|
|
7814
|
-
sessions: capByTokens(dedupedSessions, 1e4,
|
|
8119
|
+
entries: capByTokens(reconciled.entries, 2e4, entryTokens2),
|
|
8120
|
+
sessions: capByTokens(dedupedSessions, 1e4, entryTokens2),
|
|
7815
8121
|
blocks: capByTokens(dedupeBlocks(blocks), 1e4, (b) => b.totalTokens),
|
|
7816
8122
|
toolsFound,
|
|
7817
8123
|
tools,
|
|
7818
8124
|
skills,
|
|
7819
|
-
agent,
|
|
8125
|
+
agent: reconciled.agent,
|
|
7820
8126
|
attributionComplete: complete
|
|
7821
8127
|
};
|
|
7822
8128
|
}
|
|
@@ -8221,9 +8527,9 @@ async function confirm(question) {
|
|
|
8221
8527
|
}
|
|
8222
8528
|
function showLocalDashboard(payload) {
|
|
8223
8529
|
const dir = defaultConfigDir();
|
|
8224
|
-
|
|
8225
|
-
const file =
|
|
8226
|
-
|
|
8530
|
+
mkdirSync5(dir, { recursive: true });
|
|
8531
|
+
const file = join12(dir, "dashboard.html");
|
|
8532
|
+
writeFileSync5(
|
|
8227
8533
|
file,
|
|
8228
8534
|
renderDashboardHtml(payload.entries, /* @__PURE__ */ new Date(), { webBaseUrl: webBase() })
|
|
8229
8535
|
);
|
|
@@ -8474,7 +8780,13 @@ async function submitSignedIn(token, payload, flags, interactive) {
|
|
|
8474
8780
|
afterSubmitChores(flags);
|
|
8475
8781
|
}
|
|
8476
8782
|
function afterSubmitChores(flags) {
|
|
8477
|
-
if (flags.quiet)
|
|
8783
|
+
if (flags.quiet) {
|
|
8784
|
+
try {
|
|
8785
|
+
if (autoSyncInstalled()) reconcileAutoSync();
|
|
8786
|
+
} catch {
|
|
8787
|
+
}
|
|
8788
|
+
return;
|
|
8789
|
+
}
|
|
8478
8790
|
try {
|
|
8479
8791
|
reconcileAutoSync();
|
|
8480
8792
|
} catch {
|
|
@@ -8562,6 +8874,11 @@ async function runDaemon() {
|
|
|
8562
8874
|
runOnce: async () => {
|
|
8563
8875
|
rotateLogIfLarge();
|
|
8564
8876
|
await run({ dryRun: false, noSubmit: false, local: false, quiet: true });
|
|
8877
|
+
if (!loadConfig()?.cliToken) {
|
|
8878
|
+
throw new Error(
|
|
8879
|
+
"not linked \u2014 nothing submitted (run `npx whoburnedmore link --token=\u2026` from your signed-in profile first)"
|
|
8880
|
+
);
|
|
8881
|
+
}
|
|
8565
8882
|
}
|
|
8566
8883
|
});
|
|
8567
8884
|
console.log();
|