(command: IAIAssistantCommand)
| 623 | } |
| 624 | |
| 625 | private async executeAIAssistant(command: IAIAssistantCommand) { |
| 626 | if (settingsStore.getState().disableOnlineFeatures) { |
| 627 | throw new Error( |
| 628 | "Blocking request: Online features are disabled in settings." |
| 629 | ); |
| 630 | } |
| 631 | |
| 632 | const aiSettings = settingsStore.getState().ai; |
| 633 | |
| 634 | const options = getModelNames(); |
| 635 | let modelName: string; |
| 636 | if (command.model === "Ask me") { |
| 637 | // Route to a remote interactive session (Raycast) when one is driving. |
| 638 | const provider = this.choiceExecutor.promptProvider; |
| 639 | if (provider) { |
| 640 | modelName = String( |
| 641 | await provider.suggester(options, options, "Select a model"), |
| 642 | ); |
| 643 | } else if (this.choiceExecutor.interactive === false) { |
| 644 | // Non-interactive run (CLI without `ui`): the "Ask me" model picker has |
| 645 | // no one to answer it. Abort with an actionable error instead of hanging. |
| 646 | throw new ChoiceAbortError( |
| 647 | "This AI command is set to \"Ask me\" for the model, but this run is non-interactive. " + |
| 648 | "Pick a specific model in the command, or re-run with the ui flag.", |
| 649 | ); |
| 650 | } else { |
| 651 | try { |
| 652 | modelName = await GenericSuggester.Suggest(this.app, options, options); |
| 653 | } catch (error) { |
| 654 | if (isCancellationError(error)) { |
| 655 | throw new UserCancelError("Input cancelled by user"); |
| 656 | } |
| 657 | throw error; |
| 658 | } |
| 659 | } |
| 660 | } else { |
| 661 | modelName = command.model; |
| 662 | } |
| 663 | |
| 664 | const model: Model | undefined = getModelByName(modelName); |
| 665 | |
| 666 | if (!model) { |
| 667 | throw new Error(`Model ${modelName} not found with any provider.`); |
| 668 | } |
| 669 | |
| 670 | const formatter = new CompleteFormatter( |
| 671 | this.app, |
| 672 | getQuickAddInstance(), |
| 673 | this.choiceExecutor |
| 674 | ); |
| 675 | |
| 676 | const modelProvider = getModelProvider(model.name); |
| 677 | |
| 678 | if (!modelProvider) { |
| 679 | throw new Error( |
| 680 | `Model ${model.name} not found in the AI providers settings.` |
| 681 | ); |
| 682 | } |
no test coverage detected