gemi 0.211.0 → 0.212.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  // @bun
2
- import{Qa as m}from"./chunk-ba1h9pm6.js";import{createElement as j}from"react";function z(i,t){let u=Object.keys(t).sort((s,p)=>p.length-s.length).map((s)=>s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")),r=new RegExp(u.join("|"),"g");return i.replace(r,(s)=>t[s])}async function X(i,t,u=[],r){let s=[...u.map((n)=>`${i}/views/${n}.tsx`),r?`${i}/views/${r}.tsx`:`${i}/views/RootLayout.tsx`],p=new Set;for(let n of s){let e=t.moduleGraph.getModulesByFile(n);if(e)for(let d of e)p.add(d)}let b=[],l=[],g={};for(let n of p)if(n)for(let e of n.importedModules){if(e.file.includes("module.css"))g[e.file]=e.ssrTransformResult.map.sourcesContent.join("");if(e.file.includes(".css"))l.push(e.file)}for(let n of l){let e=await t.transformRequest(n+"?direct"),d=n.includes("module.css"),a="";if(d)a=z(g[n],e.default);b.push({isDev:!0,id:n,content:d?a:e.code})}return b.map((n,e)=>{return j("style",{key:e,type:"text/css","data-vite-dev-id":n.id,dangerouslySetInnerHTML:{__html:n.content}})})}async function Y(i=[]){return i.map((t,u)=>{return j("style",{key:u,id:t?.id,type:"text/css",dangerouslySetInnerHTML:{__html:t.content}})})}import{existsSync as f}from"fs";import{basename as q}from"path";import{networkInterfaces as k}from"os";var v={name:"gemi",version:"0.211.0",private:!1,license:"MIT",author:"Enes Tufekci <enes@gemijs.dev>",repository:{type:"git",url:"git+https://github.com/nstfkc/gemi.git",directory:"packages/gemi"},bin:{gemi:"./dist/bin/gemi.js","gemi-orm-generator":"./dist/bin/orm-generator.js"},files:["dist/**/*","ide/typescript-plugin/package.json","skills/**/*"],module:!0,exports:{"./http":"./http/index.ts","./client":"./client/index.ts","./ai":"./ai/index.ts","./ai/client":"./ai/client/index.ts","./ai/voice":"./ai/voice/index.ts","./ai/testing":"./ai/testing/index.ts","./testing":"./testing/index.ts","./app":"./app/index.ts","./facades":"./facades/index.ts","./email":"./email/index.ts","./vite":"./dist/vite/index.mjs","./kernel":"./kernel/index.ts","./services":"./services/index.ts","./i18n":"./i18n/index.ts","./dictionary":"./i18n/dictionaryRuntime.ts","./server":"./server/index.ts","./config":"./config/index.ts","./container":"./container/index.ts","./foundation":"./foundation/index.ts","./database":"./database/index.ts","./orm":"./orm/index.ts","./support":"./support/index.ts","./probe":"./probe/index.ts","./console/run":"./console/run.ts","./queue/work":"./services/queue/work.ts","./stats/route-table":"./stats/route-table.ts","./ide/typescript-plugin":"./ide/typescript-plugin/index.ts","./bun/preload":"./bun/preload.ts","./bun/plugin":"./bun/plugin.ts","./vitest":"./vitest/index.ts"},scripts:{lint:"oxlint",typecheck:"tsc --noEmit -p tsconfig.json && tsc --noEmit -p tsconfig.browser.json && tsc --noEmit -p ide/typescript-plugin/tsconfig.json",build:"NODE_ENV=production bun run build:core && bun run build:bin && bun run build:types && bun run build:client && bun run build:plugin && bun run build:ts-plugin && bun run build:client-types && bun run build:augmentation","build:core":"bun ./scripts/build.ts","build:bin":"bun build --outdir=./dist/bin --target=bun --external=vite --external=react-dom --external=react/jsx-runtime --external=bun --external=sharp --external=@azure/storage-blob --external=@azure/communication-email --external=@azure/identity --external=typescript --sourcemap ./bin/gemi.ts ./bin/orm-generator.ts && bun ./scripts/prepare-bin.ts","build:client":"rm -rf dist/client dist/testing dist/ai/client dist/ai/voice dist/chunks && vite build -c vite.client.config.mts","build:plugin":"vite build -c vite.plugin.config.mts","build:ts-plugin":"bun ./scripts/build-ts-plugin.ts","build:types":"tsc -p tsconfig.build.json","build:client-types":"tsc -p tsconfig.browser.json",test:"bun --bun x vitest","test:types":"vitest run --typecheck.only","test:live":"bun --bun x vitest run ai/live","test:packaging":"bun --bun x vitest run --config vitest.packaging.config.ts","build:publish":"bun scripts/build-publish.ts",prepublishOnly:"echo 'Do not publish from this directory \u2014 its exports point at TS source. Run: bun run build:publish, then publish from .publish/' && exit 1","build:augmentation":"bun ./scripts/wire-augmentation.ts"},dependencies:{"@aws-sdk/client-s3":"^3.629.0","@aws-sdk/s3-request-presigner":"^3.629.0","ast-types":"^0.14.2",commander:"^12.1.0",history:"^5.3.0","jsx-email":"2.0.0-rc2.1","magic-string":"^0.30.17",open:"^10.1.0","react-error-boundary":"^6.0.0",recast:"^0.23.9",resend:"^6.12.3",satori:"^0.12.2","temporal-polyfill":"^0.2.5","twitter-api-v2":"^1.20.2","urlpattern-polyfill":"^10.0.0",uuid:"^9.0.1"},devDependencies:{"@babel/parser":"^7.25.4","@prisma/generator-helper":"^6.5.0","@repo/typescript-config":"*","@testing-library/react":"^16.3.2","@types/bun":"^1.3.14","@types/eslint":"^8.56.5","@types/node":"^20.11.24","@types/react":"^19.0.2","@types/react-dom":"^19.0.2",eslint:"^8.57.0","happy-dom":"^21.0.4",jsdom:"^30.0.1",oxlint:"^1.39.0",postgres:"^3.4.5",react:"19.2.3","react-dom":"19.2.3",typescript:"^5.7.3",vitest:"^4.0.0"},peerDependencies:{"@azure/communication-email":"^1.1.0","@azure/identity":"^4.0.0","@azure/storage-blob":"^12.28.0",react:">=19","react-dom":">=19",sharp:"^0.34.2",typescript:">=5",vite:"^8.0.0",postgres:"^3.4.0"},peerDependenciesMeta:{"@azure/communication-email":{optional:!0},"@azure/identity":{optional:!0},"@azure/storage-blob":{optional:!0},typescript:{optional:!0},postgres:{optional:!0}}};var $=[" \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2557\u2588\u2588\u2557","\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D \u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2551","\u2588\u2588\u2551 \u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2554\u2588\u2588\u2588\u2588\u2554\u2588\u2588\u2551\u2588\u2588\u2551","\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u255D \u2588\u2588\u2551\u255A\u2588\u2588\u2554\u255D\u2588\u2588\u2551\u2588\u2588\u2551","\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2551 \u255A\u2550\u255D \u2588\u2588\u2551\u2588\u2588\u2551"," \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D"],h=Boolean(process.stdout.isTTY)&&!process.env.NO_COLOR,c=(i,t)=>h?`\x1B[${i}m${t}\x1B[0m`:t,E=(i)=>c("1",i),x=(i)=>c("2",i),o=(i)=>c("36",i),G=(i)=>c("32",i),J=(i)=>c("35",i);function N(){return v.version??"?"}function O(i){for(let t of Object.values(k()))for(let u of t??[])if((u.family==="IPv4"||u.family===4)&&!u.internal)return`http://${u.address}:${i}`;return null}function Q(i){return m(i).filter((t)=>f(t)).map((t)=>q(t))}function F(i){let{port:t,rootDir:u}=i,r=`http://localhost:${t}`,s=O(t),p=Q(u),b=(g,n)=>` ${G("\u279C")} ${E(g.padEnd(9))}${n}`,l=["",...$.map((g)=>J(g)),"",` ${x("gemi")} ${o(`v${N()}`)}`,"",b("Local:",o(r)),b("Network:",s?o(s):x("unavailable")),b("Env:",p.length?p.join(", "):x("none")),""];console.log(l.join(`
2
+ import{Qa as m}from"./chunk-ba1h9pm6.js";import{createElement as j}from"react";function z(i,t){let u=Object.keys(t).sort((s,p)=>p.length-s.length).map((s)=>s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")),r=new RegExp(u.join("|"),"g");return i.replace(r,(s)=>t[s])}async function X(i,t,u=[],r){let s=[...u.map((n)=>`${i}/views/${n}.tsx`),r?`${i}/views/${r}.tsx`:`${i}/views/RootLayout.tsx`],p=new Set;for(let n of s){let e=t.moduleGraph.getModulesByFile(n);if(e)for(let d of e)p.add(d)}let b=[],l=[],g={};for(let n of p)if(n)for(let e of n.importedModules){if(e.file.includes("module.css"))g[e.file]=e.ssrTransformResult.map.sourcesContent.join("");if(e.file.includes(".css"))l.push(e.file)}for(let n of l){let e=await t.transformRequest(n+"?direct"),d=n.includes("module.css"),a="";if(d)a=z(g[n],e.default);b.push({isDev:!0,id:n,content:d?a:e.code})}return b.map((n,e)=>{return j("style",{key:e,type:"text/css","data-vite-dev-id":n.id,dangerouslySetInnerHTML:{__html:n.content}})})}async function Y(i=[]){return i.map((t,u)=>{return j("style",{key:u,id:t?.id,type:"text/css",dangerouslySetInnerHTML:{__html:t.content}})})}import{existsSync as f}from"fs";import{basename as q}from"path";import{networkInterfaces as k}from"os";var v={name:"gemi",version:"0.212.0",private:!1,license:"MIT",author:"Enes Tufekci <enes@gemijs.dev>",repository:{type:"git",url:"git+https://github.com/nstfkc/gemi.git",directory:"packages/gemi"},bin:{gemi:"./dist/bin/gemi.js","gemi-orm-generator":"./dist/bin/orm-generator.js"},files:["dist/**/*","ide/typescript-plugin/package.json","skills/**/*"],module:!0,exports:{"./http":"./http/index.ts","./client":"./client/index.ts","./ai":"./ai/index.ts","./ai/client":"./ai/client/index.ts","./ai/voice":"./ai/voice/index.ts","./ai/testing":"./ai/testing/index.ts","./testing":"./testing/index.ts","./app":"./app/index.ts","./facades":"./facades/index.ts","./email":"./email/index.ts","./vite":"./dist/vite/index.mjs","./kernel":"./kernel/index.ts","./services":"./services/index.ts","./i18n":"./i18n/index.ts","./dictionary":"./i18n/dictionaryRuntime.ts","./server":"./server/index.ts","./config":"./config/index.ts","./container":"./container/index.ts","./foundation":"./foundation/index.ts","./database":"./database/index.ts","./orm":"./orm/index.ts","./support":"./support/index.ts","./probe":"./probe/index.ts","./console/run":"./console/run.ts","./queue/work":"./services/queue/work.ts","./stats/route-table":"./stats/route-table.ts","./ide/typescript-plugin":"./ide/typescript-plugin/index.ts","./bun/preload":"./bun/preload.ts","./bun/plugin":"./bun/plugin.ts","./vitest":"./vitest/index.ts"},scripts:{lint:"oxlint",typecheck:"tsc --noEmit -p tsconfig.json && tsc --noEmit -p tsconfig.browser.json && tsc --noEmit -p ide/typescript-plugin/tsconfig.json",build:"NODE_ENV=production bun run build:core && bun run build:bin && bun run build:types && bun run build:client && bun run build:plugin && bun run build:ts-plugin && bun run build:client-types && bun run build:augmentation","build:core":"bun ./scripts/build.ts","build:bin":"bun build --outdir=./dist/bin --target=bun --external=vite --external=react-dom --external=react/jsx-runtime --external=bun --external=sharp --external=@azure/storage-blob --external=@azure/communication-email --external=@azure/identity --external=typescript --sourcemap ./bin/gemi.ts ./bin/orm-generator.ts && bun ./scripts/prepare-bin.ts","build:client":"rm -rf dist/client dist/testing dist/ai/client dist/ai/voice dist/chunks && vite build -c vite.client.config.mts","build:plugin":"vite build -c vite.plugin.config.mts","build:ts-plugin":"bun ./scripts/build-ts-plugin.ts","build:types":"tsc -p tsconfig.build.json","build:client-types":"tsc -p tsconfig.browser.json",test:"bun --bun x vitest","test:types":"vitest run --typecheck.only","test:live":"bun --bun x vitest run ai/live","test:packaging":"bun --bun x vitest run --config vitest.packaging.config.ts","build:publish":"bun scripts/build-publish.ts",prepublishOnly:"echo 'Do not publish from this directory \u2014 its exports point at TS source. Run: bun run build:publish, then publish from .publish/' && exit 1","build:augmentation":"bun ./scripts/wire-augmentation.ts"},dependencies:{"@aws-sdk/client-s3":"^3.629.0","@aws-sdk/s3-request-presigner":"^3.629.0","ast-types":"^0.14.2",commander:"^12.1.0",history:"^5.3.0","jsx-email":"2.0.0-rc2.1","magic-string":"^0.30.17",open:"^10.1.0","react-error-boundary":"^6.0.0",recast:"^0.23.9",resend:"^6.12.3",satori:"^0.12.2","temporal-polyfill":"^0.2.5","twitter-api-v2":"^1.20.2","urlpattern-polyfill":"^10.0.0",uuid:"^9.0.1"},devDependencies:{"@babel/parser":"^7.25.4","@prisma/generator-helper":"^6.5.0","@repo/typescript-config":"*","@testing-library/react":"^16.3.2","@types/bun":"^1.3.14","@types/eslint":"^8.56.5","@types/node":"^20.11.24","@types/react":"^19.0.2","@types/react-dom":"^19.0.2",eslint:"^8.57.0","happy-dom":"^21.0.4",jsdom:"^30.0.1",oxlint:"^1.39.0",postgres:"^3.4.5",react:"19.2.3","react-dom":"19.2.3",typescript:"^5.7.3",vitest:"^4.0.0"},peerDependencies:{"@azure/communication-email":"^1.1.0","@azure/identity":"^4.0.0","@azure/storage-blob":"^12.28.0",react:">=19","react-dom":">=19",sharp:"^0.34.2",typescript:">=5",vite:"^8.0.0",postgres:"^3.4.0"},peerDependenciesMeta:{"@azure/communication-email":{optional:!0},"@azure/identity":{optional:!0},"@azure/storage-blob":{optional:!0},typescript:{optional:!0},postgres:{optional:!0}}};var $=[" \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2557\u2588\u2588\u2557","\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D \u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2551","\u2588\u2588\u2551 \u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2554\u2588\u2588\u2588\u2588\u2554\u2588\u2588\u2551\u2588\u2588\u2551","\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u255D \u2588\u2588\u2551\u255A\u2588\u2588\u2554\u255D\u2588\u2588\u2551\u2588\u2588\u2551","\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2551 \u255A\u2550\u255D \u2588\u2588\u2551\u2588\u2588\u2551"," \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D"],h=Boolean(process.stdout.isTTY)&&!process.env.NO_COLOR,c=(i,t)=>h?`\x1B[${i}m${t}\x1B[0m`:t,E=(i)=>c("1",i),x=(i)=>c("2",i),o=(i)=>c("36",i),G=(i)=>c("32",i),J=(i)=>c("35",i);function N(){return v.version??"?"}function O(i){for(let t of Object.values(k()))for(let u of t??[])if((u.family==="IPv4"||u.family===4)&&!u.internal)return`http://${u.address}:${i}`;return null}function Q(i){return m(i).filter((t)=>f(t)).map((t)=>q(t))}function F(i){let{port:t,rootDir:u}=i,r=`http://localhost:${t}`,s=O(t),p=Q(u),b=(g,n)=>` ${G("\u279C")} ${E(g.padEnd(9))}${n}`,l=["",...$.map((g)=>J(g)),"",` ${x("gemi")} ${o(`v${N()}`)}`,"",b("Local:",o(r)),b("Network:",s?o(s):x("unavailable")),b("Env:",p.length?p.join(", "):x("none")),""];console.log(l.join(`
3
3
  `))}function V(i,t){return Error(`app/views/${i}.tsx is missing. gemi's auth routes render it because ${t} is on. Add the view, or turn that setting off in app/config/auth.ts.`)}function U(i=process.env.SERVER_IDLE_TIMEOUT){if(i===void 0||i.trim()==="")return 10;let t=Number(i.trim());if(!Number.isInteger(t)||t<0||t>255)throw Error(`SERVER_IDLE_TIMEOUT must be a whole number of seconds from 0 to 255 (0 disables the timeout), got ${JSON.stringify(i)}.`);return t}
4
4
  export{X as Z,Y as _,F as $,V as aa,U as ba};
5
5
 
6
- //# debugId=C8F1512C4AD790ED64756E2164756E21
6
+ //# debugId=72BAB0FCFA58E61A64756E2164756E21
@@ -8,6 +8,6 @@
8
8
  "/**\n * Bun's default, and what both servers use when `SERVER_IDLE_TIMEOUT` is unset.\n */\nexport const DEFAULT_SERVER_IDLE_TIMEOUT = 10;\n\n/**\n * The `idleTimeout` (seconds) both `gemi dev` and `gemi start` pass to\n * `Bun.serve`, from `SERVER_IDLE_TIMEOUT` (#787).\n *\n * One reader for both servers, so a long-poll that works under `gemi start`\n * also works under `gemi dev`. Before this, only `httpProd` read the variable\n * and the dev server always ran at Bun's 10 seconds.\n *\n * It is the time a connection may stay silent, a response that has not started\n * included, before Bun closes it; `0` disables it. It does not apply to an\n * upgraded websocket (the HMR relay included), which has its own\n * `websocket.idleTimeout`.\n *\n * Unset or blank means the default. Anything that is not a whole number from 0\n * to 255 (Bun's own limits) fails the boot with the variable's name, instead\n * of Bun's \"expects idleTimeout to be an integer\", which does not say where the\n * value came from.\n */\nexport function serverIdleTimeout(raw: string | undefined = process.env.SERVER_IDLE_TIMEOUT): number {\n if (raw === undefined || raw.trim() === \"\") return DEFAULT_SERVER_IDLE_TIMEOUT;\n\n const seconds = Number(raw.trim());\n if (!Number.isInteger(seconds) || seconds < 0 || seconds > 255) {\n throw new Error(\n `SERVER_IDLE_TIMEOUT must be a whole number of seconds from 0 to 255 ` +\n `(0 disables the timeout), got ${JSON.stringify(raw)}.`,\n );\n }\n return seconds;\n}\n"
9
9
  ],
10
10
  "mappings": ";yCAAA,wBAAS,cAGT,SAAS,CAAc,CAAC,EAAc,EAAwC,CAC5E,IAAM,EAAc,OAAO,KAAK,CAAM,EACnC,KAAK,CAAC,EAAG,IAAM,EAAE,OAAS,EAAE,MAAM,EAClC,IAAI,CAAC,IAAQ,EAAI,QAAQ,sBAAuB,MAAM,CAAC,EAGpD,EAAQ,IAAI,OAAO,EAAY,KAAK,GAAG,EAAG,GAAG,EAEnD,OAAO,EAAK,QAAQ,EAAO,CAAC,IAAU,EAAO,EAAM,EAGrD,eAAsB,CAAe,CACnC,EACA,EACA,EAAyB,CAAC,EAE1B,EACA,CACA,IAAM,EAAQ,CACZ,GAAG,EAAa,IAAI,CAAC,IAAS,GAAG,WAAgB,OAAU,EAC3D,EAAS,GAAG,WAAgB,QAAe,GAAG,wBAChD,EAEM,EAAU,IAAI,IACpB,QAAW,KAAQ,EAAO,CACxB,IAAM,EAAM,EAAK,YAAY,iBAAiB,CAAI,EAClD,GAAI,EACF,QAAW,KAAK,EAAK,EAAQ,IAAI,CAAC,EAItC,IAAM,EAAS,CAAC,EACV,EAAa,CAAC,EACd,EAA2C,CAAC,EAClD,QAAW,KAAO,EAChB,GAAI,EACF,QAAW,KAAY,EAAI,gBAAiB,CAC1C,GAAI,EAAS,KAAK,SAAS,YAAY,EACrC,EAAiB,EAAS,MAAQ,EAAS,mBAAmB,IAAI,eAAe,KAAK,EAAE,EAE1F,GAAI,EAAS,KAAK,SAAS,MAAM,EAC/B,EAAW,KAAK,EAAS,IAAI,EAMrC,QAAW,KAAiB,EAAY,CACtC,IAAM,EAAY,MAAM,EAAK,iBAAiB,EAAgB,SAAS,EAEjE,EAAc,EAAc,SAAS,YAAY,EAEnD,EAAuB,GAE3B,GAAI,EACF,EAAuB,EACrB,EAAiB,GAGhB,EAA6D,OAChE,EAGF,EAAO,KAAK,CACV,MAAO,GACP,GAAI,EACJ,QAAS,EAAc,EAAuB,EAAU,IAC1D,CAAC,EAGH,OAAO,EAAO,IAAI,CAAC,EAAO,IAAM,CAC9B,OAAO,EAAc,QAAS,CAC5B,IAAK,EACL,KAAM,WACN,mBAAoB,EAAM,GAC1B,wBAAyB,CAAE,OAAQ,EAAM,OAAQ,CACnD,CAAC,EACF,EAGH,eAAsB,CAAY,CAAC,EAAS,CAAC,EAAG,CAC9C,OAAO,EAAO,IAAI,CAAC,EAAO,IAAM,CAC9B,OAAO,EAAc,QAAS,CAC5B,IAAK,EACL,GAAI,GAAO,GACX,KAAM,WACN,wBAAyB,CAAE,OAAQ,EAAM,OAAQ,CACnD,CAAC,EACF,EC3FH,qBAAS,WACT,mBAAS,aACT,4BAAS,wnIAKT,IAAM,EAAM,CACV,oKACA,mLACA,yKACA,oKACA,mLACA,yJACF,EAEM,EAAW,QAAQ,QAAQ,OAAO,KAAK,GAAK,CAAC,QAAQ,IAAI,SACzD,EAAQ,CAAC,EAAc,IAC3B,EAAW,QAAQ,KAAQ,WAAgB,EACvC,EAAO,CAAC,IAAc,EAAM,IAAK,CAAC,EAClC,EAAM,CAAC,IAAc,EAAM,IAAK,CAAC,EACjC,EAAO,CAAC,IAAc,EAAM,KAAM,CAAC,EACnC,EAAQ,CAAC,IAAc,EAAM,KAAM,CAAC,EACpC,EAAU,CAAC,IAAc,EAAM,KAAM,CAAC,EAE5C,SAAS,CAAW,EAAW,CAC7B,OAAQ,EAA6B,SAAW,IAGlD,SAAS,CAAU,CAAC,EAAsC,CACxD,QAAW,KAAU,OAAO,OAAO,EAAkB,CAAC,EACpD,QAAW,KAAS,GAAU,CAAC,EAG7B,IADa,EAAM,SAAW,QAAW,EAAM,SAAuB,IAC1D,CAAC,EAAM,SAAU,MAAO,UAAU,EAAM,WAAW,IAGnE,OAAO,KAGT,SAAS,CAAc,CAAC,EAA2B,CACjD,OAAO,EAAS,CAAO,EACpB,OAAO,CAAC,IAAS,EAAW,CAAI,CAAC,EACjC,IAAI,CAAC,IAAS,EAAS,CAAI,CAAC,EAG1B,SAAS,CAAkB,CAAC,EAGhC,CACD,IAAQ,OAAM,WAAY,EACpB,EAAQ,oBAAoB,IAC5B,EAAU,EAAW,CAAI,EACzB,EAAM,EAAe,CAAO,EAE5B,EAAM,CAAC,EAAe,IAC1B,KAAK,EAAM,QAAE,MAAM,EAAK,EAAM,OAAO,CAAC,CAAC,IAAI,IAEvC,EAAM,CACV,GACA,GAAG,EAAI,IAAI,CAAC,IAAS,EAAQ,CAAI,CAAC,EAClC,GACA,KAAK,EAAI,MAAM,KAAK,EAAK,IAAI,EAAY,GAAG,IAC5C,GACA,EAAI,SAAU,EAAK,CAAK,CAAC,EACzB,EAAI,WAAY,EAAU,EAAK,CAAO,EAAI,EAAI,aAAa,CAAC,EAC5D,EAAI,OAAQ,EAAI,OAAS,EAAI,KAAK,IAAI,EAAI,EAAI,MAAM,CAAC,EACrD,EACF,EAEA,QAAQ,IAAI,EAAI,KAAK;AAAA,CAAI,CAAC,ECjErB,SAAS,CAAwB,CAAC,EAAc,EAAoB,CACzE,OAAW,MACT,aAAa,0DAA6D,wEAE5E,ECcK,SAAS,CAAiB,CAAC,EAA0B,QAAQ,IAAI,oBAA6B,CACnG,GAAI,IAAQ,QAAa,EAAI,KAAK,IAAM,GAAI,MArBH,IAuBzC,IAAM,EAAU,OAAO,EAAI,KAAK,CAAC,EACjC,GAAI,CAAC,OAAO,UAAU,CAAO,GAAK,EAAU,GAAK,EAAU,IACzD,MAAU,MACR,qGACmC,KAAK,UAAU,CAAG,IACvD,EAEF,OAAO",
11
- "debugId": "C8F1512C4AD790ED64756E2164756E21",
11
+ "debugId": "72BAB0FCFA58E61A64756E2164756E21",
12
12
  "names": []
13
13
  }
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{$ as c,Z as P,aa as f,ba as l}from"./chunk-nvszx92e.js";import{Ba as u,Ca as m}from"./chunk-d79zfm40.js";import"./chunk-v2fd69at.js";import"./chunk-hke4hzfm.js";import"./chunk-0cckwd91.js";import"./chunk-0exm7bsw.js";import"./chunk-ba1h9pm6.js";import"./chunk-jzspg75a.js";import{Mj as S}from"./chunk-d8nxkc90.js";import{km as T}from"./chunk-f1jq1mp9.js";import{Em as y}from"./chunk-5ra8x6ax.js";import"./chunk-qymdnzpy.js";import{join as YJ}from"path";import{createServer as AJ}from"vite";import{join as R,sep as o}from"path";import{existsSync as a,statSync as s}from"fs";import{IncomingMessage as t,ServerResponse as r}from"http";import{Socket as e}from"net";function i(J){return J.replace(/\x1b\[[0-9;]*m/g,"").replace(/\[[0-9;]*m/g,"").replace(/\n\s*\n/g,`
2
+ import{$ as c,Z as P,aa as f,ba as l}from"./chunk-cr9hwkpa.js";import{Ba as u,Ca as m}from"./chunk-d79zfm40.js";import"./chunk-v2fd69at.js";import"./chunk-hke4hzfm.js";import"./chunk-0cckwd91.js";import"./chunk-0exm7bsw.js";import"./chunk-ba1h9pm6.js";import"./chunk-jzspg75a.js";import{Mj as S}from"./chunk-d8nxkc90.js";import{km as T}from"./chunk-f1jq1mp9.js";import{Em as y}from"./chunk-5ra8x6ax.js";import"./chunk-qymdnzpy.js";import{join as YJ}from"path";import{createServer as AJ}from"vite";import{join as R,sep as o}from"path";import{existsSync as a,statSync as s}from"fs";import{IncomingMessage as t,ServerResponse as r}from"http";import{Socket as e}from"net";function i(J){return J.replace(/\x1b\[[0-9;]*m/g,"").replace(/\[[0-9;]*m/g,"").replace(/\n\s*\n/g,`
3
3
  `).split(`
4
4
  `).map((W)=>W.trim()).filter((W)=>W.length>0).join(`
5
5
  `).trim()}function N(J){return`
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{$ as RJ,_ as p,aa as TJ,ba as SJ}from"./chunk-nvszx92e.js";import{Da as b,Ha as R,Ia as BJ}from"./chunk-v2fd69at.js";import"./chunk-ba1h9pm6.js";import{Qe as YJ,fh as LJ,gh as k,oh as DJ,ph as PJ,qh as AJ}from"./chunk-r6e5jwjm.js";import"./chunk-t8ghxzva.js";import"./chunk-gk2k76tn.js";import{vi as XJ,wi as HJ,zi as jJ}from"./chunk-6d807fgx.js";import{Mj as NJ}from"./chunk-d8nxkc90.js";import"./chunk-m4wagwhr.js";import"./chunk-xdrnzs3t.js";import"./chunk-ds5adkcf.js";import"./chunk-g6z6shvz.js";import"./chunk-768yza4f.js";import"./chunk-9a3wbbr6.js";import"./chunk-mcqzgyvf.js";import"./chunk-cgjdxxwy.js";import"./chunk-8wxt3v9r.js";import"./chunk-56z4jd8t.js";import"./chunk-kwvx36xw.js";import"./chunk-zbm7njvf.js";import"./chunk-24mk3gn3.js";import"./chunk-wfpvsgfy.js";import{km as zJ}from"./chunk-f1jq1mp9.js";import"./chunk-f7bayqs7.js";import{Cm as FJ}from"./chunk-q34hyv6y.js";import{Em as y}from"./chunk-5ra8x6ax.js";import"./chunk-qymdnzpy.js";import{createHash as L2}from"crypto";import{join as d,resolve as qJ,sep as bJ}from"path";import{Duplex as hJ}from"stream";import{constants as v,createBrotliCompress as cJ,createGzip as pJ}from"zlib";var dJ=["br","gzip"],lJ=1024,oJ=5,nJ=19,iJ=6;function rJ(J){if(J===void 0)return 1;if(!/^\d+(\.\d{0,3})?$/.test(J.trim()))return 1;let $=Number(J.trim());return Number.isFinite($)?Math.min($,1):1}function aJ(J){if(J===null||J===void 0)return null;let $=new Map;for(let Z of J.split(",")){let[Q,...H]=Z.split(";"),j=Q.trim().toLowerCase();if(j==="")continue;let Y=1;for(let W of H){let G=W.indexOf("=");if(G===-1)continue;if(W.slice(0,G).trim().toLowerCase()==="q"){Y=rJ(W.slice(G+1));break}}$.set(j,Y)}return $}function u(J,$=dJ){let Z=aJ(J);if(!Z)return null;let Q=Z.get("*"),H=null,j=0;for(let Y of $){let W=Z.get(Y)??Q??0;if(W>j)H=Y,j=W}return H}function sJ(J,$){if(!J)return!1;return J.split(",").some((Z)=>Z.trim().toLowerCase().split("=")[0].trim()===$)}function tJ(J,$){if(J==="HEAD")return!1;if($.status<200||$.status===204||$.status===206||$.status===304)return!1;if($.headers.has("Content-Range"))return!1;let Z=$.headers.get("Content-Type");if(!Z||!/^\s*text\/html\s*(;|$)/i.test(Z))return!1;if(!$.body)return!1;let Q=$.headers.get("Content-Encoding");if(Q&&Q.trim().toLowerCase()!=="identity")return!1;if(sJ($.headers.get("Cache-Control"),"no-transform"))return!1;let H=$.headers.get("Content-Length");if(H!==null&&Number(H)<lJ)return!1;return!0}function eJ(J){let $=J==="br"?cJ({params:{[v.BROTLI_PARAM_QUALITY]:oJ,[v.BROTLI_PARAM_LGWIN]:nJ},flush:v.BROTLI_OPERATION_FLUSH}):pJ({level:iJ,flush:v.Z_SYNC_FLUSH});return hJ.toWeb($)}function J2(J){let $=J.get("Vary");if(!$){J.set("Vary","Accept-Encoding");return}let Z=$.split(",").map((Q)=>Q.trim().toLowerCase());if(Z.includes("*")||Z.includes("accept-encoding"))return;J.append("Vary","Accept-Encoding")}function JJ(J,$){if(!tJ(J.method,$))return $;let Z=new Headers($.headers);J2(Z);let Q=u(J.headers.get("Accept-Encoding"));if(!Q)return new Response($.body,{status:$.status,statusText:$.statusText,headers:Z});let H;try{H=eJ(Q)}catch{return new Response($.body,{status:$.status,statusText:$.statusText,headers:Z})}return Z.set("Content-Encoding",Q),Z.delete("Content-Length"),new Response($.body.pipeThrough(H),{status:$.status,statusText:$.statusText,headers:Z})}import{readdir as Y2,stat as WJ}from"fs/promises";import{join as W2}from"path";import{mkdir as B2,readFile as $2,stat as R2,writeFile as T2}from"fs/promises";import{dirname as q2,join as Z2}from"path";import{promisify as $J}from"util";import{brotliCompress as Q2,constants as v2,gzip as X2}from"zlib";var H2=".vite/static-assets.json";var ZJ={br:".br",gzip:".gz"},j2=["br","gzip"],w2=$J(Q2),k2=$J(X2);async function QJ(J){let $;try{$=await $2(Z2(J,H2),"utf8")}catch{return null}let Z;try{Z=JSON.parse($)?.files}catch{return null}if(!Z||typeof Z!=="object")return null;let Q={files:{}};for(let[H,j]of Object.entries(Z)){if(!Array.isArray(j))continue;Q.files[H]=j2.filter((Y)=>j.includes(Y))}return Q}function m(J){let $=J.toString(),Z=new Bun.CryptoHasher("sha1");return Z.update($),Z.digest("hex")}async function GJ(J){let $=new Set;async function Z(Q,H){let j;try{j=await Y2(Q,{withFileTypes:!0})}catch{return}for(let Y of j){if(Y.name.startsWith("."))continue;if(H&&Y.name==="assets")continue;let W=W2(Q,Y.name),G=Y.isDirectory(),z=Y.isFile();if(Y.isSymbolicLink())try{let C=await WJ(W);G=C.isDirectory(),z=C.isFile()}catch{continue}if(z)$.add(W);else if(G&&!Y.isSymbolicLink())await Z(W,!1)}}return await Z(J,!0),$}var G2="public, max-age=31536000, must-revalidate",V2="public, max-age=31536000, immutable";async function z2(J,$,Z){if(Z.length===0||J.headers.has("Range"))return null;let Q=u(J.headers.get("Accept-Encoding"),Z);if(!Q)return null;let H=$+ZJ[Q];try{let j=await WJ(H);return j.isFile()?{encoding:Q,path:H,size:j.size}:null}catch{return null}}async function VJ(J,$,Z={}){let Q=Bun.file($),H=Z.encodings??[],j={"Content-Type":Q.type||"application/octet-stream","Cache-Control":Z.immutable?V2:G2,"Accept-Ranges":"bytes"};if(H.length>0)j.Vary="Accept-Encoding";let Y=await z2(J,$,H);if(Y){let z=Bun.file(Y.path);return new Response(z.stream(),{headers:{...j,"Content-Encoding":Y.encoding,"Content-Length":String(Y.size),ETag:`${m(z.lastModified)}-${Y.encoding}`}})}let W=Q.size;j.ETag=m(Q.lastModified);let G=XJ(J.headers.get("Range"));if(G){let z=HJ(G,W);if(!z)return YJ(W);return new Response(Q.slice(z.start,z.end+1).stream(),{status:206,headers:{...j,"Content-Range":jJ(z.start,z.end,W),"Content-Length":String(z.length)}})}return new Response(Q.stream(),{headers:{...j,"Content-Length":String(W)}})}import{stat as _2}from"fs/promises";var w="app/client.tsx";function UJ(J,$=b){let Z=J[w]?.file;if(!Z)return;return{module:R(Z,$),preload:B(J,w,$)}}function B(J,$,Z=b){let Q=[],H=new Set,j=(Y)=>{if(H.has(Y))return;H.add(Y);let W=J[Y];if(!W?.file)return;Q.push(R(W.file,Z));for(let G of W.imports??[])j(G)};return j($),Q}function U2(J,$,Z=b){let Q=new Set(B(J,$,Z)),H=[],j=new Set,Y=(G)=>{if(j.has(G))return;j.add(G);let z=J[G];if(!z)return;for(let C of z.dynamicImports??[])if(!/(^|\/)node_modules\//.test(C)&&!H.includes(C))H.push(C);for(let C of z.imports??[])Y(C)};Y($);let W=[];for(let G of H)for(let z of B(J,G,Z))if(!Q.has(z))Q.add(z),W.push(z);return W}function KJ(J,$){let Z=[],Q=new Set,H=new Set,j=(Y)=>{if(H.has(Y))return;H.add(Y);let W=J[Y];if(!W)return;for(let G of W.imports??[])j(G);for(let G of W.css??[])if(!Q.has(G))Q.add(G),Z.push(G)};return j($),Z}function OJ(J,$=b){let Z=new Map;return(Q)=>{if(!Z.has(Q)){let H=`${Q}${zJ}`,j=J[H]?.file;Z.set(Q,j?{src:R(j,$),preload:B(J,H,$),dynamicPreload:U2(J,H,$)}:void 0)}return Z.get(Q)}}var xJ="x-gemi-build";var K2="__gemiReload";function O2(J,$,Z,Q){let H=Date.now(),j=function(U){return typeof U==="number"&&H-U>=0&&H-U<Z},Y=function(U){try{let K=U?JSON.parse(U):null;return K&&typeof K==="object"&&!Array.isArray(K)?K:{}}catch{return{}}},W=function(U){let K={};for(let M in U)if(j(U[M]))K[M]=U[M];return K},G=function(U){let K=2166136261;for(let M=0;M<U.length;M++)K=Math.imul(K^U.charCodeAt(M),16777619);return(K>>>0).toString(36)},z=null,C={};try{z=window.sessionStorage,C=Y(z.getItem(J))}catch{z=null}let N=J+":",F="",I="";try{let U=new URL($,window.location.href);F=G(new URL(window.location.href).origin),I=G(U.origin+U.pathname)}catch{}let L=null;try{let U=window.name;if(!I)L=null;else if(U==="")L={};else if(U.indexOf(N)===0){let K=Y(U.slice(N.length)),M=K.m;L=K.o===F&&M&&typeof M==="object"&&!Array.isArray(M)?M:{}}}catch{L=null}if(Q==="tidy"){try{let U=window.name;if(L===null||U.indexOf(N)!==0)return"ok";for(let K in L)if(j(L[K]))return"cooldown";window.name=""}catch{}return"ok"}if(j(C[$])||L&&j(L[I]))return"cooldown";if(!z&&!L)return"storage";if(!Q)return"ok";if(z)try{let U=W(C);U[$]=H;let K=JSON.stringify(U);if(z.setItem(J,K),z.getItem(J)===K)return"ok"}catch{}if(L)try{let U=W(L);U[I]=H;let K=N+JSON.stringify({o:F,m:U});if(window.name=K,window.name===K)return"ok"}catch{}return"storage"}function CJ(J,$=30000){let Z=JSON.stringify("gemi:chunk-reload"),Q=JSON.stringify(`Failed to fetch dynamically imported module: ${J}`);return`var g=${O2.toString()};var r=!1;try{r=navigator.onLine!==!1&&g(${Z},window.location.href,${Number($)},!0)==="ok"}catch(e){}if(r)window.location.reload();else throw new Error(${Q});export {r as ${K2}}`}var x2=new RegExp(`^${LJ}/.+\\.m?js$`);function h(J){return x2.test(J)}function _J(J){if(h(J))return new Response(CJ(J),{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store"}});if(k(J))return new Response("Not found",{status:404});return}function IJ(J){let $=J?.trim();if(!$)return;try{let Z=new URL($);if(Z.protocol!=="https:"&&Z.protocol!=="http:")throw Error("not http(s)");return Z.search="",Z.hash="",Z.href.endsWith("/")?Z.href:`${Z.href}/`}catch{console.error(`GEMI_ASSET_FALLBACK_URL is not an absolute http(s) URL (${JSON.stringify($)}); missing assets are not looked up anywhere else.`);return}}function MJ({base:J,timeoutMs:$=3000,missTtlMs:Z=30000,fetch:Q=fetch,now:H=Date.now}){let j=new Map,Y=(W)=>{if(j.delete(W),j.set(W,H()+Z),j.size>1000)j.delete(j.keys().next().value)};return async(W,G)=>{if(W.method!=="GET"&&W.method!=="HEAD")return;let z=j.get(G);if(z!==void 0){if(z>H())return;j.delete(G)}let C;try{C=new URL(G.replace(/^\/+/,""),J)}catch{return}if(!C.href.startsWith(J))return;let N=new AbortController,F=setTimeout(()=>N.abort(),$),I;try{I=await Q(C.href,{method:W.method,signal:N.signal,redirect:"error"})}catch{Y(G);return}finally{clearTimeout(F)}if(I.status!==200){I.body?.cancel().catch(()=>{}),Y(G);return}let L=Bun.file(G).type,U=new Headers({"Content-Type":L!=="application/octet-stream"&&L||I.headers.get("content-type")||"application/octet-stream","Cache-Control":"public, max-age=31536000, immutable",["x-gemi-asset-fallback"]:"1"}),K=I.headers.get("content-length");if(K&&!I.headers.get("content-encoding"))U.set("Content-Length",K);return new Response(W.method==="HEAD"?null:I.body,{status:200,headers:U})}}var C2=`<!DOCTYPE html>
2
+ import{$ as RJ,_ as p,aa as TJ,ba as SJ}from"./chunk-cr9hwkpa.js";import{Da as b,Ha as R,Ia as BJ}from"./chunk-v2fd69at.js";import"./chunk-ba1h9pm6.js";import{Qe as YJ,fh as LJ,gh as k,oh as DJ,ph as PJ,qh as AJ}from"./chunk-r6e5jwjm.js";import"./chunk-t8ghxzva.js";import"./chunk-gk2k76tn.js";import{vi as XJ,wi as HJ,zi as jJ}from"./chunk-6d807fgx.js";import{Mj as NJ}from"./chunk-d8nxkc90.js";import"./chunk-m4wagwhr.js";import"./chunk-xdrnzs3t.js";import"./chunk-ds5adkcf.js";import"./chunk-g6z6shvz.js";import"./chunk-768yza4f.js";import"./chunk-9a3wbbr6.js";import"./chunk-mcqzgyvf.js";import"./chunk-cgjdxxwy.js";import"./chunk-8wxt3v9r.js";import"./chunk-56z4jd8t.js";import"./chunk-kwvx36xw.js";import"./chunk-zbm7njvf.js";import"./chunk-24mk3gn3.js";import"./chunk-wfpvsgfy.js";import{km as zJ}from"./chunk-f1jq1mp9.js";import"./chunk-f7bayqs7.js";import{Cm as FJ}from"./chunk-q34hyv6y.js";import{Em as y}from"./chunk-5ra8x6ax.js";import"./chunk-qymdnzpy.js";import{createHash as L2}from"crypto";import{join as d,resolve as qJ,sep as bJ}from"path";import{Duplex as hJ}from"stream";import{constants as v,createBrotliCompress as cJ,createGzip as pJ}from"zlib";var dJ=["br","gzip"],lJ=1024,oJ=5,nJ=19,iJ=6;function rJ(J){if(J===void 0)return 1;if(!/^\d+(\.\d{0,3})?$/.test(J.trim()))return 1;let $=Number(J.trim());return Number.isFinite($)?Math.min($,1):1}function aJ(J){if(J===null||J===void 0)return null;let $=new Map;for(let Z of J.split(",")){let[Q,...H]=Z.split(";"),j=Q.trim().toLowerCase();if(j==="")continue;let Y=1;for(let W of H){let G=W.indexOf("=");if(G===-1)continue;if(W.slice(0,G).trim().toLowerCase()==="q"){Y=rJ(W.slice(G+1));break}}$.set(j,Y)}return $}function u(J,$=dJ){let Z=aJ(J);if(!Z)return null;let Q=Z.get("*"),H=null,j=0;for(let Y of $){let W=Z.get(Y)??Q??0;if(W>j)H=Y,j=W}return H}function sJ(J,$){if(!J)return!1;return J.split(",").some((Z)=>Z.trim().toLowerCase().split("=")[0].trim()===$)}function tJ(J,$){if(J==="HEAD")return!1;if($.status<200||$.status===204||$.status===206||$.status===304)return!1;if($.headers.has("Content-Range"))return!1;let Z=$.headers.get("Content-Type");if(!Z||!/^\s*text\/html\s*(;|$)/i.test(Z))return!1;if(!$.body)return!1;let Q=$.headers.get("Content-Encoding");if(Q&&Q.trim().toLowerCase()!=="identity")return!1;if(sJ($.headers.get("Cache-Control"),"no-transform"))return!1;let H=$.headers.get("Content-Length");if(H!==null&&Number(H)<lJ)return!1;return!0}function eJ(J){let $=J==="br"?cJ({params:{[v.BROTLI_PARAM_QUALITY]:oJ,[v.BROTLI_PARAM_LGWIN]:nJ},flush:v.BROTLI_OPERATION_FLUSH}):pJ({level:iJ,flush:v.Z_SYNC_FLUSH});return hJ.toWeb($)}function J2(J){let $=J.get("Vary");if(!$){J.set("Vary","Accept-Encoding");return}let Z=$.split(",").map((Q)=>Q.trim().toLowerCase());if(Z.includes("*")||Z.includes("accept-encoding"))return;J.append("Vary","Accept-Encoding")}function JJ(J,$){if(!tJ(J.method,$))return $;let Z=new Headers($.headers);J2(Z);let Q=u(J.headers.get("Accept-Encoding"));if(!Q)return new Response($.body,{status:$.status,statusText:$.statusText,headers:Z});let H;try{H=eJ(Q)}catch{return new Response($.body,{status:$.status,statusText:$.statusText,headers:Z})}return Z.set("Content-Encoding",Q),Z.delete("Content-Length"),new Response($.body.pipeThrough(H),{status:$.status,statusText:$.statusText,headers:Z})}import{readdir as Y2,stat as WJ}from"fs/promises";import{join as W2}from"path";import{mkdir as B2,readFile as $2,stat as R2,writeFile as T2}from"fs/promises";import{dirname as q2,join as Z2}from"path";import{promisify as $J}from"util";import{brotliCompress as Q2,constants as v2,gzip as X2}from"zlib";var H2=".vite/static-assets.json";var ZJ={br:".br",gzip:".gz"},j2=["br","gzip"],w2=$J(Q2),k2=$J(X2);async function QJ(J){let $;try{$=await $2(Z2(J,H2),"utf8")}catch{return null}let Z;try{Z=JSON.parse($)?.files}catch{return null}if(!Z||typeof Z!=="object")return null;let Q={files:{}};for(let[H,j]of Object.entries(Z)){if(!Array.isArray(j))continue;Q.files[H]=j2.filter((Y)=>j.includes(Y))}return Q}function m(J){let $=J.toString(),Z=new Bun.CryptoHasher("sha1");return Z.update($),Z.digest("hex")}async function GJ(J){let $=new Set;async function Z(Q,H){let j;try{j=await Y2(Q,{withFileTypes:!0})}catch{return}for(let Y of j){if(Y.name.startsWith("."))continue;if(H&&Y.name==="assets")continue;let W=W2(Q,Y.name),G=Y.isDirectory(),z=Y.isFile();if(Y.isSymbolicLink())try{let C=await WJ(W);G=C.isDirectory(),z=C.isFile()}catch{continue}if(z)$.add(W);else if(G&&!Y.isSymbolicLink())await Z(W,!1)}}return await Z(J,!0),$}var G2="public, max-age=31536000, must-revalidate",V2="public, max-age=31536000, immutable";async function z2(J,$,Z){if(Z.length===0||J.headers.has("Range"))return null;let Q=u(J.headers.get("Accept-Encoding"),Z);if(!Q)return null;let H=$+ZJ[Q];try{let j=await WJ(H);return j.isFile()?{encoding:Q,path:H,size:j.size}:null}catch{return null}}async function VJ(J,$,Z={}){let Q=Bun.file($),H=Z.encodings??[],j={"Content-Type":Q.type||"application/octet-stream","Cache-Control":Z.immutable?V2:G2,"Accept-Ranges":"bytes"};if(H.length>0)j.Vary="Accept-Encoding";let Y=await z2(J,$,H);if(Y){let z=Bun.file(Y.path);return new Response(z.stream(),{headers:{...j,"Content-Encoding":Y.encoding,"Content-Length":String(Y.size),ETag:`${m(z.lastModified)}-${Y.encoding}`}})}let W=Q.size;j.ETag=m(Q.lastModified);let G=XJ(J.headers.get("Range"));if(G){let z=HJ(G,W);if(!z)return YJ(W);return new Response(Q.slice(z.start,z.end+1).stream(),{status:206,headers:{...j,"Content-Range":jJ(z.start,z.end,W),"Content-Length":String(z.length)}})}return new Response(Q.stream(),{headers:{...j,"Content-Length":String(W)}})}import{stat as _2}from"fs/promises";var w="app/client.tsx";function UJ(J,$=b){let Z=J[w]?.file;if(!Z)return;return{module:R(Z,$),preload:B(J,w,$)}}function B(J,$,Z=b){let Q=[],H=new Set,j=(Y)=>{if(H.has(Y))return;H.add(Y);let W=J[Y];if(!W?.file)return;Q.push(R(W.file,Z));for(let G of W.imports??[])j(G)};return j($),Q}function U2(J,$,Z=b){let Q=new Set(B(J,$,Z)),H=[],j=new Set,Y=(G)=>{if(j.has(G))return;j.add(G);let z=J[G];if(!z)return;for(let C of z.dynamicImports??[])if(!/(^|\/)node_modules\//.test(C)&&!H.includes(C))H.push(C);for(let C of z.imports??[])Y(C)};Y($);let W=[];for(let G of H)for(let z of B(J,G,Z))if(!Q.has(z))Q.add(z),W.push(z);return W}function KJ(J,$){let Z=[],Q=new Set,H=new Set,j=(Y)=>{if(H.has(Y))return;H.add(Y);let W=J[Y];if(!W)return;for(let G of W.imports??[])j(G);for(let G of W.css??[])if(!Q.has(G))Q.add(G),Z.push(G)};return j($),Z}function OJ(J,$=b){let Z=new Map;return(Q)=>{if(!Z.has(Q)){let H=`${Q}${zJ}`,j=J[H]?.file;Z.set(Q,j?{src:R(j,$),preload:B(J,H,$),dynamicPreload:U2(J,H,$)}:void 0)}return Z.get(Q)}}var xJ="x-gemi-build";var K2="__gemiReload";function O2(J,$,Z,Q){let H=Date.now(),j=function(U){return typeof U==="number"&&H-U>=0&&H-U<Z},Y=function(U){try{let K=U?JSON.parse(U):null;return K&&typeof K==="object"&&!Array.isArray(K)?K:{}}catch{return{}}},W=function(U){let K={};for(let M in U)if(j(U[M]))K[M]=U[M];return K},G=function(U){let K=2166136261;for(let M=0;M<U.length;M++)K=Math.imul(K^U.charCodeAt(M),16777619);return(K>>>0).toString(36)},z=null,C={};try{z=window.sessionStorage,C=Y(z.getItem(J))}catch{z=null}let N=J+":",F="",I="";try{let U=new URL($,window.location.href);F=G(new URL(window.location.href).origin),I=G(U.origin+U.pathname)}catch{}let L=null;try{let U=window.name;if(!I)L=null;else if(U==="")L={};else if(U.indexOf(N)===0){let K=Y(U.slice(N.length)),M=K.m;L=K.o===F&&M&&typeof M==="object"&&!Array.isArray(M)?M:{}}}catch{L=null}if(Q==="tidy"){try{let U=window.name;if(L===null||U.indexOf(N)!==0)return"ok";for(let K in L)if(j(L[K]))return"cooldown";window.name=""}catch{}return"ok"}if(j(C[$])||L&&j(L[I]))return"cooldown";if(!z&&!L)return"storage";if(!Q)return"ok";if(z)try{let U=W(C);U[$]=H;let K=JSON.stringify(U);if(z.setItem(J,K),z.getItem(J)===K)return"ok"}catch{}if(L)try{let U=W(L);U[I]=H;let K=N+JSON.stringify({o:F,m:U});if(window.name=K,window.name===K)return"ok"}catch{}return"storage"}function CJ(J,$=30000){let Z=JSON.stringify("gemi:chunk-reload"),Q=JSON.stringify(`Failed to fetch dynamically imported module: ${J}`);return`var g=${O2.toString()};var r=!1;try{r=navigator.onLine!==!1&&g(${Z},window.location.href,${Number($)},!0)==="ok"}catch(e){}if(r)window.location.reload();else throw new Error(${Q});export {r as ${K2}}`}var x2=new RegExp(`^${LJ}/.+\\.m?js$`);function h(J){return x2.test(J)}function _J(J){if(h(J))return new Response(CJ(J),{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store"}});if(k(J))return new Response("Not found",{status:404});return}function IJ(J){let $=J?.trim();if(!$)return;try{let Z=new URL($);if(Z.protocol!=="https:"&&Z.protocol!=="http:")throw Error("not http(s)");return Z.search="",Z.hash="",Z.href.endsWith("/")?Z.href:`${Z.href}/`}catch{console.error(`GEMI_ASSET_FALLBACK_URL is not an absolute http(s) URL (${JSON.stringify($)}); missing assets are not looked up anywhere else.`);return}}function MJ({base:J,timeoutMs:$=3000,missTtlMs:Z=30000,fetch:Q=fetch,now:H=Date.now}){let j=new Map,Y=(W)=>{if(j.delete(W),j.set(W,H()+Z),j.size>1000)j.delete(j.keys().next().value)};return async(W,G)=>{if(W.method!=="GET"&&W.method!=="HEAD")return;let z=j.get(G);if(z!==void 0){if(z>H())return;j.delete(G)}let C;try{C=new URL(G.replace(/^\/+/,""),J)}catch{return}if(!C.href.startsWith(J))return;let N=new AbortController,F=setTimeout(()=>N.abort(),$),I;try{I=await Q(C.href,{method:W.method,signal:N.signal,redirect:"error"})}catch{Y(G);return}finally{clearTimeout(F)}if(I.status!==200){I.body?.cancel().catch(()=>{}),Y(G);return}let L=Bun.file(G).type,U=new Headers({"Content-Type":L!=="application/octet-stream"&&L||I.headers.get("content-type")||"application/octet-stream","Cache-Control":"public, max-age=31536000, immutable",["x-gemi-asset-fallback"]:"1"}),K=I.headers.get("content-length");if(K&&!I.headers.get("content-encoding"))U.set("Content-Length",K);return new Response(W.method==="HEAD"?null:I.body,{status:200,headers:U})}}var C2=`<!DOCTYPE html>
3
3
  <html lang="en">
4
4
  <head>
5
5
  <meta charset="UTF-8" />
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{Ta as E}from"../chunk-6wrk51tb.js";import{ob as l}from"../chunk-rs3krbw9.js";import{pb as H}from"../chunk-kpww16c7.js";import{$b as I,Cb as g,Db as W,Eb as _,Fb as p,Gb as P,Hb as u,Ib as $,Jb as V,Kb as q,Lb as B,Mb as K,Qb as L,Rb as Q,Sb as T,Wb as U,Xb as y,Yb as F,Zb as C,_b as D,cc as b,fc as f,gc as k,hc as m}from"../chunk-31xknhg0.js";import"../chunk-t3vgqv9a.js";import"../chunk-y10tys3s.js";import"../chunk-bf4wqp2f.js";import"../chunk-hcysexst.js";import{Ee as h}from"../chunk-frjavybg.js";import"../chunk-jp0d4qhn.js";import"../chunk-5399t8zm.js";import{Bf as n,Cf as v,ff as d,gf as s,jh as w,nh as A,rh as R}from"../chunk-r6e5jwjm.js";import"../chunk-t8ghxzva.js";import"../chunk-gk2k76tn.js";import"../chunk-6d807fgx.js";import"../chunk-d8nxkc90.js";import"../chunk-m4wagwhr.js";import"../chunk-xdrnzs3t.js";import"../chunk-ds5adkcf.js";import{hk as M}from"../chunk-g6z6shvz.js";import"../chunk-768yza4f.js";import"../chunk-9a3wbbr6.js";import"../chunk-mcqzgyvf.js";import"../chunk-cgjdxxwy.js";import"../chunk-8wxt3v9r.js";import"../chunk-56z4jd8t.js";import"../chunk-kwvx36xw.js";import"../chunk-c94zdk4r.js";import"../chunk-zbm7njvf.js";import{cm as O,em as J}from"../chunk-24mk3gn3.js";import"../chunk-wfpvsgfy.js";import"../chunk-f1jq1mp9.js";import"../chunk-f7bayqs7.js";import"../chunk-q34hyv6y.js";import"../chunk-5ra8x6ax.js";import"../chunk-qymdnzpy.js";var N=[C,I,E,T,L,k,B,Q,D,y,_,U,f,V,F,H,b,K,q,m,$];class S{config={};providers=[];services=[];serviceInstances=[];serviceTokens=new Set;servicesBooted=!1;models=[];app=new J;boot(){if(this.models.length>0)l(...this.models);else a();this.app.config.merge(this.config),J.setInstance(this.app),this.app.registerMany([...N,...this.providers]),this.registerServices()}registerServices(){let j=this.serviceTokens;this.serviceInstances=[],this.serviceTokens=new Set,this.servicesBooted=!1;let X=new Map;for(let z of this.services){let G=typeof z==="function"?new z:z,x=G.constructor;if(!x.token)throw Error(`Service [${x.name}] is listed in \`services\` but does not declare a \`static token\`.`);let Y=X.get(x.token);if(Y)throw Error(`Services [${Y}] and [${x.name}] both declare the token "${x.token}". Tokens are the container's keys, so they must be unique.`);X.set(x.token,x.name);let Z=x;if(!j.has(x.token)&&this.app.bound(Z))throw Error(`Service [${x.name}] declares the token "${x.token}", which is already bound in the container by the framework or a provider. Binding it would replace that service everywhere, so pick a token nothing else owns.`);this.app.instance(Z,G),this.serviceInstances.push(G),this.serviceTokens.add(x.token)}this.app.setShutdownHooks(this.serviceInstances.map((z)=>({name:`${z.constructor.name}.onShutdown`,shutdown:(G)=>z.onShutdown(G)})))}async waitForBoot(){await this.app.boot(),await this.bootServices(),p(this.app)}async bootServices(){if(this.servicesBooted)return;for(let j of this.serviceInstances)await j.boot();this.servicesBooted=!0}shutdown(j){return this.run(()=>this.app.shutdown(j))}run(j){return O.run(this.app,j)}resolve(j){return this.app.make(j)}apiRoutes(){return this.app.make(A)}viewRoutes(){return this.app.make(w)}domains(){return this.app.make(R)}queue(){return this.app.make(h)}mcpHttp(){return this.app.config.get("route.mcp.remote.enabled")===!0?this.app.make(g):null}sockets(){return this.app.config.get("route.channels")?this.app.make(u):null}globalMiddleware(j){return P(j)}destroy(){if(this.app.resolved(W))this.app.make(W).stop();if(this.app.flush(),J.getInstance()===this.app)J.setInstance(void 0);O.disable()}}function a(){if(Bun.env.NODE_ENV==="production")return;let j=M();if(j.length===0)return;console.warn(`[gemi] ${j.length} model${j.length===1?" is":"s are"} registered, but Kernel.models is empty.
2
+ import{Ta as E}from"../chunk-6wrk51tb.js";import{ob as l}from"../chunk-rs3krbw9.js";import{pb as H}from"../chunk-kpww16c7.js";import{$b as I,Cb as g,Db as W,Eb as _,Fb as p,Gb as P,Hb as u,Ib as $,Jb as V,Kb as q,Lb as B,Mb as K,Qb as L,Rb as Q,Sb as T,Wb as U,Xb as y,Yb as F,Zb as C,_b as D,cc as b,fc as f,gc as k,hc as m}from"../chunk-8dh3s272.js";import"../chunk-8r7w8s60.js";import"../chunk-y10tys3s.js";import"../chunk-bf4wqp2f.js";import"../chunk-hcysexst.js";import{Ee as h}from"../chunk-frjavybg.js";import"../chunk-jp0d4qhn.js";import"../chunk-5399t8zm.js";import{Bf as n,Cf as v,ff as d,gf as s,jh as w,nh as A,rh as R}from"../chunk-r6e5jwjm.js";import"../chunk-t8ghxzva.js";import"../chunk-gk2k76tn.js";import"../chunk-6d807fgx.js";import"../chunk-d8nxkc90.js";import"../chunk-m4wagwhr.js";import"../chunk-xdrnzs3t.js";import"../chunk-ds5adkcf.js";import{hk as M}from"../chunk-g6z6shvz.js";import"../chunk-768yza4f.js";import"../chunk-9a3wbbr6.js";import"../chunk-mcqzgyvf.js";import"../chunk-cgjdxxwy.js";import"../chunk-8wxt3v9r.js";import"../chunk-56z4jd8t.js";import"../chunk-kwvx36xw.js";import"../chunk-c94zdk4r.js";import"../chunk-zbm7njvf.js";import{cm as O,em as J}from"../chunk-24mk3gn3.js";import"../chunk-wfpvsgfy.js";import"../chunk-f1jq1mp9.js";import"../chunk-f7bayqs7.js";import"../chunk-q34hyv6y.js";import"../chunk-5ra8x6ax.js";import"../chunk-qymdnzpy.js";var N=[C,I,E,T,L,k,B,Q,D,y,_,U,f,V,F,H,b,K,q,m,$];class S{config={};providers=[];services=[];serviceInstances=[];serviceTokens=new Set;servicesBooted=!1;models=[];app=new J;boot(){if(this.models.length>0)l(...this.models);else a();this.app.config.merge(this.config),J.setInstance(this.app),this.app.registerMany([...N,...this.providers]),this.registerServices()}registerServices(){let j=this.serviceTokens;this.serviceInstances=[],this.serviceTokens=new Set,this.servicesBooted=!1;let X=new Map;for(let z of this.services){let G=typeof z==="function"?new z:z,x=G.constructor;if(!x.token)throw Error(`Service [${x.name}] is listed in \`services\` but does not declare a \`static token\`.`);let Y=X.get(x.token);if(Y)throw Error(`Services [${Y}] and [${x.name}] both declare the token "${x.token}". Tokens are the container's keys, so they must be unique.`);X.set(x.token,x.name);let Z=x;if(!j.has(x.token)&&this.app.bound(Z))throw Error(`Service [${x.name}] declares the token "${x.token}", which is already bound in the container by the framework or a provider. Binding it would replace that service everywhere, so pick a token nothing else owns.`);this.app.instance(Z,G),this.serviceInstances.push(G),this.serviceTokens.add(x.token)}this.app.setShutdownHooks(this.serviceInstances.map((z)=>({name:`${z.constructor.name}.onShutdown`,shutdown:(G)=>z.onShutdown(G)})))}async waitForBoot(){await this.app.boot(),await this.bootServices(),p(this.app)}async bootServices(){if(this.servicesBooted)return;for(let j of this.serviceInstances)await j.boot();this.servicesBooted=!0}shutdown(j){return this.run(()=>this.app.shutdown(j))}run(j){return O.run(this.app,j)}resolve(j){return this.app.make(j)}apiRoutes(){return this.app.make(A)}viewRoutes(){return this.app.make(w)}domains(){return this.app.make(R)}queue(){return this.app.make(h)}mcpHttp(){return this.app.config.get("route.mcp.remote.enabled")===!0?this.app.make(g):null}sockets(){return this.app.config.get("route.channels")?this.app.make(u):null}globalMiddleware(j){return P(j)}destroy(){if(this.app.resolved(W))this.app.make(W).stop();if(this.app.flush(),J.getInstance()===this.app)J.setInstance(void 0);O.disable()}}function a(){if(Bun.env.NODE_ENV==="production")return;let j=M();if(j.length===0)return;console.warn(`[gemi] ${j.length} model${j.length===1?" is":"s are"} registered, but Kernel.models is empty.
3
3
  Nested relation reads resolve a model by name, so a policy on a subclass that does not own its
4
4
  `+" name is skipped inside every include \u2014 scoped at the root, "+`unscoped in an include, with nothing
5
5
  to notice it. Declaring the modules registers each class under its own name and audits the set:
@@ -1,4 +1,4 @@
1
1
  // @bun
2
- import{Ra as f}from"../chunk-ba1h9pm6.js";import{Sa as A}from"../chunk-jzspg75a.js";import{om as Q,qm as q,rm as w,um as Z,vm as P,wm as y,xm as S,ym as U}from"../chunk-f7bayqs7.js";import{Cm as H}from"../chunk-q34hyv6y.js";import"../chunk-5ra8x6ax.js";import{Km as F}from"../chunk-qymdnzpy.js";var x="/__gemi__/health",$=Symbol.for("gemi.server.health");function V(){let z=globalThis;return z[$]??={lagMs:0,consecutiveBreaches:0,degraded:!1,timer:void 0},z[$]}function W(){let z=V(),B=Q();return{healthy:!B&&!z.degraded,shuttingDown:B,lagMs:z.lagMs,consecutiveBreaches:z.consecutiveBreaches}}function E(z,B){let I=V();I.lagMs=z,I.consecutiveBreaches=z>B.maxLagMs?I.consecutiveBreaches+1:0;let J=I.consecutiveBreaches>=B.breaches;if(J&&!I.degraded)console.warn(`[gemi] Health: degraded (event-loop lag ${Math.round(z)}ms, ${I.consecutiveBreaches} samples in a row over ${B.maxLagMs}ms).`);else if(!J&&I.degraded)console.log(`[gemi] Health: recovered (event-loop lag ${Math.round(z)}ms).`);I.degraded=J}function G(z){let B=V();if(B.timer)return;let I=performance.now()+z.intervalMs;B.timer=setInterval(()=>{let J=performance.now();E(Math.max(0,J-I),z),I=J+z.intervalMs},z.intervalMs),B.timer.unref?.()}function _(z=process.env){return{paths:D(z.GEMI_HEALTH_PATH),intervalMs:O("GEMI_HEALTH_INTERVAL_MS",z.GEMI_HEALTH_INTERVAL_MS,500),maxLagMs:O("GEMI_HEALTH_MAX_LAG_MS",z.GEMI_HEALTH_MAX_LAG_MS,1000),breaches:Math.ceil(O("GEMI_HEALTH_BREACHES",z.GEMI_HEALTH_BREACHES,3))}}function D(z){if(z===void 0||z.trim()==="")return[x];if(z.trim().toLowerCase()==="off")return[];let B=z.split(",").map((J)=>J.trim()).filter(Boolean);if(B.filter((J)=>!J.startsWith("/")).length>0)throw Error(`GEMI_HEALTH_PATH: expected comma-separated paths starting with "/", or "off"; got ${JSON.stringify(z)}.`);return B}function O(z,B,I){if(B===void 0||B.trim()==="")return I;let J=Number(B);if(Number.isFinite(J)&&J>0)return J;return console.warn(`[gemi] Ignoring ${z}="${B}": expected a positive number.`),I}function j(z,B){if(B.length===0)return z;let I=new Set(B);return async(J,K)=>{if(!B.some((b)=>J.url.includes(b))||!I.has(new URL(J.url).pathname))return z(J,K);return y(R(J.method))}}function R(z){let B={"Cache-Control":"no-store","Content-Type":"text/plain; charset=utf-8"};if(z!=="GET"&&z!=="HEAD")return new Response("Method Not Allowed",{status:405,headers:{...B,Allow:"GET, HEAD"}});let{healthy:I,shuttingDown:J}=W();return new Response(z==="HEAD"?null:I?"ok":J?"shutting down":"degraded",{status:I?200:503,headers:B})}var L=Symbol.for("gemi.server.devGeneration"),X={graceMs:1e4,providerTimeoutMs:5000};class Y{app;inFlight=0;waiters=new Set;constructor(z){this.app=z}track(z){return async(B,I)=>{this.inFlight++;try{return await z(B,I)}finally{if(this.inFlight--,this.inFlight===0)this.wake()}}}get pending(){return this.inFlight}async retire({graceMs:z,providerTimeoutMs:B}){try{await this.idle(z),await Promise.resolve().then(()=>this.app.shutdown({timeoutMs:B}))}catch(I){C(I)}}idle(z){if(this.inFlight===0)return Promise.resolve();return new Promise((B)=>{let I=()=>{clearTimeout(J),this.waiters.delete(I),B()},J=setTimeout(I,z);this.waiters.add(I)})}wake(){for(let z of this.waiters)z()}}function N(z,B=X){let I=globalThis,J=I[L];if(I[L]=z,!J||J===z||typeof J.retire!=="function")return Promise.resolve();let K=J.retire.bind(J);return Promise.resolve().then(()=>K(B)).catch(C)}function C(z){console.error("[gemi] Shutting down the application a reload replaced failed:",z)}class k{app;instrumentation;handleSignals;server;stopping;settings;constructor(z){this.app=new A({kernel:z.kernel}),this.handleSignals=z.handleSignals??!0,this.instrumentation=S(z.instrumentation??((B,I)=>I(B)))}async start(){process.env.ROOT_DIR=H();let z=Bun.env.NODE_ENV==="production",B=_();if(z)G(B);let I=j(this.instrumentation,B.paths);if(z){if(this.handleSignals)U(()=>this.stop());this.settings=Z()}try{await this.app.waitForBoot()}catch(J){if(!z)this.app.shutdown({timeoutMs:X.providerTimeoutMs});throw J}if(z){let{httpProd:J}=await import("../chunk-th8cagtz.js");this.server=await J(this.app,I)}else{f();let{httpDev:J}=await import("../chunk-2p5anpf5.js"),K=new Y(this.app);this.server=await J(this.app,K.track(I)),N(K)}return this.server}stop(z={}){let B=this.app.sockets();return this.stopping??=P({server:this.server,closeSockets:B?()=>B.shutdown():void 0,shutdownProviders:(I)=>this.app.shutdown(I),settings:{...this.settings??Z(),...z}}),this.stopping}}export{q as shutdownSignal,W as liveness,Q as isShuttingDown,w as holdShutdown,k as Server};
2
+ import{Ra as f}from"../chunk-ba1h9pm6.js";import{Sa as A}from"../chunk-jzspg75a.js";import{om as Q,qm as q,rm as w,um as Z,vm as P,wm as y,xm as S,ym as U}from"../chunk-f7bayqs7.js";import{Cm as H}from"../chunk-q34hyv6y.js";import"../chunk-5ra8x6ax.js";import{Km as F}from"../chunk-qymdnzpy.js";var x="/__gemi__/health",$=Symbol.for("gemi.server.health");function V(){let z=globalThis;return z[$]??={lagMs:0,consecutiveBreaches:0,degraded:!1,timer:void 0},z[$]}function W(){let z=V(),B=Q();return{healthy:!B&&!z.degraded,shuttingDown:B,lagMs:z.lagMs,consecutiveBreaches:z.consecutiveBreaches}}function E(z,B){let I=V();I.lagMs=z,I.consecutiveBreaches=z>B.maxLagMs?I.consecutiveBreaches+1:0;let J=I.consecutiveBreaches>=B.breaches;if(J&&!I.degraded)console.warn(`[gemi] Health: degraded (event-loop lag ${Math.round(z)}ms, ${I.consecutiveBreaches} samples in a row over ${B.maxLagMs}ms).`);else if(!J&&I.degraded)console.log(`[gemi] Health: recovered (event-loop lag ${Math.round(z)}ms).`);I.degraded=J}function G(z){let B=V();if(B.timer)return;let I=performance.now()+z.intervalMs;B.timer=setInterval(()=>{let J=performance.now();E(Math.max(0,J-I),z),I=J+z.intervalMs},z.intervalMs),B.timer.unref?.()}function _(z=process.env){return{paths:D(z.GEMI_HEALTH_PATH),intervalMs:O("GEMI_HEALTH_INTERVAL_MS",z.GEMI_HEALTH_INTERVAL_MS,500),maxLagMs:O("GEMI_HEALTH_MAX_LAG_MS",z.GEMI_HEALTH_MAX_LAG_MS,1000),breaches:Math.ceil(O("GEMI_HEALTH_BREACHES",z.GEMI_HEALTH_BREACHES,3))}}function D(z){if(z===void 0||z.trim()==="")return[x];if(z.trim().toLowerCase()==="off")return[];let B=z.split(",").map((J)=>J.trim()).filter(Boolean);if(B.filter((J)=>!J.startsWith("/")).length>0)throw Error(`GEMI_HEALTH_PATH: expected comma-separated paths starting with "/", or "off"; got ${JSON.stringify(z)}.`);return B}function O(z,B,I){if(B===void 0||B.trim()==="")return I;let J=Number(B);if(Number.isFinite(J)&&J>0)return J;return console.warn(`[gemi] Ignoring ${z}="${B}": expected a positive number.`),I}function j(z,B){if(B.length===0)return z;let I=new Set(B);return async(J,K)=>{if(!B.some((b)=>J.url.includes(b))||!I.has(new URL(J.url).pathname))return z(J,K);return y(R(J.method))}}function R(z){let B={"Cache-Control":"no-store","Content-Type":"text/plain; charset=utf-8"};if(z!=="GET"&&z!=="HEAD")return new Response("Method Not Allowed",{status:405,headers:{...B,Allow:"GET, HEAD"}});let{healthy:I,shuttingDown:J}=W();return new Response(z==="HEAD"?null:I?"ok":J?"shutting down":"degraded",{status:I?200:503,headers:B})}var L=Symbol.for("gemi.server.devGeneration"),X={graceMs:1e4,providerTimeoutMs:5000};class Y{app;inFlight=0;waiters=new Set;constructor(z){this.app=z}track(z){return async(B,I)=>{this.inFlight++;try{return await z(B,I)}finally{if(this.inFlight--,this.inFlight===0)this.wake()}}}get pending(){return this.inFlight}async retire({graceMs:z,providerTimeoutMs:B}){try{await this.idle(z),await Promise.resolve().then(()=>this.app.shutdown({timeoutMs:B}))}catch(I){C(I)}}idle(z){if(this.inFlight===0)return Promise.resolve();return new Promise((B)=>{let I=()=>{clearTimeout(J),this.waiters.delete(I),B()},J=setTimeout(I,z);this.waiters.add(I)})}wake(){for(let z of this.waiters)z()}}function N(z,B=X){let I=globalThis,J=I[L];if(I[L]=z,!J||J===z||typeof J.retire!=="function")return Promise.resolve();let K=J.retire.bind(J);return Promise.resolve().then(()=>K(B)).catch(C)}function C(z){console.error("[gemi] Shutting down the application a reload replaced failed:",z)}class k{app;instrumentation;handleSignals;server;stopping;settings;constructor(z){this.app=new A({kernel:z.kernel}),this.handleSignals=z.handleSignals??!0,this.instrumentation=S(z.instrumentation??((B,I)=>I(B)))}async start(){process.env.ROOT_DIR=H();let z=Bun.env.NODE_ENV==="production",B=_();if(z)G(B);let I=j(this.instrumentation,B.paths);if(z){if(this.handleSignals)U(()=>this.stop());this.settings=Z()}try{await this.app.waitForBoot()}catch(J){if(!z)this.app.shutdown({timeoutMs:X.providerTimeoutMs});throw J}if(z){let{httpProd:J}=await import("../chunk-rxvp7yeq.js");this.server=await J(this.app,I)}else{f();let{httpDev:J}=await import("../chunk-gzsgc14q.js"),K=new Y(this.app);this.server=await J(this.app,K.track(I)),N(K)}return this.server}stop(z={}){let B=this.app.sockets();return this.stopping??=P({server:this.server,closeSockets:B?()=>B.shutdown():void 0,shutdownProviders:(I)=>this.app.shutdown(I),settings:{...this.settings??Z(),...z}}),this.stopping}}export{q as shutdownSignal,W as liveness,Q as isShuttingDown,w as holdShutdown,k as Server};
3
3
 
4
4
  //# debugId=71A68283FF7878EB64756E2164756E21
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{rb as v9}from"../chunk-g6tqje74.js";import{$b as k9,Ab as q4,Bb as c1,Cb as mZ,Db as cZ,Eb as Y9,Ib as K9,Jb as G9,Kb as z9,Lb as X9,Mb as F9,Nb as M9,Ob as L9,Pb as N9,Qb as D9,Rb as H9,Sb as U9,Tb as g4,Ub as _6,Vb as w,Wb as x9,Xb as O9,Yb as S9,Zb as R9,_b as _9,ac as f9,bc as C9,cc as V9,dc as T9,ec as P9,fc as b9,gc as w9,hc as q9,sb as IZ,tb as yZ,ub as AZ,vb as hZ,wb as EZ,xb as y4,yb as gZ,zb as w4}from"../chunk-31xknhg0.js";import{kc as h4}from"../chunk-t3vgqv9a.js";import"../chunk-y10tys3s.js";import{$d as pZ,_d as uZ,ae as dZ,be as lZ,ce as nZ,de as sZ,ee as oZ,fe as aZ,ge as tZ,he as rZ,ie as eZ,je as W9,ke as Z9,le as $9,me as J9,ne as Q9}from"../chunk-bf4wqp2f.js";import{oe as iZ}from"../chunk-hcysexst.js";import{Ae as TZ,Be as PZ,Ce as bZ,De as wZ,Ee as qZ,Je as vZ,pe as HZ,qe as UZ,re as xZ,se as OZ,te as SZ,ue as RZ,ve as _Z,we as kZ,xe as fZ,ye as CZ,ze as VZ}from"../chunk-frjavybg.js";import{Ke as B9,Le as j9}from"../chunk-jp0d4qhn.js";import"../chunk-5399t8zm.js";import{$f as R8,$g as YZ,Ag as u8,Bg as p8,Cg as d8,Dg as l8,Dh as jZ,Eg as n8,Eh as FZ,Fg as i8,Gg as s8,Lg as U,Mg as m,Ng as o8,Of as J8,Og as a8,Pf as Q8,Pg as t8,Qf as Y8,Qg as r8,Rf as K8,Rg as e8,Sf as G8,Te as N6,Tf as z8,Tg as WZ,Ue as P5,Ug as ZZ,Ve as b5,Vg as $Z,We as w5,Wg as JZ,Ye as q5,Yg as QZ,Zf as O8,_f as S8,af as D6,ag as _8,ah as KZ,bf as x4,bg as k8,bh as GZ,cf as Z6,cg as f8,df as O4,dg as C8,ef as S4,eg as V8,eh as zZ,fg as T8,hg as P8,if as f6,ig as R6,jf as C6,jg as b8,jh as XZ,lf as v5,mf as I5,nf as y5,ng as w8,nh as BZ,of as A5,og as q8,pf as h5,pg as I8,qf as E5,rf as g5,rh as m4,sf as m5,sg as y8,sh as e,tf as c5,tg as A8,uf as o0,ug as h8,vf as u5,vg as E8,wf as p5,xf as d5,xg as g8,yf as l5,yg as m8,zf as n5,zg as c8}from"../chunk-r6e5jwjm.js";import"../chunk-t8ghxzva.js";import"../chunk-gk2k76tn.js";import{$i as U1,Aj as $8,Cj as h1,Qi as b4,Ui as J1,Wi as a,_i as D4,aj as A1,bj as i5,cj as s5,dj as o5,ej as a5,fj as t5,rj as HW,sj as UW,vj as r5,wi as U4,wj as e5,xi as N4,yi as H1,yj as W8,zj as Z8}from"../chunk-6d807fgx.js";import"../chunk-d8nxkc90.js";import{Nj as V}from"../chunk-m4wagwhr.js";import"../chunk-xdrnzs3t.js";import{$j as v1,Zj as N8,_j as D8,ak as H8,bk as d0,ck as U8,dk as x8}from"../chunk-ds5adkcf.js";import{jk as F8,kk as M8,lk as L8}from"../chunk-g6z6shvz.js";import"../chunk-768yza4f.js";import{Uk as v8}from"../chunk-9a3wbbr6.js";import{Wk as X8,Xk as B8,Yk as j8}from"../chunk-mcqzgyvf.js";import"../chunk-cgjdxxwy.js";import"../chunk-8wxt3v9r.js";import"../chunk-56z4jd8t.js";import"../chunk-kwvx36xw.js";import{Sl as _4,Tl as MZ,Ul as LZ,Vl as NZ,Xl as DZ}from"../chunk-c94zdk4r.js";import"../chunk-zbm7njvf.js";import{fm as _}from"../chunk-24mk3gn3.js";import"../chunk-wfpvsgfy.js";import"../chunk-f1jq1mp9.js";import"../chunk-f7bayqs7.js";import"../chunk-q34hyv6y.js";import"../chunk-5ra8x6ax.js";import{Km as y1}from"../chunk-qymdnzpy.js";import{Buffer as a0}from"buffer";class t0 extends U1{client;config;constructor(...W){super();this.config=W}async connect(){let W=await import("../chunk-bxtv9am0.js");return this.client??=new W.S3Client(...this.config),{sdk:W,client:this.client}}async put(W,{signal:Z}={}){Z?.throwIfAborted();let $,J,Q,Y=process.env.BUCKET_NAME;if(W instanceof Blob)$=W,Q=`${Bun.randomUUIDv7()}.${W.type.split("/")[1].split(";")[0]}`,J=W.type;else $=W.body,Q=W.name,Y=W.bucket??Y,J=W.contentType||($ instanceof Blob||$ instanceof File?$.type:void 0);J=J||void 0;let K=$ instanceof a0?$:$ instanceof Blob||$ instanceof File?a0.from(await $.arrayBuffer()):"",{sdk:G,client:z}=await this.connect();return Z?.throwIfAborted(),await z.send(new G.PutObjectCommand({Bucket:Y,Key:Q,Body:K,ContentType:J}),{abortSignal:Z}),Q}async delete(W){let Z=typeof W==="string"?W:W.name,$=(typeof W==="string"?void 0:W.bucket)??process.env.BUCKET_NAME;if(!Z)throw Error("Object name has to be specified");let{sdk:J,client:Q}=await this.connect();try{await Q.send(new J.DeleteObjectCommand({Bucket:$,Key:Z}))}catch(Y){if(Y?.name==="NoSuchKey"||Y?.$metadata?.httpStatusCode===404)return;throw Y}}async*pages(W,{bucket:Z,signal:$}){let{sdk:J,client:Q}=await this.connect(),Y;do{$?.throwIfAborted();let K=await Q.send(new J.ListObjectsV2Command({Bucket:Z??process.env.BUCKET_NAME,Prefix:W,ContinuationToken:Y}),{abortSignal:$});yield(K.Contents??[]).map((G)=>({name:G.Key,size:G.Size??0,lastModified:G.LastModified??new Date(0)})),Y=K.IsTruncated?K.NextContinuationToken:void 0}while(Y)}async*objects(W,Z={}){for await(let $ of this.pages(W,Z))yield*$}async deletePrefix(W,Z={}){D4(W);let $=Z.bucket??process.env.BUCKET_NAME,{sdk:J,client:Q}=await this.connect(),Y=0;for await(let K of this.pages(W,{...Z,bucket:$})){if(K.length===0)continue;Z.signal?.throwIfAborted();let z=(await Q.send(new J.DeleteObjectsCommand({Bucket:$,Delete:{Objects:K.map((X)=>({Key:X.name})),Quiet:!0}}),{abortSignal:Z.signal}))?.Errors??[];if(z.length>0){let X=z[0];throw Error(`S3 could not delete ${z.length} object(s) under "${W}", e.g. "${X.Key}": ${X.Code??"unknown"} ${X.Message??""}`.trim())}Y+=K.length}return Y}async list(W){let{sdk:Z,client:$}=await this.connect();return await $.send(new Z.ListObjectsV2Command({Bucket:process.env.BUCKET_NAME,Prefix:W}))}async fetch(W,{signal:Z}={}){Z?.throwIfAborted();let $=process.env.BUCKET_NAME,J;if(typeof W==="string")J=W;else $=W.bucket??$,J=W.name;if(!J)throw Error("Object name has to be specified");let{sdk:Q,client:Y}=await this.connect();Z?.throwIfAborted();let K=await Y.send(new Q.GetObjectCommand({Bucket:$,Key:J}),{abortSignal:Z}),G=A1(K.Body.transformToWebStream(),Z);return Z?.throwIfAborted(),new Response(G,{headers:{"Content-Type":K.ContentType,"Content-Length":K.ContentLength.toString(),"Cache-Control":"private, max-age=12000, must-revalidate","Last-Modified":K.LastModified?.toUTCString()||"",ETag:K.ETag||""}})}async read(W){let Z=typeof W==="string"?{name:W}:W,$=Z.bucket??process.env.BUCKET_NAME,{name:J,range:Q=null}=Z;if(!J)throw Error("Object name has to be specified");let{sdk:Y,client:K}=await this.connect(),G;try{G=await K.send(new Y.GetObjectCommand({Bucket:$,Key:J,Range:Q?N4(Q):void 0}))}catch(j){if(j?.name==="InvalidRange"||j?.$metadata?.httpStatusCode===416)throw new J1(await this.size({name:J,bucket:$}));if(j?.name==="NoSuchKey"||j?.$metadata?.httpStatusCode===404)throw new a(J);throw j}let z=H1(G.ContentRange),X=Boolean(z)&&G.$metadata?.httpStatusCode===206,B=z?.total??G.ContentLength??0;return{body:G.Body.transformToWebStream(),start:z?.start??0,end:z?.end??B-1,total:B,partial:X,type:G.ContentType??"application/octet-stream",etag:G.ETag||void 0,lastModified:G.LastModified,name:J}}async size(W){let Z=typeof W==="string"?W:W.name,$=(typeof W==="string"?void 0:W.bucket)??process.env.BUCKET_NAME,{sdk:J,client:Q}=await this.connect();try{return(await Q.send(new J.HeadObjectCommand({Bucket:$,Key:Z}))).ContentLength??0}catch(Y){if(Y?.name==="NotFound"||Y?.$metadata?.httpStatusCode===404)throw new a(Z);throw Y}}}import{Buffer as r0}from"buffer";import{Readable as SW}from"stream";function H4(W){return W?.statusCode===404||W?.details?.errorCode==="BlobNotFound"||W?.code==="BlobNotFound"}function RW(W){return W?.statusCode===416||W?.details?.errorCode==="InvalidRange"||W?.code==="InvalidRange"}class e0 extends U1{config;serviceClientPromise=null;constructor(W={}){super();this.config=W}async serviceClient(){if(this.config.serviceClient)return this.config.serviceClient;return this.serviceClientPromise??=(async()=>{let W;try{W=await import("@azure/storage-blob")}catch{throw Error("AzureBlobDriver requires the '@azure/storage-blob' package. Install it with `bun add @azure/storage-blob`, or pass a pre-built `serviceClient`.")}let Z=this.config.connectionString??process.env.AZURE_STORAGE_CONNECTION_STRING;if(this.config.url)return new W.BlobServiceClient(this.config.url,this.config.credential);if(Z)return W.BlobServiceClient.fromConnectionString(Z);throw Error("AzureBlobDriver needs a connection string (AZURE_STORAGE_CONNECTION_STRING), a `url`, or a `serviceClient`.")})(),this.serviceClientPromise}async blob(W,Z){if(!W)throw Error("Object name has to be specified");let $=Z??this.config.container??process.env.BUCKET_NAME;if(!$)throw Error("AzureBlobDriver needs a container name, from `bucket`, the `container` config, or BUCKET_NAME.");return(await this.serviceClient()).getContainerClient($).getBlockBlobClient(W)}async put(W,{signal:Z}={}){Z?.throwIfAborted();let $,J,Q,Y;if(W instanceof Blob)$=W,Q=`${Bun.randomUUIDv7()}.${W.type.split("/")[1].split(";")[0]}`,J=W.type;else $=W.body,Q=W.name,Y=W.bucket,J=W.contentType??($ instanceof Blob||$ instanceof File?$.type:void 0);let K=$ instanceof r0?$:r0.from(await $.arrayBuffer()),G=await this.blob(Q,Y);return Z?.throwIfAborted(),await G.uploadData(K,{blobHTTPHeaders:J?{blobContentType:J}:void 0,abortSignal:Z}),Q}async*objects(W,{bucket:Z,signal:$}={}){$?.throwIfAborted();let J=Z??this.config.container??process.env.BUCKET_NAME;if(!J)throw Error("AzureBlobDriver needs a container name, from `bucket`, the `container` config, or BUCKET_NAME.");let Y=(await this.serviceClient()).getContainerClient(J);for await(let K of Y.listBlobsFlat({prefix:W}))$?.throwIfAborted(),yield{name:K.name,size:K.properties?.contentLength??0,lastModified:K.properties?.lastModified??new Date(0)}}async list(W){let Z=this.config.container??process.env.BUCKET_NAME,J=(await this.serviceClient()).getContainerClient(Z),Q=[];for await(let Y of J.listBlobsFlat({prefix:W}))Q.push(Y.name);return Q}async fetch(W,{signal:Z}={}){Z?.throwIfAborted();let $=await this.download(typeof W==="string"?{name:W}:{name:W.name,bucket:W.bucket},Z);return new Response($.body,{headers:{"Content-Type":$.type,"Content-Length":String($.total),"Cache-Control":"private, max-age=12000, must-revalidate","Last-Modified":$.lastModified?.toUTCString()??"",ETag:$.etag??""}})}async read(W){return this.download(typeof W==="string"?{name:W}:W)}async download(W,Z){let{name:$,bucket:J,range:Q=null}=W,Y=await this.blob($,J);Z?.throwIfAborted();let K,G,z=Q?.kind==="suffix"||Q?.kind==="offset"&&Q.end===null&&Q.start===0;if(Q&&z){let S=await this.size({name:$,bucket:J}),o=U4(Q,S);if(!o)throw new J1(S);K=o.start,G=o.length}else if(Q?.kind==="offset")K=Q.start,G=Q.end===null?void 0:Q.end-Q.start+1;let X;try{X=await Y.download(K,G,Z?{abortSignal:Z}:void 0)}catch(S){if(RW(S))throw new J1(await this.size({name:$,bucket:J}));if(H4(S))throw new a($);throw S}let B=H1(X.contentRange),j=Boolean(B),L=B?.total??X.contentLength??0,H=await _W(X);if(H instanceof ReadableStream)H=A1(H,Z);return Z?.throwIfAborted(),{body:H,start:B?.start??0,end:B?.end??L-1,total:L,partial:j,type:X.contentType??"application/octet-stream",etag:X.etag||void 0,lastModified:X.lastModified,name:$}}async size(W){let Z=typeof W==="string"?W:W.name,$=typeof W==="string"?void 0:W.bucket,J=await this.blob(Z,$);try{return(await J.getProperties()).contentLength??0}catch(Q){if(H4(Q))throw new a(Z);throw Q}}async delete(W){let Z=typeof W==="string"?W:W.name,$=typeof W==="string"?void 0:W.bucket,J=await this.blob(Z,$);try{await J.delete()}catch(Q){if(H4(Q))return;throw Q}}}async function _W(W){if(W.blobBody)return await W.blobBody;if(W.readableStreamBody)return SW.toWeb(W.readableStreamBody);return null}function kW(W){return W}class R4 extends Error{code="ERR_RATE_LIMITER_TIMEOUT";constructor(W){super(`RedisRateLimiter: Redis did not answer within ${W}ms.`);this.name="RedisRateLimiterTimeoutError"}}class E1 extends Error{code="ERR_RATE_LIMITER_DISCONNECTED";constructor(){super("RedisRateLimiter: the Redis client is not connected.");this.name="RedisRateLimiterDisconnectedError"}}var W6=1000,fW=60000,CW=`
2
+ import{rb as v9}from"../chunk-g6tqje74.js";import{$b as k9,Ab as q4,Bb as c1,Cb as mZ,Db as cZ,Eb as Y9,Ib as K9,Jb as G9,Kb as z9,Lb as X9,Mb as F9,Nb as M9,Ob as L9,Pb as N9,Qb as D9,Rb as H9,Sb as U9,Tb as g4,Ub as _6,Vb as w,Wb as x9,Xb as O9,Yb as S9,Zb as R9,_b as _9,ac as f9,bc as C9,cc as V9,dc as T9,ec as P9,fc as b9,gc as w9,hc as q9,sb as IZ,tb as yZ,ub as AZ,vb as hZ,wb as EZ,xb as y4,yb as gZ,zb as w4}from"../chunk-8dh3s272.js";import{kc as h4}from"../chunk-8r7w8s60.js";import"../chunk-y10tys3s.js";import{$d as pZ,_d as uZ,ae as dZ,be as lZ,ce as nZ,de as sZ,ee as oZ,fe as aZ,ge as tZ,he as rZ,ie as eZ,je as W9,ke as Z9,le as $9,me as J9,ne as Q9}from"../chunk-bf4wqp2f.js";import{oe as iZ}from"../chunk-hcysexst.js";import{Ae as TZ,Be as PZ,Ce as bZ,De as wZ,Ee as qZ,Je as vZ,pe as HZ,qe as UZ,re as xZ,se as OZ,te as SZ,ue as RZ,ve as _Z,we as kZ,xe as fZ,ye as CZ,ze as VZ}from"../chunk-frjavybg.js";import{Ke as B9,Le as j9}from"../chunk-jp0d4qhn.js";import"../chunk-5399t8zm.js";import{$f as R8,$g as YZ,Ag as u8,Bg as p8,Cg as d8,Dg as l8,Dh as jZ,Eg as n8,Eh as FZ,Fg as i8,Gg as s8,Lg as U,Mg as m,Ng as o8,Of as J8,Og as a8,Pf as Q8,Pg as t8,Qf as Y8,Qg as r8,Rf as K8,Rg as e8,Sf as G8,Te as N6,Tf as z8,Tg as WZ,Ue as P5,Ug as ZZ,Ve as b5,Vg as $Z,We as w5,Wg as JZ,Ye as q5,Yg as QZ,Zf as O8,_f as S8,af as D6,ag as _8,ah as KZ,bf as x4,bg as k8,bh as GZ,cf as Z6,cg as f8,df as O4,dg as C8,ef as S4,eg as V8,eh as zZ,fg as T8,hg as P8,if as f6,ig as R6,jf as C6,jg as b8,jh as XZ,lf as v5,mf as I5,nf as y5,ng as w8,nh as BZ,of as A5,og as q8,pf as h5,pg as I8,qf as E5,rf as g5,rh as m4,sf as m5,sg as y8,sh as e,tf as c5,tg as A8,uf as o0,ug as h8,vf as u5,vg as E8,wf as p5,xf as d5,xg as g8,yf as l5,yg as m8,zf as n5,zg as c8}from"../chunk-r6e5jwjm.js";import"../chunk-t8ghxzva.js";import"../chunk-gk2k76tn.js";import{$i as U1,Aj as $8,Cj as h1,Qi as b4,Ui as J1,Wi as a,_i as D4,aj as A1,bj as i5,cj as s5,dj as o5,ej as a5,fj as t5,rj as HW,sj as UW,vj as r5,wi as U4,wj as e5,xi as N4,yi as H1,yj as W8,zj as Z8}from"../chunk-6d807fgx.js";import"../chunk-d8nxkc90.js";import{Nj as V}from"../chunk-m4wagwhr.js";import"../chunk-xdrnzs3t.js";import{$j as v1,Zj as N8,_j as D8,ak as H8,bk as d0,ck as U8,dk as x8}from"../chunk-ds5adkcf.js";import{jk as F8,kk as M8,lk as L8}from"../chunk-g6z6shvz.js";import"../chunk-768yza4f.js";import{Uk as v8}from"../chunk-9a3wbbr6.js";import{Wk as X8,Xk as B8,Yk as j8}from"../chunk-mcqzgyvf.js";import"../chunk-cgjdxxwy.js";import"../chunk-8wxt3v9r.js";import"../chunk-56z4jd8t.js";import"../chunk-kwvx36xw.js";import{Sl as _4,Tl as MZ,Ul as LZ,Vl as NZ,Xl as DZ}from"../chunk-c94zdk4r.js";import"../chunk-zbm7njvf.js";import{fm as _}from"../chunk-24mk3gn3.js";import"../chunk-wfpvsgfy.js";import"../chunk-f1jq1mp9.js";import"../chunk-f7bayqs7.js";import"../chunk-q34hyv6y.js";import"../chunk-5ra8x6ax.js";import{Km as y1}from"../chunk-qymdnzpy.js";import{Buffer as a0}from"buffer";class t0 extends U1{client;config;constructor(...W){super();this.config=W}async connect(){let W=await import("../chunk-bxtv9am0.js");return this.client??=new W.S3Client(...this.config),{sdk:W,client:this.client}}async put(W,{signal:Z}={}){Z?.throwIfAborted();let $,J,Q,Y=process.env.BUCKET_NAME;if(W instanceof Blob)$=W,Q=`${Bun.randomUUIDv7()}.${W.type.split("/")[1].split(";")[0]}`,J=W.type;else $=W.body,Q=W.name,Y=W.bucket??Y,J=W.contentType||($ instanceof Blob||$ instanceof File?$.type:void 0);J=J||void 0;let K=$ instanceof a0?$:$ instanceof Blob||$ instanceof File?a0.from(await $.arrayBuffer()):"",{sdk:G,client:z}=await this.connect();return Z?.throwIfAborted(),await z.send(new G.PutObjectCommand({Bucket:Y,Key:Q,Body:K,ContentType:J}),{abortSignal:Z}),Q}async delete(W){let Z=typeof W==="string"?W:W.name,$=(typeof W==="string"?void 0:W.bucket)??process.env.BUCKET_NAME;if(!Z)throw Error("Object name has to be specified");let{sdk:J,client:Q}=await this.connect();try{await Q.send(new J.DeleteObjectCommand({Bucket:$,Key:Z}))}catch(Y){if(Y?.name==="NoSuchKey"||Y?.$metadata?.httpStatusCode===404)return;throw Y}}async*pages(W,{bucket:Z,signal:$}){let{sdk:J,client:Q}=await this.connect(),Y;do{$?.throwIfAborted();let K=await Q.send(new J.ListObjectsV2Command({Bucket:Z??process.env.BUCKET_NAME,Prefix:W,ContinuationToken:Y}),{abortSignal:$});yield(K.Contents??[]).map((G)=>({name:G.Key,size:G.Size??0,lastModified:G.LastModified??new Date(0)})),Y=K.IsTruncated?K.NextContinuationToken:void 0}while(Y)}async*objects(W,Z={}){for await(let $ of this.pages(W,Z))yield*$}async deletePrefix(W,Z={}){D4(W);let $=Z.bucket??process.env.BUCKET_NAME,{sdk:J,client:Q}=await this.connect(),Y=0;for await(let K of this.pages(W,{...Z,bucket:$})){if(K.length===0)continue;Z.signal?.throwIfAborted();let z=(await Q.send(new J.DeleteObjectsCommand({Bucket:$,Delete:{Objects:K.map((X)=>({Key:X.name})),Quiet:!0}}),{abortSignal:Z.signal}))?.Errors??[];if(z.length>0){let X=z[0];throw Error(`S3 could not delete ${z.length} object(s) under "${W}", e.g. "${X.Key}": ${X.Code??"unknown"} ${X.Message??""}`.trim())}Y+=K.length}return Y}async list(W){let{sdk:Z,client:$}=await this.connect();return await $.send(new Z.ListObjectsV2Command({Bucket:process.env.BUCKET_NAME,Prefix:W}))}async fetch(W,{signal:Z}={}){Z?.throwIfAborted();let $=process.env.BUCKET_NAME,J;if(typeof W==="string")J=W;else $=W.bucket??$,J=W.name;if(!J)throw Error("Object name has to be specified");let{sdk:Q,client:Y}=await this.connect();Z?.throwIfAborted();let K=await Y.send(new Q.GetObjectCommand({Bucket:$,Key:J}),{abortSignal:Z}),G=A1(K.Body.transformToWebStream(),Z);return Z?.throwIfAborted(),new Response(G,{headers:{"Content-Type":K.ContentType,"Content-Length":K.ContentLength.toString(),"Cache-Control":"private, max-age=12000, must-revalidate","Last-Modified":K.LastModified?.toUTCString()||"",ETag:K.ETag||""}})}async read(W){let Z=typeof W==="string"?{name:W}:W,$=Z.bucket??process.env.BUCKET_NAME,{name:J,range:Q=null}=Z;if(!J)throw Error("Object name has to be specified");let{sdk:Y,client:K}=await this.connect(),G;try{G=await K.send(new Y.GetObjectCommand({Bucket:$,Key:J,Range:Q?N4(Q):void 0}))}catch(j){if(j?.name==="InvalidRange"||j?.$metadata?.httpStatusCode===416)throw new J1(await this.size({name:J,bucket:$}));if(j?.name==="NoSuchKey"||j?.$metadata?.httpStatusCode===404)throw new a(J);throw j}let z=H1(G.ContentRange),X=Boolean(z)&&G.$metadata?.httpStatusCode===206,B=z?.total??G.ContentLength??0;return{body:G.Body.transformToWebStream(),start:z?.start??0,end:z?.end??B-1,total:B,partial:X,type:G.ContentType??"application/octet-stream",etag:G.ETag||void 0,lastModified:G.LastModified,name:J}}async size(W){let Z=typeof W==="string"?W:W.name,$=(typeof W==="string"?void 0:W.bucket)??process.env.BUCKET_NAME,{sdk:J,client:Q}=await this.connect();try{return(await Q.send(new J.HeadObjectCommand({Bucket:$,Key:Z}))).ContentLength??0}catch(Y){if(Y?.name==="NotFound"||Y?.$metadata?.httpStatusCode===404)throw new a(Z);throw Y}}}import{Buffer as r0}from"buffer";import{Readable as SW}from"stream";function H4(W){return W?.statusCode===404||W?.details?.errorCode==="BlobNotFound"||W?.code==="BlobNotFound"}function RW(W){return W?.statusCode===416||W?.details?.errorCode==="InvalidRange"||W?.code==="InvalidRange"}class e0 extends U1{config;serviceClientPromise=null;constructor(W={}){super();this.config=W}async serviceClient(){if(this.config.serviceClient)return this.config.serviceClient;return this.serviceClientPromise??=(async()=>{let W;try{W=await import("@azure/storage-blob")}catch{throw Error("AzureBlobDriver requires the '@azure/storage-blob' package. Install it with `bun add @azure/storage-blob`, or pass a pre-built `serviceClient`.")}let Z=this.config.connectionString??process.env.AZURE_STORAGE_CONNECTION_STRING;if(this.config.url)return new W.BlobServiceClient(this.config.url,this.config.credential);if(Z)return W.BlobServiceClient.fromConnectionString(Z);throw Error("AzureBlobDriver needs a connection string (AZURE_STORAGE_CONNECTION_STRING), a `url`, or a `serviceClient`.")})(),this.serviceClientPromise}async blob(W,Z){if(!W)throw Error("Object name has to be specified");let $=Z??this.config.container??process.env.BUCKET_NAME;if(!$)throw Error("AzureBlobDriver needs a container name, from `bucket`, the `container` config, or BUCKET_NAME.");return(await this.serviceClient()).getContainerClient($).getBlockBlobClient(W)}async put(W,{signal:Z}={}){Z?.throwIfAborted();let $,J,Q,Y;if(W instanceof Blob)$=W,Q=`${Bun.randomUUIDv7()}.${W.type.split("/")[1].split(";")[0]}`,J=W.type;else $=W.body,Q=W.name,Y=W.bucket,J=W.contentType??($ instanceof Blob||$ instanceof File?$.type:void 0);let K=$ instanceof r0?$:r0.from(await $.arrayBuffer()),G=await this.blob(Q,Y);return Z?.throwIfAborted(),await G.uploadData(K,{blobHTTPHeaders:J?{blobContentType:J}:void 0,abortSignal:Z}),Q}async*objects(W,{bucket:Z,signal:$}={}){$?.throwIfAborted();let J=Z??this.config.container??process.env.BUCKET_NAME;if(!J)throw Error("AzureBlobDriver needs a container name, from `bucket`, the `container` config, or BUCKET_NAME.");let Y=(await this.serviceClient()).getContainerClient(J);for await(let K of Y.listBlobsFlat({prefix:W}))$?.throwIfAborted(),yield{name:K.name,size:K.properties?.contentLength??0,lastModified:K.properties?.lastModified??new Date(0)}}async list(W){let Z=this.config.container??process.env.BUCKET_NAME,J=(await this.serviceClient()).getContainerClient(Z),Q=[];for await(let Y of J.listBlobsFlat({prefix:W}))Q.push(Y.name);return Q}async fetch(W,{signal:Z}={}){Z?.throwIfAborted();let $=await this.download(typeof W==="string"?{name:W}:{name:W.name,bucket:W.bucket},Z);return new Response($.body,{headers:{"Content-Type":$.type,"Content-Length":String($.total),"Cache-Control":"private, max-age=12000, must-revalidate","Last-Modified":$.lastModified?.toUTCString()??"",ETag:$.etag??""}})}async read(W){return this.download(typeof W==="string"?{name:W}:W)}async download(W,Z){let{name:$,bucket:J,range:Q=null}=W,Y=await this.blob($,J);Z?.throwIfAborted();let K,G,z=Q?.kind==="suffix"||Q?.kind==="offset"&&Q.end===null&&Q.start===0;if(Q&&z){let S=await this.size({name:$,bucket:J}),o=U4(Q,S);if(!o)throw new J1(S);K=o.start,G=o.length}else if(Q?.kind==="offset")K=Q.start,G=Q.end===null?void 0:Q.end-Q.start+1;let X;try{X=await Y.download(K,G,Z?{abortSignal:Z}:void 0)}catch(S){if(RW(S))throw new J1(await this.size({name:$,bucket:J}));if(H4(S))throw new a($);throw S}let B=H1(X.contentRange),j=Boolean(B),L=B?.total??X.contentLength??0,H=await _W(X);if(H instanceof ReadableStream)H=A1(H,Z);return Z?.throwIfAborted(),{body:H,start:B?.start??0,end:B?.end??L-1,total:L,partial:j,type:X.contentType??"application/octet-stream",etag:X.etag||void 0,lastModified:X.lastModified,name:$}}async size(W){let Z=typeof W==="string"?W:W.name,$=typeof W==="string"?void 0:W.bucket,J=await this.blob(Z,$);try{return(await J.getProperties()).contentLength??0}catch(Q){if(H4(Q))throw new a(Z);throw Q}}async delete(W){let Z=typeof W==="string"?W:W.name,$=typeof W==="string"?void 0:W.bucket,J=await this.blob(Z,$);try{await J.delete()}catch(Q){if(H4(Q))return;throw Q}}}async function _W(W){if(W.blobBody)return await W.blobBody;if(W.readableStreamBody)return SW.toWeb(W.readableStreamBody);return null}function kW(W){return W}class R4 extends Error{code="ERR_RATE_LIMITER_TIMEOUT";constructor(W){super(`RedisRateLimiter: Redis did not answer within ${W}ms.`);this.name="RedisRateLimiterTimeoutError"}}class E1 extends Error{code="ERR_RATE_LIMITER_DISCONNECTED";constructor(){super("RedisRateLimiter: the Redis client is not connected.");this.name="RedisRateLimiterDisconnectedError"}}var W6=1000,fW=60000,CW=`
3
3
  local currentKey = KEYS[1]
4
4
  local previousKey = KEYS[2]
5
5
  local limit = tonumber(ARGV[1])
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gemi",
3
- "version": "0.211.0",
3
+ "version": "0.212.0",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "author": "Enes Tufekci <enes@gemijs.dev>",
@@ -1,11 +0,0 @@
1
- // @bun
2
- import{Nd as FQ,Td as _,Ud as n,Vd as eQ,Wd as Q5,Xd as qQ,Yd as v,Zd as x,xd as o,zd as s}from"./chunk-y10tys3s.js";import{Vj as cQ}from"./chunk-xdrnzs3t.js";var x5=4000,O5=60000;function vQ(Q){if(Q===void 0)return;let $=(J,Z)=>typeof J==="number"&&Number.isFinite(J)&&J>=Z;if(!Q||!$(Q.patienceMs,0)||Q.initialWaitMs!==void 0&&!$(Q.initialWaitMs,1)||Q.maxWaitMs!==void 0&&!$(Q.maxWaitMs,1))throw Error(`The provider's retry policy ${JSON.stringify(Q)} is not usable: patienceMs has to be a number of milliseconds (0 or more), and initialWaitMs and maxWaitMs above 0.`)}function ZQ(Q,$,J,Z,Y){let G=Q.patienceMs-Z;if(G<=0)return;let V=Q.maxWaitMs??O5,z=Q.initialWaitMs??x5,j=J!==void 0?Math.min(J,V):Math.round(Math.min(V,z*2**$)*(0.5+Y()*0.5));return Math.min(j,G)}var S5=500,hQ=20000;function M5(Q,$){if(!Q)return;let J=Q.trim();if(/^\d+(\.\d+)?$/.test(J))return Math.max(0,Number(J)*1000);let Z=Date.parse(J);if(Number.isNaN(Z))return;return Math.max(0,Z-$)}function i(Q,$){let J=Math.min(hQ,S5*2**Q);return Math.round(J*(0.5+$()*0.5))}function _5(Q){return Q===429||Q===408||Q===409||Q>=500}function R5(Q,$){return _5(Q)&&x($).retryable}function bQ(Q){return Q.reason??new DOMException("The operation was aborted.","AbortError")}function yQ(Q,$){return new Promise((J,Z)=>{let Y=setTimeout(J,Q);$?.addEventListener("abort",()=>{clearTimeout(Y),Z(bQ($))},{once:!0})})}async function YQ(Q,$,J=yQ){if(!$)return await J(Q);$.throwIfAborted();let Z;try{await Promise.race([J(Q,$),new Promise((Y,G)=>{Z=()=>G(bQ($)),$.addEventListener("abort",Z,{once:!0})})])}finally{if(Z)$.removeEventListener("abort",Z)}}async function u(Q,$,J){let Z=J.fetchImpl??((W,X)=>fetch(W,X)),Y=J.sleep??yQ,G=J.random??Math.random,V=J.now??Date.now,z=Math.max(0,J.maxRetries),j=J.startedAt??V(),K=J.retry,B=(W,X,q,U)=>{let O=V()-j;try{J.onRetry?.({attempt:X+1,maxRetries:z,error:x(q),...v(q),timedOut:U,delayMs:W,elapsedMs:O,...K?{remainingMs:Math.max(0,K.patienceMs-O-W)}:{}})}catch{}return YQ(W,J.signal,Y)},H=(W,X)=>K?ZQ(K,W-z,X,V()-j,G):void 0;for(let W=0;;W++){J.signal?.throwIfAborted();let X=new AbortController,q=()=>X.abort(J.signal?.reason);J.signal?.addEventListener("abort",q,{once:!0});let U=!1,O=J.timeoutMs>0?setTimeout(()=>{U=!0,X.abort()},J.timeoutMs):void 0,N;try{N=await Z(Q,{...$,signal:X.signal})}catch(R){if(O!==void 0)clearTimeout(O);if(J.signal?.removeEventListener("abort",q),J.signal?.aborted)throw R;let I=U?new n(J.timeoutMs):R;if(U&&J.retryTimeouts===!1)throw I;let A=W<z?i(W,G):H(W,void 0);if(A===void 0)throw I;await B(A,W,I,U);continue}if(O!==void 0)clearTimeout(O);if(N.ok)return N;J.signal?.removeEventListener("abort",q);let S=await I5(N),P=new _(N.status,S,N.headers.get("x-request-id")??N.headers.get("request-id")??void 0,M5(N.headers.get("retry-after"),V()));if(!R5(N.status,P))throw P;let y=P.retryAfter??(N.status===429?x(P).retryAfter:void 0),w=W>=z?H(W,y):y===void 0?i(W,G):Math.min(y,hQ);if(w===void 0)throw P;await B(w,W,P,!1)}}async function I5(Q){let $;try{$=await Q.text()}catch{return null}try{return JSON.parse($)}catch{return $}}function fQ(Q,$,J){let Z=$.idleMs>0?$.idleMs:0,Y=$.maxMs>0?$.maxMs:0;if(!Q||!Z&&!Y)return Q;let G=Y?performance.now()+Y:1/0,V=Q.getReader();return new ReadableStream({async pull(z){let j,K,B=Math.max(0,G-performance.now()),H=!Z||B<=Z,W=H?B:Z,X=new Promise((q,U)=>{j=setTimeout(()=>{K=H?J.max():J.idle(),U(K)},W)});try{let q=await Promise.race([V.read(),X]);if(q.done)z.close();else z.enqueue(q.value)}catch(q){let U=K??q;z.error(U),V.cancel(U).catch(()=>{})}finally{clearTimeout(j)}},cancel(z){return V.cancel(z)}},{highWaterMark:0})}var WQ=30000,gQ=10,uQ=7200,A5=600,E5="gpt-live-transcribe";function T5(Q){return Q.type==="transcription"}function w5(Q){if(Q.language!==void 0&&Q.languages!==void 0)throw TypeError("A transcription session takes `languages` or `language`, not both (gpt-live-transcribe reads `languages`).");for(let Y of Q.keywords??[])if(/[<>\r\n]/.test(Y))throw TypeError(`Transcription keywords must be one line without "<" or ">", got ${JSON.stringify(Y)}.`);let $={model:Q.model??E5};if(Q.prompt!==void 0)$.prompt=Q.prompt;if(Q.keywords?.length)$.keywords=Q.keywords;if(Q.languages?.length)$.languages=Q.languages;if(Q.language!==void 0)$.language=Q.language;if(Q.delay!==void 0)$.delay=Q.delay;let J={transcription:$,turn_detection:Q.turnDetection?mQ(Q.turnDetection):null};if(Q.noiseReduction!==void 0)J.noise_reduction=Q.noiseReduction&&{type:Q.noiseReduction};let Z={type:"transcription",audio:{input:J}};if(Q.logprobs)Z.include=["item.input_audio_transcription.logprobs"];return{...Z,...Q.vendor}}function k5(Q){if(!Q)return{type:"object",properties:{}};return cQ(Q)?Q.toJSONSchema():Q}function r(Q,$){if(T5(Q))return w5(Q);let J={type:"realtime"},Z=Q.model??$;if(Z)J.model=Z;if(Q.instructions!==void 0)J.instructions=Q.instructions;if(Q.outputModalities)J.output_modalities=Q.outputModalities;if(Q.maxOutputTokens!==void 0)J.max_output_tokens=Q.maxOutputTokens;if(Q.truncation!==void 0)J.truncation=Q.truncation;if(Q.tools)J.tools=Q.tools.map((V)=>({type:"function",name:V.name,...V.description?{description:V.description}:{},parameters:k5(V.parameters)}));if(Q.toolChoice!==void 0)J.tool_choice=typeof Q.toolChoice==="string"?Q.toolChoice:{type:"function",name:Q.toolChoice.name};let Y={};if(Q.turnDetection!==void 0)Y.turn_detection=Q.turnDetection&&mQ(Q.turnDetection);if(Q.transcription!==void 0)Y.transcription=Q.transcription;if(Q.noiseReduction!==void 0)Y.noise_reduction=Q.noiseReduction&&{type:Q.noiseReduction};let G={};if(Q.voice!==void 0)G.voice=Q.voice;if(Q.speed!==void 0)G.speed=Q.speed;if(Object.keys(Y).length||Object.keys(G).length)J.audio={...Object.keys(Y).length?{input:Y}:{},...Object.keys(G).length?{output:G}:{}};return{...J,...Q.vendor}}function mQ(Q){let $={type:Q.type};if(Q.createResponse!==void 0)$.create_response=Q.createResponse;if(Q.interruptResponse!==void 0)$.interrupt_response=Q.interruptResponse;if(Q.type==="semantic_vad"){if(Q.eagerness!==void 0)$.eagerness=Q.eagerness}else{if(Q.threshold!==void 0)$.threshold=Q.threshold;if(Q.prefixPaddingMs!==void 0)$.prefix_padding_ms=Q.prefixPaddingMs;if(Q.silenceDurationMs!==void 0)$.silence_duration_ms=Q.silenceDurationMs;if(Q.idleTimeoutMs!==void 0)$.idle_timeout_ms=Q.idleTimeoutMs}return $}function VQ(Q){let $=Number(Q?.input_tokens??0),J=Number(Q?.output_tokens??0),Z={inputTokens:$,outputTokens:J,totalTokens:Number(Q?.total_tokens??$+J)},Y=Q?.input_token_details??Q?.input_tokens_details,G=Q?.output_token_details??Q?.output_tokens_details;if(typeof Y?.cached_tokens==="number")Z.cachedInputTokens=Y.cached_tokens;if(typeof Y?.audio_tokens==="number")Z.audioInputTokens=Y.audio_tokens;let V=Y?.cached_tokens_details?.audio_tokens;if(typeof V==="number")Z.cachedAudioInputTokens=V;if(typeof Y?.image_tokens==="number"&&Y.image_tokens>0)Z.imageInputTokens=Y.image_tokens;if(typeof G?.audio_tokens==="number")Z.audioOutputTokens=G.audio_tokens;return Z}class c extends Error{code;retryable;status;constructor(Q,$={}){super(Q.message,{cause:$.cause});if(this.name="RealtimeRequestError",this.code=Q.code,this.retryable=Q.retryable,$.status!==void 0)this.status=$.status}}var v5=60;class a{model;target;options;constructor(Q,$){this.target=Q,this.options=$,this.model=$.model}url(Q){return`${this.target.base}/realtime${Q}${this.target.query}`}sidebandUrl(Q){let $=this.target.base.replace(/^http(s?):/i,(Z,Y)=>`ws${Y}:`),J=this.target.query?`${this.target.query}&`:"?";return`${$}/realtime${J}call_id=${encodeURIComponent(Q)}`}async createCall(Q){let $=Q.flow??this.options.callFlow??"unified",J,Z;if($==="ephemeral")J={authorization:`Bearer ${(await this.clientSecret({session:Q.session,ttlSeconds:v5,signal:Q.signal})).value}`,"content-type":"application/sdp"},Z=Q.sdp;else{let j=new FormData;j.set("sdp",Q.sdp),j.set("session",JSON.stringify(r(Q.session??{},this.model))),J=await this.target.headers(),Z=j}if(Q.safetyIdentifier)J["OpenAI-Safety-Identifier"]=Q.safetyIdentifier;let Y=this.url("/calls"),G=await this.request(Q.webrtcFilter?`${Y}${Y.includes("?")?"&":"?"}webrtcfilter=on`:Y,{method:"POST",headers:J,body:Z},Q.signal),V=await G.text(),z=b5(G);if(!z)throw new c({code:"provider_error",message:"The provider started a realtime call but did not say which one (no Location).",retryable:!1});return{sdpAnswer:V,callId:z}}async clientSecret(Q={}){let $=Q.ttlSeconds??A5;if(!Number.isInteger($)||$<gQ||$>uQ)throw RangeError(`ttlSeconds must be a whole number from ${gQ} to ${uQ}, got ${$}.`);let J={...await this.target.headers(),"content-type":"application/json"};if(Q.safetyIdentifier)J["OpenAI-Safety-Identifier"]=Q.safetyIdentifier;let Y=await(await this.request(this.url("/client_secrets"),{method:"POST",headers:J,body:JSON.stringify({expires_after:{anchor:"created_at",seconds:$},session:r(Q.session??{},this.model)})},Q.signal)).json();if(typeof Y?.value!=="string")throw new c({code:"provider_error",message:"The provider answered a client secret request with no secret.",retryable:!1});return{value:Y.value,expiresAt:Number(Y.expires_at??0),session:Y.session,callsUrl:this.url("/calls")}}async hangup(Q,$={}){try{await this.request(this.url(`/calls/${encodeURIComponent(Q)}/hangup`),{method:"POST",headers:await this.target.headers()},$.signal)}catch(J){if(h5(J,Q))return;throw J}}sideband(Q,$={}){return new GQ({...$,callId:Q,url:this.sidebandUrl(Q),headers:this.target.headers,webSocket:$.webSocket??this.options.webSocket,hangup:()=>this.hangup(Q)})}async request(Q,$,J){try{return await u(Q,$,{maxRetries:this.target.maxRetries,timeoutMs:this.target.timeoutMs,retryTimeouts:!1,signal:J,fetchImpl:this.options.fetchImpl})}catch(Z){if(J?.aborted)throw Z;throw new c(x(Z),{cause:Z,...Z instanceof _?{status:Z.status}:{}})}}}function h5(Q,$){if(!(Q instanceof c)||Q.status!==404)return!1;let J=Q.cause instanceof _?Q.cause.body:void 0,Z=J?.error??J,Y=String(Z?.code??"").toLowerCase(),G=String(Z?.message??"").toLowerCase();if(Y.includes("call"))return!0;if(G.includes($.toLowerCase()))return!0;return/\bcall\b/.test(G)&&/not (be )?found|does not exist|no longer|ended/.test(G)}function b5(Q){let $=Q.headers.get("location");if(!$)return;let J=$.split("?")[0].replace(/\/+$/,""),Z=J.slice(J.lastIndexOf("/")+1);return Z?decodeURIComponent(Z):void 0}var y5={"response.audio_transcript.delta":"response.output_audio_transcript.delta","response.audio_transcript.done":"response.output_audio_transcript.done","response.text.delta":"response.output_text.delta","response.text.done":"response.output_text.done","response.audio.delta":"response.output_audio.delta","response.audio.done":"response.output_audio.done"};function f5(Q){if(typeof Q!=="string")return;let $;try{$=JSON.parse(Q)}catch{return}if(!$||typeof $!=="object"||typeof $.type!=="string")return;let J=y5[$.type];if(J)$.type=J;if($.type==="response.done"&&$.response?.usage)$.usage=VQ($.response.usage);if($.type==="conversation.item.input_audio_transcription.completed"&&$.usage)if($.usage.type==="duration"){let Z=Number($.usage.seconds);if(Number.isFinite(Z))$.transcriptionSeconds=Z}else $.transcriptionUsage=VQ($.usage);return $}var dQ=1,g5=500;function u5(Q,$){let J=globalThis.WebSocket;if(!J)throw Error("No global WebSocket: the realtime sideband needs Bun or Node 22+.");return new J(Q,{headers:$.headers})}class GQ{callId;ready;closed;init;socket;finalEvent;outbox=[];subscribers=new Set;listeners=new Set;backlog=[];closing=!1;finished=!1;everOpened=!1;failures=0;resolveReady;rejectReady;resolveClosed;constructor(Q){this.init=Q,this.callId=Q.callId,this.ready=new Promise(($,J)=>{this.resolveReady=$,this.rejectReady=J}),this.ready.catch(()=>{}),this.closed=new Promise(($)=>this.resolveClosed=$),this.open()}send(Q){if(this.finished||this.closing)return;let $=JSON.stringify(Q);if(this.socket?.readyState===dQ)this.socket.send($);else this.outbox.push($)}updateSession(Q){this.send({type:"session.update",session:r(Q)})}addItem(Q){this.send({type:"conversation.item.create",item:Q})}addNote(Q){this.addItem({type:"message",role:"system",content:[{type:"input_text",text:Q}]})}functionOutput(Q,$){this.addItem({type:"function_call_output",call_id:Q,output:typeof $==="string"?$:JSON.stringify($)})}createResponse(Q={}){let $={};if(Q.instructions!==void 0)$.instructions=Q.instructions;if(Q.toolChoice!==void 0)$.tool_choice=typeof Q.toolChoice==="string"?Q.toolChoice:{type:"function",name:Q.toolChoice.name};if(Q.outputModalities)$.output_modalities=Q.outputModalities;if(Q.conversation)$.conversation=Q.conversation;if(Q.metadata)$.metadata=Q.metadata;Object.assign($,Q.vendor),this.send(Object.keys($).length?{type:"response.create",response:$}:{type:"response.create"})}cancelResponse(Q){this.send(Q?{type:"response.cancel",response_id:Q}:{type:"response.cancel"})}on(Q){return this.listeners.add(Q),()=>this.listeners.delete(Q)}[Symbol.asyncIterator](){let Q={queue:this.backlog??[],done:this.finished};return this.backlog=void 0,this.subscribers.add(Q),{next:async()=>{for(;;){let J=Q.queue.shift();if(J)return{value:J,done:!1};if(Q.done)return this.subscribers.delete(Q),{value:void 0,done:!0};await new Promise((Z)=>Q.wake=Z),Q.wake=void 0}},return:async()=>{return Q.done=!0,Q.queue.length=0,this.subscribers.delete(Q),{value:void 0,done:!0}}}}close(Q=1000,$="closed"){if(this.finished||this.closing)return;if(this.closing=!0,this.socket&&this.socket.readyState<=dQ)this.socket.close(Q,$);else this.finish(Q,$,!0)}async hangup(){try{await this.init.hangup()}catch(Q){if(this.finalEvent&&!this.finalEvent.byClient&&this.finalEvent.code===1000)return;throw Q}this.close(1000,"hangup")}async open(){let Q;try{let J=await this.init.headers();if(this.closing)return this.finish(1000,"closed",!0);Q=(this.init.webSocket??u5)(this.init.url,{headers:J})}catch(J){return this.dropped(1006,J instanceof Error?J.message:String(J),!1)}this.socket=Q;let $=!1;Q.addEventListener("open",()=>{$=!0;let J=this.everOpened;this.everOpened=!0;let Z=this.failures;this.failures=0;for(let Y of this.outbox.splice(0))Q.send(Y);if(this.resolveReady(),J)this.emit({type:"sideband.reconnected",attempt:Z})}),Q.addEventListener("message",(J)=>{let Z=f5(J.data);if(Z)this.emit(Z)}),Q.addEventListener("close",(J)=>{if(this.socket!==Q)return;this.dropped(J.code??1006,J.reason??"",$)}),Q.addEventListener("error",()=>{})}dropped(Q,$,J){if(this.socket=void 0,this.closing)return this.finish(Q,$,!0);let Z=this.init.reconnect?.attempts??3;if(!((Q!==1000||!J)&&this.failures<Z))return this.finish(Q,$,!1);this.failures+=1;let G=(this.init.reconnect?.delayMs??500)*2**(this.failures-1);setTimeout(()=>void this.open(),G)}finish(Q,$,J){if(this.finished)return;this.finished=!0,this.outbox.length=0;let Z={type:"sideband.closed",code:Q,reason:$,byClient:J};this.finalEvent=Z,this.emit(Z);for(let Y of this.subscribers)Y.done=!0,Y.wake?.();if(!this.everOpened)this.rejectReady(Error(`Realtime sideband did not open (${Q} ${$}).`));this.resolveClosed(Z)}emit(Q){if(this.backlog){if(this.backlog.push(Q),this.backlog.length>g5)this.backlog.shift()}for(let $ of this.subscribers){if($.done)continue;$.queue.push(Q),$.wake?.()}for(let $ of this.listeners)try{$(Q)}catch{}}}var iQ=3;function KQ(Q){let $=new Map;for(let J of Q)for(let Z of J.content??[]){if(Z.type!=="file"||!Z.fileId||$.has(Z.fileId))continue;$.set(Z.fileId,{name:Z.name,mimeType:Z.mimeType})}return $}function nQ(Q,$,J=new Map){if(!($ instanceof _))return[];if($.status!==400&&$.status!==404)return[];let Z=BQ($.body);if(!Z)return[];let Y=c5(Q.input);if(Y.length===0)return[];let G=/^input\[(\d+)\]\.content\[(\d+)\]\.file_id$/.exec(Z.param??"");if(G){let K=Q.input[Number(G[1])],B=XQ(K)[Number(G[2])],H=B&&typeof B.file_id==="string"?B.file_id:void 0;if(H)return[H]}let V=Z.message??"",z=lQ(Y.map((K)=>K.fileId).filter((K)=>m5(V,K)));if(z.length>0)return z;let j=/Expected (image type|context stuffing file type) to be a supported format:.*but got \.([a-z0-9]+)\.?\s*$/is.exec(V);if(j){let K=j[1].toLowerCase()==="image type"?"input_image":"input_file",B=j[2].toLowerCase(),H=lQ(Y.filter((X)=>X.type===K).map((X)=>X.fileId)),W=H.filter((X)=>(J.get(X)?.name??"").trim().toLowerCase().endsWith(`.${B}`));if(W.length===1)return W;if(W.length===0&&H.length===1)return H}return[]}function rQ(Q,$,J=new Map){return{...Q,input:Q.input.map((Z)=>{let Y=XQ(Z);if(!Y.some((G)=>pQ(G,$)))return Z;return{...Z,content:Y.map((G)=>pQ(G,$)?{type:"input_text",text:m(J.get(String(G.file_id))?.name)}:G)}})}}function m(Q){return`[${Q?`attachment ${JSON.stringify(Q)}`:"an attachment"} could not be read by the provider and is not shown to you. Tell the user if it matters to the answer; uploading it again may help.]`}function pQ(Q,$){return typeof Q.file_id==="string"&&$.has(Q.file_id)}function XQ(Q){let $=Q?.content;return Array.isArray($)?$:[]}function c5(Q){let $=[];for(let J of Q)for(let Z of XQ(J))if(typeof Z.file_id==="string"&&Z.file_id)$.push({type:String(Z.type),fileId:Z.file_id});return $}function BQ(Q){if(!Q||typeof Q!=="object")return null;let $=Q,J=$.error&&typeof $.error==="object"?$.error:Q;return{message:typeof J.message==="string"?J.message:void 0,param:typeof J.param==="string"?J.param:void 0}}function m5(Q,$){let J=$.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return new RegExp(`(^|[^A-Za-z0-9_-])${J}($|[^A-Za-z0-9_-])`).test(Q)}function lQ(Q){return[...new Set(Q)]}function aQ(Q,$){if(!($ instanceof _))return null;if($.status!==400&&$.status!==404)return null;let J=Q?.input;if(!Array.isArray(J))return null;let Z=BQ($.body)?.message??"",Y=/Item with id '([^']+)' not found/i.exec(Z)?.[1];if(!Y)return null;let G=(V)=>V?.type==="reasoning";if(!J.some((V)=>G(V)&&V.id===Y))return null;return{...Q,input:J.filter((V)=>!G(V))}}async function*zQ(Q){let $="",J="",Z=[],Y,G=()=>{if(Z.length===0&&!J)return null;let j={event:J,data:Z.join(`
3
- `),id:Y};return J="",Z=[],Y=void 0,j.data?j:null},V=(j)=>{let K=j.endsWith("\r")?j.slice(0,-1):j;if(K==="")return G();if(K.startsWith(":"))return null;let B=K.indexOf(":"),H=B===-1?K:K.slice(0,B),W=B===-1?"":K.slice(B+1);if(W.startsWith(" "))W=W.slice(1);if(H==="event")J=W;else if(H==="data")Z.push(W);else if(H==="id")Y=W;return null};for await(let j of Q){$+=j;let K=$.indexOf(`
4
- `);while(K!==-1){let B=$.slice(0,K);$=$.slice(K+1);let H=V(B);if(H)yield H;K=$.indexOf(`
5
- `)}}if($.length>0){let j=V($);if(j)yield j}let z=G();if(z)yield z}async function*sQ(Q,$={}){let J=new Map,Z=new Set,Y,G=!1,V,z=(j,K)=>({type:"finish",reason:j,usage:K,...V?{model:V}:{}});for await(let j of zQ(Q)){if(j.data==="[DONE]")break;let K;try{K=JSON.parse(j.data)}catch{continue}let B=typeof K.type==="string"?K.type:j.event,H=K.response?.model;if(typeof H==="string"&&H)V=H;switch(B){case"response.output_text.delta":{let W=String(K.delta??"");if(!W)break;yield $.structuredOutput?{type:"output-delta",delta:W}:{type:"text-delta",delta:W};break}case"response.reasoning_summary_text.delta":case"response.reasoning_text.delta":{let W=String(K.delta??"");if(!W)break;yield{type:"reasoning-delta",delta:W,id:K.item_id};break}case"response.output_item.added":{let W=K.item;if(!W)break;if(W.type==="function_call"){let X=String(W.id??K.item_id??W.call_id??"");J.set(X,{callId:String(W.call_id??X),name:String(W.name??""),namespace:typeof W.namespace==="string"&&W.namespace?W.namespace:void 0,done:!1})}break}case"response.function_call_arguments.delta":{let W=J.get(String(K.item_id??""));if(!W)break;let X=String(K.delta??"");if(!X)break;yield{type:"tool-call-delta",toolCallId:W.callId,name:W.name,argsDelta:X,...W.namespace?{namespace:W.namespace}:{}};break}case"response.function_call_arguments.done":{let W=String(K.item_id??""),X=J.get(W);if(!X)break;X.done=!0,yield{type:"tool-call",toolCallId:X.callId,name:X.name,args:String(K.arguments??""),...X.namespace?{namespace:X.namespace}:{}};break}case"response.output_item.done":{let W=K.item;if(!W)break;if(W.type==="function_call"){let X=String(W.id??K.item_id??W.call_id??""),q=J.get(X);if(q?.done)break;let U=(typeof W.namespace==="string"?W.namespace:"")||q?.namespace;if(yield{type:"tool-call",toolCallId:String(W.call_id??X),name:String(W.name??q?.name??""),args:String(W.arguments??""),...U?{namespace:U}:{}},q)q.done=!0;break}if(W.type==="tool_search_call"||W.type==="tool_search_output"){if(W.type==="tool_search_call"&&W.arguments!==void 0)Y=W.arguments;let X=d5(W);if(X.loaded.length===0&&X.namespaces.length===0)break;let q=String(W.tool_search_call_id??W.id??"");if(Z.has(q))break;Z.add(q);let U=Y;Y=void 0,yield{type:"tool-search",...X,...U!==void 0&&U!==null?{arguments:U}:{}}}break}case"response.refusal.done":{yield{type:"error",error:{code:"content_filtered",message:String(K.refusal??"The model refused to answer."),retryable:!1}};break}case"response.completed":{G=!0,yield z("stop",HQ(K.response?.usage));break}case"response.incomplete":{G=!0;let W=HQ(K.response?.usage),X=K.response?.incomplete_details?.reason;if(X==="content_filter"){yield{type:"error",error:{code:"content_filtered",message:p5(K.response?.content_filters),retryable:!1}},yield z("error",W);break}yield z(X==="max_output_tokens"?"length":"stop",W);break}case"response.failed":case"error":{G=!0;let W=K.response?.error??K.error??K;yield{type:"error",error:l5(W)},yield z("error",HQ(K.response?.usage));break}}if(G)return}if(!G)yield{type:"error",error:{code:"provider_error",message:"The provider stream ended without a terminal event.",retryable:!0}},yield z("error",M())}function d5(Q){let $=[],J=[];return oQ(Q.results??Q.tools??Q.loaded??Q.output,$,J,0),{loaded:jQ($),namespaces:jQ(J)}}function oQ(Q,$,J,Z){if(!Array.isArray(Q)||Z>4)return;for(let Y of Q){if(typeof Y==="string"){$.push(Y);continue}if(!Y||typeof Y!=="object")continue;let G=Y,V=typeof G.name==="string"?G.name:typeof G.tool_name==="string"?G.tool_name:"",z=G.tools??G.functions;if(Array.isArray(z)){if(V)J.push(V);oQ(z,$,J,Z+1);continue}if(V)$.push(V)}}function jQ(Q){return Q.filter(($,J)=>Q.indexOf($)===J)}function p5(Q){if(!Array.isArray(Q))return"The provider's content filter blocked this request.";let J=[];for(let Z of Q){if(!Z||typeof Z!=="object")continue;let Y=Z,G=Y.content_filter_results;if(!G||typeof G!=="object")continue;for(let[V,z]of Object.entries(G))if(z&&typeof z==="object"&&z.filtered===!0)J.push(`${V} (${String(Y.source_type??"unknown")})`)}return J.length===0?"The provider's content filter blocked this request.":`The provider's content filter blocked this request. Categories: ${jQ(J).join(", ")}.`}function l5(Q){let $=typeof Q?.message==="string"?Q.message:"The provider stream failed.",J=String(Q?.code??"").toLowerCase();if(J==="rate_limit_exceeded")return{code:"rate_limited",message:$,retryable:!0};if(J==="context_length_exceeded")return{code:"context_length_exceeded",message:$,retryable:!1};if(J.includes("content_filter"))return{code:"content_filtered",message:$,retryable:!1};return{code:"provider_error",message:$,retryable:!0}}function M(){return{inputTokens:0,outputTokens:0,totalTokens:0}}function HQ(Q){if(!Q)return M();let $=Number(Q.input_tokens??0),J=Number(Q.output_tokens??0),Z={inputTokens:$,outputTokens:J,totalTokens:Number(Q.total_tokens??$+J)},Y=Q.output_tokens_details?.reasoning_tokens;if(typeof Y==="number")Z.reasoningTokens=Y;let G=Q.input_tokens_details?.cached_tokens;if(typeof G==="number")Z.cachedInputTokens=G;return Z}async function*tQ(Q){if(!Q)return;let $=Q.getReader(),J=new TextDecoder;try{while(!0){let{done:Y,value:G}=await $.read();if(Y)break;if(G)yield J.decode(G,{stream:!0})}let Z=J.decode();if(Z)yield Z}finally{$.releaseLock()}}function t(Q){return{responsesUrl:`${Q.base}/responses${Q.query}`,filesUrl:`${Q.base}/files${Q.query}`,headers:Q.headers,timeoutMs:Q.timeoutMs,streamIdleTimeoutMs:Q.streamIdleTimeoutMs,streamMaxDurationMs:Q.streamMaxDurationMs,maxToolArgumentChars:Q.maxToolArgumentChars,maxRetries:Q.maxRetries,...Q.retry?{retry:Q.retry}:{}}}async function*e(Q,$,J){let Z=J.parse??sQ,Y=$,G=new Set,V=0,z=!1,j=Math.max(0,Q.maxRetries),K=Q.random??Math.random,B,H=(S)=>{if(!B)return S;let P=s(s(M(),B),S.usage);return B=void 0,{...S,usage:P}},W=()=>H({type:"finish",reason:"aborted",usage:M()}),X=Q.streamIdleTimeoutMs??0,q=Q.streamMaxDurationMs??0,U=Q.maxToolArgumentChars??0,O=Q.now??Date.now,N=O();for(let S=0;;S++){let P=new AbortController,y=J.signal?AbortSignal.any([J.signal,P.signal]):P.signal,w;while(w===void 0)try{let C=[],F=()=>{},L=u(Q.responsesUrl,{method:"POST",headers:{...await Q.headers(),"content-type":"application/json"},body:JSON.stringify(Y)},{maxRetries:Q.maxRetries,timeoutMs:Q.timeoutMs,signal:y,fetchImpl:Q.fetchImpl,sleep:Q.sleep,random:Q.random,now:Q.now,startedAt:N,...Q.retry?{retry:Q.retry}:{},onRetry:(k)=>{C.push({type:"retry",...k,phase:"request"}),F()}}),T=L.then(()=>!0,()=>!0);for(;;){let k=new Promise((l)=>F=()=>l(!1)),g=await Promise.race([T,k]);if(yield*C.splice(0),g)break}w=await L}catch(C){let F=Y,L=J.files&&V<iQ?nQ(F,C,J.files).filter((g)=>!G.has(g)):[];if(L.length>0){V++;let g=x(C).message;for(let l of L)G.add(l),yield{type:"file-rejected",fileId:l,message:g,...v(C)};Y=rQ(F,new Set(L),J.files);continue}let T=z?null:aQ(Y,C);if(T){z=!0,Y=T;continue}let k=x(C);if(k.code==="aborted"){yield W();return}yield{type:"error",error:k,...v(C)},yield H({type:"finish",reason:"error",usage:M()});return}let R=[],I=!1,A,kQ=!1,f=new Map;try{let C=fQ(w.body,{idleMs:X,maxMs:q},{idle:()=>{let F=new eQ(X);return P.abort(F),F},max:()=>{let F=new Q5(q);return P.abort(F),F}});for await(let F of Z(tQ(C),{structuredOutput:J.structuredOutput})){if(F.type==="tool-call-delta"){let L=(f.get(F.toolCallId)??0)+F.argsDelta.length;if(f.set(F.toolCallId,L),U>0&&L>U){let T=new qQ(U,F.name,F.toolCallId,L);throw P.abort(T),T}yield F;continue}if(F.type==="tool-call")f.delete(F.toolCallId);if(I){yield F.type==="finish"?H(F):F;continue}if(o(F)){I=!0,yield*R.splice(0),yield F;continue}if(F.type==="error")A=F.error;R.push(F)}}catch(C){kQ=C instanceof n;let F=x(C);if(F.code==="aborted"||J.signal?.aborted){yield W();return}if(I){yield{type:"error",error:F},yield H({type:"finish",reason:"error",usage:M()});return}A=F,R.push({type:"error",error:F,...C instanceof qQ?{toolArgumentsTooLong:C.detail}:{}},{type:"finish",reason:"error",usage:M()})}if(I)return;let p=!A?.retryable||J.signal?.aborted?void 0:S<j?i(S,K):Q.retry?ZQ(Q.retry,S-j,A.retryAfter,O()-N,K):void 0;if(p!==void 0){let C={};for(let L of R){if(L.type==="finish")B=s(B??M(),L.usage);if(L.type==="error")C=v(L)}if(f.size>0)yield{type:"tool-call-discard",toolCallIds:[...f.keys()]};let F=O()-N;yield{type:"retry",attempt:S+1,maxRetries:j,error:A,...C,phase:"stream",timedOut:kQ,delayMs:p,elapsedMs:F,...Q.retry?{remainingMs:Math.max(0,Q.retry.patienceMs-F-p)}:{}};try{await YQ(p,J.signal,Q.sleep)}catch{yield W();return}continue}for(let C of R)yield C.type==="finish"?H(C):C;return}}async function QQ(Q,$,J="user_data"){let Z=new FormData;if(J)Z.set("purpose",J);Z.set("file",$);let G=await(await u(Q.filesUrl,{method:"POST",headers:await Q.headers(),body:Z},{maxRetries:Q.maxRetries,timeoutMs:Q.timeoutMs,fetchImpl:Q.fetchImpl})).json();if(!G?.id)throw Error("The provider accepted the upload but returned no file id.");return G.id}function UQ(Q,$){let{capabilities:J}=$,Z={model:$.model,input:i5(Q.messages,J,Q.tools),stream:!0};if(Q.systemPrompt)Z.instructions=Q.systemPrompt;let Y=$6(Q.tools,J);if(Y.length>0){if(Z.tools=Y,!J.parallelToolCalls)Z.parallel_tool_calls=!1;if(Q.toolChoice!==void 0)Z.tool_choice=typeof Q.toolChoice==="string"?Q.toolChoice:{type:"function",name:Q.toolChoice.name}}if(Q.output)Z.text={format:{type:"json_schema",name:Q.output.name,schema:Q.output.schema,strict:Q.output.strict}};if(Q.reasoning&&J.reasoning)Z.reasoning=Q.reasoning==="none"?{effort:"none"}:{effort:Q.reasoning,summary:"auto"};if(typeof Q.temperature==="number")Z.temperature=Q.temperature;if(typeof Q.maxOutputTokens==="number")Z.max_output_tokens=Q.maxOutputTokens;if(Q.promptCacheKey)Z.prompt_cache_key=Q.promptCacheKey;return Z}function i5(Q,$,J){let Z=[],Y=new Map;if($.toolSearch){for(let G of J??[])if($Q(G))Y.set(G.name,G)}for(let G of Q){let V=G.role,z=!t5.has(G.finishReason),j=[],K=()=>{if(j.length===0)return;Z.push({type:"message",role:V,content:j}),j=[]};for(let B of G.content??[])switch(B.type){case"text":{if(!B.text)break;j.push(h(V,B.text));break}case"output":{if(B.partial)break;j.push(h(V,JSON.stringify(B.value)));break}case"file":{if(V==="assistant")break;let H=CQ(B);if(!$.fileInput){if(H)j.push(h(V,d(B,!1)));break}if(NQ(B,H),B.providerRejected){if(H)j.push(h(V,d(B,!1)));j.push(h(V,m(B.name)));break}if(H)j.push(h(V,d(B,!!B.fileId)));if(B.fileId)j.push(a5(B));break}case"reasoning":{if(K(),!z)break;let H=e5(B);if(H)Z.push(H);break}case"tool-call":{if(B.partial)break;if(K(),$.toolSearch&&Array.isArray(B.toolSearches))for(let W of B.toolSearches)Z.push(...Q6(W,J??[]));let H={type:"function_call",call_id:B.toolCallId,name:String(B.name),arguments:JSON.stringify(B.input??{})};if(B.namespace&&Y.has(B.namespace))H.namespace=B.namespace;Z.push(H);break}case"tool-result":{K(),Z.push({type:"function_call_output",call_id:B.toolCallId,output:PQ(B)});break}}K()}return r5(Z)}var n5="No result was recorded for this tool call. Assume it did not complete.";function r5(Q){let $=new Set,J=new Set,Z=[];for(let G of Q){if(G.type==="function_call"){let V=String(G.call_id);if($.has(V))continue;$.add(V)}else if(G.type==="function_call_output"){let V=String(G.call_id);if(!$.has(V)||J.has(V))continue;J.add(V)}Z.push(G)}if(J.size===$.size)return Z;let Y=[];for(let G of Z){if(Y.push(G),G.type!=="function_call")continue;let V=String(G.call_id);if(J.has(V))continue;J.add(V),Y.push({type:"function_call_output",call_id:V,output:n5})}return Y}function h(Q,$){return{type:Q==="assistant"?"output_text":"input_text",text:$}}function CQ(Q){let $=Q.attachmentId;return typeof $==="string"&&$.startsWith(FQ)?$:void 0}function d(Q,$){let J=[`id=${JSON.stringify(Q.attachmentId)}`];if(Q.name)J.push(`name=${JSON.stringify(Q.name)}`);if(Q.mimeType)J.push(`mimeType=${JSON.stringify(Q.mimeType)}`);let Z=`attachment ${J.join(" ")}`;return $?`[${Z}]`:`[${Z} \u2014 its contents are not shown to you; a tool can read the file by this id]`}function a5(Q){return{type:LQ(Q)?"input_image":"input_file",file_id:Q.fileId}}function LQ(Q){let $=Q.mimeType?.trim().toLowerCase()??"";return $?$.startsWith("image/")&&$!=="image/svg+xml":s5(Q.name)}function NQ(Q,$){if(Q.fileId?.startsWith(FQ))throw Error(`FilePart.fileId holds a gemi attachment id (${Q.fileId}). That field is the *provider's* file id, from \`fileId\` on the upload response; the \`attachmentId\` goes in \`FilePart.attachmentId\`, is shown to the model as text, and is resolved by a tool through \`ctx.attachments\`.`);if(!Q.fileId&&!$)throw Error("FilePart.fileId is empty and there is no `attachmentId` either. `fileId` is the *provider's* file id and `attachmentId` is gemi's (`gemi_att_\u2026`), both from the upload response; an upload always answers at least one, so a part with neither was built from something other than that answer.")}function s5(Q){let $=/\.([a-z0-9]+)$/.exec(Q?.trim().toLowerCase()??"");return $?.[1]!==void 0&&o5.has($[1])}var o5=new Set(["jpeg","jpg","png","gif","webp"]),t5=new Set(["error","aborted","interrupted"]);function e5(Q){if(!Q.id)return null;let $={type:"reasoning",id:Q.id};return $.summary=Q.text?[{type:"summary_text",text:Q.text}]:[],$}function PQ(Q){if(Q.status==="ok"){let $=Q.modelOutput!==void 0?Q.modelOutput:Q.output;return typeof $==="string"?$:JSON.stringify($??null)}if(Q.status==="running"){let $=Q.job?.summary===void 0?"":` Started with: ${JSON.stringify(Q.job.summary)}.`;return`Started background job ${Q.job?.id??"(unknown)"}. It is still running, so there is no result yet: this message will be replaced by the result when it finishes. Do not start it again.${$}`}if(Q.status==="denied"){let $=Q.reason?` Reason given: ${Q.reason}`:"";if(Q.cause==="stopped")return`The run was stopped before this tool call could complete, so it did not run.${$}`;if(Q.cause==="interrupted")return`The run was interrupted (the server stopped) while this tool call was in progress, so its result was lost. It may have run in part or in full: check its effects before repeating it.${$}`;if(Q.cause==="denied-earlier")return`The user already declined this tool call earlier in this conversation, so it did not run and they were not asked again. Do not ask for it again; carry on without it.${$}`;return`The user declined this tool call, so it did not run.${$}`}return`The tool call failed and produced no result. Error (${Q.error?.code??"unknown"}): ${Q.error?.message??"no message"}`}function Q6(Q,$){let J=new Set($5(Q?.loaded)),Z=$5(Q?.namespaces),Y=new Set(Z),G=[];for(let z of $)if($Q(z)){if(!Y.has(z.name))continue;let j=z.tools.filter((K)=>J.size===0||J.has(K.name));if(j.length===0)continue;G.push({type:"namespace",name:z.name,description:z.description,tools:j.map((K)=>b(K,!0))})}else if(z.deferred&&J.has(z.name))G.push(b(z,!0));if(G.length===0)return[];return[{type:"tool_search_call",call_id:null,execution:"server",status:"completed",arguments:Q.arguments&&typeof Q.arguments==="object"?Q.arguments:{paths:Z.length>0?Z:[...J]}},{type:"tool_search_output",call_id:null,execution:"server",status:"completed",tools:G}]}function $5(Q){return Array.isArray(Q)?Q.filter(($)=>typeof $==="string"):[]}function $Q(Q){return Array.isArray(Q.tools)}function $6(Q,$){if(!Q||Q.length===0)return[];if(!$.toolSearch){let Y=[];for(let G of Q)if($Q(G))for(let V of G.tools)Y.push(b(V,!1));else Y.push(b(G,!1));return Y}let J=[],Z=!1;for(let Y of Q)if($Q(Y)){let G=Y.tools.map((V)=>{if(V.deferred)Z=!0;return b(V,!0)});J.push({type:"namespace",name:Y.name,description:Y.description,tools:G})}else{if(Y.deferred)Z=!0;J.push(b(Y,!0))}if(Z)J.push({type:"tool_search"});return J}function b(Q,$){let J={type:"function",name:Q.name,description:Q.description,parameters:Q.parameters,strict:Q.strict};if($&&Q.deferred)J.defer_loading=!0;return J}var J6=64000;function J5(Q,$){let J={model:$.model,max_tokens:Q.maxOutputTokens??J6,messages:z6(Q.messages,$.capabilities),stream:!0},Z=Q.output,Y=!!Z?.strict&&!B6(Z.schema),G=Z&&!Y?H6(Z.schema):void 0,V=[Q.systemPrompt,G].filter(Boolean);if(V.length>0)J.system=[{type:"text",text:V.join(`
6
-
7
- `)}];let z=$.capabilities.reasoning?Q.reasoning:void 0;if(z==="none"){if(/^claude-sonnet-5-5(?:-\d{8})?$/.test($.modelId))J.thinking={type:"between_tools"};J.output_config={effort:"low"}}else if(z)J.thinking={type:"adaptive",display:"summarized"},J.output_config={effort:Y6(z,$.modelId)};else if($.capabilities.reasoning&&Z6(J.messages))J.thinking={type:"adaptive"};if(J.thinking?.type==="adaptive"&&$.blockBinding)J.thinking.block_binding={prefix_mismatch_behavior:"drop_block"};if(Z&&Y)J.output_config={...J.output_config,format:{type:"json_schema",schema:X6(Z.schema)}};let j=O6(Q.tools);if(j.length>0){J.tools=j;let K=j6(Q.toolChoice,$.forcedToolChoice);if(!$.capabilities.parallelToolCalls)K.disable_parallel_tool_use=!0;if(Q.toolChoice!==void 0||K.disable_parallel_tool_use)J.tool_choice=K}return G6(J)}function Z6(Q){return Q.some(($)=>$.content.some((J)=>J.type==="thinking"||J.type==="redacted_thinking"))}var DQ="thinking-binding-controls-2026-08-01";function Z5(Q){if(/bound to a different conversation|Invalid `signature` in `thinking` block/i.test(Q))return"thinking";if(/schema is too complex/i.test(Q))return"schema";return}function Y5(Q){let $=[];for(let J of Q.messages){let Z=J.content.filter((G)=>G.type!=="thinking"&&G.type!=="redacted_thinking");if(Z.length===0)continue;let Y=$.at(-1);if(Y?.role===J.role)Y.content.push(...Z);else $.push({role:J.role,content:Z})}return{...Q,messages:$}}function Y6(Q,$){if(Q==="none"||Q==="minimal")return"low";if(Q==="xhigh"&&/^claude-(?:opus|sonnet)-4-6(?:-|$)/.test($))return"high";return Q}function G6(Q){let $=(Z)=>{if(Z)Z.cache_control={type:"ephemeral"}};$(Q.tools?.at(-1)),$(Q.system?.at(-1));let J=Q.messages.at(-1)?.content??[];return $([...J].reverse().find((Z)=>Z.type!=="thinking"&&Z.type!=="redacted_thinking")),Q}var W6=new Set(["minimum","maximum","exclusiveMinimum","exclusiveMaximum","multipleOf","minLength","maxLength","maxItems","uniqueItems"]),V6=new Set(["date-time","time","date","duration","email","hostname","uri","ipv4","ipv6","uuid"]),K6=/\\[1-9]|\(\?<?[=!]|\\[bB]/,G5=new Set(["properties","patternProperties","$defs","definitions"]);function X6(Q){let $=(J)=>{if(Array.isArray(J))return J.map($);if(!E(J))return J;let Z={},Y=[];for(let[G,V]of Object.entries(J)){if(W6.has(G)||G==="minItems"&&typeof V==="number"&&V>1||G==="format"&&typeof V==="string"&&!V6.has(V)||G==="pattern"&&typeof V==="string"&&K6.test(V)){Y.push(`${G}: ${JSON.stringify(V)}`);continue}Z[G]=G5.has(G)&&E(V)?Object.fromEntries(Object.entries(V).map(([j,K])=>[j,$(K)])):$(V)}if(Y.length>0){let G=`{${Y.join(", ")}}`;Z.description=typeof Z.description==="string"?`${Z.description} ${G}`:G}if(Z.type==="object"||E(Z.properties))Z.additionalProperties=!1;return Z};return $(Q)}function B6(Q){let $=0,J=0,Z=(Y)=>{if(Array.isArray(Y))return Y.forEach(Z);if(!E(Y))return;if(Array.isArray(Y.anyOf)||Array.isArray(Y.type))J++;if(E(Y.properties)){let G=new Set(Array.isArray(Y.required)?Y.required:[]);$+=Object.keys(Y.properties).filter((V)=>!G.has(V)).length}for(let[G,V]of Object.entries(Y))if(G5.has(G)&&E(V))Object.values(V).forEach(Z);else Z(V)};return Z(Q),$>24||J>16}function H6(Q){return`Answer with only a JSON value (no prose, no code fence) that matches this JSON schema:
8
- ${JSON.stringify(Q)}`}function j6(Q,$){if(Q==="none")return{type:"none"};if(Q==="required")return $?{type:"any"}:{type:"auto"};if(Q&&typeof Q==="object")return $?{type:"tool",name:Q.name}:{type:"auto"};return{type:"auto"}}function z6(Q,$){let J=[],Z=new Map;for(let B of Q){let H=B.role==="assistant"?"assistant":"user";J.push("step-end");for(let W of B.content??[])switch(W.type){case"text":{if(H==="assistant"?!!W.text:!!W.text?.trim())J.push({role:H,block:{type:"text",text:W.text}});break}case"output":{if(W.partial)break;let X=W.text??JSON.stringify(W.value);J.push({role:H,block:{type:"text",text:X}});break}case"file":{if(H==="assistant")break;for(let X of N6(W,$))J.push({role:H,block:X});break}case"reasoning":{let X=H==="assistant"?L6(W):void 0;if(X)J.push({role:H,block:X});break}case"tool-call":{if(W.partial)break;J.push({role:"assistant",block:{type:"tool_use",id:W.toolCallId,name:String(W.name),input:E(W.input)?W.input:{}}});break}case"tool-result":{if(J.push("step-end"),Z.has(W.toolCallId))break;Z.set(W.toolCallId,{type:"tool_result",tool_use_id:W.toolCallId,content:PQ(W),...W.status==="error"?{is_error:!0}:{}});break}}}let Y=[],G=(B,H)=>{let W=Y[Y.length-1];if(W&&W.role===B)W.content.push(H);else Y.push({role:B,content:[H]})},V=new Set,z=[],j=!1,K=()=>{for(let B of z)G("user",Z.get(B)??C6(B));z=[],j=!1};for(let B of J){if(B==="step-end"){j=!0;continue}let{role:H,block:W}=B;if(j||H==="user")K();if(W.type==="tool_use"){let X=String(W.id);if(V.has(X))continue;V.add(X),z.push(X)}G(H,W)}if(K(),Y[0]?.role==="assistant")Y.unshift({role:"user",content:[{type:"text",text:q6}]});if(Y.at(-1)?.role==="assistant")Y.push({role:"user",content:[{type:"text",text:F6}]});return Y}var q6="(The conversation continues from an earlier point.)",F6="Continue.",U6="No result was recorded for this tool call. Assume it did not complete.";function C6(Q){return{type:"tool_result",tool_use_id:Q,content:U6}}function L6(Q){let $=Q.providerMetadata?.anthropic;if(!E($))return;if($.type==="thinking"&&typeof $.signature==="string")return{type:"thinking",thinking:Q.text??"",signature:$.signature};if($.type==="redacted_thinking"&&typeof $.data==="string")return{type:"redacted_thinking",data:$.data};return}function N6(Q,$){let J=CQ(Q),Z=(G)=>J?[{type:"text",text:d(Q,G)}]:[];if(!$.fileInput)return Z(!1);if(NQ(Q,J),!Q.fileId)return Z(!1);let Y=Q.providerRejected?void 0:D6(Q);if(!Y)return[...Z(!1),{type:"text",text:m(Q.name)}];return[...Z(!0),{type:Y,source:{type:"file",file_id:Q.fileId}}]}var P6=new Set(["image/jpeg","image/png","image/gif","image/webp"]);function D6(Q){let $=Q.mimeType?.trim().toLowerCase()??"";if(LQ(Q))return!$||P6.has($)?"image":void 0;if($)return $==="application/pdf"||$==="text/plain"?"document":void 0;return/\.(pdf|txt)$/i.test(Q.name??"")?"document":void 0}function E(Q){return!!Q&&typeof Q==="object"&&!Array.isArray(Q)}function x6(Q){return Array.isArray(Q.tools)}function O6(Q){let $=[];for(let J of Q??[])for(let Z of x6(J)?J.tools:[J])$.push({name:Z.name,description:Z.description,input_schema:Z.parameters,eager_input_streaming:!0});return $}async function*X5(Q,$={}){let J=new Map,Z=[],Y,G={},V,z,j=!1,K=(B)=>({type:"finish",reason:B,usage:I6(G),...Y?{model:Y}:{}});for await(let B of zQ(Q)){let H;try{H=JSON.parse(B.data)}catch{continue}switch(typeof H.type==="string"?H.type:B.event){case"message_start":{let X=H.message??{};if(typeof X.model==="string"&&X.model)Y=X.model;G=K5(G,X.usage);break}case"content_block_start":{let X=Number(H.index),q=H.content_block??{},U={type:String(q.type??""),id:typeof q.id==="string"?q.id:void 0,name:typeof q.name==="string"?q.name:void 0,args:"",signature:typeof q.signature==="string"?q.signature:""};if(J.set(X,U),U.type==="redacted_thinking")yield{type:"reasoning-delta",delta:"",providerMetadata:{anthropic:{type:"redacted_thinking",data:String(q.data??"")}}};if(U.type==="text"&&typeof q.text==="string"&&q.text)yield V5(q.text,$);break}case"content_block_delta":{let X=J.get(Number(H.index)),q=H.delta??{};if(!X)break;if(q.type==="text_delta"){let U=String(q.text??"");if(U)yield V5(U,$)}else if(q.type==="thinking_delta"){let U=String(q.thinking??"");if(U)yield{type:"reasoning-delta",delta:U}}else if(q.type==="signature_delta")X.signature+=String(q.signature??"");else if(q.type==="input_json_delta"&&X.type==="tool_use"){let U=String(q.partial_json??"");if(!U)break;X.args+=U,yield{type:"tool-call-delta",toolCallId:X.id??"",name:X.name??"",argsDelta:U}}break}case"content_block_stop":{let X=Number(H.index),q=J.get(X);if(J.delete(X),q?.type==="thinking")yield{type:"reasoning-delta",delta:"",providerMetadata:{anthropic:{type:"thinking",signature:q.signature}}};if(q?.type==="tool_use")if(q.args||="{}",S6(q.args))yield W5(q);else Z.push(q);break}case"message_delta":{if(typeof H.delta?.stop_reason==="string")V=H.delta.stop_reason;if(H.delta?.stop_details)z=H.delta.stop_details;G=K5(G,H.usage);break}case"message_stop":{if(j=!0,V==="refusal"){yield{type:"error",error:_6(z)},yield K("error");break}let X=M6(V);if(Z.length>0&&X==="length")yield{type:"tool-call-discard",toolCallIds:Z.map((q)=>q.id??"")};else for(let q of Z)yield W5(q);yield K(X);break}case"error":{j=!0,yield{type:"error",error:R6(H.error??H)},yield K("error");break}}if(j)return}yield{type:"error",error:{code:"provider_error",message:"The provider stream ended without a terminal event.",retryable:!0}},yield K("error")}function W5(Q){return{type:"tool-call",toolCallId:Q.id??"",name:Q.name??"",args:Q.args}}function S6(Q){try{return JSON.parse(Q),!0}catch{return!1}}function V5(Q,$){return $.structuredOutput?{type:"output-delta",delta:Q}:{type:"text-delta",delta:Q}}function M6(Q){if(Q==="max_tokens"||Q==="model_context_window_exceeded")return"length";return"stop"}function _6(Q){let $=typeof Q?.explanation==="string"?Q.explanation:"",J=typeof Q?.category==="string"?` (${Q.category})`:"";return{code:"content_filtered",message:$||`The model declined to answer${J}.`,retryable:!1}}function R6(Q){let $=String(Q?.type??"").toLowerCase(),J=typeof Q?.message==="string"?Q.message:"The provider stream failed.";if($==="rate_limit_error")return{code:"rate_limited",message:J,retryable:!0};if($==="invalid_request_error"||$==="request_too_large")return{code:/prompt is too long|request_too_large/i.test(`${$} ${J}`)?"context_length_exceeded":"provider_error",message:J,retryable:!1};if($==="authentication_error"||$==="permission_error"||$==="billing_error"||$==="not_found_error")return{code:"provider_error",message:J,retryable:!1};return{code:"provider_error",message:J,retryable:!0}}function K5(Q,$){if(!$||typeof $!=="object")return Q;let J={...Q};for(let Y of["input_tokens","output_tokens","cache_creation_input_tokens","cache_read_input_tokens"])if(typeof $[Y]==="number")J[Y]=$[Y];let Z=$.output_tokens_details?.thinking_tokens;if(typeof Z==="number")J.thinking_tokens=Z;return J}function I6(Q){if(!Q)return M();let{cache_read_input_tokens:$,cache_creation_input_tokens:J}=Q,Z=(Q.input_tokens??0)+($??0)+(J??0),Y=Q.output_tokens??0,G={inputTokens:Z,outputTokens:Y,totalTokens:Z+Y};if(typeof $==="number")G.cachedInputTokens=$;if(typeof J==="number")G.cacheWriteInputTokens=J;if(typeof Q.thinking_tokens==="number")G.reasoningTokens=Q.thinking_tokens;return G}function xQ(Q){let $=SQ(Q);if($.startsWith("gpt-3.5")||$.startsWith("text-")||$.startsWith("davinci"))return{reasoning:!1,structuredOutput:!1,fileInput:!1,parallelToolCalls:!0,toolSearch:!1,supportsForcedToolChoice:!0};let J=E6($);if(J?.kind==="o")return{reasoning:!0,structuredOutput:!0,fileInput:!0,parallelToolCalls:J.major>1,toolSearch:B5(J),supportsForcedToolChoice:!0};if(J?.kind==="gpt")return{reasoning:J.major>=5,structuredOutput:J.major>4||$.startsWith("gpt-4o")||$.startsWith("gpt-4.1"),fileInput:J.major>4||$.startsWith("gpt-4o")||$.startsWith("gpt-4.1"),parallelToolCalls:!0,toolSearch:B5(J),supportsForcedToolChoice:!0};return{reasoning:!0,structuredOutput:!0,fileInput:!0,parallelToolCalls:!0,toolSearch:!0,supportsForcedToolChoice:!0}}function B5(Q){if(Q.kind==="o")return Q.major>=5;return Q.major>5||Q.major===5&&Q.minor>=2}function OQ(Q){let $=SQ(Q),J=/^claude-(?:opus|sonnet|haiku)-4(?:-(\d{1,2}))?(?:-\d{8})?$/.exec($);return{reasoning:!(/^claude-(?:3|2|instant)/.test($)||!!J&&Number(J[1]??0)<=5),structuredOutput:!0,fileInput:!0,parallelToolCalls:!0,toolSearch:!1,supportsForcedToolChoice:A6(Q)}}function A6(Q){let $=SQ(Q);return/^claude-(?:3|2|instant)/.test($)||/^claude-(?:opus|sonnet|haiku)-4(?:-|$)/.test($)||/^claude-(?:opus|sonnet|fable|mythos)-5(?:-\d{8})?$/.test($)||/^claude-haiku-5-5(?:-\d{8})?$/.test($)}function SQ(Q){return Q.trim().toLowerCase()}function E6(Q){let $=/^gpt-(\d+)(?:\.(\d+))?/.exec(Q);if($?.[1])return{kind:"gpt",major:Number($[1]),minor:Number($[2]??0)};let J=/^o(\d+)(?:[-.]|$)/.exec(Q);if(J?.[1])return{kind:"o",major:Number(J[1]),minor:0};return null}var MQ=120000,_Q=2,RQ=120000,IQ=300000;function D(Q){return typeof process>"u"?void 0:process.env?.[Q]}var T6="preview";function H5(Q){let $=Q.trim().replace(/\/+$/,"");if(!$)return"";return`${$.replace(/\/openai(?:\/v1)?$/i,"")}/openai`}function w6(Q){return/^\d{4}-\d{2}-\d{2}/.test(Q)?"":"/v1"}function AQ(Q,$={}){return{base:(Q.baseURL??D("OPENAI_BASE_URL")??"https://api.openai.com/v1").replace(/\/+$/,""),query:"",headers:async()=>{let Z=Q.apiKey??D("OPENAI_API_KEY");return{...Z?{authorization:`Bearer ${Z}`}:{},...Q.headers}},timeoutMs:Q.timeoutMs??$.timeoutMs??MQ,streamIdleTimeoutMs:Q.streamIdleTimeoutMs??RQ,streamMaxDurationMs:Q.streamMaxDurationMs??IQ,maxToolArgumentChars:Q.maxToolArgumentChars??0,maxRetries:Q.maxRetries??_Q,...TQ(Q)}}function j5(Q){let $=Q.baseURL??Q.endpoint??D("AZURE_OPENAI_ENDPOINT");if($)return H5($);let J=Q.resourceName??D("AZURE_OPENAI_RESOURCE_NAME")??D("AZURE_RESOURCE_NAME");return J?H5(`https://${J.trim()}.cognitiveservices.azure.com`):""}function EQ(Q,$={}){let J=Q.apiVersion??D("AZURE_OPENAI_API_VERSION")??T6;return{base:`${j5(Q)}${w6(J)}`,query:`?api-version=${encodeURIComponent(J)}`,headers:async()=>{if(Q.getToken)return{authorization:`Bearer ${await Q.getToken()}`,...Q.headers};let Z=Q.apiKey??D("AZURE_OPENAI_API_KEY");return{...Z?{"api-key":Z}:{},...Q.headers}},timeoutMs:Q.timeoutMs??$.timeoutMs??MQ,streamIdleTimeoutMs:Q.streamIdleTimeoutMs??RQ,streamMaxDurationMs:Q.streamMaxDurationMs??IQ,maxToolArgumentChars:Q.maxToolArgumentChars??0,maxRetries:Q.maxRetries??_Q,...TQ(Q)}}var k6="2026-10-21";function z5(Q,$={}){let J=Q.baseURL??D("ANTHROPIC_BASE_URL")??"https://api.anthropic.com";return F5(J,Q,$,async()=>{let Z=Q.workspaceId??D("ANTHROPIC_WORKSPACE_ID"),Y=Z?{"anthropic-workspace-id":Z}:{},G=Q.apiKey??D("ANTHROPIC_API_KEY");if(G)return{"x-api-key":G,...Y};let V=D("ANTHROPIC_AUTH_TOKEN");return V?{authorization:`Bearer ${V}`,...Y}:Y})}function q5(Q,$={}){let J=Q.resourceName??D("ANTHROPIC_FOUNDRY_RESOURCE"),Z=Q.baseURL??Q.endpoint??D("ANTHROPIC_FOUNDRY_BASE_URL")??(J?`https://${J.trim()}.services.ai.azure.com/anthropic`:"");if(!Z.trim())throw Error("AzureAnthropicProvider has no Foundry endpoint. Set `endpoint` (the deployment's Target URI without `/v1/messages`, e.g. `https://<resource>.services.ai.azure.com/anthropic`) or `resourceName`, or the ANTHROPIC_FOUNDRY_BASE_URL or ANTHROPIC_FOUNDRY_RESOURCE environment variable.");return F5(Z,Q,$,async()=>{if(Q.getToken)return{authorization:`Bearer ${await Q.getToken()}`};let Y=Q.apiKey??D("ANTHROPIC_FOUNDRY_API_KEY");return Y?{"api-key":Y}:{}})}function F5(Q,$,J,Z){return{base:`${Q.trim().replace(/\/+$/,"").replace(/\/v1$/,"")}/v1`,query:"",headers:async()=>({...await Z(),"anthropic-version":k6,...$.headers}),timeoutMs:$.timeoutMs??J.timeoutMs??MQ,streamIdleTimeoutMs:$.streamIdleTimeoutMs??RQ,streamMaxDurationMs:$.streamMaxDurationMs??IQ,maxToolArgumentChars:$.maxToolArgumentChars??0,maxRetries:$.maxRetries??_Q,...TQ($)}}function U5(Q,$={}){return{...EQ(Q,$),base:`${j5(Q)}/v1`,query:""}}function TQ(Q){return vQ(Q.retry),Q.retry?{retry:Q.retry}:{}}class JQ{static models(){return[]}normalizeError(Q){return x(Q)}}var C5=["gpt-5.5","gpt-5.4","gpt-5.4-mini","gpt-5.4-nano","gpt-5.2","gpt-5.1","gpt-5","gpt-5-mini","gpt-5-nano","gpt-4.1","gpt-4.1-mini","gpt-4.1-nano","gpt-4o","gpt-4o-mini","o4-mini","o3","o3-mini"];class L5 extends JQ{model;capabilities;config;constructor(Q,$={}){super();this.model=Q,this.capabilities=xQ(Q),this.config=$}static model(Q,$){return new L5(Q,$)}static models(){return C5}stream(Q){let $=UQ(Q,{model:this.model,capabilities:this.capabilities});return e(this.endpoint(),$,{signal:Q.signal,structuredOutput:Boolean(Q.output),files:KQ(Q.messages)})}upload(Q){return QQ(this.endpoint(),Q)}endpoint(){return t(AQ(this.config))}get realtime(){return new a(AQ(this.config,{timeoutMs:WQ}),{model:this.model})}}var v6=["claude-opus-5-5","claude-sonnet-5-5","claude-haiku-5-5","claude-fable-5-2","claude-fable-5-1","claude-opus-5","claude-sonnet-5","claude-fable-5","claude-opus-4-8","claude-sonnet-4-6","claude-haiku-4-5"];class wQ extends JQ{model;capabilities;config;constructor(Q,$={}){super();this.model=Q,this.capabilities=OQ(Q),this.config=$}static model(Q,$){return new wQ(Q,$)}static models(){return v6}stream(Q){return this.send(Q)}async*send(Q){let $=Q,J=!1,Z=new Set;for(;;){let Y=this.request($);if(J)Y=Y5(Y);let G,V=!1;for await(let z of e(this.endpointFor(Y),Y,{signal:Q.signal,structuredOutput:Boolean(Q.output),parse:X5})){if(G)continue;if(!V&&z.type==="error"&&z.status===400){let j=Z5(z.error.message);if(j&&!Z.has(j)){Z.add(j),G=j;continue}}if(o(z))V=!0;yield z}if(!G)return;if(G==="thinking")J=!0;else if($.output)$={...$,output:{...$.output,strict:!1}}}}request(Q){return J5(Q,{model:this.deployment(),modelId:this.model,capabilities:this.capabilities,forcedToolChoice:this.capabilities.supportsForcedToolChoice!==!1,blockBinding:this.bindsThinking()})}endpointFor(Q){let $=this.endpoint();if(!(Q.thinking?.type==="adaptive"&&Q.thinking.block_binding))return $;return{...$,headers:async()=>{let Z=await $.headers(),Y=Z["anthropic-beta"];return{...Z,"anthropic-beta":Y?`${Y},${DQ}`:DQ}}}}bindsThinking(){return!0}deployment(){return this.model}upload(Q){return QQ(this.endpoint(),Q,null)}endpoint(){return N5(z5(this.config))}}function N5(Q){return{...t(Q),responsesUrl:`${Q.base}/messages`}}class P5 extends wQ{constructor(Q,$={}){super(Q,$);this.capabilities={...OQ(Q),fileInput:!1}}static model(Q,$){return new P5(Q,$)}upload(Q){return Promise.reject(Error("AzureAnthropicProvider does not upload files: the Files API is not available on Azure-hosted Foundry deployments. The file is still stored by gemi and named to the model by its attachment id."))}deployment(){return this.config.deployment??this.model}bindsThinking(){return!1}endpoint(){return N5(q5(this.config))}}class D5 extends JQ{model;capabilities;config;constructor(Q,$={}){super();this.model=Q,this.capabilities=xQ(Q),this.config=$}static model(Q,$){return new D5(Q,$)}static models(){return C5}stream(Q){let $=UQ(Q,{model:this.deployment(),capabilities:this.capabilities});return e(this.endpoint(),$,{signal:Q.signal,structuredOutput:Boolean(Q.output),files:KQ(Q.messages)})}upload(Q){return QQ(this.endpoint(),Q,"assistants")}deployment(){return this.config.deployment??this.model}endpoint(){return t(EQ(this.config))}get realtime(){return new a(U5(this.config,{timeoutMs:WQ}),{model:this.deployment(),callFlow:"ephemeral"})}}
9
- export{u as ca,AQ as da,EQ as ea,GQ as fa,E5 as ga,VQ as ha,c as ia,a as ja,h5 as ka,JQ as la,L5 as ma,wQ as na,P5 as oa,D5 as pa};
10
-
11
- //# debugId=000D1A9856356E2864756E2164756E21