mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-26 05:27:06 +00:00
* fix(claude): preserve native titles and add remote fallback * fix(claude): write fallback titles as metadata only
33 lines
945 B
TypeScript
33 lines
945 B
TypeScript
import type { ApiSessionClient } from '@/api/apiSession'
|
|
|
|
const MAX_FALLBACK_TITLE_LENGTH = 80
|
|
|
|
export function createSessionTitleFallback(message: string): string | null {
|
|
const normalized = message.replace(/\s+/g, ' ').trim()
|
|
if (!normalized) return null
|
|
if (normalized.length <= MAX_FALLBACK_TITLE_LENGTH) return normalized
|
|
|
|
return normalized.slice(0, MAX_FALLBACK_TITLE_LENGTH - 1).trimEnd() + '…'
|
|
}
|
|
|
|
export function applySessionTitleFallback(
|
|
client: Pick<ApiSessionClient, 'updateMetadata'>,
|
|
message: string
|
|
): boolean {
|
|
const title = createSessionTitleFallback(message)
|
|
if (!title) return false
|
|
|
|
client.updateMetadata((metadata) => {
|
|
if (metadata.name?.trim() || metadata.summary?.text.trim()) return metadata
|
|
|
|
return {
|
|
...metadata,
|
|
summary: {
|
|
text: title,
|
|
updatedAt: Date.now()
|
|
}
|
|
}
|
|
})
|
|
return true
|
|
}
|