Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
fix(models): let a saved row's output cap follow the published record
vastsa6c6235c84a34
diff --git a/apps/desktop/electron/main/ipc/provider-ipc.ts b/apps/desktop/electron/main/ipc/provider-ipc.tsindex 2ab8f5cef..6a7db8480 100644--- a/apps/desktop/electron/main/ipc/provider-ipc.ts+++ b/apps/desktop/electron/main/ipc/provider-ipc.ts@@ -3,7 +3,7 @@ import {ErrorCodes,inferEndpointProfile,normalizeApiStyle,- resolveBindingContextWindow,+ resolveBindingLimits,type ModelBinding,type ProviderReorderInput,type OAuthRespondInput,@@ -404,7 +404,7 @@ export function registerProviderIpc({modelId: model.modelId,});const storedModel = provider ? bindingForModel(provider, model.modelId) : undefined;- const resolvedModel = resolveBindingContextWindow(catalogModelConfig, storedModel);+ const resolvedModel = resolveBindingLimits(catalogModelConfig, storedModel);const modelConfig = modelConfigWithBinding(resolvedModel.catalogConfig,resolvedModel.binding,diff --git a/apps/desktop/electron/main/runtime/provider-catalog.ts b/apps/desktop/electron/main/runtime/provider-catalog.tsindex 82cbda4cc..864c7d543 100644--- a/apps/desktop/electron/main/runtime/provider-catalog.ts+++ b/apps/desktop/electron/main/runtime/provider-catalog.ts@@ -3,7 +3,7 @@ import {SESSION_THINKING_LEVELS,defaultCommandShellForPlatform,isCommandShellId,- resolveBindingContextWindow,+ resolveBindingLimits,validateNetworkProxy,validateSpeechSettings,type CommandShellId,@@ -93,7 +93,7 @@ export function createProviderCatalogRuntime({modelId: string,catalogModelConfig: Parameters<typeof modelConfigWithBinding>[0],) => {- const resolved = resolveBindingContextWindow(+ const resolved = resolveBindingLimits(catalogModelConfig,bindingForModel(provider, modelId),);@@ -124,7 +124,7 @@ export function createProviderCatalogRuntime({apiStyle: provider.apiStyle,modelId,});- const resolved = resolveBindingContextWindow(+ const resolved = resolveBindingLimits(catalogModelConfig,storedModel,);@@ -139,7 +139,7 @@ export function createProviderCatalogRuntime({apiStyle: provider.apiStyle,modelId: binding.id,});- const bindingResolved = resolveBindingContextWindow(+ const bindingResolved = resolveBindingLimits(catalogModelConfig,binding,);@@ -336,7 +336,7 @@ export function createProviderCatalogRuntime({};}const { provider, modelId } = target;- const resolved = resolveBindingContextWindow(+ const resolved = resolveBindingLimits(catalogModelConfigFor(modelsDevCatalog, {vendorKey: provider.vendorKey,baseUrl: provider.baseUrl,diff --git a/apps/desktop/electron/main/runtime/session-launch.ts b/apps/desktop/electron/main/runtime/session-launch.tsindex afa2f6158..bf568708a 100644--- a/apps/desktop/electron/main/runtime/session-launch.ts+++ b/apps/desktop/electron/main/runtime/session-launch.ts@@ -6,7 +6,7 @@ import {imageGenerationBindings,isImageGenerationModel,normalizeMode,- resolveBindingContextWindow,+ resolveBindingLimits,trustedExtensionAgentKeyFromProviderId,type CommandShellCatalog,type McpServerRecord,@@ -355,7 +355,7 @@ export function createSessionLaunchRuntime({apiStyle,modelId,});- const resolvedLimits = resolveBindingContextWindow(catalogModelConfig, storedModel);+ const resolvedLimits = resolveBindingLimits(catalogModelConfig, storedModel);const modelConfig = modelConfigWithBinding(resolvedLimits.catalogConfig,resolvedLimits.binding,diff --git a/apps/desktop/test/provider-lookup-model-handler.test.mjs b/apps/desktop/test/provider-lookup-model-handler.test.mjsindex c74a21efb..42ef76d77 100644--- a/apps/desktop/test/provider-lookup-model-handler.test.mjs+++ b/apps/desktop/test/provider-lookup-model-handler.test.mjs@@ -88,7 +88,7 @@ function harness(realCatalog) {ErrorCodes,inferEndpointProfile: () => undefined,normalizeApiStyle: (value) => value ?? "chat_completions",- resolveBindingContextWindow: () => ({}),+ resolveBindingLimits: () => ({}),},"../oauth": { OAUTH_AUTH_KIND: "oauth" },"../model-discovery": {diff --git a/docs/spec/03-runtime/13-model-catalog-and-selection.md b/docs/spec/03-runtime/13-model-catalog-and-selection.mdindex 96746ac62..74f8f8256 100644--- a/docs/spec/03-runtime/13-model-catalog-and-selection.md+++ b/docs/spec/03-runtime/13-model-catalog-and-selection.md@@ -317,28 +317,31 @@ field records a models.dev match; a provider cache stores only normalizedselection fields and is re-decorated from the local raw catalog on the nextread.-### 9.1 Effective context window+### 9.1 Effective model limitsThe runtime, the context inspector and the settings surface resolve one effective-model window. Every binding records where its `contextWindow` came from-(`contextWindowSource`):+model window and output cap. Every binding records where its `contextWindow` came+from (`contextWindowSource`), and the same marker governs `maxTokens`:- `catalog` — the number is a models.dev snapshot, so a later correction to the- published `limit.context` replaces it. A refreshed record such as- `gpt-5.6-luna` (`1,050,000` tokens) stops appearing as a 128k model, and a limit- that models.dev corrects reaches the binding without deleting and re-adding the- model. Only a resolved models.dev record counts as published: when the lookup- misses and falls back to the generic shape (for example a custom gateway URL- serving an id several publishers list), its `128,000` is not a correction, and- the stored catalog snapshot stays in force.+ published `limit.context` or `limit.output` replaces it. A refreshed record+ such as `gpt-5.6-luna` (`1,050,000` tokens) stops appearing as a 128k model, a+ row added while nothing published its id stops reporting the generic 8.2k+ output once the record resolves, and a limit that models.dev corrects reaches+ the binding without deleting and re-adding the model. Only a resolved+ models.dev record counts as published: when the lookup misses and falls back to+ the generic shape (for example a custom gateway URL serving an id several+ publishers list), its `128,000` and `8,192` are not a correction, and the+ stored catalog snapshot stays in force.- `user` — the number was entered through the per-model Advanced control (or thepreset ladder in it) and is never replaced by the catalog, including the- `128,000` value that is otherwise the generic seed.+ `128,000` and `8,192` values that are otherwise the generic seed.Bindings written before the marker name no source. They keep the historical rule,deterministically: a published `limit.context` replaces exactly the generic-`128,000` seed, and every other stored value stays the explicit value. Unknown-models still use the conservative 128k generic window and are never promoted from+`128,000` seed and a published `limit.output` replaces exactly the generic+`8,192`, and every other stored value stays the explicit value. Unknown models+still use the conservative 128k / 8.2k generic limits and are never promoted froman ID pattern alone. The marker is optional in the persisted record, so a configwritten by an older version stays readable and a downgrade ignores it.diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.mdindex 3186bd901..f19f5ad1f 100644--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@ -14566,9 +14566,9 @@ plugin-form fixtures in an isolated temporary directory at runtime.#### E2E-MODEL-catalog-window-correction-reaches-saved-bindings-- **Goal**: a models.dev limit correction reaches an already saved binding without- deleting and re-adding the model, while a number the user entered in Settings is- never overwritten.+- **Goal**: a models.dev limit correction — the context window or the output cap —+ reaches an already saved binding without deleting and re-adding the model, while+ a number the user entered in Settings is never overwritten.- **Steps**:1. Configure a provider, select a model models.dev publishes a `limit.context`for, and save. Open the row's Advanced body and read the context-window field@@ -14582,6 +14582,9 @@ plugin-form fixtures in an isolated temporary directory at runtime.4. Save and reopen a provider row whose binding carries no`contextWindowSource`: once with the generic `128000` seed, once with anyother stored value.+ 5. Repeat step 4 with a row whose stored output cap is the generic `8192`, and+ one whose cap the user typed, and read the cap in the settings row and in the+ request a new session launches with.- **Expected**: Step 1 shows the published number with the "follows models.dev"hint. Step 2 shows the corrected number everywhere the effective window is used(settings row, context inspector, session launch) with no delete and re-add.@@ -14589,8 +14592,10 @@ plugin-form fixtures in an isolated temporary directory at runtime.the launched request, including a hand-typed `128000` for a model whosepublished window is larger, and the hint is gone. Step 4 resolvesdeterministically: the `128000` seed follows the catalog, every other value- stays as stored. Every step keeps the marker across the save/read round trip of- the provider row, and a config written before the marker stays readable.+ stays as stored. Step 5 applies the same provenance rule to the output cap: an+ `8192` seed follows the published `limit.output`, and a cap the user entered is+ kept. Every step keeps the marker across the save/read round trip of the+ provider row, and a config written before the marker stays readable.- **Specs linked**: `03-runtime/13-model-catalog-and-selection.md` §9.1,`03-runtime/12-provider-config-schema.md` §2,`03-runtime/11-provider-model-system.md` §2, `04-ux/06-settings-ia.md` §2diff --git a/docs/zh-CN/spec/03-runtime/13-model-catalog-and-selection.md b/docs/zh-CN/spec/03-runtime/13-model-catalog-and-selection.mdindex dc1d3d63c..72be3ca60 100644--- a/docs/zh-CN/spec/03-runtime/13-model-catalog-and-selection.md+++ b/docs/zh-CN/spec/03-runtime/13-model-catalog-and-selection.md@@ -211,7 +211,32 @@ type ModelCatalogItem = {通过 `(providerId, modelId)` 优先进行重复数据删除:`user > discovered > bundled > recent-only`。-### 9.1 对话 Composer 范围+### 9.1 有效模型上限++运行时、上下文检查器与设置界面解析同一个有效窗口与输出上限。每个绑定记录它的+`contextWindow` 从何而来(`contextWindowSource`),该标记同样作用于 `maxTokens`:++- `catalog` —— 该数值是 models.dev 的取值,之后 `limit.context` 或 `limit.output`+ 的修正会替换它。刷新后的记录(例如 `gpt-5.6-luna`,1,050,000 tokens)不再显示为+ 128k 模型;在目录还没有该 ID 时加入的行,一旦记录解析出来就不再显示通用的 8.2k+ 输出上限;被 models.dev 修正的数值无需删除再重新添加即可到达该绑定。只有解析出来的+ models.dev 记录才算「已发布」:查询未命中而回退到通用形态时(例如自定义网关地址+ 提供的是一个多家发布方都在列的 ID),它的 `128,000` 与 `8,192` 不算修正,+ 已保存的目录快照继续生效。+- `user` —— 该数值来自单个模型「高级」里的输入(或其中的预设档位),目录永不替换它,+ 包括本来就是通用种子值的 `128,000` 与 `8,192`。++在该标记出现之前写入的绑定没有来源标记,它们沿用历史规则且行为确定:已发布的+`limit.context` 只替换通用的 `128,000`,已发布的 `limit.output` 只替换通用的+`8,192`,其余保存值都视为用户显式值。未知模型仍使用保守的 128k / 8.2k 通用上限,+绝不会仅凭 ID 形态被提升。该标记在持久化记录中是可选的,因此旧版本写入的配置仍可读,+降级也不会因此出错。++用户配置的值仍会持久化并显示在「高级」中,但提供商安全不会信任超过已知已发布窗口的+放大覆盖:出站输出上限、自动压缩与溢出判定取配置值与已发布值中较小的一方;+更小的用户值会继续收窄运行期预算。++### 9.2 对话 Composer 范围对话 Composer 是已配置模型选择器,而不是原始发现目录。对于每个已启用且可运行的提供商,它只渲染该提供商持久化 `models` 绑定中的模型 ID(或旧版diff --git a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.mdindex d99086b63..b3a1061ec 100644--- a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md@@ -8263,8 +8263,8 @@ runner 会在运行时的隔离临时目录中生成六个插件形态 fixture- **Status**: Draft; native E2E requires an explicitly authorized run.#### E2E-MODEL-catalog-window-correction-reaches-saved-bindings:目录修正回流已保存绑定,且不覆盖用户手改值-- **目标**:models.dev 修正某模型上限后回流到已保存的绑定(不必删除重建),- 而用户在设置里手改的数值永不被覆盖。+- **目标**:models.dev 修正某模型上限(上下文窗口或输出上限)后回流到已保存的绑定+ (不必删除重建),而用户在设置里手改的数值永不被覆盖。- **步骤**:1. 配置一个提供商,勾选 models.dev 已发布 `limit.context` 的模型并保存。展开该行的高级区,读取上下文窗口字段与其提示。@@ -8274,11 +8274,15 @@ runner 会在运行时的隔离临时目录中生成六个插件形态 fixture重新打开设置与检查器。4. 保存并重新打开一个绑定不带 `contextWindowSource` 的提供商行:一次使用通用`128000` 种子,一次使用任意其它已存值。+ 5. 对存的是通用 `8192` 输出上限的行、以及用户手改过上限的行重复步骤 4,+ 读取设置行里的上限与新会话实际请求里的上限。- **预期**:步骤 1 显示发布值并带「跟随 models.dev」提示。步骤 2 在所有使用 effectivewindow 的地方(设置行、上下文检查器、会话启动)都显示修正后的值,无需删除重建。步骤 3 在设置行、检查器和实际请求中都保留用户输入的值,包括在目录窗口更大时手输的`128000`,且提示消失。步骤 4 表现确定:`128000` 种子跟随目录,其它值保持原样。- 每一步中标记都能在提供商行的保存/读取往返后保留,早于该标记写出的配置仍可读。+ 步骤 5 对输出上限套用同一套来源规则:`8192` 种子跟随已发布的 `limit.output`,+ 用户输入的上限保持不变。每一步中标记都能在提供商行的保存/读取往返后保留,+ 早于该标记写出的配置仍可读。- **关联规范**:`03-runtime/13-model-catalog-and-selection.md` §9.1、`03-runtime/12-provider-config-schema.md` §2、`03-runtime/11-provider-model-system.md` §2、`04-ux/06-settings-ia.md` §2diff --git a/packages/host-runtime/src/launch-resolver.ts b/packages/host-runtime/src/launch-resolver.tsindex 6ede465f0..85177699c 100644--- a/packages/host-runtime/src/launch-resolver.ts+++ b/packages/host-runtime/src/launch-resolver.ts@@ -7,7 +7,7 @@ import {isActiveInProject,isCommandShellCatalog,normalizeMode,- resolveBindingContextWindow,+ resolveBindingLimits,trustedExtensionAgentKeyFromProviderId,type CommandShellCatalog,type ModelBinding,@@ -194,7 +194,7 @@ export function createHeadlessLaunchResolver(options: HeadlessLaunchResolverOptifunction effectiveModelConfig(provider: HostProviderRecord, modelId: string, baseUrl: string | undefined) {const storedModel = bindingForModel(provider, modelId);- const resolvedLimits = resolveBindingContextWindow(catalogModelConfig(provider, modelId, baseUrl), storedModel);+ const resolvedLimits = resolveBindingLimits(catalogModelConfig(provider, modelId, baseUrl), storedModel);const modelConfig = modelConfigWithBinding(resolvedLimits.catalogConfig, resolvedLimits.binding);return { modelConfig, capabilities: capabilitiesFromModelConfig(modelConfig), storedModel };}diff --git a/packages/shared/src/model-catalog.test.ts b/packages/shared/src/model-catalog.test.tsindex d384720c5..763e45d46 100644--- a/packages/shared/src/model-catalog.test.ts+++ b/packages/shared/src/model-catalog.test.ts@@ -5,8 +5,9 @@ import {bindingFromModelInfo,bindingSupportsDocuments,effectiveContextWindow,+ effectiveMaxTokens,bindingSupportsImages,- resolveBindingContextWindow,+ resolveBindingLimits,formatCompactTokenCount,formatTokenCount,modelMatchesFilter,@@ -48,6 +49,20 @@ describe("effective model context windows", () => {});});+describe("effective model output caps", () => {+ it("lets a published cap replace the legacy generic seed", () => {+ expect(effectiveMaxTokens(131_072, 8_192)).toBe(131_072);+ expect(effectiveMaxTokens(64_000, 8_192)).toBe(64_000);+ });++ it("preserves a non-default cap, a user's number and a catalog snapshot", () => {+ expect(effectiveMaxTokens(131_072, 32_000)).toBe(32_000);+ expect(effectiveMaxTokens(131_072, 8_192, "user")).toBe(8_192);+ expect(effectiveMaxTokens(131_072, 8_192, "catalog")).toBe(131_072);+ expect(effectiveMaxTokens(undefined, undefined)).toBeUndefined();+ });+});+describe("binding context-window provenance", () => {it("marks the catalog snapshot a fresh binding is seeded with", () => {const binding = bindingFromModelInfo({@@ -102,7 +117,7 @@ describe("binding context-window provenance", () => {// automatic compaction start at ~86k tokens.const binding = { contextWindow: 1_000_000, contextWindowSource: "catalog" as const };const generic = { source: "generic", contextWindow: 128_000 };- const resolved = resolveBindingContextWindow(generic, binding);+ const resolved = resolveBindingLimits(generic, binding);expect(resolved.catalogConfig.contextWindow).toBe(1_000_000);expect(resolved.binding.contextWindow).toBe(1_000_000);expect(resolved.binding.contextWindowSource).toBe("catalog");@@ -111,10 +126,34 @@ describe("binding context-window provenance", () => {it("still follows a published record for a catalog-sourced window", () => {const binding = { contextWindow: 1_000_000, contextWindowSource: "catalog" as const };const published = { source: "models.dev", contextWindow: 1_048_576 };- const resolved = resolveBindingContextWindow(published, binding);+ const resolved = resolveBindingLimits(published, binding);expect(resolved.catalogConfig.contextWindow).toBe(1_048_576);expect(resolved.binding.contextWindow).toBe(1_048_576);});++ it("resolves the output cap a row was seeded with before its record existed", () => {+ // The row was added with the generic 8.2k cap while nothing published the+ // id. Once models.dev describes it, the published cap takes over, so the+ // saved row stops reporting an 8.2k output for a 131k model.+ const binding = {+ contextWindow: 128_000,+ maxTokens: 8_192,+ contextWindowSource: "catalog" as const,+ };+ const published = { source: "models.dev", contextWindow: 1_048_576, maxTokens: 131_072 };+ const resolved = resolveBindingLimits(published, binding);+ expect(resolved.binding.contextWindow).toBe(1_048_576);+ expect(resolved.binding.maxTokens).toBe(131_072);+ expect(resolved.catalogConfig.maxTokens).toBe(131_072);+ });++ it("keeps the output cap and window the user set", () => {+ const binding = { contextWindow: 128_000, maxTokens: 4_096, contextWindowSource: "user" as const };+ const published = { source: "models.dev", contextWindow: 1_048_576, maxTokens: 131_072 };+ const resolved = resolveBindingLimits(published, binding);+ expect(resolved.binding.contextWindow).toBe(128_000);+ expect(resolved.binding.maxTokens).toBe(4_096);+ });});describe("provider API style compatibility", () => {diff --git a/packages/shared/src/model-catalog.ts b/packages/shared/src/model-catalog.tsindex 206df9563..cf051eea5 100644--- a/packages/shared/src/model-catalog.ts+++ b/packages/shared/src/model-catalog.ts@@ -168,6 +168,31 @@ export function effectiveContextWindow(return configured;}+/**+ * Resolve a model's effective output cap.+ *+ * The provenance rule the context window follows, applied to `limit.output`: a+ * `catalog` binding reads the published record, a `user` binding is the user's+ * own number and is never replaced, and a binding written before the marker+ * existed treats the generic 8.2k seed as inherited.+ */+export function effectiveMaxTokens(+ publishedMaxTokens?: number | null,+ configuredMaxTokens?: number | null,+ source?: ContextWindowSource | null,+): number | undefined {+ const published = positiveTokenCount(publishedMaxTokens);+ const configured = positiveTokenCount(configuredMaxTokens);++ if (source === "catalog") return published ?? configured;+ if (source === "user") return configured ?? published;+ if (configured === undefined) return published;+ if (published !== undefined && configured === CATALOG_DEFAULT_MAX_TOKENS) {+ return published;+ }+ return configured;+}+/** Token counts are whole positive numbers; anything else means "unset". */function positiveTokenCount(value?: number | null): number | undefined {if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {@@ -176,58 +201,76 @@ function positiveTokenCount(value?: number | null): number | undefined {return Math.round(value);}-/** Context-window fields the resolver reads and rewrites on a binding. */-type BindingContextWindow = Pick<ModelBinding, "contextWindow"> &- Partial<Pick<ModelBinding, "contextWindowSource">>;+/** Binding fields the limits resolver reads and rewrites. */+type BindingLimits = Pick<ModelBinding, "contextWindow"> &+ Partial<Pick<ModelBinding, "maxTokens" | "contextWindowSource">>;/**- * Resolve a saved binding against its catalog baseline for+ * Resolve a saved binding's limits against its catalog baseline for* `modelConfigWithBinding`.** That runtime helper applies the historical two-argument rule, which cannot- * tell a hand-edited 128k from the generic seed. Callers that know where a- * stored value came from resolve it first: the returned baseline and binding- * both carry the source-aware window, so the two-argument rule lands on the- * same answer. An exported binding keeps the catalog as its provenance whenever- * the catalog supplied the value, so a later settings save cannot freeze an- * inherited value into a snapshot of its own.+ * tell a hand-edited 128k from the generic seed, and it takes the binding's+ * output cap as written. Callers that know where a stored value came from+ * resolve both limits first: the returned baseline and binding carry the+ * source-aware window and cap, so a saved row reads and runs with the number the+ * catalog publishes once the model resolves — a row seeded before the record+ * existed stops showing the generic 8.2k output. An exported binding keeps the+ * catalog as its provenance whenever the catalog supplied the value, so a later+ * settings save cannot freeze an inherited value into a snapshot of its own.** A `generic` baseline is the fallback for a lookup that found no record, not- * a published limit, so it never replaces a saved window: a catalog snapshot+ * a published limit, so it never replaces a saved limit: a catalog snapshot* taken while the record still resolved stays in force.*/-export function resolveBindingContextWindow<- C extends { contextWindow?: number | null; source?: string },- B extends BindingContextWindow,+export function resolveBindingLimits<+ C extends { contextWindow?: number | null; maxTokens?: number | null; source?: string },+ B extends BindingLimits,>(catalogConfig: C, binding: B): { catalogConfig: C; binding: B };-export function resolveBindingContextWindow<- C extends { contextWindow?: number | null; source?: string },- B extends BindingContextWindow,+export function resolveBindingLimits<+ C extends { contextWindow?: number | null; maxTokens?: number | null; source?: string },+ B extends BindingLimits,>(catalogConfig: C,binding: B | null | undefined,): { catalogConfig: C; binding: B | null | undefined };-export function resolveBindingContextWindow(- catalogConfig: { contextWindow?: number | null; source?: string },- binding: BindingContextWindow | null | undefined,+export function resolveBindingLimits(+ catalogConfig: { contextWindow?: number | null; maxTokens?: number | null; source?: string },+ binding: BindingLimits | null | undefined,): {- catalogConfig: { contextWindow?: number | null; source?: string };- binding: BindingContextWindow | null | undefined;+ catalogConfig: { contextWindow?: number | null; maxTokens?: number | null; source?: string };+ binding: BindingLimits | null | undefined;} {if (!binding) return { catalogConfig, binding };- const published = catalogConfig.source === "generic"- ? undefined- : positiveTokenCount(catalogConfig.contextWindow);+ const publishedRecord = catalogConfig.source !== "generic";+ const published = publishedRecord+ ? positiveTokenCount(catalogConfig.contextWindow)+ : undefined;+ const publishedMax = publishedRecord+ ? positiveTokenCount(catalogConfig.maxTokens)+ : undefined;const source = binding.contextWindowSource ?? undefined;const resolved = effectiveContextWindow(published, binding.contextWindow, source);- if (resolved === undefined) return { catalogConfig, binding };+ const resolvedMax = effectiveMaxTokens(publishedMax, binding.maxTokens, source);+ if (resolved === undefined && resolvedMax === undefined) {+ return { catalogConfig, binding };+ }const inherited = source !== "user" && published !== undefined;return {- catalogConfig: { ...catalogConfig, contextWindow: resolved },+ catalogConfig: {+ ...catalogConfig,+ ...(resolved !== undefined ? { contextWindow: resolved } : {}),+ ...(resolvedMax !== undefined ? { maxTokens: resolvedMax } : {}),+ },binding: {...binding,- contextWindow: resolved,- ...(inherited ? { contextWindowSource: "catalog" as const } : {}),+ ...(resolved !== undefined+ ? {+ contextWindow: resolved,+ ...(inherited ? { contextWindowSource: "catalog" as const } : {}),+ }+ : {}),+ ...(resolvedMax !== undefined ? { maxTokens: resolvedMax } : {}),},};}