MCPcopy Create free account
hub / github.com/docker/docker-agent / forkSession

Method forkSession

pkg/server/server.go:248–275  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

246// new session uses a fork-numbered title and starts with no runtime
247// attached.
248func (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
277func (s *Server) getSession(c echo.Context) error {
278 sess, err := s.sm.GetSession(c.Request().Context(), c.Param("id"))

Callers

nothing calls this directly

Calls 4

ForkSessionMethod · 0.80
ContextMethod · 0.80
GetAllMessagesMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected