@statezero/core 0.1.1 → 0.1.2

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.
@@ -94,6 +94,64 @@ 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 selector 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>} - Selected values
104
+ */
105
+ async function fallbackSelect(choices, message) {
106
+ console.log(`\n${message}`);
107
+ console.log("Interactive selection not available - auto-selecting all available models:");
108
+ const selected = [];
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
+ // Auto-select items that were checked by default
116
+ if (choice.checked) {
117
+ selected.push(choice.value);
118
+ console.log(` ✓ ${choice.name}`);
119
+ }
120
+ else {
121
+ console.log(` ${choice.name}`);
122
+ }
123
+ }
124
+ console.log(`\nAuto-selected ${selected.length} models for generation.`);
125
+ return selected;
126
+ }
127
+ /**
128
+ * Model selection with inquirer fallback
129
+ * @param {Array} choices - Array of choice objects
130
+ * @param {string} message - Selection message
131
+ * @returns {Promise<Array>} - Selected model objects
132
+ */
133
+ async function selectModels(choices, message) {
134
+ try {
135
+ // Try to use inquirer first
136
+ const inquirer = (await import("inquirer")).default;
137
+ const { selectedModels } = await inquirer.prompt([
138
+ {
139
+ type: "checkbox",
140
+ name: "selectedModels",
141
+ message,
142
+ choices,
143
+ pageSize: 20,
144
+ },
145
+ ]);
146
+ return selectedModels;
147
+ }
148
+ catch (error) {
149
+ // Fall back to auto-selection if inquirer fails for any reason
150
+ console.warn("Interactive selection failed, falling back to auto-selection:", error.message);
151
+ return await fallbackSelect(choices, message);
152
+ }
153
+ }
154
+ // --------------------
97
155
  // Handlebars Templates & Helpers
98
156
  // --------------------
99
157
  // Updated JS_MODEL_TEMPLATE with getters and setters
@@ -944,14 +1002,12 @@ export declare const FileObject: typeof ${backend.NAME}FileObject;
944
1002
  // --------------------
945
1003
  // Main Runner: Fetch models and prompt selection
946
1004
  // --------------------
947
- // Update main function to use this new approach
948
1005
  async function main() {
949
1006
  // Load configuration from file (CLI-only or tests) before any other operations.
950
1007
  loadConfigFromFile();
951
1008
  // Retrieve the validated configuration from the global config singleton.
952
1009
  const configData = configInstance.getConfig();
953
1010
  const backendConfigs = configData.backendConfigs;
954
- const inquirer = (await import("inquirer")).default;
955
1011
  const fetchPromises = Object.keys(backendConfigs).map(async (key) => {
956
1012
  const backend = backendConfigs[key];
957
1013
  backend.NAME = key;
@@ -966,8 +1022,10 @@ async function main() {
966
1022
  });
967
1023
  const backendModels = await Promise.all(fetchPromises);
968
1024
  const choices = [];
1025
+ // Create a simple separator object for environments where inquirer.Separator isn't available
1026
+ const createSeparator = (text) => ({ name: text, value: null });
969
1027
  for (const { backend, models } of backendModels) {
970
- choices.push(new inquirer.Separator(`\n=== ${backend.NAME} ===\n`));
1028
+ choices.push(createSeparator(`\n=== ${backend.NAME} ===\n`));
971
1029
  for (const model of models) {
972
1030
  choices.push({
973
1031
  name: model,
@@ -980,15 +1038,7 @@ async function main() {
980
1038
  console.log("No models to synchronise");
981
1039
  process.exit(0);
982
1040
  }
983
- const { selectedModels } = await inquirer.prompt([
984
- {
985
- type: "checkbox",
986
- name: "selectedModels",
987
- message: "Select models to synchronise:",
988
- choices,
989
- pageSize: 20,
990
- },
991
- ]);
1041
+ const selectedModels = await selectModels(choices, "Select models to synchronise:");
992
1042
  if (!selectedModels || selectedModels.length === 0) {
993
1043
  console.log("No models selected. Exiting.");
994
1044
  process.exit(0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@statezero/core",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "module": "ESNext",
6
6
  "description": "The type-safe frontend client for StateZero - connect directly to your backend models with zero boilerplate",