2026-03-13 10:55:51 +09:00
|
|
|
const PARENTHETICAL_SUFFIX_PATTERN = /\s*(\([^)]*\)\s*)+$/u
|
2026-04-07 10:08:04 +09:00
|
|
|
const DASH_SUFFIX_PATTERN = /\s+-\s+.+$/u
|
2026-04-06 18:07:26 +09:00
|
|
|
const ZERO_WIDTH_CHARACTERS_PATTERN = /[\u200B\u200C\u200D\uFEFF]/g
|
2026-03-13 10:55:51 +09:00
|
|
|
|
|
|
|
|
export function normalizeProtectedAgentName(agentName: string): string {
|
2026-03-13 14:09:36 +09:00
|
|
|
return agentName
|
2026-04-06 18:07:26 +09:00
|
|
|
.replace(ZERO_WIDTH_CHARACTERS_PATTERN, "")
|
2026-03-13 14:09:36 +09:00
|
|
|
.trim()
|
|
|
|
|
.toLowerCase()
|
|
|
|
|
.replace(PARENTHETICAL_SUFFIX_PATTERN, "")
|
2026-04-07 10:08:04 +09:00
|
|
|
.replace(DASH_SUFFIX_PATTERN, "")
|
2026-03-13 14:09:36 +09:00
|
|
|
.replace(/[-_]/g, "")
|
|
|
|
|
.trim()
|
2026-03-13 10:55:51 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function createProtectedAgentNameSet(agentNames: Iterable<string>): Set<string> {
|
|
|
|
|
const protectedAgentNames = new Set<string>()
|
|
|
|
|
|
|
|
|
|
for (const agentName of agentNames) {
|
|
|
|
|
const normalizedAgentName = normalizeProtectedAgentName(agentName)
|
|
|
|
|
if (normalizedAgentName.length === 0) continue
|
|
|
|
|
|
|
|
|
|
protectedAgentNames.add(normalizedAgentName)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return protectedAgentNames
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function filterProtectedAgentOverrides<TAgent>(
|
|
|
|
|
agents: Record<string, TAgent>,
|
|
|
|
|
protectedAgentNames: ReadonlySet<string>,
|
|
|
|
|
): Record<string, TAgent> {
|
|
|
|
|
return Object.fromEntries(
|
|
|
|
|
Object.entries(agents).filter(([agentName]) => {
|
|
|
|
|
return !protectedAgentNames.has(normalizeProtectedAgentName(agentName))
|
|
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
}
|