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

Method handleReadSession

pkg/runtime/sessioncontext_handlers.go:55–99  ·  view source on GitHub ↗
(ctx context.Context, sess *session.Session, toolCall tools.ToolCall, _ EventSink)

Source from the content-addressed store, hash-verified

53}
54
55func (r *LocalRuntime) handleReadSession(ctx context.Context, sess *session.Session, toolCall tools.ToolCall, _ EventSink) (*tools.ToolCallResult, error) {
56 if r.sessionStore == nil {
57 return tools.ResultError("session history is not available in this runtime"), nil
58 }
59
60 var args sessioncontext.ReadSessionArgs
61 if err := json.Unmarshal([]byte(toolCall.Function.Arguments), &args); err != nil {
62 return nil, fmt.Errorf("invalid arguments: %w", err)
63 }
64 ref := strings.TrimSpace(args.SessionID)
65 if ref == "" {
66 return tools.ResultError("session_id must not be empty"), nil
67 }
68
69 id, err := session.ResolveSessionID(ctx, r.sessionStore, ref)
70 if err != nil {
71 return tools.ResultError(fmt.Sprintf("cannot resolve session %q: %v", ref, err)), nil
72 }
73 if id == sess.ID {
74 return tools.ResultError("cannot read the current session; reference a different one"), nil
75 }
76
77 target, err := r.sessionStore.GetSession(ctx, id)
78 if errors.Is(err, session.ErrNotFound) {
79 return tools.ResultError(fmt.Sprintf("session %q not found", id)), nil
80 }
81 if err != nil {
82 return nil, fmt.Errorf("reading session %q: %w", id, err)
83 }
84
85 owned := target.GetAllMessages()
86 msgs := make([]chat.Message, 0, len(owned))
87 for i := range owned {
88 msgs = append(msgs, owned[i].Message)
89 }
90
91 transcript := sessioncontext.RenderTranscript(sessioncontext.Header{
92 ID: target.ID,
93 Title: target.Title,
94 CreatedAt: target.CreatedAt,
95 NumMessages: len(msgs),
96 }, msgs, sessioncontext.DefaultMaxChars)
97
98 return tools.ResultSuccess(transcript), nil
99}

Callers

nothing calls this directly

Calls 6

ResultErrorFunction · 0.92
ResolveSessionIDFunction · 0.92
RenderTranscriptFunction · 0.92
ResultSuccessFunction · 0.92
GetAllMessagesMethod · 0.80
GetSessionMethod · 0.65

Tested by

no test coverage detected