From 05096f1383bd5723ac2a7885acdfa91d9684c84c Mon Sep 17 00:00:00 2001 From: Arjun <6592213+arkml@users.noreply.github.com> Date: Thu, 19 Mar 2026 00:28:54 +0530 Subject: [PATCH] response formatting --- .../src/components/markdown-editor.tsx | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/apps/x/apps/renderer/src/components/markdown-editor.tsx b/apps/x/apps/renderer/src/components/markdown-editor.tsx index 8bc4cdae..c2fb38cc 100644 --- a/apps/x/apps/renderer/src/components/markdown-editor.tsx +++ b/apps/x/apps/renderer/src/components/markdown-editor.tsx @@ -1005,23 +1005,32 @@ export function MarkdownEditor({ if (currentPos !== null) { const node = editor.state.doc.nodeAt(currentPos) 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), }) + editor.view.dispatch(tr) - // Insert response text below the block if present + // Insert response text below the block as rendered markdown if (result.response) { - const insertPos = currentPos + node.nodeSize - const responseNode = editor.schema.nodes.paragraph?.create( - null, - editor.schema.text(result.response), - ) - if (responseNode) { - tr = tr.insert(insertPos, responseNode) + // Re-find position after the dispatch above + let afterPos: number | null = null + editor.state.doc.descendants((n, pos) => { + if (afterPos !== null) return false + if (n.type.name === 'taskBlock') { + try { + 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) {