devwing 0.1.10 → 0.1.12
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 +57 -21
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2176,7 +2176,6 @@ async function demoLoginCommand() {
|
|
|
2176
2176
|
} catch (error) {
|
|
2177
2177
|
logger.error("Login failed");
|
|
2178
2178
|
if (error.message) logger.error(error.message);
|
|
2179
|
-
process.exit(1);
|
|
2180
2179
|
}
|
|
2181
2180
|
}
|
|
2182
2181
|
async function demoLoginEmail() {
|
|
@@ -2752,28 +2751,29 @@ async function showUsage(tokensIn, tokensOut, cost, mode) {
|
|
|
2752
2751
|
async function requireDemoAuth() {
|
|
2753
2752
|
const apiKey = await configManager.getApiKey();
|
|
2754
2753
|
if (!apiKey) {
|
|
2755
|
-
|
|
2756
|
-
process.exit(1);
|
|
2754
|
+
throw new Error('Not authenticated. Run "devwing login" or type /login first.');
|
|
2757
2755
|
}
|
|
2758
2756
|
}
|
|
2759
2757
|
function isDemoMode() {
|
|
2760
2758
|
return process.env.DEVWING_DEMO === "1" || process.env.DEVWING_DEMO === "true";
|
|
2761
2759
|
}
|
|
2762
|
-
var
|
|
2763
|
-
var
|
|
2760
|
+
var __sessionFile = fileURLToPath(import.meta.url);
|
|
2761
|
+
var __sessionDir = dirname(__sessionFile);
|
|
2764
2762
|
function getVersion() {
|
|
2765
2763
|
const paths = [
|
|
2766
|
-
join(
|
|
2767
|
-
join(
|
|
2764
|
+
join(__sessionDir, "../package.json"),
|
|
2765
|
+
join(__sessionDir, "../../package.json"),
|
|
2766
|
+
join(__sessionDir, "../../../package.json")
|
|
2768
2767
|
];
|
|
2769
2768
|
for (const p of paths) {
|
|
2770
2769
|
try {
|
|
2771
|
-
|
|
2770
|
+
const pkg = JSON.parse(readFileSync(p, "utf-8"));
|
|
2771
|
+
if (pkg.name === "devwing" && pkg.version) return pkg.version;
|
|
2772
2772
|
} catch {
|
|
2773
2773
|
continue;
|
|
2774
2774
|
}
|
|
2775
2775
|
}
|
|
2776
|
-
return "0.1.
|
|
2776
|
+
return "0.1.10";
|
|
2777
2777
|
}
|
|
2778
2778
|
var DEMO_USER2 = {
|
|
2779
2779
|
id: "usr_a1b2c3d4-e5f6-7890-abcd-ef1234567890",
|
|
@@ -2827,6 +2827,8 @@ var InteractiveSession = class {
|
|
|
2827
2827
|
sigintCount = 0;
|
|
2828
2828
|
sigintTimer = null;
|
|
2829
2829
|
version;
|
|
2830
|
+
isBusy = false;
|
|
2831
|
+
// prevent readline events during command execution
|
|
2830
2832
|
constructor(options) {
|
|
2831
2833
|
this.options = options;
|
|
2832
2834
|
this.isDemo = isDemoMode();
|
|
@@ -2843,6 +2845,15 @@ var InteractiveSession = class {
|
|
|
2843
2845
|
this.printStartupBanner();
|
|
2844
2846
|
await this.checkAuthStatus();
|
|
2845
2847
|
this.printSystemInfo();
|
|
2848
|
+
this.createReadline();
|
|
2849
|
+
console.log();
|
|
2850
|
+
this.rl.prompt();
|
|
2851
|
+
}
|
|
2852
|
+
// ============================================================
|
|
2853
|
+
// READLINE MANAGEMENT
|
|
2854
|
+
// ============================================================
|
|
2855
|
+
createReadline() {
|
|
2856
|
+
this.isBusy = false;
|
|
2846
2857
|
this.rl = readline.createInterface({
|
|
2847
2858
|
input: process.stdin,
|
|
2848
2859
|
output: process.stdout,
|
|
@@ -2861,28 +2872,39 @@ var InteractiveSession = class {
|
|
|
2861
2872
|
}, 1500);
|
|
2862
2873
|
this.rl.prompt();
|
|
2863
2874
|
});
|
|
2875
|
+
const currentRl = this.rl;
|
|
2864
2876
|
this.rl.on("line", async (input) => {
|
|
2877
|
+
if (this.isBusy) return;
|
|
2865
2878
|
const trimmed = input.trim();
|
|
2866
2879
|
if (!trimmed) {
|
|
2867
2880
|
this.rl.prompt();
|
|
2868
2881
|
return;
|
|
2869
2882
|
}
|
|
2883
|
+
this.isBusy = true;
|
|
2870
2884
|
try {
|
|
2871
2885
|
if (trimmed.startsWith("/")) {
|
|
2872
2886
|
await this.handleSlashCommand(trimmed);
|
|
2887
|
+
return;
|
|
2873
2888
|
} else {
|
|
2874
2889
|
await this.handleAIPrompt(trimmed);
|
|
2875
2890
|
}
|
|
2876
2891
|
} catch (error) {
|
|
2877
2892
|
logger.error(error.message || "An error occurred");
|
|
2878
2893
|
}
|
|
2879
|
-
this.
|
|
2880
|
-
this.rl
|
|
2894
|
+
this.isBusy = false;
|
|
2895
|
+
if (this.rl === currentRl) {
|
|
2896
|
+
this.rl.setPrompt(this.buildPrompt());
|
|
2897
|
+
this.rl.prompt();
|
|
2898
|
+
}
|
|
2881
2899
|
});
|
|
2882
2900
|
this.rl.on("close", () => {
|
|
2883
|
-
this.
|
|
2901
|
+
if (!this.isBusy) {
|
|
2902
|
+
this.exitSession();
|
|
2903
|
+
}
|
|
2884
2904
|
});
|
|
2885
|
-
|
|
2905
|
+
}
|
|
2906
|
+
recreateReadline() {
|
|
2907
|
+
this.createReadline();
|
|
2886
2908
|
this.rl.prompt();
|
|
2887
2909
|
}
|
|
2888
2910
|
// ============================================================
|
|
@@ -2913,6 +2935,10 @@ var InteractiveSession = class {
|
|
|
2913
2935
|
console.log(
|
|
2914
2936
|
` ${chalk7.bold("Auth")} ${chalk7.green("\u25CF")} ${name} ${planColor(`(${plan})`)}`
|
|
2915
2937
|
);
|
|
2938
|
+
} else if (this.isAuthenticated) {
|
|
2939
|
+
console.log(
|
|
2940
|
+
` ${chalk7.bold("Auth")} ${chalk7.green("\u25CF")} Authenticated ${chalk7.dim("(offline)")}`
|
|
2941
|
+
);
|
|
2916
2942
|
} else {
|
|
2917
2943
|
console.log(
|
|
2918
2944
|
` ${chalk7.bold("Auth")} ${chalk7.red("\u25CF")} Not logged in ${chalk7.dim("\u2014 type /login")}`
|
|
@@ -2975,14 +3001,22 @@ var InteractiveSession = class {
|
|
|
2975
3001
|
async checkAuthStatus() {
|
|
2976
3002
|
try {
|
|
2977
3003
|
const apiKey = await configManager.getApiKey();
|
|
2978
|
-
if (apiKey) {
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
3004
|
+
if (!apiKey) {
|
|
3005
|
+
this.isAuthenticated = false;
|
|
3006
|
+
this.userProfile = null;
|
|
3007
|
+
return;
|
|
3008
|
+
}
|
|
3009
|
+
if (this.isDemo) {
|
|
3010
|
+
this.isAuthenticated = true;
|
|
3011
|
+
this.userProfile = { ...DEMO_USER2 };
|
|
3012
|
+
} else {
|
|
3013
|
+
try {
|
|
2983
3014
|
const profile = await apiClient.getProfile();
|
|
2984
3015
|
this.isAuthenticated = true;
|
|
2985
3016
|
this.userProfile = profile;
|
|
3017
|
+
} catch {
|
|
3018
|
+
this.isAuthenticated = true;
|
|
3019
|
+
this.userProfile = null;
|
|
2986
3020
|
}
|
|
2987
3021
|
}
|
|
2988
3022
|
} catch {
|
|
@@ -3012,12 +3046,14 @@ var InteractiveSession = class {
|
|
|
3012
3046
|
logger.warn("You need to be logged in for this command. Type /login first.");
|
|
3013
3047
|
return;
|
|
3014
3048
|
}
|
|
3015
|
-
this.
|
|
3049
|
+
this.isBusy = true;
|
|
3050
|
+
this.rl.close();
|
|
3016
3051
|
try {
|
|
3017
3052
|
await command.handler(args);
|
|
3018
|
-
}
|
|
3019
|
-
|
|
3053
|
+
} catch (error) {
|
|
3054
|
+
logger.error(error.message || "Command failed");
|
|
3020
3055
|
}
|
|
3056
|
+
this.recreateReadline();
|
|
3021
3057
|
}
|
|
3022
3058
|
// ============================================================
|
|
3023
3059
|
// AI PROMPT HANDLER
|