v0 4.0.2 → 4.0.3
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/dist/{payload-DE_BtQ6L.d.mts → browser-DGWbNcMR.d.cts} +481 -14
- package/dist/browser-DGWbNcMR.d.cts.map +1 -0
- package/dist/{payload-CS8GcAur.d.cts → browser-zcyUzNr5.d.mts} +481 -14
- package/dist/browser-zcyUzNr5.d.mts.map +1 -0
- package/dist/browser.cjs +1 -1
- package/dist/browser.d.cts +2 -42
- package/dist/browser.d.mts +2 -42
- package/dist/browser.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/stream-DbU4e_Uw.cjs +13 -0
- package/dist/{stream-O9jhVMON.mjs → stream-EhZyuNGL.mjs} +2 -2
- package/dist/stream-EhZyuNGL.mjs.map +1 -0
- package/package.json +1 -1
- package/dist/browser.d.cts.map +0 -1
- package/dist/browser.d.mts.map +0 -1
- package/dist/payload-CS8GcAur.d.cts.map +0 -1
- package/dist/payload-DE_BtQ6L.d.mts.map +0 -1
- package/dist/stream-O9jhVMON.mjs.map +0 -1
- package/dist/stream-YWr_UoFI.cjs +0 -13
package/dist/stream-YWr_UoFI.cjs
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
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);const l={bodySerializer:e=>JSON.stringify(e,(e,t)=>typeof t==`bigint`?t.toString():t)},u=Object.entries({$body_:`body`,$headers_:`headers`,$path_:`path`,$query_:`query`}),d=(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&&d(n.args,t);return t},f=e=>{for(let[t,n]of Object.entries(e))n&&typeof n==`object`&&!Array.isArray(n)&&!Object.keys(n).length&&delete e[t]},p=(e,t)=>{let n={body:{},headers:{},path:{},query:{}},r=d(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=u.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 f(n),n},m=({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))}}}()}},h=e=>{switch(e){case`label`:return`.`;case`matrix`:return`;`;case`simple`:return`,`;default:return`&`}},ee=e=>{switch(e){case`form`:return`,`;case`pipeDelimited`:return`|`;case`spaceDelimited`:return`%20`;default:return`,`}},te=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(ee(r));switch(r){case`label`:return`.${t}`;case`matrix`:return`;${n}=${t}`;case`simple`:return t;default:return`${n}=${t}`}}let a=h(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=te(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},ne=/\{[^{}]+\}/g,re=({path:e,url:t})=>{let n=t,r=t.match(ne);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 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 ae=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=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(`&`)},oe=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`}},se=(e,t)=>t?!!(e.headers.has(t)||e.query?.[t]||e.headers.get(`Cookie`)?.includes(`${t}=`)):!1,ce=async({security:e,...t})=>{for(let n of e){if(se(t,n.name))continue;let e=await ae(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}}},le=e=>ie({baseUrl:e.baseUrl,path:e.path,query:e.query,querySerializer:typeof e.querySerializer==`function`?e.querySerializer:b(e.querySerializer),url:e.url}),ue=(e,t)=>{let n={...e,...t};return n.baseUrl?.endsWith(`/`)&&(n.baseUrl=n.baseUrl.substring(0,n.baseUrl.length-1)),n.headers=x(e.headers,t.headers),n},de=e=>{let t=[];return e.forEach((e,n)=>{t.push([n,e])}),t},x=(...e)=>{let t=new Headers;for(let n of e){if(!n)continue;let e=n instanceof Headers?de(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 S=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 fe=()=>({error:new S,request:new S,response:new S}),pe=b({allowReserved:!1,array:{explode:!0,style:`form`},object:{explode:!0,style:`deepObject`}}),me={"Content-Type":`application/json`},C=(e={})=>({...l,headers:me,parseAs:`auto`,querySerializer:pe,...e}),w=(e={})=>{let t=ue(C(),e),n=()=>({...t}),r=e=>(t=ue(t,e),n()),i=fe(),a=async e=>{let n={...t,...e,fetch:e.fetch??t.fetch??globalThis.fetch,headers:x(t.headers,e.headers),serializedBody:void 0};return n.security&&await ce({...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:le(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`?oe(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 m({...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=>le({...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`)}},T=w(C({baseUrl:`https://api.v0.dev/v2`})),E=c.create({});function he(e,t){if(!t)return e;try{let n=E.clone(e);return ge(t)?_e(n,t):E.patch(n,t)}catch{return e}}function ge(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 _e(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(!ve(a))return e;let n=a[t];if(typeof n==`string`)return a[t]=`${n}${r}`,e;a=n}return e}function ve(e){return typeof e==`object`&&!!e}var D=class extends Error{code;id;constructor(e,t={}){super(e),this.name=`V0StreamError`,this.code=t.code,this.id=t.id}};function ye(e){return new O(async(t,n)=>{let r;for await(let n of e)r=xe(r,n),t(r);if(!r)throw new D(`v0 stream ended before sending an event`);n(k(r))})}function be(e){return new O(async(t,n)=>{let r;for await(let i of De(await e)){if(i.event===`update`){r=i.data,t(i.data);continue}if(i.event===`done`){n(i.data);return}throw new D(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 D(`v0 stream ended before sending an event`);n(k(r))})}var O=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`,Ee(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 xe(e,t){let n=e??Se(t);switch(t.object){case`chat`:return{...n,event:t,chat:A(t)};case`chat.title`:return Ce({...n,event:t},t.delta);case`message`:{let e=A(t);return{...n,event:t,message:e,parts:e.parts,usage:e.usage}}case`message.parts.chunk`:return we({...n,event:t},t.delta);case`message.usage`:return Te({...n,event:t},t.usage);case`error`:throw new D(t.message,{code:t.code,id:t.id});default:{let e=t;throw new D(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 Se(e){return{status:`streaming`,event:e,parts:[]}}function Ce(e,t){return{...e,title:t,chat:e.chat?{...e.chat,title:t}:e.chat}}function we(e,t){let n=he(e.parts,t);return{...e,parts:n,message:e.message?{...e.message,parts:n}:e.message}}function Te(e,t){return{...e,usage:t,message:e.message?{...e.message,usage:t}:e.message}}function k(e){return{...e,status:`done`}}function A(e){let{object:t,...n}=e;return n}function j(e,t){return`event: ${e}\ndata: ${JSON.stringify(t)}\n\n`}function Ee(e){return e instanceof D?{message:e.message,code:e.code,id:e.id}:e instanceof Error?{message:e.message}:{message:`v0 stream failed`}}async function*De(e){if(!e.ok)throw new D(`v0 stream request failed: ${e.status} ${e.statusText}`);if(!e.body)throw new D(`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=M(e);t&&(yield t)}}let e=n.trim();if(e){let t=M(e);t&&(yield t)}}finally{t.releaseLock()}}function M(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`)&&N(r)?{event:`update`,data:r}:t===`done`&&N(r)?{event:`done`,data:r}:t===`error`&&N(r)?{event:`error`,data:r}:null}function N(e){return typeof e==`object`&&!!e}const P=async e=>(e.chats=e.chats.map(e=>(e.createdAt=new Date(e.createdAt),e.updatedAt&&=new Date(e.updatedAt),e)),e),F=e=>(e.chat.createdAt=new Date(e.chat.createdAt),e.chat.updatedAt&&(e.chat.updatedAt=new Date(e.chat.updatedAt)),e),I=async e=>(e=F(e),e),L=async e=>(e=F(e),e),R=async e=>(e=F(e),e),z=async e=>(e=F(e),e),B=async e=>(e=F(e),e),V=async e=>(e=F(e),e),Oe=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=Oe(e),e),U=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),W=async e=>(e=U(e),e),G=async e=>(e=U(e),e),K=async e=>(e=U(e),e),ke=async e=>(e.createdAt=new Date(e.createdAt),e),q=e=>(e.createdAt=new Date(e.createdAt),e.updatedAt&&=new Date(e.updatedAt),e),Ae=async e=>(e=q(e),e),je=async e=>(e=q(e),e),Me=async e=>(e&&(e.expiresAt=new Date(e.expiresAt)),e),Ne=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),Pe=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),Fe=async e=>(e=q(e),e),Ie=async e=>(e=e.map(e=>(e.createdAt=new Date(e.createdAt),e.updatedAt=new Date(e.updatedAt),e)),e),J=e=>(e.createdAt=new Date(e.createdAt),e.updatedAt=new Date(e.updatedAt),e),Le=async e=>(e=J(e),e),Re=async e=>(e=J(e),e),ze=async e=>(e=J(e),e),Be=e=>(e.range.start=new Date(e.range.start),e.range.end=new Date(e.range.end),e.dataAsOf&&=new Date(e.dataAsOf),e),Ve=async e=>(e=Be(e),e),He=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),Ue=async e=>(e=He(e),e),We=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),Ge=async e=>(e=We(e),e),Y=e=>(e.createdAt=new Date(e.createdAt),e),Ke=async e=>(e=Y(e),e),qe=async e=>(e=Y(e),e),Je=async e=>(e=Y(e),e);var X=class{client;constructor(e){this.client=e?.client??T}},Ye=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)}},Xe=class extends X{list(e,t){let n=p([e],[{args:[{in:`query`,key:`limit`},{in:`query`,key:`cursor`},{in:`query`,key:`orderBy`},{in:`query`,key:`orderDirection`},{in:`query`,key:`authorId`},{in:`query`,key:`vercelProjectId`},{in:`query`,key:`metadata`}]}]);return(t?.client??this.client).get({responseTransformer:P,security:[{scheme:`bearer`,type:`http`}],url:`/chats`,...t,...n})}create(e,t){let n=p([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:I,security:[{scheme:`bearer`,type:`http`}],url:`/chats`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}createFromFiles(e,t){let n=p([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:L,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=p([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:R,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=p([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:z,security:[{scheme:`bearer`,type:`http`}],url:`/chats/from-repo`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}createFromTemplate(e,t){let n=p([e],[{args:[{in:`body`,key:`templateId`},{in:`body`,key:`privacy`},{in:`body`,key:`title`},{in:`body`,key:`metadata`}]}]);return(t?.client??this.client).post({responseTransformer:B,security:[{scheme:`bearer`,type:`http`}],url:`/chats/from-template`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}createFromVercelProject(e,t){let n=p([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:V,security:[{scheme:`bearer`,type:`http`}],url:`/chats/from-vercel-project`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}createFromVercelProjectWithMessageAsync(e,t){let n=p([e],[{args:[{in:`body`,key:`vercelProjectId`},{in:`body`,key:`baseBranch`},{in:`body`,key:`privacy`},{in:`body`,key:`title`},{in:`body`,key:`metadata`},{in:`body`,key:`message`},{in:`body`,key:`modelConfiguration`}]}]);return(t?.client??this.client).post({security:[{scheme:`bearer`,type:`http`}],url:`/chats/from-vercel-project/async`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}createStream(e,t){let n=p([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=p([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}})}downloadArtifact(e,t){let n=p([e],[{args:[{in:`path`,key:`chatId`},{in:`path`,key:`artifactId`}]}]);return(t?.client??this.client).get({security:[{scheme:`bearer`,type:`http`}],url:`/chats/{chatId}/artifacts/{artifactId}`,...t,...n})}syncTemplate(e,t){let n=p([e],[{args:[{in:`path`,key:`chatId`},{in:`body`,key:`expectedGitSha`}]}]);return(t?.client??this.client).post({security:[{scheme:`bearer`,type:`http`}],url:`/chats/{chatId}/template/sync`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}delete(e,t){let n=p([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=p([e],[{args:[{in:`path`,key:`chatId`}]}]);return(t?.client??this.client).get({responseTransformer:Ae,security:[{scheme:`bearer`,type:`http`}],url:`/chats/{chatId}`,...t,...n})}update(e,t){let n=p([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:je,security:[{scheme:`bearer`,type:`http`}],url:`/chats/{chatId}`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}getPreview(e,t){let n=p([e],[{args:[{in:`path`,key:`chatId`}]}]);return(t?.client??this.client).get({responseTransformer:Me,security:[{scheme:`bearer`,type:`http`}],url:`/chats/{chatId}/preview`,...t,...n})}getFiles(e,t){let n=p([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=p([e],[{args:[{in:`path`,key:`chatId`},{in:`body`,key:`files`}]}]);return(t?.client??this.client).patch({responseTransformer:Ne,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=p([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=p([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=p([e],[{args:[{in:`path`,key:`chatId`},{in:`body`,key:`messageId`}]}]);return(t?.client??this.client).post({responseTransformer:Pe,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=p([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:Fe,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=p([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=p([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=p([e],[{args:[{in:`path`,key:`chatId`}]}]);return(t?.client??this.client).sse.post({security:[{scheme:`bearer`,type:`http`}],url:`/chats/{chatId}/resume`,...t,...n})}},Ze=class extends X{list(e,t){let n=p([e],[{args:[{in:`path`,key:`chatId`},{in:`query`,key:`limit`},{in:`query`,key:`cursor`}]}]);return(t?.client??this.client).get({responseTransformer:H,security:[{scheme:`bearer`,type:`http`}],url:`/chats/{chatId}/messages`,...t,...n})}send(e,t){let n=p([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:W,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=p([e],[{args:[{in:`path`,key:`chatId`},{in:`path`,key:`messageId`}]}]);return(t?.client??this.client).get({responseTransformer:G,security:[{scheme:`bearer`,type:`http`}],url:`/chats/{chatId}/messages/{messageId}`,...t,...n})}sendStream(e,t){let n=p([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=p([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=p([e],[{args:[{in:`path`,key:`chatId`},{in:`body`,key:`task`},{in:`body`,key:`modelConfiguration`}]}]);return(t?.client??this.client).post({responseTransformer:K,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=p([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=p([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=p([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})}},Qe=class extends X{get(e,t){let n=p([e],[{args:[{in:`path`,key:`chatId`},{in:`path`,key:`checkId`}]}]);return(t?.client??this.client).get({responseTransformer:ke,security:[{scheme:`bearer`,type:`http`}],url:`/chats/{chatId}/security-checks/{checkId}`,...t,...n})}create(e,t){let n=p([e],[{args:[{in:`body`,key:`scope`},{in:`body`,key:`chatId`},{in:`body`,key:`repo`},{in:`body`,key:`vercelProjectId`},{in:`body`,key:`baseBranch`}]}]);return(t?.client??this.client).post({security:[{scheme:`bearer`,type:`http`}],url:`/security-checks/`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}},$e=class extends X{list(e){return(e?.client??this.client).get({responseTransformer:Ie,security:[{scheme:`bearer`,type:`http`}],url:`/mcp-servers`,...e})}create(e,t){let n=p([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:Le,security:[{scheme:`bearer`,type:`http`}],url:`/mcp-servers`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}delete(e,t){let n=p([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=p([e],[{args:[{in:`path`,key:`mcpServerId`}]}]);return(t?.client??this.client).get({responseTransformer:Re,security:[{scheme:`bearer`,type:`http`}],url:`/mcp-servers/{mcpServerId}`,...t,...n})}update(e,t){let n=p([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:ze,security:[{scheme:`bearer`,type:`http`}],url:`/mcp-servers/{mcpServerId}`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}},et=class extends X{list(e,t){let n=p([e],[{args:[{in:`query`,key:`cursor`},{in:`query`,key:`limit`}]}]);return(t?.client??this.client).get({security:[{scheme:`bearer`,type:`http`}],url:`/pool-credit-limits/members`,...t,...n})}update(e,t){let n=p([e],[{args:[{in:`body`,key:`updates`}]}]);return(t?.client??this.client).patch({security:[{scheme:`bearer`,type:`http`}],url:`/pool-credit-limits/members`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}reset(e,t){let n=p([e],[{args:[{in:`path`,key:`userId`}]}]);return(t?.client??this.client).delete({security:[{scheme:`bearer`,type:`http`}],url:`/pool-credit-limits/members/{userId}`,...t,...n})}get(e,t){let n=p([e],[{args:[{in:`path`,key:`userId`}]}]);return(t?.client??this.client).get({security:[{scheme:`bearer`,type:`http`}],url:`/pool-credit-limits/members/{userId}`,...t,...n})}set(e,t){let n=p([e],[{args:[{in:`path`,key:`userId`},{in:`body`,key:`setting`}]}]);return(t?.client??this.client).put({security:[{scheme:`bearer`,type:`http`}],url:`/pool-credit-limits/members/{userId}`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}},tt=class extends X{getDefault(e){return(e?.client??this.client).get({security:[{scheme:`bearer`,type:`http`}],url:`/pool-credit-limits/default`,...e})}setDefault(e,t){let n=p([e],[{args:[{in:`body`,key:`setting`}]}]);return(t?.client??this.client).put({security:[{scheme:`bearer`,type:`http`}],url:`/pool-credit-limits/default`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}_members;get members(){return this._members??=new et({client:this.client})}},nt=class extends X{deletePreviewHosts(e,t){let n=p([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=p([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=p([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}})}},rt=class extends X{getSummary(e,t){let n=p([e],[{args:[{in:`query`,key:`start`},{in:`query`,key:`end`},{in:`query`,key:`userId`}]}]);return(t?.client??this.client).get({responseTransformer:Ve,security:[{scheme:`bearer`,type:`http`}],url:`/usage/summary`,...t,...n})}listEvents(e,t){let n=p([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:Ue,security:[{scheme:`bearer`,type:`http`}],url:`/usage/events`,...t,...n})}getActivity(e,t){let n=p([e],[{args:[{in:`query`,key:`start`},{in:`query`,key:`end`},{in:`query`,key:`userId`}]}]);return(t?.client??this.client).get({responseTransformer:Ge,security:[{scheme:`bearer`,type:`http`}],url:`/usage/activity`,...t,...n})}},it=class extends X{list(e){return(e?.client??this.client).get({security:[{scheme:`bearer`,type:`http`}],url:`/hooks`,...e})}create(e,t){let n=p([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:`/hooks`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}delete(e,t){let n=p([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=p([e],[{args:[{in:`path`,key:`hookId`}]}]);return(t?.client??this.client).get({responseTransformer:qe,security:[{scheme:`bearer`,type:`http`}],url:`/hooks/{hookId}`,...t,...n})}update(e,t){let n=p([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:`/hooks/{hookId}`,...t,...n,headers:{"Content-Type":`application/json`,...t?.headers,...n.headers}})}},at=class e extends X{static __registry=new Ye;constructor(t){super(t),e.__registry.set(this,t?.key)}_chats;get chats(){return this._chats??=new Xe({client:this.client})}_messages;get messages(){return this._messages??=new Ze({client:this.client})}_securityChecks;get securityChecks(){return this._securityChecks??=new Qe({client:this.client})}_mcpServers;get mcpServers(){return this._mcpServers??=new $e({client:this.client})}_poolCreditLimits;get poolCreditLimits(){return this._poolCreditLimits??=new tt({client:this.client})}_settings;get settings(){return this._settings??=new nt({client:this.client})}_usage;get usage(){return this._usage??=new rt({client:this.client})}_webhooks;get webhooks(){return this._webhooks??=new it({client:this.client})}},ot=class extends Xe{downloadArtifact(e,t){return super.downloadArtifact(e,{parseAs:`blob`,...t})}},st=class extends at{_blobChats;get chats(){return this._blobChats??=new ot({client:this.client})}};function Z(e,t){if(!e||typeof e!=`object`||Array.isArray(e))throw TypeError(`${t} must be an object`);return e}function Q(e,t,n=!1){if(typeof e!=`string`)throw TypeError(`${t} must be a string`);if(!n&&!e.trim())throw TypeError(`${t} must not be empty`);return e}function ct(e){let t=Z(e,`element`),n={selectorPath:Q(t.selectorPath,`element.selectorPath`),tagName:Q(t.tagName,`element.tagName`)};for(let e of[`id`,`textContent`,`reactComponentName`])t[e]!==void 0&&(n[e]=Q(t[e],`element.${e}`,!0));if(t.classNames!==void 0){if(!Array.isArray(t.classNames))throw TypeError(`element.classNames must be an array`);n.classNames=t.classNames.map(e=>Q(e,`element.classNames[]`,!0))}return n}function lt(e){let t=Z(e,`edit`);if(t.type===`fontInjection`)return{type:`fontInjection`,fontName:Q(t.fontName,`fontName`)};let n=ct(t.element);if(t.type===`deleteElement`)return{type:`deleteElement`,element:n};if(t.type===`style`){let e=Z(t.changes,`changes`),r=Object.entries(e);if(!r.length)throw TypeError(`A style edit requires at least one change`);return{type:`style`,element:n,changes:Object.fromEntries(r.map(([e,t])=>{Q(e,`CSS property`);let n=Z(t,`changes.${e}`);return[e,{from:Q(n.from,`changes.${e}.from`,!0),to:Q(n.to,`changes.${e}.to`,!0)}]}))}}if(t.type===`move`){let e=t.position;if(e!==`inside`&&e!==`before`&&e!==`after`)throw TypeError(`Move position must be inside, before, or after`);let r={type:`move`,element:n,position:e};if(t.toParentSelector!==void 0&&(r.toParentSelector=Q(t.toParentSelector,`toParentSelector`)),t.targetSelector!==void 0&&(r.targetSelector=Q(t.targetSelector,`targetSelector`)),e===`inside`&&!r.toParentSelector)throw TypeError(`An inside move requires toParentSelector`);if(e!==`inside`&&!r.targetSelector)throw TypeError(`A before or after move requires targetSelector`);return r}throw TypeError(`Unknown Design Mode edit type`)}function $(e){let t=Q(e,`screenshot base64`);if(t.length%4!=0||!/^[A-Za-z0-9+/]+={0,2}$/.test(t))throw TypeError(`Screenshot must contain base64 image data without a data URI prefix`);let n=0;if(t.endsWith(`==`)?n=2:t.endsWith(`=`)&&(n=1),t.length*3/4-n>10*1024*1024)throw TypeError(`Screenshot exceeds the 10 MB attachment limit`);return`data:image/jpeg;base64,${t}`}function ut(e){if(!e.message&&!e.designMode.edits?.length)throw TypeError(`Provide instructions or at least one Design Mode edit`);if(!e.designMode.edits?.length&&!e.designMode.element&&!e.designMode.screenshot)throw TypeError(`Instructions without edits require an element or screenshot`)}function dt(e){let t=Z(e,`Design Mode message`),n=Z(t.designMode,`designMode`),r=n.edits;if(r===void 0&&(r=[]),!Array.isArray(r)||r.length>100)throw TypeError(`edits must be an array containing at most 100 edits`);let i={designMode:{edits:r.map(lt)}};if(t.message!==void 0&&(i.message=Q(t.message,`message`)),n.element!==void 0&&(i.designMode.element=Q(n.element,`designMode.element`)),n.screenshot!==void 0){let e=Z(n.screenshot,`designMode.screenshot`),t=Q(e.url,`screenshot.url`);if(t.startsWith(`data:`)){let e=/^data:image\/(jpeg|jpg|png|webp|gif);base64,(.+)$/.exec(t);if(!e)throw TypeError(`Screenshot must be a supported base64 image data URI`);$(e[2])}else{let e=new URL(t);if(e.protocol!==`https:`||e.username||e.password)throw TypeError(`Screenshot URL must use HTTPS without credentials`)}i.designMode.screenshot={url:t},e.anchorElement!==void 0&&(i.designMode.screenshot.anchorElement=Q(e.anchorElement,`screenshot.anchorElement`))}return ut(i),i}function ft(e){let t=Z(e,`Design Mode payload`),n=t.edits;if(n===void 0&&(n=[]),!Array.isArray(n)||n.length>100)throw TypeError(`edits must be an array containing at most 100 edits`);let r={designMode:{edits:n.map(lt)}};if(t.instructions!==void 0){let e=Z(t.instructions,`instructions`);if(e.message!==void 0){let t=Q(e.message,`instructions.message`,!0);t.trim()&&(r.message=t)}if(e.element!==void 0&&(r.designMode.element=Q(e.element,`instructions.element`)),e.screenshot!==void 0){let t=Z(e.screenshot,`instructions.screenshot`);if(r.designMode.screenshot={url:$(t.base64)},t.anchorElement!==void 0){let e=Q(t.anchorElement,`screenshot.anchorElement`,!0);e.trim()&&(r.designMode.screenshot.anchorElement=e)}}else e.elementScreenshot!==void 0&&(r.designMode.screenshot={url:$(e.elementScreenshot)})}return ut(r),r}Object.defineProperty(exports,`A`,{enumerable:!0,get:function(){return W}}),Object.defineProperty(exports,`B`,{enumerable:!0,get:function(){return be}}),Object.defineProperty(exports,`C`,{enumerable:!0,get:function(){return Le}}),Object.defineProperty(exports,`D`,{enumerable:!0,get:function(){return G}}),Object.defineProperty(exports,`E`,{enumerable:!0,get:function(){return ze}}),Object.defineProperty(exports,`F`,{enumerable:!0,get:function(){return Ke}}),Object.defineProperty(exports,`G`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`H`,{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,`I`,{enumerable:!0,get:function(){return qe}}),Object.defineProperty(exports,`L`,{enumerable:!0,get:function(){return Je}}),Object.defineProperty(exports,`M`,{enumerable:!0,get:function(){return Ge}}),Object.defineProperty(exports,`N`,{enumerable:!0,get:function(){return Ve}}),Object.defineProperty(exports,`O`,{enumerable:!0,get:function(){return H}}),Object.defineProperty(exports,`P`,{enumerable:!0,get:function(){return Ue}}),Object.defineProperty(exports,`R`,{enumerable:!0,get:function(){return D}}),Object.defineProperty(exports,`S`,{enumerable:!0,get:function(){return je}}),Object.defineProperty(exports,`T`,{enumerable:!0,get:function(){return Ie}}),Object.defineProperty(exports,`U`,{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,`V`,{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,`W`,{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,`_`,{enumerable:!0,get:function(){return Me}}),Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return ot}}),Object.defineProperty(exports,`b`,{enumerable:!0,get:function(){return Pe}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return Ze}}),Object.defineProperty(exports,`d`,{enumerable:!0,get:function(){return z}}),Object.defineProperty(exports,`f`,{enumerable:!0,get:function(){return B}}),Object.defineProperty(exports,`g`,{enumerable:!0,get:function(){return Fe}}),Object.defineProperty(exports,`h`,{enumerable:!0,get:function(){return I}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return ft}}),Object.defineProperty(exports,`j`,{enumerable:!0,get:function(){return ke}}),Object.defineProperty(exports,`k`,{enumerable:!0,get:function(){return K}}),Object.defineProperty(exports,`l`,{enumerable:!0,get:function(){return it}}),Object.defineProperty(exports,`m`,{enumerable:!0,get:function(){return R}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return Z}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return st}}),Object.defineProperty(exports,`p`,{enumerable:!0,get:function(){return V}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return Q}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return $e}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return dt}}),Object.defineProperty(exports,`u`,{enumerable:!0,get:function(){return L}}),Object.defineProperty(exports,`v`,{enumerable:!0,get:function(){return Ae}}),Object.defineProperty(exports,`w`,{enumerable:!0,get:function(){return Re}}),Object.defineProperty(exports,`x`,{enumerable:!0,get:function(){return Ne}}),Object.defineProperty(exports,`y`,{enumerable:!0,get:function(){return P}}),Object.defineProperty(exports,`z`,{enumerable:!0,get:function(){return ye}});
|