支持LLM工作区配置化
This commit is contained in:
parent
adf7eee7f4
commit
e34711793e
@ -1,7 +1,7 @@
|
||||
{
|
||||
"manifest_version": 3,
|
||||
"name": "渠道应用开发部知识库",
|
||||
"version": "2.0.1",
|
||||
"version": "2.0.2",
|
||||
"description": "通过关键词快速搜索内部文档",
|
||||
"permissions": ["storage"],
|
||||
"host_permissions": [
|
||||
|
||||
@ -139,6 +139,11 @@
|
||||
<input id="llmTokenExpireHours" type="number" min="1" max="168" />
|
||||
<div class="desc">超出有效期将重新获取</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="llmWorkspaceName">对话的LLM工作区名称(默认值,不要动)</label>
|
||||
<input id="llmWorkspaceName" type="text"/>
|
||||
<div class="desc">固定值:部门知识库</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="section" id="endpointSection">
|
||||
|
||||
@ -5,4 +5,5 @@
|
||||
|------------|--------|---------|---------------------|
|
||||
| 2025.06.02 | V2.0.0 | Luke.Ye | 完成插件配置化改造 |
|
||||
| 2025.06.03 | V2.0.1 | Luke.Ye | 完成llm token过期时间的配置化 |
|
||||
| 2025.06.03 | V2.0.2 | Luke.Ye | 支持LLM工作区配置化 |
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
const defaultConfig = {
|
||||
tokenExpireHours: 24,
|
||||
llmTokenExpireHours: 24,
|
||||
llmWorkspaceName: "部门知识库",
|
||||
apiConfig: {
|
||||
materialPublicUrl: {
|
||||
name: "材料公开地址",
|
||||
@ -84,6 +85,8 @@ function loadMergedConfig() {
|
||||
res.customConfig.tokenExpireHours != null ? res.customConfig.tokenExpireHours : merged.tokenExpireHours;
|
||||
merged.llmTokenExpireHours =
|
||||
res.customConfig.llmTokenExpireHours != null ? res.customConfig.llmTokenExpireHours : merged.llmTokenExpireHours;
|
||||
merged.llmWorkspaceName =
|
||||
res.customConfig.llmWorkspaceName != null ? res.customConfig.llmWorkspaceName : merged.llmWorkspaceName;
|
||||
for (const key in merged.apiConfig) {
|
||||
const override = res.customConfig.apiConfig?.[key];
|
||||
if (override) {
|
||||
|
||||
@ -323,6 +323,7 @@ async function getLLMToken(forceRefresh = false) {
|
||||
async function getLLMWorkspaceSlug(token, forceRefresh = false) {
|
||||
const config = await loadMergedConfig();
|
||||
const wsCfg = config.apiConfig.workspaces;
|
||||
const llmWorkspaceName = config.llmWorkspaceName;
|
||||
const workspacesField = wsCfg.responseParams.find(p => p.field)?.field;
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
@ -342,10 +343,15 @@ async function getLLMWorkspaceSlug(token, forceRefresh = false) {
|
||||
|
||||
const data = await response.json();
|
||||
const list = data[workspacesField] || [];
|
||||
if (list.length > 0 && list[0].slug) {
|
||||
chrome.storage.local.set({ llmWorkspaceSlug: list[0].slug, llmWorkspaceAt: now });
|
||||
log("获取llmWorkspaceSlug: " + JSON.stringify(list))
|
||||
resolve(list[0].slug);
|
||||
|
||||
let target = list.find(ws => ws.name === llmWorkspaceName);
|
||||
// 若找不到,默认用第一个
|
||||
if (!target && list.length > 0) target = list[0];
|
||||
|
||||
if (target && target.slug) {
|
||||
chrome.storage.local.set({ llmWorkspaceSlug: target.slug, llmWorkspaceAt: now });
|
||||
log("获取llmWorkspaceSlug: " + JSON.stringify(target));
|
||||
resolve(target.slug);
|
||||
} else {
|
||||
reject("未获取到LLM工作区slug");
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ function getMergedConfig(callback) {
|
||||
function renderConfig(config) {
|
||||
document.getElementById("tokenExpireHours").value = config.tokenExpireHours;
|
||||
document.getElementById("llmTokenExpireHours").value = config.llmTokenExpireHours;
|
||||
document.getElementById("llmWorkspaceName").value = config.llmWorkspaceName;
|
||||
const container = document.getElementById("endpointSection");
|
||||
container.innerHTML = "";
|
||||
|
||||
@ -56,10 +57,17 @@ function renderConfig(config) {
|
||||
|
||||
function collectUserConfig() {
|
||||
let tokenExpireHours = parseInt(document.getElementById("tokenExpireHours").value);
|
||||
if (isNaN(tokenExpireHours) || tokenExpireHours > 168 || tokenExpireHours < 0) tokenExpireHours = 24;
|
||||
if (isNaN(tokenExpireHours) || tokenExpireHours > 168 || tokenExpireHours < 0) {
|
||||
tokenExpireHours = 24;
|
||||
}
|
||||
|
||||
let llmTokenExpireHours = parseInt(document.getElementById("llmTokenExpireHours").value);
|
||||
if (isNaN(llmTokenExpireHours) || llmTokenExpireHours > 168 || llmTokenExpireHours < 0) llmTokenExpireHours = 24;
|
||||
if (isNaN(llmTokenExpireHours) || llmTokenExpireHours > 168 || llmTokenExpireHours < 0) {
|
||||
llmTokenExpireHours = 24;
|
||||
}
|
||||
|
||||
let llmWorkspaceName = document.getElementById("llmWorkspaceName").value;
|
||||
llmWorkspaceName = llmWorkspaceName && llmWorkspaceName.trim() ? llmWorkspaceName.trim() : "部门知识库";
|
||||
|
||||
const apiConfig = {};
|
||||
|
||||
@ -82,7 +90,7 @@ function collectUserConfig() {
|
||||
}
|
||||
}
|
||||
|
||||
return { tokenExpireHours, llmTokenExpireHours, apiConfig };
|
||||
return { tokenExpireHours, llmTokenExpireHours, llmWorkspaceName, apiConfig };
|
||||
}
|
||||
|
||||
|
||||
@ -108,4 +116,8 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
const popupUrl = chrome.runtime.getURL("pages/popup.html");
|
||||
chrome.tabs.create({ url: popupUrl });
|
||||
});
|
||||
document.getElementById("llmWorkspaceName").addEventListener("change", function() {
|
||||
log("llmWorkspaceName有变化,清空缓存!")
|
||||
chrome.storage.local.remove(["llmWorkspaceSlug", "llmWorkspaceAt"]);
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user