Files
owoandCursor fb5a334edb feat: /last and bind button for previous Q/A context (v0.3.4)
After attaching a session, show a button and /last command that load the latest human/assistant turn via session.history so phone users can continue with context.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-14 20:25:07 +08:00

39 lines
1.2 KiB
TypeScript

import assert from 'node:assert/strict'
import test from 'node:test'
import { extractLastTurn, formatLastTurn } from '../src/history.ts'
test('extractLastTurn pairs latest human user with following assistant', () => {
const turn = extractLastTurn([
{
type: 'user/message',
data: { source: { kind: 'plugin', plugin: 'x' }, content: [{ type: 'text', text: 'injected' }] },
},
{
type: 'user/message',
data: { source: { kind: 'user' }, content: [{ type: 'text', text: '第一问' }] },
},
{
type: 'assistant/message',
data: { message: { content: [{ type: 'text', text: '第一答' }] } },
},
{
type: 'user/message',
data: { source: { kind: 'user' }, content: [{ type: 'text', text: '第二问' }] },
},
{
type: 'assistant/message',
data: { message: { content: [{ type: 'text', text: '第二答' }] } },
},
])
assert.equal(turn.userText, '第二问')
assert.equal(turn.assistantText, '第二答')
})
test('formatLastTurn renders sections', () => {
const text = formatLastTurn({ userText: 'hi', assistantText: 'hello' })
assert.match(text, /【用户】/)
assert.match(text, /hi/)
assert.match(text, /【助手】/)
assert.match(text, /hello/)
})