1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[94644],{94644:(e,t,n)=>{n.r(t),n.d(t,{createPublicQueryHandler:()=>c,upstreamError:()=>E,validateInput:()=>i});var r=n(64193);let a={"Cache-Control":"no-store, private","X-Content-Type-Options":"nosniff"};class o extends Error{constructor(e,t=400){super(e),this.code=e,this.status=t}}let s=e=>null===e||"object"!=typeof e||Array.isArray(e)?{}:e;function i(e){var t;let n=s(e);if("string"!=typeof n.question)throw new o("INVALID_QUESTION");let r=n.question.trim();if(!r||r.length>1500||/[\u0000-\u0008\u000b\u000c\u000e-\u001f]/.test(r))throw new o("INVALID_QUESTION");if(void 0!==n.locale&&("string"!=typeof n.locale||!["es","en","de","fr"].includes(n.locale)))throw new o("INVALID_REQUEST");let a={question:r,locale:null!=(t=n.locale)?t:"es"};if(void 0!==n.tz){if("number"!=typeof n.tz||!Number.isInteger(n.tz)||Math.abs(n.tz)>840)throw new o("INVALID_REQUEST");a.tz=n.tz}if(void 0!==n.tz_name){if("string"!=typeof n.tz_name||n.tz_name.length>80)throw new o("INVALID_REQUEST");try{new Intl.DateTimeFormat("en",{timeZone:n.tz_name})}catch(e){throw new o("INVALID_REQUEST")}a.tz_name=n.tz_name}return a}async function l(e){var t;let n=e.headers.get("content-length");if(n&&Number(n)>12e3)throw new o("INPUT_TOO_LARGE",413);if(!(null==(t=e.headers.get("content-type"))?void 0:t.toLowerCase().startsWith("application/json"))||!e.body)throw new o("INVALID_REQUEST");let r=e.body.getReader(),a=new TextDecoder,s=0,l="";try{for(;;){if(e.signal.aborted)throw new o("REQUEST_CANCELLED",499);let t=await r.read();if(t.done)break;if((s+=t.value.byteLength)>12e3)throw await r.cancel().catch(()=>void 0),new o("INPUT_TOO_LARGE",413);l+=a.decode(t.value,{stream:!0})}l+=a.decode()}finally{r.releaseLock()}try{return i(JSON.parse(l))}catch(e){if(e instanceof o)throw e;throw new o("INVALID_REQUEST")}}function u(e,t,n){var r;let o=new Headers(a),s=null!=(r=null==n?void 0:n.headers.get("retry-after"))?r:"";return/^\d{1,6}$/.test(s)&&o.set("Retry-After",String(Math.max(1,Number(s)))),Response.json({error:e},{status:t,headers:o})}function E(e,t,n){return!0===t.pausado?"turno"===t.ventana?"TURN_LIMIT":"MODEL_PAUSED":401===e?"AUTH_REQUIRED":413===e?"INPUT_TOO_LARGE":429===e?"anonymous_busy"===t.motivo||"busy"===t.motivo?"BUSY":n?"RATE_LIMITED":"firewall_unavailable"===t.motivo?"ASK_UNAVAILABLE":["anonymous_global_cap","anonymous_spend_cap"].includes(String(t.motivo))?"MODEL_PAUSED":"QUOTA_EXCEEDED":400===e?"INVALID_REQUEST":e>=500?"ASK_UNAVAILABLE":"ASK_FAILED"}function c(e){return async function(t){try{var n,i;if(t.signal.aborted)return u("REQUEST_CANCELLED",499);let o=null!=(n=t.headers.get("authorization"))?n:"",c=/^Bearer ([^\s]+)$/.exec(o);if(!c||c[1].length>8192)return u("AUTH_REQUIRED",401);let _=await l(t),f=await e.authenticate(c[1],t.signal);if(t.signal.aborted)return u("REQUEST_CANCELLED",499);if("authenticated"!==f)return u("invalid"===f?"AUTH_REQUIRED":"AUTH_UNAVAILABLE","invalid"===f?401:503);let d=new Headers({"content-type":"application/json",authorization:o});for(let e of["user-agent","x-forwarded-for","x-real-ip","x-vercel-ip-country","x-vercel-forwarded-for"]){let n=t.headers.get(e);n&&n.length<=2048&&d.set(e,n)}let A=new Request(new URL("/api/ask",t.url),{method:"POST",headers:d,signal:t.signal,body:JSON.stringify({question:_.question,locale:_.locale,...void 0!==_.tz?{tz:_.tz}:{},..._.tz_name?{tz_name:_.tz_name}:{},persona:"analista",sin_acciones:!0,sin_contexto_personal:!0})}),h=await e.ask(A);if(t.signal.aborted)return u("REQUEST_CANCELLED",499);if(!(null!=(i=h.headers.get("content-type"))?i:"").includes("json"))return u(h.ok?"INVALID_RESPONSE":"ASK_UNAVAILABLE",h.ok?502:h.status,h);let I=s(await h.json().catch(()=>null));if(!h.ok||!0===I.pausado||"string"==typeof I.error)return u(E(h.status,I,h.headers.get("retry-after")),h.status,h);let L=(0,r.projectPublicResponse)(I,_.locale,e.projection);return Response.json(L,{status:h.status,headers:a})}catch(e){if(t.signal.aborted)return u("REQUEST_CANCELLED",499);if(e instanceof o)return u(e.code,e.status);if(e instanceof Error&&["UNSAFE_RESPONSE","INVALID_RESPONSE"].includes(e.message))return u(e.message,502);return u("ASK_UNAVAILABLE",503)}}}}}]);
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.