mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +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
@@ -395,7 +395,7 @@ describe('ToolCallPart show artifact action', () => {
|
||||
mocks.useToolCallPermission.mockReturnValue(null)
|
||||
})
|
||||
|
||||
const showArtifact = (params: unknown): SessionMessageAssistantTool => ({
|
||||
const showArtifact = (params: unknown, metadata?: Record<string, string>): SessionMessageAssistantTool => ({
|
||||
type: 'tool',
|
||||
id: 'call_artifact',
|
||||
name: 'ocm',
|
||||
@@ -404,6 +404,7 @@ describe('ToolCallPart show artifact action', () => {
|
||||
status: 'completed',
|
||||
input: { action: 'show_artifact', params },
|
||||
content: [{ type: 'text', text: 'Artifact shown' }],
|
||||
metadata,
|
||||
},
|
||||
})
|
||||
|
||||
@@ -433,6 +434,40 @@ describe('ToolCallPart show artifact action', () => {
|
||||
expect(link).toHaveAttribute('rel', 'noopener noreferrer')
|
||||
})
|
||||
|
||||
it('prefers the backend-resolved metadata path over the directory join', () => {
|
||||
const src = getFileApiUrl('/workspace/sessions/ses_1/report.html', { params: { raw: true } })
|
||||
|
||||
renderWithProviders(
|
||||
<ToolCallPart
|
||||
part={showArtifact(
|
||||
{ title: 'Report', path: 'reports/summary.html' },
|
||||
{ path: '/workspace/sessions/ses_1/report.html' },
|
||||
)}
|
||||
messageID="msg_1"
|
||||
directory="/repo"
|
||||
/>,
|
||||
)
|
||||
|
||||
expect(screen.getByTitle('Report')).toHaveAttribute('src', src)
|
||||
expect(screen.getByText('reports/summary.html')).toHaveAttribute('title', 'reports/summary.html')
|
||||
})
|
||||
|
||||
it('maps a repo path outside the workspace to the repo-local path', () => {
|
||||
const src = getFileApiUrl('assistant/reports/summary.html', { params: { raw: true } })
|
||||
|
||||
renderWithProviders(
|
||||
<ToolCallPart
|
||||
part={showArtifact({ title: 'Report', path: 'reports/summary.html' })}
|
||||
messageID="msg_1"
|
||||
directory="/workspace/repos/assistant"
|
||||
repoFullPath="/workspace/repos/assistant"
|
||||
repoLocalPath="assistant"
|
||||
/>,
|
||||
)
|
||||
|
||||
expect(screen.getByTitle('Report')).toHaveAttribute('src', src)
|
||||
})
|
||||
|
||||
it('resolves an absolute artifact path without a session directory', () => {
|
||||
const src = getFileApiUrl('/tmp/artifacts/report.html', { params: { raw: true } })
|
||||
|
||||
|
||||
Reference in new issue
Block a user