Skip to content

SummaryGenerator ​

Category: Agent

Source: summary_generator.dart

Classes ​

abstract SummaryGenerator ​

Shared machinery for the small-model one-liner generators.

[TitleGenerator] names a session; [RecapGenerator] says what has happened in it so far. They differ only in system prompt and length ceiling — the context blob, streaming, sanitization and error handling live here.

Constructor ​

dart
SummaryGenerator({
    required LlmClient llmClient,
    required this.maxLength,
    required this.fieldLimit,
    this.onUsage,
  })

Properties ​

PropertyTypeDescription
maxLengthintCeiling on the sanitized output, ellipsis included.
fieldLimitintPer-field cap on the context blob interpolated into the user message.
timeoutconstDeadline for the whole generation. These are background niceties — a hung provider stream must not leave a session titleless forever.

Methods ​

void Function(UsageInfo) ​

Optional per-call usage callback. Surfaces wire this to SessionManager.recordUsage(stats, role: 'title' | 'recap') so the small-model cost is accounted for in session totals.

Future<String?> generateFromContext(TitleContext context) ​

Generate from the compact tagged view of the conversation.

Returns null if generation fails for any reason.

static String? sanitizeTo(String? raw, int maxLength) ​

Clean a model response into a single printable line of at most [maxLength] characters, ellipsis included.

Collapses whitespace, drops control/combining/emoji codepoints, strips the quotes models like to wrap one-line answers in, and cuts on a word boundary when it has to cut. Returns null if nothing survives.

TitleGenerator ​

Generates short session titles using an [LlmClient].

Constructor ​

dart
TitleGenerator({required super.llmClient, super.onUsage})

Properties ​

PropertyTypeDescription
systemPromptconst

Methods ​

Future<String?> generate(String userMessage) ​

Generate a title from the first user message, before any reply exists.

static String? sanitize(String? raw) ​

Sanitize a title to a single printable line of at most 60 characters.

RecapGenerator ​

Generates a one-line session recap using a small [LlmClient].

Companion to [TitleGenerator]: titles describe what a session is about, recaps describe what has happened in it so far.

Constructor ​

dart
RecapGenerator({required super.llmClient, super.onUsage})

Properties ​

PropertyTypeDescription
systemPromptconst

Methods ​

static String? sanitize(String? raw) ​

Sanitize a recap to a single printable line of at most 200 characters.

Released under the MIT License.