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

+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 {