Open History to see the last commit
1import { useRef } from "react";
2
3import { Textarea } from "../ui/textarea";
4import { SettingsRow, SettingResetButton } from "./settingsLayout";
5import { useSettingsScope } from "./SettingsScopeContext";
6import { searchableSetting } from "./settingsSearch";
7import {
8 useScopedSettings,
9 useScopedSettingsMixed,
10 useUpdateScopedSettings,
11} from "./useScopedSettings";
12
13export function ThreadTitleInstructionsSettings() {
14 const settings = useScopedSettings();
15 const { targets } = useSettingsScope();
16 const scopeKey = targets.map((target) => `${target.environmentId}:${target.projectId}`).join(",");
17 const edited = useRef(false);
18 const updateSettings = useUpdateScopedSettings();
19 const mixed = useScopedSettingsMixed(["threadTitleInstructions"]);
20
21 return (
22 <SettingsRow
23 serverScoped
24 settingKeys={["threadTitleInstructions"]}
25 {...searchableSetting("thread-title-instructions")}
26 description="Appended to the prompt for new and regenerated thread titles."
27 resetAction={
28 mixed || settings.threadTitleInstructions !== "" ? (
29 <SettingResetButton
30 label="thread title instructions"
31 onClick={() => updateSettings({ threadTitleInstructions: "" })}
32 />
33 ) : null
34 }
35 >
36 <div className="mt-3 max-w-2xl pb-3.5">
37 <Textarea
38 key={`${scopeKey}:${mixed}:${settings.threadTitleInstructions}`}
39 aria-label="Thread title instructions"
40 onChange={() => {
41 edited.current = true;
42 }}
43 rows={4}
44 defaultValue={mixed ? "" : settings.threadTitleInstructions}
45 placeholder={
46 mixed
47 ? "Mixed. Enter instructions to apply to all selected targets."
48 : "Keep titles to a few words. Lead with the main subject."
49 }
50 onBlur={(event) => {
51 const value = event.target.value.trim();
52 if (edited.current && (mixed || value !== settings.threadTitleInstructions))
53 updateSettings({ threadTitleInstructions: value });
54 edited.current = false;
55 }}
56 />
57 </div>
58 </SettingsRow>
59 );
60}