driftnet 0.11.0 → 1.0.0
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/README.md +8 -4
- package/README.zh-TW.md +8 -4
- package/dist/driftnet.mjs +1268 -524
- package/package.json +1 -1
- package/public/index.html +135 -15
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "driftnet",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"mcpName": "io.github.KevinChu1110/driftnet",
|
|
5
5
|
"description": "Drop links into any chat; get them sorted, explained and searchable, for you and your agents. Any model, or none.",
|
|
6
6
|
"license": "MIT",
|
package/public/index.html
CHANGED
|
@@ -310,7 +310,13 @@
|
|
|
310
310
|
.tabs button[aria-selected="true"] { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
|
|
311
311
|
#st-body section[data-tab] { display: none; }
|
|
312
312
|
#st-body[data-tab="general"] section[data-tab="general"], #st-body[data-tab="access"] section[data-tab="access"],
|
|
313
|
-
#st-body[data-tab="ai"] section[data-tab="ai"] { display: block; }
|
|
313
|
+
#st-body[data-tab="ai"] section[data-tab="ai"], #st-body[data-tab="chats"] section[data-tab="chats"] { display: block; }
|
|
314
|
+
.chat-st { font-size: 13px; margin: 0 0 8px; display: flex; gap: 8px; align-items: baseline; overflow-wrap: anywhere; }
|
|
315
|
+
.chat-st::before { content: ""; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); transform: translateY(-1px); }
|
|
316
|
+
.chat-st[data-state="connected"]::before, .chat-st[data-state="webhook"]::before { background: var(--ok); }
|
|
317
|
+
.chat-st[data-state="error"] { color: var(--danger); } .chat-st[data-state="error"]::before { background: var(--danger); }
|
|
318
|
+
.chat-st[data-state="starting"]::before { background: var(--accent); }
|
|
319
|
+
.chat-help { display: block; color: var(--muted); margin: 0 0 8px; } .chat-help a { color: var(--accent); }
|
|
314
320
|
.set-row { overflow-wrap: anywhere; }
|
|
315
321
|
#st-body:not(.show-env) .envname { display: none; }
|
|
316
322
|
.tabs { background: var(--bg); box-shadow: 0 -8px 0 var(--panel); margin-bottom: 16px; }
|
|
@@ -380,6 +386,8 @@
|
|
|
380
386
|
.crumb b { color: var(--accent); font-weight: 600; }
|
|
381
387
|
main { padding: 16px 20px 48px; display: grid; gap: 12px; align-content: start; }
|
|
382
388
|
.hint { color: var(--muted); font-size: 13px; margin: -4px 2px 0; }
|
|
389
|
+
.hint.corrected button { all: unset; color: var(--accent); text-decoration: underline; cursor: pointer; }
|
|
390
|
+
.hint.corrected button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
|
|
383
391
|
|
|
384
392
|
/* A card sits on top of two action strips that show while it is dragged. */
|
|
385
393
|
.swipe { content-visibility: auto; contain-intrinsic-size: auto 150px; position: relative; border-radius: 12px; overflow: hidden; scroll-margin-top: 90px; transition: height .25s ease, margin .25s ease, opacity .25s ease; }
|
|
@@ -757,6 +765,7 @@
|
|
|
757
765
|
stats: (n, s) => `${n} ${n === 1 ? "item" : "items"} · shared ${s}×`, shared: (n) => `shared ${n}×`,
|
|
758
766
|
empty: "Nothing here yet.", emptyStart: "Nothing here yet. Paste a link below to start — or save one with the Chrome extension, or run npx driftnet add <link>.",
|
|
759
767
|
noMatch: (q, v) => `No cards match “${q}” in ${v}.`, searchAll: "Search everything", searchIn: (v) => `Search ${v}…`,
|
|
768
|
+
showingFor: (c) => `Showing results for “${c}”`, searchInstead: (q) => `search for “${q}” instead`,
|
|
760
769
|
addTitle: "Add a link", addHelp: "A link to a tool, post or video (example.com works too)", addThis: (u) => `Add this link: ${u}`, kAdd: "Add a link",
|
|
761
770
|
addedAlready: "Already saved — here it is", addNothing: "No link found in that.", noSuggestion: "No suggestion for this card — press m to pick a folder", emptyFav: "No favorites yet — swipe a card right, or tap the star.",
|
|
762
771
|
pageMore: (n) => `Show more (${n} left)`, emptyTrash: "The trash is empty.", hint: "Swipe right to favorite, left to remove.", hintTrash: "Swipe right to restore.",
|
|
@@ -835,7 +844,17 @@
|
|
|
835
844
|
status: (e) => `Now: sorting by ${({ jev: "Jev", llm: "the model", heuristic: "built-in rules" })[e.judge] ?? e.judge}, summaries: ${e.summarizer === "off" ? "off" : e.summarizer}`, keep: "set — leave empty to keep", unset: "not set",
|
|
836
845
|
locked: "set by the environment driftnet runs in", forbidden: "Server settings can only be changed on the computer running driftnet (or set DRIFTNET_TOKEN). Display settings still work.",
|
|
837
846
|
savedServer: "Saved — already in effect", chat: "Chat replies", webhook: "Outgoing webhook", digest: "Scheduled digest", feed: "Feed (RSS)", genCopied: "New password generated and copied — press Save to keep it",
|
|
838
|
-
tabGeneral: "General", tabAccess: "Access", tabAi: "AI",
|
|
847
|
+
tabGeneral: "General", tabAccess: "Access", tabAi: "AI", tabChats: "Chats",
|
|
848
|
+
chatsIntro: "Paste a bot's token and press Save: driftnet connects right away, no restart. Then send the bot a link.",
|
|
849
|
+
chatsAdvanced: "Advanced", chatsAdvancedHelp: "Limit the bots to some chats or channels, and Slack without Socket Mode (needs a public URL).",
|
|
850
|
+
chatState: { off: "Not connected — paste a token below", starting: "Connecting…", connected: (n) => n ? `Connected as ${n}` : "Connected",
|
|
851
|
+
webhook: (url) => `Ready — messages arrive at ${url}`, error: (e) => `Problem: ${e}`, needs: (f) => `Also needs: ${f}`, publicUrl: "your public URL" },
|
|
852
|
+
chatHelp: {
|
|
853
|
+
telegram: ["In Telegram, open @BotFather, send /newbot and paste the token it gives you. For groups, also send /setprivacy → Disable so the bot sees links.", [["https://t.me/BotFather", "Open @BotFather"]]],
|
|
854
|
+
discord: ["In the Discord Developer Portal, create an application, open Bot, press Reset Token and turn on Message Content Intent on the same page. Invite it with OAuth2 → URL Generator → bot.", [["https://discord.com/developers/applications", "Discord Developer Portal"]]],
|
|
855
|
+
slack: ["Create an app at api.slack.com, turn on Socket Mode (that makes the xapp- token), add the bot scopes channels:history, groups:history, chat:write and the message events, then install it and copy the xoxb- Bot User OAuth Token.", [["https://api.slack.com/apps", "Slack apps"]]],
|
|
856
|
+
line: ["In LINE Developers, create a Messaging API channel: the Channel secret is under Basic settings, the access token under Messaging API. LINE has to reach driftnet from the internet, so it needs a public URL; set the webhook to that URL + /webhooks/line.", [["https://developers.line.biz/console/", "LINE Developers"], ["https://github.com/KevinChu1110/driftnet/blob/main/docs/online.md", "Putting it online"]]],
|
|
857
|
+
},
|
|
839
858
|
updates: "Updates", bkTitle: "Backup", bkHelp: "One zip with your whole catalogue (cards, folders, notes, tokens) and your settings. Passwords and keys are left out unless you tick the box.",
|
|
840
859
|
bkDownload: "Download backup", bkSecrets: "Include passwords and keys (enter the admin password again)", bkPassword: "Admin password",
|
|
841
860
|
bkRestoreFile: "Restore from a backup file", bkRestoreHelp: "The backup is checked first. Nothing changes until you restart driftnet; your current data is kept next to it as a before-restore copy.",
|
|
@@ -931,6 +950,15 @@
|
|
|
931
950
|
DRIFTNET_WHISPER: ["whisper path", "Only if whisper or whisper-cli (speech) is not on PATH."],
|
|
932
951
|
DRIFTNET_VIDEO_FRAMES: ["Show frames to the model", "Off by default. When on, and a reel or short is still thin after the local tools, up to 8 distinct frames are attached to the same summary request, so they go to the model you configured and nowhere else. The model must accept pictures (Ollama: a vision model)."],
|
|
933
952
|
DRIFTNET_WEBHOOK_ALLOW_LOCAL: ["Allow a local webhook", "Needed when the receiver is on your own network (n8n on a LAN). Only that exact address is allowed."],
|
|
953
|
+
TELEGRAM_BOT_TOKEN: ["Bot token", "Looks like 123456789:AA…"],
|
|
954
|
+
DRIFTNET_TELEGRAM_CHATS: ["Telegram: only these chats", "Comma-separated chat ids. Empty: anyone who finds the bot. The log prints the id of each new chat."],
|
|
955
|
+
DISCORD_BOT_TOKEN: ["Bot token", "From Bot → Reset Token (not the client secret)."],
|
|
956
|
+
DISCORD_CHANNELS: ["Discord: only these channels", "Comma-separated channel ids (right-click a channel → Copy Channel ID). Empty: every channel the bot can read."],
|
|
957
|
+
SLACK_APP_TOKEN: ["App-level token", "Starts with xapp- (Basic Information → App-Level Tokens, scope connections:write)."],
|
|
958
|
+
SLACK_BOT_TOKEN: ["Bot token", "Starts with xoxb- (OAuth & Permissions)."],
|
|
959
|
+
SLACK_SIGNING_SECRET: ["Slack signing secret", "Only for Slack without Socket Mode: events go to your public URL + /webhooks/slack."],
|
|
960
|
+
LINE_CHANNEL_SECRET: ["Channel secret", "32 letters and digits, under Basic settings."],
|
|
961
|
+
LINE_CHANNEL_ACCESS_TOKEN: ["Channel access token", "Messaging API → Channel access token (long-lived) → Issue."],
|
|
934
962
|
},
|
|
935
963
|
choices: {
|
|
936
964
|
DRIFTNET_LLM_PROVIDER: { "": "None", anthropic: "Anthropic (API key)", openai: "OpenAI-compatible (OpenAI, Grok, Ollama…)", gemini: "Google Gemini (API key)", bedrock: "Amazon Bedrock", vertex: "Google Vertex AI", "claude-cli": "Claude subscription (Claude Code CLI)", "gemini-cli": "Google account (Gemini CLI)" },
|
|
@@ -958,6 +986,7 @@
|
|
|
958
986
|
stats: (n, s) => `${n} 則 · 分享 ${s} 次`, shared: (n) => `分享 ${n} 次`,
|
|
959
987
|
empty: "這裡還沒有內容。", emptyStart: "還沒有內容。在下面貼一個連結開始,或用 Chrome 擴充功能收錄,也可以執行 npx driftnet add <連結>。",
|
|
960
988
|
noMatch: (q, v) => `「${v}」裡沒有符合「${q}」的卡片。`, searchAll: "搜尋全部", searchIn: (v) => `在「${v}」裡搜尋…`,
|
|
989
|
+
showingFor: (c) => `顯示「${c}」的搜尋結果`, searchInstead: (q) => `改搜尋「${q}」`,
|
|
961
990
|
addTitle: "收錄連結", addHelp: "工具、貼文或影片的連結(只打 example.com 也可以)", addThis: (u) => `收錄這個連結:${u}`, kAdd: "收錄連結",
|
|
962
991
|
addedAlready: "已經收過了,就是這張", addNothing: "裡面找不到連結。", noSuggestion: "這張卡片沒有建議的資料夾,按 m 自己選", emptyFav: "還沒有最愛,把卡片往右滑或按星號。",
|
|
963
992
|
pageMore: (n) => `再顯示 ${n} 張`, emptyTrash: "垃圾桶是空的。", hint: "往右滑加入最愛,往左滑移到垃圾桶。", hintTrash: "往右滑還原。",
|
|
@@ -1035,7 +1064,17 @@
|
|
|
1035
1064
|
status: (e) => `目前:分類用 ${({ jev: "Jev", llm: "模型", heuristic: "內建規則" })[e.judge] ?? e.judge},摘要用 ${e.summarizer === "off" ? "(未開啟)" : e.summarizer}`, keep: "已設定,留空就不變", unset: "未設定",
|
|
1036
1065
|
locked: "由執行環境設定", forbidden: "伺服器設定只能在執行 driftnet 的那台電腦上改(或設定 DRIFTNET_TOKEN)。顯示設定照常可用。",
|
|
1037
1066
|
savedServer: "已儲存,馬上生效", chat: "聊天室回覆", webhook: "對外 Webhook", digest: "定時摘要", feed: "訂閱源(RSS)", genCopied: "已產生新密碼並複製,按「儲存」才會生效",
|
|
1038
|
-
tabGeneral: "一般", tabAccess: "存取", tabAi: "AI",
|
|
1067
|
+
tabGeneral: "一般", tabAccess: "存取", tabAi: "AI", tabChats: "聊天室",
|
|
1068
|
+
chatsIntro: "貼上機器人的權杖,按「儲存」就會馬上連線,不用重新啟動。接著傳一個連結給機器人試試。",
|
|
1069
|
+
chatsAdvanced: "進階", chatsAdvancedHelp: "只讓機器人在某些聊天室或頻道運作,以及不用 Socket Mode 的 Slack(需要公開網址)。",
|
|
1070
|
+
chatState: { off: "尚未連線,請在下面貼上權杖", starting: "連線中…", connected: (n) => n ? `已連線:${n}` : "已連線",
|
|
1071
|
+
webhook: (url) => `已就緒,訊息會送到 ${url}`, error: (e) => `有問題:${e}`, needs: (f) => `還需要填:${f}`, publicUrl: "你的公開網址" },
|
|
1072
|
+
chatHelp: {
|
|
1073
|
+
telegram: ["在 Telegram 找 @BotFather,傳 /newbot,把它給你的權杖貼到這裡。要在群組用的話,再傳 /setprivacy → Disable,機器人才看得到連結。", [["https://t.me/BotFather", "開啟 @BotFather"]]],
|
|
1074
|
+
discord: ["在 Discord Developer Portal 建立應用程式,進 Bot 頁按 Reset Token,並在同一頁打開 Message Content Intent。再用 OAuth2 → URL Generator → bot 邀請它進伺服器。", [["https://discord.com/developers/applications", "Discord Developer Portal"]]],
|
|
1075
|
+
slack: ["在 api.slack.com 建立 app,打開 Socket Mode(會產生 xapp- 開頭的權杖),加上 bot 權限 channels:history、groups:history、chat:write 和 message 事件,安裝後複製 xoxb- 開頭的 Bot User OAuth Token。", [["https://api.slack.com/apps", "Slack apps"]]],
|
|
1076
|
+
line: ["在 LINE Developers 建立 Messaging API channel:Channel secret 在 Basic settings,存取權杖在 Messaging API 頁。LINE 要從網路連到 driftnet,所以需要公開網址;把 webhook 設成該網址加上 /webhooks/line。", [["https://developers.line.biz/console/", "LINE Developers"], ["https://github.com/KevinChu1110/driftnet/blob/main/docs/zh-TW/online.md", "放上網路"]]],
|
|
1077
|
+
},
|
|
1039
1078
|
updates: "更新", bkTitle: "備份", bkHelp: "一個 zip 檔,包含整個收藏(卡片、資料夾、筆記、權杖)和設定。除非勾選,否則不會包含密碼和金鑰。",
|
|
1040
1079
|
bkDownload: "下載備份", bkSecrets: "包含密碼和金鑰(需要再輸入一次管理員密碼)", bkPassword: "管理員密碼",
|
|
1041
1080
|
bkRestoreFile: "從備份檔還原", bkRestoreHelp: "會先檢查備份檔。重新啟動 driftnet 之前不會有任何改變;目前的資料會留在旁邊,檔名帶有 before-restore。",
|
|
@@ -1131,6 +1170,15 @@
|
|
|
1131
1170
|
DRIFTNET_WHISPER: ["whisper 路徑", "只有 whisper 或 whisper-cli(語音轉文字)不在 PATH 時才需要。"],
|
|
1132
1171
|
DRIFTNET_VIDEO_FRAMES: ["把畫面交給模型看", "預設關閉。開啟後,reel 或 short 在本機工具讀完後仍然太少時,最多 8 張不重複的畫面會附在同一次摘要請求裡,只送給你設定的模型。模型必須看得懂圖片(Ollama:要用視覺模型)。"],
|
|
1133
1172
|
DRIFTNET_WEBHOOK_ALLOW_LOCAL: ["允許本機 Webhook", "接收端在你自己的區域網路時需要(例如內網的 n8n)。只放行你填的那個位址。"],
|
|
1173
|
+
TELEGRAM_BOT_TOKEN: ["機器人權杖", "長得像 123456789:AA…"],
|
|
1174
|
+
DRIFTNET_TELEGRAM_CHATS: ["Telegram:只限這些聊天室", "以逗號分隔的聊天室 ID。留空:任何找到機器人的人都能用。記錄檔會印出每個新聊天室的 ID。"],
|
|
1175
|
+
DISCORD_BOT_TOKEN: ["機器人權杖", "在 Bot → Reset Token 取得(不是 client secret)。"],
|
|
1176
|
+
DISCORD_CHANNELS: ["Discord:只限這些頻道", "以逗號分隔的頻道 ID(在頻道上按右鍵 → 複製頻道 ID)。留空:機器人看得到的所有頻道。"],
|
|
1177
|
+
SLACK_APP_TOKEN: ["App-level 權杖", "xapp- 開頭(Basic Information → App-Level Tokens,權限 connections:write)。"],
|
|
1178
|
+
SLACK_BOT_TOKEN: ["機器人權杖", "xoxb- 開頭(OAuth & Permissions 頁)。"],
|
|
1179
|
+
SLACK_SIGNING_SECRET: ["Slack 簽章密鑰", "只有不用 Socket Mode 時才需要:事件會送到你的公開網址 + /webhooks/slack。"],
|
|
1180
|
+
LINE_CHANNEL_SECRET: ["Channel secret", "32 個英數字,在 Basic settings 頁。"],
|
|
1181
|
+
LINE_CHANNEL_ACCESS_TOKEN: ["Channel access token", "Messaging API → Channel access token (long-lived) → Issue。"],
|
|
1134
1182
|
},
|
|
1135
1183
|
choices: {
|
|
1136
1184
|
DRIFTNET_LLM_PROVIDER: { "": "不使用", anthropic: "Anthropic(API 金鑰)", openai: "OpenAI 相容(OpenAI、Grok、Ollama…)", gemini: "Google Gemini(API 金鑰)", bedrock: "Amazon Bedrock", vertex: "Google Vertex AI", "claude-cli": "Claude 訂閱(Claude Code CLI)", "gemini-cli": "Google 帳號(Gemini CLI)" },
|
|
@@ -1236,7 +1284,11 @@
|
|
|
1236
1284
|
}
|
|
1237
1285
|
if (res.status === 401) throw Object.assign(new Error("unauthorized"), { unauthorized: true });
|
|
1238
1286
|
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
1239
|
-
if (meta)
|
|
1287
|
+
if (meta) {
|
|
1288
|
+
meta.total = Number(res.headers.get("x-total-count"));
|
|
1289
|
+
// A search that matched nothing as typed was run with its misspelt words corrected.
|
|
1290
|
+
try { meta.corrected = decodeURIComponent(res.headers.get("x-search-corrected") ?? ""); } catch { meta.corrected = ""; }
|
|
1291
|
+
}
|
|
1240
1292
|
return res.json();
|
|
1241
1293
|
}
|
|
1242
1294
|
|
|
@@ -1840,30 +1892,86 @@
|
|
|
1840
1892
|
const yes = (b) => (b ? "✓" : "—");
|
|
1841
1893
|
const accessStatus = `<p class="set-status">${esc(st.accessStatus(yes(a.passwordSet), yes(a.readKey), a.tunnel.running ? a.tunnel.url : "—"))}</p>`;
|
|
1842
1894
|
server = {
|
|
1843
|
-
general: group("language") + group("
|
|
1895
|
+
general: group("language") + group("digest") + group("webhook") + group("updates") + importPanel() + backupPanel(serverSettings),
|
|
1844
1896
|
access: accessStatus + accessPanel(serverSettings, field) + (agentTokens ? tokensPanel(serverSettings.access, agentTokens, minted) + pairPanel(serverSettings.access) : ""),
|
|
1845
1897
|
ai: `<p class="set-status" id="st-status">${esc(st.status(serverSettings.engines))}</p>` + aiPanel(serverSettings, field) +
|
|
1846
1898
|
`<fieldset class="set-group"><legend>${esc(st.plugins)}</legend><div class="set-row">${plugins}</div></fieldset>`,
|
|
1899
|
+
chats: chatsPanel(serverSettings, field) + group("chat"),
|
|
1847
1900
|
};
|
|
1848
1901
|
}
|
|
1849
|
-
//
|
|
1902
|
+
// Tabs instead of one long scroll: what you see, who gets in, which AI, which chats.
|
|
1850
1903
|
const tab = want ?? (welcome ? "ai" : store.get("driftnet-settings-tab") || "general");
|
|
1851
|
-
const tabs = [["general", st.tabGeneral], ["access", st.tabAccess], ["ai", st.tabAi]];
|
|
1904
|
+
const tabs = [["general", st.tabGeneral], ["access", st.tabAccess], ["ai", st.tabAi], ["chats", st.tabChats]];
|
|
1852
1905
|
const section = (k, html) => `<section data-tab="${k}" role="tabpanel" id="panel-${k}" aria-labelledby="tab-${k}">${html}</section>`;
|
|
1853
1906
|
$("st-title").textContent = st.title;
|
|
1854
1907
|
$("st-error").textContent = "";
|
|
1855
1908
|
$("st-body").innerHTML = (welcome ? `<p class="welcome">${esc(st.welcome)}</p>` : "") +
|
|
1856
1909
|
`<div class="tabs" role="tablist">${tabs.map(([k, l]) => `<button type="button" role="tab" id="tab-${k}" aria-controls="panel-${k}" tabindex="${k === tab ? 0 : -1}" data-tab-btn="${k}" aria-selected="${k === tab}">${esc(l)}</button>`).join("")}</div>` +
|
|
1857
1910
|
(typeof server === "string"
|
|
1858
|
-
? section("general", local) + section("access", server) + section("ai", server)
|
|
1859
|
-
: section("general", local + server.general) + section("access", server.access) + section("ai", server.ai));
|
|
1911
|
+
? section("general", local) + section("access", server) + section("ai", server) + section("chats", server)
|
|
1912
|
+
: section("general", local + server.general) + section("access", server.access) + section("ai", server.ai) + section("chats", server.chats));
|
|
1860
1913
|
$("st-body").dataset.tab = tab;
|
|
1861
1914
|
placeAi();
|
|
1862
1915
|
$("st-cancel").textContent = t.cancel;
|
|
1863
1916
|
$("st-save").textContent = st.save;
|
|
1864
|
-
|
|
1865
|
-
|
|
1917
|
+
// Re-drawn while open (after saving a chat token): keep who opened it.
|
|
1918
|
+
if (!$("settings-dlg").open) {
|
|
1919
|
+
settingsOpener = isDrawer() ? $("menu") : document.activeElement;
|
|
1920
|
+
$("settings-dlg").showModal();
|
|
1921
|
+
}
|
|
1866
1922
|
$("st-body").querySelector('[data-tab-btn][aria-selected="true"]')?.focus();
|
|
1923
|
+
pollChats();
|
|
1924
|
+
}
|
|
1925
|
+
/** Settings › Chats: one section per platform with its status, where to get the token, and its fields. */
|
|
1926
|
+
const CHAT_FIELDS = { telegram: ["TELEGRAM_BOT_TOKEN"], discord: ["DISCORD_BOT_TOKEN"], slack: ["SLACK_APP_TOKEN", "SLACK_BOT_TOKEN"],
|
|
1927
|
+
line: ["LINE_CHANNEL_SECRET", "LINE_CHANNEL_ACCESS_TOKEN"] };
|
|
1928
|
+
const CHAT_ADVANCED = ["DRIFTNET_TELEGRAM_CHATS", "DISCORD_CHANNELS", "SLACK_SIGNING_SECRET"];
|
|
1929
|
+
const CHAT_NAMES = { telegram: "Telegram", discord: "Discord", slack: "Slack", line: "LINE" };
|
|
1930
|
+
function chatStatusText(p, c) {
|
|
1931
|
+
const cs = T().st.chatState;
|
|
1932
|
+
if (!c) return "";
|
|
1933
|
+
if (c.state === "connected") return cs.connected(c.name);
|
|
1934
|
+
// A half-filled platform: name the missing field the way the form does.
|
|
1935
|
+
const needs = /^also needs (.+)$/.exec(c.error ?? "");
|
|
1936
|
+
if (c.state === "error" && needs) return cs.needs(needs[1].split(" and ").map((k) => T().st.labels[k]?.[0] ?? k).join(", "));
|
|
1937
|
+
if (c.state === "error") return cs.error(c.error ?? "");
|
|
1938
|
+
if (c.state === "webhook") return cs.webhook(`${(serverSettings?.access?.publicUrl ?? cs.publicUrl).replace(/\/$/, "")}/webhooks/${p}`);
|
|
1939
|
+
return cs[c.state] ?? "";
|
|
1940
|
+
}
|
|
1941
|
+
function chatsPanel(sv, field) {
|
|
1942
|
+
const st = T().st, byKey = (k) => sv.settings.find((x) => x.key === k);
|
|
1943
|
+
const rows = (keys) => keys.map(byKey).filter(Boolean).map(field).join("");
|
|
1944
|
+
const sections = Object.entries(CHAT_FIELDS).map(([p, keys]) => {
|
|
1945
|
+
const [help, links] = st.chatHelp[p];
|
|
1946
|
+
const c = sv.chats?.[p];
|
|
1947
|
+
const status = c ? `<p class="chat-st" data-chat-status="${p}" data-state="${esc(c.state)}" role="status">${esc(chatStatusText(p, c))}</p>` : "";
|
|
1948
|
+
return `<fieldset class="set-group" id="chat-${p}"><legend>${esc(CHAT_NAMES[p])}</legend>${status}
|
|
1949
|
+
<small class="chat-help">${esc(help)} ${links.map(([u, l]) => `<a href="${esc(u)}" target="_blank" rel="noopener noreferrer">${esc(l)}</a>`).join(" · ")}</small>${rows(keys)}</fieldset>`;
|
|
1950
|
+
}).join("");
|
|
1951
|
+
return `<p class="set-status">${esc(st.chatsIntro)}</p>` + sections +
|
|
1952
|
+
`<details class="set-adv"><summary>${esc(st.chatsAdvanced)}</summary><small>${esc(st.chatsAdvancedHelp)}</small>${rows(CHAT_ADVANCED)}</details>`;
|
|
1953
|
+
}
|
|
1954
|
+
/** While a bot is connecting, refresh the status lines (not the fields) every 2 s, for up to 30 s. */
|
|
1955
|
+
let chatPoll = null;
|
|
1956
|
+
function pollChats() {
|
|
1957
|
+
clearTimeout(chatPoll);
|
|
1958
|
+
let n = 0;
|
|
1959
|
+
const tick = async () => {
|
|
1960
|
+
const open = $("settings-dlg").open && serverSettings?.chats;
|
|
1961
|
+
if (!open || !Object.values(serverSettings.chats).some((c) => c.state === "starting") || ++n > 15) return;
|
|
1962
|
+
const token = store.get("driftnet-token");
|
|
1963
|
+
const r = await fetch("/api/settings", { headers: token ? { authorization: `Bearer ${token}` } : {} }).then((x) => x.ok ? x.json() : null).catch(() => null);
|
|
1964
|
+
if (r?.chats && serverSettings) {
|
|
1965
|
+
serverSettings.chats = r.chats;
|
|
1966
|
+
for (const el of $("st-body").querySelectorAll("[data-chat-status]")) {
|
|
1967
|
+
const c = r.chats[el.dataset.chatStatus];
|
|
1968
|
+
el.dataset.state = c.state;
|
|
1969
|
+
el.textContent = chatStatusText(el.dataset.chatStatus, c);
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1972
|
+
chatPoll = setTimeout(tick, 2000);
|
|
1973
|
+
};
|
|
1974
|
+
chatPoll = setTimeout(tick, 2000);
|
|
1867
1975
|
}
|
|
1868
1976
|
/** Settings › AI: the chosen provider's own fields sit under it; other providers', embeddings and tool paths fold into Advanced. */
|
|
1869
1977
|
const PROVIDER_FIELDS = { DRIFTNET_LLM_MODEL: "anthropic openai gemini bedrock vertex claude-cli gemini-cli", DRIFTNET_LLM_BASE_URL: "openai",
|
|
@@ -2231,9 +2339,9 @@
|
|
|
2231
2339
|
for (const el of body.querySelectorAll("[data-pref]")) prefs[el.dataset.pref] = el.type === "checkbox" ? el.checked : el.value;
|
|
2232
2340
|
store.set("driftnet-prefs", JSON.stringify(prefs));
|
|
2233
2341
|
applyPrefs();
|
|
2234
|
-
let serverSaved = false;
|
|
2342
|
+
let serverSaved = false, values = null;
|
|
2235
2343
|
if (serverSettings) {
|
|
2236
|
-
|
|
2344
|
+
values = {};
|
|
2237
2345
|
for (const el of body.querySelectorAll("[data-key]:not([disabled])")) {
|
|
2238
2346
|
const s = serverSettings.settings.find((x) => x.key === el.dataset.key);
|
|
2239
2347
|
if (s.secret ? el.value.trim() : el.value.trim() !== (s.value ?? "").trim()) values[s.key] = el.value.trim() === "" ? null : el.value;
|
|
@@ -2249,12 +2357,14 @@
|
|
|
2249
2357
|
if ("DRIFTNET_TOKEN" in values) values.DRIFTNET_TOKEN ? store.set("driftnet-token", values.DRIFTNET_TOKEN.trim()) : store.set("driftnet-token", "");
|
|
2250
2358
|
}
|
|
2251
2359
|
}
|
|
2252
|
-
return { serverSaved };
|
|
2360
|
+
return { serverSaved, chats: serverSaved && Object.keys(values ?? {}).some((k) => serverSettings.settings.find((x) => x.key === k)?.group === "chats") };
|
|
2253
2361
|
}
|
|
2254
2362
|
$("settings-form").onsubmit = async (e) => {
|
|
2255
2363
|
e.preventDefault();
|
|
2256
2364
|
const saved = await saveSettings();
|
|
2257
2365
|
if (!saved) return;
|
|
2366
|
+
// A chat token: stay on Chats and show whether it connects.
|
|
2367
|
+
if (saved.chats) { toast(T().st.savedServer); return openSettings(false, "chats"); }
|
|
2258
2368
|
$("settings-dlg").close();
|
|
2259
2369
|
toast(saved.serverSaved ? T().st.savedServer : T().saved);
|
|
2260
2370
|
load();
|
|
@@ -2281,6 +2391,9 @@
|
|
|
2281
2391
|
[/(\S+) did not resolve/, (m) => zh ? `沒有收錄:找不到 ${m[1]} 這個網站,請檢查網址。` : `Not saved: ${m[1]} couldn't be found — check the address.`],
|
|
2282
2392
|
[/links are not fetched|not a web link/, () => zh ? "沒有收錄:這不是網頁連結,要以 http:// 或 https:// 開頭。" : "Not saved: that isn't a web link — it needs to start with http:// or https://."],
|
|
2283
2393
|
[/(\S+) is blocked in your settings/, (m) => zh ? `沒有收錄:${m[1]} 在你的封鎖清單裡(設定 → AI →「不要收錄的網域」)。` : `Not saved: ${m[1]} is on your blocked list (Settings → AI → Never catalogue these domains).`],
|
|
2394
|
+
// A chat token of the wrong shape (Settings › Chats): name the field, and say what it should look like.
|
|
2395
|
+
[/^([A-Z_]+) doesn't look right: it (.+)/, (m) => { const l = T().st.labels[m[1]]?.[0] ?? m[1], hint = T().st.labels[m[1]]?.[1] ?? "";
|
|
2396
|
+
return zh ? `「${l}」看起來不對,請確認貼的是正確的值。${hint}` : `“${l}” doesn't look right: it ${m[2]}.`; }],
|
|
2284
2397
|
[/too many wrong passwords/, () => zh ? "密碼錯太多次,請 15 分鐘後再試。" : "Too many wrong passwords — try again in 15 minutes."],
|
|
2285
2398
|
];
|
|
2286
2399
|
for (const [re, f] of rules) { const m = re.exec(msg); if (m) return f(m); }
|
|
@@ -3590,12 +3703,15 @@
|
|
|
3590
3703
|
/** Cards fetched per page; the rest come as the reader reaches the end of the list. */
|
|
3591
3704
|
const PAGE = 60;
|
|
3592
3705
|
let pageTotal = 0, pageGen = 0, pageBusy = false, pageObserver = null, pageHost = null, keepPages = false;
|
|
3706
|
+
/** The query the reader asked to search exactly as typed (no spelling correction). */
|
|
3707
|
+
let exactQ = "";
|
|
3593
3708
|
const listParams = () => {
|
|
3594
3709
|
const p = new URLSearchParams();
|
|
3595
3710
|
if (prefs.sort !== "best") p.set("sort", prefs.sort);
|
|
3596
3711
|
if (state.view === "review") p.set("health", "dead,archived,stale");
|
|
3597
3712
|
else if (state.view !== "all") p.set("view", state.view);
|
|
3598
3713
|
for (const k of ["category", "kind", "q"]) if (state[k]) p.set(k, state[k]);
|
|
3714
|
+
if (state.q && state.q === exactQ) p.set("fuzzy", "0");
|
|
3599
3715
|
return p;
|
|
3600
3716
|
};
|
|
3601
3717
|
const moreHtml = () => items.length < pageTotal
|
|
@@ -3681,8 +3797,11 @@
|
|
|
3681
3797
|
const addQ = role === "admin" && state.q && linkLike(state.q) && (!items.length || /^(https?:\/\/|www\.)/i.test(state.q))
|
|
3682
3798
|
? `<div class="add-q"><button class="btn primary" type="button" data-add-q>${ic("plus")} ${esc(t.addThis(state.q))}</button></div>` : "";
|
|
3683
3799
|
const scoped = state.view !== "all" || state.category || state.kind;
|
|
3800
|
+
// Nothing matched the words as typed: say which spelling was searched, and offer the original.
|
|
3801
|
+
const fixed = items.length && state.q && meta.corrected
|
|
3802
|
+
? `<p class="hint corrected">${esc(t.showingFor(meta.corrected))} — <button type="button" data-search-exact>${esc(t.searchInstead(state.q))}</button></p>` : "";
|
|
3684
3803
|
$("list").innerHTML = items.length
|
|
3685
|
-
? addQ + (state.view === "trash" ? `<div class="trash-bar"><button class="btn danger" type="button" id="trash-empty">${ic("trash")} ${esc(t.emptyTrashBtn)}</button></div>` : "") + `<p class="hint swipe-hint">${esc(state.view === "trash" ? t.hintTrash : state.view === "inbox" ? t.hintInbox : state.view === "review" ? t.hintReview : t.hint)}</p>` + items.map(card).join("") + moreHtml()
|
|
3804
|
+
? fixed + addQ + (state.view === "trash" ? `<div class="trash-bar"><button class="btn danger" type="button" id="trash-empty">${ic("trash")} ${esc(t.emptyTrashBtn)}</button></div>` : "") + `<p class="hint swipe-hint">${esc(state.view === "trash" ? t.hintTrash : state.view === "inbox" ? t.hintInbox : state.view === "review" ? t.hintReview : t.hint)}</p>` + items.map(card).join("") + moreHtml()
|
|
3686
3805
|
: state.q
|
|
3687
3806
|
// Searching found nothing: say so (not "Inbox zero"), and offer the whole catalogue when only part of it was searched.
|
|
3688
3807
|
? `<div class="empty nomatch"><span>${esc(t.noMatch(state.q, viewName()))}</span>${scoped ? `<button class="btn" type="button" data-search-all>${esc(t.searchAll)}</button>` : ""}${addQ}</div>`
|
|
@@ -3692,6 +3811,7 @@
|
|
|
3692
3811
|
<button class="btn" type="button" data-connect-empty>${ic("plug")} ${esc(t.st.connect)}</button>${templateChooser(t)}` : ""}</div>`;
|
|
3693
3812
|
$("list").querySelector("[data-add-q]")?.addEventListener("click", (e) => { const b = e.currentTarget; b.disabled = true; addUrl(state.q).then(() => { if (b.isConnected) b.disabled = false; }); });
|
|
3694
3813
|
$("list").querySelector("[data-search-all]")?.addEventListener("click", () => { Object.assign(state, { view: "all", category: "", kind: "" }); load(); });
|
|
3814
|
+
$("list").querySelector("[data-search-exact]")?.addEventListener("click", () => { exactQ = state.q; render(); });
|
|
3695
3815
|
watchMore();
|
|
3696
3816
|
if (keep) scrollTo({ top: y });
|
|
3697
3817
|
$("add-form")?.addEventListener("submit", addLink);
|