MCPcopy Create free account
hub / github.com/browserwing/browserwing / SaveExplorationScript

Method SaveExplorationScript

backend/api/handlers_explore.go:138–180  ·  view source on GitHub ↗

SaveExplorationScript saves the generated script to the database

(c *gin.Context)

Source from the content-addressed store, hash-verified

136
137// SaveExplorationScript saves the generated script to the database
138func (h *Handler) SaveExplorationScript(c *gin.Context) {
139 if h.explorer == nil {
140 c.JSON(http.StatusServiceUnavailable, gin.H{"error": "AI Explorer is not available"})
141 return
142 }
143
144 sessionID := c.Param("id")
145 session, ok := h.explorer.GetSession(sessionID)
146 if !ok {
147 c.JSON(http.StatusNotFound, gin.H{"error": "session not found"})
148 return
149 }
150
151 if session.GeneratedScript == nil {
152 c.JSON(http.StatusBadRequest, gin.H{"error": "no script to save"})
153 return
154 }
155
156 // Allow overriding name/description from request
157 var req struct {
158 Name string `json:"name"`
159 Description string `json:"description"`
160 }
161 if err := c.ShouldBindJSON(&req); err == nil {
162 if req.Name != "" {
163 session.GeneratedScript.Name = req.Name
164 }
165 if req.Description != "" {
166 session.GeneratedScript.Description = req.Description
167 }
168 }
169
170 if err := h.db.SaveScript(session.GeneratedScript); err != nil {
171 c.JSON(http.StatusInternalServerError, gin.H{"error": fmt.Sprintf("failed to save script: %v", err)})
172 return
173 }
174
175 c.JSON(http.StatusOK, gin.H{
176 "id": session.GeneratedScript.ID,
177 "name": session.GeneratedScript.Name,
178 "message": "Script saved successfully",
179 })
180}

Callers

nothing calls this directly

Calls 2

GetSessionMethod · 0.65
SaveScriptMethod · 0.65

Tested by

no test coverage detected