-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusePath.ts
102 lines (88 loc) · 2.94 KB
/
usePath.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import { openFileExplorer, joinPath, getJanDataFolderPath } from '@janhq/core'
import { useAtomValue } from 'jotai'
import { selectedModelAtom } from '@/containers/DropdownListSidebar'
import { activeThreadAtom } from '@/helpers/atoms/Thread.atom'
export const usePath = () => {
const activeThread = useAtomValue(activeThreadAtom)
const selectedModel = useAtomValue(selectedModelAtom)
const onReviewInFinder = async (type: string) => {
// TODO: this logic should be refactored.
if (type !== 'Model' && !activeThread) return
const userSpace = await getJanDataFolderPath()
let filePath = undefined
const assistantId = activeThread?.assistants[0]?.assistant_id
switch (type) {
case 'Engine':
case 'Thread':
filePath = await joinPath(['threads', activeThread?.id ?? ''])
break
case 'Model':
if (!selectedModel) return
filePath = await joinPath(['models', selectedModel.id])
break
case 'Assistant':
if (!assistantId) return
filePath = await joinPath(['assistants', assistantId])
break
default:
break
}
if (!filePath) return
const fullPath = await joinPath([userSpace, filePath])
openFileExplorer(fullPath)
}
const onViewJson = async (type: string) => {
// TODO: this logic should be refactored.
if (type !== 'Model' && !activeThread) return
const userSpace = await getJanDataFolderPath()
let filePath = undefined
const assistantId = activeThread?.assistants[0]?.assistant_id
switch (type) {
case 'Engine':
case 'Thread':
filePath = await joinPath([
'threads',
activeThread?.id ?? '',
'thread.json',
])
break
case 'Model':
if (!selectedModel) return
filePath = await joinPath(['models', selectedModel.id, 'model.json'])
break
case 'Assistant':
if (!assistantId) return
filePath = await joinPath(['assistants', assistantId, 'assistant.json'])
break
default:
break
}
if (!filePath) return
const fullPath = await joinPath([userSpace, filePath])
openFileExplorer(fullPath)
}
const onViewFile = async (id: string) => {
if (!activeThread) return
const userSpace = await getJanDataFolderPath()
let filePath = undefined
filePath = await joinPath(['threads', `${activeThread.id}/files`, `${id}`])
if (!filePath) return
const fullPath = await joinPath([userSpace, filePath])
openFileExplorer(fullPath)
}
const onViewFileContainer = async () => {
if (!activeThread) return
const userSpace = await getJanDataFolderPath()
let filePath = undefined
filePath = await joinPath(['threads', `${activeThread.id}/files`])
if (!filePath) return
const fullPath = await joinPath([userSpace, filePath])
openFileExplorer(fullPath)
}
return {
onReviewInFinder,
onViewJson,
onViewFile,
onViewFileContainer,
}
}