mirror of
https://github.com/OpenRouterTeam/spawn.git
synced 2026-05-10 20:39:59 +00:00
refactor: eliminate 7 identical agents.ts boilerplate files (#2088)
* refactor: eliminate 7 identical agents.ts boilerplate files Adds createCloudAgents() factory to shared/agent-setup.ts, reducing each cloud's agents.ts from 16-line copy-paste to a single call. Net reduction of 49 lines across 9 files. Fixes #2078 Agent: complexity-hunter Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * chore: apply biome formatting --------- Co-authored-by: B <6723574+louisgv@users.noreply.github.com> Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
b755c6966c
commit
608e8b4bdd
8 changed files with 36 additions and 70 deletions
|
|
@ -1,16 +1,9 @@
|
|||
// aws/agents.ts — AWS Lightsail agent configs (thin wrapper over shared)
|
||||
|
||||
import { runServer, uploadFile } from "./aws";
|
||||
import { createAgents, resolveAgent as _resolveAgent } from "../shared/agent-setup";
|
||||
import type { AgentConfig } from "../shared/agents";
|
||||
import { createCloudAgents } from "../shared/agent-setup";
|
||||
|
||||
const runner = {
|
||||
export const { agents, resolveAgent } = createCloudAgents({
|
||||
runServer,
|
||||
uploadFile,
|
||||
};
|
||||
|
||||
export const agents = createAgents(runner);
|
||||
|
||||
export function resolveAgent(name: string): AgentConfig {
|
||||
return _resolveAgent(agents, name);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,16 +1,9 @@
|
|||
// daytona/agents.ts — Daytona agent configs (thin wrapper over shared)
|
||||
|
||||
import { runServer, uploadFile } from "./daytona";
|
||||
import { createAgents, resolveAgent as _resolveAgent } from "../shared/agent-setup";
|
||||
import type { AgentConfig } from "../shared/agents";
|
||||
import { createCloudAgents } from "../shared/agent-setup";
|
||||
|
||||
const runner = {
|
||||
export const { agents, resolveAgent } = createCloudAgents({
|
||||
runServer,
|
||||
uploadFile,
|
||||
};
|
||||
|
||||
export const agents = createAgents(runner);
|
||||
|
||||
export function resolveAgent(name: string): AgentConfig {
|
||||
return _resolveAgent(agents, name);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,16 +1,9 @@
|
|||
// digitalocean/agents.ts — DigitalOcean agent configs (thin wrapper over shared)
|
||||
|
||||
import { runServer, uploadFile } from "./digitalocean";
|
||||
import { createAgents, resolveAgent as _resolveAgent } from "../shared/agent-setup";
|
||||
import type { AgentConfig } from "../shared/agents";
|
||||
import { createCloudAgents } from "../shared/agent-setup";
|
||||
|
||||
const runner = {
|
||||
export const { agents, resolveAgent } = createCloudAgents({
|
||||
runServer,
|
||||
uploadFile,
|
||||
};
|
||||
|
||||
export const agents = createAgents(runner);
|
||||
|
||||
export function resolveAgent(name: string): AgentConfig {
|
||||
return _resolveAgent(agents, name);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,16 +1,9 @@
|
|||
// gcp/agents.ts — GCP Compute Engine agent configs (thin wrapper over shared)
|
||||
|
||||
import { runServer, uploadFile } from "./gcp";
|
||||
import { createAgents, resolveAgent as _resolveAgent } from "../shared/agent-setup";
|
||||
import type { AgentConfig } from "../shared/agents";
|
||||
import { createCloudAgents } from "../shared/agent-setup";
|
||||
|
||||
const runner = {
|
||||
export const { agents, resolveAgent } = createCloudAgents({
|
||||
runServer,
|
||||
uploadFile,
|
||||
};
|
||||
|
||||
export const agents = createAgents(runner);
|
||||
|
||||
export function resolveAgent(name: string): AgentConfig {
|
||||
return _resolveAgent(agents, name);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,16 +1,9 @@
|
|||
// hetzner/agents.ts — Hetzner Cloud agent configs (thin wrapper over shared)
|
||||
|
||||
import { runServer, uploadFile } from "./hetzner";
|
||||
import { createAgents, resolveAgent as _resolveAgent } from "../shared/agent-setup";
|
||||
import type { AgentConfig } from "../shared/agents";
|
||||
import { createCloudAgents } from "../shared/agent-setup";
|
||||
|
||||
const runner = {
|
||||
export const { agents, resolveAgent } = createCloudAgents({
|
||||
runServer,
|
||||
uploadFile,
|
||||
};
|
||||
|
||||
export const agents = createAgents(runner);
|
||||
|
||||
export function resolveAgent(name: string): AgentConfig {
|
||||
return _resolveAgent(agents, name);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,16 +1,9 @@
|
|||
// local/agents.ts — Local machine agent configs (thin wrapper over shared)
|
||||
|
||||
import { runLocal, uploadFile } from "./local";
|
||||
import { createAgents, resolveAgent as _resolveAgent } from "../shared/agent-setup";
|
||||
import type { AgentConfig } from "../shared/agents";
|
||||
import { createCloudAgents } from "../shared/agent-setup";
|
||||
|
||||
const runner = {
|
||||
export const { agents, resolveAgent } = createCloudAgents({
|
||||
runServer: runLocal,
|
||||
uploadFile: async (l: string, r: string) => uploadFile(l, r),
|
||||
};
|
||||
|
||||
export const agents = createAgents(runner);
|
||||
|
||||
export function resolveAgent(name: string): AgentConfig {
|
||||
return _resolveAgent(agents, name);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -557,3 +557,18 @@ export function resolveAgent(agents: Record<string, AgentConfig>, name: string):
|
|||
}
|
||||
return agent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory that creates agents + resolveAgent for a given CloudRunner.
|
||||
* Replaces the identical 16-line boilerplate in each cloud's agents.ts.
|
||||
*/
|
||||
export function createCloudAgents(runner: CloudRunner): {
|
||||
agents: Record<string, AgentConfig>;
|
||||
resolveAgent: (name: string) => AgentConfig;
|
||||
} {
|
||||
const agentMap = createAgents(runner);
|
||||
return {
|
||||
agents: agentMap,
|
||||
resolveAgent: (name: string) => resolveAgent(agentMap, name),
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,9 @@
|
|||
// sprite/agents.ts — Sprite agent configs (thin wrapper over shared)
|
||||
|
||||
import { runSprite, uploadFileSprite } from "./sprite";
|
||||
import { createAgents, resolveAgent as _resolveAgent } from "../shared/agent-setup";
|
||||
import type { AgentConfig } from "../shared/agents";
|
||||
import { createCloudAgents } from "../shared/agent-setup";
|
||||
|
||||
const runner = {
|
||||
export const { agents, resolveAgent } = createCloudAgents({
|
||||
runServer: runSprite,
|
||||
uploadFile: uploadFileSprite,
|
||||
};
|
||||
|
||||
export const agents = createAgents(runner);
|
||||
|
||||
export function resolveAgent(name: string): AgentConfig {
|
||||
return _resolveAgent(agents, name);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue