mirror of
https://github.com/OpenRouterTeam/spawn.git
synced 2026-05-09 19:49:58 +00:00
refactor: deduplicate resolveAgentKey/resolveCloudKey into shared resolveEntityKey (#481)
Agent: complexity-hunter Co-authored-by: A <6723574+louisgv@users.noreply.github.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
5851a9ce7b
commit
7fa9325683
1 changed files with 13 additions and 20 deletions
|
|
@ -137,37 +137,30 @@ export function findClosestKeyByNameOrKey(
|
|||
}
|
||||
|
||||
/**
|
||||
* Resolve user input to a valid agent key.
|
||||
* Resolve user input to a valid entity key (agent or cloud).
|
||||
* Tries: exact key -> case-insensitive key -> display name match (case-insensitive).
|
||||
* Returns the key if found, or null.
|
||||
*/
|
||||
export function resolveAgentKey(manifest: Manifest, input: string): string | null {
|
||||
if (manifest.agents[input]) return input;
|
||||
function resolveEntityKey(manifest: Manifest, input: string, kind: "agent" | "cloud"): string | null {
|
||||
const collection = getEntityCollection(manifest, kind);
|
||||
if (collection[input]) return input;
|
||||
const keys = getEntityKeys(manifest, kind);
|
||||
const lower = input.toLowerCase();
|
||||
for (const key of agentKeys(manifest)) {
|
||||
for (const key of keys) {
|
||||
if (key.toLowerCase() === lower) return key;
|
||||
}
|
||||
for (const key of agentKeys(manifest)) {
|
||||
if (manifest.agents[key].name.toLowerCase() === lower) return key;
|
||||
for (const key of keys) {
|
||||
if (collection[key].name.toLowerCase() === lower) return key;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve user input to a valid cloud key.
|
||||
* Tries: exact key -> case-insensitive key -> display name match (case-insensitive).
|
||||
* Returns the key if found, or null.
|
||||
*/
|
||||
export function resolveAgentKey(manifest: Manifest, input: string): string | null {
|
||||
return resolveEntityKey(manifest, input, "agent");
|
||||
}
|
||||
|
||||
export function resolveCloudKey(manifest: Manifest, input: string): string | null {
|
||||
if (manifest.clouds[input]) return input;
|
||||
const lower = input.toLowerCase();
|
||||
for (const key of cloudKeys(manifest)) {
|
||||
if (key.toLowerCase() === lower) return key;
|
||||
}
|
||||
for (const key of cloudKeys(manifest)) {
|
||||
if (manifest.clouds[key].name.toLowerCase() === lower) return key;
|
||||
}
|
||||
return null;
|
||||
return resolveEntityKey(manifest, input, "cloud");
|
||||
}
|
||||
|
||||
interface EntityDef { label: string; labelPlural: string; listCmd: string; opposite: string }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue