-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(COS-6902): Implement sub-routes for agent view (#12)
- Loading branch information
Showing
72 changed files
with
4,062 additions
and
400 deletions.
There are no files selected for viewing
This file contains 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,35 @@ | ||
import { computed } from 'mobx'; | ||
import { Tracer } from '@infra/tracer'; | ||
import { RootStore } from '@store/root'; | ||
import { AgentService } from '@domain/services/agent/agent.service'; | ||
|
||
export class ToggleAgentActiveUsecase { | ||
private service = new AgentService(); | ||
private root = RootStore.getInstance(); | ||
|
||
constructor(private id: string) { | ||
this.toggleActive = this.toggleActive.bind(this); | ||
} | ||
|
||
@computed | ||
get agent() { | ||
return this.root.agents.getById(this.id); | ||
} | ||
|
||
toggleActive() { | ||
const span = Tracer.span('ToggleAgentActiveUsecase.toggleActive'); | ||
|
||
if (!this.agent) { | ||
console.error( | ||
'ToggleAgentActiveUsecase.toggleActive: Agent not found. Aborting', | ||
); | ||
|
||
return; | ||
} | ||
|
||
this.agent.toggleStatus(); | ||
this.service.saveAgent(this.agent); | ||
|
||
span.end(); | ||
} | ||
} |
This file contains 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
1 change: 1 addition & 0 deletions
1
src/routes/agent/components/AgentConfig/Capabilities/ApplyTag/index.ts
This file contains 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 @@ | ||
export * from './ApplyTag.tsx'; |
This file contains 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
1 change: 1 addition & 0 deletions
1
src/routes/agent/components/AgentConfig/Capabilities/DetectSupportWebVisit/index.ts
This file contains 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 @@ | ||
export * from './DetectSupportWebVisit.tsx'; |
This file contains 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 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
1 change: 1 addition & 0 deletions
1
src/routes/agent/components/AgentConfig/Capabilities/EvaluateCompanyIcpFit/index.ts
This file contains 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 @@ | ||
export { EvaluateCompanyIcpFit } from './EvaluateCompanyICPFit.tsx'; |
File renamed without changes.
This file contains 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
1 change: 1 addition & 0 deletions
1
...routes/agent/components/AgentConfig/Capabilities/SendSlackNotificationCapability/index.ts
This file contains 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 @@ | ||
export * from './SendSlackNotificationCapability.tsx'; |
File renamed without changes.
This file contains 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,206 @@ | ||
import { useMemo, useEffect } from 'react'; | ||
import { useParams, useNavigate, useSearchParams } from 'react-router-dom'; | ||
|
||
import { useKeys } from 'rooks'; | ||
import { observer } from 'mobx-react-lite'; | ||
import { AgentViewUsecase } from '@domain/usecases/agents/agent-view.usecase'; | ||
|
||
import { cn } from '@ui/utils/cn'; | ||
import { Icon } from '@ui/media/Icon'; | ||
import { useStore } from '@shared/hooks/useStore'; | ||
import { useModKey } from '@shared/hooks/useModKey'; | ||
|
||
import { Scope } from './Scope'; | ||
import { goals, configs } from './config.tsx'; | ||
|
||
export const ConfigPage = observer(() => { | ||
const store = useStore(); | ||
|
||
const navigate = useNavigate(); | ||
const { id } = useParams<{ id: string }>(); | ||
const [queryParams, setQueryParams] = useSearchParams(); | ||
|
||
const agent = id ? store.agents.getById(id) : null; | ||
|
||
const usecase = useMemo( | ||
() => new AgentViewUsecase(id ?? '', queryParams.get('cid')), | ||
[id], | ||
); | ||
|
||
const ActiveConfig = useMemo( | ||
() => | ||
usecase.activeConfig ? configs[usecase.activeConfig.type] : () => null, | ||
[usecase?.activeConfig?.type], | ||
); | ||
|
||
useEffect(() => { | ||
if (!queryParams.get('cid')) { | ||
setQueryParams( | ||
(params) => { | ||
if (!usecase.activeConfig?.id) return params; | ||
params.set('cid', usecase.activeConfig.id); | ||
|
||
return params; | ||
}, | ||
{ replace: true }, | ||
); | ||
} | ||
}, []); | ||
|
||
useEffect(() => { | ||
if (id) { | ||
store.ui.commandMenu.setContext({ | ||
...store.ui.commandMenu.context, | ||
ids: [id], | ||
}); | ||
store.ui.commandMenu.setType('AgentCommands'); | ||
} | ||
}, [id]); | ||
|
||
useKeys(['Shift', 'S'], (e) => { | ||
e.stopPropagation(); | ||
e.preventDefault(); | ||
usecase.toggleActive(); | ||
}); | ||
|
||
useKeys(['Shift', 'R'], (e) => { | ||
e.stopPropagation(); | ||
e.preventDefault(); | ||
store.ui.commandMenu.setType('RenameAgent'); | ||
store.ui.commandMenu.setOpen(true); | ||
}); | ||
|
||
useModKey('Backspace', () => { | ||
store.ui.commandMenu.setType('ArchiveAgent'); | ||
store.ui.commandMenu.setOpen(true); | ||
}); | ||
|
||
if (!id) { | ||
throw new Error('No id provided'); | ||
} | ||
|
||
if (!agent) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div> | ||
<div className='flex h-screen'> | ||
<div className='w-[448px] border-r border-r-grayModern-200 px-4 py-3'> | ||
<div className='mb-2'> | ||
<div className='mb-1 flex items-center justify-between'> | ||
<h2 className='font-medium text-sm'>About this agent</h2> | ||
{agent?.value.scope && <Scope scope={agent.value.scope} />} | ||
</div> | ||
<p className='pb-2 text-sm'>{agent?.value.goal ?? 'Unknown'}</p> | ||
</div> | ||
|
||
<h2 className='mb-2 font-medium text-sm'>It's goal is to</h2> | ||
<ul className='space-y-1 mb-4'> | ||
{agent && | ||
goals[agent?.value.type]?.map((goal) => ( | ||
<div | ||
key={goal} | ||
className='flex items-center px-2 py-1 justify-between rounded-lg select-none' | ||
> | ||
<div className='flex items-center gap-2'> | ||
<Icon | ||
stroke='none' | ||
name='dot-single' | ||
className={'text-grayModern-500'} | ||
/> | ||
<p className='text-sm'>{goal}</p> | ||
</div> | ||
</div> | ||
))} | ||
</ul> | ||
|
||
<h2 className='mb-2 font-medium text-sm'>It listens for</h2> | ||
<ul className='space-y-1 mb-4'> | ||
{agent?.value.listeners.map((listener) => ( | ||
<div | ||
key={listener.id} | ||
onClick={() => { | ||
if (listener.config.length) { | ||
usecase.setActiveConfig(listener); | ||
navigate(`?lid=${listener.id}`, { replace: true }); | ||
} | ||
}} | ||
className={cn( | ||
'flex items-center px-2 py-1 justify-between rounded-lg select-none', | ||
listener.config.length && | ||
'hover:bg-grayModern-200 cursor-pointer', | ||
listener.id === usecase?.activeConfig?.id && | ||
'bg-grayModern-100 hover:bg-grayModern-100 font-medium', | ||
)} | ||
> | ||
<div className='flex items-center gap-2'> | ||
<Icon | ||
stroke={listener.errors ? 'currentColor' : 'none'} | ||
name={listener.errors ? 'radio-dot' : 'dot-single'} | ||
className={ | ||
listener.errors ? 'text-error-500' : 'text-grayModern-500' | ||
} | ||
/> | ||
<p className='text-sm'>{listener.name ?? 'Unknown'}</p> | ||
</div> | ||
|
||
{listener.config.length > 0 && ( | ||
<Icon name='settings-02' className='text-grayModern-500' /> | ||
)} | ||
</div> | ||
))} | ||
</ul> | ||
|
||
<h2 className='mb-2 font-medium text-sm'> | ||
It can perform these actions | ||
</h2> | ||
|
||
<ul className='space-y-1'> | ||
{agent?.value.capabilities.map((capability) => ( | ||
<div | ||
key={capability.id} | ||
onClick={() => { | ||
if (capability.config.length) { | ||
usecase.setActiveConfig(capability); | ||
navigate(`?cid=${capability.id}`, { replace: true }); | ||
} | ||
}} | ||
className={cn( | ||
'flex items-center px-2 py-1 justify-between rounded-lg select-none', | ||
capability.config.length && | ||
'hover:bg-grayModern-200 cursor-pointer', | ||
capability.id === usecase?.activeConfig?.id && | ||
'bg-grayModern-100 hover:bg-grayModern-100 font-medium', | ||
)} | ||
> | ||
<div className='flex items-center gap-2'> | ||
<Icon | ||
stroke={capability.errors ? 'currentColor' : 'none'} | ||
name={capability.errors ? 'radio-dot' : 'dot-single'} | ||
className={ | ||
capability.errors | ||
? 'text-error-500' | ||
: 'text-grayModern-500' | ||
} | ||
/> | ||
<p className='text-sm'>{capability.name ?? 'Unknown'}</p> | ||
</div> | ||
|
||
{capability.config.length > 0 && ( | ||
<Icon name='settings-02' className='text-grayModern-500' /> | ||
)} | ||
</div> | ||
))} | ||
</ul> | ||
</div> | ||
|
||
{usecase.activeConfig && ActiveConfig && ( | ||
<div className='w-[418px] border-r border-r-grayModern-200 px-4 py-3'> | ||
<ActiveConfig /> | ||
</div> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
}); |
This file contains 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.