@statezero/core 0.1.1 → 0.1.3
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/cli/commands/syncModels.js +57 -12
- package/package.json +1 -1
|
@@ -94,6 +94,59 @@ import { loadConfigFromFile } from "../configFileLoader.js";
|
|
|
94
94
|
* @property {string} model
|
|
95
95
|
*/
|
|
96
96
|
// --------------------
|
|
97
|
+
// Fallback Selection for Inquirer Errors
|
|
98
|
+
// --------------------
|
|
99
|
+
/**
|
|
100
|
+
* Simple fallback that generates all models when inquirer fails
|
|
101
|
+
* @param {Array} choices - Array of choice objects with {name, value, checked} properties
|
|
102
|
+
* @param {string} message - Selection message
|
|
103
|
+
* @returns {Promise<Array>} - All model values
|
|
104
|
+
*/
|
|
105
|
+
async function fallbackSelectAll(choices, message) {
|
|
106
|
+
console.log(`\n${message}`);
|
|
107
|
+
console.log("Interactive selection not available - generating ALL models:");
|
|
108
|
+
const allModels = [];
|
|
109
|
+
for (const choice of choices) {
|
|
110
|
+
// Skip separators (they don't have a 'value' property)
|
|
111
|
+
if (!choice.value) {
|
|
112
|
+
console.log(choice.name); // Print separator text
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
// Add ALL models, regardless of checked status
|
|
116
|
+
allModels.push(choice.value);
|
|
117
|
+
console.log(` ✓ ${choice.name}`);
|
|
118
|
+
}
|
|
119
|
+
console.log(`\nGenerating ALL ${allModels.length} models.`);
|
|
120
|
+
return allModels;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Model selection with inquirer fallback
|
|
124
|
+
* @param {Array} choices - Array of choice objects
|
|
125
|
+
* @param {string} message - Selection message
|
|
126
|
+
* @returns {Promise<Array>} - Selected model objects
|
|
127
|
+
*/
|
|
128
|
+
async function selectModels(choices, message) {
|
|
129
|
+
try {
|
|
130
|
+
// Try to use inquirer first
|
|
131
|
+
const inquirer = (await import("inquirer")).default;
|
|
132
|
+
const { selectedModels } = await inquirer.prompt([
|
|
133
|
+
{
|
|
134
|
+
type: "checkbox",
|
|
135
|
+
name: "selectedModels",
|
|
136
|
+
message,
|
|
137
|
+
choices,
|
|
138
|
+
pageSize: 20,
|
|
139
|
+
},
|
|
140
|
+
]);
|
|
141
|
+
return selectedModels;
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
// Fall back to generating all models if inquirer fails for any reason
|
|
145
|
+
console.warn("Interactive selection failed, generating all models:", error.message);
|
|
146
|
+
return await fallbackSelectAll(choices, message);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
// --------------------
|
|
97
150
|
// Handlebars Templates & Helpers
|
|
98
151
|
// --------------------
|
|
99
152
|
// Updated JS_MODEL_TEMPLATE with getters and setters
|
|
@@ -944,14 +997,12 @@ export declare const FileObject: typeof ${backend.NAME}FileObject;
|
|
|
944
997
|
// --------------------
|
|
945
998
|
// Main Runner: Fetch models and prompt selection
|
|
946
999
|
// --------------------
|
|
947
|
-
// Update main function to use this new approach
|
|
948
1000
|
async function main() {
|
|
949
1001
|
// Load configuration from file (CLI-only or tests) before any other operations.
|
|
950
1002
|
loadConfigFromFile();
|
|
951
1003
|
// Retrieve the validated configuration from the global config singleton.
|
|
952
1004
|
const configData = configInstance.getConfig();
|
|
953
1005
|
const backendConfigs = configData.backendConfigs;
|
|
954
|
-
const inquirer = (await import("inquirer")).default;
|
|
955
1006
|
const fetchPromises = Object.keys(backendConfigs).map(async (key) => {
|
|
956
1007
|
const backend = backendConfigs[key];
|
|
957
1008
|
backend.NAME = key;
|
|
@@ -966,8 +1017,10 @@ async function main() {
|
|
|
966
1017
|
});
|
|
967
1018
|
const backendModels = await Promise.all(fetchPromises);
|
|
968
1019
|
const choices = [];
|
|
1020
|
+
// Create a simple separator object for environments where inquirer.Separator isn't available
|
|
1021
|
+
const createSeparator = (text) => ({ name: text, value: null });
|
|
969
1022
|
for (const { backend, models } of backendModels) {
|
|
970
|
-
choices.push(
|
|
1023
|
+
choices.push(createSeparator(`\n=== ${backend.NAME} ===\n`));
|
|
971
1024
|
for (const model of models) {
|
|
972
1025
|
choices.push({
|
|
973
1026
|
name: model,
|
|
@@ -980,15 +1033,7 @@ async function main() {
|
|
|
980
1033
|
console.log("No models to synchronise");
|
|
981
1034
|
process.exit(0);
|
|
982
1035
|
}
|
|
983
|
-
const
|
|
984
|
-
{
|
|
985
|
-
type: "checkbox",
|
|
986
|
-
name: "selectedModels",
|
|
987
|
-
message: "Select models to synchronise:",
|
|
988
|
-
choices,
|
|
989
|
-
pageSize: 20,
|
|
990
|
-
},
|
|
991
|
-
]);
|
|
1036
|
+
const selectedModels = await selectModels(choices, "Select models to synchronise:");
|
|
992
1037
|
if (!selectedModels || selectedModels.length === 0) {
|
|
993
1038
|
console.log("No models selected. Exiting.");
|
|
994
1039
|
process.exit(0);
|
package/package.json
CHANGED