A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Name the asking Session in native searches on OpenCode routes
Fei2411c634a3d1fe2f
diff --git a/ds-bot/test/web-search.test.js b/ds-bot/test/web-search.test.jsindex 3edd5929..7557e92b 100644--- a/ds-bot/test/web-search.test.js+++ b/ds-bot/test/web-search.test.js@@ -87,9 +87,9 @@ test('routeOf reads the asking Session route: protocol, endpoint, key name, and{ provider: 'moonshotai', settingsNs: 'llm-pi-ai', settingsPath: ['providers', 'moonshotai'] },{ provider: 'deepseek-official', settingsNs: 'llm-deepseek-api-key', settingsPath: [] },]- const ctxFor = (provider, env = {}) => ({+ const ctxFor = (provider, env = {}, id) => ({get: name => ({- agents: { currentInitiator: () => ({ session: { requestContext: () => ({ provider, model: 'x' }) } }) },+ agents: { currentInitiator: () => ({ session: { id, requestContext: () => ({ provider, model: 'x' }) } }) },llm: { listConfigurableProviders: () => directory },settings: { describe: () => settings },launchEnvironment: { get: key => (env[key] === undefined ? undefined : { value: env[key] }) },@@ -108,11 +108,41 @@ test('routeOf reads the asking Session route: protocol, endpoint, key name, and})assert.equal(routeOf(ctxFor('openrouter')).api, undefined)assert.equal(routeOf({ get: () => undefined }), undefined)+ // 公开#184: OpenCode's gateways answered HTTP 400 "missing x-opencode-session" to every+ // native search, so web_search always fell back to the keyless results page.+ assert.deepEqual(routeOf(ctxFor('opencode-go', {}, 'sess-184')).headers, { 'x-opencode-session': 'sess-184' })+ assert.deepEqual(routeOf(ctxFor('opencode', {}, 'sess-184')).headers, { 'x-opencode-session': 'sess-184' })+ assert.deepEqual(routeOf(ctxFor('mimo', {}, 'sess-184')).headers, { 'x-team': 'bots' })+ settings.push({ ns: 'llm-pi-ai-oc', value: { headers: { 'X-OpenCode-Session': 'mine' } } })+ directory.push({ provider: 'opencode', settingsNs: 'llm-pi-ai-oc', settingsPath: [] })+ assert.deepEqual(routeOf(ctxFor('opencode', {}, 'sess-184')).headers, { 'X-OpenCode-Session': 'mine' })})// ---------------------------------------------------------------------------// Native search: own key, own origin, found by trying+test('a native search on an OpenCode route names the asking Session, as the gateway requires', async () => {+ const ctx = {+ get: name => ({+ agents: { currentInitiator: () => ({ session: { id: 'sess-184', requestContext: () => ({ provider: 'opencode-go', model: 'glm-5' }) } }) },+ llm: { listConfigurableProviders: () => [] },+ settings: { describe: () => [] },+ })[name],+ }+ const route = { ...routeOf(ctx), api: 'openai-responses' }+ const { provider, calls } = harness({+ route,+ keys: { OPENCODE_API_KEY: 'sk-oc' },+ fetch: (_url, init) => (init.headers['x-opencode-session'] === undefined+ ? json({ error: { message: 'Request is missing x-opencode-session' } }, 400)+ : json({ output: [{ type: 'web_search_call' }, { type: 'message', content: [{ type: 'output_text', text: 'ok', annotations: [{ type: 'url_citation', url: 'https://o.example/', title: 'O' }] }] }] })),+ })+ const result = await provider.search({ query: 'opencode news' })+ assert.deepEqual(result.sources, [{ url: 'https://o.example/', title: 'O' }])+ assert.equal(calls.fetch[0].init.headers['x-opencode-session'], 'sess-184')+ assert.equal(calls.webFetch.length, 0)+})+test('a host this plugin has never heard of gets native search through its protocol', async () => {const { provider, calls } = harness({route: ACME,diff --git a/ds-bot/web-search.js b/ds-bot/web-search.jsindex 9565cc83..1d56111a 100644--- a/ds-bot/web-search.js+++ b/ds-bot/web-search.js@@ -720,9 +720,20 @@ export function createAutoSearchProvider(deps, config = {}) {const stringRecord = value => (isRecord(value) ? Object.fromEntries(Object.entries(value).filter(([, item]) => typeof item === 'string')) : {})+// OpenCode's gateways turn away a request that does not name its conversation. DSH's+// adapter names it by the Session id, so a search for that Session does the same,+// unless the provider settings name one.+const OPENCODE_SESSION = 'x-opencode-session'+const OPENCODE_ROUTES = new Set(['opencode', 'opencode-go'])+const withConversation = (provider, headers, sessionId) => (!OPENCODE_ROUTES.has(provider) || sessionId === undefined+ || Object.keys(headers).some(name => name.toLowerCase() === OPENCODE_SESSION)+ ? headers+ : { ...headers, [OPENCODE_SESSION]: sessionId })+/** The route of the Session that started the current tool call: protocol, endpoint, key name, and headers. */export function routeOf(ctx) {- const request = ctx.get('agents')?.currentInitiator()?.session.requestContext()+ const session = ctx.get('agents')?.currentInitiator()?.session+ const request = session?.requestContext()const provider = str(request?.provider)if (provider === undefined) return undefinedlet section@@ -742,7 +753,7 @@ export function routeOf(ctx) {baseURL: str(section?.baseURL) ?? (DSH_DEEPSEEK_ROUTES.has(provider) ? str(envOf(ctx)('DEEPSEEK_BASE_URL')) : undefined) ?? catalogBase,apiKeyEnv: account ? undefined : str(section?.apiKeyEnv) ?? catalogKey,account,- headers: stringRecord(section?.headers),+ headers: withConversation(provider, stringRecord(section?.headers), str(session.id)),}}