Skip to content

SessionManager

Category: Session

Source: session_manager.dart

Enums

SessionReplayKind

ValueDescription
user
assistant
toolCall
toolResult
subagentSpawned
subagentEvent
subagentCompleted

Classes

SessionReplayEntry

Constructor

dart
factory SessionReplayEntry.user(String text)
dart
factory SessionReplayEntry.assistant(String text)
dart
factory SessionReplayEntry.toolCall(
    String name,
    Map<String, dynamic> arguments,
  )
dart
factory SessionReplayEntry.toolResult(String text)
dart
factory SessionReplayEntry.subagentSpawned({
    required String subagentId,
    required String task,
    int? index,
    int? total,
  })
dart
factory SessionReplayEntry.subagentEvent({
    required String subagentId,
    required SessionReplayEntry inner,
  })
dart
factory SessionReplayEntry.subagentCompleted({
    required String subagentId,
    String? error,
  })

Properties

PropertyTypeDescription
kindSessionReplayKind
textString
toolNameString?
toolArgumentsMap&lt;String, dynamic&gt;?
subagentIdString?
subagentIndexint?
subagentTotalint?
subagentInnerSessionReplayEntry?
subagentErrorString?

SessionReplay

Constructor

dart
const SessionReplay({
    required this.entries,
    required this.userCount,
    required this.assistantCount,
    required this.totalUsage,
    this.firstUserMessage,
    this.latestUserMessage,
    this.firstAssistantMessage,
    this.latestAssistantMessage,
    this.toolNames = const [],
  })

Properties

PropertyTypeDescription
entriesList&lt;SessionReplayEntry&gt;
userCountint
assistantCountint
firstUserMessageString?
latestUserMessageString?
firstAssistantMessageString?
latestAssistantMessageString?
toolNamesList&lt;String&gt;
totalUsageUsageReportPer-role token totals aggregated from persisted usage JSONL rows. Always non-null but may have an empty rows list when no usage was ever recorded (Ollama session, very old session predating recordUsage).

SessionResumeResult

Constructor

dart
const SessionResumeResult({
    required this.message,
    required this.hasConversation,
    required this.replay,
  })

Properties

PropertyTypeDescription
messageString
hasConversationbool
replaySessionReplay

SessionForkResult

Constructor

dart
const SessionForkResult({
    required this.message,
    required this.draftText,
    required this.replay,
  })

Properties

PropertyTypeDescription
messageString
draftTextString
replaySessionReplay

TitleContext

Handles session lifecycle operations independent of UI rendering.

Constructor

dart
const TitleContext({
    this.firstUserMessage,
    this.latestUserMessage,
    this.firstAssistantMessage,
    this.latestAssistantMessage,
    this.toolNames = const [],
    this.cwdBasename,
  })

Properties

PropertyTypeDescription
firstUserMessageString?
latestUserMessageString?
firstAssistantMessageString?
latestAssistantMessageString?
toolNamesList&lt;String&gt;
cwdBasenameString?

SessionManager

Constructor

dart
SessionManager({
    required this.environment,
    SessionStore? sessionStore,
    Observability? observability,
  })

Properties

PropertyTypeDescription
environmentEnvironment
titleInitialRequestedbool
titleReevaluationRequestedbool
titleManuallyOverriddenbool
currentStoreSessionStore? get
currentSessionIdSessionId? get
currentStoreSessionStore? get
currentSessionIdSessionId? get

Methods

void markManuallyRenamed()

Marks the session as manually renamed (e.g., from /rename). Sets all three flags so background title generation does not overwrite the user-chosen title.

List&lt;SessionMeta&gt; listSessions()
`SessionStore ensureSessionStore({
required String cwd,
required String modelRef,

})`

void switchToSessionStore(SessionMeta meta)
void updateSessionModel({required String modelRef})
void logEvent(String type, Map&lt;String, dynamic&gt; data)
void recordUsage(UsageStats stats, {required String role})

Records [stats] against the current session under [role] (e.g. 'main', 'subagent', 'title'). Updates the persisted token counters on SessionMeta and writes a usage JSONL row so a surface or replay can attribute costs to where they came from.

No-op when no session store is active.

Future&lt;void&gt; closeCurrent()
`Future<void> generateTitle({
required String userMessage,
required Future&lt;String?&gt; Function(String userMessage) generate,

})`

Future&lt;void&gt; renameTitle(String title)
`Future<void> reevaluateTitle({
required TitleContext context,
required Future&lt;String?&gt; Function(TitleContext context) generate,

})`

`SessionResumeResult resumeSession({
required SessionMeta session,
required AgentCore agent,

})`

`SessionForkResult? forkSession({
required int userMessageIndex,
required String messageText,
required AgentCore agent,

})`

Released under the MIT License.