refactor(providers): migrate legacy API selector at input boundary

This commit is contained in:
chengyongru authored and chengyongru committed 2026-10-10 01:33:02 +08:00
1 parent ed0eb89178
commit 7e2e804b5c
36 files changed
+294 -181

No files matched your search

+20 -6
View File
@@ -316,20 +316,20 @@ Tracing covers the providers that go through nanobot's OpenAI-compatible client
<details>
<summary><b>OpenAI</b></summary>
Without a preset API declaration, direct OpenAI uses `apiType: "auto"`: nanobot calls Chat Completions normally and routes GPT-5/GPT-6/o-series or explicit `reasoningEffort` requests through Responses. Prefer [preset API declarations](#preset-request-api) to select an API for each model and endpoint. The legacy provider-wide default remains available:
Without an API declaration, direct OpenAI calls Chat Completions normally and routes GPT-5/GPT-6/o-series or explicit `reasoningEffort` requests through Responses. Set `providers.openai.api` to change the connection default, or use [preset API declarations](#preset-request-api) for individual models:
```json
{
"providers": {
"openai": {
"apiKey": "${OPENAI_API_KEY}",
"apiType": "chat_completions"
"api": { "supportedApis": ["chat_completions"], "preferredApi": "chat_completions" }
}
}
}
```
Valid `apiType` values are exactly `auto`, `chat_completions`, and `responses`.
For OpenAI, the connection declaration is a default: explicit model presets can select any API supported by the adapter. Use only `chat_completions` and/or `responses`. Omit `api` or set it to `null` for automatic routing. A Responses-only declaration prevents Chat compatibility fallback; include both APIs to permit that fallback.
`extraBody` follows the selected OpenAI API surface. With Chat Completions, nanobot passes
ordinary fields through as the SDK `extra_body` value; list-valued `extraBody.tools` is handled
@@ -342,7 +342,7 @@ API body shape; nanobot merges ordinary top-level fields into the Responses requ
"providers": {
"openai": {
"apiKey": "${OPENAI_API_KEY}",
"apiType": "responses",
"api": { "supportedApis": ["responses"], "preferredApi": "responses" },
"extraBody": {
"tools": [{ "type": "web_search" }],
"include": ["web_search_call.action.sources"]
@@ -352,7 +352,7 @@ API body shape; nanobot merges ordinary top-level fields into the Responses requ
}
```
The WebUI's OpenAI web-search switch writes the corresponding `apiType` and `extraBody.tools`
The WebUI's OpenAI web-search switch writes a Responses-only `api` declaration and `extraBody.tools`
fields. A hosted search tool replaces nanobot's same-name local `web_search` function for that
request, while other tools such as `web_fetch` remain available.
@@ -1460,6 +1460,20 @@ For the built-in `custom` connection or any named custom provider, declare the p
The WebUI custom provider creation and editing forms expose **Supported APIs** and **Default API**. New connections start with Chat Completions; select the protocols your endpoint accepts. Existing connections without an `api` declaration retain their previous automatic routing. Use **Set supported APIs** to add a declaration. Removing a protocol used by an existing explicit model configuration is rejected; update the model configuration first.
### Legacy OpenAI API selector migration
`providers.openai.apiType` (or `api_type`) is accepted only as temporary input compatibility.
`chat_completions` and `responses` convert to a single-API connection declaration; `auto`
leaves automatic routing enabled. If `api` is also present, it wins, including `api: null`.
Saving configuration writes only the current declaration. Runtime adapters and the WebUI
use `api`; the OpenAI connection default remains overridable by explicit model presets.
The conversion is supported for the first release containing this migration and the immediately
following release. It will be removed before the third release. During this window, older clients'
OpenAI settings mutations using `apiType` are converted at the settings input boundary as well.
Save the configuration with a supported release to migrate it before upgrading beyond this window.
See the [release removal checklist](./releasing.md#openai-api-selector-compatibility-window).
### Preset request API
Leave API selection on **Auto** unless your provider requires a specific endpoint. For OpenAI-compatible providers and GitHub Copilot, a preset can choose Responses or Chat Completions. Custom gateways also allow Anthropic Messages. Credentials and endpoint URLs stay in the provider. Two presets sharing a provider can select different APIs.
@@ -1492,7 +1506,7 @@ Leave API selection on **Auto** unless your provider requires a specific endpoin
A custom preset declaring `anthropic_messages` uses the Anthropic adapter for message history, tools, thinking, and streaming. Its connection retains the provider's key, base URL, headers, query parameters, body additions, and explicit proxy. Anthropic requests target `/v1/messages`; a trailing `/v1` in the configured base is normalized by the adapter. Model names use the connection's existing prefix rules. Selecting this protocol does not change other presets sharing the connection.
Omit `api` or set it to `null` for automatic routing. An explicit declaration overrides provider API defaults, including legacy `providers.openai.apiType`. Automatic Copilot routing uses the account's last successfully discovered `supported_endpoints` when available; other automatic routes use registry defaults. Custom gateways use their connection API default when declared, otherwise Chat Completions. A preset can override that default only within the connection's declared supported APIs. Protocol behavior such as reasoning replay and native compaction remains provider-owned; declaring Responses support does not enable OpenAI-native compaction on a custom gateway.
Omit `api` or set it to `null` for automatic routing. An explicit model declaration overrides the OpenAI connection default. Automatic Copilot routing uses the account's last successfully discovered `supported_endpoints` when available; other automatic routes use registry defaults. Custom gateways use their connection API default when declared, otherwise Chat Completions. A preset can override that default only within the connection's declared supported APIs. Protocol behavior such as reasoning replay and native compaction remains provider-owned; declaring Responses support does not enable OpenAI-native compaction on a custom gateway.
In the WebUI, open **Settings → Models → a preset → API connection**. Choose **Auto**, **Responses**, **Chat Completions**, or **Anthropic Messages**, according to the host's declared adapter support. Auto shows the default API in parentheses, such as **Auto (Responses)**, and updates when the provider, model, or reasoning setting changes. The gateway resolves this default using the same rules as model requests, without probing remote endpoints. The label describes the default preference; compatibility failures can still activate permitted Chat fallback. Hosts that do not advertise API resolution show **Auto** without a resolved label. Selecting Responses also reveals **Try Chat Completions if Responses is unsupported**, which starts off when selecting Responses and requires the same model to support both endpoints.
+2 -2
View File
@@ -353,7 +353,7 @@ Named custom providers can also serve Anthropic Messages: declare `providers.<na
}
```
Use [preset API declarations](./configuration.md#preset-request-api) to choose Chat Completions or Responses for each model and endpoint. The legacy `providers.openai.apiType` remains a provider default for presets without a declaration; other providers reject provider-level `apiType`. Replace the model with a model ID available to your account. Direct OpenAI Responses, OpenAI Codex, Azure OpenAI Responses, and eligible GitHub Copilot models share [opaque Responses state retention](./configuration.md#responses-state-and-compaction); native compaction is enabled only where the backend supports it. The WebUI exposes provider-native switches for OpenAI web search, Codex Fast mode, DeepSeek web search, and Grok X Search. These switches write the corresponding raw provider request fields under `extraBody`.
Use [preset API declarations](./configuration.md#preset-request-api) to choose Chat Completions or Responses for each model and endpoint. Set `providers.openai.api` for the connection default; explicit presets override it. The old `apiType` input is converted during the [two-release compatibility window](./configuration.md#legacy-openai-api-selector-migration). Replace the model with a model ID available to your account. Direct OpenAI Responses, OpenAI Codex, Azure OpenAI Responses, and eligible GitHub Copilot models share [opaque Responses state retention](./configuration.md#responses-state-and-compaction); native compaction is enabled only where the backend supports it. The WebUI exposes provider-native switches for OpenAI web search, Codex Fast mode, DeepSeek web search, and Grok X Search. These switches write the corresponding raw provider request fields under `extraBody`.
DeepSeek's `deepseek-v4-flash`, `deepseek-v4-pro`, and `deepseek-v4-flash-vision-exp` automatically use its native Responses API. Its native `web_search` tool is enabled by default and shows its lifecycle in WebUI chat activity; set `providers.deepseek.extraBody.tools` to `[]` to disable it. OpenCode Go's `muse-spark-1.2-contributor` and `muse-spark-1.3-contributor` also use Responses by default.
@@ -422,7 +422,7 @@ If you have more than one custom OpenAI-compatible endpoint, give each endpoint
}
```
Custom provider keys define direct connections. Without an API declaration, they use OpenAI-compatible Chat Completions. `apiBase` is required because nanobot cannot know the endpoint URL. `apiKey` is optional for local servers or private proxies that do not require one. Choose a name that does not conflict with a built-in provider name or alias, such as `openai`, `openai-codex`, `github-copilot`, or `lm-studio`. Do not set `apiType` on custom provider keys; `apiType` is only for `providers.openai`.
Custom provider keys define direct connections. Without an API declaration, they use OpenAI-compatible Chat Completions. `apiBase` is required because nanobot cannot know the endpoint URL. `apiKey` is optional for local servers or private proxies that do not require one. Choose a name that does not conflict with a built-in provider name or alias, such as `openai`, `openai-codex`, `github-copilot`, or `lm-studio`. Declare the accepted protocols under `api` as described in [connection request APIs](./configuration.md#custom-connection-apis).
If your custom endpoint documents a nonstandard thinking toggle, set `providers.<name>.thinkingStyle` to `thinking_type`, `enable_thinking`, or `reasoning_split`; nanobot then maps `reasoningEffort` onto that provider-specific request body. Leave it unset for ordinary OpenAI-compatible endpoints.
+13
View File
@@ -45,6 +45,19 @@ uploading to PyPI, and deploying the documentation are separate operations.
tagging. Reconcile the final changelog and documentation source references. The tag must
point to this verified commit, not an unchecked later `main` tip.
### OpenAI API selector compatibility window
The temporary `providers.openai.apiType` / `api_type` conversion is supported for exactly
two consecutive releases: the first release containing `nanobot/config/provider_api_migration.py`
and the next release. Record the first release tag and the final supported tag in release notes.
Config saves write the new `api` declaration; there is no legacy runtime selector.
Before publishing the third release, remove `provider_api_migration.py`, its import and
`ProvidersConfig._migrate_legacy_api_type`, and the legacy settings query conversion in
`nanobot/webui/settings_models.py`. Remove the migration-specific tests and update the
configuration documentation and release notes to require the current format. Keep the
current-format routing, settings, and persistence regressions.
### TUI preflight without a release tag
Use Bun 1.3.13 and a clean checkout. The local build and packaging scripts do not require a