Repository navigation
feat(AIC-3439): let wildcard handlers accept only named providers #111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,7 +13,7 @@ import type { | |
| StreamEvent, | ||
| VariationMeta, | ||
| } from './types.js'; | ||
| import { normalizeMode, parseJSONWithPossibleFences } from './utils.js'; | ||
| import { coversProviderName, normalizeMode, parseJSONWithPossibleFences, selectModeHandler } from './utils.js'; | ||
|
|
||
| function resolveOutputFormatResponse(rawResponse: unknown, outputFormat: Record<string, unknown> | undefined): unknown { | ||
| if (!outputFormat) return rawResponse ?? ''; | ||
|
|
@@ -42,13 +42,10 @@ function selectHandler( | |
| if (!provider) throw new Error('Provider not found'); | ||
| const normalizedMode = normalizeMode(mode); | ||
|
|
||
| const exact = resolvedHandlers?.find((h) => h.providesFor?.[0] === provider && h.providesFor?.[1] === normalizedMode); | ||
| if (exact) return exact; | ||
| const chosen = resolvedHandlers ? selectModeHandler(resolvedHandlers, provider, normalizedMode) : undefined; | ||
| if (chosen) return chosen; | ||
|
|
||
| const wildcard = resolvedHandlers?.find((h) => h.providesFor?.[0] === '*' && h.providesFor?.[1] === normalizedMode); | ||
| if (wildcard) return wildcard; | ||
|
|
||
| if (!resolvedHandlers?.some((h) => h.providesFor?.[0] === provider || h.providesFor?.[0] === '*')) { | ||
| if (!resolvedHandlers?.some((handler) => coversProviderName(handler, provider))) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I put back the old |
||
| throw new Error(`Handler for provider ${provider} not found`); | ||
| } | ||
| throw new Error(`Handler for provider ${provider} with mode ${normalizedMode} not found`); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,7 +26,7 @@ import { | |
| type TraverseVisitor, | ||
| type VariationMeta, | ||
| } from './types.js'; | ||
| import { endSpanOnce, normalizeMode } from './utils.js'; | ||
| import { endSpanOnce, normalizeMode, selectModeHandler } from './utils.js'; | ||
|
|
||
| // Cycle protection: cap how many BFS layers a traversal will expand. | ||
| const MAX_TRAVERSAL_DEPTH = 100; | ||
|
|
@@ -54,16 +54,19 @@ const selectHandler = (config: AiConfigRep, meta: VariationMeta, handlers: Provi | |
|
|
||
| const mode = normalizeMode(meta.mode); | ||
|
|
||
| const exact = handlers.find((h) => h.providesFor?.[0] === provider && h.providesFor?.[1] === mode); | ||
| if (exact) return exact; | ||
|
|
||
| const wildcard = handlers.find((h) => h.providesFor?.[0] === '*' && h.providesFor?.[1] === mode); | ||
| if (wildcard) return wildcard; | ||
| const chosen = selectModeHandler(handlers, provider, mode); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Node selection is right. The |
||
| if (chosen) return chosen; | ||
|
|
||
| const byProvider = handlers.find((h) => h.providesFor?.[0] === provider); | ||
| if (byProvider) return byProvider; | ||
|
|
||
| if (handlers.length === 1) return handlers[0]; | ||
| if (handlers.length === 1) { | ||
| const only = handlers[0]; | ||
| if (only.providers !== undefined && !only.providers.includes(provider)) { | ||
| throw new Error(`Handler for provider ${provider} not found`); | ||
| } | ||
| return only; | ||
| } | ||
|
|
||
| throw new Error(`Handler for provider ${provider} not found`); | ||
| }; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test only covers the OpenAI half of #39's "unscoped wildcard is the fallback" bullet. If I change
bestWildcardtoreturn unscoped ?? bestScoped?.handler, so unscoped beats scoped, all 445 client tests still pass. Could you add the Bedrock half:[scoped(['Bedrock']), unscoped]with a Bedrock variation should run the scoped handler?