1import { j as jsxRuntimeExports, r as reactExports, i as import_0 } from "../chunks/chunk-BNtYH5Ky.js"; 2import { V as VikeSPAWrapper } from "../chunks/chunk-D0NTw0_J.js"; 3import { M as MinimalistTemplate } from "../chunks/chunk-CBa70AHI.js"; 4import { C as ChatThread, a as Composer } from "../chunks/chunk-Bsf4A-OJ.js"; 5import "../chunks/chunk-gQZ1vf8Q.js"; 6import "../chunks/chunk-BTx5AHFF.js"; 7import "../chunks/chunk-Br8eeEhf.js"; 8import "../chunks/chunk-l9Jn42e6.js"; 9import "../chunks/chunk-DsLNlzEu.js"; 10import "../chunks/chunk-2y7yGY3w.js"; 11import "../chunks/chunk-C9vQsYDo.js"; 12import "../chunks/chunk-Czm1Pvkq.js"; 13import "../chunks/chunk-C2ZLf8sv.js"; 14import "../chunks/chunk-OWGnv4s1.js"; 15import "../chunks/chunk-hjvfnpw_.js"; 16import "../chunks/chunk-ciw2aYiu.js"; 17const Layout = ({ children }) => /* @__PURE__ */ jsxRuntimeExports.jsx(VikeSPAWrapper, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(MinimalistTemplate, { children }) }); 18const import_1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ 19 __proto__: null, 20 Layout 21}, Symbol.toStringTag, { value: "Module" })); 22const WIDGET_URL = `${"https://chatapi.avify.com/api/v1".split("/api")[0]}/widget/v1/chat`; 23const CHAT_ID_KEY = "avify_widget_chat_id"; 24function getChatId() { 25 const stored = localStorage.getItem(CHAT_ID_KEY); 26 if (stored) return stored; 27 const id = crypto.randomUUID(); 28 localStorage.setItem(CHAT_ID_KEY, id); 29 return id; 30} 31function makeMessage(body, fromStore) { 32 return { 33 id: crypto.randomUUID(), 34 type: "text", 35 body, 36 fromStore, 37 timestamp: Date.now(), 38 senderRole: fromStore ? "ai" : "human" 39 }; 40} 41function ChatWidget({ pipelineId }) { 42 const [messages, setMessages] = reactExports.useState([]); 43 const [isTyping, setIsTyping] = reactExports.useState(false); 44 const [chatId] = reactExports.useState(() => getChatId()); 45 reactExports.useEffect(() => { 46 if (!pipelineId) return; 47 setMessages([makeMessage("¡Hola! ¿En qué te puedo ayudar hoy?", true)]); 48 }, [pipelineId]); 49 const handleSend = reactExports.useCallback( 50 async (text) => { 51 setMessages((prev) => [...prev, makeMessage(text, false)]); 52 setIsTyping(true);
53 try { 54 const headers = new Headers(); 55 headers.set("Content-Type", "application/json"); 56 const res = await fetch(WIDGET_URL, { 57 method: "POST", 58 headers, 59 body: JSON.stringify({ pipelineId, chatId, prompt: text }) 60 }); 61 const data = await res.json(); 62 if (data.error) throw new Error(data.error); 63 setMessages((prev) => { 64 var _a; 65 return [ 66 ...prev, 67 makeMessage(data.reply ?? "Lo siento, no pude procesar tu mensaje.", true), 68 ...((_a = data.images) == null ? void 0 : _a.map((img) => ({ 69 id: crypto.randomUUID(), 70 type: "images", 71 body: "", 72 fromStore: true, 73 timestamp: Date.now(), 74 senderRole: "ai", 75 images: [img] 76 }))) ?? [] 77 ]; 78 }); 79 } catch { 80 setMessages((prev) => [ 81 ...prev, 82 makeMessage("Ocurrió un error. Por favor intenta de nuevo.", true) 83 ]); 84 } finally { 85 setIsTyping(false); 86 } 87 }, 88 [pipelineId, chatId] 89 ); 90 return /* @__PURE__ */ jsxRuntimeExports.jsxs( 91 "div", 92 { 93 style: { 94 display: "flex", 95 flexDirection: "column", 96 height: "100dvh", 97 background: "#fff", 98 fontFamily: "system-ui, sans-serif" 99 }, 100 children: [
101 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: { flex: 1, overflow: "hidden" }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(ChatThread, { messages, isTyping }) }), 102 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: { borderTop: "1px solid #eee", padding: "8px" }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Composer, { disabled: isTyping || !pipelineId, onSend: handleSend, autoFocus: true }) }) 103 ] 104 } 105 ); 106} 107function Page() { 108 const params = new URLSearchParams(typeof window !== "undefined" ? window.location.search : ""); 109 const pipelineId = params.get("pipeline_id") ?? ""; 110 return /* @__PURE__ */ jsxRuntimeExports.jsx(ChatWidget, { pipelineId }); 111} 112const import_2 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ 113 __proto__: null, 114 default: Page 115}, Symbol.toStringTag, { value: "Module" })); 116const configValuesImported = [ 117 { 118 configName: "onRenderClient", 119 importPath: "/src/renderer/+onRenderClient.tsx", 120 isValueFile: true, 121 exportValues: import_0 122 }, 123 { 124 configName: "Layout",
125 importPath: "/src/pages/chat/+Layout.tsx", 126 isValueFile: true, 127 exportValues: import_1 128 }, 129 { 130 configName: "Page", 131 importPath: "/src/pages/chat/+Page.tsx", 132 isValueFile: true, 133 exportValues: import_2 134 } 135]; 136const configValuesSerialized = { 137 ["onBeforeRenderEnv"]: { 138 valueSerialized: "null", 139 type: "computed", 140 definedAtData: null 141 }, 142 ["dataEnv"]: { 143 valueSerialized: "null", 144 type: "computed", 145 definedAtData: null 146 }, 147 ["hydrationCanBeAborted"]: { 148 valueSerialized: "true", 149 type: "classic", 150 definedAtData: { "filePathToShowToUser": "/src/pages/chat/+config.h.ts", "fileExportPathToShowToUser": ["default", "hydrationCanBeAborted"] } 151 } 152}; 153export { 154 configValuesImported, 155 configValuesSerialized 156};
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.