{"version":3,"file":"utils.js","sources":["../../../../src/tracing/google-genai/utils.ts"],"sourcesContent":["import { GOOGLE_GENAI_INSTRUMENTED_METHODS } from './constants';\nimport type { GoogleGenAIIstrumentedMethod } from './types';\n\n/**\n * Check if a method path should be instrumented\n */\nexport function shouldInstrument(methodPath: string): methodPath is GoogleGenAIIstrumentedMethod {\n // Check for exact matches first (like 'models.generateContent')\n if (GOOGLE_GENAI_INSTRUMENTED_METHODS.includes(methodPath as GoogleGenAIIstrumentedMethod)) {\n return true;\n }\n\n // Check for method name matches (like 'sendMessage' from chat instances)\n const methodName = methodPath.split('.').pop();\n return GOOGLE_GENAI_INSTRUMENTED_METHODS.includes(methodName as GoogleGenAIIstrumentedMethod);\n}\n\n/**\n * Check if a method is a streaming method\n */\nexport function isStreamingMethod(methodPath: string): boolean {\n return methodPath.includes('Stream');\n}\n\n// Copied from https://googleapis.github.io/js-genai/release_docs/index.html\nexport type ContentListUnion = Content | Content[] | PartListUnion;\nexport type ContentUnion = Content | PartUnion[] | PartUnion;\nexport type Content = {\n parts?: Part[];\n role?: string;\n};\nexport type PartUnion = Part | string;\nexport type Part = Record & {\n inlineData?: {\n data?: string;\n displayName?: string;\n mimeType?: string;\n };\n text?: string;\n};\nexport type PartListUnion = PartUnion[] | PartUnion;\n\n// our consistent span message shape\nexport type Message = Record & {\n role: string;\n content?: PartListUnion;\n parts?: PartListUnion;\n};\n\n/**\n *\n */\nexport function contentUnionToMessages(content: ContentListUnion, role = 'user'): Message[] {\n if (typeof content === 'string') {\n return [{ role, content }];\n }\n if (Array.isArray(content)) {\n return content.flatMap(content => contentUnionToMessages(content, role));\n }\n if (typeof content !== 'object' || !content) return [];\n if ('role' in content && typeof content.role === 'string') {\n return [content as Message];\n }\n if ('parts' in content) {\n return [{ ...content, role } as Message];\n }\n return [{ role, content }];\n}\n"],"names":["GOOGLE_GENAI_INSTRUMENTED_METHODS"],"mappings":";;;;AAGA;AACA;AACA;AACO,SAAS,gBAAgB,CAAC,UAAU,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