From 6c9681529d64a00d029f39aa881de392d40b4aae Mon Sep 17 00:00:00 2001 From: Jay Date: Tue, 21 Apr 2026 11:06:39 +0900 Subject: [PATCH] feat: add first-run auto-setup wizard (engine detection, model auto-config, brain dir creation) --- src/extension.ts | 56 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/src/extension.ts b/src/extension.ts index 8e1218e..4e46b0b 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -103,10 +103,64 @@ CRITICAL RULES: export function activate(context: vscode.ExtensionContext) { vscode.window.showInformationMessage('πŸ”₯ Connect AI V2 ν™œμ„±ν™” μ™„λ£Œ!'); -console.log('Connect AI extension activated.'); + console.log('Connect AI extension activated.'); const provider = new SidebarChatProvider(context.extensionUri, context); + // ========================================== + // 초기 μ„€μ • λ§ˆλ²•μ‚¬ (첫 μ‹€ν–‰ μ‹œμ—λ§Œ) + // ========================================== + const isFirstRun = !context.globalState.get('setupComplete'); + if (isFirstRun) { + (async () => { + try { + let engineName = ''; + let modelName = ''; + + // Step 1: AI μ—”μ§„ μžλ™ 감지 + try { + const lmRes = await axios.get('http://127.0.0.1:1234/v1/models', { timeout: 2000 }); + if (lmRes.data?.data?.length > 0) { + engineName = 'LM Studio'; + modelName = lmRes.data.data[0].id; + await vscode.workspace.getConfiguration('connectAiLab').update('ollamaBase', 'http://127.0.0.1:1234', vscode.ConfigurationTarget.Global); + await vscode.workspace.getConfiguration('connectAiLab').update('defaultModel', modelName, vscode.ConfigurationTarget.Global); + } + } catch {} + + if (!engineName) { + try { + const ollamaRes = await axios.get('http://127.0.0.1:11434/api/tags', { timeout: 2000 }); + if (ollamaRes.data?.models?.length > 0) { + engineName = 'Ollama'; + modelName = ollamaRes.data.models[0].name; + await vscode.workspace.getConfiguration('connectAiLab').update('ollamaBase', 'http://127.0.0.1:11434', vscode.ConfigurationTarget.Global); + await vscode.workspace.getConfiguration('connectAiLab').update('defaultModel', modelName, vscode.ConfigurationTarget.Global); + } + } catch {} + } + + // Step 2: λ‘λ‡Œ 폴더 μžλ™ 생성 + const brainDir = path.join(os.homedir(), '.connect-ai-brain'); + if (!fs.existsSync(brainDir)) { + fs.mkdirSync(brainDir, { recursive: true }); + } + + // Step 3: μ™„λ£Œ λ©”μ‹œμ§€ + context.globalState.update('setupComplete', true); + + if (engineName) { + vscode.window.showInformationMessage(`🧠 μžλ™ μ„€μ • μ™„λ£Œ! ${engineName} 감지됨 β†’ λͺ¨λΈ: ${modelName}`); + } else { + vscode.window.showInformationMessage('🧠 Connect AI μ€€λΉ„ μ™„λ£Œ! LM Studio λ˜λŠ” Ollamaλ₯Ό μ‹€ν–‰ν•˜λ©΄ μžλ™ μ—°κ²°λ©λ‹ˆλ‹€.'); + } + } catch (e) { + // λ§ˆλ²•μ‚¬ μ‹€νŒ¨ν•΄λ„ λ¬΄μ‹œ (μ΅μŠ€ν…μ…˜ 정상 μž‘λ™) + context.globalState.update('setupComplete', true); + } + })(); + } + // ========================================== // EZER AI <-> Connect AI Bridge Server (Port 4825) // ==========================================