@amaster.ai/runtime-cli 1.1.13 → 1.1.14-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -1
- package/dist/cli.cjs +691 -225
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +691 -225
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +691 -225
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +691 -225
- package/dist/index.js.map +1 -1
- package/dist/skill/SKILL.md +40 -3
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { existsSync, rmSync, mkdirSync,
|
|
1
|
+
import { readFileSync, existsSync, rmSync, mkdirSync, writeFileSync, realpathSync } from 'fs';
|
|
2
2
|
import { join, resolve, basename } from 'path';
|
|
3
3
|
import { homedir } from 'os';
|
|
4
4
|
import { fileURLToPath } from 'url';
|
|
5
5
|
import { Command, Option } from 'commander';
|
|
6
|
-
import
|
|
6
|
+
import chalk4 from 'chalk';
|
|
7
7
|
import { createClient } from '@amaster.ai/client';
|
|
8
8
|
import ora from 'ora';
|
|
9
9
|
import { File } from 'buffer';
|
|
@@ -329,9 +329,9 @@ async function login(appCode, options) {
|
|
|
329
329
|
const appConfig = getAppConfig(appCode);
|
|
330
330
|
if (!appConfig) {
|
|
331
331
|
spinner.fail(`App not configured: ${appCode}`);
|
|
332
|
-
console.error(
|
|
332
|
+
console.error(chalk4.red(`
|
|
333
333
|
\u274C App not found: ${appCode}`));
|
|
334
|
-
console.log(
|
|
334
|
+
console.log(chalk4.yellow(`Initialize it first: amaster init --app-code ${appCode} --url <url>`));
|
|
335
335
|
process.exit(1);
|
|
336
336
|
}
|
|
337
337
|
let username = options.username;
|
|
@@ -380,7 +380,7 @@ async function login(appCode, options) {
|
|
|
380
380
|
const result = await client.auth.login(loginParams);
|
|
381
381
|
if (result.error) {
|
|
382
382
|
spinner.fail("Login failed");
|
|
383
|
-
console.error(
|
|
383
|
+
console.error(chalk4.red(result.error.message));
|
|
384
384
|
process.exit(1);
|
|
385
385
|
}
|
|
386
386
|
const loginData = result.data;
|
|
@@ -414,16 +414,16 @@ async function login(appCode, options) {
|
|
|
414
414
|
format: options.format,
|
|
415
415
|
pretty: () => {
|
|
416
416
|
console.log(
|
|
417
|
-
|
|
417
|
+
chalk4.green(
|
|
418
418
|
`
|
|
419
419
|
Welcome, ${loginData.user?.displayName || loginData.user?.email || loginData.user?.username || email}!`
|
|
420
420
|
)
|
|
421
421
|
);
|
|
422
|
-
console.log(
|
|
423
|
-
console.log(
|
|
422
|
+
console.log(chalk4.gray(`App: ${appCode}`));
|
|
423
|
+
console.log(chalk4.gray(`URL: ${appConfig.baseURL}`));
|
|
424
424
|
if (expiresAt) {
|
|
425
425
|
const expires = new Date(expiresAt);
|
|
426
|
-
console.log(
|
|
426
|
+
console.log(chalk4.gray(`Session expires: ${expires.toLocaleString()}`));
|
|
427
427
|
}
|
|
428
428
|
}
|
|
429
429
|
}
|
|
@@ -459,7 +459,7 @@ async function logout(appCode, options = {}) {
|
|
|
459
459
|
{
|
|
460
460
|
format: options.format,
|
|
461
461
|
pretty: () => {
|
|
462
|
-
console.log(
|
|
462
|
+
console.log(chalk4.green(`Logged out from ${appCode}`));
|
|
463
463
|
}
|
|
464
464
|
}
|
|
465
465
|
);
|
|
@@ -475,7 +475,7 @@ async function getMe(getClient, options = {}) {
|
|
|
475
475
|
const result = await client.auth.getMe();
|
|
476
476
|
if (result.error) {
|
|
477
477
|
spinner.fail("Failed to fetch user info");
|
|
478
|
-
console.error(
|
|
478
|
+
console.error(chalk4.red(result.error.message));
|
|
479
479
|
process.exit(1);
|
|
480
480
|
}
|
|
481
481
|
spinner.succeed("User info retrieved");
|
|
@@ -483,11 +483,11 @@ async function getMe(getClient, options = {}) {
|
|
|
483
483
|
renderOutput(user, {
|
|
484
484
|
format: options.format,
|
|
485
485
|
pretty: () => {
|
|
486
|
-
console.log(
|
|
487
|
-
console.log(` ${
|
|
488
|
-
console.log(` ${
|
|
489
|
-
console.log(` ${
|
|
490
|
-
console.log(` ${
|
|
486
|
+
console.log(chalk4.blue("\n\u{1F464} User Profile\n"));
|
|
487
|
+
console.log(` ${chalk4.bold("UID:")} ${user?.uid}`);
|
|
488
|
+
console.log(` ${chalk4.bold("Email:")} ${user?.email}`);
|
|
489
|
+
console.log(` ${chalk4.bold("Name:")} ${user?.displayName || user?.username || "N/A"}`);
|
|
490
|
+
console.log(` ${chalk4.bold("Status:")} ${user?.isActive ? "Active" : "Inactive"}`);
|
|
491
491
|
}
|
|
492
492
|
});
|
|
493
493
|
} catch (error) {
|
|
@@ -617,7 +617,7 @@ function exitWithCommandError(spinner, failureMessage, error) {
|
|
|
617
617
|
spinner.fail(failureMessage);
|
|
618
618
|
const details = error instanceof Error ? error.message : String(error);
|
|
619
619
|
if (details) {
|
|
620
|
-
console.error(
|
|
620
|
+
console.error(chalk4.red(details));
|
|
621
621
|
}
|
|
622
622
|
process.exit(1);
|
|
623
623
|
}
|
|
@@ -682,7 +682,7 @@ async function listEntities(client, options) {
|
|
|
682
682
|
});
|
|
683
683
|
if (result.error) {
|
|
684
684
|
spinner.fail("Failed to fetch entities");
|
|
685
|
-
console.error(
|
|
685
|
+
console.error(chalk4.red(result.error.message));
|
|
686
686
|
process.exit(1);
|
|
687
687
|
}
|
|
688
688
|
spinner.stop();
|
|
@@ -702,12 +702,12 @@ async function listEntities(client, options) {
|
|
|
702
702
|
renderOutput(result.data, {
|
|
703
703
|
format: options.format,
|
|
704
704
|
pretty: () => {
|
|
705
|
-
console.log(
|
|
705
|
+
console.log(chalk4.blue(`
|
|
706
706
|
\u{1F4E6} ${options.entity} in ${options.namespace}`));
|
|
707
|
-
console.log(
|
|
707
|
+
console.log(chalk4.gray(`\u5171 ${total} \u6761\u8BB0\u5F55:
|
|
708
708
|
`));
|
|
709
709
|
if (items.length === 0) {
|
|
710
|
-
console.log(
|
|
710
|
+
console.log(chalk4.gray(" \u6682\u65E0\u6570\u636E"));
|
|
711
711
|
return;
|
|
712
712
|
}
|
|
713
713
|
const firstItem = items[0];
|
|
@@ -727,7 +727,7 @@ async function listEntities(client, options) {
|
|
|
727
727
|
});
|
|
728
728
|
const headerLine = keys.map((key) => {
|
|
729
729
|
const width = widths[key] ?? 0;
|
|
730
|
-
return
|
|
730
|
+
return chalk4.bold(key.slice(0, width).padEnd(width));
|
|
731
731
|
}).join("\u2502");
|
|
732
732
|
console.log(" " + headerLine);
|
|
733
733
|
console.log(" " + keys.map((key) => "\u2500".repeat(widths[key] ?? 0)).join("\u253C"));
|
|
@@ -743,7 +743,7 @@ async function listEntities(client, options) {
|
|
|
743
743
|
}
|
|
744
744
|
console.log();
|
|
745
745
|
if (items.length < total) {
|
|
746
|
-
console.log(
|
|
746
|
+
console.log(chalk4.gray(` ... \u8FD8\u6709 ${total - items.length} \u6761\u8BB0\u5F55`));
|
|
747
747
|
}
|
|
748
748
|
}
|
|
749
749
|
});
|
|
@@ -758,14 +758,14 @@ async function getEntity(client, options) {
|
|
|
758
758
|
const result = await entityClient.get(options.namespace, options.entity, options.id);
|
|
759
759
|
if (result.error) {
|
|
760
760
|
spinner.fail("Failed to fetch entity");
|
|
761
|
-
console.error(
|
|
761
|
+
console.error(chalk4.red(result.error.message));
|
|
762
762
|
process.exit(1);
|
|
763
763
|
}
|
|
764
764
|
spinner.succeed("Entity retrieved");
|
|
765
765
|
renderOutput(result.data, {
|
|
766
766
|
format: options.format,
|
|
767
767
|
pretty: () => {
|
|
768
|
-
console.log(
|
|
768
|
+
console.log(chalk4.blue(`
|
|
769
769
|
\u{1F4C4} ${options.entity}
|
|
770
770
|
`));
|
|
771
771
|
console.log(JSON.stringify(result.data, null, 2));
|
|
@@ -783,14 +783,14 @@ async function createEntity(client, options) {
|
|
|
783
783
|
const result = await entityClient.create(options.namespace, options.entity, data);
|
|
784
784
|
if (result.error) {
|
|
785
785
|
spinner.fail("Failed to create entity");
|
|
786
|
-
console.error(
|
|
786
|
+
console.error(chalk4.red(result.error.message));
|
|
787
787
|
process.exit(1);
|
|
788
788
|
}
|
|
789
789
|
spinner.succeed("Entity created");
|
|
790
790
|
renderOutput(result.data, {
|
|
791
791
|
format: options.format,
|
|
792
792
|
pretty: () => {
|
|
793
|
-
console.log(
|
|
793
|
+
console.log(chalk4.green("\nCreated entity:"));
|
|
794
794
|
console.log(JSON.stringify(result.data, null, 2));
|
|
795
795
|
}
|
|
796
796
|
});
|
|
@@ -806,14 +806,14 @@ async function updateEntity(client, options) {
|
|
|
806
806
|
const result = await entityClient.update(options.namespace, options.entity, options.id, data);
|
|
807
807
|
if (result.error) {
|
|
808
808
|
spinner.fail("Failed to update entity");
|
|
809
|
-
console.error(
|
|
809
|
+
console.error(chalk4.red(result.error.message));
|
|
810
810
|
process.exit(1);
|
|
811
811
|
}
|
|
812
812
|
spinner.succeed("Entity updated");
|
|
813
813
|
renderOutput(result.data, {
|
|
814
814
|
format: options.format,
|
|
815
815
|
pretty: () => {
|
|
816
|
-
console.log(
|
|
816
|
+
console.log(chalk4.green("\nUpdated entity:"));
|
|
817
817
|
console.log(JSON.stringify(result.data, null, 2));
|
|
818
818
|
}
|
|
819
819
|
});
|
|
@@ -828,7 +828,7 @@ async function deleteEntity(client, options) {
|
|
|
828
828
|
const result = await entityClient.delete(options.namespace, options.entity, options.id);
|
|
829
829
|
if (result.error) {
|
|
830
830
|
spinner.fail("Failed to delete entity");
|
|
831
|
-
console.error(
|
|
831
|
+
console.error(chalk4.red(result.error.message));
|
|
832
832
|
process.exit(1);
|
|
833
833
|
}
|
|
834
834
|
spinner.succeed("Entity deleted");
|
|
@@ -842,7 +842,7 @@ async function deleteEntity(client, options) {
|
|
|
842
842
|
{
|
|
843
843
|
format: options.format,
|
|
844
844
|
pretty: () => {
|
|
845
|
-
console.log(
|
|
845
|
+
console.log(chalk4.green(`
|
|
846
846
|
Deleted ${options.entity} with ID: ${options.id}`));
|
|
847
847
|
}
|
|
848
848
|
}
|
|
@@ -859,14 +859,14 @@ async function listEntityOptions(client, options) {
|
|
|
859
859
|
const result = await entityClient.options(options.namespace, options.entity, fields);
|
|
860
860
|
if (result.error) {
|
|
861
861
|
spinner.fail("Failed to fetch entity options");
|
|
862
|
-
console.error(
|
|
862
|
+
console.error(chalk4.red(result.error.message));
|
|
863
863
|
process.exit(1);
|
|
864
864
|
}
|
|
865
865
|
spinner.succeed(`Found ${result.data?.length || 0} options`);
|
|
866
866
|
renderOutput(result.data || [], {
|
|
867
867
|
format: options.format,
|
|
868
868
|
pretty: () => {
|
|
869
|
-
console.log(
|
|
869
|
+
console.log(chalk4.blue(`
|
|
870
870
|
\u{1F9FE} ${options.entity} options
|
|
871
871
|
`));
|
|
872
872
|
console.log(JSON.stringify(result.data || [], null, 2));
|
|
@@ -889,14 +889,14 @@ async function bulkUpdateEntities(client, options) {
|
|
|
889
889
|
const result = await entityClient.bulkUpdate(options.namespace, options.entity, items);
|
|
890
890
|
if (result.error) {
|
|
891
891
|
spinner.fail("Failed to bulk update entities");
|
|
892
|
-
console.error(
|
|
892
|
+
console.error(chalk4.red(result.error.message));
|
|
893
893
|
process.exit(1);
|
|
894
894
|
}
|
|
895
895
|
spinner.succeed(`Updated ${items.length} entities`);
|
|
896
896
|
renderOutput(result.data, {
|
|
897
897
|
format: options.format,
|
|
898
898
|
pretty: () => {
|
|
899
|
-
console.log(
|
|
899
|
+
console.log(chalk4.green(`
|
|
900
900
|
Bulk updated ${items.length} ${options.entity} records:`));
|
|
901
901
|
console.log(JSON.stringify(result.data, null, 2));
|
|
902
902
|
}
|
|
@@ -913,7 +913,7 @@ async function bulkDeleteEntities(client, options) {
|
|
|
913
913
|
const result = await entityClient.bulkDelete(options.namespace, options.entity, ids);
|
|
914
914
|
if (result.error) {
|
|
915
915
|
spinner.fail("Failed to bulk delete entities");
|
|
916
|
-
console.error(
|
|
916
|
+
console.error(chalk4.red(result.error.message));
|
|
917
917
|
process.exit(1);
|
|
918
918
|
}
|
|
919
919
|
spinner.succeed(`Deleted ${ids.length} entities`);
|
|
@@ -928,7 +928,7 @@ async function bulkDeleteEntities(client, options) {
|
|
|
928
928
|
{
|
|
929
929
|
format: options.format,
|
|
930
930
|
pretty: () => {
|
|
931
|
-
console.log(
|
|
931
|
+
console.log(chalk4.green(`
|
|
932
932
|
Deleted ${ids.length} ${options.entity} records.`));
|
|
933
933
|
}
|
|
934
934
|
}
|
|
@@ -937,10 +937,165 @@ Deleted ${ids.length} ${options.entity} records.`));
|
|
|
937
937
|
exitWithCommandError(spinner, "Failed to bulk delete entities", error);
|
|
938
938
|
}
|
|
939
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 exitWithCommandError2(spinner, failureMessage, error) {
|
|
951
|
+
spinner.fail(failureMessage);
|
|
952
|
+
const details = error instanceof Error ? error.message : String(error);
|
|
953
|
+
if (details) {
|
|
954
|
+
console.error(chalk4.red(details));
|
|
955
|
+
}
|
|
956
|
+
process.exit(1);
|
|
957
|
+
}
|
|
958
|
+
function parseTableNamesInput(input) {
|
|
959
|
+
if (!input) {
|
|
960
|
+
return void 0;
|
|
961
|
+
}
|
|
962
|
+
const source = resolveInputSource2(input).trim();
|
|
963
|
+
if (!source) {
|
|
964
|
+
return void 0;
|
|
965
|
+
}
|
|
966
|
+
if (source.startsWith("[")) {
|
|
967
|
+
let parsed;
|
|
968
|
+
try {
|
|
969
|
+
parsed = JSON.parse(source);
|
|
970
|
+
} catch (error) {
|
|
971
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
972
|
+
throw new Error(`Invalid table list: ${reason}`);
|
|
973
|
+
}
|
|
974
|
+
if (!Array.isArray(parsed)) {
|
|
975
|
+
throw new Error("Table list must be a JSON array.");
|
|
976
|
+
}
|
|
977
|
+
return parsed.map((value, index) => {
|
|
978
|
+
if (typeof value !== "string") {
|
|
979
|
+
throw new Error(`Table name at index ${index} must be a string.`);
|
|
980
|
+
}
|
|
981
|
+
return value;
|
|
982
|
+
});
|
|
983
|
+
}
|
|
984
|
+
const values = source.split(/[,\n]/).map((entry) => entry.trim()).filter(Boolean);
|
|
985
|
+
return values.length > 0 ? values : void 0;
|
|
986
|
+
}
|
|
987
|
+
async function listDatasources(client, options = {}) {
|
|
988
|
+
const spinner = createSpinner("Fetching datasources...", options.format);
|
|
989
|
+
try {
|
|
990
|
+
const result = await client.http.request({
|
|
991
|
+
url: "/api/entity/source/list_with_models",
|
|
992
|
+
method: "GET"
|
|
993
|
+
});
|
|
994
|
+
if (result.error) {
|
|
995
|
+
spinner.fail("Failed to fetch datasources");
|
|
996
|
+
console.error(chalk4.red(result.error.message));
|
|
997
|
+
process.exit(1);
|
|
998
|
+
}
|
|
999
|
+
const datasources = result.data || [];
|
|
1000
|
+
spinner.succeed(`Found ${datasources.length} datasource${datasources.length === 1 ? "" : "s"}`);
|
|
1001
|
+
renderOutput(datasources, {
|
|
1002
|
+
format: options.format,
|
|
1003
|
+
tableRows: datasources.map((source) => ({
|
|
1004
|
+
sourceId: source.sourceId,
|
|
1005
|
+
name: source.name,
|
|
1006
|
+
systemBuilt: source.systemBuilt,
|
|
1007
|
+
synchronizeMode: source.synchronizeMode,
|
|
1008
|
+
modelCount: source.models?.length || 0
|
|
1009
|
+
})),
|
|
1010
|
+
csvRows: datasources.map((source) => ({
|
|
1011
|
+
sourceId: source.sourceId,
|
|
1012
|
+
name: source.name,
|
|
1013
|
+
systemBuilt: source.systemBuilt,
|
|
1014
|
+
synchronizeMode: source.synchronizeMode,
|
|
1015
|
+
modelCount: source.models?.length || 0
|
|
1016
|
+
})),
|
|
1017
|
+
ndjsonItems: datasources,
|
|
1018
|
+
pretty: () => {
|
|
1019
|
+
console.log(chalk4.blue("\nData Sources\n"));
|
|
1020
|
+
if (datasources.length === 0) {
|
|
1021
|
+
console.log(chalk4.gray("No datasources found."));
|
|
1022
|
+
return;
|
|
1023
|
+
}
|
|
1024
|
+
for (const source of datasources) {
|
|
1025
|
+
console.log(`${chalk4.green("\u2022")} ${chalk4.bold(source.name)} ${chalk4.gray(`(${source.sourceId})`)}`);
|
|
1026
|
+
console.log(` ${chalk4.gray("System Built:")} ${source.systemBuilt}`);
|
|
1027
|
+
console.log(` ${chalk4.gray("Sync Mode:")} ${source.synchronizeMode}`);
|
|
1028
|
+
if (!source.models || source.models.length === 0) {
|
|
1029
|
+
console.log(` ${chalk4.gray("Models:")} none`);
|
|
1030
|
+
continue;
|
|
1031
|
+
}
|
|
1032
|
+
console.log(` ${chalk4.gray("Models:")}`);
|
|
1033
|
+
for (const model of source.models) {
|
|
1034
|
+
const suffix = model.description ? ` ${chalk4.gray(`- ${model.description}`)}` : "";
|
|
1035
|
+
console.log(` - ${chalk4.bold(model.tableName)} ${chalk4.gray(`(${model.modelId})`)}${suffix}`);
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
});
|
|
1040
|
+
} catch (error) {
|
|
1041
|
+
exitWithCommandError2(spinner, "Failed to fetch datasources", error);
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
async function getTableSchema(client, options) {
|
|
1045
|
+
const spinner = createSpinner(`Fetching table schema for ${options.sourceId}...`, options.format);
|
|
1046
|
+
try {
|
|
1047
|
+
const tableNames = parseTableNamesInput(options.tables);
|
|
1048
|
+
const search = new URLSearchParams();
|
|
1049
|
+
if (tableNames && tableNames.length > 0) {
|
|
1050
|
+
search.set("tableNames", tableNames.join(","));
|
|
1051
|
+
}
|
|
1052
|
+
const query = search.toString();
|
|
1053
|
+
const url = `/api/entity/source/${encodeURIComponent(options.sourceId)}/create_table_statements${query ? `?${query}` : ""}`;
|
|
1054
|
+
const result = await client.http.request({
|
|
1055
|
+
url,
|
|
1056
|
+
method: "GET"
|
|
1057
|
+
});
|
|
1058
|
+
if (result.error) {
|
|
1059
|
+
spinner.fail("Failed to fetch table schema");
|
|
1060
|
+
console.error(chalk4.red(result.error.message));
|
|
1061
|
+
process.exit(1);
|
|
1062
|
+
}
|
|
1063
|
+
const tables = result.data || [];
|
|
1064
|
+
spinner.succeed(`Fetched schema for ${tables.length} table${tables.length === 1 ? "" : "s"}`);
|
|
1065
|
+
renderOutput(tables, {
|
|
1066
|
+
format: options.format,
|
|
1067
|
+
tableRows: tables.map((table) => ({
|
|
1068
|
+
tableName: table.tableName,
|
|
1069
|
+
createTableSql: table.createTableSql
|
|
1070
|
+
})),
|
|
1071
|
+
csvRows: tables.map((table) => ({
|
|
1072
|
+
tableName: table.tableName,
|
|
1073
|
+
createTableSql: table.createTableSql
|
|
1074
|
+
})),
|
|
1075
|
+
ndjsonItems: tables,
|
|
1076
|
+
pretty: () => {
|
|
1077
|
+
console.log(chalk4.blue(`
|
|
1078
|
+
Table Schemas: ${options.sourceId}
|
|
1079
|
+
`));
|
|
1080
|
+
if (tables.length === 0) {
|
|
1081
|
+
console.log(chalk4.gray("No tables found."));
|
|
1082
|
+
return;
|
|
1083
|
+
}
|
|
1084
|
+
for (const table of tables) {
|
|
1085
|
+
console.log(chalk4.green(table.tableName));
|
|
1086
|
+
console.log(table.createTableSql);
|
|
1087
|
+
console.log();
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
});
|
|
1091
|
+
} catch (error) {
|
|
1092
|
+
exitWithCommandError2(spinner, "Failed to fetch table schema", error);
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
940
1095
|
function isPlainObject3(value) {
|
|
941
1096
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
942
1097
|
}
|
|
943
|
-
function
|
|
1098
|
+
function resolveInputSource3(input) {
|
|
944
1099
|
if (!input.startsWith("@")) {
|
|
945
1100
|
return input;
|
|
946
1101
|
}
|
|
@@ -951,7 +1106,7 @@ function resolveInputSource2(input) {
|
|
|
951
1106
|
return readFileSync(filePath, "utf8");
|
|
952
1107
|
}
|
|
953
1108
|
function parseJsonInput2(input, label) {
|
|
954
|
-
const source =
|
|
1109
|
+
const source = resolveInputSource3(input).trim();
|
|
955
1110
|
if (!source) {
|
|
956
1111
|
throw new Error(`${label} is required.`);
|
|
957
1112
|
}
|
|
@@ -992,11 +1147,11 @@ function loadOptionalJsonObjectInput2(input, label) {
|
|
|
992
1147
|
}
|
|
993
1148
|
return value;
|
|
994
1149
|
}
|
|
995
|
-
function
|
|
1150
|
+
function exitWithCommandError3(spinner, failureMessage, error) {
|
|
996
1151
|
spinner.fail(failureMessage);
|
|
997
1152
|
const details = error instanceof Error ? error.message : String(error);
|
|
998
1153
|
if (details) {
|
|
999
|
-
console.error(
|
|
1154
|
+
console.error(chalk4.red(details));
|
|
1000
1155
|
}
|
|
1001
1156
|
process.exit(1);
|
|
1002
1157
|
}
|
|
@@ -1005,7 +1160,7 @@ function extractClientErrorMessage(error) {
|
|
|
1005
1160
|
}
|
|
1006
1161
|
function exitWithClientError(spinner, failureMessage, error, diagnosticMessage) {
|
|
1007
1162
|
spinner.fail(failureMessage);
|
|
1008
|
-
console.error(
|
|
1163
|
+
console.error(chalk4.red(diagnosticMessage || extractClientErrorMessage(error)));
|
|
1009
1164
|
process.exit(1);
|
|
1010
1165
|
}
|
|
1011
1166
|
function inspectStartEventFormConfiguration(bpmnXml) {
|
|
@@ -1186,7 +1341,7 @@ async function listProcesses(client, options = {}) {
|
|
|
1186
1341
|
const result = await bpmClient.getProcessDefinitions(params);
|
|
1187
1342
|
if (result.error) {
|
|
1188
1343
|
spinner.fail("Failed to fetch processes");
|
|
1189
|
-
console.error(
|
|
1344
|
+
console.error(chalk4.red(result.error.message));
|
|
1190
1345
|
process.exit(1);
|
|
1191
1346
|
}
|
|
1192
1347
|
spinner.succeed(`Found ${result.data?.length || 0} process definitions`);
|
|
@@ -1194,19 +1349,19 @@ async function listProcesses(client, options = {}) {
|
|
|
1194
1349
|
renderOutput(processes, {
|
|
1195
1350
|
format: options.format,
|
|
1196
1351
|
pretty: () => {
|
|
1197
|
-
console.log(
|
|
1352
|
+
console.log(chalk4.blue("\n\u{1F4CA} Process Definitions\n"));
|
|
1198
1353
|
for (const proc of processes) {
|
|
1199
|
-
console.log(` ${
|
|
1200
|
-
console.log(` ${
|
|
1201
|
-
console.log(` ${
|
|
1202
|
-
console.log(` ${
|
|
1203
|
-
console.log(` ${
|
|
1354
|
+
console.log(` ${chalk4.green("\u2022")} ${chalk4.bold(proc.key)}`);
|
|
1355
|
+
console.log(` ${chalk4.gray("ID:")} ${proc.id || "N/A"}`);
|
|
1356
|
+
console.log(` ${chalk4.gray("Name:")} ${proc.name || "N/A"}`);
|
|
1357
|
+
console.log(` ${chalk4.gray("Version:")} ${proc.version || "N/A"}`);
|
|
1358
|
+
console.log(` ${chalk4.gray("Suspended:")} ${proc.suspended ? "Yes" : "No"}`);
|
|
1204
1359
|
console.log();
|
|
1205
1360
|
}
|
|
1206
1361
|
}
|
|
1207
1362
|
});
|
|
1208
1363
|
} catch (error) {
|
|
1209
|
-
|
|
1364
|
+
exitWithCommandError3(spinner, "Failed to fetch processes", error);
|
|
1210
1365
|
}
|
|
1211
1366
|
}
|
|
1212
1367
|
async function getProcessXml(client, options) {
|
|
@@ -1216,21 +1371,21 @@ async function getProcessXml(client, options) {
|
|
|
1216
1371
|
const result = await bpmClient.getProcessXml(options.key);
|
|
1217
1372
|
if (result.error) {
|
|
1218
1373
|
spinner.fail("Failed to fetch process XML");
|
|
1219
|
-
console.error(
|
|
1374
|
+
console.error(chalk4.red(result.error.message));
|
|
1220
1375
|
process.exit(1);
|
|
1221
1376
|
}
|
|
1222
1377
|
spinner.succeed("Process XML retrieved");
|
|
1223
1378
|
renderOutput(result.data, {
|
|
1224
1379
|
format: options.format,
|
|
1225
1380
|
pretty: () => {
|
|
1226
|
-
console.log(
|
|
1381
|
+
console.log(chalk4.blue(`
|
|
1227
1382
|
\u{1F4C4} BPMN XML: ${options.key}
|
|
1228
1383
|
`));
|
|
1229
1384
|
console.log(result.data?.bpmn20Xml || "");
|
|
1230
1385
|
}
|
|
1231
1386
|
});
|
|
1232
1387
|
} catch (error) {
|
|
1233
|
-
|
|
1388
|
+
exitWithCommandError3(spinner, "Failed to fetch process XML", error);
|
|
1234
1389
|
}
|
|
1235
1390
|
}
|
|
1236
1391
|
async function startProcess(client, options) {
|
|
@@ -1241,22 +1396,22 @@ async function startProcess(client, options) {
|
|
|
1241
1396
|
const result = await bpmClient.startProcess(options.key, variables);
|
|
1242
1397
|
if (result.error) {
|
|
1243
1398
|
spinner.fail("Failed to start process");
|
|
1244
|
-
console.error(
|
|
1399
|
+
console.error(chalk4.red(result.error.message));
|
|
1245
1400
|
process.exit(1);
|
|
1246
1401
|
}
|
|
1247
1402
|
spinner.succeed("Process started");
|
|
1248
1403
|
renderOutput(result.data, {
|
|
1249
1404
|
format: options.format,
|
|
1250
1405
|
pretty: () => {
|
|
1251
|
-
console.log(
|
|
1252
|
-
console.log(` ${
|
|
1253
|
-
console.log(` ${
|
|
1254
|
-
console.log(` ${
|
|
1255
|
-
console.log(` ${
|
|
1406
|
+
console.log(chalk4.green("\nProcess Instance:"));
|
|
1407
|
+
console.log(` ${chalk4.bold("ID:")} ${result.data?.id}`);
|
|
1408
|
+
console.log(` ${chalk4.bold("Definition ID:")} ${result.data?.definitionId}`);
|
|
1409
|
+
console.log(` ${chalk4.bold("Business Key:")} ${result.data?.businessKey || "N/A"}`);
|
|
1410
|
+
console.log(` ${chalk4.bold("Status:")} ${result.data?.suspended ? "Suspended" : "Active"}`);
|
|
1256
1411
|
}
|
|
1257
1412
|
});
|
|
1258
1413
|
} catch (error) {
|
|
1259
|
-
|
|
1414
|
+
exitWithCommandError3(spinner, "Failed to start process", error);
|
|
1260
1415
|
}
|
|
1261
1416
|
}
|
|
1262
1417
|
async function listProcessInstances(client, options = {}) {
|
|
@@ -1267,7 +1422,7 @@ async function listProcessInstances(client, options = {}) {
|
|
|
1267
1422
|
const result = await bpmClient.getProcessInstances(params);
|
|
1268
1423
|
if (result.error) {
|
|
1269
1424
|
spinner.fail("Failed to fetch process instances");
|
|
1270
|
-
console.error(
|
|
1425
|
+
console.error(chalk4.red(result.error.message));
|
|
1271
1426
|
process.exit(1);
|
|
1272
1427
|
}
|
|
1273
1428
|
spinner.succeed(`Found ${result.data?.length || 0} process instances`);
|
|
@@ -1275,20 +1430,20 @@ async function listProcessInstances(client, options = {}) {
|
|
|
1275
1430
|
renderOutput(instances, {
|
|
1276
1431
|
format: options.format,
|
|
1277
1432
|
pretty: () => {
|
|
1278
|
-
console.log(
|
|
1433
|
+
console.log(chalk4.blue("\n\u{1F504} Process Instances\n"));
|
|
1279
1434
|
for (const instance of instances) {
|
|
1280
|
-
console.log(` ${
|
|
1281
|
-
console.log(` ${
|
|
1282
|
-
console.log(` ${
|
|
1435
|
+
console.log(` ${chalk4.green("\u2022")} ${chalk4.bold(instance.id)}`);
|
|
1436
|
+
console.log(` ${chalk4.gray("Definition:")} ${instance.definitionId || "N/A"}`);
|
|
1437
|
+
console.log(` ${chalk4.gray("Business Key:")} ${instance.businessKey || "N/A"}`);
|
|
1283
1438
|
console.log(
|
|
1284
|
-
` ${
|
|
1439
|
+
` ${chalk4.gray("Status:")} ${instance.ended ? "Ended" : instance.suspended ? "Suspended" : "Active"}`
|
|
1285
1440
|
);
|
|
1286
1441
|
console.log();
|
|
1287
1442
|
}
|
|
1288
1443
|
}
|
|
1289
1444
|
});
|
|
1290
1445
|
} catch (error) {
|
|
1291
|
-
|
|
1446
|
+
exitWithCommandError3(spinner, "Failed to fetch process instances", error);
|
|
1292
1447
|
}
|
|
1293
1448
|
}
|
|
1294
1449
|
async function getProcessInstance(client, options) {
|
|
@@ -1298,19 +1453,19 @@ async function getProcessInstance(client, options) {
|
|
|
1298
1453
|
const result = await bpmClient.getProcessInstance(options.id);
|
|
1299
1454
|
if (result.error) {
|
|
1300
1455
|
spinner.fail("Failed to fetch process instance");
|
|
1301
|
-
console.error(
|
|
1456
|
+
console.error(chalk4.red(result.error.message));
|
|
1302
1457
|
process.exit(1);
|
|
1303
1458
|
}
|
|
1304
1459
|
spinner.succeed("Process instance retrieved");
|
|
1305
1460
|
renderOutput(result.data, {
|
|
1306
1461
|
format: options.format,
|
|
1307
1462
|
pretty: () => {
|
|
1308
|
-
console.log(
|
|
1463
|
+
console.log(chalk4.blue("\n\u{1F4CA} Process Instance\n"));
|
|
1309
1464
|
console.log(JSON.stringify(result.data, null, 2));
|
|
1310
1465
|
}
|
|
1311
1466
|
});
|
|
1312
1467
|
} catch (error) {
|
|
1313
|
-
|
|
1468
|
+
exitWithCommandError3(spinner, "Failed to fetch process instance", error);
|
|
1314
1469
|
}
|
|
1315
1470
|
}
|
|
1316
1471
|
async function getActivityInstanceTree(client, options) {
|
|
@@ -1320,19 +1475,19 @@ async function getActivityInstanceTree(client, options) {
|
|
|
1320
1475
|
const result = await bpmClient.getActivityInstanceTree(options.id);
|
|
1321
1476
|
if (result.error) {
|
|
1322
1477
|
spinner.fail("Failed to fetch activity instance tree");
|
|
1323
|
-
console.error(
|
|
1478
|
+
console.error(chalk4.red(result.error.message));
|
|
1324
1479
|
process.exit(1);
|
|
1325
1480
|
}
|
|
1326
1481
|
spinner.succeed("Activity instance tree retrieved");
|
|
1327
1482
|
renderOutput(result.data, {
|
|
1328
1483
|
format: options.format,
|
|
1329
1484
|
pretty: () => {
|
|
1330
|
-
console.log(
|
|
1485
|
+
console.log(chalk4.blue("\n\u{1F333} Activity Instance Tree\n"));
|
|
1331
1486
|
console.log(JSON.stringify(result.data, null, 2));
|
|
1332
1487
|
}
|
|
1333
1488
|
});
|
|
1334
1489
|
} catch (error) {
|
|
1335
|
-
|
|
1490
|
+
exitWithCommandError3(spinner, "Failed to fetch activity instance tree", error);
|
|
1336
1491
|
}
|
|
1337
1492
|
}
|
|
1338
1493
|
async function getActiveActivities(client, options) {
|
|
@@ -1342,7 +1497,7 @@ async function getActiveActivities(client, options) {
|
|
|
1342
1497
|
const result = await bpmClient.getActiveActivities(options.id);
|
|
1343
1498
|
if (result.error) {
|
|
1344
1499
|
spinner.fail("Failed to fetch active activities");
|
|
1345
|
-
console.error(
|
|
1500
|
+
console.error(chalk4.red(result.error.message));
|
|
1346
1501
|
process.exit(1);
|
|
1347
1502
|
}
|
|
1348
1503
|
const activities = Array.isArray(result.data) ? result.data : [];
|
|
@@ -1350,12 +1505,12 @@ async function getActiveActivities(client, options) {
|
|
|
1350
1505
|
renderOutput(result.data, {
|
|
1351
1506
|
format: options.format,
|
|
1352
1507
|
pretty: () => {
|
|
1353
|
-
console.log(
|
|
1508
|
+
console.log(chalk4.blue("\n\u26A1 Active Activities\n"));
|
|
1354
1509
|
console.log(JSON.stringify(result.data, null, 2));
|
|
1355
1510
|
}
|
|
1356
1511
|
});
|
|
1357
1512
|
} catch (error) {
|
|
1358
|
-
|
|
1513
|
+
exitWithCommandError3(spinner, "Failed to fetch active activities", error);
|
|
1359
1514
|
}
|
|
1360
1515
|
}
|
|
1361
1516
|
async function getRuntimeVariables(client, options) {
|
|
@@ -1365,19 +1520,19 @@ async function getRuntimeVariables(client, options) {
|
|
|
1365
1520
|
const result = await bpmClient.getRuntimeVariables(options.id);
|
|
1366
1521
|
if (result.error) {
|
|
1367
1522
|
spinner.fail("Failed to fetch runtime variables");
|
|
1368
|
-
console.error(
|
|
1523
|
+
console.error(chalk4.red(result.error.message));
|
|
1369
1524
|
process.exit(1);
|
|
1370
1525
|
}
|
|
1371
1526
|
spinner.succeed("Runtime variables retrieved");
|
|
1372
1527
|
renderOutput(result.data, {
|
|
1373
1528
|
format: options.format,
|
|
1374
1529
|
pretty: () => {
|
|
1375
|
-
console.log(
|
|
1530
|
+
console.log(chalk4.blue("\n\u{1F9EE} Runtime Variables\n"));
|
|
1376
1531
|
console.log(JSON.stringify(result.data, null, 2));
|
|
1377
1532
|
}
|
|
1378
1533
|
});
|
|
1379
1534
|
} catch (error) {
|
|
1380
|
-
|
|
1535
|
+
exitWithCommandError3(spinner, "Failed to fetch runtime variables", error);
|
|
1381
1536
|
}
|
|
1382
1537
|
}
|
|
1383
1538
|
async function getProcessVariables(client, options) {
|
|
@@ -1390,19 +1545,19 @@ async function getProcessVariables(client, options) {
|
|
|
1390
1545
|
});
|
|
1391
1546
|
if (result.error) {
|
|
1392
1547
|
spinner.fail("Failed to fetch process variables");
|
|
1393
|
-
console.error(
|
|
1548
|
+
console.error(chalk4.red(result.error.message));
|
|
1394
1549
|
process.exit(1);
|
|
1395
1550
|
}
|
|
1396
1551
|
spinner.succeed(`Found ${result.data?.length || 0} variables`);
|
|
1397
1552
|
renderOutput(result.data || [], {
|
|
1398
1553
|
format: options.format,
|
|
1399
1554
|
pretty: () => {
|
|
1400
|
-
console.log(
|
|
1555
|
+
console.log(chalk4.blue("\n\u{1F9FE} Process Variables\n"));
|
|
1401
1556
|
console.log(JSON.stringify(result.data || [], null, 2));
|
|
1402
1557
|
}
|
|
1403
1558
|
});
|
|
1404
1559
|
} catch (error) {
|
|
1405
|
-
|
|
1560
|
+
exitWithCommandError3(spinner, "Failed to fetch process variables", error);
|
|
1406
1561
|
}
|
|
1407
1562
|
}
|
|
1408
1563
|
async function deleteProcessInstance(client, options) {
|
|
@@ -1414,7 +1569,7 @@ async function deleteProcessInstance(client, options) {
|
|
|
1414
1569
|
});
|
|
1415
1570
|
if (result.error) {
|
|
1416
1571
|
spinner.fail("Failed to delete process instance");
|
|
1417
|
-
console.error(
|
|
1572
|
+
console.error(chalk4.red(result.error.message));
|
|
1418
1573
|
process.exit(1);
|
|
1419
1574
|
}
|
|
1420
1575
|
spinner.succeed("Process instance deleted");
|
|
@@ -1427,12 +1582,12 @@ async function deleteProcessInstance(client, options) {
|
|
|
1427
1582
|
{
|
|
1428
1583
|
format: options.format,
|
|
1429
1584
|
pretty: () => {
|
|
1430
|
-
console.log(
|
|
1585
|
+
console.log(chalk4.green(`Deleted process instance: ${options.id}`));
|
|
1431
1586
|
}
|
|
1432
1587
|
}
|
|
1433
1588
|
);
|
|
1434
1589
|
} catch (error) {
|
|
1435
|
-
|
|
1590
|
+
exitWithCommandError3(spinner, "Failed to delete process instance", error);
|
|
1436
1591
|
}
|
|
1437
1592
|
}
|
|
1438
1593
|
async function suspendProcessInstance(client, options) {
|
|
@@ -1442,7 +1597,7 @@ async function suspendProcessInstance(client, options) {
|
|
|
1442
1597
|
const result = await bpmClient.suspendProcessInstance(options.id);
|
|
1443
1598
|
if (result.error) {
|
|
1444
1599
|
spinner.fail("Failed to suspend process instance");
|
|
1445
|
-
console.error(
|
|
1600
|
+
console.error(chalk4.red(result.error.message));
|
|
1446
1601
|
process.exit(1);
|
|
1447
1602
|
}
|
|
1448
1603
|
spinner.succeed("Process instance suspended");
|
|
@@ -1454,12 +1609,12 @@ async function suspendProcessInstance(client, options) {
|
|
|
1454
1609
|
{
|
|
1455
1610
|
format: options.format,
|
|
1456
1611
|
pretty: () => {
|
|
1457
|
-
console.log(
|
|
1612
|
+
console.log(chalk4.green(`Suspended process instance: ${options.id}`));
|
|
1458
1613
|
}
|
|
1459
1614
|
}
|
|
1460
1615
|
);
|
|
1461
1616
|
} catch (error) {
|
|
1462
|
-
|
|
1617
|
+
exitWithCommandError3(spinner, "Failed to suspend process instance", error);
|
|
1463
1618
|
}
|
|
1464
1619
|
}
|
|
1465
1620
|
async function activateProcessInstance(client, options) {
|
|
@@ -1469,7 +1624,7 @@ async function activateProcessInstance(client, options) {
|
|
|
1469
1624
|
const result = await bpmClient.activateProcessInstance(options.id);
|
|
1470
1625
|
if (result.error) {
|
|
1471
1626
|
spinner.fail("Failed to activate process instance");
|
|
1472
|
-
console.error(
|
|
1627
|
+
console.error(chalk4.red(result.error.message));
|
|
1473
1628
|
process.exit(1);
|
|
1474
1629
|
}
|
|
1475
1630
|
spinner.succeed("Process instance activated");
|
|
@@ -1481,12 +1636,12 @@ async function activateProcessInstance(client, options) {
|
|
|
1481
1636
|
{
|
|
1482
1637
|
format: options.format,
|
|
1483
1638
|
pretty: () => {
|
|
1484
|
-
console.log(
|
|
1639
|
+
console.log(chalk4.green(`Activated process instance: ${options.id}`));
|
|
1485
1640
|
}
|
|
1486
1641
|
}
|
|
1487
1642
|
);
|
|
1488
1643
|
} catch (error) {
|
|
1489
|
-
|
|
1644
|
+
exitWithCommandError3(spinner, "Failed to activate process instance", error);
|
|
1490
1645
|
}
|
|
1491
1646
|
}
|
|
1492
1647
|
async function modifyProcessInstance(client, options) {
|
|
@@ -1501,7 +1656,7 @@ async function modifyProcessInstance(client, options) {
|
|
|
1501
1656
|
const result = await bpmClient.modifyProcessInstance(options.id, modification);
|
|
1502
1657
|
if (result.error) {
|
|
1503
1658
|
spinner.fail("Failed to modify process instance");
|
|
1504
|
-
console.error(
|
|
1659
|
+
console.error(chalk4.red(result.error.message));
|
|
1505
1660
|
process.exit(1);
|
|
1506
1661
|
}
|
|
1507
1662
|
spinner.succeed("Process instance modified");
|
|
@@ -1514,12 +1669,12 @@ async function modifyProcessInstance(client, options) {
|
|
|
1514
1669
|
{
|
|
1515
1670
|
format: options.format,
|
|
1516
1671
|
pretty: () => {
|
|
1517
|
-
console.log(
|
|
1672
|
+
console.log(chalk4.green(`Modified process instance: ${options.id}`));
|
|
1518
1673
|
}
|
|
1519
1674
|
}
|
|
1520
1675
|
);
|
|
1521
1676
|
} catch (error) {
|
|
1522
|
-
|
|
1677
|
+
exitWithCommandError3(spinner, "Failed to modify process instance", error);
|
|
1523
1678
|
}
|
|
1524
1679
|
}
|
|
1525
1680
|
async function listTasks(client, options) {
|
|
@@ -1530,7 +1685,7 @@ async function listTasks(client, options) {
|
|
|
1530
1685
|
const result = await bpmClient.getTasks(params);
|
|
1531
1686
|
if (result.error) {
|
|
1532
1687
|
spinner.fail("Failed to fetch tasks");
|
|
1533
|
-
console.error(
|
|
1688
|
+
console.error(chalk4.red(result.error.message));
|
|
1534
1689
|
process.exit(1);
|
|
1535
1690
|
}
|
|
1536
1691
|
spinner.succeed(`Found ${result.data?.length || 0} tasks`);
|
|
@@ -1538,19 +1693,19 @@ async function listTasks(client, options) {
|
|
|
1538
1693
|
renderOutput(tasks, {
|
|
1539
1694
|
format: options.format,
|
|
1540
1695
|
pretty: () => {
|
|
1541
|
-
console.log(
|
|
1696
|
+
console.log(chalk4.blue("\n\u{1F4DD} Tasks\n"));
|
|
1542
1697
|
for (const task of tasks) {
|
|
1543
|
-
console.log(` ${
|
|
1544
|
-
console.log(` ${
|
|
1545
|
-
console.log(` ${
|
|
1546
|
-
console.log(` ${
|
|
1547
|
-
console.log(` ${
|
|
1698
|
+
console.log(` ${chalk4.green("\u2022")} ${chalk4.bold(task.name || task.id)}`);
|
|
1699
|
+
console.log(` ${chalk4.gray("ID:")} ${task.id}`);
|
|
1700
|
+
console.log(` ${chalk4.gray("Assignee:")} ${task.assignee || "Unassigned"}`);
|
|
1701
|
+
console.log(` ${chalk4.gray("Process Instance:")} ${task.processInstanceId || "N/A"}`);
|
|
1702
|
+
console.log(` ${chalk4.gray("Created:")} ${task.created || "N/A"}`);
|
|
1548
1703
|
console.log();
|
|
1549
1704
|
}
|
|
1550
1705
|
}
|
|
1551
1706
|
});
|
|
1552
1707
|
} catch (error) {
|
|
1553
|
-
|
|
1708
|
+
exitWithCommandError3(spinner, "Failed to fetch tasks", error);
|
|
1554
1709
|
}
|
|
1555
1710
|
}
|
|
1556
1711
|
async function getTask(client, options) {
|
|
@@ -1560,19 +1715,19 @@ async function getTask(client, options) {
|
|
|
1560
1715
|
const result = await bpmClient.getTask(options.id);
|
|
1561
1716
|
if (result.error) {
|
|
1562
1717
|
spinner.fail("Failed to fetch task");
|
|
1563
|
-
console.error(
|
|
1718
|
+
console.error(chalk4.red(result.error.message));
|
|
1564
1719
|
process.exit(1);
|
|
1565
1720
|
}
|
|
1566
1721
|
spinner.succeed("Task retrieved");
|
|
1567
1722
|
renderOutput(result.data, {
|
|
1568
1723
|
format: options.format,
|
|
1569
1724
|
pretty: () => {
|
|
1570
|
-
console.log(
|
|
1725
|
+
console.log(chalk4.blue("\n\u{1F4DD} Task\n"));
|
|
1571
1726
|
console.log(JSON.stringify(result.data, null, 2));
|
|
1572
1727
|
}
|
|
1573
1728
|
});
|
|
1574
1729
|
} catch (error) {
|
|
1575
|
-
|
|
1730
|
+
exitWithCommandError3(spinner, "Failed to fetch task", error);
|
|
1576
1731
|
}
|
|
1577
1732
|
}
|
|
1578
1733
|
async function getTaskCount(client, options) {
|
|
@@ -1583,18 +1738,18 @@ async function getTaskCount(client, options) {
|
|
|
1583
1738
|
const result = await bpmClient.getTaskCount(params);
|
|
1584
1739
|
if (result.error) {
|
|
1585
1740
|
spinner.fail("Failed to fetch task count");
|
|
1586
|
-
console.error(
|
|
1741
|
+
console.error(chalk4.red(result.error.message));
|
|
1587
1742
|
process.exit(1);
|
|
1588
1743
|
}
|
|
1589
1744
|
spinner.succeed("Task count retrieved");
|
|
1590
1745
|
renderOutput(result.data, {
|
|
1591
1746
|
format: options.format,
|
|
1592
1747
|
pretty: () => {
|
|
1593
|
-
console.log(
|
|
1748
|
+
console.log(chalk4.green(`Task count: ${result.data?.count ?? 0}`));
|
|
1594
1749
|
}
|
|
1595
1750
|
});
|
|
1596
1751
|
} catch (error) {
|
|
1597
|
-
|
|
1752
|
+
exitWithCommandError3(spinner, "Failed to fetch task count", error);
|
|
1598
1753
|
}
|
|
1599
1754
|
}
|
|
1600
1755
|
async function completeTask(client, options) {
|
|
@@ -1605,7 +1760,7 @@ async function completeTask(client, options) {
|
|
|
1605
1760
|
const result = await bpmClient.completeTask(options.id, variables);
|
|
1606
1761
|
if (result.error) {
|
|
1607
1762
|
spinner.fail("Failed to complete task");
|
|
1608
|
-
console.error(
|
|
1763
|
+
console.error(chalk4.red(result.error.message));
|
|
1609
1764
|
process.exit(1);
|
|
1610
1765
|
}
|
|
1611
1766
|
spinner.succeed("Task completed");
|
|
@@ -1617,12 +1772,12 @@ async function completeTask(client, options) {
|
|
|
1617
1772
|
{
|
|
1618
1773
|
format: options.format,
|
|
1619
1774
|
pretty: () => {
|
|
1620
|
-
console.log(
|
|
1775
|
+
console.log(chalk4.green(`Completed task: ${options.id}`));
|
|
1621
1776
|
}
|
|
1622
1777
|
}
|
|
1623
1778
|
);
|
|
1624
1779
|
} catch (error) {
|
|
1625
|
-
|
|
1780
|
+
exitWithCommandError3(spinner, "Failed to complete task", error);
|
|
1626
1781
|
}
|
|
1627
1782
|
}
|
|
1628
1783
|
async function delegateTask(client, options) {
|
|
@@ -1632,7 +1787,7 @@ async function delegateTask(client, options) {
|
|
|
1632
1787
|
const result = await bpmClient.delegateTask(options.id, options.userId);
|
|
1633
1788
|
if (result.error) {
|
|
1634
1789
|
spinner.fail("Failed to delegate task");
|
|
1635
|
-
console.error(
|
|
1790
|
+
console.error(chalk4.red(result.error.message));
|
|
1636
1791
|
process.exit(1);
|
|
1637
1792
|
}
|
|
1638
1793
|
spinner.succeed("Task delegated");
|
|
@@ -1645,12 +1800,12 @@ async function delegateTask(client, options) {
|
|
|
1645
1800
|
{
|
|
1646
1801
|
format: options.format,
|
|
1647
1802
|
pretty: () => {
|
|
1648
|
-
console.log(
|
|
1803
|
+
console.log(chalk4.green(`Delegated task ${options.id} to ${options.userId}`));
|
|
1649
1804
|
}
|
|
1650
1805
|
}
|
|
1651
1806
|
);
|
|
1652
1807
|
} catch (error) {
|
|
1653
|
-
|
|
1808
|
+
exitWithCommandError3(spinner, "Failed to delegate task", error);
|
|
1654
1809
|
}
|
|
1655
1810
|
}
|
|
1656
1811
|
async function getTaskForm(client, options) {
|
|
@@ -1660,19 +1815,19 @@ async function getTaskForm(client, options) {
|
|
|
1660
1815
|
const result = await bpmClient.getTaskForm(options.id);
|
|
1661
1816
|
if (result.error) {
|
|
1662
1817
|
spinner.fail("Failed to fetch task form");
|
|
1663
|
-
console.error(
|
|
1818
|
+
console.error(chalk4.red(result.error.message));
|
|
1664
1819
|
process.exit(1);
|
|
1665
1820
|
}
|
|
1666
1821
|
spinner.succeed("Task form retrieved");
|
|
1667
1822
|
renderOutput(result.data, {
|
|
1668
1823
|
format: options.format,
|
|
1669
1824
|
pretty: () => {
|
|
1670
|
-
console.log(
|
|
1825
|
+
console.log(chalk4.blue("\n\u{1F9E9} Task Form\n"));
|
|
1671
1826
|
console.log(JSON.stringify(result.data, null, 2));
|
|
1672
1827
|
}
|
|
1673
1828
|
});
|
|
1674
1829
|
} catch (error) {
|
|
1675
|
-
|
|
1830
|
+
exitWithCommandError3(spinner, "Failed to fetch task form", error);
|
|
1676
1831
|
}
|
|
1677
1832
|
}
|
|
1678
1833
|
async function getTaskFormSchema(client, options) {
|
|
@@ -1695,12 +1850,12 @@ async function getTaskFormSchema(client, options) {
|
|
|
1695
1850
|
renderOutput(result.data, {
|
|
1696
1851
|
format: options.format,
|
|
1697
1852
|
pretty: () => {
|
|
1698
|
-
console.log(
|
|
1853
|
+
console.log(chalk4.blue("\n\u{1F9E9} Task Form Schema\n"));
|
|
1699
1854
|
console.log(JSON.stringify(result.data, null, 2));
|
|
1700
1855
|
}
|
|
1701
1856
|
});
|
|
1702
1857
|
} catch (error) {
|
|
1703
|
-
|
|
1858
|
+
exitWithCommandError3(spinner, "Failed to fetch task form schema", error);
|
|
1704
1859
|
}
|
|
1705
1860
|
}
|
|
1706
1861
|
async function getTaskFormVariables(client, options) {
|
|
@@ -1710,19 +1865,19 @@ async function getTaskFormVariables(client, options) {
|
|
|
1710
1865
|
const result = await bpmClient.getTaskFormVariables(options.id);
|
|
1711
1866
|
if (result.error) {
|
|
1712
1867
|
spinner.fail("Failed to fetch task form variables");
|
|
1713
|
-
console.error(
|
|
1868
|
+
console.error(chalk4.red(result.error.message));
|
|
1714
1869
|
process.exit(1);
|
|
1715
1870
|
}
|
|
1716
1871
|
spinner.succeed("Task form variables retrieved");
|
|
1717
1872
|
renderOutput(result.data, {
|
|
1718
1873
|
format: options.format,
|
|
1719
1874
|
pretty: () => {
|
|
1720
|
-
console.log(
|
|
1875
|
+
console.log(chalk4.blue("\n\u{1F9EE} Task Form Variables\n"));
|
|
1721
1876
|
console.log(JSON.stringify(result.data, null, 2));
|
|
1722
1877
|
}
|
|
1723
1878
|
});
|
|
1724
1879
|
} catch (error) {
|
|
1725
|
-
|
|
1880
|
+
exitWithCommandError3(spinner, "Failed to fetch task form variables", error);
|
|
1726
1881
|
}
|
|
1727
1882
|
}
|
|
1728
1883
|
async function getTaskRenderedForm(client, options) {
|
|
@@ -1732,19 +1887,19 @@ async function getTaskRenderedForm(client, options) {
|
|
|
1732
1887
|
const result = await bpmClient.getTaskRenderedForm(options.id);
|
|
1733
1888
|
if (result.error) {
|
|
1734
1889
|
spinner.fail("Failed to fetch rendered task form");
|
|
1735
|
-
console.error(
|
|
1890
|
+
console.error(chalk4.red(result.error.message));
|
|
1736
1891
|
process.exit(1);
|
|
1737
1892
|
}
|
|
1738
1893
|
spinner.succeed("Rendered task form retrieved");
|
|
1739
1894
|
renderOutput(result.data, {
|
|
1740
1895
|
format: options.format,
|
|
1741
1896
|
pretty: () => {
|
|
1742
|
-
console.log(
|
|
1897
|
+
console.log(chalk4.blue("\n\u{1F9FE} Rendered Task Form\n"));
|
|
1743
1898
|
console.log(result.data || "");
|
|
1744
1899
|
}
|
|
1745
1900
|
});
|
|
1746
1901
|
} catch (error) {
|
|
1747
|
-
|
|
1902
|
+
exitWithCommandError3(spinner, "Failed to fetch rendered task form", error);
|
|
1748
1903
|
}
|
|
1749
1904
|
}
|
|
1750
1905
|
async function getTaskDeployedForm(client, options) {
|
|
@@ -1754,19 +1909,19 @@ async function getTaskDeployedForm(client, options) {
|
|
|
1754
1909
|
const result = await bpmClient.getTaskDeployedForm(options.id);
|
|
1755
1910
|
if (result.error) {
|
|
1756
1911
|
spinner.fail("Failed to fetch deployed task form");
|
|
1757
|
-
console.error(
|
|
1912
|
+
console.error(chalk4.red(result.error.message));
|
|
1758
1913
|
process.exit(1);
|
|
1759
1914
|
}
|
|
1760
1915
|
spinner.succeed("Deployed task form retrieved");
|
|
1761
1916
|
renderOutput(result.data, {
|
|
1762
1917
|
format: options.format,
|
|
1763
1918
|
pretty: () => {
|
|
1764
|
-
console.log(
|
|
1919
|
+
console.log(chalk4.blue("\n\u{1F9FE} Deployed Task Form\n"));
|
|
1765
1920
|
console.log(JSON.stringify(result.data, null, 2));
|
|
1766
1921
|
}
|
|
1767
1922
|
});
|
|
1768
1923
|
} catch (error) {
|
|
1769
|
-
|
|
1924
|
+
exitWithCommandError3(spinner, "Failed to fetch deployed task form", error);
|
|
1770
1925
|
}
|
|
1771
1926
|
}
|
|
1772
1927
|
async function getStartFormInfo(client, options) {
|
|
@@ -1786,12 +1941,12 @@ async function getStartFormInfo(client, options) {
|
|
|
1786
1941
|
renderOutput(result.data, {
|
|
1787
1942
|
format: options.format,
|
|
1788
1943
|
pretty: () => {
|
|
1789
|
-
console.log(
|
|
1944
|
+
console.log(chalk4.blue("\n\u{1F680} Start Form Info\n"));
|
|
1790
1945
|
console.log(JSON.stringify(result.data, null, 2));
|
|
1791
1946
|
}
|
|
1792
1947
|
});
|
|
1793
1948
|
} catch (error) {
|
|
1794
|
-
|
|
1949
|
+
exitWithCommandError3(spinner, "Failed to fetch start form info", error);
|
|
1795
1950
|
}
|
|
1796
1951
|
}
|
|
1797
1952
|
async function getStartFormVariables(client, options) {
|
|
@@ -1811,12 +1966,12 @@ async function getStartFormVariables(client, options) {
|
|
|
1811
1966
|
renderOutput(result.data, {
|
|
1812
1967
|
format: options.format,
|
|
1813
1968
|
pretty: () => {
|
|
1814
|
-
console.log(
|
|
1969
|
+
console.log(chalk4.blue("\n\u{1F680} Start Form Variables\n"));
|
|
1815
1970
|
console.log(JSON.stringify(result.data, null, 2));
|
|
1816
1971
|
}
|
|
1817
1972
|
});
|
|
1818
1973
|
} catch (error) {
|
|
1819
|
-
|
|
1974
|
+
exitWithCommandError3(spinner, "Failed to fetch start form variables", error);
|
|
1820
1975
|
}
|
|
1821
1976
|
}
|
|
1822
1977
|
async function getDeployedStartForm(client, options) {
|
|
@@ -1836,12 +1991,12 @@ async function getDeployedStartForm(client, options) {
|
|
|
1836
1991
|
renderOutput(result.data, {
|
|
1837
1992
|
format: options.format,
|
|
1838
1993
|
pretty: () => {
|
|
1839
|
-
console.log(
|
|
1994
|
+
console.log(chalk4.blue("\n\u{1F680} Deployed Start Form\n"));
|
|
1840
1995
|
console.log(JSON.stringify(result.data, null, 2));
|
|
1841
1996
|
}
|
|
1842
1997
|
});
|
|
1843
1998
|
} catch (error) {
|
|
1844
|
-
|
|
1999
|
+
exitWithCommandError3(spinner, "Failed to fetch deployed start form", error);
|
|
1845
2000
|
}
|
|
1846
2001
|
}
|
|
1847
2002
|
async function listHistoryTasks(client, options = {}) {
|
|
@@ -1852,7 +2007,7 @@ async function listHistoryTasks(client, options = {}) {
|
|
|
1852
2007
|
const result = await bpmClient.getHistoryTasks(params);
|
|
1853
2008
|
if (result.error) {
|
|
1854
2009
|
spinner.fail("Failed to fetch history tasks");
|
|
1855
|
-
console.error(
|
|
2010
|
+
console.error(chalk4.red(result.error.message));
|
|
1856
2011
|
process.exit(1);
|
|
1857
2012
|
}
|
|
1858
2013
|
const tasks = result.data || [];
|
|
@@ -1860,12 +2015,12 @@ async function listHistoryTasks(client, options = {}) {
|
|
|
1860
2015
|
renderOutput(tasks, {
|
|
1861
2016
|
format: options.format,
|
|
1862
2017
|
pretty: () => {
|
|
1863
|
-
console.log(
|
|
2018
|
+
console.log(chalk4.blue("\n\u{1F4DA} History Tasks\n"));
|
|
1864
2019
|
console.log(JSON.stringify(tasks, null, 2));
|
|
1865
2020
|
}
|
|
1866
2021
|
});
|
|
1867
2022
|
} catch (error) {
|
|
1868
|
-
|
|
2023
|
+
exitWithCommandError3(spinner, "Failed to fetch history tasks", error);
|
|
1869
2024
|
}
|
|
1870
2025
|
}
|
|
1871
2026
|
async function getHistoryTaskCount(client, options = {}) {
|
|
@@ -1876,18 +2031,18 @@ async function getHistoryTaskCount(client, options = {}) {
|
|
|
1876
2031
|
const result = await bpmClient.getHistoryTaskCount(params);
|
|
1877
2032
|
if (result.error) {
|
|
1878
2033
|
spinner.fail("Failed to fetch history task count");
|
|
1879
|
-
console.error(
|
|
2034
|
+
console.error(chalk4.red(result.error.message));
|
|
1880
2035
|
process.exit(1);
|
|
1881
2036
|
}
|
|
1882
2037
|
spinner.succeed("History task count retrieved");
|
|
1883
2038
|
renderOutput(result.data, {
|
|
1884
2039
|
format: options.format,
|
|
1885
2040
|
pretty: () => {
|
|
1886
|
-
console.log(
|
|
2041
|
+
console.log(chalk4.green(`History task count: ${result.data?.count ?? 0}`));
|
|
1887
2042
|
}
|
|
1888
2043
|
});
|
|
1889
2044
|
} catch (error) {
|
|
1890
|
-
|
|
2045
|
+
exitWithCommandError3(spinner, "Failed to fetch history task count", error);
|
|
1891
2046
|
}
|
|
1892
2047
|
}
|
|
1893
2048
|
async function listHistoryProcessInstances(client, options = {}) {
|
|
@@ -1898,7 +2053,7 @@ async function listHistoryProcessInstances(client, options = {}) {
|
|
|
1898
2053
|
const result = await bpmClient.getHistoryProcessInstances(params);
|
|
1899
2054
|
if (result.error) {
|
|
1900
2055
|
spinner.fail("Failed to fetch history process instances");
|
|
1901
|
-
console.error(
|
|
2056
|
+
console.error(chalk4.red(result.error.message));
|
|
1902
2057
|
process.exit(1);
|
|
1903
2058
|
}
|
|
1904
2059
|
const instances = result.data || [];
|
|
@@ -1906,12 +2061,12 @@ async function listHistoryProcessInstances(client, options = {}) {
|
|
|
1906
2061
|
renderOutput(instances, {
|
|
1907
2062
|
format: options.format,
|
|
1908
2063
|
pretty: () => {
|
|
1909
|
-
console.log(
|
|
2064
|
+
console.log(chalk4.blue("\n\u{1F4DA} History Process Instances\n"));
|
|
1910
2065
|
console.log(JSON.stringify(instances, null, 2));
|
|
1911
2066
|
}
|
|
1912
2067
|
});
|
|
1913
2068
|
} catch (error) {
|
|
1914
|
-
|
|
2069
|
+
exitWithCommandError3(spinner, "Failed to fetch history process instances", error);
|
|
1915
2070
|
}
|
|
1916
2071
|
}
|
|
1917
2072
|
async function getHistoryProcessInstanceCount(client, options = {}) {
|
|
@@ -1922,18 +2077,18 @@ async function getHistoryProcessInstanceCount(client, options = {}) {
|
|
|
1922
2077
|
const result = await bpmClient.getHistoryProcessInstanceCount(params);
|
|
1923
2078
|
if (result.error) {
|
|
1924
2079
|
spinner.fail("Failed to fetch history process instance count");
|
|
1925
|
-
console.error(
|
|
2080
|
+
console.error(chalk4.red(result.error.message));
|
|
1926
2081
|
process.exit(1);
|
|
1927
2082
|
}
|
|
1928
2083
|
spinner.succeed("History process instance count retrieved");
|
|
1929
2084
|
renderOutput(result.data, {
|
|
1930
2085
|
format: options.format,
|
|
1931
2086
|
pretty: () => {
|
|
1932
|
-
console.log(
|
|
2087
|
+
console.log(chalk4.green(`History process instance count: ${result.data?.count ?? 0}`));
|
|
1933
2088
|
}
|
|
1934
2089
|
});
|
|
1935
2090
|
} catch (error) {
|
|
1936
|
-
|
|
2091
|
+
exitWithCommandError3(spinner, "Failed to fetch history process instance count", error);
|
|
1937
2092
|
}
|
|
1938
2093
|
}
|
|
1939
2094
|
async function getHistoryProcessInstance(client, options) {
|
|
@@ -1943,19 +2098,19 @@ async function getHistoryProcessInstance(client, options) {
|
|
|
1943
2098
|
const result = await bpmClient.getHistoryProcessInstance(options.id);
|
|
1944
2099
|
if (result.error) {
|
|
1945
2100
|
spinner.fail("Failed to fetch history process instance");
|
|
1946
|
-
console.error(
|
|
2101
|
+
console.error(chalk4.red(result.error.message));
|
|
1947
2102
|
process.exit(1);
|
|
1948
2103
|
}
|
|
1949
2104
|
spinner.succeed("History process instance retrieved");
|
|
1950
2105
|
renderOutput(result.data, {
|
|
1951
2106
|
format: options.format,
|
|
1952
2107
|
pretty: () => {
|
|
1953
|
-
console.log(
|
|
2108
|
+
console.log(chalk4.blue("\n\u{1F4DA} History Process Instance\n"));
|
|
1954
2109
|
console.log(JSON.stringify(result.data, null, 2));
|
|
1955
2110
|
}
|
|
1956
2111
|
});
|
|
1957
2112
|
} catch (error) {
|
|
1958
|
-
|
|
2113
|
+
exitWithCommandError3(spinner, "Failed to fetch history process instance", error);
|
|
1959
2114
|
}
|
|
1960
2115
|
}
|
|
1961
2116
|
async function listHistoryActivityInstances(client, options = {}) {
|
|
@@ -1966,7 +2121,7 @@ async function listHistoryActivityInstances(client, options = {}) {
|
|
|
1966
2121
|
const result = await bpmClient.getHistoryActivityInstances(params);
|
|
1967
2122
|
if (result.error) {
|
|
1968
2123
|
spinner.fail("Failed to fetch history activity instances");
|
|
1969
|
-
console.error(
|
|
2124
|
+
console.error(chalk4.red(result.error.message));
|
|
1970
2125
|
process.exit(1);
|
|
1971
2126
|
}
|
|
1972
2127
|
const activities = result.data || [];
|
|
@@ -1974,12 +2129,12 @@ async function listHistoryActivityInstances(client, options = {}) {
|
|
|
1974
2129
|
renderOutput(activities, {
|
|
1975
2130
|
format: options.format,
|
|
1976
2131
|
pretty: () => {
|
|
1977
|
-
console.log(
|
|
2132
|
+
console.log(chalk4.blue("\n\u{1F4DA} History Activity Instances\n"));
|
|
1978
2133
|
console.log(JSON.stringify(activities, null, 2));
|
|
1979
2134
|
}
|
|
1980
2135
|
});
|
|
1981
2136
|
} catch (error) {
|
|
1982
|
-
|
|
2137
|
+
exitWithCommandError3(spinner, "Failed to fetch history activity instances", error);
|
|
1983
2138
|
}
|
|
1984
2139
|
}
|
|
1985
2140
|
async function listHistoryVariableInstances(client, options = {}) {
|
|
@@ -1990,7 +2145,7 @@ async function listHistoryVariableInstances(client, options = {}) {
|
|
|
1990
2145
|
const result = await bpmClient.getHistoryVariableInstances(params);
|
|
1991
2146
|
if (result.error) {
|
|
1992
2147
|
spinner.fail("Failed to fetch history variable instances");
|
|
1993
|
-
console.error(
|
|
2148
|
+
console.error(chalk4.red(result.error.message));
|
|
1994
2149
|
process.exit(1);
|
|
1995
2150
|
}
|
|
1996
2151
|
const variables = result.data || [];
|
|
@@ -1998,12 +2153,12 @@ async function listHistoryVariableInstances(client, options = {}) {
|
|
|
1998
2153
|
renderOutput(variables, {
|
|
1999
2154
|
format: options.format,
|
|
2000
2155
|
pretty: () => {
|
|
2001
|
-
console.log(
|
|
2156
|
+
console.log(chalk4.blue("\n\u{1F4DA} History Variable Instances\n"));
|
|
2002
2157
|
console.log(JSON.stringify(variables, null, 2));
|
|
2003
2158
|
}
|
|
2004
2159
|
});
|
|
2005
2160
|
} catch (error) {
|
|
2006
|
-
|
|
2161
|
+
exitWithCommandError3(spinner, "Failed to fetch history variable instances", error);
|
|
2007
2162
|
}
|
|
2008
2163
|
}
|
|
2009
2164
|
async function listUserOperationLogs(client, options = {}) {
|
|
@@ -2014,7 +2169,7 @@ async function listUserOperationLogs(client, options = {}) {
|
|
|
2014
2169
|
const result = await bpmClient.getUserOperationLogs(params);
|
|
2015
2170
|
if (result.error) {
|
|
2016
2171
|
spinner.fail("Failed to fetch user operation logs");
|
|
2017
|
-
console.error(
|
|
2172
|
+
console.error(chalk4.red(result.error.message));
|
|
2018
2173
|
process.exit(1);
|
|
2019
2174
|
}
|
|
2020
2175
|
const logs = result.data || [];
|
|
@@ -2022,12 +2177,12 @@ async function listUserOperationLogs(client, options = {}) {
|
|
|
2022
2177
|
renderOutput(logs, {
|
|
2023
2178
|
format: options.format,
|
|
2024
2179
|
pretty: () => {
|
|
2025
|
-
console.log(
|
|
2180
|
+
console.log(chalk4.blue("\n\u{1F4DA} User Operation Logs\n"));
|
|
2026
2181
|
console.log(JSON.stringify(logs, null, 2));
|
|
2027
2182
|
}
|
|
2028
2183
|
});
|
|
2029
2184
|
} catch (error) {
|
|
2030
|
-
|
|
2185
|
+
exitWithCommandError3(spinner, "Failed to fetch user operation logs", error);
|
|
2031
2186
|
}
|
|
2032
2187
|
}
|
|
2033
2188
|
async function deleteHistoryProcessInstance(client, options) {
|
|
@@ -2037,7 +2192,7 @@ async function deleteHistoryProcessInstance(client, options) {
|
|
|
2037
2192
|
const result = await bpmClient.deleteHistoryProcessInstance(options.id);
|
|
2038
2193
|
if (result.error) {
|
|
2039
2194
|
spinner.fail("Failed to delete history process instance");
|
|
2040
|
-
console.error(
|
|
2195
|
+
console.error(chalk4.red(result.error.message));
|
|
2041
2196
|
process.exit(1);
|
|
2042
2197
|
}
|
|
2043
2198
|
spinner.succeed("History process instance deleted");
|
|
@@ -2049,12 +2204,12 @@ async function deleteHistoryProcessInstance(client, options) {
|
|
|
2049
2204
|
{
|
|
2050
2205
|
format: options.format,
|
|
2051
2206
|
pretty: () => {
|
|
2052
|
-
console.log(
|
|
2207
|
+
console.log(chalk4.green(`Deleted history process instance: ${options.id}`));
|
|
2053
2208
|
}
|
|
2054
2209
|
}
|
|
2055
2210
|
);
|
|
2056
2211
|
} catch (error) {
|
|
2057
|
-
|
|
2212
|
+
exitWithCommandError3(spinner, "Failed to delete history process instance", error);
|
|
2058
2213
|
}
|
|
2059
2214
|
}
|
|
2060
2215
|
async function listRoles(client, options = {}) {
|
|
@@ -2064,7 +2219,7 @@ async function listRoles(client, options = {}) {
|
|
|
2064
2219
|
const result = await bpmClient.getRoles();
|
|
2065
2220
|
if (result.error) {
|
|
2066
2221
|
spinner.fail("Failed to fetch roles");
|
|
2067
|
-
console.error(
|
|
2222
|
+
console.error(chalk4.red(result.error.message));
|
|
2068
2223
|
process.exit(1);
|
|
2069
2224
|
}
|
|
2070
2225
|
const roles = result.data || [];
|
|
@@ -2072,12 +2227,12 @@ async function listRoles(client, options = {}) {
|
|
|
2072
2227
|
renderOutput(roles, {
|
|
2073
2228
|
format: options.format,
|
|
2074
2229
|
pretty: () => {
|
|
2075
|
-
console.log(
|
|
2230
|
+
console.log(chalk4.blue("\n\u{1F465} Roles\n"));
|
|
2076
2231
|
console.log(JSON.stringify(roles, null, 2));
|
|
2077
2232
|
}
|
|
2078
2233
|
});
|
|
2079
2234
|
} catch (error) {
|
|
2080
|
-
|
|
2235
|
+
exitWithCommandError3(spinner, "Failed to fetch roles", error);
|
|
2081
2236
|
}
|
|
2082
2237
|
}
|
|
2083
2238
|
async function getUserRoles(client, options) {
|
|
@@ -2087,7 +2242,7 @@ async function getUserRoles(client, options) {
|
|
|
2087
2242
|
const result = await bpmClient.getUserRoles(options.userId);
|
|
2088
2243
|
if (result.error) {
|
|
2089
2244
|
spinner.fail("Failed to fetch user roles");
|
|
2090
|
-
console.error(
|
|
2245
|
+
console.error(chalk4.red(result.error.message));
|
|
2091
2246
|
process.exit(1);
|
|
2092
2247
|
}
|
|
2093
2248
|
const roles = result.data || [];
|
|
@@ -2095,17 +2250,19 @@ async function getUserRoles(client, options) {
|
|
|
2095
2250
|
renderOutput(roles, {
|
|
2096
2251
|
format: options.format,
|
|
2097
2252
|
pretty: () => {
|
|
2098
|
-
console.log(
|
|
2253
|
+
console.log(chalk4.blue(`
|
|
2099
2254
|
\u{1F464} User Roles: ${options.userId}
|
|
2100
2255
|
`));
|
|
2101
2256
|
console.log(JSON.stringify(roles, null, 2));
|
|
2102
2257
|
}
|
|
2103
2258
|
});
|
|
2104
2259
|
} catch (error) {
|
|
2105
|
-
|
|
2260
|
+
exitWithCommandError3(spinner, "Failed to fetch user roles", error);
|
|
2106
2261
|
}
|
|
2107
2262
|
}
|
|
2108
|
-
|
|
2263
|
+
var WORKFLOW_LIST_PATH = "/api/proxy/builtin/platform/workflow/openapi/apps";
|
|
2264
|
+
var WORKFLOW_GET_PATH = (workflowId) => `/api/proxy/builtin/platform/workflow/openapi/apps/${encodeURIComponent(workflowId)}/dsl`;
|
|
2265
|
+
function resolveInputSource4(input) {
|
|
2109
2266
|
if (!input.startsWith("@")) {
|
|
2110
2267
|
return input;
|
|
2111
2268
|
}
|
|
@@ -2116,7 +2273,7 @@ function resolveInputSource3(input) {
|
|
|
2116
2273
|
return readFileSync(filePath, "utf8");
|
|
2117
2274
|
}
|
|
2118
2275
|
function parseJsonInput3(input, label) {
|
|
2119
|
-
const source =
|
|
2276
|
+
const source = resolveInputSource4(input).trim();
|
|
2120
2277
|
if (!source) {
|
|
2121
2278
|
throw new Error(`${label} is required.`);
|
|
2122
2279
|
}
|
|
@@ -2130,6 +2287,151 @@ function parseJsonInput3(input, label) {
|
|
|
2130
2287
|
function isPlainObject4(value) {
|
|
2131
2288
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2132
2289
|
}
|
|
2290
|
+
function parseWorkflowTracing(value) {
|
|
2291
|
+
if (!value) {
|
|
2292
|
+
return null;
|
|
2293
|
+
}
|
|
2294
|
+
if (isPlainObject4(value)) {
|
|
2295
|
+
return value;
|
|
2296
|
+
}
|
|
2297
|
+
if (typeof value !== "string") {
|
|
2298
|
+
return null;
|
|
2299
|
+
}
|
|
2300
|
+
try {
|
|
2301
|
+
const parsed = JSON.parse(value);
|
|
2302
|
+
return isPlainObject4(parsed) ? parsed : null;
|
|
2303
|
+
} catch {
|
|
2304
|
+
return null;
|
|
2305
|
+
}
|
|
2306
|
+
}
|
|
2307
|
+
function getRunnableName(summary) {
|
|
2308
|
+
const tracing = parseWorkflowTracing(summary.tracing);
|
|
2309
|
+
const baseName = tracing?.base_name;
|
|
2310
|
+
if (typeof baseName === "string" && baseName.trim()) {
|
|
2311
|
+
return baseName.trim();
|
|
2312
|
+
}
|
|
2313
|
+
return null;
|
|
2314
|
+
}
|
|
2315
|
+
function normalizeWorkflowSummary(summary) {
|
|
2316
|
+
return {
|
|
2317
|
+
...summary,
|
|
2318
|
+
id: typeof summary.id === "string" ? summary.id : "",
|
|
2319
|
+
name: typeof summary.name === "string" ? summary.name : "",
|
|
2320
|
+
runnable_name: getRunnableName(summary),
|
|
2321
|
+
description: typeof summary.description === "string" ? summary.description : null,
|
|
2322
|
+
mode: typeof summary.mode === "string" ? summary.mode : null
|
|
2323
|
+
};
|
|
2324
|
+
}
|
|
2325
|
+
function extractWorkflowInputVariables(dsl) {
|
|
2326
|
+
if (!isPlainObject4(dsl)) {
|
|
2327
|
+
return [];
|
|
2328
|
+
}
|
|
2329
|
+
const candidateNodeSets = [];
|
|
2330
|
+
if (Array.isArray(dsl.nodes)) {
|
|
2331
|
+
candidateNodeSets.push(dsl.nodes);
|
|
2332
|
+
}
|
|
2333
|
+
if (isPlainObject4(dsl.graph) && Array.isArray(dsl.graph.nodes)) {
|
|
2334
|
+
candidateNodeSets.push(dsl.graph.nodes);
|
|
2335
|
+
}
|
|
2336
|
+
const variables = [];
|
|
2337
|
+
for (const nodeSet of candidateNodeSets) {
|
|
2338
|
+
for (const node of nodeSet) {
|
|
2339
|
+
if (!isPlainObject4(node) || !isPlainObject4(node.data)) {
|
|
2340
|
+
continue;
|
|
2341
|
+
}
|
|
2342
|
+
const nodeData = node.data;
|
|
2343
|
+
if (nodeData.type !== "start" || !Array.isArray(nodeData.variables)) {
|
|
2344
|
+
continue;
|
|
2345
|
+
}
|
|
2346
|
+
for (const variable of nodeData.variables) {
|
|
2347
|
+
if (!isPlainObject4(variable) || typeof variable.variable !== "string") {
|
|
2348
|
+
continue;
|
|
2349
|
+
}
|
|
2350
|
+
variables.push({
|
|
2351
|
+
...variable,
|
|
2352
|
+
variable: variable.variable,
|
|
2353
|
+
label: typeof variable.label === "string" ? variable.label : void 0,
|
|
2354
|
+
required: typeof variable.required === "boolean" ? variable.required : void 0,
|
|
2355
|
+
type: typeof variable.type === "string" ? variable.type : void 0
|
|
2356
|
+
});
|
|
2357
|
+
}
|
|
2358
|
+
}
|
|
2359
|
+
}
|
|
2360
|
+
return variables;
|
|
2361
|
+
}
|
|
2362
|
+
function normalizeWorkflowDefinition(definition) {
|
|
2363
|
+
return {
|
|
2364
|
+
...definition,
|
|
2365
|
+
workflow_id: typeof definition.workflow_id === "string" ? definition.workflow_id : "",
|
|
2366
|
+
app_id: typeof definition.app_id === "string" ? definition.app_id : "",
|
|
2367
|
+
version: typeof definition.version === "string" ? definition.version : void 0,
|
|
2368
|
+
name: typeof definition.name === "string" ? definition.name : "",
|
|
2369
|
+
dsl: isPlainObject4(definition.dsl) ? definition.dsl : void 0,
|
|
2370
|
+
context: typeof definition.context === "string" ? definition.context : void 0,
|
|
2371
|
+
input_variables: extractWorkflowInputVariables(definition.dsl)
|
|
2372
|
+
};
|
|
2373
|
+
}
|
|
2374
|
+
function invalidResponse(status, message) {
|
|
2375
|
+
return {
|
|
2376
|
+
data: null,
|
|
2377
|
+
error: {
|
|
2378
|
+
status,
|
|
2379
|
+
message
|
|
2380
|
+
},
|
|
2381
|
+
status
|
|
2382
|
+
};
|
|
2383
|
+
}
|
|
2384
|
+
function createWorkflowService(client) {
|
|
2385
|
+
return {
|
|
2386
|
+
async list(params = {}) {
|
|
2387
|
+
const response = await client.http.request({
|
|
2388
|
+
url: WORKFLOW_LIST_PATH,
|
|
2389
|
+
method: "GET",
|
|
2390
|
+
params: {
|
|
2391
|
+
page: params.page ?? 1,
|
|
2392
|
+
limit: params.limit ?? 20,
|
|
2393
|
+
mode: params.mode ?? "workflow"
|
|
2394
|
+
}
|
|
2395
|
+
});
|
|
2396
|
+
if (!response.data || !Array.isArray(response.data.data)) {
|
|
2397
|
+
return invalidResponse(
|
|
2398
|
+
response.status,
|
|
2399
|
+
response.error?.message || "Invalid workflow list response structure"
|
|
2400
|
+
);
|
|
2401
|
+
}
|
|
2402
|
+
return {
|
|
2403
|
+
...response,
|
|
2404
|
+
data: {
|
|
2405
|
+
...response.data,
|
|
2406
|
+
page: typeof response.data.page === "number" ? response.data.page : params.page ?? 1,
|
|
2407
|
+
limit: typeof response.data.limit === "number" ? response.data.limit : params.limit ?? 20,
|
|
2408
|
+
total: typeof response.data.total === "number" ? response.data.total : response.data.data.length,
|
|
2409
|
+
has_more: typeof response.data.has_more === "boolean" ? response.data.has_more : false,
|
|
2410
|
+
data: response.data.data.map(normalizeWorkflowSummary)
|
|
2411
|
+
}
|
|
2412
|
+
};
|
|
2413
|
+
},
|
|
2414
|
+
async get(workflowId) {
|
|
2415
|
+
if (!workflowId) {
|
|
2416
|
+
return invalidResponse(400, "workflowId is required");
|
|
2417
|
+
}
|
|
2418
|
+
const response = await client.http.request({
|
|
2419
|
+
url: WORKFLOW_GET_PATH(workflowId),
|
|
2420
|
+
method: "GET"
|
|
2421
|
+
});
|
|
2422
|
+
if (!response.data || !isPlainObject4(response.data)) {
|
|
2423
|
+
return invalidResponse(
|
|
2424
|
+
response.status,
|
|
2425
|
+
response.error?.message || "Invalid workflow definition response structure"
|
|
2426
|
+
);
|
|
2427
|
+
}
|
|
2428
|
+
return {
|
|
2429
|
+
...response,
|
|
2430
|
+
data: normalizeWorkflowDefinition(response.data)
|
|
2431
|
+
};
|
|
2432
|
+
}
|
|
2433
|
+
};
|
|
2434
|
+
}
|
|
2133
2435
|
function loadOptionalJsonObjectInput3(input, label) {
|
|
2134
2436
|
if (!input) {
|
|
2135
2437
|
return {};
|
|
@@ -2150,11 +2452,11 @@ function loadOptionalJsonArrayInput(input, label) {
|
|
|
2150
2452
|
}
|
|
2151
2453
|
return value;
|
|
2152
2454
|
}
|
|
2153
|
-
function
|
|
2455
|
+
function exitWithCommandError4(spinner, failureMessage, error) {
|
|
2154
2456
|
spinner.fail(failureMessage);
|
|
2155
2457
|
const details = error instanceof Error ? error.message : String(error);
|
|
2156
2458
|
if (details) {
|
|
2157
|
-
console.error(
|
|
2459
|
+
console.error(chalk4.red(details));
|
|
2158
2460
|
}
|
|
2159
2461
|
process.exit(1);
|
|
2160
2462
|
}
|
|
@@ -2189,26 +2491,148 @@ async function runWorkflow(client, options) {
|
|
|
2189
2491
|
const result = await workflowClient.run(options.name, request);
|
|
2190
2492
|
if (result.error) {
|
|
2191
2493
|
spinner.fail("Failed to run workflow");
|
|
2192
|
-
console.error(
|
|
2494
|
+
console.error(chalk4.red(result.error.message));
|
|
2193
2495
|
process.exit(1);
|
|
2194
2496
|
}
|
|
2195
2497
|
spinner.succeed("Workflow completed");
|
|
2196
2498
|
renderOutput(result.data, {
|
|
2197
2499
|
format: options.format,
|
|
2198
2500
|
pretty: () => {
|
|
2199
|
-
console.log(
|
|
2501
|
+
console.log(chalk4.blue("\n\u26A1 Workflow Run\n"));
|
|
2200
2502
|
console.log(JSON.stringify(result.data, null, 2));
|
|
2201
2503
|
}
|
|
2202
2504
|
});
|
|
2203
2505
|
} catch (error) {
|
|
2204
|
-
|
|
2506
|
+
exitWithCommandError4(spinner, "Failed to run workflow", error);
|
|
2205
2507
|
}
|
|
2206
2508
|
}
|
|
2207
|
-
function
|
|
2509
|
+
async function listWorkflows(client, options = {}) {
|
|
2510
|
+
const spinner = createSpinner("Fetching workflows...", options.format);
|
|
2511
|
+
try {
|
|
2512
|
+
const workflowService = createWorkflowService(client);
|
|
2513
|
+
const result = await workflowService.list({
|
|
2514
|
+
page: options.page,
|
|
2515
|
+
limit: options.limit,
|
|
2516
|
+
mode: options.mode
|
|
2517
|
+
});
|
|
2518
|
+
if (result.error) {
|
|
2519
|
+
spinner.fail("Failed to fetch workflows");
|
|
2520
|
+
console.error(chalk4.red(result.error.message));
|
|
2521
|
+
process.exit(1);
|
|
2522
|
+
}
|
|
2523
|
+
const payload = result.data;
|
|
2524
|
+
const workflows = payload?.data || [];
|
|
2525
|
+
spinner.succeed(`Found ${workflows.length} workflow${workflows.length === 1 ? "" : "s"}`);
|
|
2526
|
+
renderOutput(payload, {
|
|
2527
|
+
format: options.format,
|
|
2528
|
+
tableRows: workflows.map((workflow) => ({
|
|
2529
|
+
id: workflow.id,
|
|
2530
|
+
runnableName: workflow.runnable_name,
|
|
2531
|
+
platformName: workflow.name,
|
|
2532
|
+
mode: workflow.mode,
|
|
2533
|
+
description: workflow.description
|
|
2534
|
+
})),
|
|
2535
|
+
csvRows: workflows.map((workflow) => ({
|
|
2536
|
+
id: workflow.id,
|
|
2537
|
+
runnableName: workflow.runnable_name,
|
|
2538
|
+
platformName: workflow.name,
|
|
2539
|
+
mode: workflow.mode,
|
|
2540
|
+
description: workflow.description
|
|
2541
|
+
})),
|
|
2542
|
+
ndjsonItems: workflows,
|
|
2543
|
+
pretty: () => {
|
|
2544
|
+
console.log(chalk4.blue("\nWorkflows\n"));
|
|
2545
|
+
if (workflows.length === 0) {
|
|
2546
|
+
console.log(chalk4.gray("No workflows found."));
|
|
2547
|
+
return;
|
|
2548
|
+
}
|
|
2549
|
+
for (const workflow of workflows) {
|
|
2550
|
+
console.log(`${chalk4.green("\u2022")} ${chalk4.bold(workflow.runnable_name || workflow.name)}`);
|
|
2551
|
+
console.log(` ${chalk4.gray("ID:")} ${workflow.id}`);
|
|
2552
|
+
console.log(` ${chalk4.gray("Platform Name:")} ${workflow.name}`);
|
|
2553
|
+
console.log(` ${chalk4.gray("Mode:")} ${workflow.mode || "workflow"}`);
|
|
2554
|
+
if (workflow.description) {
|
|
2555
|
+
console.log(` ${chalk4.gray("Description:")} ${workflow.description}`);
|
|
2556
|
+
}
|
|
2557
|
+
}
|
|
2558
|
+
}
|
|
2559
|
+
});
|
|
2560
|
+
} catch (error) {
|
|
2561
|
+
exitWithCommandError4(spinner, "Failed to fetch workflows", error);
|
|
2562
|
+
}
|
|
2563
|
+
}
|
|
2564
|
+
async function getWorkflow(client, options) {
|
|
2565
|
+
const spinner = createSpinner(`Fetching workflow: ${options.id}...`, options.format);
|
|
2566
|
+
try {
|
|
2567
|
+
const workflowService = createWorkflowService(client);
|
|
2568
|
+
const result = await workflowService.get(options.id);
|
|
2569
|
+
if (result.error) {
|
|
2570
|
+
spinner.fail("Failed to fetch workflow");
|
|
2571
|
+
console.error(chalk4.red(result.error.message));
|
|
2572
|
+
process.exit(1);
|
|
2573
|
+
}
|
|
2574
|
+
const workflow = result.data;
|
|
2575
|
+
const inputVariables = workflow?.input_variables || [];
|
|
2576
|
+
spinner.succeed("Workflow loaded");
|
|
2577
|
+
renderOutput(workflow, {
|
|
2578
|
+
format: options.format,
|
|
2579
|
+
tableRows: workflow ? [
|
|
2580
|
+
{
|
|
2581
|
+
appId: workflow.app_id,
|
|
2582
|
+
workflowId: workflow.workflow_id,
|
|
2583
|
+
runnableName: workflow.name,
|
|
2584
|
+
version: workflow.version || null,
|
|
2585
|
+
inputVariables: inputVariables.map((item) => item.variable).join(", ")
|
|
2586
|
+
}
|
|
2587
|
+
] : [],
|
|
2588
|
+
csvRows: workflow ? [
|
|
2589
|
+
{
|
|
2590
|
+
appId: workflow.app_id,
|
|
2591
|
+
workflowId: workflow.workflow_id,
|
|
2592
|
+
runnableName: workflow.name,
|
|
2593
|
+
version: workflow.version || null,
|
|
2594
|
+
inputVariables: inputVariables.map((item) => item.variable).join(", ")
|
|
2595
|
+
}
|
|
2596
|
+
] : [],
|
|
2597
|
+
ndjsonItems: workflow ? [workflow] : [],
|
|
2598
|
+
pretty: () => {
|
|
2599
|
+
if (!workflow) {
|
|
2600
|
+
console.log(chalk4.gray("No workflow found."));
|
|
2601
|
+
return;
|
|
2602
|
+
}
|
|
2603
|
+
console.log(chalk4.blue(`
|
|
2604
|
+
Workflow: ${workflow.name}
|
|
2605
|
+
`));
|
|
2606
|
+
console.log(`${chalk4.gray("App ID:")} ${workflow.app_id}`);
|
|
2607
|
+
console.log(`${chalk4.gray("Workflow ID:")} ${workflow.workflow_id}`);
|
|
2608
|
+
if (workflow.version) {
|
|
2609
|
+
console.log(`${chalk4.gray("Version:")} ${workflow.version}`);
|
|
2610
|
+
}
|
|
2611
|
+
console.log(`
|
|
2612
|
+
${chalk4.gray("Input Variables:")}`);
|
|
2613
|
+
if (inputVariables.length === 0) {
|
|
2614
|
+
console.log(chalk4.gray(" none"));
|
|
2615
|
+
} else {
|
|
2616
|
+
for (const variable of inputVariables) {
|
|
2617
|
+
const label = variable.label ? ` ${chalk4.gray(`(${variable.label})`)}` : "";
|
|
2618
|
+
const type = variable.type ? ` ${chalk4.gray(`[${variable.type}]`)}` : "";
|
|
2619
|
+
const required = variable.required ? chalk4.yellow(" required") : chalk4.gray(" optional");
|
|
2620
|
+
console.log(` - ${chalk4.bold(variable.variable)}${label}${type}${required}`);
|
|
2621
|
+
}
|
|
2622
|
+
}
|
|
2623
|
+
console.log(`
|
|
2624
|
+
${chalk4.gray("Run With:")} amaster workflow run ${workflow.name} --app <app-code> --input '{...}'`);
|
|
2625
|
+
}
|
|
2626
|
+
});
|
|
2627
|
+
} catch (error) {
|
|
2628
|
+
exitWithCommandError4(spinner, "Failed to fetch workflow", error);
|
|
2629
|
+
}
|
|
2630
|
+
}
|
|
2631
|
+
function exitWithCommandError5(spinner, failureMessage, error) {
|
|
2208
2632
|
spinner.fail(failureMessage);
|
|
2209
2633
|
const details = error instanceof Error ? error.message : String(error);
|
|
2210
2634
|
if (details) {
|
|
2211
|
-
console.error(
|
|
2635
|
+
console.error(chalk4.red(details));
|
|
2212
2636
|
}
|
|
2213
2637
|
process.exit(1);
|
|
2214
2638
|
}
|
|
@@ -2247,20 +2671,20 @@ async function uploadFile(client, options) {
|
|
|
2247
2671
|
const result = await s3Client.upload(file);
|
|
2248
2672
|
if (result.error) {
|
|
2249
2673
|
spinner.fail("Upload failed");
|
|
2250
|
-
console.error(
|
|
2674
|
+
console.error(chalk4.red(result.error.message));
|
|
2251
2675
|
process.exit(1);
|
|
2252
2676
|
}
|
|
2253
2677
|
spinner.succeed("Upload complete");
|
|
2254
2678
|
renderOutput(result.data, {
|
|
2255
2679
|
format: options.format,
|
|
2256
2680
|
pretty: () => {
|
|
2257
|
-
console.log(
|
|
2258
|
-
console.log(` ${
|
|
2259
|
-
console.log(` ${
|
|
2681
|
+
console.log(chalk4.green("\nFile uploaded:"));
|
|
2682
|
+
console.log(` ${chalk4.bold("Key:")} ${result.data?.key}`);
|
|
2683
|
+
console.log(` ${chalk4.bold("URL:")} ${result.data?.url || "N/A"}`);
|
|
2260
2684
|
}
|
|
2261
2685
|
});
|
|
2262
2686
|
} catch (error) {
|
|
2263
|
-
|
|
2687
|
+
exitWithCommandError5(spinner, "Upload failed", error);
|
|
2264
2688
|
}
|
|
2265
2689
|
}
|
|
2266
2690
|
async function downloadFile(client, options) {
|
|
@@ -2270,12 +2694,12 @@ async function downloadFile(client, options) {
|
|
|
2270
2694
|
const result = await s3Client.download(options.key);
|
|
2271
2695
|
if (result.error) {
|
|
2272
2696
|
spinner.fail("Download failed");
|
|
2273
|
-
console.error(
|
|
2697
|
+
console.error(chalk4.red(result.error.message));
|
|
2274
2698
|
process.exit(1);
|
|
2275
2699
|
}
|
|
2276
2700
|
if (!result.data) {
|
|
2277
2701
|
spinner.fail("Download failed");
|
|
2278
|
-
console.error(
|
|
2702
|
+
console.error(chalk4.red("Empty file response."));
|
|
2279
2703
|
process.exit(1);
|
|
2280
2704
|
}
|
|
2281
2705
|
const outputPath = resolve(options.output);
|
|
@@ -2291,13 +2715,13 @@ async function downloadFile(client, options) {
|
|
|
2291
2715
|
{
|
|
2292
2716
|
format: options.format,
|
|
2293
2717
|
pretty: () => {
|
|
2294
|
-
console.log(
|
|
2718
|
+
console.log(chalk4.green(`
|
|
2295
2719
|
File saved to: ${outputPath}`));
|
|
2296
2720
|
}
|
|
2297
2721
|
}
|
|
2298
2722
|
);
|
|
2299
2723
|
} catch (error) {
|
|
2300
|
-
|
|
2724
|
+
exitWithCommandError5(spinner, "Download failed", error);
|
|
2301
2725
|
}
|
|
2302
2726
|
}
|
|
2303
2727
|
async function getFileMetadata(client, options) {
|
|
@@ -2307,21 +2731,21 @@ async function getFileMetadata(client, options) {
|
|
|
2307
2731
|
const result = await s3Client.getMetadata(options.key);
|
|
2308
2732
|
if (result.error) {
|
|
2309
2733
|
spinner.fail("Failed to fetch metadata");
|
|
2310
|
-
console.error(
|
|
2734
|
+
console.error(chalk4.red(result.error.message));
|
|
2311
2735
|
process.exit(1);
|
|
2312
2736
|
}
|
|
2313
2737
|
spinner.succeed("Metadata retrieved");
|
|
2314
2738
|
renderOutput(result.data, {
|
|
2315
2739
|
format: options.format,
|
|
2316
2740
|
pretty: () => {
|
|
2317
|
-
console.log(
|
|
2741
|
+
console.log(chalk4.blue(`
|
|
2318
2742
|
\u{1F4C4} Metadata for ${options.key}
|
|
2319
2743
|
`));
|
|
2320
2744
|
console.log(JSON.stringify(result.data, null, 2));
|
|
2321
2745
|
}
|
|
2322
2746
|
});
|
|
2323
2747
|
} catch (error) {
|
|
2324
|
-
|
|
2748
|
+
exitWithCommandError5(spinner, "Failed to fetch metadata", error);
|
|
2325
2749
|
}
|
|
2326
2750
|
}
|
|
2327
2751
|
|
|
@@ -2362,8 +2786,8 @@ async function initOpenClaw(options) {
|
|
|
2362
2786
|
const existingConfig = getAppConfig(options.appCode);
|
|
2363
2787
|
if (existingConfig && !options.force) {
|
|
2364
2788
|
spinner.fail(`App already exists: ${options.appCode}`);
|
|
2365
|
-
console.log(
|
|
2366
|
-
console.log(
|
|
2789
|
+
console.log(chalk4.yellow(`Use --force to reinitialize`));
|
|
2790
|
+
console.log(chalk4.gray(`Current URL: ${existingConfig.baseURL}`));
|
|
2367
2791
|
process.exit(1);
|
|
2368
2792
|
}
|
|
2369
2793
|
addApp(options.appCode, {
|
|
@@ -2374,8 +2798,8 @@ async function initOpenClaw(options) {
|
|
|
2374
2798
|
if (!openClawDetected) {
|
|
2375
2799
|
spinner.succeed(`App initialized: ${options.appCode}`);
|
|
2376
2800
|
if (pretty) {
|
|
2377
|
-
console.log(
|
|
2378
|
-
console.log(
|
|
2801
|
+
console.log(chalk4.yellow("\n\u26A0\uFE0F OpenClaw not detected, skipping skill download"));
|
|
2802
|
+
console.log(chalk4.gray(" Install OpenClaw: npm install -g openclaw"));
|
|
2379
2803
|
} else {
|
|
2380
2804
|
renderOutput(
|
|
2381
2805
|
{
|
|
@@ -2393,9 +2817,9 @@ async function initOpenClaw(options) {
|
|
|
2393
2817
|
}
|
|
2394
2818
|
spinner.succeed(`App initialized: ${options.appCode}`);
|
|
2395
2819
|
if (pretty) {
|
|
2396
|
-
console.log(
|
|
2397
|
-
console.log(` App Code: ${
|
|
2398
|
-
console.log(` Base URL: ${
|
|
2820
|
+
console.log(chalk4.blue("\n\u{1F4CB} Configuration:\n"));
|
|
2821
|
+
console.log(` App Code: ${chalk4.green(options.appCode)}`);
|
|
2822
|
+
console.log(` Base URL: ${chalk4.gray(options.baseURL)}`);
|
|
2399
2823
|
console.log();
|
|
2400
2824
|
}
|
|
2401
2825
|
spinner.start("Downloading skills...");
|
|
@@ -2467,16 +2891,16 @@ async function initOpenClaw(options) {
|
|
|
2467
2891
|
};
|
|
2468
2892
|
if (pretty) {
|
|
2469
2893
|
console.log();
|
|
2470
|
-
console.log(
|
|
2894
|
+
console.log(chalk4.green("\u2705 Initialization complete!"));
|
|
2471
2895
|
console.log();
|
|
2472
2896
|
console.log(`Next step: Login to your app`);
|
|
2473
|
-
console.log(
|
|
2897
|
+
console.log(chalk4.gray(` amaster login --app ${options.appCode}`));
|
|
2474
2898
|
console.log();
|
|
2475
2899
|
if (apps.length > 1) {
|
|
2476
|
-
console.log(
|
|
2900
|
+
console.log(chalk4.blue("Configured apps:"));
|
|
2477
2901
|
for (const app of apps) {
|
|
2478
2902
|
const config = getAppConfig(app);
|
|
2479
|
-
console.log(` ${
|
|
2903
|
+
console.log(` ${chalk4.gray("\u2022")} ${app} - ${config?.baseURL}`);
|
|
2480
2904
|
}
|
|
2481
2905
|
console.log();
|
|
2482
2906
|
}
|
|
@@ -2577,6 +3001,14 @@ async function downloadMcpConfig(ossEndpoint, appCode) {
|
|
|
2577
3001
|
}
|
|
2578
3002
|
|
|
2579
3003
|
// src/cli.ts
|
|
3004
|
+
function resolveCliVersion() {
|
|
3005
|
+
try {
|
|
3006
|
+
const packageJsonUrl = new URL("../package.json", import.meta.url);
|
|
3007
|
+
return JSON.parse(readFileSync(packageJsonUrl, "utf-8")).version || "0.0.0";
|
|
3008
|
+
} catch {
|
|
3009
|
+
return "0.0.0";
|
|
3010
|
+
}
|
|
3011
|
+
}
|
|
2580
3012
|
function resolveAppCode(optionsApp) {
|
|
2581
3013
|
if (optionsApp) {
|
|
2582
3014
|
return optionsApp;
|
|
@@ -2585,38 +3017,39 @@ function resolveAppCode(optionsApp) {
|
|
|
2585
3017
|
if (defaultApp) {
|
|
2586
3018
|
return defaultApp;
|
|
2587
3019
|
}
|
|
2588
|
-
console.error(
|
|
2589
|
-
console.log(
|
|
2590
|
-
console.log(
|
|
2591
|
-
console.log(
|
|
3020
|
+
console.error(chalk4.red("\u274C No app specified."));
|
|
3021
|
+
console.log(chalk4.yellow("Use one of:"));
|
|
3022
|
+
console.log(chalk4.gray(" 1. Add --app <app-code> to the command"));
|
|
3023
|
+
console.log(chalk4.gray(" 2. Set a default app: amaster use <app-code>"));
|
|
2592
3024
|
process.exit(1);
|
|
2593
3025
|
}
|
|
2594
3026
|
function createAmasterClient(appCode) {
|
|
2595
3027
|
const appConfig = getAppConfig(appCode);
|
|
2596
3028
|
if (!appConfig) {
|
|
2597
|
-
console.error(
|
|
2598
|
-
console.log(
|
|
3029
|
+
console.error(chalk4.red(`\u274C App not configured: ${appCode}`));
|
|
3030
|
+
console.log(chalk4.yellow(`Initialize it first: amaster init --app-code ${appCode} --url <url>`));
|
|
2599
3031
|
process.exit(1);
|
|
2600
3032
|
}
|
|
2601
3033
|
const token = getAccessToken(appCode);
|
|
2602
3034
|
if (token && shouldRefreshToken(appCode)) {
|
|
2603
|
-
console.error(
|
|
3035
|
+
console.error(chalk4.yellow("\u26A0\uFE0F Session expiring soon. Please login again."));
|
|
2604
3036
|
}
|
|
2605
3037
|
const client = createClient({
|
|
2606
3038
|
baseURL: appConfig.baseURL,
|
|
2607
|
-
|
|
2608
|
-
|
|
3039
|
+
headers: {
|
|
3040
|
+
"x-app-code": appCode,
|
|
3041
|
+
...token ? {
|
|
2609
3042
|
Authorization: `Bearer ${token}`
|
|
2610
|
-
}
|
|
2611
|
-
}
|
|
3043
|
+
} : {}
|
|
3044
|
+
},
|
|
2612
3045
|
onUnauthorized: () => {
|
|
2613
3046
|
if (token) {
|
|
2614
|
-
console.error(
|
|
2615
|
-
console.error(
|
|
3047
|
+
console.error(chalk4.red("\n\u274C Session expired. Please login again."));
|
|
3048
|
+
console.error(chalk4.yellow(`Run: amaster login --app ${appCode}`));
|
|
2616
3049
|
} else {
|
|
2617
|
-
console.error(
|
|
3050
|
+
console.error(chalk4.red(`
|
|
2618
3051
|
\u274C Authentication required for app: ${appCode}`));
|
|
2619
|
-
console.error(
|
|
3052
|
+
console.error(chalk4.yellow(`Run: amaster login --app ${appCode}`));
|
|
2620
3053
|
}
|
|
2621
3054
|
process.exit(1);
|
|
2622
3055
|
}
|
|
@@ -2627,7 +3060,7 @@ function createAmasterClient(appCode) {
|
|
|
2627
3060
|
return client;
|
|
2628
3061
|
}
|
|
2629
3062
|
var program = new Command();
|
|
2630
|
-
program.name("amaster").description("CLI for Amaster SDK - Multi-app support for OpenClaw").version(
|
|
3063
|
+
program.name("amaster").description("CLI for Amaster SDK - Multi-app support for OpenClaw").version(resolveCliVersion());
|
|
2631
3064
|
program.command("apps").description("List all configured apps").addOption(createFormatOption()).action((options) => {
|
|
2632
3065
|
const apps = listApps();
|
|
2633
3066
|
const current = getCurrentApp();
|
|
@@ -2643,17 +3076,17 @@ program.command("apps").description("List all configured apps").addOption(create
|
|
|
2643
3076
|
renderOutput(appSummaries, {
|
|
2644
3077
|
format: options.format,
|
|
2645
3078
|
pretty: () => {
|
|
2646
|
-
console.log(
|
|
3079
|
+
console.log(chalk4.blue("\n\u{1F4F1} Configured Apps\n"));
|
|
2647
3080
|
if (appSummaries.length === 0) {
|
|
2648
|
-
console.log(
|
|
2649
|
-
console.log(
|
|
3081
|
+
console.log(chalk4.gray(" No apps configured"));
|
|
3082
|
+
console.log(chalk4.gray(" Run: amaster init --app-code <code> --url <url>"));
|
|
2650
3083
|
} else {
|
|
2651
3084
|
for (const app of appSummaries) {
|
|
2652
|
-
const prefix = app.current ?
|
|
2653
|
-
console.log(`${prefix}${
|
|
2654
|
-
console.log(` ${
|
|
3085
|
+
const prefix = app.current ? chalk4.green("\u2192 ") : " ";
|
|
3086
|
+
console.log(`${prefix}${chalk4.bold(app.appCode)}${app.current ? chalk4.green(" (current)") : ""}`);
|
|
3087
|
+
console.log(` ${chalk4.gray(app.baseURL || "No URL")}`);
|
|
2655
3088
|
console.log(
|
|
2656
|
-
` ${app.authenticated ?
|
|
3089
|
+
` ${app.authenticated ? chalk4.green("\u25CF Authenticated") : chalk4.yellow("\u25CB Not authenticated")}`
|
|
2657
3090
|
);
|
|
2658
3091
|
console.log();
|
|
2659
3092
|
}
|
|
@@ -2672,12 +3105,12 @@ program.command("use <app-code>").description("Set the default app for subsequen
|
|
|
2672
3105
|
{
|
|
2673
3106
|
format: options.format,
|
|
2674
3107
|
pretty: () => {
|
|
2675
|
-
console.log(
|
|
3108
|
+
console.log(chalk4.green(`\u2705 Now using app: ${appCode}`));
|
|
2676
3109
|
}
|
|
2677
3110
|
}
|
|
2678
3111
|
);
|
|
2679
3112
|
} else {
|
|
2680
|
-
console.error(
|
|
3113
|
+
console.error(chalk4.red(`\u274C App not found: ${appCode}`));
|
|
2681
3114
|
process.exit(1);
|
|
2682
3115
|
}
|
|
2683
3116
|
});
|
|
@@ -2794,6 +3227,21 @@ entityCmd.command("bulk-delete <namespace> <entity>").description("Bulk delete e
|
|
|
2794
3227
|
format: options.format
|
|
2795
3228
|
});
|
|
2796
3229
|
});
|
|
3230
|
+
var modelCmd = program.command("model").description("Discover runtime datasources and table schemas");
|
|
3231
|
+
modelCmd.command("datasources").description("List runtime datasources with their models").option("--app <app-code>", "App code (uses default if not specified)").addOption(createFormatOption()).action(async (options) => {
|
|
3232
|
+
const appCode = resolveAppCode(options.app);
|
|
3233
|
+
await listDatasources(createAmasterClient(appCode), {
|
|
3234
|
+
format: options.format
|
|
3235
|
+
});
|
|
3236
|
+
});
|
|
3237
|
+
modelCmd.command("table-schema <source-id>").description("Get CREATE TABLE statements for one datasource").option("--app <app-code>", "App code (uses default if not specified)").option("--tables <tables>", "Comma-separated table names, JSON array, or @file").addOption(createFormatOption()).action(async (sourceId, options) => {
|
|
3238
|
+
const appCode = resolveAppCode(options.app);
|
|
3239
|
+
await getTableSchema(createAmasterClient(appCode), {
|
|
3240
|
+
sourceId,
|
|
3241
|
+
tables: options.tables,
|
|
3242
|
+
format: options.format
|
|
3243
|
+
});
|
|
3244
|
+
});
|
|
2797
3245
|
var bpmCmd = program.command("bpm").description("Manage BPM processes and tasks");
|
|
2798
3246
|
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) => {
|
|
2799
3247
|
const appCode = resolveAppCode(options.app);
|
|
@@ -3146,7 +3594,25 @@ bpmCmd.command("start-form-deployed <key>").description("Get deployed start form
|
|
|
3146
3594
|
format: options.format
|
|
3147
3595
|
});
|
|
3148
3596
|
});
|
|
3149
|
-
var workflowCmd = program.command("workflow").description("
|
|
3597
|
+
var workflowCmd = program.command("workflow").description("Inspect and run workflows");
|
|
3598
|
+
workflowCmd.command("list").description("List runnable workflows").option("--app <app-code>", "App code (uses default if not specified)").option("--page <n>", "Page number").option("--limit <n>", "Page size").addOption(
|
|
3599
|
+
new Option("--mode <mode>", "Workflow app mode").choices(["workflow", "chat", "completion", "agent-chat"])
|
|
3600
|
+
).addOption(createFormatOption()).action(async (options) => {
|
|
3601
|
+
const appCode = resolveAppCode(options.app);
|
|
3602
|
+
await listWorkflows(createAmasterClient(appCode), {
|
|
3603
|
+
page: options.page ? parseInt(options.page, 10) : void 0,
|
|
3604
|
+
limit: options.limit ? parseInt(options.limit, 10) : void 0,
|
|
3605
|
+
mode: options.mode,
|
|
3606
|
+
format: options.format
|
|
3607
|
+
});
|
|
3608
|
+
});
|
|
3609
|
+
workflowCmd.command("get <id>").alias("inspect").description("Get workflow details and input variables by workflow app ID").option("--app <app-code>", "App code (uses default if not specified)").addOption(createFormatOption()).action(async (id, options) => {
|
|
3610
|
+
const appCode = resolveAppCode(options.app);
|
|
3611
|
+
await getWorkflow(createAmasterClient(appCode), {
|
|
3612
|
+
id,
|
|
3613
|
+
format: options.format
|
|
3614
|
+
});
|
|
3615
|
+
});
|
|
3150
3616
|
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(
|
|
3151
3617
|
new Option("--response-mode <mode>", "Workflow response mode").choices(["blocking", "streaming"])
|
|
3152
3618
|
).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) => {
|