-
Notifications
You must be signed in to change notification settings - Fork 470
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow using URL Params to jumpstart NewChat with a given message.
For example, ``` https://localhost:5173/#/chat/new?message=hello ``` This will start a new chat and then send the message out to kickoff the session. Issue: #418
- Loading branch information
Showing
1 changed file
with
34 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,41 @@ | ||
<script lang="ts"> | ||
import { querystring } from 'svelte-spa-router' | ||
import { addChat, setChatSettingValueByKey } from './Storage.svelte' | ||
import { replace } from 'svelte-spa-router' | ||
import { getProfile, restartProfile } from './Profiles.svelte' | ||
import { getChatDefaults, hasChatSetting } from './Settings.svelte' | ||
import { querystring } from "svelte-spa-router"; | ||
Check failure on line 2 in src/lib/NewChat.svelte GitHub Actions / lint
|
||
import { | ||
addChat, | ||
addMessage, | ||
setChatSettingValueByKey, | ||
submitExitingPromptsNow, | ||
} from "./Storage.svelte"; | ||
Check failure on line 8 in src/lib/NewChat.svelte GitHub Actions / lint
|
||
import { replace } from "svelte-spa-router"; | ||
Check failure on line 9 in src/lib/NewChat.svelte GitHub Actions / lint
|
||
import { getProfile, restartProfile } from "./Profiles.svelte"; | ||
Check failure on line 10 in src/lib/NewChat.svelte GitHub Actions / lint
|
||
import { getChatDefaults, hasChatSetting } from "./Settings.svelte"; | ||
import { v4 as uuidv4 } from "uuid"; | ||
import { type Message } from "./Types.svelte"; | ||
// Create the new chat instance then redirect to it | ||
const urlParams: URLSearchParams = new URLSearchParams($querystring) | ||
const chatId = urlParams.has('p') ? addChat(getProfile(urlParams.get('p') || '')) : addChat() | ||
Object.keys(getChatDefaults()).forEach(k => { | ||
const urlParams: URLSearchParams = new URLSearchParams($querystring); | ||
const chatId = urlParams.has("p") | ||
? addChat(getProfile(urlParams.get("p") || "")) | ||
: addChat(); | ||
Object.keys(getChatDefaults()).forEach((k) => { | ||
if (urlParams.has(k) && hasChatSetting(k as any)) { | ||
setChatSettingValueByKey(chatId, k as any, urlParams.get(k)) | ||
setChatSettingValueByKey(chatId, k as any, urlParams.get(k)); | ||
} | ||
}) | ||
restartProfile(chatId) | ||
replace(`/chat/${chatId}`) | ||
}); | ||
restartProfile(chatId); | ||
const messageContent = urlParams.get("message"); | ||
if (messageContent !== null) { | ||
const uuid = uuidv4(); | ||
const inputMessage: Message = { | ||
role: "user", | ||
content: messageContent, | ||
uuid, | ||
}; | ||
addMessage(chatId, inputMessage); | ||
$submitExitingPromptsNow = true; | ||
} | ||
replace(`/chat/${chatId}`); | ||
</script> |