Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions open-sse/services/combo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import type { RoutingHint } from "./manifestAdapter";
import type { CompressionMode } from "./compression/types.ts";
import { getModelContextLimit } from "../../src/lib/modelCapabilities";
import { getProviderConnections } from "../../src/lib/db/providers";
import { getProviderModels } from "../config/providerModels.ts";
import {
getComboModelString,
getComboStepTarget,
Expand Down Expand Up @@ -2983,6 +2984,30 @@ export async function handleComboChat({
);
// eligibleTargets intentionally unchanged — same fallback contract as tool-calling filter
}

if (!Array.isArray(autoConfigSource?.candidatePool)) {
try {
const allConnections = await getProviderConnections({ isActive: true });
const providerIds = [...new Set(allConnections.map((c) => c.provider))];
for (const providerId of providerIds) {
const providerModels = getProviderModels(providerId);
for (const model of providerModels) {
const modelStr = `${providerId}/${model.id}`;
if (!eligibleTargets.some((t) => t.modelStr === modelStr)) {
eligibleTargets.push({
provider: providerId,
model: model.id,
modelStr,
weight: 1,
connectionId: undefined,
apiKeyId: undefined,
});
}
}
}
} catch {
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

Critical ReferenceError & Missing Target Fields

There are two major issues in this block:

  1. Temporal Dead Zone (TDZ) ReferenceError: autoConfigSource is referenced on line 2988 before it is declared on line 3026. This will throw a runtime ReferenceError whenever this block is executed.
  2. Incomplete ResolvedComboTarget Structure: The dynamically added targets pushed to eligibleTargets are missing critical fields required by the ResolvedComboTarget type (such as kind, stepId, executionKey, providerId, and label). This will cause issues during candidate scoring and deduplication (e.g., target.executionKey will be undefined, filtering them out completely in scoreAutoTargets).

To fix both issues, resolve the configuration locally using a different variable name (to avoid shadowing/TDZ conflicts) and construct a fully-formed ResolvedComboTarget object.

      const localAutoConfig =
        combo?.autoConfig ||
        (isRecord(combo?.config?.auto) ? combo.config.auto : null) ||
        combo?.config ||
        {};

      if (!Array.isArray(localAutoConfig?.candidatePool)) {
        try {
          const allConnections = await getProviderConnections({ isActive: true });
          const providerIds = [...new Set(allConnections.map((c) => c.provider))];
          for (const providerId of providerIds) {
            const providerModels = getProviderModels(providerId);
            for (const model of providerModels) {
              const modelStr = `${providerId}/${model.id}`;
              if (!eligibleTargets.some((t) => t.modelStr === modelStr)) {
                eligibleTargets.push({
                  kind: "model",
                  stepId: modelStr,
                  executionKey: modelStr,
                  provider: providerId,
                  model: model.id,
                  modelStr,
                  weight: 1,
                  connectionId: null,
                  providerId: providerId,
                  label: null,
                });
              }
            }
          }
        } catch {
        }
      }

}

const prompt = extractPromptForIntent(body);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default function StudioConfigPane({ configState, setConfigState }: Studio
const { provider, setProvider, providerOptions, loading: loadingProviders } = useProviderOptions(
configState.provider ?? ""
);
const { availableModels, loading: loadingModels } = useAvailableModels();
const { availableModels, loading: loadingModels } = useAvailableModels(provider || undefined);

function update<K extends keyof ConfigState>(key: K, value: ConfigState[K]) {
setConfigState({ ...configState, [key]: value });
Expand Down Expand Up @@ -125,6 +125,7 @@ export default function StudioConfigPane({ configState, setConfigState }: Studio
onChange={(e) => {
setProvider(e.target.value);
update("provider", e.target.value);
update("model", "");
}}
disabled={loadingProviders}
className="w-full text-xs bg-surface border border-border rounded px-2 py-1.5 focus:outline-none focus:ring-1 focus:ring-primary text-text-main"
Expand Down
4 changes: 3 additions & 1 deletion src/app/(dashboard)/dashboard/providers/providerPageUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ export function filterConfiguredProviderEntries<TProvider>(
let filtered = entries;

if (showConfiguredOnly) {
filtered = filtered.filter((entry) => Number(entry.stats?.total || 0) > 0);
filtered = filtered.filter(
(entry) => entry.toggleAuthType === "no-auth" || Number(entry.stats?.total || 0) > 0
);
}

if (showFreeOnly) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ const FORMAT_MODEL_PREFIXES = {
* pickModelForFormat: (format: string) => string
* }}
*/
export function useAvailableModels() {
export function useAvailableModels(provider?: string) {
const [model, setModel] = useState("");
const [availableModels, setAvailableModels] = useState([]);
const [allModels, setAllModels] = useState<string[]>([]);
const [loading, setLoading] = useState(true);

useEffect(() => {
Expand All @@ -36,16 +36,20 @@ export function useAvailableModels() {
const res = await fetch("/api/v1/models");
const data = await res.json();
const models = (data.data || []).map((m) => m.id).sort((a, b) => compareTr(a, b));
setAvailableModels(models);
setAllModels(models);
} catch {
setAvailableModels([]);
setAllModels([]);
} finally {
setLoading(false);
}
};
fetchModels();
}, []);

const availableModels = provider
? allModels.filter((m) => m.startsWith(`${provider}/`) || m === provider)
: allModels;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Unstable Reference for availableModels

When provider is truthy, availableModels is recalculated as a new array reference on every single render. Since pickModelForFormat depends on availableModels in its dependency array, it will also be recreated on every render, potentially causing unnecessary re-renders in child components.

Wrapping this calculation in useMemo ensures reference stability.

Note: You will need to add useMemo to the React imports at the top of this file.

  const availableModels = useMemo(() => {
    return provider
      ? allModels.filter((m) => m.startsWith(`${provider}/`) || m === provider)
      : allModels;
  }, [allModels, provider]);


/**
* Pick the best model for a given format from the available models.
* Returns the first model matching the format prefixes, or the first available model.
Expand Down