Skip to content

Commit

Permalink
feat: update pyinstaller script, clearing storage
Browse files Browse the repository at this point in the history
  • Loading branch information
ObjectJosh authored and Mihir1003 committed Jun 13, 2024
1 parent a818757 commit 9cdc54f
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 134 deletions.
3 changes: 2 additions & 1 deletion newelectron/getPlatform.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@


export function getPlatform() {
const arch = process.arch === 'x64' ? 'x86_64' : process.arch;
return {
platform: process.platform,
arch: process.arch
arch: arch
};
}
Binary file added newelectron/src/bin/Darwin-x86_64/devon_agent
Binary file not shown.
16 changes: 13 additions & 3 deletions newelectron/src/frontend/components/modals/onboarding-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import { useSafeStorage } from '@/lib/services/safeStorageService'
import SafeStoragePopoverContent from '@/components/safe-storage-popover-content'
import Combobox, { ComboboxItem } from '@/components/ui/combobox'
import { models } from '@/lib/config'
import { SessionMachineContext } from '@/home'


const Dialog = lazy(() =>
import('@/components/ui/dialog').then(module => ({
Expand All @@ -42,12 +44,18 @@ const comboboxItems: ExtendedComboboxItem[] = models
company: model.company,
}))

const OnboardingModal = () => {
const OnboardingModal = ({ setModelName, setOnboarded, afterOnboard }: {
setModelName: (value: string) => void
setOnboarded: (value: boolean) => void
afterOnboard: (apiKey: string, modelName: string, folderPath: string) => void
}) => {
const [folderPath, setFolderPath] = useState('')
const [apiKey, setApiKey] = useState('')
const [selectedModel, setSelectedModel] = useState(comboboxItems[0])
const { addApiKey, getApiKey, setUseModelName } = useSafeStorage()
const [isKeySaved, setIsKeySaved] = useState(false)
const sessionActorref = SessionMachineContext.useActorRef()

useEffect(() => {
const fetchApiKey = async () => {
const res = await getApiKey(selectedModel.value)
Expand Down Expand Up @@ -80,7 +88,9 @@ const OnboardingModal = () => {
await setUseModelName(selectedModel.value)
}
handleSaveApiKey() // Store the api key
// setInitialized(true)
afterOnboard(apiKey, selectedModel.value, folderPath)
setOnboarded(true) // Makes sure the other modal doesn't show up
setModelName(selectedModel.value) // Closes the modal
}

function validateFields() {
Expand All @@ -91,7 +101,7 @@ const OnboardingModal = () => {
return (
<Suspense fallback={<></>}>
<Dialog open={true}>
<DialogContent>
<DialogContent hideclose={true.toString()}>
<div className="flex flex-col items-center justify-center my-8 mx-8 max-w-md">
<h1 className="text-3xl font-bold">
Welcome to Devon!
Expand Down
35 changes: 21 additions & 14 deletions newelectron/src/frontend/components/modals/settings-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ import { useState, useEffect, useCallback } from 'react'
import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
import {
CardTitle,
CardHeader,
CardContent,
Card,
} from '@/components/ui/card'
import { useLocalStorage } from '@/lib/hooks/chat.use-local-storage'
import { LocalStorageKey } from '@/lib/types'
import { useToast } from '@/components/ui/use-toast'
import { useSafeStorage } from '@/lib/services/safeStorageService'
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'
Expand All @@ -19,6 +16,8 @@ import { Model } from '@/lib/types'
import { models } from '@/lib/config'
import { Dialog, DialogTrigger, DialogContent } from '@/components/ui/dialog'
import Combobox, { ComboboxItem } from '@/components/ui/combobox'
import { SessionMachineContext } from '@/home'


type ExtendedComboboxItem = Model & ComboboxItem & { company: string }

Expand Down Expand Up @@ -46,15 +45,15 @@ const SettingsModal = ({ trigger }: { trigger: JSX.Element }) => {

const General = () => {
const { toast } = useToast()
const [hasAcceptedCheckbox, setHasAcceptedCheckbox, clearKey] =
useLocalStorage<boolean>(LocalStorageKey.hasAcceptedCheckbox, false)
const [selectedModel, setSelectedModel] = useState(comboboxItems[0])
// Checking model
const { checkHasEncryptedData, getUseModelName } = useSafeStorage()
const { checkHasEncryptedData, getUseModelName, deleteData } = useSafeStorage()
const sessionActorref = SessionMachineContext.useActorRef()

const handleLocalStorage = () => {
clearKey()
toast({ title: 'Local storage cleared!' })
const clearStorageAndResetSession = () => {
deleteData()
toast({ title: 'Storage cleared!' })
sessionActorref.send({ type: 'session.delete' })
}

useEffect(() => {
Expand Down Expand Up @@ -101,8 +100,8 @@ const General = () => {
{`${selectedModel.company} API Key`}
</p>
<Popover>
<PopoverTrigger className="ml-1">
<CircleHelp size={20} />
<PopoverTrigger className="ml-[2px]">
<CircleHelp size={14} />
</PopoverTrigger>
<SafeStoragePopoverContent />
</Popover>
Expand Down Expand Up @@ -139,11 +138,19 @@ const General = () => {
</Card> */}
<Card className="bg-midnight">
<CardHeader>
<h2 className="text-lg font-semibold">Miscellaneous</h2>
<div className="flex gap-1 items-center">
<h2 className="text-lg font-semibold">Miscellaneous</h2>
<Popover>
<PopoverTrigger className="ml-[2px]">
<CircleHelp size={14} />
</PopoverTrigger>
<PopoverContent side='top' className="bg-night w-fit p-2 px-3">Clears your keys from Electron Safe Storage and clears the session</PopoverContent>
</Popover>
</div>
</CardHeader>
<CardContent>
<Button className="w-fit" onClick={handleLocalStorage}>
Clear Local Storage
<Button className="w-fit" onClick={clearStorageAndResetSession}>
Clear Storage
</Button>
</CardContent>
</Card>
Expand Down
49 changes: 32 additions & 17 deletions newelectron/src/frontend/landing.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@

import { useLocalStorage } from '@/lib/hooks/chat.use-local-storage'
import Home, { SessionMachineContext } from './home'
import OnboardingModal from '@/components/modals/onboarding-modal'
import { LocalStorageKey } from '@/lib/types'
import SelectProjectDirectoryModal from '@/components/modals/select-project-directory-modal'
import { useSafeStorage } from './lib/services/safeStorageService'
import { useEffect, useState } from 'react'
Expand All @@ -11,14 +9,9 @@ export default function Landing({ smHealthCheckDone, setSmHealthCheckDone }: {
smHealthCheckDone: boolean,
setSmHealthCheckDone: (value: boolean) => void
}) {
// const [hasAcceptedCheckbox, setHasAcceptedCheckbox] =
// useLocalStorage<boolean>(LocalStorageKey.hasAcceptedCheckbox, false)

// const [hasAcceptedCheckbox, setHasAcceptedCheckbox] = useState(false)

const { checkHasEncryptedData, getUseModelName } = useSafeStorage()
const [onboarded, setOnboarded] = useState(false)
const [modelName, setModelName] = useState('')
const [onboarded, setOnboarded] = useState(false)

useEffect(() => {
const check = async () => {
Expand All @@ -28,36 +21,58 @@ export default function Landing({ smHealthCheckDone, setSmHealthCheckDone }: {
const modelName = await getUseModelName()
setModelName(modelName)
console.log('modelName', modelName)
if (modelName) {
setOnboarded(true)
return
}
}
setOnboarded(false)
}
check()
}, [checkHasEncryptedData])

const sessionActorref = SessionMachineContext.useActorRef()
const state = SessionMachineContext.useSelector(state => state, (a, b) => a.value === b.value)

function afterOnboard(apiKey: string, _modelName: string, folderPath: string) {

console.log("API KEY", apiKey, _modelName)
sessionActorref.send({
type: 'session.create', payload: {
path: folderPath,
agentConfig: {
model: _modelName,
api_key: apiKey
}
}
})
sessionActorref.on("session.creationComplete", () => {
sessionActorref.send({
type: 'session.init', payload: {
// path: folderPath,
agentConfig: {
model: _modelName,
api_key: apiKey
}
}
})
})
}

if (!smHealthCheckDone && state && !state.matches({ setup: "healthcheck" })) {
setSmHealthCheckDone(true)
if (state.context.healthcheckRetry >= 10) {
alert(`Application failed health check\n\nRetries: ${state.context.healthcheckRetry}\n\nPlease report / find more info on this issue here:\nhttps://github.com/entropy-research/Devon/issues`,)
}
}


return (
<>
<Home />

{smHealthCheckDone && !onboarded && <OnboardingModal
// initialized={false}
// setInitialized={() => {}}
{smHealthCheckDone && !modelName && <OnboardingModal
setModelName={setModelName}
setOnboarded={setOnboarded}
afterOnboard={afterOnboard}
/>}
<div className="dark">
{smHealthCheckDone && onboarded && <SelectProjectDirectoryModal
{smHealthCheckDone && !onboarded && modelName && <SelectProjectDirectoryModal
openProjectModal={!state.can({ type: 'session.toggle' }) && !state.matches('resetting')}
hideclose
sessionActorref={sessionActorref}
Expand Down
93 changes: 0 additions & 93 deletions newelectron/src/frontend/lib/hooks/chat.use-local-storage.ts

This file was deleted.

6 changes: 1 addition & 5 deletions newelectron/src/frontend/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ enum ViewMode {
Grid,
}

enum LocalStorageKey {
'hasAcceptedCheckbox' = 'hasAcceptedCheckbox',
}

export type File = {
id: string
name: string
Expand All @@ -23,4 +19,4 @@ export type Model = {
}


export { ViewMode, LocalStorageKey }
export { ViewMode }
6 changes: 5 additions & 1 deletion pyinstaller.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
pyinstaller devon_agent/__main__.py --hidden-import=tiktoken_ext.openai_public --hidden-import=tiktoken_ext --clean --onefile --collect-all litellm --hidden-import=aiosqlite --hidden-import=dotenv
pyinstaller devon_agent/__main__.py --hidden-import=tiktoken_ext.openai_public --hidden-import=tiktoken_ext --clean --onefile --collect-all litellm --hidden-import=aiosqlite --hidden-import=dotenv

if [[ "$(uname -s)" == "Darwin" && "$(uname -m)" == "arm64" ]]; then
mkdir -p newelectron/src/bin/$(uname -s)-$(uname -m)
mv dist/__main__ newelectron/src/bin/$(uname -s)-$(uname -m)/devon_agent
fi

if [[ "$(uname -s)" == "Darwin" && "$(uname -m)" == "x86_64" ]]; then
mkdir -p newelectron/src/bin/$(uname -s)-$(uname -m)
mv dist/__main__ newelectron/src/bin/$(uname -s)-$(uname -m)/devon_agent
fi

0 comments on commit 9cdc54f

Please sign in to comment.