mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-15 05:12:49 +00:00
perf: 支持显示思考过程
This commit is contained in:
parent
9fd8d44a6e
commit
b467dc55e5
@ -657,6 +657,7 @@ class WebSocketDialogMsg extends AbstractModel
|
|||||||
$text = $msgData['text'] ?? '';
|
$text = $msgData['text'] ?? '';
|
||||||
if (!$text) return '';
|
if (!$text) return '';
|
||||||
if ($msgData['type'] === 'md') {
|
if ($msgData['type'] === 'md') {
|
||||||
|
$text = preg_replace("/:::\s*reasoning[\s\S]*?:::/", "", $text);
|
||||||
$text = Base::markdown2html($text);
|
$text = Base::markdown2html($text);
|
||||||
$text = self::previewConvertTaskList($text);
|
$text = self::previewConvertTaskList($text);
|
||||||
}
|
}
|
||||||
|
|||||||
1
resources/assets/js/functions/web.js
vendored
1
resources/assets/js/functions/web.js
vendored
@ -246,6 +246,7 @@ import {convertLocalResourcePath} from "../components/Replace/utils";
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
if (type === 'md') {
|
if (type === 'md') {
|
||||||
|
text = text.replace(/:::\s*reasoning[\s\S]*?:::/g, "");
|
||||||
text = MarkdownPreview(text);
|
text = MarkdownPreview(text);
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
|
|||||||
69
resources/assets/js/store/markdown.js
vendored
69
resources/assets/js/store/markdown.js
vendored
@ -68,7 +68,72 @@ const MarkdownPluginUtils = {
|
|||||||
return value;
|
return value;
|
||||||
},
|
},
|
||||||
|
|
||||||
// 修改初始化插件函数
|
// 修改初始化插件函数(推理)
|
||||||
|
initReasoningPlugin(md) {
|
||||||
|
md.block.ruler.before('fence', 'reasoning', (state, startLine, endLine, silent) => {
|
||||||
|
const start = state.bMarks[startLine] + state.tShift[startLine];
|
||||||
|
const max = state.eMarks[startLine];
|
||||||
|
const firstLine = state.src.slice(start, max).trim();
|
||||||
|
|
||||||
|
// 检查是否匹配 :::reasoning 开始标记
|
||||||
|
const match = firstLine.match(/^:::\s*reasoning(?:\s+(\S+))?$/);
|
||||||
|
if (!match) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (silent) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
let nextLine = startLine + 1;
|
||||||
|
let content = [];
|
||||||
|
|
||||||
|
// 查找结束标记 :::
|
||||||
|
while (nextLine < endLine) {
|
||||||
|
const lineStart = state.bMarks[nextLine] + state.tShift[nextLine];
|
||||||
|
const lineMax = state.eMarks[nextLine];
|
||||||
|
const currentLine = state.src.slice(lineStart, lineMax);
|
||||||
|
|
||||||
|
if (currentLine.trim() === ':::') {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
content.push(state.getLines(nextLine, nextLine + 1, state.tShift[nextLine], true));
|
||||||
|
nextLine++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建外层容器
|
||||||
|
let token = state.push('reasoning_open', 'div', 1);
|
||||||
|
token.attrs = [['class', 'apply-reasoning']];
|
||||||
|
|
||||||
|
// 创建标签
|
||||||
|
token = state.push('reasoning_label_open', 'div', 1);
|
||||||
|
token.attrs = [['class', 'reasoning-label']];
|
||||||
|
token = state.push('text', '', 0);
|
||||||
|
token.content = $A.L('思考过程');
|
||||||
|
state.push('reasoning_label_close', 'div', -1);
|
||||||
|
|
||||||
|
// 创建内容容器
|
||||||
|
token = state.push('reasoning_content_open', 'div', 1);
|
||||||
|
token.attrs = [['class', 'reasoning-content']];
|
||||||
|
|
||||||
|
// 处理内容
|
||||||
|
if (content.length > 0) {
|
||||||
|
state.md.block.parse(content.join('\n'), state.md, state.env, state.tokens);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 关闭内容容器
|
||||||
|
state.push('reasoning_content_close', 'div', -1);
|
||||||
|
|
||||||
|
// 关闭外层容器
|
||||||
|
state.push('reasoning_close', 'div', -1);
|
||||||
|
|
||||||
|
state.line = nextLine + 1;
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
// 修改初始化插件函数(创建任务)
|
||||||
initCreateTaskPlugin(md) {
|
initCreateTaskPlugin(md) {
|
||||||
md.block.ruler.before('fence', 'create-task', (state, startLine, endLine, silent) => {
|
md.block.ruler.before('fence', 'create-task', (state, startLine, endLine, silent) => {
|
||||||
const start = state.bMarks[startLine] + state.tShift[startLine];
|
const start = state.bMarks[startLine] + state.tShift[startLine];
|
||||||
@ -201,6 +266,7 @@ export function MarkdownConver(text) {
|
|||||||
})
|
})
|
||||||
MarkdownUtils.mdi.use(mila, {attrs: {target: '_blank', rel: 'noopener'}})
|
MarkdownUtils.mdi.use(mila, {attrs: {target: '_blank', rel: 'noopener'}})
|
||||||
MarkdownUtils.mdi.use(mdKatex, {blockClass: 'katexmath-block rounded-md p-[10px]', errorColor: ' #cc0000'})
|
MarkdownUtils.mdi.use(mdKatex, {blockClass: 'katexmath-block rounded-md p-[10px]', errorColor: ' #cc0000'})
|
||||||
|
MarkdownPluginUtils.initReasoningPlugin(MarkdownUtils.mdi);
|
||||||
MarkdownPluginUtils.initCreateTaskPlugin(MarkdownUtils.mdi);
|
MarkdownPluginUtils.initCreateTaskPlugin(MarkdownUtils.mdi);
|
||||||
}
|
}
|
||||||
return MarkdownUtils.formatMsg(MarkdownUtils.mdi.render(text))
|
return MarkdownUtils.formatMsg(MarkdownUtils.mdi.render(text))
|
||||||
@ -209,6 +275,7 @@ export function MarkdownConver(text) {
|
|||||||
export function MarkdownPreview(text) {
|
export function MarkdownPreview(text) {
|
||||||
if (MarkdownUtils.mds === null) {
|
if (MarkdownUtils.mds === null) {
|
||||||
MarkdownUtils.mds = MarkdownIt()
|
MarkdownUtils.mds = MarkdownIt()
|
||||||
|
MarkdownPluginUtils.initReasoningPlugin(MarkdownUtils.mds);
|
||||||
MarkdownPluginUtils.initCreateTaskPlugin(MarkdownUtils.mds);
|
MarkdownPluginUtils.initCreateTaskPlugin(MarkdownUtils.mds);
|
||||||
}
|
}
|
||||||
return MarkdownUtils.mds.render(text)
|
return MarkdownUtils.mds.render(text)
|
||||||
|
|||||||
6
resources/assets/sass/dark.scss
vendored
6
resources/assets/sass/dark.scss
vendored
@ -306,6 +306,12 @@ body.dark-mode-reverse {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.apply-reasoning {
|
||||||
|
&:before {
|
||||||
|
background-color: #4e4e56;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.dialog-group-info {
|
.dialog-group-info {
|
||||||
|
|||||||
@ -2053,6 +2053,34 @@
|
|||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.apply-reasoning {
|
||||||
|
margin: 0 0 12px 0;
|
||||||
|
padding: 0 0 0 13px;
|
||||||
|
line-height: 26px;
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
&:before {
|
||||||
|
content: "";
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
bottom: 0;
|
||||||
|
width: 2px;
|
||||||
|
background-color: #e1e1e1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.reasoning-label {
|
||||||
|
margin-bottom: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.reasoning-content {
|
||||||
|
opacity: 0.5;
|
||||||
|
> p:last-child {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.apply-create-task {
|
.apply-create-task {
|
||||||
min-width: 160px;
|
min-width: 160px;
|
||||||
margin-bottom: 16px;
|
margin-bottom: 16px;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user