@kyma-api/agent 0.1.3 → 0.1.4
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/main.js +19 -32
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -146,7 +146,7 @@ var VERSION = (() => {
|
|
|
146
146
|
function normalizeKymaError(status, body) {
|
|
147
147
|
switch (status) {
|
|
148
148
|
case 401:
|
|
149
|
-
return { code: 401, severity: "error", message: "Session expired.", action: "Run /
|
|
149
|
+
return { code: 401, severity: "error", message: "Session expired.", action: "Run /connect to reconnect." };
|
|
150
150
|
case 402:
|
|
151
151
|
return { code: 402, severity: "error", message: "Insufficient Kyma credits.", action: "Run /billing to top up." };
|
|
152
152
|
case 429:
|
|
@@ -439,7 +439,7 @@ async function runOnboarding() {
|
|
|
439
439
|
console.log("");
|
|
440
440
|
const answer = await ask(" Connect now? (Y/n) ");
|
|
441
441
|
if (answer.toLowerCase() === "n" || answer.toLowerCase() === "no") {
|
|
442
|
-
console.log(` ${term.dim("Skipped.")} Use ${term.gold("/
|
|
442
|
+
console.log(` ${term.dim("Skipped.")} Use ${term.gold("/connect")} anytime.`);
|
|
443
443
|
console.log("");
|
|
444
444
|
markOnboarded();
|
|
445
445
|
return false;
|
|
@@ -468,7 +468,7 @@ async function runOnboarding() {
|
|
|
468
468
|
} catch (err) {
|
|
469
469
|
console.log("");
|
|
470
470
|
console.log(` ${term.dim("Login failed:")} ${err.message}`);
|
|
471
|
-
console.log(` ${term.dim("Try again with")} ${term.gold("/
|
|
471
|
+
console.log(` ${term.dim("Try again with")} ${term.gold("/connect")}`);
|
|
472
472
|
console.log("");
|
|
473
473
|
}
|
|
474
474
|
markOnboarded();
|
|
@@ -823,9 +823,9 @@ var kymaRuntimeFactory = (pi) => {
|
|
|
823
823
|
const maxW = Math.max(width, 30);
|
|
824
824
|
const logo = theme.bold(theme.fg("accent", ` \u03A8 kyma`)) + theme.fg("dim", ` v${VERSION}`);
|
|
825
825
|
const url = ` https://kymaapi.com`;
|
|
826
|
-
const accountStr = loggedIn ? `${email}${balanceStr ? ` \xB7 ${balanceStr}` : ""}` : "not connected";
|
|
826
|
+
const accountStr = loggedIn ? `${email || "connected"}${balanceStr ? ` \xB7 ${balanceStr}` : ""}` : "not connected";
|
|
827
827
|
const dirLine = `~/${repoName}`;
|
|
828
|
-
const connectLine = loggedIn ? null : `${theme.bold("/
|
|
828
|
+
const connectLine = loggedIn ? null : `${theme.bold("/connect")} to sign in`;
|
|
829
829
|
const contentLines = [accountStr, dirLine];
|
|
830
830
|
if (connectLine) contentLines.push(connectLine);
|
|
831
831
|
const visibleWidths = contentLines.map((l) => strip(l).length);
|
|
@@ -914,25 +914,12 @@ var kymaRuntimeFactory = (pi) => {
|
|
|
914
914
|
wasLoggedIn = true;
|
|
915
915
|
postLoginShown = true;
|
|
916
916
|
const postKey = getKymaApiKey();
|
|
917
|
-
const postEmail = getKymaEmail();
|
|
917
|
+
const postEmail = getKymaEmail() || "connected";
|
|
918
918
|
try {
|
|
919
919
|
const bal = await kymaApi("/v1/credits/balance", postKey);
|
|
920
|
-
ctx.ui.notify(`Authorized \xB7 ${postEmail} \xB7 $${bal.balance.toFixed(2)}`, "info");
|
|
920
|
+
ctx.ui.notify(`Authorized \xB7 ${postEmail} \xB7 $${bal.balance.toFixed(2)} \u2014 /mode to switch`, "info");
|
|
921
921
|
} catch {
|
|
922
|
-
ctx.ui.notify(`Authorized \xB7 ${postEmail}`, "info");
|
|
923
|
-
}
|
|
924
|
-
const modeOptions = [...MODE_TO_MODEL.entries()].map(
|
|
925
|
-
([mode, m]) => `${mode.padEnd(12)} ${m.name.padEnd(20)} ${m.tag}`
|
|
926
|
-
);
|
|
927
|
-
modeOptions.push("Keep default (fast)");
|
|
928
|
-
const modeChoice = await ctx.ui.select("Choose a mode for this session", modeOptions);
|
|
929
|
-
if (modeChoice && !modeChoice.startsWith("Keep")) {
|
|
930
|
-
const modeName = modeChoice.split(/\s+/)[0];
|
|
931
|
-
const modeModel = MODE_TO_MODEL.get(modeName);
|
|
932
|
-
if (modeModel) {
|
|
933
|
-
const ok = await pi.setModel(toRuntimeModel(modeModel, `${KYMA_BASE_URL}/v1`));
|
|
934
|
-
if (ok) ctx.ui.notify(`Mode: ${modeName} \u2192 ${modeModel.name}`, "info");
|
|
935
|
-
}
|
|
922
|
+
ctx.ui.notify(`Authorized \xB7 ${postEmail} \u2014 /mode to switch`, "info");
|
|
936
923
|
}
|
|
937
924
|
}
|
|
938
925
|
});
|
|
@@ -980,7 +967,7 @@ var kymaRuntimeFactory = (pi) => {
|
|
|
980
967
|
if (ok) {
|
|
981
968
|
ctx.ui.notify(`Switched to ${chosen.name} \u2014 ${chosen.tag}`, "info");
|
|
982
969
|
} else {
|
|
983
|
-
ctx.ui.notify("Failed to switch model. Run /
|
|
970
|
+
ctx.ui.notify("Failed to switch model. Run /connect to sign in.", "error");
|
|
984
971
|
}
|
|
985
972
|
}
|
|
986
973
|
pi.registerCommand("models", {
|
|
@@ -1017,7 +1004,7 @@ var kymaRuntimeFactory = (pi) => {
|
|
|
1017
1004
|
if (ok) {
|
|
1018
1005
|
ctx.ui.notify(`Mode: ${entry.mode} \u2192 ${entry.model.name}`, "info");
|
|
1019
1006
|
} else {
|
|
1020
|
-
ctx.ui.notify("Failed to switch model. Run /
|
|
1007
|
+
ctx.ui.notify("Failed to switch model. Run /connect to sign in.", "error");
|
|
1021
1008
|
}
|
|
1022
1009
|
}
|
|
1023
1010
|
});
|
|
@@ -1028,7 +1015,7 @@ var kymaRuntimeFactory = (pi) => {
|
|
|
1028
1015
|
const currentModel = ctx.model;
|
|
1029
1016
|
const lines = ["Kyma Status", DIV, ""];
|
|
1030
1017
|
if (!apiKey) {
|
|
1031
|
-
lines.push(" Not connected. Run /
|
|
1018
|
+
lines.push(" Not connected. Run /connect to sign in.");
|
|
1032
1019
|
ctx.ui.notify(lines.join("\n"), "info");
|
|
1033
1020
|
return;
|
|
1034
1021
|
}
|
|
@@ -1079,7 +1066,7 @@ var kymaRuntimeFactory = (pi) => {
|
|
|
1079
1066
|
async handler(_args, ctx) {
|
|
1080
1067
|
const apiKey = getKymaApiKey();
|
|
1081
1068
|
if (!apiKey) {
|
|
1082
|
-
ctx.ui.notify("Not connected. Run /
|
|
1069
|
+
ctx.ui.notify("Not connected. Run /connect to sign in.", "error");
|
|
1083
1070
|
return;
|
|
1084
1071
|
}
|
|
1085
1072
|
try {
|
|
@@ -1147,7 +1134,7 @@ var kymaRuntimeFactory = (pi) => {
|
|
|
1147
1134
|
async handler(_args, ctx) {
|
|
1148
1135
|
const apiKey = getKymaApiKey();
|
|
1149
1136
|
if (!apiKey) {
|
|
1150
|
-
ctx.ui.notify("Not connected. Run /
|
|
1137
|
+
ctx.ui.notify("Not connected. Run /connect first.", "error");
|
|
1151
1138
|
return;
|
|
1152
1139
|
}
|
|
1153
1140
|
try {
|
|
@@ -1203,7 +1190,7 @@ var kymaRuntimeFactory = (pi) => {
|
|
|
1203
1190
|
ctx.ui.notify("Opening feedback page...", "info");
|
|
1204
1191
|
}
|
|
1205
1192
|
});
|
|
1206
|
-
pi.registerCommand("
|
|
1193
|
+
pi.registerCommand("connect", {
|
|
1207
1194
|
description: "Sign in to your Kyma account",
|
|
1208
1195
|
async handler(_args, ctx) {
|
|
1209
1196
|
if (getKymaApiKey()) {
|
|
@@ -1243,8 +1230,8 @@ URL: ${url}`, "info");
|
|
|
1243
1230
|
"Kyma Commands",
|
|
1244
1231
|
DIV,
|
|
1245
1232
|
"",
|
|
1246
|
-
" /
|
|
1247
|
-
" /
|
|
1233
|
+
" /connect Sign in to Kyma",
|
|
1234
|
+
" /disconnect Sign out",
|
|
1248
1235
|
" /models Browse and switch models",
|
|
1249
1236
|
" /mode Switch model by task type",
|
|
1250
1237
|
" /status Account, credits, diagnostics",
|
|
@@ -1275,12 +1262,12 @@ URL: ${url}`, "info");
|
|
|
1275
1262
|
process.exit(0);
|
|
1276
1263
|
}
|
|
1277
1264
|
});
|
|
1278
|
-
pi.registerCommand("
|
|
1265
|
+
pi.registerCommand("disconnect", {
|
|
1279
1266
|
description: "Sign out of Kyma",
|
|
1280
1267
|
async handler(_args, ctx) {
|
|
1281
1268
|
const apiKey = getKymaApiKey();
|
|
1282
1269
|
if (!apiKey) {
|
|
1283
|
-
ctx.ui.notify("Not signed in. Run /
|
|
1270
|
+
ctx.ui.notify("Not signed in. Run /connect to sign in.", "info");
|
|
1284
1271
|
return;
|
|
1285
1272
|
}
|
|
1286
1273
|
if (process.env.KYMA_API_KEY) {
|
|
@@ -1293,7 +1280,7 @@ URL: ${url}`, "info");
|
|
|
1293
1280
|
clearKymaCredentials();
|
|
1294
1281
|
wasLoggedIn = false;
|
|
1295
1282
|
postLoginShown = false;
|
|
1296
|
-
ctx.ui.notify("Signed out. Run /
|
|
1283
|
+
ctx.ui.notify("Signed out. Run /connect to sign in again.", "info");
|
|
1297
1284
|
}
|
|
1298
1285
|
});
|
|
1299
1286
|
pi.registerCommand("clear", {
|