fix(session-reference): bind snapshots to prompts
This commit is contained in:
@@ -14,6 +14,7 @@ import type {
|
||||
SessionEvent,
|
||||
SessionEventMap,
|
||||
} from '@deepseek-ai/dsh-session'
|
||||
import { displayPromptContent } from '@deepseek-ai/dsh-session'
|
||||
import { fallbackSessionTitle, normalizeSessionTitle } from './normalize.ts'
|
||||
|
||||
export { fallbackSessionTitle, normalizeSessionTitle, truncateTitleUtf8 } from './normalize.ts'
|
||||
@@ -201,8 +202,9 @@ export function collectSessionTitleMessages(
|
||||
for (const event of events) {
|
||||
if (throughSeq !== undefined && event.seq > throughSeq) break
|
||||
if (event.type !== 'user/message' || event.data.source.kind !== 'user') continue
|
||||
const text = event.data.content
|
||||
.filter((block): block is Extract<(typeof event.data.content)[number], { type: 'text' }> => block.type === 'text')
|
||||
const content = displayPromptContent(event.data)
|
||||
const text = content
|
||||
.filter((block): block is Extract<(typeof content)[number], { type: 'text' }> => block.type === 'text')
|
||||
.map(block => block.text)
|
||||
.join('\n')
|
||||
if (normalizeSessionTitle(text, Number.MAX_SAFE_INTEGER).length === 0) continue
|
||||
|
||||
@@ -72,6 +72,33 @@ describe('SessionTitleService', () => {
|
||||
expect(session.surface.nodes).toEqual([message.seq])
|
||||
})
|
||||
|
||||
it('derives a fallback title from the direct prompt instead of baked prefix context', async () => {
|
||||
const ctx = new Context()
|
||||
await ctx.plugin(SessionStore)
|
||||
await ctx.plugin(SessionTitleService, CONFIG)
|
||||
const session = ctx.sessions.create(SessionId('prefixed-title'))
|
||||
session.append('turn/start', {
|
||||
turn: 1,
|
||||
trigger: { kind: 'message', source: { kind: 'user' } },
|
||||
})
|
||||
session.append('user/message', {
|
||||
content: [
|
||||
{ type: 'text', text: 'referenced snapshot title must stay hidden' },
|
||||
{ type: 'text', text: '\n\n## My request:\n' },
|
||||
{ type: 'text', text: 'Explain this referenced session' },
|
||||
],
|
||||
source: { kind: 'user' },
|
||||
envelope: {
|
||||
displayContent: [{ type: 'text', text: 'Explain this referenced session' }],
|
||||
prefixContexts: [{ source: { kind: 'plugin', plugin: 'session-reference' } }],
|
||||
},
|
||||
}, { surfaceOp: 'append' })
|
||||
|
||||
await settleTitles()
|
||||
|
||||
expect(ctx.sessionTitle.get(session)?.title).toBe('Explain this referenced session')
|
||||
})
|
||||
|
||||
it('waits through synthetic, empty, and non-text messages, then keeps the first fallback', async () => {
|
||||
const ctx = new Context()
|
||||
await ctx.plugin(SessionStore)
|
||||
|
||||
Reference in New Issue
Block a user