66 import { onMount , createEventDispatcher } from ' svelte' ;
77
88 let includeRoutingAgent = true ;
9+ let includePlannerAgent = false ;
910 let includeTaskAgent = false ;
1011 let includeStaticAgent = false ;
1112
5455 });
5556
5657 function renderRoutingFlow (){
58+ agentNodes = [];
5759 editor .clear ();
5860 let posX = 0 ;
5961 const nodeSpaceX = 300 , nodeSpaceY = 120 ;
7476 posX += nodeSpaceX;
7577 let routerPosY = nodeSpaceY * (agents .length > 0 ? agents .length : 1 ) / (routers .length > 0 ? routers .length : 1 );
7678 routers .forEach (router => {
79+ /** @type {string[]} */
7780 let profiles = [];
7881 const planner = getPlannerName (router);
7982 const chatTestLinkHtml = router .is_public ?
8891 const data = {
8992 id: router .id ,
9093 agent: router .name ,
91- profiles: profiles,
94+ profiles: profiles || [] ,
9295 type: router .type ,
96+ routing_rules: router .routing_rules || []
9397 };
9498
9599 if (router .is_host ) {
101105 routerPosY += nodeSpaceY + 50 ;
102106 });
103107
108+ const plannerAgents = agents .filter (x => x .type === ' planning' );
109+ const otherAgnets = agents .filter (x => x .type !== ' planning' );
110+
111+ posY = 100 ;
112+ posX += nodeSpaceX;
113+ plannerAgents .forEach (agent => {
114+ let html = ` <span class="h6">${ agent .name } </span>` ;
115+
116+ if (agent .profiles .length > 0 ) {
117+ html += ` <br/><i class="mdi mdi-folder font-size-16 text-info me-2"></i>` + agent .profiles .join (' , ' );
118+ }
119+
120+ const data = {
121+ id: agent .id ,
122+ agent: agent .name
123+ };
124+ let nid = editor .addNode (' agent' , 1 , 0 , posX, posY, ' enabled-node' , data, html, false );
125+
126+ const routers = agentNodes .filter (x => x .type === ' routing' && x .profiles ? .includes (' planning' ) && getPlannerName (x) === agent .name );
127+ routers .forEach (r => {
128+ editor .addConnection (r .nid , nid, ` output_1` , ` input_1` );
129+ });
130+
131+ posY += nodeSpaceY;
132+ });
133+
104134 posY = 100 ;
105135 posX += nodeSpaceX;
106- agents .forEach (agent => {
136+ otherAgnets .forEach (agent => {
107137 let profiles = [];
138+
108139 const chatTestLinkHtml = agent .is_public ?
109140 ` <a href= "chat/${ agent .id } " class="btn btn-primary float-end" target="_blank"><i class="bx bx-chat"></i></a>` :
110141 ' ' ;
132163 // connect by profile
133164 if (profiles .length > 0 ) {
134165 // match profile
135- profiles .forEach (profile => {
136- agentNodes .filter (ag => ag .type == " routing" )
137- .forEach (r => {
138- if (r .profiles .find ((p ) => p == profile)) {
166+ profiles .forEach ((/** @type {string} */ profile ) => {
167+ if (profile == ' planning' ) return ;
168+
169+ agentNodes .filter (ag => ag .type == " routing" ).forEach (r => {
170+ if (r .profiles .find ((/** @type {string} */ p ) => p == profile)) {
139171 editor .addConnection (r .nid , nid, ` output_1` , ` input_1` );
140172 } else {
141173 // editor.removeNodeInput(nid, "input_2");
142174 // editor.addConnection(userNodeId, nid, `output_1`, `input_1`);
143175 }
144176 });
145177 });
146-
147178 } else {
148179 // profile is empty
149180 /* agentNodes.filter(ag => ag.type == "routing" && ag.profiles.length == 0)
177208
178209 /** @param {import('$agentTypes').AgentModel} router */
179210 function getPlannerName (router ) {
180- const planner = router .routing_rules .find (p => p .type == " planner" );
181- return planner? .field ?? " NaviePlanner" ;
211+ const planner = router .routing_rules ? .find (p => p .type == " planner" );
212+ return !! planner ? planner .field ?? " NaviePlanner" : null ;
213+ }
214+
215+ async function handlePlannerAgentSelected () {
216+ includePlannerAgent = ! includePlannerAgent;
217+ filter .type = getAgentTypes ();
218+ const response = await getAgents (filter);
219+ agents = response? .items || [];
220+ renderRoutingFlow ();
182221 }
183222
184223 async function handleTaskAgentSelected () {
185224 includeTaskAgent = ! includeTaskAgent;
186- filter .type = includeTaskAgent ? " task" : " none" ;
187- filter .type += includeStaticAgent ? " ,static" : " ,none" ;
225+ filter .type = getAgentTypes ();
188226 const response = await getAgents (filter);
189227 agents = response? .items || [];
190228 renderRoutingFlow ();
191229 }
192230
193231 async function handleStaticAgentSelected () {
194232 includeStaticAgent = ! includeStaticAgent;
195- filter .type = includeTaskAgent ? " task" : " none" ;
196- filter .type += includeStaticAgent ? " ,static" : " ,none" ;
233+ filter .type = getAgentTypes ();
197234 const response = await getAgents (filter);
198235 agents = response? .items || [];
199236 renderRoutingFlow ();
200237 }
201238
239+ function getAgentTypes () {
240+ let types = [' none' ];
241+ if (includePlannerAgent) {
242+ types .push (' planning' );
243+ }
244+ if (includeTaskAgent) {
245+ types .push (' task' );
246+ }
247+ if (includeStaticAgent) {
248+ types .push (' static' )
249+ }
250+ return types .join (' ,' );
251+ }
252+
202253< / script>
203254
204255< div class = " btn-group" role= " group" >
205256 < input type= " checkbox" class = " btn-check active" id= " btncheck1" autocomplete= " off" / >
206257 < label class = {` btn btn-${ includeRoutingAgent ? " " : " outline-" } primary` } for = " btncheck1" > Routing Agent< / label>
207258
208- < input type= " checkbox" class = " btn-check" id= " btncheck2" autocomplete= " off" on: click= {handleTaskAgentSelected} / >
209- < label class = {` btn btn-${ includeTaskAgent ? " " : " outline-" } primary` } for = " btncheck2" > Task Agent< / label>
259+ < input type= " checkbox" class = " btn-check active" id= " btncheck2" autocomplete= " off" on: click= {() => handlePlannerAgentSelected ()}/ >
260+ < label class = {` btn btn-${ includePlannerAgent ? " " : " outline-" } primary` } for = " btncheck2" > Planner Agent< / label>
261+
262+ < input type= " checkbox" class = " btn-check" id= " btncheck3" autocomplete= " off" on: click= {() => handleTaskAgentSelected ()} / >
263+ < label class = {` btn btn-${ includeTaskAgent ? " " : " outline-" } primary` } for = " btncheck3" > Task Agent< / label>
210264
211- < input type= " checkbox" class = " btn-check" id= " btncheck3 " autocomplete= " off" on: click= {handleStaticAgentSelected} / >
212- < label class = {` btn btn-${ includeStaticAgent ? " " : " outline-" } primary` } for = " btncheck3 " > Static Agent< / label>
265+ < input type= " checkbox" class = " btn-check" id= " btncheck4 " autocomplete= " off" on: click= {() => handleStaticAgentSelected () } / >
266+ < label class = {` btn btn-${ includeStaticAgent ? " " : " outline-" } primary` } for = " btncheck4 " > Static Agent< / label>
213267< / div>
214268
215- < div id= " drawflow" style= " height: 72vh; width: 100%" >
216- < / div>
269+ < div id= " drawflow" style= " height: 72vh; width: 100%" >< / div>
0 commit comments