starkbot-cli 0.3.1 → 0.3.2
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 +21 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -337,6 +337,11 @@ function isJwtExpired(creds) {
|
|
|
337
337
|
return true;
|
|
338
338
|
}
|
|
339
339
|
}
|
|
340
|
+
function getInstanceUrl(creds) {
|
|
341
|
+
if (creds.instance_url) return creds.instance_url;
|
|
342
|
+
if (creds.instance_domain) return `https://${creds.instance_domain}`;
|
|
343
|
+
throw new Error("No instance URL configured. Run `starkbot login` or `starkbot connect` first.");
|
|
344
|
+
}
|
|
340
345
|
function requireCredentials() {
|
|
341
346
|
const creds = loadCredentials();
|
|
342
347
|
if (!creds) {
|
|
@@ -562,7 +567,12 @@ async function externalLogin() {
|
|
|
562
567
|
{
|
|
563
568
|
type: "input",
|
|
564
569
|
name: "instanceUrl",
|
|
565
|
-
message: "Instance URL (e.g.
|
|
570
|
+
message: "Instance URL (e.g. mybot.example.com):",
|
|
571
|
+
filter: (val) => {
|
|
572
|
+
const v = val.trim();
|
|
573
|
+
if (v && !/^https?:\/\//i.test(v)) return `http://${v}`;
|
|
574
|
+
return v;
|
|
575
|
+
},
|
|
566
576
|
validate: (val) => {
|
|
567
577
|
if (!val.trim()) return "Instance URL is required";
|
|
568
578
|
try {
|
|
@@ -601,6 +611,7 @@ async function externalLogin() {
|
|
|
601
611
|
tenant_id: "",
|
|
602
612
|
gateway_token: token,
|
|
603
613
|
instance_domain: domain,
|
|
614
|
+
instance_url: baseUrl,
|
|
604
615
|
mode: "external"
|
|
605
616
|
});
|
|
606
617
|
printSuccess(`Connected to ${domain}`);
|
|
@@ -883,7 +894,7 @@ async function connectCommand(opts = {}) {
|
|
|
883
894
|
const spin2 = spinner("Testing connection...");
|
|
884
895
|
spin2.start();
|
|
885
896
|
try {
|
|
886
|
-
const gw = new GatewayClient(`https://${domain}`, opts.token);
|
|
897
|
+
const gw = new GatewayClient(creds.instance_url ?? `https://${domain}`, opts.token);
|
|
887
898
|
const ok = await gw.ping();
|
|
888
899
|
spin2.stop();
|
|
889
900
|
if (ok) {
|
|
@@ -909,7 +920,7 @@ async function connectCommand(opts = {}) {
|
|
|
909
920
|
instance_domain: domain
|
|
910
921
|
});
|
|
911
922
|
spin.text = "Testing connection...";
|
|
912
|
-
const gw = new GatewayClient(`https://${domain}`, token);
|
|
923
|
+
const gw = new GatewayClient(creds.instance_url ?? `https://${domain}`, token);
|
|
913
924
|
const ok = await gw.ping();
|
|
914
925
|
spin.stop();
|
|
915
926
|
if (ok) {
|
|
@@ -1136,7 +1147,7 @@ function requireGateway() {
|
|
|
1136
1147
|
);
|
|
1137
1148
|
}
|
|
1138
1149
|
return new GatewayClient(
|
|
1139
|
-
|
|
1150
|
+
getInstanceUrl(creds),
|
|
1140
1151
|
creds.gateway_token
|
|
1141
1152
|
);
|
|
1142
1153
|
}
|
|
@@ -1150,7 +1161,8 @@ async function tryRefreshToken() {
|
|
|
1150
1161
|
const client = new FlashClient(creds.jwt);
|
|
1151
1162
|
const { token, domain } = await client.getGatewayToken();
|
|
1152
1163
|
updateCredentials({ gateway_token: token, instance_domain: domain });
|
|
1153
|
-
const
|
|
1164
|
+
const url = creds.instance_url ?? `https://${domain}`;
|
|
1165
|
+
const gw = new GatewayClient(url, token);
|
|
1154
1166
|
const ok = await gw.ping();
|
|
1155
1167
|
if (ok) {
|
|
1156
1168
|
printSuccess("Gateway token refreshed automatically.");
|
|
@@ -1266,7 +1278,8 @@ async function chatReplCommand() {
|
|
|
1266
1278
|
const creds = requireCredentials();
|
|
1267
1279
|
const domain = creds.instance_domain;
|
|
1268
1280
|
updateCredentials({ gateway_token: newToken });
|
|
1269
|
-
|
|
1281
|
+
const url = creds.instance_url ?? `https://${domain}`;
|
|
1282
|
+
gw = new GatewayClient(url, newToken);
|
|
1270
1283
|
const ok = await gw.ping();
|
|
1271
1284
|
if (ok) {
|
|
1272
1285
|
printSuccess(`Reconnected to ${domain}`);
|
|
@@ -1573,7 +1586,7 @@ async function sessionsCommand() {
|
|
|
1573
1586
|
throw new Error("Gateway not configured. Run `starkbot connect` first.");
|
|
1574
1587
|
}
|
|
1575
1588
|
const gw = new GatewayClient(
|
|
1576
|
-
|
|
1589
|
+
getInstanceUrl(creds),
|
|
1577
1590
|
creds.gateway_token
|
|
1578
1591
|
);
|
|
1579
1592
|
const spin = spinner("Fetching sessions...");
|
|
@@ -1624,7 +1637,7 @@ async function historyCommand(sessionId) {
|
|
|
1624
1637
|
process.exit(1);
|
|
1625
1638
|
}
|
|
1626
1639
|
const gw = new GatewayClient(
|
|
1627
|
-
|
|
1640
|
+
getInstanceUrl(creds),
|
|
1628
1641
|
creds.gateway_token
|
|
1629
1642
|
);
|
|
1630
1643
|
const spin = spinner("Fetching message history...");
|