xshat-lite 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 ADDED
@@ -0,0 +1,211 @@
1
+ # XShat
2
+
3
+ 一个基于浏览器自动化的命令行 AI 聊天工具。
4
+
5
+ 它的核心抽象只有四步:
6
+
7
+ 1. 输入
8
+ 2. 发送
9
+ 3. 读取
10
+ 4. 完成
11
+
12
+ 也就是说,想适配新网站时,重点不是改主流程,而是给这个网站补一份四步配置。
13
+
14
+ ## 当前内置站点
15
+
16
+ - Duck.ai
17
+ - HuggingChat
18
+ - DeepAI Chat
19
+ - Qwen
20
+ - You.com
21
+ - Microsoft Copilot
22
+ - ChatGPT
23
+ - Gemini
24
+
25
+ 其中前四个更偏向免登录或可直接访问;后两个是否能直接使用,取决于地区、配额和站点当时策略。
26
+
27
+ ## 安装
28
+
29
+ ```bash
30
+ npm install
31
+ ```
32
+
33
+ 全局安装:
34
+
35
+ ```bash
36
+ npm install -g xshat-lite
37
+ ```
38
+
39
+ 本地调试全局命令:
40
+
41
+ ```bash
42
+ npm link
43
+ ```
44
+
45
+ 如果你是在当前项目目录里本地试装,也可以:
46
+
47
+ ```bash
48
+ npm install -g .
49
+ ```
50
+
51
+ ## 运行
52
+
53
+ ```bash
54
+ xshat
55
+ ```
56
+
57
+ 开发模式:
58
+
59
+ ```bash
60
+ npm run dev
61
+ ```
62
+
63
+ 调试模式:
64
+
65
+ ```bash
66
+ XSHAT_DEBUG=true npm start
67
+ ```
68
+
69
+ 如果你还没有全局安装,也可以继续用:
70
+
71
+ ```bash
72
+ npm start
73
+ ```
74
+
75
+ ## 配置
76
+
77
+ 创建 `.env`:
78
+
79
+ ```env
80
+ DEFAULT_PROVIDER=gemini
81
+ BROWSER_HEADLESS=true
82
+ USER_DATA_DIR=./runtime/profiles/my-profile
83
+ SESSION_DIR=./runtime/sessions
84
+ LOG_DIR=./runtime/logs
85
+ ```
86
+
87
+ 全局命令模式下,运行时数据默认写入:
88
+
89
+ - Windows: `%LOCALAPPDATA%\\xshat`
90
+ - macOS / Linux: `~/.xshat`
91
+
92
+ 其中会包含:
93
+
94
+ - `runtime/profiles`
95
+ - `runtime/sessions`
96
+ - `runtime/logs`
97
+
98
+ 也可以自己指定:
99
+
100
+ ```bash
101
+ XSHAT_HOME=D:\\my-xshat xshat
102
+ ```
103
+
104
+ ## 如何扩展新网站
105
+
106
+ 在 [src/config/default.mjs](/d:/node/example/xshat/src/config/default.mjs) 里新增一个 provider。
107
+
108
+ 结构大致是:
109
+
110
+ ```js
111
+ {
112
+ id: 'mychat',
113
+ name: 'My Chat',
114
+ url: 'https://example.com/chat',
115
+ steps: {
116
+ input: {
117
+ selectors: ['textarea', '[contenteditable="true"]']
118
+ },
119
+ send: {
120
+ selectors: ['button[type="submit"]', 'button[aria-label*="Send"]']
121
+ },
122
+ read: {
123
+ selectors: ['.assistant-message', '.message.bot']
124
+ },
125
+ complete: {
126
+ mode: 'script',
127
+ script: '...',
128
+ selectors: {
129
+ response: ['.assistant-message', '.message.bot'],
130
+ pending: ['.streaming', '.loading'],
131
+ done: ['.copy-button', '.finished']
132
+ }
133
+ }
134
+ }
135
+ }
136
+ ```
137
+
138
+ ## 四步说明
139
+
140
+ `input`
141
+
142
+ - 找输入框
143
+ - 点击并聚焦
144
+ - 清空旧内容
145
+ - 粘贴消息
146
+
147
+ `send`
148
+
149
+ - 找发送按钮点击
150
+ - 如果没配到按钮,退回 `Enter`
151
+
152
+ `read`
153
+
154
+ - 定义“助手回复节点”的候选选择器
155
+
156
+ `complete`
157
+
158
+ - 判断是否还在生成
159
+ - 判断是否已经完成
160
+ - 返回当前累计文本
161
+
162
+ ## 调试命令
163
+
164
+ 聊天时可输入:
165
+
166
+ - `/inspect`:打印当前网站命中的输入框、发送按钮、读取节点和完成状态
167
+ - `/config`:打开系统设置并调整默认提供方
168
+ - `/model`:打开系统设置中的提供方配置
169
+ - `/menu`:返回主菜单
170
+
171
+ 逐 provider smoke:
172
+
173
+ ```bash
174
+ SMOKE_PROVIDER=gemini node --env-file=.env scripts/provider-smoke.mjs
175
+ ```
176
+
177
+ 多轮 smoke:
178
+
179
+ ```bash
180
+ SMOKE_PROVIDER=gemini SMOKE_PROMPTS="你好,请只回复1|继续,只回复2" node --env-file=.env scripts/provider-smoke.mjs
181
+ ```
182
+
183
+ 导出调试产物(HTML、截图、结果 JSON):
184
+
185
+ ```bash
186
+ SMOKE_PROVIDER=gemini SMOKE_SAVE_ARTIFACTS=true node --env-file=.env scripts/provider-smoke.mjs
187
+ ```
188
+
189
+ ## 项目结构
190
+
191
+ ```text
192
+ src/
193
+ config/
194
+ default.mjs
195
+ modules/
196
+ browser.mjs
197
+ chat.mjs
198
+ logger.mjs
199
+ session.mjs
200
+ ui.mjs
201
+ utils/
202
+ config.mjs
203
+ index.mjs
204
+ ```
205
+
206
+ ## 备注
207
+
208
+ - 不同网站 DOM 变动很频繁,所以选择器最好准备多个候选。
209
+ - 某些网站首页可打开,但真正发送消息时仍可能弹登录、限流或地区限制。
210
+ - 当前这套架构已经支持继续扩站,后续新增网站通常只需要补配置,不需要改主循环。
211
+ - 发布 npm 包时,运行时数据目录不会被一起打包。
package/bin/xshat.mjs ADDED
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { existsSync } from 'node:fs';
4
+ import { homedir } from 'node:os';
5
+ import { resolve } from 'node:path';
6
+ import process from 'node:process';
7
+ import dotenv from 'dotenv';
8
+
9
+ function getDefaultAppHome() {
10
+ if (process.platform === 'win32') {
11
+ const base = process.env.LOCALAPPDATA || process.env.APPDATA || homedir();
12
+ return resolve(base, 'xshat');
13
+ }
14
+
15
+ return resolve(homedir(), '.xshat');
16
+ }
17
+
18
+ function loadEnvFile(path, override = false) {
19
+ if (!existsSync(path)) {
20
+ return;
21
+ }
22
+
23
+ dotenv.config({
24
+ path,
25
+ override
26
+ });
27
+ }
28
+
29
+ if (!process.env.XSHAT_HOME) {
30
+ process.env.XSHAT_HOME = getDefaultAppHome();
31
+ }
32
+
33
+ loadEnvFile(resolve(process.env.XSHAT_HOME, '.env'));
34
+ loadEnvFile(resolve(process.cwd(), '.env'), true);
35
+
36
+ await import('../src/index.mjs');
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "xshat-lite",
3
+ "version": "1.0.0",
4
+ "description": "CLI chat and agent tool powered by free AI web providers",
5
+ "type": "module",
6
+ "main": "src/index.mjs",
7
+ "bin": {
8
+ "xshat": "./bin/xshat.mjs"
9
+ },
10
+ "files": [
11
+ "bin",
12
+ "src/config",
13
+ "src/modules",
14
+ "src/utils",
15
+ "src/index.mjs",
16
+ "README.md"
17
+ ],
18
+ "scripts": {
19
+ "start": "node ./bin/xshat.mjs",
20
+ "dev": "node --watch ./bin/xshat.mjs",
21
+ "lint": "eslint \"src/**/*.mjs\" \"test/**/*.mjs\"",
22
+ "test": "node --test",
23
+ "check": "node --check ./bin/xshat.mjs && node --check ./src/index.mjs && node --check ./src/utils/config.mjs",
24
+ "prepublishOnly": "npm run check && npm test && npm pack --dry-run",
25
+ "format": "prettier --write \"src/**/*.mjs\" \"test/**/*.mjs\"",
26
+ "format:check": "prettier --check \"src/**/*.mjs\" \"test/**/*.mjs\""
27
+ },
28
+ "keywords": [
29
+ "chat",
30
+ "ai",
31
+ "cli",
32
+ "agent",
33
+ "browser-automation",
34
+ "gemini",
35
+ "chatgpt",
36
+ "duckai",
37
+ "web-ai"
38
+ ],
39
+ "author": "",
40
+ "license": "ISC",
41
+ "preferGlobal": true,
42
+ "dependencies": {
43
+ "@inquirer/prompts": "^8.5.2",
44
+ "cli-table3": "^0.6.5",
45
+ "cloakbrowser": "^0.4.10",
46
+ "dotenv": "^16.4.5",
47
+ "marked": "^15.0.12",
48
+ "marked-terminal": "^7.3.0",
49
+ "ora": "^9.4.1",
50
+ "string-width": "^8.2.1",
51
+ "yoctocolors": "^2.1.2"
52
+ },
53
+ "devDependencies": {
54
+ "eslint": "^9.0.0",
55
+ "prettier": "^3.3.0"
56
+ },
57
+ "engines": {
58
+ "node": ">=18.0.0"
59
+ }
60
+ }