v0 3.0.9 → 3.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,14 +0,0 @@
1
- import*as e from"jsondiffpatch";const t={bodySerializer:e=>JSON.stringify(e,(e,t)=>typeof t==`bigint`?t.toString():t)},n=Object.entries({$body_:`body`,$headers_:`headers`,$path_:`path`,$query_:`query`}),r=(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&&r(n.args,t);return t},i=e=>{for(let[t,n]of Object.entries(e))n&&typeof n==`object`&&!Array.isArray(n)&&!Object.keys(n).length&&delete e[t]},a=(e,t)=>{let a={body:{},headers:{},path:{},query:{}},o=r(t),s;for(let[r,i]of e.entries())if(t[r]&&(s=t[r]),s)if(`in`in s)if(s.key){let e=o.get(s.key),t=e.map||s.key;e.in&&(a[e.in][t]=i)}else a.body=i;else for(let[e,t]of Object.entries(i??{})){let r=o.get(e);if(r)if(r.in){let n=r.map||e;a[r.in][n]=t}else a[r.map]=t;else{let r=n.find(([t])=>e.startsWith(t));if(r){let[n,i]=r;a[i][e.slice(n.length)]=t}else if(`allowExtra`in s&&s.allowExtra){for(let[n,r]of Object.entries(s.allowExtra))if(r){a[n][e]=t;break}}}}return i(a),a},o=({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))}}}()}},s=e=>{switch(e){case`label`:return`.`;case`matrix`:return`;`;case`simple`:return`,`;default:return`&`}},c=e=>{switch(e){case`form`:return`,`;case`pipeDelimited`:return`|`;case`spaceDelimited`:return`%20`;default:return`,`}},l=e=>{switch(e){case`label`:return`.`;case`matrix`:return`;`;case`simple`:return`,`;default:return`&`}},u=({allowReserved:e,explode:t,name:n,style:r,value:i})=>{if(!t){let t=(e?i:i.map(e=>encodeURIComponent(e))).join(c(r));switch(r){case`label`:return`.${t}`;case`matrix`:return`;${n}=${t}`;case`simple`:return t;default:return`${n}=${t}`}}let a=s(r),o=i.map(t=>r===`label`||r===`simple`?e?t:encodeURIComponent(t):d({allowReserved:e,name:n,value:t})).join(a);return r===`label`||r===`matrix`?a+o:o},d=({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)}`},f=({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=l(r),s=Object.entries(i).map(([t,i])=>d({allowReserved:e,name:r===`deepObject`?`${n}[${t}]`:t,value:i})).join(o);return r===`label`||r===`matrix`?o+s:s},p=/\{[^{}]+\}/g,m=({path:e,url:t})=>{let n=t,r=t.match(p);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,u({explode:r,name:i,style:a,value:o}));continue}if(typeof o==`object`){n=n.replace(t,f({explode:r,name:i,style:a,value:o,valueOnly:!0}));continue}if(a===`matrix`){n=n.replace(t,`;${d({name:i,value:o})}`);continue}let s=encodeURIComponent(a===`label`?`.${o}`:o);n=n.replace(t,s)}return n},h=({baseUrl:e,path:t,query:n,querySerializer:r,url:i})=>{let a=i.startsWith(`/`)?i:`/${i}`,o=(e??``)+a;t&&(o=m({path:t,url:o}));let s=n?r(n):``;return s.startsWith(`?`)&&(s=s.substring(1)),s&&(o+=`?${s}`),o};function ee(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 te=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},g=({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=u({allowReserved:o.allowReserved,explode:!0,name:i,style:`form`,value:a,...o.array});e&&r.push(e)}else if(typeof a==`object`){let e=f({allowReserved:o.allowReserved,explode:!0,name:i,style:`deepObject`,value:a,...o.object});e&&r.push(e)}else{let e=d({allowReserved:o.allowReserved,name:i,value:a});e&&r.push(e)}}return r.join(`&`)},ne=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`}},re=(e,t)=>t?!!(e.headers.has(t)||e.query?.[t]||e.headers.get(`Cookie`)?.includes(`${t}=`)):!1,ie=async({security:e,...t})=>{for(let n of e){if(re(t,n.name))continue;let e=await te(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}}},_=e=>h({baseUrl:e.baseUrl,path:e.path,query:e.query,querySerializer:typeof e.querySerializer==`function`?e.querySerializer:g(e.querySerializer),url:e.url}),v=(e,t)=>{let n={...e,...t};return n.baseUrl?.endsWith(`/`)&&(n.baseUrl=n.baseUrl.substring(0,n.baseUrl.length-1)),n.headers=y(e.headers,t.headers),n},ae=e=>{let t=[];return e.forEach((e,n)=>{t.push([n,e])}),t},y=(...e)=>{let t=new Headers;for(let n of e){if(!n)continue;let e=n instanceof Headers?ae(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 b=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 oe=()=>({error:new b,request:new b,response:new b}),se=g({allowReserved:!1,array:{explode:!0,style:`form`},object:{explode:!0,style:`deepObject`}}),ce={"Content-Type":`application/json`},x=(e={})=>({...t,headers:ce,parseAs:`auto`,querySerializer:se,...e}),S=(e={})=>{let t=v(x(),e),n=()=>({...t}),r=e=>(t=v(t,e),n()),i=oe(),a=async e=>{let n={...t,...e,fetch:e.fetch??t.fetch??globalThis.fetch,headers:y(t.headers,e.headers),serializedBody:void 0};return n.security&&await ie({...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:_(n)}},s=async e=>{let{opts:t,url:n}=await a(e),r={redirect:`follow`,...t,body:ee(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`?ne(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}},c=e=>t=>s({...t,method:e}),l=e=>async t=>{let{opts:n,url:r}=await a(t);return o({...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:ee(n),url:r})};return{buildUrl:e=>_({...t,...e}),connect:c(`CONNECT`),delete:c(`DELETE`),get:c(`GET`),getConfig:n,head:c(`HEAD`),interceptors:i,options:c(`OPTIONS`),patch:c(`PATCH`),post:c(`POST`),put:c(`PUT`),request:s,setConfig:r,sse:{connect:l(`CONNECT`),delete:l(`DELETE`),get:l(`GET`),head:l(`HEAD`),options:l(`OPTIONS`),patch:l(`PATCH`),post:l(`POST`),put:l(`PUT`),trace:l(`TRACE`)},trace:c(`TRACE`)}},C=S(x({baseUrl:`https://api.v0.dev/v2`})),w=async e=>(e.chats=e.chats.map(e=>(e.createdAt=new Date(e.createdAt),e.updatedAt&&=new Date(e.updatedAt),e)),e),T=e=>(e.chat.createdAt=new Date(e.chat.createdAt),e.chat.updatedAt&&(e.chat.updatedAt=new Date(e.chat.updatedAt)),e),E=async e=>(e=T(e),e),D=async e=>(e=T(e),e),O=async e=>(e=T(e),e),k=async e=>(e=T(e),e),A=async e=>(e=T(e),e),le=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=le(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),R=async e=>(e=I(e),e),z=async e=>(e&&(e.expiresAt=new Date(e.expiresAt)),e),B=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),V=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),H=async e=>(e=I(e),e),U=async e=>(e=e.map(e=>(e.createdAt=new Date(e.createdAt),e.updatedAt=new Date(e.updatedAt),e)),e),W=e=>(e.createdAt=new Date(e.createdAt),e.updatedAt=new Date(e.updatedAt),e),G=async e=>(e=W(e),e),K=async e=>(e=W(e),e),q=async e=>(e=W(e),e),ue=e=>(e.range.start=new Date(e.range.start),e.range.end=new Date(e.range.end),e.dataAsOf&&=new Date(e.dataAsOf),e),J=async e=>(e=ue(e),e),de=e=>(e.range.start=new Date(e.range.start),e.range.end=new Date(e.range.end),e.data=e.data.map(e=>(e.createdAt=new Date(e.createdAt),e)),e),fe=async e=>(e=de(e),e),pe=e=>(e.range.start=new Date(e.range.start),e.range.end=new Date(e.range.end),e.projects=e.projects.map(e=>(e.firstActivity=new Date(e.firstActivity),e.lastActivity=new Date(e.lastActivity),e)),e.chats=e.chats.map(e=>(e.firstActivity=new Date(e.firstActivity),e.lastActivity=new Date(e.lastActivity),e)),e),me=async e=>(e=pe(e),e),Y=e=>(e.createdAt=new Date(e.createdAt),e),he=async e=>(e=Y(e),e),ge=async e=>(e=Y(e),e),_e=async e=>(e=Y(e),e);var X=class{client;constructor(e){this.client=e?.client??C}},ve=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)}},ye=class extends X{list(e,t){let n=a([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:w,security:[{scheme:`bearer`,type:`http`}],url:`/chats`,...t,...n})}create(e,t){let n=a([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:`skills`},{in:`body`,key:`privacy`},{in:`body`,key:`title`},{in:`body`,key:`metadata`},{in:`body`,key:`credentialAccess`}]}]);return(t?.client??this.client).post({responseTransformer:E,security:[{scheme:`bearer`,type:`http`}],url:`/chats`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}createFromFiles(e,t){let n=a([e],[{args:[{in:`body`,key:`files`},{in:`body`,key:`privacy`},{in:`body`,key:`title`},{in:`body`,key:`metadata`}]}]);return(t?.client??this.client).post({responseTransformer:D,security:[{scheme:`bearer`,type:`http`}],url:`/chats/from-files`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}createFromZip(e,t){let n=a([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:O,security:[{scheme:`bearer`,type:`http`}],url:`/chats/from-zip`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}createFromRepo(e,t){let n=a([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:k,security:[{scheme:`bearer`,type:`http`}],url:`/chats/from-repo`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}createFromVercelProject(e,t){let n=a([e],[{args:[{in:`body`,key:`vercelProjectId`},{in:`body`,key:`baseBranch`},{in:`body`,key:`privacy`},{in:`body`,key:`title`},{in:`body`,key:`metadata`}]}]);return(t?.client??this.client).post({responseTransformer:A,security:[{scheme:`bearer`,type:`http`}],url:`/chats/from-vercel-project`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}createStream(e,t){let n=a([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:`skills`},{in:`body`,key:`privacy`},{in:`body`,key:`title`},{in:`body`,key:`metadata`},{in:`body`,key:`credentialAccess`}]}]);return(t?.client??this.client).sse.post({security:[{scheme:`bearer`,type:`http`}],url:`/chats/stream`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}createAsync(e,t){let n=a([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:`skills`},{in:`body`,key:`privacy`},{in:`body`,key:`title`},{in:`body`,key:`metadata`},{in:`body`,key:`credentialAccess`}]}]);return(t?.client??this.client).post({security:[{scheme:`bearer`,type:`http`}],url:`/chats/async`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}delete(e,t){let n=a([e],[{args:[{in:`path`,key:`chatId`}]}]);return(t?.client??this.client).delete({security:[{scheme:`bearer`,type:`http`}],url:`/chats/{chatId}`,...t,...n})}get(e,t){let n=a([e],[{args:[{in:`path`,key:`chatId`}]}]);return(t?.client??this.client).get({responseTransformer:L,security:[{scheme:`bearer`,type:`http`}],url:`/chats/{chatId}`,...t,...n})}update(e,t){let n=a([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:R,security:[{scheme:`bearer`,type:`http`}],url:`/chats/{chatId}`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}getPreview(e,t){let n=a([e],[{args:[{in:`path`,key:`chatId`}]}]);return(t?.client??this.client).get({responseTransformer:z,security:[{scheme:`bearer`,type:`http`}],url:`/chats/{chatId}/preview`,...t,...n})}getFiles(e,t){let n=a([e],[{args:[{in:`path`,key:`chatId`}]}]);return(t?.client??this.client).get({security:[{scheme:`bearer`,type:`http`}],url:`/chats/{chatId}/files`,...t,...n})}updateFiles(e,t){let n=a([e],[{args:[{in:`path`,key:`chatId`},{in:`body`,key:`files`}]}]);return(t?.client??this.client).patch({responseTransformer:B,security:[{scheme:`bearer`,type:`http`}],url:`/chats/{chatId}/files`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}downloadFiles(e,t){let n=a([e],[{args:[{in:`path`,key:`chatId`}]}]);return(t?.client??this.client).get({security:[{scheme:`bearer`,type:`http`}],url:`/chats/{chatId}/files/download`,...t,...n})}getConnectStatus(e,t){let n=a([e],[{args:[{in:`path`,key:`chatId`},{in:`query`,key:`requestId`}]}]);return(t?.client??this.client).get({security:[{scheme:`bearer`,type:`http`}],url:`/chats/{chatId}/connect/status`,...t,...n})}restoreMessage(e,t){let n=a([e],[{args:[{in:`path`,key:`chatId`},{in:`body`,key:`messageId`}]}]);return(t?.client??this.client).post({responseTransformer:V,security:[{scheme:`bearer`,type:`http`}],url:`/chats/{chatId}/restore-message`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}duplicate(e,t){let n=a([e],[{args:[{in:`path`,key:`chatId`},{in:`body`,key:`privacy`},{in:`body`,key:`title`},{in:`body`,key:`metadata`}]}]);return(t?.client??this.client).post({responseTransformer:H,security:[{scheme:`bearer`,type:`http`}],url:`/chats/{chatId}/duplicate`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}deploy(e,t){let n=a([e],[{args:[{in:`path`,key:`chatId`}]}]);return(t?.client??this.client).post({security:[{scheme:`bearer`,type:`http`}],url:`/chats/{chatId}/deploy`,...t,...n})}createVercelProject(e,t){let n=a([e],[{args:[{in:`path`,key:`chatId`},{in:`body`,key:`name`}]}]);return(t?.client??this.client).post({security:[{scheme:`bearer`,type:`http`}],url:`/chats/{chatId}/vercel-project`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}resume(e,t){let n=a([e],[{args:[{in:`path`,key:`chatId`}]}]);return(t?.client??this.client).sse.post({security:[{scheme:`bearer`,type:`http`}],url:`/chats/{chatId}/resume`,...t,...n})}},be=class extends X{list(e,t){let n=a([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:`/chats/{chatId}/messages`,...t,...n})}send(e,t){let n=a([e],[{args:[{in:`path`,key:`chatId`},{in:`body`,key:`message`},{in:`body`,key:`designMode`},{in:`body`,key:`systemPrompt`},{in:`body`,key:`modelConfiguration`},{in:`body`,key:`mcpServerIds`},{in:`body`,key:`attachments`},{in:`body`,key:`skills`}]}]);return(t?.client??this.client).post({responseTransformer:N,security:[{scheme:`bearer`,type:`http`}],url:`/chats/{chatId}/messages`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}get(e,t){let n=a([e],[{args:[{in:`path`,key:`chatId`},{in:`path`,key:`messageId`}]}]);return(t?.client??this.client).get({responseTransformer:P,security:[{scheme:`bearer`,type:`http`}],url:`/chats/{chatId}/messages/{messageId}`,...t,...n})}sendStream(e,t){let n=a([e],[{args:[{in:`path`,key:`chatId`},{in:`body`,key:`message`},{in:`body`,key:`designMode`},{in:`body`,key:`systemPrompt`},{in:`body`,key:`modelConfiguration`},{in:`body`,key:`mcpServerIds`},{in:`body`,key:`attachments`},{in:`body`,key:`skills`}]}]);return(t?.client??this.client).sse.post({security:[{scheme:`bearer`,type:`http`}],url:`/chats/{chatId}/messages/stream`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}sendAsync(e,t){let n=a([e],[{args:[{in:`path`,key:`chatId`},{in:`body`,key:`message`},{in:`body`,key:`designMode`},{in:`body`,key:`systemPrompt`},{in:`body`,key:`modelConfiguration`},{in:`body`,key:`mcpServerIds`},{in:`body`,key:`attachments`},{in:`body`,key:`skills`}]}]);return(t?.client??this.client).post({security:[{scheme:`bearer`,type:`http`}],url:`/chats/{chatId}/messages/async`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}resolve(e,t){let n=a([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:`/chats/{chatId}/messages/resolve`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}resolveStream(e,t){let n=a([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:`/chats/{chatId}/messages/resolve/stream`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}resolveAsync(e,t){let n=a([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:`/chats/{chatId}/messages/resolve/async`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}stop(e,t){let n=a([e],[{args:[{in:`path`,key:`chatId`},{in:`path`,key:`messageId`}]}]);return(t?.client??this.client).post({security:[{scheme:`bearer`,type:`http`}],url:`/chats/{chatId}/messages/{messageId}/stop`,...t,...n})}},xe=class extends X{list(e){return(e?.client??this.client).get({responseTransformer:U,security:[{scheme:`bearer`,type:`http`}],url:`/mcp-servers`,...e})}create(e,t){let n=a([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:G,security:[{scheme:`bearer`,type:`http`}],url:`/mcp-servers`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}delete(e,t){let n=a([e],[{args:[{in:`path`,key:`mcpServerId`}]}]);return(t?.client??this.client).delete({security:[{scheme:`bearer`,type:`http`}],url:`/mcp-servers/{mcpServerId}`,...t,...n})}get(e,t){let n=a([e],[{args:[{in:`path`,key:`mcpServerId`}]}]);return(t?.client??this.client).get({responseTransformer:K,security:[{scheme:`bearer`,type:`http`}],url:`/mcp-servers/{mcpServerId}`,...t,...n})}update(e,t){let n=a([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:q,security:[{scheme:`bearer`,type:`http`}],url:`/mcp-servers/{mcpServerId}`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}},Se=class extends X{deletePreviewHosts(e,t){let n=a([e],[{args:[{in:`body`,key:`hosts`}]}]);return(t?.client??this.client).delete({security:[{scheme:`bearer`,type:`http`}],url:`/settings/preview-hosts`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}getPreviewHosts(e){return(e?.client??this.client).get({security:[{scheme:`bearer`,type:`http`}],url:`/settings/preview-hosts`,...e})}appendPreviewHosts(e,t){let n=a([e],[{args:[{in:`body`,key:`hosts`}]}]);return(t?.client??this.client).patch({security:[{scheme:`bearer`,type:`http`}],url:`/settings/preview-hosts`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}setPreviewHosts(e,t){let n=a([e],[{args:[{in:`body`,key:`hosts`}]}]);return(t?.client??this.client).put({security:[{scheme:`bearer`,type:`http`}],url:`/settings/preview-hosts`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}},Ce=class extends X{getSummary(e,t){let n=a([e],[{args:[{in:`query`,key:`start`},{in:`query`,key:`end`},{in:`query`,key:`userId`}]}]);return(t?.client??this.client).get({responseTransformer:J,security:[{scheme:`bearer`,type:`http`}],url:`/usage/summary`,...t,...n})}listEvents(e,t){let n=a([e],[{args:[{in:`query`,key:`start`},{in:`query`,key:`end`},{in:`query`,key:`userId`},{in:`query`,key:`chatId`},{in:`query`,key:`messageId`},{in:`query`,key:`limit`},{in:`query`,key:`cursor`}]}]);return(t?.client??this.client).get({responseTransformer:fe,security:[{scheme:`bearer`,type:`http`}],url:`/usage/events`,...t,...n})}getActivity(e,t){let n=a([e],[{args:[{in:`query`,key:`start`},{in:`query`,key:`end`},{in:`query`,key:`userId`}]}]);return(t?.client??this.client).get({responseTransformer:me,security:[{scheme:`bearer`,type:`http`}],url:`/usage/activity`,...t,...n})}},we=class extends X{list(e){return(e?.client??this.client).get({security:[{scheme:`bearer`,type:`http`}],url:`/hooks`,...e})}create(e,t){let n=a([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:he,security:[{scheme:`bearer`,type:`http`}],url:`/hooks`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}delete(e,t){let n=a([e],[{args:[{in:`path`,key:`hookId`}]}]);return(t?.client??this.client).delete({security:[{scheme:`bearer`,type:`http`}],url:`/hooks/{hookId}`,...t,...n})}get(e,t){let n=a([e],[{args:[{in:`path`,key:`hookId`}]}]);return(t?.client??this.client).get({responseTransformer:ge,security:[{scheme:`bearer`,type:`http`}],url:`/hooks/{hookId}`,...t,...n})}update(e,t){let n=a([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:_e,security:[{scheme:`bearer`,type:`http`}],url:`/hooks/{hookId}`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}},Te=class e extends X{static __registry=new ve;constructor(t){super(t),e.__registry.set(this,t?.key)}_chats;get chats(){return this._chats??=new ye({client:this.client})}_messages;get messages(){return this._messages??=new be({client:this.client})}_mcpServers;get mcpServers(){return this._mcpServers??=new xe({client:this.client})}_settings;get settings(){return this._settings??=new Se({client:this.client})}_usage;get usage(){return this._usage??=new Ce({client:this.client})}_webhooks;get webhooks(){return this._webhooks??=new we({client:this.client})}};const Ee=e.create({});function De(e,t){if(!t)return e;try{let n=Ee.clone(e);return Oe(t)?ke(n,t):Ee.patch(n,t)}catch{return e}}function Oe(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 ke(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(!Ae(a))return e;let n=a[t];if(typeof n==`string`)return a[t]=`${n}${r}`,e;a=n}return e}function Ae(e){return typeof e==`object`&&!!e}var Z=class extends Error{code;id;constructor(e,t={}){super(e),this.name=`V0StreamError`,this.code=t.code,this.id=t.id}};function je(e){return new Ne(async(t,n)=>{let r;for await(let n of e)r=Pe(r,n),t(r);if(!r)throw new Z(`v0 stream ended before sending an event`);n(ze(r))})}function Me(e){return new Ne(async(t,n)=>{let r;for await(let i of He(await e)){if(i.event===`update`){r=i.data,t(i.data);continue}if(i.event===`done`){n(i.data);return}throw new Z(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 Z(`v0 stream ended before sending an event`);n(ze(r))})}var Ne=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(Q(`update`,r)));e.enqueue(t.encode(Q(`done`,await n.final)))}catch(n){e.enqueue(t.encode(Q(`error`,Ve(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 Pe(e,t){let n=e??Fe(t);switch(t.object){case`chat`:return{...n,event:t,chat:Be(t)};case`chat.title`:return Ie({...n,event:t},t.delta);case`message`:{let e=Be(t);return{...n,event:t,message:e,parts:e.parts,usage:e.usage}}case`message.parts.chunk`:return Le({...n,event:t},t.delta);case`message.usage`:return Re({...n,event:t},t.usage);case`error`:throw new Z(t.message,{code:t.code,id:t.id});default:{let e=t;throw new Z(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 Fe(e){return{status:`streaming`,event:e,parts:[]}}function Ie(e,t){return{...e,title:t,chat:e.chat?{...e.chat,title:t}:e.chat}}function Le(e,t){let n=De(e.parts,t);return{...e,parts:n,message:e.message?{...e.message,parts:n}:e.message}}function Re(e,t){return{...e,usage:t,message:e.message?{...e.message,usage:t}:e.message}}function ze(e){return{...e,status:`done`}}function Be(e){let{object:t,...n}=e;return n}function Q(e,t){return`event: ${e}\ndata: ${JSON.stringify(t)}\n\n`}function Ve(e){return e instanceof Z?{message:e.message,code:e.code,id:e.id}:e instanceof Error?{message:e.message}:{message:`v0 stream failed`}}async function*He(e){if(!e.ok)throw new Z(`v0 stream request failed: ${e.status} ${e.statusText}`);if(!e.body)throw new Z(`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=Ue(e);t&&(yield t)}}let e=n.trim();if(e){let t=Ue(e);t&&(yield t)}}finally{t.releaseLock()}}function Ue(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`)&&$(r)?{event:`update`,data:r}:t===`done`&&$(r)?{event:`done`,data:r}:t===`error`&&$(r)?{event:`error`,data:r}:null}function $(e){return typeof e==`object`&&!!e}export{J as A,U as C,F as D,j as E,C as F,S as I,x as L,he as M,ge as N,N as O,_e as P,y as R,K as S,P as T,w as _,xe as a,R as b,we as c,A as d,O as f,L as g,z as h,ye as i,fe as j,me as k,D as l,H as m,je as n,be as o,E as p,Me as r,Te as s,Z as t,k as u,V as v,q as w,G as x,B as y};
14
- //# sourceMappingURL=stream-CcmYkYPS.mjs.map