Change summary
internal/server/proto.go | 15 +++++++++------
internal/session/session_test.go | 2 +-
2 files changed, 10 insertions(+), 7 deletions(-)
Detailed changes
@@ -461,14 +461,19 @@ func (c *controllerV1) handleDeleteWorkspaceSession(w http.ResponseWriter, r *ht
w.WriteHeader(http.StatusOK)
}
+// updateSessionModelsRequest is the request body for updating session models.
+type updateSessionModelsRequest struct {
+ Models map[config.SelectedModelType]config.SelectedModel `json:"models"`
+}
+
// handlePostWorkspaceSessionModels updates the models for a session.
//
// @Summary Update session models
// @Tags sessions
// @Accept json
-// @Param id path string true "Workspace ID"
-// @Param sid path string true "Session ID"
-// @Param body body object true "Models" example({"models":{"large":{"model":"gpt-4o","provider":"openai"}}})
+// @Param id path string true "Workspace ID"
+// @Param sid path string true "Session ID"
+// @Param body body updateSessionModelsRequest true "Models"
// @Success 204
// @Failure 400 {object} proto.Error
// @Failure 500 {object} proto.Error
@@ -477,9 +482,7 @@ func (c *controllerV1) handlePostWorkspaceSessionModels(w http.ResponseWriter, r
workspaceID := r.PathValue("id")
sessionID := r.PathValue("sid")
- var req struct {
- Models map[config.SelectedModelType]config.SelectedModel `json:"models"`
- }
+ var req updateSessionModelsRequest
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
c.server.logError(r, "Failed to decode request", "error", err)
jsonError(w, http.StatusBadRequest, "failed to decode request")
@@ -114,7 +114,7 @@ func TestFromDBItemWithModels(t *testing.T) {
t.Run("empty models", func(t *testing.T) {
t.Parallel()
item := testDBSession()
- item.Models = sql.NullString{String: "", Valid: false}
+ item.Models = sql.NullString{String: "", Valid: true}
result := service{}.fromDBItem(item)
require.Nil(t, result.Models)
})