Skip to content
Open
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
20 changes: 20 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Deep Code 使用 `settings.json` 设置文件进行持久化配置,支持两
| `thinkingEnabled` | boolean | 是否启用思考模式(DeepSeek V4 系列默认启用) |
| `reasoningEffort` | string | 推理强度,可选 `"high"` 或 `"max"`(默认 `"max"`) |
| `debugLogEnabled` | boolean | 是否启用调试日志输出(默认 `false`) |
| `requestTimeoutMs` | number | 主模型请求超时时间,单位毫秒。`0` 表示不启用超时(默认 `0`) |
| `maxRetries` | number | 主模型请求遇到临时网络错误时的最大重试次数(默认 `2`,最大 `10`) |
| `notify` | string | 任务完成通知脚本的完整路径(如 Slack 通知脚本) |
| `webSearchTool` | string | 自定义联网搜索脚本的完整路径 |
| `mcpServers` | object | MCP 服务器配置(键为服务名,值为 McpServerConfig 对象) |
Expand All @@ -45,6 +47,8 @@ Deep Code 使用 `settings.json` 设置文件进行持久化配置,支持两
| `THINKING_ENABLED` | string | 是否启用思考模式 |
| `REASONING_EFFORT` | string | 推理强度 |
| `DEBUG_LOG_ENABLED` | string | 是否启用调试日志输出 |
| `REQUEST_TIMEOUT_MS` | string | 主模型请求超时时间,单位毫秒。`0` 表示不启用超时 |
| `MAX_RETRIES` | string | 主模型请求遇到临时网络错误时的最大重试次数 |
| `<其他任意KEY>` | string | 自定义环境变量 |

#### `thinkingEnabled` — 思考模式
Expand Down Expand Up @@ -130,6 +134,22 @@ MCP(Model Context Protocol)服务器配置。值是键值对,键为服务

设为 `true` 可让程序输出详细的调试日志(默认 `false`),用于排查 API 调用和工具执行的问题。

#### `requestTimeoutMs` 与 `maxRetries` — 请求超时与重试

用于控制主模型 Chat Completion 请求的超时和自动重试:

```json
{
"requestTimeoutMs": 300000,
"maxRetries": 2
}
```

- `requestTimeoutMs` 单位为毫秒。默认 `0` 表示不启用请求超时,避免长时间思考或长输出被意外中断。
- `maxRetries` 默认 `2`,最大 `10`。仅对临时错误重试,例如网络断开、请求超时、HTTP `408`、`409`、`425`、`429` 和 `5xx`。
- 用户主动中断、权限拒绝、HTTP `400`、`401`、`403`、`404` 等配置或请求错误不会自动重试。
- 也可以通过环境变量配置:`DEEPCODE_REQUEST_TIMEOUT_MS=300000`、`DEEPCODE_MAX_RETRIES=2`。

## 环境变量优先级

环境变量是配置应用程序的常用方式,尤其适用于敏感信息(如 api-key)或可能在不同环境之间更改的设置。
Expand Down
22 changes: 21 additions & 1 deletion docs/configuration_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ The following are all the top-level fields supported in `settings.json`, along w
| `thinkingEnabled` | boolean | Whether to enable thinking mode (enabled by default for DeepSeek V4 series)|
| `reasoningEffort` | string | Reasoning intensity, either `"high"` or `"max"` (default `"max"`) |
| `debugLogEnabled` | boolean | Enable debug log output (default `false`) |
| `requestTimeoutMs` | number | Main model request timeout in milliseconds. `0` disables the timeout (default `0`) |
| `maxRetries` | number | Maximum retry count for transient main model request failures (default `2`, max `10`) |
| `notify` | string | Full path to a task-completion notification script (e.g., Slack notification script) |
| `webSearchTool` | string | Full path to a custom web search script |
| `mcpServers` | object | MCP server configurations (keys are service names, values are McpServerConfig objects) |
Expand All @@ -45,6 +47,8 @@ The following are all the top-level fields supported in `settings.json`, along w
| `THINKING_ENABLED`| string | Enable thinking mode |
| `REASONING_EFFORT`| string | Reasoning intensity |
| `DEBUG_LOG_ENABLED`| string| Enable debug log output |
| `REQUEST_TIMEOUT_MS`| string | Main model request timeout in milliseconds. `0` disables the timeout |
| `MAX_RETRIES` | string | Maximum retry count for transient main model request failures |
| `<any other KEY>` | string | Custom environment variable |

#### `thinkingEnabled` — Thinking Mode
Expand Down Expand Up @@ -129,6 +133,22 @@ For detailed MCP usage instructions, refer to [mcp.md](mcp.md).

Set to `true` to enable detailed debug logging (default `false`), useful for troubleshooting API calls and tool execution.

#### `requestTimeoutMs` and `maxRetries` — Request Timeout and Retries

Controls timeout and automatic retries for main model Chat Completion requests:

```json
{
"requestTimeoutMs": 300000,
"maxRetries": 2
}
```

- `requestTimeoutMs` is in milliseconds. The default `0` disables request timeout so long thinking or long outputs are not interrupted unexpectedly.
- `maxRetries` defaults to `2` and is capped at `10`. Retries apply only to transient failures, such as network disconnects, request timeouts, HTTP `408`, `409`, `425`, `429`, and `5xx`.
- User interrupts, permission denials, HTTP `400`, `401`, `403`, `404`, and other request/configuration errors are not retried.
- You can also configure these through environment variables: `DEEPCODE_REQUEST_TIMEOUT_MS=300000`, `DEEPCODE_MAX_RETRIES=2`.

## Environment Variable Priority

Environment variables are a common way to configure applications, especially for sensitive information (such as api-key) or settings that may change between environments.
Expand Down Expand Up @@ -181,4 +201,4 @@ Applied in the following priority order (lower-numbered overridden by higher-num
2. User-level settings.json: `{"env": {"MCP_GITHUB_PERSONAL_ACCESS_TOKEN": "..."}}`
3. Project-level settings.json: `{"mcpServers":{"github":{"env":{"GITHUB_PERSONAL_ACCESS_TOKEN":"..."}}}}`
4. Project-level settings.json: `{"env": {"MCP_GITHUB_PERSONAL_ACCESS_TOKEN": "..."}}`
5. System environment variable: `DEEPCODE_MCP_GITHUB_PERSONAL_ACCESS_TOKEN=... deepcode`
5. System environment variable: `DEEPCODE_MCP_GITHUB_PERSONAL_ACCESS_TOKEN=... deepcode`
8 changes: 8 additions & 0 deletions src/common/openai-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export function createOpenAIClient(projectRoot: string = process.cwd()): {
thinkingEnabled: boolean;
reasoningEffort: "high" | "max";
debugLogEnabled: boolean;
requestTimeoutMs: number;
maxRetries: number;
notify?: string;
webSearchTool?: string;
env: Record<string, string>;
Expand All @@ -40,6 +42,8 @@ export function createOpenAIClient(projectRoot: string = process.cwd()): {
thinkingEnabled: settings.thinkingEnabled,
reasoningEffort: settings.reasoningEffort,
debugLogEnabled: settings.debugLogEnabled,
requestTimeoutMs: settings.requestTimeoutMs,
maxRetries: settings.maxRetries,
notify: settings.notify,
webSearchTool: settings.webSearchTool,
env: settings.env,
Expand All @@ -56,6 +60,8 @@ export function createOpenAIClient(projectRoot: string = process.cwd()): {
thinkingEnabled: settings.thinkingEnabled,
reasoningEffort: settings.reasoningEffort,
debugLogEnabled: settings.debugLogEnabled,
requestTimeoutMs: settings.requestTimeoutMs,
maxRetries: settings.maxRetries,
notify: settings.notify,
webSearchTool: settings.webSearchTool,
env: settings.env,
Expand Down Expand Up @@ -91,6 +97,8 @@ export function createOpenAIClient(projectRoot: string = process.cwd()): {
thinkingEnabled: settings.thinkingEnabled,
reasoningEffort: settings.reasoningEffort,
debugLogEnabled: settings.debugLogEnabled,
requestTimeoutMs: settings.requestTimeoutMs,
maxRetries: settings.maxRetries,
notify: settings.notify,
webSearchTool: settings.webSearchTool,
env: settings.env,
Expand Down
Loading
Loading