chatlab-cli 0.23.0 → 0.23.1
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 +53 -30
- package/dist/{chunk-NTWDG52H.mjs → chunk-AHQQQ5HZ.mjs} +41 -7
- package/dist/chunk-AHQQQ5HZ.mjs.map +1 -0
- package/dist/{chunk-D2BR3MFN.mjs → chunk-L37WJ33K.mjs} +28 -1
- package/dist/chunk-L37WJ33K.mjs.map +1 -0
- package/dist/cli.mjs +1 -1
- package/dist/{http-2DN3XOXO.mjs → http-JDORENHT.mjs} +2 -2
- package/dist/index.mjs +2 -2
- package/dist/{service-WNEVPQ4N.mjs → service-WCGGRZTA.mjs} +3 -3
- package/dist/service-WCGGRZTA.mjs.map +1 -0
- package/dist-web/assets/{DebugToolsPanel-D9O_4J04.css → DebugToolsPanel-Yzfz2ntn.css} +1 -1
- package/dist-web/assets/DebugToolsPanel.vue_vue_type_script_setup_true_lang-DXxg55kL.js +161 -0
- package/dist-web/assets/{MessageExportModal-CvocO88D.js → MessageExportModal-DMHA4X0b.js} +1 -1
- package/dist-web/assets/{fetch-CfTcWxqG.js → fetch-BxE8RQYE.js} +1 -1
- package/dist-web/assets/{fetch-DTP8Q782.js → fetch-CvfdN4gM.js} +1 -1
- package/dist-web/assets/{index-CxMP0DNd.css → index-BUfibEyG.css} +1 -1
- package/dist-web/assets/{index-CHkXbqMb.js → index-C2439065.js} +6 -6
- package/dist-web/assets/index-CD5Fz-JY.js +7 -0
- package/dist-web/assets/index-DC0LjKV6.js +2 -0
- package/dist-web/assets/index-Dl-X-izi.css +1 -0
- package/dist-web/assets/index-DywUneNT.css +1 -0
- package/dist-web/assets/index-JvmxkAGk.js +173 -0
- package/dist-web/assets/index-vEVpfw-R.js +163 -0
- package/dist-web/assets/{vendor-nuxt-ui-CuCZ1aRl.js → vendor-nuxt-ui-3XQAyMd0.js} +1 -1
- package/dist-web/assets/{web-DGd63PrV.js → web-Bm94rL5B.js} +1 -1
- package/dist-web/index.html +3 -3
- package/package.json +3 -2
- package/dist/chunk-D2BR3MFN.mjs.map +0 -1
- package/dist/chunk-NTWDG52H.mjs.map +0 -1
- package/dist/service-WNEVPQ4N.mjs.map +0 -1
- package/dist-web/assets/DebugToolsPanel.vue_vue_type_script_setup_true_lang-hp9Mjpub.js +0 -161
- package/dist-web/assets/index-B6dkyIiA.js +0 -2
- package/dist-web/assets/index-CALU1QPF.js +0 -163
- package/dist-web/assets/index-CvuHOeoU.css +0 -1
- package/dist-web/assets/index-DOS5o2_H.js +0 -7
- package/dist-web/assets/index-DuepdDzz.css +0 -1
- package/dist-web/assets/index-niwrSprs.js +0 -173
- /package/dist/{http-2DN3XOXO.mjs.map → http-JDORENHT.mjs.map} +0 -0
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ Your chat history, finally yours.
|
|
|
8
8
|
|
|
9
9
|
English | [简体中文](./README.zh-CN.md)
|
|
10
10
|
|
|
11
|
-
[Official Website](https://chatlab.fun/) · [
|
|
11
|
+
[Official Website](https://chatlab.fun/) · [Docs](https://docs.chatlab.fun/) · [Quick Start](https://docs.chatlab.fun/usage/quick-start) · [Roadmap](https://chatlab.fun/roadmap/tasks) · [Releases](https://github.com/ChatLab/ChatLab/releases)
|
|
12
12
|
|
|
13
13
|
</div>
|
|
14
14
|
|
|
@@ -16,20 +16,56 @@ ChatLab is an open-source desktop app for understanding your social conversation
|
|
|
16
16
|
|
|
17
17
|
Currently supported: **WhatsApp, LINE, WeChat, QQ, Discord, Instagram, and Telegram**. Coming next: **iMessage, Messenger, and KakaoTalk**.
|
|
18
18
|
|
|
19
|
+
> New install? Start here: [Getting started](https://docs.chatlab.fun/usage/quick-start)
|
|
20
|
+
|
|
19
21
|
## Core Features
|
|
20
22
|
|
|
21
23
|
- 🚀 **Built for large histories**: Stream parsing and multi-worker processing keep imports and analysis responsive, even at million-message scale.
|
|
22
24
|
- 🔒 **Private by default**: Your chat data and settings stay local. No mandatory cloud upload of raw conversations.
|
|
23
|
-
- 🤖 **AI that can actually operate on data**: Agent + Function Calling workflows can search, summarize, and analyze chat records with context.
|
|
25
|
+
- 🤖 **AI that can actually operate on data**: Agent + Function Calling workflows (24+ tools) can search, summarize, and analyze chat records with context.
|
|
24
26
|
- 📊 **Insight-rich visual views**: See trends, time patterns, interaction frequency, rankings, and more in one place.
|
|
25
27
|
- 🧩 **Cross-platform normalization**: Different export formats are mapped into a unified model so you can analyze them consistently.
|
|
26
28
|
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
### Desktop App
|
|
32
|
+
|
|
33
|
+
Download the installer for your OS from the [official website](https://chatlab.fun/?type=download) or [GitHub Releases](https://github.com/ChatLab/ChatLab/releases), then double-click to install.
|
|
34
|
+
|
|
35
|
+
### CLI
|
|
36
|
+
|
|
37
|
+
Requires Node.js ≥ 20.
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npm i chatlab-cli -g
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Start ChatLab:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
chatlab start # Start API + Web UI, auto-open in browser
|
|
47
|
+
chatlab start --no-open # Start API + Web UI, skip auto-open
|
|
48
|
+
chatlab start --headless # API only, no Web UI (for scripts / AI Agents)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Common options: `--port <port>` (default 3110), `--host <address>`, `--token <token>`.
|
|
52
|
+
|
|
53
|
+
To run as a persistent background service (auto-start on login + auto-restart on crash):
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
chatlab start --daemon # Install as system service (macOS / Linux)
|
|
57
|
+
chatlab status # Check service status
|
|
58
|
+
chatlab stop # Stop and uninstall service
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
For a full walkthrough, see the [Quick Start guide](https://docs.chatlab.fun/usage/quick-start).
|
|
62
|
+
|
|
27
63
|
## Usage Guides
|
|
28
64
|
|
|
29
65
|
- [Download Guide](https://chatlab.fun/?type=download)
|
|
30
|
-
- [Chat Record Export Guide](https://docs.chatlab.fun/
|
|
31
|
-
- [Standardized Format Specification](https://docs.chatlab.fun/
|
|
32
|
-
- [Troubleshooting Guide](https://docs.chatlab.fun/
|
|
66
|
+
- [Chat Record Export Guide](https://docs.chatlab.fun/usage/how-to-export)
|
|
67
|
+
- [Standardized Format Specification](https://docs.chatlab.fun/standard/chatlab-format)
|
|
68
|
+
- [Troubleshooting Guide](https://docs.chatlab.fun/usage/troubleshooting)
|
|
33
69
|
|
|
34
70
|
## Preview
|
|
35
71
|
|
|
@@ -37,7 +73,13 @@ For more previews, please visit the official website: [chatlab.fun](https://chat
|
|
|
37
73
|
|
|
38
74
|

|
|
39
75
|
|
|
40
|
-
##
|
|
76
|
+
## Architecture Overview
|
|
77
|
+
|
|
78
|
+
ChatLab is a pnpm monorepo built on Electron + Vue 3 + Nuxt UI + Tailwind CSS. Core business logic lives in shared packages (`@openchatlab/core`, `@openchatlab/node-runtime`, `@openchatlab/tools`), consumed by both the desktop app and the CLI service — so they stay in sync.
|
|
79
|
+
|
|
80
|
+
Data flows in five stages: **format detection → stream parsing → local persistence → SQL + AI query → visualization**.
|
|
81
|
+
|
|
82
|
+
For a deep dive, see the [architecture documentation](https://docs.chatlab.fun/intro).
|
|
41
83
|
|
|
42
84
|
### Architecture Principles
|
|
43
85
|
|
|
@@ -46,27 +88,6 @@ For more previews, please visit the official website: [chatlab.fun](https://chat
|
|
|
46
88
|
- **Composable intelligence**: AI features are assembled through Agent + Tool Calling, not hard-coded into one model path.
|
|
47
89
|
- **Schema-first evolution**: Import, query, analysis, and visualization share a consistent data model that scales with new features.
|
|
48
90
|
|
|
49
|
-
### Runtime Architecture
|
|
50
|
-
|
|
51
|
-
- **Main Process (control plane)**: `apps/desktop/main/index.ts` handles lifecycle and windows. `apps/desktop/main/ipc/` defines domain-scoped IPC. Core AI, query, NLP, import, and merge logic lives in shared packages (`packages/core`, `packages/node-runtime`, `packages/tools`); `apps/desktop/main/ai/` and `apps/desktop/main/i18n/` are thin Electron adaptation layers.
|
|
52
|
-
- **Worker Layer (compute plane)**: `apps/desktop/main/worker/` runs import, indexing, and query tasks via `workerManager`, delegating core logic to `@openchatlab/core` and `@openchatlab/node-runtime`.
|
|
53
|
-
- **Renderer Layer (interaction plane)**: Vue 3 + Nuxt UI + Tailwind CSS drive management, private chat, group chat, and analysis interfaces. `apps/desktop/preload/index.ts` exposes tightly scoped APIs for secure process boundaries.
|
|
54
|
-
|
|
55
|
-
### Data Pipeline
|
|
56
|
-
|
|
57
|
-
1. **Ingestion**: `parser/` detects file format and dispatches to the matching parser module.
|
|
58
|
-
2. **Persistence**: Stream-based writes populate core local entities: sessions, members, and messages.
|
|
59
|
-
3. **Indexing**: Session- and time-oriented indexes are built for timeline navigation and retrieval.
|
|
60
|
-
4. **Query & Analysis**: `worker/query/*` powers activity metrics, interaction analysis, SQL Lab, and AI-assisted exploration.
|
|
61
|
-
5. **Presentation**: The renderer turns query output into charts, rankings, timelines, and conversational analysis flows.
|
|
62
|
-
|
|
63
|
-
### Extensibility & Reliability
|
|
64
|
-
|
|
65
|
-
- **Pluggable parser architecture**: Adding a new import source is mostly an extension in `parser/formats/*`, without reworking downstream query logic.
|
|
66
|
-
- **Full + incremental import paths**: `streamImport.ts` and `incrementalImport.ts` support both first-time onboarding and ongoing updates.
|
|
67
|
-
- **Modular IPC boundaries**: Domain-based IPC segmentation reduces cross-layer coupling and limits permission spread.
|
|
68
|
-
- **Unified i18n evolution**: Main and renderer processes share an i18n system that can evolve with product scope.
|
|
69
|
-
|
|
70
91
|
---
|
|
71
92
|
|
|
72
93
|
## Local Development
|
|
@@ -79,11 +100,14 @@ For more previews, please visit the official website: [chatlab.fun](https://chat
|
|
|
79
100
|
### Setup
|
|
80
101
|
|
|
81
102
|
```bash
|
|
82
|
-
#
|
|
103
|
+
# Install dependencies
|
|
83
104
|
pnpm install
|
|
84
105
|
|
|
85
|
-
#
|
|
106
|
+
# Run desktop app in dev mode
|
|
86
107
|
pnpm dev
|
|
108
|
+
|
|
109
|
+
# Run CLI in dev mode (apps/cli)
|
|
110
|
+
cd apps/cli && pnpm dev
|
|
87
111
|
```
|
|
88
112
|
|
|
89
113
|
If Electron encounters exceptions during startup, you can try using `electron-fix`:
|
|
@@ -91,7 +115,6 @@ If Electron encounters exceptions during startup, you can try using `electron-fi
|
|
|
91
115
|
```bash
|
|
92
116
|
npm install electron-fix -g
|
|
93
117
|
electron-fix start
|
|
94
|
-
|
|
95
118
|
```
|
|
96
119
|
|
|
97
120
|
## Privacy Policy & User Agreement
|
|
@@ -30,6 +30,36 @@ import {
|
|
|
30
30
|
import * as fs from "fs";
|
|
31
31
|
import { execSync } from "child_process";
|
|
32
32
|
import { Command } from "commander";
|
|
33
|
+
|
|
34
|
+
// src/http/port.ts
|
|
35
|
+
import * as net from "net";
|
|
36
|
+
function isPortAvailable(port, host) {
|
|
37
|
+
return new Promise((resolve, reject) => {
|
|
38
|
+
const server = net.createServer();
|
|
39
|
+
server.once("error", (err) => {
|
|
40
|
+
if (err.code === "EADDRINUSE") {
|
|
41
|
+
resolve(false);
|
|
42
|
+
} else {
|
|
43
|
+
reject(err);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
server.once("listening", () => server.close(() => resolve(true)));
|
|
47
|
+
server.listen(port, host);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
function formatPortInUseError(port) {
|
|
51
|
+
return [
|
|
52
|
+
``,
|
|
53
|
+
` \u2716 Error: port ${port} is already in use.`,
|
|
54
|
+
``,
|
|
55
|
+
` Another process (possibly a ChatLab instance) is using this port. You can:`,
|
|
56
|
+
` \u2022 Use another port: chatlab start --port <port>`,
|
|
57
|
+
` \u2022 Find the process: lsof -iTCP:${port} -sTCP:LISTEN`,
|
|
58
|
+
``
|
|
59
|
+
].join("\n");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// src/cli.ts
|
|
33
63
|
var program = new Command();
|
|
34
64
|
program.name("chatlab").description("ChatLab - Chat history analysis tool").version(getVersion(), "-v, --version");
|
|
35
65
|
program.hook("preAction", async () => {
|
|
@@ -230,7 +260,7 @@ program.command("mcp").description("Start MCP Server (stdio transport, for Claud
|
|
|
230
260
|
});
|
|
231
261
|
program.command("start").description("Start ChatLab (HTTP API + Web UI)").option("--port <port>", "Server port", String(DEFAULT_API_PORT)).option("--host <host>", "Listen address", "127.0.0.1").option("--token <token>", "Custom Bearer Token (reads from config or auto-generates if omitted)").option("--headless", "API-only mode, do not serve the Web UI").option("--no-open", "Do not auto-open the browser").option("--daemon", "Run as a resident system service (auto-start on login, macOS/Linux)").action(async (options) => {
|
|
232
262
|
if (options.daemon) {
|
|
233
|
-
const { serviceInstall } = await import("./service-
|
|
263
|
+
const { serviceInstall } = await import("./service-WCGGRZTA.mjs");
|
|
234
264
|
serviceInstall({
|
|
235
265
|
port: parseInt(options.port, 10),
|
|
236
266
|
host: options.host,
|
|
@@ -239,7 +269,7 @@ program.command("start").description("Start ChatLab (HTTP API + Web UI)").option
|
|
|
239
269
|
});
|
|
240
270
|
return;
|
|
241
271
|
}
|
|
242
|
-
const { startHttpServer } = await import("./http-
|
|
272
|
+
const { startHttpServer } = await import("./http-JDORENHT.mjs");
|
|
243
273
|
const port = parseInt(options.port, 10);
|
|
244
274
|
let webRoot;
|
|
245
275
|
if (!options.headless) {
|
|
@@ -251,6 +281,10 @@ program.command("start").description("Start ChatLab (HTTP API + Web UI)").option
|
|
|
251
281
|
}
|
|
252
282
|
}
|
|
253
283
|
try {
|
|
284
|
+
if (!await isPortAvailable(port, options.host)) {
|
|
285
|
+
console.error(formatPortInUseError(port));
|
|
286
|
+
process.exit(1);
|
|
287
|
+
}
|
|
254
288
|
const info = await startHttpServer({
|
|
255
289
|
port,
|
|
256
290
|
host: options.host,
|
|
@@ -281,7 +315,7 @@ Press Ctrl+C to stop.
|
|
|
281
315
|
}
|
|
282
316
|
const shutdown = async () => {
|
|
283
317
|
console.log("\nShutting down...");
|
|
284
|
-
const { stopHttpServer } = await import("./http-
|
|
318
|
+
const { stopHttpServer } = await import("./http-JDORENHT.mjs");
|
|
285
319
|
await stopHttpServer();
|
|
286
320
|
process.exit(0);
|
|
287
321
|
};
|
|
@@ -290,7 +324,7 @@ Press Ctrl+C to stop.
|
|
|
290
324
|
} catch (err) {
|
|
291
325
|
const message = err instanceof Error ? err.message : String(err);
|
|
292
326
|
if (message.includes("EADDRINUSE")) {
|
|
293
|
-
console.error(
|
|
327
|
+
console.error(formatPortInUseError(port));
|
|
294
328
|
} else {
|
|
295
329
|
console.error(`Startup failed: ${message}`);
|
|
296
330
|
}
|
|
@@ -306,11 +340,11 @@ configCmd.command("show").description("Show current configuration").action(() =>
|
|
|
306
340
|
console.log(JSON.stringify(config, null, 2));
|
|
307
341
|
});
|
|
308
342
|
program.command("stop").description("Stop the resident service and remove auto-start (reverse of start --daemon)").action(async () => {
|
|
309
|
-
const { serviceUninstall } = await import("./service-
|
|
343
|
+
const { serviceUninstall } = await import("./service-WCGGRZTA.mjs");
|
|
310
344
|
serviceUninstall();
|
|
311
345
|
});
|
|
312
346
|
program.command("status").description("Show resident service status").action(async () => {
|
|
313
|
-
const { getServiceStatus } = await import("./service-
|
|
347
|
+
const { getServiceStatus } = await import("./service-WCGGRZTA.mjs");
|
|
314
348
|
const svc = getServiceStatus();
|
|
315
349
|
console.log("\nChatLab Status");
|
|
316
350
|
console.log("\u2500".repeat(36));
|
|
@@ -415,4 +449,4 @@ if (isDirectRun) {
|
|
|
415
449
|
export {
|
|
416
450
|
run
|
|
417
451
|
};
|
|
418
|
-
//# sourceMappingURL=chunk-
|
|
452
|
+
//# sourceMappingURL=chunk-AHQQQ5HZ.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cli.ts","../src/http/port.ts"],"sourcesContent":["/**\n * ChatLab CLI entry point\n *\n * Dev: pnpm --filter chatlab-cli run cli -- sessions\n */\n\nimport * as fs from 'fs'\nimport { execSync } from 'child_process'\nimport { Command } from 'commander'\nimport { DEFAULT_API_PORT, loadConfig, getConfigPath } from '@openchatlab/config'\nimport {\n NodePathProvider,\n DatabaseManager,\n hasPendingElectronDataWarning,\n verifyCliDataPath,\n} from '@openchatlab/node-runtime'\nimport {\n getSessionMeta,\n getSessionOverview,\n getMemberActivity,\n searchMessagesLike,\n getMembers,\n executeReadonlySql,\n} from '@openchatlab/core'\nimport { getVersion } from './version'\nimport { resolveCliPath } from './paths'\nimport { isPortAvailable, formatPortInUseError } from './http/port'\n\nconst program = new Command()\n\nprogram.name('chatlab').description('ChatLab - Chat history analysis tool').version(getVersion(), '-v, --version')\n\nprogram.hook('preAction', async () => {\n const { checkForUpdatesInteractive } = await import('./update-checker')\n await checkForUpdatesInteractive()\n})\n\nprogram\n .command('sessions')\n .description('List all imported chat sessions')\n .option('--format <format>', 'Output format (table|json)', 'table')\n .action((options) => {\n const { dbManager } = initRuntime()\n const sessionIds = dbManager.listSessionIds()\n\n if (sessionIds.length === 0) {\n console.log('No chat sessions found.')\n console.log(`Data directory: ${dbManager['pathProvider'].getUserDataDir()}`)\n dbManager.closeAll()\n return\n }\n\n const sessions = sessionIds\n .map((id) => {\n const db = dbManager.open(id)\n if (!db) return null\n const meta = getSessionMeta(db)\n if (!meta) return null\n const overview = getSessionOverview(db)\n return { id, ...meta, ...overview }\n })\n .filter(Boolean)\n\n if (options.format === 'json') {\n console.log(JSON.stringify(sessions, null, 2))\n } else {\n console.log(`${sessions.length} session(s) found:\\n`)\n for (const s of sessions) {\n if (!s) continue\n const timeRange = formatTimeRange(s.firstMessageTs, s.lastMessageTs)\n console.log(` ${s.name}`)\n console.log(` ID: ${s.id}`)\n console.log(\n ` Platform: ${s.platform} | Type: ${s.type} | Members: ${s.totalMembers} | Messages: ${s.totalMessages}`\n )\n if (timeRange) console.log(` Range: ${timeRange}`)\n console.log()\n }\n }\n\n dbManager.closeAll()\n })\n\nprogram\n .command('stats <session-id>')\n .description('Show session statistics overview')\n .option('--format <format>', 'Output format (table|json)', 'table')\n .option('--top <n>', 'Show top N active members', '10')\n .action((sessionId, options) => {\n const { dbManager } = initRuntime()\n const db = dbManager.open(sessionId)\n if (!db) {\n console.error(`Session ${sessionId} not found`)\n process.exit(1)\n }\n\n const meta = getSessionMeta(db)\n const overview = getSessionOverview(db)\n const topMembers = getMemberActivity(db).slice(0, parseInt(options.top))\n\n if (options.format === 'json') {\n console.log(JSON.stringify({ meta, overview, topMembers }, null, 2))\n } else {\n console.log(`\\nSession: ${meta?.name}`)\n console.log(`Platform: ${meta?.platform} | Type: ${meta?.type}`)\n console.log(`Total messages: ${overview.totalMessages}`)\n console.log(`Total members: ${overview.totalMembers}`)\n console.log(`Time range: ${formatTimeRange(overview.firstMessageTs, overview.lastMessageTs)}`)\n\n if (topMembers.length > 0) {\n console.log(`\\nActivity ranking (Top ${options.top}):`)\n for (const [i, m] of topMembers.entries()) {\n console.log(` ${i + 1}. ${m.name} - ${m.messageCount} messages (${m.percentage}%)`)\n }\n }\n }\n\n dbManager.closeAll()\n })\n\nprogram\n .command('search <session-id> <keyword>')\n .description('Search messages by keyword')\n .option('--limit <n>', 'Max results to return', '20')\n .option('--format <format>', 'Output format (table|json)', 'table')\n .action((sessionId, keyword, options) => {\n const { dbManager } = initRuntime()\n const db = dbManager.open(sessionId)\n if (!db) {\n console.error(`Session ${sessionId} not found`)\n process.exit(1)\n }\n\n const limit = parseInt(options.limit)\n const result = searchMessagesLike(db, keyword, { limit })\n\n if (options.format === 'json') {\n console.log(JSON.stringify(result, null, 2))\n } else {\n console.log(\n `Search \"${keyword}\" - ${result.total} result(s)${result.hasMore ? ' (showing first ' + limit + ')' : ''}:\\n`\n )\n for (const msg of result.messages) {\n const time = new Date(msg.timestamp * 1000).toLocaleString()\n console.log(` [${time}] ${msg.senderName}: ${msg.content}`)\n }\n }\n\n dbManager.closeAll()\n })\n\nprogram\n .command('members <session-id>')\n .description('List session members')\n .option('--format <format>', 'Output format (table|json)', 'table')\n .action((sessionId, options) => {\n const { dbManager } = initRuntime()\n const db = dbManager.open(sessionId)\n if (!db) {\n console.error(`Session ${sessionId} not found`)\n process.exit(1)\n }\n\n const members = getMembers(db)\n\n if (options.format === 'json') {\n console.log(JSON.stringify(members, null, 2))\n } else {\n console.log(`${members.length} member(s):\\n`)\n for (const [i, m] of members.entries()) {\n console.log(` ${i + 1}. ${m.name} (${m.platformId}) - ${m.messageCount} messages`)\n }\n }\n\n dbManager.closeAll()\n })\n\nprogram\n .command('query <session-id>')\n .description('Execute a read-only SQL query on a session database')\n .requiredOption('--sql <sql>', 'SQL query statement')\n .option('--format <format>', 'Output format (table|json)', 'table')\n .action((sessionId, options) => {\n const { dbManager } = initRuntime()\n const db = dbManager.open(sessionId)\n if (!db) {\n console.error(`Session ${sessionId} not found`)\n process.exit(1)\n }\n\n try {\n const result = executeReadonlySql(db, options.sql)\n if (options.format === 'json') {\n console.log(JSON.stringify(result, null, 2))\n } else {\n if (result.rows.length === 0) {\n console.log('No results.')\n } else {\n printTable(result.columns, result.rows)\n console.log(`\\n${result.rowCount} row(s)${result.truncated ? ' (truncated)' : ''}`)\n }\n }\n } catch (err) {\n console.error(`SQL error: ${err instanceof Error ? err.message : err}`)\n process.exit(1)\n }\n\n dbManager.closeAll()\n })\n\nprogram\n .command('import <file>')\n .description('Import a chat history file (14+ formats: QQ/WeChat/Telegram/WhatsApp/LINE/Discord/Instagram, etc.)')\n .option('--session-id <id>', 'Specify session ID (auto-generated if omitted)')\n .option('--format <id>', 'Specify format ID (skip auto-detection)')\n .action(async (file, options) => {\n if (!fs.existsSync(file)) {\n console.error(`File not found: ${file}`)\n process.exit(1)\n }\n\n const { streamImport, detectFormat } = await import('./import')\n const { dbManager } = initRuntime()\n const nativeBinding = resolveNativeBinding()\n\n const format = detectFormat(file)\n if (!format && !options.format) {\n console.error(`Unrecognized file format: ${file}`)\n console.error('Use --format <id> to specify manually, or run \"chatlab formats\" to see supported formats')\n process.exit(1)\n }\n\n console.log(`Importing: ${file}`)\n if (format) console.log(` Format: ${format.name} (${format.platform})`)\n\n try {\n const result = await streamImport(dbManager, file, {\n formatId: options.format,\n nativeBinding,\n onProgress: (p) => {\n process.stdout.write(`\\r ${p.stage}: ${p.progress}%`)\n },\n })\n\n if (result.success) {\n console.log(`\\n\\nImport succeeded!`)\n console.log(` Session ID: ${result.sessionId}`)\n console.log(` Messages written: ${result.diagnostics?.messagesWritten ?? 0}`)\n console.log(` Messages skipped: ${result.diagnostics?.messagesSkipped ?? 0}`)\n } else {\n console.error(`\\n\\nImport failed: ${result.error}`)\n process.exit(1)\n }\n } catch (err) {\n console.error(`\\n\\nImport error: ${err instanceof Error ? err.message : err}`)\n process.exit(1)\n } finally {\n dbManager.closeAll()\n }\n })\n\nprogram\n .command('formats')\n .description('List all supported chat history formats')\n .action(async () => {\n const { getSupportedFormats } = await import('./import')\n const formats = getSupportedFormats()\n console.log(`${formats.length} supported format(s):\\n`)\n for (const f of formats) {\n console.log(` ${f.id.padEnd(30)} ${f.name} (${f.platform}) [${f.extensions.join(', ')}]`)\n }\n })\n\nprogram\n .command('mcp')\n .description('Start MCP Server (stdio transport, for ClaudeCode / Cursor / AI agents)')\n .action(async () => {\n const { startCliMcpServer } = await import('./mcp')\n await startCliMcpServer()\n })\n\nprogram\n .command('start')\n .description('Start ChatLab (HTTP API + Web UI)')\n .option('--port <port>', 'Server port', String(DEFAULT_API_PORT))\n .option('--host <host>', 'Listen address', '127.0.0.1')\n .option('--token <token>', 'Custom Bearer Token (reads from config or auto-generates if omitted)')\n .option('--headless', 'API-only mode, do not serve the Web UI')\n .option('--no-open', 'Do not auto-open the browser')\n .option('--daemon', 'Run as a resident system service (auto-start on login, macOS/Linux)')\n .action(async (options) => {\n // --daemon: install as system service and exit\n if (options.daemon) {\n const { serviceInstall } = await import('./daemon/service')\n serviceInstall({\n port: parseInt(options.port, 10),\n host: options.host,\n token: options.token || undefined,\n headless: options.headless,\n })\n return\n }\n\n const { startHttpServer } = await import('./http')\n const port = parseInt(options.port, 10)\n\n let webRoot: string | undefined\n if (!options.headless) {\n const webDir = resolveCliPath('dist-web')\n if (fs.existsSync(webDir)) {\n webRoot = webDir\n } else {\n console.warn('Warning: dist-web/ not found, starting in API-only mode')\n }\n }\n\n try {\n // 启动前预检端口,快速失败,避免无谓的初始化后再报 EADDRINUSE;\n // 置于 try 内确保非 EADDRINUSE 错误(EACCES/EADDRNOTAVAIL 等)\n // 也能走到统一的 Startup failed 错误处理路径。\n if (!(await isPortAvailable(port, options.host))) {\n console.error(formatPortInUseError(port))\n process.exit(1)\n }\n\n const info = await startHttpServer({\n port,\n host: options.host,\n token: options.token || undefined,\n webRoot,\n })\n\n const { startPeriodicUpdateCheck } = await import('./update-checker')\n startPeriodicUpdateCheck()\n\n const displayHost = info.host === '0.0.0.0' ? '127.0.0.1' : info.host\n const url = `http://${displayHost}:${info.port}`\n\n console.log(`\\nChatLab v${getVersion()}`)\n if (webRoot) console.log(` Web UI: ${url}/`)\n console.log(` API: ${url}`)\n console.log(` Token: ${info.token}`)\n console.log(`\\nExample:`)\n console.log(` curl -H \"Authorization: Bearer ${info.token}\" ${url}/api/v1/status`)\n\n if (webRoot && options.open) {\n openBrowser(url)\n console.log(`\\nBrowser opened. Press Ctrl+C to stop.\\n`)\n } else {\n console.log(`\\nPress Ctrl+C to stop.\\n`)\n }\n\n const shutdown = async () => {\n console.log('\\nShutting down...')\n const { stopHttpServer } = await import('./http')\n await stopHttpServer()\n process.exit(0)\n }\n\n process.on('SIGINT', shutdown)\n process.on('SIGTERM', shutdown)\n } catch (err: unknown) {\n const message = err instanceof Error ? err.message : String(err)\n if (message.includes('EADDRINUSE')) {\n // 极低概率的 TOCTOU 竞态(预检通过后端口被占),复用统一文案\n console.error(formatPortInUseError(port))\n } else {\n console.error(`Startup failed: ${message}`)\n }\n process.exit(1)\n }\n })\n\nconst configCmd = program.command('config').description('Configuration management')\n\nconfigCmd\n .command('path')\n .description('Show config file path')\n .action(() => {\n console.log(getConfigPath())\n })\n\nconfigCmd\n .command('show')\n .description('Show current configuration')\n .action(() => {\n const config = loadConfig()\n console.log(JSON.stringify(config, null, 2))\n })\n\nprogram\n .command('stop')\n .description('Stop the resident service and remove auto-start (reverse of start --daemon)')\n .action(async () => {\n const { serviceUninstall } = await import('./daemon/service')\n serviceUninstall()\n })\n\nprogram\n .command('status')\n .description('Show resident service status')\n .action(async () => {\n const { getServiceStatus } = await import('./daemon/service')\n const svc = getServiceStatus()\n\n console.log('\\nChatLab Status')\n console.log('─'.repeat(36))\n\n if (svc.installed) {\n const portStr = svc.port ? `http://${svc.host ?? '127.0.0.1'}:${svc.port}` : ''\n console.log(` Service: ${svc.running ? 'running' : 'installed (not running)'}`)\n if (portStr) console.log(` Address: ${portStr}`)\n console.log(` Auto-start: enabled`)\n console.log(`\\n Use \\`chatlab stop\\` to remove the service.\\n`)\n } else {\n console.log(` Service: not installed`)\n console.log(` Auto-start: disabled`)\n console.log(`\\n Use \\`chatlab start --daemon\\` to install as a system service.\\n`)\n }\n })\n\n// --- 工具函数 ---\n\nfunction openBrowser(url: string): void {\n try {\n const cmd =\n process.platform === 'darwin'\n ? `open \"${url}\"`\n : process.platform === 'win32'\n ? `start \"\" \"${url}\"`\n : `xdg-open \"${url}\"`\n execSync(cmd, { stdio: 'ignore' })\n } catch {\n console.log(` Open manually: ${url}`)\n }\n}\n\n/**\n * Resolve standalone better-sqlite3 native module path.\n * Used in non-Electron environments to avoid electron-rebuild conflicts.\n */\nfunction resolveNativeBinding(): string | undefined {\n if (process.versions.electron) return undefined\n const nativePath = resolveCliPath('native/better_sqlite3.node')\n if (fs.existsSync(nativePath)) return nativePath\n return undefined\n}\n\nfunction initRuntime() {\n const config = loadConfig()\n const userDataDir = config.data.user_data_dir || undefined\n const pathProvider = new NodePathProvider(userDataDir)\n pathProvider.ensureAllDirs()\n\n if (hasPendingElectronDataWarning() || !verifyCliDataPath(pathProvider.getDatabaseDir())) {\n printElectronDataError()\n process.exit(1)\n }\n\n const nativeBinding = resolveNativeBinding()\n const dbManager = new DatabaseManager(pathProvider, { nativeBinding })\n return { config, pathProvider, dbManager }\n}\n\nfunction printElectronDataError(): void {\n console.error('\\n' + '='.repeat(68))\n console.error(' ChatLab: Electron desktop data not found')\n console.error('='.repeat(68))\n console.error('')\n console.error(' Detected that ChatLab desktop app was installed on this machine,')\n console.error(' but could not locate your chat databases.')\n console.error('')\n console.error(' This usually means you changed the data directory in desktop settings.')\n console.error('')\n console.error(' To fix this, choose one of:')\n console.error('')\n console.error(' 1. Open ChatLab desktop app — it will auto-migrate your data')\n console.error(' 2. Set the data directory manually:')\n console.error(' export CHATLAB_DATA_DIR=\"/path/to/your/data\"')\n console.error(' 3. Edit ~/.chatlab/config.toml:')\n console.error(' [data]')\n console.error(' user_data_dir = \"/path/to/your/data\"')\n console.error('')\n console.error('='.repeat(68) + '\\n')\n}\n\nfunction formatTimeRange(first: number | null, last: number | null): string {\n if (!first || !last) return 'Unknown'\n const from = new Date(first * 1000).toLocaleDateString()\n const to = new Date(last * 1000).toLocaleDateString()\n return `${from} ~ ${to}`\n}\n\nfunction printTable(columns: string[], rows: Record<string, unknown>[]): void {\n const widths = columns.map((col) => {\n const maxData = rows.reduce((max, row) => {\n const val = String(row[col] ?? '')\n return Math.max(max, val.length)\n }, 0)\n return Math.max(col.length, Math.min(maxData, 40))\n })\n\n const header = columns.map((col, i) => col.padEnd(widths[i])).join(' | ')\n const separator = widths.map((w) => '-'.repeat(w)).join('-+-')\n console.log(header)\n console.log(separator)\n\n for (const row of rows) {\n const line = columns\n .map((col, i) => {\n const val = String(row[col] ?? '')\n return val.length > 40 ? val.slice(0, 37) + '...' : val.padEnd(widths[i])\n })\n .join(' | ')\n console.log(line)\n }\n}\n\n/** CLI entry function */\nexport function run(argv?: string[]): void {\n program.parse(argv)\n}\n\n// Auto-execute when run directly as a script\nconst isDirectRun = process.argv[1]?.endsWith('cli.ts') || process.argv[1]?.endsWith('cli.js')\nif (isDirectRun) {\n run()\n}\n","/**\n * 端口可用性检测与错误文案\n */\n\nimport * as net from 'net'\n\n/**\n * 检测指定端口在给定 host 上是否可用。\n * 使用 net.createServer() 试探性绑定,无副作用(成功后立即释放)。\n */\nexport function isPortAvailable(port: number, host: string): Promise<boolean> {\n return new Promise((resolve, reject) => {\n const server = net.createServer()\n server.once('error', (err: NodeJS.ErrnoException) => {\n if (err.code === 'EADDRINUSE') {\n resolve(false)\n } else {\n reject(err)\n }\n })\n server.once('listening', () => server.close(() => resolve(true)))\n server.listen(port, host)\n })\n}\n\n/**\n * 返回端口被占用时统一的友好报错文案。\n */\nexport function formatPortInUseError(port: number): string {\n return [\n ``,\n ` ✖ Error: port ${port} is already in use.`,\n ``,\n ` Another process (possibly a ChatLab instance) is using this port. You can:`,\n ` • Use another port: chatlab start --port <port>`,\n ` • Find the process: lsof -iTCP:${port} -sTCP:LISTEN`,\n ``,\n ].join('\\n')\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,YAAY,QAAQ;AACpB,SAAS,gBAAgB;AACzB,SAAS,eAAe;;;ACJxB,YAAY,SAAS;AAMd,SAAS,gBAAgB,MAAc,MAAgC;AAC5E,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,UAAM,SAAa,iBAAa;AAChC,WAAO,KAAK,SAAS,CAAC,QAA+B;AACnD,UAAI,IAAI,SAAS,cAAc;AAC7B,gBAAQ,KAAK;AAAA,MACf,OAAO;AACL,eAAO,GAAG;AAAA,MACZ;AAAA,IACF,CAAC;AACD,WAAO,KAAK,aAAa,MAAM,OAAO,MAAM,MAAM,QAAQ,IAAI,CAAC,CAAC;AAChE,WAAO,OAAO,MAAM,IAAI;AAAA,EAC1B,CAAC;AACH;AAKO,SAAS,qBAAqB,MAAsB;AACzD,SAAO;AAAA,IACL;AAAA,IACA,wBAAmB,IAAI;AAAA,IACvB;AAAA,IACA;AAAA,IACA;AAAA,IACA,6CAAwC,IAAI;AAAA,IAC5C;AAAA,EACF,EAAE,KAAK,IAAI;AACb;;;ADVA,IAAM,UAAU,IAAI,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IAAI,MAAM;AAClB,UAAQ,IAAI,SAAS;AAErB,aAAW,OAAO,MAAM;AACtB,UAAM,OAAO,QACV,IAAI,CAAC,KAAK,MAAM;AACf,YAAM,MAAM,OAAO,IAAI,GAAG,KAAK,EAAE;AACjC,aAAO,IAAI,SAAS,KAAK,IAAI,MAAM,GAAG,EAAE,IAAI,QAAQ,IAAI,OAAO,OAAO,CAAC,CAAC;AAAA,IAC1E,CAAC,EACA,KAAK,KAAK;AACb,YAAQ,IAAI,IAAI;AAAA,EAClB;AACF;AAGO,SAAS,IAAI,MAAuB;AACzC,UAAQ,MAAM,IAAI;AACpB;AAGA,IAAM,cAAc,QAAQ,KAAK,CAAC,GAAG,SAAS,QAAQ,KAAK,QAAQ,KAAK,CAAC,GAAG,SAAS,QAAQ;AAC7F,IAAI,aAAa;AACf,MAAI;AACN;","names":[]}
|
|
@@ -2900,6 +2900,32 @@ function registerPreferencesRoutes(server2, pathProvider) {
|
|
|
2900
2900
|
});
|
|
2901
2901
|
}
|
|
2902
2902
|
|
|
2903
|
+
// src/http/routes/proxy.ts
|
|
2904
|
+
var PROXY_TARGET = "https://chatlab.fun";
|
|
2905
|
+
function registerProxyRoutes(server2) {
|
|
2906
|
+
server2.get("/_proxy/chatlab.fun/*", async (request, reply) => {
|
|
2907
|
+
const subPath = request.params["*"] ?? "";
|
|
2908
|
+
const queryString = new URLSearchParams(
|
|
2909
|
+
request.query
|
|
2910
|
+
).toString();
|
|
2911
|
+
const targetUrl = queryString ? `${PROXY_TARGET}/${subPath}?${queryString}` : `${PROXY_TARGET}/${subPath}`;
|
|
2912
|
+
try {
|
|
2913
|
+
const upstream = await fetch(targetUrl, {
|
|
2914
|
+
headers: { Accept: request.headers.accept ?? "*/*" },
|
|
2915
|
+
signal: AbortSignal.timeout(1e4)
|
|
2916
|
+
});
|
|
2917
|
+
const contentType = upstream.headers.get("content-type") ?? "application/octet-stream";
|
|
2918
|
+
const body = Buffer.from(await upstream.arrayBuffer());
|
|
2919
|
+
reply.code(upstream.status).header("content-type", contentType).send(body);
|
|
2920
|
+
} catch (err) {
|
|
2921
|
+
reply.code(502).send({
|
|
2922
|
+
error: "Proxy error",
|
|
2923
|
+
message: err instanceof Error ? err.message : String(err)
|
|
2924
|
+
});
|
|
2925
|
+
}
|
|
2926
|
+
});
|
|
2927
|
+
}
|
|
2928
|
+
|
|
2903
2929
|
// ../../packages/sync/src/types.ts
|
|
2904
2930
|
var noop = () => {
|
|
2905
2931
|
};
|
|
@@ -3835,6 +3861,7 @@ async function startHttpServer(options) {
|
|
|
3835
3861
|
initSync(server, dbManager, pathProvider, { port, host, token });
|
|
3836
3862
|
if (options?.webRoot && fs14.existsSync(options.webRoot)) {
|
|
3837
3863
|
setWebMode(true);
|
|
3864
|
+
registerProxyRoutes(server);
|
|
3838
3865
|
const fastifyStatic = await import("@fastify/static");
|
|
3839
3866
|
await server.register(fastifyStatic.default, {
|
|
3840
3867
|
root: options.webRoot,
|
|
@@ -3878,4 +3905,4 @@ export {
|
|
|
3878
3905
|
startHttpServer,
|
|
3879
3906
|
stopHttpServer
|
|
3880
3907
|
};
|
|
3881
|
-
//# sourceMappingURL=chunk-
|
|
3908
|
+
//# sourceMappingURL=chunk-L37WJ33K.mjs.map
|