n8n-editor-ui
Version:
Workflow Editor UI for n8n
2 lines • 30.5 kB
JavaScript
!function(){try{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{}).SENTRY_RELEASE={id:"n8n@2.13.4"}}catch(e){}}(),System.register(["./vue.runtime.esm-bundler-legacy-IafOlCW8.js","./_MapCache-legacy-DwgdC8YO.js","./users.store-legacy-OKuN0qAC.js","./constants-legacy-DNCca_FT.js","./_baseOrderBy-legacy-PsQY_Pvh.js","./retry-legacy-CkrvG-jL.js","./constants-legacy-iKNx7WD2.js"],(function(e,t){var n,s,a,o,i,r,d,l,c,u,m,g,f,p,v,h,I,w,y,b,M,A,S,x,T,C,O,k,E,D,$,P,_,N,F,U,L,H,R,W,j,G,Z,B,z,q,Y,J,X,K;function Q(e,t){const n=new Date(t),s=new Date(e.getFullYear(),e.getMonth(),e.getDate()),a=new Date(s);a.setDate(a.getDate()-1);const o=new Date(s);o.setDate(o.getDate()-7);const i=new Date(n.getFullYear(),n.getMonth(),n.getDate());return i.getTime()===s.getTime()?"Today":i.getTime()===a.getTime()?"Yesterday":i>=o?"This week":"Older"}function V(e){return{provider:e.provider,model:"n8n"===e?.provider||"custom-agent"===e?.provider?null:e?.model??null,workflowId:"n8n"===e?.provider?e.workflowId:null,agentId:"custom-agent"===e?.provider?e.agentId:null}}function ee(e){if(null===e.provider)return null;switch(e.provider){case"custom-agent":return e.agentId?{provider:"custom-agent",agentId:e.agentId}:null;case"n8n":return e.workflowId?{provider:"n8n",workflowId:e.workflowId}:null;default:return null===e.model?null:{provider:e.provider,model:e.model}}}function te(e,t,n){return{id:t,sessionId:e,type:"ai",name:"AI",content:[],executionId:n?.executionId??null,status:"running",createdAt:(new Date).toISOString(),updatedAt:(new Date).toISOString(),previousMessageId:n?.previousMessageId??null,retryOfMessageId:n?.retryOfMessageId??null,revisionOfMessageId:null,responses:[],alternatives:[],attachments:[],...n?.agent?V(n.agent.model):{provider:null,model:null,workflowId:null,agentId:null}}}function ne(e){return"n8n"!==e&&"custom-agent"!==e}function se({enabled:e=!0,allowedModels:t},n){return e&&(0===t.length||t.some((e=>"model"in n&&e.model===n.model)))}function ae(e,t){return{model:e,name:t?.name||"",description:null,icon:t?.icon??null,createdAt:null,updatedAt:null,metadata:{allowFileUploads:!1,allowedFilesMimeTypes:"",capabilities:{functionCalling:"n8n"!==e.provider},available:!0},groupName:null,groupIcon:null}}async function oe(e){const t=new FileReader;return await new Promise(((n,s)=>{t.onload=()=>{n({data:t.result.split("base64,")?.[1]??"",mimeType:e.type,fileName:e.name,fileSize:`${e.size} bytes`,fileExtension:e.name.split(".").pop()??"",fileType:e.type.split("/")[0]})},t.onerror=()=>{s(new Error("Failed to convert file to binary data"))},t.readAsDataURL(e)}))}function ie(e,t){const n=[...e];let s=t;if(n.length>0){const e=n[n.length-1];"hidden"===e.type?(s=e.content+t,n.pop()):"artifact-create"!==e.type&&"artifact-edit"!==e.type||!e.isIncomplete||(s=e.content+t,n.pop())}const a=function(e){if(!e.startsWith("{"))return null;try{const t=JSON.parse(e),n=I.safeParse(t);if(n.success)return{type:"with-buttons",content:n.data.text,buttons:n.data.buttons,blockUserInput:n.data.blockUserInput}}catch{}return null}(s);if(a)return n.push(a),n;let o=0;const i=/<command:artifact-create>/g,r=/<command:artifact-edit>/g;for(;o<s.length;){i.lastIndex=o,r.lastIndex=o;const e=i.exec(s),t=r.exec(s);let a=null,d=null;if(e&&t?e.index<t.index?(a=e,d="create"):(a=t,d="edit"):e?(a=e,d="create"):t&&(a=t,d="edit"),!a||!d){const e=s.slice(o);if(e){const{text:t,hiddenPrefix:s}=de(e);t&&re(n,t),s&&n.push({type:"hidden",content:s})}break}a.index>o&&re(n,s.slice(o,a.index));const l=a.index,c=s.slice(l);if("create"===d){const e=le(c);n.push(e.item),o=l+e.consumed}else{const e=ce(c);n.push(e.item),o=l+e.consumed}}return n}function re(e,t){if(""!==t){if(e.length>0){const n=e[e.length-1];if("text"===n.type)return void(e[e.length-1]={type:"text",content:n.content+t})}e.push({type:"text",content:t})}}function de(e){const t=["<command:artifact-create>","<command:artifact-edit>"];for(let n=1;n<=Math.min(e.length,30);n++){const s=e.slice(-n);for(const a of t)if(a.startsWith(s))return{text:e.slice(0,-n),hiddenPrefix:s}}return{text:e,hiddenPrefix:""}}function le(e){const t=e.indexOf("</command:artifact-create>"),n=-1===t,s=n?e:e.slice(0,t+26);return{item:{type:"artifact-create",content:s,command:{title:ue(s,"title")??"",type:ue(s,"type")??"",content:ue(s,"content")??""},isIncomplete:n},consumed:s.length}}function ce(e){const t=e.indexOf("</command:artifact-edit>"),n=-1===t,s=n?e:e.slice(0,t+24);return{item:{type:"artifact-edit",content:s,command:{title:ue(s,"title")??"",oldString:ue(s,"oldString")??"",newString:ue(s,"newString")??"",replaceAll:"true"===(ue(s,"replaceAll")??"false").toLowerCase()},isIncomplete:n},consumed:s.length}}function ue(e,t){const n=`<${t}>`,s=`</${t}>`,a=e.indexOf(n);if(-1===a)return null;const o=a+n.length,i=e.indexOf(s,o);if(-1===i){let t=e.slice(o);for(let e=1;e<s.length;e++){const n=s.slice(0,e);if(t.endsWith(n)){t=t.slice(0,-e);break}}return t.length>0?t:null}return e.slice(o,i)}return e({O:async function(e,t){return await x(e,"GET",`/workflows/${t}/execution-status?authSource=cookie`)},S:ee,T:function(e,t,n,s){return`${e.baseUrl}/chat/conversations/${t}/messages/${n}/attachments/${s}`},a:ae,b:function(e){if(!e)return[];const t=[];let n="",s={type:"normal"};const a=e.split("\n"),o=()=>{n.trim()&&(t.push(n.trimEnd()),n="")};for(let i=0;i<a.length;i++){const e=a[i],t=i<a.length-1?a[i+1]:"",r=e.trim(),d=/^( {4}|\t)/.test(e),l=/^( {0,3})(`{3,}|~{3,})/.test(e);if("backtick-fence"===s.type){if(l&&r.startsWith("```")){const t=r.match(/^(`+)/);if((t?t[1].length:0)>=s.count){n+=e+"\n",s={type:"normal"},o();continue}}}else if("tilde-fence"===s.type){if(l&&r.startsWith("~~~")){const t=r.match(/^(~+)/);if((t?t[1].length:0)>=s.count){n+=e+"\n",s={type:"normal"},o();continue}}}else if("indented"===s.type)d||""===r||(s={type:"normal"},o());else if(l&&r.startsWith("```")){const e=r.match(/^(`+)/);s={type:"backtick-fence",count:e?e[1].length:0}}else if(l&&r.startsWith("~~~")){const e=r.match(/^(~+)/);s={type:"tilde-fence",count:e?e[1].length:0}}else d&&""!==r&&(o(),s={type:"indented"});if(n+=e+"\n","normal"===s.type){const e=""===r,n=""===t.trim(),s=t.trim().startsWith("#");(e&&n||e&&s)&&o()}}return o(),t},c:function(e,t){for(const n of v.options){let s,a=-1/0;const o=ne(n)?t[n]:void 0,i=e[n].models.filter((e=>!o||se(o,e.model)));for(const e of i){const t=e.metadata.priority??0;t>a&&(a=t,s=e)}if(s)return s}},d:function(e){return"n8n"===e.provider?{name:k,query:{workflowId:e.workflowId}}:"custom-agent"===e.provider?{name:k,query:{agentId:e.agentId}}:{name:k,query:{provider:e.provider,model:e.model}}},f:function(e){const t=new Date,n=new Map;for(const s of e){const e=Q(t,s.lastMessageAt??s.updatedAt);n.has(e)||n.set(e,[]),n.get(e).push(s)}return["Today","Yesterday","This week","Older"].flatMap((e=>{const t=n.get(e)??[];return t.length>0?[{group:e,sessions:t.sort(((e,t)=>Date.parse(t.lastMessageAt??t.updatedAt)-Date.parse(e.lastMessageAt??e.updatedAt)))}]:[]}))},g:function(e){return ne(e?.provider)},h:ne,i:function(e){const t=[];for(const n of e)if("artifact-create"===n.type){if(!n.command.title)continue;t.push({title:n.command.title,type:n.command.type,content:n.command.content})}else if("artifact-edit"===n.type){const e=t.find((e=>e.title===n.command.title));e&&(n.command.replaceAll?e.content=e.content.split(n.command.oldString).join(n.command.newString):e.content=e.content.replace(n.command.oldString,n.command.newString))}return t},k:async function(e,t,n){await x(e,"DELETE",`/credentials/${t}/revoke?resolverId=${encodeURIComponent(n)}&authSource=cookie`)},l:V,o:function(e){return e&&(e.includes("text/*")||e.includes("text/markdown"))?`${e},.md`:e},p:se,s:function(e,t){let n=e;if(t.search.trim()){const e=t.search.toLowerCase();n=n.filter((t=>t.name.toLowerCase().includes(e)))}return n=[...n].sort(((e,n)=>{const s=e[t.sortBy],a=n[t.sortBy],o=s?Date.parse(s):void 0,i=a?Date.parse(a):void 0;return o&&i?i-o:o&&!i?-1:!o&&i?1:0})),n},u:function(e){const[t,n]=e.split("::"),s=v.safeParse(t).data;if(s)return"n8n"===s?{provider:"n8n",workflowId:n}:"custom-agent"===s?{provider:"custom-agent",agentId:n}:{provider:s,model:n}},v:function(e){return!(!e||"waiting"!==e.status)&&e.content.some((e=>"with-buttons"===e.type&&e.blockUserInput))},w:async function(e,t,n){return await x(e,"POST",`/credentials/${t}/authorize?resolverId=${encodeURIComponent(n)}&authSource=cookie`)},x:function(e){return`${e.provider}::${"custom-agent"===e.provider?e.agentId:"n8n"===e.provider?e.workflowId:e.model}`}}),{setters:[function(e){n=e.Ft,s=e.S},function(e){a=e.bt},function(e){o=e.As,i=e.Tr,r=e.at,d=e.en,l=e.s},function(e){c=e.Gt,u=e.N,m=e.Uo,g=e.Xa,f=e._i,p=e.gi,v=e.hi,h=e.li,I=e.mi,w=e.pi,y=e.pl,b=e.sa,M=e.ui},function(e){A=e.a,S=e.c,x=e.d,T=e.j,C=e.r},function(e){O=e.t},function(e){k=e.l,e.s}],execute:function(){try{t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},(v=(new t.Error).stack)&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[v]="3240983d-233d-4a6a-a93e-771890b0b660",t._sentryDebugIdIdentifier="sentry-dbid-3240983d-233d-4a6a-a93e-771890b0b660")}catch(t){}var t,v;e("D",E=async(e,t)=>await x(e,"POST","/chat/models",t)),D=async(e,t,n)=>{await x(e,"POST",`/chat/conversations/${t}/messages/${n}/stop`)},$=async(e,t,n,s)=>{const a=new URLSearchParams;return a.append("limit",t.toString()),n&&a.append("cursor",n),s&&a.append("type",s),await x(e,"GET",`/chat/conversations?${a.toString()}`)},P=async(e,t,n)=>await x(e,"PATCH",`/chat/conversations/${t}`,n),_=async(e,t,n)=>await P(e,t,{title:n}),N=async(e,t)=>{await x(e,"DELETE",`/chat/conversations/${t}`)},F=async(e,t)=>await x(e,"GET",`/chat/conversations/${t}`),e("E",U=async(e,t)=>await x(e,"GET",`/chat/agents/${t}`)),L=async(e,t)=>await x(e,"POST","/chat/agents",t),H=async(e,t,n)=>await x(e,"POST",`/chat/agents/${t}`,n),R=async(e,t)=>{await x(e,"DELETE",`/chat/agents/${t}`)},W=async(e,t,n)=>{const s=new FormData;for(const a of n)s.append("files",a);return await x(e,"POST",`/chat/agents/${t}/files`,s)},j=async(e,t,n)=>{await x(e,"DELETE",`/chat/agents/${t}/files/${encodeURIComponent(n)}`)},G=async e=>(await x(e,"GET","/chat/settings")).providers,Z=async(e,t)=>(await x(e,"GET","/chat/settings/"+t)).settings,B=async(e,t)=>await x(e,"POST","/chat/settings",{payload:t}),e("A",(async(e,t)=>{await x(e,"PUT","/chat/semantic-search",t)})),z=async e=>await x(e,"GET","/chat/tools"),q=async(e,t)=>await x(e,"POST","/chat/tools",{definition:t}),Y=async(e,t,n)=>await x(e,"PATCH",`/chat/tools/${t}`,n),J=async(e,t)=>{await x(e,"DELETE",`/chat/tools/${t}`)},e("y",{type:"icon",value:"message-square"}),e("C",{type:"icon",value:"bot"}),e("m",(e=>"success"===e.status&&"ai"!==e.type)),e("_",(e=>"ai"===e.type)),e("r",X={openai:{name:"@n8n/n8n-nodes-langchain.embeddingsOpenAi",version:1.2},google:{name:"@n8n/n8n-nodes-langchain.embeddingsGoogleGemini",version:1},azureOpenAi:{name:"@n8n/n8n-nodes-langchain.embeddingsAzureOpenAi",version:1},azureEntraId:{name:"@n8n/n8n-nodes-langchain.embeddingsAzureOpenAi",version:1},ollama:{name:"@n8n/n8n-nodes-langchain.embeddingsOllama",version:1},awsBedrock:{name:"@n8n/n8n-nodes-langchain.embeddingsAwsBedrock",version:1},cohere:{name:"@n8n/n8n-nodes-langchain.embeddingsCohere",version:1},mistralCloud:{name:"@n8n/n8n-nodes-langchain.embeddingsMistralCloud",version:1}}),e("n",K={embeddingModel:{credentialId:null,provider:w.options.filter((e=>e in X))[0]},vectorStore:{credentialId:null,provider:p.options[0]}}),e("t",T(A.CHAT_HUB,(()=>{const e=C(),p=o(),v=r(),I=i(),w=d(),A=a(),T=n(null);let k=null;const X=n({}),Q=n({byId:{},ids:null,hasMore:!1,nextCursor:null,lastFetchedType:void 0}),ne=n(!1),se=n(),re=n(!1),de=n(null),le=n([]),ce=n(!1),ue=n(new Map),me=e=>ue.value.get(e);function ge(e){ue.value.has(e)||ue.value.set(e,{messages:{},activeMessageChain:[]});const t=ue.value.get(e);if(!t)throw new Error(`Conversation for session ID ${e} not found`);return t}function fe(e){const t=me(e);if(!t||0===t.activeMessageChain.length)return null;const n=t.activeMessageChain[t.activeMessageChain.length-1];return t.messages[n]??null}function pe(e,t){const n=[];if(!t)return n;let s=t;for(;;){const t=e[s].responses;if(0===t.length)break;s=t[t.length-1]}let a=s;const o=new Set;for(;a&&!o.has(a);)n.unshift(a),o.add(a),a=e[a]?.previousMessageId??null;return n}function ve(e){const t={};for(const s of e)t[s.id]={...s,responses:[],alternatives:[]};for(const s of Object.values(t))s.previousMessageId&&t[s.previousMessageId]&&t[s.previousMessageId].responses.push(s.id),s.retryOfMessageId&&t[s.retryOfMessageId]&&t[s.retryOfMessageId].alternatives.push(s.id),s.revisionOfMessageId&&t[s.revisionOfMessageId]&&t[s.revisionOfMessageId].alternatives.push(s.id);const n=(e,n)=>{const s=t[e],a=t[n];return s.createdAt!==a.createdAt?s.createdAt<a.createdAt?-1:1:s.id<a.id?-1:1};for(const s of Object.values(t)){if(s.alternatives.includes(s.id)||s.alternatives.push(s.id),s.retryOfMessageId&&t[s.retryOfMessageId]){s.alternatives.push(s.retryOfMessageId);for(const e of t[s.retryOfMessageId].alternatives)e===s.id||s.alternatives.includes(e)||s.alternatives.push(e)}if(s.revisionOfMessageId&&t[s.revisionOfMessageId]){s.alternatives.push(s.revisionOfMessageId);for(const e of t[s.revisionOfMessageId].alternatives)e===s.id||s.alternatives.includes(e)||s.alternatives.push(e)}s.responses.sort(n),s.alternatives.sort(n)}return t}function he(e,t){const n=ge(e);return n.messages[t.id]=t,n.messages=ve(Object.values(n.messages)),n.activeMessageChain=pe(n.messages,t.id),t}function Ie(e,t,n){const s=ge(e).messages[t];if(!s)throw new Error(`Message with ID ${t} not found in session ${e}`);s.content=ie(s.content,n)}function we(e,t,n,s){const a=ge(e).messages[t];if(!a)throw new Error(`Message with ID ${t} not found in session ${e}`);a.status=n,s&&(a.content=s),a.updatedAt=(new Date).toISOString()}async function ye(t,n={}){return k??=E(e.restApiContext,{credentials:t}).finally((()=>{k=null})),[T.value]=await Promise.all([k,new Promise((e=>setTimeout(e,n.minLoadingTime??0)))]),T.value}async function be(t,n={}){if(!ne.value&&(void 0!==n.type&&n.type!==Q.value.lastFetchedType&&(t=!0),t||!Q.value||Q.value.hasMore||!((Q.value.ids??[]).length>0))){t||(ne.value=!0);try{const s=t?void 0:Q.value?.nextCursor??void 0,[a]=await Promise.all([$(e.restApiContext,18,s,n.type),new Promise((e=>setTimeout(e,n.minLoadingTime??0)))]);(t||null===Q.value.ids)&&(Q.value.ids=[]),Q.value.hasMore=a.hasMore,Q.value.nextCursor=a.nextCursor,Q.value.lastFetchedType=n.type;for(const e of a.data){Q.value.ids.push(e.id);const t=Q.value.byId[e.id];Q.value.byId[e.id]={...e,toolIds:t?.toolIds??e.toolIds}}}finally{ne.value=!1}}}async function Me(n){const s=Q.value.byId[n];"manual"!==s?.type&&(s&&"New Chat"!==s.title||await O((async()=>{try{return"New Chat"!==(await F(e.restApiContext,n)).session.title}catch(t){return!1}}),2e3,10),await be(!0))}function Ae(e,t){const n=ge(e).messages[t];return n||he(e,te(e,t,se.value))}async function Se(e){if(!se.value)return;const t=e instanceof S?new Error(function(e,t){const n={413:A.baseText("chatHub.error.payloadTooLarge"),400:t??A.baseText("chatHub.error.badRequest"),403:A.baseText("chatHub.error.forbidden"),500:t?A.baseText("chatHub.error.serverErrorWithReason",{interpolate:{error:t}}):A.baseText("chatHub.error.serverError")};return e&&n[e]||t||A.baseText("chatHub.error.unknown")}(e.httpStatusCode,e.message)):e instanceof Error&&e.message.includes("Failed to fetch")?new Error(A.baseText("chatHub.error.noConnection")):e;I.showError(t,A.baseText("chatHub.error.sendMessageFailed"));const{sessionId:n}=se.value;se.value=void 0,await Me(n)}function xe(e){if("n8n"!==e.provider)return!1;const t=l();if(t.workflowId!==e.workflowId)return!1;const n=t.allNodes.find((e=>e.type===c));return!!n&&!0===n.parameters?.availableInChat}function Te(){const e=l();e.workflowExecutionData={id:u,finished:!1,mode:"manual",status:"running",createdAt:new Date,startedAt:new Date,stoppedAt:void 0,workflowId:e.workflowId,data:b({resultData:{runData:{}}}),workflowData:e.workflow},e.private.setActiveExecutionId(null)}function Ce(e,t){const n=Q.value.byId[e];n&&(Q.value.byId[e]={...n,...t})}async function Oe(t,n){const s=function(e,t){const n=[];let s=[],a=0;for(const o of e)a+o.size>t&&s.length>0&&(n.push(s),s=[],a=0),s.push(o),a+=o.size;return s.length>0&&n.push(s),n}(n,1024*(p.moduleSettings["chat-hub"]?.agentUploadMaxSizeMb??20)*1024);let a;for(const o of s)a=await W(e.restApiContext,t,o);return a}function ke(e,t){const n=T.value?.[e.provider]?.models.find((t=>function(e,t){return"n8n"===t.provider?"n8n"===e.model.provider&&e.model.workflowId===t.workflowId:"custom-agent"===t.provider?"custom-agent"===e.model.provider&&e.model.agentId===t.agentId:e.model.provider===t.provider&&e.model.model===t.model}(t,e)));return n||ae(e,t)}const Ee=s((()=>{const e=p.isEnterpriseFeatureEnabled[y.Sharing],t=p.moduleSettings["chat-hub"]?.semanticSearch??K,n=t?.vectorStore.credentialId??"",s=v.getCredentialById(n);return n?s&&s?.type===M[t.vectorStore.provider]?e&&!s.isGlobal?"notShared":void 0:"notFound":"unspecified"})),De=s((()=>{const e=p.isEnterpriseFeatureEnabled[y.Sharing],t=p.moduleSettings["chat-hub"]?.semanticSearch??K,n=t?.embeddingModel.credentialId??"",s=v.getCredentialById(n);return n?s&&s?.type===h[t.embeddingModel.provider]?e&&!s.isGlobal?"notShared":void 0:"notFound":"unspecified"})),$e=s((()=>({isReadyForCurrentUser:!(Ee.value&&"notShared"!==Ee.value||De.value&&"notShared"!==De.value),vectorStoreIssue:Ee.value,embeddingIssue:De.value})));return{agents:s((()=>T.value??f)),agentsReady:s((()=>null!==T.value)),customAgents:X,getAgent:ke,fetchAgents:ye,getCustomAgent:function(e){return T.value?.["custom-agent"].models.find((t=>"agentId"in t&&t.agentId===e))},fetchCustomAgent:async function(t){const n=await U(e.restApiContext,t);X.value[t]=n},createCustomAgent:async function(t,n,s){let a=await L(e.restApiContext,t);n.length>0&&(a=await Oe(a.id,n));const o=T.value?.[a.provider]?.models.find((e=>e.name===a.model)),i=a.suggestedPrompts.filter((e=>e.text.trim().length>0)),r={model:{provider:"custom-agent",agentId:a.id},name:a.name,description:a.description??null,icon:a.icon,createdAt:a.createdAt,updatedAt:a.updatedAt,metadata:o?.metadata??{capabilities:{functionCalling:!1},allowFileUploads:!1,allowedFilesMimeTypes:"",available:!0},groupName:null,groupIcon:null,...i.length>0?{suggestedPrompts:i}:{}};return T.value?.["custom-agent"].models.push(r),X.value[a.id]=a,await ye(s),w.track("User created agent",{...V(t)}),r},updateCustomAgent:async function(t,n,s,a,o){await H(e.restApiContext,t,n);for(const r of a)await j(e.restApiContext,t,r);s.length>0&&await Oe(t,s);const i=await U(e.restApiContext,t);if(T.value?.["custom-agent"]){const e=i.suggestedPrompts.filter((e=>e.text.trim().length>0));T.value["custom-agent"].models=T.value["custom-agent"].models.map((n=>"agentId"in n&&n.agentId===t?{...n,name:i.name,...e.length>0?{suggestedPrompts:e}:{suggestedPrompts:void 0}}:n))}return X.value[t]=i,await ye(o),i},deleteCustomAgent:async function(t,n){await R(e.restApiContext,t),T.value?.["custom-agent"]&&(T.value["custom-agent"].models=T.value["custom-agent"].models.filter((e=>!("agentId"in e)||e.agentId!==t))),delete X.value[t],await ye(n)},configuredTools:le,configuredToolsLoaded:ce,fetchConfiguredTools:async function(){const t=await z(e.restApiContext);return le.value=t,ce.value=!0,t},addConfiguredTool:async function(t){const n=await q(e.restApiContext,t);return le.value=[...le.value,n],n},updateConfiguredTool:async function(t,n){const s=await Y(e.restApiContext,t,{definition:n});return le.value=le.value.map((e=>e.definition.id===t?s:e)),s},toggleToolEnabled:async function(t,n){const s=await Y(e.restApiContext,t,{enabled:n});return le.value=le.value.map((e=>e.definition.id===t?s:e)),s},removeConfiguredTool:async function(t){await J(e.restApiContext,t),le.value=le.value.filter((e=>e.definition.id!==t))},sessions:Q,sessionsReady:s((()=>null!==Q.value.ids)),sessionsLoading:s((()=>ne.value)),fetchSessions:be,fetchMoreSessions:async function(e={}){Q.value?.hasMore&&!ne.value&&await be(!1,e)},renameSession:async function(t,n){Ce(t,(await _(e.restApiContext,t,n)).session)},updateSessionModel:async function(t,n,s){Ce(t,(await P(e.restApiContext,t,{agent:{model:n,name:s}})).session)},deleteSession:async function(t){await N(e.restApiContext,t),delete Q.value.byId[t],Q.value.ids=Q.value.ids?.filter((e=>e!==t))??null},toggleSessionTool:async function(t,n){const s=Q.value?.byId[t];if(!s)throw new Error(`Session with ID ${t} not found`);const a=s.toolIds??[],o=a.includes(n)?a.filter((e=>e!==n)):[...a,n];Ce(t,(await P(e.restApiContext,t,{toolIds:o})).session)},toggleCustomAgentTool:async function(t,n){const s=X.value[t];if(!s)throw new Error(`Custom agent with ID ${t} not found`);const a=s.toolIds??[],o=a.includes(n)?a.filter((e=>e!==n)):[...a,n];X.value[t]={...s,toolIds:o},await H(e.restApiContext,t,{toolIds:o})},conversationsBySession:ue,getConversation:me,fetchMessages:async function(t){const{conversation:n,session:s}=await F(e.restApiContext,t),a=ve(Object.values(n.messages)),o=pe(a,Object.values(a).sort(((e,t)=>e.createdAt<t.createdAt?-1:1)).pop()?.id??null);ue.value.set(t,{messages:a,activeMessageChain:o}),Q.value.byId[t]=s},getActiveMessages:e=>{const t=me(e);return t?function(e,t,n){const s=[];let a=!1;for(let o=0;o<t.activeMessageChain.length;o++){const i=t.activeMessageChain[o],r=t.messages[i];r&&(a=a||"running"===r.status,a||n?.sessionId!==e||"ai"!==r.type?s.push(r):n.retryOfMessageId!==i||n.messageId?n.messageId&&o===t.activeMessageChain.length-1?(s.push({...r,status:"running"}),a=!0):s.push(r):(s.push({...r,content:[],status:"running",...V(n.agent.model)}),a=!0))}return s}(e,t,se.value):[]},switchAlternative:function(e,t){const n=me(e);if(!n?.messages[t])throw new Error(`Message with ID ${t} not found in session ${e}`);n.activeMessageChain=pe(n.messages,t)},lastMessage:fe,streaming:se,isResponding:function(e){return se.value?.sessionId===e},sendMessage:async function(t,n,s,a,o=[]){const i=m(),r=ge(t),d=r.activeMessageChain.length?r.activeMessageChain[r.activeMessageChain.length-1]:null,l=(await Promise.all(o.map(oe))).map((e=>({fileName:e.fileName??"unnamed file",mimeType:e.mimeType,data:e.data})));se.value={promptPreviousMessageId:d,promptId:i,promptText:n,sessionId:t,retryOfMessageId:null,revisionOfMessageId:null,attachments:l,agent:s};const c=xe(s.model),u=c?"manual":"production",g=c?"canvas":"chat_hub";w.track("User sent chat hub message",{...V(s.model),is_custom:"custom-agent"===s.model.provider,chat_session_id:t,mode:u,source:g});const f={model:s.model,messageId:i,sessionId:t,message:n,credentials:a,previousMessageId:d,attachments:l,agentName:s.name,timeZone:Intl.DateTimeFormat().resolvedOptions().timeZone};try{if(Q.value.byId[t]||(Q.value.byId[t]=function(e,t,n=!1){return{id:e.sessionId,title:"New Chat",ownerId:"",lastMessageAt:(new Date).toISOString(),credentialId:null,agentName:e.agent.name,agentIcon:e.agent.icon,type:n?"manual":"production",createdAt:(new Date).toISOString(),updatedAt:(new Date).toISOString(),toolIds:t,...V(e.agent.model)}}(se.value,le.value.filter((e=>e.enabled)).map((e=>e.definition.id)),c),Q.value.ids??=[],Q.value.ids.unshift(t)),c){Te();const{workflowId:a}=s.model;await async function(e,t,n){return await x(e,"POST",`/chat/conversations/manual/${t}/send`,n)}(e.restApiContext,a,{messageId:i,sessionId:t,message:n,previousMessageId:d,attachments:l,agentName:s.name,timeZone:f.timeZone})}else await async function(e,t){return await x(e,"POST","/chat/conversations/send",t)}(e.restApiContext,f)}catch(p){await Se(p)}},editMessage:async function(t,n,s,a,o,i=[],r=[]){const d=m(),l=ge(t).messages[n],c=l?.previousMessageId??null,u=await Promise.all(r.map(oe)),g={model:a.model,messageId:d,message:s,credentials:o,newAttachments:u.map((e=>({fileName:e.fileName??"unnamed file",mimeType:e.mimeType,data:e.data}))),keepAttachmentIndices:i,timeZone:Intl.DateTimeFormat().resolvedOptions().timeZone};"ai"===l?.type&&function(e,t,n){const s=ge(e).messages[t];if(!s)throw new Error(`Message with ID ${t} not found in session ${e}`);s.content=[{type:"text",content:n}]}(t,n,s),se.value={promptPreviousMessageId:c,promptId:d,promptText:s,sessionId:t,agent:a,retryOfMessageId:null,revisionOfMessageId:n,attachments:[...i.flatMap((e=>{const t=l?.attachments[e];return t?[{fileName:t.fileName??"unnamed file",mimeType:t.mimeType??"application/octet-stream",data:""}]:[]})),...u]};const f=xe(a.model),p=f?"manual":"production",v=f?"canvas":"chat_hub";w.track("User edited chat hub message",{...V(a.model),is_custom:"custom-agent"===a.model.provider,chat_session_id:t,chat_message_id:n,mode:p,source:v});try{f?(Te(),await async function(e,t){return await x(e,"POST",`/chat/conversations/manual/${t.workflowId}/${t.sessionId}/messages/${t.editId}/edit`,t.payload)}(e.restApiContext,{workflowId:a.model.workflowId,sessionId:t,editId:n,payload:{messageId:g.messageId,message:g.message,newAttachments:g.newAttachments,keepAttachmentIndices:g.keepAttachmentIndices,timeZone:g.timeZone}})):await async function(e,t){return await x(e,"POST",`/chat/conversations/${t.sessionId}/messages/${t.editId}/edit`,t.payload)}(e.restApiContext,{sessionId:t,editId:n,payload:g})}catch(h){await Se(h)}},regenerateMessage:async function(t,n,s,a){const o=ge(t).messages[n]?.previousMessageId??null,i={model:s.model,credentials:a,timeZone:Intl.DateTimeFormat().resolvedOptions().timeZone};if(!o)throw new Error("No previous message to base regeneration on");se.value={promptPreviousMessageId:o,promptId:n,promptText:"",sessionId:t,agent:s,retryOfMessageId:n,revisionOfMessageId:null,attachments:[]};const r=xe(s.model),d=r?"manual":"production",l=r?"canvas":"chat_hub";w.track("User regenerated chat hub message",{...V(s.model),is_custom:"custom-agent"===s.model.provider,chat_session_id:t,chat_message_id:n,mode:d,source:l});try{r?(Te(),await async function(e,t){return await x(e,"POST",`/chat/conversations/manual/${t.workflowId}/${t.sessionId}/messages/${t.retryId}/regenerate`,t.payload)}(e.restApiContext,{workflowId:s.model.workflowId,sessionId:t,retryId:n,payload:{timeZone:i.timeZone}})):await async function(e,t){return await x(e,"POST",`/chat/conversations/${t.sessionId}/messages/${t.retryId}/regenerate`,t.payload)}(e.restApiContext,{sessionId:t,retryId:n,payload:i})}catch(c){await Se(c)}},stopStreamingMessage:async function(t){const n=fe(t);n&&"running"===n.status&&(we(t,n.id,"cancelled"),await D(e.restApiContext,t,n.id),se.value?.sessionId===t&&(se.value=void 0,await Me(t)))},settings:de,settingsLoading:re,fetchAllChatSettings:async function(){try{re.value=!0,de.value=await G(e.restApiContext)}finally{re.value=!1}return de.value},fetchProviderSettings:async function(t){const n=await Z(e.restApiContext,t);return de.value&&(de.value[t]=g(n)),n},updateProviderSettings:async function(t){t.enabled||(t.allowedModels=[]);const n=await B(e.restApiContext,t);return de.value&&(de.value[t.provider]=g(n)),n},semanticSearchReadiness:$e,handleWebSocketExecutionBegin:function(e){const{sessionId:t}=e;if(se.value?.sessionId===t)return;const n=Q.value.byId[t];if(!n)return;const s=ee(n);s&&(se.value={promptPreviousMessageId:null,promptId:"",promptText:"",sessionId:t,retryOfMessageId:null,revisionOfMessageId:null,attachments:[],agent:ke(s,{name:n.agentName,icon:n.agentIcon})})},handleWebSocketExecutionEnd:function(e){const{sessionId:t,status:n}=e;if(se.value?.sessionId===t){const e=se.value.sessionId;if(se.value.messageId){const e=me(t)?.messages[se.value.messageId];e&&"running"===e.status&&we(t,se.value.messageId,n)}se.value=void 0,"error"===n&&I.showError(new Error("Execution failed"),A.baseText("chatHub.error.unknown")),Me(e)}},handleWebSocketStreamBegin:function(e){const{sessionId:t,messageId:n,previousMessageId:s,retryOfMessageId:a}=e;se.value?.sessionId===t&&(se.value.messageId=n,se.value.promptPreviousMessageId=s,se.value.retryOfMessageId=a);const o=me(t);if(o?.messages[n])return;s&&"waiting"===o?.messages[s]?.status&&we(t,s,"success");const i=te(t,n,se.value?.sessionId===t?se.value:void 0);i.previousMessageId=s,i.retryOfMessageId=a,he(t,i)},handleWebSocketStreamChunk:function(e){const{sessionId:t,messageId:n,content:s}=e;me(t)?.messages[n]||Ae(t,n),Ie(t,n,s)},handleWebSocketStreamEnd:function(e){const{sessionId:t,messageId:n,status:s}=e;we(t,n,s)},handleWebSocketStreamError:function(e){const{sessionId:t,messageId:n,error:s}=e,a=Ae(t,n);a.content?a.content=ie(a.content,"\n\n"+s):a.content=[{type:"text",content:s}],a.status="error",we(t,n,"error",a.content)},handleHumanMessageCreated:function(e){const t=ue.value.get(e.sessionId);if(!t)return;if(t.messages[e.messageId])return;const n={id:e.messageId,sessionId:e.sessionId,type:"human",name:"User",content:[{type:"text",content:e.content}],previousMessageId:e.previousMessageId,retryOfMessageId:null,revisionOfMessageId:null,status:"success",attachments:e.attachments.map((e=>({fileName:e.fileName,mimeType:e.mimeType}))),provider:null,model:null,workflowId:null,agentId:null,executionId:null,createdAt:new Date(e.timestamp).toISOString(),updatedAt:new Date(e.timestamp).toISOString(),responses:[],alternatives:[]};he(e.sessionId,n)},handleMessageEdited:function(e){const t=ue.value.get(e.sessionId);if(!t)return;if(t.messages[e.messageId])return;const n=t.messages[e.revisionOfMessageId],s={id:e.messageId,sessionId:e.sessionId,type:"human",name:n?.name??"User",content:[{type:"text",content:e.content}],previousMessageId:n?.previousMessageId??null,retryOfMessageId:null,revisionOfMessageId:e.revisionOfMessageId,status:"success",attachments:e.attachments.map((e=>({fileName:e.fileName,mimeType:e.mimeType}))),provider:n?.provider??null,model:n?.model??null,workflowId:n?.workflowId??null,agentId:n?.agentId??null,executionId:null,createdAt:new Date(e.timestamp).toISOString(),updatedAt:new Date(e.timestamp).toISOString(),responses:[],alternatives:[]};he(e.sessionId,s)},reconnectToStream:async function(t,n){try{const s=await async function(e,t,n){return await x(e,"POST",`/chat/conversations/${t}/reconnect${void 0!==n?`?lastSequence=${n}`:""}`,{})}(e.restApiContext,t,n);if(s.pendingChunks&&s.pendingChunks.length>0)for(const e of s.pendingChunks)s.currentMessageId&&Ie(t,s.currentMessageId,e.content);return s}catch(s){return null}}}})))}}}));
//# sourceMappingURL=chat.store-legacy-pzWGyzhB.js.map