Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(model-providers): accept equivalent effort metadata (#3004)

tiammomoc852f08848a0
diff --git a/packages/model-providers/src/__tests__/user-provider.test.ts b/packages/model-providers/src/__tests__/user-provider.test.ts
index dc4f8bd6a4..1a38a032e6 100644
--- a/packages/model-providers/src/__tests__/user-provider.test.ts
+++ b/packages/model-providers/src/__tests__/user-provider.test.ts
@@ -315,7 +315,121 @@ it('strips xd/ prefix to match registry effort metadata (entry.id ≠ custom id)
});
});
- it('falls back safely for ambiguous matches, missing target routes and invalid defaults', () => {
+ it.each(["gpt-5.6-sol", "gpt-5.6-terra"])(
+ "inherits equivalent Registry effort metadata across matching entries for %s",
+ (modelId) => {
+ const registry = structuredClone(BUNDLED_CATALOG.modelRegistry);
+ if (!registry) throw new Error("missing bundled model registry");
+ const baseEntry = registry.models.find(
+ (entry) => entry.id === `openai/${modelId}`,
+ );
+ if (!baseEntry) throw new Error(`missing ${modelId} registry entry`);
+ registry.models.push({
+ ...structuredClone(baseEntry),
+ id: `alternate/${modelId}`,
+ });
+
+ const provider = buildUserProvider(
+ {
+ id: "relay",
+ name: "Relay",
+ runtimes: {
+ codex: {
+ baseUrl: "https://relay.example/v1",
+ models: [{ id: modelId, name: modelId }],
+ },
+ },
+ },
+ { modelRegistry: registry },
+ );
+
+ expect(provider.models.codex?.[0]).toMatchObject({
+ efforts: ["low", "medium", "high", "xhigh", "max", "ultra"],
+ defaultEffort: "high",
+ });
+ },
+ );
+
+ it.each(["xd/gpt-5.6-sol", "chatgpt/gpt-5.6-sol"])(
+ "inherits equivalent Registry effort metadata after stripping the prefix from %s",
+ (modelId) => {
+ const registry = structuredClone(BUNDLED_CATALOG.modelRegistry);
+ if (!registry) throw new Error("missing bundled model registry");
+ const baseEntry = registry.models.find(
+ (entry) => entry.id === "openai/gpt-5.6-sol",
+ );
+ if (!baseEntry) throw new Error("missing gpt-5.6-sol registry entry");
+ const first = structuredClone(baseEntry);
+ first.id = "first/gpt-5.6-sol";
+ first.routes = first.routes
+ .filter((route) => route.agents.includes("codex"))
+ .map((route) => ({ ...route, modelId: "gpt-5.6-sol" }));
+ const second = structuredClone(first);
+ second.id = "second/gpt-5.6-sol";
+ registry.models = [first, second];
+
+ const provider = buildUserProvider(
+ {
+ id: "prefixed-relay",
+ name: "Prefixed Relay",
+ runtimes: {
+ codex: {
+ baseUrl: "https://relay.example/v1",
+ models: [{ id: modelId, name: modelId }],
+ },
+ },
+ },
+ { modelRegistry: registry },
+ );
+
+ expect(provider.models.codex?.[0]).toMatchObject({
+ efforts: ["low", "medium", "high", "xhigh", "max", "ultra"],
+ defaultEffort: "high",
+ });
+ },
+ );
+
+ it("rejects conflicting Registry effort metadata after prefix stripping", () => {
+ const registry = structuredClone(BUNDLED_CATALOG.modelRegistry);
+ if (!registry) throw new Error("missing bundled model registry");
+ const baseEntry = registry.models.find(
+ (entry) => entry.id === "openai/gpt-5.6-sol",
+ );
+ if (!baseEntry) throw new Error("missing gpt-5.6-sol registry entry");
+ const first = structuredClone(baseEntry);
+ first.id = "first/gpt-5.6-sol";
+ first.routes = first.routes
+ .filter((route) => route.agents.includes("codex"))
+ .map((route) => ({ ...route, modelId: "gpt-5.6-sol" }));
+ const second = structuredClone(first);
+ second.id = "second/gpt-5.6-sol";
+ second.perAgent = {
+ ...second.perAgent,
+ codex: { efforts: ["low", "medium", "high"], defaultEffort: "high" },
+ };
+ registry.models = [first, second];
+
+ const provider = buildUserProvider(
+ {
+ id: "conflicting-prefixed-relay",
+ name: "Conflicting Prefixed Relay",
+ runtimes: {
+ codex: {
+ baseUrl: "https://relay.example/v1",
+ models: [{ id: "xd/gpt-5.6-sol", name: "GPT-5.6-Sol" }],
+ },
+ },
+ },
+ { modelRegistry: registry },
+ );
+
+ expect(provider.models.codex?.[0]).toMatchObject({
+ efforts: ["low", "medium", "high", "xhigh", "max"],
+ defaultEffort: "high",
+ });
+ });
+
+ it('falls back safely for conflicting matches, missing target routes and invalid defaults', () => {
const registry = structuredClone(BUNDLED_CATALOG.modelRegistry);
if (!registry) throw new Error("missing bundled model registry");
const baseEntry = registry.models.find(
@@ -329,6 +443,10 @@ it('strips xd/ prefix to match registry effort metadata (entry.id ≠ custom id)
registry.models.push({
...structuredClone(baseEntry),
id: "alternate/gpt-5.6-sol",
+ perAgent: {
+ ...baseEntry.perAgent,
+ codex: { efforts: ["low", "medium", "high"], defaultEffort: "high" },
+ },
});
const ambiguous = buildUserProvider(
diff --git a/packages/model-providers/src/user-provider.ts b/packages/model-providers/src/user-provider.ts
index 5033f6f107..4c2a5be8c0 100644
--- a/packages/model-providers/src/user-provider.ts
+++ b/packages/model-providers/src/user-provider.ts
@@ -85,8 +85,35 @@ function toRegistryEffortMetadata(
return { efforts: [...efforts], defaultEffort };
}
+function consensusRegistryEffortMetadata(
+ entries: readonly ModelRegistry["models"][number][],
+ agent: AgentKind,
+): RegistryEffortMetadata | undefined {
+ const uniqueEntries = [
+ ...new Map(entries.map((entry) => [entry.id, entry])).values(),
+ ];
+ const metadata = uniqueEntries.map((entry) =>
+ toRegistryEffortMetadata(entry, agent),
+ );
+ const first = metadata[0];
+ if (
+ !first ||
+ metadata.some(
+ (value) =>
+ !value ||
+ value.defaultEffort !== first.defaultEffort ||
+ value.efforts.length !== first.efforts.length ||
+ value.efforts.some((effort, index) => effort !== first.efforts[index]),
+ )
+ ) {
+ return undefined;
+ }
+ return first;
+}
+
/**
- * 仅在模型能由当前 agent 的 Registry route 唯一识别时复用 effort 元数据。
+ * 仅在模型能由当前 agent 的 Registry route 唯一识别,或所有匹配
+ * 条目的 effort 元数据完全一致时复用该能力。
* 自定义 provider 的 id、model id 与路由保持原值;Pi 能力继续只认逐模型显式配置。
*/
function registryEffortMetadata(
@@ -104,11 +131,9 @@ function registryEffortMetadata(
(entry.id === modelId || route.modelId === modelId),
),
);
- const exactUnique = [
- ...new Map(exactMatches.map((entry) => [entry.id, entry])).values(),
- ];
- if (exactUnique.length === 1) return toRegistryEffortMetadata(exactUnique[0]!, agent);
- if (exactUnique.length > 1) return undefined; // ambiguous, don't strip
+ if (exactMatches.length > 0) {
+ return consensusRegistryEffortMetadata(exactMatches, agent);
+ }
// Stage 2 — prefix fallback: only when Stage 1 found nothing.
// Strip common provider prefixes so third-party custom API models
@@ -126,11 +151,7 @@ function registryEffortMetadata(
(stripped.has(entry.id) || stripped.has(route.modelId)),
),
);
- const fallbackUnique = [
- ...new Map(fallbackMatches.map((entry) => [entry.id, entry])).values(),
- ];
- if (fallbackUnique.length !== 1) return undefined;
- return toRegistryEffortMetadata(fallbackUnique[0]!, agent);
+ return consensusRegistryEffortMetadata(fallbackMatches, agent);
}
/** 固定 agent 顺序:保证派生出的 provider.agents / routing / models 顺序稳定。 */