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

settingsSearch.ts

909 lines28.4 KB

1import { isElectron } from "~/env";
2import { isMacPlatform, isWindowsPlatform, normalizeSearchText } from "~/lib/utils";
3import type { EnvironmentId } from "@t3tools/contracts";
4import type { EnvironmentConnectionPhase } from "@t3tools/client-runtime/connection";
5import {
6 validateSettingsScopeSearch,
7 type ResolvedSettingsScope,
8 type SettingsScopeSearch,
9} from "./settingsScope";
10​
11export type SettingsPath =
12 | "/settings/projects"
13 | "/settings/general"
14 | "/settings/appearance"
15 | "/settings/keybindings"
16 | "/settings/snap-shot"
17 | "/settings/providers"
18 | "/settings/integrations"
19 | "/settings/scheduled-tasks"
20 | "/settings/source-control"
21 | "/settings/connections"
22 | "/settings/archived";
23​
24/**
25 * Where a setting can be edited. Device-local rows have no scope: they render
26 * at every selection. `project-defaults` rows accept project overrides, so
27 * they are reachable from any server-backed selection.
28 */
29export type SettingsSearchScope =
30 | "environment"
31 | "environment-defaults"
32 | "project-defaults"
33 | "project"
34 | "checkout"
35 | "connections";
36​
37export interface SettingsSearchItem {
38 readonly id: string;
39 readonly title: string;
40 readonly to: SettingsPath;
41 readonly targetId?: string;
42 /** Descriptions, option labels, and aliases people may remember instead of the title. */
43 readonly searchTerms?: ReadonlyArray<string>;
44 readonly scope?: SettingsSearchScope;
45 // Its row only renders in the desktop app, so a browser result would land on
46 // an anchor that isn't there.
47 readonly desktopOnly?: boolean;
48 readonly macOnly?: boolean;
49 // Its row only renders on Windows desktop, so other desktop platforms must
50 // not expose a result that points to a missing anchor.
51 readonly windowsOnly?: boolean;
52 readonly cloudOnly?: boolean;
53 readonly environmentOnly?: boolean;
54 readonly providerSettingsOnly?: boolean;
55 readonly localBackendManagementOnly?: boolean;
56 readonly localEnvironmentOnly?: boolean;
57 readonly wslAvailableOnly?: boolean;
58 readonly requiresThreadAutoSettlement?: boolean;
60​
61export interface SettingsSearchAvailability {
62 readonly localEnvironmentDisabled?: boolean;
63 readonly hasCloudPublicConfig: boolean;
64 readonly hasEnvironment: boolean;
65 readonly hasProviderSettingsEnvironment: boolean;
66 readonly canManageLocalBackend: boolean;
67 readonly isWslSettingsRowVisible: boolean;
68 readonly hasThreadAutoSettlement: boolean;
70​
71/**
72 * Section labels in sidebar order. The sidebar nav and the search-result
73 * subtitles both render from this record, so each label exists once.
74 */
75export const SETTINGS_SECTION_LABELS: Readonly<Record<SettingsPath, string>> = {
76 "/settings/projects": "Project",
77 "/settings/general": "General",
78 "/settings/appearance": "Appearance",
79 "/settings/keybindings": "Keybindings",
80 "/settings/snap-shot": "SnapShots",
81 "/settings/providers": "Providers",
82 "/settings/integrations": "Integrations",
83 "/settings/scheduled-tasks": "Schedule Tasks",
84 "/settings/source-control": "Source Control",
85 "/settings/connections": "Connections",
86 "/settings/archived": "Archive",
87};
88​
89/**
90 * Searchable settings and stable destinations, in result order. Rows with a
91 * dedicated anchor render their id and title via `searchableSetting`; items
92 * that may not be mounted point at their nearest stable section instead.
93 */
94export const SETTINGS_SEARCH_ITEMS = [
95 {
96 id: "project-defaults",
97 title: "Project defaults and overrides",
98 to: "/settings/general",
99 scope: "project-defaults",
100 searchTerms: ["model workspace environments projects inheritance checkout"],
101 },
102 {
103 id: "project-overview",
104 title: "Project overview",
105 to: "/settings/projects",
106 searchTerms: ["name icon emoji image checkout remove delete"],
107 },
108 {
109 id: "default-model",
110 title: "Default model",
111 to: "/settings/general",
112 scope: "project-defaults",
113 searchTerms: ["new thread project provider reasoning effort"],
114 },
115 {
116 id: "default-permissions",
117 title: "Permissions",
118 to: "/settings/general",
119 scope: "project-defaults",
120 searchTerms: [
121 "new thread default runtime mode supervised approvals auto accept edits full access",
122 ],
123 },
124 {
125 id: "color-scheme",
126 title: "Color scheme",
127 to: "/settings/appearance",
128 searchTerms: ["appearance light dark system mode"],
129 // The scheme tiles sit at the top of the Appearance section.
130 targetId: "appearance",
131 },
132 {
133 id: "theme",
134 title: "Themes",
135 to: "/settings/appearance",
136 searchTerms: ["appearance colors palette custom import"],
137 // Theme cards live directly under the scheme tiles; the section is the
138 // stable scroll destination for both.
139 targetId: "appearance",
140 },
141 {
142 // Prefixed because the slider control already owns the `appearance-contrast` id.
143 id: "setting-appearance-contrast",
144 title: "Contrast",
145 to: "/settings/appearance",
146 searchTerms: ["colors borders interface"],
147 },
148 {
149 // Prefixed because the slider control already owns the `glass-opacity` id.
150 id: "setting-glass-opacity",
151 title: "Glass opacity",
152 to: "/settings/appearance",
153 searchTerms: ["transparent transparency solid menus dialogs composer"],
154 },
155 {
156 id: "diff-color-scheme",
157 title: "Diff colors",
158 to: "/settings/appearance",
159 searchTerms: ["red green blue orange additions deletions changes counts palette colorblind"],
160 },
161 {
162 id: "panel-animations",
163 title: "Panel animations",
164 to: "/settings/appearance",
165 },
166 {
167 id: "environment-identification",
168 title: "Environment identification",
169 to: "/settings/appearance",
170 searchTerms: ["dev nightly artwork pill label hide none"],
171 // The setting is stage-dependent, so its parent section is the stable destination.
172 targetId: "appearance-interface",
173 },
174 {
175 id: "interface-font",
176 title: "Interface font",
177 to: "/settings/appearance",
178 searchTerms: ["typography family size system sans"],
179 },
180 {
181 id: "prompt-font",
182 title: "Prompt font",
183 to: "/settings/appearance",
184 searchTerms: ["typography family size composer input"],
185 },
186 {
187 id: "code-font",
188 title: "Code font",
189 to: "/settings/appearance",
190 searchTerms: ["typography family size monospace code blocks diffs file previews"],
191 },
192 {
193 id: "terminal-font",
194 title: "Terminal font",
195 to: "/settings/appearance",
196 searchTerms: ["typography family size monospace output"],
197 },
198 {
199 id: "font-smoothing",
200 title: "Font smoothing",
201 to: "/settings/appearance",
202 searchTerms: ["typography text grayscale anti aliasing macos thin"],
203 macOnly: true,
204 },
205 {
206 id: "word-wrap",
207 title: "Word wrap",
208 to: "/settings/appearance",
209 searchTerms: ["long lines code blocks tables diffs file previews"],
210 },
211 {
212 id: "composer-context",
213 title: "Composer context",
214 to: "/settings/appearance",
215 },
216 {
217 id: "project-grouping",
218 title: "Project grouping",
219 to: "/settings/general",
220 searchTerms: ["combine matching repositories environments sidebar"],
221 },
222 {
223 id: "auto-settle-inactive-threads",
224 title: "Auto-settle inactive threads",
225 to: "/settings/general",
226 searchTerms: ["sidebar inactivity days no activity automatically"],
227 requiresThreadAutoSettlement: true,
228 scope: "project-defaults",
229 },
230 {
231 id: "auto-settle-merged-threads",
232 title: "Auto-settle merged threads",
233 to: "/settings/general",
234 searchTerms: ["pull request merge closed automatically sidebar"],
235 requiresThreadAutoSettlement: true,
236 scope: "project-defaults",
237 },
238 {
239 id: "days-before-auto-settle",
240 title: "Days of inactivity before auto-settle",
241 to: "/settings/general",
242 targetId: "auto-settle-inactive-threads",
243 searchTerms: ["thread timeout activity sidebar"],
244 requiresThreadAutoSettlement: true,
245 scope: "project-defaults",
246 },
247 {
248 id: "thread-notifications",
249 title: "Thread notifications",
250 to: "/settings/general",
251 searchTerms: ["notification sound alert completion input approval desktop"],
252 },
253 {
254 id: "in-app-notifications",
255 title: "In-app notifications",
256 to: "/settings/general",
257 searchTerms: ["notification toast popup completion input approval failure"],
258 },
259 {
260 id: "time-format",
261 title: "Time format",
262 to: "/settings/general",
263 searchTerms: ["timestamp clock locale system browser os 12 hour 24 hour"],
264 },
265 {
266 id: "response-streaming",
267 title: "Response streaming",
268 to: "/settings/general",
269 scope: "project-defaults",
270 searchTerms: ["output token paragraph buffered wait turn legacy"],
271 },
272 {
273 id: "hide-whitespace-changes",
274 title: "Hide whitespace changes",
275 to: "/settings/general",
276 searchTerms: ["diff ignore spaces edits default"],
277 },
278 {
279 id: "default-diff-file-state",
280 title: "Default diff file state",
281 to: "/settings/general",
282 searchTerms: ["collapsed expanded collapse expand files pull request pr code tab"],
283 },
284 {
285 id: "diff-layout",
286 title: "Diff layout",
287 to: "/settings/general",
288 searchTerms: ["stacked split side by side unified inline view"],
289 },
290 {
291 id: "proactive-panels",
292 title: "Proactive panels",
293 to: "/settings/general",
294 searchTerms: ["automatically open diff pull request pr right panel agent completion"],
295 },
296 {
297 id: "skills-in-slash-menu",
298 title: "Show skills in slash menu",
299 to: "/settings/general",
300 searchTerms: ["command menu dollar $ slash /"],
301 },
302 {
303 id: "composer-collapse",
304 title: "Collapse composer on scroll",
305 to: "/settings/general",
306 searchTerms: ["composer rest resting scroll wheel conversation timeline shrink minimize"],
307 },
308 {
309 id: "provider-update-checks",
310 title: "Provider update checks",
311 to: "/settings/general",
312 searchTerms: ["installed cli versions newer available codex claude cursor grok opencode"],
313 scope: "environment-defaults",
314 },
315 {
316 id: "continue-threads-after-server-update",
317 title: "Continue threads after restarts",
318 to: "/settings/general",
319 scope: "project-defaults",
320 searchTerms: [
321 "resume running active interrupted work restart reboot machine crash desktop update automatically",
322 ],
323 },
324 {
325 id: "background-activity",
326 title: "Background activity",
327 to: "/settings/general",
328 scope: "environment-defaults",
329 searchTerms: [
330 "balanced performance battery saver advanced git fetch provider health refresh host power monitor idle policy",
331 ],
332 },
333 {
334 id: "new-threads",
335 title: "New threads",
336 to: "/settings/general",
337 scope: "project-defaults",
338 searchTerms: ["default workspace mode draft local worktree"],
339 },
340 {
341 id: "start-from-origin",
342 title: "Start from origin",
343 to: "/settings/general",
344 scope: "project-defaults",
345 searchTerms: ["new worktrees latest matching remote branch local"],
346 },
347 {
348 id: "add-project-starts-in",
349 title: "Add project starts in",
350 to: "/settings/general",
351 scope: "environment-defaults",
352 searchTerms: ["base directory folder browser path home"],
353 },
354 {
355 id: "unpin-confirmation",
356 title: "Unpin confirmation",
357 to: "/settings/general",
358 searchTerms: ["ask before thread pinned section"],
359 },
360 {
361 id: "archive-confirmation",
362 title: "Archive confirmation",
363 to: "/settings/general",
364 searchTerms: ["ask before thread second click inline action"],
365 },
366 {
367 id: "delete-confirmation",
368 title: "Delete confirmation",
369 to: "/settings/general",
370 searchTerms: ["ask before thread chat history"],
371 },
372 {
373 id: "quit-confirmation",
374 title: "Quit shortcut",
375 to: "/settings/general",
376 searchTerms: ["confirmation desktop app exit direct hold double click press twice"],
377 desktopOnly: true,
378 },
379 {
380 id: "text-generation-model",
381 title: "Text generation model",
382 to: "/settings/general",
383 scope: "project-defaults",
384 searchTerms: ["generated thread titles source control content default provider"],
385 },
386 {
387 id: "diagnostics",
388 title: "Diagnostics",
389 to: "/settings/general",
390 searchTerms: ["logs traces processes resource history failures spans cpu memory"],
391 },
392 {
393 id: "open-source-licenses",
394 title: "Open source licenses",
395 to: "/settings/general",
396 },
397 {
398 id: "legacy-plan-mode",
399 title: "Plan mode (legacy)",
400 to: "/settings/general",
401 searchTerms: ["build plan composer old"],
402 },
403 {
404 id: "legacy-context-window-indicator",
405 title: "Context window indicator (legacy)",
406 to: "/settings/general",
407 searchTerms: ["composer meter usage tokens circle old"],
408 },
409 {
410 id: "legacy-sidebar",
411 title: "Sidebar (legacy)",
412 to: "/settings/general",
413 searchTerms: ["project thread tree old flat list"],
414 },
415 {
416 id: "keybindings",
417 title: "Keybindings",
418 to: "/settings/keybindings",
419 searchTerms: ["keyboard shortcuts hotkeys commands bindings json"],
420 },
421 {
422 id: "snap-shot-enabled",
423 title: "SnapShots",
424 searchTerms: ["window capture screenshot"],
425 to: "/settings/snap-shot",
426 },
427 {
428 id: "snap-shot-accessibility",
429 title: "Include app text",
430 to: "/settings/snap-shot",
431 targetId: "snap-shot-enabled",
432 searchTerms: [
433 "capture accessibility data text UI structure elements privacy omit agent context",
434 ],
435 },
436 {
437 id: "snap-shot-shortcut",
438 title: "Capture shortcut",
439 to: "/settings/snap-shot",
440 targetId: "snap-shot-enabled",
441 },
442 {
443 id: "snap-shot-sound",
444 title: "Capture sound",
445 to: "/settings/snap-shot",
446 targetId: "snap-shot-enabled",
447 },
448 {
449 id: "snap-shot-flash",
450 title: "Capture flash",
451 to: "/settings/snap-shot",
452 targetId: "snap-shot-enabled",
453 },
454 {
455 id: "snap-shot-animations",
456 title: "Capture animations",
457 to: "/settings/snap-shot",
458 targetId: "snap-shot-enabled",
459 },
460 {
461 id: "providers",
462 title: "Providers",
463 to: "/settings/providers",
464 searchTerms: [
465 "agents cli codex claude cursor grok opencode antigravity google sign in sign out install subscription instances authentication api key models configuration binary path config directory endpoint arguments environment variables display name accent color custom favorite hidden auto compact",
466 ],
467 },
468 {
469 id: "usage-providers",
470 title: "Usage providers",
471 to: "/settings/providers",
472 searchTerms: [
473 "usage sources CLIProxyAPI CLI proxy hub quota subscription limits management key add remove",
474 ],
475 providerSettingsOnly: true,
476 },
477 {
478 id: "provider-health-check-interval",
479 title: "Health check interval",
480 to: "/settings/providers",
481 searchTerms: ["refresh availability versions auth state models background probes seconds off"],
482 providerSettingsOnly: true,
483 },
484 {
485 id: "agent-browser-access",
486 title: "Agent browser access",
487 to: "/settings/integrations",
488 scope: "project-defaults",
489 searchTerms: ["allow disable enable open drive preview tools sessions project override"],
490 },
491 {
492 id: "device-hosts",
493 title: "Device hosts",
494 to: "/settings/integrations",
495 searchTerms: ["ssh remote simulator emulator ios android mac mini identity key connection"],
496 },
497 {
498 id: "agent-device-access",
499 title: "Agent device access",
500 to: "/settings/integrations",
501 targetId: "devices",
502 searchTerms: ["allow simulator emulator ios android drive tools sessions"],
503 },
504 {
505 id: "device-hub",
506 title: "Device hub",
507 to: "/settings/integrations",
508 targetId: "devices",
509 searchTerms: ["simulator emulator ios android install start"],
510 },
511 {
512 id: "device-platform-support",
513 title: "Simulator support",
514 to: "/settings/integrations",
515 targetId: "devices",
516 searchTerms: ["xcode android studio sdk avd runtime"],
517 },
518 {
519 id: "browser-profiles",
520 title: "Browser profiles",
521 to: "/settings/integrations",
522 targetId: "browser",
523 },
524 {
525 id: "browser-default-profile",
526 title: "Default browser profile",
527 to: "/settings/integrations",
528 targetId: "browser-profiles",
529 },
530 {
531 id: "browser-default-viewport",
532 title: "Default browser viewport",
533 to: "/settings/integrations",
534 searchTerms: ["preview size width height device desktop mobile rotate"],
535 },
536 {
537 id: "browser-default-zoom",
538 title: "Default browser zoom",
539 to: "/settings/integrations",
540 searchTerms: ["preview page scale tabs percent"],
541 },
542 {
543 id: "browser-default-appearance",
544 title: "Default browser appearance",
545 to: "/settings/integrations",
546 searchTerms: ["preview color scheme light dark system os"],
547 },
548 {
549 id: "browser-recording-frame-rate",
550 title: "Browser recording frame rate",
551 to: "/settings/integrations",
552 },
553 {
554 id: "browser-link-target",
555 title: "Open links in",
556 to: "/settings/integrations",
557 searchTerms: ["links default browser in-app browser external open"],
558 },
559 {
560 id: "browser-auto-show-floating-preview",
561 title: "Auto-show floating preview",
562 to: "/settings/integrations",
563 searchTerms: ["agent opens browser device simulator pop into view hide"],
564 },
565 {
566 id: "automatic-pull",
567 title: "Automatically pull",
568 to: "/settings/source-control",
569 scope: "project-defaults",
570 searchTerms: ["auto pull default branch current checkout fast forward upstream"],
571 },
572 {
573 id: "pull-request-merge-method",
574 title: "Default merge method",
575 to: "/settings/source-control",
576 scope: "project-defaults",
577 searchTerms: ["pull request merge squash rebase last selected"],
578 },
579 {
580 id: "source-control",
581 title: "Source control",
582 to: "/settings/source-control",
583 scope: "environment-defaults",
584 searchTerms: [
585 "version control git github gitlab forgejo gitea tea codeberg bitbucket azure devops hosting integrations credentials scan server environment",
586 ],
587 },
588 {
589 id: "git-fetch-interval",
590 title: "Git fetch interval",
591 to: "/settings/source-control",
592 searchTerms: [
593 "automatic remote branch refresh background credentials security keys seconds off",
594 ],
595 environmentOnly: true,
596 scope: "environment-defaults",
597 },
598 {
599 id: "source-control-writing-style",
600 title: "Source control writing style",
601 to: "/settings/source-control",
602 searchTerms: [
603 "repository conventions conventional commits custom instructions change descriptions request titles",
604 ],
605 environmentOnly: true,
606 },
607 {
608 id: "follow-change-request-templates",
609 title: "Follow change request templates",
610 to: "/settings/source-control",
611 searchTerms: ["repository pr pull request description structure"],
612 environmentOnly: true,
613 },
614 {
615 id: "source-control-writer-model",
616 title: "Source control writer model",
617 to: "/settings/source-control",
618 searchTerms: [
619 "override generated commit change request pr titles descriptions branch bookmark",
620 ],
621 environmentOnly: true,
622 scope: "project-defaults",
623 },
624 {
625 id: "project-actions",
626 title: "Actions",
627 to: "/settings/projects",
628 searchTerms: ["commands scripts setup run dev server checkout worktree t3.json import"],
629 },
630 {
631 id: "environment-icon",
632 title: "Environment icon",
633 to: "/settings/connections",
634 targetId: "connections-environment",
635 searchTerms: ["machine glyph sidebar mac mini studio laptop desktop server cloud vm"],
636 localBackendManagementOnly: true,
637 },
638 {
639 id: "local-environment",
640 title: "Local environment",
641 to: "/settings/connections",
642 targetId: "connections-environment",
643 searchTerms: ["turn off on disable enable local server agents remote only restart"],
644 desktopOnly: true,
645 },
646 {
647 id: "network-access",
648 title: "Network access",
649 to: "/settings/connections",
650 targetId: "connections-environment",
651 searchTerms: ["expose backend remote pairing local machine interfaces host restart"],
652 localBackendManagementOnly: true,
653 },
654 {
655 id: "tailscale-https",
656 title: "Tailscale HTTPS",
657 to: "/settings/connections",
658 targetId: "connections-environment",
659 searchTerms: ["serve magicdns endpoint remote secure network"],
660 desktopOnly: true,
661 localBackendManagementOnly: true,
662 },
663 {
664 id: "wsl-backend",
665 title: "WSL backend",
666 to: "/settings/connections",
667 searchTerms: [
668 "windows subsystem linux distro second server projects stop windows backend restart",
669 ],
670 desktopOnly: true,
671 windowsOnly: true,
672 localBackendManagementOnly: true,
673 wslAvailableOnly: true,
674 },
675 {
676 id: "t3-connect",
677 localEnvironmentOnly: true,
678 title: "T3 Connect",
679 to: "/settings/connections",
680 targetId: "connections-environment",
681 searchTerms: ["managed tunnel cloud other devices remote"],
682 desktopOnly: true,
683 cloudOnly: true,
684 },
685 {
686 id: "publish-agent-activity",
687 localEnvironmentOnly: true,
688 title: "Publish agent activity",
689 to: "/settings/connections",
690 targetId: "connections-environment",
691 searchTerms: ["mobile push notifications live activities cloud tunnel"],
692 cloudOnly: true,
693 },
694 {
695 id: "connections-environment",
696 title: "This machine",
697 to: "/settings/connections",
698 searchTerms: [
699 "connections server backend local remote access administrative permissions scope pairing links qr code authorized clients sessions revoke endpoint",
700 ],
701 },
702 {
703 id: "remote-environments",
704 title: "Environments",
705 to: "/settings/connections",
706 searchTerms: ["add pair backend host code ssh config agent tunnel saved t3 connect"],
707 },
708 {
709 id: "load-balancing",
710 title: "Load balancing",
711 to: "/settings/connections",
712 searchTerms: [
713 "automatic machine environment resources cpu memory capacity preference weight shared projects",
714 ],
715 },
716 {
717 id: "github-routing",
718 title: "GitHub sharing",
719 to: "/settings/connections",
720 searchTerms: ["pull request trusted environments shared credentials permissions read actions"],
721 },
722 {
723 id: "archive",
724 title: "Archived threads",
725 to: "/settings/archived",
726 searchTerms: ["restore reopen deleted history projects"],
727 },
728] as const satisfies ReadonlyArray<SettingsSearchItem>;
729​
730export type SettingsSearchItemId = (typeof SETTINGS_SEARCH_ITEMS)[number]["id"];
731​
732const SEARCH_ITEMS_BY_ID = new Map(SETTINGS_SEARCH_ITEMS.map((item) => [item.id, item] as const));
733​
734const SETTINGS_CATEGORY_SCOPES: Readonly<Record<SettingsPath, SettingsSearchScope | null>> = {
735 "/settings/projects": "project",
736 "/settings/general": null,
737 "/settings/appearance": null,
738 "/settings/snap-shot": null,
739 // Keybindings fan out to the selection; Providers shows the representative
740 // environment at any selection. Neither needs a particular scope to render.
741 "/settings/keybindings": null,
742 "/settings/providers": null,
743 "/settings/integrations": null,
744 "/settings/source-control": "environment-defaults",
745 "/settings/connections": "connections",
746 "/settings/scheduled-tasks": null,
747 "/settings/archived": "project-defaults",
748};
749​
750/** Search keeps the selected target. A missing row can explain its owning scope instead. */
751export function getSettingsSearchTargetScope(targetId: string) {
752 const items: readonly SettingsSearchItem[] = SETTINGS_SEARCH_ITEMS;
753 const item =
754 items.find((candidate) => candidate.id === targetId) ??
755 items.find((candidate) => candidate.targetId === targetId);
756 return item
757 ? {
758 title: item.title,
759 scope: item.scope ?? SETTINGS_CATEGORY_SCOPES[item.to],
760 ...(item.requiresThreadAutoSettlement ? { requiresThreadAutoSettlement: true } : {}),
761 }
762 : null;
764​
765interface AutoSettlementSearchEnvironment {
766 readonly environmentId: EnvironmentId;
767 readonly connection: { readonly phase: EnvironmentConnectionPhase };
768 readonly serverConfig: {
769 readonly environment: {
770 readonly capabilities: { readonly threadAutoSettlement?: boolean };
771 };
772 } | null;
774​
775/** Discovery needs one capable environment; the selected page needs every connected target to support it. */
776export function getThreadAutoSettlementSearchAvailability(
777 environments: readonly AutoSettlementSearchEnvironment[],
778 scope?: Pick<ResolvedSettingsScope, "kind" | "environmentIds">,
779) {
780 const connected = environments.filter(
781 (environment) =>
782 environment.connection.phase === "connected" && environment.serverConfig !== null,
783 );
784 const eligibleEnvironmentIds = connected
785 .filter(
786 (environment) =>
787 environment.serverConfig?.environment.capabilities.threadAutoSettlement === true,
788 )
789 .map((environment) => environment.environmentId);
790 const selected = connected.filter((environment) =>
791 scope?.environmentIds.includes(environment.environmentId),
792 );
793 return {
794 eligibleEnvironmentIds,
795 isTargetAvailable:
796 scope !== undefined &&
797 scope.kind !== "unavailable" &&
798 selected.length > 0 &&
799 selected.every((environment) => eligibleEnvironmentIds.includes(environment.environmentId)),
800 };
802​
803export function isSettingsSearchScopeAvailable(
804 requiredScope: SettingsSearchScope | null,
805 scopeKind: ResolvedSettingsScope["kind"],
806): boolean {
807 switch (requiredScope) {
808 case null:
809 case "connections":
810 return true;
811 case "environment":
812 case "checkout":
813 return requiredScope === scopeKind;
814 case "project":
815 return scopeKind === "project" || scopeKind === "checkout";
816 case "environment-defaults":
817 return scopeKind === "environment" || scopeKind === "all";
818 case "project-defaults":
819 return (
820 scopeKind === "environment" ||
821 scopeKind === "all" ||
822 scopeKind === "project" ||
823 scopeKind === "checkout"
824 );
825 }
827​
828function settingsScopeKindFromSearch(search: SettingsScopeSearch): ResolvedSettingsScope["kind"] {
829 const target = validateSettingsScopeSearch({ ...search });
830 if (target.checkout && !target.project) return "unavailable";
831 if (target.project) return target.checkout ? "checkout" : "project";
832 return target.machine ? "environment" : "all";
834​
835export function isSettingsOverviewVisible(search: SettingsScopeSearch): boolean {
836 const kind = settingsScopeKindFromSearch(search);
837 return kind === "project" || kind === "checkout";
839​
840/**
841 * `id` and `title` props for the element a search item anchors to. Panels
842 * spread (or pick from) this instead of restating the strings, so the catalog
843 * and the rendered settings cannot drift apart.
844 */
845export function searchableSetting(id: SettingsSearchItemId): {
846 readonly id: string;
847 readonly title: string;
848} {
849 const { id: anchorId, title } = SEARCH_ITEMS_BY_ID.get(id)!;
850 return { id: anchorId, title };
852​
853export function filterAvailableSettingsSearchItems(
854 availability: SettingsSearchAvailability,
855): ReadonlyArray<SettingsSearchItem> {
856 const items: ReadonlyArray<SettingsSearchItem> = SETTINGS_SEARCH_ITEMS;
857 return items.filter(
858 (item) =>
859 (!item.cloudOnly || availability.hasCloudPublicConfig) &&
860 (!item.environmentOnly || availability.hasEnvironment) &&
861 (!item.providerSettingsOnly || availability.hasProviderSettingsEnvironment) &&
862 (!item.localBackendManagementOnly || availability.canManageLocalBackend) &&
863 (!item.localEnvironmentOnly || !availability.localEnvironmentDisabled) &&
864 (!item.wslAvailableOnly || availability.isWslSettingsRowVisible) &&
865 (!item.requiresThreadAutoSettlement || availability.hasThreadAutoSettlement),
866 );
868​
869export function searchSettings(
870 query: string,
871 items: ReadonlyArray<SettingsSearchItem> = SETTINGS_SEARCH_ITEMS,
872): ReadonlyArray<SettingsSearchItem> {
873 const normalizedQuery = normalizeSearchText(query);
874 if (normalizedQuery.length === 0) return [];
875 const queryTokens = normalizedQuery.split(" ");
876 const platform = typeof navigator === "undefined" ? "" : navigator.platform;
877​
878 return items
879 .flatMap((item, index) => {
880 if (!isElectron && item.desktopOnly === true) return [];
881 if (item.macOnly && !isMacPlatform(platform)) return [];
882 if (item.windowsOnly && !isWindowsPlatform(platform)) return [];
883​
884 const title = normalizeSearchText(item.title);
885 const fields = [
886 title,
887 normalizeSearchText(SETTINGS_SECTION_LABELS[item.to]),
888 ...(item.searchTerms ?? []).map(normalizeSearchText),
889 ];
890 if (!queryTokens.every((token) => fields.some((field) => field.includes(token)))) return [];
891​
892 const exactPhraseField = fields.findIndex((field) => field.includes(normalizedQuery));
893 const rank =
894 title === normalizedQuery
895 ? 5
896 : title.startsWith(normalizedQuery)
897 ? 4
898 : title.includes(normalizedQuery)
899 ? 3
900 : queryTokens.every((token) => title.includes(token))
901 ? 2
902 : exactPhraseField >= 0
903 ? 1
904 : 0;
905 return [{ item, index, rank }];
906 })
907 .toSorted((left, right) => right.rank - left.rank || left.index - right.index)
908 .map(({ item }) => item);