1import{o as h,E as x}from"./toast.7aaa4476.js";import{f as b}from"./ipSearchingData.df1a04d3.js";import{l as _}from"./js.cookie.a9c443ab.js";import{u as v}from"./state.a5689590.js";import{h as D}from"./runtime-core.esm-bundler.693c71a8.js";/** 2 * @patsnap/agent-context v0.1.0 3 * (c) 2026 PatSnap 4 * @license MIT 5 */const f=1,T=2*60*60*1e3;class i extends Error{constructor(t,n,r){super(n),this.name="AgentContextError",this.code=t,this.cause=r}}const S="patsnap-agent-context",I=1,d="contexts",w="expiresAt";function u(e){if(e instanceof i)return e;const t=globalThis.DOMException;return t&&e instanceof t&&e.name==="QuotaExceededError"?new i("quota_exceeded","Agent context storage quota exceeded",e):new i("storage_error","Agent context storage operation failed",e)}function j(e){return new Promise((t,n)=>{e.onsuccess=()=>t(e.result),e.onerror=()=>n(u(e.error))})}function l(e){return new Promise((t,n)=>{e.oncomplete=()=>t(),e.onerror=()=>n(u(e.error)),e.onabort=()=>n(u(e.error))})}class N{constructor(t={}){this._indexedDB=t.indexedDB,this._databaseName=t.databaseName??S}getIndexedDB(){const t=this._indexedDB??globalThis.indexedDB;if(!t)throw new i("unsupported","IndexedDB is not available in this environment");return t}openDatabase(){return this._databasePromise?this._databasePromise:(this._databasePromise=new Promise((t,n)=>{let r;try{r=this.getIndexedDB().open(this._databaseName,I)}catch(s){n(u(s));return}r.onupgradeneeded=()=>{const s=r.result,a=s.objectStoreNames.contains(d)?r.transaction.objectStore(d):s.createObjectStore(d,{keyPath:"id"});a.indexNames.contains(w)||a.createIndex(w,"expiresAt")},r.onsuccess=()=>t(r.result),r.onerror=()=>{this._databasePromise=void 0,n(u(r.error))},r.onblocked=()=>{this._databasePromise=void 0,n(new i("storage_error","Agent context database open was blocked"))}}),this._databasePromise)}async put(t){try{const r=(await this.openDatabase()).transaction(d,"readwrite");r.objectStore(d).put(t),await l(r)}catch(n){throw u(n)}}async get(t){try{const r=(await this.openDatabase()).transaction(d,"readonly"),s=r.objectStore(d).get(t),a=await j(s);return await l(r),a}catch(n){throw u(n)}}async remove(t){try{const r=(await this.openDatabase()).transaction(d,"readwrite");r.objectStore(d).delete(t),await l(r)}catch(n){throw u(n)}}async removeExpired(t){try{const r=(await this.openDatabase()).transaction(d,"readwrite"),a=r.objectStore(d).index(w).openCursor(IDBKeyRange.upperBound(t));let c=0;return await new Promise((p,o)=>{a.onsuccess=()=>{const m=a.result;if(!m){p();return}m.delete(),c+=1,m.continue()},a.onerror=()=>o(u(a.error))}),await l(r),c}catch(n){throw u(n)}}}function C(){const e=globalThis.crypto;if(!(e!=null&&e.getRandomValues))throw new i("unsupported","Web Crypto is not available in this environment");if(typeof e.randomUUID=="function")return e.randomUUID();const t=e.getRandomValues(new Uint8Array(16));return Array.from(t,n=>n.toString(16).padStart(2,"0")).join("")}function g(e){if(e instanceof i)return e;const t=globalThis.DOMException;return t&&e instanceof t&&e.name==="QuotaExceededError"?new i("quota_exceeded","Agent context storage quota exceeded",e):new i("storage_error","Agent context storage operation failed",e)}function F(e){if(e!=null&&e.length)return e.map(t=>{if(!(t instanceof Blob))throw new i("invalid_payload","payload.files must contain File objects");return{blob:t.slice(0,t.size,t.type),name:t.name,type:t.type,size:t.size,lastModified:t.lastModified}})}function U(e){if(!(e!=null&&e.length))return;const t=globalThis.File;if(!t)throw new i("unsupported","File is not available in this environment");return e.map(n=>new t([n.blob],n.name,{type:n.type,lastModified:n.lastModified}))}function P(e={}){const t=e.store??new N,n=e.ttlMs??T,r=e.now??Date.now,s=e.idGenerator??C;if(!Number.isFinite(n)||n<=0)throw new i("invalid_payload","ttlMs must be a positive number");return{async save(a){if(!a.agent.trim())throw new i("invalid_payload","agent is required");try{const c=r();await t.removeExpired(c);const p=s(),o={...a.payload,files:F(a.payload.files)};return o.files||delete o.files,await t.put({id:p,schemaVersion:f,agent:a.agent,createdAt:c,expiresAt:c+n,payload:o}),{contextId:p}}catch(c){throw g(c)}},async read(a,c){if(!a)return{status:"missing"};try{const p=r(),o=await t.get(a);if(await t.removeExpired(p),!o)return{status:"missing"};if(o.expiresAt<=p)return{status:"expired"};if(o.schemaVersion!==f)return{status:"schema_mismatch"};if(o.agent!==c.expectedAgent)return{status:"agent_mismatch"};const m={...o.payload,files:U(o.payload.files)};return m.files||delete m.files,{status:"found",context:{id:o.id,schemaVersion:f,agent:o.agent,createdAt:o.createdAt,expiresAt:o.expiresAt,payload:m}}}catch(p){throw g(p)}},async remove(a){try{await t.remove(a)}catch(c){throw g(c)}},async cleanupExpired(){try{return await t.removeExpired(r())}catch(a){throw g(a)}}}}const E={novelty:{accept:".jpg,.jpeg,.png,.pdf,.doc,.docx",mimeTypes:["image/jpeg","image/png","application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document"],extensions:["jpg","jpeg","png","pdf","doc","docx"],maxFiles:11,maxFileSize:5*1024*1024,maxDocuments:1,maxImages:10},fto:{accept:".jpg,.jpeg,.png",mimeTypes:["image/jpeg","image/png"],extensions:["jpg","jpeg","png"],maxFiles:10,maxFileSize:20*1024*1024},"design-fto":{accept:".jpg,.jpeg,.png,.webp",mimeTypes:["image/jpeg","image/png","image/webp"],extensions:["jpg","jpeg","png","webp"],maxFiles:8,maxFileSize:4*1024*1024}},M=P();function A(e){var t;return((t=e.name.split(".").pop())==null?void 0:t.toLowerCase())||""}function y(e){return["pdf","doc","docx"].includes(A(e))}function R(e,t){const n=E[e];return t.size<=n.maxFileSize&&(n.mimeTypes.includes(t.type)||n.extensions.includes(A(t)))}function B(e,t){const n=E[e];return t.length>n.maxFiles||n.maxDocuments!==void 0&&t.filter(y).length>n.maxDocuments||n.maxImages!==void 0&&t.filter(r=>!y(r)).length>n.maxImages?!1:t.every(r=>R(e,r))}function O(e){return e==="design-fto"?"design_fto":e}async function X(e){var s;
5const t=((s=e.prompt)==null?void 0:s.trim())||"",n=e.files||[],r=b(e.eurekaUrl,e.path);if(!t&&n.length===0)return r;if(new URL(r,window.location.origin).origin!==window.location.origin){h({type:x.error,message:"Your input can only be transferred when both pages use the same origin.",duration:4e3});return}if(!B(e.agentId,n)){h({type:x.warning,message:"One or more attachments do not meet this Agentâs file requirements.",duration:4e3});return}try{const{contextId:a}=await M.save({agent:O(e.agentId),payload:{prompt:t,files:n}});return b(e.eurekaUrl,e.path,{contextId:a})}catch{h({type:x.error,message:"We could not save your input in this browser. Please try again.",duration:4e3});return}}function k(){const e=_(),t=v("sign-in-redirect-url",()=>({routePath:"",redirectUrl:void 0})),n=D(()=>t.value.routePath===e.path?t.value.redirectUrl:void 0);function r(s){t.value={routePath:e.path,redirectUrl:s}}return{redirectUrl:n,setRedirectUrl:r}}export{X as c,k as u};
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.