mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
fix(artifacts): render artifacts from the checked path and serve raw files once
- show_artifact returns the validated path as tool metadata; the chat card renders from it and maps repo paths with getWorkspaceFilePath, so local repos and moved sessions load the right file - serve .htm as text/html - raw file route stats and reads once and adds ETag/Last-Modified with 304 - reuse isPathWithinRoot from utils/fs-safe - move readShowArtifactCall to frontend/src/lib/artifactTool
This commit is contained in:
1 parent
f7b2ffb865
commit
5e2452172c
26 files changed
+489
-58
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { useState, useRef, useEffect, useMemo, memo } from 'react'
|
||||
import { unwrapSandboxExecCommand } from '@opencode-manager/shared/utils'
|
||||
import { readShowArtifactCall, toolContentText, type SessionMessageAssistantTool } from '@opencode-manager/shared/opencode'
|
||||
import { toolContentText, type SessionMessageAssistantTool } from '@opencode-manager/shared/opencode'
|
||||
import { useSettings } from '@/hooks/useSettings'
|
||||
import { useUserBash } from '@/stores/userBashStore'
|
||||
import { useChildLifecycleForSession } from '@/stores/sessionStatusStore'
|
||||
@@ -28,6 +28,8 @@ import {
|
||||
} from '@/lib/backgroundWork'
|
||||
import { getToolInputPath, getToolSpecificRender } from './FileToolRender'
|
||||
import { readOpenWalkthroughCall } from '@/lib/walkthroughTool'
|
||||
import { readShowArtifactCall } from '@/lib/artifactTool'
|
||||
import { getWorkspaceFilePath } from '@/lib/markdownLinks'
|
||||
import { getFileApiUrl } from '@/api/files'
|
||||
import { ArtifactPart } from './ArtifactPart'
|
||||
import type { WalkthroughSource } from '@opencode-manager/shared/schemas'
|
||||
@@ -63,6 +65,8 @@ interface ToolCallPartProps {
|
||||
part: SessionMessageAssistantTool
|
||||
messageID?: string
|
||||
directory?: string
|
||||
repoFullPath?: string
|
||||
repoLocalPath?: string
|
||||
shellOutcome?: ShellNoticeOutcome
|
||||
onFileClick?: (filePath: string, lineNumber?: number) => void
|
||||
onChildSessionClick?: (sessionId: string) => void
|
||||
@@ -119,7 +123,7 @@ function ClickableJson({ json, onFileClick }: { json: unknown; onFileClick?: (fi
|
||||
return <pre className="bg-accent p-2 rounded text-xs overflow-x-auto whitespace-pre-wrap break-words">{parts}</pre>
|
||||
}
|
||||
|
||||
export const ToolCallPart = memo(function ToolCallPart({ part, messageID, directory, shellOutcome, onFileClick, onChildSessionClick, onOpenWalkthrough }: ToolCallPartProps) {
|
||||
export const ToolCallPart = memo(function ToolCallPart({ part, messageID, directory, repoFullPath, repoLocalPath, shellOutcome, onFileClick, onChildSessionClick, onOpenWalkthrough }: ToolCallPartProps) {
|
||||
const { preferences } = useSettings()
|
||||
const { userBashCommands } = useUserBash()
|
||||
const isSubagent = part.name === 'subagent'
|
||||
@@ -254,11 +258,13 @@ export const ToolCallPart = memo(function ToolCallPart({ part, messageID, direct
|
||||
) : null
|
||||
|
||||
const artifact = readShowArtifactCall(part)
|
||||
if (artifact && (artifact.path.startsWith('/') || directory)) {
|
||||
const fullPath = artifact.path.startsWith('/')
|
||||
? artifact.path
|
||||
: `${directory?.replace(/\/+$/, '')}/${artifact.path}`
|
||||
return <ArtifactPart title={artifact.title} path={artifact.path} src={getFileApiUrl(fullPath, { params: { raw: true } })} />
|
||||
if (artifact && (artifact.resolvedPath || artifact.path.startsWith('/') || directory)) {
|
||||
const servedPath = getWorkspaceFilePath(artifact.resolvedPath ?? artifact.path, {
|
||||
directory,
|
||||
repoFullPath,
|
||||
repoLocalPath,
|
||||
})
|
||||
return <ArtifactPart title={artifact.title} path={artifact.path} src={getFileApiUrl(servedPath, { params: { raw: true } })} />
|
||||
}
|
||||
|
||||
if (isSubagent) {
|
||||
|
||||
Reference in new issue
Block a user