@redocly/openapi-docs 3.24.0-next.7 → 3.24.0-next.8
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/{redocly-openapi-docs.min.AiChatProvider-gAsQoX30.js → redocly-openapi-docs.min.AiChatProvider-D8o94qvX.js} +1 -1
- package/dist/{redocly-openapi-docs.min.AiChatSqliteDBStorage-CnYt8ojK.js → redocly-openapi-docs.min.AiChatSqliteDBStorage-BLTom3F-.js} +1 -1
- package/dist/{redocly-openapi-docs.min.AiPanel-Bvkd__SH.js → redocly-openapi-docs.min.AiPanel-DloIzPy9.js} +184 -165
- package/dist/{redocly-openapi-docs.min.SqliteDBStorage-C6xTN7YJ.js → redocly-openapi-docs.min.SqliteDBStorage-CksbFVf-.js} +1 -1
- package/dist/{redocly-openapi-docs.min.ai-chat-mappers-3WKBUVis.js → redocly-openapi-docs.min.ai-chat-mappers-Dza6UMVG.js} +1 -1
- package/dist/{redocly-openapi-docs.min.external-resolver-4BBxclf5.js → redocly-openapi-docs.min.external-resolver-Cm8qMSH6.js} +1 -1
- package/dist/{redocly-openapi-docs.min.index-DswpnLh3.js → redocly-openapi-docs.min.index-CVScN5cj.js} +1251 -1229
- package/dist/{redocly-openapi-docs.min.index-C4nhoQHY.js → redocly-openapi-docs.min.index-DQKkHTdL.js} +1 -1
- package/dist/{redocly-openapi-docs.min.index-IvDdPWpQ.js → redocly-openapi-docs.min.index-DWPYSZX6.js} +1 -1
- package/dist/redocly-openapi-docs.min.js +1 -1
- package/dist/{redocly-openapi-docs.min.lint-DxrZW_dt.js → redocly-openapi-docs.min.lint-B0W-5WwE.js} +2 -2
- package/dist/{redocly-openapi-docs.min.lint-graphql-BJaf-iso.js → redocly-openapi-docs.min.lint-graphql-y6yM0_Y_.js} +1 -1
- package/dist/{redocly-openapi-docs.min.respect-run-BxLhw6rg.js → redocly-openapi-docs.min.respect-run-C77Wul9G.js} +1 -1
- package/dist/{redocly-openapi-docs.min.standalone-DYNn4rpC.js → redocly-openapi-docs.min.standalone-BFWv5fnd.js} +3 -3
- package/dist/{redocly-openapi-docs.min.tauri-path-DkXXjCOS.js → redocly-openapi-docs.min.tauri-path-Dc9-nUUG.js} +1 -1
- package/dist/{redocly-openapi-docs.min.useAiChatQueries-DA3WodeG.js → redocly-openapi-docs.min.useAiChatQueries-B9Y_hT0w.js} +35 -33
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{X as v,Z as T,aC as x,O as _t,c as Qt,r as l,j as at}from"./redocly-openapi-docs.min.standalone-DYNn4rpC.js";import{T as Gt,c as rt,D as Ht,a as Vt,u as mt,b as gt,d as A,A as ft,I as Yt,e as E,f as Xt,g as Zt,h as te,i as wt,j as ee,k as ne,l as oe,m as ae,n as Tt,o as st,p as ht,q as At,r as re,s as se,t as Mt,R as it,v as ie,w as yt,x as le,y as ue}from"./redocly-openapi-docs.min.index-DswpnLh3.js";import{c as St,p as pe,g as ce,T as de,i as me,a as ge,s as fe,A as he,b as ye,r as Se,d as ve,e as be,o as Ie,f as ke,w as Ce,m as xe,h as _e,u as we,j as Te,k as Ae,l as Me,n as Oe,D as Ee,q as Re,t as je,v as qe,x as Ne,y as $e,z as Pe}from"./redocly-openapi-docs.min.useAiChatQueries-DA3WodeG.js";import{b as Ot,g as Et}from"./redocly-openapi-docs.min.ai-chat-mappers-3WKBUVis.js";function R(t){const e=t.toLowerCase(),n=[["google.vertex","gcp.vertex_ai"],["google.generative-ai","gcp.gemini"],["google-vertex","gcp.vertex_ai"],["amazon-bedrock","aws.bedrock"],["azure-openai","azure.ai.openai"],["anthropic","anthropic"],["openai","openai"],["azure","azure.ai.inference"],["google","gcp.gemini"],["mistral","mistral_ai"],["cohere","cohere"],["bedrock","aws.bedrock"],["groq","groq"],["deepseek","deepseek"],["perplexity","perplexity"],["xai","x_ai"]];for(const[o,r]of n)if(e===o||e.startsWith(o+".")||e.startsWith(o+"-"))return r;return t}function Rt(t){var e;return(e={"ai.generateText":"invoke_agent","ai.streamText":"invoke_agent","ai.generateObject":"invoke_agent","ai.streamObject":"invoke_agent","ai.embed":"embeddings","ai.embedMany":"embeddings","ai.rerank":"rerank"}[t])!=null?e:t}function jt(t){return typeof t=="string"?[{type:"text",content:t}]:Array.isArray(t)?t.map(e=>({type:"text",content:e.content})):[{type:"text",content:t.content}]}function De(t){var e,n,o,r,a;switch(t.type){case"text":return{type:"text",content:t.text};case"reasoning":return{type:"reasoning",content:t.text};case"tool-call":return{type:"tool_call",id:(e=t.toolCallId)!=null?e:null,name:t.toolName,arguments:t.input};case"tool-result":{const s=t.output;let i;return s&&(s.type==="text"||s.type==="error-text"||s.type==="json"||s.type==="error-json"?i=s.value:s.type==="execution-denied"?i={denied:!0,reason:s.reason}:i=s),{type:"tool_call_response",id:(n=t.toolCallId)!=null?n:null,response:i}}case"file":{const s=t.data,i=(()=>{if(typeof s=="object"&&s!==null&&!(s instanceof URL)&&!(s instanceof Uint8Array)&&!(s instanceof ArrayBuffer)&&"type"in s)switch(s.type){case"data":return s.data;case"url":return s.url;case"text":return s.text;default:return""}return s})();let u;if(i instanceof Uint8Array)u=St(i);else if(typeof i=="string"){if(i.startsWith("http://")||i.startsWith("https://"))return{type:"uri",modality:j(t.mediaType),mime_type:(o=t.mediaType)!=null?o:null,uri:i};u=i}else{if(i instanceof URL)return{type:"uri",modality:j(t.mediaType),mime_type:(r=t.mediaType)!=null?r:null,uri:i.toString()};u=String(i)}return{type:"blob",modality:j(t.mediaType),mime_type:(a=t.mediaType)!=null?a:null,content:u}}case"tool-approval-response":return{type:"tool_approval_response",approval_id:t.approvalId,approved:t.approved,reason:t.reason};case"custom":return{type:"custom",kind:t.kind};case"reasoning-file":return{type:String(t.type)};default:return{type:String(t.type)}}}function j(t){return!t||t.startsWith("image/")?"image":t.startsWith("video/")?"video":t.startsWith("audio/")?"audio":"image"}function We(t){return t.filter(e=>e.role!=="system").map(e=>{if(e.role==="system")return{role:"system",parts:[{type:"text",content:e.content}]};const n=e.content.map(De);return{role:e.role,parts:n}})}function vt({prompt:t,messages:e}){const n=[];if(typeof t=="string")n.push({role:"user",parts:[{type:"text",content:t}]});else if(Array.isArray(t))for(const o of t){const r=qt(o);r&&n.push(r)}if(e)for(const o of e){const r=qt(o);r&&n.push(r)}return n}function qt(t){if(t.role!=="system"){if(t.role==="user")return typeof t.content=="string"?{role:"user",parts:[{type:"text",content:t.content}]}:{role:"user",parts:t.content.map(e=>{var n,o,r,a,s,i,u,d;switch(e.type){case"text":return{type:"text",content:e.text};case"image":{const p=e.image;return p instanceof URL?{type:"uri",modality:"image",mime_type:(n=e.mediaType)!=null?n:null,uri:p.toString()}:typeof p=="string"?p.startsWith("http://")||p.startsWith("https://")?{type:"uri",modality:"image",mime_type:(o=e.mediaType)!=null?o:null,uri:p}:{type:"blob",modality:"image",mime_type:(r=e.mediaType)!=null?r:null,content:p}:{type:"blob",modality:"image",mime_type:(a=e.mediaType)!=null?a:null,content:St(p)}}case"file":{const p=e.data,c=(()=>{if(typeof p=="object"&&p!==null&&!(p instanceof URL)&&!(p instanceof Uint8Array)&&!(p instanceof ArrayBuffer)&&"type"in p)switch(p.type){case"data":return p.data;case"url":return p.url;case"text":return p.text;default:return""}return p})();return c instanceof URL?{type:"uri",modality:j(e.mediaType),mime_type:(s=e.mediaType)!=null?s:null,uri:c.toString()}:typeof c=="string"?c.startsWith("http://")||c.startsWith("https://")?{type:"uri",modality:j(e.mediaType),mime_type:(i=e.mediaType)!=null?i:null,uri:c}:{type:"blob",modality:j(e.mediaType),mime_type:(u=e.mediaType)!=null?u:null,content:c}:{type:"blob",modality:j(e.mediaType),mime_type:(d=e.mediaType)!=null?d:null,content:St(c)}}default:return{type:String(e.type)}}})};if(t.role==="assistant")return typeof t.content=="string"?{role:"assistant",parts:[{type:"text",content:t.content}]}:{role:"assistant",parts:t.content.map(e=>{var n,o;switch(e.type){case"text":return{type:"text",content:e.text};case"reasoning":return{type:"reasoning",content:e.text};case"tool-call":return{type:"tool_call",id:(n=e.toolCallId)!=null?n:null,name:e.toolName,arguments:e.input};case"tool-result":{const r=e.output;let a;return r&&(r.type==="text"||r.type==="error-text"||r.type==="json"||r.type==="error-json"?a=r.value:r.type==="execution-denied"?a={denied:!0,reason:r.reason}:a=r),{type:"tool_call_response",id:(o=e.toolCallId)!=null?o:null,response:a}}default:return{type:String(e.type)}}})};if(t.role==="tool")return{role:"tool",parts:t.content.map(e=>{var n;if(e.type==="tool-result"){const o=e.output;let r;return o&&(o.type==="text"||o.type==="error-text"||o.type==="json"||o.type==="error-json"?r=o.value:o.type==="execution-denied"?r={denied:!0,reason:o.reason}:r=o),{type:"tool_call_response",id:(n=e.toolCallId)!=null?n:null,response:r}}return{type:String(e.type)}})}}}function Nt({text:t,reasoning:e,toolCalls:n,files:o,finishReason:r}){const a=[];if(e)for(const s of e)"text"in s&&s.text&&a.push({type:"reasoning",content:s.text});if(t!=null&&t.length>0&&a.push({type:"text",content:t}),n)for(const s of n)a.push({type:"tool_call",id:s.toolCallId,name:s.toolName,arguments:s.input});if(o)for(const s of o)a.push({type:"blob",modality:j(s.mediaType),mime_type:s.mediaType,content:s.base64});return[{role:"assistant",parts:a,finish_reason:Pt(r)}]}function $t({objectText:t,finishReason:e}){return[{role:"assistant",parts:[{type:"text",content:t}],finish_reason:Pt(e)}]}function Pt(t){var e;return(e={stop:"stop",length:"length","content-filter":"content_filter","tool-calls":"tool_call",error:"error",other:"stop",unknown:"stop"}[t])!=null?e:t}function F(t,e){e instanceof Error?(t.recordException({name:e.name,message:e.message,stack:e.stack}),t.setStatus({code:_t.ERROR,message:e.message})):t.setStatus({code:_t.ERROR})}function Je(t){return typeof t=="string"||typeof t=="number"||typeof t=="boolean"}function lt(t){if(!Array.isArray(t))return t;const e=new Set(t.filter(Je).map(o=>typeof o));if(e.size!==1)return;const[n]=e;return n==="string"?t.filter(o=>typeof o=="string"):n==="number"?t.filter(o=>typeof o=="number"):t.filter(o=>typeof o=="boolean")}function Le(t){const e={};for(const[n,o]of Object.entries(t??{})){if(o==null)continue;const r=lt(o);r!=null&&(e[n]=r)}return e}function Fe(t){return t?.isEnabled!==!1}function h(t,e){if(!Fe(t))return{};const n={};for(const[o,r]of Object.entries(e)){if(r==null)continue;if(typeof r=="object"&&"input"in r&&typeof r.input=="function"){if(t?.recordInputs===!1)continue;const s=r.input();if(s!=null){const i=lt(s);i!=null&&(n[o]=i)}continue}if(typeof r=="object"&&"output"in r&&typeof r.output=="function"){if(t?.recordOutputs===!1)continue;const s=r.output();if(s!=null){const i=lt(s);i!=null&&(n[o]=i)}continue}const a=lt(r);a!=null&&(n[o]=a)}return n}var Ue={usage:!1,providerMetadata:!1,embedding:!1,reranking:!1,runtimeContext:!1,headers:!1,toolChoice:!1,schema:!1};function Ke(t){var e,n,o,r,a,s,i,u;return{...Ue,usage:(e=t.usage)!=null?e:!1,providerMetadata:(n=t.providerMetadata)!=null?n:!1,embedding:(o=t.embedding)!=null?o:!1,reranking:(r=t.reranking)!=null?r:!1,runtimeContext:(a=t.runtimeContext)!=null?a:!1,headers:(s=t.headers)!=null?s:!1,toolChoice:(i=t.toolChoice)!=null?i:!1,schema:(u=t.schema)!=null?u:!1}}function Be(t){const e={};for(const[n,o]of Object.entries(t??{}))Dt(e,`ai.settings.context.${n}`,o);return e}function Dt(t,e,n){if(n!=null){if(Array.isArray(n)||typeof n!="object"){t[e]=n;return}for(const[o,r]of Object.entries(n))Dt(t,`${e}.${o}`,r)}}function ut(t){return Object.fromEntries(Object.entries(t??{}).filter(([,e])=>e!=null).map(([e,n])=>[`ai.request.headers.${e}`,n]))}function V(t){var e,n,o;return{"ai.usage.inputTokenDetails.noCacheTokens":(e=t.inputTokenDetails)==null?void 0:e.noCacheTokens,"ai.usage.outputTokenDetails.textTokens":(n=t.outputTokenDetails)==null?void 0:n.textTokens,"ai.usage.outputTokenDetails.reasoningTokens":(o=t.outputTokenDetails)==null?void 0:o.reasoningTokens}}function S(t,e,n){const o={};for(const[r,a]of Object.entries(n))!e[r]||a==null||Object.assign(o,h(t,a));return o}function pt(t){return t==null?void 0:t/1e3}function ze(t){var e;return{"gen_ai.client.operation.duration":pt(t.responseTimeMs),"gen_ai.client.operation.time_to_first_chunk":pt(t.timeToFirstOutputMs),"gen_ai.client.operation.time_per_output_chunk":pt((e=t.timeBetweenOutputChunksMs)==null?void 0:e.avg)}}var Qe=class{constructor(t={}){this.callStates=new Map;var e;this.tracer=(e=t.tracer)!=null?e:v.getTracer("gen_ai"),this.supplementalAttributes=Ke(t),this.enrichSpan=t.enrichSpan}getCallState(t){return this.callStates.get(t)}cleanupCallState(t){this.callStates.delete(t)}getSpanAttributes({attributes:t,spanType:e,operationId:n,callId:o,runtimeContext:r}){var a;let s;try{s=(a=this.enrichSpan)==null?void 0:a.call(this,{spanType:e,operationId:n,callId:o,runtimeContext:r})}catch{s=void 0}return{...Le(s),...t}}executeTool({callId:t,toolCallId:e,execute:n}){var o;const r=(o=this.getCallState(t))==null?void 0:o.toolSpans.get(e);return r==null?n():T.with(r.context,n)}executeLanguageModelCall({callId:t,execute:e}){var n;const o=this.getCallState(t),r=(n=o?.inferenceContext)!=null?n:o?.stepContext;return r==null?e():T.with(r,e)}onStart(t){if(t.operationId==="ai.embed"||t.operationId==="ai.embedMany"){this.onEmbedOperationStart(t);return}if(t.operationId==="ai.rerank"){this.onRerankOperationStart(t);return}if(t.operationId==="ai.generateObject"||t.operationId==="ai.streamObject"){this.onObjectOperationStart(t);return}this.onGenerateStart(t)}onGenerateStart(t){var e;const n={recordInputs:t.recordInputs,recordOutputs:t.recordOutputs,functionId:t.functionId},o={maxOutputTokens:t.maxOutputTokens,temperature:t.temperature,topP:t.topP,topK:t.topK,presencePenalty:t.presencePenalty,frequencyPenalty:t.frequencyPenalty,stopSequences:t.stopSequences,seed:t.seed,maxRetries:t.maxRetries},r=R(t.provider),a=Rt(t.operationId),s=t.runtimeContext,i=S(n,this.supplementalAttributes,{runtimeContext:Be(s),headers:ut(t.headers)}),u=h(n,{"gen_ai.operation.name":a,"gen_ai.provider.name":r,"gen_ai.request.model":t.modelId,"gen_ai.agent.name":n.functionId,"gen_ai.request.frequency_penalty":t.frequencyPenalty,"gen_ai.request.max_tokens":t.maxOutputTokens,"gen_ai.request.presence_penalty":t.presencePenalty,"gen_ai.request.temperature":(e=t.temperature)!=null?e:void 0,"gen_ai.request.top_k":t.topK,"gen_ai.request.top_p":t.topP,"gen_ai.request.stop_sequences":t.stopSequences,"gen_ai.request.seed":t.seed,"gen_ai.system_instructions":t.instructions?{input:()=>JSON.stringify(jt(t.instructions))}:void 0,"gen_ai.input.messages":{input:()=>JSON.stringify(vt({prompt:void 0,messages:t.messages}))},...i}),d=`${a} ${t.modelId}`,p=this.tracer.startSpan(d,{attributes:this.getSpanAttributes({attributes:u,spanType:"operation",operationId:t.operationId,callId:t.callId,runtimeContext:s}),kind:x.INTERNAL}),c=v.setSpan(T.active(),p);this.callStates.set(t.callId,{operationId:t.operationId,telemetry:n,rootSpan:p,rootContext:c,stepSpan:void 0,stepContext:void 0,inferenceSpan:void 0,inferenceContext:void 0,embedSpans:new Map,rerankSpan:void 0,toolSpans:new Map,settings:o,provider:t.provider,modelId:t.modelId,runtimeContext:s,baseSupplementalAttributes:i})}onObjectOperationStart(t){var e;const n={recordInputs:t.recordInputs,recordOutputs:t.recordOutputs,functionId:t.functionId},o={maxOutputTokens:t.maxOutputTokens,temperature:t.temperature,topP:t.topP,topK:t.topK,presencePenalty:t.presencePenalty,frequencyPenalty:t.frequencyPenalty,seed:t.seed,maxRetries:t.maxRetries},r=R(t.provider),a=Rt(t.operationId),s=S(n,this.supplementalAttributes,{headers:ut(t.headers)}),i=h(n,{"gen_ai.operation.name":a,"gen_ai.provider.name":r,"gen_ai.request.model":t.modelId,"gen_ai.agent.name":n.functionId,"gen_ai.output.type":"json","gen_ai.request.frequency_penalty":t.frequencyPenalty,"gen_ai.request.max_tokens":t.maxOutputTokens,"gen_ai.request.presence_penalty":t.presencePenalty,"gen_ai.request.temperature":(e=t.temperature)!=null?e:void 0,"gen_ai.request.top_k":t.topK,"gen_ai.request.top_p":t.topP,"gen_ai.request.seed":t.seed,"gen_ai.system_instructions":t.system?{input:()=>JSON.stringify(jt(t.system))}:void 0,"gen_ai.input.messages":{input:()=>JSON.stringify(vt({prompt:t.prompt,messages:t.messages}))},...s,...S(n,this.supplementalAttributes,{schema:{"ai.schema":t.schema?{input:()=>JSON.stringify(t.schema)}:void 0,"ai.schema.name":t.schemaName,"ai.schema.description":t.schemaDescription,"ai.settings.output":t.output}})}),u=`${a} ${t.modelId}`,d=this.tracer.startSpan(u,{attributes:this.getSpanAttributes({attributes:i,spanType:"operation",operationId:t.operationId,callId:t.callId,runtimeContext:void 0}),kind:x.INTERNAL}),p=v.setSpan(T.active(),d);this.callStates.set(t.callId,{operationId:t.operationId,telemetry:n,rootSpan:d,rootContext:p,stepSpan:void 0,stepContext:void 0,inferenceSpan:void 0,inferenceContext:void 0,embedSpans:new Map,rerankSpan:void 0,toolSpans:new Map,settings:o,provider:t.provider,modelId:t.modelId,runtimeContext:void 0,baseSupplementalAttributes:s})}onObjectStepStart(t){var e;const n=this.getCallState(t.callId);if(!n?.rootSpan||!n.rootContext)return;const{telemetry:o}=n,r=R(t.provider),a=h(o,{"gen_ai.operation.name":"chat","gen_ai.provider.name":r,"gen_ai.request.model":t.modelId,"gen_ai.output.type":"json","gen_ai.request.frequency_penalty":n.settings.frequencyPenalty,"gen_ai.request.max_tokens":n.settings.maxOutputTokens,"gen_ai.request.presence_penalty":n.settings.presencePenalty,"gen_ai.request.temperature":(e=n.settings.temperature)!=null?e:void 0,"gen_ai.request.top_k":n.settings.topK,"gen_ai.request.top_p":n.settings.topP,"gen_ai.input.messages":{input:()=>t.promptMessages?JSON.stringify(We(t.promptMessages)):void 0},...n.baseSupplementalAttributes}),s=`chat ${t.modelId}`;n.inferenceSpan=this.tracer.startSpan(s,{attributes:this.getSpanAttributes({attributes:a,spanType:"languageModel",operationId:n.operationId,callId:t.callId,runtimeContext:n.runtimeContext}),kind:x.CLIENT},n.rootContext),n.inferenceContext=v.setSpan(n.rootContext,n.inferenceSpan)}onObjectStepEnd(t){var e;const n=this.getCallState(t.callId);if(!n?.inferenceSpan)return;const{telemetry:o}=n;n.inferenceSpan.setAttributes(h(o,{"gen_ai.response.finish_reasons":[t.finishReason],"gen_ai.response.id":t.response.id,"gen_ai.response.model":t.response.modelId,"gen_ai.usage.input_tokens":t.usage.inputTokens,"gen_ai.usage.output_tokens":t.usage.outputTokens,"gen_ai.usage.cache_read.input_tokens":(e=t.usage.inputTokenDetails)==null?void 0:e.cacheReadTokens,"gen_ai.output.messages":{output:()=>{try{return JSON.stringify($t({objectText:t.objectText,finishReason:t.finishReason}))}catch{return t.objectText}}},...S(o,this.supplementalAttributes,{providerMetadata:{"ai.response.providerMetadata":t.providerMetadata?JSON.stringify(t.providerMetadata):void 0},usage:V(t.usage)})})),n.inferenceSpan.end(),n.inferenceSpan=void 0,n.inferenceContext=void 0}onEmbedOperationStart(t){const e={recordInputs:t.recordInputs,recordOutputs:t.recordOutputs,functionId:t.functionId},n=R(t.provider),o=S(e,this.supplementalAttributes,{headers:ut(t.headers)}),r=t.value,a=t.operationId==="ai.embedMany",s=h(e,{"gen_ai.operation.name":"embeddings","gen_ai.provider.name":n,"gen_ai.request.model":t.modelId,...o,...S(e,this.supplementalAttributes,{embedding:a?{"ai.values":{input:()=>r.map(p=>JSON.stringify(p))}}:{"ai.value":{input:()=>JSON.stringify(r)}}})}),i=`embeddings ${t.modelId}`,u=this.tracer.startSpan(i,{attributes:this.getSpanAttributes({attributes:s,spanType:"operation",operationId:t.operationId,callId:t.callId,runtimeContext:void 0}),kind:x.CLIENT}),d=v.setSpan(T.active(),u);this.callStates.set(t.callId,{operationId:t.operationId,telemetry:e,rootSpan:u,rootContext:d,stepSpan:void 0,stepContext:void 0,inferenceSpan:void 0,inferenceContext:void 0,embedSpans:new Map,rerankSpan:void 0,toolSpans:new Map,settings:{maxRetries:t.maxRetries},provider:t.provider,modelId:t.modelId,runtimeContext:void 0,baseSupplementalAttributes:o})}onStepStart(t){const e=this.getCallState(t.callId);if(!e?.rootSpan||!e.rootContext)return;const{telemetry:n}=e;e.runtimeContext=t.runtimeContext;const o=h(n,{"gen_ai.operation.name":"agent_step",...e.baseSupplementalAttributes,...S(n,this.supplementalAttributes,{toolChoice:{"ai.prompt.toolChoice":{input:()=>t.stepToolChoice!=null?JSON.stringify(t.stepToolChoice):void 0}}})});e.stepSpan=this.tracer.startSpan(`step ${t.steps.length+1}`,{attributes:this.getSpanAttributes({attributes:o,spanType:"step",operationId:e.operationId,callId:t.callId,runtimeContext:e.runtimeContext}),kind:x.INTERNAL},e.rootContext),e.stepContext=v.setSpan(e.rootContext,e.stepSpan)}onLanguageModelCallStart(t){var e;const n=this.getCallState(t.callId);if(!n?.stepContext)return;const{telemetry:o}=n,r=R(t.provider),a=h(o,{"gen_ai.operation.name":"chat","gen_ai.provider.name":r,"gen_ai.request.model":t.modelId,"gen_ai.request.frequency_penalty":n.settings.frequencyPenalty,"gen_ai.request.max_tokens":n.settings.maxOutputTokens,"gen_ai.request.presence_penalty":n.settings.presencePenalty,"gen_ai.request.stop_sequences":n.settings.stopSequences,"gen_ai.request.temperature":(e=n.settings.temperature)!=null?e:void 0,"gen_ai.request.top_k":n.settings.topK,"gen_ai.request.top_p":n.settings.topP,"gen_ai.input.messages":{input:()=>{const s=vt({prompt:void 0,messages:t.messages});return s.length>0?JSON.stringify(s):void 0}},"gen_ai.tool.definitions":{input:()=>t.tools?JSON.stringify(t.tools):void 0}});n.inferenceSpan=this.tracer.startSpan(`chat ${t.modelId}`,{attributes:this.getSpanAttributes({attributes:a,spanType:"languageModel",operationId:n.operationId,callId:t.callId,runtimeContext:n.runtimeContext}),kind:x.CLIENT},n.stepContext),n.inferenceContext=v.setSpan(n.stepContext,n.inferenceSpan)}onLanguageModelCallEnd(t){var e,n;const o=this.getCallState(t.callId);if(!o?.inferenceSpan)return;const{telemetry:r}=o;o.inferenceSpan.setAttributes(h(r,{...ze(t.performance),"gen_ai.response.finish_reasons":[t.finishReason],"gen_ai.response.id":t.responseId,"gen_ai.usage.input_tokens":t.usage.inputTokens,"gen_ai.usage.output_tokens":t.usage.outputTokens,"gen_ai.usage.cache_read.input_tokens":(e=t.usage.inputTokenDetails)==null?void 0:e.cacheReadTokens,"gen_ai.usage.cache_creation.input_tokens":(n=t.usage.inputTokenDetails)==null?void 0:n.cacheWriteTokens,"gen_ai.output.messages":{output:()=>JSON.stringify(Nt({text:t.content.filter(a=>a.type==="text").map(a=>a.text).join("")||void 0,reasoning:t.content.filter(a=>a.type==="reasoning"),toolCalls:t.content.filter(a=>a.type==="tool-call"),files:t.content.filter(a=>a.type==="file").map(a=>a.file),finishReason:t.finishReason}))},...S(r,this.supplementalAttributes,{usage:V(t.usage)})})),o.inferenceSpan.end(),o.inferenceSpan=void 0,o.inferenceContext=void 0}onToolExecutionStart(t){const e=this.getCallState(t.callId);if(!e?.stepContext)return;const{telemetry:n}=e,{toolCall:o}=t,r=h(n,{"gen_ai.operation.name":"execute_tool","gen_ai.tool.name":o.toolName,"gen_ai.tool.call.id":o.toolCallId,"gen_ai.tool.type":"function","gen_ai.tool.call.arguments":{input:()=>JSON.stringify(o.input)}}),a=`execute_tool ${o.toolName}`,s=this.tracer.startSpan(a,{attributes:this.getSpanAttributes({attributes:r,spanType:"tool",operationId:e.operationId,callId:t.callId,runtimeContext:e.runtimeContext}),kind:x.INTERNAL},e.stepContext),i=v.setSpan(e.stepContext,s);e.toolSpans.set(o.toolCallId,{span:s,context:i})}onToolExecutionEnd(t){const e=this.getCallState(t.callId);if(!e)return;const n=e.toolSpans.get(t.toolCall.toolCallId);if(!n)return;const{span:o}=n,{telemetry:r}=e,{toolOutput:a}=t;if(o.setAttributes(h(r,{"gen_ai.execute_tool.duration":pt(t.toolExecutionMs)})),a.type==="tool-result")try{o.setAttributes(h(r,{"gen_ai.tool.call.result":{output:()=>JSON.stringify(a.output)}}))}catch{}else F(o,a.error);o.end(),e.toolSpans.delete(t.toolCall.toolCallId)}onStepEnd(t){const e=this.getCallState(t.callId);if(!e?.stepSpan)return;const{telemetry:n}=e;e.stepSpan.setAttributes(S(n,this.supplementalAttributes,{providerMetadata:{"ai.response.providerMetadata":t.providerMetadata?JSON.stringify(t.providerMetadata):void 0},usage:V(t.usage)})),e.stepSpan.end(),e.stepSpan=void 0,e.stepContext=void 0}onStepFinish(t){this.onStepEnd(t)}onEnd(t){const e=this.getCallState(t.callId);if(e?.rootSpan){if(e.operationId==="ai.embed"||e.operationId==="ai.embedMany"){this.onEmbedOperationEnd(t);return}if(e.operationId==="ai.rerank"){this.onRerankOperationEnd(t);return}if(e.operationId==="ai.generateObject"||e.operationId==="ai.streamObject"){this.onObjectOperationEnd(t);return}this.onGenerateEnd(t)}}onGenerateEnd(t){var e,n;const o=this.getCallState(t.callId);if(!o?.rootSpan)return;const{telemetry:r}=o;o.rootSpan.setAttributes(h(r,{"gen_ai.response.finish_reasons":[t.finishReason],"gen_ai.usage.input_tokens":t.usage.inputTokens,"gen_ai.usage.output_tokens":t.usage.outputTokens,"gen_ai.usage.cache_read.input_tokens":(e=t.usage.inputTokenDetails)==null?void 0:e.cacheReadTokens,"gen_ai.usage.cache_creation.input_tokens":(n=t.usage.inputTokenDetails)==null?void 0:n.cacheWriteTokens,"gen_ai.output.messages":{output:()=>{var a;return JSON.stringify(Nt({text:(a=t.text)!=null?a:void 0,reasoning:t.finalStep.reasoning,toolCalls:t.toolCalls,files:t.files,finishReason:t.finishReason}))}},...S(r,this.supplementalAttributes,{providerMetadata:{"ai.response.providerMetadata":t.finalStep.providerMetadata?JSON.stringify(t.finalStep.providerMetadata):void 0},usage:V(t.usage)})})),o.rootSpan.end(),this.cleanupCallState(t.callId)}onObjectOperationEnd(t){var e;const n=this.getCallState(t.callId);if(!n?.rootSpan)return;const{telemetry:o}=n;n.rootSpan.setAttributes(h(o,{"gen_ai.response.finish_reasons":[t.finishReason],"gen_ai.usage.input_tokens":t.usage.inputTokens,"gen_ai.usage.output_tokens":t.usage.outputTokens,"gen_ai.usage.cache_read.input_tokens":(e=t.usage.inputTokenDetails)==null?void 0:e.cacheReadTokens,"gen_ai.output.messages":{output:()=>t.object!=null?JSON.stringify($t({objectText:JSON.stringify(t.object),finishReason:t.finishReason})):void 0},...S(o,this.supplementalAttributes,{providerMetadata:{"ai.response.providerMetadata":t.providerMetadata?JSON.stringify(t.providerMetadata):void 0},usage:V(t.usage)})})),n.rootSpan.end(),this.cleanupCallState(t.callId)}onEmbedOperationEnd(t){const e=this.getCallState(t.callId);if(!e?.rootSpan)return;const{telemetry:n}=e,o=e.operationId==="ai.embedMany";e.rootSpan.setAttributes(h(n,{"gen_ai.usage.input_tokens":t.usage.tokens,...S(n,this.supplementalAttributes,{embedding:o?{"ai.embeddings":{output:()=>t.embedding.map(r=>JSON.stringify(r))}}:{"ai.embedding":{output:()=>JSON.stringify(t.embedding)}}})})),e.rootSpan.end(),this.cleanupCallState(t.callId)}onEmbedStart(t){const e=this.getCallState(t.callId);if(!e?.rootSpan||!e.rootContext)return;const{telemetry:n}=e,o=R(e.provider),r=h(n,{"gen_ai.operation.name":"embeddings","gen_ai.provider.name":o,"gen_ai.request.model":e.modelId,...e.baseSupplementalAttributes,...S(n,this.supplementalAttributes,{embedding:{"ai.values":{input:()=>t.values.map(u=>JSON.stringify(u))}}})}),a=`embeddings ${e.modelId}`,s=this.tracer.startSpan(a,{attributes:this.getSpanAttributes({attributes:r,spanType:"embedding",operationId:e.operationId,callId:t.callId,runtimeContext:e.runtimeContext}),kind:x.CLIENT},e.rootContext),i=v.setSpan(e.rootContext,s);e.embedSpans.set(t.embedCallId,{span:s,context:i})}onEmbedEnd(t){const e=this.getCallState(t.callId);if(!e)return;const n=e.embedSpans.get(t.embedCallId);if(!n)return;const{span:o}=n,{telemetry:r}=e;o.setAttributes(h(r,{"gen_ai.usage.input_tokens":t.usage.tokens,...S(r,this.supplementalAttributes,{embedding:{"ai.embeddings":{output:()=>t.embeddings.map(a=>JSON.stringify(a))}}})})),o.end(),e.embedSpans.delete(t.embedCallId)}onRerankOperationStart(t){const e={recordInputs:t.recordInputs,recordOutputs:t.recordOutputs,functionId:t.functionId},n=R(t.provider),o=S(e,this.supplementalAttributes,{headers:ut(t.headers)}),r=h(e,{"gen_ai.operation.name":"rerank","gen_ai.provider.name":n,"gen_ai.request.model":t.modelId,...o,...S(e,this.supplementalAttributes,{reranking:{"ai.documents":{input:()=>t.documents.map(u=>JSON.stringify(u))}}})}),a=`rerank ${t.modelId}`,s=this.tracer.startSpan(a,{attributes:this.getSpanAttributes({attributes:r,spanType:"operation",operationId:t.operationId,callId:t.callId,runtimeContext:void 0}),kind:x.CLIENT}),i=v.setSpan(T.active(),s);this.callStates.set(t.callId,{operationId:t.operationId,telemetry:e,rootSpan:s,rootContext:i,stepSpan:void 0,stepContext:void 0,inferenceSpan:void 0,inferenceContext:void 0,embedSpans:new Map,rerankSpan:void 0,toolSpans:new Map,settings:{maxRetries:t.maxRetries},provider:t.provider,modelId:t.modelId,runtimeContext:void 0,baseSupplementalAttributes:o})}onRerankOperationEnd(t){const e=this.getCallState(t.callId);e?.rootSpan&&(e.rootSpan.end(),this.cleanupCallState(t.callId))}onRerankStart(t){const e=this.getCallState(t.callId);if(!e?.rootSpan||!e.rootContext)return;const{telemetry:n}=e,o=R(e.provider),r=h(n,{"gen_ai.operation.name":"rerank","gen_ai.provider.name":o,"gen_ai.request.model":e.modelId,...e.baseSupplementalAttributes,...S(n,this.supplementalAttributes,{reranking:{"ai.documents":{input:()=>t.documents.map(u=>JSON.stringify(u))}}})}),a=`rerank ${e.modelId}`,s=this.tracer.startSpan(a,{attributes:this.getSpanAttributes({attributes:r,spanType:"reranking",operationId:e.operationId,callId:t.callId,runtimeContext:e.runtimeContext}),kind:x.CLIENT},e.rootContext),i=v.setSpan(e.rootContext,s);e.rerankSpan={span:s,context:i}}onRerankEnd(t){const e=this.getCallState(t.callId);if(!e?.rerankSpan)return;const{span:n}=e.rerankSpan,{telemetry:o}=e;n.setAttributes(S(o,this.supplementalAttributes,{reranking:{"ai.ranking.type":t.documentsType,"ai.ranking":{output:()=>t.ranking.map(r=>JSON.stringify(r))}}})),n.end(),e.rerankSpan=void 0}onAbort(t){const e=this.getCallState(t.callId);if(e?.rootSpan){for(const{span:n}of e.toolSpans.values())n.end();e.toolSpans.clear(),e.inferenceSpan&&(e.inferenceSpan.end(),e.inferenceSpan=void 0,e.inferenceContext=void 0),e.stepSpan&&(e.stepSpan.end(),e.stepSpan=void 0,e.stepContext=void 0);for(const{span:n}of e.embedSpans.values())n.end();e.embedSpans.clear(),e.rerankSpan&&(e.rerankSpan.span.end(),e.rerankSpan=void 0),e.rootSpan.end(),this.cleanupCallState(t.callId)}}onError(t){var e;const n=t;if(!n?.callId)return;const o=this.getCallState(n.callId);if(!o?.rootSpan)return;const r=(e=n.error)!=null?e:t;for(const{span:a}of o.toolSpans.values())F(a,r),a.end();o.toolSpans.clear(),o.inferenceSpan&&(F(o.inferenceSpan,r),o.inferenceSpan.end(),o.inferenceSpan=void 0,o.inferenceContext=void 0),o.stepSpan&&(F(o.stepSpan,r),o.stepSpan.end(),o.stepSpan=void 0,o.stepContext=void 0);for(const{span:a}of o.embedSpans.values())F(a,r),a.end();o.embedSpans.clear(),o.rerankSpan&&(F(o.rerankSpan.span,r),o.rerankSpan.span.end(),o.rerankSpan=void 0),F(o.rootSpan,r),o.rootSpan.end(),this.cleanupCallState(n.callId)}};function Ge(t){return pe({messages:t,emptyMessages:"remove",reasoning:"none",toolCalls:`before-last-${Gt}-messages`})}function He(t){return typeof t=="object"&&t!==null&&"role"in t&&"content"in t}function Ve(t){return Array.isArray(t)&&t.every(He)}function Ye(t,{conversationId:e,getModel:n}){let o=0;const r=()=>{const a=n?.();return a?{model_provider:a.provider,model_id:a.modelId}:{}};return{onStepStart:()=>{o+=1},onToolExecutionStart:a=>{t("com.redocly.aiChat.toolCallStarted",[{conversation_id:e,...rt("toolCall",a.toolCall.toolCallId,"ai"),tool_name:a.toolCall.toolName,input:a.toolCall.input,step_number:o,...r()}])},onToolExecutionEnd:a=>{const s=a.toolOutput.type==="tool-error";t("com.redocly.aiChat.toolCallFinished",[{conversation_id:e,...rt("toolCall",a.toolCall.toolCallId,"ai"),tool_name:a.toolCall.toolName,input:a.toolCall.input,step_number:o,success:!s,duration_ms:a.toolExecutionMs,...r(),...s&&{error:a.toolOutput.error instanceof Error?a.toolOutput.error.message:String(a.toolOutput.error)}}])},onStart:a=>{o=0,t("com.redocly.aiChat.conversationStarted",[{...rt("conversation",e,"ai"),model_provider:"provider"in a?a.provider:"unknown",model_id:"modelId"in a?a.modelId:"unknown"}])},onEnd:a=>{if(!("steps"in a))return;const s=a.usage;t("com.redocly.aiChat.conversationFinished",[{...rt("conversation",e,"ai"),model_provider:a.model.provider,model_id:a.model.modelId,success:!0,step_count:a.steps.length,finish_reason:a.finishReason,input_tokens:s.inputTokens,output_tokens:s.outputTokens,total_tokens:s.totalTokens}])}}}function Xe(t,e){const n=()=>v.getSpan(T.active())?T.active():e;return{startSpan:(o,r,a)=>t.startSpan(o,r,a??e),startActiveSpan:((o,r,a,s)=>{if(typeof r=="function")return t.startActiveSpan(o,{},n(),r);if(typeof a=="function")return t.startActiveSpan(o,r,n(),a);if(s)return t.startActiveSpan(o,r,a,s);throw new Error("withParentContext: invalid startActiveSpan invocation")})}}const Ze=`You are a helpful assistant that can generate titles for conversations.
|
|
1
|
+
import{X as v,Z as T,aC as x,O as _t,c as Qt,r as l,j as at}from"./redocly-openapi-docs.min.standalone-BFWv5fnd.js";import{T as Gt,c as rt,D as Ht,a as Vt,u as mt,b as gt,d as A,A as ft,I as Yt,e as E,f as Xt,g as Zt,h as te,i as wt,j as ee,k as ne,l as oe,m as ae,n as Tt,o as st,p as ht,q as At,r as re,s as se,t as Mt,R as it,v as ie,w as yt,x as le,y as ue}from"./redocly-openapi-docs.min.index-CVScN5cj.js";import{c as St,p as pe,g as ce,T as de,i as me,a as ge,s as fe,A as he,b as ye,r as Se,d as ve,e as be,o as Ie,f as ke,w as Ce,m as xe,h as _e,u as we,j as Te,k as Ae,l as Me,n as Oe,D as Ee,q as Re,t as je,v as qe,x as Ne,y as $e,z as Pe}from"./redocly-openapi-docs.min.useAiChatQueries-B9Y_hT0w.js";import{b as Ot,g as Et}from"./redocly-openapi-docs.min.ai-chat-mappers-Dza6UMVG.js";function R(t){const e=t.toLowerCase(),n=[["google.vertex","gcp.vertex_ai"],["google.generative-ai","gcp.gemini"],["google-vertex","gcp.vertex_ai"],["amazon-bedrock","aws.bedrock"],["azure-openai","azure.ai.openai"],["anthropic","anthropic"],["openai","openai"],["azure","azure.ai.inference"],["google","gcp.gemini"],["mistral","mistral_ai"],["cohere","cohere"],["bedrock","aws.bedrock"],["groq","groq"],["deepseek","deepseek"],["perplexity","perplexity"],["xai","x_ai"]];for(const[o,r]of n)if(e===o||e.startsWith(o+".")||e.startsWith(o+"-"))return r;return t}function Rt(t){var e;return(e={"ai.generateText":"invoke_agent","ai.streamText":"invoke_agent","ai.generateObject":"invoke_agent","ai.streamObject":"invoke_agent","ai.embed":"embeddings","ai.embedMany":"embeddings","ai.rerank":"rerank"}[t])!=null?e:t}function jt(t){return typeof t=="string"?[{type:"text",content:t}]:Array.isArray(t)?t.map(e=>({type:"text",content:e.content})):[{type:"text",content:t.content}]}function De(t){var e,n,o,r,a;switch(t.type){case"text":return{type:"text",content:t.text};case"reasoning":return{type:"reasoning",content:t.text};case"tool-call":return{type:"tool_call",id:(e=t.toolCallId)!=null?e:null,name:t.toolName,arguments:t.input};case"tool-result":{const s=t.output;let i;return s&&(s.type==="text"||s.type==="error-text"||s.type==="json"||s.type==="error-json"?i=s.value:s.type==="execution-denied"?i={denied:!0,reason:s.reason}:i=s),{type:"tool_call_response",id:(n=t.toolCallId)!=null?n:null,response:i}}case"file":{const s=t.data,i=(()=>{if(typeof s=="object"&&s!==null&&!(s instanceof URL)&&!(s instanceof Uint8Array)&&!(s instanceof ArrayBuffer)&&"type"in s)switch(s.type){case"data":return s.data;case"url":return s.url;case"text":return s.text;default:return""}return s})();let u;if(i instanceof Uint8Array)u=St(i);else if(typeof i=="string"){if(i.startsWith("http://")||i.startsWith("https://"))return{type:"uri",modality:j(t.mediaType),mime_type:(o=t.mediaType)!=null?o:null,uri:i};u=i}else{if(i instanceof URL)return{type:"uri",modality:j(t.mediaType),mime_type:(r=t.mediaType)!=null?r:null,uri:i.toString()};u=String(i)}return{type:"blob",modality:j(t.mediaType),mime_type:(a=t.mediaType)!=null?a:null,content:u}}case"tool-approval-response":return{type:"tool_approval_response",approval_id:t.approvalId,approved:t.approved,reason:t.reason};case"custom":return{type:"custom",kind:t.kind};case"reasoning-file":return{type:String(t.type)};default:return{type:String(t.type)}}}function j(t){return!t||t.startsWith("image/")?"image":t.startsWith("video/")?"video":t.startsWith("audio/")?"audio":"image"}function We(t){return t.filter(e=>e.role!=="system").map(e=>{if(e.role==="system")return{role:"system",parts:[{type:"text",content:e.content}]};const n=e.content.map(De);return{role:e.role,parts:n}})}function vt({prompt:t,messages:e}){const n=[];if(typeof t=="string")n.push({role:"user",parts:[{type:"text",content:t}]});else if(Array.isArray(t))for(const o of t){const r=qt(o);r&&n.push(r)}if(e)for(const o of e){const r=qt(o);r&&n.push(r)}return n}function qt(t){if(t.role!=="system"){if(t.role==="user")return typeof t.content=="string"?{role:"user",parts:[{type:"text",content:t.content}]}:{role:"user",parts:t.content.map(e=>{var n,o,r,a,s,i,u,d;switch(e.type){case"text":return{type:"text",content:e.text};case"image":{const p=e.image;return p instanceof URL?{type:"uri",modality:"image",mime_type:(n=e.mediaType)!=null?n:null,uri:p.toString()}:typeof p=="string"?p.startsWith("http://")||p.startsWith("https://")?{type:"uri",modality:"image",mime_type:(o=e.mediaType)!=null?o:null,uri:p}:{type:"blob",modality:"image",mime_type:(r=e.mediaType)!=null?r:null,content:p}:{type:"blob",modality:"image",mime_type:(a=e.mediaType)!=null?a:null,content:St(p)}}case"file":{const p=e.data,c=(()=>{if(typeof p=="object"&&p!==null&&!(p instanceof URL)&&!(p instanceof Uint8Array)&&!(p instanceof ArrayBuffer)&&"type"in p)switch(p.type){case"data":return p.data;case"url":return p.url;case"text":return p.text;default:return""}return p})();return c instanceof URL?{type:"uri",modality:j(e.mediaType),mime_type:(s=e.mediaType)!=null?s:null,uri:c.toString()}:typeof c=="string"?c.startsWith("http://")||c.startsWith("https://")?{type:"uri",modality:j(e.mediaType),mime_type:(i=e.mediaType)!=null?i:null,uri:c}:{type:"blob",modality:j(e.mediaType),mime_type:(u=e.mediaType)!=null?u:null,content:c}:{type:"blob",modality:j(e.mediaType),mime_type:(d=e.mediaType)!=null?d:null,content:St(c)}}default:return{type:String(e.type)}}})};if(t.role==="assistant")return typeof t.content=="string"?{role:"assistant",parts:[{type:"text",content:t.content}]}:{role:"assistant",parts:t.content.map(e=>{var n,o;switch(e.type){case"text":return{type:"text",content:e.text};case"reasoning":return{type:"reasoning",content:e.text};case"tool-call":return{type:"tool_call",id:(n=e.toolCallId)!=null?n:null,name:e.toolName,arguments:e.input};case"tool-result":{const r=e.output;let a;return r&&(r.type==="text"||r.type==="error-text"||r.type==="json"||r.type==="error-json"?a=r.value:r.type==="execution-denied"?a={denied:!0,reason:r.reason}:a=r),{type:"tool_call_response",id:(o=e.toolCallId)!=null?o:null,response:a}}default:return{type:String(e.type)}}})};if(t.role==="tool")return{role:"tool",parts:t.content.map(e=>{var n;if(e.type==="tool-result"){const o=e.output;let r;return o&&(o.type==="text"||o.type==="error-text"||o.type==="json"||o.type==="error-json"?r=o.value:o.type==="execution-denied"?r={denied:!0,reason:o.reason}:r=o),{type:"tool_call_response",id:(n=e.toolCallId)!=null?n:null,response:r}}return{type:String(e.type)}})}}}function Nt({text:t,reasoning:e,toolCalls:n,files:o,finishReason:r}){const a=[];if(e)for(const s of e)"text"in s&&s.text&&a.push({type:"reasoning",content:s.text});if(t!=null&&t.length>0&&a.push({type:"text",content:t}),n)for(const s of n)a.push({type:"tool_call",id:s.toolCallId,name:s.toolName,arguments:s.input});if(o)for(const s of o)a.push({type:"blob",modality:j(s.mediaType),mime_type:s.mediaType,content:s.base64});return[{role:"assistant",parts:a,finish_reason:Pt(r)}]}function $t({objectText:t,finishReason:e}){return[{role:"assistant",parts:[{type:"text",content:t}],finish_reason:Pt(e)}]}function Pt(t){var e;return(e={stop:"stop",length:"length","content-filter":"content_filter","tool-calls":"tool_call",error:"error",other:"stop",unknown:"stop"}[t])!=null?e:t}function F(t,e){e instanceof Error?(t.recordException({name:e.name,message:e.message,stack:e.stack}),t.setStatus({code:_t.ERROR,message:e.message})):t.setStatus({code:_t.ERROR})}function Je(t){return typeof t=="string"||typeof t=="number"||typeof t=="boolean"}function lt(t){if(!Array.isArray(t))return t;const e=new Set(t.filter(Je).map(o=>typeof o));if(e.size!==1)return;const[n]=e;return n==="string"?t.filter(o=>typeof o=="string"):n==="number"?t.filter(o=>typeof o=="number"):t.filter(o=>typeof o=="boolean")}function Le(t){const e={};for(const[n,o]of Object.entries(t??{})){if(o==null)continue;const r=lt(o);r!=null&&(e[n]=r)}return e}function Fe(t){return t?.isEnabled!==!1}function h(t,e){if(!Fe(t))return{};const n={};for(const[o,r]of Object.entries(e)){if(r==null)continue;if(typeof r=="object"&&"input"in r&&typeof r.input=="function"){if(t?.recordInputs===!1)continue;const s=r.input();if(s!=null){const i=lt(s);i!=null&&(n[o]=i)}continue}if(typeof r=="object"&&"output"in r&&typeof r.output=="function"){if(t?.recordOutputs===!1)continue;const s=r.output();if(s!=null){const i=lt(s);i!=null&&(n[o]=i)}continue}const a=lt(r);a!=null&&(n[o]=a)}return n}var Ue={usage:!1,providerMetadata:!1,embedding:!1,reranking:!1,runtimeContext:!1,headers:!1,toolChoice:!1,schema:!1};function Ke(t){var e,n,o,r,a,s,i,u;return{...Ue,usage:(e=t.usage)!=null?e:!1,providerMetadata:(n=t.providerMetadata)!=null?n:!1,embedding:(o=t.embedding)!=null?o:!1,reranking:(r=t.reranking)!=null?r:!1,runtimeContext:(a=t.runtimeContext)!=null?a:!1,headers:(s=t.headers)!=null?s:!1,toolChoice:(i=t.toolChoice)!=null?i:!1,schema:(u=t.schema)!=null?u:!1}}function Be(t){const e={};for(const[n,o]of Object.entries(t??{}))Dt(e,`ai.settings.context.${n}`,o);return e}function Dt(t,e,n){if(n!=null){if(Array.isArray(n)||typeof n!="object"){t[e]=n;return}for(const[o,r]of Object.entries(n))Dt(t,`${e}.${o}`,r)}}function ut(t){return Object.fromEntries(Object.entries(t??{}).filter(([,e])=>e!=null).map(([e,n])=>[`ai.request.headers.${e}`,n]))}function V(t){var e,n,o;return{"ai.usage.inputTokenDetails.noCacheTokens":(e=t.inputTokenDetails)==null?void 0:e.noCacheTokens,"ai.usage.outputTokenDetails.textTokens":(n=t.outputTokenDetails)==null?void 0:n.textTokens,"ai.usage.outputTokenDetails.reasoningTokens":(o=t.outputTokenDetails)==null?void 0:o.reasoningTokens}}function S(t,e,n){const o={};for(const[r,a]of Object.entries(n))!e[r]||a==null||Object.assign(o,h(t,a));return o}function pt(t){return t==null?void 0:t/1e3}function ze(t){var e;return{"gen_ai.client.operation.duration":pt(t.responseTimeMs),"gen_ai.client.operation.time_to_first_chunk":pt(t.timeToFirstOutputMs),"gen_ai.client.operation.time_per_output_chunk":pt((e=t.timeBetweenOutputChunksMs)==null?void 0:e.avg)}}var Qe=class{constructor(t={}){this.callStates=new Map;var e;this.tracer=(e=t.tracer)!=null?e:v.getTracer("gen_ai"),this.supplementalAttributes=Ke(t),this.enrichSpan=t.enrichSpan}getCallState(t){return this.callStates.get(t)}cleanupCallState(t){this.callStates.delete(t)}getSpanAttributes({attributes:t,spanType:e,operationId:n,callId:o,runtimeContext:r}){var a;let s;try{s=(a=this.enrichSpan)==null?void 0:a.call(this,{spanType:e,operationId:n,callId:o,runtimeContext:r})}catch{s=void 0}return{...Le(s),...t}}executeTool({callId:t,toolCallId:e,execute:n}){var o;const r=(o=this.getCallState(t))==null?void 0:o.toolSpans.get(e);return r==null?n():T.with(r.context,n)}executeLanguageModelCall({callId:t,execute:e}){var n;const o=this.getCallState(t),r=(n=o?.inferenceContext)!=null?n:o?.stepContext;return r==null?e():T.with(r,e)}onStart(t){if(t.operationId==="ai.embed"||t.operationId==="ai.embedMany"){this.onEmbedOperationStart(t);return}if(t.operationId==="ai.rerank"){this.onRerankOperationStart(t);return}if(t.operationId==="ai.generateObject"||t.operationId==="ai.streamObject"){this.onObjectOperationStart(t);return}this.onGenerateStart(t)}onGenerateStart(t){var e;const n={recordInputs:t.recordInputs,recordOutputs:t.recordOutputs,functionId:t.functionId},o={maxOutputTokens:t.maxOutputTokens,temperature:t.temperature,topP:t.topP,topK:t.topK,presencePenalty:t.presencePenalty,frequencyPenalty:t.frequencyPenalty,stopSequences:t.stopSequences,seed:t.seed,maxRetries:t.maxRetries},r=R(t.provider),a=Rt(t.operationId),s=t.runtimeContext,i=S(n,this.supplementalAttributes,{runtimeContext:Be(s),headers:ut(t.headers)}),u=h(n,{"gen_ai.operation.name":a,"gen_ai.provider.name":r,"gen_ai.request.model":t.modelId,"gen_ai.agent.name":n.functionId,"gen_ai.request.frequency_penalty":t.frequencyPenalty,"gen_ai.request.max_tokens":t.maxOutputTokens,"gen_ai.request.presence_penalty":t.presencePenalty,"gen_ai.request.temperature":(e=t.temperature)!=null?e:void 0,"gen_ai.request.top_k":t.topK,"gen_ai.request.top_p":t.topP,"gen_ai.request.stop_sequences":t.stopSequences,"gen_ai.request.seed":t.seed,"gen_ai.system_instructions":t.instructions?{input:()=>JSON.stringify(jt(t.instructions))}:void 0,"gen_ai.input.messages":{input:()=>JSON.stringify(vt({prompt:void 0,messages:t.messages}))},...i}),d=`${a} ${t.modelId}`,p=this.tracer.startSpan(d,{attributes:this.getSpanAttributes({attributes:u,spanType:"operation",operationId:t.operationId,callId:t.callId,runtimeContext:s}),kind:x.INTERNAL}),c=v.setSpan(T.active(),p);this.callStates.set(t.callId,{operationId:t.operationId,telemetry:n,rootSpan:p,rootContext:c,stepSpan:void 0,stepContext:void 0,inferenceSpan:void 0,inferenceContext:void 0,embedSpans:new Map,rerankSpan:void 0,toolSpans:new Map,settings:o,provider:t.provider,modelId:t.modelId,runtimeContext:s,baseSupplementalAttributes:i})}onObjectOperationStart(t){var e;const n={recordInputs:t.recordInputs,recordOutputs:t.recordOutputs,functionId:t.functionId},o={maxOutputTokens:t.maxOutputTokens,temperature:t.temperature,topP:t.topP,topK:t.topK,presencePenalty:t.presencePenalty,frequencyPenalty:t.frequencyPenalty,seed:t.seed,maxRetries:t.maxRetries},r=R(t.provider),a=Rt(t.operationId),s=S(n,this.supplementalAttributes,{headers:ut(t.headers)}),i=h(n,{"gen_ai.operation.name":a,"gen_ai.provider.name":r,"gen_ai.request.model":t.modelId,"gen_ai.agent.name":n.functionId,"gen_ai.output.type":"json","gen_ai.request.frequency_penalty":t.frequencyPenalty,"gen_ai.request.max_tokens":t.maxOutputTokens,"gen_ai.request.presence_penalty":t.presencePenalty,"gen_ai.request.temperature":(e=t.temperature)!=null?e:void 0,"gen_ai.request.top_k":t.topK,"gen_ai.request.top_p":t.topP,"gen_ai.request.seed":t.seed,"gen_ai.system_instructions":t.system?{input:()=>JSON.stringify(jt(t.system))}:void 0,"gen_ai.input.messages":{input:()=>JSON.stringify(vt({prompt:t.prompt,messages:t.messages}))},...s,...S(n,this.supplementalAttributes,{schema:{"ai.schema":t.schema?{input:()=>JSON.stringify(t.schema)}:void 0,"ai.schema.name":t.schemaName,"ai.schema.description":t.schemaDescription,"ai.settings.output":t.output}})}),u=`${a} ${t.modelId}`,d=this.tracer.startSpan(u,{attributes:this.getSpanAttributes({attributes:i,spanType:"operation",operationId:t.operationId,callId:t.callId,runtimeContext:void 0}),kind:x.INTERNAL}),p=v.setSpan(T.active(),d);this.callStates.set(t.callId,{operationId:t.operationId,telemetry:n,rootSpan:d,rootContext:p,stepSpan:void 0,stepContext:void 0,inferenceSpan:void 0,inferenceContext:void 0,embedSpans:new Map,rerankSpan:void 0,toolSpans:new Map,settings:o,provider:t.provider,modelId:t.modelId,runtimeContext:void 0,baseSupplementalAttributes:s})}onObjectStepStart(t){var e;const n=this.getCallState(t.callId);if(!n?.rootSpan||!n.rootContext)return;const{telemetry:o}=n,r=R(t.provider),a=h(o,{"gen_ai.operation.name":"chat","gen_ai.provider.name":r,"gen_ai.request.model":t.modelId,"gen_ai.output.type":"json","gen_ai.request.frequency_penalty":n.settings.frequencyPenalty,"gen_ai.request.max_tokens":n.settings.maxOutputTokens,"gen_ai.request.presence_penalty":n.settings.presencePenalty,"gen_ai.request.temperature":(e=n.settings.temperature)!=null?e:void 0,"gen_ai.request.top_k":n.settings.topK,"gen_ai.request.top_p":n.settings.topP,"gen_ai.input.messages":{input:()=>t.promptMessages?JSON.stringify(We(t.promptMessages)):void 0},...n.baseSupplementalAttributes}),s=`chat ${t.modelId}`;n.inferenceSpan=this.tracer.startSpan(s,{attributes:this.getSpanAttributes({attributes:a,spanType:"languageModel",operationId:n.operationId,callId:t.callId,runtimeContext:n.runtimeContext}),kind:x.CLIENT},n.rootContext),n.inferenceContext=v.setSpan(n.rootContext,n.inferenceSpan)}onObjectStepEnd(t){var e;const n=this.getCallState(t.callId);if(!n?.inferenceSpan)return;const{telemetry:o}=n;n.inferenceSpan.setAttributes(h(o,{"gen_ai.response.finish_reasons":[t.finishReason],"gen_ai.response.id":t.response.id,"gen_ai.response.model":t.response.modelId,"gen_ai.usage.input_tokens":t.usage.inputTokens,"gen_ai.usage.output_tokens":t.usage.outputTokens,"gen_ai.usage.cache_read.input_tokens":(e=t.usage.inputTokenDetails)==null?void 0:e.cacheReadTokens,"gen_ai.output.messages":{output:()=>{try{return JSON.stringify($t({objectText:t.objectText,finishReason:t.finishReason}))}catch{return t.objectText}}},...S(o,this.supplementalAttributes,{providerMetadata:{"ai.response.providerMetadata":t.providerMetadata?JSON.stringify(t.providerMetadata):void 0},usage:V(t.usage)})})),n.inferenceSpan.end(),n.inferenceSpan=void 0,n.inferenceContext=void 0}onEmbedOperationStart(t){const e={recordInputs:t.recordInputs,recordOutputs:t.recordOutputs,functionId:t.functionId},n=R(t.provider),o=S(e,this.supplementalAttributes,{headers:ut(t.headers)}),r=t.value,a=t.operationId==="ai.embedMany",s=h(e,{"gen_ai.operation.name":"embeddings","gen_ai.provider.name":n,"gen_ai.request.model":t.modelId,...o,...S(e,this.supplementalAttributes,{embedding:a?{"ai.values":{input:()=>r.map(p=>JSON.stringify(p))}}:{"ai.value":{input:()=>JSON.stringify(r)}}})}),i=`embeddings ${t.modelId}`,u=this.tracer.startSpan(i,{attributes:this.getSpanAttributes({attributes:s,spanType:"operation",operationId:t.operationId,callId:t.callId,runtimeContext:void 0}),kind:x.CLIENT}),d=v.setSpan(T.active(),u);this.callStates.set(t.callId,{operationId:t.operationId,telemetry:e,rootSpan:u,rootContext:d,stepSpan:void 0,stepContext:void 0,inferenceSpan:void 0,inferenceContext:void 0,embedSpans:new Map,rerankSpan:void 0,toolSpans:new Map,settings:{maxRetries:t.maxRetries},provider:t.provider,modelId:t.modelId,runtimeContext:void 0,baseSupplementalAttributes:o})}onStepStart(t){const e=this.getCallState(t.callId);if(!e?.rootSpan||!e.rootContext)return;const{telemetry:n}=e;e.runtimeContext=t.runtimeContext;const o=h(n,{"gen_ai.operation.name":"agent_step",...e.baseSupplementalAttributes,...S(n,this.supplementalAttributes,{toolChoice:{"ai.prompt.toolChoice":{input:()=>t.stepToolChoice!=null?JSON.stringify(t.stepToolChoice):void 0}}})});e.stepSpan=this.tracer.startSpan(`step ${t.steps.length+1}`,{attributes:this.getSpanAttributes({attributes:o,spanType:"step",operationId:e.operationId,callId:t.callId,runtimeContext:e.runtimeContext}),kind:x.INTERNAL},e.rootContext),e.stepContext=v.setSpan(e.rootContext,e.stepSpan)}onLanguageModelCallStart(t){var e;const n=this.getCallState(t.callId);if(!n?.stepContext)return;const{telemetry:o}=n,r=R(t.provider),a=h(o,{"gen_ai.operation.name":"chat","gen_ai.provider.name":r,"gen_ai.request.model":t.modelId,"gen_ai.request.frequency_penalty":n.settings.frequencyPenalty,"gen_ai.request.max_tokens":n.settings.maxOutputTokens,"gen_ai.request.presence_penalty":n.settings.presencePenalty,"gen_ai.request.stop_sequences":n.settings.stopSequences,"gen_ai.request.temperature":(e=n.settings.temperature)!=null?e:void 0,"gen_ai.request.top_k":n.settings.topK,"gen_ai.request.top_p":n.settings.topP,"gen_ai.input.messages":{input:()=>{const s=vt({prompt:void 0,messages:t.messages});return s.length>0?JSON.stringify(s):void 0}},"gen_ai.tool.definitions":{input:()=>t.tools?JSON.stringify(t.tools):void 0}});n.inferenceSpan=this.tracer.startSpan(`chat ${t.modelId}`,{attributes:this.getSpanAttributes({attributes:a,spanType:"languageModel",operationId:n.operationId,callId:t.callId,runtimeContext:n.runtimeContext}),kind:x.CLIENT},n.stepContext),n.inferenceContext=v.setSpan(n.stepContext,n.inferenceSpan)}onLanguageModelCallEnd(t){var e,n;const o=this.getCallState(t.callId);if(!o?.inferenceSpan)return;const{telemetry:r}=o;o.inferenceSpan.setAttributes(h(r,{...ze(t.performance),"gen_ai.response.finish_reasons":[t.finishReason],"gen_ai.response.id":t.responseId,"gen_ai.usage.input_tokens":t.usage.inputTokens,"gen_ai.usage.output_tokens":t.usage.outputTokens,"gen_ai.usage.cache_read.input_tokens":(e=t.usage.inputTokenDetails)==null?void 0:e.cacheReadTokens,"gen_ai.usage.cache_creation.input_tokens":(n=t.usage.inputTokenDetails)==null?void 0:n.cacheWriteTokens,"gen_ai.output.messages":{output:()=>JSON.stringify(Nt({text:t.content.filter(a=>a.type==="text").map(a=>a.text).join("")||void 0,reasoning:t.content.filter(a=>a.type==="reasoning"),toolCalls:t.content.filter(a=>a.type==="tool-call"),files:t.content.filter(a=>a.type==="file").map(a=>a.file),finishReason:t.finishReason}))},...S(r,this.supplementalAttributes,{usage:V(t.usage)})})),o.inferenceSpan.end(),o.inferenceSpan=void 0,o.inferenceContext=void 0}onToolExecutionStart(t){const e=this.getCallState(t.callId);if(!e?.stepContext)return;const{telemetry:n}=e,{toolCall:o}=t,r=h(n,{"gen_ai.operation.name":"execute_tool","gen_ai.tool.name":o.toolName,"gen_ai.tool.call.id":o.toolCallId,"gen_ai.tool.type":"function","gen_ai.tool.call.arguments":{input:()=>JSON.stringify(o.input)}}),a=`execute_tool ${o.toolName}`,s=this.tracer.startSpan(a,{attributes:this.getSpanAttributes({attributes:r,spanType:"tool",operationId:e.operationId,callId:t.callId,runtimeContext:e.runtimeContext}),kind:x.INTERNAL},e.stepContext),i=v.setSpan(e.stepContext,s);e.toolSpans.set(o.toolCallId,{span:s,context:i})}onToolExecutionEnd(t){const e=this.getCallState(t.callId);if(!e)return;const n=e.toolSpans.get(t.toolCall.toolCallId);if(!n)return;const{span:o}=n,{telemetry:r}=e,{toolOutput:a}=t;if(o.setAttributes(h(r,{"gen_ai.execute_tool.duration":pt(t.toolExecutionMs)})),a.type==="tool-result")try{o.setAttributes(h(r,{"gen_ai.tool.call.result":{output:()=>JSON.stringify(a.output)}}))}catch{}else F(o,a.error);o.end(),e.toolSpans.delete(t.toolCall.toolCallId)}onStepEnd(t){const e=this.getCallState(t.callId);if(!e?.stepSpan)return;const{telemetry:n}=e;e.stepSpan.setAttributes(S(n,this.supplementalAttributes,{providerMetadata:{"ai.response.providerMetadata":t.providerMetadata?JSON.stringify(t.providerMetadata):void 0},usage:V(t.usage)})),e.stepSpan.end(),e.stepSpan=void 0,e.stepContext=void 0}onStepFinish(t){this.onStepEnd(t)}onEnd(t){const e=this.getCallState(t.callId);if(e?.rootSpan){if(e.operationId==="ai.embed"||e.operationId==="ai.embedMany"){this.onEmbedOperationEnd(t);return}if(e.operationId==="ai.rerank"){this.onRerankOperationEnd(t);return}if(e.operationId==="ai.generateObject"||e.operationId==="ai.streamObject"){this.onObjectOperationEnd(t);return}this.onGenerateEnd(t)}}onGenerateEnd(t){var e,n;const o=this.getCallState(t.callId);if(!o?.rootSpan)return;const{telemetry:r}=o;o.rootSpan.setAttributes(h(r,{"gen_ai.response.finish_reasons":[t.finishReason],"gen_ai.usage.input_tokens":t.usage.inputTokens,"gen_ai.usage.output_tokens":t.usage.outputTokens,"gen_ai.usage.cache_read.input_tokens":(e=t.usage.inputTokenDetails)==null?void 0:e.cacheReadTokens,"gen_ai.usage.cache_creation.input_tokens":(n=t.usage.inputTokenDetails)==null?void 0:n.cacheWriteTokens,"gen_ai.output.messages":{output:()=>{var a;return JSON.stringify(Nt({text:(a=t.text)!=null?a:void 0,reasoning:t.finalStep.reasoning,toolCalls:t.toolCalls,files:t.files,finishReason:t.finishReason}))}},...S(r,this.supplementalAttributes,{providerMetadata:{"ai.response.providerMetadata":t.finalStep.providerMetadata?JSON.stringify(t.finalStep.providerMetadata):void 0},usage:V(t.usage)})})),o.rootSpan.end(),this.cleanupCallState(t.callId)}onObjectOperationEnd(t){var e;const n=this.getCallState(t.callId);if(!n?.rootSpan)return;const{telemetry:o}=n;n.rootSpan.setAttributes(h(o,{"gen_ai.response.finish_reasons":[t.finishReason],"gen_ai.usage.input_tokens":t.usage.inputTokens,"gen_ai.usage.output_tokens":t.usage.outputTokens,"gen_ai.usage.cache_read.input_tokens":(e=t.usage.inputTokenDetails)==null?void 0:e.cacheReadTokens,"gen_ai.output.messages":{output:()=>t.object!=null?JSON.stringify($t({objectText:JSON.stringify(t.object),finishReason:t.finishReason})):void 0},...S(o,this.supplementalAttributes,{providerMetadata:{"ai.response.providerMetadata":t.providerMetadata?JSON.stringify(t.providerMetadata):void 0},usage:V(t.usage)})})),n.rootSpan.end(),this.cleanupCallState(t.callId)}onEmbedOperationEnd(t){const e=this.getCallState(t.callId);if(!e?.rootSpan)return;const{telemetry:n}=e,o=e.operationId==="ai.embedMany";e.rootSpan.setAttributes(h(n,{"gen_ai.usage.input_tokens":t.usage.tokens,...S(n,this.supplementalAttributes,{embedding:o?{"ai.embeddings":{output:()=>t.embedding.map(r=>JSON.stringify(r))}}:{"ai.embedding":{output:()=>JSON.stringify(t.embedding)}}})})),e.rootSpan.end(),this.cleanupCallState(t.callId)}onEmbedStart(t){const e=this.getCallState(t.callId);if(!e?.rootSpan||!e.rootContext)return;const{telemetry:n}=e,o=R(e.provider),r=h(n,{"gen_ai.operation.name":"embeddings","gen_ai.provider.name":o,"gen_ai.request.model":e.modelId,...e.baseSupplementalAttributes,...S(n,this.supplementalAttributes,{embedding:{"ai.values":{input:()=>t.values.map(u=>JSON.stringify(u))}}})}),a=`embeddings ${e.modelId}`,s=this.tracer.startSpan(a,{attributes:this.getSpanAttributes({attributes:r,spanType:"embedding",operationId:e.operationId,callId:t.callId,runtimeContext:e.runtimeContext}),kind:x.CLIENT},e.rootContext),i=v.setSpan(e.rootContext,s);e.embedSpans.set(t.embedCallId,{span:s,context:i})}onEmbedEnd(t){const e=this.getCallState(t.callId);if(!e)return;const n=e.embedSpans.get(t.embedCallId);if(!n)return;const{span:o}=n,{telemetry:r}=e;o.setAttributes(h(r,{"gen_ai.usage.input_tokens":t.usage.tokens,...S(r,this.supplementalAttributes,{embedding:{"ai.embeddings":{output:()=>t.embeddings.map(a=>JSON.stringify(a))}}})})),o.end(),e.embedSpans.delete(t.embedCallId)}onRerankOperationStart(t){const e={recordInputs:t.recordInputs,recordOutputs:t.recordOutputs,functionId:t.functionId},n=R(t.provider),o=S(e,this.supplementalAttributes,{headers:ut(t.headers)}),r=h(e,{"gen_ai.operation.name":"rerank","gen_ai.provider.name":n,"gen_ai.request.model":t.modelId,...o,...S(e,this.supplementalAttributes,{reranking:{"ai.documents":{input:()=>t.documents.map(u=>JSON.stringify(u))}}})}),a=`rerank ${t.modelId}`,s=this.tracer.startSpan(a,{attributes:this.getSpanAttributes({attributes:r,spanType:"operation",operationId:t.operationId,callId:t.callId,runtimeContext:void 0}),kind:x.CLIENT}),i=v.setSpan(T.active(),s);this.callStates.set(t.callId,{operationId:t.operationId,telemetry:e,rootSpan:s,rootContext:i,stepSpan:void 0,stepContext:void 0,inferenceSpan:void 0,inferenceContext:void 0,embedSpans:new Map,rerankSpan:void 0,toolSpans:new Map,settings:{maxRetries:t.maxRetries},provider:t.provider,modelId:t.modelId,runtimeContext:void 0,baseSupplementalAttributes:o})}onRerankOperationEnd(t){const e=this.getCallState(t.callId);e?.rootSpan&&(e.rootSpan.end(),this.cleanupCallState(t.callId))}onRerankStart(t){const e=this.getCallState(t.callId);if(!e?.rootSpan||!e.rootContext)return;const{telemetry:n}=e,o=R(e.provider),r=h(n,{"gen_ai.operation.name":"rerank","gen_ai.provider.name":o,"gen_ai.request.model":e.modelId,...e.baseSupplementalAttributes,...S(n,this.supplementalAttributes,{reranking:{"ai.documents":{input:()=>t.documents.map(u=>JSON.stringify(u))}}})}),a=`rerank ${e.modelId}`,s=this.tracer.startSpan(a,{attributes:this.getSpanAttributes({attributes:r,spanType:"reranking",operationId:e.operationId,callId:t.callId,runtimeContext:e.runtimeContext}),kind:x.CLIENT},e.rootContext),i=v.setSpan(e.rootContext,s);e.rerankSpan={span:s,context:i}}onRerankEnd(t){const e=this.getCallState(t.callId);if(!e?.rerankSpan)return;const{span:n}=e.rerankSpan,{telemetry:o}=e;n.setAttributes(S(o,this.supplementalAttributes,{reranking:{"ai.ranking.type":t.documentsType,"ai.ranking":{output:()=>t.ranking.map(r=>JSON.stringify(r))}}})),n.end(),e.rerankSpan=void 0}onAbort(t){const e=this.getCallState(t.callId);if(e?.rootSpan){for(const{span:n}of e.toolSpans.values())n.end();e.toolSpans.clear(),e.inferenceSpan&&(e.inferenceSpan.end(),e.inferenceSpan=void 0,e.inferenceContext=void 0),e.stepSpan&&(e.stepSpan.end(),e.stepSpan=void 0,e.stepContext=void 0);for(const{span:n}of e.embedSpans.values())n.end();e.embedSpans.clear(),e.rerankSpan&&(e.rerankSpan.span.end(),e.rerankSpan=void 0),e.rootSpan.end(),this.cleanupCallState(t.callId)}}onError(t){var e;const n=t;if(!n?.callId)return;const o=this.getCallState(n.callId);if(!o?.rootSpan)return;const r=(e=n.error)!=null?e:t;for(const{span:a}of o.toolSpans.values())F(a,r),a.end();o.toolSpans.clear(),o.inferenceSpan&&(F(o.inferenceSpan,r),o.inferenceSpan.end(),o.inferenceSpan=void 0,o.inferenceContext=void 0),o.stepSpan&&(F(o.stepSpan,r),o.stepSpan.end(),o.stepSpan=void 0,o.stepContext=void 0);for(const{span:a}of o.embedSpans.values())F(a,r),a.end();o.embedSpans.clear(),o.rerankSpan&&(F(o.rerankSpan.span,r),o.rerankSpan.span.end(),o.rerankSpan=void 0),F(o.rootSpan,r),o.rootSpan.end(),this.cleanupCallState(n.callId)}};function Ge(t){return pe({messages:t,emptyMessages:"remove",reasoning:"none",toolCalls:`before-last-${Gt}-messages`})}function He(t){return typeof t=="object"&&t!==null&&"role"in t&&"content"in t}function Ve(t){return Array.isArray(t)&&t.every(He)}function Ye(t,{conversationId:e,getModel:n}){let o=0;const r=()=>{const a=n?.();return a?{model_provider:a.provider,model_id:a.modelId}:{}};return{onStepStart:()=>{o+=1},onToolExecutionStart:a=>{t("com.redocly.aiChat.toolCallStarted",[{conversation_id:e,...rt("toolCall",a.toolCall.toolCallId,"ai"),tool_name:a.toolCall.toolName,input:a.toolCall.input,step_number:o,...r()}])},onToolExecutionEnd:a=>{const s=a.toolOutput.type==="tool-error";t("com.redocly.aiChat.toolCallFinished",[{conversation_id:e,...rt("toolCall",a.toolCall.toolCallId,"ai"),tool_name:a.toolCall.toolName,input:a.toolCall.input,step_number:o,success:!s,duration_ms:a.toolExecutionMs,...r(),...s&&{error:a.toolOutput.error instanceof Error?a.toolOutput.error.message:String(a.toolOutput.error)}}])},onStart:a=>{o=0,t("com.redocly.aiChat.conversationStarted",[{...rt("conversation",e,"ai"),model_provider:"provider"in a?a.provider:"unknown",model_id:"modelId"in a?a.modelId:"unknown"}])},onEnd:a=>{if(!("steps"in a))return;const s=a.usage;t("com.redocly.aiChat.conversationFinished",[{...rt("conversation",e,"ai"),model_provider:a.model.provider,model_id:a.model.modelId,success:!0,step_count:a.steps.length,finish_reason:a.finishReason,input_tokens:s.inputTokens,output_tokens:s.outputTokens,total_tokens:s.totalTokens}])}}}function Xe(t,e){const n=()=>v.getSpan(T.active())?T.active():e;return{startSpan:(o,r,a)=>t.startSpan(o,r,a??e),startActiveSpan:((o,r,a,s)=>{if(typeof r=="function")return t.startActiveSpan(o,{},n(),r);if(typeof a=="function")return t.startActiveSpan(o,r,n(),a);if(s)return t.startActiveSpan(o,r,a,s);throw new Error("withParentContext: invalid startActiveSpan invocation")})}}const Ze=`You are a helpful assistant that can generate titles for conversations.
|
|
2
2
|
|
|
3
3
|
## Rules
|
|
4
4
|
- Titles should be at most 30 characters.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as o,a as m,d as y}from"./redocly-openapi-docs.min.ai-chat-mappers-
|
|
1
|
+
import{c as o,a as m,d as y}from"./redocly-openapi-docs.min.ai-chat-mappers-Dza6UMVG.js";import{a as h,b as r,c as d}from"./redocly-openapi-docs.min.ai-message-parts.schema-C7fjQhYX.js";import{a as c,e as a,b as g}from"./redocly-openapi-docs.min.indexes-Bp4ld5gB.js";const u={orderBy:[c(r.createdAt),c(r.indexWithinInsertBatch)],with:{parts:{orderBy:[c(h.index)]}}};class b{constructor(t){this.sqliteDB=t}sqliteDB;async findAll(){return await this.initialize(),(await this.db.query.aiChats.findMany({with:{messages:u}})).map(o)}async findRecentChatsPage(t){await this.initialize();const i=t.limit+1,s=await this.db.query.aiChats.findMany({orderBy:(l,{desc:w})=>w(l.updatedAt),limit:i,offset:t.offset}),e=s.slice(0,t.limit),n=s.length>t.limit,f=t.offset+e.length;return{items:e.map(l=>{const w={...l,messages:[]};return o(w)}),hasMore:n,nextOffset:f}}async findOne(t){await this.initialize();const i=await this.db.query.aiChats.findFirst({where:a(d.id,t),with:{messages:u}});return i&&o(i)}async upsert(t){await this.initialize();const i=m(t);await this.db.query.aiChats.findFirst({where:a(d.id,i.id),columns:{id:!0}})?await this.db.update(d).set(i).where(a(d.id,i.id)):await this.db.insert(d).values(i);for(let s=0;s<t.messages.length;s++)await this.upsertMessageRowAndParts(t.id,s,t.messages[s])}async remove(t){await this.initialize(),await this.db.delete(d).where(a(d.id,t))}async upsertMessageRowAndParts(t,i,s){const e=await this.db.query.aiMessages.findFirst({where:g(a(r.aiChatId,t),a(r.uiId,s.id))}),n=y(t,i,s,e?.id);e?await this.db.update(r).set({...n,indexWithinInsertBatch:e.indexWithinInsertBatch}).where(a(r.id,e.id)):await this.db.insert(r).values(n),await this.db.delete(h).where(a(h.aiMessageId,n.id)),n.parts.length>0&&await this.db.insert(h).values(n.parts)}get db(){return this.sqliteDB.db}async initialize(){await this.sqliteDB.initialize()}}export{b as AiChatSqliteDBStorage};
|