forkSession creates a new session whose history is a deep copy of an existing session up to (but excluding) the Nth user message. The new session uses a fork-numbered title and starts with no runtime attached.
(c echo.Context)
| 246 | // new session uses a fork-numbered title and starts with no runtime |
| 247 | // attached. |
| 248 | func (s *Server) forkSession(c echo.Context) error { |
| 249 | var req api.ForkSessionRequest |
| 250 | if err := c.Bind(&req); err != nil { |
| 251 | return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("invalid request body: %v", err)) |
| 252 | } |
| 253 | |
| 254 | forked, err := s.sm.ForkSession(c.Request().Context(), c.Param("id"), req.UserMessageIndex) |
| 255 | if err != nil { |
| 256 | switch { |
| 257 | case errors.Is(err, ErrForkOutOfRange), |
| 258 | errors.Is(err, ErrForkInSubSession): |
| 259 | return echo.NewHTTPError(http.StatusBadRequest, err.Error()) |
| 260 | } |
| 261 | return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("failed to fork session: %v", err)) |
| 262 | } |
| 263 | |
| 264 | return c.JSON(http.StatusOK, api.SessionResponse{ |
| 265 | ID: forked.ID, |
| 266 | Title: forked.Title, |
| 267 | CreatedAt: forked.CreatedAt, |
| 268 | Messages: forked.GetAllMessages(), |
| 269 | ToolsApproved: forked.ToolsApproved, |
| 270 | InputTokens: forked.InputTokens, |
| 271 | OutputTokens: forked.OutputTokens, |
| 272 | WorkingDir: forked.WorkingDir, |
| 273 | Permissions: forked.Permissions, |
| 274 | }) |
| 275 | } |
| 276 | |
| 277 | func (s *Server) getSession(c echo.Context) error { |
| 278 | sess, err := s.sm.GetSession(c.Request().Context(), c.Param("id")) |
nothing calls this directly
no test coverage detected