|
1 | 1 | import { randomUUID } from "node:crypto"; |
2 | 2 | import type { IncomingMessage, ServerResponse } from "node:http"; |
| 3 | +import { isClientToolNameConflictError } from "../agents/agent-tool-definition-adapter.js"; |
3 | 4 | import type { AgentStreamParams, ClientToolDefinition } from "../agents/command/shared-types.js"; |
4 | 5 | import type { ImageContent } from "../agents/command/types.js"; |
5 | | -import { isClientToolNameConflictError } from "../agents/agent-tool-definition-adapter.js"; |
6 | 6 | import { STREAM_ERROR_FALLBACK_TEXT } from "../agents/stream-message-shared.js"; |
7 | 7 | import { |
8 | 8 | hasNonzeroUsage, |
@@ -28,6 +28,7 @@ import {
|
28 | 28 | type InputImageSource, |
29 | 29 | } from "../media/input-files.js"; |
30 | 30 | import { defaultRuntime } from "../runtime.js"; |
| 31 | +import { resolveIntegerOption } from "../shared/number-coercion.js"; |
31 | 32 | import { |
32 | 33 | normalizeLowercaseStringOrEmpty, |
33 | 34 | normalizeOptionalString, |
@@ -111,14 +112,14 @@ function resolveOpenAiChatCompletionsLimits(
|
111 | 112 | const imageConfig = config?.images; |
112 | 113 | return { |
113 | 114 | maxBodyBytes: config?.maxBodyBytes ?? DEFAULT_OPENAI_CHAT_COMPLETIONS_BODY_BYTES, |
114 | | -maxImageParts: |
115 | | -typeof config?.maxImageParts === "number" |
116 | | - ? Math.max(0, Math.floor(config.maxImageParts)) |
117 | | - : DEFAULT_OPENAI_MAX_IMAGE_PARTS, |
118 | | -maxTotalImageBytes: |
119 | | -typeof config?.maxTotalImageBytes === "number" |
120 | | - ? Math.max(1, Math.floor(config.maxTotalImageBytes)) |
121 | | - : DEFAULT_OPENAI_MAX_TOTAL_IMAGE_BYTES, |
| 115 | +maxImageParts: resolveIntegerOption(config?.maxImageParts, DEFAULT_OPENAI_MAX_IMAGE_PARTS, { |
| 116 | +min: 0, |
| 117 | +}), |
| 118 | +maxTotalImageBytes: resolveIntegerOption( |
| 119 | + config?.maxTotalImageBytes, |
| 120 | +DEFAULT_OPENAI_MAX_TOTAL_IMAGE_BYTES, |
| 121 | +{ min: 1 }, |
| 122 | +), |
122 | 123 | images: { |
123 | 124 | allowUrl: imageConfig?.allowUrl ?? DEFAULT_OPENAI_IMAGE_LIMITS.allowUrl, |
124 | 125 | urlAllowlist: normalizeInputHostnameAllowlist(imageConfig?.urlAllowlist), |
|