|
10 | 10 | let includePlannerAgent = false; |
11 | 11 | let includeTaskAgent = false; |
12 | 12 | let includeStaticAgent = false; |
13 | | - let disabled = false; |
14 | 13 |
|
15 | 14 | /** @type {any[]} */ |
16 | 15 | let agents = []; |
|
20 | 19 |
|
21 | 20 | /** @type {import('$agentTypes').AgentFilter} */ |
22 | 21 | const filter = { |
23 | | - pager: { page: 1, size: 20, count: 0 }, |
| 22 | + pager: { page: 1, size: 100, count: 0 }, |
24 | 23 | disabled: false, |
25 | | - types: includeTaskAgent ? [AgentType.Task] : ["none"] |
| 24 | + types: [AgentType.Planning, AgentType.Task] |
26 | 25 | }; |
27 | 26 |
|
28 | 27 | /** @type {import('$agentTypes').AgentModel[]} */ |
29 | 28 | export let routers; |
30 | 29 |
|
31 | 30 | /** @type {boolean} */ |
32 | | - export let singleMode = false; |
| 31 | + export let viewMode = false; |
33 | 32 |
|
34 | 33 | /** @type {Drawflow} */ |
35 | 34 | let editor; |
36 | 35 | const dispatch = createEventDispatcher(); |
37 | | -
|
38 | | - $: { |
39 | | - // disabled = !!targetAgentId; |
40 | | - } |
41 | 36 | |
42 | 37 | onMount(async () => { |
43 | | - // const response = await getAgents(filter); |
44 | | - // agents = response?.items || []; |
| 38 | + if (viewMode) { |
| 39 | + const response = await getAgents(filter); |
| 40 | + agents = response?.items || []; |
| 41 | + } |
45 | 42 |
|
46 | 43 | const container = document.getElementById("drawflow"); |
47 | 44 | if (container) { |
|
74 | 71 | nodeSpaceY * (agents.length + 1) / 2; |
75 | 72 |
|
76 | 73 | // add end-user node |
77 | | - let userNodeId = editor.addNode('user', 0, 1, posX, posY, 'user', |
| 74 | + const userNodeId = editor.addNode('user', 0, 1, posX, posY, 'user', |
78 | 75 | { |
79 | 76 | id: "", |
80 | 77 | profiles: [], |
|
83 | 80 |
|
84 | 81 | // add router node |
85 | 82 | posX += nodeSpaceX; |
86 | | - let routerPosY = nodeSpaceY * (agents.length > 0 ? agents.length : 1) / (routers.length > 0 ? routers.length : 1); |
| 83 | + let routerPosY = viewMode ? posY : nodeSpaceY * (agents.length > 0 ? agents.length : 1) / (routers.length > 0 ? routers.length : 1); |
| 84 | +
|
87 | 85 | routers.forEach(router => { |
88 | 86 | /** @type {string[]} */ |
89 | 87 | let profiles = []; |
|
108 | 106 | if (router.is_host) { |
109 | 107 | html =`<img src="images/users/bot.png" height="30">${html}`; |
110 | 108 | } |
111 | | - let nodeId = editor.addNode('router', 1, 1, posX, routerPosY, 'router', data, `${html}`, false);; |
| 109 | +
|
| 110 | + const nodeId = editor.addNode('router', 1, 1, posX, routerPosY, 'router', data, `${html}`, false);; |
112 | 111 | // connect user and router |
113 | 112 | editor.addConnection(userNodeId, nodeId, `output_1`, `input_1`); |
114 | 113 | routerPosY += nodeSpaceY + 50; |
|
117 | 116 | const plannerAgents = agents.filter(x => x.type === 'planning'); |
118 | 117 | const otherAgnets = agents.filter(x => x.type !== 'planning'); |
119 | 118 |
|
120 | | - posY = 100; |
| 119 | + posY = 120; |
121 | 120 | posX += nodeSpaceX; |
122 | 121 | plannerAgents.forEach(agent => { |
| 122 | + /**@type {any} */ |
| 123 | + let nodeId = null; |
123 | 124 | let html = `<span class="h6">${agent.name}</span>`; |
124 | 125 |
|
125 | 126 | if (agent.profiles.length > 0) { |
|
131 | 132 | agent: agent.name |
132 | 133 | }; |
133 | 134 |
|
134 | | - const nid = editor.addNode('agent', 1, 0, posX, posY, 'enabled-node', data, html, false); |
135 | 135 | const routers = agentNodes.filter(x => x.type === AgentType.Routing && x.profiles?.includes('planning') && getPlannerName(x) === agent.name); |
| 136 | + if (!viewMode || routers.length > 0) { |
| 137 | + nodeId = editor.addNode('agent', 1, 0, posX, posY, 'enabled-node', data, html, false); |
| 138 | + } |
| 139 | +
|
136 | 140 | routers.forEach(r => { |
137 | | - editor.addConnection(r.nid, nid, `output_1`, `input_1`); |
| 141 | + if (nodeId) { |
| 142 | + editor.addConnection(r.nid, nodeId, `output_1`, `input_1`); |
| 143 | + } |
138 | 144 | }); |
139 | | - posY += nodeSpaceY; |
| 145 | +
|
| 146 | + if (!!nodeId) { |
| 147 | + posY += nodeSpaceY; |
| 148 | + } |
140 | 149 | }); |
141 | 150 |
|
142 | | - posY = 100; |
143 | | - posX += nodeSpaceX; |
144 | | - otherAgnets.forEach(agent => { |
| 151 | + posY = viewMode ? posY + 30 : 120; |
| 152 | + posX += viewMode ? 0 : nodeSpaceX; |
| 153 | + otherAgnets.forEach(agent => { |
| 154 | + /**@type {any} */ |
| 155 | + let nodeId = null; |
| 156 | + /**@type {any[]} */ |
145 | 157 | let profiles = []; |
146 | 158 |
|
147 | 159 | const chatTestLinkHtml = agent.is_public ? |
|
166 | 178 | agent: agent.name, |
167 | 179 | profiles: profiles |
168 | 180 | }; |
169 | | - const nid = editor.addNode('agent', 1, 0, posX, posY, 'enabled-node', data, html, false); |
170 | | -
|
171 | | - // connect by profile |
172 | | - if (profiles.length > 0) { |
173 | | - // match profile |
174 | | - profiles.forEach((/** @type {string} */ profile) => { |
175 | | - if (profile == 'planning') return; |
176 | | -
|
177 | | - agentNodes.filter(ag => ag.type == AgentType.Routing).forEach(r => { |
178 | | - if (r.profiles.find((/** @type {string} */ p) => p == profile)) { |
179 | | - editor.addConnection(r.nid, nid, `output_1`, `input_1`); |
180 | | - } else { |
181 | | - // editor.removeNodeInput(nid, "input_2"); |
182 | | - // editor.addConnection(userNodeId, nid, `output_1`, `input_1`); |
183 | | - } |
| 181 | + |
| 182 | +
|
| 183 | + if (viewMode && profiles.length > 0) { |
| 184 | + const filteredProfiles = profiles.filter((/** @type {string} */ profile) => profile !== 'planning'); |
| 185 | + const foundNodes = agentNodes.filter(ag => ag.type == AgentType.Routing |
| 186 | + && !!ag.profiles?.some((/** @type {any} */ p) => filteredProfiles.includes(p))); |
| 187 | +
|
| 188 | + if (foundNodes.length > 0) { |
| 189 | + nodeId = editor.addNode('agent', 1, 0, posX, posY, 'enabled-node', data, html, false); |
| 190 | + filteredProfiles.forEach((/** @type {string} */ profile) => { |
| 191 | + foundNodes.forEach(r => { |
| 192 | + if (r.profiles.find((/** @type {string} */ p) => p == profile)) { |
| 193 | + editor.addConnection(r.nid, nodeId, `output_1`, `input_1`); |
| 194 | + } |
| 195 | + }); |
184 | 196 | }); |
185 | | - }); |
186 | | - } else { |
187 | | - // profile is empty |
188 | | - /*agentNodes.filter(ag => ag.type == "routing" && ag.profiles.length == 0) |
189 | | - .forEach(r => { |
190 | | - editor.addConnection(r.nid, nid, `output_1`, `input_1`); |
191 | | - });*/ |
192 | | - |
193 | | - editor.addConnection(userNodeId, nid, `output_1`, `input_1`); |
| 197 | + } |
| 198 | + } else if (!viewMode) { |
| 199 | + nodeId = editor.addNode('agent', 1, 0, posX, posY, 'enabled-node', data, html, false); |
| 200 | +
|
| 201 | + // connect by profile |
| 202 | + if (profiles.length > 0) { |
| 203 | + // match profile |
| 204 | + const filteredProfiles = profiles.filter((/** @type {string} */ profile) => profile !== 'planning'); |
| 205 | + filteredProfiles.forEach((/** @type {string} */ profile) => { |
| 206 | + agentNodes.filter(ag => ag.type == AgentType.Routing).forEach(r => { |
| 207 | + if (r.profiles.find((/** @type {string} */ p) => p == profile)) { |
| 208 | + editor.addConnection(r.nid, nodeId, `output_1`, `input_1`); |
| 209 | + } else { |
| 210 | + // editor.removeNodeInput(nid, "input_2"); |
| 211 | + // editor.addConnection(userNodeId, nid, `output_1`, `input_1`); |
| 212 | + } |
| 213 | + }); |
| 214 | + }); |
| 215 | + } else { |
| 216 | + // profile is empty |
| 217 | + /*agentNodes.filter(ag => ag.type == "routing" && ag.profiles.length == 0) |
| 218 | + .forEach(r => { |
| 219 | + editor.addConnection(r.nid, nid, `output_1`, `input_1`); |
| 220 | + });*/ |
| 221 | + |
| 222 | + editor.addConnection(userNodeId, nodeId, `output_1`, `input_1`); |
| 223 | + } |
194 | 224 | } |
195 | 225 |
|
196 | | - posY += nodeSpaceY; |
| 226 | + if (!!nodeId) { |
| 227 | + posY += nodeSpaceY; |
| 228 | + } |
197 | 229 |
|
198 | 230 | // draw fallback routing |
199 | 231 | // fallback |
200 | | - const fallback = agent.routing_rules.find((/** @type {any} */ p) => p.type == "fallback"); |
201 | | - if (fallback) { |
202 | | - editor.addNodeOutput(nid); |
203 | | - let router = agentNodes.find(ag => ag.id == fallback.redirectTo); |
204 | | - if (router) { |
205 | | - editor.addNodeInput(router.nid); |
206 | | - var inputs = editor.getNodeFromId(router.nid).inputs; |
207 | | - let inputId = 0; |
208 | | - for (let prop in inputs) { |
209 | | - inputId++; |
210 | | - } |
211 | | - editor.addConnection(nid, router.nid, `output_1`, `input_${inputId}`); |
212 | | - } |
213 | | - } |
| 232 | + // const fallback = agent.routing_rules.find((/** @type {any} */ p) => p.type == "fallback"); |
| 233 | + // if (fallback) { |
| 234 | + // editor.addNodeOutput(nid); |
| 235 | + // let router = agentNodes.find(ag => ag.id == fallback.redirectTo); |
| 236 | + // if (router) { |
| 237 | + // editor.addNodeInput(router.nid); |
| 238 | + // var inputs = editor.getNodeFromId(router.nid).inputs; |
| 239 | + // let inputId = 0; |
| 240 | + // for (let prop in inputs) { |
| 241 | + // inputId++; |
| 242 | + // } |
| 243 | + // editor.addConnection(nid, router.nid, `output_1`, `input_${inputId}`); |
| 244 | + // } |
| 245 | + // } |
214 | 246 | }); |
215 | 247 | } |
216 | 248 | |
|
261 | 293 | </script> |
262 | 294 |
|
263 | 295 | <div class="btn-group" role="group"> |
264 | | - <input type="checkbox" class="btn-check active" id="btncheck1" autocomplete="off"/> |
265 | | - <label class={`btn btn-${includeRoutingAgent ? "" : "outline-"}primary`} for="btncheck1">Routing Agent</label> |
| 296 | + <input |
| 297 | + type="checkbox" |
| 298 | + class="btn-check active" |
| 299 | + id="btncheck1" |
| 300 | + autocomplete="off" |
| 301 | + disabled={viewMode} |
| 302 | + /> |
| 303 | + <label |
| 304 | + class={`btn btn-${includeRoutingAgent && !viewMode ? "" : "outline-"}primary`} |
| 305 | + for="btncheck1" |
| 306 | + > |
| 307 | + Routing Agent |
| 308 | + </label> |
266 | 309 |
|
267 | 310 | <input |
268 | 311 | type="checkbox" |
269 | 312 | class="btn-check active" |
270 | 313 | id="btncheck2" |
271 | 314 | autocomplete="off" |
272 | | - disabled={disabled} |
| 315 | + disabled={viewMode} |
273 | 316 | on:click={() => handlePlannerAgentSelected()} |
274 | 317 | /> |
275 | 318 | <label |
|
284 | 327 | class="btn-check" |
285 | 328 | id="btncheck3" |
286 | 329 | autocomplete="off" |
287 | | - disabled={disabled} |
| 330 | + disabled={viewMode} |
288 | 331 | on:click={() => handleTaskAgentSelected()} |
289 | 332 | /> |
290 | 333 | <label |
|
299 | 342 | class="btn-check" |
300 | 343 | id="btncheck4" |
301 | 344 | autocomplete="off" |
302 | | - disabled={disabled} |
| 345 | + disabled={viewMode} |
303 | 346 | on:click={() => handleStaticAgentSelected()} |
304 | 347 | /> |
305 | 348 | <label |
|
0 commit comments