@qitqode/qitqode-android-arm64 0.2.3 → 0.2.4

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.
Files changed (75) hide show
  1. package/bundle/{chunk-0vakk88p.js → chunk-09geev0j.js} +1 -1
  2. package/bundle/{chunk-qqxrvyx0.js → chunk-1rtx2zsc.js} +1 -1
  3. package/bundle/{chunk-tza09w2q.js → chunk-1t0c86bz.js} +1 -1
  4. package/bundle/{chunk-wg55bwqh.js → chunk-25ganjcn.js} +2 -2
  5. package/bundle/{chunk-96wwns35.js → chunk-2mm37s1w.js} +1 -1
  6. package/bundle/{chunk-z4kjxtjq.js → chunk-2prf30p3.js} +1 -1
  7. package/bundle/{chunk-cejyed1j.js → chunk-3hcr2bzt.js} +1 -1
  8. package/bundle/{chunk-p3rd2q47.js → chunk-3zrr4n6k.js} +1 -1
  9. package/bundle/{chunk-52w60e1f.js → chunk-4v2pzx22.js} +1 -1
  10. package/bundle/{chunk-hzrxmdqm.js → chunk-58dpxf8r.js} +1 -1
  11. package/bundle/{chunk-ha8b2n4x.js → chunk-58w8c6c2.js} +1 -1
  12. package/bundle/{chunk-jvybgsz5.js → chunk-620dpezx.js} +1 -1
  13. package/bundle/{chunk-78pt314g.js → chunk-6fc3gw3e.js} +1 -1
  14. package/bundle/{chunk-6tstcwxp.js → chunk-6pe60dsw.js} +1 -1
  15. package/bundle/{chunk-fsahzvd5.js → chunk-6v5867cy.js} +1 -1
  16. package/bundle/{chunk-88q0mtgp.js → chunk-7j4qne3q.js} +1 -1
  17. package/bundle/{chunk-0nbteyb0.js → chunk-7msfwk15.js} +1 -1
  18. package/bundle/{chunk-brws2aht.js → chunk-7zx1ve4w.js} +1 -1
  19. package/bundle/{chunk-msdypt5f.js → chunk-8q38721t.js} +1 -1
  20. package/bundle/{chunk-7knnz5f1.js → chunk-9pmmf4k1.js} +1 -1
  21. package/bundle/{chunk-4086z5ys.js → chunk-9y03z65a.js} +1 -1
  22. package/bundle/{chunk-3atcc483.js → chunk-a3edstpn.js} +1 -1
  23. package/bundle/{chunk-rp9r3cvt.js → chunk-ab4dq1bn.js} +1 -1
  24. package/bundle/{chunk-nftgx6bz.js → chunk-aj1sgq1d.js} +1 -1
  25. package/bundle/{chunk-262s2yz2.js → chunk-ak8e1nrf.js} +1 -1
  26. package/bundle/{chunk-56v352f8.js → chunk-b034nf8g.js} +1 -1
  27. package/bundle/{chunk-9fyz4sxa.js → chunk-b2p54yka.js} +1 -1
  28. package/bundle/{chunk-4websxrs.js → chunk-bghqsh7r.js} +1 -1
  29. package/bundle/{chunk-qktzz0sy.js → chunk-cdja76vj.js} +1 -1
  30. package/bundle/{chunk-v6h3nes1.js → chunk-ckb1y6gv.js} +1 -1
  31. package/bundle/{chunk-xq2kcar4.js → chunk-cx78hhbx.js} +1 -1
  32. package/bundle/{chunk-n0b0dfqk.js → chunk-d5qgc18n.js} +1 -1
  33. package/bundle/{chunk-49xhybc2.js → chunk-dj1jen1p.js} +1 -1
  34. package/bundle/chunk-dwhjgd8j.js +2 -0
  35. package/bundle/{chunk-a7wmadf1.js → chunk-dypdyrmy.js} +1 -1
  36. package/bundle/{chunk-yvn8dmah.js → chunk-g26tersc.js} +1 -1
  37. package/bundle/{chunk-0vxnkstz.js → chunk-grnjm8ev.js} +1 -1
  38. package/bundle/{chunk-47z3x3dp.js → chunk-hg4039nz.js} +2 -2
  39. package/bundle/{chunk-565855py.js → chunk-hz3h6e19.js} +1 -1
  40. package/bundle/{chunk-h823m51m.js → chunk-j4ad3mde.js} +1 -1
  41. package/bundle/{chunk-p27a88vp.js → chunk-j8nkz81m.js} +1 -1
  42. package/bundle/{chunk-qqrc1h5b.js → chunk-jdx3jshm.js} +1 -1
  43. package/bundle/{chunk-z8mj4z6e.js → chunk-jebss7x8.js} +1 -1
  44. package/bundle/{chunk-16w710kf.js → chunk-jqekpprn.js} +1 -1
  45. package/bundle/{chunk-65t9b9eq.js → chunk-k2g8346v.js} +1 -1
  46. package/bundle/{chunk-rscfes01.js → chunk-k2vsezeb.js} +1 -1
  47. package/bundle/{chunk-4dnntf9k.js → chunk-k6y2vw0d.js} +1 -1
  48. package/bundle/{chunk-8mm92zn2.js → chunk-kp6gh35c.js} +1 -1
  49. package/bundle/{chunk-s2gg38y0.js → chunk-kqhczjf6.js} +1 -1
  50. package/bundle/{chunk-enmsp09e.js → chunk-pdjafjry.js} +1 -1
  51. package/bundle/{chunk-c74cxhjb.js → chunk-pkn85169.js} +1 -1
  52. package/bundle/{chunk-nbd13scz.js → chunk-qk9x8j8d.js} +1 -1
  53. package/bundle/{chunk-zgv1e250.js → chunk-qnaw8k98.js} +1 -1
  54. package/bundle/{chunk-azpnrnv9.js → chunk-r6p0bd2w.js} +286 -286
  55. package/bundle/{chunk-nvwzam7a.js → chunk-rv08wm9j.js} +1 -1
  56. package/bundle/{chunk-bvf2dcq4.js → chunk-snqa3zsm.js} +1 -1
  57. package/bundle/{chunk-h99tj1e4.js → chunk-t2n7vgsq.js} +1 -1
  58. package/bundle/{chunk-g06a4chw.js → chunk-t6yzrmww.js} +1 -1
  59. package/bundle/{chunk-tdyvps17.js → chunk-thrfabyv.js} +1 -1
  60. package/bundle/{chunk-qznr1emx.js → chunk-twp3mjj0.js} +4 -4
  61. package/bundle/{chunk-dqp4nmxs.js → chunk-v3arcn10.js} +1 -1
  62. package/bundle/{chunk-vdxar0ct.js → chunk-w88ve2pm.js} +1 -1
  63. package/bundle/{chunk-083wpv6r.js → chunk-x65xbskr.js} +1 -1
  64. package/bundle/{chunk-epgcsjfp.js → chunk-x749e61j.js} +1 -1
  65. package/bundle/{chunk-0nqf1k20.js → chunk-xpjhe9gz.js} +1 -1
  66. package/bundle/{chunk-qrxqfp59.js → chunk-xv5z1bj6.js} +1 -1
  67. package/bundle/{chunk-jrwnz64e.js → chunk-ym09zrxe.js} +1 -1
  68. package/bundle/{chunk-5bjtq8t2.js → chunk-ytetprwr.js} +1 -1
  69. package/bundle/chunk-ztn9e8g1.js +2 -0
  70. package/bundle/{chunk-snbw69t6.js → chunk-zzznad30.js} +1 -1
  71. package/bundle/index.js +18 -18
  72. package/bundle/worker.js +1 -1
  73. package/package.json +1 -1
  74. package/bundle/chunk-hbyrwmne.js +0 -2
  75. package/bundle/chunk-x9ptmxt7.js +0 -2
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{zf as qH}from"./chunk-w9gzfsy7.js";import{bo as QH,fo as KH,xo as SH}from"./chunk-rp9r3cvt.js";import"./chunk-ph8hn1wt.js";import"./chunk-ptqk1j2r.js";import"./chunk-cqtkxwd8.js";import"./chunk-pr7z5dj8.js";import"./chunk-vdxar0ct.js";import"./chunk-ztyy3ga3.js";import"./chunk-mmjgf680.js";import{cs as Q}from"./chunk-x9ptmxt7.js";import"./chunk-0vakk88p.js";import{Gs as OH}from"./chunk-r5zy4za0.js";import{Ns as t,Vs as FH}from"./chunk-tr6rdr6h.js";import{ht as PH,kt as _H}from"./chunk-at22twxx.js";import"./chunk-kgptyf7n.js";import"./chunk-j9h1sp4g.js";import"./chunk-p6crzjtf.js";import"./chunk-55fcmswd.js";import"./chunk-qnvsqnz5.js";import"./chunk-r9w0thdk.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(`
2
+ import{zf as qH}from"./chunk-w9gzfsy7.js";import{bo as QH,fo as KH,xo as SH}from"./chunk-ab4dq1bn.js";import"./chunk-ph8hn1wt.js";import"./chunk-ptqk1j2r.js";import"./chunk-cqtkxwd8.js";import"./chunk-pr7z5dj8.js";import"./chunk-w88ve2pm.js";import"./chunk-ztyy3ga3.js";import"./chunk-mmjgf680.js";import{cs as Q}from"./chunk-ztn9e8g1.js";import"./chunk-09geev0j.js";import{Gs as OH}from"./chunk-r5zy4za0.js";import{Ns as t,Vs as FH}from"./chunk-tr6rdr6h.js";import{ht as PH,kt as _H}from"./chunk-at22twxx.js";import"./chunk-kgptyf7n.js";import"./chunk-j9h1sp4g.js";import"./chunk-p6crzjtf.js";import"./chunk-55fcmswd.js";import"./chunk-qnvsqnz5.js";import"./chunk-r9w0thdk.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
3
 
4
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
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}
@@ -1,2 +1,2 @@
1
1
  // @bun
2
- import{Pd as y}from"./chunk-65t9b9eq.js";import{ae as L}from"./chunk-5w76kdjr.js";import{Bh as w,_g as N}from"./chunk-azpnrnv9.js";import"./chunk-w46g7kdq.js";import"./chunk-bd21p9zz.js";import"./chunk-p54bzjtv.js";import"./chunk-ha1w0xzh.js";import"./chunk-6m9jb0s9.js";import"./chunk-vygkwwjd.js";import{Vk as q,cl as v}from"./chunk-qznr1emx.js";import"./chunk-6tstcwxp.js";import{Dl as k,Nl as O,vl as V,wl as A,xl as E}from"./chunk-qqrc1h5b.js";import"./chunk-fsahzvd5.js";import"./chunk-mh19kwzw.js";import"./chunk-88q0mtgp.js";import"./chunk-bvf2dcq4.js";import"./chunk-9zm6r55d.js";import"./chunk-vcygx6hs.js";import"./chunk-khzzmyk2.js";import"./chunk-y7hgevfv.js";import"./chunk-47k5jy1p.js";import"./chunk-rp9r3cvt.js";import"./chunk-ph8hn1wt.js";import"./chunk-ptqk1j2r.js";import"./chunk-cqtkxwd8.js";import"./chunk-pr7z5dj8.js";import"./chunk-dnnkq5y4.js";import"./chunk-t239rvej.js";import"./chunk-yz25607t.js";import"./chunk-7hvf9dgx.js";import"./chunk-wkg3c643.js";import"./chunk-fhqfqd5v.js";import"./chunk-xq2kcar4.js";import"./chunk-qrxqfp59.js";import"./chunk-73r8bjjz.js";import"./chunk-vdxar0ct.js";import"./chunk-ztyy3ga3.js";import"./chunk-mmjgf680.js";import"./chunk-nj1ntakd.js";import"./chunk-cmb62jkt.js";import"./chunk-tkrwcjkr.js";import"./chunk-x9ptmxt7.js";import"./chunk-0vakk88p.js";import"./chunk-r5zy4za0.js";import"./chunk-tr6rdr6h.js";import{ft as P}from"./chunk-at22twxx.js";import"./chunk-kgptyf7n.js";import"./chunk-j9h1sp4g.js";import"./chunk-p6crzjtf.js";import"./chunk-55fcmswd.js";import"./chunk-qnvsqnz5.js";import"./chunk-pxm4qvqk.js";import"./chunk-j8fcfhr2.js";import"./chunk-r9w0thdk.js";import{EOL as X}from"os";function U(C){let G=C.match(/^https?:\/\/[^/]+\/share\/([a-zA-Z0-9_-]+)$/);return G?G[1]:null}function M(C,G){try{return new URL(C).origin===new URL(G).origin}catch{return!1}}function S(C){let G=C.find((z)=>z.type==="session");if(!G)return null;let Z=new Map,Q=new Map;for(let z of C)if(z.type==="message")Z.set(z.data.id,z.data);else if(z.type==="part"){if(!Q.has(z.data.messageID))Q.set(z.data.messageID,[]);Q.get(z.data.messageID).push(z.data)}if(Z.size===0)return null;return{info:G.data,messages:Array.from(Z.values()).map((z)=>({info:z,parts:Q.get(z.id)??[]}))}}var m=L({command:"import <file>",describe:"import session data from JSON file or URL",builder:(C)=>{return C.positional("file",{describe:"path to JSON file or share URL",type:"string",demandOption:!0})},handler:async(C)=>{await y(process.cwd(),async()=>{let G;if(C.file.startsWith("http://")||C.file.startsWith("https://")){let J=U(C.file);if(!J){let Y=await w.runPromise(N.Service.use((R)=>R.url()));process.stdout.write(`Invalid URL format. Expected: ${Y}/share/<slug>`),process.stdout.write(X);return}let _=new URL(C.file).origin,$=await w.runPromise(N.Service.use((Y)=>Y.request())),j=M(C.file,$.baseUrl)?$.headers:{},W=$.api.data(J),K=await fetch(`${_}${W}`,{headers:j});if(!K.ok&&W!==`/api/share/${J}/data`)K=await fetch(`${_}/api/share/${J}/data`,{headers:j});if(!K.ok){process.stdout.write(`Failed to fetch share data: ${K.statusText}`),process.stdout.write(X);return}let H=await K.json(),B=S(H);if(!B){process.stdout.write(`Share not found or empty: ${J}`),process.stdout.write(X);return}G=B}else if(G=await P.readJson(C.file).catch(()=>{return}),!G){process.stdout.write(`File not found: ${C.file}`),process.stdout.write(X);return}if(!G){process.stdout.write("Failed to read session data"),process.stdout.write(X);return}let Q=v.Info.parse({...G.info,projectID:O.project.id}),z=v.toRow(Q);k.use((J)=>J.insert(V).values(z).onConflictDoUpdate({target:V.id,set:{project_id:z.project_id}}).run());for(let J of G.messages){let F=q.Info.parse(J.info),{id:_,sessionID:$,...j}=F;k.use((W)=>W.insert(A).values({id:_,session_id:z.id,time_created:F.time?.created??Date.now(),data:j}).onConflictDoNothing().run());for(let W of J.parts){let K=q.Part.parse(W),{id:H,sessionID:B,messageID:Y,...R}=K;k.use((T)=>T.insert(E).values({id:H,message_id:Y,session_id:z.id,data:R}).onConflictDoNothing().run())}}process.stdout.write(`Imported session: ${G.info.id}`),process.stdout.write(X)})}});export{S as transformShareData,M as shouldAttachShareAuthHeaders,U as parseShareUrl,m as ImportCommand};
2
+ import{Pd as y}from"./chunk-k2g8346v.js";import{ae as L}from"./chunk-5w76kdjr.js";import{Bh as w,_g as N}from"./chunk-r6p0bd2w.js";import"./chunk-w46g7kdq.js";import"./chunk-bd21p9zz.js";import"./chunk-p54bzjtv.js";import"./chunk-ha1w0xzh.js";import"./chunk-6m9jb0s9.js";import"./chunk-vygkwwjd.js";import{Vk as q,cl as v}from"./chunk-twp3mjj0.js";import"./chunk-6pe60dsw.js";import{Dl as k,Nl as O,vl as V,wl as A,xl as E}from"./chunk-jdx3jshm.js";import"./chunk-6v5867cy.js";import"./chunk-mh19kwzw.js";import"./chunk-7j4qne3q.js";import"./chunk-snqa3zsm.js";import"./chunk-9zm6r55d.js";import"./chunk-vcygx6hs.js";import"./chunk-khzzmyk2.js";import"./chunk-y7hgevfv.js";import"./chunk-47k5jy1p.js";import"./chunk-ab4dq1bn.js";import"./chunk-ph8hn1wt.js";import"./chunk-ptqk1j2r.js";import"./chunk-cqtkxwd8.js";import"./chunk-pr7z5dj8.js";import"./chunk-dnnkq5y4.js";import"./chunk-t239rvej.js";import"./chunk-yz25607t.js";import"./chunk-7hvf9dgx.js";import"./chunk-wkg3c643.js";import"./chunk-fhqfqd5v.js";import"./chunk-cx78hhbx.js";import"./chunk-xv5z1bj6.js";import"./chunk-73r8bjjz.js";import"./chunk-w88ve2pm.js";import"./chunk-ztyy3ga3.js";import"./chunk-mmjgf680.js";import"./chunk-nj1ntakd.js";import"./chunk-cmb62jkt.js";import"./chunk-tkrwcjkr.js";import"./chunk-ztn9e8g1.js";import"./chunk-09geev0j.js";import"./chunk-r5zy4za0.js";import"./chunk-tr6rdr6h.js";import{ft as P}from"./chunk-at22twxx.js";import"./chunk-kgptyf7n.js";import"./chunk-j9h1sp4g.js";import"./chunk-p6crzjtf.js";import"./chunk-55fcmswd.js";import"./chunk-qnvsqnz5.js";import"./chunk-pxm4qvqk.js";import"./chunk-j8fcfhr2.js";import"./chunk-r9w0thdk.js";import{EOL as X}from"os";function U(C){let G=C.match(/^https?:\/\/[^/]+\/share\/([a-zA-Z0-9_-]+)$/);return G?G[1]:null}function M(C,G){try{return new URL(C).origin===new URL(G).origin}catch{return!1}}function S(C){let G=C.find((z)=>z.type==="session");if(!G)return null;let Z=new Map,Q=new Map;for(let z of C)if(z.type==="message")Z.set(z.data.id,z.data);else if(z.type==="part"){if(!Q.has(z.data.messageID))Q.set(z.data.messageID,[]);Q.get(z.data.messageID).push(z.data)}if(Z.size===0)return null;return{info:G.data,messages:Array.from(Z.values()).map((z)=>({info:z,parts:Q.get(z.id)??[]}))}}var m=L({command:"import <file>",describe:"import session data from JSON file or URL",builder:(C)=>{return C.positional("file",{describe:"path to JSON file or share URL",type:"string",demandOption:!0})},handler:async(C)=>{await y(process.cwd(),async()=>{let G;if(C.file.startsWith("http://")||C.file.startsWith("https://")){let J=U(C.file);if(!J){let Y=await w.runPromise(N.Service.use((R)=>R.url()));process.stdout.write(`Invalid URL format. Expected: ${Y}/share/<slug>`),process.stdout.write(X);return}let _=new URL(C.file).origin,$=await w.runPromise(N.Service.use((Y)=>Y.request())),j=M(C.file,$.baseUrl)?$.headers:{},W=$.api.data(J),K=await fetch(`${_}${W}`,{headers:j});if(!K.ok&&W!==`/api/share/${J}/data`)K=await fetch(`${_}/api/share/${J}/data`,{headers:j});if(!K.ok){process.stdout.write(`Failed to fetch share data: ${K.statusText}`),process.stdout.write(X);return}let H=await K.json(),B=S(H);if(!B){process.stdout.write(`Share not found or empty: ${J}`),process.stdout.write(X);return}G=B}else if(G=await P.readJson(C.file).catch(()=>{return}),!G){process.stdout.write(`File not found: ${C.file}`),process.stdout.write(X);return}if(!G){process.stdout.write("Failed to read session data"),process.stdout.write(X);return}let Q=v.Info.parse({...G.info,projectID:O.project.id}),z=v.toRow(Q);k.use((J)=>J.insert(V).values(z).onConflictDoUpdate({target:V.id,set:{project_id:z.project_id}}).run());for(let J of G.messages){let F=q.Info.parse(J.info),{id:_,sessionID:$,...j}=F;k.use((W)=>W.insert(A).values({id:_,session_id:z.id,time_created:F.time?.created??Date.now(),data:j}).onConflictDoNothing().run());for(let W of J.parts){let K=q.Part.parse(W),{id:H,sessionID:B,messageID:Y,...R}=K;k.use((T)=>T.insert(E).values({id:H,message_id:Y,session_id:z.id,data:R}).onConflictDoNothing().run())}}process.stdout.write(`Imported session: ${G.info.id}`),process.stdout.write(X)})}});export{S as transformShareData,M as shouldAttachShareAuthHeaders,U as parseShareUrl,m as ImportCommand};