SessionTitleInvalidError narrows the one rename failure that blames the input; the fallback-unpin append extracts to appendFallback beside ensureFallback's guarded twin; a deferred-provider test proves rename supersedes ACTIVE generation; the invariant companion enforces messageSeqs-empty iff user-source on every appended session/title event (tsconfig gains the session-title invariant path); SessionTitleEventData field docs state the third source kind and the empty-seqs rule, mirrored into the bilingual core-data-structures page; the note qualifies the refresh unpin as conditional on a derivable replacement.
147 lines
5.6 KiB
Markdown
147 lines
5.6 KiB
Markdown
# Session Titles
|
|
|
|
English | [中文](session-title.zh.md)
|
|
|
|
Durable latest-wins title state and the optional asynchronous provider vocabulary owned by [`@deepseek-ai/dsh-session-title`](../../packages/session-title/session-title). The shared LLM helper owns the exact auxiliary request record. Package READMEs own timing, fallback, failure, and fork behavior; the generated [persistence catalog](../persistence-catalog.md) owns the complete event declarations.
|
|
|
|
Sources: [`packages/session-title/session-title/src/index.ts`](../../packages/session-title/session-title/src/index.ts), [`packages/session-title/session-title-llm/src/index.ts`](../../packages/session-title/session-title-llm/src/index.ts)
|
|
|
|
## Durable title state
|
|
|
|
`SessionTitleProviderId` is recorded for provider-produced revisions. `SessionTitleEventData` carries exact human-message provenance, while `SessionTitleSnapshot` adds the durable event envelope facts selected by `foldSessionTitle()`.
|
|
|
|
```ts type-equiv
|
|
/** Identifies one session-title provider registration. */
|
|
type SessionTitleProviderId = Branded<'SessionTitleProviderId'>
|
|
```
|
|
|
|
```ts type-equiv
|
|
/** Exact auxiliary model route that produced a title. */
|
|
interface SessionTitleModelProvenance {
|
|
/** Registered LLM provider route. */
|
|
readonly provider: string
|
|
/** Provider model id. */
|
|
readonly model: string
|
|
}
|
|
```
|
|
|
|
```ts type-equiv
|
|
/** Durable ownership record for an accepted session title. */
|
|
type SessionTitleSource =
|
|
| { readonly kind: 'fallback' }
|
|
| {
|
|
readonly kind: 'provider'
|
|
readonly provider: SessionTitleProviderId
|
|
readonly model?: SessionTitleModelProvenance
|
|
}
|
|
| {
|
|
/** Explicit user rename: pins the title — automatic generation stops scheduling. */
|
|
readonly kind: 'user'
|
|
}
|
|
```
|
|
|
|
```ts type-equiv
|
|
/** Payload of the log-only `session/title` event. */
|
|
interface SessionTitleEventData {
|
|
/** Normalized non-empty title text. */
|
|
readonly title: string
|
|
/** Exact human `user/message` seqs used to derive this title; empty for an explicit user rename. */
|
|
readonly messageSeqs: number[]
|
|
/** Built-in fallback, registered-provider, or explicit-user provenance. */
|
|
readonly source: SessionTitleSource
|
|
}
|
|
```
|
|
|
|
```ts type-equiv
|
|
/** Latest folded title plus the title event's durable envelope facts. */
|
|
interface SessionTitleSnapshot extends SessionTitleEventData {
|
|
/** Seq of the latest `session/title` event. */
|
|
readonly eventSeq: number
|
|
/** Timestamp of the latest `session/title` event. */
|
|
readonly updatedAt: number
|
|
}
|
|
```
|
|
|
|
## Auxiliary request record
|
|
|
|
The shared LLM helper records each validated, dispatchable title request before calling the model. The payload reproduces the model-visible system and message input, routing, output limit, provider ownership, and source-message attribution even when generation later fails.
|
|
|
|
```ts type-equiv
|
|
/** Exact model-visible request recorded before one auxiliary title dispatch. */
|
|
interface SessionTitleLlmRequestEventData {
|
|
/** Registered title-provider identity responsible for the request. */
|
|
readonly titleProvider: SessionTitleProviderId
|
|
/** Exact human `user/message` seqs represented in `messages`. */
|
|
readonly messageSeqs: number[]
|
|
/** Exact auxiliary LLM route. */
|
|
readonly route: SessionTitleModelProvenance
|
|
/** Exact auxiliary system prompt. */
|
|
readonly system: string
|
|
/** Exact auxiliary message list. */
|
|
readonly messages: Message[]
|
|
/** Exact auxiliary output-token cap. */
|
|
readonly maxTokens: number
|
|
}
|
|
```
|
|
|
|
## Provider input and output
|
|
|
|
The service snapshots eligible messages through one revision. A provider returns only seqs from that request; service-owned acceptance verifies ordering, normalizes the title, enforces the byte limit, and appends provenance.
|
|
|
|
```ts type-equiv
|
|
/** One eligible human text message exposed to title providers. */
|
|
interface SessionTitleUserMessage {
|
|
/** Source `user/message` event seq. */
|
|
readonly seq: number
|
|
/** Exact concatenated text-block content. */
|
|
readonly text: string
|
|
}
|
|
```
|
|
|
|
```ts type-equiv
|
|
/** Automatic generation cadence owned by a registered provider. */
|
|
type SessionTitleAutomaticMode = 'first-message' | 'all-user-messages'
|
|
```
|
|
|
|
```ts type-equiv
|
|
/** Immutable input supplied to one title-provider call. */
|
|
interface SessionTitleProviderRequest {
|
|
/** Live session being titled. */
|
|
readonly session: Session
|
|
/** All eligible human messages through this generation revision. */
|
|
readonly messages: readonly SessionTitleUserMessage[]
|
|
/** Exact current logged main-request route, when one has been recorded. */
|
|
readonly route?: SessionTitleModelProvenance
|
|
/** Cancellation for supersession, disposal, timeout composition, or the explicit caller. */
|
|
readonly signal: AbortSignal
|
|
}
|
|
```
|
|
|
|
```ts type-equiv
|
|
/** Provider output before service-owned normalization and log acceptance. */
|
|
interface SessionTitleProviderResult {
|
|
/** Proposed title text. */
|
|
readonly title: string
|
|
/** Exact seqs from `request.messages` used by this result. */
|
|
readonly messageSeqs: readonly number[]
|
|
/** Auxiliary LLM route, when generation used a model. */
|
|
readonly model?: SessionTitleModelProvenance
|
|
}
|
|
```
|
|
|
|
```ts type-equiv
|
|
/** One optional asynchronous title implementation registered with the service. */
|
|
interface SessionTitleProvider {
|
|
/** Stable provider identity recorded in title provenance. */
|
|
readonly id: SessionTitleProviderId
|
|
/** When new human prompts start automatic generation. */
|
|
readonly automatic: SessionTitleAutomaticMode
|
|
/**
|
|
* Produce one title revision.
|
|
* @param request - message snapshot, current route, session, and cancellation.
|
|
* @returns proposed title plus exact input seqs and optional model provenance.
|
|
*/
|
|
generate(request: SessionTitleProviderRequest): Promise<SessionTitleProviderResult>
|
|
}
|
|
```
|