Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions cosight_server/web/js/dag.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ function initDAG() {
// 添加节点文本
node.append("text")
.attr("class", "node-text")
.attr("id", d => d.id)
.text(d => d.name);

// 添加状态图标
Expand Down Expand Up @@ -523,7 +524,7 @@ function createDag(messageData) {
try {
// 解析消息数据
const initData = messageData.data.initData;

// 新会话检测:当 changeType=replace 或 话题/uuid 变化时,重置缓存
// try {
// const changeType = messageData.data && messageData.data.changeType;
Expand All @@ -535,7 +536,7 @@ function createDag(messageData) {
// const currentKey = `${topic || ''}__${uuid || ''}`;
// const lastSessionKey = localStorage.getItem(lastKey);

// const isNewSession = changeType === 'replace' ||
// const isNewSession = changeType === 'replace' ||
// (currentKey && lastSessionKey !== currentKey && topic !== 'restored');

// if (isNewSession && typeof window !== 'undefined' && typeof window.resetSessionCaches === 'function') {
Expand Down Expand Up @@ -568,25 +569,25 @@ function createDag(messageData) {
arr.forEach(v => depValues.push(parseInt(v)));
}
});

const minKey = depKeys.length ? Math.min(...depKeys) : 1;
const minVal = depValues.length ? Math.min(...depValues.filter(Number.isInteger)) : 1;
const isKeyZeroBased = minKey === 0;
const isValZeroBased = minVal === 0;

// 构建节点数据
const nodes = initData.steps.map((step, index) => {
const stepId = index + 1; // 步骤ID始终是1-based

// 查找这个步骤的依赖关系
let dependencies = [];

// 遍历dependencies,找到以当前步骤为目标的依赖关系
Object.keys(initData.dependencies || {}).forEach(targetKey => {
const targetIndex = parseInt(targetKey);
// 目标ID:若键或值任一为0基,则+1;否则保持不变(1基)
const actualTargetId = (isKeyZeroBased || isValZeroBased) ? targetIndex + 1 : targetIndex;

if (actualTargetId === stepId) {
// 找到了以当前步骤为目标的依赖
const sourceDeps = initData.dependencies[targetKey];
Expand All @@ -604,9 +605,9 @@ function createDag(messageData) {
}
}
});

console.log(`步骤${stepId}的依赖:`, dependencies);

return {
id: stepId,
name: `step${stepId}`,
Expand Down
14 changes: 7 additions & 7 deletions cosight_server/web/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ function calculateOptimalPanelTop(panel, nodeRect) {
function findNodeElement(nodeId) {
const nodeTexts = document.querySelectorAll('.node-text');
for (let textElement of nodeTexts) {
if (textElement.textContent.includes(`Step ${nodeId}`)) {
if (textElement.id == nodeId) {
return textElement.closest('.node');
}
}
Expand Down Expand Up @@ -1373,18 +1373,18 @@ function checkAndRestoreDAGData() {
const lastManusStep = getLastManusStepMessage();
if (lastManusStep) {
console.log('发现保存的DAG数据,开始恢复...');

// 恢复DAG图
const result = createDag({ data: lastManusStep.data, topic: 'restored' });
if (result) {
// 显示标题
if (lastManusStep.data.initData && lastManusStep.data.initData.title) {
updateDynamicTitle(lastManusStep.data.initData.title);
}

// 显示主界面
hideInitialInputAndShowMain('');

console.log('DAG数据恢复完成');
}
}
Expand Down Expand Up @@ -1955,12 +1955,12 @@ function resetUICaches() {
});
if (nodeToolPanels.clear) nodeToolPanels.clear();
}

// 清理MessageService的tool events
if (window.messageService && typeof window.messageService.clearStepToolEvents === 'function') {
window.messageService.clearStepToolEvents();
}

// 右侧内容与资源清理
try { cleanupAllResources(); } catch (_) {}

Expand All @@ -1969,7 +1969,7 @@ function resetUICaches() {
if (container) {
container.innerHTML = '';
}

console.log('[UI] 缓存已重置(保留localStorage数据)');
} catch (e) {
console.warn('重置UI缓存时发生异常:', e);
Expand Down