@sentry/server-utils 11.15.0 → 11.16.0

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.
@@ -544,10 +544,57 @@ const GEN_AI_TOOL_CALL_ID_ATTRIBUTE = "gen_ai.tool.call.id";
544
544
  function getDecisionInputMessages$1(params) {
545
545
  const questions = Array.isArray(params.questions) ? params.questions.map(toJevQuestionFormat) : params.questions;
546
546
  return getEvaluationInputMessages({
547
- state: params.input,
547
+ state: toStateMessages$1(params.input),
548
548
  questions: keyByName(questions)
549
549
  });
550
550
  }
551
+ /**
552
+ * Lay out evidence messages as gen_ai messages, so they render like Google's. Other input items (tool calls and
553
+ * their outputs) keep their layout, with output parts mapped like message parts.
554
+ */
555
+ function toStateMessages$1(input) {
556
+ if (!Array.isArray(input)) return input;
557
+ return input.map((item) => {
558
+ if (!(0, _sentry_core.isObjectLike)(item)) return item;
559
+ if (typeof item.role === "string") return {
560
+ role: item.role === "developer" ? "system" : item.role,
561
+ parts: Array.isArray(item.content) ? item.content.filter(_sentry_core.isObjectLike).map(toMessagePart) : [{
562
+ type: "text",
563
+ content: item.content
564
+ }]
565
+ };
566
+ return Array.isArray(item.output) ? {
567
+ ...item,
568
+ output: item.output.filter(_sentry_core.isObjectLike).map(toMessagePart)
569
+ } : item;
570
+ });
571
+ }
572
+ /**
573
+ * An image in a data URL is reported by its media type only: the URL holds base64, which the conventions require to be
574
+ * dropped.
575
+ */
576
+ function toMessagePart(part) {
577
+ if (part.type === "input_image" && typeof part.image_url === "string") {
578
+ const dataUrlMimeType = /^data:([^;,]+)/.exec(part.image_url)?.[1];
579
+ return part.image_url.startsWith("data:") ? {
580
+ type: "blob",
581
+ modality: "image",
582
+ mime_type: dataUrlMimeType
583
+ } : {
584
+ type: "uri",
585
+ modality: "image",
586
+ uri: part.image_url
587
+ };
588
+ }
589
+ if (part.type === "input_json") return {
590
+ type: "object",
591
+ content: part.data
592
+ };
593
+ return {
594
+ type: "text",
595
+ content: part.text ?? part.refusal
596
+ };
597
+ }
551
598
  /** Serialize the answers of a decisions response, laid out and keyed like Jev answers. */
552
599
  function getDecisionOutputMessages(answers) {
553
600
  return getEvaluationOutputMessages(keyByName(answers.map(toJevAnswerFormat)));
@@ -1681,10 +1728,38 @@ const GOOGLE_GENAI_SYSTEM_NAME = "google_genai";
1681
1728
  */
1682
1729
  function getDecisionInputMessages(params) {
1683
1730
  return getEvaluationInputMessages({
1684
- state: params.input,
1731
+ state: toStateMessages(params.input),
1685
1732
  questions: params.questions
1686
1733
  });
1687
1734
  }
1735
+ /**
1736
+ * Multimodal evidence is one part or a list of parts, recorded as one user message so it renders like OpenAI's.
1737
+ * Inline media is reported by modality and media type only: its `data` is base64, which the conventions require
1738
+ * to be dropped.
1739
+ */
1740
+ function toStateMessages(input) {
1741
+ if (typeof input === "string") return input;
1742
+ return [{
1743
+ role: "user",
1744
+ parts: (Array.isArray(input) ? input : [input]).filter(_sentry_core.isObjectLike).map((part) => {
1745
+ if (part.type === "text") return {
1746
+ type: "text",
1747
+ content: part.text
1748
+ };
1749
+ if (typeof part.uri === "string") return {
1750
+ type: "uri",
1751
+ modality: part.type,
1752
+ mime_type: part.mime_type,
1753
+ uri: part.uri
1754
+ };
1755
+ return {
1756
+ type: "blob",
1757
+ modality: part.type,
1758
+ mime_type: part.mime_type
1759
+ };
1760
+ })
1761
+ }];
1762
+ }
1688
1763
  function addDecisionResponseAttributes(span, response, recordOutputs) {
1689
1764
  if (!(0, _sentry_core.isObjectLike)(response)) return;
1690
1765
  if ((0, _sentry_core.isObjectLike)(response.usage)) {
@@ -5163,6 +5238,7 @@ function startToolSpan(observation, context, toolSpans, options) {
5163
5238
  ...recordInputs && observation.args !== void 0 ? { [_sentry_conventions_attributes.GEN_AI_TOOL_CALL_ARGUMENTS]: (0, _sentry_core.stringify)(observation.args) } : {}
5164
5239
  }
5165
5240
  });
5241
+ if (observation.conversationId) span.setAttribute(_sentry_conventions_attributes.GEN_AI_CONVERSATION_ID, observation.conversationId);
5166
5242
  if (recordOutputs) TOOL_SPANS_RECORDING_OUTPUTS.add(span);
5167
5243
  runGenAiSpanStart(options, span, call);
5168
5244
  TOOL_SPAN_END_HOOKS.set(span, (end) => runGenAiSpanEnd(options, span, call, end.isError ? {