fix: support progressive fallback for deeply nested model directories

Previously, modelToNode fallback only tried exact match then top-level
segment (e.g., "a/b/c" → "a"), skipping intermediate paths. Now tries
all parent paths progressively ("a/b/c" → "a/b" → "a"), fixing custom
nodes with longer nested directory structures.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Deep Mehta
2026-03-17 10:07:56 -07:00
parent a405a992af
commit fae8f2024a

View File

@@ -75,8 +75,8 @@ export const useModelToNodeStore = defineStore('modelToNode', () => {
/**
* Find providers for modelType with hierarchical fallback.
* Tries exact match first, then falls back to top-level segment (e.g., "parent/child" → "parent").
* Note: Only falls back one level; "a/b/c" tries "a/b/c" then "a", not "a/b".
* Tries exact match first, then progressively shorter parent paths.
* e.g., "a/b/c" tries "a/b/c" → "a/b" → "a".
*/
function findProvidersWithFallback(
modelType: string
@@ -88,12 +88,13 @@ export const useModelToNodeStore = defineStore('modelToNode', () => {
const exactMatch = modelToNodeMap.value[modelType]
if (exactMatch && exactMatch.length > 0) return exactMatch
const topLevel = modelType.split('/')[0]
if (topLevel === modelType) return undefined
const fallback = modelToNodeMap.value[topLevel]
if (fallback && fallback.length > 0) return fallback
// Try progressively shorter parent paths
const segments = modelType.split('/')
for (let i = segments.length - 1; i >= 1; i--) {
const parentPath = segments.slice(0, i).join('/')
const fallback = modelToNodeMap.value[parentPath]
if (fallback && fallback.length > 0) return fallback
}
return undefined
}