Skip to content

Commit 894ebb1

Browse files
authored
Merge pull request #286 from iceljc/features/refine-chat-window
add planner agents
2 parents 6ed16cb + 8bd41bc commit 894ebb1

File tree

3 files changed

+75
-21
lines changed

3 files changed

+75
-21
lines changed

src/lib/helpers/enums.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export const KnowledgeCollectionType = Object.freeze(knowledgeCollectionType);
7979

8080
const knowledgeCollectionDisplayType = {
8181
[knowledgeCollectionType.QuestionAnswer]: "Q & A",
82-
[knowledgeCollectionType.Document]: "Docs",
82+
[knowledgeCollectionType.Document]: "Documents",
8383
};
8484
export const KnowledgeCollectionDisplayType = Object.freeze(knowledgeCollectionDisplayType);
8585

src/routes/page/agent/router/+page.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@
5555
{#if routers}
5656
<Row>
5757
<Col>
58-
<RoutingFlow routers={routers}
58+
<RoutingFlow
59+
routers={routers}
5960
on:userNodeSelected={(e) => handleUserNodeSelected()}
6061
on:routerNodeSelected={(e) => handleRouterNodeSelected(e.detail.agent)}
6162
on:agentNodeSelected={(e) => handleAgentNodeSelected(e.detail.agent)}/>

src/routes/page/agent/router/routing-flow.svelte

Lines changed: 72 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import { onMount, createEventDispatcher } from 'svelte';
77
88
let includeRoutingAgent = true;
9+
let includePlannerAgent = false;
910
let includeTaskAgent = false;
1011
let includeStaticAgent = false;
1112
@@ -54,6 +55,7 @@
5455
});
5556
5657
function renderRoutingFlow(){
58+
agentNodes = [];
5759
editor.clear();
5860
let posX = 0;
5961
const nodeSpaceX = 300, nodeSpaceY = 120;
@@ -74,6 +76,7 @@
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 ?
@@ -88,8 +91,9 @@
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) {
@@ -101,10 +105,37 @@
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
'';
@@ -132,18 +163,18 @@
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)
@@ -177,40 +208,62 @@
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

Comments
 (0)