Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { collectRetrievalCitationEvidence } from '@/lib/mothership/chat/citation-evidence'
import type { SourceTagData } from '@/app/workspace/[workspaceId]/home/components/message-content/components/special-tags'
import { indexSourcesByUrl } from '@/app/workspace/[workspaceId]/home/components/message-content/sources-by-url'
import type { ToolCallData } from '@/app/workspace/[workspaceId]/home/types'

/** Only searches with safe sources have displayable details. */
export function getSearchActivitySources(tool: ToolCallData): SourceTagData[] | undefined {
if (tool.toolName !== 'search_workspace') return undefined
const evidence = collectRetrievalCitationEvidence([
{ toolCall: { name: tool.toolName, status: tool.status, result: tool.result } },
])
const sources = [...indexSourcesByUrl(evidence.values()).values()]
return sources.length > 0 ? sources : undefined
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import { act } from 'react'
import { createRoot, type Root } from 'react-dom/client'
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { ActivityStatus } from '@/components/ui/activity-status'
import { ToolActivityGroup } from '@/app/workspace/[workspaceId]/home/components/message-content/components/agent-group/tool-activity-group'
import type { ToolCallItemProps } from '@/app/workspace/[workspaceId]/home/components/message-content/components/agent-group/tool-call-item'
Expand Down Expand Up @@ -46,6 +46,8 @@ describe('ToolActivityGroup search disclosure', () => {
let root: Root

beforeEach(() => {
vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true)
vi.useFakeTimers()
container = document.createElement('div')
document.body.append(container)
root = createRoot(container)
Expand All @@ -54,12 +56,13 @@ describe('ToolActivityGroup search disclosure', () => {
afterEach(() => {
act(() => root.unmount())
container.remove()
vi.useRealTimers()
})

function render(tool: ToolCallData, isLive: boolean) {
function render(tools: ToolCallData[], isLive: boolean) {
act(() =>
root.render(
<ToolActivityGroup tools={[tool]} isLive={isLive} ToolCallComponent={TestToolCall} />
<ToolActivityGroup tools={tools} isLive={isLive} ToolCallComponent={TestToolCall} />
)
)
}
Expand All @@ -71,26 +74,55 @@ describe('ToolActivityGroup search disclosure', () => {
}

it('opens when live results arrive, closes for the answer, and respects manual choices', () => {
render(executingSearch, true)
render([executingSearch], true)
expect(container.querySelector('[role="button"][aria-expanded]')).toBeNull()

render(completedSearch, true)
render([completedSearch], true)
expect(disclosure().getAttribute('aria-expanded')).toBe('true')
expect(container.querySelector('a[href="https://example.test/guide"]')).not.toBeNull()

render(completedSearch, false)
render([completedSearch], false)
expect(disclosure().getAttribute('aria-expanded')).toBe('false')

act(() => disclosure().click())
expect(disclosure().getAttribute('aria-expanded')).toBe('true')
render(completedSearch, false)
render([completedSearch], false)
expect(disclosure().getAttribute('aria-expanded')).toBe('true')
render(completedSearch, true)
render([completedSearch], true)
expect(disclosure().getAttribute('aria-expanded')).toBe('true')

act(() => disclosure().click())
render(completedSearch, false)
render(completedSearch, true)
render([completedSearch], false)
render([completedSearch], true)
expect(disclosure().getAttribute('aria-expanded')).toBe('false')
})

it('keeps empty searches out of the disclosure while subsequent tools run', () => {
const emptySearch: ToolCallData = {
...completedSearch,
id: 'empty-search',
result: { success: true, output: { success: true, data: { results: [] } } },
}
const runningRead: ToolCallData = {
id: 'read-1',
toolName: 'read_document',
displayTitle: 'Reading document',
status: 'executing',
}

render([emptySearch], true)
expect.soft(container.querySelector('[role="button"][aria-expanded]')).toBeNull()

render([emptySearch, runningRead], true)
expect.soft(disclosure().getAttribute('aria-expanded')).toBe('false')

if (disclosure().getAttribute('aria-expanded') === 'false') {
act(() => disclosure().click())
}
expect.soft(container.textContent).not.toContain('No results')

render([emptySearch, completedSearch], true)
expect(container.querySelector('a[href="https://example.test/guide"]')).not.toBeNull()
expect(container.textContent).not.toContain('No results')
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ import {
import { getToolStatusDisplayTitle } from '@/lib/mothership/tools/tool-display'
import { ActivityStream } from '@/app/workspace/[workspaceId]/home/components/message-content/components/agent-group/activity-stream'
import { getNewestRunningTool } from '@/app/workspace/[workspaceId]/home/components/message-content/components/agent-group/agent-group-content'
import {
getSearchActivitySources,
SearchActivityDetails,
} from '@/app/workspace/[workspaceId]/home/components/message-content/components/agent-group/search-activity-details'
import { getSearchActivitySources } from '@/app/workspace/[workspaceId]/home/components/message-content/components/agent-group/search-activity-details'
import { SearchActivityResults } from '@/app/workspace/[workspaceId]/home/components/message-content/components/agent-group/search-activity-results'
import type { ToolCallItemProps } from '@/app/workspace/[workspaceId]/home/components/message-content/components/agent-group/tool-call-item'
import {
getActivityAttentionKey,
Expand Down Expand Up @@ -276,7 +274,7 @@ export function ToolActivityGroup({
<ToolCallComponent {...tool} toolCallId={tool.id} />
)}
{sources && (
<SearchActivityDetails
<SearchActivityResults
sources={sources}
label={`Search results for step ${index + 1}: ${getToolTitle(tool)}`}
/>
Expand Down
Loading