|
|
@@ -22,15 +22,14 @@
|
|
|
<div class="memory-card-heading">
|
|
|
<h3 class="memory-card-title">长期记忆</h3>
|
|
|
<p class="memory-card-sub">
|
|
|
- 记忆按用户隔离存放于智能体工作区:MEMORY.md 为合并后的长期记忆,memory/YYYY-MM-DD.md 为每日事实流水。
|
|
|
+ 记忆按用户隔离存放于智能体工作区:MEMORY.md 为合并后的长期记忆,memory/YYYY-MM-DD.md
|
|
|
+ 为每日事实流水。
|
|
|
保存后写入运行期配置,下一轮对话即按新策略重新装配生效。默认开启;关闭后保留已有记忆文件,但不再产生新的抽取与合并调用。
|
|
|
</p>
|
|
|
</div>
|
|
|
<div class="memory-card-actions">
|
|
|
<a-button @click="loadConfig">刷新</a-button>
|
|
|
- <a-button type="primary" :loading="configSaving" @click="handleSaveConfig">
|
|
|
- 保存
|
|
|
- </a-button>
|
|
|
+ <a-button type="primary" :loading="configSaving" @click="handleSaveConfig"> 保存 </a-button>
|
|
|
</div>
|
|
|
</div>
|
|
|
</template>
|
|
|
@@ -42,7 +41,9 @@
|
|
|
<template #label>
|
|
|
<span class="wb-label-tip">
|
|
|
启用长期记忆
|
|
|
- <a-tooltip title="开启后每轮对话结束异步抽取事实写入当日流水,并按节流策略合并进 MEMORY.md(会产生额外模型调用)。">
|
|
|
+ <a-tooltip
|
|
|
+ title="开启后每轮对话结束异步抽取事实写入当日流水,并按节流策略合并进 MEMORY.md(会产生额外模型调用)。"
|
|
|
+ >
|
|
|
<Icon icon="i-mdi:information-outline" class="wb-label-tip__icon" tabindex="0" />
|
|
|
</a-tooltip>
|
|
|
</span>
|
|
|
@@ -56,7 +57,9 @@
|
|
|
<template #label>
|
|
|
<span class="wb-label-tip">
|
|
|
记忆注入上限(Token)
|
|
|
- <a-tooltip title="MEMORY.md 等记忆内容注入 system prompt 的 Token 预算,超出时截断(框架默认 8000)。">
|
|
|
+ <a-tooltip
|
|
|
+ title="MEMORY.md 等记忆内容注入 system prompt 的 Token 预算,超出时截断(框架默认 8000)。"
|
|
|
+ >
|
|
|
<Icon icon="i-mdi:information-outline" class="wb-label-tip__icon" tabindex="0" />
|
|
|
</a-tooltip>
|
|
|
</span>
|
|
|
@@ -151,7 +154,9 @@
|
|
|
<template #label>
|
|
|
<span class="wb-label-tip">
|
|
|
每日流水保留天数
|
|
|
- <a-tooltip title="超过该天数的每日流水会移入 memory/archive/ 归档目录(默认 90 天),归档文件再按「归档保留天数」清理。">
|
|
|
+ <a-tooltip
|
|
|
+ title="超过该天数的每日流水会移入 memory/archive/ 归档目录(默认 90 天),归档文件再按「归档保留天数」清理。"
|
|
|
+ >
|
|
|
<Icon icon="i-mdi:information-outline" class="wb-label-tip__icon" tabindex="0" />
|
|
|
</a-tooltip>
|
|
|
</span>
|
|
|
@@ -212,28 +217,18 @@
|
|
|
<div class="memory-card-heading">
|
|
|
<h3 class="memory-card-title">记忆内容</h3>
|
|
|
<p class="memory-card-sub">
|
|
|
- 按智能体与用户查看、编辑记忆文件;「触发合并」立即把当日流水合并进 MEMORY.md(人工干预自动节流)。
|
|
|
+ 按智能体查看、编辑当前登录用户的记忆文件;「触发合并」立即把当日流水合并进
|
|
|
+ MEMORY.md(人工干预自动节流)。
|
|
|
</p>
|
|
|
</div>
|
|
|
<div class="memory-card-actions">
|
|
|
- <a-button
|
|
|
- :disabled="!currentCaseId || !query.agentId || !query.userId"
|
|
|
- @click="handleOpenVersions"
|
|
|
- >
|
|
|
- 版本历史
|
|
|
- </a-button>
|
|
|
+ <a-button :disabled="!currentCaseId || !query.agentId" @click="handleOpenVersions"> 版本历史 </a-button>
|
|
|
<a-button class="wb-btn-warning" :loading="consolidating" @click="handleConsolidate">
|
|
|
触发合并
|
|
|
</a-button>
|
|
|
- <a-button :loading="archiving" @click="handleArchive">
|
|
|
- 归档
|
|
|
- </a-button>
|
|
|
- <a-button :loading="cleaning" @click="handleCleanup">
|
|
|
- 清理
|
|
|
- </a-button>
|
|
|
- <a-button danger ghost :loading="removing" @click="handleRemove">
|
|
|
- 删除记忆
|
|
|
- </a-button>
|
|
|
+ <a-button :loading="archiving" @click="handleArchive"> 归档 </a-button>
|
|
|
+ <a-button :loading="cleaning" @click="handleCleanup"> 清理 </a-button>
|
|
|
+ <a-button danger ghost :loading="removing" @click="handleRemove"> 删除记忆 </a-button>
|
|
|
</div>
|
|
|
</div>
|
|
|
</template>
|
|
|
@@ -249,18 +244,7 @@
|
|
|
>
|
|
|
<a-select-option v-for="item in agentOptions" :key="item.id" :label="item.agentName" :value="item.id" />
|
|
|
</a-select>
|
|
|
- <a-select
|
|
|
- v-model:value="query.userId"
|
|
|
- class="memory-scope-select memory-scope-select--user"
|
|
|
- placeholder="选择用户"
|
|
|
- show-search
|
|
|
- option-filter-prop="label"
|
|
|
- :options="userSelectOptions"
|
|
|
- @change="handleScopeChange"
|
|
|
- />
|
|
|
- <a-button @click="handleScopeChange">
|
|
|
- 刷新文件
|
|
|
- </a-button>
|
|
|
+ <a-button @click="handleScopeChange"> 刷新文件 </a-button>
|
|
|
<span v-if="!form.enabled" class="filter-tip">长期记忆当前为关闭状态,以下为已落盘的历史记忆。</span>
|
|
|
</div>
|
|
|
|
|
|
@@ -336,11 +320,7 @@
|
|
|
</div>
|
|
|
<div class="memory-card-actions">
|
|
|
<a-button @click="loadDeclared">刷新</a-button>
|
|
|
- <a-button
|
|
|
- type="primary"
|
|
|
- :disabled="!currentCaseId || !query.agentId || !query.userId"
|
|
|
- @click="handleOpenDeclared"
|
|
|
- >
|
|
|
+ <a-button type="primary" :disabled="!currentCaseId || !query.agentId" @click="handleOpenDeclared">
|
|
|
新增
|
|
|
</a-button>
|
|
|
</div>
|
|
|
@@ -364,7 +344,13 @@
|
|
|
</a-tag>
|
|
|
</template>
|
|
|
<template v-else-if="column.key === 'action'">
|
|
|
- <a-button type="link" danger size="small" :disabled="record.revoked" @click="handleRevokeDeclared(record)">
|
|
|
+ <a-button
|
|
|
+ type="link"
|
|
|
+ danger
|
|
|
+ size="small"
|
|
|
+ :disabled="record.revoked"
|
|
|
+ @click="handleRevokeDeclared(record)"
|
|
|
+ >
|
|
|
撤销
|
|
|
</a-button>
|
|
|
</template>
|
|
|
@@ -550,9 +536,7 @@
|
|
|
<a-radio value="CONTENT">只恢复内容</a-radio>
|
|
|
<a-radio value="CONTENT_AND_WATERMARK">内容 + 合并水位</a-radio>
|
|
|
</a-radio-group>
|
|
|
- <div class="restore-tip">
|
|
|
- 只恢复内容时水位不变;同时恢复水位后,仍在 memory/ 的流水可能被重新合并。
|
|
|
- </div>
|
|
|
+ <div class="restore-tip"> 只恢复内容时水位不变;同时恢复水位后,仍在 memory/ 的流水可能被重新合并。 </div>
|
|
|
</a-form-item>
|
|
|
<a-form-item label="备注">
|
|
|
<a-input v-model:value="restoreForm.note" :maxlength="200" show-count placeholder="可选,记录本次恢复原因" />
|
|
|
@@ -569,24 +553,53 @@
|
|
|
<script lang="ts" setup name="WorkbenchAgentMemory">
|
|
|
import { computed, onMounted, reactive, ref, watch } from 'vue';
|
|
|
import {
|
|
|
- AAlert, AButton, ACard, AForm, AFormItem, AInput, AInputNumber, ARadio,
|
|
|
- ARadioButton, ARadioGroup, ASelect, ASelectOption, ASpin, ASwitch, ATabPane, ATable, ATabs, ATag,
|
|
|
- ATextarea, ATooltip, message, Modal,
|
|
|
+ AAlert,
|
|
|
+ AButton,
|
|
|
+ ACard,
|
|
|
+ AForm,
|
|
|
+ AFormItem,
|
|
|
+ AInput,
|
|
|
+ AInputNumber,
|
|
|
+ ARadio,
|
|
|
+ ARadioButton,
|
|
|
+ ARadioGroup,
|
|
|
+ ASelect,
|
|
|
+ ASelectOption,
|
|
|
+ ASpin,
|
|
|
+ ASwitch,
|
|
|
+ ATabPane,
|
|
|
+ ATable,
|
|
|
+ ATabs,
|
|
|
+ ATag,
|
|
|
+ ATextarea,
|
|
|
+ ATooltip,
|
|
|
+ message,
|
|
|
+ Modal,
|
|
|
} from '@/workbench/components/ant';
|
|
|
import { Icon } from '@/core/components/Icon';
|
|
|
import { BasicModal } from '@/core/components/Modal';
|
|
|
- import { useAccountStore } from '@/core/store/modules/account';
|
|
|
import { useUserStore } from '@/core/store/modules/case';
|
|
|
import { optionAgent } from '@/workbench/api/agent';
|
|
|
import {
|
|
|
- addDeclaredMemory, archiveMemory, cleanupMemory, consolidateMemory, getMemoryConfig, getMemoryContent,
|
|
|
- getMemoryQuality, getMemoryVersion, listDeclaredMemories, listMemoryFiles, listMemoryVersions,
|
|
|
- removeMemory, restoreMemoryVersion, revokeDeclaredMemory, updateMemoryConfig, updateMemoryContent,
|
|
|
+ addDeclaredMemory,
|
|
|
+ archiveMemory,
|
|
|
+ cleanupMemory,
|
|
|
+ consolidateMemory,
|
|
|
+ getMemoryConfig,
|
|
|
+ getMemoryContent,
|
|
|
+ getMemoryQuality,
|
|
|
+ getMemoryVersion,
|
|
|
+ listDeclaredMemories,
|
|
|
+ listMemoryFiles,
|
|
|
+ listMemoryVersions,
|
|
|
+ removeMemory,
|
|
|
+ restoreMemoryVersion,
|
|
|
+ revokeDeclaredMemory,
|
|
|
+ updateMemoryConfig,
|
|
|
+ updateMemoryContent,
|
|
|
} from '@/workbench/api/memory';
|
|
|
- import { listUser } from '@/workbench/api/user';
|
|
|
|
|
|
- const accountStore = useAccountStore();
|
|
|
- /** 案件上下文:长期记忆按案件隔离,所有读写都带当前案件 */
|
|
|
+ /** 案件上下文:长期记忆按案件隔离,所有读写都带当前案件;记忆归属用户由后端取当前登录用户 */
|
|
|
const userStore = useUserStore();
|
|
|
const currentCaseId = computed(() => String(userStore.getCaseInfo?.id || '').trim());
|
|
|
const caseName = computed(() => String(userStore.getCaseInfo?.name || '').trim());
|
|
|
@@ -626,8 +639,7 @@
|
|
|
};
|
|
|
|
|
|
const agentOptions = ref<any[]>([]);
|
|
|
- const userOptions = ref<any[]>([]);
|
|
|
- const query = reactive<{ agentId?: any; userId?: any }>({});
|
|
|
+ const query = reactive<{ agentId?: any }>({});
|
|
|
const files = ref<any[]>([]);
|
|
|
const fileLoading = ref(false);
|
|
|
const current = ref<{ path: string }>({ path: '' });
|
|
|
@@ -697,35 +709,6 @@
|
|
|
{ title: '操作', key: 'action', width: 150, align: 'center' },
|
|
|
];
|
|
|
|
|
|
- const userLabelOf = (item: any) => {
|
|
|
- const name = item.displayName || item.username || String(item.id ?? '');
|
|
|
- return item.username ? `${name}(${item.username})` : name;
|
|
|
- };
|
|
|
- const userSelectOptions = computed(() =>
|
|
|
- userOptions.value.map((item) => ({ label: userLabelOf(item), value: item.id })),
|
|
|
- );
|
|
|
-
|
|
|
- /** 用户下拉:系统用户列表接口仅管理员可用,失败时至少保留当前登录用户 */
|
|
|
- const loadUserOptions = async () => {
|
|
|
- const self = accountStore.getUserInfo;
|
|
|
- const selfOption = self?.id
|
|
|
- ? [{ id: self.id, username: self.username, displayName: self.displayName }]
|
|
|
- : [];
|
|
|
- try {
|
|
|
- const res: any = await listUser(undefined, 1, 500);
|
|
|
- const rows: any[] = res?.rows ?? res?.records ?? [];
|
|
|
- const merged = [...selfOption];
|
|
|
- rows.forEach((row) => {
|
|
|
- if (!merged.some((item) => String(item.id) === String(row.id))) {
|
|
|
- merged.push(row);
|
|
|
- }
|
|
|
- });
|
|
|
- userOptions.value = merged;
|
|
|
- } catch {
|
|
|
- userOptions.value = selfOption;
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
const customRow = (record: any) => ({
|
|
|
onClick: () => handleSelectFile(record),
|
|
|
});
|
|
|
@@ -749,8 +732,8 @@
|
|
|
message.warning('请先打开案件');
|
|
|
return false;
|
|
|
}
|
|
|
- if (!query.agentId || !query.userId) {
|
|
|
- message.warning('请先选择智能体与用户');
|
|
|
+ if (!query.agentId) {
|
|
|
+ message.warning('请先选择智能体');
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
@@ -765,13 +748,13 @@
|
|
|
|
|
|
/** 加载版本列表 */
|
|
|
const loadVersions = async () => {
|
|
|
- if (!currentCaseId.value || !query.agentId || !query.userId) {
|
|
|
+ if (!currentCaseId.value || !query.agentId) {
|
|
|
versions.value = [];
|
|
|
return;
|
|
|
}
|
|
|
versionLoading.value = true;
|
|
|
try {
|
|
|
- const res = await listMemoryVersions(currentCaseId.value, query.agentId, query.userId);
|
|
|
+ const res = await listMemoryVersions(currentCaseId.value, query.agentId);
|
|
|
versions.value = res ?? [];
|
|
|
} finally {
|
|
|
versionLoading.value = false;
|
|
|
@@ -781,13 +764,7 @@
|
|
|
/** 查看版本正文 */
|
|
|
const handleViewVersion = async (row: any) => {
|
|
|
if (!requireScope()) return;
|
|
|
- versionDetail.value =
|
|
|
- (await getMemoryVersion(
|
|
|
- row.versionId,
|
|
|
- currentCaseId.value,
|
|
|
- query.agentId,
|
|
|
- query.userId,
|
|
|
- )) ?? null;
|
|
|
+ versionDetail.value = (await getMemoryVersion(row.versionId, currentCaseId.value, query.agentId)) ?? null;
|
|
|
versionDetailVisible.value = true;
|
|
|
};
|
|
|
|
|
|
@@ -807,7 +784,6 @@
|
|
|
const payload = {
|
|
|
caseId: currentCaseId.value,
|
|
|
agentId: query.agentId,
|
|
|
- userId: query.userId,
|
|
|
mode: restoreForm.value.mode,
|
|
|
note: restoreForm.value.note,
|
|
|
};
|
|
|
@@ -854,54 +830,45 @@
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- /** 加载智能体与用户下拉(用户列表复用系统用户接口) */
|
|
|
+ /** 加载智能体下拉,并把查看用户固定为当前登录用户(记忆只允许本人查看) */
|
|
|
const loadOptions = async () => {
|
|
|
const res = await optionAgent();
|
|
|
agentOptions.value = res ?? [];
|
|
|
if (agentOptions.value.length) {
|
|
|
query.agentId = agentOptions.value[0].id;
|
|
|
}
|
|
|
- await loadUserOptions();
|
|
|
- if (userOptions.value.length) {
|
|
|
- query.userId = userOptions.value[0].id;
|
|
|
- }
|
|
|
};
|
|
|
|
|
|
- /** 加载记忆文件清单(切换智能体 / 用户后调用) */
|
|
|
+ /** 加载记忆文件清单(切换智能体后调用) */
|
|
|
const loadFiles = async () => {
|
|
|
current.value = { path: '' };
|
|
|
content.value = '';
|
|
|
- if (!currentCaseId.value || !query.agentId || !query.userId) {
|
|
|
+ if (!currentCaseId.value || !query.agentId) {
|
|
|
files.value = [];
|
|
|
return;
|
|
|
}
|
|
|
fileLoading.value = true;
|
|
|
try {
|
|
|
- const res = await listMemoryFiles(currentCaseId.value, query.agentId, query.userId);
|
|
|
+ const res = await listMemoryFiles(currentCaseId.value, query.agentId);
|
|
|
files.value = res ?? [];
|
|
|
} finally {
|
|
|
fileLoading.value = false;
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- /** 切换智能体或用户 */
|
|
|
+ /** 切换智能体 */
|
|
|
const handleScopeChange = async () => {
|
|
|
await Promise.all([loadFiles(), loadDeclared(), loadQuality()]);
|
|
|
};
|
|
|
|
|
|
/** 加载运行健康指标(按天窗口) */
|
|
|
const loadQuality = async () => {
|
|
|
- if (!currentCaseId.value || !query.userId) {
|
|
|
+ if (!currentCaseId.value) {
|
|
|
return;
|
|
|
}
|
|
|
qualityLoading.value = true;
|
|
|
try {
|
|
|
- const res = await getMemoryQuality(
|
|
|
- currentCaseId.value,
|
|
|
- query.agentId,
|
|
|
- query.userId,
|
|
|
- qualityDays.value,
|
|
|
- );
|
|
|
+ const res = await getMemoryQuality(currentCaseId.value, query.agentId, qualityDays.value);
|
|
|
if (res) {
|
|
|
quality.value = res;
|
|
|
}
|
|
|
@@ -925,17 +892,13 @@
|
|
|
|
|
|
/** 加载显式记忆(含已撤销条目,便于审计) */
|
|
|
const loadDeclared = async () => {
|
|
|
- if (!currentCaseId.value || !query.agentId || !query.userId) {
|
|
|
+ if (!currentCaseId.value || !query.agentId) {
|
|
|
declared.value = [];
|
|
|
return;
|
|
|
}
|
|
|
declaredLoading.value = true;
|
|
|
try {
|
|
|
- const res = await listDeclaredMemories(
|
|
|
- currentCaseId.value,
|
|
|
- query.agentId,
|
|
|
- query.userId,
|
|
|
- );
|
|
|
+ const res = await listDeclaredMemories(currentCaseId.value, query.agentId);
|
|
|
declared.value = res ?? [];
|
|
|
} finally {
|
|
|
declaredLoading.value = false;
|
|
|
@@ -961,7 +924,6 @@
|
|
|
await addDeclaredMemory({
|
|
|
caseId: currentCaseId.value,
|
|
|
agentId: query.agentId,
|
|
|
- userId: query.userId,
|
|
|
fact: declaredForm.value.fact.trim(),
|
|
|
evidence: declaredForm.value.evidence.trim(),
|
|
|
});
|
|
|
@@ -989,28 +951,18 @@
|
|
|
if (!ok) {
|
|
|
return;
|
|
|
}
|
|
|
- await revokeDeclaredMemory(
|
|
|
- row.id,
|
|
|
- currentCaseId.value,
|
|
|
- query.agentId,
|
|
|
- query.userId,
|
|
|
- );
|
|
|
+ await revokeDeclaredMemory(row.id, currentCaseId.value, query.agentId);
|
|
|
message.success('已撤销');
|
|
|
await loadDeclared();
|
|
|
};
|
|
|
|
|
|
/** 选中文件并加载内容 */
|
|
|
const handleSelectFile = async (row?: any) => {
|
|
|
- if (!row?.path || !currentCaseId.value || !query.agentId || !query.userId) {
|
|
|
+ if (!row?.path || !currentCaseId.value || !query.agentId) {
|
|
|
return;
|
|
|
}
|
|
|
current.value = { path: row.path };
|
|
|
- const res = await getMemoryContent(
|
|
|
- currentCaseId.value,
|
|
|
- query.agentId,
|
|
|
- query.userId,
|
|
|
- row.path,
|
|
|
- );
|
|
|
+ const res = await getMemoryContent(currentCaseId.value, query.agentId, row.path);
|
|
|
content.value = res?.content ?? '';
|
|
|
};
|
|
|
|
|
|
@@ -1024,7 +976,6 @@
|
|
|
await updateMemoryContent({
|
|
|
caseId: currentCaseId.value,
|
|
|
agentId: query.agentId,
|
|
|
- userId: query.userId,
|
|
|
path: current.value.path,
|
|
|
content: content.value,
|
|
|
});
|
|
|
@@ -1045,7 +996,7 @@
|
|
|
}
|
|
|
consolidating.value = true;
|
|
|
try {
|
|
|
- await consolidateMemory(currentCaseId.value, query.agentId, query.userId);
|
|
|
+ await consolidateMemory(currentCaseId.value, query.agentId);
|
|
|
message.success('记忆合并已完成');
|
|
|
await Promise.all([loadFiles(), loadQuality()]);
|
|
|
} finally {
|
|
|
@@ -1062,7 +1013,7 @@
|
|
|
if (!requireScope()) return;
|
|
|
archiving.value = true;
|
|
|
try {
|
|
|
- const res = await archiveMemory(currentCaseId.value, query.agentId, query.userId);
|
|
|
+ const res = await archiveMemory(currentCaseId.value, query.agentId);
|
|
|
message.success(`已归档 ${res ?? 0} 个流水文件`);
|
|
|
await loadFiles();
|
|
|
} finally {
|
|
|
@@ -1075,7 +1026,7 @@
|
|
|
if (!requireScope()) return;
|
|
|
cleaning.value = true;
|
|
|
try {
|
|
|
- const res = await cleanupMemory(currentCaseId.value, query.agentId, query.userId);
|
|
|
+ const res = await cleanupMemory(currentCaseId.value, query.agentId);
|
|
|
message.success(`已清理 ${res ?? 0} 个文件`);
|
|
|
await loadFiles();
|
|
|
} finally {
|
|
|
@@ -1089,7 +1040,8 @@
|
|
|
const ok = await new Promise<boolean>((resolve) => {
|
|
|
Modal.confirm({
|
|
|
title: '提示',
|
|
|
- content: '将删除该用户在小Z 与专家侧共用的全部长期记忆(MEMORY.md 与每日流水),且不可恢复。确认继续?',
|
|
|
+ content:
|
|
|
+ '将删除你(当前登录用户)在小Z 与专家侧共用的全部长期记忆(MEMORY.md 与每日流水),且不可恢复。确认继续?',
|
|
|
okText: '确定',
|
|
|
cancelText: '取消',
|
|
|
onOk: () => resolve(true),
|
|
|
@@ -1101,7 +1053,7 @@
|
|
|
}
|
|
|
removing.value = true;
|
|
|
try {
|
|
|
- await removeMemory(currentCaseId.value, query.agentId, query.userId);
|
|
|
+ await removeMemory(currentCaseId.value, query.agentId);
|
|
|
message.success('长期记忆已删除');
|
|
|
await Promise.all([loadFiles(), loadDeclared()]);
|
|
|
} finally {
|
|
|
@@ -1351,10 +1303,6 @@
|
|
|
width: 220px;
|
|
|
}
|
|
|
|
|
|
- .memory-scope-select--user {
|
|
|
- width: 260px;
|
|
|
- }
|
|
|
-
|
|
|
.memory-scope-bar :deep(.ant-select-selector) {
|
|
|
height: 32px !important;
|
|
|
padding: 0 10px;
|