@cortexkit/opencode-antigravity-auth 3.0.41 → 3.0.42
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.js +1186 -1179
- package/dist/cli.js.map +4 -4
- package/dist/cli.meta.json +99 -89
- package/dist/index.js +532 -456
- package/dist/index.js.map +4 -4
- package/dist/index.meta.json +105 -95
- package/dist/server.js +532 -456
- package/dist/server.js.map +4 -4
- package/dist/server.meta.json +1 -1
- package/dist/src/common-auth-embedded/fs/refresh-file-lock.js +13 -9
- package/dist/src/common-auth-embedded/routing-accessor/index.d.ts +33 -5
- package/dist/src/common-auth-embedded/routing-accessor/index.js +49 -7
- package/dist/src/common-auth-embedded/source-output.json +15 -15
- package/dist/src/plugin/__fixtures__/verified-store.js +2 -2
- package/dist/src/plugin/request-helpers.d.ts +10 -0
- package/dist/src/plugin/request-helpers.d.ts.map +1 -1
- package/dist/src/plugin/request-helpers.js +6 -0
- package/dist/src/plugin/request-helpers.js.map +1 -1
- package/dist/src/plugin/shared/request-services.d.ts +8 -1
- package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
- package/dist/src/plugin/shared/request-services.js +39 -0
- package/dist/src/plugin/shared/request-services.js.map +1 -1
- package/dist/tui-build-map.json +1 -1
- package/dist/tui-ga-build-map.json +1 -1
- package/dist/types/src/common-auth-embedded/routing-accessor/index.d.ts +33 -5
- package/dist/types/src/plugin/request-helpers.d.ts +10 -0
- package/dist/types/src/plugin/request-helpers.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/request-services.d.ts +8 -1
- package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/common-auth-embedded/fs/refresh-file-lock.js +13 -9
- package/src/common-auth-embedded/routing-accessor/index.d.ts +33 -5
- package/src/common-auth-embedded/routing-accessor/index.js +49 -7
- package/src/common-auth-embedded/source-output.json +15 -15
package/dist/server.js
CHANGED
|
@@ -12840,15 +12840,438 @@ var init_lock_record = __esm({
|
|
|
12840
12840
|
}
|
|
12841
12841
|
});
|
|
12842
12842
|
|
|
12843
|
+
// ../core/dist/common-auth-embedded/logger/capture-sink.js
|
|
12844
|
+
function createCaptureSink() {
|
|
12845
|
+
const records = [];
|
|
12846
|
+
const sink = (record5) => {
|
|
12847
|
+
records.push(record5);
|
|
12848
|
+
};
|
|
12849
|
+
return {
|
|
12850
|
+
records,
|
|
12851
|
+
sink,
|
|
12852
|
+
clear: () => {
|
|
12853
|
+
records.length = 0;
|
|
12854
|
+
}
|
|
12855
|
+
};
|
|
12856
|
+
}
|
|
12857
|
+
var init_capture_sink = __esm({
|
|
12858
|
+
"../core/dist/common-auth-embedded/logger/capture-sink.js"() {
|
|
12859
|
+
"use strict";
|
|
12860
|
+
}
|
|
12861
|
+
});
|
|
12862
|
+
|
|
12863
|
+
// ../core/dist/common-auth-embedded/logger/redact.js
|
|
12864
|
+
function isError(value) {
|
|
12865
|
+
return value instanceof Error || Object.prototype.toString.call(value) === "[object Error]";
|
|
12866
|
+
}
|
|
12867
|
+
function createRedactor(options = {}) {
|
|
12868
|
+
const patterns = [TOKEN_VALUE, ...options.extraValuePatterns ?? []].map((pattern) => new RegExp(pattern.source, pattern.flags.includes("g") ? pattern.flags : `${pattern.flags}g`));
|
|
12869
|
+
function isSecretKey(key) {
|
|
12870
|
+
const normalized = key.toLowerCase().replace(/[-_]/g, "");
|
|
12871
|
+
return SECRET_KEY_EXACT.test(key) || normalized.includes("apikey") || normalized.endsWith("secret") || normalized.endsWith("password") || normalized.endsWith("token") && !normalized.endsWith("tokens") || !!options.extraSecretKeys?.(normalized);
|
|
12872
|
+
}
|
|
12873
|
+
function errorEntries(error) {
|
|
12874
|
+
const fields2 = error;
|
|
12875
|
+
const entries = [
|
|
12876
|
+
["name", error.name],
|
|
12877
|
+
["message", error.message],
|
|
12878
|
+
["stack", error.stack]
|
|
12879
|
+
];
|
|
12880
|
+
for (const key of ["code", "status", "cause"])
|
|
12881
|
+
if (fields2[key] !== void 0)
|
|
12882
|
+
entries.push([key, fields2[key]]);
|
|
12883
|
+
const listed = new Set(entries.map(([key]) => key));
|
|
12884
|
+
for (const entry of Object.entries(error))
|
|
12885
|
+
if (!listed.has(entry[0]))
|
|
12886
|
+
entries.push(entry);
|
|
12887
|
+
return entries;
|
|
12888
|
+
}
|
|
12889
|
+
function walk(value, keys, seen, errorDepth = 0) {
|
|
12890
|
+
if (typeof value === "string") {
|
|
12891
|
+
return patterns.reduce((text2, pattern) => text2.replace(pattern, MASK), value);
|
|
12892
|
+
}
|
|
12893
|
+
if (!value || typeof value !== "object")
|
|
12894
|
+
return value;
|
|
12895
|
+
if (seen.has(value))
|
|
12896
|
+
return "[Circular]";
|
|
12897
|
+
seen.add(value);
|
|
12898
|
+
try {
|
|
12899
|
+
if (Array.isArray(value))
|
|
12900
|
+
return value.map((item) => walk(item, keys, seen, errorDepth));
|
|
12901
|
+
const error = isError(value);
|
|
12902
|
+
if (error && errorDepth >= MAX_ERROR_DEPTH)
|
|
12903
|
+
return "[Truncated]";
|
|
12904
|
+
const childDepth = error ? errorDepth + 1 : errorDepth;
|
|
12905
|
+
return Object.fromEntries((error ? errorEntries(value) : Object.entries(value)).map(([key, item]) => [
|
|
12906
|
+
key,
|
|
12907
|
+
keys && isSecretKey(key) ? MASK : walk(item, keys, seen, childDepth)
|
|
12908
|
+
]));
|
|
12909
|
+
} finally {
|
|
12910
|
+
seen.delete(value);
|
|
12911
|
+
}
|
|
12912
|
+
}
|
|
12913
|
+
return {
|
|
12914
|
+
redact: (value) => walk(value, true, /* @__PURE__ */ new WeakSet()),
|
|
12915
|
+
// Schema keys describe arguments, not credentials; only their string values are scrubbed.
|
|
12916
|
+
redactStrings: (value) => walk(value, false, /* @__PURE__ */ new WeakSet())
|
|
12917
|
+
};
|
|
12918
|
+
}
|
|
12919
|
+
var SECRET_KEY_EXACT, TOKEN_VALUE, MASK, MAX_ERROR_DEPTH, defaultRedactor, redact, redactStrings;
|
|
12920
|
+
var init_redact = __esm({
|
|
12921
|
+
"../core/dist/common-auth-embedded/logger/redact.js"() {
|
|
12922
|
+
"use strict";
|
|
12923
|
+
SECRET_KEY_EXACT = /^(authorization|x-api-key|cookie|set-cookie|refresh|access|token)$/i;
|
|
12924
|
+
TOKEN_VALUE = /\b(Bearer\s+[\w.-]+|sk-[\w-]+|eyJ[\w.-]+)\b|ckh_[A-Za-z0-9_-]{20,}/g;
|
|
12925
|
+
MASK = "***REDACTED***";
|
|
12926
|
+
MAX_ERROR_DEPTH = 8;
|
|
12927
|
+
defaultRedactor = createRedactor();
|
|
12928
|
+
redact = defaultRedactor.redact;
|
|
12929
|
+
redactStrings = defaultRedactor.redactStrings;
|
|
12930
|
+
}
|
|
12931
|
+
});
|
|
12932
|
+
|
|
12933
|
+
// ../core/dist/common-auth-embedded/logger/engine.js
|
|
12934
|
+
import { appendFileSync, chmodSync, existsSync, renameSync, statSync } from "node:fs";
|
|
12935
|
+
import { open as open4 } from "node:fs/promises";
|
|
12936
|
+
import { dirname as dirname7, resolve as resolve4 } from "node:path";
|
|
12937
|
+
function chmodPrivate(path5) {
|
|
12938
|
+
try {
|
|
12939
|
+
chmodSync(path5, 384);
|
|
12940
|
+
} catch {
|
|
12941
|
+
}
|
|
12942
|
+
}
|
|
12943
|
+
function rotateIfNeeded(f) {
|
|
12944
|
+
try {
|
|
12945
|
+
if (!(existsSync(f) && statSync(f).size >= MAX_BYTES))
|
|
12946
|
+
return;
|
|
12947
|
+
for (let i = ROTATE_KEEP - 1; i >= 1; i--) {
|
|
12948
|
+
if (existsSync(`${f}.${i}`)) {
|
|
12949
|
+
const rotated2 = `${f}.${i + 1}`;
|
|
12950
|
+
renameSync(`${f}.${i}`, rotated2);
|
|
12951
|
+
chmodPrivate(rotated2);
|
|
12952
|
+
}
|
|
12953
|
+
}
|
|
12954
|
+
const rotated = `${f}.1`;
|
|
12955
|
+
renameSync(f, rotated);
|
|
12956
|
+
chmodPrivate(rotated);
|
|
12957
|
+
} catch {
|
|
12958
|
+
}
|
|
12959
|
+
}
|
|
12960
|
+
async function closeWindowsFile(sink) {
|
|
12961
|
+
const { file, handle } = sink;
|
|
12962
|
+
sink.file = void 0;
|
|
12963
|
+
sink.handle = void 0;
|
|
12964
|
+
if (file && handle)
|
|
12965
|
+
await privateOperation(file, "log-close", () => handle.close());
|
|
12966
|
+
}
|
|
12967
|
+
async function openWindowsFile(sink, file) {
|
|
12968
|
+
await ensurePrivateDirectory(dirname7(file));
|
|
12969
|
+
try {
|
|
12970
|
+
await verifyPrivate(file, "file", true);
|
|
12971
|
+
} catch (error) {
|
|
12972
|
+
if (error.code !== "ENOENT")
|
|
12973
|
+
throw error;
|
|
12974
|
+
try {
|
|
12975
|
+
await createPrivateBytes(file, "");
|
|
12976
|
+
} catch (creationError) {
|
|
12977
|
+
if (creationError.code !== "EEXIST")
|
|
12978
|
+
throw creationError;
|
|
12979
|
+
await verifyPrivate(file, "file", true);
|
|
12980
|
+
}
|
|
12981
|
+
}
|
|
12982
|
+
sink.handle = await privateOperation(file, "log-open", () => open4(file, "a"));
|
|
12983
|
+
sink.file = file;
|
|
12984
|
+
return sink.handle;
|
|
12985
|
+
}
|
|
12986
|
+
async function flushWindowsFile(sink, file, text2) {
|
|
12987
|
+
file = resolve4(file);
|
|
12988
|
+
try {
|
|
12989
|
+
if (sink.file !== file)
|
|
12990
|
+
await closeWindowsFile(sink);
|
|
12991
|
+
let handle = sink.handle ?? await openWindowsFile(sink, file);
|
|
12992
|
+
const info = await privateOperation(file, "log-stat", () => handle.stat());
|
|
12993
|
+
if (info.size >= MAX_BYTES) {
|
|
12994
|
+
await closeWindowsFile(sink);
|
|
12995
|
+
for (let i = ROTATE_KEEP - 1; i >= 0; i--) {
|
|
12996
|
+
const source = i === 0 ? file : `${file}.${i}`;
|
|
12997
|
+
const target = `${file}.${i + 1}`;
|
|
12998
|
+
try {
|
|
12999
|
+
await verifyPrivate(source, "file", true);
|
|
13000
|
+
} catch (error) {
|
|
13001
|
+
if (error.code === "ENOENT")
|
|
13002
|
+
continue;
|
|
13003
|
+
throw error;
|
|
13004
|
+
}
|
|
13005
|
+
try {
|
|
13006
|
+
await verifyPrivate(target, "file", true);
|
|
13007
|
+
} catch (error) {
|
|
13008
|
+
if (error.code !== "ENOENT")
|
|
13009
|
+
throw error;
|
|
13010
|
+
}
|
|
13011
|
+
await replaceWindowsFile(source, target);
|
|
13012
|
+
await verifyPrivate(target, "file");
|
|
13013
|
+
}
|
|
13014
|
+
handle = await openWindowsFile(sink, file);
|
|
13015
|
+
}
|
|
13016
|
+
await privateOperation(file, "log-append", () => handle.appendFile(text2, "utf8"));
|
|
13017
|
+
} catch (error) {
|
|
13018
|
+
await closeWindowsFile(sink).catch(() => {
|
|
13019
|
+
});
|
|
13020
|
+
throw error;
|
|
13021
|
+
}
|
|
13022
|
+
}
|
|
13023
|
+
function safeSerialize(data) {
|
|
13024
|
+
try {
|
|
13025
|
+
return ` ${JSON.stringify(data)}`;
|
|
13026
|
+
} catch {
|
|
13027
|
+
return " [unserializable]";
|
|
13028
|
+
}
|
|
13029
|
+
}
|
|
13030
|
+
function createEngine(options) {
|
|
13031
|
+
let logFileSource;
|
|
13032
|
+
let initLevelSource;
|
|
13033
|
+
let runtimeLevel;
|
|
13034
|
+
let redactor = createRedactor();
|
|
13035
|
+
let captureSink;
|
|
13036
|
+
let buffer = [];
|
|
13037
|
+
let timer;
|
|
13038
|
+
let orderedSink = Promise.resolve();
|
|
13039
|
+
let sinkError;
|
|
13040
|
+
const windowsFile = {};
|
|
13041
|
+
function queueWindows(operation) {
|
|
13042
|
+
const next = orderedSink.then(operation);
|
|
13043
|
+
orderedSink = next.catch((error) => {
|
|
13044
|
+
sinkError = error;
|
|
13045
|
+
});
|
|
13046
|
+
return next;
|
|
13047
|
+
}
|
|
13048
|
+
function configure(next) {
|
|
13049
|
+
if (windowsPrivateFiles && next.file !== logFileSource)
|
|
13050
|
+
void queueWindows(() => closeWindowsFile(windowsFile)).catch(() => {
|
|
13051
|
+
});
|
|
13052
|
+
logFileSource = next.file;
|
|
13053
|
+
initLevelSource = next.level;
|
|
13054
|
+
redactor = createRedactor(next);
|
|
13055
|
+
captureSink = next.captureSink;
|
|
13056
|
+
}
|
|
13057
|
+
function setLogLevel3(l) {
|
|
13058
|
+
if (l === void 0 || l in ORDER)
|
|
13059
|
+
runtimeLevel = l;
|
|
13060
|
+
}
|
|
13061
|
+
function logFilePath() {
|
|
13062
|
+
if (logFileSource === void 0)
|
|
13063
|
+
return void 0;
|
|
13064
|
+
const resolved = typeof logFileSource === "function" ? logFileSource() : logFileSource;
|
|
13065
|
+
return resolved || void 0;
|
|
13066
|
+
}
|
|
13067
|
+
function configuredLevel() {
|
|
13068
|
+
if (runtimeLevel)
|
|
13069
|
+
return runtimeLevel;
|
|
13070
|
+
const floor = typeof initLevelSource === "function" ? initLevelSource() : initLevelSource;
|
|
13071
|
+
if (floor && floor in ORDER)
|
|
13072
|
+
return floor;
|
|
13073
|
+
return "info";
|
|
13074
|
+
}
|
|
13075
|
+
function flushLogs3(close = true) {
|
|
13076
|
+
if (timer) {
|
|
13077
|
+
clearTimeout(timer);
|
|
13078
|
+
timer = void 0;
|
|
13079
|
+
}
|
|
13080
|
+
if (!buffer.length) {
|
|
13081
|
+
if (windowsPrivateFiles)
|
|
13082
|
+
return queueWindows(async () => {
|
|
13083
|
+
if (close)
|
|
13084
|
+
await closeWindowsFile(windowsFile);
|
|
13085
|
+
if (sinkError)
|
|
13086
|
+
throw sinkError;
|
|
13087
|
+
});
|
|
13088
|
+
return;
|
|
13089
|
+
}
|
|
13090
|
+
let file;
|
|
13091
|
+
try {
|
|
13092
|
+
file = logFilePath();
|
|
13093
|
+
} catch {
|
|
13094
|
+
buffer = [];
|
|
13095
|
+
if (windowsPrivateFiles && close)
|
|
13096
|
+
return queueWindows(() => closeWindowsFile(windowsFile));
|
|
13097
|
+
return;
|
|
13098
|
+
}
|
|
13099
|
+
const text2 = buffer.join("");
|
|
13100
|
+
buffer = [];
|
|
13101
|
+
if (!file) {
|
|
13102
|
+
if (windowsPrivateFiles && close)
|
|
13103
|
+
return queueWindows(() => closeWindowsFile(windowsFile));
|
|
13104
|
+
return;
|
|
13105
|
+
}
|
|
13106
|
+
if (windowsPrivateFiles) {
|
|
13107
|
+
return queueWindows(async () => {
|
|
13108
|
+
try {
|
|
13109
|
+
await flushWindowsFile(windowsFile, file, text2);
|
|
13110
|
+
} finally {
|
|
13111
|
+
if (close)
|
|
13112
|
+
await closeWindowsFile(windowsFile);
|
|
13113
|
+
}
|
|
13114
|
+
});
|
|
13115
|
+
}
|
|
13116
|
+
try {
|
|
13117
|
+
rotateIfNeeded(file);
|
|
13118
|
+
if (existsSync(file))
|
|
13119
|
+
chmodPrivate(file);
|
|
13120
|
+
appendFileSync(file, text2, { encoding: "utf8", mode: 384 });
|
|
13121
|
+
} catch {
|
|
13122
|
+
}
|
|
13123
|
+
}
|
|
13124
|
+
function schedule2() {
|
|
13125
|
+
if (!timer)
|
|
13126
|
+
timer = setTimeout(() => {
|
|
13127
|
+
timer = void 0;
|
|
13128
|
+
const flushed = flushLogs3(false);
|
|
13129
|
+
if (flushed instanceof Promise)
|
|
13130
|
+
void flushed.catch(() => {
|
|
13131
|
+
});
|
|
13132
|
+
}, 500);
|
|
13133
|
+
}
|
|
13134
|
+
function emit(channel3, level, message, data) {
|
|
13135
|
+
if (logFileSource === void 0 && captureSink === void 0)
|
|
13136
|
+
return;
|
|
13137
|
+
try {
|
|
13138
|
+
if (ORDER[level] > ORDER[configuredLevel()])
|
|
13139
|
+
return;
|
|
13140
|
+
const scrubbedMessage = redactor.redactStrings(message);
|
|
13141
|
+
let scrubbedData;
|
|
13142
|
+
try {
|
|
13143
|
+
scrubbedData = redactor.redact(data);
|
|
13144
|
+
} catch {
|
|
13145
|
+
scrubbedData = "[unserializable]";
|
|
13146
|
+
}
|
|
13147
|
+
const line = `[${(/* @__PURE__ */ new Date()).toISOString()}] ${level.toUpperCase()} [${channel3}] ${scrubbedMessage}` + (data === void 0 ? "" : safeSerialize(scrubbedData)) + "\n";
|
|
13148
|
+
try {
|
|
13149
|
+
captureSink?.({
|
|
13150
|
+
channel: channel3,
|
|
13151
|
+
level,
|
|
13152
|
+
message: scrubbedMessage,
|
|
13153
|
+
data: scrubbedData
|
|
13154
|
+
});
|
|
13155
|
+
} catch {
|
|
13156
|
+
}
|
|
13157
|
+
if (logFileSource === void 0)
|
|
13158
|
+
return;
|
|
13159
|
+
buffer.push(line);
|
|
13160
|
+
if (buffer.length >= 50) {
|
|
13161
|
+
const flushed = flushLogs3(false);
|
|
13162
|
+
if (flushed instanceof Promise)
|
|
13163
|
+
void flushed.catch(() => {
|
|
13164
|
+
});
|
|
13165
|
+
} else
|
|
13166
|
+
schedule2();
|
|
13167
|
+
} catch {
|
|
13168
|
+
}
|
|
13169
|
+
}
|
|
13170
|
+
function createLogger5(channel3) {
|
|
13171
|
+
return {
|
|
13172
|
+
error: (m, d) => emit(channel3, "error", m, d),
|
|
13173
|
+
warn: (m, d) => emit(channel3, "warn", m, d),
|
|
13174
|
+
info: (m, d) => emit(channel3, "info", m, d),
|
|
13175
|
+
debug: (m, d) => emit(channel3, "debug", m, d),
|
|
13176
|
+
trace: (m, d) => emit(channel3, "trace", m, d)
|
|
13177
|
+
};
|
|
13178
|
+
}
|
|
13179
|
+
function reset() {
|
|
13180
|
+
if (windowsPrivateFiles)
|
|
13181
|
+
void queueWindows(() => closeWindowsFile(windowsFile)).catch(() => {
|
|
13182
|
+
});
|
|
13183
|
+
sinkError = void 0;
|
|
13184
|
+
buffer = [];
|
|
13185
|
+
if (timer) {
|
|
13186
|
+
clearTimeout(timer);
|
|
13187
|
+
timer = void 0;
|
|
13188
|
+
}
|
|
13189
|
+
logFileSource = void 0;
|
|
13190
|
+
initLevelSource = void 0;
|
|
13191
|
+
runtimeLevel = void 0;
|
|
13192
|
+
redactor = createRedactor();
|
|
13193
|
+
captureSink = void 0;
|
|
13194
|
+
}
|
|
13195
|
+
if (options)
|
|
13196
|
+
configure(options);
|
|
13197
|
+
return { configure, createLogger: createLogger5, setLogLevel: setLogLevel3, flushLogs: flushLogs3, reset };
|
|
13198
|
+
}
|
|
13199
|
+
function createLoggerInstance(options) {
|
|
13200
|
+
const { configure, createLogger: createLogger5, setLogLevel: setLogLevel3, flushLogs: flushLogs3 } = createEngine(options);
|
|
13201
|
+
return { configure, createLogger: createLogger5, setLogLevel: setLogLevel3, flushLogs: flushLogs3 };
|
|
13202
|
+
}
|
|
13203
|
+
function initLogger(options) {
|
|
13204
|
+
defaultEngine.configure(options);
|
|
13205
|
+
const { configure, createLogger: createLogger5, setLogLevel: setLogLevel3, flushLogs: flushLogs3 } = defaultEngine;
|
|
13206
|
+
return { configure, createLogger: createLogger5, setLogLevel: setLogLevel3, flushLogs: flushLogs3 };
|
|
13207
|
+
}
|
|
13208
|
+
function setLogLevel(l) {
|
|
13209
|
+
defaultEngine.setLogLevel(l);
|
|
13210
|
+
}
|
|
13211
|
+
function flushLogs() {
|
|
13212
|
+
return defaultEngine.flushLogs();
|
|
13213
|
+
}
|
|
13214
|
+
function createLogger2(channel3) {
|
|
13215
|
+
return defaultEngine.createLogger(channel3);
|
|
13216
|
+
}
|
|
13217
|
+
async function flushForTest() {
|
|
13218
|
+
return defaultEngine.flushLogs();
|
|
13219
|
+
}
|
|
13220
|
+
function resetLoggerForTest() {
|
|
13221
|
+
defaultEngine.reset();
|
|
13222
|
+
}
|
|
13223
|
+
var ORDER, MAX_BYTES, ROTATE_KEEP, defaultEngine;
|
|
13224
|
+
var init_engine = __esm({
|
|
13225
|
+
"../core/dist/common-auth-embedded/logger/engine.js"() {
|
|
13226
|
+
"use strict";
|
|
13227
|
+
init_private_files();
|
|
13228
|
+
init_redact();
|
|
13229
|
+
ORDER = {
|
|
13230
|
+
error: 0,
|
|
13231
|
+
warn: 1,
|
|
13232
|
+
info: 2,
|
|
13233
|
+
debug: 3,
|
|
13234
|
+
trace: 4
|
|
13235
|
+
};
|
|
13236
|
+
MAX_BYTES = 5 * 1024 * 1024;
|
|
13237
|
+
ROTATE_KEEP = 3;
|
|
13238
|
+
defaultEngine = createEngine();
|
|
13239
|
+
}
|
|
13240
|
+
});
|
|
13241
|
+
|
|
13242
|
+
// ../core/dist/common-auth-embedded/logger/index.js
|
|
13243
|
+
var logger_exports = {};
|
|
13244
|
+
__export(logger_exports, {
|
|
13245
|
+
createCaptureSink: () => createCaptureSink,
|
|
13246
|
+
createLogger: () => createLogger2,
|
|
13247
|
+
createLoggerInstance: () => createLoggerInstance,
|
|
13248
|
+
createRedactor: () => createRedactor,
|
|
13249
|
+
flushForTest: () => flushForTest,
|
|
13250
|
+
flushLogs: () => flushLogs,
|
|
13251
|
+
initLogger: () => initLogger,
|
|
13252
|
+
redact: () => redact,
|
|
13253
|
+
redactStrings: () => redactStrings,
|
|
13254
|
+
resetLoggerForTest: () => resetLoggerForTest,
|
|
13255
|
+
setLogLevel: () => setLogLevel
|
|
13256
|
+
});
|
|
13257
|
+
var init_logger2 = __esm({
|
|
13258
|
+
"../core/dist/common-auth-embedded/logger/index.js"() {
|
|
13259
|
+
"use strict";
|
|
13260
|
+
init_capture_sink();
|
|
13261
|
+
init_engine();
|
|
13262
|
+
init_redact();
|
|
13263
|
+
}
|
|
13264
|
+
});
|
|
13265
|
+
|
|
12843
13266
|
// ../core/dist/common-auth-embedded/fs/refresh-file-lock.js
|
|
12844
13267
|
import { randomUUID as randomUUID9 } from "node:crypto";
|
|
12845
|
-
import { link as link2, lstat as lstat3, mkdir as mkdir7, open as
|
|
12846
|
-
import { basename as basename3, dirname as
|
|
13268
|
+
import { link as link2, lstat as lstat3, mkdir as mkdir7, open as open5, readdir, readFile as readFile5, rename as rename6, rm as rm4, stat as stat3, unlink as unlink6 } from "node:fs/promises";
|
|
13269
|
+
import { basename as basename3, dirname as dirname8, join as join5 } from "node:path";
|
|
12847
13270
|
async function createExclusiveText(path5, text2) {
|
|
12848
13271
|
const tempPath = `${path5}.${randomUUID9()}.tmp`;
|
|
12849
13272
|
let handle;
|
|
12850
13273
|
try {
|
|
12851
|
-
handle = await
|
|
13274
|
+
handle = await open5(tempPath, "wx", 384);
|
|
12852
13275
|
try {
|
|
12853
13276
|
if (leaseCreationTestHooks?.beforeWrite)
|
|
12854
13277
|
await leaseCreationTestHooks.beforeWrite(tempPath);
|
|
@@ -12873,7 +13296,7 @@ async function createExclusiveText(path5, text2) {
|
|
|
12873
13296
|
}
|
|
12874
13297
|
}
|
|
12875
13298
|
async function writeExclusiveText(path5, text2) {
|
|
12876
|
-
const handle = await
|
|
13299
|
+
const handle = await open5(path5, "wx", 384);
|
|
12877
13300
|
let createdStat;
|
|
12878
13301
|
try {
|
|
12879
13302
|
createdStat = await handle.stat();
|
|
@@ -12914,7 +13337,7 @@ async function readStagedOwner(path5) {
|
|
|
12914
13337
|
return void 0;
|
|
12915
13338
|
if (before.size > STAGING_SWEEP_MAX_BYTES)
|
|
12916
13339
|
return void 0;
|
|
12917
|
-
const handle = await
|
|
13340
|
+
const handle = await open5(path5, "r");
|
|
12918
13341
|
let text2;
|
|
12919
13342
|
try {
|
|
12920
13343
|
if (!sameStagingFile(before, await handle.stat()))
|
|
@@ -12942,7 +13365,7 @@ async function readStagedOwner(path5) {
|
|
|
12942
13365
|
return { identity: before, expiresAt };
|
|
12943
13366
|
}
|
|
12944
13367
|
async function sweepAbandonedStaging(lockPath, ttlMs, now) {
|
|
12945
|
-
const directory =
|
|
13368
|
+
const directory = dirname8(lockPath);
|
|
12946
13369
|
const lockName = basename3(lockPath);
|
|
12947
13370
|
const hooks = stagingSweepTestHooks;
|
|
12948
13371
|
const names = await (hooks?.readdir ?? readdir)(directory);
|
|
@@ -13084,7 +13507,7 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
13084
13507
|
let handle;
|
|
13085
13508
|
let created = false;
|
|
13086
13509
|
try {
|
|
13087
|
-
handle = await
|
|
13510
|
+
handle = await open5(tempPath, "wx", 384);
|
|
13088
13511
|
created = true;
|
|
13089
13512
|
await handle.writeFile(`${JSON.stringify({ ownerId, expiresAt: now() + options.ttlMs })}
|
|
13090
13513
|
`, "utf8");
|
|
@@ -13138,7 +13561,7 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
13138
13561
|
}
|
|
13139
13562
|
async function tryAcquire() {
|
|
13140
13563
|
if (windowsPrivateFiles)
|
|
13141
|
-
await ensurePrivateDirectory(
|
|
13564
|
+
await ensurePrivateDirectory(dirname8(lockPath));
|
|
13142
13565
|
try {
|
|
13143
13566
|
await createLease();
|
|
13144
13567
|
return true;
|
|
@@ -13148,9 +13571,9 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
13148
13571
|
return false;
|
|
13149
13572
|
if (code2 === "ENOENT") {
|
|
13150
13573
|
if (windowsPrivateFiles)
|
|
13151
|
-
await ensurePrivateDirectory(
|
|
13574
|
+
await ensurePrivateDirectory(dirname8(lockPath));
|
|
13152
13575
|
else
|
|
13153
|
-
await mkdir7(
|
|
13576
|
+
await mkdir7(dirname8(lockPath), { recursive: true });
|
|
13154
13577
|
try {
|
|
13155
13578
|
await createLease();
|
|
13156
13579
|
return true;
|
|
@@ -13731,17 +14154,15 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
13731
14154
|
removalConfirmed = true;
|
|
13732
14155
|
}, deadline);
|
|
13733
14156
|
changingRecordError = void 0;
|
|
13734
|
-
if (markerAcquired) {
|
|
13735
|
-
|
|
13736
|
-
throw new PrivateFileError(lockPath, "release-not-confirmed", {
|
|
13737
|
-
code: "EIO"
|
|
13738
|
-
});
|
|
13739
|
-
releaseConfirmed = removalConfirmed;
|
|
14157
|
+
if (markerAcquired && removalConfirmed) {
|
|
14158
|
+
releaseConfirmed = true;
|
|
13740
14159
|
return;
|
|
13741
14160
|
}
|
|
13742
|
-
if (
|
|
13743
|
-
|
|
13744
|
-
|
|
14161
|
+
if (!markerAcquired) {
|
|
14162
|
+
if (signal?.aborted)
|
|
14163
|
+
return;
|
|
14164
|
+
await recoverStaleEvictionMarker(deadline);
|
|
14165
|
+
}
|
|
13745
14166
|
} catch (error) {
|
|
13746
14167
|
const changingRecord = windowsPrivateFiles && (isChangingLockCreate(error) || isWindowsAccessDeniedRead(error, [
|
|
13747
14168
|
lockPath,
|
|
@@ -13771,6 +14192,9 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
13771
14192
|
throw changingRecordError ?? removalError ?? new PrivateFileError(lockPath, "release-not-confirmed", {
|
|
13772
14193
|
code: "ETIMEDOUT"
|
|
13773
14194
|
});
|
|
14195
|
+
createLogger2("fs").warn("File lock release deadline expired", {
|
|
14196
|
+
lockPath
|
|
14197
|
+
});
|
|
13774
14198
|
}
|
|
13775
14199
|
};
|
|
13776
14200
|
}
|
|
@@ -13778,6 +14202,7 @@ var leaseCreationTestHooks, STAGING_UUID, STAGING_SWEEP_MIN_AGE_MS, STAGING_SWEE
|
|
|
13778
14202
|
var init_refresh_file_lock = __esm({
|
|
13779
14203
|
"../core/dist/common-auth-embedded/fs/refresh-file-lock.js"() {
|
|
13780
14204
|
"use strict";
|
|
14205
|
+
init_logger2();
|
|
13781
14206
|
init_lock_record();
|
|
13782
14207
|
init_private_files();
|
|
13783
14208
|
init_with_lock();
|
|
@@ -13794,12 +14219,12 @@ var init_refresh_file_lock = __esm({
|
|
|
13794
14219
|
});
|
|
13795
14220
|
|
|
13796
14221
|
// ../core/dist/common-auth-embedded/fs/with-lock.js
|
|
13797
|
-
import { join as join6, resolve as
|
|
14222
|
+
import { join as join6, resolve as resolve5 } from "node:path";
|
|
13798
14223
|
function lockPathFor(target, name) {
|
|
13799
14224
|
return `${target}.${name}.lock`;
|
|
13800
14225
|
}
|
|
13801
14226
|
function isChangingLockRecord(error, target, name) {
|
|
13802
|
-
const path5 =
|
|
14227
|
+
const path5 = resolve5(lockPathFor(target, name));
|
|
13803
14228
|
const paths = [path5, join6(path5, "owner.json")];
|
|
13804
14229
|
return (isWindowsSharingViolation(error) || isWindowsAccessDeniedRead(error, paths)) && (error.stage === "read" || error.stage === "verify") && paths.includes(error.path) || windowsPrivateFiles && (isWindowsAccessDeniedCreate(error, [path5], "create") || isWindowsAccessDeniedCreate(error, [`${path5}.evicting`], "directory-create"));
|
|
13805
14230
|
}
|
|
@@ -16734,429 +17159,6 @@ var init_pull = __esm({
|
|
|
16734
17159
|
}
|
|
16735
17160
|
});
|
|
16736
17161
|
|
|
16737
|
-
// ../core/dist/common-auth-embedded/logger/capture-sink.js
|
|
16738
|
-
function createCaptureSink() {
|
|
16739
|
-
const records = [];
|
|
16740
|
-
const sink = (record5) => {
|
|
16741
|
-
records.push(record5);
|
|
16742
|
-
};
|
|
16743
|
-
return {
|
|
16744
|
-
records,
|
|
16745
|
-
sink,
|
|
16746
|
-
clear: () => {
|
|
16747
|
-
records.length = 0;
|
|
16748
|
-
}
|
|
16749
|
-
};
|
|
16750
|
-
}
|
|
16751
|
-
var init_capture_sink = __esm({
|
|
16752
|
-
"../core/dist/common-auth-embedded/logger/capture-sink.js"() {
|
|
16753
|
-
"use strict";
|
|
16754
|
-
}
|
|
16755
|
-
});
|
|
16756
|
-
|
|
16757
|
-
// ../core/dist/common-auth-embedded/logger/redact.js
|
|
16758
|
-
function isError(value) {
|
|
16759
|
-
return value instanceof Error || Object.prototype.toString.call(value) === "[object Error]";
|
|
16760
|
-
}
|
|
16761
|
-
function createRedactor(options = {}) {
|
|
16762
|
-
const patterns = [TOKEN_VALUE, ...options.extraValuePatterns ?? []].map((pattern) => new RegExp(pattern.source, pattern.flags.includes("g") ? pattern.flags : `${pattern.flags}g`));
|
|
16763
|
-
function isSecretKey(key) {
|
|
16764
|
-
const normalized = key.toLowerCase().replace(/[-_]/g, "");
|
|
16765
|
-
return SECRET_KEY_EXACT.test(key) || normalized.includes("apikey") || normalized.endsWith("secret") || normalized.endsWith("password") || normalized.endsWith("token") && !normalized.endsWith("tokens") || !!options.extraSecretKeys?.(normalized);
|
|
16766
|
-
}
|
|
16767
|
-
function errorEntries(error) {
|
|
16768
|
-
const fields2 = error;
|
|
16769
|
-
const entries = [
|
|
16770
|
-
["name", error.name],
|
|
16771
|
-
["message", error.message],
|
|
16772
|
-
["stack", error.stack]
|
|
16773
|
-
];
|
|
16774
|
-
for (const key of ["code", "status", "cause"])
|
|
16775
|
-
if (fields2[key] !== void 0)
|
|
16776
|
-
entries.push([key, fields2[key]]);
|
|
16777
|
-
const listed = new Set(entries.map(([key]) => key));
|
|
16778
|
-
for (const entry of Object.entries(error))
|
|
16779
|
-
if (!listed.has(entry[0]))
|
|
16780
|
-
entries.push(entry);
|
|
16781
|
-
return entries;
|
|
16782
|
-
}
|
|
16783
|
-
function walk(value, keys, seen, errorDepth = 0) {
|
|
16784
|
-
if (typeof value === "string") {
|
|
16785
|
-
return patterns.reduce((text2, pattern) => text2.replace(pattern, MASK), value);
|
|
16786
|
-
}
|
|
16787
|
-
if (!value || typeof value !== "object")
|
|
16788
|
-
return value;
|
|
16789
|
-
if (seen.has(value))
|
|
16790
|
-
return "[Circular]";
|
|
16791
|
-
seen.add(value);
|
|
16792
|
-
try {
|
|
16793
|
-
if (Array.isArray(value))
|
|
16794
|
-
return value.map((item) => walk(item, keys, seen, errorDepth));
|
|
16795
|
-
const error = isError(value);
|
|
16796
|
-
if (error && errorDepth >= MAX_ERROR_DEPTH)
|
|
16797
|
-
return "[Truncated]";
|
|
16798
|
-
const childDepth = error ? errorDepth + 1 : errorDepth;
|
|
16799
|
-
return Object.fromEntries((error ? errorEntries(value) : Object.entries(value)).map(([key, item]) => [
|
|
16800
|
-
key,
|
|
16801
|
-
keys && isSecretKey(key) ? MASK : walk(item, keys, seen, childDepth)
|
|
16802
|
-
]));
|
|
16803
|
-
} finally {
|
|
16804
|
-
seen.delete(value);
|
|
16805
|
-
}
|
|
16806
|
-
}
|
|
16807
|
-
return {
|
|
16808
|
-
redact: (value) => walk(value, true, /* @__PURE__ */ new WeakSet()),
|
|
16809
|
-
// Schema keys describe arguments, not credentials; only their string values are scrubbed.
|
|
16810
|
-
redactStrings: (value) => walk(value, false, /* @__PURE__ */ new WeakSet())
|
|
16811
|
-
};
|
|
16812
|
-
}
|
|
16813
|
-
var SECRET_KEY_EXACT, TOKEN_VALUE, MASK, MAX_ERROR_DEPTH, defaultRedactor, redact, redactStrings;
|
|
16814
|
-
var init_redact = __esm({
|
|
16815
|
-
"../core/dist/common-auth-embedded/logger/redact.js"() {
|
|
16816
|
-
"use strict";
|
|
16817
|
-
SECRET_KEY_EXACT = /^(authorization|x-api-key|cookie|set-cookie|refresh|access|token)$/i;
|
|
16818
|
-
TOKEN_VALUE = /\b(Bearer\s+[\w.-]+|sk-[\w-]+|eyJ[\w.-]+)\b|ckh_[A-Za-z0-9_-]{20,}/g;
|
|
16819
|
-
MASK = "***REDACTED***";
|
|
16820
|
-
MAX_ERROR_DEPTH = 8;
|
|
16821
|
-
defaultRedactor = createRedactor();
|
|
16822
|
-
redact = defaultRedactor.redact;
|
|
16823
|
-
redactStrings = defaultRedactor.redactStrings;
|
|
16824
|
-
}
|
|
16825
|
-
});
|
|
16826
|
-
|
|
16827
|
-
// ../core/dist/common-auth-embedded/logger/engine.js
|
|
16828
|
-
import { appendFileSync, chmodSync, existsSync, renameSync, statSync } from "node:fs";
|
|
16829
|
-
import { open as open5 } from "node:fs/promises";
|
|
16830
|
-
import { dirname as dirname8, resolve as resolve5 } from "node:path";
|
|
16831
|
-
function chmodPrivate(path5) {
|
|
16832
|
-
try {
|
|
16833
|
-
chmodSync(path5, 384);
|
|
16834
|
-
} catch {
|
|
16835
|
-
}
|
|
16836
|
-
}
|
|
16837
|
-
function rotateIfNeeded(f) {
|
|
16838
|
-
try {
|
|
16839
|
-
if (!(existsSync(f) && statSync(f).size >= MAX_BYTES))
|
|
16840
|
-
return;
|
|
16841
|
-
for (let i = ROTATE_KEEP - 1; i >= 1; i--) {
|
|
16842
|
-
if (existsSync(`${f}.${i}`)) {
|
|
16843
|
-
const rotated2 = `${f}.${i + 1}`;
|
|
16844
|
-
renameSync(`${f}.${i}`, rotated2);
|
|
16845
|
-
chmodPrivate(rotated2);
|
|
16846
|
-
}
|
|
16847
|
-
}
|
|
16848
|
-
const rotated = `${f}.1`;
|
|
16849
|
-
renameSync(f, rotated);
|
|
16850
|
-
chmodPrivate(rotated);
|
|
16851
|
-
} catch {
|
|
16852
|
-
}
|
|
16853
|
-
}
|
|
16854
|
-
async function closeWindowsFile(sink) {
|
|
16855
|
-
const { file, handle } = sink;
|
|
16856
|
-
sink.file = void 0;
|
|
16857
|
-
sink.handle = void 0;
|
|
16858
|
-
if (file && handle)
|
|
16859
|
-
await privateOperation(file, "log-close", () => handle.close());
|
|
16860
|
-
}
|
|
16861
|
-
async function openWindowsFile(sink, file) {
|
|
16862
|
-
await ensurePrivateDirectory(dirname8(file));
|
|
16863
|
-
try {
|
|
16864
|
-
await verifyPrivate(file, "file", true);
|
|
16865
|
-
} catch (error) {
|
|
16866
|
-
if (error.code !== "ENOENT")
|
|
16867
|
-
throw error;
|
|
16868
|
-
try {
|
|
16869
|
-
await createPrivateBytes(file, "");
|
|
16870
|
-
} catch (creationError) {
|
|
16871
|
-
if (creationError.code !== "EEXIST")
|
|
16872
|
-
throw creationError;
|
|
16873
|
-
await verifyPrivate(file, "file", true);
|
|
16874
|
-
}
|
|
16875
|
-
}
|
|
16876
|
-
sink.handle = await privateOperation(file, "log-open", () => open5(file, "a"));
|
|
16877
|
-
sink.file = file;
|
|
16878
|
-
return sink.handle;
|
|
16879
|
-
}
|
|
16880
|
-
async function flushWindowsFile(sink, file, text2) {
|
|
16881
|
-
file = resolve5(file);
|
|
16882
|
-
try {
|
|
16883
|
-
if (sink.file !== file)
|
|
16884
|
-
await closeWindowsFile(sink);
|
|
16885
|
-
let handle = sink.handle ?? await openWindowsFile(sink, file);
|
|
16886
|
-
const info = await privateOperation(file, "log-stat", () => handle.stat());
|
|
16887
|
-
if (info.size >= MAX_BYTES) {
|
|
16888
|
-
await closeWindowsFile(sink);
|
|
16889
|
-
for (let i = ROTATE_KEEP - 1; i >= 0; i--) {
|
|
16890
|
-
const source = i === 0 ? file : `${file}.${i}`;
|
|
16891
|
-
const target = `${file}.${i + 1}`;
|
|
16892
|
-
try {
|
|
16893
|
-
await verifyPrivate(source, "file", true);
|
|
16894
|
-
} catch (error) {
|
|
16895
|
-
if (error.code === "ENOENT")
|
|
16896
|
-
continue;
|
|
16897
|
-
throw error;
|
|
16898
|
-
}
|
|
16899
|
-
try {
|
|
16900
|
-
await verifyPrivate(target, "file", true);
|
|
16901
|
-
} catch (error) {
|
|
16902
|
-
if (error.code !== "ENOENT")
|
|
16903
|
-
throw error;
|
|
16904
|
-
}
|
|
16905
|
-
await replaceWindowsFile(source, target);
|
|
16906
|
-
await verifyPrivate(target, "file");
|
|
16907
|
-
}
|
|
16908
|
-
handle = await openWindowsFile(sink, file);
|
|
16909
|
-
}
|
|
16910
|
-
await privateOperation(file, "log-append", () => handle.appendFile(text2, "utf8"));
|
|
16911
|
-
} catch (error) {
|
|
16912
|
-
await closeWindowsFile(sink).catch(() => {
|
|
16913
|
-
});
|
|
16914
|
-
throw error;
|
|
16915
|
-
}
|
|
16916
|
-
}
|
|
16917
|
-
function safeSerialize(data) {
|
|
16918
|
-
try {
|
|
16919
|
-
return ` ${JSON.stringify(data)}`;
|
|
16920
|
-
} catch {
|
|
16921
|
-
return " [unserializable]";
|
|
16922
|
-
}
|
|
16923
|
-
}
|
|
16924
|
-
function createEngine(options) {
|
|
16925
|
-
let logFileSource;
|
|
16926
|
-
let initLevelSource;
|
|
16927
|
-
let runtimeLevel;
|
|
16928
|
-
let redactor = createRedactor();
|
|
16929
|
-
let captureSink;
|
|
16930
|
-
let buffer = [];
|
|
16931
|
-
let timer;
|
|
16932
|
-
let orderedSink = Promise.resolve();
|
|
16933
|
-
let sinkError;
|
|
16934
|
-
const windowsFile = {};
|
|
16935
|
-
function queueWindows(operation) {
|
|
16936
|
-
const next = orderedSink.then(operation);
|
|
16937
|
-
orderedSink = next.catch((error) => {
|
|
16938
|
-
sinkError = error;
|
|
16939
|
-
});
|
|
16940
|
-
return next;
|
|
16941
|
-
}
|
|
16942
|
-
function configure(next) {
|
|
16943
|
-
if (windowsPrivateFiles && next.file !== logFileSource)
|
|
16944
|
-
void queueWindows(() => closeWindowsFile(windowsFile)).catch(() => {
|
|
16945
|
-
});
|
|
16946
|
-
logFileSource = next.file;
|
|
16947
|
-
initLevelSource = next.level;
|
|
16948
|
-
redactor = createRedactor(next);
|
|
16949
|
-
captureSink = next.captureSink;
|
|
16950
|
-
}
|
|
16951
|
-
function setLogLevel3(l) {
|
|
16952
|
-
if (l === void 0 || l in ORDER)
|
|
16953
|
-
runtimeLevel = l;
|
|
16954
|
-
}
|
|
16955
|
-
function logFilePath() {
|
|
16956
|
-
if (logFileSource === void 0)
|
|
16957
|
-
return void 0;
|
|
16958
|
-
const resolved = typeof logFileSource === "function" ? logFileSource() : logFileSource;
|
|
16959
|
-
return resolved || void 0;
|
|
16960
|
-
}
|
|
16961
|
-
function configuredLevel() {
|
|
16962
|
-
if (runtimeLevel)
|
|
16963
|
-
return runtimeLevel;
|
|
16964
|
-
const floor = typeof initLevelSource === "function" ? initLevelSource() : initLevelSource;
|
|
16965
|
-
if (floor && floor in ORDER)
|
|
16966
|
-
return floor;
|
|
16967
|
-
return "info";
|
|
16968
|
-
}
|
|
16969
|
-
function flushLogs3(close = true) {
|
|
16970
|
-
if (timer) {
|
|
16971
|
-
clearTimeout(timer);
|
|
16972
|
-
timer = void 0;
|
|
16973
|
-
}
|
|
16974
|
-
if (!buffer.length) {
|
|
16975
|
-
if (windowsPrivateFiles)
|
|
16976
|
-
return queueWindows(async () => {
|
|
16977
|
-
if (close)
|
|
16978
|
-
await closeWindowsFile(windowsFile);
|
|
16979
|
-
if (sinkError)
|
|
16980
|
-
throw sinkError;
|
|
16981
|
-
});
|
|
16982
|
-
return;
|
|
16983
|
-
}
|
|
16984
|
-
let file;
|
|
16985
|
-
try {
|
|
16986
|
-
file = logFilePath();
|
|
16987
|
-
} catch {
|
|
16988
|
-
buffer = [];
|
|
16989
|
-
if (windowsPrivateFiles && close)
|
|
16990
|
-
return queueWindows(() => closeWindowsFile(windowsFile));
|
|
16991
|
-
return;
|
|
16992
|
-
}
|
|
16993
|
-
const text2 = buffer.join("");
|
|
16994
|
-
buffer = [];
|
|
16995
|
-
if (!file) {
|
|
16996
|
-
if (windowsPrivateFiles && close)
|
|
16997
|
-
return queueWindows(() => closeWindowsFile(windowsFile));
|
|
16998
|
-
return;
|
|
16999
|
-
}
|
|
17000
|
-
if (windowsPrivateFiles) {
|
|
17001
|
-
return queueWindows(async () => {
|
|
17002
|
-
try {
|
|
17003
|
-
await flushWindowsFile(windowsFile, file, text2);
|
|
17004
|
-
} finally {
|
|
17005
|
-
if (close)
|
|
17006
|
-
await closeWindowsFile(windowsFile);
|
|
17007
|
-
}
|
|
17008
|
-
});
|
|
17009
|
-
}
|
|
17010
|
-
try {
|
|
17011
|
-
rotateIfNeeded(file);
|
|
17012
|
-
if (existsSync(file))
|
|
17013
|
-
chmodPrivate(file);
|
|
17014
|
-
appendFileSync(file, text2, { encoding: "utf8", mode: 384 });
|
|
17015
|
-
} catch {
|
|
17016
|
-
}
|
|
17017
|
-
}
|
|
17018
|
-
function schedule2() {
|
|
17019
|
-
if (!timer)
|
|
17020
|
-
timer = setTimeout(() => {
|
|
17021
|
-
timer = void 0;
|
|
17022
|
-
const flushed = flushLogs3(false);
|
|
17023
|
-
if (flushed instanceof Promise)
|
|
17024
|
-
void flushed.catch(() => {
|
|
17025
|
-
});
|
|
17026
|
-
}, 500);
|
|
17027
|
-
}
|
|
17028
|
-
function emit(channel3, level, message, data) {
|
|
17029
|
-
if (logFileSource === void 0 && captureSink === void 0)
|
|
17030
|
-
return;
|
|
17031
|
-
try {
|
|
17032
|
-
if (ORDER[level] > ORDER[configuredLevel()])
|
|
17033
|
-
return;
|
|
17034
|
-
const scrubbedMessage = redactor.redactStrings(message);
|
|
17035
|
-
let scrubbedData;
|
|
17036
|
-
try {
|
|
17037
|
-
scrubbedData = redactor.redact(data);
|
|
17038
|
-
} catch {
|
|
17039
|
-
scrubbedData = "[unserializable]";
|
|
17040
|
-
}
|
|
17041
|
-
const line = `[${(/* @__PURE__ */ new Date()).toISOString()}] ${level.toUpperCase()} [${channel3}] ${scrubbedMessage}` + (data === void 0 ? "" : safeSerialize(scrubbedData)) + "\n";
|
|
17042
|
-
try {
|
|
17043
|
-
captureSink?.({
|
|
17044
|
-
channel: channel3,
|
|
17045
|
-
level,
|
|
17046
|
-
message: scrubbedMessage,
|
|
17047
|
-
data: scrubbedData
|
|
17048
|
-
});
|
|
17049
|
-
} catch {
|
|
17050
|
-
}
|
|
17051
|
-
if (logFileSource === void 0)
|
|
17052
|
-
return;
|
|
17053
|
-
buffer.push(line);
|
|
17054
|
-
if (buffer.length >= 50) {
|
|
17055
|
-
const flushed = flushLogs3(false);
|
|
17056
|
-
if (flushed instanceof Promise)
|
|
17057
|
-
void flushed.catch(() => {
|
|
17058
|
-
});
|
|
17059
|
-
} else
|
|
17060
|
-
schedule2();
|
|
17061
|
-
} catch {
|
|
17062
|
-
}
|
|
17063
|
-
}
|
|
17064
|
-
function createLogger5(channel3) {
|
|
17065
|
-
return {
|
|
17066
|
-
error: (m, d) => emit(channel3, "error", m, d),
|
|
17067
|
-
warn: (m, d) => emit(channel3, "warn", m, d),
|
|
17068
|
-
info: (m, d) => emit(channel3, "info", m, d),
|
|
17069
|
-
debug: (m, d) => emit(channel3, "debug", m, d),
|
|
17070
|
-
trace: (m, d) => emit(channel3, "trace", m, d)
|
|
17071
|
-
};
|
|
17072
|
-
}
|
|
17073
|
-
function reset() {
|
|
17074
|
-
if (windowsPrivateFiles)
|
|
17075
|
-
void queueWindows(() => closeWindowsFile(windowsFile)).catch(() => {
|
|
17076
|
-
});
|
|
17077
|
-
sinkError = void 0;
|
|
17078
|
-
buffer = [];
|
|
17079
|
-
if (timer) {
|
|
17080
|
-
clearTimeout(timer);
|
|
17081
|
-
timer = void 0;
|
|
17082
|
-
}
|
|
17083
|
-
logFileSource = void 0;
|
|
17084
|
-
initLevelSource = void 0;
|
|
17085
|
-
runtimeLevel = void 0;
|
|
17086
|
-
redactor = createRedactor();
|
|
17087
|
-
captureSink = void 0;
|
|
17088
|
-
}
|
|
17089
|
-
if (options)
|
|
17090
|
-
configure(options);
|
|
17091
|
-
return { configure, createLogger: createLogger5, setLogLevel: setLogLevel3, flushLogs: flushLogs3, reset };
|
|
17092
|
-
}
|
|
17093
|
-
function createLoggerInstance(options) {
|
|
17094
|
-
const { configure, createLogger: createLogger5, setLogLevel: setLogLevel3, flushLogs: flushLogs3 } = createEngine(options);
|
|
17095
|
-
return { configure, createLogger: createLogger5, setLogLevel: setLogLevel3, flushLogs: flushLogs3 };
|
|
17096
|
-
}
|
|
17097
|
-
function initLogger(options) {
|
|
17098
|
-
defaultEngine.configure(options);
|
|
17099
|
-
const { configure, createLogger: createLogger5, setLogLevel: setLogLevel3, flushLogs: flushLogs3 } = defaultEngine;
|
|
17100
|
-
return { configure, createLogger: createLogger5, setLogLevel: setLogLevel3, flushLogs: flushLogs3 };
|
|
17101
|
-
}
|
|
17102
|
-
function setLogLevel(l) {
|
|
17103
|
-
defaultEngine.setLogLevel(l);
|
|
17104
|
-
}
|
|
17105
|
-
function flushLogs() {
|
|
17106
|
-
return defaultEngine.flushLogs();
|
|
17107
|
-
}
|
|
17108
|
-
function createLogger2(channel3) {
|
|
17109
|
-
return defaultEngine.createLogger(channel3);
|
|
17110
|
-
}
|
|
17111
|
-
async function flushForTest() {
|
|
17112
|
-
return defaultEngine.flushLogs();
|
|
17113
|
-
}
|
|
17114
|
-
function resetLoggerForTest() {
|
|
17115
|
-
defaultEngine.reset();
|
|
17116
|
-
}
|
|
17117
|
-
var ORDER, MAX_BYTES, ROTATE_KEEP, defaultEngine;
|
|
17118
|
-
var init_engine = __esm({
|
|
17119
|
-
"../core/dist/common-auth-embedded/logger/engine.js"() {
|
|
17120
|
-
"use strict";
|
|
17121
|
-
init_private_files();
|
|
17122
|
-
init_redact();
|
|
17123
|
-
ORDER = {
|
|
17124
|
-
error: 0,
|
|
17125
|
-
warn: 1,
|
|
17126
|
-
info: 2,
|
|
17127
|
-
debug: 3,
|
|
17128
|
-
trace: 4
|
|
17129
|
-
};
|
|
17130
|
-
MAX_BYTES = 5 * 1024 * 1024;
|
|
17131
|
-
ROTATE_KEEP = 3;
|
|
17132
|
-
defaultEngine = createEngine();
|
|
17133
|
-
}
|
|
17134
|
-
});
|
|
17135
|
-
|
|
17136
|
-
// ../core/dist/common-auth-embedded/logger/index.js
|
|
17137
|
-
var logger_exports = {};
|
|
17138
|
-
__export(logger_exports, {
|
|
17139
|
-
createCaptureSink: () => createCaptureSink,
|
|
17140
|
-
createLogger: () => createLogger2,
|
|
17141
|
-
createLoggerInstance: () => createLoggerInstance,
|
|
17142
|
-
createRedactor: () => createRedactor,
|
|
17143
|
-
flushForTest: () => flushForTest,
|
|
17144
|
-
flushLogs: () => flushLogs,
|
|
17145
|
-
initLogger: () => initLogger,
|
|
17146
|
-
redact: () => redact,
|
|
17147
|
-
redactStrings: () => redactStrings,
|
|
17148
|
-
resetLoggerForTest: () => resetLoggerForTest,
|
|
17149
|
-
setLogLevel: () => setLogLevel
|
|
17150
|
-
});
|
|
17151
|
-
var init_logger2 = __esm({
|
|
17152
|
-
"../core/dist/common-auth-embedded/logger/index.js"() {
|
|
17153
|
-
"use strict";
|
|
17154
|
-
init_capture_sink();
|
|
17155
|
-
init_engine();
|
|
17156
|
-
init_redact();
|
|
17157
|
-
}
|
|
17158
|
-
});
|
|
17159
|
-
|
|
17160
17162
|
// ../core/dist/common-auth-embedded/quota/commit-interval.js
|
|
17161
17163
|
var QUOTA_COMMIT_INTERVAL_MS, quotaCommitTimer;
|
|
17162
17164
|
var init_commit_interval = __esm({
|
|
@@ -30666,6 +30668,9 @@ function createLoggerInstance2(options) {
|
|
|
30666
30668
|
const { configure, createLogger: createLogger5, setLogLevel: setLogLevel3, flushLogs: flushLogs3 } = createEngine2(options);
|
|
30667
30669
|
return { configure, createLogger: createLogger5, setLogLevel: setLogLevel3, flushLogs: flushLogs3 };
|
|
30668
30670
|
}
|
|
30671
|
+
function createLogger3(channel3) {
|
|
30672
|
+
return defaultEngine2.createLogger(channel3);
|
|
30673
|
+
}
|
|
30669
30674
|
var ORDER2, MAX_BYTES2, ROTATE_KEEP2, defaultEngine2;
|
|
30670
30675
|
var init_engine2 = __esm({
|
|
30671
30676
|
"src/common-auth-embedded/logger/engine.js"() {
|
|
@@ -45473,6 +45478,7 @@ var NATIVE_GOOGLE_ERROR_MESSAGES = {
|
|
|
45473
45478
|
soft_quota: 'Antigravity account pool is unavailable under the quota protection policy. Add accounts, wait for quota reset, or turn off soft quota protection with `"soft_quota_threshold_percent": 100` in antigravity-auth.jsonc.',
|
|
45474
45479
|
pool_unavailable: "Antigravity account pool has no account available within the configured wait limit. Add accounts with `opencode auth login` or wait for quota reset.",
|
|
45475
45480
|
model_unavailable: "The requested Antigravity model is not available to the configured accounts. Choose another model.",
|
|
45481
|
+
routing_refused: "Routing has no Antigravity account available for this request right now; try again later.",
|
|
45476
45482
|
missing_access_token: "Missing access token. Run `opencode auth login` to reauthenticate.",
|
|
45477
45483
|
empty_response: "Antigravity returned an empty response after the internal retry attempts."
|
|
45478
45484
|
};
|
|
@@ -45499,6 +45505,9 @@ function createNativeGoogleErrorResponse(options) {
|
|
|
45499
45505
|
let body = JSON.stringify({
|
|
45500
45506
|
error: { code: options.status, status, message }
|
|
45501
45507
|
});
|
|
45508
|
+
if (options.reason === "routing_refused" && options.retryAfterSeconds !== void 0 && options.retryAfterSeconds >= 0n) {
|
|
45509
|
+
headers.set("Retry-After", options.retryAfterSeconds.toString());
|
|
45510
|
+
}
|
|
45502
45511
|
if (options.status === 412 && typeof options.resetAfterMs === "number" && Number.isFinite(options.resetAfterMs) && options.resetAfterMs >= 0) {
|
|
45503
45512
|
const delaySeconds = (BigInt(Math.ceil(options.resetAfterMs)) + 999n) / 1000n;
|
|
45504
45513
|
headers.set("Retry-After", delaySeconds.toString());
|
|
@@ -48400,6 +48409,28 @@ function selectionFor(answer, candidates) {
|
|
|
48400
48409
|
}
|
|
48401
48410
|
return { candidate };
|
|
48402
48411
|
}
|
|
48412
|
+
function refusalFor(value) {
|
|
48413
|
+
if (!isObject2(value))
|
|
48414
|
+
return void 0;
|
|
48415
|
+
const code2 = value.code;
|
|
48416
|
+
if (code2 !== "account_limit_exhausted" && code2 !== "account_selection_refused" && code2 !== "account_selection_final") {
|
|
48417
|
+
return void 0;
|
|
48418
|
+
}
|
|
48419
|
+
const refused2 = { code: code2 };
|
|
48420
|
+
const routingCode = value.routing_code;
|
|
48421
|
+
if (typeof routingCode === "string" && /^[a-z0-9._-]{1,64}$/.test(routingCode)) {
|
|
48422
|
+
refused2.routingCode = routingCode;
|
|
48423
|
+
}
|
|
48424
|
+
const retryAfterSecs = value.retry_after_secs;
|
|
48425
|
+
if (typeof retryAfterSecs === "number" && Number.isFinite(retryAfterSecs) && retryAfterSecs >= 0) {
|
|
48426
|
+
refused2.retryAfterSecs = retryAfterSecs;
|
|
48427
|
+
}
|
|
48428
|
+
const resetsAtMs = value.resets_at_ms;
|
|
48429
|
+
if (typeof resetsAtMs === "number" && Number.isSafeInteger(resetsAtMs) && resetsAtMs > 0) {
|
|
48430
|
+
refused2.resetsAtMs = resetsAtMs;
|
|
48431
|
+
}
|
|
48432
|
+
return { refused: refused2 };
|
|
48433
|
+
}
|
|
48403
48434
|
async function askRouting(input2) {
|
|
48404
48435
|
let timer;
|
|
48405
48436
|
try {
|
|
@@ -48409,8 +48440,8 @@ async function askRouting(input2) {
|
|
|
48409
48440
|
const accountFor = handle.accountFor;
|
|
48410
48441
|
if (typeof accountFor !== "function")
|
|
48411
48442
|
return void 0;
|
|
48412
|
-
const requested = input2.deadlineMs ??
|
|
48413
|
-
const deadlineMs = Number.isNaN(requested) ?
|
|
48443
|
+
const requested = input2.deadlineMs ?? 1500;
|
|
48444
|
+
const deadlineMs = Number.isNaN(requested) ? 1500 : Math.min(2e3, Math.max(1, requested));
|
|
48414
48445
|
const expired = new Promise((resolve33) => {
|
|
48415
48446
|
timer = setTimeout(() => resolve33(void 0), deadlineMs);
|
|
48416
48447
|
timer.unref();
|
|
@@ -48423,10 +48454,15 @@ async function askRouting(input2) {
|
|
|
48423
48454
|
if (typeof cap === "number" && Number.isFinite(cap)) {
|
|
48424
48455
|
request2.hold_wait_max_s = Math.max(0, Math.floor(cap));
|
|
48425
48456
|
}
|
|
48457
|
+
if (input2.refusals === true)
|
|
48458
|
+
request2.refusals = true;
|
|
48426
48459
|
const pending = accountFor.call(handle, request2, { deadlineMs });
|
|
48427
48460
|
if (!isObject2(pending) || typeof pending.then !== "function")
|
|
48428
48461
|
return void 0;
|
|
48429
48462
|
const answer = await Promise.race([pending, expired]);
|
|
48463
|
+
if (input2.refusals === true && isObject2(answer) && "refused" in answer) {
|
|
48464
|
+
return refusalFor(answer.refused);
|
|
48465
|
+
}
|
|
48430
48466
|
return selectionFor(answer, input2.candidates);
|
|
48431
48467
|
} catch {
|
|
48432
48468
|
return void 0;
|
|
@@ -48535,6 +48571,17 @@ function reportRouting(input2) {
|
|
|
48535
48571
|
};
|
|
48536
48572
|
break;
|
|
48537
48573
|
}
|
|
48574
|
+
case "credential_refused": {
|
|
48575
|
+
const { credentialId, providerCode } = input2;
|
|
48576
|
+
if (!isNonEmptyString(credentialId) || typeof providerCode !== "string" || !/^[a-z0-9._-]{1,64}$/.test(providerCode))
|
|
48577
|
+
return;
|
|
48578
|
+
payload = {
|
|
48579
|
+
...identity4,
|
|
48580
|
+
outcome: "credential_refused",
|
|
48581
|
+
provider_code: providerCode
|
|
48582
|
+
};
|
|
48583
|
+
break;
|
|
48584
|
+
}
|
|
48538
48585
|
default:
|
|
48539
48586
|
return;
|
|
48540
48587
|
}
|
|
@@ -49290,6 +49337,16 @@ function isPrimaryVaultRequest(kind, headers) {
|
|
|
49290
49337
|
var FIRST_RETRY_DELAY_MS = 1e3;
|
|
49291
49338
|
var MODEL_UNAVAILABLE_TTL_MS = 60 * 60 * 1e3;
|
|
49292
49339
|
var ROUTING_ASK_DEADLINE_MS = 2e3;
|
|
49340
|
+
function routingRefusalRetryAfterSeconds(refused2, now) {
|
|
49341
|
+
const { retryAfterSecs, resetsAtMs } = refused2;
|
|
49342
|
+
if (typeof retryAfterSecs === "number" && Number.isFinite(retryAfterSecs) && retryAfterSecs > 0) {
|
|
49343
|
+
return BigInt(Math.ceil(retryAfterSecs));
|
|
49344
|
+
}
|
|
49345
|
+
if (typeof resetsAtMs === "number" && Number.isFinite(resetsAtMs) && resetsAtMs > now) {
|
|
49346
|
+
return (BigInt(Math.ceil(resetsAtMs - now)) + 999n) / 1000n;
|
|
49347
|
+
}
|
|
49348
|
+
return void 0;
|
|
49349
|
+
}
|
|
49293
49350
|
function prepareAgyWireRequest(wire, request2) {
|
|
49294
49351
|
return wire.prepare(
|
|
49295
49352
|
request2.input,
|
|
@@ -49885,10 +49942,27 @@ function createRequestExecutor(deps) {
|
|
|
49885
49942
|
deadlineMs: Math.min(
|
|
49886
49943
|
ROUTING_ASK_DEADLINE_MS,
|
|
49887
49944
|
deadline.remainingMs()
|
|
49888
|
-
)
|
|
49945
|
+
),
|
|
49946
|
+
refusals: true
|
|
49889
49947
|
})
|
|
49890
49948
|
);
|
|
49891
49949
|
checkAborted();
|
|
49950
|
+
if (answer && "refused" in answer) {
|
|
49951
|
+
const { code: code2, routingCode } = answer.refused;
|
|
49952
|
+
log18.warn("routing-refused", {
|
|
49953
|
+
code: code2,
|
|
49954
|
+
...routingCode === void 0 ? {} : { routingCode }
|
|
49955
|
+
});
|
|
49956
|
+
const retryAfterSeconds = routingRefusalRetryAfterSeconds(
|
|
49957
|
+
answer.refused,
|
|
49958
|
+
Date.now()
|
|
49959
|
+
);
|
|
49960
|
+
return createNativeGoogleErrorResponse({
|
|
49961
|
+
status: 412,
|
|
49962
|
+
reason: "routing_refused",
|
|
49963
|
+
...retryAfterSeconds === void 0 ? {} : { retryAfterSeconds }
|
|
49964
|
+
});
|
|
49965
|
+
}
|
|
49892
49966
|
if (answer && answer.candidate.index !== account.index && !excludedIndexes?.has(answer.candidate.index)) {
|
|
49893
49967
|
account = accountManager.getCurrentOrNextForFamily(
|
|
49894
49968
|
family,
|
|
@@ -57937,6 +58011,7 @@ var WRITER_LOCK_CONSTANTS2 = Object.freeze({
|
|
|
57937
58011
|
init_private_files2();
|
|
57938
58012
|
|
|
57939
58013
|
// src/common-auth-embedded/fs/refresh-file-lock.js
|
|
58014
|
+
init_logger3();
|
|
57940
58015
|
import { randomUUID as randomUUID21 } from "node:crypto";
|
|
57941
58016
|
import { link as link4, lstat as lstat9, mkdir as mkdir17, open as open10, readdir as readdir6, readFile as readFile19, rename as rename12, rm as rm7, stat as stat16, unlink as unlink13 } from "node:fs/promises";
|
|
57942
58017
|
import { basename as basename12, dirname as dirname27, join as join33 } from "node:path";
|
|
@@ -58891,17 +58966,15 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
58891
58966
|
removalConfirmed = true;
|
|
58892
58967
|
}, deadline);
|
|
58893
58968
|
changingRecordError = void 0;
|
|
58894
|
-
if (markerAcquired) {
|
|
58895
|
-
|
|
58896
|
-
throw new PrivateFileError2(lockPath, "release-not-confirmed", {
|
|
58897
|
-
code: "EIO"
|
|
58898
|
-
});
|
|
58899
|
-
releaseConfirmed = removalConfirmed;
|
|
58969
|
+
if (markerAcquired && removalConfirmed) {
|
|
58970
|
+
releaseConfirmed = true;
|
|
58900
58971
|
return;
|
|
58901
58972
|
}
|
|
58902
|
-
if (
|
|
58903
|
-
|
|
58904
|
-
|
|
58973
|
+
if (!markerAcquired) {
|
|
58974
|
+
if (signal?.aborted)
|
|
58975
|
+
return;
|
|
58976
|
+
await recoverStaleEvictionMarker(deadline);
|
|
58977
|
+
}
|
|
58905
58978
|
} catch (error) {
|
|
58906
58979
|
const changingRecord = windowsPrivateFiles2 && (isChangingLockCreate(error) || isWindowsAccessDeniedRead2(error, [
|
|
58907
58980
|
lockPath,
|
|
@@ -58931,6 +59004,9 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
58931
59004
|
throw changingRecordError ?? removalError ?? new PrivateFileError2(lockPath, "release-not-confirmed", {
|
|
58932
59005
|
code: "ETIMEDOUT"
|
|
58933
59006
|
});
|
|
59007
|
+
createLogger3("fs").warn("File lock release deadline expired", {
|
|
59008
|
+
lockPath
|
|
59009
|
+
});
|
|
58934
59010
|
}
|
|
58935
59011
|
};
|
|
58936
59012
|
}
|