|
1 | 1 | <script lang="ts">
|
2 |
| - import { querystring } from 'svelte-spa-router' |
3 |
| - import { addChat, setChatSettingValueByKey } from './Storage.svelte' |
4 |
| - import { replace } from 'svelte-spa-router' |
5 |
| - import { getProfile, restartProfile } from './Profiles.svelte' |
6 |
| - import { getChatDefaults, hasChatSetting } from './Settings.svelte' |
| 2 | + import { querystring } from "svelte-spa-router"; |
| 3 | + import { |
| 4 | + addChat, |
| 5 | + addMessage, |
| 6 | + setChatSettingValueByKey, |
| 7 | + submitExitingPromptsNow, |
| 8 | + } from "./Storage.svelte"; |
| 9 | + import { replace } from "svelte-spa-router"; |
| 10 | + import { getProfile, restartProfile } from "./Profiles.svelte"; |
| 11 | + import { getChatDefaults, hasChatSetting } from "./Settings.svelte"; |
| 12 | + import { v4 as uuidv4 } from "uuid"; |
| 13 | + import { type Message } from "./Types.svelte"; |
7 | 14 |
|
8 | 15 | // Create the new chat instance then redirect to it
|
9 | 16 |
|
10 |
| - const urlParams: URLSearchParams = new URLSearchParams($querystring) |
11 |
| - const chatId = urlParams.has('p') ? addChat(getProfile(urlParams.get('p') || '')) : addChat() |
12 |
| - Object.keys(getChatDefaults()).forEach(k => { |
| 17 | + const urlParams: URLSearchParams = new URLSearchParams($querystring); |
| 18 | + const chatId = urlParams.has("p") |
| 19 | + ? addChat(getProfile(urlParams.get("p") || "")) |
| 20 | + : addChat(); |
| 21 | + Object.keys(getChatDefaults()).forEach((k) => { |
13 | 22 | if (urlParams.has(k) && hasChatSetting(k as any)) {
|
14 |
| - setChatSettingValueByKey(chatId, k as any, urlParams.get(k)) |
| 23 | + setChatSettingValueByKey(chatId, k as any, urlParams.get(k)); |
15 | 24 | }
|
16 |
| - }) |
17 |
| - |
18 |
| - restartProfile(chatId) |
19 |
| - replace(`/chat/${chatId}`) |
| 25 | + }); |
| 26 | +
|
| 27 | + restartProfile(chatId); |
| 28 | + const messageContent = urlParams.get("message"); |
| 29 | + if (messageContent !== null) { |
| 30 | + const uuid = uuidv4(); |
| 31 | + const inputMessage: Message = { |
| 32 | + role: "user", |
| 33 | + content: messageContent, |
| 34 | + uuid, |
| 35 | + }; |
| 36 | + addMessage(chatId, inputMessage); |
| 37 | + $submitExitingPromptsNow = true; |
| 38 | + } |
| 39 | +
|
| 40 | + replace(`/chat/${chatId}`); |
20 | 41 | </script>
|
0 commit comments