generateTitle generates a title for a session using the sessiontitle package. The generated title is stored in the session and persisted to the store. A SessionTitleEvent is emitted to notify clients.
(ctx context.Context, sess *session.Session, gen *sessiontitle.Generator, userMessages []string, events chan<- runtime.Event)
| 880 | // The generated title is stored in the session and persisted to the store. |
| 881 | // A SessionTitleEvent is emitted to notify clients. |
| 882 | func (sm *SessionManager) generateTitle(ctx context.Context, sess *session.Session, gen *sessiontitle.Generator, userMessages []string, events chan<- runtime.Event) { |
| 883 | if gen == nil || len(userMessages) == 0 { |
| 884 | return |
| 885 | } |
| 886 | |
| 887 | title, err := gen.Generate(ctx, sess.ID, userMessages) |
| 888 | if err != nil { |
| 889 | slog.ErrorContext(ctx, "Failed to generate session title", "session_id", sess.ID, "error", err) |
| 890 | return |
| 891 | } |
| 892 | |
| 893 | if title == "" { |
| 894 | return |
| 895 | } |
| 896 | |
| 897 | // Update the in-memory session |
| 898 | sess.Title = title |
| 899 | |
| 900 | // Persist the title |
| 901 | if err := sm.sessionStore.UpdateSession(ctx, sess); err != nil { |
| 902 | slog.ErrorContext(ctx, "Failed to persist generated title", "session_id", sess.ID, "error", err) |
| 903 | return |
| 904 | } |
| 905 | |
| 906 | // Emit the title event |
| 907 | select { |
| 908 | case events <- runtime.SessionTitle(sess.ID, title): |
| 909 | slog.DebugContext(ctx, "Generated and emitted session title", "session_id", sess.ID, "title", title) |
| 910 | case <-ctx.Done(): |
| 911 | slog.DebugContext(ctx, "Context cancelled while emitting title event", "session_id", sess.ID) |
| 912 | } |
| 913 | } |
| 914 | |
| 915 | func (sm *SessionManager) runtimeForSession(ctx context.Context, sess *session.Session, agentFilename, currentAgent string, rc *config.RuntimeConfig) (_ runtime.Runtime, _ *sessiontitle.Generator, err error) { |
| 916 | // Caller (RunSession) holds sm.mux and has already verified that no |
no test coverage detected