forked from CherryHQ/cherry-studio-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssistantDatabase.ts
More file actions
61 lines (54 loc) · 1.62 KB
/
AssistantDatabase.ts
File metadata and controls
61 lines (54 loc) · 1.62 KB
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
import {
deleteAssistantById as _deleteAssistantById,
getAllAssistants as _getAllAssistants,
getAssistantById as _getAssistantById,
getExternalAssistants as _getExternalAssistants,
upsertAssistants as _upsertAssistants
} from '@db/queries/assistants.queries'
import type { Assistant } from '@/types/assistant'
export async function upsertAssistants(assistantsToUpsert: Assistant[]) {
try {
return await _upsertAssistants(assistantsToUpsert)
} catch (error) {
throw new Error(`Failed to upsert assistants: ${error}`)
}
}
export async function deleteAssistantById(id: string) {
try {
return await _deleteAssistantById(id)
} catch (error) {
throw new Error(`Failed to delete assistant with id "${id}": ${error}`)
}
}
export async function getAllAssistants(): Promise<Assistant[]> {
try {
return await _getAllAssistants()
} catch (error) {
throw new Error(`Failed to get all assistants: ${error}`)
}
}
export async function getExternalAssistants(): Promise<Assistant[]> {
try {
return await _getExternalAssistants()
} catch (error) {
throw new Error(`Failed to get external assistants: ${error}`)
}
}
export async function getAssistantById(id: string): Promise<Assistant> {
try {
const assistant = await _getAssistantById(id)
if (assistant === null) {
throw new Error(`Assistant with id "${id}" not found`)
}
return assistant
} catch (error) {
throw new Error(`Failed to get assistant with id "${id}": ${error}`)
}
}
export const assistantDatabase = {
upsertAssistants,
deleteAssistantById,
getAllAssistants,
getExternalAssistants,
getAssistantById
}