teleton 0.1.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,395 @@
1
+ # Teleton Agent
2
+
3
+ **Autonomous AI Agent for Telegram with TON Blockchain Integration**
4
+
5
+ ![Now in Public Beta](https://img.shields.io/badge/Now_in_Public_Beta-0088cc?style=for-the-badge&logoColor=white)
6
+
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
8
+ [![Node.js](https://img.shields.io/badge/node-%3E%3D20.0.0-brightgreen)](https://nodejs.org/)
9
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.7-blue)](https://www.typescriptlang.org/)
10
+
11
+ ---
12
+
13
+ ## Overview
14
+
15
+ Teleton is a production-grade autonomous AI agent that operates as a real Telegram user account (not a bot), powered by multi-provider LLM support. It provides full access to the Telegram API with deep TON blockchain integration for cryptocurrency trading, NFT marketplace operations, and decentralized finance.
16
+
17
+ ### Key Highlights
18
+
19
+ - **True Autonomy** - Operates as a Telegram userbot with access to full API (not limited like bots)
20
+ - **Multi-Provider LLM** - Anthropic, OpenAI, Google Gemini, xAI Grok, Groq, OpenRouter
21
+ - **TON Native** - Built-in W5R1 wallet, jetton swaps, DNS, and DeFi integrations
22
+ - **Deals System** - Secure gift/TON trading with strategy enforcement and inline bot confirmations
23
+ - **Advanced Memory** - RAG system with hybrid FTS5 + vector search, auto-compaction, daily logs
24
+ - **121 Tools** - Telegram operations, blockchain transactions, market analysis, deals, and more
25
+ - **Production Ready** - SQLite storage, sandboxed workspace, multi-layer security
26
+
27
+ ---
28
+
29
+ ## Features
30
+
31
+ ### Tool Categories
32
+
33
+ | Category | Tools | Description |
34
+ |----------|-------|-------------|
35
+ | Telegram | 59 | Full API: messaging, media, groups, polls, stickers, gifts, stories, contacts |
36
+ | TON Blockchain | 17 | W5R1 wallet, send/receive TON, transaction history, price tracking |
37
+ | Jettons (Tokens) | 11 | Balances, swaps, prices, holders, trending tokens, liquidity pools |
38
+ | DeFi | 5 | STON.fi and DeDust DEX integration, smart routing for best swap rates |
39
+ | Deals | 5 | Secure gift/TON trading with inline bot, strategy enforcement, verification |
40
+ | TON DNS | 7 | Domain availability, auctions, bidding, resolution |
41
+ | Gift Marketplace | 4 | Floor prices, search, price history for Telegram collectible gifts |
42
+ | Business Journal | 3 | Track trades/gifts/operations with reasoning and P&L analysis |
43
+ | Memory | 2 | Persistent memory management, RAG-powered context retrieval |
44
+ | Workspace | 6 | Sandboxed file operations with security validation |
45
+
46
+ ### Advanced Capabilities
47
+
48
+ | Capability | Description |
49
+ |-----------|-------------|
50
+ | **Multi-Provider LLM** | Switch between Anthropic, OpenAI, Google, xAI, Groq, OpenRouter with one config change |
51
+ | **RAG Search** | Hybrid keyword (FTS5) + semantic (vector) search for context-aware responses |
52
+ | **Auto-Compaction** | AI-summarized context management prevents overflow, preserves key information |
53
+ | **Observation Masking** | Compresses old tool results to save ~90% context window |
54
+ | **Casino System** | Provably fair slot machine and dice games with TON payments, jackpot, and leaderboard |
55
+ | **Deals System** | Secure gift/TON trading with code-enforced strategy rules and inline bot confirmations |
56
+ | **Vision Analysis** | Image understanding via multimodal LLM |
57
+ | **Voice Synthesis** | Text-to-speech for voice messages |
58
+ | **Scheduled Tasks** | Time-based task execution with dependency resolution |
59
+ | **Message Debouncing** | Intelligent batching of rapid group messages |
60
+ | **Daily Logs** | Automatic session summaries preserved across resets |
61
+ | **Multi-Policy Access** | Configurable DM/group policies (open, allowlist, pairing, disabled) |
62
+ | **Sandboxed Workspace** | Secure file system with path traversal protection and immutable config files |
63
+
64
+ ---
65
+
66
+ ## Prerequisites
67
+
68
+ - **Node.js 20.0.0+** - [Download](https://nodejs.org/)
69
+ - **LLM API Key** - One of: [Anthropic](https://console.anthropic.com/) (recommended), [OpenAI](https://platform.openai.com/), [Google](https://aistudio.google.com/), [xAI](https://console.x.ai/), [Groq](https://console.groq.com/), [OpenRouter](https://openrouter.ai/)
70
+ - **Telegram Account** - Dedicated account recommended for security
71
+ - **Telegram API Credentials** - From [my.telegram.org/apps](https://my.telegram.org/apps)
72
+ - **Your Telegram User ID** - Message [@userinfobot](https://t.me/userinfobot)
73
+ - **Bot Token** *(optional, for deals)* - From [@BotFather](https://t.me/BotFather)
74
+
75
+ > **Security Warning**: The agent will have full control over the Telegram account. Use a dedicated account, not your main one.
76
+
77
+ ---
78
+
79
+ ## Quick Start
80
+
81
+ ### 1. Installation
82
+
83
+ **One-liner (recommended):**
84
+ ```bash
85
+ curl -fsSL https://raw.githubusercontent.com/TONresistor/teleton-agent-dev/main/install.sh | bash
86
+ ```
87
+
88
+ **npm:**
89
+ ```bash
90
+ npm install -g teleton
91
+ ```
92
+
93
+ **Docker:**
94
+ ```bash
95
+ docker run -it -v ~/.teleton:/data ghcr.io/tonresistor/teleton-agent-dev:latest setup
96
+ ```
97
+
98
+ **From source (development):**
99
+ ```bash
100
+ git clone https://github.com/TONresistor/teleton-agent-dev.git
101
+ cd teleton-agent-dev
102
+ npm install && npm run build
103
+ ```
104
+
105
+ ### 2. Setup
106
+
107
+ ```bash
108
+ teleton setup
109
+ ```
110
+
111
+ The wizard will configure:
112
+ - LLM provider selection (Anthropic, OpenAI, Google, xAI, Groq, OpenRouter)
113
+ - Telegram authentication (API credentials, phone, login code)
114
+ - Access policies (DM/group response rules)
115
+ - Admin user ID
116
+ - TON wallet generation (W5R1 with 24-word mnemonic)
117
+ - Workspace initialization (SOUL.md, STRATEGY.md, SECURITY.md, MEMORY.md)
118
+
119
+ Configuration files created:
120
+ - `~/.teleton/config.yaml` - Main configuration
121
+ - `~/.teleton/wallet.json` - TON wallet (backup mnemonic securely)
122
+ - `~/.teleton/memory.db` - SQLite database
123
+ - `~/.teleton/workspace/` - Sandboxed file storage
124
+
125
+ ### 3. Start
126
+
127
+ ```bash
128
+ teleton start
129
+ ```
130
+
131
+ ### 4. Verify
132
+
133
+ Send a message to your agent on Telegram:
134
+
135
+ ```
136
+ You: /ping
137
+ Agent: Pong! I'm alive.
138
+
139
+ You: /status
140
+ Agent: [Displays uptime, model, tool count, wallet balance]
141
+ ```
142
+
143
+ ---
144
+
145
+ ## Configuration
146
+
147
+ Edit `~/.teleton/config.yaml`:
148
+
149
+ ```yaml
150
+ agent:
151
+ provider: "anthropic" # anthropic | openai | google | xai | groq | openrouter
152
+ api_key: "sk-ant-api03-..."
153
+ model: "claude-opus-4-5-20251101"
154
+ utility_model: "claude-3-5-haiku-20241022" # optional, for summarization
155
+ max_agentic_iterations: 5
156
+
157
+ telegram:
158
+ dm_policy: "open" # open | allowlist | pairing | disabled
159
+ group_policy: "open" # open | allowlist | disabled
160
+ require_mention: true
161
+ admin_ids: [123456789]
162
+ owner_name: "Your Name"
163
+ owner_username: "your_username"
164
+
165
+ # Optional: inline bot for deals system
166
+ bot_token: "123456:ABC-DEF..."
167
+ bot_username: "your_deals_bot"
168
+
169
+ session_reset_policy:
170
+ daily_reset_enabled: true
171
+ daily_reset_hour: 4
172
+ ```
173
+
174
+ ### Environment Variables
175
+
176
+ | Variable | Description | Default |
177
+ |----------|-------------|---------|
178
+ | `TELETON_HOME` | Data directory (config, DB, session) | `~/.teleton` |
179
+ | `TELETON_API_KEY` | LLM API key (overrides config) | - |
180
+ | `TELETON_TG_API_ID` | Telegram API ID (overrides config) | - |
181
+ | `TELETON_TG_API_HASH` | Telegram API Hash (overrides config) | - |
182
+ | `TELETON_TG_PHONE` | Phone number (overrides config) | - |
183
+
184
+ ### Workspace Files
185
+
186
+ The agent's personality and rules are configured via markdown files in `~/.teleton/workspace/`:
187
+
188
+ | File | Purpose | Mutable by Agent |
189
+ |------|---------|-----------------|
190
+ | `SOUL.md` | Personality, behavior guidelines | No |
191
+ | `STRATEGY.md` | Trading rules, pricing thresholds | No |
192
+ | `SECURITY.md` | Security principles, threat recognition | No |
193
+ | `MEMORY.md` | Persistent memory (facts, contacts, decisions) | Yes |
194
+
195
+ ### Admin Commands
196
+
197
+ | Command | Description |
198
+ |---------|-------------|
199
+ | `/task <description>` | Assign a task to the agent |
200
+ | `/status` | View agent status |
201
+ | `/clear [chat_id]` | Clear conversation history |
202
+ | `/ping` | Check responsiveness |
203
+ | `/help` | Show all commands |
204
+
205
+ ---
206
+
207
+ ## Architecture
208
+
209
+ ### Tech Stack
210
+
211
+ | Layer | Technology |
212
+ |-------|------------|
213
+ | LLM | Multi-provider via [pi-ai](https://github.com/mariozechner/pi-ai) (Anthropic, OpenAI, Google, xAI, Groq, OpenRouter) |
214
+ | Telegram Userbot | [GramJS](https://gram.js.org/) (MTProto) |
215
+ | Inline Bot | [Grammy](https://grammy.dev/) (Bot API, for deal confirmations) |
216
+ | Blockchain | [TON SDK](https://github.com/ton-org/ton) (W5R1 wallet) |
217
+ | DeFi | STON.fi SDK, DeDust SDK |
218
+ | Database | [better-sqlite3](https://github.com/WiseLibs/better-sqlite3) with WAL mode |
219
+ | Vector Search | [sqlite-vec](https://github.com/asg017/sqlite-vec) (optional) |
220
+ | Token Counting | [js-tiktoken](https://github.com/dqbd/tiktoken) |
221
+ | Language | TypeScript 5.7, Node.js 20+ |
222
+
223
+ ### Project Structure
224
+
225
+ ```
226
+ tonnet-ai/
227
+ ├── src/
228
+ │ ├── index.ts # Main app, tool registry
229
+ │ ├── agent/ # Core agent runtime
230
+ │ │ ├── runtime.ts # Agentic loop orchestration
231
+ │ │ ├── client.ts # Multi-provider LLM client
232
+ │ │ └── tools/ # 121 tool implementations
233
+ │ │ ├── telegram/ # Telegram tools (59)
234
+ │ │ ├── ton/ # TON blockchain (17)
235
+ │ │ ├── jetton/ # Token operations (11)
236
+ │ │ ├── deals/ # Deal management (5)
237
+ │ │ ├── dns/ # TON DNS (7)
238
+ │ │ ├── dedust/ # DeDust DEX (3)
239
+ │ │ ├── dex/ # Smart router (2)
240
+ │ │ ├── journal/ # Business journal (3)
241
+ │ │ └── workspace/ # File operations (6)
242
+ │ ├── telegram/ # Telegram integration
243
+ │ │ ├── bridge.ts # GramJS wrapper
244
+ │ │ ├── handlers.ts # Message processing
245
+ │ │ ├── admin.ts # Admin commands
246
+ │ │ └── callbacks/ # Inline button routing
247
+ │ ├── bot/ # Grammy inline bot (deals)
248
+ │ │ ├── index.ts # DealBot class
249
+ │ │ └── services/ # Message builder, verification poller
250
+ │ ├── deals/ # Deal engine
251
+ │ │ ├── strategy-checker.ts # STRATEGY.md enforcement
252
+ │ │ ├── executor.ts # TON/gift transfers
253
+ │ │ └── gift-detector.ts # Gift receipt verification
254
+ │ ├── memory/ # Storage and knowledge
255
+ │ │ ├── schema.ts # Database schema + migrations
256
+ │ │ ├── search/ # RAG system (FTS5 + vector)
257
+ │ │ └── compaction.ts # Context auto-compaction
258
+ │ ├── ton/ # TON blockchain
259
+ │ │ ├── wallet-service.ts # W5R1 wallet
260
+ │ │ └── transfer.ts # TON send operations
261
+ │ ├── soul/ # System prompt assembly
262
+ │ │ └── loader.ts # SOUL + STRATEGY + SECURITY + MEMORY
263
+ │ ├── workspace/ # Sandboxed file system
264
+ │ │ ├── validator.ts # Path traversal protection
265
+ │ │ └── paths.ts # Workspace constants
266
+ │ ├── config/ # Configuration
267
+ │ │ ├── schema.ts # Zod validation
268
+ │ │ └── providers.ts # LLM provider registry
269
+ │ └── cli/ # CLI commands
270
+ │ └── commands/ # setup, doctor
271
+ └── README.md
272
+ ```
273
+
274
+ ---
275
+
276
+ ## Security
277
+
278
+ ### Multi-Layer Defense
279
+
280
+ | Layer | Protection |
281
+ |-------|-----------|
282
+ | **SECURITY.md** | Identity-based security principles injected into every system prompt |
283
+ | **Strategy enforcement** | Trading rules (buy/sell thresholds) enforced in code, not prompts |
284
+ | **Immutable config** | SOUL.md, STRATEGY.md, SECURITY.md cannot be modified by the agent |
285
+ | **Memory protection** | Memory writes blocked in group chats to prevent poisoning |
286
+ | **Workspace sandbox** | Agent can only access `~/.teleton/workspace/`, path traversal blocked |
287
+ | **Deal verification** | Gift transfers require a verified deal with blockchain-confirmed payment |
288
+ | **Replay protection** | Used transactions table prevents double-spending |
289
+
290
+ ### Reporting Vulnerabilities
291
+
292
+ Do not open public issues for security vulnerabilities. Contact maintainers (t.me/zkproof) directly or use GitHub's private security advisory feature.
293
+
294
+ ### Best Practices
295
+
296
+ 1. Use a dedicated Telegram account
297
+ 2. Backup your 24-word mnemonic securely offline
298
+ 3. Start with restrictive policies (`allowlist`)
299
+ 4. Set file permissions: `chmod 600 ~/.teleton/wallet.json`
300
+ 5. Never commit `config.yaml` to version control
301
+ 6. Configure `STRATEGY.md` with conservative trading thresholds
302
+ 7. Review `SECURITY.md` and customize for your use case
303
+
304
+ ---
305
+
306
+ ## Development
307
+
308
+ ### Setup
309
+
310
+ ```bash
311
+ git clone https://github.com/TONresistor/teleton-agent-dev.git
312
+ cd teleton-agent-dev
313
+ npm install
314
+ npm run setup
315
+ npm run dev # Watch mode with auto-restart
316
+ ```
317
+
318
+ ### Commands
319
+
320
+ ```bash
321
+ npm run build # Compile TypeScript to dist/
322
+ npm run start # Start agent (compiled)
323
+ npm run dev # Development mode (watch, tsx)
324
+ npm run setup # Run setup wizard
325
+ npm run doctor # Health checks
326
+ npm run typecheck # Type checking
327
+ npm run lint # ESLint
328
+ npm run format # Prettier
329
+ ```
330
+
331
+ ### Adding Custom Tools
332
+
333
+ ```typescript
334
+ // src/agent/tools/custom/my-tool.ts
335
+ import { Type } from "@sinclair/typebox";
336
+ import type { Tool, ToolExecutor, ToolResult } from "../types.js";
337
+
338
+ export const myTool: Tool = {
339
+ name: "my_custom_tool",
340
+ description: "Does something useful",
341
+ parameters: Type.Object({
342
+ input: Type.String({ description: "Input parameter" }),
343
+ }),
344
+ };
345
+
346
+ export const myToolExecutor: ToolExecutor<{ input: string }> = async (
347
+ params,
348
+ context
349
+ ): Promise<ToolResult> => {
350
+ return { success: true, data: { result: "..." } };
351
+ };
352
+
353
+ // Register in src/index.ts:
354
+ // this.toolRegistry.register(myTool, myToolExecutor);
355
+ ```
356
+
357
+ ---
358
+
359
+ ## Contributing
360
+
361
+ Contributions are welcome.
362
+
363
+ 1. Fork the repository
364
+ 2. Create a feature branch
365
+ 3. Make your changes
366
+ 4. Test thoroughly (`npm run dev`)
367
+ 5. Commit with clear messages
368
+ 6. Open a Pull Request
369
+
370
+ ---
371
+
372
+ ## License
373
+
374
+ MIT License - See [LICENSE](LICENSE) for details.
375
+
376
+ ---
377
+
378
+ ## Credits
379
+
380
+ ### Built With
381
+
382
+ - [pi-ai](https://github.com/mariozechner/pi-ai) - Multi-provider LLM SDK
383
+ - [GramJS](https://gram.js.org/) - Telegram MTProto library
384
+ - [Grammy](https://grammy.dev/) - Telegram Bot API framework
385
+ - [TON SDK](https://github.com/ton-org/ton) - TON blockchain client
386
+ - [STON.fi SDK](https://www.npmjs.com/package/@ston-fi/sdk) - DEX integration
387
+ - [DeDust SDK](https://www.npmjs.com/package/@dedust/sdk) - DEX integration
388
+
389
+ ---
390
+
391
+ ## Support
392
+
393
+ - **Issues**: [GitHub Issues](https://github.com/TONresistor/teleton-agent-dev/issues)
394
+ - **Channel**: [@ResistanceTools](https://t.me/ResistanceTools)
395
+ - **Contact**: [@zkproof](https://t.me/zkproof)
package/bin/teleton.js ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ await import("../dist/cli/index.js");
@@ -0,0 +1,74 @@
1
+ // src/workspace/paths.ts
2
+ import { join } from "path";
3
+ import { homedir } from "os";
4
+ var TELETON_ROOT = process.env.TELETON_HOME || join(homedir(), ".teleton");
5
+ var WORKSPACE_ROOT = join(TELETON_ROOT, "workspace");
6
+ var WORKSPACE_PATHS = {
7
+ // Root files
8
+ SOUL: join(WORKSPACE_ROOT, "SOUL.md"),
9
+ MEMORY: join(WORKSPACE_ROOT, "MEMORY.md"),
10
+ BOOTSTRAP: join(WORKSPACE_ROOT, "BOOTSTRAP.md"),
11
+ IDENTITY: join(WORKSPACE_ROOT, "IDENTITY.md"),
12
+ USER: join(WORKSPACE_ROOT, "USER.md"),
13
+ STRATEGY: join(WORKSPACE_ROOT, "STRATEGY.md"),
14
+ SECURITY: join(WORKSPACE_ROOT, "SECURITY.md"),
15
+ // Directories
16
+ MEMORY_DIR: join(WORKSPACE_ROOT, "memory"),
17
+ DOWNLOADS_DIR: join(WORKSPACE_ROOT, "downloads"),
18
+ UPLOADS_DIR: join(WORKSPACE_ROOT, "uploads"),
19
+ TEMP_DIR: join(WORKSPACE_ROOT, "temp"),
20
+ MEMES_DIR: join(WORKSPACE_ROOT, "memes")
21
+ };
22
+ var ALLOWED_EXTENSIONS = {
23
+ // Images
24
+ images: [".jpg", ".jpeg", ".png", ".webp", ".gif", ".bmp"],
25
+ // Audio
26
+ audio: [".mp3", ".ogg", ".wav", ".m4a", ".opus"],
27
+ // Video
28
+ video: [".mp4", ".mov", ".avi", ".webm", ".mkv"],
29
+ // Documents
30
+ documents: [".md", ".txt", ".json", ".csv", ".pdf", ".yaml", ".yml"],
31
+ // Code (for workspace files)
32
+ code: [".ts", ".js", ".py", ".sh", ".sql"],
33
+ // Stickers
34
+ stickers: [".webp", ".tgs"],
35
+ // All media
36
+ media: [
37
+ ".jpg",
38
+ ".jpeg",
39
+ ".png",
40
+ ".webp",
41
+ ".gif",
42
+ ".bmp",
43
+ ".mp3",
44
+ ".ogg",
45
+ ".wav",
46
+ ".m4a",
47
+ ".opus",
48
+ ".mp4",
49
+ ".mov",
50
+ ".avi",
51
+ ".webm",
52
+ ".mkv"
53
+ ]
54
+ };
55
+ var MAX_FILE_SIZES = {
56
+ image: 10 * 1024 * 1024,
57
+ // 10 MB
58
+ audio: 50 * 1024 * 1024,
59
+ // 50 MB
60
+ video: 100 * 1024 * 1024,
61
+ // 100 MB
62
+ document: 50 * 1024 * 1024,
63
+ // 50 MB
64
+ total_workspace: 500 * 1024 * 1024
65
+ // 500 MB total
66
+ };
67
+
68
+ export {
69
+ TELETON_ROOT,
70
+ WORKSPACE_ROOT,
71
+ WORKSPACE_PATHS,
72
+ ALLOWED_EXTENSIONS,
73
+ MAX_FILE_SIZES
74
+ };