@4via6/relay 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.
Files changed (99) hide show
  1. package/.env.example +50 -0
  2. package/README.md +253 -0
  3. package/dist/auth.d.ts +3 -0
  4. package/dist/auth.js +32 -0
  5. package/dist/auth.js.map +1 -0
  6. package/dist/bot.d.ts +2 -0
  7. package/dist/bot.js +14 -0
  8. package/dist/bot.js.map +1 -0
  9. package/dist/cli.d.ts +2 -0
  10. package/dist/cli.js +3 -0
  11. package/dist/cli.js.map +1 -0
  12. package/dist/commands/admin.d.ts +2 -0
  13. package/dist/commands/admin.js +420 -0
  14. package/dist/commands/admin.js.map +1 -0
  15. package/dist/commands/chat.d.ts +2 -0
  16. package/dist/commands/chat.js +80 -0
  17. package/dist/commands/chat.js.map +1 -0
  18. package/dist/commands/files.d.ts +2 -0
  19. package/dist/commands/files.js +162 -0
  20. package/dist/commands/files.js.map +1 -0
  21. package/dist/commands/history.d.ts +2 -0
  22. package/dist/commands/history.js +152 -0
  23. package/dist/commands/history.js.map +1 -0
  24. package/dist/commands/index.d.ts +2 -0
  25. package/dist/commands/index.js +21 -0
  26. package/dist/commands/index.js.map +1 -0
  27. package/dist/commands/mcp.d.ts +2 -0
  28. package/dist/commands/mcp.js +105 -0
  29. package/dist/commands/mcp.js.map +1 -0
  30. package/dist/commands/media.d.ts +2 -0
  31. package/dist/commands/media.js +248 -0
  32. package/dist/commands/media.js.map +1 -0
  33. package/dist/commands/monitor.d.ts +2 -0
  34. package/dist/commands/monitor.js +136 -0
  35. package/dist/commands/monitor.js.map +1 -0
  36. package/dist/commands/session.d.ts +2 -0
  37. package/dist/commands/session.js +114 -0
  38. package/dist/commands/session.js.map +1 -0
  39. package/dist/commands/shell.d.ts +2 -0
  40. package/dist/commands/shell.js +90 -0
  41. package/dist/commands/shell.js.map +1 -0
  42. package/dist/index.d.ts +1 -0
  43. package/dist/index.js +82 -0
  44. package/dist/index.js.map +1 -0
  45. package/dist/providers/claude.d.ts +52 -0
  46. package/dist/providers/claude.js +449 -0
  47. package/dist/providers/claude.js.map +1 -0
  48. package/dist/providers/codex.d.ts +45 -0
  49. package/dist/providers/codex.js +400 -0
  50. package/dist/providers/codex.js.map +1 -0
  51. package/dist/providers/index.d.ts +6 -0
  52. package/dist/providers/index.js +40 -0
  53. package/dist/providers/index.js.map +1 -0
  54. package/dist/providers/opencode.d.ts +40 -0
  55. package/dist/providers/opencode.js +498 -0
  56. package/dist/providers/opencode.js.map +1 -0
  57. package/dist/providers/types.d.ts +173 -0
  58. package/dist/providers/types.js +6 -0
  59. package/dist/providers/types.js.map +1 -0
  60. package/dist/session.d.ts +10 -0
  61. package/dist/session.js +65 -0
  62. package/dist/session.js.map +1 -0
  63. package/dist/utils/chunker.d.ts +1 -0
  64. package/dist/utils/chunker.js +24 -0
  65. package/dist/utils/chunker.js.map +1 -0
  66. package/dist/utils/errors.d.ts +12 -0
  67. package/dist/utils/errors.js +85 -0
  68. package/dist/utils/errors.js.map +1 -0
  69. package/dist/utils/files.d.ts +15 -0
  70. package/dist/utils/files.js +81 -0
  71. package/dist/utils/files.js.map +1 -0
  72. package/dist/utils/html.d.ts +4 -0
  73. package/dist/utils/html.js +10 -0
  74. package/dist/utils/html.js.map +1 -0
  75. package/dist/utils/media.d.ts +15 -0
  76. package/dist/utils/media.js +103 -0
  77. package/dist/utils/media.js.map +1 -0
  78. package/dist/utils/store.d.ts +15 -0
  79. package/dist/utils/store.js +44 -0
  80. package/dist/utils/store.js.map +1 -0
  81. package/dist/utils/stream.d.ts +21 -0
  82. package/dist/utils/stream.js +149 -0
  83. package/dist/utils/stream.js.map +1 -0
  84. package/dist/utils/stt.d.ts +7 -0
  85. package/dist/utils/stt.js +118 -0
  86. package/dist/utils/stt.js.map +1 -0
  87. package/dist/utils/system-prompt.d.ts +5 -0
  88. package/dist/utils/system-prompt.js +64 -0
  89. package/dist/utils/system-prompt.js.map +1 -0
  90. package/dist/utils/timeout.d.ts +2 -0
  91. package/dist/utils/timeout.js +18 -0
  92. package/dist/utils/timeout.js.map +1 -0
  93. package/docs/commands.md +351 -0
  94. package/docs/configuration.md +160 -0
  95. package/docs/features.md +443 -0
  96. package/docs/getting-started.md +102 -0
  97. package/docs/providers.md +236 -0
  98. package/docs/troubleshooting.md +287 -0
  99. package/package.json +54 -0
@@ -0,0 +1,351 @@
1
+ # Command Reference
2
+
3
+ Complete reference for all Relay Telegram commands. Commands marked with a provider name are only available when using that provider.
4
+
5
+ ## Chat
6
+
7
+ No command needed -- just send a message.
8
+
9
+ **Supported input types:**
10
+ - Text messages
11
+ - Voice notes (requires STT configuration)
12
+ - Photos (sent to vision-capable models)
13
+ - File attachments (text files are embedded, binary files referenced)
14
+
15
+ **Input limit:** 32,000 characters for text messages. Send longer content as a file.
16
+
17
+ **Output:** The AI's response is sent as Telegram messages. If the AI generates files or screenshots (OpenCode), they are sent as Telegram attachments automatically.
18
+
19
+ ---
20
+
21
+ ## Session Management
22
+
23
+ ### `/new [title]`
24
+
25
+ Create a new session.
26
+
27
+ ```
28
+ /new
29
+ /new Refactoring auth module
30
+ ```
31
+
32
+ The new session becomes the active session. All subsequent messages go to this session.
33
+
34
+ ### `/sessions`
35
+
36
+ List all sessions, sorted by last modified date. Shows the session ID, title, and a marker for the active session.
37
+
38
+ ### `/switch <id>`
39
+
40
+ Switch to an existing session by its ID.
41
+
42
+ ```
43
+ /switch abc123
44
+ ```
45
+
46
+ ### `/delete <id>`
47
+
48
+ Delete a session. If you delete the active session, it is cleared.
49
+
50
+ ```
51
+ /delete abc123
52
+ ```
53
+
54
+ ### `/current`
55
+
56
+ Show the currently active session's ID and title.
57
+
58
+ ### `/fork [messageId]`
59
+
60
+ Fork the current session, creating a copy. Optionally specify a message ID to fork from a specific point.
61
+
62
+ ```
63
+ /fork
64
+ /fork msg_abc123
65
+ ```
66
+
67
+ The forked session becomes the active session. Supported by OpenCode and Claude.
68
+
69
+ ---
70
+
71
+ ## Monitor
72
+
73
+ ### `/todo` (OpenCode)
74
+
75
+ View the AI's task checklist. Shows each task with a status icon:
76
+
77
+ - Completed
78
+ - In progress
79
+ - Pending
80
+ - Cancelled
81
+
82
+ ### `/diff`
83
+
84
+ Show a summary of code changes in the current session. OpenCode shows structured file-level changes; Claude and Codex delegate to `git diff`.
85
+
86
+ ### `/diff full`
87
+
88
+ Download the full diff as a text file, including before/after content for each changed file.
89
+
90
+ ---
91
+
92
+ ## File Operations
93
+
94
+ ### `/read <path>`
95
+
96
+ Read a file and display its contents.
97
+
98
+ ```
99
+ /read src/index.ts
100
+ /read package.json
101
+ ```
102
+
103
+ Files larger than 15KB are sent as a downloadable attachment.
104
+
105
+ ### `/find <query>`
106
+
107
+ Find files by name pattern.
108
+
109
+ ```
110
+ /find index.ts
111
+ /find *.json
112
+ ```
113
+
114
+ Shows up to 50 matching files.
115
+
116
+ ### `/search <pattern>`
117
+
118
+ Search file contents with a text pattern (regex supported).
119
+
120
+ ```
121
+ /search TODO
122
+ /search function.*auth
123
+ ```
124
+
125
+ Shows up to 20 matching lines with file paths and line numbers.
126
+
127
+ ### `/symbols <query>`
128
+
129
+ Find code symbols (functions, classes, variables) by name.
130
+
131
+ ```
132
+ /symbols authenticate
133
+ /symbols UserService
134
+ ```
135
+
136
+ Shows up to 30 matching symbols with their locations.
137
+
138
+ ### `/status`
139
+
140
+ Show git file status (modified, added, deleted files).
141
+
142
+ ---
143
+
144
+ ## History
145
+
146
+ ### `/history`
147
+
148
+ View the last 10 messages in the current session. Shows alternating user and assistant messages with a 200-character preview.
149
+
150
+ ### `/summarize`
151
+
152
+ Generate a summary of the current session. OpenCode only.
153
+
154
+ ### `/revert`
155
+
156
+ Undo the last AI change. OpenCode only.
157
+
158
+ ### `/unrevert`
159
+
160
+ Redo a previously reverted change. OpenCode only.
161
+
162
+ ### `/abort`
163
+
164
+ Cancel the currently running operation. Stops streaming or processing.
165
+
166
+ ### `/share`
167
+
168
+ Get a shareable URL for the current session. OpenCode only.
169
+
170
+ ---
171
+
172
+ ## Shell
173
+
174
+ ### `/shell <command>`
175
+
176
+ Run a shell command on the coding agent's machine.
177
+
178
+ ```
179
+ /shell ls -la
180
+ /shell git log --oneline -5
181
+ /shell npm test
182
+ ```
183
+
184
+ On OpenCode, this runs natively. On Claude and Codex, the command is sent as a prompt asking the AI to execute it.
185
+
186
+ ### `/cmd <command> [arguments]` (OpenCode)
187
+
188
+ Run an OpenCode-specific command.
189
+
190
+ ```
191
+ /cmd compact
192
+ /cmd agent_cycle
193
+ ```
194
+
195
+ ### `/commands` (OpenCode)
196
+
197
+ List all available OpenCode commands that can be used with `/cmd`.
198
+
199
+ ---
200
+
201
+ ## Models
202
+
203
+ ### `/models`
204
+
205
+ List all available models grouped by provider. Each model shows capability badges:
206
+
207
+ - `[reasoning]` -- The model supports extended thinking/reasoning
208
+ - `[vision]` -- The model accepts image input
209
+ - `[active]` -- Currently selected model
210
+
211
+ Example output:
212
+
213
+ ```
214
+ Available Models
215
+
216
+ anthropic
217
+ claude-sonnet-4-20250514 [reasoning] [active]
218
+ claude-opus-4-20250514 [reasoning]
219
+ claude-haiku-4-20250514
220
+
221
+ openrouter
222
+ deepseek/deepseek-r1 [reasoning]
223
+ ```
224
+
225
+ All providers fetch models dynamically from their respective APIs.
226
+
227
+ ### `/model [provider/model]`
228
+
229
+ View or change the current model.
230
+
231
+ **View current model:**
232
+ ```
233
+ /model
234
+ ```
235
+
236
+ **Set by full path:**
237
+ ```
238
+ /model anthropic/claude-sonnet-4-20250514
239
+ ```
240
+
241
+ **Set by partial match:**
242
+ ```
243
+ /model sonnet
244
+ /model deepseek
245
+ ```
246
+
247
+ After switching, the bot shows the model's capabilities:
248
+
249
+ ```
250
+ Model set to anthropic/claude-sonnet-4-20250514
251
+ Capabilities: reasoning, vision
252
+ ```
253
+
254
+ ---
255
+
256
+ ## MCP (Model Context Protocol)
257
+
258
+ MCP servers extend the AI's capabilities with additional tools like browsers, databases, and external APIs. Supported by OpenCode and Claude.
259
+
260
+ ### `/mcp`
261
+
262
+ Show the status of all configured MCP servers.
263
+
264
+ Example output:
265
+
266
+ ```
267
+ MCP Servers (2)
268
+
269
+ memory ok
270
+ browser failed
271
+ Connection refused
272
+ ```
273
+
274
+ ### `/mcp add <name> local <command...>`
275
+
276
+ Add a local MCP server. The command is run as a subprocess.
277
+
278
+ ```
279
+ /mcp add memory local npx -y @modelcontextprotocol/server-memory
280
+ /mcp add browser local npx -y @anthropic-ai/mcp-server-puppeteer
281
+ /mcp add filesystem local npx -y @modelcontextprotocol/server-filesystem /path/to/dir
282
+ ```
283
+
284
+ ### `/mcp add <name> remote <url>`
285
+
286
+ Add a remote MCP server by URL.
287
+
288
+ ```
289
+ /mcp add api remote https://mcp.example.com/sse
290
+ ```
291
+
292
+ ### `/mcp remove <name>`
293
+
294
+ Remove and disconnect an MCP server.
295
+
296
+ ```
297
+ /mcp remove browser
298
+ ```
299
+
300
+ **Provider differences:**
301
+ - **OpenCode:** Full runtime management. Servers persist in the OpenCode configuration.
302
+ - **Claude:** Persisted to `.relay/claude-mcp.json`. Servers are restored on restart.
303
+ - **Codex:** Not supported.
304
+
305
+ ---
306
+
307
+ ## Settings
308
+
309
+ ### `/health`
310
+
311
+ Show a dashboard with server status, current model (with reasoning badge), streaming status, voice STT provider, system prompt info, and project details.
312
+
313
+ ### `/config`
314
+
315
+ Show the full provider configuration as JSON.
316
+
317
+ ### `/providers`
318
+
319
+ Show available AI providers and their models (raw JSON from the provider).
320
+
321
+ ### `/agents`
322
+
323
+ List available agents (OpenCode only).
324
+
325
+ ### `/tools`
326
+
327
+ List all tools available to the AI.
328
+
329
+ ### `/project`
330
+
331
+ Show project information: ID, worktree, VCS type, branch, and directory.
332
+
333
+ ### `/git`
334
+
335
+ Show git branch and changed files status.
336
+
337
+ ### `/system`
338
+
339
+ View the current system prompt (first 500 characters), its source (custom file or built-in default), and character count.
340
+
341
+ ### `/system reload`
342
+
343
+ Force-reload the system prompt from the file. Useful if auto-reload didn't pick up a change.
344
+
345
+ ### `/start`
346
+
347
+ Show a welcome message with the active provider name.
348
+
349
+ ### `/help`
350
+
351
+ Show a compact reference of all available commands, with provider-specific sections shown based on the active provider.
@@ -0,0 +1,160 @@
1
+ # Configuration Reference
2
+
3
+ All configuration is done through environment variables in the `.env` file. Copy `.env.example` to `.env` to get started.
4
+
5
+ ## Required Variables
6
+
7
+ | Variable | Description |
8
+ |----------|-------------|
9
+ | `BOT_TOKEN` | Telegram bot token from [@BotFather](https://t.me/BotFather) |
10
+ | `ALLOWED_USER_ID` | Your Telegram user ID (only this user can interact with the bot) |
11
+ | `PROVIDER` | Which coding agent to use: `opencode`, `claude`, or `codex` |
12
+
13
+ ## Provider Configuration
14
+
15
+ Each provider has its own set of required and optional variables. See [Providers](providers.md) for detailed setup.
16
+
17
+ ### OpenCode
18
+
19
+ | Variable | Required | Default | Description |
20
+ |----------|----------|---------|-------------|
21
+ | `OPENCODE_MODE` | No | `start` | `start` spawns a local server, `connect` connects to a remote URL |
22
+ | `OPENCODE_URL` | No | `http://localhost:4096` | Server URL (used when `MODE=connect`) |
23
+ | `OPENCODE_HOSTNAME` | No | `127.0.0.1` | Bind address (used when `MODE=start`) |
24
+ | `OPENCODE_PORT` | No | `4096` | Port number (used when `MODE=start`) |
25
+ | `OPENCODE_MODEL` | No | Server default | Model override, e.g. `anthropic/claude-sonnet-4-20250514` |
26
+
27
+ ### Claude Code
28
+
29
+ | Variable | Required | Default | Description |
30
+ |----------|----------|---------|-------------|
31
+ | `ANTHROPIC_API_KEY` | Yes | -- | Anthropic API key |
32
+ | `CLAUDE_MODEL` | No | `sonnet` | Model name or ID (use `/models` to see all available) |
33
+ | `CLAUDE_PERMISSION_MODE` | No | `acceptEdits` | How Claude handles file edits |
34
+ | `CLAUDE_CWD` | No | Current directory | Working directory for Claude |
35
+
36
+ ### OpenAI Codex
37
+
38
+ | Variable | Required | Default | Description |
39
+ |----------|----------|---------|-------------|
40
+ | `CODEX_API_KEY` | Yes* | -- | OpenAI API key (*or use `OPENAI_API_KEY`) |
41
+ | `CODEX_MODEL` | No | `o3` | Model name or ID (use `/models` to see all available) |
42
+ | `CODEX_CWD` | No | Current directory | Working directory for Codex |
43
+
44
+ ## Bot Mode
45
+
46
+ | Variable | Default | Description |
47
+ |----------|---------|-------------|
48
+ | `BOT_MODE` | `polling` | `polling` for long-polling, `webhook` for webhook mode |
49
+ | `WEBHOOK_URL` | -- | Public URL for receiving Telegram updates (required when `BOT_MODE=webhook`) |
50
+ | `WEBHOOK_PORT` | `3000` | Port for the webhook HTTP server |
51
+ | `WEBHOOK_SECRET` | -- | Optional secret token for webhook verification |
52
+
53
+ ### Long Polling (default)
54
+
55
+ The bot connects to Telegram and pulls updates. Simple to set up, works behind NATs/firewalls.
56
+
57
+ ```env
58
+ BOT_MODE=polling
59
+ ```
60
+
61
+ ### Webhook Mode
62
+
63
+ The bot runs an HTTP server and Telegram pushes updates to it. Lower latency and better for production deployments.
64
+
65
+ ```env
66
+ BOT_MODE=webhook
67
+ WEBHOOK_URL=https://your-server.com/bot
68
+ WEBHOOK_PORT=3000
69
+ WEBHOOK_SECRET=your-random-secret
70
+ ```
71
+
72
+ Requirements:
73
+ - A public HTTPS URL that Telegram can reach
74
+ - The port must be accessible (default: 3000)
75
+
76
+ ## Data Persistence
77
+
78
+ | Variable | Default | Description |
79
+ |----------|---------|-------------|
80
+ | `RELAY_DATA_DIR` | `.relay/` | Directory for persisted bot state |
81
+
82
+ Relay persists session state, model selection, and provider-specific data to disk so they survive restarts. The `.relay/` directory is created automatically in the project root.
83
+
84
+ Files stored:
85
+ - `session.json` — Active session ID and selected model
86
+ - `claude-mcp.json` — Claude provider MCP server configurations
87
+ - `codex-threads.json` — Codex provider thread ID mappings
88
+
89
+ The directory is excluded from git via `.gitignore`.
90
+
91
+ ## Streaming
92
+
93
+ | Variable | Default | Description |
94
+ |----------|---------|-------------|
95
+ | `STREAMING_ENABLED` | `false` | Enable progressive message editing during AI responses |
96
+ | `STREAM_EDIT_INTERVAL_MS` | `2000` | How often (in ms) to update the Telegram message while streaming |
97
+
98
+ When streaming is enabled, the bot sends a "Thinking..." placeholder and progressively updates it as the AI generates its response. This works with all three providers.
99
+
100
+ ## Timeout
101
+
102
+ | Variable | Default | Description |
103
+ |----------|---------|-------------|
104
+ | `PROMPT_TIMEOUT_MS` | `300000` | Maximum time (in ms) to wait for a provider response. Default is 5 minutes. |
105
+
106
+ If the AI takes longer than this to respond, the request is cancelled and an error message is shown.
107
+
108
+ ## System Prompt
109
+
110
+ | Variable | Default | Description |
111
+ |----------|---------|-------------|
112
+ | `SYSTEM_PROMPT_FILE` | `skill.md` | Path to your custom system prompt file |
113
+
114
+ The bot looks for a file named `skill.md` in the project root. If found, its contents are prepended to every message sent to the AI. If the file doesn't exist, a built-in default prompt is used.
115
+
116
+ The file is watched for changes and reloaded automatically. You can also force a reload with `/system reload`.
117
+
118
+ See [Features > System Prompt](features.md#system-prompt) for details on customizing the prompt.
119
+
120
+ ## Voice / Speech-to-Text
121
+
122
+ | Variable | Default | Description |
123
+ |----------|---------|-------------|
124
+ | `STT_PROVIDER` | `auto` | STT provider: `groq`, `openai`, `assemblyai`, or `auto` |
125
+ | `GROQ_API_KEY` | -- | Groq API key for Whisper |
126
+ | `GROQ_STT_MODEL` | `whisper-large-v3-turbo` | Groq transcription model |
127
+ | `OPENAI_API_KEY` | -- | OpenAI API key for Whisper |
128
+ | `OPENAI_STT_MODEL` | `gpt-4o-mini-transcribe` | OpenAI transcription model |
129
+ | `ASSEMBLYAI_API_KEY` | -- | AssemblyAI API key |
130
+
131
+ Set at least one API key to enable voice message support. When `STT_PROVIDER=auto` (default), the cheapest available provider is selected automatically:
132
+
133
+ 1. **Groq** (fastest, has a free tier)
134
+ 2. **AssemblyAI**
135
+ 3. **OpenAI**
136
+
137
+ ## Example `.env` File
138
+
139
+ ```env
140
+ # Telegram
141
+ BOT_TOKEN=123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
142
+ ALLOWED_USER_ID=987654321
143
+
144
+ # Provider
145
+ PROVIDER=opencode
146
+ OPENCODE_MODE=start
147
+
148
+ # Bot mode (polling or webhook)
149
+ BOT_MODE=polling
150
+
151
+ # Streaming
152
+ STREAMING_ENABLED=true
153
+ STREAM_EDIT_INTERVAL_MS=2000
154
+
155
+ # Timeout
156
+ PROMPT_TIMEOUT_MS=300000
157
+
158
+ # Voice (set at least one for voice support)
159
+ GROQ_API_KEY=gsk_...
160
+ ```