Initial import — snapshot from admin host /srv/gosec/gsc-ops-api
This repo had no version control prior to this commit. The import is a
straight snapshot of the working tree at 2026-05-03; the deployed
binary on fihelvop01 was being rebuilt from this source via `make
build` + scp into place, with no upstream review path.
The snapshot already includes one in-flight fix made on 2026-05-03 to
internal/service/persona.go:GetSelfModel — the handler queried
`source` and `strength` columns plus an `is_active = true` filter on
persona.persona_commitments, none of which exist on that table (its
shape is session-bound commitments with `status`, `commitment_meta`,
etc.). The query returned a 500 every time SynapseHub bootstrapped a
persona's self-model, dropping the IdentityConstraints / Commitments /
ConscienceStandards layer from the assembled prompt. The patched
query reads existing columns only (commitment_text, commitment_type),
filters on `status='active'`, and synthesises Source="learned" /
Strength=1.0 to keep the SelfModel response shape stable for callers.
Verified live: `GET /api/v1/personas/70f7cfd9-.../self-model` now
returns 200 with `{identityConstraints:[],commitments:[],
conscienceStandards:[]}` instead of 500.
Future changes go through PRs against this repo — no more bin-only
deploys.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
98
internal/handler/personal_agent.go
Normal file
98
internal/handler/personal_agent.go
Normal file
@@ -0,0 +1,98 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/google/uuid"
|
||||
|
||||
"github.com/gosec/gsc-ops-api/internal/middleware"
|
||||
"github.com/gosec/gsc-ops-api/internal/service"
|
||||
"github.com/gosec/gsc-ops-api/pkg/types"
|
||||
)
|
||||
|
||||
// PersonalAgentHandler handles personal agent config endpoints
|
||||
type PersonalAgentHandler struct {
|
||||
svc *service.PersonalAgentService
|
||||
}
|
||||
|
||||
// NewPersonalAgentHandler creates a new personal agent handler
|
||||
func NewPersonalAgentHandler(svc *service.PersonalAgentService) *PersonalAgentHandler {
|
||||
return &PersonalAgentHandler{svc: svc}
|
||||
}
|
||||
|
||||
// GetMyConfig handles GET /api/v1/agents/me?userId=X&tenantId=Y
|
||||
func (h *PersonalAgentHandler) GetMyConfig(c *fiber.Ctx) error {
|
||||
reqID := middleware.GetRequestID(c)
|
||||
|
||||
userID, err := uuid.Parse(c.Query("userId"))
|
||||
if err != nil {
|
||||
apiErr := types.NewBadRequest("Invalid or missing userId")
|
||||
return c.Status(apiErr.Status).JSON(types.NewErrorResponse(apiErr, reqID))
|
||||
}
|
||||
|
||||
tenantID, err := uuid.Parse(c.Query("tenantId"))
|
||||
if err != nil {
|
||||
apiErr := types.NewBadRequest("Invalid or missing tenantId")
|
||||
return c.Status(apiErr.Status).JSON(types.NewErrorResponse(apiErr, reqID))
|
||||
}
|
||||
|
||||
config, err := h.svc.GetConfig(c.Context(), userID, tenantID)
|
||||
if err != nil {
|
||||
apiErr := types.NewNotFound("Personal agent config not found")
|
||||
return c.Status(apiErr.Status).JSON(types.NewErrorResponse(apiErr, reqID))
|
||||
}
|
||||
|
||||
return c.JSON(types.NewDataResponse(config, reqID))
|
||||
}
|
||||
|
||||
// UpsertMyConfig handles PUT /api/v1/agents/me
|
||||
func (h *PersonalAgentHandler) UpsertMyConfig(c *fiber.Ctx) error {
|
||||
reqID := middleware.GetRequestID(c)
|
||||
|
||||
var req types.UserAgentConfigUpsert
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
apiErr := types.NewBadRequest("Invalid request body: " + err.Error())
|
||||
return c.Status(apiErr.Status).JSON(types.NewErrorResponse(apiErr, reqID))
|
||||
}
|
||||
|
||||
if req.UserID == uuid.Nil || req.TenantID == uuid.Nil {
|
||||
apiErr := types.NewValidation("userId and tenantId are required")
|
||||
return c.Status(apiErr.Status).JSON(types.NewErrorResponse(apiErr, reqID))
|
||||
}
|
||||
|
||||
if len(req.Config) == 0 {
|
||||
apiErr := types.NewValidation("config is required")
|
||||
return c.Status(apiErr.Status).JSON(types.NewErrorResponse(apiErr, reqID))
|
||||
}
|
||||
|
||||
config, err := h.svc.UpsertConfig(c.Context(), &req)
|
||||
if err != nil {
|
||||
apiErr := types.NewInternal(err.Error())
|
||||
return c.Status(apiErr.Status).JSON(types.NewErrorResponse(apiErr, reqID))
|
||||
}
|
||||
|
||||
return c.JSON(types.NewDataResponse(config, reqID))
|
||||
}
|
||||
|
||||
// DeleteMyConfig handles DELETE /api/v1/agents/me?userId=X&tenantId=Y
|
||||
func (h *PersonalAgentHandler) DeleteMyConfig(c *fiber.Ctx) error {
|
||||
reqID := middleware.GetRequestID(c)
|
||||
|
||||
userID, err := uuid.Parse(c.Query("userId"))
|
||||
if err != nil {
|
||||
apiErr := types.NewBadRequest("Invalid or missing userId")
|
||||
return c.Status(apiErr.Status).JSON(types.NewErrorResponse(apiErr, reqID))
|
||||
}
|
||||
|
||||
tenantID, err := uuid.Parse(c.Query("tenantId"))
|
||||
if err != nil {
|
||||
apiErr := types.NewBadRequest("Invalid or missing tenantId")
|
||||
return c.Status(apiErr.Status).JSON(types.NewErrorResponse(apiErr, reqID))
|
||||
}
|
||||
|
||||
if err := h.svc.DeleteConfig(c.Context(), userID, tenantID); err != nil {
|
||||
apiErr := types.NewNotFound("Personal agent config not found")
|
||||
return c.Status(apiErr.Status).JSON(types.NewErrorResponse(apiErr, reqID))
|
||||
}
|
||||
|
||||
return c.SendStatus(fiber.StatusNoContent)
|
||||
}
|
||||
Reference in New Issue
Block a user