Open History to see the last commit
1import type { LinkedPrompt } from "@t3tools/shared/promptLinks";
2
3import { type ComposerThreadTarget, useComposerDraftStore } from "~/composerDraftStore";
4
5import { toastManager } from "../ui/toast";
6
7export function warnAboutHiddenCharacters(prompt: LinkedPrompt): void {
8 if (prompt.hiddenCharacters === 0) return;
9 toastManager.add({
10 type: "warning",
11 title: "This prompt had hidden characters, it may be malicious",
12 description: `T3 Code removed ${prompt.hiddenCharacters} hidden character${prompt.hiddenCharacters === 1 ? "" : "s"}. Read the prompt before you send it.`,
13 timeout: 0,
14 });
15}
16
17export function placeLinkedPrompt(
18 target: ComposerThreadTarget,
19 prompt: LinkedPrompt,
20 notes: ReadonlyArray<string> = [],
21): void {
22 warnAboutHiddenCharacters(prompt);
23 const place = () => {
24 useComposerDraftStore.getState().setPrompt(target, prompt.text);
25 toastManager.add({
26 type: "info",
27 title: "Prompt added from a link",
28 description: ["Read it before you send.", ...notes].join(" "),
29 });
30 };
31 const existing = useComposerDraftStore.getState().getComposerDraft(target)?.prompt ?? "";
32 if (existing.trim().length === 0 || existing === prompt.text) {
33 place();
34 return;
35 }
36 const id = toastManager.add({
37 type: "info",
38 title: "Linked prompt ready",
39 description: "This thread already has a draft. Replace it with the linked prompt?",
40 timeout: 0,
41 actionProps: {
42 children: "Replace draft",
43 onClick: () => {
44 toastManager.close(id);
45 place();
46 },
47 },
48 });
49}