@alwaysai/device-agent 1.3.1 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/application-control/config.js +2 -2
- package/lib/application-control/config.js.map +1 -1
- package/lib/application-control/environment-variables.d.ts.map +1 -1
- package/lib/application-control/environment-variables.js +9 -4
- package/lib/application-control/environment-variables.js.map +1 -1
- package/lib/application-control/environment-variables.test.js +1 -1
- package/lib/application-control/environment-variables.test.js.map +1 -1
- package/lib/application-control/install.d.ts.map +1 -1
- package/lib/application-control/install.js +7 -2
- package/lib/application-control/install.js.map +1 -1
- package/lib/application-control/models.d.ts +5 -0
- package/lib/application-control/models.d.ts.map +1 -1
- package/lib/application-control/models.js +28 -14
- package/lib/application-control/models.js.map +1 -1
- package/lib/application-control/status.d.ts.map +1 -1
- package/lib/application-control/status.js +14 -17
- package/lib/application-control/status.js.map +1 -1
- package/lib/application-control/utils.js +2 -2
- package/lib/application-control/utils.js.map +1 -1
- package/lib/cloud-connection/device-agent-cloud-connection.d.ts +5 -5
- package/lib/cloud-connection/device-agent-cloud-connection.d.ts.map +1 -1
- package/lib/cloud-connection/device-agent-cloud-connection.js +140 -105
- package/lib/cloud-connection/device-agent-cloud-connection.js.map +1 -1
- package/lib/cloud-connection/live-updates-handler.d.ts +4 -2
- package/lib/cloud-connection/live-updates-handler.d.ts.map +1 -1
- package/lib/cloud-connection/live-updates-handler.js +46 -25
- package/lib/cloud-connection/live-updates-handler.js.map +1 -1
- package/lib/cloud-connection/live-updates-handler.test.js +132 -16
- package/lib/cloud-connection/live-updates-handler.test.js.map +1 -1
- package/lib/cloud-connection/messages.d.ts.map +1 -1
- package/lib/cloud-connection/messages.js +3 -4
- package/lib/cloud-connection/messages.js.map +1 -1
- package/lib/cloud-connection/passthrough-handler.d.ts +5 -3
- package/lib/cloud-connection/passthrough-handler.d.ts.map +1 -1
- package/lib/cloud-connection/passthrough-handler.js +76 -62
- package/lib/cloud-connection/passthrough-handler.js.map +1 -1
- package/lib/cloud-connection/shadow-handler.d.ts +16 -21
- package/lib/cloud-connection/shadow-handler.d.ts.map +1 -1
- package/lib/cloud-connection/shadow-handler.js +162 -108
- package/lib/cloud-connection/shadow-handler.js.map +1 -1
- package/lib/cloud-connection/shadow-handler.test.js +100 -83
- package/lib/cloud-connection/shadow-handler.test.js.map +1 -1
- package/lib/cloud-connection/transaction-manager.d.ts +3 -0
- package/lib/cloud-connection/transaction-manager.d.ts.map +1 -1
- package/lib/cloud-connection/transaction-manager.js +11 -0
- package/lib/cloud-connection/transaction-manager.js.map +1 -1
- package/lib/cloud-connection/transaction-manager.test.js +102 -0
- package/lib/cloud-connection/transaction-manager.test.js.map +1 -1
- package/lib/device-control/device-control.d.ts +16 -15
- package/lib/device-control/device-control.d.ts.map +1 -1
- package/lib/device-control/device-control.js +117 -18
- package/lib/device-control/device-control.js.map +1 -1
- package/lib/docker/docker-compose.d.ts +14 -0
- package/lib/docker/docker-compose.d.ts.map +1 -0
- package/lib/docker/docker-compose.js +56 -0
- package/lib/docker/docker-compose.js.map +1 -0
- package/lib/index.js +2 -5
- package/lib/index.js.map +1 -1
- package/lib/infrastructure/agent-config.d.ts +45 -14
- package/lib/infrastructure/agent-config.d.ts.map +1 -1
- package/lib/infrastructure/agent-config.js +30 -15
- package/lib/infrastructure/agent-config.js.map +1 -1
- package/lib/infrastructure/agent-config.test.js +3 -0
- package/lib/infrastructure/agent-config.test.js.map +1 -1
- package/lib/local-connection/rabbitmq-connection.js +11 -11
- package/lib/local-connection/rabbitmq-connection.js.map +1 -1
- package/lib/secure-tunneling/secure-tunneling.d.ts +97 -0
- package/lib/secure-tunneling/secure-tunneling.d.ts.map +1 -0
- package/lib/secure-tunneling/secure-tunneling.js +435 -0
- package/lib/secure-tunneling/secure-tunneling.js.map +1 -0
- package/lib/secure-tunneling/secure-tunneling.test.d.ts +2 -0
- package/lib/secure-tunneling/secure-tunneling.test.d.ts.map +1 -0
- package/lib/secure-tunneling/secure-tunneling.test.js +1070 -0
- package/lib/secure-tunneling/secure-tunneling.test.js.map +1 -0
- package/lib/secure-tunneling/spawner-detached.d.ts +6 -0
- package/lib/secure-tunneling/spawner-detached.d.ts.map +1 -0
- package/lib/secure-tunneling/spawner-detached.js +107 -0
- package/lib/secure-tunneling/spawner-detached.js.map +1 -0
- package/lib/subcommands/app/analytics.d.ts.map +1 -1
- package/lib/subcommands/app/analytics.js +9 -13
- package/lib/subcommands/app/analytics.js.map +1 -1
- package/lib/subcommands/app/env-vars.d.ts.map +1 -1
- package/lib/subcommands/app/env-vars.js +11 -16
- package/lib/subcommands/app/env-vars.js.map +1 -1
- package/lib/subcommands/app/models.d.ts.map +1 -1
- package/lib/subcommands/app/models.js +12 -16
- package/lib/subcommands/app/models.js.map +1 -1
- package/lib/subcommands/device/clean.d.ts.map +1 -1
- package/lib/subcommands/device/clean.js +8 -6
- package/lib/subcommands/device/clean.js.map +1 -1
- package/lib/subcommands/device/get-info.d.ts +2 -0
- package/lib/subcommands/device/get-info.d.ts.map +1 -0
- package/lib/subcommands/device/get-info.js +36 -0
- package/lib/subcommands/device/get-info.js.map +1 -0
- package/lib/subcommands/device/index.d.ts.map +1 -1
- package/lib/subcommands/device/index.js +11 -2
- package/lib/subcommands/device/index.js.map +1 -1
- package/lib/subcommands/device/init.d.ts +5 -0
- package/lib/subcommands/device/init.d.ts.map +1 -0
- package/lib/subcommands/device/{device.js → init.js} +5 -36
- package/lib/subcommands/device/init.js.map +1 -0
- package/lib/subcommands/device/refresh.d.ts +2 -0
- package/lib/subcommands/device/refresh.d.ts.map +1 -0
- package/lib/subcommands/device/refresh.js +24 -0
- package/lib/subcommands/device/refresh.js.map +1 -0
- package/lib/subcommands/device/restart.d.ts +2 -0
- package/lib/subcommands/device/restart.d.ts.map +1 -0
- package/lib/subcommands/device/restart.js +14 -0
- package/lib/subcommands/device/restart.js.map +1 -0
- package/lib/util/check-for-updates.d.ts +3 -0
- package/lib/util/check-for-updates.d.ts.map +1 -0
- package/lib/util/check-for-updates.js +69 -0
- package/lib/util/check-for-updates.js.map +1 -0
- package/lib/util/cloud-mode-ready.d.ts +1 -0
- package/lib/util/cloud-mode-ready.d.ts.map +1 -1
- package/lib/util/cloud-mode-ready.js +36 -1
- package/lib/util/cloud-mode-ready.js.map +1 -1
- package/lib/util/file.d.ts +7 -0
- package/lib/util/file.d.ts.map +1 -0
- package/lib/util/file.js +66 -0
- package/lib/util/file.js.map +1 -0
- package/lib/util/file.test.d.ts +2 -0
- package/lib/util/file.test.d.ts.map +1 -0
- package/lib/util/file.test.js +87 -0
- package/lib/util/file.test.js.map +1 -0
- package/package.json +8 -7
- package/readme.md +3 -3
- package/src/application-control/config.ts +1 -1
- package/src/application-control/environment-variables.test.ts +1 -1
- package/src/application-control/environment-variables.ts +9 -6
- package/src/application-control/install.ts +8 -3
- package/src/application-control/models.ts +47 -19
- package/src/application-control/status.ts +16 -14
- package/src/application-control/utils.ts +1 -1
- package/src/cloud-connection/device-agent-cloud-connection.ts +202 -148
- package/src/cloud-connection/live-updates-handler.test.ts +161 -20
- package/src/cloud-connection/live-updates-handler.ts +63 -31
- package/src/cloud-connection/messages.ts +3 -4
- package/src/cloud-connection/passthrough-handler.ts +98 -76
- package/src/cloud-connection/shadow-handler.test.ts +101 -84
- package/src/cloud-connection/shadow-handler.ts +287 -133
- package/src/cloud-connection/transaction-manager.test.ts +124 -0
- package/src/cloud-connection/transaction-manager.ts +15 -0
- package/src/device-control/device-control.ts +125 -23
- package/src/docker/docker-compose.ts +60 -0
- package/src/index.ts +2 -6
- package/src/infrastructure/agent-config.test.ts +3 -0
- package/src/infrastructure/agent-config.ts +38 -40
- package/src/local-connection/rabbitmq-connection.ts +8 -8
- package/src/secure-tunneling/secure-tunneling.test.ts +1239 -0
- package/src/secure-tunneling/secure-tunneling.ts +599 -0
- package/src/secure-tunneling/spawner-detached.ts +123 -0
- package/src/subcommands/app/analytics.ts +16 -13
- package/src/subcommands/app/env-vars.ts +18 -16
- package/src/subcommands/app/models.ts +20 -16
- package/src/subcommands/device/clean.ts +5 -2
- package/src/subcommands/device/get-info.ts +49 -0
- package/src/subcommands/device/index.ts +11 -2
- package/src/subcommands/device/{device.ts → init.ts} +5 -47
- package/src/subcommands/device/refresh.ts +22 -0
- package/src/subcommands/device/restart.ts +11 -0
- package/src/util/check-for-updates.ts +69 -0
- package/src/util/cloud-mode-ready.ts +36 -0
- package/src/util/file.test.ts +90 -0
- package/src/util/file.ts +76 -0
- package/lib/docker/docker-compose-cmd.d.ts +0 -5
- package/lib/docker/docker-compose-cmd.d.ts.map +0 -1
- package/lib/docker/docker-compose-cmd.js +0 -16
- package/lib/docker/docker-compose-cmd.js.map +0 -1
- package/lib/secure-tunneling/index.d.ts +0 -5
- package/lib/secure-tunneling/index.d.ts.map +0 -1
- package/lib/secure-tunneling/index.js +0 -64
- package/lib/secure-tunneling/index.js.map +0 -1
- package/lib/subcommands/device/device.d.ts +0 -7
- package/lib/subcommands/device/device.d.ts.map +0 -1
- package/lib/subcommands/device/device.js.map +0 -1
- package/lib/util/safe-rimraf.d.ts +0 -2
- package/lib/util/safe-rimraf.d.ts.map +0 -1
- package/lib/util/safe-rimraf.js +0 -16
- package/lib/util/safe-rimraf.js.map +0 -1
- package/src/docker/docker-compose-cmd.ts +0 -15
- package/src/secure-tunneling/index.ts +0 -74
- package/src/util/safe-rimraf.ts +0 -14
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as path from 'path';
|
|
2
1
|
import { ModelInstallPayload } from '@alwaysai/device-agent-schemas';
|
|
3
2
|
import {
|
|
4
3
|
appModelsAddComponent,
|
|
@@ -23,8 +22,9 @@ import {
|
|
|
23
22
|
} from './utils';
|
|
24
23
|
import { MODEL_JSON_FILE_NAME } from 'alwaysai/lib/core/model';
|
|
25
24
|
import { writeAppCfgFile } from './config';
|
|
26
|
-
import { AppConfig } from '@alwaysai/app-configuration-schemas';
|
|
27
25
|
import { APP_MODELS_DIRECTORY_NAME } from 'alwaysai/lib/paths';
|
|
26
|
+
import { pruneDir } from '../util/file';
|
|
27
|
+
import { AppConfig } from '@alwaysai/app-configuration-schemas';
|
|
28
28
|
|
|
29
29
|
export async function getAppModels(props: { projectId: string }) {
|
|
30
30
|
const { projectId } = props;
|
|
@@ -89,14 +89,19 @@ export async function replaceModels(props: {
|
|
|
89
89
|
],
|
|
90
90
|
appDir
|
|
91
91
|
);
|
|
92
|
+
const modelsAddPromises: Promise<void>[] = [];
|
|
92
93
|
for (const modelId of modelIds) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
94
|
+
modelsAddPromises.push(
|
|
95
|
+
appModelsAddComponent({
|
|
96
|
+
yes: false,
|
|
97
|
+
dir: appDir,
|
|
98
|
+
id: modelId,
|
|
99
|
+
addToProject: false
|
|
100
|
+
})
|
|
101
|
+
);
|
|
99
102
|
}
|
|
103
|
+
await Promise.all(modelsAddPromises);
|
|
104
|
+
|
|
100
105
|
await buildApp({ appDir });
|
|
101
106
|
}
|
|
102
107
|
|
|
@@ -122,9 +127,9 @@ export async function installModelsWithPresignedURLs(
|
|
|
122
127
|
modelPayloads.map(async (payload: ModelInstallPayload) => {
|
|
123
128
|
logger.info(`Installing ${payload.id}: ${payload.version}`);
|
|
124
129
|
const version = payload.version;
|
|
125
|
-
const modelDest =
|
|
130
|
+
const modelDest = join(targetDir, payload.id);
|
|
126
131
|
await spawner.mkdirp(modelDest);
|
|
127
|
-
const localDest =
|
|
132
|
+
const localDest = join(modelDest, `${payload.version}.tar.gz`);
|
|
128
133
|
await downloadPackageUsingPresignedUrl({
|
|
129
134
|
localDest,
|
|
130
135
|
presignedUrl: payload.modelSignedUrl
|
|
@@ -173,20 +178,21 @@ export async function updateModelsWithPresignedUrls(props: {
|
|
|
173
178
|
version: appReleaseHash
|
|
174
179
|
});
|
|
175
180
|
|
|
176
|
-
const ogDir =
|
|
177
|
-
// Copy all current models to restore dir in case of failure
|
|
178
|
-
const restoreDir = `${ogDir}.restore`;
|
|
179
|
-
await spawner.rimraf(restoreDir);
|
|
180
|
-
await copyDir({ srcPath: ogDir, destPath: restoreDir });
|
|
181
|
-
|
|
182
|
-
// Create temp dir to install new models
|
|
181
|
+
const ogDir = join(appDir, APP_MODELS_DIRECTORY_NAME);
|
|
183
182
|
const tmpDir = `${ogDir}.tmp`;
|
|
184
183
|
|
|
185
184
|
try {
|
|
186
185
|
await spawner.rimraf(tmpDir);
|
|
187
186
|
await copyDir({ srcPath: ogDir, destPath: tmpDir });
|
|
187
|
+
|
|
188
|
+
await pruneModels({
|
|
189
|
+
projectId,
|
|
190
|
+
appCfg: newAppCfg,
|
|
191
|
+
path: tmpDir
|
|
192
|
+
});
|
|
193
|
+
|
|
188
194
|
await installModelsWithPresignedURLs(modelInstallPayloads, tmpDir);
|
|
189
|
-
|
|
195
|
+
|
|
190
196
|
await spawner.rimraf(ogDir);
|
|
191
197
|
await copyDir({ srcPath: tmpDir, destPath: ogDir });
|
|
192
198
|
await spawner.rimraf(tmpDir);
|
|
@@ -206,6 +212,28 @@ export async function updateModelsWithPresignedUrls(props: {
|
|
|
206
212
|
logger.info(`Models installed for project ${projectId}`);
|
|
207
213
|
} finally {
|
|
208
214
|
await spawner.rimraf(tmpDir);
|
|
209
|
-
await spawner.rimraf(restoreDir);
|
|
210
215
|
}
|
|
211
216
|
}
|
|
217
|
+
|
|
218
|
+
export async function pruneModels(props: {
|
|
219
|
+
projectId: string;
|
|
220
|
+
appCfg: AppConfig;
|
|
221
|
+
path?: string;
|
|
222
|
+
}) {
|
|
223
|
+
const { projectId, appCfg, path } = props;
|
|
224
|
+
|
|
225
|
+
const modelsPath = path || join(getAppDir(projectId), 'models');
|
|
226
|
+
|
|
227
|
+
if (!existsSync(modelsPath)) {
|
|
228
|
+
logger.error(
|
|
229
|
+
`Attempted to prune models from ${modelsPath} for project app ${projectId} that does not exist or has no models dir.`
|
|
230
|
+
);
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
await pruneDir({
|
|
235
|
+
path: modelsPath,
|
|
236
|
+
exclude: Object.keys(appCfg.models),
|
|
237
|
+
recurse: true
|
|
238
|
+
});
|
|
239
|
+
}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
compose,
|
|
3
|
+
runStreamingDockerComposeCmd,
|
|
4
|
+
runDockerComposeCmd
|
|
5
|
+
} from '../docker/docker-compose';
|
|
2
6
|
import { JsSpawner } from 'alwaysai/lib/util';
|
|
3
7
|
|
|
4
8
|
import { runDockerLogin } from '../docker/docker-cmd';
|
|
@@ -48,9 +52,8 @@ export async function getAppState(props: {
|
|
|
48
52
|
const spawner = JsSpawner({ path: appDir });
|
|
49
53
|
for (const name of composeServices.data.services) {
|
|
50
54
|
// Get container name for service
|
|
51
|
-
const containerId = await
|
|
52
|
-
|
|
53
|
-
cwd: appDir,
|
|
55
|
+
const containerId = await runDockerComposeCmd({
|
|
56
|
+
dir: appDir,
|
|
54
57
|
args: ['ps', '-q', name]
|
|
55
58
|
});
|
|
56
59
|
if (containerId === '') {
|
|
@@ -126,20 +129,19 @@ export async function getAppLogs(props: {
|
|
|
126
129
|
|
|
127
130
|
const appDir = getAppDir(projectId);
|
|
128
131
|
|
|
129
|
-
const serviceList =
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
132
|
+
const serviceList =
|
|
133
|
+
services ||
|
|
134
|
+
(await (async function () {
|
|
135
|
+
const composeServices = await compose.configServices({ cwd: appDir });
|
|
136
|
+
return composeServices.data.services;
|
|
137
|
+
})());
|
|
135
138
|
|
|
136
|
-
const argsList = args
|
|
139
|
+
const argsList = args || [];
|
|
137
140
|
|
|
138
141
|
// Use direct command with spawner in order to get a readable stream
|
|
139
|
-
return await
|
|
140
|
-
exe: 'docker-compose',
|
|
142
|
+
return await runStreamingDockerComposeCmd({
|
|
141
143
|
args: ['logs', '-f', ...argsList, ...serviceList],
|
|
142
|
-
|
|
144
|
+
dir: appDir
|
|
143
145
|
});
|
|
144
146
|
}
|
|
145
147
|
|