n8n-editor-ui
Version:
Workflow Editor UI for n8n
2 lines • 24.7 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.16.1"}}catch(e){}}(),System.register(["./vue.runtime.esm-bundler-legacy-BW6xDdqj.js","./core-legacy-VD8c7QJ-.js","./users.store-legacy-azRUgFdP.js","./constants-legacy-2_ytuuS3.js","./useRootStore-legacy-CC08el-l.js","./settings.store-legacy-I6rZOvfF.js","./retry-legacy-Sl_oDViL.js","./fileUtils-legacy-Dp16LI9C.js"],(function(e,t){var n,s,a,o,i,r,c,d,l,u,m,g,f,p,v,h,I,y,w,b,M,x,S,A,C,T,O,E,$,k,P,D,_,N,U,F,j,H,L,R,Z,G,W,B,z,q,K,J,Q,X,Y,V,ee,te,ne,se,ae;function oe(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,c=null;if(e&&t?e.index<t.index?(a=e,c="create"):(a=t,c="edit"):e?(a=e,c="create"):t&&(a=t,c="edit"),!a||!c){const e=s.slice(o);if(e){const{text:t,hiddenPrefix:s}=re(e);t&&ie(n,t),s&&n.push({type:"hidden",content:s})}break}a.index>o&&ie(n,s.slice(o,a.index));const d=a.index,l=s.slice(d);if("create"===c){const e=ce(l);n.push(e.item),o=d+e.consumed}else{const e=de(l);n.push(e.item),o=d+e.consumed}}return n}function ie(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 re(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 ce(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:le(s,"title")??"",type:le(s,"type")??"",content:le(s,"content")??""},isIncomplete:n},consumed:s.length}}function de(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:le(s,"title")??"",oldString:le(s,"oldString")??"",newString:le(s,"newString")??"",replaceAll:"true"===(le(s,"replaceAll")??"false").toLowerCase()},isIncomplete:n},consumed:s.length}}function le(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({a:async function(e,t,n){return await x(e,"POST",`/credentials/${t}/authorize?resolverId=${encodeURIComponent(n)}&authSource=cookie`)},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},l:async function(e,t){return await x(e,"GET",`/workflows/${t}/execution-status?authSource=cookie`)},o:function(e,t,n,s){return`${e.baseUrl}/chat/conversations/${t}/messages/${n}/attachments/${s}`},u:async function(e,t,n){await x(e,"DELETE",`/credentials/${t}/revoke?resolverId=${encodeURIComponent(n)}&authSource=cookie`)}}),{setters:[function(e){n=e.Ft,s=e.S},function(e){a=e.at},function(e){o=e.Pn,i=e.fr,r=e.it,c=e.s},function(e){d=e.$r,l=e.A,u=e.Eo,m=e.Fa,g=e.Ki,f=e.Kr,p=e.Pt,v=e.Qc,h=e.Xr,I=e.Zr,y=e.ei,w=e.qr},function(e){b=e.T,M=e.a,x=e.c,S=e.r,A=e.t},function(e){C=e.t},function(e){T=e.t},function(e){O=e.T,E=e.a,$=e.i,k=e.n,P=e.o,D=e.r,_=e.t,N=e.u,U=e.y}],execute:function(){try{t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},(I=(new t.Error).stack)&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[I]="11f07279-158a-43ce-afea-c4e88beb6e6b",t._sentryDebugIdIdentifier="sentry-dbid-11f07279-158a-43ce-afea-c4e88beb6e6b")}catch(t){}var t,I;e("c",F=async(e,t)=>await x(e,"POST","/chat/models",t)),j=async(e,t,n)=>{await x(e,"POST",`/chat/conversations/${t}/messages/${n}/stop`)},H=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()}`)},L=async(e,t,n)=>await x(e,"PATCH",`/chat/conversations/${t}`,n),R=async(e,t,n)=>await L(e,t,{title:n}),Z=async(e,t)=>{await x(e,"DELETE",`/chat/conversations/${t}`)},G=async(e,t)=>await x(e,"GET",`/chat/conversations/${t}`),e("s",W=async(e,t)=>await x(e,"GET",`/chat/agents/${t}`)),B=async(e,t)=>await x(e,"POST","/chat/agents",t),z=async(e,t,n)=>await x(e,"POST",`/chat/agents/${t}`,n),q=async(e,t)=>{await x(e,"DELETE",`/chat/agents/${t}`)},K=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)}`)},Q=async e=>(await x(e,"GET","/chat/settings")).providers,X=async(e,t)=>(await x(e,"GET","/chat/settings/"+t)).settings,Y=async(e,t)=>await x(e,"POST","/chat/settings",{payload:t}),e("d",(async(e,t)=>{await x(e,"PUT","/chat/semantic-search",t)})),V=async e=>await x(e,"GET","/chat/tools"),ee=async(e,t)=>await x(e,"POST","/chat/tools",{definition:t}),te=async(e,t,n)=>await x(e,"PATCH",`/chat/tools/${t}`,n),ne=async(e,t)=>{await x(e,"DELETE",`/chat/tools/${t}`)},e("r",se={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",ae={embeddingModel:{credentialId:null,provider:h.options.filter((e=>e in se))[0]},vectorStore:{credentialId:null,provider:d.options[0]}}),e("t",b(S.CHAT_HUB,(()=>{const e=A(),d=C(),h=r(),I=o(),b=i(),S=a(),se=n(null);let ie=null;const re=n({}),ce=n({byId:{},ids:null,hasMore:!1,nextCursor:null,lastFetchedType:void 0}),de=n(!1),le=n(),ue=n(!1),me=n(null),ge=n([]),fe=n(!1),pe=n(new Map),ve=e=>pe.value.get(e);function he(e){pe.value.has(e)||pe.value.set(e,{messages:{},activeMessageChain:[]});const t=pe.value.get(e);if(!t)throw new Error(`Conversation for session ID ${e} not found`);return t}function Ie(e){const t=ve(e);if(!t||0===t.activeMessageChain.length)return null;const n=t.activeMessageChain[t.activeMessageChain.length-1];return t.messages[n]??null}function ye(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 we(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 be(e,t){const n=he(e);return n.messages[t.id]=t,n.messages=we(Object.values(n.messages)),n.activeMessageChain=ye(n.messages,t.id),t}function Me(e,t,n){const s=he(e).messages[t];if(!s)throw new Error(`Message with ID ${t} not found in session ${e}`);s.content=oe(s.content,n)}function xe(e,t,n,s){const a=he(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 Se(t,n={}){return ie??=F(e.restApiContext,{credentials:t}).finally((()=>{ie=null})),[se.value]=await Promise.all([ie,new Promise((e=>setTimeout(e,n.minLoadingTime??0)))]),se.value}async function Ae(t,n={}){if(!de.value&&(void 0!==n.type&&n.type!==ce.value.lastFetchedType&&(t=!0),t||!ce.value||ce.value.hasMore||!((ce.value.ids??[]).length>0))){t||(de.value=!0);try{const s=t?void 0:ce.value?.nextCursor??void 0,[a]=await Promise.all([H(e.restApiContext,18,s,n.type),new Promise((e=>setTimeout(e,n.minLoadingTime??0)))]);(t||null===ce.value.ids)&&(ce.value.ids=[]),ce.value.hasMore=a.hasMore,ce.value.nextCursor=a.nextCursor,ce.value.lastFetchedType=n.type;for(const e of a.data){ce.value.ids.push(e.id);const t=ce.value.byId[e.id];ce.value.byId[e.id]={...e,toolIds:t?.toolIds??e.toolIds}}}finally{de.value=!1}}}async function Ce(n){const s=ce.value.byId[n];"manual"!==s?.type&&(s&&"New Chat"!==s.title||await T((async()=>{try{return"New Chat"!==(await G(e.restApiContext,n)).session.title}catch(t){return!1}}),2e3,10),await Ae(!0))}function Te(e,t){const n=he(e).messages[t];return n||be(e,$(e,t,le.value))}async function Oe(e){if(!le.value)return;const t=e instanceof M?new Error(function(e,t){const n={413:S.baseText("chatHub.error.payloadTooLarge"),400:t??S.baseText("chatHub.error.badRequest"),403:S.baseText("chatHub.error.forbidden"),500:t?S.baseText("chatHub.error.serverErrorWithReason",{interpolate:{error:t}}):S.baseText("chatHub.error.serverError")};return e&&n[e]||t||S.baseText("chatHub.error.unknown")}(e.httpStatusCode,e.message)):e instanceof Error&&e.message.includes("Failed to fetch")?new Error(S.baseText("chatHub.error.noConnection")):e;I.showError(t,S.baseText("chatHub.error.sendMessageFailed"));const{sessionId:n}=le.value;le.value=void 0,await Ce(n)}function Ee(e){if("n8n"!==e.provider)return!1;const t=c();if(t.workflowId!==e.workflowId)return!1;const n=t.allNodes.find((e=>e.type===p));return!!n&&!0===n.parameters?.availableInChat}function $e(){const e=c();e.workflowExecutionData={id:l,finished:!1,mode:"manual",status:"running",createdAt:new Date,startedAt:new Date,stoppedAt:void 0,workflowId:e.workflowId,data:g({resultData:{runData:{}}}),workflowData:e.workflow},e.private.setActiveExecutionId(null)}function ke(e,t){const n=ce.value.byId[e];n&&(ce.value.byId[e]={...n,...t})}async function Pe(t,n){const s=D(n,1024*(d.moduleSettings["chat-hub"]?.agentUploadMaxSizeMb??20)*1024);let a;for(const o of s)a=await K(e.restApiContext,t,o);return a}function De(e,t){const n=se.value?.[e.provider]?.models.find((t=>U(t,e)));return n||E(e,t)}const _e=s((()=>{const e=d.isEnterpriseFeatureEnabled[v.Sharing],t=d.moduleSettings["chat-hub"]?.semanticSearch??ae,n=t?.vectorStore.credentialId??"",s=h.getCredentialById(n);return n?s&&s?.type===w[t.vectorStore.provider]?e&&!s.isGlobal?"notShared":void 0:"notFound":"unspecified"})),Ne=s((()=>{const e=d.isEnterpriseFeatureEnabled[v.Sharing],t=d.moduleSettings["chat-hub"]?.semanticSearch??ae,n=t?.embeddingModel.credentialId??"",s=h.getCredentialById(n);return n?s&&s?.type===f[t.embeddingModel.provider]?e&&!s.isGlobal?"notShared":void 0:"notFound":"unspecified"})),Ue=s((()=>({isReadyForCurrentUser:!(_e.value&&"notShared"!==_e.value||Ne.value&&"notShared"!==Ne.value),vectorStoreIssue:_e.value,embeddingIssue:Ne.value})));return{agents:s((()=>se.value??y)),agentsReady:s((()=>null!==se.value)),customAgents:re,getAgent:De,fetchAgents:Se,getCustomAgent:function(e){return se.value?.["custom-agent"].models.find((t=>"agentId"in t&&t.agentId===e))},fetchCustomAgent:async function(t){const n=await W(e.restApiContext,t);re.value[t]=n},createCustomAgent:async function(t,n,s){let a=await B(e.restApiContext,t);n.length>0&&(a=await Pe(a.id,n));const o=se.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 se.value?.["custom-agent"].models.push(r),re.value[a.id]=a,await Se(s),b.track("User created agent",{...N(t)}),r},updateCustomAgent:async function(t,n,s,a,o){await z(e.restApiContext,t,n);for(const r of a)await J(e.restApiContext,t,r);s.length>0&&await Pe(t,s);const i=await W(e.restApiContext,t);if(se.value?.["custom-agent"]){const e=i.suggestedPrompts.filter((e=>e.text.trim().length>0));se.value["custom-agent"].models=se.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 re.value[t]=i,await Se(o),i},deleteCustomAgent:async function(t,n){await q(e.restApiContext,t),se.value?.["custom-agent"]&&(se.value["custom-agent"].models=se.value["custom-agent"].models.filter((e=>!("agentId"in e)||e.agentId!==t))),delete re.value[t],await Se(n)},configuredTools:ge,configuredToolsLoaded:fe,fetchConfiguredTools:async function(){const t=await V(e.restApiContext);return ge.value=t,fe.value=!0,t},addConfiguredTool:async function(t){const n=await ee(e.restApiContext,t);return ge.value=[...ge.value,n],n},updateConfiguredTool:async function(t,n){const s=await te(e.restApiContext,t,{definition:n});return ge.value=ge.value.map((e=>e.definition.id===t?s:e)),s},toggleToolEnabled:async function(t,n){const s=await te(e.restApiContext,t,{enabled:n});return ge.value=ge.value.map((e=>e.definition.id===t?s:e)),s},removeConfiguredTool:async function(t){await ne(e.restApiContext,t),ge.value=ge.value.filter((e=>e.definition.id!==t))},sessions:ce,sessionsReady:s((()=>null!==ce.value.ids)),sessionsLoading:s((()=>de.value)),fetchSessions:Ae,fetchMoreSessions:async function(e={}){ce.value?.hasMore&&!de.value&&await Ae(!1,e)},renameSession:async function(t,n){ke(t,(await R(e.restApiContext,t,n)).session)},updateSessionModel:async function(t,n,s){ke(t,(await L(e.restApiContext,t,{agent:{model:n,name:s}})).session)},deleteSession:async function(t){await Z(e.restApiContext,t),delete ce.value.byId[t],ce.value.ids=ce.value.ids?.filter((e=>e!==t))??null},toggleSessionTool:async function(t,n){const s=ce.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];ke(t,(await L(e.restApiContext,t,{toolIds:o})).session)},toggleCustomAgentTool:async function(t,n){const s=re.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];re.value[t]={...s,toolIds:o},await z(e.restApiContext,t,{toolIds:o})},conversationsBySession:pe,getConversation:ve,fetchMessages:async function(t){const{conversation:n,session:s}=await G(e.restApiContext,t),a=we(Object.values(n.messages)),o=ye(a,Object.values(a).sort(((e,t)=>e.createdAt<t.createdAt?-1:1)).pop()?.id??null);pe.value.set(t,{messages:a,activeMessageChain:o}),ce.value.byId[t]=s},getActiveMessages:e=>{const t=ve(e);return t?k(e,t,le.value):[]},switchAlternative:function(e,t){const n=ve(e);if(!n?.messages[t])throw new Error(`Message with ID ${t} not found in session ${e}`);n.activeMessageChain=ye(n.messages,t)},lastMessage:Ie,streaming:le,isResponding:function(e){return le.value?.sessionId===e},sendMessage:async function(t,n,s,a,o=[]){const i=u(),r=he(t),c=r.activeMessageChain.length?r.activeMessageChain[r.activeMessageChain.length-1]:null,d=(await Promise.all(o.map(_))).map((e=>({fileName:e.fileName??"unnamed file",mimeType:e.mimeType,data:e.data})));le.value={promptPreviousMessageId:c,promptId:i,promptText:n,sessionId:t,retryOfMessageId:null,revisionOfMessageId:null,attachments:d,agent:s};const l=Ee(s.model),m=l?"manual":"production",g=l?"canvas":"chat_hub";b.track("User sent chat hub message",{...N(s.model),is_custom:"custom-agent"===s.model.provider,chat_session_id:t,mode:m,source:g});const f={model:s.model,messageId:i,sessionId:t,message:n,credentials:a,previousMessageId:c,attachments:d,agentName:s.name,timeZone:Intl.DateTimeFormat().resolvedOptions().timeZone};try{if(ce.value.byId[t]||(ce.value.byId[t]=P(le.value,ge.value.filter((e=>e.enabled)).map((e=>e.definition.id)),l),ce.value.ids??=[],ce.value.ids.unshift(t)),l){$e();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:c,attachments:d,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 Oe(p)}},editMessage:async function(t,n,s,a,o,i=[],r=[]){const c=u(),d=he(t).messages[n],l=d?.previousMessageId??null,m=await Promise.all(r.map(_)),g={model:a.model,messageId:c,message:s,credentials:o,newAttachments:m.map((e=>({fileName:e.fileName??"unnamed file",mimeType:e.mimeType,data:e.data}))),keepAttachmentIndices:i,timeZone:Intl.DateTimeFormat().resolvedOptions().timeZone};"ai"===d?.type&&function(e,t,n){const s=he(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),le.value={promptPreviousMessageId:l,promptId:c,promptText:s,sessionId:t,agent:a,retryOfMessageId:null,revisionOfMessageId:n,attachments:[...i.flatMap((e=>{const t=d?.attachments[e];return t?[{fileName:t.fileName??"unnamed file",mimeType:t.mimeType??"application/octet-stream",data:""}]:[]})),...m]};const f=Ee(a.model),p=f?"manual":"production",v=f?"canvas":"chat_hub";b.track("User edited chat hub message",{...N(a.model),is_custom:"custom-agent"===a.model.provider,chat_session_id:t,chat_message_id:n,mode:p,source:v});try{f?($e(),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 Oe(h)}},regenerateMessage:async function(t,n,s,a){const o=he(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");le.value={promptPreviousMessageId:o,promptId:n,promptText:"",sessionId:t,agent:s,retryOfMessageId:n,revisionOfMessageId:null,attachments:[]};const r=Ee(s.model),c=r?"manual":"production",d=r?"canvas":"chat_hub";b.track("User regenerated chat hub message",{...N(s.model),is_custom:"custom-agent"===s.model.provider,chat_session_id:t,chat_message_id:n,mode:c,source:d});try{r?($e(),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(l){await Oe(l)}},stopStreamingMessage:async function(t){const n=Ie(t);n&&"running"===n.status&&(xe(t,n.id,"cancelled"),await j(e.restApiContext,t,n.id),le.value?.sessionId===t&&(le.value=void 0,await Ce(t)))},settings:me,settingsLoading:ue,fetchAllChatSettings:async function(){try{ue.value=!0,me.value=await Q(e.restApiContext)}finally{ue.value=!1}return me.value},fetchProviderSettings:async function(t){const n=await X(e.restApiContext,t);return me.value&&(me.value[t]=m(n)),n},updateProviderSettings:async function(t){t.enabled||(t.allowedModels=[]);const n=await Y(e.restApiContext,t);return me.value&&(me.value[t.provider]=m(n)),n},semanticSearchReadiness:Ue,handleWebSocketExecutionBegin:function(e){const{sessionId:t}=e;if(le.value?.sessionId===t)return;const n=ce.value.byId[t];if(!n)return;const s=O(n);s&&(le.value={promptPreviousMessageId:null,promptId:"",promptText:"",sessionId:t,retryOfMessageId:null,revisionOfMessageId:null,attachments:[],agent:De(s,{name:n.agentName,icon:n.agentIcon})})},handleWebSocketExecutionEnd:function(e){const{sessionId:t,status:n}=e;if(le.value?.sessionId===t){const e=le.value.sessionId;if(le.value.messageId){const e=ve(t)?.messages[le.value.messageId];e&&"running"===e.status&&xe(t,le.value.messageId,n)}le.value=void 0,"error"===n&&I.showError(new Error("Execution failed"),S.baseText("chatHub.error.unknown")),Ce(e)}},handleWebSocketStreamBegin:function(e){const{sessionId:t,messageId:n,previousMessageId:s,retryOfMessageId:a}=e;le.value?.sessionId===t&&(le.value.messageId=n,le.value.promptPreviousMessageId=s,le.value.retryOfMessageId=a);const o=ve(t);if(o?.messages[n])return;s&&"waiting"===o?.messages[s]?.status&&xe(t,s,"success");const i=$(t,n,le.value?.sessionId===t?le.value:void 0);i.previousMessageId=s,i.retryOfMessageId=a,be(t,i)},handleWebSocketStreamChunk:function(e){const{sessionId:t,messageId:n,content:s}=e;ve(t)?.messages[n]||Te(t,n),Me(t,n,s)},handleWebSocketStreamEnd:function(e){const{sessionId:t,messageId:n,status:s}=e;xe(t,n,s)},handleWebSocketStreamError:function(e){const{sessionId:t,messageId:n,error:s}=e,a=Te(t,n);a.content?a.content=oe(a.content,"\n\n"+s):a.content=[{type:"text",content:s}],a.status="error",xe(t,n,"error",a.content)},handleHumanMessageCreated:function(e){const t=pe.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:[]};be(e.sessionId,n)},handleMessageEdited:function(e){const t=pe.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:[]};be(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&&Me(t,s.currentMessageId,e.content);return s}catch(s){return null}}}})))}}}));
//# sourceMappingURL=chat.store-legacy-BnVb-kpz.js.map