mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-08-15 23:10:59 +00:00
1 line
71 KiB
JavaScript
1 line
71 KiB
JavaScript
(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,75583,e=>{e.v({basicInfoContainer:"pipelineCard-module__GUxC_G__basicInfoContainer",basicInfoDescriptionText:"pipelineCard-module__GUxC_G__basicInfoDescriptionText",basicInfoLastUpdatedTimeContainer:"pipelineCard-module__GUxC_G__basicInfoLastUpdatedTimeContainer",basicInfoNameContainer:"pipelineCard-module__GUxC_G__basicInfoNameContainer",basicInfoNameText:"pipelineCard-module__GUxC_G__basicInfoNameText",basicInfoUpdateTimeIcon:"pipelineCard-module__GUxC_G__basicInfoUpdateTimeIcon",basicInfoUpdateTimeText:"pipelineCard-module__GUxC_G__basicInfoUpdateTimeText",bigText:"pipelineCard-module__GUxC_G__bigText",cardContainer:"pipelineCard-module__GUxC_G__cardContainer",debugButtonIcon:"pipelineCard-module__GUxC_G__debugButtonIcon",iconBasicInfoContainer:"pipelineCard-module__GUxC_G__iconBasicInfoContainer",iconEmoji:"pipelineCard-module__GUxC_G__iconEmoji",operationContainer:"pipelineCard-module__GUxC_G__operationContainer",operationDefaultBadge:"pipelineCard-module__GUxC_G__operationDefaultBadge",operationDefaultBadgeIcon:"pipelineCard-module__GUxC_G__operationDefaultBadgeIcon",operationDefaultBadgeText:"pipelineCard-module__GUxC_G__operationDefaultBadgeText"})},851,e=>{e.v({configPageContainer:"pipelineConfig-module__W2iQ7G__configPageContainer",pipelineListContainer:"pipelineConfig-module__W2iQ7G__pipelineListContainer"})},27180,e=>{"use strict";var s=e.i(60498),t=e.i(49311),a=e.i(57717);e.i(56907);var i=e.i(20317);class r{id;description;name;lastUpdatedTimeAgo;isDefault;emoji;constructor(e){this.id=e.id,this.name=e.name,this.description=e.description,this.lastUpdatedTimeAgo=e.lastUpdatedTimeAgo,this.isDefault=e.isDefault,this.emoji=e.emoji}}var n=e.i(75583);e.i(26128);var l=e.i(91830);function o({cardVO:e}){let{t}=(0,l.useTranslation)();return(0,s.jsxs)("div",{className:`${n.default.cardContainer}`,children:[(0,s.jsxs)("div",{className:`${n.default.basicInfoContainer}`,children:[(0,s.jsxs)("div",{className:`${n.default.iconBasicInfoContainer}`,children:[(0,s.jsx)("div",{className:`${n.default.iconEmoji}`,children:e.emoji||"⚙️"}),(0,s.jsxs)("div",{className:`${n.default.basicInfoNameContainer}`,children:[(0,s.jsx)("div",{className:`${n.default.basicInfoNameText} ${n.default.bigText}`,children:e.name}),(0,s.jsx)("div",{className:`${n.default.basicInfoDescriptionText}`,children:e.description})]})]}),(0,s.jsxs)("div",{className:`${n.default.basicInfoLastUpdatedTimeContainer}`,children:[(0,s.jsx)("svg",{className:`${n.default.basicInfoUpdateTimeIcon}`,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",children:(0,s.jsx)("path",{d:"M12 22C6.47715 22 2 17.5228 2 12C2 6.47715 6.47715 2 12 2C17.5228 2 22 6.47715 22 12C22 17.5228 17.5228 22 12 22ZM12 20C16.4183 20 20 16.4183 20 12C20 7.58172 16.4183 4 12 4C7.58172 4 4 7.58172 4 12C4 16.4183 7.58172 20 12 20ZM13 12H17V14H11V7H13V12Z"})}),(0,s.jsxs)("div",{className:`${n.default.basicInfoUpdateTimeText}`,children:[t("pipelines.updateTime"),e.lastUpdatedTimeAgo]})]})]}),e.isDefault&&(0,s.jsx)("div",{className:n.default.operationContainer,children:(0,s.jsxs)("div",{className:n.default.operationDefaultBadge,children:[(0,s.jsx)("svg",{className:n.default.operationDefaultBadgeIcon,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",children:(0,s.jsx)("path",{d:"M12.0006 18.26L4.94715 22.2082L6.52248 14.2799L0.587891 8.7918L8.61493 7.84006L12.0006 0.5L15.3862 7.84006L23.4132 8.7918L17.4787 14.2799L19.054 22.2082L12.0006 18.26Z"})}),(0,s.jsx)("div",{className:n.default.operationDefaultBadgeText,children:t("pipelines.defaultBadge")})]})})]})}var c=e.i(851),d=e.i(50098),m=e.i(4480),x=e.i(88274),g=e.i(8557),h=e.i(70917),p=e.i(71654),u=e.i(57728),b=e.i(16585),f=e.i(19309),j=e.i(64339),v=e.i(28332),y=e.i(11607);function C({itemConfigList:e,onSubmit:a,initialValues:i}){let[r,n]=(0,t.useState)(i?.["auth-type"]||"none"),l=f.z.object(e.reduce((e,s)=>{let t;switch(s.type){case"integer":case"float":t=f.z.number();break;case"boolean":t=f.z.boolean();break;case"string":case"select":case"llm-model-selector":default:t=f.z.string();break;case"array[string]":t=f.z.array(f.z.string());break;case"prompt-editor":t=f.z.array(f.z.object({content:f.z.string(),role:f.z.string()}))}return s.required&&(t instanceof f.z.ZodString||t instanceof f.z.ZodArray)&&(t=t.min(1,{message:"此字段为必填项"})),{...e,[s.name]:t}},{})),o=(0,u.useForm)({resolver:(0,b.zodResolver)(l),defaultValues:e.reduce((e,s)=>{let t=i?.[s.name]??s.default;return{...e,[s.name]:t}},{})});(0,t.useEffect)(()=>{if(i){let s=e.reduce((e,s)=>(e[s.name]=i[s.name]??s.default,e),{});Object.entries(s).forEach(([e,s])=>{o.setValue(e,s)}),n(s["auth-type"]||"none")}},[i,o,e]),(0,t.useEffect)(()=>{let s=o.watch((s,{name:t})=>{"auth-type"===t&&n(s["auth-type"]);let i=o.getValues(),r=e.reduce((e,s)=>(e[s.name]=i[s.name]??s.default,e),{});a?.(r)});return()=>s.unsubscribe()},[o,a,e]);let c=e.filter(e=>!!(["webhook-url","auth-type","timeout","output-key"].includes(e.name)||"basic"===r&&e.name.startsWith("basic-")||"jwt"===r&&e.name.startsWith("jwt-")||"header"===r&&e.name.startsWith("header-")));return(0,s.jsx)(j.Form,{...o,children:(0,s.jsx)("div",{className:"space-y-4",children:c.map(e=>(0,s.jsx)(j.FormField,{control:o.control,name:e.name,render:({field:t})=>(0,s.jsxs)(j.FormItem,{children:[(0,s.jsxs)(j.FormLabel,{children:[(0,y.extractI18nObject)(e.label)," ",e.required&&(0,s.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,s.jsx)(j.FormControl,{children:(0,s.jsx)(v.default,{config:e,field:t})}),e.description&&(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:(0,y.extractI18nObject)(e.description)}),(0,s.jsx)(j.FormMessage,{})]})},e.id))})})}var N=e.i(74035),k=e.i(87980),w=e.i(10542);function _({onFinish:e,onNewPipelineCreated:a,isEditMode:r,pipelineId:n,showButtons:o=!0,onDeletePipeline:c,onCancel:m}){let{t:g}=(0,l.useTranslation)(),[v,_]=(0,t.useState)(!1),[S,M]=(0,t.useState)(!1),[D,I]=(0,t.useState)(!1),T=r?f.z.object({basic:f.z.object({name:f.z.string().min(1,{message:g("pipelines.nameRequired")}),description:f.z.string().min(1,{message:g("pipelines.descriptionRequired")}),emoji:f.z.string().optional()}),ai:f.z.record(f.z.string(),f.z.any()),trigger:f.z.record(f.z.string(),f.z.any()),safety:f.z.record(f.z.string(),f.z.any()),output:f.z.record(f.z.string(),f.z.any())}):f.z.object({basic:f.z.object({name:f.z.string().min(1,{message:g("pipelines.nameRequired")}),description:f.z.string().min(1,{message:g("pipelines.descriptionRequired")}),emoji:f.z.string().optional()}),ai:f.z.record(f.z.string(),f.z.any()).optional(),trigger:f.z.record(f.z.string(),f.z.any()).optional(),safety:f.z.record(f.z.string(),f.z.any()).optional(),output:f.z.record(f.z.string(),f.z.any()).optional()}),L=r?[{label:g("pipelines.basicInfo"),name:"basic"},{label:g("pipelines.aiCapabilities"),name:"ai"},{label:g("pipelines.triggerConditions"),name:"trigger"},{label:g("pipelines.safetyControls"),name:"safety"},{label:g("pipelines.outputProcessing"),name:"output"}]:[{label:g("pipelines.basicInfo"),name:"basic"}],[B,V]=(0,t.useState)(),[H,z]=(0,t.useState)(),[E,P]=(0,t.useState)(),[F,U]=(0,t.useState)(),$=(0,u.useForm)({resolver:(0,b.zodResolver)(T),defaultValues:{basic:{emoji:"⚙️"},ai:{},trigger:{},safety:{},output:{}}}),R=(0,t.useRef)(""),G=$.watch(),A=(0,t.useMemo)(()=>!!r&&!!R.current&&JSON.stringify(G)!==R.current,[r,G]);function O(e,t){if("ai"===t){let a=$.watch("ai.runner.runner");if("runner"===e.name)return(0,s.jsxs)("div",{className:"space-y-4 mb-6",children:[(0,s.jsx)("div",{className:"text-lg font-medium",children:(0,y.extractI18nObject)(e.label)}),e.description&&(0,s.jsx)("div",{className:"text-sm text-gray-500",children:(0,y.extractI18nObject)(e.description)}),(0,s.jsx)(p.default,{itemConfigList:e.config,initialValues:$.watch(t)?.[e.name]||{},onSubmit:s=>{let a=$.getValues(t)||{};$.setValue(t,{...a,[e.name]:s})}})]},e.name);if(e.name!==a)return null;if("n8n-service-api"===e.name)return(0,s.jsxs)("div",{className:"space-y-4 mb-6",children:[(0,s.jsx)("div",{className:"text-lg font-medium",children:(0,y.extractI18nObject)(e.label)}),e.description&&(0,s.jsx)("div",{className:"text-sm text-gray-500",children:(0,y.extractI18nObject)(e.description)}),(0,s.jsx)(C,{itemConfigList:e.config,initialValues:$.watch(t)?.[e.name]||{},onSubmit:s=>{let a=$.getValues(t)||{};$.setValue(t,{...a,[e.name]:s})}})]},e.name)}return(0,s.jsxs)("div",{className:"space-y-4 mb-6",children:[(0,s.jsx)("div",{className:"text-lg font-medium",children:(0,y.extractI18nObject)(e.label)}),e.description&&(0,s.jsx)("div",{className:"text-sm text-gray-500",children:(0,y.extractI18nObject)(e.description)}),(0,s.jsx)(p.default,{itemConfigList:e.config,initialValues:$.watch(t)?.[e.name]||{},onSubmit:s=>{let a=$.getValues(t)||{};$.setValue(t,{...a,[e.name]:s})}})]},e.name)}return(0,t.useEffect)(()=>{i.httpClient.getGeneralPipelineMetadata().then(e=>{for(let s of e.configs)"ai"===s.name?V(s):"trigger"===s.name?z(s):"safety"===s.name?P(s):"output"===s.name&&U(s)}),r&&i.httpClient.getPipeline(n||"").then(e=>{I(e.pipeline.is_default??!1);let s={basic:{name:e.pipeline.name,description:e.pipeline.description,emoji:e.pipeline.emoji||"⚙️"},ai:e.pipeline.config.ai,trigger:e.pipeline.config.trigger,safety:e.pipeline.config.safety,output:e.pipeline.config.output};$.reset(s),R.current=JSON.stringify(s)})},[]),(0,t.useEffect)(()=>{r||$.reset({basic:{name:"",description:"",emoji:"⚙️"}})},[$,r]),(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"!max-w-[70vw] max-w-6xl h-full p-0 flex flex-col bg-white dark:bg-black",children:(0,s.jsxs)(j.Form,{...$,children:[(0,s.jsx)("form",{id:"pipeline-form",onSubmit:$.handleSubmit(function(s){var t,l;let o,c;r?(o={config:{ai:(t=s).ai,trigger:t.trigger,safety:t.safety,output:t.output},description:t.basic.description,name:t.basic.name,emoji:t.basic.emoji},i.httpClient.updatePipeline(n||"",o).then(()=>{R.current=JSON.stringify($.getValues()),e(),d.toast.success(g("pipelines.saveSuccess"))}).catch(e=>{d.toast.error(g("pipelines.saveError")+e.msg)})):(c={config:{},description:(l=s).basic.description,name:l.basic.name,emoji:l.basic.emoji},i.httpClient.createPipeline(c).then(s=>{e(),a(s.uuid),d.toast.success(g("pipelines.createSuccess"))}).catch(e=>{d.toast.error(g("pipelines.createError")+e.msg)}))}),className:"h-full flex flex-col flex-1 min-h-0 mb-2",children:(0,s.jsx)("div",{className:"flex-1 flex flex-col min-h-0",children:(0,s.jsxs)(h.Tabs,{defaultValue:L[0].name,className:"h-full flex flex-col flex-1 min-h-0",children:[(0,s.jsx)(h.TabsList,{children:L.map(e=>(0,s.jsx)(h.TabsTrigger,{value:e.name,children:e.label},e.name))}),(0,s.jsx)("div",{id:"pipeline-form-content",className:"flex-1 overflow-y-auto min-h-0",children:L.map(e=>(0,s.jsxs)(h.TabsContent,{value:e.name,className:"overflow-y-auto max-h-full",children:["basic"===e.name&&(0,s.jsxs)("div",{className:"space-y-6",children:[(0,s.jsxs)("div",{className:"flex gap-4 items-start",children:[(0,s.jsx)(j.FormField,{control:$.control,name:"basic.name",render:({field:e})=>(0,s.jsxs)(j.FormItem,{className:"flex-1",children:[(0,s.jsxs)(j.FormLabel,{children:[g("common.name"),(0,s.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,s.jsx)(j.FormControl,{children:(0,s.jsx)(k.Input,{...e})}),(0,s.jsx)(j.FormMessage,{})]})}),(0,s.jsx)(j.FormField,{control:$.control,name:"basic.emoji",render:({field:e})=>(0,s.jsxs)(j.FormItem,{children:[(0,s.jsx)(j.FormLabel,{children:g("common.icon")}),(0,s.jsx)(j.FormControl,{children:(0,s.jsx)(w.default,{value:e.value,onChange:e.onChange})}),(0,s.jsx)(j.FormMessage,{})]})})]}),(0,s.jsx)(j.FormField,{control:$.control,name:"basic.description",render:({field:e})=>(0,s.jsxs)(j.FormItem,{children:[(0,s.jsxs)(j.FormLabel,{children:[g("common.description"),(0,s.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,s.jsx)(j.FormControl,{children:(0,s.jsx)(k.Input,{...e})}),(0,s.jsx)(j.FormMessage,{})]})})]}),r&&(0,s.jsxs)(s.Fragment,{children:["ai"===e.name&&B&&(0,s.jsx)("div",{className:"space-y-6",children:B.stages.map(e=>O(e,"ai"))}),"trigger"===e.name&&H&&(0,s.jsx)("div",{className:"space-y-6",children:H.stages.map(e=>O(e,"trigger"))}),"safety"===e.name&&E&&(0,s.jsx)("div",{className:"space-y-6",children:E.stages.map(e=>O(e,"safety"))}),"output"===e.name&&F&&(0,s.jsx)("div",{className:"space-y-6",children:F.stages.map(e=>O(e,"output"))})]})]},e.name))})]})})}),o&&(0,s.jsxs)("div",{className:"flex justify-end items-center gap-2 pt-4 border-t mb-0 bg-white dark:bg-black sticky bottom-0 z-10",children:[r&&A&&(0,s.jsxs)("div",{className:"text-amber-600 dark:text-amber-400 text-sm flex items-center gap-1.5 mr-auto",children:[(0,s.jsx)("span",{className:"inline-block w-1.5 h-1.5 rounded-full bg-amber-500"}),g("pipelines.unsavedChanges")]}),r&&!D&&(0,s.jsx)(N.Button,{type:"button",variant:"destructive",onClick:()=>{_(!0)},children:g("common.delete")}),r&&D&&(0,s.jsx)("div",{className:"text-gray-500 text-sm h-full flex items-center mr-2",children:g("pipelines.defaultPipelineCannotDelete")}),r&&(0,s.jsx)(N.Button,{type:"button",variant:"default",onClick:()=>{M(!0)},className:"bg-green-600 hover:bg-green-700 text-white",children:g("common.copy")}),(0,s.jsx)(N.Button,{type:"submit",form:"pipeline-form",children:r?g("common.save"):g("common.submit")}),(0,s.jsx)(N.Button,{type:"button",variant:"outline",onClick:m,children:g("common.cancel")})]})]})}),(0,s.jsx)(x.Dialog,{open:v,onOpenChange:_,children:(0,s.jsxs)(x.DialogContent,{children:[(0,s.jsx)(x.DialogHeader,{children:(0,s.jsx)(x.DialogTitle,{children:g("common.confirmDelete")})}),(0,s.jsx)("div",{className:"py-4",children:g("pipelines.deleteConfirmation")}),(0,s.jsxs)(x.DialogFooter,{children:[(0,s.jsx)(N.Button,{variant:"outline",onClick:()=>_(!1),children:g("common.cancel")}),(0,s.jsx)(N.Button,{variant:"destructive",onClick:()=>{n&&i.httpClient.deletePipeline(n).then(()=>{c(),_(!1),d.toast.success(g("pipelines.deleteSuccess"))}).catch(e=>{d.toast.error(g("pipelines.deleteError")+e.msg)})},children:g("common.confirmDelete")})]})]})}),(0,s.jsx)(x.Dialog,{open:S,onOpenChange:M,children:(0,s.jsxs)(x.DialogContent,{children:[(0,s.jsx)(x.DialogHeader,{children:(0,s.jsx)(x.DialogTitle,{children:g("pipelines.copyConfirmTitle")})}),(0,s.jsx)("div",{className:"py-4",children:g("pipelines.copyConfirmation")}),(0,s.jsxs)(x.DialogFooter,{children:[(0,s.jsx)(N.Button,{variant:"outline",onClick:()=>M(!1),children:g("common.cancel")}),(0,s.jsx)(N.Button,{onClick:()=>{n&&i.httpClient.copyPipeline(n).then(()=>{e(),d.toast.success(g("common.copySuccess")),M(!1),m()}).catch(e=>{d.toast.error(g("pipelines.createError")+e.msg)})},children:g("common.confirm")})]})]})})]})}var S=e.i(42839),M=e.i(13781),D=e.i(14407),I=e.i(78083),T=e.i(54944);function L({targetName:e,readonly:t=!1,onRemove:a}){return(0,s.jsxs)(I.Badge,{variant:"secondary",className:"flex items-center gap-1 px-2 py-1 text-sm bg-blue-100 dark:bg-blue-900/40 text-blue-600 dark:text-blue-300 hover:bg-blue-200 dark:hover:bg-blue-900/60",children:["@",e,!t&&a&&(0,s.jsx)("button",{onClick:a,className:"ml-1 hover:text-blue-800 dark:hover:text-blue-200 focus:outline-none",children:(0,s.jsx)(T.X,{className:"h-3 w-3"})})]})}var B=e.i(71483);class V{pipelineId;sessionType;token;ws;connectionId;reconnectAttempts;maxReconnectAttempts;reconnectDelay;heartbeatInterval;heartbeatIntervalMs;isConnecting;onConnectedCallback;onMessageCallback;onErrorCallback;onCloseCallback;onBroadcastCallback;constructor(e,s="person",t){this.pipelineId=e,this.sessionType=s,this.token=t,this.ws=null,this.connectionId=null,this.reconnectAttempts=0,this.maxReconnectAttempts=5,this.reconnectDelay=3e3,this.heartbeatInterval=null,this.heartbeatIntervalMs=3e4,this.isConnecting=!1}connect(){return new Promise((e,s)=>{try{if(this.isConnecting||this.ws&&this.ws.readyState===WebSocket.CONNECTING){console.warn("WebSocket正在连接中,忽略重复连接请求"),s(Error("Connection already in progress"));return}if(this.ws&&this.ws.readyState===WebSocket.OPEN){console.warn("WebSocket已连接,忽略重复连接请求"),e(this.connectionId||"");return}this.isConnecting=!0;let t="https:"===window.location.protocol?"wss:":"ws:",a=B.default.env.NEXT_PUBLIC_API_BASE_URL?.split("://")[1]||window.location.host,i=`${t}//${a}/api/v1/pipelines/${this.pipelineId}/ws/connect?session_type=${this.sessionType}`;this.ws=new WebSocket(i),this.ws.onopen=()=>{this.reconnectAttempts=0,this.isConnecting=!1,this.startHeartbeat()},this.ws.onmessage=s=>{try{let t=JSON.parse(s.data);this.handleMessage(t),"connected"===t.type&&t.connection_id&&(this.connectionId=t.connection_id,e(t.connection_id))}catch(e){console.error("解析WebSocket消息失败:",e),this.onErrorCallback?.(e)}},this.ws.onclose=()=>{this.isConnecting=!1,this.stopHeartbeat(),this.onCloseCallback?.(),this.reconnectAttempts<this.maxReconnectAttempts&&(this.reconnectAttempts++,setTimeout(()=>{this.connect().catch(console.error)},this.reconnectDelay*this.reconnectAttempts))},this.ws.onerror=e=>{console.error("WebSocket错误:",e),this.isConnecting=!1;let t=Error("WebSocket连接失败");this.onErrorCallback?.(t),s(t)}}catch(e){this.isConnecting=!1,s(e)}})}handleMessage(e){switch(e.type){case"connected":this.onConnectedCallback?.(e);break;case"response":if(!e.session_type||e.session_type!==this.sessionType){console.debug(`忽略不匹配的消息: 当前session=${this.sessionType}, 消息session=${e.session_type}`);break}e.data&&this.onMessageCallback?.(e.data);break;case"user_message":if(!e.session_type||e.session_type!==this.sessionType){console.debug(`忽略不匹配的用户消息: 当前session=${this.sessionType}, 消息session=${e.session_type}`);break}e.data&&this.onMessageCallback?.(e.data);break;case"pong":break;case"broadcast":e.message&&this.onBroadcastCallback?.(e.message);break;case"error":let s=Error(e.message||"未知错误");this.onErrorCallback?.(s);break;default:console.warn("未知消息类型:",e)}}sendMessage(e,s=!0){if(!this.ws||this.ws.readyState!==WebSocket.OPEN)throw Error("WebSocket未连接");this.ws.send(JSON.stringify({type:"message",message:e,stream:s}))}sendHeartbeat(){this.ws&&this.ws.readyState===WebSocket.OPEN&&this.ws.send(JSON.stringify({type:"ping"}))}startHeartbeat(){this.stopHeartbeat(),this.heartbeatInterval=setInterval(()=>{this.sendHeartbeat()},this.heartbeatIntervalMs)}stopHeartbeat(){this.heartbeatInterval&&(clearInterval(this.heartbeatInterval),this.heartbeatInterval=null)}disconnect(){this.ws&&(this.stopHeartbeat(),this.reconnectAttempts=this.maxReconnectAttempts,this.ws.readyState===WebSocket.OPEN&&this.ws.send(JSON.stringify({type:"disconnect"})),this.ws.close(),this.ws=null,this.connectionId=null,this.isConnecting=!1)}getConnectionId(){return this.connectionId}isConnected(){return null!==this.ws&&this.ws.readyState===WebSocket.OPEN}onConnected(e){return this.onConnectedCallback=e,this}onMessage(e){return this.onMessageCallback=e,this}onError(e){return this.onErrorCallback=e,this}onClose(e){return this.onCloseCallback=e,this}onBroadcast(e){return this.onBroadcastCallback=e,this}}var H=e.i(48773),z=e.i(93245),E=e.i(49230),P=e.i(45880),F=e.i(37328),U=e.i(28783),$=e.i(63946);function R({open:e,pipelineId:a,isEmbedded:r=!1,onConnectionStatusChange:n}){let{t:o}=(0,l.useTranslation)(),[c,m]=(0,t.useState)(a),[g,h]=(0,t.useState)("person"),[p,u]=(0,t.useState)([]),[b,f]=(0,t.useState)(""),[j,v]=(0,t.useState)(!1),[y,C]=(0,t.useState)(!1),[w,_]=(0,t.useState)(!1),[I,T]=(0,t.useState)(!1),[B,R]=(0,t.useState)([]),[G,A]=(0,t.useState)(!1),[O,Z]=(0,t.useState)(""),[W,q]=(0,t.useState)(!1),[J,K]=(0,t.useState)(null),[Q,X]=(0,t.useState)(new Set),[Y,ee]=(0,t.useState)(!0),es=(0,t.useRef)(null),et=(0,t.useRef)(null),ea=(0,t.useRef)(null),ei=(0,t.useRef)(null),er=(0,t.useRef)(null),en=(0,t.useRef)(!1),el=(0,t.useCallback)(()=>{setTimeout(()=>{let e=document.querySelector(".scroll-area");e&&e.scrollTo({top:e.scrollHeight,behavior:"smooth"}),es.current?.scrollIntoView({behavior:"smooth"})},0)},[]),eo=(0,t.useCallback)(async e=>{try{let s=await i.httpClient.getWebSocketHistoryMessages(e,g);u(s.messages)}catch(e){console.error("Failed to load messages:",e)}},[g]),ec=(0,t.useCallback)(async e=>{if(!en.current)try{en.current=!0,er.current&&(er.current.disconnect(),er.current=null);let s=new V(e,g);s.onConnected(()=>{T(!0),en.current=!1}).onMessage(e=>{let s={...e,message_chain:e.message_chain};u(e=>{let t=e.findIndex(e=>e.id===s.id);if(!(t>=0))return[...e,s];{let a=[...e];return a[t]=s,a}})}).onError(e=>{console.error("WebSocket错误:",e),T(!1),en.current=!1,d.toast.error(o("pipelines.debugDialog.connectionError"))}).onClose(()=>{T(!1),en.current=!1}).onBroadcast(e=>{d.toast.info(e)}),await s.connect(),er.current=s}catch(e){console.error("WebSocket连接失败:",e),T(!1),en.current=!1,d.toast.error(o("pipelines.debugDialog.connectionFailed"))}},[g,o]);(0,t.useEffect)(()=>{el()},[p,el]),(0,t.useEffect)(()=>(e?m(a):er.current&&(er.current.disconnect(),er.current=null,T(!1),en.current=!1),()=>{er.current&&(er.current.disconnect(),er.current=null,en.current=!1)}),[e,a]),(0,t.useEffect)(()=>{e&&(u([]),eo(c),ec(c))},[g,c,e,eo,ec]),(0,t.useEffect)(()=>{n?.(I)},[I,n]),(0,t.useEffect)(()=>{let e=e=>{!ea.current||ea.current.contains(e.target)||et.current?.contains(e.target)||v(!1)};return document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[]),(0,t.useEffect)(()=>{j&&_(!0)},[j]);let ed=e=>{let s=e.target.value;"group"===g&&(s.endsWith("@")?v(!0):j&&(!s.includes("@")||s.length>1)&&v(!1)),f(s)},em=()=>{C(!0),v(!1),f(b.slice(0,-1))},ex=()=>{C(!1)},eg=e=>{"Enter"!==e.key||e.shiftKey?"Backspace"===e.key&&y&&""===b&&ex():(e.preventDefault(),j?em():ep())},eh=async e=>{let s=e.target.files;if(!s||0===s.length)return;let t=[];for(let e=0;e<s.length;e++){let a=s[e];if(a.type.startsWith("image/")){let e=URL.createObjectURL(a);t.push({file:a,preview:e})}}R(e=>[...e,...t])},ep=async()=>{if(b.trim()||y||0!==B.length||J){if(!I||!er.current)return void d.toast.error(o("pipelines.debugDialog.notConnected"));try{A(!0);let e=[];if(J){let s=J.message_chain.find(e=>"Source"===e.type),t=s?s.id:J.id;e.push({type:"Quote",id:t,origin:J.message_chain.filter(e=>"Source"!==e.type)})}let s=b.trim();for(let t of(y&&(s=" "+s),y&&e.push({type:"At",target:"websocketbot",display:"websocketbot"}),s&&e.push({type:"Plain",text:s}),B))try{let s=await i.httpClient.uploadWebSocketImage(c,t.file);e.push({type:"Image",path:s.file_key})}catch(e){console.error("图片上传失败:",e),d.toast.error(o("pipelines.debugDialog.imageUploadFailed"))}f(""),C(!1),K(null),B.forEach(e=>URL.revokeObjectURL(e.preview)),R([]),er.current.sendMessage(e,Y)}catch(e){console.error("Failed to send message:",e),d.toast.error(o("pipelines.debugDialog.sendFailed"))}finally{A(!1),et.current?.focus()}}},eu=(e,t)=>{switch(e.type){case"Plain":return(0,s.jsx)("span",{children:e.text},t);case"At":{let a=e.display||e.target?.toString()||"";return(0,s.jsx)("span",{className:"inline-flex align-middle mx-1",children:(0,s.jsx)(L,{targetName:a,readonly:!0})},t)}case"AtAll":return(0,s.jsx)("span",{className:"inline-flex align-middle mx-1",children:(0,s.jsx)(L,{targetName:"全体成员",readonly:!0})},t);case"Image":{let a=e.url||(e.base64?e.base64:"");if(!a)return null;return(0,s.jsx)("div",{className:"my-2",children:(0,s.jsx)("img",{src:a,alt:"Image",className:"max-w-full max-h-96 rounded-lg cursor-pointer hover:opacity-90 transition-opacity",onClick:()=>{Z(a),q(!0)}})},t)}case"File":return(0,s.jsxs)("div",{className:"my-2 flex items-center gap-2 text-sm",children:[(0,s.jsx)("svg",{className:"w-4 h-4",fill:"currentColor",viewBox:"0 0 20 20",children:(0,s.jsx)("path",{d:"M8 4a3 3 0 00-3 3v4a5 5 0 0010 0V7a1 1 0 112 0v4a7 7 0 11-14 0V7a5 5 0 0110 0v4a3 3 0 11-6 0V7a1 1 0 012 0v4a1 1 0 102 0V7a3 3 0 00-3-3z"})}),(0,s.jsxs)("span",{children:["[文件] ",e.name||"Unknown"]})]},t);case"Voice":{let a=e.url||(e.base64?e.base64:"");if(!a)return(0,s.jsx)("span",{children:"[语音]"},t);return(0,s.jsx)("div",{className:"my-2 flex items-center gap-2",children:(0,s.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 bg-gray-100 dark:bg-gray-800 rounded-lg",children:[(0,s.jsx)("svg",{className:"w-5 h-5",fill:"currentColor",viewBox:"0 0 20 20",children:(0,s.jsx)("path",{d:"M18 3a1 1 0 00-1.196-.98l-10 2A1 1 0 006 5v9.114A4.369 4.369 0 005 14c-1.657 0-3 .895-3 2s1.343 2 3 2 3-.895 3-2V7.82l8-1.6v5.894A4.37 4.37 0 0015 12c-1.657 0-3 .895-3 2s1.343 2 3 2 3-.895 3-2V3z"})}),(0,s.jsx)("audio",{controls:!0,src:a,className:"h-8",style:{maxWidth:"200px"},children:"Your browser does not support the audio element."}),e.length&&e.length>0&&(0,s.jsxs)("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:[e.length,"s"]})]})},t)}case"Quote":return(0,s.jsx)("div",{className:"mb-2 pl-3 border-l-2 border-gray-400 dark:border-gray-500",children:(0,s.jsx)("div",{className:"text-sm opacity-75",children:e.origin?.map((e,s)=>eu(e,s))})},t);case"Source":return null;default:return(0,s.jsxs)("span",{children:["[",e.type,"]"]},t)}},eb=e=>`${e.id}-${e.timestamp}`,ef=e=>e.message_chain.some(e=>"Plain"===e.type),ej=()=>(0,s.jsxs)("div",{className:"flex flex-1 h-full min-h-0",children:[(0,s.jsxs)("div",{className:"w-14 bg-white dark:bg-black p-2 pl-0 flex-shrink-0 flex flex-col justify-start gap-2",children:[(0,s.jsx)(N.Button,{variant:"ghost",size:"icon",className:`w-10 h-10 justify-center rounded-md transition-none ${"person"===g?"bg-[#2288ee] text-white hover:bg-[#2288ee] hover:text-white":"bg-white dark:bg-gray-800 text-gray-800 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-gray-700"} border-0 shadow-none`,onClick:()=>h("person"),children:(0,s.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-6 h-6",children:(0,s.jsx)("path",{d:"M4 22C4 17.5817 7.58172 14 12 14C16.4183 14 20 17.5817 20 22H18C18 18.6863 15.3137 16 12 16C8.68629 16 6 18.6863 6 22H4ZM12 13C8.685 13 6 10.315 6 7C6 3.685 8.685 1 12 1C15.315 1 18 3.685 18 7C18 10.315 15.315 13 12 13ZM12 11C14.21 11 16 9.21 16 7C16 4.79 14.21 3 12 3C9.79 3 8 4.79 8 7C8 9.21 9.79 11 12 11Z"})})}),(0,s.jsx)(N.Button,{variant:"ghost",size:"icon",className:`w-10 h-10 justify-center rounded-md transition-none ${"group"===g?"bg-[#2288ee] text-white hover:bg-[#2288ee] hover:text-white":"bg-white dark:bg-gray-800 text-gray-800 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-gray-700"} border-0 shadow-none`,onClick:()=>h("group"),children:(0,s.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-6 h-6",children:(0,s.jsx)("path",{d:"M2 22C2 17.5817 5.58172 14 10 14C14.4183 14 18 17.5817 18 22H16C16 18.6863 13.3137 16 10 16C6.68629 16 4 18.6863 4 22H2ZM10 13C6.685 13 4 10.315 4 7C4 3.685 6.685 1 10 1C13.315 1 16 3.685 16 7C16 10.315 13.315 13 10 13ZM10 11C12.21 11 14 9.21 14 7C14 4.79 12.21 3 10 3C7.79 3 6 4.79 6 7C6 9.21 7.79 11 10 11ZM18.2837 14.7028C21.0644 15.9561 23 18.752 23 22H21C21 19.564 19.5483 17.4671 17.4628 16.5271L18.2837 14.7028ZM17.5962 3.41321C19.5944 4.23703 21 6.20361 21 8.5C21 11.3702 18.8042 13.7252 16 13.9776V11.9646C17.6967 11.7222 19 10.264 19 8.5C19 7.11935 18.2016 5.92603 17.041 5.35635L17.5962 3.41321Z"})})})]}),(0,s.jsxs)("div",{className:"flex-1 flex flex-col w-[10rem] h-full min-h-0",children:[(0,s.jsx)(S.ScrollArea,{className:"flex-1 p-6 overflow-y-auto min-h-0 bg-white dark:bg-black scroll-area",children:(0,s.jsxs)("div",{className:"space-y-6",children:[0===p.length?(0,s.jsx)("div",{className:"text-center text-muted-foreground py-12 text-lg",children:o("pipelines.debugDialog.noMessages")}):p.map(e=>{let t;return(0,s.jsx)("div",{className:(0,D.cn)("flex","user"===e.role?"justify-end":"justify-start"),children:(0,s.jsxs)("div",{className:(0,D.cn)("max-w-3xl px-5 py-3 rounded-2xl","user"===e.role?"user-message-bubble bg-blue-100 dark:bg-blue-900 text-gray-900 dark:text-gray-100 rounded-br-none":"bg-gray-100 dark:bg-gray-800 text-gray-900 dark:text-gray-100 rounded-bl-none"),children:[(e=>{let t=eb(e);if(!Q.has(t)&&ef(e)){let t=e.message_chain.filter(e=>"Plain"===e.type).map(e=>e.text).join(""),a=e.message_chain.filter(e=>"Plain"!==e.type&&"Source"!==e.type);return(0,s.jsxs)("div",{className:"text-base leading-relaxed align-middle",children:[a.map((e,s)=>eu(e,s)),(0,s.jsx)("div",{className:"markdown-body",children:(0,s.jsx)(z.default,{remarkPlugins:[E.default],rehypePlugins:[F.default,P.default,U.default,[$.default,{behavior:"wrap",properties:{className:["anchor"]}}]],components:{ul:({children:e})=>(0,s.jsx)("ul",{className:"list-disc",children:e}),ol:({children:e})=>(0,s.jsx)("ol",{className:"list-decimal",children:e}),li:({children:e})=>(0,s.jsx)("li",{className:"ml-4",children:e}),img:({src:e,alt:t,...a})=>{let i=e||"";return"string"!=typeof i?(0,s.jsx)("img",{src:e,alt:t||"",className:"max-w-full h-auto rounded-lg my-4",...a}):(0,s.jsx)("img",{src:i,alt:t||"",className:"max-w-lg h-auto my-4",...a})}},children:t})})]})}return(0,s.jsx)("div",{className:"text-base leading-relaxed align-middle whitespace-pre-wrap",children:e.message_chain.map((e,s)=>eu(e,s))})})(e),(0,s.jsxs)("div",{className:(0,D.cn)("text-xs mt-2 flex items-center justify-between gap-2","user"===e.role?"text-gray-600 dark:text-gray-300":"text-gray-500 dark:text-gray-400"),children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{children:"user"===e.role?o("pipelines.debugDialog.userMessage"):o("pipelines.debugDialog.botMessage")}),ef(e)&&(0,s.jsx)("button",{onClick:()=>{let s;return s=eb(e),void X(e=>{let t=new Set(e);return t.has(s)?t.delete(s):t.add(s),t})},className:(0,D.cn)("px-1.5 py-0.5 rounded text-[10px] transition-colors","user"===e.role?"hover:bg-blue-200 dark:hover:bg-blue-800":"hover:bg-gray-200 dark:hover:bg-gray-700"),title:Q.has(eb(e))?o("pipelines.debugDialog.showMarkdown"):o("pipelines.debugDialog.showRaw"),children:Q.has(eb(e))?(0,s.jsxs)("span",{className:"flex items-center gap-0.5",children:[(0,s.jsx)("svg",{className:"w-3 h-3",viewBox:"0 0 16 16",fill:"currentColor",children:(0,s.jsx)("path",{d:"M14.85 3H1.15C.52 3 0 3.52 0 4.15v7.69C0 12.48.52 13 1.15 13h13.69c.64 0 1.15-.52 1.15-1.15v-7.7C16 3.52 15.48 3 14.85 3zM9 11H7V8L5.5 9.92 4 8v3H2V5h2l1.5 2L7 5h2v6zm2.99.5L9.5 8H11V5h2v3h1.5l-2.51 3.5z"})}),"MD"]}):(0,s.jsxs)("span",{className:"flex items-center gap-0.5",children:[(0,s.jsx)("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6h16M4 12h16M4 18h7"})}),o("pipelines.debugDialog.showRaw")]})}),(0,s.jsxs)("button",{onClick:()=>K(e),className:(0,D.cn)("px-1.5 py-0.5 rounded text-[10px] transition-colors flex items-center gap-0.5","user"===e.role?"hover:bg-blue-200 dark:hover:bg-blue-800":"hover:bg-gray-200 dark:hover:bg-gray-700"),title:o("pipelines.debugDialog.reply"),children:[(0,s.jsx)("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 10h10a8 8 0 018 8v2M3 10l6 6m-6-6l6-6"})}),o("pipelines.debugDialog.reply")]})]}),(0,s.jsx)("span",{className:"text-[10px]",children:(e=>{if(!e)return"";let s=new Date(1e3*e),t=new Date,a=s.getHours().toString().padStart(2,"0"),i=s.getMinutes().toString().padStart(2,"0");if(t.toDateString()===s.toDateString())return`${a}:${i}`;let r=new Date(t);return(r.setDate(r.getDate()-1),r.toDateString()===s.toDateString())?`${o("bots.yesterday")} ${a}:${i}`:t.getFullYear()===s.getFullYear()?o("bots.dateFormat",{month:s.getMonth()+1,day:s.getDate()}):o("bots.earlier")})((t=e.message_chain.find(e=>"Source"===e.type))&&t.timestamp?t.timestamp:e.timestamp?Math.floor(new Date(e.timestamp).getTime()/1e3):0)})]})]})},e.id+e.timestamp)}),(0,s.jsx)("div",{ref:es})]})}),J&&(0,s.jsx)("div",{className:"px-4 py-2 bg-gray-50 dark:bg-gray-900 border-t border-gray-200 dark:border-gray-700",children:(0,s.jsxs)("div",{className:"flex items-start gap-2",children:[(0,s.jsxs)("div",{className:"flex-1 pl-3 border-l-2 border-[#2288ee]",children:[(0,s.jsxs)("div",{className:"text-xs text-gray-500 dark:text-gray-400 mb-1",children:[o("pipelines.debugDialog.replyTo")," ","user"===J.role?o("pipelines.debugDialog.userMessage"):o("pipelines.debugDialog.botMessage")]}),(0,s.jsx)("div",{className:"text-sm text-gray-700 dark:text-gray-300 line-clamp-2",children:J.message_chain.filter(e=>"Plain"===e.type).map(e=>e.text).join("")})]}),(0,s.jsx)("button",{onClick:()=>K(null),className:"w-5 h-5 text-gray-500 hover:text-gray-700 dark:hover:text-gray-300",children:"×"})]})}),B.length>0&&(0,s.jsx)("div",{className:"px-4 pb-2 bg-white dark:bg-black",children:(0,s.jsx)("div",{className:"flex gap-2 flex-wrap",children:B.map((e,t)=>(0,s.jsxs)("div",{className:"relative group",children:[(0,s.jsx)("img",{src:e.preview,alt:`preview-${t}`,className:"w-20 h-20 object-cover rounded-lg border border-gray-300 dark:border-gray-600"}),(0,s.jsx)("button",{onClick:()=>{R(e=>{let s=[...e];return URL.revokeObjectURL(s[t].preview),s.splice(t,1),s})},className:"absolute -top-2 -right-2 w-5 h-5 bg-red-500 text-white rounded-full flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity",children:"×"})]},t))})}),(0,s.jsxs)("div",{className:"p-4 pb-0 bg-white dark:bg-black flex gap-2",children:[(0,s.jsxs)("div",{className:"flex gap-2 items-center",children:[(0,s.jsxs)("div",{className:"flex items-center gap-1",children:[(0,s.jsx)("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:o("pipelines.debugDialog.streamOutput")}),(0,s.jsx)(M.Switch,{checked:Y,onCheckedChange:ee,disabled:!I,className:"data-[state=checked]:bg-[#2288ee]"})]}),(0,s.jsx)("input",{ref:ei,type:"file",accept:"image/*",multiple:!0,onChange:eh,className:"hidden"}),(0,s.jsx)(N.Button,{variant:"ghost",size:"icon",onClick:()=>ei.current?.click(),disabled:!I||G,className:"w-10 h-10 rounded-md hover:bg-gray-100 dark:hover:bg-gray-700",title:"上传图片",children:(0,s.jsx)("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"})})})]}),(0,s.jsxs)("div",{className:"flex-1 flex items-center gap-2",children:[y&&(0,s.jsx)(L,{targetName:"websocketbot",onRemove:ex}),(0,s.jsxs)("div",{className:"relative flex-1",children:[(0,s.jsx)(k.Input,{ref:et,value:b,onChange:ed,onKeyPress:eg,placeholder:o("pipelines.debugDialog.inputPlaceholder",{type:"person"===g?o("pipelines.debugDialog.privateChat"):o("pipelines.debugDialog.groupChat")}),disabled:!I||G,className:"flex-1 rounded-md px-3 py-2 border border-gray-300 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-100 focus:border-[#2288ee] transition-none text-base disabled:opacity-50"}),j&&(0,s.jsx)("div",{ref:ea,className:"absolute bottom-full left-0 mb-2 w-auto rounded-md border bg-white dark:bg-gray-800 dark:border-gray-600 shadow-lg",children:(0,s.jsx)("div",{className:(0,D.cn)("flex items-center gap-2 px-4 py-1.5 rounded cursor-pointer",w?"bg-gray-100 dark:bg-gray-700":"bg-white dark:bg-gray-800"),onClick:em,onMouseEnter:()=>_(!0),onMouseLeave:()=>_(!1),children:(0,s.jsxs)("span",{className:"text-gray-800 dark:text-gray-200",children:["@websocketbot - ",o("pipelines.debugDialog.atTips")]})})})]})]}),(0,s.jsx)(N.Button,{onClick:ep,disabled:!b.trim()&&!y&&0===B.length&&!J||!I||G,className:"rounded-md bg-[#2288ee] hover:bg-[#2288ee] w-20 text-white px-6 py-2 text-base font-medium transition-none flex items-center gap-2 shadow-none disabled:opacity-50",children:G?"上传中...":o("pipelines.debugDialog.send")})]})]})]});return r?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"flex flex-col h-full min-h-0",children:(0,s.jsx)("div",{className:"flex-1 min-h-0 flex flex-col",children:ej()})}),(0,s.jsx)(H.default,{open:W,imageUrl:O,onClose:()=>q(!1)})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(x.DialogContent,{className:"!max-w-[70vw] max-w-6xl h-[70vh] p-6 flex flex-col rounded-2xl shadow-2xl bg-white dark:bg-black",children:ej()}),(0,s.jsx)(H.default,{open:W,imageUrl:O,onClose:()=>q(!1)})]})}var G=e.i(15742),A=e.i(41235),O=e.i(74110),Z=e.i(63737);let W=(0,e.i(83227).default)("server",[["rect",{width:"20",height:"8",x:"2",y:"2",rx:"2",ry:"2",key:"ngkwjq"}],["rect",{width:"20",height:"8",x:"2",y:"14",rx:"2",ry:"2",key:"iecqi9"}],["line",{x1:"6",x2:"6.01",y1:"6",y2:"6",key:"16zg32"}],["line",{x1:"6",x2:"6.01",y1:"18",y2:"18",key:"nzw8ys"}]]);var q=e.i(53397),J=e.i(54647),K=e.i(78059);function Q({pipelineId:e}){let{t:a}=(0,l.useTranslation)(),[i,r]=(0,t.useState)(!0),[n,o]=(0,t.useState)(!0),[c,m]=(0,t.useState)(!0),[g,h]=(0,t.useState)([]),[p,u]=(0,t.useState)([]),[b,f]=(0,t.useState)([]),[j,v]=(0,t.useState)([]),[y,C]=(0,t.useState)(!1),[k,w]=(0,t.useState)(!1),[_,S]=(0,t.useState)([]),[D,L]=(0,t.useState)([]);(0,t.useEffect)(()=>{V()},[e]);let B=e=>{let s=e.manifest.manifest.metadata.author,t=e.manifest.manifest.metadata.name;return`${s}/${t}`},V=async()=>{try{r(!0);let s=await G.backendClient.getPipelineExtensions(e);o(s.enable_all_plugins??!0),m(s.enable_all_mcp_servers??!0);let t=new Set(s.bound_plugins.map(e=>`${e.author}/${e.name}`)),a=s.available_plugins.filter(e=>t.has(B(e)));h(a),u(s.available_plugins);let i=new Set(s.bound_mcp_servers||[]),n=s.available_mcp_servers.filter(e=>i.has(e.uuid||""));f(n),v(s.available_mcp_servers)}catch(e){console.error("Failed to load extensions:",e),d.toast.error(a("pipelines.extensions.loadError"))}finally{r(!1)}},H=async(s,t,i,r)=>{try{let l=s.map(e=>{let s=e.manifest.manifest.metadata;return{author:s.author||"",name:s.name}}),o=t.map(e=>e.uuid||"");await G.backendClient.updatePipelineExtensions(e,l,o,i??n,r??c),d.toast.success(a("pipelines.extensions.saveSuccess"))}catch(e){console.error("Failed to save extensions:",e),d.toast.error(a("pipelines.extensions.saveError")),V()}},z=async e=>{let s=g.filter(s=>B(s)!==e);h(s),await H(s,b)},E=async e=>{let s=b.filter(s=>s.uuid!==e);f(s),await H(g,s)},P=()=>{_.length===p.length?S([]):S(p.map(e=>B(e)))},F=()=>{D.length===j.length?L([]):L(j.map(e=>e.uuid||""))},U=async()=>{let e=p.filter(e=>_.includes(B(e)));h(e),C(!1),await H(e,b)},$=async()=>{let e=j.filter(e=>D.includes(e.uuid||""));f(e),w(!1),await H(g,e)},R=async e=>{o(e),await H(g,b,e,void 0)},Q=async e=>{m(e),await H(g,b,void 0,e)};return i?(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsx)(A.Skeleton,{className:"h-20 w-full"}),(0,s.jsx)(A.Skeleton,{className:"h-20 w-full"}),(0,s.jsx)(A.Skeleton,{className:"h-20 w-full"})]}):(0,s.jsxs)("div",{className:"space-y-6",children:[(0,s.jsxs)("div",{className:"space-y-3",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsx)("h3",{className:"text-sm font-semibold text-foreground",children:a("pipelines.extensions.pluginsTitle")}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(J.Label,{htmlFor:"enable-all-plugins",className:"text-sm font-normal cursor-pointer",children:a("pipelines.extensions.enableAllPlugins")}),(0,s.jsx)(M.Switch,{id:"enable-all-plugins",checked:n,onCheckedChange:R})]})]}),(0,s.jsx)("div",{className:"space-y-2",children:n?(0,s.jsx)("div",{className:"flex h-32 items-center justify-center rounded-lg border-2 border-dashed border-border bg-muted/30",children:(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:a("pipelines.extensions.allPluginsEnabled")})}):0===g.length?(0,s.jsx)("div",{className:"flex h-32 items-center justify-center rounded-lg border-2 border-dashed border-border",children:(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:a("pipelines.extensions.noPluginsSelected")})}):(0,s.jsx)("div",{className:"space-y-2",children:g.map(e=>{let t=B(e),i=e.manifest.manifest.metadata;return(0,s.jsxs)("div",{className:"flex items-center justify-between rounded-lg border p-3 hover:bg-accent",children:[(0,s.jsxs)("div",{className:"flex-1 flex items-center gap-3",children:[(0,s.jsx)("img",{src:G.backendClient.getPluginIconURL(i.author||"",i.name),alt:i.name,className:"w-10 h-10 rounded-lg border bg-muted object-cover flex-shrink-0"}),(0,s.jsxs)("div",{className:"flex-1",children:[(0,s.jsx)("div",{className:"font-medium",children:i.name}),(0,s.jsxs)("div",{className:"text-sm text-muted-foreground",children:[i.author," • v",i.version]}),(0,s.jsx)("div",{className:"flex gap-1 mt-1",children:(0,s.jsx)(K.default,{components:(()=>{let s={};for(let t of e.components){let e=t.manifest.manifest.kind;s[e]?s[e]++:s[e]=1}return s})(),showComponentName:!0,showTitle:!1,useBadge:!0,t:a})})]}),!e.enabled&&(0,s.jsx)(I.Badge,{variant:"secondary",children:a("pipelines.extensions.disabled")})]}),(0,s.jsx)(N.Button,{variant:"ghost",size:"icon",onClick:()=>z(t),children:(0,s.jsx)(T.X,{className:"h-4 w-4"})})]},t)})})}),(0,s.jsxs)(N.Button,{onClick:()=>{S(g.map(e=>B(e))),C(!0)},variant:"outline",className:"w-full",disabled:n,children:[(0,s.jsx)(Z.Plus,{className:"mr-2 h-4 w-4"}),a("pipelines.extensions.addPlugin")]})]}),(0,s.jsxs)("div",{className:"space-y-3",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsx)("h3",{className:"text-sm font-semibold text-foreground",children:a("pipelines.extensions.mcpServersTitle")}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(J.Label,{htmlFor:"enable-all-mcp-servers",className:"text-sm font-normal cursor-pointer",children:a("pipelines.extensions.enableAllMCPServers")}),(0,s.jsx)(M.Switch,{id:"enable-all-mcp-servers",checked:c,onCheckedChange:Q})]})]}),(0,s.jsx)("div",{className:"space-y-2",children:c?(0,s.jsx)("div",{className:"flex h-32 items-center justify-center rounded-lg border-2 border-dashed border-border bg-muted/30",children:(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:a("pipelines.extensions.allMCPServersEnabled")})}):0===b.length?(0,s.jsx)("div",{className:"flex h-32 items-center justify-center rounded-lg border-2 border-dashed border-border",children:(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:a("pipelines.extensions.noMCPServersSelected")})}):(0,s.jsx)("div",{className:"space-y-2",children:b.map(e=>(0,s.jsxs)("div",{className:"flex items-center justify-between rounded-lg border p-3 hover:bg-accent",children:[(0,s.jsxs)("div",{className:"flex-1 flex items-center gap-3",children:[(0,s.jsx)("div",{className:"w-10 h-10 rounded-lg border bg-muted flex items-center justify-center flex-shrink-0",children:(0,s.jsx)(W,{className:"h-5 w-5 text-muted-foreground"})}),(0,s.jsxs)("div",{className:"flex-1",children:[(0,s.jsx)("div",{className:"font-medium",children:e.name}),(0,s.jsx)("div",{className:"text-sm text-muted-foreground",children:e.mode}),e.runtime_info&&"connected"===e.runtime_info.status&&(0,s.jsxs)(I.Badge,{variant:"outline",className:"flex items-center gap-1 mt-1",children:[(0,s.jsx)(q.Wrench,{className:"h-3 w-3 text-black dark:text-white"}),(0,s.jsx)("span",{className:"text-xs text-black dark:text-white",children:a("pipelines.extensions.toolCount",{count:e.runtime_info.tool_count||0})})]})]}),!e.enable&&(0,s.jsx)(I.Badge,{variant:"secondary",children:a("pipelines.extensions.disabled")})]}),(0,s.jsx)(N.Button,{variant:"ghost",size:"icon",onClick:()=>E(e.uuid||""),children:(0,s.jsx)(T.X,{className:"h-4 w-4"})})]},e.uuid))})}),(0,s.jsxs)(N.Button,{onClick:()=>{L(b.map(e=>e.uuid||"")),w(!0)},variant:"outline",className:"w-full",disabled:c,children:[(0,s.jsx)(Z.Plus,{className:"mr-2 h-4 w-4"}),a("pipelines.extensions.addMCPServer")]})]}),(0,s.jsx)(x.Dialog,{open:y,onOpenChange:C,children:(0,s.jsxs)(x.DialogContent,{className:"max-w-2xl max-h-[80vh] overflow-hidden flex flex-col",children:[(0,s.jsx)(x.DialogHeader,{children:(0,s.jsx)(x.DialogTitle,{children:a("pipelines.extensions.selectPlugins")})}),p.length>0&&(0,s.jsxs)("div",{className:"flex items-center gap-3 px-1 py-2 border-b cursor-pointer",onClick:P,children:[(0,s.jsx)(O.Checkbox,{checked:_.length===p.length&&p.length>0,onCheckedChange:P}),(0,s.jsx)("span",{className:"text-sm font-medium",children:a("pipelines.extensions.selectAll")})]}),(0,s.jsx)("div",{className:"flex-1 overflow-y-auto space-y-2 pr-2",children:0===p.length?(0,s.jsx)("div",{className:"flex h-full items-center justify-center",children:(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:a("pipelines.extensions.noPluginsInstalled")})}):p.map(e=>{let t=B(e),i=e.manifest.manifest.metadata,r=_.includes(t);return(0,s.jsxs)("div",{className:"flex items-center gap-3 rounded-lg border p-3 hover:bg-accent cursor-pointer",onClick:()=>{S(e=>e.includes(t)?e.filter(e=>e!==t):[...e,t])},children:[(0,s.jsx)(O.Checkbox,{checked:r}),(0,s.jsx)("img",{src:G.backendClient.getPluginIconURL(i.author||"",i.name),alt:i.name,className:"w-10 h-10 rounded-lg border bg-muted object-cover flex-shrink-0"}),(0,s.jsxs)("div",{className:"flex-1",children:[(0,s.jsx)("div",{className:"font-medium",children:i.name}),(0,s.jsxs)("div",{className:"text-sm text-muted-foreground",children:[i.author," • v",i.version]}),(0,s.jsx)("div",{className:"flex gap-1 mt-1",children:(0,s.jsx)(K.default,{components:(()=>{let s={};for(let t of e.components){let e=t.manifest.manifest.kind;s[e]?s[e]++:s[e]=1}return s})(),showComponentName:!0,showTitle:!1,useBadge:!0,t:a})})]}),!e.enabled&&(0,s.jsx)(I.Badge,{variant:"secondary",children:a("pipelines.extensions.disabled")})]},t)})}),(0,s.jsxs)(x.DialogFooter,{children:[(0,s.jsx)(N.Button,{variant:"outline",onClick:()=>C(!1),children:a("common.cancel")}),(0,s.jsx)(N.Button,{onClick:U,children:a("common.confirm")})]})]})}),(0,s.jsx)(x.Dialog,{open:k,onOpenChange:w,children:(0,s.jsxs)(x.DialogContent,{className:"max-w-2xl max-h-[80vh] overflow-hidden flex flex-col",children:[(0,s.jsx)(x.DialogHeader,{children:(0,s.jsx)(x.DialogTitle,{children:a("pipelines.extensions.selectMCPServers")})}),j.length>0&&(0,s.jsxs)("div",{className:"flex items-center gap-3 px-1 py-2 border-b cursor-pointer",onClick:F,children:[(0,s.jsx)(O.Checkbox,{checked:D.length===j.length&&j.length>0,onCheckedChange:F}),(0,s.jsx)("span",{className:"text-sm font-medium",children:a("pipelines.extensions.selectAll")})]}),(0,s.jsx)("div",{className:"flex-1 overflow-y-auto space-y-2 pr-2",children:0===j.length?(0,s.jsx)("div",{className:"flex h-full items-center justify-center",children:(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:a("pipelines.extensions.noMCPServersConfigured")})}):j.map(e=>{let t=D.includes(e.uuid||"");return(0,s.jsxs)("div",{className:"flex items-center gap-3 rounded-lg border p-3 hover:bg-accent cursor-pointer",onClick:()=>{var s;return s=e.uuid||"",void L(e=>e.includes(s)?e.filter(e=>e!==s):[...e,s])},children:[(0,s.jsx)(O.Checkbox,{checked:t}),(0,s.jsx)("div",{className:"w-10 h-10 rounded-lg border bg-muted flex items-center justify-center flex-shrink-0",children:(0,s.jsx)(W,{className:"h-5 w-5 text-muted-foreground"})}),(0,s.jsxs)("div",{className:"flex-1",children:[(0,s.jsx)("div",{className:"font-medium",children:e.name}),(0,s.jsx)("div",{className:"text-sm text-muted-foreground",children:e.mode}),e.runtime_info&&"connected"===e.runtime_info.status&&(0,s.jsxs)(I.Badge,{variant:"outline",className:"flex items-center gap-1 mt-1",children:[(0,s.jsx)(q.Wrench,{className:"h-3 w-3 text-black dark:text-white"}),(0,s.jsx)("span",{className:"text-xs text-black dark:text-white",children:a("pipelines.extensions.toolCount",{count:e.runtime_info.tool_count||0})})]})]}),!e.enable&&(0,s.jsx)(I.Badge,{variant:"secondary",children:a("pipelines.extensions.disabled")})]},e.uuid)})}),(0,s.jsxs)(x.DialogFooter,{children:[(0,s.jsx)(N.Button,{variant:"outline",onClick:()=>w(!1),children:a("common.cancel")}),(0,s.jsx)(N.Button,{onClick:$,children:a("common.confirm")})]})]})})]})}var X=e.i(37106),Y=e.i(21984),ee=e.i(56604),es=e.i(55152),et=e.i(10034),ea=e.i(16700);function ei({pipelineId:e,onNavigateToMonitoring:a}){let{t:r}=(0,l.useTranslation)(),n=(0,t.useMemo)(()=>({selectedBots:[],selectedPipelines:[e],timeRange:"last24Hours",customDateRange:null}),[e]),{data:o,loading:c,refetch:d}=(0,es.useMonitoringData)(n),[m,x]=(0,t.useState)(null),[g,p]=(0,t.useState)({}),[u,b]=(0,t.useState)({}),[f,j]=(0,t.useState)(null),[v,y]=(0,t.useState)("messages"),C=async e=>{if(m===e)x(null);else if(x(e),!g[e]){b(s=>({...s,[e]:!0}));try{let s=await i.httpClient.get(`/api/v1/monitoring/messages/${e}/details`);s&&p(t=>({...t,[e]:{messageId:s.message_id,found:s.found,message:s.message?{id:s.message.id,timestamp:new Date(s.message.timestamp),botId:s.message.bot_id,botName:s.message.bot_name,pipelineId:s.message.pipeline_id,pipelineName:s.message.pipeline_name,messageContent:s.message.message_content,sessionId:s.message.session_id,status:s.message.status,level:s.message.level,platform:s.message.platform,userId:s.message.user_id,runnerName:s.message.runner_name,variables:s.message.variables}:void 0,llmCalls:s.llm_calls.map(e=>({id:e.id,timestamp:new Date(e.timestamp),modelName:e.model_name,status:e.status,duration:e.duration,errorMessage:e.error_message,tokens:{input:e.input_tokens||0,output:e.output_tokens||0,total:e.total_tokens||0}})),errors:s.errors.map(e=>({id:e.id,timestamp:new Date(e.timestamp),errorType:e.error_type,errorMessage:e.error_message,stackTrace:e.stack_trace})),llmStats:{totalCalls:s.llm_stats.total_calls,totalInputTokens:s.llm_stats.total_input_tokens,totalOutputTokens:s.llm_stats.total_output_tokens,totalTokens:s.llm_stats.total_tokens,totalDurationMs:s.llm_stats.total_duration_ms,averageDurationMs:s.llm_stats.average_duration_ms}}}))}catch(e){console.error("Failed to fetch message details:",e)}finally{b(s=>({...s,[e]:!1}))}}},k=async e=>{y("messages"),setTimeout(()=>{C(e)},100)};return(0,s.jsxs)("div",{className:"w-full h-full flex flex-col",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-4 pb-4 border-b border-gray-200 dark:border-gray-700",children:[(0,s.jsx)("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:r("pipelines.monitoring.description")}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[a&&(0,s.jsxs)(N.Button,{variant:"outline",size:"sm",onClick:a,className:"bg-white dark:bg-[#2a2a2e] hover:bg-gray-50 dark:hover:bg-gray-800 border-gray-300 dark:border-gray-600",children:[(0,s.jsx)("svg",{className:"w-4 h-4 mr-2",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",children:(0,s.jsx)("path",{d:"M10 6V8H5V19H16V14H18V20C18 20.5523 17.5523 21 17 21H4C3.44772 21 3 20.5523 3 20V7C3 6.44772 3.44772 6 4 6H10ZM21 3V11H19V6.413L11.2071 14.2071L9.79289 12.7929L17.585 5H13V3H21Z"})}),r("pipelines.monitoring.detailedLogs")]}),(0,s.jsxs)(N.Button,{variant:"outline",size:"sm",onClick:d,className:"bg-white dark:bg-[#2a2a2e] hover:bg-gray-50 dark:hover:bg-gray-800 border-gray-300 dark:border-gray-600",children:[(0,s.jsx)("svg",{className:"w-4 h-4 mr-2",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",children:(0,s.jsx)("path",{d:"M5.46257 4.43262C7.21556 2.91688 9.5007 2 12 2C17.5228 2 22 6.47715 22 12C22 14.1361 21.3302 16.1158 20.1892 17.7406L17 12H20C20 7.58172 16.4183 4 12 4C9.84982 4 7.89777 4.84827 6.46023 6.22842L5.46257 4.43262ZM18.5374 19.5674C16.7844 21.0831 14.4993 22 12 22C6.47715 22 2 17.5228 2 12C2 9.86386 2.66979 7.88416 3.8108 6.25944L7 12H4C4 16.4183 7.58172 20 12 20C14.1502 20 16.1022 19.1517 17.5398 17.7716L18.5374 19.5674Z"})}),r("monitoring.refreshData")]})]})]}),o&&(0,s.jsxs)("div",{className:"grid grid-cols-3 gap-4 mb-6",children:[(0,s.jsxs)("div",{className:"bg-white dark:bg-[#2a2a2e] rounded-lg border border-gray-200 dark:border-gray-700 p-4",children:[(0,s.jsx)("div",{className:"text-sm text-gray-500 dark:text-gray-400",children:r("monitoring.totalMessages")}),(0,s.jsx)("div",{className:"text-2xl font-bold text-gray-900 dark:text-gray-100 mt-1",children:o.overview.totalMessages})]}),(0,s.jsxs)("div",{className:"bg-white dark:bg-[#2a2a2e] rounded-lg border border-gray-200 dark:border-gray-700 p-4",children:[(0,s.jsx)("div",{className:"text-sm text-gray-500 dark:text-gray-400",children:r("monitoring.successRate")}),(0,s.jsxs)("div",{className:"text-2xl font-bold text-gray-900 dark:text-gray-100 mt-1",children:[o.overview.successRate.toFixed(1),"%"]})]}),(0,s.jsxs)("div",{className:"bg-white dark:bg-[#2a2a2e] rounded-lg border border-gray-200 dark:border-gray-700 p-4",children:[(0,s.jsx)("div",{className:"text-sm text-gray-500 dark:text-gray-400",children:r("monitoring.tabs.errors")}),(0,s.jsx)("div",{className:"text-2xl font-bold text-red-600 dark:text-red-400 mt-1",children:o.errors.length})]})]}),(0,s.jsxs)(h.Tabs,{value:v,onValueChange:y,className:"flex-1 flex flex-col min-h-0",children:[(0,s.jsxs)(h.TabsList,{className:"bg-gray-100 dark:bg-[#1a1a1e] h-10 p-1 mb-4",children:[(0,s.jsx)(h.TabsTrigger,{value:"messages",className:"px-4 py-1.5 text-sm font-medium cursor-pointer data-[state=active]:bg-white dark:data-[state=active]:bg-[#2a2a2e] data-[state=active]:shadow-sm",children:r("monitoring.tabs.messages")}),(0,s.jsx)(h.TabsTrigger,{value:"errors",className:"px-4 py-1.5 text-sm font-medium cursor-pointer data-[state=active]:bg-white dark:data-[state=active]:bg-[#2a2a2e] data-[state=active]:shadow-sm",children:r("monitoring.tabs.errors")}),(0,s.jsx)(h.TabsTrigger,{value:"llmCalls",className:"px-4 py-1.5 text-sm font-medium cursor-pointer data-[state=active]:bg-white dark:data-[state=active]:bg-[#2a2a2e] data-[state=active]:shadow-sm",children:r("monitoring.tabs.modelCalls")})]}),(0,s.jsxs)("div",{className:"flex-1 overflow-y-auto min-h-0",children:[(0,s.jsxs)(h.TabsContent,{value:"messages",className:"m-0 h-full",children:[c&&(0,s.jsx)("div",{className:"py-12 flex justify-center",children:(0,s.jsx)(ea.LoadingSpinner,{text:r("monitoring.messageList.loading")})}),!c&&o&&o.messages&&o.messages.length>0&&(0,s.jsx)("div",{className:"space-y-3",children:o.messages.filter(e=>{let s=e.messageContent?.trim();return s&&"[]"!==s&&'""'!==s}).map(e=>(0,s.jsxs)("div",{className:"border border-gray-200 dark:border-gray-700 rounded-lg overflow-hidden hover:shadow-md transition-all duration-200",children:[(0,s.jsx)("div",{className:"p-4 cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800/50 transition-colors",onClick:()=>C(e.id),children:(0,s.jsxs)("div",{className:"flex items-start justify-between",children:[(0,s.jsxs)("div",{className:"flex items-start flex-1",children:[(0,s.jsx)("div",{className:"mr-2 mt-0.5",children:m===e.id?(0,s.jsx)(Y.ChevronDown,{className:"w-4 h-4 text-gray-500"}):(0,s.jsx)(X.ChevronRight,{className:"w-4 h-4 text-gray-500"})}),(0,s.jsxs)("div",{className:"flex-1",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[(0,s.jsx)("span",{className:`text-xs px-2 py-0.5 rounded ${"success"===e.status?"bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200":"error"===e.status?"bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-200":"bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-200"}`,children:e.status}),(0,s.jsx)("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:e.botName})]}),(0,s.jsx)("div",{className:"text-sm text-gray-700 dark:text-gray-300 line-clamp-2",children:(0,s.jsx)(et.MessageContentRenderer,{content:e.messageContent})})]})]}),(0,s.jsx)("span",{className:"text-xs text-gray-500 dark:text-gray-400 whitespace-nowrap ml-4",children:e.timestamp.toLocaleString()})]})}),m===e.id&&(0,s.jsxs)("div",{className:"border-t border-gray-200 dark:border-gray-700 p-4 bg-gray-50 dark:bg-gray-900",children:[u[e.id]&&(0,s.jsx)("div",{className:"flex justify-center py-8",children:(0,s.jsx)(ea.LoadingSpinner,{text:r("monitoring.messageList.loading")})}),!u[e.id]&&g[e.id]&&(0,s.jsxs)("div",{className:"space-y-4",children:[g[e.id].errors.length>0&&(0,s.jsxs)("div",{className:"bg-red-50 dark:bg-red-900/20 rounded-lg p-3",children:[(0,s.jsx)("h4",{className:"text-sm font-semibold text-red-700 dark:text-red-400 mb-2",children:r("monitoring.errors.errorMessage")}),g[e.id].errors.map(e=>(0,s.jsxs)("div",{className:"text-sm space-y-2",children:[(0,s.jsxs)("div",{className:"text-red-600 dark:text-red-400",children:[e.errorType,":"," ",e.errorMessage]}),e.stackTrace&&(0,s.jsx)("pre",{className:"text-xs text-gray-600 dark:text-gray-400 overflow-auto max-h-40 bg-white dark:bg-gray-900 p-2 rounded whitespace-pre-wrap break-words",children:e.stackTrace})]},e.id))]}),g[e.id].llmCalls.length>0&&(0,s.jsxs)("div",{className:"bg-blue-50 dark:bg-blue-900/20 rounded-lg p-3",children:[(0,s.jsxs)("h4",{className:"text-sm font-semibold text-blue-700 dark:text-blue-400 mb-2",children:[r("monitoring.tabs.modelCalls")," (",g[e.id].llmCalls.length,")"]}),(0,s.jsxs)("div",{className:"text-xs text-gray-600 dark:text-gray-400 space-y-1",children:[(0,s.jsxs)("div",{children:[r("monitoring.llmCalls.totalTokens"),":"," ",g[e.id].llmStats.totalTokens]}),(0,s.jsxs)("div",{children:[r("monitoring.llmCalls.duration"),":"," ",g[e.id].llmStats.totalDurationMs.toFixed(0),"ms"]})]})]})]})]})]},e.id))}),!c&&(!o||!o.messages||0===o.messages.length)&&(0,s.jsxs)("div",{className:"text-center text-gray-500 dark:text-gray-400 py-16",children:[(0,s.jsx)("svg",{className:"w-16 h-16 mx-auto mb-4 text-gray-300 dark:text-gray-600",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})}),(0,s.jsx)("p",{className:"text-base font-medium",children:r("monitoring.messageList.noMessages")})]})]}),(0,s.jsxs)(h.TabsContent,{value:"errors",className:"m-0 h-full",children:[c&&(0,s.jsx)("div",{className:"py-12 flex justify-center",children:(0,s.jsx)(ea.LoadingSpinner,{text:r("common.loading")})}),!c&&o&&o.errors&&o.errors.length>0&&(0,s.jsx)("div",{className:"space-y-3",children:o.errors.map(e=>(0,s.jsxs)("div",{className:"border border-red-200 dark:border-red-900 rounded-lg overflow-hidden hover:shadow-md transition-all duration-200",children:[(0,s.jsx)("div",{className:"p-4 cursor-pointer hover:bg-red-50 dark:hover:bg-red-950/50 transition-colors bg-red-50/50 dark:bg-red-950/30",onClick:()=>{var s;f===(s=e.id)?j(null):j(s)},children:(0,s.jsxs)("div",{className:"flex items-start justify-between",children:[(0,s.jsxs)("div",{className:"flex items-start flex-1",children:[(0,s.jsx)("div",{className:"mr-2 mt-0.5",children:f===e.id?(0,s.jsx)(Y.ChevronDown,{className:"w-4 h-4 text-red-500"}):(0,s.jsx)(X.ChevronRight,{className:"w-4 h-4 text-red-500"})}),(0,s.jsxs)("div",{className:"flex-1",children:[(0,s.jsx)("div",{className:"flex items-center gap-2 mb-1",children:e.messageId&&(0,s.jsxs)(N.Button,{variant:"ghost",size:"sm",className:"h-5 px-1.5 text-xs",onClick:s=>{s.stopPropagation(),k(e.messageId)},children:[(0,s.jsx)(ee.ExternalLink,{className:"w-3 h-3 mr-1"}),r("monitoring.messageList.viewConversation")]})}),(0,s.jsx)("div",{className:"font-medium text-sm text-red-700 dark:text-red-300 mb-1",children:e.errorType}),(0,s.jsx)("p",{className:"text-sm text-red-600 dark:text-red-400 line-clamp-2",children:e.errorMessage})]})]}),(0,s.jsx)("span",{className:"text-xs text-gray-500 dark:text-gray-400 whitespace-nowrap ml-4",children:e.timestamp.toLocaleString()})]})}),f===e.id&&(0,s.jsx)("div",{className:"border-t border-red-200 dark:border-red-900 p-4 bg-white dark:bg-gray-900",children:(0,s.jsxs)("div",{className:"space-y-3",children:[(0,s.jsxs)("div",{className:"bg-red-50 dark:bg-red-900/20 rounded-lg p-3",children:[(0,s.jsx)("h4",{className:"text-sm font-semibold text-red-700 dark:text-red-400 mb-2",children:r("monitoring.errors.errorMessage")}),(0,s.jsx)("div",{className:"text-sm text-red-600 dark:text-red-400 whitespace-pre-wrap break-words",children:e.errorMessage})]}),e.stackTrace&&(0,s.jsxs)("div",{className:"bg-gray-50 dark:bg-gray-800 rounded-lg p-3",children:[(0,s.jsx)("h4",{className:"text-sm font-semibold text-gray-700 dark:text-gray-300 mb-2",children:r("monitoring.errors.stackTrace")}),(0,s.jsx)("pre",{className:"text-xs text-gray-600 dark:text-gray-400 overflow-auto max-h-60 bg-white dark:bg-gray-900 p-2 rounded whitespace-pre-wrap break-words",children:e.stackTrace})]})]})})]},e.id))}),!c&&(!o||!o.errors||0===o.errors.length)&&(0,s.jsxs)("div",{className:"text-center text-gray-500 dark:text-gray-400 py-16",children:[(0,s.jsx)("svg",{className:"w-16 h-16 mx-auto mb-4 text-green-300 dark:text-green-600",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"})}),(0,s.jsx)("p",{className:"text-base font-medium text-green-600 dark:text-green-400",children:r("monitoring.errors.noErrors")})]})]}),(0,s.jsxs)(h.TabsContent,{value:"llmCalls",className:"m-0 h-full",children:[c&&(0,s.jsx)("div",{className:"py-12 flex justify-center",children:(0,s.jsx)(ea.LoadingSpinner,{text:r("common.loading")})}),!c&&o&&o.llmCalls&&o.llmCalls.length>0&&(0,s.jsx)("div",{className:"space-y-3",children:o.llmCalls.map(e=>(0,s.jsx)("div",{className:"border border-gray-200 dark:border-gray-700 rounded-lg p-4 hover:shadow-md transition-all duration-200",children:(0,s.jsxs)("div",{className:"flex items-start justify-between",children:[(0,s.jsxs)("div",{className:"flex-1",children:[(0,s.jsx)("div",{className:"flex items-center gap-2 mb-2",children:(0,s.jsx)("span",{className:`text-xs px-2 py-0.5 rounded ${"success"===e.status?"bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200":"bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-200"}`,children:e.status})}),(0,s.jsx)("div",{className:"font-medium text-sm text-gray-700 dark:text-gray-300 mb-2",children:e.modelName}),(0,s.jsx)("div",{className:"text-xs text-gray-600 dark:text-gray-400 space-y-1",children:(0,s.jsxs)("div",{className:"flex flex-wrap gap-4",children:[(0,s.jsxs)("span",{children:[r("monitoring.llmCalls.inputTokens"),":"," ",e.tokens.input]}),(0,s.jsxs)("span",{children:[r("monitoring.llmCalls.outputTokens"),":"," ",e.tokens.output]}),(0,s.jsxs)("span",{children:[r("monitoring.llmCalls.totalTokens"),":"," ",e.tokens.total]}),(0,s.jsxs)("span",{children:[r("monitoring.llmCalls.duration"),":"," ",e.duration,"ms"]}),e.cost&&(0,s.jsxs)("span",{children:[r("monitoring.llmCalls.cost"),": $",e.cost.toFixed(4)]})]})}),e.errorMessage&&(0,s.jsxs)("div",{className:"mt-2 text-xs text-red-600 dark:text-red-400",children:["Error: ",e.errorMessage]})]}),(0,s.jsx)("span",{className:"text-xs text-gray-500 dark:text-gray-400 whitespace-nowrap ml-4",children:e.timestamp.toLocaleString()})]})},e.id))}),!c&&(!o||!o.llmCalls||0===o.llmCalls.length)&&(0,s.jsxs)("div",{className:"text-center text-gray-500 dark:text-gray-400 py-16",children:[(0,s.jsx)("svg",{className:"w-16 h-16 mx-auto mb-4 text-gray-300 dark:text-gray-600",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M9.75 17L9 20l-1 1h8l-1-1-.75-3M3 13h18M5 17h14a2 2 0 002-2V5a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"})}),(0,s.jsx)("p",{className:"text-base font-medium",children:r("monitoring.llmCalls.noData")})]})]})]})]})]})}function er({open:e,onOpenChange:a,pipelineId:i,isEditMode:r=!1,onFinish:n,onNewPipelineCreated:o,onDeletePipeline:c,onCancel:d}){let{t:h}=(0,l.useTranslation)(),p=(0,m.useRouter)(),[u,b]=(0,t.useState)(i),[f,j]=(0,t.useState)("config"),[v,y]=(0,t.useState)(!1);(0,t.useEffect)(()=>{b(i),j("config")},[i,e]);let C=()=>{n()},N=e=>{b(e),j("config"),o&&o(e)},k=[{key:"config",label:h("pipelines.configuration"),icon:(0,s.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",children:(0,s.jsx)("path",{d:"M5 7C5 6.17157 5.67157 5.5 6.5 5.5C7.32843 5.5 8 6.17157 8 7C8 7.82843 7.32843 8.5 6.5 8.5C5.67157 8.5 5 7.82843 5 7ZM6.5 3.5C4.567 3.5 3 5.067 3 7C3 8.933 4.567 10.5 6.5 10.5C8.433 10.5 10 8.933 10 7C10 5.067 8.433 3.5 6.5 3.5ZM12 8H20V6H12V8ZM16 17C16 16.1716 16.6716 15.5 17.5 15.5C18.3284 15.5 19 16.1716 19 17C19 17.8284 18.3284 18.5 17.5 18.5C16.6716 18.5 16 17.8284 16 17ZM17.5 13.5C15.567 13.5 14 15.067 14 17C14 18.933 15.567 20.5 17.5 20.5C19.433 20.5 21 18.933 21 17C21 15.067 19.433 13.5 17.5 13.5ZM4 16V18H12V16H4Z"})})},{key:"extensions",label:h("pipelines.extensions.title"),icon:(0,s.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",children:(0,s.jsx)("path",{d:"M7 5C7 2.79086 8.79086 1 11 1C13.2091 1 15 2.79086 15 5H18C18.5523 5 19 5.44772 19 6V9C21.2091 9 23 10.7909 23 13C23 15.2091 21.2091 17 19 17V20C19 20.5523 18.5523 21 18 21H4C3.44772 21 3 20.5523 3 20V6C3 5.44772 3.44772 5 4 5H7ZM11 3C9.89543 3 9 3.89543 9 5C9 5.23554 9.0403 5.45952 9.11355 5.66675C9.22172 5.97282 9.17461 6.31235 8.98718 6.57739C8.79974 6.84243 8.49532 7 8.17071 7H5V19H17V15.8293C17 15.5047 17.1576 15.2003 17.4226 15.0128C17.6877 14.8254 18.0272 14.7783 18.3332 14.8865C18.5405 14.9597 18.7645 15 19 15C20.1046 15 21 14.1046 21 13C21 11.8954 20.1046 11 19 11C18.7645 11 18.5405 11.0403 18.3332 11.1135C18.0272 11.2217 17.6877 11.1746 17.4226 10.9872C17.1576 10.7997 17 10.4953 17 10.1707V7H13.8293C13.5047 7 13.2003 6.84243 13.0128 6.57739C12.8254 6.31235 12.7783 5.97282 12.8865 5.66675C12.9597 5.45952 13 5.23555 13 5C13 3.89543 12.1046 3 11 3Z"})})},{key:"debug",label:h("pipelines.debugChat"),icon:(0,s.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",children:(0,s.jsx)("path",{d:"M13 19.9C15.2822 19.4367 17 17.419 17 15V12C17 11.299 16.8564 10.6219 16.5846 10H7.41538C7.14358 10.6219 7 11.299 7 12V15C7 17.419 8.71776 19.4367 11 19.9V14H13V19.9ZM5.5358 17.6907C5.19061 16.8623 5 15.9534 5 15H2V13H5V12C5 11.3573 5.08661 10.7348 5.2488 10.1436L3.0359 8.86602L4.0359 7.13397L6.05636 8.30049C6.11995 8.19854 6.18609 8.09835 6.25469 8H17.7453C17.8139 8.09835 17.88 8.19854 17.9436 8.30049L19.9641 7.13397L20.9641 8.86602L18.7512 10.1436C18.9134 10.7348 19 11.3573 19 12V13H22V15H19C19 15.9534 18.8094 16.8623 18.4642 17.6907L20.9641 19.134L19.9641 20.866L17.4383 19.4077C16.1549 20.9893 14.1955 22 12 22C9.80453 22 7.84512 20.9893 6.56171 19.4077L4.0359 20.866L3.0359 19.134L5.5358 17.6907ZM8 6C8 3.79086 9.79086 2 12 2C14.2091 2 16 3.79086 16 6H8Z"})})},{key:"monitoring",label:h("pipelines.monitoring.title"),icon:(0,s.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",children:(0,s.jsx)("path",{d:"M2 3.9934C2 3.44476 2.45531 3 2.9918 3H21.0082C21.556 3 22 3.44495 22 3.9934V20.0066C22 20.5552 21.5447 21 21.0082 21H2.9918C2.44405 21 2 20.5551 2 20.0066V3.9934ZM4 5V19H20V5H4ZM6 7H18V9H6V7ZM6 11H18V13H6V11ZM6 15H12V17H6V15Z"})})}];return r?(0,s.jsx)(x.Dialog,{open:e,onOpenChange:a,children:(0,s.jsx)(x.DialogContent,{className:"overflow-hidden p-0 !max-w-[80vw] h-[75vh] flex",children:(0,s.jsxs)(g.SidebarProvider,{className:"items-start w-full flex h-full min-h-0",children:[(0,s.jsx)(g.Sidebar,{collapsible:"none",className:"hidden md:flex h-full min-h-0 w-40 border-r bg-white dark:bg-black",children:(0,s.jsx)(g.SidebarContent,{children:(0,s.jsx)(g.SidebarGroup,{children:(0,s.jsx)(g.SidebarGroupContent,{children:(0,s.jsx)(g.SidebarMenu,{children:k.map(e=>(0,s.jsx)(g.SidebarMenuItem,{children:(0,s.jsx)(g.SidebarMenuButton,{asChild:!0,isActive:f===e.key,onClick:()=>j(e.key),children:(0,s.jsxs)("a",{href:"#",children:[e.icon,(0,s.jsx)("span",{children:e.label})]})})},e.key))})})})})}),(0,s.jsxs)("main",{className:"flex flex-1 flex-col h-full min-h-0",children:[(0,s.jsxs)(x.DialogHeader,{className:"px-6 pt-6 pb-4 shrink-0 flex flex-row items-center justify-start",style:{height:"4rem"},children:[(0,s.jsx)(x.DialogTitle,{children:h("config"===f?r?"pipelines.editPipeline":"pipelines.createPipeline":"extensions"===f?"pipelines.extensions.title":"monitoring"===f?"pipelines.monitoring.title":"pipelines.debugDialog.title")}),"debug"===f&&(0,s.jsxs)("div",{className:"flex items-center gap-2 ml-2",children:[(0,s.jsx)("div",{className:`w-2.5 h-2.5 rounded-full ${v?"bg-green-500":"bg-red-500"}`,title:h(v?"pipelines.debugDialog.connected":"pipelines.debugDialog.disconnected")}),(0,s.jsx)("span",{className:"text-sm text-gray-600 dark:text-gray-400",children:h(v?"pipelines.debugDialog.connected":"pipelines.debugDialog.disconnected")})]})]}),(0,s.jsxs)("div",{className:"flex-1 overflow-y-auto px-6 pb-4 w-full",style:{height:"calc(100% - 4rem)"},children:["config"===f&&(0,s.jsx)(_,{onFinish:C,onNewPipelineCreated:N,isEditMode:r,pipelineId:u,disableForm:!1,showButtons:!0,onDeletePipeline:c,onCancel:()=>{d()}}),"extensions"===f&&u&&(0,s.jsx)(Q,{pipelineId:u}),"debug"===f&&u&&(0,s.jsx)(R,{open:!0,pipelineId:u,isEmbedded:!0,onConnectionStatusChange:y}),"monitoring"===f&&u&&(0,s.jsx)(ei,{pipelineId:u,onNavigateToMonitoring:()=>{p.push(`/home/monitoring?pipelineId=${u}`),a(!1)}})]})]})]})})}):(0,s.jsx)(x.Dialog,{open:e,onOpenChange:a,children:(0,s.jsx)(x.DialogContent,{className:"overflow-hidden p-0 !max-w-[40vw] max-h-[70vh] flex",children:(0,s.jsxs)("main",{className:"flex flex-1 flex-col h-[70vh]",children:[(0,s.jsx)(x.DialogHeader,{className:"px-6 pt-6 pb-4 shrink-0",children:(0,s.jsx)(x.DialogTitle,{children:h("pipelines.createPipeline")})}),(0,s.jsx)("div",{className:"flex-1 overflow-y-auto px-6 pb-6",children:(0,s.jsx)(_,{onFinish:C,onNewPipelineCreated:N,isEditMode:r,pipelineId:u,disableForm:!1,showButtons:!0,onDeletePipeline:c,onCancel:()=>{d()}})})]})})})}var en=e.i(47977);function el(){let{t:e}=(0,l.useTranslation)(),[n,m]=(0,t.useState)(!1),[x,g]=(0,t.useState)(!1),[h,p]=(0,t.useState)([]),[u,b]=(0,t.useState)(""),[f,j]=(0,t.useState)("created_at"),[v,y]=(0,t.useState)("DESC");function C(s=f,t=v){i.httpClient.getPipelines(s,t).then(s=>{let t=new Date;p(s.pipelines.map(s=>{let a=Math.floor((t.getTime()-new Date(s.updated_at??t.getTime()).getTime())/1e3/60/60/24);return new r({lastUpdatedTimeAgo:a>0?` ${a} ${e("pipelines.daysAgo")}`:e("pipelines.today"),description:s.description,id:s.uuid??"",name:s.name,emoji:s.emoji,isDefault:s.is_default??!1})}))}).catch(s=>{d.toast.error(e("pipelines.getPipelineListError")+s.message)})}return(0,t.useEffect)(()=>{let e=localStorage.getItem("pipeline_sort_by"),s=localStorage.getItem("pipeline_sort_order");e&&s?(j(e),y(s),C(e,s)):C()},[]),(0,s.jsxs)("div",{className:c.default.configPageContainer,children:[(0,s.jsx)(er,{open:n,onOpenChange:m,pipelineId:u||void 0,isEditMode:x,onFinish:()=>{C()},onNewPipelineCreated:e=>{C(),b(e),g(!0),m(!0)},onDeletePipeline:()=>{C(),m(!1)},onCancel:()=>{m(!1)}}),(0,s.jsx)("div",{className:"flex flex-row justify-between items-center mb-4 px-[0.8rem]",children:(0,s.jsxs)(en.Select,{value:`${f},${v}`,onValueChange:function(e){let[s,t]=e.split(",").map(e=>e.trim());j(s),y(t),localStorage.setItem("pipeline_sort_by",s),localStorage.setItem("pipeline_sort_order",t),C(s,t)},children:[(0,s.jsx)(en.SelectTrigger,{className:"w-[180px] cursor-pointer bg-[#ffffff] dark:bg-[#2a2a2e]",children:(0,s.jsx)(en.SelectValue,{placeholder:e("pipelines.sortBy")})}),(0,s.jsxs)(en.SelectContent,{className:"bg-[#ffffff] dark:bg-[#2a2a2e]",children:[(0,s.jsx)(en.SelectItem,{value:"created_at,DESC",className:"text-gray-900 dark:text-gray-100",children:e("pipelines.newestCreated")}),(0,s.jsx)(en.SelectItem,{value:"created_at,ASC",className:"text-gray-900 dark:text-gray-100",children:e("pipelines.earliestCreated")}),(0,s.jsx)(en.SelectItem,{value:"updated_at,DESC",className:"text-gray-900 dark:text-gray-100",children:e("pipelines.recentlyEdited")}),(0,s.jsx)(en.SelectItem,{value:"updated_at,ASC",className:"text-gray-900 dark:text-gray-100",children:e("pipelines.earliestEdited")})]})]})}),(0,s.jsxs)("div",{className:c.default.pipelineListContainer,children:[(0,s.jsx)(a.default,{width:"100%",height:"10rem",plusSize:"90px",onClick:()=>{let s=G.systemInfo.limitation?.max_pipelines??-1;s>=0&&h.length>=s?d.toast.error(e("limitation.maxPipelinesReached",{max:s})):(g(!1),b(""),m(!0))}}),h.map(e=>(0,s.jsx)("div",{onClick:()=>{b(e.id),g(!0),m(!0)},children:(0,s.jsx)(o,{cardVO:e})},e.id))]})]})}e.s(["default",()=>el],27180)}]); |