@amaster.ai/runtime-cli 1.1.10 → 1.1.11

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.
package/dist/cli.js CHANGED
@@ -1,11 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
  import { existsSync, rmSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
3
- import { join, resolve } from 'path';
3
+ import { join, resolve, basename } from 'path';
4
4
  import { homedir } from 'os';
5
5
  import { Command, Option } from 'commander';
6
- import chalk7 from 'chalk';
6
+ import chalk3 from 'chalk';
7
7
  import { createClient } from '@amaster.ai/client';
8
8
  import ora from 'ora';
9
+ import { File } from 'buffer';
9
10
  import yaml from 'yaml';
10
11
 
11
12
  var __defProp = Object.defineProperty;
@@ -325,9 +326,9 @@ async function login(appCode, options) {
325
326
  const appConfig = getAppConfig(appCode);
326
327
  if (!appConfig) {
327
328
  spinner.fail(`App not configured: ${appCode}`);
328
- console.error(chalk7.red(`
329
+ console.error(chalk3.red(`
329
330
  \u274C App not found: ${appCode}`));
330
- console.log(chalk7.yellow(`Initialize it first: amaster init --app-code ${appCode} --url <url>`));
331
+ console.log(chalk3.yellow(`Initialize it first: amaster init --app-code ${appCode} --url <url>`));
331
332
  process.exit(1);
332
333
  }
333
334
  let username = options.username;
@@ -376,7 +377,7 @@ async function login(appCode, options) {
376
377
  const result = await client.auth.login(loginParams);
377
378
  if (result.error) {
378
379
  spinner.fail("Login failed");
379
- console.error(chalk7.red(result.error.message));
380
+ console.error(chalk3.red(result.error.message));
380
381
  process.exit(1);
381
382
  }
382
383
  const loginData = result.data;
@@ -410,16 +411,16 @@ async function login(appCode, options) {
410
411
  format: options.format,
411
412
  pretty: () => {
412
413
  console.log(
413
- chalk7.green(
414
+ chalk3.green(
414
415
  `
415
416
  Welcome, ${loginData.user?.displayName || loginData.user?.email || loginData.user?.username || email}!`
416
417
  )
417
418
  );
418
- console.log(chalk7.gray(`App: ${appCode}`));
419
- console.log(chalk7.gray(`URL: ${appConfig.baseURL}`));
419
+ console.log(chalk3.gray(`App: ${appCode}`));
420
+ console.log(chalk3.gray(`URL: ${appConfig.baseURL}`));
420
421
  if (expiresAt) {
421
422
  const expires = new Date(expiresAt);
422
- console.log(chalk7.gray(`Session expires: ${expires.toLocaleString()}`));
423
+ console.log(chalk3.gray(`Session expires: ${expires.toLocaleString()}`));
423
424
  }
424
425
  }
425
426
  }
@@ -455,7 +456,7 @@ async function logout(appCode, options = {}) {
455
456
  {
456
457
  format: options.format,
457
458
  pretty: () => {
458
- console.log(chalk7.green(`Logged out from ${appCode}`));
459
+ console.log(chalk3.green(`Logged out from ${appCode}`));
459
460
  }
460
461
  }
461
462
  );
@@ -471,7 +472,7 @@ async function getMe(getClient, options = {}) {
471
472
  const result = await client.auth.getMe();
472
473
  if (result.error) {
473
474
  spinner.fail("Failed to fetch user info");
474
- console.error(chalk7.red(result.error.message));
475
+ console.error(chalk3.red(result.error.message));
475
476
  process.exit(1);
476
477
  }
477
478
  spinner.succeed("User info retrieved");
@@ -479,11 +480,11 @@ async function getMe(getClient, options = {}) {
479
480
  renderOutput(user, {
480
481
  format: options.format,
481
482
  pretty: () => {
482
- console.log(chalk7.blue("\n\u{1F464} User Profile\n"));
483
- console.log(` ${chalk7.bold("UID:")} ${user?.uid}`);
484
- console.log(` ${chalk7.bold("Email:")} ${user?.email}`);
485
- console.log(` ${chalk7.bold("Name:")} ${user?.displayName || user?.username || "N/A"}`);
486
- console.log(` ${chalk7.bold("Status:")} ${user?.isActive ? "Active" : "Inactive"}`);
483
+ console.log(chalk3.blue("\n\u{1F464} User Profile\n"));
484
+ console.log(` ${chalk3.bold("UID:")} ${user?.uid}`);
485
+ console.log(` ${chalk3.bold("Email:")} ${user?.email}`);
486
+ console.log(` ${chalk3.bold("Name:")} ${user?.displayName || user?.username || "N/A"}`);
487
+ console.log(` ${chalk3.bold("Status:")} ${user?.isActive ? "Active" : "Inactive"}`);
487
488
  }
488
489
  });
489
490
  } catch (error) {
@@ -613,7 +614,7 @@ function exitWithCommandError(spinner, failureMessage, error) {
613
614
  spinner.fail(failureMessage);
614
615
  const details = error instanceof Error ? error.message : String(error);
615
616
  if (details) {
616
- console.error(chalk7.red(details));
617
+ console.error(chalk3.red(details));
617
618
  }
618
619
  process.exit(1);
619
620
  }
@@ -665,14 +666,20 @@ async function listEntities(client, options) {
665
666
  try {
666
667
  const entityClient = client.entity;
667
668
  const query = buildListQueryParams(options);
669
+ const paginationParams = {};
670
+ if (options.page !== void 0) {
671
+ paginationParams.page = options.page;
672
+ }
673
+ if (options.pageSize !== void 0) {
674
+ paginationParams.perPage = options.pageSize;
675
+ }
668
676
  const result = await entityClient.list(options.namespace, options.entity, {
669
677
  ...query,
670
- page: options.page || 1,
671
- perPage: options.pageSize || 10
678
+ ...paginationParams
672
679
  });
673
680
  if (result.error) {
674
681
  spinner.fail("Failed to fetch entities");
675
- console.error(chalk7.red(result.error.message));
682
+ console.error(chalk3.red(result.error.message));
676
683
  process.exit(1);
677
684
  }
678
685
  spinner.stop();
@@ -692,12 +699,12 @@ async function listEntities(client, options) {
692
699
  renderOutput(result.data, {
693
700
  format: options.format,
694
701
  pretty: () => {
695
- console.log(chalk7.blue(`
702
+ console.log(chalk3.blue(`
696
703
  \u{1F4E6} ${options.entity} in ${options.namespace}`));
697
- console.log(chalk7.gray(`\u5171 ${total} \u6761\u8BB0\u5F55:
704
+ console.log(chalk3.gray(`\u5171 ${total} \u6761\u8BB0\u5F55:
698
705
  `));
699
706
  if (items.length === 0) {
700
- console.log(chalk7.gray(" \u6682\u65E0\u6570\u636E"));
707
+ console.log(chalk3.gray(" \u6682\u65E0\u6570\u636E"));
701
708
  return;
702
709
  }
703
710
  const firstItem = items[0];
@@ -717,7 +724,7 @@ async function listEntities(client, options) {
717
724
  });
718
725
  const headerLine = keys.map((key) => {
719
726
  const width = widths[key] ?? 0;
720
- return chalk7.bold(key.slice(0, width).padEnd(width));
727
+ return chalk3.bold(key.slice(0, width).padEnd(width));
721
728
  }).join("\u2502");
722
729
  console.log(" " + headerLine);
723
730
  console.log(" " + keys.map((key) => "\u2500".repeat(widths[key] ?? 0)).join("\u253C"));
@@ -733,7 +740,7 @@ async function listEntities(client, options) {
733
740
  }
734
741
  console.log();
735
742
  if (items.length < total) {
736
- console.log(chalk7.gray(` ... \u8FD8\u6709 ${total - items.length} \u6761\u8BB0\u5F55`));
743
+ console.log(chalk3.gray(` ... \u8FD8\u6709 ${total - items.length} \u6761\u8BB0\u5F55`));
737
744
  }
738
745
  }
739
746
  });
@@ -748,14 +755,14 @@ async function getEntity(client, options) {
748
755
  const result = await entityClient.get(options.namespace, options.entity, options.id);
749
756
  if (result.error) {
750
757
  spinner.fail("Failed to fetch entity");
751
- console.error(chalk7.red(result.error.message));
758
+ console.error(chalk3.red(result.error.message));
752
759
  process.exit(1);
753
760
  }
754
761
  spinner.succeed("Entity retrieved");
755
762
  renderOutput(result.data, {
756
763
  format: options.format,
757
764
  pretty: () => {
758
- console.log(chalk7.blue(`
765
+ console.log(chalk3.blue(`
759
766
  \u{1F4C4} ${options.entity}
760
767
  `));
761
768
  console.log(JSON.stringify(result.data, null, 2));
@@ -773,14 +780,14 @@ async function createEntity(client, options) {
773
780
  const result = await entityClient.create(options.namespace, options.entity, data);
774
781
  if (result.error) {
775
782
  spinner.fail("Failed to create entity");
776
- console.error(chalk7.red(result.error.message));
783
+ console.error(chalk3.red(result.error.message));
777
784
  process.exit(1);
778
785
  }
779
786
  spinner.succeed("Entity created");
780
787
  renderOutput(result.data, {
781
788
  format: options.format,
782
789
  pretty: () => {
783
- console.log(chalk7.green("\nCreated entity:"));
790
+ console.log(chalk3.green("\nCreated entity:"));
784
791
  console.log(JSON.stringify(result.data, null, 2));
785
792
  }
786
793
  });
@@ -796,14 +803,14 @@ async function updateEntity(client, options) {
796
803
  const result = await entityClient.update(options.namespace, options.entity, options.id, data);
797
804
  if (result.error) {
798
805
  spinner.fail("Failed to update entity");
799
- console.error(chalk7.red(result.error.message));
806
+ console.error(chalk3.red(result.error.message));
800
807
  process.exit(1);
801
808
  }
802
809
  spinner.succeed("Entity updated");
803
810
  renderOutput(result.data, {
804
811
  format: options.format,
805
812
  pretty: () => {
806
- console.log(chalk7.green("\nUpdated entity:"));
813
+ console.log(chalk3.green("\nUpdated entity:"));
807
814
  console.log(JSON.stringify(result.data, null, 2));
808
815
  }
809
816
  });
@@ -818,7 +825,7 @@ async function deleteEntity(client, options) {
818
825
  const result = await entityClient.delete(options.namespace, options.entity, options.id);
819
826
  if (result.error) {
820
827
  spinner.fail("Failed to delete entity");
821
- console.error(chalk7.red(result.error.message));
828
+ console.error(chalk3.red(result.error.message));
822
829
  process.exit(1);
823
830
  }
824
831
  spinner.succeed("Entity deleted");
@@ -832,7 +839,7 @@ async function deleteEntity(client, options) {
832
839
  {
833
840
  format: options.format,
834
841
  pretty: () => {
835
- console.log(chalk7.green(`
842
+ console.log(chalk3.green(`
836
843
  Deleted ${options.entity} with ID: ${options.id}`));
837
844
  }
838
845
  }
@@ -849,14 +856,14 @@ async function listEntityOptions(client, options) {
849
856
  const result = await entityClient.options(options.namespace, options.entity, fields);
850
857
  if (result.error) {
851
858
  spinner.fail("Failed to fetch entity options");
852
- console.error(chalk7.red(result.error.message));
859
+ console.error(chalk3.red(result.error.message));
853
860
  process.exit(1);
854
861
  }
855
862
  spinner.succeed(`Found ${result.data?.length || 0} options`);
856
863
  renderOutput(result.data || [], {
857
864
  format: options.format,
858
865
  pretty: () => {
859
- console.log(chalk7.blue(`
866
+ console.log(chalk3.blue(`
860
867
  \u{1F9FE} ${options.entity} options
861
868
  `));
862
869
  console.log(JSON.stringify(result.data || [], null, 2));
@@ -879,14 +886,14 @@ async function bulkUpdateEntities(client, options) {
879
886
  const result = await entityClient.bulkUpdate(options.namespace, options.entity, items);
880
887
  if (result.error) {
881
888
  spinner.fail("Failed to bulk update entities");
882
- console.error(chalk7.red(result.error.message));
889
+ console.error(chalk3.red(result.error.message));
883
890
  process.exit(1);
884
891
  }
885
892
  spinner.succeed(`Updated ${items.length} entities`);
886
893
  renderOutput(result.data, {
887
894
  format: options.format,
888
895
  pretty: () => {
889
- console.log(chalk7.green(`
896
+ console.log(chalk3.green(`
890
897
  Bulk updated ${items.length} ${options.entity} records:`));
891
898
  console.log(JSON.stringify(result.data, null, 2));
892
899
  }
@@ -903,7 +910,7 @@ async function bulkDeleteEntities(client, options) {
903
910
  const result = await entityClient.bulkDelete(options.namespace, options.entity, ids);
904
911
  if (result.error) {
905
912
  spinner.fail("Failed to bulk delete entities");
906
- console.error(chalk7.red(result.error.message));
913
+ console.error(chalk3.red(result.error.message));
907
914
  process.exit(1);
908
915
  }
909
916
  spinner.succeed(`Deleted ${ids.length} entities`);
@@ -918,7 +925,7 @@ async function bulkDeleteEntities(client, options) {
918
925
  {
919
926
  format: options.format,
920
927
  pretty: () => {
921
- console.log(chalk7.green(`
928
+ console.log(chalk3.green(`
922
929
  Deleted ${ids.length} ${options.entity} records.`));
923
930
  }
924
931
  }
@@ -927,14 +934,256 @@ Deleted ${ids.length} ${options.entity} records.`));
927
934
  exitWithCommandError(spinner, "Failed to bulk delete entities", error);
928
935
  }
929
936
  }
937
+ function isPlainObject3(value) {
938
+ return typeof value === "object" && value !== null && !Array.isArray(value);
939
+ }
940
+ function resolveInputSource2(input) {
941
+ if (!input.startsWith("@")) {
942
+ return input;
943
+ }
944
+ const filePath = input.slice(1);
945
+ if (!filePath) {
946
+ throw new Error("File path is required after '@'.");
947
+ }
948
+ return readFileSync(filePath, "utf8");
949
+ }
950
+ function parseJsonInput2(input, label) {
951
+ const source = resolveInputSource2(input).trim();
952
+ if (!source) {
953
+ throw new Error(`${label} is required.`);
954
+ }
955
+ try {
956
+ return JSON.parse(source);
957
+ } catch (error) {
958
+ const reason = error instanceof Error ? error.message : String(error);
959
+ throw new Error(`Invalid ${label}: ${reason}`);
960
+ }
961
+ }
962
+ async function promptForJson2(message, defaultValue) {
963
+ const { default: inquirer } = await import('inquirer');
964
+ const { jsonData } = await inquirer.prompt([
965
+ {
966
+ type: "editor",
967
+ name: "jsonData",
968
+ message,
969
+ default: defaultValue
970
+ }
971
+ ]);
972
+ return jsonData;
973
+ }
974
+ async function loadJsonObjectInput2(input, label, promptMessage) {
975
+ const source = input ?? await promptForJson2(promptMessage, "{}");
976
+ const value = parseJsonInput2(source, label);
977
+ if (!isPlainObject3(value)) {
978
+ throw new Error(`${label} must be a JSON object.`);
979
+ }
980
+ return value;
981
+ }
982
+ function loadOptionalJsonObjectInput2(input, label) {
983
+ if (!input) {
984
+ return {};
985
+ }
986
+ const value = parseJsonInput2(input, label);
987
+ if (!isPlainObject3(value)) {
988
+ throw new Error(`${label} must be a JSON object.`);
989
+ }
990
+ return value;
991
+ }
992
+ function exitWithCommandError2(spinner, failureMessage, error) {
993
+ spinner.fail(failureMessage);
994
+ const details = error instanceof Error ? error.message : String(error);
995
+ if (details) {
996
+ console.error(chalk3.red(details));
997
+ }
998
+ process.exit(1);
999
+ }
1000
+ function extractClientErrorMessage(error) {
1001
+ return error?.message || "Unknown BPM client error.";
1002
+ }
1003
+ function exitWithClientError(spinner, failureMessage, error, diagnosticMessage) {
1004
+ spinner.fail(failureMessage);
1005
+ console.error(chalk3.red(diagnosticMessage || extractClientErrorMessage(error)));
1006
+ process.exit(1);
1007
+ }
1008
+ function inspectStartEventFormConfiguration(bpmnXml) {
1009
+ const startEventMatches = bpmnXml.match(/<[^>]*startEvent\b[\s\S]*?(?:<\/[^>]*startEvent>|\/>)/g) || [];
1010
+ return {
1011
+ startEventCount: startEventMatches.length,
1012
+ hasFormKey: startEventMatches.some((eventXml) => /\bformKey\s*=/.test(eventXml)),
1013
+ hasCamundaFormRef: startEventMatches.some((eventXml) => /\bcamunda:formRef\s*=/.test(eventXml)),
1014
+ hasCamundaFormData: startEventMatches.some((eventXml) => /<camunda:formData\b/.test(eventXml))
1015
+ };
1016
+ }
1017
+ async function diagnoseTaskFormSchemaError(bpmClient, taskId, originalMessage) {
1018
+ try {
1019
+ const taskFormResult = await bpmClient.getTaskForm(taskId);
1020
+ if (taskFormResult?.error || !taskFormResult?.data) {
1021
+ return null;
1022
+ }
1023
+ const key = typeof taskFormResult.data.key === "string" && taskFormResult.data.key.length > 0 ? taskFormResult.data.key : null;
1024
+ const camundaFormRef = taskFormResult.data.camundaFormRef;
1025
+ if (!camundaFormRef && key?.includes("/rendered-form")) {
1026
+ return [
1027
+ `Task '${taskId}' uses an embedded/generated Camunda form (${key}) rather than a schema-backed form.`,
1028
+ "`bpm task-form-schema` is expected to return 404 in this case.",
1029
+ "Use `bpm task-form`, `bpm task-rendered-form`, or `bpm task-form-variables` instead."
1030
+ ].join(" ");
1031
+ }
1032
+ if (!camundaFormRef && !key) {
1033
+ return [
1034
+ `Task '${taskId}' does not expose schema-backed form metadata.`,
1035
+ "Use `bpm task-form` or `bpm task-form-variables` instead."
1036
+ ].join(" ");
1037
+ }
1038
+ if (camundaFormRef) {
1039
+ return [
1040
+ `Task '${taskId}' appears to reference a Camunda form via camundaFormRef, but the backend returned 404 for /form-schema.`,
1041
+ `Original error: ${originalMessage}`
1042
+ ].join(" ");
1043
+ }
1044
+ } catch {
1045
+ }
1046
+ return null;
1047
+ }
1048
+ async function diagnoseStartFormError(bpmClient, processKey, originalMessage) {
1049
+ let tenantId = null;
1050
+ let startFormConfig = null;
1051
+ try {
1052
+ const definitionsResult = await bpmClient.getProcessDefinitions({ key: processKey, latestVersion: true });
1053
+ if (!definitionsResult?.error && Array.isArray(definitionsResult?.data) && definitionsResult.data.length > 0) {
1054
+ const latestDefinition = definitionsResult.data[0];
1055
+ tenantId = latestDefinition?.tenantId || null;
1056
+ }
1057
+ } catch {
1058
+ }
1059
+ try {
1060
+ const xmlResult = await bpmClient.getProcessXml(processKey);
1061
+ if (!xmlResult?.error && typeof xmlResult?.data?.bpmn20Xml === "string") {
1062
+ startFormConfig = inspectStartEventFormConfiguration(xmlResult.data.bpmn20Xml);
1063
+ }
1064
+ } catch {
1065
+ }
1066
+ if (startFormConfig && !startFormConfig.hasFormKey && !startFormConfig.hasCamundaFormRef && !startFormConfig.hasCamundaFormData) {
1067
+ const tenantHint = tenantId && /no tenant-id/i.test(originalMessage) ? ` The process definition is tenant-scoped ('${tenantId}'), and this endpoint also appears to resolve by key without tenant context.` : "";
1068
+ return [
1069
+ `Process '${processKey}' exists, but its start event does not define formKey, camunda:formRef, or camunda:formData.`,
1070
+ "`bpm start-form*` endpoints are expected to fail for this model.",
1071
+ `Use \`bpm xml ${processKey}\` to inspect the BPMN or configure a start form first.${tenantHint}`
1072
+ ].join(" ");
1073
+ }
1074
+ if (tenantId && /no tenant-id/i.test(originalMessage)) {
1075
+ return [
1076
+ `Process '${processKey}' exists under tenant '${tenantId}', but the backend start-form endpoint resolved the process definition by key without tenant-id.`,
1077
+ "Current CLI/SDK sends only processKey for this endpoint.",
1078
+ "This is likely a backend multi-tenant lookup limitation rather than a wrong CLI parameter."
1079
+ ].join(" ");
1080
+ }
1081
+ if (/formKey/i.test(originalMessage) && /camunda:formRef/i.test(originalMessage)) {
1082
+ return [
1083
+ `Process '${processKey}' does not expose a deployed start form because neither formKey nor camunda:formRef is configured on the start event.`,
1084
+ "If you need a start form, add formKey or camunda:formRef in the BPMN model."
1085
+ ].join(" ");
1086
+ }
1087
+ return null;
1088
+ }
1089
+ function buildProcessDefinitionQueryParams(options) {
1090
+ const params = loadOptionalJsonObjectInput2(options.query, "process query params");
1091
+ if (options.key) params.key = options.key;
1092
+ if (options.name) params.name = options.name;
1093
+ if (options.latestVersion !== void 0) params.latestVersion = options.latestVersion;
1094
+ if (options.active !== void 0) params.active = options.active;
1095
+ if (options.suspended !== void 0) params.suspended = options.suspended;
1096
+ if (options.sortBy) params.sortBy = options.sortBy;
1097
+ if (options.sortOrder) params.sortOrder = options.sortOrder;
1098
+ return params;
1099
+ }
1100
+ function buildTaskQueryParams(options) {
1101
+ const params = loadOptionalJsonObjectInput2(options.query, "task query params");
1102
+ if (options.processInstanceId) params.processInstanceId = options.processInstanceId;
1103
+ if (options.assignee) params.assignee = options.assignee;
1104
+ if (options.candidateUser) params.candidateUser = options.candidateUser;
1105
+ if (options.candidateGroup) params.candidateGroup = options.candidateGroup;
1106
+ if (options.name) params.name = options.name;
1107
+ if (options.nameLike) params.nameLike = options.nameLike;
1108
+ if (options.taskDefinitionKey) params.taskDefinitionKey = options.taskDefinitionKey;
1109
+ if (options.firstResult !== void 0) params.firstResult = options.firstResult;
1110
+ if (options.maxResults !== void 0) params.maxResults = options.maxResults;
1111
+ if (options.sortBy) params.sortBy = options.sortBy;
1112
+ if (options.sortOrder) params.sortOrder = options.sortOrder;
1113
+ return params;
1114
+ }
1115
+ function buildProcessInstanceQueryParams(options) {
1116
+ const params = loadOptionalJsonObjectInput2(options.query, "process instance query params");
1117
+ if (options.processDefinitionKey) params.processDefinitionKey = options.processDefinitionKey;
1118
+ if (options.active !== void 0) params.active = options.active;
1119
+ if (options.firstResult !== void 0) params.firstResult = options.firstResult;
1120
+ if (options.maxResults !== void 0) params.maxResults = options.maxResults;
1121
+ return params;
1122
+ }
1123
+ function buildHistoryTaskQueryParams(options) {
1124
+ const params = loadOptionalJsonObjectInput2(options.query, "history task query params");
1125
+ if (options.taskAssignee) params.taskAssignee = options.taskAssignee;
1126
+ if (options.processInstanceId) params.processInstanceId = options.processInstanceId;
1127
+ if (options.finished !== void 0) params.finished = options.finished;
1128
+ if (options.unfinished !== void 0) params.unfinished = options.unfinished;
1129
+ if (options.scope) params.scope = options.scope;
1130
+ if (options.firstResult !== void 0) params.firstResult = options.firstResult;
1131
+ if (options.maxResults !== void 0) params.maxResults = options.maxResults;
1132
+ if (options.sortBy) params.sortBy = options.sortBy;
1133
+ if (options.sortOrder) params.sortOrder = options.sortOrder;
1134
+ return params;
1135
+ }
1136
+ function buildHistoryProcessInstanceQueryParams(options) {
1137
+ const params = loadOptionalJsonObjectInput2(options.query, "history process instance query params");
1138
+ if (options.startedBy) params.startedBy = options.startedBy;
1139
+ if (options.finished !== void 0) params.finished = options.finished;
1140
+ if (options.unfinished !== void 0) params.unfinished = options.unfinished;
1141
+ if (options.processDefinitionKey) params.processDefinitionKey = options.processDefinitionKey;
1142
+ if (options.scope) params.scope = options.scope;
1143
+ if (options.sortBy) params.sortBy = options.sortBy;
1144
+ if (options.sortOrder) params.sortOrder = options.sortOrder;
1145
+ if (options.firstResult !== void 0) params.firstResult = options.firstResult;
1146
+ if (options.maxResults !== void 0) params.maxResults = options.maxResults;
1147
+ return params;
1148
+ }
1149
+ function buildHistoryActivityQueryParams(options) {
1150
+ const params = loadOptionalJsonObjectInput2(options.query, "history activity query params");
1151
+ if (options.processInstanceId) params.processInstanceId = options.processInstanceId;
1152
+ if (options.activityId) params.activityId = options.activityId;
1153
+ if (options.activityType) params.activityType = options.activityType;
1154
+ if (options.finished !== void 0) params.finished = options.finished;
1155
+ if (options.sortBy) params.sortBy = options.sortBy;
1156
+ if (options.sortOrder) params.sortOrder = options.sortOrder;
1157
+ return params;
1158
+ }
1159
+ function buildHistoryVariableQueryParams(options) {
1160
+ const params = loadOptionalJsonObjectInput2(options.query, "history variable query params");
1161
+ if (options.processInstanceId) params.processInstanceId = options.processInstanceId;
1162
+ if (options.variableName) params.variableName = options.variableName;
1163
+ if (options.deserializeValues !== void 0) params.deserializeValues = options.deserializeValues;
1164
+ return params;
1165
+ }
1166
+ function buildUserOperationLogQueryParams(options) {
1167
+ const params = loadOptionalJsonObjectInput2(options.query, "user operation log query params");
1168
+ if (options.processInstanceId) params.processInstanceId = options.processInstanceId;
1169
+ if (options.taskId) params.taskId = options.taskId;
1170
+ if (options.userId) params.userId = options.userId;
1171
+ if (options.operationType) params.operationType = options.operationType;
1172
+ if (options.sortBy) params.sortBy = options.sortBy;
1173
+ if (options.sortOrder) params.sortOrder = options.sortOrder;
1174
+ if (options.firstResult !== void 0) params.firstResult = options.firstResult;
1175
+ if (options.maxResults !== void 0) params.maxResults = options.maxResults;
1176
+ return params;
1177
+ }
930
1178
  async function listProcesses(client, options = {}) {
931
1179
  const spinner = createSpinner("Fetching process definitions...", options.format);
932
1180
  try {
933
1181
  const bpmClient = client.bpm;
934
- const result = await bpmClient.getProcessDefinitions();
1182
+ const params = buildProcessDefinitionQueryParams(options);
1183
+ const result = await bpmClient.getProcessDefinitions(params);
935
1184
  if (result.error) {
936
1185
  spinner.fail("Failed to fetch processes");
937
- console.error(chalk7.red(result.error.message));
1186
+ console.error(chalk3.red(result.error.message));
938
1187
  process.exit(1);
939
1188
  }
940
1189
  spinner.succeed(`Found ${result.data?.length || 0} process definitions`);
@@ -942,169 +1191,1045 @@ async function listProcesses(client, options = {}) {
942
1191
  renderOutput(processes, {
943
1192
  format: options.format,
944
1193
  pretty: () => {
945
- console.log(chalk7.blue("\n\u{1F4CA} Process Definitions\n"));
1194
+ console.log(chalk3.blue("\n\u{1F4CA} Process Definitions\n"));
946
1195
  for (const proc of processes) {
947
- console.log(` ${chalk7.green("\u2022")} ${chalk7.bold(proc.key)}`);
948
- console.log(` ${chalk7.gray("Name:")} ${proc.name || "N/A"}`);
949
- console.log(` ${chalk7.gray("Version:")} ${proc.version || "N/A"}`);
1196
+ console.log(` ${chalk3.green("\u2022")} ${chalk3.bold(proc.key)}`);
1197
+ console.log(` ${chalk3.gray("ID:")} ${proc.id || "N/A"}`);
1198
+ console.log(` ${chalk3.gray("Name:")} ${proc.name || "N/A"}`);
1199
+ console.log(` ${chalk3.gray("Version:")} ${proc.version || "N/A"}`);
1200
+ console.log(` ${chalk3.gray("Suspended:")} ${proc.suspended ? "Yes" : "No"}`);
950
1201
  console.log();
951
1202
  }
952
1203
  }
953
1204
  });
954
1205
  } catch (error) {
955
- spinner.fail("Failed to fetch processes");
956
- throw error;
1206
+ exitWithCommandError2(spinner, "Failed to fetch processes", error);
1207
+ }
1208
+ }
1209
+ async function getProcessXml(client, options) {
1210
+ const spinner = createSpinner(`Fetching BPMN XML for ${options.key}...`, options.format);
1211
+ try {
1212
+ const bpmClient = client.bpm;
1213
+ const result = await bpmClient.getProcessXml(options.key);
1214
+ if (result.error) {
1215
+ spinner.fail("Failed to fetch process XML");
1216
+ console.error(chalk3.red(result.error.message));
1217
+ process.exit(1);
1218
+ }
1219
+ spinner.succeed("Process XML retrieved");
1220
+ renderOutput(result.data, {
1221
+ format: options.format,
1222
+ pretty: () => {
1223
+ console.log(chalk3.blue(`
1224
+ \u{1F4C4} BPMN XML: ${options.key}
1225
+ `));
1226
+ console.log(result.data?.bpmn20Xml || "");
1227
+ }
1228
+ });
1229
+ } catch (error) {
1230
+ exitWithCommandError2(spinner, "Failed to fetch process XML", error);
957
1231
  }
958
1232
  }
959
1233
  async function startProcess(client, options) {
960
1234
  const spinner = createSpinner(`Starting process: ${options.key}...`, options.format);
961
1235
  try {
962
1236
  const bpmClient = client.bpm;
963
- const variables = options.variables ? JSON.parse(options.variables) : {};
964
- const result = await bpmClient.startProcess({
965
- processKey: options.key,
966
- variables
967
- });
1237
+ const variables = loadOptionalJsonObjectInput2(options.variables, "process variables");
1238
+ const result = await bpmClient.startProcess(options.key, variables);
968
1239
  if (result.error) {
969
1240
  spinner.fail("Failed to start process");
970
- console.error(chalk7.red(result.error.message));
1241
+ console.error(chalk3.red(result.error.message));
971
1242
  process.exit(1);
972
1243
  }
973
1244
  spinner.succeed("Process started");
974
1245
  renderOutput(result.data, {
975
1246
  format: options.format,
976
1247
  pretty: () => {
977
- console.log(chalk7.green("\nProcess Instance:"));
978
- console.log(` ${chalk7.bold("ID:")} ${result.data?.id}`);
979
- console.log(` ${chalk7.bold("Definition ID:")} ${result.data?.definitionId}`);
980
- console.log(` ${chalk7.bold("Business Key:")} ${result.data?.businessKey || "N/A"}`);
981
- console.log(` ${chalk7.bold("Status:")} ${result.data?.suspended ? "Suspended" : "Active"}`);
1248
+ console.log(chalk3.green("\nProcess Instance:"));
1249
+ console.log(` ${chalk3.bold("ID:")} ${result.data?.id}`);
1250
+ console.log(` ${chalk3.bold("Definition ID:")} ${result.data?.definitionId}`);
1251
+ console.log(` ${chalk3.bold("Business Key:")} ${result.data?.businessKey || "N/A"}`);
1252
+ console.log(` ${chalk3.bold("Status:")} ${result.data?.suspended ? "Suspended" : "Active"}`);
982
1253
  }
983
1254
  });
984
1255
  } catch (error) {
985
- spinner.fail("Failed to start process");
986
- throw error;
1256
+ exitWithCommandError2(spinner, "Failed to start process", error);
987
1257
  }
988
1258
  }
989
- async function listTasks(client, options) {
990
- const spinner = createSpinner("Fetching tasks...", options.format);
1259
+ async function listProcessInstances(client, options = {}) {
1260
+ const spinner = createSpinner("Fetching process instances...", options.format);
991
1261
  try {
992
1262
  const bpmClient = client.bpm;
993
- const params = {};
994
- if (options.assignee) {
995
- params.assignee = options.assignee;
996
- }
997
- const result = await bpmClient.getMyTasks(params);
1263
+ const params = buildProcessInstanceQueryParams(options);
1264
+ const result = await bpmClient.getProcessInstances(params);
998
1265
  if (result.error) {
999
- spinner.fail("Failed to fetch tasks");
1000
- console.error(chalk7.red(result.error.message));
1266
+ spinner.fail("Failed to fetch process instances");
1267
+ console.error(chalk3.red(result.error.message));
1001
1268
  process.exit(1);
1002
1269
  }
1003
- spinner.succeed(`Found ${result.data?.length || 0} tasks`);
1004
- const tasks = result.data || [];
1005
- renderOutput(tasks, {
1270
+ spinner.succeed(`Found ${result.data?.length || 0} process instances`);
1271
+ const instances = result.data || [];
1272
+ renderOutput(instances, {
1006
1273
  format: options.format,
1007
1274
  pretty: () => {
1008
- console.log(chalk7.blue("\n\u{1F4DD} Tasks\n"));
1009
- for (const task of tasks) {
1010
- console.log(` ${chalk7.green("\u2022")} ${chalk7.bold(task.name || task.id)}`);
1011
- console.log(` ${chalk7.gray("ID:")} ${task.id}`);
1012
- console.log(` ${chalk7.gray("Assignee:")} ${task.assignee || "Unassigned"}`);
1013
- console.log(` ${chalk7.gray("Created:")} ${task.created || "N/A"}`);
1275
+ console.log(chalk3.blue("\n\u{1F504} Process Instances\n"));
1276
+ for (const instance of instances) {
1277
+ console.log(` ${chalk3.green("\u2022")} ${chalk3.bold(instance.id)}`);
1278
+ console.log(` ${chalk3.gray("Definition:")} ${instance.definitionId || "N/A"}`);
1279
+ console.log(` ${chalk3.gray("Business Key:")} ${instance.businessKey || "N/A"}`);
1280
+ console.log(
1281
+ ` ${chalk3.gray("Status:")} ${instance.ended ? "Ended" : instance.suspended ? "Suspended" : "Active"}`
1282
+ );
1014
1283
  console.log();
1015
1284
  }
1016
1285
  }
1017
1286
  });
1018
1287
  } catch (error) {
1019
- spinner.fail("Failed to fetch tasks");
1020
- throw error;
1288
+ exitWithCommandError2(spinner, "Failed to fetch process instances", error);
1021
1289
  }
1022
1290
  }
1023
- async function completeTask(client, options) {
1024
- const spinner = createSpinner(`Completing task: ${options.id}...`, options.format);
1291
+ async function getProcessInstance(client, options) {
1292
+ const spinner = createSpinner("Fetching process instance...", options.format);
1025
1293
  try {
1026
1294
  const bpmClient = client.bpm;
1027
- const variables = options.variables ? JSON.parse(options.variables) : {};
1028
- const result = await bpmClient.completeTask(options.id, { variables });
1295
+ const result = await bpmClient.getProcessInstance(options.id);
1029
1296
  if (result.error) {
1030
- spinner.fail("Failed to complete task");
1031
- console.error(chalk7.red(result.error.message));
1297
+ spinner.fail("Failed to fetch process instance");
1298
+ console.error(chalk3.red(result.error.message));
1032
1299
  process.exit(1);
1033
1300
  }
1034
- spinner.succeed("Task completed");
1301
+ spinner.succeed("Process instance retrieved");
1302
+ renderOutput(result.data, {
1303
+ format: options.format,
1304
+ pretty: () => {
1305
+ console.log(chalk3.blue("\n\u{1F4CA} Process Instance\n"));
1306
+ console.log(JSON.stringify(result.data, null, 2));
1307
+ }
1308
+ });
1309
+ } catch (error) {
1310
+ exitWithCommandError2(spinner, "Failed to fetch process instance", error);
1311
+ }
1312
+ }
1313
+ async function getActivityInstanceTree(client, options) {
1314
+ const spinner = createSpinner("Fetching activity instance tree...", options.format);
1315
+ try {
1316
+ const bpmClient = client.bpm;
1317
+ const result = await bpmClient.getActivityInstanceTree(options.id);
1318
+ if (result.error) {
1319
+ spinner.fail("Failed to fetch activity instance tree");
1320
+ console.error(chalk3.red(result.error.message));
1321
+ process.exit(1);
1322
+ }
1323
+ spinner.succeed("Activity instance tree retrieved");
1324
+ renderOutput(result.data, {
1325
+ format: options.format,
1326
+ pretty: () => {
1327
+ console.log(chalk3.blue("\n\u{1F333} Activity Instance Tree\n"));
1328
+ console.log(JSON.stringify(result.data, null, 2));
1329
+ }
1330
+ });
1331
+ } catch (error) {
1332
+ exitWithCommandError2(spinner, "Failed to fetch activity instance tree", error);
1333
+ }
1334
+ }
1335
+ async function getActiveActivities(client, options) {
1336
+ const spinner = createSpinner("Fetching active activities...", options.format);
1337
+ try {
1338
+ const bpmClient = client.bpm;
1339
+ const result = await bpmClient.getActiveActivities(options.id);
1340
+ if (result.error) {
1341
+ spinner.fail("Failed to fetch active activities");
1342
+ console.error(chalk3.red(result.error.message));
1343
+ process.exit(1);
1344
+ }
1345
+ const activities = Array.isArray(result.data) ? result.data : [];
1346
+ spinner.succeed(`Found ${activities.length} active activities`);
1347
+ renderOutput(result.data, {
1348
+ format: options.format,
1349
+ pretty: () => {
1350
+ console.log(chalk3.blue("\n\u26A1 Active Activities\n"));
1351
+ console.log(JSON.stringify(result.data, null, 2));
1352
+ }
1353
+ });
1354
+ } catch (error) {
1355
+ exitWithCommandError2(spinner, "Failed to fetch active activities", error);
1356
+ }
1357
+ }
1358
+ async function getRuntimeVariables(client, options) {
1359
+ const spinner = createSpinner("Fetching runtime variables...", options.format);
1360
+ try {
1361
+ const bpmClient = client.bpm;
1362
+ const result = await bpmClient.getRuntimeVariables(options.id);
1363
+ if (result.error) {
1364
+ spinner.fail("Failed to fetch runtime variables");
1365
+ console.error(chalk3.red(result.error.message));
1366
+ process.exit(1);
1367
+ }
1368
+ spinner.succeed("Runtime variables retrieved");
1369
+ renderOutput(result.data, {
1370
+ format: options.format,
1371
+ pretty: () => {
1372
+ console.log(chalk3.blue("\n\u{1F9EE} Runtime Variables\n"));
1373
+ console.log(JSON.stringify(result.data, null, 2));
1374
+ }
1375
+ });
1376
+ } catch (error) {
1377
+ exitWithCommandError2(spinner, "Failed to fetch runtime variables", error);
1378
+ }
1379
+ }
1380
+ async function getProcessVariables(client, options) {
1381
+ const spinner = createSpinner("Fetching process variables...", options.format);
1382
+ try {
1383
+ const bpmClient = client.bpm;
1384
+ const result = await bpmClient.getProcessVariables({
1385
+ processInstanceId: options.id,
1386
+ variableName: options.name
1387
+ });
1388
+ if (result.error) {
1389
+ spinner.fail("Failed to fetch process variables");
1390
+ console.error(chalk3.red(result.error.message));
1391
+ process.exit(1);
1392
+ }
1393
+ spinner.succeed(`Found ${result.data?.length || 0} variables`);
1394
+ renderOutput(result.data || [], {
1395
+ format: options.format,
1396
+ pretty: () => {
1397
+ console.log(chalk3.blue("\n\u{1F9FE} Process Variables\n"));
1398
+ console.log(JSON.stringify(result.data || [], null, 2));
1399
+ }
1400
+ });
1401
+ } catch (error) {
1402
+ exitWithCommandError2(spinner, "Failed to fetch process variables", error);
1403
+ }
1404
+ }
1405
+ async function deleteProcessInstance(client, options) {
1406
+ const spinner = createSpinner(`Deleting process instance: ${options.id}...`, options.format);
1407
+ try {
1408
+ const bpmClient = client.bpm;
1409
+ const result = await bpmClient.deleteProcessInstance(options.id, {
1410
+ skipCustomListeners: options.skipCustomListeners
1411
+ });
1412
+ if (result.error) {
1413
+ spinner.fail("Failed to delete process instance");
1414
+ console.error(chalk3.red(result.error.message));
1415
+ process.exit(1);
1416
+ }
1417
+ spinner.succeed("Process instance deleted");
1035
1418
  renderOutput(
1036
1419
  {
1037
1420
  id: options.id,
1038
- completed: true
1421
+ deleted: true,
1422
+ skipCustomListeners: !!options.skipCustomListeners
1039
1423
  },
1040
1424
  {
1041
1425
  format: options.format,
1042
1426
  pretty: () => {
1043
- console.log(chalk7.green(`Completed task: ${options.id}`));
1427
+ console.log(chalk3.green(`Deleted process instance: ${options.id}`));
1044
1428
  }
1045
1429
  }
1046
1430
  );
1047
1431
  } catch (error) {
1048
- spinner.fail("Failed to complete task");
1049
- throw error;
1432
+ exitWithCommandError2(spinner, "Failed to delete process instance", error);
1433
+ }
1434
+ }
1435
+ async function suspendProcessInstance(client, options) {
1436
+ const spinner = createSpinner(`Suspending process instance: ${options.id}...`, options.format);
1437
+ try {
1438
+ const bpmClient = client.bpm;
1439
+ const result = await bpmClient.suspendProcessInstance(options.id);
1440
+ if (result.error) {
1441
+ spinner.fail("Failed to suspend process instance");
1442
+ console.error(chalk3.red(result.error.message));
1443
+ process.exit(1);
1444
+ }
1445
+ spinner.succeed("Process instance suspended");
1446
+ renderOutput(
1447
+ {
1448
+ id: options.id,
1449
+ suspended: true
1450
+ },
1451
+ {
1452
+ format: options.format,
1453
+ pretty: () => {
1454
+ console.log(chalk3.green(`Suspended process instance: ${options.id}`));
1455
+ }
1456
+ }
1457
+ );
1458
+ } catch (error) {
1459
+ exitWithCommandError2(spinner, "Failed to suspend process instance", error);
1460
+ }
1461
+ }
1462
+ async function activateProcessInstance(client, options) {
1463
+ const spinner = createSpinner(`Activating process instance: ${options.id}...`, options.format);
1464
+ try {
1465
+ const bpmClient = client.bpm;
1466
+ const result = await bpmClient.activateProcessInstance(options.id);
1467
+ if (result.error) {
1468
+ spinner.fail("Failed to activate process instance");
1469
+ console.error(chalk3.red(result.error.message));
1470
+ process.exit(1);
1471
+ }
1472
+ spinner.succeed("Process instance activated");
1473
+ renderOutput(
1474
+ {
1475
+ id: options.id,
1476
+ activated: true
1477
+ },
1478
+ {
1479
+ format: options.format,
1480
+ pretty: () => {
1481
+ console.log(chalk3.green(`Activated process instance: ${options.id}`));
1482
+ }
1483
+ }
1484
+ );
1485
+ } catch (error) {
1486
+ exitWithCommandError2(spinner, "Failed to activate process instance", error);
1487
+ }
1488
+ }
1489
+ async function modifyProcessInstance(client, options) {
1490
+ const spinner = createSpinner(`Modifying process instance: ${options.id}...`, options.format);
1491
+ try {
1492
+ const bpmClient = client.bpm;
1493
+ const modification = await loadJsonObjectInput2(
1494
+ options.modification,
1495
+ "process modification",
1496
+ "Enter process modification JSON:"
1497
+ );
1498
+ const result = await bpmClient.modifyProcessInstance(options.id, modification);
1499
+ if (result.error) {
1500
+ spinner.fail("Failed to modify process instance");
1501
+ console.error(chalk3.red(result.error.message));
1502
+ process.exit(1);
1503
+ }
1504
+ spinner.succeed("Process instance modified");
1505
+ renderOutput(
1506
+ {
1507
+ id: options.id,
1508
+ modified: true,
1509
+ modification
1510
+ },
1511
+ {
1512
+ format: options.format,
1513
+ pretty: () => {
1514
+ console.log(chalk3.green(`Modified process instance: ${options.id}`));
1515
+ }
1516
+ }
1517
+ );
1518
+ } catch (error) {
1519
+ exitWithCommandError2(spinner, "Failed to modify process instance", error);
1520
+ }
1521
+ }
1522
+ async function listTasks(client, options) {
1523
+ const spinner = createSpinner("Fetching tasks...", options.format);
1524
+ try {
1525
+ const bpmClient = client.bpm;
1526
+ const params = buildTaskQueryParams(options);
1527
+ const result = await bpmClient.getTasks(params);
1528
+ if (result.error) {
1529
+ spinner.fail("Failed to fetch tasks");
1530
+ console.error(chalk3.red(result.error.message));
1531
+ process.exit(1);
1532
+ }
1533
+ spinner.succeed(`Found ${result.data?.length || 0} tasks`);
1534
+ const tasks = result.data || [];
1535
+ renderOutput(tasks, {
1536
+ format: options.format,
1537
+ pretty: () => {
1538
+ console.log(chalk3.blue("\n\u{1F4DD} Tasks\n"));
1539
+ for (const task of tasks) {
1540
+ console.log(` ${chalk3.green("\u2022")} ${chalk3.bold(task.name || task.id)}`);
1541
+ console.log(` ${chalk3.gray("ID:")} ${task.id}`);
1542
+ console.log(` ${chalk3.gray("Assignee:")} ${task.assignee || "Unassigned"}`);
1543
+ console.log(` ${chalk3.gray("Process Instance:")} ${task.processInstanceId || "N/A"}`);
1544
+ console.log(` ${chalk3.gray("Created:")} ${task.created || "N/A"}`);
1545
+ console.log();
1546
+ }
1547
+ }
1548
+ });
1549
+ } catch (error) {
1550
+ exitWithCommandError2(spinner, "Failed to fetch tasks", error);
1551
+ }
1552
+ }
1553
+ async function getTask(client, options) {
1554
+ const spinner = createSpinner(`Fetching task: ${options.id}...`, options.format);
1555
+ try {
1556
+ const bpmClient = client.bpm;
1557
+ const result = await bpmClient.getTask(options.id);
1558
+ if (result.error) {
1559
+ spinner.fail("Failed to fetch task");
1560
+ console.error(chalk3.red(result.error.message));
1561
+ process.exit(1);
1562
+ }
1563
+ spinner.succeed("Task retrieved");
1564
+ renderOutput(result.data, {
1565
+ format: options.format,
1566
+ pretty: () => {
1567
+ console.log(chalk3.blue("\n\u{1F4DD} Task\n"));
1568
+ console.log(JSON.stringify(result.data, null, 2));
1569
+ }
1570
+ });
1571
+ } catch (error) {
1572
+ exitWithCommandError2(spinner, "Failed to fetch task", error);
1573
+ }
1574
+ }
1575
+ async function getTaskCount(client, options) {
1576
+ const spinner = createSpinner("Fetching task count...", options.format);
1577
+ try {
1578
+ const bpmClient = client.bpm;
1579
+ const params = buildTaskQueryParams(options);
1580
+ const result = await bpmClient.getTaskCount(params);
1581
+ if (result.error) {
1582
+ spinner.fail("Failed to fetch task count");
1583
+ console.error(chalk3.red(result.error.message));
1584
+ process.exit(1);
1585
+ }
1586
+ spinner.succeed("Task count retrieved");
1587
+ renderOutput(result.data, {
1588
+ format: options.format,
1589
+ pretty: () => {
1590
+ console.log(chalk3.green(`Task count: ${result.data?.count ?? 0}`));
1591
+ }
1592
+ });
1593
+ } catch (error) {
1594
+ exitWithCommandError2(spinner, "Failed to fetch task count", error);
1595
+ }
1596
+ }
1597
+ async function completeTask(client, options) {
1598
+ const spinner = createSpinner(`Completing task: ${options.id}...`, options.format);
1599
+ try {
1600
+ const bpmClient = client.bpm;
1601
+ const variables = loadOptionalJsonObjectInput2(options.variables, "task variables");
1602
+ const result = await bpmClient.completeTask(options.id, variables);
1603
+ if (result.error) {
1604
+ spinner.fail("Failed to complete task");
1605
+ console.error(chalk3.red(result.error.message));
1606
+ process.exit(1);
1607
+ }
1608
+ spinner.succeed("Task completed");
1609
+ renderOutput(
1610
+ {
1611
+ id: options.id,
1612
+ completed: true
1613
+ },
1614
+ {
1615
+ format: options.format,
1616
+ pretty: () => {
1617
+ console.log(chalk3.green(`Completed task: ${options.id}`));
1618
+ }
1619
+ }
1620
+ );
1621
+ } catch (error) {
1622
+ exitWithCommandError2(spinner, "Failed to complete task", error);
1623
+ }
1624
+ }
1625
+ async function delegateTask(client, options) {
1626
+ const spinner = createSpinner(`Delegating task: ${options.id}...`, options.format);
1627
+ try {
1628
+ const bpmClient = client.bpm;
1629
+ const result = await bpmClient.delegateTask(options.id, options.userId);
1630
+ if (result.error) {
1631
+ spinner.fail("Failed to delegate task");
1632
+ console.error(chalk3.red(result.error.message));
1633
+ process.exit(1);
1634
+ }
1635
+ spinner.succeed("Task delegated");
1636
+ renderOutput(
1637
+ {
1638
+ id: options.id,
1639
+ userId: options.userId,
1640
+ delegated: true
1641
+ },
1642
+ {
1643
+ format: options.format,
1644
+ pretty: () => {
1645
+ console.log(chalk3.green(`Delegated task ${options.id} to ${options.userId}`));
1646
+ }
1647
+ }
1648
+ );
1649
+ } catch (error) {
1650
+ exitWithCommandError2(spinner, "Failed to delegate task", error);
1651
+ }
1652
+ }
1653
+ async function getTaskForm(client, options) {
1654
+ const spinner = createSpinner("Fetching task form...", options.format);
1655
+ try {
1656
+ const bpmClient = client.bpm;
1657
+ const result = await bpmClient.getTaskForm(options.id);
1658
+ if (result.error) {
1659
+ spinner.fail("Failed to fetch task form");
1660
+ console.error(chalk3.red(result.error.message));
1661
+ process.exit(1);
1662
+ }
1663
+ spinner.succeed("Task form retrieved");
1664
+ renderOutput(result.data, {
1665
+ format: options.format,
1666
+ pretty: () => {
1667
+ console.log(chalk3.blue("\n\u{1F9E9} Task Form\n"));
1668
+ console.log(JSON.stringify(result.data, null, 2));
1669
+ }
1670
+ });
1671
+ } catch (error) {
1672
+ exitWithCommandError2(spinner, "Failed to fetch task form", error);
1673
+ }
1674
+ }
1675
+ async function getTaskFormSchema(client, options) {
1676
+ const spinner = createSpinner("Fetching task form schema...", options.format);
1677
+ try {
1678
+ const bpmClient = client.bpm;
1679
+ const result = await bpmClient.getTaskFormSchema(
1680
+ options.id,
1681
+ options.redirect ? { redirect: options.redirect } : void 0
1682
+ );
1683
+ if (result.error) {
1684
+ const diagnostic = await diagnoseTaskFormSchemaError(
1685
+ bpmClient,
1686
+ options.id,
1687
+ extractClientErrorMessage(result.error)
1688
+ );
1689
+ exitWithClientError(spinner, "Failed to fetch task form schema", result.error, diagnostic);
1690
+ }
1691
+ spinner.succeed("Task form schema retrieved");
1692
+ renderOutput(result.data, {
1693
+ format: options.format,
1694
+ pretty: () => {
1695
+ console.log(chalk3.blue("\n\u{1F9E9} Task Form Schema\n"));
1696
+ console.log(JSON.stringify(result.data, null, 2));
1697
+ }
1698
+ });
1699
+ } catch (error) {
1700
+ exitWithCommandError2(spinner, "Failed to fetch task form schema", error);
1701
+ }
1702
+ }
1703
+ async function getTaskFormVariables(client, options) {
1704
+ const spinner = createSpinner("Fetching task form variables...", options.format);
1705
+ try {
1706
+ const bpmClient = client.bpm;
1707
+ const result = await bpmClient.getTaskFormVariables(options.id);
1708
+ if (result.error) {
1709
+ spinner.fail("Failed to fetch task form variables");
1710
+ console.error(chalk3.red(result.error.message));
1711
+ process.exit(1);
1712
+ }
1713
+ spinner.succeed("Task form variables retrieved");
1714
+ renderOutput(result.data, {
1715
+ format: options.format,
1716
+ pretty: () => {
1717
+ console.log(chalk3.blue("\n\u{1F9EE} Task Form Variables\n"));
1718
+ console.log(JSON.stringify(result.data, null, 2));
1719
+ }
1720
+ });
1721
+ } catch (error) {
1722
+ exitWithCommandError2(spinner, "Failed to fetch task form variables", error);
1723
+ }
1724
+ }
1725
+ async function getTaskRenderedForm(client, options) {
1726
+ const spinner = createSpinner("Fetching rendered task form...", options.format);
1727
+ try {
1728
+ const bpmClient = client.bpm;
1729
+ const result = await bpmClient.getTaskRenderedForm(options.id);
1730
+ if (result.error) {
1731
+ spinner.fail("Failed to fetch rendered task form");
1732
+ console.error(chalk3.red(result.error.message));
1733
+ process.exit(1);
1734
+ }
1735
+ spinner.succeed("Rendered task form retrieved");
1736
+ renderOutput(result.data, {
1737
+ format: options.format,
1738
+ pretty: () => {
1739
+ console.log(chalk3.blue("\n\u{1F9FE} Rendered Task Form\n"));
1740
+ console.log(result.data || "");
1741
+ }
1742
+ });
1743
+ } catch (error) {
1744
+ exitWithCommandError2(spinner, "Failed to fetch rendered task form", error);
1745
+ }
1746
+ }
1747
+ async function getTaskDeployedForm(client, options) {
1748
+ const spinner = createSpinner("Fetching deployed task form...", options.format);
1749
+ try {
1750
+ const bpmClient = client.bpm;
1751
+ const result = await bpmClient.getTaskDeployedForm(options.id);
1752
+ if (result.error) {
1753
+ spinner.fail("Failed to fetch deployed task form");
1754
+ console.error(chalk3.red(result.error.message));
1755
+ process.exit(1);
1756
+ }
1757
+ spinner.succeed("Deployed task form retrieved");
1758
+ renderOutput(result.data, {
1759
+ format: options.format,
1760
+ pretty: () => {
1761
+ console.log(chalk3.blue("\n\u{1F9FE} Deployed Task Form\n"));
1762
+ console.log(JSON.stringify(result.data, null, 2));
1763
+ }
1764
+ });
1765
+ } catch (error) {
1766
+ exitWithCommandError2(spinner, "Failed to fetch deployed task form", error);
1767
+ }
1768
+ }
1769
+ async function getStartFormInfo(client, options) {
1770
+ const spinner = createSpinner("Fetching start form info...", options.format);
1771
+ try {
1772
+ const bpmClient = client.bpm;
1773
+ const result = await bpmClient.getStartFormInfo(options.key);
1774
+ if (result.error) {
1775
+ const diagnostic = await diagnoseStartFormError(
1776
+ bpmClient,
1777
+ options.key,
1778
+ extractClientErrorMessage(result.error)
1779
+ );
1780
+ exitWithClientError(spinner, "Failed to fetch start form info", result.error, diagnostic);
1781
+ }
1782
+ spinner.succeed("Start form info retrieved");
1783
+ renderOutput(result.data, {
1784
+ format: options.format,
1785
+ pretty: () => {
1786
+ console.log(chalk3.blue("\n\u{1F680} Start Form Info\n"));
1787
+ console.log(JSON.stringify(result.data, null, 2));
1788
+ }
1789
+ });
1790
+ } catch (error) {
1791
+ exitWithCommandError2(spinner, "Failed to fetch start form info", error);
1792
+ }
1793
+ }
1794
+ async function getStartFormVariables(client, options) {
1795
+ const spinner = createSpinner("Fetching start form variables...", options.format);
1796
+ try {
1797
+ const bpmClient = client.bpm;
1798
+ const result = await bpmClient.getStartFormVariables(options.key);
1799
+ if (result.error) {
1800
+ const diagnostic = await diagnoseStartFormError(
1801
+ bpmClient,
1802
+ options.key,
1803
+ extractClientErrorMessage(result.error)
1804
+ );
1805
+ exitWithClientError(spinner, "Failed to fetch start form variables", result.error, diagnostic);
1806
+ }
1807
+ spinner.succeed("Start form variables retrieved");
1808
+ renderOutput(result.data, {
1809
+ format: options.format,
1810
+ pretty: () => {
1811
+ console.log(chalk3.blue("\n\u{1F680} Start Form Variables\n"));
1812
+ console.log(JSON.stringify(result.data, null, 2));
1813
+ }
1814
+ });
1815
+ } catch (error) {
1816
+ exitWithCommandError2(spinner, "Failed to fetch start form variables", error);
1817
+ }
1818
+ }
1819
+ async function getDeployedStartForm(client, options) {
1820
+ const spinner = createSpinner("Fetching deployed start form...", options.format);
1821
+ try {
1822
+ const bpmClient = client.bpm;
1823
+ const result = await bpmClient.getDeployedStartForm(options.key);
1824
+ if (result.error) {
1825
+ const diagnostic = await diagnoseStartFormError(
1826
+ bpmClient,
1827
+ options.key,
1828
+ extractClientErrorMessage(result.error)
1829
+ );
1830
+ exitWithClientError(spinner, "Failed to fetch deployed start form", result.error, diagnostic);
1831
+ }
1832
+ spinner.succeed("Deployed start form retrieved");
1833
+ renderOutput(result.data, {
1834
+ format: options.format,
1835
+ pretty: () => {
1836
+ console.log(chalk3.blue("\n\u{1F680} Deployed Start Form\n"));
1837
+ console.log(JSON.stringify(result.data, null, 2));
1838
+ }
1839
+ });
1840
+ } catch (error) {
1841
+ exitWithCommandError2(spinner, "Failed to fetch deployed start form", error);
1842
+ }
1843
+ }
1844
+ async function listHistoryTasks(client, options = {}) {
1845
+ const spinner = createSpinner("Fetching history tasks...", options.format);
1846
+ try {
1847
+ const bpmClient = client.bpm;
1848
+ const params = buildHistoryTaskQueryParams(options);
1849
+ const result = await bpmClient.getHistoryTasks(params);
1850
+ if (result.error) {
1851
+ spinner.fail("Failed to fetch history tasks");
1852
+ console.error(chalk3.red(result.error.message));
1853
+ process.exit(1);
1854
+ }
1855
+ const tasks = result.data || [];
1856
+ spinner.succeed(`Found ${tasks.length} history tasks`);
1857
+ renderOutput(tasks, {
1858
+ format: options.format,
1859
+ pretty: () => {
1860
+ console.log(chalk3.blue("\n\u{1F4DA} History Tasks\n"));
1861
+ console.log(JSON.stringify(tasks, null, 2));
1862
+ }
1863
+ });
1864
+ } catch (error) {
1865
+ exitWithCommandError2(spinner, "Failed to fetch history tasks", error);
1866
+ }
1867
+ }
1868
+ async function getHistoryTaskCount(client, options = {}) {
1869
+ const spinner = createSpinner("Fetching history task count...", options.format);
1870
+ try {
1871
+ const bpmClient = client.bpm;
1872
+ const params = buildHistoryTaskQueryParams(options);
1873
+ const result = await bpmClient.getHistoryTaskCount(params);
1874
+ if (result.error) {
1875
+ spinner.fail("Failed to fetch history task count");
1876
+ console.error(chalk3.red(result.error.message));
1877
+ process.exit(1);
1878
+ }
1879
+ spinner.succeed("History task count retrieved");
1880
+ renderOutput(result.data, {
1881
+ format: options.format,
1882
+ pretty: () => {
1883
+ console.log(chalk3.green(`History task count: ${result.data?.count ?? 0}`));
1884
+ }
1885
+ });
1886
+ } catch (error) {
1887
+ exitWithCommandError2(spinner, "Failed to fetch history task count", error);
1888
+ }
1889
+ }
1890
+ async function listHistoryProcessInstances(client, options = {}) {
1891
+ const spinner = createSpinner("Fetching history process instances...", options.format);
1892
+ try {
1893
+ const bpmClient = client.bpm;
1894
+ const params = buildHistoryProcessInstanceQueryParams(options);
1895
+ const result = await bpmClient.getHistoryProcessInstances(params);
1896
+ if (result.error) {
1897
+ spinner.fail("Failed to fetch history process instances");
1898
+ console.error(chalk3.red(result.error.message));
1899
+ process.exit(1);
1900
+ }
1901
+ const instances = result.data || [];
1902
+ spinner.succeed(`Found ${instances.length} history process instances`);
1903
+ renderOutput(instances, {
1904
+ format: options.format,
1905
+ pretty: () => {
1906
+ console.log(chalk3.blue("\n\u{1F4DA} History Process Instances\n"));
1907
+ console.log(JSON.stringify(instances, null, 2));
1908
+ }
1909
+ });
1910
+ } catch (error) {
1911
+ exitWithCommandError2(spinner, "Failed to fetch history process instances", error);
1912
+ }
1913
+ }
1914
+ async function getHistoryProcessInstanceCount(client, options = {}) {
1915
+ const spinner = createSpinner("Fetching history process instance count...", options.format);
1916
+ try {
1917
+ const bpmClient = client.bpm;
1918
+ const params = buildHistoryProcessInstanceQueryParams(options);
1919
+ const result = await bpmClient.getHistoryProcessInstanceCount(params);
1920
+ if (result.error) {
1921
+ spinner.fail("Failed to fetch history process instance count");
1922
+ console.error(chalk3.red(result.error.message));
1923
+ process.exit(1);
1924
+ }
1925
+ spinner.succeed("History process instance count retrieved");
1926
+ renderOutput(result.data, {
1927
+ format: options.format,
1928
+ pretty: () => {
1929
+ console.log(chalk3.green(`History process instance count: ${result.data?.count ?? 0}`));
1930
+ }
1931
+ });
1932
+ } catch (error) {
1933
+ exitWithCommandError2(spinner, "Failed to fetch history process instance count", error);
1934
+ }
1935
+ }
1936
+ async function getHistoryProcessInstance(client, options) {
1937
+ const spinner = createSpinner("Fetching history process instance...", options.format);
1938
+ try {
1939
+ const bpmClient = client.bpm;
1940
+ const result = await bpmClient.getHistoryProcessInstance(options.id);
1941
+ if (result.error) {
1942
+ spinner.fail("Failed to fetch history process instance");
1943
+ console.error(chalk3.red(result.error.message));
1944
+ process.exit(1);
1945
+ }
1946
+ spinner.succeed("History process instance retrieved");
1947
+ renderOutput(result.data, {
1948
+ format: options.format,
1949
+ pretty: () => {
1950
+ console.log(chalk3.blue("\n\u{1F4DA} History Process Instance\n"));
1951
+ console.log(JSON.stringify(result.data, null, 2));
1952
+ }
1953
+ });
1954
+ } catch (error) {
1955
+ exitWithCommandError2(spinner, "Failed to fetch history process instance", error);
1956
+ }
1957
+ }
1958
+ async function listHistoryActivityInstances(client, options = {}) {
1959
+ const spinner = createSpinner("Fetching history activity instances...", options.format);
1960
+ try {
1961
+ const bpmClient = client.bpm;
1962
+ const params = buildHistoryActivityQueryParams(options);
1963
+ const result = await bpmClient.getHistoryActivityInstances(params);
1964
+ if (result.error) {
1965
+ spinner.fail("Failed to fetch history activity instances");
1966
+ console.error(chalk3.red(result.error.message));
1967
+ process.exit(1);
1968
+ }
1969
+ const activities = result.data || [];
1970
+ spinner.succeed(`Found ${activities.length} history activity instances`);
1971
+ renderOutput(activities, {
1972
+ format: options.format,
1973
+ pretty: () => {
1974
+ console.log(chalk3.blue("\n\u{1F4DA} History Activity Instances\n"));
1975
+ console.log(JSON.stringify(activities, null, 2));
1976
+ }
1977
+ });
1978
+ } catch (error) {
1979
+ exitWithCommandError2(spinner, "Failed to fetch history activity instances", error);
1980
+ }
1981
+ }
1982
+ async function listHistoryVariableInstances(client, options = {}) {
1983
+ const spinner = createSpinner("Fetching history variable instances...", options.format);
1984
+ try {
1985
+ const bpmClient = client.bpm;
1986
+ const params = buildHistoryVariableQueryParams(options);
1987
+ const result = await bpmClient.getHistoryVariableInstances(params);
1988
+ if (result.error) {
1989
+ spinner.fail("Failed to fetch history variable instances");
1990
+ console.error(chalk3.red(result.error.message));
1991
+ process.exit(1);
1992
+ }
1993
+ const variables = result.data || [];
1994
+ spinner.succeed(`Found ${variables.length} history variable instances`);
1995
+ renderOutput(variables, {
1996
+ format: options.format,
1997
+ pretty: () => {
1998
+ console.log(chalk3.blue("\n\u{1F4DA} History Variable Instances\n"));
1999
+ console.log(JSON.stringify(variables, null, 2));
2000
+ }
2001
+ });
2002
+ } catch (error) {
2003
+ exitWithCommandError2(spinner, "Failed to fetch history variable instances", error);
2004
+ }
2005
+ }
2006
+ async function listUserOperationLogs(client, options = {}) {
2007
+ const spinner = createSpinner("Fetching user operation logs...", options.format);
2008
+ try {
2009
+ const bpmClient = client.bpm;
2010
+ const params = buildUserOperationLogQueryParams(options);
2011
+ const result = await bpmClient.getUserOperationLogs(params);
2012
+ if (result.error) {
2013
+ spinner.fail("Failed to fetch user operation logs");
2014
+ console.error(chalk3.red(result.error.message));
2015
+ process.exit(1);
2016
+ }
2017
+ const logs = result.data || [];
2018
+ spinner.succeed(`Found ${logs.length} user operation logs`);
2019
+ renderOutput(logs, {
2020
+ format: options.format,
2021
+ pretty: () => {
2022
+ console.log(chalk3.blue("\n\u{1F4DA} User Operation Logs\n"));
2023
+ console.log(JSON.stringify(logs, null, 2));
2024
+ }
2025
+ });
2026
+ } catch (error) {
2027
+ exitWithCommandError2(spinner, "Failed to fetch user operation logs", error);
2028
+ }
2029
+ }
2030
+ async function deleteHistoryProcessInstance(client, options) {
2031
+ const spinner = createSpinner(`Deleting history process instance: ${options.id}...`, options.format);
2032
+ try {
2033
+ const bpmClient = client.bpm;
2034
+ const result = await bpmClient.deleteHistoryProcessInstance(options.id);
2035
+ if (result.error) {
2036
+ spinner.fail("Failed to delete history process instance");
2037
+ console.error(chalk3.red(result.error.message));
2038
+ process.exit(1);
2039
+ }
2040
+ spinner.succeed("History process instance deleted");
2041
+ renderOutput(
2042
+ {
2043
+ id: options.id,
2044
+ deleted: true
2045
+ },
2046
+ {
2047
+ format: options.format,
2048
+ pretty: () => {
2049
+ console.log(chalk3.green(`Deleted history process instance: ${options.id}`));
2050
+ }
2051
+ }
2052
+ );
2053
+ } catch (error) {
2054
+ exitWithCommandError2(spinner, "Failed to delete history process instance", error);
2055
+ }
2056
+ }
2057
+ async function listRoles(client, options = {}) {
2058
+ const spinner = createSpinner("Fetching roles...", options.format);
2059
+ try {
2060
+ const bpmClient = client.bpm;
2061
+ const result = await bpmClient.getRoles();
2062
+ if (result.error) {
2063
+ spinner.fail("Failed to fetch roles");
2064
+ console.error(chalk3.red(result.error.message));
2065
+ process.exit(1);
2066
+ }
2067
+ const roles = result.data || [];
2068
+ spinner.succeed(`Found ${roles.length} roles`);
2069
+ renderOutput(roles, {
2070
+ format: options.format,
2071
+ pretty: () => {
2072
+ console.log(chalk3.blue("\n\u{1F465} Roles\n"));
2073
+ console.log(JSON.stringify(roles, null, 2));
2074
+ }
2075
+ });
2076
+ } catch (error) {
2077
+ exitWithCommandError2(spinner, "Failed to fetch roles", error);
2078
+ }
2079
+ }
2080
+ async function getUserRoles(client, options) {
2081
+ const spinner = createSpinner(`Fetching roles for user: ${options.userId}...`, options.format);
2082
+ try {
2083
+ const bpmClient = client.bpm;
2084
+ const result = await bpmClient.getUserRoles(options.userId);
2085
+ if (result.error) {
2086
+ spinner.fail("Failed to fetch user roles");
2087
+ console.error(chalk3.red(result.error.message));
2088
+ process.exit(1);
2089
+ }
2090
+ const roles = result.data || [];
2091
+ spinner.succeed(`Found ${roles.length} roles for user ${options.userId}`);
2092
+ renderOutput(roles, {
2093
+ format: options.format,
2094
+ pretty: () => {
2095
+ console.log(chalk3.blue(`
2096
+ \u{1F464} User Roles: ${options.userId}
2097
+ `));
2098
+ console.log(JSON.stringify(roles, null, 2));
2099
+ }
2100
+ });
2101
+ } catch (error) {
2102
+ exitWithCommandError2(spinner, "Failed to fetch user roles", error);
2103
+ }
2104
+ }
2105
+ function resolveInputSource3(input) {
2106
+ if (!input.startsWith("@")) {
2107
+ return input;
2108
+ }
2109
+ const filePath = input.slice(1);
2110
+ if (!filePath) {
2111
+ throw new Error("File path is required after '@'.");
2112
+ }
2113
+ return readFileSync(filePath, "utf8");
2114
+ }
2115
+ function parseJsonInput3(input, label) {
2116
+ const source = resolveInputSource3(input).trim();
2117
+ if (!source) {
2118
+ throw new Error(`${label} is required.`);
2119
+ }
2120
+ try {
2121
+ return JSON.parse(source);
2122
+ } catch (error) {
2123
+ const reason = error instanceof Error ? error.message : String(error);
2124
+ throw new Error(`Invalid ${label}: ${reason}`);
2125
+ }
2126
+ }
2127
+ function isPlainObject4(value) {
2128
+ return typeof value === "object" && value !== null && !Array.isArray(value);
2129
+ }
2130
+ function loadOptionalJsonObjectInput3(input, label) {
2131
+ if (!input) {
2132
+ return {};
2133
+ }
2134
+ const value = parseJsonInput3(input, label);
2135
+ if (!isPlainObject4(value)) {
2136
+ throw new Error(`${label} must be a JSON object.`);
2137
+ }
2138
+ return value;
2139
+ }
2140
+ function loadOptionalJsonArrayInput(input, label) {
2141
+ if (!input) {
2142
+ return void 0;
2143
+ }
2144
+ const value = parseJsonInput3(input, label);
2145
+ if (!Array.isArray(value)) {
2146
+ throw new Error(`${label} must be a JSON array.`);
1050
2147
  }
2148
+ return value;
1051
2149
  }
1052
- async function listWorkflows(client, options = {}) {
1053
- const spinner = createSpinner("Fetching workflows...", options.format);
1054
- try {
1055
- const workflowClient = client.workflow;
1056
- const result = await workflowClient.listWorkflows();
1057
- if (result.error) {
1058
- spinner.fail("Failed to fetch workflows");
1059
- console.error(chalk7.red(result.error.message));
1060
- process.exit(1);
2150
+ function exitWithCommandError3(spinner, failureMessage, error) {
2151
+ spinner.fail(failureMessage);
2152
+ const details = error instanceof Error ? error.message : String(error);
2153
+ if (details) {
2154
+ console.error(chalk3.red(details));
2155
+ }
2156
+ process.exit(1);
2157
+ }
2158
+ function buildWorkflowRunRequest(options) {
2159
+ const request = loadOptionalJsonObjectInput3(options.request, "workflow request");
2160
+ if (options.input) {
2161
+ const inputs = parseJsonInput3(options.input, "workflow input");
2162
+ if (!isPlainObject4(inputs)) {
2163
+ throw new Error("workflow input must be a JSON object.");
1061
2164
  }
1062
- spinner.succeed(`Found ${result.data?.length || 0} workflows`);
1063
- const workflows = result.data || [];
1064
- renderOutput(workflows, {
1065
- format: options.format,
1066
- pretty: () => {
1067
- console.log(chalk7.blue("\n\u26A1 Workflows\n"));
1068
- for (const workflow of workflows) {
1069
- console.log(` ${chalk7.green("\u2022")} ${chalk7.bold(workflow.code || workflow.id)}`);
1070
- console.log(` ${chalk7.gray("Name:")} ${workflow.name || "N/A"}`);
1071
- console.log(` ${chalk7.gray("Description:")} ${workflow.description || "N/A"}`);
1072
- console.log(` ${chalk7.gray("Status:")} ${workflow.status || "N/A"}`);
1073
- console.log();
1074
- }
1075
- }
1076
- });
1077
- } catch (error) {
1078
- spinner.fail("Failed to fetch workflows");
1079
- throw error;
2165
+ request.inputs = inputs;
2166
+ }
2167
+ if (options.responseMode) {
2168
+ request.response_mode = options.responseMode;
2169
+ }
2170
+ if (options.user) {
2171
+ request.user = options.user;
2172
+ }
2173
+ if (options.files) {
2174
+ request.files = loadOptionalJsonArrayInput(options.files, "workflow files");
1080
2175
  }
2176
+ if (options.traceId) {
2177
+ request.trace_id = options.traceId;
2178
+ }
2179
+ return request;
1081
2180
  }
1082
- async function executeWorkflow(client, options) {
1083
- const spinner = createSpinner(`Executing workflow: ${options.id}...`, options.format);
2181
+ async function runWorkflow(client, options) {
2182
+ const spinner = createSpinner(`Running workflow: ${options.name}...`, options.format);
1084
2183
  try {
1085
2184
  const workflowClient = client.workflow;
1086
- const input = options.input ? JSON.parse(options.input) : {};
1087
- const result = await workflowClient.execute(options.id, {
1088
- input,
1089
- version: options.version
1090
- });
2185
+ const request = buildWorkflowRunRequest(options);
2186
+ const result = await workflowClient.run(options.name, request);
1091
2187
  if (result.error) {
1092
- spinner.fail("Failed to execute workflow");
1093
- console.error(chalk7.red(result.error.message));
2188
+ spinner.fail("Failed to run workflow");
2189
+ console.error(chalk3.red(result.error.message));
1094
2190
  process.exit(1);
1095
2191
  }
1096
- spinner.succeed("Workflow executed");
2192
+ spinner.succeed("Workflow completed");
1097
2193
  renderOutput(result.data, {
1098
2194
  format: options.format,
1099
2195
  pretty: () => {
1100
- console.log(chalk7.green("\nExecution Result:"));
2196
+ console.log(chalk3.blue("\n\u26A1 Workflow Run\n"));
1101
2197
  console.log(JSON.stringify(result.data, null, 2));
1102
2198
  }
1103
2199
  });
1104
2200
  } catch (error) {
1105
- spinner.fail("Failed to execute workflow");
1106
- throw error;
2201
+ exitWithCommandError3(spinner, "Failed to run workflow", error);
2202
+ }
2203
+ }
2204
+ function exitWithCommandError4(spinner, failureMessage, error) {
2205
+ spinner.fail(failureMessage);
2206
+ const details = error instanceof Error ? error.message : String(error);
2207
+ if (details) {
2208
+ console.error(chalk3.red(details));
2209
+ }
2210
+ process.exit(1);
2211
+ }
2212
+ async function toBuffer(data) {
2213
+ if (data instanceof Blob) {
2214
+ return Buffer.from(await data.arrayBuffer());
2215
+ }
2216
+ if (Buffer.isBuffer(data)) {
2217
+ return data;
2218
+ }
2219
+ if (data instanceof Uint8Array) {
2220
+ return Buffer.from(data);
2221
+ }
2222
+ if (data instanceof ArrayBuffer) {
2223
+ return Buffer.from(data);
2224
+ }
2225
+ if (typeof data === "string") {
2226
+ return Buffer.from(data);
1107
2227
  }
2228
+ if (typeof data === "object" && data !== null && "arrayBuffer" in data && typeof data.arrayBuffer === "function") {
2229
+ const arrayBuffer = await data.arrayBuffer();
2230
+ return Buffer.from(arrayBuffer);
2231
+ }
2232
+ throw new Error(`Unsupported download response type: ${Object.prototype.toString.call(data)}`);
1108
2233
  }
1109
2234
  async function uploadFile(client, options) {
1110
2235
  const spinner = createSpinner("Uploading file...", options.format);
@@ -1115,74 +2240,87 @@ async function uploadFile(client, options) {
1115
2240
  spinner.fail(`File not found: ${options.file}`);
1116
2241
  process.exit(1);
1117
2242
  }
1118
- const result = await s3Client.uploadFile(filePath, {
1119
- key: options.key,
1120
- bucket: options.bucket,
1121
- isPublic: options.public
1122
- });
2243
+ const file = new File([readFileSync(filePath)], basename(filePath));
2244
+ const result = await s3Client.upload(file);
1123
2245
  if (result.error) {
1124
2246
  spinner.fail("Upload failed");
1125
- console.error(chalk7.red(result.error.message));
2247
+ console.error(chalk3.red(result.error.message));
1126
2248
  process.exit(1);
1127
2249
  }
1128
2250
  spinner.succeed("Upload complete");
1129
2251
  renderOutput(result.data, {
1130
2252
  format: options.format,
1131
2253
  pretty: () => {
1132
- console.log(chalk7.green("\nFile uploaded:"));
1133
- console.log(` ${chalk7.bold("Key:")} ${result.data?.key}`);
1134
- console.log(` ${chalk7.bold("URL:")} ${result.data?.url || "N/A"}`);
1135
- console.log(` ${chalk7.bold("Bucket:")} ${result.data?.bucket || options.bucket || "default"}`);
2254
+ console.log(chalk3.green("\nFile uploaded:"));
2255
+ console.log(` ${chalk3.bold("Key:")} ${result.data?.key}`);
2256
+ console.log(` ${chalk3.bold("URL:")} ${result.data?.url || "N/A"}`);
1136
2257
  }
1137
2258
  });
1138
2259
  } catch (error) {
1139
- spinner.fail("Upload failed");
1140
- throw error;
2260
+ exitWithCommandError4(spinner, "Upload failed", error);
1141
2261
  }
1142
2262
  }
1143
- async function listFiles(client, options) {
1144
- const spinner = createSpinner("Fetching files...", options.format);
2263
+ async function downloadFile(client, options) {
2264
+ const spinner = createSpinner("Downloading file...", options.format);
1145
2265
  try {
1146
2266
  const s3Client = client.s3;
1147
- const result = await s3Client.listFiles({
1148
- bucket: options.bucket,
1149
- prefix: options.prefix,
1150
- page: options.page || 1,
1151
- pageSize: options.pageSize || 10
1152
- });
2267
+ const result = await s3Client.download(options.key);
2268
+ if (result.error) {
2269
+ spinner.fail("Download failed");
2270
+ console.error(chalk3.red(result.error.message));
2271
+ process.exit(1);
2272
+ }
2273
+ if (!result.data) {
2274
+ spinner.fail("Download failed");
2275
+ console.error(chalk3.red("Empty file response."));
2276
+ process.exit(1);
2277
+ }
2278
+ const outputPath = resolve(options.output);
2279
+ const buffer = await toBuffer(result.data);
2280
+ writeFileSync(outputPath, buffer);
2281
+ spinner.succeed("Download complete");
2282
+ renderOutput(
2283
+ {
2284
+ key: options.key,
2285
+ output: outputPath,
2286
+ downloaded: true
2287
+ },
2288
+ {
2289
+ format: options.format,
2290
+ pretty: () => {
2291
+ console.log(chalk3.green(`
2292
+ File saved to: ${outputPath}`));
2293
+ }
2294
+ }
2295
+ );
2296
+ } catch (error) {
2297
+ exitWithCommandError4(spinner, "Download failed", error);
2298
+ }
2299
+ }
2300
+ async function getFileMetadata(client, options) {
2301
+ const spinner = createSpinner("Fetching file metadata...", options.format);
2302
+ try {
2303
+ const s3Client = client.s3;
2304
+ const result = await s3Client.getMetadata(options.key);
1153
2305
  if (result.error) {
1154
- spinner.fail("Failed to fetch files");
1155
- console.error(chalk7.red(result.error.message));
2306
+ spinner.fail("Failed to fetch metadata");
2307
+ console.error(chalk3.red(result.error.message));
1156
2308
  process.exit(1);
1157
2309
  }
1158
- spinner.succeed(`Found ${result.data?.total || 0} files`);
1159
- const files = result.data?.list || [];
2310
+ spinner.succeed("Metadata retrieved");
1160
2311
  renderOutput(result.data, {
1161
2312
  format: options.format,
1162
2313
  pretty: () => {
1163
- console.log(chalk7.blue(`
1164
- \u{1F4C1} Files${options.bucket ? ` in ${options.bucket}` : ""}
2314
+ console.log(chalk3.blue(`
2315
+ \u{1F4C4} Metadata for ${options.key}
1165
2316
  `));
1166
- for (const file of files) {
1167
- console.log(` ${chalk7.green("\u2022")} ${chalk7.bold(file.key)}`);
1168
- console.log(` ${chalk7.gray("Size:")} ${formatBytes(file.size || 0)}`);
1169
- console.log(` ${chalk7.gray("Modified:")} ${file.lastModified || "N/A"}`);
1170
- console.log();
1171
- }
2317
+ console.log(JSON.stringify(result.data, null, 2));
1172
2318
  }
1173
2319
  });
1174
2320
  } catch (error) {
1175
- spinner.fail("Failed to fetch files");
1176
- throw error;
2321
+ exitWithCommandError4(spinner, "Failed to fetch metadata", error);
1177
2322
  }
1178
2323
  }
1179
- function formatBytes(bytes) {
1180
- if (bytes === 0) return "0 B";
1181
- const k = 1024;
1182
- const sizes = ["B", "KB", "MB", "GB", "TB"];
1183
- const i = Math.floor(Math.log(bytes) / Math.log(k));
1184
- return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + " " + sizes[i];
1185
- }
1186
2324
 
1187
2325
  // src/commands/openclaw.ts
1188
2326
  init_config();
@@ -1221,8 +2359,8 @@ async function initOpenClaw(options) {
1221
2359
  const existingConfig = getAppConfig(options.appCode);
1222
2360
  if (existingConfig && !options.force) {
1223
2361
  spinner.fail(`App already exists: ${options.appCode}`);
1224
- console.log(chalk7.yellow(`Use --force to reinitialize`));
1225
- console.log(chalk7.gray(`Current URL: ${existingConfig.baseURL}`));
2362
+ console.log(chalk3.yellow(`Use --force to reinitialize`));
2363
+ console.log(chalk3.gray(`Current URL: ${existingConfig.baseURL}`));
1226
2364
  process.exit(1);
1227
2365
  }
1228
2366
  addApp(options.appCode, {
@@ -1233,8 +2371,8 @@ async function initOpenClaw(options) {
1233
2371
  if (!openClawDetected) {
1234
2372
  spinner.succeed(`App initialized: ${options.appCode}`);
1235
2373
  if (pretty) {
1236
- console.log(chalk7.yellow("\n\u26A0\uFE0F OpenClaw not detected, skipping skill download"));
1237
- console.log(chalk7.gray(" Install OpenClaw: npm install -g openclaw"));
2374
+ console.log(chalk3.yellow("\n\u26A0\uFE0F OpenClaw not detected, skipping skill download"));
2375
+ console.log(chalk3.gray(" Install OpenClaw: npm install -g openclaw"));
1238
2376
  } else {
1239
2377
  renderOutput(
1240
2378
  {
@@ -1252,9 +2390,9 @@ async function initOpenClaw(options) {
1252
2390
  }
1253
2391
  spinner.succeed(`App initialized: ${options.appCode}`);
1254
2392
  if (pretty) {
1255
- console.log(chalk7.blue("\n\u{1F4CB} Configuration:\n"));
1256
- console.log(` App Code: ${chalk7.green(options.appCode)}`);
1257
- console.log(` Base URL: ${chalk7.gray(options.baseURL)}`);
2393
+ console.log(chalk3.blue("\n\u{1F4CB} Configuration:\n"));
2394
+ console.log(` App Code: ${chalk3.green(options.appCode)}`);
2395
+ console.log(` Base URL: ${chalk3.gray(options.baseURL)}`);
1258
2396
  console.log();
1259
2397
  }
1260
2398
  spinner.start("Downloading skills...");
@@ -1326,16 +2464,16 @@ async function initOpenClaw(options) {
1326
2464
  };
1327
2465
  if (pretty) {
1328
2466
  console.log();
1329
- console.log(chalk7.green("\u2705 Initialization complete!"));
2467
+ console.log(chalk3.green("\u2705 Initialization complete!"));
1330
2468
  console.log();
1331
2469
  console.log(`Next step: Login to your app`);
1332
- console.log(chalk7.gray(` amaster login --app ${options.appCode}`));
2470
+ console.log(chalk3.gray(` amaster login --app ${options.appCode}`));
1333
2471
  console.log();
1334
2472
  if (apps.length > 1) {
1335
- console.log(chalk7.blue("Configured apps:"));
2473
+ console.log(chalk3.blue("Configured apps:"));
1336
2474
  for (const app of apps) {
1337
2475
  const config = getAppConfig(app);
1338
- console.log(` ${chalk7.gray("\u2022")} ${app} - ${config?.baseURL}`);
2476
+ console.log(` ${chalk3.gray("\u2022")} ${app} - ${config?.baseURL}`);
1339
2477
  }
1340
2478
  console.log();
1341
2479
  }
@@ -1444,40 +2582,45 @@ function resolveAppCode(optionsApp) {
1444
2582
  if (defaultApp) {
1445
2583
  return defaultApp;
1446
2584
  }
1447
- console.error(chalk7.red("\u274C No app specified."));
1448
- console.log(chalk7.yellow("Use one of:"));
1449
- console.log(chalk7.gray(" 1. Add --app <app-code> to the command"));
1450
- console.log(chalk7.gray(" 2. Set a default app: amaster use <app-code>"));
2585
+ console.error(chalk3.red("\u274C No app specified."));
2586
+ console.log(chalk3.yellow("Use one of:"));
2587
+ console.log(chalk3.gray(" 1. Add --app <app-code> to the command"));
2588
+ console.log(chalk3.gray(" 2. Set a default app: amaster use <app-code>"));
1451
2589
  process.exit(1);
1452
2590
  }
1453
2591
  function createAmasterClient(appCode) {
1454
2592
  const appConfig = getAppConfig(appCode);
1455
2593
  if (!appConfig) {
1456
- console.error(chalk7.red(`\u274C App not configured: ${appCode}`));
1457
- console.log(chalk7.yellow(`Initialize it first: amaster init --app-code ${appCode} --url <url>`));
2594
+ console.error(chalk3.red(`\u274C App not configured: ${appCode}`));
2595
+ console.log(chalk3.yellow(`Initialize it first: amaster init --app-code ${appCode} --url <url>`));
1458
2596
  process.exit(1);
1459
2597
  }
1460
2598
  const token = getAccessToken(appCode);
1461
- if (!token) {
1462
- console.error(chalk7.red(`\u274C Not authenticated for app: ${appCode}`));
1463
- console.log(chalk7.yellow(`Login first: amaster login --app ${appCode}`));
1464
- process.exit(1);
1465
- }
1466
- if (shouldRefreshToken(appCode)) {
1467
- console.error(chalk7.yellow("\u26A0\uFE0F Session expiring soon. Please login again."));
2599
+ if (token && shouldRefreshToken(appCode)) {
2600
+ console.error(chalk3.yellow("\u26A0\uFE0F Session expiring soon. Please login again."));
1468
2601
  }
1469
2602
  const client = createClient({
1470
2603
  baseURL: appConfig.baseURL,
1471
- headers: {
1472
- Authorization: `Bearer ${token}`
1473
- },
2604
+ ...token ? {
2605
+ headers: {
2606
+ Authorization: `Bearer ${token}`
2607
+ }
2608
+ } : {},
1474
2609
  onUnauthorized: () => {
1475
- console.error(chalk7.red("\n\u274C Session expired. Please login again."));
1476
- console.error(chalk7.yellow(`Run: amaster login --app ${appCode}`));
2610
+ if (token) {
2611
+ console.error(chalk3.red("\n\u274C Session expired. Please login again."));
2612
+ console.error(chalk3.yellow(`Run: amaster login --app ${appCode}`));
2613
+ } else {
2614
+ console.error(chalk3.red(`
2615
+ \u274C Authentication required for app: ${appCode}`));
2616
+ console.error(chalk3.yellow(`Run: amaster login --app ${appCode}`));
2617
+ }
1477
2618
  process.exit(1);
1478
2619
  }
1479
2620
  });
1480
- client.setAccessToken(token);
2621
+ if (token) {
2622
+ client.setAccessToken(token);
2623
+ }
1481
2624
  return client;
1482
2625
  }
1483
2626
  var program = new Command();
@@ -1497,17 +2640,17 @@ program.command("apps").description("List all configured apps").addOption(create
1497
2640
  renderOutput(appSummaries, {
1498
2641
  format: options.format,
1499
2642
  pretty: () => {
1500
- console.log(chalk7.blue("\n\u{1F4F1} Configured Apps\n"));
2643
+ console.log(chalk3.blue("\n\u{1F4F1} Configured Apps\n"));
1501
2644
  if (appSummaries.length === 0) {
1502
- console.log(chalk7.gray(" No apps configured"));
1503
- console.log(chalk7.gray(" Run: amaster init --app-code <code> --url <url>"));
2645
+ console.log(chalk3.gray(" No apps configured"));
2646
+ console.log(chalk3.gray(" Run: amaster init --app-code <code> --url <url>"));
1504
2647
  } else {
1505
2648
  for (const app of appSummaries) {
1506
- const prefix = app.current ? chalk7.green("\u2192 ") : " ";
1507
- console.log(`${prefix}${chalk7.bold(app.appCode)}${app.current ? chalk7.green(" (current)") : ""}`);
1508
- console.log(` ${chalk7.gray(app.baseURL || "No URL")}`);
2649
+ const prefix = app.current ? chalk3.green("\u2192 ") : " ";
2650
+ console.log(`${prefix}${chalk3.bold(app.appCode)}${app.current ? chalk3.green(" (current)") : ""}`);
2651
+ console.log(` ${chalk3.gray(app.baseURL || "No URL")}`);
1509
2652
  console.log(
1510
- ` ${app.authenticated ? chalk7.green("\u25CF Authenticated") : chalk7.yellow("\u25CB Not authenticated")}`
2653
+ ` ${app.authenticated ? chalk3.green("\u25CF Authenticated") : chalk3.yellow("\u25CB Not authenticated")}`
1511
2654
  );
1512
2655
  console.log();
1513
2656
  }
@@ -1526,12 +2669,12 @@ program.command("use <app-code>").description("Set the default app for subsequen
1526
2669
  {
1527
2670
  format: options.format,
1528
2671
  pretty: () => {
1529
- console.log(chalk7.green(`\u2705 Now using app: ${appCode}`));
2672
+ console.log(chalk3.green(`\u2705 Now using app: ${appCode}`));
1530
2673
  }
1531
2674
  }
1532
2675
  );
1533
2676
  } else {
1534
- console.error(chalk7.red(`\u274C App not found: ${appCode}`));
2677
+ console.error(chalk3.red(`\u274C App not found: ${appCode}`));
1535
2678
  process.exit(1);
1536
2679
  }
1537
2680
  });
@@ -1563,13 +2706,13 @@ program.command("whoami").description("Show current user information").option("-
1563
2706
  await getMe(() => createAmasterClient(appCode), { format: options.format });
1564
2707
  });
1565
2708
  var entityCmd = program.command("entity").description("Manage entities");
1566
- entityCmd.command("list <namespace> <entity>").description("List entities").option("--app <app-code>", "App code (uses default if not specified)").option("--page <page>", "Page number", "1").option("--page-size <size>", "Page size", "10").option("-f, --fields <fields>", "Comma-separated fields to return").option("-r, --relations <relations>", "Comma-separated relations to load").option("-k, --keyword <keyword>", "Keyword to search").option("--keyword-fields <fields>", "Comma-separated fields for keyword search").option("--order-by <field>", "Field to sort by").addOption(new Option("--order-dir <dir>", "Sort direction").choices(["asc", "desc"])).option("--orders <orders>", "Multi-order expression, e.g. created_at:desc,name:asc").option("--filter <json>", "Advanced __filter JSON or @file").option("--limit <limit>", "Limit number of records").option("--offset <offset>", "Offset number of records").option("-q, --query <json>", "Additional EntityQueryParams as JSON or @file").addOption(createFormatOption()).action(async (namespace, entityName, options) => {
2709
+ entityCmd.command("list <namespace> <entity>").description("List entities").option("--app <app-code>", "App code (uses default if not specified)").option("--page <page>", "Page number").option("--page-size <size>", "Page size").option("-f, --fields <fields>", "Comma-separated fields to return").option("-r, --relations <relations>", "Comma-separated relations to load").option("-k, --keyword <keyword>", "Keyword to search").option("--keyword-fields <fields>", "Comma-separated fields for keyword search").option("--order-by <field>", "Field to sort by").addOption(new Option("--order-dir <dir>", "Sort direction").choices(["asc", "desc"])).option("--orders <orders>", "Multi-order expression, e.g. created_at:desc,name:asc").option("--filter <json>", "Advanced __filter JSON or @file").option("--limit <limit>", "Limit number of records").option("--offset <offset>", "Offset number of records").option("-q, --query <json>", "Additional EntityQueryParams as JSON or @file").addOption(createFormatOption()).action(async (namespace, entityName, options) => {
1567
2710
  const appCode = resolveAppCode(options.app);
1568
2711
  await listEntities(createAmasterClient(appCode), {
1569
2712
  namespace,
1570
2713
  entity: entityName,
1571
- page: parseInt(options.page),
1572
- pageSize: parseInt(options.pageSize),
2714
+ page: options.page ? parseInt(options.page) : void 0,
2715
+ pageSize: options.pageSize ? parseInt(options.pageSize) : void 0,
1573
2716
  fields: options.fields,
1574
2717
  relations: options.relations,
1575
2718
  keyword: options.keyword,
@@ -1649,11 +2792,28 @@ entityCmd.command("bulk-delete <namespace> <entity>").description("Bulk delete e
1649
2792
  });
1650
2793
  });
1651
2794
  var bpmCmd = program.command("bpm").description("Manage BPM processes and tasks");
1652
- bpmCmd.command("processes").description("List process definitions").option("--app <app-code>", "App code (uses default if not specified)").addOption(createFormatOption()).action(async (options) => {
2795
+ bpmCmd.command("processes").description("List process definitions").option("--app <app-code>", "App code (uses default if not specified)").option("--key <key>", "Filter by process definition key").option("--name <name>", "Filter by process definition name").option("--latest-version", "Only return latest version").option("--active", "Only return active process definitions").option("--suspended", "Only return suspended process definitions").option("--sort-by <field>", "Sort field").addOption(new Option("--sort-order <order>", "Sort order").choices(["asc", "desc"])).option("-q, --query <json>", "Additional ProcessDefinitionQueryParams as JSON or @file").addOption(createFormatOption()).action(async (options) => {
2796
+ const appCode = resolveAppCode(options.app);
2797
+ await listProcesses(createAmasterClient(appCode), {
2798
+ key: options.key,
2799
+ name: options.name,
2800
+ latestVersion: options.latestVersion,
2801
+ active: options.active,
2802
+ suspended: options.suspended,
2803
+ sortBy: options.sortBy,
2804
+ sortOrder: options.sortOrder,
2805
+ query: options.query,
2806
+ format: options.format
2807
+ });
2808
+ });
2809
+ bpmCmd.command("xml <key>").description("Get BPMN XML for a process definition key").option("--app <app-code>", "App code (uses default if not specified)").addOption(createFormatOption()).action(async (key, options) => {
1653
2810
  const appCode = resolveAppCode(options.app);
1654
- await listProcesses(createAmasterClient(appCode), { format: options.format });
2811
+ await getProcessXml(createAmasterClient(appCode), {
2812
+ key,
2813
+ format: options.format
2814
+ });
1655
2815
  });
1656
- bpmCmd.command("start <key>").description("Start a process instance").option("--app <app-code>", "App code (uses default if not specified)").option("-v, --variables <json>", "Process variables as JSON").addOption(createFormatOption()).action(async (key, options) => {
2816
+ bpmCmd.command("start <key>").description("Start a process instance").option("--app <app-code>", "App code (uses default if not specified)").option("-v, --variables <json>", "Process variables as JSON or @file").addOption(createFormatOption()).action(async (key, options) => {
1657
2817
  const appCode = resolveAppCode(options.app);
1658
2818
  await startProcess(createAmasterClient(appCode), {
1659
2819
  key,
@@ -1661,14 +2821,127 @@ bpmCmd.command("start <key>").description("Start a process instance").option("--
1661
2821
  format: options.format
1662
2822
  });
1663
2823
  });
1664
- bpmCmd.command("tasks").description("List tasks").option("--app <app-code>", "App code (uses default if not specified)").option("-a, --assignee <assignee>", "Filter by assignee").addOption(createFormatOption()).action(async (options) => {
2824
+ bpmCmd.command("instances").description("List process instances").option("--app <app-code>", "App code (uses default if not specified)").option("--process-definition-key <key>", "Filter by process definition key").option("--active", "Only return active instances").option("--first-result <n>", "Pagination offset").option("--max-results <n>", "Maximum number of results").option("-q, --query <json>", "Additional ProcessInstanceQueryParams as JSON or @file").addOption(createFormatOption()).action(async (options) => {
2825
+ const appCode = resolveAppCode(options.app);
2826
+ await listProcessInstances(createAmasterClient(appCode), {
2827
+ processDefinitionKey: options.processDefinitionKey,
2828
+ active: options.active,
2829
+ firstResult: options.firstResult ? parseInt(options.firstResult) : void 0,
2830
+ maxResults: options.maxResults ? parseInt(options.maxResults) : void 0,
2831
+ query: options.query,
2832
+ format: options.format
2833
+ });
2834
+ });
2835
+ bpmCmd.command("instance <id>").description("Get a process instance by ID").option("--app <app-code>", "App code (uses default if not specified)").addOption(createFormatOption()).action(async (id, options) => {
2836
+ const appCode = resolveAppCode(options.app);
2837
+ await getProcessInstance(createAmasterClient(appCode), {
2838
+ id,
2839
+ format: options.format
2840
+ });
2841
+ });
2842
+ bpmCmd.command("instance-tree <id>").description("Get the activity instance tree for a process instance").option("--app <app-code>", "App code (uses default if not specified)").addOption(createFormatOption()).action(async (id, options) => {
2843
+ const appCode = resolveAppCode(options.app);
2844
+ await getActivityInstanceTree(createAmasterClient(appCode), {
2845
+ id,
2846
+ format: options.format
2847
+ });
2848
+ });
2849
+ bpmCmd.command("active-activities <id>").description("Get active activities for a process instance").option("--app <app-code>", "App code (uses default if not specified)").addOption(createFormatOption()).action(async (id, options) => {
2850
+ const appCode = resolveAppCode(options.app);
2851
+ await getActiveActivities(createAmasterClient(appCode), {
2852
+ id,
2853
+ format: options.format
2854
+ });
2855
+ });
2856
+ bpmCmd.command("runtime-variables <id>").description("Get runtime variables for a process instance").option("--app <app-code>", "App code (uses default if not specified)").addOption(createFormatOption()).action(async (id, options) => {
2857
+ const appCode = resolveAppCode(options.app);
2858
+ await getRuntimeVariables(createAmasterClient(appCode), {
2859
+ id,
2860
+ format: options.format
2861
+ });
2862
+ });
2863
+ bpmCmd.command("variables <id>").description("Get historic variables for a process instance").option("--app <app-code>", "App code (uses default if not specified)").option("--name <name>", "Filter by variable name").addOption(createFormatOption()).action(async (id, options) => {
2864
+ const appCode = resolveAppCode(options.app);
2865
+ await getProcessVariables(createAmasterClient(appCode), {
2866
+ id,
2867
+ name: options.name,
2868
+ format: options.format
2869
+ });
2870
+ });
2871
+ bpmCmd.command("delete-instance <id>").description("Delete a process instance").option("--app <app-code>", "App code (uses default if not specified)").option("--skip-custom-listeners", "Skip custom listeners during deletion").addOption(createFormatOption()).action(async (id, options) => {
2872
+ const appCode = resolveAppCode(options.app);
2873
+ await deleteProcessInstance(createAmasterClient(appCode), {
2874
+ id,
2875
+ skipCustomListeners: options.skipCustomListeners,
2876
+ format: options.format
2877
+ });
2878
+ });
2879
+ bpmCmd.command("suspend-instance <id>").description("Suspend a process instance").option("--app <app-code>", "App code (uses default if not specified)").addOption(createFormatOption()).action(async (id, options) => {
2880
+ const appCode = resolveAppCode(options.app);
2881
+ await suspendProcessInstance(createAmasterClient(appCode), {
2882
+ id,
2883
+ format: options.format
2884
+ });
2885
+ });
2886
+ bpmCmd.command("activate-instance <id>").description("Activate a suspended process instance").option("--app <app-code>", "App code (uses default if not specified)").addOption(createFormatOption()).action(async (id, options) => {
2887
+ const appCode = resolveAppCode(options.app);
2888
+ await activateProcessInstance(createAmasterClient(appCode), {
2889
+ id,
2890
+ format: options.format
2891
+ });
2892
+ });
2893
+ bpmCmd.command("modify-instance <id>").description("Modify a process instance").option("--app <app-code>", "App code (uses default if not specified)").option("-m, --modification <json>", "ProcessInstanceModification JSON or @file").addOption(createFormatOption()).action(async (id, options) => {
2894
+ const appCode = resolveAppCode(options.app);
2895
+ await modifyProcessInstance(createAmasterClient(appCode), {
2896
+ id,
2897
+ modification: options.modification,
2898
+ format: options.format
2899
+ });
2900
+ });
2901
+ bpmCmd.command("tasks").description("List tasks").option("--app <app-code>", "App code (uses default if not specified)").option("-a, --assignee <assignee>", "Filter by assignee").option("--process-instance-id <id>", "Filter by process instance ID").option("--candidate-user <user>", "Filter by candidate user").option("--candidate-group <group>", "Filter by candidate group").option("--name <name>", "Filter by exact task name").option("--name-like <name>", "Filter by fuzzy task name").option("--task-definition-key <key>", "Filter by task definition key").option("--first-result <n>", "Pagination offset").option("--max-results <n>", "Maximum number of results").option("--sort-by <field>", "Sort field").addOption(new Option("--sort-order <order>", "Sort order").choices(["asc", "desc"])).option("-q, --query <json>", "Additional TaskQueryParams as JSON or @file").addOption(createFormatOption()).action(async (options) => {
1665
2902
  const appCode = resolveAppCode(options.app);
1666
2903
  await listTasks(createAmasterClient(appCode), {
2904
+ processInstanceId: options.processInstanceId,
2905
+ assignee: options.assignee,
2906
+ candidateUser: options.candidateUser,
2907
+ candidateGroup: options.candidateGroup,
2908
+ name: options.name,
2909
+ nameLike: options.nameLike,
2910
+ taskDefinitionKey: options.taskDefinitionKey,
2911
+ firstResult: options.firstResult ? parseInt(options.firstResult) : void 0,
2912
+ maxResults: options.maxResults ? parseInt(options.maxResults) : void 0,
2913
+ sortBy: options.sortBy,
2914
+ sortOrder: options.sortOrder,
2915
+ query: options.query,
2916
+ format: options.format
2917
+ });
2918
+ });
2919
+ bpmCmd.command("task <id>").description("Get a task by ID").option("--app <app-code>", "App code (uses default if not specified)").addOption(createFormatOption()).action(async (id, options) => {
2920
+ const appCode = resolveAppCode(options.app);
2921
+ await getTask(createAmasterClient(appCode), {
2922
+ id,
2923
+ format: options.format
2924
+ });
2925
+ });
2926
+ bpmCmd.command("task-count").description("Get task count").option("--app <app-code>", "App code (uses default if not specified)").option("-a, --assignee <assignee>", "Filter by assignee").option("--process-instance-id <id>", "Filter by process instance ID").option("--candidate-user <user>", "Filter by candidate user").option("--candidate-group <group>", "Filter by candidate group").option("--name <name>", "Filter by exact task name").option("--name-like <name>", "Filter by fuzzy task name").option("--task-definition-key <key>", "Filter by task definition key").option("--first-result <n>", "Pagination offset").option("--max-results <n>", "Maximum number of results").option("--sort-by <field>", "Sort field").addOption(new Option("--sort-order <order>", "Sort order").choices(["asc", "desc"])).option("-q, --query <json>", "Additional TaskQueryParams as JSON or @file").addOption(createFormatOption()).action(async (options) => {
2927
+ const appCode = resolveAppCode(options.app);
2928
+ await getTaskCount(createAmasterClient(appCode), {
2929
+ processInstanceId: options.processInstanceId,
1667
2930
  assignee: options.assignee,
2931
+ candidateUser: options.candidateUser,
2932
+ candidateGroup: options.candidateGroup,
2933
+ name: options.name,
2934
+ nameLike: options.nameLike,
2935
+ taskDefinitionKey: options.taskDefinitionKey,
2936
+ firstResult: options.firstResult ? parseInt(options.firstResult) : void 0,
2937
+ maxResults: options.maxResults ? parseInt(options.maxResults) : void 0,
2938
+ sortBy: options.sortBy,
2939
+ sortOrder: options.sortOrder,
2940
+ query: options.query,
1668
2941
  format: options.format
1669
2942
  });
1670
2943
  });
1671
- bpmCmd.command("complete <id>").description("Complete a task").option("--app <app-code>", "App code (uses default if not specified)").option("-v, --variables <json>", "Task variables as JSON").addOption(createFormatOption()).action(async (id, options) => {
2944
+ bpmCmd.command("complete <id>").description("Complete a task").option("--app <app-code>", "App code (uses default if not specified)").option("-v, --variables <json>", "Task variables as JSON or @file").addOption(createFormatOption()).action(async (id, options) => {
1672
2945
  const appCode = resolveAppCode(options.app);
1673
2946
  await completeTask(createAmasterClient(appCode), {
1674
2947
  id,
@@ -1676,33 +2949,236 @@ bpmCmd.command("complete <id>").description("Complete a task").option("--app <ap
1676
2949
  format: options.format
1677
2950
  });
1678
2951
  });
1679
- var workflowCmd = program.command("workflow").description("Manage workflows");
1680
- workflowCmd.command("list").description("List workflows").option("--app <app-code>", "App code (uses default if not specified)").addOption(createFormatOption()).action(async (options) => {
2952
+ bpmCmd.command("delegate <id>").description("Delegate a task to another user").option("--app <app-code>", "App code (uses default if not specified)").requiredOption("--user-id <userId>", "Delegate target user ID").addOption(createFormatOption()).action(async (id, options) => {
2953
+ const appCode = resolveAppCode(options.app);
2954
+ await delegateTask(createAmasterClient(appCode), {
2955
+ id,
2956
+ userId: options.userId,
2957
+ format: options.format
2958
+ });
2959
+ });
2960
+ bpmCmd.command("task-form <id>").description("Get task form metadata").option("--app <app-code>", "App code (uses default if not specified)").addOption(createFormatOption()).action(async (id, options) => {
1681
2961
  const appCode = resolveAppCode(options.app);
1682
- await listWorkflows(createAmasterClient(appCode), { format: options.format });
2962
+ await getTaskForm(createAmasterClient(appCode), {
2963
+ id,
2964
+ format: options.format
2965
+ });
1683
2966
  });
1684
- workflowCmd.command("execute <id>").description("Execute a workflow").option("--app <app-code>", "App code (uses default if not specified)").option("-i, --input <json>", "Workflow input as JSON").addOption(createFormatOption()).action(async (id, options) => {
2967
+ bpmCmd.command("task-form-schema <id>").description("Get task form schema").option("--app <app-code>", "App code (uses default if not specified)").option("--redirect <url>", "Optional redirect URL").addOption(createFormatOption()).action(async (id, options) => {
1685
2968
  const appCode = resolveAppCode(options.app);
1686
- await executeWorkflow(createAmasterClient(appCode), {
2969
+ await getTaskFormSchema(createAmasterClient(appCode), {
1687
2970
  id,
1688
- input: options.input,
2971
+ redirect: options.redirect,
1689
2972
  format: options.format
1690
2973
  });
1691
2974
  });
1692
- var s3Cmd = program.command("s3").description("Manage S3 files");
1693
- s3Cmd.command("list").description("List files").option("--app <app-code>", "App code (uses default if not specified)").option("-b, --bucket <bucket>", "Bucket name").addOption(createFormatOption()).action(async (options) => {
2975
+ bpmCmd.command("task-form-variables <id>").description("Get task form variables").option("--app <app-code>", "App code (uses default if not specified)").addOption(createFormatOption()).action(async (id, options) => {
2976
+ const appCode = resolveAppCode(options.app);
2977
+ await getTaskFormVariables(createAmasterClient(appCode), {
2978
+ id,
2979
+ format: options.format
2980
+ });
2981
+ });
2982
+ bpmCmd.command("task-rendered-form <id>").description("Get rendered task form HTML").option("--app <app-code>", "App code (uses default if not specified)").addOption(createFormatOption()).action(async (id, options) => {
2983
+ const appCode = resolveAppCode(options.app);
2984
+ await getTaskRenderedForm(createAmasterClient(appCode), {
2985
+ id,
2986
+ format: options.format
2987
+ });
2988
+ });
2989
+ bpmCmd.command("task-deployed-form <id>").description("Get deployed task form definition").option("--app <app-code>", "App code (uses default if not specified)").addOption(createFormatOption()).action(async (id, options) => {
2990
+ const appCode = resolveAppCode(options.app);
2991
+ await getTaskDeployedForm(createAmasterClient(appCode), {
2992
+ id,
2993
+ format: options.format
2994
+ });
2995
+ });
2996
+ bpmCmd.command("start-form <key>").description("Get start form info for a process definition key").option("--app <app-code>", "App code (uses default if not specified)").addOption(createFormatOption()).action(async (key, options) => {
2997
+ const appCode = resolveAppCode(options.app);
2998
+ await getStartFormInfo(createAmasterClient(appCode), {
2999
+ key,
3000
+ format: options.format
3001
+ });
3002
+ });
3003
+ bpmCmd.command("start-form-variables <key>").description("Get start form variables for a process definition key").option("--app <app-code>", "App code (uses default if not specified)").addOption(createFormatOption()).action(async (key, options) => {
3004
+ const appCode = resolveAppCode(options.app);
3005
+ await getStartFormVariables(createAmasterClient(appCode), {
3006
+ key,
3007
+ format: options.format
3008
+ });
3009
+ });
3010
+ bpmCmd.command("history-tasks").description("List history tasks").option("--app <app-code>", "App code (uses default if not specified)").option("--task-assignee <assignee>", "Filter by historical task assignee").option("--process-instance-id <id>", "Filter by process instance ID").option("--finished", "Only return finished history tasks").option("--unfinished", "Only return unfinished history tasks").addOption(new Option("--scope <scope>", "History task scope").choices(["handled"])).option("--first-result <n>", "Pagination offset").option("--max-results <n>", "Maximum number of results").option("--sort-by <field>", "Sort field").addOption(new Option("--sort-order <order>", "Sort order").choices(["asc", "desc"])).option("-q, --query <json>", "Additional HistoryTaskQueryParams as JSON or @file").addOption(createFormatOption()).action(async (options) => {
3011
+ const appCode = resolveAppCode(options.app);
3012
+ await listHistoryTasks(createAmasterClient(appCode), {
3013
+ taskAssignee: options.taskAssignee,
3014
+ processInstanceId: options.processInstanceId,
3015
+ finished: options.finished,
3016
+ unfinished: options.unfinished,
3017
+ scope: options.scope,
3018
+ firstResult: options.firstResult ? parseInt(options.firstResult) : void 0,
3019
+ maxResults: options.maxResults ? parseInt(options.maxResults) : void 0,
3020
+ sortBy: options.sortBy,
3021
+ sortOrder: options.sortOrder,
3022
+ query: options.query,
3023
+ format: options.format
3024
+ });
3025
+ });
3026
+ bpmCmd.command("history-task-count").description("Get history task count").option("--app <app-code>", "App code (uses default if not specified)").option("--task-assignee <assignee>", "Filter by historical task assignee").option("--process-instance-id <id>", "Filter by process instance ID").option("--finished", "Only count finished history tasks").option("--unfinished", "Only count unfinished history tasks").addOption(new Option("--scope <scope>", "History task scope").choices(["handled"])).option("--first-result <n>", "Pagination offset").option("--max-results <n>", "Maximum number of results").option("--sort-by <field>", "Sort field").addOption(new Option("--sort-order <order>", "Sort order").choices(["asc", "desc"])).option("-q, --query <json>", "Additional HistoryTaskQueryParams as JSON or @file").addOption(createFormatOption()).action(async (options) => {
3027
+ const appCode = resolveAppCode(options.app);
3028
+ await getHistoryTaskCount(createAmasterClient(appCode), {
3029
+ taskAssignee: options.taskAssignee,
3030
+ processInstanceId: options.processInstanceId,
3031
+ finished: options.finished,
3032
+ unfinished: options.unfinished,
3033
+ scope: options.scope,
3034
+ firstResult: options.firstResult ? parseInt(options.firstResult) : void 0,
3035
+ maxResults: options.maxResults ? parseInt(options.maxResults) : void 0,
3036
+ sortBy: options.sortBy,
3037
+ sortOrder: options.sortOrder,
3038
+ query: options.query,
3039
+ format: options.format
3040
+ });
3041
+ });
3042
+ bpmCmd.command("history-instances").description("List history process instances").option("--app <app-code>", "App code (uses default if not specified)").option("--started-by <userId>", "Filter by starter user ID").option("--process-definition-key <key>", "Filter by process definition key").option("--finished", "Only return finished history instances").option("--unfinished", "Only return unfinished history instances").addOption(new Option("--scope <scope>", "History process scope").choices(["initiated"])).option("--sort-by <field>", "Sort field").addOption(new Option("--sort-order <order>", "Sort order").choices(["asc", "desc"])).option("--first-result <n>", "Pagination offset").option("--max-results <n>", "Maximum number of results").option("-q, --query <json>", "Additional HistoryProcessInstanceQueryParams as JSON or @file").addOption(createFormatOption()).action(async (options) => {
3043
+ const appCode = resolveAppCode(options.app);
3044
+ await listHistoryProcessInstances(createAmasterClient(appCode), {
3045
+ startedBy: options.startedBy,
3046
+ processDefinitionKey: options.processDefinitionKey,
3047
+ finished: options.finished,
3048
+ unfinished: options.unfinished,
3049
+ scope: options.scope,
3050
+ sortBy: options.sortBy,
3051
+ sortOrder: options.sortOrder,
3052
+ firstResult: options.firstResult ? parseInt(options.firstResult) : void 0,
3053
+ maxResults: options.maxResults ? parseInt(options.maxResults) : void 0,
3054
+ query: options.query,
3055
+ format: options.format
3056
+ });
3057
+ });
3058
+ bpmCmd.command("history-instance-count").description("Get history process instance count").option("--app <app-code>", "App code (uses default if not specified)").option("--started-by <userId>", "Filter by starter user ID").option("--process-definition-key <key>", "Filter by process definition key").option("--finished", "Only count finished history instances").option("--unfinished", "Only count unfinished history instances").addOption(new Option("--scope <scope>", "History process scope").choices(["initiated"])).option("--sort-by <field>", "Sort field").addOption(new Option("--sort-order <order>", "Sort order").choices(["asc", "desc"])).option("--first-result <n>", "Pagination offset").option("--max-results <n>", "Maximum number of results").option("-q, --query <json>", "Additional HistoryProcessInstanceQueryParams as JSON or @file").addOption(createFormatOption()).action(async (options) => {
3059
+ const appCode = resolveAppCode(options.app);
3060
+ await getHistoryProcessInstanceCount(createAmasterClient(appCode), {
3061
+ startedBy: options.startedBy,
3062
+ processDefinitionKey: options.processDefinitionKey,
3063
+ finished: options.finished,
3064
+ unfinished: options.unfinished,
3065
+ scope: options.scope,
3066
+ sortBy: options.sortBy,
3067
+ sortOrder: options.sortOrder,
3068
+ firstResult: options.firstResult ? parseInt(options.firstResult) : void 0,
3069
+ maxResults: options.maxResults ? parseInt(options.maxResults) : void 0,
3070
+ query: options.query,
3071
+ format: options.format
3072
+ });
3073
+ });
3074
+ bpmCmd.command("history-instance <id>").description("Get a history process instance by ID").option("--app <app-code>", "App code (uses default if not specified)").addOption(createFormatOption()).action(async (id, options) => {
3075
+ const appCode = resolveAppCode(options.app);
3076
+ await getHistoryProcessInstance(createAmasterClient(appCode), {
3077
+ id,
3078
+ format: options.format
3079
+ });
3080
+ });
3081
+ bpmCmd.command("history-activities").description("List history activity instances").option("--app <app-code>", "App code (uses default if not specified)").option("--process-instance-id <id>", "Filter by process instance ID").option("--activity-id <activityId>", "Filter by BPMN activity ID").option("--activity-type <activityType>", "Filter by activity type").option("--finished", "Only return finished history activity instances").option("--sort-by <field>", "Sort field").addOption(new Option("--sort-order <order>", "Sort order").choices(["asc", "desc"])).option("-q, --query <json>", "Additional HistoryActivityQueryParams as JSON or @file").addOption(createFormatOption()).action(async (options) => {
3082
+ const appCode = resolveAppCode(options.app);
3083
+ await listHistoryActivityInstances(createAmasterClient(appCode), {
3084
+ processInstanceId: options.processInstanceId,
3085
+ activityId: options.activityId,
3086
+ activityType: options.activityType,
3087
+ finished: options.finished,
3088
+ sortBy: options.sortBy,
3089
+ sortOrder: options.sortOrder,
3090
+ query: options.query,
3091
+ format: options.format
3092
+ });
3093
+ });
3094
+ bpmCmd.command("history-variables").description("List history variable instances").option("--app <app-code>", "App code (uses default if not specified)").option("--process-instance-id <id>", "Filter by process instance ID").option("--variable-name <name>", "Filter by variable name").option("--deserialize-values", "Deserialize complex variable values").option("-q, --query <json>", "Additional HistoryVariableQueryParams as JSON or @file").addOption(createFormatOption()).action(async (options) => {
3095
+ const appCode = resolveAppCode(options.app);
3096
+ await listHistoryVariableInstances(createAmasterClient(appCode), {
3097
+ processInstanceId: options.processInstanceId,
3098
+ variableName: options.variableName,
3099
+ deserializeValues: options.deserializeValues,
3100
+ query: options.query,
3101
+ format: options.format
3102
+ });
3103
+ });
3104
+ bpmCmd.command("user-operations").description("List user operation logs").option("--app <app-code>", "App code (uses default if not specified)").option("--process-instance-id <id>", "Filter by process instance ID").option("--task-id <id>", "Filter by task ID").option("--user-id <userId>", "Filter by user ID").option("--operation-type <type>", "Filter by operation type").option("--sort-by <field>", "Sort field").addOption(new Option("--sort-order <order>", "Sort order").choices(["asc", "desc"])).option("--first-result <n>", "Pagination offset").option("--max-results <n>", "Maximum number of results").option("-q, --query <json>", "Additional UserOperationLogQueryParams as JSON or @file").addOption(createFormatOption()).action(async (options) => {
3105
+ const appCode = resolveAppCode(options.app);
3106
+ await listUserOperationLogs(createAmasterClient(appCode), {
3107
+ processInstanceId: options.processInstanceId,
3108
+ taskId: options.taskId,
3109
+ userId: options.userId,
3110
+ operationType: options.operationType,
3111
+ sortBy: options.sortBy,
3112
+ sortOrder: options.sortOrder,
3113
+ firstResult: options.firstResult ? parseInt(options.firstResult) : void 0,
3114
+ maxResults: options.maxResults ? parseInt(options.maxResults) : void 0,
3115
+ query: options.query,
3116
+ format: options.format
3117
+ });
3118
+ });
3119
+ bpmCmd.command("delete-history-instance <id>").description("Delete a history process instance").option("--app <app-code>", "App code (uses default if not specified)").addOption(createFormatOption()).action(async (id, options) => {
3120
+ const appCode = resolveAppCode(options.app);
3121
+ await deleteHistoryProcessInstance(createAmasterClient(appCode), {
3122
+ id,
3123
+ format: options.format
3124
+ });
3125
+ });
3126
+ bpmCmd.command("roles").description("List runtime roles").option("--app <app-code>", "App code (uses default if not specified)").addOption(createFormatOption()).action(async (options) => {
3127
+ const appCode = resolveAppCode(options.app);
3128
+ await listRoles(createAmasterClient(appCode), {
3129
+ format: options.format
3130
+ });
3131
+ });
3132
+ bpmCmd.command("user-roles <userId>").description("List roles assigned to a user").option("--app <app-code>", "App code (uses default if not specified)").addOption(createFormatOption()).action(async (userId, options) => {
3133
+ const appCode = resolveAppCode(options.app);
3134
+ await getUserRoles(createAmasterClient(appCode), {
3135
+ userId,
3136
+ format: options.format
3137
+ });
3138
+ });
3139
+ bpmCmd.command("start-form-deployed <key>").description("Get deployed start form definition for a process definition key").option("--app <app-code>", "App code (uses default if not specified)").addOption(createFormatOption()).action(async (key, options) => {
3140
+ const appCode = resolveAppCode(options.app);
3141
+ await getDeployedStartForm(createAmasterClient(appCode), {
3142
+ key,
3143
+ format: options.format
3144
+ });
3145
+ });
3146
+ var workflowCmd = program.command("workflow").description("Run workflows");
3147
+ workflowCmd.command("run <name>").alias("execute").description("Run a workflow").option("--app <app-code>", "App code (uses default if not specified)").option("-i, --input <json>", "Workflow inputs object as JSON or @file").option("-r, --request <json>", "Full WorkflowRunRequest as JSON or @file").addOption(
3148
+ new Option("--response-mode <mode>", "Workflow response mode").choices(["blocking", "streaming"])
3149
+ ).option("--user <user>", "Workflow user identifier").option("--files <json>", "Workflow files array as JSON or @file").option("--trace-id <traceId>", "Workflow trace ID").addOption(createFormatOption()).action(async (name, options) => {
1694
3150
  const appCode = resolveAppCode(options.app);
1695
- await listFiles(createAmasterClient(appCode), {
1696
- bucket: options.bucket,
3151
+ await runWorkflow(createAmasterClient(appCode), {
3152
+ name,
3153
+ input: options.input,
3154
+ request: options.request,
3155
+ responseMode: options.responseMode,
3156
+ user: options.user,
3157
+ files: options.files,
3158
+ traceId: options.traceId,
1697
3159
  format: options.format
1698
3160
  });
1699
3161
  });
1700
- s3Cmd.command("upload <file>").description("Upload a file").option("--app <app-code>", "App code (uses default if not specified)").option("-b, --bucket <bucket>", "Bucket name").option("-k, --key <key>", "Object key").addOption(createFormatOption()).action(async (file, options) => {
3162
+ var s3Cmd = program.command("s3").description("Manage S3 files");
3163
+ s3Cmd.command("upload <file>").description("Upload a file").option("--app <app-code>", "App code (uses default if not specified)").addOption(createFormatOption()).action(async (file, options) => {
1701
3164
  const appCode = resolveAppCode(options.app);
1702
3165
  await uploadFile(createAmasterClient(appCode), {
1703
3166
  file,
1704
- bucket: options.bucket,
1705
- key: options.key,
3167
+ format: options.format
3168
+ });
3169
+ });
3170
+ s3Cmd.command("download <key> <output>").description("Download a file to a local path").option("--app <app-code>", "App code (uses default if not specified)").addOption(createFormatOption()).action(async (key, output, options) => {
3171
+ const appCode = resolveAppCode(options.app);
3172
+ await downloadFile(createAmasterClient(appCode), {
3173
+ key,
3174
+ output,
3175
+ format: options.format
3176
+ });
3177
+ });
3178
+ s3Cmd.command("metadata <key>").description("Get file metadata").option("--app <app-code>", "App code (uses default if not specified)").addOption(createFormatOption()).action(async (key, options) => {
3179
+ const appCode = resolveAppCode(options.app);
3180
+ await getFileMetadata(createAmasterClient(appCode), {
3181
+ key,
1706
3182
  format: options.format
1707
3183
  });
1708
3184
  });