remove at rowbot block for single tasks

This commit is contained in:
Arjun 2026-03-19 00:40:49 +05:30
parent 05096f1383
commit 5e1debad6a

View file

@ -930,7 +930,7 @@ export function MarkdownEditor({
} }
if (activeRowboatMention) { if (activeRowboatMention) {
// Insert block with processing state immediately // Insert a temporary processing block
const blockData: Record<string, unknown> = { instruction, processing: true } const blockData: Record<string, unknown> = { instruction, processing: true }
const insertFrom = activeRowboatMention.range.from const insertFrom = activeRowboatMention.range.from
@ -951,21 +951,27 @@ export function MarkdownEditor({
setActiveRowboatMention(null) setActiveRowboatMention(null)
setRowboatAnchorTop(null) setRowboatAnchorTop(null)
// Find the taskBlock we just inserted so we can update it later
const processingData = JSON.stringify(blockData)
let taskBlockPos: number | null = null
editor.state.doc.descendants((node, pos) => {
if (taskBlockPos !== null) return false
if (node.type.name === 'taskBlock' && node.attrs.data === processingData) {
taskBlockPos = pos
return false
}
})
// Get editor content for the agent // Get editor content for the agent
const editorContent = editor.storage.markdown?.getMarkdown?.() ?? '' const editorContent = editor.storage.markdown?.getMarkdown?.() ?? ''
// Call the assistant agent asynchronously // Helper to find the processing block
const findProcessingBlock = (): number | null => {
let pos: number | null = null
editor.state.doc.descendants((node, p) => {
if (pos !== null) return false
if (node.type.name === 'taskBlock') {
try {
const data = JSON.parse(node.attrs.data || '{}')
if (data.instruction === instruction && data.processing === true) {
pos = p
return false
}
} catch { /* skip */ }
}
})
return pos
}
try { try {
const result = await window.ipc.invoke('inline-task:process', { const result = await window.ipc.invoke('inline-task:process', {
instruction, instruction,
@ -973,55 +979,41 @@ export function MarkdownEditor({
notePath: notePath ?? '', notePath: notePath ?? '',
}) })
// Update the block: remove processing, add schedule if any const currentPos = findProcessingBlock()
const updatedData: Record<string, unknown> = { instruction } if (currentPos === null) return
if (result.schedule) {
updatedData.schedule = result.schedule
updatedData['schedule-label'] = result.scheduleLabel
// Mark note as live if there's a schedule
if (onFrontmatterChange) {
const fields = extractAllFrontmatterValues(frontmatter ?? null)
fields['live_note'] = 'true'
onFrontmatterChange(buildFrontmatter(fields))
}
}
// Find the processing block again (position may have shifted)
let currentPos: number | null = null
editor.state.doc.descendants((node, pos) => {
if (currentPos !== null) return false
if (node.type.name === 'taskBlock') {
try {
const data = JSON.parse(node.attrs.data || '{}')
if (data.instruction === instruction && data.processing === true) {
currentPos = pos
return false
}
} catch { /* skip */ }
}
})
if (currentPos !== null) {
const node = editor.state.doc.nodeAt(currentPos) const node = editor.state.doc.nodeAt(currentPos)
if (node) { if (!node) return
// Update the block data (remove processing, add schedule)
if (result.schedule) {
// Scheduled task: keep the block, update with schedule info
const updatedData: Record<string, unknown> = {
instruction,
schedule: result.schedule,
'schedule-label': result.scheduleLabel,
}
const tr = editor.state.tr.setNodeMarkup(currentPos, undefined, { const tr = editor.state.tr.setNodeMarkup(currentPos, undefined, {
data: JSON.stringify(updatedData), data: JSON.stringify(updatedData),
}) })
editor.view.dispatch(tr) editor.view.dispatch(tr)
// Insert response text below the block as rendered markdown // Mark note as live
if (onFrontmatterChange) {
const fields = extractAllFrontmatterValues(frontmatter ?? null)
fields['live_note'] = 'true'
onFrontmatterChange(buildFrontmatter(fields))
}
// Insert response text below the block if any
if (result.response) { if (result.response) {
// Re-find position after the dispatch above
let afterPos: number | null = null let afterPos: number | null = null
editor.state.doc.descendants((n, pos) => { editor.state.doc.descendants((n, p) => {
if (afterPos !== null) return false if (afterPos !== null) return false
if (n.type.name === 'taskBlock') { if (n.type.name === 'taskBlock') {
try { try {
const data = JSON.parse(n.attrs.data || '{}') const data = JSON.parse(n.attrs.data || '{}')
if (data.instruction === instruction && !data.processing) { if (data.instruction === instruction && !data.processing) {
afterPos = pos + n.nodeSize afterPos = p + n.nodeSize
return false return false
} }
} catch { /* skip */ } } catch { /* skip */ }
@ -1031,31 +1023,26 @@ export function MarkdownEditor({
editor.chain().insertContentAt(afterPos, result.response).run() editor.chain().insertContentAt(afterPos, result.response).run()
} }
} }
} else {
// One-time task: remove the processing block, insert response in its place
const insertPos = currentPos
const deleteEnd = currentPos + node.nodeSize
editor.chain().focus().deleteRange({ from: insertPos, to: deleteEnd }).run()
if (result.response) {
editor.chain().insertContentAt(insertPos, result.response).run()
} }
} }
} catch (error) { } catch (error) {
console.error('[RowboatAdd] Processing failed:', error) console.error('[RowboatAdd] Processing failed:', error)
// Remove processing state on error // Remove the processing block on error
let currentPos: number | null = null const currentPos = findProcessingBlock()
editor.state.doc.descendants((node, pos) => {
if (currentPos !== null) return false
if (node.type.name === 'taskBlock') {
try {
const data = JSON.parse(node.attrs.data || '{}')
if (data.instruction === instruction && data.processing === true) {
currentPos = pos
return false
}
} catch { /* skip */ }
}
})
if (currentPos !== null) { if (currentPos !== null) {
const tr = editor.state.tr.setNodeMarkup(currentPos, undefined, { const node = editor.state.doc.nodeAt(currentPos)
data: JSON.stringify({ instruction }), if (node) {
}) editor.chain().focus().deleteRange({ from: currentPos, to: currentPos + node.nodeSize }).run()
editor.view.dispatch(tr) }
} }
} }
} }