Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

LabsSettingsPanel.tsx

249 lines8.9 KB

1import { useAuth } from "@clerk/react";
2import { Link } from "@tanstack/react-router";
3import { managedCapabilityDenial } from "@t3tools/contracts";
4import { ToolCallVisibility } from "@t3tools/contracts/settings";
5import * as Schema from "effect/Schema";
6​
7import { hasCloudPublicConfig } from "~/cloud/publicConfig";
8import { useT3ConnectAuthPrompt } from "../clerk/useT3ConnectAuthPrompt";
9import { Button } from "../ui/button";
10import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "../ui/select";
11import { Switch } from "../ui/switch";
12import { ScopedSwitch } from "./ScopedSwitch";
13import { SettingsPageContainer, SettingsRow, SettingsSection } from "./settingsLayout";
14import { searchableSetting } from "./settingsSearch";
15import { LegacyFeaturesSection } from "./SettingsPanels";
16import { useScopedSettings, useUpdateScopedSettings } from "./useScopedSettings";
17import { useOptionalSettingsScope } from "./SettingsScopeContext";
18import { firstManagedDenial, usePrimaryManagedPolicy } from "~/state/managedPolicy";
19​
20/** Features still settling in, and legacy behavior kept for people who rely on it. */
21export function LabsSettingsPanel() {
22 return (
23 <SettingsPageContainer>
24 <SettingsSection id="beta" title="Beta">
25 <BoringSidebarRow />
26 <BoringSidebarMultilineRow />
27 <ToolCallVisibilityRow />
28 {/* Clerk is only mounted when this build has T3 Connect. */}
29 {hasCloudPublicConfig() ? <GuestLinksRowWithSignIn /> : <GuestLinksRow />}
30 <LinkedEnvironmentsRow />
31 <SimlockHostsRow />
32 </SettingsSection>
33 <LegacyFeaturesSection />
34 </SettingsPageContainer>
35 );
37​
38function BoringSidebarRow() {
39 const settings = useScopedSettings();
40 const updateSettings = useUpdateScopedSettings();
41 return (
42 <SettingsRow
43 {...searchableSetting("boring-sidebar")}
44 description="Group sidebar threads into project folders. Pinned threads stay on top, and Snoozed and Settled stay below the folders."
45 control={
46 <Switch
47 checked={settings.boringSidebarEnabled || settings.legacySidebarEnabled}
48 // Turning it off also clears the opt-in of the removed legacy sidebar.
49 onCheckedChange={(checked) =>
50 updateSettings({ boringSidebarEnabled: Boolean(checked), legacySidebarEnabled: false })
51 }
52 aria-label="Boring sidebar (group by project)"
53 />
54 }
55 />
56 );
58​
59function BoringSidebarMultilineRow() {
60 const settings = useScopedSettings();
61 const updateSettings = useUpdateScopedSettings();
62 return (
63 <SettingsRow
64 {...searchableSetting("boring-sidebar-multiline")}
65 description="In the boring sidebar, show folder threads on two lines: the title, then the branch, pull request, and agent."
66 control={
67 <Switch
68 checked={settings.boringSidebarMultilineRows}
69 onCheckedChange={(checked) =>
70 updateSettings({ boringSidebarMultilineRows: Boolean(checked) })
71 }
72 aria-label="Two-line folder rows"
73 />
74 }
75 />
76 );
78​
79const TOOL_CALL_VISIBILITY_LABELS: Record<ToolCallVisibility, string> = {
80 showAll: "Show all",
81 hideSuccessful: "Hide successful",
82 hideAll: "Hide all",
83 zen: "Zen",
84};
85​
86const isToolCallVisibility = Schema.is(ToolCallVisibility);
87​
88function ToolCallVisibilityRow() {
89 const settings = useScopedSettings();
90 const updateSettings = useUpdateScopedSettings();
91 return (
92 <SettingsRow
93 {...searchableSetting("tool-call-visibility")}
94 description="Hide the commands, edits, and searches agents run. Hide successful keeps failures. Zen shows only final answers. Approvals, questions, and errors always show."
95 control={
96 <div className="w-full sm:w-40">
97 <Select
98 value={settings.toolCallVisibility}
99 onValueChange={(value) => {
100 if (isToolCallVisibility(value)) updateSettings({ toolCallVisibility: value });
101 }}
102 >
103 <SelectTrigger size="sm" className="w-full min-w-0" aria-label="Tool calls in chat">
104 <SelectValue>{TOOL_CALL_VISIBILITY_LABELS[settings.toolCallVisibility]}</SelectValue>
105 </SelectTrigger>
106 <SelectPopup align="end" alignItemWithTrigger={false}>
107 <SelectItem value="showAll">Show all</SelectItem>
108 <SelectItem value="hideSuccessful">Hide successful</SelectItem>
109 <SelectItem value="hideAll">Hide all</SelectItem>
110 <SelectItem value="zen">Zen</SelectItem>
111 </SelectPopup>
112 </Select>
113 </div>
114 }
115 />
116 );
118​
119/** Signed out of T3 Connect, the row offers to sign in instead of its switch. */
120function GuestLinksRowWithSignIn() {
121 const { isSignedIn } = useAuth();
122 const { openAuthPrompt } = useT3ConnectAuthPrompt();
123 // `isSignedIn` is undefined until Clerk loads.
124 if (isSignedIn !== false) return <GuestLinksRow />;
125 return (
126 <SettingsRow
127 {...searchableSetting("guest-links")}
128 description="Share a thread with a guest who watches it live in a browser and sends messages you approve. Sign in to T3 Connect to use guest links."
129 control={
130 <Button size="sm" variant="outline" onClick={openAuthPrompt}>
131 Sign in
132 </Button>
133 }
134 />
135 );
137​
138function GuestLinksRow() {
139 const settings = useScopedSettings();
140 const updateSettings = useUpdateScopedSettings();
141 const scope = useOptionalSettingsScope();
142 const primaryPolicy = usePrimaryManagedPolicy();
143 // Guests arrive through T3 Connect, so a policy that turns Connect off turns this off too.
144 const connectDenial = firstManagedDenial(
145 scope
146 ? scope.connectedEnvironments.map((environment) => environment.serverConfig?.managedPolicy)
147 : [primaryPolicy],
148 (policy) => managedCapabilityDenial(policy, "connect"),
149 );
150 return (
151 <SettingsRow
152 serverScoped
153 {...searchableSetting("guest-links")}
154 settingKeys={["guestSharingEnabled"]}
155 // Turning guest links off still works without T3 Connect.
156 managed={settings.guestSharingEnabled ? undefined : connectDenial}
157 description={
158 <>
159 Share a thread with a guest who watches it live in a browser and sends messages you
160 approve. Needs T3 Connect: sign in and link this machine in{" "}
161 <Link to="/settings/access" className="underline underline-offset-2">
162 Sharing & access
163 </Link>
164 . Turning it off stops every guest link.
165 </>
166 }
167 control={
168 <ScopedSwitch
169 settingKeys={["guestSharingEnabled"]}
170 checked={settings.guestSharingEnabled}
171 onCheckedChange={(checked) => updateSettings({ guestSharingEnabled: Boolean(checked) })}
172 aria-label="Guest links"
173 />
174 }
175 />
176 );
178​
179function LinkedEnvironmentsRow() {
180 const settings = useScopedSettings();
181 const updateSettings = useUpdateScopedSettings();
182 return (
183 <SettingsRow
184 serverScoped
185 {...searchableSetting("linked-environments-beta")}
186 settingKeys={["linkedEnvironmentsEnabled"]}
187 description={
188 <>
189 Let agents here work on your other machines, and theirs here. Turn it on for each machine,
190 then link them in{" "}
191 <Link to="/settings/connections" className="underline underline-offset-2">
192 Connections
193 </Link>
194 . While off, nothing new starts over a link; running tasks finish.
195 </>
196 }
197 control={
198 <ScopedSwitch
199 settingKeys={["linkedEnvironmentsEnabled"]}
200 checked={settings.linkedEnvironmentsEnabled}
201 onCheckedChange={(checked) =>
202 updateSettings({ linkedEnvironmentsEnabled: Boolean(checked) })
203 }
204 aria-label="Linked environments"
205 />
206 }
207 />
208 );
210​
211function SimlockHostsRow() {
212 const settings = useScopedSettings();
213 const updateSettings = useUpdateScopedSettings();
214 return (
215 <SettingsRow
216 serverScoped
217 {...searchableSetting("simlock-hosts")}
218 settingKeys={["simlockDeviceHostsEnabled"]}
219 description={
220 <>
221 Let the Device panel lease simulators and emulators from your own{" "}
222 <a
223 href="https://incubator.callstack.com/simlock/"
224 target="_blank"
225 rel="noreferrer"
226 className="underline underline-offset-2"
227 >
228 Simlock
229 </a>{" "}
230 pool, added in{" "}
231 <Link to="/settings/devices" className="underline underline-offset-2">
232 Devices
233 </Link>
234 . An alpha that may change or break. T3 Code never installs Simlock.
235 </>
236 }
237 control={
238 <ScopedSwitch
239 settingKeys={["simlockDeviceHostsEnabled"]}
240 checked={settings.simlockDeviceHostsEnabled}
241 onCheckedChange={(checked) =>
242 updateSettings({ simlockDeviceHostsEnabled: Boolean(checked) })
243 }
244 aria-label="Simlock device hosts"
245 />
246 }
247 />
248 );