UNPKG

askui

Version:

Reliable, automated end-to-end-testing that depends on what is shown on your screen instead of the technology you are running on

73 lines (72 loc) 5.16 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.UiControlClientDependencyBuilder = void 0; const is_ci_1 = __importDefault(require("is-ci")); const http_client_got_1 = require("../utils/http/http-client-got"); const ui_controller_client_1 = require("./ui-controller-client"); const inference_client_1 = require("./inference-client"); const analytics_1 = require("../utils/analytics"); const proxy_builder_1 = require("../utils/proxy/proxy-builder"); const execution_runtime_1 = require("./execution-runtime"); const reporting_1 = require("../core/reporting"); const read_credentials_1 = require("./read-credentials"); const linear_retry_strategy_1 = require("./retry-strategies/linear-retry-strategy"); class UiControlClientDependencyBuilder { static buildHttpClient(clientArgs) { return __awaiter(this, void 0, void 0, function* () { var _a; const analytics = new analytics_1.Analytics(); const analyticsHeaders = yield analytics.getAnalyticsHeaders(clientArgs.context); const analyticsCookies = yield analytics.getAnalyticsCookies(); return new http_client_got_1.HttpClientGot((_a = clientArgs.credentials) === null || _a === void 0 ? void 0 : _a.token, analyticsHeaders, analyticsCookies, clientArgs.proxyAgents); }); } static buildInferenceClient(clientArgs) { return __awaiter(this, void 0, void 0, function* () { var _a; const httpClient = yield UiControlClientDependencyBuilder.buildHttpClient(clientArgs); return new inference_client_1.InferenceClient(clientArgs.inferenceServerUrl, httpClient, clientArgs.resize, (_a = clientArgs.credentials) === null || _a === void 0 ? void 0 : _a.workspaceId, clientArgs.modelComposition, clientArgs.inferenceServerApiVersion); }); } static buildUiControllerClient(clientArgs) { return new ui_controller_client_1.UiControllerClient(clientArgs.uiControllerUrl); } static build(clientArgs) { return __awaiter(this, void 0, void 0, function* () { var _a, _b; const uiControllerClient = UiControlClientDependencyBuilder.buildUiControllerClient(clientArgs); const inferenceClient = yield UiControlClientDependencyBuilder.buildInferenceClient(clientArgs); const stepReporter = new reporting_1.StepReporter(clientArgs.reporter); const workspaceId = (_a = clientArgs.credentials) === null || _a === void 0 ? void 0 : _a.workspaceId; return { executionRuntime: new execution_runtime_1.ExecutionRuntime(uiControllerClient, inferenceClient, stepReporter, (_b = clientArgs.retryStrategy) !== null && _b !== void 0 ? _b : new linear_retry_strategy_1.LinearRetryStrategy()), stepReporter, workspaceId, }; }); } static getClientArgsWithDefaults(clientArgs) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; return Object.assign(Object.assign({}, clientArgs), { aiElementArgs: { additionalLocations: (_b = (_a = clientArgs.aiElementArgs) === null || _a === void 0 ? void 0 : _a.additionalLocations) !== null && _b !== void 0 ? _b : [], onLocationNotExist: (_d = (_c = clientArgs.aiElementArgs) === null || _c === void 0 ? void 0 : _c.onLocationNotExist) !== null && _d !== void 0 ? _d : 'error', }, context: { isCi: (_f = (_e = clientArgs.context) === null || _e === void 0 ? void 0 : _e.isCi) !== null && _f !== void 0 ? _f : is_ci_1.default, }, credentials: (0, read_credentials_1.readCredentials)(clientArgs), inferenceServerApiVersion: (_g = clientArgs.inferenceServerApiVersion) !== null && _g !== void 0 ? _g : 'v1', inferenceServerUrl: (_h = clientArgs.inferenceServerUrl) !== null && _h !== void 0 ? _h : 'https://inference.askui.com', proxyAgents: (_j = clientArgs.proxyAgents) !== null && _j !== void 0 ? _j : (yield (0, proxy_builder_1.envProxyAgents)()), uiControllerUrl: (_k = clientArgs.uiControllerUrl) !== null && _k !== void 0 ? _k : 'http://127.0.0.1:6769' }); }); } } exports.UiControlClientDependencyBuilder = UiControlClientDependencyBuilder;