tg-agent 1.2.2 → 1.2.5

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.
Files changed (3) hide show
  1. package/README.cn.md +203 -0
  2. package/README.md +128 -89
  3. package/package.json +2 -2
package/README.cn.md ADDED
@@ -0,0 +1,203 @@
1
+ # tg-agent
2
+
3
+ 一个在本地运行的 Telegram 机器人,支持多家 LLM 提供商(Codex、Claude Code、Antigravity 等),支持账号登录(OAuth)和 API 密钥认证。处理对话、工具调用与会话管理,支持多会话、会话持久化、/stop 中断、工具状态回写,适合在 macOS 上长期运行。
4
+
5
+ ## 功能
6
+
7
+ - Telegram 私聊与群组交互(支持论坛话题)
8
+ - 多会话管理:/new /list /use /close /reset
9
+ - 会话持久化:默认保存到 `~/.tg-agent/tg-sessions`
10
+ - 运行中可取消:/stop
11
+ - 自动 Markdown 渲染:优先 MarkdownV2,失败回退 Markdown,再回退纯文本
12
+ - 多 Provider / 多 Model 选择(支持 Codex / antigravity / Gemini CLI 等)
13
+ - OAuth 登录与注销(/login, /logout)
14
+ - 工具调用:内置 `fetch`,可选 MCP(HTTP/stdio)
15
+ - 多媒体文件支持:图片、文档、音频、视频、语音、视频笔记
16
+ - 代理支持:模型与工具请求可分别配置
17
+ - 工作区管理:可为不同聊天设置独立工作目录
18
+
19
+ ## 快速开始
20
+
21
+ 1) 全局安装
22
+
23
+ ```bash
24
+ npm install -g tg-agent
25
+ ```
26
+
27
+ 2) 运行
28
+
29
+ ```bash
30
+ tg-agent
31
+ ```
32
+
33
+ 首次运行会提示输入 `telegram.bot_token`,并写入到 `~/.tg-agent/config.toml`。
34
+
35
+ 3) 配置文件(可选)
36
+
37
+ 你可以手动创建或编辑 `~/.tg-agent/config.toml`,最小示例如下:
38
+
39
+ ```toml
40
+ [telegram]
41
+ bot_token = "YOUR_BOT_TOKEN"
42
+ ```
43
+
44
+ ## 使用说明
45
+
46
+ 在 Telegram 中发送以下命令:
47
+
48
+ ### 会话管理
49
+
50
+ - `/new [title]` - 创建新会话
51
+ - `/list` - 列出所有会话
52
+ - `/use <id>` - 切换到指定会话
53
+ - `/close [id]` - 关闭会话(默认关闭当前会话)
54
+ - `/reset` - 清空当前会话历史
55
+ - `/stop` - 终止当前正在处理的请求
56
+
57
+ ### 模型与 Provider
58
+
59
+ - `/providers` - 列出所有可用的 Provider
60
+ - `/models [provider]` - 列出指定 Provider 的模型(不指定则显示当前会话的 Provider)
61
+ - `/provider <name>` - 设置当前会话的 Provider
62
+ - `/model <provider>/<model>` - 设置当前会话的模型
63
+
64
+ ### 工作区与工具
65
+
66
+ - `/workspace [path]` - 查看或设置当前会话的工作区目录
67
+ - `/mcp` - 查看 MCP 服务器与连接状态
68
+ - `/mcp refresh` - 刷新 MCP 目录
69
+ - `/status` - 查看当前会话的模型和工作区设置
70
+
71
+ ### 认证
72
+
73
+ - `/login <provider>` - OAuth 登录到指定 Provider
74
+ - `/logout <provider>` - 退出指定 Provider 的登录
75
+
76
+ ### 帮助
77
+
78
+ - `/start` 或 `/help` - 显示命令帮助
79
+
80
+ **注意**:默认仅支持私聊(DM)。如需在群组中使用,请配置 `telegram.allowed_user_ids` 白名单。
81
+
82
+ ### 图片与文件
83
+
84
+ - 直接发送图片、文档、音频、视频、语音或视频笔记给机器人,文件会保存到 `~/.tg-agent/uploads`,并自动附加到提示词中
85
+ - 图片会作为多模态输入传给模型(若模型支持图像)
86
+ - Agent 可使用 `send_photo` / `send_file` 工具把本地文件发回 Telegram(路径需在工作目录或 uploads 下)
87
+
88
+ ## 配置文件
89
+
90
+ 所有配置统一放在 `~/.tg-agent/config.toml`。首次启动会提示输入 `telegram.bot_token`,其余字段使用默认值。
91
+
92
+ ### 完整配置示例
93
+
94
+ ```toml
95
+ [telegram]
96
+ bot_token = "YOUR_BOT_TOKEN"
97
+ allowed_user_ids = ["123456789"]
98
+ parse_mode = ""
99
+
100
+ [model]
101
+ provider = "openai-codex"
102
+ model = "gpt-5.2"
103
+ openai_api_key = ""
104
+
105
+ [paths]
106
+ workspace_dir = ""
107
+ session_dir = "~/.tg-agent/tg-sessions"
108
+
109
+ [workspace_mappings]
110
+ # 为特定聊天 ID 设置独立工作区
111
+ # "-123456789" = "~/projects/project-a"
112
+
113
+ [limits]
114
+ max_sessions = 5
115
+ max_concurrent = 5
116
+ max_history_messages = 40
117
+ max_output_tokens = 0
118
+
119
+ [timeouts]
120
+ model_timeout_ms = 60000
121
+ model_timeout_stream_ms = 300000
122
+ fetch_timeout_ms = 60000
123
+
124
+ [fetch]
125
+ max_bytes = 200000
126
+ proxy_url = ""
127
+
128
+ [proxy]
129
+ url = ""
130
+
131
+ [auth]
132
+ codex_home = "~/.codex"
133
+
134
+ [logging]
135
+ agent_events = true
136
+ agent_stream = true
137
+
138
+ [system]
139
+ prompt = "You are running in user's personal computer or VPS, using telegram bot to interact with user. Be concise and practical."
140
+
141
+ [tls]
142
+ extra_ca_certs = ""
143
+ reject_unauthorized = ""
144
+ ```
145
+
146
+ ### 配置说明
147
+
148
+ - `telegram.allowed_user_ids`: 允许使用机器人的用户 ID 列表(空列表表示允许所有用户)
149
+ - `paths.workspace_dir`: 默认工作区目录
150
+ - `workspace_mappings`: 为特定聊天 ID 设置独立工作区(键为字符串格式的聊天 ID)
151
+ - `limits.max_sessions`: 每个聊天最多保留的会话数
152
+ - `limits.max_concurrent`: 最大并发请求数
153
+ - `limits.max_history_messages`: 每个会话最多保留的历史消息数
154
+ - `timeouts`: 各种操作的超时时间(毫秒)
155
+ - `fetch.max_bytes`: fetch 工具下载文件的最大字节数
156
+ - `tls.extra_ca_certs`: 额外的 CA 证书文件路径
157
+ - `tls.reject_unauthorized`: 是否拒绝未授权的 TLS 证书(空字符串表示使用系统默认)
158
+
159
+ ## Codex 认证
160
+
161
+ 优先使用本机 Codex OAuth 凭据(`codex login` 写入的配置)。
162
+ 也可以在 Telegram 内执行 `/login openai-codex`,将凭据保存到 `~/.tg-agent/auth.json`。
163
+ 如果运行时提示缺少权限或无法找到凭据,请重新执行:
164
+
165
+ ```bash
166
+ codex login
167
+ ```
168
+
169
+ ## MCP 配置
170
+
171
+ 在同一个 `~/.tg-agent/config.toml` 中添加 MCP 服务器:
172
+
173
+ ```toml
174
+ [mcp_servers.context7]
175
+ type = "stdio"
176
+ command = "npx"
177
+ args = ["-y", "@upstash/context7-mcp@latest"]
178
+
179
+ [mcp_servers.Notion]
180
+ url = "https://mcp.notion.com/mcp"
181
+ ```
182
+
183
+ 支持两种类型的 MCP 服务器:
184
+ - `stdio`: 通过标准输入输出通信(使用 `command` 和 `args`)
185
+ - HTTP: 通过 HTTP 请求通信(使用 `url`)
186
+
187
+ ## Skills 配置
188
+
189
+ 将 Skills 放到 `~/.tg-agent/skills` 文件夹,程序就会自动发现。
190
+
191
+ ## 常见问题
192
+
193
+ - `Bad Request: can't parse entities`: 说明文本不符合 MarkdownV2 规则,当前实现会自动降级到 Markdown 或纯文本。
194
+ - `No Codex OAuth credentials found`: 执行 `codex login` 或使用 `/login openai-codex`。
195
+ - `insufficient permissions`: 检查组织/项目权限或 OAuth scope。
196
+ - 网络错误:检查代理配置与 TLS 证书设置。
197
+ - 文件上传失败:检查 `~/.tg-agent/uploads` 目录权限。
198
+
199
+ ## 安全说明
200
+
201
+ - 不要提交 `~/.tg-agent/config.toml` 到仓库
202
+ - 建议开启 `telegram.allowed_user_ids` 白名单,限制可访问的用户
203
+ - 敏感信息(如 API keys)存储在配置文件中,请妥善保管
package/README.md CHANGED
@@ -1,84 +1,95 @@
1
1
  # tg-agent
2
2
 
3
- 一个在本地运行的 Telegram DM 机器人,用 Codex 账号驱动的 agent 来处理对话、工具调用与会话管理。支持多会话、会话持久化、/stop 中断、工具状态回写,适合在 macOS 上长期跑。
3
+ A locally running Telegram bot that supports multiple LLM providers (Codex, Claude Code, Antigravity, etc.) with both account login (OAuth) and API key authentication. Handles conversations, tool calls, and session management. Supports multiple sessions, session persistence, `/stop` cancellation, and tool status updates. Suitable for long-term running on macOS.
4
4
 
5
- ## 功能
5
+ ## Features
6
6
 
7
- - Telegram DM 交互(仅私聊)
8
- - 多会话管理:/new /list /use /close /reset
9
- - 会话持久化:默认保存到 `~/.tg-agent/tg-sessions`
10
- - 运行中可取消:/stop
11
- - 自动 Markdown 渲染:优先 MarkdownV2,失败回退 Markdown,再回退纯文本
12
- - Provider / Model 选择(支持 Codex / antigravity / Gemini CLI 等)
13
- - OAuth 登录与注销(/login, /logout
14
- - 工具调用:内置 `fetch`,可选 MCPHTTP/stdio
15
- - 图片/文件上传与发送(Telegram 附件、`send_photo`/`send_file` 工具)
16
- - 代理支持:模型与工具请求可分别配置
7
+ - Telegram private chat and group interactions (supports forum topics)
8
+ - Multi-session management: /new /list /use /close /reset
9
+ - Session persistence: saved to `~/.tg-agent/tg-sessions` by default
10
+ - Cancellable during execution: /stop
11
+ - Automatic Markdown rendering: prefers MarkdownV2, falls back to Markdown, then plain text
12
+ - Multiple Provider / Model selection (supports Codex / antigravity / Gemini CLI, etc.)
13
+ - OAuth login and logout (/login, /logout)
14
+ - Tool calls: built-in `fetch`, optional MCP (HTTP/stdio)
15
+ - Multimedia file support: images, documents, audio, video, voice, video notes
16
+ - Proxy support: model and tool requests can be configured separately
17
+ - Workspace management: set independent working directories for different chats
17
18
 
18
- ## 快速开始
19
+ ## Quick Start
19
20
 
20
- 1) 安装依赖
21
+ 1. Install globally
21
22
 
22
23
  ```bash
23
- npm install
24
+ npm install -g tg-agent
24
25
  ```
25
26
 
26
- 2) 配置文件(可选)
27
+ 2. Run
27
28
 
28
- 你可以手动创建 `~/.tg-agent/config.toml`,最小示例如下:
29
+ ```bash
30
+ tg-agent
31
+ ```
32
+
33
+ On first run, you'll be prompted to enter `telegram.bot_token` which will be written to `~/.tg-agent/config.toml`.
34
+
35
+ 3. Configuration (optional)
36
+
37
+ You can manually create or edit `~/.tg-agent/config.toml` with a minimal example:
29
38
 
30
39
  ```toml
31
40
  [telegram]
32
41
  bot_token = "YOUR_BOT_TOKEN"
33
42
  ```
34
43
 
35
- 3) 运行
44
+ ## Usage
36
45
 
37
- ```bash
38
- npm run dev
39
- ```
46
+ Send the following commands in Telegram:
40
47
 
41
- 首次运行会提示输入 `telegram.bot_token` 并写入配置文件。
48
+ ### Session Management
42
49
 
43
- 或构建后运行:
50
+ - `/new [title]` - Create a new session
51
+ - `/list` - List all sessions
52
+ - `/use <id>` - Switch to a specific session
53
+ - `/close [id]` - Close a session (defaults to current session)
54
+ - `/reset` - Clear current session history
55
+ - `/stop` - Cancel the currently processing request
44
56
 
45
- ```bash
46
- npm run build
47
- npm start
48
- ```
57
+ ### Models and Providers
58
+
59
+ - `/providers` - List all available providers
60
+ - `/models [provider]` - List models for a provider (shows current session's provider if not specified)
61
+ - `/provider <name>` - Set the provider for current session
62
+ - `/model <provider>/<model>` - Set the model for current session
49
63
 
50
- ## 使用说明
64
+ ### Workspace and Tools
51
65
 
52
- Telegram 私聊中发送:
66
+ - `/workspace [path]` - View or set the workspace directory for current session
67
+ - `/mcp` - View MCP servers and connection status
68
+ - `/mcp refresh` - Refresh MCP catalog
69
+ - `/status` - View current session's model and workspace settings
53
70
 
54
- - `/new [title]` 创建会话
55
- - `/list` 列出会话
56
- - `/use <id>` 切换会话
57
- - `/close [id]` 关闭会话
58
- - `/reset` 清空当前会话历史
59
- - `/stop` 终止当前正在处理的请求
60
- - `/providers` 列出可用 Provider
61
- - `/models [provider]` 列出模型
62
- - `/provider <name>` 设置当前会话 Provider
63
- - `/model <provider>/<model>` 设置当前会话模型
64
- - `/mcp` 查看 MCP 服务器与连接状态
65
- - `/status` 查看当前会话模型设置
66
- - `/login <provider>` OAuth 登录
67
- - `/logout <provider>` 退出登录
71
+ ### Authentication
68
72
 
69
- 默认仅支持私聊(DM)。
73
+ - `/login <provider>` - OAuth login to a provider
74
+ - `/logout <provider>` - Logout from a provider
70
75
 
71
- ### 图片与文件
76
+ ### Help
72
77
 
73
- - 直接发送图片或文件给机器人,会保存到 `~/.tg-agent/uploads`,并自动附加到提示词中。
74
- - 图片会作为多模态输入传给模型(若模型支持图像)。
75
- - Agent 可使用 `send_photo` / `send_file` 工具把本地文件发回 Telegram(路径需在工作目录或 uploads 下)。
78
+ - `/start` or `/help` - Show command help
76
79
 
77
- ## 配置文件
80
+ **Note**: By default, only private chats (DM) are supported. To use in groups, configure `telegram.allowed_user_ids` whitelist.
78
81
 
79
- 所有配置统一放在 `~/.tg-agent/config.toml`。首次启动会提示输入 `telegram.bot_token`,其余字段使用默认值。
82
+ ### Images and Files
80
83
 
81
- 常用字段示例:
84
+ - Send images, documents, audio, video, voice, or video notes directly to the bot. Files are saved to `~/.tg-agent/uploads` and automatically attached to the prompt
85
+ - Images are passed as multimodal input to the model (if the model supports images)
86
+ - Agent can use `send_photo` / `send_file` tools to send local files back to Telegram (paths must be in workspace directory or uploads folder)
87
+
88
+ ## Configuration
89
+
90
+ All configuration is stored in `~/.tg-agent/config.toml`. On first startup, you'll be prompted to enter `telegram.bot_token`, other fields use default values.
91
+
92
+ ### Complete Configuration Example
82
93
 
83
94
  ```toml
84
95
  [telegram]
@@ -95,26 +106,69 @@ openai_api_key = ""
95
106
  workspace_dir = ""
96
107
  session_dir = "~/.tg-agent/tg-sessions"
97
108
 
98
- [proxy]
99
- url = ""
109
+ [workspace_mappings]
110
+ # Set independent workspace for specific chat IDs
111
+ # "-123456789" = "~/projects/project-a"
112
+
113
+ [limits]
114
+ max_sessions = 5
115
+ max_concurrent = 5
116
+ max_history_messages = 40
117
+ max_output_tokens = 0
118
+
119
+ [timeouts]
120
+ model_timeout_ms = 60000
121
+ model_timeout_stream_ms = 300000
122
+ fetch_timeout_ms = 60000
100
123
 
101
124
  [fetch]
125
+ max_bytes = 200000
102
126
  proxy_url = ""
127
+
128
+ [proxy]
129
+ url = ""
130
+
131
+ [auth]
132
+ codex_home = "~/.codex"
133
+
134
+ [logging]
135
+ agent_events = true
136
+ agent_stream = true
137
+
138
+ [system]
139
+ prompt = "You are running in user's personal computer or VPS, using telegram bot to interact with user. Be concise and practical."
140
+
141
+ [tls]
142
+ extra_ca_certs = ""
143
+ reject_unauthorized = ""
103
144
  ```
104
145
 
105
- ## Codex 认证
146
+ ### Configuration Options
147
+
148
+ - `telegram.allowed_user_ids`: List of user IDs allowed to use the bot (empty list means all users are allowed)
149
+ - `paths.workspace_dir`: Default workspace directory
150
+ - `workspace_mappings`: Set independent workspace for specific chat IDs (keys are chat IDs as strings)
151
+ - `limits.max_sessions`: Maximum number of sessions to keep per chat
152
+ - `limits.max_concurrent`: Maximum number of concurrent requests
153
+ - `limits.max_history_messages`: Maximum number of history messages per session
154
+ - `timeouts`: Timeout settings for various operations (in milliseconds)
155
+ - `fetch.max_bytes`: Maximum bytes for fetch tool file downloads
156
+ - `tls.extra_ca_certs`: Path to additional CA certificate file
157
+ - `tls.reject_unauthorized`: Whether to reject unauthorized TLS certificates (empty string means use system default)
106
158
 
107
- 优先使用本机 Codex OAuth 凭据(`codex login` 写入的配置)。
108
- 也可以在 Telegram 内执行 `/login openai-codex`,将凭据保存到 `~/.tg-agent/auth.json`。
109
- 如果运行时提示缺少权限或无法找到凭据,请重新执行:
159
+ ## Codex Authentication
160
+
161
+ Prefers local Codex OAuth credentials (written by `codex login`).
162
+ You can also execute `/login openai-codex` in Telegram to save credentials to `~/.tg-agent/auth.json`.
163
+ If you see missing permissions or cannot find credentials at runtime, re-run:
110
164
 
111
165
  ```bash
112
166
  codex login
113
167
  ```
114
168
 
115
- ## MCP 配置
169
+ ## MCP Configuration
116
170
 
117
- 在同一个 `~/.tg-agent/config.toml` 中添加 MCP 服务器:
171
+ Add MCP servers in the same `~/.tg-agent/config.toml`:
118
172
 
119
173
  ```toml
120
174
  [mcp_servers.context7]
@@ -126,40 +180,25 @@ args = ["-y", "@upstash/context7-mcp@latest"]
126
180
  url = "https://mcp.notion.com/mcp"
127
181
  ```
128
182
 
129
- ## 打包发布
130
-
131
- 构建并生成可执行入口:
132
-
133
- ```bash
134
- npm run build
135
- ```
136
-
137
- 本地验证打包内容:
138
-
139
- ```bash
140
- npm pack
141
- ```
142
-
143
- 发布到 npm(可选):
183
+ Two types of MCP servers are supported:
144
184
 
145
- ```bash
146
- npm publish
147
- ```
185
+ - `stdio`: Communication via standard input/output (using `command` and `args`)
186
+ - HTTP: Communication via HTTP requests (using `url`)
148
187
 
149
- 安装后可直接使用:
188
+ ## Skills Configuration
150
189
 
151
- ```bash
152
- tg-agent
153
- ```
190
+ Place Skills in the `~/.tg-agent/skills` folder, and the program will automatically discover them.
154
191
 
155
- ## 常见问题
192
+ ## Troubleshooting
156
193
 
157
- - `Bad Request: can't parse entities`: 说明文本不符合 MarkdownV2 规则,当前实现会自动降级。
158
- - `No Codex OAuth credentials found`: 执行 `codex login`。
159
- - `insufficient permissions`: 检查组织/项目权限或 OAuth scope
160
- - 网络错误:检查代理配置与 TLS 证书设置。
194
+ - `Bad Request: can't parse entities`: Text doesn't conform to MarkdownV2 rules. The implementation automatically falls back to Markdown or plain text.
195
+ - `No Codex OAuth credentials found`: Run `codex login` or use `/login openai-codex`.
196
+ - `insufficient permissions`: Check organization/project permissions or OAuth scope.
197
+ - Network errors: Check proxy configuration and TLS certificate settings.
198
+ - File upload failures: Check permissions for `~/.tg-agent/uploads` directory.
161
199
 
162
- ## 安全说明
200
+ ## Security
163
201
 
164
- - 不要提交 `~/.tg-agent/config.toml` 到仓库。
165
- - 建议开启 `telegram.allowed_user_ids` 白名单。
202
+ - Do not commit `~/.tg-agent/config.toml` to the repository
203
+ - It's recommended to enable `telegram.allowed_user_ids` whitelist to restrict access
204
+ - Sensitive information (such as API keys) is stored in the config file, keep it secure
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tg-agent",
3
- "version": "1.2.2",
4
- "description": "Telegram Codex agent",
3
+ "version": "1.2.5",
4
+ "description": "Telegram Agent Bot",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "tg-agent": "dist/cli.js"