@brizz/sdk 0.1.57 → 0.1.59

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.
Files changed (43) hide show
  1. package/README.md +52 -3
  2. package/dist/chunk-4QNEI7VZ.cjs +984 -0
  3. package/dist/{chunk-DCXOK7PX.cjs → chunk-5QZM5EVP.cjs} +8 -8
  4. package/dist/{chunk-O2IBZJOJ.cjs → chunk-6QXPHZEO.cjs} +4 -4
  5. package/dist/chunk-EZCNPWKM.js +984 -0
  6. package/dist/{chunk-7PRTTYWM.js → chunk-GABRGNAU.js} +1 -1
  7. package/dist/{chunk-GUKWVI53.js → chunk-GISL4K6Z.js} +27 -1
  8. package/dist/{chunk-RV7JIIDG.cjs → chunk-NF52RMLW.cjs} +27 -1
  9. package/dist/{chunk-42KYS2LU.js → chunk-ZGX52S4U.js} +2 -2
  10. package/dist/index.cjs +280 -966
  11. package/dist/index.js +238 -924
  12. package/dist/interrupt-36U5562Z.cjs +12 -0
  13. package/dist/{interrupt-UKJK5WOA.js → interrupt-6BSXUK3O.js} +2 -2
  14. package/dist/{mcp-FBTQYIOL.js → mcp-TTECBPGZ.js} +4 -3
  15. package/dist/{mcp-WHXEBLRI.cjs → mcp-UPBKSTB7.cjs} +19 -18
  16. package/dist/session.cjs +78 -0
  17. package/dist/session.js +78 -0
  18. package/dist/types/cjs/index.d.ts +2 -2
  19. package/dist/types/cjs/internal/error-type.d.ts +1 -0
  20. package/dist/types/cjs/internal/instrumentation/mcp/semantic-conventions.d.ts +1 -1
  21. package/dist/types/cjs/internal/instrumentation/typesafe.d.ts +0 -8
  22. package/dist/types/cjs/internal/log/emit.d.ts +8 -0
  23. package/dist/types/cjs/internal/log/logging.d.ts +2 -2
  24. package/dist/types/cjs/internal/semantic-conventions.d.ts +13 -0
  25. package/dist/types/cjs/internal/serialization.d.ts +2 -0
  26. package/dist/types/cjs/internal/trace/decision-call.d.ts +24 -0
  27. package/dist/types/cjs/internal/trace/index.d.ts +2 -0
  28. package/dist/types/cjs/internal/trace/session.d.ts +2 -1
  29. package/dist/types/cjs/session.d.ts +6 -0
  30. package/dist/types/esm/index.d.ts +2 -2
  31. package/dist/types/esm/internal/error-type.d.ts +1 -0
  32. package/dist/types/esm/internal/instrumentation/mcp/semantic-conventions.d.ts +1 -1
  33. package/dist/types/esm/internal/instrumentation/typesafe.d.ts +0 -8
  34. package/dist/types/esm/internal/log/emit.d.ts +8 -0
  35. package/dist/types/esm/internal/log/logging.d.ts +2 -2
  36. package/dist/types/esm/internal/semantic-conventions.d.ts +13 -0
  37. package/dist/types/esm/internal/serialization.d.ts +2 -0
  38. package/dist/types/esm/internal/trace/decision-call.d.ts +24 -0
  39. package/dist/types/esm/internal/trace/index.d.ts +2 -0
  40. package/dist/types/esm/internal/trace/session.d.ts +2 -1
  41. package/dist/types/esm/session.d.ts +6 -0
  42. package/package.json +29 -18
  43. package/dist/interrupt-BYLSBXTV.cjs +0 -12
package/dist/index.cjs CHANGED
@@ -1,11 +1,10 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6;
2
2
 
3
3
 
4
4
  var _chunkUNLNNKZ7cjs = require('./chunk-UNLNNKZ7.cjs');
5
5
 
6
6
 
7
7
 
8
- var _chunkDCXOK7PXcjs = require('./chunk-DCXOK7PX.cjs');
9
8
 
10
9
 
11
10
 
@@ -15,18 +14,13 @@ var _chunkDCXOK7PXcjs = require('./chunk-DCXOK7PX.cjs');
15
14
 
16
15
 
17
16
 
18
- var _chunkDC2MFO65cjs = require('./chunk-DC2MFO65.cjs');
19
-
20
-
21
17
 
22
18
 
23
19
 
24
20
 
25
21
 
26
- var _chunkWC573FCIcjs = require('./chunk-WC573FCI.cjs');
27
22
 
28
23
 
29
- var _chunkO2IBZJOJcjs = require('./chunk-O2IBZJOJ.cjs');
30
24
 
31
25
 
32
26
 
@@ -45,9 +39,11 @@ var _chunkO2IBZJOJcjs = require('./chunk-O2IBZJOJ.cjs');
45
39
 
46
40
 
47
41
 
42
+ var _chunk4QNEI7VZcjs = require('./chunk-4QNEI7VZ.cjs');
48
43
 
49
44
 
50
45
 
46
+ var _chunk5QZM5EVPcjs = require('./chunk-5QZM5EVP.cjs');
51
47
 
52
48
 
53
49
 
@@ -55,6 +51,7 @@ var _chunkO2IBZJOJcjs = require('./chunk-O2IBZJOJ.cjs');
55
51
 
56
52
 
57
53
 
54
+ var _chunkDC2MFO65cjs = require('./chunk-DC2MFO65.cjs');
58
55
 
59
56
 
60
57
 
@@ -62,8 +59,10 @@ var _chunkO2IBZJOJcjs = require('./chunk-O2IBZJOJ.cjs');
62
59
 
63
60
 
64
61
 
62
+ var _chunkWC573FCIcjs = require('./chunk-WC573FCI.cjs');
65
63
 
66
64
 
65
+ var _chunk6QXPHZEOcjs = require('./chunk-6QXPHZEO.cjs');
67
66
 
68
67
 
69
68
 
@@ -87,7 +86,7 @@ var _chunkO2IBZJOJcjs = require('./chunk-O2IBZJOJ.cjs');
87
86
 
88
87
 
89
88
 
90
- var _chunkRV7JIIDGcjs = require('./chunk-RV7JIIDG.cjs');
89
+ var _chunkNF52RMLWcjs = require('./chunk-NF52RMLW.cjs');
91
90
 
92
91
 
93
92
  var _chunkOBGZSXTJcjs = require('./chunk-OBGZSXTJ.cjs');
@@ -113,7 +112,7 @@ var _api = require('@opentelemetry/api');
113
112
 
114
113
  // src/internal/instrumentation/langgraph/attributes.ts
115
114
  var INSTRUMENTATION_NAME = "@brizz/sdk/langgraph";
116
- var INSTRUMENTATION_VERSION = _chunkDCXOK7PXcjs.getSDKVersion.call(void 0, );
115
+ var INSTRUMENTATION_VERSION = _chunk5QZM5EVPcjs.getSDKVersion.call(void 0, );
117
116
  var MODULE_NAME = "@langchain/langgraph";
118
117
  var SUPPORTED_VERSIONS = [">=0.2.0 <2"];
119
118
  function isSupportedVersion(version) {
@@ -451,25 +450,40 @@ var BrizzOpenAIInstrumentation = class extends _openinferenceinstrumentationopen
451
450
 
452
451
 
453
452
 
453
+
454
+ // src/internal/error-type.ts
455
+ function errorType(error) {
456
+ if (!(error instanceof Error)) {
457
+ return "_OTHER";
458
+ }
459
+ return _optionalChain([error, 'access', _19 => _19.constructor, 'optionalAccess', _20 => _20.name]) || error.name || "_OTHER";
460
+ }
461
+
462
+ // src/internal/serialization.ts
463
+ function toJson(value) {
464
+ try {
465
+ return JSON.stringify(value);
466
+ } catch (error) {
467
+ _chunkWC573FCIcjs.logger.debug(`Brizz: value is not JSON-serializable: ${String(error)}`);
468
+ return void 0;
469
+ }
470
+ }
471
+ function text(value) {
472
+ return typeof value === "string" ? value : _nullishCoalesce(toJson(value), () => ( ""));
473
+ }
474
+
475
+ // src/internal/instrumentation/typesafe.ts
454
476
  var INSTRUMENTATION_NAME2 = "@brizz/sdk/typesafe";
455
477
  var MODULE_NAME2 = "@typesafe-ai/sdk";
456
478
  var SUPPORTED_VERSIONS2 = [">=0.5.7 <1"];
457
479
  var SPAN_NAME = "typesafe.system_one";
458
480
  var PROVIDER_NAME = "typesafe";
459
- var OPERATION_NAME = "classify";
460
- var ATTR_OPERATION_NAME = "gen_ai.operation.name";
461
- var ATTR_PROVIDER_NAME = "gen_ai.provider.name";
462
- var ATTR_REQUEST_MODEL = "gen_ai.request.model";
463
- var ATTR_RESPONSE_MODEL = "gen_ai.response.model";
464
- var ATTR_INPUT_TOKENS = "gen_ai.usage.input_tokens";
465
- var ATTR_OUTPUT_TOKENS = "gen_ai.usage.output_tokens";
466
- var ATTR_INPUT_MESSAGES = "gen_ai.input.messages";
467
481
  var ATTR_QUESTIONS = "typesafe.questions";
468
482
  var ATTR_ANSWERS = "typesafe.answers";
469
483
  var PATCHED_FLAG2 = /* @__PURE__ */ Symbol.for("brizz.typesafe.patched");
470
484
  var TypeSafeInstrumentation = class extends _instrumentation.InstrumentationBase {
471
485
  constructor(config = {}) {
472
- super(INSTRUMENTATION_NAME2, _chunkDCXOK7PXcjs.getSDKVersion.call(void 0, ), config);
486
+ super(INSTRUMENTATION_NAME2, _chunk5QZM5EVPcjs.getSDKVersion.call(void 0, ), config);
473
487
  this.setTracerProvider(_chunkDC2MFO65cjs.brizzTracerProvider);
474
488
  }
475
489
  init() {
@@ -492,7 +506,7 @@ var TypeSafeInstrumentation = class extends _instrumentation.InstrumentationBase
492
506
  * `patchInstalledTypeSafe`, or `instrumentModules: { typesafe }`.
493
507
  */
494
508
  manuallyInstrument(moduleExports) {
495
- const client = _optionalChain([moduleExports, 'optionalAccess', _19 => _19.TypeSafeClient]);
509
+ const client = _optionalChain([moduleExports, 'optionalAccess', _21 => _21.TypeSafeClient]);
496
510
  if (typeof client !== "function" || !client.prototype) {
497
511
  _chunkWC573FCIcjs.logger.debug("Brizz TypeSafe: module does not expose TypeSafeClient \u2014 skipping patch");
498
512
  return;
@@ -575,9 +589,9 @@ function patchSystemOne(proto, getTracer) {
575
589
  function observe(pending, span) {
576
590
  const onError = (error) => endSpan(span, error);
577
591
  try {
578
- if (typeof _optionalChain([pending, 'optionalAccess', _20 => _20.asResponse]) === "function") {
592
+ if (typeof _optionalChain([pending, 'optionalAccess', _22 => _22.asResponse]) === "function") {
579
593
  pending.asResponse().then((response) => {
580
- if (typeof _optionalChain([response, 'optionalAccess', _21 => _21.clone]) !== "function") {
594
+ if (typeof _optionalChain([response, 'optionalAccess', _23 => _23.clone]) !== "function") {
581
595
  endSpan(span);
582
596
  return;
583
597
  }
@@ -588,7 +602,7 @@ function observe(pending, span) {
588
602
  }, onError);
589
603
  return pending;
590
604
  }
591
- if (typeof _optionalChain([pending, 'optionalAccess', _22 => _22.then]) === "function") {
605
+ if (typeof _optionalChain([pending, 'optionalAccess', _24 => _24.then]) === "function") {
592
606
  pending.then((result) => {
593
607
  recordResult(span, result);
594
608
  endSpan(span);
@@ -603,18 +617,18 @@ function observe(pending, span) {
603
617
  }
604
618
  function startSpan(getTracer, request) {
605
619
  try {
606
- const model = typeof _optionalChain([request, 'optionalAccess', _23 => _23.model]) === "string" && request.model !== "" ? request.model : void 0;
620
+ const model = typeof _optionalChain([request, 'optionalAccess', _25 => _25.model]) === "string" && request.model !== "" ? request.model : void 0;
607
621
  const attributes = {
608
- [ATTR_OPERATION_NAME]: OPERATION_NAME,
609
- [ATTR_PROVIDER_NAME]: PROVIDER_NAME,
610
- [ATTR_INPUT_MESSAGES]: JSON.stringify([
611
- { role: "user", parts: [{ type: "text", content: text(_optionalChain([request, 'optionalAccess', _24 => _24.state])) }] }
622
+ [_chunkNF52RMLWcjs.GEN_AI_OPERATION_NAME]: _chunkNF52RMLWcjs.GEN_AI_OPERATION_CLASSIFY,
623
+ [_chunkNF52RMLWcjs.GEN_AI_PROVIDER_NAME]: PROVIDER_NAME,
624
+ [_chunkNF52RMLWcjs.GEN_AI_INPUT_MESSAGES]: JSON.stringify([
625
+ { role: "user", parts: [{ type: "text", content: text(_optionalChain([request, 'optionalAccess', _26 => _26.state])) }] }
612
626
  ])
613
627
  };
614
628
  if (model) {
615
- attributes[ATTR_REQUEST_MODEL] = model;
629
+ attributes[_chunkNF52RMLWcjs.GEN_AI_REQUEST_MODEL] = model;
616
630
  }
617
- if (_optionalChain([request, 'optionalAccess', _25 => _25.questions]) !== void 0) {
631
+ if (_optionalChain([request, 'optionalAccess', _27 => _27.questions]) !== void 0) {
618
632
  attributes[ATTR_QUESTIONS] = JSON.stringify(request.questions);
619
633
  }
620
634
  return getTracer().startSpan(SPAN_NAME, { kind: _api.SpanKind.CLIENT, attributes });
@@ -627,13 +641,13 @@ function recordResult(span, result) {
627
641
  try {
628
642
  const { model, usage, answers } = _nullishCoalesce(result, () => ( {}));
629
643
  if (typeof model === "string" && model) {
630
- span.setAttribute(ATTR_RESPONSE_MODEL, model);
644
+ span.setAttribute(_chunkNF52RMLWcjs.GEN_AI_RESPONSE_MODEL, model);
631
645
  }
632
- if (typeof _optionalChain([usage, 'optionalAccess', _26 => _26.input_tokens]) === "number") {
633
- span.setAttribute(ATTR_INPUT_TOKENS, usage.input_tokens);
646
+ if (typeof _optionalChain([usage, 'optionalAccess', _28 => _28.input_tokens]) === "number") {
647
+ span.setAttribute(_chunkNF52RMLWcjs.GEN_AI_USAGE_INPUT_TOKENS, usage.input_tokens);
634
648
  }
635
- if (typeof _optionalChain([usage, 'optionalAccess', _27 => _27.output_tokens]) === "number") {
636
- span.setAttribute(ATTR_OUTPUT_TOKENS, usage.output_tokens);
649
+ if (typeof _optionalChain([usage, 'optionalAccess', _29 => _29.output_tokens]) === "number") {
650
+ span.setAttribute(_chunkNF52RMLWcjs.GEN_AI_USAGE_OUTPUT_TOKENS, usage.output_tokens);
637
651
  }
638
652
  if (answers !== void 0) {
639
653
  span.setAttribute(ATTR_ANSWERS, JSON.stringify(answers));
@@ -649,12 +663,10 @@ function endSpan(span, error) {
649
663
  if (error !== void 0) {
650
664
  span.recordException(error instanceof Error ? error : new Error(String(error)));
651
665
  span.setStatus({ code: _api.SpanStatusCode.ERROR, message: String(error) });
666
+ span.setAttribute(_chunkNF52RMLWcjs.ERROR_TYPE, errorType(error));
652
667
  }
653
668
  span.end();
654
669
  }
655
- function text(value) {
656
- return typeof value === "string" ? value : _nullishCoalesce(JSON.stringify(value), () => ( ""));
657
- }
658
670
 
659
671
  // src/internal/instrumentation/auto-init.ts
660
672
  var exceptionLogger = (error) => {
@@ -698,7 +710,7 @@ function loadGenAIInstrumentations() {
698
710
  function loadMCPInstrumentation() {
699
711
  void (async () => {
700
712
  try {
701
- const { MCPInstrumentation } = await Promise.resolve().then(() => _interopRequireWildcard(require("./mcp-WHXEBLRI.cjs")));
713
+ const { MCPInstrumentation } = await Promise.resolve().then(() => _interopRequireWildcard(require("./mcp-UPBKSTB7.cjs")));
702
714
  const mcp = new MCPInstrumentation({ exceptionLogger });
703
715
  _instrumentation.registerInstrumentations.call(void 0, { instrumentations: [mcp], tracerProvider: _chunkDC2MFO65cjs.brizzTracerProvider });
704
716
  _chunkWC573FCIcjs.logger.debug("Auto-loaded MCP instrumentation");
@@ -782,7 +794,7 @@ function loadVercelAITelemetry() {
782
794
  }
783
795
  const isV7 = typeof ai.registerTelemetry === "function";
784
796
  const integrations = [];
785
- const { createInterruptIntegration } = await Promise.resolve().then(() => _interopRequireWildcard(require("./interrupt-BYLSBXTV.cjs")));
797
+ const { createInterruptIntegration } = await Promise.resolve().then(() => _interopRequireWildcard(require("./interrupt-36U5562Z.cjs")));
786
798
  integrations.push(createInterruptIntegration());
787
799
  let otelCollectorLoaded = false;
788
800
  try {
@@ -861,7 +873,7 @@ function parseBoolEnv(name) {
861
873
  return void 0;
862
874
  }
863
875
  function resolveConfig(options) {
864
- const envLogLevel = process.env["BRIZZ_LOG_LEVEL"] || _optionalChain([options, 'access', _28 => _28.logLevel, 'optionalAccess', _29 => _29.toString, 'call', _30 => _30()]) || _chunkWC573FCIcjs.DEFAULT_LOG_LEVEL.toString();
876
+ const envLogLevel = process.env["BRIZZ_LOG_LEVEL"] || _optionalChain([options, 'access', _30 => _30.logLevel, 'optionalAccess', _31 => _31.toString, 'call', _32 => _32()]) || _chunkWC573FCIcjs.DEFAULT_LOG_LEVEL.toString();
865
877
  let resolvedLogLevel;
866
878
  if (envLogLevel) {
867
879
  resolvedLogLevel = _chunkWC573FCIcjs.parseLogLevel.call(void 0, envLogLevel);
@@ -1017,29 +1029,29 @@ var PATCHED_MARKER = /* @__PURE__ */ Symbol.for("brizz.langchain.callbackManager
1017
1029
  var TRACER_PATCHED_MARKER = /* @__PURE__ */ Symbol.for("brizz.langchain.tracerPatched");
1018
1030
  var runContexts = /* @__PURE__ */ new WeakMap();
1019
1031
  var OMITTED_KEYS = /* @__PURE__ */ new Set([
1020
- _chunkRV7JIIDGcjs.USER_EMAIL,
1021
- _chunkRV7JIIDGcjs.USER_NAME,
1022
- _chunkRV7JIIDGcjs.ORGANIZATION_NAME,
1023
- _chunkRV7JIIDGcjs.ORGANIZATION_DOMAIN
1032
+ _chunkNF52RMLWcjs.USER_EMAIL,
1033
+ _chunkNF52RMLWcjs.USER_NAME,
1034
+ _chunkNF52RMLWcjs.ORGANIZATION_NAME,
1035
+ _chunkNF52RMLWcjs.ORGANIZATION_DOMAIN
1024
1036
  ]);
1025
1037
  var TOOL_CALL_ID_METADATA_KEY = "brizz_tool_call_id";
1026
1038
  var TOOL_ID = "tool.id";
1027
1039
  var TOOL_CALL_ID_ARG = 7;
1028
1040
  function runMetadataFromContext() {
1029
- const bag = _api.context.active().getValue(_chunkRV7JIIDGcjs.PROPERTIES_CONTEXT_KEY);
1041
+ const bag = _api.context.active().getValue(_chunkNF52RMLWcjs.PROPERTIES_CONTEXT_KEY);
1030
1042
  if (!bag) {
1031
1043
  return void 0;
1032
1044
  }
1033
1045
  const metadata = {};
1034
1046
  for (const [name, value] of Object.entries(bag)) {
1035
1047
  if (!OMITTED_KEYS.has(name)) {
1036
- metadata[`${_chunkRV7JIIDGcjs.BRIZZ}.${name}`] = String(value);
1048
+ metadata[`${_chunkNF52RMLWcjs.BRIZZ}.${name}`] = String(value);
1037
1049
  }
1038
1050
  }
1039
1051
  return Object.keys(metadata).length > 0 ? metadata : void 0;
1040
1052
  }
1041
1053
  function patchCallbackManagerModule(module2) {
1042
- const callbackManager = _optionalChain([module2, 'optionalAccess', _31 => _31.CallbackManager]);
1054
+ const callbackManager = _optionalChain([module2, 'optionalAccess', _33 => _33.CallbackManager]);
1043
1055
  if (callbackManager === null || typeof callbackManager !== "function" && typeof callbackManager !== "object") {
1044
1056
  return false;
1045
1057
  }
@@ -1062,7 +1074,7 @@ function patchCallbackManagerModule(module2) {
1062
1074
  }
1063
1075
  } catch (e2) {
1064
1076
  }
1065
- _optionalChain([manager, 'optionalAccess', _32 => _32.handlers, 'optionalAccess', _33 => _33.forEach, 'call', _34 => _34((handler) => {
1077
+ _optionalChain([manager, 'optionalAccess', _34 => _34.handlers, 'optionalAccess', _35 => _35.forEach, 'call', _36 => _36((handler) => {
1066
1078
  try {
1067
1079
  patchTracer(handler);
1068
1080
  } catch (e3) {
@@ -1075,21 +1087,21 @@ function patchCallbackManagerModule(module2) {
1075
1087
  return true;
1076
1088
  }
1077
1089
  function patchTracer(handler) {
1078
- const tracer = handler;
1079
- if (typeof tracer !== "object" || tracer === null || tracer[TRACER_PATCHED_MARKER] === true) {
1090
+ const tracer2 = handler;
1091
+ if (typeof tracer2 !== "object" || tracer2 === null || tracer2[TRACER_PATCHED_MARKER] === true) {
1080
1092
  return;
1081
1093
  }
1082
- const addRunToRunMap = tracer["_addRunToRunMap"];
1083
- const onRunCreate = tracer["onRunCreate"];
1084
- const endTrace = tracer["_endTrace"];
1094
+ const addRunToRunMap = tracer2["_addRunToRunMap"];
1095
+ const onRunCreate = tracer2["onRunCreate"];
1096
+ const endTrace = tracer2["_endTrace"];
1085
1097
  if (typeof addRunToRunMap !== "function" || typeof onRunCreate !== "function" || typeof endTrace !== "function") {
1086
1098
  return;
1087
1099
  }
1088
- tracer[TRACER_PATCHED_MARKER] = true;
1089
- tracer["onRunCreate"] = inRunContext(onRunCreate);
1090
- tracer["_endTrace"] = inRunContext(endTrace);
1100
+ tracer2[TRACER_PATCHED_MARKER] = true;
1101
+ tracer2["onRunCreate"] = inRunContext(onRunCreate);
1102
+ tracer2["_endTrace"] = inRunContext(endTrace);
1091
1103
  const addRun = addRunToRunMap;
1092
- tracer["_addRunToRunMap"] = function(...args) {
1104
+ tracer2["_addRunToRunMap"] = function(...args) {
1093
1105
  const run = addRun.apply(this, args);
1094
1106
  if (typeof run === "object" && run !== null) {
1095
1107
  runContexts.set(run, _api.context.active());
@@ -1105,7 +1117,7 @@ function inRunContext(method) {
1105
1117
  }
1106
1118
  function patchToolStart(prototype) {
1107
1119
  const proto = prototype;
1108
- const original = _optionalChain([proto, 'optionalAccess', _35 => _35["handleToolStart"]]);
1120
+ const original = _optionalChain([proto, 'optionalAccess', _37 => _37["handleToolStart"]]);
1109
1121
  if (!proto || typeof original !== "function") {
1110
1122
  return;
1111
1123
  }
@@ -1143,12 +1155,12 @@ function patchInstalledCallbackManager() {
1143
1155
  function restampLangChainSpan(span) {
1144
1156
  try {
1145
1157
  const scope = span.instrumentationScope;
1146
- if (_optionalChain([scope, 'optionalAccess', _36 => _36.name]) !== SCOPE_NAME) {
1158
+ if (_optionalChain([scope, 'optionalAccess', _38 => _38.name]) !== SCOPE_NAME) {
1147
1159
  return;
1148
1160
  }
1149
1161
  const attrs = span.attributes;
1150
1162
  const metadata = attrs["metadata"];
1151
- if (typeof metadata !== "string" || !metadata.includes(`"${_chunkRV7JIIDGcjs.BRIZZ}.`) && !metadata.includes(`"${TOOL_CALL_ID_METADATA_KEY}"`)) {
1163
+ if (typeof metadata !== "string" || !metadata.includes(`"${_chunkNF52RMLWcjs.BRIZZ}.`) && !metadata.includes(`"${TOOL_CALL_ID_METADATA_KEY}"`)) {
1152
1164
  return;
1153
1165
  }
1154
1166
  const parsed = JSON.parse(metadata);
@@ -1157,7 +1169,7 @@ function restampLangChainSpan(span) {
1157
1169
  }
1158
1170
  const entries = parsed;
1159
1171
  for (const [key, value] of Object.entries(entries)) {
1160
- if (key.startsWith(`${_chunkRV7JIIDGcjs.BRIZZ}.`) && value !== null && value !== void 0) {
1172
+ if (key.startsWith(`${_chunkNF52RMLWcjs.BRIZZ}.`) && value !== null && value !== void 0) {
1161
1173
  attrs[key] = String(value);
1162
1174
  }
1163
1175
  }
@@ -1205,7 +1217,7 @@ var InstrumentationRegistry = (_class = class _InstrumentationRegistry {construc
1205
1217
  * @private
1206
1218
  */
1207
1219
  loadManualInstrumentations(instrumentations, exceptionLogger2) {
1208
- if (_optionalChain([this, 'access', _37 => _37.manualModules, 'optionalAccess', _38 => _38.openAI])) {
1220
+ if (_optionalChain([this, 'access', _39 => _39.manualModules, 'optionalAccess', _40 => _40.openAI])) {
1209
1221
  try {
1210
1222
  const openAIInst = new BrizzOpenAIInstrumentation();
1211
1223
  openAIInst.manuallyInstrument(this.manualModules.openAI);
@@ -1216,18 +1228,18 @@ var InstrumentationRegistry = (_class = class _InstrumentationRegistry {construc
1216
1228
  }
1217
1229
  }
1218
1230
  const instrumentationConfigs = [
1219
- { class: _instrumentationanthropic.AnthropicInstrumentation, name: "Anthropic", module: _optionalChain([this, 'access', _39 => _39.manualModules, 'optionalAccess', _40 => _40.anthropic]) },
1220
- { class: _instrumentationcohere.CohereInstrumentation, name: "Cohere", module: _optionalChain([this, 'access', _41 => _41.manualModules, 'optionalAccess', _42 => _42.cohere]) },
1221
- { class: _instrumentationbedrock.BedrockInstrumentation, name: "Bedrock", module: _optionalChain([this, 'access', _43 => _43.manualModules, 'optionalAccess', _44 => _44.bedrock]) },
1222
- { class: _instrumentationpinecone.PineconeInstrumentation, name: "Pinecone", module: _optionalChain([this, 'access', _45 => _45.manualModules, 'optionalAccess', _46 => _46.pinecone]) },
1231
+ { class: _instrumentationanthropic.AnthropicInstrumentation, name: "Anthropic", module: _optionalChain([this, 'access', _41 => _41.manualModules, 'optionalAccess', _42 => _42.anthropic]) },
1232
+ { class: _instrumentationcohere.CohereInstrumentation, name: "Cohere", module: _optionalChain([this, 'access', _43 => _43.manualModules, 'optionalAccess', _44 => _44.cohere]) },
1233
+ { class: _instrumentationbedrock.BedrockInstrumentation, name: "Bedrock", module: _optionalChain([this, 'access', _45 => _45.manualModules, 'optionalAccess', _46 => _46.bedrock]) },
1234
+ { class: _instrumentationpinecone.PineconeInstrumentation, name: "Pinecone", module: _optionalChain([this, 'access', _47 => _47.manualModules, 'optionalAccess', _48 => _48.pinecone]) },
1223
1235
  {
1224
1236
  class: _instrumentationllamaindex.LlamaIndexInstrumentation,
1225
1237
  name: "LlamaIndex",
1226
- module: _optionalChain([this, 'access', _47 => _47.manualModules, 'optionalAccess', _48 => _48.llamaindex])
1238
+ module: _optionalChain([this, 'access', _49 => _49.manualModules, 'optionalAccess', _50 => _50.llamaindex])
1227
1239
  },
1228
- { class: _instrumentationchromadb.ChromaDBInstrumentation, name: "ChromaDB", module: _optionalChain([this, 'access', _49 => _49.manualModules, 'optionalAccess', _50 => _50.chromadb]) },
1229
- { class: _instrumentationqdrant.QdrantInstrumentation, name: "Qdrant", module: _optionalChain([this, 'access', _51 => _51.manualModules, 'optionalAccess', _52 => _52.qdrant]) },
1230
- { class: _instrumentationtogether.TogetherInstrumentation, name: "Together", module: _optionalChain([this, 'access', _53 => _53.manualModules, 'optionalAccess', _54 => _54.together]) }
1240
+ { class: _instrumentationchromadb.ChromaDBInstrumentation, name: "ChromaDB", module: _optionalChain([this, 'access', _51 => _51.manualModules, 'optionalAccess', _52 => _52.chromadb]) },
1241
+ { class: _instrumentationqdrant.QdrantInstrumentation, name: "Qdrant", module: _optionalChain([this, 'access', _53 => _53.manualModules, 'optionalAccess', _54 => _54.qdrant]) },
1242
+ { class: _instrumentationtogether.TogetherInstrumentation, name: "Together", module: _optionalChain([this, 'access', _55 => _55.manualModules, 'optionalAccess', _56 => _56.together]) }
1231
1243
  ];
1232
1244
  for (const config of instrumentationConfigs) {
1233
1245
  if (!config.module) {
@@ -1243,7 +1255,7 @@ var InstrumentationRegistry = (_class = class _InstrumentationRegistry {construc
1243
1255
  instrumentations.push(instrumentation);
1244
1256
  }
1245
1257
  }
1246
- if (_optionalChain([this, 'access', _55 => _55.manualModules, 'optionalAccess', _56 => _56.langchain, 'optionalAccess', _57 => _57.callbackManagerModule])) {
1258
+ if (_optionalChain([this, 'access', _57 => _57.manualModules, 'optionalAccess', _58 => _58.langchain, 'optionalAccess', _59 => _59.callbackManagerModule])) {
1247
1259
  const callbackManagerModule = this.manualModules.langchain.callbackManagerModule;
1248
1260
  void (async () => {
1249
1261
  try {
@@ -1259,7 +1271,7 @@ var InstrumentationRegistry = (_class = class _InstrumentationRegistry {construc
1259
1271
  }
1260
1272
  })();
1261
1273
  }
1262
- if (_optionalChain([this, 'access', _58 => _58.manualModules, 'optionalAccess', _59 => _59.langgraph])) {
1274
+ if (_optionalChain([this, 'access', _60 => _60.manualModules, 'optionalAccess', _61 => _61.langgraph])) {
1263
1275
  try {
1264
1276
  new LangGraphInstrumentation().manuallyInstrument(this.manualModules.langgraph);
1265
1277
  _chunkWC573FCIcjs.logger.debug("Manual instrumentation enabled for LangGraph");
@@ -1267,7 +1279,7 @@ var InstrumentationRegistry = (_class = class _InstrumentationRegistry {construc
1267
1279
  _chunkWC573FCIcjs.logger.error(`Failed to apply LangGraph instrumentation: ${String(error)}`);
1268
1280
  }
1269
1281
  }
1270
- if (_optionalChain([this, 'access', _60 => _60.manualModules, 'optionalAccess', _61 => _61.typesafe])) {
1282
+ if (_optionalChain([this, 'access', _62 => _62.manualModules, 'optionalAccess', _63 => _63.typesafe])) {
1271
1283
  try {
1272
1284
  new TypeSafeInstrumentation().manuallyInstrument(this.manualModules.typesafe);
1273
1285
  _chunkWC573FCIcjs.logger.debug("Manual instrumentation enabled for TypeSafe");
@@ -1275,7 +1287,7 @@ var InstrumentationRegistry = (_class = class _InstrumentationRegistry {construc
1275
1287
  _chunkWC573FCIcjs.logger.error(`Failed to apply TypeSafe instrumentation: ${String(error)}`);
1276
1288
  }
1277
1289
  }
1278
- if (_optionalChain([this, 'access', _62 => _62.manualModules, 'optionalAccess', _63 => _63.google_vertexai])) {
1290
+ if (_optionalChain([this, 'access', _64 => _64.manualModules, 'optionalAccess', _65 => _65.google_vertexai])) {
1279
1291
  const vertexModule = this.manualModules.google_vertexai;
1280
1292
  void (async () => {
1281
1293
  try {
@@ -1290,7 +1302,7 @@ var InstrumentationRegistry = (_class = class _InstrumentationRegistry {construc
1290
1302
  }
1291
1303
  })();
1292
1304
  }
1293
- if (_optionalChain([this, 'access', _64 => _64.manualModules, 'optionalAccess', _65 => _65.google_genai])) {
1305
+ if (_optionalChain([this, 'access', _66 => _66.manualModules, 'optionalAccess', _67 => _67.google_genai])) {
1294
1306
  const genaiModule = this.manualModules.google_genai;
1295
1307
  void (async () => {
1296
1308
  try {
@@ -1305,11 +1317,11 @@ var InstrumentationRegistry = (_class = class _InstrumentationRegistry {construc
1305
1317
  }
1306
1318
  })();
1307
1319
  }
1308
- if (_optionalChain([this, 'access', _66 => _66.manualModules, 'optionalAccess', _67 => _67.mcp])) {
1320
+ if (_optionalChain([this, 'access', _68 => _68.manualModules, 'optionalAccess', _69 => _69.mcp])) {
1309
1321
  const mcpModules = this.manualModules.mcp;
1310
1322
  void (async () => {
1311
1323
  try {
1312
- const { MCPInstrumentation } = await Promise.resolve().then(() => _interopRequireWildcard(require("./mcp-WHXEBLRI.cjs")));
1324
+ const { MCPInstrumentation } = await Promise.resolve().then(() => _interopRequireWildcard(require("./mcp-UPBKSTB7.cjs")));
1313
1325
  const instrumentation = new MCPInstrumentation({ exceptionLogger: exceptionLogger2 });
1314
1326
  instrumentation.manuallyInstrument(mcpModules);
1315
1327
  _chunkWC573FCIcjs.logger.debug("Manual instrumentation enabled for MCP");
@@ -1351,722 +1363,6 @@ var _exporterlogsotlphttp = require('@opentelemetry/exporter-logs-otlp-http');
1351
1363
 
1352
1364
  var _sdklogs = require('@opentelemetry/sdk-logs');
1353
1365
 
1354
- // src/internal/trace/session.ts
1355
-
1356
- var sessionTracer = _chunkDC2MFO65cjs.brizzTracerProvider.getTracer("@brizz/sdk");
1357
- function setCurrentSpanCustomProperties(properties) {
1358
- const current = _api.trace.getActiveSpan();
1359
- if (!current || !current.isRecording()) {
1360
- return;
1361
- }
1362
- for (const [key, value] of Object.entries(properties)) {
1363
- try {
1364
- current.setAttribute(`${_chunkRV7JIIDGcjs.BRIZZ}.${key}`, value);
1365
- } catch (e5) {
1366
- }
1367
- }
1368
- }
1369
- function callWithProperties(properties, fn, thisArg, ...args) {
1370
- const base = _api.context.active();
1371
- const prev = base.getValue(_chunkRV7JIIDGcjs.PROPERTIES_CONTEXT_KEY);
1372
- const merged = prev ? { ...prev, ...properties } : properties;
1373
- const next = base.setValue(_chunkRV7JIIDGcjs.PROPERTIES_CONTEXT_KEY, merged);
1374
- return _api.context.with(next, fn, thisArg, ...args);
1375
- }
1376
- function withProperties(properties, fn, thisArg) {
1377
- return function wrapped(...args) {
1378
- return callWithProperties(
1379
- properties,
1380
- fn,
1381
- thisArg !== void 0 ? thisArg : this,
1382
- ...args
1383
- );
1384
- };
1385
- }
1386
- function propagatePropertiesImperatively(properties, base = _api.context.active()) {
1387
- try {
1388
- const manager = _api.context;
1389
- const mgr = _optionalChain([manager, 'access', _68 => _68._getContextManager, 'optionalCall', _69 => _69()]);
1390
- const store = _optionalChain([mgr, 'optionalAccess', _70 => _70._asyncLocalStorage]);
1391
- if (!store || typeof store.enterWith !== "function") {
1392
- return;
1393
- }
1394
- const prev = base.getValue(_chunkRV7JIIDGcjs.PROPERTIES_CONTEXT_KEY);
1395
- const merged = prev ? { ...prev, ...properties } : properties;
1396
- store.enterWith(base.setValue(_chunkRV7JIIDGcjs.PROPERTIES_CONTEXT_KEY, merged));
1397
- } catch (e6) {
1398
- }
1399
- }
1400
- function setUser(user) {
1401
- const properties = { [_chunkRV7JIIDGcjs.USER_ID]: user.id };
1402
- if (user.email !== void 0) {
1403
- properties[_chunkRV7JIIDGcjs.USER_EMAIL] = user.email;
1404
- }
1405
- if (user.name !== void 0) {
1406
- properties[_chunkRV7JIIDGcjs.USER_NAME] = user.name;
1407
- }
1408
- if (user.role !== void 0) {
1409
- properties[_chunkRV7JIIDGcjs.USER_ROLE] = user.role;
1410
- }
1411
- if (user.plan !== void 0) {
1412
- properties[_chunkRV7JIIDGcjs.USER_PLAN] = user.plan;
1413
- }
1414
- if (user.traits) {
1415
- for (const [key, value] of Object.entries(user.traits)) {
1416
- const k = `user.${key}`;
1417
- if (properties[k] === void 0) {
1418
- properties[k] = value;
1419
- }
1420
- }
1421
- }
1422
- setCurrentSpanCustomProperties(properties);
1423
- propagatePropertiesImperatively(properties);
1424
- }
1425
- function setOrganization(org) {
1426
- const properties = { [_chunkRV7JIIDGcjs.ORGANIZATION_ID]: org.id };
1427
- if (org.name !== void 0) {
1428
- properties[_chunkRV7JIIDGcjs.ORGANIZATION_NAME] = org.name;
1429
- }
1430
- if (org.plan !== void 0) {
1431
- properties[_chunkRV7JIIDGcjs.ORGANIZATION_PLAN] = org.plan;
1432
- }
1433
- if (org.domain !== void 0) {
1434
- properties[_chunkRV7JIIDGcjs.ORGANIZATION_DOMAIN] = org.domain;
1435
- }
1436
- if (org.traits) {
1437
- for (const [key, value] of Object.entries(org.traits)) {
1438
- const k = `organization.${key}`;
1439
- if (properties[k] === void 0) {
1440
- properties[k] = value;
1441
- }
1442
- }
1443
- }
1444
- setCurrentSpanCustomProperties(properties);
1445
- propagatePropertiesImperatively(properties);
1446
- }
1447
- function setMessageId(id) {
1448
- const properties = { [_chunkRV7JIIDGcjs.MESSAGE_ID]: id };
1449
- setCurrentSpanCustomProperties(properties);
1450
- propagatePropertiesImperatively(properties);
1451
- }
1452
- function setSessionId(id) {
1453
- const properties = { [_chunkRV7JIIDGcjs.SESSION_ID]: id };
1454
- setCurrentSpanCustomProperties(properties);
1455
- propagatePropertiesImperatively(properties);
1456
- }
1457
- var SERVICE_NAME_MAX_BYTES = 256;
1458
- function serviceNameProblem(name) {
1459
- if (typeof name !== "string" || name === "") {
1460
- return "must be a non-empty string";
1461
- }
1462
- if (/[\r\n\0]/.test(name)) {
1463
- return `${JSON.stringify(name)} contains CR, LF, or NUL`;
1464
- }
1465
- const byteLength = new globalThis.TextEncoder().encode(name).length;
1466
- if (byteLength > SERVICE_NAME_MAX_BYTES) {
1467
- return `is ${byteLength} bytes, over the ${SERVICE_NAME_MAX_BYTES}-byte limit`;
1468
- }
1469
- return void 0;
1470
- }
1471
- function serviceNameProperties(name) {
1472
- const problem = serviceNameProblem(name);
1473
- if (problem !== void 0) {
1474
- _chunkWC573FCIcjs.logger.warn(`Service name ${problem}; keeping the configured appName.`);
1475
- return {};
1476
- }
1477
- return { [_chunkRV7JIIDGcjs.SERVICE_NAME]: name };
1478
- }
1479
- function setServiceName(name) {
1480
- const properties = serviceNameProperties(name);
1481
- setCurrentSpanCustomProperties(properties);
1482
- propagatePropertiesImperatively(properties);
1483
- }
1484
- function callWithServiceName(name, fn, thisArg, ...args) {
1485
- return callWithProperties(serviceNameProperties(name), fn, thisArg, ...args);
1486
- }
1487
- function withServiceName(name, fn, thisArg) {
1488
- return withProperties(serviceNameProperties(name), fn, thisArg);
1489
- }
1490
- function resolveServiceNameFromContext() {
1491
- const props = _api.context.active().getValue(_chunkRV7JIIDGcjs.PROPERTIES_CONTEXT_KEY);
1492
- return _optionalChain([props, 'optionalAccess', _71 => _71[_chunkRV7JIIDGcjs.SERVICE_NAME]]);
1493
- }
1494
- function userProperties(user) {
1495
- const properties = { [_chunkRV7JIIDGcjs.USER_ID]: user.id };
1496
- if (user.email !== void 0) {
1497
- properties[_chunkRV7JIIDGcjs.USER_EMAIL] = user.email;
1498
- }
1499
- if (user.name !== void 0) {
1500
- properties[_chunkRV7JIIDGcjs.USER_NAME] = user.name;
1501
- }
1502
- if (user.role !== void 0) {
1503
- properties[_chunkRV7JIIDGcjs.USER_ROLE] = user.role;
1504
- }
1505
- if (user.plan !== void 0) {
1506
- properties[_chunkRV7JIIDGcjs.USER_PLAN] = user.plan;
1507
- }
1508
- if (user.traits) {
1509
- for (const [key, value] of Object.entries(user.traits)) {
1510
- const k = `user.${key}`;
1511
- if (properties[k] === void 0) {
1512
- properties[k] = value;
1513
- }
1514
- }
1515
- }
1516
- return properties;
1517
- }
1518
- function organizationProperties(org) {
1519
- const properties = { [_chunkRV7JIIDGcjs.ORGANIZATION_ID]: org.id };
1520
- if (org.name !== void 0) {
1521
- properties[_chunkRV7JIIDGcjs.ORGANIZATION_NAME] = org.name;
1522
- }
1523
- if (org.plan !== void 0) {
1524
- properties[_chunkRV7JIIDGcjs.ORGANIZATION_PLAN] = org.plan;
1525
- }
1526
- if (org.domain !== void 0) {
1527
- properties[_chunkRV7JIIDGcjs.ORGANIZATION_DOMAIN] = org.domain;
1528
- }
1529
- if (org.traits) {
1530
- for (const [key, value] of Object.entries(org.traits)) {
1531
- const k = `organization.${key}`;
1532
- if (properties[k] === void 0) {
1533
- properties[k] = value;
1534
- }
1535
- }
1536
- }
1537
- return properties;
1538
- }
1539
- function callWithUser(user, fn, thisArg, ...args) {
1540
- return callWithProperties(userProperties(user), fn, thisArg, ...args);
1541
- }
1542
- function withUser(user, fn, thisArg) {
1543
- return withProperties(userProperties(user), fn, thisArg);
1544
- }
1545
- function callWithOrganization(org, fn, thisArg, ...args) {
1546
- return callWithProperties(organizationProperties(org), fn, thisArg, ...args);
1547
- }
1548
- function withOrganization(org, fn, thisArg) {
1549
- return withProperties(organizationProperties(org), fn, thisArg);
1550
- }
1551
- function callWithMessageId(id, fn, thisArg, ...args) {
1552
- return callWithProperties({ [_chunkRV7JIIDGcjs.MESSAGE_ID]: id }, fn, thisArg, ...args);
1553
- }
1554
- function withMessageId(id, fn, thisArg) {
1555
- return withProperties({ [_chunkRV7JIIDGcjs.MESSAGE_ID]: id }, fn, thisArg);
1556
- }
1557
- function inheritedMuteTools() {
1558
- const properties = _api.context.active().getValue(_chunkRV7JIIDGcjs.PROPERTIES_CONTEXT_KEY);
1559
- return _optionalChain([properties, 'optionalAccess', _72 => _72[_chunkRV7JIIDGcjs.MUTE_TOOLS]]);
1560
- }
1561
- function muteProperties(options) {
1562
- const { input = true, output = true, tools = output } = options;
1563
- const properties = {};
1564
- if (input) {
1565
- properties[_chunkRV7JIIDGcjs.MUTE_INPUT] = "true";
1566
- }
1567
- if (output) {
1568
- properties[_chunkRV7JIIDGcjs.MUTE_OUTPUT] = "true";
1569
- }
1570
- if (tools !== output) {
1571
- properties[_chunkRV7JIIDGcjs.MUTE_TOOLS] = String(tools);
1572
- } else {
1573
- const inherited = inheritedMuteTools();
1574
- if (tools && inherited === "false") {
1575
- properties[_chunkRV7JIIDGcjs.MUTE_TOOLS] = "true";
1576
- } else if (options.tools === false && inherited === "true") {
1577
- properties[_chunkRV7JIIDGcjs.MUTE_TOOLS] = "false";
1578
- }
1579
- }
1580
- return properties;
1581
- }
1582
- function callWithMute(options, fn, thisArg, ...args) {
1583
- return callWithProperties(muteProperties(options), fn, thisArg, ...args);
1584
- }
1585
- function withMute(options, fn, thisArg) {
1586
- return withProperties(muteProperties(options), fn, thisArg);
1587
- }
1588
- function withSessionId(sessionId, fn, thisArg, extraProperties) {
1589
- const properties = { [_chunkRV7JIIDGcjs.SESSION_ID]: sessionId, ...extraProperties };
1590
- return withProperties(properties, fn, thisArg);
1591
- }
1592
- function callWithSessionId(sessionId, fn, thisArg, ...args) {
1593
- return callWithProperties({ [_chunkRV7JIIDGcjs.SESSION_ID]: sessionId }, fn, thisArg, ...args);
1594
- }
1595
- var Session = (_class2 = class {
1596
-
1597
- __init2() {this.inputs = []}
1598
- __init3() {this.outputs = []}
1599
- __init4() {this.inputContexts = []}
1600
- __init5() {this.outputContexts = []}
1601
-
1602
- constructor(sessionId, span) {;_class2.prototype.__init2.call(this);_class2.prototype.__init3.call(this);_class2.prototype.__init4.call(this);_class2.prototype.__init5.call(this);
1603
- this.sessionId = sessionId;
1604
- this.span = span;
1605
- }
1606
- /**
1607
- * Append a user turn to session input tracking.
1608
- *
1609
- * Each call appends one element to `brizz.session.input` (the text) AND one
1610
- * element to `brizz.session.input.context` (the per-turn context bag). The
1611
- * two arrays stay index-aligned — the ingestion pipeline zips them together
1612
- * so the i-th context bag lands on the i-th user_display conversation item's
1613
- * `span_attributes` map.
1614
- *
1615
- * @param text - Text to append (null becomes a null/"hide marker")
1616
- * @param context - Optional per-turn context bag to attach to this turn
1617
- */
1618
- setInput(text2, context8) {
1619
- this.inputs.push(text2);
1620
- this.inputContexts.push(_nullishCoalesce(context8, () => ( {})));
1621
- this.span.setAttribute(_chunkRV7JIIDGcjs.SESSION_INPUT, JSON.stringify(this.inputs));
1622
- this.span.setAttribute(_chunkRV7JIIDGcjs.SESSION_INPUT_CONTEXT, JSON.stringify(this.inputContexts));
1623
- }
1624
- /**
1625
- * Append an assistant turn to session output tracking.
1626
- *
1627
- * Symmetric to {@link setInput} — appends one text element and one
1628
- * context-bag element to the index-aligned `brizz.session.output` /
1629
- * `brizz.session.output.context` arrays.
1630
- *
1631
- * @param text - Text to append (null becomes a null/"hide marker")
1632
- * @param context - Optional per-turn context bag to attach to this turn
1633
- */
1634
- setOutput(text2, context8) {
1635
- this.outputs.push(text2);
1636
- this.outputContexts.push(_nullishCoalesce(context8, () => ( {})));
1637
- this.span.setAttribute(_chunkRV7JIIDGcjs.SESSION_OUTPUT, JSON.stringify(this.outputs));
1638
- this.span.setAttribute(_chunkRV7JIIDGcjs.SESSION_OUTPUT_CONTEXT, JSON.stringify(this.outputContexts));
1639
- }
1640
- /**
1641
- * Set the session title on the span.
1642
- *
1643
- * @param title - The generated title string
1644
- */
1645
- setTitle(title) {
1646
- this.span.setAttribute(_chunkRV7JIIDGcjs.SESSION_TITLE, title);
1647
- }
1648
- /**
1649
- * Update custom properties on the session span.
1650
- * Properties are prefixed with 'brizz.'.
1651
- *
1652
- * @param properties - Key-value properties to set on the session
1653
- */
1654
- updateProperties(properties) {
1655
- for (const [key, value] of Object.entries(properties)) {
1656
- this.span.setAttribute(`${_chunkRV7JIIDGcjs.BRIZZ}.${key}`, value);
1657
- }
1658
- }
1659
- /**
1660
- * Set end-user identity on the session span: `brizz.user.id` and, when
1661
- * provided, `brizz.user.email` / `brizz.user.name`. Undefined fields are omitted.
1662
- *
1663
- * @param user - User identity (`id` required; `email` / `name` optional)
1664
- */
1665
- setUser(user) {
1666
- if (user.traits) {
1667
- for (const [key, value] of Object.entries(user.traits)) {
1668
- this.span.setAttribute(`${_chunkRV7JIIDGcjs.BRIZZ}.user.${key}`, value);
1669
- }
1670
- }
1671
- this.span.setAttribute(`${_chunkRV7JIIDGcjs.BRIZZ}.${_chunkRV7JIIDGcjs.USER_ID}`, user.id);
1672
- if (user.email !== void 0) {
1673
- this.span.setAttribute(`${_chunkRV7JIIDGcjs.BRIZZ}.${_chunkRV7JIIDGcjs.USER_EMAIL}`, user.email);
1674
- }
1675
- if (user.name !== void 0) {
1676
- this.span.setAttribute(`${_chunkRV7JIIDGcjs.BRIZZ}.${_chunkRV7JIIDGcjs.USER_NAME}`, user.name);
1677
- }
1678
- if (user.role !== void 0) {
1679
- this.span.setAttribute(`${_chunkRV7JIIDGcjs.BRIZZ}.${_chunkRV7JIIDGcjs.USER_ROLE}`, user.role);
1680
- }
1681
- if (user.plan !== void 0) {
1682
- this.span.setAttribute(`${_chunkRV7JIIDGcjs.BRIZZ}.${_chunkRV7JIIDGcjs.USER_PLAN}`, user.plan);
1683
- }
1684
- }
1685
- /**
1686
- * Set organization identity on the session span: `brizz.organization.id` and,
1687
- * when provided, `brizz.organization.name`. Undefined fields are omitted.
1688
- *
1689
- * @param org - Organization identity (`id` required; `name` optional)
1690
- */
1691
- setOrganization(org) {
1692
- if (org.traits) {
1693
- for (const [key, value] of Object.entries(org.traits)) {
1694
- this.span.setAttribute(`${_chunkRV7JIIDGcjs.BRIZZ}.organization.${key}`, value);
1695
- }
1696
- }
1697
- this.span.setAttribute(`${_chunkRV7JIIDGcjs.BRIZZ}.${_chunkRV7JIIDGcjs.ORGANIZATION_ID}`, org.id);
1698
- if (org.name !== void 0) {
1699
- this.span.setAttribute(`${_chunkRV7JIIDGcjs.BRIZZ}.${_chunkRV7JIIDGcjs.ORGANIZATION_NAME}`, org.name);
1700
- }
1701
- if (org.plan !== void 0) {
1702
- this.span.setAttribute(`${_chunkRV7JIIDGcjs.BRIZZ}.${_chunkRV7JIIDGcjs.ORGANIZATION_PLAN}`, org.plan);
1703
- }
1704
- if (org.domain !== void 0) {
1705
- this.span.setAttribute(`${_chunkRV7JIIDGcjs.BRIZZ}.${_chunkRV7JIIDGcjs.ORGANIZATION_DOMAIN}`, org.domain);
1706
- }
1707
- }
1708
- /**
1709
- * Attach an external link (URL) to this session.
1710
- *
1711
- * The link surfaces on the session's detail panel in Brizz — use it to
1712
- * correlate a session with an external record such as a Datadog trace,
1713
- * Sentry issue, or internal dashboard. Re-sending the same URL is idempotent;
1714
- * distinct URLs add separate links.
1715
- *
1716
- * @param url - The link target
1717
- * @param options - Optional `title` (defaults to the URL host) and `linkType`
1718
- * (free-form category, defaults to `'generic'`)
1719
- */
1720
- addExternalLink(url, options) {
1721
- emitExternalLink(this.sessionId, url, _optionalChain([options, 'optionalAccess', _73 => _73.title]), _optionalChain([options, 'optionalAccess', _74 => _74.linkType]));
1722
- }
1723
- }, _class2);
1724
- var SessionTitle = class {
1725
-
1726
- constructor(span) {
1727
- this.span = span;
1728
- }
1729
- /**
1730
- * Set the generated title on the wrapper span.
1731
- *
1732
- * @param title - The generated title string
1733
- */
1734
- setTitle(title) {
1735
- this.span.setAttribute(_chunkRV7JIIDGcjs.SESSION_TITLE, title);
1736
- }
1737
- };
1738
- function getActiveSession() {
1739
- return _api.context.active().getValue(_chunkRV7JIIDGcjs.SESSION_OBJECT_CONTEXT_KEY);
1740
- }
1741
- function resolveSessionIdFromContext() {
1742
- const active = getActiveSession();
1743
- if (active) {
1744
- return active.sessionId;
1745
- }
1746
- const props = _api.context.active().getValue(_chunkRV7JIIDGcjs.PROPERTIES_CONTEXT_KEY);
1747
- return _optionalChain([props, 'optionalAccess', _75 => _75[_chunkRV7JIIDGcjs.SESSION_ID]]);
1748
- }
1749
- function resolveMessageIdFromContext() {
1750
- const props = _api.context.active().getValue(_chunkRV7JIIDGcjs.PROPERTIES_CONTEXT_KEY);
1751
- return _optionalChain([props, 'optionalAccess', _76 => _76[_chunkRV7JIIDGcjs.MESSAGE_ID]]);
1752
- }
1753
- function emitExternalLink(sessionId, url, title, linkType) {
1754
- try {
1755
- emitEventWithSessionId(sessionId, _chunkRV7JIIDGcjs.EXTERNAL_LINK_EVENT_NAME, {
1756
- [_chunkRV7JIIDGcjs.EXTERNAL_LINK_URL]: url,
1757
- [_chunkRV7JIIDGcjs.EXTERNAL_LINK_TITLE]: _nullishCoalesce(title, () => ( "")),
1758
- [_chunkRV7JIIDGcjs.EXTERNAL_LINK_TYPE]: _nullishCoalesce(linkType, () => ( "generic"))
1759
- });
1760
- } catch (error) {
1761
- _chunkWC573FCIcjs.logger.warn("addExternalLink: failed to emit external link", error);
1762
- }
1763
- }
1764
- function addExternalLink(url, options) {
1765
- const sessionId = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _77 => _77.sessionId]), () => ( resolveSessionIdFromContext()));
1766
- if (!sessionId) {
1767
- _chunkWC573FCIcjs.logger.warn(
1768
- "addExternalLink called without a resolvable session id; link dropped. Pass options.sessionId or call inside a startSession/callWithSessionId scope."
1769
- );
1770
- return;
1771
- }
1772
- emitExternalLink(sessionId, url, _optionalChain([options, 'optionalAccess', _78 => _78.title]), _optionalChain([options, 'optionalAccess', _79 => _79.linkType]));
1773
- }
1774
- function recordFeedback(type, options) {
1775
- const eventAttributes = { [_chunkRV7JIIDGcjs.FEEDBACK_TYPE]: type };
1776
- if (_optionalChain([options, 'optionalAccess', _80 => _80.score]) !== void 0) {
1777
- eventAttributes[_chunkRV7JIIDGcjs.FEEDBACK_SCORE] = options.score;
1778
- }
1779
- if (_optionalChain([options, 'optionalAccess', _81 => _81.reason]) !== void 0) {
1780
- eventAttributes[_chunkRV7JIIDGcjs.FEEDBACK_REASON] = options.reason;
1781
- }
1782
- if (_optionalChain([options, 'optionalAccess', _82 => _82.comment]) !== void 0) {
1783
- eventAttributes[_chunkRV7JIIDGcjs.FEEDBACK_COMMENT] = options.comment;
1784
- }
1785
- if (_optionalChain([options, 'optionalAccess', _83 => _83.source]) !== void 0) {
1786
- eventAttributes[_chunkRV7JIIDGcjs.FEEDBACK_SOURCE] = options.source;
1787
- }
1788
- if (_optionalChain([options, 'optionalAccess', _84 => _84.attributes])) {
1789
- for (const [key, value] of Object.entries(options.attributes)) {
1790
- const k = `${_chunkRV7JIIDGcjs.FEEDBACK_ATTR_PREFIX}${key}`;
1791
- if (eventAttributes[k] === void 0) {
1792
- eventAttributes[k] = value;
1793
- }
1794
- }
1795
- }
1796
- const messageId = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _85 => _85.messageId]), () => ( resolveMessageIdFromContext()));
1797
- const sessionId = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _86 => _86.sessionId]), () => ( resolveSessionIdFromContext()));
1798
- if (messageId === void 0 && sessionId === void 0) {
1799
- _chunkWC573FCIcjs.logger.warn(
1800
- "recordFeedback called with no resolvable message id or session id; the feedback cannot be attributed to a message or conversation. Pass options.messageId / options.sessionId or call inside a startSession/callWithMessageId scope."
1801
- );
1802
- }
1803
- const anchor = {};
1804
- if (messageId !== void 0) {
1805
- anchor[_chunkRV7JIIDGcjs.MESSAGE_ID] = messageId;
1806
- }
1807
- if (sessionId !== void 0) {
1808
- anchor[_chunkRV7JIIDGcjs.SESSION_ID] = sessionId;
1809
- }
1810
- try {
1811
- if (Object.keys(anchor).length === 0) {
1812
- emitEvent(_chunkRV7JIIDGcjs.FEEDBACK_EVENT_NAME, eventAttributes);
1813
- } else {
1814
- callWithProperties(anchor, () => emitEvent(_chunkRV7JIIDGcjs.FEEDBACK_EVENT_NAME, eventAttributes));
1815
- }
1816
- } catch (error) {
1817
- _chunkWC573FCIcjs.logger.warn("recordFeedback: failed to emit feedback event", error);
1818
- }
1819
- }
1820
- var METRIC_NAME_PATTERN = /^[a-z][a-z0-9_.-]{0,63}$/;
1821
- var METRIC_COMMENT_MAX_LEN = 4096;
1822
- var METRIC_ATTRIBUTES_MAX = 20;
1823
- var METRIC_ATTRIBUTE_VALUE_MAX_LEN = 256;
1824
- function recordMetric(options) {
1825
- try {
1826
- recordMetricImpl(options);
1827
- } catch (error) {
1828
- _chunkWC573FCIcjs.logger.warn(`recordMetric(${JSON.stringify(_optionalChain([options, 'optionalAccess', _87 => _87.name]))}) failed; metric dropped.`, error);
1829
- }
1830
- }
1831
- function recordMetricImpl(options) {
1832
- const name = typeof options.name === "string" ? options.name.toLowerCase() : "";
1833
- if (!METRIC_NAME_PATTERN.test(name)) {
1834
- _chunkWC573FCIcjs.logger.warn(
1835
- `recordMetric called with an invalid name ${JSON.stringify(options.name)}; metric dropped. Names must match ${METRIC_NAME_PATTERN.source} after lowercasing.`
1836
- );
1837
- return;
1838
- }
1839
- if (_chunkRV7JIIDGcjs.RESERVED_METRIC_NAMES.has(name)) {
1840
- _chunkWC573FCIcjs.logger.warn(
1841
- `recordMetric called with the reserved name ${JSON.stringify(name)}; metric dropped. Brizz computes this metric itself \u2014 pick a different name.`
1842
- );
1843
- return;
1844
- }
1845
- const { value } = options;
1846
- let numericValue;
1847
- if (typeof value === "boolean") {
1848
- numericValue = value ? 1 : 0;
1849
- } else if (typeof value === "number" && Number.isFinite(value)) {
1850
- numericValue = value;
1851
- } else {
1852
- _chunkWC573FCIcjs.logger.warn(
1853
- `recordMetric(${name}) called with a non-finite or non-numeric value ${JSON.stringify(value)}; metric dropped.`
1854
- );
1855
- return;
1856
- }
1857
- if (options.serviceName !== void 0) {
1858
- const problem = serviceNameProblem(options.serviceName);
1859
- if (problem !== void 0) {
1860
- _chunkWC573FCIcjs.logger.warn(`recordMetric(${name}) service name ${problem}; metric dropped.`);
1861
- return;
1862
- }
1863
- }
1864
- const scope = _nullishCoalesce(options.scope, () => ( _chunkRV7JIIDGcjs.METRIC_SCOPE_SESSION));
1865
- if (scope !== _chunkRV7JIIDGcjs.METRIC_SCOPE_SESSION && scope !== _chunkRV7JIIDGcjs.METRIC_SCOPE_TRACE) {
1866
- _chunkWC573FCIcjs.logger.warn(
1867
- `recordMetric(${name}) called with an invalid scope ${JSON.stringify(scope)}; expected '${_chunkRV7JIIDGcjs.METRIC_SCOPE_SESSION}' or '${_chunkRV7JIIDGcjs.METRIC_SCOPE_TRACE}'. Metric dropped.`
1868
- );
1869
- return;
1870
- }
1871
- const eventAttributes = {
1872
- [_chunkRV7JIIDGcjs.METRIC_NAME]: name,
1873
- [_chunkRV7JIIDGcjs.METRIC_VALUE]: numericValue
1874
- };
1875
- if (options.scope !== void 0) {
1876
- eventAttributes[_chunkRV7JIIDGcjs.METRIC_SCOPE] = scope;
1877
- }
1878
- if (options.unit !== void 0) {
1879
- eventAttributes[_chunkRV7JIIDGcjs.METRIC_UNIT] = options.unit;
1880
- }
1881
- if (options.minValue !== void 0) {
1882
- eventAttributes[_chunkRV7JIIDGcjs.METRIC_MIN] = options.minValue;
1883
- }
1884
- if (options.maxValue !== void 0) {
1885
- eventAttributes[_chunkRV7JIIDGcjs.METRIC_MAX] = options.maxValue;
1886
- }
1887
- if (options.comment !== void 0) {
1888
- let comment = options.comment;
1889
- if (comment.length > METRIC_COMMENT_MAX_LEN) {
1890
- _chunkWC573FCIcjs.logger.warn(
1891
- `recordMetric(${name}) comment exceeds ${METRIC_COMMENT_MAX_LEN} characters; truncated.`
1892
- );
1893
- comment = comment.slice(0, METRIC_COMMENT_MAX_LEN);
1894
- }
1895
- eventAttributes[_chunkRV7JIIDGcjs.METRIC_COMMENT] = comment;
1896
- }
1897
- if (options.polarity !== void 0) {
1898
- const polarity = options.polarity;
1899
- if (polarity === _chunkRV7JIIDGcjs.METRIC_POLARITY_POSITIVE || polarity === _chunkRV7JIIDGcjs.METRIC_POLARITY_NEGATIVE) {
1900
- eventAttributes[_chunkRV7JIIDGcjs.METRIC_POLARITY] = polarity;
1901
- } else {
1902
- _chunkWC573FCIcjs.logger.warn(
1903
- `recordMetric(${name}) called with an invalid polarity ${JSON.stringify(polarity)}; expected '${_chunkRV7JIIDGcjs.METRIC_POLARITY_POSITIVE}' or '${_chunkRV7JIIDGcjs.METRIC_POLARITY_NEGATIVE}'. Emitting the metric without it.`
1904
- );
1905
- }
1906
- }
1907
- if (options.timestamp !== void 0) {
1908
- if (Number.isFinite(options.timestamp.getTime())) {
1909
- eventAttributes[_chunkRV7JIIDGcjs.METRIC_TIMESTAMP] = options.timestamp.toISOString();
1910
- } else {
1911
- _chunkWC573FCIcjs.logger.warn(
1912
- `recordMetric(${name}) called with an invalid timestamp; emitting the metric without it.`
1913
- );
1914
- }
1915
- }
1916
- if (options.attributes) {
1917
- let accepted = 0;
1918
- for (const [key, attrValue] of Object.entries(options.attributes)) {
1919
- if (accepted >= METRIC_ATTRIBUTES_MAX) {
1920
- _chunkWC573FCIcjs.logger.warn(
1921
- `recordMetric(${name}) called with more than ${METRIC_ATTRIBUTES_MAX} attributes; the excess was dropped.`
1922
- );
1923
- break;
1924
- }
1925
- const normalizedKey = key.toLowerCase();
1926
- if (!METRIC_NAME_PATTERN.test(normalizedKey)) {
1927
- _chunkWC573FCIcjs.logger.warn(
1928
- `recordMetric(${name}) called with an invalid attribute key ${JSON.stringify(key)}; that attribute was dropped. Keys must match ${METRIC_NAME_PATTERN.source} after lowercasing.`
1929
- );
1930
- continue;
1931
- }
1932
- let text2 = typeof attrValue === "string" ? attrValue : String(attrValue);
1933
- if (text2.length > METRIC_ATTRIBUTE_VALUE_MAX_LEN) {
1934
- _chunkWC573FCIcjs.logger.warn(
1935
- `recordMetric(${name}) attribute ${JSON.stringify(normalizedKey)} exceeds ${METRIC_ATTRIBUTE_VALUE_MAX_LEN} characters; truncated.`
1936
- );
1937
- text2 = text2.slice(0, METRIC_ATTRIBUTE_VALUE_MAX_LEN);
1938
- }
1939
- eventAttributes[`${_chunkRV7JIIDGcjs.METRIC_ATTRIBUTE_PREFIX}${normalizedKey}`] = text2;
1940
- accepted += 1;
1941
- }
1942
- }
1943
- const traceId = typeof options.traceId === "string" && options.traceId !== "" ? options.traceId : void 0;
1944
- if (traceId !== void 0) {
1945
- eventAttributes[_chunkRV7JIIDGcjs.METRIC_TRACE_ID] = traceId;
1946
- }
1947
- if (scope === _chunkRV7JIIDGcjs.METRIC_SCOPE_TRACE && traceId === void 0) {
1948
- const spanContext = _optionalChain([_api.trace, 'access', _88 => _88.getActiveSpan, 'call', _89 => _89(), 'optionalAccess', _90 => _90.spanContext, 'call', _91 => _91()]);
1949
- if (!spanContext || !_api.isSpanContextValid.call(void 0, spanContext)) {
1950
- _chunkWC573FCIcjs.logger.warn(
1951
- `recordMetric(${name}) called with scope 'trace' but no trace; metric dropped. Pass options.traceId, or call inside the span of the trace being scored.`
1952
- );
1953
- return;
1954
- }
1955
- eventAttributes[_chunkRV7JIIDGcjs.METRIC_TRACE_ID] = spanContext.traceId;
1956
- }
1957
- const sessionId = _nullishCoalesce(options.sessionId, () => ( (traceId === void 0 ? resolveSessionIdFromContext() : void 0)));
1958
- if (sessionId === void 0 && traceId === void 0) {
1959
- _chunkWC573FCIcjs.logger.warn(
1960
- `recordMetric(${name}) called with no resolvable session id or trace id; the metric cannot be attributed to a conversation and is dropped. Pass options.sessionId or options.traceId, or call inside a startSession/callWithSessionId scope.`
1961
- );
1962
- return;
1963
- }
1964
- const base = _api.context.active();
1965
- const ambient = base.getValue(_chunkRV7JIIDGcjs.PROPERTIES_CONTEXT_KEY);
1966
- const properties = { ...ambient };
1967
- if (sessionId === void 0) {
1968
- delete properties[_chunkRV7JIIDGcjs.SESSION_ID];
1969
- delete properties[_chunkRV7JIIDGcjs.MESSAGE_ID];
1970
- } else {
1971
- properties[_chunkRV7JIIDGcjs.SESSION_ID] = sessionId;
1972
- }
1973
- if (options.serviceName !== void 0) {
1974
- properties[_chunkRV7JIIDGcjs.SERVICE_NAME] = options.serviceName;
1975
- }
1976
- try {
1977
- _api.context.with(
1978
- base.setValue(_chunkRV7JIIDGcjs.PROPERTIES_CONTEXT_KEY, properties),
1979
- () => emitEvent(_chunkRV7JIIDGcjs.METRIC_EVENT_NAME, eventAttributes)
1980
- );
1981
- } catch (error) {
1982
- _chunkWC573FCIcjs.logger.warn("recordMetric: failed to emit metric event", error);
1983
- }
1984
- }
1985
- function startSession(sessionId, callback, extraProperties, options) {
1986
- const isTitle = _optionalChain([options, 'optionalAccess', _92 => _92.mode]) === "title";
1987
- const spanName = isTitle ? _chunkRV7JIIDGcjs.SESSION_TITLE_SPAN_NAME : _chunkRV7JIIDGcjs.SESSION_SPAN_NAME;
1988
- return sessionTracer.startActiveSpan(spanName, (span) => {
1989
- span.setAttribute(`${_chunkRV7JIIDGcjs.BRIZZ}.${_chunkRV7JIIDGcjs.SESSION_ID}`, sessionId);
1990
- if (extraProperties) {
1991
- for (const [key, value] of Object.entries(extraProperties)) {
1992
- span.setAttribute(`${_chunkRV7JIIDGcjs.BRIZZ}.${key}`, value);
1993
- }
1994
- }
1995
- const session = new Session(sessionId, span);
1996
- const contextProperties = { [_chunkRV7JIIDGcjs.SESSION_ID]: sessionId };
1997
- if (isTitle) {
1998
- contextProperties[_chunkRV7JIIDGcjs.SESSION_TITLE_GENERATION] = "true";
1999
- }
2000
- if (extraProperties) {
2001
- for (const [key, value] of Object.entries(extraProperties)) {
2002
- contextProperties[key] = String(value);
2003
- }
2004
- }
2005
- return callWithProperties(contextProperties, () => {
2006
- const sessionCtx = _api.context.active().setValue(_chunkRV7JIIDGcjs.SESSION_OBJECT_CONTEXT_KEY, session);
2007
- return _api.context.with(sessionCtx, () => {
2008
- try {
2009
- const result = callback(session);
2010
- if (result && typeof result.then === "function") {
2011
- return result.then((value) => {
2012
- span.end();
2013
- return value;
2014
- }).catch((error) => {
2015
- span.recordException(error);
2016
- span.setStatus({ code: _api.SpanStatusCode.ERROR });
2017
- span.end();
2018
- throw error;
2019
- });
2020
- }
2021
- span.end();
2022
- return result;
2023
- } catch (error) {
2024
- span.recordException(error);
2025
- span.setStatus({ code: _api.SpanStatusCode.ERROR });
2026
- span.end();
2027
- throw error;
2028
- }
2029
- });
2030
- });
2031
- });
2032
- }
2033
- function startSessionTitle(callback, options) {
2034
- const resolvedSessionId = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _93 => _93.sessionId]), () => ( _optionalChain([getActiveSession, 'call', _94 => _94(), 'optionalAccess', _95 => _95.sessionId])));
2035
- return sessionTracer.startActiveSpan(_chunkRV7JIIDGcjs.SESSION_TITLE_SPAN_NAME, (span) => {
2036
- if (resolvedSessionId) {
2037
- span.setAttribute(`${_chunkRV7JIIDGcjs.BRIZZ}.${_chunkRV7JIIDGcjs.SESSION_ID}`, resolvedSessionId);
2038
- }
2039
- const sessionTitle = new SessionTitle(span);
2040
- const properties = { [_chunkRV7JIIDGcjs.SESSION_TITLE_GENERATION]: "true" };
2041
- if (resolvedSessionId) {
2042
- properties[_chunkRV7JIIDGcjs.SESSION_ID] = resolvedSessionId;
2043
- }
2044
- return callWithProperties(properties, () => {
2045
- try {
2046
- const result = callback(sessionTitle);
2047
- if (result && typeof result.then === "function") {
2048
- return result.then((value) => {
2049
- span.end();
2050
- return value;
2051
- }).catch((error) => {
2052
- span.recordException(error);
2053
- span.setStatus({ code: _api.SpanStatusCode.ERROR });
2054
- span.end();
2055
- throw error;
2056
- });
2057
- }
2058
- span.end();
2059
- return result;
2060
- } catch (error) {
2061
- span.recordException(error);
2062
- span.setStatus({ code: _api.SpanStatusCode.ERROR });
2063
- span.end();
2064
- throw error;
2065
- }
2066
- });
2067
- });
2068
- }
2069
-
2070
1366
  // src/internal/log/processors/log-processor.ts
2071
1367
 
2072
1368
 
@@ -2504,14 +1800,14 @@ var BrizzSimpleLogRecordProcessor = class extends _sdklogs.SimpleLogRecordProces
2504
1800
  this.config = config;
2505
1801
  }
2506
1802
  onEmit(logRecord) {
2507
- const maskingConfig = _optionalChain([this, 'access', _96 => _96.config, 'access', _97 => _97.masking, 'optionalAccess', _98 => _98.eventMasking]);
1803
+ const maskingConfig = _optionalChain([this, 'access', _70 => _70.config, 'access', _71 => _71.masking, 'optionalAccess', _72 => _72.eventMasking]);
2508
1804
  if (maskingConfig) {
2509
1805
  maskLog(logRecord, maskingConfig);
2510
1806
  }
2511
- const associationProperties = _api.context.active().getValue(_chunkRV7JIIDGcjs.PROPERTIES_CONTEXT_KEY);
1807
+ const associationProperties = _api.context.active().getValue(_chunkNF52RMLWcjs.PROPERTIES_CONTEXT_KEY);
2512
1808
  if (associationProperties) {
2513
1809
  for (const [key, value] of Object.entries(associationProperties)) {
2514
- logRecord.setAttribute(`${_chunkRV7JIIDGcjs.BRIZZ}.${key}`, value);
1810
+ logRecord.setAttribute(`${_chunkNF52RMLWcjs.BRIZZ}.${key}`, value);
2515
1811
  }
2516
1812
  }
2517
1813
  super.onEmit(logRecord);
@@ -2524,14 +1820,14 @@ var BrizzBatchLogRecordProcessor = class extends _sdklogs.BatchLogRecordProcesso
2524
1820
  this.config = config;
2525
1821
  }
2526
1822
  onEmit(logRecord) {
2527
- const maskingConfig = _optionalChain([this, 'access', _99 => _99.config, 'access', _100 => _100.masking, 'optionalAccess', _101 => _101.eventMasking]);
1823
+ const maskingConfig = _optionalChain([this, 'access', _73 => _73.config, 'access', _74 => _74.masking, 'optionalAccess', _75 => _75.eventMasking]);
2528
1824
  if (maskingConfig) {
2529
1825
  maskLog(logRecord, maskingConfig);
2530
1826
  }
2531
- const associationProperties = _api.context.active().getValue(_chunkRV7JIIDGcjs.PROPERTIES_CONTEXT_KEY);
1827
+ const associationProperties = _api.context.active().getValue(_chunkNF52RMLWcjs.PROPERTIES_CONTEXT_KEY);
2532
1828
  if (associationProperties) {
2533
1829
  for (const [key, value] of Object.entries(associationProperties)) {
2534
- logRecord.setAttribute(`${_chunkRV7JIIDGcjs.BRIZZ}.${key}`, value);
1830
+ logRecord.setAttribute(`${_chunkNF52RMLWcjs.BRIZZ}.${key}`, value);
2535
1831
  }
2536
1832
  }
2537
1833
  super.onEmit(logRecord);
@@ -2558,7 +1854,7 @@ function maskLog(logRecord, config) {
2558
1854
  newAttributes[key] = value;
2559
1855
  }
2560
1856
  for (const [key, value] of Object.entries(logRecord.attributes)) {
2561
- if (key.startsWith(_chunkRV7JIIDGcjs.INTERNAL_EVENT_PREFIX)) {
1857
+ if (key.startsWith(_chunkNF52RMLWcjs.INTERNAL_EVENT_PREFIX)) {
2562
1858
  newAttributes[key] = value;
2563
1859
  }
2564
1860
  }
@@ -2580,7 +1876,7 @@ function maskLog(logRecord, config) {
2580
1876
  }
2581
1877
 
2582
1878
  // src/internal/log/logging.ts
2583
- var LoggingModule = (_class3 = class _LoggingModule {constructor() { _class3.prototype.__init6.call(this);_class3.prototype.__init7.call(this);_class3.prototype.__init8.call(this); }
1879
+ var LoggingModule = (_class2 = class _LoggingModule {constructor() { _class2.prototype.__init2.call(this);_class2.prototype.__init3.call(this);_class2.prototype.__init4.call(this); }
2584
1880
  static __initStatic() {this.instance = null}
2585
1881
  static getInstance() {
2586
1882
  if (!this.instance) {
@@ -2588,10 +1884,10 @@ var LoggingModule = (_class3 = class _LoggingModule {constructor() { _class3.pro
2588
1884
  }
2589
1885
  return this.instance;
2590
1886
  }
2591
- __init6() {this.config = null}
2592
- __init7() {this.loggerProvider = null}
1887
+ __init2() {this.config = null}
1888
+ __init3() {this.loggerProvider = null}
2593
1889
  /** Providers for scoped service names, keyed by service name. */
2594
- __init8() {this.scopedProviders = /* @__PURE__ */ new Map()}
1890
+ __init4() {this.scopedProviders = /* @__PURE__ */ new Map()}
2595
1891
  /**
2596
1892
  * Build the log exporter for a service. The service header is fixed per
2597
1893
  * exporter and the gateway rewrites service.name from it, so each service
@@ -2625,14 +1921,14 @@ var LoggingModule = (_class3 = class _LoggingModule {constructor() { _class3.pro
2625
1921
  _chunkWC573FCIcjs.logger.debug("Creating logger provider", {
2626
1922
  serviceName,
2627
1923
  disableBatch: config.disableBatch,
2628
- hasMasking: !!_optionalChain([config, 'access', _102 => _102.masking, 'optionalAccess', _103 => _103.eventMasking])
1924
+ hasMasking: !!_optionalChain([config, 'access', _76 => _76.masking, 'optionalAccess', _77 => _77.eventMasking])
2629
1925
  });
2630
1926
  const exporter = this.createLogExporter(config, serviceName);
2631
1927
  const processor = config.disableBatch ? new BrizzSimpleLogRecordProcessor(exporter, config) : new BrizzBatchLogRecordProcessor(exporter, config);
2632
1928
  const resourceAttributes = {
2633
1929
  ...config.resourceAttributes,
2634
1930
  "service.name": serviceName,
2635
- [BRIZZ_SDK_VERSION]: _chunkDCXOK7PXcjs.getSDKVersion.call(void 0, ),
1931
+ [BRIZZ_SDK_VERSION]: _chunk5QZM5EVPcjs.getSDKVersion.call(void 0, ),
2636
1932
  [BRIZZ_SDK_LANGUAGE]: SDK_LANGUAGE
2637
1933
  };
2638
1934
  if (config.environment) {
@@ -2651,7 +1947,7 @@ var LoggingModule = (_class3 = class _LoggingModule {constructor() { _class3.pro
2651
1947
  * `callWithServiceName`, else the configured appName.
2652
1948
  */
2653
1949
  activeLoggerProvider() {
2654
- const serviceName = resolveServiceNameFromContext();
1950
+ const serviceName = _chunk4QNEI7VZcjs.resolveServiceNameFromContext.call(void 0, );
2655
1951
  if (!serviceName || !this.config || serviceName === this.config.appName) {
2656
1952
  return this.loggerProvider;
2657
1953
  }
@@ -2674,6 +1970,7 @@ var LoggingModule = (_class3 = class _LoggingModule {constructor() { _class3.pro
2674
1970
  this.loggerProvider = this.createLoggerProvider(config, config.appName);
2675
1971
  }
2676
1972
  _LoggingModule.instance = this;
1973
+ _chunk4QNEI7VZcjs.setEventSink.call(void 0, this);
2677
1974
  _chunkWC573FCIcjs.logger.info("Logging module setup completed");
2678
1975
  }
2679
1976
  /**
@@ -2733,7 +2030,7 @@ var LoggingModule = (_class3 = class _LoggingModule {constructor() { _class3.pro
2733
2030
  }
2734
2031
  async forceFlush() {
2735
2032
  await Promise.all(
2736
- [...this.scopedProviders.values(), this.loggerProvider].map(async (p) => _optionalChain([p, 'optionalAccess', _104 => _104.forceFlush, 'call', _105 => _105()]))
2033
+ [...this.scopedProviders.values(), this.loggerProvider].map(async (p) => _optionalChain([p, 'optionalAccess', _78 => _78.forceFlush, 'call', _79 => _79()]))
2737
2034
  );
2738
2035
  }
2739
2036
  /**
@@ -2751,22 +2048,15 @@ var LoggingModule = (_class3 = class _LoggingModule {constructor() { _class3.pro
2751
2048
  if (_LoggingModule.instance === this) {
2752
2049
  _LoggingModule.instance = null;
2753
2050
  }
2051
+ _chunk4QNEI7VZcjs.clearEventSink.call(void 0, this);
2754
2052
  _chunkWC573FCIcjs.logger.debug("Logging module shutdown completed");
2755
2053
  }
2756
- }, _class3.__initStatic(), _class3);
2757
- function emitEvent(name, attributes, body, severityNumber = _api.SeverityNumber.INFO) {
2758
- return LoggingModule.getInstance().emitEvent(name, attributes, body, severityNumber);
2759
- }
2760
- function emitEventWithSessionId(sessionId, name, attributes, body, severityNumber = _api.SeverityNumber.INFO) {
2761
- return callWithSessionId(sessionId, () => {
2762
- LoggingModule.getInstance().emitEvent(name, attributes, body, severityNumber);
2763
- });
2764
- }
2054
+ }, _class2.__initStatic(), _class2);
2765
2055
 
2766
2056
  // src/internal/metric/metrics.ts
2767
2057
  var _exportermetricsotlphttp = require('@opentelemetry/exporter-metrics-otlp-http');
2768
2058
 
2769
- var MetricsModule = (_class4 = class _MetricsModule {constructor() { _class4.prototype.__init9.call(this);_class4.prototype.__init10.call(this); }
2059
+ var MetricsModule = (_class3 = class _MetricsModule {constructor() { _class3.prototype.__init5.call(this);_class3.prototype.__init6.call(this); }
2770
2060
  static __initStatic2() {this.instance = null}
2771
2061
  static getInstance() {
2772
2062
  if (!this.instance) {
@@ -2774,8 +2064,8 @@ var MetricsModule = (_class4 = class _MetricsModule {constructor() { _class4.pro
2774
2064
  }
2775
2065
  return this.instance;
2776
2066
  }
2777
- __init9() {this.metricsExporter = null}
2778
- __init10() {this.metricsReader = null}
2067
+ __init5() {this.metricsExporter = null}
2068
+ __init6() {this.metricsReader = null}
2779
2069
  /**
2780
2070
  * Initialize the metrics exporter
2781
2071
  */
@@ -2846,7 +2136,7 @@ var MetricsModule = (_class4 = class _MetricsModule {constructor() { _class4.pro
2846
2136
  return this.metricsReader;
2847
2137
  }
2848
2138
  async forceFlush() {
2849
- await _optionalChain([this, 'access', _106 => _106.metricsReader, 'optionalAccess', _107 => _107.forceFlush, 'call', _108 => _108()]);
2139
+ await _optionalChain([this, 'access', _80 => _80.metricsReader, 'optionalAccess', _81 => _81.forceFlush, 'call', _82 => _82()]);
2850
2140
  }
2851
2141
  /**
2852
2142
  * Shutdown the metrics module
@@ -2860,7 +2150,7 @@ var MetricsModule = (_class4 = class _MetricsModule {constructor() { _class4.pro
2860
2150
  }
2861
2151
  _chunkWC573FCIcjs.logger.debug("Metrics module shutdown completed");
2862
2152
  }
2863
- }, _class4.__initStatic2(), _class4);
2153
+ }, _class3.__initStatic2(), _class3);
2864
2154
  function getMetricsExporter() {
2865
2155
  return MetricsModule.getInstance().getMetricsExporter();
2866
2156
  }
@@ -2874,22 +2164,22 @@ var _exportertraceotlpproto = require('@opentelemetry/exporter-trace-otlp-proto'
2874
2164
  // src/internal/trace/exporters/span-exporter.ts
2875
2165
  var _core = require('@opentelemetry/core');
2876
2166
 
2877
- var BrizzSpanExporter = (_class5 = class {
2167
+ var BrizzSpanExporter = (_class4 = class {
2878
2168
 
2879
2169
 
2880
2170
 
2881
2171
 
2882
- __init11() {this._resources = /* @__PURE__ */ new Map()}
2883
- __init12() {this._delegates = /* @__PURE__ */ new Map()}
2172
+ __init7() {this._resources = /* @__PURE__ */ new Map()}
2173
+ __init8() {this._delegates = /* @__PURE__ */ new Map()}
2884
2174
 
2885
- constructor(delegate, config, factory) {;_class5.prototype.__init11.call(this);_class5.prototype.__init12.call(this);
2175
+ constructor(delegate, config, factory) {;_class4.prototype.__init7.call(this);_class4.prototype.__init8.call(this);
2886
2176
  this._delegate = delegate;
2887
2177
  this._delegateFactory = factory;
2888
2178
  this._defaultServiceName = config.appName;
2889
2179
  const resourceAttrs = {
2890
2180
  ...config.resourceAttributes,
2891
2181
  "service.name": config.appName,
2892
- [BRIZZ_SDK_VERSION]: _chunkDCXOK7PXcjs.getSDKVersion.call(void 0, ),
2182
+ [BRIZZ_SDK_VERSION]: _chunk5QZM5EVPcjs.getSDKVersion.call(void 0, ),
2893
2183
  [BRIZZ_SDK_LANGUAGE]: SDK_LANGUAGE
2894
2184
  };
2895
2185
  if (config.environment) {
@@ -2903,7 +2193,7 @@ var BrizzSpanExporter = (_class5 = class {
2903
2193
  }
2904
2194
  /** The service a span reports under: its scoped override, else the configured appName. */
2905
2195
  _serviceNameOf(span) {
2906
- const value = span.attributes[_chunkRV7JIIDGcjs.SERVICE_NAME_ATTRIBUTE];
2196
+ const value = span.attributes[_chunkNF52RMLWcjs.SERVICE_NAME_ATTRIBUTE];
2907
2197
  return typeof value === "string" && value !== "" ? value : this._defaultServiceName;
2908
2198
  }
2909
2199
  _resourceFor(serviceName) {
@@ -3016,11 +2306,11 @@ var BrizzSpanExporter = (_class5 = class {
3016
2306
  }
3017
2307
  async forceFlush() {
3018
2308
  await Promise.all([
3019
- _optionalChain([this, 'access', _109 => _109._delegate, 'access', _110 => _110.forceFlush, 'optionalCall', _111 => _111()]),
3020
- ...[...this._delegates.values()].map(async (delegate) => _optionalChain([delegate, 'access', _112 => _112.forceFlush, 'optionalCall', _113 => _113()]))
2309
+ _optionalChain([this, 'access', _83 => _83._delegate, 'access', _84 => _84.forceFlush, 'optionalCall', _85 => _85()]),
2310
+ ...[...this._delegates.values()].map(async (delegate) => _optionalChain([delegate, 'access', _86 => _86.forceFlush, 'optionalCall', _87 => _87()]))
3021
2311
  ]);
3022
2312
  }
3023
- }, _class5);
2313
+ }, _class4);
3024
2314
 
3025
2315
  // src/internal/trace/processors/span-processor.ts
3026
2316
 
@@ -3029,10 +2319,10 @@ var BrizzSpanExporter = (_class5 = class {
3029
2319
 
3030
2320
 
3031
2321
  function applyContextAttributes(span) {
3032
- const sessionProperties = _api.context.active().getValue(_chunkRV7JIIDGcjs.PROPERTIES_CONTEXT_KEY);
2322
+ const sessionProperties = _api.context.active().getValue(_chunkNF52RMLWcjs.PROPERTIES_CONTEXT_KEY);
3033
2323
  if (sessionProperties) {
3034
2324
  for (const [key, value] of Object.entries(sessionProperties)) {
3035
- span.setAttribute(`${_chunkRV7JIIDGcjs.BRIZZ}.${key}`, value);
2325
+ span.setAttribute(`${_chunkNF52RMLWcjs.BRIZZ}.${key}`, value);
3036
2326
  }
3037
2327
  }
3038
2328
  }
@@ -3075,7 +2365,7 @@ var BrizzSimpleSpanProcessor = class extends _sdktrace.SimpleSpanProcessor {
3075
2365
  }
3076
2366
  onEnd(span) {
3077
2367
  restampLangChainSpan(span);
3078
- const maskingConfig = _optionalChain([this, 'access', _114 => _114.config, 'access', _115 => _115.masking, 'optionalAccess', _116 => _116.spanMasking]);
2368
+ const maskingConfig = _optionalChain([this, 'access', _88 => _88.config, 'access', _89 => _89.masking, 'optionalAccess', _90 => _90.spanMasking]);
3079
2369
  if (maskingConfig) {
3080
2370
  maskReadableSpan(span, maskingConfig);
3081
2371
  }
@@ -3094,7 +2384,7 @@ var BrizzBatchSpanProcessor = class extends _sdktrace.BatchSpanProcessor {
3094
2384
  }
3095
2385
  onEnd(span) {
3096
2386
  restampLangChainSpan(span);
3097
- const maskingConfig = _optionalChain([this, 'access', _117 => _117.config, 'access', _118 => _118.masking, 'optionalAccess', _119 => _119.spanMasking]);
2387
+ const maskingConfig = _optionalChain([this, 'access', _91 => _91.config, 'access', _92 => _92.masking, 'optionalAccess', _93 => _93.spanMasking]);
3098
2388
  if (maskingConfig) {
3099
2389
  maskReadableSpan(span, maskingConfig);
3100
2390
  }
@@ -3111,7 +2401,7 @@ function maskReadableSpan(span, config) {
3111
2401
  for (const [k, v] of Object.entries(attrs)) {
3112
2402
  masked[k] = v;
3113
2403
  }
3114
- if (_optionalChain([config, 'access', _120 => _120.rules, 'optionalAccess', _121 => _121.length])) {
2404
+ if (_optionalChain([config, 'access', _94 => _94.rules, 'optionalAccess', _95 => _95.length])) {
3115
2405
  masked = maskAttributes(masked, config.rules);
3116
2406
  }
3117
2407
  if (!config.disableDefaultRules) {
@@ -3130,7 +2420,7 @@ function maskReadableSpan(span, config) {
3130
2420
  }
3131
2421
 
3132
2422
  // src/internal/trace/tracing.ts
3133
- var TracingModule = (_class6 = class _TracingModule {constructor() { _class6.prototype.__init13.call(this);_class6.prototype.__init14.call(this); }
2423
+ var TracingModule = (_class5 = class _TracingModule {constructor() { _class5.prototype.__init9.call(this);_class5.prototype.__init10.call(this); }
3134
2424
  static __initStatic3() {this.instance = null}
3135
2425
  static getInstance() {
3136
2426
  if (!this.instance) {
@@ -3138,8 +2428,8 @@ var TracingModule = (_class6 = class _TracingModule {constructor() { _class6.pro
3138
2428
  }
3139
2429
  return this.instance;
3140
2430
  }
3141
- __init13() {this.spanExporter = null}
3142
- __init14() {this.spanProcessor = null}
2431
+ __init9() {this.spanExporter = null}
2432
+ __init10() {this.spanProcessor = null}
3143
2433
  /**
3144
2434
  * Initialize the span exporter
3145
2435
  */
@@ -3183,7 +2473,7 @@ var TracingModule = (_class6 = class _TracingModule {constructor() { _class6.pro
3183
2473
  }
3184
2474
  _chunkWC573FCIcjs.logger.debug("Initializing span processor", {
3185
2475
  disableBatch: config.disableBatch,
3186
- hasMasking: !!_optionalChain([config, 'access', _122 => _122.masking, 'optionalAccess', _123 => _123.spanMasking])
2476
+ hasMasking: !!_optionalChain([config, 'access', _96 => _96.masking, 'optionalAccess', _97 => _97.spanMasking])
3187
2477
  });
3188
2478
  const spanProcessor = config.disableBatch ? new BrizzSimpleSpanProcessor(this.spanExporter, config) : new BrizzBatchSpanProcessor(this.spanExporter, config);
3189
2479
  _chunkWC573FCIcjs.logger.debug("Span processor initialized successfully");
@@ -3227,7 +2517,7 @@ var TracingModule = (_class6 = class _TracingModule {constructor() { _class6.pro
3227
2517
  return this.spanProcessor;
3228
2518
  }
3229
2519
  async forceFlush() {
3230
- await _optionalChain([this, 'access', _124 => _124.spanProcessor, 'optionalAccess', _125 => _125.forceFlush, 'call', _126 => _126()]);
2520
+ await _optionalChain([this, 'access', _98 => _98.spanProcessor, 'optionalAccess', _99 => _99.forceFlush, 'call', _100 => _100()]);
3231
2521
  }
3232
2522
  async shutdown() {
3233
2523
  _chunkWC573FCIcjs.logger.debug("Shutting down tracing module");
@@ -3242,7 +2532,7 @@ var TracingModule = (_class6 = class _TracingModule {constructor() { _class6.pro
3242
2532
  _TracingModule.instance = null;
3243
2533
  _chunkWC573FCIcjs.logger.debug("Tracing module shutdown completed");
3244
2534
  }
3245
- }, _class6.__initStatic3(), _class6);
2535
+ }, _class5.__initStatic3(), _class5);
3246
2536
  function getSpanExporter() {
3247
2537
  return TracingModule.getInstance().getSpanExporter();
3248
2538
  }
@@ -3250,131 +2540,153 @@ function getSpanProcessor() {
3250
2540
  return TracingModule.getInstance().getSpanProcessor();
3251
2541
  }
3252
2542
 
3253
- // src/internal/trace/agent.ts
3254
- var _crypto = require('crypto');
2543
+ // src/internal/trace/decision-call.ts
3255
2544
 
3256
- function newInstanceId() {
3257
- return _crypto.randomUUID.call(void 0, ).replaceAll("-", "").slice(0, 8);
3258
- }
3259
- function activeProperties() {
3260
- return _nullishCoalesce(_api.context.active().getValue(_chunkRV7JIIDGcjs.PROPERTIES_CONTEXT_KEY), () => ( {}));
3261
- }
3262
- function encodeToken(agent) {
3263
- const payload = {
3264
- id: agent.id,
3265
- parentId: agent.parentId,
3266
- name: agent.name,
3267
- traceparent: agent.traceparent,
3268
- sessionId: agent.sessionId
3269
- };
3270
- return Buffer.from(JSON.stringify(payload), "utf8").toString("base64url");
2545
+
2546
+ var tracer = _chunkDC2MFO65cjs.brizzTracerProvider.getTracer("@brizz/sdk/decision-call", _chunk5QZM5EVPcjs.getSDKVersion.call(void 0, ));
2547
+ function decisionCall(options, callback) {
2548
+ const span = startDecisionSpan(options);
2549
+ if (!span) {
2550
+ return callback(describeResultOn(void 0, options.provider));
2551
+ }
2552
+ const callbackContext = _core.suppressTracing.call(void 0, _api.trace.setSpan(_api.context.active(), span));
2553
+ let result;
2554
+ try {
2555
+ result = _api.context.with(
2556
+ callbackContext,
2557
+ callback,
2558
+ void 0,
2559
+ describeResultOn(span, options.provider)
2560
+ );
2561
+ } catch (error) {
2562
+ endWithError(span, error);
2563
+ throw error;
2564
+ }
2565
+ return endWhenSettled(span, result);
3271
2566
  }
3272
- function currentTraceparent() {
3273
- const carrier = {};
2567
+ function recordDecisionCall(record) {
3274
2568
  try {
3275
- _chunkDC2MFO65cjs.injectTraceContext.call(void 0, _api.context.active(), carrier);
3276
- } catch (e7) {
3277
- }
3278
- return _nullishCoalesce(carrier["traceparent"], () => ( ""));
3279
- }
3280
- function agentHandle(id, parentId, name) {
3281
- const opened = {
3282
- id,
3283
- parentId,
3284
- name,
3285
- traceparent: currentTraceparent(),
3286
- sessionId: _nullishCoalesce(activeProperties()[_chunkRV7JIIDGcjs.SESSION_ID], () => ( ""))
3287
- };
3288
- return {
3289
- ...opened,
3290
- get token() {
3291
- return encodeToken(opened);
2569
+ const span = startDecisionSpan(record, _nullishCoalesce(record.startTime, () => ( record.endTime)));
2570
+ if (!span) {
2571
+ return;
3292
2572
  }
3293
- };
2573
+ const call = describeResultOn(span, record.provider);
2574
+ if (record.answers !== void 0) {
2575
+ call.setAnswers(record.answers);
2576
+ }
2577
+ call.setUsage(record);
2578
+ if (record.costUsd !== void 0) {
2579
+ call.setCost(record.costUsd);
2580
+ }
2581
+ span.end(record.endTime);
2582
+ } catch (error) {
2583
+ _chunkWC573FCIcjs.logger.debug(`Brizz decision call: could not record the call: ${String(error)}`);
2584
+ }
3294
2585
  }
3295
- function decodeToken(token) {
2586
+ function startDecisionSpan(options, startTime) {
3296
2587
  try {
3297
- const payload = JSON.parse(Buffer.from(token, "base64url").toString("utf8"));
3298
- return payload.id ? payload : void 0;
3299
- } catch (e8) {
2588
+ const requestModel = options.requestModel || options.model;
2589
+ const attributes = {
2590
+ [_chunkNF52RMLWcjs.GEN_AI_OPERATION_NAME]: _chunkNF52RMLWcjs.GEN_AI_OPERATION_CLASSIFY,
2591
+ [_chunkNF52RMLWcjs.GEN_AI_PROVIDER_NAME]: options.provider,
2592
+ [_chunkNF52RMLWcjs.GEN_AI_REQUEST_MODEL]: requestModel,
2593
+ [_chunkNF52RMLWcjs.GEN_AI_RESPONSE_MODEL]: options.model,
2594
+ [_chunkNF52RMLWcjs.GEN_AI_OUTPUT_TYPE]: "json"
2595
+ };
2596
+ const inputMessages = toJson([
2597
+ {
2598
+ role: "user",
2599
+ parts: [
2600
+ { type: "text", content: text(options.state) },
2601
+ { type: `${options.provider}.questions`, content: options.questions }
2602
+ ]
2603
+ }
2604
+ ]);
2605
+ if (inputMessages !== void 0) {
2606
+ attributes[_chunkNF52RMLWcjs.GEN_AI_INPUT_MESSAGES] = inputMessages;
2607
+ }
2608
+ const sessionId = currentSessionId();
2609
+ if (sessionId) {
2610
+ attributes[_chunkNF52RMLWcjs.GEN_AI_CONVERSATION_ID] = sessionId;
2611
+ }
2612
+ return tracer.startSpan(`${_chunkNF52RMLWcjs.GEN_AI_OPERATION_CLASSIFY} ${requestModel}`, {
2613
+ kind: _api.SpanKind.CLIENT,
2614
+ attributes,
2615
+ startTime
2616
+ });
2617
+ } catch (error) {
2618
+ _chunkWC573FCIcjs.logger.debug(`Brizz decision call: could not start span: ${String(error)}`);
3300
2619
  return void 0;
3301
2620
  }
3302
2621
  }
3303
- function unreadableAgent(agent) {
3304
- return {
3305
- id: "",
3306
- parentId: "",
3307
- name: "",
3308
- traceparent: "",
3309
- sessionId: "",
3310
- token: typeof agent === "string" ? "" : _nullishCoalesce(agent.token, () => ( ""))
3311
- };
2622
+ function currentSessionId() {
2623
+ const properties = _api.context.active().getValue(_chunkNF52RMLWcjs.PROPERTIES_CONTEXT_KEY);
2624
+ return _optionalChain([properties, 'optionalAccess', _101 => _101[_chunkNF52RMLWcjs.SESSION_ID]]);
3312
2625
  }
3313
- function resolveAgent(agent) {
3314
- const options = typeof agent === "string" ? { name: agent } : agent;
3315
- let id;
3316
- let parentId;
3317
- let name;
3318
- let sessionId = "";
3319
- let parentContext = _api.context.active();
3320
- if (options.token === void 0) {
3321
- id = options.id || newInstanceId();
3322
- parentId = options.parentId || activeProperties()[_chunkRV7JIIDGcjs.AGENT_ID] || "";
3323
- name = _nullishCoalesce(options.name, () => ( ""));
3324
- } else {
3325
- const decoded = decodeToken(options.token);
3326
- if (!decoded) {
3327
- _chunkWC573FCIcjs.logger.warn("Brizz: ignoring an unreadable agent token");
3328
- return void 0;
2626
+ function describeResultOn(span, provider) {
2627
+ const set = (key, value) => {
2628
+ if (!span || value === void 0) {
2629
+ return;
3329
2630
  }
3330
- id = decoded.id;
3331
- parentId = decoded.parentId;
3332
- name = decoded.name;
3333
- sessionId = decoded.sessionId;
3334
- if (decoded.traceparent) {
3335
- try {
3336
- parentContext = _chunkDC2MFO65cjs.extractTraceContext.call(void 0, parentContext, { traceparent: decoded.traceparent });
3337
- } catch (e9) {
3338
- }
2631
+ try {
2632
+ span.setAttribute(key, value);
2633
+ } catch (error) {
2634
+ _chunkWC573FCIcjs.logger.debug(`Brizz decision call: could not set ${key}: ${String(error)}`);
3339
2635
  }
3340
- }
3341
- const properties = { [_chunkRV7JIIDGcjs.AGENT_ID]: id, [_chunkRV7JIIDGcjs.AGENT_NAME]: name };
3342
- if (parentId) {
3343
- properties[_chunkRV7JIIDGcjs.AGENT_PARENT_ID] = parentId;
3344
- }
3345
- if (sessionId) {
3346
- properties[_chunkRV7JIIDGcjs.SESSION_ID] = sessionId;
3347
- }
3348
- return { id, parentId, name, properties, parentContext };
2636
+ };
2637
+ return {
2638
+ setAnswers(answers) {
2639
+ set(
2640
+ _chunkNF52RMLWcjs.GEN_AI_OUTPUT_MESSAGES,
2641
+ toJson([
2642
+ {
2643
+ role: "assistant",
2644
+ parts: [{ type: `${provider}.answers`, content: answers }],
2645
+ finish_reason: "stop"
2646
+ }
2647
+ ])
2648
+ );
2649
+ },
2650
+ setUsage(usage) {
2651
+ set(_chunkNF52RMLWcjs.GEN_AI_USAGE_INPUT_TOKENS, finiteNumber(_optionalChain([usage, 'optionalAccess', _102 => _102.inputTokens])));
2652
+ set(_chunkNF52RMLWcjs.GEN_AI_USAGE_OUTPUT_TOKENS, finiteNumber(_optionalChain([usage, 'optionalAccess', _103 => _103.outputTokens])));
2653
+ },
2654
+ setCost(costUsd) {
2655
+ set(_chunkNF52RMLWcjs.GEN_AI_USAGE_COST_USD, finiteNumber(costUsd));
2656
+ }
2657
+ };
3349
2658
  }
3350
- function startAgent(agent, callback) {
3351
- const resolved = resolveAgent(agent);
3352
- if (!resolved) {
3353
- return callback(unreadableAgent(agent));
2659
+ function endWhenSettled(span, result) {
2660
+ if (typeof _optionalChain([result, 'optionalAccess', _104 => _104.then]) !== "function") {
2661
+ span.end();
2662
+ return result;
3354
2663
  }
3355
- const { id, parentId, name, properties, parentContext } = resolved;
3356
- return _api.context.with(
3357
- parentContext,
3358
- () => callWithProperties(properties, () => callback(agentHandle(id, parentId, name)))
2664
+ return Promise.resolve(result).then(
2665
+ (value) => {
2666
+ span.end();
2667
+ return value;
2668
+ },
2669
+ (error) => {
2670
+ endWithError(span, error);
2671
+ throw error;
2672
+ }
3359
2673
  );
3360
2674
  }
3361
- function withAgent(agent, fn, thisArg) {
3362
- return function wrapped(...args) {
3363
- return startAgent(
3364
- agent,
3365
- () => fn.apply(thisArg !== void 0 ? thisArg : this, args)
3366
- );
3367
- };
3368
- }
3369
- function setAgent(agent) {
3370
- const resolved = resolveAgent(agent);
3371
- if (!resolved) {
3372
- return unreadableAgent(agent);
2675
+ function endWithError(span, error) {
2676
+ try {
2677
+ span.recordException(error instanceof Error ? error : String(error));
2678
+ span.setStatus({
2679
+ code: _api.SpanStatusCode.ERROR,
2680
+ message: error instanceof Error ? error.message : String(error)
2681
+ });
2682
+ span.setAttribute(_chunkNF52RMLWcjs.ERROR_TYPE, errorType(error));
2683
+ } catch (describeError) {
2684
+ _chunkWC573FCIcjs.logger.debug(`Brizz decision call: could not record the error: ${String(describeError)}`);
3373
2685
  }
3374
- const { id, parentId, name, properties, parentContext } = resolved;
3375
- setCurrentSpanCustomProperties(properties);
3376
- propagatePropertiesImperatively(properties, parentContext);
3377
- return agentHandle(id, parentId, name);
2686
+ span.end();
2687
+ }
2688
+ function finiteNumber(value) {
2689
+ return typeof value === "number" && Number.isFinite(value) ? value : void 0;
3378
2690
  }
3379
2691
 
3380
2692
  // src/internal/sdk.ts
@@ -3391,7 +2703,7 @@ function globalTracerDelegate() {
3391
2703
  const global = _api.trace.getTracerProvider();
3392
2704
  return typeof global.getDelegate === "function" ? global.getDelegate() : global;
3393
2705
  }
3394
- var _Brizz = (_class7 = class __Brizz {constructor() { _class7.prototype.__init15.call(this);_class7.prototype.__init16.call(this);_class7.prototype.__init17.call(this); }
2706
+ var _Brizz = (_class6 = class __Brizz {constructor() { _class6.prototype.__init11.call(this);_class6.prototype.__init12.call(this);_class6.prototype.__init13.call(this); }
3395
2707
  static __initStatic4() {this.instance = null}
3396
2708
  static getInstance() {
3397
2709
  if (!this.instance) {
@@ -3400,18 +2712,18 @@ var _Brizz = (_class7 = class __Brizz {constructor() { _class7.prototype.__init1
3400
2712
  return this.instance;
3401
2713
  }
3402
2714
  /** Flag indicating if SDK initialization has completed successfully */
3403
- __init15() {this._initialized = false}
2715
+ __init11() {this._initialized = false}
3404
2716
  /** OpenTelemetry tracer provider */
3405
- __init16() {this._tracerProvider = null}
2717
+ __init12() {this._tracerProvider = null}
3406
2718
  /** OpenTelemetry meter provider */
3407
- __init17() {this._meterProvider = null}
2719
+ __init13() {this._meterProvider = null}
3408
2720
  /**
3409
2721
  * Set up instrumentation registry and configure manual modules.
3410
2722
  * @private
3411
2723
  */
3412
2724
  setupInstrumentation(options) {
3413
2725
  const registry = InstrumentationRegistry.getInstance();
3414
- _chunkDCXOK7PXcjs.configure.call(void 0, resolveMcpSessionTracking(options.mcpSessionTracking));
2726
+ _chunk5QZM5EVPcjs.configure.call(void 0, resolveMcpSessionTracking(options.mcpSessionTracking));
3415
2727
  patchInstalledCallbackManager();
3416
2728
  patchInstalledLangGraph();
3417
2729
  patchInstalledTypeSafe();
@@ -3446,7 +2758,7 @@ var _Brizz = (_class7 = class __Brizz {constructor() { _class7.prototype.__init1
3446
2758
  const resourceAttributes = {
3447
2759
  ...resolvedConfig.resourceAttributes,
3448
2760
  "service.name": resolvedConfig.appName,
3449
- [BRIZZ_SDK_VERSION]: _chunkDCXOK7PXcjs.getSDKVersion.call(void 0, ),
2761
+ [BRIZZ_SDK_VERSION]: _chunk5QZM5EVPcjs.getSDKVersion.call(void 0, ),
3450
2762
  [BRIZZ_SDK_LANGUAGE]: SDK_LANGUAGE
3451
2763
  };
3452
2764
  if (resolvedConfig.environment) {
@@ -3456,7 +2768,7 @@ var _Brizz = (_class7 = class __Brizz {constructor() { _class7.prototype.__init1
3456
2768
  resourceAttributes["service.version"] = resolvedConfig.appVersion;
3457
2769
  }
3458
2770
  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));
3459
- const spanProcessors = resolvedConfig.disableSpanExporter ? [] : [new (0, _chunkO2IBZJOJcjs.InterruptPropagator)(), getSpanProcessor()];
2771
+ const spanProcessors = resolvedConfig.disableSpanExporter ? [] : [new (0, _chunk6QXPHZEOcjs.InterruptPropagator)(), getSpanProcessor()];
3460
2772
  if (resolvedConfig.setGlobalTracerProvider) {
3461
2773
  this._tracerProvider = new (0, _sdktrace.TracerProvider)({ resource, spanProcessors });
3462
2774
  this.registerGlobalTracerProvider(this._tracerProvider);
@@ -3556,19 +2868,19 @@ var _Brizz = (_class7 = class __Brizz {constructor() { _class7.prototype.__init1
3556
2868
  try {
3557
2869
  const tracingModule = TracingModule.getInstance();
3558
2870
  await tracingModule.shutdown();
3559
- } catch (e10) {
2871
+ } catch (e5) {
3560
2872
  _chunkWC573FCIcjs.logger.debug("Tracing module already shut down or not initialized");
3561
2873
  }
3562
2874
  try {
3563
2875
  const metricsModule = MetricsModule.getInstance();
3564
2876
  metricsModule.shutdown();
3565
- } catch (e11) {
2877
+ } catch (e6) {
3566
2878
  _chunkWC573FCIcjs.logger.debug("Metrics module already shut down or not initialized");
3567
2879
  }
3568
2880
  try {
3569
2881
  const loggingModule = LoggingModule.getInstance();
3570
2882
  await loggingModule.shutdown();
3571
- } catch (e12) {
2883
+ } catch (e7) {
3572
2884
  _chunkWC573FCIcjs.logger.debug("Logging module already shut down or not initialized");
3573
2885
  }
3574
2886
  _chunkWC573FCIcjs.logger.info("All telemetry modules shut down successfully");
@@ -3690,10 +3002,10 @@ var _Brizz = (_class7 = class __Brizz {constructor() { _class7.prototype.__init1
3690
3002
  }
3691
3003
  try {
3692
3004
  await this.shutdownModules();
3693
- await _optionalChain([this, 'access', _127 => _127._tracerProvider, 'optionalAccess', _128 => _128.forceFlush, 'call', _129 => _129()]);
3694
- await _optionalChain([this, 'access', _130 => _130._tracerProvider, 'optionalAccess', _131 => _131.shutdown, 'call', _132 => _132()]);
3695
- await _optionalChain([this, 'access', _133 => _133._meterProvider, 'optionalAccess', _134 => _134.forceFlush, 'call', _135 => _135()]);
3696
- await _optionalChain([this, 'access', _136 => _136._meterProvider, 'optionalAccess', _137 => _137.shutdown, 'call', _138 => _138()]);
3005
+ await _optionalChain([this, 'access', _105 => _105._tracerProvider, 'optionalAccess', _106 => _106.forceFlush, 'call', _107 => _107()]);
3006
+ await _optionalChain([this, 'access', _108 => _108._tracerProvider, 'optionalAccess', _109 => _109.shutdown, 'call', _110 => _110()]);
3007
+ await _optionalChain([this, 'access', _111 => _111._meterProvider, 'optionalAccess', _112 => _112.forceFlush, 'call', _113 => _113()]);
3008
+ await _optionalChain([this, 'access', _114 => _114._meterProvider, 'optionalAccess', _115 => _115.shutdown, 'call', _116 => _116()]);
3697
3009
  this._initialized = false;
3698
3010
  this._tracerProvider = null;
3699
3011
  this._meterProvider = null;
@@ -3708,7 +3020,7 @@ var _Brizz = (_class7 = class __Brizz {constructor() { _class7.prototype.__init1
3708
3020
  }
3709
3021
  }
3710
3022
  }
3711
- }, _class7.__initStatic4(), _class7);
3023
+ }, _class6.__initStatic4(), _class6);
3712
3024
  var Brizz = new _Brizz();
3713
3025
 
3714
3026
  // src/index.ts
@@ -3761,4 +3073,6 @@ var Brizz = new _Brizz();
3761
3073
 
3762
3074
 
3763
3075
 
3764
- exports.Brizz = Brizz; exports.DEFAULT_PII_PATTERNS = DEFAULT_PII_PATTERNS; exports.LogLevel = _chunkWC573FCIcjs.LogLevel; exports.Session = Session; exports.SessionTitle = SessionTitle; exports.SeverityNumber = _api.SeverityNumber; exports.addExternalLink = addExternalLink; exports.callWithMessageId = callWithMessageId; exports.callWithMute = callWithMute; exports.callWithOrganization = callWithOrganization; exports.callWithProperties = callWithProperties; exports.callWithServiceName = callWithServiceName; exports.callWithSessionId = callWithSessionId; exports.callWithUser = callWithUser; exports.emitEvent = emitEvent; exports.emitEventWithSessionId = emitEventWithSessionId; exports.getActiveSession = getActiveSession; exports.getLogLevel = _chunkWC573FCIcjs.getLogLevel; exports.getMetricsExporter = getMetricsExporter; exports.getMetricsReader = getMetricsReader; exports.getSpanExporter = getSpanExporter; exports.getSpanProcessor = getSpanProcessor; exports.getTracerProvider = _chunkDC2MFO65cjs.getTracerProvider; exports.logger = _chunkWC573FCIcjs.logger; exports.maskAttributes = maskAttributes; exports.maskValue = maskValue; exports.recordFeedback = recordFeedback; exports.recordMetric = recordMetric; exports.setAgent = setAgent; exports.setCurrentSpanCustomProperties = setCurrentSpanCustomProperties; exports.setLogLevel = _chunkWC573FCIcjs.setLogLevel; exports.setMessageId = setMessageId; exports.setOrganization = setOrganization; exports.setServiceName = setServiceName; exports.setSessionId = setSessionId; exports.setUser = setUser; exports.startAgent = startAgent; exports.startSession = startSession; exports.startSessionTitle = startSessionTitle; exports.withAgent = withAgent; exports.withMessageId = withMessageId; exports.withMute = withMute; exports.withOrganization = withOrganization; exports.withProperties = withProperties; exports.withServiceName = withServiceName; exports.withSessionId = withSessionId; exports.withUser = withUser;
3076
+
3077
+
3078
+ exports.Brizz = Brizz; exports.DEFAULT_PII_PATTERNS = DEFAULT_PII_PATTERNS; exports.LogLevel = _chunkWC573FCIcjs.LogLevel; exports.Session = _chunk4QNEI7VZcjs.Session; exports.SessionTitle = _chunk4QNEI7VZcjs.SessionTitle; exports.SeverityNumber = _api.SeverityNumber; exports.addExternalLink = _chunk4QNEI7VZcjs.addExternalLink; exports.callWithMessageId = _chunk4QNEI7VZcjs.callWithMessageId; exports.callWithMute = _chunk4QNEI7VZcjs.callWithMute; exports.callWithOrganization = _chunk4QNEI7VZcjs.callWithOrganization; exports.callWithProperties = _chunk4QNEI7VZcjs.callWithProperties; exports.callWithServiceName = _chunk4QNEI7VZcjs.callWithServiceName; exports.callWithSessionId = _chunk4QNEI7VZcjs.callWithSessionId; exports.callWithUser = _chunk4QNEI7VZcjs.callWithUser; exports.decisionCall = decisionCall; exports.emitEvent = _chunk4QNEI7VZcjs.emitEvent; exports.emitEventWithSessionId = _chunk4QNEI7VZcjs.emitEventWithSessionId; exports.getActiveSession = _chunk4QNEI7VZcjs.getActiveSession; exports.getLogLevel = _chunkWC573FCIcjs.getLogLevel; exports.getMetricsExporter = getMetricsExporter; exports.getMetricsReader = getMetricsReader; exports.getSpanExporter = getSpanExporter; exports.getSpanProcessor = getSpanProcessor; exports.getTracerProvider = _chunkDC2MFO65cjs.getTracerProvider; exports.logger = _chunkWC573FCIcjs.logger; exports.maskAttributes = maskAttributes; exports.maskValue = maskValue; exports.recordDecisionCall = recordDecisionCall; exports.recordFeedback = _chunk4QNEI7VZcjs.recordFeedback; exports.recordMetric = _chunk4QNEI7VZcjs.recordMetric; exports.setAgent = _chunk4QNEI7VZcjs.setAgent; exports.setCurrentSpanCustomProperties = _chunk4QNEI7VZcjs.setCurrentSpanCustomProperties; exports.setLogLevel = _chunkWC573FCIcjs.setLogLevel; exports.setMessageId = _chunk4QNEI7VZcjs.setMessageId; exports.setOrganization = _chunk4QNEI7VZcjs.setOrganization; exports.setServiceName = _chunk4QNEI7VZcjs.setServiceName; exports.setSessionId = _chunk4QNEI7VZcjs.setSessionId; exports.setUser = _chunk4QNEI7VZcjs.setUser; exports.startAgent = _chunk4QNEI7VZcjs.startAgent; exports.startSession = _chunk4QNEI7VZcjs.startSession; exports.startSessionTitle = _chunk4QNEI7VZcjs.startSessionTitle; exports.withAgent = _chunk4QNEI7VZcjs.withAgent; exports.withMessageId = _chunk4QNEI7VZcjs.withMessageId; exports.withMute = _chunk4QNEI7VZcjs.withMute; exports.withOrganization = _chunk4QNEI7VZcjs.withOrganization; exports.withProperties = _chunk4QNEI7VZcjs.withProperties; exports.withServiceName = _chunk4QNEI7VZcjs.withServiceName; exports.withSessionId = _chunk4QNEI7VZcjs.withSessionId; exports.withUser = _chunk4QNEI7VZcjs.withUser;