@nine-lab/nine-mu 0.1.185 → 0.1.186
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 +14 -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 +13 -71
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;
|
|
@@ -45,47 +46,7 @@ export class NineChatManager {
|
|
|
45
46
|
});
|
|
46
47
|
}
|
|
47
48
|
|
|
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
|
-
|
|
58
|
-
// 2. Maps 데이터 로드
|
|
59
|
-
const routes = await this.#fetchRoutes();
|
|
60
|
-
|
|
61
|
-
// 3. AI 엔진(Brain) 호출
|
|
62
|
-
const response = await this.#mcpClient.callTool({
|
|
63
|
-
name: "system-brain",
|
|
64
|
-
arguments: {
|
|
65
|
-
user_input: userInput,
|
|
66
|
-
routes: routes,
|
|
67
|
-
current_path: window.location.pathname // 실시간 경로 주입
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
// 4. 결과 파싱 및 처리
|
|
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
49
|
|
|
78
|
-
// 6. 시스템 액션(페이지 이동 등) 수행
|
|
79
|
-
if (this.#onAction) this.#onAction(result);
|
|
80
|
-
|
|
81
|
-
this.#updateStatus("준비 완료");
|
|
82
|
-
|
|
83
|
-
} catch (err) {
|
|
84
|
-
trace.error("❌ Ask Error:", err);
|
|
85
|
-
this.#pushMessage('assistant', "분석 중 오류가 발생했습니다.");
|
|
86
|
-
this.#updateStatus("에러 발생");
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
50
|
|
|
90
51
|
/** 데이터 수집 (클라이언트 클릭 한방용) */
|
|
91
52
|
async collect(type) {
|
|
@@ -101,22 +62,7 @@ export class NineChatManager {
|
|
|
101
62
|
}
|
|
102
63
|
}
|
|
103
64
|
|
|
104
|
-
async #fetchRoutes() {
|
|
105
|
-
const r = await fetch("/admin/prompts/data/routes.json");
|
|
106
|
-
return r.ok ? await r.json() : [];
|
|
107
|
-
}
|
|
108
65
|
|
|
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
66
|
|
|
121
67
|
#updateStatus(msg) {
|
|
122
68
|
if (this.#onStatus) this.#onStatus(msg);
|
|
@@ -130,40 +76,36 @@ export class NineChatManager {
|
|
|
130
76
|
async #getRoutes(toolName, args = {}) {
|
|
131
77
|
|
|
132
78
|
const res = await fetch(this.#routeUrl);
|
|
133
|
-
|
|
134
|
-
throw new Error(`HTTP error! status: ${res.status}`);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return await res.json();
|
|
79
|
+
return res.ok ? await res.json() : [];
|
|
138
80
|
}
|
|
139
81
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
#chatHistory = []; // 💡 이전 대화들을 저장할 메모리 창고
|
|
145
|
-
|
|
146
82
|
addChatHistory(message) {
|
|
147
83
|
|
|
148
84
|
this.#chatHistory.push({ role: 'ai', text: message });
|
|
149
85
|
}
|
|
150
86
|
|
|
151
|
-
handleChatSubmit = async
|
|
87
|
+
handleChatSubmit = async userInput => {
|
|
152
88
|
|
|
153
|
-
|
|
89
|
+
/**
|
|
90
|
+
if (!this.#mcpClient) {
|
|
91
|
+
this.#updateStatus("⏳ 연결 대기 중...");
|
|
92
|
+
return [null, new Error("MCP 클라이언트가 연결되지 않았습니다.")];
|
|
93
|
+
} */
|
|
94
|
+
|
|
95
|
+
this.#chatHistory.push({ role: 'user', text: userInput });
|
|
154
96
|
|
|
155
97
|
// 1. 이전 대화 내역을 하나의 텍스트 포맷으로 예쁘게 말아줍니다.
|
|
156
98
|
const formattedHistory = this.#chatHistory.map(chat => {
|
|
157
99
|
return chat.role === 'user' ? `User: ${chat.text}` : `AI: ${chat.text}`;
|
|
158
100
|
}).join('\n');
|
|
159
|
-
|
|
101
|
+
const currentPath = window.location.pathname;
|
|
160
102
|
|
|
161
103
|
// 2. AI 호출 시 history를 함께 실어서 보냅니다.
|
|
162
104
|
return await this.#callTool("system-brain", {
|
|
163
|
-
user_input :
|
|
105
|
+
user_input : userInput,
|
|
164
106
|
chat_history: formattedHistory,
|
|
165
107
|
routes : await this.#getRoutes(),
|
|
166
|
-
current_path :
|
|
108
|
+
current_path : currentPath,
|
|
167
109
|
});
|
|
168
110
|
}
|
|
169
111
|
}
|