agent-shim 11.86.3 → 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 +365 -302
- 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);
|
|
@@ -148665,10 +148723,12 @@ function enrichStatuslinePayload(params) {
|
|
|
148665
148723
|
const clientEmail = isObject4(params.payload) && typeof params.payload.email === "string" && params.payload.email !== "" ? params.payload.email : void 0;
|
|
148666
148724
|
const clientPlan = clientEmail !== void 0 && isObject4(params.payload) && typeof params.payload.plan_tier === "string" && params.payload.plan_tier !== "" ? params.payload.plan_tier : void 0;
|
|
148667
148725
|
const account = clientEmail === void 0 ? params.account : void 0;
|
|
148726
|
+
const routedProvider = routedProviderOf(params);
|
|
148727
|
+
const launchProvider = params.env.AGENT_SHIM_PROVIDER;
|
|
148668
148728
|
let summary = {
|
|
148669
148729
|
identity: params.identityName ?? identity,
|
|
148670
148730
|
identityLabel: params.identityLabel,
|
|
148671
|
-
provider:
|
|
148731
|
+
provider: launchProvider === void 0 || launchProvider === "" ? routedProvider : routedProvider !== void 0 && routedProvider.toLowerCase() !== (params.providerName ?? launchProvider).toLowerCase() ? routedProvider : launchProvider,
|
|
148672
148732
|
providerAccountEmail: void 0,
|
|
148673
148733
|
providerAccountSub: void 0,
|
|
148674
148734
|
providerPlan: void 0,
|
|
@@ -148690,9 +148750,8 @@ function enrichStatuslinePayload(params) {
|
|
|
148690
148750
|
...params.doorCostUsd === void 0 ? {} : { doorCostUsd: params.doorCostUsd }
|
|
148691
148751
|
};
|
|
148692
148752
|
let scopedName;
|
|
148693
|
-
const routedProvider = routedProviderOf(params);
|
|
148694
148753
|
if (params.snapshot !== void 0) {
|
|
148695
|
-
scopedName = providerScopedState(params.snapshot, params.providerName, params.env.AGENT_SHIM_PROVIDER)
|
|
148754
|
+
scopedName = routedProvider === void 0 ? providerScopedState(params.snapshot, params.providerName, params.env.AGENT_SHIM_PROVIDER) : providerScopedState(params.snapshot, routedProvider, routedProvider);
|
|
148696
148755
|
const scopedState = scopedName === void 0 ? void 0 : params.snapshot.providers[scopedName];
|
|
148697
148756
|
const states = summary.provider === void 0 && routedProvider === void 0 && scopedState === void 0 ? Object.values(params.snapshot.providers) : scopedState === void 0 ? [] : [scopedState];
|
|
148698
148757
|
let email3;
|
|
@@ -148748,6 +148807,11 @@ function enrichStatuslinePayload(params) {
|
|
|
148748
148807
|
return { payload: enriched, summary };
|
|
148749
148808
|
}
|
|
148750
148809
|
function routedProviderOf(params) {
|
|
148810
|
+
const model = isObject4(params.payload) && isObject4(params.payload.model) ? params.payload.model : void 0;
|
|
148811
|
+
const selectedProvider = prefixBeforeSlash(typeof model?.id === "string" ? model.id : void 0) ?? prefixBeforeSlash(typeof model?.display_name === "string" ? model.display_name : void 0);
|
|
148812
|
+
if (selectedProvider !== void 0) {
|
|
148813
|
+
return selectedProvider;
|
|
148814
|
+
}
|
|
148751
148815
|
if (params.modelChoice?.provider !== void 0 && params.modelChoice.provider !== "") {
|
|
148752
148816
|
return params.modelChoice.provider;
|
|
148753
148817
|
}
|
|
@@ -148755,8 +148819,7 @@ function routedProviderOf(params) {
|
|
|
148755
148819
|
if (targetPrefix !== void 0) {
|
|
148756
148820
|
return targetPrefix;
|
|
148757
148821
|
}
|
|
148758
|
-
|
|
148759
|
-
return prefixBeforeSlash(typeof model?.id === "string" ? model.id : void 0) ?? prefixBeforeSlash(typeof model?.display_name === "string" ? model.display_name : void 0);
|
|
148822
|
+
return void 0;
|
|
148760
148823
|
}
|
|
148761
148824
|
function prefixBeforeSlash(value3) {
|
|
148762
148825
|
if (value3 === void 0) {
|
|
@@ -148839,12 +148902,12 @@ var CACHE_READ_PRICE_RATIO = 0.1;
|
|
|
148839
148902
|
function doorCostUsdOf(records, prices) {
|
|
148840
148903
|
let totalUsd = 0;
|
|
148841
148904
|
let costed = 0;
|
|
148842
|
-
for (const
|
|
148843
|
-
const { usage } =
|
|
148905
|
+
for (const record3 of records) {
|
|
148906
|
+
const { usage } = record3;
|
|
148844
148907
|
if (usage === void 0) {
|
|
148845
148908
|
continue;
|
|
148846
148909
|
}
|
|
148847
|
-
const price =
|
|
148910
|
+
const price = record3.model === void 0 ? void 0 : prices[`${record3.provider}/${record3.model}`];
|
|
148848
148911
|
if (price === void 0) {
|
|
148849
148912
|
return void 0;
|
|
148850
148913
|
}
|
|
@@ -148894,7 +148957,7 @@ function readDoorCostUsd(params) {
|
|
|
148894
148957
|
const sinceMs = sessionDurationMs === void 0 ? void 0 : Date.parse(`${segmentDay(nowMs - sessionDurationMs)}T00:00:00.000Z`);
|
|
148895
148958
|
const { records } = readUsageLog(params.fs, params.logDir, sinceMs === void 0 ? {} : { sinceMs });
|
|
148896
148959
|
return doorCostUsdOf(
|
|
148897
|
-
records.filter((
|
|
148960
|
+
records.filter((record3) => record3.clientSessionId === params.conversationId),
|
|
148898
148961
|
params.prices
|
|
148899
148962
|
);
|
|
148900
148963
|
}
|
|
@@ -150774,8 +150837,8 @@ function afterCompaction(frame, compaction) {
|
|
|
150774
150837
|
}
|
|
150775
150838
|
return { ...frame, used_percentage: Math.min(FULL_PERCENT3, postTokens / windowTokens * FULL_PERCENT3) };
|
|
150776
150839
|
}
|
|
150777
|
-
function restored(frame,
|
|
150778
|
-
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 };
|
|
150779
150842
|
}
|
|
150780
150843
|
function recordOf2(frame, usedPercentage, observedAtMs, nowMs) {
|
|
150781
150844
|
const usage = frame.current_usage;
|
|
@@ -150822,14 +150885,14 @@ function contextFrameOf(input2) {
|
|
|
150822
150885
|
let observedAtMs = nowMs;
|
|
150823
150886
|
if (isSuspiciousZero(frame) && !input2.drawsPercent) {
|
|
150824
150887
|
const loaded = loadCache(ports, file2, ContextRecordSchema);
|
|
150825
|
-
const
|
|
150888
|
+
const record3 = loaded !== void 0 && nowMs - loaded.savedAtMs <= CONTEXT_RECORD_MAX_AGE_MS ? loaded : void 0;
|
|
150826
150889
|
const compaction = input2.compaction();
|
|
150827
|
-
if (compaction !== void 0 && (
|
|
150890
|
+
if (compaction !== void 0 && (record3 === void 0 || compaction.atMs > record3.observedAtMs)) {
|
|
150828
150891
|
drawn = afterCompaction(frame, compaction);
|
|
150829
150892
|
observedAtMs = compaction.atMs;
|
|
150830
|
-
} else if (
|
|
150831
|
-
drawn = restored(frame,
|
|
150832
|
-
observedAtMs =
|
|
150893
|
+
} else if (record3 !== void 0) {
|
|
150894
|
+
drawn = restored(frame, record3);
|
|
150895
|
+
observedAtMs = record3.observedAtMs;
|
|
150833
150896
|
}
|
|
150834
150897
|
}
|
|
150835
150898
|
const goodPercent = goodPercentOf(drawn);
|
|
@@ -151520,9 +151583,9 @@ function wholeTokens(count2) {
|
|
|
151520
151583
|
function writtenCountsKey(usage) {
|
|
151521
151584
|
return [usage.input_tokens, usage.output_tokens, usage.cache_creation_input_tokens, usage.cache_read_input_tokens].map(String).join("|");
|
|
151522
151585
|
}
|
|
151523
|
-
function foldTokens(state,
|
|
151524
|
-
const usage =
|
|
151525
|
-
if (
|
|
151586
|
+
function foldTokens(state, record3) {
|
|
151587
|
+
const usage = record3.message?.usage;
|
|
151588
|
+
if (record3.type !== "assistant" || usage === void 0) {
|
|
151526
151589
|
return state;
|
|
151527
151590
|
}
|
|
151528
151591
|
const counts = {
|
|
@@ -151531,7 +151594,7 @@ function foldTokens(state, record2) {
|
|
|
151531
151594
|
cacheCreationTokens: wholeTokens(usage.cache_creation_input_tokens),
|
|
151532
151595
|
cacheReadTokens: wholeTokens(usage.cache_read_input_tokens)
|
|
151533
151596
|
};
|
|
151534
|
-
const key =
|
|
151597
|
+
const key = record3.message?.id ?? writtenCountsKey(usage);
|
|
151535
151598
|
if (state.open?.key === key) {
|
|
151536
151599
|
return { totals: sum(state.totals, increase(state.open.usage, counts)), open: { key, usage: larger(state.open.usage, counts) } };
|
|
151537
151600
|
}
|
|
@@ -151629,15 +151692,15 @@ function identityOfLine(line) {
|
|
|
151629
151692
|
} catch {
|
|
151630
151693
|
return void 0;
|
|
151631
151694
|
}
|
|
151632
|
-
const
|
|
151633
|
-
if (!
|
|
151695
|
+
const record3 = RecordSchema.safeParse(parsed);
|
|
151696
|
+
if (!record3.success || record3.data.type !== "assistant") {
|
|
151634
151697
|
return void 0;
|
|
151635
151698
|
}
|
|
151636
|
-
const model = boundedDisplayText(
|
|
151699
|
+
const model = boundedDisplayText(record3.data.message?.model ?? "");
|
|
151637
151700
|
if (model === "" || model === SYNTHETIC_MODEL) {
|
|
151638
151701
|
return void 0;
|
|
151639
151702
|
}
|
|
151640
|
-
const advisor = boundedDisplayText(
|
|
151703
|
+
const advisor = boundedDisplayText(record3.data.advisorModel ?? "");
|
|
151641
151704
|
return { model, advisor: advisor === "" ? void 0 : advisor };
|
|
151642
151705
|
}
|
|
151643
151706
|
function joined2(pieces) {
|
|
@@ -152178,11 +152241,11 @@ function parseTranscriptRecord(line) {
|
|
|
152178
152241
|
}
|
|
152179
152242
|
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? TranscriptRecordSchema.parse(parsed) : void 0;
|
|
152180
152243
|
}
|
|
152181
|
-
function recordTimeMs(
|
|
152182
|
-
if (
|
|
152244
|
+
function recordTimeMs(record3) {
|
|
152245
|
+
if (record3.timestamp === void 0) {
|
|
152183
152246
|
return void 0;
|
|
152184
152247
|
}
|
|
152185
|
-
const ms = Date.parse(
|
|
152248
|
+
const ms = Date.parse(record3.timestamp);
|
|
152186
152249
|
return Number.isNaN(ms) ? void 0 : ms;
|
|
152187
152250
|
}
|
|
152188
152251
|
|
|
@@ -152546,32 +152609,32 @@ function withUnanswered(tools, agents) {
|
|
|
152546
152609
|
function foldNewResponse(state, key) {
|
|
152547
152610
|
return { ...state, responseKey: key, ...withUnanswered(state.tools, state.agents) };
|
|
152548
152611
|
}
|
|
152549
|
-
function foldActivityLatest(state,
|
|
152550
|
-
if (
|
|
152612
|
+
function foldActivityLatest(state, record3) {
|
|
152613
|
+
if (record3.isSidechain === true) {
|
|
152551
152614
|
return state;
|
|
152552
152615
|
}
|
|
152553
|
-
const atMs = recordTimeMs(
|
|
152616
|
+
const atMs = recordTimeMs(record3);
|
|
152554
152617
|
let next = state;
|
|
152555
|
-
if (
|
|
152556
|
-
const toolUseId = QUEUED_TOOL_USE_ID.exec(
|
|
152557
|
-
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)) {
|
|
152558
152621
|
next = foldAgentAnnouncement(next, toolUseId, atMs);
|
|
152559
152622
|
}
|
|
152560
152623
|
}
|
|
152561
|
-
const responseKey =
|
|
152624
|
+
const responseKey = record3.type === "assistant" ? record3.message?.id ?? record3.requestId : void 0;
|
|
152562
152625
|
if (responseKey !== void 0 && responseKey !== next.responseKey) {
|
|
152563
152626
|
next = next.responseKey === void 0 ? { ...next, responseKey } : foldNewResponse(next, responseKey);
|
|
152564
152627
|
}
|
|
152565
|
-
const content =
|
|
152628
|
+
const content = record3.message?.content;
|
|
152566
152629
|
if (!Array.isArray(content)) {
|
|
152567
152630
|
return next;
|
|
152568
152631
|
}
|
|
152569
152632
|
const resultCount = content.filter((block2) => block2.type === "tool_result").length;
|
|
152570
152633
|
for (const block2 of content) {
|
|
152571
|
-
if (
|
|
152634
|
+
if (record3.type === "assistant" && block2.type === "tool_use" && block2.id !== void 0 && block2.name !== void 0 && !isRemembered(next, block2.id, atMs)) {
|
|
152572
152635
|
next = foldToolUse(remember2(next, block2.id, atMs), { id: block2.id, name: block2.name, input: block2.input }, atMs);
|
|
152573
|
-
} else if (
|
|
152574
|
-
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;
|
|
152575
152638
|
const taskId = createdTaskId(block2.content, outcome);
|
|
152576
152639
|
next = foldToolResult(next, {
|
|
152577
152640
|
id: block2.tool_use_id,
|
|
@@ -152604,9 +152667,9 @@ function withName(set3, name) {
|
|
|
152604
152667
|
}
|
|
152605
152668
|
return { ...set3, others: [...set3.others, digest2] };
|
|
152606
152669
|
}
|
|
152607
|
-
function foldActivityCumulative(state,
|
|
152608
|
-
const content =
|
|
152609
|
-
if (
|
|
152670
|
+
function foldActivityCumulative(state, record3) {
|
|
152671
|
+
const content = record3.message?.content;
|
|
152672
|
+
if (record3.isSidechain === true || record3.type !== "assistant" || !Array.isArray(content)) {
|
|
152610
152673
|
return state;
|
|
152611
152674
|
}
|
|
152612
152675
|
let { skills, mcpServers } = state;
|
|
@@ -152623,8 +152686,8 @@ function foldActivityCumulative(state, record2) {
|
|
|
152623
152686
|
}
|
|
152624
152687
|
return skills === state.skills && mcpServers === state.mcpServers ? state : { skills, mcpServers };
|
|
152625
152688
|
}
|
|
152626
|
-
function foldActivity(state,
|
|
152627
|
-
return { cumulative: foldActivityCumulative(state.cumulative,
|
|
152689
|
+
function foldActivity(state, record3) {
|
|
152690
|
+
return { cumulative: foldActivityCumulative(state.cumulative, record3), latest: foldActivityLatest(state.latest, record3) };
|
|
152628
152691
|
}
|
|
152629
152692
|
function isLive(startedAtMs, nowMs, maxMs) {
|
|
152630
152693
|
return startedAtMs === void 0 || nowMs - startedAtMs <= maxMs;
|
|
@@ -152703,8 +152766,8 @@ var LOCAL_ONLY_USER_TEXT_PREFIXES = ["<command-name>", "<command-message>", "<lo
|
|
|
152703
152766
|
function isLocalOnlyUserText(text5) {
|
|
152704
152767
|
return LOCAL_ONLY_USER_TEXT_PREFIXES.some((prefix) => text5.startsWith(prefix));
|
|
152705
152768
|
}
|
|
152706
|
-
function opensRequest(
|
|
152707
|
-
const content =
|
|
152769
|
+
function opensRequest(record3) {
|
|
152770
|
+
const content = record3.message?.content;
|
|
152708
152771
|
if (typeof content === "string") {
|
|
152709
152772
|
return !isLocalOnlyUserText(content);
|
|
152710
152773
|
}
|
|
@@ -152713,34 +152776,34 @@ function opensRequest(record2) {
|
|
|
152713
152776
|
}
|
|
152714
152777
|
return true;
|
|
152715
152778
|
}
|
|
152716
|
-
function ttlOf(
|
|
152717
|
-
const writes =
|
|
152779
|
+
function ttlOf(record3) {
|
|
152780
|
+
const writes = record3.message?.usage?.cache_creation;
|
|
152718
152781
|
if ((writes?.ephemeral_5m_input_tokens ?? 0) > 0) {
|
|
152719
152782
|
return PROMPT_CACHE_TTL_SECONDS.fiveMinutes;
|
|
152720
152783
|
}
|
|
152721
152784
|
return (writes?.ephemeral_1h_input_tokens ?? 0) > 0 ? PROMPT_CACHE_TTL_SECONDS.oneHour : void 0;
|
|
152722
152785
|
}
|
|
152723
|
-
function foldPromptCache(cache,
|
|
152786
|
+
function foldPromptCache(cache, record3, atMs) {
|
|
152724
152787
|
if (atMs === void 0) {
|
|
152725
152788
|
return cache;
|
|
152726
152789
|
}
|
|
152727
152790
|
let next = cache;
|
|
152728
|
-
if (
|
|
152729
|
-
const startsRequest =
|
|
152791
|
+
if (record3.type === "assistant") {
|
|
152792
|
+
const startsRequest = record3.requestId === void 0 || record3.requestId !== cache.requestId;
|
|
152730
152793
|
const requestAnchorAtMs = startsRequest ? cache.previousMainAtMs : cache.requestAnchorAtMs;
|
|
152731
152794
|
const anchorAtMs = requestAnchorAtMs !== void 0 && requestAnchorAtMs <= atMs ? requestAnchorAtMs : atMs;
|
|
152732
|
-
const ttlSeconds = ttlOf(
|
|
152733
|
-
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 };
|
|
152734
152797
|
}
|
|
152735
|
-
if (
|
|
152798
|
+
if (record3.type === "user" && opensRequest(record3)) {
|
|
152736
152799
|
next = { ...next, pendingAtMs: atMs };
|
|
152737
152800
|
}
|
|
152738
152801
|
return { ...next, previousMainAtMs: atMs };
|
|
152739
152802
|
}
|
|
152740
|
-
function foldCumulative(state,
|
|
152741
|
-
const atMs = recordTimeMs(
|
|
152803
|
+
function foldCumulative(state, record3) {
|
|
152804
|
+
const atMs = recordTimeMs(record3);
|
|
152742
152805
|
const next = { ...state };
|
|
152743
|
-
if (
|
|
152806
|
+
if (record3.type === "system" && record3.subtype === "compact_boundary" && atMs !== void 0) {
|
|
152744
152807
|
next.compactions += 1;
|
|
152745
152808
|
}
|
|
152746
152809
|
if (atMs !== void 0 && next.startedAtMs === void 0 && next.startUnknown !== true) {
|
|
@@ -152751,30 +152814,30 @@ function foldCumulative(state, record2) {
|
|
|
152751
152814
|
function laterCompaction(held, met) {
|
|
152752
152815
|
return held === void 0 || met !== void 0 && met.atMs > held.atMs ? met : held;
|
|
152753
152816
|
}
|
|
152754
|
-
function foldLatest(state,
|
|
152755
|
-
const atMs = recordTimeMs(
|
|
152817
|
+
function foldLatest(state, record3) {
|
|
152818
|
+
const atMs = recordTimeMs(record3);
|
|
152756
152819
|
const next = { ...state };
|
|
152757
|
-
if (
|
|
152758
|
-
next.customTitle =
|
|
152759
|
-
} else if (
|
|
152760
|
-
next.aiTitle =
|
|
152761
|
-
} else if (
|
|
152762
|
-
next.slug =
|
|
152763
|
-
}
|
|
152764
|
-
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) {
|
|
152765
152828
|
next.lastAssistantAtMs = atMs;
|
|
152766
152829
|
}
|
|
152767
|
-
if (
|
|
152768
|
-
const postTokens =
|
|
152830
|
+
if (record3.type === "system" && record3.subtype === "compact_boundary" && atMs !== void 0) {
|
|
152831
|
+
const postTokens = record3.compactMetadata?.postTokens;
|
|
152769
152832
|
next.compaction = laterCompaction(state.compaction, { atMs, ...postTokens === void 0 ? {} : { postTokens: Math.trunc(postTokens) } });
|
|
152770
152833
|
}
|
|
152771
|
-
if (
|
|
152772
|
-
next.cache = foldPromptCache(state.cache,
|
|
152834
|
+
if (record3.isSidechain !== true) {
|
|
152835
|
+
next.cache = foldPromptCache(state.cache, record3, atMs);
|
|
152773
152836
|
}
|
|
152774
152837
|
return next;
|
|
152775
152838
|
}
|
|
152776
|
-
function foldSession(state,
|
|
152777
|
-
return { cumulative: foldCumulative(state.cumulative,
|
|
152839
|
+
function foldSession(state, record3) {
|
|
152840
|
+
return { cumulative: foldCumulative(state.cumulative, record3), latest: foldLatest(state.latest, record3) };
|
|
152778
152841
|
}
|
|
152779
152842
|
function hasRequest(cache) {
|
|
152780
152843
|
return cache.anchorAtMs !== void 0 || cache.pendingAtMs !== void 0;
|
|
@@ -152819,19 +152882,19 @@ var TranscriptCacheSchema = external_exports.strictObject({
|
|
|
152819
152882
|
function eachRecord(bytes, visit2) {
|
|
152820
152883
|
const end = bytes.lastIndexOf(NEWLINE2) + 1;
|
|
152821
152884
|
for (const line of new TextDecoder().decode(bytes.subarray(0, end)).split("\n")) {
|
|
152822
|
-
const
|
|
152823
|
-
if (
|
|
152824
|
-
visit2(
|
|
152885
|
+
const record3 = line === "" ? void 0 : parseTranscriptRecord(line);
|
|
152886
|
+
if (record3 !== void 0) {
|
|
152887
|
+
visit2(record3);
|
|
152825
152888
|
}
|
|
152826
152889
|
}
|
|
152827
152890
|
return end;
|
|
152828
152891
|
}
|
|
152829
152892
|
function foldLines(state, bytes) {
|
|
152830
152893
|
let { session, tokens, activity } = state;
|
|
152831
|
-
const consumed = eachRecord(bytes, (
|
|
152832
|
-
session = foldSession(session,
|
|
152833
|
-
tokens = foldTokens(tokens,
|
|
152834
|
-
activity = foldActivity(activity,
|
|
152894
|
+
const consumed = eachRecord(bytes, (record3) => {
|
|
152895
|
+
session = foldSession(session, record3);
|
|
152896
|
+
tokens = foldTokens(tokens, record3);
|
|
152897
|
+
activity = foldActivity(activity, record3);
|
|
152835
152898
|
});
|
|
152836
152899
|
return { session, tokens, activity, consumed };
|
|
152837
152900
|
}
|
|
@@ -152898,9 +152961,9 @@ function newerFrom(ports, transcriptPath, size, previous, cumulative) {
|
|
|
152898
152961
|
}
|
|
152899
152962
|
function foldNewer(from, bytes, offset) {
|
|
152900
152963
|
let { state, activity } = from;
|
|
152901
|
-
const consumed = eachRecord(bytes, (
|
|
152902
|
-
state = foldLatest(state,
|
|
152903
|
-
activity = foldActivityLatest(activity,
|
|
152964
|
+
const consumed = eachRecord(bytes, (record3) => {
|
|
152965
|
+
state = foldLatest(state, record3);
|
|
152966
|
+
activity = foldActivityLatest(activity, record3);
|
|
152904
152967
|
});
|
|
152905
152968
|
return { offset: offset + consumed, state, activity };
|
|
152906
152969
|
}
|
|
@@ -153111,7 +153174,7 @@ function registerStatuslineCommand(program2, deps) {
|
|
|
153111
153174
|
let modelChoice;
|
|
153112
153175
|
if (sessionHeader !== void 0) {
|
|
153113
153176
|
try {
|
|
153114
|
-
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);
|
|
153115
153178
|
if (last?.model !== void 0) {
|
|
153116
153179
|
if (last.provider !== providerName) {
|
|
153117
153180
|
routedTarget = `${last.provider}/${last.model}`;
|
|
@@ -163417,7 +163480,7 @@ function registerCredentialCommand(program2, deps, ports = realCommandPorts(deps
|
|
|
163417
163480
|
process.stdout.write(REMOTE_LOCK_FRAME);
|
|
163418
163481
|
try {
|
|
163419
163482
|
withIdentityNamesLock(deps.paths, nonWaitingIdentityNamesLockPorts, () => {
|
|
163420
|
-
if (!identityRecords(deps.paths).some((
|
|
163483
|
+
if (!identityRecords(deps.paths).some((record3) => record3.name === name)) {
|
|
163421
163484
|
process.exitCode = REMOTE_NO_IDENTITY_STATUS;
|
|
163422
163485
|
return;
|
|
163423
163486
|
}
|
|
@@ -164996,12 +165059,12 @@ function registerProviderCommand(program2, deps) {
|
|
|
164996
165059
|
const door = readFrontDoorState(realFarmFs, paths.frontdoorStateFile);
|
|
164997
165060
|
const recordedPid = door?.port === void 0 ? void 0 : door.supervisorPid;
|
|
164998
165061
|
const pid = recordedPid !== void 0 && realIsProcessAlive(recordedPid) ? recordedPid : void 0;
|
|
164999
|
-
const
|
|
165000
|
-
const home =
|
|
165001
|
-
const generation =
|
|
165002
|
-
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.");
|
|
165003
165066
|
const env = home === void 0 ? process.env : { ...process.env, CODEX_HOME: home };
|
|
165004
|
-
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)));
|
|
165005
165068
|
if (options.refresh === true) {
|
|
165006
165069
|
const currentDoor = readFrontDoorState(realFarmFs, paths.frontdoorStateFile);
|
|
165007
165070
|
const recordedCurrentPid = currentDoor?.port === void 0 ? void 0 : currentDoor.supervisorPid;
|
|
@@ -165575,12 +165638,12 @@ function collectUsageReport(fs35, paths, filters) {
|
|
|
165575
165638
|
const id2 = filters.identity === void 0 ? void 0 : requireIdentityId(paths, filters.identity);
|
|
165576
165639
|
const label2 = identityLabeller(paths);
|
|
165577
165640
|
const log = readUsageLog(fs35, paths.usageLogDir, sinceMs === void 0 ? {} : { sinceMs });
|
|
165578
|
-
const records = log.records.filter((
|
|
165641
|
+
const records = log.records.filter((record3) => (id2 === void 0 || record3.identity === id2) && (provider === void 0 || record3.provider === provider));
|
|
165579
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) }));
|
|
165580
165643
|
return {
|
|
165581
165644
|
since: sinceMs === void 0 ? void 0 : new Date(sinceMs).toISOString(),
|
|
165582
165645
|
logDir: paths.usageLogDir,
|
|
165583
|
-
summaries: summariseUsage(records.map((
|
|
165646
|
+
summaries: summariseUsage(records.map((record3) => record3.identity === void 0 ? record3 : { ...record3, identity: label2(record3.identity) })),
|
|
165584
165647
|
snapshots,
|
|
165585
165648
|
invalidLines: log.invalidLines
|
|
165586
165649
|
};
|
|
@@ -165743,7 +165806,7 @@ async function refreshQuotas(paths, filters) {
|
|
|
165743
165806
|
const warnings = [];
|
|
165744
165807
|
if (filters.provider === void 0 || filters.provider === ANTHROPIC_PROVIDER) {
|
|
165745
165808
|
const anthropic = createRealAnthropicUsageRefresher({ paths, store, cwd: process.cwd(), spawnDaemon: spawnDetachedSupervisor, log: () => void 0 });
|
|
165746
|
-
const names = new Map(identityRecords(paths).map((
|
|
165809
|
+
const names = new Map(identityRecords(paths).map((record3) => [record3.id, record3.name]));
|
|
165747
165810
|
const subscribed = (id2 === void 0 ? listUsageSnapshots(realFarmFs, paths.usageSnapshotsDir).map((snapshot) => snapshot.identity) : [id2]).flatMap((snapshotId) => {
|
|
165748
165811
|
const name = names.get(snapshotId);
|
|
165749
165812
|
return name === void 0 ? [] : [{ name, snapshot: readUsageSnapshot(realFarmFs, paths.usageSnapshotsDir, snapshotId), account: readAccountMetadata(realFarmFs, paths.identitiesDir, snapshotId) }];
|
|
@@ -166325,7 +166388,7 @@ function createCompactionDeps(wiring) {
|
|
|
166325
166388
|
return decideCompaction({
|
|
166326
166389
|
atUtilisation: wiring.policy.compactAtUtilisation,
|
|
166327
166390
|
snapshot: readUsageSnapshot(fs35, paths.usageSnapshotsDir, identity),
|
|
166328
|
-
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),
|
|
166329
166392
|
sessions,
|
|
166330
166393
|
sessionId,
|
|
166331
166394
|
nowMs
|
|
@@ -166364,9 +166427,9 @@ function quotaHitOf(fs35, paths, identity, sessionId, sinceMs, nowMs) {
|
|
|
166364
166427
|
}
|
|
166365
166428
|
const { records } = readUsageLog(fs35, paths.usageLogDir, { sinceMs });
|
|
166366
166429
|
for (let index = records.length - 1; index >= 0; index -= 1) {
|
|
166367
|
-
const
|
|
166368
|
-
if (
|
|
166369
|
-
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 } };
|
|
166370
166433
|
}
|
|
166371
166434
|
}
|
|
166372
166435
|
return void 0;
|
|
@@ -166459,7 +166522,7 @@ function createIdentityMover(deps) {
|
|
|
166459
166522
|
throw error63;
|
|
166460
166523
|
}
|
|
166461
166524
|
try {
|
|
166462
|
-
const toRecord = identityRecordsOver(farmFs, paths.identitiesDir).find((
|
|
166525
|
+
const toRecord = identityRecordsOver(farmFs, paths.identitiesDir).find((record3) => record3.id === request7.to);
|
|
166463
166526
|
const toName = toRecord === void 0 ? void 0 : toRecord.name ?? toRecord.id;
|
|
166464
166527
|
if (toName === void 0) {
|
|
166465
166528
|
return { kind: "stay", reason: `no identity is stored under identities/${request7.to}` };
|
|
@@ -166927,8 +166990,8 @@ async function runSupervised(params) {
|
|
|
166927
166990
|
log,
|
|
166928
166991
|
// An identity whose name cannot be read is named by its id, which reaches it, so its relaunch reports the file.
|
|
166929
166992
|
nameOf: (id2) => {
|
|
166930
|
-
const
|
|
166931
|
-
return
|
|
166993
|
+
const record3 = identityRecordsOver(realFarmFs, paths.identitiesDir).find((candidate) => candidate.id === id2);
|
|
166994
|
+
return record3 === void 0 ? void 0 : record3.name ?? record3.id;
|
|
166932
166995
|
}
|
|
166933
166996
|
},
|
|
166934
166997
|
launch
|