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

86 lines (85 loc) 5.8 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 { AgentOsClient } from './agent-os/agent-os-client'; import { AndroidAdbClient } from './android/android-adb-client'; import { LegacyAndroidClient } from './legacy-controller/legacy-android-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'; import { CacheManager, DummyCacheManager } from '../core/cache'; import { logger } from '../lib/logger'; 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); let cacheManager = new DummyCacheManager(); if (clientArgs.cacheConfig) { cacheManager = new CacheManager(clientArgs.cacheConfig); } return new InferenceClient(clientArgs.inferenceServerUrl, httpClient, cacheManager, clientArgs.resize, (_a = clientArgs.credentials) === null || _a === void 0 ? void 0 : _a.workspaceId, clientArgs.modelComposition, clientArgs.inferenceServerApiVersion); }); } static buildDeviceClient(clientArgs) { var _a, _b; if (clientArgs.runtime === 'android') { const android = (_a = clientArgs.android) !== null && _a !== void 0 ? _a : {}; if (((_b = android.transport) !== null && _b !== void 0 ? _b : 'legacy-controller') === 'adb') { return new AndroidAdbClient(android); } return new LegacyAndroidClient(android); } return new AgentOsClient(clientArgs.agentOsUrl); } static build(clientArgs) { return __awaiter(this, void 0, void 0, function* () { var _a, _b; const deviceClient = UiControlClientDependencyBuilder.buildDeviceClient(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(deviceClient, 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, _l, _m; if (clientArgs.uiControllerUrl !== undefined && clientArgs.agentOsUrl === undefined) { logger.warn("'uiControllerUrl' is deprecated and will be removed in a future release. " + "Use 'agentOsUrl' instead."); } return Object.assign(Object.assign({}, clientArgs), { agentOsUrl: (_b = (_a = clientArgs.agentOsUrl) !== null && _a !== void 0 ? _a : clientArgs.uiControllerUrl) !== null && _b !== void 0 ? _b : 'localhost:26000', aiElementArgs: { additionalLocations: (_d = (_c = clientArgs.aiElementArgs) === null || _c === void 0 ? void 0 : _c.additionalLocations) !== null && _d !== void 0 ? _d : [], onLocationNotExist: (_f = (_e = clientArgs.aiElementArgs) === null || _e === void 0 ? void 0 : _e.onLocationNotExist) !== null && _f !== void 0 ? _f : 'error', }, context: { isCi: (_h = (_g = clientArgs.context) === null || _g === void 0 ? void 0 : _g.isCi) !== null && _h !== void 0 ? _h : isCI, }, credentials: readCredentials(clientArgs), inferenceServerApiVersion: (_j = clientArgs.inferenceServerApiVersion) !== null && _j !== void 0 ? _j : 'v1', inferenceServerUrl: (_k = clientArgs.inferenceServerUrl) !== null && _k !== void 0 ? _k : 'https://inference.askui.com', proxyAgents: (_l = clientArgs.proxyAgents) !== null && _l !== void 0 ? _l : (yield envProxyAgents()), runtime: (_m = clientArgs.runtime) !== null && _m !== void 0 ? _m : 'desktop' }); }); } }