@fivetu53/soul-chat 1.0.6 → 1.0.7
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/bin/api.js +9 -0
- package/bin/index.js +49 -1
- package/package.json +1 -1
package/bin/api.js
CHANGED
|
@@ -219,6 +219,15 @@ export async function clearConversation(conversationId) {
|
|
|
219
219
|
return data;
|
|
220
220
|
}
|
|
221
221
|
|
|
222
|
+
export async function deleteMessage(messageId) {
|
|
223
|
+
const response = await request(`/api/chat/messages/${messageId}`, {
|
|
224
|
+
method: 'DELETE'
|
|
225
|
+
});
|
|
226
|
+
const data = await response.json();
|
|
227
|
+
if (!response.ok) throw new Error(data.error);
|
|
228
|
+
return data;
|
|
229
|
+
}
|
|
230
|
+
|
|
222
231
|
// Memory APIs
|
|
223
232
|
export async function getMemories(characterId) {
|
|
224
233
|
const response = await request(`/api/memories/${characterId}`);
|
package/bin/index.js
CHANGED
|
@@ -10,7 +10,7 @@ import { loadConfig, saveConfig, getConfigPath } from './config.js';
|
|
|
10
10
|
import { checkAuth, showAuthScreen } from './auth.js';
|
|
11
11
|
import {
|
|
12
12
|
isLoggedIn, getCurrentUser, logout, updateProfile,
|
|
13
|
-
sendMessage, getCharacters, createCharacter, getConversations, getMessages, clearConversation, getMemories, pinMemory, deleteMemory
|
|
13
|
+
sendMessage, getCharacters, createCharacter, getConversations, getMessages, clearConversation, deleteMessage, getMemories, pinMemory, deleteMemory
|
|
14
14
|
} from './api.js';
|
|
15
15
|
|
|
16
16
|
// Setup marked with terminal renderer
|
|
@@ -191,6 +191,19 @@ async function showWelcome() {
|
|
|
191
191
|
await waitForEnter();
|
|
192
192
|
}
|
|
193
193
|
|
|
194
|
+
// 检查版本更新
|
|
195
|
+
let versionInfo = null;
|
|
196
|
+
async function checkVersion() {
|
|
197
|
+
try {
|
|
198
|
+
const pkg = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
199
|
+
const currentVersion = pkg.version;
|
|
200
|
+
const latestVersion = execSync('npm view @fivetu53/soul-chat version --registry https://registry.npmmirror.com 2>/dev/null', { encoding: 'utf8', timeout: 5000 }).trim();
|
|
201
|
+
versionInfo = { current: currentVersion, latest: latestVersion, hasUpdate: latestVersion !== currentVersion };
|
|
202
|
+
} catch (err) {
|
|
203
|
+
// 忽略版本检查错误
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
194
207
|
// 页面:菜单
|
|
195
208
|
async function showMenu() {
|
|
196
209
|
const menuItems = [
|
|
@@ -221,6 +234,15 @@ async function showMenu() {
|
|
|
221
234
|
console.log();
|
|
222
235
|
console.log(c('hint', ' 使用方向键选择,Enter 确认'));
|
|
223
236
|
console.log(c('primary', ' 门户网站: https://soul-chat.jdctools.com.cn'));
|
|
237
|
+
|
|
238
|
+
// 显示版本信息
|
|
239
|
+
if (versionInfo) {
|
|
240
|
+
if (versionInfo.hasUpdate) {
|
|
241
|
+
console.log(c('yellow', ` 发现新版本: v${versionInfo.current} → v${versionInfo.latest},运行 soul update 更新`));
|
|
242
|
+
} else {
|
|
243
|
+
console.log(c('hint', ` 当前版本: v${versionInfo.current} (最新)`));
|
|
244
|
+
}
|
|
245
|
+
}
|
|
224
246
|
};
|
|
225
247
|
|
|
226
248
|
draw();
|
|
@@ -484,6 +506,29 @@ async function showChat() {
|
|
|
484
506
|
continue;
|
|
485
507
|
}
|
|
486
508
|
|
|
509
|
+
if (input === '/delete') {
|
|
510
|
+
// 删除最后一轮对话(用户消息+AI回复)
|
|
511
|
+
if (messages.length >= 2) {
|
|
512
|
+
const lastUserMsg = [...messages].reverse().find(m => m.role === 'user' && m.id);
|
|
513
|
+
if (lastUserMsg?.id) {
|
|
514
|
+
try {
|
|
515
|
+
await deleteMessage(lastUserMsg.id);
|
|
516
|
+
// 从本地移除最后一轮对话
|
|
517
|
+
const userIdx = messages.lastIndexOf(lastUserMsg);
|
|
518
|
+
if (userIdx !== -1) {
|
|
519
|
+
messages.splice(userIdx, 2); // 删除用户消息和AI回复
|
|
520
|
+
}
|
|
521
|
+
} catch (err) {
|
|
522
|
+
// 忽略
|
|
523
|
+
}
|
|
524
|
+
} else {
|
|
525
|
+
// 没有ID,只删除本地
|
|
526
|
+
messages.splice(-2, 2);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
continue;
|
|
530
|
+
}
|
|
531
|
+
|
|
487
532
|
messages.push({ role: 'user', text: input });
|
|
488
533
|
drawMessages();
|
|
489
534
|
|
|
@@ -1083,6 +1128,9 @@ async function main() {
|
|
|
1083
1128
|
|
|
1084
1129
|
await showWelcome();
|
|
1085
1130
|
|
|
1131
|
+
// 后台检查版本更新
|
|
1132
|
+
checkVersion();
|
|
1133
|
+
|
|
1086
1134
|
while (true) {
|
|
1087
1135
|
const choice = await showMenu();
|
|
1088
1136
|
|