1import{i as e,l as t,r as n,u as r}from"./session-HFeFroCn.js";import{s as i}from"./analytics-DTxWGg6e.js";var a=/\{[^{}]+\}/g,o=()=>typeof process==`object`&&Number.parseInt(process?.versions?.node?.substring(0,2))>=18&&process.versions.undici;function s(){return Math.random().toString(36).slice(2,11)}function c(e){let{baseUrl:t=``,Request:n=globalThis.Request,fetch:r=globalThis.fetch,querySerializer:i,bodySerializer:a,pathSerializer:c,headers:l,requestInitExt:u=void 0,...d}={...e};u=o()?u:void 0,t=_(t);let v=[];async function y(e,o){let{baseUrl:y,fetch:b=r,Request:x=n,headers:S,params:C={},parseAs:w=`json`,querySerializer:T,bodySerializer:E=a??m,pathSerializer:D,body:O,middleware:k=[],...A}=o||{},j=t;y&&(j=_(y)??t);let M=typeof i==`function`?i:f(i);T&&(M=typeof T==`function`?T:f({...typeof i==`object`?i:{},...T}));let N=D||c||p,P=O===void 0?void 0:E(O,g(l,S,C.header)),F=g(P===void 0||P instanceof FormData?{}:{"Content-Type":`application/json`},l,S,C.header),I=[...v,...k],L={redirect:`follow`,...d,...A,body:P,headers:F},R,z,B=new x(h(e,{baseUrl:j,params:C,querySerializer:M,pathSerializer:N}),L),V;for(let e in A)e in B||(B[e]=A[e]);if(I.length){R=s(),z=Object.freeze({baseUrl:j,fetch:b,parseAs:w,querySerializer:M,bodySerializer:E,pathSerializer:N});for(let t of I)if(t&&typeof t==`object`&&typeof t.onRequest==`function`){let n=await t.onRequest({request:B,schemaPath:e,params:C,options:z,id:R});if(n)if(n instanceof x)B=n;else if(n instanceof Response){V=n;break}else throw Error(`onRequest: must return new Request() or Response() when modifying the request`)}}if(!V){try{V=await b(B,u)}catch(t){let n=t;if(I.length)for(let t=I.length-1;t>=0;t--){let r=I[t];if(r&&typeof r==`object`&&typeof r.onError==`function`){let t=await r.onError({request:B,error:n,schemaPath:e,params:C,options:z,id:R});if(t){if(t instanceof Response){n=void 0,V=t;break}if(t instanceof Error){n=t;continue}throw Error(`onError: must return new Response() or instance of Error`)}}}if(n)throw n}if(I.length)for(let t=I.length-1;t>=0;t--){let n=I[t];if(n&&typeof n==`object`&&typeof n.onResponse==`function`){let t=await n.onResponse({request:B,response:V,schemaPath:e,params:C,options:z,id:R});if(t){if(!(t instanceof Response))throw Error(`onResponse: must return new Response() when modifying the response`);V=t}}}}let H=V.headers.get(`Content-Length`);if(V.status===204||B.method===`HEAD`||H===`0`&&!V.headers.get(`Transfer-Encoding`)?.includes(`chunked`))return V.ok?{data:void 0,response:V}:{error:void 0,response:V};if(V.ok)return{data:await(async()=>{if(w===`stream`)return V.body;if(w===`json`&&!H){let e=await V.text();return e?JSON.parse(e):void 0}return await V[w]()})(),response:V};let U=await V.text();try{U=JSON.parse(U)}catch{}return{error:U,response:V}}return{request(e,t,n){return y(t,{...n,method:e.toUpperCase()})},GET(e,t){return y(e,{...t,method:`GET`})},PUT(e,t){return y(e,{...t,method:`PUT`})},POST(e,t){return y(e,{...t,method:`POST`})},DELETE(e,t){return y(e,{...t,method:`DELETE`})},OPTIONS(e,t){return y(e,{...t,method:`OPTIONS`})},HEAD(e,t){return y(e,{...t,method:`HEAD`})},PATCH(e,t){return y(e,{...t,method:`PATCH`})},TRACE(e,t){return y(e,{...t,method:`TRACE`})},use(...e){for(let t of e)if(t){if(typeof t!=`object`||!(`onRequest`in t||`onResponse`in t||`onError`in t))throw Error("Middleware must be an object with one of `onRequest()`, `onResponse() or `onError()`");v.push(t)}},eject(...e){for(let t of e){let e=v.indexOf(t);e!==-1&&v.splice(e,1)}}}}function l(e,t,n){if(t==null)return``;if(typeof t==`object`)throw Error("Deeply-nested arrays/objects arenât supported. Provide your own `querySerializer()` to handle these.");return`${e}=${n?.allowReserved===!0?t:encodeURIComponent(t)}`}function u(e,t,n){if(!t||typeof t!=`object`)return``;let r=[],i={simple:`,`,label:`.`,matrix:`;`}[n.style]||`&`;if(n.style!==`deepObject`&&n.explode===!1){for(let e in t)r.push(e,n.allowReserved===!0?t[e]:encodeURIComponent(t[e]));let i=r.join(`,`);switch(n.style){case`form`:return`${e}=${i}`;case`label`:return`.${i}`;case`matrix`:return`;${e}=${i}`;default:return i}}for(let i in t){let a=n.style===`deepObject`?`${e}[${i}]`:i;r.push(l(a,t[i],n))}let a=r.join(i);return n.style===`label`||n.style===`matrix`?`${i}${a}`:a}function d(e,t,n){if(!Array.isArray(t))return``;if(n.explode===!1){let r={form:`,`,spaceDelimited:`%20`,pipeDelimited:`|`}[n.style]||`,`,i=(n.allowReserved===!0?t:t.map(e=>encodeURIComponent(e))).join(r);switch(n.style){case`simple`:return i;case`label`:return`.${i}`;case`matrix`:return`;${e}=${i}`;default:return`${e}=${i}`}}let r={simple:`,`,label:`.`,matrix:`;`}[n.style]||`&`,i=[];for(let r of t)n.style===`simple`||n.style===`label`?i.push(n.allowReserved===!0?r:encodeURIComponent(r)):i.push(l(e,r,n));return n.style===`label`||n.style===`matrix`?`${r}${i.join(r)}`:i.join(r)}function f(e){return function(t){let n=[];if(t&&typeof t==`object`)for(let r in t){let i=t[r];
1if(i!=null){if(Array.isArray(i)){if(i.length===0)continue;n.push(d(r,i,{style:`form`,explode:!0,...e?.array,allowReserved:e?.allowReserved||!1}));continue}if(typeof i==`object`){n.push(u(r,i,{style:`deepObject`,explode:!0,...e?.object,allowReserved:e?.allowReserved||!1}));continue}n.push(l(r,i,e))}}return n.join(`&`)}}function p(e,t){let n=e;for(let r of e.match(a)??[]){let e=r.substring(1,r.length-1),i=!1,a=`simple`;if(e.endsWith(`*`)&&(i=!0,e=e.substring(0,e.length-1)),e.startsWith(`.`)?(a=`label`,e=e.substring(1)):e.startsWith(`;`)&&(a=`matrix`,e=e.substring(1)),!t||t[e]===void 0||t[e]===null)continue;let o=t[e];if(Array.isArray(o)){n=n.replace(r,d(e,o,{style:a,explode:i}));continue}if(typeof o==`object`){n=n.replace(r,u(e,o,{style:a,explode:i}));continue}if(a===`matrix`){n=n.replace(r,`;${l(e,o)}`);continue}n=n.replace(r,a===`label`?`.${encodeURIComponent(o)}`:encodeURIComponent(o))}return n}function m(e,t){return e instanceof FormData?e:t&&(t.get instanceof Function?t.get(`Content-Type`)??t.get(`content-type`):t[`Content-Type`]??t[`content-type`])===`application/x-www-form-urlencoded`?new URLSearchParams(e).toString():JSON.stringify(e)}function h(e,t){let n=`${t.baseUrl}${e}`;t.params?.path&&(n=t.pathSerializer(n,t.params.path));let r=t.querySerializer(t.params.query??{});return r.startsWith(`?`)&&(r=r.substring(1)),r&&(n+=`?${r}`),n}function g(...e){let t=new Headers;for(let n of e){if(!n||typeof n!=`object`)continue;let e=n instanceof Headers?n.entries():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,r)}return t}function _(e){return e.endsWith(`/`)?e.substring(0,e.length-1):e}var v=`sprag.activeWorkspace.`,y=new Map,b=new Set;function x(){return typeof localStorage>`u`?null:localStorage}function S(e){if(!e)return null;let t=y.get(e);if(t)return t;let n;try{n=x()?.getItem(v+e)??null}catch{return null}return n&&y.set(e,n),n}function C(e,t){y.set(e,t);try{x()?.setItem(v+e,t)}catch{}b.forEach(e=>e())}function w(e){return b.add(e),()=>{b.delete(e)}}function T(){let e=r()?.id,t=S(e);return e&&t?{userId:e,workspaceId:t}:null}function E(){if(typeof window>`u`)return`marketing`;let e=window.location.pathname;return e===`/app`||e.startsWith(`/app/`)?`app`:`marketing`}var D=`api_request`;function O(e){try{i(D,e.transport===`http`?{endpoint:e.endpoint,transport:`http`,source:e.source,authenticated:e.authenticated,ok:e.ok,duration_ms:e.durationMs,model:e.model,method:e.method,status:e.status}:{endpoint:e.endpoint,transport:`websocket`,source:e.source,authenticated:e.authenticated,ok:e.outcome===`completed`,duration_ms:e.durationMs,model:e.model,outcome:e.outcome,close_code:e.closeCode,turns:e.turns})}catch{}}function k(e){if(typeof e!=`object`||!e)return;let t=e.model;return typeof t==`string`?t:void 0}var A=new Map,j=`X-Organization-Id`,M=new Map;async function N(t,r,i){if(!await e())return null;let{accessToken:a,user:o}=n();if(!a||o?.user_id!==r)return null;let s=new Request(t);return s.headers.set(`Authorization`,`Bearer ${a}`),i(s)}var P={onRequest({id:e,request:t}){let r=E(),i=T(),{accessToken:a,user:o}=n(),s=new Request(t);return a&&o&&(s.headers.set(`Authorization`,`Bearer ${a}`),i&&i.userId===o.user_id&&s.headers.set(j,i.workspaceId),M.set(e,{request:s.clone(),userId:o.user_id})),A.set(e,{authenticated:!!a,source:r}),s},async onResponse({id:e,response:t,options:n}){let r=M.get(e);if(M.delete(e),!(t.status!==401||!r))return await N(r.request,r.userId,n.fetch)??void 0},onError({id:e}){M.delete(e)}},F=new Map,I=262144;async function L(e){if(e.headers.get(`content-type`)?.includes(`application/json`))try{let t=await e.clone().blob();return t.size>I?void 0:k(JSON.parse(await t.text()))}catch{return}}function R(e){let t=F.get(e);return F.delete(e),t===void 0?void 0:Math.round(performance.now()-t)}function z(e){let t=A.get(e)??{authenticated:!1,source:E()};return A.delete(e),t}var B={onRequest({id:e}){F.set(e,performance.now())},onResponse({id:e,request:t,response:n,schemaPath:r}){let i=R(e),{authenticated:a,source:o}=z(e);(async()=>{O({transport:`http`,endpoint:r,source:o,method:t.method,status:n.status,ok:n.ok,durationMs:i,authenticated:a,model:await L(t)})})()}
1,onError({id:e,request:t,schemaPath:n}){let r=R(e),{authenticated:i,source:a}=z(e);O({transport:`http`,endpoint:n,source:a,method:t.method,status:0,ok:!1,durationMs:r,authenticated:i})}};function V(e){let n=c({baseUrl:t,fetch:e??(e=>globalThis.fetch(e))});return n.use(P),n.use(B),n}var H=V();async function U(e,r={}){let{accessToken:i,user:a}=n(),o=new Headers(r.headers);i&&o.set(`Authorization`,`Bearer ${i}`);let s=new Request(`${t}${e}`,{...r,headers:o}),c=i&&a?{request:s.clone(),userId:a.user_id}:null,l=await globalThis.fetch(s);return l.status!==401||!c?l:await N(c.request,c.userId,e=>globalThis.fetch(e))??l}export{O as a,C as c,k as i,U as n,S as o,E as r,w as s,H as t};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.