@nine-lab/nine-mu 0.1.185 → 0.1.187
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/nine-mu.js +21 -60
- 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/src/components/NineChatManager.js +23 -70
package/package.json
CHANGED
|
@@ -9,6 +9,7 @@ export class NineChatManager {
|
|
|
9
9
|
#onMessage; // UI에 메시지를 뿌려줄 콜백 추가
|
|
10
10
|
#owner;
|
|
11
11
|
#routeUrl;
|
|
12
|
+
#chatHistory = []; // 💡 이전 대화들을 저장할 메모리 창고
|
|
12
13
|
|
|
13
14
|
constructor(owner, callbacks = {}) {
|
|
14
15
|
this.#owner = owner;
|
|
@@ -43,49 +44,20 @@ export class NineChatManager {
|
|
|
43
44
|
trace.error("❌ MCP 연결 실패", err);
|
|
44
45
|
this.#updateStatus("❌ Connection Failed");
|
|
45
46
|
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/** 메인 실행 함수 */
|
|
49
|
-
async ask(userInput) {
|
|
50
|
-
if (!this.#mcpClient) {
|
|
51
|
-
await this.connect(); // 미연결 시 연결 대기
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
try {
|
|
55
|
-
// 1. 사용자 메시지 UI 전송
|
|
56
|
-
this.#pushMessage('user', userInput);
|
|
57
47
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
user_input: userInput,
|
|
66
|
-
routes: routes,
|
|
67
|
-
current_path: window.location.pathname // 실시간 경로 주입
|
|
48
|
+
this.#mcpClient.onNotification((notification) => {
|
|
49
|
+
console.log(notification);
|
|
50
|
+
if (notification.method === "notifications/logging/message") {
|
|
51
|
+
const data = JSON.parse(notification.params.message);
|
|
52
|
+
if (data.type === "BRAIN_DECISION") {
|
|
53
|
+
// UI에 중간 진행 상황 출력 ("ai", data.message);
|
|
54
|
+
//this.#pushMessage('assistant', data.message);
|
|
68
55
|
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const result = JSON.parse(response.content[0].text);
|
|
73
|
-
console.log("AI Response:", result);
|
|
74
|
-
|
|
75
|
-
// 5. AI 메시지 UI 전송 (DATA_REQUEST 버튼 처리를 위해 result 포함)
|
|
76
|
-
this.#pushMessage('assistant', result.message, result);
|
|
77
|
-
|
|
78
|
-
// 6. 시스템 액션(페이지 이동 등) 수행
|
|
79
|
-
if (this.#onAction) this.#onAction(result);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
80
59
|
|
|
81
|
-
this.#updateStatus("준비 완료");
|
|
82
60
|
|
|
83
|
-
} catch (err) {
|
|
84
|
-
trace.error("❌ Ask Error:", err);
|
|
85
|
-
this.#pushMessage('assistant', "분석 중 오류가 발생했습니다.");
|
|
86
|
-
this.#updateStatus("에러 발생");
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
61
|
|
|
90
62
|
/** 데이터 수집 (클라이언트 클릭 한방용) */
|
|
91
63
|
async collect(type) {
|
|
@@ -101,22 +73,7 @@ export class NineChatManager {
|
|
|
101
73
|
}
|
|
102
74
|
}
|
|
103
75
|
|
|
104
|
-
async #fetchRoutes() {
|
|
105
|
-
const r = await fetch("/admin/prompts/data/routes.json");
|
|
106
|
-
return r.ok ? await r.json() : [];
|
|
107
|
-
}
|
|
108
76
|
|
|
109
|
-
#pushMessage(role, content, result = null) {
|
|
110
|
-
if (this.#onMessage) {
|
|
111
|
-
this.#onMessage({
|
|
112
|
-
role,
|
|
113
|
-
content,
|
|
114
|
-
intent: result?.intent,
|
|
115
|
-
required_args: result?.action?.required_args,
|
|
116
|
-
action: result?.action
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
77
|
|
|
121
78
|
#updateStatus(msg) {
|
|
122
79
|
if (this.#onStatus) this.#onStatus(msg);
|
|
@@ -130,40 +87,36 @@ export class NineChatManager {
|
|
|
130
87
|
async #getRoutes(toolName, args = {}) {
|
|
131
88
|
|
|
132
89
|
const res = await fetch(this.#routeUrl);
|
|
133
|
-
|
|
134
|
-
throw new Error(`HTTP error! status: ${res.status}`);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return await res.json();
|
|
90
|
+
return res.ok ? await res.json() : [];
|
|
138
91
|
}
|
|
139
92
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
#chatHistory = []; // 💡 이전 대화들을 저장할 메모리 창고
|
|
145
|
-
|
|
146
93
|
addChatHistory(message) {
|
|
147
94
|
|
|
148
95
|
this.#chatHistory.push({ role: 'ai', text: message });
|
|
149
96
|
}
|
|
150
97
|
|
|
151
|
-
handleChatSubmit = async
|
|
98
|
+
handleChatSubmit = async userInput => {
|
|
152
99
|
|
|
153
|
-
|
|
100
|
+
/**
|
|
101
|
+
if (!this.#mcpClient) {
|
|
102
|
+
this.#updateStatus("⏳ 연결 대기 중...");
|
|
103
|
+
return [null, new Error("MCP 클라이언트가 연결되지 않았습니다.")];
|
|
104
|
+
} */
|
|
105
|
+
|
|
106
|
+
this.#chatHistory.push({ role: 'user', text: userInput });
|
|
154
107
|
|
|
155
108
|
// 1. 이전 대화 내역을 하나의 텍스트 포맷으로 예쁘게 말아줍니다.
|
|
156
109
|
const formattedHistory = this.#chatHistory.map(chat => {
|
|
157
110
|
return chat.role === 'user' ? `User: ${chat.text}` : `AI: ${chat.text}`;
|
|
158
111
|
}).join('\n');
|
|
159
|
-
|
|
112
|
+
const currentPath = window.location.pathname;
|
|
160
113
|
|
|
161
114
|
// 2. AI 호출 시 history를 함께 실어서 보냅니다.
|
|
162
115
|
return await this.#callTool("system-brain", {
|
|
163
|
-
user_input :
|
|
116
|
+
user_input : userInput,
|
|
164
117
|
chat_history: formattedHistory,
|
|
165
118
|
routes : await this.#getRoutes(),
|
|
166
|
-
current_path :
|
|
119
|
+
current_path : currentPath,
|
|
167
120
|
});
|
|
168
121
|
}
|
|
169
122
|
}
|