@nine-lab/nine-mu 0.1.143 → 0.1.144

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nine-lab/nine-mu",
3
- "version": "0.1.143",
3
+ "version": "0.1.144",
4
4
  "description": "AI-Driven Full-Stack Code Fabrication Engine",
5
5
  "type": "module",
6
6
  "main": "./dist/nine-mu.umd.js",
@@ -32,7 +32,6 @@ export class NineChat extends HTMLElement {
32
32
  this.#render();
33
33
  this.#initInteractions(); // UI 토글 로직
34
34
  this.#initActions(); // 엔터 시 실행 로직
35
- this.#initMcp();
36
35
 
37
36
  const res = await api.post("/nine-mu/config/get", {});
38
37
  this.#routesPath = res?.userDir + "/" + this.#packageName + "/public/prompts/data/routes.json";
@@ -69,7 +68,6 @@ export class NineChat extends HTMLElement {
69
68
  // --- [그룹 2: Action] 엔터키 입력 시 서비스 호출 ---
70
69
  #initActions() {
71
70
  const $textarea = this.shadowRoot.querySelector('#q');
72
- const $status = this.shadowRoot.querySelector('#status-tag');
73
71
 
74
72
  $textarea.addEventListener('keypress', async (e) => {
75
73
  if (e.key === 'Enter' && !e.shiftKey) {
@@ -77,7 +75,7 @@ export class NineChat extends HTMLElement {
77
75
  const userInput = e.target.value.trim();
78
76
  if (!userInput) return;
79
77
 
80
-
78
+ await this.#manager.handleChatSubmit($textarea);
81
79
  // async onUserInput(userInput) {
82
80
  // "어떤 툴을 써라"가 아니라 "이 질문을 해결해라"라고 던짐
83
81
  // 그러면 AI가 위 툴 목록 중 'analyze_menu_gap'이 적절한지 스스로 판단해서 실행함
@@ -95,59 +93,11 @@ export class NineChat extends HTMLElement {
95
93
  // 2. 서버(AI)가 실행하고 보내준 결과물 파싱
96
94
  const result = JSON.parse(response.content[0].text);
97
95
 
98
- // AI가 툴을 실행하고 가져온 결과(action)에 따라 화면만 띄움
99
- if (result.action === "SHOW_DIFF") this.openDiff(result);
100
- //}
101
-
102
-
103
-
104
- /**
105
- // 1. UI 피드백
106
- $status.textContent = "⚙️ 공정 분석 중...";
107
- e.target.value = '';
108
-
109
- // 2. 체크된 타겟 수집
110
- const targets = Array.from(this.shadowRoot.querySelectorAll('input[name="gen_target"]:checked'))
111
- .map(el => el.value);
112
-
113
- // 3. 분리된 서비스 호출
114
- try {
115
- const result = await this.#service.generate(command, targets, this.#routes);
116
-
117
- // 4. 성공 처리
118
- $status.textContent = "✅ 완료";
119
- nine.alert("소스 생성 성공").rgb();
120
- this.dispatchEvent(new CustomEvent('nine-mu-completed', { detail: result, bubbles: true }));
121
- } catch (err) {
122
- // 5. 실패 처리
123
- $status.textContent = "❌ 실패";
124
- nine.alert(err.message).rgb().shake();
125
- } */
96
+ if (result.action === "SHOW_DIFF") this.openDiff(result);
126
97
  }
127
98
  });
128
99
  }
129
100
 
130
- #initMcp = async () => {
131
- // 중복 연결 방지
132
- if (this.#mcpClient) return;
133
-
134
- try {
135
- // [변경] WebSocket 트랜스포트 설정 (서버 주소와 프로토콜 확인)
136
- const transport = new WebSocketClientTransport(new URL(this.#connectorUrl));
137
-
138
- this.#mcpClient = new Client({
139
- name: "nine-mcp-client",
140
- version: "1.0.0"
141
- }, { capabilities: { tools: {} } });
142
-
143
- trace.log("Connecting to MCP via WebSocket...");
144
- await this.#mcpClient.connect(transport);
145
-
146
- trace.log("✅ Nine MCP Connected (WebSocket)");
147
- } catch (err) {
148
- trace.error("❌ MCP 초기화 에러:", err);
149
- }
150
- };
151
101
 
152
102
  #render() {
153
103
  const placeholder = this.getAttribute("placeholder") || "나에게 무엇이든 물어봐...";
@@ -3,7 +3,7 @@ import { WebSocketClientTransport } from "@modelcontextprotocol/sdk/client/webso
3
3
  import { trace, api, nine } from "@nine-lab/nine-util";
4
4
 
5
5
  export class NineChatManager {
6
- #client;
6
+ #mcpClient;
7
7
  #onAction;
8
8
  #onStatus;
9
9
  #onMessage; // UI에 메시지를 뿌려줄 콜백 추가
@@ -22,18 +22,17 @@ export class NineChatManager {
22
22
  }
23
23
 
24
24
  async #connect() {
25
- if (this.#client) return;
25
+ if (this.#mcpClient) return;
26
26
 
27
27
  const connectorUrl = this.#owner.getAttribute('connector-url');
28
- const transport = new WebSocketClientTransport(new URL(connectorUrl));
29
28
 
30
- this.#client = new Client({
29
+ const transport = new WebSocketClientTransport(new URL(connectorUrl));
30
+ this.#mcpClient = new Client({
31
31
  name: "nine-mu-client", version: "1.0.0"
32
32
  }, { capabilities: { tools: {} } });
33
33
 
34
- trace.log("==============");
35
- // 전역 nine 객체의 safe를 활용 (try-catch 제거)
36
- this.#client.connect(transport)
34
+
35
+ this.#mcpClient.connect(transport)
37
36
  .then(() => {
38
37
  this.#updateStatus("✅ MCP Connected");
39
38
  })
@@ -41,29 +40,11 @@ export class NineChatManager {
41
40
  trace.error("❌ MCP 연결 실패", err);
42
41
  this.#updateStatus("❌ Connection Failed");
43
42
  });
44
-
45
-
46
- return;
47
-
48
- try {
49
- const connectorUrl = this.#owner.getAttribute('connector-url');
50
-
51
- const transport = new WebSocketClientTransport(new URL(connectorUrl));
52
- this.#client = new Client({
53
- name: "nine-mu-client", version: "1.0.0"
54
- }, { capabilities: { tools: {} } });
55
-
56
- await this.#client.connect(transport);
57
- this.#updateStatus("✅ MCP Connected");
58
- } catch (err) {
59
- trace.error("❌ Orchestrator Connection Failed", err);
60
- this.#updateStatus("❌ Connection Failed");
61
- }
62
43
  }
63
44
 
64
45
  /** 메인 실행 함수 */
65
46
  async ask(userInput) {
66
- if (!this.#client) {
47
+ if (!this.#mcpClient) {
67
48
  await this.connect(); // 미연결 시 연결 대기
68
49
  }
69
50
 
@@ -75,7 +56,7 @@ export class NineChatManager {
75
56
  const routes = await this.#fetchRoutes();
76
57
 
77
58
  // 3. AI 엔진(Brain) 호출
78
- const response = await this.#client.callTool({
59
+ const response = await this.#mcpClient.callTool({
79
60
  name: "system-brain",
80
61
  arguments: {
81
62
  user_input: userInput,
@@ -138,4 +119,16 @@ export class NineChatManager {
138
119
  if (this.#onStatus) this.#onStatus(msg);
139
120
  trace.log(`[Status]: ${msg}`);
140
121
  }
122
+
123
+ handleChatSubmit = async el => {
124
+ const response = await this.#mcpClient.callTool({
125
+ name: "ask_nine_engine",
126
+ arguments: {
127
+ prompt: el.value.trim(),
128
+ routes: [] // 현재 화면의 메뉴 정보
129
+ }
130
+ });
131
+
132
+ console.log(response);
133
+ }
141
134
  }