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
93 lines (92 loc) • 6.43 kB
JavaScript
;
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 agent_os_client_1 = require("./agent-os/agent-os-client");
const android_adb_client_1 = require("./android/android-adb-client");
const legacy_android_client_1 = require("./legacy-controller/legacy-android-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");
const cache_1 = require("../core/cache");
const logger_1 = require("../lib/logger");
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);
let cacheManager = new cache_1.DummyCacheManager();
if (clientArgs.cacheConfig) {
cacheManager = new cache_1.CacheManager(clientArgs.cacheConfig);
}
return new inference_client_1.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 android_adb_client_1.AndroidAdbClient(android);
}
return new legacy_android_client_1.LegacyAndroidClient(android);
}
return new agent_os_client_1.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 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(deviceClient, 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, _l, _m;
if (clientArgs.uiControllerUrl !== undefined && clientArgs.agentOsUrl === undefined) {
logger_1.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 : is_ci_1.default,
}, credentials: (0, read_credentials_1.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 (0, proxy_builder_1.envProxyAgents)()), runtime: (_m = clientArgs.runtime) !== null && _m !== void 0 ? _m : 'desktop' });
});
}
}
exports.UiControlClientDependencyBuilder = UiControlClientDependencyBuilder;