Skip to content
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

[GUI multiprocess] option 2: tabless multiple goosed processes per window #355

Merged
merged 11 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions ui/desktop/bundle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env python3
import re
from pathlib import Path
from typing import Dict, Union

def replace_env_macro(provider_type: str, host: str, model: str) -> bool:
"""
Replace content between environment macro markers with formatted environment variables.

Args:
provider_type (str): The type of provider (e.g., 'databricks')
host (str): The host URL
model (str): The model name

Returns:
bool: True if successful, False otherwise
"""
file_path = './src/main.ts'

try:
# Read the file content
with open(file_path, 'r', encoding='utf-8') as f:
content = f.read()

# Format the environment variables
formatted_vars = [
f" process.env.GOOSE_PROVIDER__TYPE = '{provider_type}';",
f" process.env.GOOSE_PROVIDER__HOST = '{host}';",
f" process.env.GOOSE_PROVIDER__MODEL = '{model}';"
]

replacement_content = "\n".join(formatted_vars)
replacement_content += "\n return true;"

# Define the pattern to match content between markers
pattern = r'//{env-macro-start}//.*?//{env-macro-end}//'
flags = re.DOTALL # Allow matching across multiple lines

# Create the replacement string with the markers and new content
replacement = f"//{{env-macro-start}}//\n{replacement_content}\n//{{env-macro-end}}//"

# Perform the replacement
new_content, count = re.subn(pattern, replacement, content, flags=flags)

if count == 0:
print(f"Error: Could not find macro markers in {file_path}")
return False

# Write the modified content back to the file
with open(file_path, 'w', encoding='utf-8') as f:
f.write(new_content)

print(f"Successfully updated {file_path}")
return True

except Exception as e:
print(f"Error processing file {file_path}: {str(e)}")
return False

# Example usage
if __name__ == '__main__':
import argparse

parser = argparse.ArgumentParser(description='Update environment variables in main.ts')
parser.add_argument('--type', required=True, help='Provider type (e.g., databricks)')
parser.add_argument('--host', required=True, help='Host URL')
parser.add_argument('--model', required=True, help='Model name')

args = parser.parse_args()

success = replace_env_macro(
provider_type=args.type,
host=args.host,
model=args.model
)

if not success:
print("Failed to update environment variables")
exit(1)
31 changes: 21 additions & 10 deletions ui/desktop/src/ChatWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import Splash from './components/Splash';
import GooseMessage from './components/GooseMessage';
import UserMessage from './components/UserMessage';
import Input from './components/Input';
import Tabs from './components/Tabs';
import MoreMenu from './components/MoreMenu';
import { Bird } from './components/ui/icons';
import LoadingGoose from './components/LoadingGoose';
Expand Down Expand Up @@ -140,17 +139,9 @@ function ChatContent({
return (
<div className="chat-content flex flex-col w-screen h-screen bg-window-gradient items-center justify-center p-[10px]">
<div className="flex w-screen">
<div className="flex-1">
<Tabs
chats={chats}
selectedChatId={selectedChatId}
setSelectedChatId={setSelectedChatId}
setChats={setChats}
/>
</div>
<div className="flex">
<MoreMenu
className="absolute top-2 right-2"
className="absolute top-2 right-2 no-drag"
onStopGoose={() => {
stop();
}}
Expand Down Expand Up @@ -225,6 +216,25 @@ function ChatContent({
}

export default function ChatWindow() {
// Add keyboard shortcut handler
useEffect(() => {
const handleKeyDown = (event: KeyboardEvent) => {
// Check for Command+N (Mac) or Control+N (Windows/Linux)
if ((event.metaKey || event.ctrlKey) && event.key === 'n') {
event.preventDefault(); // Prevent default browser behavior
window.electron.createChatWindow();
}
};

// Add event listener
window.addEventListener('keydown', handleKeyDown);

// Cleanup
return () => {
window.removeEventListener('keydown', handleKeyDown);
};
}, []);

// Check if API key is missing from the window arguments
const apiCredsMissing = window.electron.getConfig().apiCredsMissing;

Expand Down Expand Up @@ -262,6 +272,7 @@ export default function ChatWindow() {

return (
<div className="relative w-screen h-screen overflow-hidden bg-transparent flex flex-col">
<div className="titlebar-drag-region" />
{apiCredsMissing ? (
<div className="w-full h-full">
<ApiKeyWarning className="w-full h-full" />
Expand Down
239 changes: 0 additions & 239 deletions ui/desktop/src/components/Tabs.tsx

This file was deleted.

Loading
Loading