diff --git a/core/src/api/index.ts b/core/src/api/index.ts index 64e781096b..dd2fc8e246 100644 --- a/core/src/api/index.ts +++ b/core/src/api/index.ts @@ -10,6 +10,7 @@ export enum AppRoute { openAppDirectory = 'openAppDirectory', openFileExplore = 'openFileExplorer', relaunch = 'relaunch', + janJoin = 'janJoin' } export enum AppEvent { diff --git a/core/src/core.ts b/core/src/core.ts index f268233b7f..3a8ef7f903 100644 --- a/core/src/core.ts +++ b/core/src/core.ts @@ -44,6 +44,8 @@ const getUserSpace = (): Promise => global.core.api?.getUserSpace() const openFileExplorer: (path: string) => Promise = (path) => global.core.api?.openFileExplorer(path) +const janJoin: (dirs: string[]) => Promise = (dirs) => global.core.api?.janJoin(dirs) + const getResourcePath: () => Promise = () => global.core.api?.getResourcePath() /** @@ -66,4 +68,5 @@ export { getUserSpace, openFileExplorer, getResourcePath, + janJoin, } diff --git a/electron/handlers/app.ts b/electron/handlers/app.ts index fc2d0ee596..eff9f4c132 100644 --- a/electron/handlers/app.ts +++ b/electron/handlers/app.ts @@ -48,6 +48,10 @@ export function handleAppIPCs() { shell.openPath(url) }) + ipcMain.handle("janJoin", async (_event, stringArray) => { + return join(stringArray) + }) + /** * Relaunches the app in production - reload window in development. * @param _event - The IPC event object. diff --git a/web/screens/Chat/Sidebar/index.tsx b/web/screens/Chat/Sidebar/index.tsx index f25b277be5..27245291c2 100644 --- a/web/screens/Chat/Sidebar/index.tsx +++ b/web/screens/Chat/Sidebar/index.tsx @@ -1,8 +1,6 @@ -import { join } from 'path' - import React from 'react' -import { getUserSpace, openFileExplorer } from '@janhq/core' +import { getUserSpace, openFileExplorer, janJoin } from '@janhq/core' import { Input, Textarea } from '@janhq/uikit' @@ -54,23 +52,22 @@ const Sidebar: React.FC = () => { const assistantId = activeThread.assistants[0]?.assistant_id switch (type) { case 'Thread': - filePath = join('threads', activeThread.id) + filePath = await janJoin(['threads', activeThread.id]) break case 'Model': if (!selectedModel) return - filePath = join('models', selectedModel.id) + filePath = await janJoin(['models', selectedModel.id]) break case 'Assistant': if (!assistantId) return - filePath = join('assistants', assistantId) + filePath = await janJoin(['assistants', assistantId]) break default: break } if (!filePath) return - - const fullPath = join(userSpace, filePath) + const fullPath = await janJoin([userSpace, filePath]) openFileExplorer(fullPath) } @@ -87,15 +84,15 @@ const Sidebar: React.FC = () => { const assistantId = activeThread.assistants[0]?.assistant_id switch (type) { case 'Thread': - filePath = join('threads', activeThread.id, 'thread.json') + filePath = await janJoin(['threads', activeThread.id, 'thread.json']) break case 'Model': if (!selectedModel) return - filePath = join('models', selectedModel.id, 'model.json') + filePath = await janJoin(['models', selectedModel.id, 'model.json']) break case 'Assistant': if (!assistantId) return - filePath = join('assistants', assistantId, 'assistant.json') + filePath = await janJoin(['assistants', assistantId, 'assistant.json']) break default: break @@ -103,7 +100,7 @@ const Sidebar: React.FC = () => { if (!filePath) return - const fullPath = join(userSpace, filePath) + const fullPath = await janJoin([userSpace, filePath]) openFileExplorer(fullPath) }