mirror of
https://github.com/NanmiCoder/claude-code-haha.git
synced 2026-10-10 11:53:10 +08:00
feat(desktop): preview documents in the workspace and images in chat
Documents the agent writes open in the workspace panel instead of another application, and local images the agent mentions show up in the conversation. Workspace preview - PDF (pdf.js with its own layout and text layer), Word (docx-preview inside a scripts-disabled sandboxed iframe) and Excel (SheetJS; .xlsx, .xlsm, .xls) open in the side panel with zoom and fit, per-file scroll/zoom/sheet memory, and a refresh when the agent rewrites the file. The engines load lazily. - Bytes come from a new GET /api/sessions/:id/workspace/raw route, with an extension allowlist, size caps, the workspace boundary and canonical-path checks. The file endpoint returns metadata and a version for documents. The client fetches with the bearer credential, so it works in Electron, LAN H5 and remote access alike. - Chat links, output cards and the change card open pdf/docx/xlsx in the workspace; documents outside the workdir still go to the system application. - Image viewer with fit, zoom and pan, and "open in system app". Chat images - Markdown images outside the workdir, at ~/, C:\ and file:// paths render, open in the viewer, and offer "open original" (pictures only). - Images returned by tools such as Read appear as thumbnails under the call. Hardening found in review - previewFsUrl escapes each path segment; a double-escaped %2e%2e used to leave /preview-fs/<session>/. - The CORS, API timing and remote-access header decorators set headers in place. Rebuilding the response buffered whole files in memory and dropped Content-Length. - The engine owns the pdf.js worker, so closing one document no longer fails the next open. - Office archives are inflated in steps to check their real sizes, not the sizes they declare. - A viewer that fails to load stays in its panel instead of taking the window down. Adds pdfjs-dist, docx-preview, xlsx (SheetJS 0.20.3 tarball) and fflate as renderer dev dependencies; Vite bundles them. Refs #1397
This commit is contained in:
@@ -73,6 +73,15 @@ describe('specifier resolution', () => {
|
||||
|
||||
test('returns null for unresolvable asset imports instead of inventing an edge', () => {
|
||||
expect(resolveSpecifier(root, 'desktop/src/pages/Page.tsx', '../assets/logo.png', files)).toBeNull()
|
||||
expect(resolveSpecifier(root, 'desktop/src/pages/Page.tsx', '../assets/logo.png?url', files)).toBeNull()
|
||||
})
|
||||
|
||||
test('reads a Vite query suffix as the module it names, so a worker still selects its importer', () => {
|
||||
// `import Worker from './service?worker'` is an edge to service.ts: without it, a
|
||||
// change to the worker's source selects nothing for the module that starts it.
|
||||
expect(resolveSpecifier(root, 'src/entry.ts', './service?worker', files)).toBe('src/service.ts')
|
||||
expect(resolveSpecifier(root, 'src/entry.ts', './service?worker&inline', files)).toBe('src/service.ts')
|
||||
expect(resolveSpecifier(root, 'desktop/src/pages/Page.tsx', '@/lib/alias?url', files)).toBe('desktop/src/lib/alias.ts')
|
||||
})
|
||||
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
|
||||
@@ -113,9 +113,12 @@ export function resolveSpecifier(
|
||||
specifier: string,
|
||||
fileSet: ReadonlySet<string>,
|
||||
): string | null {
|
||||
const base = specifier.startsWith('@/')
|
||||
? join(rootDir, 'desktop', 'src', specifier.slice(2))
|
||||
: resolve(join(rootDir, dirname(fromFile)), specifier)
|
||||
// A Vite query (`./pdf.worker?worker`, `./chunk?url`) names the same module as the
|
||||
// bare path: a change to that module must still select its importer's checks.
|
||||
const bare = specifier.replace(/\?.*$/, '')
|
||||
const base = bare.startsWith('@/')
|
||||
? join(rootDir, 'desktop', 'src', bare.slice(2))
|
||||
: resolve(join(rootDir, dirname(fromFile)), bare)
|
||||
|
||||
const candidates: string[] = [base]
|
||||
for (const extension of RESOLUTION_EXTENSIONS) {
|
||||
|
||||
Reference in New Issue
Block a user