v0 2.2.5 → 3.0.0-canary.6f0caa8
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/LICENSE +13 -0
- package/README.md +20 -12
- package/dist/index.cjs +13 -0
- package/dist/index.d.cts +6269 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +6269 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +14 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +37 -64
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -21
- package/dist/index.js.map +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2025 Vercel, Inc.
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,21 +1,29 @@
|
|
|
1
|
-
#
|
|
1
|
+
# v0
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
TypeScript SDK for the v0 API.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Install
|
|
6
6
|
|
|
7
|
-
```
|
|
8
|
-
|
|
7
|
+
```sh
|
|
8
|
+
npm install v0
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
pnpm dlx v0@latest init
|
|
13
|
-
```
|
|
11
|
+
## Usage
|
|
14
12
|
|
|
15
|
-
```
|
|
16
|
-
|
|
13
|
+
```ts
|
|
14
|
+
import { v0 } from 'v0'
|
|
15
|
+
|
|
16
|
+
const response = await v0.chats.create({
|
|
17
|
+
message: 'Build me a personal website',
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
if (response.error) {
|
|
21
|
+
throw new Error(response.error.message)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
console.log(response.data.chat.id)
|
|
17
25
|
```
|
|
18
26
|
|
|
19
|
-
|
|
27
|
+
The default `v0` client uses `V0_API_KEY` when present, otherwise it falls back to Vercel OIDC auth for server-side code deployed on Vercel. Use `createV0Client` when you need custom auth or client options.
|
|
20
28
|
|
|
21
|
-
|
|
29
|
+
See https://v0.app/docs/api/v2 for full documentation and API reference.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`jsondiffpatch`);c=s(c,1);let l=require(`@vercel/oidc`);const u={bodySerializer:e=>JSON.stringify(e,(e,t)=>typeof t==`bigint`?t.toString():t)},d=Object.entries({$body_:`body`,$headers_:`headers`,$path_:`path`,$query_:`query`}),f=(e,t)=>{t||=new Map;for(let n of e)`in`in n?n.key&&t.set(n.key,{in:n.in,map:n.map}):`key`in n?t.set(n.key,{map:n.map}):n.args&&f(n.args,t);return t},p=e=>{for(let[t,n]of Object.entries(e))n&&typeof n==`object`&&!Array.isArray(n)&&!Object.keys(n).length&&delete e[t]},m=(e,t)=>{let n={body:{},headers:{},path:{},query:{}},r=f(t),i;for(let[a,o]of e.entries())if(t[a]&&(i=t[a]),i)if(`in`in i)if(i.key){let e=r.get(i.key),t=e.map||i.key;e.in&&(n[e.in][t]=o)}else n.body=o;else for(let[e,t]of Object.entries(o??{})){let a=r.get(e);if(a)if(a.in){let r=a.map||e;n[a.in][r]=t}else n[a.map]=t;else{let r=d.find(([t])=>e.startsWith(t));if(r){let[i,a]=r;n[a][e.slice(i.length)]=t}else if(`allowExtra`in i&&i.allowExtra){for(let[r,a]of Object.entries(i.allowExtra))if(a){n[r][e]=t;break}}}}return p(n),n},h=({onRequest:e,onSseError:t,onSseEvent:n,responseTransformer:r,responseValidator:i,sseDefaultRetryDelay:a,sseMaxRetryAttempts:o,sseMaxRetryDelay:s,sseSleepFn:c,url:l,...u})=>{let d,f=c??(e=>new Promise(t=>setTimeout(t,e)));return{stream:async function*(){let c=a??3e3,p=0,m=u.signal??new AbortController().signal;for(;!m.aborted;){p++;let a=u.headers instanceof Headers?u.headers:new Headers(u.headers);d!==void 0&&a.set(`Last-Event-ID`,d);try{let t={redirect:`follow`,...u,body:u.serializedBody,headers:a,signal:m},o=new Request(l,t);e&&(o=await e(l,t));let s=await(u.fetch??globalThis.fetch)(o);if(!s.ok)throw Error(`SSE failed: ${s.status} ${s.statusText}`);if(!s.body)throw Error(`No body in SSE response`);let f=s.body.pipeThrough(new TextDecoderStream).getReader(),p=``,h=()=>{try{f.cancel()}catch{}};m.addEventListener(`abort`,h);try{for(;;){let{done:e,value:t}=await f.read();if(e)break;p+=t,p=p.replace(/\r\n/g,`
|
|
2
|
+
`).replace(/\r/g,`
|
|
3
|
+
`);let a=p.split(`
|
|
4
|
+
|
|
5
|
+
`);p=a.pop()??``;for(let e of a){let t=e.split(`
|
|
6
|
+
`),a=[],o;for(let e of t)if(e.startsWith(`data:`))a.push(e.replace(/^data:\s*/,``));else if(e.startsWith(`event:`))o=e.replace(/^event:\s*/,``);else if(e.startsWith(`id:`))d=e.replace(/^id:\s*/,``);else if(e.startsWith(`retry:`)){let t=Number.parseInt(e.replace(/^retry:\s*/,``),10);Number.isNaN(t)||(c=t)}let s,l=!1;if(a.length){let e=a.join(`
|
|
7
|
+
`);try{s=JSON.parse(e),l=!0}catch{s=e}}l&&(i&&await i(s),r&&(s=await r(s))),n?.({data:s,event:o,id:d,retry:c}),a.length&&(yield s)}}}finally{m.removeEventListener(`abort`,h),f.releaseLock()}break}catch(e){if(t?.(e),o!==void 0&&p>=o)break;await f(Math.min(c*2**(p-1),s??3e4))}}}()}},ee=e=>{switch(e){case`label`:return`.`;case`matrix`:return`;`;case`simple`:return`,`;default:return`&`}},te=e=>{switch(e){case`form`:return`,`;case`pipeDelimited`:return`|`;case`spaceDelimited`:return`%20`;default:return`,`}},ne=e=>{switch(e){case`label`:return`.`;case`matrix`:return`;`;case`simple`:return`,`;default:return`&`}},g=({allowReserved:e,explode:t,name:n,style:r,value:i})=>{if(!t){let t=(e?i:i.map(e=>encodeURIComponent(e))).join(te(r));switch(r){case`label`:return`.${t}`;case`matrix`:return`;${n}=${t}`;case`simple`:return t;default:return`${n}=${t}`}}let a=ee(r),o=i.map(t=>r===`label`||r===`simple`?e?t:encodeURIComponent(t):_({allowReserved:e,name:n,value:t})).join(a);return r===`label`||r===`matrix`?a+o:o},_=({allowReserved:e,name:t,value:n})=>{if(n==null)return``;if(typeof n==`object`)throw Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");return`${t}=${e?n:encodeURIComponent(n)}`},v=({allowReserved:e,explode:t,name:n,style:r,value:i,valueOnly:a})=>{if(i instanceof Date)return a?i.toISOString():`${n}=${i.toISOString()}`;if(r!==`deepObject`&&!t){let t=[];Object.entries(i).forEach(([n,r])=>{t=[...t,n,e?r:encodeURIComponent(r)]});let a=t.join(`,`);switch(r){case`form`:return`${n}=${a}`;case`label`:return`.${a}`;case`matrix`:return`;${n}=${a}`;default:return a}}let o=ne(r),s=Object.entries(i).map(([t,i])=>_({allowReserved:e,name:r===`deepObject`?`${n}[${t}]`:t,value:i})).join(o);return r===`label`||r===`matrix`?o+s:s},y=/\{[^{}]+\}/g,re=({path:e,url:t})=>{let n=t,r=t.match(y);if(r)for(let t of r){let r=!1,i=t.substring(1,t.length-1),a=`simple`;i.endsWith(`*`)&&(r=!0,i=i.substring(0,i.length-1)),i.startsWith(`.`)?(i=i.substring(1),a=`label`):i.startsWith(`;`)&&(i=i.substring(1),a=`matrix`);let o=e[i];if(o==null)continue;if(Array.isArray(o)){n=n.replace(t,g({explode:r,name:i,style:a,value:o}));continue}if(typeof o==`object`){n=n.replace(t,v({explode:r,name:i,style:a,value:o,valueOnly:!0}));continue}if(a===`matrix`){n=n.replace(t,`;${_({name:i,value:o})}`);continue}let s=encodeURIComponent(a===`label`?`.${o}`:o);n=n.replace(t,s)}return n},ie=({baseUrl:e,path:t,query:n,querySerializer:r,url:i})=>{let a=i.startsWith(`/`)?i:`/${i}`,o=(e??``)+a;t&&(o=re({path:t,url:o}));let s=n?r(n):``;return s.startsWith(`?`)&&(s=s.substring(1)),s&&(o+=`?${s}`),o};function b(e){let t=e.body!==void 0;if(t&&e.bodySerializer)return`serializedBody`in e?e.serializedBody!==void 0&&e.serializedBody!==``?e.serializedBody:null:e.body===``?null:e.body;if(t)return e.body}const x=async(e,t)=>{let n=typeof t==`function`?await t(e):t;if(n)return e.scheme===`bearer`?`Bearer ${n}`:e.scheme===`basic`?`Basic ${btoa(n)}`:n},S=({parameters:e={},...t}={})=>n=>{let r=[];if(n&&typeof n==`object`)for(let i in n){let a=n[i];if(a==null)continue;let o=e[i]||t;if(Array.isArray(a)){let e=g({allowReserved:o.allowReserved,explode:!0,name:i,style:`form`,value:a,...o.array});e&&r.push(e)}else if(typeof a==`object`){let e=v({allowReserved:o.allowReserved,explode:!0,name:i,style:`deepObject`,value:a,...o.object});e&&r.push(e)}else{let e=_({allowReserved:o.allowReserved,name:i,value:a});e&&r.push(e)}}return r.join(`&`)},ae=e=>{if(!e)return`stream`;let t=e.split(`;`)[0]?.trim();if(t){if(t.startsWith(`application/json`)||t.endsWith(`+json`))return`json`;if(t===`multipart/form-data`)return`formData`;if([`application/`,`audio/`,`image/`,`video/`].some(e=>t.startsWith(e)))return`blob`;if(t.startsWith(`text/`))return`text`}},oe=(e,t)=>t?!!(e.headers.has(t)||e.query?.[t]||e.headers.get(`Cookie`)?.includes(`${t}=`)):!1,se=async({security:e,...t})=>{for(let n of e){if(oe(t,n.name))continue;let e=await x(n,t.auth);if(!e)continue;let r=n.name??`Authorization`;switch(n.in){case`query`:t.query||={},t.query[r]=e;break;case`cookie`:t.headers.append(`Cookie`,`${r}=${e}`);break;default:t.headers.set(r,e);break}}},C=e=>ie({baseUrl:e.baseUrl,path:e.path,query:e.query,querySerializer:typeof e.querySerializer==`function`?e.querySerializer:S(e.querySerializer),url:e.url}),w=(e,t)=>{let n={...e,...t};return n.baseUrl?.endsWith(`/`)&&(n.baseUrl=n.baseUrl.substring(0,n.baseUrl.length-1)),n.headers=T(e.headers,t.headers),n},ce=e=>{let t=[];return e.forEach((e,n)=>{t.push([n,e])}),t},T=(...e)=>{let t=new Headers;for(let n of e){if(!n)continue;let e=n instanceof Headers?ce(n):Object.entries(n);for(let[n,r]of e)if(r===null)t.delete(n);else if(Array.isArray(r))for(let e of r)t.append(n,e);else r!==void 0&&t.set(n,typeof r==`object`?JSON.stringify(r):r)}return t};var E=class{fns=[];clear(){this.fns=[]}eject(e){let t=this.getInterceptorIndex(e);this.fns[t]&&(this.fns[t]=null)}exists(e){let t=this.getInterceptorIndex(e);return!!this.fns[t]}getInterceptorIndex(e){return typeof e==`number`?this.fns[e]?e:-1:this.fns.indexOf(e)}update(e,t){let n=this.getInterceptorIndex(e);return this.fns[n]?(this.fns[n]=t,e):!1}use(e){return this.fns.push(e),this.fns.length-1}};const le=()=>({error:new E,request:new E,response:new E}),ue=S({allowReserved:!1,array:{explode:!0,style:`form`},object:{explode:!0,style:`deepObject`}}),de={"Content-Type":`application/json`},D=(e={})=>({...u,headers:de,parseAs:`auto`,querySerializer:ue,...e}),O=(e={})=>{let t=w(D(),e),n=()=>({...t}),r=e=>(t=w(t,e),n()),i=le(),a=async e=>{let n={...t,...e,fetch:e.fetch??t.fetch??globalThis.fetch,headers:T(t.headers,e.headers),serializedBody:void 0};return n.security&&await se({...n,security:n.security}),n.requestValidator&&await n.requestValidator(n),n.body!==void 0&&n.bodySerializer&&(n.serializedBody=n.bodySerializer(n.body)),(n.body===void 0||n.serializedBody===``)&&n.headers.delete(`Content-Type`),{opts:n,url:C(n)}},o=async e=>{let{opts:t,url:n}=await a(e),r={redirect:`follow`,...t,body:b(t)},o=new Request(n,r);for(let e of i.request.fns)e&&(o=await e(o,t));let s=t.fetch,c;try{c=await s(o)}catch(e){let n=e;for(let r of i.error.fns)r&&(n=await r(e,void 0,o,t));if(n||={},t.throwOnError)throw n;return t.responseStyle===`data`?void 0:{error:n,request:o,response:void 0}}for(let e of i.response.fns)e&&(c=await e(c,o,t));let l={request:o,response:c};if(c.ok){let e=(t.parseAs===`auto`?ae(c.headers.get(`Content-Type`)):t.parseAs)??`json`;if(c.status===204||c.headers.get(`Content-Length`)===`0`){let n;switch(e){case`arrayBuffer`:case`blob`:case`text`:n=await c[e]();break;case`formData`:n=new FormData;break;case`stream`:n=c.body;break;default:n={};break}return t.responseStyle===`data`?n:{data:n,...l}}let n;switch(e){case`arrayBuffer`:case`blob`:case`formData`:case`text`:n=await c[e]();break;case`json`:{let e=await c.text();n=e?JSON.parse(e):{};break}case`stream`:return t.responseStyle===`data`?c.body:{data:c.body,...l}}return e===`json`&&(t.responseValidator&&await t.responseValidator(n),t.responseTransformer&&(n=await t.responseTransformer(n))),t.responseStyle===`data`?n:{data:n,...l}}let u=await c.text(),d;try{d=JSON.parse(u)}catch{}let f=d??u,p=f;for(let e of i.error.fns)e&&(p=await e(f,c,o,t));if(p||={},t.throwOnError)throw p;return t.responseStyle===`data`?void 0:{error:p,...l}},s=e=>t=>o({...t,method:e}),c=e=>async t=>{let{opts:n,url:r}=await a(t);return h({...n,body:n.body,headers:n.headers,method:e,onRequest:async(e,t)=>{let r=new Request(e,t);for(let e of i.request.fns)e&&(r=await e(r,n));return r},serializedBody:b(n),url:r})};return{buildUrl:e=>C({...t,...e}),connect:s(`CONNECT`),delete:s(`DELETE`),get:s(`GET`),getConfig:n,head:s(`HEAD`),interceptors:i,options:s(`OPTIONS`),patch:s(`PATCH`),post:s(`POST`),put:s(`PUT`),request:o,setConfig:r,sse:{connect:c(`CONNECT`),delete:c(`DELETE`),get:c(`GET`),head:c(`HEAD`),options:c(`OPTIONS`),patch:c(`PATCH`),post:c(`POST`),put:c(`PUT`),trace:c(`TRACE`)},trace:s(`TRACE`)}},fe=O(D()),pe=async e=>(e.chats=e.chats.map(e=>(e.createdAt=new Date(e.createdAt),e.updatedAt&&=new Date(e.updatedAt),e)),e),k=e=>(e.chat.createdAt=new Date(e.chat.createdAt),e.chat.updatedAt&&(e.chat.updatedAt=new Date(e.chat.updatedAt)),e),me=async e=>(e=k(e),e),he=async e=>(e=k(e),e),ge=async e=>(e=k(e),e),A=e=>(e.messages=e.messages.map(e=>(e.createdAt=new Date(e.createdAt),e.updatedAt=new Date(e.updatedAt),e.parts=e.parts.map(e=>(e.startedAt&&=new Date(e.startedAt),e.finishedAt&&=new Date(e.finishedAt),e)),e)),e),j=async e=>(e=A(e),e),M=e=>(e.createdAt=new Date(e.createdAt),e.updatedAt=new Date(e.updatedAt),e.parts=e.parts.map(e=>(e.startedAt&&=new Date(e.startedAt),e.finishedAt&&=new Date(e.finishedAt),e)),e),N=async e=>(e=M(e),e),P=async e=>(e=M(e),e),F=async e=>(e=M(e),e),I=e=>(e.createdAt=new Date(e.createdAt),e.updatedAt&&=new Date(e.updatedAt),e),L=async e=>(e=I(e),e),_e=async e=>(e=I(e),e),ve=async e=>(e.messages=e.messages.map(e=>(e.createdAt=new Date(e.createdAt),e.updatedAt=new Date(e.updatedAt),e.parts=e.parts.map(e=>(e.startedAt&&=new Date(e.startedAt),e.finishedAt&&=new Date(e.finishedAt),e)),e)),e),ye=async e=>(e.messages=e.messages.map(e=>(e.createdAt=new Date(e.createdAt),e.updatedAt=new Date(e.updatedAt),e.parts=e.parts.map(e=>(e.startedAt&&=new Date(e.startedAt),e.finishedAt&&=new Date(e.finishedAt),e)),e)),e),be=async e=>(e=I(e),e),xe=async e=>(e=e.map(e=>(e.createdAt=new Date(e.createdAt),e.updatedAt=new Date(e.updatedAt),e)),e),R=e=>(e.createdAt=new Date(e.createdAt),e.updatedAt=new Date(e.updatedAt),e),Se=async e=>(e=R(e),e),Ce=async e=>(e=R(e),e),we=async e=>(e=R(e),e),z=e=>(e.createdAt=new Date(e.createdAt),e.updatedAt=new Date(e.updatedAt),e),Te=async e=>(e=z(e),e),Ee=async e=>(e=z(e),e),De=async e=>(e=z(e),e),Oe=async e=>(e=z(e),e),B=e=>(e.createdAt=new Date(e.createdAt),e),ke=async e=>(e=B(e),e),Ae=async e=>(e=B(e),e),je=async e=>(e=B(e),e);var V=class{client;constructor(e){this.client=e?.client??fe}},Me=class{defaultKey=`default`;instances=new Map;get(e){let t=this.instances.get(e??this.defaultKey);if(!t)throw Error(`No SDK client found. Create one with "new V0Sdk()" to fix this error.`);return t}set(e,t){this.instances.set(t??this.defaultKey,e)}},Ne=class extends V{list(e,t){let n=m([e],[{args:[{in:`query`,key:`limit`},{in:`query`,key:`cursor`},{in:`query`,key:`authorId`},{in:`query`,key:`vercelProjectId`},{in:`query`,key:`metadata`}]}]);return(t?.client??this.client).get({responseTransformer:pe,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats`,...t,...n})}create(e,t){let n=m([e],[{args:[{in:`body`,key:`message`},{in:`body`,key:`systemPrompt`},{in:`body`,key:`modelConfiguration`},{in:`body`,key:`attachments`},{in:`body`,key:`mcpServerIds`},{in:`body`,key:`skillIds`},{in:`body`,key:`privacy`},{in:`body`,key:`title`},{in:`body`,key:`metadata`}]}]);return(t?.client??this.client).post({responseTransformer:me,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}createFromZip(e,t){let n=m([e],[{args:[{in:`body`,key:`url`},{in:`body`,key:`privacy`},{in:`body`,key:`title`},{in:`body`,key:`metadata`}]}]);return(t?.client??this.client).post({responseTransformer:he,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/from-zip`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}createFromRepo(e,t){let n=m([e],[{args:[{in:`body`,key:`repo`},{in:`body`,key:`privacy`},{in:`body`,key:`title`},{in:`body`,key:`metadata`}]}]);return(t?.client??this.client).post({responseTransformer:ge,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/from-repo`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}createStream(e,t){let n=m([e],[{args:[{in:`body`,key:`message`},{in:`body`,key:`systemPrompt`},{in:`body`,key:`modelConfiguration`},{in:`body`,key:`attachments`},{in:`body`,key:`mcpServerIds`},{in:`body`,key:`skillIds`},{in:`body`,key:`privacy`},{in:`body`,key:`title`},{in:`body`,key:`metadata`}]}]);return(t?.client??this.client).sse.post({security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/stream`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}createAsync(e,t){let n=m([e],[{args:[{in:`body`,key:`message`},{in:`body`,key:`systemPrompt`},{in:`body`,key:`modelConfiguration`},{in:`body`,key:`attachments`},{in:`body`,key:`mcpServerIds`},{in:`body`,key:`skillIds`},{in:`body`,key:`privacy`},{in:`body`,key:`title`},{in:`body`,key:`metadata`}]}]);return(t?.client??this.client).post({security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/async`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}delete(e,t){let n=m([e],[{args:[{in:`path`,key:`chatId`}]}]);return(t?.client??this.client).delete({security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/{chatId}`,...t,...n})}get(e,t){let n=m([e],[{args:[{in:`path`,key:`chatId`}]}]);return(t?.client??this.client).get({responseTransformer:L,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/{chatId}`,...t,...n})}update(e,t){let n=m([e],[{args:[{in:`path`,key:`chatId`},{in:`body`,key:`title`},{in:`body`,key:`privacy`},{in:`body`,key:`metadata`}]}]);return(t?.client??this.client).patch({responseTransformer:_e,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/{chatId}`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}getPreview(e,t){let n=m([e],[{args:[{in:`path`,key:`chatId`}]}]);return(t?.client??this.client).get({security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/{chatId}/preview`,...t,...n})}getFiles(e,t){let n=m([e],[{args:[{in:`path`,key:`chatId`}]}]);return(t?.client??this.client).get({security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/{chatId}/files`,...t,...n})}updateFiles(e,t){let n=m([e],[{args:[{in:`path`,key:`chatId`},{in:`body`,key:`files`}]}]);return(t?.client??this.client).patch({responseTransformer:ve,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/{chatId}/files`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}downloadFiles(e,t){let n=m([e],[{args:[{in:`path`,key:`chatId`}]}]);return(t?.client??this.client).get({security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/{chatId}/files/download`,...t,...n})}restoreMessage(e,t){let n=m([e],[{args:[{in:`path`,key:`chatId`},{in:`body`,key:`messageId`}]}]);return(t?.client??this.client).post({responseTransformer:ye,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/{chatId}/restore-message`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}duplicate(e,t){let n=m([e],[{args:[{in:`path`,key:`chatId`},{in:`body`,key:`privacy`},{in:`body`,key:`title`}]}]);return(t?.client??this.client).post({responseTransformer:be,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/{chatId}/duplicate`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}deploy(e,t){let n=m([e],[{args:[{in:`path`,key:`chatId`}]}]);return(t?.client??this.client).post({security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/{chatId}/deploy`,...t,...n})}createVercelProject(e,t){let n=m([e],[{args:[{in:`path`,key:`chatId`},{in:`body`,key:`name`}]}]);return(t?.client??this.client).post({security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/{chatId}/vercel-project`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}resume(e,t){let n=m([e],[{args:[{in:`path`,key:`chatId`}]}]);return(t?.client??this.client).sse.post({security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/{chatId}/resume`,...t,...n})}},Pe=class extends V{list(e,t){let n=m([e],[{args:[{in:`path`,key:`chatId`},{in:`query`,key:`limit`},{in:`query`,key:`cursor`}]}]);return(t?.client??this.client).get({responseTransformer:j,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/{chatId}/messages`,...t,...n})}send(e,t){let n=m([e],[{args:[{in:`path`,key:`chatId`},{in:`body`,key:`message`},{in:`body`,key:`systemPrompt`},{in:`body`,key:`modelConfiguration`},{in:`body`,key:`mcpServerIds`},{in:`body`,key:`attachments`},{in:`body`,key:`skillIds`},{in:`body`,key:`action`}]}]);return(t?.client??this.client).post({responseTransformer:N,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/{chatId}/messages`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}get(e,t){let n=m([e],[{args:[{in:`path`,key:`chatId`},{in:`path`,key:`messageId`}]}]);return(t?.client??this.client).get({responseTransformer:P,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/{chatId}/messages/{messageId}`,...t,...n})}sendStream(e,t){let n=m([e],[{args:[{in:`path`,key:`chatId`},{in:`body`,key:`message`},{in:`body`,key:`systemPrompt`},{in:`body`,key:`modelConfiguration`},{in:`body`,key:`mcpServerIds`},{in:`body`,key:`attachments`},{in:`body`,key:`skillIds`},{in:`body`,key:`action`}]}]);return(t?.client??this.client).sse.post({security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/{chatId}/messages/stream`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}sendAsync(e,t){let n=m([e],[{args:[{in:`path`,key:`chatId`},{in:`body`,key:`message`},{in:`body`,key:`systemPrompt`},{in:`body`,key:`modelConfiguration`},{in:`body`,key:`mcpServerIds`},{in:`body`,key:`attachments`},{in:`body`,key:`skillIds`},{in:`body`,key:`action`}]}]);return(t?.client??this.client).post({security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/{chatId}/messages/async`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}resolve(e,t){let n=m([e],[{args:[{in:`path`,key:`chatId`},{in:`body`,key:`task`},{in:`body`,key:`modelConfiguration`}]}]);return(t?.client??this.client).post({responseTransformer:F,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/{chatId}/messages/resolve`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}resolveStream(e,t){let n=m([e],[{args:[{in:`path`,key:`chatId`},{in:`body`,key:`task`},{in:`body`,key:`modelConfiguration`}]}]);return(t?.client??this.client).sse.post({security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/{chatId}/messages/resolve/stream`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}resolveAsync(e,t){let n=m([e],[{args:[{in:`path`,key:`chatId`},{in:`body`,key:`task`},{in:`body`,key:`modelConfiguration`}]}]);return(t?.client??this.client).post({security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/{chatId}/messages/resolve/async`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}stop(e,t){let n=m([e],[{args:[{in:`path`,key:`chatId`},{in:`path`,key:`messageId`}]}]);return(t?.client??this.client).post({security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/{chatId}/messages/{messageId}/stop`,...t,...n})}},Fe=class extends V{list(e){return(e?.client??this.client).get({responseTransformer:xe,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/mcp-servers`,...e})}create(e,t){let n=m([e],[{args:[{in:`body`,key:`name`},{in:`body`,key:`url`},{in:`body`,key:`description`},{in:`body`,key:`enabled`},{in:`body`,key:`auth`},{in:`body`,key:`scope`}]}]);return(t?.client??this.client).post({responseTransformer:Se,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/mcp-servers`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}delete(e,t){let n=m([e],[{args:[{in:`path`,key:`mcpServerId`}]}]);return(t?.client??this.client).delete({security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/mcp-servers/{mcpServerId}`,...t,...n})}get(e,t){let n=m([e],[{args:[{in:`path`,key:`mcpServerId`}]}]);return(t?.client??this.client).get({responseTransformer:Ce,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/mcp-servers/{mcpServerId}`,...t,...n})}update(e,t){let n=m([e],[{args:[{in:`path`,key:`mcpServerId`},{in:`body`,key:`name`},{in:`body`,key:`url`},{in:`body`,key:`description`},{in:`body`,key:`enabled`},{in:`body`,key:`auth`},{in:`body`,key:`scope`}]}]);return(t?.client??this.client).patch({responseTransformer:we,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/mcp-servers/{mcpServerId}`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}},Ie=class extends V{listApiKeys(e,t){let n=m([e],[{args:[{in:`path`,key:`orgId`},{in:`path`,key:`teamId`}]}]);return(t?.client??this.client).get({security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/organizations/{orgId}/teams/{teamId}/api-keys`,...t,...n})}createApiKey(e,t){let n=m([e],[{args:[{in:`path`,key:`orgId`},{in:`path`,key:`teamId`},{in:`body`,key:`name`}]}]);return(t?.client??this.client).post({security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/organizations/{orgId}/teams/{teamId}/api-keys`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}deleteApiKey(e,t){let n=m([e],[{args:[{in:`path`,key:`orgId`},{in:`path`,key:`teamId`},{in:`path`,key:`keyId`}]}]);return(t?.client??this.client).delete({security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/organizations/{orgId}/teams/{teamId}/api-keys/{keyId}`,...t,...n})}deleteSpendLimit(e,t){let n=m([e],[{args:[{in:`path`,key:`orgId`},{in:`path`,key:`teamId`}]}]);return(t?.client??this.client).delete({security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/organizations/{orgId}/teams/{teamId}/spend-limit`,...t,...n})}getSpendLimit(e,t){let n=m([e],[{args:[{in:`path`,key:`orgId`},{in:`path`,key:`teamId`}]}]);return(t?.client??this.client).get({responseTransformer:De,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/organizations/{orgId}/teams/{teamId}/spend-limit`,...t,...n})}setSpendLimit(e,t){let n=m([e],[{args:[{in:`path`,key:`orgId`},{in:`path`,key:`teamId`},{in:`body`,key:`limit`}]}]);return(t?.client??this.client).put({responseTransformer:Oe,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/organizations/{orgId}/teams/{teamId}/spend-limit`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}},Le=class extends V{getSpendLimit(e,t){let n=m([e],[{args:[{in:`path`,key:`orgId`}]}]);return(t?.client??this.client).get({responseTransformer:Te,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/organizations/{orgId}/spend-limit`,...t,...n})}setSpendLimit(e,t){let n=m([e],[{args:[{in:`path`,key:`orgId`},{in:`body`,key:`limit`}]}]);return(t?.client??this.client).put({responseTransformer:Ee,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/organizations/{orgId}/spend-limit`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}_teams;get teams(){return this._teams??=new Ie({client:this.client})}},Re=class extends V{list(e){return(e?.client??this.client).get({security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/hooks`,...e})}create(e,t){let n=m([e],[{args:[{in:`body`,key:`name`},{in:`body`,key:`events`},{in:`body`,key:`url`},{in:`body`,key:`chatId`}]}]);return(t?.client??this.client).post({responseTransformer:ke,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/hooks`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}delete(e,t){let n=m([e],[{args:[{in:`path`,key:`hookId`}]}]);return(t?.client??this.client).delete({security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/hooks/{hookId}`,...t,...n})}get(e,t){let n=m([e],[{args:[{in:`path`,key:`hookId`}]}]);return(t?.client??this.client).get({responseTransformer:Ae,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/hooks/{hookId}`,...t,...n})}update(e,t){let n=m([e],[{args:[{in:`path`,key:`hookId`},{in:`body`,key:`name`},{in:`body`,key:`events`},{in:`body`,key:`url`}]}]);return(t?.client??this.client).patch({responseTransformer:je,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/hooks/{hookId}`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}},ze=class e extends V{static __registry=new Me;constructor(t){super(t),e.__registry.set(this,t?.key)}_chats;get chats(){return this._chats??=new Ne({client:this.client})}_messages;get messages(){return this._messages??=new Pe({client:this.client})}_mcpServers;get mcpServers(){return this._mcpServers??=new Fe({client:this.client})}_organizations;get organizations(){return this._organizations??=new Le({client:this.client})}_webhooks;get webhooks(){return this._webhooks??=new Re({client:this.client})}};const H=c.create({});function Be(e,t){if(!t)return e;try{let n=H.clone(e);return Ve(t)?He(n,t):H.patch(n,t)}catch{return e}}function Ve(e){if(!Array.isArray(e))return!1;let t=e[0];if(!Array.isArray(t)||t.length===0)return!1;let n=t[t.length-1];return e[1]===9&&e[2]===9&&typeof n==`string`&&t.slice(0,-1).every(e=>Number.isInteger(e))}function He(e,t){let n=t[0],r=n[n.length-1];if(typeof r!=`string`)return e;let i=n.slice(0,-1);if(i.length===0)return typeof e==`string`?`${e}${r}`:e;let a=e;for(let t of i){if(!Ue(a))return e;let n=a[t];if(typeof n==`string`)return a[t]=`${n}${r}`,e;a=n}return e}function Ue(e){return typeof e==`object`&&!!e}var U=class extends Error{code;id;constructor(e,t={}){super(e),this.name=`V0StreamError`,this.code=t.code,this.id=t.id}};function W(e){return new G(async(t,n)=>{let r;for await(let n of e)r=Ge(r,n),t(r);if(!r)throw new U(`v0 stream ended before sending an event`);n(K(r))})}function We(e){return new G(async(t,n)=>{let r;for await(let i of Ze(await e)){if(i.event===`update`){r=i.data,t(i.data);continue}if(i.event===`done`){n(i.data);return}throw new U(typeof i.data.message==`string`?i.data.message:`v0 stream failed`,{code:typeof i.data.code==`string`?i.data.code:void 0,id:typeof i.data.id==`string`?i.data.id:void 0})}if(!r)throw new U(`v0 stream ended before sending an event`);n(K(r))})}var G=class{stream;history=[];subscribers=new Set;finalPromise;started=!1;finished=!1;failure;resolveFinal;rejectFinal;constructor(e){this.run=e,this.finalPromise=new Promise((e,t)=>{this.resolveFinal=e,this.rejectFinal=t}),this.finalPromise.catch(()=>{}),this.stream={[Symbol.asyncIterator]:()=>this.subscribe()}}get final(){return this.start(),this.finalPromise}toResponse(e={}){let t=new TextEncoder,n=this,r=new ReadableStream({async start(e){try{for await(let r of n.stream)e.enqueue(t.encode(J(`update`,r)));e.enqueue(t.encode(J(`done`,await n.final)))}catch(n){e.enqueue(t.encode(J(`error`,Xe(n))))}finally{e.close()}}}),i=new Headers(e.headers);return i.has(`Content-Type`)||i.set(`Content-Type`,`text/event-stream; charset=utf-8`),i.has(`Cache-Control`)||i.set(`Cache-Control`,`no-cache, no-transform`),i.has(`Connection`)||i.set(`Connection`,`keep-alive`),i.has(`X-Accel-Buffering`)||i.set(`X-Accel-Buffering`,`no`),new Response(r,{...e,headers:i})}async*subscribe(){let e={queue:[...this.history],notify:void 0};this.subscribers.add(e),this.start();try{for(;;){if(e.queue.length>0){yield e.queue.shift();continue}if(this.failure)throw this.failure;if(this.finished)return;await new Promise(t=>{e.notify=t}),e.notify=void 0}}finally{this.subscribers.delete(e)}}start(){this.started||(this.started=!0,this.run(e=>this.publish(e),e=>this.finish(e)).catch(e=>this.fail(e)))}publish(e){this.history.push(e);for(let t of this.subscribers)t.queue.push(e),t.notify?.()}finish(e){this.finished||(this.finished=!0,this.resolveFinal(e),this.notifySubscribers())}fail(e){this.finished||(this.finished=!0,this.failure=e,this.rejectFinal(e),this.notifySubscribers())}notifySubscribers(){for(let e of this.subscribers)e.notify?.()}};function Ge(e,t){let n=e??Ke(t);switch(t.object){case`chat`:return{...n,event:t,chat:q(t)};case`chat.title`:return qe({...n,event:t},t.delta);case`message`:{let e=q(t);return{...n,event:t,message:e,parts:e.parts,usage:e.usage}}case`message.parts.chunk`:return Je({...n,event:t},t.delta);case`message.usage`:return Ye({...n,event:t},t.usage);case`error`:throw new U(t.message,{code:t.code,id:t.id});default:{let e=t;throw new U(typeof e.message==`string`?e.message:`v0 stream failed`,{code:typeof e.code==`string`?e.code:void 0,id:typeof e.id==`string`?e.id:void 0})}}}function Ke(e){return{status:`streaming`,event:e,parts:[]}}function qe(e,t){return{...e,title:t,chat:e.chat?{...e.chat,title:t}:e.chat}}function Je(e,t){let n=Be(e.parts,t);return{...e,parts:n,message:e.message?{...e.message,parts:n}:e.message}}function Ye(e,t){return{...e,usage:t,message:e.message?{...e.message,usage:t}:e.message}}function K(e){return{...e,status:`done`}}function q(e){let{object:t,...n}=e;return n}function J(e,t){return`event: ${e}\ndata: ${JSON.stringify(t)}\n\n`}function Xe(e){return e instanceof U?{message:e.message,code:e.code,id:e.id}:e instanceof Error?{message:e.message}:{message:`v0 stream failed`}}async function*Ze(e){if(!e.ok)throw new U(`v0 stream request failed: ${e.status} ${e.statusText}`);if(!e.body)throw new U(`v0 stream response did not include a body`);let t=e.body.pipeThrough(new TextDecoderStream).getReader(),n=``;try{for(;;){let{done:e,value:r}=await t.read();if(e)break;n+=r,n=n.replace(/\r\n/g,`
|
|
8
|
+
`).replace(/\r/g,`
|
|
9
|
+
`);let i=n.split(`
|
|
10
|
+
|
|
11
|
+
`);n=i.pop()??``;for(let e of i){let t=Y(e);t&&(yield t)}}let e=n.trim();if(e){let t=Y(e);t&&(yield t)}}finally{t.releaseLock()}}function Y(e){let t=`message`,n=[];for(let r of e.split(`
|
|
12
|
+
`)){if(r.startsWith(`event:`)){t=r.replace(/^event:\s*/,``);continue}r.startsWith(`data:`)&&n.push(r.replace(/^data:\s*/,``))}if(n.length===0)return null;let r=JSON.parse(n.join(`
|
|
13
|
+
`));return(t===`update`||t===`message`)&&X(r)?{event:`update`,data:r}:t===`done`&&X(r)?{event:`done`,data:r}:t===`error`&&X(r)?{event:`error`,data:r}:null}function X(e){return typeof e==`object`&&!!e}function Z(e={}){return async t=>(e.getToken??l.getVercelOidcToken)()}function Q(e={}){let{auth:t=$,...n}=e;return tt(new ze({client:O(D({baseUrl:`https://v0.app`,...n,auth:t}))}))}const Qe=Q(),$e=Z();async function $(e){return et()??$e(e)}function et(){return globalThis.process?.env?.V0_API_KEY}function tt(e){let t=nt(e.chats),n=rt(e.messages);return new Proxy(e,{get(e,r,i){return r===`chats`?t:r===`messages`?n:Reflect.get(e,r,i)}})}function nt(e){return new Proxy(e,{get(e,t,n){return t===`createStream`?async(t,n)=>W((await e.createStream(t,n)).stream):Reflect.get(e,t,n)}})}function rt(e){return new Proxy(e,{get(e,t,n){return t===`sendStream`?async(t,n)=>W((await e.sendStream(t,n)).stream):Reflect.get(e,t,n)}})}exports.V0StreamError=U,exports.createV0Client=Q,exports.readV0Stream=We,exports.v0=Qe,exports.vercelOidcAuth=Z;
|