@alwaysai/device-agent 1.3.1-1 → 1.3.1-2

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 (34) hide show
  1. package/lib/cloud-connection/device-agent-cloud-connection.d.ts +2 -3
  2. package/lib/cloud-connection/device-agent-cloud-connection.d.ts.map +1 -1
  3. package/lib/cloud-connection/device-agent-cloud-connection.js +76 -87
  4. package/lib/cloud-connection/device-agent-cloud-connection.js.map +1 -1
  5. package/lib/cloud-connection/shadow-handler.d.ts +10 -33
  6. package/lib/cloud-connection/shadow-handler.d.ts.map +1 -1
  7. package/lib/cloud-connection/shadow-handler.js +154 -114
  8. package/lib/cloud-connection/shadow-handler.js.map +1 -1
  9. package/lib/cloud-connection/shadow-handler.test.js +98 -74
  10. package/lib/cloud-connection/shadow-handler.test.js.map +1 -1
  11. package/lib/device-control/device-control.d.ts +2 -2
  12. package/lib/device-control/device-control.d.ts.map +1 -1
  13. package/lib/device-control/device-control.js.map +1 -1
  14. package/lib/secure-tunneling/spawner-detached.d.ts.map +1 -1
  15. package/lib/secure-tunneling/spawner-detached.js +35 -18
  16. package/lib/secure-tunneling/spawner-detached.js.map +1 -1
  17. package/lib/subcommands/app/analytics.d.ts.map +1 -1
  18. package/lib/subcommands/app/analytics.js +9 -13
  19. package/lib/subcommands/app/analytics.js.map +1 -1
  20. package/lib/subcommands/app/env-vars.d.ts.map +1 -1
  21. package/lib/subcommands/app/env-vars.js +11 -16
  22. package/lib/subcommands/app/env-vars.js.map +1 -1
  23. package/lib/subcommands/app/models.d.ts.map +1 -1
  24. package/lib/subcommands/app/models.js +12 -16
  25. package/lib/subcommands/app/models.js.map +1 -1
  26. package/package.json +2 -2
  27. package/src/cloud-connection/device-agent-cloud-connection.ts +81 -100
  28. package/src/cloud-connection/shadow-handler.test.ts +99 -74
  29. package/src/cloud-connection/shadow-handler.ts +237 -152
  30. package/src/device-control/device-control.ts +3 -3
  31. package/src/secure-tunneling/spawner-detached.ts +36 -20
  32. package/src/subcommands/app/analytics.ts +16 -13
  33. package/src/subcommands/app/env-vars.ts +18 -16
  34. package/src/subcommands/app/models.ts +20 -16
@@ -8,6 +8,10 @@ import { EnvVars, getAllEnvs } from '../../application-control';
8
8
  import { DeviceAgentCloudConnection } from '../../cloud-connection/device-agent-cloud-connection';
9
9
  import sleep from '../../util/sleep';
10
10
  import { logger } from '../../util/logger';
11
+ import {
12
+ buildUpdateProjectShadowMessage,
13
+ getShadowTopic
14
+ } from '@alwaysai/device-agent-schemas';
11
15
 
12
16
  export const getAllEnvsCliLeaf = CliLeaf({
13
17
  name: 'get-all-envs',
@@ -43,7 +47,7 @@ export const setEnvCliLeaf = CliLeaf({
43
47
  })
44
48
  },
45
49
  async action(args, opts) {
46
- const { project, service } = opts;
50
+ const { project: projectId, service } = opts;
47
51
  const envVars: EnvVars = { [service]: {} };
48
52
  args.forEach((arg: string) => {
49
53
  const nameVal = arg.split('=');
@@ -56,26 +60,24 @@ export const setEnvCliLeaf = CliLeaf({
56
60
  const deviceAgent = new DeviceAgentCloudConnection();
57
61
  await deviceAgent.setupHandlers();
58
62
 
59
- // Update the shadow as a client
60
- const topic = deviceAgent.getShadowTopics().projects.update;
61
- const packet = {
62
- state: {
63
- desired: {
64
- [project]: {
65
- envVars
66
- }
67
- }
68
- },
69
- clientToken: 'client'
63
+ const toDesire = {
64
+ [projectId]: {
65
+ envVars
66
+ }
70
67
  };
71
- logger.debug(
72
- `Publishing message:\n${JSON.stringify({ topic, packet }, null, 2)}`
68
+ deviceAgent.publisher.publish(
69
+ getShadowTopic(deviceAgent.getClientId(), 'projects', 'update'),
70
+ JSON.stringify(
71
+ buildUpdateProjectShadowMessage({
72
+ clientId: 'client',
73
+ desired: toDesire
74
+ })
75
+ )
73
76
  );
74
- deviceAgent.publisher.publish(topic, JSON.stringify(packet));
75
77
  // Sleep for extra time to ensure time for shadow response
76
78
  await sleep(10000);
77
79
 
78
- while (deviceAgent.isCmdInProgress(project)) {
80
+ while (deviceAgent.isCmdInProgress(projectId)) {
79
81
  await sleep(1000);
80
82
  }
81
83
  await deviceAgent.stop();
@@ -14,6 +14,11 @@ import {
14
14
  import { DeviceAgentCloudConnection } from '../../cloud-connection/device-agent-cloud-connection';
15
15
  import sleep from '../../util/sleep';
16
16
  import { logger } from '../../util/logger';
17
+ import {
18
+ buildUpdateProjectShadowMessage,
19
+ getShadowTopic,
20
+ validateShadowProjectsUpdateAll
21
+ } from '@alwaysai/device-agent-schemas';
17
22
 
18
23
  export const showAppModelsCliLeaf = CliLeaf({
19
24
  name: 'show-models',
@@ -49,34 +54,33 @@ export const addModelCliLeaf = CliLeaf({
49
54
  })
50
55
  },
51
56
  async action(_, opts) {
52
- const { project, model, version } = opts;
57
+ const { project: projectId, model, version } = opts;
53
58
  const deviceAgent = new DeviceAgentCloudConnection();
54
59
  await deviceAgent.setupHandlers();
55
60
 
56
61
  // Update the shadow as a client
57
- const topic = deviceAgent.getShadowTopics().projects.update;
58
62
 
59
- const newAppCfg = await readAppCfgFile({ projectId: project });
63
+ const newAppCfg = await readAppCfgFile({ projectId: projectId });
60
64
  newAppCfg.models[model] = Number(version);
61
65
 
62
- const packet = {
63
- state: {
64
- desired: {
65
- [project]: {
66
- appConfig: JSON.stringify(newAppCfg)
67
- }
68
- }
69
- },
70
- clientToken: 'client'
66
+ const toDesire = {
67
+ [projectId]: {
68
+ appConfig: JSON.stringify(newAppCfg)
69
+ }
71
70
  };
72
- logger.debug(
73
- `Publishing message:\n${JSON.stringify({ topic, packet }, null, 2)}`
71
+ deviceAgent.publisher.publish(
72
+ getShadowTopic(deviceAgent.getClientId(), 'projects', 'update'),
73
+ JSON.stringify(
74
+ buildUpdateProjectShadowMessage({
75
+ clientId: 'client',
76
+ desired: toDesire
77
+ })
78
+ )
74
79
  );
75
- deviceAgent.publisher.publish(topic, JSON.stringify(packet));
76
80
  // Sleep for extra time to ensure time for shadow response
77
81
  await sleep(10000);
78
82
 
79
- while (deviceAgent.isCmdInProgress(project)) {
83
+ while (deviceAgent.isCmdInProgress(projectId)) {
80
84
  await sleep(1000);
81
85
  }
82
86
  await deviceAgent.stop();