@cortexkit/opencode-openai-auth 1.0.3 → 1.0.5

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 (91) hide show
  1. package/README.md +12 -60
  2. package/dist/bin.js +13 -0
  3. package/dist/index-116q849r.js +2 -0
  4. package/dist/index-4fnghj9e.js +65 -0
  5. package/dist/index-66asrje2.js +2 -0
  6. package/dist/index-826s1yxa.js +2 -0
  7. package/dist/index-a69gr76b.js +2 -0
  8. package/dist/index-fsky1rsh.js +12 -0
  9. package/dist/index-fsxbncpw.js +3 -0
  10. package/dist/index-h263aftt.js +157 -0
  11. package/dist/{index-hy9030jh.js → index-nx2qh047.js} +1 -1
  12. package/dist/{index-766sfrh5.js → index-pg305s90.js} +1 -1
  13. package/dist/index-ssj7m2rd.js +8 -0
  14. package/dist/index-y4gxyxqd.js +2 -0
  15. package/dist/index-ydz3hbhc.js +2 -0
  16. package/dist/index.d.ts +2 -56
  17. package/dist/index.js +1 -1
  18. package/dist/map-m6f5a_IA.d.ts +56 -0
  19. package/dist/{pool-lifecycle-YLz2B8A5.d.ts → pool-lifecycle-C_6YRmsh.d.ts} +99 -789
  20. package/dist/{port-file-Do3lQIEk.d.ts → port-file-ZPlxXB4G.d.ts} +1 -1
  21. package/dist/{protocol-BOBdkqqm.d.ts → protocol-DctqemRI.d.ts} +1 -1
  22. package/dist/rpc/port-file.d.ts +1 -1
  23. package/dist/rpc/port-file.js +1 -1
  24. package/dist/rpc/protocol.d.ts +1 -1
  25. package/dist/rpc/protocol.js +1 -1
  26. package/dist/rpc/rpc-client.d.ts +3 -3
  27. package/dist/rpc/rpc-client.js +1 -1
  28. package/dist/rpc/rpc-dir.js +1 -1
  29. package/dist/{sidebar-state-D6cUKgkm.d.ts → sidebar-state-z_M7Trnd.d.ts} +5 -3
  30. package/dist/sidebar-state.d.ts +1 -1
  31. package/dist/sidebar-state.js +1 -1
  32. package/dist/{token-ypk61xj0.js → token-bzhkgc29.js} +1 -1
  33. package/dist/token-util-4a2xxnpg.js +1 -0
  34. package/dist/tui-preferences.d.ts +2 -1
  35. package/dist/tui-preferences.js +3 -3
  36. package/dist/tui.d.ts +2 -2
  37. package/dist/v2/server.d.ts +1 -1
  38. package/dist/v2/server.js +3 -4
  39. package/package.json +13 -8
  40. package/src/tui-compiled/raw/logger.js +10 -2
  41. package/src/tui-compiled/raw/shared/0332701351b3eeec-format.js +65 -34
  42. package/src/tui-compiled/raw/shared/053cc17b5419261e-codec.js +2 -1
  43. package/src/tui-compiled/raw/shared/0766d78c6f481f18-watcher.js +26 -10
  44. package/src/tui-compiled/raw/shared/375d9cca2def037d-private-files.js +302 -0
  45. package/src/tui-compiled/raw/shared/39c3cb05738fcf6d-projection.js +3 -1
  46. package/src/tui-compiled/raw/shared/43fc9e6b994519c7-refresh-lock.js +5 -0
  47. package/src/tui-compiled/raw/shared/458b934e92490331-mutate.js +2 -2
  48. package/src/tui-compiled/raw/shared/4825e03209d6ae3e-with-lock.js +4 -0
  49. package/src/tui-compiled/raw/shared/4f36d333d081d040-merge.js +21 -5
  50. package/src/tui-compiled/raw/shared/7211cfec06a298bc-atomic-write.js +21 -0
  51. package/src/tui-compiled/raw/shared/905bffc0220f43d0-map.js +36 -1
  52. package/src/tui-compiled/raw/shared/a09b6a533c11858f-tui-preferences.js +6 -4
  53. package/src/tui-compiled/raw/shared/c14988621dc60a75-port-file.js +30 -8
  54. package/src/tui-compiled/raw/shared/c64d7afbc14ca125-sidebar-file.js +17 -8
  55. package/src/tui-compiled/raw/shared/c852a15cfe489d12-pool.js +3 -0
  56. package/src/tui-compiled/raw/shared/cd94316a888b0a8e-schema.js +3 -2
  57. package/src/tui-compiled/raw/shared/d5a8f1061ee2f114-index.js +2 -2
  58. package/src/tui-compiled/raw/shared/d7dcba96fea1685c-engine.js +126 -11
  59. package/src/tui-compiled/raw/shared/e8cd4929507508d8-refresh-file-lock.js +254 -37
  60. package/src/tui-compiled/raw/shared/ec971142548df90e-index.js +1 -0
  61. package/src/tui-compiled/raw/shared/fbcdcd0f925e74c0-rpc-client.js +15 -1
  62. package/src/tui-compiled/runtime/logger.js +10 -2
  63. package/src/tui-compiled/runtime/shared/0332701351b3eeec-format.js +65 -34
  64. package/src/tui-compiled/runtime/shared/053cc17b5419261e-codec.js +2 -1
  65. package/src/tui-compiled/runtime/shared/0766d78c6f481f18-watcher.js +26 -10
  66. package/src/tui-compiled/runtime/shared/375d9cca2def037d-private-files.js +302 -0
  67. package/src/tui-compiled/runtime/shared/39c3cb05738fcf6d-projection.js +3 -1
  68. package/src/tui-compiled/runtime/shared/43fc9e6b994519c7-refresh-lock.js +5 -0
  69. package/src/tui-compiled/runtime/shared/458b934e92490331-mutate.js +2 -2
  70. package/src/tui-compiled/runtime/shared/4825e03209d6ae3e-with-lock.js +4 -0
  71. package/src/tui-compiled/runtime/shared/4f36d333d081d040-merge.js +21 -5
  72. package/src/tui-compiled/runtime/shared/7211cfec06a298bc-atomic-write.js +21 -0
  73. package/src/tui-compiled/runtime/shared/905bffc0220f43d0-map.js +36 -1
  74. package/src/tui-compiled/runtime/shared/a09b6a533c11858f-tui-preferences.js +6 -4
  75. package/src/tui-compiled/runtime/shared/c14988621dc60a75-port-file.js +30 -8
  76. package/src/tui-compiled/runtime/shared/c64d7afbc14ca125-sidebar-file.js +17 -8
  77. package/src/tui-compiled/runtime/shared/c852a15cfe489d12-pool.js +3 -0
  78. package/src/tui-compiled/runtime/shared/cd94316a888b0a8e-schema.js +3 -2
  79. package/src/tui-compiled/runtime/shared/d5a8f1061ee2f114-index.js +2 -2
  80. package/src/tui-compiled/runtime/shared/d7dcba96fea1685c-engine.js +126 -11
  81. package/src/tui-compiled/runtime/shared/e8cd4929507508d8-refresh-file-lock.js +254 -37
  82. package/src/tui-compiled/runtime/shared/ec971142548df90e-index.js +1 -0
  83. package/src/tui-compiled/runtime/shared/fbcdcd0f925e74c0-rpc-client.js +15 -1
  84. package/dist/index-8kj7sa1p.js +0 -12
  85. package/dist/index-b3q3j39x.js +0 -2
  86. package/dist/index-bmd7x5aq.js +0 -2
  87. package/dist/index-ff1jy44a.js +0 -222
  88. package/dist/index-jyr8y8k4.js +0 -7
  89. package/dist/index-rv08jmd4.js +0 -2
  90. package/dist/index-sjx8t1nr.js +0 -2
  91. package/dist/token-util-wdza526f.js +0 -1
@@ -0,0 +1,2 @@
1
+ import{createRequire as n}from"node:module";var k=Object.defineProperty;var q=(b,a)=>()=>(a||b((a={exports:{}}).exports,a),a.exports);var l=(b)=>b;function m(b,a){this[b]=l.bind(null,a)}var r=(b,a)=>{for(var c in a)k(b,c,{get:a[c],enumerable:!0,configurable:!0,set:m.bind(a,c)})};var t=n(import.meta.url),o=Symbol.dispose||Symbol.for("Symbol.dispose"),p=Symbol.asyncDispose||Symbol.for("Symbol.asyncDispose"),u=(b,a,c)=>{if(a!=null){if(typeof a!=="object"&&typeof a!=="function")throw TypeError('Object expected to be assigned to "using" declaration');var e;if(c)e=a[p];if(e===void 0)e=a[o];if(typeof e!=="function")throw TypeError("Object not disposable");b.push([c,e,a])}else if(c)b.push([c]);return a},v=(b,a,c)=>{var e=typeof SuppressedError==="function"?SuppressedError:function(d,i,f,g){return g=Error(f),g.name="SuppressedError",g.error=d,g.suppressed=i,g},j=(d)=>a=c?new e(d,a,"An error was suppressed during disposal"):(c=!0,d),h=(d)=>{while(d=b.pop())try{var i=d[1]&&d[1].call(d[2]);if(d[0])return Promise.resolve(i).then(h,(f)=>(j(f),h()))}catch(f){j(f)}if(c)throw a};return h()};
2
+ export{q as pe,r as qe,t as re,u as se,v as te};
@@ -0,0 +1,2 @@
1
+ import{Ld as k,Md as _,Nd as R}from"./index-fsky1rsh.js";import{be as h,ge as D}from"./index-116q849r.js";import{me as w}from"./index-pg305s90.js";class T extends Error{operation;constructor(f){super(`a ${f} on a strict notification scope needs a session id`);this.name="RpcSessionRequiredError",this.operation=f}}function F(f){return typeof f==="string"&&f.length>0}var S=new Map;function W(f){let x=JSON.stringify([f.rpcRoot,f.directoryPrefix,f.registrationSessionId,...f.requireSession===!0?["strict"]:[]]),z=S.get(x);if(!z)z={queue:[],nextId:1,lastDrainAtBySession:new Map,lastDrainAtAny:0},S.set(x,z);return z}var U=100,j=3000;function d(f,x,z){if(f.requireSession===!0&&!F(z))throw new T("push");let J=W(f);if(J.queue.push({id:J.nextId++,type:"open-dialog",payload:x,sessionId:z}),J.queue.length>U)J.queue=J.queue.slice(-U)}function i(f,x=0,z){if(f.requireSession===!0&&!F(z))throw new T("drain");let J=W(f),Y=Date.now();if(J.lastDrainAtAny=Y,z!==void 0)J.lastDrainAtBySession.set(z,Y);let Z=f.sessionlessDrain==="broadcast-only",V=(B)=>z===void 0?!Z||B.sessionId===void 0:B.sessionId===void 0||B.sessionId===z;if(x>0)J.queue=J.queue.filter((B)=>{if(B.id>x)return!0;if(z===void 0)return!Z||B.sessionId!==void 0;return B.sessionId!==z});return J.queue.filter((B)=>B.id>x&&V(B))}function n(f,x){let z=Date.now(),J=W(f),Y=x!==void 0?J.lastDrainAtBySession.get(x)??0:f.sessionlessDrain==="broadcast-only"?J.lastDrainAtAny:0;return Y>0&&z-Y<j}import{randomBytes as t,timingSafeEqual as q}from"node:crypto";import{unlink as v}from"node:fs/promises";import{createServer as u}from"node:http";import{join as I}from"node:path";class N extends Error{status;constructor(f,x){if(!Number.isInteger(f)||f<400||f>499)throw RangeError(`RpcRequestError status must be 4xx, got ${f}`);super(x);this.name="RpcRequestError",this.status=f}}var E=1e6;class g extends Error{declaredOversize;constructor(f){super("body too large");this.declaredOversize=f}}function l(f){return new Promise((x,z)=>{let J=(B=!1)=>{f.removeAllListeners("data"),f.on("data",()=>{}),f.resume(),z(new g(B))},Y=Number(f.headers["content-length"]);if(Number.isFinite(Y)&&Y>E){J(!0);return}let Z=[],V=0;f.on("data",(B)=>{if(V+=B.length,V>E){J();return}Z.push(B)}),f.on("end",()=>x(Buffer.concat(Z).toString("utf8"))),f.on("error",z)})}class m extends Error{}async function p(f,x){let z,J=new Promise((Y,Z)=>{z=setTimeout(()=>Z(new m("apply deadline exceeded")),x),z.unref?.()});f.catch(()=>{});try{return await Promise.race([f,J])}finally{clearTimeout(z)}}function c(f,x){if(!f?.startsWith("Bearer "))return!1;let z=Buffer.from(f.slice(7)),J=Buffer.from(x);return z.length===J.length&&q(z,J)}async function Bf(f){if(typeof f.drain==="function"===(typeof f.drainAsync==="function"))throw TypeError("exactly one of drain or drainAsync must be provided");let x=f.log??{warn(){},debug(){}},z=t(32).toString("hex"),J=f.timeoutMs??90000,Y=f.receiptTimeoutMs??2000,Z=!1,V=new Set,B=u((G,K)=>{G.setTimeout(J,()=>{G.socket.destroy()}),M(G,K)});B.on("connection",(G)=>{V.add(G),G.once("close",()=>V.delete(G))}),B.requestTimeout=Y,B.headersTimeout=Y;async function M(G,K){let H=(X,Q,C={})=>{if(K.headersSent||K.writableEnded||K.destroyed)return;K.writeHead(X,{"content-type":"application/json",...C}),K.end(JSON.stringify(Q))};try{let X=new URL(G.url??"/","http://127.0.0.1").pathname;if(G.method==="GET"&&X==="/health")return H(200,{ok:!0});if(G.method!=="POST"||!X.startsWith("/rpc/"))return H(404,{error:"not found"});if(!c(G.headers.authorization,z))return H(401,{error:"unauthorized"});let Q=X.slice(5),C;try{C=await l(G)}catch($){if(!($ instanceof g))throw $;if($.declaredOversize){let y=G.socket;K.once("finish",()=>{y.end();let A=setTimeout(()=>y.destroy(),2000);if(A.unref(),G.once("end",()=>y.destroy()),y.once("close",()=>clearTimeout(A)),G.complete)y.destroy()})}return H(413,{error:"body too large"},{connection:"close"})}let b;try{b=JSON.parse(C||"{}")}catch{return H(400,{error:"invalid json"})}if(Q==="pending-notifications"){let $;try{if(f.parsePending)$=f.parsePending(b);else{if(!b||typeof b!=="object"||Array.isArray(b))throw Error("invalid params");let L=b;if(f.requireSession===!0&&!F(L.sessionId))return H(400,{error:"session required"});if("lastReceivedId"in L&&(typeof L.lastReceivedId!=="number"||!Number.isSafeInteger(L.lastReceivedId)||L.lastReceivedId<0)||"sessionId"in L&&typeof L.sessionId!=="string")throw Error("invalid params");$={lastReceivedId:Number(L.lastReceivedId??0),sessionId:typeof L.sessionId==="string"?L.sessionId:void 0}}}catch(L){if(L instanceof N)throw L;return H(400,{error:"invalid params"})}let{lastReceivedId:y,sessionId:A}=$;if(f.requireSession===!0&&!F(A))return H(400,{error:"session required"});if(A===void 0&&!Z)Z=!0,x.warn("rpc notification drain missing session id",{pid:process.pid});let O;if(f.drainAsync)try{O=await f.drainAsync(y,A)}catch(L){return x.warn("rpc notification drain failed",{pid:process.pid,error:L instanceof Error?L.message:String(L)}),H(500,{error:"drain failed"})}else O=f.drain?.(y,A);return H(200,{messages:O})}if(Q==="apply"){let $=Promise.resolve(f.apply(b)),y=f.applyDeadlineMs===void 0?await $:await p($,f.applyDeadlineMs);return H(200,y)}return H(404,{error:"unknown method"})}catch(X){if(X instanceof N)return x.debug("rpc request refused",{pid:process.pid,status:X.status}),H(X.status,{error:X.message});if(X instanceof m)return x.warn("rpc apply deadline exceeded",{pid:process.pid,deadlineMs:f.applyDeadlineMs}),H(504,{error:"handler deadline exceeded"});x.warn("rpc request failed",{pid:process.pid,error:X instanceof Error?X.message:String(X)}),H(500,{error:"internal error"})}}let P=await new Promise((G,K)=>{B.on("error",K),B.listen(0,"127.0.0.1",()=>{let H=B.address();if(H&&typeof H==="object")G(H.port);else K(Error("no port"))})});if(B.unref(),f.sweepRoot)try{await R(f.sweepRoot,f.dir,f.isManagedDir,x)}catch(G){x.warn("rpc state sweep failed",{pid:process.pid,error:G instanceof Error?G.message:String(G)})}try{await _(f.dir,{port:P,token:z,pid:process.pid},{secureDir:f.secureDir}),x.debug("rpc server pid",{pid:process.pid,rpcPort:P})}catch(G){throw await new Promise((K)=>B.close(()=>K())),G}return{port:P,token:z,async stop(){await new Promise((H)=>{B.closeAllConnections?.(),B.close(()=>H());for(let X of V)X.destroy()});let G=I(f.dir,`port-${process.pid}.json`),K=await D(G).then((H)=>JSON.parse(H)).catch((H)=>{if(H instanceof h&&H.code!=="ENOENT")throw H;return});if(K?.port===P&&K.token===z)await v(G).catch(()=>{})}}}async function Hf(f,x,z){let J=globalThis,Y=Symbol.for(f),Z=J[Y]??{servers:new Map,pending:new Map};J[Y]=Z;let{servers:V,pending:B}=Z,M=B.get(x)??Promise.resolve(),P,G=M.catch(()=>{}).then(async()=>{let H=V.get(x);if(H){if(await H.stop(),V.get(x)===H)V.delete(x)}P=await z(),V.set(x,P)});B.set(x,G);try{await G}finally{if(B.get(x)===G)B.delete(x)}let K=P;if(!K)throw Error("RPC server failed to start");return{server:K,release:async()=>{if(V.get(x)!==K)return;if(await K.stop(),V.get(x)===K)V.delete(x)}}}var bf=k(w);
2
+ export{d as Fd,i as Gd,n as Hd,Bf as Id,Hf as Jd,bf as Kd};
@@ -0,0 +1,2 @@
1
+ import{Td as P,Wd as e}from"./index-y4gxyxqd.js";var V="all",zz=Object.freeze(["primary"]);function y(z){return z.kind==="retired"?z.retiredAt:z.checkedAt}function M(z,H){return JSON.stringify([z,H])}function T(z){return typeof z==="object"&&z!==null&&!Array.isArray(z)}function W(z){return typeof z==="number"&&Number.isFinite(z)}function b(z){return typeof z==="string"&&z.length>0}function I(z,H,J){return z[H]===void 0||J(z[H])}function Hz(z){return W(z)&&z>0}function F(z){return typeof z==="string"}function Jz(z){if(!T(z)||!b(z.scope)||!b(z.label))return!1;switch(z.kind){case"reading":return W(z.checkedAt)&&W(z.usedPercent)&&I(z,"resetsAt",F)&&I(z,"windowMinutes",Hz);case"retired":return W(z.retiredAt);case"absent":return W(z.checkedAt);default:return!1}}function Uz(z){if(!T(z)||!W(z.checkedAt))return!1;if(z.kind==="cleared")return!0;return z.kind==="reading"&&typeof z.reached==="boolean"&&I(z,"remainingPercent",W)&&I(z,"usedPercent",W)&&I(z,"resetsAt",F)&&I(z,"limit",W)&&I(z,"used",W)&&I(z,"remaining",W)&&I(z,"unit",F)}function p(z){return T(z)&&W(z.value)&&Number.isInteger(z.value)&&z.value>=0&&W(z.checkedAt)}function N(z){return T(z)&&Object.values(z).every(p)}function A(z){if(!T(z))return;let H=Object.entries(z).filter(([,J])=>p(J));return H.length===0?void 0:Object.fromEntries(H)}function R(z){if(Q(z))return z;if(!T(z))return;let{counters:H,...J}=z;if(!Q(J))return;let U=A(H);return{...J,...U===void 0?{}:{counters:U}}}function Q(z){if(!T(z)||!Array.isArray(z.limits))return!1;let H=new Set;for(let J of z.limits){if(!Jz(J))return!1;let U=M(J.scope,J.label);if(H.has(U))return!1;H.add(U)}return I(z,"budget",Uz)&&I(z,"counters",N)}var m=900000,d="no quota reading yet",v="no limits reported";function s(z){let H=Math.max(1,Math.round(z/60000));if(H<60)return`${H}m`;let J=Math.round(H/60);if(J<24)return`${J}h`;return`${Math.max(1,Math.round(H/1440))}d`}function Xz(z){if(z%1440===0)return`${z/1440}d`;if(z%60===0)return`${z/60}h`;return`${z}m`}function o(z){if(z.scope!==V||z.windowMinutes===void 0)return z.label;return Xz(z.windowMinutes)}function L(z){return Math.min(100,Math.max(0,z))}function c(z){return`${Math.round(L(z))}% left`}function g(z,H,J){let U=z===void 0?Number.NaN:Date.parse(z);return{...Number.isFinite(U)&&U>J?{resetIn:s(U-J)}:{},resetSinceReading:Number.isFinite(U)&&U>H&&U<=J}}function Yz(z,H){let J=z.windowMinutes,U=H.windowMinutes;if(J!==void 0&&U!==void 0&&J!==U)return J-U;if(J===void 0!==(U===void 0))return J===void 0?1:-1;if(z.scope!==H.scope){if(z.scope===V)return-1;if(H.scope===V)return 1;return z.scope<H.scope?-1:1}return z.label<H.label?-1:z.label>H.label?1:0}function u(z,H){if(!z)return{windows:[]};let{now:J}=H,Z=z.limits.filter((Y)=>Y.kind==="reading"&&Y.remainingPercent!==void 0).sort(Yz).map((Y)=>{let D=L(Y.remainingPercent??0);return{kind:"window",name:o(Y),figure:c(Y.remainingPercent??0),remainingPercent:D,checkedAt:Y.checkedAt,...g(Y.resetsAt,Y.checkedAt,J)}}),X=z.budget;if(X){let Y=X.remainingPercent,D=X.reached?"credits spent":Y!==void 0?`credits ${c(Y)}`:"credits available";Z.push({kind:"budget",name:"credits",figure:D,...Y===void 0?{}:{remainingPercent:L(Y)},checkedAt:X.checkedAt,...g(X.resetsAt,X.checkedAt,J)})}if(Z.length>0){let Y=J-Math.min(...Z.map((D)=>D.checkedAt));if(Y>(H.staleAfterMs??m))return{windows:Z,age:`checked ${s(Y)} ago`}}return{windows:Z}}function n(z,H){let J=u(z,H),U=(H.form??"full")==="full",Z=J.windows.map((X)=>{let Y=U&&X.resetIn?`, resets ${X.resetIn}`:"";return`${X.kind==="budget"?"":`${X.name} `}${X.figure}${Y}`});return J.age===void 0?Z:[...Z,J.age]}function Zz(z,H){let J=n(z,H);if(J.length>0)return J.join(" · ");return z&&z.limits.length>0?v:d}function $z(z){if(z.kind==="retired")return{scope:z.scope,label:z.label,kind:"retired",checkedAt:z.retiredAt};if(z.kind==="absent")return{scope:z.scope,label:z.label,kind:"absent",checkedAt:z.checkedAt};return{scope:z.scope,label:z.label,kind:"reading",checkedAt:z.checkedAt,usedPercent:z.usedPercent,remainingPercent:100-z.usedPercent,...z.windowMinutes===void 0?{}:{windowMinutes:z.windowMinutes},...z.resetsAt===void 0?{}:{resetsAt:z.resetsAt}}}function Gz(z,H){let J=z.windowMinutes!==void 0,U=H.windowMinutes!==void 0;if(J!==U)return J?-1:1;if(J&&U&&z.windowMinutes!==H.windowMinutes)return(H.windowMinutes??0)-(z.windowMinutes??0);if(z.label!==H.label)return z.label<H.label?-1:1;return 0}function Vz(z){return{checkedAt:z.checkedAt,reached:z.reached,...z.remainingPercent===void 0?{}:{remainingPercent:z.remainingPercent},...z.resetsAt===void 0?{}:{resetsAt:z.resetsAt}}}function Wz(z,H=V){let J=new Map;for(let G of z?.limits??[]){if(G.scope!==H&&G.scope!==V)continue;let K=J.get(G.label);if(K===void 0){J.set(G.label,G);continue}let j=G.scope===V?K:G,E=G.scope===V?G:K;J.set(G.label,j.kind==="reading"?j:E)}let U=[...J.values()].map($z).sort(Gz),Z=U.filter((G)=>G.kind==="reading"),X=Z.length>0?Z:U,Y=X.length>0?Math.min(...X.map((G)=>G.checkedAt)):void 0,D=z?.budget?.kind==="reading"?Vz(z.budget):void 0,S=A(z?.counters);return{scope:H,limits:U,...Y===void 0?{}:{checkedAt:Y},...D===void 0?{}:{budget:D},...S===void 0?{}:{counters:S}}}function Dz(z,H){let J=z?.budget;if(J?.reached!==!0||typeof J.resetsAt!=="string")return;let U=Date.parse(J.resetsAt);if(!Number.isFinite(U)||U<=H)return;return{resetsAt:J.resetsAt,resetAtMs:U}}function Iz(z){return z.kind==="reading"&&typeof z.usedPercent==="number"&&Number.isFinite(z.usedPercent)&&z.usedPercent>=100}function xz(z,H){if(typeof z.resetsAt!=="string")return;let J=Date.parse(z.resetsAt);return Number.isFinite(J)&&J>H?J:void 0}class O extends TypeError{constructor(z){super(z);this.name="QuotaCodecError"}}function C(z){return typeof z==="object"&&z!==null&&!Array.isArray(z)}function q(z){return typeof z==="number"&&Number.isFinite(z)}function l(z){return z===void 0||typeof z==="string"&&z!==""}function r(z){return typeof z==="string"&&z!==""}function _(z,H){return z[H]===void 0||q(z[H])}function k(z,H){return z[H]===void 0||typeof z[H]==="string"}function Bz(z){return C(z)&&l(z.scope)&&r(z.label)&&q(z.usedPercent)&&k(z,"resetsAt")&&(z.windowMinutes===void 0||q(z.windowMinutes)&&z.windowMinutes>0)}function Tz(z){return C(z)&&l(z.scope)&&r(z.label)}function Mz(z){if(!C(z))return!1;if(z.kind==="cleared")return!0;return z.kind==="reading"&&typeof z.reached==="boolean"&&_(z,"remainingPercent")&&_(z,"usedPercent")&&k(z,"resetsAt")&&_(z,"limit")&&_(z,"used")&&_(z,"remaining")&&k(z,"unit")}function a(z){if(!C(z)||!q(z.checkedAt))return!1;let H=z.readings??[],J=z.coverage??[];if(!Array.isArray(H)||!Array.isArray(J))return!1;let U=new Set;for(let Z of H){if(!Bz(Z))return!1;let X=M(Z.scope??V,Z.label);if(U.has(X))return!1;U.add(X)}if(!J.every(Tz))return!1;return(z.budget===void 0||Mz(z.budget))&&(z.counters===void 0||N(z.counters))}function Qz(z,H){if(z.scope!==H.scope)return z.scope<H.scope?-1:1;if(z.label!==H.label)return z.label<H.label?-1:1;return 0}function Rz(z,H,J){if(H===void 0)return z;if(z!==void 0&&J<z.checkedAt)return z;return{...H,checkedAt:J}}function _z(z,H){let J=new Map(Object.entries(z??{}));for(let[U,Z]of Object.entries(H??{})){let X=J.get(U);if(X===void 0||Z.checkedAt>=X.checkedAt)J.set(U,Z)}return J.size===0?void 0:Object.fromEntries(J)}function f(z,H){let J=z===void 0?void 0:R(z);if(z!==void 0&&J===void 0)throw new O("stored quota map is malformed");if(!a(H))throw new O("quota observation is malformed");let U=J??{limits:[]},Z=H.checkedAt,X=new Map;for(let $ of U.limits)X.set(M($.scope,$.label),$);let Y=($)=>{let x=X.get($);return x===void 0||Z>=y(x)},D=new Set;for(let $ of H.readings??[]){let x=$.scope??V,B=M(x,$.label);if(D.add(B),!Y(B))continue;X.set(B,{scope:x,label:$.label,kind:"reading",checkedAt:Z,usedPercent:$.usedPercent,...$.resetsAt===void 0?{}:{resetsAt:$.resetsAt},...$.windowMinutes===void 0?{}:{windowMinutes:$.windowMinutes}})}for(let $ of H.coverage??[]){let x=$.scope??V,B=M(x,$.label);if(D.has(B)||!Y(B))continue;let h=X.get(B);X.set(B,h===void 0||h.kind==="absent"?{scope:x,label:$.label,kind:"absent",checkedAt:Z}:{scope:x,label:$.label,kind:"retired",retiredAt:Z})}let{limits:S,budget:G,counters:K,...j}=U,E=Rz(U.budget,H.budget,Z),w=_z(U.counters,H.counters);return{...j,limits:[...X.values()].sort(Qz),...E===void 0?{}:{budget:E},...w===void 0?{}:{counters:w}}}var Kz=Object.freeze({validate:Q,decode:R,merge:f});import{tmpdir as i}from"node:os";import{join as t}from"node:path";var jz=["error","warn","info","debug","trace"];function Ez(){return process.env.OPENCODE_OPENAI_AUTH_LOG_FILE??(process.platform==="win32"?t(i(),"opencode-openai-auth","opencode-openai-auth.log"):t(i(),"opencode-openai-auth.log"))}function Oz(){let z=process.env.OPENCODE_OPENAI_AUTH_LOG_LEVEL;return z&&jz.includes(z)?z:void 0}e({file:Ez,level:Oz});if(process.once("beforeExit",async()=>{try{await P()}catch{process.emitWarning("OpenAI auth could not flush its log file at shutdown")}}),process.platform!=="win32")process.on("exit",()=>P());
2
+ export{V as jd,zz as kd,R as ld,Q as md,f as nd,Kz as od,o as pd,n as qd,Zz as rd,Wz as sd,Dz as td,Iz as ud,xz as vd};
@@ -0,0 +1,12 @@
1
+ import{ae as O,be as U,ee as b,fe as m,ge as L,ke as y}from"./index-116q849r.js";import{createHash as Zz,randomUUID as v}from"node:crypto";import{chmod as t,mkdir as r,open as e,readdir as j,rename as zz,rmdir as Gz,stat as Jz,unlink as S}from"node:fs/promises";import{join as R,resolve as D}from"node:path";function l(z){return typeof z==="number"&&Number.isSafeInteger(z)&&z>0}function F(z){if(!l(z))return!1;try{return process.kill(z,0),!0}catch(J){return J.code==="EPERM"}}function Cz(z){return(J)=>Kz(J,z)}function Kz(z,J){if(/^[0-9a-f]{16}$/.test(z))return!0;return z.startsWith(J)&&/^[0-9a-f]{16}$/.test(z.slice(J.length))}function Nz(z){let J=/^port-(\d+)\.json$/.exec(z);return J?Number(J[1]):void 0}function p(z,J){if(z===null||typeof z!=="object"||Array.isArray(z))return!1;let{pid:V,port:Q,token:K}=z;return l(V)&&Nz(J)===V&&typeof Q==="number"&&Number.isInteger(Q)&&Q>=1&&Q<=65535&&typeof K==="string"&&K.length>0}async function h(z,J){J?.debug("rpc corrupt port file",{pid:process.pid,portFile:z}),await S(z).catch(()=>{})}async function Az(z,J,V={}){let Q=async()=>{let K=R(z,`port-${J.pid}.json`);if(O)return await m(z,V.secureDir??!1),await V.beforeWrite?.(),await y(K,JSON.stringify({...J,startedAt:Date.now()}),{stagePath:`${K}.${(V.stageName??v)()}.tmp`}),K;if(await r(z,{recursive:!0,mode:V.secureDir?448:void 0}),V.secureDir)await t(z,448);await V.beforeWrite?.();let W={...J,startedAt:Date.now()},Y=`${K}.${(V.stageName??v)()}.tmp`,N,G=!1;try{N=await e(Y,"wx",384),G=!0,await N.writeFile(JSON.stringify(W),"utf8"),await N.chmod(384),await N.close(),N=void 0,await zz(Y,K),G=!1}finally{if(await N?.close().catch(()=>{}),G)await S(Y).catch(()=>{})}return K};try{return await Q()}catch(K){if(K.code==="ENOENT")return await Q();throw K}}async function Oz(z,J,V,Q){let K;try{K=await j(z,{withFileTypes:!0})}catch(Y){if(Y.code==="ENOENT")return;throw Y}let W=D(J);for(let Y of K){if(!Y.isDirectory()||!V(Y.name))continue;let N=R(z,Y.name),G;try{G=await j(N)}catch(X){if(X.code==="ENOENT")continue;throw X}for(let X of G){if(!X.startsWith("port-")||!X.endsWith(".json"))continue;let $=R(N,X),Z;try{Z=await L($)}catch(H){if(H instanceof U&&H.code!=="ENOENT")throw H;continue}if(Z===void 0)continue;let q;try{q=JSON.parse(Z)}catch{await h($,Q);continue}if(!p(q,X)){await h($,Q);continue}if(!F(q.pid))await S($).catch(()=>{})}if(D(N)!==W)await Gz(N).catch(()=>{})}}async function c(z,J){if(!F(J.pid))return null;let V=R(D(z),`port-${J.pid}.json`);try{if(O)await b(V,"file");let Q=await Jz(V);return`${V}:${Q.dev}:${Q.ino}:${Q.mtimeMs}:${Q.size}`}catch(Q){if(Q instanceof U&&Q.code!=="ENOENT")throw Q;return null}}async function a(z,J,V={}){let Q;try{if(O)await b(z,"directory");Q=await j(z)}catch(G){if(G instanceof U&&G.code!=="ENOENT")throw G;return null}let K=[];for(let G of Q){if(!G.startsWith("port-")||!G.endsWith(".json"))continue;try{let X=JSON.parse(await L(R(z,G)));if(p(X,G))if(F(X.pid))K.push(X);else await S(R(z,G)).catch(()=>{})}catch(X){if(X instanceof U&&X.code!=="ENOENT")throw X}}if(K.length===0)return null;let W=J!==void 0&&J>=1?K.filter((G)=>G.pid===J):[];if(V.exactPid===!0&&W.length===0)return null;let Y=W.length>0?W:K,N=(G)=>typeof G.startedAt==="number"&&Number.isFinite(G.startedAt)?G.startedAt:-1/0;return Y.sort((G,X)=>N(X)-N(G))[0]??null}import{open as Qz}from"node:fs/promises";import{connect as Vz}from"node:net";import{join as Wz,resolve as o}from"node:path";var i=2000,A=new Map,T=new Map;async function Xz(z,J){let V=Wz(o(z),`port-${J.pid}.json`);if(O){let K=JSON.parse(await L(V));if(K.pid!==J.pid||K.port!==J.port||K.token!==J.token)return null;return null}let Q;try{Q=await Qz(V,"r");let K=await Q.stat(),W=JSON.parse(await Q.readFile("utf8"));if(W.pid!==J.pid||W.port!==J.port||W.token!==J.token)return null;return`${V}:${K.dev}:${K.ino}:${K.mtimeMs}:${K.size}`}catch{return null}finally{await Q?.close().catch(()=>{})}}async function s(z,J,V,Q){let K=A.get(z);if(!O&&K&&await c(J,K.entry)===K.identity)return K;A.delete(z);let W=T.get(z);if(W)return W;let Y=(async()=>{let N=await(Q.discover??a)(J,V,Q);if(!N)return null;let G=await Xz(J,N);if(!G)return{entry:N,identity:""};let X={entry:N,identity:G};return A.set(z,X),X})();T.set(z,Y);try{return await Y}finally{if(T.get(z)===Y)T.delete(z)}}async function d(z,J,V,Q=i){return new Promise((K)=>{let W,Y=!1,N=!1,G=($,Z=!1)=>{if(Y)return;Y=!0,clearTimeout(X),W?.destroy(),K({value:$,stale:Z})},X=setTimeout(()=>G(null),Q);try{let $=JSON.stringify(V);W=Vz({host:"127.0.0.1",port:z.port}),W.on("connect",()=>{N=!0,W?.write(`POST /rpc/${J} HTTP/1.0\r
2
+ Host: 127.0.0.1:${z.port}\r
3
+ Connection: close\r
4
+ Content-Type: application/json\r
5
+ Content-Length: ${Buffer.byteLength($)}\r
6
+ Authorization: Bearer ${z.token}\r
7
+ \r
8
+ `+$)});let Z=[],q=0,C,H,_=Buffer.alloc(0),g=()=>{if(C===void 0)return G(null);try{let E=Buffer.concat(Z).subarray(C);G(JSON.parse(E.toString("utf8")))}catch{G(null)}};W.on("data",(E)=>{if(Y)return;if(q+=E.length,Z.push(E),C===void 0){_=Buffer.concat([_,E]);let B=_.indexOf(`\r
9
+ \r
10
+ `);if(B>=0)C=B+4;if((C??_.length)>16384)return G(null);if(C!==void 0){let x=_.subarray(0,B).toString("latin1").split(`\r
11
+ `),f=/^HTTP\/1\.[01] (\d{3})(?: |$)/.exec(x[0]??"");if(!f)return G(null);let w=Number(f[1]);if(w<200||w>=300)return G(null,[401,403,404,410].includes(w));for(let M of x.slice(1)){let k=M.indexOf(":"),u=M.slice(0,k).toLowerCase(),P=M.slice(k+1).trim();if(u==="transfer-encoding")return G(null);if(u==="content-length"){if(H!==void 0||!/^\d+$/.test(P))return G(null);if(H=Number(P),!Number.isSafeInteger(H)||H>8388608)return G(null)}}_=Buffer.alloc(0)}}let I=q-(C??q);if(I>8388608)return G(null);if(H!==void 0){if(I>H)return G(null);if(I===H)g()}}),W.on("end",()=>{if(H!==void 0&&q-(C??0)!==H)return G(null);g()}),W.on("error",()=>G(null,!N)),W.on("close",()=>G(null))}catch{G(null,!N)}})}async function n(z,J,V,Q,K,W,Y=i){let N=JSON.stringify([o(z),J??null,V.exactPid===!0]),G=await s(N,z,J,V);if(Q(G?.entry??null),!G)return null;let X=Date.now()+Y,$=await d(G.entry,K,W,Y);if(!$.stale)return $.value;if(A.get(N)===G)A.delete(N);let Z=await s(N,z,J,V);if(!Z||Date.now()>=X)return null;if(Z.entry.port===G.entry.port&&Z.entry.pid===G.entry.pid&&Z.entry.token===G.entry.token){if(A.get(N)===Z)A.delete(N);return null}let q=await d(Z.entry,K,W,X-Date.now());if(q.stale&&A.get(N)===Z)A.delete(N);return q.value}function Tz(z,J,V,Q={}){let K={exactPid:Q.exactPid,discover:Q.discover},W=!1,Y=(N)=>{if(W)return;V?.(N),W=!0};return{async pending(N,G,X){return(await n(z,J,K,Y,"pending-notifications",{lastReceivedId:N,sessionId:G},X))?.messages??[]},async apply(N,G){return await n(z,J,K,Y,"apply",{...N},G)??{text:"apply failed",knobs:{}}}}}
12
+ export{Cz as Ld,Az as Md,Oz as Nd,a as Od,i as Pd,Tz as Qd};
@@ -0,0 +1,3 @@
1
+ import{sc as X,uc as V}from"./index-h263aftt.js";import{randomUUID as Z}from"node:crypto";import{chmod as $,mkdir as G,readFile as H,rename as L,rm as T,stat as f,writeFile as g}from"node:fs/promises";import{dirname as k,resolve as w}from"node:path";var x="(no OpenCode 1 logins on this machine)";function C(b=process.env){return X(b)}async function Q(b){let z;try{z=await H(b,"utf8")}catch(q){if(q.code==="ENOENT")return;throw q}let j=JSON.parse(z);if(!j||typeof j!=="object"||Array.isArray(j))throw Error(`${b} does not hold a JSON object`);return j}function R(b){return b===void 0?void 0:JSON.stringify(b)}async function D(b){try{return(await f(b)).mode&511}catch(z){if(z.code==="ENOENT")return;throw z}}function _(b=C()){let z=new Map;return{path:w(b),async get(j){let q=(await Q(b))?.[j.path.id];return z.set(j.path.id,R(q)),q},async set(j){let q=j.path.id,W=await D(b),J=await Q(b)??{};if(!z.has(q)||z.get(q)!==R(J[q]))throw new V;J[q]=j.body,await G(k(b),{recursive:!0});let B=`${b}.${Z()}.tmp`;try{await g(B,`${JSON.stringify(J,null,2)}
2
+ `,{mode:W??384}),await $(B,W??384),await L(B,b)}catch(Y){throw await T(B,{force:!0}).catch(()=>{}),Y}return z.set(q,R(j.body)),!0},async all(){let j=await Q(b);if(!j||Object.keys(j).length===0)return{[x]:!0};return j}}}
3
+ export{_ as c};