@brizz/sdk 0.1.3-rc.0 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/preload.cjs CHANGED
@@ -1343,7 +1343,7 @@ var HANDLED_SPAN_NAMES = {
1343
1343
  "ai.streamText": "ai.streamText",
1344
1344
  "ai.toolCall": (span) => {
1345
1345
  const toolName = span.attributes["ai.toolCall.name"];
1346
- return `${toolName}.tool`;
1346
+ return `${String(toolName ?? "unknown")}.tool`;
1347
1347
  }
1348
1348
  };
1349
1349
  var AI_RESPONSE_TEXT = "ai.response.text";
@@ -1353,10 +1353,11 @@ var AI_USAGE_COMPLETION_TOKENS = "ai.usage.completionTokens";
1353
1353
  var AI_MODEL_PROVIDER = "ai.model.provider";
1354
1354
  var transformAiSdkSpanName = (span) => {
1355
1355
  if (span.name in HANDLED_SPAN_NAMES) {
1356
- if (typeof HANDLED_SPAN_NAMES[span.name] === "function") {
1357
- span.name = HANDLED_SPAN_NAMES[span.name](span);
1358
- } else {
1359
- span.name = HANDLED_SPAN_NAMES[span.name];
1356
+ const handler = HANDLED_SPAN_NAMES[span.name];
1357
+ if (typeof handler === "function") {
1358
+ span.name = handler(span);
1359
+ } else if (handler) {
1360
+ span.name = handler;
1360
1361
  }
1361
1362
  }
1362
1363
  };
@@ -1371,26 +1372,30 @@ var transformPromptMessages = (attributes) => {
1371
1372
  if (AI_PROMPT_MESSAGES in attributes) {
1372
1373
  try {
1373
1374
  const messages = JSON.parse(attributes[AI_PROMPT_MESSAGES]);
1374
- messages.forEach((msg, index) => {
1375
- logger.debug("Transforming prompt message", { msg, type: typeof msg.content });
1376
- if (typeof msg.content === "string") {
1377
- attributes[`${import_ai_semantic_conventions.SpanAttributes.LLM_PROMPTS}.${index}.content`] = msg.content;
1375
+ for (const [index, msg] of messages.entries()) {
1376
+ const message = msg;
1377
+ logger.debug("Transforming prompt message", { msg: message, type: typeof message.content });
1378
+ if (typeof message.content === "string") {
1379
+ attributes[`${import_ai_semantic_conventions.SpanAttributes.LLM_PROMPTS}.${index}.content`] = message.content;
1378
1380
  } else {
1379
- if (Array.isArray(msg.content) && msg.content.length > 0) {
1380
- const lastContent = msg.content[msg.content.length - 1];
1381
- if (lastContent.text) {
1381
+ if (Array.isArray(message.content) && message.content.length > 0) {
1382
+ const lastContent = message.content.at(-1);
1383
+ if (lastContent?.text) {
1382
1384
  attributes[`${import_ai_semantic_conventions.SpanAttributes.LLM_PROMPTS}.${index}.content`] = lastContent.text;
1383
1385
  }
1384
1386
  } else {
1385
1387
  attributes[`${import_ai_semantic_conventions.SpanAttributes.LLM_PROMPTS}.${index}.content`] = JSON.stringify(
1386
- msg.content
1388
+ message.content
1387
1389
  );
1388
1390
  }
1389
1391
  }
1390
- attributes[`${import_ai_semantic_conventions.SpanAttributes.LLM_PROMPTS}.${index}.role`] = msg.role;
1391
- });
1392
+ attributes[`${import_ai_semantic_conventions.SpanAttributes.LLM_PROMPTS}.${index}.role`] = message.role;
1393
+ }
1392
1394
  delete attributes[AI_PROMPT_MESSAGES];
1393
- } catch {
1395
+ } catch (error) {
1396
+ logger.debug("Skipping prompt messages transformation because of JSON parsing error", {
1397
+ e: error
1398
+ });
1394
1399
  }
1395
1400
  }
1396
1401
  };
@@ -1416,11 +1421,7 @@ var calculateTotalTokens = (attributes) => {
1416
1421
  var transformVendor = (attributes) => {
1417
1422
  if (AI_MODEL_PROVIDER in attributes) {
1418
1423
  const vendor = attributes[AI_MODEL_PROVIDER];
1419
- if (vendor && vendor.startsWith("openai")) {
1420
- attributes[import_ai_semantic_conventions.SpanAttributes.LLM_SYSTEM] = "OpenAI";
1421
- } else {
1422
- attributes[import_ai_semantic_conventions.SpanAttributes.LLM_SYSTEM] = vendor;
1423
- }
1424
+ attributes[import_ai_semantic_conventions.SpanAttributes.LLM_SYSTEM] = vendor && vendor.startsWith("openai") ? "OpenAI" : vendor;
1424
1425
  delete attributes[AI_MODEL_PROVIDER];
1425
1426
  }
1426
1427
  };
@@ -1436,11 +1437,20 @@ var shouldHandleSpan = (span) => {
1436
1437
  return span.name in HANDLED_SPAN_NAMES;
1437
1438
  };
1438
1439
  var transformAiSdkSpan = (span) => {
1439
- logger.debug("Transforming AI SDK span", { spanName: span.name });
1440
1440
  if (!shouldHandleSpan(span)) {
1441
1441
  logger.debug("Skipping span transformation", { spanName: span.name });
1442
1442
  return;
1443
1443
  }
1444
+ for (const key in span.attributes) {
1445
+ if (Number.isNaN(span.attributes[key])) {
1446
+ span.attributes[key] = 0;
1447
+ }
1448
+ }
1449
+ logger.debug("Transforming AI SDK span", {
1450
+ spanName: span.name,
1451
+ spanContext: span.spanContext(),
1452
+ attributes: span.attributes
1453
+ });
1444
1454
  transformAiSdkSpanName(span);
1445
1455
  transformAiSdkAttributes(span.attributes);
1446
1456
  };