The best way to control Claude Code, Codex and more from any computer or phone

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