mirror of
https://github.com/baserow/baserow.git
synced 2026-12-05 00:38:35 +00:00
Each Agent tool declares the tools that give the model an input it can't get otherwise, like get_table_schema for create_rows. Saving allowed tools without them is refused, Kuma refuses such a grant, and the tool permissions modal allows them along with the tool and locks them while it is allowed. Each section of the modal gets a Select all and Deselect all button.
255 lines
8.0 KiB
Vue
255 lines
8.0 KiB
Vue
<template>
|
|
<Modal ref="modal" small>
|
|
<template #content>
|
|
<h2 class="box__title">{{ $t('agent.toolPermissions') }}</h2>
|
|
<p class="agent-tool-permissions__description">
|
|
{{ $t('agent.toolPermissionsDescription', { name: agentName }) }}
|
|
</p>
|
|
<div
|
|
v-for="group in groups"
|
|
:key="group.type"
|
|
class="agent-tool-permissions__group"
|
|
>
|
|
<div class="agent-tool-permissions__group-name">
|
|
<i :class="group.icon"></i>
|
|
{{ group.label }}
|
|
</div>
|
|
<p class="agent-tool-permissions__summary">
|
|
{{
|
|
$t('agent.toolsAskFirstSummary', {
|
|
on: group.tools.filter((tool) => picked.has(tool.name)).length,
|
|
total: group.tools.filter((tool) => !tool.deactivated).length,
|
|
count: group.tools.filter((tool) => askFirst.has(tool.name))
|
|
.length,
|
|
})
|
|
}}
|
|
</p>
|
|
<div
|
|
v-for="kind in kindsOf(group)"
|
|
:key="kind.label"
|
|
class="agent-tool-permissions__list"
|
|
>
|
|
<div class="agent-tool-permissions__list-head">
|
|
<span>{{ kind.label }}</span>
|
|
<Button
|
|
v-if="editable && usableIn(kind).length"
|
|
type="secondary"
|
|
size="small"
|
|
class="agent-tool-permissions__select-all"
|
|
@click="allowAll(kind, !allAllowed(kind))"
|
|
>{{
|
|
$t(
|
|
allAllowed(kind)
|
|
? 'agent.deselectAllTools'
|
|
: 'agent.selectAllTools'
|
|
)
|
|
}}</Button
|
|
>
|
|
<div class="agent-tool-permissions__columns">
|
|
<span>{{ $t('agent.toolAllow') }}</span>
|
|
<span>{{ $t('agent.toolAskFirst') }}</span>
|
|
</div>
|
|
</div>
|
|
<div
|
|
v-for="tool in kind.tools"
|
|
:key="tool.name"
|
|
class="agent-tool-permissions__tool"
|
|
>
|
|
<div>
|
|
<div class="agent-tool-permissions__tool-name">
|
|
{{ tool.label }}
|
|
</div>
|
|
<div
|
|
v-if="tool.description"
|
|
class="agent-tool-permissions__tool-description"
|
|
>
|
|
{{ tool.description }}
|
|
</div>
|
|
</div>
|
|
<div class="agent-tool-permissions__columns">
|
|
<button
|
|
v-if="tool.deactivatedClickModal"
|
|
type="button"
|
|
class="agent-tool-permissions__locked agent-tool-permissions__locked--button"
|
|
:aria-label="$t('agent.toolLocked', { name: tool.label })"
|
|
@click="deactivatedModals[tool.name].show()"
|
|
>
|
|
<i class="iconoir-lock" aria-hidden="true"></i>
|
|
</button>
|
|
<i
|
|
v-else-if="tool.deactivated"
|
|
class="agent-tool-permissions__locked iconoir-lock"
|
|
role="img"
|
|
:aria-label="$t('agent.toolLocked', { name: tool.label })"
|
|
></i>
|
|
<template v-else>
|
|
<Checkbox
|
|
v-tooltip="requiredByText(tool.name)"
|
|
class="agent-tool-permissions__allow"
|
|
:model-value="picked.has(tool.name)"
|
|
:disabled="!editable || requiring.has(tool.name)"
|
|
@update:model-value="allow(tool.name, $event)"
|
|
>{{ tool.label
|
|
}}<template v-if="requiring.has(tool.name)"
|
|
>, {{ requiredByText(tool.name) }}</template
|
|
></Checkbox
|
|
>
|
|
<Checkbox
|
|
class="agent-tool-permissions__ask-first"
|
|
:model-value="askFirst.has(tool.name)"
|
|
:disabled="!editable || !picked.has(tool.name)"
|
|
@update:model-value="setAskFirst(tool.name, $event)"
|
|
>{{
|
|
$t('agent.toolAskFirstLabel', { name: tool.label })
|
|
}}</Checkbox
|
|
>
|
|
</template>
|
|
</div>
|
|
<component
|
|
:is="tool.deactivatedClickModal[0]"
|
|
v-if="tool.deactivatedClickModal"
|
|
:ref="(modal) => (deactivatedModals[tool.name] = modal)"
|
|
:workspace="workspace"
|
|
v-bind="tool.deactivatedClickModal[1]"
|
|
/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="agent-tool-permissions__actions">
|
|
<Button type="secondary" button-type="button" @click="modal.hide()">
|
|
{{ $t(editable ? 'action.cancel' : 'agent.toolsClose') }}
|
|
</Button>
|
|
<Button
|
|
v-if="editable"
|
|
type="primary"
|
|
button-type="button"
|
|
@click="done"
|
|
>
|
|
{{ $t('agent.toolsDone') }}
|
|
</Button>
|
|
</div>
|
|
</template>
|
|
</Modal>
|
|
</template>
|
|
|
|
<script setup>
|
|
import { useNuxtApp } from '#app'
|
|
import { computed, ref } from 'vue'
|
|
import { useI18n } from 'vue-i18n'
|
|
import {
|
|
agentToolLabel,
|
|
agentToolsRequiring,
|
|
groupAgentTools,
|
|
nextAskFirst,
|
|
requiredAgentTools,
|
|
} from '@baserow/modules/agent/agentTools'
|
|
|
|
/** Picks an Agent's tools and which ask first, saved only on Done. */
|
|
const props = defineProps({
|
|
availableTools: { type: Array, required: true },
|
|
allowedTools: { type: Array, required: true },
|
|
askFirstTools: { type: Array, required: true },
|
|
agentName: { type: String, required: true },
|
|
editable: { type: Boolean, required: true },
|
|
/** The Agent's workspace, for the modal of a tool it can't use. */
|
|
workspace: { type: Object, default: null },
|
|
})
|
|
const emit = defineEmits(['save'])
|
|
const { t } = useI18n()
|
|
const { $registry } = useNuxtApp()
|
|
|
|
const modal = ref(null)
|
|
const picked = ref(new Set())
|
|
const askFirst = ref(new Set())
|
|
const deactivatedModals = {}
|
|
const groups = computed(() =>
|
|
groupAgentTools(props.availableTools, $registry, t)
|
|
)
|
|
const requiring = computed(() =>
|
|
agentToolsRequiring(props.availableTools, picked.value)
|
|
)
|
|
|
|
function requiredByText(name) {
|
|
const names = requiring.value.get(name)
|
|
if (!names) return null
|
|
return t('agent.toolRequiredBy', {
|
|
names: names.map((n) => agentToolLabel(n, $registry, t)).join(', '),
|
|
})
|
|
}
|
|
|
|
function withRequired(names) {
|
|
return new Set([...names, ...requiredAgentTools(props.availableTools, names)])
|
|
}
|
|
|
|
const usableIn = (kind) => kind.tools.filter((tool) => !tool.deactivated)
|
|
const allAllowed = (kind) =>
|
|
usableIn(kind).every((tool) => picked.value.has(tool.name))
|
|
|
|
function kindsOf(group) {
|
|
return [
|
|
{
|
|
label: t('agent.toolsReads'),
|
|
tools: group.tools.filter((tool) => !tool.changesData),
|
|
},
|
|
{
|
|
label: t('agent.toolsChanges'),
|
|
tools: group.tools.filter((tool) => tool.changesData),
|
|
},
|
|
].filter((kind) => kind.tools.length)
|
|
}
|
|
|
|
/** Allow exactly these tools and the ones they require. */
|
|
function pick(names) {
|
|
const next = withRequired(names)
|
|
askFirst.value = new Set(
|
|
nextAskFirst(props.availableTools, picked.value, askFirst.value, next)
|
|
)
|
|
picked.value = next
|
|
}
|
|
|
|
function allow(name, allowed) {
|
|
if (!props.editable) return
|
|
pick(
|
|
allowed
|
|
? [...picked.value, name]
|
|
: [...picked.value].filter((other) => other !== name)
|
|
)
|
|
}
|
|
|
|
function allowAll(kind, allowed) {
|
|
if (!props.editable) return
|
|
const names = usableIn(kind).map((tool) => tool.name)
|
|
pick(
|
|
allowed
|
|
? [...picked.value, ...names]
|
|
: [...picked.value].filter((name) => !names.includes(name))
|
|
)
|
|
}
|
|
|
|
function setAskFirst(name, value) {
|
|
if (!props.editable || !picked.value.has(name)) return
|
|
const next = new Set(askFirst.value)
|
|
if (value) next.add(name)
|
|
else next.delete(name)
|
|
askFirst.value = next
|
|
}
|
|
|
|
function show() {
|
|
picked.value = withRequired(props.allowedTools)
|
|
askFirst.value = new Set(props.askFirstTools)
|
|
modal.value.show()
|
|
}
|
|
|
|
function done() {
|
|
if (!props.editable) return
|
|
const names = props.availableTools.map((tool) => tool.name)
|
|
emit('save', {
|
|
allowed_tools: names.filter((name) => picked.value.has(name)),
|
|
ask_first_tools: names.filter((name) => askFirst.value.has(name)),
|
|
})
|
|
modal.value.hide()
|
|
}
|
|
|
|
defineExpose({ show })
|
|
</script>
|