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

Function cloneChatMessage

pkg/session/session.go:453–494  ·  view source on GitHub ↗

cloneChatMessage returns a deep copy of a chat.Message, duplicating all slice and pointer fields that would otherwise alias the original.

(m chat.Message)

Source from the content-addressed store, hash-verified

451// cloneChatMessage returns a deep copy of a chat.Message, duplicating
452// all slice and pointer fields that would otherwise alias the original.
453func cloneChatMessage(m chat.Message) chat.Message {
454 if m.MultiContent != nil {
455 orig := m.MultiContent
456 m.MultiContent = make([]chat.MessagePart, len(orig))
457 for i, part := range orig {
458 if part.ImageURL != nil {
459 imgCopy := *part.ImageURL
460 part.ImageURL = &imgCopy
461 }
462 if part.File != nil {
463 fileCopy := *part.File
464 part.File = &fileCopy
465 }
466 if part.Document != nil {
467 docCopy := *part.Document
468 if part.Document.Source.InlineData != nil {
469 docCopy.Source.InlineData = slices.Clone(part.Document.Source.InlineData)
470 }
471 part.Document = &docCopy
472 }
473 m.MultiContent[i] = part
474 }
475 }
476 if m.FunctionCall != nil {
477 fcCopy := *m.FunctionCall
478 m.FunctionCall = &fcCopy
479 }
480 if m.ToolCalls != nil {
481 m.ToolCalls = slices.Clone(m.ToolCalls)
482 }
483 if m.ToolDefinitions != nil {
484 m.ToolDefinitions = cloneToolDefinitions(m.ToolDefinitions)
485 }
486 if m.Usage != nil {
487 usageCopy := *m.Usage
488 m.Usage = &usageCopy
489 }
490 if m.ThoughtSignature != nil {
491 m.ThoughtSignature = slices.Clone(m.ThoughtSignature)
492 }
493 return m
494}
495
496func cloneToolDefinitions(src []tools.Tool) []tools.Tool {
497 if src == nil {

Callers 1

cloneMessageFunction · 0.85

Calls 2

cloneToolDefinitionsFunction · 0.85
CloneMethod · 0.45

Tested by

no test coverage detected