@@ -8,15 +8,12 @@ const mcpStore = useMcpStore()
88const agentStore = useAgentStore ()
99const { t } = useI18n ()
1010
11- const allTools = ref ([])
12- // const selectedTree = ref([])
13-
1411const selectedTree = computed ({
1512 get () {
1613 return agentStore .getRevised ? .selectedNode
1714 },
1815 set (value ) {
19- console .log (value)
16+ console .log (' Selected tools ' , value)
2017 if (agentStore .getRevised ) {
2118 agentStore .getRevised .selectedNode = value
2219 }
@@ -31,43 +28,49 @@ const items = ref([
3128 }
3229])
3330
34- watch (allTools, (val ) => {
35- console .log (' Tool list updated' )
36- const flatChildren = []
37- const children = val .map ((type ) => ({
38- id: type .server ,
39- name: type .server ,
40- children: type .tools
41- ? type .tools .map ((obj ) => {
42- const id = agentStore .genId (type .server , obj .name )
43- const unit = {
44- id: id,
45- server: type .server ,
46- name: obj .name
47- }
48- flatChildren .push (id)
49- return unit
50- })
51- : []
52- }))
53- const rootObj = items .value [0 ]
54- rootObj .children = children
55- items .value = [rootObj]
56-
57- const newSelectedNode = agentStore .getRevised .selectedNode .filter ((node ) => {
58- return flatChildren .includes (node)
59- })
60- agentStore .getRevised .selectedNode = newSelectedNode
61- })
31+ watch (
32+ () => agentStore .allTools ,
33+ (val ) => {
34+ if (! agentStore .hasTools ) {
35+ return
36+ }
37+ console .log (' Tools Updated' , val)
38+ const flatChildren = []
39+ const children = val .map ((type ) => ({
40+ id: type .server ,
41+ name: type .server ,
42+ children: type .tools
43+ ? type .tools .map ((obj ) => {
44+ const id = agentStore .genId (type .server , obj .name )
45+ const unit = {
46+ id: id,
47+ server: type .server ,
48+ name: obj .name
49+ }
50+ flatChildren .push (id)
51+ return unit
52+ })
53+ : []
54+ }))
55+ const rootObj = items .value [0 ]
56+ rootObj .children = children
57+ items .value = [rootObj]
58+
59+ agentStore .agents .forEach ((agent ) => {
60+ const newSelectedNode = agent .selectedNode .filter ((node ) => {
61+ return flatChildren .includes (node)
62+ })
63+ agent .selectedNode = newSelectedNode
64+ })
65+ }
66+ )
6267
6368onMounted (() => {
6469 load ()
65- console .log (selectedTree)
66- console .log (items .value )
6770})
6871
6972function load () {
70- const mcpServers = mcpStore .getServers
73+ const mcpServers = mcpStore .getServers ()
7174 const mcpKeys = Object .keys (mcpServers)
7275 // Create an array of Promises
7376 const toolPromises = mcpKeys .map ((key ) => {
@@ -82,7 +85,7 @@ function load() {
8285 // If toolsListFunction is not a function, return an object with content as null
8386 return Promise .resolve ({
8487 name: key,
85- content : null
88+ tools : []
8689 })
8790 }
8891 })
@@ -92,7 +95,8 @@ function load() {
9295 // Return a Promise that resolves when all toolPromises are resolved
9396
9497 return Promise .all (toolPromises).then ((data ) => {
95- allTools .value = data
98+ console .log (data)
99+ agentStore .allTools = data
96100 })
97101}
98102
@@ -112,6 +116,7 @@ function handleNameUpdate() {
112116< / script>
113117
114118< template>
119+ <!-- < v- btn @click= " console.log(agentStore.allTools)" >< / v- btn> -->
115120 < div v- if = " agentStore.getRevised" : key= " agentStore.getRevised" >
116121 < v- card : title= " $t('agent.config')" >
117122 < v- divider>< / v- divider>
@@ -150,7 +155,17 @@ function handleNameUpdate() {
150155 < / template>
151156 < / v- confirm- edit>
152157
153- < v- card v- if = " selectedTree" class = " mt-4" : title= " $t('agent.tools')" >
158+ < v- alert
159+ v- if = " !agentStore.hasTools"
160+ border= " top"
161+ type= " warning"
162+ variant= " outlined"
163+ prominent
164+ class = " mt-4"
165+ >
166+ {{ $t (' agent.no-tools' ) }}
167+ < / v- alert>
168+ < v- card v- else class = " mt-4" : title= " $t('agent.tools')" >
154169 < v- row dense>
155170 < v- divider>< / v- divider>
156171 < v- treeview
@@ -179,42 +194,34 @@ function handleNameUpdate() {
179194 < / div>
180195 < div class = " d-flex flex-wrap ga-1" >
181196 < v- scroll- x- transition group hide- on- leave>
182- < v- chip
183- v- for = " selection in selectedTree"
184- : key= " selection"
185- : text= " agentStore.getId(selection).name"
186- color= " grey"
187- size= " small"
188- border
189- closable
190- label
191- @click: close= " onClickClose(selection)"
192- >
193- < template #prepend>
194- < v- avatar
195- : text= " agentStore.getAbbr(agentStore.getId(selection).server)"
196- : color= " agentStore.getColor(selection)"
197- start
198- variant= " plain"
199- >
200- < / v- avatar>
201- < / template>
202- < / v- chip>
197+ < div v- for = " (selection, index) in selectedTree" : key= " index" >
198+ < v- chip
199+ v- if = " selection"
200+ : key= " selection"
201+ : text= " agentStore.getId(selection).name"
202+ color= " grey"
203+ size= " small"
204+ border
205+ closable
206+ label
207+ @click= " console.log(selection, index)"
208+ @click: close= " onClickClose(selection)"
209+ >
210+ < template #prepend>
211+ < v- avatar
212+ : text= " agentStore.getAbbr(agentStore.getId(selection).server)"
213+ : color= " agentStore.getColor(selection)"
214+ start
215+ variant= " plain"
216+ >
217+ < / v- avatar>
218+ < / template>
219+ < / v- chip>
220+ < / div>
203221 < / v- scroll- x- transition>
204222 < / div>
205223 < / v- card- text>
206224 < / v- row>
207-
208- <!-- < v- divider>< / v- divider>
209-
210- < template v- slot: actions>
211- < v- btn text= " Reset" @click= " selectedTree = []" >< / v- btn>
212-
213- < v- spacer>< / v- spacer>
214-
215- < v- btn append- icon= " mdi-content-save" color= " surface-light" text= " Save" variant= " flat" border>< / v- btn>
216- < v- btn @click= " console.log(agentStore.selected)" >< / v- btn>
217- < / template> -->
218225 < / v- card>
219226 < / div>
220227< / template>
0 commit comments