<template>
<div class="admin-tools-panel">
<div class="admin-tools-header">
<h2 class="admin-tools-title">Tools</h2>
<GnButton
variant="primary"
size="sm"
:loading="running"
@click="onReload"
>
{{ running ? 'Reloading…' : 'Reload tools' }}
</GnButton>
</div>
<p class="admin-tools-description">
Re-reads the tools in <code>tools/</code>, the context providers, and reconnects
every MCP server — no restart, no downtime. New tools are callable from the next
message of every session. Admin only: it swaps the toolset all profiles resolve against.
</p>
<div v-if="report" class="admin-tools-report" :class="{ 'has-problems': !report.ok }">
<div class="admin-tools-line">
<i class="ph ph-check-circle" aria-hidden="true"></i>
<span>
{{ report.tools.length }} tool{{ report.tools.length === 1 ? '' : 's' }} loaded
<template v-if="report.tools.length"> — {{ report.tools.join(', ') }}</template>
<span class="admin-tools-total">({{ report.total_tools }} in the registry)</span>
</span>
</div>
<div v-if="report.missing_enabled.length" class="admin-tools-line is-warning">
<i class="ph ph-warning" aria-hidden="true"></i>
<span>
<code>enabled.json</code> names {{ report.missing_enabled.join(', ') }} — no such tool
exists, so it is dropped from every profile.
</span>
</div>
<div v-for="(error, file) in report.tool_errors" :key="file" class="admin-tools-line is-error">
<i class="ph ph-x-circle" aria-hidden="true"></i>
<span><code>{{ file }}</code>: {{ error }}</span>
</div>
<div v-if="report.mcp_error" class="admin-tools-line is-error">
<i class="ph ph-x-circle" aria-hidden="true"></i>
<span>MCP reload failed: {{ report.mcp_error }}</span>
</div>
<div v-else class="admin-tools-line">
<i class="ph ph-plugs-connected" aria-hidden="true"></i>
<span>
{{ report.mcp_tools.length }} MCP tool{{ report.mcp_tools.length === 1 ? '' : 's' }} —
{{ report.providers.length }} context provider{{ report.providers.length === 1 ? '' : 's' }}
</span>
</div>
</div>
</div>
</template>
<script setup>
import { ref } from 'vue'
import { useToast } from 'gnexus-ui-kit/vue'
import { GnButton } from 'gnexus-ui-kit/vue'
import * as api from '@/api/index.js'
const toast = useToast()
const running = ref(false)
const report = ref(null)
async function onReload() {
running.value = true
try {
report.value = await api.reloadTools()
if (report.value.ok) {
toast.success({ title: `Reloaded ${report.value.tools.length} tool(s)` })
} else {
toast.error({ title: 'Reload finished with errors — see the panel' })
}
} catch (err) {
toast.error({ title: 'Failed to reload tools', text: err.message })
} finally {
running.value = false
}
}
</script>
<style scoped lang="scss">
@use 'kit-deps' as *;
.admin-tools-panel {
margin-bottom: 24px;
}
.admin-tools-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 12px;
}
.admin-tools-title {
font-size: 1.1rem;
font-weight: 600;
margin: 0;
color: var(--gn-color-text-medium);
}
.admin-tools-description {
margin: 0 0 16px;
font-size: 0.875rem;
color: var(--gn-color-text-medium);
code {
font-size: 0.8rem;
}
}
.admin-tools-report {
display: flex;
flex-direction: column;
gap: 6px;
padding: 12px;
border: 1px solid var(--gn-color-border);
border-radius: var(--gn-radius-md);
font-size: 0.85rem;
color: var(--gn-color-text-medium);
&.has-problems {
border-color: var(--gn-color-danger, var(--gn-color-border));
}
}
.admin-tools-line {
display: flex;
align-items: flex-start;
gap: 8px;
i {
flex-shrink: 0;
margin-top: 2px;
}
&.is-warning i {
color: var(--gn-color-warning, inherit);
}
&.is-error i {
color: var(--gn-color-danger, inherit);
}
code {
font-size: 0.8rem;
}
}
.admin-tools-total {
color: var(--gn-color-text-dimmed);
}
</style>