@polka-codes/cli 0.4.0 → 0.4.1
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 +74 -65
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -31901,7 +31901,7 @@ class CoderAgent extends AgentBase {
|
|
|
31901
31901
|
}
|
|
31902
31902
|
}
|
|
31903
31903
|
// package.json
|
|
31904
|
-
var version = "0.4.
|
|
31904
|
+
var version = "0.4.1";
|
|
31905
31905
|
|
|
31906
31906
|
// src/Chat.ts
|
|
31907
31907
|
import readline from "node:readline";
|
|
@@ -32174,7 +32174,7 @@ class Runner {
|
|
|
32174
32174
|
this.#options = options;
|
|
32175
32175
|
const service = createService(options.provider, {
|
|
32176
32176
|
apiKey: options.apiKey,
|
|
32177
|
-
modelId: options.
|
|
32177
|
+
modelId: options.modelId
|
|
32178
32178
|
});
|
|
32179
32179
|
let rules2 = options.config.rules;
|
|
32180
32180
|
if (typeof rules2 === "string") {
|
|
@@ -37719,31 +37719,7 @@ var fetchOllamaModels = async () => {
|
|
|
37719
37719
|
return [];
|
|
37720
37720
|
}
|
|
37721
37721
|
};
|
|
37722
|
-
async function configPrompt(
|
|
37723
|
-
const globalConfigPath = getGlobalConfigPath();
|
|
37724
|
-
let configPath = options.global ? globalConfigPath : localConfigFileName;
|
|
37725
|
-
const existingConfig = existsSync2(configPath) ? loadConfigAtPath(configPath) : undefined;
|
|
37726
|
-
if (!existingConfig && !options.global) {
|
|
37727
|
-
const isGlobal = await esm_default4({
|
|
37728
|
-
message: "No config file found. Do you want to create one?",
|
|
37729
|
-
choices: [
|
|
37730
|
-
{
|
|
37731
|
-
name: `Create a global config at ${globalConfigPath}`,
|
|
37732
|
-
value: true
|
|
37733
|
-
},
|
|
37734
|
-
{
|
|
37735
|
-
name: `Create a local config at ${configPath}`,
|
|
37736
|
-
value: false
|
|
37737
|
-
}
|
|
37738
|
-
]
|
|
37739
|
-
});
|
|
37740
|
-
if (isGlobal) {
|
|
37741
|
-
configPath = globalConfigPath;
|
|
37742
|
-
} else {
|
|
37743
|
-
configPath = localConfigFileName;
|
|
37744
|
-
}
|
|
37745
|
-
}
|
|
37746
|
-
console.log(`Config file path: ${configPath}`);
|
|
37722
|
+
async function configPrompt(existingConfig) {
|
|
37747
37723
|
const provider2 = await esm_default4({
|
|
37748
37724
|
message: "Choose AI Provider:",
|
|
37749
37725
|
choices: Object.entries(AiServiceProvider).map(([key2, value]) => ({ name: key2, value })),
|
|
@@ -37777,6 +37753,50 @@ async function configPrompt(options, save) {
|
|
|
37777
37753
|
break;
|
|
37778
37754
|
}
|
|
37779
37755
|
const apiKey = await esm_default3({ message: "Enter API Key:", mask: "*" });
|
|
37756
|
+
return { provider: provider2, modelId, apiKey };
|
|
37757
|
+
}
|
|
37758
|
+
async function printConfig(configPath) {
|
|
37759
|
+
const config = existsSync2(configPath) ? loadConfigAtPath(configPath) : undefined;
|
|
37760
|
+
if (!config) {
|
|
37761
|
+
console.log("No config found");
|
|
37762
|
+
return;
|
|
37763
|
+
}
|
|
37764
|
+
console.log(`Config file path: ${configPath}`);
|
|
37765
|
+
if (config.apiKey) {
|
|
37766
|
+
config.apiKey = "<redacted>";
|
|
37767
|
+
}
|
|
37768
|
+
console.log($stringify(config));
|
|
37769
|
+
}
|
|
37770
|
+
async function configCommand(options) {
|
|
37771
|
+
const globalConfigPath = getGlobalConfigPath();
|
|
37772
|
+
let configPath = options.global ? globalConfigPath : localConfigFileName;
|
|
37773
|
+
if (options.print) {
|
|
37774
|
+
await printConfig(configPath);
|
|
37775
|
+
return;
|
|
37776
|
+
}
|
|
37777
|
+
const existingConfig = existsSync2(configPath) ? loadConfigAtPath(configPath) : undefined;
|
|
37778
|
+
if (!existingConfig && !options.global) {
|
|
37779
|
+
const isGlobal = await esm_default4({
|
|
37780
|
+
message: "No config file found. Do you want to create one?",
|
|
37781
|
+
choices: [
|
|
37782
|
+
{
|
|
37783
|
+
name: `Create a global config at ${globalConfigPath}`,
|
|
37784
|
+
value: true
|
|
37785
|
+
},
|
|
37786
|
+
{
|
|
37787
|
+
name: `Create a local config at ${configPath}`,
|
|
37788
|
+
value: false
|
|
37789
|
+
}
|
|
37790
|
+
]
|
|
37791
|
+
});
|
|
37792
|
+
if (isGlobal) {
|
|
37793
|
+
configPath = globalConfigPath;
|
|
37794
|
+
} else {
|
|
37795
|
+
configPath = localConfigFileName;
|
|
37796
|
+
}
|
|
37797
|
+
}
|
|
37798
|
+
console.log(`Config file path: ${configPath}`);
|
|
37799
|
+
const { provider: provider2, modelId, apiKey } = await configPrompt(existingConfig);
|
|
37780
37800
|
if (apiKey && configPath === localConfigFileName) {
|
|
37781
37801
|
const option = await esm_default4({
|
|
37782
37802
|
message: "It is not recommended to store API keys in the local config file. How would you like to proceed?",
|
|
@@ -37822,33 +37842,10 @@ POLKA_API_KEY=${apiKey}`;
|
|
|
37822
37842
|
}
|
|
37823
37843
|
}
|
|
37824
37844
|
const newConfig = import_lodash2.merge({}, existingConfig, { provider: provider2, modelId, apiKey });
|
|
37825
|
-
|
|
37826
|
-
|
|
37827
|
-
|
|
37828
|
-
|
|
37829
|
-
}
|
|
37830
|
-
return newConfig;
|
|
37831
|
-
}
|
|
37832
|
-
async function printConfig(configPath) {
|
|
37833
|
-
const config = existsSync2(configPath) ? loadConfigAtPath(configPath) : undefined;
|
|
37834
|
-
if (!config) {
|
|
37835
|
-
console.log("No config found");
|
|
37836
|
-
return;
|
|
37837
|
-
}
|
|
37838
|
-
console.log(`Config file path: ${configPath}`);
|
|
37839
|
-
if (config.apiKey) {
|
|
37840
|
-
config.apiKey = "<redacted>";
|
|
37841
|
-
}
|
|
37842
|
-
console.log($stringify(config));
|
|
37843
|
-
}
|
|
37844
|
-
async function configCommand(options) {
|
|
37845
|
-
const globalConfigPath = getGlobalConfigPath();
|
|
37846
|
-
const configPath = options.global ? globalConfigPath : localConfigFileName;
|
|
37847
|
-
if (options.print) {
|
|
37848
|
-
await printConfig(configPath);
|
|
37849
|
-
return;
|
|
37850
|
-
}
|
|
37851
|
-
await configPrompt(options, true);
|
|
37845
|
+
mkdirSync(dirname2(configPath), { recursive: true });
|
|
37846
|
+
writeFileSync(configPath, $stringify(newConfig));
|
|
37847
|
+
console.log(`Config file saved at: ${configPath}`);
|
|
37848
|
+
return;
|
|
37852
37849
|
}
|
|
37853
37850
|
|
|
37854
37851
|
// src/options.ts
|
|
@@ -37857,10 +37854,10 @@ function addSharedOptions(command) {
|
|
|
37857
37854
|
}
|
|
37858
37855
|
function parseOptions(options) {
|
|
37859
37856
|
const config = loadConfig(options.config ?? options.c);
|
|
37860
|
-
const provider2 = options.apiProvider || process.env.POLKA_API_PROVIDER || config?.provider
|
|
37857
|
+
const provider2 = options.apiProvider || process.env.POLKA_API_PROVIDER || config?.provider;
|
|
37861
37858
|
return {
|
|
37862
37859
|
provider: provider2,
|
|
37863
|
-
|
|
37860
|
+
modelId: options.modelId || process.env.POLKA_MODEL_ID || config?.modelId,
|
|
37864
37861
|
apiKey: options.apiKey || process.env.POLKA_API_KEY || config?.apiKey,
|
|
37865
37862
|
maxIterations: options.maxIterations ?? 30,
|
|
37866
37863
|
config
|
|
@@ -37871,21 +37868,21 @@ function parseOptions(options) {
|
|
|
37871
37868
|
var program2 = new Command;
|
|
37872
37869
|
program2.name("polka").description("Polka Codes CLI").version(version);
|
|
37873
37870
|
var runChat = async (options) => {
|
|
37874
|
-
let { provider: provider2,
|
|
37875
|
-
if (!provider2
|
|
37876
|
-
const newConfig = await configPrompt({
|
|
37871
|
+
let { provider: provider2, modelId, apiKey, config, maxIterations } = parseOptions(options);
|
|
37872
|
+
if (!provider2) {
|
|
37873
|
+
const newConfig = await configPrompt({ provider: provider2, modelId, apiKey, ...config });
|
|
37877
37874
|
provider2 = newConfig.provider;
|
|
37878
|
-
|
|
37875
|
+
modelId = newConfig.modelId;
|
|
37879
37876
|
apiKey = newConfig.apiKey;
|
|
37880
37877
|
}
|
|
37881
37878
|
console.log("Starting chat session...");
|
|
37882
37879
|
console.log("Provider:", provider2);
|
|
37883
|
-
console.log("Model:",
|
|
37880
|
+
console.log("Model:", modelId);
|
|
37884
37881
|
console.log('Type ".help" for more information.');
|
|
37885
37882
|
console.log("What can I do for you?");
|
|
37886
37883
|
const runner = new Runner({
|
|
37887
37884
|
provider: provider2,
|
|
37888
|
-
|
|
37885
|
+
modelId: modelId ?? defaultModels[provider2],
|
|
37889
37886
|
apiKey,
|
|
37890
37887
|
config: config ?? {},
|
|
37891
37888
|
maxIterations,
|
|
@@ -37945,12 +37942,18 @@ program2.argument("[task]", "The task to execute").action(async (taskArg, option
|
|
|
37945
37942
|
runChat(options);
|
|
37946
37943
|
return;
|
|
37947
37944
|
}
|
|
37948
|
-
|
|
37945
|
+
let { provider: provider2, modelId, apiKey, config, maxIterations } = parseOptions(options);
|
|
37946
|
+
if (!provider2) {
|
|
37947
|
+
const newConfig = await configPrompt({ provider: provider2, modelId, apiKey, ...config });
|
|
37948
|
+
provider2 = newConfig.provider;
|
|
37949
|
+
modelId = newConfig.modelId;
|
|
37950
|
+
apiKey = newConfig.apiKey;
|
|
37951
|
+
}
|
|
37949
37952
|
console.log("Provider:", provider2);
|
|
37950
|
-
console.log("Model:",
|
|
37953
|
+
console.log("Model:", modelId);
|
|
37951
37954
|
const runner = new Runner({
|
|
37952
37955
|
provider: provider2,
|
|
37953
|
-
|
|
37956
|
+
modelId: modelId ?? defaultModels[provider2],
|
|
37954
37957
|
apiKey,
|
|
37955
37958
|
config: config ?? {},
|
|
37956
37959
|
maxIterations,
|
|
@@ -37982,3 +37985,9 @@ program2.argument("[task]", "The task to execute").action(async (taskArg, option
|
|
|
37982
37985
|
});
|
|
37983
37986
|
addSharedOptions(program2);
|
|
37984
37987
|
program2.parse();
|
|
37988
|
+
process.on("uncaughtException", (error) => {
|
|
37989
|
+
if (error instanceof Error && error.name === "ExitPromptError") {
|
|
37990
|
+
} else {
|
|
37991
|
+
throw error;
|
|
37992
|
+
}
|
|
37993
|
+
});
|