143 lines
5.4 KiB
Markdown
143 lines
5.4 KiB
Markdown
# 会话标题
|
|
|
|
[English](session-title.md) | 中文
|
|
|
|
[`@deepseek-ai/dsh-session-title`](../../packages/session-title/session-title) 所拥有的持久化后写覆盖标题状态与可选异步提供方词汇。共享 LLM(大语言模型)辅助组件负责精确的辅助请求记录。各包(package)README 负责时序、回退、失败与 fork 行为;生成的[持久化日志事件目录](../persistence-catalog.md)负责完整的事件声明。
|
|
|
|
源码:[`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)
|
|
|
|
## 持久标题状态
|
|
|
|
提供方生成修订时会记录 `SessionTitleProviderId`。`SessionTitleEventData` 携带精确的人类消息来源信息,`SessionTitleSnapshot` 则加入 `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
|
|
}
|
|
```
|
|
|
|
```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. */
|
|
readonly messageSeqs: number[]
|
|
/** Built-in fallback or registered-provider 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
|
|
}
|
|
```
|
|
|
|
## 辅助请求记录
|
|
|
|
共享 LLM 辅助组件会在调用模型前,记录每一项已经过验证且可分发的标题请求。即使后续生成失败,载荷仍会复现模型可见的系统输入与消息输入、路由、输出上限、提供方归属和源消息归因。
|
|
|
|
```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
|
|
}
|
|
```
|
|
|
|
## 提供方输入与输出
|
|
|
|
服务会对截至某一修订的合格消息创建快照。提供方返回的 seq 仅可来自该请求;由服务负责的接受过程会验证顺序、规范化标题、强制执行字节上限并追加来源信息。
|
|
|
|
```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>
|
|
}
|
|
```
|