teleton 0.8.1 → 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/dist/{chunk-5FNWBZ5K.js → chunk-2IZU3REP.js} +147 -82
  2. package/dist/chunk-3UFPFWYP.js +12 -0
  3. package/dist/{chunk-KVXV7EF7.js → chunk-55SKE6YH.js} +2 -2
  4. package/dist/{setup-server-32XGDPE6.js → chunk-57URFK6M.js} +7 -206
  5. package/dist/chunk-5SEMA47R.js +75 -0
  6. package/dist/{chunk-S6PHGKOC.js → chunk-7YKSXOQQ.js} +10 -2
  7. package/dist/{chunk-UP55PXFH.js → chunk-C4NKJT2Z.js} +8 -0
  8. package/dist/{chunk-CGOXE4WP.js → chunk-GGXJLMOH.js} +404 -730
  9. package/dist/{chunk-QBHRXLZS.js → chunk-H7MFXJZK.js} +2 -2
  10. package/dist/{chunk-3S4GGLLR.js → chunk-HEDJCLA6.js} +58 -19
  11. package/dist/{chunk-AYWEJCDB.js → chunk-J73TA3UM.js} +7 -7
  12. package/dist/{chunk-QV2GLOTK.js → chunk-LC4TV3KL.js} +1 -1
  13. package/dist/{chunk-RCMD3U65.js → chunk-NQ6FZKCE.js} +13 -0
  14. package/dist/{chunk-7U7BOHCL.js → chunk-VYKW7FMV.js} +147 -63
  15. package/dist/chunk-W25Z7CM6.js +487 -0
  16. package/dist/{chunk-OJCLKU5Z.js → chunk-WFTC3JJW.js} +16 -0
  17. package/dist/{server-3FHI2SEB.js → chunk-XBSCYMKM.js} +23 -369
  18. package/dist/{chunk-PHSAHTK4.js → chunk-YOSUPUAJ.js} +75 -7
  19. package/dist/cli/index.js +61 -17
  20. package/dist/{client-MPHPIZB6.js → client-YOOHI776.js} +4 -4
  21. package/dist/{get-my-gifts-CC6HAVWB.js → get-my-gifts-Y7EN7RK4.js} +3 -3
  22. package/dist/index.js +14 -13
  23. package/dist/{memory-UBHM7ILG.js → memory-Q6EWGK2S.js} +6 -4
  24. package/dist/memory-hook-WUXJNVT5.js +18 -0
  25. package/dist/{migrate-UBBEJ5BL.js → migrate-WFU6COBN.js} +4 -4
  26. package/dist/server-GYZXKIKU.js +787 -0
  27. package/dist/server-YODFBZKG.js +392 -0
  28. package/dist/setup-server-IZBUOJRU.js +215 -0
  29. package/dist/{store-M5IMUQCL.js → store-7M4XV6M5.js} +5 -5
  30. package/dist/{task-dependency-resolver-RR2O5S7B.js → task-dependency-resolver-L6UUMTHK.js} +2 -2
  31. package/dist/{task-executor-6W5HRX5C.js → task-executor-XBNJLUCS.js} +2 -2
  32. package/dist/{tool-adapter-IH5VGBOO.js → tool-adapter-IVX2XQJE.js} +1 -1
  33. package/dist/{tool-index-PMAOXWUA.js → tool-index-NYH57UWP.js} +3 -3
  34. package/dist/{transcript-NGDPSNIH.js → transcript-IM7G25OS.js} +2 -2
  35. package/package.json +4 -2
  36. package/dist/chunk-XBE4JB7C.js +0 -8
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getModelsForProvider
3
- } from "./chunk-OJCLKU5Z.js";
3
+ } from "./chunk-WFTC3JJW.js";
4
4
  import {
5
5
  ConfigSchema,
6
6
  DealsConfigSchema,
@@ -11,40 +11,26 @@ import {
11
11
  isNewWorkspace,
12
12
  saveWallet,
13
13
  walletExists
14
- } from "./chunk-S6PHGKOC.js";
14
+ } from "./chunk-7YKSXOQQ.js";
15
15
  import {
16
16
  getClaudeCodeApiKey,
17
17
  getProviderMetadata,
18
18
  getSupportedProviders,
19
19
  isClaudeCodeTokenValid,
20
20
  validateApiKeyFormat
21
- } from "./chunk-PHSAHTK4.js";
22
- import "./chunk-VFA7QMCZ.js";
21
+ } from "./chunk-YOSUPUAJ.js";
23
22
  import {
24
23
  TELEGRAM_MAX_MESSAGE_LENGTH
25
- } from "./chunk-UP55PXFH.js";
24
+ } from "./chunk-C4NKJT2Z.js";
26
25
  import {
27
26
  fetchWithTimeout
28
27
  } from "./chunk-XQUHC3JZ.js";
29
- import "./chunk-R4YSJ4EY.js";
30
28
  import {
31
29
  TELETON_ROOT
32
30
  } from "./chunk-EYWNOHMJ.js";
33
31
  import {
34
32
  createLogger
35
- } from "./chunk-RCMD3U65.js";
36
- import "./chunk-3RG5ZIWI.js";
37
-
38
- // src/webui/setup-server.ts
39
- import { Hono as Hono2 } from "hono";
40
- import { serve } from "@hono/node-server";
41
- import { cors } from "hono/cors";
42
- import { bodyLimit } from "hono/body-limit";
43
- import { existsSync as existsSync3, readFileSync as readFileSync2 } from "fs";
44
- import { join as join3, dirname as dirname2, resolve, relative } from "path";
45
- import { fileURLToPath } from "url";
46
- import { exec } from "child_process";
47
- import { platform } from "os";
33
+ } from "./chunk-NQ6FZKCE.js";
48
34
 
49
35
  // src/webui/routes/setup.ts
50
36
  import { Hono } from "hono";
@@ -467,7 +453,7 @@ function createSetupRoutes() {
467
453
  app.get("/detect-claude-code-key", (c) => {
468
454
  try {
469
455
  const key = getClaudeCodeApiKey();
470
- const masked = key.slice(0, 12) + "****" + key.slice(-4);
456
+ const masked = maskKey(key);
471
457
  return c.json({
472
458
  success: true,
473
459
  data: {
@@ -871,191 +857,6 @@ function createSetupRoutes() {
871
857
  return app;
872
858
  }
873
859
 
874
- // src/webui/setup-server.ts
875
- import { randomBytes as randomBytes2 } from "crypto";
876
- import { readFileSync as readYaml, writeFileSync as writeFileSync3 } from "fs";
877
- import YAML2 from "yaml";
878
- var log3 = createLogger("Setup");
879
- function findWebDist() {
880
- const candidates = [resolve("dist/web"), resolve("web")];
881
- const __dirname = dirname2(fileURLToPath(import.meta.url));
882
- candidates.push(resolve(__dirname, "web"), resolve(__dirname, "../dist/web"));
883
- for (const candidate of candidates) {
884
- if (existsSync3(join3(candidate, "index.html"))) {
885
- return candidate;
886
- }
887
- }
888
- return null;
889
- }
890
- function autoOpenBrowser(url) {
891
- const os = platform();
892
- let cmd;
893
- if (os === "darwin") {
894
- cmd = `open "${url}"`;
895
- } else if (os === "win32") {
896
- cmd = `start "${url}"`;
897
- } else {
898
- cmd = `xdg-open "${url}"`;
899
- }
900
- exec(cmd, (err) => {
901
- if (err) {
902
- log3.info(`Open this URL in your browser: ${url}`);
903
- }
904
- });
905
- }
906
- var SetupServer = class {
907
- constructor(port = 7777) {
908
- this.port = port;
909
- this.app = new Hono2();
910
- this.launchPromise = new Promise((resolve2) => {
911
- this.launchResolve = resolve2;
912
- });
913
- this.setupMiddleware();
914
- this.setupRoutes();
915
- this.setupStaticServing();
916
- }
917
- app;
918
- server = null;
919
- launchResolve = null;
920
- launchPromise;
921
- /** Returns a promise that resolves with the auth token when the user clicks "Start Agent" */
922
- waitForLaunch() {
923
- return this.launchPromise;
924
- }
925
- setupMiddleware() {
926
- this.app.use(
927
- "*",
928
- cors({
929
- origin: [
930
- "http://localhost:5173",
931
- `http://localhost:${this.port}`,
932
- "http://127.0.0.1:5173",
933
- `http://127.0.0.1:${this.port}`
934
- ],
935
- credentials: true,
936
- allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH"],
937
- allowHeaders: ["Content-Type"],
938
- maxAge: 3600
939
- })
940
- );
941
- this.app.use(
942
- "*",
943
- bodyLimit({
944
- maxSize: 2 * 1024 * 1024,
945
- onError: (c) => c.json({ success: false, error: "Request body too large (max 2MB)" }, 413)
946
- })
947
- );
948
- this.app.use("*", async (c, next) => {
949
- await next();
950
- c.res.headers.set("X-Content-Type-Options", "nosniff");
951
- c.res.headers.set("X-Frame-Options", "DENY");
952
- c.res.headers.set("Referrer-Policy", "strict-origin-when-cross-origin");
953
- });
954
- }
955
- setupRoutes() {
956
- this.app.get("/health", (c) => c.json({ status: "ok" }));
957
- this.app.route("/api/setup", createSetupRoutes());
958
- this.app.get(
959
- "/auth/check",
960
- (c) => c.json({ success: true, data: { authenticated: false, setup: true } })
961
- );
962
- this.app.post("/api/setup/launch", async (c) => {
963
- try {
964
- const token = randomBytes2(32).toString("hex");
965
- const configPath = join3(TELETON_ROOT, "config.yaml");
966
- const raw = readYaml(configPath, "utf-8");
967
- const config = YAML2.parse(raw);
968
- config.webui = { ...config.webui || {}, enabled: true, auth_token: token };
969
- writeFileSync3(configPath, YAML2.stringify(config), { encoding: "utf-8", mode: 384 });
970
- log3.info("Launch requested \u2014 auth token generated");
971
- const resolve2 = this.launchResolve;
972
- this.launchResolve = null;
973
- if (resolve2) {
974
- setTimeout(() => resolve2(token), 500);
975
- }
976
- return c.json({ success: true, data: { token } });
977
- } catch (err) {
978
- return c.json(
979
- { success: false, error: err instanceof Error ? err.message : String(err) },
980
- 500
981
- );
982
- }
983
- });
984
- this.app.onError((err, c) => {
985
- log3.error({ err }, "Setup server error");
986
- return c.json({ success: false, error: err.message || "Internal server error" }, 500);
987
- });
988
- }
989
- setupStaticServing() {
990
- const webDist = findWebDist();
991
- if (!webDist) return;
992
- const indexHtml = readFileSync2(join3(webDist, "index.html"), "utf-8");
993
- const mimeTypes = {
994
- js: "application/javascript",
995
- css: "text/css",
996
- svg: "image/svg+xml",
997
- png: "image/png",
998
- jpg: "image/jpeg",
999
- jpeg: "image/jpeg",
1000
- ico: "image/x-icon",
1001
- json: "application/json",
1002
- woff2: "font/woff2",
1003
- woff: "font/woff"
1004
- };
1005
- this.app.get("*", (c) => {
1006
- const filePath = resolve(join3(webDist, c.req.path));
1007
- const rel = relative(webDist, filePath);
1008
- if (rel.startsWith("..") || resolve(filePath) !== filePath) {
1009
- return c.html(indexHtml);
1010
- }
1011
- try {
1012
- const content = readFileSync2(filePath);
1013
- const ext = filePath.split(".").pop() || "";
1014
- if (mimeTypes[ext]) {
1015
- const immutable = c.req.path.startsWith("/assets/");
1016
- return c.body(content, 200, {
1017
- "Content-Type": mimeTypes[ext],
1018
- "Cache-Control": immutable ? "public, max-age=31536000, immutable" : "public, max-age=3600"
1019
- });
1020
- }
1021
- } catch {
1022
- }
1023
- return c.html(indexHtml);
1024
- });
1025
- }
1026
- async start() {
1027
- return new Promise((resolve2, reject) => {
1028
- try {
1029
- this.server = serve(
1030
- {
1031
- fetch: this.app.fetch,
1032
- hostname: "127.0.0.1",
1033
- port: this.port
1034
- },
1035
- () => {
1036
- const url = `http://localhost:${this.port}/setup`;
1037
- log3.info(`Setup wizard: ${url}`);
1038
- autoOpenBrowser(url);
1039
- resolve2();
1040
- }
1041
- );
1042
- } catch (error) {
1043
- reject(error);
1044
- }
1045
- });
1046
- }
1047
- async stop() {
1048
- if (this.server) {
1049
- return new Promise((resolve2) => {
1050
- this.server.closeAllConnections();
1051
- this.server?.close(() => {
1052
- log3.info("Setup server stopped");
1053
- resolve2();
1054
- });
1055
- });
1056
- }
1057
- }
1058
- };
1059
860
  export {
1060
- SetupServer
861
+ createSetupRoutes
1061
862
  };
@@ -0,0 +1,75 @@
1
+ import {
2
+ createLogger
3
+ } from "./chunk-NQ6FZKCE.js";
4
+
5
+ // src/api/tls.ts
6
+ import { existsSync, readFileSync, writeFileSync } from "fs";
7
+ import { join } from "path";
8
+ import { createHash, X509Certificate } from "crypto";
9
+ import { generate } from "selfsigned";
10
+ var log = createLogger("TLS");
11
+ function computeFingerprint(certPem) {
12
+ const x509 = new X509Certificate(certPem);
13
+ const der = x509.raw;
14
+ return createHash("sha256").update(der).digest("hex");
15
+ }
16
+ function isCertValid(certPem) {
17
+ try {
18
+ const x509 = new X509Certificate(certPem);
19
+ const now = /* @__PURE__ */ new Date();
20
+ return now >= new Date(x509.validFrom) && now <= new Date(x509.validTo);
21
+ } catch {
22
+ return false;
23
+ }
24
+ }
25
+ async function ensureTlsCert(dataDir) {
26
+ const certPath = join(dataDir, "api-cert.pem");
27
+ const keyPath = join(dataDir, "api-key.pem");
28
+ if (existsSync(certPath) && existsSync(keyPath)) {
29
+ const cert = readFileSync(certPath, "utf-8");
30
+ const key = readFileSync(keyPath, "utf-8");
31
+ if (isCertValid(cert)) {
32
+ const fingerprint2 = computeFingerprint(cert);
33
+ log.info("Loaded existing TLS certificate");
34
+ return { cert, key, fingerprint: fingerprint2 };
35
+ }
36
+ log.warn("Existing TLS certificate is expired, regenerating");
37
+ }
38
+ log.info("Generating self-signed TLS certificate");
39
+ const notBeforeDate = /* @__PURE__ */ new Date();
40
+ const notAfterDate = /* @__PURE__ */ new Date();
41
+ notAfterDate.setFullYear(notAfterDate.getFullYear() + 2);
42
+ const pems = await generate([{ name: "commonName", value: "teleton-api" }], {
43
+ keySize: 2048,
44
+ algorithm: "sha256",
45
+ notBeforeDate,
46
+ notAfterDate,
47
+ extensions: [
48
+ { name: "basicConstraints", cA: false, critical: true },
49
+ {
50
+ name: "keyUsage",
51
+ digitalSignature: true,
52
+ keyEncipherment: true,
53
+ critical: true
54
+ },
55
+ { name: "extKeyUsage", serverAuth: true },
56
+ {
57
+ name: "subjectAltName",
58
+ altNames: [
59
+ { type: 2, value: "localhost" },
60
+ { type: 7, ip: "127.0.0.1" },
61
+ { type: 7, ip: "::1" }
62
+ ]
63
+ }
64
+ ]
65
+ });
66
+ writeFileSync(certPath, pems.cert, { mode: 384 });
67
+ writeFileSync(keyPath, pems.private, { mode: 384 });
68
+ const fingerprint = computeFingerprint(pems.cert);
69
+ log.info(`TLS certificate generated (fingerprint: ${fingerprint.slice(0, 16)}...)`);
70
+ return { cert: pems.cert, key: pems.private, fingerprint };
71
+ }
72
+
73
+ export {
74
+ ensureTlsCert
75
+ };
@@ -4,7 +4,7 @@ import {
4
4
  } from "./chunk-VFA7QMCZ.js";
5
5
  import {
6
6
  TELEGRAM_MAX_MESSAGE_LENGTH
7
- } from "./chunk-UP55PXFH.js";
7
+ } from "./chunk-C4NKJT2Z.js";
8
8
  import {
9
9
  fetchWithTimeout
10
10
  } from "./chunk-XQUHC3JZ.js";
@@ -15,7 +15,7 @@ import {
15
15
  } from "./chunk-EYWNOHMJ.js";
16
16
  import {
17
17
  createLogger
18
- } from "./chunk-RCMD3U65.js";
18
+ } from "./chunk-NQ6FZKCE.js";
19
19
 
20
20
  // src/ton/endpoint.ts
21
21
  var ENDPOINT_CACHE_TTL_MS = 6e4;
@@ -351,6 +351,13 @@ var _DevObject = z.object({
351
351
  hot_reload: z.boolean().default(false).describe("Enable plugin hot-reload (watches ~/.teleton/plugins/ for changes)")
352
352
  });
353
353
  var DevConfigSchema = _DevObject.default(_DevObject.parse({}));
354
+ var _ApiObject = z.object({
355
+ enabled: z.boolean().default(false).describe("Enable HTTPS Management API server"),
356
+ port: z.number().min(1).max(65535).default(7778).describe("HTTPS server port"),
357
+ key_hash: z.string().default("").describe("SHA-256 hash of the API key (auto-generated if empty)"),
358
+ allowed_ips: z.array(z.string()).default([]).describe("IP whitelist (empty = allow all authenticated requests)")
359
+ });
360
+ var ApiConfigSchema = _ApiObject.default(_ApiObject.parse({}));
354
361
  var McpServerSchema = z.object({
355
362
  command: z.string().optional().describe("Stdio command (e.g. 'npx @modelcontextprotocol/server-filesystem /tmp')"),
356
363
  args: z.array(z.string()).optional().describe("Explicit args array (overrides command splitting)"),
@@ -410,6 +417,7 @@ var ConfigSchema = z.object({
410
417
  dev: DevConfigSchema,
411
418
  tool_rag: ToolRagConfigSchema,
412
419
  capabilities: CapabilitiesConfigSchema,
420
+ api: ApiConfigSchema.optional(),
413
421
  ton_proxy: TonProxyConfigSchema,
414
422
  mcp: McpConfigSchema,
415
423
  plugins: z.record(z.string(), z.unknown()).default({}).describe("Per-plugin config (key = plugin name with underscores)"),
@@ -23,6 +23,9 @@ var CONTEXT_MAX_RECENT_MESSAGES = 10;
23
23
  var CONTEXT_MAX_RELEVANT_CHUNKS = 5;
24
24
  var FEED_MESSAGE_MAX_CHARS = 2e3;
25
25
  var HYBRID_SEARCH_MIN_SCORE = 0.15;
26
+ var RECENCY_DECAY_FACTOR = 0.05;
27
+ var RECENCY_WEIGHT = 0.15;
28
+ var EMBEDDING_QUERY_MAX_CHARS = 1e3;
26
29
  var CONTEXT_OVERFLOW_SUMMARY_MESSAGES = 15;
27
30
  var RATE_LIMIT_MAX_RETRIES = 3;
28
31
  var SERVER_ERROR_MAX_RETRIES = 3;
@@ -56,6 +59,7 @@ var RESULT_TRUNCATION_KEEP_CHARS = 500;
56
59
  var EMBEDDING_CACHE_EVICTION_RATIO = 0.1;
57
60
  var WEB_FETCH_MAX_TEXT_LENGTH = 2e4;
58
61
  var WEB_SEARCH_MAX_RESULTS = 10;
62
+ var TOOL_CONCURRENCY_LIMIT = 2;
59
63
  var TOOL_RAG_MIN_SCORE = 0.1;
60
64
  var TOOL_RAG_VECTOR_WEIGHT = 0.6;
61
65
  var TOOL_RAG_KEYWORD_WEIGHT = 0.4;
@@ -85,6 +89,9 @@ export {
85
89
  CONTEXT_MAX_RELEVANT_CHUNKS,
86
90
  FEED_MESSAGE_MAX_CHARS,
87
91
  HYBRID_SEARCH_MIN_SCORE,
92
+ RECENCY_DECAY_FACTOR,
93
+ RECENCY_WEIGHT,
94
+ EMBEDDING_QUERY_MAX_CHARS,
88
95
  CONTEXT_OVERFLOW_SUMMARY_MESSAGES,
89
96
  RATE_LIMIT_MAX_RETRIES,
90
97
  SERVER_ERROR_MAX_RETRIES,
@@ -118,6 +125,7 @@ export {
118
125
  EMBEDDING_CACHE_EVICTION_RATIO,
119
126
  WEB_FETCH_MAX_TEXT_LENGTH,
120
127
  WEB_SEARCH_MAX_RESULTS,
128
+ TOOL_CONCURRENCY_LIMIT,
121
129
  TOOL_RAG_MIN_SCORE,
122
130
  TOOL_RAG_VECTOR_WEIGHT,
123
131
  TOOL_RAG_KEYWORD_WEIGHT