beecork 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/dist/cli/commands.d.ts +14 -0
- package/dist/cli/commands.d.ts.map +1 -0
- package/dist/cli/commands.js +215 -0
- package/dist/cli/commands.js.map +1 -0
- package/dist/cli/helpers.d.ts +4 -0
- package/dist/cli/helpers.d.ts.map +1 -0
- package/dist/cli/helpers.js +46 -0
- package/dist/cli/helpers.js.map +1 -0
- package/dist/cli/setup.d.ts +2 -0
- package/dist/cli/setup.d.ts.map +1 -0
- package/dist/cli/setup.js +145 -0
- package/dist/cli/setup.js.map +1 -0
- package/dist/config.d.ts +9 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +97 -0
- package/dist/config.js.map +1 -0
- package/dist/cron/scheduler.d.ts +20 -0
- package/dist/cron/scheduler.d.ts.map +1 -0
- package/dist/cron/scheduler.js +151 -0
- package/dist/cron/scheduler.js.map +1 -0
- package/dist/cron/store.d.ts +12 -0
- package/dist/cron/store.d.ts.map +1 -0
- package/dist/cron/store.js +82 -0
- package/dist/cron/store.js.map +1 -0
- package/dist/daemon.d.ts +2 -0
- package/dist/daemon.d.ts.map +1 -0
- package/dist/daemon.js +140 -0
- package/dist/daemon.js.map +1 -0
- package/dist/db/index.d.ts +4 -0
- package/dist/db/index.d.ts.map +1 -0
- package/dist/db/index.js +66 -0
- package/dist/db/index.js.map +1 -0
- package/dist/db/migrations.d.ts +3 -0
- package/dist/db/migrations.d.ts.map +1 -0
- package/dist/db/migrations.js +85 -0
- package/dist/db/migrations.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +66 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/server.d.ts +3 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +304 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/memory/extractor.d.ts +6 -0
- package/dist/memory/extractor.d.ts.map +1 -0
- package/dist/memory/extractor.js +105 -0
- package/dist/memory/extractor.js.map +1 -0
- package/dist/service/install.d.ts +5 -0
- package/dist/service/install.d.ts.map +1 -0
- package/dist/service/install.js +118 -0
- package/dist/service/install.js.map +1 -0
- package/dist/service/templates.d.ts +5 -0
- package/dist/service/templates.d.ts.map +1 -0
- package/dist/service/templates.js +53 -0
- package/dist/service/templates.js.map +1 -0
- package/dist/session/approval.d.ts +20 -0
- package/dist/session/approval.d.ts.map +1 -0
- package/dist/session/approval.js +59 -0
- package/dist/session/approval.js.map +1 -0
- package/dist/session/circuit-breaker.d.ts +18 -0
- package/dist/session/circuit-breaker.d.ts.map +1 -0
- package/dist/session/circuit-breaker.js +67 -0
- package/dist/session/circuit-breaker.js.map +1 -0
- package/dist/session/context-monitor.d.ts +16 -0
- package/dist/session/context-monitor.d.ts.map +1 -0
- package/dist/session/context-monitor.js +44 -0
- package/dist/session/context-monitor.js.map +1 -0
- package/dist/session/manager.d.ts +42 -0
- package/dist/session/manager.d.ts.map +1 -0
- package/dist/session/manager.js +291 -0
- package/dist/session/manager.js.map +1 -0
- package/dist/session/subprocess.d.ts +23 -0
- package/dist/session/subprocess.d.ts.map +1 -0
- package/dist/session/subprocess.js +119 -0
- package/dist/session/subprocess.js.map +1 -0
- package/dist/session/tool-classifier.d.ts +4 -0
- package/dist/session/tool-classifier.d.ts.map +1 -0
- package/dist/session/tool-classifier.js +57 -0
- package/dist/session/tool-classifier.js.map +1 -0
- package/dist/telegram/bot.d.ts +25 -0
- package/dist/telegram/bot.d.ts.map +1 -0
- package/dist/telegram/bot.js +293 -0
- package/dist/telegram/bot.js.map +1 -0
- package/dist/telegram/formatter.d.ts +11 -0
- package/dist/telegram/formatter.d.ts.map +1 -0
- package/dist/telegram/formatter.js +54 -0
- package/dist/telegram/formatter.js.map +1 -0
- package/dist/types.d.ts +131 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/util/logger.d.ts +17 -0
- package/dist/util/logger.d.ts.map +1 -0
- package/dist/util/logger.js +56 -0
- package/dist/util/logger.js.map +1 -0
- package/dist/util/paths.d.ts +11 -0
- package/dist/util/paths.d.ts.map +1 -0
- package/dist/util/paths.js +40 -0
- package/dist/util/paths.js.map +1 -0
- package/dist/util/platform.d.ts +3 -0
- package/dist/util/platform.d.ts.map +1 -0
- package/dist/util/platform.js +10 -0
- package/dist/util/platform.js.map +1 -0
- package/dist/util/retry.d.ts +3 -0
- package/dist/util/retry.d.ts.map +1 -0
- package/dist/util/retry.js +19 -0
- package/dist/util/retry.js.map +1 -0
- package/dist/whatsapp/client.d.ts +23 -0
- package/dist/whatsapp/client.d.ts.map +1 -0
- package/dist/whatsapp/client.js +125 -0
- package/dist/whatsapp/client.js.map +1 -0
- package/dist/whatsapp/formatter.d.ts +3 -0
- package/dist/whatsapp/formatter.d.ts.map +1 -0
- package/dist/whatsapp/formatter.js +25 -0
- package/dist/whatsapp/formatter.js.map +1 -0
- package/package.json +53 -0
- package/templates/CLAUDE.md +25 -0
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import TelegramBot from 'node-telegram-bot-api';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { chunkText, formatTabStatus } from './formatter.js';
|
|
5
|
+
import { logger } from '../util/logger.js';
|
|
6
|
+
import { retryWithBackoff } from '../util/retry.js';
|
|
7
|
+
import { getTabConfig, getAdminUserId, validateTabName } from '../config.js';
|
|
8
|
+
import { getLogsDir } from '../util/paths.js';
|
|
9
|
+
export class BeecorkTelegramBot {
|
|
10
|
+
bot;
|
|
11
|
+
tabManager;
|
|
12
|
+
config;
|
|
13
|
+
activeChatIds = new Set();
|
|
14
|
+
// Debounce: collect messages within a window before sending
|
|
15
|
+
debounceTimers = new Map();
|
|
16
|
+
debounceBuffers = new Map();
|
|
17
|
+
constructor(config, tabManager) {
|
|
18
|
+
this.config = config;
|
|
19
|
+
this.tabManager = tabManager;
|
|
20
|
+
this.bot = new TelegramBot(config.telegram.token, { polling: true });
|
|
21
|
+
this.setupHandlers();
|
|
22
|
+
logger.info('Telegram bot started (polling mode)');
|
|
23
|
+
}
|
|
24
|
+
setupHandlers() {
|
|
25
|
+
this.bot.on('message', async (msg) => {
|
|
26
|
+
if (!this.isAllowed(msg.from?.id))
|
|
27
|
+
return;
|
|
28
|
+
const chatId = msg.chat.id;
|
|
29
|
+
this.activeChatIds.add(chatId);
|
|
30
|
+
const text = msg.text?.trim();
|
|
31
|
+
if (!text)
|
|
32
|
+
return;
|
|
33
|
+
try {
|
|
34
|
+
// Commands bypass debouncing
|
|
35
|
+
if (text.startsWith('/')) {
|
|
36
|
+
await this.handleCommand(chatId, text, msg.from?.id, msg.message_id);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
// Regular messages: debounce
|
|
40
|
+
const { tabName } = this.parseMessage(text);
|
|
41
|
+
const debounceMs = getTabConfig(tabName).debounceMs ?? 3000;
|
|
42
|
+
const key = `${chatId}:${tabName}`;
|
|
43
|
+
// Buffer the message
|
|
44
|
+
if (!this.debounceBuffers.has(key)) {
|
|
45
|
+
this.debounceBuffers.set(key, { messages: [], chatId, messageId: msg.message_id });
|
|
46
|
+
}
|
|
47
|
+
this.debounceBuffers.get(key).messages.push(text);
|
|
48
|
+
// Reset timer
|
|
49
|
+
const existingTimer = this.debounceTimers.get(key);
|
|
50
|
+
if (existingTimer)
|
|
51
|
+
clearTimeout(existingTimer);
|
|
52
|
+
this.debounceTimers.set(key, setTimeout(() => {
|
|
53
|
+
this.debounceTimers.delete(key);
|
|
54
|
+
const buffer = this.debounceBuffers.get(key);
|
|
55
|
+
this.debounceBuffers.delete(key);
|
|
56
|
+
if (buffer) {
|
|
57
|
+
const combined = buffer.messages.join('\n\n');
|
|
58
|
+
this.handleMessage(buffer.chatId, combined, buffer.messageId).catch(err => {
|
|
59
|
+
logger.error('Telegram: error handling debounced message:', err);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}, debounceMs));
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
logger.error('Telegram: error handling message:', err);
|
|
66
|
+
await this.bot.sendMessage(chatId, `Error: ${err instanceof Error ? err.message : String(err)}`);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
async handleCommand(chatId, text, userId, messageId) {
|
|
71
|
+
if (text === '/tabs' || text.startsWith('/tabs@')) {
|
|
72
|
+
const tabs = this.tabManager.listTabs();
|
|
73
|
+
const formatted = formatTabStatus(tabs);
|
|
74
|
+
await this.bot.sendMessage(chatId, formatted);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (text.startsWith('/stop ')) {
|
|
78
|
+
if (!this.isAdmin(userId)) {
|
|
79
|
+
await this.bot.sendMessage(chatId, 'Only admin can stop tabs.');
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const tabName = text.slice(6).trim();
|
|
83
|
+
this.tabManager.stopTab(tabName);
|
|
84
|
+
await this.bot.sendMessage(chatId, `Stopped tab: ${tabName}`);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (text.startsWith('/tab ')) {
|
|
88
|
+
// Validate tab name
|
|
89
|
+
const rest = text.slice(5);
|
|
90
|
+
const spaceIdx = rest.indexOf(' ');
|
|
91
|
+
if (spaceIdx > 0) {
|
|
92
|
+
const tabName = rest.slice(0, spaceIdx);
|
|
93
|
+
const validationError = validateTabName(tabName);
|
|
94
|
+
if (validationError) {
|
|
95
|
+
await this.bot.sendMessage(chatId, `Invalid tab name: ${validationError}`);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// Fall through to handleMessage
|
|
100
|
+
await this.handleMessage(chatId, text, messageId);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
// Unknown command — treat as regular message
|
|
104
|
+
await this.handleMessage(chatId, text, messageId);
|
|
105
|
+
}
|
|
106
|
+
async handleMessage(chatId, text, messageId) {
|
|
107
|
+
const { tabName, prompt } = this.parseMessage(text);
|
|
108
|
+
if (!prompt)
|
|
109
|
+
return;
|
|
110
|
+
// React with ⏳
|
|
111
|
+
await this.setReaction(chatId, messageId, '⏳');
|
|
112
|
+
// Typing indicator
|
|
113
|
+
await this.bot.sendChatAction(chatId, 'typing');
|
|
114
|
+
const typingInterval = setInterval(() => {
|
|
115
|
+
this.bot.sendChatAction(chatId, 'typing').catch(() => { });
|
|
116
|
+
}, 4000);
|
|
117
|
+
// "Still working" timeout
|
|
118
|
+
const stillWorkingTimeout = setTimeout(() => {
|
|
119
|
+
this.bot.sendMessage(chatId, `Still working on your request in tab "${tabName}"...`).catch(() => { });
|
|
120
|
+
}, 120000); // 2 minutes
|
|
121
|
+
// Streaming: track the message we edit in-place
|
|
122
|
+
let sentMessageId = null;
|
|
123
|
+
let accumulatedText = '';
|
|
124
|
+
let lastEditTime = 0;
|
|
125
|
+
const onTextChunk = async (chunk) => {
|
|
126
|
+
accumulatedText += chunk;
|
|
127
|
+
// Buffer at least 100 chars and throttle edits to 1/second
|
|
128
|
+
const now = Date.now();
|
|
129
|
+
if (accumulatedText.length < 100 || now - lastEditTime < 1000)
|
|
130
|
+
return;
|
|
131
|
+
lastEditTime = now;
|
|
132
|
+
try {
|
|
133
|
+
const preview = accumulatedText.slice(0, 4000) + (accumulatedText.length > 4000 ? '...' : '');
|
|
134
|
+
const prefix = tabName !== 'default' ? `[${tabName}] ` : '';
|
|
135
|
+
if (!sentMessageId) {
|
|
136
|
+
const sent = await this.bot.sendMessage(chatId, prefix + preview);
|
|
137
|
+
sentMessageId = sent.message_id;
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
await this.bot.editMessageText(prefix + preview, { chat_id: chatId, message_id: sentMessageId });
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
catch { /* edit failures are non-critical */ }
|
|
144
|
+
};
|
|
145
|
+
try {
|
|
146
|
+
const result = await this.tabManager.sendMessage(tabName, prompt, { onTextChunk });
|
|
147
|
+
clearInterval(typingInterval);
|
|
148
|
+
clearTimeout(stillWorkingTimeout);
|
|
149
|
+
if (result.error) {
|
|
150
|
+
await this.setReaction(chatId, messageId, '❌');
|
|
151
|
+
await this.bot.sendMessage(chatId, `Error in tab "${tabName}":\n${result.text}`);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
// React with ✅
|
|
155
|
+
await this.setReaction(chatId, messageId, '✅');
|
|
156
|
+
// Send final response (or edit the streaming message)
|
|
157
|
+
const responseText = result.text || '(empty response)';
|
|
158
|
+
if (sentMessageId) {
|
|
159
|
+
// Edit final content into streaming message
|
|
160
|
+
try {
|
|
161
|
+
const prefix = tabName !== 'default' ? `[${tabName}] ` : '';
|
|
162
|
+
const finalText = prefix + responseText;
|
|
163
|
+
if (finalText.length <= 4096) {
|
|
164
|
+
await this.bot.editMessageText(finalText, { chat_id: chatId, message_id: sentMessageId });
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
// Too long for edit, send as new messages
|
|
168
|
+
await this.sendResponse(chatId, responseText, tabName);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
await this.sendResponse(chatId, responseText, tabName);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
await this.sendResponse(chatId, responseText, tabName);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
catch (err) {
|
|
180
|
+
clearInterval(typingInterval);
|
|
181
|
+
clearTimeout(stillWorkingTimeout);
|
|
182
|
+
await this.setReaction(chatId, messageId, '❌');
|
|
183
|
+
throw err;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
parseMessage(text) {
|
|
187
|
+
if (text.startsWith('/tab ')) {
|
|
188
|
+
const rest = text.slice(5);
|
|
189
|
+
const spaceIdx = rest.indexOf(' ');
|
|
190
|
+
if (spaceIdx === -1)
|
|
191
|
+
return { tabName: rest, prompt: '' };
|
|
192
|
+
return { tabName: rest.slice(0, spaceIdx), prompt: rest.slice(spaceIdx + 1).trim() };
|
|
193
|
+
}
|
|
194
|
+
return { tabName: 'default', prompt: text };
|
|
195
|
+
}
|
|
196
|
+
async sendResponse(chatId, text, tabName) {
|
|
197
|
+
const prefix = tabName && tabName !== 'default' ? `[${tabName}] ` : '';
|
|
198
|
+
const fullText = prefix + text;
|
|
199
|
+
const chunks = chunkText(fullText);
|
|
200
|
+
// For very long outputs: send first 3 chunks + file
|
|
201
|
+
if (chunks.length > 10) {
|
|
202
|
+
for (let i = 0; i < 3; i++) {
|
|
203
|
+
await this.sendWithRetry(chatId, chunks[i]);
|
|
204
|
+
}
|
|
205
|
+
// Send rest as file
|
|
206
|
+
const tmpPath = path.join(getLogsDir(), `response-${Date.now()}.txt`);
|
|
207
|
+
fs.writeFileSync(tmpPath, fullText);
|
|
208
|
+
await this.bot.sendDocument(chatId, tmpPath, { caption: `Full response (${chunks.length} chunks)` });
|
|
209
|
+
fs.unlinkSync(tmpPath);
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
for (const chunk of chunks) {
|
|
213
|
+
await this.sendWithRetry(chatId, chunk);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
async sendWithRetry(chatId, text) {
|
|
217
|
+
try {
|
|
218
|
+
await retryWithBackoff(async () => {
|
|
219
|
+
try {
|
|
220
|
+
await this.bot.sendMessage(chatId, text, { parse_mode: 'Markdown' });
|
|
221
|
+
}
|
|
222
|
+
catch {
|
|
223
|
+
await this.bot.sendMessage(chatId, text); // Fallback to plain text
|
|
224
|
+
}
|
|
225
|
+
}, [1000, 5000, 15000], 'telegram-send');
|
|
226
|
+
}
|
|
227
|
+
catch (err) {
|
|
228
|
+
// Log to delivery failures
|
|
229
|
+
const failLog = path.join(getLogsDir(), 'delivery-failures.log');
|
|
230
|
+
const entry = `[${new Date().toISOString()}] chatId=${chatId} error=${err instanceof Error ? err.message : err} text=${text.slice(0, 200)}\n`;
|
|
231
|
+
fs.appendFileSync(failLog, entry);
|
|
232
|
+
logger.error(`Delivery failed after retries for chat ${chatId}`);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
/** Send a notification to all allowed users */
|
|
236
|
+
async sendNotification(text) {
|
|
237
|
+
for (const chatId of this.activeChatIds) {
|
|
238
|
+
try {
|
|
239
|
+
await this.bot.sendMessage(chatId, text);
|
|
240
|
+
}
|
|
241
|
+
catch (err) {
|
|
242
|
+
logger.error(`Failed to send notification to chat ${chatId}:`, err);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
for (const userId of this.config.telegram.allowedUserIds) {
|
|
246
|
+
if (this.activeChatIds.has(userId))
|
|
247
|
+
continue;
|
|
248
|
+
try {
|
|
249
|
+
await this.bot.sendMessage(userId, text);
|
|
250
|
+
this.activeChatIds.add(userId);
|
|
251
|
+
}
|
|
252
|
+
catch { /* User hasn't started conversation yet */ }
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
stop() {
|
|
256
|
+
this.bot.stopPolling();
|
|
257
|
+
// Clear all debounce timers
|
|
258
|
+
for (const timer of this.debounceTimers.values())
|
|
259
|
+
clearTimeout(timer);
|
|
260
|
+
this.debounceTimers.clear();
|
|
261
|
+
this.debounceBuffers.clear();
|
|
262
|
+
logger.info('Telegram bot stopped');
|
|
263
|
+
}
|
|
264
|
+
isAllowed(userId) {
|
|
265
|
+
if (!userId)
|
|
266
|
+
return false;
|
|
267
|
+
return this.config.telegram.allowedUserIds.includes(userId);
|
|
268
|
+
}
|
|
269
|
+
isAdmin(userId) {
|
|
270
|
+
if (!userId)
|
|
271
|
+
return false;
|
|
272
|
+
return userId === getAdminUserId();
|
|
273
|
+
}
|
|
274
|
+
/** Set emoji reaction on a message via raw Telegram API */
|
|
275
|
+
async setReaction(chatId, messageId, emoji) {
|
|
276
|
+
try {
|
|
277
|
+
const url = `https://api.telegram.org/bot${this.config.telegram.token}/setMessageReaction`;
|
|
278
|
+
await fetch(url, {
|
|
279
|
+
method: 'POST',
|
|
280
|
+
headers: { 'Content-Type': 'application/json' },
|
|
281
|
+
body: JSON.stringify({
|
|
282
|
+
chat_id: chatId,
|
|
283
|
+
message_id: messageId,
|
|
284
|
+
reaction: [{ type: 'emoji', emoji }],
|
|
285
|
+
}),
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
catch {
|
|
289
|
+
// Reactions not supported or failed — non-critical
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
//# sourceMappingURL=bot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bot.js","sourceRoot":"","sources":["../../src/telegram/bot.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC7E,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAI9C,MAAM,OAAO,kBAAkB;IACrB,GAAG,CAAc;IACjB,UAAU,CAAa;IACvB,MAAM,CAAgB;IACtB,aAAa,GAAgB,IAAI,GAAG,EAAE,CAAC;IAC/C,4DAA4D;IACpD,cAAc,GAAgC,IAAI,GAAG,EAAE,CAAC;IACxD,eAAe,GAA2E,IAAI,GAAG,EAAE,CAAC;IAE5G,YAAY,MAAqB,EAAE,UAAsB;QACvD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,GAAG,GAAG,IAAI,WAAW,CAAC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ACf,UAAU,EAAE,SAAS;oBACrB,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;iBACrC,CAAC;aACH,CAAC,CAAC;QACL,CAAC;QAAC,MAAM,CAAC;YACP,mDAAmD;QACrD,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Split long text into chunks that fit within Telegram's message limit */
|
|
2
|
+
export declare function chunkText(text: string, maxLength?: number): string[];
|
|
3
|
+
/** Escape special characters for Telegram MarkdownV2 */
|
|
4
|
+
export declare function escapeMarkdownV2(text: string): string;
|
|
5
|
+
/** Format a tab status message */
|
|
6
|
+
export declare function formatTabStatus(tabs: Array<{
|
|
7
|
+
name: string;
|
|
8
|
+
status: string;
|
|
9
|
+
lastActivityAt: string;
|
|
10
|
+
}>): string;
|
|
11
|
+
//# sourceMappingURL=formatter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../src/telegram/formatter.ts"],"names":[],"mappings":"AAEA,2EAA2E;AAC3E,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,GAAE,MAA4B,GAAG,MAAM,EAAE,CA4BzF;AAED,wDAAwD;AACxD,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAErD;AAED,kCAAkC;AAClC,wBAAgB,eAAe,CAAC,IAAI,EAAE,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,MAAM,CAM7G"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
const TELEGRAM_MAX_LENGTH = 4096;
|
|
2
|
+
/** Split long text into chunks that fit within Telegram's message limit */
|
|
3
|
+
export function chunkText(text, maxLength = TELEGRAM_MAX_LENGTH) {
|
|
4
|
+
if (text.length <= maxLength)
|
|
5
|
+
return [text];
|
|
6
|
+
const chunks = [];
|
|
7
|
+
let remaining = text;
|
|
8
|
+
while (remaining.length > 0) {
|
|
9
|
+
if (remaining.length <= maxLength) {
|
|
10
|
+
chunks.push(remaining);
|
|
11
|
+
break;
|
|
12
|
+
}
|
|
13
|
+
// Try to break at a newline
|
|
14
|
+
let breakPoint = remaining.lastIndexOf('\n', maxLength);
|
|
15
|
+
if (breakPoint <= 0 || breakPoint < maxLength * 0.5) {
|
|
16
|
+
// Try to break at a space
|
|
17
|
+
breakPoint = remaining.lastIndexOf(' ', maxLength);
|
|
18
|
+
}
|
|
19
|
+
if (breakPoint <= 0 || breakPoint < maxLength * 0.5) {
|
|
20
|
+
// Hard break
|
|
21
|
+
breakPoint = maxLength;
|
|
22
|
+
}
|
|
23
|
+
chunks.push(remaining.slice(0, breakPoint));
|
|
24
|
+
remaining = remaining.slice(breakPoint).trimStart();
|
|
25
|
+
}
|
|
26
|
+
return chunks;
|
|
27
|
+
}
|
|
28
|
+
/** Escape special characters for Telegram MarkdownV2 */
|
|
29
|
+
export function escapeMarkdownV2(text) {
|
|
30
|
+
return text.replace(/([_*\[\]()~`>#+\-=|{}.!\\])/g, '\\$1');
|
|
31
|
+
}
|
|
32
|
+
/** Format a tab status message */
|
|
33
|
+
export function formatTabStatus(tabs) {
|
|
34
|
+
if (tabs.length === 0)
|
|
35
|
+
return 'No tabs.';
|
|
36
|
+
return tabs.map(t => {
|
|
37
|
+
const ago = timeAgo(t.lastActivityAt);
|
|
38
|
+
return `• ${t.name} [${t.status}] — ${ago}`;
|
|
39
|
+
}).join('\n');
|
|
40
|
+
}
|
|
41
|
+
function timeAgo(isoDate) {
|
|
42
|
+
const diff = Date.now() - new Date(isoDate).getTime();
|
|
43
|
+
const mins = Math.floor(diff / 60000);
|
|
44
|
+
if (mins < 1)
|
|
45
|
+
return 'just now';
|
|
46
|
+
if (mins < 60)
|
|
47
|
+
return `${mins}m ago`;
|
|
48
|
+
const hours = Math.floor(mins / 60);
|
|
49
|
+
if (hours < 24)
|
|
50
|
+
return `${hours}h ago`;
|
|
51
|
+
const days = Math.floor(hours / 24);
|
|
52
|
+
return `${days}d ago`;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=formatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatter.js","sourceRoot":"","sources":["../../src/telegram/formatter.ts"],"names":[],"mappings":"AAAA,MAAM,mBAAmB,GAAG,IAAI,CAAC;AAEjC,2EAA2E;AAC3E,MAAM,UAAU,SAAS,CAAC,IAAY,EAAE,YAAoB,mBAAmB;IAC7E,IAAI,IAAI,CAAC,MAAM,IAAI,SAAS;QAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAE5C,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,IAAI,SAAS,GAAG,IAAI,CAAC;IAErB,OAAO,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC5B,IAAI,SAAS,CAAC,MAAM,IAAI,SAAS,EAAE,CAAC;YAClC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACvB,MAAM;QACR,CAAC;QAED,4BAA4B;QAC5B,IAAI,UAAU,GAAG,SAAS,CAAC,WAAW,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QACxD,IAAI,UAAU,IAAI,CAAC,IAAI,UAAU,GAAG,SAAS,GAAG,GAAG,EAAE,CAAC;YACpD,0BAA0B;YAC1B,UAAU,GAAG,SAAS,CAAC,WAAW,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;QACrD,CAAC;QACD,IAAI,UAAU,IAAI,CAAC,IAAI,UAAU,GAAG,SAAS,GAAG,GAAG,EAAE,CAAC;YACpD,aAAa;YACb,UAAU,GAAG,SAAS,CAAC;QACzB,CAAC;QAED,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC;QAC5C,SAAS,GAAG,SA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AC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
export interface TelegramConfig {
|
|
2
|
+
token: string;
|
|
3
|
+
allowedUserIds: number[];
|
|
4
|
+
adminUserId?: number;
|
|
5
|
+
}
|
|
6
|
+
export interface ClaudeCodeConfig {
|
|
7
|
+
bin: string;
|
|
8
|
+
defaultFlags: string[];
|
|
9
|
+
maxBudgetUsd?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface MemoryConfig {
|
|
12
|
+
enabled: boolean;
|
|
13
|
+
dbPath: string;
|
|
14
|
+
maxLongTermEntries: number;
|
|
15
|
+
}
|
|
16
|
+
export interface TabConfig {
|
|
17
|
+
workingDir: string;
|
|
18
|
+
approvalMode: ApprovalMode;
|
|
19
|
+
approvalTimeoutMinutes: number;
|
|
20
|
+
debounceMs: number;
|
|
21
|
+
systemPrompt?: string;
|
|
22
|
+
}
|
|
23
|
+
export type ApprovalMode = 'yolo' | 'ask' | 'auto-safe';
|
|
24
|
+
export interface WhatsAppConfig {
|
|
25
|
+
enabled: boolean;
|
|
26
|
+
mode: 'baileys';
|
|
27
|
+
sessionPath: string;
|
|
28
|
+
allowedNumbers: string[];
|
|
29
|
+
}
|
|
30
|
+
export interface BeecorkConfig {
|
|
31
|
+
telegram: TelegramConfig;
|
|
32
|
+
whatsapp?: WhatsAppConfig;
|
|
33
|
+
claudeCode: ClaudeCodeConfig;
|
|
34
|
+
tabs: Record<string, TabConfig>;
|
|
35
|
+
memory: MemoryConfig;
|
|
36
|
+
deployment: 'local' | 'vps';
|
|
37
|
+
}
|
|
38
|
+
export type TabStatus = 'idle' | 'running' | 'error' | 'stopped';
|
|
39
|
+
export interface Tab {
|
|
40
|
+
id: string;
|
|
41
|
+
name: string;
|
|
42
|
+
sessionId: string;
|
|
43
|
+
status: TabStatus;
|
|
44
|
+
workingDir: string;
|
|
45
|
+
createdAt: string;
|
|
46
|
+
lastActivityAt: string;
|
|
47
|
+
pid: number | null;
|
|
48
|
+
}
|
|
49
|
+
export interface StreamInit {
|
|
50
|
+
type: 'system';
|
|
51
|
+
subtype: 'init';
|
|
52
|
+
session_id: string;
|
|
53
|
+
tools: string[];
|
|
54
|
+
mcp_servers: string[];
|
|
55
|
+
model: string;
|
|
56
|
+
}
|
|
57
|
+
export interface StreamContentText {
|
|
58
|
+
type: 'text';
|
|
59
|
+
text: string;
|
|
60
|
+
}
|
|
61
|
+
export interface StreamContentToolUse {
|
|
62
|
+
type: 'tool_use';
|
|
63
|
+
id: string;
|
|
64
|
+
name: string;
|
|
65
|
+
input: Record<string, unknown>;
|
|
66
|
+
}
|
|
67
|
+
export interface StreamContentToolResult {
|
|
68
|
+
type: 'tool_result';
|
|
69
|
+
tool_use_id: string;
|
|
70
|
+
content: string;
|
|
71
|
+
}
|
|
72
|
+
export type StreamContentBlock = StreamContentText | StreamContentToolUse | StreamContentToolResult;
|
|
73
|
+
export interface StreamAssistant {
|
|
74
|
+
type: 'assistant';
|
|
75
|
+
message: {
|
|
76
|
+
id: string;
|
|
77
|
+
role: 'assistant';
|
|
78
|
+
content: StreamContentBlock[];
|
|
79
|
+
stop_reason: string;
|
|
80
|
+
usage: StreamUsage;
|
|
81
|
+
};
|
|
82
|
+
session_id: string;
|
|
83
|
+
}
|
|
84
|
+
export interface StreamResult {
|
|
85
|
+
type: 'result';
|
|
86
|
+
subtype: 'success' | 'error';
|
|
87
|
+
is_error: boolean;
|
|
88
|
+
duration_ms: number;
|
|
89
|
+
result: string;
|
|
90
|
+
session_id: string;
|
|
91
|
+
total_cost_usd: number;
|
|
92
|
+
usage: StreamUsage;
|
|
93
|
+
}
|
|
94
|
+
export interface StreamUsage {
|
|
95
|
+
input_tokens: number;
|
|
96
|
+
output_tokens: number;
|
|
97
|
+
cache_creation_input_tokens: number;
|
|
98
|
+
cache_read_input_tokens: number;
|
|
99
|
+
}
|
|
100
|
+
export type StreamEvent = StreamInit | StreamAssistant | StreamResult;
|
|
101
|
+
export type CronScheduleType = 'at' | 'every' | 'cron';
|
|
102
|
+
export interface CronJob {
|
|
103
|
+
id: string;
|
|
104
|
+
name: string;
|
|
105
|
+
scheduleType: CronScheduleType;
|
|
106
|
+
schedule: string;
|
|
107
|
+
tabName: string;
|
|
108
|
+
message: string;
|
|
109
|
+
enabled: boolean;
|
|
110
|
+
createdAt: string;
|
|
111
|
+
lastRunAt: string | null;
|
|
112
|
+
nextRunAt: string | null;
|
|
113
|
+
}
|
|
114
|
+
export interface Memory {
|
|
115
|
+
id: number;
|
|
116
|
+
content: string;
|
|
117
|
+
tabName: string | null;
|
|
118
|
+
createdAt: string;
|
|
119
|
+
source: 'tool' | 'auto';
|
|
120
|
+
}
|
|
121
|
+
export interface CircuitBreakerConfig {
|
|
122
|
+
maxRepeats: number;
|
|
123
|
+
windowSize: number;
|
|
124
|
+
}
|
|
125
|
+
export interface ApprovalRequest {
|
|
126
|
+
tabName: string;
|
|
127
|
+
toolName: string;
|
|
128
|
+
toolArgs: Record<string, unknown>;
|
|
129
|
+
description: string;
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,kBAAkB,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,SAAS;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,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GAAG,IAAI,GAAG,OAAO,GAAG,MAAM,CAAC;AAEvD,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,gBAAgB,CAAC;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAID,MAAM,WAAW,MAAM;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;CACzB;AAID,MAAM,WAAW,oBAAoB;IACnC,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB;AAID,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,WAAW,EAAE,MAAM,CAAC;CACrB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,iBAAiB"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
2
|
+
declare class Logger {
|
|
3
|
+
private minLevel;
|
|
4
|
+
private logFile;
|
|
5
|
+
private stream;
|
|
6
|
+
setLevel(level: LogLevel): void;
|
|
7
|
+
setLogFile(name: string): void;
|
|
8
|
+
private write;
|
|
9
|
+
debug(msg: string, ...args: unknown[]): void;
|
|
10
|
+
info(msg: string, ...args: unknown[]): void;
|
|
11
|
+
warn(msg: string, ...args: unknown[]): void;
|
|
12
|
+
error(msg: string, ...args: unknown[]): void;
|
|
13
|
+
close(): void;
|
|
14
|
+
}
|
|
15
|
+
export declare const logger: Logger;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/util/logger.ts"],"names":[],"mappings":"AAIA,KAAK,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AASpD,cAAM,MAAM;IACV,OAAO,CAAC,QAAQ,CAAoB;IACpC,OAAO,CAAC,OAAO,CAAuB;IACtC,OAAO,CAAC,MAAM,CAA+B;IAE7C,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;IAI/B,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAO9B,OAAO,CAAC,KAAK;IAsBb,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAC5C,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAC3C,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAC3C,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAE5C,KAAK,IAAI,IAAI;CAMd;AAED,eAAO,MAAM,MAAM,QAAe,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { getLogsDir } from './paths.js';
|
|
4
|
+
const LEVEL_PRIORITY = {
|
|
5
|
+
debug: 0,
|
|
6
|
+
info: 1,
|
|
7
|
+
warn: 2,
|
|
8
|
+
error: 3,
|
|
9
|
+
};
|
|
10
|
+
class Logger {
|
|
11
|
+
minLevel = 'info';
|
|
12
|
+
logFile = null;
|
|
13
|
+
stream = null;
|
|
14
|
+
setLevel(level) {
|
|
15
|
+
this.minLevel = level;
|
|
16
|
+
}
|
|
17
|
+
setLogFile(name) {
|
|
18
|
+
const dir = getLogsDir();
|
|
19
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
20
|
+
this.logFile = path.join(dir, name);
|
|
21
|
+
this.stream = fs.createWriteStream(this.logFile, { flags: 'a' });
|
|
22
|
+
}
|
|
23
|
+
write(level, msg, ...args) {
|
|
24
|
+
if (LEVEL_PRIORITY[level] < LEVEL_PRIORITY[this.minLevel])
|
|
25
|
+
return;
|
|
26
|
+
const timestamp = new Date().toISOString();
|
|
27
|
+
const prefix = `[${timestamp}] [${level.toUpperCase()}]`;
|
|
28
|
+
const line = args.length > 0
|
|
29
|
+
? `${prefix} ${msg} ${args.map(a => typeof a === 'string' ? a : JSON.stringify(a)).join(' ')}`
|
|
30
|
+
: `${prefix} ${msg}`;
|
|
31
|
+
if (this.stream) {
|
|
32
|
+
this.stream.write(line + '\n');
|
|
33
|
+
}
|
|
34
|
+
if (level === 'error') {
|
|
35
|
+
console.error(line);
|
|
36
|
+
}
|
|
37
|
+
else if (level === 'warn') {
|
|
38
|
+
console.warn(line);
|
|
39
|
+
}
|
|
40
|
+
else if (level !== 'debug') {
|
|
41
|
+
console.log(line);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
debug(msg, ...args) { this.write('debug', msg, ...args); }
|
|
45
|
+
info(msg, ...args) { this.write('info', msg, ...args); }
|
|
46
|
+
warn(msg, ...args) { this.write('warn', msg, ...args); }
|
|
47
|
+
error(msg, ...args) { this.write('error', msg, ...args); }
|
|
48
|
+
close() {
|
|
49
|
+
if (this.stream) {
|
|
50
|
+
this.stream.end();
|
|
51
|
+
this.stream = null;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export const logger = new Logger();
|
|
56
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/util/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAIxC,MAAM,cAAc,GAA6B;IAC/C,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;CACT,CAAC;AAEF,MAAM,MAAM;IACF,QAAQ,GAAa,MAAM,CAAC;IAC5B,OAAO,GAAkB,IAAI,CAAC;IAC9B,MAAM,GAA0B,IAAI,CAAC;IAE7C,QAAQ,CAAC,KAAe;QACtB,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;IACxB,CAAC;IAED,UAAU,CAAC,IAAY;QACrB,MAAM,GAAG,GAAG,UAAU,EAAE,CAAC;QACzB,EAAE,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACvC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QACpC,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC,iBAAiB,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;IACnE,CAAC;IAEO,KAAK,CAAC,KAAe,EAAE,GAAW,EAAE,GAAG,IAAe;QAC5D,IAAI,cAAc,CAAC,KAAK,CAAC,GAAG,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC;YAAE,OAAO;QAElE,MAAM,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC,WA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AM,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IACjF,KAAK,CAAC,GAAW,EAAE,GAAG,IAAe,IAAU,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IAEnF,KAAK;QACH,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;YAClB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACrB,CAAC;IACH,CAAC;CACF;AAED,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare function getBeecorkHome(): string;
|
|
2
|
+
export declare function getConfigPath(): string;
|
|
3
|
+
export declare function getDbPath(): string;
|
|
4
|
+
export declare function getCrontabPath(): string;
|
|
5
|
+
export declare function getMcpConfigPath(): string;
|
|
6
|
+
export declare function getLogsDir(): string;
|
|
7
|
+
export declare function getPidPath(): string;
|
|
8
|
+
export declare function getCronReloadSignalPath(): string;
|
|
9
|
+
export declare function ensureBeecorkDirs(): void;
|
|
10
|
+
export declare function expandHome(p: string): string;
|
|
11
|
+
//# sourceMappingURL=paths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../src/util/paths.ts"],"names":[],"mappings":"AAMA,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAED,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAED,wBAAgB,SAAS,IAAI,MAAM,CAElC;AAED,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAED,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAED,wBAAgB,UAAU,IAAI,MAAM,CAEnC;AAED,wBAAgB,UAAU,IAAI,MAAM,CAEnC;AAED,wBAAgB,uBAAuB,IAAI,MAAM,CAEhD;AAED,wBAAgB,iBAAiB,IAAI,IAAI,CAIxC;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAK5C"}
|