gut-cli 0.1.16 → 0.1.18
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 +30 -26
- package/dist/index.js.map +1 -1
- package/dist/lib/index.js +7 -6
- package/dist/lib/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -90,6 +90,7 @@ import { Command as Command2 } from "commander";
|
|
|
90
90
|
import chalk2 from "chalk";
|
|
91
91
|
|
|
92
92
|
// src/lib/credentials.ts
|
|
93
|
+
import { createRequire } from "module";
|
|
93
94
|
var SERVICE_NAME = "gut-cli";
|
|
94
95
|
var PROVIDER_KEY_MAP = {
|
|
95
96
|
gemini: "gemini-api-key",
|
|
@@ -106,10 +107,10 @@ var FALLBACK_ENV_MAP = {
|
|
|
106
107
|
openai: "OPENAI_API_KEY",
|
|
107
108
|
anthropic: "ANTHROPIC_API_KEY"
|
|
108
109
|
};
|
|
109
|
-
|
|
110
|
+
function getKeytar() {
|
|
110
111
|
try {
|
|
111
|
-
const
|
|
112
|
-
return keytar
|
|
112
|
+
const require2 = createRequire(import.meta.url);
|
|
113
|
+
return require2("keytar");
|
|
113
114
|
} catch {
|
|
114
115
|
return null;
|
|
115
116
|
}
|
|
@@ -118,7 +119,7 @@ async function saveApiKey(provider, apiKey) {
|
|
|
118
119
|
if (provider === "ollama") {
|
|
119
120
|
throw new Error("Ollama does not require an API key");
|
|
120
121
|
}
|
|
121
|
-
const keytar =
|
|
122
|
+
const keytar = getKeytar();
|
|
122
123
|
if (!keytar) {
|
|
123
124
|
throw new Error("Keychain not available. Set environment variable instead.");
|
|
124
125
|
}
|
|
@@ -132,7 +133,7 @@ async function getApiKey(provider) {
|
|
|
132
133
|
if (envKey) return envKey;
|
|
133
134
|
const fallbackKey = process.env[FALLBACK_ENV_MAP[provider]];
|
|
134
135
|
if (fallbackKey) return fallbackKey;
|
|
135
|
-
const keytar =
|
|
136
|
+
const keytar = getKeytar();
|
|
136
137
|
if (!keytar) return null;
|
|
137
138
|
return keytar.getPassword(SERVICE_NAME, PROVIDER_KEY_MAP[provider]);
|
|
138
139
|
}
|
|
@@ -140,7 +141,7 @@ async function deleteApiKey(provider) {
|
|
|
140
141
|
if (provider === "ollama") {
|
|
141
142
|
throw new Error("Ollama does not use an API key");
|
|
142
143
|
}
|
|
143
|
-
const keytar =
|
|
144
|
+
const keytar = getKeytar();
|
|
144
145
|
if (!keytar) {
|
|
145
146
|
throw new Error("Keychain not available.");
|
|
146
147
|
}
|
|
@@ -177,27 +178,30 @@ async function readSecretInput(prompt) {
|
|
|
177
178
|
stdin.setRawMode(true);
|
|
178
179
|
stdin.resume();
|
|
179
180
|
stdin.setEncoding("utf8");
|
|
180
|
-
const onData = (
|
|
181
|
-
const
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
181
|
+
const onData = (data) => {
|
|
182
|
+
for (const char of data) {
|
|
183
|
+
const charCode = char.charCodeAt(0);
|
|
184
|
+
if (charCode === 13 || charCode === 10) {
|
|
185
|
+
stdin.setRawMode(false);
|
|
186
|
+
stdin.pause();
|
|
187
|
+
stdin.removeListener("data", onData);
|
|
188
|
+
console.log();
|
|
189
|
+
resolve(input);
|
|
190
|
+
return;
|
|
191
|
+
} else if (charCode === 127 || charCode === 8) {
|
|
192
|
+
if (input.length > 0) {
|
|
193
|
+
input = input.slice(0, -1);
|
|
194
|
+
process.stdout.write("\b \b");
|
|
195
|
+
}
|
|
196
|
+
} else if (charCode === 3) {
|
|
197
|
+
stdin.setRawMode(false);
|
|
198
|
+
stdin.pause();
|
|
199
|
+
console.log();
|
|
200
|
+
process.exit(0);
|
|
201
|
+
} else if (charCode >= 32) {
|
|
202
|
+
input += char;
|
|
203
|
+
process.stdout.write("*");
|
|
192
204
|
}
|
|
193
|
-
} else if (charCode === 3) {
|
|
194
|
-
stdin.setRawMode(false);
|
|
195
|
-
stdin.pause();
|
|
196
|
-
console.log();
|
|
197
|
-
process.exit(0);
|
|
198
|
-
} else if (charCode >= 32) {
|
|
199
|
-
input += char;
|
|
200
|
-
process.stdout.write("*");
|
|
201
205
|
}
|
|
202
206
|
};
|
|
203
207
|
stdin.on("data", onData);
|