An open-source, faster Devin alternative
TypeScript
Project Sessions tab: show every agent's sessions with an agent filter (#767)
devin-ai-integration[bot]c3f0fafc5d4f
diff --git a/web/src/managed-agents/Detail.tsx b/web/src/managed-agents/Detail.tsxindex 9a13eac5..28ba1b5a 100644--- a/web/src/managed-agents/Detail.tsx+++ b/web/src/managed-agents/Detail.tsx@@ -67,7 +67,10 @@ import { ManagedAgentChatTransport } from './chat-transport'import { DebugInspector } from './DebugInspector'import { isNearScrollEnd } from './scroll-follow'import { createStartCommand, starterCommands } from './onboarding'-import { projectContextSearch } from './project-context'+import {+ projectContextSearch,+ requestedProjectAgentId,+} from './project-context'import {playgroundSessionIdFromSearch,playgroundSessionSearch,@@ -593,6 +596,13 @@ export default function ManagedAgentDetail({const firstRunPrompt = templateFirstRunPrompt(location.state)const [newSessionKey, setNewSessionKey] = useState(() => crypto.randomUUID())const [adoptedPlaygroundId, setAdoptedPlaygroundId] = useState<string>()+ const projectId = project?.project.id+ // On the project Sessions tab the agent selector offers "All agents"; an+ // explicit ?agent= narrows it. Every other tab needs a concrete agent.+ const sessionsAgentFilter =+ project && activeTab === 'sessions'+ ? requestedProjectAgentId(location.search, project.project.agents)+ : agentIdconst agents = useQuery({queryKey: ['managed-agents'],@@ -634,6 +644,12 @@ export default function ManagedAgentDetail({queryFn: () => getManagedAgentSessions(agentId),refetchInterval: 5_000,})+ const projectSessions = useQuery({+ queryKey: ['managed-agent-sessions', 'project', projectId],+ queryFn: () => getManagedAgentSessions(undefined, { projectId }),+ enabled: Boolean(projectId),+ refetchInterval: 5_000,+ })const channels = useQuery({queryKey: ['managed-agent-channels'],queryFn: getManagedAgentChannels,@@ -649,9 +665,20 @@ export default function ManagedAgentDetail({const playgroundSessions = environmentSessions.filter((session) => session.source === 'playground',)- const externalSessions = environmentSessions.filter(- (session) => session.source !== 'playground',- )+ const externalSessions = (+ project+ ? sessionsForEnvironment(+ projectSessions.data ?? [],+ project.deployments,+ sessionsAgentFilter,+ environment,+ )+ : environmentSessions+ ).filter((session) => session.source !== 'playground')+ const projectAgentName = (id: string) => {+ const candidate = project?.project.agents.find((a) => a.id === id)+ return candidate ? displayManagedAgentName(candidate) : id+ }const selectedPlayground = playgroundSessions.find((session) => session.id === requestedPlaygroundId,)@@ -713,6 +740,19 @@ export default function ManagedAgentDetail({<span className="font-mono text-xs">{session.id}</span>),},+ ...(project+ ? ([+ {+ key: 'agent',+ header: 'Agent',+ cell: (session) => (+ <span className="text-xs">+ {projectAgentName(session.agentId)}+ </span>+ ),+ },+ ] as Column<ManagedAgentSessionSummary>[])+ : []),{key: 'source',header: 'Source',@@ -880,13 +920,13 @@ export default function ManagedAgentDetail({<selectid="project-agent"aria-label="Project agent"- value={agentId}+ value={sessionsAgentFilter ?? ''}onChange={(event) => {setNewSessionKey(crypto.randomUUID())const search = new URLSearchParams(projectContextSearch(location.search,- event.target.value,+ event.target.value || undefined,environment,),)@@ -898,13 +938,18 @@ export default function ManagedAgentDetail({}}className="border-input bg-background h-9 min-w-52 rounded-md border px-3 text-sm outline-none">+ {activeTab === 'sessions' ? (+ <option value="">All agents</option>+ ) : null}{project.project.agents.map((candidate) => (<option key={candidate.id} value={candidate.id}>{displayManagedAgentName(candidate)}</option>))}</select>- {projectAgent ? <AgentNameSourceDialog agent={projectAgent} /> : null}+ {projectAgent && sessionsAgentFilter ? (+ <AgentNameSourceDialog agent={projectAgent} />+ ) : null}</div>) : null}@@ -1149,8 +1194,9 @@ export default function ManagedAgentDetail({<div><PanelTitle>Sessions</PanelTitle><PanelDescription className="mt-1">- Sessions started through channels and the API. Playground- sessions stay in the playground.+ Sessions started through channels and the API+ {project ? ' across every agent in this project' : ''}.+ Playground sessions stay in the playground.</PanelDescription></div><div className="text-muted-foreground flex items-center gap-1.5 text-xs">@@ -1161,11 +1207,11 @@ export default function ManagedAgentDetail({columns={sessionColumns}rows={externalSessions}rowKey={(session) => session.id}- loading={sessions.isLoading}+ loading={project ? projectSessions.isLoading : sessions.isLoading}onRowClick={(session) => {if (!project) returnvoid navigate(- `/projects/${encodeURIComponent(project.project.id)}/sessions/${encodeURIComponent(session.id)}?${searchParams.toString()}`,+ `/projects/${encodeURIComponent(project.project.id)}/sessions/${encodeURIComponent(session.id)}${projectContextSearch(location.search, sessionsAgentFilter, environment)}`,)}}empty={diff --git a/web/src/managed-agents/api.ts b/web/src/managed-agents/api.tsindex 99589363..9eb17c48 100644--- a/web/src/managed-agents/api.ts+++ b/web/src/managed-agents/api.ts@@ -1718,9 +1718,13 @@ export async function getManagedAgentDeployments(agentId: string) {* Rows are ordered by creation time; one page of a hundred is what the* agent view shows.*/-export async function getManagedAgentSessions(agentId?: string) {+export async function getManagedAgentSessions(+ agentId?: string,+ options: { projectId?: string } = {},+) {const query = new URLSearchParams({ limit: '100' })if (agentId) query.set('agent', agentId)+ if (options.projectId) query.set('project', options.projectId)const { sessions } = await apiFetch(`/managed-agents/sessions?${query.toString()}`,undefined,diff --git a/web/src/managed-agents/project-context.test.ts b/web/src/managed-agents/project-context.test.tsindex 4f27f270..79620769 100644--- a/web/src/managed-agents/project-context.test.ts+++ b/web/src/managed-agents/project-context.test.ts@@ -2,6 +2,7 @@ import { describe, expect, it } from 'vitest'import {projectContextSearch,projectEnvironmentSearch,+ requestedProjectAgentId,selectedProjectAgentId,} from './project-context'@@ -24,6 +25,18 @@ describe('managed project context', () => {).toBe('support')})+ it('only reports an agent the URL explicitly names', () => {+ expect(requestedProjectAgentId('?agent=support', agents)).toBe('support')+ expect(requestedProjectAgentId('', agents)).toBeUndefined()+ expect(requestedProjectAgentId('?agent=gone', agents)).toBeUndefined()+ })++ it('drops the agent from the URL when none is chosen', () => {+ expect(+ projectContextSearch('?agent=support', undefined, 'development'),+ ).toBe('')+ })+it('stores agent and environment in one navigation state', () => {expect(projectContextSearch('?tab=value', 'support', 'production')).toBe('?tab=value&agent=support&environment=production',diff --git a/web/src/managed-agents/project-context.ts b/web/src/managed-agents/project-context.tsindex bf27cdc0..8ebd0753 100644--- a/web/src/managed-agents/project-context.ts+++ b/web/src/managed-agents/project-context.ts@@ -22,13 +22,26 @@ export function selectedProjectAgentId(return agents.find((agent) => agent.id === requested)?.id ?? agents[0]?.id}+/**+ * The agent explicitly chosen in the URL, or undefined when none is — the+ * project Sessions tab treats that as "every agent in the project".+ */+export function requestedProjectAgentId(+ search: string,+ agents: ReadonlyArray<{ id: string }>,+) {+ const requested = new URLSearchParams(search).get('agent')+ return agents.find((agent) => agent.id === requested)?.id+}+export function projectContextSearch(search: string,- agentId: string,+ agentId: string | undefined,environment: ProjectEnvironment,) {const next = new URLSearchParams(search)- next.set('agent', agentId)+ if (agentId) next.set('agent', agentId)+ else next.delete('agent')if (environment === 'development') next.delete('environment')else next.set('environment', environment)return next.size ? `?${next.toString()}` : ''diff --git a/web/src/managed-agents/session-history.test.ts b/web/src/managed-agents/session-history.test.tsindex ffdb219e..6fcca911 100644--- a/web/src/managed-agents/session-history.test.ts+++ b/web/src/managed-agents/session-history.test.ts@@ -79,6 +79,25 @@ describe('sessionsForEnvironment', () => {),).toEqual([])})++ it('spans every agent in the environment when no agent is given', () => {+ expect(+ sessionsForEnvironment(+ [+ session('mine', 'dev-1'),+ session('other', 'other-dev'),+ session('prod', 'other-prod'),+ ],+ [+ deployment('dev-1', 'development'),+ deployment('other-dev', 'development', 'other-agent'),+ deployment('other-prod', 'production', 'other-agent'),+ ],+ undefined,+ 'development',+ ).map(({ id }) => id),+ ).toEqual(['mine', 'other'])+ })})describe('playground session URL state', () => {diff --git a/web/src/managed-agents/session-history.ts b/web/src/managed-agents/session-history.tsindex aaf3a782..39a816ef 100644--- a/web/src/managed-agents/session-history.ts+++ b/web/src/managed-agents/session-history.ts@@ -5,17 +5,20 @@ import type {} from './api'import type { ProjectEnvironment } from './project-context'-export function sessionsForEnvironment<T extends Pick<ManagedAgentSession, 'deploymentId'>>(+export function sessionsForEnvironment<+ T extends Pick<ManagedAgentSession, 'deploymentId'>,+>(sessions: T[],deployments: ManagedAgentDeployment[],- agentId: string,+ agentId: string | undefined,environment: ProjectEnvironment,): T[] {const deploymentIds = new Set(deployments.filter((deployment) =>- deployment.agentId === agentId && deployment.alias === environment,+ (!agentId || deployment.agentId === agentId) &&+ deployment.alias === environment,).map((deployment) => deployment.id),)