fix(ai,coding-agent): omit undefined provider request options closes #3627

This commit is contained in:
Mario Zechner
2026-04-24 14:18:35 +02:00
parent 90d8051636
commit c1b62ae7fe
6 changed files with 32 additions and 29 deletions

View File

@@ -2,6 +2,10 @@
## [Unreleased] ## [Unreleased]
### Fixed
- Fixed OpenAI/Azure/Anthropic provider request option forwarding to omit undefined `timeout`/`maxRetries`, avoiding SDK validation errors such as `timeout must be an integer` when provider controls are not set ([#3627](https://github.com/badlogic/pi-mono/issues/3627))
## [0.70.1] - 2026-04-24 ## [0.70.1] - 2026-04-24
### Added ### Added

View File

@@ -456,16 +456,12 @@ export const streamAnthropic: StreamFunction<"anthropic-messages", AnthropicOpti
if (nextParams !== undefined) { if (nextParams !== undefined) {
params = nextParams as MessageCreateParamsStreaming; params = nextParams as MessageCreateParamsStreaming;
} }
const response = await client.messages const requestOptions = {
.create( ...(options?.signal ? { signal: options.signal } : {}),
{ ...params, stream: true }, ...(options?.timeoutMs !== undefined ? { timeout: options.timeoutMs } : {}),
{ ...(options?.maxRetries !== undefined ? { maxRetries: options.maxRetries } : {}),
signal: options?.signal, };
timeout: options?.timeoutMs, const response = await client.messages.create({ ...params, stream: true }, requestOptions).asResponse();
maxRetries: options?.maxRetries,
},
)
.asResponse();
await options?.onResponse?.({ status: response.status, headers: headersToRecord(response.headers) }, model); await options?.onResponse?.({ status: response.status, headers: headersToRecord(response.headers) }, model);
stream.push({ type: "start", partial: output }); stream.push({ type: "start", partial: output });

View File

@@ -91,13 +91,12 @@ export const streamAzureOpenAIResponses: StreamFunction<"azure-openai-responses"
if (nextParams !== undefined) { if (nextParams !== undefined) {
params = nextParams as ResponseCreateParamsStreaming; params = nextParams as ResponseCreateParamsStreaming;
} }
const { data: openaiStream, response } = await client.responses const requestOptions = {
.create(params, { ...(options?.signal ? { signal: options.signal } : {}),
signal: options?.signal, ...(options?.timeoutMs !== undefined ? { timeout: options.timeoutMs } : {}),
timeout: options?.timeoutMs, ...(options?.maxRetries !== undefined ? { maxRetries: options.maxRetries } : {}),
maxRetries: options?.maxRetries, };
}) const { data: openaiStream, response } = await client.responses.create(params, requestOptions).withResponse();
.withResponse();
await options?.onResponse?.({ status: response.status, headers: headersToRecord(response.headers) }, model); await options?.onResponse?.({ status: response.status, headers: headersToRecord(response.headers) }, model);
stream.push({ type: "start", partial: output }); stream.push({ type: "start", partial: output });

View File

@@ -144,12 +144,13 @@ export const streamOpenAICompletions: StreamFunction<"openai-completions", OpenA
if (nextParams !== undefined) { if (nextParams !== undefined) {
params = nextParams as OpenAI.Chat.Completions.ChatCompletionCreateParamsStreaming; params = nextParams as OpenAI.Chat.Completions.ChatCompletionCreateParamsStreaming;
} }
const requestOptions = {
...(options?.signal ? { signal: options.signal } : {}),
...(options?.timeoutMs !== undefined ? { timeout: options.timeoutMs } : {}),
...(options?.maxRetries !== undefined ? { maxRetries: options.maxRetries } : {}),
};
const { data: openaiStream, response } = await client.chat.completions const { data: openaiStream, response } = await client.chat.completions
.create(params, { .create(params, requestOptions)
signal: options?.signal,
timeout: options?.timeoutMs,
maxRetries: options?.maxRetries,
})
.withResponse(); .withResponse();
await options?.onResponse?.({ status: response.status, headers: headersToRecord(response.headers) }, model); await options?.onResponse?.({ status: response.status, headers: headersToRecord(response.headers) }, model);
stream.push({ type: "start", partial: output }); stream.push({ type: "start", partial: output });

View File

@@ -98,13 +98,12 @@ export const streamOpenAIResponses: StreamFunction<"openai-responses", OpenAIRes
if (nextParams !== undefined) { if (nextParams !== undefined) {
params = nextParams as ResponseCreateParamsStreaming; params = nextParams as ResponseCreateParamsStreaming;
} }
const { data: openaiStream, response } = await client.responses const requestOptions = {
.create(params, { ...(options?.signal ? { signal: options.signal } : {}),
signal: options?.signal, ...(options?.timeoutMs !== undefined ? { timeout: options.timeoutMs } : {}),
timeout: options?.timeoutMs, ...(options?.maxRetries !== undefined ? { maxRetries: options.maxRetries } : {}),
maxRetries: options?.maxRetries, };
}) const { data: openaiStream, response } = await client.responses.create(params, requestOptions).withResponse();
.withResponse();
await options?.onResponse?.({ status: response.status, headers: headersToRecord(response.headers) }, model); await options?.onResponse?.({ status: response.status, headers: headersToRecord(response.headers) }, model);
stream.push({ type: "start", partial: output }); stream.push({ type: "start", partial: output });

View File

@@ -2,6 +2,10 @@
## [Unreleased] ## [Unreleased]
### Fixed
- Fixed provider retry/timeout forwarding to omit undefined provider request controls, avoiding downstream SDK validation errors such as `timeout must be an integer` when `retry.provider.timeoutMs` is not configured ([#3627](https://github.com/badlogic/pi-mono/issues/3627))
## [0.70.1] - 2026-04-24 ## [0.70.1] - 2026-04-24
### New Features ### New Features