From dd7cfc8db3a90eb02bce09e53da21daa17298ca1 Mon Sep 17 00:00:00 2001 From: zerob13 Date: Wed, 13 Aug 2025 14:33:48 +0800 Subject: [PATCH 1/4] fix: artifact react load failed --- src/main/index.ts | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main/index.ts b/src/main/index.ts index b1eecdefc..08e8b504e 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -156,17 +156,18 @@ app.whenReady().then(async () => { // 注册 'deepcdn' 协议,用于加载应用内置资源 (模拟 CDN) protocol.handle('deepcdn', (request) => { try { + console.log('deepcdn', request.url) const filePath = request.url.slice('deepcdn://'.length) - // 根据开发/生产环境确定资源路径 - const resourcesPath = is.dev - ? path.join(app.getAppPath(), 'resources') - : process.resourcesPath - // 检查资源是否被解包 (app.asar.unpacked),优先使用解包路径 - const unpackedResourcesPath = path.join(resourcesPath, 'app.asar.unpacked', 'resources') - - const baseResourcesDir = fs.existsSync(unpackedResourcesPath) - ? unpackedResourcesPath - : path.join(resourcesPath, 'resources') // 否则使用默认资源路径 + // 根据开发/生产环境确定资源路径(按候选目录探测,避免错误拼接导致重复 resources) + const candidates = is.dev + ? [path.join(app.getAppPath(), 'resources')] + : [ + path.join(process.resourcesPath, 'app.asar.unpacked', 'resources'), + path.join(process.resourcesPath, 'resources'), + process.resourcesPath + ] + const baseResourcesDir = + candidates.find((p) => fs.existsSync(path.join(p, 'cdn'))) || candidates[0] const fullPath = path.join(baseResourcesDir, 'cdn', filePath) From 8173120e266a535372434eb053214160af6a9064 Mon Sep 17 00:00:00 2001 From: zerob13 Date: Wed, 13 Aug 2025 15:03:53 +0800 Subject: [PATCH 2/4] chore: remove log --- src/main/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/index.ts b/src/main/index.ts index 08e8b504e..2e7b21a46 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -156,7 +156,7 @@ app.whenReady().then(async () => { // 注册 'deepcdn' 协议,用于加载应用内置资源 (模拟 CDN) protocol.handle('deepcdn', (request) => { try { - console.log('deepcdn', request.url) + // console.log('deepcdn', request.url) const filePath = request.url.slice('deepcdn://'.length) // 根据开发/生产环境确定资源路径(按候选目录探测,避免错误拼接导致重复 resources) const candidates = is.dev From bce4329a5ce8db3cd5e0d6cae32d79f2cb95866a Mon Sep 17 00:00:00 2001 From: zerob13 Date: Wed, 13 Aug 2025 15:59:15 +0800 Subject: [PATCH 3/4] fix: artifacts code not stream --- package.json | 2 +- .../components/artifacts/ArtifactDialog.vue | 36 ++++++++++++++----- .../message/MessageBlockContent.vue | 22 +++++++----- src/renderer/src/stores/artifact.ts | 13 ++++++- 4 files changed, 55 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 8414d80b4..78ed24227 100644 --- a/package.json +++ b/package.json @@ -158,7 +158,7 @@ "vue-i18n": "^11.1.11", "vue-router": "4", "vue-tsc": "^2.2.10", - "vue-use-monaco": "^0.0.6", + "vue-use-monaco": "^0.0.8", "vue-virtual-scroller": "^2.0.0-beta.8", "vuedraggable": "^4.1.0", "yaml": "^2.8.0", diff --git a/src/renderer/src/components/artifacts/ArtifactDialog.vue b/src/renderer/src/components/artifacts/ArtifactDialog.vue index d9fdc2b0d..54b91766a 100644 --- a/src/renderer/src/components/artifacts/ArtifactDialog.vue +++ b/src/renderer/src/components/artifacts/ArtifactDialog.vue @@ -162,7 +162,7 @@ const appVersion = ref('') const codeLanguage = ref( artifactStore.currentArtifact?.language || artifactStore.currentArtifact?.type || '' ) -const { createEditor, updateCode } = useMonaco() +const { createEditor, updateCode } = useMonaco({ MAX_HEIGHT: '500px'}) const codeEditor = ref(null) // 创建节流版本的语言检测函数,1秒内最多执行一次 @@ -176,24 +176,31 @@ const throttledDetectLanguage = useThrottleFn( watch( () => artifactStore.currentArtifact, - () => { - // 如果当前 artifact 的语言已经被检测过了,就不再进行检测 + (newArtifact) => { + if (!newArtifact) return + + // Update language detection codeLanguage.value = - artifactStore.currentArtifact?.language || - getFileExtension(artifactStore.currentArtifact?.type || '') + newArtifact.language || + getFileExtension(newArtifact.type || '') + if (codeLanguage.value === 'mermaid') { return } - const newCode = artifactStore.currentArtifact?.content || '' + + const newCode = newArtifact.content || '' // Check if we need to detect language if (!codeLanguage.value || codeLanguage.value === '') { throttledDetectLanguage(newCode) } - updateCode(artifactStore.currentArtifact?.content || '', codeLanguage.value) + + // Always update Monaco editor content + updateCode(newCode, codeLanguage.value) }, { - immediate: true + immediate: true, + deep: true // Add deep watching to catch property changes } ) @@ -209,6 +216,19 @@ watch( } ) +// Add a specific watcher for content changes to ensure real-time updates +watch( + () => artifactStore.currentArtifact?.content, + (newContent) => { + if (newContent !== undefined) { + updateCode(newContent, codeLanguage.value) + } + }, + { + immediate: true + } +) + watch( () => codeEditor.value, () => { diff --git a/src/renderer/src/components/message/MessageBlockContent.vue b/src/renderer/src/components/message/MessageBlockContent.vue index 4f1ff2c30..eb4b20f6a 100644 --- a/src/renderer/src/components/message/MessageBlockContent.vue +++ b/src/renderer/src/components/message/MessageBlockContent.vue @@ -71,10 +71,13 @@ watch( if (part.type === 'artifact' && part.artifact) { if (props.block.status === 'loading') { if (artifactStore.currentArtifact?.id === part.artifact.identifier) { - artifactStore.currentArtifact.content = part.content - artifactStore.currentArtifact.title = part.artifact.title - artifactStore.currentArtifact.type = part.artifact.type - artifactStore.currentArtifact.status = part.loading ? 'loading' : 'loaded' + // Use updateArtifactContent to trigger reactivity + artifactStore.updateArtifactContent({ + content: part.content, + title: part.artifact.title, + type: part.artifact.type, + status: part.loading ? 'loading' : 'loaded' + }) } else { artifactStore.showArtifact( { @@ -91,10 +94,13 @@ watch( } } else { if (artifactStore.currentArtifact?.id === part.artifact.identifier) { - artifactStore.currentArtifact.content = part.content - artifactStore.currentArtifact.title = part.artifact.title - artifactStore.currentArtifact.type = part.artifact.type - artifactStore.currentArtifact.status = 'loaded' + // Use updateArtifactContent to trigger reactivity + artifactStore.updateArtifactContent({ + content: part.content, + title: part.artifact.title, + type: part.artifact.type, + status: 'loaded' + }) } } } diff --git a/src/renderer/src/stores/artifact.ts b/src/renderer/src/stores/artifact.ts index 8e252d751..784fef3d7 100644 --- a/src/renderer/src/stores/artifact.ts +++ b/src/renderer/src/stores/artifact.ts @@ -34,6 +34,16 @@ export const useArtifactStore = defineStore('artifact', () => { return currentMessageId.value === messageId && currentThreadId.value === threadId } + const updateArtifactContent = (updates: Partial) => { + if (currentArtifact.value) { + // Create a new object to trigger reactivity + currentArtifact.value = { + ...currentArtifact.value, + ...updates + } + } + } + return { currentArtifact, currentMessageId, @@ -41,6 +51,7 @@ export const useArtifactStore = defineStore('artifact', () => { isOpen, showArtifact, hideArtifact, - validateContext + validateContext, + updateArtifactContent } }) From 928d744daefda357bc4e093524cca9388d5b40e8 Mon Sep 17 00:00:00 2001 From: zerob13 Date: Wed, 13 Aug 2025 16:04:50 +0800 Subject: [PATCH 4/4] fix: format --- src/renderer/src/components/artifacts/ArtifactDialog.vue | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/renderer/src/components/artifacts/ArtifactDialog.vue b/src/renderer/src/components/artifacts/ArtifactDialog.vue index 54b91766a..6e311b4c1 100644 --- a/src/renderer/src/components/artifacts/ArtifactDialog.vue +++ b/src/renderer/src/components/artifacts/ArtifactDialog.vue @@ -162,7 +162,7 @@ const appVersion = ref('') const codeLanguage = ref( artifactStore.currentArtifact?.language || artifactStore.currentArtifact?.type || '' ) -const { createEditor, updateCode } = useMonaco({ MAX_HEIGHT: '500px'}) +const { createEditor, updateCode } = useMonaco({ MAX_HEIGHT: '500px' }) const codeEditor = ref(null) // 创建节流版本的语言检测函数,1秒内最多执行一次 @@ -180,9 +180,7 @@ watch( if (!newArtifact) return // Update language detection - codeLanguage.value = - newArtifact.language || - getFileExtension(newArtifact.type || '') + codeLanguage.value = newArtifact.language || getFileExtension(newArtifact.type || '') if (codeLanguage.value === 'mermaid') { return