@shawnstack/quickforge 1.3.13 → 1.3.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # 速构 QuickForge
2
2
 
3
3
  <p align="center">
4
- <img alt="Version" src="https://img.shields.io/badge/version-1.3.13-blue" />
4
+ <img alt="Version" src="https://img.shields.io/badge/version-1.3.14-blue" />
5
5
  <img alt="License" src="https://img.shields.io/badge/license-MIT-green" />
6
6
  <img alt="Node" src="https://img.shields.io/badge/node-%3E%3D20-brightgreen" />
7
7
  <img alt="React" src="https://img.shields.io/badge/react-19-61DAFB?logo=react" />
@@ -65,7 +65,7 @@ QuickForge 的工具能力很直接,因此也需要谨慎使用:
65
65
  #### 从 npm 安装
66
66
 
67
67
  ```bash
68
- npm install -g @shawnstack/quickforge@1.3.13
68
+ npm install -g @shawnstack/quickforge@1.3.14
69
69
  qf
70
70
 
71
71
  # CLI 工具
@@ -79,17 +79,17 @@ qf update
79
79
  当前版本的离线包:
80
80
 
81
81
  ```text
82
- package-offline/shawnstack-quickforge-1.3.13.tgz
82
+ package-offline/shawnstack-quickforge-1.3.14.tgz
83
83
  ```
84
84
 
85
85
  在安装了 Node.js 20+ 和 npm 的机器上执行:
86
86
 
87
87
  ```bash
88
- npm install -g ./package-offline/shawnstack-quickforge-1.3.13.tgz
88
+ npm install -g ./package-offline/shawnstack-quickforge-1.3.14.tgz
89
89
  qf
90
90
  ```
91
91
 
92
- 该包由 `v1.3.13` 标签生成,包含离线安装所需的运行时依赖。
92
+ 该包由 `v1.3.14` 标签生成,包含离线安装所需的运行时依赖。
93
93
 
94
94
  ### 本地开发
95
95
 
@@ -228,7 +228,7 @@ QuickForge intentionally exposes powerful local capabilities, so the boundaries
228
228
  #### npm
229
229
 
230
230
  ```bash
231
- npm install -g @shawnstack/quickforge@1.3.13
231
+ npm install -g @shawnstack/quickforge@1.3.14
232
232
  qf
233
233
 
234
234
  # CLI utilities
@@ -239,20 +239,20 @@ qf update
239
239
 
240
240
  #### Offline tarball
241
241
 
242
- The offline release package for `v1.3.13` is:
242
+ The offline release package for `v1.3.14` is:
243
243
 
244
244
  ```text
245
- package-offline/shawnstack-quickforge-1.3.13.tgz
245
+ package-offline/shawnstack-quickforge-1.3.14.tgz
246
246
  ```
247
247
 
248
248
  Install it on a machine with Node.js 20+ and npm:
249
249
 
250
250
  ```bash
251
- npm install -g ./package-offline/shawnstack-quickforge-1.3.13.tgz
251
+ npm install -g ./package-offline/shawnstack-quickforge-1.3.14.tgz
252
252
  qf
253
253
  ```
254
254
 
255
- The package was generated from tag `v1.3.13` and includes bundled runtime dependencies for offline installation.
255
+ The package was generated from tag `v1.3.14` and includes bundled runtime dependencies for offline installation.
256
256
 
257
257
  ### Local development
258
258
 
@@ -1,4 +1,4 @@
1
- import{a as e,i as t,n,r,s as i}from"./index-Bx9iFrzC.js";import{t as a}from"./headers-5EYI0_pl.js";import{a as o,n as s,r as c,t as l}from"./transform-messages-CV4kCtBB.js";import{n as u,t as ee}from"./github-copilot-headers-CrI0CIJ7.js";function d(e,t,n,r,i){if(r===`m`)throw TypeError(`Private method is not writable`);if(r===`a`&&!i)throw TypeError(`Private accessor was defined without a setter`);if(typeof t==`function`?e!==t||!i:!t.has(e))throw TypeError(`Cannot write private member to an object whose class did not declare it`);return r===`a`?i.call(e,n):i?i.value=n:t.set(e,n),n}function f(e,t,n,r){if(n===`a`&&!r)throw TypeError(`Private accessor was defined without a getter`);if(typeof t==`function`?e!==t||!r:!t.has(e))throw TypeError(`Cannot read private member from an object whose class did not declare it`);return n===`m`?r:n===`a`?r.call(e):r?r.value:t.get(e)}var p=function(){let{crypto:e}=globalThis;if(e?.randomUUID)return p=e.randomUUID.bind(e),e.randomUUID();let t=new Uint8Array(1),n=e?()=>e.getRandomValues(t)[0]:()=>Math.random()*255&255;return`10000000-1000-4000-8000-100000000000`.replace(/[018]/g,e=>(e^n()&15>>e/4).toString(16))};function m(e){return typeof e==`object`&&!!e&&(`name`in e&&e.name===`AbortError`||`message`in e&&String(e.message).includes(`FetchRequestCanceledException`))}var h=e=>{if(e instanceof Error)return e;if(typeof e==`object`&&e){try{if(Object.prototype.toString.call(e)===`[object Error]`){let t=Error(e.message,e.cause?{cause:e.cause}:{});return e.stack&&(t.stack=e.stack),e.cause&&!t.cause&&(t.cause=e.cause),e.name&&(t.name=e.name),t}}catch{}try{return Error(JSON.stringify(e))}catch{}}return Error(e)},g=class extends Error{},_=class e extends g{constructor(t,n,r,i,a){super(`${e.makeMessage(t,n,r)}`),this.status=t,this.headers=i,this.requestID=i?.get(`request-id`),this.error=n,this.type=a??null}static makeMessage(e,t,n){let r=t?.message?typeof t.message==`string`?t.message:JSON.stringify(t.message):t?JSON.stringify(t):n;return e&&r?`${e} ${r}`:e?`${e} status code (no body)`:r||`(no status code or body)`}static generate(t,n,r,i){if(!t||!i)return new te({message:r,cause:h(n)});let a=n,o=a?.error?.type;return t===400?new re(t,a,r,i,o):t===401?new ie(t,a,r,i,o):t===403?new ae(t,a,r,i,o):t===404?new oe(t,a,r,i,o):t===409?new se(t,a,r,i,o):t===422?new ce(t,a,r,i,o):t===429?new le(t,a,r,i,o):t>=500?new ue(t,a,r,i,o):new e(t,a,r,i,o)}},v=class extends _{constructor({message:e}={}){super(void 0,void 0,e||`Request was aborted.`,void 0)}},te=class extends _{constructor({message:e,cause:t}){super(void 0,void 0,e||`Connection error.`,void 0),t&&(this.cause=t)}},ne=class extends te{constructor({message:e}={}){super({message:e??`Request timed out.`})}},re=class extends _{},ie=class extends _{},ae=class extends _{},oe=class extends _{},se=class extends _{},ce=class extends _{},le=class extends _{},ue=class extends _{},de=/^[a-z][a-z0-9+.-]*:/i,fe=e=>de.test(e),pe=e=>(pe=Array.isArray,pe(e)),me=pe;function he(e){return typeof e==`object`?e??{}:{}}function ge(e){if(!e)return!0;for(let t in e)return!1;return!0}function _e(e,t){return Object.prototype.hasOwnProperty.call(e,t)}var ve=(e,t)=>{if(typeof t!=`number`||!Number.isInteger(t))throw new g(`${e} must be an integer`);if(t<0)throw new g(`${e} must be a positive integer`);return t},ye=e=>{try{return JSON.parse(e)}catch{return}},be=e=>new Promise(t=>setTimeout(t,e)),y=`0.90.0`,xe=()=>typeof window<`u`&&window.document!==void 0&&typeof navigator<`u`;function Se(){return typeof Deno<`u`&&Deno.build!=null?`deno`:typeof EdgeRuntime<`u`?`edge`:Object.prototype.toString.call(globalThis.process===void 0?0:globalThis.process)===`[object process]`?`node`:`unknown`}var Ce=()=>{let e=Se();if(e===`deno`)return{"X-Stainless-Lang":`js`,"X-Stainless-Package-Version":y,"X-Stainless-OS":Ee(Deno.build.os),"X-Stainless-Arch":Te(Deno.build.arch),"X-Stainless-Runtime":`deno`,"X-Stainless-Runtime-Version":typeof Deno.version==`string`?Deno.version:Deno.version?.deno??`unknown`};if(typeof EdgeRuntime<`u`)return{"X-Stainless-Lang":`js`,"X-Stainless-Package-Version":y,"X-Stainless-OS":`Unknown`,"X-Stainless-Arch":`other:${EdgeRuntime}`,"X-Stainless-Runtime":`edge`,"X-Stainless-Runtime-Version":globalThis.process.version};if(e===`node`)return{"X-Stainless-Lang":`js`,"X-Stainless-Package-Version":y,"X-Stainless-OS":Ee(globalThis.process.platform??`unknown`),"X-Stainless-Arch":Te(globalThis.process.arch??`unknown`),"X-Stainless-Runtime":`node`,"X-Stainless-Runtime-Version":globalThis.process.version??`unknown`};let t=we();return t?{"X-Stainless-Lang":`js`,"X-Stainless-Package-Version":y,"X-Stainless-OS":`Unknown`,"X-Stainless-Arch":`unknown`,"X-Stainless-Runtime":`browser:${t.browser}`,"X-Stainless-Runtime-Version":t.version}:{"X-Stainless-Lang":`js`,"X-Stainless-Package-Version":y,"X-Stainless-OS":`Unknown`,"X-Stainless-Arch":`unknown`,"X-Stainless-Runtime":`unknown`,"X-Stainless-Runtime-Version":`unknown`}};function we(){if(typeof navigator>`u`||!navigator)return null;for(let{key:e,pattern:t}of[{key:`edge`,pattern:/Edge(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:`ie`,pattern:/MSIE(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:`ie`,pattern:/Trident(?:.*rv\:(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:`chrome`,pattern:/Chrome(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:`firefox`,pattern:/Firefox(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:`safari`,pattern:/(?:Version\W+(\d+)\.(\d+)(?:\.(\d+))?)?(?:\W+Mobile\S*)?\W+Safari/}]){let n=t.exec(navigator.userAgent);if(n)return{browser:e,version:`${n[1]||0}.${n[2]||0}.${n[3]||0}`}}return null}var Te=e=>e===`x32`?`x32`:e===`x86_64`||e===`x64`?`x64`:e===`arm`?`arm`:e===`aarch64`||e===`arm64`?`arm64`:e?`other:${e}`:`unknown`,Ee=e=>(e=e.toLowerCase(),e.includes(`ios`)?`iOS`:e===`android`?`Android`:e===`darwin`?`MacOS`:e===`win32`?`Windows`:e===`freebsd`?`FreeBSD`:e===`openbsd`?`OpenBSD`:e===`linux`?`Linux`:e?`Other:${e}`:`Unknown`),De,Oe=()=>De??=Ce();function ke(){if(typeof fetch<`u`)return fetch;throw Error("`fetch` is not defined as a global; Either pass `fetch` to the client, `new Anthropic({ fetch })` or polyfill the global, `globalThis.fetch = fetch`")}function Ae(...e){let t=globalThis.ReadableStream;if(t===void 0)throw Error("`ReadableStream` is not defined as a global; You will need to polyfill it, `globalThis.ReadableStream = ReadableStream`");return new t(...e)}function je(e){let t=Symbol.asyncIterator in e?e[Symbol.asyncIterator]():e[Symbol.iterator]();return Ae({start(){},async pull(e){let{done:n,value:r}=await t.next();n?e.close():e.enqueue(r)},async cancel(){await t.return?.()}})}function Me(e){if(e[Symbol.asyncIterator])return e;let t=e.getReader();return{async next(){try{let e=await t.read();return e?.done&&t.releaseLock(),e}catch(e){throw t.releaseLock(),e}},async return(){let e=t.cancel();return t.releaseLock(),await e,{done:!0,value:void 0}},[Symbol.asyncIterator](){return this}}}async function Ne(e){if(typeof e!=`object`||!e)return;if(e[Symbol.asyncIterator]){await e[Symbol.asyncIterator]().return?.();return}let t=e.getReader(),n=t.cancel();t.releaseLock(),await n}var Pe=({headers:e,body:t})=>({bodyHeaders:{"content-type":`application/json`},body:JSON.stringify(t)});function Fe(e){return Object.entries(e).filter(([e,t])=>t!==void 0).map(([e,t])=>{if(typeof t==`string`||typeof t==`number`||typeof t==`boolean`)return`${encodeURIComponent(e)}=${encodeURIComponent(t)}`;if(t===null)return`${encodeURIComponent(e)}=`;throw new g(`Cannot stringify type ${typeof t}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`)}).join(`&`)}function Ie(e){let t=0;for(let n of e)t+=n.length;let n=new Uint8Array(t),r=0;for(let t of e)n.set(t,r),r+=t.length;return n}var Le;function Re(e){let t;return(Le??=(t=new globalThis.TextEncoder,t.encode.bind(t)))(e)}var ze;function Be(e){let t;return(ze??=(t=new globalThis.TextDecoder,t.decode.bind(t)))(e)}var b,x,Ve=class{constructor(){b.set(this,void 0),x.set(this,void 0),d(this,b,new Uint8Array,`f`),d(this,x,null,`f`)}decode(e){if(e==null)return[];let t=e instanceof ArrayBuffer?new Uint8Array(e):typeof e==`string`?Re(e):e;d(this,b,Ie([f(this,b,`f`),t]),`f`);let n=[],r;for(;(r=He(f(this,b,`f`),f(this,x,`f`)))!=null;){if(r.carriage&&f(this,x,`f`)==null){d(this,x,r.index,`f`);continue}if(f(this,x,`f`)!=null&&(r.index!==f(this,x,`f`)+1||r.carriage)){n.push(Be(f(this,b,`f`).subarray(0,f(this,x,`f`)-1))),d(this,b,f(this,b,`f`).subarray(f(this,x,`f`)),`f`),d(this,x,null,`f`);continue}let e=f(this,x,`f`)===null?r.preceding:r.preceding-1,t=Be(f(this,b,`f`).subarray(0,e));n.push(t),d(this,b,f(this,b,`f`).subarray(r.index),`f`),d(this,x,null,`f`)}return n}flush(){return f(this,b,`f`).length?this.decode(`
1
+ import{a as e,i as t,n,r,s as i}from"./index-CgTJgJ5U.js";import{t as a}from"./headers-5EYI0_pl.js";import{a as o,n as s,r as c,t as l}from"./transform-messages-CV4kCtBB.js";import{n as u,t as ee}from"./github-copilot-headers-CrI0CIJ7.js";function d(e,t,n,r,i){if(r===`m`)throw TypeError(`Private method is not writable`);if(r===`a`&&!i)throw TypeError(`Private accessor was defined without a setter`);if(typeof t==`function`?e!==t||!i:!t.has(e))throw TypeError(`Cannot write private member to an object whose class did not declare it`);return r===`a`?i.call(e,n):i?i.value=n:t.set(e,n),n}function f(e,t,n,r){if(n===`a`&&!r)throw TypeError(`Private accessor was defined without a getter`);if(typeof t==`function`?e!==t||!r:!t.has(e))throw TypeError(`Cannot read private member from an object whose class did not declare it`);return n===`m`?r:n===`a`?r.call(e):r?r.value:t.get(e)}var p=function(){let{crypto:e}=globalThis;if(e?.randomUUID)return p=e.randomUUID.bind(e),e.randomUUID();let t=new Uint8Array(1),n=e?()=>e.getRandomValues(t)[0]:()=>Math.random()*255&255;return`10000000-1000-4000-8000-100000000000`.replace(/[018]/g,e=>(e^n()&15>>e/4).toString(16))};function m(e){return typeof e==`object`&&!!e&&(`name`in e&&e.name===`AbortError`||`message`in e&&String(e.message).includes(`FetchRequestCanceledException`))}var h=e=>{if(e instanceof Error)return e;if(typeof e==`object`&&e){try{if(Object.prototype.toString.call(e)===`[object Error]`){let t=Error(e.message,e.cause?{cause:e.cause}:{});return e.stack&&(t.stack=e.stack),e.cause&&!t.cause&&(t.cause=e.cause),e.name&&(t.name=e.name),t}}catch{}try{return Error(JSON.stringify(e))}catch{}}return Error(e)},g=class extends Error{},_=class e extends g{constructor(t,n,r,i,a){super(`${e.makeMessage(t,n,r)}`),this.status=t,this.headers=i,this.requestID=i?.get(`request-id`),this.error=n,this.type=a??null}static makeMessage(e,t,n){let r=t?.message?typeof t.message==`string`?t.message:JSON.stringify(t.message):t?JSON.stringify(t):n;return e&&r?`${e} ${r}`:e?`${e} status code (no body)`:r||`(no status code or body)`}static generate(t,n,r,i){if(!t||!i)return new te({message:r,cause:h(n)});let a=n,o=a?.error?.type;return t===400?new re(t,a,r,i,o):t===401?new ie(t,a,r,i,o):t===403?new ae(t,a,r,i,o):t===404?new oe(t,a,r,i,o):t===409?new se(t,a,r,i,o):t===422?new ce(t,a,r,i,o):t===429?new le(t,a,r,i,o):t>=500?new ue(t,a,r,i,o):new e(t,a,r,i,o)}},v=class extends _{constructor({message:e}={}){super(void 0,void 0,e||`Request was aborted.`,void 0)}},te=class extends _{constructor({message:e,cause:t}){super(void 0,void 0,e||`Connection error.`,void 0),t&&(this.cause=t)}},ne=class extends te{constructor({message:e}={}){super({message:e??`Request timed out.`})}},re=class extends _{},ie=class extends _{},ae=class extends _{},oe=class extends _{},se=class extends _{},ce=class extends _{},le=class extends _{},ue=class extends _{},de=/^[a-z][a-z0-9+.-]*:/i,fe=e=>de.test(e),pe=e=>(pe=Array.isArray,pe(e)),me=pe;function he(e){return typeof e==`object`?e??{}:{}}function ge(e){if(!e)return!0;for(let t in e)return!1;return!0}function _e(e,t){return Object.prototype.hasOwnProperty.call(e,t)}var ve=(e,t)=>{if(typeof t!=`number`||!Number.isInteger(t))throw new g(`${e} must be an integer`);if(t<0)throw new g(`${e} must be a positive integer`);return t},ye=e=>{try{return JSON.parse(e)}catch{return}},be=e=>new Promise(t=>setTimeout(t,e)),y=`0.90.0`,xe=()=>typeof window<`u`&&window.document!==void 0&&typeof navigator<`u`;function Se(){return typeof Deno<`u`&&Deno.build!=null?`deno`:typeof EdgeRuntime<`u`?`edge`:Object.prototype.toString.call(globalThis.process===void 0?0:globalThis.process)===`[object process]`?`node`:`unknown`}var Ce=()=>{let e=Se();if(e===`deno`)return{"X-Stainless-Lang":`js`,"X-Stainless-Package-Version":y,"X-Stainless-OS":Ee(Deno.build.os),"X-Stainless-Arch":Te(Deno.build.arch),"X-Stainless-Runtime":`deno`,"X-Stainless-Runtime-Version":typeof Deno.version==`string`?Deno.version:Deno.version?.deno??`unknown`};if(typeof EdgeRuntime<`u`)return{"X-Stainless-Lang":`js`,"X-Stainless-Package-Version":y,"X-Stainless-OS":`Unknown`,"X-Stainless-Arch":`other:${EdgeRuntime}`,"X-Stainless-Runtime":`edge`,"X-Stainless-Runtime-Version":globalThis.process.version};if(e===`node`)return{"X-Stainless-Lang":`js`,"X-Stainless-Package-Version":y,"X-Stainless-OS":Ee(globalThis.process.platform??`unknown`),"X-Stainless-Arch":Te(globalThis.process.arch??`unknown`),"X-Stainless-Runtime":`node`,"X-Stainless-Runtime-Version":globalThis.process.version??`unknown`};let t=we();return t?{"X-Stainless-Lang":`js`,"X-Stainless-Package-Version":y,"X-Stainless-OS":`Unknown`,"X-Stainless-Arch":`unknown`,"X-Stainless-Runtime":`browser:${t.browser}`,"X-Stainless-Runtime-Version":t.version}:{"X-Stainless-Lang":`js`,"X-Stainless-Package-Version":y,"X-Stainless-OS":`Unknown`,"X-Stainless-Arch":`unknown`,"X-Stainless-Runtime":`unknown`,"X-Stainless-Runtime-Version":`unknown`}};function we(){if(typeof navigator>`u`||!navigator)return null;for(let{key:e,pattern:t}of[{key:`edge`,pattern:/Edge(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:`ie`,pattern:/MSIE(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:`ie`,pattern:/Trident(?:.*rv\:(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:`chrome`,pattern:/Chrome(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:`firefox`,pattern:/Firefox(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:`safari`,pattern:/(?:Version\W+(\d+)\.(\d+)(?:\.(\d+))?)?(?:\W+Mobile\S*)?\W+Safari/}]){let n=t.exec(navigator.userAgent);if(n)return{browser:e,version:`${n[1]||0}.${n[2]||0}.${n[3]||0}`}}return null}var Te=e=>e===`x32`?`x32`:e===`x86_64`||e===`x64`?`x64`:e===`arm`?`arm`:e===`aarch64`||e===`arm64`?`arm64`:e?`other:${e}`:`unknown`,Ee=e=>(e=e.toLowerCase(),e.includes(`ios`)?`iOS`:e===`android`?`Android`:e===`darwin`?`MacOS`:e===`win32`?`Windows`:e===`freebsd`?`FreeBSD`:e===`openbsd`?`OpenBSD`:e===`linux`?`Linux`:e?`Other:${e}`:`Unknown`),De,Oe=()=>De??=Ce();function ke(){if(typeof fetch<`u`)return fetch;throw Error("`fetch` is not defined as a global; Either pass `fetch` to the client, `new Anthropic({ fetch })` or polyfill the global, `globalThis.fetch = fetch`")}function Ae(...e){let t=globalThis.ReadableStream;if(t===void 0)throw Error("`ReadableStream` is not defined as a global; You will need to polyfill it, `globalThis.ReadableStream = ReadableStream`");return new t(...e)}function je(e){let t=Symbol.asyncIterator in e?e[Symbol.asyncIterator]():e[Symbol.iterator]();return Ae({start(){},async pull(e){let{done:n,value:r}=await t.next();n?e.close():e.enqueue(r)},async cancel(){await t.return?.()}})}function Me(e){if(e[Symbol.asyncIterator])return e;let t=e.getReader();return{async next(){try{let e=await t.read();return e?.done&&t.releaseLock(),e}catch(e){throw t.releaseLock(),e}},async return(){let e=t.cancel();return t.releaseLock(),await e,{done:!0,value:void 0}},[Symbol.asyncIterator](){return this}}}async function Ne(e){if(typeof e!=`object`||!e)return;if(e[Symbol.asyncIterator]){await e[Symbol.asyncIterator]().return?.();return}let t=e.getReader(),n=t.cancel();t.releaseLock(),await n}var Pe=({headers:e,body:t})=>({bodyHeaders:{"content-type":`application/json`},body:JSON.stringify(t)});function Fe(e){return Object.entries(e).filter(([e,t])=>t!==void 0).map(([e,t])=>{if(typeof t==`string`||typeof t==`number`||typeof t==`boolean`)return`${encodeURIComponent(e)}=${encodeURIComponent(t)}`;if(t===null)return`${encodeURIComponent(e)}=`;throw new g(`Cannot stringify type ${typeof t}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`)}).join(`&`)}function Ie(e){let t=0;for(let n of e)t+=n.length;let n=new Uint8Array(t),r=0;for(let t of e)n.set(t,r),r+=t.length;return n}var Le;function Re(e){let t;return(Le??=(t=new globalThis.TextEncoder,t.encode.bind(t)))(e)}var ze;function Be(e){let t;return(ze??=(t=new globalThis.TextDecoder,t.decode.bind(t)))(e)}var b,x,Ve=class{constructor(){b.set(this,void 0),x.set(this,void 0),d(this,b,new Uint8Array,`f`),d(this,x,null,`f`)}decode(e){if(e==null)return[];let t=e instanceof ArrayBuffer?new Uint8Array(e):typeof e==`string`?Re(e):e;d(this,b,Ie([f(this,b,`f`),t]),`f`);let n=[],r;for(;(r=He(f(this,b,`f`),f(this,x,`f`)))!=null;){if(r.carriage&&f(this,x,`f`)==null){d(this,x,r.index,`f`);continue}if(f(this,x,`f`)!=null&&(r.index!==f(this,x,`f`)+1||r.carriage)){n.push(Be(f(this,b,`f`).subarray(0,f(this,x,`f`)-1))),d(this,b,f(this,b,`f`).subarray(f(this,x,`f`)),`f`),d(this,x,null,`f`);continue}let e=f(this,x,`f`)===null?r.preceding:r.preceding-1,t=Be(f(this,b,`f`).subarray(0,e));n.push(t),d(this,b,f(this,b,`f`).subarray(r.index),`f`),d(this,x,null,`f`)}return n}flush(){return f(this,b,`f`).length?this.decode(`
2
2
  `):[]}};b=new WeakMap,x=new WeakMap,Ve.NEWLINE_CHARS=new Set([`
3
3
  `,`\r`]),Ve.NEWLINE_REGEXP=/\r\n|[\n\r]/g;function He(e,t){for(let n=t??0;n<e.length;n++){if(e[n]===10)return{preceding:n,index:n+1,carriage:!1};if(e[n]===13)return{preceding:n,index:n+1,carriage:!0}}return null}function Ue(e){for(let t=0;t<e.length-1;t++){if(e[t]===10&&e[t+1]===10||e[t]===13&&e[t+1]===13)return t+2;if(e[t]===13&&e[t+1]===10&&t+3<e.length&&e[t+2]===13&&e[t+3]===10)return t+4}return-1}var We={off:0,error:200,warn:300,info:400,debug:500},Ge=(e,t,n)=>{if(e){if(_e(We,e))return e;S(n).warn(`${t} was set to ${JSON.stringify(e)}, expected one of ${JSON.stringify(Object.keys(We))}`)}};function Ke(){}function qe(e,t,n){return!t||We[e]>We[n]?Ke:t[e].bind(t)}var Je={error:Ke,warn:Ke,info:Ke,debug:Ke},Ye=new WeakMap;function S(e){let t=e.logger,n=e.logLevel??`off`;if(!t)return Je;let r=Ye.get(t);if(r&&r[0]===n)return r[1];let i={error:qe(`error`,t,n),warn:qe(`warn`,t,n),info:qe(`info`,t,n),debug:qe(`debug`,t,n)};return Ye.set(t,[n,i]),i}var C=e=>(e.options&&(e.options={...e.options},delete e.options.headers),e.headers&&=Object.fromEntries((e.headers instanceof Headers?[...e.headers]:Object.entries(e.headers)).map(([e,t])=>[e,e.toLowerCase()===`x-api-key`||e.toLowerCase()===`authorization`||e.toLowerCase()===`cookie`||e.toLowerCase()===`set-cookie`?`***`:t])),`retryOfRequestLogID`in e&&(e.retryOfRequestLogID&&(e.retryOf=e.retryOfRequestLogID),delete e.retryOfRequestLogID),e),Xe,Ze=class e{constructor(e,t,n){this.iterator=e,Xe.set(this,void 0),this.controller=t,d(this,Xe,n,`f`)}static fromSSEResponse(t,n,r){let i=!1,a=r?S(r):console;async function*o(){if(i)throw new g("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");i=!0;let e=!1;try{for await(let e of Qe(t,n)){if(e.event===`completion`)try{yield JSON.parse(e.data)}catch(t){throw a.error(`Could not parse message into JSON:`,e.data),a.error(`From chunk:`,e.raw),t}if(e.event===`message_start`||e.event===`message_delta`||e.event===`message_stop`||e.event===`content_block_start`||e.event===`content_block_delta`||e.event===`content_block_stop`||e.event===`message`||e.event===`user.message`||e.event===`user.interrupt`||e.event===`user.tool_confirmation`||e.event===`user.custom_tool_result`||e.event===`agent.message`||e.event===`agent.thinking`||e.event===`agent.tool_use`||e.event===`agent.tool_result`||e.event===`agent.mcp_tool_use`||e.event===`agent.mcp_tool_result`||e.event===`agent.custom_tool_use`||e.event===`agent.thread_context_compacted`||e.event===`session.status_running`||e.event===`session.status_idle`||e.event===`session.status_rescheduled`||e.event===`session.status_terminated`||e.event===`session.error`||e.event===`session.deleted`||e.event===`span.model_request_start`||e.event===`span.model_request_end`)try{yield JSON.parse(e.data)}catch(t){throw a.error(`Could not parse message into JSON:`,e.data),a.error(`From chunk:`,e.raw),t}if(e.event!==`ping`&&e.event===`error`){let n=ye(e.data)??e.data,r=n?.error?.type;throw new _(void 0,n,void 0,t.headers,r)}}e=!0}catch(e){if(m(e))return;throw e}finally{e||n.abort()}}return new e(o,n,r)}static fromReadableStream(t,n,r){let i=!1;async function*a(){let e=new Ve,n=Me(t);for await(let t of n)for(let n of e.decode(t))yield n;for(let t of e.flush())yield t}async function*o(){if(i)throw new g("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");i=!0;let e=!1;try{for await(let t of a())e||t&&(yield JSON.parse(t));e=!0}catch(e){if(m(e))return;throw e}finally{e||n.abort()}}return new e(o,n,r)}[(Xe=new WeakMap,Symbol.asyncIterator)](){return this.iterator()}tee(){let t=[],n=[],r=this.iterator(),i=e=>({next:()=>{if(e.length===0){let e=r.next();t.push(e),n.push(e)}return e.shift()}});return[new e(()=>i(t),this.controller,f(this,Xe,`f`)),new e(()=>i(n),this.controller,f(this,Xe,`f`))]}toReadableStream(){let e=this,t;return Ae({async start(){t=e[Symbol.asyncIterator]()},async pull(e){try{let{value:n,done:r}=await t.next();if(r)return e.close();let i=Re(JSON.stringify(n)+`
4
4
  `);e.enqueue(i)}catch(t){e.error(t)}},async cancel(){await t.return?.()}})}};async function*Qe(e,t){if(!e.body)throw t.abort(),globalThis.navigator!==void 0&&globalThis.navigator.product===`ReactNative`?new g(`The default react-native fetch implementation does not support streaming. Please use expo/fetch: https://docs.expo.dev/versions/latest/sdk/expo/#expofetch-api`):new g(`Attempted to iterate over a response with no body`);let n=new et,r=new Ve,i=Me(e.body);for await(let e of $e(i))for(let t of r.decode(e)){let e=n.decode(t);e&&(yield e)}for(let e of r.flush()){let t=n.decode(e);t&&(yield t)}}async function*$e(e){let t=new Uint8Array;for await(let n of e){if(n==null)continue;let e=n instanceof ArrayBuffer?new Uint8Array(n):typeof n==`string`?Re(n):n,r=new Uint8Array(t.length+e.length);r.set(t),r.set(e,t.length),t=r;let i;for(;(i=Ue(t))!==-1;)yield t.slice(0,i),t=t.slice(i)}t.length>0&&(yield t)}var et=class{constructor(){this.event=null,this.data=[],this.chunks=[]}decode(e){if(e.endsWith(`\r`)&&(e=e.substring(0,e.length-1)),!e){if(!this.event&&!this.data.length)return null;let e={event:this.event,data:this.data.join(`
@@ -1 +1 @@
1
- import{i as e,o as t,s as n}from"./index-Bx9iFrzC.js";import{t as r}from"./headers-5EYI0_pl.js";import{i,r as a}from"./transform-messages-CV4kCtBB.js";import{t as o}from"./openai-Cn7eGqwa.js";import{n as s,r as c,t as l}from"./openai-responses-shared-Cx1dCwfa.js";var u=`v1`,d=new Set([`openai`,`openai-codex`,`opencode`,`azure-openai-responses`]);function f(e){let t=new Map;if(!e)return t;for(let n of e.split(`,`)){let e=n.trim();if(!e)continue;let[r,i]=e.split(`=`,2);!r||!i||t.set(r.trim(),i.trim())}return t}function p(e,t){return t?.azureDeploymentName?t.azureDeploymentName:f({}.AZURE_OPENAI_DEPLOYMENT_NAME_MAP).get(e.id)||e.id}var m=(t,i,a)=>{let o=new e;return(async()=>{let e=p(t,a),s={role:`assistant`,content:[],api:`azure-openai-responses`,provider:t.provider,model:t.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:`stop`,timestamp:Date.now()};try{let l=y(t,a?.apiKey||n(t.provider)||``,a),u=b(t,i,a,e),d=await a?.onPayload?.(u,t);d!==void 0&&(u=d);let f={...a?.signal?{signal:a.signal}:{},...a?.timeoutMs===void 0?{}:{timeout:a.timeoutMs},...a?.maxRetries===void 0?{}:{maxRetries:a.maxRetries}},{data:p,response:m}=await l.responses.create(u,f).withResponse();if(await a?.onResponse?.({status:m.status,headers:r(m.headers)},t),o.push({type:`start`,partial:s}),await c(p,s,o,t),a?.signal?.aborted)throw Error(`Request was aborted`);if(s.stopReason===`aborted`||s.stopReason===`error`)throw Error(`An unknown error occurred`);o.push({type:`done`,reason:s.stopReason,message:s}),o.end()}catch(e){for(let e of s.content)delete e.index,delete e.partialJson;s.stopReason=a?.signal?.aborted?`aborted`:`error`,s.errorMessage=e instanceof Error?e.message:JSON.stringify(e),o.push({type:`error`,reason:s.stopReason,error:s}),o.end()}})(),o},h=(e,r,o)=>{let s=o?.apiKey||n(e.provider);if(!s)throw Error(`No API key for provider: ${e.provider}`);let c=a(e,o,s),l=t(e)?o?.reasoning:i(o?.reasoning);return m(e,r,{...c,reasoningEffort:l})};function g(e){let t=e.trim().replace(/\/+$/,``),n;try{n=new URL(t)}catch{throw Error(`Invalid Azure OpenAI base URL: ${e}`)}let r=n.hostname.endsWith(`.openai.azure.com`)||n.hostname.endsWith(`.cognitiveservices.azure.com`),i=n.pathname.replace(/\/+$/,``);return r&&(i===``||i===`/`||i===`/openai`)&&(n.pathname=`/openai/v1`,n.search=``),n.toString().replace(/\/+$/,``)}function _(e){return`https://${e}.openai.azure.com/openai/v1`}function v(e,t){let n=t?.azureApiVersion||{}.AZURE_OPENAI_API_VERSION||u,r=t?.azureBaseUrl?.trim()||{}.AZURE_OPENAI_BASE_URL?.trim()||void 0,i=t?.azureResourceName||{}.AZURE_OPENAI_RESOURCE_NAME,a=r;if(!a&&i&&(a=_(i)),!a&&e.baseUrl&&(a=e.baseUrl),!a)throw Error(`Azure OpenAI base URL is required. Set AZURE_OPENAI_BASE_URL or AZURE_OPENAI_RESOURCE_NAME, or pass azureBaseUrl, azureResourceName, or model.baseUrl.`);return{baseUrl:g(a),apiVersion:n}}function y(e,t,n){if(!t){if(!{}.AZURE_OPENAI_API_KEY)throw Error(`Azure OpenAI API key is required. Set AZURE_OPENAI_API_KEY environment variable or pass it as an argument.`);t={}.AZURE_OPENAI_API_KEY}let r={...e.headers};n?.headers&&Object.assign(r,n.headers);let{baseUrl:i,apiVersion:a}=v(e,n);return new o({apiKey:t,apiVersion:a,dangerouslyAllowBrowser:!0,defaultHeaders:r,baseURL:i})}function b(e,t,n,r){let i={model:r,input:l(e,t,d),stream:!0,prompt_cache_key:n?.sessionId};return n?.maxTokens&&(i.max_output_tokens=n?.maxTokens),n?.temperature!==void 0&&(i.temperature=n?.temperature),t.tools&&t.tools.length>0&&(i.tools=s(t.tools)),e.reasoning&&(n?.reasoningEffort||n?.reasoningSummary?(i.reasoning={effort:n?.reasoningEffort||`medium`,summary:n?.reasoningSummary||`auto`},i.include=[`reasoning.encrypted_content`]):i.reasoning={effort:`none`}),i}export{m as streamAzureOpenAIResponses,h as streamSimpleAzureOpenAIResponses};
1
+ import{i as e,o as t,s as n}from"./index-CgTJgJ5U.js";import{t as r}from"./headers-5EYI0_pl.js";import{i,r as a}from"./transform-messages-CV4kCtBB.js";import{t as o}from"./openai-Cn7eGqwa.js";import{n as s,r as c,t as l}from"./openai-responses-shared-BWikZIo_.js";var u=`v1`,d=new Set([`openai`,`openai-codex`,`opencode`,`azure-openai-responses`]);function f(e){let t=new Map;if(!e)return t;for(let n of e.split(`,`)){let e=n.trim();if(!e)continue;let[r,i]=e.split(`=`,2);!r||!i||t.set(r.trim(),i.trim())}return t}function p(e,t){return t?.azureDeploymentName?t.azureDeploymentName:f({}.AZURE_OPENAI_DEPLOYMENT_NAME_MAP).get(e.id)||e.id}var m=(t,i,a)=>{let o=new e;return(async()=>{let e=p(t,a),s={role:`assistant`,content:[],api:`azure-openai-responses`,provider:t.provider,model:t.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:`stop`,timestamp:Date.now()};try{let l=y(t,a?.apiKey||n(t.provider)||``,a),u=b(t,i,a,e),d=await a?.onPayload?.(u,t);d!==void 0&&(u=d);let f={...a?.signal?{signal:a.signal}:{},...a?.timeoutMs===void 0?{}:{timeout:a.timeoutMs},...a?.maxRetries===void 0?{}:{maxRetries:a.maxRetries}},{data:p,response:m}=await l.responses.create(u,f).withResponse();if(await a?.onResponse?.({status:m.status,headers:r(m.headers)},t),o.push({type:`start`,partial:s}),await c(p,s,o,t),a?.signal?.aborted)throw Error(`Request was aborted`);if(s.stopReason===`aborted`||s.stopReason===`error`)throw Error(`An unknown error occurred`);o.push({type:`done`,reason:s.stopReason,message:s}),o.end()}catch(e){for(let e of s.content)delete e.index,delete e.partialJson;s.stopReason=a?.signal?.aborted?`aborted`:`error`,s.errorMessage=e instanceof Error?e.message:JSON.stringify(e),o.push({type:`error`,reason:s.stopReason,error:s}),o.end()}})(),o},h=(e,r,o)=>{let s=o?.apiKey||n(e.provider);if(!s)throw Error(`No API key for provider: ${e.provider}`);let c=a(e,o,s),l=t(e)?o?.reasoning:i(o?.reasoning);return m(e,r,{...c,reasoningEffort:l})};function g(e){let t=e.trim().replace(/\/+$/,``),n;try{n=new URL(t)}catch{throw Error(`Invalid Azure OpenAI base URL: ${e}`)}let r=n.hostname.endsWith(`.openai.azure.com`)||n.hostname.endsWith(`.cognitiveservices.azure.com`),i=n.pathname.replace(/\/+$/,``);return r&&(i===``||i===`/`||i===`/openai`)&&(n.pathname=`/openai/v1`,n.search=``),n.toString().replace(/\/+$/,``)}function _(e){return`https://${e}.openai.azure.com/openai/v1`}function v(e,t){let n=t?.azureApiVersion||{}.AZURE_OPENAI_API_VERSION||u,r=t?.azureBaseUrl?.trim()||{}.AZURE_OPENAI_BASE_URL?.trim()||void 0,i=t?.azureResourceName||{}.AZURE_OPENAI_RESOURCE_NAME,a=r;if(!a&&i&&(a=_(i)),!a&&e.baseUrl&&(a=e.baseUrl),!a)throw Error(`Azure OpenAI base URL is required. Set AZURE_OPENAI_BASE_URL or AZURE_OPENAI_RESOURCE_NAME, or pass azureBaseUrl, azureResourceName, or model.baseUrl.`);return{baseUrl:g(a),apiVersion:n}}function y(e,t,n){if(!t){if(!{}.AZURE_OPENAI_API_KEY)throw Error(`Azure OpenAI API key is required. Set AZURE_OPENAI_API_KEY environment variable or pass it as an argument.`);t={}.AZURE_OPENAI_API_KEY}let r={...e.headers};n?.headers&&Object.assign(r,n.headers);let{baseUrl:i,apiVersion:a}=v(e,n);return new o({apiKey:t,apiVersion:a,dangerouslyAllowBrowser:!0,defaultHeaders:r,baseURL:i})}function b(e,t,n,r){let i={model:r,input:l(e,t,d),stream:!0,prompt_cache_key:n?.sessionId};return n?.maxTokens&&(i.max_output_tokens=n?.maxTokens),n?.temperature!==void 0&&(i.temperature=n?.temperature),t.tools&&t.tools.length>0&&(i.tools=s(t.tools)),e.reasoning&&(n?.reasoningEffort||n?.reasoningSummary?(i.reasoning={effort:n?.reasoningEffort||`medium`,summary:n?.reasoningSummary||`auto`},i.include=[`reasoning.encrypted_content`]):i.reasoning={effort:`none`}),i}export{m as streamAzureOpenAIResponses,h as streamSimpleAzureOpenAIResponses};
@@ -1 +1 @@
1
- import{a as e,i as t,s as n}from"./index-Bx9iFrzC.js";import{a as r,i,r as a}from"./transform-messages-CV4kCtBB.js";import{c as o,i as s,n as c,o as l,r as u,s as d,t as f}from"./google-shared-XhYUKiGZ.js";var p=0,m=(r,i,a)=>{let o=new t;return(async()=>{let t={role:`assistant`,content:[],api:`google-generative-ai`,provider:r.provider,model:r.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:`stop`,timestamp:Date.now()};try{let c=g(r,a?.apiKey||n(r.provider)||``,a?.headers),l=_(r,i,a),f=await a?.onPayload?.(l,r);f!==void 0&&(l=f);let m=await c.models.generateContentStream(l);o.push({type:`start`,partial:t});let h=null,v=t.content,y=()=>v.length-1;for await(let n of m){t.responseId||=n.responseId;let i=n.candidates?.[0];if(i?.content?.parts)for(let e of i.content.parts){if(e.text!==void 0){let n=u(e);(!h||n&&h.type!==`thinking`||!n&&h.type!==`text`)&&(h&&(h.type===`text`?o.push({type:`text_end`,contentIndex:v.length-1,content:h.text,partial:t}):o.push({type:`thinking_end`,contentIndex:y(),content:h.thinking,partial:t})),n?(h={type:`thinking`,thinking:``,thinkingSignature:void 0},t.content.push(h),o.push({type:`thinking_start`,contentIndex:y(),partial:t})):(h={type:`text`,text:``},t.content.push(h),o.push({type:`text_start`,contentIndex:y(),partial:t}))),h.type===`thinking`?(h.thinking+=e.text,h.thinkingSignature=d(h.thinkingSignature,e.thoughtSignature),o.push({type:`thinking_delta`,contentIndex:y(),delta:e.text,partial:t})):(h.text+=e.text,h.textSignature=d(h.textSignature,e.thoughtSignature),o.push({type:`text_delta`,contentIndex:y(),delta:e.text,partial:t}))}if(e.functionCall){h&&=(h.type===`text`?o.push({type:`text_end`,contentIndex:y(),content:h.text,partial:t}):o.push({type:`thinking_end`,contentIndex:y(),content:h.thinking,partial:t}),null);let n=e.functionCall.id,r={type:`toolCall`,id:!n||t.content.some(e=>e.type===`toolCall`&&e.id===n)?`${e.functionCall.name}_${Date.now()}_${++p}`:n,name:e.functionCall.name||``,arguments:e.functionCall.args??{},...e.thoughtSignature&&{thoughtSignature:e.thoughtSignature}};t.content.push(r),o.push({type:`toolcall_start`,contentIndex:y(),partial:t}),o.push({type:`toolcall_delta`,contentIndex:y(),delta:JSON.stringify(r.arguments),partial:t}),o.push({type:`toolcall_end`,contentIndex:y(),toolCall:r,partial:t})}}i?.finishReason&&(t.stopReason=s(i.finishReason),t.content.some(e=>e.type===`toolCall`)&&(t.stopReason=`toolUse`)),n.usageMetadata&&(t.usage={input:(n.usageMetadata.promptTokenCount||0)-(n.usageMetadata.cachedContentTokenCount||0),output:(n.usageMetadata.candidatesTokenCount||0)+(n.usageMetadata.thoughtsTokenCount||0),cacheRead:n.usageMetadata.cachedContentTokenCount||0,cacheWrite:0,totalTokens:n.usageMetadata.totalTokenCount||0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},e(r,t.usage))}if(h&&(h.type===`text`?o.push({type:`text_end`,contentIndex:y(),content:h.text,partial:t}):o.push({type:`thinking_end`,contentIndex:y(),content:h.thinking,partial:t})),a?.signal?.aborted)throw Error(`Request was aborted`);if(t.stopReason===`aborted`||t.stopReason===`error`)throw Error(`An unknown error occurred`);o.push({type:`done`,reason:t.stopReason,message:t}),o.end()}catch(e){for(let e of t.content)`index`in e&&delete e.index;t.stopReason=a?.signal?.aborted?`aborted`:`error`,t.errorMessage=e instanceof Error?e.message:JSON.stringify(e),o.push({type:`error`,reason:t.stopReason,error:t}),o.end()}})(),o},h=(e,t,r)=>{let o=r?.apiKey||n(e.provider);if(!o)throw Error(`No API key for provider: ${e.provider}`);let s=a(e,r,o);if(!r?.reasoning)return m(e,t,{...s,thinking:{enabled:!1}});let c=i(r.reasoning),l=e;return y(l)||b(l)||v(l)?m(e,t,{...s,thinking:{enabled:!0,level:S(c,l)}}):m(e,t,{...s,thinking:{enabled:!0,budgetTokens:C(l,c,r.thinkingBudgets)}})};function g(e,t,n){let r={};return e.baseUrl&&(r.baseUrl=e.baseUrl,r.apiVersion=``),(e.headers||n)&&(r.headers={...e.headers,...n}),new o({apiKey:t,httpOptions:Object.keys(r).length>0?r:void 0})}function _(e,t,n={}){let i=f(e,t),a={};n.temperature!==void 0&&(a.temperature=n.temperature),n.maxTokens!==void 0&&(a.maxOutputTokens=n.maxTokens);let o={...Object.keys(a).length>0&&a,...t.systemPrompt&&{systemInstruction:r(t.systemPrompt)},...t.tools&&t.tools.length>0&&{tools:c(t.tools)}};if(t.tools&&t.tools.length>0&&n.toolChoice?o.toolConfig={functionCallingConfig:{mode:l(n.toolChoice)}}:o.toolConfig=void 0,n.thinking?.enabled&&e.reasoning){let e={includeThoughts:!0};n.thinking.level===void 0?n.thinking.budgetTokens!==void 0&&(e.thinkingBudget=n.thinking.budgetTokens):e.thinkingLevel=n.thinking.level,o.thinkingConfig=e}else e.reasoning&&n.thinking&&!n.thinking.enabled&&(o.thinkingConfig=x(e));if(n.signal){if(n.signal.aborted)throw Error(`Request aborted`);o.abortSignal=n.signal}return{model:e.id,contents:i,config:o}}function v(e){return/gemma-?4/.test(e.id.toLowerCase())}function y(e){return/gemini-3(?:\.\d+)?-pro/.test(e.id.toLowerCase())}function b(e){return/gemini-3(?:\.\d+)?-flash/.test(e.id.toLowerCase())}function x(e){return y(e)?{thinkingLevel:`LOW`}:b(e)||v(e)?{thinkingLevel:`MINIMAL`}:{thinkingBudget:0}}function S(e,t){if(y(t))switch(e){case`minimal`:case`low`:return`LOW`;case`medium`:case`high`:return`HIGH`}if(v(t))switch(e){case`minimal`:case`low`:return`MINIMAL`;case`medium`:case`high`:return`HIGH`}switch(e){case`minimal`:return`MINIMAL`;case`low`:return`LOW`;case`medium`:return`MEDIUM`;case`high`:return`HIGH`}}function C(e,t,n){return n?.[t]===void 0?e.id.includes(`2.5-pro`)?{minimal:128,low:2048,medium:8192,high:32768}[t]:e.id.includes(`2.5-flash-lite`)?{minimal:512,low:2048,medium:8192,high:24576}[t]:e.id.includes(`2.5-flash`)?{minimal:128,low:2048,medium:8192,high:24576}[t]:-1:n[t]}export{m as streamGoogle,h as streamSimpleGoogle};
1
+ import{a as e,i as t,s as n}from"./index-CgTJgJ5U.js";import{a as r,i,r as a}from"./transform-messages-CV4kCtBB.js";import{c as o,i as s,n as c,o as l,r as u,s as d,t as f}from"./google-shared-XhYUKiGZ.js";var p=0,m=(r,i,a)=>{let o=new t;return(async()=>{let t={role:`assistant`,content:[],api:`google-generative-ai`,provider:r.provider,model:r.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:`stop`,timestamp:Date.now()};try{let c=g(r,a?.apiKey||n(r.provider)||``,a?.headers),l=_(r,i,a),f=await a?.onPayload?.(l,r);f!==void 0&&(l=f);let m=await c.models.generateContentStream(l);o.push({type:`start`,partial:t});let h=null,v=t.content,y=()=>v.length-1;for await(let n of m){t.responseId||=n.responseId;let i=n.candidates?.[0];if(i?.content?.parts)for(let e of i.content.parts){if(e.text!==void 0){let n=u(e);(!h||n&&h.type!==`thinking`||!n&&h.type!==`text`)&&(h&&(h.type===`text`?o.push({type:`text_end`,contentIndex:v.length-1,content:h.text,partial:t}):o.push({type:`thinking_end`,contentIndex:y(),content:h.thinking,partial:t})),n?(h={type:`thinking`,thinking:``,thinkingSignature:void 0},t.content.push(h),o.push({type:`thinking_start`,contentIndex:y(),partial:t})):(h={type:`text`,text:``},t.content.push(h),o.push({type:`text_start`,contentIndex:y(),partial:t}))),h.type===`thinking`?(h.thinking+=e.text,h.thinkingSignature=d(h.thinkingSignature,e.thoughtSignature),o.push({type:`thinking_delta`,contentIndex:y(),delta:e.text,partial:t})):(h.text+=e.text,h.textSignature=d(h.textSignature,e.thoughtSignature),o.push({type:`text_delta`,contentIndex:y(),delta:e.text,partial:t}))}if(e.functionCall){h&&=(h.type===`text`?o.push({type:`text_end`,contentIndex:y(),content:h.text,partial:t}):o.push({type:`thinking_end`,contentIndex:y(),content:h.thinking,partial:t}),null);let n=e.functionCall.id,r={type:`toolCall`,id:!n||t.content.some(e=>e.type===`toolCall`&&e.id===n)?`${e.functionCall.name}_${Date.now()}_${++p}`:n,name:e.functionCall.name||``,arguments:e.functionCall.args??{},...e.thoughtSignature&&{thoughtSignature:e.thoughtSignature}};t.content.push(r),o.push({type:`toolcall_start`,contentIndex:y(),partial:t}),o.push({type:`toolcall_delta`,contentIndex:y(),delta:JSON.stringify(r.arguments),partial:t}),o.push({type:`toolcall_end`,contentIndex:y(),toolCall:r,partial:t})}}i?.finishReason&&(t.stopReason=s(i.finishReason),t.content.some(e=>e.type===`toolCall`)&&(t.stopReason=`toolUse`)),n.usageMetadata&&(t.usage={input:(n.usageMetadata.promptTokenCount||0)-(n.usageMetadata.cachedContentTokenCount||0),output:(n.usageMetadata.candidatesTokenCount||0)+(n.usageMetadata.thoughtsTokenCount||0),cacheRead:n.usageMetadata.cachedContentTokenCount||0,cacheWrite:0,totalTokens:n.usageMetadata.totalTokenCount||0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},e(r,t.usage))}if(h&&(h.type===`text`?o.push({type:`text_end`,contentIndex:y(),content:h.text,partial:t}):o.push({type:`thinking_end`,contentIndex:y(),content:h.thinking,partial:t})),a?.signal?.aborted)throw Error(`Request was aborted`);if(t.stopReason===`aborted`||t.stopReason===`error`)throw Error(`An unknown error occurred`);o.push({type:`done`,reason:t.stopReason,message:t}),o.end()}catch(e){for(let e of t.content)`index`in e&&delete e.index;t.stopReason=a?.signal?.aborted?`aborted`:`error`,t.errorMessage=e instanceof Error?e.message:JSON.stringify(e),o.push({type:`error`,reason:t.stopReason,error:t}),o.end()}})(),o},h=(e,t,r)=>{let o=r?.apiKey||n(e.provider);if(!o)throw Error(`No API key for provider: ${e.provider}`);let s=a(e,r,o);if(!r?.reasoning)return m(e,t,{...s,thinking:{enabled:!1}});let c=i(r.reasoning),l=e;return y(l)||b(l)||v(l)?m(e,t,{...s,thinking:{enabled:!0,level:S(c,l)}}):m(e,t,{...s,thinking:{enabled:!0,budgetTokens:C(l,c,r.thinkingBudgets)}})};function g(e,t,n){let r={};return e.baseUrl&&(r.baseUrl=e.baseUrl,r.apiVersion=``),(e.headers||n)&&(r.headers={...e.headers,...n}),new o({apiKey:t,httpOptions:Object.keys(r).length>0?r:void 0})}function _(e,t,n={}){let i=f(e,t),a={};n.temperature!==void 0&&(a.temperature=n.temperature),n.maxTokens!==void 0&&(a.maxOutputTokens=n.maxTokens);let o={...Object.keys(a).length>0&&a,...t.systemPrompt&&{systemInstruction:r(t.systemPrompt)},...t.tools&&t.tools.length>0&&{tools:c(t.tools)}};if(t.tools&&t.tools.length>0&&n.toolChoice?o.toolConfig={functionCallingConfig:{mode:l(n.toolChoice)}}:o.toolConfig=void 0,n.thinking?.enabled&&e.reasoning){let e={includeThoughts:!0};n.thinking.level===void 0?n.thinking.budgetTokens!==void 0&&(e.thinkingBudget=n.thinking.budgetTokens):e.thinkingLevel=n.thinking.level,o.thinkingConfig=e}else e.reasoning&&n.thinking&&!n.thinking.enabled&&(o.thinkingConfig=x(e));if(n.signal){if(n.signal.aborted)throw Error(`Request aborted`);o.abortSignal=n.signal}return{model:e.id,contents:i,config:o}}function v(e){return/gemma-?4/.test(e.id.toLowerCase())}function y(e){return/gemini-3(?:\.\d+)?-pro/.test(e.id.toLowerCase())}function b(e){return/gemini-3(?:\.\d+)?-flash/.test(e.id.toLowerCase())}function x(e){return y(e)?{thinkingLevel:`LOW`}:b(e)||v(e)?{thinkingLevel:`MINIMAL`}:{thinkingBudget:0}}function S(e,t){if(y(t))switch(e){case`minimal`:case`low`:return`LOW`;case`medium`:case`high`:return`HIGH`}if(v(t))switch(e){case`minimal`:case`low`:return`MINIMAL`;case`medium`:case`high`:return`HIGH`}switch(e){case`minimal`:return`MINIMAL`;case`low`:return`LOW`;case`medium`:return`MEDIUM`;case`high`:return`HIGH`}}function C(e,t,n){return n?.[t]===void 0?e.id.includes(`2.5-pro`)?{minimal:128,low:2048,medium:8192,high:32768}[t]:e.id.includes(`2.5-flash-lite`)?{minimal:512,low:2048,medium:8192,high:24576}[t]:e.id.includes(`2.5-flash`)?{minimal:128,low:2048,medium:8192,high:24576}[t]:-1:n[t]}export{m as streamGoogle,h as streamSimpleGoogle};
@@ -1,2 +1,2 @@
1
- import{a as e,i as t}from"./index-Bx9iFrzC.js";import{t as n}from"./headers-5EYI0_pl.js";import{a as r,i,r as a}from"./transform-messages-CV4kCtBB.js";import{a as o,n as s,o as c,r as l,s as u,t as d}from"./google-shared-XhYUKiGZ.js";var f=`https://cloudcode-pa.googleapis.com`,p=[`https://daily-cloudcode-pa.sandbox.googleapis.com`,`https://autopush-cloudcode-pa.sandbox.googleapis.com`,f],m={"User-Agent":`google-cloud-sdk vscode_cloudshelleditor/0.1`,"X-Goog-Api-Client":`gl-node/22.17.0`,"Client-Metadata":JSON.stringify({ideType:`IDE_UNSPECIFIED`,platform:`PLATFORM_UNSPECIFIED`,pluginType:`GEMINI`})},h=`1.21.9`;function g(){return{"User-Agent":`antigravity/${{}.PI_AI_ANTIGRAVITY_VERSION||h} darwin/arm64`}}var _=`You are Antigravity, a powerful agentic AI coding assistant designed by the Google Deepmind team working on Advanced Agentic Coding.You are pair programming with a USER to solve their coding task. The task may require creating a new codebase, modifying or debugging an existing codebase, or simply answering a question.**Absolute paths only****Proactiveness**`,v=0,y=3,b=1e3,x=2,S=500,C=`interleaved-thinking-2025-05-14`;function w(e,t){let n=e=>e>0?Math.ceil(e+1e3):void 0,r=t instanceof Headers?t:t?.headers;if(r){let e=r.get(`retry-after`);if(e){let t=Number(e);if(Number.isFinite(t)){let e=n(t*1e3);if(e!==void 0)return e}let r=new Date(e).getTime();if(!Number.isNaN(r)){let e=n(r-Date.now());if(e!==void 0)return e}}let t=r.get(`x-ratelimit-reset`);if(t){let e=Number.parseInt(t,10);if(!Number.isNaN(e)){let t=n(e*1e3-Date.now());if(t!==void 0)return t}}let i=r.get(`x-ratelimit-reset-after`);if(i){let e=Number(i);if(Number.isFinite(e)){let t=n(e*1e3);if(t!==void 0)return t}}}let i=e.match(/reset after (?:(\d+)h)?(?:(\d+)m)?(\d+(?:\.\d+)?)s/i);if(i){let e=i[1]?parseInt(i[1],10):0,t=i[2]?parseInt(i[2],10):0,r=parseFloat(i[3]);if(!Number.isNaN(r)){let i=n(((e*60+t)*60+r)*1e3);if(i!==void 0)return i}}let a=e.match(/Please retry in ([0-9.]+)(ms|s)/i);if(a?.[1]){let e=parseFloat(a[1]);if(!Number.isNaN(e)&&e>0){let t=n(a[2].toLowerCase()===`ms`?e:e*1e3);if(t!==void 0)return t}}let o=e.match(/"retryDelay":\s*"([0-9.]+)(ms|s)"/i);if(o?.[1]){let e=parseFloat(o[1]);if(!Number.isNaN(e)&&e>0){let t=n(o[2].toLowerCase()===`ms`?e:e*1e3);if(t!==void 0)return t}}}function T(e){return e.provider===`google-antigravity`&&e.id.startsWith(`claude-`)&&e.reasoning}function E(e){return/gemini-3(?:\.1)?-pro/.test(e.toLowerCase())}function D(e){return/gemini-3(?:\.1)?-flash/.test(e.toLowerCase())}function O(e){return E(e)||D(e)}function k(e,t){return e===429||e===500||e===502||e===503||e===504?!0:/resource.?exhausted|rate.?limit|overloaded|service.?unavailable|other.?side.?closed/i.test(t)}function A(e){try{let t=JSON.parse(e);if(t.error?.message)return t.error.message}catch{}return e}function j(e,t){return new Promise((n,r)=>{if(t?.aborted){r(Error(`Request was aborted`));return}let i=setTimeout(n,e);t?.addEventListener(`abort`,()=>{clearTimeout(i),r(Error(`Request was aborted`))})})}var M=(r,i,a)=>{let s=new t;return(async()=>{let t={role:`assistant`,content:[],api:`google-gemini-cli`,provider:r.provider,model:r.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:`stop`,timestamp:Date.now()};try{let c=a?.apiKey;if(!c)throw Error(`Google Cloud Code Assist requires OAuth authentication. Use /login to authenticate.`);let d,h;try{let e=JSON.parse(c);d=e.token,h=e.projectId}catch{throw Error(`Invalid Google Cloud Code Assist credentials. Use /login to re-authenticate.`)}if(!d||!h)throw Error(`Missing token or projectId in Google Cloud credentials. Use /login to re-authenticate.`);let _=r.provider===`google-antigravity`,E=r.baseUrl?.trim(),D=E?[E]:_?p:[f],O=P(r,i,h,a,_),M=await a?.onPayload?.(O,r);M!==void 0&&(O=M);let N=_?g():m,F={Authorization:`Bearer ${d}`,"Content-Type":`application/json`,Accept:`text/event-stream`,...N,...T(r)?{"anthropic-beta":C}:{},...a?.headers},I=JSON.stringify(O),L,R,z,B=0;for(let e=0;e<=y;e++){if(a?.signal?.aborted)throw Error(`Request was aborted`);try{if(z=`${D[B]}/v1internal:streamGenerateContent?alt=sse`,L=await fetch(z,{method:`POST`,headers:F,body:I,signal:a?.signal}),await a?.onResponse?.({status:L.status,headers:n(L.headers)},r),L.ok)break;let t=await L.text();if((L.status===403||L.status===404)&&B<D.length-1){B++;continue}if(e<y&&k(L.status,t)){B<D.length-1&&B++;let n=w(t,L),r=n??b*2**e,i=a?.maxRetryDelayMs??6e4;if(i>0&&n&&n>i){let e=Math.ceil(n/1e3);throw Error(`Server requested ${e}s retry delay (max: ${Math.ceil(i/1e3)}s). ${A(t)}`)}await j(r,a?.signal);continue}throw Error(`Cloud Code Assist API error (${L.status}): ${A(t)}`)}catch(t){if(t instanceof Error&&(t.name===`AbortError`||t.message===`Request was aborted`))throw Error(`Request was aborted`);if(R=t instanceof Error?t:Error(String(t)),R.message===`fetch failed`&&R.cause instanceof Error&&(R=Error(`Network error: ${R.cause.message}`)),e<y){await j(b*2**e,a?.signal);continue}throw R}}if(!L||!L.ok)throw R??Error(`Failed to get response after retries`);let V=!1,H=()=>{V||=(s.push({type:`start`,partial:t}),!0)},U=()=>{t.content=[],t.usage={input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},t.stopReason=`stop`,t.errorMessage=void 0,t.timestamp=Date.now(),V=!1},W=async n=>{if(!n.body)throw Error(`No response body`);let i=!1,c=null,d=t.content,f=()=>d.length-1,p=n.body.getReader(),m=new TextDecoder,h=``,g=()=>{p.cancel().catch(()=>{})};a?.signal?.addEventListener(`abort`,g);try{for(;;){if(a?.signal?.aborted)throw Error(`Request was aborted`);let{done:n,value:g}=await p.read();if(n)break;h+=m.decode(g,{stream:!0});let _=h.split(`
1
+ import{a as e,i as t}from"./index-CgTJgJ5U.js";import{t as n}from"./headers-5EYI0_pl.js";import{a as r,i,r as a}from"./transform-messages-CV4kCtBB.js";import{a as o,n as s,o as c,r as l,s as u,t as d}from"./google-shared-XhYUKiGZ.js";var f=`https://cloudcode-pa.googleapis.com`,p=[`https://daily-cloudcode-pa.sandbox.googleapis.com`,`https://autopush-cloudcode-pa.sandbox.googleapis.com`,f],m={"User-Agent":`google-cloud-sdk vscode_cloudshelleditor/0.1`,"X-Goog-Api-Client":`gl-node/22.17.0`,"Client-Metadata":JSON.stringify({ideType:`IDE_UNSPECIFIED`,platform:`PLATFORM_UNSPECIFIED`,pluginType:`GEMINI`})},h=`1.21.9`;function g(){return{"User-Agent":`antigravity/${{}.PI_AI_ANTIGRAVITY_VERSION||h} darwin/arm64`}}var _=`You are Antigravity, a powerful agentic AI coding assistant designed by the Google Deepmind team working on Advanced Agentic Coding.You are pair programming with a USER to solve their coding task. The task may require creating a new codebase, modifying or debugging an existing codebase, or simply answering a question.**Absolute paths only****Proactiveness**`,v=0,y=3,b=1e3,x=2,S=500,C=`interleaved-thinking-2025-05-14`;function w(e,t){let n=e=>e>0?Math.ceil(e+1e3):void 0,r=t instanceof Headers?t:t?.headers;if(r){let e=r.get(`retry-after`);if(e){let t=Number(e);if(Number.isFinite(t)){let e=n(t*1e3);if(e!==void 0)return e}let r=new Date(e).getTime();if(!Number.isNaN(r)){let e=n(r-Date.now());if(e!==void 0)return e}}let t=r.get(`x-ratelimit-reset`);if(t){let e=Number.parseInt(t,10);if(!Number.isNaN(e)){let t=n(e*1e3-Date.now());if(t!==void 0)return t}}let i=r.get(`x-ratelimit-reset-after`);if(i){let e=Number(i);if(Number.isFinite(e)){let t=n(e*1e3);if(t!==void 0)return t}}}let i=e.match(/reset after (?:(\d+)h)?(?:(\d+)m)?(\d+(?:\.\d+)?)s/i);if(i){let e=i[1]?parseInt(i[1],10):0,t=i[2]?parseInt(i[2],10):0,r=parseFloat(i[3]);if(!Number.isNaN(r)){let i=n(((e*60+t)*60+r)*1e3);if(i!==void 0)return i}}let a=e.match(/Please retry in ([0-9.]+)(ms|s)/i);if(a?.[1]){let e=parseFloat(a[1]);if(!Number.isNaN(e)&&e>0){let t=n(a[2].toLowerCase()===`ms`?e:e*1e3);if(t!==void 0)return t}}let o=e.match(/"retryDelay":\s*"([0-9.]+)(ms|s)"/i);if(o?.[1]){let e=parseFloat(o[1]);if(!Number.isNaN(e)&&e>0){let t=n(o[2].toLowerCase()===`ms`?e:e*1e3);if(t!==void 0)return t}}}function T(e){return e.provider===`google-antigravity`&&e.id.startsWith(`claude-`)&&e.reasoning}function E(e){return/gemini-3(?:\.1)?-pro/.test(e.toLowerCase())}function D(e){return/gemini-3(?:\.1)?-flash/.test(e.toLowerCase())}function O(e){return E(e)||D(e)}function k(e,t){return e===429||e===500||e===502||e===503||e===504?!0:/resource.?exhausted|rate.?limit|overloaded|service.?unavailable|other.?side.?closed/i.test(t)}function A(e){try{let t=JSON.parse(e);if(t.error?.message)return t.error.message}catch{}return e}function j(e,t){return new Promise((n,r)=>{if(t?.aborted){r(Error(`Request was aborted`));return}let i=setTimeout(n,e);t?.addEventListener(`abort`,()=>{clearTimeout(i),r(Error(`Request was aborted`))})})}var M=(r,i,a)=>{let s=new t;return(async()=>{let t={role:`assistant`,content:[],api:`google-gemini-cli`,provider:r.provider,model:r.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:`stop`,timestamp:Date.now()};try{let c=a?.apiKey;if(!c)throw Error(`Google Cloud Code Assist requires OAuth authentication. Use /login to authenticate.`);let d,h;try{let e=JSON.parse(c);d=e.token,h=e.projectId}catch{throw Error(`Invalid Google Cloud Code Assist credentials. Use /login to re-authenticate.`)}if(!d||!h)throw Error(`Missing token or projectId in Google Cloud credentials. Use /login to re-authenticate.`);let _=r.provider===`google-antigravity`,E=r.baseUrl?.trim(),D=E?[E]:_?p:[f],O=P(r,i,h,a,_),M=await a?.onPayload?.(O,r);M!==void 0&&(O=M);let N=_?g():m,F={Authorization:`Bearer ${d}`,"Content-Type":`application/json`,Accept:`text/event-stream`,...N,...T(r)?{"anthropic-beta":C}:{},...a?.headers},I=JSON.stringify(O),L,R,z,B=0;for(let e=0;e<=y;e++){if(a?.signal?.aborted)throw Error(`Request was aborted`);try{if(z=`${D[B]}/v1internal:streamGenerateContent?alt=sse`,L=await fetch(z,{method:`POST`,headers:F,body:I,signal:a?.signal}),await a?.onResponse?.({status:L.status,headers:n(L.headers)},r),L.ok)break;let t=await L.text();if((L.status===403||L.status===404)&&B<D.length-1){B++;continue}if(e<y&&k(L.status,t)){B<D.length-1&&B++;let n=w(t,L),r=n??b*2**e,i=a?.maxRetryDelayMs??6e4;if(i>0&&n&&n>i){let e=Math.ceil(n/1e3);throw Error(`Server requested ${e}s retry delay (max: ${Math.ceil(i/1e3)}s). ${A(t)}`)}await j(r,a?.signal);continue}throw Error(`Cloud Code Assist API error (${L.status}): ${A(t)}`)}catch(t){if(t instanceof Error&&(t.name===`AbortError`||t.message===`Request was aborted`))throw Error(`Request was aborted`);if(R=t instanceof Error?t:Error(String(t)),R.message===`fetch failed`&&R.cause instanceof Error&&(R=Error(`Network error: ${R.cause.message}`)),e<y){await j(b*2**e,a?.signal);continue}throw R}}if(!L||!L.ok)throw R??Error(`Failed to get response after retries`);let V=!1,H=()=>{V||=(s.push({type:`start`,partial:t}),!0)},U=()=>{t.content=[],t.usage={input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},t.stopReason=`stop`,t.errorMessage=void 0,t.timestamp=Date.now(),V=!1},W=async n=>{if(!n.body)throw Error(`No response body`);let i=!1,c=null,d=t.content,f=()=>d.length-1,p=n.body.getReader(),m=new TextDecoder,h=``,g=()=>{p.cancel().catch(()=>{})};a?.signal?.addEventListener(`abort`,g);try{for(;;){if(a?.signal?.aborted)throw Error(`Request was aborted`);let{done:n,value:g}=await p.read();if(n)break;h+=m.decode(g,{stream:!0});let _=h.split(`
2
2
  `);h=_.pop()||``;for(let n of _){if(!n.startsWith(`data:`))continue;let a=n.slice(5).trim();if(!a)continue;let p;try{p=JSON.parse(a)}catch{continue}let m=p.response;if(!m)continue;t.responseId||=m.responseId;let h=m.candidates?.[0];if(h?.content?.parts)for(let e of h.content.parts){if(e.text!==void 0){i=!0;let n=l(e);(!c||n&&c.type!==`thinking`||!n&&c.type!==`text`)&&(c&&(c.type===`text`?s.push({type:`text_end`,contentIndex:d.length-1,content:c.text,partial:t}):s.push({type:`thinking_end`,contentIndex:f(),content:c.thinking,partial:t})),n?(c={type:`thinking`,thinking:``,thinkingSignature:void 0},t.content.push(c),H(),s.push({type:`thinking_start`,contentIndex:f(),partial:t})):(c={type:`text`,text:``},t.content.push(c),H(),s.push({type:`text_start`,contentIndex:f(),partial:t}))),c.type===`thinking`?(c.thinking+=e.text,c.thinkingSignature=u(c.thinkingSignature,e.thoughtSignature),s.push({type:`thinking_delta`,contentIndex:f(),delta:e.text,partial:t})):(c.text+=e.text,c.textSignature=u(c.textSignature,e.thoughtSignature),s.push({type:`text_delta`,contentIndex:f(),delta:e.text,partial:t}))}if(e.functionCall){i=!0,c&&=(c.type===`text`?s.push({type:`text_end`,contentIndex:f(),content:c.text,partial:t}):s.push({type:`thinking_end`,contentIndex:f(),content:c.thinking,partial:t}),null);let n=e.functionCall.id,r={type:`toolCall`,id:!n||t.content.some(e=>e.type===`toolCall`&&e.id===n)?`${e.functionCall.name}_${Date.now()}_${++v}`:n,name:e.functionCall.name||``,arguments:e.functionCall.args??{},...e.thoughtSignature&&{thoughtSignature:e.thoughtSignature}};t.content.push(r),H(),s.push({type:`toolcall_start`,contentIndex:f(),partial:t}),s.push({type:`toolcall_delta`,contentIndex:f(),delta:JSON.stringify(r.arguments),partial:t}),s.push({type:`toolcall_end`,contentIndex:f(),toolCall:r,partial:t})}}if(h?.finishReason&&(t.stopReason=o(h.finishReason),t.content.some(e=>e.type===`toolCall`)&&(t.stopReason=`toolUse`)),m.usageMetadata){let n=m.usageMetadata.promptTokenCount||0,i=m.usageMetadata.cachedContentTokenCount||0;t.usage={input:n-i,output:(m.usageMetadata.candidatesTokenCount||0)+(m.usageMetadata.thoughtsTokenCount||0),cacheRead:i,cacheWrite:0,totalTokens:m.usageMetadata.totalTokenCount||0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},e(r,t.usage)}}}}finally{a?.signal?.removeEventListener(`abort`,g)}return c&&(c.type===`text`?s.push({type:`text_end`,contentIndex:f(),content:c.text,partial:t}):s.push({type:`thinking_end`,contentIndex:f(),content:c.thinking,partial:t})),i},G=!1,K=L;for(let e=0;e<=x;e++){if(a?.signal?.aborted)throw Error(`Request was aborted`);if(e>0){if(await j(S*2**(e-1),a?.signal),!z)throw Error(`Missing request URL`);if(K=await fetch(z,{method:`POST`,headers:F,body:I,signal:a?.signal}),await a?.onResponse?.({status:K.status,headers:n(K.headers)},r),!K.ok){let e=await K.text();throw Error(`Cloud Code Assist API error (${K.status}): ${e}`)}}if(await W(K)){G=!0;break}e<x&&U()}if(!G)throw Error(`Cloud Code Assist API returned an empty response`);if(a?.signal?.aborted)throw Error(`Request was aborted`);if(t.stopReason===`aborted`||t.stopReason===`error`)throw Error(`An unknown error occurred`);s.push({type:`done`,reason:t.stopReason,message:t}),s.end()}catch(e){for(let e of t.content)`index`in e&&delete e.index;t.stopReason=a?.signal?.aborted?`aborted`:`error`,t.errorMessage=e instanceof Error?e.message:JSON.stringify(e),s.push({type:`error`,reason:t.stopReason,error:t}),s.end()}})(),s},N=(e,t,n)=>{let r=n?.apiKey;if(!r)throw Error(`Google Cloud Code Assist requires OAuth authentication. Use /login to authenticate.`);let o=a(e,n,r);if(!n?.reasoning)return M(e,t,{...o,thinking:{enabled:!1}});let s=i(n.reasoning);if(O(e.id))return M(e,t,{...o,thinking:{enabled:!0,level:I(s,e.id)}});let c={minimal:1024,low:2048,medium:8192,high:16384,...n.thinkingBudgets}[s],l=Math.min((o.maxTokens||0)+c,e.maxTokens);return l<=c&&(c=Math.max(0,l-1024)),M(e,t,{...o,maxTokens:l,thinking:{enabled:!0,budgetTokens:c}})};function P(e,t,n,i={},a=!1){let o=d(e,t),l={};i.temperature!==void 0&&(l.temperature=i.temperature),i.maxTokens!==void 0&&(l.maxOutputTokens=i.maxTokens),i.thinking?.enabled&&e.reasoning?(l.thinkingConfig={includeThoughts:!0},i.thinking.level===void 0?i.thinking.budgetTokens!==void 0&&(l.thinkingConfig.thinkingBudget=i.thinking.budgetTokens):l.thinkingConfig.thinkingLevel=i.thinking.level):e.reasoning&&i.thinking&&!i.thinking.enabled&&(l.thinkingConfig=F(e.id));let u={contents:o};if(u.sessionId=i.sessionId,t.systemPrompt&&(u.systemInstruction={parts:[{text:r(t.systemPrompt)}]}),Object.keys(l).length>0&&(u.generationConfig=l),t.tools&&t.tools.length>0){let n=e.id.startsWith(`claude-`);u.tools=s(t.tools,n),i.toolChoice&&(u.toolConfig={functionCallingConfig:{mode:c(i.toolChoice)}})}if(a){let e=u.systemInstruction?.parts??[];u.systemInstruction={role:`user`,parts:[{text:_},{text:`Please ignore following [ignore]${_}[/ignore]`},...e]}}return{project:n,model:e.id,request:u,...a?{requestType:`agent`}:{},userAgent:a?`antigravity`:`pi-coding-agent`,requestId:`${a?`agent`:`pi`}-${Date.now()}-${Math.random().toString(36).slice(2,11)}`}}function F(e){return E(e)?{thinkingLevel:`LOW`}:D(e)?{thinkingLevel:`MINIMAL`}:{thinkingBudget:0}}function I(e,t){if(E(t))switch(e){case`minimal`:case`low`:return`LOW`;case`medium`:case`high`:return`HIGH`}switch(e){case`minimal`:return`MINIMAL`;case`low`:return`LOW`;case`medium`:return`MEDIUM`;case`high`:return`HIGH`}}export{P as buildRequest,w as extractRetryDelay,M as streamGoogleGeminiCli,N as streamSimpleGoogleGeminiCli};
@@ -1 +1 @@
1
- import{a as e,i as t}from"./index-Bx9iFrzC.js";import{a as n,i as r,r as i}from"./transform-messages-CV4kCtBB.js";import{c as a,i as o,l as s,n as c,o as l,r as u,s as d,t as f,u as p}from"./google-shared-XhYUKiGZ.js";var m=`v1`,h=`gcp-vertex-credentials`,g={THINKING_LEVEL_UNSPECIFIED:p.THINKING_LEVEL_UNSPECIFIED,MINIMAL:p.MINIMAL,LOW:p.LOW,MEDIUM:p.MEDIUM,HIGH:p.HIGH},_=0,v=(n,r,i)=>{let a=new t;return(async()=>{let t={role:`assistant`,content:[],api:`google-vertex`,provider:n.provider,model:n.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:`stop`,timestamp:Date.now()};try{let s=T(i),c=s?x(n,s,i?.headers):b(n,D(i),O(i),i?.headers),l=k(n,r,i),f=await i?.onPayload?.(l,n);f!==void 0&&(l=f);let p=await c.models.generateContentStream(l);a.push({type:`start`,partial:t});let m=null,h=t.content,g=()=>h.length-1;for await(let r of p){t.responseId||=r.responseId;let i=r.candidates?.[0];if(i?.content?.parts)for(let e of i.content.parts){if(e.text!==void 0){let n=u(e);(!m||n&&m.type!==`thinking`||!n&&m.type!==`text`)&&(m&&(m.type===`text`?a.push({type:`text_end`,contentIndex:h.length-1,content:m.text,partial:t}):a.push({type:`thinking_end`,contentIndex:g(),content:m.thinking,partial:t})),n?(m={type:`thinking`,thinking:``,thinkingSignature:void 0},t.content.push(m),a.push({type:`thinking_start`,contentIndex:g(),partial:t})):(m={type:`text`,text:``},t.content.push(m),a.push({type:`text_start`,contentIndex:g(),partial:t}))),m.type===`thinking`?(m.thinking+=e.text,m.thinkingSignature=d(m.thinkingSignature,e.thoughtSignature),a.push({type:`thinking_delta`,contentIndex:g(),delta:e.text,partial:t})):(m.text+=e.text,m.textSignature=d(m.textSignature,e.thoughtSignature),a.push({type:`text_delta`,contentIndex:g(),delta:e.text,partial:t}))}if(e.functionCall){m&&=(m.type===`text`?a.push({type:`text_end`,contentIndex:g(),content:m.text,partial:t}):a.push({type:`thinking_end`,contentIndex:g(),content:m.thinking,partial:t}),null);let n=e.functionCall.id,r={type:`toolCall`,id:!n||t.content.some(e=>e.type===`toolCall`&&e.id===n)?`${e.functionCall.name}_${Date.now()}_${++_}`:n,name:e.functionCall.name||``,arguments:e.functionCall.args??{},...e.thoughtSignature&&{thoughtSignature:e.thoughtSignature}};t.content.push(r),a.push({type:`toolcall_start`,contentIndex:g(),partial:t}),a.push({type:`toolcall_delta`,contentIndex:g(),delta:JSON.stringify(r.arguments),partial:t}),a.push({type:`toolcall_end`,contentIndex:g(),toolCall:r,partial:t})}}i?.finishReason&&(t.stopReason=o(i.finishReason),t.content.some(e=>e.type===`toolCall`)&&(t.stopReason=`toolUse`)),r.usageMetadata&&(t.usage={input:(r.usageMetadata.promptTokenCount||0)-(r.usageMetadata.cachedContentTokenCount||0),output:(r.usageMetadata.candidatesTokenCount||0)+(r.usageMetadata.thoughtsTokenCount||0),cacheRead:r.usageMetadata.cachedContentTokenCount||0,cacheWrite:0,totalTokens:r.usageMetadata.totalTokenCount||0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},e(n,t.usage))}if(m&&(m.type===`text`?a.push({type:`text_end`,contentIndex:g(),content:m.text,partial:t}):a.push({type:`thinking_end`,contentIndex:g(),content:m.thinking,partial:t})),i?.signal?.aborted)throw Error(`Request was aborted`);if(t.stopReason===`aborted`||t.stopReason===`error`)throw Error(`An unknown error occurred`);a.push({type:`done`,reason:t.stopReason,message:t}),a.end()}catch(e){for(let e of t.content)`index`in e&&delete e.index;t.stopReason=i?.signal?.aborted?`aborted`:`error`,t.errorMessage=e instanceof Error?e.message:JSON.stringify(e),a.push({type:`error`,reason:t.stopReason,error:t}),a.end()}})(),a},y=(e,t,n)=>{let a=i(e,n,void 0);if(!n?.reasoning)return v(e,t,{...a,thinking:{enabled:!1}});let o=r(n.reasoning),s=e;return A(s)||j(s)?v(e,t,{...a,thinking:{enabled:!0,level:N(o,s)}}):v(e,t,{...a,thinking:{enabled:!0,budgetTokens:P(s,o,n.thinkingBudgets)}})};function b(e,t,n,r){return new a({vertexai:!0,project:t,location:n,apiVersion:m,httpOptions:S(e,r)})}function x(e,t,n){return new a({vertexai:!0,apiKey:t,apiVersion:m,httpOptions:S(e,n)})}function S(e,t){let n={},r=C(e.baseUrl);return r&&(n.baseUrl=r,n.baseUrlResourceScope=s.COLLECTION,w(r)&&(n.apiVersion=``)),(e.headers||t)&&(n.headers={...e.headers,...t}),Object.keys(n).length>0?n:void 0}function C(e){let t=e.trim();if(!(!t||t.includes(`{location}`)))return t}function w(e){try{return new URL(e).pathname.split(`/`).some(e=>/^v\d+(?:beta\d*)?$/.test(e))}catch{return/(?:^|\/)v\d+(?:beta\d*)?(?:\/|$)/.test(e)}}function T(e){let t=e?.apiKey?.trim()||{}.GOOGLE_CLOUD_API_KEY?.trim();if(!(!t||t===h||E(t)))return t}function E(e){return/^<[^>]+>$/.test(e)}function D(e){let t=e?.project||{}.GOOGLE_CLOUD_PROJECT||{}.GCLOUD_PROJECT;if(!t)throw Error(`Vertex AI requires a project ID. Set GOOGLE_CLOUD_PROJECT/GCLOUD_PROJECT or pass project in options.`);return t}function O(e){let t=e?.location||{}.GOOGLE_CLOUD_LOCATION;if(!t)throw Error(`Vertex AI requires a location. Set GOOGLE_CLOUD_LOCATION or pass location in options.`);return t}function k(e,t,r={}){let i=f(e,t),a={};r.temperature!==void 0&&(a.temperature=r.temperature),r.maxTokens!==void 0&&(a.maxOutputTokens=r.maxTokens);let o={...Object.keys(a).length>0&&a,...t.systemPrompt&&{systemInstruction:n(t.systemPrompt)},...t.tools&&t.tools.length>0&&{tools:c(t.tools)}};if(t.tools&&t.tools.length>0&&r.toolChoice?o.toolConfig={functionCallingConfig:{mode:l(r.toolChoice)}}:o.toolConfig=void 0,r.thinking?.enabled&&e.reasoning){let e={includeThoughts:!0};r.thinking.level===void 0?r.thinking.budgetTokens!==void 0&&(e.thinkingBudget=r.thinking.budgetTokens):e.thinkingLevel=g[r.thinking.level],o.thinkingConfig=e}else e.reasoning&&r.thinking&&!r.thinking.enabled&&(o.thinkingConfig=M(e));if(r.signal){if(r.signal.aborted)throw Error(`Request aborted`);o.abortSignal=r.signal}return{model:e.id,contents:i,config:o}}function A(e){return/gemini-3(?:\.\d+)?-pro/.test(e.id.toLowerCase())}function j(e){return/gemini-3(?:\.\d+)?-flash/.test(e.id.toLowerCase())}function M(e){let t=e;return A(t)?{thinkingLevel:p.LOW}:j(t)?{thinkingLevel:p.MINIMAL}:{thinkingBudget:0}}function N(e,t){if(A(t))switch(e){case`minimal`:case`low`:return`LOW`;case`medium`:case`high`:return`HIGH`}switch(e){case`minimal`:return`MINIMAL`;case`low`:return`LOW`;case`medium`:return`MEDIUM`;case`high`:return`HIGH`}}function P(e,t,n){return n?.[t]===void 0?e.id.includes(`2.5-pro`)?{minimal:128,low:2048,medium:8192,high:32768}[t]:e.id.includes(`2.5-flash`)?{minimal:128,low:2048,medium:8192,high:24576}[t]:-1:n[t]}export{v as streamGoogleVertex,y as streamSimpleGoogleVertex};
1
+ import{a as e,i as t}from"./index-CgTJgJ5U.js";import{a as n,i as r,r as i}from"./transform-messages-CV4kCtBB.js";import{c as a,i as o,l as s,n as c,o as l,r as u,s as d,t as f,u as p}from"./google-shared-XhYUKiGZ.js";var m=`v1`,h=`gcp-vertex-credentials`,g={THINKING_LEVEL_UNSPECIFIED:p.THINKING_LEVEL_UNSPECIFIED,MINIMAL:p.MINIMAL,LOW:p.LOW,MEDIUM:p.MEDIUM,HIGH:p.HIGH},_=0,v=(n,r,i)=>{let a=new t;return(async()=>{let t={role:`assistant`,content:[],api:`google-vertex`,provider:n.provider,model:n.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:`stop`,timestamp:Date.now()};try{let s=T(i),c=s?x(n,s,i?.headers):b(n,D(i),O(i),i?.headers),l=k(n,r,i),f=await i?.onPayload?.(l,n);f!==void 0&&(l=f);let p=await c.models.generateContentStream(l);a.push({type:`start`,partial:t});let m=null,h=t.content,g=()=>h.length-1;for await(let r of p){t.responseId||=r.responseId;let i=r.candidates?.[0];if(i?.content?.parts)for(let e of i.content.parts){if(e.text!==void 0){let n=u(e);(!m||n&&m.type!==`thinking`||!n&&m.type!==`text`)&&(m&&(m.type===`text`?a.push({type:`text_end`,contentIndex:h.length-1,content:m.text,partial:t}):a.push({type:`thinking_end`,contentIndex:g(),content:m.thinking,partial:t})),n?(m={type:`thinking`,thinking:``,thinkingSignature:void 0},t.content.push(m),a.push({type:`thinking_start`,contentIndex:g(),partial:t})):(m={type:`text`,text:``},t.content.push(m),a.push({type:`text_start`,contentIndex:g(),partial:t}))),m.type===`thinking`?(m.thinking+=e.text,m.thinkingSignature=d(m.thinkingSignature,e.thoughtSignature),a.push({type:`thinking_delta`,contentIndex:g(),delta:e.text,partial:t})):(m.text+=e.text,m.textSignature=d(m.textSignature,e.thoughtSignature),a.push({type:`text_delta`,contentIndex:g(),delta:e.text,partial:t}))}if(e.functionCall){m&&=(m.type===`text`?a.push({type:`text_end`,contentIndex:g(),content:m.text,partial:t}):a.push({type:`thinking_end`,contentIndex:g(),content:m.thinking,partial:t}),null);let n=e.functionCall.id,r={type:`toolCall`,id:!n||t.content.some(e=>e.type===`toolCall`&&e.id===n)?`${e.functionCall.name}_${Date.now()}_${++_}`:n,name:e.functionCall.name||``,arguments:e.functionCall.args??{},...e.thoughtSignature&&{thoughtSignature:e.thoughtSignature}};t.content.push(r),a.push({type:`toolcall_start`,contentIndex:g(),partial:t}),a.push({type:`toolcall_delta`,contentIndex:g(),delta:JSON.stringify(r.arguments),partial:t}),a.push({type:`toolcall_end`,contentIndex:g(),toolCall:r,partial:t})}}i?.finishReason&&(t.stopReason=o(i.finishReason),t.content.some(e=>e.type===`toolCall`)&&(t.stopReason=`toolUse`)),r.usageMetadata&&(t.usage={input:(r.usageMetadata.promptTokenCount||0)-(r.usageMetadata.cachedContentTokenCount||0),output:(r.usageMetadata.candidatesTokenCount||0)+(r.usageMetadata.thoughtsTokenCount||0),cacheRead:r.usageMetadata.cachedContentTokenCount||0,cacheWrite:0,totalTokens:r.usageMetadata.totalTokenCount||0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},e(n,t.usage))}if(m&&(m.type===`text`?a.push({type:`text_end`,contentIndex:g(),content:m.text,partial:t}):a.push({type:`thinking_end`,contentIndex:g(),content:m.thinking,partial:t})),i?.signal?.aborted)throw Error(`Request was aborted`);if(t.stopReason===`aborted`||t.stopReason===`error`)throw Error(`An unknown error occurred`);a.push({type:`done`,reason:t.stopReason,message:t}),a.end()}catch(e){for(let e of t.content)`index`in e&&delete e.index;t.stopReason=i?.signal?.aborted?`aborted`:`error`,t.errorMessage=e instanceof Error?e.message:JSON.stringify(e),a.push({type:`error`,reason:t.stopReason,error:t}),a.end()}})(),a},y=(e,t,n)=>{let a=i(e,n,void 0);if(!n?.reasoning)return v(e,t,{...a,thinking:{enabled:!1}});let o=r(n.reasoning),s=e;return A(s)||j(s)?v(e,t,{...a,thinking:{enabled:!0,level:N(o,s)}}):v(e,t,{...a,thinking:{enabled:!0,budgetTokens:P(s,o,n.thinkingBudgets)}})};function b(e,t,n,r){return new a({vertexai:!0,project:t,location:n,apiVersion:m,httpOptions:S(e,r)})}function x(e,t,n){return new a({vertexai:!0,apiKey:t,apiVersion:m,httpOptions:S(e,n)})}function S(e,t){let n={},r=C(e.baseUrl);return r&&(n.baseUrl=r,n.baseUrlResourceScope=s.COLLECTION,w(r)&&(n.apiVersion=``)),(e.headers||t)&&(n.headers={...e.headers,...t}),Object.keys(n).length>0?n:void 0}function C(e){let t=e.trim();if(!(!t||t.includes(`{location}`)))return t}function w(e){try{return new URL(e).pathname.split(`/`).some(e=>/^v\d+(?:beta\d*)?$/.test(e))}catch{return/(?:^|\/)v\d+(?:beta\d*)?(?:\/|$)/.test(e)}}function T(e){let t=e?.apiKey?.trim()||{}.GOOGLE_CLOUD_API_KEY?.trim();if(!(!t||t===h||E(t)))return t}function E(e){return/^<[^>]+>$/.test(e)}function D(e){let t=e?.project||{}.GOOGLE_CLOUD_PROJECT||{}.GCLOUD_PROJECT;if(!t)throw Error(`Vertex AI requires a project ID. Set GOOGLE_CLOUD_PROJECT/GCLOUD_PROJECT or pass project in options.`);return t}function O(e){let t=e?.location||{}.GOOGLE_CLOUD_LOCATION;if(!t)throw Error(`Vertex AI requires a location. Set GOOGLE_CLOUD_LOCATION or pass location in options.`);return t}function k(e,t,r={}){let i=f(e,t),a={};r.temperature!==void 0&&(a.temperature=r.temperature),r.maxTokens!==void 0&&(a.maxOutputTokens=r.maxTokens);let o={...Object.keys(a).length>0&&a,...t.systemPrompt&&{systemInstruction:n(t.systemPrompt)},...t.tools&&t.tools.length>0&&{tools:c(t.tools)}};if(t.tools&&t.tools.length>0&&r.toolChoice?o.toolConfig={functionCallingConfig:{mode:l(r.toolChoice)}}:o.toolConfig=void 0,r.thinking?.enabled&&e.reasoning){let e={includeThoughts:!0};r.thinking.level===void 0?r.thinking.budgetTokens!==void 0&&(e.thinkingBudget=r.thinking.budgetTokens):e.thinkingLevel=g[r.thinking.level],o.thinkingConfig=e}else e.reasoning&&r.thinking&&!r.thinking.enabled&&(o.thinkingConfig=M(e));if(r.signal){if(r.signal.aborted)throw Error(`Request aborted`);o.abortSignal=r.signal}return{model:e.id,contents:i,config:o}}function A(e){return/gemini-3(?:\.\d+)?-pro/.test(e.id.toLowerCase())}function j(e){return/gemini-3(?:\.\d+)?-flash/.test(e.id.toLowerCase())}function M(e){let t=e;return A(t)?{thinkingLevel:p.LOW}:j(t)?{thinkingLevel:p.MINIMAL}:{thinkingBudget:0}}function N(e,t){if(A(t))switch(e){case`minimal`:case`low`:return`LOW`;case`medium`:case`high`:return`HIGH`}switch(e){case`minimal`:return`MINIMAL`;case`low`:return`LOW`;case`medium`:return`MEDIUM`;case`high`:return`HIGH`}}function P(e,t,n){return n?.[t]===void 0?e.id.includes(`2.5-pro`)?{minimal:128,low:2048,medium:8192,high:32768}[t]:e.id.includes(`2.5-flash`)?{minimal:128,low:2048,medium:8192,high:24576}[t]:-1:n[t]}export{v as streamGoogleVertex,y as streamSimpleGoogleVertex};