@qitqode/qitqode-android-arm64 0.2.1 → 0.2.2
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/bun +0 -0
- package/bundle/chunk-0cdtq1r3.js +2 -0
- package/bundle/{chunk-v7mg632n.js → chunk-0yjdatm6.js} +1 -1
- package/bundle/{chunk-3ktj87g4.js → chunk-0ykeedfm.js} +1 -1
- package/bundle/{chunk-a0rjp24v.js → chunk-2517cev8.js} +1 -1
- package/bundle/{chunk-rnq5ezrt.js → chunk-2faah8w1.js} +1 -1
- package/bundle/{chunk-p5mes2sh.js → chunk-3888asr7.js} +1 -1
- package/bundle/{chunk-3wxvpvg4.js → chunk-3c3xzz0g.js} +1 -1
- package/bundle/{chunk-3aq70t26.js → chunk-3jms025t.js} +1 -1
- package/bundle/{chunk-f1bcz9yz.js → chunk-44y6dffe.js} +1 -1
- package/bundle/{chunk-wp3dpt6d.js → chunk-45fyv9f1.js} +1 -1
- package/bundle/{chunk-dknemkw2.js → chunk-543pt030.js} +1 -1
- package/bundle/{chunk-zqkv8796.js → chunk-5js6a6gf.js} +1 -1
- package/bundle/{chunk-dj3525nn.js → chunk-6f8qqbac.js} +189 -189
- package/bundle/{chunk-q9ft590w.js → chunk-7ab3yw9j.js} +1 -1
- package/bundle/chunk-7q003wdd.js +4 -0
- package/bundle/{chunk-6y4mwmn4.js → chunk-7z884mz2.js} +1 -1
- package/bundle/{chunk-qeg0jnxq.js → chunk-7zc04q43.js} +1 -1
- package/bundle/{chunk-g5cgpvef.js → chunk-85xh72hk.js} +1 -1
- package/bundle/{chunk-tce12v85.js → chunk-8apeexas.js} +1 -1
- package/bundle/{chunk-7myg8076.js → chunk-8d6e4jg7.js} +1 -1
- package/bundle/{chunk-qg9bt0kx.js → chunk-8v6x712g.js} +1 -1
- package/bundle/{chunk-mx3jd1p9.js → chunk-91z7azf7.js} +1 -1
- package/bundle/{chunk-e89zjjmj.js → chunk-96sqbyvf.js} +1 -1
- package/bundle/{chunk-bzs2ep7s.js → chunk-9bm9z52r.js} +1 -1
- package/bundle/{chunk-6bghztra.js → chunk-9pnpmtb2.js} +1 -1
- package/bundle/chunk-9s785py4.js +28 -0
- package/bundle/{chunk-kc1xmcc9.js → chunk-a550vst5.js} +39 -37
- package/bundle/{chunk-7zvawpe1.js → chunk-a5pbvp1f.js} +1 -1
- package/bundle/{chunk-tq1dqhes.js → chunk-c1bw1q75.js} +1 -1
- package/bundle/{chunk-erdjd9w3.js → chunk-c47vp7ne.js} +1 -1
- package/bundle/{chunk-ke5rqv5b.js → chunk-cbhgf058.js} +1 -1
- package/bundle/{chunk-jgtcfw96.js → chunk-dbztxdea.js} +1 -1
- package/bundle/{chunk-57xbwzdn.js → chunk-dy31mchw.js} +1 -1
- package/bundle/{chunk-jjjs8p0t.js → chunk-e374shb8.js} +1 -1
- package/bundle/{chunk-s7yza695.js → chunk-e5rda9mx.js} +1 -1
- package/bundle/{chunk-qzszrd0s.js → chunk-e999xtfj.js} +1 -1
- package/bundle/{chunk-nb86kh94.js → chunk-ehfxypks.js} +69 -71
- package/bundle/{chunk-hpa7e9va.js → chunk-epa576pa.js} +2 -2
- package/bundle/{chunk-knh01n2r.js → chunk-et5dnymk.js} +1 -1
- package/bundle/{chunk-ahyqfbmq.js → chunk-frsd6e1h.js} +1 -1
- package/bundle/{chunk-ztn2jv26.js → chunk-g7k6ecb2.js} +1 -1
- package/bundle/{chunk-xjpvv3vp.js → chunk-h10wjk96.js} +1 -1
- package/bundle/{chunk-hmznf0ax.js → chunk-h2bmss2m.js} +1 -1
- package/bundle/chunk-h4f582d6.js +2 -0
- package/bundle/chunk-h57c6ne3.js +2 -0
- package/bundle/{chunk-yg0pfngv.js → chunk-hnrqhcgq.js} +1 -1
- package/bundle/{chunk-fvkwcx35.js → chunk-hy86wfad.js} +1 -1
- package/bundle/{chunk-073ydjmk.js → chunk-j17421hz.js} +1 -1
- package/bundle/chunk-kh8de8re.js +2 -0
- package/bundle/{chunk-yqb6cfed.js → chunk-kmwy6c9g.js} +1 -1
- package/bundle/{chunk-mk2s9py8.js → chunk-mce8aa9y.js} +1 -1
- package/bundle/{chunk-s99cvvc9.js → chunk-me1ja46g.js} +1 -1
- package/bundle/{chunk-faa0zxey.js → chunk-mrn44msr.js} +1 -1
- package/bundle/chunk-q2q3dmg3.js +2 -0
- package/bundle/chunk-q46pzk9z.js +8 -0
- package/bundle/{chunk-pfh34atn.js → chunk-racrb1b3.js} +1 -1
- package/bundle/{chunk-fymt1rym.js → chunk-s0c0t6qr.js} +1 -1
- package/bundle/{chunk-qkh8697x.js → chunk-s77qktcn.js} +1 -1
- package/bundle/{chunk-mxf9p0p9.js → chunk-sghy9s7m.js} +1 -1
- package/bundle/{chunk-r2qns6yc.js → chunk-sjreby6e.js} +1 -1
- package/bundle/{chunk-29v1v357.js → chunk-skxhg212.js} +1 -1
- package/bundle/{chunk-yerfyz4w.js → chunk-ssdw9zre.js} +1 -1
- package/bundle/{chunk-g9end129.js → chunk-t1475j9f.js} +1 -1
- package/bundle/{chunk-0z1cxvk1.js → chunk-tj3rem3q.js} +1 -1
- package/bundle/{chunk-f7rj6fck.js → chunk-vk88jj60.js} +1 -1
- package/bundle/{chunk-ex93y6dw.js → chunk-vrv67tt0.js} +1 -1
- package/bundle/{chunk-9eg2ytjd.js → chunk-vtw0wwch.js} +1 -1
- package/bundle/{chunk-q148vndn.js → chunk-vyh300ac.js} +1 -1
- package/bundle/{chunk-vjx0064q.js → chunk-w30b563s.js} +1 -1
- package/bundle/chunk-wcx7hc2p.js +635 -0
- package/bundle/{chunk-7rhry8nv.js → chunk-wv8qx8sa.js} +1 -1
- package/bundle/{chunk-sh76e256.js → chunk-xmjntwjc.js} +1 -1
- package/bundle/{chunk-nm6wnne9.js → chunk-y2ptjam9.js} +1 -1
- package/bundle/{chunk-nh044sjn.js → chunk-y6h35v4a.js} +1 -1
- package/bundle/{chunk-0yagj4ss.js → chunk-y72p79v2.js} +1 -1
- package/bundle/{chunk-4jq25vbc.js → chunk-y9q0f9qz.js} +1 -1
- package/bundle/{chunk-f4zfk5ye.js → chunk-yhsnmpzv.js} +1 -1
- package/bundle/{chunk-qf1dqzra.js → chunk-ywdtp534.js} +1 -1
- package/bundle/{chunk-xnhvt98g.js → chunk-zcp0wx4j.js} +1 -1
- package/bundle/index.js +3 -3
- package/bundle/worker.js +1 -1
- package/package.json +1 -1
- package/bundle/chunk-0xrr0k94.js +0 -2
- package/bundle/chunk-3kn57y8d.js +0 -619
- package/bundle/chunk-9nn4jpb7.js +0 -2
- package/bundle/chunk-9tk4wsn4.js +0 -2
- package/bundle/chunk-egae7vvg.js +0 -2
- package/bundle/chunk-fghqr4x8.js +0 -8
- package/bundle/chunk-x3afqfww.js +0 -4
- package/bundle/chunk-xwgc2pw7.js +0 -28
- package/bundle/chunk-yxeja9kg.js +0 -2
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{Rd as q}from"./chunk-yajd975f.js";import{Uf as v}from"./chunk-t1jgx17a.js";import{Zg as S}from"./chunk-
|
|
2
|
+
import{Rd as q}from"./chunk-yajd975f.js";import{Uf as v}from"./chunk-t1jgx17a.js";import{Zg as S}from"./chunk-wcx7hc2p.js";import"./chunk-ehfxypks.js";import"./chunk-9rxyq6f9.js";import"./chunk-5az84brc.js";import"./chunk-94qhpkfx.js";import"./chunk-c1g8n10t.js";import"./chunk-a2dz9nqh.js";import"./chunk-vhe92p7a.js";import"./chunk-a550vst5.js";import"./chunk-e374shb8.js";import{Vl as Q,cm as H}from"./chunk-zcp0wx4j.js";import"./chunk-epa576pa.js";import"./chunk-y287zwkr.js";import"./chunk-7zc04q43.js";import"./chunk-vtw0wwch.js";import"./chunk-rk2bk4s7.js";import"./chunk-e586sjb0.js";import"./chunk-b50t4jc5.js";import"./chunk-zdzxsyxs.js";import"./chunk-xny5ecn0.js";import"./chunk-8d6e4jg7.js";import"./chunk-my3cswnp.js";import"./chunk-4mvg7jt1.js";import"./chunk-cqtkxwd8.js";import"./chunk-wf4x5cjc.js";import"./chunk-mswx4k75.js";import"./chunk-vqpfpmha.js";import"./chunk-vm1ek7yf.js";import"./chunk-fd7fmvyw.js";import"./chunk-1sfcxdbw.js";import"./chunk-bgng3rdj.js";import"./chunk-s77qktcn.js";import"./chunk-8v6x712g.js";import"./chunk-pfkm3j8g.js";import"./chunk-h2bmss2m.js";import{cs as K}from"./chunk-ywdtp534.js";import"./chunk-03mbn7nj.js";import"./chunk-gr4bctqj.js";import"./chunk-732yr6qq.js";import"./chunk-73fz0cf4.js";import"./chunk-0cdtq1r3.js";import"./chunk-xmjntwjc.js";import"./chunk-tj3rem3q.js";import"./chunk-7q003wdd.js";import"./chunk-cbmwhvxw.js";import"./chunk-9etpppyv.js";import"./chunk-9ea1n338.js";import"./chunk-ngvp6zc2.js";import"./chunk-1p6jjrea.js";import"./chunk-ks1cs80p.js";import"./chunk-a92hh67a.js";import"./chunk-qhnpq5gb.js";import"./chunk-f83wv08n.js";var P=q({command:"pr <number>",describe:"fetch and checkout a GitHub PR branch, then run qitqode",builder:(Y)=>Y.positional("number",{type:"number",describe:"PR number to checkout",demandOption:!0}),async handler(Y){await H.provide({directory:process.cwd(),async fn(){if(H.project.vcs!=="git")v.error("Could not find git repository. Please run this command from a git repository."),process.exit(1);let J=Y.number,Z=`pr/${J}`;if(v.println(`Fetching and checking out PR #${J}...`),(await K.run(["gh","pr","checkout",`${J}`,"--branch",Z,"--force"],{nothrow:!0})).code!==0)v.error(`Failed to checkout PR #${J}. Make sure you have gh CLI installed and authenticated.`),process.exit(1);let _=await K.text(["gh","pr","view",`${J}`,"--json","headRepository,headRepositoryOwner,isCrossRepository,headRefName,body"],{nothrow:!0}),V;if(_.code===0){let j=_.text;if(j.trim()){let z=JSON.parse(j);if(z&&z.isCrossRepository&&z.headRepository&&z.headRepositoryOwner){let L=z.headRepositoryOwner.login,W=z.headRepository.name,C=L;if(!(await S.runPromise(Q.Service.use((F)=>F.run(["remote"],{cwd:H.worktree}))).then((F)=>F.text().trim())).split(`
|
|
3
3
|
`).includes(C))await S.runPromise(Q.Service.use((F)=>F.run(["remote","add",C,`https://github.com/${L}/${W}.git`],{cwd:H.worktree}))),v.println(`Added fork remote: ${C}`);let X=z.headRefName;await S.runPromise(Q.Service.use((F)=>F.run(["branch",`--set-upstream-to=${C}/${X}`,Z],{cwd:H.worktree})))}if(z&&z.body){let L=z.body.match(/https:\/\/opncd\.ai\/s\/([a-zA-Z0-9_-]+)/);if(L){let W=L[0];v.println(`Found qitqode session: ${W}`),v.println("Importing session...");let C=await K.text(["qitqode","import",W],{nothrow:!0});if(C.code===0){let X=C.text.trim().match(/Imported session: ([a-zA-Z0-9_-]+)/);if(X)V=X[1],v.println(`Session imported: ${V}`)}}}}}v.println(`Successfully checked out PR #${J} as branch '${Z}'`),v.println(),v.println("Starting qitqode..."),v.println();let D=V?["-s",V]:[],$=await K.spawn(["qitqode",...D],{stdin:"inherit",stdout:"inherit",stderr:"inherit",cwd:process.cwd()}).exited;if($!==0)throw Error(`qitqode exited with code ${$}`)}})}});export{P as PrCommand};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{ds as rZ}from"./chunk-03mbn7nj.js";import{ts as X$}from"./chunk-
|
|
2
|
+
import{ds as rZ}from"./chunk-03mbn7nj.js";import{ts as X$}from"./chunk-0cdtq1r3.js";import{et as R,nt as g}from"./chunk-7q003wdd.js";import{At as f,Dt as YZ}from"./chunk-cbmwhvxw.js";import{xH as Z$}from"./chunk-ks1cs80p.js";import{LO as iZ,NO as XZ,PO as GZ}from"./chunk-f83wv08n.js";function X1({onRequest:Z,onSseError:$,onSseEvent:X,responseTransformer:J,responseValidator:G,sseDefaultRetryDelay:z,sseMaxRetryAttempts:W,sseMaxRetryDelay:V,sseSleepFn:O,url:Q,...D}){let M,L=O??((N)=>new Promise((j)=>setTimeout(j,N)));return{stream:async function*(){let N=z??3000,j=0,I=D.signal??new AbortController().signal;while(!0){if(I.aborted)break;j++;let F=D.headers instanceof Headers?D.headers:new Headers(D.headers);if(M!==void 0)F.set("Last-Event-ID",M);try{let P={redirect:"follow",...D,body:D.serializedBody,headers:F,signal:I},h=new Request(Q,P);if(Z)h=await Z(Q,P);let S=await(D.fetch??globalThis.fetch)(h);if(!S.ok)throw Error(`SSE failed: ${S.status} ${S.statusText}`);if(!S.body)throw Error("No body in SSE response");let T=S.body.pipeThrough(new TextDecoderStream).getReader(),x="",t$=()=>{try{T.cancel()}catch{}};I.addEventListener("abort",t$);try{while(!0){let{done:TZ,value:wZ}=await T.read();if(TZ)break;x+=wZ,x=x.replace(/\r\n?/g,`
|
|
3
3
|
`);let o$=x.split(`
|
|
4
4
|
|
|
5
5
|
`);x=o$.pop()??"";for(let FZ of o$){let HZ=FZ.split(`
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{$q as dJ,Zq as mJ,_q as vJ,ar as lJ,dr as d,er as l,gr as uJ,hr as cJ,kr as pJ,lr as iJ,mr as nJ,nr as aJ,or as rJ,qr as AQ}from"./chunk-pfkm3j8g.js";import{Ts as FQ,us as CQ,vs as DQ}from"./chunk-sh76e256.js";import{et as x,nt as GJ}from"./chunk-x3afqfww.js";import{$F as MJ,AB as HJ,AF as t,AG as NJ,BE as zJ,BF as OJ,DB as WJ,DF as y,EI as gJ,FB as $Q,IC as IJ,KA as tJ,LC as PJ,LG as kJ,ME as ZJ,NB as f,OC as T,PG as LJ,QF as TJ,RC as KJ,SG as SJ,WE as z,WG as xJ,XD as qQ,XF as EJ,_G as fJ,aF as b,cE as _J,cF as CJ,cG as oJ,gG as RJ,hM as j,iG as VJ,jH as E,lG as hJ,mF as DJ,nF as FJ,oF as AJ,oH as yJ,pH as bJ,rE as BQ,sE as wQ,sO as g,tO as eJ,uC as GQ,uG as jJ,vE as $J,wE as UJ,wO as HQ,xB as wJ,xH as I,xO as WQ,yM as o,yO as R}from"./chunk-ks1cs80p.js";import{LO as zQ,NO as u,PO as S}from"./chunk-f83wv08n.js";var IX={};u(IX,{resource:()=>BJ,layer:()=>EQ,enabled:()=>OQ,Observability:()=>WX});var p={};u(p,{make:()=>IQ,layer:()=>ZX});var VQ=AJ.pipe(FJ,DJ((J)=>{if(lJ(J)&&J.reason._tag==="StatusCodeError"&&J.reason.response.status===429){let Q=HJ(J.reason.response.headers["retry-after"]).pipe(WJ(CJ),wJ(()=>5));return t(T(Q))}return t(T(1))})),sJ=E(function*(J){let Q=yield*jJ(),X=f(Q,b),Y=f(Q,UJ),$=fJ(Q),G=KJ(IJ(J.exportInterval),PJ),B=void 0,C=nJ(f(Q,pJ)).pipe(iJ(NJ(rJ,!1)),aJ({schedule:VQ,times:3})),V=vJ({"user-agent":`effect-opentelemetry-${J.label}/0.0.0`});if(J.headers)V=dJ(mJ(J.headers),V);let r=uJ(J.url,{headers:V}),O=[],s=OJ(()=>{if(B!==void 0&&X.currentTimeMillisUnsafe()<B)return y;else if(B!==void 0)B=void 0;let h=O;if(J.maxBatchSize!=="disabled"){if(O.length===0)return y;O=[]}return C.execute(cJ(r,J.body(h))).pipe(EJ,SJ(!1))}).pipe(MJ((h)=>{if(B!==void 0)return y;return B=X.currentTimeMillisUnsafe()+60000,O=[],yJ("Disabling exporter for 60 seconds",h)}),bJ({package:"@effect/opentelemetry",module:J.label}));return yield*zJ(Y,s.pipe(RJ,kJ,VJ(J.shutdownTimeout))),yield*hJ(G).pipe(TJ(s),LJ,xJ(Y)),{push(h){if(B!==void 0)return;if(O.push(h),J.maxBatchSize!=="disabled"&&O.length>=J.maxBatchSize)gJ($(s),Y)}}});var jQ=(J)=>{let Q=J.attributes?e(Object.entries(J.attributes)):[];if(Q.push({key:"service.name",value:{stringValue:J.serviceName}}),J.serviceVersion)Q.push({key:"service.version",value:{stringValue:J.serviceVersion}});return{attributes:Q,droppedAttributesCount:0}},JQ=E(function*(J){let Q={...yield*g(o(eJ(j,j)),"OTEL_RESOURCE_ATTRIBUTES"),...J?.attributes},X=J?.serviceName??Q["service.name"]??(yield*g(j,"OTEL_SERVICE_NAME"));delete Q["service.name"];let Y=J?.serviceVersion??Q["service.version"]??(yield*g(o(j),"OTEL_SERVICE_VERSION"));return delete Q["service.version"],jQ({serviceName:X,serviceVersion:Y,attributes:Q})},oJ),QQ=(J)=>{let Q=J.attributes.find((X)=>X.key==="service.name");if(!Q||!Q.value.stringValue)throw Error("Resource does not contain a service name");return Q.value.stringValue},e=(J)=>{let Q=[];for(let[X,Y]of J)Q.push({key:X,value:m(Y)});return Q},m=(J)=>{if(Array.isArray(J))return{arrayValue:{values:J.map(m)}};switch(typeof J){case"string":return{stringValue:J};case"bigint":return{intValue:Number(J)};case"number":return Number.isInteger(J)?{intValue:J}:{doubleValue:J};case"boolean":return{boolValue:J};default:return{stringValue:tJ(J)}}};var c={};u(c,{layerProtobuf:()=>YX,layerJson:()=>XX,OtlpSerialization:()=>M});var N={Varint:0,Fixed64:1,LengthDelimited:2,Fixed32:5},k=(J,Q)=>J<<3|Q,D=(J)=>{let Q=[],X=typeof J==="bigint"?J:BigInt(J);while(X>0x7fn)Q.push(Number(X&0x7fn)|128),X>>=7n;return Q.push(Number(X)),new Uint8Array(Q)};var kQ=(J)=>{let Q=new Uint8Array(8);return new DataView(Q.buffer).setBigUint64(0,J,!0),Q},LQ=(J)=>{let Q=new Uint8Array(4);return new DataView(Q.buffer).setUint32(0,J,!0),Q},SQ=(J)=>{let Q=new Uint8Array(8);return new DataView(Q.buffer).setFloat64(0,J,!0),Q},xQ=(J)=>new TextEncoder().encode(J),fQ=(J)=>{let Q=new Uint8Array(J.length/2);for(let X=0;X<J.length;X+=2)Q[X/2]=parseInt(J.slice(X,X+2),16);return Q},Z=(...J)=>{let Q=J.reduce(($,G)=>$+G.length,0),X=new Uint8Array(Q),Y=0;for(let $ of J)X.set($,Y),Y+=$.length;return X},q=(J,Q)=>Z(D(k(J,N.Varint)),D(Q));var JJ=(J,Q)=>q(J,Q?1:0),W=(J,Q)=>Z(D(k(J,N.Fixed64)),kQ(Q)),v=(J,Q)=>Z(D(k(J,N.Fixed32)),LQ(Q)),F=(J,Q)=>Z(D(k(J,N.Fixed64)),SQ(Q)),L=(J,Q)=>Z(D(k(J,N.LengthDelimited)),D(Q.length),Q),K=(J,Q)=>L(J,xQ(Q)),U=(J,Q)=>L(J,fQ(Q)),w=(J,Q)=>L(J,Q),_=(J,Q,X)=>Z(...Q.map((Y)=>w(J,X(Y))));var H=(J,Q)=>Q!==void 0&&Q!==""?K(J,Q):new Uint8Array(0);var QJ=(J)=>{if(J.stringValue!==void 0&&J.stringValue!==null)return K(1,J.stringValue);if(J.boolValue!==void 0&&J.boolValue!==null)return JJ(2,J.boolValue);if(J.intValue!==void 0&&J.intValue!==null)return q(3,BigInt(J.intValue));if(J.doubleValue!==void 0&&J.doubleValue!==null)return F(4,J.doubleValue);if(J.arrayValue!==void 0)return w(5,bQ(J.arrayValue));if(J.kvlistValue!==void 0)return w(6,gQ(J.kvlistValue));if(J.bytesValue!==void 0)return L(7,J.bytesValue);return new Uint8Array(0)},bQ=(J)=>_(1,J.values,QJ),gQ=(J)=>_(1,J.values,P),P=(J)=>Z(K(1,J.key),w(2,QJ(J.value))),XJ=(J)=>Z(K(1,J.name),H(2,J.version),J.attributes?_(3,J.attributes,P):new Uint8Array(0),J.droppedAttributesCount?q(4,J.droppedAttributesCount):new Uint8Array(0)),YJ=(J)=>Z(_(1,J.attributes,P),J.droppedAttributesCount>0?q(2,J.droppedAttributesCount):new Uint8Array(0));var mQ=(J)=>Z(H(2,J.message),q(3,J.code)),vQ=(J)=>Z(W(1,BigInt(J.timeUnixNano)),K(2,J.name),_(3,J.attributes,P),J.droppedAttributesCount>0?q(4,J.droppedAttributesCount):new Uint8Array(0)),dQ=(J)=>Z(U(1,J.traceId),U(2,J.spanId),H(3,J.traceState),_(4,J.attributes,P),J.droppedAttributesCount>0?q(5,J.droppedAttributesCount):new Uint8Array(0),J.flags!==void 0?v(6,J.flags):new Uint8Array(0)),lQ=(J)=>Z(U(1,J.traceId),U(2,J.spanId),H(3,J.traceState),J.parentSpanId!==void 0?U(4,J.parentSpanId):new Uint8Array(0),K(5,J.name),q(6,J.kind),W(7,BigInt(J.startTimeUnixNano)),W(8,BigInt(J.endTimeUnixNano)),_(9,J.attributes,P),J.droppedAttributesCount>0?q(10,J.droppedAttributesCount):new Uint8Array(0),_(11,J.events,vQ),J.droppedEventsCount>0?q(12,J.droppedEventsCount):new Uint8Array(0),_(13,J.links,dQ),J.droppedLinksCount>0?q(14,J.droppedLinksCount):new Uint8Array(0),w(15,mQ(J.status)),J.flags!==void 0?v(16,J.flags):new Uint8Array(0)),uQ=(J)=>Z(w(1,XJ(J.scope)),_(2,J.spans,lQ),H(3,J.schemaUrl)),cQ=(J)=>Z(w(1,YJ(J.resource)),_(2,J.scopeSpans,uQ),H(3,J.schemaUrl)),XQ=(J)=>_(1,J.resourceSpans,cQ);var YQ=(J)=>Z(W(2,BigInt(J.startTimeUnixNano)),W(3,BigInt(J.timeUnixNano)),J.asDouble!==void 0?F(4,J.asDouble):new Uint8Array(0),J.asInt!==void 0?W(6,BigInt(J.asInt)):new Uint8Array(0),_(7,J.attributes,P),J.flags!==void 0?q(8,J.flags):new Uint8Array(0)),pQ=(J)=>{let Q=Z(...J.bucketCounts.map((Y)=>W(6,BigInt(Y)))),X=Z(...J.explicitBounds.map((Y)=>F(7,Y)));return Z(W(2,BigInt(J.startTimeUnixNano)),W(3,BigInt(J.timeUnixNano)),W(4,BigInt(J.count)),J.sum!==void 0?F(5,J.sum):new Uint8Array(0),Q,X,_(9,J.attributes,P),J.flags!==void 0?q(10,J.flags):new Uint8Array(0),J.min!==void 0?F(11,J.min):new Uint8Array(0),J.max!==void 0?F(12,J.max):new Uint8Array(0))},iQ=(J)=>_(1,J.dataPoints,YQ),nQ=(J)=>Z(_(1,J.dataPoints,YQ),q(2,J.aggregationTemporality),JJ(3,J.isMonotonic)),aQ=(J)=>Z(_(1,J.dataPoints,pQ),q(2,J.aggregationTemporality)),rQ=(J)=>Z(K(1,J.name),H(2,J.description),H(3,J.unit),J.gauge!==void 0?w(5,iQ(J.gauge)):new Uint8Array(0),J.sum!==void 0?w(7,nQ(J.sum)):new Uint8Array(0),J.histogram!==void 0?w(9,aQ(J.histogram)):new Uint8Array(0)),sQ=(J)=>Z(w(1,XJ(J.scope)),_(2,J.metrics,rQ),H(3,J.schemaUrl)),tQ=(J)=>Z(w(1,YJ(J.resource)),_(2,J.scopeMetrics,sQ),H(3,J.schemaUrl)),ZQ=(J)=>_(1,J.resourceMetrics,tQ);var oQ=(J)=>Z(W(1,BigInt(J.timeUnixNano)),J.severityNumber!==void 0?q(2,J.severityNumber):new Uint8Array(0),H(3,J.severityText),J.body!==void 0?w(5,QJ(J.body)):new Uint8Array(0),_(6,J.attributes,P),J.droppedAttributesCount!==void 0&&J.droppedAttributesCount>0?q(7,J.droppedAttributesCount):new Uint8Array(0),J.flags!==void 0?v(8,J.flags):new Uint8Array(0),J.traceId!==void 0&&J.traceId!==""?U(9,J.traceId):new Uint8Array(0),J.spanId!==void 0&&J.spanId!==""?U(10,J.spanId):new Uint8Array(0),J.observedTimeUnixNano!==void 0?W(11,BigInt(J.observedTimeUnixNano)):new Uint8Array(0)),eQ=(J)=>Z(w(1,XJ(J.scope)),_(2,J.logRecords,oQ),H(3,J.schemaUrl)),JX=(J)=>Z(w(1,YJ(J.resource)),_(2,J.scopeLogs,eQ),H(3,J.schemaUrl)),_Q=(J)=>_(1,J.resourceLogs,JX);class M extends $Q()("effect/observability/OtlpSerialization"){}var XX=ZJ(M,{traces:(J)=>l(J),metrics:(J)=>l(J),logs:(J)=>l(J)}),YX=ZJ(M,{traces:(J)=>d(XQ(J),"application/x-protobuf"),metrics:(J)=>d(ZQ(J),"application/x-protobuf"),logs:(J)=>d(_Q(J),"application/x-protobuf")});var IQ=E(function*(J){let Q=yield*M,X=yield*JQ(J.resource),Y={name:QQ(X)},$=yield*sJ({label:"OtlpLogger",url:J.url,headers:J.headers,maxBatchSize:J.maxBatchSize??1000,exportInterval:J.exportInterval??T(1),body:(B)=>Q.logs({resourceLogs:[{resource:X,scopeLogs:[{scope:Y,logRecords:B}]}]}),shutdownTimeout:J.shutdownTimeout??T(3)}),G={excludeLogSpans:J.excludeLogSpans??!1,clock:yield*b};return HQ((B)=>{$.push(_X(B,G))})}),ZX=(J)=>WQ([IQ(J)],{mergeWithExisting:J.mergeWithExisting??!0}),_X=(J,Q)=>{let Y=Q.clock.currentTimeNanosUnsafe().toString(),$=J.date.getTime(),G=e(Object.entries(J.fiber.getRef(BQ)));if(G.push({key:"fiberId",value:{intValue:J.fiber.id}}),!Q.excludeLogSpans)for(let[V,r]of J.fiber.getRef(wQ))G.push({key:`logSpan.${V}`,value:{stringValue:`${$-r}ms`}});if(J.cause.reasons.length>0)G.push({key:"log.error",value:{stringValue:qQ(J.cause)}});let B=GQ(J.message),C={severityNumber:$X(J.logLevel),severityText:J.logLevel,timeUnixNano:Y,observedTimeUnixNano:Y,attributes:G,body:m(B.length===1?B[0]:B),droppedAttributesCount:0};if(J.fiber.currentSpan)C.traceId=J.fiber.currentSpan.traceId,C.spanId=J.fiber.currentSpan.spanId;return C},$X=(J)=>{switch(J){case"Trace":return A.SEVERITY_NUMBER_TRACE;case"Debug":return A.SEVERITY_NUMBER_DEBUG;case"Info":return A.SEVERITY_NUMBER_INFO;case"Warn":return A.SEVERITY_NUMBER_WARN;case"Error":return A.SEVERITY_NUMBER_ERROR;case"Fatal":return A.SEVERITY_NUMBER_FATAL;default:return A.SEVERITY_NUMBER_UNSPECIFIED}},A={SEVERITY_NUMBER_UNSPECIFIED:0,SEVERITY_NUMBER_TRACE:1,SEVERITY_NUMBER_TRACE2:2,SEVERITY_NUMBER_TRACE3:3,SEVERITY_NUMBER_TRACE4:4,SEVERITY_NUMBER_DEBUG:5,SEVERITY_NUMBER_DEBUG2:6,SEVERITY_NUMBER_DEBUG3:7,SEVERITY_NUMBER_DEBUG4:8,SEVERITY_NUMBER_INFO:9,SEVERITY_NUMBER_INFO2:10,SEVERITY_NUMBER_INFO3:11,SEVERITY_NUMBER_INFO4:12,SEVERITY_NUMBER_WARN:13,SEVERITY_NUMBER_WARN2:14,SEVERITY_NUMBER_WARN3:15,SEVERITY_NUMBER_WARN4:16,SEVERITY_NUMBER_ERROR:17,SEVERITY_NUMBER_ERROR2:18,SEVERITY_NUMBER_ERROR3:19,SEVERITY_NUMBER_ERROR4:20,SEVERITY_NUMBER_FATAL:21,SEVERITY_NUMBER_FATAL2:22,SEVERITY_NUMBER_FATAL3:23,SEVERITY_NUMBER_FATAL4:24};var UQ={};u(UQ,{logger:()=>n,layer:()=>qJ,create:()=>KQ});var GX=(J)=>J==="sessionID"?"session.id":J,PQ=(J)=>Object.fromEntries(Object.entries(J??{}).filter((Q)=>Q[1]!==void 0&&Q[1]!==null).map(([Q,X])=>[GX(Q),X])),qX=(J)=>{if(Array.isArray(J))return J.map((Q)=>String(Q)).join(" ");return J===void 0?"":String(J)},i=(J,Q,X,Y)=>{let $=PQ({...Q,...Y}),G=J(X);return Object.keys($).length?I.annotateLogs(G,$):G},n=R.make((J)=>{let Q=PQ(J.fiber.getRef($J.CurrentLogAnnotations)),X=J.date.getTime();for(let[B,C]of J.fiber.getRef($J.CurrentLogSpans))Q[`logSpan.${B}`]=`${X-C}ms`;if(J.cause.reasons.length>0)Q.cause=_J.pretty(J.cause);let Y=typeof Q.service==="string"?Q.service:void 0;if(Y)delete Q.service;let $=Y?GJ.create({service:Y}):GJ.Default,G=qX(J.message);switch(J.logLevel){case"Trace":case"Debug":return $.debug(G,Q);case"Warn":return $.warn(G,Q);case"Error":case"Fatal":return $.error(G,Q);default:return $.info(G,Q)}}),qJ=R.layer([n],{mergeWithExisting:!1}),KQ=(J={})=>({debug:(Q,X)=>i((Y)=>I.logDebug(Y),J,Q,X),info:(Q,X)=>i((Y)=>I.logInfo(Y),J,Q,X),warn:(Q,X)=>i((Y)=>I.logWarning(Y),J,Q,X),error:(Q,X)=>i((Y)=>I.logError(Y),J,Q,X),with:(Q)=>KQ({...J,...Q})});var a=x.OTEL_EXPORTER_OTLP_ENDPOINT,OQ=!!a,BX=crypto.randomUUID(),TQ=x.OTEL_EXPORTER_OTLP_HEADERS?x.OTEL_EXPORTER_OTLP_HEADERS.split(",").reduce((J,Q)=>{let[X,...Y]=Q.split("=");return J[X]=Y.join("="),J},{}):void 0;function BJ(){let J=FQ("main"),Q=(()=>{let X=process.env.OTEL_RESOURCE_ATTRIBUTES;if(!X)return{};try{return Object.fromEntries(X.split(",").map((Y)=>{let $=Y.indexOf("=");if($<1)throw Error("Invalid OTEL_RESOURCE_ATTRIBUTES entry");return[decodeURIComponent(Y.slice(0,$)),decodeURIComponent(Y.slice($+1))]}))}catch{return{}}})();return{serviceName:"qitqode",serviceVersion:CQ,attributes:{...Q,"deployment.environment.name":DQ,"qitqode.client":x.QITQODE_CLIENT,"qitqode.process_role":J.processRole,"qitqode.run_id":J.runID,"service.instance.id":BX}}}function wX(){return R.layer([n,p.make({url:`${a}/v1/logs`,resource:BJ(),headers:TQ})],{mergeWithExisting:!1}).pipe(z.provide(c.layerJson),z.provide(AQ.layer))}var HX=async()=>{let J=await import("./chunk-n90eh3e7.js"),Q=await import("./chunk-as845ya4.js"),X=await import("./chunk-9jsgs71h.js"),{AsyncLocalStorageContextManager:Y}=await import("./chunk-r0s28gnb.js").then((m)=>zQ(m.default,1)),{context:$}=await import("./chunk-7nqdhe7x.js").then((m)=>zQ(m.default,1)),G=new Y;return G.enable(),$.setGlobalContextManager(G),J.layer(()=>({resource:BJ(),spanProcessor:new X.BatchSpanProcessor(new Q.OTLPTraceExporter({url:`${a}/v1/traces`,headers:TQ}))}))},EQ=!a?qJ:z.unwrap(I.gen(function*(){let J=yield*I.promise(HX);return z.mergeAll(J,wX())})),WX={enabled:OQ,layer:EQ};var aX=z.makeMemoMapUnsafe();
|
|
2
|
+
import{$q as dJ,Zq as mJ,_q as vJ,ar as lJ,dr as d,er as l,gr as uJ,hr as cJ,kr as pJ,lr as iJ,mr as nJ,nr as aJ,or as rJ,qr as AQ}from"./chunk-pfkm3j8g.js";import{Ts as FQ,us as CQ,vs as DQ}from"./chunk-xmjntwjc.js";import{et as x,nt as GJ}from"./chunk-7q003wdd.js";import{$F as MJ,AB as HJ,AF as t,AG as NJ,BE as zJ,BF as OJ,DB as WJ,DF as y,EI as gJ,FB as $Q,IC as IJ,KA as tJ,LC as PJ,LG as kJ,ME as ZJ,NB as f,OC as T,PG as LJ,QF as TJ,RC as KJ,SG as SJ,WE as z,WG as xJ,XD as qQ,XF as EJ,_G as fJ,aF as b,cE as _J,cF as CJ,cG as oJ,gG as RJ,hM as j,iG as VJ,jH as E,lG as hJ,mF as DJ,nF as FJ,oF as AJ,oH as yJ,pH as bJ,rE as BQ,sE as wQ,sO as g,tO as eJ,uC as GQ,uG as jJ,vE as $J,wE as UJ,wO as HQ,xB as wJ,xH as I,xO as WQ,yM as o,yO as R}from"./chunk-ks1cs80p.js";import{LO as zQ,NO as u,PO as S}from"./chunk-f83wv08n.js";var IX={};u(IX,{resource:()=>BJ,layer:()=>EQ,enabled:()=>OQ,Observability:()=>WX});var p={};u(p,{make:()=>IQ,layer:()=>ZX});var VQ=AJ.pipe(FJ,DJ((J)=>{if(lJ(J)&&J.reason._tag==="StatusCodeError"&&J.reason.response.status===429){let Q=HJ(J.reason.response.headers["retry-after"]).pipe(WJ(CJ),wJ(()=>5));return t(T(Q))}return t(T(1))})),sJ=E(function*(J){let Q=yield*jJ(),X=f(Q,b),Y=f(Q,UJ),$=fJ(Q),G=KJ(IJ(J.exportInterval),PJ),B=void 0,C=nJ(f(Q,pJ)).pipe(iJ(NJ(rJ,!1)),aJ({schedule:VQ,times:3})),V=vJ({"user-agent":`effect-opentelemetry-${J.label}/0.0.0`});if(J.headers)V=dJ(mJ(J.headers),V);let r=uJ(J.url,{headers:V}),O=[],s=OJ(()=>{if(B!==void 0&&X.currentTimeMillisUnsafe()<B)return y;else if(B!==void 0)B=void 0;let h=O;if(J.maxBatchSize!=="disabled"){if(O.length===0)return y;O=[]}return C.execute(cJ(r,J.body(h))).pipe(EJ,SJ(!1))}).pipe(MJ((h)=>{if(B!==void 0)return y;return B=X.currentTimeMillisUnsafe()+60000,O=[],yJ("Disabling exporter for 60 seconds",h)}),bJ({package:"@effect/opentelemetry",module:J.label}));return yield*zJ(Y,s.pipe(RJ,kJ,VJ(J.shutdownTimeout))),yield*hJ(G).pipe(TJ(s),LJ,xJ(Y)),{push(h){if(B!==void 0)return;if(O.push(h),J.maxBatchSize!=="disabled"&&O.length>=J.maxBatchSize)gJ($(s),Y)}}});var jQ=(J)=>{let Q=J.attributes?e(Object.entries(J.attributes)):[];if(Q.push({key:"service.name",value:{stringValue:J.serviceName}}),J.serviceVersion)Q.push({key:"service.version",value:{stringValue:J.serviceVersion}});return{attributes:Q,droppedAttributesCount:0}},JQ=E(function*(J){let Q={...yield*g(o(eJ(j,j)),"OTEL_RESOURCE_ATTRIBUTES"),...J?.attributes},X=J?.serviceName??Q["service.name"]??(yield*g(j,"OTEL_SERVICE_NAME"));delete Q["service.name"];let Y=J?.serviceVersion??Q["service.version"]??(yield*g(o(j),"OTEL_SERVICE_VERSION"));return delete Q["service.version"],jQ({serviceName:X,serviceVersion:Y,attributes:Q})},oJ),QQ=(J)=>{let Q=J.attributes.find((X)=>X.key==="service.name");if(!Q||!Q.value.stringValue)throw Error("Resource does not contain a service name");return Q.value.stringValue},e=(J)=>{let Q=[];for(let[X,Y]of J)Q.push({key:X,value:m(Y)});return Q},m=(J)=>{if(Array.isArray(J))return{arrayValue:{values:J.map(m)}};switch(typeof J){case"string":return{stringValue:J};case"bigint":return{intValue:Number(J)};case"number":return Number.isInteger(J)?{intValue:J}:{doubleValue:J};case"boolean":return{boolValue:J};default:return{stringValue:tJ(J)}}};var c={};u(c,{layerProtobuf:()=>YX,layerJson:()=>XX,OtlpSerialization:()=>M});var N={Varint:0,Fixed64:1,LengthDelimited:2,Fixed32:5},k=(J,Q)=>J<<3|Q,D=(J)=>{let Q=[],X=typeof J==="bigint"?J:BigInt(J);while(X>0x7fn)Q.push(Number(X&0x7fn)|128),X>>=7n;return Q.push(Number(X)),new Uint8Array(Q)};var kQ=(J)=>{let Q=new Uint8Array(8);return new DataView(Q.buffer).setBigUint64(0,J,!0),Q},LQ=(J)=>{let Q=new Uint8Array(4);return new DataView(Q.buffer).setUint32(0,J,!0),Q},SQ=(J)=>{let Q=new Uint8Array(8);return new DataView(Q.buffer).setFloat64(0,J,!0),Q},xQ=(J)=>new TextEncoder().encode(J),fQ=(J)=>{let Q=new Uint8Array(J.length/2);for(let X=0;X<J.length;X+=2)Q[X/2]=parseInt(J.slice(X,X+2),16);return Q},Z=(...J)=>{let Q=J.reduce(($,G)=>$+G.length,0),X=new Uint8Array(Q),Y=0;for(let $ of J)X.set($,Y),Y+=$.length;return X},q=(J,Q)=>Z(D(k(J,N.Varint)),D(Q));var JJ=(J,Q)=>q(J,Q?1:0),W=(J,Q)=>Z(D(k(J,N.Fixed64)),kQ(Q)),v=(J,Q)=>Z(D(k(J,N.Fixed32)),LQ(Q)),F=(J,Q)=>Z(D(k(J,N.Fixed64)),SQ(Q)),L=(J,Q)=>Z(D(k(J,N.LengthDelimited)),D(Q.length),Q),K=(J,Q)=>L(J,xQ(Q)),U=(J,Q)=>L(J,fQ(Q)),w=(J,Q)=>L(J,Q),_=(J,Q,X)=>Z(...Q.map((Y)=>w(J,X(Y))));var H=(J,Q)=>Q!==void 0&&Q!==""?K(J,Q):new Uint8Array(0);var QJ=(J)=>{if(J.stringValue!==void 0&&J.stringValue!==null)return K(1,J.stringValue);if(J.boolValue!==void 0&&J.boolValue!==null)return JJ(2,J.boolValue);if(J.intValue!==void 0&&J.intValue!==null)return q(3,BigInt(J.intValue));if(J.doubleValue!==void 0&&J.doubleValue!==null)return F(4,J.doubleValue);if(J.arrayValue!==void 0)return w(5,bQ(J.arrayValue));if(J.kvlistValue!==void 0)return w(6,gQ(J.kvlistValue));if(J.bytesValue!==void 0)return L(7,J.bytesValue);return new Uint8Array(0)},bQ=(J)=>_(1,J.values,QJ),gQ=(J)=>_(1,J.values,P),P=(J)=>Z(K(1,J.key),w(2,QJ(J.value))),XJ=(J)=>Z(K(1,J.name),H(2,J.version),J.attributes?_(3,J.attributes,P):new Uint8Array(0),J.droppedAttributesCount?q(4,J.droppedAttributesCount):new Uint8Array(0)),YJ=(J)=>Z(_(1,J.attributes,P),J.droppedAttributesCount>0?q(2,J.droppedAttributesCount):new Uint8Array(0));var mQ=(J)=>Z(H(2,J.message),q(3,J.code)),vQ=(J)=>Z(W(1,BigInt(J.timeUnixNano)),K(2,J.name),_(3,J.attributes,P),J.droppedAttributesCount>0?q(4,J.droppedAttributesCount):new Uint8Array(0)),dQ=(J)=>Z(U(1,J.traceId),U(2,J.spanId),H(3,J.traceState),_(4,J.attributes,P),J.droppedAttributesCount>0?q(5,J.droppedAttributesCount):new Uint8Array(0),J.flags!==void 0?v(6,J.flags):new Uint8Array(0)),lQ=(J)=>Z(U(1,J.traceId),U(2,J.spanId),H(3,J.traceState),J.parentSpanId!==void 0?U(4,J.parentSpanId):new Uint8Array(0),K(5,J.name),q(6,J.kind),W(7,BigInt(J.startTimeUnixNano)),W(8,BigInt(J.endTimeUnixNano)),_(9,J.attributes,P),J.droppedAttributesCount>0?q(10,J.droppedAttributesCount):new Uint8Array(0),_(11,J.events,vQ),J.droppedEventsCount>0?q(12,J.droppedEventsCount):new Uint8Array(0),_(13,J.links,dQ),J.droppedLinksCount>0?q(14,J.droppedLinksCount):new Uint8Array(0),w(15,mQ(J.status)),J.flags!==void 0?v(16,J.flags):new Uint8Array(0)),uQ=(J)=>Z(w(1,XJ(J.scope)),_(2,J.spans,lQ),H(3,J.schemaUrl)),cQ=(J)=>Z(w(1,YJ(J.resource)),_(2,J.scopeSpans,uQ),H(3,J.schemaUrl)),XQ=(J)=>_(1,J.resourceSpans,cQ);var YQ=(J)=>Z(W(2,BigInt(J.startTimeUnixNano)),W(3,BigInt(J.timeUnixNano)),J.asDouble!==void 0?F(4,J.asDouble):new Uint8Array(0),J.asInt!==void 0?W(6,BigInt(J.asInt)):new Uint8Array(0),_(7,J.attributes,P),J.flags!==void 0?q(8,J.flags):new Uint8Array(0)),pQ=(J)=>{let Q=Z(...J.bucketCounts.map((Y)=>W(6,BigInt(Y)))),X=Z(...J.explicitBounds.map((Y)=>F(7,Y)));return Z(W(2,BigInt(J.startTimeUnixNano)),W(3,BigInt(J.timeUnixNano)),W(4,BigInt(J.count)),J.sum!==void 0?F(5,J.sum):new Uint8Array(0),Q,X,_(9,J.attributes,P),J.flags!==void 0?q(10,J.flags):new Uint8Array(0),J.min!==void 0?F(11,J.min):new Uint8Array(0),J.max!==void 0?F(12,J.max):new Uint8Array(0))},iQ=(J)=>_(1,J.dataPoints,YQ),nQ=(J)=>Z(_(1,J.dataPoints,YQ),q(2,J.aggregationTemporality),JJ(3,J.isMonotonic)),aQ=(J)=>Z(_(1,J.dataPoints,pQ),q(2,J.aggregationTemporality)),rQ=(J)=>Z(K(1,J.name),H(2,J.description),H(3,J.unit),J.gauge!==void 0?w(5,iQ(J.gauge)):new Uint8Array(0),J.sum!==void 0?w(7,nQ(J.sum)):new Uint8Array(0),J.histogram!==void 0?w(9,aQ(J.histogram)):new Uint8Array(0)),sQ=(J)=>Z(w(1,XJ(J.scope)),_(2,J.metrics,rQ),H(3,J.schemaUrl)),tQ=(J)=>Z(w(1,YJ(J.resource)),_(2,J.scopeMetrics,sQ),H(3,J.schemaUrl)),ZQ=(J)=>_(1,J.resourceMetrics,tQ);var oQ=(J)=>Z(W(1,BigInt(J.timeUnixNano)),J.severityNumber!==void 0?q(2,J.severityNumber):new Uint8Array(0),H(3,J.severityText),J.body!==void 0?w(5,QJ(J.body)):new Uint8Array(0),_(6,J.attributes,P),J.droppedAttributesCount!==void 0&&J.droppedAttributesCount>0?q(7,J.droppedAttributesCount):new Uint8Array(0),J.flags!==void 0?v(8,J.flags):new Uint8Array(0),J.traceId!==void 0&&J.traceId!==""?U(9,J.traceId):new Uint8Array(0),J.spanId!==void 0&&J.spanId!==""?U(10,J.spanId):new Uint8Array(0),J.observedTimeUnixNano!==void 0?W(11,BigInt(J.observedTimeUnixNano)):new Uint8Array(0)),eQ=(J)=>Z(w(1,XJ(J.scope)),_(2,J.logRecords,oQ),H(3,J.schemaUrl)),JX=(J)=>Z(w(1,YJ(J.resource)),_(2,J.scopeLogs,eQ),H(3,J.schemaUrl)),_Q=(J)=>_(1,J.resourceLogs,JX);class M extends $Q()("effect/observability/OtlpSerialization"){}var XX=ZJ(M,{traces:(J)=>l(J),metrics:(J)=>l(J),logs:(J)=>l(J)}),YX=ZJ(M,{traces:(J)=>d(XQ(J),"application/x-protobuf"),metrics:(J)=>d(ZQ(J),"application/x-protobuf"),logs:(J)=>d(_Q(J),"application/x-protobuf")});var IQ=E(function*(J){let Q=yield*M,X=yield*JQ(J.resource),Y={name:QQ(X)},$=yield*sJ({label:"OtlpLogger",url:J.url,headers:J.headers,maxBatchSize:J.maxBatchSize??1000,exportInterval:J.exportInterval??T(1),body:(B)=>Q.logs({resourceLogs:[{resource:X,scopeLogs:[{scope:Y,logRecords:B}]}]}),shutdownTimeout:J.shutdownTimeout??T(3)}),G={excludeLogSpans:J.excludeLogSpans??!1,clock:yield*b};return HQ((B)=>{$.push(_X(B,G))})}),ZX=(J)=>WQ([IQ(J)],{mergeWithExisting:J.mergeWithExisting??!0}),_X=(J,Q)=>{let Y=Q.clock.currentTimeNanosUnsafe().toString(),$=J.date.getTime(),G=e(Object.entries(J.fiber.getRef(BQ)));if(G.push({key:"fiberId",value:{intValue:J.fiber.id}}),!Q.excludeLogSpans)for(let[V,r]of J.fiber.getRef(wQ))G.push({key:`logSpan.${V}`,value:{stringValue:`${$-r}ms`}});if(J.cause.reasons.length>0)G.push({key:"log.error",value:{stringValue:qQ(J.cause)}});let B=GQ(J.message),C={severityNumber:$X(J.logLevel),severityText:J.logLevel,timeUnixNano:Y,observedTimeUnixNano:Y,attributes:G,body:m(B.length===1?B[0]:B),droppedAttributesCount:0};if(J.fiber.currentSpan)C.traceId=J.fiber.currentSpan.traceId,C.spanId=J.fiber.currentSpan.spanId;return C},$X=(J)=>{switch(J){case"Trace":return A.SEVERITY_NUMBER_TRACE;case"Debug":return A.SEVERITY_NUMBER_DEBUG;case"Info":return A.SEVERITY_NUMBER_INFO;case"Warn":return A.SEVERITY_NUMBER_WARN;case"Error":return A.SEVERITY_NUMBER_ERROR;case"Fatal":return A.SEVERITY_NUMBER_FATAL;default:return A.SEVERITY_NUMBER_UNSPECIFIED}},A={SEVERITY_NUMBER_UNSPECIFIED:0,SEVERITY_NUMBER_TRACE:1,SEVERITY_NUMBER_TRACE2:2,SEVERITY_NUMBER_TRACE3:3,SEVERITY_NUMBER_TRACE4:4,SEVERITY_NUMBER_DEBUG:5,SEVERITY_NUMBER_DEBUG2:6,SEVERITY_NUMBER_DEBUG3:7,SEVERITY_NUMBER_DEBUG4:8,SEVERITY_NUMBER_INFO:9,SEVERITY_NUMBER_INFO2:10,SEVERITY_NUMBER_INFO3:11,SEVERITY_NUMBER_INFO4:12,SEVERITY_NUMBER_WARN:13,SEVERITY_NUMBER_WARN2:14,SEVERITY_NUMBER_WARN3:15,SEVERITY_NUMBER_WARN4:16,SEVERITY_NUMBER_ERROR:17,SEVERITY_NUMBER_ERROR2:18,SEVERITY_NUMBER_ERROR3:19,SEVERITY_NUMBER_ERROR4:20,SEVERITY_NUMBER_FATAL:21,SEVERITY_NUMBER_FATAL2:22,SEVERITY_NUMBER_FATAL3:23,SEVERITY_NUMBER_FATAL4:24};var UQ={};u(UQ,{logger:()=>n,layer:()=>qJ,create:()=>KQ});var GX=(J)=>J==="sessionID"?"session.id":J,PQ=(J)=>Object.fromEntries(Object.entries(J??{}).filter((Q)=>Q[1]!==void 0&&Q[1]!==null).map(([Q,X])=>[GX(Q),X])),qX=(J)=>{if(Array.isArray(J))return J.map((Q)=>String(Q)).join(" ");return J===void 0?"":String(J)},i=(J,Q,X,Y)=>{let $=PQ({...Q,...Y}),G=J(X);return Object.keys($).length?I.annotateLogs(G,$):G},n=R.make((J)=>{let Q=PQ(J.fiber.getRef($J.CurrentLogAnnotations)),X=J.date.getTime();for(let[B,C]of J.fiber.getRef($J.CurrentLogSpans))Q[`logSpan.${B}`]=`${X-C}ms`;if(J.cause.reasons.length>0)Q.cause=_J.pretty(J.cause);let Y=typeof Q.service==="string"?Q.service:void 0;if(Y)delete Q.service;let $=Y?GJ.create({service:Y}):GJ.Default,G=qX(J.message);switch(J.logLevel){case"Trace":case"Debug":return $.debug(G,Q);case"Warn":return $.warn(G,Q);case"Error":case"Fatal":return $.error(G,Q);default:return $.info(G,Q)}}),qJ=R.layer([n],{mergeWithExisting:!1}),KQ=(J={})=>({debug:(Q,X)=>i((Y)=>I.logDebug(Y),J,Q,X),info:(Q,X)=>i((Y)=>I.logInfo(Y),J,Q,X),warn:(Q,X)=>i((Y)=>I.logWarning(Y),J,Q,X),error:(Q,X)=>i((Y)=>I.logError(Y),J,Q,X),with:(Q)=>KQ({...J,...Q})});var a=x.OTEL_EXPORTER_OTLP_ENDPOINT,OQ=!!a,BX=crypto.randomUUID(),TQ=x.OTEL_EXPORTER_OTLP_HEADERS?x.OTEL_EXPORTER_OTLP_HEADERS.split(",").reduce((J,Q)=>{let[X,...Y]=Q.split("=");return J[X]=Y.join("="),J},{}):void 0;function BJ(){let J=FQ("main"),Q=(()=>{let X=process.env.OTEL_RESOURCE_ATTRIBUTES;if(!X)return{};try{return Object.fromEntries(X.split(",").map((Y)=>{let $=Y.indexOf("=");if($<1)throw Error("Invalid OTEL_RESOURCE_ATTRIBUTES entry");return[decodeURIComponent(Y.slice(0,$)),decodeURIComponent(Y.slice($+1))]}))}catch{return{}}})();return{serviceName:"qitqode",serviceVersion:CQ,attributes:{...Q,"deployment.environment.name":DQ,"qitqode.client":x.QITQODE_CLIENT,"qitqode.process_role":J.processRole,"qitqode.run_id":J.runID,"service.instance.id":BX}}}function wX(){return R.layer([n,p.make({url:`${a}/v1/logs`,resource:BJ(),headers:TQ})],{mergeWithExisting:!1}).pipe(z.provide(c.layerJson),z.provide(AQ.layer))}var HX=async()=>{let J=await import("./chunk-n90eh3e7.js"),Q=await import("./chunk-as845ya4.js"),X=await import("./chunk-9jsgs71h.js"),{AsyncLocalStorageContextManager:Y}=await import("./chunk-r0s28gnb.js").then((m)=>zQ(m.default,1)),{context:$}=await import("./chunk-7nqdhe7x.js").then((m)=>zQ(m.default,1)),G=new Y;return G.enable(),$.setGlobalContextManager(G),J.layer(()=>({resource:BJ(),spanProcessor:new X.BatchSpanProcessor(new Q.OTLPTraceExporter({url:`${a}/v1/traces`,headers:TQ}))}))},EQ=!a?qJ:z.unwrap(I.gen(function*(){let J=yield*I.promise(HX);return z.mergeAll(J,wX())})),WX={enabled:OQ,layer:EQ};var aX=z.makeMemoMapUnsafe();
|
|
3
3
|
export{qJ as Tq,UQ as Uq,EQ as Vq,WX as Wq,IX as Xq,aX as Yq};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{Vo as z}from"./chunk-
|
|
2
|
+
import{Vo as z}from"./chunk-8d6e4jg7.js";class B extends Error{cause;constructor(q,x){super(q);this.name="QreditChargeError",this.cause=x}}async function E(q){return z(q)}function F(q){if(q===void 0)return"\u2014";if(q===0)return"0";let x=q<0?"-":"",j=Math.abs(q);if(j<0.001)return x+j.toFixed(6);if(j<0.01)return x+j.toFixed(4);if(j<0.1)return x+j.toFixed(3);if(j<1)return x+j.toFixed(2);return x+(Number.isInteger(j)?String(j):j.toFixed(2))}
|
|
3
3
|
export{B as F,E as G,F as H};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{Ed as j}from"./chunk-
|
|
2
|
+
import{Ed as j}from"./chunk-0yjdatm6.js";import{Rd as Q}from"./chunk-yajd975f.js";import{Uf as M}from"./chunk-t1jgx17a.js";import{ng as N}from"./chunk-et5dnymk.js";import{Zg as $}from"./chunk-wcx7hc2p.js";import"./chunk-ehfxypks.js";import"./chunk-9rxyq6f9.js";import"./chunk-5az84brc.js";import"./chunk-94qhpkfx.js";import"./chunk-c1g8n10t.js";import"./chunk-a2dz9nqh.js";import"./chunk-vhe92p7a.js";import{bk as J,tl as X}from"./chunk-a550vst5.js";import"./chunk-e374shb8.js";import"./chunk-zcp0wx4j.js";import"./chunk-epa576pa.js";import"./chunk-y287zwkr.js";import"./chunk-7zc04q43.js";import"./chunk-vtw0wwch.js";import"./chunk-rk2bk4s7.js";import"./chunk-e586sjb0.js";import"./chunk-b50t4jc5.js";import{fo as _}from"./chunk-zdzxsyxs.js";import"./chunk-xny5ecn0.js";import"./chunk-8d6e4jg7.js";import"./chunk-my3cswnp.js";import"./chunk-4mvg7jt1.js";import"./chunk-cqtkxwd8.js";import"./chunk-wf4x5cjc.js";import"./chunk-mswx4k75.js";import"./chunk-vqpfpmha.js";import"./chunk-vm1ek7yf.js";import"./chunk-fd7fmvyw.js";import"./chunk-1sfcxdbw.js";import"./chunk-bgng3rdj.js";import"./chunk-s77qktcn.js";import"./chunk-8v6x712g.js";import"./chunk-pfkm3j8g.js";import{Vr as Z}from"./chunk-h2bmss2m.js";import{cs as E}from"./chunk-ywdtp534.js";import"./chunk-03mbn7nj.js";import"./chunk-gr4bctqj.js";import"./chunk-732yr6qq.js";import"./chunk-73fz0cf4.js";import"./chunk-0cdtq1r3.js";import"./chunk-xmjntwjc.js";import"./chunk-tj3rem3q.js";import{et as Y}from"./chunk-7q003wdd.js";import{yt as V}from"./chunk-cbmwhvxw.js";import"./chunk-9etpppyv.js";import"./chunk-9ea1n338.js";import"./chunk-ngvp6zc2.js";import"./chunk-1p6jjrea.js";import"./chunk-ks1cs80p.js";import"./chunk-a92hh67a.js";import"./chunk-qhnpq5gb.js";import"./chunk-f83wv08n.js";import{EOL as L}from"os";import k from"path";function P(){let q=["-R","-S"];if(process.platform!=="win32")return["less",...q];let z=_("less");if(z){if(V.stat(z)?.size)return[z,...q]}if(Y.QITQODE_GIT_BASH_PATH){let G=k.join(Y.QITQODE_GIT_BASH_PATH,"..","..","usr","bin","less.exe");if(V.stat(G)?.size)return[G,...q]}let B=_("git");if(B){let G=k.join(B,"..","..","usr","bin","less.exe");if(V.stat(G)?.size)return[G,...q]}return["cmd","/c","more"]}var g=Q({command:"session",describe:"manage sessions",builder:(q)=>q.command(T).command(D).command(v).demandCommand(),async handler(){}}),v=Q({command:"import-claude",describe:"import Claude Code sessions (~/.claude/projects) into qitqode",builder:(q)=>q.option("force",{describe:"re-sync every session, ignoring the mtime cache",type:"boolean",default:!1}),handler:async(q)=>{let z=await N.run({force:q.force});M.println(`Claude import: scanned ${z.scanned}, imported ${z.imported}, resynced ${z.resynced}, skipped ${z.skipped}`+(z.errors.length?`, errors ${z.errors.length}`:""));for(let B of z.errors)M.error(B)}}),D=Q({command:"delete <sessionID>",describe:"delete a session",builder:(q)=>{return q.positional("sessionID",{describe:"session ID to delete",type:"string",demandOption:!0})},handler:async(q)=>{await j(process.cwd(),async()=>{let z=J.make(q.sessionID);try{await $.runPromise(X.Service.use((B)=>B.get(z)))}catch{M.error(`Session not found: ${q.sessionID}`),process.exit(1)}await $.runPromise(X.Service.use((B)=>B.remove(z))),M.println(M.Style.TEXT_SUCCESS_BOLD+`Session ${q.sessionID} deleted`+M.Style.TEXT_NORMAL)})}}),T=Q({command:"list",describe:"list sessions",builder:(q)=>{return q.option("max-count",{alias:"n",describe:"limit to N most recent sessions",type:"number"}).option("format",{describe:"output format",type:"string",choices:["table","json"],default:"table"})},handler:async(q)=>{await j(process.cwd(),async()=>{let z=[...X.list({roots:!0,limit:q.maxCount})];if(z.length===0)return;let B;if(q.format==="json")B=f(z);else B=b(z);if(process.stdout.isTTY&&!q.maxCount&&q.format==="table"){let H=E.spawn(P(),{stdin:"pipe",stdout:"inherit",stderr:"inherit"});if(!H.stdin){console.log(B);return}H.stdin.write(B),H.stdin.end(),await H.exited}else console.log(B)})}});function b(q){let z=[],B=Math.max(20,...q.map((K)=>K.id.length)),G=Math.max(25,...q.map((K)=>K.title.length)),H=`Session ID${" ".repeat(B-10)} Title${" ".repeat(G-5)} Updated`;z.push(H),z.push("\u2500".repeat(H.length));for(let K of q){let A=Z.truncate(K.title,G),R=Z.todayTimeOrDateTime(K.time.updated),w=`${K.id.padEnd(B)} ${A.padEnd(G)} ${R}`;z.push(w)}return z.join(L)}function f(q){let z=q.map((B)=>({id:B.id,title:B.title,updated:B.time.updated,created:B.time.created,projectId:B.projectID,directory:B.directory}));return JSON.stringify(z,null,2)}export{T as SessionListCommand,v as SessionImportClaudeCommand,D as SessionDeleteCommand,g as SessionCommand};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{An as j,Bn as R,Cn as O,Dn as A,Jn as y,On as q,Pn as M,Rn as C,Xn as K}from"./chunk-
|
|
2
|
+
import{An as j,Bn as R,Cn as O,Dn as A,Jn as y,On as q,Pn as M,Rn as C,Xn as K}from"./chunk-vtw0wwch.js";import{cs as D}from"./chunk-ywdtp534.js";import{Vs as m,Ys as v}from"./chunk-tj3rem3q.js";import{At as b,Dt as I,yt as d}from"./chunk-cbmwhvxw.js";import{QO as T,RO as _}from"./chunk-f83wv08n.js";import P from"path";function pt(t){let e=t&&typeof t==="object"&&"cause"in t?t.cause??t:t;if(!(e instanceof D.RunFailedError))return{error:e,detail:v(e),missing:!1};let r=e.stderr.toString().split(/\r?\n/).map((o)=>o.trim()).filter(Boolean),n=r.filter((o)=>o.startsWith("error:")).map((o)=>o.replace(/^error:\s*/,""));return{error:e,detail:n[0]??r.at(-1),missing:r.some((o)=>o.includes("No version matching"))}}var $={resolve:(t)=>q(t)},z={readText:(t)=>d.readText(t),write:async(t,e)=>{await d.write(t,e)},exists:(t)=>d.exists(t),files:(t,e)=>K(t,e)},G=z;function V(t){if(typeof t==="string")return t;if(!Array.isArray(t))return;if(typeof t[0]!=="string")return;return t[0]}function H(t){if(!t||typeof t!=="object"||Array.isArray(t))return;let e=t;if(!Array.isArray(e.plugin))return;return e.plugin}function Q(t){if(typeof t==="string"){let e=t.trim();if(e)return e;return}if(!m(t))return;for(let e of["import","default"]){let r=t[e];if(typeof r!=="string")continue;let n=r.trim();if(!n)continue;return n}}function U(t){if(!m(t))return;let e=t.config;if(!m(e))return;return e}function E(t,e){let r=t.exports;if(!m(r))return;let n=r[`./${e}`];if(!Q(n))return;return{opts:U(n)}}function X(t){let e=t.main;if(typeof e!=="string")return!1;return Boolean(e.trim())}function Y(t){let e=typeof t.json.name==="string"&&t.json.name.trim().length>0?t.json.name.trim():P.basename(t.dir),r=[],n=E(t.json,"server");if(n)r.push({kind:"server",opts:n.opts});else if(X(t.json))r.push({kind:"server"});let o=E(t.json,"tui");if(o)r.push({kind:"tui",opts:o.opts});if(!r.some((c)=>c.kind==="tui")&&C(e,t).length)r.push({kind:"tui"});return r}function g(t,e,r,n=!1){return A(t,O(t,e,r,{formattingOptions:{tabSize:2,insertSpaces:!0},isArrayInsertion:n}))}function Z(t,e,r,n,o=!1){let c=y(r).pkg,u=(e??[]).map((i,p)=>({item:i,i:p,spec:V(i)})).filter((i)=>{if(!i.spec)return!1;if(i.spec===r)return!0;if(i.spec.startsWith("file://"))return!1;return y(i.spec).pkg===c});if(!u.length){if(!e)return{mode:"add",text:g(t,["plugin"],[n])};return{mode:"add",text:g(t,["plugin",e.length],n,!0)}}if(!o)return{mode:"noop",text:t};let s=u[0];if(!s)return{mode:"noop",text:t};if(u.length===1&&s.spec===r)return{mode:"noop",text:t};let a=t;if(typeof s.item==="string")a=g(a,["plugin",s.i],n);if(Array.isArray(s.item)&&typeof s.item[0]==="string")a=g(a,["plugin",s.i,0],r);let l=u.map((i)=>i.i).filter((i)=>i!==s.i).sort((i,p)=>p-i);for(let i of l)a=g(a,["plugin",i],void 0);return{mode:"replace",text:a}}async function gt(t,e=$){let r=await e.resolve(t).then((n)=>({ok:!0,item:n}),(n)=>({ok:!1,error:n}));if(!r.ok)return{ok:!1,code:"install_failed",error:r.error};return{ok:!0,target:r.item}}async function dt(t){let e=await M(t).then((n)=>({ok:!0,item:n}),(n)=>({ok:!1,error:n}));if(!e.ok)return{ok:!1,code:"manifest_read_failed",file:t,error:e.error};let r=await Promise.resolve().then(()=>Y(e.item)).then((n)=>({ok:!0,item:n}),(n)=>({ok:!1,error:n}));if(!r.ok)return{ok:!1,code:"manifest_read_failed",file:e.item.pkg,error:r.error};if(!r.item.length)return{ok:!1,code:"manifest_no_targets",file:e.item.pkg};return{ok:!0,targets:r.item}}function tt(t){if(t.global)return t.config??I.Path.config;let r=t.vcs==="git"&&t.worktree!=="/"?t.worktree:t.directory;return P.join(r,".qitqode")}function et(t){if(t==="server")return"qitqode";return"tui"}async function rt(t,e,r,n,o){let x=[];try{let c=et(e.kind);const S=T(x,await b.acquire(`plug-config:${d.resolve(P.join(t,c))}`),1);let u=o.files(t,c);let s=u[0];for(let f of u){if(!await o.exists(f))continue;s=f;break}let a=await o.readText(s).catch((f)=>{if(f.code==="ENOENT")return"{}";return f});if(a instanceof Error)return{ok:!1,code:"patch_failed",kind:e.kind,error:a};let l=a.trim()?a:"{}";let i=[];let p=j(l,i,{allowTrailingComma:!0});if(i.length){let f=i[0],h=l.substring(0,f.offset).split(`
|
|
3
3
|
`);return{ok:!1,code:"invalid_json",kind:e.kind,file:s,line:h.length,col:h[h.length-1].length+1,parse:R(f.error)}}let N=H(p);let F=e.opts?[r,e.opts]:r;let k=Z(l,N,r,F,n);if(k.mode==="noop")return{ok:!0,item:{kind:e.kind,mode:k.mode,file:s}};let w=await o.write(s,k.text).catch((f)=>f);if(w instanceof Error)return{ok:!1,code:"patch_failed",kind:e.kind,error:w};return{ok:!0,item:{kind:e.kind,mode:k.mode,file:s}}}catch(J){var B=J,L=1}finally{var W=_(x,B,L);W&&await W}}async function mt(t,e=G){let r=tt(t),n=[];for(let o of t.targets){let c=await rt(r,o,t.spec,Boolean(t.force),e);if(!c.ok)return{...c,dir:r};n.push(c.item)}return{ok:!0,dir:r,items:n}}
|
|
4
4
|
export{pt as p,z as q,gt as r,dt as s,mt as t};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{A as g,u as a,v as b,w as c,x as d,y as e,z as f}from"./chunk-
|
|
2
|
+
import{A as g,u as a,v as b,w as c,x as d,y as e,z as f}from"./chunk-sjreby6e.js";import"./chunk-7zc04q43.js";import"./chunk-vtw0wwch.js";import"./chunk-rk2bk4s7.js";import"./chunk-e586sjb0.js";import"./chunk-8v6x712g.js";import"./chunk-pfkm3j8g.js";import"./chunk-h2bmss2m.js";import"./chunk-ywdtp534.js";import"./chunk-03mbn7nj.js";import"./chunk-gr4bctqj.js";import"./chunk-73fz0cf4.js";import"./chunk-xmjntwjc.js";import"./chunk-tj3rem3q.js";import"./chunk-7q003wdd.js";import"./chunk-cbmwhvxw.js";import"./chunk-9etpppyv.js";import"./chunk-9ea1n338.js";import"./chunk-ngvp6zc2.js";import"./chunk-1p6jjrea.js";import"./chunk-ks1cs80p.js";import"./chunk-f83wv08n.js";export{e as waitForDependencies,c as layer,f as get,d as defaultLayer,g as TuiConfig,b as Service,a as Info};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{of as qH}from"./chunk-mxhb5adq.js";import{Oo as SH,so as QH,wo as KH}from"./chunk-8d6e4jg7.js";import"./chunk-my3cswnp.js";import"./chunk-4mvg7jt1.js";import"./chunk-cqtkxwd8.js";import"./chunk-wf4x5cjc.js";import"./chunk-h2bmss2m.js";import"./chunk-ywdtp534.js";import"./chunk-03mbn7nj.js";import{ts as Q}from"./chunk-0cdtq1r3.js";import"./chunk-xmjntwjc.js";import{Xs as OH}from"./chunk-tj3rem3q.js";import{et as t,mt as FH}from"./chunk-7q003wdd.js";import{At as PH,Dt as _H}from"./chunk-cbmwhvxw.js";import"./chunk-9etpppyv.js";import"./chunk-9ea1n338.js";import"./chunk-ngvp6zc2.js";import"./chunk-1p6jjrea.js";import"./chunk-ks1cs80p.js";import"./chunk-f83wv08n.js";var vH=0.9,fH=256,XH="[Earlier tool result removed to fit the request size limit]",m;function v(H){return Buffer.byteLength(JSON.stringify(H),"utf8")}function DH(){return t.QITQODE_QLEX_MAX_REQUEST_BYTES??m}function e(H){let J=t.QITQODE_QLEX_MAX_REQUEST_BYTES;if(J!==void 0)return J;let K=Math.max(1,Math.min(Math.floor(H*vH),Math.floor(H)-1));return m=m===void 0?K:Math.min(m,K),m}function l(H,J){return!!H&&typeof H==="object"&&H.role===J}function YH(H){let J=[],K=0;while(K<H.length){let Z=K,$=H[K];if(K++,l($,"assistant")&&Array.isArray($?.tool_calls)&&$.tool_calls.length>0)while(K<H.length&&l(H[K],"tool"))K++;J.push({start:Z,end:K})}return J}function VH(H,J){if(J.length===0)return[];let K=-1;for(let Z=J.length-1;Z>=0;Z--){let $=J[Z],z=!1;for(let X=$.start;X<$.end;X++)if(l(H[X],"user"))z=!0;if(z){K=Z;break}}return J.filter((Z,$)=>{if($===J.length-1)return!1;if($===K)return!1;if(Z.start===0&&l(H[0],"system"))return!1;return!0})}function HH(H,J){let K=v(H),Z={toolResultsElided:0,unitsDropped:0},$=()=>({body:H,bytes:K,originalBytes:K,reduced:!1,actions:Z});if(!H||typeof H!=="object")return $();let z=H.messages;if(!Array.isArray(z))return $();let X=z.map((U)=>U&&typeof U==="object"?{...U}:U),Y=()=>({...H,messages:X}),V=()=>v(Y())<=J;{let U=X;for(let P of VH(U,YH(U))){let S=!1;for(let L=P.start;L<P.end;L++){let E=U[L];if(!l(E,"tool"))continue;let w=E?.content;if(typeof w!=="string"||w.length<fH)continue;if(w===XH)continue;U[L]={...E,content:XH},Z.toolResultsElided++,S=!0}if(S&&V())break}}if(!V())for(;;){let U=X,S=VH(U,YH(U))[0];if(!S)break;if(X=[...U.slice(0,S.start),...U.slice(S.end)],Z.unitsDropped++,V())break}let W=Y(),G=v(W);return{body:W,bytes:G,originalBytes:K,reduced:G<K&&G<=J,actions:Z}}import y from"fs/promises";import LH from"path";import{randomUUID as yH}from"crypto";var k=FH({service:"provider.qlex"}),pH=Q.streamUrl(),uH=Q.omniqueryBaseUrl()+"/runOrchestrated";function b(H,J){let K=H;if(J.status!==void 0)K.status=J.status;if(J.upstreamCode!==void 0)K.upstreamCode=J.upstreamCode;if(J.requestId!==void 0)K.requestId=J.requestId;if(K.category=J.category,K.retryable=J.retryable,J.outputBudgetRecoveryAvailable!==void 0)K.outputBudgetRecoveryAvailable=J.outputBudgetRecoveryAvailable;if(J.outputBudgetRecoveryTokens!==void 0)K.outputBudgetRecoveryTokens=J.outputBudgetRecoveryTokens}function x(H,J){return{...H,...J}}class MH extends Error{name="QlexNotLoggedInError";constructor(H){super(Q.copy().notLoggedIn);b(this,x({category:"invalid_credentials",retryable:!1},H))}}class kH extends Error{name="QlexInsufficientBalanceError";constructor(H,J){super(Q.copy().insufficientBalance(H));b(this,x({status:402,category:"billing",retryable:!1},J))}}class EH extends Error{name="QlexRateLimitError";constructor(H){super(Q.copy().rateLimit);b(this,x({status:429,category:"rate_limited",retryable:!0},H))}}class wH extends Error{name="QlexInvalidCredentialsError";constructor(H,J){super(Q.copy().invalidCredentials(H));b(this,x({status:401,category:"invalid_credentials",retryable:!1},J))}}class RH extends Error{name="QlexRequestRejectedError";constructor(H,J,K){super(Q.copy().requestRejected(H,J));b(this,x({status:400,category:"request_rejected",retryable:!1},K))}}class a extends Error{name="QlexRequestTooLargeError";stage;constructor(H="irreducible",J,K){super(H==="after-reduction"?Q.copy().requestTooLargeAfterReduction(J):Q.copy().requestTooLargeIrreducible(J));this.stage=H,b(this,x({status:413,category:"request_too_large",retryable:!1},K))}}class CH extends Error{name="QlexRequestNotSentError";constructor(H,J){super(Q.copy().requestNotSent(H));b(this,x({category:"request_rejected",retryable:!1},J))}}class u extends Error{name="QlexGatewayError";constructor(H,J){super(Q.copy().gatewayUnavailable(H));b(this,x({category:"gateway_routing",retryable:!1},J))}}var cH=60000,mH=180000;function lJ(H){return Q.sanitizeUpstreamError(H)}class g extends Error{name="QlexStreamError";constructor(H,J,K){let Z=x({category:"unknown",retryable:!1},J);super(Z.category==="output_budget_exhausted"?Q.copy().outputBudgetExhausted():Z.category==="empty_output"?Q.copy().emptyOutput():Z.category==="stream_truncated"?Q.copy().streamCutOff(K):Z.category==="stream_failed"?Q.copy().streamFailedAfterRetries(K):Q.copy().streamFailed(H));b(this,Z),OH(this)}}var lH=[{match:/\b(unauthori[sz]ed|forbidden|invalid[ _-]?(api[ _-]?key|token|credential)|expired[ _-]?token|authentication[ _-]?(failed|error)|401|403)\b/i,category:"invalid_credentials",retryable:!1},{match:/(output (?:token )?budget|maximum output tokens|max_tokens|finish[_ -]?reason.{0,20}(length|budget)|reasoning.{0,20}(budget|tokens))/i,category:"output_budget_exhausted",retryable:!1},{match:/\b(no visible output|empty output|produced no (?:visible )?(?:text|output)|nothing to display)\b/i,category:"empty_output",retryable:!1},{match:/\b(insufficient[ _-]?(credits?|qredits?|balance|funds)|payment[ _-]?required|quota[ _-]?exceeded|out[ _-]?of[ _-]?(credits?|qredits?)|402)\b/i,category:"billing",retryable:!1},{match:/\b(rate[ _-]?limit(ed|s)?|too[ _-]?many[ _-]?requests|429)\b/i,category:"rate_limited",retryable:!0},{match:/(unexpected end of (json|input|stream|data)|premature (close|end)|socket hang ?up|incomplete (response|output|json|message)|truncated|stream (ended|closed|terminated) (early|unexpectedly|prematurely)|\bECONNRESET\b|\bEPIPE\b)/i,category:"stream_truncated",retryable:!0},{match:/\b(overloaded|at capacity|service[ _-]?unavailable|temporarily[ _-]?unavailable|bad[ _-]?gateway|gateway[ _-]?time(d[ _-]?out|out)|timed[ _-]?out|502|503|504)\b/i,category:"transient",retryable:!0}],dH={ERR_EMPTY_RESULT:{category:"empty_output",retryable:!1},ERR_TRUNCATED_OUTPUT:{category:"stream_truncated",retryable:!0},ERR_STREAM:{category:"stream_failed",retryable:!0}},nH=/^\s*(ERR_[A-Z0-9_]+)\b(?:\s*(?:[\u2014\u2013:-]\s*)?)?/i,iH=/\b(req_[A-Za-z0-9][A-Za-z0-9_-]*)\b/;function rH(H){let J=H??"",K=nH.exec(J),Z=K?.[1]?.toUpperCase(),$=iH.exec(J)?.[1],z=K?J.slice(K[0].length):J;if(Z!==void 0){let X=dH[Z];if(X!==void 0)return{...X,upstreamCode:Z,...$?{requestId:$}:{}}}for(let X of lH)if(X.match.test(z))return{category:X.category,retryable:X.retryable,...Z?{upstreamCode:Z}:{},...$?{requestId:$}:{}};return{category:"unknown",retryable:!1,...Z?{upstreamCode:Z}:{},...$?{requestId:$}:{}}}function oH(H){return QH(H)}function AH(H,J){let K,Z,$,z=!1;try{let W=JSON.parse(J);if(W&&typeof W==="object"){let G=W.error&&typeof W.error==="object"?W.error:void 0;if(typeof G?.code==="string")K=G.code;else if(typeof W.code==="string")K=W.code;if(typeof G?.message==="string")Z=G.message;else if(typeof W.message==="string")Z=W.message;if(typeof W.details?.field==="string")$=W.details.field}}catch(W){z=/^\s*[\[{]/.test(J)&&(sH(J)||/unexpected end|end of json|unterminated string/i.test(String(W)))}let X=K?.toUpperCase()??"",Y=(()=>{if(z)return"stream_truncated";if(H===402)return"billing";if(H===413)return"request_too_large";if(H===429)return"rate_limited";if(H===401||H===403)return X==="ERR_GATEWAY_REQUIRED"||oH(J)?"gateway_routing":"invalid_credentials";if(X.includes("CONFIG"))return"configuration";if(H>=500)return"transient";if(H>=400)return"request_rejected";return"unknown"})(),V={status:H,category:Y,retryable:Y==="transient"||Y==="rate_limited"||Y==="stream_truncated"};if(K!==void 0)V.upstreamCode=K;if(Z!==void 0)V.upstreamMessage=Z;if($!==void 0)V.field=$;return V}function sH(H){let J=0,K=!1,Z=!1;for(let $ of H){if(K){if(Z)Z=!1;else if($==="\\")Z=!0;else if($==='"')K=!1;continue}if($==='"')K=!0;else if($==="{"||$==="[")J++;else if($==="}"||$==="]")J--;if(J<0)return!1}return K||J>0}function aH(H){let J=Q.tierBudgetFacts(H.tier),K=H.advisory,Z=K?.tierOutputLimit??J?.output;if(H.requestedTotal!==void 0)return{total:Z===void 0?H.requestedTotal:Math.min(H.requestedTotal,Z)};if(!K&&!J)return{};let $=K?.reasoningReserveTokens??J?.reasoningReserve??0,z=K?.visibleOutputFloorTokens??J?.visibleOutputFloor??0,X=K?.recommendedTotalTokens??K?.tierRecommendedStepTokens??J?.recommendedTotal??J?.recommendedStep??Z,Y=K?.viableTotalFloorTokens??J?.viableTotalFloor??$+z,V=X===void 0?Y:Math.max(X,Y),W=K?.reasoningReported??J?.reasoning;return{total:Z===void 0?V:Math.min(V,Z),reasoningBudget:W&&$>0?Math.min($,V):void 0}}var tH=new Set(["coding","agent","research","review","chat"]);function eH(H){if(H===void 0)return;if(typeof H==="string"&&tH.has(H))return H;throw Error(`invalid Qortex posture: ${String(H)}`)}function HJ(H){if(H===void 0)return;let J=Array.isArray(H)?H:[H];if(J.every((K)=>typeof K==="string"&&/^[^/\s]+\/[^/\s]+$/.test(K)))return Array.isArray(H)?J:H;throw Error(`invalid Qortex directive registry key: ${String(H)}`)}function s(H){if(typeof H==="string")return H;if(Array.isArray(H))return H.map((J)=>{if(typeof J==="string")return J;if(J&&typeof J==="object"){let K=J;if(typeof K.text==="string")return K.text;if(typeof K.content==="string")return K.content}return""}).join("");if(H===void 0||H===null)return"";return String(H)}var JJ="[Tool call]",KJ="[Tool returned no output]";function TH(H){if(!Array.isArray(H))return{messages:H,dropped:[]};let J=[];return{messages:H.flatMap((Z,$)=>{if(!Z||typeof Z!=="object")return J.push({index:$,role:typeof Z,reason:"not-an-object"}),[];let z=Z,X=s(z.content);if(X.trim().length>0)return[{...z,content:X}];if(z.role==="assistant"&&Array.isArray(z.tool_calls)&&z.tool_calls.length>0)return[{...z,content:JJ}];if(z.role==="tool"&&typeof z.tool_call_id==="string"&&z.tool_call_id.trim().length>0)return[{...z,content:KJ}];return J.push({index:$,role:typeof z.role==="string"?z.role:"unknown",reason:"empty-content"}),[]}),dropped:J}}function ZJ(H){return TH(H).messages}function $J(H){if(!Array.isArray(H))return!1;return H.some((J)=>!!J&&typeof J==="object"&&J.role==="user")}function zJ(H){if(!Array.isArray(H))return!1;return H.some((J)=>{if(!J||typeof J!=="object")return!1;let K=J;if(K.role!=="user")return!1;return s(K.content).trim().length>0})}function XJ(H){if(!Array.isArray(H))return H;let J=(z)=>!!z&&typeof z==="object"&&z.role==="system",K=0;while(K<H.length&&J(H[K]))K++;if(K<=1)return H;let Z=H.slice(0,K),$=Z.map((z)=>typeof z.content==="string"?z.content:String(z.content??"")).filter((z)=>z.length>0).join(`
|
|
3
|
+
|
|
4
|
+
`);return[{...Z[0],role:"system",content:$},...H.slice(K)]}var d="<tool_call>",r="</tool_call>";function YJ(H){if(!Array.isArray(H)||H.length===0)return;let J=H.map((K)=>{try{return JSON.stringify(K)}catch{return}}).filter((K)=>K!==void 0);if(J.length===0)return;return["# Tools","","You may call one or more functions to assist with the user query.","","You are provided with function signatures within <tools></tools> XML tags:","<tools>",...J,"</tools>","","For each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:","<tool_call>",'{"name": <function-name>, "arguments": <args-json-object>}',"</tool_call>","","Function results will be provided within <tool_response></tool_response> XML tags. Do not write <tool_response> blocks yourself.","Only use the functions declared above. Never invent function names, and never write out a function-call-like block in any other format."].join(`
|
|
5
|
+
`)}var VJ=3;function $H(H){let J=H;for(let K=0;K<VJ;K++){if(J!==null&&typeof J==="object")return J;if(typeof J!=="string")return;try{J=JSON.parse(J)}catch{return}}return}function DJ(H){let J=H?.tool_calls;if(!Array.isArray(J))return;for(let K of J){let Z=K?.function;if(!Z)continue;k.debug("tool call ingress",{tool:typeof Z.name==="string"?Z.name:"?",source:"native",args:zH(Z.arguments)})}}function zH(H,J=300){let K;try{K=typeof H==="string"?H:JSON.stringify(H)??String(H)}catch{K="<unrenderable>"}return K.length<=J?K:`${K.slice(0,J)}\u2026 (${K.length} chars total)`}function WJ(H){let J=H.function??{},K=typeof J.name==="string"?J.name:"",Z=J.arguments===void 0?{}:$H(J.arguments);if(Z===void 0)k.warn("dropping unrecoverable tool-call arguments while re-encoding history",{tool:K,raw:zH(J.arguments)});return`${d}
|
|
6
|
+
${JSON.stringify({name:K,arguments:Z??{}})}
|
|
7
|
+
${r}`}function IH(H,J){if(!Array.isArray(H))return H;let K=H.map(($)=>{if(!$||typeof $!=="object")return $;let z=$;if(z.role==="assistant"&&Array.isArray(z.tool_calls)){let X=z.tool_calls.map(WJ).join(`
|
|
8
|
+
`),Y=s(z.content),{tool_calls:V,...W}=z;return{...W,content:Y.length>0?`${Y}
|
|
9
|
+
${X}`:X}}if(z.role==="tool"){let{tool_call_id:X,name:Y,...V}=z;return{...V,role:"user",content:`<tool_response>
|
|
10
|
+
${s(z.content)}
|
|
11
|
+
</tool_response>`}}return $}),Z=YJ(J);if(Z){let $=0;while($<K.length&&!!K[$]&&typeof K[$]==="object"&&K[$].role==="system")$++;K.splice($,0,{role:"system",content:Z})}return K}function NJ(){return process.env.QITQODE_TOOL_PROTOCOL==="text"?"text":"native"}function GJ(H){if(Array.isArray(H.tools)&&H.tools.length>0)return!0;let J=H.messages;if(!Array.isArray(J))return!1;return J.some((K)=>{if(!K||typeof K!=="object")return!1;let Z=K;return Z.role==="tool"||Z.role==="assistant"&&Array.isArray(Z.tool_calls)})}function WH(H,J){let K=J?.toolMode??"native",Z=H.model??"default",$={stream:H.stream??!0};if(H.temperature!==void 0)$.temperature=H.temperature;if(H.max_tokens!==void 0)$.max_tokens=H.max_tokens;let z=aH({tier:Z,advisory:J?.outputAdvisory,requestedTotal:$.max_tokens});if(z.total!==void 0)$.max_tokens=z.total;if(z.reasoningBudget!==void 0)$.thinking={budget_tokens:z.reasoningBudget};if(J?.outputBudgetRecoveryTokens!==void 0){let G=typeof $.max_tokens==="number"?$.max_tokens:0,U=J.outputAdvisory?.tierOutputLimit??Q.tierBudgetFacts(Z)?.output,P=Math.min(J.outputBudgetRecoveryTokens,U??J.outputBudgetRecoveryTokens);if(P>G)$.max_tokens=P}if(H.tools!==void 0)$.tools=H.tools;if(H.tool_choice!==void 0)$.tool_choice=H.tool_choice;if(H.stream_options!==void 0)$.stream_options=H.stream_options;let X=K==="text"?IH(H.messages,H.tools):H.messages,Y={},V=eH(H.posture);if(V!==void 0)Y.posture=V;let W=HJ(H.directive);if(W!==void 0)Y.directive=W;if(H.modelPersona!==void 0)Y.modelPersona=H.modelPersona;return{tier:Z,messages:XJ(ZJ(X)),opts:$,...Y}}var n=new Map,p=LH.join(_H.Path.data,"qlex-tier-advisories.json"),jJ="qlex-tier-advisories",UJ=2592000000,NH=!1,PJ;function BH(H,J){if(!H||typeof H!=="object")return;let K=H;if(typeof K.capturedAt!=="number"||J-K.capturedAt>UJ)return;if(!K.advisory)return;return{advisory:K.advisory,capturedAt:K.capturedAt}}async function _J(){if(NH)return;try{let H=JSON.parse(await y.readFile(p,"utf8")),J=Date.now();for(let[K,Z]of Object.entries(H)){let $=BH(Z,J);if($)bH(K,$.advisory,$.capturedAt)}}catch{}NH=!0}function FJ(){return PJ??=_J()}function bH(H,J,K=Date.now()){n.set(H,{advisory:J,capturedAt:K})}async function OJ(H){await PH.withLock(jJ,async()=>{let J={};try{let Z=JSON.parse(await y.readFile(p,"utf8")),$=Date.now();for(let[z,X]of Object.entries(Z)){let Y=BH(X,$);if(Y)J[z]=Y}}catch{}for(let[Z,$]of H){let z=J[Z];if(!z||z.capturedAt<=$.capturedAt)J[Z]=$}await y.mkdir(LH.dirname(p),{recursive:!0});let K=`${p}.${process.pid}.${yH()}.tmp`;try{await y.writeFile(K,JSON.stringify(J)),await y.rename(K,p)}catch(Z){throw await y.rm(K,{force:!0}).catch(()=>{}),Z}})}function QJ(){if(i)return;i=!0,ZH=ZH.then(()=>{return i=!1,OJ([...n].map(([H,J])=>[H,J]))}).catch((H)=>{i=!1,k.warn("failed to persist tier output advisories",{file:p,error:H instanceof Error?H.message:String(H)})})}function f(H){return typeof H==="number"&&Number.isFinite(H)&&H>0?H:void 0}function SJ(H,J){let K={},Z=f(J.tierOutputLimit),$=f(J.tierRecommendedStepTokens),z=f(J.reasoningReserveTokens),X=f(J.visibleOutputFloorTokens),Y=f(J.recommendedTotalTokens),V=f(J.viableTotalFloorTokens),W=f(J.budgetPolicyVersion);if(Z!==void 0)K.tierOutputLimit=Z;if($!==void 0)K.tierRecommendedStepTokens=$;if(z!==void 0)K.reasoningReserveTokens=z;if(X!==void 0)K.visibleOutputFloorTokens=X;if(Y!==void 0)K.recommendedTotalTokens=Y;if(V!==void 0)K.viableTotalFloorTokens=V;if(typeof J.reasoningReported==="boolean")K.reasoningReported=J.reasoningReported;if(W!==void 0)K.budgetPolicyVersion=W;if(Object.keys(K).length===0)return;bH(H,K),QJ()}function qJ(H){return n.get(H)?.advisory}function dJ(){n.clear()}function nJ(){return ZH}function LJ(H){let J=(K)=>typeof K==="string"&&(K.startsWith("qlex")||K.startsWith("qortex"));return J(H.id)||J(H.object)}function MJ(H){let J=[],K=H.indexOf(`
|
|
12
|
+
`)===-1?[H]:H.split(`
|
|
13
|
+
`);for(let X of K){let Y=X.endsWith("\r")?X.slice(0,-1):X;if(!Y.startsWith("data:"))continue;let V=Y.slice(5);if(V.startsWith(" "))V=V.slice(1);J.push(V)}if(J.length===0)return{kind:"skip"};let Z=J.length===1?J[0]:J.join(`
|
|
14
|
+
`);if(Z==="")return{kind:"skip"};if(Z==="[DONE]")return{kind:"done"};if(Z.startsWith("[ERROR]"))return{kind:"error",message:Z.slice(7).trim()||"qlex stream error"};let $=Z.charCodeAt(0),z=$===123||$===91||$===32||$===9||$===10||$===13;try{if(!z)return{kind:"token",content:Z};let X=JSON.parse(Z);if(X&&typeof X==="object"){let Y=X.id;if(Y==="qlex-cost"||Y==="qortex-cost")return{kind:"cost",cost:X};if(Y==="qlex-stream"&&X.usage&&typeof X.usage==="object"){let G=X.choices,U;if(Array.isArray(G)&&G[0]&&typeof G[0]==="object"){let P=G[0].finish_reason;if(typeof P==="string")U=P}return{kind:"usage",usage:X.usage,finishReason:U}}if(Array.isArray(X.choices))return{kind:"passthrough",chunk:X};let V=X,W=typeof V.content==="string"?V.content:typeof V.text==="string"?V.text:typeof V.delta==="string"?V.delta:void 0;if(W!==void 0)return{kind:"token",content:W};if(LJ(X)){let G=X.object;return{kind:"control",control:typeof G==="string"&&G.endsWith(".tier.outputLimits")?"tier-output-limits":"unknown",chunk:X}}}}catch{}return{kind:"token",content:Z}}function kJ(H,J){let K=Math.min(H.length,J.length-1);for(let Z=K;Z>=1;Z--)if(J.startsWith(H.slice(H.length-Z)))return Z;return 0}function EJ(H){if(typeof H==="string"){try{let K=JSON.parse(H);if(K!==null&&typeof K==="object")return H}catch{}let J=$H(H);return JSON.stringify(J??H)}return JSON.stringify(H??{})}class xH{onText;onToolCall;pending="";inBlock=!1;constructor(H,J){this.onText=H;this.onToolCall=J}feed(H){this.pending+=H,this.drain(!1)}flush(){if(this.drain(!0),this.inBlock)this.emitBlock(this.pending,!0),this.inBlock=!1;else if(this.pending.length>0)this.onText(this.pending);this.pending=""}drain(H){while(!0)if(!this.inBlock){let J=this.pending.indexOf(d);if(J===-1){let K=H?0:kJ(this.pending,d),Z=this.pending.length-K;if(Z>0)this.onText(this.pending.slice(0,Z)),this.pending=K>0?this.pending.slice(Z):"";return}if(J>0)this.onText(this.pending.slice(0,J));this.pending=this.pending.slice(J+d.length),this.inBlock=!0}else{let J=this.pending.indexOf(r);if(J===-1)return;if(this.emitBlock(this.pending.slice(0,J),!1),this.pending=this.pending.slice(J+r.length),this.pending.startsWith(`\r
|
|
15
|
+
`))this.pending=this.pending.slice(2);else if(this.pending.startsWith(`
|
|
16
|
+
`))this.pending=this.pending.slice(1);this.inBlock=!1}}emitBlock(H,J){try{let K=JSON.parse(H.trim());if(K&&typeof K==="object"&&typeof K.name==="string"){this.onToolCall({name:K.name,arguments:EJ(K.arguments)});return}}catch{}this.onText(`${d}${H}${J?"":r}`)}}function JH(H,J,K){let Z={id:"qlex-stream",object:"chat.completion.chunk",created:Math.floor(Date.now()/1000),model:"qlex",choices:[{index:0,delta:H,finish_reason:J}]};if(K)Z.usage=K;return`data: ${JSON.stringify(Z)}
|
|
17
|
+
|
|
18
|
+
`}function wJ(H,J){let K=J?.toolProtocolEnabled===!0,Z=J?.tier,$=J?.requestedOutputBudget,z=J?.idleTimeoutMs??mH,X=H.getReader(),Y=new TextDecoder,V=new TextEncoder,W="",G=!1,U=!1,P,S,L,E,w=!1,C=!1,h=0,A=0;return new ReadableStream({async start(_){let I=(D)=>{if(D.length>0)w=!0;A+=D.length;let N=G?{content:D}:{role:"assistant",content:D};G=!0,_.enqueue(V.encode(JH(N,null)))},c=0,F=K?new xH(I,(D)=>{k.debug("tool call ingress",{tool:D.name,source:"text-shim",args:zH(D.arguments),objectShaped:$H(D.arguments)!==void 0});let N={...G?{}:{role:"assistant"},tool_calls:[{index:c,id:`qlexcall_${Date.now().toString(36)}_${c}`,type:"function",function:{name:D.name,arguments:D.arguments}}]};G=!0,C=!0,c++,_.enqueue(V.encode(JH(N,null)))}):void 0,q=(D)=>F?F.feed(D):I(D),R=()=>{F?.flush();let N=P||S!==void 0||L!==void 0?{prompt_tokens:P?.tokens.prompt??L?.prompt??0,completion_tokens:P?.tokens.completion??L?.completion??0,total_tokens:P?.tokens.total??(P?.tokens.prompt??L?.prompt??0)+(P?.tokens.completion??L?.completion??0),cost_usd:P?.cost_usd,cost_credits:P?.cost_credits??P?.cost_qredits,context_window:S}:void 0;if(N&&(N.cost_usd??0)>0&&N.prompt_tokens===0)k.warn("qlex billed turn reported zero prompt tokens",{tier:Z,completionTokens:N.completion_tokens,costUsd:N.cost_usd,source:P?"cost.summary":"usage frame"});let j=c>0?"tool_calls":E??"stop";if(j==="length"||j==="max_tokens"){let O=o(Z??"default",$),T=O!==void 0;k.debug("qlex output budget exhausted",{tier:Z,contentStreamed:w,outputBudgetRecoveryAvailable:T}),_.error(new g("output budget exhausted",{category:"output_budget_exhausted",retryable:!1,outputBudgetRecoveryAvailable:T,outputBudgetRecoveryTokens:O})),U=!0;return}if(!w&&!C&&E!=="tool_calls"){let O=o(Z??"default",$),T=O!==void 0;k.debug("qlex completed without visible output",{tier:Z,outputBudgetRecoveryAvailable:T}),_.error(new g("empty output",{category:"empty_output",retryable:!1,outputBudgetRecoveryAvailable:T,outputBudgetRecoveryTokens:O})),U=!0;return}if(_.enqueue(V.encode(JH({},j,N))),_.enqueue(V.encode(`data: [DONE]
|
|
19
|
+
|
|
20
|
+
`)),!P&&Z!==void 0)k.info("qlex cost frame absent on stream finish",{tier:Z});_.close(),U=!0},M=(D)=>{let N=MJ(D);switch(h++,N.kind){case"skip":return!1;case"token":return q(N.content),!1;case"passthrough":{let j=N.chunk.choices;if(Array.isArray(j)&&j[0]&&typeof j[0]==="object"){let O=j[0].finish_reason;if(typeof O==="string")E=O;let T=j[0].delta;if(typeof T?.content==="string"&&T.content.length>0)w=!0;if(Array.isArray(T?.tool_calls))C=!0;DJ(j[0].delta)}G=!0;{let O=N.chunk.choices?.[0]?.delta?.content;if(typeof O==="string")A+=O.length}return _.enqueue(V.encode(`data: ${JSON.stringify(N.chunk)}
|
|
21
|
+
|
|
22
|
+
`)),!1}case"cost":if(N.cost.final)P=N.cost;return!1;case"usage":if(N.usage.context_window!==void 0)S=N.usage.context_window;if(N.usage.prompt_tokens!==void 0&&N.usage.completion_tokens!==void 0)L={prompt:N.usage.prompt_tokens,completion:N.usage.completion_tokens};if(N.finishReason!==void 0)E=N.finishReason;return!1;case"control":{if(N.control==="tier-output-limits"){let j=N.chunk;if(Z!==void 0)SJ(Z,j);k.debug("qlex tier output limits",{tierOutputLimit:j.tierOutputLimit,tierRecommendedStepTokens:j.tierRecommendedStepTokens,tierStepGuidance:j.tierStepGuidance,reasoningReserveTokens:j.reasoningReserveTokens,visibleOutputFloorTokens:j.visibleOutputFloorTokens,recommendedTotalTokens:j.recommendedTotalTokens,viableTotalFloorTokens:j.viableTotalFloorTokens,reasoningReported:j.reasoningReported,budgetPolicyVersion:j.budgetPolicyVersion})}else k.debug("qlex control frame dropped",{id:N.chunk.id,object:N.chunk.object});return!1}case"done":return R(),!0;case"error":{let j=rH(N.message);k.warn("qlex stream error frame",{tier:Z,raw:N.message,frameIndex:h,streamedContentChars:A,contentStreamed:G,upstreamCode:j.upstreamCode,requestId:j.requestId,category:j.category,retryable:j.retryable});let O=j.category==="output_budget_exhausted"||j.category==="empty_output"?o(Z??"default",$):void 0;if(j.retryable===!1&&O!==void 0)j.outputBudgetRecoveryAvailable=!0,j.outputBudgetRecoveryTokens=O;return _.error(new g(N.message,j,{textKept:w})),U=!0,!0}}},B=async()=>{if(!(z>0))return X.read();let D;try{return await Promise.race([X.read(),new Promise((N,j)=>{D=setTimeout(()=>{let O=Math.round(z/1000);k.warn("qlex stream idle timeout",{tier:Z,idleTimeoutMs:z,frameIndex:h,streamedContentChars:A,contentStreamed:G}),j(new g(`the gateway sent nothing for ${O}s`,{category:"transient",retryable:!0})),X.cancel(Error(`qlex stream idle for ${O}s`)).catch(()=>{})},z)})])}finally{if(D!==void 0)clearTimeout(D)}};try{while(!0){let{done:N,value:j}=await B();if(N)break;W+=Y.decode(j,{stream:!0});let O;while((O=W.indexOf(`
|
|
23
|
+
|
|
24
|
+
`))!==-1){let T=W.slice(0,O);if(W=W.slice(O+2),M(T))return}}W+=Y.decode();let D=W.replace(/\r?\n$/,"");if(D.length>0&&M(D))return;if(!U)R()}catch(D){if(!U)_.error(D instanceof g?D:new g(D instanceof Error?D.message:String(D)))}finally{X.releaseLock()}},cancel(_){X.cancel(_).catch(()=>{})}})}function hH(H){return{content:typeof H.content==="string"?H.content:H.choices?.[0]?.message?.content??"",finishReason:H.choices?.[0]?.finish_reason??"stop"}}function RJ(H){let J=H??{},{content:K,finishReason:Z}=hH(J),$=J.usage??{},z=$.prompt_tokens??0,X=$.completion_tokens??0,Y="orch-"+Date.now().toString(36),V=Math.floor(Date.now()/1000),W=(L,E,w)=>{let C={id:Y,object:"chat.completion.chunk",created:V,model:"orchestrated",choices:[{index:0,delta:L,finish_reason:E}]};if(w)C.usage=w;return`data: ${JSON.stringify(C)}
|
|
25
|
+
|
|
26
|
+
`},G={prompt_tokens:z,completion_tokens:X,total_tokens:$.total_tokens??z+X};if(typeof $.cost_usd==="number")G.cost_usd=$.cost_usd;if(typeof $.cost_credits==="number")G.cost_credits=$.cost_credits;if(typeof $.context_window==="number")G.context_window=$.context_window;let U=[W({role:"assistant",content:""},null),W({content:K},null),W({},Z,G),`data: [DONE]
|
|
27
|
+
|
|
28
|
+
`],P=new TextEncoder,S=new ReadableStream({start(L){for(let E of U)L.enqueue(P.encode(E));L.close()}});return new Response(S,{status:200,headers:{"content-type":"text/event-stream"}})}function iJ(H){let J=H??{},{content:K,finishReason:Z}=hH(J),$=J.usage??{},z=$.prompt_tokens??0,X=$.completion_tokens??0,Y={id:"orch-"+Date.now(),object:"chat.completion",created:Math.floor(Date.now()/1000),model:"orchestrated",choices:[{index:0,message:{role:"assistant",content:K},finish_reason:Z}],usage:{prompt_tokens:z,completion_tokens:X,total_tokens:$.total_tokens??z+X,...typeof $.cost_usd==="number"?{cost_usd:$.cost_usd}:{},...typeof $.context_window==="number"?{context_window:$.context_window}:{}}};return new Response(JSON.stringify(Y),{status:200,headers:{"content-type":"application/json"}})}async function CJ(H,J,K){let Z=AH(H,J),$=J?`HTTP ${H}: ${J}`:`HTTP ${H}`;switch(k.error("gateway rejected request",{tier:K.tier,status:H,category:Z.category,upstreamCode:Z.upstreamCode,field:Z.field,retryable:Z.retryable}),Z.category){case"billing":return new kH(J||void 0,Z);case"rate_limited":return new EH(Z);case"gateway_routing":return new u(`HTTP ${H}`,Z);case"invalid_credentials":return await K.onInvalidCredentials?.().catch(()=>{}),new wH($,Z);case"request_too_large":return new a("irreducible",Z.upstreamMessage??J??void 0,Z);case"request_rejected":case"tool_protocol":return new RH(Z.upstreamMessage??J??void 0,Z.field,Z);case"configuration":case"transient":case"unknown":default:return new u($,Z)}}function GH(H){let J=DH();if(J===void 0)return H;let K=v(H);if(K<=J)return H;let Z=HH(H,J);return k.warn("request over known size ceiling, reducing before send",{tier:H.tier,bytes:K,ceiling:J,reducedBytes:Z.bytes,fits:Z.reduced,...Z.actions}),Z.bytes<K?Z.body:H}function jH(H){let J=v(H),K=e(J),Z=HH(H,K);if(!Z.reduced)throw k.error("request too large and cannot be reduced further",{tier:H.tier,rejectedBytes:J,ceiling:K,reducedBytes:Z.bytes,...Z.actions}),new a("irreducible");return k.warn("request too large, retrying once with reduced history",{tier:H.tier,rejectedBytes:J,ceiling:K,reducedBytes:Z.bytes,...Z.actions,notice:Q.copy().requestTooLargeRecovering()}),Z.body}function UH(H){let J=v(H);throw e(J),k.error("reduced request still too large",{tier:H.tier,rejectedBytes:J}),new a("after-reduction")}function AJ(H,J=globalThis.fetch,K,Z){let $=Z?.responseTimeoutMs??cH;return async(z,X)=>{if(X?.method==="POST"&&typeof X?.body==="string"){let Y;try{Y=JSON.parse(X.body)}catch{return J(z,X)}let V=NJ();await FJ();let W=qJ(Y.model??"default"),G=WH(Y,{toolMode:V,outputAdvisory:W});if($J(Y.messages)&&!zJ(G.messages)){let{dropped:F}=TH(V==="text"?IH(Y.messages,Y.tools):Y.messages);throw k.error("refusing to send: user message lost in normalization",{tier:G.tier,toolMode:V,inputRoles:Array.isArray(Y.messages)?Y.messages.map((q)=>q&&typeof q==="object"?String(q.role):"?"):"not-an-array",droppedCount:F.length,dropped:F}),new CH("your message could not be turned into sendable content")}let U=await H(),P=typeof U==="string"?{key:U,method:"sso"}:U;if(!P?.key)throw new MH;let S=new Headers(X.headers),L=()=>{if(P.method==="api-key")S.delete("Authorization"),S.set("x-api-key",P.key);else S.delete("x-api-key"),S.set("Authorization",`Bearer ${P.key}`)};L(),S.set("Content-Type","application/json");let E=!1,w=async(F,q)=>{let R=AH(F,q),M=async()=>({retry:!1,error:await CJ(F,q,{onInvalidCredentials:K,tier:G.tier})});if(R.category!=="invalid_credentials"||E)return M();E=!0;let B=KH(P),D=await SH(P);if(D.kind==="recovered"&&KH(D.credential)!==B)return P=D.credential,L(),{retry:!0};if(D.kind==="inconclusive")return{retry:!1,error:new u(`HTTP ${F}: ${D.reason}`,R)};return M()};if(G.tier==="orchestrated"){let F=X.signal,q=async(B)=>{let D=new AbortController,N=()=>D.abort(F?.reason);if(F)if(F.aborted)D.abort(F.reason);else F.addEventListener("abort",N,{once:!0});let j=!1,O=setTimeout(()=>{j=!0,D.abort()},$);try{return await J(uH,{method:"POST",headers:S,body:JSON.stringify(B),signal:D.signal})}catch(T){if(j)throw new u(`no response within ${Math.round($/1000)}s`);throw T}finally{clearTimeout(O),F?.removeEventListener("abort",N)}},R=GH(G),M=await q(R);if(M.status===413){if(await M.body?.cancel().catch(()=>{}),R=jH(R),M=await q(R),M.status===413)await M.body?.cancel().catch(()=>{}),UH(R)}while(!M.ok){let B=await M.text().catch(()=>""),D=await w(M.status,B);if(!D.retry)throw D.error;M=await q(R)}return RJ(await M.json())}let C=X.signal,h=async(F)=>{let q=new AbortController,R=()=>q.abort(C?.reason);if(C)if(C.aborted)q.abort(C.reason);else C.addEventListener("abort",R,{once:!0});let M=()=>C?.removeEventListener("abort",R),B=!1,D=setTimeout(()=>{B=!0,q.abort()},$);try{return{res:await J(pH,{method:"POST",headers:S,body:JSON.stringify(F),signal:q.signal}),detach:M}}catch(N){if(M(),B)throw new u(`no response within ${Math.round($/1000)}s`);throw N}finally{clearTimeout(D)}},A=GH(G),{res:_,detach:I}=await h(A);if(_.status===400&&V==="native"&&GJ(Y))I(),await _.body?.cancel().catch(()=>{}),A=WH(Y,{toolMode:"text",outputAdvisory:W}),{res:_,detach:I}=await h(A);if(_.status===413){if(I(),await _.body?.cancel().catch(()=>{}),A=jH(A),{res:_,detach:I}=await h(A),_.status===413)I(),await _.body?.cancel().catch(()=>{}),UH(A)}try{while(!_.ok){let F=await _.text().catch(()=>""),q=await w(_.status,F);if(I(),!q.retry)throw q.error;({res:_,detach:I}=await h(A))}}catch(F){throw I(),F}if(Y.stream!==!1&&_.body){let F=Array.isArray(Y.tools)&&Y.tools.length>0;return new Response(wJ(_.body,{toolProtocolEnabled:F,tier:G.tier,requestedOutputBudget:G.opts.max_tokens}),{status:_.status,statusText:_.statusText,headers:{"content-type":"text/event-stream"}})}return _}return J(z,X)}}function rJ(H){let J=H.getToken??(async()=>H.bearerToken),K=AJ(J,globalThis.fetch,H.onInvalidCredentials);return qH({name:H.name??"qlex",baseURL:Q.streamBaseUrl(),fetch:K})}function oJ(H,J){return o(H,J)!==void 0}var TJ=2;function o(H,J){let K=n.get(H)?.advisory,Z=Q.tierBudgetFacts(H),$=K?.tierOutputLimit??Z?.output;if(!$)return;let z=J??K?.recommendedTotalTokens??K?.tierRecommendedStepTokens??Z?.recommendedTotal??Z?.recommendedStep;if(!z||z>=$)return;let X=K?.recommendedTotalTokens??K?.tierRecommendedStepTokens??Z?.recommendedTotal??Z?.recommendedStep??z,Y=Math.min($,Math.max(z+1,z*TJ,X));return Y>z?Y:void 0}var i=!1,ZH=Promise.resolve();export{wJ as transformQlexStream,RJ as toOrchestratedSSEStream,iJ as toOpenAICompletion,lJ as sanitizeUpstreamProviderError,NJ as resolveToolMode,YJ as renderToolProtocolPrompt,SJ as recordTierOutputAdvisory,aH as planTierBudget,kJ as partialTagSuffixLength,MJ as parseQlexFrame,AH as parseQlexError,TH as normalizeQlexMessagesWithReport,ZJ as normalizeQlexMessages,XJ as mergeLeadingSystemMessages,oH as isGatewayRequiredError,$J as hasUserRoleMessage,zJ as hasUsableUserMessage,GJ as hasToolContext,o as getTierOutputBudgetRecovery,qJ as getTierOutputAdvisory,nJ as flushTierOutputAdvisoryWrites,s as flattenMessageContent,IH as encodeToolProtocolMessages,EJ as encodeExtractedArguments,$H as decodeToolArgumentsToObject,rJ as createQlexProvider,AJ as createCustomFetch,dJ as clearTierOutputAdvisories,rH as classifyQlexStreamError,oJ as canIncreaseTierOutputBudget,WH as buildQlexBody,xH as ToolCallExtractor,d as TOOL_CALL_OPEN,r as TOOL_CALL_CLOSE,g as QlexStreamError,a as QlexRequestTooLargeError,RH as QlexRequestRejectedError,CH as QlexRequestNotSentError,EH as QlexRateLimitError,MH as QlexNotLoggedInError,wH as QlexInvalidCredentialsError,kH as QlexInsufficientBalanceError,u as QlexGatewayError,pH as QLEX_STREAM_URL,mH as QLEX_STREAM_IDLE_TIMEOUT_MS,cH as QLEX_RESPONSE_TIMEOUT_MS,uH as QLEX_ORCHESTRATED_URL};
|