promptlayer 1.0.61 → 1.1.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.
- package/README.md +9 -0
- package/dist/esm/chunk-SWBNW72U.js +2 -0
- package/dist/esm/chunk-SWBNW72U.js.map +1 -0
- package/dist/esm/index.js +2 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/openai-agents.js +3 -0
- package/dist/esm/openai-agents.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/openai-agents.d.mts +42 -0
- package/dist/openai-agents.d.ts +42 -0
- package/dist/openai-agents.js +3 -0
- package/dist/openai-agents.js.map +1 -0
- package/package.json +23 -2
- package/src/integrations/openai-agents/helpers.test.ts +254 -0
- package/src/integrations/openai-agents/ids.ts +27 -0
- package/src/integrations/openai-agents/index.ts +8 -0
- package/src/integrations/openai-agents/instrumentation.test.ts +46 -0
- package/src/integrations/openai-agents/instrumentation.ts +47 -0
- package/src/integrations/openai-agents/mapping.ts +714 -0
- package/src/integrations/openai-agents/otlp-json.ts +120 -0
- package/src/integrations/openai-agents/processor.test.ts +509 -0
- package/src/integrations/openai-agents/processor.ts +388 -0
- package/src/integrations/openai-agents/time.ts +56 -0
- package/src/integrations/openai-agents/types.ts +49 -0
- package/src/integrations/openai-agents/url.ts +9 -0
- package/src/openai-agents.ts +1 -0
- package/tsup.config.ts +4 -1
- package/vitest.config.ts +3 -0
package/README.md
CHANGED
|
@@ -95,6 +95,15 @@ openai.chat.completions.create({
|
|
|
95
95
|
|
|
96
96
|
After making your first few requests, you should be able to see them in the PromptLayer dashboard!
|
|
97
97
|
|
|
98
|
+
## Optional Extensions
|
|
99
|
+
|
|
100
|
+
OpenAI Agents telemetry support is available as an optional extension of the
|
|
101
|
+
base library.
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
npm install promptlayer @openai/agents
|
|
105
|
+
```
|
|
106
|
+
|
|
98
107
|
## Contributing
|
|
99
108
|
|
|
100
109
|
We welcome contributions to our open source project, including new features, infrastructure improvements, and better documentation. For more information or any questions, contact us at [hello@promptlayer.com](mailto:hello@promptlayer.com).
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var vn=Object.defineProperty,to=Object.defineProperties;var eo=Object.getOwnPropertyDescriptors;var Je=Object.getOwnPropertySymbols;var In=Object.prototype.hasOwnProperty,En=Object.prototype.propertyIsEnumerable;var tn=(t,n)=>(n=Symbol[t])?n:Symbol.for("Symbol."+t);var Pn=(t,n,e)=>n in t?vn(t,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[n]=e,C=(t,n)=>{for(var e in n||(n={}))In.call(n,e)&&Pn(t,e,n[e]);if(Je)for(var e of Je(n))En.call(n,e)&&Pn(t,e,n[e]);return t},X=(t,n)=>to(t,eo(n));var Ve=(t=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(t,{get:(n,e)=>(typeof require!="undefined"?require:n)[e]}):t)(function(t){if(typeof require!="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var Ye=(t,n)=>{var e={};for(var s in t)In.call(t,s)&&n.indexOf(s)<0&&(e[s]=t[s]);if(t!=null&&Je)for(var s of Je(t))n.indexOf(s)<0&&En.call(t,s)&&(e[s]=t[s]);return e};var E=(t,n,e)=>new Promise((s,a)=>{var r=m=>{try{d(e.next(m))}catch(u){a(u)}},p=m=>{try{d(e.throw(m))}catch(u){a(u)}},d=m=>m.done?s(m.value):Promise.resolve(m.value).then(r,p);d((e=e.apply(t,n)).next())}),lt=function(t,n){this[0]=t,this[1]=n},Xe=(t,n,e)=>{var s=(p,d,m,u)=>{try{var _=e[p](d),w=(d=_.value)instanceof lt,x=_.done;Promise.resolve(w?d[0]:d).then(b=>w?s(p==="return"?p:"next",d[1]?{done:b.done,value:b.value}:b,m,u):m({value:b,done:x})).catch(b=>s("throw",b,m,u))}catch(b){u(b)}},a=p=>r[p]=d=>new Promise((m,u)=>s(p,d,m,u)),r={};return e=e.apply(t,n),r[tn("asyncIterator")]=()=>r,a("next"),a("throw"),a("return"),r};var He=(t,n,e)=>(n=t[tn("asyncIterator")])?n.call(t):(t=t[tn("iterator")](),n={},e=(s,a)=>(a=t[s])&&(n[s]=r=>new Promise((p,d,m)=>(r=a.call(t,r),m=r.done,Promise.resolve(r.value).then(u=>p({value:u,done:m}),d)))),e("next"),e("return"),n);var On={png:"image/png",webp:"image/webp",jpeg:"image/jpeg",jpg:"image/jpeg",gif:"image/gif",url:"image/png"},v=(t,n,e,s)=>C({id:t,type:"function",function:{name:n,arguments:typeof e=="string"?e:JSON.stringify(e)}},s?{tool_id:s}:{}),g=s=>{var a=s,{type:t,item_id:n}=a,e=Ye(a,["type","item_id"]);let r=C({type:t},e);return n&&(r.id=n),r},At=(t,n)=>({role:"assistant",input_variables:[],template_format:"f-string",content:t,tool_calls:n}),Tt=(t,n)=>({prompt_template:{messages:[t],type:"chat",input_variables:[]},metadata:n});function Sn(t){var n,e,s,a;return C(C({type:"url_citation",url:(n=t.url)!=null?n:"",title:(e=t.title)!=null?e:"",start_index:(s=t.start_index)!=null?s:0,end_index:(a=t.end_index)!=null?a:0},t.cited_text!=null?{cited_text:t.cited_text}:{}),t.encrypted_index!=null?{encrypted_index:t.encrypted_index}:{})}var Nn=(t,n,e)=>{var p,d,m,u,_,w,x,b,I,A,h,R,f,y,q,$,j,D,B,U,N,K,z,nt,G,tt,et,ct,pt,ut,_t,dt,mt,ft,gt,yt,ht,xt,bt,Rt;let s=[],a=[];if(Array.isArray(t.content)){for(let O of t.content){if(!O||typeof O!="object")continue;let F=O.type;if(F==="text"){let J=(p=O.text)!=null?p:"",ot=(m=(d=O.citations)!=null?d:O.annotations)!=null?m:[],V=[];for(let Y of ot)Y&&typeof Y=="object"&&V.push(Sn(Y));s.push(g(C({type:"text",text:J},V.length>0?{annotations:V}:{})))}else if(F==="thinking")s.push(g({type:"thinking",thinking:(u=O.thinking)!=null?u:"",signature:(_=O.signature)!=null?_:""}));else if(F==="tool_use")a.push(v((w=O.id)!=null?w:"",(x=O.name)!=null?x:"",(b=O.input)!=null?b:{}));else if(F==="server_tool_use")s.push(g({type:"server_tool_use",id:(I=O.id)!=null?I:"",name:(A=O.name)!=null?A:"",input:(h=O.input)!=null?h:{}}));else if(F==="web_search_tool_result"){let J=(R=O.content)!=null?R:[],ot=[];for(let V of J)if(V&&typeof V=="object"&&V.type==="web_search_result"){let Y=V;ot.push({type:"web_search_result",url:Y.url,title:Y.title,encrypted_content:Y.encrypted_content,page_age:Y.page_age})}s.push(g({type:"web_search_tool_result",tool_use_id:(f=O.tool_use_id)!=null?f:"",content:ot}))}else F==="bash_code_execution_tool_result"&&s.push(g({type:"bash_code_execution_tool_result",tool_use_id:(y=O.tool_use_id)!=null?y:"",content:(q=O.content)!=null?q:{}}))}let Q=At(s,a);return Tt(Q,n)}if(t.type==="content_block_start")if((($=t.content_block)==null?void 0:$.type)==="thinking")s.push(g({type:"thinking",thinking:"",signature:""}));else if(((j=t.content_block)==null?void 0:j.type)==="text")s.push(g({type:"text",text:""}));else if(((D=t.content_block)==null?void 0:D.type)==="tool_use")a.push(v((B=t.content_block.id)!=null?B:"",(U=t.content_block.name)!=null?U:"",{}));else if(((N=t.content_block)==null?void 0:N.type)==="server_tool_use")s.push(g({type:"server_tool_use",id:(K=t.content_block.id)!=null?K:"",name:(z=t.content_block.name)!=null?z:"",input:(nt=t.content_block.input)!=null?nt:{}}));else if(((G=t.content_block)==null?void 0:G.type)==="web_search_tool_result"){let Q=(tt=t.content_block.content)!=null?tt:[],O=[];for(let F of Q)if(F&&typeof F=="object"&&F.type==="web_search_result"){let J=F;O.push({type:"web_search_result",url:J.url,title:J.title,encrypted_content:J.encrypted_content,page_age:J.page_age})}s.push(g({type:"web_search_tool_result",tool_use_id:(et=t.content_block.tool_use_id)!=null?et:"",content:O}))}else((ct=t.content_block)==null?void 0:ct.type)==="bash_code_execution_tool_result"&&s.push(g({type:"bash_code_execution_tool_result",tool_use_id:(pt=t.content_block.tool_use_id)!=null?pt:"",content:(ut=t.content_block.content)!=null?ut:{}}));else if(t.type==="content_block_delta"){if(((_t=t.delta)==null?void 0:_t.type)==="thinking_delta")s.push(g({type:"thinking",thinking:(dt=t.delta.thinking)!=null?dt:"",signature:""}));else if(((mt=t.delta)==null?void 0:mt.type)==="text_delta")s.push(g({type:"text",text:(ft=t.delta.text)!=null?ft:""}));else if(((gt=t.delta)==null?void 0:gt.type)==="signature_delta")s.push(g({type:"thinking",thinking:"",signature:(yt=t.delta.signature)!=null?yt:""}));else if(((ht=t.delta)==null?void 0:ht.type)==="input_json_delta")(e==null?void 0:e[t.index])==="server_tool_use"?s.push(g({type:"server_tool_use",id:"",name:"",input:(xt=t.delta.partial_json)!=null?xt:{}})):a.push(v("","",(bt=t.delta.partial_json)!=null?bt:""));else if(((Rt=t.delta)==null?void 0:Rt.type)==="citations_delta"&&t.delta.citation){let Q=t.delta.citation,O=[Sn(Q)];s.push(g({type:"text",text:"",annotations:O}))}}let r=At(s,a);return Tt(r,n)},no=t=>typeof t=="string"&&t.startsWith("image/");function qn(t){var e,s,a,r;let n=t.web;return n&&typeof n=="object"?{uri:(e=n.uri)!=null?e:"",title:(s=n.title)!=null?s:""}:{uri:(a=t.uri)!=null?a:"",title:(r=t.title)!=null?r:""}}function oo(t){if(!t||typeof t!="object")return;let n=t.content,e=n==null?void 0:n.parts;if(!Array.isArray(e))return;let s=[];for(let a of e)a&&typeof a=="object"&&typeof a.text=="string"&&s.push(a.text);return s.length>0?s.join(""):void 0}function so(t){var s,a,r,p;if(!t||typeof t!="object")return[];let n=(s=t.citations)!=null?s:[],e=[];for(let d of n){if(!d||typeof d!="object")continue;let m=(a=d.uri)!=null?a:"";if(!m)continue;let u=(r=d.startIndex)!=null?r:0,_=(p=d.endIndex)!=null?p:0;e.push({type:"url_citation",url:m,title:m,start_index:u,end_index:_})}return e}function ao(t,n){if(!t||typeof t!="object")return[];let e=t.groundingMetadata,s=t.citationMetadata,a=io(e,n),r=so(s);return[...a,...r]}function io(t,n){var d,m,u,_,w,x,b,I,A;let e=t&&typeof t=="object"?(d=t.groundingChunks)!=null?d:[]:[],s=t&&typeof t=="object"?(m=t.groundingSupports)!=null?m:[]:[];function a(h,R,f){let y=h.text;if(y!=null&&y!=="")return y;if(n!=null&&f>R)return n.slice(R,f)||void 0}if(s.length>0&&e.length>0){let h=[],R=new Set;for(let f of s){if(!f||typeof f!="object")continue;let y=(u=f.segment)!=null?u:{},q=(_=f.groundingChunkIndices)!=null?_:[],$=(w=y.startIndex)!=null?w:0,j=(x=y.endIndex)!=null?x:0,D=a(y,$,j);for(let B of q){if(typeof B!="number"||B>=e.length)continue;let U=e[B];if(!U||typeof U!="object")continue;let N=U.maps;if(N&&typeof N=="object"){let G=(b=N.uri)!=null?b:"",tt=(I=N.title)!=null?I:"",et=N.placeId;(G||tt)&&h.push(C(X(C({type:"map_citation",url:G,title:tt||G},et!=null?{place_id:et}:{}),{start_index:$,end_index:j}),D!=null?{cited_text:D}:{}));continue}let K=U.retrievedContext;if(K&&typeof K=="object"){let G=(A=K.title)!=null?A:"";G&&!R.has(G)&&(R.add(G),h.push({type:"file_citation",file_id:G,filename:G,index:B}));continue}let{uri:z,title:nt}=qn(U);z&&h.push(C({type:"url_citation",url:z,title:nt||z,start_index:$,end_index:j},D!=null?{cited_text:D}:{}))}}return h}if(!t||typeof t!="object")return[];let r=[],p=new Set;return e.forEach((h,R)=>{var D,B,U;if(!h||typeof h!="object")return;let f=h,y=f.maps;if(y&&typeof y=="object"){let N=(D=y.uri)!=null?D:"",K=(B=y.title)!=null?B:"",z=y.placeId;(N||K)&&r.push(X(C({type:"map_citation",url:N,title:K||N},z!=null?{place_id:z}:{}),{start_index:0,end_index:0}));return}let q=f.retrievedContext;if(q&&typeof q=="object"){let N=(U=q.title)!=null?U:"";N&&!p.has(N)&&(p.add(N),r.push({type:"file_citation",file_id:N,filename:N,index:R}));return}let{uri:$,title:j}=qn(f);$&&r.push({type:"url_citation",url:$,title:j||$,start_index:0,end_index:0})}),r}var Mn=(t,n)=>{var m,u,_,w,x,b,I,A,h;let e=[],s=[];for(let R of(m=t.candidates)!=null?m:[])if(R.content&&R.content.parts&&Array.isArray(R.content.parts))for(let f of R.content.parts)if(f.text!=null)f.thought===!0?e.push(g({type:"thinking",thinking:f.text,signature:(u=f.thoughtSignature)!=null?u:""})):e.push(g(C({type:"text",text:f.text},f.thoughtSignature?{thought_signature:f.thoughtSignature}:{})));else if(f.functionCall)s.push(v(f.functionCall.id||"",f.functionCall.name||"",f.functionCall.args||{}));else if(f.executableCode){let y=f.executableCode;e.push(g(C({type:"code",code:(_=y.code)!=null?_:""},y.language!=null?{language:y.language}:{})))}else if(f.codeExecutionResult){let y=f.codeExecutionResult;e.push(g({type:"code_execution_result",output:(w=y.output)!=null?w:"",outcome:(x=y.outcome)!=null?x:"OUTCOME_OK"}))}else{let y=f.inlineData;if(y&&f.thought!==!0){let q=(b=y.mimeType)!=null?b:"image/png",$=(I=y.data)!=null?I:"";if(no(q)&&$){let j={};f.thoughtSignature&&(j.thought_signature=f.thoughtSignature),f.aspectRatio!=null&&(j.aspect_ratio=f.aspectRatio),f.imageSize!=null&&(j.image_size=f.imageSize),e.push(g(C({type:"output_media",url:$,mime_type:q,media_type:"image"},Object.keys(j).length?{provider_metadata:j}:{})))}}}let a=(A=t.candidates)==null?void 0:A[0],r=oo(a),p=ao(a,r);if(p.length>0)for(let R=0;R<e.length;R++){let f=e[R];if(f&&typeof f=="object"&&f.type==="text"){let y=(h=f.annotations)!=null?h:[];e[R]=X(C({},f),{annotations:[...y,...p]})}}let d=At(e,s);return Tt(d,n)},en=(t,n)=>{let e=[],s=[];for(let r of t.choices)if(r.delta){r.delta.content&&e.push(g({type:"text",text:r.delta.content}));let p=r.delta.tool_calls||r.delta.toolCalls;if(p&&Array.isArray(p))for(let d of p)d.function&&s.push(v(d.id||"",d.function.name||"",d.function.arguments||""))}let a=At(e,s);return Tt(a,n)},Wn=(t,n)=>{var p,d,m,u,_,w,x,b,I,A,h,R,f,y,q,$,j,D,B,U,N,K,z,nt,G,tt,et,ct,pt,ut,_t,dt,mt,ft,gt,yt,ht,xt,bt,Rt,Q,O,F,J,ot,V,Y,Ct,kt,Pt,It,Et,Ot,St,qt,Nt,Mt,Wt,jt,$t,Lt,Gt,Ut,Ft,Dt,Bt,Kt,zt,Jt,Vt,Yt,Xt,Ht,Zt,Qt,vt,te,ee,ne,oe,se,ae,ie,re,le,ce,pe,ue,_e,de,me,fe,ge,ye,he,xe,be,Re,we,Ae,Te,Ce,ke,Pe,Ie,Ee,Oe,Se,qe,Ne,Me,We,je,$e,Le,Ge,Ue,Fe,De,Be,Ke,ze,T,S,i,l,k,st,rn,ln,cn,pn,un,_n,dn,mn,fn,gn,yn,hn,xn,bn,Rn,wn,An,Tn,Cn,kn;let e=[],s=[],a=t==null?void 0:t.type;if(a==="response.reasoning_summary_text.delta"){let o=(p=t==null?void 0:t.delta)!=null?p:"",P=(d=t==null?void 0:t.item_id)!=null?d:"";o&&e.push(g({type:"thinking",item_id:P,thinking:o,signature:""}))}else if(a==="response.reasoning_summary_text.done"){let o=(m=t==null?void 0:t.text)!=null?m:"",P=(u=t==null?void 0:t.item_id)!=null?u:"";o&&e.push(g({type:"thinking",item_id:P,thinking:o,signature:""}))}else if(a==="response.reasoning_summary_part.added"){let o=(_=t==null?void 0:t.part)!=null?_:{},P=(w=t==null?void 0:t.item_id)!=null?w:"";if((o==null?void 0:o.type)==="summary_text"){let c=(x=o==null?void 0:o.text)!=null?x:"";e.push(g({type:"thinking",item_id:P,thinking:c,signature:""}))}}else if(a==="response.reasoning_summary_part.done"){let o=(b=t==null?void 0:t.part)!=null?b:{},P=(I=t==null?void 0:t.item_id)!=null?I:"";if((o==null?void 0:o.type)==="summary_text"){let c=(A=o==null?void 0:o.text)!=null?A:"";c&&e.push(g({type:"thinking",item_id:P,thinking:c,signature:""}))}}else if(a==="response.function_call_arguments.delta"){let o=(h=t==null?void 0:t.item_id)!=null?h:"",P=(R=t==null?void 0:t.delta)!=null?R:"";P&&s.push(v("","",P,o))}else if(a==="response.function_call_arguments.done"){let o=(f=t==null?void 0:t.item_id)!=null?f:"",P=(y=t==null?void 0:t.arguments)!=null?y:"";P&&s.push(v("","",P,o))}else if(a==="response.output_item.added"){let o=(q=t==null?void 0:t.item)!=null?q:{},P=o==null?void 0:o.type,c=($=o==null?void 0:o.id)!=null?$:"";P==="reasoning"?e.push(g({type:"thinking",thinking:"",signature:"",item_id:c})):P==="function_call"?s.push(v((o==null?void 0:o.call_id)||"",(o==null?void 0:o.name)||"","",c)):P==="message"?e.push(g({type:"text",item_id:c,text:""})):P==="code_interpreter_call"?e.push(g({type:"code",item_id:c,code:(j=o==null?void 0:o.code)!=null?j:"",container_id:(D=o==null?void 0:o.container_id)!=null?D:""})):P==="image_generation_call"?e.push(g({type:"output_media",item_id:c,url:"",mime_type:"image/png",media_type:"image"})):P==="mcp_list_tools"?e.push(g({type:"mcp_list_tools",item_id:c,server_label:(B=o==null?void 0:o.server_label)!=null?B:"",tools:(U=o==null?void 0:o.tools)!=null?U:[]})):P==="mcp_call"?e.push(g({type:"mcp_call",item_id:c,name:(N=o==null?void 0:o.name)!=null?N:"",server_label:(K=o==null?void 0:o.server_label)!=null?K:"",arguments:(z=o==null?void 0:o.arguments)!=null?z:"",output:o==null?void 0:o.output,error:o==null?void 0:o.error,approval_request_id:o==null?void 0:o.approval_request_id})):P==="mcp_approval_request"?e.push(g({type:"mcp_approval_request",item_id:c,name:(nt=o==null?void 0:o.name)!=null?nt:"",arguments:(G=o==null?void 0:o.arguments)!=null?G:"",server_label:(tt=o==null?void 0:o.server_label)!=null?tt:""})):P==="shell_call"?e.push(g({type:"shell_call",item_id:c,call_id:(et=o==null?void 0:o.call_id)!=null?et:"",action:(ct=o==null?void 0:o.action)!=null?ct:{},status:(pt=o==null?void 0:o.status)!=null?pt:"in_progress"})):P==="shell_call_output"?e.push(g({type:"shell_call_output",item_id:c,call_id:(ut=o==null?void 0:o.call_id)!=null?ut:"",output:(_t=o==null?void 0:o.output)!=null?_t:[],status:(dt=o==null?void 0:o.status)!=null?dt:"in_progress"})):P==="apply_patch_call"?e.push(g({type:"apply_patch_call",item_id:c,call_id:(mt=o==null?void 0:o.call_id)!=null?mt:"",operation:(ft=o==null?void 0:o.operation)!=null?ft:{},status:(gt=o==null?void 0:o.status)!=null?gt:"in_progress"})):P==="apply_patch_call_output"&&e.push(g({type:"apply_patch_call_output",item_id:c,call_id:(yt=o==null?void 0:o.call_id)!=null?yt:"",output:(ht=o==null?void 0:o.output)!=null?ht:"",status:(xt=o==null?void 0:o.status)!=null?xt:"in_progress"}))}else if(a==="response.content_part.added"){let o=(bt=t==null?void 0:t.part)!=null?bt:{},P=(Rt=o==null?void 0:o.type)!=null?Rt:"output_text",c=(Q=t==null?void 0:t.item_id)!=null?Q:"";P==="output_text"&&e.push(g({type:"text",item_id:c,text:(O=o==null?void 0:o.text)!=null?O:"",annotations:(o==null?void 0:o.annotations)||[]}))}else if(a==="response.content_part.done"){let o=(F=t==null?void 0:t.part)!=null?F:{},P=(J=o==null?void 0:o.type)!=null?J:"output_text",c=(ot=t==null?void 0:t.item_id)!=null?ot:"";P==="output_text"&&e.push(g({type:"text",item_id:c,text:(V=o==null?void 0:o.text)!=null?V:"",annotations:(o==null?void 0:o.annotations)||[]}))}else if(a==="response.output_text.annotation.added"){let o=(t==null?void 0:t.annotation)||{},P=o==null?void 0:o.type,c=null;P==="url_citation"?c={type:"url_citation",title:(Y=o==null?void 0:o.title)!=null?Y:"",url:(Ct=o==null?void 0:o.url)!=null?Ct:"",start_index:(kt=o==null?void 0:o.start_index)!=null?kt:0,end_index:(Pt=o==null?void 0:o.end_index)!=null?Pt:0}:P==="file_citation"?c={type:"file_citation",index:(It=o==null?void 0:o.index)!=null?It:0,file_id:(Et=o==null?void 0:o.file_id)!=null?Et:"",filename:(Ot=o==null?void 0:o.filename)!=null?Ot:""}:c=o,e.push(g({type:"text",item_id:(St=t==null?void 0:t.item_id)!=null?St:"",text:"",annotations:[c]}))}else if(a==="response.code_interpreter_call.in_progress")e.push(g({type:"code",item_id:(qt=t==null?void 0:t.item_id)!=null?qt:"",code:(Nt=t==null?void 0:t.code)!=null?Nt:"",container_id:(Mt=t==null?void 0:t.container_id)!=null?Mt:""}));else if(a==="response.code_interpreter_call_code.delta")e.push(g({type:"code",item_id:(Wt=t==null?void 0:t.item_id)!=null?Wt:"",code:(jt=t==null?void 0:t.delta)!=null?jt:"",container_id:($t=t==null?void 0:t.container_id)!=null?$t:""}));else if(a==="response.output_text.delta"){let o=(Lt=t==null?void 0:t.delta)!=null?Lt:"";o&&e.push(g({type:"text",item_id:(Gt=t==null?void 0:t.item_id)!=null?Gt:"",text:o}))}else if(a==="response.output_text.done")e.push(g({type:"text",item_id:(Ut=t==null?void 0:t.item_id)!=null?Ut:"",text:(Ft=t==null?void 0:t.text)!=null?Ft:""}));else if(a==="response.output_item.done"){let o=(Dt=t==null?void 0:t.item)!=null?Dt:{},P=o==null?void 0:o.type,c=(Bt=o==null?void 0:o.id)!=null?Bt:"";if(P==="reasoning"){let M=((Kt=o==null?void 0:o.summary)!=null?Kt:[]).map(at=>{var L;return(L=at==null?void 0:at.text)!=null?L:""}).join("");e.push(g({type:"thinking",item_id:c,thinking:M,signature:""}))}else if(P==="function_call")s.push(v((o==null?void 0:o.call_id)||"",(o==null?void 0:o.name)||"",(o==null?void 0:o.arguments)||"",c));else if(P==="message"){let W=(zt=o==null?void 0:o.content)!=null?zt:[];for(let M of W)(M==null?void 0:M.type)==="output_text"&&e.push(g({type:"text",item_id:c,text:(Jt=M==null?void 0:M.text)!=null?Jt:""}))}else if(P==="code_interpreter_call")e.push(g({type:"code",item_id:c,code:(Vt=o==null?void 0:o.code)!=null?Vt:"",container_id:(Yt=o==null?void 0:o.container_id)!=null?Yt:""}));else if(P==="image_generation_call"){let W=(Xt=o==null?void 0:o.result)!=null?Xt:"",at=((Ht=o==null?void 0:o.output_format)!=null?Ht:"png")==="webp"?"image/webp":"image/png",L={};for(let rt of["revised_prompt","background","size","quality","output_format"])(o==null?void 0:o[rt])!=null&&(L[rt]=o[rt]);e.push(g(C({type:"output_media",item_id:c,url:W,mime_type:at,media_type:"image"},Object.keys(L).length?{provider_metadata:L}:{})))}else P==="mcp_list_tools"?e.push(g({type:"mcp_list_tools",item_id:c,server_label:(Zt=o==null?void 0:o.server_label)!=null?Zt:"",tools:(Qt=o==null?void 0:o.tools)!=null?Qt:[],error:o==null?void 0:o.error})):P==="mcp_call"?e.push(g({type:"mcp_call",item_id:c,name:(vt=o==null?void 0:o.name)!=null?vt:"",server_label:(te=o==null?void 0:o.server_label)!=null?te:"",arguments:(ee=o==null?void 0:o.arguments)!=null?ee:"",output:o==null?void 0:o.output,error:o==null?void 0:o.error,approval_request_id:o==null?void 0:o.approval_request_id})):P==="mcp_approval_request"?e.push(g({type:"mcp_approval_request",item_id:c,name:(ne=o==null?void 0:o.name)!=null?ne:"",arguments:(oe=o==null?void 0:o.arguments)!=null?oe:"",server_label:(se=o==null?void 0:o.server_label)!=null?se:""})):P==="shell_call"?e.push(g({type:"shell_call",item_id:c,call_id:(ae=o==null?void 0:o.call_id)!=null?ae:"",action:(ie=o==null?void 0:o.action)!=null?ie:{},status:(re=o==null?void 0:o.status)!=null?re:"completed"})):P==="shell_call_output"?e.push(g({type:"shell_call_output",item_id:c,call_id:(le=o==null?void 0:o.call_id)!=null?le:"",output:(ce=o==null?void 0:o.output)!=null?ce:[],status:(pe=o==null?void 0:o.status)!=null?pe:"completed"})):P==="apply_patch_call"?e.push(g({type:"apply_patch_call",item_id:c,call_id:(ue=o==null?void 0:o.call_id)!=null?ue:"",operation:(_e=o==null?void 0:o.operation)!=null?_e:{},status:(de=o==null?void 0:o.status)!=null?de:"completed"})):P==="apply_patch_call_output"&&e.push(g({type:"apply_patch_call_output",item_id:c,call_id:(me=o==null?void 0:o.call_id)!=null?me:"",output:(fe=o==null?void 0:o.output)!=null?fe:"",status:(ge=o==null?void 0:o.status)!=null?ge:"completed"}))}else if(a==="response.code_interpreter_call_code.done")e.push(g({type:"code",item_id:(ye=t==null?void 0:t.item_id)!=null?ye:"",code:(he=t==null?void 0:t.code)!=null?he:"",container_id:(xe=t==null?void 0:t.container_id)!=null?xe:""}));else if(a==="response.code_interpreter_call.interpreting")e.push(g({type:"code",item_id:(be=t==null?void 0:t.item_id)!=null?be:"",code:(Re=t==null?void 0:t.code)!=null?Re:"",container_id:(we=t==null?void 0:t.container_id)!=null?we:""}));else if(a==="response.code_interpreter_call.completed")e.push(g({type:"code",item_id:(Ae=t==null?void 0:t.item_id)!=null?Ae:"",code:(Te=t==null?void 0:t.code)!=null?Te:"",container_id:(Ce=t==null?void 0:t.container_id)!=null?Ce:""}));else if(a==="response.image_generation_call.in_progress")e.push(g({type:"output_media",item_id:(ke=t==null?void 0:t.item_id)!=null?ke:"",url:"",mime_type:"image/png",media_type:"image"}));else if(a==="response.image_generation_call.generating")e.push(g({type:"output_media",item_id:(Pe=t==null?void 0:t.item_id)!=null?Pe:"",url:"",mime_type:"image/png",media_type:"image"}));else if(a==="response.image_generation_call.partial_image"){let P=((Ie=t==null?void 0:t.output_format)!=null?Ie:"png")==="webp"?"image/webp":"image/png",c={};for(let W of["background","size","quality","output_format"])(t==null?void 0:t[W])!=null&&(c[W]=t[W]);e.push(g(C({type:"output_media",item_id:(Ee=t==null?void 0:t.item_id)!=null?Ee:"",url:(Oe=t==null?void 0:t.partial_image_b64)!=null?Oe:"",mime_type:P,media_type:"image"},Object.keys(c).length?{provider_metadata:c}:{})))}else if(a==="response.shell_call_command.added")e.push(g({type:"shell_call",action:{command:(Se=t==null?void 0:t.command)!=null?Se:""}}));else if(a==="response.shell_call_command.delta")e.push(g({type:"shell_call",action:{command:(qe=t==null?void 0:t.delta)!=null?qe:""}}));else if(a==="response.shell_call_command.done")e.push(g({type:"shell_call",action:{command:(Ne=t==null?void 0:t.command)!=null?Ne:""}}));else if(a==="response.shell_call_output_content.delta")e.push(g({type:"shell_call_output",item_id:(Me=t==null?void 0:t.item_id)!=null?Me:"",output:[(We=t==null?void 0:t.delta)!=null?We:{}]}));else if(a==="response.shell_call_output_content.done")e.push(g({type:"shell_call_output",item_id:(je=t==null?void 0:t.item_id)!=null?je:"",output:($e=t==null?void 0:t.output)!=null?$e:[]}));else if(a==="response.apply_patch_call_operation_diff.delta")e.push(g({type:"apply_patch_call",item_id:(Le=t==null?void 0:t.item_id)!=null?Le:"",operation:{diff:(Ge=t==null?void 0:t.delta)!=null?Ge:""}}));else if(a==="response.apply_patch_call_operation_diff.done")e.push(g({type:"apply_patch_call",item_id:(Ue=t==null?void 0:t.item_id)!=null?Ue:"",operation:{diff:(Fe=t==null?void 0:t.diff)!=null?Fe:""}}));else if(a==="response.completed"){let o=(De=t==null?void 0:t.response)!=null?De:{},P=(Be=o==null?void 0:o.output)!=null?Be:[];for(let c of P){let W=c==null?void 0:c.type,M=(Ke=c==null?void 0:c.id)!=null?Ke:"";if(W==="reasoning"){let L=((ze=c==null?void 0:c.summary)!=null?ze:[]).map(rt=>{var wt;return(wt=rt==null?void 0:rt.text)!=null?wt:""}).join("");e.push(g({type:"thinking",item_id:M,thinking:L,signature:""}))}else if(W==="function_call")s.push(v((c==null?void 0:c.call_id)||"",(c==null?void 0:c.name)||"",(c==null?void 0:c.arguments)||"",M));else if(W==="message"){let at=(T=c==null?void 0:c.content)!=null?T:[];for(let L of at)(L==null?void 0:L.type)==="output_text"&&e.push(g({type:"text",item_id:M,text:(S=L==null?void 0:L.text)!=null?S:"",annotations:(L==null?void 0:L.annotations)||[]}))}else if(W==="code_interpreter_call")e.push(g({type:"code",item_id:M,code:(i=c==null?void 0:c.code)!=null?i:"",container_id:(l=c==null?void 0:c.container_id)!=null?l:""}));else if(W==="image_generation_call"){let at=(k=c==null?void 0:c.result)!=null?k:"",rt=((st=c==null?void 0:c.output_format)!=null?st:"png")==="webp"?"image/webp":"image/png",wt={};for(let ve of["revised_prompt","background","size","quality","output_format"])(c==null?void 0:c[ve])!=null&&(wt[ve]=c[ve]);e.push(g(C({type:"output_media",item_id:M,url:at,mime_type:rt,media_type:"image"},Object.keys(wt).length?{provider_metadata:wt}:{})))}else W==="mcp_list_tools"?e.push(g({type:"mcp_list_tools",item_id:M,server_label:(rn=c==null?void 0:c.server_label)!=null?rn:"",tools:(ln=c==null?void 0:c.tools)!=null?ln:[],error:c==null?void 0:c.error})):W==="mcp_call"?e.push(g({type:"mcp_call",item_id:M,name:(cn=c==null?void 0:c.name)!=null?cn:"",server_label:(pn=c==null?void 0:c.server_label)!=null?pn:"",arguments:(un=c==null?void 0:c.arguments)!=null?un:"",output:c==null?void 0:c.output,error:c==null?void 0:c.error,approval_request_id:c==null?void 0:c.approval_request_id})):W==="mcp_approval_request"?e.push(g({type:"mcp_approval_request",item_id:M,name:(_n=c==null?void 0:c.name)!=null?_n:"",arguments:(dn=c==null?void 0:c.arguments)!=null?dn:"",server_label:(mn=c==null?void 0:c.server_label)!=null?mn:""})):W==="shell_call"?e.push(g({type:"shell_call",item_id:M,call_id:(fn=c==null?void 0:c.call_id)!=null?fn:"",action:(gn=c==null?void 0:c.action)!=null?gn:{},status:(yn=c==null?void 0:c.status)!=null?yn:"completed"})):W==="shell_call_output"?e.push(g({type:"shell_call_output",item_id:M,call_id:(hn=c==null?void 0:c.call_id)!=null?hn:"",output:(xn=c==null?void 0:c.output)!=null?xn:[],status:(bn=c==null?void 0:c.status)!=null?bn:"completed"})):W==="apply_patch_call"?e.push(g({type:"apply_patch_call",item_id:M,call_id:(Rn=c==null?void 0:c.call_id)!=null?Rn:"",operation:(wn=c==null?void 0:c.operation)!=null?wn:{},status:(An=c==null?void 0:c.status)!=null?An:"completed"})):W==="apply_patch_call_output"&&e.push(g({type:"apply_patch_call_output",item_id:M,call_id:(Tn=c==null?void 0:c.call_id)!=null?Tn:"",output:(Cn=c==null?void 0:c.output)!=null?Cn:"",status:(kn=c==null?void 0:c.status)!=null?kn:"completed"}))}}let r=At(e,s||[]);return Tt(r,n)},jn=(t,n)=>{var r,p,d,m;let e=[],s=[];if("contentBlockDelta"in t){let u=((r=t.contentBlockDelta)==null?void 0:r.delta)||{};if("reasoningContent"in u){let _=((p=u.reasoningContent)==null?void 0:p.text)||"",w=((d=u.reasoningContent)==null?void 0:d.signature)||"";e.push(g({type:"thinking",thinking:_,signature:w}))}else if("text"in u)e.push(g({type:"text",text:u.text||""}));else if("toolUse"in u){let _=u.toolUse||{};s.push(v(_.toolUseId||"",_.name||"",_.input||""))}}else if("contentBlockStart"in t){let u=((m=t.contentBlockStart)==null?void 0:m.start)||{};if("toolUse"in u){let _=u.toolUse||{};s.push(v(_.toolUseId||"",_.name||"",""))}}let a=At(e,s);return Tt(a,n)},ro=["size","quality","background","output_format"],$n=(t,n)=>{var r,p,d,m,u,_,w;let e=[],s=(r=t==null?void 0:t.type)!=null?r:"";if(s==="image_generation.partial_image"){let x=(p=t==null?void 0:t.b64_json)!=null?p:"";if(x){let b=(d=t==null?void 0:t.output_format)!=null?d:"png",I=(m=On[b])!=null?m:"image/png",A={},h=t==null?void 0:t.partial_image_index;h!=null&&(A.partial_image_index=h),e.push(g(C({type:"output_media",url:x,mime_type:I,media_type:"image"},Object.keys(A).length?{provider_metadata:A}:{})))}}else if(s==="image_generation.completed"){let x=(u=t==null?void 0:t.b64_json)!=null?u:"",b=(_=t==null?void 0:t.output_format)!=null?_:"png",I=(w=On[b])!=null?w:"image/png",A={};for(let h of ro)(t==null?void 0:t[h])!=null&&(A[h]=t[h]);e.push(g(C({type:"output_media",url:x,mime_type:I,media_type:"image"},Object.keys(A).length?{provider_metadata:A}:{})))}return{prompt_template:{type:"completion",content:e,input_variables:[]},metadata:n}};var Dn=["openai","openai.azure"],Ze=t=>{var a,r,p,d,m,u,_,w,x,b,I,A,h,R,f,y,q,$,j,D,B,U,N,K,z,nt,G,tt,et,ct,pt,ut,_t,dt,mt,ft,gt,yt,ht,xt,bt,Rt,Q,O,F,J,ot,V,Y,Ct,kt,Pt,It,Et,Ot,St,qt,Nt,Mt,Wt,jt,$t,Lt,Gt,Ut,Ft,Dt,Bt,Kt,zt,Jt,Vt,Yt,Xt,Ht,Zt,Qt,vt,te,ee,ne,oe,se,ae,ie,re,le,ce,pe,ue,_e,de,me,fe,ge,ye,he,xe,be,Re,we,Ae,Te,Ce,ke,Pe,Ie,Ee,Oe,Se,qe,Ne,Me,We,je,$e,Le,Ge,Ue,Fe,De,Be,Ke,ze;let n={id:null,object:"response",created_at:null,status:null,error:null,incomplete_details:null,instructions:null,max_output_tokens:null,model:null,output:[],parallel_tool_calls:!0,previous_response_id:null,reasoning:{},store:!0,temperature:1,text:void 0,tool_choice:"auto",tools:[],top_p:1,truncation:"disabled",usage:null,user:null,metadata:{}},e={},s={};for(let T of t){let S=T==null?void 0:T.type;if(S==="response.created"){let i=T.response||{};n.id=(a=i.id)!=null?a:n.id,n.created_at=(r=i.created_at)!=null?r:n.created_at,n.model=(p=i.model)!=null?p:n.model,n.status=(d=i.status)!=null?d:n.status,n.parallel_tool_calls=(m=i.parallel_tool_calls)!=null?m:n.parallel_tool_calls,n.temperature=(u=i.temperature)!=null?u:n.temperature,n.tool_choice=(_=i.tool_choice)!=null?_:n.tool_choice,n.tools=(w=i.tools)!=null?w:n.tools,n.top_p=(x=i.top_p)!=null?x:n.top_p,n.truncation=(b=i.truncation)!=null?b:n.truncation,n.max_output_tokens=(I=i.max_output_tokens)!=null?I:n.max_output_tokens,n.previous_response_id=(A=i.previous_response_id)!=null?A:n.previous_response_id,n.store=(h=i.store)!=null?h:n.store,n.user=(R=i.user)!=null?R:n.user,n.metadata=(f=i.metadata)!=null?f:n.metadata;let l=i.text;l&&(n.text=l);let k=i.reasoning;k&&(n.reasoning=k);continue}if(S==="response.in_progress"){let i=T.response||{};n.status=(y=i.status)!=null?y:n.status;continue}if(S==="response.output_item.added"){let i=T.item||{},l=i.id,k=i.type,st=T.output_index;st!=null&&l&&(s[st]=l),k==="reasoning"?e[l]={type:"reasoning",id:l,summary:[],status:(q=i.status)!=null?q:"in_progress"}:k==="function_call"?e[l]={type:"function_call",id:l,call_id:i.call_id,name:i.name,arguments:"",status:($=i.status)!=null?$:"in_progress"}:k==="message"?e[l]={type:"message",id:l,role:(j=i.role)!=null?j:"assistant",content:[],status:(D=i.status)!=null?D:"in_progress"}:k==="code_interpreter_call"?e[l]={type:"code_interpreter_call",id:l,container_id:i.container_id,code:(B=i.code)!=null?B:"",status:(U=i.status)!=null?U:"in_progress"}:k==="image_generation_call"?e[l]={type:"image_generation_call",id:l,status:(N=i.status)!=null?N:"in_progress",revised_prompt:(K=i.revised_prompt)!=null?K:"",result:(z=i.result)!=null?z:"",background:i.background,size:i.size,quality:i.quality,output_format:i.output_format}:k==="web_search_call"?e[l]={type:"web_search_call",id:l,status:(nt=i.status)!=null?nt:"in_progress"}:k==="file_search_call"?e[l]={type:"file_search_call",id:l,status:(G=i.status)!=null?G:"in_progress"}:k==="mcp_list_tools"?e[l]={type:"mcp_list_tools",id:l,server_label:(tt=i.server_label)!=null?tt:"",tools:(et=i.tools)!=null?et:[],error:(ct=i.error)!=null?ct:null}:k==="mcp_call"?e[l]={type:"mcp_call",id:l,name:(pt=i.name)!=null?pt:"",server_label:(ut=i.server_label)!=null?ut:"",arguments:(_t=i.arguments)!=null?_t:"",output:(dt=i.output)!=null?dt:null,error:(mt=i.error)!=null?mt:null,approval_request_id:(ft=i.approval_request_id)!=null?ft:null,status:(gt=i.status)!=null?gt:"in_progress"}:k==="mcp_approval_request"?e[l]={type:"mcp_approval_request",id:l,name:(yt=i.name)!=null?yt:"",arguments:(ht=i.arguments)!=null?ht:"",server_label:(xt=i.server_label)!=null?xt:""}:k==="shell_call"?e[l]={type:"shell_call",id:l,call_id:(bt=i.call_id)!=null?bt:"",action:(Rt=i.action)!=null?Rt:{},status:(Q=i.status)!=null?Q:"in_progress"}:k==="shell_call_output"?e[l]={type:"shell_call_output",id:l,call_id:(O=i.call_id)!=null?O:"",output:(F=i.output)!=null?F:[],status:(J=i.status)!=null?J:"in_progress"}:k==="apply_patch_call"?e[l]={type:"apply_patch_call",id:l,call_id:(ot=i.call_id)!=null?ot:"",operation:(V=i.operation)!=null?V:{},status:(Y=i.status)!=null?Y:"in_progress"}:k==="apply_patch_call_output"&&(e[l]={type:"apply_patch_call_output",id:l,call_id:(Ct=i.call_id)!=null?Ct:"",output:(kt=i.output)!=null?kt:"",status:(Pt=i.status)!=null?Pt:"in_progress"});continue}if(S==="response.reasoning_summary_part.added"){let i=T.item_id,l=T.part||{};if(i in e&&e[i].type==="reasoning"){let k={type:(It=l.type)!=null?It:"summary_text",text:(Et=l.text)!=null?Et:""};e[i].summary.push(k)}continue}if(S==="response.reasoning_summary_text.delta"){let i=T.item_id,l=(Ot=T.delta)!=null?Ot:"",k=(St=T.summary_index)!=null?St:0;if(i in e&&e[i].type==="reasoning"){for(;e[i].summary.length<=k;)e[i].summary.push({type:"summary_text",text:""});e[i].summary[k].text+=l}continue}if(S==="response.reasoning_summary_text.done"){let i=T.item_id,l=(qt=T.text)!=null?qt:"",k=(Nt=T.summary_index)!=null?Nt:0;if(i in e&&e[i].type==="reasoning"){for(;e[i].summary.length<=k;)e[i].summary.push({type:"summary_text",text:""});e[i].summary[k].text=l}continue}if(S==="response.reasoning_summary_part.done"){let i=T.item_id,l=T.part||{};if(i in e&&e[i].type==="reasoning"){let k=(Mt=T.summary_index)!=null?Mt:0;k<e[i].summary.length&&(e[i].summary[k]={type:(Wt=l.type)!=null?Wt:"summary_text",text:(jt=l.text)!=null?jt:""})}continue}if(S==="response.function_call_arguments.delta"){let i=T.item_id,l=($t=T.delta)!=null?$t:"";i in e&&(e[i].arguments=`${e[i].arguments||""}${l}`);continue}if(S==="response.function_call_arguments.done"){let i=T.item_id,l=(Lt=T.arguments)!=null?Lt:"";i in e&&(e[i].arguments=l);continue}if(S==="response.content_part.added"){let i=T.part||{},l=Object.values(e).find(k=>k.type==="message");if(l){let k={type:(Gt=i.type)!=null?Gt:"output_text",text:(Ut=i.text)!=null?Ut:"",annotations:(Ft=i.annotations)!=null?Ft:[]};l.content.push(k)}continue}if(S==="response.output_text.delta"){let i=(Dt=T.delta)!=null?Dt:"";for(let l of Object.values(e))if(l.type==="message"&&l.content&&l.content.length){let k=l.content[l.content.length-1];k&&k.type==="output_text"&&(k.text=`${k.text||""}${i}`);break}continue}if(S==="response.output_text.done"){let i=(Bt=T.text)!=null?Bt:"";for(let l of Object.values(e))if(l.type==="message"&&l.content&&l.content.length){let k=l.content[l.content.length-1];k&&k.type==="output_text"&&(k.text=i);break}continue}if(S==="response.output_item.done"){let i=T.item||{},l=i.id;l in e&&(e[l].status=(Kt=i.status)!=null?Kt:"completed",i.type==="reasoning"?e[l].summary=(zt=i.summary)!=null?zt:e[l].summary:i.type==="function_call"?(e[l].arguments=(Jt=i.arguments)!=null?Jt:e[l].arguments,e[l].call_id=(Vt=i.call_id)!=null?Vt:e[l].call_id,e[l].name=(Yt=i.name)!=null?Yt:e[l].name):i.type==="message"?(e[l].content=(Xt=i.content)!=null?Xt:e[l].content,e[l].role=(Ht=i.role)!=null?Ht:e[l].role):i.type==="image_generation_call"?(e[l].result=(Zt=i.result)!=null?Zt:e[l].result,e[l].revised_prompt=(Qt=i.revised_prompt)!=null?Qt:e[l].revised_prompt,e[l].background=(vt=i.background)!=null?vt:e[l].background,e[l].size=(te=i.size)!=null?te:e[l].size,e[l].quality=(ee=i.quality)!=null?ee:e[l].quality,e[l].output_format=(ne=i.output_format)!=null?ne:e[l].output_format):i.type==="code_interpreter_call"?(e[l].code=(oe=i.code)!=null?oe:e[l].code,e[l].container_id=(se=i.container_id)!=null?se:e[l].container_id):i.type==="mcp_list_tools"?(e[l].tools=(ae=i.tools)!=null?ae:e[l].tools,e[l].error=(ie=i.error)!=null?ie:e[l].error):i.type==="mcp_call"?(e[l].name=(re=i.name)!=null?re:e[l].name,e[l].arguments=(le=i.arguments)!=null?le:e[l].arguments,e[l].output=(ce=i.output)!=null?ce:e[l].output,e[l].error=(pe=i.error)!=null?pe:e[l].error,e[l].server_label=(ue=i.server_label)!=null?ue:e[l].server_label):i.type==="mcp_approval_request"?(e[l].name=(_e=i.name)!=null?_e:e[l].name,e[l].arguments=(de=i.arguments)!=null?de:e[l].arguments,e[l].server_label=(me=i.server_label)!=null?me:e[l].server_label):i.type==="shell_call"?(e[l].action=(fe=i.action)!=null?fe:e[l].action,e[l].call_id=(ge=i.call_id)!=null?ge:e[l].call_id):i.type==="shell_call_output"?(e[l].output=(ye=i.output)!=null?ye:e[l].output,e[l].call_id=(he=i.call_id)!=null?he:e[l].call_id):i.type==="apply_patch_call"?(e[l].operation=(xe=i.operation)!=null?xe:e[l].operation,e[l].call_id=(be=i.call_id)!=null?be:e[l].call_id):i.type==="apply_patch_call_output"?(e[l].output=(Re=i.output)!=null?Re:e[l].output,e[l].call_id=(we=i.call_id)!=null?we:e[l].call_id):(i.type==="web_search_call"||i.type==="file_search_call")&&(e[l].action=i.action),n.output.push(e[l]));continue}if(S==="response.image_generation_call.in_progress"){let i=T.item_id;i in e&&(e[i].status="in_progress");continue}if(S==="response.image_generation_call.generating"){let i=T.item_id;i in e&&(e[i].status="generating");continue}if(S==="response.image_generation_call.partial_image"){let i=T.item_id;i in e&&(e[i].result=(Ae=T.partial_image_b64)!=null?Ae:e[i].result,e[i].background=(Te=T.background)!=null?Te:e[i].background,e[i].size=(Ce=T.size)!=null?Ce:e[i].size,e[i].quality=(ke=T.quality)!=null?ke:e[i].quality,e[i].output_format=(Pe=T.output_format)!=null?Pe:e[i].output_format);continue}if(S==="response.shell_call_command.added"){let i=s[T.output_index];if(i&&i in e){let l=e[i].action||{commands:[]};l.commands||(l.commands=[]),l.commands[T.command_index]=(Ie=T.command)!=null?Ie:"",e[i].action=l}continue}if(S==="response.shell_call_command.delta"){let i=s[T.output_index];if(i&&i in e){let l=e[i].action||{commands:[]};l.commands||(l.commands=[]);let k=(Ee=T.command_index)!=null?Ee:0;l.commands[k]=((Oe=l.commands[k])!=null?Oe:"")+((Se=T.delta)!=null?Se:""),e[i].action=l}continue}if(S==="response.shell_call_command.done"){let i=s[T.output_index];if(i&&i in e){let l=e[i].action||{commands:[]};l.commands||(l.commands=[]),l.commands[T.command_index]=(qe=T.command)!=null?qe:"",e[i].action=l}continue}if(S==="response.shell_call_output_content.delta"){let i=T.item_id;if(i&&i in e){e[i].output||(e[i].output=[]);let l=(Ne=T.command_index)!=null?Ne:0,k=(Me=e[i].output[l])!=null?Me:{stdout:"",stderr:""},st=(We=T.delta)!=null?We:{};st.stdout&&(k.stdout=((je=k.stdout)!=null?je:"")+st.stdout),st.stderr&&(k.stderr=(($e=k.stderr)!=null?$e:"")+st.stderr),e[i].output[l]=k}continue}if(S==="response.shell_call_output_content.done"){let i=T.item_id;i&&i in e&&(e[i].output=(Le=T.output)!=null?Le:e[i].output);continue}if(S==="response.apply_patch_call_operation_diff.delta"){let i=T.item_id;if(i&&i in e){let l=e[i].operation||{};l.diff=((Ge=l.diff)!=null?Ge:"")+((Ue=T.delta)!=null?Ue:""),e[i].operation=l}continue}if(S==="response.apply_patch_call_operation_diff.done"){let i=T.item_id;if(i&&i in e){let l=e[i].operation||{};l.diff=(Fe=T.diff)!=null?Fe:l.diff,e[i].operation=l}continue}if(S==="response.completed"){let i=T.response||{};n.status=(Be=(De=i.status)!=null?De:n.status)!=null?Be:"completed",n.usage=(Ke=i.usage)!=null?Ke:n.usage,n.output=(ze=i.output)!=null?ze:n.output,i.reasoning&&(n.reasoning=i.reasoning);continue}}return n},nn=t=>{var d,m,u,_,w,x,b,I,A,h;let n=null,e,s={id:"",choices:[],created:Date.now(),model:"",object:"chat.completion"},a=t.at(-1);if(!a)return s;let r;for(let R of t){if(R.choices.length===0)continue;let f=R.choices[0].delta;f.content&&(n=`${n||""}${f.content||""}`),f.function_call&&(e={name:`${e?e.name:""}${f.function_call.name||""}`,arguments:`${e?e.arguments:""}${f.function_call.arguments||""}`});let y=(d=f.tool_calls)==null?void 0:d[0];if(y){r=r||[];let q=r.at(-1);if(!q||y.id){r.push({id:y.id||"",type:y.type||"function",function:{name:((m=y.function)==null?void 0:m.name)||"",arguments:((u=y.function)==null?void 0:u.arguments)||""}});continue}q.function.name=`${q.function.name}${((_=y.function)==null?void 0:_.name)||""}`,q.function.arguments=`${q.function.arguments}${((w=y.function)==null?void 0:w.arguments)||""}`}}let p=t[0].choices.at(0);return s.choices.push({finish_reason:(x=p==null?void 0:p.finish_reason)!=null?x:"stop",index:(b=p==null?void 0:p.index)!=null?b:0,logprobs:(I=p==null?void 0:p.logprobs)!=null?I:null,message:{role:"assistant",content:n,function_call:e||void 0,tool_calls:r||void 0,refusal:(A=p==null?void 0:p.delta.refusal)!=null?A:null}}),s.id=a.id,s.model=a.model,s.created=a.created,s.system_fingerprint=a.system_fingerprint,s.usage=(h=a.usage)!=null?h:void 0,s},Ln=t=>{let n={id:"",choices:[{finish_reason:"stop",index:0,text:"",logprobs:null}],created:Date.now(),model:"",object:"text_completion"},e=t.at(-1);if(!e)return n;let s="";for(let a of t)a.choices.length>0&&a.choices[0].text&&(s=`${s}${a.choices[0].text}`);return n.choices[0].text=s,n.id=e.id,n.created=e.created,n.model=e.model,n.system_fingerprint=e.system_fingerprint,n.usage=e.usage,n},on=t=>{var _,w,x,b,I,A;let n={id:"",model:"",content:[],role:"assistant",type:"message",stop_reason:"stop_sequence",stop_sequence:null,usage:{input_tokens:0,output_tokens:0,cache_creation_input_tokens:0,cache_read_input_tokens:0,server_tool_use:null,service_tier:null}};if(!t.at(-1))return n;let s=null,a=null,r="",p="",d="",m="",u={};for(let h of t)if(h.type==="message_start")n=C({},h.message);else if(h.type==="content_block_start")s=C({},h.content_block),a="index"in h&&typeof h.index=="number"?h.index:null,s.type==="thinking"?(r="",p=""):s.type==="text"?d="":(s.type==="tool_use"||s.type==="server_tool_use")&&(m="");else if(h.type==="content_block_delta"){let R=h.delta,f="index"in h&&typeof h.index=="number"?h.index:null;if((R==null?void 0:R.type)==="citations_delta"){let y=R.citation;if(y&&typeof y=="object"&&y.type==="web_search_result_location"&&f!==null){let q=C(C({type:"url_citation",url:(_=y.url)!=null?_:"",title:(w=y.title)!=null?w:"",start_index:(x=y.start_index)!=null?x:0,end_index:(b=y.end_index)!=null?b:0},y.cited_text!=null?{cited_text:y.cited_text}:{}),y.encrypted_index!=null?{encrypted_index:y.encrypted_index}:{});u[f]||(u[f]=[]),u[f].push(q)}}else s!==null&&(s.type==="thinking"?(R&&"signature"in R&&(r=R.signature||""),R&&"thinking"in R&&(p+=R.thinking||"")):s.type==="text"?R&&"text"in R&&(d+=R.text||""):(s.type==="tool_use"||s.type==="server_tool_use")&&(R==null?void 0:R.type)==="input_json_delta"&&(m+=R.partial_json||""))}else if(h.type==="content_block_stop"&&s!==null){if(s.type==="thinking")s.signature=r,s.thinking=p;else if(s.type==="text")s.text=d,s.citations=null,a!==null&&((I=u[a])!=null&&I.length)&&(s.annotations=u[a]);else if(s.type==="tool_use"||s.type==="server_tool_use")try{s.input=m?JSON.parse(m):{}}catch(R){s.input={}}n.content.push(s),s=null,a=null,r="",p="",d="",m=""}else h.type==="message_delta"&&("usage"in h&&h.usage&&(n.usage=X(C({},n.usage),{output_tokens:(A=h.usage.output_tokens)!=null?A:0})),"delta"in h&&h.delta&&("stop_reason"in h.delta&&h.delta.stop_reason!==void 0&&(n.stop_reason=h.delta.stop_reason),"stop_sequence"in h.delta&&h.delta.stop_sequence!==void 0&&(n.stop_sequence=h.delta.stop_sequence)));return n},Gn=t=>{let n={completion:"",id:"",model:"",stop_reason:"",type:"completion"},e=t.at(-1);if(!e)return n;let s="";for(let a of t)s=`${s}${a.completion}`;return n.completion=s,n.id=e.id,n.model=e.model,n.stop_reason=e.stop_reason,n},lo=t=>{var p,d,m,u,_,w,x,b,I,A;let n=null,e={id:"",choices:[],created:Date.now(),model:"",object:"chat.completion"},s=t.at(-1).data;if(!s)return e;let a;for(let h of t){if(h.data.choices.length===0)continue;let R=h.data.choices[0].delta;R.content&&(n=`${n||""}${R.content||""}`);let f=(p=R.toolCalls)==null?void 0:p[0];if(f){a=a||[];let y=a.at(-1);if(!y||f.id){a.push({id:f.id||"",type:f.type||"function",function:{name:((d=f.function)==null?void 0:d.name)||"",arguments:((m=f.function)==null?void 0:m.arguments)||""}});continue}y.function.name=`${y.function.name}${((u=f.function)==null?void 0:u.name)||""}`,y.function.arguments=`${y.function.arguments}${((_=f.function)==null?void 0:_.arguments)||""}`}}let r=t[0].data.choices.at(0);return e.choices.push({finish_reason:(w=r==null?void 0:r.finish_reason)!=null?w:"stop",index:(x=r==null?void 0:r.index)!=null?x:0,logprobs:(b=r==null?void 0:r.logprobs)!=null?b:null,message:{role:"assistant",content:n,tool_calls:a||void 0,refusal:(I=r==null?void 0:r.delta.refusal)!=null?I:null}}),e.id=s.id,e.model=s.model,e.created=s.created,e.usage=(A=s.usage)!=null?A:void 0,e},Un=t=>{let n={ResponseMetadata:{},output:{message:{}},stopReason:"end_turn",metrics:{},usage:{}},e=[],s=null,a="",r="",p="",d="";for(let m of t)if("contentBlockStart"in m){let u=m.contentBlockStart;if("start"in u&&"toolUse"in u.start){let _=u.start.toolUse;s={toolUse:{toolUseId:_.toolUseId,name:_.name}},a=""}}else if("contentBlockDelta"in m){let u=m.contentBlockDelta.delta;if("text"in u)r+=u.text;else if("reasoningContent"in u){let _=u.reasoningContent;"text"in _?d+=_.text:"signature"in _&&(p+=_.signature)}else if("toolUse"in u&&"input"in u.toolUse){let _=u.toolUse.input;if(a+=_,!_.trim())continue}}else if("contentBlockStop"in m)if(s&&a){try{s.toolUse.input=JSON.parse(a)}catch(u){s.toolUse.input={}}e.push(s),s=null,a=""}else r?(e.push({text:r}),r=""):d&&p&&(e.push({reasoningContent:{reasoningText:{text:d,signature:p}}}),d="",p="");else if("messageStop"in m)n.stopReason=m.messageStop.stopReason;else if("metadata"in m){let u=m.metadata;n.usage=(u==null?void 0:u.usage)||{},n.metrics=(u==null?void 0:u.metrics)||{}}return n.output.message={role:"assistant",content:e},n},co=(t,n,e,s,a,r,p,d,m)=>{var x,b,I;let u=C({},p),_=[];if(t){let A={text:t,thought:!0};d&&(A.thoughtSignature=d),_.push(A)}if(n){let A={text:n,thought:null};m&&(A.thoughtSignature=m),_.push(A)}for(let A of a)_.push({executableCode:A});for(let A of r)_.push({codeExecutionResult:A});for(let A of s)_.push({inlineData:A});for(let A of e)_.push({functionCall:A});_.length>0&&((b=(x=u.candidates)==null?void 0:x[0])!=null&&b.content)&&(u.candidates[0].content.parts=_);let w=(I=p==null?void 0:p.candidates)==null?void 0:I[0];return w&&(u.candidates||(u.candidates=[]),u.candidates[0]||(u.candidates[0]={content:{parts:[]}}),w.groundingMetadata!=null&&(u.candidates[0].groundingMetadata=w.groundingMetadata),w.urlContextMetadata!=null&&(u.candidates[0].urlContextMetadata=w.urlContextMetadata),w.citationMetadata!=null&&(u.candidates[0].citationMetadata=w.citationMetadata)),u},Bn=t=>{var _,w,x,b,I,A,h;let{GenerateContentResponse:n}=Ve("@google/genai");if(!t.length)return new n;let e="",s="",a=[],r=[],p=[],d=[],m=null,u=null;for(let R of t)if(R.candidates&&((w=(_=R.candidates[0])==null?void 0:_.content)!=null&&w.parts))for(let f of R.candidates[0].content.parts)if(f.text!=null)f.thought===!0?(e+=f.text,f.thoughtSignature&&(m=f.thoughtSignature)):(s+=f.text,f.thoughtSignature&&(u=f.thoughtSignature));else if(f.functionCall)a.push(f.functionCall);else if(f.inlineData){let y=f.inlineData;r.push({data:(x=y.data)!=null?x:"",mimeType:(b=y.mimeType)!=null?b:"image/png"})}else f.executableCode?p.push({code:(I=f.executableCode.code)!=null?I:"",language:f.executableCode.language}):f.codeExecutionResult&&d.push({output:(A=f.codeExecutionResult.output)!=null?A:"",outcome:(h=f.codeExecutionResult.outcome)!=null?h:"OUTCOME_OK"});return co(e,s,a,r,p,d,t[t.length-1],m,u)},po=t=>Bn(t),uo=t=>Bn(t),_o=["size","quality","background","output_format"],sn=t=>{var r,p,d,m,u;let n={created:null,data:[],usage:null},e={},s="png";for(let _ of t){let w=(r=_==null?void 0:_.type)!=null?r:"";if(w==="image_generation.partial_image"){let x=_.b64_json;if(x!=null){let b=(p=_.partial_image_index)!=null?p:0;e[b]=x}}else if(w==="image_generation.completed"){let x=_.b64_json;if(x!=null){let b=(d=_.partial_image_index)!=null?d:0;e[b]=x}n.created=(m=_.created_at)!=null?m:n.created,n.usage=(u=_.usage)!=null?u:n.usage;for(let b of _o)_[b]!=null&&(n[b]=_[b]);_.output_format&&(s=_.output_format)}}n.output_format||(n.output_format=s);let a=Object.keys(e).map(Number).sort((_,w)=>_-w);return a.length>0&&(n.data=a.map(_=>({b64_json:e[_]}))),n},Kn=(t,n="openai.chat.completions.create")=>{if(n==="openai.responses.create"||n==="openai.AzureOpenAI.responses.create")return Ze(t);if(n==="openai.images.generate"||n==="openai.AzureOpenAI.images.generate")return sn(t);if("completion"in t[0])return t.reduce((e,s)=>X(C({},s),{completion:`${e.completion}${s.completion}`}),{});if(n==="anthropic.messages.create")return on(t);if("text"in t[0].choices[0]){let e="";for(let a of t)e=`${e}${a.choices[0].text}`;let s=structuredClone(t.at(-1));return s.choices[0].text=e,s}if("delta"in t[0].choices[0]){let e=nn(t);return e.choices[0]=C(C({},e.choices[0]),e.choices[0].message),e}return""},Fn=(t,n,e)=>{let s=n.model.provider,a=n.model.name;if(s==="anthropic"||s==="anthropic.bedrock"||s==="vertexai"&&a.startsWith("claude"))return Nn(t,n,e==null?void 0:e.anthropicBlockTypeByIndex);if(s==="google"||s==="vertexai"&&a.startsWith("gemini"))return Mn(t,n);if(s==="amazon.bedrock")return jn(t,n);if(s==="mistral")return en(t.data,n);if(s==="openai"||s==="openai.azure"){let r=n.model.api_type||"chat-completions";return r==="responses"?Wn(t,n):r==="images"?$n(t,n):en(t,n)}return null};function Wo(t,n,e,s){return Xe(this,null,function*(){var x,b,I;let a={request_id:null,raw_response:null,prompt_blueprint:null},r={},p=s.model.provider;p=="amazon.bedrock"&&(r=t==null?void 0:t.$metadata,t=t==null?void 0:t.stream);let d=[],m=p==="anthropic"||p==="anthropic.bedrock"||p==="vertexai"&&((I=(b=(x=s.model)==null?void 0:x.name)==null?void 0:b.startsWith)==null?void 0:I.call(b,"claude")),u={};try{for(var A=He(t),h,R,f;h=!(R=yield new lt(A.next())).done;h=!1){let y=R.value;d.push(y),m&&(y==null?void 0:y.type)==="content_block_start"&&y.content_block&&(u[y.index]=y.content_block.type),a.raw_response=y,a.prompt_blueprint=Fn(y,s,{anthropicBlockTypeByIndex:u}),yield a}}catch(R){f=[R]}finally{try{h&&(R=A.return)&&(yield new lt(R.call(A)))}finally{if(f)throw f[0]}}let _=e(d);p==="amazon.bedrock"&&(_.ResponseMetadata=r),a.raw_response=_,a.prompt_blueprint=Fn(_,s),yield a;let w=yield new lt(n({request_response:_}));a.request_id=w.request_id,a.prompt_blueprint=w.prompt_blueprint,yield a})}var zn={"openai:chat-completions":{chat:{function_name:"openai.chat.completions.create",stream_function:nn},completion:{function_name:"openai.completions.create",stream_function:Ln}},"openai:responses":{chat:{function_name:"openai.responses.create",stream_function:Ze}},"openai:images":{completion:{function_name:"openai.images.generate",stream_function:sn}},anthropic:{chat:{function_name:"anthropic.messages.create",stream_function:on},completion:{function_name:"anthropic.completions.create",stream_function:Gn}},"openai.azure:chat-completions":{chat:{function_name:"openai.AzureOpenAI.chat.completions.create",stream_function:nn},completion:{function_name:"openai.AzureOpenAI.completions.create",stream_function:Ln}},"openai.azure:responses":{chat:{function_name:"openai.AzureOpenAI.responses.create",stream_function:Ze},completion:{function_name:"openai.AzureOpenAI.responses.create",stream_function:Ze}},"openai.azure:images":{completion:{function_name:"openai.AzureOpenAI.images.generate",stream_function:sn}},google:{chat:{function_name:"google.convo.send_message",stream_function:po},completion:{function_name:"google.model.generate_content",stream_function:uo}},"amazon.bedrock":{chat:{function_name:"boto3.bedrock-runtime.converse",stream_function:Un},completion:{function_name:"boto3.bedrock-runtime.converse",stream_function:Un}},"anthropic.bedrock":{chat:{function_name:"anthropic.messages.create",stream_function:on},completion:{function_name:"anthropic.completions.create",stream_function:Gn}},mistral:{chat:{function_name:"mistral.client.chat",stream_function:lo},completion:{function_name:"",stream_function:null}}};import mo from"ably";import{Centrifuge as fo}from"centrifuge";import go from"p-retry";var Vn="1.1.0",yo=()=>{var t;if(typeof process!="undefined"&&((t=process.versions)!=null&&t.node)){let n=process.versions.node.split(".");return`${n[0]}.${n[1]}`}return"unknown"},ho=yo(),xo=`promptlayer-js/${Vn} (node ${ho})`,Z=()=>({"User-Agent":xo,"X-SDK-Version":Vn}),an="SET_WORKFLOW_COMPLETE";function bo(t,n,e,s){return E(this,null,function*(){let a=yield H(`${t}/workflow-version-execution-results?workflow_version_execution_id=${n}&return_all_outputs=${e}`,C({headers:s},Z()));if(!a.ok)throw new Error("Failed to fetch final output");return a.json()})}function Yn(t,n,e,s,a){return function(r){return E(this,null,function*(){if(r.name===an)try{let p=JSON.parse(r.data),d=p.result_code,m;if(d==="OK"||d==null)m=p.final_output;else if(d==="EXCEEDS_SIZE_LIMIT")m=yield bo(t,e,s,a),n.resolve(m);else throw new Error(`Unsupported final output code: ${d}`);n.resolve(m)}catch(p){n.reject(p)}})}}function Ro(d){return E(this,arguments,function*({token:t,channelName:n,executionId:e,returnAllOutputs:s,headers:a,timeout:r,baseURL:p}){let m=new mo.Realtime(t),u=m.channels.get(n),_={},w=new Promise((b,I)=>{_.resolve=b,_.reject=I}),x=Yn(p,_,e,s,a);yield u.subscribe(an,x);try{return yield new Promise((b,I)=>{let A=setTimeout(()=>{I(new Error("Workflow execution did not complete properly (timeout)"))},r);w.then(h=>{clearTimeout(A),b(h)}).catch(h=>{clearTimeout(A),I(h)})})}finally{console.log("Closing client"),u.unsubscribe(an,x),m.close(),console.log("Closed client")}})}var H=(t,n)=>E(null,null,function*(){return go(()=>E(null,null,function*(){let e=yield fetch(t,n);if(e.status>=500&&e.status<600||e.status===429)throw new Error(`Server error: ${e.status} ${e.statusText}`);return e}),{retries:3,factor:2,minTimeout:2e3,maxTimeout:15e3,randomize:!0,onFailedAttempt:e=>{console.info(`PromptLayer API request attempt ${e.attemptNumber} failed. ${e.retriesLeft} retries left.`)}})}),Do=(t,n,e,s=!0)=>E(null,null,function*(){return e.request_response[Symbol.asyncIterator]!==void 0?Ao(t,n,e.request_response,e,s):yield Xn(t,n,e,s)}),Xn=(t,n,e,s=!0)=>E(null,null,function*(){try{let a=yield H(`${n}/track-request`,{method:"POST",headers:C({"Content-Type":"application/json"},Z()),body:JSON.stringify(e)}),r=yield a.json();if(a.status!==200){let p=r.message||r.error||"Failed to log request";if(s)throw new Error(p);it(r,"WARNING: While logging your request, PromptLayer experienced the following error:")}if(r&&e.return_pl_id)return[e.request_response,r.request_id]}catch(a){if(s)throw a;console.warn(`WARNING: While logging your request PromptLayer had the following error: ${a}`)}return e.request_response}),Bo=(t,n,e,s=!0)=>E(null,null,function*(){try{let a=yield H(`${n}/library-track-metadata`,{method:"POST",headers:C({"Content-Type":"application/json"},Z()),body:JSON.stringify(X(C({},e),{api_key:t}))}),r=yield a.json();if(a.status!==200){let p=r.message||r.error||"Failed to track metadata";if(s)throw new Error(p);return it(r,"WARNING: While logging metadata to your request, PromptLayer experienced the following error"),!1}}catch(a){if(s)throw a;return console.warn(`WARNING: While logging metadata to your request, PromptLayer experienced the following error: ${a}`),!1}return!0}),Ko=(t,n,e,s=!0)=>E(null,null,function*(){try{let a=yield H(`${n}/library-track-score`,{method:"POST",headers:C({"Content-Type":"application/json"},Z()),body:JSON.stringify(X(C({},e),{api_key:t}))}),r=yield a.json();if(a.status!==200){let p=r.message||r.error||"Failed to track score";if(s)throw new Error(p);return it(r,"WARNING: While scoring your request, PromptLayer experienced the following error"),!1}}catch(a){if(s)throw a;return console.warn(`WARNING: While scoring your request, PromptLayer experienced the following error: ${a}`),!1}return!0}),zo=(t,n,e,s=!0)=>E(null,null,function*(){try{let a=yield H(`${n}/library-track-prompt`,{method:"POST",headers:C({"Content-Type":"application/json"},Z()),body:JSON.stringify(X(C({},e),{api_key:t}))}),r=yield a.json();if(a.status!==200){let p=r.message||r.error||"Failed to track prompt";if(s)throw new Error(p);return it(r,"WARNING: While associating your request with a prompt template, PromptLayer experienced the following error"),!1}}catch(a){if(s)throw a;return console.warn(`WARNING: While associating your request with a prompt template, PromptLayer experienced the following error: ${a}`),!1}return!0}),Jo=(t,n,e,s=!0)=>E(null,null,function*(){try{let a=yield H(`${n}/track-group`,{method:"POST",headers:C({"Content-Type":"application/json"},Z()),body:JSON.stringify(X(C({},e),{api_key:t}))}),r=yield a.json();if(a.status!==200){let p=r.message||r.error||"Failed to track group";if(s)throw new Error(p);return it(r,"WARNING: While associating your request with a group, PromptLayer experienced the following error"),!1}}catch(a){if(s)throw a;return console.warn(`WARNING: While associating your request with a group, PromptLayer experienced the following error: ${a}`),!1}return!0}),Vo=(t,n,e=!0)=>E(null,null,function*(){try{let s=yield H(`${n}/create-group`,{method:"POST",headers:C({"Content-Type":"application/json"},Z()),body:JSON.stringify({api_key:t})}),a=yield s.json();if(s.status!==200){let r=a.message||a.error||"Failed to create group";if(e)throw new Error(r);return it(a,"WARNING: While creating a group PromptLayer had the following error"),!1}return a.id}catch(s){if(e)throw s;return console.warn(`WARNING: While creating a group PromptLayer had the following error: ${s}`),!1}}),Yo=(t,n,e,s,a=!0)=>E(null,null,function*(){try{let r=new URL(`${n}/prompt-templates/${e}`),p=yield H(r,{method:"POST",headers:C({"Content-Type":"application/json","X-API-KEY":t},Z()),body:JSON.stringify(s)}),d=yield p.json();if(p.status!==200){let m=d.message||d.error||"Failed to fetch prompt template";if(a)throw new Error(m);return console.warn(`WARNING: While fetching a prompt template PromptLayer had the following error: ${m}`),null}return d.warning&&console.warn(`WARNING: While fetching your prompt PromptLayer had the following error: ${d.warning}`),d}catch(r){if(a)throw r;return console.warn(`WARNING: While fetching a prompt template PromptLayer had the following error: ${r}`),null}}),Xo=(t,n,e,s=!0)=>E(null,null,function*(){let a=yield H(`${n}/rest/prompt-templates`,{method:"POST",headers:C({"Content-Type":"application/json","X-API-KEY":t},Z()),body:JSON.stringify({prompt_template:C({},e),prompt_version:C({},e),release_labels:e.release_labels?e.release_labels:void 0})}),r=yield a.json();if(a.status!==200&&a.status!==201){let p=r.message||r.error||"Failed to publish prompt template";if(s)throw new Error(p);it(r,"WARNING: While publishing a prompt template PromptLayer had the following error")}return r}),Ho=(t,n,e,s=!0)=>E(null,null,function*(){var d;let a=new URL(`${n}/prompt-templates`);Object.entries(e||{}).forEach(([m,u])=>a.searchParams.append(m,u.toString()));let r=yield H(a,{headers:C({"Content-Type":"application/json","X-API-KEY":t},Z())}),p=yield r.json();if(r.status!==200){let m=p.message||p.error||"Failed to fetch prompt templates";if(s)throw new Error(m);return it(p,"WARNING: While fetching all prompt templates PromptLayer had the following error"),[]}return(d=p.items)!=null?d:[]}),wo=t=>E(null,null,function*(){let n=new URL(`${t.baseURL}/connection/websocket`);n.protocol=n.protocol==="https:"?"wss:":"ws:";let e=new fo(n.toString(),{token:t.token}),s=e.newSubscription(t.channelName);return new Promise((a,r)=>{let p=_=>{u(),a(_)},d=Yn(t.baseURL,{resolve:p,reject:r},t.executionId,t.returnAllOutputs,t.headers);s.on("publication",_=>{d({name:_.data.message_name,data:_.data.data})});let m=setTimeout(()=>{r(new Error("Workflow execution did not complete properly (timeout)"))},t.timeout),u=()=>{clearTimeout(m),s.unsubscribe(),e.disconnect()};s.on("error",_=>{u(),r(`Centrifugo subscription error: ${_}`)}),e.on("error",_=>{u(),r(`Centrifugo client error: ${_}`)}),s.subscribe(),e.connect()})}),Zo=u=>E(null,[u],function*({workflow_name:t,input_variables:n,metadata:e={},workflow_label_name:s=null,workflow_version_number:a=null,return_all_outputs:r=!1,api_key:p,timeout:d=36e5,baseURL:m}){let _={input_variables:n,metadata:e,workflow_label_name:s,workflow_version_number:a,return_all_outputs:r},w=C({"Content-Type":"application/json","X-API-KEY":p},Z());try{let x=yield H(`${m}/workflows/${encodeURIComponent(t)}/run`,{method:"POST",headers:w,body:JSON.stringify(_)});if(x.status!==201)return{success:!1,message:`Failed to run workflow: ${(yield x.json().catch(()=>({}))).error||x.statusText}`};let b=yield x.json();b.warning&&console.warn(`WARNING: ${b.warning}`);let I=b.workflow_version_execution_id;if(!I)return console.log("No execution ID returned from workflow run"),{success:!1,message:"Failed to run workflow"};let A=`workflow_updates:${I}`,R=yield(yield H(`${m}/ws-token-request-library?capability=${A}`,{method:"POST",headers:w})).json(),y={token:R.token_details.token,channelName:A,executionId:I,returnAllOutputs:r,headers:w,timeout:d,baseURL:m};return R.messaging_backend==="centrifugo"?wo(y):yield Ro(y)}catch(x){throw console.error(`Failed to run workflow: ${x instanceof Error?x.message:x}`),x}});function Ao(t,n,e,s,a=!0){return Xe(this,null,function*(){let r=[];try{for(var m=He(e),u,_,w;u=!(_=yield new lt(m.next())).done;u=!1){let x=_.value;yield s.return_pl_id?[x,null]:x,r.push(x)}}catch(_){w=[_]}finally{try{u&&(_=m.return)&&(yield new lt(_.call(m)))}finally{if(w)throw w[0]}}let p=Kn(r,s.function_name),d=yield new lt(Xn(t,n,X(C({},s),{request_response:p,request_end_time:new Date().toISOString()}),a));if(d&&s.return_pl_id){let x=d[1];yield[r.at(-1),x]}})}var it=(t,n)=>{try{console.warn(`${n}: ${t.message}`)}catch(e){console.warn(`${n}: ${t}`)}},Qo=(t,n,e=!0)=>E(null,null,function*(){try{let s=yield H(`${t}/track-request`,{method:"POST",headers:C({"Content-Type":"application/json"},Z()),body:JSON.stringify(n)}),a=yield s.json();if(s.status!==200){let r=a.message||a.error||"Failed to track request";if(e)throw new Error(r);it(a,"WARNING: While logging your request, PromptLayer experienced the following error:")}return a}catch(s){if(e)throw s;console.warn(`WARNING: While logging your request PromptLayer had the following error: ${s}`)}return{}}),To=(t,n)=>E(null,null,function*(){return yield t.chat.completions.create(n)}),Co=(t,n)=>E(null,null,function*(){return yield t.completions.create(n)}),Hn={chat:To,completion:Co},vo=(t,n)=>E(null,null,function*(){var r,p;let e=Ve("openai").default,s=new e({baseURL:n.baseURL,apiKey:n.apiKey});n==null||delete n.apiKey,n==null||delete n.baseURL;let a=(p=(r=t.metadata)==null?void 0:r.model)==null?void 0:p.api_type;if(a==="chat-completions"){let d=Hn[t.prompt_template.type];return yield d(s,n)}else return a==="images"?yield s.images.generate(n):yield s.responses.create(n)}),ts=(t,n)=>E(null,null,function*(){var r,p;let{AzureOpenAI:e}=Ve("openai"),s=new e({endpoint:process.env.AZURE_OPENAI_ENDPOINT||n.baseURL,apiVersion:process.env.OPENAI_API_VERSION||n.apiVersion,apiKey:process.env.AZURE_OPENAI_API_KEY||n.apiKey});n==null||delete n.baseURL,n==null||delete n.apiVersion,n==null||delete n.apiKey;let a=(p=(r=t.metadata)==null?void 0:r.model)==null?void 0:p.api_type;if(a==="chat-completions"){let d=Hn[t.prompt_template.type];return yield d(s,n)}else return a==="images"?yield s.images.generate(n):yield s.responses.create(n)}),Zn=(t,n)=>E(null,null,function*(){return t.messages.create(n)}),ko=(t,n)=>E(null,null,function*(){return t.completions.create(n)}),Qn={chat:Zn,completion:ko},es=(t,n)=>E(null,null,function*(){let e=Ve("@anthropic-ai/sdk").default,s=new e({baseURL:n.baseURL,apiKey:n.apiKey}),a=Qn[t.prompt_template.type];return a(s,n)}),ns=(t,n,e,s=!0)=>E(null,null,function*(){try{let a=yield H(`${n}/log-request`,{method:"POST",headers:C({"Content-Type":"application/json","X-API-KEY":t},Z()),body:JSON.stringify(e)}),r=yield a.json();if(a.status!==201){let p=r.message||r.error||"Failed to log request";if(s)throw new Error(p);return it(r,"WARNING: While logging your request PromptLayer had the following error"),null}return r}catch(a){if(s)throw a;return console.warn(`WARNING: While tracking your prompt PromptLayer had the following error: ${a}`),null}}),Po=(t,n)=>E(null,null,function*(){var p,d;let e=n==null?void 0:n.history,s=n==null?void 0:n.generationConfig,a=e.length>0?(p=e[e.length-1])==null?void 0:p.parts:"",r=t.chats.create({model:n==null?void 0:n.model,history:(d=e.slice(0,-1))!=null?d:[],config:s});return n!=null&&n.stream?yield r.sendMessageStream({message:a}):yield r.sendMessage({message:a})}),Io=(t,s)=>E(null,null,function*(){var a=s,{stream:n}=a,e=Ye(a,["stream"]);return n?yield t.generateContentStream(C({},e)):yield t.generateContent(C({},e))}),Eo={chat:Po,completion:Io},Oo=(t,n)=>E(null,null,function*(){let{GoogleGenAI:e}=yield import("@google/genai"),s=process.env.GOOGLE_API_KEY||process.env.GEMINI_API_KEY,a=process.env.VERTEX_AI_PROJECT_ID||process.env.GOOGLE_PROJECT_ID||process.env.GOOGLE_CLOUD_PROJECT,r=process.env.VERTEX_AI_PROJECT_LOCATION||process.env.GOOGLE_PROJECT_LOCATION||process.env.GOOGLE_CLOUD_PROJECT_LOCATION,p={keyFilename:process.env.GOOGLE_APPLICATION_CREDENTIALS,projectId:a,scopes:["https://www.googleapis.com/auth/cloud-platform"]},d=s?new e({apiKey:s}):new e({vertexai:!0,project:a,location:r,googleAuthOptions:p}),m=Eo[t.prompt_template.type];return yield m(d,n)}),Jn=t=>t.replace(/_([a-z])/g,(n,e)=>e.toUpperCase()),Qe=(t,n=new Set)=>!t||typeof t!="object"?t:Array.isArray(t)?t.map(e=>Qe(e,n)):Object.fromEntries(Object.entries(t).map(([e,s])=>n.has(e)?[Jn(e),s]:[Jn(e),Qe(s,n)])),os=(t,n,e={},s=!1)=>{var m,u,_,w,x,b,I,A,h;let a=(_=n==null?void 0:n.client)!=null?_:(u=(m=t.metadata)==null?void 0:m.model)==null?void 0:u.provider,r=(x=(w=t.metadata)==null?void 0:w.model)==null?void 0:x.api_type;if(!a)throw new Error("Provider type not found in prompt blueprint or custom provider");let p=X(C({},t.llm_kwargs||{}),{stream:s});["google","vertexai"].includes(a)&&((I=(b=t.metadata)==null?void 0:b.model)!=null&&I.name.startsWith("gemini"))&&(p=Qe(p,new Set(["function_declarations","properties"])));let d={baseURL:(h=n==null?void 0:n.base_url)!=null?h:(A=t.provider_base_url)==null?void 0:A.url,apiKey:n==null?void 0:n.api_key};return Object.entries(d).forEach(([R,f])=>{f!==void 0&&(p[R]=f)}),s&&Dn.includes(a)&&r==="chat-completions"&&(p.stream_options={include_usage:!0}),{provider_type:a,kwargs:p}},ss=(t,n)=>{let e=zn[t];if(!e)throw new Error(`Unsupported provider type: ${t}`);let s=n.type,a=e[s];if(!a)throw new Error(`Unsupported template type '${n.type}' for provider '${t}'`);return a},as=(t,n)=>E(null,null,function*(){var s;let e=(s=t.metadata)==null?void 0:s.model;if(!e)throw new Error("Model metadata not found in prompt blueprint");if(e.name.startsWith("gemini"))return Oo(t,n);if(e.name.startsWith("claude")){let{AnthropicVertex:a}=yield import("@anthropic-ai/vertex-sdk"),r=new a({baseURL:n.baseURL});if(t.prompt_template.type==="chat")return Zn(r,n);throw new Error(`Unsupported prompt template type '${t.prompt_template.type}' for Anthropic Vertex AI`)}throw new Error(`Unsupported model name '${e.name}' for Vertex AI request`)}),is=(t,n)=>E(null,null,function*(){let{BedrockRuntimeClient:e,ConverseCommand:s,ConverseStreamCommand:a}=yield import("@aws-sdk/client-bedrock-runtime"),r=new e({credentials:{accessKeyId:(n==null?void 0:n.aws_access_key)||process.env.AWS_ACCESS_KEY_ID,secretAccessKey:(n==null?void 0:n.aws_secret_key)||process.env.AWS_SECRET_ACCESS_KEY,sessionToken:(n==null?void 0:n.aws_session_token)||process.env.AWS_SESSION_TOKEN},region:(n==null?void 0:n.aws_region)||process.env.AWS_REGION||process.env.AWS_DEFAULT_REGION||"us-east-1"});if(n!=null&&n.stream){delete n.stream;let p=new a(C({},n));return yield r.send(p)}else{n==null||delete n.stream;let p=new s(C({},n));return yield r.send(p)}}),rs=(t,n)=>E(null,null,function*(){let{AnthropicBedrock:e}=yield import("@anthropic-ai/bedrock-sdk"),s=new e({awsAccessKey:n.aws_access_key,awsSecretKey:n.aws_secret_key,awsRegion:n.aws_region,awsSessionToken:n.aws_session_token,baseURL:n.base_url}),a=Qn[t.prompt_template.type];return a(s,n)}),ls=(t,n)=>E(null,null,function*(){let{Mistral:e}=yield import("@mistralai/mistralai"),s=new e({apiKey:process.env.MISTRAL_API_KEY});return n=Qe(n,new Set),n!=null&&n.stream?(delete n.stream,yield s.chat.stream(n)):(delete n.stream,yield s.chat.complete(n))}),cs=t=>{var n,e,s,a,r,p;if(typeof globalThis.process!="undefined")return(s=(e=(n=globalThis.process.env)==null?void 0:n[t])==null?void 0:e.trim())!=null?s:void 0;if(typeof globalThis.Deno!="undefined")return(p=(r=(a=globalThis.Deno.env)==null?void 0:a.get)==null?void 0:r.call(a,t))==null?void 0:p.trim()};export{C as a,X as b,Ve as c,E as d,Wo as e,Vn as f,Z as g,H as h,Do as i,Bo as j,Ko as k,zo as l,Jo as m,Vo as n,Yo as o,Xo as p,Ho as q,Zo as r,Qo as s,vo as t,ts as u,es as v,ns as w,Oo as x,os as y,ss as z,as as A,is as B,rs as C,ls as D,cs as E};
|
|
2
|
+
//# sourceMappingURL=chunk-SWBNW72U.js.map
|