diff --git a/dashboard/package.json b/dashboard/package.json index 81a353bf2d..172791fc02 100644 --- a/dashboard/package.json +++ b/dashboard/package.json @@ -35,6 +35,7 @@ "markstream-vue": "1.0.5-beta.0", "mermaid": "^11.12.2", "monaco-editor": "^0.52.2", + "pdfjs-dist": "6.3.289", "pinia": "2.1.6", "pinyin-pro": "^3.26.0", "qrcode": "^1.5.4", diff --git a/dashboard/pnpm-lock.yaml b/dashboard/pnpm-lock.yaml index cae4d6bc12..ff1ab0450b 100644 --- a/dashboard/pnpm-lock.yaml +++ b/dashboard/pnpm-lock.yaml @@ -69,6 +69,9 @@ importers: monaco-editor: specifier: ^0.52.2 version: 0.52.2 + pdfjs-dist: + specifier: 6.3.289 + version: 6.3.289 pinia: specifier: 2.1.6 version: 2.1.6(typescript@5.1.6)(vue@3.3.4) @@ -518,6 +521,81 @@ packages: '@monaco-editor/loader@1.7.0': resolution: {integrity: sha512-gIwR1HrJrrx+vfyOhYmCZ0/JcWqG5kbfG7+d3f/C1LXk2EvzAbHSg3MQ5lO2sMlo9izoAZ04shohfKLVT6crVA==} + '@napi-rs/canvas-android-arm64@1.0.9': + resolution: {integrity: sha512-4LGXk2/0HVzE29K8SzML5WubgCp++B1FH3qgl35XmSZE+lLdr6P9VRQEnZ0MCLZMTSuJP41yyhtoiVNEuvrTIA==} + engines: {node: '>= 10'} + cpu: [arm64] + os: [android] + + '@napi-rs/canvas-darwin-arm64@1.0.9': + resolution: {integrity: sha512-YNdfLBzY0W/Pep9fo2L6RmoNlNksnn05LRnX66W63R3ij58S25QOTcjdtEt2v8+PnCESzqZsYzUo+QPeIR44NA==} + engines: {node: '>= 10'} + cpu: [arm64] + os: [darwin] + + '@napi-rs/canvas-darwin-x64@1.0.9': + resolution: {integrity: sha512-ceZQSknTEcy3dOXoekv59LTCkXjvnLsq+VW5PeNNDHEPQbRS5Ervkm1EaDa7WLAjiYWMLuSQTRTHao1dEX4prg==} + engines: {node: '>= 10'} + cpu: [x64] + os: [darwin] + + '@napi-rs/canvas-linux-arm-gnueabihf@1.0.9': + resolution: {integrity: sha512-XhfI0Wwv4llhd6nnWDtY3kQKjq0r+y1i91PlJlJI24ag2U9WrnwbG1qS3+fDLEyouwEVFchiKkTEHozK+5iUNA==} + engines: {node: '>= 10'} + cpu: [arm] + os: [linux] + + '@napi-rs/canvas-linux-arm64-gnu@1.0.9': + resolution: {integrity: sha512-012oiYtKaE7i9oxc8q7nraT7kDOpLcaCmFLzVe9Ty34RHDdoDzbWLrVh827CNxYh/EADX1eSikA3ymLjo/nNuw==} + engines: {node: '>= 10'} + cpu: [arm64] + os: [linux] + libc: [glibc] + + '@napi-rs/canvas-linux-arm64-musl@1.0.9': + resolution: {integrity: sha512-Ls5UWYFFn63casTZEczbeyEg3vRDRkv9lscuGwfchtY5yLLQhgOB8SN4YGxmfJ5vTaBwZ2YUxBS3NtmjJmFXdA==} + engines: {node: '>= 10'} + cpu: [arm64] + os: [linux] + libc: [musl] + + '@napi-rs/canvas-linux-riscv64-gnu@1.0.9': + resolution: {integrity: sha512-hLKEGxV7ZiRHqndePTokgDMdBlo/rDfzg7P4p4QIv9pUhuYobnu3R2NIFLCRghG0nwfo+s2sw+c1xZFeCmEAsw==} + engines: {node: '>= 10'} + cpu: [riscv64] + os: [linux] + libc: [glibc] + + '@napi-rs/canvas-linux-x64-gnu@1.0.9': + resolution: {integrity: sha512-6kaz3w0QMy77PDWk6rJ1ksIihdad3qzEyX2o2oGT8GwCaypfT5mhjr8buOO5hstyLxcWXDScuz56RsINLtBPIQ==} + engines: {node: '>= 10'} + cpu: [x64] + os: [linux] + libc: [glibc] + + '@napi-rs/canvas-linux-x64-musl@1.0.9': + resolution: {integrity: sha512-xrGvmS3v55hmZ86ls/kBLVNMUTYio3f6Ik0DireemG994VfPAwiA3ZXA0Uf1bByctkB3NQ1Sfb+H5bkdUnnzfQ==} + engines: {node: '>= 10'} + cpu: [x64] + os: [linux] + libc: [musl] + + '@napi-rs/canvas-win32-arm64-msvc@1.0.9': + resolution: {integrity: sha512-yjmVS3ArZeRVCP7jqbPq4rpZa/BhTeI7ELE2XqJg3snICQBDevLZyArxswHkiTnT34KRic33/4fLirrHI+SY8A==} + engines: {node: '>= 10'} + cpu: [arm64] + os: [win32] + + '@napi-rs/canvas-win32-x64-msvc@1.0.9': + resolution: {integrity: sha512-QlSYQdMQslB81nlABo9wNfQ6npFhE7/O+saCZdqVGueGanyRk4jCogD5EwQenfP3kIq9e+mm6GreQBjX5MrA8g==} + engines: {node: '>= 10'} + cpu: [x64] + os: [win32] + + '@napi-rs/canvas@1.0.9': + resolution: {integrity: sha512-QviPdJImDi/jMAvBfqaw+19BndMd/sizXVW3NnpMd3VJGz++QXkOHcP9kWR/smHG0hNjHeyuHFyrx/5lD0oNcQ==} + engines: {node: '>= 10'} + '@nodelib/fs.scandir@2.1.5': resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==} engines: {node: '>= 8'} @@ -2451,6 +2529,10 @@ packages: pathe@2.0.3: resolution: {integrity: sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w==} + pdfjs-dist@6.3.289: + resolution: {integrity: sha512-ZHjSVpDa3D6izMq8/04lvkhkATUmL9px6ChPaXc1k6nU2Mrhlg1/7F0bdUqCwUjw3NsPTfPZsMDUU6ZIcRaeQw==} + engines: {node: '>=22.13.0 || >=24'} + perfect-debounce@1.0.0: resolution: {integrity: sha512-xCy9V055GLEqoFaHoC1SoLIaLmWctgCUaBaWxDZ7/Zx4CTyX7cJQLJOok/orfjZAh9kEYpjJa4d0KcJmCbctZA==} @@ -3518,6 +3600,54 @@ snapshots: dependencies: state-local: 1.0.7 + '@napi-rs/canvas-android-arm64@1.0.9': + optional: true + + '@napi-rs/canvas-darwin-arm64@1.0.9': + optional: true + + '@napi-rs/canvas-darwin-x64@1.0.9': + optional: true + + '@napi-rs/canvas-linux-arm-gnueabihf@1.0.9': + optional: true + + '@napi-rs/canvas-linux-arm64-gnu@1.0.9': + optional: true + + '@napi-rs/canvas-linux-arm64-musl@1.0.9': + optional: true + + '@napi-rs/canvas-linux-riscv64-gnu@1.0.9': + optional: true + + '@napi-rs/canvas-linux-x64-gnu@1.0.9': + optional: true + + '@napi-rs/canvas-linux-x64-musl@1.0.9': + optional: true + + '@napi-rs/canvas-win32-arm64-msvc@1.0.9': + optional: true + + '@napi-rs/canvas-win32-x64-msvc@1.0.9': + optional: true + + '@napi-rs/canvas@1.0.9': + optionalDependencies: + '@napi-rs/canvas-android-arm64': 1.0.9 + '@napi-rs/canvas-darwin-arm64': 1.0.9 + '@napi-rs/canvas-darwin-x64': 1.0.9 + '@napi-rs/canvas-linux-arm-gnueabihf': 1.0.9 + '@napi-rs/canvas-linux-arm64-gnu': 1.0.9 + '@napi-rs/canvas-linux-arm64-musl': 1.0.9 + '@napi-rs/canvas-linux-riscv64-gnu': 1.0.9 + '@napi-rs/canvas-linux-x64-gnu': 1.0.9 + '@napi-rs/canvas-linux-x64-musl': 1.0.9 + '@napi-rs/canvas-win32-arm64-msvc': 1.0.9 + '@napi-rs/canvas-win32-x64-msvc': 1.0.9 + optional: true + '@nodelib/fs.scandir@2.1.5': dependencies: '@nodelib/fs.stat': 2.0.5 @@ -5594,6 +5724,10 @@ snapshots: pathe@2.0.3: {} + pdfjs-dist@6.3.289: + optionalDependencies: + '@napi-rs/canvas': 1.0.9 + perfect-debounce@1.0.0: {} picocolors@1.1.1: {} diff --git a/dashboard/scripts/pdfjs-assets.mjs b/dashboard/scripts/pdfjs-assets.mjs new file mode 100644 index 0000000000..ba80e66df4 --- /dev/null +++ b/dashboard/scripts/pdfjs-assets.mjs @@ -0,0 +1,56 @@ +import { readFileSync, readdirSync } from "node:fs"; +import { createRequire } from "node:module"; +import { dirname, join } from "node:path"; + +const require = createRequire(import.meta.url); +const packagePath = require.resolve("pdfjs-dist/package.json"); +const root = dirname(packagePath); +const { version } = JSON.parse(readFileSync(packagePath, "utf8")); + +/** Serve the same versioned PDF resources in development and production. */ +export function pdfjsAssets() { + const files = new Map([["LICENSE", join(root, "LICENSE")]]); + for (const directory of ["cmaps", "standard_fonts", "wasm", "iccs"]) { + for (const entry of readdirSync(join(root, directory), { + withFileTypes: true, + })) { + if (entry.isFile()) { + files.set( + `${directory}/${entry.name}`, + join(root, directory, entry.name), + ); + } + } + } + return { + name: "pdfjs-assets", + configureServer(server) { + server.middlewares.use( + `${server.config.base}pdfjs/${version}/`, + (req, res, next) => { + const name = req.url?.split("?")[0].replace(/^\//, ""); + const file = files.get(name); + if (!file) return next(); + res.setHeader( + "Content-Type", + name.endsWith(".wasm") + ? "application/wasm" + : /\.m?js$/.test(name) + ? "text/javascript" + : "application/octet-stream", + ); + res.end(readFileSync(file)); + }, + ); + }, + generateBundle() { + for (const [name, file] of files) { + this.emitFile({ + type: "asset", + fileName: `pdfjs/${version}/${name}`, + source: readFileSync(file), + }); + } + }, + }; +} diff --git a/dashboard/src/api/v1.ts b/dashboard/src/api/v1.ts index 709d4060a7..158d8fdd9d 100644 --- a/dashboard/src/api/v1.ts +++ b/dashboard/src/api/v1.ts @@ -944,11 +944,12 @@ export const chatApi = { }), ); }, - downloadProjectWorkspaceFile(projectId: string, path: string) { + downloadProjectWorkspaceFile(projectId: string, path: string, signal?: AbortSignal) { return openApiV1.downloadChatProjectWorkspaceFile({ path: { project_id: projectId }, query: { path }, responseType: 'blob', + signal, }) as Promise>; }, addProjectSession(projectId: string, sessionId: string) { diff --git a/dashboard/src/components/chat/WorkspaceFilesPanel.vue b/dashboard/src/components/chat/WorkspaceFilesPanel.vue index baeafb1286..b34884ca88 100644 --- a/dashboard/src/components/chat/WorkspaceFilesPanel.vue +++ b/dashboard/src/components/chat/WorkspaceFilesPanel.vue @@ -1,203 +1,366 @@