donobu
Version:
Create browser automations with an LLM agent and replay them as Playwright scripts.
75 lines • 3.02 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GptConfigsApi = void 0;
const GptConfigNotFoundException_1 = require("../exceptions/GptConfigNotFoundException");
const Logger_1 = require("../utils/Logger");
/**
* This API manages the GPT connection configurations available to the Donobu runtime.
*/
class GptConfigsApi {
constructor(gptConfigsManager, agentsManager) {
this.gptConfigsManager = gptConfigsManager;
this.agentsManager = agentsManager;
}
async set(req, res) {
const config = req.body;
const name = req.params.name;
if (!name) {
throw new GptConfigNotFoundException_1.GptConfigNotFoundException(name);
}
await this.gptConfigsManager.set(name, config);
res.json(GptConfigsApi.redactSensativeData(config));
}
async get(req, res) {
const name = req.params.name;
const config = GptConfigsApi.redactSensativeData(await this.gptConfigsManager.get(name));
res.json(config);
}
async getAll(_req, res) {
const configs = await this.gptConfigsManager.getAll();
const redactedConfigs = new Map(Array.from(configs.entries()).map(([key, value]) => [
key,
GptConfigsApi.redactSensativeData(value),
]));
res.json(Object.fromEntries(redactedConfigs));
}
async delete(req, res) {
const name = req.params.name;
await this.gptConfigsManager.delete(name);
try {
// If this GPT config is associated with an agent, delete its reference.
const agentNameToConfigNameMap = await this.agentsManager.getAll();
agentNameToConfigNameMap.forEach(async (configName, agentName) => {
if (configName === name) {
try {
await this.agentsManager.set(agentName, null);
}
catch (error) {
Logger_1.appLogger.warn(`Failed to unset Donobu ${agentName} agent configuration from '${name}'`, error);
}
}
});
}
catch (error) {
Logger_1.appLogger.warn(`Failed to unset Donobu agent configurations from '${name}'`, error);
}
res.json({});
}
/**
* Redacts sensative data from the given GPT configuration so that the record
* can be safely returned through the API.
*/
static redactSensativeData(config) {
const configCopy = { ...config };
for (const redactedFieldName of GptConfigsApi.REDACTED_FIELD_NAMES) {
if (redactedFieldName in configCopy) {
// Use type assertion to tell TypeScript this is allowed
configCopy[redactedFieldName] = '****************';
}
}
return configCopy;
}
}
exports.GptConfigsApi = GptConfigsApi;
GptConfigsApi.REDACTED_FIELD_NAMES = ['apiKey', 'secretAccessKey'];
//# sourceMappingURL=GptConfigsApi.js.map