@fivetu53/soul-chat 1.0.5 → 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 +52 -12
- 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
|
|
@@ -121,17 +121,9 @@ end try`;
|
|
|
121
121
|
if (result !== 'ok') return null;
|
|
122
122
|
} else if (process.platform === 'win32') {
|
|
123
123
|
// Windows: 用 PowerShell 导出剪贴板图片
|
|
124
|
-
|
|
125
|
-
const psScript = `
|
|
126
|
-
|
|
127
|
-
$img = [System.Windows.Forms.Clipboard]::GetImage()
|
|
128
|
-
if ($img) {
|
|
129
|
-
$img.Save('${tmpFile.replace(/\\/g, '/')}', [System.Drawing.Imaging.ImageFormat]::Png)
|
|
130
|
-
Write-Output 'ok'
|
|
131
|
-
} else {
|
|
132
|
-
Write-Output 'no'
|
|
133
|
-
}`;
|
|
134
|
-
const result = execSync(`powershell -NoProfile -ExecutionPolicy Bypass -Command "${psScript.replace(/"/g, '\\"').replace(/\n/g, ' ')}"`, { encoding: 'utf8', windowsHide: true }).trim();
|
|
124
|
+
const savePath = tmpFile.replace(/\\/g, '/');
|
|
125
|
+
const psScript = `Add-Type -AssemblyName System.Windows.Forms; $img = [System.Windows.Forms.Clipboard]::GetImage(); if ($img) { $img.Save('${savePath}', [System.Drawing.Imaging.ImageFormat]::Png); Write-Output 'ok' } else { Write-Output 'no' }`;
|
|
126
|
+
const result = execSync(`powershell -NoProfile -ExecutionPolicy Bypass -Command "${psScript}"`, { encoding: 'utf8', windowsHide: true }).trim();
|
|
135
127
|
if (result !== 'ok') return null;
|
|
136
128
|
} else {
|
|
137
129
|
return null;
|
|
@@ -199,6 +191,19 @@ async function showWelcome() {
|
|
|
199
191
|
await waitForEnter();
|
|
200
192
|
}
|
|
201
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
|
+
|
|
202
207
|
// 页面:菜单
|
|
203
208
|
async function showMenu() {
|
|
204
209
|
const menuItems = [
|
|
@@ -229,6 +234,15 @@ async function showMenu() {
|
|
|
229
234
|
console.log();
|
|
230
235
|
console.log(c('hint', ' 使用方向键选择,Enter 确认'));
|
|
231
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
|
+
}
|
|
232
246
|
};
|
|
233
247
|
|
|
234
248
|
draw();
|
|
@@ -492,6 +506,29 @@ async function showChat() {
|
|
|
492
506
|
continue;
|
|
493
507
|
}
|
|
494
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
|
+
|
|
495
532
|
messages.push({ role: 'user', text: input });
|
|
496
533
|
drawMessages();
|
|
497
534
|
|
|
@@ -1091,6 +1128,9 @@ async function main() {
|
|
|
1091
1128
|
|
|
1092
1129
|
await showWelcome();
|
|
1093
1130
|
|
|
1131
|
+
// 后台检查版本更新
|
|
1132
|
+
checkVersion();
|
|
1133
|
+
|
|
1094
1134
|
while (true) {
|
|
1095
1135
|
const choice = await showMenu();
|
|
1096
1136
|
|