laohuang 0.9.4 → 0.9.5

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/bin.js CHANGED
@@ -39903,14 +39903,41 @@ async function main(argv, options = {}) {
39903
39903
  model: args.model,
39904
39904
  baseUrl: args.baseUrl
39905
39905
  });
39906
- if (!await validateConfiguredSelection({
39906
+ const validation = await validateConfiguredSelection({
39907
39907
  config,
39908
39908
  catalog: modelPlatform.catalog,
39909
39909
  providerAuth,
39910
39910
  presenter: startupPresenter
39911
- })) {
39911
+ });
39912
+ if (validation === false) {
39912
39913
  return 2;
39913
39914
  }
39915
+ if (typeof validation === "string") {
39916
+ const canRecover = (options.stdin ?? process.stdin).isTTY === true && (options.stdout ?? process.stdout).isTTY === true && !args.model && !environ["LAOHUANG_MODEL"];
39917
+ if (!canRecover) throw new Error(validation);
39918
+ outputFn(`${validation}. Please reconfigure profile '${config.profile}'.`);
39919
+ let selection;
39920
+ try {
39921
+ selection = await runInitialModelSelection({ selector, presenter: startupPresenter, providerAuth });
39922
+ } catch (error) {
39923
+ if (!(error instanceof PromptCancelledError) && !(error instanceof PromptEofError)) throw error;
39924
+ selection = null;
39925
+ }
39926
+ if (selection === null) {
39927
+ outputFn("Configuration cancelled.");
39928
+ return 0;
39929
+ }
39930
+ const saved = manager.resolve({ environ: {}, profile: config.profile });
39931
+ const baseUrl = selection.config.provider === saved.provider ? saved.baseUrl : selection.config.baseUrl;
39932
+ manager.configure({
39933
+ name: config.profile,
39934
+ provider: selection.config.provider,
39935
+ model: selection.config.model,
39936
+ baseUrl
39937
+ });
39938
+ config = { ...config, ...selection.config, baseUrl: args.baseUrl ?? environ["LAOHUANG_BASE_URL"] ?? baseUrl };
39939
+ outputFn(`Saved profile '${config.profile}' to ${configPath}`);
39940
+ }
39914
39941
  } else {
39915
39942
  const selection = await runInitialModelSelection({
39916
39943
  selector,
@@ -40328,7 +40355,7 @@ async function runInitialModelSelection(options) {
40328
40355
  async function validateConfiguredSelection(options) {
40329
40356
  const provider2 = options.catalog.getProvider(options.config.provider);
40330
40357
  if (provider2 === void 0) {
40331
- throw new Error(`Unknown provider: ${options.config.provider}`);
40358
+ return `Unknown provider: ${options.config.provider}`;
40332
40359
  }
40333
40360
  if (!await options.providerAuth.ensureConfigured(options.config.provider, {
40334
40361
  promptIfMissing: true,
@@ -40341,9 +40368,7 @@ async function validateConfiguredSelection(options) {
40341
40368
  }
40342
40369
  await options.catalog.refresh(options.config.provider);
40343
40370
  if (options.catalog.getModel(options.config.provider, options.config.model) === void 0) {
40344
- throw new Error(
40345
- `Unknown model: ${options.config.provider}/${options.config.model}`
40346
- );
40371
+ return `Unknown model: ${options.config.provider}/${options.config.model}`;
40347
40372
  }
40348
40373
  return true;
40349
40374
  }