Skip to content
Merged
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
8 changes: 5 additions & 3 deletions src/node/services/aiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,21 @@ import type {
} from "@/common/types/stream";
import { applyToolPolicy, type ToolPolicy } from "@/common/utils/tools/toolPolicy";
import { MockScenarioPlayer } from "./mock/mockScenarioPlayer";
import { Agent } from "undici";
import { EnvHttpProxyAgent, type Dispatcher } from "undici";

// Export a standalone version of getToolsForModel for use in backend

// Create undici agent with unlimited timeouts for AI streaming requests.
// Safe because users control cancellation via AbortSignal from the UI.
const unlimitedTimeoutAgent = new Agent({
// Uses EnvHttpProxyAgent to automatically respect HTTP_PROXY, HTTPS_PROXY,
// and NO_PROXY environment variables for debugging/corporate network support.
const unlimitedTimeoutAgent = new EnvHttpProxyAgent({
bodyTimeout: 0, // No timeout - prevents BodyTimeoutError on long reasoning pauses
headersTimeout: 0, // No timeout for headers
});

// Extend RequestInit with undici-specific dispatcher property (Node.js only)
type RequestInitWithDispatcher = RequestInit & { dispatcher?: InstanceType<typeof Agent> };
type RequestInitWithDispatcher = RequestInit & { dispatcher?: Dispatcher };

/**
* Default fetch function with unlimited timeouts for AI streaming.
Expand Down