agent-shim 11.86.4 → 11.86.5
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/cli.cjs +355 -297
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -16281,8 +16281,8 @@ function rewriteKeyNames(ctx) {
|
|
|
16281
16281
|
bySchema.set(entry.schema, entry);
|
|
16282
16282
|
}
|
|
16283
16283
|
const rewrites = /* @__PURE__ */ new Map();
|
|
16284
|
-
for (const
|
|
16285
|
-
const seen = ctx.seen.get(
|
|
16284
|
+
for (const record3 of pendingRecords.get(ctx) ?? []) {
|
|
16285
|
+
const seen = ctx.seen.get(record3);
|
|
16286
16286
|
const names = (seen?.def ?? seen?.schema)?.propertyNames;
|
|
16287
16287
|
if (!names || names === true || rewrites.has(names))
|
|
16288
16288
|
continue;
|
|
@@ -30516,9 +30516,9 @@ function frontDoorOrigin(state) {
|
|
|
30516
30516
|
const port = state?.directPort ?? state?.lastDirectPort;
|
|
30517
30517
|
return port === void 0 ? void 0 : directOrigin(port);
|
|
30518
30518
|
}
|
|
30519
|
-
function writeFrontDoorDirectRecord(fs35, recordsDir,
|
|
30519
|
+
function writeFrontDoorDirectRecord(fs35, recordsDir, record3) {
|
|
30520
30520
|
fs35.mkdirp(recordsDir);
|
|
30521
|
-
fs35.writeFilePrivate(import_node_path7.default.join(recordsDir, `${String(
|
|
30521
|
+
fs35.writeFilePrivate(import_node_path7.default.join(recordsDir, `${String(record3.pid)}.json`), `${JSON.stringify({ directPort: record3.directPort })}
|
|
30522
30522
|
`);
|
|
30523
30523
|
}
|
|
30524
30524
|
function removeFrontDoorDirectRecord(fs35, recordsDir, pid) {
|
|
@@ -30576,12 +30576,12 @@ function pruneMalformedFrontDoorDirectFiles(fs35, recordsDir, isRunning) {
|
|
|
30576
30576
|
}
|
|
30577
30577
|
}
|
|
30578
30578
|
function liveFrontDoorDirectRecords(records, liveness) {
|
|
30579
|
-
return records.filter((
|
|
30579
|
+
return records.filter((record3) => liveness.doors.has(record3.pid) || liveness.unknown.has(record3.pid));
|
|
30580
30580
|
}
|
|
30581
30581
|
function pruneDeadFrontDoorDirectRecords(fs35, recordsDir, records, liveness) {
|
|
30582
|
-
for (const
|
|
30583
|
-
if (!liveness.doors.has(
|
|
30584
|
-
removeFrontDoorDirectRecord(fs35, recordsDir,
|
|
30582
|
+
for (const record3 of records) {
|
|
30583
|
+
if (!liveness.doors.has(record3.pid) && !liveness.unknown.has(record3.pid)) {
|
|
30584
|
+
removeFrontDoorDirectRecord(fs35, recordsDir, record3.pid);
|
|
30585
30585
|
}
|
|
30586
30586
|
}
|
|
30587
30587
|
}
|
|
@@ -30613,9 +30613,9 @@ function readFrontDoorSessionRecord(fs35, sessionsDir, name) {
|
|
|
30613
30613
|
function listFrontDoorSessions(fs35, sessionsDir) {
|
|
30614
30614
|
const sessions = [];
|
|
30615
30615
|
for (const name of fs35.readdir(sessionsDir)) {
|
|
30616
|
-
const
|
|
30617
|
-
if (
|
|
30618
|
-
sessions.push(summaryOf(
|
|
30616
|
+
const record3 = isSessionRecordName(name) ? readFrontDoorSessionRecord(fs35, sessionsDir, name) : void 0;
|
|
30617
|
+
if (record3 !== void 0) {
|
|
30618
|
+
sessions.push(summaryOf(record3));
|
|
30619
30619
|
}
|
|
30620
30620
|
}
|
|
30621
30621
|
return sessions.sort((a10, b) => a10.pid - b.pid);
|
|
@@ -31127,8 +31127,8 @@ function captureFromEnv(env, logsDir) {
|
|
|
31127
31127
|
function createFileCapture(file2, now = () => /* @__PURE__ */ new Date()) {
|
|
31128
31128
|
fs3.mkdirSync(path9.dirname(file2), { recursive: true });
|
|
31129
31129
|
let nextId = 0;
|
|
31130
|
-
const append = (
|
|
31131
|
-
fs3.appendFileSync(file2, `${JSON.stringify({ ts: now().toISOString(), ...
|
|
31130
|
+
const append = (record3) => {
|
|
31131
|
+
fs3.appendFileSync(file2, `${JSON.stringify({ ts: now().toISOString(), ...record3 })}
|
|
31132
31132
|
`, { mode: CAPTURE_FILE_MODE });
|
|
31133
31133
|
};
|
|
31134
31134
|
return {
|
|
@@ -31755,16 +31755,16 @@ async function runSupervisor(initialConfig, ports, options = {}) {
|
|
|
31755
31755
|
}
|
|
31756
31756
|
}
|
|
31757
31757
|
function undeterminedFrontDoors(inputs) {
|
|
31758
|
-
return inputs.frontDoorRecords.flatMap((
|
|
31759
|
-
const reason = inputs.frontDoorLiveness.unknown.get(
|
|
31760
|
-
return reason === void 0 ? [] : [{ pid:
|
|
31758
|
+
return inputs.frontDoorRecords.flatMap((record3) => {
|
|
31759
|
+
const reason = inputs.frontDoorLiveness.unknown.get(record3.pid);
|
|
31760
|
+
return reason === void 0 ? [] : [{ pid: record3.pid, origin: directOrigin(record3.directPort), reason }];
|
|
31761
31761
|
});
|
|
31762
31762
|
}
|
|
31763
31763
|
function currentHeadroomAllowlistInputs(fs35, paths, frontDoorLiveness) {
|
|
31764
31764
|
const named = frontDoorOrigin(readFrontDoorState(fs35, paths.frontdoorStateFile));
|
|
31765
31765
|
const records = listFrontDoorDirectRecords(fs35, paths.frontdoorDirectRecordsDir);
|
|
31766
|
-
const liveness = frontDoorLiveness(records.map((
|
|
31767
|
-
const live = liveFrontDoorDirectRecords(records, liveness).map((
|
|
31766
|
+
const liveness = frontDoorLiveness(records.map((record3) => record3.pid));
|
|
31767
|
+
const live = liveFrontDoorDirectRecords(records, liveness).map((record3) => directOrigin(record3.directPort));
|
|
31768
31768
|
return {
|
|
31769
31769
|
frontDoorRecords: records,
|
|
31770
31770
|
frontDoorLiveness: liveness,
|
|
@@ -33130,30 +33130,30 @@ function readIdentityRecords(port, identitiesDir) {
|
|
|
33130
33130
|
}
|
|
33131
33131
|
}
|
|
33132
33132
|
const sorted = [...records].map(([id2, name]) => ({ id: id2, name })).sort((left, right) => left.id < right.id ? -1 : left.id > right.id ? 1 : 0);
|
|
33133
|
-
return sorted.filter((
|
|
33134
|
-
const twins = sorted.filter((other) => other.name ===
|
|
33133
|
+
return sorted.filter((record3) => {
|
|
33134
|
+
const twins = sorted.filter((other) => other.name === record3.name && port.sameDirectory(import_node_path14.default.join(identitiesDir, other.id), import_node_path14.default.join(identitiesDir, record3.id)));
|
|
33135
33135
|
const kept = twins.find((twin) => !port.isSymlink(import_node_path14.default.join(identitiesDir, twin.id))) ?? twins[0];
|
|
33136
|
-
return kept === void 0 || kept.id ===
|
|
33136
|
+
return kept === void 0 || kept.id === record3.id;
|
|
33137
33137
|
});
|
|
33138
33138
|
}
|
|
33139
33139
|
function duplicateIdentityNames(records) {
|
|
33140
33140
|
const byName = /* @__PURE__ */ new Map();
|
|
33141
|
-
for (const
|
|
33142
|
-
if (
|
|
33143
|
-
byName.set(
|
|
33141
|
+
for (const record3 of records) {
|
|
33142
|
+
if (record3.name !== void 0) {
|
|
33143
|
+
byName.set(record3.name, [...byName.get(record3.name) ?? [], record3.id]);
|
|
33144
33144
|
}
|
|
33145
33145
|
}
|
|
33146
33146
|
return [...byName].filter(([, ids]) => ids.length > 1).map(([name, ids]) => ({ name, ids }));
|
|
33147
33147
|
}
|
|
33148
33148
|
function identityIdIn(records, name) {
|
|
33149
|
-
const matches2 = records.filter((
|
|
33149
|
+
const matches2 = records.filter((record3) => record3.name === name);
|
|
33150
33150
|
if (matches2.length > 1) {
|
|
33151
|
-
throw new DuplicateIdentityNameError(name, matches2.map((
|
|
33151
|
+
throw new DuplicateIdentityNameError(name, matches2.map((record3) => record3.id));
|
|
33152
33152
|
}
|
|
33153
|
-
return matches2[0]?.id ?? records.find((
|
|
33153
|
+
return matches2[0]?.id ?? records.find((record3) => record3.name === void 0 && record3.id === name)?.id;
|
|
33154
33154
|
}
|
|
33155
33155
|
function identityNameIn(records, id2) {
|
|
33156
|
-
return records.find((
|
|
33156
|
+
return records.find((record3) => record3.id === id2)?.name;
|
|
33157
33157
|
}
|
|
33158
33158
|
function freeIdentityId(name, taken) {
|
|
33159
33159
|
if (!taken(name)) {
|
|
@@ -34249,9 +34249,9 @@ function readUsageLog(fs35, logDir, options = {}) {
|
|
|
34249
34249
|
continue;
|
|
34250
34250
|
}
|
|
34251
34251
|
invalidLines += read.invalidLines;
|
|
34252
|
-
for (const
|
|
34253
|
-
if (sinceMs === void 0 || Date.parse(
|
|
34254
|
-
records.push(
|
|
34252
|
+
for (const record3 of read.records) {
|
|
34253
|
+
if (sinceMs === void 0 || Date.parse(record3.at) >= sinceMs) {
|
|
34254
|
+
records.push(record3);
|
|
34255
34255
|
}
|
|
34256
34256
|
}
|
|
34257
34257
|
}
|
|
@@ -34343,13 +34343,13 @@ function listUsageSnapshots(fs35, snapshotsDir) {
|
|
|
34343
34343
|
}
|
|
34344
34344
|
function summariseUsage(records) {
|
|
34345
34345
|
const groups = /* @__PURE__ */ new Map();
|
|
34346
|
-
for (const
|
|
34347
|
-
const key = `${
|
|
34346
|
+
for (const record3 of records) {
|
|
34347
|
+
const key = `${record3.identity ?? ""}\0${record3.provider}`;
|
|
34348
34348
|
const group = groups.get(key);
|
|
34349
34349
|
if (group === void 0) {
|
|
34350
|
-
groups.set(key, [
|
|
34350
|
+
groups.set(key, [record3]);
|
|
34351
34351
|
} else {
|
|
34352
|
-
group.push(
|
|
34352
|
+
group.push(record3);
|
|
34353
34353
|
}
|
|
34354
34354
|
}
|
|
34355
34355
|
const summaries = [...groups.values()].flatMap((group) => {
|
|
@@ -34359,21 +34359,21 @@ function summariseUsage(records) {
|
|
|
34359
34359
|
return [];
|
|
34360
34360
|
}
|
|
34361
34361
|
const modelCounts = /* @__PURE__ */ new Map();
|
|
34362
|
-
for (const
|
|
34363
|
-
if (
|
|
34364
|
-
modelCounts.set(
|
|
34362
|
+
for (const record3 of group) {
|
|
34363
|
+
if (record3.model !== void 0) {
|
|
34364
|
+
modelCounts.set(record3.model, (modelCounts.get(record3.model) ?? 0) + 1);
|
|
34365
34365
|
}
|
|
34366
34366
|
}
|
|
34367
|
-
const sum2 = (field) => group.reduce((total,
|
|
34367
|
+
const sum2 = (field) => group.reduce((total, record3) => total + (record3.usage?.[field] ?? 0), 0);
|
|
34368
34368
|
return [
|
|
34369
34369
|
{
|
|
34370
34370
|
identity: first.identity,
|
|
34371
34371
|
provider: first.provider,
|
|
34372
34372
|
requests: group.length,
|
|
34373
|
-
failed: group.filter((
|
|
34373
|
+
failed: group.filter((record3) => record3.status >= FIRST_ERROR_STATUS).length,
|
|
34374
34374
|
limits: {
|
|
34375
|
-
"rate-limited": group.filter((
|
|
34376
|
-
"quota-exhausted": group.filter((
|
|
34375
|
+
"rate-limited": group.filter((record3) => record3.limit?.kind === "rate-limited").length,
|
|
34376
|
+
"quota-exhausted": group.filter((record3) => record3.limit?.kind === "quota-exhausted").length
|
|
34377
34377
|
},
|
|
34378
34378
|
tokens: {
|
|
34379
34379
|
inputTokens: sum2("inputTokens"),
|
|
@@ -35538,8 +35538,8 @@ function acquireIdentityLock(params) {
|
|
|
35538
35538
|
}
|
|
35539
35539
|
let lastHolderPid;
|
|
35540
35540
|
for (let attempt = 0; attempt < maxAttempts; attempt += 1) {
|
|
35541
|
-
const
|
|
35542
|
-
if (params.fs.writeFileExclusive(lockPath, `${JSON.stringify(
|
|
35541
|
+
const record3 = { identity: params.identity, pid: params.pid, token, acquiredAtMs: params.nowMs() };
|
|
35542
|
+
if (params.fs.writeFileExclusive(lockPath, `${JSON.stringify(record3)}
|
|
35543
35543
|
`)) {
|
|
35544
35544
|
return {
|
|
35545
35545
|
path: lockPath,
|
|
@@ -36717,10 +36717,10 @@ function windowBlockedUntil(windows) {
|
|
|
36717
36717
|
}
|
|
36718
36718
|
function windowBurn(records, which) {
|
|
36719
36719
|
const points = [];
|
|
36720
|
-
for (const
|
|
36721
|
-
const window =
|
|
36720
|
+
for (const record3 of records) {
|
|
36721
|
+
const window = record3.rateLimitHeaders === void 0 ? void 0 : parseUnifiedRateLimit(record3.rateLimitHeaders)?.[which];
|
|
36722
36722
|
if (window?.utilization !== void 0 && window.resetsAt !== void 0) {
|
|
36723
|
-
points.push({ resetsAt: window.resetsAt, point: { atMs: Date.parse(
|
|
36723
|
+
points.push({ resetsAt: window.resetsAt, point: { atMs: Date.parse(record3.at), utilization: window.utilization } });
|
|
36724
36724
|
}
|
|
36725
36725
|
}
|
|
36726
36726
|
const latest = points.at(-1)?.resetsAt;
|
|
@@ -36732,16 +36732,16 @@ function windowBurn(records, which) {
|
|
|
36732
36732
|
}
|
|
36733
36733
|
return (last.utilization - first.utilization) / (last.atMs - first.atMs);
|
|
36734
36734
|
}
|
|
36735
|
-
function billedTokensOf(
|
|
36736
|
-
const usage =
|
|
36735
|
+
function billedTokensOf(record3) {
|
|
36736
|
+
const usage = record3.usage;
|
|
36737
36737
|
return (usage?.inputTokens ?? 0) + (usage?.cacheCreationInputTokens ?? 0) + (usage?.outputTokens ?? 0);
|
|
36738
36738
|
}
|
|
36739
36739
|
function utilisationPerBilledToken(records, which) {
|
|
36740
36740
|
const points = [];
|
|
36741
|
-
for (const
|
|
36742
|
-
const window =
|
|
36741
|
+
for (const record3 of records) {
|
|
36742
|
+
const window = record3.rateLimitHeaders === void 0 ? void 0 : parseUnifiedRateLimit(record3.rateLimitHeaders)?.[which];
|
|
36743
36743
|
if (window?.utilization !== void 0 && window.resetsAt !== void 0) {
|
|
36744
|
-
points.push({ resetsAt: window.resetsAt, utilization: window.utilization, billed: billedTokensOf(
|
|
36744
|
+
points.push({ resetsAt: window.resetsAt, utilization: window.utilization, billed: billedTokensOf(record3) });
|
|
36745
36745
|
}
|
|
36746
36746
|
}
|
|
36747
36747
|
const latest = points.at(-1)?.resetsAt;
|
|
@@ -36756,8 +36756,8 @@ function utilisationPerBilledToken(records, which) {
|
|
|
36756
36756
|
}
|
|
36757
36757
|
function windowRatio(records) {
|
|
36758
36758
|
const points = [];
|
|
36759
|
-
for (const
|
|
36760
|
-
const unified =
|
|
36759
|
+
for (const record3 of records) {
|
|
36760
|
+
const unified = record3.rateLimitHeaders === void 0 ? void 0 : parseUnifiedRateLimit(record3.rateLimitHeaders);
|
|
36761
36761
|
const five = unified?.fiveHour;
|
|
36762
36762
|
const seven = unified?.sevenDay;
|
|
36763
36763
|
if (five?.utilization !== void 0 && five.resetsAt !== void 0 && seven?.utilization !== void 0 && seven.resetsAt !== void 0) {
|
|
@@ -37007,21 +37007,21 @@ function pruneUsageLog(fs35, logDir, nowMs) {
|
|
|
37007
37007
|
function later(left, right) {
|
|
37008
37008
|
return left.localeCompare(right) >= 0 ? left : right;
|
|
37009
37009
|
}
|
|
37010
|
-
function observedAt(
|
|
37011
|
-
return new Date(Date.parse(
|
|
37010
|
+
function observedAt(record3) {
|
|
37011
|
+
return new Date(Date.parse(record3.at) + record3.latencyMs).toISOString();
|
|
37012
37012
|
}
|
|
37013
|
-
function foldProviderState(current,
|
|
37014
|
-
const seen = observedAt(
|
|
37015
|
-
const newest = current?.lastRequestAt === void 0 ||
|
|
37016
|
-
const rateLimit =
|
|
37017
|
-
const unified = parseUnifiedRateLimit(
|
|
37018
|
-
return { observedAt: seen, headers:
|
|
37013
|
+
function foldProviderState(current, record3) {
|
|
37014
|
+
const seen = observedAt(record3);
|
|
37015
|
+
const newest = current?.lastRequestAt === void 0 || record3.at.localeCompare(current.lastRequestAt) >= 0;
|
|
37016
|
+
const rateLimit = record3.rateLimitHeaders === void 0 || current?.rateLimit !== void 0 && current.rateLimit.observedAt.localeCompare(seen) > 0 ? current?.rateLimit : (() => {
|
|
37017
|
+
const unified = parseUnifiedRateLimit(record3.rateLimitHeaders);
|
|
37018
|
+
return { observedAt: seen, headers: record3.rateLimitHeaders, ...unified === void 0 ? {} : { unified } };
|
|
37019
37019
|
})();
|
|
37020
|
-
const lastLimit =
|
|
37021
|
-
const lastModel = newest ?
|
|
37020
|
+
const lastLimit = record3.limit === void 0 || current?.lastLimit !== void 0 && current.lastLimit.observedAt.localeCompare(seen) > 0 ? current?.lastLimit : { ...record3.limit, observedAt: seen, status: record3.status };
|
|
37021
|
+
const lastModel = newest ? record3.model ?? current?.lastModel : current.lastModel ?? record3.model;
|
|
37022
37022
|
return {
|
|
37023
|
-
lastRequestAt: current?.lastRequestAt === void 0 ?
|
|
37024
|
-
...newest ? { lastStatus:
|
|
37023
|
+
lastRequestAt: current?.lastRequestAt === void 0 ? record3.at : later(current.lastRequestAt, record3.at),
|
|
37024
|
+
...newest ? { lastStatus: record3.status } : current.lastStatus === void 0 ? {} : { lastStatus: current.lastStatus },
|
|
37025
37025
|
...lastModel === void 0 ? {} : { lastModel },
|
|
37026
37026
|
...rateLimit === void 0 ? {} : { rateLimit },
|
|
37027
37027
|
...lastLimit === void 0 ? {} : { lastLimit },
|
|
@@ -37073,7 +37073,7 @@ function createUsageStore(deps) {
|
|
|
37073
37073
|
};
|
|
37074
37074
|
return {
|
|
37075
37075
|
record: (input2) => {
|
|
37076
|
-
const
|
|
37076
|
+
const record3 = UsageRecordSchema.parse(input2);
|
|
37077
37077
|
const nowMs = deps.now();
|
|
37078
37078
|
fs35.mkdirPrivate(paths.usageDir);
|
|
37079
37079
|
fs35.mkdirPrivate(paths.usageLogDir);
|
|
@@ -37082,11 +37082,11 @@ function createUsageStore(deps) {
|
|
|
37082
37082
|
pruneUsageLog(fs35, paths.usageLogDir, nowMs);
|
|
37083
37083
|
prunedDay = day;
|
|
37084
37084
|
}
|
|
37085
|
-
fs35.appendFilePrivate(import_node_path22.default.join(paths.usageLogDir, segmentName(day, deps.pid)), `${JSON.stringify(
|
|
37085
|
+
fs35.appendFilePrivate(import_node_path22.default.join(paths.usageLogDir, segmentName(day, deps.pid)), `${JSON.stringify(record3)}
|
|
37086
37086
|
`);
|
|
37087
|
-
deps.onRecord?.(
|
|
37088
|
-
if (
|
|
37089
|
-
rewriteSnapshot(
|
|
37087
|
+
deps.onRecord?.(record3);
|
|
37088
|
+
if (record3.identity !== void 0) {
|
|
37089
|
+
rewriteSnapshot(record3.identity, (current) => ({ ...current?.providers, [record3.provider]: foldProviderState(current?.providers[record3.provider], record3) }));
|
|
37090
37090
|
}
|
|
37091
37091
|
},
|
|
37092
37092
|
recordQuota: (identity, provider, quota) => rewriteSnapshot(identity, (current) => {
|
|
@@ -37133,7 +37133,7 @@ function loadPoolMembers(fs35, paths, identities, nowMs, idOf) {
|
|
|
37133
37133
|
if (id2 === void 0) {
|
|
37134
37134
|
return { identity, records: [] };
|
|
37135
37135
|
}
|
|
37136
|
-
const records = log.records.filter((
|
|
37136
|
+
const records = log.records.filter((record3) => record3.identity === id2 && record3.provider === ANTHROPIC_PROVIDER && Date.parse(record3.at) >= windowStartMs);
|
|
37137
37137
|
try {
|
|
37138
37138
|
const snapshot = readUsageSnapshot(fs35, paths.usageSnapshotsDir, id2);
|
|
37139
37139
|
const account = readAccountMetadata(fs35, paths.identitiesDir, id2) ?? snapshot?.account;
|
|
@@ -37489,9 +37489,9 @@ function readNameRenameRecords(paths) {
|
|
|
37489
37489
|
function strayNameRenameRecordFiles(paths) {
|
|
37490
37490
|
return readRecordFiles(paths).filter((entry) => !isFiledForItsPair(entry)).map((entry) => entry.file);
|
|
37491
37491
|
}
|
|
37492
|
-
function writeNameRenameRecord(paths,
|
|
37492
|
+
function writeNameRenameRecord(paths, record3) {
|
|
37493
37493
|
realFarmFs.mkdirPrivate(paths.identityNameRenamesDir);
|
|
37494
|
-
realFarmFs.writeFilePrivate(recordFile(paths,
|
|
37494
|
+
realFarmFs.writeFilePrivate(recordFile(paths, record3.from, record3.to), `${JSON.stringify(NameRenameRecordSchema.parse(record3), null, 2)}
|
|
37495
37495
|
`, { durable: true });
|
|
37496
37496
|
}
|
|
37497
37497
|
function removeNameRenameRecord(paths, from, to2) {
|
|
@@ -37512,20 +37512,20 @@ function referencesToName(paths, name) {
|
|
|
37512
37512
|
const picked = picksText === void 0 ? void 0 : picksWithIdentityRenamed(picksText, name, name)?.renamed;
|
|
37513
37513
|
return [...pools, ...jobs, ...models, ...profiles, ...rules, ...active, ...picked === void 0 ? [] : [`${String(picked)} recorded pool pick${picked === 1 ? "" : "s"}`]];
|
|
37514
37514
|
}
|
|
37515
|
-
function isSettled(paths,
|
|
37516
|
-
const stored2 = records.find((candidate) => candidate.id ===
|
|
37515
|
+
function isSettled(paths, record3, records) {
|
|
37516
|
+
const stored2 = records.find((candidate) => candidate.id === record3.id);
|
|
37517
37517
|
if (stored2 === void 0) {
|
|
37518
37518
|
return true;
|
|
37519
37519
|
}
|
|
37520
|
-
if (stored2.name !==
|
|
37520
|
+
if (stored2.name !== record3.to) {
|
|
37521
37521
|
return false;
|
|
37522
37522
|
}
|
|
37523
|
-
const shared = records.some((candidate) => candidate.id !==
|
|
37524
|
-
return shared || referencesToName(paths,
|
|
37523
|
+
const shared = records.some((candidate) => candidate.id !== record3.id && candidate.name === record3.from);
|
|
37524
|
+
return shared || referencesToName(paths, record3.from).length === 0;
|
|
37525
37525
|
}
|
|
37526
37526
|
function unfinishedNameRenames(paths) {
|
|
37527
37527
|
const records = identityRecordsOver(realFarmFs, paths.identitiesDir);
|
|
37528
|
-
return readNameRenameRecords(paths).filter((
|
|
37528
|
+
return readNameRenameRecords(paths).filter((record3) => !isSettled(paths, record3, records));
|
|
37529
37529
|
}
|
|
37530
37530
|
function removeSettledNameRenames(paths) {
|
|
37531
37531
|
const records = identityRecordsOver(realFarmFs, paths.identitiesDir);
|
|
@@ -37533,19 +37533,19 @@ function removeSettledNameRenames(paths) {
|
|
|
37533
37533
|
import_node_fs10.default.rmSync(entry.file, { force: true });
|
|
37534
37534
|
}
|
|
37535
37535
|
}
|
|
37536
|
-
function describeInterruptedNameRename(paths,
|
|
37537
|
-
const references = referencesToName(paths,
|
|
37538
|
-
const rewritten = references.length === 0 ? "" : ` and has already rewritten references to "${
|
|
37539
|
-
const claimants = identityRecordsOver(realFarmFs, paths.identitiesDir).filter((candidate) => candidate.name ===
|
|
37540
|
-
const finish = claimants > 1 ||
|
|
37541
|
-
return `A rename of identity "${
|
|
37536
|
+
function describeInterruptedNameRename(paths, record3) {
|
|
37537
|
+
const references = referencesToName(paths, record3.to);
|
|
37538
|
+
const rewritten = references.length === 0 ? "" : ` and has already rewritten references to "${record3.to}" (${references.join(", ")})`;
|
|
37539
|
+
const claimants = identityRecordsOver(realFarmFs, paths.identitiesDir).filter((candidate) => candidate.name === record3.from).length;
|
|
37540
|
+
const finish = claimants > 1 || record3.id !== record3.from ? `agent-shim identity rename ${record3.id} ${record3.to} --id` : `agent-shim identity rename ${record3.from} ${record3.to}`;
|
|
37541
|
+
return `A rename of identity "${record3.from}" to "${record3.to}" was interrupted${rewritten}. Finish it with \`${finish}\`.`;
|
|
37542
37542
|
}
|
|
37543
37543
|
function missingIdentityRemedy(paths, name) {
|
|
37544
|
-
const giving = unfinishedNameRenames(paths).find((
|
|
37544
|
+
const giving = unfinishedNameRenames(paths).find((record3) => record3.to === name);
|
|
37545
37545
|
return giving === void 0 ? `Run \`agent-shim identity add ${name}\` first.` : describeInterruptedNameRename(paths, giving);
|
|
37546
37546
|
}
|
|
37547
37547
|
function requireNoInterruptedNameRename(paths, name, action, except) {
|
|
37548
|
-
const held = unfinishedNameRenames(paths).find((
|
|
37548
|
+
const held = unfinishedNameRenames(paths).find((record3) => (record3.from === name || record3.to === name) && !(record3.id === except?.id && record3.from === except.from && record3.to === except.to));
|
|
37549
37549
|
if (held !== void 0) {
|
|
37550
37550
|
throw new InterruptedNameRenameError(action, describeInterruptedNameRename(paths, held));
|
|
37551
37551
|
}
|
|
@@ -37607,14 +37607,14 @@ function readRecord(fs35, directory, name) {
|
|
|
37607
37607
|
function registerLaunch(fs35, directory, owner, isRunning) {
|
|
37608
37608
|
fs35.mkdirPrivate(directory);
|
|
37609
37609
|
for (const name of fs35.readdir(directory)) {
|
|
37610
|
-
const
|
|
37611
|
-
if (
|
|
37610
|
+
const record4 = readRecord(fs35, directory, name);
|
|
37611
|
+
if (record4 !== void 0 && !isRunning(record4.pid)) {
|
|
37612
37612
|
fs35.removeRecursive(import_node_path26.default.join(directory, name));
|
|
37613
37613
|
}
|
|
37614
37614
|
}
|
|
37615
37615
|
const file2 = recordFile2(directory, owner.pid);
|
|
37616
|
-
const
|
|
37617
|
-
fs35.writeFilePrivate(file2, `${JSON.stringify(
|
|
37616
|
+
const record3 = { pid: owner.pid, identity: owner.identity, startedAt: new Date(owner.startedAtMs).toISOString() };
|
|
37617
|
+
fs35.writeFilePrivate(file2, `${JSON.stringify(record3)}
|
|
37618
37618
|
`);
|
|
37619
37619
|
return () => {
|
|
37620
37620
|
fs35.removeRecursive(file2);
|
|
@@ -37622,8 +37622,8 @@ function registerLaunch(fs35, directory, owner, isRunning) {
|
|
|
37622
37622
|
}
|
|
37623
37623
|
function liveLaunchesOn(fs35, directory, identity, isRunning) {
|
|
37624
37624
|
return fs35.readdir(directory).flatMap((name) => {
|
|
37625
|
-
const
|
|
37626
|
-
return
|
|
37625
|
+
const record3 = readRecord(fs35, directory, name);
|
|
37626
|
+
return record3?.identity === identity && isRunning(record3.pid) ? [record3.pid] : [];
|
|
37627
37627
|
}).sort((left, right) => left - right);
|
|
37628
37628
|
}
|
|
37629
37629
|
var import_node_path26, import_node_crypto9, LaunchRecordSchema, RECORD_SUFFIX2;
|
|
@@ -37716,10 +37716,10 @@ function createIdentityNameReader(paths) {
|
|
|
37716
37716
|
};
|
|
37717
37717
|
}
|
|
37718
37718
|
function identityLabeller(paths) {
|
|
37719
|
-
const records = new Map(identityRecords(paths).map((
|
|
37719
|
+
const records = new Map(identityRecords(paths).map((record3) => [record3.id, record3]));
|
|
37720
37720
|
return (id2) => {
|
|
37721
|
-
const
|
|
37722
|
-
return
|
|
37721
|
+
const record3 = records.get(id2);
|
|
37722
|
+
return record3 === void 0 ? goneIdentityLabel(id2) : record3.name ?? unreadableIdentityLabel(id2);
|
|
37723
37723
|
};
|
|
37724
37724
|
}
|
|
37725
37725
|
function unreadableIdentityLabel(id2) {
|
|
@@ -37771,7 +37771,7 @@ function idKeyedFiles(paths, id2) {
|
|
|
37771
37771
|
function loggedIdentityIds(paths) {
|
|
37772
37772
|
let logged;
|
|
37773
37773
|
return () => {
|
|
37774
|
-
logged ??= new Set(readUsageLog(realUsageReadFs, paths.usageLogDir).records.flatMap((
|
|
37774
|
+
logged ??= new Set(readUsageLog(realUsageReadFs, paths.usageLogDir).records.flatMap((record3) => record3.identity === void 0 ? [] : [record3.identity]));
|
|
37775
37775
|
return logged;
|
|
37776
37776
|
};
|
|
37777
37777
|
}
|
|
@@ -37781,7 +37781,7 @@ function idAllocation(paths, keychain, loggedIds) {
|
|
|
37781
37781
|
loggedIds,
|
|
37782
37782
|
keychain,
|
|
37783
37783
|
recordIds: () => {
|
|
37784
|
-
recordIds ??= identityRecords(paths).map((
|
|
37784
|
+
recordIds ??= identityRecords(paths).map((record3) => record3.id);
|
|
37785
37785
|
return recordIds;
|
|
37786
37786
|
}
|
|
37787
37787
|
};
|
|
@@ -37956,7 +37956,7 @@ function listIdentities(paths) {
|
|
|
37956
37956
|
return [];
|
|
37957
37957
|
}
|
|
37958
37958
|
const active = readActiveIdentity2(paths);
|
|
37959
|
-
const names = new Map(identityRecords(paths).map((
|
|
37959
|
+
const names = new Map(identityRecords(paths).map((record3) => [record3.id, record3.name]));
|
|
37960
37960
|
const result = [];
|
|
37961
37961
|
for (const id2 of listIdentityDirectories(paths).names) {
|
|
37962
37962
|
const read = readIdentityForListing(paths, id2);
|
|
@@ -37971,9 +37971,9 @@ function listIdentities(paths) {
|
|
|
37971
37971
|
result.push("problem" in read ? { name, id: id2, isActive, problem: read.problem } : { name, id: id2, identity: read, isActive });
|
|
37972
37972
|
}
|
|
37973
37973
|
const unreachable = new Set(listIdentityDirectories(paths).unreachable.map((entry) => entry.name));
|
|
37974
|
-
for (const
|
|
37975
|
-
const name =
|
|
37976
|
-
result.push({ name, id:
|
|
37974
|
+
for (const record3 of identityRecords(paths).filter((candidate) => !identityIdExists(paths, candidate.id) && !unreachable.has(candidate.id))) {
|
|
37975
|
+
const name = record3.name ?? record3.id;
|
|
37976
|
+
result.push({ name, id: record3.id, isActive: name === active, problem: DISPLACED_PROBLEM, displaced: true });
|
|
37977
37977
|
}
|
|
37978
37978
|
return result.sort((left, right) => left.name < right.name ? -1 : left.name > right.name ? 1 : left.id < right.id ? -1 : left.id > right.id ? 1 : 0);
|
|
37979
37979
|
}
|
|
@@ -41958,7 +41958,7 @@ var init_package = __esm({
|
|
|
41958
41958
|
"package.json"() {
|
|
41959
41959
|
package_default = {
|
|
41960
41960
|
name: "agent-shim",
|
|
41961
|
-
version: "11.86.
|
|
41961
|
+
version: "11.86.5",
|
|
41962
41962
|
description: "A profile manager and launcher for Claude Code that lets one person run multiple logins from one machine while controlling what gets shared between them.",
|
|
41963
41963
|
license: "MIT",
|
|
41964
41964
|
author: "Joseph Mearman <joseph@mearman.co.uk>",
|
|
@@ -57497,17 +57497,17 @@ var require_dns = __commonJS({
|
|
|
57497
57497
|
const timestamp = Date.now();
|
|
57498
57498
|
const records = { records: { 4: null, 6: null } };
|
|
57499
57499
|
let minTTL = this.#maxTTL;
|
|
57500
|
-
for (const
|
|
57501
|
-
|
|
57502
|
-
if (typeof
|
|
57503
|
-
|
|
57504
|
-
minTTL = Math.min(minTTL,
|
|
57500
|
+
for (const record3 of addresses) {
|
|
57501
|
+
record3.timestamp = timestamp;
|
|
57502
|
+
if (typeof record3.ttl === "number") {
|
|
57503
|
+
record3.ttl = Math.min(record3.ttl, this.#maxTTL);
|
|
57504
|
+
minTTL = Math.min(minTTL, record3.ttl);
|
|
57505
57505
|
} else {
|
|
57506
|
-
|
|
57506
|
+
record3.ttl = this.#maxTTL;
|
|
57507
57507
|
}
|
|
57508
|
-
const familyRecords = records.records[
|
|
57509
|
-
familyRecords.ips.push(
|
|
57510
|
-
records.records[
|
|
57508
|
+
const familyRecords = records.records[record3.family] ?? { ips: [] };
|
|
57509
|
+
familyRecords.ips.push(record3);
|
|
57510
|
+
records.records[record3.family] = familyRecords;
|
|
57511
57511
|
}
|
|
57512
57512
|
this.storage.set(origin.hostname, records, { ttl: minTTL });
|
|
57513
57513
|
}
|
|
@@ -73926,9 +73926,9 @@ function createProviderLookup(ports) {
|
|
|
73926
73926
|
};
|
|
73927
73927
|
};
|
|
73928
73928
|
}
|
|
73929
|
-
function withQuotaRefresh(
|
|
73929
|
+
function withQuotaRefresh(record3, refresher) {
|
|
73930
73930
|
return (usageRecord) => {
|
|
73931
|
-
|
|
73931
|
+
record3(usageRecord);
|
|
73932
73932
|
if (usageRecord.identity !== void 0 && usageRecord.provider !== ANTHROPIC_PROVIDER) {
|
|
73933
73933
|
void refresher.refresh(usageRecord.identity, usageRecord.provider);
|
|
73934
73934
|
}
|
|
@@ -122545,18 +122545,18 @@ var NamelessIdentityError = class extends CliError {
|
|
|
122545
122545
|
};
|
|
122546
122546
|
function renamedIdentity(paths, from, options) {
|
|
122547
122547
|
const records = identityRecords(paths);
|
|
122548
|
-
const
|
|
122549
|
-
if (
|
|
122548
|
+
const record3 = options.byId === true ? records.find((candidate) => candidate.id === from) : records.find((candidate) => candidate.id === requireIdentityId(paths, from));
|
|
122549
|
+
if (record3 === void 0) {
|
|
122550
122550
|
throw new UnknownIdentityIdError(from);
|
|
122551
122551
|
}
|
|
122552
|
-
const { name } =
|
|
122552
|
+
const { name } = record3;
|
|
122553
122553
|
if (name === void 0) {
|
|
122554
|
-
throw new NamelessIdentityError(
|
|
122554
|
+
throw new NamelessIdentityError(record3.id);
|
|
122555
122555
|
}
|
|
122556
|
-
if (!identityIdExists(paths,
|
|
122557
|
-
throw displacedIdentity(paths, "renamed", name,
|
|
122556
|
+
if (!identityIdExists(paths, record3.id)) {
|
|
122557
|
+
throw displacedIdentity(paths, "renamed", name, record3.id);
|
|
122558
122558
|
}
|
|
122559
|
-
return { id:
|
|
122559
|
+
return { id: record3.id, name, shared: records.some((other) => other.id !== record3.id && other.name === name) };
|
|
122560
122560
|
}
|
|
122561
122561
|
|
|
122562
122562
|
// src/identityRename.ts
|
|
@@ -123126,7 +123126,7 @@ function snapshotStep(paths, ports, from, to2) {
|
|
|
123126
123126
|
function usageWindowNote(paths, ports, from, to2) {
|
|
123127
123127
|
const windowStartMs = ports.lock.nowMs() - FIVE_HOUR_WINDOW_MS;
|
|
123128
123128
|
const { records } = readUsageLog(ports.fs, paths.usageLogDir, { sinceMs: windowStartMs });
|
|
123129
|
-
const logged = records.some((
|
|
123129
|
+
const logged = records.some((record3) => record3.identity === from && record3.provider === ANTHROPIC_PROVIDER && Date.parse(record3.at) >= windowStartMs);
|
|
123130
123130
|
return logged ? `Usage already logged for "${from}" in the last five hours stays filed under that id: the usage log is appended to by the running front door, so it is not rewritten. Until those hours pass, pool ranking has no burn rate or five-hour to seven-day ratio for "${to2}" from them. Its quota windows come from its snapshot, which moved, and are unaffected.` : void 0;
|
|
123131
123131
|
}
|
|
123132
123132
|
function credentialHolderSteps(paths, ports, from, to2, moved) {
|
|
@@ -123462,7 +123462,7 @@ async function applyUnderLocks(paths, from, to2, ports, gathered, hooks) {
|
|
|
123462
123462
|
const marks = [...carried.map((step2) => ({ started: true, done: step2.done })), ...plan.steps.map(() => ({ started: false, done: false }))];
|
|
123463
123463
|
const descriptions = [...carried.map((step2) => step2.description), ...plan.steps.map((step2) => step2.description)];
|
|
123464
123464
|
const startedAt = resumed?.startedAt ?? new Date(ports.lock.nowMs()).toISOString();
|
|
123465
|
-
const
|
|
123465
|
+
const record3 = () => {
|
|
123466
123466
|
writeRenameJournal(ports.fs, file2, { version: 1, from, to: to2, startedAt, pid: ports.lock.pid, steps: descriptions.map((description, position) => ({ description, started: marks[position]?.started === true, done: marks[position]?.done === true })) });
|
|
123467
123467
|
};
|
|
123468
123468
|
const positionOf = (index) => carried.length + index;
|
|
@@ -123475,14 +123475,14 @@ async function applyUnderLocks(paths, from, to2, ports, gathered, hooks) {
|
|
|
123475
123475
|
};
|
|
123476
123476
|
const save = (index, when) => {
|
|
123477
123477
|
try {
|
|
123478
|
-
|
|
123478
|
+
record3();
|
|
123479
123479
|
} catch (failure2) {
|
|
123480
123480
|
throw new JournalWriteError(failure2, `${when} "${descriptions[positionOf(index)] ?? String(index)}"`);
|
|
123481
123481
|
}
|
|
123482
123482
|
};
|
|
123483
123483
|
try {
|
|
123484
123484
|
try {
|
|
123485
|
-
|
|
123485
|
+
record3();
|
|
123486
123486
|
} catch (failure2) {
|
|
123487
123487
|
throw new JournalWriteError(failure2, "before the first step", rolledBackOutcome(resumed !== void 0));
|
|
123488
123488
|
}
|
|
@@ -123508,7 +123508,7 @@ async function applyUnderLocks(paths, from, to2, ports, gathered, hooks) {
|
|
|
123508
123508
|
const mark = markOf(index);
|
|
123509
123509
|
mark.started = false;
|
|
123510
123510
|
mark.done = false;
|
|
123511
|
-
|
|
123511
|
+
record3();
|
|
123512
123512
|
}
|
|
123513
123513
|
});
|
|
123514
123514
|
} catch (error63) {
|
|
@@ -123583,7 +123583,7 @@ async function renameIdentity(paths, from, to2, ports, options = {}) {
|
|
|
123583
123583
|
});
|
|
123584
123584
|
try {
|
|
123585
123585
|
const plan = planNameChange(paths, from, to2, ports, options);
|
|
123586
|
-
const resumed = unfinishedNameRenames(paths).find((
|
|
123586
|
+
const resumed = unfinishedNameRenames(paths).find((record3) => record3.id === id2 && record3.from === plan.name && record3.to === to2);
|
|
123587
123587
|
writeNameRenameRecord(paths, { version: 1, id: id2, from: plan.name, to: to2, startedAt: resumed?.startedAt ?? new Date(ports.lock.nowMs()).toISOString() });
|
|
123588
123588
|
try {
|
|
123589
123589
|
await applyAll(plan.steps, {
|
|
@@ -125851,7 +125851,7 @@ function committedContextTokens(sessions, records) {
|
|
|
125851
125851
|
continue;
|
|
125852
125852
|
}
|
|
125853
125853
|
const sinceMs = Date.parse(session.since);
|
|
125854
|
-
const written = records.some((
|
|
125854
|
+
const written = records.some((record3) => record3.sessionId === session.sessionId && record3.identity === session.identity && Date.parse(record3.at) >= sinceMs);
|
|
125855
125855
|
if (!written) {
|
|
125856
125856
|
committed[session.identity] = (committed[session.identity] ?? 0) + session.carriedTokens;
|
|
125857
125857
|
}
|
|
@@ -125915,8 +125915,8 @@ async function supervisedSessionOf(fs35, paths, sessionId, runningAmong) {
|
|
|
125915
125915
|
init_read();
|
|
125916
125916
|
|
|
125917
125917
|
// src/selection/signals.ts
|
|
125918
|
-
function targetOf(
|
|
125919
|
-
return
|
|
125918
|
+
function targetOf(record3) {
|
|
125919
|
+
return record3.model === void 0 ? void 0 : `${record3.provider}/${record3.model}`;
|
|
125920
125920
|
}
|
|
125921
125921
|
function median(values) {
|
|
125922
125922
|
if (values.length === 0) {
|
|
@@ -125929,18 +125929,18 @@ function median(values) {
|
|
|
125929
125929
|
return sorted.length % 2 === 0 && above !== void 0 && below !== void 0 ? (above + below) / 2 : sorted[middle];
|
|
125930
125930
|
}
|
|
125931
125931
|
var OBSERVATION_WINDOW = 20;
|
|
125932
|
-
function observeRecord(observations,
|
|
125933
|
-
const target = targetOf(
|
|
125932
|
+
function observeRecord(observations, record3) {
|
|
125933
|
+
const target = targetOf(record3);
|
|
125934
125934
|
if (target === void 0) {
|
|
125935
125935
|
return new Map(observations);
|
|
125936
125936
|
}
|
|
125937
|
-
const kept = [...observations.get(target) ?? [],
|
|
125937
|
+
const kept = [...observations.get(target) ?? [], record3].slice(-OBSERVATION_WINDOW);
|
|
125938
125938
|
return new Map(observations).set(target, kept);
|
|
125939
125939
|
}
|
|
125940
125940
|
function observationOf(records) {
|
|
125941
|
-
const completed = records.filter((
|
|
125942
|
-
const latencies = completed.map((
|
|
125943
|
-
const usage = records.flatMap((
|
|
125941
|
+
const completed = records.filter((record3) => record3.outcome === "completed");
|
|
125942
|
+
const latencies = completed.map((record3) => record3.latencyMs);
|
|
125943
|
+
const usage = records.flatMap((record3) => record3.usage === void 0 ? [] : [record3.usage]);
|
|
125944
125944
|
const input2 = usage.reduce((sum2, entry) => sum2 + (entry.inputTokens ?? 0), 0);
|
|
125945
125945
|
const output2 = usage.reduce((sum2, entry) => sum2 + (entry.outputTokens ?? 0), 0);
|
|
125946
125946
|
const cacheRead = usage.reduce((sum2, entry) => sum2 + (entry.cacheReadInputTokens ?? 0), 0);
|
|
@@ -125963,12 +125963,12 @@ var SEED_LOOKBACK_RECORDS = 500;
|
|
|
125963
125963
|
function createTargetObservationStore(fs35, paths) {
|
|
125964
125964
|
let observations = /* @__PURE__ */ new Map();
|
|
125965
125965
|
const seeded = readRecentUsageRecords(fs35, paths.usageLogDir, SEED_LOOKBACK_RECORDS);
|
|
125966
|
-
for (const
|
|
125967
|
-
observations = observeRecord(observations,
|
|
125966
|
+
for (const record3 of seeded) {
|
|
125967
|
+
observations = observeRecord(observations, record3);
|
|
125968
125968
|
}
|
|
125969
125969
|
return {
|
|
125970
|
-
observe: (
|
|
125971
|
-
observations = observeRecord(observations,
|
|
125970
|
+
observe: (record3) => {
|
|
125971
|
+
observations = observeRecord(observations, record3);
|
|
125972
125972
|
},
|
|
125973
125973
|
observation: (target) => {
|
|
125974
125974
|
const records = observations.get(target);
|
|
@@ -126531,8 +126531,8 @@ function createCredentialCustody(randomId) {
|
|
|
126531
126531
|
held.delete(hopId);
|
|
126532
126532
|
},
|
|
126533
126533
|
redeem: (hopId, provider) => {
|
|
126534
|
-
const
|
|
126535
|
-
return
|
|
126534
|
+
const record3 = held.get(hopId);
|
|
126535
|
+
return record3?.provider === provider ? record3.credentials : void 0;
|
|
126536
126536
|
}
|
|
126537
126537
|
};
|
|
126538
126538
|
}
|
|
@@ -126774,20 +126774,20 @@ var SYSTEM_SUBTYPES = ["task_started", "task_progress", "task_updated", "task_no
|
|
|
126774
126774
|
function isRecord10(value3) {
|
|
126775
126775
|
return typeof value3 === "object" && value3 !== null && !Array.isArray(value3);
|
|
126776
126776
|
}
|
|
126777
|
-
function stringField(
|
|
126778
|
-
const value3 =
|
|
126777
|
+
function stringField(record3, field) {
|
|
126778
|
+
const value3 = record3[field];
|
|
126779
126779
|
return typeof value3 === "string" && value3 !== "" ? value3 : void 0;
|
|
126780
126780
|
}
|
|
126781
|
-
function numberField(
|
|
126782
|
-
const value3 =
|
|
126781
|
+
function numberField(record3, field) {
|
|
126782
|
+
const value3 = record3[field];
|
|
126783
126783
|
return typeof value3 === "number" && Number.isFinite(value3) ? value3 : void 0;
|
|
126784
126784
|
}
|
|
126785
|
-
function booleanField(
|
|
126786
|
-
const value3 =
|
|
126785
|
+
function booleanField(record3, field) {
|
|
126786
|
+
const value3 = record3[field];
|
|
126787
126787
|
return typeof value3 === "boolean" ? value3 : void 0;
|
|
126788
126788
|
}
|
|
126789
|
-
function usageOf(
|
|
126790
|
-
const raw =
|
|
126789
|
+
function usageOf(record3) {
|
|
126790
|
+
const raw = record3.usage;
|
|
126791
126791
|
if (!isRecord10(raw)) {
|
|
126792
126792
|
return void 0;
|
|
126793
126793
|
}
|
|
@@ -126961,12 +126961,12 @@ function parseJsonObject(body) {
|
|
|
126961
126961
|
}
|
|
126962
126962
|
return isRecord11(parsed) ? parsed : void 0;
|
|
126963
126963
|
}
|
|
126964
|
-
function nonEmptyString(
|
|
126965
|
-
const value3 =
|
|
126964
|
+
function nonEmptyString(record3, field) {
|
|
126965
|
+
const value3 = record3 === void 0 ? void 0 : record3[field];
|
|
126966
126966
|
return typeof value3 === "string" && value3 !== "" ? value3 : void 0;
|
|
126967
126967
|
}
|
|
126968
|
-
function finiteNumber(
|
|
126969
|
-
const value3 =
|
|
126968
|
+
function finiteNumber(record3, field) {
|
|
126969
|
+
const value3 = record3 === void 0 ? void 0 : record3[field];
|
|
126970
126970
|
return typeof value3 === "number" && Number.isFinite(value3) ? value3 : void 0;
|
|
126971
126971
|
}
|
|
126972
126972
|
function excerpt(text5) {
|
|
@@ -127064,9 +127064,9 @@ function createRcSessionTracker(deps) {
|
|
|
127064
127064
|
const timer = setInterval(sweep, deps.idleMs);
|
|
127065
127065
|
timer.unref();
|
|
127066
127066
|
const birth = (id2, facts) => {
|
|
127067
|
-
const
|
|
127068
|
-
entries.set(id2,
|
|
127069
|
-
return
|
|
127067
|
+
const record3 = { id: id2, createdAt: deps.now(), lastSeenAt: deps.now(), ...facts, pending: /* @__PURE__ */ new Map(), workerState: void 0, workerIdleSeconds: void 0, sequenceNum: void 0, liveTasks: /* @__PURE__ */ new Map() };
|
|
127068
|
+
entries.set(id2, record3);
|
|
127069
|
+
return record3;
|
|
127070
127070
|
};
|
|
127071
127071
|
const persistCredential = (entry) => {
|
|
127072
127072
|
if (entry.oauthAuthorization !== void 0) {
|
|
@@ -128942,7 +128942,7 @@ function identityRecordFindings(records, displaced, nameRenames, strayNameRename
|
|
|
128942
128942
|
})),
|
|
128943
128943
|
...displaced.map(({ id: id2, name, directoryPresent }) => ({
|
|
128944
128944
|
severity: "warn",
|
|
128945
|
-
message: `${name === void 0 ? `The identity stored under identities/${id2}` : `Identity "${name}"`} has no identity.json in identities/${id2}, which ${directoryPresent ? "holds none yet" : "is missing"}: its identity.json is in a superseded farm a resync left when it was interrupted. ${name === void 0 ? `Its identity.json gives no name that can be read, ${records.some((
|
|
128945
|
+
message: `${name === void 0 ? `The identity stored under identities/${id2}` : `Identity "${name}"`} has no identity.json in identities/${id2}, which ${directoryPresent ? "holds none yet" : "is missing"}: its identity.json is in a superseded farm a resync left when it was interrupted. ${name === void 0 ? `Its identity.json gives no name that can be read, ${records.some((record3) => record3.name === id2) ? `and its id is the name of another identity, so a launch by its id reaches that one: repair the file in the superseded farm and launch it by the name the file gives, or rename the identity named "${id2}" first and then launch this one by its id (\`agent-shim run @${id2}\`) to put it back.` : `so launch it by its id (\`agent-shim run @${id2}\`) to put it back, then repair the file.`}` : `The next launch of "${name}" puts it back.`}`,
|
|
128946
128946
|
subject: name ?? id2
|
|
128947
128947
|
}))
|
|
128948
128948
|
];
|
|
@@ -130005,8 +130005,8 @@ function collectDoctorReport(params) {
|
|
|
130005
130005
|
const { paths } = params;
|
|
130006
130006
|
const { names: identityNames, unreachable: unreachableIdentities } = listIdentityDirectories(paths);
|
|
130007
130007
|
const records = identityRecords(paths);
|
|
130008
|
-
const displacedIdentities = records.filter((
|
|
130009
|
-
const identities = identityNames.filter((id2) => (records.some((
|
|
130008
|
+
const displacedIdentities = records.filter((record3) => !identityIdExists(paths, record3.id) && !unreachableIdentities.some((entry) => entry.name === record3.id));
|
|
130009
|
+
const identities = identityNames.filter((id2) => (records.some((record3) => record3.id === id2) || !import_node_fs26.default.existsSync(import_node_path62.default.join(paths.identitiesDir, id2, "identity.json"))) && !displacedIdentities.some((record3) => record3.id === id2)).map((id2) => {
|
|
130010
130010
|
const farmRoot = import_node_path62.default.join(paths.identitiesDir, id2);
|
|
130011
130011
|
const identityPath = import_node_path62.default.join(farmRoot, "identity.json");
|
|
130012
130012
|
return { name: identityNameIn(records, id2) ?? id2, id: id2, path: identityPath, raw: realFsPort.readFileUtf8(identityPath), farmRoot, credentialsFilePresent: import_node_fs26.default.existsSync(credentialsFilePath(farmRoot)), account: readIdentityAccount(realFsPort, paths.identitiesDir, id2)?.account };
|
|
@@ -130074,7 +130074,7 @@ function collectDoctorReport(params) {
|
|
|
130074
130074
|
providerAliases: readProviderAliases(paths),
|
|
130075
130075
|
renameJournals: listRenameJournals(realFarmFs, paths.identityRenamesDir),
|
|
130076
130076
|
unreachableIdentities,
|
|
130077
|
-
identityRecords: { all: records, displaced: displacedIdentities.map((
|
|
130077
|
+
identityRecords: { all: records, displaced: displacedIdentities.map((record3) => ({ ...record3, directoryPresent: import_node_fs26.default.existsSync(import_node_path62.default.join(paths.identitiesDir, record3.id)) })), nameRenames: unfinishedNameRenames(paths).map((record3) => ({ from: record3.from, description: describeInterruptedNameRename(paths, record3) })), strayNameRenameFiles: strayNameRenameRecordFiles(paths) },
|
|
130078
130078
|
directoryRules: { path: paths.directoryRulesFile, raw: realFsPort.readFileUtf8(paths.directoryRulesFile) },
|
|
130079
130079
|
globalConfig: { path: paths.globalConfigFile, raw: realFsPort.readFileUtf8(paths.globalConfigFile) },
|
|
130080
130080
|
models: readableOr(() => readGlobalConfig(paths)?.models, void 0),
|
|
@@ -141763,9 +141763,9 @@ function createLiveSessionRegistry(ports) {
|
|
|
141763
141763
|
let bySessionId = /* @__PURE__ */ new Map();
|
|
141764
141764
|
const recordNames = () => fs35.readdir(sessionsDir).filter(isSessionRecordName);
|
|
141765
141765
|
const rebuildIndexes = () => {
|
|
141766
|
-
const records = [...known.values()].flatMap(({ record:
|
|
141767
|
-
tokens = new Set(records.map((
|
|
141768
|
-
bySessionId = new Map(records.flatMap((
|
|
141766
|
+
const records = [...known.values()].flatMap(({ record: record3 }) => record3 === void 0 ? [] : [record3]);
|
|
141767
|
+
tokens = new Set(records.map((record3) => record3.token));
|
|
141768
|
+
bySessionId = new Map(records.flatMap((record3) => record3.sessionId === void 0 ? [] : [[record3.sessionId, record3]]));
|
|
141769
141769
|
};
|
|
141770
141770
|
const load = (name, stat) => {
|
|
141771
141771
|
known.set(name, { stat: { mtimeMs: stat.mtimeMs, sizeBytes: stat.sizeBytes }, record: readFrontDoorSessionRecord(fs35, sessionsDir, name) });
|
|
@@ -141815,7 +141815,7 @@ function createLiveSessionRegistry(ports) {
|
|
|
141815
141815
|
}
|
|
141816
141816
|
}
|
|
141817
141817
|
rebuildIndexes();
|
|
141818
|
-
return [...known.values()].flatMap(({ record:
|
|
141818
|
+
return [...known.values()].flatMap(({ record: record3 }) => record3 === void 0 ? [] : [summaryOf(record3)]).sort((a10, b) => a10.pid - b.pid);
|
|
141819
141819
|
},
|
|
141820
141820
|
forget: (pids) => {
|
|
141821
141821
|
for (const pid of pids) {
|
|
@@ -143326,6 +143326,54 @@ function createAntigravityRelay(params) {
|
|
|
143326
143326
|
return { pushChunk, finish, message };
|
|
143327
143327
|
}
|
|
143328
143328
|
|
|
143329
|
+
// src/antigravity/recursiveSchema.ts
|
|
143330
|
+
function rejectedPath(body) {
|
|
143331
|
+
try {
|
|
143332
|
+
const value3 = JSON.parse(body);
|
|
143333
|
+
if (!record2(value3) || !record2(value3.error) || typeof value3.error.message !== "string") return void 0;
|
|
143334
|
+
const match = /ref loop of required fields was found at (\$defs\.[A-Za-z0-9_.$-]+)\s*$/u.exec(value3.error.message);
|
|
143335
|
+
return match?.[1]?.split(".");
|
|
143336
|
+
} catch {
|
|
143337
|
+
return void 0;
|
|
143338
|
+
}
|
|
143339
|
+
}
|
|
143340
|
+
function record2(value3) {
|
|
143341
|
+
return typeof value3 === "object" && value3 !== null && !Array.isArray(value3);
|
|
143342
|
+
}
|
|
143343
|
+
function descend(value3, key) {
|
|
143344
|
+
if (Array.isArray(value3) && /^\d+$/u.test(key)) return value3[Number(key)];
|
|
143345
|
+
return record2(value3) && Object.hasOwn(value3, key) ? value3[key] : void 0;
|
|
143346
|
+
}
|
|
143347
|
+
function relaxRejectedRecursiveProperty(request7, body) {
|
|
143348
|
+
const path90 = rejectedPath(body);
|
|
143349
|
+
if (path90 === void 0) return void 0;
|
|
143350
|
+
const propertyIndex = path90.lastIndexOf("properties");
|
|
143351
|
+
const name = path90[propertyIndex + 1];
|
|
143352
|
+
if (propertyIndex < 0 || name === void 0) return void 0;
|
|
143353
|
+
const copy2 = structuredClone(request7);
|
|
143354
|
+
let changed = false;
|
|
143355
|
+
for (const tool of copy2.tools ?? []) {
|
|
143356
|
+
for (const declaration of tool.functionDeclarations) {
|
|
143357
|
+
const schema = declaration.parametersJsonSchema;
|
|
143358
|
+
if (schema === void 0) continue;
|
|
143359
|
+
let leaf = schema;
|
|
143360
|
+
for (const part of path90) leaf = descend(leaf, part);
|
|
143361
|
+
if (!record2(leaf) || typeof leaf.$ref !== "string") continue;
|
|
143362
|
+
let owner = schema;
|
|
143363
|
+
for (const part of path90.slice(0, propertyIndex)) owner = descend(owner, part);
|
|
143364
|
+
if (!record2(owner) || !Array.isArray(owner.required) || !owner.required.includes(name) || !record2(owner.properties)) continue;
|
|
143365
|
+
const property = owner.properties[name];
|
|
143366
|
+
if (!record2(property)) continue;
|
|
143367
|
+
owner.required = owner.required.filter((item) => item !== name);
|
|
143368
|
+
const description = typeof property.description === "string" ? `${property.description}
|
|
143369
|
+
` : "";
|
|
143370
|
+
property.description = `${description}This property is required by the original tool schema.`;
|
|
143371
|
+
changed = true;
|
|
143372
|
+
}
|
|
143373
|
+
}
|
|
143374
|
+
return changed ? copy2 : void 0;
|
|
143375
|
+
}
|
|
143376
|
+
|
|
143329
143377
|
// src/antigravity/route.ts
|
|
143330
143378
|
init_translate();
|
|
143331
143379
|
init_cloudUpstream();
|
|
@@ -143513,6 +143561,7 @@ async function* callLocalAntigravity(params) {
|
|
|
143513
143561
|
init_quota();
|
|
143514
143562
|
var MS_PER_SECOND13 = 1e3;
|
|
143515
143563
|
var ROUTING_MEMORY_SESSIONS = 256;
|
|
143564
|
+
var MAX_SCHEMA_RETRIES = 16;
|
|
143516
143565
|
function exhaustedMessage(exhaustion) {
|
|
143517
143566
|
const window = exhaustion.window === "five_hour" ? "5-hour" : "weekly";
|
|
143518
143567
|
return `Antigravity ${window} limit reached; it resets at ${new Date(exhaustion.resetSec * MS_PER_SECOND13).toISOString()}.`;
|
|
@@ -143600,6 +143649,7 @@ function createAntigravityRoute(ports) {
|
|
|
143600
143649
|
const tried = /* @__PURE__ */ new Set();
|
|
143601
143650
|
let iterator;
|
|
143602
143651
|
let firstResult;
|
|
143652
|
+
let schemaRetries = 0;
|
|
143603
143653
|
for (; ; ) {
|
|
143604
143654
|
tried.add(translated.model);
|
|
143605
143655
|
const upstreamChunks2 = config2.mode === "local" ? callLocalAntigravity({
|
|
@@ -143625,6 +143675,14 @@ function createAntigravityRoute(ports) {
|
|
|
143625
143675
|
break;
|
|
143626
143676
|
} catch (error63) {
|
|
143627
143677
|
if (error63 instanceof AntigravityUpstreamError) {
|
|
143678
|
+
if (error63.status === HTTP_STATUS.badRequest && schemaRetries < MAX_SCHEMA_RETRIES) {
|
|
143679
|
+
const repaired = relaxRejectedRecursiveProperty(translated.request, error63.body);
|
|
143680
|
+
if (repaired !== void 0) {
|
|
143681
|
+
schemaRetries += 1;
|
|
143682
|
+
translated = { ...translated, request: repaired };
|
|
143683
|
+
continue;
|
|
143684
|
+
}
|
|
143685
|
+
}
|
|
143628
143686
|
const is429 = error63.status === HTTP_STATUS.tooManyRequests;
|
|
143629
143687
|
const learned = is429 ? parseQuotaExhaustion(error63.body, nowMs) : void 0;
|
|
143630
143688
|
if (learned !== void 0) {
|
|
@@ -144754,8 +144812,8 @@ function createRcSelfHostLocal(deps) {
|
|
|
144754
144812
|
if (host === RC_SELF_HOST_OAUTH_HOST) {
|
|
144755
144813
|
if (method === "POST" && pathname === "/v1/oauth/token") {
|
|
144756
144814
|
const body = parseJsonObject2(await deps.readBody(request7, CONTROL_BODY_CAP_BYTES));
|
|
144757
|
-
const
|
|
144758
|
-
if (
|
|
144815
|
+
const record3 = deps.credentialRecord();
|
|
144816
|
+
if (record3 === void 0) {
|
|
144759
144817
|
answerServerJson(response, HTTP_SERVICE_UNAVAILABLE, { error: "the front door's self-hosted Remote Control surface is on but no credential has been minted for it" });
|
|
144760
144818
|
return true;
|
|
144761
144819
|
}
|
|
@@ -144763,7 +144821,7 @@ function createRcSelfHostLocal(deps) {
|
|
|
144763
144821
|
answerServerJson(response, HTTP_STATUS.badRequest, { error: "unsupported_grant_type" });
|
|
144764
144822
|
return true;
|
|
144765
144823
|
}
|
|
144766
|
-
answerServerJson(response, HTTP_STATUS.ok, { access_token:
|
|
144824
|
+
answerServerJson(response, HTTP_STATUS.ok, { access_token: record3.accessToken, refresh_token: record3.refreshToken, expires_in: RC_SELF_HOST_OAUTH_TOKEN_TTL_SECONDS, scope: RC_SELF_HOST_SCOPE_LIST.join(" ") });
|
|
144767
144825
|
return true;
|
|
144768
144826
|
}
|
|
144769
144827
|
if (method === "GET" && pathname === "/v1/oauth/hello") {
|
|
@@ -144778,14 +144836,14 @@ function createRcSelfHostLocal(deps) {
|
|
|
144778
144836
|
return true;
|
|
144779
144837
|
}
|
|
144780
144838
|
if (method === "GET" && pathname === "/api/oauth/profile") {
|
|
144781
|
-
const
|
|
144782
|
-
if (
|
|
144839
|
+
const record3 = deps.credentialRecord();
|
|
144840
|
+
if (record3 === void 0) {
|
|
144783
144841
|
answerServerJson(response, HTTP_SERVICE_UNAVAILABLE, { error: "the front door's self-hosted Remote Control surface is on but no credential has been minted for it" });
|
|
144784
144842
|
return true;
|
|
144785
144843
|
}
|
|
144786
144844
|
answerServerJson(response, HTTP_STATUS.ok, {
|
|
144787
|
-
account: { uuid:
|
|
144788
|
-
organization: { uuid:
|
|
144845
|
+
account: { uuid: record3.accountUuid, display_name: "agent-shim self-hosted", created_at: (/* @__PURE__ */ new Date(0)).toISOString() },
|
|
144846
|
+
organization: { uuid: record3.organizationUuid, organization_type: "claude_max" }
|
|
144789
144847
|
});
|
|
144790
144848
|
return true;
|
|
144791
144849
|
}
|
|
@@ -144795,12 +144853,12 @@ function createRcSelfHostLocal(deps) {
|
|
|
144795
144853
|
}
|
|
144796
144854
|
if (method === "POST" && pathname === "/api/oauth/validate") {
|
|
144797
144855
|
await deps.readBody(request7, CONTROL_BODY_CAP_BYTES);
|
|
144798
|
-
const
|
|
144799
|
-
if (
|
|
144856
|
+
const record3 = deps.credentialRecord();
|
|
144857
|
+
if (record3 === void 0) {
|
|
144800
144858
|
answerServerJson(response, HTTP_SERVICE_UNAVAILABLE, { error: "the front door's self-hosted Remote Control surface is on but no credential has been minted for it" });
|
|
144801
144859
|
return true;
|
|
144802
144860
|
}
|
|
144803
|
-
answerServerJson(response, HTTP_STATUS.ok, { scopes: [...RC_SELF_HOST_SCOPE_LIST], expiresAt: null, subscriptionType: "max", account_uuid:
|
|
144861
|
+
answerServerJson(response, HTTP_STATUS.ok, { scopes: [...RC_SELF_HOST_SCOPE_LIST], expiresAt: null, subscriptionType: "max", account_uuid: record3.accountUuid, organization_uuid: record3.organizationUuid });
|
|
144804
144862
|
return true;
|
|
144805
144863
|
}
|
|
144806
144864
|
if (method === "POST" && (pathname === "/api/event_logging/v2/batch" || pathname === "/api/claude_code/metrics" || pathname === "/api/claude_cli_feedback")) {
|
|
@@ -145318,8 +145376,8 @@ function createRcCredentialStore(fs35, dir) {
|
|
|
145318
145376
|
return;
|
|
145319
145377
|
}
|
|
145320
145378
|
const cursor3 = sequenceNumOfJson(readParsed(sessionId)?.highestSequenceNum);
|
|
145321
|
-
const
|
|
145322
|
-
fs35.writeFilePrivate(fileFor(sessionId), `${JSON.stringify(
|
|
145379
|
+
const record3 = { ...credential, ...cursor3 === void 0 ? {} : { highestSequenceNum: cursor3 } };
|
|
145380
|
+
fs35.writeFilePrivate(fileFor(sessionId), `${JSON.stringify(record3, null, 2)}
|
|
145323
145381
|
`);
|
|
145324
145382
|
},
|
|
145325
145383
|
readCursor: (sessionId) => {
|
|
@@ -145333,8 +145391,8 @@ function createRcCredentialStore(fs35, dir) {
|
|
|
145333
145391
|
return;
|
|
145334
145392
|
}
|
|
145335
145393
|
const credential = credentialOfJson(readParsed(sessionId));
|
|
145336
|
-
const
|
|
145337
|
-
fs35.writeFilePrivate(fileFor(sessionId), `${JSON.stringify(
|
|
145394
|
+
const record3 = credential === void 0 ? { highestSequenceNum } : { ...credential, highestSequenceNum };
|
|
145395
|
+
fs35.writeFilePrivate(fileFor(sessionId), `${JSON.stringify(record3, null, 2)}
|
|
145338
145396
|
`);
|
|
145339
145397
|
},
|
|
145340
145398
|
remove: (sessionId) => {
|
|
@@ -145884,12 +145942,12 @@ function parseJsonObject3(body) {
|
|
|
145884
145942
|
}
|
|
145885
145943
|
return isRecord18(parsed) ? parsed : void 0;
|
|
145886
145944
|
}
|
|
145887
|
-
function nonEmptyString2(
|
|
145888
|
-
const value3 =
|
|
145945
|
+
function nonEmptyString2(record3, field) {
|
|
145946
|
+
const value3 = record3 === void 0 ? void 0 : record3[field];
|
|
145889
145947
|
return typeof value3 === "string" && value3 !== "" ? value3 : void 0;
|
|
145890
145948
|
}
|
|
145891
|
-
function numberOf(
|
|
145892
|
-
const value3 =
|
|
145949
|
+
function numberOf(record3, field) {
|
|
145950
|
+
const value3 = record3 === void 0 ? void 0 : record3[field];
|
|
145893
145951
|
if (typeof value3 === "number" && Number.isFinite(value3)) {
|
|
145894
145952
|
return value3;
|
|
145895
145953
|
}
|
|
@@ -146068,8 +146126,8 @@ function parseJsonObject4(body) {
|
|
|
146068
146126
|
}
|
|
146069
146127
|
return isRecord19(parsed) ? parsed : void 0;
|
|
146070
146128
|
}
|
|
146071
|
-
function nonEmptyString3(
|
|
146072
|
-
const value3 =
|
|
146129
|
+
function nonEmptyString3(record3, field) {
|
|
146130
|
+
const value3 = record3 === void 0 ? void 0 : record3[field];
|
|
146073
146131
|
return typeof value3 === "string" && value3 !== "" ? value3 : void 0;
|
|
146074
146132
|
}
|
|
146075
146133
|
function newRcSelfHostConversation(newUuid, now) {
|
|
@@ -146419,12 +146477,12 @@ function isRecord20(value3) {
|
|
|
146419
146477
|
function isWebSearchRefusal(value3) {
|
|
146420
146478
|
return !Array.isArray(value3);
|
|
146421
146479
|
}
|
|
146422
|
-
function nonEmptyString4(
|
|
146423
|
-
const value3 =
|
|
146480
|
+
function nonEmptyString4(record3, field) {
|
|
146481
|
+
const value3 = record3 === void 0 ? void 0 : record3[field];
|
|
146424
146482
|
return typeof value3 === "string" && value3 !== "" ? value3 : void 0;
|
|
146425
146483
|
}
|
|
146426
|
-
function numberOf2(
|
|
146427
|
-
const value3 =
|
|
146484
|
+
function numberOf2(record3, field) {
|
|
146485
|
+
const value3 = record3 === void 0 ? void 0 : record3[field];
|
|
146428
146486
|
if (typeof value3 === "number" && Number.isFinite(value3)) {
|
|
146429
146487
|
return value3;
|
|
146430
146488
|
}
|
|
@@ -146433,8 +146491,8 @@ function numberOf2(record2, field) {
|
|
|
146433
146491
|
}
|
|
146434
146492
|
return void 0;
|
|
146435
146493
|
}
|
|
146436
|
-
function stringArray(
|
|
146437
|
-
const value3 =
|
|
146494
|
+
function stringArray(record3, field) {
|
|
146495
|
+
const value3 = record3 === void 0 ? void 0 : record3[field];
|
|
146438
146496
|
if (!Array.isArray(value3)) {
|
|
146439
146497
|
return void 0;
|
|
146440
146498
|
}
|
|
@@ -147933,8 +147991,8 @@ function realFrontDoorSupervisorPorts(paths, respawnGeneration, lifecycle, track
|
|
|
147933
147991
|
routingSnapshots.set(snapshot.identity, snapshot);
|
|
147934
147992
|
publishUsageEvent(snapshot);
|
|
147935
147993
|
},
|
|
147936
|
-
onRecord: (
|
|
147937
|
-
observations.observe(
|
|
147994
|
+
onRecord: (record3) => {
|
|
147995
|
+
observations.observe(record3);
|
|
147938
147996
|
}
|
|
147939
147997
|
});
|
|
147940
147998
|
const quotaRefresher = createRealQuotaRefresher({ paths, store: usageStore, log });
|
|
@@ -148038,22 +148096,22 @@ function realFrontDoorSupervisorPorts(paths, respawnGeneration, lifecycle, track
|
|
|
148038
148096
|
log
|
|
148039
148097
|
});
|
|
148040
148098
|
const headroomDecision = createHeadroomDecision(createRoutingSettingReader(paths));
|
|
148041
|
-
const recordUsage = (
|
|
148042
|
-
withQuotaRefresh(usageStore.record, quotaRefresher)(
|
|
148099
|
+
const recordUsage = (record3) => {
|
|
148100
|
+
withQuotaRefresh(usageStore.record, quotaRefresher)(record3);
|
|
148043
148101
|
};
|
|
148044
148102
|
const usageMiddleware = createUsageMiddleware({
|
|
148045
148103
|
// Each finished response also tells the per-session headroom decision when the session's cache was last touched and whether it read from it.
|
|
148046
|
-
record: (
|
|
148047
|
-
const { usage } =
|
|
148104
|
+
record: (record3, event) => {
|
|
148105
|
+
const { usage } = record3;
|
|
148048
148106
|
headroomDecision.observe({
|
|
148049
|
-
sessionId:
|
|
148050
|
-
startedAtMs: Date.parse(
|
|
148051
|
-
viaHeadroom:
|
|
148107
|
+
sessionId: record3.sessionId,
|
|
148108
|
+
startedAtMs: Date.parse(record3.at),
|
|
148109
|
+
viaHeadroom: record3.viaHeadroom === true,
|
|
148052
148110
|
lineage: event.lineage,
|
|
148053
|
-
endedAtMs: Date.parse(
|
|
148111
|
+
endedAtMs: Date.parse(record3.at) + record3.durationMs,
|
|
148054
148112
|
cache: usage === void 0 ? void 0 : { readTokens: usage.cacheReadInputTokens ?? 0, writtenTokens: usage.cacheCreationInputTokens ?? 0, uncachedTokens: usage.inputTokens ?? 0 }
|
|
148055
148113
|
});
|
|
148056
|
-
recordUsage(
|
|
148114
|
+
recordUsage(record3);
|
|
148057
148115
|
},
|
|
148058
148116
|
defer: (task) => {
|
|
148059
148117
|
setImmediate(task);
|
|
@@ -148844,12 +148902,12 @@ var CACHE_READ_PRICE_RATIO = 0.1;
|
|
|
148844
148902
|
function doorCostUsdOf(records, prices) {
|
|
148845
148903
|
let totalUsd = 0;
|
|
148846
148904
|
let costed = 0;
|
|
148847
|
-
for (const
|
|
148848
|
-
const { usage } =
|
|
148905
|
+
for (const record3 of records) {
|
|
148906
|
+
const { usage } = record3;
|
|
148849
148907
|
if (usage === void 0) {
|
|
148850
148908
|
continue;
|
|
148851
148909
|
}
|
|
148852
|
-
const price =
|
|
148910
|
+
const price = record3.model === void 0 ? void 0 : prices[`${record3.provider}/${record3.model}`];
|
|
148853
148911
|
if (price === void 0) {
|
|
148854
148912
|
return void 0;
|
|
148855
148913
|
}
|
|
@@ -148899,7 +148957,7 @@ function readDoorCostUsd(params) {
|
|
|
148899
148957
|
const sinceMs = sessionDurationMs === void 0 ? void 0 : Date.parse(`${segmentDay(nowMs - sessionDurationMs)}T00:00:00.000Z`);
|
|
148900
148958
|
const { records } = readUsageLog(params.fs, params.logDir, sinceMs === void 0 ? {} : { sinceMs });
|
|
148901
148959
|
return doorCostUsdOf(
|
|
148902
|
-
records.filter((
|
|
148960
|
+
records.filter((record3) => record3.clientSessionId === params.conversationId),
|
|
148903
148961
|
params.prices
|
|
148904
148962
|
);
|
|
148905
148963
|
}
|
|
@@ -150779,8 +150837,8 @@ function afterCompaction(frame, compaction) {
|
|
|
150779
150837
|
}
|
|
150780
150838
|
return { ...frame, used_percentage: Math.min(FULL_PERCENT3, postTokens / windowTokens * FULL_PERCENT3) };
|
|
150781
150839
|
}
|
|
150782
|
-
function restored(frame,
|
|
150783
|
-
return { ...frame, used_percentage:
|
|
150840
|
+
function restored(frame, record3) {
|
|
150841
|
+
return { ...frame, used_percentage: record3.usedPercentage, total_input_tokens: record3.totalInputTokens, current_usage: record3.currentUsage, context_window_size: frame.context_window_size ?? record3.windowTokens };
|
|
150784
150842
|
}
|
|
150785
150843
|
function recordOf2(frame, usedPercentage, observedAtMs, nowMs) {
|
|
150786
150844
|
const usage = frame.current_usage;
|
|
@@ -150827,14 +150885,14 @@ function contextFrameOf(input2) {
|
|
|
150827
150885
|
let observedAtMs = nowMs;
|
|
150828
150886
|
if (isSuspiciousZero(frame) && !input2.drawsPercent) {
|
|
150829
150887
|
const loaded = loadCache(ports, file2, ContextRecordSchema);
|
|
150830
|
-
const
|
|
150888
|
+
const record3 = loaded !== void 0 && nowMs - loaded.savedAtMs <= CONTEXT_RECORD_MAX_AGE_MS ? loaded : void 0;
|
|
150831
150889
|
const compaction = input2.compaction();
|
|
150832
|
-
if (compaction !== void 0 && (
|
|
150890
|
+
if (compaction !== void 0 && (record3 === void 0 || compaction.atMs > record3.observedAtMs)) {
|
|
150833
150891
|
drawn = afterCompaction(frame, compaction);
|
|
150834
150892
|
observedAtMs = compaction.atMs;
|
|
150835
|
-
} else if (
|
|
150836
|
-
drawn = restored(frame,
|
|
150837
|
-
observedAtMs =
|
|
150893
|
+
} else if (record3 !== void 0) {
|
|
150894
|
+
drawn = restored(frame, record3);
|
|
150895
|
+
observedAtMs = record3.observedAtMs;
|
|
150838
150896
|
}
|
|
150839
150897
|
}
|
|
150840
150898
|
const goodPercent = goodPercentOf(drawn);
|
|
@@ -151525,9 +151583,9 @@ function wholeTokens(count2) {
|
|
|
151525
151583
|
function writtenCountsKey(usage) {
|
|
151526
151584
|
return [usage.input_tokens, usage.output_tokens, usage.cache_creation_input_tokens, usage.cache_read_input_tokens].map(String).join("|");
|
|
151527
151585
|
}
|
|
151528
|
-
function foldTokens(state,
|
|
151529
|
-
const usage =
|
|
151530
|
-
if (
|
|
151586
|
+
function foldTokens(state, record3) {
|
|
151587
|
+
const usage = record3.message?.usage;
|
|
151588
|
+
if (record3.type !== "assistant" || usage === void 0) {
|
|
151531
151589
|
return state;
|
|
151532
151590
|
}
|
|
151533
151591
|
const counts = {
|
|
@@ -151536,7 +151594,7 @@ function foldTokens(state, record2) {
|
|
|
151536
151594
|
cacheCreationTokens: wholeTokens(usage.cache_creation_input_tokens),
|
|
151537
151595
|
cacheReadTokens: wholeTokens(usage.cache_read_input_tokens)
|
|
151538
151596
|
};
|
|
151539
|
-
const key =
|
|
151597
|
+
const key = record3.message?.id ?? writtenCountsKey(usage);
|
|
151540
151598
|
if (state.open?.key === key) {
|
|
151541
151599
|
return { totals: sum(state.totals, increase(state.open.usage, counts)), open: { key, usage: larger(state.open.usage, counts) } };
|
|
151542
151600
|
}
|
|
@@ -151634,15 +151692,15 @@ function identityOfLine(line) {
|
|
|
151634
151692
|
} catch {
|
|
151635
151693
|
return void 0;
|
|
151636
151694
|
}
|
|
151637
|
-
const
|
|
151638
|
-
if (!
|
|
151695
|
+
const record3 = RecordSchema.safeParse(parsed);
|
|
151696
|
+
if (!record3.success || record3.data.type !== "assistant") {
|
|
151639
151697
|
return void 0;
|
|
151640
151698
|
}
|
|
151641
|
-
const model = boundedDisplayText(
|
|
151699
|
+
const model = boundedDisplayText(record3.data.message?.model ?? "");
|
|
151642
151700
|
if (model === "" || model === SYNTHETIC_MODEL) {
|
|
151643
151701
|
return void 0;
|
|
151644
151702
|
}
|
|
151645
|
-
const advisor = boundedDisplayText(
|
|
151703
|
+
const advisor = boundedDisplayText(record3.data.advisorModel ?? "");
|
|
151646
151704
|
return { model, advisor: advisor === "" ? void 0 : advisor };
|
|
151647
151705
|
}
|
|
151648
151706
|
function joined2(pieces) {
|
|
@@ -152183,11 +152241,11 @@ function parseTranscriptRecord(line) {
|
|
|
152183
152241
|
}
|
|
152184
152242
|
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? TranscriptRecordSchema.parse(parsed) : void 0;
|
|
152185
152243
|
}
|
|
152186
|
-
function recordTimeMs(
|
|
152187
|
-
if (
|
|
152244
|
+
function recordTimeMs(record3) {
|
|
152245
|
+
if (record3.timestamp === void 0) {
|
|
152188
152246
|
return void 0;
|
|
152189
152247
|
}
|
|
152190
|
-
const ms = Date.parse(
|
|
152248
|
+
const ms = Date.parse(record3.timestamp);
|
|
152191
152249
|
return Number.isNaN(ms) ? void 0 : ms;
|
|
152192
152250
|
}
|
|
152193
152251
|
|
|
@@ -152551,32 +152609,32 @@ function withUnanswered(tools, agents) {
|
|
|
152551
152609
|
function foldNewResponse(state, key) {
|
|
152552
152610
|
return { ...state, responseKey: key, ...withUnanswered(state.tools, state.agents) };
|
|
152553
152611
|
}
|
|
152554
|
-
function foldActivityLatest(state,
|
|
152555
|
-
if (
|
|
152612
|
+
function foldActivityLatest(state, record3) {
|
|
152613
|
+
if (record3.isSidechain === true) {
|
|
152556
152614
|
return state;
|
|
152557
152615
|
}
|
|
152558
|
-
const atMs = recordTimeMs(
|
|
152616
|
+
const atMs = recordTimeMs(record3);
|
|
152559
152617
|
let next = state;
|
|
152560
|
-
if (
|
|
152561
|
-
const toolUseId = QUEUED_TOOL_USE_ID.exec(
|
|
152562
|
-
if (toolUseId !== void 0 && QUEUED_TASK_ID.test(
|
|
152618
|
+
if (record3.type === "queue-operation" && record3.operation === "enqueue" && record3.content !== void 0 && atMs !== void 0) {
|
|
152619
|
+
const toolUseId = QUEUED_TOOL_USE_ID.exec(record3.content)?.[1];
|
|
152620
|
+
if (toolUseId !== void 0 && QUEUED_TASK_ID.test(record3.content)) {
|
|
152563
152621
|
next = foldAgentAnnouncement(next, toolUseId, atMs);
|
|
152564
152622
|
}
|
|
152565
152623
|
}
|
|
152566
|
-
const responseKey =
|
|
152624
|
+
const responseKey = record3.type === "assistant" ? record3.message?.id ?? record3.requestId : void 0;
|
|
152567
152625
|
if (responseKey !== void 0 && responseKey !== next.responseKey) {
|
|
152568
152626
|
next = next.responseKey === void 0 ? { ...next, responseKey } : foldNewResponse(next, responseKey);
|
|
152569
152627
|
}
|
|
152570
|
-
const content =
|
|
152628
|
+
const content = record3.message?.content;
|
|
152571
152629
|
if (!Array.isArray(content)) {
|
|
152572
152630
|
return next;
|
|
152573
152631
|
}
|
|
152574
152632
|
const resultCount = content.filter((block2) => block2.type === "tool_result").length;
|
|
152575
152633
|
for (const block2 of content) {
|
|
152576
|
-
if (
|
|
152634
|
+
if (record3.type === "assistant" && block2.type === "tool_use" && block2.id !== void 0 && block2.name !== void 0 && !isRemembered(next, block2.id, atMs)) {
|
|
152577
152635
|
next = foldToolUse(remember2(next, block2.id, atMs), { id: block2.id, name: block2.name, input: block2.input }, atMs);
|
|
152578
|
-
} else if (
|
|
152579
|
-
const outcome = resultCount === 1 ?
|
|
152636
|
+
} else if (record3.type === "user" && block2.type === "tool_result" && block2.tool_use_id !== void 0) {
|
|
152637
|
+
const outcome = resultCount === 1 ? record3.toolUseResult : void 0;
|
|
152580
152638
|
const taskId = createdTaskId(block2.content, outcome);
|
|
152581
152639
|
next = foldToolResult(next, {
|
|
152582
152640
|
id: block2.tool_use_id,
|
|
@@ -152609,9 +152667,9 @@ function withName(set3, name) {
|
|
|
152609
152667
|
}
|
|
152610
152668
|
return { ...set3, others: [...set3.others, digest2] };
|
|
152611
152669
|
}
|
|
152612
|
-
function foldActivityCumulative(state,
|
|
152613
|
-
const content =
|
|
152614
|
-
if (
|
|
152670
|
+
function foldActivityCumulative(state, record3) {
|
|
152671
|
+
const content = record3.message?.content;
|
|
152672
|
+
if (record3.isSidechain === true || record3.type !== "assistant" || !Array.isArray(content)) {
|
|
152615
152673
|
return state;
|
|
152616
152674
|
}
|
|
152617
152675
|
let { skills, mcpServers } = state;
|
|
@@ -152628,8 +152686,8 @@ function foldActivityCumulative(state, record2) {
|
|
|
152628
152686
|
}
|
|
152629
152687
|
return skills === state.skills && mcpServers === state.mcpServers ? state : { skills, mcpServers };
|
|
152630
152688
|
}
|
|
152631
|
-
function foldActivity(state,
|
|
152632
|
-
return { cumulative: foldActivityCumulative(state.cumulative,
|
|
152689
|
+
function foldActivity(state, record3) {
|
|
152690
|
+
return { cumulative: foldActivityCumulative(state.cumulative, record3), latest: foldActivityLatest(state.latest, record3) };
|
|
152633
152691
|
}
|
|
152634
152692
|
function isLive(startedAtMs, nowMs, maxMs) {
|
|
152635
152693
|
return startedAtMs === void 0 || nowMs - startedAtMs <= maxMs;
|
|
@@ -152708,8 +152766,8 @@ var LOCAL_ONLY_USER_TEXT_PREFIXES = ["<command-name>", "<command-message>", "<lo
|
|
|
152708
152766
|
function isLocalOnlyUserText(text5) {
|
|
152709
152767
|
return LOCAL_ONLY_USER_TEXT_PREFIXES.some((prefix) => text5.startsWith(prefix));
|
|
152710
152768
|
}
|
|
152711
|
-
function opensRequest(
|
|
152712
|
-
const content =
|
|
152769
|
+
function opensRequest(record3) {
|
|
152770
|
+
const content = record3.message?.content;
|
|
152713
152771
|
if (typeof content === "string") {
|
|
152714
152772
|
return !isLocalOnlyUserText(content);
|
|
152715
152773
|
}
|
|
@@ -152718,34 +152776,34 @@ function opensRequest(record2) {
|
|
|
152718
152776
|
}
|
|
152719
152777
|
return true;
|
|
152720
152778
|
}
|
|
152721
|
-
function ttlOf(
|
|
152722
|
-
const writes =
|
|
152779
|
+
function ttlOf(record3) {
|
|
152780
|
+
const writes = record3.message?.usage?.cache_creation;
|
|
152723
152781
|
if ((writes?.ephemeral_5m_input_tokens ?? 0) > 0) {
|
|
152724
152782
|
return PROMPT_CACHE_TTL_SECONDS.fiveMinutes;
|
|
152725
152783
|
}
|
|
152726
152784
|
return (writes?.ephemeral_1h_input_tokens ?? 0) > 0 ? PROMPT_CACHE_TTL_SECONDS.oneHour : void 0;
|
|
152727
152785
|
}
|
|
152728
|
-
function foldPromptCache(cache,
|
|
152786
|
+
function foldPromptCache(cache, record3, atMs) {
|
|
152729
152787
|
if (atMs === void 0) {
|
|
152730
152788
|
return cache;
|
|
152731
152789
|
}
|
|
152732
152790
|
let next = cache;
|
|
152733
|
-
if (
|
|
152734
|
-
const startsRequest =
|
|
152791
|
+
if (record3.type === "assistant") {
|
|
152792
|
+
const startsRequest = record3.requestId === void 0 || record3.requestId !== cache.requestId;
|
|
152735
152793
|
const requestAnchorAtMs = startsRequest ? cache.previousMainAtMs : cache.requestAnchorAtMs;
|
|
152736
152794
|
const anchorAtMs = requestAnchorAtMs !== void 0 && requestAnchorAtMs <= atMs ? requestAnchorAtMs : atMs;
|
|
152737
|
-
const ttlSeconds = ttlOf(
|
|
152738
|
-
next = { ...cache, requestId: startsRequest ?
|
|
152795
|
+
const ttlSeconds = ttlOf(record3) ?? cache.ttlSeconds;
|
|
152796
|
+
next = { ...cache, requestId: startsRequest ? record3.requestId : cache.requestId, requestAnchorAtMs, anchorAtMs, ttlSeconds, pendingAtMs: void 0 };
|
|
152739
152797
|
}
|
|
152740
|
-
if (
|
|
152798
|
+
if (record3.type === "user" && opensRequest(record3)) {
|
|
152741
152799
|
next = { ...next, pendingAtMs: atMs };
|
|
152742
152800
|
}
|
|
152743
152801
|
return { ...next, previousMainAtMs: atMs };
|
|
152744
152802
|
}
|
|
152745
|
-
function foldCumulative(state,
|
|
152746
|
-
const atMs = recordTimeMs(
|
|
152803
|
+
function foldCumulative(state, record3) {
|
|
152804
|
+
const atMs = recordTimeMs(record3);
|
|
152747
152805
|
const next = { ...state };
|
|
152748
|
-
if (
|
|
152806
|
+
if (record3.type === "system" && record3.subtype === "compact_boundary" && atMs !== void 0) {
|
|
152749
152807
|
next.compactions += 1;
|
|
152750
152808
|
}
|
|
152751
152809
|
if (atMs !== void 0 && next.startedAtMs === void 0 && next.startUnknown !== true) {
|
|
@@ -152756,30 +152814,30 @@ function foldCumulative(state, record2) {
|
|
|
152756
152814
|
function laterCompaction(held, met) {
|
|
152757
152815
|
return held === void 0 || met !== void 0 && met.atMs > held.atMs ? met : held;
|
|
152758
152816
|
}
|
|
152759
|
-
function foldLatest(state,
|
|
152760
|
-
const atMs = recordTimeMs(
|
|
152817
|
+
function foldLatest(state, record3) {
|
|
152818
|
+
const atMs = recordTimeMs(record3);
|
|
152761
152819
|
const next = { ...state };
|
|
152762
|
-
if (
|
|
152763
|
-
next.customTitle =
|
|
152764
|
-
} else if (
|
|
152765
|
-
next.aiTitle =
|
|
152766
|
-
} else if (
|
|
152767
|
-
next.slug =
|
|
152768
|
-
}
|
|
152769
|
-
if (
|
|
152820
|
+
if (record3.type === "custom-title" && record3.customTitle !== void 0) {
|
|
152821
|
+
next.customTitle = record3.customTitle;
|
|
152822
|
+
} else if (record3.type === "ai-title" && record3.aiTitle !== void 0) {
|
|
152823
|
+
next.aiTitle = record3.aiTitle;
|
|
152824
|
+
} else if (record3.slug !== void 0) {
|
|
152825
|
+
next.slug = record3.slug;
|
|
152826
|
+
}
|
|
152827
|
+
if (record3.type === "assistant" && atMs !== void 0) {
|
|
152770
152828
|
next.lastAssistantAtMs = atMs;
|
|
152771
152829
|
}
|
|
152772
|
-
if (
|
|
152773
|
-
const postTokens =
|
|
152830
|
+
if (record3.type === "system" && record3.subtype === "compact_boundary" && atMs !== void 0) {
|
|
152831
|
+
const postTokens = record3.compactMetadata?.postTokens;
|
|
152774
152832
|
next.compaction = laterCompaction(state.compaction, { atMs, ...postTokens === void 0 ? {} : { postTokens: Math.trunc(postTokens) } });
|
|
152775
152833
|
}
|
|
152776
|
-
if (
|
|
152777
|
-
next.cache = foldPromptCache(state.cache,
|
|
152834
|
+
if (record3.isSidechain !== true) {
|
|
152835
|
+
next.cache = foldPromptCache(state.cache, record3, atMs);
|
|
152778
152836
|
}
|
|
152779
152837
|
return next;
|
|
152780
152838
|
}
|
|
152781
|
-
function foldSession(state,
|
|
152782
|
-
return { cumulative: foldCumulative(state.cumulative,
|
|
152839
|
+
function foldSession(state, record3) {
|
|
152840
|
+
return { cumulative: foldCumulative(state.cumulative, record3), latest: foldLatest(state.latest, record3) };
|
|
152783
152841
|
}
|
|
152784
152842
|
function hasRequest(cache) {
|
|
152785
152843
|
return cache.anchorAtMs !== void 0 || cache.pendingAtMs !== void 0;
|
|
@@ -152824,19 +152882,19 @@ var TranscriptCacheSchema = external_exports.strictObject({
|
|
|
152824
152882
|
function eachRecord(bytes, visit2) {
|
|
152825
152883
|
const end = bytes.lastIndexOf(NEWLINE2) + 1;
|
|
152826
152884
|
for (const line of new TextDecoder().decode(bytes.subarray(0, end)).split("\n")) {
|
|
152827
|
-
const
|
|
152828
|
-
if (
|
|
152829
|
-
visit2(
|
|
152885
|
+
const record3 = line === "" ? void 0 : parseTranscriptRecord(line);
|
|
152886
|
+
if (record3 !== void 0) {
|
|
152887
|
+
visit2(record3);
|
|
152830
152888
|
}
|
|
152831
152889
|
}
|
|
152832
152890
|
return end;
|
|
152833
152891
|
}
|
|
152834
152892
|
function foldLines(state, bytes) {
|
|
152835
152893
|
let { session, tokens, activity } = state;
|
|
152836
|
-
const consumed = eachRecord(bytes, (
|
|
152837
|
-
session = foldSession(session,
|
|
152838
|
-
tokens = foldTokens(tokens,
|
|
152839
|
-
activity = foldActivity(activity,
|
|
152894
|
+
const consumed = eachRecord(bytes, (record3) => {
|
|
152895
|
+
session = foldSession(session, record3);
|
|
152896
|
+
tokens = foldTokens(tokens, record3);
|
|
152897
|
+
activity = foldActivity(activity, record3);
|
|
152840
152898
|
});
|
|
152841
152899
|
return { session, tokens, activity, consumed };
|
|
152842
152900
|
}
|
|
@@ -152903,9 +152961,9 @@ function newerFrom(ports, transcriptPath, size, previous, cumulative) {
|
|
|
152903
152961
|
}
|
|
152904
152962
|
function foldNewer(from, bytes, offset) {
|
|
152905
152963
|
let { state, activity } = from;
|
|
152906
|
-
const consumed = eachRecord(bytes, (
|
|
152907
|
-
state = foldLatest(state,
|
|
152908
|
-
activity = foldActivityLatest(activity,
|
|
152964
|
+
const consumed = eachRecord(bytes, (record3) => {
|
|
152965
|
+
state = foldLatest(state, record3);
|
|
152966
|
+
activity = foldActivityLatest(activity, record3);
|
|
152909
152967
|
});
|
|
152910
152968
|
return { offset: offset + consumed, state, activity };
|
|
152911
152969
|
}
|
|
@@ -153116,7 +153174,7 @@ function registerStatuslineCommand(program2, deps) {
|
|
|
153116
153174
|
let modelChoice;
|
|
153117
153175
|
if (sessionHeader !== void 0) {
|
|
153118
153176
|
try {
|
|
153119
|
-
const last = readUsageLog(realFarmFs, deps.paths.usageLogDir, { sinceMs: nowMs - ROUTED_TARGET_LOOKBACK_MS }).records.filter((
|
|
153177
|
+
const last = readUsageLog(realFarmFs, deps.paths.usageLogDir, { sinceMs: nowMs - ROUTED_TARGET_LOOKBACK_MS }).records.filter((record3) => record3.sessionId === sessionHeader).at(-1);
|
|
153120
153178
|
if (last?.model !== void 0) {
|
|
153121
153179
|
if (last.provider !== providerName) {
|
|
153122
153180
|
routedTarget = `${last.provider}/${last.model}`;
|
|
@@ -163422,7 +163480,7 @@ function registerCredentialCommand(program2, deps, ports = realCommandPorts(deps
|
|
|
163422
163480
|
process.stdout.write(REMOTE_LOCK_FRAME);
|
|
163423
163481
|
try {
|
|
163424
163482
|
withIdentityNamesLock(deps.paths, nonWaitingIdentityNamesLockPorts, () => {
|
|
163425
|
-
if (!identityRecords(deps.paths).some((
|
|
163483
|
+
if (!identityRecords(deps.paths).some((record3) => record3.name === name)) {
|
|
163426
163484
|
process.exitCode = REMOTE_NO_IDENTITY_STATUS;
|
|
163427
163485
|
return;
|
|
163428
163486
|
}
|
|
@@ -165001,12 +165059,12 @@ function registerProviderCommand(program2, deps) {
|
|
|
165001
165059
|
const door = readFrontDoorState(realFarmFs, paths.frontdoorStateFile);
|
|
165002
165060
|
const recordedPid = door?.port === void 0 ? void 0 : door.supervisorPid;
|
|
165003
165061
|
const pid = recordedPid !== void 0 && realIsProcessAlive(recordedPid) ? recordedPid : void 0;
|
|
165004
|
-
const
|
|
165005
|
-
const home =
|
|
165006
|
-
const generation =
|
|
165007
|
-
if (pid !== void 0 &&
|
|
165062
|
+
const record3 = pid === void 0 ? void 0 : readFrontDoorCodexRecord(realFarmFs, paths.frontdoorDir, pid);
|
|
165063
|
+
const home = record3?.codexHome;
|
|
165064
|
+
const generation = record3?.generation;
|
|
165065
|
+
if (pid !== void 0 && record3 === void 0) throw new UsageError("The serving front door's Codex home or catalogue generation is unavailable.");
|
|
165008
165066
|
const env = home === void 0 ? process.env : { ...process.env, CODEX_HOME: home };
|
|
165009
|
-
const cache2 = options.refresh === true ? await (pid === void 0 ||
|
|
165067
|
+
const cache2 = options.refresh === true ? await (pid === void 0 || record3 === void 0 ? refreshCatalogueForReal(paths, name, env) : refreshCatalogueForReal(paths, name, env, pid, record3.generation)) : parseCatalogueCache(realFsPort.readFileUtf8(catalogueCachePath(paths, name, pid, generation)));
|
|
165010
165068
|
if (options.refresh === true) {
|
|
165011
165069
|
const currentDoor = readFrontDoorState(realFarmFs, paths.frontdoorStateFile);
|
|
165012
165070
|
const recordedCurrentPid = currentDoor?.port === void 0 ? void 0 : currentDoor.supervisorPid;
|
|
@@ -165580,12 +165638,12 @@ function collectUsageReport(fs35, paths, filters) {
|
|
|
165580
165638
|
const id2 = filters.identity === void 0 ? void 0 : requireIdentityId(paths, filters.identity);
|
|
165581
165639
|
const label2 = identityLabeller(paths);
|
|
165582
165640
|
const log = readUsageLog(fs35, paths.usageLogDir, sinceMs === void 0 ? {} : { sinceMs });
|
|
165583
|
-
const records = log.records.filter((
|
|
165641
|
+
const records = log.records.filter((record3) => (id2 === void 0 || record3.identity === id2) && (provider === void 0 || record3.provider === provider));
|
|
165584
165642
|
const snapshots = (id2 === void 0 ? listUsageSnapshots(fs35, paths.usageSnapshotsDir) : [readUsageSnapshot(fs35, paths.usageSnapshotsDir, id2)].flatMap((snapshot) => snapshot === void 0 ? [] : [snapshot])).map((snapshot) => provider === void 0 ? snapshot : { ...snapshot, providers: Object.fromEntries(Object.entries(snapshot.providers).filter(([name]) => name === provider)) }).filter((snapshot) => Object.keys(snapshot.providers).length > 0).map((snapshot) => ({ ...snapshot, identity: label2(snapshot.identity) }));
|
|
165585
165643
|
return {
|
|
165586
165644
|
since: sinceMs === void 0 ? void 0 : new Date(sinceMs).toISOString(),
|
|
165587
165645
|
logDir: paths.usageLogDir,
|
|
165588
|
-
summaries: summariseUsage(records.map((
|
|
165646
|
+
summaries: summariseUsage(records.map((record3) => record3.identity === void 0 ? record3 : { ...record3, identity: label2(record3.identity) })),
|
|
165589
165647
|
snapshots,
|
|
165590
165648
|
invalidLines: log.invalidLines
|
|
165591
165649
|
};
|
|
@@ -165748,7 +165806,7 @@ async function refreshQuotas(paths, filters) {
|
|
|
165748
165806
|
const warnings = [];
|
|
165749
165807
|
if (filters.provider === void 0 || filters.provider === ANTHROPIC_PROVIDER) {
|
|
165750
165808
|
const anthropic = createRealAnthropicUsageRefresher({ paths, store, cwd: process.cwd(), spawnDaemon: spawnDetachedSupervisor, log: () => void 0 });
|
|
165751
|
-
const names = new Map(identityRecords(paths).map((
|
|
165809
|
+
const names = new Map(identityRecords(paths).map((record3) => [record3.id, record3.name]));
|
|
165752
165810
|
const subscribed = (id2 === void 0 ? listUsageSnapshots(realFarmFs, paths.usageSnapshotsDir).map((snapshot) => snapshot.identity) : [id2]).flatMap((snapshotId) => {
|
|
165753
165811
|
const name = names.get(snapshotId);
|
|
165754
165812
|
return name === void 0 ? [] : [{ name, snapshot: readUsageSnapshot(realFarmFs, paths.usageSnapshotsDir, snapshotId), account: readAccountMetadata(realFarmFs, paths.identitiesDir, snapshotId) }];
|
|
@@ -166330,7 +166388,7 @@ function createCompactionDeps(wiring) {
|
|
|
166330
166388
|
return decideCompaction({
|
|
166331
166389
|
atUtilisation: wiring.policy.compactAtUtilisation,
|
|
166332
166390
|
snapshot: readUsageSnapshot(fs35, paths.usageSnapshotsDir, identity),
|
|
166333
|
-
records: () => readUsageLog(fs35, paths.usageLogDir, { sinceMs: nowMs - FIVE_HOUR_WINDOW_MS }).records.filter((
|
|
166391
|
+
records: () => readUsageLog(fs35, paths.usageLogDir, { sinceMs: nowMs - FIVE_HOUR_WINDOW_MS }).records.filter((record3) => record3.identity === identity),
|
|
166334
166392
|
sessions,
|
|
166335
166393
|
sessionId,
|
|
166336
166394
|
nowMs
|
|
@@ -166369,9 +166427,9 @@ function quotaHitOf(fs35, paths, identity, sessionId, sinceMs, nowMs) {
|
|
|
166369
166427
|
}
|
|
166370
166428
|
const { records } = readUsageLog(fs35, paths.usageLogDir, { sinceMs });
|
|
166371
166429
|
for (let index = records.length - 1; index >= 0; index -= 1) {
|
|
166372
|
-
const
|
|
166373
|
-
if (
|
|
166374
|
-
return { reason, ...
|
|
166430
|
+
const record3 = records[index];
|
|
166431
|
+
if (record3?.sessionId === sessionId && record3.identity === identity && record3.limit?.kind === "quota-exhausted") {
|
|
166432
|
+
return { reason, ...record3.limit.resetAt === void 0 ? {} : { resetAt: record3.limit.resetAt } };
|
|
166375
166433
|
}
|
|
166376
166434
|
}
|
|
166377
166435
|
return void 0;
|
|
@@ -166464,7 +166522,7 @@ function createIdentityMover(deps) {
|
|
|
166464
166522
|
throw error63;
|
|
166465
166523
|
}
|
|
166466
166524
|
try {
|
|
166467
|
-
const toRecord = identityRecordsOver(farmFs, paths.identitiesDir).find((
|
|
166525
|
+
const toRecord = identityRecordsOver(farmFs, paths.identitiesDir).find((record3) => record3.id === request7.to);
|
|
166468
166526
|
const toName = toRecord === void 0 ? void 0 : toRecord.name ?? toRecord.id;
|
|
166469
166527
|
if (toName === void 0) {
|
|
166470
166528
|
return { kind: "stay", reason: `no identity is stored under identities/${request7.to}` };
|
|
@@ -166932,8 +166990,8 @@ async function runSupervised(params) {
|
|
|
166932
166990
|
log,
|
|
166933
166991
|
// An identity whose name cannot be read is named by its id, which reaches it, so its relaunch reports the file.
|
|
166934
166992
|
nameOf: (id2) => {
|
|
166935
|
-
const
|
|
166936
|
-
return
|
|
166993
|
+
const record3 = identityRecordsOver(realFarmFs, paths.identitiesDir).find((candidate) => candidate.id === id2);
|
|
166994
|
+
return record3 === void 0 ? void 0 : record3.name ?? record3.id;
|
|
166937
166995
|
}
|
|
166938
166996
|
},
|
|
166939
166997
|
launch
|