import{k as U,o as W,w as H,_ as c,Z as a,Y as o,X as i,N as n,W as N,r as f,c as A,j as z,$ as h,F as O,R as X,L as Y,S as Z,U as G,V as l,m as t}from"./vendor-vue-Dqr9UV61-aster.js";import{c as x,i as M,j as r}from"./index-DHt40zKj-aster.js";import{P as J}from"./PageTour-CdU2AnnI-aster.js";import{_ as $}from"./PixelSection.vue_vue_type_script_setup_true_lang-BFSQ9vuX-aster.js";import{u as K,e as Q,h as j,B as p,j as ee}from"./vendor-ui-SnQwDthD-aster.js";import{p as se,a0 as te,a1 as ae,j as oe}from"./vendor-icons-B2dQ8Ycb-aster.js";import{_ as ie}from"./_plugin-vue_export-helper-DlAUqK2U-aster.js";import"./vendor-DWmN2shr-aster.js";const ne={class:"page"},le={class:"toolbar","data-tour":"sessions-actions"},re={class:"history-reader"},ue={class:"history-reader-head"},de={key:0,class:"history-empty"},ce={key:1,class:"history-empty"},me={key:2,class:"history-message-list"},ve={class:"history-message-role"},fe=U({__name:"SessionsView",setup(pe){const D=Z(),S=G(),w=K(),I=Q(),y=f(!1),k=f(!1),m=f([]),d=f([]),b=f(!1),u=A(()=>String(D.query.session||"")),g=A(()=>m.value.find(e=>e.id===u.value)),L=[{target:'[data-tour="sessions-actions"]',title:"刷新历史",text:"历史页展示本地保存的上下文列表。外部网关新建记录后，可以用刷新同步最新数据。"},{target:'[data-tour="sessions-table"]',title:"管理历史记录",text:"这里能查看标题、用户、消息数和更新时间，也可以清理不再需要的本地记录。"}],P=[{title:"历史",key:"title",minWidth:260,render:e=>t("div",[t("strong",r(e,["title"],r(e,["id"]))),t("div",{class:"muted small-text mono"},r(e,["id"]))])},{title:"用户",key:"userId",width:160,render:e=>t("span",r(e,["userId","user_id"],"-"))},{title:"消息数",key:"messageCount",width:100,render:e=>t("span",r(e,["messageCount","message_count"],"-"))},{title:"更新时间",key:"updatedAt",width:190,render:e=>t("span",M(r(e,["updatedAt","updated_at","createdAt"])))},{title:"操作",key:"actions",width:150,render(e){const s=r(e,["id"]);return t(j,{size:6},{default:()=>[t(p,{size:"tiny",secondary:!0,disabled:!s,onClick:()=>F(s)},{icon:()=>t(ae,{size:13}),default:()=>"查看"}),t(p,{size:"tiny",secondary:!0,type:"error",disabled:!s,onClick:()=>R(s)},{icon:()=>t(oe,{size:13}),default:()=>"删除"})]})}}];async function C(){y.value=!0;try{const e=await x.sessionsPage({limit:100,offset:0});m.value=e.items}catch(e){w.error(e.message)}finally{y.value=!1}}async function T(e){if(!e){d.value=[];return}k.value=!0;try{d.value=await x.sessionMessages(e)}catch(s){d.value=[],w.error(s.message)}finally{k.value=!1}}function F(e){e&&S.push({name:"sessions",query:{session:e}})}function V(){S.push({name:"sessions"})}function R(e){I.warning({title:"删除历史记录",content:e,positiveText:"删除",negativeText:"取消",async onPositiveClick(){await x.sessionDelete(e),m.value=m.value.filter(s=>r(s,["id"])!==e),u.value===e&&await V(),w.success("已删除"),await C()}})}function q(e){return e==="user"?"用户":e==="assistant"?"助手":e==="tool"?"工具":"系统"}return W(async()=>{await C(),await T(u.value)}),H(u,e=>{T(e)}),(e,s)=>{var B;return l(),c("div",ne,[a("div",le,[s[4]||(s[4]=a("div",null,[a("h2",{class:"section-title"},"历史"),a("p",{class:"section-subtitle"},"只读查看本地对话记录和网关映射上下文。")],-1)),o(n(j),null,{default:i(()=>[o(n(p),{size:"small",secondary:"",onClick:s[0]||(s[0]=v=>b.value=!0)},{icon:i(()=>[o(n(se),{size:14})]),default:i(()=>[s[2]||(s[2]=z(" 使用教程 ",-1))]),_:1}),o(n(p),{size:"small",secondary:"",loading:y.value,onClick:C},{default:i(()=>[...s[3]||(s[3]=[z("刷新",-1)])]),_:1},8,["loading"])]),_:1})]),u.value?(l(),N($,{key:0,"data-tour":"sessions-table",title:"历史详情",subtitle:((B=g.value)==null?void 0:B.title)||u.value},{default:i(()=>{var v;return[a("div",re,[a("div",ue,[o(n(p),{size:"small",secondary:"",onClick:V},{icon:i(()=>[o(n(te),{size:14})]),default:i(()=>[s[5]||(s[5]=z(" 返回列表 ",-1))]),_:1}),a("span",null,h(((v=g.value)==null?void 0:v.messageCount)??d.value.length)+" 条消息 · "+h(g.value?n(M)(g.value.updatedAt):u.value),1)]),k.value?(l(),c("div",de,"加载中...")):d.value.length===0?(l(),c("div",ce,"没有可显示的消息。")):(l(),c("div",me,[(l(!0),c(O,null,X(d.value,(_,E)=>(l(),c("article",{key:`${E}-${_.role}`,class:Y(["history-message",_.role])},[a("div",ve,h(q(_.role)),1),a("p",null,h(_.content||"(empty)"),1)],2))),128))]))])]}),_:1},8,["subtitle"])):(l(),N($,{key:1,"data-tour":"sessions-table",title:"历史表",subtitle:"可查看历史元数据，也可以删除本地历史记录。"},{default:i(()=>[o(n(ee),{columns:P,data:m.value,loading:y.value,bordered:!1},null,8,["data","loading"])]),_:1})),o(J,{show:b.value,"onUpdate:show":s[1]||(s[1]=v=>b.value=v),steps:L,"title-id":"sessionsTourTitle"},null,8,["show"])])}}}),ze=ie(fe,[["__scopeId","data-v-17982850"]]);export{ze as default};
