response formatting

This commit is contained in:
Arjun 2026-03-19 00:28:54 +05:30
parent d291ceec80
commit 05096f1383

View file

@ -1005,23 +1005,32 @@ export function MarkdownEditor({
if (currentPos !== null) { if (currentPos !== null) {
const node = editor.state.doc.nodeAt(currentPos) const node = editor.state.doc.nodeAt(currentPos)
if (node) { if (node) {
let tr = editor.state.tr.setNodeMarkup(currentPos, undefined, { // Update the block data (remove processing, add schedule)
const tr = editor.state.tr.setNodeMarkup(currentPos, undefined, {
data: JSON.stringify(updatedData), data: JSON.stringify(updatedData),
}) })
editor.view.dispatch(tr)
// Insert response text below the block if present // Insert response text below the block as rendered markdown
if (result.response) { if (result.response) {
const insertPos = currentPos + node.nodeSize // Re-find position after the dispatch above
const responseNode = editor.schema.nodes.paragraph?.create( let afterPos: number | null = null
null, editor.state.doc.descendants((n, pos) => {
editor.schema.text(result.response), if (afterPos !== null) return false
) if (n.type.name === 'taskBlock') {
if (responseNode) { try {
tr = tr.insert(insertPos, responseNode) const data = JSON.parse(n.attrs.data || '{}')
if (data.instruction === instruction && !data.processing) {
afterPos = pos + n.nodeSize
return false
}
} catch { /* skip */ }
}
})
if (afterPos !== null) {
editor.chain().insertContentAt(afterPos, result.response).run()
} }
} }
editor.view.dispatch(tr)
} }
} }
} catch (error) { } catch (error) {