-
Notifications
You must be signed in to change notification settings - Fork 2.7k
ui: load builtins #1679
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
ui: load builtins #1679
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7ead029
update toggle style
lily-de b0862a2
update routes
lily-de 97310f8
fmt
lily-de 195b835
load default apps on startup
lily-de 8d06062
key = smooshed lowercase name
lily-de dd90a9f
try to sync with main
lily-de 8ce8c67
match main
lily-de 96d5db3
fmt
lily-de f1eb8ed
remove
lily-de File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
ui/desktop/src/components/settings_v2/extensions/LoadBuiltins.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| import type { ExtensionConfig } from '../../../api/types.gen'; | ||
| import builtInExtensionsData from '../../../built-in-extensions.json'; | ||
| import { FixedExtensionEntry } from '@/src/components/ConfigContext'; | ||
|
|
||
| // Type definition for built-in extensions from JSON | ||
| type BuiltinExtension = { | ||
| id: string; | ||
| name: string; | ||
| description: string; | ||
| enabled: boolean; | ||
| type: 'builtin'; | ||
| env_keys: string[]; | ||
| timeout?: number; | ||
| }; | ||
|
|
||
| // TODO: need to keep this in sync better with `name_to_key` on the rust side | ||
| function nameToKey(name: string): string { | ||
| return name | ||
| .split('') | ||
| .filter((char) => !char.match(/\s/)) | ||
| .join('') | ||
| .toLowerCase(); | ||
| } | ||
|
|
||
| /** | ||
| * Synchronizes built-in extensions with the config system. | ||
| * This function ensures all built-in extensions are added, which is especially | ||
| * important for first-time users with an empty config.yaml. | ||
| * | ||
| * @param existingExtensions Current list of extensions from the config (could be empty) | ||
| * @param addExtensionFn Function to add a new extension to the config | ||
| * @returns Promise that resolves when sync is complete | ||
| */ | ||
| export async function syncBuiltInExtensions( | ||
| existingExtensions: FixedExtensionEntry[], | ||
| addExtensionFn: (name: string, config: ExtensionConfig, enabled: boolean) => Promise<void> | ||
| ): Promise<void> { | ||
| try { | ||
| console.log('Setting up built-in extensions... in syncBuiltinExtensions'); | ||
|
|
||
| // Create a set of existing extension IDs for quick lookup | ||
| const existingExtensionKeys = new Set(existingExtensions.map((ext) => nameToKey(ext.name))); | ||
| console.log('existing extension ids', existingExtensionKeys); | ||
|
|
||
| // Cast the imported JSON data to the expected type | ||
| const builtinExtensions = builtInExtensionsData as BuiltinExtension[]; | ||
|
|
||
| // Track how many extensions were added | ||
| let addedCount = 0; | ||
|
|
||
| // Check each built-in extension | ||
| for (const builtinExt of builtinExtensions) { | ||
| // Only add if the extension doesn't already exist | ||
| if (!existingExtensionKeys.has(builtinExt.id)) { | ||
| console.log(`Adding built-in extension: ${builtinExt.id}`); | ||
|
|
||
| // Convert to the ExtensionConfig format | ||
| const extConfig: ExtensionConfig = { | ||
| name: builtinExt.name, | ||
| type: 'builtin', | ||
| timeout: builtinExt.timeout ?? 300, | ||
| }; | ||
|
|
||
| // Add the extension with its default enabled state | ||
| await addExtensionFn(nameToKey(builtinExt.name), extConfig, builtinExt.enabled); | ||
| addedCount++; | ||
| } | ||
| } | ||
|
|
||
| if (addedCount > 0) { | ||
| console.log(`Added ${addedCount} built-in extensions.`); | ||
| } else { | ||
| console.log('All built-in extensions already present.'); | ||
| } | ||
| } catch (error) { | ||
| console.error('Failed to add built-in extensions:', error); | ||
| throw error; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Function to initialize all built-in extensions for a first-time user. | ||
| * This can be called when the application is first installed. | ||
| */ | ||
| export async function initializeBuiltInExtensions( | ||
| addExtensionFn: (name: string, config: ExtensionConfig, enabled: boolean) => Promise<void> | ||
| ): Promise<void> { | ||
| // Call with an empty list to ensure all built-ins are added | ||
| await syncBuiltInExtensions([], addExtensionFn); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the first value in each item is what we use the make the name for the extension, make it 'pretty' so it matches what it's like in the UI for CLI <-> UI config compatibility (e.g. user makes a change in one or the other, make sure we are editing the same part of the config)