Files
report/frontend/dist/assets/AIChatView-Bce7qiIa.js
T
2026-07-19 03:44:35 +09:00

27 lines
5.8 KiB
JavaScript

import{c as x,_ as O,o as D,a as h,b as v,S as V,d as e,u as A,e as $,f as K,F as P,r as j,g as z,w as B,v as L,h as F,i as G,j as g,k as p,l as q,n as H,m as f,p as J,t as N}from"./index-DWIiqzW2.js";/**
* @license lucide-vue-next v0.322.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const U=x("ChevronLeftIcon",[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]]);/**
* @license lucide-vue-next v0.322.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const Z=x("SendIcon",[["path",{d:"m22 2-7 20-4-9-9-4Z",key:"1q3vgg"}],["path",{d:"M22 2 11 13",key:"nzbqef"}]]),Q={class:"app-layout"},W={class:"main-content"},X={class:"chat-container"},Y={class:"chat-header"},ee={class:"header-left"},te={class:"message"},se={class:"avatar"},ae={class:"content"},oe={key:0,class:"message-wrapper assistant loading"},ne={class:"chat-input-section"},ie={class:"chat-input-wrapper"},re=["onKeydown"],ce=["disabled"],le={__name:"AIChatView",setup(de){const w=q(),C=p([]),i=p([{role:"assistant",text:"안녕하세요! 비즈니스 분석 및 전략 수립을 도와드리는 AI 어시스턴트입니다. 무엇을 도와드릴까요?"}]),c=p(""),d=p(!1),u=p(null),m=async()=>{try{const s=await g.get("/api/companies");s.ok&&(C.value=await s.json())}catch(s){console.error("Failed to fetch companies:",s)}},b=()=>{localStorage.removeItem("accessToken"),w.push("/login")},k=async()=>{if(!c.value.trim()||d.value)return;const s=c.value,t=localStorage.getItem("ai_preferred_provider")==="gpt"?"gpt":"gemini",n=localStorage.getItem("ai_gemini_key")||"",l=localStorage.getItem("ai_gpt_key")||"";i.value.push({role:"user",text:s}),c.value="",d.value=!0,await I();try{let a="";const M=`
당신은 '강촌상사'의 비즈니스 데이터 관리 전문가입니다.
아래 명령어를 사용하여 시스템을 직접 제어할 수 있습니다.
반드시 답변 마지막 줄에 해당 형식을 포함해 주세요.
1. 업체 이름 변경: [COMMAND] RENAME: 기존이름 -> 새로운이름
2. 새로운 업체 추가: [COMMAND] CREATE: 신규업체명
예: "네, 경주 업체를 새롭게 추가했습니다. [COMMAND] CREATE: 경주"
`;if(t==="gemini"){if(!n)throw new Error("Gemini API Key가 필요합니다.");const o=`https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=${n}`,r=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({contents:[{parts:[{text:M+`
`+s}]}]})});if(!r.ok)throw new Error("Gemini API 오류");a=(await r.json()).candidates[0].content.parts[0].text}else if(t==="gpt"){if(!l)throw new Error("GPT API Key가 필요합니다.");const o=await fetch("https://api.openai.com/v1/chat/completions",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${l}`},body:JSON.stringify({model:"gpt-4o-mini",messages:[{role:"system",content:M},{role:"user",content:s}]})});if(!o.ok)throw new Error("OpenAI API 오류 (할당량 부족 등)");a=(await o.json()).choices[0].message.content}const _=a.match(/\[COMMAND\] RENAME:\s*(.+)\s*->\s*(.+)/i);if(_){const o=_[1].trim(),r=_[2].trim();(await g.put("/api/reports/rename",{oldName:o,newName:r})).ok&&(a=a.replace(/\[COMMAND\].*$/m,`
✅ 시스템: '${o}' -> '${r}' 변경 완료.`),await m())}const E=a.match(/\[COMMAND\] CREATE:\s*(.+)/i);if(E){const o=E[1].trim();(await g.post("/api/reports/add",{name:o})).ok&&(a=a.replace(/\[COMMAND\].*$/m,`
✅ 시스템: '${o}' 업체 신규 등록 완료.`),await m())}i.value.push({role:"assistant",text:a})}catch(a){console.error("AI Request Failed:",a),i.value.push({role:"assistant",text:`오류: ${a.message}. 설정을 확인해 주세요.`})}finally{d.value=!1,await I()}},S=async()=>{var s;if(i.value.length<=1){alert("저장할 대화 내용이 없습니다.");return}try{const t=((s=i.value.find(l=>l.role==="user"))==null?void 0:s.text.substring(0,20))||"AI 대화";(await g.post("/api/ai/save",{title:t+"...",messages:i.value})).ok?alert("대화가 성공적으로 저장되었습니다."):alert("저장 중 오류가 발생했습니다.")}catch(t){alert("저장 실패: "+t.message)}},I=async()=>{await H(),u.value&&(u.value.scrollTop=u.value.scrollHeight)},T=()=>{w.push("/")},y=()=>{w.push("/")};return D(()=>{m()}),(s,t)=>(f(),h("div",Q,[v(V,{companies:C.value,onSelect:y,onEdit:y,onRefresh:m,onChangeView:y,onLogout:b},null,8,["companies"]),e("main",W,[e("div",X,[e("header",Y,[e("div",ee,[e("button",{class:"btn-back",onClick:T},[v(A(U),{size:20})]),t[1]||(t[1]=e("h1",null,"AI 비즈니스 어시스턴트",-1))]),e("button",{class:"btn-save",onClick:S},[v(A($),{size:18}),t[2]||(t[2]=K(" 저장하기 ",-1))])]),e("div",{class:"chat-history",ref_key:"historyRef",ref:u},[(f(!0),h(P,null,j(i.value,(n,l)=>(f(),h("div",{key:l,class:J(["message-wrapper",n.role])},[e("div",te,[e("div",se,N(n.role==="user"?"U":"AI"),1),e("div",ae,[e("p",null,N(n.text),1)])])],2))),128)),d.value?(f(),h("div",oe,[...t[3]||(t[3]=[e("div",{class:"message"},[e("div",{class:"avatar"},"AI"),e("div",{class:"content"},[e("div",{class:"typing-indicator"},[e("span"),e("span"),e("span")])])],-1)])])):z("",!0)],512),e("div",ne,[e("div",ie,[B(e("textarea",{"onUpdate:modelValue":t[0]||(t[0]=n=>c.value=n),placeholder:"비즈니스 전략이나 분석에 대해 물어보세요... (Shift+Enter 줄바꿈, Enter 전송)",onKeydown:F(G(k,["exact","prevent"]),["enter"]),rows:"1"},null,40,re),[[L,c.value]]),e("button",{class:"btn-send",onClick:k,disabled:d.value||!c.value.trim()},[v(A(Z),{size:20})],8,ce)]),t[4]||(t[4]=e("p",{class:"input-hint"},"Gemini 1.5 Flash 모델이 답변을 생성합니다.",-1))])])])]))}},ue=O(le,[["__scopeId","data-v-7c7c57d1"]]);export{ue as default};