-
Notifications
You must be signed in to change notification settings - Fork 163
Expand file tree
/
Copy pathcreate-dialog.ts
More file actions
42 lines (40 loc) · 1.17 KB
/
create-dialog.ts
File metadata and controls
42 lines (40 loc) · 1.17 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
import { db } from 'src/utils/db'
import { genId } from 'src/utils/functions'
import { Dialog, Workspace } from 'src/utils/types'
import { Ref } from 'vue'
import { useRouter } from 'vue-router'
import { useI18n } from 'vue-i18n'
export function useCreateDialog(workspace: Ref<Workspace>) {
const router = useRouter()
const { t } = useI18n()
async function createDialog(props: Partial<Dialog> = {}) {
const id = genId()
const messageId = genId()
await db.transaction('rw', db.dialogs, db.messages, () => {
db.dialogs.add({
id,
workspaceId: workspace.value.id,
name: t('createDialog.newDialog'),
msgTree: { $root: [messageId], [messageId]: [] },
msgRoute: [],
msgBranchState: {},
assistantId: workspace.value.defaultAssistantId,
inputVars: {},
...props
})
db.messages.add({
id: messageId,
dialogId: id,
type: 'user',
contents: [{
type: 'user-message',
text: '',
items: []
}],
status: 'inputing'
})
})
router.push(`/workspaces/${workspace.value.id}/dialogs/${id}`)
}
return { createDialog }
}