Merge branch 'worktree-agent-a559cecce669715a6'

This commit is contained in:
sam committed 2026-11-22 02:13:32 +11:00
commit 65a8b7cd47
5 files changed
+88 -1

No files matched your search

+22
View File
@@ -5480,6 +5480,28 @@ paths:
tags:
- Governance
/api/settings/agent-model:
delete:
operationId: delete-agent-model
parameters:
- description: Agent model alias; omit for the default model
explode: false
in: query
name: alias
schema:
description: Agent model alias; omit for the default model
type: string
responses:
"204":
description: No Content
default:
content:
application/problem+json:
schema:
$ref: "#/components/schemas/ErrorModel"
description: Error
summary: Delete an agent model
tags:
- Governance
get:
operationId: get-agent-model
parameters:
+19
View File
@@ -409,6 +409,10 @@ func (m *Module) Register(api huma.API) {
OperationID: "put-agent-model", Method: http.MethodPut, Path: "/api/settings/agent-model",
Summary: "Set the agent model", Tags: tags,
}, m.putAgentModel)
huma.Register(api, huma.Operation{
OperationID: "delete-agent-model", Method: http.MethodDelete, Path: "/api/settings/agent-model",
Summary: "Delete an agent model", Tags: tags, DefaultStatus: http.StatusNoContent,
}, m.deleteAgentModel)
huma.Register(api, huma.Operation{
OperationID: "test-agent-model", Method: http.MethodPost, Path: "/api/settings/agent-model/test",
Summary: "Ask a model one question before saving it", Tags: tags,
@@ -606,6 +610,21 @@ func (m *Module) putAgentModel(ctx context.Context, in *agentModelInput) (*httpa
return httpapi.OK(model), nil
}
func (m *Module) deleteAgentModel(ctx context.Context, in *agentModelAlias) (*struct{}, error) {
if err := ValidateAgentModelAlias(in.Alias); err != nil {
return nil, huma.NewError(http.StatusBadRequest, err.Error())
}
found, err := m.store.DeleteModelRole(ctx, m.orgID, agentModelRole(in.Alias))
if err != nil {
m.log.ErrorContext(ctx, "delete agent model", "error", err)
return nil, huma.NewError(http.StatusInternalServerError, "couldn't delete the agent model")
}
if !found {
return nil, huma.NewError(http.StatusNotFound, "no such agent model")
}
return nil, nil
}
// modelAnswer is a test call's answer.
type modelAnswer struct {
Model string `json:"model"`
@@ -71,6 +71,20 @@ func (s *Store) PutModelRole(ctx context.Context, m ModelRole) error {
return nil
}
// DeleteModelRole removes the organisation's model for role and reports
// whether one existed.
func (s *Store) DeleteModelRole(ctx context.Context, orgID, role string) (bool, error) {
res, err := s.db.ExecContext(ctx, `DELETE FROM governance.model_roles WHERE org_id = $1 AND role = $2`, orgID, role)
if err != nil {
return false, fmt.Errorf("delete model role %q: %w", role, err)
}
n, err := res.RowsAffected()
if err != nil {
return false, fmt.Errorf("delete model role %q: %w", role, err)
}
return n > 0, nil
}
// Settings is an organisation's settings as stored. A duration is kept in
// milliseconds: Postgres has no duration type that scans into one.
type Settings struct {
+2
View File
@@ -228,6 +228,8 @@ export const api = {
agentModels: () => request<Record<string, AgentModel>>("/api/settings/agent-models"),
putAgentModel: (alias: string, model: AgentModel) =>
request<AgentModel>("/api/settings/agent-model" + qs({ alias }), { method: "PUT", body: model }),
deleteAgentModel: (alias: string) =>
request<void>("/api/settings/agent-model" + qs({ alias }), { method: "DELETE", parse: false }),
testAgentModel: (model: AgentModel) =>
request<{ answer: string; model: string }>("/api/settings/agent-model/test", { method: "POST", body: model, timeoutMs: 60_000 }),
policyText: (kind: PolicyKind, version?: number) =>
+31 -1
View File
@@ -5,6 +5,7 @@ import { computed, onMounted, ref } from "vue";
import PageHeader from "@/base/PageHeader.vue";
import { Button } from "@/components/ui/button";
import { DataTable, type DataTableColumn } from "@/components/ui/data-table";
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from "@/components/ui/alert-dialog";
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
@@ -91,6 +92,20 @@ async function save(): Promise<void> {
busy.value = false;
}
}
const pending = ref<Row | null>(null);
const removeError = ref("");
async function remove(row: Row): Promise<void> {
busy.value = true;
removeError.value = "";
try {
await api.deleteAgentModel(row.alias === "default" ? "" : row.alias);
await reload();
} catch (cause) {
removeError.value = describeError(cause, errors.common.unknown);
} finally {
busy.value = false;
}
}
</script>
<template>
@@ -107,11 +122,26 @@ async function save(): Promise<void> {
<template #cell-base="{ row }"><span class="font-mono text-caption">{{ row.base_url }}</span></template>
<template #cell-key="{ row }">{{ row.api_key_credential }}</template>
<template #actions="{ row }">
<MoreMenu :label="`${row.alias} actions`"><DropdownMenuItem @select="open(row)">Edit</DropdownMenuItem></MoreMenu>
<MoreMenu :label="`${row.alias} actions`"><DropdownMenuItem @select="open(row)">Edit</DropdownMenuItem><DropdownMenuItem class="text-danger" @select="pending = row">Delete</DropdownMenuItem></MoreMenu>
</template>
<template #empty><Empty><EmptyHeader><EmptyTitle>No models</EmptyTitle></EmptyHeader></Empty></template>
</DataTable>
<p v-if="removeError" role="alert" class="pt-2 text-caption text-danger">{{ removeError }}</p>
<AlertDialog :open="pending !== null" @update:open="(v: boolean) => { if (!v) pending = null; }">
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Delete model?</AlertDialogTitle>
<AlertDialogDescription>Delete the alias "{{ pending?.alias }}"? Workflows that name it will fail.</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction @click="if (pending) { const row = pending; pending = null; void remove(row); }">Delete model</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
<Dialog v-model:open="editing">
<DialogContent class="sm:max-w-2xl">
<DialogHeader><DialogTitle>{{ isNew ? "Add model" : `Edit ${form.alias}` }}</DialogTitle></DialogHeader>