Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b98ab79ae2 | |||
| 0d88d22509 |
81
www/app.js
81
www/app.js
@@ -150,6 +150,8 @@ async function loadBackendConfig() {
|
||||
CONFIG.apiKey = backendConfig.llm.api_key;
|
||||
CONFIG.model = backendConfig.llm.model;
|
||||
CONFIG.maxTokens = backendConfig.llm.max_tokens || 2048;
|
||||
CONFIG.enableThinking = backendConfig.llm.enable_thinking || 0;
|
||||
CONFIG.enableVision = backendConfig.llm.enable_vision || 0;
|
||||
}
|
||||
|
||||
updateAgentsDisplay();
|
||||
@@ -3234,10 +3236,12 @@ function showAgentChatPage() {
|
||||
<!-- 上传选项弹窗 -->
|
||||
<div class="attach-panel" id="attachPanel">
|
||||
<div class="attach-panel-content">
|
||||
${CONFIG.enableVision ? `
|
||||
<div class="attach-item" data-type="image">
|
||||
<div class="attach-icon">📷</div>
|
||||
<div class="attach-label">上传图片</div>
|
||||
</div>
|
||||
` : ''}
|
||||
<div class="attach-item" data-type="file">
|
||||
<div class="attach-icon">📄</div>
|
||||
<div class="attach-label">上传文件</div>
|
||||
@@ -3245,7 +3249,7 @@ function showAgentChatPage() {
|
||||
</div>
|
||||
</div>
|
||||
<input type="file" id="imageInput" accept="image/*" style="display:none">
|
||||
<input type="file" id="fileInput" accept=".txt,.md,.pdf,.doc,.docx,.json,.csv" style="display:none">
|
||||
<input type="file" id="fileInput" accept=".txt,.md,.json,.csv,.xml,.yaml,.yml,.log,.sql,.html,.css,.js,.py,.java,.c,.cpp,.go,.rs,.sh,.bash,.ini,.conf,.cfg" style="display:none">
|
||||
|
||||
<!-- 搜索栏 -->
|
||||
<div class="search-bar" id="searchBar">
|
||||
@@ -3763,10 +3767,12 @@ function openConversation(id) {
|
||||
<!-- 上传选项弹窗 -->
|
||||
<div class="attach-panel" id="attachPanel">
|
||||
<div class="attach-panel-content">
|
||||
${CONFIG.enableVision ? `
|
||||
<div class="attach-item" data-type="image">
|
||||
<div class="attach-icon">📷</div>
|
||||
<div class="attach-label">上传图片</div>
|
||||
</div>
|
||||
` : ''}
|
||||
<div class="attach-item" data-type="file">
|
||||
<div class="attach-icon">📄</div>
|
||||
<div class="attach-label">上传文件</div>
|
||||
@@ -3774,7 +3780,7 @@ function openConversation(id) {
|
||||
</div>
|
||||
</div>
|
||||
<input type="file" id="imageInput" accept="image/*" style="display:none">
|
||||
<input type="file" id="fileInput" accept=".txt,.md,.pdf,.doc,.docx,.json,.csv" style="display:none">
|
||||
<input type="file" id="fileInput" accept=".txt,.md,.json,.csv,.xml,.yaml,.yml,.log,.sql,.html,.css,.js,.py,.java,.c,.cpp,.go,.rs,.sh,.bash,.ini,.conf,.cfg" style="display:none">
|
||||
</div>
|
||||
`;
|
||||
|
||||
@@ -5293,35 +5299,58 @@ async function handleFileUpload(e) {
|
||||
const file = e.target.files[0];
|
||||
if (!file) return;
|
||||
|
||||
const reader = new FileReader();
|
||||
reader.onload = async (event) => {
|
||||
const content = event.target.result;
|
||||
const fileName = file.name;
|
||||
|
||||
// 添加用户消息
|
||||
currentConversation.messages.push({
|
||||
role: 'user',
|
||||
content: `[文件: ${fileName}]\\n\\n${content.slice(0, 500)}${content.length > 500 ? '...' : ''}`
|
||||
});
|
||||
|
||||
currentConversation.updatedAt = Date.now();
|
||||
saveConversations();
|
||||
renderMessages();
|
||||
|
||||
if (welcome) welcome.style.display = 'none';
|
||||
|
||||
// 调用AI生成
|
||||
await streamGenerateWithFile(content, fileName);
|
||||
};
|
||||
// 检查文件类型(只支持文本文件)
|
||||
const allowedExtensions = ['.txt', '.md', '.json', '.csv', '.xml', '.yaml', '.yml', '.log', '.sql', '.html', '.css', '.js', '.py', '.java', '.c', '.cpp', '.go', '.rs', '.sh', '.bash', '.ini', '.conf', '.cfg'];
|
||||
const fileName = file.name.toLowerCase();
|
||||
const isAllowed = allowedExtensions.some(ext => fileName.endsWith(ext));
|
||||
|
||||
// 根据文件类型读取
|
||||
if (file.name.endsWith('.pdf') || file.name.endsWith('.doc') || file.name.endsWith('.docx')) {
|
||||
// PDF/Word文件暂时只显示文件名
|
||||
showToast('PDF/Word文件暂不支持解析,请上传文本文件');
|
||||
if (!isAllowed) {
|
||||
showToast('只支持文本类型的文件(txt、md、json、代码文件等)');
|
||||
e.target.value = '';
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查文件大小(限制约 10KB,大约 10000 字符)
|
||||
const maxSizeKB = 15; // 留一点余量
|
||||
if (file.size > maxSizeKB * 1024) {
|
||||
showToast(`文件太大,请上传小于 ${maxSizeKB}KB 的文本文件`);
|
||||
e.target.value = '';
|
||||
return;
|
||||
}
|
||||
|
||||
showToast('正在读取文件...');
|
||||
|
||||
const reader = new FileReader();
|
||||
reader.onload = async (event) => {
|
||||
let content = event.target.result;
|
||||
|
||||
// 限制最多 10000 字符
|
||||
if (content.length > 10000) {
|
||||
content = content.slice(0, 10000);
|
||||
showToast(`文件内容已截取前 10000 字符`);
|
||||
}
|
||||
|
||||
// 把文件内容附加到输入框,让用户可以添加额外说明
|
||||
const currentText = userInput.value.trim();
|
||||
const filePrefix = `【文件:${file.name}】\n内容如下:\n`;
|
||||
|
||||
if (currentText) {
|
||||
userInput.value = `${currentText}\n\n${filePrefix}${content}`;
|
||||
} else {
|
||||
userInput.value = `${filePrefix}${content}`;
|
||||
}
|
||||
|
||||
// 自动调整输入框高度
|
||||
autoResize(userInput);
|
||||
userInput.focus();
|
||||
|
||||
showToast('文件内容已添加到输入框');
|
||||
};
|
||||
|
||||
reader.onerror = () => {
|
||||
showToast('文件读取失败');
|
||||
};
|
||||
|
||||
reader.readAsText(file);
|
||||
e.target.value = '';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user