teleton 0.8.4 → 0.8.6

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 (84) hide show
  1. package/README.md +40 -17
  2. package/dist/{bootstrap-NNEI3Z5H.js → bootstrap-PFBH6ALD.js} +11 -8
  3. package/dist/bridge-guards-HZTNH7IB.js +9 -0
  4. package/dist/{chunk-NH2CNRKJ.js → chunk-2UUGRY5B.js} +151 -159
  5. package/dist/{chunk-UMUONAD6.js → chunk-4MFN75ZK.js} +5941 -2716
  6. package/dist/{chunk-LC4TV3KL.js → chunk-4MG2AROG.js} +5 -7
  7. package/dist/{chunk-LZQOX6YY.js → chunk-6IFNQWIM.js} +7714 -8748
  8. package/dist/chunk-7KI25UJU.js +215 -0
  9. package/dist/chunk-AX5NBEHX.js +12 -0
  10. package/dist/{chunk-5LOHRZYY.js → chunk-BLUES3FJ.js} +80 -101
  11. package/dist/{chunk-CUE4UZXR.js → chunk-BT2I3ETV.js} +3 -3
  12. package/dist/chunk-CXTZPOTA.js +107 -0
  13. package/dist/{chunk-LVTKJQ7O.js → chunk-D3GT6YIY.js} +59 -7
  14. package/dist/chunk-EKCXKL5M.js +53 -0
  15. package/dist/{chunk-XDZDOKIF.js → chunk-F6S3L3OV.js} +3 -3
  16. package/dist/{chunk-C4NKJT2Z.js → chunk-J4WDJ7XS.js} +1 -1
  17. package/dist/{chunk-G7PCW63M.js → chunk-JYF2MM5I.js} +147 -113
  18. package/dist/{chunk-NVKBBTI6.js → chunk-K3QSIIMZ.js} +9 -6
  19. package/dist/{chunk-EYWNOHMJ.js → chunk-L653KKCR.js} +1 -0
  20. package/dist/chunk-OMQIAWEU.js +273 -0
  21. package/dist/chunk-PCT7GYBP.js +274 -0
  22. package/dist/chunk-QYZBWU2D.js +139 -0
  23. package/dist/{chunk-WTDAICGT.js → chunk-R6W4DJRK.js} +7 -7
  24. package/dist/{chunk-5SEMA47R.js → chunk-RILOEIK6.js} +1 -1
  25. package/dist/{chunk-6OOHHJ4N.js → chunk-TFTNZZDH.js} +20 -20
  26. package/dist/chunk-TTOZCZWE.js +96 -0
  27. package/dist/chunk-UJ54YT2T.js +12 -0
  28. package/dist/{chunk-GHMXWAXI.js → chunk-ULVL2W3D.js} +211 -445
  29. package/dist/{chunk-NQ6FZKCE.js → chunk-V3S3NXBQ.js} +3 -1
  30. package/dist/{chunk-H7MFXJZK.js → chunk-WSL4KIOI.js} +31 -26
  31. package/dist/{chunk-35MX4ZUI.js → chunk-Z5WY7BSB.js} +5 -5
  32. package/dist/{chunk-ALKAAG4O.js → chunk-ZGKE3OTA.js} +112 -49
  33. package/dist/{chunk-JROBTXWY.js → chunk-ZHRDETCX.js} +38 -4
  34. package/dist/cli/index.d.ts +2 -0
  35. package/dist/cli/index.js +272 -159
  36. package/dist/{client-5KD25NOP.js → client-S5UIK6OG.js} +10 -8
  37. package/dist/daily-logs-3WXGYAQF.js +25 -0
  38. package/dist/{get-my-gifts-Y7EN7RK4.js → get-my-gifts-3YSYM3LI.js} +3 -2
  39. package/dist/harden-permissions-PV5SGV5D.js +100 -0
  40. package/dist/index.d.ts +923 -0
  41. package/dist/index.js +29 -20
  42. package/dist/knowledge-RRWUIO3G.js +19 -0
  43. package/dist/{local-IHKJFQJS.js → local-MSZAXWUL.js} +3 -3
  44. package/dist/mcp-loader-OELDFR63.js +15 -0
  45. package/dist/{memory-QMJRM3XJ.js → memory-6U6HGRK2.js} +23 -12
  46. package/dist/memory-hook-T7Y235KY.js +19 -0
  47. package/dist/messages-KV5ADNJB.js +17 -0
  48. package/dist/{migrate-5VBAP52B.js → migrate-AX3HOKOO.js} +10 -7
  49. package/dist/{paths-XA2RJH4S.js → paths-WMVV7ZAJ.js} +1 -1
  50. package/dist/{server-WWGVDFPW.js → server-MFRYOGHR.js} +21 -23
  51. package/dist/{server-AJCOURH7.js → server-SFLCAZFR.js} +221 -27
  52. package/dist/{setup-server-VDY64CWW.js → setup-server-YWAPKZVE.js} +26 -26
  53. package/dist/{store-BY7S6IFN.js → store-PGHQASBC.js} +11 -8
  54. package/dist/{task-dependency-resolver-L6UUMTHK.js → task-dependency-resolver-YQKADDEU.js} +24 -10
  55. package/dist/{task-executor-XBNJLUCS.js → task-executor-LWAWD225.js} +4 -4
  56. package/dist/{tool-adapter-IVX2XQJE.js → tool-adapter-VKLUZSQS.js} +1 -1
  57. package/dist/{tool-index-FTERJSZK.js → tool-index-YEWDF5CK.js} +5 -5
  58. package/dist/{transcript-IM7G25OS.js → transcript-4Y3Z2BJ3.js} +3 -3
  59. package/dist/web/assets/Config-MNxA69ib.js +1 -0
  60. package/dist/web/assets/Conversations-Dk958paA.js +1 -0
  61. package/dist/web/assets/Dashboard-dM18fGOm.js +1 -0
  62. package/dist/web/assets/Hooks-D2griQnI.js +1 -0
  63. package/dist/web/assets/Mcp-CtWNzwsz.js +1 -0
  64. package/dist/web/assets/Memory-CfLwH45G.js +1 -0
  65. package/dist/web/assets/Plugins-3hoJprFo.js +1 -0
  66. package/dist/web/assets/SearchInput-CpcETdpE.js +1 -0
  67. package/dist/web/assets/Soul-BSxE73aK.js +1 -0
  68. package/dist/web/assets/Tasks-DkCkfu3A.js +1 -0
  69. package/dist/web/assets/TelegramSettingsPanel-BRzc5G6e.js +1 -0
  70. package/dist/web/assets/Tools-Du8B8Mb4.js +1 -0
  71. package/dist/web/assets/Wallet-BLILP2Gn.js +1 -0
  72. package/dist/web/assets/Workspace-qklcXpXV.js +1 -0
  73. package/dist/web/assets/index-BwEPTTKp.js +90 -0
  74. package/dist/web/assets/index-noejUsK7.css +1 -0
  75. package/dist/web/assets/{index.es-DitvF-9H.js → index.es-DdpKlnGb.js} +1 -1
  76. package/dist/web/assets/useToolManager-tdxkKn3H.js +1 -0
  77. package/dist/web/assets/utils-CnsbSMo4.js +1 -0
  78. package/dist/web/index.html +2 -2
  79. package/package.json +7 -12
  80. package/src/templates/HEARTBEAT.md +5 -0
  81. package/dist/memory-hook-VUNWZ3NY.js +0 -19
  82. package/dist/web/assets/index-BfYCdwLI.js +0 -80
  83. package/dist/web/assets/index-DmlyQVhR.css +0 -1
  84. package/dist/{chunk-WFTC3JJW.js → chunk-3NO7QU7W.js} +1 -1
@@ -0,0 +1,107 @@
1
+ import {
2
+ TELETON_ROOT,
3
+ WORKSPACE_PATHS,
4
+ WORKSPACE_ROOT
5
+ } from "./chunk-L653KKCR.js";
6
+ import {
7
+ createLogger
8
+ } from "./chunk-V3S3NXBQ.js";
9
+
10
+ // src/workspace/manager.ts
11
+ import { existsSync, mkdirSync, readFileSync, writeFileSync, copyFileSync } from "fs";
12
+ import { join, dirname } from "path";
13
+ import { fileURLToPath } from "url";
14
+ var log = createLogger("Workspace");
15
+ function findPackageRoot() {
16
+ let dir = dirname(fileURLToPath(import.meta.url));
17
+ for (let i = 0; i < 10; i++) {
18
+ if (existsSync(join(dir, "package.json"))) return dir;
19
+ dir = dirname(dir);
20
+ }
21
+ return process.cwd();
22
+ }
23
+ var TEMPLATES_DIR = join(findPackageRoot(), "src", "templates");
24
+ async function ensureWorkspace(config) {
25
+ const silent = config?.silent ?? false;
26
+ if (!existsSync(TELETON_ROOT)) {
27
+ mkdirSync(TELETON_ROOT, { recursive: true });
28
+ if (!silent) log.info(`Created Teleton root at ${TELETON_ROOT}`);
29
+ }
30
+ if (!existsSync(WORKSPACE_ROOT)) {
31
+ mkdirSync(WORKSPACE_ROOT, { recursive: true });
32
+ if (!silent) log.info(`Created workspace at ${WORKSPACE_ROOT}`);
33
+ }
34
+ const directories = [
35
+ WORKSPACE_PATHS.MEMORY_DIR,
36
+ WORKSPACE_PATHS.DOWNLOADS_DIR,
37
+ WORKSPACE_PATHS.UPLOADS_DIR,
38
+ WORKSPACE_PATHS.TEMP_DIR,
39
+ WORKSPACE_PATHS.MEMES_DIR
40
+ ];
41
+ for (const dir of directories) {
42
+ if (!existsSync(dir)) {
43
+ mkdirSync(dir, { recursive: true });
44
+ }
45
+ }
46
+ const workspace = {
47
+ root: TELETON_ROOT,
48
+ workspace: WORKSPACE_ROOT,
49
+ // Workspace files
50
+ soulPath: WORKSPACE_PATHS.SOUL,
51
+ memoryPath: WORKSPACE_PATHS.MEMORY,
52
+ identityPath: WORKSPACE_PATHS.IDENTITY,
53
+ userPath: WORKSPACE_PATHS.USER,
54
+ strategyPath: WORKSPACE_PATHS.STRATEGY,
55
+ securityPath: WORKSPACE_PATHS.SECURITY,
56
+ // Workspace directories
57
+ memoryDir: WORKSPACE_PATHS.MEMORY_DIR,
58
+ downloadsDir: WORKSPACE_PATHS.DOWNLOADS_DIR,
59
+ uploadsDir: WORKSPACE_PATHS.UPLOADS_DIR,
60
+ tempDir: WORKSPACE_PATHS.TEMP_DIR,
61
+ memesDir: WORKSPACE_PATHS.MEMES_DIR,
62
+ // Protected files (outside workspace)
63
+ sessionPath: join(TELETON_ROOT, "telegram_session.txt"),
64
+ configPath: join(TELETON_ROOT, "config.yaml"),
65
+ walletPath: join(TELETON_ROOT, "wallet.json")
66
+ };
67
+ if (config?.ensureTemplates) {
68
+ await bootstrapTemplates(workspace, silent);
69
+ }
70
+ return workspace;
71
+ }
72
+ async function bootstrapTemplates(workspace, silent = false) {
73
+ const templates = [
74
+ { name: "SOUL.md", path: workspace.soulPath },
75
+ { name: "MEMORY.md", path: workspace.memoryPath },
76
+ { name: "IDENTITY.md", path: workspace.identityPath },
77
+ { name: "USER.md", path: workspace.userPath },
78
+ { name: "SECURITY.md", path: workspace.securityPath },
79
+ { name: "STRATEGY.md", path: workspace.strategyPath },
80
+ { name: "HEARTBEAT.md", path: WORKSPACE_PATHS.HEARTBEAT }
81
+ ];
82
+ for (const template of templates) {
83
+ if (!existsSync(template.path)) {
84
+ const templateSource = join(TEMPLATES_DIR, template.name);
85
+ if (existsSync(templateSource)) {
86
+ copyFileSync(templateSource, template.path);
87
+ if (!silent) log.info(`Created ${template.name}`);
88
+ }
89
+ }
90
+ }
91
+ }
92
+ function isNewWorkspace(workspace) {
93
+ return !existsSync(workspace.configPath);
94
+ }
95
+ function loadTemplate(name) {
96
+ const templatePath = join(TEMPLATES_DIR, name);
97
+ if (!existsSync(templatePath)) {
98
+ throw new Error(`Template ${name} not found at ${templatePath}`);
99
+ }
100
+ return readFileSync(templatePath, "utf-8");
101
+ }
102
+
103
+ export {
104
+ ensureWorkspace,
105
+ isNewWorkspace,
106
+ loadTemplate
107
+ };
@@ -1,24 +1,25 @@
1
1
  import {
2
2
  getClaudeCodeApiKey,
3
3
  refreshClaudeCodeApiKey
4
- } from "./chunk-WTDAICGT.js";
4
+ } from "./chunk-R6W4DJRK.js";
5
5
  import {
6
6
  getProviderMetadata
7
- } from "./chunk-6OOHHJ4N.js";
7
+ } from "./chunk-TFTNZZDH.js";
8
8
  import {
9
9
  fetchWithTimeout
10
10
  } from "./chunk-XQUHC3JZ.js";
11
11
  import {
12
12
  appendToTranscript,
13
13
  readTranscript
14
- } from "./chunk-LC4TV3KL.js";
14
+ } from "./chunk-4MG2AROG.js";
15
15
  import {
16
16
  createLogger
17
- } from "./chunk-NQ6FZKCE.js";
17
+ } from "./chunk-V3S3NXBQ.js";
18
18
 
19
19
  // src/agent/client.ts
20
20
  import {
21
21
  complete,
22
+ stream,
22
23
  getModel
23
24
  } from "@mariozechner/pi-ai";
24
25
 
@@ -264,7 +265,7 @@ async function chatWithContext(config, options) {
264
265
  systemPrompt = "/no_think\n" + systemPrompt;
265
266
  if (tools && tools.length > 0) {
266
267
  cocoonAllowedTools = new Set(tools.map((t) => t.name));
267
- const { injectToolsIntoSystemPrompt } = await import("./tool-adapter-IVX2XQJE.js");
268
+ const { injectToolsIntoSystemPrompt } = await import("./tool-adapter-VKLUZSQS.js");
268
269
  systemPrompt = injectToolsIntoSystemPrompt(systemPrompt, tools);
269
270
  tools = void 0;
270
271
  }
@@ -283,7 +284,7 @@ async function chatWithContext(config, options) {
283
284
  cacheRetention: "long"
284
285
  };
285
286
  if (isCocoon) {
286
- const { stripCocoonPayload } = await import("./tool-adapter-IVX2XQJE.js");
287
+ const { stripCocoonPayload } = await import("./tool-adapter-VKLUZSQS.js");
287
288
  completeOptions.onPayload = stripCocoonPayload;
288
289
  }
289
290
  let response = await complete(model, context, completeOptions);
@@ -298,7 +299,7 @@ async function chatWithContext(config, options) {
298
299
  if (isCocoon) {
299
300
  const textBlock = response.content.find((b) => b.type === "text");
300
301
  if (textBlock?.type === "text" && textBlock.text.includes("<tool_call>")) {
301
- const { parseToolCallsFromText, extractPlainText } = await import("./tool-adapter-IVX2XQJE.js");
302
+ const { parseToolCallsFromText, extractPlainText } = await import("./tool-adapter-VKLUZSQS.js");
302
303
  const syntheticCalls = parseToolCallsFromText(textBlock.text, cocoonAllowedTools);
303
304
  if (syntheticCalls.length > 0) {
304
305
  const plainText = extractPlainText(textBlock.text);
@@ -331,6 +332,56 @@ async function chatWithContext(config, options) {
331
332
  context: updatedContext
332
333
  };
333
334
  }
335
+ function streamWithContext(config, options) {
336
+ const provider = config.provider || "anthropic";
337
+ const model = getProviderModel(provider, config.model);
338
+ const tools = provider === "google" && options.tools ? sanitizeToolsForGemini(options.tools) : options.tools;
339
+ const systemPrompt = options.systemPrompt || options.context.systemPrompt || "";
340
+ const context = {
341
+ ...options.context,
342
+ systemPrompt,
343
+ tools
344
+ };
345
+ const temperature = options.temperature ?? config.temperature;
346
+ const streamOptions = {
347
+ apiKey: getEffectiveApiKey(provider, config.api_key),
348
+ maxTokens: options.maxTokens ?? config.max_tokens,
349
+ temperature,
350
+ sessionId: options.sessionId,
351
+ cacheRetention: "long"
352
+ };
353
+ const eventStream = stream(model, context, streamOptions);
354
+ async function* textDeltas() {
355
+ for await (const event of eventStream) {
356
+ if (event.type === "text_delta" && event.delta) {
357
+ yield event.delta;
358
+ }
359
+ if (event.type === "toolcall_start") {
360
+ return;
361
+ }
362
+ }
363
+ }
364
+ const resultPromise = (async () => {
365
+ const response = await eventStream.result();
366
+ const thinkRe = /<think>[\s\S]*?<\/think>/g;
367
+ for (const block of response.content) {
368
+ if (block.type === "text" && block.text.includes("<think>")) {
369
+ block.text = block.text.replace(thinkRe, "").trim();
370
+ }
371
+ }
372
+ if (options.persistTranscript && options.sessionId) {
373
+ appendToTranscript(options.sessionId, response);
374
+ }
375
+ const textContent = response.content.find((block) => block.type === "text");
376
+ const text = textContent?.type === "text" ? textContent.text : "";
377
+ const updatedContext = {
378
+ ...context,
379
+ messages: [...context.messages, response]
380
+ };
381
+ return { message: response, text, context: updatedContext };
382
+ })();
383
+ return { textStream: textDeltas(), result: resultPromise };
384
+ }
334
385
  function loadContextFromTranscript(sessionId, systemPrompt) {
335
386
  const messages = readTranscript(sessionId);
336
387
  const seenToolCallIds = /* @__PURE__ */ new Set();
@@ -358,6 +409,7 @@ export {
358
409
  getProviderModel,
359
410
  getUtilityModel,
360
411
  chatWithContext,
412
+ streamWithContext,
361
413
  loadContextFromTranscript,
362
414
  createClient
363
415
  };
@@ -0,0 +1,53 @@
1
+ // packages/sdk/dist/index.js
2
+ var PluginSDKError = class extends Error {
3
+ constructor(message, code) {
4
+ super(message);
5
+ this.code = code;
6
+ }
7
+ name = "PluginSDKError";
8
+ };
9
+ var SDK_VERSION = "1.0.0";
10
+
11
+ // src/sdk/telegram-utils.ts
12
+ function requireBridge(bridge) {
13
+ if (!bridge.isAvailable()) {
14
+ throw new PluginSDKError(
15
+ "Telegram bridge not connected. SDK telegram methods can only be called at runtime (inside tool executors or start()), not during plugin loading.",
16
+ "BRIDGE_NOT_CONNECTED"
17
+ );
18
+ }
19
+ }
20
+ function getClient(bridge) {
21
+ return bridge.getRawClient().getClient();
22
+ }
23
+ function toSimpleMessage(msg) {
24
+ const fromId = msg.fromId;
25
+ let senderId = 0;
26
+ if (fromId) {
27
+ if ("userId" in fromId) senderId = Number(fromId.userId);
28
+ else if ("channelId" in fromId) senderId = Number(fromId.channelId);
29
+ else if ("chatId" in fromId) senderId = Number(fromId.chatId);
30
+ }
31
+ return {
32
+ id: msg.id,
33
+ text: msg.message ?? "",
34
+ senderId,
35
+ timestamp: new Date(msg.date * 1e3)
36
+ };
37
+ }
38
+ var _Api;
39
+ async function getApi() {
40
+ if (!_Api) {
41
+ _Api = (await import("telegram")).Api;
42
+ }
43
+ return _Api;
44
+ }
45
+
46
+ export {
47
+ PluginSDKError,
48
+ SDK_VERSION,
49
+ requireBridge,
50
+ getClient,
51
+ toSimpleMessage,
52
+ getApi
53
+ };
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  getDatabase
3
- } from "./chunk-GHMXWAXI.js";
3
+ } from "./chunk-ULVL2W3D.js";
4
4
  import {
5
5
  createLogger
6
- } from "./chunk-NQ6FZKCE.js";
6
+ } from "./chunk-V3S3NXBQ.js";
7
7
 
8
8
  // src/session/store.ts
9
9
  import { randomUUID } from "crypto";
@@ -269,7 +269,7 @@ function pruneOldSessions(maxAgeDays = 30) {
269
269
  const result = db.prepare(`DELETE FROM sessions WHERE updated_at < ? AND updated_at > 0`).run(cutoffMs);
270
270
  const pruned = result.changes;
271
271
  if (pruned > 0) {
272
- log.info(`\u{1F5D1}\uFE0F Pruned ${pruned} session(s) older than ${maxAgeDays} days`);
272
+ log.info(`Pruned ${pruned} session(s) older than ${maxAgeDays} days`);
273
273
  }
274
274
  return pruned;
275
275
  } catch (error) {
@@ -59,7 +59,7 @@ var RESULT_TRUNCATION_KEEP_CHARS = 500;
59
59
  var EMBEDDING_CACHE_EVICTION_RATIO = 0.1;
60
60
  var WEB_FETCH_MAX_TEXT_LENGTH = 2e4;
61
61
  var WEB_SEARCH_MAX_RESULTS = 10;
62
- var TOOL_CONCURRENCY_LIMIT = 2;
62
+ var TOOL_CONCURRENCY_LIMIT = 3;
63
63
  var TOOL_RAG_MIN_SCORE = 0.1;
64
64
  var TOOL_RAG_VECTOR_WEIGHT = 0.6;
65
65
  var TOOL_RAG_KEYWORD_WEIGHT = 0.4;