@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.
Files changed (84) hide show
  1. package/LICENSE +12 -0
  2. package/lib/application-control/config.d.ts.map +1 -1
  3. package/lib/application-control/config.js +6 -1
  4. package/lib/application-control/config.js.map +1 -1
  5. package/lib/application-control/index.d.ts +2 -2
  6. package/lib/application-control/index.d.ts.map +1 -1
  7. package/lib/application-control/index.js +2 -2
  8. package/lib/application-control/index.js.map +1 -1
  9. package/lib/application-control/install.d.ts +2 -2
  10. package/lib/application-control/install.d.ts.map +1 -1
  11. package/lib/application-control/install.js +10 -0
  12. package/lib/application-control/install.js.map +1 -1
  13. package/lib/application-control/status.d.ts +3 -3
  14. package/lib/application-control/status.d.ts.map +1 -1
  15. package/lib/application-control/status.js +4 -4
  16. package/lib/application-control/status.js.map +1 -1
  17. package/lib/cloud-connection/device-agent-cloud-connection.d.ts +7 -7
  18. package/lib/cloud-connection/device-agent-cloud-connection.d.ts.map +1 -1
  19. package/lib/cloud-connection/device-agent-cloud-connection.js +158 -100
  20. package/lib/cloud-connection/device-agent-cloud-connection.js.map +1 -1
  21. package/lib/cloud-connection/live-updates-handler.d.ts +9 -9
  22. package/lib/cloud-connection/live-updates-handler.d.ts.map +1 -1
  23. package/lib/cloud-connection/live-updates-handler.js +45 -42
  24. package/lib/cloud-connection/live-updates-handler.js.map +1 -1
  25. package/lib/cloud-connection/live-updates-handler.test.js +6 -5
  26. package/lib/cloud-connection/live-updates-handler.test.js.map +1 -1
  27. package/lib/cloud-connection/message-builder.d.ts +7 -0
  28. package/lib/cloud-connection/message-builder.d.ts.map +1 -0
  29. package/lib/cloud-connection/message-builder.js +63 -0
  30. package/lib/cloud-connection/message-builder.js.map +1 -0
  31. package/lib/cloud-connection/messages.d.ts +5 -15
  32. package/lib/cloud-connection/messages.d.ts.map +1 -1
  33. package/lib/cloud-connection/messages.js +22 -31
  34. package/lib/cloud-connection/messages.js.map +1 -1
  35. package/lib/cloud-connection/publisher.d.ts +4 -5
  36. package/lib/cloud-connection/publisher.d.ts.map +1 -1
  37. package/lib/cloud-connection/publisher.js +12 -21
  38. package/lib/cloud-connection/publisher.js.map +1 -1
  39. package/lib/cloud-connection/transaction-queue.d.ts +12 -0
  40. package/lib/cloud-connection/transaction-queue.d.ts.map +1 -0
  41. package/lib/cloud-connection/transaction-queue.js +38 -0
  42. package/lib/cloud-connection/transaction-queue.js.map +1 -0
  43. package/lib/cloud-connection/transaction-queue.test.d.ts +2 -0
  44. package/lib/cloud-connection/transaction-queue.test.d.ts.map +1 -0
  45. package/lib/cloud-connection/transaction-queue.test.js +46 -0
  46. package/lib/cloud-connection/transaction-queue.test.js.map +1 -0
  47. package/lib/local-connection/rabbitmq-connection.d.ts.map +1 -1
  48. package/lib/local-connection/rabbitmq-connection.js +5 -1
  49. package/lib/local-connection/rabbitmq-connection.js.map +1 -1
  50. package/lib/subcommands/app/index.d.ts.map +1 -1
  51. package/lib/subcommands/app/index.js +1 -0
  52. package/lib/subcommands/app/index.js.map +1 -1
  53. package/lib/subcommands/app/models.d.ts +5 -0
  54. package/lib/subcommands/app/models.d.ts.map +1 -1
  55. package/lib/subcommands/app/models.js +42 -1
  56. package/lib/subcommands/app/models.js.map +1 -1
  57. package/lib/subcommands/app/status.js +1 -1
  58. package/lib/subcommands/app/status.js.map +1 -1
  59. package/lib/subcommands/app/version.d.ts.map +1 -1
  60. package/lib/subcommands/app/version.js +9 -11
  61. package/lib/subcommands/app/version.js.map +1 -1
  62. package/lib/util/logger.d.ts.map +1 -1
  63. package/lib/util/logger.js +3 -1
  64. package/lib/util/logger.js.map +1 -1
  65. package/package.json +5 -4
  66. package/readme.md +30 -1
  67. package/src/application-control/config.ts +5 -1
  68. package/src/application-control/index.ts +2 -2
  69. package/src/application-control/install.ts +17 -4
  70. package/src/application-control/status.ts +9 -8
  71. package/src/cloud-connection/device-agent-cloud-connection.ts +225 -132
  72. package/src/cloud-connection/live-updates-handler.test.ts +6 -5
  73. package/src/cloud-connection/live-updates-handler.ts +90 -64
  74. package/src/cloud-connection/message-builder.ts +117 -0
  75. package/src/cloud-connection/messages.ts +27 -35
  76. package/src/cloud-connection/publisher.ts +17 -30
  77. package/src/cloud-connection/transaction-queue.test.ts +55 -0
  78. package/src/cloud-connection/transaction-queue.ts +40 -0
  79. package/src/local-connection/rabbitmq-connection.ts +5 -1
  80. package/src/subcommands/app/index.ts +3 -1
  81. package/src/subcommands/app/models.ts +44 -0
  82. package/src/subcommands/app/status.ts +2 -2
  83. package/src/subcommands/app/version.ts +16 -14
  84. 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
- getAppStatus,
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 getAppStatus({ projectId: project });
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 { ClientMessage, keyMirrors } from '@alwaysai/device-agent-schemas';
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: ClientMessage = {
40
+ const message: AppVersionControlMessage = {
37
41
  timestamp: '',
38
42
  topic,
43
+ messageType: keyMirrors.toDeviceAgentMessageType.app_version_control,
44
+ txId: generateTxId(),
39
45
  payload: {
40
- messageType: keyMirrors.clientMessageType.app_version_control,
41
- appVersionControl: {
42
- baseCommand: keyMirrors.appVersionControl.install,
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: ClientMessage = {
73
+ const message: AppVersionControlMessage = {
71
74
  timestamp: '',
72
75
  topic,
76
+ messageType: keyMirrors.toDeviceAgentMessageType.app_version_control,
77
+ txId: generateTxId(),
73
78
  payload: {
74
- messageType: keyMirrors.clientMessageType.app_version_control,
75
- appVersionControl: {
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);
@@ -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
  });