@nine-lab/nine-mu 0.1.134 → 0.1.136
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/css/nine-mu.css +3 -1
- package/dist/nine-mu.js +205 -101
- package/dist/nine-mu.js.map +1 -1
- package/dist/nine-mu.umd.js +3 -3
- package/dist/nine-mu.umd.js.map +1 -1
- package/package.json +1 -1
- package/public/css/nine-mu.css +3 -1
- package/src/components/NineChat.js +4 -0
- package/src/components/NineChatManager.js +121 -0
package/package.json
CHANGED
package/public/css/nine-mu.css
CHANGED
|
@@ -172,7 +172,7 @@
|
|
|
172
172
|
}
|
|
173
173
|
|
|
174
174
|
.foot {
|
|
175
|
-
margin-bottom:
|
|
175
|
+
margin-bottom: 4px;
|
|
176
176
|
width: 100%;
|
|
177
177
|
height: 200px;
|
|
178
178
|
--background: #f0f0f0;
|
|
@@ -198,6 +198,8 @@
|
|
|
198
198
|
border-radius: 8px;
|
|
199
199
|
resize: none;
|
|
200
200
|
padding: 8px;
|
|
201
|
+
background: white;
|
|
202
|
+
color: #333;
|
|
201
203
|
}
|
|
202
204
|
textarea:hover {
|
|
203
205
|
border: 1px solid #999;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { trace } from "@nopeer";
|
|
2
2
|
import { nine, api } from '@nine-lab/nine-util';
|
|
3
|
+
import { NineChatManager } from './NineChatManager.js';
|
|
3
4
|
import { NineMuService } from '../services/NineMuService.js';
|
|
4
5
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
5
6
|
import { WebSocketClientTransport } from "@modelcontextprotocol/sdk/client/websocket.js";
|
|
@@ -12,6 +13,7 @@ export class NineChat extends HTMLElement {
|
|
|
12
13
|
#routesPath;
|
|
13
14
|
#connectorUrl;
|
|
14
15
|
#mcpClient;
|
|
16
|
+
#manager;
|
|
15
17
|
|
|
16
18
|
constructor() {
|
|
17
19
|
super();
|
|
@@ -38,6 +40,8 @@ export class NineChat extends HTMLElement {
|
|
|
38
40
|
|
|
39
41
|
// 경로 데이터 로드
|
|
40
42
|
this.#routes = await this.#service.fetchRoutes(this.getAttribute('route-url'));
|
|
43
|
+
|
|
44
|
+
this.#manager = new NineChatManager(this);
|
|
41
45
|
}
|
|
42
46
|
|
|
43
47
|
// --- [그룹 1: Interaction] 화면 토글 및 메뉴 클릭 ---
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
|
+
import { WebSocketClientTransport } from "@modelcontextprotocol/sdk/client/websocket.js";
|
|
3
|
+
import { trace, api, nine } from "@nine-lab/nine-util";
|
|
4
|
+
|
|
5
|
+
export class NineChatManager {
|
|
6
|
+
#client;
|
|
7
|
+
#connectorUrl;
|
|
8
|
+
#onAction;
|
|
9
|
+
#onStatus;
|
|
10
|
+
#onMessage; // UI에 메시지를 뿌려줄 콜백 추가
|
|
11
|
+
#owner;
|
|
12
|
+
|
|
13
|
+
constructor(owner, callbacks = {}) {
|
|
14
|
+
this.#owner = owner;
|
|
15
|
+
this.#connectorUrl = this.#owner.getAttribute('connector-url');
|
|
16
|
+
|
|
17
|
+
// 콜백 함수들 연결
|
|
18
|
+
this.#onAction = callbacks.onAction;
|
|
19
|
+
this.#onStatus = callbacks.onStatus;
|
|
20
|
+
this.#onMessage = callbacks.onMessage;
|
|
21
|
+
|
|
22
|
+
// 연결 시작 (비동기)
|
|
23
|
+
this.connect();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async connect() {
|
|
27
|
+
if (this.#client) return;
|
|
28
|
+
try {
|
|
29
|
+
const transport = new WebSocketClientTransport(new URL(this.#connectorUrl));
|
|
30
|
+
this.#client = new Client({
|
|
31
|
+
name: "nine-mu-client", version: "1.0.0"
|
|
32
|
+
}, { capabilities: { tools: {} } });
|
|
33
|
+
|
|
34
|
+
await this.#client.connect(transport);
|
|
35
|
+
this.#updateStatus("✅ MCP Connected");
|
|
36
|
+
} catch (err) {
|
|
37
|
+
trace.error("❌ Orchestrator Connection Failed", err);
|
|
38
|
+
this.#updateStatus("❌ Connection Failed");
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** 메인 실행 함수 */
|
|
43
|
+
async ask(userInput) {
|
|
44
|
+
if (!this.#client) {
|
|
45
|
+
await this.connect(); // 미연결 시 연결 대기
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
// 1. 사용자 메시지 UI 전송
|
|
50
|
+
this.#pushMessage('user', userInput);
|
|
51
|
+
|
|
52
|
+
// 2. Maps 데이터 로드
|
|
53
|
+
const routes = await this.#fetchRoutes();
|
|
54
|
+
|
|
55
|
+
// 3. AI 엔진(Brain) 호출
|
|
56
|
+
const response = await this.#client.callTool({
|
|
57
|
+
name: "system-brain",
|
|
58
|
+
arguments: {
|
|
59
|
+
user_input: userInput,
|
|
60
|
+
routes: routes,
|
|
61
|
+
current_path: window.location.pathname // 실시간 경로 주입
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// 4. 결과 파싱 및 처리
|
|
66
|
+
const result = JSON.parse(response.content[0].text);
|
|
67
|
+
console.log("AI Response:", result);
|
|
68
|
+
|
|
69
|
+
// 5. AI 메시지 UI 전송 (DATA_REQUEST 버튼 처리를 위해 result 포함)
|
|
70
|
+
this.#pushMessage('assistant', result.message, result);
|
|
71
|
+
|
|
72
|
+
// 6. 시스템 액션(페이지 이동 등) 수행
|
|
73
|
+
if (this.#onAction) this.#onAction(result);
|
|
74
|
+
|
|
75
|
+
this.#updateStatus("준비 완료");
|
|
76
|
+
|
|
77
|
+
} catch (err) {
|
|
78
|
+
trace.error("❌ Ask Error:", err);
|
|
79
|
+
this.#pushMessage('assistant', "분석 중 오류가 발생했습니다.");
|
|
80
|
+
this.#updateStatus("에러 발생");
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** 데이터 수집 (클라이언트 클릭 한방용) */
|
|
85
|
+
async collect(type) {
|
|
86
|
+
this.#updateStatus(`${type} 데이터 수집 중...`);
|
|
87
|
+
// 웹 컴포넌트 환경에서는 전역 객체나 특정 DOM에서 데이터를 긁어옴
|
|
88
|
+
switch (type) {
|
|
89
|
+
case 'SOURCE':
|
|
90
|
+
return window?.nineEditor?.getValue() || "/* 소스를 찾을 수 없습니다 */";
|
|
91
|
+
case 'DDL':
|
|
92
|
+
return "/* DDL 정보가 수집되었습니다 */";
|
|
93
|
+
default:
|
|
94
|
+
return "";
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async #fetchRoutes() {
|
|
99
|
+
const r = await fetch("/admin/prompts/data/routes.json");
|
|
100
|
+
return r.ok ? await r.json() : [];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
#pushMessage(role, content, result = null) {
|
|
104
|
+
if (this.#onMessage) {
|
|
105
|
+
this.#onMessage({
|
|
106
|
+
role,
|
|
107
|
+
content,
|
|
108
|
+
intent: result?.intent,
|
|
109
|
+
required_args: result?.action?.required_args,
|
|
110
|
+
action: result?.action
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
#updateStatus(msg) {
|
|
116
|
+
if (this.#onStatus) this.#onStatus(msg);
|
|
117
|
+
trace.log(`[Status]: ${msg}`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export default NineChatManager;
|