teleton 0.8.3 → 0.8.4

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.
@@ -1,6 +1,9 @@
1
1
  import {
2
2
  TELEGRAM_MAX_MESSAGE_LENGTH
3
3
  } from "./chunk-C4NKJT2Z.js";
4
+ import {
5
+ getProviderMetadata
6
+ } from "./chunk-6OOHHJ4N.js";
4
7
  import {
5
8
  TELETON_ROOT,
6
9
  WORKSPACE_PATHS,
@@ -10,97 +13,11 @@ import {
10
13
  createLogger
11
14
  } from "./chunk-NQ6FZKCE.js";
12
15
 
13
- // src/workspace/manager.ts
14
- import { existsSync, mkdirSync, readFileSync, writeFileSync, copyFileSync } from "fs";
15
- import { join, dirname } from "path";
16
- import { fileURLToPath } from "url";
17
- var log = createLogger("Workspace");
18
- function findPackageRoot() {
19
- let dir = dirname(fileURLToPath(import.meta.url));
20
- for (let i = 0; i < 10; i++) {
21
- if (existsSync(join(dir, "package.json"))) return dir;
22
- dir = dirname(dir);
23
- }
24
- return process.cwd();
25
- }
26
- var TEMPLATES_DIR = join(findPackageRoot(), "src", "templates");
27
- async function ensureWorkspace(config) {
28
- const silent = config?.silent ?? false;
29
- if (!existsSync(TELETON_ROOT)) {
30
- mkdirSync(TELETON_ROOT, { recursive: true });
31
- if (!silent) log.info(`Created Teleton root at ${TELETON_ROOT}`);
32
- }
33
- if (!existsSync(WORKSPACE_ROOT)) {
34
- mkdirSync(WORKSPACE_ROOT, { recursive: true });
35
- if (!silent) log.info(`Created workspace at ${WORKSPACE_ROOT}`);
36
- }
37
- const directories = [
38
- WORKSPACE_PATHS.MEMORY_DIR,
39
- WORKSPACE_PATHS.DOWNLOADS_DIR,
40
- WORKSPACE_PATHS.UPLOADS_DIR,
41
- WORKSPACE_PATHS.TEMP_DIR,
42
- WORKSPACE_PATHS.MEMES_DIR
43
- ];
44
- for (const dir of directories) {
45
- if (!existsSync(dir)) {
46
- mkdirSync(dir, { recursive: true });
47
- }
48
- }
49
- const workspace = {
50
- root: TELETON_ROOT,
51
- workspace: WORKSPACE_ROOT,
52
- // Workspace files
53
- soulPath: WORKSPACE_PATHS.SOUL,
54
- memoryPath: WORKSPACE_PATHS.MEMORY,
55
- identityPath: WORKSPACE_PATHS.IDENTITY,
56
- userPath: WORKSPACE_PATHS.USER,
57
- strategyPath: WORKSPACE_PATHS.STRATEGY,
58
- securityPath: WORKSPACE_PATHS.SECURITY,
59
- // Workspace directories
60
- memoryDir: WORKSPACE_PATHS.MEMORY_DIR,
61
- downloadsDir: WORKSPACE_PATHS.DOWNLOADS_DIR,
62
- uploadsDir: WORKSPACE_PATHS.UPLOADS_DIR,
63
- tempDir: WORKSPACE_PATHS.TEMP_DIR,
64
- memesDir: WORKSPACE_PATHS.MEMES_DIR,
65
- // Protected files (outside workspace)
66
- sessionPath: join(TELETON_ROOT, "telegram_session.txt"),
67
- configPath: join(TELETON_ROOT, "config.yaml"),
68
- walletPath: join(TELETON_ROOT, "wallet.json")
69
- };
70
- if (config?.ensureTemplates) {
71
- await bootstrapTemplates(workspace, silent);
72
- }
73
- return workspace;
74
- }
75
- async function bootstrapTemplates(workspace, silent = false) {
76
- const templates = [
77
- { name: "SOUL.md", path: workspace.soulPath },
78
- { name: "MEMORY.md", path: workspace.memoryPath },
79
- { name: "IDENTITY.md", path: workspace.identityPath },
80
- { name: "USER.md", path: workspace.userPath },
81
- { name: "SECURITY.md", path: workspace.securityPath },
82
- { name: "STRATEGY.md", path: workspace.strategyPath }
83
- ];
84
- for (const template of templates) {
85
- if (!existsSync(template.path)) {
86
- const templateSource = join(TEMPLATES_DIR, template.name);
87
- if (existsSync(templateSource)) {
88
- copyFileSync(templateSource, template.path);
89
- if (!silent) log.info(`Created ${template.name}`);
90
- }
91
- }
92
- }
93
- }
94
- function isNewWorkspace(workspace) {
95
- return !existsSync(workspace.configPath);
96
- }
97
- function loadTemplate(name) {
98
- const templatePath = join(TEMPLATES_DIR, name);
99
- if (!existsSync(templatePath)) {
100
- throw new Error(`Template ${name} not found at ${templatePath}`);
101
- }
102
- return readFileSync(templatePath, "utf-8");
103
- }
16
+ // src/config/loader.ts
17
+ import { readFileSync, existsSync, writeFileSync, mkdirSync } from "fs";
18
+ import { parse, stringify } from "yaml";
19
+ import { homedir } from "os";
20
+ import { dirname, join } from "path";
104
21
 
105
22
  // src/config/schema.ts
106
23
  import { z } from "zod";
@@ -292,9 +209,224 @@ var ConfigSchema = z.object({
292
209
  tavily_api_key: z.string().optional().describe("Tavily API key for web search & extract (free at https://tavily.com)")
293
210
  });
294
211
 
212
+ // src/config/loader.ts
213
+ var log = createLogger("Config");
214
+ var DEFAULT_CONFIG_PATH = join(TELETON_ROOT, "config.yaml");
215
+ function expandPath(path) {
216
+ if (path.startsWith("~")) {
217
+ return join(homedir(), path.slice(1));
218
+ }
219
+ return path;
220
+ }
221
+ function loadConfig(configPath = DEFAULT_CONFIG_PATH) {
222
+ const fullPath = expandPath(configPath);
223
+ if (!existsSync(fullPath)) {
224
+ throw new Error(`Config file not found: ${fullPath}
225
+ Run 'teleton setup' to create one.`);
226
+ }
227
+ let content;
228
+ try {
229
+ content = readFileSync(fullPath, "utf-8");
230
+ } catch (error) {
231
+ throw new Error(`Cannot read config file ${fullPath}: ${error.message}`);
232
+ }
233
+ let raw;
234
+ try {
235
+ raw = parse(content);
236
+ } catch (error) {
237
+ throw new Error(`Invalid YAML in ${fullPath}: ${error.message}`);
238
+ }
239
+ if (raw && typeof raw === "object" && "market" in raw) {
240
+ log.warn("config.market is deprecated and ignored. Use market-api plugin instead.");
241
+ delete raw.market;
242
+ }
243
+ const result = ConfigSchema.safeParse(raw);
244
+ if (!result.success) {
245
+ throw new Error(`Invalid config: ${result.error.message}`);
246
+ }
247
+ const config = result.data;
248
+ const provider = config.agent.provider;
249
+ if (provider !== "anthropic" && provider !== "claude-code" && !raw.agent?.model) {
250
+ const meta = getProviderMetadata(provider);
251
+ config.agent.model = meta.defaultModel;
252
+ }
253
+ config.telegram.session_path = expandPath(config.telegram.session_path);
254
+ config.storage.sessions_file = expandPath(config.storage.sessions_file);
255
+ config.storage.memory_file = expandPath(config.storage.memory_file);
256
+ if (process.env.TELETON_API_KEY) {
257
+ config.agent.api_key = process.env.TELETON_API_KEY;
258
+ }
259
+ if (process.env.TELETON_TG_API_ID) {
260
+ const apiId = parseInt(process.env.TELETON_TG_API_ID, 10);
261
+ if (isNaN(apiId)) {
262
+ throw new Error(
263
+ `Invalid TELETON_TG_API_ID environment variable: "${process.env.TELETON_TG_API_ID}" is not a valid integer`
264
+ );
265
+ }
266
+ config.telegram.api_id = apiId;
267
+ }
268
+ if (process.env.TELETON_TG_API_HASH) {
269
+ config.telegram.api_hash = process.env.TELETON_TG_API_HASH;
270
+ }
271
+ if (process.env.TELETON_TG_PHONE) {
272
+ config.telegram.phone = process.env.TELETON_TG_PHONE;
273
+ }
274
+ if (process.env.TELETON_WEBUI_ENABLED) {
275
+ config.webui.enabled = process.env.TELETON_WEBUI_ENABLED === "true";
276
+ }
277
+ if (process.env.TELETON_WEBUI_PORT) {
278
+ const port = parseInt(process.env.TELETON_WEBUI_PORT, 10);
279
+ if (!isNaN(port) && port >= 1024 && port <= 65535) {
280
+ config.webui.port = port;
281
+ }
282
+ }
283
+ if (process.env.TELETON_WEBUI_HOST) {
284
+ config.webui.host = process.env.TELETON_WEBUI_HOST;
285
+ if (!["127.0.0.1", "localhost", "::1"].includes(config.webui.host)) {
286
+ log.warn(
287
+ { host: config.webui.host },
288
+ "WebUI bound to non-loopback address \u2014 ensure auth_token is set"
289
+ );
290
+ }
291
+ }
292
+ if (process.env.TELETON_API_ENABLED) {
293
+ if (!config.api) config.api = { enabled: false, port: 7778, key_hash: "", allowed_ips: [] };
294
+ config.api.enabled = process.env.TELETON_API_ENABLED === "true";
295
+ }
296
+ if (process.env.TELETON_API_PORT) {
297
+ const port = parseInt(process.env.TELETON_API_PORT, 10);
298
+ if (!isNaN(port) && port >= 1024 && port <= 65535) {
299
+ if (!config.api) config.api = { enabled: false, port: 7778, key_hash: "", allowed_ips: [] };
300
+ config.api.port = port;
301
+ }
302
+ }
303
+ if (process.env.TELETON_BASE_URL) {
304
+ try {
305
+ new URL(process.env.TELETON_BASE_URL);
306
+ config.agent.base_url = process.env.TELETON_BASE_URL;
307
+ } catch {
308
+ throw new Error(
309
+ `Invalid TELETON_BASE_URL: "${process.env.TELETON_BASE_URL}" is not a valid URL`
310
+ );
311
+ }
312
+ }
313
+ if (process.env.TELETON_TAVILY_API_KEY) {
314
+ config.tavily_api_key = process.env.TELETON_TAVILY_API_KEY;
315
+ }
316
+ if (process.env.TELETON_TONAPI_KEY) {
317
+ config.tonapi_key = process.env.TELETON_TONAPI_KEY;
318
+ }
319
+ if (process.env.TELETON_TONCENTER_API_KEY) {
320
+ config.toncenter_api_key = process.env.TELETON_TONCENTER_API_KEY;
321
+ }
322
+ return config;
323
+ }
324
+ function configExists(configPath = DEFAULT_CONFIG_PATH) {
325
+ return existsSync(expandPath(configPath));
326
+ }
327
+ function getDefaultConfigPath() {
328
+ return DEFAULT_CONFIG_PATH;
329
+ }
330
+
331
+ // src/workspace/manager.ts
332
+ import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2, copyFileSync } from "fs";
333
+ import { join as join2, dirname as dirname2 } from "path";
334
+ import { fileURLToPath } from "url";
335
+ var log2 = createLogger("Workspace");
336
+ function findPackageRoot() {
337
+ let dir = dirname2(fileURLToPath(import.meta.url));
338
+ for (let i = 0; i < 10; i++) {
339
+ if (existsSync2(join2(dir, "package.json"))) return dir;
340
+ dir = dirname2(dir);
341
+ }
342
+ return process.cwd();
343
+ }
344
+ var TEMPLATES_DIR = join2(findPackageRoot(), "src", "templates");
345
+ async function ensureWorkspace(config) {
346
+ const silent = config?.silent ?? false;
347
+ if (!existsSync2(TELETON_ROOT)) {
348
+ mkdirSync2(TELETON_ROOT, { recursive: true });
349
+ if (!silent) log2.info(`Created Teleton root at ${TELETON_ROOT}`);
350
+ }
351
+ if (!existsSync2(WORKSPACE_ROOT)) {
352
+ mkdirSync2(WORKSPACE_ROOT, { recursive: true });
353
+ if (!silent) log2.info(`Created workspace at ${WORKSPACE_ROOT}`);
354
+ }
355
+ const directories = [
356
+ WORKSPACE_PATHS.MEMORY_DIR,
357
+ WORKSPACE_PATHS.DOWNLOADS_DIR,
358
+ WORKSPACE_PATHS.UPLOADS_DIR,
359
+ WORKSPACE_PATHS.TEMP_DIR,
360
+ WORKSPACE_PATHS.MEMES_DIR
361
+ ];
362
+ for (const dir of directories) {
363
+ if (!existsSync2(dir)) {
364
+ mkdirSync2(dir, { recursive: true });
365
+ }
366
+ }
367
+ const workspace = {
368
+ root: TELETON_ROOT,
369
+ workspace: WORKSPACE_ROOT,
370
+ // Workspace files
371
+ soulPath: WORKSPACE_PATHS.SOUL,
372
+ memoryPath: WORKSPACE_PATHS.MEMORY,
373
+ identityPath: WORKSPACE_PATHS.IDENTITY,
374
+ userPath: WORKSPACE_PATHS.USER,
375
+ strategyPath: WORKSPACE_PATHS.STRATEGY,
376
+ securityPath: WORKSPACE_PATHS.SECURITY,
377
+ // Workspace directories
378
+ memoryDir: WORKSPACE_PATHS.MEMORY_DIR,
379
+ downloadsDir: WORKSPACE_PATHS.DOWNLOADS_DIR,
380
+ uploadsDir: WORKSPACE_PATHS.UPLOADS_DIR,
381
+ tempDir: WORKSPACE_PATHS.TEMP_DIR,
382
+ memesDir: WORKSPACE_PATHS.MEMES_DIR,
383
+ // Protected files (outside workspace)
384
+ sessionPath: join2(TELETON_ROOT, "telegram_session.txt"),
385
+ configPath: join2(TELETON_ROOT, "config.yaml"),
386
+ walletPath: join2(TELETON_ROOT, "wallet.json")
387
+ };
388
+ if (config?.ensureTemplates) {
389
+ await bootstrapTemplates(workspace, silent);
390
+ }
391
+ return workspace;
392
+ }
393
+ async function bootstrapTemplates(workspace, silent = false) {
394
+ const templates = [
395
+ { name: "SOUL.md", path: workspace.soulPath },
396
+ { name: "MEMORY.md", path: workspace.memoryPath },
397
+ { name: "IDENTITY.md", path: workspace.identityPath },
398
+ { name: "USER.md", path: workspace.userPath },
399
+ { name: "SECURITY.md", path: workspace.securityPath },
400
+ { name: "STRATEGY.md", path: workspace.strategyPath }
401
+ ];
402
+ for (const template of templates) {
403
+ if (!existsSync2(template.path)) {
404
+ const templateSource = join2(TEMPLATES_DIR, template.name);
405
+ if (existsSync2(templateSource)) {
406
+ copyFileSync(templateSource, template.path);
407
+ if (!silent) log2.info(`Created ${template.name}`);
408
+ }
409
+ }
410
+ }
411
+ }
412
+ function isNewWorkspace(workspace) {
413
+ return !existsSync2(workspace.configPath);
414
+ }
415
+ function loadTemplate(name) {
416
+ const templatePath = join2(TEMPLATES_DIR, name);
417
+ if (!existsSync2(templatePath)) {
418
+ throw new Error(`Template ${name} not found at ${templatePath}`);
419
+ }
420
+ return readFileSync2(templatePath, "utf-8");
421
+ }
422
+
295
423
  export {
296
424
  DealsConfigSchema,
297
425
  ConfigSchema,
426
+ expandPath,
427
+ loadConfig,
428
+ configExists,
429
+ getDefaultConfigPath,
298
430
  ensureWorkspace,
299
431
  isNewWorkspace,
300
432
  loadTemplate
@@ -33,11 +33,9 @@ import {
33
33
  module_default,
34
34
  parseHtml,
35
35
  randomLong,
36
- readRawConfig,
37
36
  sanitizeForContext,
38
37
  sanitizeForPrompt,
39
38
  sendTon,
40
- setNestedValue,
41
39
  stripCustomEmoji,
42
40
  toGrammyKeyboard,
43
41
  toLong,
@@ -49,9 +47,8 @@ import {
49
47
  validateWritePath,
50
48
  withBlockchainRetry,
51
49
  withTxLock,
52
- writePluginSecret,
53
- writeRawConfig
54
- } from "./chunk-7MWKT67G.js";
50
+ writePluginSecret
51
+ } from "./chunk-LZQOX6YY.js";
55
52
  import {
56
53
  getCachedTonClient,
57
54
  getKeyPair,
@@ -60,15 +57,16 @@ import {
60
57
  getWalletBalance,
61
58
  invalidateTonClientCache,
62
59
  loadWallet,
63
- setToncenterApiKey
64
- } from "./chunk-FUNF6H4W.js";
60
+ readRawConfig,
61
+ setNestedValue,
62
+ setToncenterApiKey,
63
+ writeRawConfig
64
+ } from "./chunk-JROBTXWY.js";
65
65
  import {
66
66
  getDefaultConfigPath,
67
- loadConfig
68
- } from "./chunk-AEHTQI3H.js";
69
- import {
67
+ loadConfig,
70
68
  loadTemplate
71
- } from "./chunk-AERHOXGC.js";
69
+ } from "./chunk-NH2CNRKJ.js";
72
70
  import {
73
71
  ChatStore,
74
72
  JOURNAL_SCHEMA,
@@ -18241,7 +18239,7 @@ ${blue} \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u250
18241
18239
  );
18242
18240
  if (this.config.webui.enabled) {
18243
18241
  try {
18244
- const { WebUIServer } = await import("./server-N4T7E25M.js");
18242
+ const { WebUIServer } = await import("./server-AJCOURH7.js");
18245
18243
  const mcpServers = () => Object.entries(this.config.mcp.servers).map(([name, serverConfig]) => {
18246
18244
  const type = serverConfig.command ? "stdio" : serverConfig.url ? "streamable-http" : "sse";
18247
18245
  const target = serverConfig.command ?? serverConfig.url ?? "";
@@ -18294,7 +18292,7 @@ ${blue} \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u250
18294
18292
  }
18295
18293
  if (this.config.api?.enabled) {
18296
18294
  try {
18297
- const { ApiServer: ApiServerClass } = await import("./server-JF6FX772.js");
18295
+ const { ApiServer: ApiServerClass } = await import("./server-WWGVDFPW.js");
18298
18296
  const mcpServers = () => Object.entries(this.config.mcp.servers).map(([name, serverConfig]) => {
18299
18297
  const type = serverConfig.command ? "stdio" : serverConfig.url ? "streamable-http" : "sse";
18300
18298
  const target = serverConfig.command ?? serverConfig.url ?? "";
package/dist/cli/index.js CHANGED
@@ -7,34 +7,31 @@ import {
7
7
  import {
8
8
  TelegramUserClient,
9
9
  main
10
- } from "../chunk-33Z47EXI.js";
10
+ } from "../chunk-UMUONAD6.js";
11
11
  import "../chunk-NVKBBTI6.js";
12
12
  import "../chunk-H7MFXJZK.js";
13
+ import "../chunk-LZQOX6YY.js";
13
14
  import {
14
15
  CONFIGURABLE_KEYS,
15
16
  deleteNestedValue,
16
- getNestedValue,
17
- readRawConfig,
18
- setNestedValue,
19
- writeRawConfig
20
- } from "../chunk-7MWKT67G.js";
21
- import {
22
17
  generateWallet,
18
+ getNestedValue,
23
19
  importWallet,
24
20
  loadWallet,
21
+ readRawConfig,
25
22
  saveWallet,
26
- walletExists
27
- } from "../chunk-FUNF6H4W.js";
28
- import {
29
- configExists,
30
- getDefaultConfigPath
31
- } from "../chunk-AEHTQI3H.js";
23
+ setNestedValue,
24
+ walletExists,
25
+ writeRawConfig
26
+ } from "../chunk-JROBTXWY.js";
32
27
  import {
33
28
  ConfigSchema,
34
29
  DealsConfigSchema,
30
+ configExists,
35
31
  ensureWorkspace,
32
+ getDefaultConfigPath,
36
33
  isNewWorkspace
37
- } from "../chunk-AERHOXGC.js";
34
+ } from "../chunk-NH2CNRKJ.js";
38
35
  import "../chunk-XDZDOKIF.js";
39
36
  import "../chunk-GHMXWAXI.js";
40
37
  import "../chunk-ALKAAG4O.js";
@@ -391,7 +388,7 @@ function sleep(ms) {
391
388
  }
392
389
  async function onboardCommand(options = {}) {
393
390
  if (options.ui) {
394
- const { SetupServer } = await import("../setup-server-IX3BFPPH.js");
391
+ const { SetupServer } = await import("../setup-server-VDY64CWW.js");
395
392
  const port = parseInt(options.uiPort || "7777") || 7777;
396
393
  const url = `http://localhost:${port}/setup`;
397
394
  const blue2 = "\x1B[34m";
@@ -1964,7 +1961,7 @@ program.command("start").description("Start the Teleton agent").option("-c, --co
1964
1961
  if (options.jsonCredentials) {
1965
1962
  process.env.TELETON_JSON_CREDENTIALS = "true";
1966
1963
  }
1967
- const { startApiOnly } = await import("../bootstrap-DDFVEMYI.js");
1964
+ const { startApiOnly } = await import("../bootstrap-NNEI3Z5H.js");
1968
1965
  await startApiOnly({ config: options.config, apiPort: options.apiPort });
1969
1966
  return;
1970
1967
  }
package/dist/index.js CHANGED
@@ -1,13 +1,12 @@
1
1
  import {
2
2
  TeletonApp,
3
3
  main
4
- } from "./chunk-33Z47EXI.js";
4
+ } from "./chunk-UMUONAD6.js";
5
5
  import "./chunk-NVKBBTI6.js";
6
6
  import "./chunk-H7MFXJZK.js";
7
- import "./chunk-7MWKT67G.js";
8
- import "./chunk-FUNF6H4W.js";
9
- import "./chunk-AEHTQI3H.js";
10
- import "./chunk-AERHOXGC.js";
7
+ import "./chunk-LZQOX6YY.js";
8
+ import "./chunk-JROBTXWY.js";
9
+ import "./chunk-NH2CNRKJ.js";
11
10
  import "./chunk-XDZDOKIF.js";
12
11
  import "./chunk-GHMXWAXI.js";
13
12
  import "./chunk-ALKAAG4O.js";
@@ -13,12 +13,11 @@ import {
13
13
  createToolsRoutes,
14
14
  createWorkspaceRoutes,
15
15
  logInterceptor
16
- } from "./chunk-2ERTYRHA.js";
16
+ } from "./chunk-G7PCW63M.js";
17
17
  import "./chunk-WFTC3JJW.js";
18
- import "./chunk-7MWKT67G.js";
19
- import "./chunk-FUNF6H4W.js";
20
- import "./chunk-AEHTQI3H.js";
21
- import "./chunk-AERHOXGC.js";
18
+ import "./chunk-LZQOX6YY.js";
19
+ import "./chunk-JROBTXWY.js";
20
+ import "./chunk-NH2CNRKJ.js";
22
21
  import "./chunk-XDZDOKIF.js";
23
22
  import "./chunk-GHMXWAXI.js";
24
23
  import "./chunk-ALKAAG4O.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createSetupRoutes
3
- } from "./chunk-OIMAE24Q.js";
3
+ } from "./chunk-5LOHRZYY.js";
4
4
  import {
5
5
  createConfigRoutes,
6
6
  createHooksRoutes,
@@ -16,15 +16,14 @@ import {
16
16
  createToolsRoutes,
17
17
  createWorkspaceRoutes,
18
18
  logInterceptor
19
- } from "./chunk-2ERTYRHA.js";
19
+ } from "./chunk-G7PCW63M.js";
20
20
  import {
21
21
  ensureTlsCert
22
22
  } from "./chunk-5SEMA47R.js";
23
23
  import "./chunk-WFTC3JJW.js";
24
- import "./chunk-7MWKT67G.js";
25
- import "./chunk-FUNF6H4W.js";
26
- import "./chunk-AEHTQI3H.js";
27
- import "./chunk-AERHOXGC.js";
24
+ import "./chunk-LZQOX6YY.js";
25
+ import "./chunk-JROBTXWY.js";
26
+ import "./chunk-NH2CNRKJ.js";
28
27
  import "./chunk-XDZDOKIF.js";
29
28
  import "./chunk-GHMXWAXI.js";
30
29
  import "./chunk-ALKAAG4O.js";
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  createSetupRoutes
3
- } from "./chunk-OIMAE24Q.js";
3
+ } from "./chunk-5LOHRZYY.js";
4
4
  import "./chunk-WFTC3JJW.js";
5
- import "./chunk-FUNF6H4W.js";
6
- import "./chunk-AERHOXGC.js";
5
+ import "./chunk-JROBTXWY.js";
6
+ import "./chunk-NH2CNRKJ.js";
7
7
  import "./chunk-VFA7QMCZ.js";
8
8
  import "./chunk-C4NKJT2Z.js";
9
9
  import "./chunk-WTDAICGT.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teleton",
3
- "version": "0.8.3",
3
+ "version": "0.8.4",
4
4
  "workspaces": [
5
5
  "packages/*"
6
6
  ],
@@ -1,142 +0,0 @@
1
- import {
2
- ConfigSchema
3
- } from "./chunk-AERHOXGC.js";
4
- import {
5
- getProviderMetadata
6
- } from "./chunk-6OOHHJ4N.js";
7
- import {
8
- TELETON_ROOT
9
- } from "./chunk-EYWNOHMJ.js";
10
- import {
11
- createLogger
12
- } from "./chunk-NQ6FZKCE.js";
13
-
14
- // src/config/loader.ts
15
- import { readFileSync, existsSync, writeFileSync, mkdirSync } from "fs";
16
- import { parse, stringify } from "yaml";
17
- import { homedir } from "os";
18
- import { dirname, join } from "path";
19
- var log = createLogger("Config");
20
- var DEFAULT_CONFIG_PATH = join(TELETON_ROOT, "config.yaml");
21
- function expandPath(path) {
22
- if (path.startsWith("~")) {
23
- return join(homedir(), path.slice(1));
24
- }
25
- return path;
26
- }
27
- function loadConfig(configPath = DEFAULT_CONFIG_PATH) {
28
- const fullPath = expandPath(configPath);
29
- if (!existsSync(fullPath)) {
30
- throw new Error(`Config file not found: ${fullPath}
31
- Run 'teleton setup' to create one.`);
32
- }
33
- let content;
34
- try {
35
- content = readFileSync(fullPath, "utf-8");
36
- } catch (error) {
37
- throw new Error(`Cannot read config file ${fullPath}: ${error.message}`);
38
- }
39
- let raw;
40
- try {
41
- raw = parse(content);
42
- } catch (error) {
43
- throw new Error(`Invalid YAML in ${fullPath}: ${error.message}`);
44
- }
45
- if (raw && typeof raw === "object" && "market" in raw) {
46
- log.warn("config.market is deprecated and ignored. Use market-api plugin instead.");
47
- delete raw.market;
48
- }
49
- const result = ConfigSchema.safeParse(raw);
50
- if (!result.success) {
51
- throw new Error(`Invalid config: ${result.error.message}`);
52
- }
53
- const config = result.data;
54
- const provider = config.agent.provider;
55
- if (provider !== "anthropic" && provider !== "claude-code" && !raw.agent?.model) {
56
- const meta = getProviderMetadata(provider);
57
- config.agent.model = meta.defaultModel;
58
- }
59
- config.telegram.session_path = expandPath(config.telegram.session_path);
60
- config.storage.sessions_file = expandPath(config.storage.sessions_file);
61
- config.storage.memory_file = expandPath(config.storage.memory_file);
62
- if (process.env.TELETON_API_KEY) {
63
- config.agent.api_key = process.env.TELETON_API_KEY;
64
- }
65
- if (process.env.TELETON_TG_API_ID) {
66
- const apiId = parseInt(process.env.TELETON_TG_API_ID, 10);
67
- if (isNaN(apiId)) {
68
- throw new Error(
69
- `Invalid TELETON_TG_API_ID environment variable: "${process.env.TELETON_TG_API_ID}" is not a valid integer`
70
- );
71
- }
72
- config.telegram.api_id = apiId;
73
- }
74
- if (process.env.TELETON_TG_API_HASH) {
75
- config.telegram.api_hash = process.env.TELETON_TG_API_HASH;
76
- }
77
- if (process.env.TELETON_TG_PHONE) {
78
- config.telegram.phone = process.env.TELETON_TG_PHONE;
79
- }
80
- if (process.env.TELETON_WEBUI_ENABLED) {
81
- config.webui.enabled = process.env.TELETON_WEBUI_ENABLED === "true";
82
- }
83
- if (process.env.TELETON_WEBUI_PORT) {
84
- const port = parseInt(process.env.TELETON_WEBUI_PORT, 10);
85
- if (!isNaN(port) && port >= 1024 && port <= 65535) {
86
- config.webui.port = port;
87
- }
88
- }
89
- if (process.env.TELETON_WEBUI_HOST) {
90
- config.webui.host = process.env.TELETON_WEBUI_HOST;
91
- if (!["127.0.0.1", "localhost", "::1"].includes(config.webui.host)) {
92
- log.warn(
93
- { host: config.webui.host },
94
- "WebUI bound to non-loopback address \u2014 ensure auth_token is set"
95
- );
96
- }
97
- }
98
- if (process.env.TELETON_API_ENABLED) {
99
- if (!config.api) config.api = { enabled: false, port: 7778, key_hash: "", allowed_ips: [] };
100
- config.api.enabled = process.env.TELETON_API_ENABLED === "true";
101
- }
102
- if (process.env.TELETON_API_PORT) {
103
- const port = parseInt(process.env.TELETON_API_PORT, 10);
104
- if (!isNaN(port) && port >= 1024 && port <= 65535) {
105
- if (!config.api) config.api = { enabled: false, port: 7778, key_hash: "", allowed_ips: [] };
106
- config.api.port = port;
107
- }
108
- }
109
- if (process.env.TELETON_BASE_URL) {
110
- try {
111
- new URL(process.env.TELETON_BASE_URL);
112
- config.agent.base_url = process.env.TELETON_BASE_URL;
113
- } catch {
114
- throw new Error(
115
- `Invalid TELETON_BASE_URL: "${process.env.TELETON_BASE_URL}" is not a valid URL`
116
- );
117
- }
118
- }
119
- if (process.env.TELETON_TAVILY_API_KEY) {
120
- config.tavily_api_key = process.env.TELETON_TAVILY_API_KEY;
121
- }
122
- if (process.env.TELETON_TONAPI_KEY) {
123
- config.tonapi_key = process.env.TELETON_TONAPI_KEY;
124
- }
125
- if (process.env.TELETON_TONCENTER_API_KEY) {
126
- config.toncenter_api_key = process.env.TELETON_TONCENTER_API_KEY;
127
- }
128
- return config;
129
- }
130
- function configExists(configPath = DEFAULT_CONFIG_PATH) {
131
- return existsSync(expandPath(configPath));
132
- }
133
- function getDefaultConfigPath() {
134
- return DEFAULT_CONFIG_PATH;
135
- }
136
-
137
- export {
138
- expandPath,
139
- loadConfig,
140
- configExists,
141
- getDefaultConfigPath
142
- };