@alwaysai/device-agent 0.2.0 → 1.0.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/LICENSE +12 -0
- package/lib/application-control/config.d.ts.map +1 -1
- package/lib/application-control/config.js +6 -1
- package/lib/application-control/config.js.map +1 -1
- package/lib/application-control/index.d.ts +2 -2
- package/lib/application-control/index.d.ts.map +1 -1
- package/lib/application-control/index.js +2 -2
- package/lib/application-control/index.js.map +1 -1
- package/lib/application-control/install.d.ts +2 -2
- package/lib/application-control/install.d.ts.map +1 -1
- package/lib/application-control/install.js +10 -0
- package/lib/application-control/install.js.map +1 -1
- package/lib/application-control/status.d.ts +3 -3
- package/lib/application-control/status.d.ts.map +1 -1
- package/lib/application-control/status.js +4 -4
- package/lib/application-control/status.js.map +1 -1
- package/lib/cloud-connection/device-agent-cloud-connection.d.ts +7 -7
- package/lib/cloud-connection/device-agent-cloud-connection.d.ts.map +1 -1
- package/lib/cloud-connection/device-agent-cloud-connection.js +158 -100
- package/lib/cloud-connection/device-agent-cloud-connection.js.map +1 -1
- package/lib/cloud-connection/live-updates-handler.d.ts +9 -9
- package/lib/cloud-connection/live-updates-handler.d.ts.map +1 -1
- package/lib/cloud-connection/live-updates-handler.js +45 -42
- package/lib/cloud-connection/live-updates-handler.js.map +1 -1
- package/lib/cloud-connection/live-updates-handler.test.js +6 -5
- package/lib/cloud-connection/live-updates-handler.test.js.map +1 -1
- package/lib/cloud-connection/message-builder.d.ts +7 -0
- package/lib/cloud-connection/message-builder.d.ts.map +1 -0
- package/lib/cloud-connection/message-builder.js +63 -0
- package/lib/cloud-connection/message-builder.js.map +1 -0
- package/lib/cloud-connection/messages.d.ts +5 -15
- package/lib/cloud-connection/messages.d.ts.map +1 -1
- package/lib/cloud-connection/messages.js +22 -31
- package/lib/cloud-connection/messages.js.map +1 -1
- package/lib/cloud-connection/publisher.d.ts +4 -5
- package/lib/cloud-connection/publisher.d.ts.map +1 -1
- package/lib/cloud-connection/publisher.js +12 -21
- package/lib/cloud-connection/publisher.js.map +1 -1
- package/lib/cloud-connection/transaction-queue.d.ts +12 -0
- package/lib/cloud-connection/transaction-queue.d.ts.map +1 -0
- package/lib/cloud-connection/transaction-queue.js +38 -0
- package/lib/cloud-connection/transaction-queue.js.map +1 -0
- package/lib/cloud-connection/transaction-queue.test.d.ts +2 -0
- package/lib/cloud-connection/transaction-queue.test.d.ts.map +1 -0
- package/lib/cloud-connection/transaction-queue.test.js +46 -0
- package/lib/cloud-connection/transaction-queue.test.js.map +1 -0
- package/lib/local-connection/rabbitmq-connection.d.ts.map +1 -1
- package/lib/local-connection/rabbitmq-connection.js +5 -1
- package/lib/local-connection/rabbitmq-connection.js.map +1 -1
- package/lib/subcommands/app/index.d.ts.map +1 -1
- package/lib/subcommands/app/index.js +1 -0
- package/lib/subcommands/app/index.js.map +1 -1
- package/lib/subcommands/app/models.d.ts +5 -0
- package/lib/subcommands/app/models.d.ts.map +1 -1
- package/lib/subcommands/app/models.js +42 -1
- package/lib/subcommands/app/models.js.map +1 -1
- package/lib/subcommands/app/status.js +1 -1
- package/lib/subcommands/app/status.js.map +1 -1
- package/lib/subcommands/app/version.d.ts.map +1 -1
- package/lib/subcommands/app/version.js +9 -11
- package/lib/subcommands/app/version.js.map +1 -1
- package/lib/util/logger.d.ts.map +1 -1
- package/lib/util/logger.js +3 -1
- package/lib/util/logger.js.map +1 -1
- package/package.json +5 -4
- package/readme.md +30 -1
- package/src/application-control/config.ts +5 -1
- package/src/application-control/index.ts +2 -2
- package/src/application-control/install.ts +17 -4
- package/src/application-control/status.ts +9 -8
- package/src/cloud-connection/device-agent-cloud-connection.ts +225 -132
- package/src/cloud-connection/live-updates-handler.test.ts +6 -5
- package/src/cloud-connection/live-updates-handler.ts +90 -64
- package/src/cloud-connection/message-builder.ts +117 -0
- package/src/cloud-connection/messages.ts +27 -35
- package/src/cloud-connection/publisher.ts +17 -30
- package/src/cloud-connection/transaction-queue.test.ts +55 -0
- package/src/cloud-connection/transaction-queue.ts +40 -0
- package/src/local-connection/rabbitmq-connection.ts +5 -1
- package/src/subcommands/app/index.ts +3 -1
- package/src/subcommands/app/models.ts +44 -0
- package/src/subcommands/app/status.ts +2 -2
- package/src/subcommands/app/version.ts +16 -14
- package/src/util/logger.ts +5 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CliLeaf,
|
|
3
|
+
CliNumberInput,
|
|
3
4
|
CliStringArrayInput,
|
|
4
5
|
CliStringInput
|
|
5
6
|
} from '@alwaysai/alwayscli';
|
|
@@ -75,6 +76,49 @@ export const addModelCliLeaf = CliLeaf({
|
|
|
75
76
|
}
|
|
76
77
|
});
|
|
77
78
|
|
|
79
|
+
export const installModelCliLeaf = CliLeaf({
|
|
80
|
+
name: 'install-model',
|
|
81
|
+
description: 'Install an alwaysAI model to a project',
|
|
82
|
+
namedInputs: {
|
|
83
|
+
project: CliStringInput({
|
|
84
|
+
description: 'Project ID',
|
|
85
|
+
required: true
|
|
86
|
+
}),
|
|
87
|
+
modelName: CliStringInput({
|
|
88
|
+
description: 'Model Name',
|
|
89
|
+
required: true
|
|
90
|
+
}),
|
|
91
|
+
modelVersion: CliNumberInput({
|
|
92
|
+
description: 'Model Version',
|
|
93
|
+
required: true
|
|
94
|
+
})
|
|
95
|
+
},
|
|
96
|
+
async action(_, opts) {
|
|
97
|
+
const { project, modelName, modelVersion } = opts;
|
|
98
|
+
const deviceAgent = new DeviceAgentCloudConnection();
|
|
99
|
+
await deviceAgent.setupHandlers();
|
|
100
|
+
const topic = deviceAgent.getShadowTopics().projects.getAccepted;
|
|
101
|
+
const newAppCfg = await readAppCfgFile({ projectId: project });
|
|
102
|
+
newAppCfg['models'][modelName] = modelVersion;
|
|
103
|
+
|
|
104
|
+
const message = {
|
|
105
|
+
state: {
|
|
106
|
+
delta: {
|
|
107
|
+
[project]: {
|
|
108
|
+
appConfig: JSON.stringify(newAppCfg)
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
clientToken: deviceAgent.getClientId()
|
|
113
|
+
};
|
|
114
|
+
await deviceAgent.handleMessage(topic, message);
|
|
115
|
+
while (deviceAgent.isCmdInProgress(project)) {
|
|
116
|
+
await sleep(1000);
|
|
117
|
+
}
|
|
118
|
+
await deviceAgent.stop();
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
|
|
78
122
|
export const removeModelCliLeaf = CliLeaf({
|
|
79
123
|
name: 'remove-model',
|
|
80
124
|
description: 'Remove a model from an alwaysAI app',
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CliLeaf, CliStringInput } from '@alwaysai/alwayscli';
|
|
2
2
|
import {
|
|
3
3
|
getAppLogs,
|
|
4
|
-
|
|
4
|
+
getAppState,
|
|
5
5
|
restartApp,
|
|
6
6
|
startApp,
|
|
7
7
|
stopApp
|
|
@@ -19,7 +19,7 @@ export const getAppStatusCliLeaf = CliLeaf({
|
|
|
19
19
|
},
|
|
20
20
|
async action(_, opts) {
|
|
21
21
|
const { project } = opts;
|
|
22
|
-
const appStatus = await
|
|
22
|
+
const appStatus = await getAppState({ projectId: project });
|
|
23
23
|
logger.info(JSON.stringify(appStatus, null, 2));
|
|
24
24
|
}
|
|
25
25
|
});
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { CliLeaf, CliStringInput } from '@alwaysai/alwayscli';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
AppVersionControlMessage,
|
|
4
|
+
generateTxId,
|
|
5
|
+
keyMirrors
|
|
6
|
+
} from '@alwaysai/device-agent-schemas';
|
|
3
7
|
import { rollbackApp } from '../../application-control';
|
|
4
8
|
import { DeviceAgentCloudConnection } from '../../cloud-connection/device-agent-cloud-connection';
|
|
5
9
|
import { AgentConfigFile } from '../../infrastructure/agent-config';
|
|
@@ -33,16 +37,15 @@ export const installAppCliLeaf = CliLeaf({
|
|
|
33
37
|
const deviceAgent = new DeviceAgentCloudConnection();
|
|
34
38
|
await deviceAgent.setupHandlers();
|
|
35
39
|
const topic = deviceAgent.getToDeviceTopic();
|
|
36
|
-
const message:
|
|
40
|
+
const message: AppVersionControlMessage = {
|
|
37
41
|
timestamp: '',
|
|
38
42
|
topic,
|
|
43
|
+
messageType: keyMirrors.toDeviceAgentMessageType.app_version_control,
|
|
44
|
+
txId: generateTxId(),
|
|
39
45
|
payload: {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
projectId: project,
|
|
44
|
-
appReleaseHash: releaseHash
|
|
45
|
-
}
|
|
46
|
+
baseCommand: keyMirrors.appVersionControl.install,
|
|
47
|
+
projectId: project,
|
|
48
|
+
appReleaseHash: releaseHash
|
|
46
49
|
}
|
|
47
50
|
};
|
|
48
51
|
await deviceAgent.handleMessage(topic, message);
|
|
@@ -67,15 +70,14 @@ export const uninstallAppCliLeaf = CliLeaf({
|
|
|
67
70
|
const deviceAgent = new DeviceAgentCloudConnection();
|
|
68
71
|
await deviceAgent.setupHandlers();
|
|
69
72
|
const topic = deviceAgent.getToDeviceTopic();
|
|
70
|
-
const message:
|
|
73
|
+
const message: AppVersionControlMessage = {
|
|
71
74
|
timestamp: '',
|
|
72
75
|
topic,
|
|
76
|
+
messageType: keyMirrors.toDeviceAgentMessageType.app_version_control,
|
|
77
|
+
txId: generateTxId(),
|
|
73
78
|
payload: {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
baseCommand: keyMirrors.appVersionControl.uninstall,
|
|
77
|
-
projectId: project
|
|
78
|
-
}
|
|
79
|
+
baseCommand: keyMirrors.appVersionControl.uninstall,
|
|
80
|
+
projectId: project
|
|
79
81
|
}
|
|
80
82
|
};
|
|
81
83
|
await deviceAgent.handleMessage(topic, message);
|
package/src/util/logger.ts
CHANGED
|
@@ -19,10 +19,14 @@ const transports = ALWAYSAI_LOG_TO_CONSOLE
|
|
|
19
19
|
export const logger = winston.createLogger({
|
|
20
20
|
level: LOG_LEVEL,
|
|
21
21
|
format: winston.format.combine(
|
|
22
|
+
winston.format.timestamp(),
|
|
22
23
|
winston.format.colorize(),
|
|
23
24
|
winston.format.errors({ stack: true }),
|
|
24
25
|
winston.format.splat(),
|
|
25
|
-
winston.format.simple()
|
|
26
|
+
winston.format.simple(),
|
|
27
|
+
winston.format.printf(({ timestamp = '', level = '', message = '' }) => {
|
|
28
|
+
return `[${timestamp}] ${level}: ${message}`;
|
|
29
|
+
})
|
|
26
30
|
),
|
|
27
31
|
transports
|
|
28
32
|
});
|