alwaysai
Version:
The alwaysAI command-line interface (CLI)
50 lines • 2.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.appModelsUpdateComponent = void 0;
const logSymbols = require("log-symbols");
const alwayscli_1 = require("@alwaysai/alwayscli");
const user_1 = require("../../user");
const util_1 = require("../../../util");
const infrastructure_1 = require("../../../infrastructure");
const app_1 = require("../../../core/app");
async function appModelsUpdateComponent(props) {
const { yes, dir = process.cwd() } = props;
await (0, user_1.checkUserIsLoggedInComponent)({ yes });
const appJsonFile = (0, app_1.AppJsonFile)(dir);
const { models } = appJsonFile.read();
const updates = [];
if (!models || Object.keys(models).length === 0) {
(0, util_1.echo)('No models to update!');
}
else {
const spinner = (0, util_1.Spinner)('Fetching model metadata');
for (const [id, currentVersion] of Object.entries(models)) {
try {
const { version: latestVersion } = await (0, infrastructure_1.CliRpcClient)().getModelVersion({ id });
if (currentVersion !== latestVersion) {
updates.push([id, currentVersion, latestVersion]);
}
}
catch (exception) {
spinner.fail();
if (exception.code === 'MODEL_VERSION_NOT_FOUND') {
throw new alwayscli_1.CliTerseError(`Model not found: "${id}"`);
}
throw exception;
}
}
spinner.succeed();
if (updates.length === 0) {
(0, util_1.echo)(`${logSymbols.success} All models are already up to date!`);
}
else {
(0, util_1.echo)(`${logSymbols.success} Updated models`);
updates.forEach(([id, currentVersion, nextVersion]) => {
(0, util_1.echo)(` ${id} ${currentVersion} --> ${nextVersion}`);
appJsonFile.addModel(id, nextVersion);
});
}
}
}
exports.appModelsUpdateComponent = appModelsUpdateComponent;
//# sourceMappingURL=app-models-update-component.js.map