@alwaysai/device-agent 1.5.0 → 2.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 (273) hide show
  1. package/lib/application-control/config.d.ts.map +1 -1
  2. package/lib/application-control/config.js +8 -3
  3. package/lib/application-control/config.js.map +1 -1
  4. package/lib/application-control/environment-variables.d.ts +1 -5
  5. package/lib/application-control/environment-variables.d.ts.map +1 -1
  6. package/lib/application-control/environment-variables.js +9 -26
  7. package/lib/application-control/environment-variables.js.map +1 -1
  8. package/lib/application-control/environment-variables.test.js +27 -7
  9. package/lib/application-control/environment-variables.test.js.map +1 -1
  10. package/lib/application-control/index.d.ts +4 -4
  11. package/lib/application-control/index.d.ts.map +1 -1
  12. package/lib/application-control/index.js +1 -4
  13. package/lib/application-control/index.js.map +1 -1
  14. package/lib/application-control/install.d.ts.map +1 -1
  15. package/lib/application-control/install.js +8 -7
  16. package/lib/application-control/install.js.map +1 -1
  17. package/lib/application-control/models.d.ts +0 -11
  18. package/lib/application-control/models.d.ts.map +1 -1
  19. package/lib/application-control/models.js +5 -54
  20. package/lib/application-control/models.js.map +1 -1
  21. package/lib/application-control/utils.d.ts +0 -4
  22. package/lib/application-control/utils.d.ts.map +1 -1
  23. package/lib/application-control/utils.js +1 -24
  24. package/lib/application-control/utils.js.map +1 -1
  25. package/lib/cloud-connection/bootstrap-provision.js +3 -2
  26. package/lib/cloud-connection/bootstrap-provision.js.map +1 -1
  27. package/lib/cloud-connection/device-agent-cloud-connection.d.ts +10 -15
  28. package/lib/cloud-connection/device-agent-cloud-connection.d.ts.map +1 -1
  29. package/lib/cloud-connection/device-agent-cloud-connection.js +279 -250
  30. package/lib/cloud-connection/device-agent-cloud-connection.js.map +1 -1
  31. package/lib/cloud-connection/device-agent.d.ts.map +1 -1
  32. package/lib/cloud-connection/device-agent.js +11 -9
  33. package/lib/cloud-connection/device-agent.js.map +1 -1
  34. package/lib/cloud-connection/live-updates-handler.d.ts +18 -28
  35. package/lib/cloud-connection/live-updates-handler.d.ts.map +1 -1
  36. package/lib/cloud-connection/live-updates-handler.js +54 -169
  37. package/lib/cloud-connection/live-updates-handler.js.map +1 -1
  38. package/lib/cloud-connection/live-updates-handler.test.js +71 -165
  39. package/lib/cloud-connection/live-updates-handler.test.js.map +1 -1
  40. package/lib/cloud-connection/passthrough-handler.d.ts +4 -1
  41. package/lib/cloud-connection/passthrough-handler.d.ts.map +1 -1
  42. package/lib/cloud-connection/passthrough-handler.js +30 -11
  43. package/lib/cloud-connection/passthrough-handler.js.map +1 -1
  44. package/lib/cloud-connection/shadow-handler.d.ts +5 -3
  45. package/lib/cloud-connection/shadow-handler.d.ts.map +1 -1
  46. package/lib/cloud-connection/shadow-handler.js +59 -27
  47. package/lib/cloud-connection/shadow-handler.js.map +1 -1
  48. package/lib/cloud-connection/shadow-handler.test.js +45 -57
  49. package/lib/cloud-connection/shadow-handler.test.js.map +1 -1
  50. package/lib/cloud-connection/shadow.d.ts.map +1 -1
  51. package/lib/cloud-connection/shadow.js +2 -1
  52. package/lib/cloud-connection/shadow.js.map +1 -1
  53. package/lib/cloud-connection/transaction-manager.d.ts +4 -2
  54. package/lib/cloud-connection/transaction-manager.d.ts.map +1 -1
  55. package/lib/cloud-connection/transaction-manager.js +18 -29
  56. package/lib/cloud-connection/transaction-manager.js.map +1 -1
  57. package/lib/cloud-connection/transaction-manager.test.js +3 -3
  58. package/lib/cloud-connection/transaction-manager.test.js.map +1 -1
  59. package/lib/device-control/device-control.d.ts +8 -8
  60. package/lib/device-control/device-control.d.ts.map +1 -1
  61. package/lib/device-control/device-control.js +95 -71
  62. package/lib/device-control/device-control.js.map +1 -1
  63. package/lib/docker/docker-compose.d.ts.map +1 -1
  64. package/lib/docker/docker-compose.js +2 -1
  65. package/lib/docker/docker-compose.js.map +1 -1
  66. package/lib/infrastructure/agent-config.d.ts +2 -1
  67. package/lib/infrastructure/agent-config.d.ts.map +1 -1
  68. package/lib/infrastructure/agent-config.js +7 -7
  69. package/lib/infrastructure/agent-config.js.map +1 -1
  70. package/lib/infrastructure/agent-config.test.js +3 -1
  71. package/lib/infrastructure/agent-config.test.js.map +1 -1
  72. package/lib/infrastructure/config-check-utility.d.ts +6 -0
  73. package/lib/infrastructure/config-check-utility.d.ts.map +1 -0
  74. package/lib/infrastructure/config-check-utility.js +67 -0
  75. package/lib/infrastructure/config-check-utility.js.map +1 -0
  76. package/lib/infrastructure/config-check-utility.test.d.ts +2 -0
  77. package/lib/infrastructure/config-check-utility.test.d.ts.map +1 -0
  78. package/lib/infrastructure/config-check-utility.test.js +109 -0
  79. package/lib/infrastructure/config-check-utility.test.js.map +1 -0
  80. package/lib/infrastructure/device-certificate.d.ts +10 -0
  81. package/lib/infrastructure/device-certificate.d.ts.map +1 -0
  82. package/lib/infrastructure/device-certificate.js +47 -0
  83. package/lib/infrastructure/device-certificate.js.map +1 -0
  84. package/lib/infrastructure/device-certificate.test.d.ts +2 -0
  85. package/lib/infrastructure/device-certificate.test.d.ts.map +1 -0
  86. package/lib/infrastructure/device-certificate.test.js +24 -0
  87. package/lib/infrastructure/device-certificate.test.js.map +1 -0
  88. package/lib/infrastructure/legacy-migration/legacy-file.test.d.ts +2 -0
  89. package/lib/infrastructure/legacy-migration/legacy-file.test.d.ts.map +1 -0
  90. package/lib/infrastructure/legacy-migration/legacy-file.test.js +61 -0
  91. package/lib/infrastructure/legacy-migration/legacy-file.test.js.map +1 -0
  92. package/lib/infrastructure/legacy-migration/legacy-files.d.ts +75 -0
  93. package/lib/infrastructure/legacy-migration/legacy-files.d.ts.map +1 -0
  94. package/lib/infrastructure/legacy-migration/legacy-files.js +75 -0
  95. package/lib/infrastructure/legacy-migration/legacy-files.js.map +1 -0
  96. package/lib/infrastructure/legacy-migration/legacy-migration.d.ts +6 -0
  97. package/lib/infrastructure/legacy-migration/legacy-migration.d.ts.map +1 -0
  98. package/lib/infrastructure/legacy-migration/legacy-migration.js +149 -0
  99. package/lib/infrastructure/legacy-migration/legacy-migration.js.map +1 -0
  100. package/lib/infrastructure/legacy-migration/legacy-migration.test.d.ts +2 -0
  101. package/lib/infrastructure/legacy-migration/legacy-migration.test.d.ts.map +1 -0
  102. package/lib/infrastructure/legacy-migration/legacy-migration.test.js +226 -0
  103. package/lib/infrastructure/legacy-migration/legacy-migration.test.js.map +1 -0
  104. package/lib/infrastructure/require-files-present-ready.test.d.ts +2 -0
  105. package/lib/infrastructure/require-files-present-ready.test.d.ts.map +1 -0
  106. package/lib/infrastructure/require-files-present-ready.test.js +44 -0
  107. package/lib/infrastructure/require-files-present-ready.test.js.map +1 -0
  108. package/lib/infrastructure/required-config-checks.d.ts +2 -0
  109. package/lib/infrastructure/required-config-checks.d.ts.map +1 -0
  110. package/lib/infrastructure/required-config-checks.js +30 -0
  111. package/lib/infrastructure/required-config-checks.js.map +1 -0
  112. package/lib/infrastructure/tokens-and-device-cfg.d.ts.map +1 -1
  113. package/lib/infrastructure/tokens-and-device-cfg.js +11 -8
  114. package/lib/infrastructure/tokens-and-device-cfg.js.map +1 -1
  115. package/lib/local-connection/rabbitmq-connection.d.ts.map +1 -1
  116. package/lib/local-connection/rabbitmq-connection.js +14 -14
  117. package/lib/local-connection/rabbitmq-connection.js.map +1 -1
  118. package/lib/secure-tunneling/secure-tunneling.d.ts +9 -9
  119. package/lib/secure-tunneling/secure-tunneling.d.ts.map +1 -1
  120. package/lib/secure-tunneling/secure-tunneling.js +21 -16
  121. package/lib/secure-tunneling/secure-tunneling.js.map +1 -1
  122. package/lib/secure-tunneling/secure-tunneling.test.js +11 -13
  123. package/lib/secure-tunneling/secure-tunneling.test.js.map +1 -1
  124. package/lib/subcommands/app/analytics.d.ts.map +1 -1
  125. package/lib/subcommands/app/analytics.js +1 -2
  126. package/lib/subcommands/app/analytics.js.map +1 -1
  127. package/lib/subcommands/app/env-vars.d.ts +4 -0
  128. package/lib/subcommands/app/env-vars.d.ts.map +1 -1
  129. package/lib/subcommands/app/env-vars.js +52 -6
  130. package/lib/subcommands/app/env-vars.js.map +1 -1
  131. package/lib/subcommands/app/index.d.ts.map +1 -1
  132. package/lib/subcommands/app/index.js +1 -3
  133. package/lib/subcommands/app/index.js.map +1 -1
  134. package/lib/subcommands/app/models.d.ts +0 -11
  135. package/lib/subcommands/app/models.d.ts.map +1 -1
  136. package/lib/subcommands/app/models.js +2 -58
  137. package/lib/subcommands/app/models.js.map +1 -1
  138. package/lib/subcommands/app/shadow.d.ts.map +1 -1
  139. package/lib/subcommands/app/shadow.js +6 -5
  140. package/lib/subcommands/app/shadow.js.map +1 -1
  141. package/lib/subcommands/app/version.d.ts.map +1 -1
  142. package/lib/subcommands/app/version.js +2 -4
  143. package/lib/subcommands/app/version.js.map +1 -1
  144. package/lib/subcommands/config.d.ts +2 -0
  145. package/lib/subcommands/config.d.ts.map +1 -0
  146. package/lib/subcommands/config.js +39 -0
  147. package/lib/subcommands/config.js.map +1 -0
  148. package/lib/subcommands/device/clean.d.ts +1 -1
  149. package/lib/subcommands/device/clean.d.ts.map +1 -1
  150. package/lib/subcommands/device/clean.js +23 -13
  151. package/lib/subcommands/device/clean.js.map +1 -1
  152. package/lib/subcommands/device/index.d.ts.map +1 -1
  153. package/lib/subcommands/device/index.js +3 -1
  154. package/lib/subcommands/device/index.js.map +1 -1
  155. package/lib/subcommands/device/init.js +8 -8
  156. package/lib/subcommands/device/init.js.map +1 -1
  157. package/lib/subcommands/device/migrate.d.ts +2 -0
  158. package/lib/subcommands/device/migrate.d.ts.map +1 -0
  159. package/lib/subcommands/device/migrate.js +24 -0
  160. package/lib/subcommands/device/migrate.js.map +1 -0
  161. package/lib/subcommands/device/refresh.d.ts.map +1 -1
  162. package/lib/subcommands/device/refresh.js +1 -0
  163. package/lib/subcommands/device/refresh.js.map +1 -1
  164. package/lib/subcommands/index.d.ts +1 -1
  165. package/lib/subcommands/index.d.ts.map +1 -1
  166. package/lib/subcommands/index.js +3 -1
  167. package/lib/subcommands/index.js.map +1 -1
  168. package/lib/subcommands/rabbitmq-connection.d.ts +1 -1
  169. package/lib/subcommands/rabbitmq-connection.d.ts.map +1 -1
  170. package/lib/util/aai-error.d.ts +12 -0
  171. package/lib/util/aai-error.d.ts.map +1 -0
  172. package/lib/util/aai-error.js +11 -0
  173. package/lib/util/aai-error.js.map +1 -0
  174. package/lib/util/aws-regions.d.ts +2 -0
  175. package/lib/util/aws-regions.d.ts.map +1 -0
  176. package/lib/util/{cloud-mode-ready.js → aws-regions.js} +2 -20
  177. package/lib/util/aws-regions.js.map +1 -0
  178. package/lib/util/check-for-updates.d.ts.map +1 -1
  179. package/lib/util/check-for-updates.js +5 -28
  180. package/lib/util/check-for-updates.js.map +1 -1
  181. package/lib/util/clean-certs.d.ts.map +1 -1
  182. package/lib/util/clean-certs.js +5 -4
  183. package/lib/util/clean-certs.js.map +1 -1
  184. package/lib/util/directories.d.ts +4 -18
  185. package/lib/util/directories.d.ts.map +1 -1
  186. package/lib/util/directories.js +18 -32
  187. package/lib/util/directories.js.map +1 -1
  188. package/lib/util/file.d.ts +4 -0
  189. package/lib/util/file.d.ts.map +1 -1
  190. package/lib/util/file.js +65 -4
  191. package/lib/util/file.js.map +1 -1
  192. package/lib/util/get-device-id.d.ts.map +1 -1
  193. package/lib/util/get-device-id.js +7 -1
  194. package/lib/util/get-device-id.js.map +1 -1
  195. package/lib/util/http-client.js +3 -3
  196. package/lib/util/http-client.js.map +1 -1
  197. package/package.json +19 -17
  198. package/readme.md +12 -32
  199. package/src/application-control/config.ts +9 -12
  200. package/src/application-control/environment-variables.test.ts +28 -7
  201. package/src/application-control/environment-variables.ts +13 -40
  202. package/src/application-control/index.ts +3 -16
  203. package/src/application-control/install.ts +15 -10
  204. package/src/application-control/models.ts +6 -87
  205. package/src/application-control/utils.ts +0 -28
  206. package/src/cloud-connection/bootstrap-provision.ts +7 -7
  207. package/src/cloud-connection/device-agent-cloud-connection.ts +639 -525
  208. package/src/cloud-connection/device-agent.ts +16 -7
  209. package/src/cloud-connection/live-updates-handler.test.ts +121 -189
  210. package/src/cloud-connection/live-updates-handler.ts +99 -234
  211. package/src/cloud-connection/passthrough-handler.ts +55 -18
  212. package/src/cloud-connection/shadow-handler.test.ts +45 -57
  213. package/src/cloud-connection/shadow-handler.ts +103 -57
  214. package/src/cloud-connection/shadow.ts +4 -1
  215. package/src/cloud-connection/transaction-manager.test.ts +3 -3
  216. package/src/cloud-connection/transaction-manager.ts +53 -39
  217. package/src/device-control/device-control.ts +102 -70
  218. package/src/docker/docker-compose.ts +3 -2
  219. package/src/infrastructure/agent-config.test.ts +6 -2
  220. package/src/infrastructure/agent-config.ts +8 -7
  221. package/src/infrastructure/config-check-utility.test.ts +154 -0
  222. package/src/infrastructure/config-check-utility.ts +77 -0
  223. package/src/infrastructure/device-certificate.test.ts +40 -0
  224. package/src/infrastructure/device-certificate.ts +58 -0
  225. package/src/infrastructure/legacy-migration/legacy-file.test.ts +88 -0
  226. package/src/infrastructure/legacy-migration/legacy-files.ts +101 -0
  227. package/src/infrastructure/legacy-migration/legacy-migration.test.ts +396 -0
  228. package/src/infrastructure/legacy-migration/legacy-migration.ts +229 -0
  229. package/src/infrastructure/require-files-present-ready.test.ts +53 -0
  230. package/src/infrastructure/required-config-checks.ts +33 -0
  231. package/src/infrastructure/tokens-and-device-cfg.ts +12 -10
  232. package/src/local-connection/rabbitmq-connection.ts +22 -17
  233. package/src/secure-tunneling/secure-tunneling.test.ts +20 -22
  234. package/src/secure-tunneling/secure-tunneling.ts +41 -29
  235. package/src/subcommands/app/analytics.ts +2 -4
  236. package/src/subcommands/app/env-vars.ts +72 -9
  237. package/src/subcommands/app/index.ts +3 -11
  238. package/src/subcommands/app/models.ts +5 -81
  239. package/src/subcommands/app/shadow.ts +6 -5
  240. package/src/subcommands/app/version.ts +3 -4
  241. package/src/subcommands/config.ts +42 -0
  242. package/src/subcommands/device/clean.ts +31 -17
  243. package/src/subcommands/device/index.ts +3 -1
  244. package/src/subcommands/device/init.ts +11 -11
  245. package/src/subcommands/device/migrate.ts +20 -0
  246. package/src/subcommands/device/refresh.ts +1 -0
  247. package/src/subcommands/index.ts +3 -1
  248. package/src/util/aai-error.ts +20 -0
  249. package/src/util/{cloud-mode-ready.ts → aws-regions.ts} +0 -24
  250. package/src/util/check-for-updates.ts +14 -30
  251. package/src/util/clean-certs.ts +8 -4
  252. package/src/util/directories.ts +23 -67
  253. package/src/util/file.ts +83 -3
  254. package/src/util/get-device-id.ts +7 -7
  255. package/src/util/http-client.ts +2 -2
  256. package/lib/util/cloud-mode-ready.d.ts +0 -3
  257. package/lib/util/cloud-mode-ready.d.ts.map +0 -1
  258. package/lib/util/cloud-mode-ready.js.map +0 -1
  259. package/lib/util/download-file.d.ts +0 -6
  260. package/lib/util/download-file.d.ts.map +0 -1
  261. package/lib/util/download-file.js +0 -25
  262. package/lib/util/download-file.js.map +0 -1
  263. package/lib/util/fetch-with-timeout.d.ts +0 -4
  264. package/lib/util/fetch-with-timeout.d.ts.map +0 -1
  265. package/lib/util/fetch-with-timeout.js +0 -30
  266. package/lib/util/fetch-with-timeout.js.map +0 -1
  267. package/lib/util/parsing.d.ts +0 -2
  268. package/lib/util/parsing.d.ts.map +0 -1
  269. package/lib/util/parsing.js +0 -17
  270. package/lib/util/parsing.js.map +0 -1
  271. package/src/util/download-file.ts +0 -25
  272. package/src/util/fetch-with-timeout.ts +0 -35
  273. package/src/util/parsing.ts +0 -11
@@ -1,14 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.microServiceHttpClient = exports.httpClient = void 0;
4
- const node_fetch_1 = require("node-fetch");
5
4
  const endpoints_1 = require("../endpoints");
6
5
  const infrastructure_1 = require("alwaysai/lib/infrastructure");
7
6
  const logger_1 = require("../util/logger");
7
+ const util_1 = require("alwaysai/lib/util");
8
8
  async function httpClient(url, method, headers, data) {
9
9
  const options = Object.assign({ method }, (data ? { body: data, headers } : { headers }));
10
10
  try {
11
- const response = await (0, node_fetch_1.default)(url, options);
11
+ const response = await fetch(url, options);
12
12
  const contentType = response.headers.get('content-type');
13
13
  if (contentType === 'application/json') {
14
14
  return await response.json();
@@ -18,7 +18,7 @@ async function httpClient(url, method, headers, data) {
18
18
  }
19
19
  }
20
20
  catch (e) {
21
- logger_1.logger.error(`HTTP Client error for ${url}: ${e.message}`);
21
+ logger_1.logger.error(`HTTP Client error for ${url}:\n${(0, util_1.stringifyError)(e)}`);
22
22
  }
23
23
  }
24
24
  exports.httpClient = httpClient;
@@ -1 +1 @@
1
- {"version":3,"file":"http-client.js","sourceRoot":"","sources":["../../src/util/http-client.ts"],"names":[],"mappings":";;;AAAA,2CAA+B;AAC/B,4CAAsD;AACtD,gEAAsE;AACtE,2CAAwC;AAEjC,KAAK,UAAU,UAAU,CAC9B,GAAW,EACX,MAAc,EACd,OAAY,EACZ,IAAa;IAEb,MAAM,OAAO,mBACX,MAAM,IACH,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAClD,CAAC;IACF,IAAI;QACF,MAAM,QAAQ,GAAG,MAAM,IAAA,oBAAK,EAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAC3C,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QACzD,IAAI,WAAW,KAAK,kBAAkB,EAAE;YACtC,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;SAC9B;QACD,IAAI,WAAY,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE;YACvC,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;SAC9B;KACF;IAAC,OAAO,CAAC,EAAE;QACV,eAAM,CAAC,KAAK,CAAC,yBAAyB,GAAG,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;KAC5D;AACH,CAAC;AAtBD,gCAsBC;AAEM,KAAK,UAAU,sBAAsB,CAC1C,OAAe,EACf,IAAY,EACZ,MAAc,EACd,IAAa;IAEb,MAAM,QAAQ,GAAG,IAAA,kCAAsB,EAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACvD,MAAM,EAAE,wBAAwB,EAAE,GAAG,IAAA,wCAAuB,GAAE,CAAC;IAC/D,MAAM,mBAAmB,GAAG,MAAM,wBAAwB,EAAE,CAAC;IAC7D,OAAO,MAAM,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,mBAAmB,EAAE,IAAI,CAAC,CAAC;AACvE,CAAC;AAVD,wDAUC"}
1
+ {"version":3,"file":"http-client.js","sourceRoot":"","sources":["../../src/util/http-client.ts"],"names":[],"mappings":";;;AAAA,4CAAsD;AACtD,gEAAsE;AACtE,2CAAwC;AACxC,4CAAmD;AAE5C,KAAK,UAAU,UAAU,CAC9B,GAAW,EACX,MAAc,EACd,OAAY,EACZ,IAAa;IAEb,MAAM,OAAO,mBACX,MAAM,IACH,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAClD,CAAC;IACF,IAAI;QACF,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAC3C,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QACzD,IAAI,WAAW,KAAK,kBAAkB,EAAE;YACtC,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;SAC9B;QACD,IAAI,WAAY,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE;YACvC,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;SAC9B;KACF;IAAC,OAAO,CAAC,EAAE;QACV,eAAM,CAAC,KAAK,CAAC,yBAAyB,GAAG,MAAM,IAAA,qBAAc,EAAC,CAAC,CAAC,EAAE,CAAC,CAAC;KACrE;AACH,CAAC;AAtBD,gCAsBC;AAEM,KAAK,UAAU,sBAAsB,CAC1C,OAAe,EACf,IAAY,EACZ,MAAc,EACd,IAAa;IAEb,MAAM,QAAQ,GAAG,IAAA,kCAAsB,EAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACvD,MAAM,EAAE,wBAAwB,EAAE,GAAG,IAAA,wCAAuB,GAAE,CAAC;IAC/D,MAAM,mBAAmB,GAAG,MAAM,wBAAwB,EAAE,CAAC;IAC7D,OAAO,MAAM,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,mBAAmB,EAAE,IAAI,CAAC,CAAC;AACvE,CAAC;AAVD,wDAUC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@alwaysai/device-agent",
3
3
  "description": "The alwaysAI Device Agent",
4
- "version": "1.5.0",
4
+ "version": "2.0.0",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
7
7
  "publishConfig": {
@@ -13,7 +13,7 @@
13
13
  },
14
14
  "engines": {
15
15
  "npm": ">=7.0.0",
16
- "node": ">=16.0.0"
16
+ "node": ">=18.0.0"
17
17
  },
18
18
  "scripts": {
19
19
  "build": "tsc --project tsconfig.build.json",
@@ -34,44 +34,46 @@
34
34
  "publish-provisioning:prod": "node ./scripts/publish-provisioning-scripts.js prod"
35
35
  },
36
36
  "dependencies": {
37
- "@alwaysai/alwayscli": "0.3.2",
38
- "@alwaysai/app-configuration-schemas": "0.1.0",
39
- "@alwaysai/config-nodejs": "0.3.0",
40
- "@alwaysai/device-agent-schemas": "2.3.3",
37
+ "@alwaysai/alwayscli": "0.3.3",
38
+ "@alwaysai/app-configuration-schemas": "0.2.0",
39
+ "@alwaysai/config-nodejs": "0.3.3",
40
+ "@alwaysai/device-agent-schemas": "3.1.0",
41
41
  "@carnesen/coded-error": "0.4.0",
42
42
  "ajv": "8.11.0",
43
- "alwaysai": "2.5.3",
43
+ "alwaysai": "2.6.1",
44
44
  "amqplib": "0.10.3",
45
- "aws-iot-device-sdk": "2.2.12",
46
- "docker-compose": "0.24.3",
45
+ "aws-iot-device-sdk": "2.2.15",
46
+ "docker-compose": "0.24.8",
47
47
  "lodash": "4.17.21",
48
- "node-fetch": "2.6.1",
49
48
  "node-os-utils": "1.3.7",
50
49
  "rimraf": "4.4.0",
50
+ "serialize-error": "8.1.0",
51
51
  "systeminformation": "5.21.13",
52
52
  "uuid": "9.0.0",
53
53
  "winston": "3.13.0",
54
54
  "winston-daily-rotate-file": "5.0.0",
55
- "yaml": "2.2.1"
55
+ "yaml": "2.5.0"
56
56
  },
57
57
  "devDependencies": {
58
- "@alwaysai/eslint-config": "0.1.0",
58
+ "@alwaysai/eslint-config": "0.1.3",
59
59
  "@alwaysai/tsconfig": "0.0.1",
60
60
  "@types/amqplib": "0.10.5",
61
61
  "@types/destroy": "1.0.0",
62
- "@types/jest": "28.1.2",
63
- "@types/node": "16.11.12",
62
+ "@types/jest": "29.1.2",
63
+ "@types/node": "18.11.9",
64
64
  "@types/node-os-utils": "^1.3.4",
65
+ "@types/rimraf": "3.0.2",
65
66
  "@types/sinon": "10.0.6",
67
+ "@types/tar": "6.1.2",
66
68
  "@typescript-eslint/eslint-plugin": "^5.48.0",
67
69
  "@typescript-eslint/parser": "^5.48.0",
68
- "aws-sdk": "^2.1046.0",
70
+ "aws-sdk": "^2.1663.0",
69
71
  "cp-cli": "2.0.0",
70
72
  "get-stream": "6.0.1",
71
- "jest": "28.1.1",
73
+ "jest": "29.7.0",
72
74
  "sinon": "12.0.1",
73
75
  "tempy": "0.7.1",
74
- "ts-jest": "28.0.5",
76
+ "ts-jest": "29.2.3",
75
77
  "ts-mock-imports": "1.3.8",
76
78
  "ts-node": "10.8.1",
77
79
  "typescript": "4.6.4"
package/readme.md CHANGED
@@ -28,7 +28,6 @@ change.
28
28
  - [Control the application](#control-the-application)
29
29
  - [Manage application models](#manage-application-models)
30
30
  - [Update models to new version of the same model ID](#update-models-to-new-version-of-the-same-model-id)
31
- - [Replace models for an application for new ID](#replace-models-for-an-application-for-new-id)
32
31
  - [Manually download a model package](#manually-download-a-model-package)
33
32
  - [Set and update environment variables](#set-and-update-environment-variables)
34
33
  - [Device Cleaning and Uninstalling](#device-cleaning-and-uninstalling)
@@ -86,15 +85,18 @@ Provisioning the device performs the following:
86
85
  Run the following command on the target device to provision it:
87
86
 
88
87
  ```bash
89
- $ curl -fsSL https://artifacts.alwaysai.co/device-agent/provision.sh | bash -s -- --email <email> --password <password> [--device-name <device_name>]
88
+ $ curl -fsSL https://artifacts.alwaysai.co/device-agent/provision.sh | bash -s -- --email <email> --password <password> [--device-name <device_name>] [--pm2-overwrite] [--agent-tag <agent_tag>]
90
89
  ```
91
90
 
92
- Where:
93
- * `email` is the email associated with your alwaysAI account.
94
- * `password` is the password for your alwaysAI account.
95
- * `device_name` is an optional device name, which will be displayed on the
96
- devices page of the alwaysAI Dashboard. If a device name is not provided, one
97
- will be generated for you and logged to the console for reference.
91
+
92
+ | Options | Details |
93
+ |:----------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
94
+ | --email | [REQUIRED] The email associated with your alwaysAI account. |
95
+ | --password | [REQUIRED] The password associated with your alwaysAI account |
96
+ | --device-name | [OPTIONAL] A device name to be associated with this device. It will be displayed on the devices page of the alwaysAI Dashboard. If a device name is not provided, one will be generated for you and logged to the console for reference. |
97
+ | --pm2-overwrite | [OPTIONAL] Overwrite any existing pm2 configuration with the latest provided by the script. The default behavior is to leave existing pm2 configurations as-is. |
98
+ | --agent-tag | [OPTIONAL] Select a specific release tag for the alwaysAI Device Agent. The default option is latest, which tracks the latest production release from alwaysAI. |
99
+
98
100
 
99
101
  **Important note**: If your password contains one or more special characters and you receive an error message that your password does not match your username but you are sure that it is correctly entered, please try preceding every special character in your password with a backslash, and re-running the provisioning command. You can also reset your password at https://console.alwaysai.co/dashboard by logging out, navigating to the sign in page, and clicking '`Forgot Password?`'.
100
102
 
@@ -303,7 +305,6 @@ Subcommands:
303
305
  app uninstall : Remove an alwaysAI app
304
306
  app show-models : Show the application models
305
307
  app add-model : Add a model to an alwaysAI app
306
- app remove-model : Remove a model from an alwaysAI app
307
308
  app get-all-envs : Get environment variables for an application
308
309
  app set-env : Set environment variables for a service
309
310
  app get-analytics-cfg : Get analytics configuration for an application
@@ -362,32 +363,11 @@ There are several ways to manage the models for your application.
362
363
  #### Update models to new version of the same model ID
363
364
 
364
365
  If a new version of a model is published for an existing model ID, and an
365
- application is already configured to be using that model ID, updating to the
366
+ application is already configured to be using that model ID, updating the
366
367
  new model can simply be done with:
367
368
 
368
369
  ```bash
369
- $ aai-agent app stop --project <project_id>
370
- $ aai-agent app update-models --project <project_id>
371
- $ aai-agent app start --project <project_id>
372
- ```
373
-
374
- #### Replace models for an application for new ID
375
-
376
- If you'd like to install an entirely new model to an application, replacing the
377
- model the app was originally configured with, run the following command:
378
-
379
- ```bash
380
- $ aai-agent app stop --project <project_id>
381
- $ aai-agent app replace-models --project <project_id> --models <model_id_1> [<model_id_2> ...]
382
- $ aai-agent app start --project <project_id>
383
- ```
384
-
385
- If you plan on using this method, you can make your application source model ID
386
- agnostic by providing the model ID to edgeIQ in the following way:
387
-
388
- Select the first model in the config list:
389
- ```python
390
- obj_detect = edgeiq.ObjectDetection(edgeiq._globals.MODEL_ID_LIST[0])
370
+ $ aai-agent app add-model --project <ProjectID> --model <ModelID> --version <ModelVersion>
391
371
  ```
392
372
 
393
373
  #### Manually download a model package
@@ -6,13 +6,14 @@ import {
6
6
  requireAppInstalled,
7
7
  requireAppReady
8
8
  } from './utils';
9
- import { JsSpawner } from 'alwaysai/lib/util';
9
+ import { JsSpawner, stringifyError } from 'alwaysai/lib/util';
10
10
  import { compose } from '../docker/docker-compose';
11
11
  import { assign, merge } from 'lodash';
12
12
  import { AppJsonFile } from 'alwaysai/lib/core/app';
13
13
  import { AppConfig } from '@alwaysai/app-configuration-schemas';
14
14
  import { isAppStarted, restartApp } from './status';
15
15
  import { logger } from '../util/logger';
16
+ import AaiError from '../util/aai-error';
16
17
 
17
18
  export async function readAppCfgFile(props: {
18
19
  projectId: string;
@@ -27,11 +28,9 @@ export async function readAppCfgFile(props: {
27
28
  try {
28
29
  return appJson.read();
29
30
  } catch (e) {
30
- throw new Error(
31
- `Error reading app config for ${projectId}:\n${
32
- e.message
33
- }\n${appJson.getErrors()}`
34
- );
31
+ throw new AaiError(`Error reading app config for ${projectId}`, {
32
+ cause: appJson.getErrors()
33
+ });
35
34
  }
36
35
  }
37
36
 
@@ -45,11 +44,9 @@ export async function writeAppCfgFile(props: {
45
44
  try {
46
45
  appJson.write(appCfg);
47
46
  } catch (e) {
48
- throw new Error(
49
- `Error writing app config for ${projectId}:\n${
50
- e.message
51
- }\n${appJson.getErrors()}`
52
- );
47
+ throw new AaiError(`Error writing app config for ${projectId}`, {
48
+ cause: appJson.getErrors()
49
+ });
53
50
  }
54
51
  }
55
52
 
@@ -124,7 +121,7 @@ export async function writeDockerCompose(props: {
124
121
  try {
125
122
  await compose.config({ cwd: appDir, configAsString: composeOutput });
126
123
  } catch (e) {
127
- logger.error(JSON.stringify(e));
124
+ logger.error(stringifyError(e));
128
125
  }
129
126
  await spawner.writeFile('docker-compose.yaml', composeOutput);
130
127
  }
@@ -91,6 +91,24 @@ describe('Test environment variable get and set', () => {
91
91
  edgeiq: { TEST3: '5', TEST4: '6' }
92
92
  });
93
93
  });
94
+ test('get all envs with one service and one cleared env', async () => {
95
+ const compose = {
96
+ services: {
97
+ alwaysai: {
98
+ environment: ['TEST=', 'TEST2=2']
99
+ }
100
+ }
101
+ };
102
+ jest.mocked(readDockerCompose).mockResolvedValue(compose);
103
+
104
+ const envVars = await getAllEnvs({ projectId: projectId1 });
105
+ expect(jest.mocked(readDockerCompose)).toBeCalledWith({
106
+ projectId: projectId1
107
+ });
108
+ expect(envVars).toEqual({
109
+ alwaysai: { TEST: '', TEST2: '2' }
110
+ });
111
+ });
94
112
  });
95
113
  describe('Test setEnv()', () => {
96
114
  test('Set one env', async () => {
@@ -126,7 +144,7 @@ describe('Test environment variable get and set', () => {
126
144
  };
127
145
  jest.mocked(readDockerCompose).mockResolvedValue(compose);
128
146
 
129
- const envVars = { alwaysai: { TEST1: '2' } };
147
+ const envVars = { alwaysai: { TEST1: '2', TEST2: '2' } };
130
148
  await setEnv({ projectId: projectId1, envVars });
131
149
  expect(jest.mocked(readDockerCompose)).toBeCalledWith({
132
150
  projectId: projectId1
@@ -152,7 +170,10 @@ describe('Test environment variable get and set', () => {
152
170
  };
153
171
  jest.mocked(readDockerCompose).mockResolvedValue(compose);
154
172
 
155
- const envVars = { alwaysai: { TEST1: '2' } };
173
+ const envVars = {
174
+ alwaysai: { TEST1: '2', TEST2: '4' },
175
+ other: { OTHER_TEST: '1' }
176
+ };
156
177
  await setEnv({ projectId: projectId1, envVars });
157
178
  expect(jest.mocked(readDockerCompose)).toBeCalledWith({
158
179
  projectId: projectId1
@@ -171,7 +192,7 @@ describe('Test environment variable get and set', () => {
171
192
  }
172
193
  });
173
194
  });
174
- test('Remove one env', async () => {
195
+ test('Unset an envvar', async () => {
175
196
  const environment = ['TEST1=1', 'TEST2=2'];
176
197
  const compose = {
177
198
  services: {
@@ -180,7 +201,7 @@ describe('Test environment variable get and set', () => {
180
201
  };
181
202
  jest.mocked(readDockerCompose).mockResolvedValue(compose);
182
203
 
183
- const envVars = { alwaysai: { TEST1: null } };
204
+ const envVars = { alwaysai: { TEST1: '', TEST2: '2' } };
184
205
  await setEnv({ projectId: projectId1, envVars });
185
206
  expect(jest.mocked(readDockerCompose)).toBeCalledWith({
186
207
  projectId: projectId1
@@ -190,7 +211,7 @@ describe('Test environment variable get and set', () => {
190
211
  dockerCompose: {
191
212
  services: {
192
213
  alwaysai: {
193
- environment: ['TEST2=2']
214
+ environment: ['TEST1=', 'TEST2=2']
194
215
  }
195
216
  }
196
217
  }
@@ -199,12 +220,12 @@ describe('Test environment variable get and set', () => {
199
220
  });
200
221
  describe('Test helpers', () => {
201
222
  test('convertStringEnvsToKeyVal', () => {
202
- const stringEnvs: string[] = ['TEST1=', 'TEST2=test2', 'TEST3=null'];
223
+ const stringEnvs: string[] = ['TEST1=', 'TEST2=test2', 'TEST3='];
203
224
  const envVars = convertStringEnvsToKeyVal(stringEnvs);
204
225
  expect(envVars).toEqual({
205
226
  TEST1: '',
206
227
  TEST2: 'test2',
207
- TEST3: 'null'
228
+ TEST3: ''
208
229
  });
209
230
  });
210
231
  });
@@ -4,13 +4,7 @@ import { buildApp, getAppDir, requireAppReady } from './utils';
4
4
  import { logger } from '../util/logger';
5
5
  import { AgentConfigFile } from '../infrastructure/agent-config';
6
6
  import { isAppStarted, restartApp } from './status';
7
- import { replaceFalseyWithNull } from '../util/parsing';
8
-
9
- export interface EnvVars {
10
- [service: string]: {
11
- [name: string]: string | null;
12
- };
13
- }
7
+ import { EnvVars } from '@alwaysai/device-agent-schemas';
14
8
 
15
9
  export async function setEnv(props: { projectId: string; envVars: EnvVars }) {
16
10
  const { projectId, envVars } = props;
@@ -28,44 +22,27 @@ export async function setEnv(props: { projectId: string; envVars: EnvVars }) {
28
22
  throw new Error(`Docker compose file for ${projectId} has no services!`);
29
23
  }
30
24
  const services: string[] = Object.keys(envVars);
31
- for (const s of services) {
32
- if (!Object.keys(composeParsed['services']).includes(s)) {
25
+ const composeServices = composeParsed['services'];
26
+
27
+ services.forEach((s) => {
28
+ if (!Object.keys(composeServices).includes(s)) {
33
29
  throw new Error(
34
- `Service ${s} not found in ${JSON.stringify(
35
- composeParsed['services'],
36
- null,
37
- 2
38
- )}`
30
+ `Service ${s} not found in ${JSON.stringify(composeServices, null, 2)}`
39
31
  );
40
32
  }
41
33
 
42
- const service = composeParsed['services'][s];
43
- const oldEnv: string[] | undefined = service['environment'];
34
+ const service = composeServices[s];
44
35
  const envVarsForService = envVars[s];
45
36
 
46
- const newEnvVarsObj = {};
47
- oldEnv?.forEach((envVarStr: string) => {
48
- const envVarSplit = envVarStr.split('=');
49
- const key = envVarSplit[0];
50
- const value = envVarSplit[1];
51
- if (envVarsForService[key] !== null) {
52
- newEnvVarsObj[key] = value;
37
+ const envVarList: string[] = Object.keys(envVarsForService).map(
38
+ (envVar) => {
39
+ const value = envVarsForService[envVar];
40
+ return `${envVar}=${value}`;
53
41
  }
54
- });
55
-
56
- for (const envVar of Object.keys(envVarsForService)) {
57
- if (envVarsForService[envVar] !== null) {
58
- newEnvVarsObj[envVar] = envVarsForService[envVar];
59
- }
60
- }
61
-
62
- const envVarList: string[] = [];
63
- for (const envVar of Object.keys(newEnvVarsObj)) {
64
- envVarList.push(`${envVar}=${newEnvVarsObj[envVar]}`);
65
- }
42
+ );
66
43
 
67
44
  service['environment'] = envVarList;
68
- }
45
+ });
69
46
 
70
47
  await writeDockerCompose({ projectId, dockerCompose: composeParsed });
71
48
 
@@ -138,9 +115,5 @@ export async function getAllEnvs(props: {
138
115
  }
139
116
  }
140
117
  }
141
-
142
- // Device shadow needs null to delete
143
- replaceFalseyWithNull(envVars, true);
144
-
145
118
  return envVars;
146
119
  }
@@ -9,7 +9,7 @@ import {
9
9
  restartApp
10
10
  } from './status';
11
11
  import { ModelDetails } from './types';
12
- import { EnvVars, getAllEnvs, setEnv } from './environment-variables';
12
+ import { getAllEnvs, setEnv } from './environment-variables';
13
13
 
14
14
  export {
15
15
  readAppCfgFile,
@@ -23,24 +23,11 @@ export {
23
23
  stopApp,
24
24
  restartApp,
25
25
  ModelDetails,
26
- EnvVars,
27
26
  getAllEnvs,
28
27
  setEnv
29
28
  };
30
29
 
31
30
  // CLI-mode only
32
- import {
33
- getAppModels,
34
- removeModel,
35
- replaceModels,
36
- updateModels,
37
- updateModelsWithPresignedUrls
38
- } from './models';
31
+ import { getAppModels, updateModelsWithPresignedUrls } from './models';
39
32
 
40
- export {
41
- getAppModels,
42
- removeModel,
43
- replaceModels,
44
- updateModels,
45
- updateModelsWithPresignedUrls
46
- };
33
+ export { getAppModels, updateModelsWithPresignedUrls };
@@ -2,8 +2,8 @@ import { rimraf } from 'rimraf';
2
2
  import * as fs from 'fs';
3
3
  import * as path from 'path';
4
4
  import { buildDockerImage } from 'alwaysai/lib/util/docker';
5
- import { JsSpawner, Spawner } from 'alwaysai/lib/util';
6
- import { getAppDir, downloadPackageUsingPresignedUrl, buildApp } from './utils';
5
+ import { JsSpawner, Spawner, stringifyError } from 'alwaysai/lib/util';
6
+ import { getAppDir, buildApp } from './utils';
7
7
  import { AppDetails } from '@alwaysai/device-agent-schemas';
8
8
  import { BACKUP_EXT } from './backup';
9
9
  import { startApp, stopApp, isAppStarted } from './status';
@@ -15,7 +15,7 @@ import {
15
15
  TargetJsonFile,
16
16
  appCleanDocker,
17
17
  getPythonVenvPaths,
18
- installPythonVenv,
18
+ createPythonVenv,
19
19
  installPythonReqs
20
20
  } from 'alwaysai/lib/core/app';
21
21
  import { DOCKER_IMAGE_ID_INITIAL_VALUE } from 'alwaysai/lib/constants';
@@ -29,6 +29,7 @@ import {
29
29
  LOCAL_CONNECTION_ROUTING_KEY
30
30
  } from '../local-connection/constants';
31
31
  import { DOCKERFILE, PYTHON_REQUIREMENTS_FILE_NAME } from 'alwaysai/lib/paths';
32
+ import { downloadToFile } from '../util/file';
32
33
 
33
34
  type SignedUrlPayloadType = {
34
35
  appInstallPayload: {
@@ -72,9 +73,11 @@ export async function installApp(props: {
72
73
  logger.info('Application currently running. Stopping...');
73
74
  try {
74
75
  await stopApp({ projectId });
75
- } catch (error) {
76
+ } catch (e) {
76
77
  logger.error(
77
- 'Could not stop the application. Old container might still be present after installation.'
78
+ `Could not stop the application. Old container might still be present after installation.\n${stringifyError(
79
+ e
80
+ )}`
78
81
  );
79
82
  }
80
83
  }
@@ -96,9 +99,9 @@ export async function installApp(props: {
96
99
  // download app package
97
100
  const localDest = path.join(appDir, `${path.basename(appReleaseHash)}.tgz`);
98
101
  const { appSignedUrl } = signedUrlsPayload.appInstallPayload;
99
- await downloadPackageUsingPresignedUrl({
100
- localDest,
101
- presignedUrl: appSignedUrl
102
+ await downloadToFile({
103
+ path: localDest,
104
+ url: appSignedUrl
102
105
  });
103
106
 
104
107
  // Unpack app package and remove tar file
@@ -176,7 +179,7 @@ async function installAppBuildReqs(props: { appDir: string }) {
176
179
 
177
180
  const targetSpawner = targetJsonFile.readContainerSpawner();
178
181
  const pythonVenvPaths = await getPythonVenvPaths({ targetCfg });
179
- await installPythonVenv({ targetSpawner, pythonVenvPaths, logger });
182
+ await createPythonVenv({ targetSpawner, pythonVenvPaths, logger });
180
183
  if (await hostSpawner.exists(PYTHON_REQUIREMENTS_FILE_NAME)) {
181
184
  await installPythonReqs({
182
185
  reqFilePath: PYTHON_REQUIREMENTS_FILE_NAME,
@@ -236,7 +239,9 @@ export async function uninstallApp(props: {
236
239
  await stopApp({ projectId });
237
240
  } catch (e) {
238
241
  logger.warn(
239
- `Failed to stop ${projectId}, may be left running...\n${e.message}`
242
+ `Failed to stop ${projectId}, may be left running...\n${stringifyError(
243
+ e
244
+ )}`
240
245
  );
241
246
  }
242
247
  await AgentConfigFile().setAppUninstalled({ projectId });
@@ -1,29 +1,17 @@
1
1
  import { ModelInstallPayload } from '@alwaysai/device-agent-schemas';
2
- import {
3
- appModelsAddComponent,
4
- appModelsRemoveAllComponent,
5
- appModelsRemoveComponent,
6
- appModelsUpdateComponent
7
- } from 'alwaysai/lib/components/app';
8
2
  import { JsSpawner } from 'alwaysai/lib/util';
9
3
  import { logger } from '../util/logger';
10
4
  import { existsSync, createReadStream } from 'fs';
11
5
  import { join, dirname } from 'path';
12
6
  import { AgentConfigFile } from '../infrastructure/agent-config';
13
7
  import { copyDir } from '../util/copy-dir';
14
- import { runInDir } from '../util/run-in-dir';
15
8
  import { isAppStarted, restartApp } from './status';
16
9
  import { ModelDetails } from './types';
17
- import {
18
- buildApp,
19
- downloadPackageUsingPresignedUrl,
20
- getAppDir,
21
- requireAppReady
22
- } from './utils';
10
+ import { buildApp, getAppDir, requireAppReady } from './utils';
23
11
  import { MODEL_JSON_FILE_NAME } from 'alwaysai/lib/core/model';
24
12
  import { writeAppCfgFile } from './config';
25
13
  import { APP_MODELS_DIRECTORY_NAME } from 'alwaysai/lib/paths';
26
- import { pruneDir } from '../util/file';
14
+ import { downloadToFile, pruneDir } from '../util/file';
27
15
  import { AppConfig } from '@alwaysai/app-configuration-schemas';
28
16
 
29
17
  export async function getAppModels(props: { projectId: string }) {
@@ -48,75 +36,6 @@ export async function getAppModels(props: { projectId: string }) {
48
36
  return modelDetails;
49
37
  }
50
38
 
51
- export async function removeModel(props: {
52
- projectId: string;
53
- modelId: string;
54
- }) {
55
- const { projectId, modelId } = props;
56
- await requireAppReady({ projectId });
57
-
58
- const appDir = getAppDir(projectId);
59
-
60
- await runInDir(
61
- appModelsRemoveComponent,
62
- [
63
- {
64
- id: modelId,
65
- purge: true,
66
- removeFromProject: false
67
- }
68
- ],
69
- appDir
70
- );
71
- }
72
-
73
- export async function replaceModels(props: {
74
- projectId: string;
75
- modelIds: string[];
76
- }) {
77
- const { projectId, modelIds } = props;
78
- await requireAppReady({ projectId });
79
-
80
- const appDir = getAppDir(projectId);
81
-
82
- await runInDir(
83
- appModelsRemoveAllComponent,
84
- [
85
- {
86
- purge: true,
87
- removeFromProject: false
88
- }
89
- ],
90
- appDir
91
- );
92
- const modelsAddPromises: Promise<void>[] = [];
93
- for (const modelId of modelIds) {
94
- modelsAddPromises.push(
95
- appModelsAddComponent({
96
- yes: false,
97
- dir: appDir,
98
- id: modelId,
99
- addToProject: false
100
- })
101
- );
102
- }
103
- await Promise.all(modelsAddPromises);
104
-
105
- await buildApp({ appDir });
106
- }
107
-
108
- export async function updateModels(props: { projectId: string }) {
109
- const { projectId } = props;
110
- await requireAppReady({ projectId });
111
-
112
- const appDir = getAppDir(projectId);
113
- await appModelsUpdateComponent({
114
- yes: false,
115
- dir: appDir
116
- });
117
- await buildApp({ appDir });
118
- }
119
-
120
39
  export async function installModelsWithPresignedURLs(
121
40
  modelPayloads: ModelInstallPayload[],
122
41
  targetDir: string
@@ -130,9 +49,9 @@ export async function installModelsWithPresignedURLs(
130
49
  const modelDest = join(targetDir, payload.id);
131
50
  await spawner.mkdirp(modelDest);
132
51
  const localDest = join(modelDest, `${payload.version}.tar.gz`);
133
- await downloadPackageUsingPresignedUrl({
134
- localDest,
135
- presignedUrl: payload.modelSignedUrl
52
+ await downloadToFile({
53
+ path: localDest,
54
+ url: payload.modelSignedUrl
136
55
  });
137
56
  await spawner.untar(createReadStream(localDest), dirname(modelDest));
138
57
  await updateModelJson(modelDest, (modelJson) => ({
@@ -222,7 +141,7 @@ export async function pruneModels(props: {
222
141
  }) {
223
142
  const { projectId, appCfg, path } = props;
224
143
 
225
- const modelsPath = path || join(getAppDir(projectId), 'models');
144
+ const modelsPath = path ?? join(getAppDir(projectId), 'models');
226
145
 
227
146
  if (!existsSync(modelsPath)) {
228
147
  logger.error(