UNPKG

n8n-editor-ui

Version:

Workflow Editor UI for n8n

2 lines 10.3 kB
(function(){try{var e=typeof window<`u`?window:typeof global<`u`?global:typeof globalThis<`u`?globalThis:typeof self<`u`?self:{};e.SENTRY_RELEASE={id:`n8n@2.16.1`}}catch{}})();try{(function(){var e=typeof window<`u`?window:typeof global<`u`?global:typeof globalThis<`u`?globalThis:typeof self<`u`?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]=`54eabcbb-c27e-404e-b5a6-6d4015a46b05`,e._sentryDebugIdIdentifier=`sentry-dbid-54eabcbb-c27e-404e-b5a6-6d4015a46b05`)})()}catch{}import{$ as e,A as t,C as n,E as r,Ft as i,Ht as a,N as o,S as s,Sn as c,T as l,Wt as u,_ as d,_n as f,gt as p,j as m,pt as ee,rt as h,w as g,yt as _}from"./vue.runtime.esm-bundler-C3C09Zii.js";import{at as v}from"./core-Bz5WjPxS.js";import{Di as te,Ii as y,Qi as b,Xi as x,Zi as S,n as C}from"./src-XqE2yCpG.js";import{t as w}from"./_plugin-vue_export-helper-CIL7EULb.js";import{ai as T,fr as ne,it as re,r as ie}from"./users.store-xP93bV7X.js";import{Bo as ae,Kr as oe,Xr as E}from"./constants-DuQbSl-q.js";import{t as se}from"./settings.store-CAFiYCMH.js";import{n as D}from"./dist-BL9AkvYs.js";import{f as O,h as k,i as A,r as j,u as M}from"./constants-BVzsnVB6.js";import{t as N}from"./chat.store-mz4IZJ73.js";import{E as P,S as F,a as I,d as L,h as R,u as z,v as B,w as V}from"./fileUtils-D6dhtxVJ.js";import{t as H}from"./ChatAgentAvatar-DKWX_rQ_.js";var ce=o({__name:`ChatProviderAvatar`,props:{provider:{},icon:{}},setup(t){let n=s(()=>I(t.provider===`n8n`?{provider:`n8n`,workflowId:``}:t.provider===`custom-agent`?{provider:`custom-agent`,agentId:``}:{provider:t.provider,model:``},{icon:t.icon}));return(t,r)=>(e(),g(H,{agent:n.value,size:`sm`},null,8,[`agent`]))}});function U(e,t){return t?(e.data?.fullName??e.label??``).toLowerCase().includes(t):!0}function W(e){let t=e.id;return!!(t.endsWith(`::configure`)||t.endsWith(`::add-model`)||t.endsWith(`::error`)||t.endsWith(`::loading`)||e.disabled||!e.data?.provider)}function G(e,t,n=!1){if(W(e))return null;if(!t||n)return e;let r=U(e,t),i=e.children??[],a=i.flatMap(e=>{let n=G(e,t,r);return n?[n]:[]});return r||a.length>0?i.length>0&&a.length===0?null:{...e,children:a}:null}function K(e,t){return{id:V(e.model),icon:e.icon??t??void 0,label:y(e.name,45),disabled:!1,data:{provider:e.model.provider,description:e.description??void 0,fullName:e.name}}}function q(e,{isLoading:t,i18n:n,includeCustomAgents:r}){if(!r)return null;let i=t?[]:e.map(e=>K(e,F));return{id:`custom-agent`,label:n.baseText(`chatHub.agent.personalAgents`),icon:F,data:{provider:`custom-agent`},children:[...t?[{id:`custom-agent::loading`,label:n.baseText(`generic.loadingEllipsis`),disabled:!0}]:i,{id:O,icon:{type:`icon`,value:`plus`},label:n.baseText(`chatHub.agent.newAgent`),disabled:!1,divided:t||i.length>0}]}}function J(e,t){let n=new Map;for(let t of e){let e=t.groupName??``,r=n.get(e)??[];n.set(e,[...r,t])}return n.size<2?e.map(e=>K(e,P)):[...n].map(([e,n])=>{let r=e===``?t.baseText(`chatHub.models.selector.personalProject`):e;return{id:`n8n-project-${e}`,label:r,icon:n[0]?.groupIcon??P,data:{provider:`n8n`},children:n.map(e=>K(e,P))}})}function Y(e,{includeCustomAgents:t,i18n:n,isLoading:r}){if(!t)return null;let i=n.baseText(`chatHub.workflowAgents.empty.noAgents`),a=n.baseText(`generic.loadingEllipsis`);return{id:`n8n`,label:n.baseText(`chatHub.agent.workflowAgents`),icon:P,data:{provider:`n8n`},children:r?[{id:`n8n::loading`,label:a,disabled:!0}]:e.length===0?[{id:`n8n::no-agents`,label:i,disabled:!0}]:J(e,n)}}function X(e,{models:t,error:n},r){let{settings:i,i18n:a,isLoading:o,credentials:s}=r,c=i[e];if(c?.enabled===!1)return null;let l={id:`${e}::configure`,icon:{type:`icon`,value:`settings`},label:a.baseText(`chatHub.agent.configureCredentials`),disabled:!1};if(o)return{id:e,label:k[e],data:{provider:e},children:[l,{id:`${e}::loading`,label:a.baseText(`generic.loadingEllipsis`),disabled:!0,divided:!0}]};let u=(c?.allowedModels??[]).flatMap(t=>t.isManual?[I({provider:e,model:t.model},{name:t.displayName})]:[]),d=[...t,...u].toSorted((e,t)=>(t.metadata.priority??0)-(e.metadata.priority??0)),f=d.length>0?d.flatMap((e,t)=>{if(c&&!R(c,e.model))return[];let n=K(e);return[t===0?{...n,divided:!0}:n]}).filter((e,t,n)=>n.findIndex(t=>t.id===e.id)===t):n?[{id:`${e}::error`,divided:!0,disabled:!0,label:n}]:[],p=[l,...f,...(f.length>0||s?.[e])&&c?.allowedModels.length===0?[{id:`${e}::add-model`,icon:{type:`icon`,value:`plus`},label:a.baseText(`chatHub.agent.addModel`),disabled:!1,divided:!0}]:[]];return{id:e,data:{provider:e},label:k[e],children:p}}function Z(e,t){let n=e.children??[],r=[...t,e.label];return n.length===0?[{...e,divided:!1,data:e.data?{...e.data,parts:r}:void 0}]:n.flatMap(e=>Z(e,r))}function le(e,t,n){return t?e.reduce((e,r)=>{let i=G(r,t);if(!i)return e;let a=Z(i,[]),o=Math.max(0,10-e.length),s=i.data?.provider,c=s?k[s]:``;if(e.push(...a.slice(0,o)),a.length>o){let t=o>0?n.baseText(`chatHub.models.selector.moreModels`,{interpolate:{providerName:c}}):i.label,r=a.slice(o).map(e=>({...e,label:y(e.data?.fullName??``,45),data:e.data?{...e.data,parts:void 0}:void 0}));e.push({...i,divided:!1,label:t,children:r})}return e},[]):e}function ue(e,t){let n=[],r=q(e[`custom-agent`].models,t),i=Y(e.n8n.models,t);r&&n.push(r),i&&n.push(i);let a=E.options.toSorted((e,t)=>(M.includes(e)?1:-1)-(M.includes(t)?1:-1)),o=!1;for(let r of a){let i=X(r,e[r],t);i&&(n.push(o?i:{...i,divided:!0}),o=!0)}return n}var Q=w(o({__name:`ModelSelector`,props:{selectedAgent:{},includeCustomAgents:{type:Boolean,default:!0},credentials:{},text:{type:Boolean},warnMissingCredentials:{type:Boolean,default:!1},agents:{},isLoading:{type:Boolean}},emits:[`change`,`createCustomAgent`,`selectCredential`],setup(a,{expose:o,emit:p}){let y=p;function w(e,t){y(`selectCredential`,e,t)}function E(e,t){y(`change`,{provider:e,model:t})}let O=v(),M=ee(`dropdownRef`),N=ie(),P=se(),F=re(),I=T(),R=ne(),V=i(``),U=s(()=>a.selectedAgent?F.getCredentialById(a.credentials?.[a.selectedAgent.model.provider]??``)?.name:void 0),W=s(()=>B(a.selectedAgent?.model)),G=s(()=>a.warnMissingCredentials&&W.value&&a.selectedAgent?.model.provider&&!a.credentials?.[a.selectedAgent?.model.provider]),K=s(()=>ue(a.agents,{includeCustomAgents:a.includeCustomAgents,isLoading:a.isLoading,i18n:O,settings:P.moduleSettings?.[`chat-hub`]?.providers??{},credentials:a.credentials})),q=s(()=>le(K.value,V.value,O)),J=s(()=>a.selectedAgent?.name??O.baseText(`chatHub.models.selector.defaultLabel`)),Y=s(()=>ae(I.personalProject?.scopes).credential.create);function X(e){let t=oe[e];if(F.getCredentialsByType(t).length===0&&Y.value){N.openNewCredential(t);return}N.openModalWithData({name:j,data:{credentialType:t,displayName:k[e],initialValue:a.credentials?.[e]??null,onSelect:t=>w(e,t)}})}function Z(e){N.openModalWithData({name:A,data:{provider:e,initialValue:null,onSelect:E}})}function Q(e){if(e===`agent::new`){y(`createCustomAgent`);return}let[,t]=e.split(`::`),n=L(e);if(n){if(t===`configure`&&B(n)){X(n.provider);return}if(t===`add-model`&&B(n)){Z(n.provider);return}R.track(`User selected model or agent`,{...z(n),is_custom:n.provider===`custom-agent`}),y(`change`,n)}}function $(e){V.value=e.toLowerCase()}return o({open:()=>M.value?.open(),openCredentialSelector:e=>X(e)}),(i,o)=>(e(),g(u(C),{ref_key:`dropdownRef`,ref:M,items:q.value,teleported:``,placement:`bottom-start`,"extra-popper-class":[i.$style.component,V.value?i.$style.searching:``].join(` `),searchable:``,emptyText:V.value?u(O).baseText(`chatHub.models.selector.noMatch`):void 0,onSearch:$,onSelect:Q},{trigger:_(()=>[m(u(S),{variant:a.text?`ghost`:`subtle`,class:f(i.$style.dropdownButton),text:a.text,"data-test-id":`chat-model-selector`},{default:_(()=>[m(H,{agent:a.selectedAgent,size:U.value||!W.value?`md`:`sm`,class:f(i.$style.icon)},null,8,[`agent`,`size`,`class`]),n(`div`,{class:f(i.$style.selected)},[n(`div`,null,c(u(D)(J.value,u(30))),1),U.value?(e(),g(u(x),{key:0,size:`xsmall`,color:`text-light`},{default:_(()=>[t(c(u(D)(U.value,u(30))),1)]),_:1})):G.value?(e(),g(u(x),{key:1,size:`xsmall`,color:`danger`},{default:_(()=>[m(u(b),{icon:`node-validation-error`,size:`xsmall`,class:f(i.$style.credentialsMissingIcon)},null,8,[`class`]),t(` `+c(u(O).baseText(`chatHub.agent.credentialsMissing`)),1)]),_:1})):l(``,!0)],2),m(u(b),{icon:`chevron-down`,size:`medium`})]),_:1},8,[`variant`,`class`,`text`])]),"item-leading":_(({item:t})=>[t.data?.provider?(e(),g(ce,{key:0,provider:t.data?.provider,icon:t.icon,class:f(i.$style.menuIcon)},null,8,[`provider`,`icon`,`class`])):l(``,!0)]),"item-label":_(({item:n,ui:a})=>[n.data?.parts?(e(),r(`div`,{key:0,class:f([i.$style.flattenedLabel,a.class])},[(e(!0),r(d,null,h(n.data.parts,(a,o)=>(e(),r(d,{key:o},[o>0?(e(),g(u(x),{key:0,color:`text-light`,class:f(i.$style.separator)},{default:_(()=>[m(u(b),{icon:`chevron-right`,size:`small`})]),_:1},8,[`class`])):l(``,!0),m(u(x),{size:`medium`,color:o===n.data.parts.length-1?`text-dark`:`text-base`},{default:_(()=>[t(c(a),1)]),_:2},1032,[`color`])],64))),128))],2)):(e(),g(u(x),{key:1,class:f(a.class),size:`medium`,color:`text-dark`},{default:_(()=>[t(c(n.label),1)]),_:2},1032,[`class`]))]),"item-trailing":_(({item:t,ui:n})=>[t.data?.description?(e(),g(u(te),{key:0,content:u(D)(t.data.description,200,0),class:f(n.class),"content-class":i.$style.tooltip,placement:`right`},{default:_(()=>[m(u(b),{icon:`info`,size:`medium`,color:`text-light`,class:f(i.$style.infoIcon)},null,8,[`class`])]),_:1},8,[`content`,`class`,`content-class`])):l(``,!0)]),_:1},8,[`items`,`extra-popper-class`,`emptyText`]))}}),[[`__cssModules`,{$style:{component:`_component_wt5tl_125`,dropdownButton:`_dropdownButton_wt5tl_130`,credentialsMissingIcon:`_credentialsMissingIcon_wt5tl_141`,selected:`_selected_wt5tl_146`,icon:`_icon_wt5tl_153`,infoIcon:`_infoIcon_wt5tl_158`,menuIcon:`_menuIcon_wt5tl_159`,avatarIcon:`_avatarIcon_wt5tl_167`,tooltip:`_tooltip_wt5tl_171`,flattenedLabel:`_flattenedLabel_wt5tl_176`,separator:`_separator_wt5tl_185`}}]]);function $(e){let t=N(),n=i(!1),r=s(()=>a(e)),o=s(()=>{if(r.value)return t.customAgents[r.value]});return p(r,async e=>{if(e)try{n.value=!0,await t.fetchCustomAgent(e)}finally{n.value=!1}},{immediate:!0}),{isLoading:n,customAgent:o}}export{Q as n,$ as t}; //# sourceMappingURL=useCustomAgent-RYHrbz79.js.map