MCPcopy Index your code
hub / github.com/docker/docker-agent / resolveSession

Method resolveSession

pkg/chatserver/server.go:436–451  ·  view source on GitHub ↗

resolveSession decides whether to start fresh or continue an existing conversation. When X-Conversation-Id is set and we have an existing session for it, we work on a deep copy and append only the latest user message from the request (the prior history is already in the session). The cached session

(id string, msgs []ChatCompletionMessage)

Source from the content-addressed store, hash-verified

434// which case the caller rejects the request rather than replaying the
435// prior turn.
436func (s *server) resolveSession(id string, msgs []ChatCompletionMessage) (*session.Session, error) {
437 if id != "" {
438 if existing := s.conversations.Get(id); existing != nil {
439 working := existing.Clone()
440 if !appendLatestUser(working, msgs) {
441 return nil, errors.New("no user message provided")
442 }
443 return working, nil
444 }
445 }
446 sess := buildSession(msgs)
447 if sess == nil {
448 return nil, errors.New("no user message provided")
449 }
450 return sess, nil
451}
452
453// commitConversation stores the session into the cache after a run, but
454// only when the run succeeded. A failed turn must not advance the cached

Calls 5

appendLatestUserFunction · 0.85
buildSessionFunction · 0.85
GetMethod · 0.65
CloneMethod · 0.45
NewMethod · 0.45