diff --git a/src/cli.py b/src/cli.py index 1278087..fc654bf 100755 --- a/src/cli.py +++ b/src/cli.py @@ -116,12 +116,22 @@ def run_file(filepath): if not os.path.exists(filepath): print(f"\033[1;31m[!] Error: File '{filepath}' not found.\033[0m") sys.exit(1) + try: + from stdlib_modules import check_and_prompt_ai_engine + check_and_prompt_ai_engine() + except Exception: + pass with open(filepath, "r", encoding="utf-8") as f: code = f.read() run_code(code) def start_repl(): print(ASCII_BANNER) + try: + from stdlib_modules import check_and_prompt_ai_engine + check_and_prompt_ai_engine() + except Exception: + pass evaluator = Evaluator() buffer = [] @@ -223,6 +233,8 @@ Creator: {AUTHOR} airalang run Execute an AiraLang script airalang build [-o out] Compile script to standalone executable airalang new Create a new AiraLang project scaffold + airalang --ai-setup Configure Aira AI Engine API key (interactive) + airalang --set-key [provider] Set API key for provider (OpenRouter/Groq/OpenAI/Gemini) airalang -v, --version Display version information airalang -h, --help Show this help message """) @@ -234,6 +246,21 @@ def main(): print(f"AiraLang v{VERSION} | Creator: {AUTHOR}") elif arg1 in ("-h", "--help"): print_help() + elif arg1 in ("--ai-setup", "--setup-ai"): + from stdlib_modules import prompt_developer_for_ai_key + prompt_developer_for_ai_key() + sys.exit(0) + elif arg1 == "--set-key": + if len(sys.argv) > 2: + from stdlib_modules import create_ai_module + ai_mod = create_ai_module() + prov = sys.argv[3] if len(sys.argv) > 3 else None + ai_mod.methods["set_key"](sys.argv[2], provider=prov) + print(f"\033[1;32m✓ API Key successfully configured and saved to config!\033[0m") + sys.exit(0) + else: + print("\033[1;31m[!] Error: Specify API key: airalang --set-key [provider]\033[0m") + sys.exit(1) elif arg1 == "run": if len(sys.argv) > 2: run_file(sys.argv[2]) diff --git a/src/parser.py b/src/parser.py index 6dac874..7c27709 100644 --- a/src/parser.py +++ b/src/parser.py @@ -47,8 +47,18 @@ class Parser: RESET = "\033[0m" BOLD = "\033[1m" + ai_tag = "" + try: + from stdlib_modules import _GLOBAL_AI_STATE + has_key = any(v for k, v in _GLOBAL_AI_STATE["keys"].items() if k != "ollama" and v) + if has_key: + active_p = _GLOBAL_AI_STATE.get("active_provider", "ai").upper() + ai_tag = f" [AI Engine: {active_p}]" + except Exception: + pass + warning = ( - f"\n{CYAN}✨ [Aira Compiler Auto-Fix]:{RESET}\n" + f"\n{CYAN}✨ [Aira Compiler Auto-Fix{ai_tag}]:{RESET}\n" f"{YELLOW}Hey there! I am Aira From Aira Group Of Technology by Adam Eehan.{RESET}\n" f"Heyyy, here you missed a semicolon (;) at {BOLD}line {line}{RESET}!\n" f"Please concentrate on your code, now you can relax, I've put it automatically.\n" diff --git a/src/stdlib_modules.py b/src/stdlib_modules.py index 4b77981..5f8b748 100644 --- a/src/stdlib_modules.py +++ b/src/stdlib_modules.py @@ -533,15 +533,28 @@ def prompt_developer_for_ai_key(): cfg["keys"] = {} cfg["keys"][detected_provider] = user_key cfg["active_provider"] = detected_provider + cfg["ai_prompted"] = True save_airalang_config(cfg) print(f"{GREEN}✓ Aira AI Engine activated! Provider auto-detected as '{detected_provider}'.{RESET}") print(f"{CYAN}Identity: Aira AI by Adam Eehan. Saved to ~/.config/airalang/config.json{RESET}\n") return True else: - print(f"{YELLOW}ℹ️ Skipped. Aira AI running in offline mode.{RESET}\n") + cfg = load_airalang_config() + cfg["ai_prompted"] = True + save_airalang_config(cfg) + print(f"{YELLOW}ℹ️ Skipped. Aira AI running in offline mode. (Run 'airalang --ai-setup' anytime to activate){RESET}\n") return False +def check_and_prompt_ai_engine(force=False): + cfg = load_airalang_config() + has_key = any(v for k, v in _GLOBAL_AI_STATE["keys"].items() if k != "ollama" and v) + if has_key and not force: + return True + if cfg.get("ai_prompted") and not force: + return False + return prompt_developer_for_ai_key() + def create_ai_module(): state = _GLOBAL_AI_STATE