mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 10:41:25 +00:00
refactor(auto-reply): share unique model catalog insertion
This commit is contained in:
@@ -24,6 +24,31 @@ import {
|
|||||||
import type { InlineDirectives } from "./directive-handling.parse.js";
|
import type { InlineDirectives } from "./directive-handling.parse.js";
|
||||||
import { type ModelDirectiveSelection, resolveModelDirectiveSelection } from "./model-selection.js";
|
import { type ModelDirectiveSelection, resolveModelDirectiveSelection } from "./model-selection.js";
|
||||||
|
|
||||||
|
function pushUniqueCatalogEntry(params: {
|
||||||
|
keys: Set<string>;
|
||||||
|
out: ModelPickerCatalogEntry[];
|
||||||
|
provider: string;
|
||||||
|
id: string;
|
||||||
|
name?: string;
|
||||||
|
fallbackNameToId: boolean;
|
||||||
|
}) {
|
||||||
|
const provider = normalizeProviderId(params.provider);
|
||||||
|
const id = String(params.id ?? "").trim();
|
||||||
|
if (!provider || !id) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const key = modelKey(provider, id);
|
||||||
|
if (params.keys.has(key)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
params.keys.add(key);
|
||||||
|
params.out.push({
|
||||||
|
provider,
|
||||||
|
id,
|
||||||
|
name: params.fallbackNameToId ? (params.name ?? id) : params.name,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function buildModelPickerCatalog(params: {
|
function buildModelPickerCatalog(params: {
|
||||||
cfg: OpenClawConfig;
|
cfg: OpenClawConfig;
|
||||||
defaultProvider: string;
|
defaultProvider: string;
|
||||||
@@ -42,17 +67,14 @@ function buildModelPickerCatalog(params: {
|
|||||||
const keys = new Set<string>();
|
const keys = new Set<string>();
|
||||||
|
|
||||||
const pushRef = (ref: { provider: string; model: string }, name?: string) => {
|
const pushRef = (ref: { provider: string; model: string }, name?: string) => {
|
||||||
const provider = normalizeProviderId(ref.provider);
|
pushUniqueCatalogEntry({
|
||||||
const id = String(ref.model ?? "").trim();
|
keys,
|
||||||
if (!provider || !id) {
|
out,
|
||||||
return;
|
provider: ref.provider,
|
||||||
}
|
id: ref.model,
|
||||||
const key = modelKey(provider, id);
|
name,
|
||||||
if (keys.has(key)) {
|
fallbackNameToId: true,
|
||||||
return;
|
});
|
||||||
}
|
|
||||||
keys.add(key);
|
|
||||||
out.push({ provider, id, name: name ?? id });
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const pushRaw = (raw?: string) => {
|
const pushRaw = (raw?: string) => {
|
||||||
@@ -99,17 +121,14 @@ function buildModelPickerCatalog(params: {
|
|||||||
const out: ModelPickerCatalogEntry[] = [];
|
const out: ModelPickerCatalogEntry[] = [];
|
||||||
|
|
||||||
const push = (entry: ModelPickerCatalogEntry) => {
|
const push = (entry: ModelPickerCatalogEntry) => {
|
||||||
const provider = normalizeProviderId(entry.provider);
|
pushUniqueCatalogEntry({
|
||||||
const id = String(entry.id ?? "").trim();
|
keys,
|
||||||
if (!provider || !id) {
|
out,
|
||||||
return;
|
provider: entry.provider,
|
||||||
}
|
id: String(entry.id ?? ""),
|
||||||
const key = modelKey(provider, id);
|
name: entry.name,
|
||||||
if (keys.has(key)) {
|
fallbackNameToId: false,
|
||||||
return;
|
});
|
||||||
}
|
|
||||||
keys.add(key);
|
|
||||||
out.push({ provider, id, name: entry.name });
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const hasAllowlist = Object.keys(params.cfg.agents?.defaults?.models ?? {}).length > 0;
|
const hasAllowlist = Object.keys(params.cfg.agents?.defaults?.models ?? {}).length > 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user