Auto-deduplicate agent shortname on join request approval

When approving an agent join request with a shortname already in use,
append a numeric suffix (e.g. "openclaw-2") instead of returning an error.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Dotta
2026-03-06 13:54:58 -06:00
parent d8f7c6bf81
commit 0b42045053
4 changed files with 1305 additions and 766 deletions

View File

@@ -165,6 +165,22 @@ export function hasAgentShortnameCollision(
});
}
export function deduplicateAgentName(
candidateName: string,
existingAgents: AgentShortnameRow[],
): string {
if (!hasAgentShortnameCollision(candidateName, existingAgents)) {
return candidateName;
}
for (let i = 2; i <= 100; i++) {
const suffixed = `${candidateName} ${i}`;
if (!hasAgentShortnameCollision(suffixed, existingAgents)) {
return suffixed;
}
}
return `${candidateName} ${Date.now()}`;
}
export function agentService(db: Db) {
function withUrlKey<T extends { id: string; name: string }>(row: T) {
return {

View File

@@ -1,5 +1,5 @@
export { companyService } from "./companies.js";
export { agentService } from "./agents.js";
export { agentService, deduplicateAgentName } from "./agents.js";
export { assetService } from "./assets.js";
export { projectService } from "./projects.js";
export { issueService, type IssueFilters } from "./issues.js";