@brizz/sdk 0.2.1 → 0.2.3
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/CHANGELOG.md +13 -0
- package/dist/{chunk-KJSZPKSN.js → chunk-2XK75HRB.js} +1 -1
- package/dist/{chunk-6OYS2GR3.js → chunk-DIOULRY4.js} +2 -1
- package/dist/{chunk-QXHGMS5A.cjs → chunk-DY3UL5K7.cjs} +1 -1
- package/dist/{chunk-P5OONZTF.cjs → chunk-PUOXH4CD.cjs} +3 -2
- package/dist/google-genai-KDEYFHTK.cjs +12 -0
- package/dist/{google-genai-H6TMOKRX.js → google-genai-ZKKWSBVY.js} +3 -1
- package/dist/google-genai.cjs +2 -2
- package/dist/google-genai.js +1 -1
- package/dist/index.cjs +242 -207
- package/dist/index.js +226 -191
- package/dist/{mcp-YTBE75NP.js → mcp-5N37RUW3.js} +1 -1
- package/dist/{mcp-6LNVYVJQ.cjs → mcp-QPMPVJZD.cjs} +11 -11
- package/dist/types/cjs/internal/instrumentation/google-genai.d.ts +1 -0
- package/dist/types/cjs/internal/masking/utils.d.ts +1 -1
- package/dist/types/esm/internal/instrumentation/google-genai.d.ts +1 -0
- package/dist/types/esm/internal/masking/utils.d.ts +1 -1
- package/package.json +21 -19
- package/dist/google-genai-6S5E7GZ4.cjs +0 -10
package/dist/index.js
CHANGED
|
@@ -43,7 +43,7 @@ import {
|
|
|
43
43
|
import {
|
|
44
44
|
configure,
|
|
45
45
|
getSDKVersion
|
|
46
|
-
} from "./chunk-
|
|
46
|
+
} from "./chunk-2XK75HRB.js";
|
|
47
47
|
import {
|
|
48
48
|
AI_SDK_OTEL_SCOPE,
|
|
49
49
|
APPROVALS,
|
|
@@ -708,7 +708,7 @@ function loadGenAIInstrumentations() {
|
|
|
708
708
|
function loadMCPInstrumentation() {
|
|
709
709
|
void (async () => {
|
|
710
710
|
try {
|
|
711
|
-
const { MCPInstrumentation } = await import("./mcp-
|
|
711
|
+
const { MCPInstrumentation } = await import("./mcp-5N37RUW3.js");
|
|
712
712
|
const mcp = new MCPInstrumentation({ exceptionLogger });
|
|
713
713
|
registerInstrumentations({ instrumentations: [mcp], tracerProvider: brizzTracerProvider });
|
|
714
714
|
logger.debug("Auto-loaded MCP instrumentation");
|
|
@@ -761,7 +761,7 @@ function loadVertexAIInstrumentation() {
|
|
|
761
761
|
function loadGoogleGenAIInstrumentation() {
|
|
762
762
|
void (async () => {
|
|
763
763
|
try {
|
|
764
|
-
const { GoogleGenAIInstrumentation } = await import("./google-genai-
|
|
764
|
+
const { GoogleGenAIInstrumentation } = await import("./google-genai-ZKKWSBVY.js");
|
|
765
765
|
const googleGenAI = new GoogleGenAIInstrumentation({ exceptionLogger });
|
|
766
766
|
registerInstrumentations({
|
|
767
767
|
instrumentations: [googleGenAI],
|
|
@@ -1256,7 +1256,7 @@ var InstrumentationRegistry = class _InstrumentationRegistry {
|
|
|
1256
1256
|
const genaiModule = this.manualModules.google_genai;
|
|
1257
1257
|
void (async () => {
|
|
1258
1258
|
try {
|
|
1259
|
-
const { GoogleGenAIInstrumentation } = await import("./google-genai-
|
|
1259
|
+
const { GoogleGenAIInstrumentation } = await import("./google-genai-ZKKWSBVY.js");
|
|
1260
1260
|
const genaiInst = new GoogleGenAIInstrumentation({ exceptionLogger: exceptionLogger2 });
|
|
1261
1261
|
genaiInst.manuallyInstrument(genaiModule);
|
|
1262
1262
|
logger.debug("Manual instrumentation enabled for Google GenAI");
|
|
@@ -1271,7 +1271,7 @@ var InstrumentationRegistry = class _InstrumentationRegistry {
|
|
|
1271
1271
|
const mcpModules = this.manualModules.mcp;
|
|
1272
1272
|
void (async () => {
|
|
1273
1273
|
try {
|
|
1274
|
-
const { MCPInstrumentation } = await import("./mcp-
|
|
1274
|
+
const { MCPInstrumentation } = await import("./mcp-5N37RUW3.js");
|
|
1275
1275
|
const instrumentation = new MCPInstrumentation({ exceptionLogger: exceptionLogger2 });
|
|
1276
1276
|
instrumentation.manuallyInstrument(mcpModules);
|
|
1277
1277
|
logger.debug("Manual instrumentation enabled for MCP");
|
|
@@ -1307,184 +1307,6 @@ var InstrumentationRegistry = class _InstrumentationRegistry {
|
|
|
1307
1307
|
}
|
|
1308
1308
|
};
|
|
1309
1309
|
|
|
1310
|
-
// src/internal/instrumentation/vercel-ai/interrupt.ts
|
|
1311
|
-
import { trace as trace3 } from "@opentelemetry/api";
|
|
1312
|
-
var INNER_OPERATION_IDS = /* @__PURE__ */ new Set([
|
|
1313
|
-
"ai.generateText.doGenerate",
|
|
1314
|
-
"ai.streamText.doStream"
|
|
1315
|
-
]);
|
|
1316
|
-
function isLegacyModelCallSpan(span) {
|
|
1317
|
-
if (INNER_OPERATION_IDS.has(span.name)) {
|
|
1318
|
-
return true;
|
|
1319
|
-
}
|
|
1320
|
-
const opId = span.attributes["ai.operationId"];
|
|
1321
|
-
return typeof opId === "string" && INNER_OPERATION_IDS.has(opId);
|
|
1322
|
-
}
|
|
1323
|
-
function isGenAIModelCallSpan(span) {
|
|
1324
|
-
return span.instrumentationScope?.name === AI_SDK_OTEL_SCOPE && span.attributes["gen_ai.operation.name"] === "chat";
|
|
1325
|
-
}
|
|
1326
|
-
var MAX_PENDING_ENTRIES = 1024;
|
|
1327
|
-
var pendingByParentSpanId = /* @__PURE__ */ new Map();
|
|
1328
|
-
var needsApprovalToolNames = /* @__PURE__ */ new Set();
|
|
1329
|
-
var versionState = { sawActiveSpan: false };
|
|
1330
|
-
function setPending(parentSpanId, value) {
|
|
1331
|
-
pendingByParentSpanId.set(parentSpanId, value);
|
|
1332
|
-
evictOldest(pendingByParentSpanId);
|
|
1333
|
-
}
|
|
1334
|
-
function extractInterruptTools(tools) {
|
|
1335
|
-
if (!tools || typeof tools !== "object") {
|
|
1336
|
-
return [];
|
|
1337
|
-
}
|
|
1338
|
-
return Object.entries(tools).filter(
|
|
1339
|
-
([, t]) => !!t && typeof t === "object" && t.needsApproval
|
|
1340
|
-
).map(([name]) => name);
|
|
1341
|
-
}
|
|
1342
|
-
function parsePromptToolNames(raw) {
|
|
1343
|
-
if (!Array.isArray(raw)) {
|
|
1344
|
-
return null;
|
|
1345
|
-
}
|
|
1346
|
-
const names = [];
|
|
1347
|
-
for (const element of raw) {
|
|
1348
|
-
if (typeof element !== "string") {
|
|
1349
|
-
continue;
|
|
1350
|
-
}
|
|
1351
|
-
try {
|
|
1352
|
-
const parsed = JSON.parse(element);
|
|
1353
|
-
if (parsed && typeof parsed.name === "string") {
|
|
1354
|
-
names.push(parsed.name);
|
|
1355
|
-
}
|
|
1356
|
-
} catch {
|
|
1357
|
-
}
|
|
1358
|
-
}
|
|
1359
|
-
return names.length > 0 ? names : null;
|
|
1360
|
-
}
|
|
1361
|
-
var verdictsByToolCallId = /* @__PURE__ */ new Map();
|
|
1362
|
-
function recordVerdicts(messages) {
|
|
1363
|
-
if (!Array.isArray(messages)) {
|
|
1364
|
-
return;
|
|
1365
|
-
}
|
|
1366
|
-
const parts = messages.flatMap((message) => {
|
|
1367
|
-
const content = message?.content;
|
|
1368
|
-
return Array.isArray(content) ? content : [];
|
|
1369
|
-
});
|
|
1370
|
-
const askedOf = /* @__PURE__ */ new Map();
|
|
1371
|
-
for (const part of parts) {
|
|
1372
|
-
if (part?.type === "tool-approval-request" && part.isAutomatic !== true) {
|
|
1373
|
-
askedOf.set(part.approvalId, part.toolCallId);
|
|
1374
|
-
}
|
|
1375
|
-
}
|
|
1376
|
-
for (const part of parts) {
|
|
1377
|
-
const toolCallId = part?.type === "tool-approval-response" && askedOf.get(part.approvalId);
|
|
1378
|
-
if (typeof toolCallId === "string" && typeof part.approved === "boolean") {
|
|
1379
|
-
verdictsByToolCallId.set(toolCallId, part.approved);
|
|
1380
|
-
evictOldest(verdictsByToolCallId);
|
|
1381
|
-
}
|
|
1382
|
-
}
|
|
1383
|
-
}
|
|
1384
|
-
function verdictsForRequest(inputMessages) {
|
|
1385
|
-
if (typeof inputMessages !== "string" || verdictsByToolCallId.size === 0) {
|
|
1386
|
-
return void 0;
|
|
1387
|
-
}
|
|
1388
|
-
let messages;
|
|
1389
|
-
try {
|
|
1390
|
-
messages = JSON.parse(inputMessages);
|
|
1391
|
-
} catch {
|
|
1392
|
-
return void 0;
|
|
1393
|
-
}
|
|
1394
|
-
if (!Array.isArray(messages)) {
|
|
1395
|
-
return void 0;
|
|
1396
|
-
}
|
|
1397
|
-
const verdicts = {};
|
|
1398
|
-
for (const message of [...messages].reverse()) {
|
|
1399
|
-
const { role, parts } = message ?? {};
|
|
1400
|
-
if (role === "assistant" || role === "system") {
|
|
1401
|
-
break;
|
|
1402
|
-
}
|
|
1403
|
-
for (const part of Array.isArray(parts) ? parts : []) {
|
|
1404
|
-
const approved = part?.type === "tool_call_response" && typeof part.id === "string" ? verdictsByToolCallId.get(part.id) : void 0;
|
|
1405
|
-
if (approved !== void 0) {
|
|
1406
|
-
verdicts[part.id] = approved;
|
|
1407
|
-
}
|
|
1408
|
-
}
|
|
1409
|
-
}
|
|
1410
|
-
return Object.keys(verdicts).length > 0 ? JSON.stringify(verdicts) : void 0;
|
|
1411
|
-
}
|
|
1412
|
-
function evictOldest(map) {
|
|
1413
|
-
while (map.size > MAX_PENDING_ENTRIES) {
|
|
1414
|
-
const oldest = map.keys().next().value;
|
|
1415
|
-
if (oldest === void 0) {
|
|
1416
|
-
break;
|
|
1417
|
-
}
|
|
1418
|
-
map.delete(oldest);
|
|
1419
|
-
}
|
|
1420
|
-
}
|
|
1421
|
-
function createInterruptIntegration() {
|
|
1422
|
-
const onStart = (event) => {
|
|
1423
|
-
recordVerdicts(event.messages);
|
|
1424
|
-
for (const name of extractInterruptTools(event.tools)) {
|
|
1425
|
-
needsApprovalToolNames.add(name);
|
|
1426
|
-
}
|
|
1427
|
-
};
|
|
1428
|
-
const onStepStart = (event) => {
|
|
1429
|
-
const span = trace3.getActiveSpan();
|
|
1430
|
-
if (span) {
|
|
1431
|
-
versionState.sawActiveSpan = true;
|
|
1432
|
-
}
|
|
1433
|
-
const names = extractInterruptTools(event.tools);
|
|
1434
|
-
if (names.length === 0) {
|
|
1435
|
-
return;
|
|
1436
|
-
}
|
|
1437
|
-
for (const name of names) {
|
|
1438
|
-
needsApprovalToolNames.add(name);
|
|
1439
|
-
}
|
|
1440
|
-
if (!span) {
|
|
1441
|
-
return;
|
|
1442
|
-
}
|
|
1443
|
-
const value = JSON.stringify(names);
|
|
1444
|
-
span.setAttribute(INTERRUPT_TOOLS, value);
|
|
1445
|
-
setPending(span.spanContext().spanId, value);
|
|
1446
|
-
};
|
|
1447
|
-
return {
|
|
1448
|
-
onStart,
|
|
1449
|
-
onStepStart
|
|
1450
|
-
};
|
|
1451
|
-
}
|
|
1452
|
-
var InterruptPropagator = class {
|
|
1453
|
-
onStart(span, _parentContext) {
|
|
1454
|
-
if (isGenAIModelCallSpan(span)) {
|
|
1455
|
-
const verdicts = verdictsForRequest(span.attributes["gen_ai.input.messages"]);
|
|
1456
|
-
if (verdicts) {
|
|
1457
|
-
span.setAttribute(APPROVALS, verdicts);
|
|
1458
|
-
}
|
|
1459
|
-
return;
|
|
1460
|
-
}
|
|
1461
|
-
if (!isLegacyModelCallSpan(span)) {
|
|
1462
|
-
return;
|
|
1463
|
-
}
|
|
1464
|
-
const parentSpanId = span.parentSpanContext?.spanId;
|
|
1465
|
-
const stashed = parentSpanId && pendingByParentSpanId.get(parentSpanId);
|
|
1466
|
-
if (stashed) {
|
|
1467
|
-
span.setAttribute(INTERRUPT_TOOLS, stashed);
|
|
1468
|
-
pendingByParentSpanId.delete(parentSpanId);
|
|
1469
|
-
return;
|
|
1470
|
-
}
|
|
1471
|
-
if (versionState.sawActiveSpan || needsApprovalToolNames.size === 0) {
|
|
1472
|
-
return;
|
|
1473
|
-
}
|
|
1474
|
-
const scoped = parsePromptToolNames(span.attributes["ai.prompt.tools"]);
|
|
1475
|
-
const names = scoped === null ? [...needsApprovalToolNames] : scoped.filter((n) => needsApprovalToolNames.has(n));
|
|
1476
|
-
if (names.length > 0) {
|
|
1477
|
-
span.setAttribute(INTERRUPT_TOOLS, JSON.stringify(names));
|
|
1478
|
-
}
|
|
1479
|
-
}
|
|
1480
|
-
onEnd() {
|
|
1481
|
-
}
|
|
1482
|
-
async shutdown() {
|
|
1483
|
-
}
|
|
1484
|
-
async forceFlush() {
|
|
1485
|
-
}
|
|
1486
|
-
};
|
|
1487
|
-
|
|
1488
1310
|
// src/internal/log/logging.ts
|
|
1489
1311
|
import { SeverityNumber } from "@opentelemetry/api";
|
|
1490
1312
|
import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-http";
|
|
@@ -1764,10 +1586,13 @@ function compilePatternEntries(patternEntries) {
|
|
|
1764
1586
|
var compiledPatternCache = /* @__PURE__ */ new WeakMap();
|
|
1765
1587
|
function getCompiledPatternsForRule(rule) {
|
|
1766
1588
|
const key = rule.patterns;
|
|
1767
|
-
|
|
1768
|
-
|
|
1589
|
+
const cached = compiledPatternCache.get(key);
|
|
1590
|
+
if (cached) {
|
|
1591
|
+
return cached;
|
|
1769
1592
|
}
|
|
1770
|
-
const
|
|
1593
|
+
const entries = convertPatternsToPatternEntries(rule.patterns);
|
|
1594
|
+
const pattern = compilePatternEntries(entries);
|
|
1595
|
+
const compiled = { pattern, custom: pattern && compileCustomEntries(entries) };
|
|
1771
1596
|
compiledPatternCache.set(key, compiled);
|
|
1772
1597
|
return compiled;
|
|
1773
1598
|
}
|
|
@@ -1817,11 +1642,40 @@ function executeRegexWithTimeout(pattern, value, timeoutMs = 100) {
|
|
|
1817
1642
|
}
|
|
1818
1643
|
return matches;
|
|
1819
1644
|
}
|
|
1820
|
-
|
|
1645
|
+
var BUILTIN_ENTRIES = new Set(DEFAULT_PII_PATTERNS);
|
|
1646
|
+
function compileCustomEntries(patternEntries) {
|
|
1647
|
+
const groups = patternEntries.filter((entry) => !BUILTIN_ENTRIES.has(entry)).flatMap((entry) => {
|
|
1648
|
+
try {
|
|
1649
|
+
return [getGroupedPattern(entry)];
|
|
1650
|
+
} catch {
|
|
1651
|
+
return [];
|
|
1652
|
+
}
|
|
1653
|
+
});
|
|
1654
|
+
return groups.length > 0 ? new RegExp(groups.join("|")) : null;
|
|
1655
|
+
}
|
|
1656
|
+
function isDecimalPart(value, match) {
|
|
1657
|
+
const start = match.index;
|
|
1658
|
+
const end = start + match[0].length;
|
|
1659
|
+
if (!/^[0-9]+$/.test(match[0])) {
|
|
1660
|
+
return false;
|
|
1661
|
+
}
|
|
1662
|
+
const afterPoint = value.charAt(start - 1) === "." && /^[0-9]$/.test(value.charAt(start - 2));
|
|
1663
|
+
const beforePoint = value.charAt(end) === "." && /^[0-9]$/.test(value.charAt(end + 1));
|
|
1664
|
+
return afterPoint || beforePoint;
|
|
1665
|
+
}
|
|
1666
|
+
function overlapsAny(match, others) {
|
|
1667
|
+
const end = match.index + match[0].length;
|
|
1668
|
+
return others.some((other) => other.index < end && match.index < other.index + other[0].length);
|
|
1669
|
+
}
|
|
1670
|
+
function maskStringByPattern(value, pattern, mode = "full", custom = pattern) {
|
|
1821
1671
|
const matches = [];
|
|
1822
1672
|
try {
|
|
1823
1673
|
const regexMatches = executeRegexWithTimeout(pattern, value);
|
|
1674
|
+
const customMatches = custom && regexMatches.some((match) => isDecimalPart(value, match)) ? executeRegexWithTimeout(custom, value) : [];
|
|
1824
1675
|
for (const match of regexMatches) {
|
|
1676
|
+
if (isDecimalPart(value, match) && !overlapsAny(match, customMatches)) {
|
|
1677
|
+
continue;
|
|
1678
|
+
}
|
|
1825
1679
|
matches.push({
|
|
1826
1680
|
start: match.index,
|
|
1827
1681
|
end: match.index + match[0].length,
|
|
@@ -1865,11 +1719,11 @@ function maskStringByPatternBasedRule(value, rule) {
|
|
|
1865
1719
|
if (!patternEntries || patternEntries.length === 0) {
|
|
1866
1720
|
return mode === "partial" && value ? value.at(0) + "*****" : "*****";
|
|
1867
1721
|
}
|
|
1868
|
-
const
|
|
1869
|
-
if (!
|
|
1722
|
+
const { pattern, custom } = getCompiledPatternsForRule(rule);
|
|
1723
|
+
if (!pattern) {
|
|
1870
1724
|
return value;
|
|
1871
1725
|
}
|
|
1872
|
-
return maskStringByPattern(value,
|
|
1726
|
+
return maskStringByPattern(value, pattern, mode, custom);
|
|
1873
1727
|
}
|
|
1874
1728
|
function maskValue(value, rule) {
|
|
1875
1729
|
if (typeof value === "string") {
|
|
@@ -2286,6 +2140,184 @@ function getMetricsReader() {
|
|
|
2286
2140
|
return MetricsModule.getInstance().getMetricsReader();
|
|
2287
2141
|
}
|
|
2288
2142
|
|
|
2143
|
+
// src/internal/instrumentation/vercel-ai/interrupt.ts
|
|
2144
|
+
import { trace as trace3 } from "@opentelemetry/api";
|
|
2145
|
+
var INNER_OPERATION_IDS = /* @__PURE__ */ new Set([
|
|
2146
|
+
"ai.generateText.doGenerate",
|
|
2147
|
+
"ai.streamText.doStream"
|
|
2148
|
+
]);
|
|
2149
|
+
function isLegacyModelCallSpan(span) {
|
|
2150
|
+
if (INNER_OPERATION_IDS.has(span.name)) {
|
|
2151
|
+
return true;
|
|
2152
|
+
}
|
|
2153
|
+
const opId = span.attributes["ai.operationId"];
|
|
2154
|
+
return typeof opId === "string" && INNER_OPERATION_IDS.has(opId);
|
|
2155
|
+
}
|
|
2156
|
+
function isGenAIModelCallSpan(span) {
|
|
2157
|
+
return span.instrumentationScope?.name === AI_SDK_OTEL_SCOPE && span.attributes["gen_ai.operation.name"] === "chat";
|
|
2158
|
+
}
|
|
2159
|
+
var MAX_PENDING_ENTRIES = 1024;
|
|
2160
|
+
var pendingByParentSpanId = /* @__PURE__ */ new Map();
|
|
2161
|
+
var needsApprovalToolNames = /* @__PURE__ */ new Set();
|
|
2162
|
+
var versionState = { sawActiveSpan: false };
|
|
2163
|
+
function setPending(parentSpanId, value) {
|
|
2164
|
+
pendingByParentSpanId.set(parentSpanId, value);
|
|
2165
|
+
evictOldest(pendingByParentSpanId);
|
|
2166
|
+
}
|
|
2167
|
+
function extractInterruptTools(tools) {
|
|
2168
|
+
if (!tools || typeof tools !== "object") {
|
|
2169
|
+
return [];
|
|
2170
|
+
}
|
|
2171
|
+
return Object.entries(tools).filter(
|
|
2172
|
+
([, t]) => !!t && typeof t === "object" && t.needsApproval
|
|
2173
|
+
).map(([name]) => name);
|
|
2174
|
+
}
|
|
2175
|
+
function parsePromptToolNames(raw) {
|
|
2176
|
+
if (!Array.isArray(raw)) {
|
|
2177
|
+
return null;
|
|
2178
|
+
}
|
|
2179
|
+
const names = [];
|
|
2180
|
+
for (const element of raw) {
|
|
2181
|
+
if (typeof element !== "string") {
|
|
2182
|
+
continue;
|
|
2183
|
+
}
|
|
2184
|
+
try {
|
|
2185
|
+
const parsed = JSON.parse(element);
|
|
2186
|
+
if (parsed && typeof parsed.name === "string") {
|
|
2187
|
+
names.push(parsed.name);
|
|
2188
|
+
}
|
|
2189
|
+
} catch {
|
|
2190
|
+
}
|
|
2191
|
+
}
|
|
2192
|
+
return names.length > 0 ? names : null;
|
|
2193
|
+
}
|
|
2194
|
+
var verdictsByToolCallId = /* @__PURE__ */ new Map();
|
|
2195
|
+
function recordVerdicts(messages) {
|
|
2196
|
+
if (!Array.isArray(messages)) {
|
|
2197
|
+
return;
|
|
2198
|
+
}
|
|
2199
|
+
const parts = messages.flatMap((message) => {
|
|
2200
|
+
const content = message?.content;
|
|
2201
|
+
return Array.isArray(content) ? content : [];
|
|
2202
|
+
});
|
|
2203
|
+
const askedOf = /* @__PURE__ */ new Map();
|
|
2204
|
+
for (const part of parts) {
|
|
2205
|
+
if (part?.type === "tool-approval-request" && part.isAutomatic !== true) {
|
|
2206
|
+
askedOf.set(part.approvalId, part.toolCallId);
|
|
2207
|
+
}
|
|
2208
|
+
}
|
|
2209
|
+
for (const part of parts) {
|
|
2210
|
+
const toolCallId = part?.type === "tool-approval-response" && askedOf.get(part.approvalId);
|
|
2211
|
+
if (typeof toolCallId === "string" && typeof part.approved === "boolean") {
|
|
2212
|
+
verdictsByToolCallId.set(toolCallId, part.approved);
|
|
2213
|
+
evictOldest(verdictsByToolCallId);
|
|
2214
|
+
}
|
|
2215
|
+
}
|
|
2216
|
+
}
|
|
2217
|
+
function verdictsForRequest(inputMessages) {
|
|
2218
|
+
if (typeof inputMessages !== "string" || verdictsByToolCallId.size === 0) {
|
|
2219
|
+
return void 0;
|
|
2220
|
+
}
|
|
2221
|
+
let messages;
|
|
2222
|
+
try {
|
|
2223
|
+
messages = JSON.parse(inputMessages);
|
|
2224
|
+
} catch {
|
|
2225
|
+
return void 0;
|
|
2226
|
+
}
|
|
2227
|
+
if (!Array.isArray(messages)) {
|
|
2228
|
+
return void 0;
|
|
2229
|
+
}
|
|
2230
|
+
const verdicts = {};
|
|
2231
|
+
for (const message of [...messages].reverse()) {
|
|
2232
|
+
const { role, parts } = message ?? {};
|
|
2233
|
+
if (role === "assistant" || role === "system") {
|
|
2234
|
+
break;
|
|
2235
|
+
}
|
|
2236
|
+
for (const part of Array.isArray(parts) ? parts : []) {
|
|
2237
|
+
const approved = part?.type === "tool_call_response" && typeof part.id === "string" ? verdictsByToolCallId.get(part.id) : void 0;
|
|
2238
|
+
if (approved !== void 0) {
|
|
2239
|
+
verdicts[part.id] = approved;
|
|
2240
|
+
}
|
|
2241
|
+
}
|
|
2242
|
+
}
|
|
2243
|
+
return Object.keys(verdicts).length > 0 ? JSON.stringify(verdicts) : void 0;
|
|
2244
|
+
}
|
|
2245
|
+
function evictOldest(map) {
|
|
2246
|
+
while (map.size > MAX_PENDING_ENTRIES) {
|
|
2247
|
+
const oldest = map.keys().next().value;
|
|
2248
|
+
if (oldest === void 0) {
|
|
2249
|
+
break;
|
|
2250
|
+
}
|
|
2251
|
+
map.delete(oldest);
|
|
2252
|
+
}
|
|
2253
|
+
}
|
|
2254
|
+
function createInterruptIntegration() {
|
|
2255
|
+
const onStart = (event) => {
|
|
2256
|
+
recordVerdicts(event.messages);
|
|
2257
|
+
for (const name of extractInterruptTools(event.tools)) {
|
|
2258
|
+
needsApprovalToolNames.add(name);
|
|
2259
|
+
}
|
|
2260
|
+
};
|
|
2261
|
+
const onStepStart = (event) => {
|
|
2262
|
+
const span = trace3.getActiveSpan();
|
|
2263
|
+
if (span) {
|
|
2264
|
+
versionState.sawActiveSpan = true;
|
|
2265
|
+
}
|
|
2266
|
+
const names = extractInterruptTools(event.tools);
|
|
2267
|
+
if (names.length === 0) {
|
|
2268
|
+
return;
|
|
2269
|
+
}
|
|
2270
|
+
for (const name of names) {
|
|
2271
|
+
needsApprovalToolNames.add(name);
|
|
2272
|
+
}
|
|
2273
|
+
if (!span) {
|
|
2274
|
+
return;
|
|
2275
|
+
}
|
|
2276
|
+
const value = JSON.stringify(names);
|
|
2277
|
+
span.setAttribute(INTERRUPT_TOOLS, value);
|
|
2278
|
+
setPending(span.spanContext().spanId, value);
|
|
2279
|
+
};
|
|
2280
|
+
return {
|
|
2281
|
+
onStart,
|
|
2282
|
+
onStepStart
|
|
2283
|
+
};
|
|
2284
|
+
}
|
|
2285
|
+
var InterruptPropagator = class {
|
|
2286
|
+
onStart(span, _parentContext) {
|
|
2287
|
+
if (isGenAIModelCallSpan(span)) {
|
|
2288
|
+
const verdicts = verdictsForRequest(span.attributes["gen_ai.input.messages"]);
|
|
2289
|
+
if (verdicts) {
|
|
2290
|
+
span.setAttribute(APPROVALS, verdicts);
|
|
2291
|
+
}
|
|
2292
|
+
return;
|
|
2293
|
+
}
|
|
2294
|
+
if (!isLegacyModelCallSpan(span)) {
|
|
2295
|
+
return;
|
|
2296
|
+
}
|
|
2297
|
+
const parentSpanId = span.parentSpanContext?.spanId;
|
|
2298
|
+
const stashed = parentSpanId && pendingByParentSpanId.get(parentSpanId);
|
|
2299
|
+
if (stashed) {
|
|
2300
|
+
span.setAttribute(INTERRUPT_TOOLS, stashed);
|
|
2301
|
+
pendingByParentSpanId.delete(parentSpanId);
|
|
2302
|
+
return;
|
|
2303
|
+
}
|
|
2304
|
+
if (versionState.sawActiveSpan || needsApprovalToolNames.size === 0) {
|
|
2305
|
+
return;
|
|
2306
|
+
}
|
|
2307
|
+
const scoped = parsePromptToolNames(span.attributes["ai.prompt.tools"]);
|
|
2308
|
+
const names = scoped === null ? [...needsApprovalToolNames] : scoped.filter((n) => needsApprovalToolNames.has(n));
|
|
2309
|
+
if (names.length > 0) {
|
|
2310
|
+
span.setAttribute(INTERRUPT_TOOLS, JSON.stringify(names));
|
|
2311
|
+
}
|
|
2312
|
+
}
|
|
2313
|
+
onEnd() {
|
|
2314
|
+
}
|
|
2315
|
+
async shutdown() {
|
|
2316
|
+
}
|
|
2317
|
+
async forceFlush() {
|
|
2318
|
+
}
|
|
2319
|
+
};
|
|
2320
|
+
|
|
2289
2321
|
// src/internal/instrumentation/vercel-ai/model-call-end.ts
|
|
2290
2322
|
var NO_USAGE = {
|
|
2291
2323
|
inputTokens: void 0,
|
|
@@ -2633,6 +2665,7 @@ var LIBRARY_ID_ATTRIBUTES = [
|
|
|
2633
2665
|
];
|
|
2634
2666
|
var DEFAULT_RULE_ATTRIBUTES = String.raw`^(?!brizz\.(?!session\.(?:input|output)(?:\.context)?$|session\.title$|internal\.intent$)` + `|(?:${LIBRARY_ID_ATTRIBUTES.map((key) => key.replaceAll(".", String.raw`\.`)).join("|")})$)`;
|
|
2635
2667
|
var isText = (value) => typeof value === "string" || Array.isArray(value) && value.some((item) => typeof item === "string");
|
|
2668
|
+
var interrupts = new InterruptPropagator();
|
|
2636
2669
|
var DEFAULT_MASKING_RULES = [
|
|
2637
2670
|
{
|
|
2638
2671
|
mode: "partial",
|
|
@@ -2648,6 +2681,7 @@ var BrizzSimpleSpanProcessor = class extends SimpleSpanProcessor {
|
|
|
2648
2681
|
}
|
|
2649
2682
|
onStart(span, parentContext) {
|
|
2650
2683
|
applyContextAttributes(span);
|
|
2684
|
+
interrupts.onStart(span, parentContext);
|
|
2651
2685
|
super.onStart(span, parentContext);
|
|
2652
2686
|
}
|
|
2653
2687
|
onEnd(span) {
|
|
@@ -2667,6 +2701,7 @@ var BrizzBatchSpanProcessor = class extends BatchSpanProcessor {
|
|
|
2667
2701
|
}
|
|
2668
2702
|
onStart(span, parentContext) {
|
|
2669
2703
|
applyContextAttributes(span);
|
|
2704
|
+
interrupts.onStart(span, parentContext);
|
|
2670
2705
|
super.onStart(span, parentContext);
|
|
2671
2706
|
}
|
|
2672
2707
|
onEnd(span) {
|
|
@@ -3055,7 +3090,7 @@ var _Brizz = class __Brizz {
|
|
|
3055
3090
|
resourceAttributes["service.version"] = resolvedConfig.appVersion;
|
|
3056
3091
|
}
|
|
3057
3092
|
const resource = defaultResource().merge(detectResources({ detectors: [envDetector, hostDetector, processDetector] })).merge(resourceFromAttributes3(resourceAttributes));
|
|
3058
|
-
const spanProcessors = resolvedConfig.disableSpanExporter ? [] : [
|
|
3093
|
+
const spanProcessors = resolvedConfig.disableSpanExporter ? [] : [getSpanProcessor()];
|
|
3059
3094
|
if (resolvedConfig.setGlobalTracerProvider) {
|
|
3060
3095
|
this._tracerProvider = new SdkTracerProvider({ resource, spanProcessors });
|
|
3061
3096
|
this.registerGlobalTracerProvider(this._tracerProvider);
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
var
|
|
11
|
+
var _chunkDY3UL5K7cjs = require('./chunk-DY3UL5K7.cjs');
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
var _chunkIWSFMCHHcjs = require('./chunk-IWSFMCHH.cjs');
|
|
@@ -409,14 +409,14 @@ function wrapOnRequest(original, tracer) {
|
|
|
409
409
|
return original.apply(this, args);
|
|
410
410
|
}
|
|
411
411
|
const method = request.method;
|
|
412
|
-
if (method === METHOD_TOOLS_CALL &&
|
|
412
|
+
if (method === METHOD_TOOLS_CALL && _chunkDY3UL5K7cjs.isSessionToolCall.call(void 0, request)) {
|
|
413
413
|
return answerSessionToolCall(this, request, tracer, args, original);
|
|
414
414
|
}
|
|
415
415
|
const handler = _nullishCoalesce(handlers.get(method), () => ( this.fallbackRequestHandler));
|
|
416
416
|
if (!handler) {
|
|
417
417
|
return original.apply(this, args);
|
|
418
418
|
}
|
|
419
|
-
const tracking =
|
|
419
|
+
const tracking = _chunkDY3UL5K7cjs.isEnabled.call(void 0, ) && method === METHOD_TOOLS_CALL ? _chunkDY3UL5K7cjs.popTrackingArguments.call(void 0, request) : {};
|
|
420
420
|
const started = safeStartServerSpan(tracer, request, this, tracking);
|
|
421
421
|
if (!started) {
|
|
422
422
|
return original.apply(this, args);
|
|
@@ -426,9 +426,9 @@ function wrapOnRequest(original, tracer) {
|
|
|
426
426
|
if (method === METHOD_TOOLS_LIST) {
|
|
427
427
|
hooks.onResult = (result) => {
|
|
428
428
|
let advertised = result;
|
|
429
|
-
if (
|
|
429
|
+
if (_chunkDY3UL5K7cjs.isEnabled.call(void 0, )) {
|
|
430
430
|
try {
|
|
431
|
-
advertised =
|
|
431
|
+
advertised = _chunkDY3UL5K7cjs.patchListToolsResult.call(void 0, result);
|
|
432
432
|
} catch (error) {
|
|
433
433
|
_chunkC5OT6GAQcjs.logger.warn(
|
|
434
434
|
`Brizz MCP: failed to patch tools/list schemas: ${String(error)}`
|
|
@@ -439,7 +439,7 @@ function wrapOnRequest(original, tracer) {
|
|
|
439
439
|
try {
|
|
440
440
|
emitSchemaSpansFromListResponse(
|
|
441
441
|
advertised,
|
|
442
|
-
|
|
442
|
+
_chunkDY3UL5K7cjs.resolveTransportSessionId.call(void 0, this),
|
|
443
443
|
tracer
|
|
444
444
|
);
|
|
445
445
|
} catch (error) {
|
|
@@ -452,7 +452,7 @@ function wrapOnRequest(original, tracer) {
|
|
|
452
452
|
}
|
|
453
453
|
if (method !== METHOD_TOOLS_CALL) {
|
|
454
454
|
hooks.onError = () => {
|
|
455
|
-
|
|
455
|
+
_chunkDY3UL5K7cjs.stampAndPropagateSession.call(void 0, span, _chunkDY3UL5K7cjs.resolveSessionId.call(void 0, this, spanCtx), spanCtx);
|
|
456
456
|
};
|
|
457
457
|
}
|
|
458
458
|
const wrappedHandler = (req, extra) => _api.context.with(
|
|
@@ -486,7 +486,7 @@ function answerSessionToolCall(protocol, request, tracer, args, original) {
|
|
|
486
486
|
if (!handlers) {
|
|
487
487
|
return original.apply(protocol, args);
|
|
488
488
|
}
|
|
489
|
-
const { id, result } =
|
|
489
|
+
const { id, result } = _chunkDY3UL5K7cjs.sessionToolResult.call(void 0, );
|
|
490
490
|
const started = safeStartServerSpan(tracer, request, protocol, { sessionId: id });
|
|
491
491
|
const handler = () => started ? _api.context.with(started.spanCtx, () => result) : result;
|
|
492
492
|
const hadEntry = handlers.has(METHOD_TOOLS_CALL);
|
|
@@ -576,8 +576,8 @@ function safeStartServerSpan(tracer, request, protocol, tracking = {}) {
|
|
|
576
576
|
parentCtx
|
|
577
577
|
);
|
|
578
578
|
applyServerRequestAttributes(span, request, protocol);
|
|
579
|
-
const resolved = request.method === METHOD_TOOLS_CALL ? _nullishCoalesce(tracking.sessionId, () => (
|
|
580
|
-
const { context: sessCtx } =
|
|
579
|
+
const resolved = request.method === METHOD_TOOLS_CALL ? _nullishCoalesce(tracking.sessionId, () => ( _chunkDY3UL5K7cjs.resolveSessionId.call(void 0, protocol, parentCtx))) : void 0;
|
|
580
|
+
const { context: sessCtx } = _chunkDY3UL5K7cjs.stampAndPropagateSession.call(void 0,
|
|
581
581
|
span,
|
|
582
582
|
resolved,
|
|
583
583
|
parentCtx,
|
|
@@ -633,7 +633,7 @@ function safeEnd(span) {
|
|
|
633
633
|
|
|
634
634
|
// src/internal/instrumentation/mcp/version.ts
|
|
635
635
|
var INSTRUMENTATION_NAME = "@brizz/sdk/mcp";
|
|
636
|
-
var INSTRUMENTATION_VERSION =
|
|
636
|
+
var INSTRUMENTATION_VERSION = _chunkDY3UL5K7cjs.getSDKVersion.call(void 0, );
|
|
637
637
|
|
|
638
638
|
// src/internal/instrumentation/mcp/instrumentation.ts
|
|
639
639
|
var PROTOCOL_MODULE_NAME = "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IAttributesMaskingRule, IPatternBasedMaskingRule } from './types.js';
|
|
2
|
-
export declare function maskStringByPattern(value: string, pattern: RegExp, mode?: 'partial' | 'full'): string;
|
|
2
|
+
export declare function maskStringByPattern(value: string, pattern: RegExp, mode?: 'partial' | 'full', custom?: RegExp | null): string;
|
|
3
3
|
export declare function maskStringByPatternBasedRule(value: string, rule: IPatternBasedMaskingRule): string;
|
|
4
4
|
export declare function maskValue(value: unknown, rule: IPatternBasedMaskingRule): unknown;
|
|
5
5
|
export declare function maskAttributes(attributes: Record<string, unknown>, rules: readonly IAttributesMaskingRule[], outputOriginalValue?: boolean): Record<string, unknown>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IAttributesMaskingRule, IPatternBasedMaskingRule } from './types.js';
|
|
2
|
-
export declare function maskStringByPattern(value: string, pattern: RegExp, mode?: 'partial' | 'full'): string;
|
|
2
|
+
export declare function maskStringByPattern(value: string, pattern: RegExp, mode?: 'partial' | 'full', custom?: RegExp | null): string;
|
|
3
3
|
export declare function maskStringByPatternBasedRule(value: string, rule: IPatternBasedMaskingRule): string;
|
|
4
4
|
export declare function maskValue(value: unknown, rule: IPatternBasedMaskingRule): unknown;
|
|
5
5
|
export declare function maskAttributes(attributes: Record<string, unknown>, rules: readonly IAttributesMaskingRule[], outputOriginalValue?: boolean): Record<string, unknown>;
|