* fix(web-search-deepseek): disable thinking for auxiliary search requests The provider discards the generated text of the auxiliary Messages turn, so reasoning tokens have no consumer. DeepSeek enables thinking by default, which adds latency and output tokens to every search. Fixes #6099. * feat(web): add opt-in traditional Search and Fetch APIs * test(web): verify API settings persistence and refresh Session evidence * fix(web): require an explicit Search API base with its route prefix * docs(web): document direct Search and Fetch API decisions * fix(web): keep Messages search default behind the new Web Search API switch - Rename useTraditionalApi/traditionalBaseURL to useSearchApi/searchApiBaseURL and label the switch "Use the new Web Search API"; Messages search stays the default. - Default the Search / Fetch API base to https://api.deepseek.com/v1/tools. - Authenticate the Search API with an API key only: DeepSeek Account tokens returned an empty HTTP 404 on /v1/tools/* when probed on 2026-10-16. - Remove the count setting, which tool-web's maxResults always overrides, and the undocumented DeepSeek-API-Version header. - Name the active API's base URL field and the current settings path in endpoint guidance; re-record the endpoint guidance Session. - Keep WebFetchResult.statusCode required: DeepSeek Fetch reports HTTP 200 and drops the page title, so the fetch-metadata widening and its upgrade guide are removed. * fix(web): accept account sign-in on the live Search API The public Search and Fetch routes went live on 2026-10-16 and accept the DeepSeek Account token, so account-route Sessions send it to the Search API as they do for Messages search, and the settings copy no longer says account sign-in does not apply. Record the live behavior in the README and Agent Note: summaries of 1,000-2,300 characters, an HTTP 500 for an unresolvable Fetch target, and migration notes for gateways without /v1/tools routes. Test doubles now use the live response fields and RFC 3339 offsets. * feat(web): configure Search API result count and send the triggering question - Add web-search-deepseek.count (1-50, default 10, the service default) and show it as "Results per search" in Search API mode, where "Max searches per request" applies only to Messages; a smaller request maxResults still wins. - Send the initiating Session's latest human prompt as ori_question, with whitespace collapsed and cut to the API's 128-character limit; blank or absent prompts omit it, and sendOriginalQuestion: false disables it. The settings hint states that the question is sent. - Match the web search double on the request's query field, since ori_question now carries every query in the prompt. * fix(client): unify web search endpoint override controls * feat(web): configure registered search and fetch providers through shared settings * feat(web): include Exa and Perplexity in provider settings * test(web): cover provider settings branches and refresh plugin snapshots * revert(web): drop the provider dropdown, schema-driven form, and Exa/Perplexity settings Revert aed8c5cb609, d88c47dcd80, and 036a5a337d3. The Web search settings page returns to the DeepSeek toggle; the DeepSeek Search and Fetch API split is reintroduced as one plugin in the following commit. * feat(web): move the DeepSeek Search and Fetch APIs into web-deepseek-api The new web-deepseek-api plugin registers deepseek-search-api and deepseek-fetch-api over one credential and API base, and exports the authentication and redirect-rejecting transport that web-search-deepseek now reuses for Messages search only. The web service reads searchProvider and fetchProvider for each operation, so the Web search settings switch selects both APIs together on save and restores Messages search with local HTTP fetch when turned off. The switch hint links to the DeepSeek search and fetch guide. * refactor(client): keep the web search endpoint fields on the shared override controls Drop the always-visible reset and the inherited-address placeholder from the Web search page, restoring ui-primitives to its base. Each endpoint field shows the selected section's effective value and offers Reset to default only for an override, like every other settings field. * refactor(web): keep Messages search independent of web-deepseek-api Restore dsh-web-search-deepseek to its own credential and transport code, keeping only the disabled-thinking request and the current settings guidance, so the Messages plugin no longer depends on the Search and Fetch API package. dsh-web-deepseek-api keeps its transport internal; the regions that repeat the Messages helpers carry jscpd:ignore markers, with the rationale recorded in the Search and Fetch API Agent Note. * refactor(web): keep the web-deepseek-api request type module-private --------- Co-authored-by: LegGasai <[email protected]>
297 lines
14 KiB
TypeScript
297 lines
14 KiB
TypeScript
// Web e2e scenario for the shipped default search composition. A real browser
|
|
// drives `web_search`; the model stream is replayed while the real DeepSeek
|
|
// provider calls a deterministic local Search API endpoint through
|
|
// the real credentials service.
|
|
import { readFile } from 'node:fs/promises'
|
|
import { createServer, type Server } from 'node:http'
|
|
import type { AddressInfo } from 'node:net'
|
|
import { fileURLToPath } from 'node:url'
|
|
import type { Browser, Page } from 'playwright'
|
|
import { chromium } from 'playwright'
|
|
import { afterAll, beforeAll, describe, expect, it, onTestFailed } from 'vitest'
|
|
import { credentialRef } from '@deepseek-ai/dsh-credentials'
|
|
import type { SessionEvent } from '@deepseek-ai/dsh-session'
|
|
import { WEB_SEARCH_MAX_RESULTS } from '@deepseek-ai/dsh-tool-web'
|
|
import {
|
|
assertFixtureInventory, captureStableAria, compareOrRefreshGolden, fixtureUserPrompts,
|
|
launchWebScaffold, recordFixture, watchConsole, webSnapshotMode, type WebScaffold,
|
|
} from './scaffold.ts'
|
|
import { connectFreshWorkspace, expandOwningTurnProcess, newEnglishPage, saveFailureShot } from './support.ts'
|
|
|
|
const SNAPSHOT_DIR = fileURLToPath(new URL('../../../snapshots/web/web-search-round', import.meta.url))
|
|
const FIXTURE = fileURLToPath(new URL('../../../snapshots/web/web-search-round/session.v3.jsonl', import.meta.url))
|
|
const UI_EXPECTED = fileURLToPath(new URL('../../../snapshots/web/web-search-round/ui.expected.md', import.meta.url))
|
|
const MODE = webSnapshotMode()
|
|
const QUERIES = ['DeepSeek Harness snapshot search', 'DeepSeek Harness multi-query search'] as const
|
|
const PROMPT = `Use web_search once with queries ${JSON.stringify(QUERIES)}. Then reply exactly SEARCH_DONE and stop.`
|
|
const SEARCH_CREDENTIAL_REF = credentialRef('DSH_WEB_SEARCH_E2E_KEY')
|
|
const SEARCH_CREDENTIAL = 'snapshot-search-key'
|
|
|
|
/**
|
|
* Provider results the double returns per query. The combined result exceeds
|
|
* the shipped `searchMaxResults`, so the tool's round-robin cap and the card's
|
|
* scroll container are both exercised. Each row carries a title, a snippet,
|
|
* and a date, so 8 kept rows exceed the `.sources` 320px max-height.
|
|
*/
|
|
const PROVIDER_RESULT_COUNT = 6
|
|
|
|
/** One provider result's URL, by 1-based provider order. */
|
|
function resultUrl(queryIndex: number, ordinal: number): string {
|
|
return `https://docs.example.test/search/${queryIndex + 1}/${ordinal}`
|
|
}
|
|
|
|
/** One provider result's title, by 1-based provider order. */
|
|
function resultTitle(queryIndex: number, ordinal: number): string {
|
|
return `Snapshot Search ${queryIndex + 1} Result ${ordinal}`
|
|
}
|
|
|
|
/** One provider result's citation excerpt, by 1-based provider order. */
|
|
function resultSnippet(queryIndex: number, ordinal: number): string {
|
|
return `Snapshot search ${queryIndex + 1} excerpt ${ordinal}: the harness replays this source list from a local endpoint.`
|
|
}
|
|
|
|
/** One provider result's publication date, by 1-based provider order (July 2026 days 01..12). */
|
|
function resultPageAge(ordinal: number): string {
|
|
return `2026-07-${String(ordinal).padStart(2, '0')}`
|
|
}
|
|
|
|
/** The 1-based provider ordinals, in provider order. */
|
|
const RESULT_ORDINALS = Array.from({ length: PROVIDER_RESULT_COUNT }, (_value, index) => index + 1)
|
|
|
|
/** Sources kept after round-robin merging reaches the shipped combined cap. */
|
|
const KEPT_SOURCES = RESULT_ORDINALS.flatMap(ordinal => QUERIES.map((_query, queryIndex) => ({
|
|
url: resultUrl(queryIndex, ordinal),
|
|
title: resultTitle(queryIndex, ordinal),
|
|
snippet: resultSnippet(queryIndex, ordinal),
|
|
publishedAt: resultPageAge(ordinal),
|
|
}))).slice(0, WEB_SEARCH_MAX_RESULTS)
|
|
|
|
/** URLs omitted after the combined source cap is reached. */
|
|
const DROPPED_SOURCE_URLS = RESULT_ORDINALS.flatMap(ordinal => QUERIES.map(
|
|
(_query, queryIndex) => resultUrl(queryIndex, ordinal),
|
|
)).slice(WEB_SEARCH_MAX_RESULTS)
|
|
|
|
interface CapturedSearchRequest {
|
|
path: string
|
|
apiKey: string | undefined
|
|
body: unknown
|
|
}
|
|
|
|
/** The Search API `query` field of one captured request body; `ori_question` also names every query. */
|
|
function requestQuery(body: unknown): unknown {
|
|
return typeof body === 'object' && body !== null && 'query' in body ? body.query : undefined
|
|
}
|
|
|
|
/** Start the deterministic DeepSeek Search double used by the real provider. */
|
|
async function startSearchServer(captured: CapturedSearchRequest[]): Promise<{ server: Server; baseURL: string }> {
|
|
const server = createServer((request, response) => {
|
|
let body = ''
|
|
request.setEncoding('utf8')
|
|
request.on('data', (chunk: string) => { body += chunk })
|
|
request.on('end', () => {
|
|
const parsedBody: unknown = JSON.parse(body)
|
|
captured.push({
|
|
path: request.url ?? '',
|
|
apiKey: typeof request.headers.authorization === 'string' ? request.headers.authorization : undefined,
|
|
body: parsedBody,
|
|
})
|
|
const queryIndex = QUERIES.findIndex(query => requestQuery(parsedBody) === query)
|
|
if (queryIndex < 0) {
|
|
response.writeHead(400, { 'content-type': 'application/json' })
|
|
response.end(JSON.stringify({ error: 'unknown fixture query' }))
|
|
return
|
|
}
|
|
response.writeHead(200, { 'content-type': 'application/json' })
|
|
response.end(JSON.stringify({
|
|
results: RESULT_ORDINALS.map(ordinal => ({
|
|
url: resultUrl(queryIndex, ordinal),
|
|
title: resultTitle(queryIndex, ordinal),
|
|
snippet: resultSnippet(queryIndex, ordinal),
|
|
content: '', site_name: null, site_icon: null,
|
|
date: resultPageAge(ordinal),
|
|
})),
|
|
}))
|
|
})
|
|
})
|
|
await new Promise<void>((resolve, reject) => {
|
|
server.once('error', reject)
|
|
server.listen(0, '127.0.0.1', () => {
|
|
server.off('error', reject)
|
|
resolve()
|
|
})
|
|
})
|
|
const address = server.address() as AddressInfo
|
|
return { server, baseURL: `http://127.0.0.1:${address.port}` }
|
|
}
|
|
|
|
describe('web e2e: opt-in Search API web search', () => {
|
|
let scaffold: WebScaffold
|
|
let browser: Browser
|
|
let page: Page
|
|
let searchServer: Server | undefined
|
|
let tripwire: ReturnType<typeof watchConsole>
|
|
const searchRequests: CapturedSearchRequest[] = []
|
|
const sessionEvents: SessionEvent[] = []
|
|
|
|
beforeAll(async () => {
|
|
const search = await startSearchServer(searchRequests)
|
|
searchServer = search.server
|
|
scaffold = await launchWebScaffold({
|
|
extraOverlayPath: fileURLToPath(new URL('./pin-browse-picker.overlay.yml', import.meta.url)),
|
|
compareReplaySession: true,
|
|
deepSeekWebApi: {
|
|
baseURL: `${search.baseURL}/api/v1/tools`,
|
|
apiKeyEnv: SEARCH_CREDENTIAL_REF,
|
|
select: true,
|
|
},
|
|
...(MODE === 'record' ? {} : { replayFixture: FIXTURE, paceMs: 15 }),
|
|
})
|
|
await scaffold.ctx.credentials.set(SEARCH_CREDENTIAL_REF, SEARCH_CREDENTIAL)
|
|
scaffold.ctx.on('session/event', (_session, event: SessionEvent) => { sessionEvents.push(event) })
|
|
browser = await chromium.launch()
|
|
page = await newEnglishPage(browser)
|
|
tripwire = watchConsole(page)
|
|
await page.goto(scaffold.authenticatedUrl, { waitUntil: 'load' })
|
|
await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
|
|
await connectFreshWorkspace(page, scaffold.workspaceCwd)
|
|
}, 120_000)
|
|
|
|
afterAll(async () => {
|
|
await browser?.close()
|
|
await scaffold?.close()
|
|
await new Promise<void>((resolve, reject) => {
|
|
if (searchServer === undefined) {
|
|
resolve()
|
|
return
|
|
}
|
|
searchServer.close((error) => {
|
|
if (error === undefined) resolve()
|
|
else reject(error)
|
|
})
|
|
})
|
|
})
|
|
|
|
it('drives the recorded search to a settled turn (all modes)', async () => {
|
|
onTestFailed(() => saveFailureShot(page, 'web-e2e-search-drive'))
|
|
if (MODE !== 'record') {
|
|
expect(fixtureUserPrompts(await readFile(FIXTURE, 'utf8'))).toEqual([PROMPT])
|
|
}
|
|
const input = page.locator('[data-composer-input]').first()
|
|
await input.waitFor({ timeout: 10_000 })
|
|
const settled = scaffold.whenTurnSettled()
|
|
await input.fill(PROMPT)
|
|
await input.press('Enter')
|
|
const sessionId = await settled
|
|
if (MODE === 'record') await recordFixture(scaffold, sessionId, FIXTURE)
|
|
}, 200_000)
|
|
|
|
it.skipIf(MODE === 'record')('uses the real provider and persists the capped structured result', () => {
|
|
expect(searchRequests).toHaveLength(QUERIES.length)
|
|
for (const query of QUERIES) {
|
|
const request = searchRequests.find(candidate => requestQuery(candidate.body) === query)
|
|
if (request === undefined) throw new Error(`missing provider request for query: ${query}`)
|
|
expect(request).toMatchObject({ path: '/api/v1/tools/search', apiKey: `Bearer ${SEARCH_CREDENTIAL}` })
|
|
expect(request.body).toEqual({
|
|
query, count: WEB_SEARCH_MAX_RESULTS, need_content: false, ori_question: Array.from(PROMPT).slice(0, 128).join(''),
|
|
})
|
|
}
|
|
expect(sessionEvents.filter(event => event.type === 'web/deepseek-search-llm-request')).toEqual([])
|
|
|
|
const searchCall = sessionEvents.find(
|
|
(event): event is Extract<SessionEvent, { type: 'tool/call' }> =>
|
|
event.type === 'tool/call' && event.data.name === 'web_search',
|
|
)
|
|
if (searchCall === undefined) throw new Error('the replayed turn did not call web_search')
|
|
const searchResult = sessionEvents.find(
|
|
(event): event is Extract<SessionEvent, { type: 'tool/result' }> =>
|
|
event.type === 'tool/result' && event.data.message.source.callId === searchCall.data.callId,
|
|
)
|
|
if (searchResult === undefined) throw new Error('web_search produced no durable result')
|
|
const message = searchResult.data.message
|
|
expect(message.isError).toBe(false)
|
|
const rendered = message.content.filter(block => block.type === 'text').map(block => block.text).join('')
|
|
// The tool interleaves sources from both seam results before applying the
|
|
// combined cap, so each query remains represented in model-visible output.
|
|
for (const source of KEPT_SOURCES) {
|
|
expect(rendered).toContain(`[${source.title}](${source.url})`)
|
|
}
|
|
for (const url of DROPPED_SOURCE_URLS) {
|
|
expect(rendered).not.toContain(url)
|
|
}
|
|
expect(rendered).toContain(
|
|
`(Showing the first ${WEB_SEARCH_MAX_RESULTS} sources. Refine the query for more.)`,
|
|
)
|
|
expect(searchResult.data.meta).toMatchObject({
|
|
sources: KEPT_SOURCES,
|
|
truncated: true,
|
|
})
|
|
})
|
|
|
|
it.skipIf(MODE === 'record')('matches the settled search card aria golden', async () => {
|
|
onTestFailed(() => saveFailureShot(page, 'web-e2e-search-aria'))
|
|
await expect.poll(() => page.getByText('SEARCH_DONE', { exact: true }).count(), { timeout: 15_000 })
|
|
.toBeGreaterThanOrEqual(1)
|
|
const searchTool = page.locator('[data-tool="web_search"]')
|
|
await expandOwningTurnProcess(page, searchTool)
|
|
await searchTool.waitFor({ timeout: 10_000 })
|
|
const snapshot = await captureStableAria(page, '[class*="centerCol"]', scaffold.workspaceCwd)
|
|
await compareOrRefreshGolden(UI_EXPECTED, snapshot, MODE)
|
|
})
|
|
|
|
it.skipIf(MODE === 'record')('scrolls the capped source list inside the fixed-height container', async () => {
|
|
onTestFailed(() => saveFailureShot(page, 'web-e2e-search-sources-scroll'))
|
|
const row = page.locator('[data-tool="web_search"] [data-expandable]').first()
|
|
await expandOwningTurnProcess(page, row)
|
|
await row.click()
|
|
await expect.poll(() => row.getAttribute('aria-expanded'), { timeout: 5_000 }).toBe('true')
|
|
|
|
const card = page.locator('[data-web="search"]')
|
|
const sources = card.locator('ol')
|
|
await sources.waitFor({ timeout: 10_000 })
|
|
// The card draws exactly the sources the model saw after the combined cap.
|
|
expect(await sources.locator('li').count()).toBe(WEB_SEARCH_MAX_RESULTS)
|
|
// The list is complete in the DOM, so the card carries no expand control.
|
|
expect(await card.locator('button').count()).toBe(0)
|
|
expect(await card.getByText('Source list truncated').isVisible()).toBe(true)
|
|
|
|
const geometry = await sources.evaluate((element) => {
|
|
const computed = getComputedStyle(element)
|
|
return {
|
|
maxHeight: computed.maxHeight,
|
|
overflowY: computed.overflowY,
|
|
scrollHeight: element.scrollHeight,
|
|
clientHeight: element.clientHeight,
|
|
}
|
|
})
|
|
expect(geometry.maxHeight).toBe('320px')
|
|
expect(geometry.overflowY).toBe('auto')
|
|
expect(geometry.scrollHeight).toBeGreaterThan(geometry.clientHeight)
|
|
})
|
|
|
|
it.skipIf(MODE === 'record')('reserves marker room a scroll container cannot clip back', async () => {
|
|
onTestFailed(() => saveFailureShot(page, 'web-e2e-search-marker-room'))
|
|
await expandOwningTurnProcess(page, page.locator('[data-tool="web_search"]'))
|
|
// `overflow-y: auto` clips inline-start overflow with no way to scroll it
|
|
// back, and markers are right-aligned to the content edge, so a marker wider
|
|
// than `padding-left` silently loses its leading digits. `searchMaxResults`
|
|
// is an unbounded positive integer, so measure the widest three-digit marker
|
|
// in the list's own font and require the shipped padding to hold it.
|
|
const marker = await page.locator('[data-web="search"] ol').evaluate((element) => {
|
|
const probe = document.createElement('span')
|
|
probe.style.cssText = 'position:absolute;visibility:hidden;white-space:pre;font:inherit'
|
|
probe.textContent = '999. '
|
|
element.append(probe)
|
|
const widest = probe.getBoundingClientRect().width
|
|
probe.remove()
|
|
return { widest, paddingLeft: parseFloat(getComputedStyle(element).paddingLeft) }
|
|
})
|
|
expect(marker.paddingLeft).toBeGreaterThanOrEqual(marker.widest)
|
|
})
|
|
|
|
it.skipIf(MODE === 'record')('stayed clean and kept the exact fixture inventory', async () => {
|
|
expect(tripwire.pageErrors).toEqual([])
|
|
expect(tripwire.warnings).toEqual([])
|
|
await assertFixtureInventory(SNAPSHOT_DIR, ['session.v3.jsonl', 'ui.expected.md'])
|
|
})
|
|
})
|