v0 2.2.5 → 3.0.0-canary.8c49281
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 +26 -11
- package/dist/index.cjs +13 -0
- package/dist/index.d.cts +5572 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +5572 -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,36 @@
|
|
|
1
|
-
#
|
|
1
|
+
# v0
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
TypeScript SDK for the v0 Platform API.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Install
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
|
|
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 { createV0Client } from 'v0'
|
|
15
|
+
|
|
16
|
+
const v0 = createV0Client({
|
|
17
|
+
auth: process.env.V0_API_KEY!,
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
const response = await v0.chats.create({
|
|
21
|
+
body: {
|
|
22
|
+
type: 'prompt',
|
|
23
|
+
message: 'Build me a personal website',
|
|
24
|
+
},
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
if (response.error) {
|
|
28
|
+
throw new Error(response.error.message)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
console.log(response.data.chat.id)
|
|
17
32
|
```
|
|
18
33
|
|
|
19
|
-
|
|
34
|
+
For server-side code deployed on Vercel with OIDC enabled, `auth` can be omitted.
|
|
20
35
|
|
|
21
|
-
|
|
36
|
+
See the repository README for streaming and development examples.
|
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)};Object.entries({$body_:`body`,$headers_:`headers`,$path_:`path`,$query_:`query`});const d=({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))}}}()}},f=e=>{switch(e){case`label`:return`.`;case`matrix`:return`;`;case`simple`:return`,`;default:return`&`}},p=e=>{switch(e){case`form`:return`,`;case`pipeDelimited`:return`|`;case`spaceDelimited`:return`%20`;default:return`,`}},m=e=>{switch(e){case`label`:return`.`;case`matrix`:return`;`;case`simple`:return`,`;default:return`&`}},h=({allowReserved:e,explode:t,name:n,style:r,value:i})=>{if(!t){let t=(e?i:i.map(e=>encodeURIComponent(e))).join(p(r));switch(r){case`label`:return`.${t}`;case`matrix`:return`;${n}=${t}`;case`simple`:return t;default:return`${n}=${t}`}}let a=f(r),o=i.map(t=>r===`label`||r===`simple`?e?t:encodeURIComponent(t):g({allowReserved:e,name:n,value:t})).join(a);return r===`label`||r===`matrix`?a+o:o},g=({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)}`},_=({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=m(r),s=Object.entries(i).map(([t,i])=>g({allowReserved:e,name:r===`deepObject`?`${n}[${t}]`:t,value:i})).join(o);return r===`label`||r===`matrix`?o+s:s},ee=/\{[^{}]+\}/g,te=({path:e,url:t})=>{let n=t,r=t.match(ee);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,h({explode:r,name:i,style:a,value:o}));continue}if(typeof o==`object`){n=n.replace(t,_({explode:r,name:i,style:a,value:o,valueOnly:!0}));continue}if(a===`matrix`){n=n.replace(t,`;${g({name:i,value:o})}`);continue}let s=encodeURIComponent(a===`label`?`.${o}`:o);n=n.replace(t,s)}return n},v=({baseUrl:e,path:t,query:n,querySerializer:r,url:i})=>{let a=i.startsWith(`/`)?i:`/${i}`,o=(e??``)+a;t&&(o=te({path:t,url:o}));let s=n?r(n):``;return s.startsWith(`?`)&&(s=s.substring(1)),s&&(o+=`?${s}`),o};function y(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 ne=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},b=({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=h({allowReserved:o.allowReserved,explode:!0,name:i,style:`form`,value:a,...o.array});e&&r.push(e)}else if(typeof a==`object`){let e=_({allowReserved:o.allowReserved,explode:!0,name:i,style:`deepObject`,value:a,...o.object});e&&r.push(e)}else{let e=g({allowReserved:o.allowReserved,name:i,value:a});e&&r.push(e)}}return r.join(`&`)},re=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`}},ie=(e,t)=>t?!!(e.headers.has(t)||e.query?.[t]||e.headers.get(`Cookie`)?.includes(`${t}=`)):!1,ae=async({security:e,...t})=>{for(let n of e){if(ie(t,n.name))continue;let e=await ne(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}}},x=e=>v({baseUrl:e.baseUrl,path:e.path,query:e.query,querySerializer:typeof e.querySerializer==`function`?e.querySerializer:b(e.querySerializer),url:e.url}),S=(e,t)=>{let n={...e,...t};return n.baseUrl?.endsWith(`/`)&&(n.baseUrl=n.baseUrl.substring(0,n.baseUrl.length-1)),n.headers=C(e.headers,t.headers),n},oe=e=>{let t=[];return e.forEach((e,n)=>{t.push([n,e])}),t},C=(...e)=>{let t=new Headers;for(let n of e){if(!n)continue;let e=n instanceof Headers?oe(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 w=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 se=()=>({error:new w,request:new w,response:new w}),T=b({allowReserved:!1,array:{explode:!0,style:`form`},object:{explode:!0,style:`deepObject`}}),ce={"Content-Type":`application/json`},E=(e={})=>({...u,headers:ce,parseAs:`auto`,querySerializer:T,...e}),D=(e={})=>{let t=S(E(),e),n=()=>({...t}),r=e=>(t=S(t,e),n()),i=se(),a=async e=>{let n={...t,...e,fetch:e.fetch??t.fetch??globalThis.fetch,headers:C(t.headers,e.headers),serializedBody:void 0};return n.security&&await ae({...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:x(n)}},o=async e=>{let{opts:t,url:n}=await a(e),r={redirect:`follow`,...t,body:y(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`?re(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 d({...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:y(n),url:r})};return{buildUrl:e=>x({...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`)}},le=D(E()),ue=async e=>(e.chats=e.chats.map(e=>(e.createdAt=new Date(e.createdAt),e.updatedAt&&=new Date(e.updatedAt),e)),e),de=e=>(e.chat.createdAt=new Date(e.chat.createdAt),e.chat.updatedAt&&(e.chat.updatedAt=new Date(e.chat.updatedAt)),e),fe=async e=>(e=de(e),e),pe=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),me=async e=>(e=pe(e),e),O=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),k=async e=>(e=O(e),e),A=async e=>(e=O(e),e),j=async e=>(e=O(e),e),M=e=>(e.createdAt=new Date(e.createdAt),e.updatedAt&&=new Date(e.updatedAt),e),N=async e=>(e=M(e),e),P=async e=>(e=M(e),e),F=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),I=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),L=async e=>(e=M(e),e),R=async e=>(e=e.map(e=>(e.createdAt=new Date(e.createdAt),e.updatedAt=new Date(e.updatedAt),e)),e),z=e=>(e.createdAt=new Date(e.createdAt),e.updatedAt=new Date(e.updatedAt),e),he=async e=>(e=z(e),e),ge=async e=>(e=z(e),e),_e=async e=>(e=z(e),e),B=e=>(e.createdAt=new Date(e.createdAt),e.updatedAt=new Date(e.updatedAt),e),ve=async e=>(e=B(e),e),ye=async e=>(e=B(e),e),be=async e=>(e=B(e),e),xe=async e=>(e=B(e),e),V=e=>(e.createdAt=new Date(e.createdAt),e),Se=async e=>(e=V(e),e),Ce=async e=>(e=V(e),e),we=async e=>(e=V(e),e);var H=class{client;constructor(e){this.client=e?.client??le}},Te=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)}},U=class extends H{list(e){return(e?.client??this.client).get({responseTransformer:ue,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats`,...e})}create(e){return(e.client??this.client).post({responseTransformer:fe,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats`,...e,headers:{"Content-Type":`application/json`,...e.headers}})}createStream(e){return(e.client??this.client).sse.post({security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/stream`,...e,headers:{"Content-Type":`application/json`,...e.headers}})}createAsync(e){return(e.client??this.client).post({security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/async`,...e,headers:{"Content-Type":`application/json`,...e.headers}})}delete(e){return(e.client??this.client).delete({security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/{chatId}`,...e})}get(e){return(e.client??this.client).get({responseTransformer:N,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/{chatId}`,...e})}update(e){return(e.client??this.client).patch({responseTransformer:P,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/{chatId}`,...e,headers:{"Content-Type":`application/json`,...e.headers}})}getPreview(e){return(e.client??this.client).get({security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/{chatId}/preview`,...e})}getFiles(e){return(e.client??this.client).get({security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/{chatId}/files`,...e})}updateFiles(e){return(e.client??this.client).patch({responseTransformer:F,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/{chatId}/files`,...e,headers:{"Content-Type":`application/json`,...e.headers}})}downloadFiles(e){return(e.client??this.client).get({security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/{chatId}/files/download`,...e})}restoreMessage(e){return(e.client??this.client).post({responseTransformer:I,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/{chatId}/restore-message`,...e,headers:{"Content-Type":`application/json`,...e.headers}})}duplicate(e){return(e.client??this.client).post({responseTransformer:L,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/{chatId}/duplicate`,...e,headers:{"Content-Type":`application/json`,...e.headers}})}deploy(e){return(e.client??this.client).post({security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/{chatId}/deploy`,...e})}createVercelProject(e){return(e.client??this.client).post({security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/{chatId}/vercel-project`,...e,headers:{"Content-Type":`application/json`,...e.headers}})}resume(e){return(e.client??this.client).sse.post({security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/{chatId}/resume`,...e})}},Ee=class extends H{list(e){return(e.client??this.client).get({responseTransformer:me,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/{chatId}/messages`,...e})}send(e){return(e.client??this.client).post({responseTransformer:k,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/{chatId}/messages`,...e,headers:{"Content-Type":`application/json`,...e.headers}})}get(e){return(e.client??this.client).get({responseTransformer:A,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/{chatId}/messages/{messageId}`,...e})}sendStream(e){return(e.client??this.client).sse.post({security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/{chatId}/messages/stream`,...e,headers:{"Content-Type":`application/json`,...e.headers}})}sendAsync(e){return(e.client??this.client).post({security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/{chatId}/messages/async`,...e,headers:{"Content-Type":`application/json`,...e.headers}})}resolve(e){return(e.client??this.client).post({responseTransformer:j,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/{chatId}/messages/resolve`,...e,headers:{"Content-Type":`application/json`,...e.headers}})}resolveStream(e){return(e.client??this.client).sse.post({security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/{chatId}/messages/resolve/stream`,...e,headers:{"Content-Type":`application/json`,...e.headers}})}resolveAsync(e){return(e.client??this.client).post({security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/{chatId}/messages/resolve/async`,...e,headers:{"Content-Type":`application/json`,...e.headers}})}stop(e){return(e.client??this.client).post({security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/chats/{chatId}/messages/{messageId}/stop`,...e})}},De=class extends H{list(e){return(e?.client??this.client).get({responseTransformer:R,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/mcp-servers`,...e})}create(e){return(e.client??this.client).post({responseTransformer:he,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/mcp-servers`,...e,headers:{"Content-Type":`application/json`,...e.headers}})}delete(e){return(e.client??this.client).delete({security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/mcp-servers/{mcpServerId}`,...e})}get(e){return(e.client??this.client).get({responseTransformer:ge,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/mcp-servers/{mcpServerId}`,...e})}update(e){return(e.client??this.client).patch({responseTransformer:_e,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/mcp-servers/{mcpServerId}`,...e,headers:{"Content-Type":`application/json`,...e.headers}})}},Oe=class extends H{listApiKeys(e){return(e.client??this.client).get({security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/organizations/{orgId}/teams/{teamId}/api-keys`,...e})}createApiKey(e){return(e.client??this.client).post({security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/organizations/{orgId}/teams/{teamId}/api-keys`,...e,headers:{"Content-Type":`application/json`,...e.headers}})}deleteApiKey(e){return(e.client??this.client).delete({security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/organizations/{orgId}/teams/{teamId}/api-keys/{keyId}`,...e})}deleteSpendLimit(e){return(e.client??this.client).delete({security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/organizations/{orgId}/teams/{teamId}/spend-limit`,...e})}getSpendLimit(e){return(e.client??this.client).get({responseTransformer:be,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/organizations/{orgId}/teams/{teamId}/spend-limit`,...e})}setSpendLimit(e){return(e.client??this.client).put({responseTransformer:xe,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/organizations/{orgId}/teams/{teamId}/spend-limit`,...e,headers:{"Content-Type":`application/json`,...e.headers}})}},ke=class extends H{getSpendLimit(e){return(e.client??this.client).get({responseTransformer:ve,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/organizations/{orgId}/spend-limit`,...e})}setSpendLimit(e){return(e.client??this.client).put({responseTransformer:ye,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/organizations/{orgId}/spend-limit`,...e,headers:{"Content-Type":`application/json`,...e.headers}})}_teams;get teams(){return this._teams??=new Oe({client:this.client})}},Ae=class extends H{list(e){return(e?.client??this.client).get({security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/hooks`,...e})}create(e){return(e.client??this.client).post({responseTransformer:Se,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/hooks`,...e,headers:{"Content-Type":`application/json`,...e.headers}})}delete(e){return(e.client??this.client).delete({security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/hooks/{hookId}`,...e})}get(e){return(e.client??this.client).get({responseTransformer:Ce,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/hooks/{hookId}`,...e})}update(e){return(e.client??this.client).patch({responseTransformer:we,security:[{scheme:`bearer`,type:`http`}],url:`/api/v2/hooks/{hookId}`,...e,headers:{"Content-Type":`application/json`,...e.headers}})}},je=class e extends H{static __registry=new Te;constructor(t){super(t),e.__registry.set(this,t?.key)}_chats;get chats(){return this._chats??=new U({client:this.client})}_messages;get messages(){return this._messages??=new Ee({client:this.client})}_mcpServers;get mcpServers(){return this._mcpServers??=new De({client:this.client})}_organizations;get organizations(){return this._organizations??=new ke({client:this.client})}_webhooks;get webhooks(){return this._webhooks??=new Ae({client:this.client})}};const W=c.create({});function Me(e,t){if(!t)return e;try{let n=W.clone(e);return Ne(t)?Pe(n,t):W.patch(n,t)}catch{return e}}function Ne(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 Pe(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(!Fe(a))return e;let n=a[t];if(typeof n==`string`)return a[t]=`${n}${r}`,e;a=n}return e}function Fe(e){return typeof e==`object`&&!!e}var G=class extends Error{code;id;constructor(e,t={}){super(e),this.name=`V0StreamError`,this.code=t.code,this.id=t.id}};function K(e){return new q(async(t,n)=>{let r;for await(let n of e)r=Le(r,n),t(r);if(!r)throw new G(`v0 stream ended before sending an event`);n(J(r))})}function Ie(e){return new q(async(t,n)=>{let r;for await(let i of Ue(await e)){if(i.event===`update`){r=i.data,t(i.data);continue}if(i.event===`done`){n(i.data);return}throw new G(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 G(`v0 stream ended before sending an event`);n(J(r))})}var q=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(X(`update`,r)));e.enqueue(t.encode(X(`done`,await n.final)))}catch(n){e.enqueue(t.encode(X(`error`,He(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 Le(e,t){let n=e??Re(t);switch(t.object){case`chat`:return{...n,event:t,chat:Y(t)};case`chat.title`:return ze({...n,event:t},t.delta);case`message`:{let e=Y(t);return{...n,event:t,message:e,parts:e.parts,usage:e.usage}}case`message.parts.chunk`:return Be({...n,event:t},t.delta);case`message.usage`:return Ve({...n,event:t},t.usage);case`error`:throw new G(t.message,{code:t.code,id:t.id});default:{let e=t;throw new G(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 Re(e){return{status:`streaming`,event:e,parts:[]}}function ze(e,t){return{...e,title:t,chat:e.chat?{...e.chat,title:t}:e.chat}}function Be(e,t){let n=Me(e.parts,t);return{...e,parts:n,message:e.message?{...e.message,parts:n}:e.message}}function Ve(e,t){return{...e,usage:t,message:e.message?{...e.message,usage:t}:e.message}}function J(e){return{...e,status:`done`}}function Y(e){let{object:t,...n}=e;return n}function X(e,t){return`event: ${e}\ndata: ${JSON.stringify(t)}\n\n`}function He(e){return e instanceof G?{message:e.message,code:e.code,id:e.id}:e instanceof Error?{message:e.message}:{message:`v0 stream failed`}}async function*Ue(e){if(!e.ok)throw new G(`v0 stream request failed: ${e.status} ${e.statusText}`);if(!e.body)throw new G(`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=Z(e);t&&(yield t)}}let e=n.trim();if(e){let t=Z(e);t&&(yield t)}}finally{t.releaseLock()}}function Z(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`)&&Q(r)?{event:`update`,data:r}:t===`done`&&Q(r)?{event:`done`,data:r}:t===`error`&&Q(r)?{event:`error`,data:r}:null}function Q(e){return typeof e==`object`&&!!e}function $(e={}){return async t=>(e.getToken??l.getVercelOidcToken)()}function We(e={}){return Ge(new je({client:D(E({baseUrl:`https://v0.app`,auth:$(),...e}))}))}function Ge(e){let t=Ke(e.chats),n=qe(e.messages);return new Proxy(e,{get(e,r,i){return r===`chats`?t:r===`messages`?n:Reflect.get(e,r,i)}})}function Ke(e){return new Proxy(e,{get(e,t,n){return t===`createStream`?async t=>K((await e.createStream(t)).stream):Reflect.get(e,t,n)}})}function qe(e){return new Proxy(e,{get(e,t,n){return t===`sendStream`?async t=>K((await e.sendStream(t)).stream):Reflect.get(e,t,n)}})}exports.V0StreamError=G,exports.createV0Client=We,exports.readV0Stream=Ie,exports.vercelOidcAuth=$;
|