mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-23 03:19:41 +00:00
Merge pull request #3373 from xinnan-tech/feat-snapshot-dialog-code-diff
feat: 历史版本快照增加代码对比视图
This commit is contained in:
commit
628d4cedb7
3 changed files with 189 additions and 13 deletions
85
main/manager-web/package-lock.json
generated
85
main/manager-web/package-lock.json
generated
|
|
@ -13,10 +13,12 @@
|
|||
"dotenv": "^16.5.0",
|
||||
"element-ui": "^2.15.14",
|
||||
"flyio": "^0.6.14",
|
||||
"highlight.js": "^11.12.0",
|
||||
"normalize.css": "^8.0.1",
|
||||
"opus-decoder": "^0.7.7",
|
||||
"opus-recorder": "^8.0.5",
|
||||
"sm-crypto": "^0.3.13",
|
||||
"v-code-diff": "^1.16.0",
|
||||
"vue": "^2.6.14",
|
||||
"vue-axios": "^3.5.2",
|
||||
"vue-i18n": "^8.28.2",
|
||||
|
|
@ -5134,6 +5136,16 @@
|
|||
"url": "https://github.com/chalk/chalk?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/cli-highlight/node_modules/highlight.js": {
|
||||
"version": "10.7.3",
|
||||
"resolved": "https://registry.npmmirror.com/highlight.js/-/highlight.js-10.7.3.tgz",
|
||||
"integrity": "sha512-tzcUFauisWKNHaRkN4Wjl/ZA07gENAjFl3J/c480dprkGTg5EQstgaNFqBfUqCq54kZRIEcreTsAgF/m2quD7A==",
|
||||
"dev": true,
|
||||
"license": "BSD-3-Clause",
|
||||
"engines": {
|
||||
"node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/cli-spinners": {
|
||||
"version": "2.9.2",
|
||||
"resolved": "https://registry.npmmirror.com/cli-spinners/-/cli-spinners-2.9.2.tgz",
|
||||
|
|
@ -6165,6 +6177,21 @@
|
|||
"integrity": "sha512-T0NIuQpnTvFDATNuHN5roPwSBG83rFsuO+MXXH9/3N1eFbn4wcPjttvjMLEPWJ0RGUYgQE7cGgS3tNxbqCGM7g==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/diff": {
|
||||
"version": "5.2.2",
|
||||
"resolved": "https://registry.npmmirror.com/diff/-/diff-5.2.2.tgz",
|
||||
"integrity": "sha512-vtcDfH3TOjP8UekytvnHH1o1P4FcUdt4eQ1Y+Abap1tk/OB2MWQvcwS2ClCd1zuIhc3JKOx6p3kod8Vfys3E+A==",
|
||||
"license": "BSD-3-Clause",
|
||||
"engines": {
|
||||
"node": ">=0.3.1"
|
||||
}
|
||||
},
|
||||
"node_modules/diff-match-patch": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmmirror.com/diff-match-patch/-/diff-match-patch-1.0.5.tgz",
|
||||
"integrity": "sha512-IayShXAgj/QMXgB0IWmKx+rOPuGMhqm5w6jvFxmVenXKIzRqTAAsbBPT3kWQeGANj3jGgvcvv4yK6SxqYmikgw==",
|
||||
"license": "Apache-2.0"
|
||||
},
|
||||
"node_modules/diff-sequences": {
|
||||
"version": "29.6.3",
|
||||
"resolved": "https://registry.npmmirror.com/diff-sequences/-/diff-sequences-29.6.3.tgz",
|
||||
|
|
@ -7732,12 +7759,12 @@
|
|||
}
|
||||
},
|
||||
"node_modules/highlight.js": {
|
||||
"version": "10.7.3",
|
||||
"resolved": "https://registry.npmmirror.com/highlight.js/-/highlight.js-10.7.3.tgz",
|
||||
"integrity": "sha512-tzcUFauisWKNHaRkN4Wjl/ZA07gENAjFl3J/c480dprkGTg5EQstgaNFqBfUqCq54kZRIEcreTsAgF/m2quD7A==",
|
||||
"dev": true,
|
||||
"version": "11.12.0",
|
||||
"resolved": "https://registry.npmmirror.com/highlight.js/-/highlight.js-11.12.0.tgz",
|
||||
"integrity": "sha512-nbfWpyRMcMrPMmDwJB+dhX/eiaPKtc2RB+0QZskqJ3WjRA/FDS0e9hZrx8EC/lbEv8gXy98FcDbNa/dspAaJMg==",
|
||||
"license": "BSD-3-Clause",
|
||||
"engines": {
|
||||
"node": "*"
|
||||
"node": ">=12.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/hosted-git-info": {
|
||||
|
|
@ -13574,6 +13601,28 @@
|
|||
"uuid": "bin/uuid"
|
||||
}
|
||||
},
|
||||
"node_modules/v-code-diff": {
|
||||
"version": "1.16.0",
|
||||
"resolved": "https://registry.npmmirror.com/v-code-diff/-/v-code-diff-1.16.0.tgz",
|
||||
"integrity": "sha512-xNhzfK/OHgVs86T1Wnjb1YqSAYHXhmwAAYm8G7yVWuc96j9QWyIhG1xirWMjrzlkJr3KRGR+TUKqG23P5bl8Pg==",
|
||||
"hasInstallScript": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"diff": "^5.2.2",
|
||||
"diff-match-patch": "^1.0.5",
|
||||
"highlight.js": "^11.12.0",
|
||||
"vue-demi": "^0.14.10"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@vue/composition-api": "^1.4.9",
|
||||
"vue": "^2.6.0 || >=3.0.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@vue/composition-api": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/validate-npm-package-license": {
|
||||
"version": "3.0.4",
|
||||
"resolved": "https://registry.npmmirror.com/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz",
|
||||
|
|
@ -13974,6 +14023,32 @@
|
|||
"vue": "^3.0.0 || ^2.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/vue-demi": {
|
||||
"version": "0.14.10",
|
||||
"resolved": "https://registry.npmmirror.com/vue-demi/-/vue-demi-0.14.10.tgz",
|
||||
"integrity": "sha512-nMZBOwuzabUO0nLgIcc6rycZEebF6eeUfaiQx9+WSk8e29IbLvPU9feI6tqW4kTo3hvoYAJkMh8n8D0fuISphg==",
|
||||
"hasInstallScript": true,
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"vue-demi-fix": "bin/vue-demi-fix.js",
|
||||
"vue-demi-switch": "bin/vue-demi-switch.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/antfu"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@vue/composition-api": "^1.0.0-rc.1",
|
||||
"vue": "^3.0.0-0 || ^2.6.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@vue/composition-api": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/vue-hot-reload-api": {
|
||||
"version": "2.3.4",
|
||||
"resolved": "https://registry.npmmirror.com/vue-hot-reload-api/-/vue-hot-reload-api-2.3.4.tgz",
|
||||
|
|
|
|||
|
|
@ -18,10 +18,12 @@
|
|||
"dotenv": "^16.5.0",
|
||||
"element-ui": "^2.15.14",
|
||||
"flyio": "^0.6.14",
|
||||
"highlight.js": "^11.12.0",
|
||||
"normalize.css": "^8.0.1",
|
||||
"opus-decoder": "^0.7.7",
|
||||
"opus-recorder": "^8.0.5",
|
||||
"sm-crypto": "^0.3.13",
|
||||
"v-code-diff": "^1.16.0",
|
||||
"vue": "^2.6.14",
|
||||
"vue-axios": "^3.5.2",
|
||||
"vue-i18n": "^8.28.2",
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
<el-dialog
|
||||
:title="$t('agentSnapshot.title')"
|
||||
:visible="visible"
|
||||
width="860px"
|
||||
width="960px"
|
||||
class="agent-snapshot-dialog"
|
||||
:before-close="guardRestoreInFlightClose"
|
||||
:close-on-click-modal="!restoring"
|
||||
|
|
@ -126,7 +126,7 @@
|
|||
<el-dialog
|
||||
:title="detailDialogTitle"
|
||||
:visible.sync="detailVisible"
|
||||
width="860px"
|
||||
width="960px"
|
||||
class="snapshot-detail-dialog"
|
||||
>
|
||||
<template slot="title">
|
||||
|
|
@ -269,8 +269,21 @@
|
|||
</div>
|
||||
<div v-else class="value-empty">{{ $t('agentSnapshot.noFunctionChange') }}</div>
|
||||
</div>
|
||||
<div v-else-if="shouldUseCodeDiff(item)" class="diff-code-wrapper">
|
||||
<CodeDiff
|
||||
:old-string="item.beforeText"
|
||||
:new-string="item.afterText"
|
||||
:language="codeDiffLanguage(item)"
|
||||
output-format="side-by-side"
|
||||
diff-style="word"
|
||||
:context="8"
|
||||
max-height="320px"
|
||||
:filename="item.beforeTitle"
|
||||
:new-filename="item.afterTitle"
|
||||
/>
|
||||
</div>
|
||||
<div v-else class="diff-values" :class="{ 'is-complex': item.complex }">
|
||||
<div class="diff-pane diff-before">
|
||||
<div class="diff-pane diff-before 1">
|
||||
<div class="diff-pane-title">{{ item.beforeTitle }}</div>
|
||||
<div class="diff-value" :class="valueClass(item)">
|
||||
<div
|
||||
|
|
@ -306,7 +319,7 @@
|
|||
<el-dialog
|
||||
:title="restorePreviewTitle"
|
||||
:visible.sync="restorePreviewVisible"
|
||||
width="860px"
|
||||
width="960px"
|
||||
class="snapshot-detail-dialog"
|
||||
:before-close="guardRestoreInFlightClose"
|
||||
:close-on-click-modal="!restoring"
|
||||
|
|
@ -401,8 +414,21 @@
|
|||
</div>
|
||||
<div v-else class="value-empty">{{ $t('agentSnapshot.noFunctionChange') }}</div>
|
||||
</div>
|
||||
<div v-else-if="shouldUseCodeDiff(item)" class="diff-code-wrapper">
|
||||
<CodeDiff
|
||||
:old-string="item.beforeText"
|
||||
:new-string="item.afterText"
|
||||
:language="codeDiffLanguage(item)"
|
||||
output-format="side-by-side"
|
||||
diff-style="word"
|
||||
:context="8"
|
||||
max-height="320px"
|
||||
:filename="item.beforeTitle"
|
||||
:new-filename="item.afterTitle"
|
||||
/>
|
||||
</div>
|
||||
<div v-else class="diff-values" :class="{ 'is-complex': item.complex }">
|
||||
<div class="diff-pane diff-before">
|
||||
<div class="diff-pane diff-before 2">
|
||||
<div class="diff-pane-title">{{ item.beforeTitle }}</div>
|
||||
<div class="diff-value" :class="valueClass(item)">
|
||||
<div
|
||||
|
|
@ -485,6 +511,8 @@
|
|||
import Api from "@/apis/api";
|
||||
import correctWord from "@/apis/module/correctWord";
|
||||
import { formatDate } from "@/utils/date";
|
||||
import { CodeDiff, hljs } from "v-code-diff";
|
||||
import markdown from "highlight.js/lib/languages/markdown";
|
||||
import {
|
||||
hasValidCurrentStateToken,
|
||||
normalizeSnapshotOrderedValue,
|
||||
|
|
@ -492,6 +520,8 @@ import {
|
|||
SNAPSHOT_SECRET_REDACTED
|
||||
} from "./agentSnapshotDisplayUtils.mjs";
|
||||
|
||||
hljs.registerLanguage("markdown", markdown);
|
||||
|
||||
const FALLBACK_PLUGIN_NAME_KEYS = {
|
||||
SYSTEM_PLUGIN_WEATHER: "agentSnapshot.plugin.SYSTEM_PLUGIN_WEATHER",
|
||||
SYSTEM_PLUGIN_MUSIC: "agentSnapshot.plugin.SYSTEM_PLUGIN_MUSIC",
|
||||
|
|
@ -559,6 +589,9 @@ const CHAT_HISTORY_CONF_LABEL_KEYS = {
|
|||
};
|
||||
export default {
|
||||
name: "AgentSnapshotDialog",
|
||||
components: {
|
||||
CodeDiff
|
||||
},
|
||||
props: {
|
||||
visible: {
|
||||
type: Boolean,
|
||||
|
|
@ -1543,6 +1576,18 @@ export default {
|
|||
}
|
||||
return "text";
|
||||
},
|
||||
shouldUseCodeDiff(item) {
|
||||
return Boolean(
|
||||
item &&
|
||||
!item.single &&
|
||||
(item.displayType === "markdown" || item.complex || item.field === "summaryMemory")
|
||||
);
|
||||
},
|
||||
codeDiffLanguage(item) {
|
||||
return item?.displayType === "markdown" || item?.field === "summaryMemory"
|
||||
? "markdown"
|
||||
: "json";
|
||||
},
|
||||
valueClass(item) {
|
||||
return [`is-${item.displayType || "text"}`];
|
||||
},
|
||||
|
|
@ -2067,10 +2112,20 @@ export default {
|
|||
@import '@/styles/global.scss';
|
||||
|
||||
::v-deep .el-dialog {
|
||||
margin-top: 6vh !important;
|
||||
border-radius: 10px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
margin: 32px auto !important;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
||||
max-height: calc(100vh - 64px);
|
||||
}
|
||||
|
||||
::v-deep .el-dialog__wrapper {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
::v-deep .el-dialog__header {
|
||||
|
|
@ -2139,6 +2194,7 @@ export default {
|
|||
}
|
||||
|
||||
::v-deep .el-dialog__body {
|
||||
overflow-y: auto;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
|
|
@ -2273,7 +2329,7 @@ export default {
|
|||
|
||||
.snapshot-diff {
|
||||
min-height: 220px;
|
||||
max-height: 62vh;
|
||||
max-height: 68vh;
|
||||
overflow: auto;
|
||||
padding-right: 2px;
|
||||
@include scrollbar-style;
|
||||
|
|
@ -2341,6 +2397,12 @@ export default {
|
|||
border-left: 0;
|
||||
}
|
||||
|
||||
.diff-code-wrapper {
|
||||
padding: 0 14px 1px;
|
||||
text-align: left;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.diff-pane-title {
|
||||
margin-bottom: 8px;
|
||||
color: #3d4566;
|
||||
|
|
@ -2388,6 +2450,43 @@ export default {
|
|||
text-align: left;
|
||||
}
|
||||
|
||||
::v-deep .code-diff-view,
|
||||
::v-deep .code-diff-view .blob-num,
|
||||
::v-deep .code-diff-view .blob-code-inner,
|
||||
::v-deep .code-diff-view .file-header {
|
||||
font-family: Avenir, Helvetica, Arial, sans-serif;
|
||||
}
|
||||
|
||||
::v-deep .code-diff-view::-webkit-scrollbar {
|
||||
width: 6px;
|
||||
}
|
||||
|
||||
::v-deep .code-diff-view::-webkit-scrollbar-thumb {
|
||||
background: #a1c9fd;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
::v-deep .code-diff-view::-webkit-scrollbar-track {
|
||||
background: #f0f3fe;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
::v-deep .code-diff-view .blob-code-inner {
|
||||
font-size: 13px;
|
||||
line-height: 1.45;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
::v-deep .code-diff-view .hljs-emphasis,
|
||||
::v-deep .code-diff-view em {
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
::v-deep .code-diff-view .diff-table .blob-code-deletion .x,
|
||||
::v-deep .code-diff-view .diff-table .blob-code-addition .x {
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
.function-change-view {
|
||||
padding: 16px;
|
||||
background: #fff;
|
||||
|
|
|
|||
Loading…
Reference in a new issue