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

66 lines (65 loc) 4.58 kB
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()); }); }; import isCI from 'is-ci'; import { HttpClientGot } from '../utils/http/http-client-got'; import { UiControllerClient } from './ui-controller-client'; import { InferenceClient } from './inference-client'; import { Analytics } from '../utils/analytics'; import { envProxyAgents } from '../utils/proxy/proxy-builder'; import { ExecutionRuntime } from './execution-runtime'; import { StepReporter } from '../core/reporting'; import { readCredentials } from './read-credentials'; import { LinearRetryStrategy } from './retry-strategies/linear-retry-strategy'; export class UiControlClientDependencyBuilder { static buildHttpClient(clientArgs) { return __awaiter(this, void 0, void 0, function* () { var _a; const analytics = new Analytics(); const analyticsHeaders = yield analytics.getAnalyticsHeaders(clientArgs.context); const analyticsCookies = yield analytics.getAnalyticsCookies(); return new 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 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 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 StepReporter(clientArgs.reporter); const workspaceId = (_a = clientArgs.credentials) === null || _a === void 0 ? void 0 : _a.workspaceId; return { executionRuntime: new ExecutionRuntime(uiControllerClient, inferenceClient, stepReporter, (_b = clientArgs.retryStrategy) !== null && _b !== void 0 ? _b : new 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 : isCI, }, credentials: 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 envProxyAgents()), uiControllerUrl: (_k = clientArgs.uiControllerUrl) !== null && _k !== void 0 ? _k : 'http://127.0.0.1:6769' }); }); } }