-
Notifications
You must be signed in to change notification settings - Fork 2.7k
feat: external goosed server #5978
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
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3934835
implementing ability to oconnect to a remote goosed
michaelneale 4811e3f
safe fallback
michaelneale 4df1812
cleanup and wording
michaelneale 25543fe
Merge branch 'main' into micn/external-goosed-server
michaelneale a2bae41
Merge branch 'main' into micn/external-goosed-server
michaelneale c6976e6
cleanup based on feedback
michaelneale d6cc12a
moving around
michaelneale 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
180 changes: 180 additions & 0 deletions
180
ui/desktop/src/components/settings/app/ExternalBackendSection.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,180 @@ | ||
| import { useState, useEffect } from 'react'; | ||
| import { Switch } from '../../ui/switch'; | ||
| import { Input } from '../../ui/input'; | ||
| import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '../../ui/card'; | ||
| import { AlertCircle } from 'lucide-react'; | ||
|
|
||
| interface ExternalGoosedConfig { | ||
| enabled: boolean; | ||
| url: string; | ||
| secret: string; | ||
| } | ||
|
|
||
| interface Settings { | ||
| externalGoosed?: Partial<ExternalGoosedConfig>; | ||
| } | ||
|
|
||
| const DEFAULT_CONFIG: ExternalGoosedConfig = { | ||
| enabled: false, | ||
| url: '', | ||
| secret: '', | ||
| }; | ||
|
|
||
| function parseConfig(partial: Partial<ExternalGoosedConfig> | undefined): ExternalGoosedConfig { | ||
| return { | ||
| enabled: partial?.enabled ?? DEFAULT_CONFIG.enabled, | ||
| url: partial?.url ?? DEFAULT_CONFIG.url, | ||
| secret: partial?.secret ?? DEFAULT_CONFIG.secret, | ||
| }; | ||
| } | ||
|
|
||
| export default function ExternalBackendSection() { | ||
| const [config, setConfig] = useState<ExternalGoosedConfig>(DEFAULT_CONFIG); | ||
| const [isSaving, setIsSaving] = useState(false); | ||
| const [urlError, setUrlError] = useState<string | null>(null); | ||
|
|
||
| useEffect(() => { | ||
| const loadSettings = async () => { | ||
| const settings = (await window.electron.getSettings()) as Settings | null; | ||
| setConfig(parseConfig(settings?.externalGoosed)); | ||
| }; | ||
| loadSettings(); | ||
| }, []); | ||
|
|
||
| const validateUrl = (value: string): boolean => { | ||
| if (!value) { | ||
| setUrlError(null); | ||
| return true; | ||
| } | ||
| try { | ||
| const parsed = new URL(value); | ||
| if (!['http:', 'https:'].includes(parsed.protocol)) { | ||
| setUrlError('URL must use http or https protocol'); | ||
| return false; | ||
| } | ||
| setUrlError(null); | ||
| return true; | ||
| } catch { | ||
| setUrlError('Invalid URL format'); | ||
| return false; | ||
| } | ||
| }; | ||
|
|
||
| const saveConfig = async (newConfig: ExternalGoosedConfig): Promise<void> => { | ||
| setIsSaving(true); | ||
| try { | ||
| const currentSettings = ((await window.electron.getSettings()) as Settings) || {}; | ||
| await window.electron.saveSettings({ | ||
| ...currentSettings, | ||
| externalGoosed: newConfig, | ||
| }); | ||
| } catch (error) { | ||
| console.error('Failed to save external backend settings:', error); | ||
| } finally { | ||
| setIsSaving(false); | ||
| } | ||
| }; | ||
|
|
||
| const updateField = <K extends keyof ExternalGoosedConfig>( | ||
| field: K, | ||
| value: ExternalGoosedConfig[K] | ||
| ) => { | ||
| const newConfig = { ...config, [field]: value }; | ||
| setConfig(newConfig); | ||
| return newConfig; | ||
| }; | ||
|
|
||
| const handleUrlChange = (value: string) => { | ||
| updateField('url', value); | ||
| validateUrl(value); | ||
| }; | ||
|
|
||
| const handleUrlBlur = async () => { | ||
| if (validateUrl(config.url)) { | ||
| await saveConfig(config); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <section id="external-backend" className="space-y-4 pr-4 mt-1"> | ||
| <Card className="pb-2"> | ||
| <CardHeader className="pb-0"> | ||
| <CardTitle>Goose Server</CardTitle> | ||
| <CardDescription> | ||
| By default goose launches a server for you, use this to connect to an external goose | ||
| server | ||
michaelneale marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| </CardDescription> | ||
| </CardHeader> | ||
| <CardContent className="pt-4 space-y-4 px-4"> | ||
| <div className="flex items-center justify-between"> | ||
| <div> | ||
| <h3 className="text-text-default text-xs">Use external server</h3> | ||
| <p className="text-xs text-text-muted max-w-md mt-[2px]"> | ||
| Connect to a goose server running elsewhere (requires app restart) | ||
| </p> | ||
| </div> | ||
| <div className="flex items-center"> | ||
| <Switch | ||
| checked={config.enabled} | ||
| onCheckedChange={(checked) => saveConfig(updateField('enabled', checked))} | ||
| disabled={isSaving} | ||
| variant="mono" | ||
| /> | ||
| </div> | ||
| </div> | ||
|
|
||
| {config.enabled && ( | ||
| <> | ||
| <div className="space-y-2"> | ||
| <label htmlFor="external-url" className="text-text-default text-xs"> | ||
| Server URL | ||
| </label> | ||
| <Input | ||
| id="external-url" | ||
| type="url" | ||
| placeholder="http://127.0.0.1:3000" | ||
| value={config.url} | ||
| onChange={(e) => handleUrlChange(e.target.value)} | ||
| onBlur={handleUrlBlur} | ||
| disabled={isSaving} | ||
| className={urlError ? 'border-red-500' : ''} | ||
| /> | ||
| {urlError && ( | ||
| <p className="text-xs text-red-500 flex items-center gap-1"> | ||
| <AlertCircle size={12} /> | ||
| {urlError} | ||
| </p> | ||
| )} | ||
| </div> | ||
|
|
||
| <div className="space-y-2"> | ||
| <label htmlFor="external-secret" className="text-text-default text-xs"> | ||
| Secret Key | ||
| </label> | ||
| <Input | ||
| id="external-secret" | ||
| type="password" | ||
| placeholder="Enter the server's secret key" | ||
| value={config.secret} | ||
| onChange={(e) => updateField('secret', e.target.value)} | ||
| onBlur={() => saveConfig(config)} | ||
| disabled={isSaving} | ||
| /> | ||
| <p className="text-xs text-text-muted"> | ||
| The secret key configured on the goosed server (GOOSE_SERVER__SECRET_KEY) | ||
| </p> | ||
| </div> | ||
|
|
||
| <div className="bg-amber-50 dark:bg-amber-950 border border-amber-200 dark:border-amber-800 rounded-md p-3"> | ||
| <p className="text-xs text-amber-800 dark:text-amber-200"> | ||
| <strong>Note:</strong> Changes require restarting Goose to take effect. New chat | ||
| windows will connect to the external server. | ||
| </p> | ||
| </div> | ||
| </> | ||
| )} | ||
| </CardContent> | ||
| </Card> | ||
| </section> | ||
| ); | ||
| } | ||
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 |
|---|---|---|
| @@ -1,9 +1,5 @@ | ||
| // Helper to construct API endpoints | ||
| export const getApiUrl = (endpoint: string): string => { | ||
| const baseUrl = | ||
| String(window.appConfig.get('GOOSE_API_HOST') || '') + | ||
| ':' + | ||
| String(window.appConfig.get('GOOSE_PORT') || ''); | ||
| const gooseApiHost = String(window.appConfig.get('GOOSE_API_HOST') || ''); | ||
| const cleanEndpoint = endpoint.startsWith('/') ? endpoint : `/${endpoint}`; | ||
| return `${baseUrl}${cleanEndpoint}`; | ||
| return `${gooseApiHost}${cleanEndpoint}`; | ||
| }; |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.