donobu
Version:
Create browser automations with an LLM agent and replay them as Playwright scripts.
84 lines • 3.63 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AgentsApi = void 0;
const v4_1 = require("zod/v4");
const InvalidParamValueException_1 = require("../exceptions/InvalidParamValueException");
const DonobuAgentType_1 = require("../models/DonobuAgentType");
/**
* API controller for managing the mapping between Donobu agents and GPT configurations.
*
* The AgentsApi provides endpoints for associating Donobu agents (like 'flow-runner')
* with specific GPT configurations. This mapping system allows flows to use different
* AI models and configurations based on their requirements. The API maintains a
* many-to-one relationship where multiple agents can reference the same GPT configuration,
* but each agent can only have one active configuration at a time.
*
* **Agent Types:**
* - `flow-runner`: The primary agent used for autonomous flow execution
*
* **Key Features:**
* - Validates GPT configuration existence before assignment
* - Supports null assignments to unlink agents from configurations
* - Provides both individual and bulk retrieval of agent mappings
* - Maintains referential integrity with the GPT configurations system
*/
class AgentsApi {
constructor(agentsManager) {
this.agentsManager = agentsManager;
}
/**
* Sets the GPT configuration for a specific Donobu agent.
*
* This endpoint allows updating the GPT configuration associated with a particular
* agent. The operation validates that:
* 1. The agent name is a valid Donobu agent type
* 2. The GPT configuration exists (if non-null)
* 3. The assignment can be persisted successfully
*
* Setting a null configuration effectively unlinks the agent from any GPT configuration,
* which may prevent the agent from being used in autonomous flows.
*
* @throws {InvalidParamValueException} When the agent name is not a valid DonobuAgent
*/
async set(req, res) {
const parsedBody = v4_1.z
.object({
gptConfigName: v4_1.z.string().nullable(),
})
.parse(req.body);
const agentName = req.params.name;
if (!DonobuAgentType_1.DonobuAgent.includes(agentName)) {
throw new InvalidParamValueException_1.InvalidParamValueException('/api/agents/:name', agentName);
}
await this.agentsManager.set(agentName, parsedBody.gptConfigName);
res.json(parsedBody);
}
/**
* Retrieves the GPT configuration name for a specific agent.
*
* Returns the currently assigned GPT configuration for the specified agent.
* If no configuration is assigned, returns null. The response includes
* validation to ensure the referenced configuration still exists.
*/
async get(req, res) {
const agentName = req.params.name;
const gptConfigName = await this.agentsManager.get(agentName);
res.json({
gptConfigName: gptConfigName,
});
}
/**
* Retrieves all agent-to-GPT-configuration mappings.
*
* Returns a complete mapping of all Donobu agents to their assigned GPT configurations.
* This endpoint is useful for administrative interfaces and system configuration
* overviews. The response includes all defined agents, even those without
* assigned configurations (which will have null values).
*/
async getAll(_req, res) {
const agentsMapping = await this.agentsManager.getAll();
res.json(Object.fromEntries(agentsMapping));
}
}
exports.AgentsApi = AgentsApi;
//# sourceMappingURL=AgentsApi.js.map