Machine-produced by `pnpm run rescope-vendor --apply` plus the regeneration it prints: `pnpm install` for the lockfile, `pnpm run gen-third-party-notices`, `verify-translation-pairing --write` for the touched bilingual pairs, `gen-doc-graphs`, and one typert snapshot whose ids embed character offsets. `pnpm run rescope-vendor --check` verifies the result. Renames nine vendored packages (cordis, cosmokit, schemastery and the six @cordisjs plugins) and every reference that resolves them: manifest names and dependency keys, module specifiers including declare-module merges, cordis.yml plugin names, tsconfig paths, every Markdown fence, and `docs/` prose. Directory names, upstream versions, and dependency ranges are unchanged, so vendor/README.md still reads as an upstream snapshot; its manifest table gains an upstream-name column so THIRD_PARTY_NOTICES keeps MIT attribution pointed at each fork's origin. The tutorial tier follows the rename end to end: its yaml fences named plugins the Loader can no longer resolve, its `ts ignore-check` fences disagreed with the compiled fences beside them, and its prose quoted both. The contracts that told readers to keep upstream names — the root convention and the vendoring cookbook's tree comment and manifest invariant — now say to rescope instead. Two rules read `@deepseek-ai/` as "another workspace plugin": the client bundle purity gate now names the vendored libraries a browser bundle inlines, and the files where a bare `cordis` is an agent-preset id keep that product data.
163 lines
5.8 KiB
TypeScript
163 lines
5.8 KiB
TypeScript
import { createUserMessage } from '@deepseek-ai/dsh-llm'
|
|
import { Context } from '@deepseek-ai/cordis'
|
|
import { describe, expect, it } from 'vitest'
|
|
import SessionStore, { Session, SessionId } from '@deepseek-ai/dsh-session'
|
|
import SessionTitleService, {
|
|
SessionTitleProviderId,
|
|
fallbackSessionTitle,
|
|
foldSessionTitle,
|
|
normalizeSessionTitle,
|
|
truncateTitleUtf8,
|
|
} from '@deepseek-ai/dsh-session-title'
|
|
|
|
const CONFIG = {
|
|
fallbackMaxWords: 5,
|
|
fallbackMaxBytes: 40,
|
|
maxTitleBytes: 80,
|
|
} as const
|
|
|
|
async function settleTitles(): Promise<void> {
|
|
await new Promise(resolve => setTimeout(resolve, 0))
|
|
}
|
|
|
|
describe('session title normalization', () => {
|
|
it('removes terminal controls, collapses whitespace, and applies word and UTF-8 byte caps', () => {
|
|
expect(normalizeSessionTitle('\u001B]0;stolen\u0007 Hello\t brave\nnew world ', 80))
|
|
.toBe('Hello brave new world')
|
|
expect(fallbackSessionTitle('one two three four', 3, 80)).toBe('one two three')
|
|
expect(fallbackSessionTitle('你好世界', 5, 7)).toBe('你好')
|
|
expect(Buffer.byteLength(fallbackSessionTitle('😀😀', 5, 5), 'utf8')).toBe(4)
|
|
})
|
|
|
|
it('rejects non-positive and fractional public limits', () => {
|
|
expect(() => truncateTitleUtf8('title', 0)).toThrow(/maxBytes must be a positive integer/)
|
|
expect(() => fallbackSessionTitle('title', 1.5, 10)).toThrow(/maxWords must be a positive integer/)
|
|
})
|
|
})
|
|
|
|
describe('SessionTitleService', () => {
|
|
it('logs and folds an immediate fallback after the first eligible human text message', async () => {
|
|
const ctx = new Context()
|
|
await ctx.plugin(SessionStore)
|
|
await ctx.plugin(SessionTitleService, CONFIG)
|
|
const session = ctx.sessions.create(SessionId('fresh'))
|
|
session.append('turn/start', {
|
|
turn: 1,
|
|
})
|
|
const message = session.append('user/message', createUserMessage({
|
|
content: [{ type: 'text', text: ' Build\nlog-backed session titles please ' }],
|
|
source: { kind: 'user' },
|
|
}), { surfaceOp: 'append' })
|
|
|
|
await settleTitles()
|
|
|
|
const titleEvent = session.events.findLast(event => event.type === 'session/title')
|
|
expect(titleEvent).toMatchObject({
|
|
type: 'session/title',
|
|
seq: 2,
|
|
data: {
|
|
title: 'Build log-backed session titles please',
|
|
messageSeqs: [message.seq],
|
|
source: { kind: 'fallback' },
|
|
},
|
|
})
|
|
expect(ctx.sessionTitle.get(session)).toEqual({
|
|
title: 'Build log-backed session titles please',
|
|
messageSeqs: [message.seq],
|
|
source: { kind: 'fallback' },
|
|
eventSeq: 2,
|
|
updatedAt: titleEvent?.time,
|
|
})
|
|
expect(session.deriveMessages()).toHaveLength(1)
|
|
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,
|
|
})
|
|
session.append('user/message', createUserMessage({
|
|
content: [{ type: 'text', text: 'Explain this referenced session' }],
|
|
source: { kind: 'user' },
|
|
}), { 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)
|
|
await ctx.plugin(SessionTitleService, CONFIG)
|
|
const session = ctx.sessions.create(SessionId('eligibility'))
|
|
session.append('turn/start', {
|
|
turn: 1,
|
|
})
|
|
session.append('user/message', createUserMessage({
|
|
content: [{ type: 'text', text: 'plugin text' }],
|
|
source: { kind: 'plugin', plugin: 'seed' },
|
|
}), { surfaceOp: 'append' })
|
|
session.append('user/message', createUserMessage({
|
|
content: [{ type: 'reasoning', text: 'not visible text' }],
|
|
source: { kind: 'user' },
|
|
}), { surfaceOp: 'append' })
|
|
session.append('user/message', createUserMessage({
|
|
content: [{ type: 'text', text: ' \n\t ' }],
|
|
source: { kind: 'user' },
|
|
}), { surfaceOp: 'append' })
|
|
await settleTitles()
|
|
expect(ctx.sessionTitle.get(session)).toBeUndefined()
|
|
|
|
const eligible = session.append('user/message', createUserMessage({
|
|
content: [{ type: 'text', text: 'first real prompt' }],
|
|
source: { kind: 'user' },
|
|
}), { surfaceOp: 'append' })
|
|
await settleTitles()
|
|
const first = ctx.sessionTitle.get(session)
|
|
session.append('user/message', createUserMessage({
|
|
content: [{ type: 'text', text: 'later prompt' }],
|
|
source: { kind: 'user' },
|
|
}), { surfaceOp: 'append' })
|
|
await settleTitles()
|
|
|
|
expect(first?.messageSeqs).toEqual([eligible.seq])
|
|
expect(ctx.sessionTitle.get(session)).toEqual(first)
|
|
expect(session.events.filter(event => event.type === 'session/title')).toHaveLength(1)
|
|
})
|
|
|
|
it('folds the latest title event during replay', () => {
|
|
const seed = Session.create(SessionId('source'))
|
|
seed.append('session/title', {
|
|
title: 'Earlier',
|
|
messageSeqs: [1],
|
|
source: { kind: 'fallback' },
|
|
})
|
|
seed.append('session/title', {
|
|
title: 'Later',
|
|
messageSeqs: [1, 4],
|
|
source: {
|
|
kind: 'provider',
|
|
provider: SessionTitleProviderId('test-provider'),
|
|
model: { provider: 'mock', model: 'title-model' },
|
|
},
|
|
})
|
|
|
|
expect(foldSessionTitle(seed.events)).toEqual({
|
|
title: 'Later',
|
|
messageSeqs: [1, 4],
|
|
source: {
|
|
kind: 'provider',
|
|
provider: SessionTitleProviderId('test-provider'),
|
|
model: { provider: 'mock', model: 'title-model' },
|
|
},
|
|
eventSeq: 1,
|
|
updatedAt: seed.events[1]?.time,
|
|
})
|
|
})
|
|
})
|