fix(ollama): route models by advertised capability (#11088)

Landed with the design call resolved per the owner's pick — **option 1**: the synced store is now endpoint-agnostic (persistDiscoveredModels and managedModelImport no longer drop non-chat models at write time), and chat selectability moved to read time (auto-pool expansion in autoStrategy applies filterChatSelectableModels; the models-route projection already had its chatOnly filter). Your discovery test now passes end-to-end (3/3): /api/show capabilities persist per connection and image/embedding requests route through the advertising host.

Reconciliation notes: conflicted areas merged onto the current tip (adobe discovery import, requestedModel preflight signature, resolvedProvider fast-path coexists with the synced-route override — explicit resolution wins); carried base-red drains (#10055 memoization, #11071 test variants) dropped as already-landed; the managed-model-import exclusion test was propagated to the new contract (image/video models persist; the read filter still hides them from chat pickers — pinned by a new assertion). Full battery: 205/206 focused (the one red is a confirmed periodic-timer timing flake on the loaded devbox — 20/20 isolated), autoCombo vitest 30/30, combo suites 46/46, gates + typecheck clean.

Thank you @yourspraveen — the capability probe + routing design was right; it just needed the store contract opened up. Fixes #11087.
This commit is contained in:
Praveen K Palaniswamy
2026-08-23 10:45:01 -04:00
committed by GitHub
parent c68cda7dfb
commit 65e81158ab
5094 changed files with 564668 additions and 80301 deletions

View File

@@ -67,21 +67,76 @@ export function patchJsonManifestFile(filePath, basePath) {
}
const BASE_PATH_LITERAL_RE =
/basePath\s*:\s*(?:""|''|`{2})|basePath\s*:\s*void 0|"basePath"\s*:\s*""/g;
/(?:basePath|assetPrefix)\s*:\s*(?:""|''|``)|(?:basePath|assetPrefix)\s*:\s*void 0|"(?:basePath|assetPrefix)"\s*:\s*""|"NEXT_PUBLIC_OMNIROUTE_BASE_PATH"\s*:\s*""|NEXT_PUBLIC_OMNIROUTE_BASE_PATH\s*:\s*""/g;
/**
* Rewrite the bare config literals Next bakes into the standalone output:
* - `basePath` (routing + server-rendered links) — the original scope;
* - `assetPrefix` (Next 16 app-router renders SSR asset URLs from
* `assetPrefix` ALONE — basePath only affects routing, so a subpath
* deploy must mirror it or every `/_next/static` shell reference 404s);
* - the `NEXT_PUBLIC_OMNIROUTE_BASE_PATH` env mirror in the inline
* nextConfig (server.js) so server-side env reads stay consistent.
*
* @param {string} content
* @param {string} basePath
*/
export function patchBasePathLiterals(content, basePath) {
const escaped = basePath.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
return content.replace(BASE_PATH_LITERAL_RE, (match) => {
if (match.startsWith('"basePath"')) return `"basePath":"${escaped}"`;
if (match.includes("void 0")) return `basePath:"${escaped}"`;
return `basePath:"${escaped}"`;
if (match.startsWith('"NEXT_PUBLIC_OMNIROUTE_BASE_PATH"')) {
return `"NEXT_PUBLIC_OMNIROUTE_BASE_PATH":"${escaped}"`;
}
if (match.startsWith("NEXT_PUBLIC_OMNIROUTE_BASE_PATH")) {
return `NEXT_PUBLIC_OMNIROUTE_BASE_PATH:"${escaped}"`;
}
if (match.startsWith('"')) {
// `"basePath":""` / `"assetPrefix":""` (JSON-ish inline config)
const key = match.slice(1, match.indexOf('"', 1));
return `"${key}":"${escaped}"`;
}
// `basePath:""` / `basePath:void 0` / `assetPrefix:""` (minified code)
const key = match.slice(0, match.indexOf(":")).trim();
return `${key}:"${escaped}"`;
});
}
/**
* Turbopack's client `process` shim ships an empty env object (`.env={}`).
* Next 16's client code reads NEXT_PUBLIC_* / OMNIROUTE_BASE_PATH from it at
* runtime, so without this the client never learns the subpath and the
* dashboard's fetch/EventSource rewriting (basePathFetch) silently stays on
* the root path. Populate the two keys the app reads.
*
* @param {string} content
* @param {string} basePath
*/
export function patchProcessEnvShim(content, basePath) {
const escaped = basePath.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
return content.replace(/\.env=\{\}/g, () => {
const keys = `OMNIROUTE_BASE_PATH:"${escaped}",NEXT_PUBLIC_OMNIROUTE_BASE_PATH:"${escaped}"`;
return `.env={${keys}}`;
});
}
/**
* Rewrite baked absolute asset URLs (`"/_next/static/..."`) to the subpath.
* Covers the client-reference-manifest chunk lists (they are serialized into
* the RSC flight payload verbatim) and the client/server chunk media imports
* — every `/ _next/static` reference must be prefixed because the standalone
* server only serves assets under basePath.
*
* @param {string} content
* @param {string} basePath
*/
export function patchBakedAssetUrls(content, basePath) {
const escaped = basePath.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
return content.replace(
/(["'`])\/_next\/static/g,
(_match, quote) => `${quote}${escaped}/_next/static`
);
}
/**
* @param {string} rootDir
* @param {string} basePath
@@ -98,9 +153,12 @@ function walkAndPatchTextFiles(rootDir, basePath) {
stack.push(full);
continue;
}
if (!/\.(?:js|json|cjs|mjs)$/.test(entry.name)) continue;
if (!/\.(?:js|json|cjs|mjs|html)$/.test(entry.name)) continue;
const before = fs.readFileSync(full, "utf8");
const after = patchBasePathLiterals(before, basePath);
const after = [patchBasePathLiterals, patchProcessEnvShim, patchBakedAssetUrls].reduce(
(content, patch) => patch(content, basePath),
before
);
if (after !== before) {
fs.writeFileSync(full, after);
patchedFiles += 1;