























@@ -13,6 +13,8 @@ export type ResolvedModelRuntimePolicy = {
1313source?: ModelRuntimePolicySource;
1414};
151516+type ModelEntryMatchKind = "none" | "exact" | "provider-wildcard";
17+1618function hasRuntimePolicy(value: AgentRuntimePolicyConfig | undefined): boolean {
1719return Boolean(value?.id?.trim());
1820}
@@ -63,26 +65,41 @@ function modelEntryMatches(params: {
6365provider: string | undefined;
6466modelId: string;
6567}): boolean {
68+return modelEntryMatchKind(params) === "exact";
69+}
70+71+function modelEntryMatchKind(params: {
72+entry: Pick<ModelDefinitionConfig, "id">;
73+provider: string | undefined;
74+modelId: string;
75+}): ModelEntryMatchKind {
6676const entryId = params.entry.id.trim();
6777if (entryId === params.modelId) {
68-return true;
78+return "exact";
6979}
7080const slash = entryId.indexOf("/");
7181if (slash <= 0) {
72-return false;
82+return "none";
7383}
74-return (
75-normalizeProviderId(entryId.slice(0, slash)) === normalizeProviderId(params.provider ?? "") &&
76-entryId.slice(slash + 1).trim() === params.modelId
77-);
84+if (normalizeProviderId(entryId.slice(0, slash)) !== normalizeProviderId(params.provider ?? "")) {
85+return "none";
86+}
87+const entryModelId = entryId.slice(slash + 1).trim();
88+if (entryModelId === params.modelId) {
89+return "exact";
90+}
91+if (entryModelId === "*") {
92+return "provider-wildcard";
93+}
94+return "none";
7895}
799680-function modelKeyMatches(params: {
97+function modelKeyMatchKind(params: {
8198key: string;
8299provider: string | undefined;
83100modelId: string;
84-}): boolean {
85-return modelEntryMatches({
101+}): ModelEntryMatchKind {
102+return modelEntryMatchKind({
86103entry: { id: params.key },
87104provider: params.provider,
88105modelId: params.modelId,
@@ -95,6 +112,7 @@ function resolveAgentModelEntryRuntimePolicy(params: {
95112modelId?: string;
96113agentId?: string;
97114sessionKey?: string;
115+matchKind: Exclude<ModelEntryMatchKind, "none">;
98116}): ResolvedModelRuntimePolicy {
99117const modelId = normalizeModelIdForProvider(params.provider, params.modelId);
100118if (!params.config || !modelId) {
@@ -115,7 +133,7 @@ function resolveAgentModelEntryRuntimePolicy(params: {
115133for (const models of modelMaps) {
116134for (const [key, entry] of Object.entries(models ?? {})) {
117135if (
118-modelKeyMatches({ key, provider: params.provider, modelId }) &&
136+modelKeyMatchKind({ key, provider: params.provider, modelId }) === params.matchKind &&
119137hasRuntimePolicy(entry?.agentRuntime)
120138) {
121139return { policy: entry.agentRuntime, source: "model" };
@@ -146,7 +164,7 @@ export function resolveModelRuntimePolicy(params: {
146164agentId?: string;
147165sessionKey?: string;
148166}): ResolvedModelRuntimePolicy {
149-const agentModelPolicy = resolveAgentModelEntryRuntimePolicy(params);
167+const agentModelPolicy = resolveAgentModelEntryRuntimePolicy({ ...params, matchKind: "exact" });
150168if (agentModelPolicy.policy) {
151169return agentModelPolicy;
152170}
@@ -159,6 +177,13 @@ export function resolveModelRuntimePolicy(params: {
159177if (hasRuntimePolicy(modelConfig?.agentRuntime)) {
160178return { policy: modelConfig?.agentRuntime, source: "model" };
161179}
180+const agentWildcardModelPolicy = resolveAgentModelEntryRuntimePolicy({
181+ ...params,
182+matchKind: "provider-wildcard",
183+});
184+if (agentWildcardModelPolicy.policy) {
185+return agentWildcardModelPolicy;
186+}
162187if (hasRuntimePolicy(providerConfig?.agentRuntime)) {
163188return { policy: providerConfig?.agentRuntime, source: "provider" };
164189}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。