From 82d436b5373eb66ff3a24f81da453598a881cc10 Mon Sep 17 00:00:00 2001 From: hanishkvc Date: Thu, 27 Nov 2025 12:05:05 +0530 Subject: [PATCH] SimpleChatTCRV:Markdown: flexible unwind list --- .../public_simplechat/docs/changelog.md | 7 +++++ tools/server/public_simplechat/typemd.mjs | 28 ++++++++++--------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/tools/server/public_simplechat/docs/changelog.md b/tools/server/public_simplechat/docs/changelog.md index 747803d6bc..9d642de0a1 100644 --- a/tools/server/public_simplechat/docs/changelog.md +++ b/tools/server/public_simplechat/docs/changelog.md @@ -339,3 +339,10 @@ their respective functionalities. Add support for base64 encoded pdf passing to ai models, when the models and llama engine gain that capability in turn using openai file - file-data type sub block within content array or so ... + +See why the ai streamed response not showing up in TCExternalAi chat session ui, even thou the content is getting +appended to its DivStream. IE why it is hidden. + +Markdown if a line which doesnt have any list marker appears at the same offset level as the last list item, +that too after a new line before this ambiguous line, then maybe pop out 1 level wrt the list. + diff --git a/tools/server/public_simplechat/typemd.mjs b/tools/server/public_simplechat/typemd.mjs index 2b07f417bf..da42938063 100644 --- a/tools/server/public_simplechat/typemd.mjs +++ b/tools/server/public_simplechat/typemd.mjs @@ -109,15 +109,23 @@ export class MarkDown { } } - unwind_list() { - while (true) { + /** + * Unwind till the specified offset level. + * @param {number} unwindTillOffset + */ + unwind_list(unwindTillOffset=-1) { + if (this.in.list.offsets.length == 0) { + return { done: true, remaining: 0 } + } + while (this.in.list.offsets[this.in.list.offsets.length-1] > unwindTillOffset) { + this.in.list.offsets.pop() let popped = this.in.list.endType.pop() - if (popped == undefined) { + this.html += popped; + if (this.in.list.offsets.length == 0) { break } - this.html += popped } - this.in.list.offsets.length = 0 + return { done: true, remaining: this.in.list.offsets.length } } /** @@ -154,20 +162,14 @@ export class MarkDown { this.in.list.endType.push("\n") } } else if (lastOffset > curOffset){ - while (this.in.list.offsets[this.in.list.offsets.length-1] > curOffset) { - this.in.list.offsets.pop() - let popped = this.in.list.endType.pop() - this.html += popped; - if (this.in.list.offsets.length == 0) { - break - } - } + this.unwind_list(curOffset) } this.html += `
  • ${matchList[3]}
  • \n` return true } else { if (this.in.list.offsets.length > 0) { if (emptyTracker.cur > 0) { + // skip empty line return true } let matchOffset = line.match(/^([ ]*)(.*)$/);