@alwaysai/device-agent 0.0.16 → 0.0.17

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 (69) hide show
  1. package/lib/application-control/config.d.ts.map +1 -1
  2. package/lib/application-control/config.js +4 -4
  3. package/lib/application-control/config.js.map +1 -1
  4. package/lib/application-control/install.d.ts.map +1 -1
  5. package/lib/application-control/install.js +1 -1
  6. package/lib/application-control/install.js.map +1 -1
  7. package/lib/application-control/models.js +1 -1
  8. package/lib/application-control/utils.d.ts.map +1 -1
  9. package/lib/application-control/utils.js +3 -3
  10. package/lib/application-control/utils.js.map +1 -1
  11. package/lib/cloud-connection/device-agent-cloud-connection.d.ts.map +1 -1
  12. package/lib/cloud-connection/device-agent-cloud-connection.js +28 -15
  13. package/lib/cloud-connection/device-agent-cloud-connection.js.map +1 -1
  14. package/lib/cloud-connection/live-updates-handler.d.ts.map +1 -1
  15. package/lib/cloud-connection/live-updates-handler.js +9 -8
  16. package/lib/cloud-connection/live-updates-handler.js.map +1 -1
  17. package/lib/cloud-connection/shadow-handler.d.ts +9 -5
  18. package/lib/cloud-connection/shadow-handler.d.ts.map +1 -1
  19. package/lib/cloud-connection/shadow-handler.js +14 -6
  20. package/lib/cloud-connection/shadow-handler.js.map +1 -1
  21. package/lib/cloud-connection/shadow-handler.test.js +24 -14
  22. package/lib/cloud-connection/shadow-handler.test.js.map +1 -1
  23. package/lib/cloud-connection/shadow.js +1 -1
  24. package/lib/cloud-connection/shadow.js.map +1 -1
  25. package/lib/subcommands/app/env-vars.d.ts +8 -0
  26. package/lib/subcommands/app/env-vars.d.ts.map +1 -0
  27. package/lib/subcommands/app/env-vars.js +43 -0
  28. package/lib/subcommands/app/env-vars.js.map +1 -0
  29. package/lib/subcommands/app/index.d.ts.map +1 -1
  30. package/lib/subcommands/app/index.js +20 -19
  31. package/lib/subcommands/app/index.js.map +1 -1
  32. package/lib/subcommands/app/models.d.ts +20 -0
  33. package/lib/subcommands/app/models.d.ts.map +1 -0
  34. package/lib/subcommands/app/models.js +114 -0
  35. package/lib/subcommands/app/models.js.map +1 -0
  36. package/lib/subcommands/app/status.d.ts +17 -0
  37. package/lib/subcommands/app/status.d.ts.map +1 -0
  38. package/lib/subcommands/app/status.js +103 -0
  39. package/lib/subcommands/app/status.js.map +1 -0
  40. package/lib/subcommands/app/version.d.ts +12 -0
  41. package/lib/subcommands/app/version.d.ts.map +1 -0
  42. package/lib/subcommands/app/version.js +103 -0
  43. package/lib/subcommands/app/version.js.map +1 -0
  44. package/lib/util/get-device-id.js +1 -1
  45. package/lib/util/get-device-id.js.map +1 -1
  46. package/lib/util/http-client.js +1 -1
  47. package/lib/util/http-client.js.map +1 -1
  48. package/package.json +1 -1
  49. package/src/application-control/config.ts +8 -4
  50. package/src/application-control/install.ts +3 -1
  51. package/src/application-control/models.ts +1 -1
  52. package/src/application-control/utils.ts +3 -4
  53. package/src/cloud-connection/device-agent-cloud-connection.ts +33 -21
  54. package/src/cloud-connection/live-updates-handler.ts +14 -13
  55. package/src/cloud-connection/shadow-handler.test.ts +24 -14
  56. package/src/cloud-connection/shadow-handler.ts +21 -8
  57. package/src/cloud-connection/shadow.ts +1 -1
  58. package/src/subcommands/app/env-vars.ts +46 -0
  59. package/src/subcommands/app/index.ts +16 -17
  60. package/src/subcommands/app/models.ts +129 -0
  61. package/src/subcommands/app/status.ts +92 -0
  62. package/src/subcommands/app/version.ts +103 -0
  63. package/src/util/get-device-id.ts +1 -1
  64. package/src/util/http-client.ts +1 -1
  65. package/lib/subcommands/app/app.d.ts +0 -60
  66. package/lib/subcommands/app/app.d.ts.map +0 -1
  67. package/lib/subcommands/app/app.js +0 -370
  68. package/lib/subcommands/app/app.js.map +0 -1
  69. package/src/subcommands/app/app.ts +0 -390
@@ -1,390 +0,0 @@
1
- import {
2
- CliLeaf,
3
- CliStringArrayInput,
4
- CliStringInput,
5
- CliTerseError
6
- } from '@alwaysai/alwayscli';
7
- import { ClientMessage, keyMirrors } from '@alwaysai/device-agent-schemas';
8
- import {
9
- getAllEnvs,
10
- getAppLogs,
11
- getAppModels,
12
- getAppStatus,
13
- readAppCfgFile,
14
- removeModel,
15
- replaceModels,
16
- restartApp,
17
- rollbackApp,
18
- setEnv,
19
- startApp,
20
- stopApp,
21
- updateModels
22
- } from '../../application-control';
23
- import { DeviceAgentCloudConnection } from '../../cloud-connection/device-agent-cloud-connection';
24
- import { AgentConfigFile } from '../../infrastructure/agent-config';
25
- import { logger } from '../../util/logger';
26
- import sleep from '../../util/sleep';
27
-
28
- export const listAppsCliLeaf = CliLeaf({
29
- name: 'list',
30
- description: 'List all installed apps',
31
- namedInputs: {},
32
- async action(_, opts) {
33
- const apps = await AgentConfigFile().getApps();
34
- console.table(apps);
35
- }
36
- });
37
-
38
- export const listAppReleasesCliLeaf = CliLeaf({
39
- name: 'list-releases',
40
- description: 'List all releases for a given app',
41
- namedInputs: {
42
- project: CliStringInput({
43
- description: 'Project ID',
44
- required: true
45
- })
46
- },
47
- hidden: true,
48
- async action(_, opts) {
49
- throw new CliTerseError('This command is yet currently implemented!');
50
- }
51
- });
52
-
53
- export const listAppLatestReleaseCliLeaf = CliLeaf({
54
- name: 'list-latest-release',
55
- description: 'List the latest release hash for a given app',
56
- namedInputs: {
57
- project: CliStringInput({
58
- description: 'Project ID',
59
- required: true
60
- })
61
- },
62
- hidden: true,
63
- async action(_, opts) {
64
- throw new CliTerseError('This command is yet currently implemented!');
65
- }
66
- });
67
-
68
- export const installAppCliLeaf = CliLeaf({
69
- name: 'install',
70
- description: 'Install an alwaysAI app from a project',
71
- namedInputs: {
72
- project: CliStringInput({
73
- description: 'Project ID',
74
- required: true
75
- }),
76
- releaseHash: CliStringInput({
77
- description: 'Release Hash',
78
- required: true
79
- })
80
- },
81
- async action(_, opts) {
82
- const { project, releaseHash } = opts;
83
- const deviceAgent = new DeviceAgentCloudConnection();
84
- await deviceAgent.setupHandlers();
85
- const topic = deviceAgent.getToDeviceTopic();
86
- const message: ClientMessage = {
87
- timestamp: '',
88
- topic,
89
- payload: {
90
- messageType: keyMirrors.clientMessageType.app_version_control,
91
- appVersionControl: {
92
- baseCommand: keyMirrors.appVersionControl.install,
93
- projectId: project,
94
- appReleaseHash: releaseHash
95
- }
96
- }
97
- };
98
- await deviceAgent.handleMessage(topic, message);
99
- while (deviceAgent.isCmdInProgress(project)) {
100
- await sleep(1000);
101
- }
102
- deviceAgent.stop();
103
- }
104
- });
105
-
106
- export const getAppStatusCliLeaf = CliLeaf({
107
- name: 'status',
108
- description: 'Get the status of an installed alwaysAI app',
109
- namedInputs: {
110
- project: CliStringInput({
111
- description: 'Project ID',
112
- required: true
113
- })
114
- },
115
- async action(_, opts) {
116
- const { project } = opts;
117
- const appStatus = await getAppStatus({ projectId: project });
118
- logger.info(JSON.stringify(appStatus, null, 2));
119
- }
120
- });
121
-
122
- export const startAppCliLeaf = CliLeaf({
123
- name: 'start',
124
- description: 'Start an installed alwaysAI app',
125
- namedInputs: {
126
- project: CliStringInput({
127
- description: 'Project ID',
128
- required: true
129
- }),
130
- dockerLoginToken: CliStringInput({
131
- description: 'Docker login token'
132
- })
133
- },
134
- async action(_, opts) {
135
- const { project, dockerLoginToken } = opts;
136
- await startApp({ projectId: project, dockerLoginToken });
137
- }
138
- });
139
-
140
- export const getAppLogsCliLeaf = CliLeaf({
141
- name: 'logs',
142
- description: 'Get logs for an application',
143
- namedInputs: {
144
- project: CliStringInput({
145
- description: 'Project ID',
146
- required: true
147
- })
148
- },
149
- async action(_, opts) {
150
- const { project } = opts;
151
- const readable = await getAppLogs({ projectId: project });
152
- readable.setEncoding('utf8');
153
- for await (const chunk of readable) {
154
- logger.info(chunk);
155
- }
156
- }
157
- });
158
-
159
- export const stopAppCliLeaf = CliLeaf({
160
- name: 'stop',
161
- description: 'Stop a running alwaysAI app',
162
- namedInputs: {
163
- project: CliStringInput({
164
- description: 'Project ID',
165
- required: true
166
- })
167
- },
168
- async action(_, opts) {
169
- const { project } = opts;
170
- await stopApp({ projectId: project });
171
- }
172
- });
173
-
174
- export const restartAppCliLeaf = CliLeaf({
175
- name: 'restart',
176
- description: 'Restart running alwaysAI app',
177
- namedInputs: {
178
- project: CliStringInput({
179
- description: 'Project ID',
180
- required: true
181
- })
182
- },
183
- async action(_, opts) {
184
- const { project } = opts;
185
- await restartApp({ projectId: project });
186
- }
187
- });
188
-
189
- export const uninstallAppCliLeaf = CliLeaf({
190
- name: 'uninstall',
191
- description: 'Remove an alwaysAI app',
192
- namedInputs: {
193
- project: CliStringInput({
194
- description: 'Project ID',
195
- required: true
196
- })
197
- },
198
- async action(_, opts) {
199
- const { project } = opts;
200
- const deviceAgent = new DeviceAgentCloudConnection();
201
- await deviceAgent.setupHandlers();
202
- const topic = deviceAgent.getToDeviceTopic();
203
- const message: ClientMessage = {
204
- timestamp: '',
205
- topic,
206
- payload: {
207
- messageType: keyMirrors.clientMessageType.app_version_control,
208
- appVersionControl: {
209
- baseCommand: keyMirrors.appVersionControl.uninstall,
210
- projectId: project
211
- }
212
- }
213
- };
214
- await deviceAgent.handleMessage(topic, message);
215
- while (deviceAgent.isCmdInProgress(project)) {
216
- await sleep(1000);
217
- }
218
- deviceAgent.stop();
219
- }
220
- });
221
-
222
- export const rollbackAppCliLeaf = CliLeaf({
223
- name: 'rollback',
224
- description: 'Rollback an alwaysAI app to the previous version',
225
- namedInputs: {
226
- project: CliStringInput({
227
- description: 'Project ID',
228
- required: true
229
- })
230
- },
231
- hidden: true,
232
- async action(_, opts) {
233
- const { project } = opts;
234
- await rollbackApp({ projectId: project });
235
- }
236
- });
237
-
238
- export const showAppModelsCliLeaf = CliLeaf({
239
- name: 'show-models',
240
- description: 'Show the application models',
241
- namedInputs: {
242
- project: CliStringInput({
243
- description: 'Project ID',
244
- required: true
245
- })
246
- },
247
- async action(_, opts) {
248
- const { project } = opts;
249
- const appModels = await getAppModels({ projectId: project });
250
- console.table(appModels);
251
- }
252
- });
253
-
254
- export const addModelCliLeaf = CliLeaf({
255
- name: 'add-model',
256
- description: 'Add a model to an alwaysAI app',
257
- namedInputs: {
258
- project: CliStringInput({
259
- description: 'Project ID',
260
- required: true
261
- }),
262
- model: CliStringInput({
263
- description: 'Model ID',
264
- required: true
265
- }),
266
- version: CliStringInput({
267
- description: 'Model version',
268
- required: true
269
- })
270
- },
271
- async action(_, opts) {
272
- const { project, model, version } = opts;
273
- const deviceAgent = new DeviceAgentCloudConnection();
274
- await deviceAgent.setupHandlers();
275
-
276
- const topic = deviceAgent.getShadowTopics().projects.updateDelta;
277
-
278
- const newAppCfg = await readAppCfgFile({ projectId: project });
279
- newAppCfg.models[model] = Number(version);
280
-
281
- const message = {
282
- version: 3,
283
- timestamp: 0,
284
- state: {
285
- [project]: {
286
- appConfig: JSON.stringify(newAppCfg)
287
- }
288
- },
289
- clientToken: 'not-self'
290
- };
291
-
292
- await deviceAgent.handleMessage(topic, message);
293
- while (deviceAgent.isCmdInProgress(project)) {
294
- await sleep(1000);
295
- }
296
- deviceAgent.stop();
297
- }
298
- });
299
-
300
- export const removeModelCliLeaf = CliLeaf({
301
- name: 'remove-model',
302
- description: 'Remove a model from an alwaysAI app',
303
- namedInputs: {
304
- project: CliStringInput({
305
- description: 'Project ID',
306
- required: true
307
- }),
308
- model: CliStringInput({
309
- description: 'Model ID',
310
- required: true
311
- })
312
- },
313
- async action(_, opts) {
314
- const { project, model } = opts;
315
- await removeModel({ projectId: project, modelId: model });
316
- }
317
- });
318
-
319
- export const replaceModelsCliLeaf = CliLeaf({
320
- name: 'replace-models',
321
- description: 'Replace all models of an alwaysAI app with new models',
322
- namedInputs: {
323
- project: CliStringInput({
324
- description: 'Project Id',
325
- required: true
326
- }),
327
- models: CliStringArrayInput({
328
- description: 'One or more model IDs',
329
- required: true
330
- })
331
- },
332
- async action(_, opts) {
333
- const { project, models } = opts;
334
- await replaceModels({ projectId: project, modelIds: models });
335
- }
336
- });
337
-
338
- export const updateModelsCliLeaf = CliLeaf({
339
- name: 'update-models',
340
- description: 'Update all models for an alwaysAI app',
341
- namedInputs: {
342
- project: CliStringInput({
343
- description: 'Project Id',
344
- required: true
345
- })
346
- },
347
- async action(_, opts) {
348
- const { project } = opts;
349
- await updateModels({ projectId: project });
350
- }
351
- });
352
-
353
- export const getAllEnvsCliLeaf = CliLeaf({
354
- name: 'get-all-envs',
355
- description: 'Get environment variables for an application',
356
- namedInputs: {
357
- project: CliStringInput({
358
- description: 'Project Id',
359
- required: true
360
- })
361
- },
362
- async action(_, opts) {
363
- const { project } = opts;
364
- logger.info(await getAllEnvs({ projectId: project }));
365
- }
366
- });
367
-
368
- export const setEnvCliLeaf = CliLeaf({
369
- name: 'set-env',
370
- description: 'Set environment variables for a service',
371
- positionalInput: CliStringArrayInput({
372
- placeholder: '<NAME=VALUE> [<NAME=VALUE> ...]',
373
- required: true
374
- }),
375
- namedInputs: {
376
- project: CliStringInput({
377
- description: 'Project Id',
378
- required: true
379
- }),
380
- service: CliStringInput({
381
- description:
382
- 'The name of the docker-compose service to apply environment variable to',
383
- required: false
384
- })
385
- },
386
- async action(args, opts) {
387
- const { project, service } = opts;
388
- await setEnv({ projectId: project, vars: args, service });
389
- }
390
- });