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
43 changes: 43 additions & 0 deletions docs/en/docs/integrations/dsh.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,43 @@ the Server default/workspace binding, or set it to an existing Scope intentional
Environment overrides take precedence over plugin patch values, which take precedence over defaults. They must be
present in the process launching DSH; changing another terminal's environment does not update a running host.

## Use a custom Responses API provider

The plugin registers the Server's MCP tools with DSH, and DSH sends their definitions with every model request. A
custom `llm-pi-ai` provider that declares `api: openai-responses` sends function tools without a `strict` field
unless it sets `compat.supportsStrictMode`. The OpenAI Responses API applies strict mode to a function tool that
omits the field, and it fails a request that carries the PowerContext tool definitions in that mode. The stream ends
with `server_error`, and DSH reports:

```text
dsh: PI_AI_ERROR: An error occurred while processing your request.
```

Set the switch on the provider in the profile's `cordis.patch.yml`:

```yaml
- id: llm-pi-ai
config:
providers:
my-openai:
displayName: OpenAI
api: openai-responses
baseURL: https://api.openai.com/v1
apiKeyEnv: OPENAI_API_KEY
compat:
supportsStrictMode: true
models:
- id: gpt-4.1-mini
contextWindow: 400000
maxTokens: 8000
```

With the switch, DSH sends every function tool with `strict: false` and leaves its JSON Schema unchanged. A model
entry accepts the same `compat` block when only some models of the provider need it. Models that DSH serves from its
installed catalog, such as those of the built-in `openai` provider, already send `strict: false`, and providers that
use `api: openai-completions` are not affected. The provider for the
[PowerContext gateway](#point-dsh-at-the-gateway) is a custom Responses provider and needs the switch.

## Optional long-term memory for dsh-pet

Pet chat in DSH Web and Desktop can recall older preferences from a dedicated PowerContext Scope while keeping the pet's
Expand Down Expand Up @@ -667,6 +704,8 @@ gateway's `/gateway/v1` to `llm-pi-ai` with `api: openai-responses`, and select
api: openai-responses
baseURL: http://127.0.0.1:8787/gateway/v1
apiKeyEnv: PC_GATEWAY_KEY
compat:
supportsStrictMode: true
models:
- id: approved-model
contextWindow: 400000
Expand All @@ -680,6 +719,10 @@ gateway's `/gateway/v1` to `llm-pi-ai` with `api: openai-responses`, and select
If the profile already configures `llm-pi-ai` providers, add `powercontext-gateway` to that `providers` map instead of
adding a second entry. Export the gateway's `PC_GATEWAY_API_KEY` value as `PC_GATEWAY_KEY` where DSH starts.

`compat.supportsStrictMode` makes DSH send its tool definitions, including the PowerContext MCP tools, with
`strict: false`. The gateway forwards tool definitions as DSH sends them, so without the switch the upstream fails as
described in [Use a custom Responses API provider](#use-a-custom-responses-api-provider).

Use the Responses API. DSH always streams. On the Responses route, the gateway calls the model without streaming and
replays the checked response to DSH as a stream, so the turn completes and is captured. On the Chat Completions route
(`api: openai-completions`), the gateway forwards DSH's streamed request. An enforcing Core withholds the streamed
Expand Down
42 changes: 42 additions & 0 deletions docs/zh/docs/integrations/dsh.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,42 @@ Web 和 Desktop 共用已保存的 `hosts.dsh` 连接设置及 `$DSH_HOME/powerc
已有界面和模型 patch 可以保留。setup 会检查合成后的 PowerContext 连接设置;冲突处理和动态配置限制见
[远程连接配置](../operate/connect-remote-server.md)。原生 include 文件必须存在,循环引用、不支持的文件类型或无法验证的动态结构会在保存前报错。

## 使用自定义的 Responses API provider

插件把 Server 的 MCP 工具注册到 DSH,DSH 在每次模型请求中都会带上这些工具的定义。
自定义的 `llm-pi-ai` provider 如果声明了 `api: openai-responses`,又没有设置 `compat.supportsStrictMode`,
发出的函数工具就不带 `strict` 字段。OpenAI Responses API 会对缺少该字段的函数工具启用 strict 模式,
而带有 PowerContext 工具定义的请求在这种模式下会失败:响应流以 `server_error` 结束,DSH 报告:

```text
dsh: PI_AI_ERROR: An error occurred while processing your request.
```

请在 profile 的 `cordis.patch.yml` 中为该 provider 打开这个开关:

```yaml
- id: llm-pi-ai
config:
providers:
my-openai:
displayName: OpenAI
api: openai-responses
baseURL: https://api.openai.com/v1
apiKeyEnv: OPENAI_API_KEY
compat:
supportsStrictMode: true
models:
- id: gpt-4.1-mini
contextWindow: 400000
maxTokens: 8000
```

打开后,DSH 发出的每个函数工具都带 `strict: false`,JSON Schema 保持不变。
如果只有部分模型需要,也可以把同样的 `compat` 写在模型条目上。
DSH 从自带模型目录提供的模型(例如内置 `openai` provider 的模型)本来就发送 `strict: false`;
使用 `api: openai-completions` 的 provider 不受影响。
[PowerContext gateway](#让-dsh-指向-gateway) 的 provider 属于自定义的 Responses provider,需要打开这个开关。

## 可选:为 dsh-pet 开启长期记忆

DSH Web 和 Desktop 的桌宠聊天可以从独立的 PowerContext Scope 查找旧偏好,原有的人设、近期窗口和本地聊天记录照常使用。
Expand Down Expand Up @@ -569,6 +605,8 @@ DSH 会把密钥作为 bearer token 发送:
api: openai-responses
baseURL: http://127.0.0.1:8787/gateway/v1
apiKeyEnv: PC_GATEWAY_KEY
compat:
supportsStrictMode: true
models:
- id: approved-model
contextWindow: 400000
Expand All @@ -582,6 +620,10 @@ DSH 会把密钥作为 bearer token 发送:
如果 profile 已经配置了 `llm-pi-ai` 的 provider,请把 `powercontext-gateway` 加到已有的 `providers` 中,
不要再添加一个条目。在启动 DSH 的环境中,把 gateway 的 `PC_GATEWAY_API_KEY` 的值导出为 `PC_GATEWAY_KEY`。

`compat.supportsStrictMode` 让 DSH 发出的工具定义(包括 PowerContext 的 MCP 工具)带上 `strict: false`。
gateway 按 DSH 发来的内容转发工具定义,缺少这个开关时,上游会像
[使用自定义的 Responses API provider](#使用自定义的-responses-api-provider)所述那样失败。

请使用 Responses API。DSH 总是流式请求。在 Responses 路由上,gateway 以非流式方式调用模型,
再把检查通过的响应以流的形式重放给 DSH,因此这一轮能够完成并被采集。
在 Chat Completions 路由(`api: openai-completions`)上,gateway 转发 DSH 的流式请求。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ The file also retains ordinary Python transport-policy tests that require no DSH
These tests launch the real `dsh --profile sdk` subprocess and a real PowerContext Server with isolated homes.
Only the built distributable plugin files are installed. Host tool registration, pre-step processing, message
construction, model request assembly, and session persistence are not replaced. A loopback model fixture provides
scripted OpenAI-compatible streaming replies and Server inference decisions. A loopback proxy can inject HTTP
scripted OpenAI-compatible streaming replies and Server inference decisions. It also answers the OpenAI
Responses API for the scenario that configures a custom `llm-pi-ai` Responses provider and checks the tool definitions
DSH sends. A loopback proxy can inject HTTP
failures at individual PowerContext endpoints or hold the native MCP initialization response.

The setup scenario first runs `powercontext setup dsh --source <this checkout>` with the pinned DSH executable
Expand Down
28 changes: 26 additions & 2 deletions integrations/dsh/plugins/powercontext/tests/runtime/fixture.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,28 @@ export async function environment({ realModel, fullCatalog = false } = {}) {
const model = await listen(async (req, res) => {
const body = await bodyOf(req)
modelRequests.push(body)
if (new URL(req.url, 'http://localhost').pathname.endsWith('/responses')) {
const item = {
id: 'msg_fixture', type: 'message', role: 'assistant', status: 'completed',
content: [{ type: 'output_text', text: 'Task completed.', annotations: [] }],
}
const response = {
id: 'resp_fixture', object: 'response', model: body.model, created_at: 0, status: 'completed',
output: [item], usage: { input_tokens: 10, output_tokens: 10, total_tokens: 20 },
}
res.writeHead(200, { 'Content-Type': 'text/event-stream' })
res.end([
{ type: 'response.created', response: { ...response, status: 'in_progress', output: [] } },
{ type: 'response.output_item.added', output_index: 0, item: { ...item, status: 'in_progress', content: [] } },
{ type: 'response.content_part.added', item_id: item.id, output_index: 0, content_index: 0,
part: { type: 'output_text', text: '', annotations: [] } },
{ type: 'response.output_text.delta', item_id: item.id, output_index: 0, content_index: 0,
delta: item.content[0].text },
{ type: 'response.output_item.done', output_index: 0, item },
{ type: 'response.completed', response },
].map(event => `event: ${event.type}\ndata: ${JSON.stringify(event)}\n\n`).join(''))
return
}
if (realModel) {
const upstream = await fetch(realModel.baseUrl.replace(/\/$/, '') + '/chat/completions', {
method: 'POST', signal: AbortSignal.timeout(90000),
Expand Down Expand Up @@ -360,6 +382,7 @@ export function apply(ctx) {
{ id: 'skill-filesystem', config: { watch: false } },
{ id: 'session-persistence-jsonl', config: { root: join(dshHome, 'sessions'), compression: 'none' } },
{ id: 'llm-deepseek', config: { baseURL: model.url + '/v1', apiKeyEnv: 'DEEPSEEK_API_KEY', thinking: 'disabled' } },
...options.patches ?? [],
{ insert: [{ id: 'powercontext-dsh', name: pathToFileURL(join(installed, 'lib/index.js')).href, config: {
baseUrl: proxy.url, timeoutMs: 15000, requestTimeoutMs: 5000, flushOnCapture: true, ...config,
} }] },
Expand All @@ -372,7 +395,8 @@ export function apply(ctx) {
DEEPSEEK_BASE_URL: model.url + '/v1', DSH_TELEMETRY_DISABLED: '1', ...options.env }
const instance = new DeepSeekHarness({
dshBin: process.env.DSH_TEST_BIN ?? dshBin, dshHome, patches: [patch], cwd: workspace, processCwd: workspace,
provider: 'deepseek-official', model: realModel?.model ?? 'deepseek-v4-flash', maxTokens,
provider: options.provider ?? 'deepseek-official',
model: options.model ?? realModel?.model ?? 'deepseek-v4-flash', maxTokens,
initializeTimeoutMs, requestTimeoutMs: realModel ? 120000 : 30000,
env,
})
Expand All @@ -397,7 +421,7 @@ export function apply(ctx) {
return { instance, dshHome, workspace, installed, patch, env, diagnostics, contextTraces, doctor, status }
}
return {
home, api, scopeId, calls, mcpCalls, modelRequests, harness, baseUrl: proxy.url,
home, api, scopeId, calls, mcpCalls, modelRequests, harness, baseUrl: proxy.url, modelUrl: model.url,
setFault(value) {
fault = value
if (fault?.path !== '/mcp' || !fault.hold) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,3 +447,35 @@ test('real DSH enforces the host Scope for native MCP path arguments before disp
assert.ok(result?.content.includes(env.scopeId))
} finally { await env.close() }
})

test('a custom Responses provider with supportsStrictMode sends each PowerContext MCP tool non-strict with its schema unchanged',
{ timeout: 120000 }, async () => {
const env = await environment()
try {
const { instance } = env.harness({}, {
provider: 'responses-fixture', model: 'fixture',
patches: [{ id: 'llm-pi-ai', config: { providers: { 'responses-fixture': {
api: 'openai-responses', baseURL: env.modelUrl + '/v1', apiKeyEnv: 'DEEPSEEK_API_KEY',
compat: { supportsStrictMode: true },
models: [{ id: 'fixture', contextWindow: 128000, maxTokens: 4096 }],
} } } }],
})
const run = await instance.run('Reply with an acknowledgement.')
assert.ok(run.finalResponse)
const catalog = env.mcpCalls.filter(call => call.body?.method === 'tools/list')
.flatMap(call => call.result?.tools ?? [])
assert.ok(catalog.length, 'catalog must be observed on the actual Server MCP connection')
// The OpenAI Responses API applies strict mode to a tool that omits `strict` and then fails on these unions.
assert.ok(JSON.stringify(catalog).includes('"anyOf"'), 'the Server catalog no longer contains a union schema')
const request = env.modelRequests.find(r => Array.isArray(r.input) && r.tools?.length)
assert.ok(request, 'the agent step must reach the Responses fixture')
const sent = new Map(request.tools.filter(tool => tool.name.startsWith('mcp__powercontext__'))
.map(tool => [tool.name, tool]))
assert.equal(sent.size, catalog.length)
for (const tool of catalog) {
const definition = sent.get(`mcp__powercontext__${tool.name}`)
assert.equal(definition?.strict, false, `${tool.name} must be sent with strict: false`)
assert.deepEqual(definition.parameters, tool.inputSchema)
}
} finally { await env.close() }
})