fastclaw-cli 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +140 -57
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -534,8 +534,8 @@ function registerAppsCommand(admin) {
|
|
|
534
534
|
}
|
|
535
535
|
})
|
|
536
536
|
);
|
|
537
|
-
apps.command("list").description("List all apps").action(
|
|
538
|
-
withErrorHandler(async () => {
|
|
537
|
+
apps.command("list").description("List all apps").option("-t, --show-token", "Show full API token (masked by default)").action(
|
|
538
|
+
withErrorHandler(async (cmdOpts) => {
|
|
539
539
|
const { client, cfg } = getClient(apps);
|
|
540
540
|
const list = await client.listApps();
|
|
541
541
|
if (cfg.json) {
|
|
@@ -543,9 +543,16 @@ function registerAppsCommand(admin) {
|
|
|
543
543
|
} else if (list.length === 0) {
|
|
544
544
|
console.log(chalk4.dim("No apps found."));
|
|
545
545
|
} else {
|
|
546
|
+
const maskToken2 = (token) => token.length > 8 ? token.slice(0, 4) + "****" + token.slice(-4) : "****";
|
|
546
547
|
printTable(
|
|
547
|
-
["ID", "Name", "Status", "Created"],
|
|
548
|
-
list.map((a) => [
|
|
548
|
+
["ID", "Name", "Token", "Status", "Created"],
|
|
549
|
+
list.map((a) => [
|
|
550
|
+
a.id,
|
|
551
|
+
a.name,
|
|
552
|
+
cmdOpts.showToken ? a.api_token : maskToken2(a.api_token),
|
|
553
|
+
a.status,
|
|
554
|
+
a.created_at
|
|
555
|
+
])
|
|
549
556
|
);
|
|
550
557
|
}
|
|
551
558
|
})
|
|
@@ -583,12 +590,50 @@ function registerAdminCommand(program2) {
|
|
|
583
590
|
|
|
584
591
|
// src/commands/bot/crud.ts
|
|
585
592
|
import chalk5 from "chalk";
|
|
586
|
-
|
|
587
|
-
|
|
593
|
+
|
|
594
|
+
// src/commands/bot/resolve.ts
|
|
595
|
+
function getClient2(cmd) {
|
|
596
|
+
const opts = { ...cmd.parent.opts(), ...cmd.opts() };
|
|
588
597
|
const cfg = resolveConfig(opts);
|
|
589
598
|
requireOption(cfg.appToken, "app-token");
|
|
590
599
|
return { client: new FastClawClient({ url: cfg.url, appToken: cfg.appToken }), cfg };
|
|
591
600
|
}
|
|
601
|
+
function getAdminClient(cmd) {
|
|
602
|
+
const opts = { ...cmd.parent.opts(), ...cmd.opts() };
|
|
603
|
+
const cfg = resolveConfig(opts);
|
|
604
|
+
requireOption(cfg.adminToken, "admin-token");
|
|
605
|
+
return { client: new FastClawClient({ url: cfg.url, adminToken: cfg.adminToken }), cfg };
|
|
606
|
+
}
|
|
607
|
+
async function resolveClientForBot(cmd, botId) {
|
|
608
|
+
const opts = { ...cmd.parent.opts(), ...cmd.opts() };
|
|
609
|
+
const cfg = resolveConfig(opts);
|
|
610
|
+
if (cfg.appToken) {
|
|
611
|
+
try {
|
|
612
|
+
const client = new FastClawClient({ url: cfg.url, appToken: cfg.appToken });
|
|
613
|
+
await client.getBot(botId);
|
|
614
|
+
return { client, cfg };
|
|
615
|
+
} catch {
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
if (cfg.adminToken) {
|
|
619
|
+
const adminClient = new FastClawClient({ url: cfg.url, adminToken: cfg.adminToken });
|
|
620
|
+
const apps = await adminClient.listApps();
|
|
621
|
+
for (const app of apps) {
|
|
622
|
+
try {
|
|
623
|
+
const appClient = new FastClawClient({ url: cfg.url, appToken: app.api_token });
|
|
624
|
+
await appClient.getBot(botId);
|
|
625
|
+
return { client: appClient, cfg };
|
|
626
|
+
} catch {
|
|
627
|
+
continue;
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
throw new Error(
|
|
632
|
+
`Bot ${botId} not found. Ensure the correct --app-token is set, or provide --admin-token for cross-app lookup.`
|
|
633
|
+
);
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
// src/commands/bot/crud.ts
|
|
592
637
|
function registerBotCrudCommands(bot) {
|
|
593
638
|
bot.command("create").description("Create a new bot").requiredOption("-n, --name <name>", "Bot name").option("--slug <slug>", "URL slug").option("--user-id <userId>", "User ID").option("--expires-at <date>", "Expiration date (ISO-8601)").action(
|
|
594
639
|
withErrorHandler(async (cmdOpts) => {
|
|
@@ -615,26 +660,70 @@ function registerBotCrudCommands(bot) {
|
|
|
615
660
|
}
|
|
616
661
|
})
|
|
617
662
|
);
|
|
618
|
-
bot.command("list").description("List bots").option("--user-id <userId>", "User ID").action(
|
|
663
|
+
bot.command("list").description("List bots").option("--user-id <userId>", "User ID").option("-A, --all", "List bots across all apps (requires admin token)").action(
|
|
619
664
|
withErrorHandler(async (cmdOpts) => {
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
665
|
+
if (cmdOpts.all) {
|
|
666
|
+
const { client: adminClient, cfg } = getAdminClient(bot);
|
|
667
|
+
const userId = cmdOpts.userId || cfg.userId;
|
|
668
|
+
const apps = await adminClient.listApps();
|
|
669
|
+
const allBots = [];
|
|
670
|
+
for (const app of apps) {
|
|
671
|
+
const appClient = new FastClawClient({ url: cfg.url, appToken: app.api_token });
|
|
672
|
+
try {
|
|
673
|
+
const bots = await appClient.listBots(userId);
|
|
674
|
+
for (const b of bots) {
|
|
675
|
+
let ready = "-";
|
|
676
|
+
if (b.status === "running") {
|
|
677
|
+
try {
|
|
678
|
+
const s = await appClient.getBotStatus(b.id);
|
|
679
|
+
ready = s.ready ? "yes" : "no";
|
|
680
|
+
} catch {
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
allBots.push({ app_name: app.name, bot: b, ready });
|
|
684
|
+
}
|
|
685
|
+
} catch {
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
if (cfg.json) {
|
|
689
|
+
printJson(allBots.map((x) => ({ ...x.bot, app_name: x.app_name, ready: x.ready })));
|
|
690
|
+
} else if (allBots.length === 0) {
|
|
691
|
+
console.log(chalk5.dim("No bots found."));
|
|
692
|
+
} else {
|
|
693
|
+
printTable(
|
|
694
|
+
["App", "ID", "Name", "Slug", "Status", "Ready", "Created"],
|
|
695
|
+
allBots.map((x) => [x.app_name, x.bot.id, x.bot.name, x.bot.slug, x.bot.status, x.ready, x.bot.created_at])
|
|
696
|
+
);
|
|
697
|
+
}
|
|
627
698
|
} else {
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
)
|
|
699
|
+
const { client, cfg } = getClient2(bot);
|
|
700
|
+
const userId = cmdOpts.userId || cfg.userId;
|
|
701
|
+
const list = await client.listBots(userId);
|
|
702
|
+
if (cfg.json) {
|
|
703
|
+
printJson(list);
|
|
704
|
+
} else if (list.length === 0) {
|
|
705
|
+
console.log(chalk5.dim("No bots found."));
|
|
706
|
+
} else {
|
|
707
|
+
const rows = [];
|
|
708
|
+
for (const b of list) {
|
|
709
|
+
let ready = "-";
|
|
710
|
+
if (b.status === "running") {
|
|
711
|
+
try {
|
|
712
|
+
const s = await client.getBotStatus(b.id);
|
|
713
|
+
ready = s.ready ? "yes" : "no";
|
|
714
|
+
} catch {
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
rows.push([b.id, b.name, b.slug, b.status, ready, b.created_at]);
|
|
718
|
+
}
|
|
719
|
+
printTable(["ID", "Name", "Slug", "Status", "Ready", "Created"], rows);
|
|
720
|
+
}
|
|
632
721
|
}
|
|
633
722
|
})
|
|
634
723
|
);
|
|
635
724
|
bot.command("get <id>").description("Get bot details").action(
|
|
636
725
|
withErrorHandler(async (id) => {
|
|
637
|
-
const { client, cfg } =
|
|
726
|
+
const { client, cfg } = await resolveClientForBot(bot, id);
|
|
638
727
|
const b = await client.getBot(id);
|
|
639
728
|
if (cfg.json) {
|
|
640
729
|
printJson(b);
|
|
@@ -658,7 +747,7 @@ function registerBotCrudCommands(bot) {
|
|
|
658
747
|
);
|
|
659
748
|
bot.command("update <id>").description("Update a bot").option("-n, --name <name>", "New name").option("--slug <slug>", "New slug").option("--expires-at <date>", "New expiration date").action(
|
|
660
749
|
withErrorHandler(async (id, cmdOpts) => {
|
|
661
|
-
const { client, cfg } =
|
|
750
|
+
const { client, cfg } = await resolveClientForBot(bot, id);
|
|
662
751
|
const result = await client.updateBot(id, {
|
|
663
752
|
name: cmdOpts.name,
|
|
664
753
|
slug: cmdOpts.slug,
|
|
@@ -673,7 +762,7 @@ function registerBotCrudCommands(bot) {
|
|
|
673
762
|
);
|
|
674
763
|
bot.command("delete <id>").description("Delete a bot").action(
|
|
675
764
|
withErrorHandler(async (id) => {
|
|
676
|
-
const { client, cfg } =
|
|
765
|
+
const { client, cfg } = await resolveClientForBot(bot, id);
|
|
677
766
|
const res = await client.deleteBot(id);
|
|
678
767
|
if (cfg.json) {
|
|
679
768
|
printJson(res);
|
|
@@ -686,12 +775,6 @@ function registerBotCrudCommands(bot) {
|
|
|
686
775
|
|
|
687
776
|
// src/commands/bot/lifecycle.ts
|
|
688
777
|
import chalk6 from "chalk";
|
|
689
|
-
function getClient3(bot) {
|
|
690
|
-
const opts = { ...bot.parent.opts(), ...bot.opts() };
|
|
691
|
-
const cfg = resolveConfig(opts);
|
|
692
|
-
requireOption(cfg.appToken, "app-token");
|
|
693
|
-
return { client: new FastClawClient({ url: cfg.url, appToken: cfg.appToken }), cfg };
|
|
694
|
-
}
|
|
695
778
|
function buildBotUrls(baseUrl, slug, accessToken) {
|
|
696
779
|
const { hostname } = new URL(baseUrl);
|
|
697
780
|
const webchatUrl = `https://${slug}.${hostname}#token=${accessToken}`;
|
|
@@ -701,7 +784,7 @@ function buildBotUrls(baseUrl, slug, accessToken) {
|
|
|
701
784
|
function registerBotLifecycleCommands(bot) {
|
|
702
785
|
bot.command("start <id>").description("Start a bot").option("--wait", "Wait until bot is ready", true).action(
|
|
703
786
|
withErrorHandler(async (id, cmdOpts) => {
|
|
704
|
-
const { client, cfg } =
|
|
787
|
+
const { client, cfg } = await resolveClientForBot(bot, id);
|
|
705
788
|
await client.startBot(id);
|
|
706
789
|
if (cmdOpts.wait) {
|
|
707
790
|
const spinner = startSpinner("Waiting for bot to be ready...");
|
|
@@ -722,7 +805,7 @@ function registerBotLifecycleCommands(bot) {
|
|
|
722
805
|
);
|
|
723
806
|
bot.command("stop <id>").description("Stop a bot").action(
|
|
724
807
|
withErrorHandler(async (id) => {
|
|
725
|
-
const { client, cfg } =
|
|
808
|
+
const { client, cfg } = await resolveClientForBot(bot, id);
|
|
726
809
|
const res = await client.stopBot(id);
|
|
727
810
|
if (cfg.json) {
|
|
728
811
|
printJson(res);
|
|
@@ -733,7 +816,7 @@ function registerBotLifecycleCommands(bot) {
|
|
|
733
816
|
);
|
|
734
817
|
bot.command("restart <id>").description("Restart a bot").action(
|
|
735
818
|
withErrorHandler(async (id) => {
|
|
736
|
-
const { client, cfg } =
|
|
819
|
+
const { client, cfg } = await resolveClientForBot(bot, id);
|
|
737
820
|
const res = await client.restartBot(id);
|
|
738
821
|
if (cfg.json) {
|
|
739
822
|
printJson(res);
|
|
@@ -744,7 +827,7 @@ function registerBotLifecycleCommands(bot) {
|
|
|
744
827
|
);
|
|
745
828
|
bot.command("status <id>").description("Get bot status").action(
|
|
746
829
|
withErrorHandler(async (id) => {
|
|
747
|
-
const { client, cfg } =
|
|
830
|
+
const { client, cfg } = await resolveClientForBot(bot, id);
|
|
748
831
|
const s = await client.getBotStatus(id);
|
|
749
832
|
const urls = s.status === "running" && s.ready ? await client.getBot(id).then((b) => buildBotUrls(cfg.url, b.slug, b.access_token)) : null;
|
|
750
833
|
if (cfg.json) {
|
|
@@ -772,7 +855,7 @@ function registerBotLifecycleCommands(bot) {
|
|
|
772
855
|
);
|
|
773
856
|
bot.command("connect <id>").description("Get bot connection info").action(
|
|
774
857
|
withErrorHandler(async (id) => {
|
|
775
|
-
const { client, cfg } =
|
|
858
|
+
const { client, cfg } = await resolveClientForBot(bot, id);
|
|
776
859
|
const [c, b] = await Promise.all([client.getBotConnect(id), client.getBot(id)]);
|
|
777
860
|
const urls = buildBotUrls(cfg.url, b.slug, b.access_token);
|
|
778
861
|
if (cfg.json) {
|
|
@@ -793,7 +876,7 @@ function registerBotLifecycleCommands(bot) {
|
|
|
793
876
|
);
|
|
794
877
|
bot.command("reset-token <id>").description("Reset bot access token").action(
|
|
795
878
|
withErrorHandler(async (id) => {
|
|
796
|
-
const { client, cfg } =
|
|
879
|
+
const { client, cfg } = await resolveClientForBot(bot, id);
|
|
797
880
|
const res = await client.resetBotToken(id);
|
|
798
881
|
if (cfg.json) {
|
|
799
882
|
printJson(res);
|
|
@@ -831,7 +914,7 @@ async function promptSelect(message, choices) {
|
|
|
831
914
|
}
|
|
832
915
|
|
|
833
916
|
// src/commands/model/provider.ts
|
|
834
|
-
function
|
|
917
|
+
function getClient3(model) {
|
|
835
918
|
const opts = model.parent.opts();
|
|
836
919
|
const cfg = resolveConfig(opts);
|
|
837
920
|
requireOption(cfg.appToken, "app-token");
|
|
@@ -840,7 +923,7 @@ function getClient4(model) {
|
|
|
840
923
|
function registerModelProviderCommands(model) {
|
|
841
924
|
model.command("add <bot-id>").description("Add a model provider (interactive or preset)").option("-p, --provider <name>", "Provider name or preset (google/anthropic/openai)").option("-k, --api-key <key>", "API key").action(
|
|
842
925
|
withErrorHandler(async (botId, cmdOpts) => {
|
|
843
|
-
const { client, cfg } =
|
|
926
|
+
const { client, cfg } = getClient3(model);
|
|
844
927
|
let providerName = cmdOpts.provider;
|
|
845
928
|
let apiKey = cmdOpts.apiKey;
|
|
846
929
|
if (!providerName) {
|
|
@@ -883,7 +966,7 @@ function registerModelProviderCommands(model) {
|
|
|
883
966
|
);
|
|
884
967
|
model.command("list <bot-id>").description("List model providers").action(
|
|
885
968
|
withErrorHandler(async (botId) => {
|
|
886
|
-
const { client, cfg } =
|
|
969
|
+
const { client, cfg } = getClient3(model);
|
|
887
970
|
const providers = await client.listProviders(botId);
|
|
888
971
|
if (cfg.json) {
|
|
889
972
|
printJson(providers);
|
|
@@ -901,7 +984,7 @@ function registerModelProviderCommands(model) {
|
|
|
901
984
|
);
|
|
902
985
|
model.command("get <bot-id> <provider>").description("Get provider details").action(
|
|
903
986
|
withErrorHandler(async (botId, provider) => {
|
|
904
|
-
const { client, cfg } =
|
|
987
|
+
const { client, cfg } = getClient3(model);
|
|
905
988
|
const p = await client.getProvider(botId, provider);
|
|
906
989
|
if (cfg.json) {
|
|
907
990
|
printJson(p);
|
|
@@ -917,7 +1000,7 @@ function registerModelProviderCommands(model) {
|
|
|
917
1000
|
);
|
|
918
1001
|
model.command("delete <bot-id> <provider>").description("Delete a model provider").action(
|
|
919
1002
|
withErrorHandler(async (botId, provider) => {
|
|
920
|
-
const { client, cfg } =
|
|
1003
|
+
const { client, cfg } = getClient3(model);
|
|
921
1004
|
await client.deleteProvider(botId, provider);
|
|
922
1005
|
if (cfg.json) {
|
|
923
1006
|
printJson({ message: "deleted" });
|
|
@@ -929,7 +1012,7 @@ function registerModelProviderCommands(model) {
|
|
|
929
1012
|
const defaults = model.command("defaults").description("Manage default model settings");
|
|
930
1013
|
defaults.command("get <bot-id>").description("Get default model settings").action(
|
|
931
1014
|
withErrorHandler(async (botId) => {
|
|
932
|
-
const { client, cfg } =
|
|
1015
|
+
const { client, cfg } = getClient3(model);
|
|
933
1016
|
const d = await client.getDefaults(botId);
|
|
934
1017
|
if (cfg.json) {
|
|
935
1018
|
printJson(d);
|
|
@@ -943,7 +1026,7 @@ function registerModelProviderCommands(model) {
|
|
|
943
1026
|
);
|
|
944
1027
|
defaults.command("set <bot-id>").description("Set default model").option("--primary <model>", "Primary model (provider/model_id)").option("--fallback <model>", "Fallback model").action(
|
|
945
1028
|
withErrorHandler(async (botId, cmdOpts) => {
|
|
946
|
-
const { client, cfg } =
|
|
1029
|
+
const { client, cfg } = getClient3(model);
|
|
947
1030
|
const body = {};
|
|
948
1031
|
if (cmdOpts.primary) body.primary_model = cmdOpts.primary;
|
|
949
1032
|
if (cmdOpts.fallback) body.fallback_model = cmdOpts.fallback;
|
|
@@ -969,7 +1052,7 @@ function registerModelCommand(program2) {
|
|
|
969
1052
|
|
|
970
1053
|
// src/commands/channel/crud.ts
|
|
971
1054
|
import chalk8 from "chalk";
|
|
972
|
-
function
|
|
1055
|
+
function getClient4(parent) {
|
|
973
1056
|
const opts = parent.parent.opts();
|
|
974
1057
|
const cfg = resolveConfig(opts);
|
|
975
1058
|
requireOption(cfg.appToken, "app-token");
|
|
@@ -978,7 +1061,7 @@ function getClient5(parent) {
|
|
|
978
1061
|
function registerChannelCrudCommands(channel) {
|
|
979
1062
|
channel.command("add <bot-id>").description("Add an IM channel").option("-c, --channel <type>", "Channel type (feishu/telegram/slack/discord)").option("--account <name>", "Account name", "default").option("--dm-policy <policy>", "DM policy (open/pairing/allowlist/disabled)").option("--group-policy <policy>", "Group policy (open/allowlist/disabled)").action(
|
|
980
1063
|
withErrorHandler(async (botId, cmdOpts) => {
|
|
981
|
-
const { client, cfg } =
|
|
1064
|
+
const { client, cfg } = getClient4(channel);
|
|
982
1065
|
let channelType = cmdOpts.channel;
|
|
983
1066
|
if (!channelType) {
|
|
984
1067
|
channelType = await promptSelect("Channel type:", [
|
|
@@ -1019,7 +1102,7 @@ function registerChannelCrudCommands(channel) {
|
|
|
1019
1102
|
);
|
|
1020
1103
|
channel.command("list <bot-id>").description("List channels").action(
|
|
1021
1104
|
withErrorHandler(async (botId) => {
|
|
1022
|
-
const { client, cfg } =
|
|
1105
|
+
const { client, cfg } = getClient4(channel);
|
|
1023
1106
|
const channels = await client.listChannels(botId);
|
|
1024
1107
|
if (cfg.json) {
|
|
1025
1108
|
printJson(channels);
|
|
@@ -1038,7 +1121,7 @@ function registerChannelCrudCommands(channel) {
|
|
|
1038
1121
|
);
|
|
1039
1122
|
channel.command("remove <bot-id> <channel>").description("Remove a channel").option("--account <name>", "Specific account to remove").action(
|
|
1040
1123
|
withErrorHandler(async (botId, ch, cmdOpts) => {
|
|
1041
|
-
const { client, cfg } =
|
|
1124
|
+
const { client, cfg } = getClient4(channel);
|
|
1042
1125
|
const result = await client.removeChannel(botId, ch, cmdOpts.account);
|
|
1043
1126
|
if (cfg.json) {
|
|
1044
1127
|
printJson(result);
|
|
@@ -1050,7 +1133,7 @@ function registerChannelCrudCommands(channel) {
|
|
|
1050
1133
|
}
|
|
1051
1134
|
|
|
1052
1135
|
// src/commands/channel/pairing.ts
|
|
1053
|
-
function
|
|
1136
|
+
function getClient5(parent) {
|
|
1054
1137
|
const root = parent.parent.parent;
|
|
1055
1138
|
const opts = root.opts();
|
|
1056
1139
|
const cfg = resolveConfig(opts);
|
|
@@ -1061,7 +1144,7 @@ function registerPairingCommands(channel) {
|
|
|
1061
1144
|
const pairing = channel.command("pairing").description("Manage channel pairing");
|
|
1062
1145
|
pairing.command("list <bot-id> <channel>").description("List pairing requests").action(
|
|
1063
1146
|
withErrorHandler(async (botId, ch) => {
|
|
1064
|
-
const { client, cfg } =
|
|
1147
|
+
const { client, cfg } = getClient5(pairing);
|
|
1065
1148
|
const list = await client.listPairing(botId, ch);
|
|
1066
1149
|
if (cfg.json) {
|
|
1067
1150
|
printJson(list);
|
|
@@ -1072,7 +1155,7 @@ function registerPairingCommands(channel) {
|
|
|
1072
1155
|
);
|
|
1073
1156
|
pairing.command("approve <bot-id> <channel>").description("Approve a pairing request").requiredOption("--code <code>", "Pairing code").action(
|
|
1074
1157
|
withErrorHandler(async (botId, ch, cmdOpts) => {
|
|
1075
|
-
const { client, cfg } =
|
|
1158
|
+
const { client, cfg } = getClient5(pairing);
|
|
1076
1159
|
const result = await client.approvePairing(botId, ch, { code: cmdOpts.code });
|
|
1077
1160
|
if (cfg.json) {
|
|
1078
1161
|
printJson(result);
|
|
@@ -1083,7 +1166,7 @@ function registerPairingCommands(channel) {
|
|
|
1083
1166
|
);
|
|
1084
1167
|
pairing.command("revoke <bot-id> <channel>").description("Revoke a user's pairing").requiredOption("--user-id <userId>", "User ID to revoke").action(
|
|
1085
1168
|
withErrorHandler(async (botId, ch, cmdOpts) => {
|
|
1086
|
-
const { client, cfg } =
|
|
1169
|
+
const { client, cfg } = getClient5(pairing);
|
|
1087
1170
|
const result = await client.revokePairing(botId, ch, { user_id: cmdOpts.userId });
|
|
1088
1171
|
if (cfg.json) {
|
|
1089
1172
|
printJson(result);
|
|
@@ -1094,7 +1177,7 @@ function registerPairingCommands(channel) {
|
|
|
1094
1177
|
);
|
|
1095
1178
|
pairing.command("users <bot-id> <channel>").description("List paired users").action(
|
|
1096
1179
|
withErrorHandler(async (botId, ch) => {
|
|
1097
|
-
const { client, cfg } =
|
|
1180
|
+
const { client, cfg } = getClient5(pairing);
|
|
1098
1181
|
const result = await client.listPairedUsers(botId, ch);
|
|
1099
1182
|
if (cfg.json) {
|
|
1100
1183
|
printJson(result);
|
|
@@ -1114,7 +1197,7 @@ function registerChannelCommand(program2) {
|
|
|
1114
1197
|
|
|
1115
1198
|
// src/commands/device/crud.ts
|
|
1116
1199
|
import chalk9 from "chalk";
|
|
1117
|
-
function
|
|
1200
|
+
function getClient6(device) {
|
|
1118
1201
|
const opts = device.parent.opts();
|
|
1119
1202
|
const cfg = resolveConfig(opts);
|
|
1120
1203
|
requireOption(cfg.appToken, "app-token");
|
|
@@ -1123,7 +1206,7 @@ function getClient7(device) {
|
|
|
1123
1206
|
function registerDeviceCrudCommands(device) {
|
|
1124
1207
|
device.command("list <bot-id>").description("List devices").option("--status <status>", "Filter by status (pending/paired)").option("--client-mode <mode>", "Filter by client mode (web/cli/desktop)").action(
|
|
1125
1208
|
withErrorHandler(async (botId, cmdOpts) => {
|
|
1126
|
-
const { client, cfg } =
|
|
1209
|
+
const { client, cfg } = getClient6(device);
|
|
1127
1210
|
const result = await client.listDevices(botId, {
|
|
1128
1211
|
status: cmdOpts.status,
|
|
1129
1212
|
client_mode: cmdOpts.clientMode
|
|
@@ -1150,7 +1233,7 @@ function registerDeviceCrudCommands(device) {
|
|
|
1150
1233
|
);
|
|
1151
1234
|
device.command("approve <bot-id> <request-id>").description("Approve a device pairing request").action(
|
|
1152
1235
|
withErrorHandler(async (botId, requestId) => {
|
|
1153
|
-
const { client, cfg } =
|
|
1236
|
+
const { client, cfg } = getClient6(device);
|
|
1154
1237
|
const result = await client.approveDevice(botId, requestId);
|
|
1155
1238
|
if (cfg.json) {
|
|
1156
1239
|
printJson(result);
|
|
@@ -1161,7 +1244,7 @@ function registerDeviceCrudCommands(device) {
|
|
|
1161
1244
|
);
|
|
1162
1245
|
device.command("revoke <bot-id> <device-id>").description("Revoke a paired device").option("--role <role>", "Role to revoke", "operator").action(
|
|
1163
1246
|
withErrorHandler(async (botId, deviceId, cmdOpts) => {
|
|
1164
|
-
const { client, cfg } =
|
|
1247
|
+
const { client, cfg } = getClient6(device);
|
|
1165
1248
|
const result = await client.revokeDevice(botId, deviceId, cmdOpts.role);
|
|
1166
1249
|
if (cfg.json) {
|
|
1167
1250
|
printJson(result);
|
|
@@ -1181,7 +1264,7 @@ function registerDeviceCommand(program2) {
|
|
|
1181
1264
|
// src/commands/skill/crud.ts
|
|
1182
1265
|
import { readFileSync as readFileSync2 } from "fs";
|
|
1183
1266
|
import chalk10 from "chalk";
|
|
1184
|
-
function
|
|
1267
|
+
function getClient7(skill) {
|
|
1185
1268
|
const opts = skill.parent.opts();
|
|
1186
1269
|
const cfg = resolveConfig(opts);
|
|
1187
1270
|
requireOption(cfg.appToken, "app-token");
|
|
@@ -1190,7 +1273,7 @@ function getClient8(skill) {
|
|
|
1190
1273
|
function registerSkillCrudCommands(skill) {
|
|
1191
1274
|
skill.command("list <bot-id>").description("List skills").action(
|
|
1192
1275
|
withErrorHandler(async (botId) => {
|
|
1193
|
-
const { client, cfg } =
|
|
1276
|
+
const { client, cfg } = getClient7(skill);
|
|
1194
1277
|
const list = await client.listSkills(botId);
|
|
1195
1278
|
if (cfg.json) {
|
|
1196
1279
|
printJson(list);
|
|
@@ -1203,7 +1286,7 @@ function registerSkillCrudCommands(skill) {
|
|
|
1203
1286
|
);
|
|
1204
1287
|
skill.command("set <bot-id> <name>").description("Create or update a skill").option("-c, --content <content>", "Skill content (markdown)").option("-f, --file <path>", "Read content from file").action(
|
|
1205
1288
|
withErrorHandler(async (botId, name, cmdOpts) => {
|
|
1206
|
-
const { client, cfg } =
|
|
1289
|
+
const { client, cfg } = getClient7(skill);
|
|
1207
1290
|
let content;
|
|
1208
1291
|
if (cmdOpts.file) {
|
|
1209
1292
|
content = readFileSync2(cmdOpts.file, "utf-8");
|
|
@@ -1222,7 +1305,7 @@ function registerSkillCrudCommands(skill) {
|
|
|
1222
1305
|
);
|
|
1223
1306
|
skill.command("delete <bot-id> <name>").description("Delete a skill").action(
|
|
1224
1307
|
withErrorHandler(async (botId, name) => {
|
|
1225
|
-
const { client, cfg } =
|
|
1308
|
+
const { client, cfg } = getClient7(skill);
|
|
1226
1309
|
const result = await client.deleteSkill(botId, name);
|
|
1227
1310
|
if (cfg.json) {
|
|
1228
1311
|
printJson(result);
|