@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.cjs
CHANGED
|
@@ -43,7 +43,7 @@ var _chunkUF4GMVEYcjs = require('./chunk-UF4GMVEY.cjs');
|
|
|
43
43
|
|
|
44
44
|
|
|
45
45
|
|
|
46
|
-
var
|
|
46
|
+
var _chunkDY3UL5K7cjs = require('./chunk-DY3UL5K7.cjs');
|
|
47
47
|
|
|
48
48
|
|
|
49
49
|
|
|
@@ -110,7 +110,7 @@ var _api = require('@opentelemetry/api');
|
|
|
110
110
|
|
|
111
111
|
// src/internal/instrumentation/langgraph/attributes.ts
|
|
112
112
|
var INSTRUMENTATION_NAME = "@brizz/sdk/langgraph";
|
|
113
|
-
var INSTRUMENTATION_VERSION =
|
|
113
|
+
var INSTRUMENTATION_VERSION = _chunkDY3UL5K7cjs.getSDKVersion.call(void 0, );
|
|
114
114
|
var MODULE_NAME = "@langchain/langgraph";
|
|
115
115
|
var SUPPORTED_VERSIONS = [">=0.2.0 <2"];
|
|
116
116
|
function isSupportedVersion(version) {
|
|
@@ -481,7 +481,7 @@ var ATTR_ANSWERS = "typesafe.answers";
|
|
|
481
481
|
var PATCHED_FLAG2 = /* @__PURE__ */ Symbol.for("brizz.typesafe.patched");
|
|
482
482
|
var TypeSafeInstrumentation = class extends _instrumentation.InstrumentationBase {
|
|
483
483
|
constructor(config = {}) {
|
|
484
|
-
super(INSTRUMENTATION_NAME2,
|
|
484
|
+
super(INSTRUMENTATION_NAME2, _chunkDY3UL5K7cjs.getSDKVersion.call(void 0, ), config);
|
|
485
485
|
this.setTracerProvider(_chunkDC2MFO65cjs.brizzTracerProvider);
|
|
486
486
|
}
|
|
487
487
|
init() {
|
|
@@ -708,7 +708,7 @@ function loadGenAIInstrumentations() {
|
|
|
708
708
|
function loadMCPInstrumentation() {
|
|
709
709
|
void (async () => {
|
|
710
710
|
try {
|
|
711
|
-
const { MCPInstrumentation } = await Promise.resolve().then(() => _interopRequireWildcard(require("./mcp-
|
|
711
|
+
const { MCPInstrumentation } = await Promise.resolve().then(() => _interopRequireWildcard(require("./mcp-QPMPVJZD.cjs")));
|
|
712
712
|
const mcp = new MCPInstrumentation({ exceptionLogger });
|
|
713
713
|
_instrumentation.registerInstrumentations.call(void 0, { instrumentations: [mcp], tracerProvider: _chunkDC2MFO65cjs.brizzTracerProvider });
|
|
714
714
|
_chunkC5OT6GAQcjs.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 Promise.resolve().then(() => _interopRequireWildcard(require("./google-genai-
|
|
764
|
+
const { GoogleGenAIInstrumentation } = await Promise.resolve().then(() => _interopRequireWildcard(require("./google-genai-KDEYFHTK.cjs")));
|
|
765
765
|
const googleGenAI = new GoogleGenAIInstrumentation({ exceptionLogger });
|
|
766
766
|
_instrumentation.registerInstrumentations.call(void 0, {
|
|
767
767
|
instrumentations: [googleGenAI],
|
|
@@ -1256,7 +1256,7 @@ var InstrumentationRegistry = (_class = class _InstrumentationRegistry {construc
|
|
|
1256
1256
|
const genaiModule = this.manualModules.google_genai;
|
|
1257
1257
|
void (async () => {
|
|
1258
1258
|
try {
|
|
1259
|
-
const { GoogleGenAIInstrumentation } = await Promise.resolve().then(() => _interopRequireWildcard(require("./google-genai-
|
|
1259
|
+
const { GoogleGenAIInstrumentation } = await Promise.resolve().then(() => _interopRequireWildcard(require("./google-genai-KDEYFHTK.cjs")));
|
|
1260
1260
|
const genaiInst = new GoogleGenAIInstrumentation({ exceptionLogger: exceptionLogger2 });
|
|
1261
1261
|
genaiInst.manuallyInstrument(genaiModule);
|
|
1262
1262
|
_chunkC5OT6GAQcjs.logger.debug("Manual instrumentation enabled for Google GenAI");
|
|
@@ -1271,7 +1271,7 @@ var InstrumentationRegistry = (_class = class _InstrumentationRegistry {construc
|
|
|
1271
1271
|
const mcpModules = this.manualModules.mcp;
|
|
1272
1272
|
void (async () => {
|
|
1273
1273
|
try {
|
|
1274
|
-
const { MCPInstrumentation } = await Promise.resolve().then(() => _interopRequireWildcard(require("./mcp-
|
|
1274
|
+
const { MCPInstrumentation } = await Promise.resolve().then(() => _interopRequireWildcard(require("./mcp-QPMPVJZD.cjs")));
|
|
1275
1275
|
const instrumentation = new MCPInstrumentation({ exceptionLogger: exceptionLogger2 });
|
|
1276
1276
|
instrumentation.manuallyInstrument(mcpModules);
|
|
1277
1277
|
_chunkC5OT6GAQcjs.logger.debug("Manual instrumentation enabled for MCP");
|
|
@@ -1307,184 +1307,6 @@ var InstrumentationRegistry = (_class = class _InstrumentationRegistry {construc
|
|
|
1307
1307
|
}
|
|
1308
1308
|
}, _class);
|
|
1309
1309
|
|
|
1310
|
-
// src/internal/instrumentation/vercel-ai/interrupt.ts
|
|
1311
|
-
|
|
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 _optionalChain([span, 'access', _70 => _70.instrumentationScope, 'optionalAccess', _71 => _71.name]) === _chunkIWSFMCHHcjs.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 (e4) {
|
|
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 = _optionalChain([message, 'optionalAccess', _72 => _72.content]);
|
|
1368
|
-
return Array.isArray(content) ? content : [];
|
|
1369
|
-
});
|
|
1370
|
-
const askedOf = /* @__PURE__ */ new Map();
|
|
1371
|
-
for (const part of parts) {
|
|
1372
|
-
if (_optionalChain([part, 'optionalAccess', _73 => _73.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 = _optionalChain([part, 'optionalAccess', _74 => _74.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 (e5) {
|
|
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 } = _nullishCoalesce(message, () => ( {}));
|
|
1400
|
-
if (role === "assistant" || role === "system") {
|
|
1401
|
-
break;
|
|
1402
|
-
}
|
|
1403
|
-
for (const part of Array.isArray(parts) ? parts : []) {
|
|
1404
|
-
const approved = _optionalChain([part, 'optionalAccess', _75 => _75.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 = _api.trace.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(_chunkIWSFMCHHcjs.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(_chunkIWSFMCHHcjs.APPROVALS, verdicts);
|
|
1458
|
-
}
|
|
1459
|
-
return;
|
|
1460
|
-
}
|
|
1461
|
-
if (!isLegacyModelCallSpan(span)) {
|
|
1462
|
-
return;
|
|
1463
|
-
}
|
|
1464
|
-
const parentSpanId = _optionalChain([span, 'access', _76 => _76.parentSpanContext, 'optionalAccess', _77 => _77.spanId]);
|
|
1465
|
-
const stashed = parentSpanId && pendingByParentSpanId.get(parentSpanId);
|
|
1466
|
-
if (stashed) {
|
|
1467
|
-
span.setAttribute(_chunkIWSFMCHHcjs.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(_chunkIWSFMCHHcjs.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
|
|
|
1490
1312
|
var _exporterlogsotlphttp = require('@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 (e4) {
|
|
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") {
|
|
@@ -1928,7 +1782,7 @@ var BrizzSimpleLogRecordProcessor = class extends _sdklogs.SimpleLogRecordProces
|
|
|
1928
1782
|
this.config = config;
|
|
1929
1783
|
}
|
|
1930
1784
|
onEmit(logRecord) {
|
|
1931
|
-
const maskingConfig = _optionalChain([this, 'access',
|
|
1785
|
+
const maskingConfig = _optionalChain([this, 'access', _70 => _70.config, 'access', _71 => _71.masking, 'optionalAccess', _72 => _72.eventMasking]);
|
|
1932
1786
|
if (maskingConfig) {
|
|
1933
1787
|
maskLog(logRecord, maskingConfig);
|
|
1934
1788
|
}
|
|
@@ -1948,7 +1802,7 @@ var BrizzBatchLogRecordProcessor = class extends _sdklogs.BatchLogRecordProcesso
|
|
|
1948
1802
|
this.config = config;
|
|
1949
1803
|
}
|
|
1950
1804
|
onEmit(logRecord) {
|
|
1951
|
-
const maskingConfig = _optionalChain([this, 'access',
|
|
1805
|
+
const maskingConfig = _optionalChain([this, 'access', _73 => _73.config, 'access', _74 => _74.masking, 'optionalAccess', _75 => _75.eventMasking]);
|
|
1952
1806
|
if (maskingConfig) {
|
|
1953
1807
|
maskLog(logRecord, maskingConfig);
|
|
1954
1808
|
}
|
|
@@ -2049,14 +1903,14 @@ var LoggingModule = (_class2 = class _LoggingModule {constructor() { _class2.pro
|
|
|
2049
1903
|
_chunkC5OT6GAQcjs.logger.debug("Creating logger provider", {
|
|
2050
1904
|
serviceName,
|
|
2051
1905
|
disableBatch: config.disableBatch,
|
|
2052
|
-
hasMasking: !!_optionalChain([config, 'access',
|
|
1906
|
+
hasMasking: !!_optionalChain([config, 'access', _76 => _76.masking, 'optionalAccess', _77 => _77.eventMasking])
|
|
2053
1907
|
});
|
|
2054
1908
|
const exporter = this.createLogExporter(config, serviceName);
|
|
2055
1909
|
const processor = config.disableBatch ? new BrizzSimpleLogRecordProcessor(exporter, config) : new BrizzBatchLogRecordProcessor(exporter, config);
|
|
2056
1910
|
const resourceAttributes = {
|
|
2057
1911
|
...config.resourceAttributes,
|
|
2058
1912
|
"service.name": serviceName,
|
|
2059
|
-
[BRIZZ_SDK_VERSION]:
|
|
1913
|
+
[BRIZZ_SDK_VERSION]: _chunkDY3UL5K7cjs.getSDKVersion.call(void 0, ),
|
|
2060
1914
|
[BRIZZ_SDK_LANGUAGE]: SDK_LANGUAGE
|
|
2061
1915
|
};
|
|
2062
1916
|
if (config.environment) {
|
|
@@ -2158,7 +2012,7 @@ var LoggingModule = (_class2 = class _LoggingModule {constructor() { _class2.pro
|
|
|
2158
2012
|
}
|
|
2159
2013
|
async forceFlush() {
|
|
2160
2014
|
await Promise.all(
|
|
2161
|
-
[...this.scopedProviders.values(), this.loggerProvider].map(async (p) => _optionalChain([p, 'optionalAccess',
|
|
2015
|
+
[...this.scopedProviders.values(), this.loggerProvider].map(async (p) => _optionalChain([p, 'optionalAccess', _78 => _78.forceFlush, 'call', _79 => _79()]))
|
|
2162
2016
|
);
|
|
2163
2017
|
}
|
|
2164
2018
|
/**
|
|
@@ -2264,7 +2118,7 @@ var MetricsModule = (_class3 = class _MetricsModule {constructor() { _class3.pro
|
|
|
2264
2118
|
return this.metricsReader;
|
|
2265
2119
|
}
|
|
2266
2120
|
async forceFlush() {
|
|
2267
|
-
await _optionalChain([this, 'access',
|
|
2121
|
+
await _optionalChain([this, 'access', _80 => _80.metricsReader, 'optionalAccess', _81 => _81.forceFlush, 'call', _82 => _82()]);
|
|
2268
2122
|
}
|
|
2269
2123
|
/**
|
|
2270
2124
|
* Shutdown the metrics module
|
|
@@ -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
|
+
|
|
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 _optionalChain([span, 'access', _83 => _83.instrumentationScope, 'optionalAccess', _84 => _84.name]) === _chunkIWSFMCHHcjs.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 (e5) {
|
|
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 = _optionalChain([message, 'optionalAccess', _85 => _85.content]);
|
|
2201
|
+
return Array.isArray(content) ? content : [];
|
|
2202
|
+
});
|
|
2203
|
+
const askedOf = /* @__PURE__ */ new Map();
|
|
2204
|
+
for (const part of parts) {
|
|
2205
|
+
if (_optionalChain([part, 'optionalAccess', _86 => _86.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 = _optionalChain([part, 'optionalAccess', _87 => _87.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 (e6) {
|
|
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 } = _nullishCoalesce(message, () => ( {}));
|
|
2233
|
+
if (role === "assistant" || role === "system") {
|
|
2234
|
+
break;
|
|
2235
|
+
}
|
|
2236
|
+
for (const part of Array.isArray(parts) ? parts : []) {
|
|
2237
|
+
const approved = _optionalChain([part, 'optionalAccess', _88 => _88.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 = _api.trace.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(_chunkIWSFMCHHcjs.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(_chunkIWSFMCHHcjs.APPROVALS, verdicts);
|
|
2291
|
+
}
|
|
2292
|
+
return;
|
|
2293
|
+
}
|
|
2294
|
+
if (!isLegacyModelCallSpan(span)) {
|
|
2295
|
+
return;
|
|
2296
|
+
}
|
|
2297
|
+
const parentSpanId = _optionalChain([span, 'access', _89 => _89.parentSpanContext, 'optionalAccess', _90 => _90.spanId]);
|
|
2298
|
+
const stashed = parentSpanId && pendingByParentSpanId.get(parentSpanId);
|
|
2299
|
+
if (stashed) {
|
|
2300
|
+
span.setAttribute(_chunkIWSFMCHHcjs.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(_chunkIWSFMCHHcjs.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,
|
|
@@ -2437,7 +2469,7 @@ function createCollector(OpenTelemetry) {
|
|
|
2437
2469
|
providerMetadata: true
|
|
2438
2470
|
})
|
|
2439
2471
|
);
|
|
2440
|
-
} catch (
|
|
2472
|
+
} catch (e7) {
|
|
2441
2473
|
return void 0;
|
|
2442
2474
|
}
|
|
2443
2475
|
}
|
|
@@ -2466,7 +2498,7 @@ var BrizzSpanExporter = (_class4 = class {
|
|
|
2466
2498
|
const resourceAttrs = {
|
|
2467
2499
|
...config.resourceAttributes,
|
|
2468
2500
|
"service.name": config.appName,
|
|
2469
|
-
[BRIZZ_SDK_VERSION]:
|
|
2501
|
+
[BRIZZ_SDK_VERSION]: _chunkDY3UL5K7cjs.getSDKVersion.call(void 0, ),
|
|
2470
2502
|
[BRIZZ_SDK_LANGUAGE]: SDK_LANGUAGE
|
|
2471
2503
|
};
|
|
2472
2504
|
if (config.environment) {
|
|
@@ -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 _sdktrace.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 _sdktrace.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) {
|
|
@@ -2830,7 +2865,7 @@ function getSpanProcessor() {
|
|
|
2830
2865
|
// src/internal/trace/decision-call.ts
|
|
2831
2866
|
|
|
2832
2867
|
|
|
2833
|
-
var tracer = _chunkDC2MFO65cjs.brizzTracerProvider.getTracer("@brizz/sdk/decision-call",
|
|
2868
|
+
var tracer = _chunkDC2MFO65cjs.brizzTracerProvider.getTracer("@brizz/sdk/decision-call", _chunkDY3UL5K7cjs.getSDKVersion.call(void 0, ));
|
|
2834
2869
|
function decisionCall(options, callback) {
|
|
2835
2870
|
const span = startDecisionSpan(options);
|
|
2836
2871
|
if (!span) {
|
|
@@ -3010,7 +3045,7 @@ var _Brizz = (_class6 = class __Brizz {constructor() { _class6.prototype.__init1
|
|
|
3010
3045
|
*/
|
|
3011
3046
|
setupInstrumentation(options) {
|
|
3012
3047
|
const registry = InstrumentationRegistry.getInstance();
|
|
3013
|
-
|
|
3048
|
+
_chunkDY3UL5K7cjs.configure.call(void 0, resolveMcpSessionTracking(options.mcpSessionTracking));
|
|
3014
3049
|
patchInstalledCallbackManager();
|
|
3015
3050
|
patchInstalledLangGraph();
|
|
3016
3051
|
patchInstalledTypeSafe();
|
|
@@ -3045,7 +3080,7 @@ var _Brizz = (_class6 = class __Brizz {constructor() { _class6.prototype.__init1
|
|
|
3045
3080
|
const resourceAttributes = {
|
|
3046
3081
|
...resolvedConfig.resourceAttributes,
|
|
3047
3082
|
"service.name": resolvedConfig.appName,
|
|
3048
|
-
[BRIZZ_SDK_VERSION]:
|
|
3083
|
+
[BRIZZ_SDK_VERSION]: _chunkDY3UL5K7cjs.getSDKVersion.call(void 0, ),
|
|
3049
3084
|
[BRIZZ_SDK_LANGUAGE]: SDK_LANGUAGE
|
|
3050
3085
|
};
|
|
3051
3086
|
if (resolvedConfig.environment) {
|
|
@@ -3055,7 +3090,7 @@ var _Brizz = (_class6 = class __Brizz {constructor() { _class6.prototype.__init1
|
|
|
3055
3090
|
resourceAttributes["service.version"] = resolvedConfig.appVersion;
|
|
3056
3091
|
}
|
|
3057
3092
|
const resource = _resources2.defaultResource.call(void 0, ).merge(_resources2.detectResources.call(void 0, { detectors: [_resources2.envDetector, _resources2.hostDetector, _resources2.processDetector] })).merge(_resources2.resourceFromAttributes.call(void 0, resourceAttributes));
|
|
3058
|
-
const spanProcessors = resolvedConfig.disableSpanExporter ? [] : [
|
|
3093
|
+
const spanProcessors = resolvedConfig.disableSpanExporter ? [] : [getSpanProcessor()];
|
|
3059
3094
|
if (resolvedConfig.setGlobalTracerProvider) {
|
|
3060
3095
|
this._tracerProvider = new (0, _sdktrace.TracerProvider)({ resource, spanProcessors });
|
|
3061
3096
|
this.registerGlobalTracerProvider(this._tracerProvider);
|
|
@@ -3155,19 +3190,19 @@ var _Brizz = (_class6 = class __Brizz {constructor() { _class6.prototype.__init1
|
|
|
3155
3190
|
try {
|
|
3156
3191
|
const tracingModule = TracingModule.getInstance();
|
|
3157
3192
|
await tracingModule.shutdown();
|
|
3158
|
-
} catch (
|
|
3193
|
+
} catch (e8) {
|
|
3159
3194
|
_chunkC5OT6GAQcjs.logger.debug("Tracing module already shut down or not initialized");
|
|
3160
3195
|
}
|
|
3161
3196
|
try {
|
|
3162
3197
|
const metricsModule = MetricsModule.getInstance();
|
|
3163
3198
|
metricsModule.shutdown();
|
|
3164
|
-
} catch (
|
|
3199
|
+
} catch (e9) {
|
|
3165
3200
|
_chunkC5OT6GAQcjs.logger.debug("Metrics module already shut down or not initialized");
|
|
3166
3201
|
}
|
|
3167
3202
|
try {
|
|
3168
3203
|
const loggingModule = LoggingModule.getInstance();
|
|
3169
3204
|
await loggingModule.shutdown();
|
|
3170
|
-
} catch (
|
|
3205
|
+
} catch (e10) {
|
|
3171
3206
|
_chunkC5OT6GAQcjs.logger.debug("Logging module already shut down or not initialized");
|
|
3172
3207
|
}
|
|
3173
3208
|
_chunkC5OT6GAQcjs.logger.info("All telemetry modules shut down successfully");
|