donobu
Version:
Create browser automations with an LLM agent and replay them as Playwright scripts.
55 lines • 1.78 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GptConfigsManager = void 0;
const v4_1 = require("zod/v4");
/**
* This class manages GPT configs and is responsible for validation around
* that context.
*/
class GptConfigsManager {
constructor(persistence, gptClientFactory) {
this.persistence = persistence;
this.gptClientFactory = gptClientFactory;
}
static async create(persistence, gptClientFactory) {
const instance = new GptConfigsManager(persistence, gptClientFactory);
return instance;
}
/**
* Attempt to save the given GPT config. Where possible, a zero-cost
* request is attempted to be made with the GPT config before saving it.
* If the zero-cost request is attempted and it fails, this method throws.
*/
async set(name, config) {
await this.verifyGptConfigOrThrow(name, config);
await this.persistence.set(name, config);
}
/**
* Fetch a GPT config by name.
*/
async get(name) {
return this.persistence.get(name);
}
/**
* Fetch all GPT configs.
*/
async getAll() {
return this.persistence.getAll();
}
/**
* Delete a GPT config by name.
*/
async delete(name) {
return this.persistence.delete(name);
}
/**
* Verifies the given GPT config and name or throws if they are invalid.
*/
async verifyGptConfigOrThrow(name, config) {
v4_1.z.object({ name: v4_1.z.string().min(1).max(64) }).parse({ name });
// Creating a GPT client performs validation on its own.
await this.gptClientFactory.createClient(config);
}
}
exports.GptConfigsManager = GptConfigsManager;
//# sourceMappingURL=GptConfigsManager.js.map