2026-07-13 23:27:00 +08:00
|
|
|
/**
|
|
|
|
|
* Real Loader-path guard for an injected namespace plugin. A default export would make
|
|
|
|
|
* `unwrapExports` collapse the namespace and drop `inject`, causing access to `ctx.web` to fail.
|
|
|
|
|
* Hand-built mounting bypasses that path, so this test unwraps through the real Loader first; see
|
|
|
|
|
* postmortem 0001.
|
|
|
|
|
*/
|
Add web capability seam: ctx.web, search/fetch providers, web tools
Introduce web access as a first-class capability seam so the model-facing
web tools stay stable while backends change. dsh-web owns ctx.web as a
provider registry with registration-order-independent selection and the
WebError taxonomy; dsh-web-search-exa, dsh-web-search-perplexity, and
dsh-web-fetch-local register capabilities into it; dsh-tool-web is the sole
owner of the model-facing web_search/web_fetch schemas, prompt sections, and
HTML-to-markdown presentation. Search and fetch are deliberately one seam.
Providers ship as namespace plugins that register into ctx.web (like an
LlmAdapter into ctx.llm), not key-owning services, since multiple search
providers cannot each own the key. Tool registration follows product
enablement, not backend availability, so load order/credentials never enter
the model contract; the seam resolves the provider at execution time and
surfaces a structured WebError otherwise.
Moves the RFC to implemented/ amended to match what shipped. Example/app
configs are intentionally not wired yet (RFC migration step 6).
2026-06-25 15:04:12 +08:00
|
|
|
|
|
|
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
|
import { Context } from 'cordis'
|
|
|
|
|
import Loader from '@cordisjs/plugin-loader'
|
|
|
|
|
import SystemPrompt from '@deepseek-ai/dsh-system-prompt'
|
|
|
|
|
import ToolRegistry from '@deepseek-ai/dsh-tools'
|
|
|
|
|
import WebService from '@deepseek-ai/dsh-web'
|
|
|
|
|
import * as toolWeb from '@deepseek-ai/dsh-tool-web'
|
|
|
|
|
|
|
|
|
|
describe('dsh-tool-web real-load-path guard', () => {
|
|
|
|
|
it('has no default export and keeps name/inject/Config through unwrapExports', () => {
|
|
|
|
|
expect('default' in toolWeb).toBe(false)
|
|
|
|
|
|
|
|
|
|
const loader = Object.create(Loader.prototype) as Loader
|
|
|
|
|
const unwrapped = loader.unwrapExports(toolWeb) as Record<string, unknown>
|
|
|
|
|
expect(unwrapped).toBe(toolWeb)
|
|
|
|
|
expect(unwrapped.name).toBe('tool-web')
|
|
|
|
|
expect(unwrapped.inject).toEqual(['tools', 'web', 'systemPrompt'])
|
|
|
|
|
expect(typeof unwrapped.apply).toBe('function')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('boots over ctx.web through the unwrapped module without an inject error', async () => {
|
|
|
|
|
const ctx = new Context()
|
|
|
|
|
await ctx.plugin(SystemPrompt)
|
|
|
|
|
await ctx.plugin(ToolRegistry)
|
|
|
|
|
await ctx.plugin(WebService, {})
|
|
|
|
|
|
|
|
|
|
const loader = Object.create(Loader.prototype) as Loader
|
|
|
|
|
const unwrapped = loader.unwrapExports(toolWeb) as Parameters<Context['plugin']>[0]
|
2026-07-13 23:27:00 +08:00
|
|
|
// Mounting the collapsed shape would throw for missing injection here.
|
Add web capability seam: ctx.web, search/fetch providers, web tools
Introduce web access as a first-class capability seam so the model-facing
web tools stay stable while backends change. dsh-web owns ctx.web as a
provider registry with registration-order-independent selection and the
WebError taxonomy; dsh-web-search-exa, dsh-web-search-perplexity, and
dsh-web-fetch-local register capabilities into it; dsh-tool-web is the sole
owner of the model-facing web_search/web_fetch schemas, prompt sections, and
HTML-to-markdown presentation. Search and fetch are deliberately one seam.
Providers ship as namespace plugins that register into ctx.web (like an
LlmAdapter into ctx.llm), not key-owning services, since multiple search
providers cannot each own the key. Tool registration follows product
enablement, not backend availability, so load order/credentials never enter
the model contract; the seam resolves the provider at execution time and
surfaces a structured WebError otherwise.
Moves the RFC to implemented/ amended to match what shipped. Example/app
configs are intentionally not wired yet (RFC migration step 6).
2026-06-25 15:04:12 +08:00
|
|
|
const fiber = await ctx.plugin(unwrapped)
|
|
|
|
|
expect(ctx.tools.schemas().map(s => s.name)).toEqual(expect.arrayContaining(['web_search', 'web_fetch']))
|
|
|
|
|
await fiber.dispose()
|
|
|
|
|
})
|
|
|
|
|
})
|