Files
discord-decomp/_bundle/Module937.js
T
2026-11-01 12:12:55 +02:00

191 lines
6.9 KiB
JavaScript

// Metro module 937 (f938).
import { fill } from "./addNonEnumerableProperty";
import * as _Module936 from "./Module936";
import { isJsonRpcRequest, isJsonRpcResponse, isValidContentItem } from "./Module936";
import { extractSessionDataFromInitializeRequest, buildClientAttributesFromInfo, extractSessionDataFromInitializeResponse } from "./extractClientInfo";
import { cleanupSessionDataForTransport, storeSessionDataForTransport, updateSessionDataForTransport } from "./Module939";
import { withIsolationScope, getIsolationScope } from "./Module848";
import { buildMcpServerSpanConfig, createMcpNotificationSpan, createMcpOutgoingNotificationSpan } from "./createMcpSpan";
import { startInactiveSpan, withActiveSpan } from "./createChildOrRootSpan";
import { MCP_PROTOCOL_VERSION_ATTRIBUTE } from "./Module940";
import { cleanupPendingSpansForTransport, storeSpanForRequest, completeSpanWithResults } from "./Module945";
import { captureError } from "./Module947";
import { HermesBuiltin } from "../_hermes/prelude";
function $mk117561($env) {
return () => {
const r4 = $env;
const r3 = $env.$parent[0];
return r3.call.apply(r3, [r4[3], ...r4[1]]);
};
}
function $mk117562($env) {
return function captureJsonRpcErrorResponse(a0) {
L11: {
try {
if (a0 && typeof a0 === "object" && "code" in a0 && "message" in a0) {
if (a0.code !== -32603) {
if (!(a0.code >= -32099)) {
break L11;
}
if (!(a0.code <= -32000)) {
break L11;
}
}
const error = new Error(a0.message);
error.name = `JsonRpcError_${a0.code}`;
captureError(error, "protocol");
}
} catch ($e) {}
}
};
}
let env772 = {};
Object.defineProperty(exports, Symbol.toStringTag, {
value: "Module"
});
export function wrapTransportError(a0) {
if (a0.onerror) {
fill(a0, "onerror", (c23911_0) => function(a0) {
(function captureTransportError(a0) {
try {
captureError(a0, "transport");
} catch ($e) {}
})(a0);
return c23911_0.call(this, a0);
});
}
}
export function wrapTransportOnClose(a0) {
if (a0.onclose) {
fill(a0, "onclose", (c23912_0) => function(...args) {
cleanupPendingSpansForTransport(this);
cleanupSessionDataForTransport(this);
return c23912_0.call.apply(c23912_0, [this, ...args]);
});
}
}
export function wrapTransportOnMessage(a0, c12581_0) {
if (a0.onmessage) {
fill(a0, "onmessage", (c23913_0) => function(a0, a1) {
let c28691_0, c28691_3;
if (isJsonRpcRequest(a0)) {
const r33 = a0.method === "initialize";
c28691_0 = r33;
if (r33) {
try {
const r37 = extractSessionDataFromInitializeRequest(a0);
c28691_3 = r37;
storeSessionDataForTransport(this, r37);
} catch ($e) {}
}
return withIsolationScope(getIsolationScope().clone(), () => {
const r23 = startInactiveSpan(buildMcpServerSpanConfig(a0, this, a1, c12581_0));
if (c28691_0 && c28691_3) {
const r26 = {};
HermesBuiltin.copyDataProperties(r26, buildClientAttributesFromInfo(c28691_3.clientInfo));
let protocolVersion = c28691_3.protocolVersion;
if (protocolVersion) {
const r33 = {};
r33[MCP_PROTOCOL_VERSION_ATTRIBUTE] = c28691_3.protocolVersion;
protocolVersion = r33;
}
HermesBuiltin.copyDataProperties(r26, protocolVersion);
r23.setAttributes(r26);
}
storeSpanForRequest(this, a0.id, r23, a0.method);
return withActiveSpan(r23, () => c23913_0.call(this, a0, a1));
});
}
return _Module936.isJsonRpcNotification(a0) ? createMcpNotificationSpan(a0, this, a1, c12581_0, () => c23913_0.call(this, a0, a1)) : c23913_0.call(this, a0, a1);
});
}
}
export function wrapTransportSend(a0, a1) {
let env12582 = {
$parent: env772
};
env12582[0] = a1;
if (a0.send) {
fill(a0, "send", (a0) => {
let env23914 = {
$parent: env12582
};
env23914[0] = a0;
return async function(...c28692_1) {
let r89, mcpOutgoingNotificationSpan;
let c28692_2, c28692_3, _this2;
const _this = this;
let c28692_5 = 0;
const r11 = env23914;
L22: {
L21: {
try {
let env31175;
_this2 = _this;
c28692_3 = r11;
const r34 = env31175 = {
$parent: r11
};
c28692_2 = r34;
env31175[3] = _this2;
env31175[1] = c28692_1;
env31175[2] = void 0;
env31175[0] = void 0;
await void 0;
env31175[2] = env31175[1][0];
const isJsonRpcNotification = _Module936.isJsonRpcNotification(env31175[2]);
const r62 = c28692_2;
const r63 = c28692_3;
if (isJsonRpcNotification) {
mcpOutgoingNotificationSpan = createMcpOutgoingNotificationSpan(env31175[2], _this2, r63.$parent[0], $mk117561(r62));
break L22;
}
if (isJsonRpcResponse(env31175[2]) && env31175[2].id !== null && env31175[2].id !== void 0) {
if (env31175[2].error) {
const error = env31175[2].error;
$mk117562(env23914.$parent.$parent)(error);
}
L17: {
if (isValidContentItem(env31175[2].result)) {
if (!env31175[2].result.protocolVersion && !env31175[2].result.serverInfo) {
break L17;
}
c28692_5 = 1;
env31175[0] = extractSessionDataFromInitializeResponse(env31175[2].result);
updateSessionDataForTransport(_this2, env31175[0]);
c28692_5 = 0;
}
}
completeSpanWithResults(_this2, env31175[2].id, env31175[2].result, c28692_3.$parent[0]);
}
const r79 = env23914[0];
r89 = r79.call.apply(r79, [_this2, ...env31175[1]]);
} catch ($e) {
let r31 = $e;
if (c28692_5 !== 0) {
while (true) {
try {
c28692_5 = 0;
completeSpanWithResults(_this2, env31175[2].id, env31175[2].result, c28692_3.$parent[0]);
const r186 = env23914[0];
r89 = r186.call.apply(r186, [_this2, ...env31175[1]]);
break L21;
} catch ($e) {
r31 = $e;
if (c28692_5 === 0) {
break;
}
}
}
}
throw r31;
}
}
return r89;
}
return mcpOutgoingNotificationSpan;
};
});
}
}