Skip to content

Open-source AI browser agent for Chrome and Firefox (monorepo) 🧠

Set the Local OpenAI-compatible Proxy's context window automatically

Claude98d2893e113e
diff --git a/docs/fr/providers-and-models.md b/docs/fr/providers-and-models.md
index 41fde5c77..6144da9a5 100644
--- a/docs/fr/providers-and-models.md
+++ b/docs/fr/providers-and-models.md
@@ -149,7 +149,13 @@ carte proxy générique exige une clé client :
- **LocalAI** : `http://localhost:8080/v1` — le serveur compatible OpenAI de LocalAI
- **GPT4All** : `http://localhost:4891/v1` — le serveur API local de GPT4All
- **Proxy local compatible OpenAI** : `http://127.0.0.1:8317/v1` — passerelle
- locale générique authentifiée ; le modèle et la clé API client sont requis
+ locale générique authentifiée ; le modèle et la clé API client sont requis.
+ Après « Charger les modèles », le choix d'un modèle ou « Tester la connexion »,
+ la fenêtre de contexte est réglée automatiquement : carte du modèle choisi dans
+ `/v1/models` du proxy, puis `n_ctx` live d'un serveur llama.cpp derrière lui
+ (`GET /props?model=`), puis le nom d'un modèle hébergé connu (128k au plus),
+ sinon la valeur par défaut du proxy, **64k** (16k auparavant). Un nom ou la
+ valeur par défaut ne remplace qu'une valeur par défaut, jamais un nombre saisi
#### Exemple de proxy d'abonnement (CLIProxyAPI)
diff --git a/docs/providers-and-models.md b/docs/providers-and-models.md
index 53aff6cbf..8fc2388cb 100644
--- a/docs/providers-and-models.md
+++ b/docs/providers-and-models.md
@@ -555,7 +555,9 @@ proxy card require their configured client keys:
- **LocalAI**: `http://localhost:8080/v1` — LocalAI's OpenAI-compatible server
- **GPT4All**: `http://localhost:4891/v1` — GPT4All's local API server
- **Local OpenAI-compatible Proxy**: `http://127.0.0.1:8317/v1` — a generic,
- authenticated local gateway; the model and proxy client API key are required
+ authenticated local gateway; the model and proxy client API key are required.
+ Its context window is set automatically after **Load Models**, a model pick or
+ **Test Connection**, and falls back to 64k (see below)
- **Unsloth Studio**: `http://127.0.0.1:8888/v1` by default, with a configurable
port — Studio's API URL, loaded model, and generated API key are required
@@ -621,6 +623,28 @@ Keep the listener on `127.0.0.1`, require a strong random client key, and never
publish the endpoint to a LAN or the internet. Official provider API keys remain
the stable default.
+**Context window.** After **Load Models**, picking a model from the loaded list,
+or **Test Connection**, WebBrain sets the card's **Context window** from the first
+source that knows it:
+
+1. the proxy's `/v1/models` card for the selected model (`max_model_len`,
+ `max_context_length`, `context_window`, `context_length`, `max_input_tokens`
+ or `input_token_limit`);
+2. `GET /props?model=<model>` at the proxy root, when a llama.cpp server behind it
+ reports the loaded model's live `n_ctx`;
+3. the model name, for hosted models WebBrain knows (`claude-…`, `gpt-5…`,
+ `gemini-…`, …), capped at 128k because subscription gateways can serve less
+ context than the vendor API advertises;
+4. otherwise the **64k** proxy fallback, which is also the card's default
+ (previously 16k, which starved the hosted models these gateways usually front).
+
+A reported window (1 or 2) may shrink a manual value; a name or the fallback only
+replaces the default, the old 16k default, or a value WebBrain filled in itself,
+never a number you typed. If the proxy fronts a small local model and reports
+nothing, lower **Context window** to that model's loaded window, because 64k can
+overflow it. Untouched cards (never saved, no key) move from 16k to 64k on
+upgrade; a saved card still at 16k moves at its next detection.
+
Ollama, llama.cpp, ODS, LM Studio, and LocalAI default to `visionMode: auto`. WebBrain asks
the selected server for model capability metadata before enrichment and sends
screenshots only when the response explicitly reports image input. A failed or
@@ -668,7 +692,7 @@ template/parser, and a current runtime version (LocalAI added tool streaming in
**Context window.** Size the loaded context for the selected prompt tier, its tool schemas, the live page/history and the requested output. **16k is a local configuration fallback, not a reliable minimum for every tier.** Current Mid and Full agent prompts can exceed that window before useful history accumulates. Use a larger loaded window for these tiers; the quality audit verified a Full-tier 64K run with real compaction and restarts. A smaller Compact setup needs its own sizing check and offers fewer tools, including no native long-chat tool set. Automatically summarizing old history cannot shrink the fixed prompt or schemas, and the character-based estimate is not an exact model tokenizer.
-The agent reads `provider.contextWindow` (`providers/base.js`) to drive auto-compaction. When no value is configured, local providers default to **16k**; cloud/router defaults depend on the known model, with a category fallback of 128k. **Test connection** / **Load models** auto-detect for **llama.cpp**, **ODS**, **Ollama**, and **LM Studio** when reported (llama.cpp / ODS `GET /props` `n_ctx`, Ollama `GET /api/ps` live context then `/api/show` `num_ctx`, LM Studio `/api/v0/models` `loaded_context_length`). Detection refreshes the local fallback; it shrinks a larger manual override only from live/runtime context (not from Ollama `/api/show` alone). Jan / vLLM / SGLang / LocalAI / Unsloth Studio do not auto-detect yet. Set `config.contextWindow` to match the server's actual loaded window; increasing the setting alone does not enlarge the model server's context.
+The agent reads `provider.contextWindow` (`providers/base.js`) to drive auto-compaction. When no value is configured, local providers default to **16k** (the Local OpenAI-compatible Proxy to **64k**); cloud/router defaults depend on the known model, with a category fallback of 128k. **Test connection** / **Load models** auto-detect for **llama.cpp**, **ODS**, **Ollama**, **LM Studio**, **vLLM**, **SGLang**, **LocalAI** and the **Local OpenAI-compatible Proxy** when reported (llama.cpp / ODS `GET /props` `n_ctx`, Ollama `GET /api/ps` live context then `/api/show` `num_ctx`, LM Studio `/api/v0/models` `loaded_context_length`, vLLM / SGLang `/v1/models` `max_model_len`, LocalAI model config `context_size`, the proxy as described in the [subscription proxy guide](#subscription-proxy-guide-easycliproxyapi--cliproxyapi)). Detection refreshes the local fallback; it shrinks a larger manual override only from live/runtime context (not from Ollama `/api/show` alone). Jan / GPT4All / Unsloth Studio do not auto-detect yet. Set `config.contextWindow` to match the server's actual loaded window; increasing the setting alone does not enlarge the model server's context.
### Prompt/tool tiers and modes
diff --git a/docs/zh-CN/providers-and-models.md b/docs/zh-CN/providers-and-models.md
index 84ac7b030..c7908aa3a 100644
--- a/docs/zh-CN/providers-and-models.md
+++ b/docs/zh-CN/providers-and-models.md
@@ -127,7 +127,10 @@ WebBrain 会直接记录;若服务省略用量,则记录基于字符数的
- **LocalAI**:`http://localhost:8080/v1` — LocalAI 的 OpenAI 兼容服务器
- **GPT4All**:`http://localhost:4891/v1` — GPT4All 本地 API 服务器
- **本地 OpenAI 兼容代理**:`http://127.0.0.1:8317/v1` — 通用的、带认证的
- 本地网关;模型和代理客户端 API 密钥均为必填
+ 本地网关;模型和代理客户端 API 密钥均为必填。加载模型、选择模型或测试连接后,
+ 上下文窗口会按以下顺序自动设置:代理 `/v1/models` 中所选模型的卡片、其后 llama.cpp
+ 服务器的 `GET /props?model=` 实时 `n_ctx`、已知托管模型名称(上限 128k),否则使用
+ **64k** 的代理默认值(此前为 16k)。名称和默认值只替换默认值,不会覆盖您手动输入的数值
#### 订阅代理示例(CLIProxyAPI)
diff --git a/src/chrome/src/providers/context-windows.js b/src/chrome/src/providers/context-windows.js
index 5bb5fbb5f..6dbecf2c7 100644
--- a/src/chrome/src/providers/context-windows.js
+++ b/src/chrome/src/providers/context-windows.js
@@ -2,6 +2,15 @@ import { deepSeekModelCapabilities } from './deepseek-config.js';
export const DEFAULT_LOCAL_CONTEXT_WINDOW = 16384;
export const DEFAULT_CLOUD_CONTEXT_WINDOW = 128000;
+// The Local OpenAI-compatible Proxy usually fronts hosted models through a
+// subscription CLI gateway (CLIProxyAPI style), whose windows start at 128k,
+// so the 16k local fallback starved them. 64k is the fallback when the proxy
+// reports nothing: it can overflow a small local model behind the proxy, which
+// a reported or live window then corrects (manager._detectLocalContextWindow).
+export const LOCAL_OPENAI_PROXY_CONTEXT_WINDOW = 65536;
+// Gateways can serve less context than the vendor API advertises for the same
+// model id, so a window taken from the model name alone stays at 128k or less.
+export const LOCAL_OPENAI_PROXY_MAX_NAMED_CONTEXT_WINDOW = DEFAULT_CLOUD_CONTEXT_WINDOW;
export const MIN_CONTEXT_WINDOW = 4096;
export const MAX_CONTEXT_WINDOW = 1048576;
@@ -74,6 +83,9 @@ export function shouldApplyDetectedContextWindow(current, detected, options = {}
const cur = Number(current);
if (!Number.isFinite(cur) || cur <= 0) return true;
if (cur === DEFAULT_LOCAL_CONTEXT_WINDOW) return true;
+ // A provider's own shipped default, or a value WebBrain filled in itself,
+ // is not a user override either.
+ if (Array.isArray(options.replaceable) && options.replaceable.some((value) => Number(value) === cur)) return true;
if (next >= cur) return false;
return options.shrinkOverride === true;
}
@@ -225,6 +237,39 @@ export function parseOpenAiModelListContextWindow(data, preferredModel = '') {
return null;
}
+/**
+ * Local OpenAI-compatible Proxy `GET /v1/models`. Gateways describe a model's
+ * window in different fields (vLLM-style `max_model_len`, OpenRouter-style
+ * `context_length`, Gemini-style `input_token_limit`, …). Only the selected
+ * model's card counts: never borrow another model's window.
+ */
+export function parseOpenAiProxyModelListContextWindow(data, preferredModel = '') {
+ const want = String(preferredModel || '').trim();
+ const source = Array.isArray(data?.data) ? data.data : [];
+ if (!want || !source.length) return null;
+ const card = source.find((m) => m && typeof m === 'object' && modelIdsMatch(m.id, want));
+ if (!card) return null;
+ return openAiModelCardContextWindow(card) ?? normalizeDetectedContextWindow(
+ card.context_length ??
+ card.contextLength ??
+ card.max_input_tokens ??
+ card.maxInputTokens ??
+ card.input_token_limit ??
+ card.inputTokenLimit ??
+ card.top_provider?.context_length
+ );
+}
+
+/**
+ * Known hosted model behind the proxy, by name only (`claude-…`, `gpt-5…`,
+ * `gemini-…`, …), capped at LOCAL_OPENAI_PROXY_MAX_NAMED_CONTEXT_WINDOW.
+ * Null for names WebBrain does not know: the proxy fallback applies then.
+ */
+export function inferLocalProxyModelContextWindow(model) {
+ const known = inferKnownModelContextWindow({ providerName: 'local-openai-proxy', model });
+ return known == null ? null : Math.min(known, LOCAL_OPENAI_PROXY_MAX_NAMED_CONTEXT_WINDOW);
+}
+
/**
* LocalAI `GET /api/models/config-json/:name` — use configured runtime
* `context_size` only. Do not infer from architecture/model maxima.
@@ -266,17 +311,28 @@ export function lmStudioContextWindowIsLive(data, preferredModel = '') {
/**
* Best-effort context-window metadata for cloud/router models. Local models
* are runtime-configured by the user/server; they stay on the conservative 16k
- * default until Settings supplies `config.contextWindow` (including values
- * filled by Test connection / Load models auto-detect).
+ * default (64k for the Local OpenAI-compatible Proxy) until Settings supplies
+ * `config.contextWindow` (including values filled by Test connection / Load
+ * models auto-detect).
*/
export function inferContextWindow(config = {}) {
const category = clean(config.category);
- if (category === 'local') return DEFAULT_LOCAL_CONTEXT_WINDOW;
+ const provider = clean(config.providerName || config.type || config.label);
+ if (category === 'local') {
+ return provider === 'local-openai-proxy' ? LOCAL_OPENAI_PROXY_CONTEXT_WINDOW : DEFAULT_LOCAL_CONTEXT_WINDOW;
+ }
+ if (!clean(config.model)) return DEFAULT_CLOUD_CONTEXT_WINDOW;
+ return inferKnownModelContextWindow(config) ?? DEFAULT_CLOUD_CONTEXT_WINDOW;
+}
+/**
+ * Context window of a model WebBrain knows by name, or null for any other
+ * name (callers pick their own fallback).
+ */
+export function inferKnownModelContextWindow(config = {}) {
const provider = clean(config.providerName || config.type || config.label);
const model = clean(config.model);
-
- if (!model) return DEFAULT_CLOUD_CONTEXT_WINDOW;
+ if (!model) return null;
// OpenAI
if (/(?:^|\/)gpt-6(?:\.1)?-(?:luna-pro|sol|astra)(?:[.\-:]|$)/.test(model)) return 1050000;
@@ -340,7 +396,7 @@ export function inferContextWindow(config = {}) {
if (model.includes('qwen-max')) return K128;
if (/qwen3-(?:235b|30b|32b|next)/.test(model)) return K128;
- return DEFAULT_CLOUD_CONTEXT_WINDOW;
+ return null;
}
export const DEFAULT_MAX_OUTPUT_TOKENS = 4096;
diff --git a/src/chrome/src/providers/manager.js b/src/chrome/src/providers/manager.js
index 747105fc0..243b3bf02 100644
--- a/src/chrome/src/providers/manager.js
+++ b/src/chrome/src/providers/manager.js
@@ -54,6 +54,8 @@ import {
} from './vision-capabilities.js';
import {
canonicalizeOllamaBaseUrl,
+ inferLocalProxyModelContextWindow,
+ LOCAL_OPENAI_PROXY_CONTEXT_WINDOW,
lmStudioContextWindowIsLive,
parseLlamaCppPropsContextWindow,
parseLocalAiModelConfigContextWindow,
@@ -62,6 +64,7 @@ import {
parseOllamaShowContextWindow,
parseOllamaShowVisionSupport,
parseOpenAiModelListContextWindow,
+ parseOpenAiProxyModelListContextWindow,
shouldApplyDetectedContextWindow,
} from './context-windows.js';
import {
@@ -686,7 +689,7 @@ export class ProviderManager {
baseUrl: 'http://127.0.0.1:8317/v1',
model: '',
requiresModel: true,
- contextWindow: 16384,
+ contextWindow: LOCAL_OPENAI_PROXY_CONTEXT_WINDOW,
apiKey: '',
requiresApiKey: true,
supportsAskStreaming: true,
@@ -1019,6 +1022,22 @@ export class ProviderManager {
return defaults;
}
+ // The Local OpenAI-compatible Proxy shipped with the 16k local window,
+ // which starves the hosted models it usually fronts. Move cards nobody set
+ // up (no configured marker, no credentials) to the 64k default. A set-up
+ // card keeps its value until the next Test connection, Load models or model
+ // pick, where 16k already counts as a replaceable default.
+ _migrateUntouchedLocalProxyContextWindows(migrated) {
+ const defaults = this._defaultConfigs().local_openai_proxy;
+ for (const [id, config] of Object.entries(migrated)) {
+ if (!config || typeof config !== 'object') continue;
+ if (String(config.duplicateOf || id) !== 'local_openai_proxy') continue;
+ if (config.configured === true || this._hasStoredProviderCredentials(defaults, config)) continue;
+ if (Number(config.contextWindow) !== 16384) continue;
+ migrated[id] = { ...config, contextWindow: LOCAL_OPENAI_PROXY_CONTEXT_WINDOW };
+ }
+ }
+
_migrateStoredProviderConfigs(stored) {
const migrated = { ...stored };
const storedOpenAi = migrated.openai;
@@ -1091,6 +1110,7 @@ export class ProviderManager {
contextWindow: 32768,
};
}
+ this._migrateUntouchedLocalProxyContextWindows(migrated);
this._migrateUntouchedShippedDefaults(migrated);
// The OpenCode entry is editable, so only replace the retired shipped
// model while it still points at the official Zen endpoint. In particular,
@@ -2540,10 +2560,12 @@ export class ProviderManager {
const current = this.providers.get(id) || provider;
if (!shouldApplyDetectedContextWindow(current?.config?.contextWindow, detected.contextWindow, {
shrinkOverride: detected.shrinkOverride === true,
+ replaceable: this._replaceableContextWindows(id, current?.config),
})) {
return { ok: true };
}
- if (!await this._updateProviderContextWindow(id, detected.contextWindow, observed)) {
+ if (!await this._updateProviderContextWindow(id, detected.contextWindow, observed,
+ this._detectedContextWindowFields(id, current?.config, detected.contextWindow))) {
return { ok: false, error: 'Provider changed before context detection completed' };
}
return { ok: true, contextWindow: detected.contextWindow };
@@ -2633,17 +2655,38 @@ export class ProviderManager {
return true;
}
- async _updateProviderContextWindow(id, contextWindow, observed = {}) {
+ async _updateProviderContextWindow(id, contextWindow, observed = {}, extra = {}) {
const current = this.providers.get(id);
if (!current || !Number.isFinite(contextWindow) || contextWindow <= 0) return false;
if (observed.model !== undefined && current.config.model !== observed.model) return false;
if (observed.baseUrl !== undefined && current.config.baseUrl !== observed.baseUrl) return false;
- if (Number(current.config.contextWindow) === contextWindow) return true;
- this.providers.set(id, this._createProvider(id, { ...current.config, contextWindow }));
+ const unchanged = Number(current.config.contextWindow) === contextWindow
+ && Object.entries(extra).every(([key, value]) => current.config[key] === value);
+ if (unchanged) return true;
+ this.providers.set(id, this._createProvider(id, { ...current.config, ...extra, contextWindow }));
await this.save();
return true;
}
+ /**
+ * Stored windows that detection may replace besides the 16k local default.
+ * For the Local OpenAI-compatible Proxy: its own 64k default and the last
+ * window WebBrain filled in itself (`autoContextWindow`), so a name-based
+ * 128k for one model does not stick when an unknown model is picked next.
+ * Any other value is a user override.
+ */
+ _replaceableContextWindows(id, config) {
+ if (this._providerDefinitionId(id, config) !== 'local_openai_proxy') return [];
+ const auto = Number(config?.autoContextWindow);
+ return [LOCAL_OPENAI_PROXY_CONTEXT_WINDOW, ...(Number.isFinite(auto) && auto > 0 ? [auto] : [])];
+ }
+
+ _detectedContextWindowFields(id, config, contextWindow) {
+ return this._providerDefinitionId(id, config) === 'local_openai_proxy'
+ ? { autoContextWindow: contextWindow }
+ : {};
+ }
+
async _attachDetectedContextWindow(id, provider, result, options = {}) {
const definitionId = this._providerDefinitionId(id, provider?.config);
if (!result?.ok || !LOCAL_MODEL_LIST_PROVIDER_IDS.includes(definitionId)) return result;
@@ -2656,10 +2699,12 @@ export class ProviderManager {
const current = this.providers.get(id) || provider;
if (!shouldApplyDetectedContextWindow(current?.config?.contextWindow, detected.contextWindow, {
shrinkOverride: detected.shrinkOverride === true,
+ replaceable: this._replaceableContextWindows(id, current?.config),
})) {
return result;
}
- if (!await this._updateProviderContextWindow(id, detected.contextWindow, observed)) {
+ if (!await this._updateProviderContextWindow(id, detected.contextWindow, observed,
+ this._detectedContextWindowFields(id, current?.config, detected.contextWindow))) {
return result;
}
return { ...result, contextWindow: detected.contextWindow };
@@ -2749,6 +2794,36 @@ export class ProviderManager {
return { contextWindow, shrinkOverride: true };
}
+ if (definitionId === 'local_openai_proxy') {
+ // Nothing describes the window of a model the proxy does not name.
+ if (!model) return null;
+ const openAiBase = /\/v1$/i.test(rawBaseUrl) ? rawBaseUrl : `${root}/v1`;
+ // 1. The proxy's own card for the selected model.
+ let data = options.modelListData || null;
+ if (!data) {
+ try {
+ const res = await fetchWithFallback(`${openAiBase}/models`, { method: 'GET', headers });
+ if (res.ok) data = await res.json();
+ } catch { /* try the next source */ }
+ }
+ const listed = data ? parseOpenAiProxyModelListContextWindow(data, model) : null;
+ if (listed != null) return { contextWindow: listed, shrinkOverride: true };
+ // 2. A llama.cpp server behind the proxy reports the loaded model's
+ // live n_ctx (`?model=` selects it on a llama-server router).
+ try {
+ const res = await fetchWithFallback(`${root}/props?model=${encodeURIComponent(model)}`, { method: 'GET', headers });
+ if (res.ok) {
+ const live = parseLlamaCppPropsContextWindow(await res.json());
+ if (live != null) return { contextWindow: live, shrinkOverride: true };
+ }
+ } catch { /* try the next source */ }
+ // 3. A hosted model WebBrain knows by name, capped at 128k.
+ const named = inferLocalProxyModelContextWindow(model);
+ if (named != null) return { contextWindow: named, shrinkOverride: false };
+ // 4. The proxy fallback. It only replaces a default, never an override.
+ return { contextWindow: LOCAL_OPENAI_PROXY_CONTEXT_WINDOW, shrinkOverride: false };
+ }
+
if (definitionId === 'localai') {
if (!model) return null;
const res = await fetchWithFallback(`${root}/api/models/config-json/${encodeURIComponent(model)}`, {
diff --git a/src/chrome/src/ui/settings.js b/src/chrome/src/ui/settings.js
index fc405cd7a..496211667 100644
--- a/src/chrome/src/ui/settings.js
+++ b/src/chrome/src/ui/settings.js
@@ -2618,6 +2618,12 @@ const WEBGPU_CONTEXT_WINDOW_FIELD = {
placeholder: '32768',
};
+// Matches LOCAL_OPENAI_PROXY_CONTEXT_WINDOW (providers/context-windows.js).
+const LOCAL_PROXY_CONTEXT_WINDOW_FIELD = {
+ ...CONTEXT_WINDOW_FIELD,
+ placeholder: '65536',
+};
+
const MAX_OUTPUT_TOKENS_FIELD = {
key: 'maxOutputTokens',
labelKey: 'st.provider.field.max_output_tokens',
@@ -3363,7 +3369,7 @@ function renderProviders() {
{ key: 'baseUrl', labelKey: 'st.provider.field.server_url', type: 'text', placeholder: 'http://127.0.0.1:8317/v1' },
{ key: 'apiKey', labelKey: 'st.provider.field.api_key', type: 'password', placeholder: 'required — use the proxy client API key' },
{ key: 'model', labelKey: 'st.provider.field.model', type: 'text', placeholder: 'model exposed by the proxy' },
- CONTEXT_WINDOW_FIELD,
+ LOCAL_PROXY_CONTEXT_WINDOW_FIELD,
{ key: 'supportsVision', labelKey: 'st.provider.field.supports_vision', type: 'checkbox' },
PROMPT_TIER_FIELD,
],
diff --git a/src/firefox/src/providers/context-windows.js b/src/firefox/src/providers/context-windows.js
index 5bb5fbb5f..6dbecf2c7 100644
--- a/src/firefox/src/providers/context-windows.js
+++ b/src/firefox/src/providers/context-windows.js
@@ -2,6 +2,15 @@ import { deepSeekModelCapabilities } from './deepseek-config.js';
export const DEFAULT_LOCAL_CONTEXT_WINDOW = 16384;
export const DEFAULT_CLOUD_CONTEXT_WINDOW = 128000;
+// The Local OpenAI-compatible Proxy usually fronts hosted models through a
+// subscription CLI gateway (CLIProxyAPI style), whose windows start at 128k,
+// so the 16k local fallback starved them. 64k is the fallback when the proxy
+// reports nothing: it can overflow a small local model behind the proxy, which
+// a reported or live window then corrects (manager._detectLocalContextWindow).
+export const LOCAL_OPENAI_PROXY_CONTEXT_WINDOW = 65536;
+// Gateways can serve less context than the vendor API advertises for the same
+// model id, so a window taken from the model name alone stays at 128k or less.
+export const LOCAL_OPENAI_PROXY_MAX_NAMED_CONTEXT_WINDOW = DEFAULT_CLOUD_CONTEXT_WINDOW;
export const MIN_CONTEXT_WINDOW = 4096;
export const MAX_CONTEXT_WINDOW = 1048576;
@@ -74,6 +83,9 @@ export function shouldApplyDetectedContextWindow(current, detected, options = {}
const cur = Number(current);
if (!Number.isFinite(cur) || cur <= 0) return true;
if (cur === DEFAULT_LOCAL_CONTEXT_WINDOW) return true;
+ // A provider's own shipped default, or a value WebBrain filled in itself,
+ // is not a user override either.
+ if (Array.isArray(options.replaceable) && options.replaceable.some((value) => Number(value) === cur)) return true;
if (next >= cur) return false;
return options.shrinkOverride === true;
}
@@ -225,6 +237,39 @@ export function parseOpenAiModelListContextWindow(data, preferredModel = '') {
return null;
}
+/**
+ * Local OpenAI-compatible Proxy `GET /v1/models`. Gateways describe a model's
+ * window in different fields (vLLM-style `max_model_len`, OpenRouter-style
+ * `context_length`, Gemini-style `input_token_limit`, …). Only the selected
+ * model's card counts: never borrow another model's window.
+ */
+export function parseOpenAiProxyModelListContextWindow(data, preferredModel = '') {
+ const want = String(preferredModel || '').trim();
+ const source = Array.isArray(data?.data) ? data.data : [];
+ if (!want || !source.length) return null;
+ const card = source.find((m) => m && typeof m === 'object' && modelIdsMatch(m.id, want));
+ if (!card) return null;
+ return openAiModelCardContextWindow(card) ?? normalizeDetectedContextWindow(
+ card.context_length ??
+ card.contextLength ??
+ card.max_input_tokens ??
+ card.maxInputTokens ??
+ card.input_token_limit ??
+ card.inputTokenLimit ??
+ card.top_provider?.context_length
+ );
+}
+
+/**
+ * Known hosted model behind the proxy, by name only (`claude-…`, `gpt-5…`,
+ * `gemini-…`, …), capped at LOCAL_OPENAI_PROXY_MAX_NAMED_CONTEXT_WINDOW.
+ * Null for names WebBrain does not know: the proxy fallback applies then.
+ */
+export function inferLocalProxyModelContextWindow(model) {
+ const known = inferKnownModelContextWindow({ providerName: 'local-openai-proxy', model });
+ return known == null ? null : Math.min(known, LOCAL_OPENAI_PROXY_MAX_NAMED_CONTEXT_WINDOW);
+}
+
/**
* LocalAI `GET /api/models/config-json/:name` — use configured runtime
* `context_size` only. Do not infer from architecture/model maxima.
@@ -266,17 +311,28 @@ export function lmStudioContextWindowIsLive(data, preferredModel = '') {
/**
* Best-effort context-window metadata for cloud/router models. Local models
* are runtime-configured by the user/server; they stay on the conservative 16k
- * default until Settings supplies `config.contextWindow` (including values
- * filled by Test connection / Load models auto-detect).
+ * default (64k for the Local OpenAI-compatible Proxy) until Settings supplies
+ * `config.contextWindow` (including values filled by Test connection / Load
+ * models auto-detect).
*/
export function inferContextWindow(config = {}) {
const category = clean(config.category);
- if (category === 'local') return DEFAULT_LOCAL_CONTEXT_WINDOW;
+ const provider = clean(config.providerName || config.type || config.label);
+ if (category === 'local') {
+ return provider === 'local-openai-proxy' ? LOCAL_OPENAI_PROXY_CONTEXT_WINDOW : DEFAULT_LOCAL_CONTEXT_WINDOW;
+ }
+ if (!clean(config.model)) return DEFAULT_CLOUD_CONTEXT_WINDOW;
+ return inferKnownModelContextWindow(config) ?? DEFAULT_CLOUD_CONTEXT_WINDOW;
+}
+/**
+ * Context window of a model WebBrain knows by name, or null for any other
+ * name (callers pick their own fallback).
+ */
+export function inferKnownModelContextWindow(config = {}) {
const provider = clean(config.providerName || config.type || config.label);
const model = clean(config.model);
-
- if (!model) return DEFAULT_CLOUD_CONTEXT_WINDOW;
+ if (!model) return null;
// OpenAI
if (/(?:^|\/)gpt-6(?:\.1)?-(?:luna-pro|sol|astra)(?:[.\-:]|$)/.test(model)) return 1050000;
@@ -340,7 +396,7 @@ export function inferContextWindow(config = {}) {
if (model.includes('qwen-max')) return K128;
if (/qwen3-(?:235b|30b|32b|next)/.test(model)) return K128;
- return DEFAULT_CLOUD_CONTEXT_WINDOW;
+ return null;
}
export const DEFAULT_MAX_OUTPUT_TOKENS = 4096;
diff --git a/src/firefox/src/providers/manager.js b/src/firefox/src/providers/manager.js
index a701b960e..cdabd531a 100644
--- a/src/firefox/src/providers/manager.js
+++ b/src/firefox/src/providers/manager.js
@@ -28,6 +28,8 @@ import {
} from './vision-capabilities.js';
import {
canonicalizeOllamaBaseUrl,
+ inferLocalProxyModelContextWindow,
+ LOCAL_OPENAI_PROXY_CONTEXT_WINDOW,
lmStudioContextWindowIsLive,
parseLlamaCppPropsContextWindow,
parseLocalAiModelConfigContextWindow,
@@ -36,6 +38,7 @@ import {
parseOllamaShowContextWindow,
parseOllamaShowVisionSupport,
parseOpenAiModelListContextWindow,
+ parseOpenAiProxyModelListContextWindow,
shouldApplyDetectedContextWindow,
} from './context-windows.js';
import {
@@ -595,7 +598,7 @@ export class ProviderManager {
baseUrl: 'http://127.0.0.1:8317/v1',
model: '',
requiresModel: true,
- contextWindow: 16384,
+ contextWindow: LOCAL_OPENAI_PROXY_CONTEXT_WINDOW,
apiKey: '',
requiresApiKey: true,
supportsAskStreaming: true,
@@ -904,6 +907,22 @@ export class ProviderManager {
return defaults;
}
+ // The Local OpenAI-compatible Proxy shipped with the 16k local window,
+ // which starves the hosted models it usually fronts. Move cards nobody set
+ // up (no configured marker, no credentials) to the 64k default. A set-up
+ // card keeps its value until the next Test connection, Load models or model
+ // pick, where 16k already counts as a replaceable default.
+ _migrateUntouchedLocalProxyContextWindows(migrated) {
+ const defaults = this._defaultConfigs().local_openai_proxy;
+ for (const [id, config] of Object.entries(migrated)) {
+ if (!config || typeof config !== 'object') continue;
+ if (String(config.duplicateOf || id) !== 'local_openai_proxy') continue;
+ if (config.configured === true || this._hasStoredProviderCredentials(defaults, config)) continue;
+ if (Number(config.contextWindow) !== 16384) continue;
+ migrated[id] = { ...config, contextWindow: LOCAL_OPENAI_PROXY_CONTEXT_WINDOW };
+ }
+ }
+
_migrateStoredProviderConfigs(stored) {
const migrated = { ...stored };
const storedOpenAi = migrated.openai;
@@ -952,6 +971,7 @@ export class ProviderManager {
outputCostPerMillionUsd: 0.56,
};
}
+ this._migrateUntouchedLocalProxyContextWindows(migrated);
this._migrateUntouchedShippedDefaults(migrated);
// The OpenCode entry is editable, so only replace the retired shipped
// model while it still points at the official Zen endpoint. In particular,
@@ -2079,10 +2099,12 @@ export class ProviderManager {
const current = this.providers.get(id) || provider;
if (!shouldApplyDetectedContextWindow(current?.config?.contextWindow, detected.contextWindow, {
shrinkOverride: detected.shrinkOverride === true,
+ replaceable: this._replaceableContextWindows(id, current?.config),
})) {
return { ok: true };
}
- if (!await this._updateProviderContextWindow(id, detected.contextWindow, observed)) {
+ if (!await this._updateProviderContextWindow(id, detected.contextWindow, observed,
+ this._detectedContextWindowFields(id, current?.config, detected.contextWindow))) {
return { ok: false, error: 'Provider changed before context detection completed' };
}
return { ok: true, contextWindow: detected.contextWindow };
@@ -2172,17 +2194,38 @@ export class ProviderManager {
return true;
}
- async _updateProviderContextWindow(id, contextWindow, observed = {}) {
+ async _updateProviderContextWindow(id, contextWindow, observed = {}, extra = {}) {
const current = this.providers.get(id);
if (!current || !Number.isFinite(contextWindow) || contextWindow <= 0) return false;
if (observed.model !== undefined && current.config.model !== observed.model) return false;
if (observed.baseUrl !== undefined && current.config.baseUrl !== observed.baseUrl) return false;
- if (Number(current.config.contextWindow) === contextWindow) return true;
- this.providers.set(id, this._createProvider(id, { ...current.config, contextWindow }));
+ const unchanged = Number(current.config.contextWindow) === contextWindow
+ && Object.entries(extra).every(([key, value]) => current.config[key] === value);
+ if (unchanged) return true;
+ this.providers.set(id, this._createProvider(id, { ...current.config, ...extra, contextWindow }));
await this.save();
return true;
}
+ /**
+ * Stored windows that detection may replace besides the 16k local default.
+ * For the Local OpenAI-compatible Proxy: its own 64k default and the last
+ * window WebBrain filled in itself (`autoContextWindow`), so a name-based
+ * 128k for one model does not stick when an unknown model is picked next.
+ * Any other value is a user override.
+ */
+ _replaceableContextWindows(id, config) {
+ if (this._providerDefinitionId(id, config) !== 'local_openai_proxy') return [];
+ const auto = Number(config?.autoContextWindow);
+ return [LOCAL_OPENAI_PROXY_CONTEXT_WINDOW, ...(Number.isFinite(auto) && auto > 0 ? [auto] : [])];
+ }
+
+ _detectedContextWindowFields(id, config, contextWindow) {
+ return this._providerDefinitionId(id, config) === 'local_openai_proxy'
+ ? { autoContextWindow: contextWindow }
+ : {};
+ }
+
async _attachDetectedContextWindow(id, provider, result, options = {}) {
const definitionId = this._providerDefinitionId(id, provider?.config);
if (!result?.ok || !LOCAL_MODEL_LIST_PROVIDER_IDS.includes(definitionId)) return result;
@@ -2195,10 +2238,12 @@ export class ProviderManager {
const current = this.providers.get(id) || provider;
if (!shouldApplyDetectedContextWindow(current?.config?.contextWindow, detected.contextWindow, {
shrinkOverride: detected.shrinkOverride === true,
+ replaceable: this._replaceableContextWindows(id, current?.config),
})) {
return result;
}
- if (!await this._updateProviderContextWindow(id, detected.contextWindow, observed)) {
+ if (!await this._updateProviderContextWindow(id, detected.contextWindow, observed,
+ this._detectedContextWindowFields(id, current?.config, detected.contextWindow))) {
return result;
}
return { ...result, contextWindow: detected.contextWindow };
@@ -2288,6 +2333,36 @@ export class ProviderManager {
return { contextWindow, shrinkOverride: true };
}
+ if (definitionId === 'local_openai_proxy') {
+ // Nothing describes the window of a model the proxy does not name.
+ if (!model) return null;
+ const openAiBase = /\/v1$/i.test(rawBaseUrl) ? rawBaseUrl : `${root}/v1`;
+ // 1. The proxy's own card for the selected model.
+ let data = options.modelListData || null;
+ if (!data) {
+ try {
+ const res = await fetch(`${openAiBase}/models`, { method: 'GET', headers });
+ if (res.ok) data = await res.json();
+ } catch { /* try the next source */ }
+ }
+ const listed = data ? parseOpenAiProxyModelListContextWindow(data, model) : null;
+ if (listed != null) return { contextWindow: listed, shrinkOverride: true };
+ // 2. A llama.cpp server behind the proxy reports the loaded model's
+ // live n_ctx (`?model=` selects it on a llama-server router).
+ try {
+ const res = await fetch(`${root}/props?model=${encodeURIComponent(model)}`, { method: 'GET', headers });
+ if (res.ok) {
+ const live = parseLlamaCppPropsContextWindow(await res.json());
+ if (live != null) return { contextWindow: live, shrinkOverride: true };
+ }
+ } catch { /* try the next source */ }
+ // 3. A hosted model WebBrain knows by name, capped at 128k.
+ const named = inferLocalProxyModelContextWindow(model);
+ if (named != null) return { contextWindow: named, shrinkOverride: false };
+ // 4. The proxy fallback. It only replaces a default, never an override.
+ return { contextWindow: LOCAL_OPENAI_PROXY_CONTEXT_WINDOW, shrinkOverride: false };
+ }
+
if (definitionId === 'localai') {
if (!model) return null;
const res = await fetch(`${root}/api/models/config-json/${encodeURIComponent(model)}`, {
diff --git a/src/firefox/src/ui/settings.js b/src/firefox/src/ui/settings.js
index 085853c05..d59709755 100644
--- a/src/firefox/src/ui/settings.js
+++ b/src/firefox/src/ui/settings.js
@@ -2372,6 +2372,12 @@ const CONTEXT_WINDOW_FIELD = {
step: 1024,
};
+// Matches LOCAL_OPENAI_PROXY_CONTEXT_WINDOW (providers/context-windows.js).
+const LOCAL_PROXY_CONTEXT_WINDOW_FIELD = {
+ ...CONTEXT_WINDOW_FIELD,
+ placeholder: '65536',
+};
+
const MAX_OUTPUT_TOKENS_FIELD = {
key: 'maxOutputTokens',
labelKey: 'st.provider.field.max_output_tokens',
@@ -2893,7 +2899,7 @@ function renderProviders() {
{ key: 'baseUrl', labelKey: 'st.provider.field.server_url', type: 'text', placeholder: 'http://127.0.0.1:8317/v1' },
{ key: 'apiKey', labelKey: 'st.provider.field.api_key', type: 'password', placeholder: 'required — use the proxy client API key' },
{ key: 'model', labelKey: 'st.provider.field.model', type: 'text', placeholder: 'model exposed by the proxy' },
- CONTEXT_WINDOW_FIELD,
+ LOCAL_PROXY_CONTEXT_WINDOW_FIELD,
{ key: 'supportsVision', labelKey: 'st.provider.field.supports_vision', type: 'checkbox' },
PROMPT_TIER_FIELD,
],
diff --git a/test/run.js b/test/run.js
index d649cad21..350fda637 100644
--- a/test/run.js
+++ b/test/run.js
@@ -71907,9 +71907,10 @@ test('tri-state local vision controls and pre-enrichment preparation stay mirror
test('inferContextWindow: model-aware cloud/router defaults and local 16k fallback', () => {
for (const infer of [inferContextWindowCh, inferContextWindowFx]) {
- for (const providerName of ['lmstudio', 'jan', 'vllm', 'sglang', 'localai', 'gpt4all', 'local-openai-proxy']) {
+ for (const providerName of ['lmstudio', 'jan', 'vllm', 'sglang', 'localai', 'gpt4all']) {
assert.equal(infer({ category: 'local', providerName, model: 'qwen3.7-plus' }), 16384);
}
+ assert.equal(infer({ category: 'local', providerName: 'local-openai-proxy', model: 'qwen3.7-plus' }), 65536);
for (const model of ['gpt-6-luna-pro', 'gpt-6.1-sol', 'gpt-6-astra', 'gpt-5.6', 'gpt-5.6-sol', 'gpt-5.6-terra', 'gpt-5.6-luna']) {
assert.equal(infer({ category: 'cloud', providerName: 'openai', model }), 1050000);
}
@@ -72882,6 +72883,227 @@ test('ProviderManager persists detected local context windows with safe apply po
}
});
+test('Local OpenAI-compatible Proxy context window: model card, live props, model name, 64k fallback', async () => {
+ const originalFetch = globalThis.fetch;
+ const originalChrome = globalThis.chrome;
+ const originalBrowser = globalThis.browser;
+ const jsonOk = (body) => new Response(JSON.stringify(body), { status: 200, headers: { 'Content-Type': 'application/json' } });
+ const makeRuntime = (writes) => ({
+ storage: { local: { async get() { return {}; }, async set(patch) { writes.push(patch); } } },
+ runtime: { id: 'test-runtime' },
+ });
+ const modules = [
+ ['chrome', ProviderManagerCh, 'chrome', 'src/chrome/src/providers/context-windows.js'],
+ ['firefox', ProviderManagerFx, 'browser', 'src/firefox/src/providers/context-windows.js'],
+ ];
+ try {
+ for (const [label, PM, runtimeKey, contextRel] of modules) {
+ const cw = await import('file://' + path.join(ROOT, contextRel).replace(/\\/g, '/'));
+ assert.equal(cw.LOCAL_OPENAI_PROXY_CONTEXT_WINDOW, 65536, `${label}: proxy fallback`);
+ // Parsers: only the selected model's card, under any common field name.
+ assert.equal(cw.parseOpenAiProxyModelListContextWindow({ data: [
+ { id: 'other', context_length: 32768 },
+ { id: 'Served-Model', context_length: 200000 },
+ ] }, 'served-model'), 200000);
+ assert.equal(cw.parseOpenAiProxyModelListContextWindow({ data: [{ id: 'm', max_model_len: 40960, context_length: 200000 }] }, 'm'), 40960);
+ assert.equal(cw.parseOpenAiProxyModelListContextWindow({ data: [{ id: 'm', input_token_limit: 1048576 }] }, 'm'), 1048576);
+ assert.equal(cw.parseOpenAiProxyModelListContextWindow({ data: [{ id: 'other', context_length: 32768 }] }, 'm'), null);
+ assert.equal(cw.parseOpenAiProxyModelListContextWindow({ data: [{ id: 'm', context_length: 32768 }] }, ''), null);
+ assert.equal(cw.parseOpenAiProxyModelListContextWindow({ data: [{ id: 'm', object: 'model' }] }, 'm'), null);
+ // vLLM/SGLang parsing is unchanged: context_length stays ignored there.
+ assert.equal(cw.parseOpenAiModelListContextWindow({ data: [{ id: 'm', context_length: 65536 }] }, 'm'), null);
+ // Names: known hosted models, capped at 128k; unknown names stay null.
+ assert.equal(cw.inferLocalProxyModelContextWindow('claude-sonnet-4-5-20250929'), 128000);
+ assert.equal(cw.inferLocalProxyModelContextWindow('gpt-5-codex'), 128000);
+ assert.equal(cw.inferLocalProxyModelContextWindow('gemini-2.5-pro'), 128000);
+ assert.equal(cw.inferLocalProxyModelContextWindow('my-local-qwen'), null);
+ assert.equal(cw.inferKnownModelContextWindow({ model: 'my-local-qwen' }), null);
+ assert.equal(cw.inferContextWindow({ category: 'cloud', model: 'my-local-qwen' }), 128000, `${label}: cloud fallback unchanged`);
+ // Replaceable windows count as defaults; anything else stays an override.
+ assert.equal(cw.shouldApplyDetectedContextWindow(65536, 128000), false);
+ assert.equal(cw.shouldApplyDetectedContextWindow(65536, 128000, { replaceable: [65536] }), true);
+ assert.equal(cw.shouldApplyDetectedContextWindow(128000, 65536, { replaceable: [65536, 128000] }), true);
+ assert.equal(cw.shouldApplyDetectedContextWindow(32768, 65536, { replaceable: [65536] }), false);
+
+ const proxyConfig = (mgr, extra = {}) => ({
+ ...mgr._defaultConfigs().local_openai_proxy,
+ apiKey: 'strong-local-proxy-key',
+ configured: true,
+ ...extra,
+ });
+ const setup = (fetchImpl, extra) => {
+ const writes = [];
+ globalThis[runtimeKey] = makeRuntime(writes);
+ globalThis.fetch = fetchImpl;
+ const mgr = new PM();
+ mgr.providers.set('local_openai_proxy', mgr._createProvider('local_openai_proxy', proxyConfig(mgr, extra)));
+ return { mgr, writes, config: () => mgr.providers.get('local_openai_proxy').config };
+ };
+
+ // 1. Load models: the proxy's card for the selected model sets the window.
+ {
+ const { mgr, writes, config } = setup(async (url) => (String(url).endsWith('/v1/models')
+ ? jsonOk({ data: [{ id: 'other', context_length: 32768 }, { id: 'claude-sonnet-4-5', context_length: 200000 }] })
+ : new Response('missing', { status: 404 })), { model: 'claude-sonnet-4-5' });
+ const result = await mgr.listProviderModels('local_openai_proxy');
+ assert.equal(result.ok, true, `${label}: proxy list ok`);
+ assert.equal(result.contextWindow, 200000, `${label}: proxy card window applied`);
+ assert.equal(config().contextWindow, 200000);
+ assert.equal(config().autoContextWindow, 200000, `${label}: auto-filled window is remembered`);
+ assert.ok(writes.some((patch) => patch.providers?.local_openai_proxy?.contextWindow === 200000));
+ }
+
+ // 2. Model pick: llama.cpp behind the proxy reports the loaded model's live n_ctx.
+ {
+ const urls = [];
+ const { mgr, config } = setup(async (url) => {
+ urls.push(String(url));
+ if (String(url).endsWith('/v1/models')) return jsonOk({ data: [{ id: 'qwen-local', object: 'model' }] });
+ if (String(url).includes('/props?model=qwen-local')) return jsonOk({ default_generation_settings: { n_ctx: 32768 } });
+ return new Response('missing', { status: 404 });
+ }, { model: 'qwen-local' });
+ const result = await mgr.detectProviderContextWindow('local_openai_proxy', 'qwen-local');
+ assert.equal(result.ok, true);
+ assert.equal(result.contextWindow, 32768, `${label}: live n_ctx shrinks the 64k default`);
+ assert.equal(config().contextWindow, 32768);
+ assert.ok(urls.some((url) => url === 'http://127.0.0.1:8317/props?model=qwen-local'), `${label}: props probed at the proxy root`);
+ }
+
+ // 3. Test connection on a set-up card still at the old 16k: a known name wins.
+ {
+ const { mgr, config } = setup(async (url) => {
+ const u = String(url);
+ if (u.endsWith('/chat/completions')) return jsonOk({ choices: [{ message: { content: 'ok' } }] });
+ if (u.endsWith('/v1/models')) return jsonOk({ data: [{ id: 'gpt-5', object: 'model' }] });
+ return new Response('missing', { status: 404 });
+ }, { model: 'gpt-5', contextWindow: 16384 });
+ const result = await mgr.testProvider('local_openai_proxy');
+ assert.equal(result.ok, true, `${label}: proxy test ok`);
+ assert.equal(result.contextWindow, 128000, `${label}: known hosted model, capped at 128k`);
+ assert.equal(config().contextWindow, 128000);
+ }
+
+ // 4. Unknown model on a set-up 16k card: the 64k fallback replaces the old default.
+ {
+ const { mgr, config } = setup(async (url) => (String(url).endsWith('/v1/models')
+ ? jsonOk({ data: [{ id: 'house-model', object: 'model' }] })
+ : new Response('missing', { status: 404 })), { model: 'house-model', contextWindow: 16384 });
+ const result = await mgr.detectProviderContextWindow('local_openai_proxy', 'house-model');
+ assert.equal(result.contextWindow, 65536, `${label}: undetected window falls back to 64k`);
+ assert.equal(config().contextWindow, 65536);
+ }
+
+ // 5. A window WebBrain filled in for the previous model does not stick.
+ {
+ const { mgr, config } = setup(async () => new Response('missing', { status: 404 }), {
+ model: 'house-model', contextWindow: 128000, autoContextWindow: 128000,
+ });
+ const result = await mgr.detectProviderContextWindow('local_openai_proxy', 'house-model');
+ assert.equal(result.contextWindow, 65536, `${label}: auto 128k from a known model is replaceable`);
+ assert.equal(config().contextWindow, 65536);
+ }
+
+ // 6. A manual override is never enlarged by a name or the fallback...
+ {
+ const { mgr, config } = setup(async () => new Response('missing', { status: 404 }), {
+ model: 'claude-sonnet-4-5', contextWindow: 24576,
+ });
+ const result = await mgr.detectProviderContextWindow('local_openai_proxy', 'claude-sonnet-4-5');
+ assert.equal(result.ok, true);
+ assert.equal(result.contextWindow, undefined, `${label}: override kept`);
+ assert.equal(config().contextWindow, 24576);
+ }
+ // ...but a reported window may shrink it.
+ {
+ const { mgr, config } = setup(async (url) => (String(url).endsWith('/v1/models')
+ ? jsonOk({ data: [{ id: 'served', max_model_len: 8192 }] })
+ : new Response('missing', { status: 404 })), { model: 'served', contextWindow: 24576 });
+ const result = await mgr.detectProviderContextWindow('local_openai_proxy', 'served');
+ assert.equal(result.contextWindow, 8192, `${label}: reported card shrinks an override`);
+ assert.equal(config().contextWindow, 8192);
+ }
+
+ // 7. No model selected: nothing to detect.
+ {
+ const { mgr } = setup(async () => { throw new Error('no request without a model'); }, { model: '' });
+ assert.equal(await mgr._detectLocalContextWindow('local_openai_proxy', mgr.providers.get('local_openai_proxy')), null);
+ }
+ }
+ } finally {
+ globalThis.fetch = originalFetch;
+ if (originalChrome === undefined) delete globalThis.chrome;
+ else globalThis.chrome = originalChrome;
+ if (originalBrowser === undefined) delete globalThis.browser;
+ else globalThis.browser = originalBrowser;
+ }
+});
+
+test('ProviderManager load moves untouched Local OpenAI-compatible Proxy cards from 16k to 64k', async () => {
+ const originalChrome = globalThis.chrome;
+ const originalBrowser = globalThis.browser;
+ const makeRuntime = (storageData) => ({
+ storage: {
+ local: {
+ async get(keys) {
+ if (Array.isArray(keys)) return Object.fromEntries(keys.map((key) => [key, storageData[key]]));
+ if (typeof keys === 'string') return { [keys]: storageData[keys] };
+ return { ...storageData };
+ },
+ async set(patch) { Object.assign(storageData, patch); },
+ async remove(keys) { for (const key of Array.isArray(keys) ? keys : [keys]) delete storageData[key]; },
+ },
+ },
+ runtime: {
+ id: 'test-runtime',
+ getPlatformInfo(cb) {
+ const info = { os: 'test', arch: 'x64', nacl_arch: 'x64' };
+ if (typeof cb === 'function') cb(info);
+ return Promise.resolve(info);
+ },
+ },
+ });
+ try {
+ for (const [label, PM, runtimeKey] of [
+ ['chrome', ProviderManagerCh, 'chrome'],
+ ['firefox', ProviderManagerFx, 'browser'],
+ ]) {
+ const defaults = new PM()._defaultConfigs().local_openai_proxy;
+ const snapshot = { ...defaults, contextWindow: 16384 };
+ for (const [name, stored, expected] of [
+ ['untouched snapshot', { ...snapshot, configured: false }, 65536],
+ ['legacy snapshot without a configured marker', { ...snapshot }, 65536],
+ ['set-up card', { ...snapshot, configured: true, apiKey: 'strong-local-proxy-key', model: 'm' }, 16384],
+ ['legacy card with a key', { ...snapshot, apiKey: 'strong-local-proxy-key' }, 16384],
+ ['edited window', { ...snapshot, configured: false, contextWindow: 32768 }, 32768],
+ ]) {
+ const storageData = { webbrainDeviceGuid: '11111111-1111-4111-8111-111111111111', providers: { local_openai_proxy: stored } };
+ globalThis[runtimeKey] = makeRuntime(storageData);
+ const mgr = new PM();
+ await mgr.load();
+ assert.equal(mgr.providers.get('local_openai_proxy').config.contextWindow, expected, `${label}: ${name}`);
+ }
+ const fresh = new PM();
+ globalThis[runtimeKey] = makeRuntime({ webbrainDeviceGuid: '11111111-1111-4111-8111-111111111111' });
+ await fresh.load();
+ assert.equal(fresh.providers.get('local_openai_proxy').config.contextWindow, 65536, `${label}: new installs start at 64k`);
+ }
+ } finally {
+ if (originalChrome === undefined) delete globalThis.chrome;
+ else globalThis.chrome = originalChrome;
+ if (originalBrowser === undefined) delete globalThis.browser;
+ else globalThis.browser = originalBrowser;
+ }
+});
+
+test('Settings shows the 64k proxy context default as the field placeholder in both builds', () => {
+ for (const settingsRel of ['src/chrome/src/ui/settings.js', 'src/firefox/src/ui/settings.js']) {
+ const settings = fs.readFileSync(path.join(ROOT, settingsRel), 'utf8');
+ assert.match(settings, /const LOCAL_PROXY_CONTEXT_WINDOW_FIELD = \{\s*\.\.\.CONTEXT_WINDOW_FIELD,\s*placeholder: '65536',\s*\};/, `${settingsRel}: proxy placeholder`);
+ const block = settings.slice(settings.indexOf('local_openai_proxy: {'), settings.indexOf('\n },', settings.indexOf('local_openai_proxy: {')));
+ assert.match(block, /LOCAL_PROXY_CONTEXT_WINDOW_FIELD,/, `${settingsRel}: proxy card uses the 64k field`);
+ }
+});
+
test('Ollama launch handoff content script is shipped in both manifests', () => {
for (const manifestPath of ['src/chrome/manifest.json', 'src/firefox/manifest.json']) {
const manifest = JSON.parse(fs.readFileSync(path.join(ROOT, manifestPath), 'utf8'));
@@ -75302,7 +75524,7 @@ test('_defaultConfigs: generic local OpenAI-compatible proxy is safe and configu
assert.equal(config.providerName, 'local-openai-proxy');
assert.equal(config.model, '', `${label}: users must choose a proxy-exposed model`);
assert.equal(config.requiresModel, true, `${label}: proxy requests need an explicit model`);
- assert.equal(config.contextWindow, 16384, `${label}: proxy should inherit the conservative local context default`);
+ assert.equal(config.contextWindow, 65536, `${label}: proxy fronts hosted models, so its undetected fallback is 64k`);
assert.equal(config.apiKey, '', `${label}: no shared credential should ship`);
assert.equal(config.requiresApiKey, true, `${label}: proxy authentication must be required`);
assert.equal(config.supportsAskStreaming, true, `${label}: compatible proxy should use Ask streaming with fallback`);