risum 모듈 — RISU modules[] — 기능 확장
{
"type": "risuModule",
"name": "추론계승모듈2",
"id": "46e90489-f878-493a-80a2-8c5a2e8a4705",
"namespace": "yamiv4_thought_inline",
"description": "",
"customModuleToggle": "=추론계승2=group\n생각계승=생각 계승=select=Off,1개,3개,5개,10개",
"trigger": [
{
"type": "start",
"conditions": [],
"effect": [
{
"type": "triggerlua",
"code": "local function parseCount(value)\n local v = tostring(value or \"\")\n if v == \"0\" or v == \"Off\" or v == \"\" or v == \"nil\" then return 0 end\n if v == \"1\" or v == \"1개\" then return 1 end\n if v == \"2\" or v == \"3개\" then return 3 end\n if v == \"3\" or v == \"5개\" then return 5 end\n if v == \"4\" or v == \"10개\" then return 10 end\n return 0\nend\n\nlocal function trim(value)\n return tostring(value or \"\"):gsub(\"^%s+\", \"\"):gsub(\"%s+$\", \"\")\nend\n\nlocal function addThought(value, out)\n local body = trim(value)\n if body ~= \"\" and body ~= \"null\" then\n out[#out + 1] = body\n end\nend\n\nlocal function collectThoughtArray(value, out)\n if type(value) ~= \"table\" then return end\n for _, body in ipairs(value) do\n addThought(body, out)\n end\nend\n\nlocal function collectBlocks(text, out)\n if type(text) ~= \"string\" then return end\n local patterns = {\n \"<%s*[Tt]houghts%s*>(.-)<%s*/%s*[Tt]houghts%s*>\",\n \"<%s*[Tt]hought%s*>(.-)<%s*/%s*[Tt]hought%s*>\",\n \"<%s*[Tt]hink%s*>(.-)<%s*/%s*[Tt]hink%s*>\",\n \"<%s*[Tt]hinking%s*>(.-)<%s*/%s*[Tt]hinking%s*>\"\n }\n for _, pattern in ipairs(patterns) do\n local pos = 1\n while true do\n local s, e, body = string.find(text, pattern, pos)\n if not s then break end\n addThought(body, out)\n pos = e + 1\n end\n end\nend\n\nlocal function stripBlocks(text)\n if type(text) ~= \"string\" then return text end\n local stripped = text\n stripped = stripped:gsub(\"<%s*[Tt]houghts%s*>.-<%s*/%s*[Tt]houghts%s*>\", \"\")\n stripped = stripped:gsub(\"<%s*[Tt]hought%s*>.-<%s*/%s*[Tt]hought%s*>\", \"\")\n stripped = stripped:gsub(\"<%s*[Tt]hink%s*>.-<%s*/%s*[Tt]hink%s*>\", \"\")\n stripped = stripped:gsub(\"<%s*[Tt]hinking%s*>.-<%s*/%s*[Tt]hinking%s*>\", \"\")\n stripped = stripped:gsub(\"\\n%s*\\n%s*\\n+\", \"\\n\\n\")\n return trim(stripped)\nend\n\nlocal function isAssistantRole(role)\n return role == \"assistant\" or role == \"char\" or role == \"bot\"\nend\n\nlocal function splitThinkingBody(text)\n local bodyStart, bodyEnd = string.find(text, \"<%s*/%s*[Tt]hinking%s*>\")\n if not bodyStart then\n bodyStart, bodyEnd = string.find(text, \"<%s*/%s*[Tt]hink%s*>\")\n end\n if not bodyStart then return nil, nil end\n\n local thought = string.sub(text, 1, bodyStart - 1)\n local body = string.sub(text, bodyEnd + 1)\n\n thought = thought:gsub(\"^%s*<%s*[Tt]hinking%s*>%s*\", \"\")\n thought = thought:gsub(\"^%s*<%s*[Tt]hink%s*>%s*\", \"\")\n\n return trim(thought), trim(body)\nend\n\nlocal function restoreReasoningBody(text)\n if type(text) ~= \"string\" then return text end\n\n local before, inner, after = string.match(text, \"^(.-)<%s*[Tt]houghts%s*>(.-)<%s*/%s*[Tt]houghts%s*>(.*)$\")\n if inner then\n local thought, body = splitThinkingBody(inner)\n if body and body ~= \"\" then\n local tail = trim(after)\n if tail == \"null\" then tail = \"\" end\n tail = tail:gsub(\"^null%s*\", \"\")\n tail = trim(tail)\n\n local pieces = {}\n local prefix = trim(before)\n if prefix ~= \"\" then pieces[#pieces + 1] = prefix end\n if thought and thought ~= \"\" then\n pieces[#pieces + 1] = \"<Thoughts>\\n\" .. thought .. \"\\n</Thoughts>\"\n end\n pieces[#pieces + 1] = body\n if tail ~= \"\" then pieces[#pieces + 1] = tail end\n return trim(table.concat(pieces, \"\\n\"))\n end\n end\n\n local thought, body = splitThinkingBody(text)\n if body and body ~= \"\" then\n if thought and thought ~= \"\" then\n return trim(\"<Thoughts>\\n\" .. thought .. \"\\n</Thoughts>\\n\" .. body)\n end\n return trim(body)\n end\n\n return trim(text:gsub(\"%s*null%s*$\", \"\"))\nend\n\nlistenEdit(\"editOutput\", function(id, data, meta)\n return restoreReasoningBody(data)\nend)\n\nlistenEdit(\"editRequest\", function(id, data, meta)\n local count = parseCount(getGlobalVar(id, \"toggle_생각계승\"))\n if count <= 0 then\n return data\n end\n if type(data) ~= \"table\" then\n return data\n end\n\n local entries = {}\n\n for i = 1, #data do\n local msg = data[i]\n if msg and isAssistantRole(msg.role) then\n local messageThoughts = {}\n collectThoughtArray(msg.thoughts, messageThoughts)\n msg.thoughts = nil\n collectBlocks(msg.content, messageThoughts)\n msg.content = stripBlocks(msg.content)\n if #messageThoughts > 0 then\n entries[#entries + 1] = {\n index = i,\n body = table.concat(messageThoughts, \"\\n\\n\")\n }\n end\n end\n end\n\n if #entries == 0 then\n return data\n end\n\n local startIndex = #entries - count + 1\n if startIndex < 1 then startIndex = 1 end\n\n for i = startIndex, #entries do\n local entry = entries[i]\n local msg = data[entry.index]\n if msg and type(msg.content) == \"string\" then\n local block = \"<Thoughts>\\n\" .. entry.body .. \"\\n</Thoughts>\"\n local body = trim(msg.content)\n if body ~= \"\" then\n msg.content = block .. \"\\n\" .. body\n else\n msg.content = block\n end\n end\n end\n\n return data\nend)"
}
],
"lowLevelAccess": false
}
],
"hideIcon": false,
"lowLevelAccess": false,
"regex": [],
"lorebook": [],
"assets": []
}