@diafunc/cli 0.2.0 → 0.3.1

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.
@@ -4,7 +4,7 @@ import { Command } from "commander";
4
4
  // package.json
5
5
  var package_default = {
6
6
  name: "@diafunc/cli",
7
- version: "0.2.0",
7
+ version: "0.3.1",
8
8
  description: "Diafunc CLI \u2014 command-line interface for the Diafunc platform",
9
9
  type: "module",
10
10
  bin: {
@@ -660,37 +660,7 @@ function createAdminService(client) {
660
660
  },
661
661
  // (Backup methods moved to storage service — see src/client/services/storage.ts.
662
662
  // Backup endpoints live under @RestApi("storage") on the platform.)
663
- // Analyses
664
- async getLastAnalysis() {
665
- return client.request({
666
- method: "GET",
667
- service: SERVICE,
668
- path: "/analyses/last"
669
- });
670
- },
671
- async getRecentAnalyses(count = 20) {
672
- return client.request({
673
- method: "GET",
674
- service: SERVICE,
675
- path: "/analyses/recent",
676
- query: { count }
677
- });
678
- },
679
- async getAnalysis(analysisId) {
680
- return client.request({
681
- method: "GET",
682
- service: SERVICE,
683
- path: `/analyses/${encodeURIComponent(analysisId)}`
684
- });
685
- },
686
- async saveAnalysis(analysis) {
687
- return client.request({
688
- method: "POST",
689
- service: SERVICE,
690
- path: "/analyses/",
691
- body: analysis
692
- });
693
- },
663
+ // Analyses moved to the analysis service (see src/client/services/analysis.ts).
694
664
  // Utilization
695
665
  async getActualUtilization() {
696
666
  return client.request({
@@ -1069,8 +1039,157 @@ function registerStatusCommand(parent) {
1069
1039
  // src/commands/auth/token.ts
1070
1040
  import chalk6 from "chalk";
1071
1041
 
1042
+ // src/client/services/analysis.ts
1043
+ var SERVICE2 = "analyses";
1044
+ var RUNS_SERVICE = "runs";
1045
+ var PRESETS_SERVICE = "analysis-presets";
1046
+ var TRIGGERS_SERVICE = "triggers";
1047
+ function createAnalysisService(client) {
1048
+ return {
1049
+ async getLast() {
1050
+ return client.request({
1051
+ method: "GET",
1052
+ service: SERVICE2,
1053
+ path: "/last"
1054
+ });
1055
+ },
1056
+ async getRecent(count = 20) {
1057
+ return client.request({
1058
+ method: "GET",
1059
+ service: SERVICE2,
1060
+ path: "/recent",
1061
+ query: { count }
1062
+ });
1063
+ },
1064
+ async get(analysisId) {
1065
+ return client.request({
1066
+ method: "GET",
1067
+ service: SERVICE2,
1068
+ path: `/${encodeURIComponent(analysisId)}`
1069
+ });
1070
+ },
1071
+ async save(analysis) {
1072
+ return client.request({
1073
+ method: "POST",
1074
+ service: SERVICE2,
1075
+ path: "/",
1076
+ body: analysis
1077
+ });
1078
+ },
1079
+ /**
1080
+ * Combined create-and-run in one round-trip. Body is a fresh recipe (analysisId
1081
+ * must be null); server saves it and queues a run. Returns AnalysisRun with
1082
+ * analysisId populated. Preferred over save+rerun for one-shot tools.
1083
+ */
1084
+ async createAndRun(analysis) {
1085
+ return client.request({
1086
+ method: "POST",
1087
+ service: SERVICE2,
1088
+ path: "/runs",
1089
+ body: analysis
1090
+ });
1091
+ },
1092
+ /**
1093
+ * Enqueues a new run for an existing analysis recipe. Returns the newly created
1094
+ * run in state QUEUED; the dispatcher pool picks it up within ~5s and transitions
1095
+ * it through DISPATCHING -> RUNNING -> COMPLETED / FAILED. Poll getRun(runId) to
1096
+ * follow progress.
1097
+ */
1098
+ async rerun(analysisId) {
1099
+ return client.request({
1100
+ method: "POST",
1101
+ service: SERVICE2,
1102
+ path: `/${encodeURIComponent(analysisId)}/runs`
1103
+ });
1104
+ },
1105
+ async getRunsForAnalysis(analysisId, count = 20) {
1106
+ return client.request({
1107
+ method: "GET",
1108
+ service: SERVICE2,
1109
+ path: `/${encodeURIComponent(analysisId)}/runs`,
1110
+ query: { count }
1111
+ });
1112
+ },
1113
+ async getRun(runId) {
1114
+ return client.request({
1115
+ method: "GET",
1116
+ service: RUNS_SERVICE,
1117
+ path: `/${encodeURIComponent(runId)}`
1118
+ });
1119
+ },
1120
+ async cancelRun(runId) {
1121
+ return client.request({
1122
+ method: "POST",
1123
+ service: RUNS_SERVICE,
1124
+ path: `/${encodeURIComponent(runId)}/cancel`
1125
+ });
1126
+ },
1127
+ // ---------- presets ----------
1128
+ async getPresets() {
1129
+ return client.request({
1130
+ method: "GET",
1131
+ service: PRESETS_SERVICE,
1132
+ path: "/"
1133
+ });
1134
+ },
1135
+ async getPreset(presetId) {
1136
+ return client.request({
1137
+ method: "GET",
1138
+ service: PRESETS_SERVICE,
1139
+ path: `/${encodeURIComponent(presetId)}`
1140
+ });
1141
+ },
1142
+ async savePreset(preset) {
1143
+ return client.request({
1144
+ method: "POST",
1145
+ service: PRESETS_SERVICE,
1146
+ path: "/",
1147
+ body: preset
1148
+ });
1149
+ },
1150
+ async deletePreset(presetId) {
1151
+ await client.request({
1152
+ method: "DELETE",
1153
+ service: PRESETS_SERVICE,
1154
+ path: `/${encodeURIComponent(presetId)}`
1155
+ });
1156
+ },
1157
+ // ---------- triggers ----------
1158
+ async createTrigger(analysisId, body) {
1159
+ return client.request({
1160
+ method: "POST",
1161
+ service: SERVICE2,
1162
+ path: `/${encodeURIComponent(analysisId)}/triggers`,
1163
+ body
1164
+ });
1165
+ },
1166
+ async listTriggers(analysisId) {
1167
+ return client.request({
1168
+ method: "GET",
1169
+ service: SERVICE2,
1170
+ path: `/${encodeURIComponent(analysisId)}/triggers`
1171
+ });
1172
+ },
1173
+ async updateTrigger(triggerId, body) {
1174
+ return client.request({
1175
+ method: "PATCH",
1176
+ service: TRIGGERS_SERVICE,
1177
+ path: `/${encodeURIComponent(triggerId)}`,
1178
+ body
1179
+ });
1180
+ },
1181
+ async deleteTrigger(triggerId) {
1182
+ await client.request({
1183
+ method: "DELETE",
1184
+ service: TRIGGERS_SERVICE,
1185
+ path: `/${encodeURIComponent(triggerId)}`
1186
+ });
1187
+ }
1188
+ };
1189
+ }
1190
+
1072
1191
  // src/client/services/storage.ts
1073
- var SERVICE2 = "storage";
1192
+ var SERVICE3 = "storage";
1074
1193
  function enc(s) {
1075
1194
  return encodeURIComponent(s);
1076
1195
  }
@@ -1083,14 +1202,14 @@ function createStorageService(client) {
1083
1202
  async entityExists(ref) {
1084
1203
  return client.request({
1085
1204
  method: "GET",
1086
- service: SERVICE2,
1205
+ service: SERVICE3,
1087
1206
  path: `/entities/exists${entityPath(ref)}`
1088
1207
  });
1089
1208
  },
1090
1209
  async getEntity(ref, content = false) {
1091
1210
  return client.request({
1092
1211
  method: "GET",
1093
- service: SERVICE2,
1212
+ service: SERVICE3,
1094
1213
  path: `/entities/actual${entityPath(ref)}`,
1095
1214
  query: content ? { content: true } : void 0
1096
1215
  });
@@ -1098,14 +1217,14 @@ function createStorageService(client) {
1098
1217
  async getEntityContent(ref) {
1099
1218
  return client.requestRaw({
1100
1219
  method: "GET",
1101
- service: SERVICE2,
1220
+ service: SERVICE3,
1102
1221
  path: `/entities/contents/actual${entityPath(ref)}`
1103
1222
  });
1104
1223
  },
1105
1224
  async saveEntities(entities) {
1106
1225
  return client.request({
1107
1226
  method: "PUT",
1108
- service: SERVICE2,
1227
+ service: SERVICE3,
1109
1228
  path: "/entities/actual",
1110
1229
  body: entities
1111
1230
  });
@@ -1113,14 +1232,14 @@ function createStorageService(client) {
1113
1232
  async deleteEntity(ref) {
1114
1233
  return client.request({
1115
1234
  method: "DELETE",
1116
- service: SERVICE2,
1235
+ service: SERVICE3,
1117
1236
  path: `/entities/actual${entityPath(ref)}`
1118
1237
  });
1119
1238
  },
1120
1239
  async saveEntityContentBase64(ref, base64Content) {
1121
1240
  return client.request({
1122
1241
  method: "PUT",
1123
- service: SERVICE2,
1242
+ service: SERVICE3,
1124
1243
  path: `/entities/contents/actual${entityPath(ref)}`,
1125
1244
  rawBody: base64Content,
1126
1245
  contentType: "text/plain"
@@ -1129,7 +1248,7 @@ function createStorageService(client) {
1129
1248
  async uploadEntityContent(ref, formData) {
1130
1249
  return client.request({
1131
1250
  method: "PUT",
1132
- service: SERVICE2,
1251
+ service: SERVICE3,
1133
1252
  path: `/entities/contents/actual${entityPath(ref)}`,
1134
1253
  rawBody: formData
1135
1254
  });
@@ -1137,35 +1256,35 @@ function createStorageService(client) {
1137
1256
  async deleteEntityContent(ref) {
1138
1257
  return client.request({
1139
1258
  method: "DELETE",
1140
- service: SERVICE2,
1259
+ service: SERVICE3,
1141
1260
  path: `/entities/contents/actual${entityPath(ref)}`
1142
1261
  });
1143
1262
  },
1144
1263
  async getEntityHistory(ref, version) {
1145
1264
  return client.request({
1146
1265
  method: "GET",
1147
- service: SERVICE2,
1266
+ service: SERVICE3,
1148
1267
  path: `/entities/history${entityPath(ref)}/${version}`
1149
1268
  });
1150
1269
  },
1151
1270
  async getEntityHistoryRange(ref, fromVersion, toVersion) {
1152
1271
  return client.request({
1153
1272
  method: "GET",
1154
- service: SERVICE2,
1273
+ service: SERVICE3,
1155
1274
  path: `/entities/history${entityPath(ref)}/${fromVersion}/${toVersion}`
1156
1275
  });
1157
1276
  },
1158
1277
  async renameEntity(ref, newEntityId) {
1159
1278
  return client.request({
1160
1279
  method: "PUT",
1161
- service: SERVICE2,
1280
+ service: SERVICE3,
1162
1281
  path: `/entities/ids${entityPath(ref)}/${enc(newEntityId)}`
1163
1282
  });
1164
1283
  },
1165
1284
  async revertEntity(ref, version) {
1166
1285
  return client.request({
1167
1286
  method: "PUT",
1168
- service: SERVICE2,
1287
+ service: SERVICE3,
1169
1288
  path: `/entities/revert${entityPath(ref)}/${version}`
1170
1289
  });
1171
1290
  },
@@ -1173,7 +1292,7 @@ function createStorageService(client) {
1173
1292
  async searchEntityIds(projectId, projectBranch, body) {
1174
1293
  return client.request({
1175
1294
  method: "POST",
1176
- service: SERVICE2,
1295
+ service: SERVICE3,
1177
1296
  path: "/entity-ids/search",
1178
1297
  body
1179
1298
  });
@@ -1182,14 +1301,14 @@ function createStorageService(client) {
1182
1301
  async getLinkedEntities(direction, ref) {
1183
1302
  return client.request({
1184
1303
  method: "GET",
1185
- service: SERVICE2,
1304
+ service: SERVICE3,
1186
1305
  path: `/linked-entities/${enc(direction)}${entityPath(ref)}`
1187
1306
  });
1188
1307
  },
1189
1308
  async saveLinkedEntities(ref, linkId, entities) {
1190
1309
  return client.request({
1191
1310
  method: "PUT",
1192
- service: SERVICE2,
1311
+ service: SERVICE3,
1193
1312
  path: `/linked-entities/${enc(ref.projectId)}/${enc(ref.projectBranch)}/${enc(ref.entityId)}/${enc(ref.entityBranch)}/${enc(linkId)}`,
1194
1313
  body: entities
1195
1314
  });
@@ -1198,21 +1317,21 @@ function createStorageService(client) {
1198
1317
  async getLinks(direction, ref) {
1199
1318
  return client.request({
1200
1319
  method: "GET",
1201
- service: SERVICE2,
1320
+ service: SERVICE3,
1202
1321
  path: `/links/actual/${enc(direction)}${entityPath(ref)}`
1203
1322
  });
1204
1323
  },
1205
1324
  async getLinkIds(direction, ref) {
1206
1325
  return client.request({
1207
1326
  method: "GET",
1208
- service: SERVICE2,
1327
+ service: SERVICE3,
1209
1328
  path: `/links/ids/actual/${enc(direction)}${entityPath(ref)}`
1210
1329
  });
1211
1330
  },
1212
1331
  async createLink(projectId, projectBranch, sourceEntityId, sourceEntityBranch, linkId, targetEntityId, targetEntityBranch, link) {
1213
1332
  return client.request({
1214
1333
  method: "POST",
1215
- service: SERVICE2,
1334
+ service: SERVICE3,
1216
1335
  path: `/links/actual/${enc(projectId)}/${enc(projectBranch)}/${enc(sourceEntityId)}/${enc(sourceEntityBranch)}/${enc(linkId)}/${enc(targetEntityId)}/${enc(targetEntityBranch)}`,
1217
1336
  body: link
1218
1337
  });
@@ -1224,7 +1343,7 @@ function createStorageService(client) {
1224
1343
  }
1225
1344
  return client.request({
1226
1345
  method: "DELETE",
1227
- service: SERVICE2,
1346
+ service: SERVICE3,
1228
1347
  path: path7
1229
1348
  });
1230
1349
  },
@@ -1232,21 +1351,21 @@ function createStorageService(client) {
1232
1351
  async getEvents(ref) {
1233
1352
  return client.request({
1234
1353
  method: "GET",
1235
- service: SERVICE2,
1354
+ service: SERVICE3,
1236
1355
  path: `/events/actual${entityPath(ref)}`
1237
1356
  });
1238
1357
  },
1239
1358
  async getEvent(ref, eventId, occurrenceId) {
1240
1359
  return client.request({
1241
1360
  method: "GET",
1242
- service: SERVICE2,
1361
+ service: SERVICE3,
1243
1362
  path: `/events/actual${entityPath(ref)}/${enc(eventId)}/${enc(occurrenceId)}`
1244
1363
  });
1245
1364
  },
1246
1365
  async createEvents(events) {
1247
1366
  return client.request({
1248
1367
  method: "POST",
1249
- service: SERVICE2,
1368
+ service: SERVICE3,
1250
1369
  path: "/events/",
1251
1370
  body: events
1252
1371
  });
@@ -1254,7 +1373,7 @@ function createStorageService(client) {
1254
1373
  async consumeEvents(body) {
1255
1374
  return client.request({
1256
1375
  method: "POST",
1257
- service: SERVICE2,
1376
+ service: SERVICE3,
1258
1377
  path: "/events/consume",
1259
1378
  body
1260
1379
  });
@@ -1262,7 +1381,7 @@ function createStorageService(client) {
1262
1381
  async deleteEvent(ref, eventId, occurrenceId) {
1263
1382
  return client.request({
1264
1383
  method: "DELETE",
1265
- service: SERVICE2,
1384
+ service: SERVICE3,
1266
1385
  path: `/events/actual${entityPath(ref)}/${enc(eventId)}/${enc(occurrenceId)}`
1267
1386
  });
1268
1387
  },
@@ -1270,7 +1389,7 @@ function createStorageService(client) {
1270
1389
  async getTableSnapshot(ref, request) {
1271
1390
  return client.request({
1272
1391
  method: "POST",
1273
- service: SERVICE2,
1392
+ service: SERVICE3,
1274
1393
  path: `/tables${entityPath(ref)}/snapshots`,
1275
1394
  body: request ?? {}
1276
1395
  });
@@ -1278,35 +1397,35 @@ function createStorageService(client) {
1278
1397
  async appendRow(ref) {
1279
1398
  return client.request({
1280
1399
  method: "POST",
1281
- service: SERVICE2,
1400
+ service: SERVICE3,
1282
1401
  path: `/tables${entityPath(ref)}/rows`
1283
1402
  });
1284
1403
  },
1285
1404
  async deleteRow(ref, rowIndex) {
1286
1405
  return client.request({
1287
1406
  method: "DELETE",
1288
- service: SERVICE2,
1407
+ service: SERVICE3,
1289
1408
  path: `/tables${entityPath(ref)}/rows/${rowIndex}`
1290
1409
  });
1291
1410
  },
1292
1411
  async appendColumn(ref) {
1293
1412
  return client.request({
1294
1413
  method: "POST",
1295
- service: SERVICE2,
1414
+ service: SERVICE3,
1296
1415
  path: `/tables${entityPath(ref)}/columns`
1297
1416
  });
1298
1417
  },
1299
1418
  async deleteColumn(ref, columnIndex) {
1300
1419
  return client.request({
1301
1420
  method: "DELETE",
1302
- service: SERVICE2,
1421
+ service: SERVICE3,
1303
1422
  path: `/tables${entityPath(ref)}/columns/${columnIndex}`
1304
1423
  });
1305
1424
  },
1306
1425
  async mergeCells(ref, cells) {
1307
1426
  return client.request({
1308
1427
  method: "PUT",
1309
- service: SERVICE2,
1428
+ service: SERVICE3,
1310
1429
  path: `/tables${entityPath(ref)}/cells`,
1311
1430
  body: cells
1312
1431
  });
@@ -1314,14 +1433,14 @@ function createStorageService(client) {
1314
1433
  async deleteCell(ref, rowIndex, columnIndex) {
1315
1434
  return client.request({
1316
1435
  method: "DELETE",
1317
- service: SERVICE2,
1436
+ service: SERVICE3,
1318
1437
  path: `/tables${entityPath(ref)}/cells/${rowIndex}/${columnIndex}`
1319
1438
  });
1320
1439
  },
1321
1440
  async clearTable(ref) {
1322
1441
  return client.request({
1323
1442
  method: "POST",
1324
- service: SERVICE2,
1443
+ service: SERVICE3,
1325
1444
  path: `/tables${entityPath(ref)}/clear`
1326
1445
  });
1327
1446
  },
@@ -1329,7 +1448,7 @@ function createStorageService(client) {
1329
1448
  async importTable(ref, formData, columnHeaders = true) {
1330
1449
  return client.request({
1331
1450
  method: "PUT",
1332
- service: SERVICE2,
1451
+ service: SERVICE3,
1333
1452
  path: `/table-imports${entityPath(ref)}`,
1334
1453
  query: { columnHeaders },
1335
1454
  rawBody: formData
@@ -1338,21 +1457,21 @@ function createStorageService(client) {
1338
1457
  async getImport(ref, importId) {
1339
1458
  return client.request({
1340
1459
  method: "GET",
1341
- service: SERVICE2,
1460
+ service: SERVICE3,
1342
1461
  path: `/imports${entityPath(ref)}/${enc(importId)}`
1343
1462
  });
1344
1463
  },
1345
1464
  async exportTableCsv(ref) {
1346
1465
  return client.requestRaw({
1347
1466
  method: "POST",
1348
- service: SERVICE2,
1467
+ service: SERVICE3,
1349
1468
  path: `/table-exports${entityPath(ref)}/csv`
1350
1469
  });
1351
1470
  },
1352
1471
  async exportTableExcel(ref) {
1353
1472
  return client.requestRaw({
1354
1473
  method: "POST",
1355
- service: SERVICE2,
1474
+ service: SERVICE3,
1356
1475
  path: `/table-exports${entityPath(ref)}/excel`
1357
1476
  });
1358
1477
  },
@@ -1360,14 +1479,14 @@ function createStorageService(client) {
1360
1479
  async getProjectBranches(projectId) {
1361
1480
  return client.request({
1362
1481
  method: "GET",
1363
- service: SERVICE2,
1482
+ service: SERVICE3,
1364
1483
  path: `/project-branches/${enc(projectId)}`
1365
1484
  });
1366
1485
  },
1367
1486
  async createProjectBranch(request) {
1368
1487
  return client.request({
1369
1488
  method: "POST",
1370
- service: SERVICE2,
1489
+ service: SERVICE3,
1371
1490
  path: "/project-branches/",
1372
1491
  body: request
1373
1492
  });
@@ -1375,21 +1494,21 @@ function createStorageService(client) {
1375
1494
  async deleteProjectBranch(projectId, projectBranch) {
1376
1495
  return client.request({
1377
1496
  method: "DELETE",
1378
- service: SERVICE2,
1497
+ service: SERVICE3,
1379
1498
  path: `/project-branches/${enc(projectId)}/${enc(projectBranch)}`
1380
1499
  });
1381
1500
  },
1382
1501
  async getEntityBranches(projectId, projectBranch, entityId) {
1383
1502
  return client.request({
1384
1503
  method: "GET",
1385
- service: SERVICE2,
1504
+ service: SERVICE3,
1386
1505
  path: `/entity-branches/${enc(projectId)}/${enc(projectBranch)}/${enc(entityId)}`
1387
1506
  });
1388
1507
  },
1389
1508
  async createEntityBranch(request) {
1390
1509
  return client.request({
1391
1510
  method: "POST",
1392
- service: SERVICE2,
1511
+ service: SERVICE3,
1393
1512
  path: "/entity-branches/",
1394
1513
  body: request
1395
1514
  });
@@ -1398,7 +1517,7 @@ function createStorageService(client) {
1398
1517
  async merge(request) {
1399
1518
  return client.request({
1400
1519
  method: "POST",
1401
- service: SERVICE2,
1520
+ service: SERVICE3,
1402
1521
  path: "/merge/",
1403
1522
  body: request
1404
1523
  });
@@ -1406,7 +1525,7 @@ function createStorageService(client) {
1406
1525
  async fork(request) {
1407
1526
  return client.request({
1408
1527
  method: "POST",
1409
- service: SERVICE2,
1528
+ service: SERVICE3,
1410
1529
  path: "/fork/",
1411
1530
  body: request
1412
1531
  });
@@ -1415,7 +1534,7 @@ function createStorageService(client) {
1415
1534
  async searchProject(projectId, projectBranch, body) {
1416
1535
  return client.request({
1417
1536
  method: "POST",
1418
- service: SERVICE2,
1537
+ service: SERVICE3,
1419
1538
  path: `/project-searches/${enc(projectId)}/${enc(projectBranch)}`,
1420
1539
  body
1421
1540
  });
@@ -1424,21 +1543,21 @@ function createStorageService(client) {
1424
1543
  async createShortTermProjectBackup() {
1425
1544
  return client.request({
1426
1545
  method: "POST",
1427
- service: SERVICE2,
1546
+ service: SERVICE3,
1428
1547
  path: "/backups/project/short-term/create"
1429
1548
  });
1430
1549
  },
1431
1550
  async createLongTermProjectBackup() {
1432
1551
  return client.request({
1433
1552
  method: "POST",
1434
- service: SERVICE2,
1553
+ service: SERVICE3,
1435
1554
  path: "/backups/project/long-term/create"
1436
1555
  });
1437
1556
  },
1438
1557
  async restoreProjectBackup(request) {
1439
1558
  return client.request({
1440
1559
  method: "POST",
1441
- service: SERVICE2,
1560
+ service: SERVICE3,
1442
1561
  path: "/backups/project/restore",
1443
1562
  body: request
1444
1563
  });
@@ -1446,21 +1565,21 @@ function createStorageService(client) {
1446
1565
  async createShortTermFullBackup() {
1447
1566
  return client.request({
1448
1567
  method: "POST",
1449
- service: SERVICE2,
1568
+ service: SERVICE3,
1450
1569
  path: "/backups/full/short-term/create"
1451
1570
  });
1452
1571
  },
1453
1572
  async createLongTermFullBackup() {
1454
1573
  return client.request({
1455
1574
  method: "POST",
1456
- service: SERVICE2,
1575
+ service: SERVICE3,
1457
1576
  path: "/backups/full/long-term/create"
1458
1577
  });
1459
1578
  },
1460
1579
  async restoreFullBackup(request) {
1461
1580
  return client.request({
1462
1581
  method: "POST",
1463
- service: SERVICE2,
1582
+ service: SERVICE3,
1464
1583
  path: "/backups/full/restore",
1465
1584
  body: request
1466
1585
  });
@@ -1471,7 +1590,7 @@ function createStorageService(client) {
1471
1590
  }
1472
1591
 
1473
1592
  // src/client/services/evaluation.ts
1474
- var SERVICE3 = "evaluation";
1593
+ var SERVICE4 = "evaluation";
1475
1594
  function enc2(s) {
1476
1595
  return encodeURIComponent(s);
1477
1596
  }
@@ -1481,7 +1600,7 @@ function createEvaluationService(client) {
1481
1600
  async call(request, async = false) {
1482
1601
  return client.request({
1483
1602
  method: "POST",
1484
- service: SERVICE3,
1603
+ service: SERVICE4,
1485
1604
  path: "/calls/",
1486
1605
  body: request,
1487
1606
  query: async ? { async: true } : void 0
@@ -1491,14 +1610,14 @@ function createEvaluationService(client) {
1491
1610
  async getEvaluations(projectId, projectBranch, functionId, functionBranch, year, month, day, hour) {
1492
1611
  return client.request({
1493
1612
  method: "GET",
1494
- service: SERVICE3,
1613
+ service: SERVICE4,
1495
1614
  path: `/evaluations/${enc2(projectId)}/${enc2(projectBranch)}/${enc2(functionId)}/${enc2(functionBranch)}/${year}/${month}/${day}/${hour}`
1496
1615
  });
1497
1616
  },
1498
1617
  async getEvaluation(projectId, projectBranch, functionId, functionBranch, year, month, day, hour, evaluationId, result = false) {
1499
1618
  return client.request({
1500
1619
  method: "GET",
1501
- service: SERVICE3,
1620
+ service: SERVICE4,
1502
1621
  path: `/evaluations/${enc2(projectId)}/${enc2(projectBranch)}/${enc2(functionId)}/${enc2(functionBranch)}/${year}/${month}/${day}/${hour}/${enc2(evaluationId)}`,
1503
1622
  query: result ? { result: true } : void 0
1504
1623
  });
@@ -1507,7 +1626,7 @@ function createEvaluationService(client) {
1507
1626
  async getLastEvaluation(projectId, projectBranch, functionId, functionBranch) {
1508
1627
  return client.request({
1509
1628
  method: "GET",
1510
- service: SERVICE3,
1629
+ service: SERVICE4,
1511
1630
  path: `/last-evaluation/${enc2(projectId)}/${enc2(projectBranch)}/${enc2(functionId)}/${enc2(functionBranch)}`
1512
1631
  });
1513
1632
  },
@@ -1515,7 +1634,7 @@ function createEvaluationService(client) {
1515
1634
  async getOutputs(projectId, evaluationId) {
1516
1635
  return client.request({
1517
1636
  method: "GET",
1518
- service: SERVICE3,
1637
+ service: SERVICE4,
1519
1638
  path: `/output/${enc2(projectId)}/${enc2(evaluationId)}`
1520
1639
  });
1521
1640
  },
@@ -1523,7 +1642,7 @@ function createEvaluationService(client) {
1523
1642
  async getLogs(projectId, projectBranch, functionId, functionBranch, year, month, day, hour) {
1524
1643
  return client.request({
1525
1644
  method: "GET",
1526
- service: SERVICE3,
1645
+ service: SERVICE4,
1527
1646
  path: `/log/${enc2(projectId)}/${enc2(projectBranch)}/${enc2(functionId)}/${enc2(functionBranch)}/${year}/${month}/${day}/${hour}`
1528
1647
  });
1529
1648
  },
@@ -1531,7 +1650,7 @@ function createEvaluationService(client) {
1531
1650
  async getSourceCode(projectId, projectBranch, functionId, functionBranch, sourceCodeHash, sourceCodeId) {
1532
1651
  return client.request({
1533
1652
  method: "GET",
1534
- service: SERVICE3,
1653
+ service: SERVICE4,
1535
1654
  path: `/sourcecodes/${enc2(projectId)}/${enc2(projectBranch)}/${enc2(functionId)}/${enc2(functionBranch)}/${enc2(sourceCodeHash)}/${enc2(sourceCodeId)}`
1536
1655
  });
1537
1656
  },
@@ -1539,7 +1658,7 @@ function createEvaluationService(client) {
1539
1658
  async stopEvaluation(projectId, projectBranch, functionId, functionBranch, year, month, day, hour, evaluationId) {
1540
1659
  return client.request({
1541
1660
  method: "POST",
1542
- service: SERVICE3,
1661
+ service: SERVICE4,
1543
1662
  path: `/stop/${enc2(projectId)}/${enc2(projectBranch)}/${enc2(functionId)}/${enc2(functionBranch)}/${year}/${month}/${day}/${hour}/${enc2(evaluationId)}`
1544
1663
  });
1545
1664
  },
@@ -1547,21 +1666,21 @@ function createEvaluationService(client) {
1547
1666
  async getTriggers(projectId, projectBranch, functionId, functionBranch) {
1548
1667
  return client.request({
1549
1668
  method: "GET",
1550
- service: SERVICE3,
1669
+ service: SERVICE4,
1551
1670
  path: `/triggers/actual/${enc2(projectId)}/${enc2(projectBranch)}/${enc2(functionId)}/${enc2(functionBranch)}`
1552
1671
  });
1553
1672
  },
1554
1673
  async getTrigger(projectId, projectBranch, functionId, functionBranch, triggerId) {
1555
1674
  return client.request({
1556
1675
  method: "GET",
1557
- service: SERVICE3,
1676
+ service: SERVICE4,
1558
1677
  path: `/triggers/actual/${enc2(projectId)}/${enc2(projectBranch)}/${enc2(functionId)}/${enc2(functionBranch)}/${enc2(triggerId)}`
1559
1678
  });
1560
1679
  },
1561
1680
  async saveTrigger(trigger) {
1562
1681
  return client.request({
1563
1682
  method: "PUT",
1564
- service: SERVICE3,
1683
+ service: SERVICE4,
1565
1684
  path: "/triggers/",
1566
1685
  body: trigger
1567
1686
  });
@@ -1569,7 +1688,7 @@ function createEvaluationService(client) {
1569
1688
  async deleteTrigger(projectId, projectBranch, functionId, functionBranch, triggerId) {
1570
1689
  return client.request({
1571
1690
  method: "DELETE",
1572
- service: SERVICE3,
1691
+ service: SERVICE4,
1573
1692
  path: `/triggers/${enc2(projectId)}/${enc2(projectBranch)}/${enc2(functionId)}/${enc2(functionBranch)}/${enc2(triggerId)}`
1574
1693
  });
1575
1694
  },
@@ -1577,7 +1696,7 @@ function createEvaluationService(client) {
1577
1696
  async getEngines() {
1578
1697
  return client.request({
1579
1698
  method: "GET",
1580
- service: SERVICE3,
1699
+ service: SERVICE4,
1581
1700
  path: "/engines/"
1582
1701
  });
1583
1702
  }
@@ -1585,7 +1704,7 @@ function createEvaluationService(client) {
1585
1704
  }
1586
1705
 
1587
1706
  // src/client/services/scheduler.ts
1588
- var SERVICE4 = "scheduler";
1707
+ var SERVICE5 = "scheduler";
1589
1708
  function enc3(s) {
1590
1709
  return encodeURIComponent(s);
1591
1710
  }
@@ -1594,7 +1713,7 @@ function createSchedulerService(client) {
1594
1713
  async scheduleCall(request) {
1595
1714
  return client.request({
1596
1715
  method: "POST",
1597
- service: SERVICE4,
1716
+ service: SERVICE5,
1598
1717
  path: "/calls/",
1599
1718
  body: request
1600
1719
  });
@@ -1602,7 +1721,7 @@ function createSchedulerService(client) {
1602
1721
  async stopScheduled(projectId, projectBranch, functionId, functionBranch, year, month, day, hour, evaluationId) {
1603
1722
  return client.request({
1604
1723
  method: "POST",
1605
- service: SERVICE4,
1724
+ service: SERVICE5,
1606
1725
  path: `/stop/${enc3(projectId)}/${enc3(projectBranch)}/${enc3(functionId)}/${enc3(functionBranch)}/${year}/${month}/${day}/${hour}/${enc3(evaluationId)}`
1607
1726
  });
1608
1727
  }
@@ -1610,7 +1729,7 @@ function createSchedulerService(client) {
1610
1729
  }
1611
1730
 
1612
1731
  // src/client/services/language.ts
1613
- var SERVICE5 = "language";
1732
+ var SERVICE6 = "language";
1614
1733
  function enc4(s) {
1615
1734
  return encodeURIComponent(s);
1616
1735
  }
@@ -1620,7 +1739,7 @@ function createLanguageService(client) {
1620
1739
  async chat(request) {
1621
1740
  return client.request({
1622
1741
  method: "POST",
1623
- service: SERVICE5,
1742
+ service: SERVICE6,
1624
1743
  path: "/chat/",
1625
1744
  body: request
1626
1745
  });
@@ -1629,7 +1748,7 @@ function createLanguageService(client) {
1629
1748
  async chatStream(request) {
1630
1749
  return client.requestRaw({
1631
1750
  method: "POST",
1632
- service: SERVICE5,
1751
+ service: SERVICE6,
1633
1752
  path: "/chat/stream",
1634
1753
  body: request
1635
1754
  });
@@ -1638,7 +1757,7 @@ function createLanguageService(client) {
1638
1757
  async upload(formData) {
1639
1758
  return client.request({
1640
1759
  method: "POST",
1641
- service: SERVICE5,
1760
+ service: SERVICE6,
1642
1761
  path: "/upload/",
1643
1762
  rawBody: formData
1644
1763
  });
@@ -1647,7 +1766,7 @@ function createLanguageService(client) {
1647
1766
  async getUsage() {
1648
1767
  return client.request({
1649
1768
  method: "GET",
1650
- service: SERVICE5,
1769
+ service: SERVICE6,
1651
1770
  path: "/usage/"
1652
1771
  });
1653
1772
  },
@@ -1655,35 +1774,35 @@ function createLanguageService(client) {
1655
1774
  async getSessions() {
1656
1775
  return client.request({
1657
1776
  method: "GET",
1658
- service: SERVICE5,
1777
+ service: SERVICE6,
1659
1778
  path: "/sessions/"
1660
1779
  });
1661
1780
  },
1662
1781
  async getSession(sessionId) {
1663
1782
  return client.request({
1664
1783
  method: "GET",
1665
- service: SERVICE5,
1784
+ service: SERVICE6,
1666
1785
  path: `/sessions/${enc4(sessionId)}`
1667
1786
  });
1668
1787
  },
1669
1788
  async deleteSession(sessionId) {
1670
1789
  return client.request({
1671
1790
  method: "DELETE",
1672
- service: SERVICE5,
1791
+ service: SERVICE6,
1673
1792
  path: `/sessions/${enc4(sessionId)}`
1674
1793
  });
1675
1794
  },
1676
1795
  async getSessionMessages(sessionId) {
1677
1796
  return client.request({
1678
1797
  method: "GET",
1679
- service: SERVICE5,
1798
+ service: SERVICE6,
1680
1799
  path: `/sessions/${enc4(sessionId)}/messages`
1681
1800
  });
1682
1801
  },
1683
1802
  async renameSession(sessionId, title) {
1684
1803
  return client.request({
1685
1804
  method: "PUT",
1686
- service: SERVICE5,
1805
+ service: SERVICE6,
1687
1806
  path: `/sessions/${enc4(sessionId)}/title`,
1688
1807
  rawBody: title,
1689
1808
  contentType: "text/plain"
@@ -1693,7 +1812,7 @@ function createLanguageService(client) {
1693
1812
  }
1694
1813
 
1695
1814
  // src/client/services/index-search.ts
1696
- var SERVICE6 = "index";
1815
+ var SERVICE7 = "index";
1697
1816
  function enc5(s) {
1698
1817
  return encodeURIComponent(s);
1699
1818
  }
@@ -1702,14 +1821,14 @@ function createIndexService(client) {
1702
1821
  async rebuildAll() {
1703
1822
  return client.request({
1704
1823
  method: "POST",
1705
- service: SERVICE6,
1824
+ service: SERVICE7,
1706
1825
  path: "/indexes/rebuild"
1707
1826
  });
1708
1827
  },
1709
1828
  async rebuildProject(projectId) {
1710
1829
  return client.request({
1711
1830
  method: "POST",
1712
- service: SERVICE6,
1831
+ service: SERVICE7,
1713
1832
  path: `/indexes/rebuild/${enc5(projectId)}`
1714
1833
  });
1715
1834
  }
@@ -1722,6 +1841,7 @@ function createApiClient(options = {}) {
1722
1841
  return {
1723
1842
  http,
1724
1843
  admin: createAdminService(http),
1844
+ analysis: createAnalysisService(http),
1725
1845
  storage: createStorageService(http),
1726
1846
  evaluation: createEvaluationService(http),
1727
1847
  scheduler: createSchedulerService(http),
@@ -4298,20 +4418,6 @@ function createEntity(projectId, entityId, entityType, name, description, attrib
4298
4418
  }
4299
4419
  return entity;
4300
4420
  }
4301
- function generateSourceCode(rawDataTableId, analysisChapterId, timeHours) {
4302
- return `var rawDataTable = diafunc.table("${rawDataTableId}");
4303
- var analysisChapter = diafunc.chapter("${analysisChapterId}");
4304
-
4305
- return diafunc
4306
- .analyze()
4307
- .automatic()
4308
- .from(rawDataTable)
4309
- .to(analysisChapter)
4310
- .hours(${timeHours});`;
4311
- }
4312
- function stringToBinary(str) {
4313
- return Buffer.from(str).toString("base64");
4314
- }
4315
4421
  function formatDuration(ms) {
4316
4422
  const seconds = Math.floor(ms / 1e3);
4317
4423
  const minutes = Math.floor(seconds / 60);
@@ -4333,6 +4439,13 @@ function getOutputFormat14(cmd) {
4333
4439
  const globalOpts = cmd.optsWithGlobals();
4334
4440
  return globalOpts.output ?? config.defaults.output ?? "human";
4335
4441
  }
4442
+ function parseCsv(value) {
4443
+ if (value === void 0) return null;
4444
+ return value.split(",").map((s) => s.trim()).filter((s) => s.length > 0);
4445
+ }
4446
+ function isTerminalState(state) {
4447
+ return state === "COMPLETED" || state === "FAILED" || state === "CANCELLED";
4448
+ }
4336
4449
  async function runAnalysis(file, options, cmd) {
4337
4450
  if (!fs6.existsSync(file)) {
4338
4451
  console.error(chalk23.red(`File not found: ${file}`));
@@ -4341,11 +4454,11 @@ async function runAnalysis(file, options, cmd) {
4341
4454
  const api = createApiClient();
4342
4455
  const projectName = options.name ?? path5.basename(file, path5.extname(file));
4343
4456
  const visibility = options.visibility.toUpperCase();
4344
- const analysis = {
4457
+ const recipe = {
4345
4458
  userId: null,
4346
- analysisId: randomUUID3(),
4459
+ analysisId: null,
4347
4460
  phase: "PREPARATION",
4348
- step: "CREATE_PROJECT",
4461
+ step: "LAUNCH_ANALYSIS",
4349
4462
  projectName,
4350
4463
  projectDescription: options.description,
4351
4464
  visibility,
@@ -4361,27 +4474,33 @@ async function runAnalysis(file, options, cmd) {
4361
4474
  day: null,
4362
4475
  hour: null,
4363
4476
  evaluationId: null,
4364
- started: null
4477
+ started: null,
4478
+ targetKeys: parseCsv(options.targets),
4479
+ questions: parseCsv(options.questions),
4480
+ segmentKey: options.segment ?? null
4365
4481
  };
4366
4482
  process.stdout.write(`Creating project "${projectName}" ...`);
4367
- await createProjectStructure(api, analysis);
4483
+ const { projectId, rawDataTableId } = await provisionProject(api, recipe);
4484
+ recipe.projectId = projectId;
4485
+ recipe.rawDataTableId = rawDataTableId;
4368
4486
  console.log(chalk23.green(" done"));
4369
4487
  process.stdout.write(`Importing ${path5.basename(file)} ...`);
4370
- await importData(api, analysis, file);
4488
+ await importData(api, projectId, rawDataTableId, file);
4371
4489
  console.log(chalk23.green(" done"));
4372
- process.stdout.write("Launching analysis ...");
4373
- await launchAnalysis(api, analysis);
4490
+ process.stdout.write("Queuing analysis run ...");
4491
+ const run = await api.analysis.createAndRun(recipe);
4374
4492
  console.log(chalk23.green(" done"));
4493
+ console.log(chalk23.dim(` analysisId: ${run.analysisId}`));
4494
+ console.log(chalk23.dim(` runId: ${run.runId}`));
4375
4495
  console.log();
4376
- await monitorAnalysis(api, analysis, cmd);
4496
+ await monitorRun(api, run.runId, recipe, cmd);
4377
4497
  }
4378
- async function createProjectStructure(api, analysis) {
4498
+ async function provisionProject(api, recipe) {
4379
4499
  const project = await api.admin.createProject({
4380
- visibility: analysis.visibility,
4500
+ visibility: recipe.visibility,
4381
4501
  language: "Java",
4382
4502
  active: true
4383
4503
  });
4384
- analysis.projectId = project.projectId;
4385
4504
  await api.storage.createProjectBranch({
4386
4505
  projectId: project.projectId,
4387
4506
  sourceProjectBranch: null,
@@ -4391,93 +4510,34 @@ async function createProjectStructure(api, analysis) {
4391
4510
  project.projectId,
4392
4511
  project.projectId,
4393
4512
  "project",
4394
- analysis.projectName,
4395
- analysis.projectDescription,
4513
+ recipe.projectName,
4514
+ recipe.projectDescription,
4396
4515
  null,
4397
4516
  [],
4398
4517
  null,
4399
4518
  null
4400
4519
  );
4401
4520
  await api.storage.saveEntities([projectEntity]);
4402
- const notebookId = randomUUID3();
4403
- analysis.notebookId = notebookId;
4404
- const notebookEntity = createEntity(
4521
+ const rawDataTableId = randomUUID3();
4522
+ const rawDataTable = createEntity(
4405
4523
  project.projectId,
4406
- notebookId,
4407
- "notebook",
4408
- analysis.projectName,
4524
+ rawDataTableId,
4525
+ "table",
4526
+ "Raw Data Table",
4409
4527
  null,
4410
4528
  null,
4411
4529
  [],
4412
4530
  null,
4413
4531
  null
4414
4532
  );
4415
- const projectRef = {
4416
- projectId: project.projectId,
4417
- projectBranch: "main",
4418
- entityId: project.projectId,
4419
- entityBranch: "main"
4420
- };
4421
- await api.storage.saveLinkedEntities(projectRef, "main", [notebookEntity]);
4422
- const analysisChapterId = randomUUID3();
4423
- analysis.analysisChapterId = analysisChapterId;
4424
- const foundationChapterId = randomUUID3();
4425
- const notebookRef = {
4426
- projectId: project.projectId,
4427
- projectBranch: "main",
4428
- entityId: notebookId,
4429
- entityBranch: "main"
4430
- };
4431
- await api.storage.saveLinkedEntities(notebookRef, "sections", [
4432
- createEntity(project.projectId, randomUUID3(), "text", null, null, { index: 0, text: "This notebook is an analysis of your data." }, ["introduction"], null, null),
4433
- createEntity(project.projectId, randomUUID3(), "contents", null, null, { index: 1 }, [], null, null),
4434
- createEntity(project.projectId, analysisChapterId, "chapter", "Analysis", null, { index: 2 }, ["analysis"], null, null),
4435
- createEntity(project.projectId, foundationChapterId, "chapter", "Foundation", null, { index: 3 }, ["foundation"], null, null)
4436
- ]);
4437
- const rawDataChapterId = randomUUID3();
4438
- const analysisFunctionChapterId = randomUUID3();
4439
- const foundationRef = {
4440
- projectId: project.projectId,
4441
- projectBranch: "main",
4442
- entityId: foundationChapterId,
4443
- entityBranch: "main"
4444
- };
4445
- await api.storage.saveLinkedEntities(foundationRef, "sections", [
4446
- createEntity(project.projectId, rawDataChapterId, "chapter", "Raw Data", null, { index: 0 }, ["raw-data"], null, null),
4447
- createEntity(project.projectId, analysisFunctionChapterId, "chapter", "Analysis Function", null, { index: 1 }, ["analysis-function"], null, null)
4448
- ]);
4449
- const rawDataTableId = randomUUID3();
4450
- analysis.rawDataTableId = rawDataTableId;
4451
- const rawDataRef = {
4452
- projectId: project.projectId,
4453
- projectBranch: "main",
4454
- entityId: rawDataChapterId,
4455
- entityBranch: "main"
4456
- };
4457
- await api.storage.saveLinkedEntities(rawDataRef, "sections", [
4458
- createEntity(project.projectId, rawDataTableId, "table", "Raw Data Table", null, { index: 0 }, [], null, null)
4459
- ]);
4460
- const analysisFunctionId = randomUUID3();
4461
- analysis.analysisFunctionId = analysisFunctionId;
4462
- const sourceCode = generateSourceCode(rawDataTableId, analysisChapterId, analysis.time);
4463
- const content = stringToBinary(JSON.stringify({ sourceCode }));
4464
- const funcRef = {
4465
- projectId: project.projectId,
4466
- projectBranch: "main",
4467
- entityId: analysisFunctionChapterId,
4468
- entityBranch: "main"
4469
- };
4470
- await api.storage.saveLinkedEntities(funcRef, "sections", [
4471
- createEntity(project.projectId, analysisFunctionId, "function", "Analysis Function", null, { index: 1, language: "Java" }, [], "text/plain", content)
4472
- ]);
4473
- analysis.step = "UPLOAD_DATA";
4474
- await api.admin.saveAnalysis(analysis);
4533
+ await api.storage.saveEntities([rawDataTable]);
4534
+ return { projectId: project.projectId, rawDataTableId };
4475
4535
  }
4476
- async function importData(api, analysis, file) {
4536
+ async function importData(api, projectId, rawDataTableId, file) {
4477
4537
  const ref = {
4478
- projectId: analysis.projectId,
4538
+ projectId,
4479
4539
  projectBranch: "main",
4480
- entityId: analysis.rawDataTableId,
4540
+ entityId: rawDataTableId,
4481
4541
  entityBranch: "main"
4482
4542
  };
4483
4543
  const fileBuffer = fs6.readFileSync(file);
@@ -4490,126 +4550,105 @@ async function importData(api, analysis, file) {
4490
4550
  const imp = await api.storage.getImport(ref, importId);
4491
4551
  if (imp.finished !== null) {
4492
4552
  if (!imp.succeeded) throw new Error(`Import failed: ${imp.error}`);
4493
- break;
4553
+ return;
4494
4554
  }
4495
4555
  }
4496
- analysis.step = "LAUNCH_ANALYSIS";
4497
- await api.admin.saveAnalysis(analysis);
4556
+ throw new Error("Import did not finish within 5 minutes");
4498
4557
  }
4499
- async function launchAnalysis(api, analysis) {
4500
- const funcRef = {
4501
- projectId: analysis.projectId,
4502
- projectBranch: "main",
4503
- entityId: analysis.analysisFunctionId,
4504
- entityBranch: "main"
4505
- };
4506
- const sourceCode = generateSourceCode(analysis.rawDataTableId, analysis.analysisChapterId, analysis.time);
4507
- const content = stringToBinary(JSON.stringify({ sourceCode }));
4508
- await api.storage.saveEntityContentBase64(funcRef, content);
4509
- const now = /* @__PURE__ */ new Date();
4510
- analysis.evaluationId = randomUUID3();
4511
- analysis.year = now.getUTCFullYear();
4512
- analysis.month = now.getUTCMonth() + 1;
4513
- analysis.day = now.getUTCDate();
4514
- analysis.hour = now.getUTCHours();
4515
- await api.evaluation.call({
4516
- evaluationId: analysis.evaluationId,
4517
- projectId: analysis.projectId,
4518
- projectBranch: "main",
4519
- functionId: analysis.analysisFunctionId,
4520
- functionBranch: "main",
4521
- targetEntityId: null,
4522
- targetEntityBranch: null,
4523
- arguments: null,
4524
- types: null,
4525
- requested: Date.now(),
4526
- provideOutputs: true,
4527
- removeFunction: false
4528
- }, true);
4529
- analysis.phase = "ANALYSIS";
4530
- analysis.started = Date.now();
4531
- await api.admin.saveAnalysis(analysis);
4532
- }
4533
- async function monitorAnalysis(api, analysis, cmd) {
4558
+ async function monitorRun(api, runId, recipe, cmd) {
4534
4559
  const config = loadConfig();
4535
4560
  const outputFormat = getOutputFormat14(cmd);
4536
- const computationMs = parseFloat(analysis.time) * 60 * 60 * 1e3;
4561
+ const computationMs = parseFloat(recipe.time) * 60 * 60 * 1e3;
4562
+ const startMs = Date.now();
4537
4563
  const seenOutputIds = /* @__PURE__ */ new Set();
4564
+ let observedAnalysisId = recipe.analysisId;
4538
4565
  for (let i = 0; ; i++) {
4539
4566
  await new Promise((resolve) => setTimeout(resolve, 2e3));
4567
+ let run = null;
4540
4568
  try {
4541
- const evaluation = await api.evaluation.getEvaluation(
4542
- analysis.projectId,
4543
- "main",
4544
- analysis.analysisFunctionId,
4545
- "main",
4546
- analysis.year,
4547
- analysis.month,
4548
- analysis.day,
4549
- analysis.hour,
4550
- analysis.evaluationId,
4551
- true
4552
- );
4553
- if (!evaluation.active) {
4554
- analysis.phase = "COMPLETION";
4555
- await api.admin.saveAnalysis(analysis);
4556
- console.log();
4557
- if (evaluation.successful) {
4558
- const duration = evaluation.completed - evaluation.started;
4559
- const durationStr = formatDuration(duration);
4560
- if (outputFormat === "human") {
4561
- console.log(chalk23.green(`Analysis complete! (${durationStr})`));
4562
- if (evaluation.result) console.log(` Result: ${evaluation.result}`);
4563
- const endpoint = config.profiles[config.currentProfile]?.endpoint ?? "https://diafunc.com";
4564
- console.log(` Project: ${analysisUrl(analysis, endpoint)}`);
4565
- } else {
4566
- format({
4567
- status: "completed",
4568
- successful: true,
4569
- duration,
4570
- result: evaluation.result,
4571
- projectId: analysis.projectId
4572
- }, { format: outputFormat });
4573
- }
4574
- } else {
4575
- if (outputFormat === "human") {
4576
- console.log(chalk23.red("Analysis failed."));
4577
- console.log(` Error: ${evaluation.error}`);
4578
- } else {
4579
- format({
4580
- status: "failed",
4581
- error: evaluation.error,
4582
- projectId: analysis.projectId
4583
- }, { format: outputFormat });
4569
+ const opt = await api.analysis.getRun(runId);
4570
+ run = opt.run;
4571
+ } catch {
4572
+ }
4573
+ if (!run) continue;
4574
+ if (run.analysisId) observedAnalysisId = run.analysisId;
4575
+ if (run.evaluationId && recipe.projectId) {
4576
+ try {
4577
+ const outputs = await api.evaluation.getOutputs(recipe.projectId, run.evaluationId);
4578
+ for (const out of outputs) {
4579
+ if (!seenOutputIds.has(out.outputId)) {
4580
+ seenOutputIds.add(out.outputId);
4581
+ if (outputFormat === "human") {
4582
+ console.log(` ${chalk23.dim("Output:")} ${out.output}`);
4583
+ }
4584
4584
  }
4585
4585
  }
4586
- return;
4586
+ } catch {
4587
4587
  }
4588
- } catch {
4589
4588
  }
4590
- try {
4591
- const outputs = await api.evaluation.getOutputs(analysis.projectId, analysis.evaluationId);
4592
- for (const out of outputs) {
4593
- if (!seenOutputIds.has(out.outputId)) {
4594
- seenOutputIds.add(out.outputId);
4595
- if (outputFormat === "human") console.log(` ${chalk23.dim("Output:")} ${out.output}`);
4589
+ if (isTerminalState(run.state)) {
4590
+ console.log();
4591
+ const baseStart = run.startedAt ?? run.submittedAt ?? startMs;
4592
+ const duration = (run.endedAt ?? Date.now()) - baseStart;
4593
+ const durationStr = formatDuration(duration);
4594
+ if (run.state === "COMPLETED") {
4595
+ if (outputFormat === "human") {
4596
+ console.log(chalk23.green(`Analysis complete! (${durationStr})`));
4597
+ if (observedAnalysisId) {
4598
+ try {
4599
+ const opt = await api.analysis.get(observedAnalysisId);
4600
+ if (opt.analysis?.notebookId) {
4601
+ const endpoint = config.profiles[config.currentProfile]?.endpoint ?? "https://diafunc.com";
4602
+ console.log(` Project: ${analysisUrl(opt.analysis, endpoint)}`);
4603
+ }
4604
+ } catch {
4605
+ }
4606
+ }
4607
+ } else {
4608
+ format({
4609
+ status: "completed",
4610
+ runId,
4611
+ analysisId: observedAnalysisId,
4612
+ duration,
4613
+ projectId: recipe.projectId
4614
+ }, { format: outputFormat });
4615
+ }
4616
+ } else if (run.state === "CANCELLED") {
4617
+ if (outputFormat === "human") {
4618
+ console.log(chalk23.yellow("Analysis cancelled."));
4619
+ } else {
4620
+ format({ status: "cancelled", runId, analysisId: observedAnalysisId }, { format: outputFormat });
4621
+ }
4622
+ } else {
4623
+ if (outputFormat === "human") {
4624
+ console.log(chalk23.red("Analysis failed."));
4625
+ if (run.errorMessage) console.log(` Error: ${run.errorMessage}`);
4626
+ } else {
4627
+ format({
4628
+ status: "failed",
4629
+ runId,
4630
+ analysisId: observedAnalysisId,
4631
+ error: run.errorMessage
4632
+ }, { format: outputFormat });
4596
4633
  }
4597
4634
  }
4598
- } catch {
4635
+ return;
4599
4636
  }
4600
4637
  if (outputFormat === "human" && i % 5 === 0) {
4601
- const elapsed = Date.now() - analysis.started;
4602
- const progress = Math.min(elapsed / computationMs, 1);
4638
+ const elapsed = Date.now() - startMs;
4639
+ const progress = run.progressTotal && run.progressTotal > 0 ? (run.progressDone ?? 0) / run.progressTotal : Math.min(elapsed / computationMs, 1);
4603
4640
  const pct = Math.round(progress * 100);
4604
- const bar = "\u2588".repeat(Math.round(progress * 30)) + "\u2591".repeat(30 - Math.round(progress * 30));
4605
- process.stdout.write(`\r Analysis in progress [${bar}] ${pct}% `);
4641
+ const filled = Math.round(progress * 30);
4642
+ const bar = "\u2588".repeat(filled) + "\u2591".repeat(30 - filled);
4643
+ const stateLabel = run.state.toLowerCase().padEnd(11);
4644
+ process.stdout.write(`\r ${stateLabel} [${bar}] ${pct}% `);
4606
4645
  }
4607
4646
  }
4608
4647
  }
4609
4648
  async function listAnalyses(limit, cmd) {
4610
4649
  const outputFormat = getOutputFormat14(cmd);
4611
4650
  const api = createApiClient();
4612
- const analyses = await api.admin.getRecentAnalyses(limit);
4651
+ const analyses = await api.analysis.getRecent(limit);
4613
4652
  const rows = analyses.map((a) => ({
4614
4653
  analysisId: a.analysisId ?? "\u2014",
4615
4654
  projectName: a.projectName ?? "\u2014",
@@ -4626,7 +4665,7 @@ async function listAnalyses(limit, cmd) {
4626
4665
  async function getAnalysisDetails(analysisId, cmd) {
4627
4666
  const outputFormat = getOutputFormat14(cmd);
4628
4667
  const api = createApiClient();
4629
- const result = analysisId ? await api.admin.getAnalysis(analysisId) : await api.admin.getLastAnalysis();
4668
+ const result = analysisId ? await api.analysis.get(analysisId) : await api.analysis.getLast();
4630
4669
  if (!result.analysis) {
4631
4670
  console.log(chalk23.dim("No analysis found."));
4632
4671
  return;
@@ -4635,32 +4674,46 @@ async function getAnalysisDetails(analysisId, cmd) {
4635
4674
  }
4636
4675
  async function watchAnalysis(analysisId, cmd) {
4637
4676
  const api = createApiClient();
4638
- const result = analysisId ? await api.admin.getAnalysis(analysisId) : await api.admin.getLastAnalysis();
4677
+ const result = analysisId ? await api.analysis.get(analysisId) : await api.analysis.getLast();
4639
4678
  if (!result.analysis) {
4640
4679
  console.log(chalk23.dim("No analysis found."));
4641
4680
  return;
4642
4681
  }
4643
- const analysis = result.analysis;
4644
- if (analysis.phase === "COMPLETION") {
4645
- console.log(chalk23.green("Analysis already completed."));
4646
- console.log(` Analysis ID: ${analysis.analysisId}`);
4647
- if (analysis.projectId) {
4682
+ const recipe = result.analysis;
4683
+ if (!recipe.analysisId) {
4684
+ console.log(chalk23.dim("Analysis has no analysisId yet."));
4685
+ return;
4686
+ }
4687
+ const runs = await api.analysis.getRunsForAnalysis(recipe.analysisId, 1);
4688
+ if (runs.length === 0) {
4689
+ console.log(chalk23.dim("No runs for this analysis."));
4690
+ return;
4691
+ }
4692
+ const latest = runs[0];
4693
+ if (isTerminalState(latest.state)) {
4694
+ console.log(chalk23.green(`Latest run already in terminal state: ${latest.state}`));
4695
+ if (recipe.projectId && recipe.notebookId) {
4648
4696
  const config = loadConfig();
4649
4697
  const endpoint = config.profiles[config.currentProfile]?.endpoint ?? "https://diafunc.com";
4650
- console.log(` Project: ${analysisUrl(analysis, endpoint)}`);
4698
+ console.log(` Project: ${analysisUrl(recipe, endpoint)}`);
4651
4699
  }
4652
4700
  return;
4653
4701
  }
4654
- if (analysis.phase === "ANALYSIS") {
4655
- console.log(`Watching analysis for project "${analysis.projectId}" ...`);
4656
- await monitorAnalysis(api, analysis, cmd);
4657
- return;
4658
- }
4659
- console.log(chalk23.yellow(`Analysis in preparation (step: ${analysis.step}); not yet running.`));
4702
+ console.log(`Watching run ${latest.runId} for analysis ${recipe.analysisId} ...`);
4703
+ await monitorRun(api, latest.runId, recipe, cmd);
4704
+ }
4705
+ async function rerunAnalysis(analysisId) {
4706
+ const api = createApiClient();
4707
+ const run = await api.analysis.rerun(analysisId);
4708
+ console.log(chalk23.green(`\u2713 Queued new run ${run.runId} for analysis ${analysisId}`));
4709
+ console.log(chalk23.dim(` State: ${run.state}`));
4710
+ console.log();
4711
+ console.log(chalk23.dim("The dispatcher picks up queued runs every few seconds."));
4712
+ console.log(chalk23.dim(`Track progress: diafunc analyze watch ${analysisId}`));
4660
4713
  }
4661
4714
  async function openAnalysis(analysisId) {
4662
4715
  const api = createApiClient();
4663
- const result = analysisId ? await api.admin.getAnalysis(analysisId) : await api.admin.getLastAnalysis();
4716
+ const result = analysisId ? await api.analysis.get(analysisId) : await api.analysis.getLast();
4664
4717
  if (!result.analysis?.projectId) {
4665
4718
  console.log(chalk23.dim("No analysis found (or analysis has no project yet)."));
4666
4719
  return;
@@ -4671,9 +4724,179 @@ async function openAnalysis(analysisId) {
4671
4724
  console.log(`Opening ${url} ...`);
4672
4725
  openUrl(url);
4673
4726
  }
4727
+ async function createRecipe(options, cmd) {
4728
+ const outputFormat = getOutputFormat14(cmd);
4729
+ const api = createApiClient();
4730
+ const visibility = options.visibility.toUpperCase();
4731
+ const recipe = {
4732
+ userId: null,
4733
+ analysisId: null,
4734
+ phase: "PREPARATION",
4735
+ step: "LAUNCH_ANALYSIS",
4736
+ projectName: options.name ?? "CLI Analysis",
4737
+ projectDescription: options.description ?? "",
4738
+ visibility,
4739
+ time: options.hours,
4740
+ budget: options.budget,
4741
+ projectId: options.projectId,
4742
+ notebookId: null,
4743
+ rawDataTableId: options.rawDataTableId,
4744
+ analysisFunctionId: null,
4745
+ analysisChapterId: null,
4746
+ year: null,
4747
+ month: null,
4748
+ day: null,
4749
+ hour: null,
4750
+ evaluationId: null,
4751
+ started: null,
4752
+ targetKeys: parseCsv(options.targets),
4753
+ questions: parseCsv(options.questions),
4754
+ segmentKey: options.segment ?? null
4755
+ };
4756
+ const saved = await api.analysis.save(recipe);
4757
+ format(saved, { format: outputFormat });
4758
+ }
4759
+ async function updateRecipe(analysisId, options, cmd) {
4760
+ const outputFormat = getOutputFormat14(cmd);
4761
+ const api = createApiClient();
4762
+ const opt = await api.analysis.get(analysisId);
4763
+ if (!opt.analysis) {
4764
+ console.error(chalk23.red(`Analysis not found: ${analysisId}`));
4765
+ process.exit(1);
4766
+ }
4767
+ const recipe = opt.analysis;
4768
+ if (options.targets !== void 0) recipe.targetKeys = parseCsv(options.targets);
4769
+ if (options.hours !== void 0) recipe.time = options.hours;
4770
+ if (options.budget !== void 0) recipe.budget = options.budget;
4771
+ if (options.questions !== void 0) recipe.questions = parseCsv(options.questions);
4772
+ if (options.segment !== void 0) recipe.segmentKey = options.segment;
4773
+ if (options.name !== void 0) recipe.projectName = options.name;
4774
+ if (options.description !== void 0) recipe.projectDescription = options.description;
4775
+ const saved = await api.analysis.save(recipe);
4776
+ format(saved, { format: outputFormat });
4777
+ }
4778
+ async function listRuns(analysisId, count, cmd) {
4779
+ const outputFormat = getOutputFormat14(cmd);
4780
+ const api = createApiClient();
4781
+ const runs = await api.analysis.getRunsForAnalysis(analysisId, count);
4782
+ const rows = runs.map((r) => ({
4783
+ runId: r.runId,
4784
+ state: r.state,
4785
+ submittedAt: r.submittedAt ? new Date(r.submittedAt).toISOString() : "\u2014",
4786
+ startedAt: r.startedAt ? new Date(r.startedAt).toISOString() : "\u2014",
4787
+ endedAt: r.endedAt ? new Date(r.endedAt).toISOString() : "\u2014",
4788
+ evaluationId: r.evaluationId ?? "\u2014"
4789
+ }));
4790
+ format(rows, {
4791
+ format: outputFormat,
4792
+ columns: ["runId", "state", "submittedAt", "endedAt", "evaluationId"]
4793
+ });
4794
+ }
4795
+ async function cancelRun(runId, cmd) {
4796
+ const outputFormat = getOutputFormat14(cmd);
4797
+ const api = createApiClient();
4798
+ const run = await api.analysis.cancelRun(runId);
4799
+ if (outputFormat === "human") {
4800
+ console.log(chalk23.green(`\u2713 Run ${run.runId} state: ${run.state}`));
4801
+ } else {
4802
+ format(run, { format: outputFormat });
4803
+ }
4804
+ }
4805
+ async function listPresets(cmd) {
4806
+ const outputFormat = getOutputFormat14(cmd);
4807
+ const api = createApiClient();
4808
+ const presets = await api.analysis.getPresets();
4809
+ format(presets.map((p) => ({
4810
+ presetId: p.presetId ?? "\u2014",
4811
+ name: p.name,
4812
+ targets: p.targetKeys.join(", "),
4813
+ questions: p.questions.length,
4814
+ segment: p.segmentKey ?? "\u2014",
4815
+ hours: p.time,
4816
+ budget: p.budget
4817
+ })), {
4818
+ format: outputFormat,
4819
+ columns: ["presetId", "name", "targets", "questions", "segment", "hours", "budget"]
4820
+ });
4821
+ }
4822
+ async function getPreset(presetId, cmd) {
4823
+ const outputFormat = getOutputFormat14(cmd);
4824
+ const api = createApiClient();
4825
+ const opt = await api.analysis.getPreset(presetId);
4826
+ if (!opt.preset) {
4827
+ console.log(chalk23.dim("Preset not found."));
4828
+ return;
4829
+ }
4830
+ format(opt.preset, { format: outputFormat });
4831
+ }
4832
+ async function savePreset(options, cmd) {
4833
+ const outputFormat = getOutputFormat14(cmd);
4834
+ const api = createApiClient();
4835
+ const preset = {
4836
+ presetId: options.id ?? null,
4837
+ name: options.name,
4838
+ targetKeys: parseCsv(options.targets) ?? [],
4839
+ questions: parseCsv(options.questions) ?? [],
4840
+ segmentKey: options.segment ?? null,
4841
+ time: options.hours,
4842
+ budget: options.budget
4843
+ };
4844
+ const saved = await api.analysis.savePreset(preset);
4845
+ format(saved, { format: outputFormat });
4846
+ }
4847
+ async function deletePreset(presetId) {
4848
+ const api = createApiClient();
4849
+ await api.analysis.deletePreset(presetId);
4850
+ console.log(chalk23.green(`\u2713 Deleted preset ${presetId}`));
4851
+ }
4852
+ async function listTriggers(analysisId, cmd) {
4853
+ const outputFormat = getOutputFormat14(cmd);
4854
+ const api = createApiClient();
4855
+ const triggers = await api.analysis.listTriggers(analysisId);
4856
+ format(triggers.map((t) => ({
4857
+ triggerId: t.triggerId,
4858
+ kind: t.kind,
4859
+ schedule: t.scheduleSpec,
4860
+ active: t.active,
4861
+ nextFireAt: t.nextFireAt ? new Date(t.nextFireAt).toISOString() : "\u2014"
4862
+ })), {
4863
+ format: outputFormat,
4864
+ columns: ["triggerId", "kind", "schedule", "active", "nextFireAt"]
4865
+ });
4866
+ }
4867
+ async function createTrigger(analysisId, kind, schedule, cmd) {
4868
+ const outputFormat = getOutputFormat14(cmd);
4869
+ const upper = kind.toUpperCase();
4870
+ if (upper !== "ONCE" && upper !== "CRON") {
4871
+ console.error(chalk23.red(`Invalid kind "${kind}" \u2014 must be ONCE or CRON.`));
4872
+ process.exit(1);
4873
+ }
4874
+ const api = createApiClient();
4875
+ const trigger = await api.analysis.createTrigger(analysisId, {
4876
+ kind: upper,
4877
+ scheduleSpec: schedule
4878
+ });
4879
+ format(trigger, { format: outputFormat });
4880
+ }
4881
+ async function deleteTrigger(triggerId) {
4882
+ const api = createApiClient();
4883
+ await api.analysis.deleteTrigger(triggerId);
4884
+ console.log(chalk23.green(`\u2713 Deleted trigger ${triggerId}`));
4885
+ }
4886
+ async function toggleTrigger(triggerId, active, cmd) {
4887
+ const outputFormat = getOutputFormat14(cmd);
4888
+ const lc = active.toLowerCase();
4889
+ if (lc !== "true" && lc !== "false") {
4890
+ console.error(chalk23.red(`Invalid active value "${active}" \u2014 must be true or false.`));
4891
+ process.exit(1);
4892
+ }
4893
+ const api = createApiClient();
4894
+ const trigger = await api.analysis.updateTrigger(triggerId, { active: lc === "true" });
4895
+ format(trigger, { format: outputFormat });
4896
+ }
4674
4897
  function registerAnalyzeCommand(program) {
4675
4898
  const analyze = program.command("analyze").description("Run and manage automatic analyses");
4676
- analyze.argument("[file]", "CSV or Excel file to analyze").option("--name <name>", "Project name (derived from filename if omitted)").option("--description <text>", "Project description", "").option("--visibility <vis>", "Project visibility (PRIVATE or PUBLIC)", "PRIVATE").option("--time <hours>", "Computation time in hours", "4").option("--budget <credits>", "Credit budget", "400").action(async (file, options, cmd) => {
4899
+ analyze.argument("[file]", "CSV or Excel file to analyze").option("--name <name>", "Project name (derived from filename if omitted)").option("--description <text>", "Project description", "").option("--visibility <vis>", "Project visibility (PRIVATE or PUBLIC)", "PRIVATE").option("--time <hours>", "Computation time in hours", "4").option("--budget <credits>", "Credit budget", "400").option("--targets <keys>", "Comma-separated target column keys").option("--questions <list>", "Comma-separated questions to answer").option("--segment <key>", "Column key to segment the analysis by").action(async (file, options, cmd) => {
4677
4900
  try {
4678
4901
  if (!file) {
4679
4902
  analyze.help();
@@ -4698,7 +4921,7 @@ function registerAnalyzeCommand(program) {
4698
4921
  handleError(error);
4699
4922
  }
4700
4923
  });
4701
- analyze.command("watch").description("Live-monitor a running analysis with progress bar and streaming outputs").argument("[id]", "Analysis ID (defaults to the most recent)").action(async (id, _options, cmd) => {
4924
+ analyze.command("watch").description("Live-monitor the latest run of an analysis with progress and streaming outputs").argument("[id]", "Analysis ID (defaults to the most recent)").action(async (id, _options, cmd) => {
4702
4925
  try {
4703
4926
  await watchAnalysis(id, cmd);
4704
4927
  } catch (error) {
@@ -4712,6 +4935,99 @@ function registerAnalyzeCommand(program) {
4712
4935
  handleError(error);
4713
4936
  }
4714
4937
  });
4938
+ analyze.command("rerun").description("Rerun an existing analysis as a new run \u2014 reuses the recipe and data").argument("<id>", "Analysis ID to rerun").action(async (id) => {
4939
+ try {
4940
+ await rerunAnalysis(id);
4941
+ } catch (error) {
4942
+ handleError(error);
4943
+ }
4944
+ });
4945
+ analyze.command("create").description("Create a recipe without queuing a run (use `analyze rerun <id>` later to launch)").requiredOption("--project-id <id>", "Project ID hosting the raw-data table").requiredOption("--raw-data-table-id <id>", "Raw-data table entity ID").requiredOption("--targets <keys>", "Comma-separated target column keys").option("--hours <h>", "Computation hours", "4").option("--budget <credits>", "Credit budget", "400").option("--questions <list>", "Comma-separated questions").option("--segment <key>", "Segmentation column key").option("--name <name>", "Recipe name").option("--description <text>", "Recipe description").option("--visibility <vis>", "PRIVATE or PUBLIC", "PRIVATE").action(async (options, cmd) => {
4946
+ try {
4947
+ await createRecipe(options, cmd);
4948
+ } catch (error) {
4949
+ handleError(error);
4950
+ }
4951
+ });
4952
+ analyze.command("update").description("Update fields of an existing analysis recipe").argument("<id>", "Analysis ID to update").option("--targets <keys>", "New comma-separated target keys").option("--hours <h>", "New compute hours").option("--budget <credits>", "New token budget").option("--questions <list>", "New comma-separated questions").option("--segment <key>", "New segment key").option("--name <name>", "New name").option("--description <text>", "New description").action(async (id, options, cmd) => {
4953
+ try {
4954
+ await updateRecipe(id, options, cmd);
4955
+ } catch (error) {
4956
+ handleError(error);
4957
+ }
4958
+ });
4959
+ analyze.command("runs").description("List recent runs for an analysis (newest first)").argument("<id>", "Analysis ID").option("--count <n>", "Max number of runs to show", "20").action(async (id, options, cmd) => {
4960
+ try {
4961
+ await listRuns(id, parseInt(options.count, 10), cmd);
4962
+ } catch (error) {
4963
+ handleError(error);
4964
+ }
4965
+ });
4966
+ analyze.command("cancel").description("Cancel a non-terminal run (idempotent on terminal runs)").argument("<runId>", "Run ID to cancel").action(async (runId, _options, cmd) => {
4967
+ try {
4968
+ await cancelRun(runId, cmd);
4969
+ } catch (error) {
4970
+ handleError(error);
4971
+ }
4972
+ });
4973
+ const presets = analyze.command("presets").description("Manage saved analysis presets");
4974
+ presets.command("list").description("List your analysis presets").action(async (_options, cmd) => {
4975
+ try {
4976
+ await listPresets(cmd);
4977
+ } catch (error) {
4978
+ handleError(error);
4979
+ }
4980
+ });
4981
+ presets.command("get").description("Show details of a preset").argument("<id>", "Preset ID").action(async (id, _options, cmd) => {
4982
+ try {
4983
+ await getPreset(id, cmd);
4984
+ } catch (error) {
4985
+ handleError(error);
4986
+ }
4987
+ });
4988
+ presets.command("save").description("Create a new preset (omit --id) or update an existing one (with --id)").requiredOption("--name <name>", "Preset name").requiredOption("--targets <keys>", "Comma-separated target keys").requiredOption("--hours <h>", "Compute hours").requiredOption("--budget <credits>", "Credit budget").option("--questions <list>", "Comma-separated questions").option("--segment <key>", "Segmentation key").option("--id <id>", "Existing preset ID (update mode)").action(async (options, cmd) => {
4989
+ try {
4990
+ await savePreset(options, cmd);
4991
+ } catch (error) {
4992
+ handleError(error);
4993
+ }
4994
+ });
4995
+ presets.command("delete").description("Delete a preset").argument("<id>", "Preset ID").action(async (id) => {
4996
+ try {
4997
+ await deletePreset(id);
4998
+ } catch (error) {
4999
+ handleError(error);
5000
+ }
5001
+ });
5002
+ const triggers = analyze.command("triggers").description("Manage scheduled triggers on an analysis");
5003
+ triggers.command("list").description("List triggers for an analysis").argument("<analysisId>", "Analysis ID").action(async (analysisId, _options, cmd) => {
5004
+ try {
5005
+ await listTriggers(analysisId, cmd);
5006
+ } catch (error) {
5007
+ handleError(error);
5008
+ }
5009
+ });
5010
+ triggers.command("create").description("Create a trigger (ONCE: ISO-8601 timestamp; CRON: cron expression)").argument("<analysisId>", "Analysis ID").requiredOption("--kind <kind>", "ONCE or CRON").requiredOption("--schedule <spec>", "ISO-8601 timestamp (ONCE) or cron expression (CRON)").action(async (analysisId, options, cmd) => {
5011
+ try {
5012
+ await createTrigger(analysisId, options.kind, options.schedule, cmd);
5013
+ } catch (error) {
5014
+ handleError(error);
5015
+ }
5016
+ });
5017
+ triggers.command("delete").description("Delete a trigger").argument("<triggerId>", "Trigger ID").action(async (triggerId) => {
5018
+ try {
5019
+ await deleteTrigger(triggerId);
5020
+ } catch (error) {
5021
+ handleError(error);
5022
+ }
5023
+ });
5024
+ triggers.command("toggle").description("Activate or deactivate a trigger").argument("<triggerId>", "Trigger ID").requiredOption("--active <bool>", "true or false").action(async (triggerId, options, cmd) => {
5025
+ try {
5026
+ await toggleTrigger(triggerId, options.active, cmd);
5027
+ } catch (error) {
5028
+ handleError(error);
5029
+ }
5030
+ });
4715
5031
  }
4716
5032
 
4717
5033
  // src/commands/completion/index.ts
@@ -5403,4 +5719,4 @@ export {
5403
5719
  package_default,
5404
5720
  createProgram
5405
5721
  };
5406
- //# sourceMappingURL=chunk-YNIZ5WGU.js.map
5722
+ //# sourceMappingURL=chunk-PDVC2LAL.js.map