UNPKG

donobu

Version:

Create browser automations with an LLM agent and replay them as Playwright scripts.

65 lines 2.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GptClientFactoryImpl = void 0; const InvalidParamValueException_1 = require("../exceptions/InvalidParamValueException"); const GptConfig_1 = require("../models/GptConfig"); const AnthropicGptClient_1 = require("./AnthropicGptClient"); const DonobuGptClient_1 = require("./DonobuGptClient"); const GoogleGenerativeAiGptClient_1 = require("./GoogleGenerativeAiGptClient"); const GptClientPlugin_1 = require("./GptClientPlugin"); const OllamaGptClient_1 = require("./OllamaGptClient"); const OpenAiGptClient_1 = require("./OpenAiGptClient"); /** * Default implementation of GptClientFactory that creates GPT clients * based on configuration and validates them by performing a ping. * * Built-in types are handled directly; unknown types are delegated to * the GPT client plugin registry. */ class GptClientFactoryImpl { constructor(gptClientPlugins = new GptClientPlugin_1.GptClientPluginRegistry([])) { this.gptClientPlugins = gptClientPlugins; } async createClient(config) { const client = await this.resolveClient(config); await client.ping(); return client; } /** * Resolves the correct GptClient implementation for the given config. * Built-in config types (matching {@link GptConfigSchema}) are handled * by known implementations; everything else is delegated to the * GPT client plugin registry. */ async resolveClient(config) { // Try built-in types first — safeParse gives us proper type narrowing. const builtIn = GptConfig_1.GptConfigSchema.safeParse(config); if (builtIn.success) { return this.createBuiltInClient(builtIn.data); } // Fall back to plugin registry for plugin-provided types. const plugin = this.gptClientPlugins.get(config.type); if (plugin) { return plugin.createClient(config); } throw new InvalidParamValueException_1.InvalidParamValueException('type', config.type); } createBuiltInClient(config) { switch (config.type) { case 'ANTHROPIC': return new AnthropicGptClient_1.AnthropicGptClient(config); case 'DONOBU': return new DonobuGptClient_1.DonobuGptClient(config); case 'GOOGLE_GEMINI': return new GoogleGenerativeAiGptClient_1.GoogleGenerativeAiGptClient(config); case 'OLLAMA': return new OllamaGptClient_1.OllamaGptClient(config); case 'OPENAI': return new OpenAiGptClient_1.OpenAiGptClient(config); default: throw new InvalidParamValueException_1.InvalidParamValueException('type', config.type); } } } exports.GptClientFactoryImpl = GptClientFactoryImpl; //# sourceMappingURL=GptClientFactory.js.map