@mcpjam/inspector 3.13.0 → 3.14.0
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/bin/runtime-profile.mjs +774 -0
- package/bin/start.js +117 -24
- package/dist/client/assets/{OAuthDesktopReturnNotice-D5tJNqny.js → OAuthDesktopReturnNotice-D7d-faB1.js} +2 -2
- package/dist/client/assets/{app-bootstrap-baadQQNk.js → app-bootstrap-BtDjj9nz.js} +350 -350
- package/dist/client/assets/{button-DHPqnOj6.js → button-B99pZFz_.js} +2 -2
- package/dist/client/assets/{chunk-D32TOXHM-BPB6AqSK.js → chunk-D32TOXHM-Bcyg0ZVj.js} +5 -5
- package/dist/client/assets/{dead-clicks-autocapture-Cbczl2El.js → dead-clicks-autocapture-CnUHv5CB.js} +2 -2
- package/dist/client/assets/{error-reporting-CORfsjyM.js → error-reporting-BohBwcQQ.js} +4 -4
- package/dist/client/assets/{error-reporting-B4hGM_ob.js → error-reporting-p6G1ojum.js} +1 -1
- package/dist/client/assets/{exception-autocapture-CMOUrnel.js → exception-autocapture-Q-isBTHp.js} +2 -2
- package/dist/client/assets/{failed-request-tracker-DoQRXuIy.js → failed-request-tracker-BBJW8izb.js} +2 -2
- package/dist/client/assets/{highlighted-body-KQOG7T2V-_ljE4u1k.js → highlighted-body-KQOG7T2V-zsXWRnSM.js} +2 -2
- package/dist/client/assets/{index-BBr8TZVx.js → index-C9oFRqoK.js} +3 -3
- package/dist/client/assets/{jszip.min-C-vIQbxH.js → jszip.min-C86zG41a.js} +2 -2
- package/dist/client/assets/{mermaid-MCJ5UELQ-DTJaEEBm.js → mermaid-MCJ5UELQ-DAW4LYwz.js} +1 -1
- package/dist/client/assets/{posthog-recorder-Dby9Z8HR.js → posthog-recorder-trUd0BXy.js} +2 -2
- package/dist/client/assets/{preload-helper-Dvt1a6xa.js → preload-helper-Buauuydw.js} +2 -2
- package/dist/client/assets/{react-CD7Pk4KS.js → react-CZb-kDOs.js} +2 -2
- package/dist/client/assets/{rolldown-runtime-mzU9SaVm.js → rolldown-runtime-Bkua2_Tb.js} +1 -1
- package/dist/client/assets/{surveys-DYqpu8xl.js → surveys-BISK_WOT.js} +2 -2
- package/dist/client/assets/{trace-timeline-PnE1ouRj.js → trace-timeline-CRewsP1E.js} +2 -2
- package/dist/client/assets/{trace-timeline-WXINST5z.js → trace-timeline-D-DWE-sO.js} +1 -1
- package/dist/client/assets/{web-vitals-BLq6M5vx.js → web-vitals-DqmZ9w02.js} +2 -2
- package/dist/client/index.html +7 -7
- package/dist/server/authorization-MA42CNYT.js +22 -0
- package/dist/server/chunk-7M3XVZCQ.js +381 -0
- package/dist/server/{chunk-MBS3EZ3U.js → chunk-7ZIR7SX7.js} +5 -44
- package/dist/server/chunk-C47PTIDS.js +487 -0
- package/dist/server/chunk-DHRTCKJA.js +3979 -0
- package/dist/server/chunk-HJTKF2X6.js +45 -0
- package/dist/server/{chunk-2FVSBJQF.js → chunk-KNO4KZJF.js} +224 -758
- package/dist/server/{chunk-QHYREDE3.js → chunk-RWFTW2EW.js} +7 -5
- package/dist/server/chunk-SDWJSPSI.js +252 -0
- package/dist/server/chunk-VFRLMHOC.js +33 -0
- package/dist/server/chunk-XSQ2GC45.js +438 -0
- package/dist/server/chunk-YQ2BTE46.js +88 -0
- package/dist/server/{consent-lifetime-TYLDY64H.js → consent-lifetime-OXQM37RV.js} +4 -3
- package/dist/server/grants-UVE62NGN.js +37 -0
- package/dist/server/harness-install-cli.js +239 -4
- package/dist/server/index.js +9044 -9216
- package/dist/server/local-turn-XSUGEKTL.js +19 -0
- package/dist/server/runtime-health-TCF3ZEKS.js +28 -0
- package/dist/server/runtime-lifecycle-YQ3KWDLJ.js +53 -0
- package/package.json +26 -23
- package/dist/server/chunk-I7ZVTBZP.js +0 -3100
- package/dist/server/local-turn-VQDSTY6T.js +0 -12
|
@@ -0,0 +1,487 @@
|
|
|
1
|
+
// server/utils/logger.ts
|
|
2
|
+
import * as Sentry from "@sentry/node";
|
|
3
|
+
import { Axiom } from "@axiomhq/js";
|
|
4
|
+
|
|
5
|
+
// server/utils/log-events.ts
|
|
6
|
+
var warnedMissingEnv = false;
|
|
7
|
+
var ALLOWED_ENVIRONMENTS = [
|
|
8
|
+
"prod",
|
|
9
|
+
"staging",
|
|
10
|
+
"preview",
|
|
11
|
+
"dev",
|
|
12
|
+
"local",
|
|
13
|
+
"test"
|
|
14
|
+
];
|
|
15
|
+
var ENVIRONMENT_ALIASES = {
|
|
16
|
+
production: "prod",
|
|
17
|
+
development: "dev"
|
|
18
|
+
};
|
|
19
|
+
function resolveEnvironment() {
|
|
20
|
+
const fromEnv = process.env.ENVIRONMENT?.trim();
|
|
21
|
+
if (fromEnv && ALLOWED_ENVIRONMENTS.includes(fromEnv)) {
|
|
22
|
+
return fromEnv;
|
|
23
|
+
}
|
|
24
|
+
const aliased = fromEnv ? ENVIRONMENT_ALIASES[fromEnv] : void 0;
|
|
25
|
+
if (aliased) {
|
|
26
|
+
return aliased;
|
|
27
|
+
}
|
|
28
|
+
if (process.env.NODE_ENV === "test") return "test";
|
|
29
|
+
if (process.env.NODE_ENV === "production") {
|
|
30
|
+
if (!warnedMissingEnv) {
|
|
31
|
+
warnedMissingEnv = true;
|
|
32
|
+
process.stderr.write(
|
|
33
|
+
"[logging] ENVIRONMENT not set in production; defaulting to 'prod'\n"
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
return "prod";
|
|
37
|
+
}
|
|
38
|
+
return "dev";
|
|
39
|
+
}
|
|
40
|
+
var BAKED_VERSION = "3.14.0";
|
|
41
|
+
function blankToNull(value) {
|
|
42
|
+
return value === void 0 || value.trim() === "" ? null : value;
|
|
43
|
+
}
|
|
44
|
+
function resolveAppVersion() {
|
|
45
|
+
return blankToNull(BAKED_VERSION) ?? blankToNull(process.env.npm_package_version);
|
|
46
|
+
}
|
|
47
|
+
function resolveRelease() {
|
|
48
|
+
return blankToNull(process.env.RAILWAY_GIT_COMMIT_SHA) ?? blankToNull(process.env.GIT_SHA) ?? resolveAppVersion();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// shared/secret-shape-redaction.ts
|
|
52
|
+
var authHeaderLike = () => /\b(authorization["']?\s*:\s*)["']?[^\n\r"'`]+/gi;
|
|
53
|
+
var tokenLike = () => /\bBearer\s+[A-Za-z0-9._~\-+/=]+\b/gi;
|
|
54
|
+
var skKeyLike = () => /\bsk-(?:[A-Za-z0-9]+-)*[A-Za-z0-9]{16,}\b/g;
|
|
55
|
+
var jwtLike = () => /\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\b/g;
|
|
56
|
+
var secretParamLike = () => /\b((?:api[_-]?key|apikey|access[_-]?token|refresh[_-]?token|id[_-]?token|client[_-]?secret|authorization|secret|password|passwd|pwd|token|auth|key|sig|signature)\s*[=:]\s*["']?)[^&\s"'`]+/gi;
|
|
57
|
+
var urlBasicAuthLike = () => /(\/\/[^\s/:@]+:)[^\s@/]+@/g;
|
|
58
|
+
function redactSecretShapes(text, replacement = "[redacted]") {
|
|
59
|
+
if (!text) return text;
|
|
60
|
+
const parts = text.split(SECRET_PLACEHOLDER);
|
|
61
|
+
if (parts.length === 1) return redactSegment(text, replacement);
|
|
62
|
+
return parts.map(
|
|
63
|
+
(part, index) => (
|
|
64
|
+
// Odd segments are the captured names.
|
|
65
|
+
index % 2 === 1 ? `{{secret:${part}}}` : redactSegment(part, replacement)
|
|
66
|
+
)
|
|
67
|
+
).join("");
|
|
68
|
+
}
|
|
69
|
+
var SECRET_PLACEHOLDER = /\{\{secret:([A-Z_][A-Z0-9_]*)\}\}/g;
|
|
70
|
+
function redactSegment(text, replacement) {
|
|
71
|
+
if (!text) return text;
|
|
72
|
+
return text.replace(authHeaderLike(), `$1${replacement}`).replace(tokenLike(), `Bearer ${replacement}`).replace(jwtLike(), replacement).replace(urlBasicAuthLike(), `$1${replacement}@`).replace(skKeyLike(), replacement).replace(secretParamLike(), `$1${replacement}`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// server/utils/log-scrubber.ts
|
|
76
|
+
var FORBIDDEN_KEY_SUBSTRINGS = [
|
|
77
|
+
"authorization",
|
|
78
|
+
"cookie",
|
|
79
|
+
"password",
|
|
80
|
+
"token",
|
|
81
|
+
"secret",
|
|
82
|
+
"apikey",
|
|
83
|
+
"pkceverifier",
|
|
84
|
+
"pkcechallenge",
|
|
85
|
+
"stripecustomer",
|
|
86
|
+
"stripesubscription",
|
|
87
|
+
"stripeprice",
|
|
88
|
+
"x-mcp-session-auth",
|
|
89
|
+
"x-api-key",
|
|
90
|
+
// Header-broker model lease (E2B network-transform delivery). A signed model
|
|
91
|
+
// lease — never log it, even though the inspector never handles it directly
|
|
92
|
+
// (defense in depth).
|
|
93
|
+
"x-mcpjam-harness-lease"
|
|
94
|
+
];
|
|
95
|
+
var ALLOWLISTED_KEYS = /* @__PURE__ */ new Set(["emaildomain"]);
|
|
96
|
+
var EMAIL_LIKE = /\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/gi;
|
|
97
|
+
function isForbiddenKey(key) {
|
|
98
|
+
const lower = key.toLowerCase();
|
|
99
|
+
if (ALLOWLISTED_KEYS.has(lower)) return false;
|
|
100
|
+
if (lower === "email" || lower.endsWith("email")) return true;
|
|
101
|
+
return FORBIDDEN_KEY_SUBSTRINGS.some((s) => lower.includes(s));
|
|
102
|
+
}
|
|
103
|
+
function scrubString(s) {
|
|
104
|
+
return s.replace(authHeaderLike(), "$1[redacted]").replace(tokenLike(), "Bearer [redacted-token]").replace(jwtLike(), "[redacted-jwt]").replace(urlBasicAuthLike(), "$1[redacted]@").replace(EMAIL_LIKE, "[redacted-email]").replace(skKeyLike(), "[redacted-secret]").replace(secretParamLike(), "$1[redacted]");
|
|
105
|
+
}
|
|
106
|
+
function scrubLogPayload(value) {
|
|
107
|
+
return scrubValue(value, /* @__PURE__ */ new WeakSet());
|
|
108
|
+
}
|
|
109
|
+
function scrubValue(value, seen) {
|
|
110
|
+
if (value === null || value === void 0) return value;
|
|
111
|
+
if (typeof value === "string") return scrubString(value);
|
|
112
|
+
if (typeof value !== "object") return value;
|
|
113
|
+
if (value instanceof Date) return value.toISOString();
|
|
114
|
+
if (value instanceof Error) {
|
|
115
|
+
return {
|
|
116
|
+
name: value.name,
|
|
117
|
+
message: scrubString(value.message),
|
|
118
|
+
stack: value.stack ? scrubString(value.stack) : void 0
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
if (typeof Buffer !== "undefined" && Buffer.isBuffer(value)) {
|
|
122
|
+
return "[buffer]";
|
|
123
|
+
}
|
|
124
|
+
if (seen.has(value)) return "[circular]";
|
|
125
|
+
seen.add(value);
|
|
126
|
+
if (Array.isArray(value)) return value.map((v) => scrubValue(v, seen));
|
|
127
|
+
const out = {};
|
|
128
|
+
for (const [k, v] of Object.entries(value)) {
|
|
129
|
+
if (isForbiddenKey(k)) {
|
|
130
|
+
out[k] = "[redacted]";
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
out[k] = scrubValue(v, seen);
|
|
134
|
+
}
|
|
135
|
+
return out;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// server/utils/error-capture-stamp.ts
|
|
139
|
+
var CAPTURE_STAMP = Symbol.for("mcpjam.errorOriginCaptureHandled");
|
|
140
|
+
function isStampable(value) {
|
|
141
|
+
return typeof value === "object" && value !== null;
|
|
142
|
+
}
|
|
143
|
+
function safeErrorMessage(value) {
|
|
144
|
+
try {
|
|
145
|
+
return value instanceof Error ? value.message : String(value);
|
|
146
|
+
} catch {
|
|
147
|
+
return "[unreadable error value]";
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function markOriginCaptureHandled(value) {
|
|
151
|
+
if (!isStampable(value)) return;
|
|
152
|
+
try {
|
|
153
|
+
Object.defineProperty(value, CAPTURE_STAMP, {
|
|
154
|
+
value: true,
|
|
155
|
+
enumerable: false,
|
|
156
|
+
configurable: true,
|
|
157
|
+
writable: true
|
|
158
|
+
});
|
|
159
|
+
} catch {
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
function ensureStampable(value) {
|
|
163
|
+
if (!isStampable(value)) return new Error(String(value));
|
|
164
|
+
let extensible;
|
|
165
|
+
try {
|
|
166
|
+
extensible = Object.isExtensible(value);
|
|
167
|
+
} catch {
|
|
168
|
+
extensible = false;
|
|
169
|
+
}
|
|
170
|
+
if (!extensible) {
|
|
171
|
+
const wrapped = new Error(
|
|
172
|
+
safeErrorMessage(value)
|
|
173
|
+
);
|
|
174
|
+
Object.defineProperty(wrapped, "cause", {
|
|
175
|
+
value,
|
|
176
|
+
enumerable: false,
|
|
177
|
+
configurable: true,
|
|
178
|
+
writable: true
|
|
179
|
+
});
|
|
180
|
+
return wrapped;
|
|
181
|
+
}
|
|
182
|
+
return value;
|
|
183
|
+
}
|
|
184
|
+
var MAX_CAUSE_DEPTH = 8;
|
|
185
|
+
function isOriginCaptureHandled(error) {
|
|
186
|
+
const seen = /* @__PURE__ */ new Set();
|
|
187
|
+
let current = error;
|
|
188
|
+
for (let depth = 0; depth < MAX_CAUSE_DEPTH; depth += 1) {
|
|
189
|
+
if (!isStampable(current) || seen.has(current)) return false;
|
|
190
|
+
seen.add(current);
|
|
191
|
+
try {
|
|
192
|
+
if (current[CAPTURE_STAMP] === true) return true;
|
|
193
|
+
const normalized = current.normalized;
|
|
194
|
+
if (isStampable(normalized) && normalized[CAPTURE_STAMP] === true) {
|
|
195
|
+
return true;
|
|
196
|
+
}
|
|
197
|
+
current = current.cause;
|
|
198
|
+
} catch {
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// server/utils/logger.ts
|
|
206
|
+
var isVerbose = () => process.env.VERBOSE_LOGS === "true";
|
|
207
|
+
var isDev = () => process.env.NODE_ENV !== "production";
|
|
208
|
+
var shouldLog = () => isVerbose() || isDev();
|
|
209
|
+
function isTrackingDisabled() {
|
|
210
|
+
const dnt = process.env.DO_NOT_TRACK;
|
|
211
|
+
return dnt === "1" || dnt === "true";
|
|
212
|
+
}
|
|
213
|
+
var axiomClient;
|
|
214
|
+
function getAxiom() {
|
|
215
|
+
if (isTrackingDisabled()) return null;
|
|
216
|
+
if (axiomClient === void 0) {
|
|
217
|
+
axiomClient = process.env.AXIOM_TOKEN && process.env.AXIOM_DATASET ? new Axiom({ token: process.env.AXIOM_TOKEN }) : null;
|
|
218
|
+
}
|
|
219
|
+
return axiomClient;
|
|
220
|
+
}
|
|
221
|
+
var dataset = () => process.env.AXIOM_DATASET ?? "";
|
|
222
|
+
var environment = () => resolveEnvironment();
|
|
223
|
+
function ingestToAxiom(level, message, context) {
|
|
224
|
+
const axiom = getAxiom();
|
|
225
|
+
if (!axiom) return;
|
|
226
|
+
axiom.ingest(dataset(), [
|
|
227
|
+
{ ...context, level, message, environment: environment() }
|
|
228
|
+
]);
|
|
229
|
+
}
|
|
230
|
+
function safeErrorText(error) {
|
|
231
|
+
try {
|
|
232
|
+
return error instanceof Error ? error.message : String(error);
|
|
233
|
+
} catch {
|
|
234
|
+
return "[unreadable error value]";
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
function captureOriginErrorToSentry(error, options) {
|
|
238
|
+
Sentry.captureException(error, options);
|
|
239
|
+
}
|
|
240
|
+
var logger = {
|
|
241
|
+
/**
|
|
242
|
+
* Log an error. Always sends to Sentry and Axiom, only prints to console in dev/verbose mode.
|
|
243
|
+
*
|
|
244
|
+
* This is the server's single Sentry capture path for free-form errors —
|
|
245
|
+
* `Hono.onError` routes through here, so route handlers never call
|
|
246
|
+
* `captureException` themselves and nothing double-counts.
|
|
247
|
+
*
|
|
248
|
+
* NOTE: For new production diagnostics in `server/routes/web/`, prefer `logger.event()` —
|
|
249
|
+
* free-form messages are not queryable in Axiom. Legacy callers (CLI, system code,
|
|
250
|
+
* non-route utilities) remain on this API. See `server/utils/LOGGING.md`.
|
|
251
|
+
*/
|
|
252
|
+
error(message, error, context) {
|
|
253
|
+
if (!isOriginCaptureHandled(error)) {
|
|
254
|
+
Sentry.captureException(error ?? new Error(message), {
|
|
255
|
+
extra: { message, ...context }
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
ingestToAxiom("error", message, {
|
|
259
|
+
...context,
|
|
260
|
+
error: safeErrorText(error)
|
|
261
|
+
});
|
|
262
|
+
if (shouldLog()) {
|
|
263
|
+
console.error(message, error);
|
|
264
|
+
}
|
|
265
|
+
},
|
|
266
|
+
/**
|
|
267
|
+
* Log a warning. Sends to Axiom, only prints to console in dev/verbose mode.
|
|
268
|
+
*
|
|
269
|
+
* Deliberately does NOT capture to Sentry. Every `logger.warn` in the tree
|
|
270
|
+
* used to become a Sentry event, which across thousands of self-hosted
|
|
271
|
+
* installs is the single largest quota-spike vector we have — and a warning
|
|
272
|
+
* is by definition something we chose not to treat as a failure. Axiom is
|
|
273
|
+
* the right home for it: queryable, cheap, no issue-tracker noise. A warning
|
|
274
|
+
* that genuinely needs a Sentry issue should be an explicit
|
|
275
|
+
* `logger.event(..., { error, sentry: true })` at the callsite that owns it.
|
|
276
|
+
*
|
|
277
|
+
* NOTE: For new production diagnostics in `server/routes/web/`, prefer `logger.event()` —
|
|
278
|
+
* free-form messages are not queryable in Axiom. Legacy callers (CLI, system code,
|
|
279
|
+
* non-route utilities) remain on this API. See `server/utils/LOGGING.md`.
|
|
280
|
+
*/
|
|
281
|
+
warn(message, context) {
|
|
282
|
+
ingestToAxiom("warn", message, context);
|
|
283
|
+
if (shouldLog()) {
|
|
284
|
+
console.warn(message);
|
|
285
|
+
}
|
|
286
|
+
},
|
|
287
|
+
/**
|
|
288
|
+
* Log info. Always sends to Axiom. Only prints to console in dev/verbose mode.
|
|
289
|
+
*
|
|
290
|
+
* NOTE: For new production diagnostics in `server/routes/web/`, prefer `logger.event()` —
|
|
291
|
+
* free-form messages are not queryable in Axiom. Legacy callers (CLI, system code,
|
|
292
|
+
* non-route utilities) remain on this API. See `server/utils/LOGGING.md`.
|
|
293
|
+
*/
|
|
294
|
+
info(message, context) {
|
|
295
|
+
ingestToAxiom("info", message, context);
|
|
296
|
+
if (shouldLog()) {
|
|
297
|
+
console.log(message);
|
|
298
|
+
}
|
|
299
|
+
},
|
|
300
|
+
/**
|
|
301
|
+
* Log debug info. Always sends to Axiom. Only prints to console in dev/verbose mode. Does not send to Sentry.
|
|
302
|
+
*/
|
|
303
|
+
debug(message, ...args) {
|
|
304
|
+
ingestToAxiom("debug", message, args.length ? { args } : void 0);
|
|
305
|
+
if (shouldLog()) {
|
|
306
|
+
console.log(message, ...args);
|
|
307
|
+
}
|
|
308
|
+
},
|
|
309
|
+
/**
|
|
310
|
+
* Flush pending Axiom events. Call before process exit.
|
|
311
|
+
*/
|
|
312
|
+
async flush() {
|
|
313
|
+
await getAxiom()?.flush();
|
|
314
|
+
},
|
|
315
|
+
event(eventName, base, payload, options) {
|
|
316
|
+
emit(eventName, base, payload, options);
|
|
317
|
+
},
|
|
318
|
+
systemEvent(eventName, base, payload, options) {
|
|
319
|
+
emit(eventName, base, payload, options);
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
var MAX_ERROR_MESSAGE_CHARS = 2e3;
|
|
323
|
+
var MAX_ERROR_STACK_CHARS = 4e3;
|
|
324
|
+
function serializeEmitError(error) {
|
|
325
|
+
try {
|
|
326
|
+
if (error instanceof Error) {
|
|
327
|
+
return {
|
|
328
|
+
name: error.name,
|
|
329
|
+
message: error.message.slice(0, MAX_ERROR_MESSAGE_CHARS),
|
|
330
|
+
...error.stack ? { stack: error.stack.slice(0, MAX_ERROR_STACK_CHARS) } : {}
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
return String(error).slice(0, MAX_ERROR_MESSAGE_CHARS);
|
|
334
|
+
} catch {
|
|
335
|
+
return "[unserializable error]";
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
function emit(eventName, base, payload, options) {
|
|
339
|
+
const fullPayload = scrubLogPayload({
|
|
340
|
+
...base,
|
|
341
|
+
...payload,
|
|
342
|
+
...options?.error !== void 0 ? { error: serializeEmitError(options.error) } : {},
|
|
343
|
+
event: eventName,
|
|
344
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
345
|
+
});
|
|
346
|
+
const axiom = getAxiom();
|
|
347
|
+
if (axiom) {
|
|
348
|
+
axiom.ingest(dataset(), [fullPayload]);
|
|
349
|
+
}
|
|
350
|
+
if (options?.sentry === true) {
|
|
351
|
+
if (options.error instanceof Error) {
|
|
352
|
+
Sentry.captureException(options.error, { extra: fullPayload });
|
|
353
|
+
} else {
|
|
354
|
+
Sentry.captureMessage(eventName, {
|
|
355
|
+
level: "error",
|
|
356
|
+
extra: {
|
|
357
|
+
...fullPayload,
|
|
358
|
+
...options.error !== void 0 ? { rawError: String(options.error) } : {}
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
if (shouldLog()) {
|
|
364
|
+
const consoleFn = eventName.endsWith(".failed") ? console.error : console.log;
|
|
365
|
+
consoleFn(`[event] ${eventName}`, fullPayload);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
process.on("beforeExit", () => logger.flush());
|
|
369
|
+
|
|
370
|
+
// server/utils/harness/local/local-state-lock.ts
|
|
371
|
+
import { randomUUID } from "crypto";
|
|
372
|
+
import { mkdir, readFile, rm, stat, writeFile } from "fs/promises";
|
|
373
|
+
import { join } from "path";
|
|
374
|
+
var DEFAULT_STALE_MS = 3e4;
|
|
375
|
+
var DEFAULT_POLL_MS = 25;
|
|
376
|
+
var DEFAULT_TIMEOUT_MS = 45e3;
|
|
377
|
+
async function readLockBody(file) {
|
|
378
|
+
try {
|
|
379
|
+
const parsed = JSON.parse(await readFile(file, "utf8"));
|
|
380
|
+
if (!parsed || typeof parsed !== "object") return null;
|
|
381
|
+
const body = parsed;
|
|
382
|
+
if (typeof body.pid !== "number" || !Number.isInteger(body.pid) || body.pid <= 0 || typeof body.nonce !== "string" || body.nonce.length === 0) {
|
|
383
|
+
return null;
|
|
384
|
+
}
|
|
385
|
+
return { pid: body.pid, nonce: body.nonce, at: Number(body.at) || 0 };
|
|
386
|
+
} catch {
|
|
387
|
+
return null;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
function lockHolderProvablyGone(body) {
|
|
391
|
+
if (body === null || body.pid === process.pid) return false;
|
|
392
|
+
try {
|
|
393
|
+
process.kill(body.pid, 0);
|
|
394
|
+
return false;
|
|
395
|
+
} catch (error) {
|
|
396
|
+
return error.code === "ESRCH";
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
function createLocalStateMutationLock(options) {
|
|
400
|
+
let mutationChain = Promise.resolve();
|
|
401
|
+
const staleMs = options.staleMs ?? DEFAULT_STALE_MS;
|
|
402
|
+
const pollMs = options.pollMs ?? DEFAULT_POLL_MS;
|
|
403
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
404
|
+
const acquire = async () => {
|
|
405
|
+
const root = options.rootDir();
|
|
406
|
+
const file = join(root, options.lockFileName);
|
|
407
|
+
await mkdir(root, { recursive: true, mode: 448 });
|
|
408
|
+
const nonce = randomUUID();
|
|
409
|
+
const deadline = Date.now() + timeoutMs;
|
|
410
|
+
for (; ; ) {
|
|
411
|
+
try {
|
|
412
|
+
await writeFile(
|
|
413
|
+
file,
|
|
414
|
+
JSON.stringify({ pid: process.pid, nonce, at: Date.now() }),
|
|
415
|
+
{ flag: "wx", mode: 384 }
|
|
416
|
+
);
|
|
417
|
+
return async () => {
|
|
418
|
+
const held = await readLockBody(file);
|
|
419
|
+
if (held?.nonce !== nonce) {
|
|
420
|
+
logger.warn(
|
|
421
|
+
`[local-harness] ${options.resourceLabel} lock was taken over; not releasing`
|
|
422
|
+
);
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
await rm(file, { force: true }).catch(() => {
|
|
426
|
+
});
|
|
427
|
+
};
|
|
428
|
+
} catch (error) {
|
|
429
|
+
if (error.code !== "EEXIST") throw error;
|
|
430
|
+
const body = await readLockBody(file);
|
|
431
|
+
const age = await stat(file).then(
|
|
432
|
+
(info) => Date.now() - info.mtimeMs,
|
|
433
|
+
() => 0
|
|
434
|
+
);
|
|
435
|
+
const holderGone = lockHolderProvablyGone(body);
|
|
436
|
+
const unattributable = body === null && age > staleMs;
|
|
437
|
+
if (holderGone || unattributable) {
|
|
438
|
+
logger.warn(
|
|
439
|
+
`[local-harness] breaking an abandoned ${options.resourceLabel} lock`,
|
|
440
|
+
{ age, holderGone, unattributable }
|
|
441
|
+
);
|
|
442
|
+
await rm(file, { force: true }).catch(() => {
|
|
443
|
+
});
|
|
444
|
+
continue;
|
|
445
|
+
}
|
|
446
|
+
if (Date.now() > deadline) {
|
|
447
|
+
throw new Error(
|
|
448
|
+
`timed out waiting for the local harness ${options.resourceLabel} lock` + (body === null ? "" : ` (held by pid ${body.pid})`) + ". Its holder could not be proven gone, and taking it over would admit concurrent state writers."
|
|
449
|
+
);
|
|
450
|
+
}
|
|
451
|
+
await new Promise(
|
|
452
|
+
(resolvePromise) => setTimeout(resolvePromise, pollMs)
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
};
|
|
457
|
+
return (operation) => {
|
|
458
|
+
const guarded = async () => {
|
|
459
|
+
const release = await acquire();
|
|
460
|
+
try {
|
|
461
|
+
return await operation();
|
|
462
|
+
} finally {
|
|
463
|
+
await release();
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
const run = mutationChain.then(guarded, guarded);
|
|
467
|
+
mutationChain = run.then(
|
|
468
|
+
() => void 0,
|
|
469
|
+
() => void 0
|
|
470
|
+
);
|
|
471
|
+
return run;
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
export {
|
|
476
|
+
resolveEnvironment,
|
|
477
|
+
resolveAppVersion,
|
|
478
|
+
resolveRelease,
|
|
479
|
+
redactSecretShapes,
|
|
480
|
+
markOriginCaptureHandled,
|
|
481
|
+
ensureStampable,
|
|
482
|
+
isOriginCaptureHandled,
|
|
483
|
+
captureOriginErrorToSentry,
|
|
484
|
+
logger,
|
|
485
|
+
createLocalStateMutationLock
|
|
486
|
+
};
|
|
487
|
+
//# sourceMappingURL=chunk-C47PTIDS.js.map
|