alvin-bot 5.6.2 → 5.8.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/CHANGELOG.md +29 -0
- package/README.md +1 -1
- package/dist/claude.js +1 -102
- package/dist/config.js +1 -96
- package/dist/engine.js +1 -90
- package/dist/find-claude-binary.js +1 -98
- package/dist/handlers/async-agent-chunk-handler.js +1 -50
- package/dist/handlers/background-bypass.js +1 -75
- package/dist/handlers/commands.js +1 -2336
- package/dist/handlers/cron-progress.js +1 -52
- package/dist/handlers/document.js +1 -194
- package/dist/handlers/message.js +1 -959
- package/dist/handlers/photo.js +1 -154
- package/dist/handlers/platform-message.js +1 -360
- package/dist/handlers/stuck-timer.js +1 -54
- package/dist/handlers/video.js +1 -237
- package/dist/handlers/voice.js +1 -148
- package/dist/i18n.js +1 -805
- package/dist/index.js +1 -697
- package/dist/init-data-dir.js +1 -98
- package/dist/middleware/auth.js +1 -233
- package/dist/migrate.js +1 -162
- package/dist/paths.js +1 -146
- package/dist/platforms/discord.js +1 -175
- package/dist/platforms/index.js +1 -130
- package/dist/platforms/signal.js +1 -205
- package/dist/platforms/slack-slash-parser.js +1 -32
- package/dist/platforms/slack.js +1 -501
- package/dist/platforms/telegram.js +1 -111
- package/dist/platforms/types.js +1 -8
- package/dist/platforms/whatsapp-auth-helpers.js +1 -53
- package/dist/platforms/whatsapp.js +1 -707
- package/dist/providers/claude-sdk-provider.js +1 -565
- package/dist/providers/codex-cli-provider.js +1 -134
- package/dist/providers/index.js +1 -7
- package/dist/providers/ollama-provider.js +1 -32
- package/dist/providers/openai-compatible.js +1 -406
- package/dist/providers/registry.js +1 -352
- package/dist/providers/runtime-header.js +1 -45
- package/dist/providers/tool-executor.js +1 -475
- package/dist/providers/types.js +1 -227
- package/dist/services/access.js +1 -144
- package/dist/services/allowed-users-gate.js +1 -56
- package/dist/services/alvin-dispatch.js +1 -130
- package/dist/services/alvin-mcp-tools.js +1 -104
- package/dist/services/asset-index.js +1 -224
- package/dist/services/async-agent-parser.js +1 -418
- package/dist/services/async-agent-watcher.js +1 -443
- package/dist/services/auto-diagnostic.js +1 -228
- package/dist/services/broadcast.js +1 -52
- package/dist/services/browser-manager.js +1 -562
- package/dist/services/browser-webfetch.js +1 -127
- package/dist/services/browser.js +1 -121
- package/dist/services/cdp-bootstrap.js +1 -357
- package/dist/services/compaction.js +1 -144
- package/dist/services/critical-notify.js +1 -203
- package/dist/services/cron-resolver.js +1 -58
- package/dist/services/cron-scheduling.js +1 -310
- package/dist/services/cron.js +1 -861
- package/dist/services/custom-tools.js +1 -317
- package/dist/services/delivery-queue.js +1 -173
- package/dist/services/delivery-registry.js +1 -21
- package/dist/services/disk-cleanup.js +1 -203
- package/dist/services/elevenlabs.js +1 -58
- package/dist/services/embeddings/auto-detect.js +1 -74
- package/dist/services/embeddings/fts5.js +1 -108
- package/dist/services/embeddings/gemini.js +1 -65
- package/dist/services/embeddings/index.js +1 -496
- package/dist/services/embeddings/ollama.js +1 -78
- package/dist/services/embeddings/openai.js +1 -49
- package/dist/services/embeddings/provider.js +1 -22
- package/dist/services/embeddings/vector-base.js +1 -113
- package/dist/services/embeddings-migration.js +1 -193
- package/dist/services/embeddings.js +1 -9
- package/dist/services/env-file.js +1 -50
- package/dist/services/exec-guard.js +1 -71
- package/dist/services/fallback-order.js +1 -154
- package/dist/services/file-permissions.js +1 -93
- package/dist/services/heartbeat-file.js +1 -65
- package/dist/services/heartbeat.js +1 -313
- package/dist/services/hooks.js +1 -44
- package/dist/services/imagegen.js +1 -72
- package/dist/services/language-detect.js +1 -154
- package/dist/services/markdown.js +1 -63
- package/dist/services/mcp.js +1 -263
- package/dist/services/memory-extractor.js +1 -178
- package/dist/services/memory-inject-mode.js +1 -43
- package/dist/services/memory-layers.js +1 -156
- package/dist/services/memory.js +1 -146
- package/dist/services/ollama-manager.js +1 -339
- package/dist/services/permissions-wizard.js +1 -291
- package/dist/services/personality.js +1 -376
- package/dist/services/plugins.js +1 -171
- package/dist/services/preflight.js +1 -292
- package/dist/services/process-manager.js +1 -291
- package/dist/services/release-highlights.js +1 -79
- package/dist/services/reminders.js +1 -97
- package/dist/services/restart.js +1 -48
- package/dist/services/security-audit.js +1 -74
- package/dist/services/self-diagnosis.js +1 -272
- package/dist/services/self-search.js +1 -129
- package/dist/services/session-persistence.js +1 -237
- package/dist/services/session.js +1 -282
- package/dist/services/skills.js +1 -290
- package/dist/services/ssrf-guard.js +1 -162
- package/dist/services/standing-orders.js +1 -29
- package/dist/services/steer-channel.js +1 -46
- package/dist/services/stop-controller.js +1 -52
- package/dist/services/subagent-dedup.js +1 -0
- package/dist/services/subagent-delivery.js +1 -452
- package/dist/services/subagent-stats.js +1 -123
- package/dist/services/subagents.js +1 -814
- package/dist/services/sudo.js +1 -329
- package/dist/services/telegram.js +1 -158
- package/dist/services/timing-safe-bearer.js +1 -51
- package/dist/services/tool-discovery.js +1 -214
- package/dist/services/trends.js +1 -580
- package/dist/services/updater.js +1 -291
- package/dist/services/usage-tracker.js +1 -144
- package/dist/services/users.js +1 -271
- package/dist/services/voice.js +1 -104
- package/dist/services/watchdog-brake.js +1 -154
- package/dist/services/watchdog.js +1 -311
- package/dist/services/workspaces.js +1 -276
- package/dist/tui/index.js +1 -667
- package/dist/util/console-formatter.js +1 -109
- package/dist/util/debounce.js +1 -24
- package/dist/util/telegram-error-filter.js +1 -62
- package/dist/version.js +1 -24
- package/dist/web/bind-strategy.js +1 -42
- package/dist/web/canvas.js +1 -30
- package/dist/web/doctor-api.js +1 -604
- package/dist/web/openai-compat.js +1 -252
- package/dist/web/server.js +1 -1831
- package/dist/web/setup-api.js +1 -1101
- package/package.json +5 -2
- package/dist/.metadata_never_index +0 -0
package/dist/providers/types.js
CHANGED
|
@@ -1,227 +1 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Alvin Bot — Multi-Model Provider Abstraction
|
|
3
|
-
*
|
|
4
|
-
* Unified interfaces for different LLM backends.
|
|
5
|
-
* Every provider implements the same interface, making model switching seamless.
|
|
6
|
-
*/
|
|
7
|
-
// ── Provider Presets (common configurations) ────────────
|
|
8
|
-
export const PROVIDER_PRESETS = {
|
|
9
|
-
// OpenAI (via Codex CLI — full tool use)
|
|
10
|
-
"codex-cli": {
|
|
11
|
-
type: "codex-cli",
|
|
12
|
-
name: "Codex CLI (OpenAI)",
|
|
13
|
-
model: "gpt-5.4",
|
|
14
|
-
supportsTools: true,
|
|
15
|
-
supportsVision: false,
|
|
16
|
-
supportsStreaming: true,
|
|
17
|
-
contextWindow: 400_000,
|
|
18
|
-
},
|
|
19
|
-
// Anthropic (via Agent SDK — full tool use, 1M-context beta enabled)
|
|
20
|
-
"claude-sdk": {
|
|
21
|
-
type: "claude-sdk",
|
|
22
|
-
name: "Claude (Agent SDK)",
|
|
23
|
-
supportsTools: true,
|
|
24
|
-
supportsVision: true,
|
|
25
|
-
supportsStreaming: true,
|
|
26
|
-
contextWindow: 1_000_000,
|
|
27
|
-
},
|
|
28
|
-
// Anthropic API (via OpenAI-compatible endpoint — no Agent SDK needed)
|
|
29
|
-
"claude-opus": {
|
|
30
|
-
type: "openai-compatible",
|
|
31
|
-
name: "Claude Opus 4",
|
|
32
|
-
model: "claude-opus-4-6",
|
|
33
|
-
baseUrl: "https://api.anthropic.com/v1/",
|
|
34
|
-
supportsVision: true,
|
|
35
|
-
supportsStreaming: true,
|
|
36
|
-
supportsTools: true,
|
|
37
|
-
contextWindow: 200_000,
|
|
38
|
-
},
|
|
39
|
-
"claude-sonnet": {
|
|
40
|
-
type: "openai-compatible",
|
|
41
|
-
name: "Claude Sonnet 4.6",
|
|
42
|
-
model: "claude-sonnet-4-6",
|
|
43
|
-
baseUrl: "https://api.anthropic.com/v1/",
|
|
44
|
-
supportsVision: true,
|
|
45
|
-
supportsStreaming: true,
|
|
46
|
-
supportsTools: true,
|
|
47
|
-
contextWindow: 200_000,
|
|
48
|
-
},
|
|
49
|
-
"claude-haiku": {
|
|
50
|
-
type: "openai-compatible",
|
|
51
|
-
name: "Claude Haiku 4.5",
|
|
52
|
-
model: "claude-haiku-4-5",
|
|
53
|
-
baseUrl: "https://api.anthropic.com/v1/",
|
|
54
|
-
supportsVision: true,
|
|
55
|
-
supportsStreaming: true,
|
|
56
|
-
supportsTools: true,
|
|
57
|
-
contextWindow: 200_000,
|
|
58
|
-
},
|
|
59
|
-
// Groq (fast inference, free tier, supports function calling)
|
|
60
|
-
"groq": {
|
|
61
|
-
type: "openai-compatible",
|
|
62
|
-
name: "Groq (Llama 3.3 70B)",
|
|
63
|
-
model: "llama-3.3-70b-versatile",
|
|
64
|
-
baseUrl: "https://api.groq.com/openai/v1",
|
|
65
|
-
supportsVision: false,
|
|
66
|
-
supportsStreaming: true,
|
|
67
|
-
supportsTools: true,
|
|
68
|
-
contextWindow: 128_000,
|
|
69
|
-
},
|
|
70
|
-
// OpenAI (supports function calling)
|
|
71
|
-
"gpt-4o": {
|
|
72
|
-
type: "openai-compatible",
|
|
73
|
-
name: "GPT-4o",
|
|
74
|
-
model: "gpt-4o",
|
|
75
|
-
baseUrl: "https://api.openai.com/v1",
|
|
76
|
-
supportsVision: true,
|
|
77
|
-
supportsStreaming: true,
|
|
78
|
-
supportsTools: true,
|
|
79
|
-
contextWindow: 128_000,
|
|
80
|
-
},
|
|
81
|
-
"gpt-4o-mini": {
|
|
82
|
-
type: "openai-compatible",
|
|
83
|
-
name: "GPT-4o Mini",
|
|
84
|
-
model: "gpt-4o-mini",
|
|
85
|
-
baseUrl: "https://api.openai.com/v1",
|
|
86
|
-
supportsVision: true,
|
|
87
|
-
supportsStreaming: true,
|
|
88
|
-
supportsTools: true,
|
|
89
|
-
contextWindow: 128_000,
|
|
90
|
-
},
|
|
91
|
-
// Google Gemini (via OpenAI-compatible endpoint, supports function calling)
|
|
92
|
-
"gemini-2.5-pro": {
|
|
93
|
-
type: "openai-compatible",
|
|
94
|
-
name: "Gemini 2.5 Pro",
|
|
95
|
-
model: "gemini-2.5-pro",
|
|
96
|
-
baseUrl: "https://generativelanguage.googleapis.com/v1beta/openai",
|
|
97
|
-
supportsVision: true,
|
|
98
|
-
supportsStreaming: true,
|
|
99
|
-
supportsTools: true,
|
|
100
|
-
contextWindow: 1_000_000,
|
|
101
|
-
},
|
|
102
|
-
"gemini-2.5-flash": {
|
|
103
|
-
type: "openai-compatible",
|
|
104
|
-
name: "Gemini 2.5 Flash",
|
|
105
|
-
model: "gemini-2.5-flash",
|
|
106
|
-
baseUrl: "https://generativelanguage.googleapis.com/v1beta/openai",
|
|
107
|
-
supportsVision: true,
|
|
108
|
-
supportsStreaming: true,
|
|
109
|
-
supportsTools: true,
|
|
110
|
-
contextWindow: 1_000_000,
|
|
111
|
-
},
|
|
112
|
-
"gemini-3-pro": {
|
|
113
|
-
type: "openai-compatible",
|
|
114
|
-
name: "Gemini 3 Pro (Preview)",
|
|
115
|
-
model: "gemini-3-pro-preview",
|
|
116
|
-
baseUrl: "https://generativelanguage.googleapis.com/v1beta/openai",
|
|
117
|
-
supportsVision: true,
|
|
118
|
-
supportsStreaming: true,
|
|
119
|
-
supportsTools: true,
|
|
120
|
-
contextWindow: 2_000_000,
|
|
121
|
-
},
|
|
122
|
-
"gemini-3-flash": {
|
|
123
|
-
type: "openai-compatible",
|
|
124
|
-
name: "Gemini 3 Flash (Preview)",
|
|
125
|
-
model: "gemini-3-flash-preview",
|
|
126
|
-
baseUrl: "https://generativelanguage.googleapis.com/v1beta/openai",
|
|
127
|
-
supportsVision: true,
|
|
128
|
-
supportsStreaming: true,
|
|
129
|
-
supportsTools: true,
|
|
130
|
-
contextWindow: 1_000_000,
|
|
131
|
-
},
|
|
132
|
-
// OpenAI newer models
|
|
133
|
-
"gpt-4.1": {
|
|
134
|
-
type: "openai-compatible",
|
|
135
|
-
name: "GPT-4.1",
|
|
136
|
-
model: "gpt-4.1",
|
|
137
|
-
baseUrl: "https://api.openai.com/v1",
|
|
138
|
-
supportsVision: true,
|
|
139
|
-
supportsStreaming: true,
|
|
140
|
-
supportsTools: true,
|
|
141
|
-
contextWindow: 1_000_000,
|
|
142
|
-
},
|
|
143
|
-
"gpt-4.1-mini": {
|
|
144
|
-
type: "openai-compatible",
|
|
145
|
-
name: "GPT-4.1 Mini",
|
|
146
|
-
model: "gpt-4.1-mini",
|
|
147
|
-
baseUrl: "https://api.openai.com/v1",
|
|
148
|
-
supportsVision: true,
|
|
149
|
-
supportsStreaming: true,
|
|
150
|
-
supportsTools: true,
|
|
151
|
-
contextWindow: 1_000_000,
|
|
152
|
-
},
|
|
153
|
-
"o3-mini": {
|
|
154
|
-
type: "openai-compatible",
|
|
155
|
-
name: "o3 Mini",
|
|
156
|
-
model: "o3-mini",
|
|
157
|
-
baseUrl: "https://api.openai.com/v1",
|
|
158
|
-
supportsVision: false,
|
|
159
|
-
supportsStreaming: true,
|
|
160
|
-
supportsTools: true,
|
|
161
|
-
contextWindow: 200_000,
|
|
162
|
-
},
|
|
163
|
-
// Groq additional models
|
|
164
|
-
"groq-llama-3.1-8b": {
|
|
165
|
-
type: "openai-compatible",
|
|
166
|
-
name: "Llama 3.1 8B (Groq)",
|
|
167
|
-
model: "llama-3.1-8b-instant",
|
|
168
|
-
baseUrl: "https://api.groq.com/openai/v1",
|
|
169
|
-
supportsVision: false,
|
|
170
|
-
supportsStreaming: true,
|
|
171
|
-
supportsTools: true,
|
|
172
|
-
contextWindow: 128_000,
|
|
173
|
-
},
|
|
174
|
-
"groq-mixtral": {
|
|
175
|
-
type: "openai-compatible",
|
|
176
|
-
name: "Mixtral 8x7B (Groq)",
|
|
177
|
-
model: "mixtral-8x7b-32768",
|
|
178
|
-
baseUrl: "https://api.groq.com/openai/v1",
|
|
179
|
-
supportsVision: false,
|
|
180
|
-
supportsStreaming: true,
|
|
181
|
-
supportsTools: true,
|
|
182
|
-
contextWindow: 32_768,
|
|
183
|
-
},
|
|
184
|
-
// NVIDIA NIM (150+ free models)
|
|
185
|
-
"nvidia-llama-3.3-70b": {
|
|
186
|
-
type: "openai-compatible",
|
|
187
|
-
name: "Llama 3.3 70B (NVIDIA)",
|
|
188
|
-
model: "meta/llama-3.3-70b-instruct",
|
|
189
|
-
baseUrl: "https://integrate.api.nvidia.com/v1",
|
|
190
|
-
supportsVision: false,
|
|
191
|
-
supportsStreaming: true,
|
|
192
|
-
supportsTools: true,
|
|
193
|
-
contextWindow: 128_000,
|
|
194
|
-
},
|
|
195
|
-
"nvidia-kimi-k2.5": {
|
|
196
|
-
type: "openai-compatible",
|
|
197
|
-
name: "Kimi K2.5 (NVIDIA)",
|
|
198
|
-
model: "moonshotai/kimi-k2.5",
|
|
199
|
-
baseUrl: "https://integrate.api.nvidia.com/v1",
|
|
200
|
-
supportsVision: true,
|
|
201
|
-
supportsStreaming: true,
|
|
202
|
-
supportsTools: true,
|
|
203
|
-
contextWindow: 200_000,
|
|
204
|
-
},
|
|
205
|
-
// Ollama (local models) — Gemma 4 E4B has an 8k context window
|
|
206
|
-
"ollama": {
|
|
207
|
-
type: "openai-compatible",
|
|
208
|
-
name: "Gemma 4 E4B (Ollama)",
|
|
209
|
-
model: "gemma4:e4b",
|
|
210
|
-
baseUrl: "http://localhost:11434/v1",
|
|
211
|
-
supportsVision: true,
|
|
212
|
-
supportsStreaming: true,
|
|
213
|
-
contextWindow: 8_192,
|
|
214
|
-
},
|
|
215
|
-
// OpenRouter (any model, one API, supports function calling).
|
|
216
|
-
// Context window varies by model — default 200k is a middle-ground guess.
|
|
217
|
-
"openrouter": {
|
|
218
|
-
type: "openai-compatible",
|
|
219
|
-
name: "OpenRouter",
|
|
220
|
-
model: "anthropic/claude-sonnet-4",
|
|
221
|
-
baseUrl: "https://openrouter.ai/api/v1",
|
|
222
|
-
supportsVision: true,
|
|
223
|
-
supportsStreaming: true,
|
|
224
|
-
supportsTools: true,
|
|
225
|
-
contextWindow: 200_000,
|
|
226
|
-
},
|
|
227
|
-
};
|
|
1
|
+
const _0x13f223=_0x46e4,_0x15aab6=_0x46e4;(function(_0x50ffc1,_0x430c23){const _0x59c9ee=_0x46e4,_0x3843e2=_0x46e4,_0x411608=_0x50ffc1();while(!![]){try{const _0x4049d2=-parseInt(_0x59c9ee(0xe6))/(-0xafd*0x1+-0x3c*0x7a+0x2796)*(-parseInt(_0x59c9ee(0xbb))/(0x1c1*-0x3+0x1447+0xf02*-0x1))+-parseInt(_0x59c9ee(0xc1))/(0x32*-0x6c+0x25c9+-0x10ae)*(parseInt(_0x59c9ee(0xda))/(-0x3c5+-0x895*-0x1+-0x2*0x266))+parseInt(_0x59c9ee(0xe1))/(-0x1*0x4b8+-0x22*0xa1+0x9*0x2e7)+-parseInt(_0x59c9ee(0xdf))/(-0x2699+0x1*-0x1c39+-0x592*-0xc)+parseInt(_0x59c9ee(0xad))/(-0x565+-0x2078+0x25e4)+-parseInt(_0x59c9ee(0xdc))/(-0x7*0x2da+-0x18ce+-0x4*-0xb33)+parseInt(_0x3843e2(0xb9))/(0x25a9+-0x43*-0x26+-0x2f92)*(-parseInt(_0x59c9ee(0xb2))/(-0x13ce+0x82f*-0x1+0x29*0xaf));if(_0x4049d2===_0x430c23)break;else _0x411608['push'](_0x411608['shift']());}catch(_0x440ae2){_0x411608['push'](_0x411608['shift']());}}}(_0x33da,-0xd0b3+-0x1d4af+0x49bf5));const _0x23898f=(function(){let _0x4e072a=!![];return function(_0x492fd9,_0x4a4315){const _0x57e918=_0x4e072a?function(){if(_0x4a4315){const _0x4b643f=_0x4a4315['apply'](_0x492fd9,arguments);return _0x4a4315=null,_0x4b643f;}}:function(){};return _0x4e072a=![],_0x57e918;};}()),_0x54f3d5=_0x23898f(this,function(){const _0x1ce697=_0x46e4,_0x1bd906=_0x46e4;return _0x54f3d5[_0x1ce697(0xa8)]()['search'](_0x1ce697(0xeb)+'+$')[_0x1bd906(0xa8)]()['constructo'+'r'](_0x54f3d5)['search'](_0x1bd906(0xeb)+'+$');});function _0x46e4(_0x178430,_0x25b36d){_0x178430=_0x178430-(0x1bb2+-0x1f*0x95+-0x905*0x1);const _0x13da90=_0x33da();let _0x4db26e=_0x13da90[_0x178430];if(_0x46e4['tvADbB']===undefined){var _0x5c0fd9=function(_0x1974e4){const _0x184509='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x1aa4b3='',_0x2daf3c='',_0x50ffc1=_0x1aa4b3+_0x5c0fd9;for(let _0x430c23=0x1eaf+-0x1*0x255b+0x7a*0xe,_0x411608,_0x4049d2,_0x440ae2=0xbf*0x1c+0x15c6+-0x2aaa*0x1;_0x4049d2=_0x1974e4['charAt'](_0x440ae2++);~_0x4049d2&&(_0x411608=_0x430c23%(-0x199*-0xb+-0xd*0x92+-0x35*0x31)?_0x411608*(-0x215e+-0x12aa+0x3bc*0xe)+_0x4049d2:_0x4049d2,_0x430c23++%(-0xb5*0xd+0xe2b+-0x4f6))?_0x1aa4b3+=_0x50ffc1['charCodeAt'](_0x440ae2+(0x862+-0x18*-0xe8+-0x1e18))-(-0x1*0x291+0xcd5+0x11*-0x9a)!==0x5*0x142+0x4*0x582+-0x19*0x122?String['fromCharCode'](-0x81*-0x17+-0xde5*0x1+0x34d&_0x411608>>(-(-0xa04+-0xdf3+-0x1*-0x17f9)*_0x430c23&-0x16a7+-0x1eb+0x1898)):_0x430c23:-0x4*0xa7+-0x119b+0x1437){_0x4049d2=_0x184509['indexOf'](_0x4049d2);}for(let _0xdc7cde=0xa*0x13d+-0x1faa+0x1348,_0xea5d3b=_0x1aa4b3['length'];_0xdc7cde<_0xea5d3b;_0xdc7cde++){_0x2daf3c+='%'+('00'+_0x1aa4b3['charCodeAt'](_0xdc7cde)['toString'](0x1264+0x7a3+-0x19f7))['slice'](-(-0x10*-0x265+-0x1e9b+-0x7b3));}return decodeURIComponent(_0x2daf3c);};_0x46e4['MwkHfv']=_0x5c0fd9,_0x46e4['ScsdVI']={},_0x46e4['tvADbB']=!![];}const _0x43a72d=_0x13da90[-0xb3*-0x1d+0xffa*0x2+-0x343b],_0x441ebb=_0x178430+_0x43a72d,_0x25c9fb=_0x46e4['ScsdVI'][_0x441ebb];if(!_0x25c9fb){const _0x1aa5d4=function(_0x1a77a1){this['KHxITs']=_0x1a77a1,this['jYPupj']=[-0x1*-0x25c9+0x615+-0x2bdd,-0x895*-0x1+-0x6*0x1f1+0x311,-0x1562+-0x1*-0x1df5+0x5*-0x1b7],this['qFFubp']=function(){return'newState';},this['LwMacV']='\x5cw+\x20*\x5c(\x5c)\x20*{\x5cw+\x20*',this['IRNYNN']='[\x27|\x22].+[\x27|\x22];?\x20*}';};_0x1aa5d4['prototype']['PUqjfJ']=function(){const _0x3c6946=new RegExp(this['LwMacV']+this['IRNYNN']),_0x1016b6=_0x3c6946['test'](this['qFFubp']['toString']())?--this['jYPupj'][-0x2699+0x1*-0x1c39+-0x42d3*-0x1]:--this['jYPupj'][-0x565+-0x2078+0x25dd];return this['mwOCAa'](_0x1016b6);},_0x1aa5d4['prototype']['mwOCAa']=function(_0x4db469){if(!Boolean(~_0x4db469))return _0x4db469;return this['JyCZXi'](this['KHxITs']);},_0x1aa5d4['prototype']['JyCZXi']=function(_0x3c488f){for(let _0x44eb75=-0x7*0x2da+-0x18ce+-0x6*-0x776,_0x12c6be=this['jYPupj']['length'];_0x44eb75<_0x12c6be;_0x44eb75++){this['jYPupj']['push'](Math['round'](Math['random']())),_0x12c6be=this['jYPupj']['length'];}return _0x3c488f(this['jYPupj'][0x25a9+-0x43*-0x26+-0x2f9b]);},new _0x1aa5d4(_0x46e4)['PUqjfJ'](),_0x4db26e=_0x46e4['MwkHfv'](_0x4db26e),_0x46e4['ScsdVI'][_0x441ebb]=_0x4db26e;}else _0x4db26e=_0x25c9fb;return _0x4db26e;}_0x54f3d5();export const PROVIDER_PRESETS={'codex-cli':{'type':_0x13f223(0xd2),'name':'Codex\x20CLI\x20'+_0x13f223(0xcd),'model':_0x15aab6(0xb8),'supportsTools':!![],'supportsVision':![],'supportsStreaming':!![],'contextWindow':0x61a80},'claude-sdk':{'type':'claude-sdk','name':_0x15aab6(0xca)+_0x15aab6(0xcb),'supportsTools':!![],'supportsVision':!![],'supportsStreaming':!![],'contextWindow':0xf4240},'claude-opus':{'type':_0x13f223(0xb1)+'patible','name':_0x15aab6(0xf2)+_0x15aab6(0xed),'model':_0x13f223(0xb6)+'s-4-6','baseUrl':_0x15aab6(0xf3)+_0x13f223(0xb7)+_0x13f223(0xc4),'supportsVision':!![],'supportsStreaming':!![],'supportsTools':!![],'contextWindow':0x30d40},'claude-sonnet':{'type':'openai-com'+'patible','name':'Claude\x20Son'+_0x15aab6(0xe0),'model':'claude-son'+_0x15aab6(0xef),'baseUrl':'https://ap'+_0x15aab6(0xb7)+_0x13f223(0xc4),'supportsVision':!![],'supportsStreaming':!![],'supportsTools':!![],'contextWindow':0x30d40},'claude-haiku':{'type':_0x13f223(0xb1)+'patible','name':_0x15aab6(0xcc)+_0x15aab6(0xb0),'model':_0x13f223(0xdb)+'ku-4-5','baseUrl':_0x13f223(0xf3)+_0x15aab6(0xb7)+_0x15aab6(0xc4),'supportsVision':!![],'supportsStreaming':!![],'supportsTools':!![],'contextWindow':0x30d40},'groq':{'type':_0x15aab6(0xb1)+_0x13f223(0xae),'name':_0x15aab6(0xd4)+_0x15aab6(0xe3),'model':_0x15aab6(0xe9)+_0x13f223(0xb5)+_0x15aab6(0xc0),'baseUrl':_0x13f223(0xf3)+_0x15aab6(0xd0)+'/openai/v1','supportsVision':![],'supportsStreaming':!![],'supportsTools':!![],'contextWindow':0x1f400},'gpt-4o':{'type':'openai-com'+_0x13f223(0xae),'name':_0x15aab6(0xc5),'model':_0x15aab6(0xbd),'baseUrl':_0x13f223(0xf3)+_0x15aab6(0xd6)+_0x15aab6(0xb4),'supportsVision':!![],'supportsStreaming':!![],'supportsTools':!![],'contextWindow':0x1f400},'gpt-4o-mini':{'type':'openai-com'+'patible','name':_0x13f223(0xc6)+'i','model':_0x13f223(0xe5)+'i','baseUrl':_0x15aab6(0xf3)+_0x13f223(0xd6)+_0x13f223(0xb4),'supportsVision':!![],'supportsStreaming':!![],'supportsTools':!![],'contextWindow':0x1f400},'gemini-2.5-pro':{'type':_0x15aab6(0xb1)+_0x15aab6(0xae),'name':_0x15aab6(0xf0)+'\x20Pro','model':_0x13f223(0xbf)+_0x15aab6(0xaf),'baseUrl':'https://ge'+_0x13f223(0xf7)+_0x15aab6(0xd5)+_0x15aab6(0xa5)+_0x15aab6(0xd9)+_0x15aab6(0xee),'supportsVision':!![],'supportsStreaming':!![],'supportsTools':!![],'contextWindow':0xf4240},'gemini-2.5-flash':{'type':_0x13f223(0xb1)+_0x15aab6(0xae),'name':_0x15aab6(0xf0)+_0x13f223(0xde),'model':'gemini-2.5'+'-flash','baseUrl':_0x15aab6(0xd7)+_0x13f223(0xf7)+_0x15aab6(0xd5)+'gleapis.co'+_0x15aab6(0xd9)+_0x15aab6(0xee),'supportsVision':!![],'supportsStreaming':!![],'supportsTools':!![],'contextWindow':0xf4240},'gemini-3-pro':{'type':_0x15aab6(0xb1)+_0x13f223(0xae),'name':'Gemini\x203\x20P'+'ro\x20(Previe'+'w)','model':'gemini-3-p'+_0x15aab6(0xf8),'baseUrl':_0x15aab6(0xd7)+_0x15aab6(0xf7)+_0x13f223(0xd5)+_0x15aab6(0xa5)+_0x13f223(0xd9)+'penai','supportsVision':!![],'supportsStreaming':!![],'supportsTools':!![],'contextWindow':0x1e8480},'gemini-3-flash':{'type':_0x13f223(0xb1)+_0x15aab6(0xae),'name':_0x15aab6(0xac)+'lash\x20(Prev'+_0x15aab6(0xc9),'model':_0x13f223(0xba)+_0x15aab6(0xf6)+'ew','baseUrl':'https://ge'+_0x15aab6(0xf7)+'nguage.goo'+_0x15aab6(0xa5)+_0x13f223(0xd9)+'penai','supportsVision':!![],'supportsStreaming':!![],'supportsTools':!![],'contextWindow':0xf4240},'gpt-4.1':{'type':'openai-com'+_0x15aab6(0xae),'name':_0x13f223(0xe2),'model':'gpt-4.1','baseUrl':_0x13f223(0xf3)+'i.openai.c'+_0x13f223(0xb4),'supportsVision':!![],'supportsStreaming':!![],'supportsTools':!![],'contextWindow':0xf4240},'gpt-4.1-mini':{'type':'openai-com'+_0x13f223(0xae),'name':_0x13f223(0xc3)+'ni','model':_0x13f223(0xce)+'ni','baseUrl':'https://ap'+_0x15aab6(0xd6)+_0x13f223(0xb4),'supportsVision':!![],'supportsStreaming':!![],'supportsTools':!![],'contextWindow':0xf4240},'o3-mini':{'type':_0x15aab6(0xb1)+_0x13f223(0xae),'name':_0x15aab6(0xa2),'model':_0x13f223(0xa3),'baseUrl':_0x15aab6(0xf3)+'i.openai.c'+_0x15aab6(0xb4),'supportsVision':![],'supportsStreaming':!![],'supportsTools':!![],'contextWindow':0x30d40},'groq-llama-3.1-8b':{'type':_0x13f223(0xb1)+_0x13f223(0xae),'name':_0x15aab6(0xbc)+_0x13f223(0xbe),'model':_0x13f223(0xcf)+_0x13f223(0xdd),'baseUrl':_0x15aab6(0xf3)+_0x13f223(0xd0)+'/openai/v1','supportsVision':![],'supportsStreaming':!![],'supportsTools':!![],'contextWindow':0x1f400},'groq-mixtral':{'type':_0x13f223(0xb1)+_0x15aab6(0xae),'name':_0x13f223(0xf1)+_0x13f223(0xe8),'model':_0x15aab6(0xc8)+'7b-32768','baseUrl':_0x15aab6(0xf3)+'i.groq.com'+_0x15aab6(0xd1),'supportsVision':![],'supportsStreaming':!![],'supportsTools':!![],'contextWindow':0x8000},'nvidia-llama-3.3-70b':{'type':_0x13f223(0xb1)+_0x15aab6(0xae),'name':_0x13f223(0xc2)+'70B\x20(NVIDI'+'A)','model':'meta/llama'+_0x15aab6(0xab)+'nstruct','baseUrl':'https://in'+_0x13f223(0xd3)+'i.nvidia.c'+'om/v1','supportsVision':![],'supportsStreaming':!![],'supportsTools':!![],'contextWindow':0x1f400},'nvidia-kimi-k2.5':{'type':'openai-com'+'patible','name':_0x13f223(0xaa)+_0x15aab6(0xa9),'model':'moonshotai'+_0x15aab6(0xe7),'baseUrl':'https://in'+_0x15aab6(0xd3)+_0x13f223(0xc7)+_0x15aab6(0xb4),'supportsVision':!![],'supportsStreaming':!![],'supportsTools':!![],'contextWindow':0x30d40},'ollama':{'type':'openai-com'+'patible','name':_0x15aab6(0xa6)+_0x15aab6(0xe4),'model':_0x13f223(0xf5),'baseUrl':'http://loc'+_0x15aab6(0xa4)+_0x15aab6(0xf4),'supportsVision':!![],'supportsStreaming':!![],'contextWindow':0x2000},'openrouter':{'type':_0x15aab6(0xb1)+_0x13f223(0xae),'name':_0x15aab6(0xb3),'model':_0x13f223(0xea)+_0x15aab6(0xa7)+'net-4','baseUrl':_0x13f223(0xd8)+'enrouter.a'+_0x13f223(0xec),'supportsVision':!![],'supportsStreaming':!![],'supportsTools':!![],'contextWindow':0x30d40}};function _0x33da(){const _0x2c19d9=['r1bultqUmsbnAq','yY5JB20VDJeV','r1bultrV','r1bultrVie1PBG','As5UDMLKAweUyW','BwL4DhjHBc04Ea','Awv3kq','q2XHDwrLicHbzW','zw50ifnesYK','q2XHDwrLieHHAq','ke9Wzw5bssK','z3b0ltqUms1TAq','BgXHBweTmY4Xlq','As5NCM9XlMnVBq','l29Wzw5HAs92mq','y29KzxGTy2XP','DgvNCMf0zs5HCa','r3jVCsaOtgXHBq','BMD1ywDLlMDVBW','As5VCgvUywKUyW','Ahr0Chm6lY9Nzq','Ahr0Chm6lY9VCa','Bs92mwjLDgeVBW','nZG4sKvpsuvv','y2XHDwrLlwHHAq','mti3nZG5nNvSAxLVvW','ogiTAw5ZDgfUDa','iezSyxnO','mJKZmdCWAvzPzNrX','BMv0idqUnG','ntC4odiWq0DZshfA','r1bultqUmq','ysaZlJmGnZbckq','qIaOt2XSyw1Hkq','z3b0ltrVlw1PBG','mtb0sK1OEgC','l2TPBwKTAZiUnq','n0iGkeDYB3eP','BgXHBweTmY4Zlq','yw50AhjVCgLJlW','kcGOlISPkYKRkq','As9HCgKVDJe','CYa0','CgvUywK','BMv0ltqTnG','r2vTAw5PidiUnq','twL4DhjHBca4Ea','q2XHDwrLie9WDq','Ahr0Chm6lY9HCa','mZqVDJe','z2vTBwe0oMu0yG','BgfZAc1WCMv2Aq','BMvYyxrPDMvSyq','CM8TChjLDMLLDW','BZmGtwLUAq','BZmTBwLUAq','ywXOB3n0oJeXna','z2XLyxbPCY5JBW','r2vTBweGncbfna','y2XHDwrLlxnVBG','Dg9tDhjPBMC','ke5wsurjqsK','s2LTAsblmI41ia','ltmUmY03mgiTAq','r2vTAw5PidmGrG','mtC5ntKYn2nQrxHREq','Cgf0AwjSzq','lxbYBW','A3uGnc41','B3bLBMfPlwnVBq','mZblywvnrNi','t3bLBLjVDxrLCG','B20VDJe','nZbIlxzLCNnHDa','y2XHDwrLlw9WDq','As5HBNrOCM9WAq','z3b0ltuUna','mtG2mJfUBgHjzum','z2vTAw5PltmTzG','ndm5mdHgt2fbCMO','tgXHBweGmY4Xia','z3b0ltrV','oeiGkeDYB3eP','z2vTAw5PltiUnq','AwXL','mZC4m3Ljr3z5wa','tgXHBweGmY4Zia'];_0x33da=function(){return _0x2c19d9;};return _0x33da();}
|
package/dist/services/access.js
CHANGED
|
@@ -1,144 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Access Control Service — Manages group approvals and security.
|
|
3
|
-
*
|
|
4
|
-
* Security model:
|
|
5
|
-
* - DMs: only ALLOWED_USERS can interact (unchanged)
|
|
6
|
-
* - Groups: must be explicitly approved by an admin before bot responds
|
|
7
|
-
* - New groups: bot sends approval request to admin, stays silent until approved
|
|
8
|
-
* - Admin can block/unblock groups at any time
|
|
9
|
-
* - Forwarded message processing can be toggled
|
|
10
|
-
*/
|
|
11
|
-
import fs from "fs";
|
|
12
|
-
import { ACCESS_FILE, RUNTIME_DIR } from "../paths.js";
|
|
13
|
-
// Ensure data dir exists
|
|
14
|
-
if (!fs.existsSync(RUNTIME_DIR))
|
|
15
|
-
fs.mkdirSync(RUNTIME_DIR, { recursive: true });
|
|
16
|
-
let config = {
|
|
17
|
-
groups: {},
|
|
18
|
-
settings: {
|
|
19
|
-
allowForwards: true,
|
|
20
|
-
autoApproveGroups: false,
|
|
21
|
-
groupRateLimitPerHour: 30,
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
// Load on startup
|
|
25
|
-
try {
|
|
26
|
-
const raw = fs.readFileSync(ACCESS_FILE, "utf-8");
|
|
27
|
-
config = JSON.parse(raw);
|
|
28
|
-
}
|
|
29
|
-
catch {
|
|
30
|
-
save(); // Create default file
|
|
31
|
-
}
|
|
32
|
-
function save() {
|
|
33
|
-
fs.writeFileSync(ACCESS_FILE, JSON.stringify(config, null, 2));
|
|
34
|
-
}
|
|
35
|
-
// ── Group Management ─────────────────────────────────
|
|
36
|
-
/**
|
|
37
|
-
* Check if a group chat is approved.
|
|
38
|
-
* Returns: "approved" | "pending" | "blocked" | "new"
|
|
39
|
-
*/
|
|
40
|
-
export function getGroupStatus(chatId) {
|
|
41
|
-
const key = String(chatId);
|
|
42
|
-
const group = config.groups[key];
|
|
43
|
-
if (!group)
|
|
44
|
-
return "new";
|
|
45
|
-
return group.status;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Register a new group (first time the bot sees it).
|
|
49
|
-
* Returns the group info.
|
|
50
|
-
*/
|
|
51
|
-
export function registerGroup(chatId, title, addedBy) {
|
|
52
|
-
const key = String(chatId);
|
|
53
|
-
if (config.groups[key]) {
|
|
54
|
-
// Update title if changed
|
|
55
|
-
config.groups[key].title = title;
|
|
56
|
-
save();
|
|
57
|
-
return config.groups[key];
|
|
58
|
-
}
|
|
59
|
-
const group = {
|
|
60
|
-
chatId,
|
|
61
|
-
title,
|
|
62
|
-
addedBy,
|
|
63
|
-
firstSeen: Date.now(),
|
|
64
|
-
status: config.settings.autoApproveGroups ? "approved" : "pending",
|
|
65
|
-
statusChanged: Date.now(),
|
|
66
|
-
messageCount: 0,
|
|
67
|
-
};
|
|
68
|
-
config.groups[key] = group;
|
|
69
|
-
save();
|
|
70
|
-
return group;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Approve a group.
|
|
74
|
-
*/
|
|
75
|
-
export function approveGroup(chatId) {
|
|
76
|
-
const key = String(chatId);
|
|
77
|
-
const group = config.groups[key];
|
|
78
|
-
if (!group)
|
|
79
|
-
return false;
|
|
80
|
-
group.status = "approved";
|
|
81
|
-
group.statusChanged = Date.now();
|
|
82
|
-
save();
|
|
83
|
-
return true;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Block a group.
|
|
87
|
-
*/
|
|
88
|
-
export function blockGroup(chatId) {
|
|
89
|
-
const key = String(chatId);
|
|
90
|
-
const group = config.groups[key];
|
|
91
|
-
if (!group)
|
|
92
|
-
return false;
|
|
93
|
-
group.status = "blocked";
|
|
94
|
-
group.statusChanged = Date.now();
|
|
95
|
-
save();
|
|
96
|
-
return true;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Increment message count for a group.
|
|
100
|
-
*/
|
|
101
|
-
export function trackGroupMessage(chatId) {
|
|
102
|
-
const key = String(chatId);
|
|
103
|
-
if (config.groups[key]) {
|
|
104
|
-
config.groups[key].messageCount++;
|
|
105
|
-
// Save periodically (every 10 messages to reduce I/O)
|
|
106
|
-
if (config.groups[key].messageCount % 10 === 0)
|
|
107
|
-
save();
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Get all groups.
|
|
112
|
-
*/
|
|
113
|
-
export function listGroups() {
|
|
114
|
-
return Object.values(config.groups).sort((a, b) => b.firstSeen - a.firstSeen);
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Remove a group from tracking.
|
|
118
|
-
*/
|
|
119
|
-
export function removeGroup(chatId) {
|
|
120
|
-
const key = String(chatId);
|
|
121
|
-
if (!config.groups[key])
|
|
122
|
-
return false;
|
|
123
|
-
delete config.groups[key];
|
|
124
|
-
save();
|
|
125
|
-
return true;
|
|
126
|
-
}
|
|
127
|
-
// ── Settings ─────────────────────────────────────────
|
|
128
|
-
export function isForwardingAllowed() {
|
|
129
|
-
return config.settings.allowForwards;
|
|
130
|
-
}
|
|
131
|
-
export function setForwardingAllowed(allowed) {
|
|
132
|
-
config.settings.allowForwards = allowed;
|
|
133
|
-
save();
|
|
134
|
-
}
|
|
135
|
-
export function isAutoApproveEnabled() {
|
|
136
|
-
return config.settings.autoApproveGroups;
|
|
137
|
-
}
|
|
138
|
-
export function setAutoApprove(enabled) {
|
|
139
|
-
config.settings.autoApproveGroups = enabled;
|
|
140
|
-
save();
|
|
141
|
-
}
|
|
142
|
-
export function getSettings() {
|
|
143
|
-
return { ...config.settings };
|
|
144
|
-
}
|
|
1
|
+
const _0xf2923c=_0x4fa2,_0xadb944=_0x4fa2;(function(_0x55978a,_0x4c32ab){const _0x533c3b=_0x4fa2,_0x16e9e4=_0x4fa2,_0x33b1b1=_0x55978a();while(!![]){try{const _0x6ce9e7=-parseInt(_0x533c3b(0xfe))/(0x2*0x6d9+-0xa31+-0x380)+parseInt(_0x533c3b(0x10f))/(0x12b9*-0x2+0x2261+-0x1*-0x313)*(parseInt(_0x533c3b(0xea))/(0xe66+0x2576+0x3fd*-0xd))+-parseInt(_0x16e9e4(0x102))/(-0x200d+-0x2*-0x1265+0x27*-0x1f)*(parseInt(_0x533c3b(0x106))/(0xbef+0x21da+0x65*-0x74))+-parseInt(_0x16e9e4(0x10e))/(-0x1*-0xeef+-0x20*0xef+0x3*0x4fd)+-parseInt(_0x16e9e4(0x105))/(-0x1100+-0xf1a+0x2021)*(-parseInt(_0x533c3b(0xe9))/(-0x5df*-0x5+0x2bb*0x6+-0x2db5*0x1))+-parseInt(_0x533c3b(0xf0))/(0x23c6*-0x1+0x27*-0x53+0x7*0x6ec)*(-parseInt(_0x533c3b(0x108))/(0x2446+0x9*0x2f9+-0x3efd))+parseInt(_0x533c3b(0xfd))/(-0x2041+0xd0f+-0x19*-0xc5)*(parseInt(_0x533c3b(0x10b))/(-0x1*-0x169f+-0x2100+0xa6d));if(_0x6ce9e7===_0x4c32ab)break;else _0x33b1b1['push'](_0x33b1b1['shift']());}catch(_0x474c49){_0x33b1b1['push'](_0x33b1b1['shift']());}}}(_0x5f32,-0xb891+-0x3ba40*0x5+-0x1*-0x2087e3));import _0x2626cf from'fs';import{ACCESS_FILE,RUNTIME_DIR}from'../paths.js';if(!_0x2626cf[_0xf2923c(0xf4)](RUNTIME_DIR))_0x2626cf[_0xadb944(0xef)](RUNTIME_DIR,{'recursive':!![]});let config={'groups':{},'settings':{'allowForwards':!![],'autoApproveGroups':![],'groupRateLimitPerHour':0x1e}};try{const raw=_0x2626cf[_0xadb944(0xf9)+'nc'](ACCESS_FILE,_0xf2923c(0x10c));config=JSON['parse'](raw);}catch{save();}function save(){const _0x29add0=_0xadb944,_0x2876d0=_0xf2923c,_0x27427f=(function(){let _0x2f509d=!![];return function(_0x5043d1,_0xd8624d){const _0x26c64b=_0x2f509d?function(){const _0x4e33a1=_0x4fa2;if(_0xd8624d){const _0x4a5bc2=_0xd8624d[_0x4e33a1(0x104)](_0x5043d1,arguments);return _0xd8624d=null,_0x4a5bc2;}}:function(){};return _0x2f509d=![],_0x26c64b;};}()),_0x15a30b=_0x27427f(this,function(){const _0x154aae=_0x4fa2,_0x20e6bc=_0x4fa2;return _0x15a30b[_0x154aae(0x10a)]()[_0x154aae(0xee)](_0x154aae(0xf2)+'+$')[_0x154aae(0x10a)]()[_0x20e6bc(0xf3)+'r'](_0x15a30b)['search'](_0x154aae(0xf2)+'+$');});_0x15a30b(),_0x2626cf['writeFileS'+_0x29add0(0xec)](ACCESS_FILE,JSON[_0x2876d0(0xeb)](config,null,-0x1*0x1b73+0x1579*-0x1+0x1*0x30ee));}export function getGroupStatus(_0x4606f4){const _0x213f57=_0xf2923c,_0x1efdb0=_0xf2923c,_0x3f817d=String(_0x4606f4),_0x18d200=config[_0x213f57(0xed)][_0x3f817d];if(!_0x18d200)return _0x1efdb0(0xf1);return _0x18d200[_0x213f57(0xf8)];}export function registerGroup(_0xa3c2bc,_0x1ed7c4,_0x1a774b){const _0x415435=_0xadb944,_0x561ae6=_0xadb944,_0x486e7c=String(_0xa3c2bc);if(config['groups'][_0x486e7c])return config[_0x415435(0xed)][_0x486e7c][_0x415435(0x100)]=_0x1ed7c4,save(),config[_0x415435(0xed)][_0x486e7c];const _0x453fd5={'chatId':_0xa3c2bc,'title':_0x1ed7c4,'addedBy':_0x1a774b,'firstSeen':Date[_0x415435(0x111)](),'status':config['settings'][_0x415435(0x107)+_0x561ae6(0xfc)]?'approved':_0x415435(0xf6),'statusChanged':Date[_0x415435(0x111)](),'messageCount':0x0};return config['groups'][_0x486e7c]=_0x453fd5,save(),_0x453fd5;}export function approveGroup(_0x36e01d){const _0x4a267f=_0xadb944,_0x3583ff=_0xadb944,_0x4a8f15=String(_0x36e01d),_0x50d627=config[_0x4a267f(0xed)][_0x4a8f15];if(!_0x50d627)return![];return _0x50d627[_0x4a267f(0xf8)]=_0x3583ff(0x110),_0x50d627[_0x3583ff(0x103)+_0x3583ff(0x10d)]=Date[_0x3583ff(0x111)](),save(),!![];}export function blockGroup(_0x536022){const _0x382b9e=_0xadb944,_0x8b1b33=_0xf2923c,_0x540bd8=String(_0x536022),_0x192fd9=config[_0x382b9e(0xed)][_0x540bd8];if(!_0x192fd9)return![];return _0x192fd9[_0x8b1b33(0xf8)]=_0x8b1b33(0x109),_0x192fd9[_0x8b1b33(0x103)+_0x382b9e(0x10d)]=Date[_0x382b9e(0x111)](),save(),!![];}export function trackGroupMessage(_0x55a730){const _0x249a08=_0xf2923c,_0x1d6d02=_0xadb944,_0x9e9e97=String(_0x55a730);if(config[_0x249a08(0xed)][_0x9e9e97]){config[_0x249a08(0xed)][_0x9e9e97][_0x249a08(0x101)+'nt']++;if(config[_0x249a08(0xed)][_0x9e9e97]['messageCou'+'nt']%(-0x9*-0x2c5+-0x17ff+0x26*-0x6)===0x10f8+-0x17*-0x11f+-0x2ac1)save();}}export function listGroups(){const _0xee727e=_0xadb944,_0x16ba04=_0xadb944;return Object[_0xee727e(0xf5)](config[_0xee727e(0xed)])['sort']((_0x39c93e,_0x39a65b)=>_0x39a65b['firstSeen']-_0x39c93e[_0x16ba04(0xf7)]);}function _0x4fa2(_0x2efa27,_0x1fcdb2){_0x2efa27=_0x2efa27-(0x121d+-0x1585+0x451);const _0x59a67e=_0x5f32();let _0x40d684=_0x59a67e[_0x2efa27];if(_0x4fa2['zCMbeq']===undefined){var _0x4bf555=function(_0x414336){const _0x5d6966='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x1a2f14='',_0x2567f6='',_0x5de6b3=_0x1a2f14+_0x4bf555;for(let _0x4f3e74=-0x26ed*-0x1+-0x1*-0x1a2d+-0x411a,_0x891514,_0x5c9794,_0x214114=-0x1a8a+-0x1*0x1b73+0x11ff*0x3;_0x5c9794=_0x414336['charAt'](_0x214114++);~_0x5c9794&&(_0x891514=_0x4f3e74%(-0xc0*-0x2b+-0x14*-0x14+-0x21cc)?_0x891514*(0x142f*0x1+0x198e+-0x11*0x2ad)+_0x5c9794:_0x5c9794,_0x4f3e74++%(-0xeb6+-0x7d0+0x168a))?_0x1a2f14+=_0x5de6b3['charCodeAt'](_0x214114+(0x1ab1+0x2*-0xdff+-0x7*-0x31))-(-0x1eb0+0x1*-0xdcd+0x2c87*0x1)!==-0x11*-0x199+-0x9bf*-0x3+0x1*-0x3866?String['fromCharCode'](0x134d+0xcf*-0xb+-0x969&_0x891514>>(-(0x1f2a+0x2*-0x300+-0x1928)*_0x4f3e74&-0x4db*-0x8+0x183c+-0x1*0x3f0e)):_0x4f3e74:0xbf*0x10+-0xc27+0x37){_0x5c9794=_0x5d6966['indexOf'](_0x5c9794);}for(let _0x52e2f1=-0x162f+-0x18bb+0x2eea*0x1,_0x295c95=_0x1a2f14['length'];_0x52e2f1<_0x295c95;_0x52e2f1++){_0x2567f6+='%'+('00'+_0x1a2f14['charCodeAt'](_0x52e2f1)['toString'](-0x1f44+0xe49+0x110b))['slice'](-(-0x2*0x80e+0x355*0xb+-0x7*0x2ef));}return decodeURIComponent(_0x2567f6);};_0x4fa2['IWTgqV']=_0x4bf555,_0x4fa2['ITkKBu']={},_0x4fa2['zCMbeq']=!![];}const _0x1f10e1=_0x59a67e[0x85*0x3e+-0xb4d+0x1*-0x14e9],_0x3e14e8=_0x2efa27+_0x1f10e1,_0x219b20=_0x4fa2['ITkKBu'][_0x3e14e8];if(!_0x219b20){const _0x5289cd=function(_0x495ed3){this['XmwhnK']=_0x495ed3,this['YShGuG']=[0x973*-0x1+0x12de+0x96a*-0x1,0x2b*0x39+0xf*-0xf9+0x504,0x1080+-0x28d*0x7+0x15b*0x1],this['zONiOt']=function(){return'newState';},this['LXeAUO']='\x5cw+\x20*\x5c(\x5c)\x20*{\x5cw+\x20*',this['kYTcEK']='[\x27|\x22].+[\x27|\x22];?\x20*}';};_0x5289cd['prototype']['wuvKwi']=function(){const _0x3e407b=new RegExp(this['LXeAUO']+this['kYTcEK']),_0x590179=_0x3e407b['test'](this['zONiOt']['toString']())?--this['YShGuG'][0xb5*0x2+0x10f6+0x125f*-0x1]:--this['YShGuG'][0x10d*0x1d+0x3*-0x64+-0xd*0x241];return this['gJfcNB'](_0x590179);},_0x5289cd['prototype']['gJfcNB']=function(_0x1d98b0){if(!Boolean(~_0x1d98b0))return _0x1d98b0;return this['PygGMJ'](this['XmwhnK']);},_0x5289cd['prototype']['PygGMJ']=function(_0x191982){for(let _0x512843=-0x13e*0x17+0x2f5+0x4f*0x53,_0x44c0d3=this['YShGuG']['length'];_0x512843<_0x44c0d3;_0x512843++){this['YShGuG']['push'](Math['round'](Math['random']())),_0x44c0d3=this['YShGuG']['length'];}return _0x191982(this['YShGuG'][0xb3d+0x2*0x6d9+-0x18ef]);},new _0x5289cd(_0x4fa2)['wuvKwi'](),_0x40d684=_0x4fa2['IWTgqV'](_0x40d684),_0x4fa2['ITkKBu'][_0x3e14e8]=_0x40d684;}else _0x40d684=_0x219b20;return _0x40d684;}export function removeGroup(_0x473e76){const _0x2d5f84=_0xf2923c,_0x1a6fea=_0xadb944,_0x24d50b=String(_0x473e76);if(!config[_0x2d5f84(0xed)][_0x24d50b])return![];return delete config[_0x2d5f84(0xed)][_0x24d50b],save(),!![];}export function isForwardingAllowed(){return config['settings']['allowForwa'+'rds'];}export function setForwardingAllowed(_0x2dedad){const _0x51fd69=_0xadb944,_0x45d76f=_0xadb944;config[_0x51fd69(0xff)][_0x51fd69(0xfa)+_0x51fd69(0xfb)]=_0x2dedad,save();}export function isAutoApproveEnabled(){const _0x5cd389=_0xf2923c,_0x4caf88=_0xadb944;return config[_0x5cd389(0xff)]['autoApprov'+_0x4caf88(0xfc)];}function _0x5f32(){const _0x5234e8=['CMvHzezPBgvtEq','ywXSB3DgB3j3yq','CMrZ','zuDYB3vWCW','nJqXm0PfsNbNqG','mtm2mZm4owX4BgPNCG','C2v0DgLUz3m','DgL0Bgu','BwvZC2fNzunVDq','ntmWndeYuLj0vNnj','C3rHDhvZq2HHBG','yxbWBhK','n3fzs0Pjzq','mtboDercDe0','yxv0B0fWChjVDG','mta5ndiZmfHpvxPiva','yMXVy2TLza','Dg9tDhjPBMC','mZGWneLOCLvjsa','DxrMltG','z2vK','mZyWnJu0mfvAzfPArW','mte2nZjbwgzkDwC','yxbWCM92zwq','BM93','mteZnZeYndblB3rxAuq','nZa4DNbzwNng','C3rYAw5NAwz5','Ew5J','z3jVDxbZ','C2vHCMnO','BwTKAxjtEw5J','ovLbtfbrAG','BMv3','kcGOlISPkYKRkq','y29UC3rYDwn0BW','zxHPC3rZu3LUyW','DMfSDwvZ','CgvUzgLUzW','zMLYC3rtzwvU','C3rHDhvZ'];_0x5f32=function(){return _0x5234e8;};return _0x5f32();}export function setAutoApprove(_0x548eff){const _0x50489e=_0xf2923c,_0x1901c6=_0xf2923c;config[_0x50489e(0xff)]['autoApprov'+_0x50489e(0xfc)]=_0x548eff,save();}export function getSettings(){return{...config['settings']};}
|
|
@@ -1,56 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* ALLOWED_USERS Startup Gate (v4.12.2)
|
|
3
|
-
*
|
|
4
|
-
* Pure decision function that runs at startup to decide whether Alvin should
|
|
5
|
-
* refuse to start because its Telegram bot is configured but has no user
|
|
6
|
-
* allowlist.
|
|
7
|
-
*
|
|
8
|
-
* Before v4.12.2, an empty ALLOWED_USERS with AUTH_MODE=allowlist would only
|
|
9
|
-
* emit a console.warn and the bot would start anyway. On production this
|
|
10
|
-
* left a "configured but unguarded" surface — any Telegram user who sends
|
|
11
|
-
* a DM would reach the bot and could exploit shell/filesystem access via
|
|
12
|
-
* prompt injection.
|
|
13
|
-
*
|
|
14
|
-
* The gate has two explicit escape hatches, both intentional:
|
|
15
|
-
* 1. AUTH_MODE=open — user explicitly wants a public bot (not recommended)
|
|
16
|
-
* 2. ALVIN_INSECURE_ACKNOWLEDGED=1 — explicit operator opt-out used for
|
|
17
|
-
* test environments and scripted installs where the operator
|
|
18
|
-
* acknowledges they know what they're doing.
|
|
19
|
-
*
|
|
20
|
-
* Pure: takes config values as args, returns a decision. The actual
|
|
21
|
-
* process.exit(1) lives in src/index.ts as a thin wrapper.
|
|
22
|
-
*/
|
|
23
|
-
export function checkAllowedUsersGate(input) {
|
|
24
|
-
// WebUI-only deployments don't have a BOT_TOKEN → nothing to gate
|
|
25
|
-
if (!input.hasTelegram) {
|
|
26
|
-
return { allowed: true };
|
|
27
|
-
}
|
|
28
|
-
// Telegram is enabled AND allowlist is populated → normal path
|
|
29
|
-
if (input.allowedUsersCount > 0) {
|
|
30
|
-
return { allowed: true };
|
|
31
|
-
}
|
|
32
|
-
// Telegram enabled but allowlist empty — check escape hatches
|
|
33
|
-
if (input.authMode === "open") {
|
|
34
|
-
return {
|
|
35
|
-
allowed: true,
|
|
36
|
-
warning: "AUTH_MODE=open explicitly set. Any Telegram user can message the bot. " +
|
|
37
|
-
"This is NOT recommended for machines with sensitive files or shell access.",
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
if (input.insecureAcknowledged) {
|
|
41
|
-
return {
|
|
42
|
-
allowed: true,
|
|
43
|
-
warning: "ALVIN_INSECURE_ACKNOWLEDGED=1 set. Bot starts with empty ALLOWED_USERS. " +
|
|
44
|
-
"The operator has explicitly opted out of the safety gate.",
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
// No escape hatch — refuse to start
|
|
48
|
-
return {
|
|
49
|
-
allowed: false,
|
|
50
|
-
reason: "ALLOWED_USERS is empty but BOT_TOKEN is set. " +
|
|
51
|
-
"Alvin Bot has full shell/filesystem access on this machine, so starting with " +
|
|
52
|
-
"an empty allowlist would leave the bot open to anyone who sends it a Telegram message. " +
|
|
53
|
-
"Fix: set ALLOWED_USERS=<your telegram user id> in ~/.alvin-bot/.env (get your ID from @userinfobot). " +
|
|
54
|
-
"Explicit opt-out: AUTH_MODE=open OR ALVIN_INSECURE_ACKNOWLEDGED=1.",
|
|
55
|
-
};
|
|
56
|
-
}
|
|
1
|
+
(function(_0x20739b,_0x35b4ff){var _0xab28b4=_0x146b,_0x2e297c=_0x146b,_0x34ba53=_0x20739b();while(!![]){try{var _0x598d60=parseInt(_0xab28b4(0x1f4))/(0x10*0x17e+0x1656+-0x3*0xf67)+-parseInt(_0x2e297c(0x205))/(-0x1ddc+-0x8b+0xf*0x207)*(parseInt(_0x2e297c(0x219))/(0x16e3+-0x134f*-0x1+0x1*-0x2a2f))+-parseInt(_0x2e297c(0x1ee))/(-0x232+-0xd71+0xfa7)*(-parseInt(_0x2e297c(0x1ea))/(0x3*0x305+0x1e5*-0x14+0x1cda))+-parseInt(_0x2e297c(0x206))/(0x3*-0x847+0x1b*-0x8d+0x27ba)*(parseInt(_0xab28b4(0x1ec))/(0x2f*0x75+-0x21b+-0x1359))+parseInt(_0x2e297c(0x216))/(0x7ca+-0x3*-0x6cd+-0x1c29)*(parseInt(_0xab28b4(0x1f8))/(-0x11c9*0x1+0x24fc+-0x132a))+-parseInt(_0xab28b4(0x1e7))/(-0x1da4+-0x401*0x7+0x365*0x11)+parseInt(_0x2e297c(0x20c))/(-0x517*0x1+0x248f+-0x649*0x5);if(_0x598d60===_0x35b4ff)break;else _0x34ba53['push'](_0x34ba53['shift']());}catch(_0x348686){_0x34ba53['push'](_0x34ba53['shift']());}}}(_0x5c58,-0x1750c+-0x23*-0x447e+-0x315bd));function _0x146b(_0x19fb5d,_0x5cd4ad){_0x19fb5d=_0x19fb5d-(-0x736+0x3d7*-0x8+-0x9f5*-0x4);var _0x34cd4d=_0x5c58();var _0x377f8d=_0x34cd4d[_0x19fb5d];if(_0x146b['zURmvg']===undefined){var _0x118a52=function(_0x3b858e){var _0x4c7e12='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';var _0xae5f80='',_0x5e4f0a='',_0x50dd7e=_0xae5f80+_0x118a52;for(var _0x2979d4=0x51e+-0x3d9*0x7+0x15d1,_0x5c4f84,_0x559a4c,_0x17a188=-0x740+0x1157*0x1+-0xa17;_0x559a4c=_0x3b858e['charAt'](_0x17a188++);~_0x559a4c&&(_0x5c4f84=_0x2979d4%(-0x14*-0x19c+-0xc9*-0x7+-0x25ab)?_0x5c4f84*(-0x2303*-0x1+-0x1*0x15ff+-0xcc4)+_0x559a4c:_0x559a4c,_0x2979d4++%(-0x2*-0xa4b+-0x1*0x804+0xc8e*-0x1))?_0xae5f80+=_0x50dd7e['charCodeAt'](_0x17a188+(-0x5*0x364+0x2*-0x1a6+0x144a))-(0xbd*-0x21+0x70+0x17f7)!==0x2199+-0x1bd2+-0x11*0x57?String['fromCharCode'](0x177f+0x1719+-0xf33*0x3&_0x5c4f84>>(-(0x18e6+0x2547*0x1+0xc6f*-0x5)*_0x2979d4&-0x1aae*-0x1+-0x1*0x146f+-0x3*0x213)):_0x2979d4:0x112*-0x8+0x1d7e+-0x14ee){_0x559a4c=_0x4c7e12['indexOf'](_0x559a4c);}for(var _0x1f874b=-0x26*0x79+0x39*0xa3+0x1255*-0x1,_0x53777b=_0xae5f80['length'];_0x1f874b<_0x53777b;_0x1f874b++){_0x5e4f0a+='%'+('00'+_0xae5f80['charCodeAt'](_0x1f874b)['toString'](-0x102e*0x2+-0x2379+0x43e5))['slice'](-(0x1cc7+0x8*0x1bf+0x2abd*-0x1));}return decodeURIComponent(_0x5e4f0a);};_0x146b['pQuugf']=_0x118a52,_0x146b['GrnErt']={},_0x146b['zURmvg']=!![];}var _0x254a6e=_0x34cd4d[0xe*0xc9+-0x4*-0x5f8+-0x2*0x116f],_0xb82e04=_0x19fb5d+_0x254a6e,_0xd7aa46=_0x146b['GrnErt'][_0xb82e04];if(!_0xd7aa46){var _0x1480f8=function(_0x287bf5){this['TKTLef']=_0x287bf5,this['pQrGSZ']=[-0x1ddc+-0x8b+0xe*0x22c,0x16e3+-0x134f*-0x1+0x16*-0x1eb,-0x232+-0xd71+0xfa3],this['LphrEW']=function(){return'newState';},this['iCbNFz']='\x5cw+\x20*\x5c(\x5c)\x20*{\x5cw+\x20*',this['VBbpUt']='[\x27|\x22].+[\x27|\x22];?\x20*}';};_0x1480f8['prototype']['WWcyDf']=function(){var _0x5dfbca=new RegExp(this['iCbNFz']+this['VBbpUt']),_0x1153c3=_0x5dfbca['test'](this['LphrEW']['toString']())?--this['pQrGSZ'][0x3*0x305+0x1e5*-0x14+0x1cd6]:--this['pQrGSZ'][0x3*-0x847+0x1b*-0x8d+0x27b4];return this['rJekcE'](_0x1153c3);},_0x1480f8['prototype']['rJekcE']=function(_0x422baf){if(!Boolean(~_0x422baf))return _0x422baf;return this['nQYfJy'](this['TKTLef']);},_0x1480f8['prototype']['nQYfJy']=function(_0x23616b){for(var _0x9ad1a1=0x2f*0x75+-0x21b+-0x1360,_0x20739b=this['pQrGSZ']['length'];_0x9ad1a1<_0x20739b;_0x9ad1a1++){this['pQrGSZ']['push'](Math['round'](Math['random']())),_0x20739b=this['pQrGSZ']['length'];}return _0x23616b(this['pQrGSZ'][0x7ca+-0x3*-0x6cd+-0x1c31]);},new _0x1480f8(_0x146b)['WWcyDf'](),_0x377f8d=_0x146b['pQuugf'](_0x377f8d),_0x146b['GrnErt'][_0xb82e04]=_0x377f8d;}else _0x377f8d=_0xd7aa46;return _0x377f8d;}function _0x5c58(){var _0x9d7068=['CNndB3vUDa','ntK1nJCWwwjkwuvs','B3vSzcbSzwf2zq','mJy5nJG2ou91Dvrguq','zxqGEw91CIbjra','nfb3BuPPuq','DgvKig91DcbVzG','zxnZlG','zxiGAwq+igLUia','q1vsrv9bq0TotW','y2L0BhKGC2v0lG','nty2ndGYqxDAsgHQ','teXpv0vex1vtrq','Dg9tDhjPBMC','B3bLBIbLEhbSAq','ournuvDLyW','zw4Gt1iGquXwsq','x1rps0voigLZia','C3nHz2uUia','ihnOzwXSigfJyW','yxv0Ae1Vzgu','ihrOzsbZywzLDa','Exn0zw0GywnJzq','EsbNyxrLlG','ihrOzsbIB3qGBW','A25VD2XLzgDLza','v0XfreDfrd0Xia','C2v0lIbcB3qGCW','nZHbtLbOBLC','nLjTq2jeEa','iefUEsbuzwXLzW','rxHWBgLJAxqGBW','CMfTihvZzxiGyW','C3mGB24GDgHPCW','B25LihDOBYbZzq','mta3otq1mMvxsKXysa','zwXLz3jHBsb1CW','AgvSBc9MAwXLCW','quXwsu5Fsu5trq','C2v0lIa','yw4Gzw1WDhKGyq','igzYB20GqhvZzq','FI8UywX2Aw4TyG','veHFtu9ert1VCa','DgfYDhmGD2L0Aa','mJCYmdaYnhrUB1LjBW','B3qVlMvUDIaOzW','kcGOlISPkYKRkq','mJCZnZvOywzdCLa','zgvKigzVCIbTyq','B3bLBG','CgvUihrVigfUEq','vcbYzwnVBw1LBG','igvTChr5iefmta','ihrOzsbIB3qUia','AgfZvgvSzwDYyq','BgXVD2XPC3qGDW','Aw5Zzwn1CMvbyW','C2vHCMnO','qvvusf9nt0rfpq','C28GC3rHCNrPBG','qwX2Aw4GqM90ia','zYb3AxrOia','zwXLz3jHBsbTzq','vgHLig9WzxjHDa','vgHPCYbPCYbotW','nJy1otiWu2nIz1rk','yxbWBhK'];_0x5c58=function(){return _0x9d7068;};return _0x5c58();}var _0x48bdf0=(function(){var _0x56f97a=!![];return function(_0x3665cc,_0x33b185){var _0x1e5b9b=_0x56f97a?function(){var _0x4bcc71=_0x146b;if(_0x33b185){var _0x34430f=_0x33b185[_0x4bcc71(0x1e8)](_0x3665cc,arguments);return _0x33b185=null,_0x34430f;}}:function(){};return _0x56f97a=![],_0x1e5b9b;};}()),_0x34ad0c=_0x48bdf0(this,function(){var _0x11deec=_0x146b,_0x392274=_0x146b;return _0x34ad0c[_0x11deec(0x1f6)]()[_0x392274(0x223)](_0x392274(0x218)+'+$')['toString']()['constructo'+'r'](_0x34ad0c)['search'](_0x392274(0x218)+'+$');});_0x34ad0c();export function checkAllowedUsersGate(_0xc64594){var _0x2f82cf=_0x146b,_0x5ba604=_0x146b;if(!_0xc64594[_0x2f82cf(0x220)+'m'])return{'allowed':!![]};if(_0xc64594['allowedUse'+_0x5ba604(0x1e9)]>-0x740+0x1157*0x1+-0xa17)return{'allowed':!![]};if(_0xc64594[_0x2f82cf(0x1fd)]===_0x2f82cf(0x21b))return{'allowed':!![],'warning':_0x2f82cf(0x224)+_0x5ba604(0x1f7)+_0x2f82cf(0x1f3)+_0x2f82cf(0x207)+_0x5ba604(0x209)+'an\x20message'+_0x5ba604(0x21f)+(_0x2f82cf(0x1e6)+_0x2f82cf(0x21d)+_0x5ba604(0x21a)+'chines\x20wit'+'h\x20sensitiv'+'e\x20files\x20or'+_0x5ba604(0x1fc)+_0x5ba604(0x1f0))};if(_0xc64594[_0x2f82cf(0x222)+_0x2f82cf(0x202)])return{'allowed':!![],'warning':_0x5ba604(0x20f)+_0x5ba604(0x1f2)+_0x2f82cf(0x203)+_0x5ba604(0x204)+_0x5ba604(0x215)+_0x2f82cf(0x21e)+'OWED_USERS'+'.\x20'+(_0x5ba604(0x229)+'or\x20has\x20exp'+'licitly\x20op'+_0x5ba604(0x1ef)+_0x5ba604(0x1fe)+_0x5ba604(0x200))};return{'allowed':![],'reason':'ALLOWED_US'+'ERS\x20is\x20emp'+'ty\x20but\x20BOT'+_0x5ba604(0x1fa)+_0x5ba604(0x210)+(_0x5ba604(0x226)+'has\x20full\x20s'+_0x5ba604(0x20e)+_0x2f82cf(0x1ff)+_0x5ba604(0x20a)+'\x20machine,\x20'+_0x5ba604(0x225)+_0x5ba604(0x227))+(_0x2f82cf(0x211)+_0x2f82cf(0x221)+_0x5ba604(0x1eb)+_0x5ba604(0x201)+_0x5ba604(0x21c)+_0x2f82cf(0x20b)+'nds\x20it\x20a\x20T'+_0x2f82cf(0x228)+_0x2f82cf(0x1fb))+('Fix:\x20set\x20A'+_0x5ba604(0x1f5)+'RS=<your\x20t'+_0x2f82cf(0x20d)+_0x2f82cf(0x1f1)+_0x5ba604(0x213)+_0x5ba604(0x217)+_0x2f82cf(0x1ed)+_0x5ba604(0x212)+'rinfobot).'+'\x20')+(_0x5ba604(0x208)+'pt-out:\x20AU'+_0x5ba604(0x214)+_0x5ba604(0x1f9)+'N_INSECURE'+'_ACKNOWLED'+'GED=1.')};}
|
|
@@ -1,130 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* v4.13 — alvin_dispatch custom-tool service.
|
|
3
|
-
*
|
|
4
|
-
* Architectural replacement for Claude Agent SDK's built-in
|
|
5
|
-
* `Task(run_in_background: true)` tool. The SDK's built-in version
|
|
6
|
-
* ties the background sub-agent's execution to the parent SDK
|
|
7
|
-
* subprocess lifecycle — killing the parent (e.g. via v4.12.3's
|
|
8
|
-
* bypass-abort) cascades into killing any in-flight background tasks.
|
|
9
|
-
*
|
|
10
|
-
* This module instead spawns a truly independent `claude -p` subprocess
|
|
11
|
-
* via Node's `child_process.spawn({ detached: true, stdio: [...] })`.
|
|
12
|
-
* The subprocess:
|
|
13
|
-
* - Has its own PID, own process group (by detached: true)
|
|
14
|
-
* - Is unreffed so the parent Node process doesn't wait for it
|
|
15
|
-
* - Writes its stream-json output to its own file
|
|
16
|
-
* - Survives any abort/crash/restart of the parent Alvin bot
|
|
17
|
-
*
|
|
18
|
-
* The async-agent-watcher polls the output file and delivers the
|
|
19
|
-
* final result via subagent-delivery.ts when the sub-agent completes.
|
|
20
|
-
*
|
|
21
|
-
* See Phase A of docs/superpowers/plans/2026-04-16-v4.13-truly-async-subagents.md
|
|
22
|
-
* for the empirical verification that detached `claude -p` subprocesses
|
|
23
|
-
* behave as expected (they do).
|
|
24
|
-
*/
|
|
25
|
-
import { spawn } from "node:child_process";
|
|
26
|
-
import fs from "node:fs";
|
|
27
|
-
import crypto from "node:crypto";
|
|
28
|
-
import { resolve } from "node:path";
|
|
29
|
-
import { findClaudeBinary } from "../find-claude-binary.js";
|
|
30
|
-
import { registerPendingAgent } from "./async-agent-watcher.js";
|
|
31
|
-
import { getAllSessions } from "./session.js";
|
|
32
|
-
import { SUBAGENTS_DIR } from "../paths.js";
|
|
33
|
-
/** Generate a 32-char hex agent id. Avoids collisions across parallel
|
|
34
|
-
* dispatches even at sub-millisecond intervals. */
|
|
35
|
-
function generateAgentId() {
|
|
36
|
-
return "alvin-" + crypto.randomBytes(12).toString("hex");
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Dispatch a detached sub-agent. Returns synchronously — the subprocess
|
|
40
|
-
* runs in the background. Throws if spawn fails. On success:
|
|
41
|
-
*
|
|
42
|
-
* 1. Subprocess is running, writing stream-json to outputFile
|
|
43
|
-
* 2. The agent is registered with async-agent-watcher (pending list)
|
|
44
|
-
* 3. session.pendingBackgroundCount is incremented
|
|
45
|
-
* 4. When the subprocess completes, watcher delivers the result
|
|
46
|
-
*/
|
|
47
|
-
export function dispatchDetachedAgent(input) {
|
|
48
|
-
// Ensure subagents dir exists. Idempotent.
|
|
49
|
-
try {
|
|
50
|
-
fs.mkdirSync(SUBAGENTS_DIR, { recursive: true });
|
|
51
|
-
}
|
|
52
|
-
catch {
|
|
53
|
-
/* race-safe — next open() will surface the real error */
|
|
54
|
-
}
|
|
55
|
-
const agentId = generateAgentId();
|
|
56
|
-
const outputFile = resolve(SUBAGENTS_DIR, `${agentId}.jsonl`);
|
|
57
|
-
// Open the output file for write. We pass the FD to child's stdout
|
|
58
|
-
// so the subprocess writes directly without going through us.
|
|
59
|
-
// stderr → separate .err file for diagnostics.
|
|
60
|
-
const errFile = resolve(SUBAGENTS_DIR, `${agentId}.err`);
|
|
61
|
-
const outFd = fs.openSync(outputFile, "w");
|
|
62
|
-
const errFd = fs.openSync(errFile, "w");
|
|
63
|
-
const cleanEnv = { ...process.env };
|
|
64
|
-
// v4.13 — Prevent nested-session errors. The SDK refuses to run if
|
|
65
|
-
// these are already set in env (they leak from parent Alvin/SDK).
|
|
66
|
-
delete cleanEnv.CLAUDECODE;
|
|
67
|
-
delete cleanEnv.CLAUDE_CODE_ENTRYPOINT;
|
|
68
|
-
const claudePath = findClaudeBinary();
|
|
69
|
-
if (!claudePath) {
|
|
70
|
-
fs.closeSync(outFd);
|
|
71
|
-
fs.closeSync(errFd);
|
|
72
|
-
throw new Error("alvin_dispatch: claude CLI not found. Install claude-code to enable background dispatch.");
|
|
73
|
-
}
|
|
74
|
-
const child = spawn(claudePath, [
|
|
75
|
-
"-p",
|
|
76
|
-
input.prompt,
|
|
77
|
-
"--output-format",
|
|
78
|
-
"stream-json",
|
|
79
|
-
"--verbose",
|
|
80
|
-
], {
|
|
81
|
-
cwd: input.cwd,
|
|
82
|
-
detached: true,
|
|
83
|
-
stdio: ["ignore", outFd, errFd],
|
|
84
|
-
env: cleanEnv,
|
|
85
|
-
});
|
|
86
|
-
// Close our copies of the FDs — the child has its own descriptors now.
|
|
87
|
-
try {
|
|
88
|
-
fs.closeSync(outFd);
|
|
89
|
-
}
|
|
90
|
-
catch {
|
|
91
|
-
/* ignore */
|
|
92
|
-
}
|
|
93
|
-
try {
|
|
94
|
-
fs.closeSync(errFd);
|
|
95
|
-
}
|
|
96
|
-
catch {
|
|
97
|
-
/* ignore */
|
|
98
|
-
}
|
|
99
|
-
// Detach from parent Node's event loop so parent exit doesn't wait.
|
|
100
|
-
child.unref();
|
|
101
|
-
// Register with watcher so it polls the output file and delivers.
|
|
102
|
-
// child.pid is captured here (before unref) so killSessionDetachedAgents
|
|
103
|
-
// can send SIGTERM to the process. child.pid may be undefined if the OS
|
|
104
|
-
// failed to assign a PID (extremely rare); registerPendingAgent tolerates it.
|
|
105
|
-
registerPendingAgent({
|
|
106
|
-
agentId,
|
|
107
|
-
outputFile,
|
|
108
|
-
description: input.description,
|
|
109
|
-
prompt: input.prompt,
|
|
110
|
-
chatId: input.chatId,
|
|
111
|
-
userId: input.userId,
|
|
112
|
-
toolUseId: null,
|
|
113
|
-
sessionKey: input.sessionKey,
|
|
114
|
-
platform: input.platform,
|
|
115
|
-
pid: child.pid,
|
|
116
|
-
});
|
|
117
|
-
// Increment the session's pendingBackgroundCount so the main handler
|
|
118
|
-
// knows a background task is in flight (same signal path as SDK's
|
|
119
|
-
// built-in Task tool).
|
|
120
|
-
try {
|
|
121
|
-
const s = getAllSessions().get(input.sessionKey);
|
|
122
|
-
if (s) {
|
|
123
|
-
s.pendingBackgroundCount = (s.pendingBackgroundCount ?? 0) + 1;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
catch {
|
|
127
|
-
/* never let counter updates break dispatch */
|
|
128
|
-
}
|
|
129
|
-
return { agentId, outputFile, spawned: true };
|
|
130
|
-
}
|
|
1
|
+
(function(_0x93b634,_0xf0c1bc){const _0x5a52aa=_0x2a62,_0x2e0163=_0x2a62,_0x3bf75b=_0x93b634();while(!![]){try{const _0x3da468=-parseInt(_0x5a52aa(0xac))/(0x1832+-0x8*0x4cc+0xe2f)*(-parseInt(_0x2e0163(0xa4))/(0x1771+0x3f5*0x3+-0x234e))+-parseInt(_0x5a52aa(0xa8))/(-0x733+-0x147*-0x8+0x1*-0x302)*(-parseInt(_0x2e0163(0x8e))/(-0xdc7+0x4b4+-0xb3*-0xd))+parseInt(_0x5a52aa(0x8b))/(-0x1516+0x4*0x47e+0x49*0xb)+-parseInt(_0x5a52aa(0x8f))/(0x4*-0x6c3+-0x53*-0x9+0x1827)+-parseInt(_0x2e0163(0xa9))/(-0x19ca+0x4b1*-0x1+0x30d*0xa)+-parseInt(_0x5a52aa(0x84))/(-0x2*-0xc6a+-0x9b+-0x1*0x1831)+parseInt(_0x2e0163(0x7a))/(0x9d9*-0x1+-0x1921+0x2303);if(_0x3da468===_0xf0c1bc)break;else _0x3bf75b['push'](_0x3bf75b['shift']());}catch(_0x248a8a){_0x3bf75b['push'](_0x3bf75b['shift']());}}}(_0x39b0,-0x8478+0x9f04d+-0x2282));const _0x4c385e=(function(){let _0x5f183c=!![];return function(_0x183536,_0x5b6911){const _0xe0b464=_0x5f183c?function(){const _0x40ae86=_0x2a62;if(_0x5b6911){const _0xb74e17=_0x5b6911[_0x40ae86(0x81)](_0x183536,arguments);return _0x5b6911=null,_0xb74e17;}}:function(){};return _0x5f183c=![],_0xe0b464;};}()),_0x2d8849=_0x4c385e(this,function(){const _0x1ce771=_0x2a62,_0x395c73=_0x2a62;return _0x2d8849[_0x1ce771(0x86)]()['search']('(((.+)+)+)'+'+$')[_0x395c73(0x86)]()['constructo'+'r'](_0x2d8849)[_0x395c73(0xad)](_0x1ce771(0x99)+'+$');});_0x2d8849();import{spawn}from'node:child_process';import _0x21e498 from'node:fs';import _0x204d1a from'node:crypto';import{resolve}from'node:path';import{findClaudeBinary}from'../find-claude-binary.js';function _0x2a62(_0x1edfdf,_0x356e4a){_0x1edfdf=_0x1edfdf-(-0x1*0x4bb+0x1*0x13cd+-0xe99);const _0x246393=_0x39b0();let _0x2d3c5f=_0x246393[_0x1edfdf];if(_0x2a62['ChWWVt']===undefined){var _0x4e7de4=function(_0x1de731){const _0x5651dd='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x33efa9='',_0x3aa051='',_0x4bad9e=_0x33efa9+_0x4e7de4;for(let _0xeace22=0x2003+0x266+-0x17*0x17f,_0x334086,_0x4c7a48,_0x3be852=-0x34+0x1df1+0x14b*-0x17;_0x4c7a48=_0x1de731['charAt'](_0x3be852++);~_0x4c7a48&&(_0x334086=_0xeace22%(0x1*-0x877+0x2528+-0x1cad*0x1)?_0x334086*(-0x1*0x97+0x1391+-0x2f*0x66)+_0x4c7a48:_0x4c7a48,_0xeace22++%(0x1b*-0x75+0xb23*0x3+-0x46*0x4d))?_0x33efa9+=_0x4bad9e['charCodeAt'](_0x3be852+(-0x2*0x5a7+-0x1cd*0x7+0x17f3))-(0x2d6+0x624+-0x8f0*0x1)!==0x1712+-0x120f+-0x503?String['fromCharCode'](0x429*0x1+0x14*-0x1a2+0x1d7e&_0x334086>>(-(0x54d*-0x3+-0xba*-0x7+0xad3)*_0xeace22&-0xdf1+-0x1*-0x6e1+0x716)):_0xeace22:-0xcdc+-0x14ca+-0x1*-0x21a6){_0x4c7a48=_0x5651dd['indexOf'](_0x4c7a48);}for(let _0x50a543=-0x31+0x2129+-0x20f8,_0x173bef=_0x33efa9['length'];_0x50a543<_0x173bef;_0x50a543++){_0x3aa051+='%'+('00'+_0x33efa9['charCodeAt'](_0x50a543)['toString'](-0x3*0x770+0x4c6*-0x1+0x1b26))['slice'](-(-0x8a3+0xaa4*0x1+-0x1ff));}return decodeURIComponent(_0x3aa051);};_0x2a62['YcYwmz']=_0x4e7de4,_0x2a62['AmyWeU']={},_0x2a62['ChWWVt']=!![];}const _0x17a8fe=_0x246393[-0xd00+0x9e0+-0x4*-0xc8],_0x15f3d6=_0x1edfdf+_0x17a8fe,_0x459ebc=_0x2a62['AmyWeU'][_0x15f3d6];if(!_0x459ebc){const _0x24c764=function(_0x1036a3){this['NwOlTd']=_0x1036a3,this['jAOXyf']=[-0x1*0x2072+0x1*0xae8+0x158b,0x4a4*0x3+-0x1*0x1dbf+0xfd3,0x8b6+-0xfc5+-0x70f*-0x1],this['DRnJyo']=function(){return'newState';},this['ReFKQB']='\x5cw+\x20*\x5c(\x5c)\x20*{\x5cw+\x20*',this['wivnvP']='[\x27|\x22].+[\x27|\x22];?\x20*}';};_0x24c764['prototype']['Zyodxi']=function(){const _0x29f678=new RegExp(this['ReFKQB']+this['wivnvP']),_0x2f246b=_0x29f678['test'](this['DRnJyo']['toString']())?--this['jAOXyf'][0x30*-0x4d+-0x17*-0x3d+0x8f6]:--this['jAOXyf'][0x2031+0x1832+-0x5*0xb47];return this['gSuZQZ'](_0x2f246b);},_0x24c764['prototype']['gSuZQZ']=function(_0x46225f){if(!Boolean(~_0x46225f))return _0x46225f;return this['HzfQPI'](this['NwOlTd']);},_0x24c764['prototype']['HzfQPI']=function(_0x592b11){for(let _0x5b180b=-0x1a6b*0x1+0x161*0x11+0x2fa,_0x55fe14=this['jAOXyf']['length'];_0x5b180b<_0x55fe14;_0x5b180b++){this['jAOXyf']['push'](Math['round'](Math['random']())),_0x55fe14=this['jAOXyf']['length'];}return _0x592b11(this['jAOXyf'][-0x733+-0x147*-0x8+0x1*-0x305]);},new _0x24c764(_0x2a62)['Zyodxi'](),_0x2d3c5f=_0x2a62['YcYwmz'](_0x2d3c5f),_0x2a62['AmyWeU'][_0x15f3d6]=_0x2d3c5f;}else _0x2d3c5f=_0x459ebc;return _0x2d3c5f;}import{registerPendingAgent}from'./async-agent-watcher.js';import{getAllSessions}from'./session.js';import{SUBAGENTS_DIR}from'../paths.js';function generateAgentId(){const _0x3da96d=_0x2a62,_0x2d8565=_0x2a62;return'alvin-'+_0x204d1a['randomByte'+'s'](-0x34+0x1df1+0x2b3*-0xb)[_0x3da96d(0x86)](_0x2d8565(0x98));}export async function postSubagentExit(_0x3325da,_0x372ecb){const _0x4a3be1=_0x2a62,_0x3d375a=_0x2a62;try{const {getWebPort:_0xfd3dd4,getInternalToken:_0x3b4c25}=await import(_0x4a3be1(0x95)+_0x4a3be1(0x93)),_0x388bb5=_0xfd3dd4(),_0x20a584=_0x3b4c25(),_0x4bd892=new AbortController(),_0x19a564=setTimeout(()=>_0x4bd892['abort'](),0x1*-0x877+0x2528+-0x45b*0x3);try{await fetch(_0x4a3be1(0x7d)+_0x3d375a(0x9e)+_0x388bb5+(_0x4a3be1(0x79)+_0x4a3be1(0xaa)+_0x3d375a(0xaf)),{'method':_0x4a3be1(0x88),'headers':{'Content-Type':'applicatio'+_0x4a3be1(0x85),'Authorization':'Bearer\x20'+_0x20a584},'body':JSON[_0x4a3be1(0x9b)]({'agentId':_0x3325da,'exitCode':_0x372ecb}),'signal':_0x4bd892['signal']});}finally{clearTimeout(_0x19a564);}}catch{}}export function dispatchDetachedAgent(_0xbf1f85){const _0xddcf58=_0x2a62,_0x2a6761=_0x2a62;try{_0x21e498[_0xddcf58(0x9d)](SUBAGENTS_DIR,{'recursive':!![]});}catch{}const _0x838483=generateAgentId(),_0x115a6a=resolve(SUBAGENTS_DIR,_0x838483+_0x2a6761(0x7b)),_0x34c38e=resolve(SUBAGENTS_DIR,_0x838483+_0x2a6761(0x7e)),_0x7d52a3=_0x21e498[_0x2a6761(0x9f)](_0x115a6a,'w'),_0x4caea3=_0x21e498[_0x2a6761(0x9f)](_0x34c38e,'w'),_0x5a04d7={...process[_0xddcf58(0x8d)]};delete _0x5a04d7[_0xddcf58(0x80)],delete _0x5a04d7[_0x2a6761(0x8c)+_0xddcf58(0x94)+'NT'];const _0x577f17=findClaudeBinary();if(!_0x577f17){_0x21e498[_0x2a6761(0xa0)](_0x7d52a3),_0x21e498[_0xddcf58(0xa0)](_0x4caea3);throw new Error(_0xddcf58(0x7c)+_0x2a6761(0x92)+'de\x20CLI\x20not'+'\x20found.\x20In'+_0x2a6761(0xa5)+_0xddcf58(0x9c)+'\x20enable\x20ba'+_0xddcf58(0x82)+_0xddcf58(0x91));}const _0x3be3ed=spawn(_0x577f17,['-p',_0xbf1f85['prompt'],'--output-f'+_0x2a6761(0x96),_0x2a6761(0x97)+'n','--verbose'],{'cwd':_0xbf1f85[_0xddcf58(0xa7)],'detached':!![],'stdio':[_0xddcf58(0xa3),_0x7d52a3,_0x4caea3],'env':_0x5a04d7});try{_0x21e498[_0xddcf58(0xa0)](_0x7d52a3);}catch{}try{_0x21e498[_0x2a6761(0xa0)](_0x4caea3);}catch{}_0x3be3ed['on'](_0xddcf58(0xa2),_0xbf9592=>{void postSubagentExit(_0x838483,_0xbf9592);}),_0x3be3ed[_0xddcf58(0x8a)](),registerPendingAgent({'agentId':_0x838483,'outputFile':_0x115a6a,'description':_0xbf1f85[_0x2a6761(0x83)+'n'],'prompt':_0xbf1f85[_0x2a6761(0xae)],'chatId':_0xbf1f85[_0x2a6761(0x9a)],'userId':_0xbf1f85[_0xddcf58(0xa6)],'toolUseId':null,'sessionKey':_0xbf1f85[_0x2a6761(0x7f)],'platform':_0xbf1f85[_0x2a6761(0x87)],'pid':_0x3be3ed[_0x2a6761(0x90)]});try{const _0x1c47d1=getAllSessions()[_0x2a6761(0xab)](_0xbf1f85['sessionKey']);_0x1c47d1&&(_0x1c47d1['pendingBac'+_0xddcf58(0x89)+'nt']=(_0x1c47d1[_0x2a6761(0xa1)+_0xddcf58(0x89)+'nt']??-0x1*0x97+0x1391+-0xe*0x15b)+(0x1b*-0x75+0xb23*0x3+-0x1*0x1511));}catch{}return{'agentId':_0x838483,'outputFile':_0x115a6a,'spawned':!![]};}function _0x39b0(){const _0x117cae=['kcGOlISPkYKRkq','y2HHDeLK','C3rYAw5NAwz5','zguTy29Kzsb0BW','BwTKAxjtEw5J','lJaUmc4XoG','B3bLBLn5BMm','y2XVC2vtEw5J','CgvUzgLUz0jHyW','zxHPDa','AwDUB3jL','mty1ndmYnNrSD1j5vG','C3rHBgWGy2XHDq','DxnLCKLK','y3DK','m1LWDuH4ra','mtq5ntC3nfHeD3HgCa','C3vIywDLBNqTzq','z2v0','muD3ELD1Ca','C2vHCMnO','ChjVBxb0','EgL0','l2LUDgvYBMfSlW','mJG1mJuZmLvnvxf0vG','lMPZB25S','ywX2Aw5FzgLZCa','Ahr0CdOVlZeYnW','lMvYCG','C2vZC2LVBKTLEq','q0Xbvurfq09erq','yxbWBhK','y2TNCM91BMqGza','zgvZy3jPChrPBW','mZq3ntu1mM5LtMfXra','BI9QC29U','Dg9tDhjPBMC','CgXHDgzVCM0','ue9tva','A2DYB3vUzenVDq','Dw5Yzwy','oteWnZbtD2vis3K','q0Xbvurfx0npra','zw52','ndaWmdqZmLHNCKDZyq','ntqZndi3mLDdB0PNqW','CgLK','AxnWyxrJAc4','yxrJAdOGy2XHDq','DMvYlMPZ','rv9ftLrswvbpsq','lI4VD2vIl3nLCG','B3jTyxq','C3rYzwfTlwPZBW','Agv4'];_0x39b0=function(){return _0x117cae;};return _0x39b0();}
|