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

settingsSearch.ts

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