@blueking/ai-blueking 2.0.0-beta.3 → 2.0.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"use-chatbot-init.d.ts","sourceRoot":"","sources":["../../../src/components/composables/use-chatbot-init.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAI/B,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAG7F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAG7C,MAAM,MAAM,aAAa,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;AAErD,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,aAAa,CAAC;IACpB,KAAK,EAAE,YAAY,CAAC;IACpB,cAAc,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACrC;AAED,MAAM,WAAW,oBAAoB;IACnC,mBAAmB,EAAE,mBAAmB,GAAG,IAAI,CAAC;IAChD,UAAU,EAAE,WAAW,GAAG,IAAI,CAAC;IAC/B,SAAS,EAAE,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;IAC7B,aAAa,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IAC5B,gBAAgB,EAAE,OAAO,CAAC;IAC1B,sBAAsB,EAAE,IAAI,GAAG,sBAAsB,CAAC;IACtD,eAAe,EAAE,eAAe,CAAC;CAClC;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,oBAAoB,GAAG,oBAAoB,CAgJjF"}
1
+ {"version":3,"file":"use-chatbot-init.d.ts","sourceRoot":"","sources":["../../../src/components/composables/use-chatbot-init.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAI/B,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAG7F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAG7C,MAAM,MAAM,aAAa,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;AAErD,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,aAAa,CAAC;IACpB,KAAK,EAAE,YAAY,CAAC;IACpB,cAAc,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACrC;AAED,MAAM,WAAW,oBAAoB;IACnC,mBAAmB,EAAE,mBAAmB,GAAG,IAAI,CAAC;IAChD,UAAU,EAAE,WAAW,GAAG,IAAI,CAAC;IAC/B,SAAS,EAAE,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;IAC7B,aAAa,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IAC5B,gBAAgB,EAAE,OAAO,CAAC;IAC1B,sBAAsB,EAAE,IAAI,GAAG,sBAAsB,CAAC;IACtD,eAAe,EAAE,eAAe,CAAC;CAClC;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,oBAAoB,GAAG,oBAAoB,CA4IjF"}
@@ -33374,15 +33374,7 @@ function bT(e) {
33374
33374
  }) : null, d = new hT(null, t.shortcuts || []);
33375
33375
  return I(async () => {
33376
33376
  if (!(!s || a.value)) try {
33377
- if (c) {
33378
- if (await s.agent.getAgentInfo(), await s.session.getSessions(), t.sessionCode) await s.session.chooseSession(t.sessionCode);
33379
- else if (s.session.list.value.length > 0) {
33380
- let e = s.session.list.value[0];
33381
- await s.session.chooseSession(e.sessionCode);
33382
- }
33383
- i.value = !0;
33384
- } else i.value = !0;
33385
- n("agent-info-loaded", s);
33377
+ c ? (await Promise.all([s.agent.getAgentInfo(), s.session.getSessions()]), l && await l.loadRecentSession({ skipLoadSessions: !0 }), i.value = !0) : i.value = !0, n("agent-info-loaded", s);
33386
33378
  } catch (e) {
33387
33379
  console.error("Failed to initialize ChatBot:", e), a.value = e, n("error", e);
33388
33380
  }
@@ -3035,7 +3035,7 @@ Use Shift + Enter to enter a new line`:`输入 “/”唤出 Prompt
3035
3035
  ${i}
3036
3036
  </div>
3037
3037
  `}),w=async()=>{if(r.sessionBusinessManager)try{await r.sessionBusinessManager.createNewSession()}catch(e){console.error(`Failed to create new session:`,e),md({theme:`error`,message:u9(`创建会话失败`)})}i(`new-chat`)},T=e=>{e.stopPropagation(),r.sessionBusinessManager?(h||g(),h&&h.handleTriggerClick(e)):i(`history-click`,e)},E=()=>{i(`help-click`)},D=e=>{e.stopPropagation(),h&&h.isVisible()&&h.hide(),p&&(p.state.isVisible?p.hide():p.show())},O=e=>{e.stopPropagation(),e.preventDefault();let t=e.currentTarget,n=t.dataset.action;if(!t.classList.contains(`disabled`))switch(p&&p.hide(),n){case`rename`:k();break;case`auto-generate`:i(`auto-generate-name`);break;case`share`:i(`share`);break}},k=()=>{document.removeEventListener(`click`,N),d.value=r.sessionName||``,u.value=!0,setTimeout(()=>{document.addEventListener(`click`,N)},100),setTimeout(()=>{if(f.value)try{let e=f.value;e&&typeof e.focus==`function`&&e.focus();let t=e.$el?.querySelector(`input`);t&&typeof t.select==`function`&&t.select()}catch(e){console.warn(`Failed to focus rename input:`,e)}},100)},A=()=>{let e=d.value.trim();if(!e){j();return}i(`rename`,e),u.value=!1,d.value=``},j=()=>{u.value=!1,d.value=``},M=(e,t)=>{d.value=e,t.key===`Enter`?A():t.key===`Escape`&&j()},N=e=>{if(!u.value)return;let t=e.target,n=document.querySelector(`.rename-tooltip`);n&&!n.contains(t)&&j()},P=async()=>{if(!l.value)return;let e=(await Promise.resolve().then(()=>(T9(),j0t))).default;p&&=(p.destroy(),null),p=e(l.value,{content:C.value,theme:`ai-blueking-light more-menu-light light`,placement:`bottom-start`,trigger:`manual`,interactive:!0,allowHTML:!0,arrow:!1,offset:[0,4],appendTo:()=>document.querySelector(`.ai-blueking-panel`)||document.body,onShow:()=>{setTimeout(async()=>{let{default:e}=await Promise.resolve().then(()=>(T9(),j0t));document.querySelectorAll(`.tippy-menu-item`).forEach(t=>{let n=t;n.addEventListener(`click`,O);let r=n.getAttribute(`data-tippy-content`);if(r&&!m.has(n)){let t=e(n,{content:r,theme:`ai-blueking-tooltip`,trigger:`mouseenter focus`,arrow:!0,delay:[300,0],appendTo:()=>document.querySelector(`.ai-blueking-panel`)||document.body});m.set(n,t)}})},0)},onHide:()=>{document.querySelectorAll(`.tippy-menu-item`).forEach(e=>{let t=e;t.removeEventListener(`click`,O);let n=m.get(t);n&&(n.destroy(),m.delete(t))})}})};return gr(()=>[r.isCompressionHeight,r.hasSessionContents],()=>{p&&p.setContent(C.value)}),Jn(()=>{P(),r.sessionBusinessManager&&g(),document.addEventListener(`click`,N)}),Yn(()=>{p&&=(p.destroy(),null),m.forEach(e=>{e.destroy()}),m.clear(),h&&=(h.destroy(),null),document.removeEventListener(`click`,N)}),t({headerRef:o,historyIconRef:s}),(t,n)=>(H(),U(`div`,{ref_key:`headerRef`,ref:o,class:_e([`ai-header drag-handle`,{draggable:r.draggable}])},[Br(`div`,t4t,[Br(`div`,n4t,[Br(`img`,{alt:`logo`,src:V(_0t)},null,8,r4t)]),Br(`div`,{class:_e([`title`,{"title-with-tooltip":u.value}])},[Wr(Ce(_.value)+` `,1),Gr(` 重命名 tooltip 直接绑定在 title 上 `),u.value?(H(),U(`div`,i4t,[Br(`div`,a4t,[Vr(V(Cu),{ref_key:`renameInputRef`,ref:f,modelValue:d.value,"onUpdate:modelValue":n[0]||=e=>d.value=e,class:`rename-input`,placeholder:V(u9)(`请输入新的会话名称`),onKeyup:M},null,8,[`modelValue`,`placeholder`]),Br(`div`,{class:`rename-buttons`},[Br(`i`,{class:`bkai-icon bkai-check-1 rename-btn confirm-btn`,onClick:A}),Br(`i`,{class:`bkai-icon bkai-close rename-btn cancel-btn`,onClick:j})])])])):Gr(`v-if`,!0)],2),r.showMoreIcon&&b.value?(H(),U(`span`,{key:0,ref_key:`moreIconRef`,ref:l,class:`bkai-icon bkai-more`,onClick:D},null,512)):Gr(`v-if`,!0)]),Br(`div`,o4t,[Gr(` 新增会话按钮 `),r.showNewChatIcon&&e.enableChatSession!==!1?Dn((H(),U(`i`,{key:0,class:_e([`bkai-icon`,`bkai-xinzengliaotian`,{disabled:!b.value}]),style:fe(S()),onClick:n[1]||=e=>b.value?w():void 0},null,6)),[[V(a),{content:x(V(u9)(`新增会话`)),boundary:`parent`}]]):Gr(`v-if`,!0),Gr(` 历史会话按钮 `),r.showHistoryIcon&&e.enableChatSession!==!1?Dn((H(),U(`i`,{key:1,ref_key:`historyIconRef`,ref:s,class:_e([`bkai-icon`,`bkai-history`,{disabled:!b.value}]),style:fe(S()),onClick:n[2]||=e=>b.value?T(e):void 0},null,6)),[[V(a),{content:x(V(u9)(`历史会话`)),boundary:`parent`}]]):Gr(`v-if`,!0),e.chatGroup?.enabled?Dn((H(),U(`i`,{key:2,class:`bkai-icon bkai-zhushou`,onClick:E},null,512)),[[V(a),{content:V(u9)(`转人工`),boundary:`parent`}]]):Gr(`v-if`,!0),r.showCompressionIcon?Dn((H(),U(`i`,{key:3,class:_e([`bkai-icon`,v.value]),onClick:n[3]||=e=>i(`toggle-compression`)},null,2)),[[V(a),{content:y.value,boundary:`parent`}]]):Gr(`v-if`,!0),Dn(Br(`i`,{class:`bkai-icon bkai-close-line-2`,onClick:n[4]||=e=>i(`close`)},null,512),[[V(a),{content:V(u9)(`关闭`),boundary:`parent`}]])])],2))}}),[[`__scopeId`,`data-v-3cf2263c`]]),c4t=e=>{var t;return{conversationSettings:{openingRemark:e?.conversation_settings?.opening_remark,predefinedQuestions:e?.conversation_settings?.predefined_questions,commands:e==null||(t=e.conversation_settings)==null?void 0:t.commands?.map(e=>({id:e.id,name:e.name,alias:e.alias,icon:e.icon,components:e.components.map(e=>({type:e.type,name:e.name,key:e.key,placeholder:e.placeholder,default:e.default,required:e.required,fillBack:e.fill_back,fillRegx:e.fill_regx,rows:e.rows,min:e.min,max:e.max,options:e.options})),content:e.content,agentId:e.agent_id,status:e.status,supportUpload:e.support_upload})),enableChatSession:e?.conversation_settings?.enable_chat_session},promptSetting:e?.prompt_setting?{content:e.prompt_setting.content,supportUpload:e.prompt_setting.support_upload}:void 0,agentName:e?.agent_name,chatGroup:e?.chat_group?{enabled:e.chat_group.enabled,staff:e.chat_group.staff,username:e.chat_group.username}:void 0,saasUrl:e?.saas_url,resources:e?.resources}},D9;(function(e){e.FlowAgent=`flow_agent`,e.KnowledgeRag=`knowledge_rag`,e.ReferenceDocument=`reference_document`})(D9||={});var O9;(function(e){e.Activity=`activity`,e.Assistant=`assistant`,e.Developer=`developer`,e.Guide=`guide`,e.Hidden=`hidden`,e.HiddenAssistant=`hidden-assistant`,e.HiddenGuide=`hidden-guide`,e.HiddenSystem=`hidden-system`,e.HiddenUser=`hidden-user`,e.Info=`info`,e.Pause=`pause`,e.Placeholder=`placeholder`,e.Reasoning=`reasoning`,e.System=`system`,e.TemplateAssistant=`template-assistant`,e.TemplateGuide=`template-guide`,e.TemplateHidden=`template-hidden`,e.TemplateSystem=`template-system`,e.TemplateUser=`template-user`,e.Tool=`tool`,e.User=`user`})(O9||={});var k9;(function(e){e.Complete=`complete`,e.Error=`error`,e.Pending=`pending`,e.Stop=`stop`,e.Streaming=`streaming`})(k9||={});var A9;(function(e){e.Binary=`binary`,e.Function=`function`,e.Text=`text`})(A9||={});function l4t(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function j9(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t],r=Object.keys(n);typeof Object.getOwnPropertySymbols==`function`&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){l4t(e,t,n[t])})}return e}function u4t(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function M9(e,t){return t??={},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):u4t(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}),e}var N9=e=>{let t={id:e.id,messageId:e.message_id,name:e.name,role:e.role,sessionCode:e.session_code,status:e.status};switch(e.role){case O9.Activity:{let n=e,r=e=>e.map(e=>({name:e.name,originFileUrl:e.origin_file_url,url:e.url})),i;switch(n.activity_type){case D9.ReferenceDocument:i=r(n.content);break;case D9.KnowledgeRag:{let e=n.content;i={content:e.content,referenceDocument:r(e.reference_document)};break}case D9.FlowAgent:default:i=n.content;break}return M9(j9({},t),{activityType:n.activity_type,content:i,role:n.role})}case O9.Assistant:{let n=e;return M9(j9({},t),{content:n.content,property:n.property,role:n.role,toolCalls:n.tool_calls?.map(e=>({function:{arguments:e.function.arguments,name:e.function.name,description:e.function.description,mcpName:e.function.mcp_name},id:e.id,type:e.type}))})}case O9.Developer:{let n=e;return M9(j9({},t),{content:n.content,role:n.role})}case O9.Guide:{let n=e;return M9(j9({},t),{content:n.content,role:n.role})}case O9.Hidden:{let n=e;return M9(j9({},t),{content:n.content,role:n.role})}case O9.HiddenAssistant:{let n=e;return M9(j9({},t),{content:n.content,role:n.role})}case O9.HiddenGuide:{let n=e;return M9(j9({},t),{content:n.content,role:n.role})}case O9.HiddenSystem:{let n=e;return M9(j9({},t),{content:n.content,role:n.role})}case O9.HiddenUser:{let n=e;return M9(j9({},t),{content:n.content,role:n.role})}case O9.Info:{let n=e;return M9(j9({},t),{content:n.content,role:n.role})}case O9.Pause:{let n=e;return M9(j9({},t),{content:n.content,role:n.role})}case O9.Placeholder:{let n=e;return M9(j9({},t),{content:n.content,role:n.role})}case O9.Reasoning:{let n=e;return M9(j9({},t),{content:n.content,duration:n.duration,role:n.role})}case O9.System:{let n=e;return M9(j9({},t),{content:n.content,role:n.role})}case O9.TemplateAssistant:{let n=e;return M9(j9({},t),{content:n.content,role:n.role})}case O9.TemplateGuide:{let n=e;return M9(j9({},t),{content:n.content,role:n.role})}case O9.TemplateHidden:{let n=e;return M9(j9({},t),{content:n.content,role:n.role})}case O9.TemplateSystem:{let n=e;return M9(j9({},t),{content:n.content,role:n.role})}case O9.TemplateUser:{let n=e;return M9(j9({},t),{content:n.content,role:n.role})}case O9.Tool:{let n=e;return M9(j9({},t),{content:n.content,duration:n.duration,error:n.error,role:n.role,toolCallId:n.tool_call_id})}case O9.User:{let n=e,r=n.content;return M9(j9({},t),{content:Array.isArray(r)?r.map(e=>{if(e.type===A9.Binary){let t=e;return{data:t.data,filename:t.filename,id:t.id,mimeType:t.mime_type,type:t.type,url:t.url}}return e}):r,property:n.property,role:n.role})}}},d4t=e=>{let t={id:e.id,message_id:e.messageId,name:e.name,role:e.role,session_code:e.sessionCode,status:e.status};switch(e.role){case O9.Activity:{let n=e,r=e=>e.map(e=>({name:e.name,origin_file_url:e.originFileUrl,url:e.url})),i;switch(n.activityType){case D9.ReferenceDocument:i=r(n.content);break;case D9.KnowledgeRag:{let e=n.content;i={content:e.content,reference_document:r(e.referenceDocument)};break}case D9.FlowAgent:default:i=n.content;break}return M9(j9({},t),{activity_type:n.activityType,content:i,role:n.role})}case O9.Assistant:{let n=e;return M9(j9({},t),{property:n.property,content:n.content,role:n.role,tool_calls:n.toolCalls?.map(e=>({function:{arguments:e.function.arguments,name:e.function.name,description:e.function.description,mcp_name:e.function.mcpName},id:e.id,type:e.type}))})}case O9.Developer:{let n=e;return M9(j9({},t),{content:n.content,role:n.role})}case O9.Guide:{let n=e;return M9(j9({},t),{content:n.content,role:n.role})}case O9.Hidden:{let n=e;return M9(j9({},t),{content:n.content,role:n.role})}case O9.HiddenAssistant:{let n=e;return M9(j9({},t),{content:n.content,role:n.role})}case O9.HiddenGuide:{let n=e;return M9(j9({},t),{content:n.content,role:n.role})}case O9.HiddenSystem:{let n=e;return M9(j9({},t),{content:n.content,role:n.role})}case O9.HiddenUser:{let n=e;return M9(j9({},t),{content:n.content,role:n.role})}case O9.Info:{let n=e;return M9(j9({},t),{content:n.content,role:n.role})}case O9.Pause:{let n=e;return M9(j9({},t),{content:n.content,role:n.role})}case O9.Placeholder:{let n=e;return M9(j9({},t),{content:n.content,role:n.role})}case O9.Reasoning:{let n=e;return M9(j9({},t),{content:n.content,duration:n.duration,role:n.role})}case O9.System:{let n=e;return M9(j9({},t),{content:n.content,role:n.role})}case O9.TemplateAssistant:{let n=e;return M9(j9({},t),{content:n.content,role:n.role})}case O9.TemplateGuide:{let n=e;return M9(j9({},t),{content:n.content,role:n.role})}case O9.TemplateHidden:{let n=e;return M9(j9({},t),{content:n.content,role:n.role})}case O9.TemplateSystem:{let n=e;return M9(j9({},t),{content:n.content,role:n.role})}case O9.TemplateUser:{let n=e;return M9(j9({},t),{content:n.content,role:n.role})}case O9.Tool:{let n=e;return M9(j9({},t),{content:n.content,duration:n.duration,error:n.error,role:n.role,tool_call_id:n.toolCallId})}case O9.User:{let n=e,r=n.content;return M9(j9({},t),{content:Array.isArray(r)?r.map(e=>{if(e.type===A9.Binary){let t=e;return{data:t.data,filename:t.filename,id:t.id,mime_type:t.mimeType,type:t.type,url:t.url}}return e}):r,property:n.property,role:n.role})}}},P9=e=>({sessionCode:e.session_code,sessionContentCount:e.session_content_count,sessionName:e.session_name,isTemporary:e.is_temporary,model:e.model,comment:e.comment,labels:e.labels,rate:e.rate,updatedAt:e.updated_at,createdAt:e.created_at,roleInfo:e.role_info?{collectionId:e.role_info.collection_id,collectionName:e.role_info.collection_name,content:e.role_info.content,variables:e.role_info.variables}:void 0,sessionProperty:{isAutoClear:e.session_property?.is_auto_clear,isAutoCalcPrompt:e.session_property?.is_auto_clac_prompt}}),f4t=e=>({session_code:e.sessionCode,session_content_count:e.sessionContentCount,session_name:e.sessionName,is_temporary:e.isTemporary,model:e.model,comment:e.comment,labels:e.labels,rate:e.rate,updated_at:e.updatedAt,created_at:e.createdAt,role_info:e.roleInfo?{collection_id:e.roleInfo.collectionId,collection_name:e.roleInfo.collectionName,content:e.roleInfo.content,variables:e.roleInfo.variables}:void 0,session_property:{is_auto_clear:e.sessionProperty?.isAutoClear,is_auto_clac_prompt:e.sessionProperty?.isAutoCalcPrompt}}),p4t=e=>({session_code:e.sessionCode,session_content_ids:e.sessionContentIds,rate:e.rate,comment:e.comment,labels:e.labels}),m4t=e=>({sessionCode:e.session_code,sessionContentIds:e.session_content_ids,rate:e.rate,comment:e.comment,labels:e.lables});function h4t(e,t,n,r,i,a,o){try{var s=e[a](o),l=s.value}catch(e){n(e);return}s.done?t(l):Promise.resolve(l).then(r,i)}function g4t(e){return function(){var t=this,n=arguments;return new Promise(function(r,i){var a=e.apply(t,n);function o(e){h4t(a,r,i,o,s,`next`,e)}function s(e){h4t(a,r,i,o,s,`throw`,e)}o(void 0)})}}function _4t(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function v4t(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t],r=Object.keys(n);typeof Object.getOwnPropertySymbols==`function`&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){_4t(e,t,n[t])})}return e}function y4t(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function b4t(e,t){return t??={},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):y4t(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}),e}var x4t=()=>`temp_${Date.now()}_${Math.random().toString(36).slice(2,9)}`,S4t=e=>{let t=en([]),n=en(!1),r=en(!1);return{list:t,isListLoading:n,isDeleteLoading:r,getMessages:r=>(n.value=!0,e.http?.message.getMessages(r).then(e=>{t.value=e}).finally(()=>{n.value=!1})),clearMessages:()=>{let n=t.value.map(e=>e.id);return e.http?.message.batchDeleteMessages(n).then(()=>{t.value=[]})},getCurrentLoadingMessage:()=>t.value.findLast(e=>[k9.Pending,k9.Streaming].includes(e.status)),getMessageByMessageId:e=>t.value.find(t=>t.messageId===e),modifyMessage:e=>{t.value=t.value.map(t=>t.messageId===e.messageId?e:t)},plusMessage:e=>{t.value.push(e)},createAndPlusMessage:function(){var n=g4t(function*(n){let r=x4t(),i=b4t(v4t({},n),{id:r,messageId:r});t.value.push(i);try{let i=yield e.http?.message.plusMessage(n);if(i){let e=t.value.findIndex(e=>e.messageId===r);if(e!==-1){let r=v4t({},i,`property`in n&&n.property?{property:n.property}:{});t.value[e]=r}}}catch(e){let n=t.value.findIndex(e=>e.messageId===r);throw n!==-1&&(t.value[n]=b4t(v4t({},t.value[n]),{status:k9.Error})),e}});return function(e){return n.apply(this,arguments)}}(),deleteMessages:function(){var n=g4t(function*(n){let i=n.reduce((e,t)=>(t.role===O9.User&&e.push(t.id),e),[]);if(i.length<=0)return;let a=[...t.value];t.value=t.value.filter(e=>!n.includes(e)),r.value=!0;try{yield e.http?.message.batchDeleteMessages(i)}catch(e){throw t.value=a,e}finally{r.value=!1}});return function(e){return n.apply(this,arguments)}}(),shareMessages:function(){var t=g4t(function*(t,n,r){let i=n.reduce((e,t)=>(t.role===O9.User&&e.push(t.id),e),[]);if(!(i.length<=0))return e.http?.message.shareMessages(t,i,r)});return function(e,n,r){return t.apply(this,arguments)}}(),getFlowAgentTaskInfo:t=>e.http?.message.getFlowAgentTaskInfo(t),getFlowAgentTaskNodeInfo:(t,n)=>e.http?.message.getFlowAgentTaskNodeInfo(t,n),reset:()=>{t.value=[],n.value=!1,r.value=!1}}},F9;(function(e){e.FlowAgentEnd=`flow_agent_end`,e.FlowAgentResult=`flow_agent_result`,e.FlowAgentStart=`flow_agent_start`,e.KnowledgeRagEnd=`knowledge_rag_end`,e.KnowledgeRagResult=`knowledge_rag_result`,e.KnowledgeRagStart=`knowledge_rag_start`,e.KnowledgeRagTextContent=`knowledge_rag_text_content`,e.ReferenceDocument=`reference_document`,e.TempMessage=`temp_message`})(F9||={});var I9;(function(e){e.ActivityDelta=`ACTIVITY_DELTA`,e.ActivitySnapshot=`ACTIVITY_SNAPSHOT`,e.Custom=`CUSTOM`,e.MessagesSnapshot=`MESSAGES_SNAPSHOT`,e.Raw=`RAW`,e.RunError=`RUN_ERROR`,e.RunFinished=`RUN_FINISHED`,e.RunStarted=`RUN_STARTED`,e.StateDelta=`STATE_DELTA`,e.StateSnapshot=`STATE_SNAPSHOT`,e.StepFinished=`STEP_FINISHED`,e.StepStarted=`STEP_STARTED`,e.TextMessageChunk=`TEXT_MESSAGE_CHUNK`,e.TextMessageContent=`TEXT_MESSAGE_CONTENT`,e.TextMessageEnd=`TEXT_MESSAGE_END`,e.TextMessageStart=`TEXT_MESSAGE_START`,e.ThinkingEnd=`THINKING_END`,e.ThinkingStart=`THINKING_START`,e.ThinkingTextMessageContent=`THINKING_TEXT_MESSAGE_CONTENT`,e.ThinkingTextMessageEnd=`THINKING_TEXT_MESSAGE_END`,e.ThinkingTextMessageStart=`THINKING_TEXT_MESSAGE_START`,e.ToolCallArgs=`TOOL_CALL_ARGS`,e.ToolCallChunk=`TOOL_CALL_CHUNK`,e.ToolCallEnd=`TOOL_CALL_END`,e.ToolCallResult=`TOOL_CALL_RESULT`,e.ToolCallStart=`TOOL_CALL_START`})(I9||={});var C4t;(function(e){e.Failed=`failed`,e.Running=`running`,e.Success=`success`,e.Suspended=`suspended`})(C4t||={});var w4t;(function(e){e.Blocked=`BLOCKED`,e.Created=`CREATED`,e.Failed=`FAILED`,e.Finished=`FINISHED`,e.LoopReady=`LOOP_READY`,e.Ready=`READY`,e.Revoked=`REVOKED`,e.RollBackFailed=`ROLL_BACK_FAILED`,e.RollBackSuccess=`ROLL_BACK_SUCCESS`,e.RollingBack=`ROLLING_BACK`,e.Running=`RUNNING`,e.Suspended=`SUSPENDED`})(w4t||={});function L9(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var R9=class{handleActivityDeltaEvent(e){}handleActivitySnapshotEvent(e){}handleCustomEvent(e){switch(e.name){case F9.FlowAgentStart:this.handleFlowAgentStartCustomEvent(e);break;case F9.FlowAgentResult:this.handleFlowAgentResultCustomEvent(e);break;case F9.FlowAgentEnd:this.handleFlowAgentEndCustomEvent(e);break;case F9.ReferenceDocument:this.handleReferenceDocumentCustomEvent(e);break;case F9.KnowledgeRagStart:this.handleKnowledgeRagStartCustomEvent(e);break;case F9.KnowledgeRagTextContent:this.handleKnowledgeRagTextContentCustomEvent(e);break;case F9.KnowledgeRagResult:this.handleKnowledgeRagResultCustomEvent(e);break;case F9.KnowledgeRagEnd:this.handleKnowledgeRagEndCustomEvent(e);break;case F9.TempMessage:this.handleTempMessageCustomEvent(e);break;default:break}}handleFlowAgentEndCustomEvent(e){let t=this.messageModule.getCurrentLoadingMessage();if(t&&t.role===O9.Activity&&t.activityType===D9.FlowAgent){let n=e.value;t.content.task_outputs=n.task_outputs,t.status=k9.Complete}}handleFlowAgentResultCustomEvent(e){let t=this.messageModule.getCurrentLoadingMessage();t&&t.role===O9.Activity&&t.activityType===D9.FlowAgent&&(t.content=e.value)}handleFlowAgentStartCustomEvent(e){let t=e.value;this.messageModule.plusMessage({role:O9.Activity,activityType:D9.FlowAgent,content:{nodes:{},task_id:Number(t.task_id),task_name:``,task_outputs:[],task_state:w4t.Created},status:k9.Streaming})}handleKnowledgeRagEndCustomEvent(e){let t=this.messageModule.getCurrentLoadingMessage();t&&t.role===O9.Activity&&t.activityType===D9.KnowledgeRag&&(t.status=k9.Complete)}handleKnowledgeRagResultCustomEvent(e){let t=this.messageModule.getCurrentLoadingMessage();t&&t.role===O9.Activity&&t.activityType===D9.KnowledgeRag&&(t.content.referenceDocument=e.value)}handleKnowledgeRagStartCustomEvent(e){this.messageModule.plusMessage({role:O9.Activity,activityType:D9.KnowledgeRag,content:{content:``,referenceDocument:[]},status:k9.Streaming})}handleKnowledgeRagTextContentCustomEvent(e){let t=this.messageModule.getCurrentLoadingMessage();if(t&&t.role===O9.Activity&&t.activityType===D9.KnowledgeRag){let n=e.value;t.content.content=n.cover?n.chunk.content:t.content.content+n.chunk.content}}handleMessagesSnapshotEvent(e){e.messages&&e.messages.length>0&&(this.messageModule.list.value=e.messages.map(N9))}handleRawEvent(e){}handleReferenceDocumentCustomEvent(e){this.messageModule.plusMessage({role:O9.Activity,activityType:D9.ReferenceDocument,content:e.value,status:k9.Complete})}handleRunErrorEvent(e){let t=this.messageModule.getCurrentLoadingMessage();t&&(t.status=k9.Complete),this.messageModule.plusMessage({role:O9.Assistant,content:e.message,status:k9.Error})}handleRunFinishedEvent(e){let t=this.messageModule.getCurrentLoadingMessage();t&&(t.status=k9.Complete)}handleRunStartedEvent(e){}handleStateDeltaEvent(e){}handleStateSnapshotEvent(e){}handleStepFinishedEvent(e){}handleStepStartedEvent(e){}handleTempMessageCustomEvent(e){let t=e.value;this.messageModule.plusMessage({role:O9.Assistant,content:t.message,status:t.status})}handleTextMessageChunkEvent(e){let t=this.messageModule.getCurrentLoadingMessage();t?t.content+=e.delta||``:this.messageModule.plusMessage({role:e.role,content:e.delta||``,status:k9.Complete,messageId:e.messageId})}handleTextMessageContentEvent(e){let t=this.messageModule.getMessageByMessageId(e.messageId);t&&(t.content+=e.delta)}handleTextMessageEndEvent(e){let t=this.messageModule.getMessageByMessageId(e.messageId);t&&(t.status=k9.Complete)}handleTextMessageStartEvent(e){this.messageModule.plusMessage({role:e.role,content:``,status:k9.Streaming,messageId:e.messageId})}handleThinkingEndEvent(e){let t=this.messageModule.getCurrentLoadingMessage();t&&t.role===O9.Reasoning&&(t.duration=e.duration,t.status=k9.Complete)}handleThinkingStartEvent(e){this.messageModule.plusMessage({role:O9.Reasoning,content:[],status:k9.Streaming})}handleThinkingTextMessageContentEvent(e){let t=this.messageModule.getCurrentLoadingMessage();t&&t.role===O9.Reasoning&&(t.content[t.content.length-1]+=e.delta)}handleThinkingTextMessageEndEvent(e){}handleThinkingTextMessageStartEvent(e){let t=this.messageModule.getCurrentLoadingMessage();t&&t.role===O9.Reasoning&&t.content.push(``)}handleToolCallArgsEvent(e){this.messageModule.list.value.forEach(t=>{t.role===O9.Assistant&&t.toolCalls&&t.toolCalls.forEach(t=>{t.id===e.toolCallId&&(t.function.arguments+=e.delta)})})}handleToolCallChunkEvent(e){}handleToolCallEndEvent(e){this.messageModule.list.value.forEach(t=>{t.role===O9.Assistant&&t.toolCalls&&t.toolCalls.some(t=>t.id===e.toolCallId)&&(t.status=k9.Complete)})}handleToolCallResultEvent(e){this.messageModule.plusMessage({role:O9.Tool,content:e.content,duration:e.duration,status:k9.Complete,toolCallId:e.toolCallId,messageId:e.messageId})}handleToolCallStartEvent(e){this.messageModule.plusMessage({role:O9.Assistant,content:``,status:k9.Streaming,toolCalls:[{id:e.toolCallId,type:A9.Function,function:{mcpName:e.mcpName,name:e.toolCallName,arguments:``,description:e.description}}]})}injectMessageModule(e){this.messageModule=e}onDone(){var e,t;(e=(t=this).onDoneCallback)==null||e.call(t)}onError(e){var t,n;this.messageModule.plusMessage({role:O9.Assistant,content:e.message,status:k9.Error}),(t=(n=this).onErrorCallback)==null||t.call(n,e)}onMessage(e){var t,n;let r=e;switch((t=(n=this).onMessageCallback)==null||t.call(n,r),r.type){case I9.ActivityDelta:this.handleActivityDeltaEvent(r);break;case I9.ActivitySnapshot:this.handleActivitySnapshotEvent(r);break;case I9.Custom:this.handleCustomEvent(r);break;case I9.MessagesSnapshot:this.handleMessagesSnapshotEvent(r);break;case I9.Raw:this.handleRawEvent(r);break;case I9.RunError:this.handleRunErrorEvent(r);break;case I9.RunFinished:this.handleRunFinishedEvent(r);break;case I9.RunStarted:this.handleRunStartedEvent(r);break;case I9.StateDelta:this.handleStateDeltaEvent(r);break;case I9.StateSnapshot:this.handleStateSnapshotEvent(r);break;case I9.StepFinished:this.handleStepFinishedEvent(r);break;case I9.StepStarted:this.handleStepStartedEvent(r);break;case I9.TextMessageChunk:this.handleTextMessageChunkEvent(r);break;case I9.TextMessageContent:this.handleTextMessageContentEvent(r);break;case I9.TextMessageEnd:this.handleTextMessageEndEvent(r);break;case I9.TextMessageStart:this.handleTextMessageStartEvent(r);break;case I9.ThinkingEnd:this.handleThinkingEndEvent(r);break;case I9.ThinkingStart:this.handleThinkingStartEvent(r);break;case I9.ThinkingTextMessageContent:this.handleThinkingTextMessageContentEvent(r);break;case I9.ThinkingTextMessageEnd:this.handleThinkingTextMessageEndEvent(r);break;case I9.ThinkingTextMessageStart:this.handleThinkingTextMessageStartEvent(r);break;case I9.ToolCallArgs:this.handleToolCallArgsEvent(r);break;case I9.ToolCallChunk:this.handleToolCallChunkEvent(r);break;case I9.ToolCallEnd:this.handleToolCallEndEvent(r);break;case I9.ToolCallResult:this.handleToolCallResultEvent(r);break;case I9.ToolCallStart:this.handleToolCallStartEvent(r);break;default:break}}onStart(){var e,t;(e=(t=this).onStartCallback)==null||e.call(t)}constructor(e){L9(this,`messageModule`,void 0),L9(this,`onDoneCallback`,void 0),L9(this,`onErrorCallback`,void 0),L9(this,`onMessageCallback`,void 0),L9(this,`onStartCallback`,void 0),this.onDoneCallback=e?.onDone,this.onErrorCallback=e?.onError,this.onMessageCallback=e?.onMessage,this.onStartCallback=e?.onStart}};function T4t(e,t,n,r,i,a,o){try{var s=e[a](o),l=s.value}catch(e){n(e);return}s.done?t(l):Promise.resolve(l).then(r,i)}function z9(e){return function(){var t=this,n=arguments;return new Promise(function(r,i){var a=e.apply(t,n);function o(e){T4t(a,r,i,o,s,`next`,e)}function s(e){T4t(a,r,i,o,s,`throw`,e)}o(void 0)})}}function E4t(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function D4t(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t],r=Object.keys(n);typeof Object.getOwnPropertySymbols==`function`&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){E4t(e,t,n[t])})}return e}var O4t=(e,t)=>{let n=en(null),r=en(!1),i=en(!1),a=t||new R9,o=null,s=()=>(r.value=!0,e.http?.agent.getAgentInfo().then(e=>{n.value=e}).finally(()=>{r.value=!1})),l=(t,n)=>{let r=t.promptSetting?.content?.at(-1);if(r?.role===O9.Pause){var i;(i=e.message)==null||i.createAndPlusMessage({role:O9.Assistant,content:r.content,status:k9.Complete,sessionCode:n,property:{extra:{pause:!0}}})}},u=function(){var t=z9(function*(t,n,r){var s;a instanceof R9&&a.injectMessageModule(e.message),o=new AbortController,(s=e.http)==null||s.fetchClient.streamRequest(D4t({url:n||`chat_completion/`,method:`POST`,data:{session_code:t},controller:o,onDone:()=>{var e;i.value=!1,(e=a.onDone)==null||e.call(a)},onError:e=>{var t;i.value=!1,(t=a.onError)==null||t.call(a,e)},onMessage:e=>{var t;(t=a.onMessage)==null||t.call(a,e)},onStart:()=>{var e;i.value=!0,(e=a.onStart)==null||e.call(a)}},r))});return function(e,n,r){return t.apply(this,arguments)}}(),d=function(){var t=z9(function*(t,n,r,i,a){yield e.message?.createAndPlusMessage(D4t({role:O9.User,content:t,status:k9.Complete,sessionCode:n},a&&{property:a})),u(n,r,i)});return function(e,n,r,i,a){return t.apply(this,arguments)}}(),f=(t,n,r)=>{let i=e.message?.list.value.at(-1);(i?.status===k9.Streaming||i?.role===O9.User)&&u(t,n,r)},p=()=>{var e;o==null||(e=o.abort)==null||e.call(o),o=null},m=function(){var t=z9(function*(t){return e.http.message?.stopChat(t)});return function(e){return t.apply(this,arguments)}}();return{info:n,isInfoLoading:r,isChatting:i,chat:d,handleRole:l,resendMessage:function(){var t=z9(function*(t,n,r,i,a){let o=e.message?.list.value||[],s=o.findIndex(e=>String(e.id)===t);if(s===-1)throw Error(`Message not found: ${t}`);let l=o[s];if(l.role!==O9.User)throw Error(`Can only resend user messages`);let d=l.content,f=l.property,p=r??d,m=o.slice(s),h=e.message?.deleteMessages(m),g=e.message?.createAndPlusMessage(D4t({role:O9.User,content:p,status:k9.Complete,sessionCode:n},f&&{property:f}));u(n,i,a),Promise.all([h,g]).catch(e=>{console.error(`[resendMessage] API error:`,e)})});return function(e,n,r,i,a){return t.apply(this,arguments)}}(),resumeStreamingChat:f,abortChat:p,stopChat:m,getAgentInfo:s,reset:e=>{a=e||new R9,n.value=null,r.value=!1}}};function k4t(e,t,n,r,i,a,o){try{var s=e[a](o),l=s.value}catch(e){n(e);return}s.done?t(l):Promise.resolve(l).then(r,i)}function A4t(e){return function(){var t=this,n=arguments;return new Promise(function(r,i){var a=e.apply(t,n);function o(e){k4t(a,r,i,o,s,`next`,e)}function s(e){k4t(a,r,i,o,s,`throw`,e)}o(void 0)})}}function B9(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function V9(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t],r=Object.keys(n);typeof Object.getOwnPropertySymbols==`function`&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){B9(e,t,n[t])})}return e}function j4t(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function H9(e,t){return t??={},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):j4t(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}),e}var M4t=class{clear(){this.handlers=[]}eject(e){this.handlers[e]&&(this.handlers[e]=null)}forEach(e){this.handlers.forEach(t=>{t!==null&&e(t)})}use(e,t){return this.handlers.push({fulfilled:e,rejected:t}),this.handlers.length-1}constructor(){B9(this,`handlers`,[])}},N4t=class e{applyResponseErrorInterceptors(e){let t=e;return this.interceptors.response.forEach(e=>{e.rejected&&(t=e.rejected(t))}),t}create(t){return new e(W9(this.defaults,t||{}))}delete(e,t,n){return this.request(H9(V9({},n),{url:e,method:`DELETE`,params:t}))}get(e,t,n){return this.request(H9(V9({},n),{url:e,method:`GET`,params:t}))}head(e,t,n){return this.request(H9(V9({},n),{url:e,method:`HEAD`,params:t}))}options(e,t,n){return this.request(H9(V9({},n),{url:e,method:`OPTIONS`,params:t}))}patch(e,t,n){return this.request(H9(V9({},n),{url:e,method:`PATCH`,data:t}))}post(e,t,n){return this.request(H9(V9({},n),{url:e,method:`POST`,data:t}))}prepareRequest(e,t=!1){let n=W9(this.defaults,e);this.interceptors.request.forEach(e=>{if(e.fulfilled)try{n=e.fulfilled(n)}catch(t){throw e.rejected?e.rejected(t):t}});let r=n.url||``;n.baseURL&&!r.startsWith(`http`)&&(r=n.baseURL+r),r=P4t(r,n.params);let i=F4t(n.data),a=new Headers(F4t(n.headers));t&&!a.has(`Accept`)&&a.set(`Accept`,`text/event-stream`),i!=null&&(n.transformRequest?i=n.transformRequest(i,F4t(n.headers)):a.get(`Content-Type`)?.includes(`application/json`)&&typeof i==`object`&&!(i instanceof FormData)&&!(i instanceof Blob)&&!(i instanceof ArrayBuffer)&&(i=JSON.stringify(i)));let o=n.controller?n.controller:new AbortController,s={method:n.method,credentials:n.credentials,mode:n.mode,headers:a,body:i,signal:o.signal};return{url:r,requestConfig:n,fetchConfig:s,controller:o}}put(e,t,n){return this.request(H9(V9({},n),{url:e,method:`PUT`,data:t}))}request(e){var t=this;return A4t(function*(){let{url:n,fetchConfig:r,requestConfig:i,controller:a}=t.prepareRequest(e),o=i.timeout&&i.timeout>0?setTimeout(()=>a.abort(),i.timeout):void 0;try{let e=yield fetch(n,r);o&&clearTimeout(o);let a,s=i.responseType||`json`;try{switch(s){case`json`:a=yield e.json();break;case`text`:a=yield e.text();break;case`blob`:a=yield e.blob();break;case`arrayBuffer`:a=yield e.arrayBuffer();break;case`formData`:a=yield e.formData();break;default:a=yield e.json()}}catch{a=null}i.transformResponse&&(a=i.transformResponse(a));let l={data:a,status:e.status,statusText:e.statusText,headers:e.headers,config:i};if(!(i.validateStatus||t.defaults.validateStatus)(e.status))throw U9(l.data?.error?.message||`Request failed with status code ${e.status}`,i,`ERR_BAD_RESPONSE`,l);let u=l;t.interceptors.response.forEach(e=>{if(e.fulfilled)try{u=e.fulfilled(u)}catch(t){throw e.rejected?e.rejected(t):t}}),u instanceof Promise&&(u=yield u);let d=u.data;if(![0,`success`].includes(d.code))throw U9(d.message,i,d.code,u);return d.data}catch(e){if(o&&clearTimeout(o),e instanceof Error&&e.name===`AbortError`){let e=U9(`Request timeout`,i,`ECONNABORTED`,void 0);throw t.applyResponseErrorInterceptors(e)}let n=e.isAxiosError===!0?e:U9(e.message,i,e.code,void 0);throw t.applyResponseErrorInterceptors(n)}})()}stream(e,t){return this.streamRequest(H9(V9({},t),{url:e}))}streamRequest(e){var t=this;return A4t(function*(){let{url:n,fetchConfig:r,requestConfig:i}=t.prepareRequest(e,!0);try{var a;let u=yield fetch(n,r);if(!(i.validateStatus||t.defaults.validateStatus)(u.status)){var o;let t=`Request failed with status code ${u.status}`;try{let e=yield u.json();e!=null&&e.error?.message&&(t=e.error.message)}catch{t=`Request failed with status code ${u.status}`}let n=U9(t,i,`ERR_BAD_RESPONSE`,void 0);(o=e.onError)==null||o.call(e,n);return}(a=e.onStart)==null||a.call(e);let d=u.body?.pipeThrough(new window.TextDecoderStream).getReader();if(!d){var s;let t=Error(`IResponse body is not readable`);(s=e.onError)==null||s.call(e,t);return}let f=``,p=e=>{try{return JSON.parse(e),!0}catch{return!1}};for(;;){let{value:t,done:n}=yield d.read();if(n){var l;(l=e.onDone)==null||l.call(e);break}(f+t.toString()).split(`
3038
- `).forEach(t=>{let n=t.replace(`data:`,``).trim();if(p(n)){var r;let t=JSON.parse(n);(r=e.onMessage)==null||r.call(e,t),f=``}else n&&(f=n)})}}catch(t){if(t instanceof Error)if(t.name===`AbortError`){var u;(u=e.onDone)==null||u.call(e)}else{var d;(d=e.onError)==null||d.call(e,t)}throw t}})()}constructor(e={}){B9(this,`defaults`,void 0),B9(this,`interceptors`,void 0),this.defaults=W9({method:`GET`,headers:{"Content-Type":`application/json`},timeout:3e4,responseType:`json`,credentials:`include`,mode:`cors`,validateStatus:e=>e>=200&&e<300},e),this.interceptors={request:new M4t,response:new M4t}}};function P4t(e,t){if(!t)return e;let n=new URLSearchParams;Object.keys(t).forEach(e=>{let r=t[e];r!=null&&(Array.isArray(r)?r.forEach(t=>n.append(e,String(t))):n.append(e,String(r)))});let r=n.toString();return r?`${e}${e.includes(`?`)?`&`:`?`}${r}`:e}function U9(e,t,n,r){let i=Error(e);return i.config=t,i.code=String(n),i.response=r,i.isAxiosError=!0,i}function F4t(e){return typeof e==`function`?e():e}function I4t(e){if(!e||typeof e!=`object`)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function W9(e,t){let n=V9({},e);for(let r in t){let i=t[r];if(I4t(i)){let t=e[r];n[r]=W9(t||{},i)}else n[r]=i}return n}new N4t;var L4t=e=>{let t=new N4t({baseURL:e.requestData.urlPrefix});return e.interceptors?.request&&t.interceptors.request.use(e.interceptors.request),e.interceptors?.response&&t.interceptors.response.use(e.interceptors.response),{fetchClient:t,reset:e=>{t.defaults.baseURL=e.requestData.urlPrefix,t.interceptors.request.clear(),t.interceptors.response.clear(),e.interceptors?.request&&t.interceptors.request.use(e.interceptors.request),e.interceptors?.response&&t.interceptors.response.use(e.interceptors.response)}}},R4t=e=>({getAgentInfo:t=>e.get(`agent/info/`,void 0,t).then(c4t)});function z4t(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function B4t(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t],r=Object.keys(n);typeof Object.getOwnPropertySymbols==`function`&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){z4t(e,t,n[t])})}return e}var V4t=e=>({getMessages:(t,n,r)=>e.get(`session_content/content/`,{session_code:t,limit:n},r).then(e=>e.map(N9)),plusMessage:(t,n)=>e.post(`session_content/`,d4t(t),n).then(N9),modifyMessage:(t,n)=>e.put(`session_content/${t.id}/`,d4t(t),n).then(N9),deleteMessage:(t,n)=>e.delete(`session_content/${t}/`,void 0,n),batchDeleteMessages:(t,n)=>e.post(`session_content/batch_delete/`,{ids:t},n),shareMessages:(t,n,r,i)=>e.post(`share/`,B4t({session_code:t,content_ids:n},r?{expired_at:r}:{}),i),stopChat:(t,n)=>e.post(`session_content/stop/`,{session_code:t},n),getFlowAgentTaskInfo:(t,n)=>e.get(`flow_agent/${t}/task_info/`,void 0,n),getFlowAgentTaskNodeInfo:(t,n,r)=>e.get(`flow_agent/${t}/task_node_info/${n}/`,void 0,r)});function H4t(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function U4t(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t],r=Object.keys(n);typeof Object.getOwnPropertySymbols==`function`&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){H4t(e,t,n[t])})}return e}function W4t(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function G4t(e,t){return t??={},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):W4t(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}),e}var K4t=e=>({clearSession:(t,n)=>e.post(`chat_completion/${t}/clear/`,void 0,n),getSessions:t=>e.get(`session/`,void 0,t).then(e=>e.map(P9)),plusSession:(t,n)=>e.post(`session/`,f4t(t),n).then(e=>P9(e)),modifySession:(t,n)=>e.put(`session/${t.sessionCode}/`,f4t(t),n).then(e=>P9(e)),deleteSession:(t,n)=>e.delete(`session/${t}/`,void 0,n),batchDeleteSessions:(t,n)=>e.post(`session/batch_delete/`,{session_codes:t},n),getSession:(t,n)=>e.get(`session/${t}/`,void 0,n).then(e=>P9(e)),postSessionFeedback:(t,n)=>e.post(`session_feedback/`,p4t(t),n).then(e=>m4t(e)),getSessionFeedbackReasons:(t,n)=>e.get(`session_feedback/reasons/`,{rate:t},n),renameSession:(t,n)=>e.post(`session/${t}/ai_rename/`,void 0,n).then(e=>P9(e)),uploadFile:(t,n,r)=>{let i=encodeURIComponent(n.name);return n.arrayBuffer().then(a=>e.post(`session/${t}/upload/${i}/`,a,G4t(U4t({},r),{headers:{"Content-Disposition":`attachment; filename="${n.name}"`}})))}}),q4t=e=>({agent:R4t(e),session:K4t(e),message:V4t(e),fetchClient:e});function J4t(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Y4t(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t],r=Object.keys(n);typeof Object.getOwnPropertySymbols==`function`&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){J4t(e,t,n[t])})}return e}function X4t(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function Z4t(e,t){return t??={},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):X4t(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}),e}var Q4t=e=>{let{fetchClient:t,reset:n}=L4t(e);return Z4t(Y4t({},q4t(t)),{reset:n})},$4t=()=>({agent:null,http:null,message:null,session:null,registerAgent(e){this.agent=e},registerHttp(e){this.http=e},registerMessage(e){this.message=e},registerSession(e){this.session=e}});function e3t(e,t,n,r,i,a,o){try{var s=e[a](o),l=s.value}catch(e){n(e);return}s.done?t(l):Promise.resolve(l).then(r,i)}function G9(e){return function(){var t=this,n=arguments;return new Promise(function(r,i){var a=e.apply(t,n);function o(e){e3t(a,r,i,o,s,`next`,e)}function s(e){e3t(a,r,i,o,s,`throw`,e)}o(void 0)})}}function t3t(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function n3t(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t],r=Object.keys(n);typeof Object.getOwnPropertySymbols==`function`&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){t3t(e,t,n[t])})}return e}var r3t=e=>{let t=en([]),n=en(null),r=en(!1),i=en(!1),a=en(!1),o=en(!1),s=en(!1),l=en(!1),u=en(!1),d=e=>{t.value=t.value.map(t=>t.sessionCode===e.sessionCode?n3t({},t,e):t),n.value?.sessionCode===e.sessionCode&&(n.value=t.value.find(t=>t.sessionCode===e.sessionCode)??n.value)},f=()=>(i.value=!0,e.http?.session.getSessions().then(e=>{t.value=e}).finally(()=>{i.value=!1})),p=function(){var r=G9(function*(r,i){var a;if((a=e.agent)==null||a.abortChat(),n.value=t.value.find(e=>e.sessionCode===r)??null,i?.loadMessages!==!1){var o;yield e.message?.getMessages(r),(o=e.agent)==null||o.resumeStreamingChat(r)}else e.message&&(e.message.list.value=[])});return function(e,t){return r.apply(this,arguments)}}();return{list:t,current:n,isCurrentLoading:r,isListLoading:i,isCreateLoading:a,isUpdateLoading:o,isDeleteLoading:s,isBatchDeleteLoading:l,getSessions:f,chooseSession:p,getSession:t=>(r.value=!0,e.http?.session.getSession(t).then(e=>{n.value=e}).finally(()=>{r.value=!1})),createSession:function(){var n=G9(function*(n,r){a.value=!0;try{let i=yield e.http?.session.plusSession(n);i&&(t.value.unshift(i),yield p(i.sessionCode,{loadMessages:r?.loadMessages??!1}))}finally{a.value=!1}});return function(e,t){return n.apply(this,arguments)}}(),updateSession:t=>(o.value=!0,e.http?.session.modifySession(t).then(e=>{d(e)}).finally(()=>{o.value=!1})),deleteSession:function(){var r=G9(function*(r){s.value=!0;try{yield e.http?.session.deleteSession(r),t.value=t.value.filter(e=>e.sessionCode!==r),n.value?.sessionCode===r&&t.value[0]?.sessionCode&&(yield p(t.value[0].sessionCode))}finally{s.value=!1}});return function(e){return r.apply(this,arguments)}}(),batchDeleteSessions:function(){var r=G9(function*(r){if(r.length!==0){l.value=!0;try{yield e.http?.session.batchDeleteSessions(r);let i=new Set(r);t.value=t.value.filter(e=>!i.has(e.sessionCode)),n.value&&i.has(n.value.sessionCode)&&(t.value.length>0?yield p(t.value[0].sessionCode):(n.value=null,e.message&&(e.message.list.value=[])))}finally{l.value=!1}}});return function(e){return r.apply(this,arguments)}}(),postSessionFeedback:t=>e.http?.session.postSessionFeedback(t),getSessionFeedbackReasons:t=>e.http?.session.getSessionFeedbackReasons(t),renameSession:t=>(u.value=!0,e.http?.session.renameSession(t).then(e=>{d({sessionCode:e.sessionCode,sessionName:e.sessionName})}).finally(()=>{u.value=!1})),uploadFile:(t,n)=>e.http?.session.uploadFile(t,n),reset:()=>{t.value=[],n.value=null,r.value=!1,i.value=!1,a.value=!1,o.value=!1,s.value=!1,l.value=!1,u.value=!1}}},i3t=e=>{let t=$4t(),n=Q4t(e),r=O4t(t,e.protocol),i=S4t(t),a=r3t(t);return t.registerHttp(n),t.registerMessage(i),t.registerAgent(r),t.registerSession(a),{agent:r,session:a,message:i,http:n,reset:e=>{n.reset(e),r.reset(e.protocol),i.reset(),a.reset()}}},a3t=class{_isGenerating;_isStopLoading;agentModule;config;eventEmitter;messageModule;sessionModule;autoRenameSessionIfNeeded(e){this.sessionModule&&this.messageModule.list.value.length===1&&this.sessionModule.renameSession(e).catch(e=>{console.error(`[ChatBusinessManager] Auto rename session failed:`,e)})}emit(e,t){this.eventEmitter?.emit(e,t)}constructor(e,t,n=null,r=null,i={}){this.agentModule=e,this.messageModule=t,this.sessionModule=n,this.eventEmitter=r,this.config=i,this._isGenerating=en(!1),this._isStopLoading=en(!1)}get isGenerating(){return this._isGenerating}get isStopLoading(){return this._isStopLoading}get isMessagesLoading(){return this.messageModule.isListLoading}get messages(){return this.messageModule.list}get openingRemark(){return this.config.openingRemark||``}get predefinedQuestions(){return this.config.predefinedQuestions||[]}async batchDeleteMessages(e){try{await this.messageModule.deleteMessages(e);let t=e.map(e=>e.id).filter(Boolean);this.emit(`messages-batch-deleted`,{messageIds:t})}catch(e){throw console.error(`Failed to batch delete messages:`,e),this.emit(`chat-error`,{action:`batch-delete-messages`,error:e}),e}}async deleteMessage(e){try{await this.messageModule.deleteMessages([e]),this.emit(`message-deleted`,{messageId:e.id})}catch(e){throw console.error(`Failed to delete message:`,e),this.emit(`chat-error`,{action:`delete-message`,error:e}),e}}handleStreamEnd(){this._isGenerating.value=!1,this.emit(`receive-end`,{})}handleStreamError(e){this._isGenerating.value=!1,this.emit(`receive-error`,{error:e})}handleStreamStart(){this._isGenerating.value=!0,this.emit(`receive-start`,{})}async regenerateFromAIMessages(e,t){try{if(!e||e.length===0)throw Error(`No AI messages provided`);let n=this.messages.value,r=v0t(n,e[0]);if(!r)throw Error(`No user message found before AI messages`);let i=r.id;if(i===void 0)throw Error(`User message has no id`);await this.regenerateMessage(String(i),t)}catch(e){throw console.error(`Failed to regenerate from AI messages:`,e),this.emit(`chat-error`,{action:`regenerate`,error:e}),e}}async regenerateMessage(e,t){try{let n=this.messages.value,r=n.findIndex(t=>String(t.id)===e);if(r===-1)throw Error(`Message not found: ${e}`);let i=n[r];if(i.role!==O9.User)throw Error(`Can only regenerate from user messages`);let a=n.slice(r),o=typeof i.content==`string`?i.content:JSON.stringify(i.content),s=i.property;this._isGenerating.value=!0;let l=this.messageModule.deleteMessages(a);this.agentModule.chat(o,t,void 0,void 0,s),this.emit(`chat-regenerate`,{messageId:e}),l.catch(e=>{console.error(`[regenerateMessage] Delete API error:`,e)})}catch(e){throw console.error(`Failed to regenerate message:`,e),this._isGenerating.value=!1,this.emit(`chat-error`,{action:`regenerate`,error:e}),e}}async resendMessageWithProperty(e,t,n,r){try{let i=this.messages.value,a=i.findIndex(t=>String(t.id)===e);if(a===-1)throw Error(`Message not found: ${e}`);if(i[a].role!==O9.User)throw Error(`Can only resend user messages`);let o=i.slice(a);this._isGenerating.value=!0;let s=this.messageModule.deleteMessages(o);this.agentModule.chat(n,t,void 0,void 0,r),this.emit(`chat-resend`,{messageId:e}),s.catch(e=>{console.error(`[resendMessageWithProperty] Delete API error:`,e)})}catch(e){throw console.error(`Failed to resend message with property:`,e),this._isGenerating.value=!1,this.emit(`chat-error`,{action:`resend`,error:e}),e}}async retryMessage(e){try{console.warn(`retryMessage not implemented yet`),this.emit(`chat-retry`,{messageId:e})}catch(e){throw console.error(`Failed to retry message:`,e),this.emit(`chat-error`,{action:`retry`,error:e}),e}}async sendMessage(e,t,n={}){try{if(!t)throw Error(`No active session. Please create or select a session first.`);this._isGenerating.value=!0,this.emit(`send-message`,{content:e}),await this.agentModule.chat(e,t,void 0,void 0,n.property),this.autoRenameSessionIfNeeded(t)}catch(e){throw console.error(`Failed to send message:`,e),this._isGenerating.value=!1,this.emit(`chat-error`,{action:`send`,error:e}),e}}async stopGeneration(){let e=this.sessionModule?.current?.value?.sessionCode??``;this._isStopLoading.value=!0;try{await this.agentModule.stopChat(e),this._isGenerating.value=!1,this.emit(`stop`,{})}catch(e){console.error(`Failed to stop generation:`,e),this.emit(`chat-error`,{action:`stop`,error:e})}finally{this._isStopLoading.value=!1}}},o3t=class{agentModule;config;eventEmitter;sessionModule;emit(e,t){this.eventEmitter?.emit(e,t)}constructor(e,t=null,n=null,r={}){this.sessionModule=e,this.agentModule=t,this.eventEmitter=n,this.config=r}get currentSession(){return this.sessionModule.current}get isCreateLoading(){return this.sessionModule.isCreateLoading}get isCurrentLoading(){return this.sessionModule.isCurrentLoading}get isDeleteLoading(){return this.sessionModule.isDeleteLoading}get isListLoading(){return this.sessionModule.isListLoading}get isUpdateLoading(){return this.sessionModule.isUpdateLoading}get sessionList(){return this.sessionModule.list}async createNewSession(){return this.createSession({name:`新会话`,sessionCode:`new_session_${Date.now()}`})}async createSession(e={}){if(this.config.enableChatSession===!1)throw Error(`Chat session is disabled`);try{let t={sessionName:e.name||`新会话`,sessionCode:e.sessionCode||`session_${Date.now()}`,isTemporary:e.isTemporary||!1};await this.sessionModule.createSession(t);let n=this.agentModule?.info.value;n&&this.agentModule?.handleRole(n,t.sessionCode),this.emit(`session-created`,{session:this.sessionModule.current.value})}catch(e){throw console.error(`Failed to create session:`,e),this.emit(`session-error`,{action:`create`,error:e}),e}}async deleteSession(e){try{await this.sessionModule.deleteSession(e),this.emit(`session-deleted`,{sessionCode:e})}catch(e){throw console.error(`Failed to delete session:`,e),this.emit(`session-error`,{action:`delete`,error:e}),e}}async getSession(e){try{await this.sessionModule.getSession(e)}catch(e){throw console.error(`Failed to get session:`,e),this.emit(`session-error`,{action:`get`,error:e}),e}}async loadRecentSession(e){try{e?.skipLoadSessions||await this.loadSessions();let t=this.sessionList.value;if(this.config.initialSessionCode){await this.switchSession(this.config.initialSessionCode);return}if(t.length>0){let e=t[0];(e.sessionContentCount??0)>0?await this.createNewSession():await this.switchSession(e.sessionCode,{loadMessages:!1});return}await this.createNewSession()}catch(e){throw console.error(`Failed to load recent session:`,e),e}}async loadSessions(){try{await this.sessionModule.getSessions(),this.emit(`sessions-loaded`,{sessions:this.sessionList.value})}catch(e){throw console.error(`Failed to load sessions:`,e),this.emit(`session-error`,{action:`load`,error:e}),e}}async switchSession(e,t){try{await this.sessionModule.chooseSession(e,t),this.emit(`session-switched`,{session:this.sessionModule.current.value})}catch(e){throw console.error(`Failed to switch session:`,e),this.emit(`session-error`,{action:`switch`,error:e}),e}}async updateSessionName(e,t){try{let n=this.sessionList.value.find(t=>t.sessionCode===e);if(!n)throw Error(`Session not found: ${e}`);await this.sessionModule.updateSession({...n,sessionName:t}),this.emit(`session-updated`,{session:this.sessionModule.current.value})}catch(e){throw console.error(`Failed to update session name:`,e),this.emit(`session-error`,{action:`update`,error:e}),e}}},s3t=class{messageModule;sessionModule;constructor(e,t){this.messageModule=e,this.sessionModule=t}async shareMessages(e){if(e.length===0)throw Error(`No messages to share`);let t=this.sessionModule.current?.value?.sessionCode;if(!t)throw Error(`No active session`);let n=await this.messageModule.shareMessages(t,e);if(!n)throw Error(`Share failed: no result returned`);return{shareUrl:`${n.share_page}share-page/${n.share_token}`,userMessageIds:e.map(e=>String(e.id))}}},c3t=class{_agentShortcuts;_effectiveShortcuts;_propsShortcuts;eventEmitter;emit(e,t){this.eventEmitter?.emit(e,t)}constructor(e=null,t=[]){this._propsShortcuts=en(t),this._agentShortcuts=en([]),this.eventEmitter=e,this._effectiveShortcuts=ii(()=>this._propsShortcuts.value.length>0?this._propsShortcuts.value:this._agentShortcuts.value.length>0?this._agentShortcuts.value:[])}get count(){return this._effectiveShortcuts.value.length}get effectiveShortcuts(){return this._effectiveShortcuts}get hasShortcuts(){return this._effectiveShortcuts.value.length>0}get shortcuts(){return this._effectiveShortcuts}addShortcut(e){this._propsShortcuts.value.push(e)}clear(){this._propsShortcuts.value=[],this._agentShortcuts.value=[]}filterByTextLength(e,t){return!e||e.length>t?[]:this._effectiveShortcuts.value}filterShortcuts(e,t){return t?this._effectiveShortcuts.value.filter(n=>t(n,e)):this._effectiveShortcuts.value}getShortcutById(e){return this._effectiveShortcuts.value.find(t=>t.id===e)}handleShortcutClick(e,t,n=`main`){this.emit(`shortcut-click`,{shortcut:e,selectedText:t,source:n})}limitShortcuts(e){return this._effectiveShortcuts.value.slice(0,e)}removeShortcut(e){this._propsShortcuts.value=this._propsShortcuts.value.filter(t=>t.id!==e)}setAgentShortcuts(e){this._agentShortcuts.value=e}setShortcuts(e){this._propsShortcuts.value=e}},l3t=class{_isCompressed;_isDraggingOrResizing;_nimbusMinimized;_panelVisible;_positionAndSize;cleanupFunctions;config;containerRef=null;debugMode;listeners;onceListeners;constructor(e={}){this.config=e,this.listeners=new Map,this.onceListeners=new Map,this.debugMode=e.debug??!1,this.cleanupFunctions=[],this._panelVisible=en(e.initialPanelVisible??!1),this._nimbusMinimized=en(e.initialNimbusMinimized??!1),this._isDraggingOrResizing=en(!1),this._isCompressed=en(!1),this._positionAndSize=en({x:0,y:0,width:400,height:window.innerHeight})}get container(){return{updatePosition:this.updatePosition.bind(this),updateSize:this.updateSize.bind(this),updatePositionAndSize:this.updatePositionAndSize.bind(this),toggleCompression:this.toggleCompression.bind(this),expandForSidePanel:this.expandForSidePanel.bind(this),collapseSidePanel:this.collapseSidePanel.bind(this),positionAndSize:ii(()=>this.containerRef?.positionAndSize?.value??this._positionAndSize.value),isCompressed:ii(()=>this._isCompressed.value),isSidePanelExpanded:ii(()=>this.containerRef?.isSidePanelExpanded?.value??!1)}}get isCompressed(){return this._isCompressed}get isDraggingOrResizing(){return this._isDraggingOrResizing}get nimbus(){return{minimize:this.minimizeNimbus.bind(this),restore:this.restoreNimbus.bind(this),toggle:this.toggleNimbus.bind(this),isMinimized:ii(()=>this._nimbusMinimized.value)}}get nimbusMinimized(){return this._nimbusMinimized}get panel(){return{show:this.showPanel.bind(this),hide:this.hidePanel.bind(this),toggle:this.togglePanel.bind(this),isVisible:ii(()=>this._panelVisible.value)}}get panelVisible(){return this._panelVisible}get state(){return{panelVisible:this._panelVisible,nimbusMinimized:this._nimbusMinimized,isDraggingOrResizing:this._isDraggingOrResizing,positionAndSize:this._positionAndSize}}collapseSidePanel(){this.containerRef?.collapseSidePanel&&this.containerRef.collapseSidePanel()}destroy(){this.listeners.clear(),this.onceListeners.clear(),this.cleanupFunctions.forEach(e=>e()),this.cleanupFunctions=[],this.debugMode&&console.debug(`[ComponentManager] Destroyed`)}emit(e,t){this.debugMode&&console.debug(`[ComponentManager] Emitting "${e}"`,t);let n=this.listeners.get(e);n&&n.forEach(n=>{try{n(t)}catch(t){console.error(`[ComponentManager] Error in listener for "${e}":`,t)}});let r=this.onceListeners.get(e);if(r&&r.size>0){let n=Array.from(r);this.onceListeners.delete(e),n.forEach(n=>{try{n(t)}catch(t){console.error(`[ComponentManager] Error in once listener for "${e}":`,t)}})}}emitInternal(e,t){this.emit(e,t)}expandForSidePanel(e){this.containerRef?.expandForSidePanel&&this.containerRef.expandForSidePanel(e)}getConfig(){return this.config}getRegisteredEvents(){let e=new Set;return this.listeners.forEach((t,n)=>e.add(n)),this.onceListeners.forEach((t,n)=>e.add(n)),Array.from(e)}handleDragging(e){this._isDraggingOrResizing.value=!0,this._positionAndSize.value=e,this.emit(`dragging`,e)}handleDragStop(e){this._isDraggingOrResizing.value=!1,this._positionAndSize.value=e,this.emit(`drag-stop`,e)}handleNimbusClick(){this.emit(`nimbus-click`,{}),this.showPanel()}handlePopupClick(){this.emit(`popup-click`,{}),this.showPanel()}handlePopupShortcutClick(e){this.emit(`popup-shortcut-click`,{shortcut:e}),this.emit(`shortcut-click`,{shortcut:e,source:`popup`})}handleResizeStop(e){this._isDraggingOrResizing.value=!1,this._positionAndSize.value=e,this.emit(`resize-stop`,e)}handleResizing(e){this._isDraggingOrResizing.value=!0,this._positionAndSize.value=e,this.emit(`resizing`,e)}handleShortcutClick(e,t){this.emit(`shortcut-click`,{shortcut:e,source:t})}hasListeners(e){return this.listenerCount(e)>0}hidePanel(){this._panelVisible.value=!1,this.emit(`panel-hide`,{})}listenerCount(e){return(this.listeners.get(e)?.size??0)+(this.onceListeners.get(e)?.size??0)}minimizeNimbus(){this._nimbusMinimized.value=!0,this.emit(`nimbus-minimize`,{})}off(e,t){t?(this.listeners.get(e)?.delete(t),this.onceListeners.get(e)?.delete(t),this.debugMode&&console.debug(`[ComponentManager] Unsubscribed from "${e}", remaining: ${this.listenerCount(e)}`)):(this.listeners.delete(e),this.onceListeners.delete(e),this.debugMode&&console.debug(`[ComponentManager] Removed all listeners for "${e}"`))}on(e,t){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t),this.debugMode&&console.debug(`[ComponentManager] Subscribed to "${e}", total: ${this.listenerCount(e)}`),()=>{this.off(e,t)}}once(e,t){return this.onceListeners.has(e)||this.onceListeners.set(e,new Set),this.onceListeners.get(e).add(t),this.debugMode&&console.debug(`[ComponentManager] Subscribed once to "${e}"`),()=>{this.onceListeners.get(e)?.delete(t)}}restoreNimbus(){this._nimbusMinimized.value=!1,this.emit(`nimbus-restore`,{})}setCompressed(e){this._isCompressed.value=e}setContainerRef(e){this.containerRef=e,e?.isCompressed&&(this._isCompressed.value=e.isCompressed.value)}setDebugMode(e){this.debugMode=e}setDraggingOrResizing(e){this._isDraggingOrResizing.value=e}showPanel(e){this._panelVisible.value=!0,this.emit(`panel-show`,{sessionCode:e})}toggleCompression(){this.containerRef?this.containerRef.toggleCompression():this._isCompressed.value=!this._isCompressed.value}toggleNimbus(){this._nimbusMinimized.value?this.restoreNimbus():this.minimizeNimbus()}togglePanel(){this._panelVisible.value?this.hidePanel():this.showPanel()}updatePosition(e,t){this._positionAndSize.value={...this._positionAndSize.value,x:e,y:t}}updatePositionAndSize(e,t,n,r){this._positionAndSize.value={x:e,y:t,width:n,height:r}}updateSize(e,t){this._positionAndSize.value={...this._positionAndSize.value,width:e,height:t}}};function u3t(e){return new l3t(e)}var d3t={"panel-show":`show`,"panel-hide":`close`,"panel-toggle":null,"nimbus-click":null,"nimbus-minimize":null,"nimbus-restore":null,"popup-click":null,"popup-shortcut-click":null,dragging:`dragging`,resizing:`resizing`,"drag-stop":`drag-stop`,"resize-stop":`resize-stop`,"compression-toggle":null,"side-panel-expand":null,"side-panel-collapse":null,"send-message":`send-message`,"receive-start":`receive-start`,"receive-text":`receive-text`,"receive-end":`receive-end`,"receive-error":null,stop:`stop`,"chat-regenerate":null,"chat-retry":null,"message-deleted":null,"messages-batch-deleted":null,"session-created":null,"session-switched":null,"session-deleted":null,"session-updated":null,"sessions-loaded":null,"session-initialized":`session-initialized`,"session-error":null,"shortcut-click":`shortcut-click`,"chat-error":null,"sdk-error":`sdk-error`,"new-chat":`new-chat`,"history-click":`history-click`,"auto-generate-name":`auto-generate-name`,"help-click":`help-click`,rename:`rename`,share:`share`,close:`close`,"toggle-compression":null,"transfer-messages":`transfer-messages`,"share-messages":`share-messages`,"agent-info-loaded":null,error:null};function f3t(e,t){switch(e){case`send-message`:return[t.content];case`rename`:return[t.newName];case`history-click`:return[t.event];case`dragging`:case`resizing`:case`drag-stop`:case`resize-stop`:case`shortcut-click`:case`session-initialized`:case`sdk-error`:case`transfer-messages`:case`share-messages`:return[t];case`panel-show`:case`panel-hide`:case`receive-start`:case`receive-text`:case`receive-end`:case`stop`:case`new-chat`:case`auto-generate-name`:case`help-click`:case`share`:case`close`:return[];default:return[t]}}function p3t(e){let{props:t,emit:n,scrollToBottom:r}=e,i=en(!1),a=en(null),o=()=>t.chatHelper?!t.chatHelper.agent||!t.chatHelper.session||!t.chatHelper.message?{valid:!1,error:`[ChatBot] Invalid chatHelper: missing required modules (agent, session, message)`}:{valid:!0}:t.url?{valid:!0}:{valid:!1,error:`[ChatBot] Neither chatHelper nor url provided. Component requires at least one.`},s=(()=>{let e=o();if(!e.valid)return console.error(e.error),a.value=Error(e.error),null;if(t.chatHelper)return t.chatHelper;let i=new R9({onStart:()=>{n(`receive-start`)},onMessage:e=>{n(`receive-text`)},onDone:()=>{n(`receive-end`),r()},onError:e=>{n(`error`,e)}}),s=i3t({requestData:{urlPrefix:S0t(t.url),headers:t.requestOptions?.headers,data:t.requestOptions?.data},protocol:i});return i.injectMessageModule(s.message),s})(),l=!t.chatHelper,u=s?new o3t(s.session,s.agent,null,{enableChatSession:!0,autoSwitchToInitialSession:!!t.sessionCode,loadRecentSessionOnMount:t.autoLoad,initialSessionCode:t.sessionCode}):null,d=s?new a3t(s.agent,s.message,s.session,null,{openingRemark:t.helloText,predefinedQuestions:t.prompts,placeholder:t.placeholder}):null,f=new c3t(null,t.shortcuts||[]);return Jn(async()=>{if(!(!s||a.value))try{if(l){if(await s.agent.getAgentInfo(),await s.session.getSessions(),t.sessionCode)await s.session.chooseSession(t.sessionCode);else if(s.session.list.value.length>0){let e=s.session.list.value[0];await s.session.chooseSession(e.sessionCode)}i.value=!0}else i.value=!0;n(`agent-info-loaded`,s)}catch(e){console.error(`Failed to initialize ChatBot:`,e),a.value=e,n(`error`,e)}}),Yn(()=>{l&&s&&s.agent.stopChat(s.session.current?.value?.sessionCode??``)}),{chatHelper:s,isStandaloneMode:l,isInitialized:i,initError:a,chatBusinessManager:d,sessionBusinessManager:u,shortcutManager:f}}function m3t(e){let{props:t,chatHelper:n,chatBusinessManager:r,sessionBusinessManager:i,shortcutManager:a,isStandaloneMode:o,isInitialized:s,selectedShortcut:l}=e,u=ii(()=>r?.isStopLoading.value?x6.StopLoading:((t.chatHelper||n)?.agent)?.isChatting?.value?x6.Streaming:x6.Complete),d=ii(()=>u.value===x6.Streaming?u5.Disabled:void 0),f=ii(()=>r?.messages.value??[]),p=ii(()=>r?.isMessagesLoading.value??!1);return{messageStatus:u,messageToolsStatus:d,messages:f,isMessagesLoading:p,isGenerating:ii(()=>r?.isGenerating.value??!1),currentSession:ii(()=>i?.currentSession.value??null),isWelcomeState:ii(()=>o&&!s.value?!1:!p.value&&f.value.length===0),openingRemark:ii(()=>n?.agent.info.value?.conversationSettings?.openingRemark||``),effectiveResources:ii(()=>t.resources?.length?t.resources:n?.agent.info.value?.resources??[]),effectivePrompts:ii(()=>t.prompts?.length?t.prompts:n?.agent.info.value?.conversationSettings?.predefinedQuestions??[]),effectiveSupportUpload:ii(()=>l.value?.supportUpload?l.value.supportUpload.vision===!0:n?.agent.info.value?.promptSetting?.supportUpload?.vision===!0),chatbotStyle:ii(()=>({height:typeof t.height==`number`?`${t.height}px`:t.height,maxWidth:typeof t.maxWidth==`number`?`${t.maxWidth}px`:t.maxWidth})),filteredShortcuts:ii(()=>a.shortcuts.value)}}function h3t(e){let{emit:t,chatHelper:n,chatBusinessManager:r,selectedShortcut:i,selectedResources:a}=e,o=tn([[]]),s=tn(``),l=(e,t)=>{o.value=e,a.value=t},u=async(e,i={})=>{if(!r||!n)throw Error(`[ChatBot] Cannot send message: chatBusinessManager not initialized`);let l=n.session.current?.value?.sessionCode;if(!l)throw Error(`[ChatBot] Cannot send message: no active session`);o.value=[[]],s.value=``,a.value=[],t(`send-message`,typeof e==`string`?e:``),await r.sendMessage(e,l,i)},d=async e=>{let t=n?.session.current?.value?.sessionCode;if(!t)throw Error(`[ChatBot] Cannot upload: no active session`);let r=await n.session.uploadFile(t,e);if(!r?.download_url)throw Error(`[ChatBot] Upload failed: no download URL returned`);return r},f=async(e,n)=>{try{let t={};s.value&&(t.cite=s.value),i.value&&(t.command=i.value.id),a.value.length&&(t.resources=a.value),await u(e,Object.keys(t).length?{property:{extra:t}}:{})}catch(e){console.error(`Failed to send message:`,e),t(`error`,e)}},p=async()=>{await m()},m=async()=>{if(!r){console.error(`[ChatBot] Cannot stop generation: chatBusinessManager not initialized`);return}await r.stopGeneration(),t(`stop`)};return{userInput:o,cite:s,handleUpdateModelValue:l,doSendMessage:u,handleSendMessage:f,handleUpload:d,handleStopSending:p,stopGeneration:m}}function g3t(e){let{emit:t,chatHelper:n,isStandaloneMode:r}=e,i=async e=>{if(!(!n||e.length===0))try{await C0t((await new s3t(n.message,n.session).shareMessages(e)).shareUrl),md({message:`分享链接已复制到剪贴板`,theme:`success`})}catch(e){console.error(`[ChatBot] Failed to share messages:`,e),md({message:`分享失败,请重试`,theme:`error`})}};return{handleConfirmShare:async e=>{r&&await i(e),t(`confirm-share`,e)}}}function _3t(e){let{props:t,emit:n,shortcutManager:r,doSendMessage:i,selectedShortcut:a}=e,o=r.effectiveShortcuts,s=(e,t)=>{let n=e,r;if(r=n.enable_fill_back&&n.fill_back_component_key?n.fill_back_component_key:n.components?.find(e=>e.fillBack)?.key,r&&t){let e=n.components?.map(e=>e.key===r?{...e,default:t}:{...e,default:e.default??void 0});a.value={...n,components:e,formModel:{...n.formModel,[r]:t}}}else a.value={...n,formModel:{...n.formModel}}},l=(e,t)=>{let n=e.components||[];return{extra:{cite:{type:`structured`,title:e.alias||e.name,data:n.map(e=>({key:e.name||e.key,value:String(t[e.key]??``)}))},command:e.id,context:n.map(e=>({[e.key]:t[e.key],context_type:e.type,__label:e.name||e.key,__key:e.key,__value:t[e.key]}))}}},u=e=>{let t=e.property?.extra;return t?.shortcut?t.shortcut:t?.command?o.value.find(e=>e.id===t.command)??null:null},d=(e,t)=>{s(e,t),n(`shortcut-click`,{shortcut:e,source:`main`})},f=()=>{a.value=null};return gr(()=>t.shortcuts,e=>{r.setShortcuts(e||[])},{immediate:!0}),gr(()=>e.chatHelper?.agent.info.value?.conversationSettings?.commands,e=>{e&&r.setAgentShortcuts(e)},{immediate:!0}),{effectiveShortcuts:o,selectShortcutWithText:s,buildShortcutProperty:l,getShortcutFromMessage:u,handleSelectShortcut:d,handleCloseShortcut:f,handleShortcutSubmit:async e=>{if(!a.value){console.error(`[ChatBot] No selected shortcut`);return}let t=l(a.value,e),r=a.value.name,o=a.value;f();try{await i(r,{property:t})}catch(e){a.value=o,console.error(`[ChatBot] Failed to submit shortcut:`,e),n(`error`,e)}}}}function v3t(e){let{emit:t,chatHelper:n,chatBusinessManager:r,cite:i,focusInput:a,scrollToBottom:o,getShortcutFromMessage:s,buildShortcutProperty:l}=e,u=async e=>{if(!r||!n){console.error(`[ChatBot] Cannot delete messages: chatBusinessManager not initialized`);return}try{let t=r.messages.value,i=v0t(t,e[0]);if(!i){console.error(`[ChatBot] No user message found before AI messages`);return}let a=[i,...e];await n.message.deleteMessages(a)}catch(e){console.error(`[ChatBot] Failed to delete messages:`,e),t(`error`,e)}},d=async e=>{if(!r||!n){console.error(`[ChatBot] Cannot regenerate: chatBusinessManager not initialized`);return}let i=n.session.current?.value?.sessionCode;if(!i){console.error(`[ChatBot] Cannot regenerate: no active session`);return}try{await r.regenerateFromAIMessages(e,i),o()}catch(e){console.error(`[ChatBot] Failed to regenerate:`,e),t(`error`,e)}},f=async e=>{if(!r||!n){console.error(`[ChatBot] Cannot delete message: chatHelper not initialized`);return}try{let t=r.messages.value,i=t.findIndex(t=>t===e);if(i===-1){console.error(`[ChatBot] User message not found in messages list`);return}let a=[];for(let e=i+1;e<t.length;e++){let n=t[e];if(n.role===b6.User)break;a.push(n)}let o=[e,...a];await n.message.deleteMessages(o)}catch(e){console.error(`[ChatBot] Failed to delete user message:`,e),t(`error`,e)}};return{handleAgentAction:async(e,t)=>{if(e.id===`cite`){i.value=t.filter(e=>e.role!==b6.Reasoning).map(e=>typeof e.content==`string`?e.content:JSON.stringify(e.content||``)).join(`
3038
+ `).forEach(t=>{let n=t.replace(`data:`,``).trim();if(p(n)){var r;let t=JSON.parse(n);(r=e.onMessage)==null||r.call(e,t),f=``}else n&&(f=n)})}}catch(t){if(t instanceof Error)if(t.name===`AbortError`){var u;(u=e.onDone)==null||u.call(e)}else{var d;(d=e.onError)==null||d.call(e,t)}throw t}})()}constructor(e={}){B9(this,`defaults`,void 0),B9(this,`interceptors`,void 0),this.defaults=W9({method:`GET`,headers:{"Content-Type":`application/json`},timeout:3e4,responseType:`json`,credentials:`include`,mode:`cors`,validateStatus:e=>e>=200&&e<300},e),this.interceptors={request:new M4t,response:new M4t}}};function P4t(e,t){if(!t)return e;let n=new URLSearchParams;Object.keys(t).forEach(e=>{let r=t[e];r!=null&&(Array.isArray(r)?r.forEach(t=>n.append(e,String(t))):n.append(e,String(r)))});let r=n.toString();return r?`${e}${e.includes(`?`)?`&`:`?`}${r}`:e}function U9(e,t,n,r){let i=Error(e);return i.config=t,i.code=String(n),i.response=r,i.isAxiosError=!0,i}function F4t(e){return typeof e==`function`?e():e}function I4t(e){if(!e||typeof e!=`object`)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function W9(e,t){let n=V9({},e);for(let r in t){let i=t[r];if(I4t(i)){let t=e[r];n[r]=W9(t||{},i)}else n[r]=i}return n}new N4t;var L4t=e=>{let t=new N4t({baseURL:e.requestData.urlPrefix});return e.interceptors?.request&&t.interceptors.request.use(e.interceptors.request),e.interceptors?.response&&t.interceptors.response.use(e.interceptors.response),{fetchClient:t,reset:e=>{t.defaults.baseURL=e.requestData.urlPrefix,t.interceptors.request.clear(),t.interceptors.response.clear(),e.interceptors?.request&&t.interceptors.request.use(e.interceptors.request),e.interceptors?.response&&t.interceptors.response.use(e.interceptors.response)}}},R4t=e=>({getAgentInfo:t=>e.get(`agent/info/`,void 0,t).then(c4t)});function z4t(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function B4t(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t],r=Object.keys(n);typeof Object.getOwnPropertySymbols==`function`&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){z4t(e,t,n[t])})}return e}var V4t=e=>({getMessages:(t,n,r)=>e.get(`session_content/content/`,{session_code:t,limit:n},r).then(e=>e.map(N9)),plusMessage:(t,n)=>e.post(`session_content/`,d4t(t),n).then(N9),modifyMessage:(t,n)=>e.put(`session_content/${t.id}/`,d4t(t),n).then(N9),deleteMessage:(t,n)=>e.delete(`session_content/${t}/`,void 0,n),batchDeleteMessages:(t,n)=>e.post(`session_content/batch_delete/`,{ids:t},n),shareMessages:(t,n,r,i)=>e.post(`share/`,B4t({session_code:t,content_ids:n},r?{expired_at:r}:{}),i),stopChat:(t,n)=>e.post(`session_content/stop/`,{session_code:t},n),getFlowAgentTaskInfo:(t,n)=>e.get(`flow_agent/${t}/task_info/`,void 0,n),getFlowAgentTaskNodeInfo:(t,n,r)=>e.get(`flow_agent/${t}/task_node_info/${n}/`,void 0,r)});function H4t(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function U4t(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t],r=Object.keys(n);typeof Object.getOwnPropertySymbols==`function`&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){H4t(e,t,n[t])})}return e}function W4t(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function G4t(e,t){return t??={},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):W4t(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}),e}var K4t=e=>({clearSession:(t,n)=>e.post(`chat_completion/${t}/clear/`,void 0,n),getSessions:t=>e.get(`session/`,void 0,t).then(e=>e.map(P9)),plusSession:(t,n)=>e.post(`session/`,f4t(t),n).then(e=>P9(e)),modifySession:(t,n)=>e.put(`session/${t.sessionCode}/`,f4t(t),n).then(e=>P9(e)),deleteSession:(t,n)=>e.delete(`session/${t}/`,void 0,n),batchDeleteSessions:(t,n)=>e.post(`session/batch_delete/`,{session_codes:t},n),getSession:(t,n)=>e.get(`session/${t}/`,void 0,n).then(e=>P9(e)),postSessionFeedback:(t,n)=>e.post(`session_feedback/`,p4t(t),n).then(e=>m4t(e)),getSessionFeedbackReasons:(t,n)=>e.get(`session_feedback/reasons/`,{rate:t},n),renameSession:(t,n)=>e.post(`session/${t}/ai_rename/`,void 0,n).then(e=>P9(e)),uploadFile:(t,n,r)=>{let i=encodeURIComponent(n.name);return n.arrayBuffer().then(a=>e.post(`session/${t}/upload/${i}/`,a,G4t(U4t({},r),{headers:{"Content-Disposition":`attachment; filename="${n.name}"`}})))}}),q4t=e=>({agent:R4t(e),session:K4t(e),message:V4t(e),fetchClient:e});function J4t(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Y4t(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t],r=Object.keys(n);typeof Object.getOwnPropertySymbols==`function`&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){J4t(e,t,n[t])})}return e}function X4t(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function Z4t(e,t){return t??={},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):X4t(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}),e}var Q4t=e=>{let{fetchClient:t,reset:n}=L4t(e);return Z4t(Y4t({},q4t(t)),{reset:n})},$4t=()=>({agent:null,http:null,message:null,session:null,registerAgent(e){this.agent=e},registerHttp(e){this.http=e},registerMessage(e){this.message=e},registerSession(e){this.session=e}});function e3t(e,t,n,r,i,a,o){try{var s=e[a](o),l=s.value}catch(e){n(e);return}s.done?t(l):Promise.resolve(l).then(r,i)}function G9(e){return function(){var t=this,n=arguments;return new Promise(function(r,i){var a=e.apply(t,n);function o(e){e3t(a,r,i,o,s,`next`,e)}function s(e){e3t(a,r,i,o,s,`throw`,e)}o(void 0)})}}function t3t(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function n3t(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t],r=Object.keys(n);typeof Object.getOwnPropertySymbols==`function`&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){t3t(e,t,n[t])})}return e}var r3t=e=>{let t=en([]),n=en(null),r=en(!1),i=en(!1),a=en(!1),o=en(!1),s=en(!1),l=en(!1),u=en(!1),d=e=>{t.value=t.value.map(t=>t.sessionCode===e.sessionCode?n3t({},t,e):t),n.value?.sessionCode===e.sessionCode&&(n.value=t.value.find(t=>t.sessionCode===e.sessionCode)??n.value)},f=()=>(i.value=!0,e.http?.session.getSessions().then(e=>{t.value=e}).finally(()=>{i.value=!1})),p=function(){var r=G9(function*(r,i){var a;if((a=e.agent)==null||a.abortChat(),n.value=t.value.find(e=>e.sessionCode===r)??null,i?.loadMessages!==!1){var o;yield e.message?.getMessages(r),(o=e.agent)==null||o.resumeStreamingChat(r)}else e.message&&(e.message.list.value=[])});return function(e,t){return r.apply(this,arguments)}}();return{list:t,current:n,isCurrentLoading:r,isListLoading:i,isCreateLoading:a,isUpdateLoading:o,isDeleteLoading:s,isBatchDeleteLoading:l,getSessions:f,chooseSession:p,getSession:t=>(r.value=!0,e.http?.session.getSession(t).then(e=>{n.value=e}).finally(()=>{r.value=!1})),createSession:function(){var n=G9(function*(n,r){a.value=!0;try{let i=yield e.http?.session.plusSession(n);i&&(t.value.unshift(i),yield p(i.sessionCode,{loadMessages:r?.loadMessages??!1}))}finally{a.value=!1}});return function(e,t){return n.apply(this,arguments)}}(),updateSession:t=>(o.value=!0,e.http?.session.modifySession(t).then(e=>{d(e)}).finally(()=>{o.value=!1})),deleteSession:function(){var r=G9(function*(r){s.value=!0;try{yield e.http?.session.deleteSession(r),t.value=t.value.filter(e=>e.sessionCode!==r),n.value?.sessionCode===r&&t.value[0]?.sessionCode&&(yield p(t.value[0].sessionCode))}finally{s.value=!1}});return function(e){return r.apply(this,arguments)}}(),batchDeleteSessions:function(){var r=G9(function*(r){if(r.length!==0){l.value=!0;try{yield e.http?.session.batchDeleteSessions(r);let i=new Set(r);t.value=t.value.filter(e=>!i.has(e.sessionCode)),n.value&&i.has(n.value.sessionCode)&&(t.value.length>0?yield p(t.value[0].sessionCode):(n.value=null,e.message&&(e.message.list.value=[])))}finally{l.value=!1}}});return function(e){return r.apply(this,arguments)}}(),postSessionFeedback:t=>e.http?.session.postSessionFeedback(t),getSessionFeedbackReasons:t=>e.http?.session.getSessionFeedbackReasons(t),renameSession:t=>(u.value=!0,e.http?.session.renameSession(t).then(e=>{d({sessionCode:e.sessionCode,sessionName:e.sessionName})}).finally(()=>{u.value=!1})),uploadFile:(t,n)=>e.http?.session.uploadFile(t,n),reset:()=>{t.value=[],n.value=null,r.value=!1,i.value=!1,a.value=!1,o.value=!1,s.value=!1,l.value=!1,u.value=!1}}},i3t=e=>{let t=$4t(),n=Q4t(e),r=O4t(t,e.protocol),i=S4t(t),a=r3t(t);return t.registerHttp(n),t.registerMessage(i),t.registerAgent(r),t.registerSession(a),{agent:r,session:a,message:i,http:n,reset:e=>{n.reset(e),r.reset(e.protocol),i.reset(),a.reset()}}},a3t=class{_isGenerating;_isStopLoading;agentModule;config;eventEmitter;messageModule;sessionModule;autoRenameSessionIfNeeded(e){this.sessionModule&&this.messageModule.list.value.length===1&&this.sessionModule.renameSession(e).catch(e=>{console.error(`[ChatBusinessManager] Auto rename session failed:`,e)})}emit(e,t){this.eventEmitter?.emit(e,t)}constructor(e,t,n=null,r=null,i={}){this.agentModule=e,this.messageModule=t,this.sessionModule=n,this.eventEmitter=r,this.config=i,this._isGenerating=en(!1),this._isStopLoading=en(!1)}get isGenerating(){return this._isGenerating}get isStopLoading(){return this._isStopLoading}get isMessagesLoading(){return this.messageModule.isListLoading}get messages(){return this.messageModule.list}get openingRemark(){return this.config.openingRemark||``}get predefinedQuestions(){return this.config.predefinedQuestions||[]}async batchDeleteMessages(e){try{await this.messageModule.deleteMessages(e);let t=e.map(e=>e.id).filter(Boolean);this.emit(`messages-batch-deleted`,{messageIds:t})}catch(e){throw console.error(`Failed to batch delete messages:`,e),this.emit(`chat-error`,{action:`batch-delete-messages`,error:e}),e}}async deleteMessage(e){try{await this.messageModule.deleteMessages([e]),this.emit(`message-deleted`,{messageId:e.id})}catch(e){throw console.error(`Failed to delete message:`,e),this.emit(`chat-error`,{action:`delete-message`,error:e}),e}}handleStreamEnd(){this._isGenerating.value=!1,this.emit(`receive-end`,{})}handleStreamError(e){this._isGenerating.value=!1,this.emit(`receive-error`,{error:e})}handleStreamStart(){this._isGenerating.value=!0,this.emit(`receive-start`,{})}async regenerateFromAIMessages(e,t){try{if(!e||e.length===0)throw Error(`No AI messages provided`);let n=this.messages.value,r=v0t(n,e[0]);if(!r)throw Error(`No user message found before AI messages`);let i=r.id;if(i===void 0)throw Error(`User message has no id`);await this.regenerateMessage(String(i),t)}catch(e){throw console.error(`Failed to regenerate from AI messages:`,e),this.emit(`chat-error`,{action:`regenerate`,error:e}),e}}async regenerateMessage(e,t){try{let n=this.messages.value,r=n.findIndex(t=>String(t.id)===e);if(r===-1)throw Error(`Message not found: ${e}`);let i=n[r];if(i.role!==O9.User)throw Error(`Can only regenerate from user messages`);let a=n.slice(r),o=typeof i.content==`string`?i.content:JSON.stringify(i.content),s=i.property;this._isGenerating.value=!0;let l=this.messageModule.deleteMessages(a);this.agentModule.chat(o,t,void 0,void 0,s),this.emit(`chat-regenerate`,{messageId:e}),l.catch(e=>{console.error(`[regenerateMessage] Delete API error:`,e)})}catch(e){throw console.error(`Failed to regenerate message:`,e),this._isGenerating.value=!1,this.emit(`chat-error`,{action:`regenerate`,error:e}),e}}async resendMessageWithProperty(e,t,n,r){try{let i=this.messages.value,a=i.findIndex(t=>String(t.id)===e);if(a===-1)throw Error(`Message not found: ${e}`);if(i[a].role!==O9.User)throw Error(`Can only resend user messages`);let o=i.slice(a);this._isGenerating.value=!0;let s=this.messageModule.deleteMessages(o);this.agentModule.chat(n,t,void 0,void 0,r),this.emit(`chat-resend`,{messageId:e}),s.catch(e=>{console.error(`[resendMessageWithProperty] Delete API error:`,e)})}catch(e){throw console.error(`Failed to resend message with property:`,e),this._isGenerating.value=!1,this.emit(`chat-error`,{action:`resend`,error:e}),e}}async retryMessage(e){try{console.warn(`retryMessage not implemented yet`),this.emit(`chat-retry`,{messageId:e})}catch(e){throw console.error(`Failed to retry message:`,e),this.emit(`chat-error`,{action:`retry`,error:e}),e}}async sendMessage(e,t,n={}){try{if(!t)throw Error(`No active session. Please create or select a session first.`);this._isGenerating.value=!0,this.emit(`send-message`,{content:e}),await this.agentModule.chat(e,t,void 0,void 0,n.property),this.autoRenameSessionIfNeeded(t)}catch(e){throw console.error(`Failed to send message:`,e),this._isGenerating.value=!1,this.emit(`chat-error`,{action:`send`,error:e}),e}}async stopGeneration(){let e=this.sessionModule?.current?.value?.sessionCode??``;this._isStopLoading.value=!0;try{await this.agentModule.stopChat(e),this._isGenerating.value=!1,this.emit(`stop`,{})}catch(e){console.error(`Failed to stop generation:`,e),this.emit(`chat-error`,{action:`stop`,error:e})}finally{this._isStopLoading.value=!1}}},o3t=class{agentModule;config;eventEmitter;sessionModule;emit(e,t){this.eventEmitter?.emit(e,t)}constructor(e,t=null,n=null,r={}){this.sessionModule=e,this.agentModule=t,this.eventEmitter=n,this.config=r}get currentSession(){return this.sessionModule.current}get isCreateLoading(){return this.sessionModule.isCreateLoading}get isCurrentLoading(){return this.sessionModule.isCurrentLoading}get isDeleteLoading(){return this.sessionModule.isDeleteLoading}get isListLoading(){return this.sessionModule.isListLoading}get isUpdateLoading(){return this.sessionModule.isUpdateLoading}get sessionList(){return this.sessionModule.list}async createNewSession(){return this.createSession({name:`新会话`,sessionCode:`new_session_${Date.now()}`})}async createSession(e={}){if(this.config.enableChatSession===!1)throw Error(`Chat session is disabled`);try{let t={sessionName:e.name||`新会话`,sessionCode:e.sessionCode||`session_${Date.now()}`,isTemporary:e.isTemporary||!1};await this.sessionModule.createSession(t);let n=this.agentModule?.info.value;n&&this.agentModule?.handleRole(n,t.sessionCode),this.emit(`session-created`,{session:this.sessionModule.current.value})}catch(e){throw console.error(`Failed to create session:`,e),this.emit(`session-error`,{action:`create`,error:e}),e}}async deleteSession(e){try{await this.sessionModule.deleteSession(e),this.emit(`session-deleted`,{sessionCode:e})}catch(e){throw console.error(`Failed to delete session:`,e),this.emit(`session-error`,{action:`delete`,error:e}),e}}async getSession(e){try{await this.sessionModule.getSession(e)}catch(e){throw console.error(`Failed to get session:`,e),this.emit(`session-error`,{action:`get`,error:e}),e}}async loadRecentSession(e){try{e?.skipLoadSessions||await this.loadSessions();let t=this.sessionList.value;if(this.config.initialSessionCode){await this.switchSession(this.config.initialSessionCode);return}if(t.length>0){let e=t[0];(e.sessionContentCount??0)>0?await this.createNewSession():await this.switchSession(e.sessionCode,{loadMessages:!1});return}await this.createNewSession()}catch(e){throw console.error(`Failed to load recent session:`,e),e}}async loadSessions(){try{await this.sessionModule.getSessions(),this.emit(`sessions-loaded`,{sessions:this.sessionList.value})}catch(e){throw console.error(`Failed to load sessions:`,e),this.emit(`session-error`,{action:`load`,error:e}),e}}async switchSession(e,t){try{await this.sessionModule.chooseSession(e,t),this.emit(`session-switched`,{session:this.sessionModule.current.value})}catch(e){throw console.error(`Failed to switch session:`,e),this.emit(`session-error`,{action:`switch`,error:e}),e}}async updateSessionName(e,t){try{let n=this.sessionList.value.find(t=>t.sessionCode===e);if(!n)throw Error(`Session not found: ${e}`);await this.sessionModule.updateSession({...n,sessionName:t}),this.emit(`session-updated`,{session:this.sessionModule.current.value})}catch(e){throw console.error(`Failed to update session name:`,e),this.emit(`session-error`,{action:`update`,error:e}),e}}},s3t=class{messageModule;sessionModule;constructor(e,t){this.messageModule=e,this.sessionModule=t}async shareMessages(e){if(e.length===0)throw Error(`No messages to share`);let t=this.sessionModule.current?.value?.sessionCode;if(!t)throw Error(`No active session`);let n=await this.messageModule.shareMessages(t,e);if(!n)throw Error(`Share failed: no result returned`);return{shareUrl:`${n.share_page}share-page/${n.share_token}`,userMessageIds:e.map(e=>String(e.id))}}},c3t=class{_agentShortcuts;_effectiveShortcuts;_propsShortcuts;eventEmitter;emit(e,t){this.eventEmitter?.emit(e,t)}constructor(e=null,t=[]){this._propsShortcuts=en(t),this._agentShortcuts=en([]),this.eventEmitter=e,this._effectiveShortcuts=ii(()=>this._propsShortcuts.value.length>0?this._propsShortcuts.value:this._agentShortcuts.value.length>0?this._agentShortcuts.value:[])}get count(){return this._effectiveShortcuts.value.length}get effectiveShortcuts(){return this._effectiveShortcuts}get hasShortcuts(){return this._effectiveShortcuts.value.length>0}get shortcuts(){return this._effectiveShortcuts}addShortcut(e){this._propsShortcuts.value.push(e)}clear(){this._propsShortcuts.value=[],this._agentShortcuts.value=[]}filterByTextLength(e,t){return!e||e.length>t?[]:this._effectiveShortcuts.value}filterShortcuts(e,t){return t?this._effectiveShortcuts.value.filter(n=>t(n,e)):this._effectiveShortcuts.value}getShortcutById(e){return this._effectiveShortcuts.value.find(t=>t.id===e)}handleShortcutClick(e,t,n=`main`){this.emit(`shortcut-click`,{shortcut:e,selectedText:t,source:n})}limitShortcuts(e){return this._effectiveShortcuts.value.slice(0,e)}removeShortcut(e){this._propsShortcuts.value=this._propsShortcuts.value.filter(t=>t.id!==e)}setAgentShortcuts(e){this._agentShortcuts.value=e}setShortcuts(e){this._propsShortcuts.value=e}},l3t=class{_isCompressed;_isDraggingOrResizing;_nimbusMinimized;_panelVisible;_positionAndSize;cleanupFunctions;config;containerRef=null;debugMode;listeners;onceListeners;constructor(e={}){this.config=e,this.listeners=new Map,this.onceListeners=new Map,this.debugMode=e.debug??!1,this.cleanupFunctions=[],this._panelVisible=en(e.initialPanelVisible??!1),this._nimbusMinimized=en(e.initialNimbusMinimized??!1),this._isDraggingOrResizing=en(!1),this._isCompressed=en(!1),this._positionAndSize=en({x:0,y:0,width:400,height:window.innerHeight})}get container(){return{updatePosition:this.updatePosition.bind(this),updateSize:this.updateSize.bind(this),updatePositionAndSize:this.updatePositionAndSize.bind(this),toggleCompression:this.toggleCompression.bind(this),expandForSidePanel:this.expandForSidePanel.bind(this),collapseSidePanel:this.collapseSidePanel.bind(this),positionAndSize:ii(()=>this.containerRef?.positionAndSize?.value??this._positionAndSize.value),isCompressed:ii(()=>this._isCompressed.value),isSidePanelExpanded:ii(()=>this.containerRef?.isSidePanelExpanded?.value??!1)}}get isCompressed(){return this._isCompressed}get isDraggingOrResizing(){return this._isDraggingOrResizing}get nimbus(){return{minimize:this.minimizeNimbus.bind(this),restore:this.restoreNimbus.bind(this),toggle:this.toggleNimbus.bind(this),isMinimized:ii(()=>this._nimbusMinimized.value)}}get nimbusMinimized(){return this._nimbusMinimized}get panel(){return{show:this.showPanel.bind(this),hide:this.hidePanel.bind(this),toggle:this.togglePanel.bind(this),isVisible:ii(()=>this._panelVisible.value)}}get panelVisible(){return this._panelVisible}get state(){return{panelVisible:this._panelVisible,nimbusMinimized:this._nimbusMinimized,isDraggingOrResizing:this._isDraggingOrResizing,positionAndSize:this._positionAndSize}}collapseSidePanel(){this.containerRef?.collapseSidePanel&&this.containerRef.collapseSidePanel()}destroy(){this.listeners.clear(),this.onceListeners.clear(),this.cleanupFunctions.forEach(e=>e()),this.cleanupFunctions=[],this.debugMode&&console.debug(`[ComponentManager] Destroyed`)}emit(e,t){this.debugMode&&console.debug(`[ComponentManager] Emitting "${e}"`,t);let n=this.listeners.get(e);n&&n.forEach(n=>{try{n(t)}catch(t){console.error(`[ComponentManager] Error in listener for "${e}":`,t)}});let r=this.onceListeners.get(e);if(r&&r.size>0){let n=Array.from(r);this.onceListeners.delete(e),n.forEach(n=>{try{n(t)}catch(t){console.error(`[ComponentManager] Error in once listener for "${e}":`,t)}})}}emitInternal(e,t){this.emit(e,t)}expandForSidePanel(e){this.containerRef?.expandForSidePanel&&this.containerRef.expandForSidePanel(e)}getConfig(){return this.config}getRegisteredEvents(){let e=new Set;return this.listeners.forEach((t,n)=>e.add(n)),this.onceListeners.forEach((t,n)=>e.add(n)),Array.from(e)}handleDragging(e){this._isDraggingOrResizing.value=!0,this._positionAndSize.value=e,this.emit(`dragging`,e)}handleDragStop(e){this._isDraggingOrResizing.value=!1,this._positionAndSize.value=e,this.emit(`drag-stop`,e)}handleNimbusClick(){this.emit(`nimbus-click`,{}),this.showPanel()}handlePopupClick(){this.emit(`popup-click`,{}),this.showPanel()}handlePopupShortcutClick(e){this.emit(`popup-shortcut-click`,{shortcut:e}),this.emit(`shortcut-click`,{shortcut:e,source:`popup`})}handleResizeStop(e){this._isDraggingOrResizing.value=!1,this._positionAndSize.value=e,this.emit(`resize-stop`,e)}handleResizing(e){this._isDraggingOrResizing.value=!0,this._positionAndSize.value=e,this.emit(`resizing`,e)}handleShortcutClick(e,t){this.emit(`shortcut-click`,{shortcut:e,source:t})}hasListeners(e){return this.listenerCount(e)>0}hidePanel(){this._panelVisible.value=!1,this.emit(`panel-hide`,{})}listenerCount(e){return(this.listeners.get(e)?.size??0)+(this.onceListeners.get(e)?.size??0)}minimizeNimbus(){this._nimbusMinimized.value=!0,this.emit(`nimbus-minimize`,{})}off(e,t){t?(this.listeners.get(e)?.delete(t),this.onceListeners.get(e)?.delete(t),this.debugMode&&console.debug(`[ComponentManager] Unsubscribed from "${e}", remaining: ${this.listenerCount(e)}`)):(this.listeners.delete(e),this.onceListeners.delete(e),this.debugMode&&console.debug(`[ComponentManager] Removed all listeners for "${e}"`))}on(e,t){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t),this.debugMode&&console.debug(`[ComponentManager] Subscribed to "${e}", total: ${this.listenerCount(e)}`),()=>{this.off(e,t)}}once(e,t){return this.onceListeners.has(e)||this.onceListeners.set(e,new Set),this.onceListeners.get(e).add(t),this.debugMode&&console.debug(`[ComponentManager] Subscribed once to "${e}"`),()=>{this.onceListeners.get(e)?.delete(t)}}restoreNimbus(){this._nimbusMinimized.value=!1,this.emit(`nimbus-restore`,{})}setCompressed(e){this._isCompressed.value=e}setContainerRef(e){this.containerRef=e,e?.isCompressed&&(this._isCompressed.value=e.isCompressed.value)}setDebugMode(e){this.debugMode=e}setDraggingOrResizing(e){this._isDraggingOrResizing.value=e}showPanel(e){this._panelVisible.value=!0,this.emit(`panel-show`,{sessionCode:e})}toggleCompression(){this.containerRef?this.containerRef.toggleCompression():this._isCompressed.value=!this._isCompressed.value}toggleNimbus(){this._nimbusMinimized.value?this.restoreNimbus():this.minimizeNimbus()}togglePanel(){this._panelVisible.value?this.hidePanel():this.showPanel()}updatePosition(e,t){this._positionAndSize.value={...this._positionAndSize.value,x:e,y:t}}updatePositionAndSize(e,t,n,r){this._positionAndSize.value={x:e,y:t,width:n,height:r}}updateSize(e,t){this._positionAndSize.value={...this._positionAndSize.value,width:e,height:t}}};function u3t(e){return new l3t(e)}var d3t={"panel-show":`show`,"panel-hide":`close`,"panel-toggle":null,"nimbus-click":null,"nimbus-minimize":null,"nimbus-restore":null,"popup-click":null,"popup-shortcut-click":null,dragging:`dragging`,resizing:`resizing`,"drag-stop":`drag-stop`,"resize-stop":`resize-stop`,"compression-toggle":null,"side-panel-expand":null,"side-panel-collapse":null,"send-message":`send-message`,"receive-start":`receive-start`,"receive-text":`receive-text`,"receive-end":`receive-end`,"receive-error":null,stop:`stop`,"chat-regenerate":null,"chat-retry":null,"message-deleted":null,"messages-batch-deleted":null,"session-created":null,"session-switched":null,"session-deleted":null,"session-updated":null,"sessions-loaded":null,"session-initialized":`session-initialized`,"session-error":null,"shortcut-click":`shortcut-click`,"chat-error":null,"sdk-error":`sdk-error`,"new-chat":`new-chat`,"history-click":`history-click`,"auto-generate-name":`auto-generate-name`,"help-click":`help-click`,rename:`rename`,share:`share`,close:`close`,"toggle-compression":null,"transfer-messages":`transfer-messages`,"share-messages":`share-messages`,"agent-info-loaded":null,error:null};function f3t(e,t){switch(e){case`send-message`:return[t.content];case`rename`:return[t.newName];case`history-click`:return[t.event];case`dragging`:case`resizing`:case`drag-stop`:case`resize-stop`:case`shortcut-click`:case`session-initialized`:case`sdk-error`:case`transfer-messages`:case`share-messages`:return[t];case`panel-show`:case`panel-hide`:case`receive-start`:case`receive-text`:case`receive-end`:case`stop`:case`new-chat`:case`auto-generate-name`:case`help-click`:case`share`:case`close`:return[];default:return[t]}}function p3t(e){let{props:t,emit:n,scrollToBottom:r}=e,i=en(!1),a=en(null),o=()=>t.chatHelper?!t.chatHelper.agent||!t.chatHelper.session||!t.chatHelper.message?{valid:!1,error:`[ChatBot] Invalid chatHelper: missing required modules (agent, session, message)`}:{valid:!0}:t.url?{valid:!0}:{valid:!1,error:`[ChatBot] Neither chatHelper nor url provided. Component requires at least one.`},s=(()=>{let e=o();if(!e.valid)return console.error(e.error),a.value=Error(e.error),null;if(t.chatHelper)return t.chatHelper;let i=new R9({onStart:()=>{n(`receive-start`)},onMessage:e=>{n(`receive-text`)},onDone:()=>{n(`receive-end`),r()},onError:e=>{n(`error`,e)}}),s=i3t({requestData:{urlPrefix:S0t(t.url),headers:t.requestOptions?.headers,data:t.requestOptions?.data},protocol:i});return i.injectMessageModule(s.message),s})(),l=!t.chatHelper,u=s?new o3t(s.session,s.agent,null,{enableChatSession:!0,autoSwitchToInitialSession:!!t.sessionCode,loadRecentSessionOnMount:t.autoLoad,initialSessionCode:t.sessionCode}):null,d=s?new a3t(s.agent,s.message,s.session,null,{openingRemark:t.helloText,predefinedQuestions:t.prompts,placeholder:t.placeholder}):null,f=new c3t(null,t.shortcuts||[]);return Jn(async()=>{if(!(!s||a.value))try{l?(await Promise.all([s.agent.getAgentInfo(),s.session.getSessions()]),u&&await u.loadRecentSession({skipLoadSessions:!0}),i.value=!0):i.value=!0,n(`agent-info-loaded`,s)}catch(e){console.error(`Failed to initialize ChatBot:`,e),a.value=e,n(`error`,e)}}),Yn(()=>{l&&s&&s.agent.stopChat(s.session.current?.value?.sessionCode??``)}),{chatHelper:s,isStandaloneMode:l,isInitialized:i,initError:a,chatBusinessManager:d,sessionBusinessManager:u,shortcutManager:f}}function m3t(e){let{props:t,chatHelper:n,chatBusinessManager:r,sessionBusinessManager:i,shortcutManager:a,isStandaloneMode:o,isInitialized:s,selectedShortcut:l}=e,u=ii(()=>r?.isStopLoading.value?x6.StopLoading:((t.chatHelper||n)?.agent)?.isChatting?.value?x6.Streaming:x6.Complete),d=ii(()=>u.value===x6.Streaming?u5.Disabled:void 0),f=ii(()=>r?.messages.value??[]),p=ii(()=>r?.isMessagesLoading.value??!1);return{messageStatus:u,messageToolsStatus:d,messages:f,isMessagesLoading:p,isGenerating:ii(()=>r?.isGenerating.value??!1),currentSession:ii(()=>i?.currentSession.value??null),isWelcomeState:ii(()=>o&&!s.value?!1:!p.value&&f.value.length===0),openingRemark:ii(()=>n?.agent.info.value?.conversationSettings?.openingRemark||``),effectiveResources:ii(()=>t.resources?.length?t.resources:n?.agent.info.value?.resources??[]),effectivePrompts:ii(()=>t.prompts?.length?t.prompts:n?.agent.info.value?.conversationSettings?.predefinedQuestions??[]),effectiveSupportUpload:ii(()=>l.value?.supportUpload?l.value.supportUpload.vision===!0:n?.agent.info.value?.promptSetting?.supportUpload?.vision===!0),chatbotStyle:ii(()=>({height:typeof t.height==`number`?`${t.height}px`:t.height,maxWidth:typeof t.maxWidth==`number`?`${t.maxWidth}px`:t.maxWidth})),filteredShortcuts:ii(()=>a.shortcuts.value)}}function h3t(e){let{emit:t,chatHelper:n,chatBusinessManager:r,selectedShortcut:i,selectedResources:a}=e,o=tn([[]]),s=tn(``),l=(e,t)=>{o.value=e,a.value=t},u=async(e,i={})=>{if(!r||!n)throw Error(`[ChatBot] Cannot send message: chatBusinessManager not initialized`);let l=n.session.current?.value?.sessionCode;if(!l)throw Error(`[ChatBot] Cannot send message: no active session`);o.value=[[]],s.value=``,a.value=[],t(`send-message`,typeof e==`string`?e:``),await r.sendMessage(e,l,i)},d=async e=>{let t=n?.session.current?.value?.sessionCode;if(!t)throw Error(`[ChatBot] Cannot upload: no active session`);let r=await n.session.uploadFile(t,e);if(!r?.download_url)throw Error(`[ChatBot] Upload failed: no download URL returned`);return r},f=async(e,n)=>{try{let t={};s.value&&(t.cite=s.value),i.value&&(t.command=i.value.id),a.value.length&&(t.resources=a.value),await u(e,Object.keys(t).length?{property:{extra:t}}:{})}catch(e){console.error(`Failed to send message:`,e),t(`error`,e)}},p=async()=>{await m()},m=async()=>{if(!r){console.error(`[ChatBot] Cannot stop generation: chatBusinessManager not initialized`);return}await r.stopGeneration(),t(`stop`)};return{userInput:o,cite:s,handleUpdateModelValue:l,doSendMessage:u,handleSendMessage:f,handleUpload:d,handleStopSending:p,stopGeneration:m}}function g3t(e){let{emit:t,chatHelper:n,isStandaloneMode:r}=e,i=async e=>{if(!(!n||e.length===0))try{await C0t((await new s3t(n.message,n.session).shareMessages(e)).shareUrl),md({message:`分享链接已复制到剪贴板`,theme:`success`})}catch(e){console.error(`[ChatBot] Failed to share messages:`,e),md({message:`分享失败,请重试`,theme:`error`})}};return{handleConfirmShare:async e=>{r&&await i(e),t(`confirm-share`,e)}}}function _3t(e){let{props:t,emit:n,shortcutManager:r,doSendMessage:i,selectedShortcut:a}=e,o=r.effectiveShortcuts,s=(e,t)=>{let n=e,r;if(r=n.enable_fill_back&&n.fill_back_component_key?n.fill_back_component_key:n.components?.find(e=>e.fillBack)?.key,r&&t){let e=n.components?.map(e=>e.key===r?{...e,default:t}:{...e,default:e.default??void 0});a.value={...n,components:e,formModel:{...n.formModel,[r]:t}}}else a.value={...n,formModel:{...n.formModel}}},l=(e,t)=>{let n=e.components||[];return{extra:{cite:{type:`structured`,title:e.alias||e.name,data:n.map(e=>({key:e.name||e.key,value:String(t[e.key]??``)}))},command:e.id,context:n.map(e=>({[e.key]:t[e.key],context_type:e.type,__label:e.name||e.key,__key:e.key,__value:t[e.key]}))}}},u=e=>{let t=e.property?.extra;return t?.shortcut?t.shortcut:t?.command?o.value.find(e=>e.id===t.command)??null:null},d=(e,t)=>{s(e,t),n(`shortcut-click`,{shortcut:e,source:`main`})},f=()=>{a.value=null};return gr(()=>t.shortcuts,e=>{r.setShortcuts(e||[])},{immediate:!0}),gr(()=>e.chatHelper?.agent.info.value?.conversationSettings?.commands,e=>{e&&r.setAgentShortcuts(e)},{immediate:!0}),{effectiveShortcuts:o,selectShortcutWithText:s,buildShortcutProperty:l,getShortcutFromMessage:u,handleSelectShortcut:d,handleCloseShortcut:f,handleShortcutSubmit:async e=>{if(!a.value){console.error(`[ChatBot] No selected shortcut`);return}let t=l(a.value,e),r=a.value.name,o=a.value;f();try{await i(r,{property:t})}catch(e){a.value=o,console.error(`[ChatBot] Failed to submit shortcut:`,e),n(`error`,e)}}}}function v3t(e){let{emit:t,chatHelper:n,chatBusinessManager:r,cite:i,focusInput:a,scrollToBottom:o,getShortcutFromMessage:s,buildShortcutProperty:l}=e,u=async e=>{if(!r||!n){console.error(`[ChatBot] Cannot delete messages: chatBusinessManager not initialized`);return}try{let t=r.messages.value,i=v0t(t,e[0]);if(!i){console.error(`[ChatBot] No user message found before AI messages`);return}let a=[i,...e];await n.message.deleteMessages(a)}catch(e){console.error(`[ChatBot] Failed to delete messages:`,e),t(`error`,e)}},d=async e=>{if(!r||!n){console.error(`[ChatBot] Cannot regenerate: chatBusinessManager not initialized`);return}let i=n.session.current?.value?.sessionCode;if(!i){console.error(`[ChatBot] Cannot regenerate: no active session`);return}try{await r.regenerateFromAIMessages(e,i),o()}catch(e){console.error(`[ChatBot] Failed to regenerate:`,e),t(`error`,e)}},f=async e=>{if(!r||!n){console.error(`[ChatBot] Cannot delete message: chatHelper not initialized`);return}try{let t=r.messages.value,i=t.findIndex(t=>t===e);if(i===-1){console.error(`[ChatBot] User message not found in messages list`);return}let a=[];for(let e=i+1;e<t.length;e++){let n=t[e];if(n.role===b6.User)break;a.push(n)}let o=[e,...a];await n.message.deleteMessages(o)}catch(e){console.error(`[ChatBot] Failed to delete user message:`,e),t(`error`,e)}};return{handleAgentAction:async(e,t)=>{if(e.id===`cite`){i.value=t.filter(e=>e.role!==b6.Reasoning).map(e=>typeof e.content==`string`?e.content:JSON.stringify(e.content||``)).join(`
3039
3039
  `),a();return}if(e.id===`rebuild`){await d(t);return}if(e.id===`delete`){await u(t);return}if(e.id===`like`||e.id===`unlike`){let t=e.id===`like`?5:0;try{return await n?.session.getSessionFeedbackReasons(t)||[]}catch(e){return console.error(`[ChatBot] Failed to get feedback reasons:`,e),[]}}console.log(`handleAgentAction`,e,t)},handleAgentFeedback:async(e,i,a,o)=>{if(!n){console.error(`[ChatBot] Cannot submit feedback: chatHelper not initialized`);return}let s=n.session.current?.value?.sessionCode;if(!s){console.error(`[ChatBot] Cannot submit feedback: no active session`);return}let l=y0t(r?.messages.value||[],i[0]);if(l===void 0){console.error(`[ChatBot] Cannot submit feedback: no user message found`);return}let u=e.id===`like`?5:0;try{await n.session.postSessionFeedback({sessionCode:s,sessionContentIds:[l],rate:u,labels:a,comment:o}),t(`feedback`,e,i[0],a,o)}catch(e){console.error(`[ChatBot] Failed to submit feedback:`,e),t(`error`,e)}},handleUserAction:async(e,t)=>{if(e.id===`delete`){await f(t);return}if(e.id===`cite`){i.value=typeof t.content==`string`?t.content:JSON.stringify(t.content||``),a();return}console.log(`handleUserAction`,e,t)},handleUserInputConfirm:async(e,r,i)=>{if(!n){console.error(`[ChatBot] Cannot edit message: chatHelper not initialized`);return}let a=n.session.current?.value?.sessionCode;if(!a){console.error(`[ChatBot] Cannot edit message: no active session`);return}let s=e.id;if(s===void 0){console.error(`[ChatBot] Cannot edit message: message has no id`);return}try{console.log(`handleUserInputConfirm`,s,a,r),await n.agent.resendMessage(String(s),a,r),o()}catch(e){console.error(`[ChatBot] Failed to edit and resend message:`,e),t(`error`,e)}},handleUserShortcutConfirm:async(e,i)=>{if(!r||!n){console.error(`[ChatBot] Cannot edit shortcut message: chatHelper not initialized`);return}let a=n.session.current?.value?.sessionCode;if(!a){console.error(`[ChatBot] Cannot edit shortcut message: no active session`);return}let u=e.id;if(u===void 0){console.error(`[ChatBot] Cannot edit shortcut message: message has no id`);return}try{let t=s(e);if(!t){console.error(`[ChatBot] Cannot edit shortcut message: shortcut not found`);return}let n=l(t,i),d=String(i.input??``);await r.resendMessageWithProperty(String(u),a,d,n),o()}catch(e){console.error(`[ChatBot] Failed to edit shortcut message:`,e),t(`error`,e)}},handleStopStreaming:async()=>{if(!r){console.error(`[ChatBot] Cannot stop generation: chatBusinessManager not initialized`);return}await r.stopGeneration(),t(`stop`)}}}var y3t={key:0,class:`chatbot-error`},b3t=Bn({__name:`chat-bot`,props:{autoLoad:{type:Boolean,default:!0},chatHelper:{default:void 0},enableSelection:{type:Boolean,default:!1},extCls:{},height:{},helloText:{},maxWidth:{},messageToolsTippyOptions:{},placeholder:{},prompts:{},requestOptions:{},resources:{default:()=>[]},sessionCode:{},shareLoading:{type:Boolean,default:!1},shortcuts:{default:()=>[]},url:{default:``}},emits:[`agent-info-loaded`,`cancel-share`,`confirm-share`,`error`,`execution-panel-change`,`feedback`,`receive-end`,`receive-start`,`receive-text`,`request-share`,`send-message`,`session-switched`,`shortcut-click`,`stop`],setup(e,{expose:t,emit:n}){let r=e,i=n,a=en(),o=en(),s=en(),l=tn([]),u=en(null),d=async()=>{await Sn(),a.value&&(a.value.scrollTop=a.value.scrollHeight)},f=()=>{s.value?.focus?.()},{chatHelper:p,isStandaloneMode:m,isInitialized:h,initError:g,chatBusinessManager:_,sessionBusinessManager:v,shortcutManager:y}=p3t({props:r,emit:i,scrollToBottom:d}),{userInput:b,cite:x,handleUpdateModelValue:S,doSendMessage:C,handleSendMessage:w,handleUpload:T,handleStopSending:E,stopGeneration:D}=h3t({emit:i,chatHelper:p,chatBusinessManager:_,selectedShortcut:u,selectedResources:l}),{handleSelectShortcut:O,handleCloseShortcut:k,handleShortcutSubmit:A,selectShortcutWithText:j,getShortcutFromMessage:M,buildShortcutProperty:N}=_3t({props:r,emit:i,chatHelper:p,shortcutManager:y,doSendMessage:C,selectedShortcut:u}),{messageStatus:P,messageToolsStatus:F,messages:I,isMessagesLoading:L,isGenerating:R,currentSession:ee,isWelcomeState:te,openingRemark:z,effectiveResources:B,effectivePrompts:ne,effectiveSupportUpload:re,chatbotStyle:ie,filteredShortcuts:ae}=m3t({props:r,chatHelper:p,chatBusinessManager:_,sessionBusinessManager:v,shortcutManager:y,isStandaloneMode:m,isInitialized:h,selectedShortcut:u}),{handleAgentAction:oe,handleAgentFeedback:se,handleUserAction:ce,handleUserInputConfirm:le,handleUserShortcutConfirm:ue,handleStopStreaming:de}=v3t({emit:i,chatHelper:p,chatBusinessManager:_,cite:x,focusInput:f,scrollToBottom:d,getShortcutFromMessage:M,buildShortcutProperty:N}),{handleConfirmShare:pe}=g3t({emit:i,chatHelper:p,isStandaloneMode:m}),me=e=>{i(`execution-panel-change`,e)},he=async e=>{let t=e.data?.props;if(t?.task_id!=null&&t?.node_id)return p?.message.getFlowAgentTaskNodeInfo(t.task_id,t.node_id)};return t({sendMessage:e=>w(e,[[]]),stopGeneration:D,switchSession:async e=>{if(!v){console.error(`[ChatBot] Cannot switch session: sessionBusinessManager not initialized`);return}try{await v.switchSession(e),i(`session-switched`,v.currentSession.value)}catch(e){console.error(`Failed to switch session:`,e),i(`error`,e)}},messages:I,currentSession:ee,isGenerating:R,getChatHelper:()=>p,setCiteText:e=>{x.value=e},focusInput:f,enterShareMode:()=>o.value?.enterShareMode(),exitShareMode:()=>o.value?.exitShareMode(),selectShortcut:(e,t)=>{j(e,t)}}),(t,n)=>(H(),U(`div`,{class:_e([`ai-chatbot`,r.extCls,{"welcome-state":V(te)}]),style:fe(V(ie))},[Gr(` 初始化错误提示 `),V(g)?(H(),U(`div`,y3t,[Br(`span`,null,Ce(V(g).message),1)])):(H(),U(Or,{key:1},[Gr(` 独立模式:初始化中(getAgentInfo → getSessions → chooseSession)统一展示 Loading `),Gr(` <div
3040
3040
  v-else-if="isStandaloneMode && !isInitialized"
3041
3041
  class="chatbot-loading"
@@ -2801,7 +2801,7 @@ Use Shift + Enter to enter a new line`:`输入 “/”唤出 Prompt
2801
2801
  <div class="tippy-dropdown-menu">
2802
2802
  ${r}
2803
2803
  </div>
2804
- `}),E=async()=>{if(a.sessionBusinessManager)try{await a.sessionBusinessManager.createNewSession()}catch(e){console.error(`Failed to create new session:`,e),(0,n.Message)({theme:`error`,message:B9(`创建会话失败`)})}o(`new-chat`)},D=e=>{e.stopPropagation(),a.sessionBusinessManager?(_||v(),_&&_.handleTriggerClick(e)):o(`history-click`,e)},O=()=>{o(`help-click`)},k=e=>{e.stopPropagation(),_&&_.isVisible()&&_.hide(),h&&(h.state.isVisible?h.hide():h.show())},A=e=>{e.stopPropagation(),e.preventDefault();let t=e.currentTarget,n=t.dataset.action;if(!t.classList.contains(`disabled`))switch(h&&h.hide(),n){case`rename`:j();break;case`auto-generate`:o(`auto-generate-name`);break;case`share`:o(`share`);break}},j=()=>{document.removeEventListener(`click`,F),p.value=a.sessionName||``,f.value=!0,setTimeout(()=>{document.addEventListener(`click`,F)},100),setTimeout(()=>{if(m.value)try{let e=m.value;e&&typeof e.focus==`function`&&e.focus();let t=e.$el?.querySelector(`input`);t&&typeof t.select==`function`&&t.select()}catch(e){console.warn(`Failed to focus rename input:`,e)}},100)},M=()=>{let e=p.value.trim();if(!e){N();return}o(`rename`,e),f.value=!1,p.value=``},N=()=>{f.value=!1,p.value=``},P=(e,t)=>{p.value=e,t.key===`Enter`?M():t.key===`Escape`&&N()},F=e=>{if(!f.value)return;let t=e.target,n=document.querySelector(`.rename-tooltip`);n&&!n.contains(t)&&N()},I=async()=>{if(!d.value)return;let e=(await import(`tippy.js`)).default;h&&=(h.destroy(),null),h=e(d.value,{content:T.value,theme:`ai-blueking-light more-menu-light light`,placement:`bottom-start`,trigger:`manual`,interactive:!0,allowHTML:!0,arrow:!1,offset:[0,4],appendTo:()=>document.querySelector(`.ai-blueking-panel`)||document.body,onShow:()=>{setTimeout(async()=>{let{default:e}=await import(`tippy.js`);document.querySelectorAll(`.tippy-menu-item`).forEach(t=>{let n=t;n.addEventListener(`click`,A);let r=n.getAttribute(`data-tippy-content`);if(r&&!g.has(n)){let t=e(n,{content:r,theme:`ai-blueking-tooltip`,trigger:`mouseenter focus`,arrow:!0,delay:[300,0],appendTo:()=>document.querySelector(`.ai-blueking-panel`)||document.body});g.set(n,t)}})},0)},onHide:()=>{document.querySelectorAll(`.tippy-menu-item`).forEach(e=>{let t=e;t.removeEventListener(`click`,A);let n=g.get(t);n&&(n.destroy(),g.delete(t))})}})};return(0,t.watch)(()=>[a.isCompressionHeight,a.hasSessionContents],()=>{h&&h.setContent(T.value)}),(0,t.onMounted)(()=>{I(),a.sessionBusinessManager&&v(),document.addEventListener(`click`,F)}),(0,t.onBeforeUnmount)(()=>{h&&=(h.destroy(),null),g.forEach(e=>{e.destroy()}),g.clear(),_&&=(_.destroy(),null),document.removeEventListener(`click`,F)}),r({headerRef:l,historyIconRef:u}),(r,i)=>((0,t.openBlock)(),(0,t.createElementBlock)(`div`,{ref_key:`headerRef`,ref:l,class:(0,t.normalizeClass)([`ai-header drag-handle`,{draggable:a.draggable}])},[(0,t.createElementVNode)(`div`,sxt,[(0,t.createElementVNode)(`div`,cxt,[(0,t.createElementVNode)(`img`,{alt:`logo`,src:(0,t.unref)(jbt)},null,8,lxt)]),(0,t.createElementVNode)(`div`,{class:(0,t.normalizeClass)([`title`,{"title-with-tooltip":f.value}])},[(0,t.createTextVNode)((0,t.toDisplayString)(y.value)+` `,1),(0,t.createCommentVNode)(` 重命名 tooltip 直接绑定在 title 上 `),f.value?((0,t.openBlock)(),(0,t.createElementBlock)(`div`,uxt,[(0,t.createElementVNode)(`div`,dxt,[(0,t.createVNode)((0,t.unref)(n.Input),{ref_key:`renameInputRef`,ref:m,modelValue:p.value,"onUpdate:modelValue":i[0]||=e=>p.value=e,class:`rename-input`,placeholder:(0,t.unref)(B9)(`请输入新的会话名称`),onKeyup:P},null,8,[`modelValue`,`placeholder`]),(0,t.createElementVNode)(`div`,{class:`rename-buttons`},[(0,t.createElementVNode)(`i`,{class:`bkai-icon bkai-check-1 rename-btn confirm-btn`,onClick:M}),(0,t.createElementVNode)(`i`,{class:`bkai-icon bkai-close rename-btn cancel-btn`,onClick:N})])])])):(0,t.createCommentVNode)(`v-if`,!0)],2),a.showMoreIcon&&S.value?((0,t.openBlock)(),(0,t.createElementBlock)(`span`,{key:0,ref_key:`moreIconRef`,ref:d,class:`bkai-icon bkai-more`,onClick:k},null,512)):(0,t.createCommentVNode)(`v-if`,!0)]),(0,t.createElementVNode)(`div`,fxt,[(0,t.createCommentVNode)(` 新增会话按钮 `),a.showNewChatIcon&&e.enableChatSession!==!1?(0,t.withDirectives)(((0,t.openBlock)(),(0,t.createElementBlock)(`i`,{key:0,class:(0,t.normalizeClass)([`bkai-icon`,`bkai-xinzengliaotian`,{disabled:!S.value}]),style:(0,t.normalizeStyle)(w()),onClick:i[1]||=e=>S.value?E():void 0},null,6)),[[(0,t.unref)(s),{content:C((0,t.unref)(B9)(`新增会话`)),boundary:`parent`}]]):(0,t.createCommentVNode)(`v-if`,!0),(0,t.createCommentVNode)(` 历史会话按钮 `),a.showHistoryIcon&&e.enableChatSession!==!1?(0,t.withDirectives)(((0,t.openBlock)(),(0,t.createElementBlock)(`i`,{key:1,ref_key:`historyIconRef`,ref:u,class:(0,t.normalizeClass)([`bkai-icon`,`bkai-history`,{disabled:!S.value}]),style:(0,t.normalizeStyle)(w()),onClick:i[2]||=e=>S.value?D(e):void 0},null,6)),[[(0,t.unref)(s),{content:C((0,t.unref)(B9)(`历史会话`)),boundary:`parent`}]]):(0,t.createCommentVNode)(`v-if`,!0),e.chatGroup?.enabled?(0,t.withDirectives)(((0,t.openBlock)(),(0,t.createElementBlock)(`i`,{key:2,class:`bkai-icon bkai-zhushou`,onClick:O},null,512)),[[(0,t.unref)(s),{content:(0,t.unref)(B9)(`转人工`),boundary:`parent`}]]):(0,t.createCommentVNode)(`v-if`,!0),a.showCompressionIcon?(0,t.withDirectives)(((0,t.openBlock)(),(0,t.createElementBlock)(`i`,{key:3,class:(0,t.normalizeClass)([`bkai-icon`,b.value]),onClick:i[3]||=e=>o(`toggle-compression`)},null,2)),[[(0,t.unref)(s),{content:x.value,boundary:`parent`}]]):(0,t.createCommentVNode)(`v-if`,!0),(0,t.withDirectives)((0,t.createElementVNode)(`i`,{class:`bkai-icon bkai-close-line-2`,onClick:i[4]||=e=>o(`close`)},null,512),[[(0,t.unref)(s),{content:(0,t.unref)(B9)(`关闭`),boundary:`parent`}]])])],2))}}),[[`__scopeId`,`data-v-3cf2263c`]]),mxt=class{_isGenerating;_isStopLoading;agentModule;config;eventEmitter;messageModule;sessionModule;autoRenameSessionIfNeeded(e){this.sessionModule&&this.messageModule.list.value.length===1&&this.sessionModule.renameSession(e).catch(e=>{console.error(`[ChatBusinessManager] Auto rename session failed:`,e)})}emit(e,t){this.eventEmitter?.emit(e,t)}constructor(e,n,r=null,i=null,a={}){this.agentModule=e,this.messageModule=n,this.sessionModule=r,this.eventEmitter=i,this.config=a,this._isGenerating=(0,t.ref)(!1),this._isStopLoading=(0,t.ref)(!1)}get isGenerating(){return this._isGenerating}get isStopLoading(){return this._isStopLoading}get isMessagesLoading(){return this.messageModule.isListLoading}get messages(){return this.messageModule.list}get openingRemark(){return this.config.openingRemark||``}get predefinedQuestions(){return this.config.predefinedQuestions||[]}async batchDeleteMessages(e){try{await this.messageModule.deleteMessages(e);let t=e.map(e=>e.id).filter(Boolean);this.emit(`messages-batch-deleted`,{messageIds:t})}catch(e){throw console.error(`Failed to batch delete messages:`,e),this.emit(`chat-error`,{action:`batch-delete-messages`,error:e}),e}}async deleteMessage(e){try{await this.messageModule.deleteMessages([e]),this.emit(`message-deleted`,{messageId:e.id})}catch(e){throw console.error(`Failed to delete message:`,e),this.emit(`chat-error`,{action:`delete-message`,error:e}),e}}handleStreamEnd(){this._isGenerating.value=!1,this.emit(`receive-end`,{})}handleStreamError(e){this._isGenerating.value=!1,this.emit(`receive-error`,{error:e})}handleStreamStart(){this._isGenerating.value=!0,this.emit(`receive-start`,{})}async regenerateFromAIMessages(e,t){try{if(!e||e.length===0)throw Error(`No AI messages provided`);let n=this.messages.value,r=z9(n,e[0]);if(!r)throw Error(`No user message found before AI messages`);let i=r.id;if(i===void 0)throw Error(`User message has no id`);await this.regenerateMessage(String(i),t)}catch(e){throw console.error(`Failed to regenerate from AI messages:`,e),this.emit(`chat-error`,{action:`regenerate`,error:e}),e}}async regenerateMessage(e,t){try{let n=this.messages.value,r=n.findIndex(t=>String(t.id)===e);if(r===-1)throw Error(`Message not found: ${e}`);let i=n[r];if(i.role!==a.MessageRole.User)throw Error(`Can only regenerate from user messages`);let o=n.slice(r),s=typeof i.content==`string`?i.content:JSON.stringify(i.content),l=i.property;this._isGenerating.value=!0;let u=this.messageModule.deleteMessages(o);this.agentModule.chat(s,t,void 0,void 0,l),this.emit(`chat-regenerate`,{messageId:e}),u.catch(e=>{console.error(`[regenerateMessage] Delete API error:`,e)})}catch(e){throw console.error(`Failed to regenerate message:`,e),this._isGenerating.value=!1,this.emit(`chat-error`,{action:`regenerate`,error:e}),e}}async resendMessageWithProperty(e,t,n,r){try{let i=this.messages.value,o=i.findIndex(t=>String(t.id)===e);if(o===-1)throw Error(`Message not found: ${e}`);if(i[o].role!==a.MessageRole.User)throw Error(`Can only resend user messages`);let s=i.slice(o);this._isGenerating.value=!0;let l=this.messageModule.deleteMessages(s);this.agentModule.chat(n,t,void 0,void 0,r),this.emit(`chat-resend`,{messageId:e}),l.catch(e=>{console.error(`[resendMessageWithProperty] Delete API error:`,e)})}catch(e){throw console.error(`Failed to resend message with property:`,e),this._isGenerating.value=!1,this.emit(`chat-error`,{action:`resend`,error:e}),e}}async retryMessage(e){try{console.warn(`retryMessage not implemented yet`),this.emit(`chat-retry`,{messageId:e})}catch(e){throw console.error(`Failed to retry message:`,e),this.emit(`chat-error`,{action:`retry`,error:e}),e}}async sendMessage(e,t,n={}){try{if(!t)throw Error(`No active session. Please create or select a session first.`);this._isGenerating.value=!0,this.emit(`send-message`,{content:e}),await this.agentModule.chat(e,t,void 0,void 0,n.property),this.autoRenameSessionIfNeeded(t)}catch(e){throw console.error(`Failed to send message:`,e),this._isGenerating.value=!1,this.emit(`chat-error`,{action:`send`,error:e}),e}}async stopGeneration(){let e=this.sessionModule?.current?.value?.sessionCode??``;this._isStopLoading.value=!0;try{await this.agentModule.stopChat(e),this._isGenerating.value=!1,this.emit(`stop`,{})}catch(e){console.error(`Failed to stop generation:`,e),this.emit(`chat-error`,{action:`stop`,error:e})}finally{this._isStopLoading.value=!1}}},hxt=class{agentModule;config;eventEmitter;sessionModule;emit(e,t){this.eventEmitter?.emit(e,t)}constructor(e,t=null,n=null,r={}){this.sessionModule=e,this.agentModule=t,this.eventEmitter=n,this.config=r}get currentSession(){return this.sessionModule.current}get isCreateLoading(){return this.sessionModule.isCreateLoading}get isCurrentLoading(){return this.sessionModule.isCurrentLoading}get isDeleteLoading(){return this.sessionModule.isDeleteLoading}get isListLoading(){return this.sessionModule.isListLoading}get isUpdateLoading(){return this.sessionModule.isUpdateLoading}get sessionList(){return this.sessionModule.list}async createNewSession(){return this.createSession({name:`新会话`,sessionCode:`new_session_${Date.now()}`})}async createSession(e={}){if(this.config.enableChatSession===!1)throw Error(`Chat session is disabled`);try{let t={sessionName:e.name||`新会话`,sessionCode:e.sessionCode||`session_${Date.now()}`,isTemporary:e.isTemporary||!1};await this.sessionModule.createSession(t);let n=this.agentModule?.info.value;n&&this.agentModule?.handleRole(n,t.sessionCode),this.emit(`session-created`,{session:this.sessionModule.current.value})}catch(e){throw console.error(`Failed to create session:`,e),this.emit(`session-error`,{action:`create`,error:e}),e}}async deleteSession(e){try{await this.sessionModule.deleteSession(e),this.emit(`session-deleted`,{sessionCode:e})}catch(e){throw console.error(`Failed to delete session:`,e),this.emit(`session-error`,{action:`delete`,error:e}),e}}async getSession(e){try{await this.sessionModule.getSession(e)}catch(e){throw console.error(`Failed to get session:`,e),this.emit(`session-error`,{action:`get`,error:e}),e}}async loadRecentSession(e){try{e?.skipLoadSessions||await this.loadSessions();let t=this.sessionList.value;if(this.config.initialSessionCode){await this.switchSession(this.config.initialSessionCode);return}if(t.length>0){let e=t[0];(e.sessionContentCount??0)>0?await this.createNewSession():await this.switchSession(e.sessionCode,{loadMessages:!1});return}await this.createNewSession()}catch(e){throw console.error(`Failed to load recent session:`,e),e}}async loadSessions(){try{await this.sessionModule.getSessions(),this.emit(`sessions-loaded`,{sessions:this.sessionList.value})}catch(e){throw console.error(`Failed to load sessions:`,e),this.emit(`session-error`,{action:`load`,error:e}),e}}async switchSession(e,t){try{await this.sessionModule.chooseSession(e,t),this.emit(`session-switched`,{session:this.sessionModule.current.value})}catch(e){throw console.error(`Failed to switch session:`,e),this.emit(`session-error`,{action:`switch`,error:e}),e}}async updateSessionName(e,t){try{let n=this.sessionList.value.find(t=>t.sessionCode===e);if(!n)throw Error(`Session not found: ${e}`);await this.sessionModule.updateSession({...n,sessionName:t}),this.emit(`session-updated`,{session:this.sessionModule.current.value})}catch(e){throw console.error(`Failed to update session name:`,e),this.emit(`session-error`,{action:`update`,error:e}),e}}},gxt=class{messageModule;sessionModule;constructor(e,t){this.messageModule=e,this.sessionModule=t}async shareMessages(e){if(e.length===0)throw Error(`No messages to share`);let t=this.sessionModule.current?.value?.sessionCode;if(!t)throw Error(`No active session`);let n=await this.messageModule.shareMessages(t,e);if(!n)throw Error(`Share failed: no result returned`);return{shareUrl:`${n.share_page}share-page/${n.share_token}`,userMessageIds:e.map(e=>String(e.id))}}},_xt=class{_agentShortcuts;_effectiveShortcuts;_propsShortcuts;eventEmitter;emit(e,t){this.eventEmitter?.emit(e,t)}constructor(e=null,n=[]){this._propsShortcuts=(0,t.ref)(n),this._agentShortcuts=(0,t.ref)([]),this.eventEmitter=e,this._effectiveShortcuts=(0,t.computed)(()=>this._propsShortcuts.value.length>0?this._propsShortcuts.value:this._agentShortcuts.value.length>0?this._agentShortcuts.value:[])}get count(){return this._effectiveShortcuts.value.length}get effectiveShortcuts(){return this._effectiveShortcuts}get hasShortcuts(){return this._effectiveShortcuts.value.length>0}get shortcuts(){return this._effectiveShortcuts}addShortcut(e){this._propsShortcuts.value.push(e)}clear(){this._propsShortcuts.value=[],this._agentShortcuts.value=[]}filterByTextLength(e,t){return!e||e.length>t?[]:this._effectiveShortcuts.value}filterShortcuts(e,t){return t?this._effectiveShortcuts.value.filter(n=>t(n,e)):this._effectiveShortcuts.value}getShortcutById(e){return this._effectiveShortcuts.value.find(t=>t.id===e)}handleShortcutClick(e,t,n=`main`){this.emit(`shortcut-click`,{shortcut:e,selectedText:t,source:n})}limitShortcuts(e){return this._effectiveShortcuts.value.slice(0,e)}removeShortcut(e){this._propsShortcuts.value=this._propsShortcuts.value.filter(t=>t.id!==e)}setAgentShortcuts(e){this._agentShortcuts.value=e}setShortcuts(e){this._propsShortcuts.value=e}},vxt=class{_isCompressed;_isDraggingOrResizing;_nimbusMinimized;_panelVisible;_positionAndSize;cleanupFunctions;config;containerRef=null;debugMode;listeners;onceListeners;constructor(e={}){this.config=e,this.listeners=new Map,this.onceListeners=new Map,this.debugMode=e.debug??!1,this.cleanupFunctions=[],this._panelVisible=(0,t.ref)(e.initialPanelVisible??!1),this._nimbusMinimized=(0,t.ref)(e.initialNimbusMinimized??!1),this._isDraggingOrResizing=(0,t.ref)(!1),this._isCompressed=(0,t.ref)(!1),this._positionAndSize=(0,t.ref)({x:0,y:0,width:400,height:window.innerHeight})}get container(){return{updatePosition:this.updatePosition.bind(this),updateSize:this.updateSize.bind(this),updatePositionAndSize:this.updatePositionAndSize.bind(this),toggleCompression:this.toggleCompression.bind(this),expandForSidePanel:this.expandForSidePanel.bind(this),collapseSidePanel:this.collapseSidePanel.bind(this),positionAndSize:(0,t.computed)(()=>this.containerRef?.positionAndSize?.value??this._positionAndSize.value),isCompressed:(0,t.computed)(()=>this._isCompressed.value),isSidePanelExpanded:(0,t.computed)(()=>this.containerRef?.isSidePanelExpanded?.value??!1)}}get isCompressed(){return this._isCompressed}get isDraggingOrResizing(){return this._isDraggingOrResizing}get nimbus(){return{minimize:this.minimizeNimbus.bind(this),restore:this.restoreNimbus.bind(this),toggle:this.toggleNimbus.bind(this),isMinimized:(0,t.computed)(()=>this._nimbusMinimized.value)}}get nimbusMinimized(){return this._nimbusMinimized}get panel(){return{show:this.showPanel.bind(this),hide:this.hidePanel.bind(this),toggle:this.togglePanel.bind(this),isVisible:(0,t.computed)(()=>this._panelVisible.value)}}get panelVisible(){return this._panelVisible}get state(){return{panelVisible:this._panelVisible,nimbusMinimized:this._nimbusMinimized,isDraggingOrResizing:this._isDraggingOrResizing,positionAndSize:this._positionAndSize}}collapseSidePanel(){this.containerRef?.collapseSidePanel&&this.containerRef.collapseSidePanel()}destroy(){this.listeners.clear(),this.onceListeners.clear(),this.cleanupFunctions.forEach(e=>e()),this.cleanupFunctions=[],this.debugMode&&console.debug(`[ComponentManager] Destroyed`)}emit(e,t){this.debugMode&&console.debug(`[ComponentManager] Emitting "${e}"`,t);let n=this.listeners.get(e);n&&n.forEach(n=>{try{n(t)}catch(t){console.error(`[ComponentManager] Error in listener for "${e}":`,t)}});let r=this.onceListeners.get(e);if(r&&r.size>0){let n=Array.from(r);this.onceListeners.delete(e),n.forEach(n=>{try{n(t)}catch(t){console.error(`[ComponentManager] Error in once listener for "${e}":`,t)}})}}emitInternal(e,t){this.emit(e,t)}expandForSidePanel(e){this.containerRef?.expandForSidePanel&&this.containerRef.expandForSidePanel(e)}getConfig(){return this.config}getRegisteredEvents(){let e=new Set;return this.listeners.forEach((t,n)=>e.add(n)),this.onceListeners.forEach((t,n)=>e.add(n)),Array.from(e)}handleDragging(e){this._isDraggingOrResizing.value=!0,this._positionAndSize.value=e,this.emit(`dragging`,e)}handleDragStop(e){this._isDraggingOrResizing.value=!1,this._positionAndSize.value=e,this.emit(`drag-stop`,e)}handleNimbusClick(){this.emit(`nimbus-click`,{}),this.showPanel()}handlePopupClick(){this.emit(`popup-click`,{}),this.showPanel()}handlePopupShortcutClick(e){this.emit(`popup-shortcut-click`,{shortcut:e}),this.emit(`shortcut-click`,{shortcut:e,source:`popup`})}handleResizeStop(e){this._isDraggingOrResizing.value=!1,this._positionAndSize.value=e,this.emit(`resize-stop`,e)}handleResizing(e){this._isDraggingOrResizing.value=!0,this._positionAndSize.value=e,this.emit(`resizing`,e)}handleShortcutClick(e,t){this.emit(`shortcut-click`,{shortcut:e,source:t})}hasListeners(e){return this.listenerCount(e)>0}hidePanel(){this._panelVisible.value=!1,this.emit(`panel-hide`,{})}listenerCount(e){return(this.listeners.get(e)?.size??0)+(this.onceListeners.get(e)?.size??0)}minimizeNimbus(){this._nimbusMinimized.value=!0,this.emit(`nimbus-minimize`,{})}off(e,t){t?(this.listeners.get(e)?.delete(t),this.onceListeners.get(e)?.delete(t),this.debugMode&&console.debug(`[ComponentManager] Unsubscribed from "${e}", remaining: ${this.listenerCount(e)}`)):(this.listeners.delete(e),this.onceListeners.delete(e),this.debugMode&&console.debug(`[ComponentManager] Removed all listeners for "${e}"`))}on(e,t){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t),this.debugMode&&console.debug(`[ComponentManager] Subscribed to "${e}", total: ${this.listenerCount(e)}`),()=>{this.off(e,t)}}once(e,t){return this.onceListeners.has(e)||this.onceListeners.set(e,new Set),this.onceListeners.get(e).add(t),this.debugMode&&console.debug(`[ComponentManager] Subscribed once to "${e}"`),()=>{this.onceListeners.get(e)?.delete(t)}}restoreNimbus(){this._nimbusMinimized.value=!1,this.emit(`nimbus-restore`,{})}setCompressed(e){this._isCompressed.value=e}setContainerRef(e){this.containerRef=e,e?.isCompressed&&(this._isCompressed.value=e.isCompressed.value)}setDebugMode(e){this.debugMode=e}setDraggingOrResizing(e){this._isDraggingOrResizing.value=e}showPanel(e){this._panelVisible.value=!0,this.emit(`panel-show`,{sessionCode:e})}toggleCompression(){this.containerRef?this.containerRef.toggleCompression():this._isCompressed.value=!this._isCompressed.value}toggleNimbus(){this._nimbusMinimized.value?this.restoreNimbus():this.minimizeNimbus()}togglePanel(){this._panelVisible.value?this.hidePanel():this.showPanel()}updatePosition(e,t){this._positionAndSize.value={...this._positionAndSize.value,x:e,y:t}}updatePositionAndSize(e,t,n,r){this._positionAndSize.value={x:e,y:t,width:n,height:r}}updateSize(e,t){this._positionAndSize.value={...this._positionAndSize.value,width:e,height:t}}};function yxt(e){return new vxt(e)}var bxt={"panel-show":`show`,"panel-hide":`close`,"panel-toggle":null,"nimbus-click":null,"nimbus-minimize":null,"nimbus-restore":null,"popup-click":null,"popup-shortcut-click":null,dragging:`dragging`,resizing:`resizing`,"drag-stop":`drag-stop`,"resize-stop":`resize-stop`,"compression-toggle":null,"side-panel-expand":null,"side-panel-collapse":null,"send-message":`send-message`,"receive-start":`receive-start`,"receive-text":`receive-text`,"receive-end":`receive-end`,"receive-error":null,stop:`stop`,"chat-regenerate":null,"chat-retry":null,"message-deleted":null,"messages-batch-deleted":null,"session-created":null,"session-switched":null,"session-deleted":null,"session-updated":null,"sessions-loaded":null,"session-initialized":`session-initialized`,"session-error":null,"shortcut-click":`shortcut-click`,"chat-error":null,"sdk-error":`sdk-error`,"new-chat":`new-chat`,"history-click":`history-click`,"auto-generate-name":`auto-generate-name`,"help-click":`help-click`,rename:`rename`,share:`share`,close:`close`,"toggle-compression":null,"transfer-messages":`transfer-messages`,"share-messages":`share-messages`,"agent-info-loaded":null,error:null};function xxt(e,t){switch(e){case`send-message`:return[t.content];case`rename`:return[t.newName];case`history-click`:return[t.event];case`dragging`:case`resizing`:case`drag-stop`:case`resize-stop`:case`shortcut-click`:case`session-initialized`:case`sdk-error`:case`transfer-messages`:case`share-messages`:return[t];case`panel-show`:case`panel-hide`:case`receive-start`:case`receive-text`:case`receive-end`:case`stop`:case`new-chat`:case`auto-generate-name`:case`help-click`:case`share`:case`close`:return[];default:return[t]}}function Sxt(e){let{props:n,emit:r,scrollToBottom:i}=e,o=(0,t.ref)(!1),s=(0,t.ref)(null),l=()=>n.chatHelper?!n.chatHelper.agent||!n.chatHelper.session||!n.chatHelper.message?{valid:!1,error:`[ChatBot] Invalid chatHelper: missing required modules (agent, session, message)`}:{valid:!0}:n.url?{valid:!0}:{valid:!1,error:`[ChatBot] Neither chatHelper nor url provided. Component requires at least one.`},u=(()=>{let e=l();if(!e.valid)return console.error(e.error),s.value=Error(e.error),null;if(n.chatHelper)return n.chatHelper;let t=new a.AGUIProtocol({onStart:()=>{r(`receive-start`)},onMessage:e=>{r(`receive-text`)},onDone:()=>{r(`receive-end`),i()},onError:e=>{r(`error`,e)}}),o=(0,a.useChatHelper)({requestData:{urlPrefix:Fbt(n.url),headers:n.requestOptions?.headers,data:n.requestOptions?.data},protocol:t});return t.injectMessageModule(o.message),o})(),d=!n.chatHelper,f=u?new hxt(u.session,u.agent,null,{enableChatSession:!0,autoSwitchToInitialSession:!!n.sessionCode,loadRecentSessionOnMount:n.autoLoad,initialSessionCode:n.sessionCode}):null,p=u?new mxt(u.agent,u.message,u.session,null,{openingRemark:n.helloText,predefinedQuestions:n.prompts,placeholder:n.placeholder}):null,m=new _xt(null,n.shortcuts||[]);return(0,t.onMounted)(async()=>{if(!(!u||s.value))try{if(d){if(await u.agent.getAgentInfo(),await u.session.getSessions(),n.sessionCode)await u.session.chooseSession(n.sessionCode);else if(u.session.list.value.length>0){let e=u.session.list.value[0];await u.session.chooseSession(e.sessionCode)}o.value=!0}else o.value=!0;r(`agent-info-loaded`,u)}catch(e){console.error(`Failed to initialize ChatBot:`,e),s.value=e,r(`error`,e)}}),(0,t.onBeforeUnmount)(()=>{d&&u&&u.agent.stopChat(u.session.current?.value?.sessionCode??``)}),{chatHelper:u,isStandaloneMode:d,isInitialized:o,initError:s,chatBusinessManager:p,sessionBusinessManager:f,shortcutManager:m}}function Cxt(e){let{props:n,chatHelper:r,chatBusinessManager:i,sessionBusinessManager:a,shortcutManager:o,isStandaloneMode:s,isInitialized:l,selectedShortcut:u}=e,d=(0,t.computed)(()=>i?.isStopLoading.value?j6.StopLoading:((n.chatHelper||r)?.agent)?.isChatting?.value?j6.Streaming:j6.Complete),f=(0,t.computed)(()=>d.value===j6.Streaming?b5.Disabled:void 0),p=(0,t.computed)(()=>i?.messages.value??[]),m=(0,t.computed)(()=>i?.isMessagesLoading.value??!1);return{messageStatus:d,messageToolsStatus:f,messages:p,isMessagesLoading:m,isGenerating:(0,t.computed)(()=>i?.isGenerating.value??!1),currentSession:(0,t.computed)(()=>a?.currentSession.value??null),isWelcomeState:(0,t.computed)(()=>s&&!l.value?!1:!m.value&&p.value.length===0),openingRemark:(0,t.computed)(()=>r?.agent.info.value?.conversationSettings?.openingRemark||``),effectiveResources:(0,t.computed)(()=>n.resources?.length?n.resources:r?.agent.info.value?.resources??[]),effectivePrompts:(0,t.computed)(()=>n.prompts?.length?n.prompts:r?.agent.info.value?.conversationSettings?.predefinedQuestions??[]),effectiveSupportUpload:(0,t.computed)(()=>u.value?.supportUpload?u.value.supportUpload.vision===!0:r?.agent.info.value?.promptSetting?.supportUpload?.vision===!0),chatbotStyle:(0,t.computed)(()=>({height:typeof n.height==`number`?`${n.height}px`:n.height,maxWidth:typeof n.maxWidth==`number`?`${n.maxWidth}px`:n.maxWidth})),filteredShortcuts:(0,t.computed)(()=>o.shortcuts.value)}}function wxt(e){let{emit:n,chatHelper:r,chatBusinessManager:i,selectedShortcut:a,selectedResources:o}=e,s=(0,t.shallowRef)([[]]),l=(0,t.shallowRef)(``),u=(e,t)=>{s.value=e,o.value=t},d=async(e,t={})=>{if(!i||!r)throw Error(`[ChatBot] Cannot send message: chatBusinessManager not initialized`);let a=r.session.current?.value?.sessionCode;if(!a)throw Error(`[ChatBot] Cannot send message: no active session`);s.value=[[]],l.value=``,o.value=[],n(`send-message`,typeof e==`string`?e:``),await i.sendMessage(e,a,t)},f=async e=>{let t=r?.session.current?.value?.sessionCode;if(!t)throw Error(`[ChatBot] Cannot upload: no active session`);let n=await r.session.uploadFile(t,e);if(!n?.download_url)throw Error(`[ChatBot] Upload failed: no download URL returned`);return n},p=async(e,t)=>{try{let t={};l.value&&(t.cite=l.value),a.value&&(t.command=a.value.id),o.value.length&&(t.resources=o.value),await d(e,Object.keys(t).length?{property:{extra:t}}:{})}catch(e){console.error(`Failed to send message:`,e),n(`error`,e)}},m=async()=>{await h()},h=async()=>{if(!i){console.error(`[ChatBot] Cannot stop generation: chatBusinessManager not initialized`);return}await i.stopGeneration(),n(`stop`)};return{userInput:s,cite:l,handleUpdateModelValue:u,doSendMessage:d,handleSendMessage:p,handleUpload:f,handleStopSending:m,stopGeneration:h}}function Txt(e){let{emit:t,chatHelper:r,isStandaloneMode:i}=e,a=async e=>{if(!(!r||e.length===0))try{await Ibt((await new gxt(r.message,r.session).shareMessages(e)).shareUrl),(0,n.Message)({message:`分享链接已复制到剪贴板`,theme:`success`})}catch(e){console.error(`[ChatBot] Failed to share messages:`,e),(0,n.Message)({message:`分享失败,请重试`,theme:`error`})}};return{handleConfirmShare:async e=>{i&&await a(e),t(`confirm-share`,e)}}}function Ext(e){let{props:n,emit:r,shortcutManager:i,doSendMessage:a,selectedShortcut:o}=e,s=i.effectiveShortcuts,l=(e,t)=>{let n=e,r;if(r=n.enable_fill_back&&n.fill_back_component_key?n.fill_back_component_key:n.components?.find(e=>e.fillBack)?.key,r&&t){let e=n.components?.map(e=>e.key===r?{...e,default:t}:{...e,default:e.default??void 0});o.value={...n,components:e,formModel:{...n.formModel,[r]:t}}}else o.value={...n,formModel:{...n.formModel}}},u=(e,t)=>{let n=e.components||[];return{extra:{cite:{type:`structured`,title:e.alias||e.name,data:n.map(e=>({key:e.name||e.key,value:String(t[e.key]??``)}))},command:e.id,context:n.map(e=>({[e.key]:t[e.key],context_type:e.type,__label:e.name||e.key,__key:e.key,__value:t[e.key]}))}}},d=e=>{let t=e.property?.extra;return t?.shortcut?t.shortcut:t?.command?s.value.find(e=>e.id===t.command)??null:null},f=(e,t)=>{l(e,t),r(`shortcut-click`,{shortcut:e,source:`main`})},p=()=>{o.value=null};return(0,t.watch)(()=>n.shortcuts,e=>{i.setShortcuts(e||[])},{immediate:!0}),(0,t.watch)(()=>e.chatHelper?.agent.info.value?.conversationSettings?.commands,e=>{e&&i.setAgentShortcuts(e)},{immediate:!0}),{effectiveShortcuts:s,selectShortcutWithText:l,buildShortcutProperty:u,getShortcutFromMessage:d,handleSelectShortcut:f,handleCloseShortcut:p,handleShortcutSubmit:async e=>{if(!o.value){console.error(`[ChatBot] No selected shortcut`);return}let t=u(o.value,e),n=o.value.name,i=o.value;p();try{await a(n,{property:t})}catch(e){o.value=i,console.error(`[ChatBot] Failed to submit shortcut:`,e),r(`error`,e)}}}}function Dxt(e){let{emit:t,chatHelper:n,chatBusinessManager:r,cite:i,focusInput:a,scrollToBottom:o,getShortcutFromMessage:s,buildShortcutProperty:l}=e,u=async e=>{if(!r||!n){console.error(`[ChatBot] Cannot delete messages: chatBusinessManager not initialized`);return}try{let t=r.messages.value,i=z9(t,e[0]);if(!i){console.error(`[ChatBot] No user message found before AI messages`);return}let a=[i,...e];await n.message.deleteMessages(a)}catch(e){console.error(`[ChatBot] Failed to delete messages:`,e),t(`error`,e)}},d=async e=>{if(!r||!n){console.error(`[ChatBot] Cannot regenerate: chatBusinessManager not initialized`);return}let i=n.session.current?.value?.sessionCode;if(!i){console.error(`[ChatBot] Cannot regenerate: no active session`);return}try{await r.regenerateFromAIMessages(e,i),o()}catch(e){console.error(`[ChatBot] Failed to regenerate:`,e),t(`error`,e)}},f=async e=>{if(!r||!n){console.error(`[ChatBot] Cannot delete message: chatHelper not initialized`);return}try{let t=r.messages.value,i=t.findIndex(t=>t===e);if(i===-1){console.error(`[ChatBot] User message not found in messages list`);return}let a=[];for(let e=i+1;e<t.length;e++){let n=t[e];if(n.role===A6.User)break;a.push(n)}let o=[e,...a];await n.message.deleteMessages(o)}catch(e){console.error(`[ChatBot] Failed to delete user message:`,e),t(`error`,e)}};return{handleAgentAction:async(e,t)=>{if(e.id===`cite`){i.value=t.filter(e=>e.role!==A6.Reasoning).map(e=>typeof e.content==`string`?e.content:JSON.stringify(e.content||``)).join(`
2804
+ `}),E=async()=>{if(a.sessionBusinessManager)try{await a.sessionBusinessManager.createNewSession()}catch(e){console.error(`Failed to create new session:`,e),(0,n.Message)({theme:`error`,message:B9(`创建会话失败`)})}o(`new-chat`)},D=e=>{e.stopPropagation(),a.sessionBusinessManager?(_||v(),_&&_.handleTriggerClick(e)):o(`history-click`,e)},O=()=>{o(`help-click`)},k=e=>{e.stopPropagation(),_&&_.isVisible()&&_.hide(),h&&(h.state.isVisible?h.hide():h.show())},A=e=>{e.stopPropagation(),e.preventDefault();let t=e.currentTarget,n=t.dataset.action;if(!t.classList.contains(`disabled`))switch(h&&h.hide(),n){case`rename`:j();break;case`auto-generate`:o(`auto-generate-name`);break;case`share`:o(`share`);break}},j=()=>{document.removeEventListener(`click`,F),p.value=a.sessionName||``,f.value=!0,setTimeout(()=>{document.addEventListener(`click`,F)},100),setTimeout(()=>{if(m.value)try{let e=m.value;e&&typeof e.focus==`function`&&e.focus();let t=e.$el?.querySelector(`input`);t&&typeof t.select==`function`&&t.select()}catch(e){console.warn(`Failed to focus rename input:`,e)}},100)},M=()=>{let e=p.value.trim();if(!e){N();return}o(`rename`,e),f.value=!1,p.value=``},N=()=>{f.value=!1,p.value=``},P=(e,t)=>{p.value=e,t.key===`Enter`?M():t.key===`Escape`&&N()},F=e=>{if(!f.value)return;let t=e.target,n=document.querySelector(`.rename-tooltip`);n&&!n.contains(t)&&N()},I=async()=>{if(!d.value)return;let e=(await import(`tippy.js`)).default;h&&=(h.destroy(),null),h=e(d.value,{content:T.value,theme:`ai-blueking-light more-menu-light light`,placement:`bottom-start`,trigger:`manual`,interactive:!0,allowHTML:!0,arrow:!1,offset:[0,4],appendTo:()=>document.querySelector(`.ai-blueking-panel`)||document.body,onShow:()=>{setTimeout(async()=>{let{default:e}=await import(`tippy.js`);document.querySelectorAll(`.tippy-menu-item`).forEach(t=>{let n=t;n.addEventListener(`click`,A);let r=n.getAttribute(`data-tippy-content`);if(r&&!g.has(n)){let t=e(n,{content:r,theme:`ai-blueking-tooltip`,trigger:`mouseenter focus`,arrow:!0,delay:[300,0],appendTo:()=>document.querySelector(`.ai-blueking-panel`)||document.body});g.set(n,t)}})},0)},onHide:()=>{document.querySelectorAll(`.tippy-menu-item`).forEach(e=>{let t=e;t.removeEventListener(`click`,A);let n=g.get(t);n&&(n.destroy(),g.delete(t))})}})};return(0,t.watch)(()=>[a.isCompressionHeight,a.hasSessionContents],()=>{h&&h.setContent(T.value)}),(0,t.onMounted)(()=>{I(),a.sessionBusinessManager&&v(),document.addEventListener(`click`,F)}),(0,t.onBeforeUnmount)(()=>{h&&=(h.destroy(),null),g.forEach(e=>{e.destroy()}),g.clear(),_&&=(_.destroy(),null),document.removeEventListener(`click`,F)}),r({headerRef:l,historyIconRef:u}),(r,i)=>((0,t.openBlock)(),(0,t.createElementBlock)(`div`,{ref_key:`headerRef`,ref:l,class:(0,t.normalizeClass)([`ai-header drag-handle`,{draggable:a.draggable}])},[(0,t.createElementVNode)(`div`,sxt,[(0,t.createElementVNode)(`div`,cxt,[(0,t.createElementVNode)(`img`,{alt:`logo`,src:(0,t.unref)(jbt)},null,8,lxt)]),(0,t.createElementVNode)(`div`,{class:(0,t.normalizeClass)([`title`,{"title-with-tooltip":f.value}])},[(0,t.createTextVNode)((0,t.toDisplayString)(y.value)+` `,1),(0,t.createCommentVNode)(` 重命名 tooltip 直接绑定在 title 上 `),f.value?((0,t.openBlock)(),(0,t.createElementBlock)(`div`,uxt,[(0,t.createElementVNode)(`div`,dxt,[(0,t.createVNode)((0,t.unref)(n.Input),{ref_key:`renameInputRef`,ref:m,modelValue:p.value,"onUpdate:modelValue":i[0]||=e=>p.value=e,class:`rename-input`,placeholder:(0,t.unref)(B9)(`请输入新的会话名称`),onKeyup:P},null,8,[`modelValue`,`placeholder`]),(0,t.createElementVNode)(`div`,{class:`rename-buttons`},[(0,t.createElementVNode)(`i`,{class:`bkai-icon bkai-check-1 rename-btn confirm-btn`,onClick:M}),(0,t.createElementVNode)(`i`,{class:`bkai-icon bkai-close rename-btn cancel-btn`,onClick:N})])])])):(0,t.createCommentVNode)(`v-if`,!0)],2),a.showMoreIcon&&S.value?((0,t.openBlock)(),(0,t.createElementBlock)(`span`,{key:0,ref_key:`moreIconRef`,ref:d,class:`bkai-icon bkai-more`,onClick:k},null,512)):(0,t.createCommentVNode)(`v-if`,!0)]),(0,t.createElementVNode)(`div`,fxt,[(0,t.createCommentVNode)(` 新增会话按钮 `),a.showNewChatIcon&&e.enableChatSession!==!1?(0,t.withDirectives)(((0,t.openBlock)(),(0,t.createElementBlock)(`i`,{key:0,class:(0,t.normalizeClass)([`bkai-icon`,`bkai-xinzengliaotian`,{disabled:!S.value}]),style:(0,t.normalizeStyle)(w()),onClick:i[1]||=e=>S.value?E():void 0},null,6)),[[(0,t.unref)(s),{content:C((0,t.unref)(B9)(`新增会话`)),boundary:`parent`}]]):(0,t.createCommentVNode)(`v-if`,!0),(0,t.createCommentVNode)(` 历史会话按钮 `),a.showHistoryIcon&&e.enableChatSession!==!1?(0,t.withDirectives)(((0,t.openBlock)(),(0,t.createElementBlock)(`i`,{key:1,ref_key:`historyIconRef`,ref:u,class:(0,t.normalizeClass)([`bkai-icon`,`bkai-history`,{disabled:!S.value}]),style:(0,t.normalizeStyle)(w()),onClick:i[2]||=e=>S.value?D(e):void 0},null,6)),[[(0,t.unref)(s),{content:C((0,t.unref)(B9)(`历史会话`)),boundary:`parent`}]]):(0,t.createCommentVNode)(`v-if`,!0),e.chatGroup?.enabled?(0,t.withDirectives)(((0,t.openBlock)(),(0,t.createElementBlock)(`i`,{key:2,class:`bkai-icon bkai-zhushou`,onClick:O},null,512)),[[(0,t.unref)(s),{content:(0,t.unref)(B9)(`转人工`),boundary:`parent`}]]):(0,t.createCommentVNode)(`v-if`,!0),a.showCompressionIcon?(0,t.withDirectives)(((0,t.openBlock)(),(0,t.createElementBlock)(`i`,{key:3,class:(0,t.normalizeClass)([`bkai-icon`,b.value]),onClick:i[3]||=e=>o(`toggle-compression`)},null,2)),[[(0,t.unref)(s),{content:x.value,boundary:`parent`}]]):(0,t.createCommentVNode)(`v-if`,!0),(0,t.withDirectives)((0,t.createElementVNode)(`i`,{class:`bkai-icon bkai-close-line-2`,onClick:i[4]||=e=>o(`close`)},null,512),[[(0,t.unref)(s),{content:(0,t.unref)(B9)(`关闭`),boundary:`parent`}]])])],2))}}),[[`__scopeId`,`data-v-3cf2263c`]]),mxt=class{_isGenerating;_isStopLoading;agentModule;config;eventEmitter;messageModule;sessionModule;autoRenameSessionIfNeeded(e){this.sessionModule&&this.messageModule.list.value.length===1&&this.sessionModule.renameSession(e).catch(e=>{console.error(`[ChatBusinessManager] Auto rename session failed:`,e)})}emit(e,t){this.eventEmitter?.emit(e,t)}constructor(e,n,r=null,i=null,a={}){this.agentModule=e,this.messageModule=n,this.sessionModule=r,this.eventEmitter=i,this.config=a,this._isGenerating=(0,t.ref)(!1),this._isStopLoading=(0,t.ref)(!1)}get isGenerating(){return this._isGenerating}get isStopLoading(){return this._isStopLoading}get isMessagesLoading(){return this.messageModule.isListLoading}get messages(){return this.messageModule.list}get openingRemark(){return this.config.openingRemark||``}get predefinedQuestions(){return this.config.predefinedQuestions||[]}async batchDeleteMessages(e){try{await this.messageModule.deleteMessages(e);let t=e.map(e=>e.id).filter(Boolean);this.emit(`messages-batch-deleted`,{messageIds:t})}catch(e){throw console.error(`Failed to batch delete messages:`,e),this.emit(`chat-error`,{action:`batch-delete-messages`,error:e}),e}}async deleteMessage(e){try{await this.messageModule.deleteMessages([e]),this.emit(`message-deleted`,{messageId:e.id})}catch(e){throw console.error(`Failed to delete message:`,e),this.emit(`chat-error`,{action:`delete-message`,error:e}),e}}handleStreamEnd(){this._isGenerating.value=!1,this.emit(`receive-end`,{})}handleStreamError(e){this._isGenerating.value=!1,this.emit(`receive-error`,{error:e})}handleStreamStart(){this._isGenerating.value=!0,this.emit(`receive-start`,{})}async regenerateFromAIMessages(e,t){try{if(!e||e.length===0)throw Error(`No AI messages provided`);let n=this.messages.value,r=z9(n,e[0]);if(!r)throw Error(`No user message found before AI messages`);let i=r.id;if(i===void 0)throw Error(`User message has no id`);await this.regenerateMessage(String(i),t)}catch(e){throw console.error(`Failed to regenerate from AI messages:`,e),this.emit(`chat-error`,{action:`regenerate`,error:e}),e}}async regenerateMessage(e,t){try{let n=this.messages.value,r=n.findIndex(t=>String(t.id)===e);if(r===-1)throw Error(`Message not found: ${e}`);let i=n[r];if(i.role!==a.MessageRole.User)throw Error(`Can only regenerate from user messages`);let o=n.slice(r),s=typeof i.content==`string`?i.content:JSON.stringify(i.content),l=i.property;this._isGenerating.value=!0;let u=this.messageModule.deleteMessages(o);this.agentModule.chat(s,t,void 0,void 0,l),this.emit(`chat-regenerate`,{messageId:e}),u.catch(e=>{console.error(`[regenerateMessage] Delete API error:`,e)})}catch(e){throw console.error(`Failed to regenerate message:`,e),this._isGenerating.value=!1,this.emit(`chat-error`,{action:`regenerate`,error:e}),e}}async resendMessageWithProperty(e,t,n,r){try{let i=this.messages.value,o=i.findIndex(t=>String(t.id)===e);if(o===-1)throw Error(`Message not found: ${e}`);if(i[o].role!==a.MessageRole.User)throw Error(`Can only resend user messages`);let s=i.slice(o);this._isGenerating.value=!0;let l=this.messageModule.deleteMessages(s);this.agentModule.chat(n,t,void 0,void 0,r),this.emit(`chat-resend`,{messageId:e}),l.catch(e=>{console.error(`[resendMessageWithProperty] Delete API error:`,e)})}catch(e){throw console.error(`Failed to resend message with property:`,e),this._isGenerating.value=!1,this.emit(`chat-error`,{action:`resend`,error:e}),e}}async retryMessage(e){try{console.warn(`retryMessage not implemented yet`),this.emit(`chat-retry`,{messageId:e})}catch(e){throw console.error(`Failed to retry message:`,e),this.emit(`chat-error`,{action:`retry`,error:e}),e}}async sendMessage(e,t,n={}){try{if(!t)throw Error(`No active session. Please create or select a session first.`);this._isGenerating.value=!0,this.emit(`send-message`,{content:e}),await this.agentModule.chat(e,t,void 0,void 0,n.property),this.autoRenameSessionIfNeeded(t)}catch(e){throw console.error(`Failed to send message:`,e),this._isGenerating.value=!1,this.emit(`chat-error`,{action:`send`,error:e}),e}}async stopGeneration(){let e=this.sessionModule?.current?.value?.sessionCode??``;this._isStopLoading.value=!0;try{await this.agentModule.stopChat(e),this._isGenerating.value=!1,this.emit(`stop`,{})}catch(e){console.error(`Failed to stop generation:`,e),this.emit(`chat-error`,{action:`stop`,error:e})}finally{this._isStopLoading.value=!1}}},hxt=class{agentModule;config;eventEmitter;sessionModule;emit(e,t){this.eventEmitter?.emit(e,t)}constructor(e,t=null,n=null,r={}){this.sessionModule=e,this.agentModule=t,this.eventEmitter=n,this.config=r}get currentSession(){return this.sessionModule.current}get isCreateLoading(){return this.sessionModule.isCreateLoading}get isCurrentLoading(){return this.sessionModule.isCurrentLoading}get isDeleteLoading(){return this.sessionModule.isDeleteLoading}get isListLoading(){return this.sessionModule.isListLoading}get isUpdateLoading(){return this.sessionModule.isUpdateLoading}get sessionList(){return this.sessionModule.list}async createNewSession(){return this.createSession({name:`新会话`,sessionCode:`new_session_${Date.now()}`})}async createSession(e={}){if(this.config.enableChatSession===!1)throw Error(`Chat session is disabled`);try{let t={sessionName:e.name||`新会话`,sessionCode:e.sessionCode||`session_${Date.now()}`,isTemporary:e.isTemporary||!1};await this.sessionModule.createSession(t);let n=this.agentModule?.info.value;n&&this.agentModule?.handleRole(n,t.sessionCode),this.emit(`session-created`,{session:this.sessionModule.current.value})}catch(e){throw console.error(`Failed to create session:`,e),this.emit(`session-error`,{action:`create`,error:e}),e}}async deleteSession(e){try{await this.sessionModule.deleteSession(e),this.emit(`session-deleted`,{sessionCode:e})}catch(e){throw console.error(`Failed to delete session:`,e),this.emit(`session-error`,{action:`delete`,error:e}),e}}async getSession(e){try{await this.sessionModule.getSession(e)}catch(e){throw console.error(`Failed to get session:`,e),this.emit(`session-error`,{action:`get`,error:e}),e}}async loadRecentSession(e){try{e?.skipLoadSessions||await this.loadSessions();let t=this.sessionList.value;if(this.config.initialSessionCode){await this.switchSession(this.config.initialSessionCode);return}if(t.length>0){let e=t[0];(e.sessionContentCount??0)>0?await this.createNewSession():await this.switchSession(e.sessionCode,{loadMessages:!1});return}await this.createNewSession()}catch(e){throw console.error(`Failed to load recent session:`,e),e}}async loadSessions(){try{await this.sessionModule.getSessions(),this.emit(`sessions-loaded`,{sessions:this.sessionList.value})}catch(e){throw console.error(`Failed to load sessions:`,e),this.emit(`session-error`,{action:`load`,error:e}),e}}async switchSession(e,t){try{await this.sessionModule.chooseSession(e,t),this.emit(`session-switched`,{session:this.sessionModule.current.value})}catch(e){throw console.error(`Failed to switch session:`,e),this.emit(`session-error`,{action:`switch`,error:e}),e}}async updateSessionName(e,t){try{let n=this.sessionList.value.find(t=>t.sessionCode===e);if(!n)throw Error(`Session not found: ${e}`);await this.sessionModule.updateSession({...n,sessionName:t}),this.emit(`session-updated`,{session:this.sessionModule.current.value})}catch(e){throw console.error(`Failed to update session name:`,e),this.emit(`session-error`,{action:`update`,error:e}),e}}},gxt=class{messageModule;sessionModule;constructor(e,t){this.messageModule=e,this.sessionModule=t}async shareMessages(e){if(e.length===0)throw Error(`No messages to share`);let t=this.sessionModule.current?.value?.sessionCode;if(!t)throw Error(`No active session`);let n=await this.messageModule.shareMessages(t,e);if(!n)throw Error(`Share failed: no result returned`);return{shareUrl:`${n.share_page}share-page/${n.share_token}`,userMessageIds:e.map(e=>String(e.id))}}},_xt=class{_agentShortcuts;_effectiveShortcuts;_propsShortcuts;eventEmitter;emit(e,t){this.eventEmitter?.emit(e,t)}constructor(e=null,n=[]){this._propsShortcuts=(0,t.ref)(n),this._agentShortcuts=(0,t.ref)([]),this.eventEmitter=e,this._effectiveShortcuts=(0,t.computed)(()=>this._propsShortcuts.value.length>0?this._propsShortcuts.value:this._agentShortcuts.value.length>0?this._agentShortcuts.value:[])}get count(){return this._effectiveShortcuts.value.length}get effectiveShortcuts(){return this._effectiveShortcuts}get hasShortcuts(){return this._effectiveShortcuts.value.length>0}get shortcuts(){return this._effectiveShortcuts}addShortcut(e){this._propsShortcuts.value.push(e)}clear(){this._propsShortcuts.value=[],this._agentShortcuts.value=[]}filterByTextLength(e,t){return!e||e.length>t?[]:this._effectiveShortcuts.value}filterShortcuts(e,t){return t?this._effectiveShortcuts.value.filter(n=>t(n,e)):this._effectiveShortcuts.value}getShortcutById(e){return this._effectiveShortcuts.value.find(t=>t.id===e)}handleShortcutClick(e,t,n=`main`){this.emit(`shortcut-click`,{shortcut:e,selectedText:t,source:n})}limitShortcuts(e){return this._effectiveShortcuts.value.slice(0,e)}removeShortcut(e){this._propsShortcuts.value=this._propsShortcuts.value.filter(t=>t.id!==e)}setAgentShortcuts(e){this._agentShortcuts.value=e}setShortcuts(e){this._propsShortcuts.value=e}},vxt=class{_isCompressed;_isDraggingOrResizing;_nimbusMinimized;_panelVisible;_positionAndSize;cleanupFunctions;config;containerRef=null;debugMode;listeners;onceListeners;constructor(e={}){this.config=e,this.listeners=new Map,this.onceListeners=new Map,this.debugMode=e.debug??!1,this.cleanupFunctions=[],this._panelVisible=(0,t.ref)(e.initialPanelVisible??!1),this._nimbusMinimized=(0,t.ref)(e.initialNimbusMinimized??!1),this._isDraggingOrResizing=(0,t.ref)(!1),this._isCompressed=(0,t.ref)(!1),this._positionAndSize=(0,t.ref)({x:0,y:0,width:400,height:window.innerHeight})}get container(){return{updatePosition:this.updatePosition.bind(this),updateSize:this.updateSize.bind(this),updatePositionAndSize:this.updatePositionAndSize.bind(this),toggleCompression:this.toggleCompression.bind(this),expandForSidePanel:this.expandForSidePanel.bind(this),collapseSidePanel:this.collapseSidePanel.bind(this),positionAndSize:(0,t.computed)(()=>this.containerRef?.positionAndSize?.value??this._positionAndSize.value),isCompressed:(0,t.computed)(()=>this._isCompressed.value),isSidePanelExpanded:(0,t.computed)(()=>this.containerRef?.isSidePanelExpanded?.value??!1)}}get isCompressed(){return this._isCompressed}get isDraggingOrResizing(){return this._isDraggingOrResizing}get nimbus(){return{minimize:this.minimizeNimbus.bind(this),restore:this.restoreNimbus.bind(this),toggle:this.toggleNimbus.bind(this),isMinimized:(0,t.computed)(()=>this._nimbusMinimized.value)}}get nimbusMinimized(){return this._nimbusMinimized}get panel(){return{show:this.showPanel.bind(this),hide:this.hidePanel.bind(this),toggle:this.togglePanel.bind(this),isVisible:(0,t.computed)(()=>this._panelVisible.value)}}get panelVisible(){return this._panelVisible}get state(){return{panelVisible:this._panelVisible,nimbusMinimized:this._nimbusMinimized,isDraggingOrResizing:this._isDraggingOrResizing,positionAndSize:this._positionAndSize}}collapseSidePanel(){this.containerRef?.collapseSidePanel&&this.containerRef.collapseSidePanel()}destroy(){this.listeners.clear(),this.onceListeners.clear(),this.cleanupFunctions.forEach(e=>e()),this.cleanupFunctions=[],this.debugMode&&console.debug(`[ComponentManager] Destroyed`)}emit(e,t){this.debugMode&&console.debug(`[ComponentManager] Emitting "${e}"`,t);let n=this.listeners.get(e);n&&n.forEach(n=>{try{n(t)}catch(t){console.error(`[ComponentManager] Error in listener for "${e}":`,t)}});let r=this.onceListeners.get(e);if(r&&r.size>0){let n=Array.from(r);this.onceListeners.delete(e),n.forEach(n=>{try{n(t)}catch(t){console.error(`[ComponentManager] Error in once listener for "${e}":`,t)}})}}emitInternal(e,t){this.emit(e,t)}expandForSidePanel(e){this.containerRef?.expandForSidePanel&&this.containerRef.expandForSidePanel(e)}getConfig(){return this.config}getRegisteredEvents(){let e=new Set;return this.listeners.forEach((t,n)=>e.add(n)),this.onceListeners.forEach((t,n)=>e.add(n)),Array.from(e)}handleDragging(e){this._isDraggingOrResizing.value=!0,this._positionAndSize.value=e,this.emit(`dragging`,e)}handleDragStop(e){this._isDraggingOrResizing.value=!1,this._positionAndSize.value=e,this.emit(`drag-stop`,e)}handleNimbusClick(){this.emit(`nimbus-click`,{}),this.showPanel()}handlePopupClick(){this.emit(`popup-click`,{}),this.showPanel()}handlePopupShortcutClick(e){this.emit(`popup-shortcut-click`,{shortcut:e}),this.emit(`shortcut-click`,{shortcut:e,source:`popup`})}handleResizeStop(e){this._isDraggingOrResizing.value=!1,this._positionAndSize.value=e,this.emit(`resize-stop`,e)}handleResizing(e){this._isDraggingOrResizing.value=!0,this._positionAndSize.value=e,this.emit(`resizing`,e)}handleShortcutClick(e,t){this.emit(`shortcut-click`,{shortcut:e,source:t})}hasListeners(e){return this.listenerCount(e)>0}hidePanel(){this._panelVisible.value=!1,this.emit(`panel-hide`,{})}listenerCount(e){return(this.listeners.get(e)?.size??0)+(this.onceListeners.get(e)?.size??0)}minimizeNimbus(){this._nimbusMinimized.value=!0,this.emit(`nimbus-minimize`,{})}off(e,t){t?(this.listeners.get(e)?.delete(t),this.onceListeners.get(e)?.delete(t),this.debugMode&&console.debug(`[ComponentManager] Unsubscribed from "${e}", remaining: ${this.listenerCount(e)}`)):(this.listeners.delete(e),this.onceListeners.delete(e),this.debugMode&&console.debug(`[ComponentManager] Removed all listeners for "${e}"`))}on(e,t){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t),this.debugMode&&console.debug(`[ComponentManager] Subscribed to "${e}", total: ${this.listenerCount(e)}`),()=>{this.off(e,t)}}once(e,t){return this.onceListeners.has(e)||this.onceListeners.set(e,new Set),this.onceListeners.get(e).add(t),this.debugMode&&console.debug(`[ComponentManager] Subscribed once to "${e}"`),()=>{this.onceListeners.get(e)?.delete(t)}}restoreNimbus(){this._nimbusMinimized.value=!1,this.emit(`nimbus-restore`,{})}setCompressed(e){this._isCompressed.value=e}setContainerRef(e){this.containerRef=e,e?.isCompressed&&(this._isCompressed.value=e.isCompressed.value)}setDebugMode(e){this.debugMode=e}setDraggingOrResizing(e){this._isDraggingOrResizing.value=e}showPanel(e){this._panelVisible.value=!0,this.emit(`panel-show`,{sessionCode:e})}toggleCompression(){this.containerRef?this.containerRef.toggleCompression():this._isCompressed.value=!this._isCompressed.value}toggleNimbus(){this._nimbusMinimized.value?this.restoreNimbus():this.minimizeNimbus()}togglePanel(){this._panelVisible.value?this.hidePanel():this.showPanel()}updatePosition(e,t){this._positionAndSize.value={...this._positionAndSize.value,x:e,y:t}}updatePositionAndSize(e,t,n,r){this._positionAndSize.value={x:e,y:t,width:n,height:r}}updateSize(e,t){this._positionAndSize.value={...this._positionAndSize.value,width:e,height:t}}};function yxt(e){return new vxt(e)}var bxt={"panel-show":`show`,"panel-hide":`close`,"panel-toggle":null,"nimbus-click":null,"nimbus-minimize":null,"nimbus-restore":null,"popup-click":null,"popup-shortcut-click":null,dragging:`dragging`,resizing:`resizing`,"drag-stop":`drag-stop`,"resize-stop":`resize-stop`,"compression-toggle":null,"side-panel-expand":null,"side-panel-collapse":null,"send-message":`send-message`,"receive-start":`receive-start`,"receive-text":`receive-text`,"receive-end":`receive-end`,"receive-error":null,stop:`stop`,"chat-regenerate":null,"chat-retry":null,"message-deleted":null,"messages-batch-deleted":null,"session-created":null,"session-switched":null,"session-deleted":null,"session-updated":null,"sessions-loaded":null,"session-initialized":`session-initialized`,"session-error":null,"shortcut-click":`shortcut-click`,"chat-error":null,"sdk-error":`sdk-error`,"new-chat":`new-chat`,"history-click":`history-click`,"auto-generate-name":`auto-generate-name`,"help-click":`help-click`,rename:`rename`,share:`share`,close:`close`,"toggle-compression":null,"transfer-messages":`transfer-messages`,"share-messages":`share-messages`,"agent-info-loaded":null,error:null};function xxt(e,t){switch(e){case`send-message`:return[t.content];case`rename`:return[t.newName];case`history-click`:return[t.event];case`dragging`:case`resizing`:case`drag-stop`:case`resize-stop`:case`shortcut-click`:case`session-initialized`:case`sdk-error`:case`transfer-messages`:case`share-messages`:return[t];case`panel-show`:case`panel-hide`:case`receive-start`:case`receive-text`:case`receive-end`:case`stop`:case`new-chat`:case`auto-generate-name`:case`help-click`:case`share`:case`close`:return[];default:return[t]}}function Sxt(e){let{props:n,emit:r,scrollToBottom:i}=e,o=(0,t.ref)(!1),s=(0,t.ref)(null),l=()=>n.chatHelper?!n.chatHelper.agent||!n.chatHelper.session||!n.chatHelper.message?{valid:!1,error:`[ChatBot] Invalid chatHelper: missing required modules (agent, session, message)`}:{valid:!0}:n.url?{valid:!0}:{valid:!1,error:`[ChatBot] Neither chatHelper nor url provided. Component requires at least one.`},u=(()=>{let e=l();if(!e.valid)return console.error(e.error),s.value=Error(e.error),null;if(n.chatHelper)return n.chatHelper;let t=new a.AGUIProtocol({onStart:()=>{r(`receive-start`)},onMessage:e=>{r(`receive-text`)},onDone:()=>{r(`receive-end`),i()},onError:e=>{r(`error`,e)}}),o=(0,a.useChatHelper)({requestData:{urlPrefix:Fbt(n.url),headers:n.requestOptions?.headers,data:n.requestOptions?.data},protocol:t});return t.injectMessageModule(o.message),o})(),d=!n.chatHelper,f=u?new hxt(u.session,u.agent,null,{enableChatSession:!0,autoSwitchToInitialSession:!!n.sessionCode,loadRecentSessionOnMount:n.autoLoad,initialSessionCode:n.sessionCode}):null,p=u?new mxt(u.agent,u.message,u.session,null,{openingRemark:n.helloText,predefinedQuestions:n.prompts,placeholder:n.placeholder}):null,m=new _xt(null,n.shortcuts||[]);return(0,t.onMounted)(async()=>{if(!(!u||s.value))try{d?(await Promise.all([u.agent.getAgentInfo(),u.session.getSessions()]),f&&await f.loadRecentSession({skipLoadSessions:!0}),o.value=!0):o.value=!0,r(`agent-info-loaded`,u)}catch(e){console.error(`Failed to initialize ChatBot:`,e),s.value=e,r(`error`,e)}}),(0,t.onBeforeUnmount)(()=>{d&&u&&u.agent.stopChat(u.session.current?.value?.sessionCode??``)}),{chatHelper:u,isStandaloneMode:d,isInitialized:o,initError:s,chatBusinessManager:p,sessionBusinessManager:f,shortcutManager:m}}function Cxt(e){let{props:n,chatHelper:r,chatBusinessManager:i,sessionBusinessManager:a,shortcutManager:o,isStandaloneMode:s,isInitialized:l,selectedShortcut:u}=e,d=(0,t.computed)(()=>i?.isStopLoading.value?j6.StopLoading:((n.chatHelper||r)?.agent)?.isChatting?.value?j6.Streaming:j6.Complete),f=(0,t.computed)(()=>d.value===j6.Streaming?b5.Disabled:void 0),p=(0,t.computed)(()=>i?.messages.value??[]),m=(0,t.computed)(()=>i?.isMessagesLoading.value??!1);return{messageStatus:d,messageToolsStatus:f,messages:p,isMessagesLoading:m,isGenerating:(0,t.computed)(()=>i?.isGenerating.value??!1),currentSession:(0,t.computed)(()=>a?.currentSession.value??null),isWelcomeState:(0,t.computed)(()=>s&&!l.value?!1:!m.value&&p.value.length===0),openingRemark:(0,t.computed)(()=>r?.agent.info.value?.conversationSettings?.openingRemark||``),effectiveResources:(0,t.computed)(()=>n.resources?.length?n.resources:r?.agent.info.value?.resources??[]),effectivePrompts:(0,t.computed)(()=>n.prompts?.length?n.prompts:r?.agent.info.value?.conversationSettings?.predefinedQuestions??[]),effectiveSupportUpload:(0,t.computed)(()=>u.value?.supportUpload?u.value.supportUpload.vision===!0:r?.agent.info.value?.promptSetting?.supportUpload?.vision===!0),chatbotStyle:(0,t.computed)(()=>({height:typeof n.height==`number`?`${n.height}px`:n.height,maxWidth:typeof n.maxWidth==`number`?`${n.maxWidth}px`:n.maxWidth})),filteredShortcuts:(0,t.computed)(()=>o.shortcuts.value)}}function wxt(e){let{emit:n,chatHelper:r,chatBusinessManager:i,selectedShortcut:a,selectedResources:o}=e,s=(0,t.shallowRef)([[]]),l=(0,t.shallowRef)(``),u=(e,t)=>{s.value=e,o.value=t},d=async(e,t={})=>{if(!i||!r)throw Error(`[ChatBot] Cannot send message: chatBusinessManager not initialized`);let a=r.session.current?.value?.sessionCode;if(!a)throw Error(`[ChatBot] Cannot send message: no active session`);s.value=[[]],l.value=``,o.value=[],n(`send-message`,typeof e==`string`?e:``),await i.sendMessage(e,a,t)},f=async e=>{let t=r?.session.current?.value?.sessionCode;if(!t)throw Error(`[ChatBot] Cannot upload: no active session`);let n=await r.session.uploadFile(t,e);if(!n?.download_url)throw Error(`[ChatBot] Upload failed: no download URL returned`);return n},p=async(e,t)=>{try{let t={};l.value&&(t.cite=l.value),a.value&&(t.command=a.value.id),o.value.length&&(t.resources=o.value),await d(e,Object.keys(t).length?{property:{extra:t}}:{})}catch(e){console.error(`Failed to send message:`,e),n(`error`,e)}},m=async()=>{await h()},h=async()=>{if(!i){console.error(`[ChatBot] Cannot stop generation: chatBusinessManager not initialized`);return}await i.stopGeneration(),n(`stop`)};return{userInput:s,cite:l,handleUpdateModelValue:u,doSendMessage:d,handleSendMessage:p,handleUpload:f,handleStopSending:m,stopGeneration:h}}function Txt(e){let{emit:t,chatHelper:r,isStandaloneMode:i}=e,a=async e=>{if(!(!r||e.length===0))try{await Ibt((await new gxt(r.message,r.session).shareMessages(e)).shareUrl),(0,n.Message)({message:`分享链接已复制到剪贴板`,theme:`success`})}catch(e){console.error(`[ChatBot] Failed to share messages:`,e),(0,n.Message)({message:`分享失败,请重试`,theme:`error`})}};return{handleConfirmShare:async e=>{i&&await a(e),t(`confirm-share`,e)}}}function Ext(e){let{props:n,emit:r,shortcutManager:i,doSendMessage:a,selectedShortcut:o}=e,s=i.effectiveShortcuts,l=(e,t)=>{let n=e,r;if(r=n.enable_fill_back&&n.fill_back_component_key?n.fill_back_component_key:n.components?.find(e=>e.fillBack)?.key,r&&t){let e=n.components?.map(e=>e.key===r?{...e,default:t}:{...e,default:e.default??void 0});o.value={...n,components:e,formModel:{...n.formModel,[r]:t}}}else o.value={...n,formModel:{...n.formModel}}},u=(e,t)=>{let n=e.components||[];return{extra:{cite:{type:`structured`,title:e.alias||e.name,data:n.map(e=>({key:e.name||e.key,value:String(t[e.key]??``)}))},command:e.id,context:n.map(e=>({[e.key]:t[e.key],context_type:e.type,__label:e.name||e.key,__key:e.key,__value:t[e.key]}))}}},d=e=>{let t=e.property?.extra;return t?.shortcut?t.shortcut:t?.command?s.value.find(e=>e.id===t.command)??null:null},f=(e,t)=>{l(e,t),r(`shortcut-click`,{shortcut:e,source:`main`})},p=()=>{o.value=null};return(0,t.watch)(()=>n.shortcuts,e=>{i.setShortcuts(e||[])},{immediate:!0}),(0,t.watch)(()=>e.chatHelper?.agent.info.value?.conversationSettings?.commands,e=>{e&&i.setAgentShortcuts(e)},{immediate:!0}),{effectiveShortcuts:s,selectShortcutWithText:l,buildShortcutProperty:u,getShortcutFromMessage:d,handleSelectShortcut:f,handleCloseShortcut:p,handleShortcutSubmit:async e=>{if(!o.value){console.error(`[ChatBot] No selected shortcut`);return}let t=u(o.value,e),n=o.value.name,i=o.value;p();try{await a(n,{property:t})}catch(e){o.value=i,console.error(`[ChatBot] Failed to submit shortcut:`,e),r(`error`,e)}}}}function Dxt(e){let{emit:t,chatHelper:n,chatBusinessManager:r,cite:i,focusInput:a,scrollToBottom:o,getShortcutFromMessage:s,buildShortcutProperty:l}=e,u=async e=>{if(!r||!n){console.error(`[ChatBot] Cannot delete messages: chatBusinessManager not initialized`);return}try{let t=r.messages.value,i=z9(t,e[0]);if(!i){console.error(`[ChatBot] No user message found before AI messages`);return}let a=[i,...e];await n.message.deleteMessages(a)}catch(e){console.error(`[ChatBot] Failed to delete messages:`,e),t(`error`,e)}},d=async e=>{if(!r||!n){console.error(`[ChatBot] Cannot regenerate: chatBusinessManager not initialized`);return}let i=n.session.current?.value?.sessionCode;if(!i){console.error(`[ChatBot] Cannot regenerate: no active session`);return}try{await r.regenerateFromAIMessages(e,i),o()}catch(e){console.error(`[ChatBot] Failed to regenerate:`,e),t(`error`,e)}},f=async e=>{if(!r||!n){console.error(`[ChatBot] Cannot delete message: chatHelper not initialized`);return}try{let t=r.messages.value,i=t.findIndex(t=>t===e);if(i===-1){console.error(`[ChatBot] User message not found in messages list`);return}let a=[];for(let e=i+1;e<t.length;e++){let n=t[e];if(n.role===A6.User)break;a.push(n)}let o=[e,...a];await n.message.deleteMessages(o)}catch(e){console.error(`[ChatBot] Failed to delete user message:`,e),t(`error`,e)}};return{handleAgentAction:async(e,t)=>{if(e.id===`cite`){i.value=t.filter(e=>e.role!==A6.Reasoning).map(e=>typeof e.content==`string`?e.content:JSON.stringify(e.content||``)).join(`
2805
2805
  `),a();return}if(e.id===`rebuild`){await d(t);return}if(e.id===`delete`){await u(t);return}if(e.id===`like`||e.id===`unlike`){let t=e.id===`like`?5:0;try{return await n?.session.getSessionFeedbackReasons(t)||[]}catch(e){return console.error(`[ChatBot] Failed to get feedback reasons:`,e),[]}}console.log(`handleAgentAction`,e,t)},handleAgentFeedback:async(e,i,a,o)=>{if(!n){console.error(`[ChatBot] Cannot submit feedback: chatHelper not initialized`);return}let s=n.session.current?.value?.sessionCode;if(!s){console.error(`[ChatBot] Cannot submit feedback: no active session`);return}let l=Mbt(r?.messages.value||[],i[0]);if(l===void 0){console.error(`[ChatBot] Cannot submit feedback: no user message found`);return}let u=e.id===`like`?5:0;try{await n.session.postSessionFeedback({sessionCode:s,sessionContentIds:[l],rate:u,labels:a,comment:o}),t(`feedback`,e,i[0],a,o)}catch(e){console.error(`[ChatBot] Failed to submit feedback:`,e),t(`error`,e)}},handleUserAction:async(e,t)=>{if(e.id===`delete`){await f(t);return}if(e.id===`cite`){i.value=typeof t.content==`string`?t.content:JSON.stringify(t.content||``),a();return}console.log(`handleUserAction`,e,t)},handleUserInputConfirm:async(e,r,i)=>{if(!n){console.error(`[ChatBot] Cannot edit message: chatHelper not initialized`);return}let a=n.session.current?.value?.sessionCode;if(!a){console.error(`[ChatBot] Cannot edit message: no active session`);return}let s=e.id;if(s===void 0){console.error(`[ChatBot] Cannot edit message: message has no id`);return}try{console.log(`handleUserInputConfirm`,s,a,r),await n.agent.resendMessage(String(s),a,r),o()}catch(e){console.error(`[ChatBot] Failed to edit and resend message:`,e),t(`error`,e)}},handleUserShortcutConfirm:async(e,i)=>{if(!r||!n){console.error(`[ChatBot] Cannot edit shortcut message: chatHelper not initialized`);return}let a=n.session.current?.value?.sessionCode;if(!a){console.error(`[ChatBot] Cannot edit shortcut message: no active session`);return}let u=e.id;if(u===void 0){console.error(`[ChatBot] Cannot edit shortcut message: message has no id`);return}try{let t=s(e);if(!t){console.error(`[ChatBot] Cannot edit shortcut message: shortcut not found`);return}let n=l(t,i),d=String(i.input??``);await r.resendMessageWithProperty(String(u),a,d,n),o()}catch(e){console.error(`[ChatBot] Failed to edit shortcut message:`,e),t(`error`,e)}},handleStopStreaming:async()=>{if(!r){console.error(`[ChatBot] Cannot stop generation: chatBusinessManager not initialized`);return}await r.stopGeneration(),t(`stop`)}}}var Oxt={key:0,class:`chatbot-error`},kxt=(0,t.defineComponent)({__name:`chat-bot`,props:{autoLoad:{type:Boolean,default:!0},chatHelper:{default:void 0},enableSelection:{type:Boolean,default:!1},extCls:{},height:{},helloText:{},maxWidth:{},messageToolsTippyOptions:{},placeholder:{},prompts:{},requestOptions:{},resources:{default:()=>[]},sessionCode:{},shareLoading:{type:Boolean,default:!1},shortcuts:{default:()=>[]},url:{default:``}},emits:[`agent-info-loaded`,`cancel-share`,`confirm-share`,`error`,`execution-panel-change`,`feedback`,`receive-end`,`receive-start`,`receive-text`,`request-share`,`send-message`,`session-switched`,`shortcut-click`,`stop`],setup(e,{expose:n,emit:r}){let i=e,a=r,o=(0,t.ref)(),s=(0,t.ref)(),l=(0,t.ref)(),u=(0,t.shallowRef)([]),d=(0,t.ref)(null),f=async()=>{await(0,t.nextTick)(),o.value&&(o.value.scrollTop=o.value.scrollHeight)},p=()=>{l.value?.focus?.()},{chatHelper:m,isStandaloneMode:h,isInitialized:g,initError:_,chatBusinessManager:v,sessionBusinessManager:y,shortcutManager:b}=Sxt({props:i,emit:a,scrollToBottom:f}),{userInput:x,cite:S,handleUpdateModelValue:C,doSendMessage:w,handleSendMessage:T,handleUpload:E,handleStopSending:D,stopGeneration:O}=wxt({emit:a,chatHelper:m,chatBusinessManager:v,selectedShortcut:d,selectedResources:u}),{handleSelectShortcut:k,handleCloseShortcut:A,handleShortcutSubmit:j,selectShortcutWithText:M,getShortcutFromMessage:N,buildShortcutProperty:P}=Ext({props:i,emit:a,chatHelper:m,shortcutManager:b,doSendMessage:w,selectedShortcut:d}),{messageStatus:F,messageToolsStatus:I,messages:L,isMessagesLoading:R,isGenerating:ee,currentSession:te,isWelcomeState:z,openingRemark:ne,effectiveResources:re,effectivePrompts:ie,effectiveSupportUpload:ae,chatbotStyle:oe,filteredShortcuts:se}=Cxt({props:i,chatHelper:m,chatBusinessManager:v,sessionBusinessManager:y,shortcutManager:b,isStandaloneMode:h,isInitialized:g,selectedShortcut:d}),{handleAgentAction:B,handleAgentFeedback:ce,handleUserAction:le,handleUserInputConfirm:ue,handleUserShortcutConfirm:de,handleStopStreaming:fe}=Dxt({emit:a,chatHelper:m,chatBusinessManager:v,cite:S,focusInput:p,scrollToBottom:f,getShortcutFromMessage:N,buildShortcutProperty:P}),{handleConfirmShare:pe}=Txt({emit:a,chatHelper:m,isStandaloneMode:h}),me=e=>{a(`execution-panel-change`,e)},he=async e=>{let t=e.data?.props;if(t?.task_id!=null&&t?.node_id)return m?.message.getFlowAgentTaskNodeInfo(t.task_id,t.node_id)};return n({sendMessage:e=>T(e,[[]]),stopGeneration:O,switchSession:async e=>{if(!y){console.error(`[ChatBot] Cannot switch session: sessionBusinessManager not initialized`);return}try{await y.switchSession(e),a(`session-switched`,y.currentSession.value)}catch(e){console.error(`Failed to switch session:`,e),a(`error`,e)}},messages:L,currentSession:te,isGenerating:ee,getChatHelper:()=>m,setCiteText:e=>{S.value=e},focusInput:p,enterShareMode:()=>s.value?.enterShareMode(),exitShareMode:()=>s.value?.exitShareMode(),selectShortcut:(e,t)=>{M(e,t)}}),(n,r)=>((0,t.openBlock)(),(0,t.createElementBlock)(`div`,{class:(0,t.normalizeClass)([`ai-chatbot`,i.extCls,{"welcome-state":(0,t.unref)(z)}]),style:(0,t.normalizeStyle)((0,t.unref)(oe))},[(0,t.createCommentVNode)(` 初始化错误提示 `),(0,t.unref)(_)?((0,t.openBlock)(),(0,t.createElementBlock)(`div`,Oxt,[(0,t.createElementVNode)(`span`,null,(0,t.toDisplayString)((0,t.unref)(_).message),1)])):((0,t.openBlock)(),(0,t.createElementBlock)(t.Fragment,{key:1},[(0,t.createCommentVNode)(` 独立模式:初始化中(getAgentInfo → getSessions → chooseSession)统一展示 Loading `),(0,t.createCommentVNode)(` <div
2806
2806
  v-else-if="isStandaloneMode && !isInitialized"
2807
2807
  class="chatbot-loading"
@@ -33450,15 +33450,7 @@ function ST(e) {
33450
33450
  }) : null, d = new gT(null, t.shortcuts || []);
33451
33451
  return F(async () => {
33452
33452
  if (!(!s || a.value)) try {
33453
- if (c) {
33454
- if (await s.agent.getAgentInfo(), await s.session.getSessions(), t.sessionCode) await s.session.chooseSession(t.sessionCode);
33455
- else if (s.session.list.value.length > 0) {
33456
- let e = s.session.list.value[0];
33457
- await s.session.chooseSession(e.sessionCode);
33458
- }
33459
- i.value = !0;
33460
- } else i.value = !0;
33461
- n("agent-info-loaded", s);
33453
+ c ? (await Promise.all([s.agent.getAgentInfo(), s.session.getSessions()]), l && await l.loadRecentSession({ skipLoadSessions: !0 }), i.value = !0) : i.value = !0, n("agent-info-loaded", s);
33462
33454
  } catch (e) {
33463
33455
  console.error("Failed to initialize ChatBot:", e), a.value = e, n("error", e);
33464
33456
  }
@@ -3035,7 +3035,7 @@ Use Shift + Enter to enter a new line`:`输入 “/”唤出 Prompt
3035
3035
  ${r}
3036
3036
  </div>
3037
3037
  `}),T=async()=>{if(i.sessionBusinessManager)try{await i.sessionBusinessManager.createNewSession()}catch(e){console.error(`Failed to create new session:`,e),_c({theme:`error`,message:V7(`创建会话失败`)})}a(`new-chat`)},E=e=>{e.stopPropagation(),i.sessionBusinessManager?(g||_(),g&&g.handleTriggerClick(e)):a(`history-click`,e)},D=()=>{a(`help-click`)},O=e=>{e.stopPropagation(),g&&g.isVisible()&&g.hide(),m&&(m.state.isVisible?m.hide():m.show())},k=e=>{e.stopPropagation(),e.preventDefault();let t=e.currentTarget,n=t.dataset.action;if(!t.classList.contains(`disabled`))switch(m&&m.hide(),n){case`rename`:A();break;case`auto-generate`:a(`auto-generate-name`);break;case`share`:a(`share`);break}},A=()=>{document.removeEventListener(`click`,P),f.value=i.sessionName||``,d.value=!0,setTimeout(()=>{document.addEventListener(`click`,P)},100),setTimeout(()=>{if(p.value)try{let e=p.value;e&&typeof e.focus==`function`&&e.focus();let t=e.$el?.querySelector(`input`);t&&typeof t.select==`function`&&t.select()}catch(e){console.warn(`Failed to focus rename input:`,e)}},100)},j=()=>{let e=f.value.trim();if(!e){M();return}a(`rename`,e),d.value=!1,f.value=``},M=()=>{d.value=!1,f.value=``},N=(e,t)=>{f.value=e,t.key===`Enter`?j():t.key===`Escape`&&M()},P=e=>{if(!d.value)return;let t=e.target,n=document.querySelector(`.rename-tooltip`);n&&!n.contains(t)&&M()},F=async()=>{if(!u.value)return;let e=(await Promise.resolve().then(()=>(m9(),jqt))).default;m&&=(m.destroy(),null),m=e(u.value,{content:w.value,theme:`ai-blueking-light more-menu-light light`,placement:`bottom-start`,trigger:`manual`,interactive:!0,allowHTML:!0,arrow:!1,offset:[0,4],appendTo:()=>document.querySelector(`.ai-blueking-panel`)||document.body,onShow:()=>{setTimeout(async()=>{let{default:e}=await Promise.resolve().then(()=>(m9(),jqt));document.querySelectorAll(`.tippy-menu-item`).forEach(t=>{let n=t;n.addEventListener(`click`,k);let r=n.getAttribute(`data-tippy-content`);if(r&&!h.has(n)){let t=e(n,{content:r,theme:`ai-blueking-tooltip`,trigger:`mouseenter focus`,arrow:!0,delay:[300,0],appendTo:()=>document.querySelector(`.ai-blueking-panel`)||document.body});h.set(n,t)}})},0)},onHide:()=>{document.querySelectorAll(`.tippy-menu-item`).forEach(e=>{let t=e;t.removeEventListener(`click`,k);let n=h.get(t);n&&(n.destroy(),h.delete(t))})}})};return(0,t.watch)(()=>[i.isCompressionHeight,i.hasSessionContents],()=>{m&&m.setContent(w.value)}),(0,t.onMounted)(()=>{F(),i.sessionBusinessManager&&_(),document.addEventListener(`click`,P)}),(0,t.onBeforeUnmount)(()=>{m&&=(m.destroy(),null),h.forEach(e=>{e.destroy()}),h.clear(),g&&=(g.destroy(),null),document.removeEventListener(`click`,P)}),n({headerRef:s,historyIconRef:l}),(n,r)=>((0,t.openBlock)(),(0,t.createElementBlock)(`div`,{ref_key:`headerRef`,ref:s,class:(0,t.normalizeClass)([`ai-header drag-handle`,{draggable:i.draggable}])},[(0,t.createElementVNode)(`div`,UJt,[(0,t.createElementVNode)(`div`,WJt,[(0,t.createElementVNode)(`img`,{alt:`logo`,src:(0,t.unref)(vqt)},null,8,GJt)]),(0,t.createElementVNode)(`div`,{class:(0,t.normalizeClass)([`title`,{"title-with-tooltip":d.value}])},[(0,t.createTextVNode)((0,t.toDisplayString)(v.value)+` `,1),(0,t.createCommentVNode)(` 重命名 tooltip 直接绑定在 title 上 `),d.value?((0,t.openBlock)(),(0,t.createElementBlock)(`div`,KJt,[(0,t.createElementVNode)(`div`,qJt,[(0,t.createVNode)((0,t.unref)(ps),{ref_key:`renameInputRef`,ref:p,modelValue:f.value,"onUpdate:modelValue":r[0]||=e=>f.value=e,class:`rename-input`,placeholder:(0,t.unref)(V7)(`请输入新的会话名称`),onKeyup:N},null,8,[`modelValue`,`placeholder`]),(0,t.createElementVNode)(`div`,{class:`rename-buttons`},[(0,t.createElementVNode)(`i`,{class:`bkai-icon bkai-check-1 rename-btn confirm-btn`,onClick:j}),(0,t.createElementVNode)(`i`,{class:`bkai-icon bkai-close rename-btn cancel-btn`,onClick:M})])])])):(0,t.createCommentVNode)(`v-if`,!0)],2),i.showMoreIcon&&x.value?((0,t.openBlock)(),(0,t.createElementBlock)(`span`,{key:0,ref_key:`moreIconRef`,ref:u,class:`bkai-icon bkai-more`,onClick:O},null,512)):(0,t.createCommentVNode)(`v-if`,!0)]),(0,t.createElementVNode)(`div`,JJt,[(0,t.createCommentVNode)(` 新增会话按钮 `),i.showNewChatIcon&&e.enableChatSession!==!1?(0,t.withDirectives)(((0,t.openBlock)(),(0,t.createElementBlock)(`i`,{key:0,class:(0,t.normalizeClass)([`bkai-icon`,`bkai-xinzengliaotian`,{disabled:!x.value}]),style:(0,t.normalizeStyle)(C()),onClick:r[1]||=e=>x.value?T():void 0},null,6)),[[(0,t.unref)(o),{content:S((0,t.unref)(V7)(`新增会话`)),boundary:`parent`}]]):(0,t.createCommentVNode)(`v-if`,!0),(0,t.createCommentVNode)(` 历史会话按钮 `),i.showHistoryIcon&&e.enableChatSession!==!1?(0,t.withDirectives)(((0,t.openBlock)(),(0,t.createElementBlock)(`i`,{key:1,ref_key:`historyIconRef`,ref:l,class:(0,t.normalizeClass)([`bkai-icon`,`bkai-history`,{disabled:!x.value}]),style:(0,t.normalizeStyle)(C()),onClick:r[2]||=e=>x.value?E(e):void 0},null,6)),[[(0,t.unref)(o),{content:S((0,t.unref)(V7)(`历史会话`)),boundary:`parent`}]]):(0,t.createCommentVNode)(`v-if`,!0),e.chatGroup?.enabled?(0,t.withDirectives)(((0,t.openBlock)(),(0,t.createElementBlock)(`i`,{key:2,class:`bkai-icon bkai-zhushou`,onClick:D},null,512)),[[(0,t.unref)(o),{content:(0,t.unref)(V7)(`转人工`),boundary:`parent`}]]):(0,t.createCommentVNode)(`v-if`,!0),i.showCompressionIcon?(0,t.withDirectives)(((0,t.openBlock)(),(0,t.createElementBlock)(`i`,{key:3,class:(0,t.normalizeClass)([`bkai-icon`,y.value]),onClick:r[3]||=e=>a(`toggle-compression`)},null,2)),[[(0,t.unref)(o),{content:b.value,boundary:`parent`}]]):(0,t.createCommentVNode)(`v-if`,!0),(0,t.withDirectives)((0,t.createElementVNode)(`i`,{class:`bkai-icon bkai-close-line-2`,onClick:r[4]||=e=>a(`close`)},null,512),[[(0,t.unref)(o),{content:(0,t.unref)(V7)(`关闭`),boundary:`parent`}]])])],2))}}),[[`__scopeId`,`data-v-3cf2263c`]]),XJt=e=>{var t;return{conversationSettings:{openingRemark:e?.conversation_settings?.opening_remark,predefinedQuestions:e?.conversation_settings?.predefined_questions,commands:e==null||(t=e.conversation_settings)==null?void 0:t.commands?.map(e=>({id:e.id,name:e.name,alias:e.alias,icon:e.icon,components:e.components.map(e=>({type:e.type,name:e.name,key:e.key,placeholder:e.placeholder,default:e.default,required:e.required,fillBack:e.fill_back,fillRegx:e.fill_regx,rows:e.rows,min:e.min,max:e.max,options:e.options})),content:e.content,agentId:e.agent_id,status:e.status,supportUpload:e.support_upload})),enableChatSession:e?.conversation_settings?.enable_chat_session},promptSetting:e?.prompt_setting?{content:e.prompt_setting.content,supportUpload:e.prompt_setting.support_upload}:void 0,agentName:e?.agent_name,chatGroup:e?.chat_group?{enabled:e.chat_group.enabled,staff:e.chat_group.staff,username:e.chat_group.username}:void 0,saasUrl:e?.saas_url,resources:e?.resources}},g9;(function(e){e.FlowAgent=`flow_agent`,e.KnowledgeRag=`knowledge_rag`,e.ReferenceDocument=`reference_document`})(g9||={});var _9;(function(e){e.Activity=`activity`,e.Assistant=`assistant`,e.Developer=`developer`,e.Guide=`guide`,e.Hidden=`hidden`,e.HiddenAssistant=`hidden-assistant`,e.HiddenGuide=`hidden-guide`,e.HiddenSystem=`hidden-system`,e.HiddenUser=`hidden-user`,e.Info=`info`,e.Pause=`pause`,e.Placeholder=`placeholder`,e.Reasoning=`reasoning`,e.System=`system`,e.TemplateAssistant=`template-assistant`,e.TemplateGuide=`template-guide`,e.TemplateHidden=`template-hidden`,e.TemplateSystem=`template-system`,e.TemplateUser=`template-user`,e.Tool=`tool`,e.User=`user`})(_9||={});var v9;(function(e){e.Complete=`complete`,e.Error=`error`,e.Pending=`pending`,e.Stop=`stop`,e.Streaming=`streaming`})(v9||={});var y9;(function(e){e.Binary=`binary`,e.Function=`function`,e.Text=`text`})(y9||={});function ZJt(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function b9(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t],r=Object.keys(n);typeof Object.getOwnPropertySymbols==`function`&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){ZJt(e,t,n[t])})}return e}function QJt(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function x9(e,t){return t??={},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):QJt(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}),e}var S9=e=>{let t={id:e.id,messageId:e.message_id,name:e.name,role:e.role,sessionCode:e.session_code,status:e.status};switch(e.role){case _9.Activity:{let n=e,r=e=>e.map(e=>({name:e.name,originFileUrl:e.origin_file_url,url:e.url})),i;switch(n.activity_type){case g9.ReferenceDocument:i=r(n.content);break;case g9.KnowledgeRag:{let e=n.content;i={content:e.content,referenceDocument:r(e.reference_document)};break}case g9.FlowAgent:default:i=n.content;break}return x9(b9({},t),{activityType:n.activity_type,content:i,role:n.role})}case _9.Assistant:{let n=e;return x9(b9({},t),{content:n.content,property:n.property,role:n.role,toolCalls:n.tool_calls?.map(e=>({function:{arguments:e.function.arguments,name:e.function.name,description:e.function.description,mcpName:e.function.mcp_name},id:e.id,type:e.type}))})}case _9.Developer:{let n=e;return x9(b9({},t),{content:n.content,role:n.role})}case _9.Guide:{let n=e;return x9(b9({},t),{content:n.content,role:n.role})}case _9.Hidden:{let n=e;return x9(b9({},t),{content:n.content,role:n.role})}case _9.HiddenAssistant:{let n=e;return x9(b9({},t),{content:n.content,role:n.role})}case _9.HiddenGuide:{let n=e;return x9(b9({},t),{content:n.content,role:n.role})}case _9.HiddenSystem:{let n=e;return x9(b9({},t),{content:n.content,role:n.role})}case _9.HiddenUser:{let n=e;return x9(b9({},t),{content:n.content,role:n.role})}case _9.Info:{let n=e;return x9(b9({},t),{content:n.content,role:n.role})}case _9.Pause:{let n=e;return x9(b9({},t),{content:n.content,role:n.role})}case _9.Placeholder:{let n=e;return x9(b9({},t),{content:n.content,role:n.role})}case _9.Reasoning:{let n=e;return x9(b9({},t),{content:n.content,duration:n.duration,role:n.role})}case _9.System:{let n=e;return x9(b9({},t),{content:n.content,role:n.role})}case _9.TemplateAssistant:{let n=e;return x9(b9({},t),{content:n.content,role:n.role})}case _9.TemplateGuide:{let n=e;return x9(b9({},t),{content:n.content,role:n.role})}case _9.TemplateHidden:{let n=e;return x9(b9({},t),{content:n.content,role:n.role})}case _9.TemplateSystem:{let n=e;return x9(b9({},t),{content:n.content,role:n.role})}case _9.TemplateUser:{let n=e;return x9(b9({},t),{content:n.content,role:n.role})}case _9.Tool:{let n=e;return x9(b9({},t),{content:n.content,duration:n.duration,error:n.error,role:n.role,toolCallId:n.tool_call_id})}case _9.User:{let n=e,r=n.content;return x9(b9({},t),{content:Array.isArray(r)?r.map(e=>{if(e.type===y9.Binary){let t=e;return{data:t.data,filename:t.filename,id:t.id,mimeType:t.mime_type,type:t.type,url:t.url}}return e}):r,property:n.property,role:n.role})}}},$Jt=e=>{let t={id:e.id,message_id:e.messageId,name:e.name,role:e.role,session_code:e.sessionCode,status:e.status};switch(e.role){case _9.Activity:{let n=e,r=e=>e.map(e=>({name:e.name,origin_file_url:e.originFileUrl,url:e.url})),i;switch(n.activityType){case g9.ReferenceDocument:i=r(n.content);break;case g9.KnowledgeRag:{let e=n.content;i={content:e.content,reference_document:r(e.referenceDocument)};break}case g9.FlowAgent:default:i=n.content;break}return x9(b9({},t),{activity_type:n.activityType,content:i,role:n.role})}case _9.Assistant:{let n=e;return x9(b9({},t),{property:n.property,content:n.content,role:n.role,tool_calls:n.toolCalls?.map(e=>({function:{arguments:e.function.arguments,name:e.function.name,description:e.function.description,mcp_name:e.function.mcpName},id:e.id,type:e.type}))})}case _9.Developer:{let n=e;return x9(b9({},t),{content:n.content,role:n.role})}case _9.Guide:{let n=e;return x9(b9({},t),{content:n.content,role:n.role})}case _9.Hidden:{let n=e;return x9(b9({},t),{content:n.content,role:n.role})}case _9.HiddenAssistant:{let n=e;return x9(b9({},t),{content:n.content,role:n.role})}case _9.HiddenGuide:{let n=e;return x9(b9({},t),{content:n.content,role:n.role})}case _9.HiddenSystem:{let n=e;return x9(b9({},t),{content:n.content,role:n.role})}case _9.HiddenUser:{let n=e;return x9(b9({},t),{content:n.content,role:n.role})}case _9.Info:{let n=e;return x9(b9({},t),{content:n.content,role:n.role})}case _9.Pause:{let n=e;return x9(b9({},t),{content:n.content,role:n.role})}case _9.Placeholder:{let n=e;return x9(b9({},t),{content:n.content,role:n.role})}case _9.Reasoning:{let n=e;return x9(b9({},t),{content:n.content,duration:n.duration,role:n.role})}case _9.System:{let n=e;return x9(b9({},t),{content:n.content,role:n.role})}case _9.TemplateAssistant:{let n=e;return x9(b9({},t),{content:n.content,role:n.role})}case _9.TemplateGuide:{let n=e;return x9(b9({},t),{content:n.content,role:n.role})}case _9.TemplateHidden:{let n=e;return x9(b9({},t),{content:n.content,role:n.role})}case _9.TemplateSystem:{let n=e;return x9(b9({},t),{content:n.content,role:n.role})}case _9.TemplateUser:{let n=e;return x9(b9({},t),{content:n.content,role:n.role})}case _9.Tool:{let n=e;return x9(b9({},t),{content:n.content,duration:n.duration,error:n.error,role:n.role,tool_call_id:n.toolCallId})}case _9.User:{let n=e,r=n.content;return x9(b9({},t),{content:Array.isArray(r)?r.map(e=>{if(e.type===y9.Binary){let t=e;return{data:t.data,filename:t.filename,id:t.id,mime_type:t.mimeType,type:t.type,url:t.url}}return e}):r,property:n.property,role:n.role})}}},C9=e=>({sessionCode:e.session_code,sessionContentCount:e.session_content_count,sessionName:e.session_name,isTemporary:e.is_temporary,model:e.model,comment:e.comment,labels:e.labels,rate:e.rate,updatedAt:e.updated_at,createdAt:e.created_at,roleInfo:e.role_info?{collectionId:e.role_info.collection_id,collectionName:e.role_info.collection_name,content:e.role_info.content,variables:e.role_info.variables}:void 0,sessionProperty:{isAutoClear:e.session_property?.is_auto_clear,isAutoCalcPrompt:e.session_property?.is_auto_clac_prompt}}),eYt=e=>({session_code:e.sessionCode,session_content_count:e.sessionContentCount,session_name:e.sessionName,is_temporary:e.isTemporary,model:e.model,comment:e.comment,labels:e.labels,rate:e.rate,updated_at:e.updatedAt,created_at:e.createdAt,role_info:e.roleInfo?{collection_id:e.roleInfo.collectionId,collection_name:e.roleInfo.collectionName,content:e.roleInfo.content,variables:e.roleInfo.variables}:void 0,session_property:{is_auto_clear:e.sessionProperty?.isAutoClear,is_auto_clac_prompt:e.sessionProperty?.isAutoCalcPrompt}}),tYt=e=>({session_code:e.sessionCode,session_content_ids:e.sessionContentIds,rate:e.rate,comment:e.comment,labels:e.labels}),nYt=e=>({sessionCode:e.session_code,sessionContentIds:e.session_content_ids,rate:e.rate,comment:e.comment,labels:e.lables});function rYt(e,t,n,r,i,a,o){try{var s=e[a](o),l=s.value}catch(e){n(e);return}s.done?t(l):Promise.resolve(l).then(r,i)}function w9(e){return function(){var t=this,n=arguments;return new Promise(function(r,i){var a=e.apply(t,n);function o(e){rYt(a,r,i,o,s,`next`,e)}function s(e){rYt(a,r,i,o,s,`throw`,e)}o(void 0)})}}function iYt(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function T9(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t],r=Object.keys(n);typeof Object.getOwnPropertySymbols==`function`&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){iYt(e,t,n[t])})}return e}function aYt(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function oYt(e,t){return t??={},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):aYt(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}),e}var sYt=()=>`temp_${Date.now()}_${Math.random().toString(36).slice(2,9)}`,cYt=e=>{let n=(0,t.ref)([]),r=(0,t.ref)(!1),i=(0,t.ref)(!1);return{list:n,isListLoading:r,isDeleteLoading:i,getMessages:t=>(r.value=!0,e.http?.message.getMessages(t).then(e=>{n.value=e}).finally(()=>{r.value=!1})),clearMessages:()=>{let t=n.value.map(e=>e.id);return e.http?.message.batchDeleteMessages(t).then(()=>{n.value=[]})},getCurrentLoadingMessage:()=>n.value.findLast(e=>[v9.Pending,v9.Streaming].includes(e.status)),getMessageByMessageId:e=>n.value.find(t=>t.messageId===e),modifyMessage:e=>{n.value=n.value.map(t=>t.messageId===e.messageId?e:t)},plusMessage:e=>{n.value.push(e)},createAndPlusMessage:function(){var t=w9(function*(t){let r=sYt(),i=oYt(T9({},t),{id:r,messageId:r});n.value.push(i);try{let i=yield e.http?.message.plusMessage(t);if(i){let e=n.value.findIndex(e=>e.messageId===r);if(e!==-1){let r=T9({},i,`property`in t&&t.property?{property:t.property}:{});n.value[e]=r}}}catch(e){let t=n.value.findIndex(e=>e.messageId===r);throw t!==-1&&(n.value[t]=oYt(T9({},n.value[t]),{status:v9.Error})),e}});return function(e){return t.apply(this,arguments)}}(),deleteMessages:function(){var t=w9(function*(t){let r=t.reduce((e,t)=>(t.role===_9.User&&e.push(t.id),e),[]);if(r.length<=0)return;let a=[...n.value];n.value=n.value.filter(e=>!t.includes(e)),i.value=!0;try{yield e.http?.message.batchDeleteMessages(r)}catch(e){throw n.value=a,e}finally{i.value=!1}});return function(e){return t.apply(this,arguments)}}(),shareMessages:function(){var t=w9(function*(t,n,r){let i=n.reduce((e,t)=>(t.role===_9.User&&e.push(t.id),e),[]);if(!(i.length<=0))return e.http?.message.shareMessages(t,i,r)});return function(e,n,r){return t.apply(this,arguments)}}(),getFlowAgentTaskInfo:t=>e.http?.message.getFlowAgentTaskInfo(t),getFlowAgentTaskNodeInfo:(t,n)=>e.http?.message.getFlowAgentTaskNodeInfo(t,n),reset:()=>{n.value=[],r.value=!1,i.value=!1}}},E9;(function(e){e.FlowAgentEnd=`flow_agent_end`,e.FlowAgentResult=`flow_agent_result`,e.FlowAgentStart=`flow_agent_start`,e.KnowledgeRagEnd=`knowledge_rag_end`,e.KnowledgeRagResult=`knowledge_rag_result`,e.KnowledgeRagStart=`knowledge_rag_start`,e.KnowledgeRagTextContent=`knowledge_rag_text_content`,e.ReferenceDocument=`reference_document`,e.TempMessage=`temp_message`})(E9||={});var D9;(function(e){e.ActivityDelta=`ACTIVITY_DELTA`,e.ActivitySnapshot=`ACTIVITY_SNAPSHOT`,e.Custom=`CUSTOM`,e.MessagesSnapshot=`MESSAGES_SNAPSHOT`,e.Raw=`RAW`,e.RunError=`RUN_ERROR`,e.RunFinished=`RUN_FINISHED`,e.RunStarted=`RUN_STARTED`,e.StateDelta=`STATE_DELTA`,e.StateSnapshot=`STATE_SNAPSHOT`,e.StepFinished=`STEP_FINISHED`,e.StepStarted=`STEP_STARTED`,e.TextMessageChunk=`TEXT_MESSAGE_CHUNK`,e.TextMessageContent=`TEXT_MESSAGE_CONTENT`,e.TextMessageEnd=`TEXT_MESSAGE_END`,e.TextMessageStart=`TEXT_MESSAGE_START`,e.ThinkingEnd=`THINKING_END`,e.ThinkingStart=`THINKING_START`,e.ThinkingTextMessageContent=`THINKING_TEXT_MESSAGE_CONTENT`,e.ThinkingTextMessageEnd=`THINKING_TEXT_MESSAGE_END`,e.ThinkingTextMessageStart=`THINKING_TEXT_MESSAGE_START`,e.ToolCallArgs=`TOOL_CALL_ARGS`,e.ToolCallChunk=`TOOL_CALL_CHUNK`,e.ToolCallEnd=`TOOL_CALL_END`,e.ToolCallResult=`TOOL_CALL_RESULT`,e.ToolCallStart=`TOOL_CALL_START`})(D9||={});var lYt;(function(e){e.Failed=`failed`,e.Running=`running`,e.Success=`success`,e.Suspended=`suspended`})(lYt||={});var uYt;(function(e){e.Blocked=`BLOCKED`,e.Created=`CREATED`,e.Failed=`FAILED`,e.Finished=`FINISHED`,e.LoopReady=`LOOP_READY`,e.Ready=`READY`,e.Revoked=`REVOKED`,e.RollBackFailed=`ROLL_BACK_FAILED`,e.RollBackSuccess=`ROLL_BACK_SUCCESS`,e.RollingBack=`ROLLING_BACK`,e.Running=`RUNNING`,e.Suspended=`SUSPENDED`})(uYt||={});function O9(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var k9=class{handleActivityDeltaEvent(e){}handleActivitySnapshotEvent(e){}handleCustomEvent(e){switch(e.name){case E9.FlowAgentStart:this.handleFlowAgentStartCustomEvent(e);break;case E9.FlowAgentResult:this.handleFlowAgentResultCustomEvent(e);break;case E9.FlowAgentEnd:this.handleFlowAgentEndCustomEvent(e);break;case E9.ReferenceDocument:this.handleReferenceDocumentCustomEvent(e);break;case E9.KnowledgeRagStart:this.handleKnowledgeRagStartCustomEvent(e);break;case E9.KnowledgeRagTextContent:this.handleKnowledgeRagTextContentCustomEvent(e);break;case E9.KnowledgeRagResult:this.handleKnowledgeRagResultCustomEvent(e);break;case E9.KnowledgeRagEnd:this.handleKnowledgeRagEndCustomEvent(e);break;case E9.TempMessage:this.handleTempMessageCustomEvent(e);break;default:break}}handleFlowAgentEndCustomEvent(e){let t=this.messageModule.getCurrentLoadingMessage();if(t&&t.role===_9.Activity&&t.activityType===g9.FlowAgent){let n=e.value;t.content.task_outputs=n.task_outputs,t.status=v9.Complete}}handleFlowAgentResultCustomEvent(e){let t=this.messageModule.getCurrentLoadingMessage();t&&t.role===_9.Activity&&t.activityType===g9.FlowAgent&&(t.content=e.value)}handleFlowAgentStartCustomEvent(e){let t=e.value;this.messageModule.plusMessage({role:_9.Activity,activityType:g9.FlowAgent,content:{nodes:{},task_id:Number(t.task_id),task_name:``,task_outputs:[],task_state:uYt.Created},status:v9.Streaming})}handleKnowledgeRagEndCustomEvent(e){let t=this.messageModule.getCurrentLoadingMessage();t&&t.role===_9.Activity&&t.activityType===g9.KnowledgeRag&&(t.status=v9.Complete)}handleKnowledgeRagResultCustomEvent(e){let t=this.messageModule.getCurrentLoadingMessage();t&&t.role===_9.Activity&&t.activityType===g9.KnowledgeRag&&(t.content.referenceDocument=e.value)}handleKnowledgeRagStartCustomEvent(e){this.messageModule.plusMessage({role:_9.Activity,activityType:g9.KnowledgeRag,content:{content:``,referenceDocument:[]},status:v9.Streaming})}handleKnowledgeRagTextContentCustomEvent(e){let t=this.messageModule.getCurrentLoadingMessage();if(t&&t.role===_9.Activity&&t.activityType===g9.KnowledgeRag){let n=e.value;t.content.content=n.cover?n.chunk.content:t.content.content+n.chunk.content}}handleMessagesSnapshotEvent(e){e.messages&&e.messages.length>0&&(this.messageModule.list.value=e.messages.map(S9))}handleRawEvent(e){}handleReferenceDocumentCustomEvent(e){this.messageModule.plusMessage({role:_9.Activity,activityType:g9.ReferenceDocument,content:e.value,status:v9.Complete})}handleRunErrorEvent(e){let t=this.messageModule.getCurrentLoadingMessage();t&&(t.status=v9.Complete),this.messageModule.plusMessage({role:_9.Assistant,content:e.message,status:v9.Error})}handleRunFinishedEvent(e){let t=this.messageModule.getCurrentLoadingMessage();t&&(t.status=v9.Complete)}handleRunStartedEvent(e){}handleStateDeltaEvent(e){}handleStateSnapshotEvent(e){}handleStepFinishedEvent(e){}handleStepStartedEvent(e){}handleTempMessageCustomEvent(e){let t=e.value;this.messageModule.plusMessage({role:_9.Assistant,content:t.message,status:t.status})}handleTextMessageChunkEvent(e){let t=this.messageModule.getCurrentLoadingMessage();t?t.content+=e.delta||``:this.messageModule.plusMessage({role:e.role,content:e.delta||``,status:v9.Complete,messageId:e.messageId})}handleTextMessageContentEvent(e){let t=this.messageModule.getMessageByMessageId(e.messageId);t&&(t.content+=e.delta)}handleTextMessageEndEvent(e){let t=this.messageModule.getMessageByMessageId(e.messageId);t&&(t.status=v9.Complete)}handleTextMessageStartEvent(e){this.messageModule.plusMessage({role:e.role,content:``,status:v9.Streaming,messageId:e.messageId})}handleThinkingEndEvent(e){let t=this.messageModule.getCurrentLoadingMessage();t&&t.role===_9.Reasoning&&(t.duration=e.duration,t.status=v9.Complete)}handleThinkingStartEvent(e){this.messageModule.plusMessage({role:_9.Reasoning,content:[],status:v9.Streaming})}handleThinkingTextMessageContentEvent(e){let t=this.messageModule.getCurrentLoadingMessage();t&&t.role===_9.Reasoning&&(t.content[t.content.length-1]+=e.delta)}handleThinkingTextMessageEndEvent(e){}handleThinkingTextMessageStartEvent(e){let t=this.messageModule.getCurrentLoadingMessage();t&&t.role===_9.Reasoning&&t.content.push(``)}handleToolCallArgsEvent(e){this.messageModule.list.value.forEach(t=>{t.role===_9.Assistant&&t.toolCalls&&t.toolCalls.forEach(t=>{t.id===e.toolCallId&&(t.function.arguments+=e.delta)})})}handleToolCallChunkEvent(e){}handleToolCallEndEvent(e){this.messageModule.list.value.forEach(t=>{t.role===_9.Assistant&&t.toolCalls&&t.toolCalls.some(t=>t.id===e.toolCallId)&&(t.status=v9.Complete)})}handleToolCallResultEvent(e){this.messageModule.plusMessage({role:_9.Tool,content:e.content,duration:e.duration,status:v9.Complete,toolCallId:e.toolCallId,messageId:e.messageId})}handleToolCallStartEvent(e){this.messageModule.plusMessage({role:_9.Assistant,content:``,status:v9.Streaming,toolCalls:[{id:e.toolCallId,type:y9.Function,function:{mcpName:e.mcpName,name:e.toolCallName,arguments:``,description:e.description}}]})}injectMessageModule(e){this.messageModule=e}onDone(){var e,t;(e=(t=this).onDoneCallback)==null||e.call(t)}onError(e){var t,n;this.messageModule.plusMessage({role:_9.Assistant,content:e.message,status:v9.Error}),(t=(n=this).onErrorCallback)==null||t.call(n,e)}onMessage(e){var t,n;let r=e;switch((t=(n=this).onMessageCallback)==null||t.call(n,r),r.type){case D9.ActivityDelta:this.handleActivityDeltaEvent(r);break;case D9.ActivitySnapshot:this.handleActivitySnapshotEvent(r);break;case D9.Custom:this.handleCustomEvent(r);break;case D9.MessagesSnapshot:this.handleMessagesSnapshotEvent(r);break;case D9.Raw:this.handleRawEvent(r);break;case D9.RunError:this.handleRunErrorEvent(r);break;case D9.RunFinished:this.handleRunFinishedEvent(r);break;case D9.RunStarted:this.handleRunStartedEvent(r);break;case D9.StateDelta:this.handleStateDeltaEvent(r);break;case D9.StateSnapshot:this.handleStateSnapshotEvent(r);break;case D9.StepFinished:this.handleStepFinishedEvent(r);break;case D9.StepStarted:this.handleStepStartedEvent(r);break;case D9.TextMessageChunk:this.handleTextMessageChunkEvent(r);break;case D9.TextMessageContent:this.handleTextMessageContentEvent(r);break;case D9.TextMessageEnd:this.handleTextMessageEndEvent(r);break;case D9.TextMessageStart:this.handleTextMessageStartEvent(r);break;case D9.ThinkingEnd:this.handleThinkingEndEvent(r);break;case D9.ThinkingStart:this.handleThinkingStartEvent(r);break;case D9.ThinkingTextMessageContent:this.handleThinkingTextMessageContentEvent(r);break;case D9.ThinkingTextMessageEnd:this.handleThinkingTextMessageEndEvent(r);break;case D9.ThinkingTextMessageStart:this.handleThinkingTextMessageStartEvent(r);break;case D9.ToolCallArgs:this.handleToolCallArgsEvent(r);break;case D9.ToolCallChunk:this.handleToolCallChunkEvent(r);break;case D9.ToolCallEnd:this.handleToolCallEndEvent(r);break;case D9.ToolCallResult:this.handleToolCallResultEvent(r);break;case D9.ToolCallStart:this.handleToolCallStartEvent(r);break;default:break}}onStart(){var e,t;(e=(t=this).onStartCallback)==null||e.call(t)}constructor(e){O9(this,`messageModule`,void 0),O9(this,`onDoneCallback`,void 0),O9(this,`onErrorCallback`,void 0),O9(this,`onMessageCallback`,void 0),O9(this,`onStartCallback`,void 0),this.onDoneCallback=e?.onDone,this.onErrorCallback=e?.onError,this.onMessageCallback=e?.onMessage,this.onStartCallback=e?.onStart}};function dYt(e,t,n,r,i,a,o){try{var s=e[a](o),l=s.value}catch(e){n(e);return}s.done?t(l):Promise.resolve(l).then(r,i)}function A9(e){return function(){var t=this,n=arguments;return new Promise(function(r,i){var a=e.apply(t,n);function o(e){dYt(a,r,i,o,s,`next`,e)}function s(e){dYt(a,r,i,o,s,`throw`,e)}o(void 0)})}}function fYt(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function j9(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t],r=Object.keys(n);typeof Object.getOwnPropertySymbols==`function`&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){fYt(e,t,n[t])})}return e}var pYt=(e,n)=>{let r=(0,t.ref)(null),i=(0,t.ref)(!1),a=(0,t.ref)(!1),o=n||new k9,s=null,l=()=>(i.value=!0,e.http?.agent.getAgentInfo().then(e=>{r.value=e}).finally(()=>{i.value=!1})),u=(t,n)=>{let r=t.promptSetting?.content?.at(-1);if(r?.role===_9.Pause){var i;(i=e.message)==null||i.createAndPlusMessage({role:_9.Assistant,content:r.content,status:v9.Complete,sessionCode:n,property:{extra:{pause:!0}}})}},d=function(){var t=A9(function*(t,n,r){var i;o instanceof k9&&o.injectMessageModule(e.message),s=new AbortController,(i=e.http)==null||i.fetchClient.streamRequest(j9({url:n||`chat_completion/`,method:`POST`,data:{session_code:t},controller:s,onDone:()=>{var e;a.value=!1,(e=o.onDone)==null||e.call(o)},onError:e=>{var t;a.value=!1,(t=o.onError)==null||t.call(o,e)},onMessage:e=>{var t;(t=o.onMessage)==null||t.call(o,e)},onStart:()=>{var e;a.value=!0,(e=o.onStart)==null||e.call(o)}},r))});return function(e,n,r){return t.apply(this,arguments)}}(),f=function(){var t=A9(function*(t,n,r,i,a){yield e.message?.createAndPlusMessage(j9({role:_9.User,content:t,status:v9.Complete,sessionCode:n},a&&{property:a})),d(n,r,i)});return function(e,n,r,i,a){return t.apply(this,arguments)}}(),p=(t,n,r)=>{let i=e.message?.list.value.at(-1);(i?.status===v9.Streaming||i?.role===_9.User)&&d(t,n,r)},m=()=>{var e;s==null||(e=s.abort)==null||e.call(s),s=null},h=function(){var t=A9(function*(t){return e.http.message?.stopChat(t)});return function(e){return t.apply(this,arguments)}}();return{info:r,isInfoLoading:i,isChatting:a,chat:f,handleRole:u,resendMessage:function(){var t=A9(function*(t,n,r,i,a){let o=e.message?.list.value||[],s=o.findIndex(e=>String(e.id)===t);if(s===-1)throw Error(`Message not found: ${t}`);let l=o[s];if(l.role!==_9.User)throw Error(`Can only resend user messages`);let u=l.content,f=l.property,p=r??u,m=o.slice(s),h=e.message?.deleteMessages(m),g=e.message?.createAndPlusMessage(j9({role:_9.User,content:p,status:v9.Complete,sessionCode:n},f&&{property:f}));d(n,i,a),Promise.all([h,g]).catch(e=>{console.error(`[resendMessage] API error:`,e)})});return function(e,n,r,i,a){return t.apply(this,arguments)}}(),resumeStreamingChat:p,abortChat:m,stopChat:h,getAgentInfo:l,reset:e=>{o=e||new k9,r.value=null,i.value=!1}}};function mYt(e,t,n,r,i,a,o){try{var s=e[a](o),l=s.value}catch(e){n(e);return}s.done?t(l):Promise.resolve(l).then(r,i)}function hYt(e){return function(){var t=this,n=arguments;return new Promise(function(r,i){var a=e.apply(t,n);function o(e){mYt(a,r,i,o,s,`next`,e)}function s(e){mYt(a,r,i,o,s,`throw`,e)}o(void 0)})}}function M9(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function N9(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t],r=Object.keys(n);typeof Object.getOwnPropertySymbols==`function`&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){M9(e,t,n[t])})}return e}function gYt(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function P9(e,t){return t??={},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):gYt(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}),e}var _Yt=class{clear(){this.handlers=[]}eject(e){this.handlers[e]&&(this.handlers[e]=null)}forEach(e){this.handlers.forEach(t=>{t!==null&&e(t)})}use(e,t){return this.handlers.push({fulfilled:e,rejected:t}),this.handlers.length-1}constructor(){M9(this,`handlers`,[])}},vYt=class e{applyResponseErrorInterceptors(e){let t=e;return this.interceptors.response.forEach(e=>{e.rejected&&(t=e.rejected(t))}),t}create(t){return new e(L9(this.defaults,t||{}))}delete(e,t,n){return this.request(P9(N9({},n),{url:e,method:`DELETE`,params:t}))}get(e,t,n){return this.request(P9(N9({},n),{url:e,method:`GET`,params:t}))}head(e,t,n){return this.request(P9(N9({},n),{url:e,method:`HEAD`,params:t}))}options(e,t,n){return this.request(P9(N9({},n),{url:e,method:`OPTIONS`,params:t}))}patch(e,t,n){return this.request(P9(N9({},n),{url:e,method:`PATCH`,data:t}))}post(e,t,n){return this.request(P9(N9({},n),{url:e,method:`POST`,data:t}))}prepareRequest(e,t=!1){let n=L9(this.defaults,e);this.interceptors.request.forEach(e=>{if(e.fulfilled)try{n=e.fulfilled(n)}catch(t){throw e.rejected?e.rejected(t):t}});let r=n.url||``;n.baseURL&&!r.startsWith(`http`)&&(r=n.baseURL+r),r=yYt(r,n.params);let i=I9(n.data),a=new Headers(I9(n.headers));t&&!a.has(`Accept`)&&a.set(`Accept`,`text/event-stream`),i!=null&&(n.transformRequest?i=n.transformRequest(i,I9(n.headers)):a.get(`Content-Type`)?.includes(`application/json`)&&typeof i==`object`&&!(i instanceof FormData)&&!(i instanceof Blob)&&!(i instanceof ArrayBuffer)&&(i=JSON.stringify(i)));let o=n.controller?n.controller:new AbortController,s={method:n.method,credentials:n.credentials,mode:n.mode,headers:a,body:i,signal:o.signal};return{url:r,requestConfig:n,fetchConfig:s,controller:o}}put(e,t,n){return this.request(P9(N9({},n),{url:e,method:`PUT`,data:t}))}request(e){var t=this;return hYt(function*(){let{url:n,fetchConfig:r,requestConfig:i,controller:a}=t.prepareRequest(e),o=i.timeout&&i.timeout>0?setTimeout(()=>a.abort(),i.timeout):void 0;try{let e=yield fetch(n,r);o&&clearTimeout(o);let a,s=i.responseType||`json`;try{switch(s){case`json`:a=yield e.json();break;case`text`:a=yield e.text();break;case`blob`:a=yield e.blob();break;case`arrayBuffer`:a=yield e.arrayBuffer();break;case`formData`:a=yield e.formData();break;default:a=yield e.json()}}catch{a=null}i.transformResponse&&(a=i.transformResponse(a));let l={data:a,status:e.status,statusText:e.statusText,headers:e.headers,config:i};if(!(i.validateStatus||t.defaults.validateStatus)(e.status))throw F9(l.data?.error?.message||`Request failed with status code ${e.status}`,i,`ERR_BAD_RESPONSE`,l);let u=l;t.interceptors.response.forEach(e=>{if(e.fulfilled)try{u=e.fulfilled(u)}catch(t){throw e.rejected?e.rejected(t):t}}),u instanceof Promise&&(u=yield u);let d=u.data;if(![0,`success`].includes(d.code))throw F9(d.message,i,d.code,u);return d.data}catch(e){if(o&&clearTimeout(o),e instanceof Error&&e.name===`AbortError`){let e=F9(`Request timeout`,i,`ECONNABORTED`,void 0);throw t.applyResponseErrorInterceptors(e)}let n=e.isAxiosError===!0?e:F9(e.message,i,e.code,void 0);throw t.applyResponseErrorInterceptors(n)}})()}stream(e,t){return this.streamRequest(P9(N9({},t),{url:e}))}streamRequest(e){var t=this;return hYt(function*(){let{url:n,fetchConfig:r,requestConfig:i}=t.prepareRequest(e,!0);try{var a;let u=yield fetch(n,r);if(!(i.validateStatus||t.defaults.validateStatus)(u.status)){var o;let t=`Request failed with status code ${u.status}`;try{let e=yield u.json();e!=null&&e.error?.message&&(t=e.error.message)}catch{t=`Request failed with status code ${u.status}`}let n=F9(t,i,`ERR_BAD_RESPONSE`,void 0);(o=e.onError)==null||o.call(e,n);return}(a=e.onStart)==null||a.call(e);let d=u.body?.pipeThrough(new window.TextDecoderStream).getReader();if(!d){var s;let t=Error(`IResponse body is not readable`);(s=e.onError)==null||s.call(e,t);return}let f=``,p=e=>{try{return JSON.parse(e),!0}catch{return!1}};for(;;){let{value:t,done:n}=yield d.read();if(n){var l;(l=e.onDone)==null||l.call(e);break}(f+t.toString()).split(`
3038
- `).forEach(t=>{let n=t.replace(`data:`,``).trim();if(p(n)){var r;let t=JSON.parse(n);(r=e.onMessage)==null||r.call(e,t),f=``}else n&&(f=n)})}}catch(t){if(t instanceof Error)if(t.name===`AbortError`){var u;(u=e.onDone)==null||u.call(e)}else{var d;(d=e.onError)==null||d.call(e,t)}throw t}})()}constructor(e={}){M9(this,`defaults`,void 0),M9(this,`interceptors`,void 0),this.defaults=L9({method:`GET`,headers:{"Content-Type":`application/json`},timeout:3e4,responseType:`json`,credentials:`include`,mode:`cors`,validateStatus:e=>e>=200&&e<300},e),this.interceptors={request:new _Yt,response:new _Yt}}};function yYt(e,t){if(!t)return e;let n=new URLSearchParams;Object.keys(t).forEach(e=>{let r=t[e];r!=null&&(Array.isArray(r)?r.forEach(t=>n.append(e,String(t))):n.append(e,String(r)))});let r=n.toString();return r?`${e}${e.includes(`?`)?`&`:`?`}${r}`:e}function F9(e,t,n,r){let i=Error(e);return i.config=t,i.code=String(n),i.response=r,i.isAxiosError=!0,i}function I9(e){return typeof e==`function`?e():e}function bYt(e){if(!e||typeof e!=`object`)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function L9(e,t){let n=N9({},e);for(let r in t){let i=t[r];if(bYt(i)){let t=e[r];n[r]=L9(t||{},i)}else n[r]=i}return n}new vYt;var xYt=e=>{let t=new vYt({baseURL:e.requestData.urlPrefix});return e.interceptors?.request&&t.interceptors.request.use(e.interceptors.request),e.interceptors?.response&&t.interceptors.response.use(e.interceptors.response),{fetchClient:t,reset:e=>{t.defaults.baseURL=e.requestData.urlPrefix,t.interceptors.request.clear(),t.interceptors.response.clear(),e.interceptors?.request&&t.interceptors.request.use(e.interceptors.request),e.interceptors?.response&&t.interceptors.response.use(e.interceptors.response)}}},SYt=e=>({getAgentInfo:t=>e.get(`agent/info/`,void 0,t).then(XJt)});function CYt(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function wYt(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t],r=Object.keys(n);typeof Object.getOwnPropertySymbols==`function`&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){CYt(e,t,n[t])})}return e}var TYt=e=>({getMessages:(t,n,r)=>e.get(`session_content/content/`,{session_code:t,limit:n},r).then(e=>e.map(S9)),plusMessage:(t,n)=>e.post(`session_content/`,$Jt(t),n).then(S9),modifyMessage:(t,n)=>e.put(`session_content/${t.id}/`,$Jt(t),n).then(S9),deleteMessage:(t,n)=>e.delete(`session_content/${t}/`,void 0,n),batchDeleteMessages:(t,n)=>e.post(`session_content/batch_delete/`,{ids:t},n),shareMessages:(t,n,r,i)=>e.post(`share/`,wYt({session_code:t,content_ids:n},r?{expired_at:r}:{}),i),stopChat:(t,n)=>e.post(`session_content/stop/`,{session_code:t},n),getFlowAgentTaskInfo:(t,n)=>e.get(`flow_agent/${t}/task_info/`,void 0,n),getFlowAgentTaskNodeInfo:(t,n,r)=>e.get(`flow_agent/${t}/task_node_info/${n}/`,void 0,r)});function EYt(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function DYt(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t],r=Object.keys(n);typeof Object.getOwnPropertySymbols==`function`&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){EYt(e,t,n[t])})}return e}function OYt(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function kYt(e,t){return t??={},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):OYt(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}),e}var AYt=e=>({clearSession:(t,n)=>e.post(`chat_completion/${t}/clear/`,void 0,n),getSessions:t=>e.get(`session/`,void 0,t).then(e=>e.map(C9)),plusSession:(t,n)=>e.post(`session/`,eYt(t),n).then(e=>C9(e)),modifySession:(t,n)=>e.put(`session/${t.sessionCode}/`,eYt(t),n).then(e=>C9(e)),deleteSession:(t,n)=>e.delete(`session/${t}/`,void 0,n),batchDeleteSessions:(t,n)=>e.post(`session/batch_delete/`,{session_codes:t},n),getSession:(t,n)=>e.get(`session/${t}/`,void 0,n).then(e=>C9(e)),postSessionFeedback:(t,n)=>e.post(`session_feedback/`,tYt(t),n).then(e=>nYt(e)),getSessionFeedbackReasons:(t,n)=>e.get(`session_feedback/reasons/`,{rate:t},n),renameSession:(t,n)=>e.post(`session/${t}/ai_rename/`,void 0,n).then(e=>C9(e)),uploadFile:(t,n,r)=>{let i=encodeURIComponent(n.name);return n.arrayBuffer().then(a=>e.post(`session/${t}/upload/${i}/`,a,kYt(DYt({},r),{headers:{"Content-Disposition":`attachment; filename="${n.name}"`}})))}}),jYt=e=>({agent:SYt(e),session:AYt(e),message:TYt(e),fetchClient:e});function MYt(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function NYt(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t],r=Object.keys(n);typeof Object.getOwnPropertySymbols==`function`&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){MYt(e,t,n[t])})}return e}function PYt(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function FYt(e,t){return t??={},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):PYt(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}),e}var IYt=e=>{let{fetchClient:t,reset:n}=xYt(e);return FYt(NYt({},jYt(t)),{reset:n})},LYt=()=>({agent:null,http:null,message:null,session:null,registerAgent(e){this.agent=e},registerHttp(e){this.http=e},registerMessage(e){this.message=e},registerSession(e){this.session=e}});function RYt(e,t,n,r,i,a,o){try{var s=e[a](o),l=s.value}catch(e){n(e);return}s.done?t(l):Promise.resolve(l).then(r,i)}function R9(e){return function(){var t=this,n=arguments;return new Promise(function(r,i){var a=e.apply(t,n);function o(e){RYt(a,r,i,o,s,`next`,e)}function s(e){RYt(a,r,i,o,s,`throw`,e)}o(void 0)})}}function zYt(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function BYt(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t],r=Object.keys(n);typeof Object.getOwnPropertySymbols==`function`&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){zYt(e,t,n[t])})}return e}var VYt=e=>{let n=(0,t.ref)([]),r=(0,t.ref)(null),i=(0,t.ref)(!1),a=(0,t.ref)(!1),o=(0,t.ref)(!1),s=(0,t.ref)(!1),l=(0,t.ref)(!1),u=(0,t.ref)(!1),d=(0,t.ref)(!1),f=e=>{n.value=n.value.map(t=>t.sessionCode===e.sessionCode?BYt({},t,e):t),r.value?.sessionCode===e.sessionCode&&(r.value=n.value.find(t=>t.sessionCode===e.sessionCode)??r.value)},p=()=>(a.value=!0,e.http?.session.getSessions().then(e=>{n.value=e}).finally(()=>{a.value=!1})),m=function(){var t=R9(function*(t,i){var a;if((a=e.agent)==null||a.abortChat(),r.value=n.value.find(e=>e.sessionCode===t)??null,i?.loadMessages!==!1){var o;yield e.message?.getMessages(t),(o=e.agent)==null||o.resumeStreamingChat(t)}else e.message&&(e.message.list.value=[])});return function(e,n){return t.apply(this,arguments)}}();return{list:n,current:r,isCurrentLoading:i,isListLoading:a,isCreateLoading:o,isUpdateLoading:s,isDeleteLoading:l,isBatchDeleteLoading:u,getSessions:p,chooseSession:m,getSession:t=>(i.value=!0,e.http?.session.getSession(t).then(e=>{r.value=e}).finally(()=>{i.value=!1})),createSession:function(){var t=R9(function*(t,r){o.value=!0;try{let i=yield e.http?.session.plusSession(t);i&&(n.value.unshift(i),yield m(i.sessionCode,{loadMessages:r?.loadMessages??!1}))}finally{o.value=!1}});return function(e,n){return t.apply(this,arguments)}}(),updateSession:t=>(s.value=!0,e.http?.session.modifySession(t).then(e=>{f(e)}).finally(()=>{s.value=!1})),deleteSession:function(){var t=R9(function*(t){l.value=!0;try{yield e.http?.session.deleteSession(t),n.value=n.value.filter(e=>e.sessionCode!==t),r.value?.sessionCode===t&&n.value[0]?.sessionCode&&(yield m(n.value[0].sessionCode))}finally{l.value=!1}});return function(e){return t.apply(this,arguments)}}(),batchDeleteSessions:function(){var t=R9(function*(t){if(t.length!==0){u.value=!0;try{yield e.http?.session.batchDeleteSessions(t);let i=new Set(t);n.value=n.value.filter(e=>!i.has(e.sessionCode)),r.value&&i.has(r.value.sessionCode)&&(n.value.length>0?yield m(n.value[0].sessionCode):(r.value=null,e.message&&(e.message.list.value=[])))}finally{u.value=!1}}});return function(e){return t.apply(this,arguments)}}(),postSessionFeedback:t=>e.http?.session.postSessionFeedback(t),getSessionFeedbackReasons:t=>e.http?.session.getSessionFeedbackReasons(t),renameSession:t=>(d.value=!0,e.http?.session.renameSession(t).then(e=>{f({sessionCode:e.sessionCode,sessionName:e.sessionName})}).finally(()=>{d.value=!1})),uploadFile:(t,n)=>e.http?.session.uploadFile(t,n),reset:()=>{n.value=[],r.value=null,i.value=!1,a.value=!1,o.value=!1,s.value=!1,l.value=!1,u.value=!1,d.value=!1}}},z9=e=>{let t=LYt(),n=IYt(e),r=pYt(t,e.protocol),i=cYt(t),a=VYt(t);return t.registerHttp(n),t.registerMessage(i),t.registerAgent(r),t.registerSession(a),{agent:r,session:a,message:i,http:n,reset:e=>{n.reset(e),r.reset(e.protocol),i.reset(),a.reset()}}},HYt=class{_isGenerating;_isStopLoading;agentModule;config;eventEmitter;messageModule;sessionModule;autoRenameSessionIfNeeded(e){this.sessionModule&&this.messageModule.list.value.length===1&&this.sessionModule.renameSession(e).catch(e=>{console.error(`[ChatBusinessManager] Auto rename session failed:`,e)})}emit(e,t){this.eventEmitter?.emit(e,t)}constructor(e,n,r=null,i=null,a={}){this.agentModule=e,this.messageModule=n,this.sessionModule=r,this.eventEmitter=i,this.config=a,this._isGenerating=(0,t.ref)(!1),this._isStopLoading=(0,t.ref)(!1)}get isGenerating(){return this._isGenerating}get isStopLoading(){return this._isStopLoading}get isMessagesLoading(){return this.messageModule.isListLoading}get messages(){return this.messageModule.list}get openingRemark(){return this.config.openingRemark||``}get predefinedQuestions(){return this.config.predefinedQuestions||[]}async batchDeleteMessages(e){try{await this.messageModule.deleteMessages(e);let t=e.map(e=>e.id).filter(Boolean);this.emit(`messages-batch-deleted`,{messageIds:t})}catch(e){throw console.error(`Failed to batch delete messages:`,e),this.emit(`chat-error`,{action:`batch-delete-messages`,error:e}),e}}async deleteMessage(e){try{await this.messageModule.deleteMessages([e]),this.emit(`message-deleted`,{messageId:e.id})}catch(e){throw console.error(`Failed to delete message:`,e),this.emit(`chat-error`,{action:`delete-message`,error:e}),e}}handleStreamEnd(){this._isGenerating.value=!1,this.emit(`receive-end`,{})}handleStreamError(e){this._isGenerating.value=!1,this.emit(`receive-error`,{error:e})}handleStreamStart(){this._isGenerating.value=!0,this.emit(`receive-start`,{})}async regenerateFromAIMessages(e,t){try{if(!e||e.length===0)throw Error(`No AI messages provided`);let n=this.messages.value,r=B7(n,e[0]);if(!r)throw Error(`No user message found before AI messages`);let i=r.id;if(i===void 0)throw Error(`User message has no id`);await this.regenerateMessage(String(i),t)}catch(e){throw console.error(`Failed to regenerate from AI messages:`,e),this.emit(`chat-error`,{action:`regenerate`,error:e}),e}}async regenerateMessage(e,t){try{let n=this.messages.value,r=n.findIndex(t=>String(t.id)===e);if(r===-1)throw Error(`Message not found: ${e}`);let i=n[r];if(i.role!==_9.User)throw Error(`Can only regenerate from user messages`);let a=n.slice(r),o=typeof i.content==`string`?i.content:JSON.stringify(i.content),s=i.property;this._isGenerating.value=!0;let l=this.messageModule.deleteMessages(a);this.agentModule.chat(o,t,void 0,void 0,s),this.emit(`chat-regenerate`,{messageId:e}),l.catch(e=>{console.error(`[regenerateMessage] Delete API error:`,e)})}catch(e){throw console.error(`Failed to regenerate message:`,e),this._isGenerating.value=!1,this.emit(`chat-error`,{action:`regenerate`,error:e}),e}}async resendMessageWithProperty(e,t,n,r){try{let i=this.messages.value,a=i.findIndex(t=>String(t.id)===e);if(a===-1)throw Error(`Message not found: ${e}`);if(i[a].role!==_9.User)throw Error(`Can only resend user messages`);let o=i.slice(a);this._isGenerating.value=!0;let s=this.messageModule.deleteMessages(o);this.agentModule.chat(n,t,void 0,void 0,r),this.emit(`chat-resend`,{messageId:e}),s.catch(e=>{console.error(`[resendMessageWithProperty] Delete API error:`,e)})}catch(e){throw console.error(`Failed to resend message with property:`,e),this._isGenerating.value=!1,this.emit(`chat-error`,{action:`resend`,error:e}),e}}async retryMessage(e){try{console.warn(`retryMessage not implemented yet`),this.emit(`chat-retry`,{messageId:e})}catch(e){throw console.error(`Failed to retry message:`,e),this.emit(`chat-error`,{action:`retry`,error:e}),e}}async sendMessage(e,t,n={}){try{if(!t)throw Error(`No active session. Please create or select a session first.`);this._isGenerating.value=!0,this.emit(`send-message`,{content:e}),await this.agentModule.chat(e,t,void 0,void 0,n.property),this.autoRenameSessionIfNeeded(t)}catch(e){throw console.error(`Failed to send message:`,e),this._isGenerating.value=!1,this.emit(`chat-error`,{action:`send`,error:e}),e}}async stopGeneration(){let e=this.sessionModule?.current?.value?.sessionCode??``;this._isStopLoading.value=!0;try{await this.agentModule.stopChat(e),this._isGenerating.value=!1,this.emit(`stop`,{})}catch(e){console.error(`Failed to stop generation:`,e),this.emit(`chat-error`,{action:`stop`,error:e})}finally{this._isStopLoading.value=!1}}},B9=class{agentModule;config;eventEmitter;sessionModule;emit(e,t){this.eventEmitter?.emit(e,t)}constructor(e,t=null,n=null,r={}){this.sessionModule=e,this.agentModule=t,this.eventEmitter=n,this.config=r}get currentSession(){return this.sessionModule.current}get isCreateLoading(){return this.sessionModule.isCreateLoading}get isCurrentLoading(){return this.sessionModule.isCurrentLoading}get isDeleteLoading(){return this.sessionModule.isDeleteLoading}get isListLoading(){return this.sessionModule.isListLoading}get isUpdateLoading(){return this.sessionModule.isUpdateLoading}get sessionList(){return this.sessionModule.list}async createNewSession(){return this.createSession({name:`新会话`,sessionCode:`new_session_${Date.now()}`})}async createSession(e={}){if(this.config.enableChatSession===!1)throw Error(`Chat session is disabled`);try{let t={sessionName:e.name||`新会话`,sessionCode:e.sessionCode||`session_${Date.now()}`,isTemporary:e.isTemporary||!1};await this.sessionModule.createSession(t);let n=this.agentModule?.info.value;n&&this.agentModule?.handleRole(n,t.sessionCode),this.emit(`session-created`,{session:this.sessionModule.current.value})}catch(e){throw console.error(`Failed to create session:`,e),this.emit(`session-error`,{action:`create`,error:e}),e}}async deleteSession(e){try{await this.sessionModule.deleteSession(e),this.emit(`session-deleted`,{sessionCode:e})}catch(e){throw console.error(`Failed to delete session:`,e),this.emit(`session-error`,{action:`delete`,error:e}),e}}async getSession(e){try{await this.sessionModule.getSession(e)}catch(e){throw console.error(`Failed to get session:`,e),this.emit(`session-error`,{action:`get`,error:e}),e}}async loadRecentSession(e){try{e?.skipLoadSessions||await this.loadSessions();let t=this.sessionList.value;if(this.config.initialSessionCode){await this.switchSession(this.config.initialSessionCode);return}if(t.length>0){let e=t[0];(e.sessionContentCount??0)>0?await this.createNewSession():await this.switchSession(e.sessionCode,{loadMessages:!1});return}await this.createNewSession()}catch(e){throw console.error(`Failed to load recent session:`,e),e}}async loadSessions(){try{await this.sessionModule.getSessions(),this.emit(`sessions-loaded`,{sessions:this.sessionList.value})}catch(e){throw console.error(`Failed to load sessions:`,e),this.emit(`session-error`,{action:`load`,error:e}),e}}async switchSession(e,t){try{await this.sessionModule.chooseSession(e,t),this.emit(`session-switched`,{session:this.sessionModule.current.value})}catch(e){throw console.error(`Failed to switch session:`,e),this.emit(`session-error`,{action:`switch`,error:e}),e}}async updateSessionName(e,t){try{let n=this.sessionList.value.find(t=>t.sessionCode===e);if(!n)throw Error(`Session not found: ${e}`);await this.sessionModule.updateSession({...n,sessionName:t}),this.emit(`session-updated`,{session:this.sessionModule.current.value})}catch(e){throw console.error(`Failed to update session name:`,e),this.emit(`session-error`,{action:`update`,error:e}),e}}},UYt=class{messageModule;sessionModule;constructor(e,t){this.messageModule=e,this.sessionModule=t}async shareMessages(e){if(e.length===0)throw Error(`No messages to share`);let t=this.sessionModule.current?.value?.sessionCode;if(!t)throw Error(`No active session`);let n=await this.messageModule.shareMessages(t,e);if(!n)throw Error(`Share failed: no result returned`);return{shareUrl:`${n.share_page}share-page/${n.share_token}`,userMessageIds:e.map(e=>String(e.id))}}},V9=class{_agentShortcuts;_effectiveShortcuts;_propsShortcuts;eventEmitter;emit(e,t){this.eventEmitter?.emit(e,t)}constructor(e=null,n=[]){this._propsShortcuts=(0,t.ref)(n),this._agentShortcuts=(0,t.ref)([]),this.eventEmitter=e,this._effectiveShortcuts=(0,t.computed)(()=>this._propsShortcuts.value.length>0?this._propsShortcuts.value:this._agentShortcuts.value.length>0?this._agentShortcuts.value:[])}get count(){return this._effectiveShortcuts.value.length}get effectiveShortcuts(){return this._effectiveShortcuts}get hasShortcuts(){return this._effectiveShortcuts.value.length>0}get shortcuts(){return this._effectiveShortcuts}addShortcut(e){this._propsShortcuts.value.push(e)}clear(){this._propsShortcuts.value=[],this._agentShortcuts.value=[]}filterByTextLength(e,t){return!e||e.length>t?[]:this._effectiveShortcuts.value}filterShortcuts(e,t){return t?this._effectiveShortcuts.value.filter(n=>t(n,e)):this._effectiveShortcuts.value}getShortcutById(e){return this._effectiveShortcuts.value.find(t=>t.id===e)}handleShortcutClick(e,t,n=`main`){this.emit(`shortcut-click`,{shortcut:e,selectedText:t,source:n})}limitShortcuts(e){return this._effectiveShortcuts.value.slice(0,e)}removeShortcut(e){this._propsShortcuts.value=this._propsShortcuts.value.filter(t=>t.id!==e)}setAgentShortcuts(e){this._agentShortcuts.value=e}setShortcuts(e){this._propsShortcuts.value=e}},WYt=class{_isCompressed;_isDraggingOrResizing;_nimbusMinimized;_panelVisible;_positionAndSize;cleanupFunctions;config;containerRef=null;debugMode;listeners;onceListeners;constructor(e={}){this.config=e,this.listeners=new Map,this.onceListeners=new Map,this.debugMode=e.debug??!1,this.cleanupFunctions=[],this._panelVisible=(0,t.ref)(e.initialPanelVisible??!1),this._nimbusMinimized=(0,t.ref)(e.initialNimbusMinimized??!1),this._isDraggingOrResizing=(0,t.ref)(!1),this._isCompressed=(0,t.ref)(!1),this._positionAndSize=(0,t.ref)({x:0,y:0,width:400,height:window.innerHeight})}get container(){return{updatePosition:this.updatePosition.bind(this),updateSize:this.updateSize.bind(this),updatePositionAndSize:this.updatePositionAndSize.bind(this),toggleCompression:this.toggleCompression.bind(this),expandForSidePanel:this.expandForSidePanel.bind(this),collapseSidePanel:this.collapseSidePanel.bind(this),positionAndSize:(0,t.computed)(()=>this.containerRef?.positionAndSize?.value??this._positionAndSize.value),isCompressed:(0,t.computed)(()=>this._isCompressed.value),isSidePanelExpanded:(0,t.computed)(()=>this.containerRef?.isSidePanelExpanded?.value??!1)}}get isCompressed(){return this._isCompressed}get isDraggingOrResizing(){return this._isDraggingOrResizing}get nimbus(){return{minimize:this.minimizeNimbus.bind(this),restore:this.restoreNimbus.bind(this),toggle:this.toggleNimbus.bind(this),isMinimized:(0,t.computed)(()=>this._nimbusMinimized.value)}}get nimbusMinimized(){return this._nimbusMinimized}get panel(){return{show:this.showPanel.bind(this),hide:this.hidePanel.bind(this),toggle:this.togglePanel.bind(this),isVisible:(0,t.computed)(()=>this._panelVisible.value)}}get panelVisible(){return this._panelVisible}get state(){return{panelVisible:this._panelVisible,nimbusMinimized:this._nimbusMinimized,isDraggingOrResizing:this._isDraggingOrResizing,positionAndSize:this._positionAndSize}}collapseSidePanel(){this.containerRef?.collapseSidePanel&&this.containerRef.collapseSidePanel()}destroy(){this.listeners.clear(),this.onceListeners.clear(),this.cleanupFunctions.forEach(e=>e()),this.cleanupFunctions=[],this.debugMode&&console.debug(`[ComponentManager] Destroyed`)}emit(e,t){this.debugMode&&console.debug(`[ComponentManager] Emitting "${e}"`,t);let n=this.listeners.get(e);n&&n.forEach(n=>{try{n(t)}catch(t){console.error(`[ComponentManager] Error in listener for "${e}":`,t)}});let r=this.onceListeners.get(e);if(r&&r.size>0){let n=Array.from(r);this.onceListeners.delete(e),n.forEach(n=>{try{n(t)}catch(t){console.error(`[ComponentManager] Error in once listener for "${e}":`,t)}})}}emitInternal(e,t){this.emit(e,t)}expandForSidePanel(e){this.containerRef?.expandForSidePanel&&this.containerRef.expandForSidePanel(e)}getConfig(){return this.config}getRegisteredEvents(){let e=new Set;return this.listeners.forEach((t,n)=>e.add(n)),this.onceListeners.forEach((t,n)=>e.add(n)),Array.from(e)}handleDragging(e){this._isDraggingOrResizing.value=!0,this._positionAndSize.value=e,this.emit(`dragging`,e)}handleDragStop(e){this._isDraggingOrResizing.value=!1,this._positionAndSize.value=e,this.emit(`drag-stop`,e)}handleNimbusClick(){this.emit(`nimbus-click`,{}),this.showPanel()}handlePopupClick(){this.emit(`popup-click`,{}),this.showPanel()}handlePopupShortcutClick(e){this.emit(`popup-shortcut-click`,{shortcut:e}),this.emit(`shortcut-click`,{shortcut:e,source:`popup`})}handleResizeStop(e){this._isDraggingOrResizing.value=!1,this._positionAndSize.value=e,this.emit(`resize-stop`,e)}handleResizing(e){this._isDraggingOrResizing.value=!0,this._positionAndSize.value=e,this.emit(`resizing`,e)}handleShortcutClick(e,t){this.emit(`shortcut-click`,{shortcut:e,source:t})}hasListeners(e){return this.listenerCount(e)>0}hidePanel(){this._panelVisible.value=!1,this.emit(`panel-hide`,{})}listenerCount(e){return(this.listeners.get(e)?.size??0)+(this.onceListeners.get(e)?.size??0)}minimizeNimbus(){this._nimbusMinimized.value=!0,this.emit(`nimbus-minimize`,{})}off(e,t){t?(this.listeners.get(e)?.delete(t),this.onceListeners.get(e)?.delete(t),this.debugMode&&console.debug(`[ComponentManager] Unsubscribed from "${e}", remaining: ${this.listenerCount(e)}`)):(this.listeners.delete(e),this.onceListeners.delete(e),this.debugMode&&console.debug(`[ComponentManager] Removed all listeners for "${e}"`))}on(e,t){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t),this.debugMode&&console.debug(`[ComponentManager] Subscribed to "${e}", total: ${this.listenerCount(e)}`),()=>{this.off(e,t)}}once(e,t){return this.onceListeners.has(e)||this.onceListeners.set(e,new Set),this.onceListeners.get(e).add(t),this.debugMode&&console.debug(`[ComponentManager] Subscribed once to "${e}"`),()=>{this.onceListeners.get(e)?.delete(t)}}restoreNimbus(){this._nimbusMinimized.value=!1,this.emit(`nimbus-restore`,{})}setCompressed(e){this._isCompressed.value=e}setContainerRef(e){this.containerRef=e,e?.isCompressed&&(this._isCompressed.value=e.isCompressed.value)}setDebugMode(e){this.debugMode=e}setDraggingOrResizing(e){this._isDraggingOrResizing.value=e}showPanel(e){this._panelVisible.value=!0,this.emit(`panel-show`,{sessionCode:e})}toggleCompression(){this.containerRef?this.containerRef.toggleCompression():this._isCompressed.value=!this._isCompressed.value}toggleNimbus(){this._nimbusMinimized.value?this.restoreNimbus():this.minimizeNimbus()}togglePanel(){this._panelVisible.value?this.hidePanel():this.showPanel()}updatePosition(e,t){this._positionAndSize.value={...this._positionAndSize.value,x:e,y:t}}updatePositionAndSize(e,t,n,r){this._positionAndSize.value={x:e,y:t,width:n,height:r}}updateSize(e,t){this._positionAndSize.value={...this._positionAndSize.value,width:e,height:t}}};function GYt(e){return new WYt(e)}var KYt={"panel-show":`show`,"panel-hide":`close`,"panel-toggle":null,"nimbus-click":null,"nimbus-minimize":null,"nimbus-restore":null,"popup-click":null,"popup-shortcut-click":null,dragging:`dragging`,resizing:`resizing`,"drag-stop":`drag-stop`,"resize-stop":`resize-stop`,"compression-toggle":null,"side-panel-expand":null,"side-panel-collapse":null,"send-message":`send-message`,"receive-start":`receive-start`,"receive-text":`receive-text`,"receive-end":`receive-end`,"receive-error":null,stop:`stop`,"chat-regenerate":null,"chat-retry":null,"message-deleted":null,"messages-batch-deleted":null,"session-created":null,"session-switched":null,"session-deleted":null,"session-updated":null,"sessions-loaded":null,"session-initialized":`session-initialized`,"session-error":null,"shortcut-click":`shortcut-click`,"chat-error":null,"sdk-error":`sdk-error`,"new-chat":`new-chat`,"history-click":`history-click`,"auto-generate-name":`auto-generate-name`,"help-click":`help-click`,rename:`rename`,share:`share`,close:`close`,"toggle-compression":null,"transfer-messages":`transfer-messages`,"share-messages":`share-messages`,"agent-info-loaded":null,error:null};function qYt(e,t){switch(e){case`send-message`:return[t.content];case`rename`:return[t.newName];case`history-click`:return[t.event];case`dragging`:case`resizing`:case`drag-stop`:case`resize-stop`:case`shortcut-click`:case`session-initialized`:case`sdk-error`:case`transfer-messages`:case`share-messages`:return[t];case`panel-show`:case`panel-hide`:case`receive-start`:case`receive-text`:case`receive-end`:case`stop`:case`new-chat`:case`auto-generate-name`:case`help-click`:case`share`:case`close`:return[];default:return[t]}}var JYt=class{_selectedMessageIds;_isSelectionMode;_editingSessionCode;_loadingStates;constructor(){this._selectedMessageIds=(0,t.ref)(new Set),this._isSelectionMode=(0,t.ref)(!1),this._editingSessionCode=(0,t.ref)(null),this._loadingStates=(0,t.reactive)({})}get isSelectionMode(){return this._isSelectionMode}get editingSessionCode(){return this._editingSessionCode}toggleSelectionMode(){this._isSelectionMode.value=!this._isSelectionMode.value,this._isSelectionMode.value||this.clearSelection()}enableSelectionMode(){this._isSelectionMode.value=!0}disableSelectionMode(){this._isSelectionMode.value=!1,this.clearSelection()}toggleMessageSelection(e){this._selectedMessageIds.value.has(e)?this._selectedMessageIds.value.delete(e):this._selectedMessageIds.value.add(e),this._selectedMessageIds.value=new Set(this._selectedMessageIds.value)}selectMessage(e){this._selectedMessageIds.value.add(e),this._selectedMessageIds.value=new Set(this._selectedMessageIds.value)}deselectMessage(e){this._selectedMessageIds.value.delete(e),this._selectedMessageIds.value=new Set(this._selectedMessageIds.value)}isMessageSelected(e){return this._selectedMessageIds.value.has(e)}clearSelection(){this._selectedMessageIds.value.clear(),this._selectedMessageIds.value=new Set(this._selectedMessageIds.value)}selectAllMessages(e){this._selectedMessageIds.value=new Set(e)}get selectedMessages(){return Array.from(this._selectedMessageIds.value)}get selectedCount(){return this._selectedMessageIds.value.size}get hasSelection(){return this._selectedMessageIds.value.size>0}startEditingSession(e){this._editingSessionCode.value=e}stopEditingSession(){this._editingSessionCode.value=null}isEditingSession(e){return e?this._editingSessionCode.value===e:this._editingSessionCode.value!==null}setLoading(e,t){this._loadingStates[e]=t}isLoading(e){return this._loadingStates[e]??!1}clearLoadingStates(){Object.keys(this._loadingStates).forEach(e=>{this._loadingStates[e]=!1})}reset(){this.clearSelection(),this.disableSelectionMode(),this.stopEditingSession(),this.clearLoadingStates()}};function YYt(e){let{props:n,emit:r,scrollToBottom:i}=e,a=(0,t.ref)(!1),o=(0,t.ref)(null),s=()=>n.chatHelper?!n.chatHelper.agent||!n.chatHelper.session||!n.chatHelper.message?{valid:!1,error:`[ChatBot] Invalid chatHelper: missing required modules (agent, session, message)`}:{valid:!0}:n.url?{valid:!0}:{valid:!1,error:`[ChatBot] Neither chatHelper nor url provided. Component requires at least one.`},l=(()=>{let e=s();if(!e.valid)return console.error(e.error),o.value=Error(e.error),null;if(n.chatHelper)return n.chatHelper;let t=new k9({onStart:()=>{r(`receive-start`)},onMessage:e=>{r(`receive-text`)},onDone:()=>{r(`receive-end`),i()},onError:e=>{r(`error`,e)}}),a=z9({requestData:{urlPrefix:Sqt(n.url),headers:n.requestOptions?.headers,data:n.requestOptions?.data},protocol:t});return t.injectMessageModule(a.message),a})(),u=!n.chatHelper,d=l?new B9(l.session,l.agent,null,{enableChatSession:!0,autoSwitchToInitialSession:!!n.sessionCode,loadRecentSessionOnMount:n.autoLoad,initialSessionCode:n.sessionCode}):null,f=l?new HYt(l.agent,l.message,l.session,null,{openingRemark:n.helloText,predefinedQuestions:n.prompts,placeholder:n.placeholder}):null,p=new V9(null,n.shortcuts||[]);return(0,t.onMounted)(async()=>{if(!(!l||o.value))try{if(u){if(await l.agent.getAgentInfo(),await l.session.getSessions(),n.sessionCode)await l.session.chooseSession(n.sessionCode);else if(l.session.list.value.length>0){let e=l.session.list.value[0];await l.session.chooseSession(e.sessionCode)}a.value=!0}else a.value=!0;r(`agent-info-loaded`,l)}catch(e){console.error(`Failed to initialize ChatBot:`,e),o.value=e,r(`error`,e)}}),(0,t.onBeforeUnmount)(()=>{u&&l&&l.agent.stopChat(l.session.current?.value?.sessionCode??``)}),{chatHelper:l,isStandaloneMode:u,isInitialized:a,initError:o,chatBusinessManager:f,sessionBusinessManager:d,shortcutManager:p}}function XYt(e){let{props:n,chatHelper:r,chatBusinessManager:i,sessionBusinessManager:a,shortcutManager:o,isStandaloneMode:s,isInitialized:l,selectedShortcut:u}=e,d=(0,t.computed)(()=>i?.isStopLoading.value?j3.StopLoading:((n.chatHelper||r)?.agent)?.isChatting?.value?j3.Streaming:j3.Complete),f=(0,t.computed)(()=>d.value===j3.Streaming?x8.Disabled:void 0),p=(0,t.computed)(()=>i?.messages.value??[]),m=(0,t.computed)(()=>i?.isMessagesLoading.value??!1);return{messageStatus:d,messageToolsStatus:f,messages:p,isMessagesLoading:m,isGenerating:(0,t.computed)(()=>i?.isGenerating.value??!1),currentSession:(0,t.computed)(()=>a?.currentSession.value??null),isWelcomeState:(0,t.computed)(()=>s&&!l.value?!1:!m.value&&p.value.length===0),openingRemark:(0,t.computed)(()=>r?.agent.info.value?.conversationSettings?.openingRemark||``),effectiveResources:(0,t.computed)(()=>n.resources?.length?n.resources:r?.agent.info.value?.resources??[]),effectivePrompts:(0,t.computed)(()=>n.prompts?.length?n.prompts:r?.agent.info.value?.conversationSettings?.predefinedQuestions??[]),effectiveSupportUpload:(0,t.computed)(()=>u.value?.supportUpload?u.value.supportUpload.vision===!0:r?.agent.info.value?.promptSetting?.supportUpload?.vision===!0),chatbotStyle:(0,t.computed)(()=>({height:typeof n.height==`number`?`${n.height}px`:n.height,maxWidth:typeof n.maxWidth==`number`?`${n.maxWidth}px`:n.maxWidth})),filteredShortcuts:(0,t.computed)(()=>o.shortcuts.value)}}function ZYt(e){let{emit:n,chatHelper:r,chatBusinessManager:i,selectedShortcut:a,selectedResources:o}=e,s=(0,t.shallowRef)([[]]),l=(0,t.shallowRef)(``),u=(e,t)=>{s.value=e,o.value=t},d=async(e,t={})=>{if(!i||!r)throw Error(`[ChatBot] Cannot send message: chatBusinessManager not initialized`);let a=r.session.current?.value?.sessionCode;if(!a)throw Error(`[ChatBot] Cannot send message: no active session`);s.value=[[]],l.value=``,o.value=[],n(`send-message`,typeof e==`string`?e:``),await i.sendMessage(e,a,t)},f=async e=>{let t=r?.session.current?.value?.sessionCode;if(!t)throw Error(`[ChatBot] Cannot upload: no active session`);let n=await r.session.uploadFile(t,e);if(!n?.download_url)throw Error(`[ChatBot] Upload failed: no download URL returned`);return n},p=async(e,t)=>{try{let t={};l.value&&(t.cite=l.value),a.value&&(t.command=a.value.id),o.value.length&&(t.resources=o.value),await d(e,Object.keys(t).length?{property:{extra:t}}:{})}catch(e){console.error(`Failed to send message:`,e),n(`error`,e)}},m=async()=>{await h()},h=async()=>{if(!i){console.error(`[ChatBot] Cannot stop generation: chatBusinessManager not initialized`);return}await i.stopGeneration(),n(`stop`)};return{userInput:s,cite:l,handleUpdateModelValue:u,doSendMessage:d,handleSendMessage:p,handleUpload:f,handleStopSending:m,stopGeneration:h}}function QYt(e){let{emit:t,chatHelper:n,isStandaloneMode:r}=e,i=async e=>{if(!(!n||e.length===0))try{await Cqt((await new UYt(n.message,n.session).shareMessages(e)).shareUrl),_c({message:`分享链接已复制到剪贴板`,theme:`success`})}catch(e){console.error(`[ChatBot] Failed to share messages:`,e),_c({message:`分享失败,请重试`,theme:`error`})}};return{handleConfirmShare:async e=>{r&&await i(e),t(`confirm-share`,e)}}}function $Yt(e){let{props:n,emit:r,shortcutManager:i,doSendMessage:a,selectedShortcut:o}=e,s=i.effectiveShortcuts,l=(e,t)=>{let n=e,r;if(r=n.enable_fill_back&&n.fill_back_component_key?n.fill_back_component_key:n.components?.find(e=>e.fillBack)?.key,r&&t){let e=n.components?.map(e=>e.key===r?{...e,default:t}:{...e,default:e.default??void 0});o.value={...n,components:e,formModel:{...n.formModel,[r]:t}}}else o.value={...n,formModel:{...n.formModel}}},u=(e,t)=>{let n=e.components||[];return{extra:{cite:{type:`structured`,title:e.alias||e.name,data:n.map(e=>({key:e.name||e.key,value:String(t[e.key]??``)}))},command:e.id,context:n.map(e=>({[e.key]:t[e.key],context_type:e.type,__label:e.name||e.key,__key:e.key,__value:t[e.key]}))}}},d=e=>{let t=e.property?.extra;return t?.shortcut?t.shortcut:t?.command?s.value.find(e=>e.id===t.command)??null:null},f=(e,t)=>{l(e,t),r(`shortcut-click`,{shortcut:e,source:`main`})},p=()=>{o.value=null};return(0,t.watch)(()=>n.shortcuts,e=>{i.setShortcuts(e||[])},{immediate:!0}),(0,t.watch)(()=>e.chatHelper?.agent.info.value?.conversationSettings?.commands,e=>{e&&i.setAgentShortcuts(e)},{immediate:!0}),{effectiveShortcuts:s,selectShortcutWithText:l,buildShortcutProperty:u,getShortcutFromMessage:d,handleSelectShortcut:f,handleCloseShortcut:p,handleShortcutSubmit:async e=>{if(!o.value){console.error(`[ChatBot] No selected shortcut`);return}let t=u(o.value,e),n=o.value.name,i=o.value;p();try{await a(n,{property:t})}catch(e){o.value=i,console.error(`[ChatBot] Failed to submit shortcut:`,e),r(`error`,e)}}}}function eXt(e){let{emit:t,chatHelper:n,chatBusinessManager:r,cite:i,focusInput:a,scrollToBottom:o,getShortcutFromMessage:s,buildShortcutProperty:l}=e,u=async e=>{if(!r||!n){console.error(`[ChatBot] Cannot delete messages: chatBusinessManager not initialized`);return}try{let t=r.messages.value,i=B7(t,e[0]);if(!i){console.error(`[ChatBot] No user message found before AI messages`);return}let a=[i,...e];await n.message.deleteMessages(a)}catch(e){console.error(`[ChatBot] Failed to delete messages:`,e),t(`error`,e)}},d=async e=>{if(!r||!n){console.error(`[ChatBot] Cannot regenerate: chatBusinessManager not initialized`);return}let i=n.session.current?.value?.sessionCode;if(!i){console.error(`[ChatBot] Cannot regenerate: no active session`);return}try{await r.regenerateFromAIMessages(e,i),o()}catch(e){console.error(`[ChatBot] Failed to regenerate:`,e),t(`error`,e)}},f=async e=>{if(!r||!n){console.error(`[ChatBot] Cannot delete message: chatHelper not initialized`);return}try{let t=r.messages.value,i=t.findIndex(t=>t===e);if(i===-1){console.error(`[ChatBot] User message not found in messages list`);return}let a=[];for(let e=i+1;e<t.length;e++){let n=t[e];if(n.role===A3.User)break;a.push(n)}let o=[e,...a];await n.message.deleteMessages(o)}catch(e){console.error(`[ChatBot] Failed to delete user message:`,e),t(`error`,e)}};return{handleAgentAction:async(e,t)=>{if(e.id===`cite`){i.value=t.filter(e=>e.role!==A3.Reasoning).map(e=>typeof e.content==`string`?e.content:JSON.stringify(e.content||``)).join(`
3038
+ `).forEach(t=>{let n=t.replace(`data:`,``).trim();if(p(n)){var r;let t=JSON.parse(n);(r=e.onMessage)==null||r.call(e,t),f=``}else n&&(f=n)})}}catch(t){if(t instanceof Error)if(t.name===`AbortError`){var u;(u=e.onDone)==null||u.call(e)}else{var d;(d=e.onError)==null||d.call(e,t)}throw t}})()}constructor(e={}){M9(this,`defaults`,void 0),M9(this,`interceptors`,void 0),this.defaults=L9({method:`GET`,headers:{"Content-Type":`application/json`},timeout:3e4,responseType:`json`,credentials:`include`,mode:`cors`,validateStatus:e=>e>=200&&e<300},e),this.interceptors={request:new _Yt,response:new _Yt}}};function yYt(e,t){if(!t)return e;let n=new URLSearchParams;Object.keys(t).forEach(e=>{let r=t[e];r!=null&&(Array.isArray(r)?r.forEach(t=>n.append(e,String(t))):n.append(e,String(r)))});let r=n.toString();return r?`${e}${e.includes(`?`)?`&`:`?`}${r}`:e}function F9(e,t,n,r){let i=Error(e);return i.config=t,i.code=String(n),i.response=r,i.isAxiosError=!0,i}function I9(e){return typeof e==`function`?e():e}function bYt(e){if(!e||typeof e!=`object`)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function L9(e,t){let n=N9({},e);for(let r in t){let i=t[r];if(bYt(i)){let t=e[r];n[r]=L9(t||{},i)}else n[r]=i}return n}new vYt;var xYt=e=>{let t=new vYt({baseURL:e.requestData.urlPrefix});return e.interceptors?.request&&t.interceptors.request.use(e.interceptors.request),e.interceptors?.response&&t.interceptors.response.use(e.interceptors.response),{fetchClient:t,reset:e=>{t.defaults.baseURL=e.requestData.urlPrefix,t.interceptors.request.clear(),t.interceptors.response.clear(),e.interceptors?.request&&t.interceptors.request.use(e.interceptors.request),e.interceptors?.response&&t.interceptors.response.use(e.interceptors.response)}}},SYt=e=>({getAgentInfo:t=>e.get(`agent/info/`,void 0,t).then(XJt)});function CYt(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function wYt(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t],r=Object.keys(n);typeof Object.getOwnPropertySymbols==`function`&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){CYt(e,t,n[t])})}return e}var TYt=e=>({getMessages:(t,n,r)=>e.get(`session_content/content/`,{session_code:t,limit:n},r).then(e=>e.map(S9)),plusMessage:(t,n)=>e.post(`session_content/`,$Jt(t),n).then(S9),modifyMessage:(t,n)=>e.put(`session_content/${t.id}/`,$Jt(t),n).then(S9),deleteMessage:(t,n)=>e.delete(`session_content/${t}/`,void 0,n),batchDeleteMessages:(t,n)=>e.post(`session_content/batch_delete/`,{ids:t},n),shareMessages:(t,n,r,i)=>e.post(`share/`,wYt({session_code:t,content_ids:n},r?{expired_at:r}:{}),i),stopChat:(t,n)=>e.post(`session_content/stop/`,{session_code:t},n),getFlowAgentTaskInfo:(t,n)=>e.get(`flow_agent/${t}/task_info/`,void 0,n),getFlowAgentTaskNodeInfo:(t,n,r)=>e.get(`flow_agent/${t}/task_node_info/${n}/`,void 0,r)});function EYt(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function DYt(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t],r=Object.keys(n);typeof Object.getOwnPropertySymbols==`function`&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){EYt(e,t,n[t])})}return e}function OYt(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function kYt(e,t){return t??={},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):OYt(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}),e}var AYt=e=>({clearSession:(t,n)=>e.post(`chat_completion/${t}/clear/`,void 0,n),getSessions:t=>e.get(`session/`,void 0,t).then(e=>e.map(C9)),plusSession:(t,n)=>e.post(`session/`,eYt(t),n).then(e=>C9(e)),modifySession:(t,n)=>e.put(`session/${t.sessionCode}/`,eYt(t),n).then(e=>C9(e)),deleteSession:(t,n)=>e.delete(`session/${t}/`,void 0,n),batchDeleteSessions:(t,n)=>e.post(`session/batch_delete/`,{session_codes:t},n),getSession:(t,n)=>e.get(`session/${t}/`,void 0,n).then(e=>C9(e)),postSessionFeedback:(t,n)=>e.post(`session_feedback/`,tYt(t),n).then(e=>nYt(e)),getSessionFeedbackReasons:(t,n)=>e.get(`session_feedback/reasons/`,{rate:t},n),renameSession:(t,n)=>e.post(`session/${t}/ai_rename/`,void 0,n).then(e=>C9(e)),uploadFile:(t,n,r)=>{let i=encodeURIComponent(n.name);return n.arrayBuffer().then(a=>e.post(`session/${t}/upload/${i}/`,a,kYt(DYt({},r),{headers:{"Content-Disposition":`attachment; filename="${n.name}"`}})))}}),jYt=e=>({agent:SYt(e),session:AYt(e),message:TYt(e),fetchClient:e});function MYt(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function NYt(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t],r=Object.keys(n);typeof Object.getOwnPropertySymbols==`function`&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){MYt(e,t,n[t])})}return e}function PYt(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function FYt(e,t){return t??={},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):PYt(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}),e}var IYt=e=>{let{fetchClient:t,reset:n}=xYt(e);return FYt(NYt({},jYt(t)),{reset:n})},LYt=()=>({agent:null,http:null,message:null,session:null,registerAgent(e){this.agent=e},registerHttp(e){this.http=e},registerMessage(e){this.message=e},registerSession(e){this.session=e}});function RYt(e,t,n,r,i,a,o){try{var s=e[a](o),l=s.value}catch(e){n(e);return}s.done?t(l):Promise.resolve(l).then(r,i)}function R9(e){return function(){var t=this,n=arguments;return new Promise(function(r,i){var a=e.apply(t,n);function o(e){RYt(a,r,i,o,s,`next`,e)}function s(e){RYt(a,r,i,o,s,`throw`,e)}o(void 0)})}}function zYt(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function BYt(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t],r=Object.keys(n);typeof Object.getOwnPropertySymbols==`function`&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){zYt(e,t,n[t])})}return e}var VYt=e=>{let n=(0,t.ref)([]),r=(0,t.ref)(null),i=(0,t.ref)(!1),a=(0,t.ref)(!1),o=(0,t.ref)(!1),s=(0,t.ref)(!1),l=(0,t.ref)(!1),u=(0,t.ref)(!1),d=(0,t.ref)(!1),f=e=>{n.value=n.value.map(t=>t.sessionCode===e.sessionCode?BYt({},t,e):t),r.value?.sessionCode===e.sessionCode&&(r.value=n.value.find(t=>t.sessionCode===e.sessionCode)??r.value)},p=()=>(a.value=!0,e.http?.session.getSessions().then(e=>{n.value=e}).finally(()=>{a.value=!1})),m=function(){var t=R9(function*(t,i){var a;if((a=e.agent)==null||a.abortChat(),r.value=n.value.find(e=>e.sessionCode===t)??null,i?.loadMessages!==!1){var o;yield e.message?.getMessages(t),(o=e.agent)==null||o.resumeStreamingChat(t)}else e.message&&(e.message.list.value=[])});return function(e,n){return t.apply(this,arguments)}}();return{list:n,current:r,isCurrentLoading:i,isListLoading:a,isCreateLoading:o,isUpdateLoading:s,isDeleteLoading:l,isBatchDeleteLoading:u,getSessions:p,chooseSession:m,getSession:t=>(i.value=!0,e.http?.session.getSession(t).then(e=>{r.value=e}).finally(()=>{i.value=!1})),createSession:function(){var t=R9(function*(t,r){o.value=!0;try{let i=yield e.http?.session.plusSession(t);i&&(n.value.unshift(i),yield m(i.sessionCode,{loadMessages:r?.loadMessages??!1}))}finally{o.value=!1}});return function(e,n){return t.apply(this,arguments)}}(),updateSession:t=>(s.value=!0,e.http?.session.modifySession(t).then(e=>{f(e)}).finally(()=>{s.value=!1})),deleteSession:function(){var t=R9(function*(t){l.value=!0;try{yield e.http?.session.deleteSession(t),n.value=n.value.filter(e=>e.sessionCode!==t),r.value?.sessionCode===t&&n.value[0]?.sessionCode&&(yield m(n.value[0].sessionCode))}finally{l.value=!1}});return function(e){return t.apply(this,arguments)}}(),batchDeleteSessions:function(){var t=R9(function*(t){if(t.length!==0){u.value=!0;try{yield e.http?.session.batchDeleteSessions(t);let i=new Set(t);n.value=n.value.filter(e=>!i.has(e.sessionCode)),r.value&&i.has(r.value.sessionCode)&&(n.value.length>0?yield m(n.value[0].sessionCode):(r.value=null,e.message&&(e.message.list.value=[])))}finally{u.value=!1}}});return function(e){return t.apply(this,arguments)}}(),postSessionFeedback:t=>e.http?.session.postSessionFeedback(t),getSessionFeedbackReasons:t=>e.http?.session.getSessionFeedbackReasons(t),renameSession:t=>(d.value=!0,e.http?.session.renameSession(t).then(e=>{f({sessionCode:e.sessionCode,sessionName:e.sessionName})}).finally(()=>{d.value=!1})),uploadFile:(t,n)=>e.http?.session.uploadFile(t,n),reset:()=>{n.value=[],r.value=null,i.value=!1,a.value=!1,o.value=!1,s.value=!1,l.value=!1,u.value=!1,d.value=!1}}},z9=e=>{let t=LYt(),n=IYt(e),r=pYt(t,e.protocol),i=cYt(t),a=VYt(t);return t.registerHttp(n),t.registerMessage(i),t.registerAgent(r),t.registerSession(a),{agent:r,session:a,message:i,http:n,reset:e=>{n.reset(e),r.reset(e.protocol),i.reset(),a.reset()}}},HYt=class{_isGenerating;_isStopLoading;agentModule;config;eventEmitter;messageModule;sessionModule;autoRenameSessionIfNeeded(e){this.sessionModule&&this.messageModule.list.value.length===1&&this.sessionModule.renameSession(e).catch(e=>{console.error(`[ChatBusinessManager] Auto rename session failed:`,e)})}emit(e,t){this.eventEmitter?.emit(e,t)}constructor(e,n,r=null,i=null,a={}){this.agentModule=e,this.messageModule=n,this.sessionModule=r,this.eventEmitter=i,this.config=a,this._isGenerating=(0,t.ref)(!1),this._isStopLoading=(0,t.ref)(!1)}get isGenerating(){return this._isGenerating}get isStopLoading(){return this._isStopLoading}get isMessagesLoading(){return this.messageModule.isListLoading}get messages(){return this.messageModule.list}get openingRemark(){return this.config.openingRemark||``}get predefinedQuestions(){return this.config.predefinedQuestions||[]}async batchDeleteMessages(e){try{await this.messageModule.deleteMessages(e);let t=e.map(e=>e.id).filter(Boolean);this.emit(`messages-batch-deleted`,{messageIds:t})}catch(e){throw console.error(`Failed to batch delete messages:`,e),this.emit(`chat-error`,{action:`batch-delete-messages`,error:e}),e}}async deleteMessage(e){try{await this.messageModule.deleteMessages([e]),this.emit(`message-deleted`,{messageId:e.id})}catch(e){throw console.error(`Failed to delete message:`,e),this.emit(`chat-error`,{action:`delete-message`,error:e}),e}}handleStreamEnd(){this._isGenerating.value=!1,this.emit(`receive-end`,{})}handleStreamError(e){this._isGenerating.value=!1,this.emit(`receive-error`,{error:e})}handleStreamStart(){this._isGenerating.value=!0,this.emit(`receive-start`,{})}async regenerateFromAIMessages(e,t){try{if(!e||e.length===0)throw Error(`No AI messages provided`);let n=this.messages.value,r=B7(n,e[0]);if(!r)throw Error(`No user message found before AI messages`);let i=r.id;if(i===void 0)throw Error(`User message has no id`);await this.regenerateMessage(String(i),t)}catch(e){throw console.error(`Failed to regenerate from AI messages:`,e),this.emit(`chat-error`,{action:`regenerate`,error:e}),e}}async regenerateMessage(e,t){try{let n=this.messages.value,r=n.findIndex(t=>String(t.id)===e);if(r===-1)throw Error(`Message not found: ${e}`);let i=n[r];if(i.role!==_9.User)throw Error(`Can only regenerate from user messages`);let a=n.slice(r),o=typeof i.content==`string`?i.content:JSON.stringify(i.content),s=i.property;this._isGenerating.value=!0;let l=this.messageModule.deleteMessages(a);this.agentModule.chat(o,t,void 0,void 0,s),this.emit(`chat-regenerate`,{messageId:e}),l.catch(e=>{console.error(`[regenerateMessage] Delete API error:`,e)})}catch(e){throw console.error(`Failed to regenerate message:`,e),this._isGenerating.value=!1,this.emit(`chat-error`,{action:`regenerate`,error:e}),e}}async resendMessageWithProperty(e,t,n,r){try{let i=this.messages.value,a=i.findIndex(t=>String(t.id)===e);if(a===-1)throw Error(`Message not found: ${e}`);if(i[a].role!==_9.User)throw Error(`Can only resend user messages`);let o=i.slice(a);this._isGenerating.value=!0;let s=this.messageModule.deleteMessages(o);this.agentModule.chat(n,t,void 0,void 0,r),this.emit(`chat-resend`,{messageId:e}),s.catch(e=>{console.error(`[resendMessageWithProperty] Delete API error:`,e)})}catch(e){throw console.error(`Failed to resend message with property:`,e),this._isGenerating.value=!1,this.emit(`chat-error`,{action:`resend`,error:e}),e}}async retryMessage(e){try{console.warn(`retryMessage not implemented yet`),this.emit(`chat-retry`,{messageId:e})}catch(e){throw console.error(`Failed to retry message:`,e),this.emit(`chat-error`,{action:`retry`,error:e}),e}}async sendMessage(e,t,n={}){try{if(!t)throw Error(`No active session. Please create or select a session first.`);this._isGenerating.value=!0,this.emit(`send-message`,{content:e}),await this.agentModule.chat(e,t,void 0,void 0,n.property),this.autoRenameSessionIfNeeded(t)}catch(e){throw console.error(`Failed to send message:`,e),this._isGenerating.value=!1,this.emit(`chat-error`,{action:`send`,error:e}),e}}async stopGeneration(){let e=this.sessionModule?.current?.value?.sessionCode??``;this._isStopLoading.value=!0;try{await this.agentModule.stopChat(e),this._isGenerating.value=!1,this.emit(`stop`,{})}catch(e){console.error(`Failed to stop generation:`,e),this.emit(`chat-error`,{action:`stop`,error:e})}finally{this._isStopLoading.value=!1}}},B9=class{agentModule;config;eventEmitter;sessionModule;emit(e,t){this.eventEmitter?.emit(e,t)}constructor(e,t=null,n=null,r={}){this.sessionModule=e,this.agentModule=t,this.eventEmitter=n,this.config=r}get currentSession(){return this.sessionModule.current}get isCreateLoading(){return this.sessionModule.isCreateLoading}get isCurrentLoading(){return this.sessionModule.isCurrentLoading}get isDeleteLoading(){return this.sessionModule.isDeleteLoading}get isListLoading(){return this.sessionModule.isListLoading}get isUpdateLoading(){return this.sessionModule.isUpdateLoading}get sessionList(){return this.sessionModule.list}async createNewSession(){return this.createSession({name:`新会话`,sessionCode:`new_session_${Date.now()}`})}async createSession(e={}){if(this.config.enableChatSession===!1)throw Error(`Chat session is disabled`);try{let t={sessionName:e.name||`新会话`,sessionCode:e.sessionCode||`session_${Date.now()}`,isTemporary:e.isTemporary||!1};await this.sessionModule.createSession(t);let n=this.agentModule?.info.value;n&&this.agentModule?.handleRole(n,t.sessionCode),this.emit(`session-created`,{session:this.sessionModule.current.value})}catch(e){throw console.error(`Failed to create session:`,e),this.emit(`session-error`,{action:`create`,error:e}),e}}async deleteSession(e){try{await this.sessionModule.deleteSession(e),this.emit(`session-deleted`,{sessionCode:e})}catch(e){throw console.error(`Failed to delete session:`,e),this.emit(`session-error`,{action:`delete`,error:e}),e}}async getSession(e){try{await this.sessionModule.getSession(e)}catch(e){throw console.error(`Failed to get session:`,e),this.emit(`session-error`,{action:`get`,error:e}),e}}async loadRecentSession(e){try{e?.skipLoadSessions||await this.loadSessions();let t=this.sessionList.value;if(this.config.initialSessionCode){await this.switchSession(this.config.initialSessionCode);return}if(t.length>0){let e=t[0];(e.sessionContentCount??0)>0?await this.createNewSession():await this.switchSession(e.sessionCode,{loadMessages:!1});return}await this.createNewSession()}catch(e){throw console.error(`Failed to load recent session:`,e),e}}async loadSessions(){try{await this.sessionModule.getSessions(),this.emit(`sessions-loaded`,{sessions:this.sessionList.value})}catch(e){throw console.error(`Failed to load sessions:`,e),this.emit(`session-error`,{action:`load`,error:e}),e}}async switchSession(e,t){try{await this.sessionModule.chooseSession(e,t),this.emit(`session-switched`,{session:this.sessionModule.current.value})}catch(e){throw console.error(`Failed to switch session:`,e),this.emit(`session-error`,{action:`switch`,error:e}),e}}async updateSessionName(e,t){try{let n=this.sessionList.value.find(t=>t.sessionCode===e);if(!n)throw Error(`Session not found: ${e}`);await this.sessionModule.updateSession({...n,sessionName:t}),this.emit(`session-updated`,{session:this.sessionModule.current.value})}catch(e){throw console.error(`Failed to update session name:`,e),this.emit(`session-error`,{action:`update`,error:e}),e}}},UYt=class{messageModule;sessionModule;constructor(e,t){this.messageModule=e,this.sessionModule=t}async shareMessages(e){if(e.length===0)throw Error(`No messages to share`);let t=this.sessionModule.current?.value?.sessionCode;if(!t)throw Error(`No active session`);let n=await this.messageModule.shareMessages(t,e);if(!n)throw Error(`Share failed: no result returned`);return{shareUrl:`${n.share_page}share-page/${n.share_token}`,userMessageIds:e.map(e=>String(e.id))}}},V9=class{_agentShortcuts;_effectiveShortcuts;_propsShortcuts;eventEmitter;emit(e,t){this.eventEmitter?.emit(e,t)}constructor(e=null,n=[]){this._propsShortcuts=(0,t.ref)(n),this._agentShortcuts=(0,t.ref)([]),this.eventEmitter=e,this._effectiveShortcuts=(0,t.computed)(()=>this._propsShortcuts.value.length>0?this._propsShortcuts.value:this._agentShortcuts.value.length>0?this._agentShortcuts.value:[])}get count(){return this._effectiveShortcuts.value.length}get effectiveShortcuts(){return this._effectiveShortcuts}get hasShortcuts(){return this._effectiveShortcuts.value.length>0}get shortcuts(){return this._effectiveShortcuts}addShortcut(e){this._propsShortcuts.value.push(e)}clear(){this._propsShortcuts.value=[],this._agentShortcuts.value=[]}filterByTextLength(e,t){return!e||e.length>t?[]:this._effectiveShortcuts.value}filterShortcuts(e,t){return t?this._effectiveShortcuts.value.filter(n=>t(n,e)):this._effectiveShortcuts.value}getShortcutById(e){return this._effectiveShortcuts.value.find(t=>t.id===e)}handleShortcutClick(e,t,n=`main`){this.emit(`shortcut-click`,{shortcut:e,selectedText:t,source:n})}limitShortcuts(e){return this._effectiveShortcuts.value.slice(0,e)}removeShortcut(e){this._propsShortcuts.value=this._propsShortcuts.value.filter(t=>t.id!==e)}setAgentShortcuts(e){this._agentShortcuts.value=e}setShortcuts(e){this._propsShortcuts.value=e}},WYt=class{_isCompressed;_isDraggingOrResizing;_nimbusMinimized;_panelVisible;_positionAndSize;cleanupFunctions;config;containerRef=null;debugMode;listeners;onceListeners;constructor(e={}){this.config=e,this.listeners=new Map,this.onceListeners=new Map,this.debugMode=e.debug??!1,this.cleanupFunctions=[],this._panelVisible=(0,t.ref)(e.initialPanelVisible??!1),this._nimbusMinimized=(0,t.ref)(e.initialNimbusMinimized??!1),this._isDraggingOrResizing=(0,t.ref)(!1),this._isCompressed=(0,t.ref)(!1),this._positionAndSize=(0,t.ref)({x:0,y:0,width:400,height:window.innerHeight})}get container(){return{updatePosition:this.updatePosition.bind(this),updateSize:this.updateSize.bind(this),updatePositionAndSize:this.updatePositionAndSize.bind(this),toggleCompression:this.toggleCompression.bind(this),expandForSidePanel:this.expandForSidePanel.bind(this),collapseSidePanel:this.collapseSidePanel.bind(this),positionAndSize:(0,t.computed)(()=>this.containerRef?.positionAndSize?.value??this._positionAndSize.value),isCompressed:(0,t.computed)(()=>this._isCompressed.value),isSidePanelExpanded:(0,t.computed)(()=>this.containerRef?.isSidePanelExpanded?.value??!1)}}get isCompressed(){return this._isCompressed}get isDraggingOrResizing(){return this._isDraggingOrResizing}get nimbus(){return{minimize:this.minimizeNimbus.bind(this),restore:this.restoreNimbus.bind(this),toggle:this.toggleNimbus.bind(this),isMinimized:(0,t.computed)(()=>this._nimbusMinimized.value)}}get nimbusMinimized(){return this._nimbusMinimized}get panel(){return{show:this.showPanel.bind(this),hide:this.hidePanel.bind(this),toggle:this.togglePanel.bind(this),isVisible:(0,t.computed)(()=>this._panelVisible.value)}}get panelVisible(){return this._panelVisible}get state(){return{panelVisible:this._panelVisible,nimbusMinimized:this._nimbusMinimized,isDraggingOrResizing:this._isDraggingOrResizing,positionAndSize:this._positionAndSize}}collapseSidePanel(){this.containerRef?.collapseSidePanel&&this.containerRef.collapseSidePanel()}destroy(){this.listeners.clear(),this.onceListeners.clear(),this.cleanupFunctions.forEach(e=>e()),this.cleanupFunctions=[],this.debugMode&&console.debug(`[ComponentManager] Destroyed`)}emit(e,t){this.debugMode&&console.debug(`[ComponentManager] Emitting "${e}"`,t);let n=this.listeners.get(e);n&&n.forEach(n=>{try{n(t)}catch(t){console.error(`[ComponentManager] Error in listener for "${e}":`,t)}});let r=this.onceListeners.get(e);if(r&&r.size>0){let n=Array.from(r);this.onceListeners.delete(e),n.forEach(n=>{try{n(t)}catch(t){console.error(`[ComponentManager] Error in once listener for "${e}":`,t)}})}}emitInternal(e,t){this.emit(e,t)}expandForSidePanel(e){this.containerRef?.expandForSidePanel&&this.containerRef.expandForSidePanel(e)}getConfig(){return this.config}getRegisteredEvents(){let e=new Set;return this.listeners.forEach((t,n)=>e.add(n)),this.onceListeners.forEach((t,n)=>e.add(n)),Array.from(e)}handleDragging(e){this._isDraggingOrResizing.value=!0,this._positionAndSize.value=e,this.emit(`dragging`,e)}handleDragStop(e){this._isDraggingOrResizing.value=!1,this._positionAndSize.value=e,this.emit(`drag-stop`,e)}handleNimbusClick(){this.emit(`nimbus-click`,{}),this.showPanel()}handlePopupClick(){this.emit(`popup-click`,{}),this.showPanel()}handlePopupShortcutClick(e){this.emit(`popup-shortcut-click`,{shortcut:e}),this.emit(`shortcut-click`,{shortcut:e,source:`popup`})}handleResizeStop(e){this._isDraggingOrResizing.value=!1,this._positionAndSize.value=e,this.emit(`resize-stop`,e)}handleResizing(e){this._isDraggingOrResizing.value=!0,this._positionAndSize.value=e,this.emit(`resizing`,e)}handleShortcutClick(e,t){this.emit(`shortcut-click`,{shortcut:e,source:t})}hasListeners(e){return this.listenerCount(e)>0}hidePanel(){this._panelVisible.value=!1,this.emit(`panel-hide`,{})}listenerCount(e){return(this.listeners.get(e)?.size??0)+(this.onceListeners.get(e)?.size??0)}minimizeNimbus(){this._nimbusMinimized.value=!0,this.emit(`nimbus-minimize`,{})}off(e,t){t?(this.listeners.get(e)?.delete(t),this.onceListeners.get(e)?.delete(t),this.debugMode&&console.debug(`[ComponentManager] Unsubscribed from "${e}", remaining: ${this.listenerCount(e)}`)):(this.listeners.delete(e),this.onceListeners.delete(e),this.debugMode&&console.debug(`[ComponentManager] Removed all listeners for "${e}"`))}on(e,t){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t),this.debugMode&&console.debug(`[ComponentManager] Subscribed to "${e}", total: ${this.listenerCount(e)}`),()=>{this.off(e,t)}}once(e,t){return this.onceListeners.has(e)||this.onceListeners.set(e,new Set),this.onceListeners.get(e).add(t),this.debugMode&&console.debug(`[ComponentManager] Subscribed once to "${e}"`),()=>{this.onceListeners.get(e)?.delete(t)}}restoreNimbus(){this._nimbusMinimized.value=!1,this.emit(`nimbus-restore`,{})}setCompressed(e){this._isCompressed.value=e}setContainerRef(e){this.containerRef=e,e?.isCompressed&&(this._isCompressed.value=e.isCompressed.value)}setDebugMode(e){this.debugMode=e}setDraggingOrResizing(e){this._isDraggingOrResizing.value=e}showPanel(e){this._panelVisible.value=!0,this.emit(`panel-show`,{sessionCode:e})}toggleCompression(){this.containerRef?this.containerRef.toggleCompression():this._isCompressed.value=!this._isCompressed.value}toggleNimbus(){this._nimbusMinimized.value?this.restoreNimbus():this.minimizeNimbus()}togglePanel(){this._panelVisible.value?this.hidePanel():this.showPanel()}updatePosition(e,t){this._positionAndSize.value={...this._positionAndSize.value,x:e,y:t}}updatePositionAndSize(e,t,n,r){this._positionAndSize.value={x:e,y:t,width:n,height:r}}updateSize(e,t){this._positionAndSize.value={...this._positionAndSize.value,width:e,height:t}}};function GYt(e){return new WYt(e)}var KYt={"panel-show":`show`,"panel-hide":`close`,"panel-toggle":null,"nimbus-click":null,"nimbus-minimize":null,"nimbus-restore":null,"popup-click":null,"popup-shortcut-click":null,dragging:`dragging`,resizing:`resizing`,"drag-stop":`drag-stop`,"resize-stop":`resize-stop`,"compression-toggle":null,"side-panel-expand":null,"side-panel-collapse":null,"send-message":`send-message`,"receive-start":`receive-start`,"receive-text":`receive-text`,"receive-end":`receive-end`,"receive-error":null,stop:`stop`,"chat-regenerate":null,"chat-retry":null,"message-deleted":null,"messages-batch-deleted":null,"session-created":null,"session-switched":null,"session-deleted":null,"session-updated":null,"sessions-loaded":null,"session-initialized":`session-initialized`,"session-error":null,"shortcut-click":`shortcut-click`,"chat-error":null,"sdk-error":`sdk-error`,"new-chat":`new-chat`,"history-click":`history-click`,"auto-generate-name":`auto-generate-name`,"help-click":`help-click`,rename:`rename`,share:`share`,close:`close`,"toggle-compression":null,"transfer-messages":`transfer-messages`,"share-messages":`share-messages`,"agent-info-loaded":null,error:null};function qYt(e,t){switch(e){case`send-message`:return[t.content];case`rename`:return[t.newName];case`history-click`:return[t.event];case`dragging`:case`resizing`:case`drag-stop`:case`resize-stop`:case`shortcut-click`:case`session-initialized`:case`sdk-error`:case`transfer-messages`:case`share-messages`:return[t];case`panel-show`:case`panel-hide`:case`receive-start`:case`receive-text`:case`receive-end`:case`stop`:case`new-chat`:case`auto-generate-name`:case`help-click`:case`share`:case`close`:return[];default:return[t]}}var JYt=class{_selectedMessageIds;_isSelectionMode;_editingSessionCode;_loadingStates;constructor(){this._selectedMessageIds=(0,t.ref)(new Set),this._isSelectionMode=(0,t.ref)(!1),this._editingSessionCode=(0,t.ref)(null),this._loadingStates=(0,t.reactive)({})}get isSelectionMode(){return this._isSelectionMode}get editingSessionCode(){return this._editingSessionCode}toggleSelectionMode(){this._isSelectionMode.value=!this._isSelectionMode.value,this._isSelectionMode.value||this.clearSelection()}enableSelectionMode(){this._isSelectionMode.value=!0}disableSelectionMode(){this._isSelectionMode.value=!1,this.clearSelection()}toggleMessageSelection(e){this._selectedMessageIds.value.has(e)?this._selectedMessageIds.value.delete(e):this._selectedMessageIds.value.add(e),this._selectedMessageIds.value=new Set(this._selectedMessageIds.value)}selectMessage(e){this._selectedMessageIds.value.add(e),this._selectedMessageIds.value=new Set(this._selectedMessageIds.value)}deselectMessage(e){this._selectedMessageIds.value.delete(e),this._selectedMessageIds.value=new Set(this._selectedMessageIds.value)}isMessageSelected(e){return this._selectedMessageIds.value.has(e)}clearSelection(){this._selectedMessageIds.value.clear(),this._selectedMessageIds.value=new Set(this._selectedMessageIds.value)}selectAllMessages(e){this._selectedMessageIds.value=new Set(e)}get selectedMessages(){return Array.from(this._selectedMessageIds.value)}get selectedCount(){return this._selectedMessageIds.value.size}get hasSelection(){return this._selectedMessageIds.value.size>0}startEditingSession(e){this._editingSessionCode.value=e}stopEditingSession(){this._editingSessionCode.value=null}isEditingSession(e){return e?this._editingSessionCode.value===e:this._editingSessionCode.value!==null}setLoading(e,t){this._loadingStates[e]=t}isLoading(e){return this._loadingStates[e]??!1}clearLoadingStates(){Object.keys(this._loadingStates).forEach(e=>{this._loadingStates[e]=!1})}reset(){this.clearSelection(),this.disableSelectionMode(),this.stopEditingSession(),this.clearLoadingStates()}};function YYt(e){let{props:n,emit:r,scrollToBottom:i}=e,a=(0,t.ref)(!1),o=(0,t.ref)(null),s=()=>n.chatHelper?!n.chatHelper.agent||!n.chatHelper.session||!n.chatHelper.message?{valid:!1,error:`[ChatBot] Invalid chatHelper: missing required modules (agent, session, message)`}:{valid:!0}:n.url?{valid:!0}:{valid:!1,error:`[ChatBot] Neither chatHelper nor url provided. Component requires at least one.`},l=(()=>{let e=s();if(!e.valid)return console.error(e.error),o.value=Error(e.error),null;if(n.chatHelper)return n.chatHelper;let t=new k9({onStart:()=>{r(`receive-start`)},onMessage:e=>{r(`receive-text`)},onDone:()=>{r(`receive-end`),i()},onError:e=>{r(`error`,e)}}),a=z9({requestData:{urlPrefix:Sqt(n.url),headers:n.requestOptions?.headers,data:n.requestOptions?.data},protocol:t});return t.injectMessageModule(a.message),a})(),u=!n.chatHelper,d=l?new B9(l.session,l.agent,null,{enableChatSession:!0,autoSwitchToInitialSession:!!n.sessionCode,loadRecentSessionOnMount:n.autoLoad,initialSessionCode:n.sessionCode}):null,f=l?new HYt(l.agent,l.message,l.session,null,{openingRemark:n.helloText,predefinedQuestions:n.prompts,placeholder:n.placeholder}):null,p=new V9(null,n.shortcuts||[]);return(0,t.onMounted)(async()=>{if(!(!l||o.value))try{u?(await Promise.all([l.agent.getAgentInfo(),l.session.getSessions()]),d&&await d.loadRecentSession({skipLoadSessions:!0}),a.value=!0):a.value=!0,r(`agent-info-loaded`,l)}catch(e){console.error(`Failed to initialize ChatBot:`,e),o.value=e,r(`error`,e)}}),(0,t.onBeforeUnmount)(()=>{u&&l&&l.agent.stopChat(l.session.current?.value?.sessionCode??``)}),{chatHelper:l,isStandaloneMode:u,isInitialized:a,initError:o,chatBusinessManager:f,sessionBusinessManager:d,shortcutManager:p}}function XYt(e){let{props:n,chatHelper:r,chatBusinessManager:i,sessionBusinessManager:a,shortcutManager:o,isStandaloneMode:s,isInitialized:l,selectedShortcut:u}=e,d=(0,t.computed)(()=>i?.isStopLoading.value?j3.StopLoading:((n.chatHelper||r)?.agent)?.isChatting?.value?j3.Streaming:j3.Complete),f=(0,t.computed)(()=>d.value===j3.Streaming?x8.Disabled:void 0),p=(0,t.computed)(()=>i?.messages.value??[]),m=(0,t.computed)(()=>i?.isMessagesLoading.value??!1);return{messageStatus:d,messageToolsStatus:f,messages:p,isMessagesLoading:m,isGenerating:(0,t.computed)(()=>i?.isGenerating.value??!1),currentSession:(0,t.computed)(()=>a?.currentSession.value??null),isWelcomeState:(0,t.computed)(()=>s&&!l.value?!1:!m.value&&p.value.length===0),openingRemark:(0,t.computed)(()=>r?.agent.info.value?.conversationSettings?.openingRemark||``),effectiveResources:(0,t.computed)(()=>n.resources?.length?n.resources:r?.agent.info.value?.resources??[]),effectivePrompts:(0,t.computed)(()=>n.prompts?.length?n.prompts:r?.agent.info.value?.conversationSettings?.predefinedQuestions??[]),effectiveSupportUpload:(0,t.computed)(()=>u.value?.supportUpload?u.value.supportUpload.vision===!0:r?.agent.info.value?.promptSetting?.supportUpload?.vision===!0),chatbotStyle:(0,t.computed)(()=>({height:typeof n.height==`number`?`${n.height}px`:n.height,maxWidth:typeof n.maxWidth==`number`?`${n.maxWidth}px`:n.maxWidth})),filteredShortcuts:(0,t.computed)(()=>o.shortcuts.value)}}function ZYt(e){let{emit:n,chatHelper:r,chatBusinessManager:i,selectedShortcut:a,selectedResources:o}=e,s=(0,t.shallowRef)([[]]),l=(0,t.shallowRef)(``),u=(e,t)=>{s.value=e,o.value=t},d=async(e,t={})=>{if(!i||!r)throw Error(`[ChatBot] Cannot send message: chatBusinessManager not initialized`);let a=r.session.current?.value?.sessionCode;if(!a)throw Error(`[ChatBot] Cannot send message: no active session`);s.value=[[]],l.value=``,o.value=[],n(`send-message`,typeof e==`string`?e:``),await i.sendMessage(e,a,t)},f=async e=>{let t=r?.session.current?.value?.sessionCode;if(!t)throw Error(`[ChatBot] Cannot upload: no active session`);let n=await r.session.uploadFile(t,e);if(!n?.download_url)throw Error(`[ChatBot] Upload failed: no download URL returned`);return n},p=async(e,t)=>{try{let t={};l.value&&(t.cite=l.value),a.value&&(t.command=a.value.id),o.value.length&&(t.resources=o.value),await d(e,Object.keys(t).length?{property:{extra:t}}:{})}catch(e){console.error(`Failed to send message:`,e),n(`error`,e)}},m=async()=>{await h()},h=async()=>{if(!i){console.error(`[ChatBot] Cannot stop generation: chatBusinessManager not initialized`);return}await i.stopGeneration(),n(`stop`)};return{userInput:s,cite:l,handleUpdateModelValue:u,doSendMessage:d,handleSendMessage:p,handleUpload:f,handleStopSending:m,stopGeneration:h}}function QYt(e){let{emit:t,chatHelper:n,isStandaloneMode:r}=e,i=async e=>{if(!(!n||e.length===0))try{await Cqt((await new UYt(n.message,n.session).shareMessages(e)).shareUrl),_c({message:`分享链接已复制到剪贴板`,theme:`success`})}catch(e){console.error(`[ChatBot] Failed to share messages:`,e),_c({message:`分享失败,请重试`,theme:`error`})}};return{handleConfirmShare:async e=>{r&&await i(e),t(`confirm-share`,e)}}}function $Yt(e){let{props:n,emit:r,shortcutManager:i,doSendMessage:a,selectedShortcut:o}=e,s=i.effectiveShortcuts,l=(e,t)=>{let n=e,r;if(r=n.enable_fill_back&&n.fill_back_component_key?n.fill_back_component_key:n.components?.find(e=>e.fillBack)?.key,r&&t){let e=n.components?.map(e=>e.key===r?{...e,default:t}:{...e,default:e.default??void 0});o.value={...n,components:e,formModel:{...n.formModel,[r]:t}}}else o.value={...n,formModel:{...n.formModel}}},u=(e,t)=>{let n=e.components||[];return{extra:{cite:{type:`structured`,title:e.alias||e.name,data:n.map(e=>({key:e.name||e.key,value:String(t[e.key]??``)}))},command:e.id,context:n.map(e=>({[e.key]:t[e.key],context_type:e.type,__label:e.name||e.key,__key:e.key,__value:t[e.key]}))}}},d=e=>{let t=e.property?.extra;return t?.shortcut?t.shortcut:t?.command?s.value.find(e=>e.id===t.command)??null:null},f=(e,t)=>{l(e,t),r(`shortcut-click`,{shortcut:e,source:`main`})},p=()=>{o.value=null};return(0,t.watch)(()=>n.shortcuts,e=>{i.setShortcuts(e||[])},{immediate:!0}),(0,t.watch)(()=>e.chatHelper?.agent.info.value?.conversationSettings?.commands,e=>{e&&i.setAgentShortcuts(e)},{immediate:!0}),{effectiveShortcuts:s,selectShortcutWithText:l,buildShortcutProperty:u,getShortcutFromMessage:d,handleSelectShortcut:f,handleCloseShortcut:p,handleShortcutSubmit:async e=>{if(!o.value){console.error(`[ChatBot] No selected shortcut`);return}let t=u(o.value,e),n=o.value.name,i=o.value;p();try{await a(n,{property:t})}catch(e){o.value=i,console.error(`[ChatBot] Failed to submit shortcut:`,e),r(`error`,e)}}}}function eXt(e){let{emit:t,chatHelper:n,chatBusinessManager:r,cite:i,focusInput:a,scrollToBottom:o,getShortcutFromMessage:s,buildShortcutProperty:l}=e,u=async e=>{if(!r||!n){console.error(`[ChatBot] Cannot delete messages: chatBusinessManager not initialized`);return}try{let t=r.messages.value,i=B7(t,e[0]);if(!i){console.error(`[ChatBot] No user message found before AI messages`);return}let a=[i,...e];await n.message.deleteMessages(a)}catch(e){console.error(`[ChatBot] Failed to delete messages:`,e),t(`error`,e)}},d=async e=>{if(!r||!n){console.error(`[ChatBot] Cannot regenerate: chatBusinessManager not initialized`);return}let i=n.session.current?.value?.sessionCode;if(!i){console.error(`[ChatBot] Cannot regenerate: no active session`);return}try{await r.regenerateFromAIMessages(e,i),o()}catch(e){console.error(`[ChatBot] Failed to regenerate:`,e),t(`error`,e)}},f=async e=>{if(!r||!n){console.error(`[ChatBot] Cannot delete message: chatHelper not initialized`);return}try{let t=r.messages.value,i=t.findIndex(t=>t===e);if(i===-1){console.error(`[ChatBot] User message not found in messages list`);return}let a=[];for(let e=i+1;e<t.length;e++){let n=t[e];if(n.role===A3.User)break;a.push(n)}let o=[e,...a];await n.message.deleteMessages(o)}catch(e){console.error(`[ChatBot] Failed to delete user message:`,e),t(`error`,e)}};return{handleAgentAction:async(e,t)=>{if(e.id===`cite`){i.value=t.filter(e=>e.role!==A3.Reasoning).map(e=>typeof e.content==`string`?e.content:JSON.stringify(e.content||``)).join(`
3039
3039
  `),a();return}if(e.id===`rebuild`){await d(t);return}if(e.id===`delete`){await u(t);return}if(e.id===`like`||e.id===`unlike`){let t=e.id===`like`?5:0;try{return await n?.session.getSessionFeedbackReasons(t)||[]}catch(e){return console.error(`[ChatBot] Failed to get feedback reasons:`,e),[]}}console.log(`handleAgentAction`,e,t)},handleAgentFeedback:async(e,i,a,o)=>{if(!n){console.error(`[ChatBot] Cannot submit feedback: chatHelper not initialized`);return}let s=n.session.current?.value?.sessionCode;if(!s){console.error(`[ChatBot] Cannot submit feedback: no active session`);return}let l=yqt(r?.messages.value||[],i[0]);if(l===void 0){console.error(`[ChatBot] Cannot submit feedback: no user message found`);return}let u=e.id===`like`?5:0;try{await n.session.postSessionFeedback({sessionCode:s,sessionContentIds:[l],rate:u,labels:a,comment:o}),t(`feedback`,e,i[0],a,o)}catch(e){console.error(`[ChatBot] Failed to submit feedback:`,e),t(`error`,e)}},handleUserAction:async(e,t)=>{if(e.id===`delete`){await f(t);return}if(e.id===`cite`){i.value=typeof t.content==`string`?t.content:JSON.stringify(t.content||``),a();return}console.log(`handleUserAction`,e,t)},handleUserInputConfirm:async(e,r,i)=>{if(!n){console.error(`[ChatBot] Cannot edit message: chatHelper not initialized`);return}let a=n.session.current?.value?.sessionCode;if(!a){console.error(`[ChatBot] Cannot edit message: no active session`);return}let s=e.id;if(s===void 0){console.error(`[ChatBot] Cannot edit message: message has no id`);return}try{console.log(`handleUserInputConfirm`,s,a,r),await n.agent.resendMessage(String(s),a,r),o()}catch(e){console.error(`[ChatBot] Failed to edit and resend message:`,e),t(`error`,e)}},handleUserShortcutConfirm:async(e,i)=>{if(!r||!n){console.error(`[ChatBot] Cannot edit shortcut message: chatHelper not initialized`);return}let a=n.session.current?.value?.sessionCode;if(!a){console.error(`[ChatBot] Cannot edit shortcut message: no active session`);return}let u=e.id;if(u===void 0){console.error(`[ChatBot] Cannot edit shortcut message: message has no id`);return}try{let t=s(e);if(!t){console.error(`[ChatBot] Cannot edit shortcut message: shortcut not found`);return}let n=l(t,i),d=String(i.input??``);await r.resendMessageWithProperty(String(u),a,d,n),o()}catch(e){console.error(`[ChatBot] Failed to edit shortcut message:`,e),t(`error`,e)}},handleStopStreaming:async()=>{if(!r){console.error(`[ChatBot] Cannot stop generation: chatBusinessManager not initialized`);return}await r.stopGeneration(),t(`stop`)}}}var tXt={key:0,class:`chatbot-error`},nXt=(0,t.defineComponent)({__name:`chat-bot`,props:{autoLoad:{type:Boolean,default:!0},chatHelper:{default:void 0},enableSelection:{type:Boolean,default:!1},extCls:{},height:{},helloText:{},maxWidth:{},messageToolsTippyOptions:{},placeholder:{},prompts:{},requestOptions:{},resources:{default:()=>[]},sessionCode:{},shareLoading:{type:Boolean,default:!1},shortcuts:{default:()=>[]},url:{default:``}},emits:[`agent-info-loaded`,`cancel-share`,`confirm-share`,`error`,`execution-panel-change`,`feedback`,`receive-end`,`receive-start`,`receive-text`,`request-share`,`send-message`,`session-switched`,`shortcut-click`,`stop`],setup(e,{expose:n,emit:r}){let i=e,a=r,o=(0,t.ref)(),s=(0,t.ref)(),l=(0,t.ref)(),u=(0,t.shallowRef)([]),d=(0,t.ref)(null),f=async()=>{await(0,t.nextTick)(),o.value&&(o.value.scrollTop=o.value.scrollHeight)},p=()=>{l.value?.focus?.()},{chatHelper:m,isStandaloneMode:h,isInitialized:g,initError:_,chatBusinessManager:v,sessionBusinessManager:y,shortcutManager:b}=YYt({props:i,emit:a,scrollToBottom:f}),{userInput:x,cite:S,handleUpdateModelValue:C,doSendMessage:w,handleSendMessage:T,handleUpload:E,handleStopSending:D,stopGeneration:O}=ZYt({emit:a,chatHelper:m,chatBusinessManager:v,selectedShortcut:d,selectedResources:u}),{handleSelectShortcut:k,handleCloseShortcut:A,handleShortcutSubmit:j,selectShortcutWithText:M,getShortcutFromMessage:N,buildShortcutProperty:P}=$Yt({props:i,emit:a,chatHelper:m,shortcutManager:b,doSendMessage:w,selectedShortcut:d}),{messageStatus:F,messageToolsStatus:I,messages:L,isMessagesLoading:R,isGenerating:ee,currentSession:z,isWelcomeState:B,openingRemark:V,effectiveResources:te,effectivePrompts:ne,effectiveSupportUpload:re,chatbotStyle:ie,filteredShortcuts:ae}=XYt({props:i,chatHelper:m,chatBusinessManager:v,sessionBusinessManager:y,shortcutManager:b,isStandaloneMode:h,isInitialized:g,selectedShortcut:d}),{handleAgentAction:H,handleAgentFeedback:oe,handleUserAction:se,handleUserInputConfirm:ce,handleUserShortcutConfirm:le,handleStopStreaming:ue}=eXt({emit:a,chatHelper:m,chatBusinessManager:v,cite:S,focusInput:p,scrollToBottom:f,getShortcutFromMessage:N,buildShortcutProperty:P}),{handleConfirmShare:de}=QYt({emit:a,chatHelper:m,isStandaloneMode:h}),fe=e=>{a(`execution-panel-change`,e)},pe=async e=>{let t=e.data?.props;if(t?.task_id!=null&&t?.node_id)return m?.message.getFlowAgentTaskNodeInfo(t.task_id,t.node_id)};return n({sendMessage:e=>T(e,[[]]),stopGeneration:O,switchSession:async e=>{if(!y){console.error(`[ChatBot] Cannot switch session: sessionBusinessManager not initialized`);return}try{await y.switchSession(e),a(`session-switched`,y.currentSession.value)}catch(e){console.error(`Failed to switch session:`,e),a(`error`,e)}},messages:L,currentSession:z,isGenerating:ee,getChatHelper:()=>m,setCiteText:e=>{S.value=e},focusInput:p,enterShareMode:()=>s.value?.enterShareMode(),exitShareMode:()=>s.value?.exitShareMode(),selectShortcut:(e,t)=>{M(e,t)}}),(n,r)=>((0,t.openBlock)(),(0,t.createElementBlock)(`div`,{class:(0,t.normalizeClass)([`ai-chatbot`,i.extCls,{"welcome-state":(0,t.unref)(B)}]),style:(0,t.normalizeStyle)((0,t.unref)(ie))},[(0,t.createCommentVNode)(` 初始化错误提示 `),(0,t.unref)(_)?((0,t.openBlock)(),(0,t.createElementBlock)(`div`,tXt,[(0,t.createElementVNode)(`span`,null,(0,t.toDisplayString)((0,t.unref)(_).message),1)])):((0,t.openBlock)(),(0,t.createElementBlock)(t.Fragment,{key:1},[(0,t.createCommentVNode)(` 独立模式:初始化中(getAgentInfo → getSessions → chooseSession)统一展示 Loading `),(0,t.createCommentVNode)(` <div
3040
3040
  v-else-if="isStandaloneMode && !isInitialized"
3041
3041
  class="chatbot-loading"
@@ -2801,7 +2801,7 @@ Use Shift + Enter to enter a new line`:`输入 “/”唤出 Prompt
2801
2801
  <div class="tippy-dropdown-menu">
2802
2802
  ${r}
2803
2803
  </div>
2804
- `}),E=async()=>{if(a.sessionBusinessManager)try{await a.sessionBusinessManager.createNewSession()}catch(e){console.error(`Failed to create new session:`,e),(0,n.Message)({theme:`error`,message:R9(`创建会话失败`)})}o(`new-chat`)},D=e=>{e.stopPropagation(),a.sessionBusinessManager?(_||v(),_&&_.handleTriggerClick(e)):o(`history-click`,e)},O=()=>{o(`help-click`)},k=e=>{e.stopPropagation(),_&&_.isVisible()&&_.hide(),h&&(h.state.isVisible?h.hide():h.show())},A=e=>{e.stopPropagation(),e.preventDefault();let t=e.currentTarget,n=t.dataset.action;if(!t.classList.contains(`disabled`))switch(h&&h.hide(),n){case`rename`:j();break;case`auto-generate`:o(`auto-generate-name`);break;case`share`:o(`share`);break}},j=()=>{document.removeEventListener(`click`,F),p.value=a.sessionName||``,f.value=!0,setTimeout(()=>{document.addEventListener(`click`,F)},100),setTimeout(()=>{if(m.value)try{let e=m.value;e&&typeof e.focus==`function`&&e.focus();let t=e.$el?.querySelector(`input`);t&&typeof t.select==`function`&&t.select()}catch(e){console.warn(`Failed to focus rename input:`,e)}},100)},M=()=>{let e=p.value.trim();if(!e){N();return}o(`rename`,e),f.value=!1,p.value=``},N=()=>{f.value=!1,p.value=``},P=(e,t)=>{p.value=e,t.key===`Enter`?M():t.key===`Escape`&&N()},F=e=>{if(!f.value)return;let t=e.target,n=document.querySelector(`.rename-tooltip`);n&&!n.contains(t)&&N()},I=async()=>{if(!d.value)return;let e=(await import(`tippy.js`)).default;h&&=(h.destroy(),null),h=e(d.value,{content:T.value,theme:`ai-blueking-light more-menu-light light`,placement:`bottom-start`,trigger:`manual`,interactive:!0,allowHTML:!0,arrow:!1,offset:[0,4],appendTo:()=>document.querySelector(`.ai-blueking-panel`)||document.body,onShow:()=>{setTimeout(async()=>{let{default:e}=await import(`tippy.js`);document.querySelectorAll(`.tippy-menu-item`).forEach(t=>{let n=t;n.addEventListener(`click`,A);let r=n.getAttribute(`data-tippy-content`);if(r&&!g.has(n)){let t=e(n,{content:r,theme:`ai-blueking-tooltip`,trigger:`mouseenter focus`,arrow:!0,delay:[300,0],appendTo:()=>document.querySelector(`.ai-blueking-panel`)||document.body});g.set(n,t)}})},0)},onHide:()=>{document.querySelectorAll(`.tippy-menu-item`).forEach(e=>{let t=e;t.removeEventListener(`click`,A);let n=g.get(t);n&&(n.destroy(),g.delete(t))})}})};return(0,t.watch)(()=>[a.isCompressionHeight,a.hasSessionContents],()=>{h&&h.setContent(T.value)}),(0,t.onMounted)(()=>{I(),a.sessionBusinessManager&&v(),document.addEventListener(`click`,F)}),(0,t.onBeforeUnmount)(()=>{h&&=(h.destroy(),null),g.forEach(e=>{e.destroy()}),g.clear(),_&&=(_.destroy(),null),document.removeEventListener(`click`,F)}),r({headerRef:l,historyIconRef:u}),(r,i)=>((0,t.openBlock)(),(0,t.createElementBlock)(`div`,{ref_key:`headerRef`,ref:l,class:(0,t.normalizeClass)([`ai-header drag-handle`,{draggable:a.draggable}])},[(0,t.createElementVNode)(`div`,lxt,[(0,t.createElementVNode)(`div`,uxt,[(0,t.createElementVNode)(`img`,{alt:`logo`,src:(0,t.unref)(Nbt)},null,8,dxt)]),(0,t.createElementVNode)(`div`,{class:(0,t.normalizeClass)([`title`,{"title-with-tooltip":f.value}])},[(0,t.createTextVNode)((0,t.toDisplayString)(y.value)+` `,1),(0,t.createCommentVNode)(` 重命名 tooltip 直接绑定在 title 上 `),f.value?((0,t.openBlock)(),(0,t.createElementBlock)(`div`,fxt,[(0,t.createElementVNode)(`div`,pxt,[(0,t.createVNode)((0,t.unref)(n.Input),{ref_key:`renameInputRef`,ref:m,modelValue:p.value,"onUpdate:modelValue":i[0]||=e=>p.value=e,class:`rename-input`,placeholder:(0,t.unref)(R9)(`请输入新的会话名称`),onKeyup:P},null,8,[`modelValue`,`placeholder`]),(0,t.createElementVNode)(`div`,{class:`rename-buttons`},[(0,t.createElementVNode)(`i`,{class:`bkai-icon bkai-check-1 rename-btn confirm-btn`,onClick:M}),(0,t.createElementVNode)(`i`,{class:`bkai-icon bkai-close rename-btn cancel-btn`,onClick:N})])])])):(0,t.createCommentVNode)(`v-if`,!0)],2),a.showMoreIcon&&S.value?((0,t.openBlock)(),(0,t.createElementBlock)(`span`,{key:0,ref_key:`moreIconRef`,ref:d,class:`bkai-icon bkai-more`,onClick:k},null,512)):(0,t.createCommentVNode)(`v-if`,!0)]),(0,t.createElementVNode)(`div`,mxt,[(0,t.createCommentVNode)(` 新增会话按钮 `),a.showNewChatIcon&&e.enableChatSession!==!1?(0,t.withDirectives)(((0,t.openBlock)(),(0,t.createElementBlock)(`i`,{key:0,class:(0,t.normalizeClass)([`bkai-icon`,`bkai-xinzengliaotian`,{disabled:!S.value}]),style:(0,t.normalizeStyle)(w()),onClick:i[1]||=e=>S.value?E():void 0},null,6)),[[(0,t.unref)(s),{content:C((0,t.unref)(R9)(`新增会话`)),boundary:`parent`}]]):(0,t.createCommentVNode)(`v-if`,!0),(0,t.createCommentVNode)(` 历史会话按钮 `),a.showHistoryIcon&&e.enableChatSession!==!1?(0,t.withDirectives)(((0,t.openBlock)(),(0,t.createElementBlock)(`i`,{key:1,ref_key:`historyIconRef`,ref:u,class:(0,t.normalizeClass)([`bkai-icon`,`bkai-history`,{disabled:!S.value}]),style:(0,t.normalizeStyle)(w()),onClick:i[2]||=e=>S.value?D(e):void 0},null,6)),[[(0,t.unref)(s),{content:C((0,t.unref)(R9)(`历史会话`)),boundary:`parent`}]]):(0,t.createCommentVNode)(`v-if`,!0),e.chatGroup?.enabled?(0,t.withDirectives)(((0,t.openBlock)(),(0,t.createElementBlock)(`i`,{key:2,class:`bkai-icon bkai-zhushou`,onClick:O},null,512)),[[(0,t.unref)(s),{content:(0,t.unref)(R9)(`转人工`),boundary:`parent`}]]):(0,t.createCommentVNode)(`v-if`,!0),a.showCompressionIcon?(0,t.withDirectives)(((0,t.openBlock)(),(0,t.createElementBlock)(`i`,{key:3,class:(0,t.normalizeClass)([`bkai-icon`,b.value]),onClick:i[3]||=e=>o(`toggle-compression`)},null,2)),[[(0,t.unref)(s),{content:x.value,boundary:`parent`}]]):(0,t.createCommentVNode)(`v-if`,!0),(0,t.withDirectives)((0,t.createElementVNode)(`i`,{class:`bkai-icon bkai-close-line-2`,onClick:i[4]||=e=>o(`close`)},null,512),[[(0,t.unref)(s),{content:(0,t.unref)(R9)(`关闭`),boundary:`parent`}]])])],2))}}),[[`__scopeId`,`data-v-3cf2263c`]]),gxt=class{_isGenerating;_isStopLoading;agentModule;config;eventEmitter;messageModule;sessionModule;autoRenameSessionIfNeeded(e){this.sessionModule&&this.messageModule.list.value.length===1&&this.sessionModule.renameSession(e).catch(e=>{console.error(`[ChatBusinessManager] Auto rename session failed:`,e)})}emit(e,t){this.eventEmitter?.emit(e,t)}constructor(e,n,r=null,i=null,a={}){this.agentModule=e,this.messageModule=n,this.sessionModule=r,this.eventEmitter=i,this.config=a,this._isGenerating=(0,t.ref)(!1),this._isStopLoading=(0,t.ref)(!1)}get isGenerating(){return this._isGenerating}get isStopLoading(){return this._isStopLoading}get isMessagesLoading(){return this.messageModule.isListLoading}get messages(){return this.messageModule.list}get openingRemark(){return this.config.openingRemark||``}get predefinedQuestions(){return this.config.predefinedQuestions||[]}async batchDeleteMessages(e){try{await this.messageModule.deleteMessages(e);let t=e.map(e=>e.id).filter(Boolean);this.emit(`messages-batch-deleted`,{messageIds:t})}catch(e){throw console.error(`Failed to batch delete messages:`,e),this.emit(`chat-error`,{action:`batch-delete-messages`,error:e}),e}}async deleteMessage(e){try{await this.messageModule.deleteMessages([e]),this.emit(`message-deleted`,{messageId:e.id})}catch(e){throw console.error(`Failed to delete message:`,e),this.emit(`chat-error`,{action:`delete-message`,error:e}),e}}handleStreamEnd(){this._isGenerating.value=!1,this.emit(`receive-end`,{})}handleStreamError(e){this._isGenerating.value=!1,this.emit(`receive-error`,{error:e})}handleStreamStart(){this._isGenerating.value=!0,this.emit(`receive-start`,{})}async regenerateFromAIMessages(e,t){try{if(!e||e.length===0)throw Error(`No AI messages provided`);let n=this.messages.value,r=L9(n,e[0]);if(!r)throw Error(`No user message found before AI messages`);let i=r.id;if(i===void 0)throw Error(`User message has no id`);await this.regenerateMessage(String(i),t)}catch(e){throw console.error(`Failed to regenerate from AI messages:`,e),this.emit(`chat-error`,{action:`regenerate`,error:e}),e}}async regenerateMessage(e,t){try{let n=this.messages.value,r=n.findIndex(t=>String(t.id)===e);if(r===-1)throw Error(`Message not found: ${e}`);let i=n[r];if(i.role!==a.MessageRole.User)throw Error(`Can only regenerate from user messages`);let o=n.slice(r),s=typeof i.content==`string`?i.content:JSON.stringify(i.content),l=i.property;this._isGenerating.value=!0;let u=this.messageModule.deleteMessages(o);this.agentModule.chat(s,t,void 0,void 0,l),this.emit(`chat-regenerate`,{messageId:e}),u.catch(e=>{console.error(`[regenerateMessage] Delete API error:`,e)})}catch(e){throw console.error(`Failed to regenerate message:`,e),this._isGenerating.value=!1,this.emit(`chat-error`,{action:`regenerate`,error:e}),e}}async resendMessageWithProperty(e,t,n,r){try{let i=this.messages.value,o=i.findIndex(t=>String(t.id)===e);if(o===-1)throw Error(`Message not found: ${e}`);if(i[o].role!==a.MessageRole.User)throw Error(`Can only resend user messages`);let s=i.slice(o);this._isGenerating.value=!0;let l=this.messageModule.deleteMessages(s);this.agentModule.chat(n,t,void 0,void 0,r),this.emit(`chat-resend`,{messageId:e}),l.catch(e=>{console.error(`[resendMessageWithProperty] Delete API error:`,e)})}catch(e){throw console.error(`Failed to resend message with property:`,e),this._isGenerating.value=!1,this.emit(`chat-error`,{action:`resend`,error:e}),e}}async retryMessage(e){try{console.warn(`retryMessage not implemented yet`),this.emit(`chat-retry`,{messageId:e})}catch(e){throw console.error(`Failed to retry message:`,e),this.emit(`chat-error`,{action:`retry`,error:e}),e}}async sendMessage(e,t,n={}){try{if(!t)throw Error(`No active session. Please create or select a session first.`);this._isGenerating.value=!0,this.emit(`send-message`,{content:e}),await this.agentModule.chat(e,t,void 0,void 0,n.property),this.autoRenameSessionIfNeeded(t)}catch(e){throw console.error(`Failed to send message:`,e),this._isGenerating.value=!1,this.emit(`chat-error`,{action:`send`,error:e}),e}}async stopGeneration(){let e=this.sessionModule?.current?.value?.sessionCode??``;this._isStopLoading.value=!0;try{await this.agentModule.stopChat(e),this._isGenerating.value=!1,this.emit(`stop`,{})}catch(e){console.error(`Failed to stop generation:`,e),this.emit(`chat-error`,{action:`stop`,error:e})}finally{this._isStopLoading.value=!1}}},B9=class{agentModule;config;eventEmitter;sessionModule;emit(e,t){this.eventEmitter?.emit(e,t)}constructor(e,t=null,n=null,r={}){this.sessionModule=e,this.agentModule=t,this.eventEmitter=n,this.config=r}get currentSession(){return this.sessionModule.current}get isCreateLoading(){return this.sessionModule.isCreateLoading}get isCurrentLoading(){return this.sessionModule.isCurrentLoading}get isDeleteLoading(){return this.sessionModule.isDeleteLoading}get isListLoading(){return this.sessionModule.isListLoading}get isUpdateLoading(){return this.sessionModule.isUpdateLoading}get sessionList(){return this.sessionModule.list}async createNewSession(){return this.createSession({name:`新会话`,sessionCode:`new_session_${Date.now()}`})}async createSession(e={}){if(this.config.enableChatSession===!1)throw Error(`Chat session is disabled`);try{let t={sessionName:e.name||`新会话`,sessionCode:e.sessionCode||`session_${Date.now()}`,isTemporary:e.isTemporary||!1};await this.sessionModule.createSession(t);let n=this.agentModule?.info.value;n&&this.agentModule?.handleRole(n,t.sessionCode),this.emit(`session-created`,{session:this.sessionModule.current.value})}catch(e){throw console.error(`Failed to create session:`,e),this.emit(`session-error`,{action:`create`,error:e}),e}}async deleteSession(e){try{await this.sessionModule.deleteSession(e),this.emit(`session-deleted`,{sessionCode:e})}catch(e){throw console.error(`Failed to delete session:`,e),this.emit(`session-error`,{action:`delete`,error:e}),e}}async getSession(e){try{await this.sessionModule.getSession(e)}catch(e){throw console.error(`Failed to get session:`,e),this.emit(`session-error`,{action:`get`,error:e}),e}}async loadRecentSession(e){try{e?.skipLoadSessions||await this.loadSessions();let t=this.sessionList.value;if(this.config.initialSessionCode){await this.switchSession(this.config.initialSessionCode);return}if(t.length>0){let e=t[0];(e.sessionContentCount??0)>0?await this.createNewSession():await this.switchSession(e.sessionCode,{loadMessages:!1});return}await this.createNewSession()}catch(e){throw console.error(`Failed to load recent session:`,e),e}}async loadSessions(){try{await this.sessionModule.getSessions(),this.emit(`sessions-loaded`,{sessions:this.sessionList.value})}catch(e){throw console.error(`Failed to load sessions:`,e),this.emit(`session-error`,{action:`load`,error:e}),e}}async switchSession(e,t){try{await this.sessionModule.chooseSession(e,t),this.emit(`session-switched`,{session:this.sessionModule.current.value})}catch(e){throw console.error(`Failed to switch session:`,e),this.emit(`session-error`,{action:`switch`,error:e}),e}}async updateSessionName(e,t){try{let n=this.sessionList.value.find(t=>t.sessionCode===e);if(!n)throw Error(`Session not found: ${e}`);await this.sessionModule.updateSession({...n,sessionName:t}),this.emit(`session-updated`,{session:this.sessionModule.current.value})}catch(e){throw console.error(`Failed to update session name:`,e),this.emit(`session-error`,{action:`update`,error:e}),e}}},_xt=class{messageModule;sessionModule;constructor(e,t){this.messageModule=e,this.sessionModule=t}async shareMessages(e){if(e.length===0)throw Error(`No messages to share`);let t=this.sessionModule.current?.value?.sessionCode;if(!t)throw Error(`No active session`);let n=await this.messageModule.shareMessages(t,e);if(!n)throw Error(`Share failed: no result returned`);return{shareUrl:`${n.share_page}share-page/${n.share_token}`,userMessageIds:e.map(e=>String(e.id))}}},V9=class{_agentShortcuts;_effectiveShortcuts;_propsShortcuts;eventEmitter;emit(e,t){this.eventEmitter?.emit(e,t)}constructor(e=null,n=[]){this._propsShortcuts=(0,t.ref)(n),this._agentShortcuts=(0,t.ref)([]),this.eventEmitter=e,this._effectiveShortcuts=(0,t.computed)(()=>this._propsShortcuts.value.length>0?this._propsShortcuts.value:this._agentShortcuts.value.length>0?this._agentShortcuts.value:[])}get count(){return this._effectiveShortcuts.value.length}get effectiveShortcuts(){return this._effectiveShortcuts}get hasShortcuts(){return this._effectiveShortcuts.value.length>0}get shortcuts(){return this._effectiveShortcuts}addShortcut(e){this._propsShortcuts.value.push(e)}clear(){this._propsShortcuts.value=[],this._agentShortcuts.value=[]}filterByTextLength(e,t){return!e||e.length>t?[]:this._effectiveShortcuts.value}filterShortcuts(e,t){return t?this._effectiveShortcuts.value.filter(n=>t(n,e)):this._effectiveShortcuts.value}getShortcutById(e){return this._effectiveShortcuts.value.find(t=>t.id===e)}handleShortcutClick(e,t,n=`main`){this.emit(`shortcut-click`,{shortcut:e,selectedText:t,source:n})}limitShortcuts(e){return this._effectiveShortcuts.value.slice(0,e)}removeShortcut(e){this._propsShortcuts.value=this._propsShortcuts.value.filter(t=>t.id!==e)}setAgentShortcuts(e){this._agentShortcuts.value=e}setShortcuts(e){this._propsShortcuts.value=e}},vxt=class{_isCompressed;_isDraggingOrResizing;_nimbusMinimized;_panelVisible;_positionAndSize;cleanupFunctions;config;containerRef=null;debugMode;listeners;onceListeners;constructor(e={}){this.config=e,this.listeners=new Map,this.onceListeners=new Map,this.debugMode=e.debug??!1,this.cleanupFunctions=[],this._panelVisible=(0,t.ref)(e.initialPanelVisible??!1),this._nimbusMinimized=(0,t.ref)(e.initialNimbusMinimized??!1),this._isDraggingOrResizing=(0,t.ref)(!1),this._isCompressed=(0,t.ref)(!1),this._positionAndSize=(0,t.ref)({x:0,y:0,width:400,height:window.innerHeight})}get container(){return{updatePosition:this.updatePosition.bind(this),updateSize:this.updateSize.bind(this),updatePositionAndSize:this.updatePositionAndSize.bind(this),toggleCompression:this.toggleCompression.bind(this),expandForSidePanel:this.expandForSidePanel.bind(this),collapseSidePanel:this.collapseSidePanel.bind(this),positionAndSize:(0,t.computed)(()=>this.containerRef?.positionAndSize?.value??this._positionAndSize.value),isCompressed:(0,t.computed)(()=>this._isCompressed.value),isSidePanelExpanded:(0,t.computed)(()=>this.containerRef?.isSidePanelExpanded?.value??!1)}}get isCompressed(){return this._isCompressed}get isDraggingOrResizing(){return this._isDraggingOrResizing}get nimbus(){return{minimize:this.minimizeNimbus.bind(this),restore:this.restoreNimbus.bind(this),toggle:this.toggleNimbus.bind(this),isMinimized:(0,t.computed)(()=>this._nimbusMinimized.value)}}get nimbusMinimized(){return this._nimbusMinimized}get panel(){return{show:this.showPanel.bind(this),hide:this.hidePanel.bind(this),toggle:this.togglePanel.bind(this),isVisible:(0,t.computed)(()=>this._panelVisible.value)}}get panelVisible(){return this._panelVisible}get state(){return{panelVisible:this._panelVisible,nimbusMinimized:this._nimbusMinimized,isDraggingOrResizing:this._isDraggingOrResizing,positionAndSize:this._positionAndSize}}collapseSidePanel(){this.containerRef?.collapseSidePanel&&this.containerRef.collapseSidePanel()}destroy(){this.listeners.clear(),this.onceListeners.clear(),this.cleanupFunctions.forEach(e=>e()),this.cleanupFunctions=[],this.debugMode&&console.debug(`[ComponentManager] Destroyed`)}emit(e,t){this.debugMode&&console.debug(`[ComponentManager] Emitting "${e}"`,t);let n=this.listeners.get(e);n&&n.forEach(n=>{try{n(t)}catch(t){console.error(`[ComponentManager] Error in listener for "${e}":`,t)}});let r=this.onceListeners.get(e);if(r&&r.size>0){let n=Array.from(r);this.onceListeners.delete(e),n.forEach(n=>{try{n(t)}catch(t){console.error(`[ComponentManager] Error in once listener for "${e}":`,t)}})}}emitInternal(e,t){this.emit(e,t)}expandForSidePanel(e){this.containerRef?.expandForSidePanel&&this.containerRef.expandForSidePanel(e)}getConfig(){return this.config}getRegisteredEvents(){let e=new Set;return this.listeners.forEach((t,n)=>e.add(n)),this.onceListeners.forEach((t,n)=>e.add(n)),Array.from(e)}handleDragging(e){this._isDraggingOrResizing.value=!0,this._positionAndSize.value=e,this.emit(`dragging`,e)}handleDragStop(e){this._isDraggingOrResizing.value=!1,this._positionAndSize.value=e,this.emit(`drag-stop`,e)}handleNimbusClick(){this.emit(`nimbus-click`,{}),this.showPanel()}handlePopupClick(){this.emit(`popup-click`,{}),this.showPanel()}handlePopupShortcutClick(e){this.emit(`popup-shortcut-click`,{shortcut:e}),this.emit(`shortcut-click`,{shortcut:e,source:`popup`})}handleResizeStop(e){this._isDraggingOrResizing.value=!1,this._positionAndSize.value=e,this.emit(`resize-stop`,e)}handleResizing(e){this._isDraggingOrResizing.value=!0,this._positionAndSize.value=e,this.emit(`resizing`,e)}handleShortcutClick(e,t){this.emit(`shortcut-click`,{shortcut:e,source:t})}hasListeners(e){return this.listenerCount(e)>0}hidePanel(){this._panelVisible.value=!1,this.emit(`panel-hide`,{})}listenerCount(e){return(this.listeners.get(e)?.size??0)+(this.onceListeners.get(e)?.size??0)}minimizeNimbus(){this._nimbusMinimized.value=!0,this.emit(`nimbus-minimize`,{})}off(e,t){t?(this.listeners.get(e)?.delete(t),this.onceListeners.get(e)?.delete(t),this.debugMode&&console.debug(`[ComponentManager] Unsubscribed from "${e}", remaining: ${this.listenerCount(e)}`)):(this.listeners.delete(e),this.onceListeners.delete(e),this.debugMode&&console.debug(`[ComponentManager] Removed all listeners for "${e}"`))}on(e,t){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t),this.debugMode&&console.debug(`[ComponentManager] Subscribed to "${e}", total: ${this.listenerCount(e)}`),()=>{this.off(e,t)}}once(e,t){return this.onceListeners.has(e)||this.onceListeners.set(e,new Set),this.onceListeners.get(e).add(t),this.debugMode&&console.debug(`[ComponentManager] Subscribed once to "${e}"`),()=>{this.onceListeners.get(e)?.delete(t)}}restoreNimbus(){this._nimbusMinimized.value=!1,this.emit(`nimbus-restore`,{})}setCompressed(e){this._isCompressed.value=e}setContainerRef(e){this.containerRef=e,e?.isCompressed&&(this._isCompressed.value=e.isCompressed.value)}setDebugMode(e){this.debugMode=e}setDraggingOrResizing(e){this._isDraggingOrResizing.value=e}showPanel(e){this._panelVisible.value=!0,this.emit(`panel-show`,{sessionCode:e})}toggleCompression(){this.containerRef?this.containerRef.toggleCompression():this._isCompressed.value=!this._isCompressed.value}toggleNimbus(){this._nimbusMinimized.value?this.restoreNimbus():this.minimizeNimbus()}togglePanel(){this._panelVisible.value?this.hidePanel():this.showPanel()}updatePosition(e,t){this._positionAndSize.value={...this._positionAndSize.value,x:e,y:t}}updatePositionAndSize(e,t,n,r){this._positionAndSize.value={x:e,y:t,width:n,height:r}}updateSize(e,t){this._positionAndSize.value={...this._positionAndSize.value,width:e,height:t}}};function yxt(e){return new vxt(e)}var bxt={"panel-show":`show`,"panel-hide":`close`,"panel-toggle":null,"nimbus-click":null,"nimbus-minimize":null,"nimbus-restore":null,"popup-click":null,"popup-shortcut-click":null,dragging:`dragging`,resizing:`resizing`,"drag-stop":`drag-stop`,"resize-stop":`resize-stop`,"compression-toggle":null,"side-panel-expand":null,"side-panel-collapse":null,"send-message":`send-message`,"receive-start":`receive-start`,"receive-text":`receive-text`,"receive-end":`receive-end`,"receive-error":null,stop:`stop`,"chat-regenerate":null,"chat-retry":null,"message-deleted":null,"messages-batch-deleted":null,"session-created":null,"session-switched":null,"session-deleted":null,"session-updated":null,"sessions-loaded":null,"session-initialized":`session-initialized`,"session-error":null,"shortcut-click":`shortcut-click`,"chat-error":null,"sdk-error":`sdk-error`,"new-chat":`new-chat`,"history-click":`history-click`,"auto-generate-name":`auto-generate-name`,"help-click":`help-click`,rename:`rename`,share:`share`,close:`close`,"toggle-compression":null,"transfer-messages":`transfer-messages`,"share-messages":`share-messages`,"agent-info-loaded":null,error:null};function xxt(e,t){switch(e){case`send-message`:return[t.content];case`rename`:return[t.newName];case`history-click`:return[t.event];case`dragging`:case`resizing`:case`drag-stop`:case`resize-stop`:case`shortcut-click`:case`session-initialized`:case`sdk-error`:case`transfer-messages`:case`share-messages`:return[t];case`panel-show`:case`panel-hide`:case`receive-start`:case`receive-text`:case`receive-end`:case`stop`:case`new-chat`:case`auto-generate-name`:case`help-click`:case`share`:case`close`:return[];default:return[t]}}var Sxt=class{_selectedMessageIds;_isSelectionMode;_editingSessionCode;_loadingStates;constructor(){this._selectedMessageIds=(0,t.ref)(new Set),this._isSelectionMode=(0,t.ref)(!1),this._editingSessionCode=(0,t.ref)(null),this._loadingStates=(0,t.reactive)({})}get isSelectionMode(){return this._isSelectionMode}get editingSessionCode(){return this._editingSessionCode}toggleSelectionMode(){this._isSelectionMode.value=!this._isSelectionMode.value,this._isSelectionMode.value||this.clearSelection()}enableSelectionMode(){this._isSelectionMode.value=!0}disableSelectionMode(){this._isSelectionMode.value=!1,this.clearSelection()}toggleMessageSelection(e){this._selectedMessageIds.value.has(e)?this._selectedMessageIds.value.delete(e):this._selectedMessageIds.value.add(e),this._selectedMessageIds.value=new Set(this._selectedMessageIds.value)}selectMessage(e){this._selectedMessageIds.value.add(e),this._selectedMessageIds.value=new Set(this._selectedMessageIds.value)}deselectMessage(e){this._selectedMessageIds.value.delete(e),this._selectedMessageIds.value=new Set(this._selectedMessageIds.value)}isMessageSelected(e){return this._selectedMessageIds.value.has(e)}clearSelection(){this._selectedMessageIds.value.clear(),this._selectedMessageIds.value=new Set(this._selectedMessageIds.value)}selectAllMessages(e){this._selectedMessageIds.value=new Set(e)}get selectedMessages(){return Array.from(this._selectedMessageIds.value)}get selectedCount(){return this._selectedMessageIds.value.size}get hasSelection(){return this._selectedMessageIds.value.size>0}startEditingSession(e){this._editingSessionCode.value=e}stopEditingSession(){this._editingSessionCode.value=null}isEditingSession(e){return e?this._editingSessionCode.value===e:this._editingSessionCode.value!==null}setLoading(e,t){this._loadingStates[e]=t}isLoading(e){return this._loadingStates[e]??!1}clearLoadingStates(){Object.keys(this._loadingStates).forEach(e=>{this._loadingStates[e]=!1})}reset(){this.clearSelection(),this.disableSelectionMode(),this.stopEditingSession(),this.clearLoadingStates()}};function Cxt(e){let{props:n,emit:r,scrollToBottom:i}=e,o=(0,t.ref)(!1),s=(0,t.ref)(null),l=()=>n.chatHelper?!n.chatHelper.agent||!n.chatHelper.session||!n.chatHelper.message?{valid:!1,error:`[ChatBot] Invalid chatHelper: missing required modules (agent, session, message)`}:{valid:!0}:n.url?{valid:!0}:{valid:!1,error:`[ChatBot] Neither chatHelper nor url provided. Component requires at least one.`},u=(()=>{let e=l();if(!e.valid)return console.error(e.error),s.value=Error(e.error),null;if(n.chatHelper)return n.chatHelper;let t=new a.AGUIProtocol({onStart:()=>{r(`receive-start`)},onMessage:e=>{r(`receive-text`)},onDone:()=>{r(`receive-end`),i()},onError:e=>{r(`error`,e)}}),o=(0,a.useChatHelper)({requestData:{urlPrefix:Lbt(n.url),headers:n.requestOptions?.headers,data:n.requestOptions?.data},protocol:t});return t.injectMessageModule(o.message),o})(),d=!n.chatHelper,f=u?new B9(u.session,u.agent,null,{enableChatSession:!0,autoSwitchToInitialSession:!!n.sessionCode,loadRecentSessionOnMount:n.autoLoad,initialSessionCode:n.sessionCode}):null,p=u?new gxt(u.agent,u.message,u.session,null,{openingRemark:n.helloText,predefinedQuestions:n.prompts,placeholder:n.placeholder}):null,m=new V9(null,n.shortcuts||[]);return(0,t.onMounted)(async()=>{if(!(!u||s.value))try{if(d){if(await u.agent.getAgentInfo(),await u.session.getSessions(),n.sessionCode)await u.session.chooseSession(n.sessionCode);else if(u.session.list.value.length>0){let e=u.session.list.value[0];await u.session.chooseSession(e.sessionCode)}o.value=!0}else o.value=!0;r(`agent-info-loaded`,u)}catch(e){console.error(`Failed to initialize ChatBot:`,e),s.value=e,r(`error`,e)}}),(0,t.onBeforeUnmount)(()=>{d&&u&&u.agent.stopChat(u.session.current?.value?.sessionCode??``)}),{chatHelper:u,isStandaloneMode:d,isInitialized:o,initError:s,chatBusinessManager:p,sessionBusinessManager:f,shortcutManager:m}}function wxt(e){let{props:n,chatHelper:r,chatBusinessManager:i,sessionBusinessManager:a,shortcutManager:o,isStandaloneMode:s,isInitialized:l,selectedShortcut:u}=e,d=(0,t.computed)(()=>i?.isStopLoading.value?k6.StopLoading:((n.chatHelper||r)?.agent)?.isChatting?.value?k6.Streaming:k6.Complete),f=(0,t.computed)(()=>d.value===k6.Streaming?v5.Disabled:void 0),p=(0,t.computed)(()=>i?.messages.value??[]),m=(0,t.computed)(()=>i?.isMessagesLoading.value??!1);return{messageStatus:d,messageToolsStatus:f,messages:p,isMessagesLoading:m,isGenerating:(0,t.computed)(()=>i?.isGenerating.value??!1),currentSession:(0,t.computed)(()=>a?.currentSession.value??null),isWelcomeState:(0,t.computed)(()=>s&&!l.value?!1:!m.value&&p.value.length===0),openingRemark:(0,t.computed)(()=>r?.agent.info.value?.conversationSettings?.openingRemark||``),effectiveResources:(0,t.computed)(()=>n.resources?.length?n.resources:r?.agent.info.value?.resources??[]),effectivePrompts:(0,t.computed)(()=>n.prompts?.length?n.prompts:r?.agent.info.value?.conversationSettings?.predefinedQuestions??[]),effectiveSupportUpload:(0,t.computed)(()=>u.value?.supportUpload?u.value.supportUpload.vision===!0:r?.agent.info.value?.promptSetting?.supportUpload?.vision===!0),chatbotStyle:(0,t.computed)(()=>({height:typeof n.height==`number`?`${n.height}px`:n.height,maxWidth:typeof n.maxWidth==`number`?`${n.maxWidth}px`:n.maxWidth})),filteredShortcuts:(0,t.computed)(()=>o.shortcuts.value)}}function Txt(e){let{emit:n,chatHelper:r,chatBusinessManager:i,selectedShortcut:a,selectedResources:o}=e,s=(0,t.shallowRef)([[]]),l=(0,t.shallowRef)(``),u=(e,t)=>{s.value=e,o.value=t},d=async(e,t={})=>{if(!i||!r)throw Error(`[ChatBot] Cannot send message: chatBusinessManager not initialized`);let a=r.session.current?.value?.sessionCode;if(!a)throw Error(`[ChatBot] Cannot send message: no active session`);s.value=[[]],l.value=``,o.value=[],n(`send-message`,typeof e==`string`?e:``),await i.sendMessage(e,a,t)},f=async e=>{let t=r?.session.current?.value?.sessionCode;if(!t)throw Error(`[ChatBot] Cannot upload: no active session`);let n=await r.session.uploadFile(t,e);if(!n?.download_url)throw Error(`[ChatBot] Upload failed: no download URL returned`);return n},p=async(e,t)=>{try{let t={};l.value&&(t.cite=l.value),a.value&&(t.command=a.value.id),o.value.length&&(t.resources=o.value),await d(e,Object.keys(t).length?{property:{extra:t}}:{})}catch(e){console.error(`Failed to send message:`,e),n(`error`,e)}},m=async()=>{await h()},h=async()=>{if(!i){console.error(`[ChatBot] Cannot stop generation: chatBusinessManager not initialized`);return}await i.stopGeneration(),n(`stop`)};return{userInput:s,cite:l,handleUpdateModelValue:u,doSendMessage:d,handleSendMessage:p,handleUpload:f,handleStopSending:m,stopGeneration:h}}function Ext(e){let{emit:t,chatHelper:r,isStandaloneMode:i}=e,a=async e=>{if(!(!r||e.length===0))try{await Rbt((await new _xt(r.message,r.session).shareMessages(e)).shareUrl),(0,n.Message)({message:`分享链接已复制到剪贴板`,theme:`success`})}catch(e){console.error(`[ChatBot] Failed to share messages:`,e),(0,n.Message)({message:`分享失败,请重试`,theme:`error`})}};return{handleConfirmShare:async e=>{i&&await a(e),t(`confirm-share`,e)}}}function Dxt(e){let{props:n,emit:r,shortcutManager:i,doSendMessage:a,selectedShortcut:o}=e,s=i.effectiveShortcuts,l=(e,t)=>{let n=e,r;if(r=n.enable_fill_back&&n.fill_back_component_key?n.fill_back_component_key:n.components?.find(e=>e.fillBack)?.key,r&&t){let e=n.components?.map(e=>e.key===r?{...e,default:t}:{...e,default:e.default??void 0});o.value={...n,components:e,formModel:{...n.formModel,[r]:t}}}else o.value={...n,formModel:{...n.formModel}}},u=(e,t)=>{let n=e.components||[];return{extra:{cite:{type:`structured`,title:e.alias||e.name,data:n.map(e=>({key:e.name||e.key,value:String(t[e.key]??``)}))},command:e.id,context:n.map(e=>({[e.key]:t[e.key],context_type:e.type,__label:e.name||e.key,__key:e.key,__value:t[e.key]}))}}},d=e=>{let t=e.property?.extra;return t?.shortcut?t.shortcut:t?.command?s.value.find(e=>e.id===t.command)??null:null},f=(e,t)=>{l(e,t),r(`shortcut-click`,{shortcut:e,source:`main`})},p=()=>{o.value=null};return(0,t.watch)(()=>n.shortcuts,e=>{i.setShortcuts(e||[])},{immediate:!0}),(0,t.watch)(()=>e.chatHelper?.agent.info.value?.conversationSettings?.commands,e=>{e&&i.setAgentShortcuts(e)},{immediate:!0}),{effectiveShortcuts:s,selectShortcutWithText:l,buildShortcutProperty:u,getShortcutFromMessage:d,handleSelectShortcut:f,handleCloseShortcut:p,handleShortcutSubmit:async e=>{if(!o.value){console.error(`[ChatBot] No selected shortcut`);return}let t=u(o.value,e),n=o.value.name,i=o.value;p();try{await a(n,{property:t})}catch(e){o.value=i,console.error(`[ChatBot] Failed to submit shortcut:`,e),r(`error`,e)}}}}function Oxt(e){let{emit:t,chatHelper:n,chatBusinessManager:r,cite:i,focusInput:a,scrollToBottom:o,getShortcutFromMessage:s,buildShortcutProperty:l}=e,u=async e=>{if(!r||!n){console.error(`[ChatBot] Cannot delete messages: chatBusinessManager not initialized`);return}try{let t=r.messages.value,i=L9(t,e[0]);if(!i){console.error(`[ChatBot] No user message found before AI messages`);return}let a=[i,...e];await n.message.deleteMessages(a)}catch(e){console.error(`[ChatBot] Failed to delete messages:`,e),t(`error`,e)}},d=async e=>{if(!r||!n){console.error(`[ChatBot] Cannot regenerate: chatBusinessManager not initialized`);return}let i=n.session.current?.value?.sessionCode;if(!i){console.error(`[ChatBot] Cannot regenerate: no active session`);return}try{await r.regenerateFromAIMessages(e,i),o()}catch(e){console.error(`[ChatBot] Failed to regenerate:`,e),t(`error`,e)}},f=async e=>{if(!r||!n){console.error(`[ChatBot] Cannot delete message: chatHelper not initialized`);return}try{let t=r.messages.value,i=t.findIndex(t=>t===e);if(i===-1){console.error(`[ChatBot] User message not found in messages list`);return}let a=[];for(let e=i+1;e<t.length;e++){let n=t[e];if(n.role===O6.User)break;a.push(n)}let o=[e,...a];await n.message.deleteMessages(o)}catch(e){console.error(`[ChatBot] Failed to delete user message:`,e),t(`error`,e)}};return{handleAgentAction:async(e,t)=>{if(e.id===`cite`){i.value=t.filter(e=>e.role!==O6.Reasoning).map(e=>typeof e.content==`string`?e.content:JSON.stringify(e.content||``)).join(`
2804
+ `}),E=async()=>{if(a.sessionBusinessManager)try{await a.sessionBusinessManager.createNewSession()}catch(e){console.error(`Failed to create new session:`,e),(0,n.Message)({theme:`error`,message:R9(`创建会话失败`)})}o(`new-chat`)},D=e=>{e.stopPropagation(),a.sessionBusinessManager?(_||v(),_&&_.handleTriggerClick(e)):o(`history-click`,e)},O=()=>{o(`help-click`)},k=e=>{e.stopPropagation(),_&&_.isVisible()&&_.hide(),h&&(h.state.isVisible?h.hide():h.show())},A=e=>{e.stopPropagation(),e.preventDefault();let t=e.currentTarget,n=t.dataset.action;if(!t.classList.contains(`disabled`))switch(h&&h.hide(),n){case`rename`:j();break;case`auto-generate`:o(`auto-generate-name`);break;case`share`:o(`share`);break}},j=()=>{document.removeEventListener(`click`,F),p.value=a.sessionName||``,f.value=!0,setTimeout(()=>{document.addEventListener(`click`,F)},100),setTimeout(()=>{if(m.value)try{let e=m.value;e&&typeof e.focus==`function`&&e.focus();let t=e.$el?.querySelector(`input`);t&&typeof t.select==`function`&&t.select()}catch(e){console.warn(`Failed to focus rename input:`,e)}},100)},M=()=>{let e=p.value.trim();if(!e){N();return}o(`rename`,e),f.value=!1,p.value=``},N=()=>{f.value=!1,p.value=``},P=(e,t)=>{p.value=e,t.key===`Enter`?M():t.key===`Escape`&&N()},F=e=>{if(!f.value)return;let t=e.target,n=document.querySelector(`.rename-tooltip`);n&&!n.contains(t)&&N()},I=async()=>{if(!d.value)return;let e=(await import(`tippy.js`)).default;h&&=(h.destroy(),null),h=e(d.value,{content:T.value,theme:`ai-blueking-light more-menu-light light`,placement:`bottom-start`,trigger:`manual`,interactive:!0,allowHTML:!0,arrow:!1,offset:[0,4],appendTo:()=>document.querySelector(`.ai-blueking-panel`)||document.body,onShow:()=>{setTimeout(async()=>{let{default:e}=await import(`tippy.js`);document.querySelectorAll(`.tippy-menu-item`).forEach(t=>{let n=t;n.addEventListener(`click`,A);let r=n.getAttribute(`data-tippy-content`);if(r&&!g.has(n)){let t=e(n,{content:r,theme:`ai-blueking-tooltip`,trigger:`mouseenter focus`,arrow:!0,delay:[300,0],appendTo:()=>document.querySelector(`.ai-blueking-panel`)||document.body});g.set(n,t)}})},0)},onHide:()=>{document.querySelectorAll(`.tippy-menu-item`).forEach(e=>{let t=e;t.removeEventListener(`click`,A);let n=g.get(t);n&&(n.destroy(),g.delete(t))})}})};return(0,t.watch)(()=>[a.isCompressionHeight,a.hasSessionContents],()=>{h&&h.setContent(T.value)}),(0,t.onMounted)(()=>{I(),a.sessionBusinessManager&&v(),document.addEventListener(`click`,F)}),(0,t.onBeforeUnmount)(()=>{h&&=(h.destroy(),null),g.forEach(e=>{e.destroy()}),g.clear(),_&&=(_.destroy(),null),document.removeEventListener(`click`,F)}),r({headerRef:l,historyIconRef:u}),(r,i)=>((0,t.openBlock)(),(0,t.createElementBlock)(`div`,{ref_key:`headerRef`,ref:l,class:(0,t.normalizeClass)([`ai-header drag-handle`,{draggable:a.draggable}])},[(0,t.createElementVNode)(`div`,lxt,[(0,t.createElementVNode)(`div`,uxt,[(0,t.createElementVNode)(`img`,{alt:`logo`,src:(0,t.unref)(Nbt)},null,8,dxt)]),(0,t.createElementVNode)(`div`,{class:(0,t.normalizeClass)([`title`,{"title-with-tooltip":f.value}])},[(0,t.createTextVNode)((0,t.toDisplayString)(y.value)+` `,1),(0,t.createCommentVNode)(` 重命名 tooltip 直接绑定在 title 上 `),f.value?((0,t.openBlock)(),(0,t.createElementBlock)(`div`,fxt,[(0,t.createElementVNode)(`div`,pxt,[(0,t.createVNode)((0,t.unref)(n.Input),{ref_key:`renameInputRef`,ref:m,modelValue:p.value,"onUpdate:modelValue":i[0]||=e=>p.value=e,class:`rename-input`,placeholder:(0,t.unref)(R9)(`请输入新的会话名称`),onKeyup:P},null,8,[`modelValue`,`placeholder`]),(0,t.createElementVNode)(`div`,{class:`rename-buttons`},[(0,t.createElementVNode)(`i`,{class:`bkai-icon bkai-check-1 rename-btn confirm-btn`,onClick:M}),(0,t.createElementVNode)(`i`,{class:`bkai-icon bkai-close rename-btn cancel-btn`,onClick:N})])])])):(0,t.createCommentVNode)(`v-if`,!0)],2),a.showMoreIcon&&S.value?((0,t.openBlock)(),(0,t.createElementBlock)(`span`,{key:0,ref_key:`moreIconRef`,ref:d,class:`bkai-icon bkai-more`,onClick:k},null,512)):(0,t.createCommentVNode)(`v-if`,!0)]),(0,t.createElementVNode)(`div`,mxt,[(0,t.createCommentVNode)(` 新增会话按钮 `),a.showNewChatIcon&&e.enableChatSession!==!1?(0,t.withDirectives)(((0,t.openBlock)(),(0,t.createElementBlock)(`i`,{key:0,class:(0,t.normalizeClass)([`bkai-icon`,`bkai-xinzengliaotian`,{disabled:!S.value}]),style:(0,t.normalizeStyle)(w()),onClick:i[1]||=e=>S.value?E():void 0},null,6)),[[(0,t.unref)(s),{content:C((0,t.unref)(R9)(`新增会话`)),boundary:`parent`}]]):(0,t.createCommentVNode)(`v-if`,!0),(0,t.createCommentVNode)(` 历史会话按钮 `),a.showHistoryIcon&&e.enableChatSession!==!1?(0,t.withDirectives)(((0,t.openBlock)(),(0,t.createElementBlock)(`i`,{key:1,ref_key:`historyIconRef`,ref:u,class:(0,t.normalizeClass)([`bkai-icon`,`bkai-history`,{disabled:!S.value}]),style:(0,t.normalizeStyle)(w()),onClick:i[2]||=e=>S.value?D(e):void 0},null,6)),[[(0,t.unref)(s),{content:C((0,t.unref)(R9)(`历史会话`)),boundary:`parent`}]]):(0,t.createCommentVNode)(`v-if`,!0),e.chatGroup?.enabled?(0,t.withDirectives)(((0,t.openBlock)(),(0,t.createElementBlock)(`i`,{key:2,class:`bkai-icon bkai-zhushou`,onClick:O},null,512)),[[(0,t.unref)(s),{content:(0,t.unref)(R9)(`转人工`),boundary:`parent`}]]):(0,t.createCommentVNode)(`v-if`,!0),a.showCompressionIcon?(0,t.withDirectives)(((0,t.openBlock)(),(0,t.createElementBlock)(`i`,{key:3,class:(0,t.normalizeClass)([`bkai-icon`,b.value]),onClick:i[3]||=e=>o(`toggle-compression`)},null,2)),[[(0,t.unref)(s),{content:x.value,boundary:`parent`}]]):(0,t.createCommentVNode)(`v-if`,!0),(0,t.withDirectives)((0,t.createElementVNode)(`i`,{class:`bkai-icon bkai-close-line-2`,onClick:i[4]||=e=>o(`close`)},null,512),[[(0,t.unref)(s),{content:(0,t.unref)(R9)(`关闭`),boundary:`parent`}]])])],2))}}),[[`__scopeId`,`data-v-3cf2263c`]]),gxt=class{_isGenerating;_isStopLoading;agentModule;config;eventEmitter;messageModule;sessionModule;autoRenameSessionIfNeeded(e){this.sessionModule&&this.messageModule.list.value.length===1&&this.sessionModule.renameSession(e).catch(e=>{console.error(`[ChatBusinessManager] Auto rename session failed:`,e)})}emit(e,t){this.eventEmitter?.emit(e,t)}constructor(e,n,r=null,i=null,a={}){this.agentModule=e,this.messageModule=n,this.sessionModule=r,this.eventEmitter=i,this.config=a,this._isGenerating=(0,t.ref)(!1),this._isStopLoading=(0,t.ref)(!1)}get isGenerating(){return this._isGenerating}get isStopLoading(){return this._isStopLoading}get isMessagesLoading(){return this.messageModule.isListLoading}get messages(){return this.messageModule.list}get openingRemark(){return this.config.openingRemark||``}get predefinedQuestions(){return this.config.predefinedQuestions||[]}async batchDeleteMessages(e){try{await this.messageModule.deleteMessages(e);let t=e.map(e=>e.id).filter(Boolean);this.emit(`messages-batch-deleted`,{messageIds:t})}catch(e){throw console.error(`Failed to batch delete messages:`,e),this.emit(`chat-error`,{action:`batch-delete-messages`,error:e}),e}}async deleteMessage(e){try{await this.messageModule.deleteMessages([e]),this.emit(`message-deleted`,{messageId:e.id})}catch(e){throw console.error(`Failed to delete message:`,e),this.emit(`chat-error`,{action:`delete-message`,error:e}),e}}handleStreamEnd(){this._isGenerating.value=!1,this.emit(`receive-end`,{})}handleStreamError(e){this._isGenerating.value=!1,this.emit(`receive-error`,{error:e})}handleStreamStart(){this._isGenerating.value=!0,this.emit(`receive-start`,{})}async regenerateFromAIMessages(e,t){try{if(!e||e.length===0)throw Error(`No AI messages provided`);let n=this.messages.value,r=L9(n,e[0]);if(!r)throw Error(`No user message found before AI messages`);let i=r.id;if(i===void 0)throw Error(`User message has no id`);await this.regenerateMessage(String(i),t)}catch(e){throw console.error(`Failed to regenerate from AI messages:`,e),this.emit(`chat-error`,{action:`regenerate`,error:e}),e}}async regenerateMessage(e,t){try{let n=this.messages.value,r=n.findIndex(t=>String(t.id)===e);if(r===-1)throw Error(`Message not found: ${e}`);let i=n[r];if(i.role!==a.MessageRole.User)throw Error(`Can only regenerate from user messages`);let o=n.slice(r),s=typeof i.content==`string`?i.content:JSON.stringify(i.content),l=i.property;this._isGenerating.value=!0;let u=this.messageModule.deleteMessages(o);this.agentModule.chat(s,t,void 0,void 0,l),this.emit(`chat-regenerate`,{messageId:e}),u.catch(e=>{console.error(`[regenerateMessage] Delete API error:`,e)})}catch(e){throw console.error(`Failed to regenerate message:`,e),this._isGenerating.value=!1,this.emit(`chat-error`,{action:`regenerate`,error:e}),e}}async resendMessageWithProperty(e,t,n,r){try{let i=this.messages.value,o=i.findIndex(t=>String(t.id)===e);if(o===-1)throw Error(`Message not found: ${e}`);if(i[o].role!==a.MessageRole.User)throw Error(`Can only resend user messages`);let s=i.slice(o);this._isGenerating.value=!0;let l=this.messageModule.deleteMessages(s);this.agentModule.chat(n,t,void 0,void 0,r),this.emit(`chat-resend`,{messageId:e}),l.catch(e=>{console.error(`[resendMessageWithProperty] Delete API error:`,e)})}catch(e){throw console.error(`Failed to resend message with property:`,e),this._isGenerating.value=!1,this.emit(`chat-error`,{action:`resend`,error:e}),e}}async retryMessage(e){try{console.warn(`retryMessage not implemented yet`),this.emit(`chat-retry`,{messageId:e})}catch(e){throw console.error(`Failed to retry message:`,e),this.emit(`chat-error`,{action:`retry`,error:e}),e}}async sendMessage(e,t,n={}){try{if(!t)throw Error(`No active session. Please create or select a session first.`);this._isGenerating.value=!0,this.emit(`send-message`,{content:e}),await this.agentModule.chat(e,t,void 0,void 0,n.property),this.autoRenameSessionIfNeeded(t)}catch(e){throw console.error(`Failed to send message:`,e),this._isGenerating.value=!1,this.emit(`chat-error`,{action:`send`,error:e}),e}}async stopGeneration(){let e=this.sessionModule?.current?.value?.sessionCode??``;this._isStopLoading.value=!0;try{await this.agentModule.stopChat(e),this._isGenerating.value=!1,this.emit(`stop`,{})}catch(e){console.error(`Failed to stop generation:`,e),this.emit(`chat-error`,{action:`stop`,error:e})}finally{this._isStopLoading.value=!1}}},B9=class{agentModule;config;eventEmitter;sessionModule;emit(e,t){this.eventEmitter?.emit(e,t)}constructor(e,t=null,n=null,r={}){this.sessionModule=e,this.agentModule=t,this.eventEmitter=n,this.config=r}get currentSession(){return this.sessionModule.current}get isCreateLoading(){return this.sessionModule.isCreateLoading}get isCurrentLoading(){return this.sessionModule.isCurrentLoading}get isDeleteLoading(){return this.sessionModule.isDeleteLoading}get isListLoading(){return this.sessionModule.isListLoading}get isUpdateLoading(){return this.sessionModule.isUpdateLoading}get sessionList(){return this.sessionModule.list}async createNewSession(){return this.createSession({name:`新会话`,sessionCode:`new_session_${Date.now()}`})}async createSession(e={}){if(this.config.enableChatSession===!1)throw Error(`Chat session is disabled`);try{let t={sessionName:e.name||`新会话`,sessionCode:e.sessionCode||`session_${Date.now()}`,isTemporary:e.isTemporary||!1};await this.sessionModule.createSession(t);let n=this.agentModule?.info.value;n&&this.agentModule?.handleRole(n,t.sessionCode),this.emit(`session-created`,{session:this.sessionModule.current.value})}catch(e){throw console.error(`Failed to create session:`,e),this.emit(`session-error`,{action:`create`,error:e}),e}}async deleteSession(e){try{await this.sessionModule.deleteSession(e),this.emit(`session-deleted`,{sessionCode:e})}catch(e){throw console.error(`Failed to delete session:`,e),this.emit(`session-error`,{action:`delete`,error:e}),e}}async getSession(e){try{await this.sessionModule.getSession(e)}catch(e){throw console.error(`Failed to get session:`,e),this.emit(`session-error`,{action:`get`,error:e}),e}}async loadRecentSession(e){try{e?.skipLoadSessions||await this.loadSessions();let t=this.sessionList.value;if(this.config.initialSessionCode){await this.switchSession(this.config.initialSessionCode);return}if(t.length>0){let e=t[0];(e.sessionContentCount??0)>0?await this.createNewSession():await this.switchSession(e.sessionCode,{loadMessages:!1});return}await this.createNewSession()}catch(e){throw console.error(`Failed to load recent session:`,e),e}}async loadSessions(){try{await this.sessionModule.getSessions(),this.emit(`sessions-loaded`,{sessions:this.sessionList.value})}catch(e){throw console.error(`Failed to load sessions:`,e),this.emit(`session-error`,{action:`load`,error:e}),e}}async switchSession(e,t){try{await this.sessionModule.chooseSession(e,t),this.emit(`session-switched`,{session:this.sessionModule.current.value})}catch(e){throw console.error(`Failed to switch session:`,e),this.emit(`session-error`,{action:`switch`,error:e}),e}}async updateSessionName(e,t){try{let n=this.sessionList.value.find(t=>t.sessionCode===e);if(!n)throw Error(`Session not found: ${e}`);await this.sessionModule.updateSession({...n,sessionName:t}),this.emit(`session-updated`,{session:this.sessionModule.current.value})}catch(e){throw console.error(`Failed to update session name:`,e),this.emit(`session-error`,{action:`update`,error:e}),e}}},_xt=class{messageModule;sessionModule;constructor(e,t){this.messageModule=e,this.sessionModule=t}async shareMessages(e){if(e.length===0)throw Error(`No messages to share`);let t=this.sessionModule.current?.value?.sessionCode;if(!t)throw Error(`No active session`);let n=await this.messageModule.shareMessages(t,e);if(!n)throw Error(`Share failed: no result returned`);return{shareUrl:`${n.share_page}share-page/${n.share_token}`,userMessageIds:e.map(e=>String(e.id))}}},V9=class{_agentShortcuts;_effectiveShortcuts;_propsShortcuts;eventEmitter;emit(e,t){this.eventEmitter?.emit(e,t)}constructor(e=null,n=[]){this._propsShortcuts=(0,t.ref)(n),this._agentShortcuts=(0,t.ref)([]),this.eventEmitter=e,this._effectiveShortcuts=(0,t.computed)(()=>this._propsShortcuts.value.length>0?this._propsShortcuts.value:this._agentShortcuts.value.length>0?this._agentShortcuts.value:[])}get count(){return this._effectiveShortcuts.value.length}get effectiveShortcuts(){return this._effectiveShortcuts}get hasShortcuts(){return this._effectiveShortcuts.value.length>0}get shortcuts(){return this._effectiveShortcuts}addShortcut(e){this._propsShortcuts.value.push(e)}clear(){this._propsShortcuts.value=[],this._agentShortcuts.value=[]}filterByTextLength(e,t){return!e||e.length>t?[]:this._effectiveShortcuts.value}filterShortcuts(e,t){return t?this._effectiveShortcuts.value.filter(n=>t(n,e)):this._effectiveShortcuts.value}getShortcutById(e){return this._effectiveShortcuts.value.find(t=>t.id===e)}handleShortcutClick(e,t,n=`main`){this.emit(`shortcut-click`,{shortcut:e,selectedText:t,source:n})}limitShortcuts(e){return this._effectiveShortcuts.value.slice(0,e)}removeShortcut(e){this._propsShortcuts.value=this._propsShortcuts.value.filter(t=>t.id!==e)}setAgentShortcuts(e){this._agentShortcuts.value=e}setShortcuts(e){this._propsShortcuts.value=e}},vxt=class{_isCompressed;_isDraggingOrResizing;_nimbusMinimized;_panelVisible;_positionAndSize;cleanupFunctions;config;containerRef=null;debugMode;listeners;onceListeners;constructor(e={}){this.config=e,this.listeners=new Map,this.onceListeners=new Map,this.debugMode=e.debug??!1,this.cleanupFunctions=[],this._panelVisible=(0,t.ref)(e.initialPanelVisible??!1),this._nimbusMinimized=(0,t.ref)(e.initialNimbusMinimized??!1),this._isDraggingOrResizing=(0,t.ref)(!1),this._isCompressed=(0,t.ref)(!1),this._positionAndSize=(0,t.ref)({x:0,y:0,width:400,height:window.innerHeight})}get container(){return{updatePosition:this.updatePosition.bind(this),updateSize:this.updateSize.bind(this),updatePositionAndSize:this.updatePositionAndSize.bind(this),toggleCompression:this.toggleCompression.bind(this),expandForSidePanel:this.expandForSidePanel.bind(this),collapseSidePanel:this.collapseSidePanel.bind(this),positionAndSize:(0,t.computed)(()=>this.containerRef?.positionAndSize?.value??this._positionAndSize.value),isCompressed:(0,t.computed)(()=>this._isCompressed.value),isSidePanelExpanded:(0,t.computed)(()=>this.containerRef?.isSidePanelExpanded?.value??!1)}}get isCompressed(){return this._isCompressed}get isDraggingOrResizing(){return this._isDraggingOrResizing}get nimbus(){return{minimize:this.minimizeNimbus.bind(this),restore:this.restoreNimbus.bind(this),toggle:this.toggleNimbus.bind(this),isMinimized:(0,t.computed)(()=>this._nimbusMinimized.value)}}get nimbusMinimized(){return this._nimbusMinimized}get panel(){return{show:this.showPanel.bind(this),hide:this.hidePanel.bind(this),toggle:this.togglePanel.bind(this),isVisible:(0,t.computed)(()=>this._panelVisible.value)}}get panelVisible(){return this._panelVisible}get state(){return{panelVisible:this._panelVisible,nimbusMinimized:this._nimbusMinimized,isDraggingOrResizing:this._isDraggingOrResizing,positionAndSize:this._positionAndSize}}collapseSidePanel(){this.containerRef?.collapseSidePanel&&this.containerRef.collapseSidePanel()}destroy(){this.listeners.clear(),this.onceListeners.clear(),this.cleanupFunctions.forEach(e=>e()),this.cleanupFunctions=[],this.debugMode&&console.debug(`[ComponentManager] Destroyed`)}emit(e,t){this.debugMode&&console.debug(`[ComponentManager] Emitting "${e}"`,t);let n=this.listeners.get(e);n&&n.forEach(n=>{try{n(t)}catch(t){console.error(`[ComponentManager] Error in listener for "${e}":`,t)}});let r=this.onceListeners.get(e);if(r&&r.size>0){let n=Array.from(r);this.onceListeners.delete(e),n.forEach(n=>{try{n(t)}catch(t){console.error(`[ComponentManager] Error in once listener for "${e}":`,t)}})}}emitInternal(e,t){this.emit(e,t)}expandForSidePanel(e){this.containerRef?.expandForSidePanel&&this.containerRef.expandForSidePanel(e)}getConfig(){return this.config}getRegisteredEvents(){let e=new Set;return this.listeners.forEach((t,n)=>e.add(n)),this.onceListeners.forEach((t,n)=>e.add(n)),Array.from(e)}handleDragging(e){this._isDraggingOrResizing.value=!0,this._positionAndSize.value=e,this.emit(`dragging`,e)}handleDragStop(e){this._isDraggingOrResizing.value=!1,this._positionAndSize.value=e,this.emit(`drag-stop`,e)}handleNimbusClick(){this.emit(`nimbus-click`,{}),this.showPanel()}handlePopupClick(){this.emit(`popup-click`,{}),this.showPanel()}handlePopupShortcutClick(e){this.emit(`popup-shortcut-click`,{shortcut:e}),this.emit(`shortcut-click`,{shortcut:e,source:`popup`})}handleResizeStop(e){this._isDraggingOrResizing.value=!1,this._positionAndSize.value=e,this.emit(`resize-stop`,e)}handleResizing(e){this._isDraggingOrResizing.value=!0,this._positionAndSize.value=e,this.emit(`resizing`,e)}handleShortcutClick(e,t){this.emit(`shortcut-click`,{shortcut:e,source:t})}hasListeners(e){return this.listenerCount(e)>0}hidePanel(){this._panelVisible.value=!1,this.emit(`panel-hide`,{})}listenerCount(e){return(this.listeners.get(e)?.size??0)+(this.onceListeners.get(e)?.size??0)}minimizeNimbus(){this._nimbusMinimized.value=!0,this.emit(`nimbus-minimize`,{})}off(e,t){t?(this.listeners.get(e)?.delete(t),this.onceListeners.get(e)?.delete(t),this.debugMode&&console.debug(`[ComponentManager] Unsubscribed from "${e}", remaining: ${this.listenerCount(e)}`)):(this.listeners.delete(e),this.onceListeners.delete(e),this.debugMode&&console.debug(`[ComponentManager] Removed all listeners for "${e}"`))}on(e,t){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t),this.debugMode&&console.debug(`[ComponentManager] Subscribed to "${e}", total: ${this.listenerCount(e)}`),()=>{this.off(e,t)}}once(e,t){return this.onceListeners.has(e)||this.onceListeners.set(e,new Set),this.onceListeners.get(e).add(t),this.debugMode&&console.debug(`[ComponentManager] Subscribed once to "${e}"`),()=>{this.onceListeners.get(e)?.delete(t)}}restoreNimbus(){this._nimbusMinimized.value=!1,this.emit(`nimbus-restore`,{})}setCompressed(e){this._isCompressed.value=e}setContainerRef(e){this.containerRef=e,e?.isCompressed&&(this._isCompressed.value=e.isCompressed.value)}setDebugMode(e){this.debugMode=e}setDraggingOrResizing(e){this._isDraggingOrResizing.value=e}showPanel(e){this._panelVisible.value=!0,this.emit(`panel-show`,{sessionCode:e})}toggleCompression(){this.containerRef?this.containerRef.toggleCompression():this._isCompressed.value=!this._isCompressed.value}toggleNimbus(){this._nimbusMinimized.value?this.restoreNimbus():this.minimizeNimbus()}togglePanel(){this._panelVisible.value?this.hidePanel():this.showPanel()}updatePosition(e,t){this._positionAndSize.value={...this._positionAndSize.value,x:e,y:t}}updatePositionAndSize(e,t,n,r){this._positionAndSize.value={x:e,y:t,width:n,height:r}}updateSize(e,t){this._positionAndSize.value={...this._positionAndSize.value,width:e,height:t}}};function yxt(e){return new vxt(e)}var bxt={"panel-show":`show`,"panel-hide":`close`,"panel-toggle":null,"nimbus-click":null,"nimbus-minimize":null,"nimbus-restore":null,"popup-click":null,"popup-shortcut-click":null,dragging:`dragging`,resizing:`resizing`,"drag-stop":`drag-stop`,"resize-stop":`resize-stop`,"compression-toggle":null,"side-panel-expand":null,"side-panel-collapse":null,"send-message":`send-message`,"receive-start":`receive-start`,"receive-text":`receive-text`,"receive-end":`receive-end`,"receive-error":null,stop:`stop`,"chat-regenerate":null,"chat-retry":null,"message-deleted":null,"messages-batch-deleted":null,"session-created":null,"session-switched":null,"session-deleted":null,"session-updated":null,"sessions-loaded":null,"session-initialized":`session-initialized`,"session-error":null,"shortcut-click":`shortcut-click`,"chat-error":null,"sdk-error":`sdk-error`,"new-chat":`new-chat`,"history-click":`history-click`,"auto-generate-name":`auto-generate-name`,"help-click":`help-click`,rename:`rename`,share:`share`,close:`close`,"toggle-compression":null,"transfer-messages":`transfer-messages`,"share-messages":`share-messages`,"agent-info-loaded":null,error:null};function xxt(e,t){switch(e){case`send-message`:return[t.content];case`rename`:return[t.newName];case`history-click`:return[t.event];case`dragging`:case`resizing`:case`drag-stop`:case`resize-stop`:case`shortcut-click`:case`session-initialized`:case`sdk-error`:case`transfer-messages`:case`share-messages`:return[t];case`panel-show`:case`panel-hide`:case`receive-start`:case`receive-text`:case`receive-end`:case`stop`:case`new-chat`:case`auto-generate-name`:case`help-click`:case`share`:case`close`:return[];default:return[t]}}var Sxt=class{_selectedMessageIds;_isSelectionMode;_editingSessionCode;_loadingStates;constructor(){this._selectedMessageIds=(0,t.ref)(new Set),this._isSelectionMode=(0,t.ref)(!1),this._editingSessionCode=(0,t.ref)(null),this._loadingStates=(0,t.reactive)({})}get isSelectionMode(){return this._isSelectionMode}get editingSessionCode(){return this._editingSessionCode}toggleSelectionMode(){this._isSelectionMode.value=!this._isSelectionMode.value,this._isSelectionMode.value||this.clearSelection()}enableSelectionMode(){this._isSelectionMode.value=!0}disableSelectionMode(){this._isSelectionMode.value=!1,this.clearSelection()}toggleMessageSelection(e){this._selectedMessageIds.value.has(e)?this._selectedMessageIds.value.delete(e):this._selectedMessageIds.value.add(e),this._selectedMessageIds.value=new Set(this._selectedMessageIds.value)}selectMessage(e){this._selectedMessageIds.value.add(e),this._selectedMessageIds.value=new Set(this._selectedMessageIds.value)}deselectMessage(e){this._selectedMessageIds.value.delete(e),this._selectedMessageIds.value=new Set(this._selectedMessageIds.value)}isMessageSelected(e){return this._selectedMessageIds.value.has(e)}clearSelection(){this._selectedMessageIds.value.clear(),this._selectedMessageIds.value=new Set(this._selectedMessageIds.value)}selectAllMessages(e){this._selectedMessageIds.value=new Set(e)}get selectedMessages(){return Array.from(this._selectedMessageIds.value)}get selectedCount(){return this._selectedMessageIds.value.size}get hasSelection(){return this._selectedMessageIds.value.size>0}startEditingSession(e){this._editingSessionCode.value=e}stopEditingSession(){this._editingSessionCode.value=null}isEditingSession(e){return e?this._editingSessionCode.value===e:this._editingSessionCode.value!==null}setLoading(e,t){this._loadingStates[e]=t}isLoading(e){return this._loadingStates[e]??!1}clearLoadingStates(){Object.keys(this._loadingStates).forEach(e=>{this._loadingStates[e]=!1})}reset(){this.clearSelection(),this.disableSelectionMode(),this.stopEditingSession(),this.clearLoadingStates()}};function Cxt(e){let{props:n,emit:r,scrollToBottom:i}=e,o=(0,t.ref)(!1),s=(0,t.ref)(null),l=()=>n.chatHelper?!n.chatHelper.agent||!n.chatHelper.session||!n.chatHelper.message?{valid:!1,error:`[ChatBot] Invalid chatHelper: missing required modules (agent, session, message)`}:{valid:!0}:n.url?{valid:!0}:{valid:!1,error:`[ChatBot] Neither chatHelper nor url provided. Component requires at least one.`},u=(()=>{let e=l();if(!e.valid)return console.error(e.error),s.value=Error(e.error),null;if(n.chatHelper)return n.chatHelper;let t=new a.AGUIProtocol({onStart:()=>{r(`receive-start`)},onMessage:e=>{r(`receive-text`)},onDone:()=>{r(`receive-end`),i()},onError:e=>{r(`error`,e)}}),o=(0,a.useChatHelper)({requestData:{urlPrefix:Lbt(n.url),headers:n.requestOptions?.headers,data:n.requestOptions?.data},protocol:t});return t.injectMessageModule(o.message),o})(),d=!n.chatHelper,f=u?new B9(u.session,u.agent,null,{enableChatSession:!0,autoSwitchToInitialSession:!!n.sessionCode,loadRecentSessionOnMount:n.autoLoad,initialSessionCode:n.sessionCode}):null,p=u?new gxt(u.agent,u.message,u.session,null,{openingRemark:n.helloText,predefinedQuestions:n.prompts,placeholder:n.placeholder}):null,m=new V9(null,n.shortcuts||[]);return(0,t.onMounted)(async()=>{if(!(!u||s.value))try{d?(await Promise.all([u.agent.getAgentInfo(),u.session.getSessions()]),f&&await f.loadRecentSession({skipLoadSessions:!0}),o.value=!0):o.value=!0,r(`agent-info-loaded`,u)}catch(e){console.error(`Failed to initialize ChatBot:`,e),s.value=e,r(`error`,e)}}),(0,t.onBeforeUnmount)(()=>{d&&u&&u.agent.stopChat(u.session.current?.value?.sessionCode??``)}),{chatHelper:u,isStandaloneMode:d,isInitialized:o,initError:s,chatBusinessManager:p,sessionBusinessManager:f,shortcutManager:m}}function wxt(e){let{props:n,chatHelper:r,chatBusinessManager:i,sessionBusinessManager:a,shortcutManager:o,isStandaloneMode:s,isInitialized:l,selectedShortcut:u}=e,d=(0,t.computed)(()=>i?.isStopLoading.value?k6.StopLoading:((n.chatHelper||r)?.agent)?.isChatting?.value?k6.Streaming:k6.Complete),f=(0,t.computed)(()=>d.value===k6.Streaming?v5.Disabled:void 0),p=(0,t.computed)(()=>i?.messages.value??[]),m=(0,t.computed)(()=>i?.isMessagesLoading.value??!1);return{messageStatus:d,messageToolsStatus:f,messages:p,isMessagesLoading:m,isGenerating:(0,t.computed)(()=>i?.isGenerating.value??!1),currentSession:(0,t.computed)(()=>a?.currentSession.value??null),isWelcomeState:(0,t.computed)(()=>s&&!l.value?!1:!m.value&&p.value.length===0),openingRemark:(0,t.computed)(()=>r?.agent.info.value?.conversationSettings?.openingRemark||``),effectiveResources:(0,t.computed)(()=>n.resources?.length?n.resources:r?.agent.info.value?.resources??[]),effectivePrompts:(0,t.computed)(()=>n.prompts?.length?n.prompts:r?.agent.info.value?.conversationSettings?.predefinedQuestions??[]),effectiveSupportUpload:(0,t.computed)(()=>u.value?.supportUpload?u.value.supportUpload.vision===!0:r?.agent.info.value?.promptSetting?.supportUpload?.vision===!0),chatbotStyle:(0,t.computed)(()=>({height:typeof n.height==`number`?`${n.height}px`:n.height,maxWidth:typeof n.maxWidth==`number`?`${n.maxWidth}px`:n.maxWidth})),filteredShortcuts:(0,t.computed)(()=>o.shortcuts.value)}}function Txt(e){let{emit:n,chatHelper:r,chatBusinessManager:i,selectedShortcut:a,selectedResources:o}=e,s=(0,t.shallowRef)([[]]),l=(0,t.shallowRef)(``),u=(e,t)=>{s.value=e,o.value=t},d=async(e,t={})=>{if(!i||!r)throw Error(`[ChatBot] Cannot send message: chatBusinessManager not initialized`);let a=r.session.current?.value?.sessionCode;if(!a)throw Error(`[ChatBot] Cannot send message: no active session`);s.value=[[]],l.value=``,o.value=[],n(`send-message`,typeof e==`string`?e:``),await i.sendMessage(e,a,t)},f=async e=>{let t=r?.session.current?.value?.sessionCode;if(!t)throw Error(`[ChatBot] Cannot upload: no active session`);let n=await r.session.uploadFile(t,e);if(!n?.download_url)throw Error(`[ChatBot] Upload failed: no download URL returned`);return n},p=async(e,t)=>{try{let t={};l.value&&(t.cite=l.value),a.value&&(t.command=a.value.id),o.value.length&&(t.resources=o.value),await d(e,Object.keys(t).length?{property:{extra:t}}:{})}catch(e){console.error(`Failed to send message:`,e),n(`error`,e)}},m=async()=>{await h()},h=async()=>{if(!i){console.error(`[ChatBot] Cannot stop generation: chatBusinessManager not initialized`);return}await i.stopGeneration(),n(`stop`)};return{userInput:s,cite:l,handleUpdateModelValue:u,doSendMessage:d,handleSendMessage:p,handleUpload:f,handleStopSending:m,stopGeneration:h}}function Ext(e){let{emit:t,chatHelper:r,isStandaloneMode:i}=e,a=async e=>{if(!(!r||e.length===0))try{await Rbt((await new _xt(r.message,r.session).shareMessages(e)).shareUrl),(0,n.Message)({message:`分享链接已复制到剪贴板`,theme:`success`})}catch(e){console.error(`[ChatBot] Failed to share messages:`,e),(0,n.Message)({message:`分享失败,请重试`,theme:`error`})}};return{handleConfirmShare:async e=>{i&&await a(e),t(`confirm-share`,e)}}}function Dxt(e){let{props:n,emit:r,shortcutManager:i,doSendMessage:a,selectedShortcut:o}=e,s=i.effectiveShortcuts,l=(e,t)=>{let n=e,r;if(r=n.enable_fill_back&&n.fill_back_component_key?n.fill_back_component_key:n.components?.find(e=>e.fillBack)?.key,r&&t){let e=n.components?.map(e=>e.key===r?{...e,default:t}:{...e,default:e.default??void 0});o.value={...n,components:e,formModel:{...n.formModel,[r]:t}}}else o.value={...n,formModel:{...n.formModel}}},u=(e,t)=>{let n=e.components||[];return{extra:{cite:{type:`structured`,title:e.alias||e.name,data:n.map(e=>({key:e.name||e.key,value:String(t[e.key]??``)}))},command:e.id,context:n.map(e=>({[e.key]:t[e.key],context_type:e.type,__label:e.name||e.key,__key:e.key,__value:t[e.key]}))}}},d=e=>{let t=e.property?.extra;return t?.shortcut?t.shortcut:t?.command?s.value.find(e=>e.id===t.command)??null:null},f=(e,t)=>{l(e,t),r(`shortcut-click`,{shortcut:e,source:`main`})},p=()=>{o.value=null};return(0,t.watch)(()=>n.shortcuts,e=>{i.setShortcuts(e||[])},{immediate:!0}),(0,t.watch)(()=>e.chatHelper?.agent.info.value?.conversationSettings?.commands,e=>{e&&i.setAgentShortcuts(e)},{immediate:!0}),{effectiveShortcuts:s,selectShortcutWithText:l,buildShortcutProperty:u,getShortcutFromMessage:d,handleSelectShortcut:f,handleCloseShortcut:p,handleShortcutSubmit:async e=>{if(!o.value){console.error(`[ChatBot] No selected shortcut`);return}let t=u(o.value,e),n=o.value.name,i=o.value;p();try{await a(n,{property:t})}catch(e){o.value=i,console.error(`[ChatBot] Failed to submit shortcut:`,e),r(`error`,e)}}}}function Oxt(e){let{emit:t,chatHelper:n,chatBusinessManager:r,cite:i,focusInput:a,scrollToBottom:o,getShortcutFromMessage:s,buildShortcutProperty:l}=e,u=async e=>{if(!r||!n){console.error(`[ChatBot] Cannot delete messages: chatBusinessManager not initialized`);return}try{let t=r.messages.value,i=L9(t,e[0]);if(!i){console.error(`[ChatBot] No user message found before AI messages`);return}let a=[i,...e];await n.message.deleteMessages(a)}catch(e){console.error(`[ChatBot] Failed to delete messages:`,e),t(`error`,e)}},d=async e=>{if(!r||!n){console.error(`[ChatBot] Cannot regenerate: chatBusinessManager not initialized`);return}let i=n.session.current?.value?.sessionCode;if(!i){console.error(`[ChatBot] Cannot regenerate: no active session`);return}try{await r.regenerateFromAIMessages(e,i),o()}catch(e){console.error(`[ChatBot] Failed to regenerate:`,e),t(`error`,e)}},f=async e=>{if(!r||!n){console.error(`[ChatBot] Cannot delete message: chatHelper not initialized`);return}try{let t=r.messages.value,i=t.findIndex(t=>t===e);if(i===-1){console.error(`[ChatBot] User message not found in messages list`);return}let a=[];for(let e=i+1;e<t.length;e++){let n=t[e];if(n.role===O6.User)break;a.push(n)}let o=[e,...a];await n.message.deleteMessages(o)}catch(e){console.error(`[ChatBot] Failed to delete user message:`,e),t(`error`,e)}};return{handleAgentAction:async(e,t)=>{if(e.id===`cite`){i.value=t.filter(e=>e.role!==O6.Reasoning).map(e=>typeof e.content==`string`?e.content:JSON.stringify(e.content||``)).join(`
2805
2805
  `),a();return}if(e.id===`rebuild`){await d(t);return}if(e.id===`delete`){await u(t);return}if(e.id===`like`||e.id===`unlike`){let t=e.id===`like`?5:0;try{return await n?.session.getSessionFeedbackReasons(t)||[]}catch(e){return console.error(`[ChatBot] Failed to get feedback reasons:`,e),[]}}console.log(`handleAgentAction`,e,t)},handleAgentFeedback:async(e,i,a,o)=>{if(!n){console.error(`[ChatBot] Cannot submit feedback: chatHelper not initialized`);return}let s=n.session.current?.value?.sessionCode;if(!s){console.error(`[ChatBot] Cannot submit feedback: no active session`);return}let l=Pbt(r?.messages.value||[],i[0]);if(l===void 0){console.error(`[ChatBot] Cannot submit feedback: no user message found`);return}let u=e.id===`like`?5:0;try{await n.session.postSessionFeedback({sessionCode:s,sessionContentIds:[l],rate:u,labels:a,comment:o}),t(`feedback`,e,i[0],a,o)}catch(e){console.error(`[ChatBot] Failed to submit feedback:`,e),t(`error`,e)}},handleUserAction:async(e,t)=>{if(e.id===`delete`){await f(t);return}if(e.id===`cite`){i.value=typeof t.content==`string`?t.content:JSON.stringify(t.content||``),a();return}console.log(`handleUserAction`,e,t)},handleUserInputConfirm:async(e,r,i)=>{if(!n){console.error(`[ChatBot] Cannot edit message: chatHelper not initialized`);return}let a=n.session.current?.value?.sessionCode;if(!a){console.error(`[ChatBot] Cannot edit message: no active session`);return}let s=e.id;if(s===void 0){console.error(`[ChatBot] Cannot edit message: message has no id`);return}try{console.log(`handleUserInputConfirm`,s,a,r),await n.agent.resendMessage(String(s),a,r),o()}catch(e){console.error(`[ChatBot] Failed to edit and resend message:`,e),t(`error`,e)}},handleUserShortcutConfirm:async(e,i)=>{if(!r||!n){console.error(`[ChatBot] Cannot edit shortcut message: chatHelper not initialized`);return}let a=n.session.current?.value?.sessionCode;if(!a){console.error(`[ChatBot] Cannot edit shortcut message: no active session`);return}let u=e.id;if(u===void 0){console.error(`[ChatBot] Cannot edit shortcut message: message has no id`);return}try{let t=s(e);if(!t){console.error(`[ChatBot] Cannot edit shortcut message: shortcut not found`);return}let n=l(t,i),d=String(i.input??``);await r.resendMessageWithProperty(String(u),a,d,n),o()}catch(e){console.error(`[ChatBot] Failed to edit shortcut message:`,e),t(`error`,e)}},handleStopStreaming:async()=>{if(!r){console.error(`[ChatBot] Cannot stop generation: chatBusinessManager not initialized`);return}await r.stopGeneration(),t(`stop`)}}}var kxt={key:0,class:`chatbot-error`},Axt=(0,t.defineComponent)({__name:`chat-bot`,props:{autoLoad:{type:Boolean,default:!0},chatHelper:{default:void 0},enableSelection:{type:Boolean,default:!1},extCls:{},height:{},helloText:{},maxWidth:{},messageToolsTippyOptions:{},placeholder:{},prompts:{},requestOptions:{},resources:{default:()=>[]},sessionCode:{},shareLoading:{type:Boolean,default:!1},shortcuts:{default:()=>[]},url:{default:``}},emits:[`agent-info-loaded`,`cancel-share`,`confirm-share`,`error`,`execution-panel-change`,`feedback`,`receive-end`,`receive-start`,`receive-text`,`request-share`,`send-message`,`session-switched`,`shortcut-click`,`stop`],setup(e,{expose:n,emit:r}){let i=e,a=r,o=(0,t.ref)(),s=(0,t.ref)(),l=(0,t.ref)(),u=(0,t.shallowRef)([]),d=(0,t.ref)(null),f=async()=>{await(0,t.nextTick)(),o.value&&(o.value.scrollTop=o.value.scrollHeight)},p=()=>{l.value?.focus?.()},{chatHelper:m,isStandaloneMode:h,isInitialized:g,initError:_,chatBusinessManager:v,sessionBusinessManager:y,shortcutManager:b}=Cxt({props:i,emit:a,scrollToBottom:f}),{userInput:x,cite:S,handleUpdateModelValue:C,doSendMessage:w,handleSendMessage:T,handleUpload:E,handleStopSending:D,stopGeneration:O}=Txt({emit:a,chatHelper:m,chatBusinessManager:v,selectedShortcut:d,selectedResources:u}),{handleSelectShortcut:k,handleCloseShortcut:A,handleShortcutSubmit:j,selectShortcutWithText:M,getShortcutFromMessage:N,buildShortcutProperty:P}=Dxt({props:i,emit:a,chatHelper:m,shortcutManager:b,doSendMessage:w,selectedShortcut:d}),{messageStatus:F,messageToolsStatus:I,messages:L,isMessagesLoading:R,isGenerating:ee,currentSession:te,isWelcomeState:z,openingRemark:ne,effectiveResources:re,effectivePrompts:ie,effectiveSupportUpload:ae,chatbotStyle:oe,filteredShortcuts:se}=wxt({props:i,chatHelper:m,chatBusinessManager:v,sessionBusinessManager:y,shortcutManager:b,isStandaloneMode:h,isInitialized:g,selectedShortcut:d}),{handleAgentAction:B,handleAgentFeedback:ce,handleUserAction:le,handleUserInputConfirm:ue,handleUserShortcutConfirm:de,handleStopStreaming:fe}=Oxt({emit:a,chatHelper:m,chatBusinessManager:v,cite:S,focusInput:p,scrollToBottom:f,getShortcutFromMessage:N,buildShortcutProperty:P}),{handleConfirmShare:pe}=Ext({emit:a,chatHelper:m,isStandaloneMode:h}),me=e=>{a(`execution-panel-change`,e)},he=async e=>{let t=e.data?.props;if(t?.task_id!=null&&t?.node_id)return m?.message.getFlowAgentTaskNodeInfo(t.task_id,t.node_id)};return n({sendMessage:e=>T(e,[[]]),stopGeneration:O,switchSession:async e=>{if(!y){console.error(`[ChatBot] Cannot switch session: sessionBusinessManager not initialized`);return}try{await y.switchSession(e),a(`session-switched`,y.currentSession.value)}catch(e){console.error(`Failed to switch session:`,e),a(`error`,e)}},messages:L,currentSession:te,isGenerating:ee,getChatHelper:()=>m,setCiteText:e=>{S.value=e},focusInput:p,enterShareMode:()=>s.value?.enterShareMode(),exitShareMode:()=>s.value?.exitShareMode(),selectShortcut:(e,t)=>{M(e,t)}}),(n,r)=>((0,t.openBlock)(),(0,t.createElementBlock)(`div`,{class:(0,t.normalizeClass)([`ai-chatbot`,i.extCls,{"welcome-state":(0,t.unref)(z)}]),style:(0,t.normalizeStyle)((0,t.unref)(oe))},[(0,t.createCommentVNode)(` 初始化错误提示 `),(0,t.unref)(_)?((0,t.openBlock)(),(0,t.createElementBlock)(`div`,kxt,[(0,t.createElementVNode)(`span`,null,(0,t.toDisplayString)((0,t.unref)(_).message),1)])):((0,t.openBlock)(),(0,t.createElementBlock)(t.Fragment,{key:1},[(0,t.createCommentVNode)(` 独立模式:初始化中(getAgentInfo → getSessions → chooseSession)统一展示 Loading `),(0,t.createCommentVNode)(` <div
2806
2806
  v-else-if="isStandaloneMode && !isInitialized"
2807
2807
  class="chatbot-loading"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blueking/ai-blueking",
3
- "version": "2.0.0-beta.3",
3
+ "version": "2.0.0-beta.4",
4
4
  "description": "AI 小鲸 V2 - 基于新架构的智能对话组件",
5
5
  "license": "MIT",
6
6
  "author": "Tencent BlueKing",