Keep requestImageMaxBytes as the pi profile setting

This commit is contained in:
creatixchu committed 2026-11-20 12:31:53 +08:00
1 parent 2d5b444e0e
commit 286f2f3a20
12 files changed
+45 -40

No files matched your search

+2 -2
View File
@@ -2274,7 +2274,7 @@ export interface Config extends ProtocolConfig, ModelListingConfig {
- `inject`: `llm`
- `refs`: `Api` (`@earendil-works/pi-ai`) · `CacheRetention` (`@earendil-works/pi-ai`) · `Model` (`@earendil-works/pi-ai`) · `ModelThinkingLevel` (`@earendil-works/pi-ai`) · `OpenAICompletionsCompat` (`@earendil-works/pi-ai`) · [`RetryPolicyConfig`](../packages/llm/llm/src/index.ts) · `ThinkingBudgets` (`@earendil-works/pi-ai`) · `Transport` (`@earendil-works/pi-ai`) · `Volatile` (`@deepseek-ai/cordis`)
- `source`: [`packages/llm/llm-pi-ai/src/config.ts:255`](../packages/llm/llm-pi-ai/src/config.ts)
- `source`: [`packages/llm/llm-pi-ai/src/config.ts:257`](../packages/llm/llm-pi-ai/src/config.ts)
```ts config-catalog
/** Plugin configuration: the provider routes this instance owns. */
@@ -2393,7 +2393,7 @@ export interface PiAiProviderProfile {
* The effective cap is the smaller of this value and the route's equal share of maxRequestImageBytes.
* Omission uses the catalog budget converted to raw bytes, or 1 MiB without catalog metadata.
*/
maxImageBytes?: number
requestImageMaxBytes?: number
/** Provider-owned model-request retry policy; omission uses normal mode with five retries. */
retryPolicy?: RetryPolicyConfig
}
+2 -2
View File
@@ -2276,7 +2276,7 @@ export interface Config extends ProtocolConfig, ModelListingConfig {
- `inject`: `llm`
- `refs`: `Api` (`@earendil-works/pi-ai`) · `CacheRetention` (`@earendil-works/pi-ai`) · `Model` (`@earendil-works/pi-ai`) · `ModelThinkingLevel` (`@earendil-works/pi-ai`) · `OpenAICompletionsCompat` (`@earendil-works/pi-ai`) · [`RetryPolicyConfig`](../packages/llm/llm/src/index.ts) · `ThinkingBudgets` (`@earendil-works/pi-ai`) · `Transport` (`@earendil-works/pi-ai`) · `Volatile` (`@deepseek-ai/cordis`)
- `source`: [`packages/llm/llm-pi-ai/src/config.ts:255`](../packages/llm/llm-pi-ai/src/config.ts)
- `source`: [`packages/llm/llm-pi-ai/src/config.ts:257`](../packages/llm/llm-pi-ai/src/config.ts)
```ts config-catalog
/** Plugin configuration: the provider routes this instance owns. */
@@ -2395,7 +2395,7 @@ export interface PiAiProviderProfile {
* The effective cap is the smaller of this value and the route's equal share of maxRequestImageBytes.
* Omission uses the catalog budget converted to raw bytes, or 1 MiB without catalog metadata.
*/
maxImageBytes?: number
requestImageMaxBytes?: number
/** Provider-owned model-request retry policy; omission uses normal mode with five retries. */
retryPolicy?: RetryPolicyConfig
}
@@ -9,8 +9,8 @@
en: 6bee071887ac3982
zh: ec0176e47b3e64a1
/request-image-byte-limits/change:
en: f0636ed9e57d5081
zh: ad5c5584f0e8bfe1
en: 17fdb9e78254c0f4
zh: 9f31b97bede355ae
/request-image-byte-limits/migration:
en: 56bb5f70380e26b8
zh: c7a62c8709b1bd90
en: f42239aa9df6c95c
zh: ef4972f9e4f74ee8
@@ -10,13 +10,13 @@ English | [中文](guide.zh.md)
Model-request images distinguish `maxImageBytes`, a hard encoded-byte limit, from `imageTargetBytes`, a preferred target. The encoder keeps the 85/75/60 quality ladder and reduces dimensions further only when its smallest output exceeds the hard limit. Each reduction starts from the saved source. A limit that cannot fit even a 1×1 image fails with `IMAGE_REQUEST_TOO_LARGE`; oversized bytes are never returned. Stored attachments are unchanged, and request caches regenerate under a new transform version.
pi exposes only hard limits. `maxImageBytes` replaces `requestImageMaxBytes` and overrides the selected model's per-image byte cap. `requestImageBudgetCount` defaults to 20. The effective hard limit is the smaller of that cap and `3 × floor(maxRequestImageBytes / (4 × requestImageBudgetCount))`; the internal soft target equals it. Default allocation is 0.75 MiB per image. Width and height follow catalog limits unless `requestImageMaxDimension` overrides both with the same value; unequal local width/height overrides are not supported.
pi exposes only hard limits. `requestImageMaxBytes` keeps its name and now sets a hard cap on the encoded image. `requestImageBudgetCount` defaults to 20. The effective hard limit is the smaller of that cap and `3 × floor(maxRequestImageBytes / (4 × requestImageBudgetCount))`; the internal soft target equals it. Default allocation is 0.75 MiB per image. Width and height follow catalog limits unless `requestImageMaxDimension` overrides both with the same value; unequal local width/height overrides are not supported.
DeepSeek renames the configurable `imageMaxBytes` soft target to `imageTargetBytes`, retaining its 2 MiB default. Its hard cap is fixed at 32 MiB. CUA's fixed `screenshotTarget.maxBytes` also becomes a hard cap. Request-image targets describe maximum dimensions; actual output can be smaller. Aggregate request limits still apply to actual encoded payloads.
## Migration
1. In pi provider profiles, replace `requestImageMaxBytes` with `maxImageBytes` and review its hard-limit meaning. Set `requestImageBudgetCount` to the desired allocation divisor, independently of the retained-count cap. The aggregate base64 budget must allow at least four bytes per share. For 1 MiB allocations, use a sufficient aggregate budget and divisor, such as 32 MiB and 20 shares, plus `maxImageBytes: 1048576`.
1. In pi provider profiles, review any explicit `requestImageMaxBytes` value. Images that exceed this value after quality adjustment now shrink further. Set `requestImageBudgetCount` to the desired allocation divisor, independently of the retained-count cap. The aggregate base64 budget must allow at least four bytes per share. For 1 MiB allocations, use a sufficient aggregate budget and divisor, such as 32 MiB and 20 shares, plus `requestImageMaxBytes: 1048576`.
2. In DeepSeek `models` and `modelOverrides`, rename `imageMaxBytes` to `imageTargetBytes`. Keep the value at or below 32 MiB. The retired field is rejected with migration guidance.
3. Consumers of `ImageRequestTarget` replace `maxBytes` with `maxImageBytes` and supply `imageTargetBytes` no greater than it. Read the final width and height from `readImageRequest`, including for coordinate mapping. Direct `readRequestImageFile` and `requestImageVariantId` callers must pass resolved resize controls; DeepSeek helper consumers use `resolveRequestImageTargetBytes` and `DEFAULT_REQUEST_IMAGE_TARGET_BYTES`.
4. Attachment-local deployments may tune `requestImageMinShrinkFactor` (default 1.1, greater than one) and `requestImageByteHeadroom` (default 0.95, in `(0, 1]`). Verify actual encoded bytes stay within the hard limit and coordinate mappings match the returned dimensions.
@@ -10,13 +10,13 @@ description: "请求图片在编码后执行字节硬上限,DeepSeek 的软目
模型请求图片区分编码字节硬上限 `maxImageBytes` 和软目标 `imageTargetBytes`。编码器保留 85/75/60 质量阶梯,只有最小结果仍超过硬上限时才继续缩小尺寸。每次缩放都从已保存的源图开始。连 1×1 图片也无法满足上限时,以 `IMAGE_REQUEST_TOO_LARGE` 失败,不返回超限字节。存储附件保持不变,请求缓存使用新的变换版本重新生成。
pi 只暴露硬上限。`maxImageBytes` 替代 `requestImageMaxBytes`,用于覆盖所选模型的单图字节上限。`requestImageBudgetCount` 默认为 20。最终硬上限取该单图上限与 `3 × floor(maxRequestImageBytes / (4 × requestImageBudgetCount))` 的较小值,内部软目标等于硬上限。默认每张图分得 0.75 MiB。宽高跟随目录限制,或由 `requestImageMaxDimension` 用同一个值覆盖;不支持分别配置不同的本地宽高上限。
pi 只暴露硬上限。继续使用 `requestImageMaxBytes`,它现在限制编码后每张图的字节数。`requestImageBudgetCount` 默认为 20。最终硬上限取该单图上限与 `3 × floor(maxRequestImageBytes / (4 × requestImageBudgetCount))` 的较小值,内部软目标等于硬上限。默认每张图分得 0.75 MiB。宽高跟随目录限制,或由 `requestImageMaxDimension` 用同一个值覆盖;不支持分别配置不同的本地宽高上限。
DeepSeek 将可配置软目标 `imageMaxBytes` 重命名为 `imageTargetBytes`,默认仍为 2 MiB,硬上限固定为 32 MiB。CUA 的固定截图配置 `screenshotTarget.maxBytes` 也改为硬上限。请求图片目标描述最大尺寸,实际输出可能更小。请求总量限制仍按实际编码载荷执行。
## 迁移
1. 在 pi 提供方配置中,将 `requestImageMaxBytes` 改为 `maxImageBytes`,并按硬上限语义检查取值。通过 `requestImageBudgetCount` 配置预算分摊张数,它独立于保留图片数量上限。base64 总预算须为每份预算至少提供 4 个字节。若希望每张分配 1 MiB,应使用足够的总预算及分摊张数,例如 32 MiB、20 份,再设置 `maxImageBytes: 1048576`。
1. 如果 pi 提供方配置已设置 `requestImageMaxBytes`,请检查现有取值。调低编码质量后仍超过该值的图片会继续缩小尺寸。通过 `requestImageBudgetCount` 配置预算分摊张数,它独立于保留图片数量上限。base64 总预算须为每份预算至少提供 4 个字节。若希望每张分配 1 MiB,应使用足够的总预算及分摊张数,例如 32 MiB、20 份,再设置 `requestImageMaxBytes: 1048576`。
2. 在 DeepSeek 的 `models` 和 `modelOverrides` 中,将 `imageMaxBytes` 改为 `imageTargetBytes`,值不得超过 32 MiB。旧字段会被拒绝,并提示迁移方式。
3. `ImageRequestTarget` 调用方将 `maxBytes` 改为 `maxImageBytes`,并提供不大于硬上限的 `imageTargetBytes`。包括坐标换算在内的调用方,都从 `readImageRequest` 获取最终宽高。直接调用 `readRequestImageFile` 和 `requestImageVariantId` 时须传入已解析的缩放参数;DeepSeek 辅助函数调用方改用 `resolveRequestImageTargetBytes` 和 `DEFAULT_REQUEST_IMAGE_TARGET_BYTES`。
4. 附件本地存储可配置 `requestImageMinShrinkFactor`,默认 1.1,必须大于 1;以及 `requestImageByteHeadroom`,默认 0.95,范围为 `(0, 1]`。检查实际编码字节满足硬上限,坐标映射与返回尺寸一致。
+2 -2
View File
@@ -21,8 +21,8 @@
en: f3b761c7c7ecb82f
zh: e10d999aa348ef86
/deepseek-ai-dsh-llm-pi-ai/use-this-package/configure-provider-routes:
en: 90a1571e9de28c7d
zh: 8a2d445ed31f1bd7
en: 5f2e3298066947a2
zh: 0166148523454073
/deepseek-ai-dsh-llm-pi-ai/use-this-package/sign-in-to-a-provider:
en: c36f66438638ae08
zh: 066a2fc4cb97c86f
+3 -3
View File
@@ -47,7 +47,7 @@ Each profile may set a `retryPolicy`; omission uses normal mode with five retrie
reasoning: high
requestImagePixelBudget: 4194304 # total pixels; 2048 by 2048 default
requestImageMaxDimension: 3000 # override catalog width and height limits
maxImageBytes: 1048576 # hard per-image cap before allocation
requestImageMaxBytes: 1048576 # hard per-image cap before allocation
requestImageBudgetCount: 20 # fixed number of equal budget shares
maxRequestImageBytes: 20971520 # accumulated base64 payload
maxRequestImages: 50 # retained image occurrences
@@ -89,14 +89,14 @@ Each profile may set a `retryPolicy`; omission uses normal mode with five retrie
| `defaultMaxTokens` | `128,000` | Output-cap fallback for undescribed models |
| `requestImagePixelBudget` | `4,194,304` | Total-pixel budget for each deterministic request image |
| `requestImageMaxDimension` | catalog width/height limits | Maximum width and height for each request image; an explicit value overrides both catalog limits |
| `maxImageBytes` | catalog base64 cap converted to raw bytes; otherwise `1 MiB` | Hard per-image cap before allocation; an explicit value overrides the catalog cap |
| `requestImageMaxBytes` | catalog base64 cap converted to raw bytes; otherwise `1 MiB` | Hard per-image cap before allocation; an explicit value overrides the catalog cap |
| `requestImageBudgetCount` | `20` | Fixed divisor of the aggregate image budget; independent of retained image count |
| `maxRequestImageBytes` | `20 MiB` | Aggregate base64 image-payload bound; a request whose retained images exceed it fails with `IMAGE_OFFLOAD_REQUIRED` |
| `maxRequestImages` | `50` | Retained request-image count bound; a request whose retained images exceed it fails with `IMAGE_OFFLOAD_REQUIRED`. The default follows Azure OpenAI's 50-image limit; raise it on routes whose provider accepts more images |
| `imageOffloadCountQuantum` | `10`, capped at `maxRequestImages` | Oldest images offloaded per count overflow |
| `retryPolicy` | normal, 5 retries | Provider-owned retry policy executed by `dsh-llm-retry` |
Request images inherit the selected pi-ai model's `inputLimits.images.resize` width, height, and base64-byte cap. `requestImageMaxDimension` overrides both dimensions with one value; it cannot express unequal width and height overrides. `maxImageBytes` overrides the per-image cap in raw encoded bytes. The effective hard limit is `min(3 × floor(maxRequestImageBytes / (4 × requestImageBudgetCount)), maxImageBytes or catalog cap or 1 MiB)`, with the catalog cap converted using `3 × floor(catalogBytes / 4)`. Configuration must allow at least four aggregate base64 bytes per budget share. Defaults allocate 0.75 MiB per image, so 20 images at that limit use at most 20 MiB of base64 payload. Budget shares stay fixed as history grows; `maxRequestImages` separately controls retained occurrences. Missing catalog dimensions leave that axis uncapped, while total pixels remain governed by `requestImagePixelBudget`.
Request images inherit the selected pi-ai model's `inputLimits.images.resize` width, height, and base64-byte cap. `requestImageMaxDimension` overrides both dimensions with one value; it cannot express unequal width and height overrides. `requestImageMaxBytes` overrides the per-image cap in raw encoded bytes. The effective hard limit is `min(3 × floor(maxRequestImageBytes / (4 × requestImageBudgetCount)), requestImageMaxBytes or catalog cap or 1 MiB)`, with the catalog cap converted using `3 × floor(catalogBytes / 4)`. Configuration must allow at least four aggregate base64 bytes per budget share. Defaults allocate 0.75 MiB per image, so 20 images at that limit use at most 20 MiB of base64 payload. Budget shares stay fixed as history grows; `maxRequestImages` separately controls retained occurrences. Missing catalog dimensions leave that axis uncapped, while total pixels remain governed by `requestImagePixelBudget`.
pi exposes no separate soft-byte target: the shared encoder's `imageTargetBytes` equals its effective `maxImageBytes`. After the quality ladder, images that still exceed the limit are resized and re-encoded until they fit; an impossible limit fails explicitly. Stored attachments stay unchanged. Image descriptors and screenshot coordinates use the final encoded dimensions. Increase `requestImageBudgetCount` for smaller per-image allocations, or decrease it for larger ones; the aggregate cap still applies to actual payloads.
+3 -3
View File
@@ -47,7 +47,7 @@ kind: "package-reference"
reasoning: high
requestImagePixelBudget: 4194304 # total pixels; 2048 by 2048 default
requestImageMaxDimension: 3000 # override catalog width and height limits
maxImageBytes: 1048576 # hard per-image cap before allocation
requestImageMaxBytes: 1048576 # hard per-image cap before allocation
requestImageBudgetCount: 20 # fixed number of equal budget shares
maxRequestImageBytes: 20971520 # accumulated base64 payload
maxRequestImages: 50 # retained image occurrences
@@ -89,14 +89,14 @@ kind: "package-reference"
| `defaultMaxTokens` | `128,000` | 未描述模型的输出上限回退 |
| `requestImagePixelBudget` | `4,194,304` | 每张确定性请求图片的总像素预算 |
| `requestImageMaxDimension` | 目录中的宽高限制 | 每张请求图片的最大宽度和高度;显式配置会覆盖目录中的两个限制 |
| `maxImageBytes` | 目录的 base64 上限换算为原始字节;否则为 `1 MiB` | 分摊前的单图硬上限;显式配置会覆盖目录上限 |
| `requestImageMaxBytes` | 目录的 base64 上限换算为原始字节;否则为 `1 MiB` | 分摊前的单图硬上限;显式配置会覆盖目录上限 |
| `requestImageBudgetCount` | `20` | 图片总预算的固定分摊张数,与当前保留图片数量无关 |
| `maxRequestImageBytes` | `20 MiB` | base64 图片载荷总上限,保留图片超过时请求以 `IMAGE_OFFLOAD_REQUIRED` 失败 |
| `maxRequestImages` | `50` | 保留请求图片数量上限,保留图片超过时请求以 `IMAGE_OFFLOAD_REQUIRED` 失败。默认值取 Azure OpenAI 的 50 张上限;提供方接受更多图片的路由应调高 |
| `imageOffloadCountQuantum` | `10`,不超过 `maxRequestImages` | 每次数量超限时省略的最老图片数 |
| `retryPolicy` | normal,5 次重试 | 由 `dsh-llm-retry` 执行的提供方自有重试策略 |
请求图片继承所选 pi-ai 模型的 `inputLimits.images.resize` 宽度、高度和 base64 字节上限。`requestImageMaxDimension` 用同一个值覆盖宽高,不能分别配置不同的宽度和高度上限。`maxImageBytes` 按原始编码字节覆盖单图上限。最终硬上限为 `min(3 × floor(maxRequestImageBytes / (4 × requestImageBudgetCount)), maxImageBytes 或目录上限或 1 MiB)`,其中目录上限通过 `3 × floor(catalogBytes / 4)` 换算。总预算须为每份预算至少提供 4 个 base64 字节。默认每张图分得 0.75 MiB,20 张达到该上限的图片最多占用 20 MiB base64 载荷。历史增长不会改变分摊张数;`maxRequestImages` 单独控制保留图片数量。目录缺少某个尺寸时,路由不限制该轴,总像素仍由 `requestImagePixelBudget` 控制。
请求图片继承所选 pi-ai 模型的 `inputLimits.images.resize` 宽度、高度和 base64 字节上限。`requestImageMaxDimension` 用同一个值覆盖宽高,不能分别配置不同的宽度和高度上限。`requestImageMaxBytes` 按原始编码字节覆盖单图上限。最终硬上限为 `min(3 × floor(maxRequestImageBytes / (4 × requestImageBudgetCount)), requestImageMaxBytes 或目录上限或 1 MiB)`,其中目录上限通过 `3 × floor(catalogBytes / 4)` 换算。总预算须为每份预算至少提供 4 个 base64 字节。默认每张图分得 0.75 MiB,20 张达到该上限的图片最多占用 20 MiB base64 载荷。历史增长不会改变分摊张数;`maxRequestImages` 单独控制保留图片数量。目录缺少某个尺寸时,路由不限制该轴,总像素仍由 `requestImagePixelBudget` 控制。
pi 不暴露单独的软字节目标,共享编码器的 `imageTargetBytes` 等于最终 `maxImageBytes`。质量阶梯结束后仍超限的图片会继续缩小尺寸并重新编码,直到满足上限;无法满足的极小上限会明确报错。存储附件保持不变。图片描述和截图坐标使用最终编码尺寸。调大 `requestImageBudgetCount` 会减小每张图的分配额度,调小则增加额度;总预算仍按实际载荷执行。
+11 -8
View File
@@ -206,14 +206,14 @@ export interface PiAiProviderProfile {
* The effective cap is the smaller of this value and the route's equal share of maxRequestImageBytes.
* Omission uses the catalog budget converted to raw bytes, or 1 MiB without catalog metadata.
*/
maxImageBytes?: number
requestImageMaxBytes?: number
/** Provider-owned model-request retry policy; omission uses normal mode with five retries. */
retryPolicy?: RetryPolicyConfig
}
/** Validated profile with its route stamped and every adapter-owned default resolved. */
export interface ResolvedPiAiProviderProfile
extends Omit<PiAiProviderProfile, 'apiKeyEnv' | 'retryPolicy' | 'models' | 'displayName'> {
extends Omit<PiAiProviderProfile, 'apiKeyEnv' | 'retryPolicy' | 'models' | 'displayName' | 'requestImageMaxBytes'> {
/** Harness route key and the `Models` collection key (the configuration dict key). */
provider: string
/** Resolved display name for selectors and configuration surfaces. */
@@ -232,6 +232,8 @@ export interface ResolvedPiAiProviderProfile
requestImageBudgetCount: number
/** Positive total-pixel request-version budget after defaulting. */
requestImagePixelBudget: number
/** Configured hard per-image cap in raw encoded bytes, before the request budget is shared. */
maxImageBytes?: number
/** Immutable retry policy captured with this provider route. */
retryPolicy: ResolvedRetryPolicy
/**
@@ -381,7 +383,7 @@ const profile = z.object({
requestImageBudgetCount: z.number().step(1).min(1).max(Number.MAX_SAFE_INTEGER).default(DEFAULT_REQUEST_IMAGE_BUDGET_COUNT),
requestImagePixelBudget: z.number().step(1).min(1).default(DEFAULT_REQUEST_IMAGE_PIXEL_BUDGET),
requestImageMaxDimension: z.number().step(1).min(1).max(Number.MAX_SAFE_INTEGER),
maxImageBytes: z.number().step(1).min(1).max(Number.MAX_SAFE_INTEGER),
requestImageMaxBytes: z.number().step(1).min(1).max(Number.MAX_SAFE_INTEGER),
retryPolicy: RetryPolicySchema,
})
@@ -456,10 +458,10 @@ export function resolveProfiles(
for (const [provider, source] of entries) {
rejectRemovedFields(provider, source)
if ('imageTargetBytes' in source) {
throw new Error('llm-pi-ai: imageTargetBytes is not configurable; pi uses its effective maxImageBytes as the target')
throw new Error('llm-pi-ai: imageTargetBytes is not configurable; pi uses the effective per-image cap as the target')
}
if ('requestImageMaxBytes' in source) {
throw new Error('llm-pi-ai: replace requestImageMaxBytes with maxImageBytes; the new value is a hard per-image cap')
if ('maxImageBytes' in source) {
throw new Error(`llm-pi-ai: provider "${provider}" must use requestImageMaxBytes to set the per-image cap; maxImageBytes is internal`)
}
if (provider.length === 0) throw new Error('llm-pi-ai: provider names must be non-empty')
if (source.baseURL !== undefined && source.baseURL.length === 0) {
@@ -500,7 +502,7 @@ export function resolveProfiles(
if (!Number.isSafeInteger(requestImagePixelBudget) || requestImagePixelBudget <= 0) {
throw new Error(`llm-pi-ai: provider "${provider}" requestImagePixelBudget must be a positive safe integer`)
}
for (const field of ['requestImageMaxDimension', 'maxImageBytes'] as const) {
for (const field of ['requestImageMaxDimension', 'requestImageMaxBytes'] as const) {
const value = source[field]
if (value !== undefined && (!Number.isSafeInteger(value) || value <= 0)) {
throw new Error(`llm-pi-ai: provider "${provider}" ${field} must be a positive safe integer`)
@@ -547,9 +549,10 @@ export function resolveProfiles(
if (validation === 'strict' || !(error instanceof PiAiCatalogError)) throw error
catalogError ??= error.message
}
const { apiKeyEnv, retryPolicy, models: _models, displayName: _displayName, ...rest } = source
const { apiKeyEnv, retryPolicy, models: _models, displayName: _displayName, requestImageMaxBytes, ...rest } = source
resolved.set(provider, {
...rest,
...requestImageMaxBytes === undefined ? {} : { maxImageBytes: requestImageMaxBytes },
provider,
displayName,
...apiKeyEnv === undefined ? {} : { apiKeyEnv: credentialRef(apiKeyEnv) },
+3 -3
View File
@@ -1255,7 +1255,7 @@ it.each([
})
it('resolves the exact pi-ai image budget for screenshot coordinates', () => {
const adapter = adapterOf({ deepseek: { apiKeyEnv: 'PI_TEST_KEY', requestImagePixelBudget: 10_000, maxImageBytes: 50_000 } })
const adapter = adapterOf({ deepseek: { apiKeyEnv: 'PI_TEST_KEY', requestImagePixelBudget: 10_000, requestImageMaxBytes: 50_000 } })
expect(adapter.imageRequestTarget('deepseek', 'deepseek-flash', { ...IMAGE_REF, width: 1000, height: 1000 }))
.toEqual({ width: 100, height: 100, maxImageBytes: 50_000, imageTargetBytes: 50_000 })
expect(() => adapter.imageRequestTarget('missing', 'deepseek-flash', IMAGE_REF)).toThrow('does not own provider')
@@ -1265,7 +1265,7 @@ it('resolves the exact pi-ai image budget for screenshot coordinates', () => {
it.each([
[{}, { width: 627, height: 2000, maxImageBytes: 786_432, imageTargetBytes: 786_432 }],
[{
requestImageMaxDimension: 3000, maxImageBytes: 500_000,
requestImageMaxDimension: 3000, requestImageMaxBytes: 500_000,
}, {
width: 940, height: 3000, maxImageBytes: 500_000, imageTargetBytes: 500_000,
}],
@@ -1290,7 +1290,7 @@ it.each([
const ref = { ...IMAGE_REF, width: 1146, height: 3657 }
expect(adapter.imageRequestTarget('anthropic', 'claude-sonnet-4-5', ref)).toEqual(expected)
const prepared = await adapter.prepareCall('anthropic', 'claude-sonnet-4-5')
providers = { anthropic: { ...providers['anthropic'], requestImageMaxDimension: 777, maxImageBytes: 333 } }
providers = { anthropic: { ...providers['anthropic'], requestImageMaxDimension: 777, requestImageMaxBytes: 333 } }
expect(adapter.imageRequestTarget('anthropic', 'claude-sonnet-4-5', ref)).toMatchObject({
height: 777, maxImageBytes: 333, imageTargetBytes: 333,
})
+10 -8
View File
@@ -92,13 +92,13 @@ describe('request image policy bounds', () => {
expect(profile.requestImageMaxDimension).toBeUndefined()
expect(profile.maxImageBytes).toBeUndefined()
expect(profile.requestImageBudgetCount).toBe(20)
const explicit = routeWith({ requestImageMaxDimension: 3000, maxImageBytes: 2000000 })() as Options
const explicit = routeWith({ requestImageMaxDimension: 3000, requestImageMaxBytes: 2000000 })() as Options
expect(resolveProfiles(explicit.providers).get('acme-gateway')).toMatchObject({
requestImageMaxDimension: 3000, maxImageBytes: 2000000,
})
})
it.each(['requestImageMaxDimension', 'maxImageBytes', 'requestImageBudgetCount'])(
it.each(['requestImageMaxDimension', 'requestImageMaxBytes', 'requestImageBudgetCount'])(
'rejects invalid %s at the configuration parser', (field) => {
for (const value of [0, -1, 1.5, Infinity, Number.MAX_SAFE_INTEGER + 1]) {
expect(routeWith({ [field]: value })).toThrow()
@@ -114,8 +114,8 @@ describe('request image policy bounds', () => {
['requestImageMaxDimension', 0, /requestImageMaxDimension must be a positive safe integer/],
['requestImageMaxDimension', 1.5, /requestImageMaxDimension must be a positive safe integer/],
['requestImageMaxDimension', Number.MAX_SAFE_INTEGER + 1, /requestImageMaxDimension must be a positive safe integer/],
['maxImageBytes', 0, /maxImageBytes must be a positive safe integer/],
['maxImageBytes', 1.5, /maxImageBytes must be a positive safe integer/],
['requestImageMaxBytes', 0, /requestImageMaxBytes must be a positive safe integer/],
['requestImageMaxBytes', 1.5, /requestImageMaxBytes must be a positive safe integer/],
] as const)('rejects %s=%s at service resolution', (field, value, message) => {
const programmatic = {
providers: {
@@ -143,10 +143,12 @@ it('rejects an aggregate budget without room for one base64 group per allocated
.toThrow(/maxRequestImageBytes/)
})
it('rejects the retired soft-byte configuration key instead of ignoring it', () => {
expect(() => { assertServiceable(routeWith({ requestImageMaxBytes: 1024 })() as Options) })
.toThrow(/replace requestImageMaxBytes with maxImageBytes/)
})
it.each([{ maxImageBytes: 1024 }, { requestImageMaxBytes: 1024, maxImageBytes: 1024 }])(
'rejects the internal byte-cap name in a provider profile: %j', (fields) => {
expect(() => { assertServiceable(routeWith(fields)() as Options) })
.toThrow(/provider "acme-gateway" must use requestImageMaxBytes.*maxImageBytes is internal/)
},
)
it('refuses a separate pi soft target at the configuration boundary', () => {
@@ -7,7 +7,7 @@
api: anthropic-messages
baseURL: https://image-override.invalid
requestImageMaxDimension: 3000
maxImageBytes: 4096
requestImageMaxBytes: 4096
models:
- id: vision
input: [text, image]