Skip to content

Commit

Permalink
[app] Conditionally start goosed based on valid config
Browse files Browse the repository at this point in the history
  • Loading branch information
alexhancock committed Jan 7, 2025
1 parent f972b94 commit 5ba5d92
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
5 changes: 2 additions & 3 deletions ui/desktop/src/components/ApiKeyWarning.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export function ApiKeyWarning({ className }: ApiKeyWarningProps) {
<Bird />
</div>
<div className="text-center space-y-4 max-w-2xl w-full">
<h2 className="text-2xl font-semibold text-gray-800">API Key Required</h2>
<h2 className="text-2xl font-semibold text-gray-800">Credentials Required</h2>
<p className="text-gray-600 mb-4">
To use Goose, you need to set environment variables for one of the following providers:
</p>
Expand Down Expand Up @@ -94,8 +94,7 @@ export function ApiKeyWarning({ className }: ApiKeyWarningProps) {
</pre>
</Collapsible>
</div>

<p className="text-sm text-gray-500 mt-4">
<p className="text-gray-600 mt-4">
After setting these variables, restart Goose for the changes to take effect.
</p>
</div>
Expand Down
29 changes: 17 additions & 12 deletions ui/desktop/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,20 @@ const parseArgs = () => {
};

const checkApiCredentials = () => {

loadZshEnv(app.isPackaged);

//{env-macro-start}//
const apiKeyProvidersValid =
['openai', 'anthropic', 'google', 'groq', 'openrouter'].includes(process.env.GOOSE_PROVIDER__TYPE) &&
process.env.GOOSE_PROVIDER__HOST &&
process.env.GOOSE_PROVIDER__MODEL &&
process.env.GOOSE_PROVIDER__API_KEY;
['openai', 'anthropic', 'google', 'groq', 'openrouter'].includes(process.env.GOOSE_PROVIDER__TYPE) &&
process.env.GOOSE_PROVIDER__HOST &&
process.env.GOOSE_PROVIDER__MODEL &&
process.env.GOOSE_PROVIDER__API_KEY;

const optionalApiKeyProvidersValid =
['ollama', 'databricks'].includes(process.env.GOOSE_PROVIDER__TYPE) &&
process.env.GOOSE_PROVIDER__HOST &&
process.env.GOOSE_PROVIDER__MODEL;
process.env.GOOSE_PROVIDER__HOST &&
process.env.GOOSE_PROVIDER__MODEL;

return apiKeyProvidersValid|| optionalApiKeyProvidersValid;
//{env-macro-end}//
return apiKeyProvidersValid || optionalApiKeyProvidersValid;
};

const generateSecretKey = () => {
Expand Down Expand Up @@ -119,7 +116,15 @@ const createChat = async (app, query?: string, dir?: string) => {
// Apply current environment settings before creating chat
updateEnvironmentVariables(envToggles);

const [port, working_dir] = await startGoosed(app, dir);
const maybeStartGoosed = async () => {
if (checkApiCredentials()) {
return startGoosed(app, dir);
} else {
return [0, ''];
}
}

const [port, working_dir] = await maybeStartGoosed();
const mainWindow = new BrowserWindow({
titleBarStyle: 'hidden',
trafficLightPosition: { x: 16, y: 10 },
Expand Down

0 comments on commit 5ba5d92

Please sign in to comment.