feat: enhance magic notes AI comments
This commit is contained in:
@@ -1832,6 +1832,30 @@ describe('AssistantDatabase', () => {
|
||||
content: '可以拆成可检查的发布步骤。'
|
||||
})
|
||||
])
|
||||
const reanalyzed = database.saveMagicNoteAnalysis({
|
||||
entryId: entry.id,
|
||||
expectedRevision: analyzed.entries[0]!.revision,
|
||||
comments: [
|
||||
{
|
||||
id: '00000000-0000-4000-8000-000000000402',
|
||||
kind: 'narrative',
|
||||
content: '可以继续补充目标读者和发布场景。',
|
||||
direction: 'expand',
|
||||
format: 'narrative'
|
||||
}
|
||||
]
|
||||
})
|
||||
expect(reanalyzed.entries[0]!.comments).toEqual([
|
||||
expect.objectContaining({
|
||||
content: '可以拆成可检查的发布步骤。'
|
||||
}),
|
||||
expect.objectContaining({
|
||||
content: '可以继续补充目标读者和发布场景。',
|
||||
direction: 'expand',
|
||||
format: 'narrative',
|
||||
analyzedAt: expect.any(String)
|
||||
})
|
||||
])
|
||||
expect(database.listTasks()).toEqual([])
|
||||
database.close()
|
||||
})
|
||||
|
||||
@@ -2065,12 +2065,25 @@ export class AssistantDatabase {
|
||||
}): MagicNoteDetail {
|
||||
const database = this.requireDatabase()
|
||||
const existing = database
|
||||
.prepare('SELECT note_id FROM magic_note_entries WHERE id = ?')
|
||||
.get(input.entryId) as { note_id: string } | undefined
|
||||
.prepare(
|
||||
`SELECT note_id, comments_json
|
||||
FROM magic_note_entries
|
||||
WHERE id = ?`
|
||||
)
|
||||
.get(input.entryId) as
|
||||
| { note_id: string; comments_json: string }
|
||||
| undefined
|
||||
if (!existing) {
|
||||
throw new Error('记录不存在')
|
||||
}
|
||||
const now = new Date().toISOString()
|
||||
const comments = [
|
||||
...(JSON.parse(existing.comments_json) as MagicNoteComment[]),
|
||||
...input.comments.map((comment) => ({
|
||||
...comment,
|
||||
analyzedAt: now
|
||||
}))
|
||||
]
|
||||
const result = database
|
||||
.prepare(
|
||||
`UPDATE magic_note_entries
|
||||
@@ -2079,7 +2092,7 @@ export class AssistantDatabase {
|
||||
WHERE id = ? AND revision = ?`
|
||||
)
|
||||
.run(
|
||||
JSON.stringify(input.comments),
|
||||
JSON.stringify(comments),
|
||||
now,
|
||||
now,
|
||||
input.entryId,
|
||||
@@ -2156,8 +2169,22 @@ export class AssistantDatabase {
|
||||
expectedRevision: number
|
||||
comments: MagicNoteComment[]
|
||||
}): MagicTodoItem {
|
||||
const database = this.requireDatabase()
|
||||
const existing = database
|
||||
.prepare('SELECT comments_json FROM magic_todos WHERE id = ?')
|
||||
.get(input.todoId) as { comments_json: string } | undefined
|
||||
if (!existing) {
|
||||
throw new Error('待办不存在')
|
||||
}
|
||||
const now = new Date().toISOString()
|
||||
const result = this.requireDatabase()
|
||||
const comments = [
|
||||
...(JSON.parse(existing.comments_json) as MagicNoteComment[]),
|
||||
...input.comments.map((comment) => ({
|
||||
...comment,
|
||||
analyzedAt: now
|
||||
}))
|
||||
]
|
||||
const result = database
|
||||
.prepare(
|
||||
`UPDATE magic_todos
|
||||
SET comments_json = ?, analyzed_at = ?,
|
||||
@@ -2165,7 +2192,7 @@ export class AssistantDatabase {
|
||||
WHERE id = ? AND revision = ?`
|
||||
)
|
||||
.run(
|
||||
JSON.stringify(input.comments),
|
||||
JSON.stringify(comments),
|
||||
now,
|
||||
now,
|
||||
input.todoId,
|
||||
|
||||
Reference in New Issue
Block a user