56 lines
3.1 KiB
Vue
56 lines
3.1 KiB
Vue
<script setup lang="ts">
|
|
import { computed, onMounted, ref } from "vue";
|
|
import PageHeader from "@/base/PageHeader.vue";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Input } from "@/components/ui/input";
|
|
import { SettingRow } from "@/components/ui/setting-row";
|
|
import { useSettingsStore } from "@/stores/settings";
|
|
import ApplyStatusRows from "./ApplyStatusRows.vue";
|
|
import CardAccordion from "./CardAccordion.vue";
|
|
import HistoryLink from "./HistoryLink.vue";
|
|
|
|
interface Profile { image?: string; kit?: string; adapter?: string; tools?: string[] }
|
|
const KIND = "agent-profiles";
|
|
const store = useSettingsStore();
|
|
onMounted(store.load);
|
|
const profiles = computed(() => store.drafts[KIND]?.value as Record<string, Profile> | null);
|
|
const name = ref("");
|
|
const open = ref("");
|
|
const unsaved = computed(() => store.changesFor(KIND).length > 0);
|
|
const entries = computed(() => Object.entries(profiles.value ?? {}));
|
|
function add() {
|
|
if (unsaved.value) return;
|
|
const key = name.value.trim();
|
|
if (!key || profiles.value?.[key]) return;
|
|
const draft = store.drafts[KIND];
|
|
if (!draft) return;
|
|
if (!draft.value) draft.value = {};
|
|
(draft.value as Record<string, Profile>)[key] = { image: "", kit: "", adapter: "", tools: [] };
|
|
name.value = "";
|
|
open.value = String(Object.keys(draft.value as Record<string, Profile>).indexOf(key));
|
|
}
|
|
function tools(profile: Profile, value: string | number) {
|
|
profile.tools = String(value).split(",").map(tool => tool.trim()).filter(Boolean);
|
|
}
|
|
</script>
|
|
<template>
|
|
<div>
|
|
<PageHeader title="Agent profiles"><HistoryLink :kinds="[KIND]" /></PageHeader>
|
|
<ApplyStatusRows :kind="KIND" class="mb-4" />
|
|
<p v-if="store.catalogError || store.pageErrorFor(KIND)" class="mb-4 text-sm text-destructive" role="alert">{{ store.catalogError || store.pageErrorFor(KIND) }}</p>
|
|
<form class="mb-4 flex gap-2" @submit.prevent="add">
|
|
<Input v-model="name" aria-label="Profile name" placeholder="Profile name" class="max-w-xs" :disabled="unsaved" />
|
|
<Button type="submit" :disabled="unsaved || !name.trim() || !!profiles?.[name.trim()]">Add profile</Button>
|
|
</form>
|
|
<p v-if="!Object.keys(profiles ?? {}).length" class="text-sm text-fg-muted">No agent profiles.</p>
|
|
<CardAccordion v-model:open="open" :items="entries" :title="([key]) => key" remove-label="Remove" mono @remove="delete profiles![entries[$event]![0]]">
|
|
<template #default="{ item: [key, profile] }">
|
|
<SettingRow label="Image" :for="`${key}-image`"><Input :id="`${key}-image`" v-model="profile.image" placeholder="Container image" /></SettingRow>
|
|
<SettingRow label="Kit" :for="`${key}-kit`" hint="Pinned digest. Used only when Image is empty."><Input :id="`${key}-kit`" v-model="profile.kit" placeholder="registry/kit@sha256:…" /></SettingRow>
|
|
<SettingRow label="Adapter" :for="`${key}-adapter`"><Input :id="`${key}-adapter`" v-model="profile.adapter" /></SettingRow>
|
|
<SettingRow label="Tools" :for="`${key}-tools`" hint="Comma-separated tool names."><Input :id="`${key}-tools`" :model-value="(profile.tools ?? []).join(', ')" @update:model-value="tools(profile, $event)" /></SettingRow>
|
|
</template>
|
|
</CardAccordion>
|
|
</div>
|
|
</template>
|