driftnet 0.1.2 → 0.2.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/.env.example +5 -1
- package/README.md +25 -10
- package/README.zh-TW.md +21 -10
- package/dist/driftnet.mjs +197 -34
- package/package.json +1 -1
- package/public/index.html +177 -3
package/.env.example
CHANGED
|
@@ -62,8 +62,12 @@ DRIFTNET_HOST=
|
|
|
62
62
|
DRIFTNET_DB=
|
|
63
63
|
# Required for writes (ingest, feedback, MCP) when the server is reachable from the internet
|
|
64
64
|
DRIFTNET_TOKEN=
|
|
65
|
-
# public: anyone can read, writes need the token | private:
|
|
65
|
+
# public: anyone can read, writes need the token | private: reads need the token or the read key
|
|
66
66
|
DRIFTNET_ACCESS=public
|
|
67
|
+
# Read-only share key: reads only, also accepted as ?key= in URLs (⚙ Settings can generate one)
|
|
68
|
+
DRIFTNET_READ_KEY=
|
|
69
|
+
# Path to cloudflared, for the page's public-URL button
|
|
70
|
+
DRIFTNET_CLOUDFLARED=
|
|
67
71
|
# Token budget for the page outline sent to the judge and the model
|
|
68
72
|
DRIFTNET_DIGEST_TOKENS=350
|
|
69
73
|
# Public URL of this server; replies link to the item on the web page
|
package/README.md
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
[](https://github.com/KevinChu1110/driftnet/blob/main/LICENSE)
|
|
11
11
|
[](https://www.npmjs.com/package/driftnet)
|
|
12
|
+
[](https://github.com/KevinChu1110/driftnet/actions/workflows/ci.yml)
|
|
12
13
|
[](https://glama.ai/mcp/servers/KevinChu1110/driftnet)
|
|
13
14
|

|
|
14
15
|

|
|
@@ -317,8 +318,10 @@ set by the environment itself (systemd, Docker, your shell) wins and shows there
|
|
|
317
318
|
| `DRIFTNET_SUMMARY_RULES` | — | Your own instructions for every summary, e.g. “Say whether it is free.” Agents get them too |
|
|
318
319
|
| `DRIFTNET_BLOCK_DOMAINS` | — | Domains never catalogued (subdomains included), comma separated |
|
|
319
320
|
| `DRIFTNET_PLUGINS` | `~/.driftnet/plugins` | Folder of extractor plugins (`.js` / `.mjs`), see [`examples/plugins`](https://github.com/KevinChu1110/driftnet/blob/main/examples/plugins) |
|
|
320
|
-
| `DRIFTNET_TOKEN` | — |
|
|
321
|
-
| `
|
|
321
|
+
| `DRIFTNET_TOKEN` | — | Admin password: writes, settings, MCP with every tool, the agent queue. Settable on the page |
|
|
322
|
+
| `DRIFTNET_READ_KEY` | — | Read-only share key (header or `?key=`): reading and the read-only MCP tools |
|
|
323
|
+
| `DRIFTNET_ACCESS` | `public` | `public`: anyone can read. `private`: reads need the password or the share key |
|
|
324
|
+
| `DRIFTNET_CLOUDFLARED` | `cloudflared` | Path to `cloudflared`, for the page's public-URL button |
|
|
322
325
|
| `DRIFTNET_PUBLIC_URL` | — | Replies link to the item on the web page |
|
|
323
326
|
| `DRIFTNET_HOME` | `~/.driftnet` | Folder for `.env`, the database and the service log |
|
|
324
327
|
| `DRIFTNET_DB` | `~/.driftnet/driftnet.db` | SQLite file |
|
|
@@ -341,13 +344,27 @@ set by the environment itself (systemd, Docker, your shell) wins and shows there
|
|
|
341
344
|
|
|
342
345
|
## Putting it online (optional)
|
|
343
346
|
|
|
344
|
-
Only needed
|
|
345
|
-
|
|
347
|
+
Only needed when something outside this computer should reach it: your phone, LINE around the clock,
|
|
348
|
+
or AIs that run in the cloud (Claude.ai, ChatGPT, Grok, Hermes or OpenClaw on a server). The server
|
|
349
|
+
listens on `127.0.0.1`. Everything below is on the page under **⚙ Settings → Access & connections**:
|
|
346
350
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
+
1. **Admin password.** Pick your own or press *Generate*; a meter says how strong it is. It can only
|
|
352
|
+
be set from this computer. Anyone who knows it can add, move and delete, so don't reuse one.
|
|
353
|
+
2. **Who can read.** *Private* means the password or the share key is needed to read anything.
|
|
354
|
+
3. **Read-only share key.** For AIs that can only open links: `…/llms.txt?key=…` reads the catalogue
|
|
355
|
+
and nothing more. If it leaks, press *New key*. The admin password is never accepted in a URL.
|
|
356
|
+
4. **Public URL.** One button opens a temporary `https://….trycloudflare.com` address through
|
|
357
|
+
Cloudflare (no account; install [`cloudflared`](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/downloads/)
|
|
358
|
+
yourself, driftnet never downloads it). It needs the password, turns reading private, and closes
|
|
359
|
+
when driftnet stops.
|
|
360
|
+
|
|
361
|
+
Then **🔌 Connect an AI** in the sidebar has a ready-to-paste card for Claude Code, Claude.ai / Claude
|
|
362
|
+
Desktop (custom connector, read-only), ChatGPT custom GPTs, any chat that can open a link, and
|
|
363
|
+
Hermes / OpenClaw / pi, with the URL and the share key filled in.
|
|
364
|
+
|
|
365
|
+
<p align="center"><img src="https://raw.githubusercontent.com/KevinChu1110/driftnet/main/assets/access-connect-en.jpg" alt="Access & connections in Settings, and the Connect an AI cards" width="100%"></p>
|
|
366
|
+
|
|
367
|
+
For a permanent address, put HTTPS in front instead, e.g. Caddy:
|
|
351
368
|
|
|
352
369
|
```caddyfile
|
|
353
370
|
driftnet.example.com {
|
|
@@ -355,8 +372,6 @@ driftnet.example.com {
|
|
|
355
372
|
}
|
|
356
373
|
```
|
|
357
374
|
|
|
358
|
-
From a laptop, `cloudflared tunnel --url http://localhost:8787` gives a temporary public URL.
|
|
359
|
-
|
|
360
375
|
## Where your data goes
|
|
361
376
|
|
|
362
377
|
> [!IMPORTANT]
|
package/README.zh-TW.md
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
[](https://github.com/KevinChu1110/driftnet/blob/main/LICENSE)
|
|
11
11
|
[](https://www.npmjs.com/package/driftnet)
|
|
12
|
+
[](https://github.com/KevinChu1110/driftnet/actions/workflows/ci.yml)
|
|
12
13
|
[](https://glama.ai/mcp/servers/KevinChu1110/driftnet)
|
|
13
14
|

|
|
14
15
|

|
|
@@ -292,8 +293,10 @@ agent 寫回來的內容跟其他不可信的輸入一樣要檢查:格式、
|
|
|
292
293
|
| `DRIFTNET_SUMMARY_RULES` | — | 每次摘要都要遵守的自訂規則,例如「說明是否免費」;agent 也會收到 |
|
|
293
294
|
| `DRIFTNET_BLOCK_DOMAINS` | — | 永遠不收錄的網域(含子網域),用逗號分隔 |
|
|
294
295
|
| `DRIFTNET_PLUGINS` | `~/.driftnet/plugins` | 擷取器外掛(`.js`/`.mjs`)的資料夾,範例見 [`examples/plugins`](https://github.com/KevinChu1110/driftnet/blob/main/examples/plugins) |
|
|
295
|
-
| `DRIFTNET_TOKEN` | — |
|
|
296
|
-
| `
|
|
296
|
+
| `DRIFTNET_TOKEN` | — | 管理密碼:寫入、改設定、完整的 MCP 工具、agent 佇列。可以在網頁上設定 |
|
|
297
|
+
| `DRIFTNET_READ_KEY` | — | 唯讀分享碼(放 header 或 `?key=`):只能讀,MCP 也只有讀取類工具 |
|
|
298
|
+
| `DRIFTNET_ACCESS` | `public` | `public`:任何人都能讀。`private`:讀取要密碼或分享碼 |
|
|
299
|
+
| `DRIFTNET_CLOUDFLARED` | `cloudflared` | `cloudflared` 的路徑,給網頁上的「公開網址」按鈕用 |
|
|
297
300
|
| `DRIFTNET_PUBLIC_URL` | — | 回覆裡附上網頁連結 |
|
|
298
301
|
| `DRIFTNET_HOME` | `~/.driftnet` | 放 `.env`、資料庫和服務日誌的資料夾 |
|
|
299
302
|
| `DRIFTNET_DB` | `~/.driftnet/driftnet.db` | SQLite 檔案位置 |
|
|
@@ -316,13 +319,23 @@ agent 寫回來的內容跟其他不可信的輸入一樣要檢查:格式、
|
|
|
316
319
|
|
|
317
320
|
## 放上網路(選用)
|
|
318
321
|
|
|
319
|
-
|
|
320
|
-
|
|
322
|
+
只有當這台電腦以外的東西要連進來時才需要:你的手機、24 小時收 LINE,或是跑在雲端的 AI(Claude 網頁版、
|
|
323
|
+
ChatGPT、Grok、架在伺服器上的 Hermes 或 OpenClaw)。伺服器只聽 `127.0.0.1`。以下全部都在網頁的
|
|
324
|
+
**⚙ 設定 →「存取與連線」**:
|
|
321
325
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
+
1. **管理密碼。**自己取一組,或按「產生」;旁邊會顯示強弱。只能在這台電腦上設定。知道它的人可以新增、移動、刪除,所以不要沿用其他網站的密碼。
|
|
327
|
+
2. **誰可以讀。**選「要有密碼或分享碼才能讀」,沒有就什麼都看不到。
|
|
328
|
+
3. **唯讀分享碼。**給只會開連結的 AI:`…/llms.txt?key=…` 只能讀清單。外流就按「重新產生」。管理密碼永遠不能放在網址裡。
|
|
329
|
+
4. **公開網址。**按一下就透過 Cloudflare 開一個臨時的 `https://….trycloudflare.com`(免帳號;
|
|
330
|
+
[`cloudflared`](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/downloads/)
|
|
331
|
+
要自己裝,driftnet 不會幫你下載)。必須先設密碼,開啟後讀取會改成私人,driftnet 關掉就跟著關。
|
|
332
|
+
|
|
333
|
+
接著側邊欄的 **🔌 連接 AI** 會列出 Claude Code、Claude 網頁版/桌面版(自訂 connector,唯讀)、ChatGPT 自訂 GPT、
|
|
334
|
+
任何會開連結的聊天 AI,以及 Hermes/OpenClaw/pi 的設定,網址和分享碼都已經填好,複製貼上就能用。
|
|
335
|
+
|
|
336
|
+
<p align="center"><img src="https://raw.githubusercontent.com/KevinChu1110/driftnet/main/assets/access-connect-zh-TW.jpg" alt="設定裡的「存取與連線」,和「連接 AI」的卡片" width="100%"></p>
|
|
337
|
+
|
|
338
|
+
想要固定網址的話,改在前面加 HTTPS,例如 Caddy:
|
|
326
339
|
|
|
327
340
|
```caddyfile
|
|
328
341
|
driftnet.example.com {
|
|
@@ -330,8 +343,6 @@ driftnet.example.com {
|
|
|
330
343
|
}
|
|
331
344
|
```
|
|
332
345
|
|
|
333
|
-
在筆電上,`cloudflared tunnel --url http://localhost:8787` 可以拿到一個臨時的公開網址。
|
|
334
|
-
|
|
335
346
|
## 資料去哪裡
|
|
336
347
|
|
|
337
348
|
> [!IMPORTANT]
|
package/dist/driftnet.mjs
CHANGED
|
@@ -2267,7 +2267,7 @@ async function handleChatText(dn3, text, ctx) {
|
|
|
2267
2267
|
}
|
|
2268
2268
|
if (extractUrls(text).length === 0) return null;
|
|
2269
2269
|
const results = await dn3.pipeline.ingestMessage(text, ctx);
|
|
2270
|
-
const base = process.env.DRIFTNET_PUBLIC_URL;
|
|
2270
|
+
const base = process.env.DRIFTNET_TUNNEL_URL || process.env.DRIFTNET_PUBLIC_URL;
|
|
2271
2271
|
const mode = process.env.DRIFTNET_REPLY ?? "link";
|
|
2272
2272
|
if (mode === "off" || !results.length) return null;
|
|
2273
2273
|
const label = (folder) => dn3.folderLabel(folder, t.locale);
|
|
@@ -2384,8 +2384,8 @@ var init_slack = __esm({
|
|
|
2384
2384
|
});
|
|
2385
2385
|
|
|
2386
2386
|
// apps/server/src/adapters/telegram.ts
|
|
2387
|
-
function startTelegram(dn3,
|
|
2388
|
-
const api2 = (method, body) => fetch(`https://api.telegram.org/bot${
|
|
2387
|
+
function startTelegram(dn3, token2) {
|
|
2388
|
+
const api2 = (method, body) => fetch(`https://api.telegram.org/bot${token2}/${method}`, {
|
|
2389
2389
|
method: "POST",
|
|
2390
2390
|
headers: { "content-type": "application/json" },
|
|
2391
2391
|
body: JSON.stringify(body)
|
|
@@ -2470,7 +2470,7 @@ async function catchUp(dn3, fetchAfter) {
|
|
|
2470
2470
|
}
|
|
2471
2471
|
return handled;
|
|
2472
2472
|
}
|
|
2473
|
-
function startDiscord(dn3,
|
|
2473
|
+
function startDiscord(dn3, token2) {
|
|
2474
2474
|
const client = new Client({
|
|
2475
2475
|
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, GatewayIntentBits.DirectMessages]
|
|
2476
2476
|
});
|
|
@@ -2488,7 +2488,7 @@ function startDiscord(dn3, token) {
|
|
|
2488
2488
|
return [...(await channel.messages.fetch({ after, limit: 100 })).values()].map(toChatMessage);
|
|
2489
2489
|
});
|
|
2490
2490
|
});
|
|
2491
|
-
void client.login(
|
|
2491
|
+
void client.login(token2);
|
|
2492
2492
|
return () => void client.destroy();
|
|
2493
2493
|
}
|
|
2494
2494
|
var LAST, toChatMessage;
|
|
@@ -2511,8 +2511,15 @@ var init_discord = __esm({
|
|
|
2511
2511
|
// apps/server/src/mcp.ts
|
|
2512
2512
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2513
2513
|
import { z as z3 } from "zod";
|
|
2514
|
-
function createMcpServer(dn3, agentName = "agent") {
|
|
2515
|
-
const
|
|
2514
|
+
function createMcpServer(dn3, agentName = "agent", opts = {}) {
|
|
2515
|
+
const mcp = new McpServer({ name: "driftnet", version: "0.2.0" });
|
|
2516
|
+
const READ_TOOLS = /* @__PURE__ */ new Set(["driftnet_search", "driftnet_recent", "driftnet_get", "driftnet_folders"]);
|
|
2517
|
+
const server2 = {
|
|
2518
|
+
registerTool: ((name2, ...rest) => {
|
|
2519
|
+
if (opts.readOnly && !READ_TOOLS.has(name2)) return void 0;
|
|
2520
|
+
return mcp.registerTool(name2, ...rest);
|
|
2521
|
+
})
|
|
2522
|
+
};
|
|
2516
2523
|
const categories = Object.keys(dn3.categories);
|
|
2517
2524
|
const worthHelp = "Rating floor: skip < low < normal < must-see. Defaults to 'normal', which hides skipped and low-value items";
|
|
2518
2525
|
const categoryHelp = "A folder id from driftnet_folders; includes everything in its sub-folders. Omit for all folders";
|
|
@@ -2745,7 +2752,7 @@ ${JSON.stringify(rows, null, 1)}` }] };
|
|
|
2745
2752
|
}
|
|
2746
2753
|
}
|
|
2747
2754
|
);
|
|
2748
|
-
return
|
|
2755
|
+
return mcp;
|
|
2749
2756
|
}
|
|
2750
2757
|
function row(i) {
|
|
2751
2758
|
return {
|
|
@@ -2962,7 +2969,11 @@ var init_settings = __esm({
|
|
|
2962
2969
|
{ key: "DRIFTNET_REPLY", group: "chat", choices: ["", "link", "full", "off"] },
|
|
2963
2970
|
{ key: "DRIFTNET_PUBLIC_URL", group: "chat" },
|
|
2964
2971
|
{ key: "DRIFTNET_SUMMARY_RULES", group: "rules", multiline: true, max: 1e3 },
|
|
2965
|
-
{ key: "DRIFTNET_BLOCK_DOMAINS", group: "rules", max: 2e3 }
|
|
2972
|
+
{ key: "DRIFTNET_BLOCK_DOMAINS", group: "rules", max: 2e3 },
|
|
2973
|
+
// Access: the page shows these in their own panel (password strength, share key, public URL).
|
|
2974
|
+
{ key: "DRIFTNET_TOKEN", group: "access", secret: true, min: 8, max: 200 },
|
|
2975
|
+
{ key: "DRIFTNET_READ_KEY", group: "access", min: 16, max: 200 },
|
|
2976
|
+
{ key: "DRIFTNET_ACCESS", group: "access", choices: ["", "public", "private"] }
|
|
2966
2977
|
];
|
|
2967
2978
|
SettingsError = class extends Error {
|
|
2968
2979
|
};
|
|
@@ -3010,6 +3021,8 @@ var init_settings = __esm({
|
|
|
3010
3021
|
if (value !== null) {
|
|
3011
3022
|
if (s.choices && !s.choices.includes(value)) throw new SettingsError(`${key} must be one of ${s.choices.filter(Boolean).join(", ")}`);
|
|
3012
3023
|
if (value.length > (s.max ?? 500)) throw new SettingsError(`${key} is too long`);
|
|
3024
|
+
if (s.min && value.length < s.min) throw new SettingsError(`${key} needs at least ${s.min} characters`);
|
|
3025
|
+
if (s.key === "DRIFTNET_TOKEN" && /\s/.test(value)) throw new SettingsError("the password can't contain spaces");
|
|
3013
3026
|
if (value.includes("`")) throw new SettingsError(`${key} can't contain a backtick`);
|
|
3014
3027
|
if (!s.multiline && /[\r\n]/.test(value)) throw new SettingsError(`${key} must be one line`);
|
|
3015
3028
|
if (/URL$/.test(key) && !/^https?:\/\/\S+$/.test(value)) throw new SettingsError(`${key} must be an http(s) URL`);
|
|
@@ -3051,6 +3064,105 @@ var init_settings = __esm({
|
|
|
3051
3064
|
}
|
|
3052
3065
|
});
|
|
3053
3066
|
|
|
3067
|
+
// apps/server/src/access.ts
|
|
3068
|
+
import { spawn as spawn2, spawnSync } from "node:child_process";
|
|
3069
|
+
import { randomBytes, timingSafeEqual as timingSafeEqual3 } from "node:crypto";
|
|
3070
|
+
function same(given, want) {
|
|
3071
|
+
if (!given || !want) return false;
|
|
3072
|
+
const a = Buffer.from(given);
|
|
3073
|
+
const b = Buffer.from(want);
|
|
3074
|
+
return a.length === b.length && timingSafeEqual3(a, b);
|
|
3075
|
+
}
|
|
3076
|
+
function isAdmin(req, env2) {
|
|
3077
|
+
const t = token(env2);
|
|
3078
|
+
return !t || same(bearer(req), t);
|
|
3079
|
+
}
|
|
3080
|
+
function canRead(req, env2) {
|
|
3081
|
+
if (!isPrivate(env2) || isAdmin(req, env2)) return true;
|
|
3082
|
+
const k = readKey(env2);
|
|
3083
|
+
return same(bearer(req), k) || same(queryKey(req), k);
|
|
3084
|
+
}
|
|
3085
|
+
function isLocal(req) {
|
|
3086
|
+
const ip = req.socket.remoteAddress ?? "";
|
|
3087
|
+
const loopback = ip === "127.0.0.1" || ip === "::1" || ip === "::ffff:127.0.0.1";
|
|
3088
|
+
const host = /^(localhost|127\.0\.0\.1|\[::1\])(:\d+)?$/.test(req.headers.host ?? "");
|
|
3089
|
+
const forwarded = ["x-forwarded-for", "forwarded", "x-real-ip", "cf-connecting-ip", "cf-ray"].some((h) => req.headers[h] !== void 0);
|
|
3090
|
+
return loopback && host && !forwarded;
|
|
3091
|
+
}
|
|
3092
|
+
var token, readKey, isPrivate, bearer, queryKey, newKey, Tunnel;
|
|
3093
|
+
var init_access = __esm({
|
|
3094
|
+
"apps/server/src/access.ts"() {
|
|
3095
|
+
"use strict";
|
|
3096
|
+
token = (env2) => env2.DRIFTNET_TOKEN || void 0;
|
|
3097
|
+
readKey = (env2) => env2.DRIFTNET_READ_KEY || void 0;
|
|
3098
|
+
isPrivate = (env2) => env2.DRIFTNET_ACCESS === "private";
|
|
3099
|
+
bearer = (req) => (req.headers.authorization ?? "").replace(/^Bearer\s+/i, "").trim() || null;
|
|
3100
|
+
queryKey = (req) => new URL(req.url ?? "/", "http://x").searchParams.get("key");
|
|
3101
|
+
newKey = () => randomBytes(24).toString("base64url");
|
|
3102
|
+
Tunnel = class {
|
|
3103
|
+
constructor(port, bin = process.env.DRIFTNET_CLOUDFLARED || "cloudflared") {
|
|
3104
|
+
this.port = port;
|
|
3105
|
+
this.bin = bin;
|
|
3106
|
+
}
|
|
3107
|
+
port;
|
|
3108
|
+
bin;
|
|
3109
|
+
child = null;
|
|
3110
|
+
url = null;
|
|
3111
|
+
error = null;
|
|
3112
|
+
available() {
|
|
3113
|
+
try {
|
|
3114
|
+
return spawnSync(this.bin, ["--version"], { stdio: "ignore", timeout: 5e3 }).status === 0;
|
|
3115
|
+
} catch {
|
|
3116
|
+
return false;
|
|
3117
|
+
}
|
|
3118
|
+
}
|
|
3119
|
+
get running() {
|
|
3120
|
+
return this.child !== null;
|
|
3121
|
+
}
|
|
3122
|
+
start(timeoutMs = 3e4) {
|
|
3123
|
+
if (this.url && this.child) return Promise.resolve(this.url);
|
|
3124
|
+
this.error = null;
|
|
3125
|
+
return new Promise((resolve3, reject) => {
|
|
3126
|
+
const child = spawn2(this.bin, ["tunnel", "--no-autoupdate", "--url", `http://127.0.0.1:${this.port}`], { stdio: ["ignore", "pipe", "pipe"] });
|
|
3127
|
+
this.child = child;
|
|
3128
|
+
const timer = setTimeout(() => fail(new Error("cloudflared did not report a URL in time")), timeoutMs);
|
|
3129
|
+
const fail = (err) => {
|
|
3130
|
+
clearTimeout(timer);
|
|
3131
|
+
this.error = err.message;
|
|
3132
|
+
this.stop();
|
|
3133
|
+
reject(err);
|
|
3134
|
+
};
|
|
3135
|
+
const scan = (chunk) => {
|
|
3136
|
+
const m = /https:\/\/[a-z0-9-]+\.trycloudflare\.com/.exec(chunk.toString());
|
|
3137
|
+
if (m && !this.url) {
|
|
3138
|
+
clearTimeout(timer);
|
|
3139
|
+
this.url = m[0];
|
|
3140
|
+
resolve3(m[0]);
|
|
3141
|
+
}
|
|
3142
|
+
};
|
|
3143
|
+
child.stdout?.on("data", scan);
|
|
3144
|
+
child.stderr?.on("data", scan);
|
|
3145
|
+
child.on("error", (err) => fail(err));
|
|
3146
|
+
child.on("exit", (code) => {
|
|
3147
|
+
if (this.child === child) {
|
|
3148
|
+
this.child = null;
|
|
3149
|
+
this.url = null;
|
|
3150
|
+
if (code) this.error = `cloudflared exited with code ${code}`;
|
|
3151
|
+
}
|
|
3152
|
+
clearTimeout(timer);
|
|
3153
|
+
});
|
|
3154
|
+
});
|
|
3155
|
+
}
|
|
3156
|
+
stop() {
|
|
3157
|
+
const child = this.child;
|
|
3158
|
+
this.child = null;
|
|
3159
|
+
this.url = null;
|
|
3160
|
+
child?.kill();
|
|
3161
|
+
}
|
|
3162
|
+
};
|
|
3163
|
+
}
|
|
3164
|
+
});
|
|
3165
|
+
|
|
3054
3166
|
// apps/server/src/feeds.ts
|
|
3055
3167
|
function llmsTxt(dn3) {
|
|
3056
3168
|
const items = dn3.store.list({ minWorth: "normal", limit: 300 });
|
|
@@ -3072,7 +3184,7 @@ function llmsTxt(dn3) {
|
|
|
3072
3184
|
function openApi(serverUrl) {
|
|
3073
3185
|
return {
|
|
3074
3186
|
openapi: "3.1.0",
|
|
3075
|
-
info: { title: "driftnet", version: "0.
|
|
3187
|
+
info: { title: "driftnet", version: "0.2.0", description: "Search and save shared AI tools." },
|
|
3076
3188
|
servers: [{ url: serverUrl }],
|
|
3077
3189
|
components: { securitySchemes: { bearer: { type: "http", scheme: "bearer" } } },
|
|
3078
3190
|
security: [{ bearer: [] }],
|
|
@@ -3202,24 +3314,30 @@ var init_feeds = __esm({
|
|
|
3202
3314
|
// apps/server/src/main.ts
|
|
3203
3315
|
var main_exports = {};
|
|
3204
3316
|
import { readFileSync as readFileSync5 } from "node:fs";
|
|
3205
|
-
import { spawn as
|
|
3317
|
+
import { spawn as spawn3 } from "node:child_process";
|
|
3206
3318
|
import { createServer } from "node:http";
|
|
3207
|
-
import { timingSafeEqual as timingSafeEqual3 } from "node:crypto";
|
|
3208
3319
|
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
3209
|
-
function authorized(req) {
|
|
3210
|
-
if (!TOKEN) return true;
|
|
3211
|
-
const given = Buffer.from((req.headers.authorization ?? "").replace(/^Bearer\s+/i, ""));
|
|
3212
|
-
const want = Buffer.from(TOKEN);
|
|
3213
|
-
return given.length === want.length && timingSafeEqual3(given, want);
|
|
3214
|
-
}
|
|
3215
3320
|
function settingsAllowed(req) {
|
|
3216
3321
|
if (!authorized(req)) return false;
|
|
3217
3322
|
const host = req.headers.host ?? "";
|
|
3218
|
-
if (!
|
|
3323
|
+
if (!token(env) && !isLocal(req)) return false;
|
|
3219
3324
|
const origin = req.headers.origin;
|
|
3220
3325
|
if (origin && origin !== `http://${host}` && origin !== `https://${host}`) return false;
|
|
3221
3326
|
return req.method === "GET" || /^application\/json\b/.test(req.headers["content-type"] ?? "");
|
|
3222
3327
|
}
|
|
3328
|
+
function accessView(req) {
|
|
3329
|
+
const t = token(env);
|
|
3330
|
+
return {
|
|
3331
|
+
access: {
|
|
3332
|
+
local: isLocal(req),
|
|
3333
|
+
private: isPrivate(env),
|
|
3334
|
+
passwordSet: !!t,
|
|
3335
|
+
readKey: readKey(env) ?? null,
|
|
3336
|
+
publicUrl: env.DRIFTNET_TUNNEL_URL || env.DRIFTNET_PUBLIC_URL || null,
|
|
3337
|
+
tunnel: { available: tunnel.available(), running: tunnel.running, url: tunnel.url, error: tunnel.error }
|
|
3338
|
+
}
|
|
3339
|
+
};
|
|
3340
|
+
}
|
|
3223
3341
|
async function readJson(req) {
|
|
3224
3342
|
const raw = await readBody(req);
|
|
3225
3343
|
try {
|
|
@@ -3245,7 +3363,7 @@ function send(res, status, body, type = "application/json; charset=utf-8") {
|
|
|
3245
3363
|
function openBrowser(url2) {
|
|
3246
3364
|
const [command, args] = process.platform === "darwin" ? ["open", [url2]] : process.platform === "win32" ? ["cmd", ["/c", "start", "", url2]] : ["xdg-open", [url2]];
|
|
3247
3365
|
try {
|
|
3248
|
-
|
|
3366
|
+
spawn3(command, args, { stdio: "ignore", detached: true }).on("error", () => {
|
|
3249
3367
|
}).unref();
|
|
3250
3368
|
} catch {
|
|
3251
3369
|
}
|
|
@@ -3265,7 +3383,7 @@ async function suggestLocalModel() {
|
|
|
3265
3383
|
} catch {
|
|
3266
3384
|
}
|
|
3267
3385
|
}
|
|
3268
|
-
var env, fromEnvironment, envFile, plugins, dn, settings, PORT, HOST,
|
|
3386
|
+
var env, fromEnvironment, envFile, plugins, dn, settings, PORT, HOST, indexHtml, STATIC, authorized, tunnel, BadRequest, server;
|
|
3269
3387
|
var init_main = __esm({
|
|
3270
3388
|
async "apps/server/src/main.ts"() {
|
|
3271
3389
|
"use strict";
|
|
@@ -3278,6 +3396,7 @@ var init_main = __esm({
|
|
|
3278
3396
|
init_mcp();
|
|
3279
3397
|
init_export();
|
|
3280
3398
|
init_settings();
|
|
3399
|
+
init_access();
|
|
3281
3400
|
init_feeds();
|
|
3282
3401
|
env = process.env;
|
|
3283
3402
|
fromEnvironment = new Set(Object.keys(env).filter((k) => env[k] !== void 0));
|
|
@@ -3287,9 +3406,7 @@ var init_main = __esm({
|
|
|
3287
3406
|
settings = new Settings(env, fromEnvironment);
|
|
3288
3407
|
PORT = Number(env.PORT ?? 8787);
|
|
3289
3408
|
HOST = env.DRIFTNET_HOST ?? "127.0.0.1";
|
|
3290
|
-
|
|
3291
|
-
PRIVATE = env.DRIFTNET_ACCESS === "private";
|
|
3292
|
-
if (PRIVATE && !TOKEN) {
|
|
3409
|
+
if (isPrivate(env) && !token(env)) {
|
|
3293
3410
|
console.error("DRIFTNET_ACCESS=private needs DRIFTNET_TOKEN to be set");
|
|
3294
3411
|
process.exit(1);
|
|
3295
3412
|
}
|
|
@@ -3300,6 +3417,13 @@ var init_main = __esm({
|
|
|
3300
3417
|
"/icon-512.png": [readFileSync5(new URL("../public/icon-512.png", import.meta.url)), "image/png"],
|
|
3301
3418
|
"/manifest.webmanifest": [readFileSync5(new URL("../public/manifest.webmanifest", import.meta.url)), "application/manifest+json"]
|
|
3302
3419
|
};
|
|
3420
|
+
authorized = (req) => isAdmin(req, env);
|
|
3421
|
+
tunnel = new Tunnel(PORT);
|
|
3422
|
+
process.on("exit", () => tunnel.stop());
|
|
3423
|
+
for (const signal of ["SIGINT", "SIGTERM"]) process.on(signal, () => {
|
|
3424
|
+
tunnel.stop();
|
|
3425
|
+
process.exit(0);
|
|
3426
|
+
});
|
|
3303
3427
|
BadRequest = class extends Error {
|
|
3304
3428
|
};
|
|
3305
3429
|
server = createServer(async (req, res) => {
|
|
@@ -3312,9 +3436,9 @@ var init_main = __esm({
|
|
|
3312
3436
|
res.writeHead(200, { "content-type": asset[1], "cache-control": "public, max-age=86400" });
|
|
3313
3437
|
return res.end(asset[0]);
|
|
3314
3438
|
}
|
|
3315
|
-
if (
|
|
3439
|
+
if (req.method === "GET" && !canRead(req, env)) return send(res, 401, { error: "unauthorized" });
|
|
3316
3440
|
if (req.method === "GET" && path === "/llms.txt") return send(res, 200, llmsTxt(dn), "text/plain; charset=utf-8");
|
|
3317
|
-
if (req.method === "GET" && path === "/openapi.json") return send(res, 200, openApi(`${url2.protocol}//${url2.host}`));
|
|
3441
|
+
if (req.method === "GET" && path === "/openapi.json") return send(res, 200, openApi(env.DRIFTNET_TUNNEL_URL || env.DRIFTNET_PUBLIC_URL || `${url2.protocol}//${url2.host}`));
|
|
3318
3442
|
if (req.method === "GET" && path === "/api/categories") return send(res, 200, dn.categories);
|
|
3319
3443
|
if (req.method === "GET" && path === "/api/ui") {
|
|
3320
3444
|
const categories = Object.fromEntries(
|
|
@@ -3407,11 +3531,16 @@ var init_main = __esm({
|
|
|
3407
3531
|
}
|
|
3408
3532
|
if (path === "/api/settings" && (req.method === "GET" || req.method === "PUT")) {
|
|
3409
3533
|
if (!settingsAllowed(req)) {
|
|
3410
|
-
return send(res, 403, { error:
|
|
3534
|
+
return send(res, 403, { error: token(env) ? "unauthorized" : "settings can only be changed from this machine; set an admin password to change them remotely" });
|
|
3411
3535
|
}
|
|
3412
3536
|
if (req.method === "PUT") {
|
|
3413
3537
|
try {
|
|
3414
|
-
const
|
|
3538
|
+
const values = (await readJson(req)).values ?? {};
|
|
3539
|
+
const nextToken = "DRIFTNET_TOKEN" in values ? values.DRIFTNET_TOKEN : token(env);
|
|
3540
|
+
const nextAccess = "DRIFTNET_ACCESS" in values ? values.DRIFTNET_ACCESS : env.DRIFTNET_ACCESS;
|
|
3541
|
+
if (nextAccess === "private" && !nextToken) throw new SettingsError("private access needs an admin password");
|
|
3542
|
+
if (values.DRIFTNET_TOKEN === null && tunnel.running) throw new SettingsError("turn the public URL off before removing the password");
|
|
3543
|
+
const changed = settings.update(values);
|
|
3415
3544
|
if (changed.length) dn.reconfigure(env);
|
|
3416
3545
|
return send(res, 200, { ...settings.view(), changed, engines: dn.engines });
|
|
3417
3546
|
} catch (err) {
|
|
@@ -3419,7 +3548,40 @@ var init_main = __esm({
|
|
|
3419
3548
|
throw err;
|
|
3420
3549
|
}
|
|
3421
3550
|
}
|
|
3422
|
-
return send(res, 200, { ...settings.view(), engines: dn.engines, plugins });
|
|
3551
|
+
return send(res, 200, { ...settings.view(), engines: dn.engines, plugins, ...accessView(req) });
|
|
3552
|
+
}
|
|
3553
|
+
if (req.method === "POST" && path === "/api/read-key") {
|
|
3554
|
+
if (!settingsAllowed(req)) return send(res, 403, { error: "unauthorized" });
|
|
3555
|
+
try {
|
|
3556
|
+
settings.update({ DRIFTNET_READ_KEY: newKey() });
|
|
3557
|
+
return send(res, 200, { ...settings.view(), ...accessView(req) });
|
|
3558
|
+
} catch (err) {
|
|
3559
|
+
if (err instanceof SettingsError) return send(res, 400, { error: err.message });
|
|
3560
|
+
throw err;
|
|
3561
|
+
}
|
|
3562
|
+
}
|
|
3563
|
+
if (req.method === "POST" && path === "/api/tunnel") {
|
|
3564
|
+
if (!settingsAllowed(req)) return send(res, 403, { error: "unauthorized" });
|
|
3565
|
+
const { on } = await readJson(req);
|
|
3566
|
+
try {
|
|
3567
|
+
if (!on) {
|
|
3568
|
+
tunnel.stop();
|
|
3569
|
+
delete env.DRIFTNET_TUNNEL_URL;
|
|
3570
|
+
} else {
|
|
3571
|
+
if (!token(env)) throw new SettingsError("set an admin password first");
|
|
3572
|
+
if (!tunnel.available()) throw new SettingsError("cloudflared is not installed");
|
|
3573
|
+
const lock = {};
|
|
3574
|
+
if (!isPrivate(env)) lock.DRIFTNET_ACCESS = "private";
|
|
3575
|
+
if (!readKey(env)) lock.DRIFTNET_READ_KEY = newKey();
|
|
3576
|
+
settings.update(lock);
|
|
3577
|
+
env.DRIFTNET_TUNNEL_URL = await tunnel.start();
|
|
3578
|
+
console.log(`[tunnel] public URL: ${env.DRIFTNET_TUNNEL_URL}`);
|
|
3579
|
+
}
|
|
3580
|
+
return send(res, 200, { ...settings.view(), ...accessView(req) });
|
|
3581
|
+
} catch (err) {
|
|
3582
|
+
if (err instanceof SettingsError) return send(res, 400, { error: err.message });
|
|
3583
|
+
return send(res, 502, { error: err.message });
|
|
3584
|
+
}
|
|
3423
3585
|
}
|
|
3424
3586
|
if (req.method === "GET" && path === "/api/export") {
|
|
3425
3587
|
const lang = url2.searchParams.get("lang");
|
|
@@ -3493,9 +3655,10 @@ var init_main = __esm({
|
|
|
3493
3655
|
return send(res, r.status, r.body ?? "", "text/plain");
|
|
3494
3656
|
}
|
|
3495
3657
|
if (path === "/mcp") {
|
|
3496
|
-
|
|
3658
|
+
const admin = authorized(req);
|
|
3659
|
+
if (!admin && !canRead(req, env)) return send(res, 401, { error: "unauthorized" });
|
|
3497
3660
|
const agent = req.headers["x-driftnet-agent"]?.slice(0, 40) ?? "agent";
|
|
3498
|
-
const mcp = createMcpServer(dn, agent);
|
|
3661
|
+
const mcp = createMcpServer(dn, agent, { readOnly: !admin });
|
|
3499
3662
|
const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: void 0 });
|
|
3500
3663
|
res.on("close", () => {
|
|
3501
3664
|
void transport.close();
|
|
@@ -3506,7 +3669,7 @@ var init_main = __esm({
|
|
|
3506
3669
|
return await transport.handleRequest(req, res, body);
|
|
3507
3670
|
}
|
|
3508
3671
|
if (req.method === "POST" && path === "/api/pending") {
|
|
3509
|
-
if (!
|
|
3672
|
+
if (!token(env) || !authorized(req)) return send(res, 401, { error: "unauthorized (set an admin password)" });
|
|
3510
3673
|
const body = await readJson(req);
|
|
3511
3674
|
const agent = `agent:${String(body.agent ?? "http").slice(0, 40)}`;
|
|
3512
3675
|
const items = dn.store.claimPending(agent, Number(body.limit ?? 5));
|
|
@@ -3529,7 +3692,7 @@ var init_main = __esm({
|
|
|
3529
3692
|
}
|
|
3530
3693
|
const enrichMatch = /^\/api\/items\/(\d+)\/enrich$/.exec(path);
|
|
3531
3694
|
if (req.method === "POST" && enrichMatch) {
|
|
3532
|
-
if (!
|
|
3695
|
+
if (!token(env) || !authorized(req)) return send(res, 401, { error: "unauthorized (set an admin password)" });
|
|
3533
3696
|
const body = await readJson(req);
|
|
3534
3697
|
const agent = `agent:${String(body.agent ?? "http").slice(0, 40)}`;
|
|
3535
3698
|
delete body.agent;
|
|
@@ -3598,7 +3761,7 @@ var init_mcp_stdio = __esm({
|
|
|
3598
3761
|
|
|
3599
3762
|
// apps/server/src/cli.ts
|
|
3600
3763
|
var [cmd = "start"] = process.argv.slice(2);
|
|
3601
|
-
var VERSION = "0.
|
|
3764
|
+
var VERSION = "0.2.0";
|
|
3602
3765
|
if (cmd === "start") await init_main().then(() => main_exports);
|
|
3603
3766
|
else if (cmd === "mcp") await init_mcp_stdio().then(() => mcp_stdio_exports);
|
|
3604
3767
|
else if (cmd === "--version" || cmd === "-v") console.log(VERSION);
|
package/package.json
CHANGED
package/public/index.html
CHANGED
|
@@ -129,6 +129,21 @@
|
|
|
129
129
|
.set-row small { color: var(--muted); }
|
|
130
130
|
.set-status { font-size: 13px; color: var(--muted); background: var(--bg); border-radius: 8px; padding: 8px 10px; margin-bottom: 14px; }
|
|
131
131
|
.set-scroll { max-height: min(70vh, 640px); overflow: auto; margin: 0 -18px; padding: 0 18px; }
|
|
132
|
+
.keyrow { display: flex; gap: 6px; align-items: center; }
|
|
133
|
+
.keyrow input { flex: 1; min-width: 0; font-family: ui-monospace, Menlo, monospace; font-size: 14px; }
|
|
134
|
+
.keyrow .btn { min-height: 38px; padding: 6px 10px; white-space: nowrap; }
|
|
135
|
+
.meter { height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; margin-top: 2px; }
|
|
136
|
+
.meter i { display: block; height: 100%; width: 0; transition: width .2s ease, background .2s ease; }
|
|
137
|
+
.meter[data-s="weak"] i { width: 33%; background: var(--danger); }
|
|
138
|
+
.meter[data-s="ok"] i { width: 66%; background: var(--star); }
|
|
139
|
+
.meter[data-s="strong"] i { width: 100%; background: var(--ok); }
|
|
140
|
+
.warn { background: var(--star-soft); color: var(--text); border-radius: 8px; padding: 8px 10px; font-size: 13px; margin: 4px 0 10px; }
|
|
141
|
+
.warn.danger { background: var(--danger-soft); }
|
|
142
|
+
.conn { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; }
|
|
143
|
+
.conn h4 { margin: 0 0 4px; font-size: 15px; }
|
|
144
|
+
.conn p { margin: 0 0 8px; font-size: 13px; color: var(--muted); }
|
|
145
|
+
.conn pre { margin: 0; background: var(--bg); border-radius: 8px; padding: 8px 10px; font-size: 12.5px; white-space: pre-wrap; word-break: break-all; }
|
|
146
|
+
.conn .copy { float: right; margin: -2px 0 6px 8px; min-height: 32px; padding: 4px 10px; font-size: 13px; }
|
|
132
147
|
.welcome { background: var(--accent-soft); color: var(--text); border-radius: 10px; padding: 10px 12px; font-size: 14px; margin-bottom: 14px; }
|
|
133
148
|
.tool.grip { cursor: grab; display: none; }
|
|
134
149
|
@media (hover: hover) and (pointer: fine) { .tool.grip { display: grid; } }
|
|
@@ -258,6 +273,11 @@
|
|
|
258
273
|
<button class="btn" id="st-cancel" type="button"></button><button class="btn primary" id="st-save" type="submit"></button></div>
|
|
259
274
|
</form>
|
|
260
275
|
</dialog>
|
|
276
|
+
<dialog id="connect-dlg" class="wide">
|
|
277
|
+
<h3 id="cx-title"></h3>
|
|
278
|
+
<div class="set-scroll" id="cx-body"></div>
|
|
279
|
+
<div class="dlg-actions"><span class="spacer"></span><button class="btn" id="cx-close" type="button"></button></div>
|
|
280
|
+
</dialog>
|
|
261
281
|
<dialog id="note-dlg">
|
|
262
282
|
<form id="note-form" method="dialog">
|
|
263
283
|
<h3 id="in-title"></h3>
|
|
@@ -293,7 +313,7 @@
|
|
|
293
313
|
favorite: "Add to favorites", unfavorite: "Remove from favorites", remove: "Move to trash", restore: "Restore",
|
|
294
314
|
swipeFav: "☆ Favorite", swipeUnfav: "★ Unfavorite", swipeTrash: "Remove 🗑", swipeRestore: "↩ Restore",
|
|
295
315
|
removed: (n) => `“${n}” moved to the trash`, restored: (n) => `“${n}” restored`, faved: (n) => `★ “${n}” added to favorites`,
|
|
296
|
-
undo: "Undo", tokenPrompt: "This catalogue is private. Enter
|
|
316
|
+
undo: "Undo", tokenPrompt: "This catalogue is private. Enter the admin password, or a read-only share key to just look.", tokenSave: "Open",
|
|
297
317
|
failed: "Couldn't save — check your connection.", menu: "Menu", close: "Close menu", showing: "Showing:",
|
|
298
318
|
folders: "Folders", newFolder: "New folder", newSub: "New folder inside", editFolder: "Edit folder", folderName: "Name",
|
|
299
319
|
folderDesc: "What goes here? (driftnet's AI reads this to sort new links)", folderParent: "Inside", topLevel: "— Top level —",
|
|
@@ -316,6 +336,19 @@
|
|
|
316
336
|
status: (e) => `Now: sorting by ${({ jev: "Jev", llm: "the model", heuristic: "built-in rules" })[e.judge] ?? e.judge}, summaries by ${e.summarizer === "off" ? "nobody (off)" : e.summarizer}`, keep: "set — leave empty to keep", unset: "not set",
|
|
317
337
|
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.",
|
|
318
338
|
savedServer: "Saved — already in effect",
|
|
339
|
+
access: "Access & connections",
|
|
340
|
+
password: "Admin password", passwordHelp: "Needed to add links, change settings and let agents write. At least 8 characters, no spaces.",
|
|
341
|
+
generate: "Generate", show: "Show", hide: "Hide", copy: "Copy", copied: "Copied",
|
|
342
|
+
strength: { weak: "Weak — easy to guess. Fine on this computer only; don't open a public URL with it.", ok: "OK", strong: "Strong" },
|
|
343
|
+
passwordWarn: "Anyone with this password can add, move and delete in your catalogue. Don't reuse a password from elsewhere, and don't paste it into public chats.",
|
|
344
|
+
accessMode: "Who can read", accessChoices: { "": "Anyone who can reach this page", public: "Anyone who can reach this page", private: "Only with the password or the share key" },
|
|
345
|
+
shareKey: "Read-only share key", shareKeyHelp: "For AIs that can only open links (ChatGPT, Grok, Claude.ai): they can read your catalogue, nothing more. If it leaks, make a new one.",
|
|
346
|
+
newShareKey: "New key", noShareKey: "No share key yet.",
|
|
347
|
+
tunnel: "Public URL for cloud AIs", tunnelHelp: "Claude.ai, ChatGPT, Grok and agents on other machines can't reach localhost. This opens a temporary https address through Cloudflare (no account). It changes every time and closes when driftnet stops.",
|
|
348
|
+
tunnelOn: "Open a public URL", tunnelOff: "Close it", tunnelNeedsPassword: "Save an admin password first.",
|
|
349
|
+
tunnelInstall: "Needs cloudflared (driftnet never downloads it for you):", tunnelPrivate: "Opening it switches reading to “only with the password or the share key”.",
|
|
350
|
+
tunnelStarting: "Starting the tunnel… (up to 30 s)", saveFirst: "Save first, then open the public URL.",
|
|
351
|
+
connect: "🔌 Connect an AI",
|
|
319
352
|
labels: {
|
|
320
353
|
DRIFTNET_LLM_PROVIDER: ["Model provider", "Summaries. None: links are still sorted, only without a summary."],
|
|
321
354
|
DRIFTNET_LLM_MODEL: ["Model", "e.g. claude-haiku-5-5, gpt-5-mini, gemini-3.8-flash, qwen3"],
|
|
@@ -354,7 +387,7 @@
|
|
|
354
387
|
favorite: "加入最愛", unfavorite: "移出最愛", remove: "移到垃圾桶", restore: "還原",
|
|
355
388
|
swipeFav: "☆ 加入最愛", swipeUnfav: "★ 移出最愛", swipeTrash: "移到垃圾桶 🗑", swipeRestore: "↩ 還原",
|
|
356
389
|
removed: (n) => `已將「${n}」移到垃圾桶`, restored: (n) => `已還原「${n}」`, faved: (n) => `★ 已將「${n}」加入最愛`,
|
|
357
|
-
undo: "復原", tokenPrompt: "
|
|
390
|
+
undo: "復原", tokenPrompt: "這份清單是私人的。請輸入管理密碼;只想瀏覽的話,輸入唯讀分享碼也可以。", tokenSave: "開啟",
|
|
358
391
|
failed: "沒有存成功,請檢查網路。", menu: "選單", close: "關閉選單", showing: "目前顯示:",
|
|
359
392
|
folders: "資料夾", newFolder: "新資料夾", newSub: "在裡面新增資料夾", editFolder: "編輯資料夾", folderName: "名稱",
|
|
360
393
|
folderDesc: "放什麼?(driftnet 的 AI 會照這段說明把新連結分進來)", folderParent: "放在", topLevel: "— 最上層 —",
|
|
@@ -377,6 +410,19 @@
|
|
|
377
410
|
status: (e) => `目前:分類用 ${({ jev: "Jev", llm: "模型", heuristic: "內建規則" })[e.judge] ?? e.judge},摘要用 ${e.summarizer === "off" ? "(未開啟)" : e.summarizer}`, keep: "已設定,留空就不變", unset: "未設定",
|
|
378
411
|
locked: "由執行環境設定", forbidden: "伺服器設定只能在執行 driftnet 的那台電腦上改(或設定 DRIFTNET_TOKEN)。顯示設定照常可用。",
|
|
379
412
|
savedServer: "已儲存,馬上生效",
|
|
413
|
+
access: "存取與連線",
|
|
414
|
+
password: "管理密碼", passwordHelp: "新增連結、改設定、讓 agent 寫入都需要它。至少 8 個字元,不能有空白。",
|
|
415
|
+
generate: "產生", show: "顯示", hide: "隱藏", copy: "複製", copied: "已複製",
|
|
416
|
+
strength: { weak: "弱:很容易被猜到。只在這台電腦用還可以,不要拿它開公開網址。", ok: "普通", strong: "強" },
|
|
417
|
+
passwordWarn: "知道這組密碼的人,可以新增、移動、刪除你清單裡的東西。不要沿用其他網站的密碼,也不要貼到公開的聊天室。",
|
|
418
|
+
accessMode: "誰可以讀", accessChoices: { "": "連得到這個網頁的人都可以", public: "連得到這個網頁的人都可以", private: "要有密碼或分享碼才能讀" },
|
|
419
|
+
shareKey: "唯讀分享碼", shareKeyHelp: "給只會開連結的 AI(ChatGPT、Grok、Claude 網頁版):只能讀你的清單,不能改。外流的話重產一組就好。",
|
|
420
|
+
newShareKey: "重新產生", noShareKey: "還沒有分享碼。",
|
|
421
|
+
tunnel: "給雲端 AI 的公開網址", tunnelHelp: "Claude 網頁版、ChatGPT、Grok 和其他機器上的 agent 連不到 localhost。這會透過 Cloudflare(免帳號)開一個臨時的 https 網址;每次都不一樣,driftnet 關掉就跟著關。",
|
|
422
|
+
tunnelOn: "開啟公開網址", tunnelOff: "關閉", tunnelNeedsPassword: "要先儲存管理密碼。",
|
|
423
|
+
tunnelInstall: "需要 cloudflared(driftnet 不會自動幫你下載):", tunnelPrivate: "開啟後,「誰可以讀」會改成要有密碼或分享碼。",
|
|
424
|
+
tunnelStarting: "正在開通道…(最多 30 秒)", saveFirst: "先按儲存,再開公開網址。",
|
|
425
|
+
connect: "🔌 連接 AI",
|
|
380
426
|
labels: {
|
|
381
427
|
DRIFTNET_LLM_PROVIDER: ["模型來源", "用來寫摘要。選「不使用」也會分類,只是沒有摘要。"],
|
|
382
428
|
DRIFTNET_LLM_MODEL: ["模型", "例如 claude-haiku-5-5、gpt-5-mini、gemini-3.8-flash、qwen3"],
|
|
@@ -511,7 +557,8 @@
|
|
|
511
557
|
`<button type="button" class="icon" data-new="" title="${esc(T().newFolder)}" aria-label="${esc(T().newFolder)}">+</button></div>` +
|
|
512
558
|
`<div class="tree" role="list">${folderRows(null, 0)}</div><h2>${esc(T().kind)}</h2><div class="row kinds">` + btn("kind", "", T().any, "") +
|
|
513
559
|
Object.entries(T().kinds).map(([k, v]) => btn("kind", k, v, "")).join("") + `</div>` +
|
|
514
|
-
`<div class="foot"><button type="button" data-
|
|
560
|
+
`<div class="foot"><button type="button" data-connect>${esc(T().st.connect)}</button>` +
|
|
561
|
+
`<button type="button" data-settings>${esc(T().settings)}</button>` +
|
|
515
562
|
`<button type="button" data-export="markdown">${esc(T().exportMd)}</button>` +
|
|
516
563
|
`<button type="button" data-export="vault">${esc(T().exportVault)}</button></div>`;
|
|
517
564
|
$("nav").onclick = (e) => {
|
|
@@ -527,6 +574,7 @@
|
|
|
527
574
|
if (b.dataset.edit) return openFolderDialog(b.dataset.edit);
|
|
528
575
|
if (b.dataset.export) return download(b.dataset.export);
|
|
529
576
|
if (b.dataset.settings !== undefined) { if (isDrawer()) setMenu(false); return openSettings(); }
|
|
577
|
+
if (b.dataset.connect !== undefined) { if (isDrawer()) setMenu(false); return openConnect(); }
|
|
530
578
|
if (b.dataset.new !== undefined) return openFolderDialog(null, b.dataset.new || null);
|
|
531
579
|
const { field, value } = b.dataset;
|
|
532
580
|
// Choosing a category stays inside the current view; choosing a view clears the category.
|
|
@@ -758,6 +806,7 @@
|
|
|
758
806
|
const plugins = serverSettings.plugins?.length ? serverSettings.plugins.map((p) => `<div>🧩 ${esc(p)}</div>`).join("")
|
|
759
807
|
: esc(st.pluginsNone(serverSettings.file.replace(/\.env$/, "plugins/")));
|
|
760
808
|
server = `<p class="set-status" id="st-status">${esc(st.status(serverSettings.engines))}</p>` +
|
|
809
|
+
accessPanel(serverSettings, field) +
|
|
761
810
|
group("model") + group("language") + group("rules") +
|
|
762
811
|
`<fieldset class="set-group"><legend>${esc(st.plugins)}</legend><div class="set-row">${plugins}</div></fieldset>`;
|
|
763
812
|
}
|
|
@@ -769,6 +818,82 @@
|
|
|
769
818
|
$("settings-dlg").showModal();
|
|
770
819
|
}
|
|
771
820
|
$("st-cancel").onclick = () => $("settings-dlg").close();
|
|
821
|
+
|
|
822
|
+
// ── Access panel: password, who can read, share key, public URL ───────────
|
|
823
|
+
const pwStrength = (pw) => {
|
|
824
|
+
const kinds = [/[a-z]/, /[A-Z]/, /\d/, /[^\w]/].filter((r) => r.test(pw)).length;
|
|
825
|
+
if ((pw.length >= 16 && kinds >= 2) || (pw.length >= 12 && kinds >= 3)) return "strong";
|
|
826
|
+
return pw.length >= 10 && kinds >= 2 ? "ok" : "weak";
|
|
827
|
+
};
|
|
828
|
+
const randomPassword = () => { const a = new Uint8Array(18); crypto.getRandomValues(a); return btoa(String.fromCharCode(...a)).replace(/[+/=]/g, "").slice(0, 22); };
|
|
829
|
+
function accessPanel(v, field) {
|
|
830
|
+
const st = T().st, a = v.access;
|
|
831
|
+
const byKey = (k) => v.settings.find((x) => x.key === k);
|
|
832
|
+
const pw = byKey("DRIFTNET_TOKEN"), mode = byKey("DRIFTNET_ACCESS");
|
|
833
|
+
const pwInput = `<div class="keyrow"><input id="ac-pw" data-key="DRIFTNET_TOKEN" type="password" autocomplete="new-password"
|
|
834
|
+
placeholder="${esc(pw.set ? st.keep : st.unset)}" ${pw.locked ? "disabled" : ""}>
|
|
835
|
+
<button class="btn" type="button" id="ac-show" ${pw.locked ? "disabled" : ""}>${esc(st.show)}</button>
|
|
836
|
+
<button class="btn" type="button" id="ac-gen" ${pw.locked ? "disabled" : ""}>${esc(st.generate)}</button></div>
|
|
837
|
+
<div class="meter" id="ac-meter"><i></i></div><small id="ac-strength"></small>`;
|
|
838
|
+
const modeSel = `<select data-key="DRIFTNET_ACCESS" ${mode.locked ? "disabled" : ""}>${["public", "private"].map((c) =>
|
|
839
|
+
`<option value="${c}" ${(mode.value || "public") === c ? "selected" : ""}>${esc(st.accessChoices[c])}</option>`).join("")}</select>`;
|
|
840
|
+
const key = a.readKey
|
|
841
|
+
? `<div class="keyrow"><input id="ac-key" readonly value="${esc(a.readKey)}"><button class="btn" type="button" data-copy="#ac-key">${esc(st.copy)}</button>
|
|
842
|
+
<button class="btn" type="button" id="ac-newkey" ${byKey("DRIFTNET_READ_KEY").locked ? "disabled" : ""}>${esc(st.newShareKey)}</button></div>`
|
|
843
|
+
: `<div class="keyrow"><small>${esc(st.noShareKey)}</small><span class="spacer"></span><button class="btn" type="button" id="ac-newkey">${esc(st.generate)}</button></div>`;
|
|
844
|
+
const t = a.tunnel;
|
|
845
|
+
let tun;
|
|
846
|
+
if (t.running && t.url) tun = `<div class="keyrow"><input id="ac-url" readonly value="${esc(t.url)}"><button class="btn" type="button" data-copy="#ac-url">${esc(st.copy)}</button>
|
|
847
|
+
<button class="btn danger" type="button" id="ac-tunnel" data-on="0">${esc(st.tunnelOff)}</button></div>`;
|
|
848
|
+
else if (!t.available) tun = `<p class="warn">${esc(st.tunnelInstall)}<br><code>brew install cloudflared</code> · <code>winget install Cloudflare.cloudflared</code> ·
|
|
849
|
+
<a href="https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/downloads/" target="_blank" rel="noopener noreferrer">Linux</a></p>`;
|
|
850
|
+
else tun = `<button class="btn primary" type="button" id="ac-tunnel" data-on="1" ${a.passwordSet ? "" : "disabled"}>${esc(st.tunnelOn)}</button>
|
|
851
|
+
<small>${esc(a.passwordSet ? st.tunnelPrivate : st.tunnelNeedsPassword)}</small>`;
|
|
852
|
+
return `<fieldset class="set-group" id="ac"><legend>${esc(st.access)}</legend>
|
|
853
|
+
<div class="set-row"><span>${esc(st.password)} <small>DRIFTNET_TOKEN</small></span>${pwInput}
|
|
854
|
+
<small>${esc(pw.locked ? st.locked : st.passwordHelp)}</small></div>
|
|
855
|
+
<p class="warn">${esc(st.passwordWarn)}</p>
|
|
856
|
+
<label class="set-row"><span>${esc(st.accessMode)} <small>DRIFTNET_ACCESS</small></span>${modeSel}</label>
|
|
857
|
+
<div class="set-row"><span>${esc(st.shareKey)} <small>DRIFTNET_READ_KEY</small></span>${key}<small>${esc(st.shareKeyHelp)}</small></div>
|
|
858
|
+
<div class="set-row"><span>${esc(st.tunnel)}</span>${tun}<small>${esc(st.tunnelHelp)}</small>${t.error ? `<small class="dlg-error">${esc(t.error)}</small>` : ""}</div>
|
|
859
|
+
</fieldset>`;
|
|
860
|
+
}
|
|
861
|
+
async function adminFetch(path, method, body) {
|
|
862
|
+
const token = store.get("driftnet-token");
|
|
863
|
+
const res = await fetch(path, { method, headers: { "content-type": "application/json", ...(token ? { authorization: `Bearer ${token}` } : {}) },
|
|
864
|
+
...(body ? { body: JSON.stringify(body) } : {}) }).catch(() => null);
|
|
865
|
+
const data = await res?.json().catch(() => ({}));
|
|
866
|
+
if (!res?.ok) { $("st-error").textContent = data?.error ?? T().failed; return null; }
|
|
867
|
+
return data;
|
|
868
|
+
}
|
|
869
|
+
$("st-body").addEventListener("input", (e) => {
|
|
870
|
+
if (e.target.id !== "ac-pw") return;
|
|
871
|
+
const pw = e.target.value, s = pw ? pwStrength(pw) : "";
|
|
872
|
+
$("ac-meter").dataset.s = s;
|
|
873
|
+
$("ac-strength").textContent = s ? T().st.strength[s] : "";
|
|
874
|
+
});
|
|
875
|
+
$("st-body").addEventListener("click", async (e) => {
|
|
876
|
+
const st = T().st;
|
|
877
|
+
const b = e.target.closest("button");
|
|
878
|
+
if (!b) return;
|
|
879
|
+
if (b.dataset.copy) {
|
|
880
|
+
const el = $("st-body").querySelector(b.dataset.copy) ?? $("cx-body").querySelector(b.dataset.copy);
|
|
881
|
+
await navigator.clipboard?.writeText(el.value ?? el.textContent).catch(() => {});
|
|
882
|
+
b.textContent = st.copied; setTimeout(() => (b.textContent = st.copy), 1200);
|
|
883
|
+
} else if (b.id === "ac-show") {
|
|
884
|
+
const i = $("ac-pw"); i.type = i.type === "password" ? "text" : "password"; b.textContent = i.type === "password" ? st.show : st.hide;
|
|
885
|
+
} else if (b.id === "ac-gen") {
|
|
886
|
+
const i = $("ac-pw"); i.value = randomPassword(); i.type = "text"; $("ac-show").textContent = st.hide;
|
|
887
|
+
i.dispatchEvent(new Event("input", { bubbles: true }));
|
|
888
|
+
} else if (b.id === "ac-newkey") {
|
|
889
|
+
if (await adminFetch("/api/read-key", "POST", {})) openSettings();
|
|
890
|
+
} else if (b.id === "ac-tunnel") {
|
|
891
|
+
if (b.dataset.on === "1" && $("ac-pw")?.value) { $("st-error").textContent = st.saveFirst; return; }
|
|
892
|
+
b.disabled = true; b.textContent = b.dataset.on === "1" ? st.tunnelStarting : b.textContent;
|
|
893
|
+
if (await adminFetch("/api/tunnel", "POST", { on: b.dataset.on === "1" })) openSettings();
|
|
894
|
+
else b.disabled = false;
|
|
895
|
+
}
|
|
896
|
+
});
|
|
772
897
|
$("settings-form").onsubmit = async (e) => {
|
|
773
898
|
e.preventDefault();
|
|
774
899
|
const body = $("st-body");
|
|
@@ -789,6 +914,8 @@
|
|
|
789
914
|
const data = await res?.json().catch(() => ({}));
|
|
790
915
|
if (!res?.ok) { $("st-error").textContent = data?.error ?? T().failed; return; }
|
|
791
916
|
serverSaved = true;
|
|
917
|
+
// The page keeps working with the password it just set (or forgets a removed one).
|
|
918
|
+
if ("DRIFTNET_TOKEN" in values) values.DRIFTNET_TOKEN ? store.set("driftnet-token", values.DRIFTNET_TOKEN.trim()) : store.set("driftnet-token", "");
|
|
792
919
|
}
|
|
793
920
|
}
|
|
794
921
|
$("settings-dlg").close();
|
|
@@ -796,6 +923,53 @@
|
|
|
796
923
|
load();
|
|
797
924
|
};
|
|
798
925
|
|
|
926
|
+
// ── Connect an AI: copy-paste cards with the URL and keys filled in ───────
|
|
927
|
+
async function openConnect() {
|
|
928
|
+
const t = T(), st = t.st, zh = locale === "zh-TW";
|
|
929
|
+
const token = store.get("driftnet-token");
|
|
930
|
+
const res = await fetch("/api/settings", { headers: token ? { authorization: `Bearer ${token}` } : {} }).catch(() => null);
|
|
931
|
+
const a = res?.ok ? (await res.json()).access : null;
|
|
932
|
+
const base = (a?.publicUrl || location.origin).replace(/\/$/, "");
|
|
933
|
+
const isLocalUrl = /\/\/(localhost|127\.0\.0\.1|\[::1\])/.test(base);
|
|
934
|
+
const key = a?.readKey || (zh ? "<唯讀分享碼>" : "<share-key>");
|
|
935
|
+
const pw = zh ? "<你的管理密碼>" : "<your-admin-password>";
|
|
936
|
+
const withKey = (u) => (a?.private || a?.readKey ? `${u}?key=${key}` : u);
|
|
937
|
+
const card = (id, title, desc, code) => `<div class="conn"><h4>${esc(title)}</h4><p>${esc(desc)}</p>
|
|
938
|
+
<button class="btn copy" type="button" data-copy="#cx-${id}">${esc(st.copy)}</button><pre id="cx-${id}">${esc(code)}</pre></div>`;
|
|
939
|
+
const cards = [
|
|
940
|
+
card("cc", "Claude Code", zh ? "這台電腦上:裝插件(含 skill 和本機 MCP)。在別台電腦:連這個網址,可以讀也可以寫。" : "On this computer: the plugin (skill + local MCP). Elsewhere: connect to this URL, read and write.",
|
|
941
|
+
`/plugin install driftnet --marketplace KevinChu1110/driftnet\n\nclaude mcp add --transport http driftnet ${base}/mcp \\\n --header "Authorization: Bearer ${pw}"`),
|
|
942
|
+
card("claude", zh ? "Claude 網頁版/桌面版(自訂 connector)" : "Claude.ai / Claude Desktop (custom connector)",
|
|
943
|
+
zh ? "設定 → Connectors → 新增自訂 connector,貼上這個網址。用分享碼連線,只能搜尋和查看,不能改。" : "Settings → Connectors → Add custom connector, paste this URL. The share key makes it read-only: search and look, no changes.",
|
|
944
|
+
withKey(`${base}/mcp`)),
|
|
945
|
+
card("gpt", zh ? "ChatGPT 自訂 GPT(Actions)" : "ChatGPT custom GPT (Actions)",
|
|
946
|
+
zh ? "Actions → 從網址匯入 schema。驗證選 API Key、Bearer,填管理密碼(可寫入)或分享碼(唯讀)。" : "Actions → Import from URL. Authentication: API Key, Bearer — the admin password (read and write) or the share key (read-only).",
|
|
947
|
+
withKey(`${base}/openapi.json`)),
|
|
948
|
+
card("chat", zh ? "ChatGPT/Grok/Gemini 對話中直接用" : "ChatGPT / Grok / Gemini, right in a chat",
|
|
949
|
+
zh ? "只要 AI 會開網址就行,把這段貼進對話。唯讀。" : "Any AI that can open a link: paste this into the chat. Read-only.",
|
|
950
|
+
zh ? `讀一下 ${withKey(`${base}/llms.txt`)} ,這是我收藏的 AI 工具清單。幫我找適合「(你的需求)」的工具。`
|
|
951
|
+
: `Read ${withKey(`${base}/llms.txt`)} — it's my catalogue of AI tools. Find me one for: (your task).`),
|
|
952
|
+
card("agents", "Hermes / OpenClaw / pi", zh ? "這些 agent 的 MCP 設定。用管理密碼可以收錄、投票、幫忙讀佇列裡的連結。" : "MCP settings for these agents. With the admin password they can save, vote and work the queue.",
|
|
953
|
+
JSON.stringify({ mcpServers: { driftnet: { type: "http", url: `${base}/mcp`, headers: { Authorization: `Bearer ${pw}` } } } }, null, 2)),
|
|
954
|
+
].join("");
|
|
955
|
+
const warn = isLocalUrl
|
|
956
|
+
? `<p class="warn danger">${esc(zh ? "這個網址只有這台電腦連得到。雲端的 AI(Claude 網頁版、ChatGPT、Grok、別台機器上的 agent)請先到 ⚙ 設定 →「存取與連線」開公開網址。"
|
|
957
|
+
: "This address only works on this computer. For cloud AIs (Claude.ai, ChatGPT, Grok, agents on other machines), open a public URL first: ⚙ Settings → Access & connections.")}</p>` : "";
|
|
958
|
+
const noKey = a && !a.readKey ? `<p class="warn">${esc(zh ? "還沒有唯讀分享碼:到 ⚙ 設定 →「存取與連線」產生一組。" : "No share key yet: make one in ⚙ Settings → Access & connections.")}</p>` : "";
|
|
959
|
+
$("cx-title").textContent = st.connect;
|
|
960
|
+
$("cx-body").innerHTML = warn + noKey + cards;
|
|
961
|
+
$("cx-close").textContent = t.cancel === "Cancel" ? "Close" : "關閉";
|
|
962
|
+
$("connect-dlg").showModal();
|
|
963
|
+
}
|
|
964
|
+
$("cx-close").onclick = () => $("connect-dlg").close();
|
|
965
|
+
$("connect-dlg").addEventListener("click", async (e) => {
|
|
966
|
+
if (e.target === $("connect-dlg")) return $("connect-dlg").close();
|
|
967
|
+
const b = e.target.closest("button[data-copy]");
|
|
968
|
+
if (!b) return;
|
|
969
|
+
await navigator.clipboard?.writeText($("cx-body").querySelector(b.dataset.copy).textContent).catch(() => {});
|
|
970
|
+
b.textContent = T().st.copied; setTimeout(() => (b.textContent = T().st.copy), 1200);
|
|
971
|
+
});
|
|
972
|
+
|
|
799
973
|
// ── Notes ────────────────────────────────────────────────────────────────
|
|
800
974
|
/** Write with the token; on a refusal show `errorEl` or a toast. */
|
|
801
975
|
async function write(path, method, body) {
|