teleton 0.1.18 → 0.1.20
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/README.md +1 -0
- package/dist/chunk-OQGNS2FV.js +184 -0
- package/dist/{chunk-Q4N5NJ2B.js → chunk-Y4G7HSOQ.js} +232 -288
- package/dist/cli/index.js +3 -2
- package/dist/index.js +3 -2
- package/dist/transcript-DF2Y6CFY.js +22 -0
- package/package.json +1 -1
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Mi,
|
|
3
|
+
Mn,
|
|
4
|
+
br,
|
|
5
|
+
dt,
|
|
6
|
+
le,
|
|
7
|
+
qn,
|
|
8
|
+
ut,
|
|
9
|
+
ye
|
|
10
|
+
} from "./chunk-U7FQYCBQ.js";
|
|
11
|
+
import {
|
|
12
|
+
appendToTranscript,
|
|
13
|
+
archiveTranscript,
|
|
14
|
+
readTranscript,
|
|
15
|
+
transcriptExists
|
|
16
|
+
} from "./chunk-OQGNS2FV.js";
|
|
1
17
|
import {
|
|
2
18
|
ChatStore,
|
|
3
19
|
ContextBuilder,
|
|
@@ -62,16 +78,6 @@ import {
|
|
|
62
78
|
telegramGetMyGiftsExecutor,
|
|
63
79
|
telegramGetMyGiftsTool
|
|
64
80
|
} from "./chunk-B2PRMXOH.js";
|
|
65
|
-
import {
|
|
66
|
-
Mi,
|
|
67
|
-
Mn,
|
|
68
|
-
br,
|
|
69
|
-
dt,
|
|
70
|
-
le,
|
|
71
|
-
qn,
|
|
72
|
-
ut,
|
|
73
|
-
ye
|
|
74
|
-
} from "./chunk-U7FQYCBQ.js";
|
|
75
81
|
import {
|
|
76
82
|
__commonJS,
|
|
77
83
|
__toESM
|
|
@@ -2044,122 +2050,6 @@ import {
|
|
|
2044
2050
|
complete,
|
|
2045
2051
|
getModel
|
|
2046
2052
|
} from "@mariozechner/pi-ai";
|
|
2047
|
-
|
|
2048
|
-
// src/session/transcript.ts
|
|
2049
|
-
import { appendFileSync as appendFileSync2, readFileSync as readFileSync5, existsSync as existsSync6, mkdirSync as mkdirSync4, unlinkSync, renameSync } from "fs";
|
|
2050
|
-
import { join as join4 } from "path";
|
|
2051
|
-
var SESSIONS_DIR = join4(TELETON_ROOT, "sessions");
|
|
2052
|
-
function getTranscriptPath(sessionId) {
|
|
2053
|
-
return join4(SESSIONS_DIR, `${sessionId}.jsonl`);
|
|
2054
|
-
}
|
|
2055
|
-
function ensureSessionsDir() {
|
|
2056
|
-
if (!existsSync6(SESSIONS_DIR)) {
|
|
2057
|
-
mkdirSync4(SESSIONS_DIR, { recursive: true });
|
|
2058
|
-
}
|
|
2059
|
-
}
|
|
2060
|
-
function appendToTranscript(sessionId, message) {
|
|
2061
|
-
ensureSessionsDir();
|
|
2062
|
-
const transcriptPath = getTranscriptPath(sessionId);
|
|
2063
|
-
const line = JSON.stringify(message) + "\n";
|
|
2064
|
-
try {
|
|
2065
|
-
appendFileSync2(transcriptPath, line, "utf-8");
|
|
2066
|
-
} catch (error) {
|
|
2067
|
-
console.error(`Failed to append to transcript ${sessionId}:`, error);
|
|
2068
|
-
}
|
|
2069
|
-
}
|
|
2070
|
-
function extractToolCallIds(msg) {
|
|
2071
|
-
const ids = /* @__PURE__ */ new Set();
|
|
2072
|
-
if (msg.role === "assistant" && Array.isArray(msg.content)) {
|
|
2073
|
-
for (const block of msg.content) {
|
|
2074
|
-
const blockType = block.type;
|
|
2075
|
-
if (blockType === "toolCall" || blockType === "tool_use") {
|
|
2076
|
-
const id = block.id || block.toolCallId || block.tool_use_id;
|
|
2077
|
-
if (id) ids.add(id);
|
|
2078
|
-
}
|
|
2079
|
-
}
|
|
2080
|
-
}
|
|
2081
|
-
return ids;
|
|
2082
|
-
}
|
|
2083
|
-
function sanitizeMessages(messages) {
|
|
2084
|
-
const sanitized = [];
|
|
2085
|
-
let pendingToolCallIds = /* @__PURE__ */ new Set();
|
|
2086
|
-
let removedCount = 0;
|
|
2087
|
-
for (let i = 0; i < messages.length; i++) {
|
|
2088
|
-
const msg = messages[i];
|
|
2089
|
-
if (msg.role === "assistant") {
|
|
2090
|
-
const newToolIds = extractToolCallIds(msg);
|
|
2091
|
-
if (pendingToolCallIds.size > 0 && newToolIds.size > 0) {
|
|
2092
|
-
console.warn(
|
|
2093
|
-
`\u26A0\uFE0F Found ${pendingToolCallIds.size} pending tool results that were never received`
|
|
2094
|
-
);
|
|
2095
|
-
}
|
|
2096
|
-
pendingToolCallIds = newToolIds;
|
|
2097
|
-
sanitized.push(msg);
|
|
2098
|
-
} else if (msg.role === "toolResult" || msg.role === "tool_result") {
|
|
2099
|
-
const toolCallId = msg.toolCallId || msg.tool_use_id || msg.tool_call_id;
|
|
2100
|
-
if (toolCallId && pendingToolCallIds.has(toolCallId)) {
|
|
2101
|
-
pendingToolCallIds.delete(toolCallId);
|
|
2102
|
-
sanitized.push(msg);
|
|
2103
|
-
} else {
|
|
2104
|
-
removedCount++;
|
|
2105
|
-
console.warn(
|
|
2106
|
-
`\u{1F9F9} Removing out-of-order/orphaned toolResult: ${toolCallId?.slice(0, 20)}...`
|
|
2107
|
-
);
|
|
2108
|
-
continue;
|
|
2109
|
-
}
|
|
2110
|
-
} else if (msg.role === "user") {
|
|
2111
|
-
if (pendingToolCallIds.size > 0) {
|
|
2112
|
-
console.warn(
|
|
2113
|
-
`\u26A0\uFE0F User message arrived while ${pendingToolCallIds.size} tool results pending - marking them as orphaned`
|
|
2114
|
-
);
|
|
2115
|
-
pendingToolCallIds.clear();
|
|
2116
|
-
}
|
|
2117
|
-
sanitized.push(msg);
|
|
2118
|
-
} else {
|
|
2119
|
-
sanitized.push(msg);
|
|
2120
|
-
}
|
|
2121
|
-
}
|
|
2122
|
-
if (removedCount > 0) {
|
|
2123
|
-
console.log(`\u{1F9F9} Sanitized ${removedCount} orphaned/out-of-order toolResult(s) from transcript`);
|
|
2124
|
-
}
|
|
2125
|
-
return sanitized;
|
|
2126
|
-
}
|
|
2127
|
-
function readTranscript(sessionId) {
|
|
2128
|
-
const transcriptPath = getTranscriptPath(sessionId);
|
|
2129
|
-
if (!existsSync6(transcriptPath)) {
|
|
2130
|
-
return [];
|
|
2131
|
-
}
|
|
2132
|
-
try {
|
|
2133
|
-
const content = readFileSync5(transcriptPath, "utf-8");
|
|
2134
|
-
const lines = content.trim().split("\n").filter(Boolean);
|
|
2135
|
-
const messages = lines.map((line) => JSON.parse(line));
|
|
2136
|
-
return sanitizeMessages(messages);
|
|
2137
|
-
} catch (error) {
|
|
2138
|
-
console.error(`Failed to read transcript ${sessionId}:`, error);
|
|
2139
|
-
return [];
|
|
2140
|
-
}
|
|
2141
|
-
}
|
|
2142
|
-
function transcriptExists(sessionId) {
|
|
2143
|
-
return existsSync6(getTranscriptPath(sessionId));
|
|
2144
|
-
}
|
|
2145
|
-
function archiveTranscript(sessionId) {
|
|
2146
|
-
const transcriptPath = getTranscriptPath(sessionId);
|
|
2147
|
-
const timestamp = Date.now();
|
|
2148
|
-
const archivePath = `${transcriptPath}.${timestamp}.archived`;
|
|
2149
|
-
if (!existsSync6(transcriptPath)) {
|
|
2150
|
-
return false;
|
|
2151
|
-
}
|
|
2152
|
-
try {
|
|
2153
|
-
renameSync(transcriptPath, archivePath);
|
|
2154
|
-
console.log(`\u{1F4E6} Archived transcript: ${sessionId} \u2192 ${timestamp}.archived`);
|
|
2155
|
-
return true;
|
|
2156
|
-
} catch (error) {
|
|
2157
|
-
console.error(`Failed to archive transcript ${sessionId}:`, error);
|
|
2158
|
-
return false;
|
|
2159
|
-
}
|
|
2160
|
-
}
|
|
2161
|
-
|
|
2162
|
-
// src/agent/client.ts
|
|
2163
2053
|
var modelCache = /* @__PURE__ */ new Map();
|
|
2164
2054
|
function getProviderModel(provider, modelId) {
|
|
2165
2055
|
const cacheKey = `${provider}:${modelId}`;
|
|
@@ -2789,7 +2679,7 @@ ${oversizedNotes.join("\n")}` : "";
|
|
|
2789
2679
|
|
|
2790
2680
|
// src/session/memory-hook.ts
|
|
2791
2681
|
import { writeFile, mkdir } from "fs/promises";
|
|
2792
|
-
import { join as
|
|
2682
|
+
import { join as join4 } from "path";
|
|
2793
2683
|
import { complete as complete3 } from "@mariozechner/pi-ai";
|
|
2794
2684
|
async function generateSlugViaClaude(params) {
|
|
2795
2685
|
const provider = params.provider || "anthropic";
|
|
@@ -2830,7 +2720,7 @@ Slug:`,
|
|
|
2830
2720
|
async function saveSessionMemory(params) {
|
|
2831
2721
|
try {
|
|
2832
2722
|
const { TELETON_ROOT: TELETON_ROOT2 } = await import("./paths-TMNTEDDD.js");
|
|
2833
|
-
const memoryDir =
|
|
2723
|
+
const memoryDir = join4(TELETON_ROOT2, "memory");
|
|
2834
2724
|
await mkdir(memoryDir, { recursive: true });
|
|
2835
2725
|
const now = /* @__PURE__ */ new Date();
|
|
2836
2726
|
const dateStr = now.toISOString().split("T")[0];
|
|
@@ -2842,7 +2732,7 @@ async function saveSessionMemory(params) {
|
|
|
2842
2732
|
utilityModel: params.utilityModel
|
|
2843
2733
|
});
|
|
2844
2734
|
const filename = `${dateStr}-${slug}.md`;
|
|
2845
|
-
const filepath =
|
|
2735
|
+
const filepath = join4(memoryDir, filename);
|
|
2846
2736
|
const timeStr = now.toISOString().split("T")[1].split(".")[0];
|
|
2847
2737
|
console.log("\u{1F4DD} Generating session summary...");
|
|
2848
2738
|
let summary;
|
|
@@ -3722,8 +3612,8 @@ import { TelegramClient, Api } from "telegram";
|
|
|
3722
3612
|
import { Logger, LogLevel } from "telegram/extensions/Logger.js";
|
|
3723
3613
|
import { StringSession } from "telegram/sessions/index.js";
|
|
3724
3614
|
import { NewMessage } from "telegram/events/index.js";
|
|
3725
|
-
import { existsSync as
|
|
3726
|
-
import { dirname as
|
|
3615
|
+
import { existsSync as existsSync6, readFileSync as readFileSync5, writeFileSync as writeFileSync3, mkdirSync as mkdirSync4, chmodSync } from "fs";
|
|
3616
|
+
import { dirname as dirname3 } from "path";
|
|
3727
3617
|
import { createInterface } from "readline";
|
|
3728
3618
|
|
|
3729
3619
|
// src/telegram/formatting.ts
|
|
@@ -3821,8 +3711,8 @@ var TelegramUserClient = class {
|
|
|
3821
3711
|
*/
|
|
3822
3712
|
loadSession() {
|
|
3823
3713
|
try {
|
|
3824
|
-
if (
|
|
3825
|
-
return
|
|
3714
|
+
if (existsSync6(this.config.sessionPath)) {
|
|
3715
|
+
return readFileSync5(this.config.sessionPath, "utf-8").trim();
|
|
3826
3716
|
}
|
|
3827
3717
|
} catch (error) {
|
|
3828
3718
|
console.warn("Failed to load session:", error);
|
|
@@ -3839,9 +3729,9 @@ var TelegramUserClient = class {
|
|
|
3839
3729
|
console.warn("No session string to save");
|
|
3840
3730
|
return;
|
|
3841
3731
|
}
|
|
3842
|
-
const dir =
|
|
3843
|
-
if (!
|
|
3844
|
-
|
|
3732
|
+
const dir = dirname3(this.config.sessionPath);
|
|
3733
|
+
if (!existsSync6(dir)) {
|
|
3734
|
+
mkdirSync4(dir, { recursive: true });
|
|
3845
3735
|
}
|
|
3846
3736
|
writeFileSync3(this.config.sessionPath, sessionString, { encoding: "utf-8" });
|
|
3847
3737
|
chmodSync(this.config.sessionPath, 384);
|
|
@@ -3859,7 +3749,7 @@ var TelegramUserClient = class {
|
|
|
3859
3749
|
return;
|
|
3860
3750
|
}
|
|
3861
3751
|
try {
|
|
3862
|
-
const hasSession =
|
|
3752
|
+
const hasSession = existsSync6(this.config.sessionPath);
|
|
3863
3753
|
if (hasSession) {
|
|
3864
3754
|
await this.client.connect();
|
|
3865
3755
|
} else {
|
|
@@ -4352,20 +4242,20 @@ var TelegramBridge = class {
|
|
|
4352
4242
|
};
|
|
4353
4243
|
|
|
4354
4244
|
// src/telegram/offset-store.ts
|
|
4355
|
-
import { readFileSync as
|
|
4356
|
-
import { dirname as
|
|
4357
|
-
import { join as
|
|
4358
|
-
var OFFSET_FILE =
|
|
4245
|
+
import { readFileSync as readFileSync6, writeFileSync as writeFileSync4, existsSync as existsSync7, mkdirSync as mkdirSync5 } from "fs";
|
|
4246
|
+
import { dirname as dirname4 } from "path";
|
|
4247
|
+
import { join as join5 } from "path";
|
|
4248
|
+
var OFFSET_FILE = join5(TELETON_ROOT, "telegram-offset.json");
|
|
4359
4249
|
var STORE_VERSION = 2;
|
|
4360
4250
|
var offsetCache = null;
|
|
4361
4251
|
function loadState() {
|
|
4362
4252
|
if (offsetCache) return offsetCache;
|
|
4363
4253
|
try {
|
|
4364
|
-
if (!
|
|
4254
|
+
if (!existsSync7(OFFSET_FILE)) {
|
|
4365
4255
|
offsetCache = { version: STORE_VERSION, perChat: {} };
|
|
4366
4256
|
return offsetCache;
|
|
4367
4257
|
}
|
|
4368
|
-
const raw =
|
|
4258
|
+
const raw = readFileSync6(OFFSET_FILE, "utf-8");
|
|
4369
4259
|
const state = JSON.parse(raw);
|
|
4370
4260
|
if (state.version === 1 || !state.perChat) {
|
|
4371
4261
|
offsetCache = { version: STORE_VERSION, perChat: {} };
|
|
@@ -4381,9 +4271,9 @@ function loadState() {
|
|
|
4381
4271
|
}
|
|
4382
4272
|
function saveState(state) {
|
|
4383
4273
|
try {
|
|
4384
|
-
const dir =
|
|
4385
|
-
if (!
|
|
4386
|
-
|
|
4274
|
+
const dir = dirname4(OFFSET_FILE);
|
|
4275
|
+
if (!existsSync7(dir)) {
|
|
4276
|
+
mkdirSync5(dir, { recursive: true });
|
|
4387
4277
|
}
|
|
4388
4278
|
writeFileSync4(OFFSET_FILE, JSON.stringify(state, null, 2), "utf-8");
|
|
4389
4279
|
offsetCache = state;
|
|
@@ -4838,10 +4728,10 @@ var MessageHandler = class {
|
|
|
4838
4728
|
// src/ton/wallet-service.ts
|
|
4839
4729
|
import { mnemonicNew, mnemonicToPrivateKey, mnemonicValidate } from "@ton/crypto";
|
|
4840
4730
|
import { WalletContractV5R1, TonClient, fromNano } from "@ton/ton";
|
|
4841
|
-
import { readFileSync as
|
|
4842
|
-
import { join as
|
|
4731
|
+
import { readFileSync as readFileSync7, writeFileSync as writeFileSync5, existsSync as existsSync8, mkdirSync as mkdirSync6, chmodSync as chmodSync2 } from "fs";
|
|
4732
|
+
import { join as join6, dirname as dirname5 } from "path";
|
|
4843
4733
|
import { getHttpEndpoint } from "@orbs-network/ton-access";
|
|
4844
|
-
var WALLET_FILE =
|
|
4734
|
+
var WALLET_FILE = join6(TELETON_ROOT, "wallet.json");
|
|
4845
4735
|
async function generateWallet() {
|
|
4846
4736
|
const mnemonic = await mnemonicNew(24);
|
|
4847
4737
|
const keyPair = await mnemonicToPrivateKey(mnemonic);
|
|
@@ -4859,19 +4749,19 @@ async function generateWallet() {
|
|
|
4859
4749
|
};
|
|
4860
4750
|
}
|
|
4861
4751
|
function saveWallet(wallet) {
|
|
4862
|
-
const dir =
|
|
4863
|
-
if (!
|
|
4864
|
-
|
|
4752
|
+
const dir = dirname5(WALLET_FILE);
|
|
4753
|
+
if (!existsSync8(dir)) {
|
|
4754
|
+
mkdirSync6(dir, { recursive: true });
|
|
4865
4755
|
}
|
|
4866
4756
|
writeFileSync5(WALLET_FILE, JSON.stringify(wallet, null, 2), "utf-8");
|
|
4867
4757
|
chmodSync2(WALLET_FILE, 384);
|
|
4868
4758
|
}
|
|
4869
4759
|
function loadWallet() {
|
|
4870
|
-
if (!
|
|
4760
|
+
if (!existsSync8(WALLET_FILE)) {
|
|
4871
4761
|
return null;
|
|
4872
4762
|
}
|
|
4873
4763
|
try {
|
|
4874
|
-
const content =
|
|
4764
|
+
const content = readFileSync7(WALLET_FILE, "utf-8");
|
|
4875
4765
|
return JSON.parse(content);
|
|
4876
4766
|
} catch (error) {
|
|
4877
4767
|
console.error("Failed to load wallet:", error);
|
|
@@ -4879,7 +4769,7 @@ function loadWallet() {
|
|
|
4879
4769
|
}
|
|
4880
4770
|
}
|
|
4881
4771
|
function walletExists() {
|
|
4882
|
-
return
|
|
4772
|
+
return existsSync8(WALLET_FILE);
|
|
4883
4773
|
}
|
|
4884
4774
|
async function importWallet(mnemonic) {
|
|
4885
4775
|
const valid = await mnemonicValidate(mnemonic);
|
|
@@ -4921,14 +4811,20 @@ async function getWalletBalance(address4) {
|
|
|
4921
4811
|
return null;
|
|
4922
4812
|
}
|
|
4923
4813
|
}
|
|
4814
|
+
var TON_PRICE_CACHE_TTL_MS = 3e4;
|
|
4815
|
+
var _tonPriceCache = null;
|
|
4924
4816
|
async function getTonPrice() {
|
|
4817
|
+
if (_tonPriceCache && Date.now() - _tonPriceCache.timestamp < TON_PRICE_CACHE_TTL_MS) {
|
|
4818
|
+
return { ..._tonPriceCache };
|
|
4819
|
+
}
|
|
4925
4820
|
try {
|
|
4926
4821
|
const response = await tonapiFetch(`/rates?tokens=ton¤cies=usd`);
|
|
4927
4822
|
if (response.ok) {
|
|
4928
4823
|
const data = await response.json();
|
|
4929
4824
|
const price = data?.rates?.TON?.prices?.USD;
|
|
4930
4825
|
if (typeof price === "number" && price > 0) {
|
|
4931
|
-
|
|
4826
|
+
_tonPriceCache = { usd: price, source: "TonAPI", timestamp: Date.now() };
|
|
4827
|
+
return _tonPriceCache;
|
|
4932
4828
|
}
|
|
4933
4829
|
}
|
|
4934
4830
|
} catch {
|
|
@@ -4943,7 +4839,8 @@ async function getTonPrice() {
|
|
|
4943
4839
|
const data = await response.json();
|
|
4944
4840
|
const price = data["the-open-network"]?.usd;
|
|
4945
4841
|
if (typeof price === "number" && price > 0) {
|
|
4946
|
-
|
|
4842
|
+
_tonPriceCache = { usd: price, source: "CoinGecko", timestamp: Date.now() };
|
|
4843
|
+
return _tonPriceCache;
|
|
4947
4844
|
}
|
|
4948
4845
|
} catch (error) {
|
|
4949
4846
|
console.error("Failed to get TON price:", error);
|
|
@@ -5445,8 +5342,8 @@ var MessageDebouncer = class {
|
|
|
5445
5342
|
|
|
5446
5343
|
// src/market/db.ts
|
|
5447
5344
|
import Database from "better-sqlite3";
|
|
5448
|
-
import { join as
|
|
5449
|
-
var DB_PATH =
|
|
5345
|
+
import { join as join7 } from "path";
|
|
5346
|
+
var DB_PATH = join7(TELETON_ROOT, "gifts.db");
|
|
5450
5347
|
function getDb2() {
|
|
5451
5348
|
const db = new Database(DB_PATH);
|
|
5452
5349
|
db.pragma("journal_mode = WAL");
|
|
@@ -5765,7 +5662,7 @@ var MarketPriceService = class {
|
|
|
5765
5662
|
};
|
|
5766
5663
|
|
|
5767
5664
|
// src/index.ts
|
|
5768
|
-
import { join as
|
|
5665
|
+
import { join as join14 } from "path";
|
|
5769
5666
|
|
|
5770
5667
|
// src/agent/tools/registry.ts
|
|
5771
5668
|
import { validateToolCall } from "@mariozechner/pi-ai";
|
|
@@ -6554,16 +6451,16 @@ var telegramSendPhotoExecutor = async (params, context) => {
|
|
|
6554
6451
|
// src/agent/tools/telegram/media/send-voice.ts
|
|
6555
6452
|
import { Type as Type11 } from "@sinclair/typebox";
|
|
6556
6453
|
import { Api as Api10 } from "telegram";
|
|
6557
|
-
import { unlinkSync as
|
|
6454
|
+
import { unlinkSync as unlinkSync2 } from "fs";
|
|
6558
6455
|
|
|
6559
6456
|
// src/services/tts.ts
|
|
6560
6457
|
import { spawn } from "child_process";
|
|
6561
|
-
import { writeFileSync as writeFileSync6, mkdirSync as
|
|
6562
|
-
import { join as
|
|
6458
|
+
import { writeFileSync as writeFileSync6, mkdirSync as mkdirSync7, existsSync as existsSync9, unlinkSync } from "fs";
|
|
6459
|
+
import { join as join8 } from "path";
|
|
6563
6460
|
import { tmpdir } from "os";
|
|
6564
6461
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
6565
|
-
var PIPER_VOICES_DIR =
|
|
6566
|
-
var PIPER_VENV =
|
|
6462
|
+
var PIPER_VOICES_DIR = join8(TELETON_ROOT, "piper-voices");
|
|
6463
|
+
var PIPER_VENV = join8(TELETON_ROOT, "rvc-env");
|
|
6567
6464
|
var PIPER_VOICES = {
|
|
6568
6465
|
trump: "en_US-trump-high.onnx",
|
|
6569
6466
|
// Trump voice (default) ⭐
|
|
@@ -6657,21 +6554,21 @@ async function generateSpeech(options) {
|
|
|
6657
6554
|
}
|
|
6658
6555
|
}
|
|
6659
6556
|
async function generatePiperTTS(text, voice) {
|
|
6660
|
-
const tempDir =
|
|
6661
|
-
if (!
|
|
6662
|
-
|
|
6557
|
+
const tempDir = join8(tmpdir(), "tonnet-tts");
|
|
6558
|
+
if (!existsSync9(tempDir)) {
|
|
6559
|
+
mkdirSync7(tempDir, { recursive: true });
|
|
6663
6560
|
}
|
|
6664
6561
|
const id = randomUUID3();
|
|
6665
|
-
const wavPath =
|
|
6666
|
-
const oggPath =
|
|
6562
|
+
const wavPath = join8(tempDir, `${id}.wav`);
|
|
6563
|
+
const oggPath = join8(tempDir, `${id}.ogg`);
|
|
6667
6564
|
const modelFile = PIPER_VOICES[voice.toLowerCase()] ?? voice;
|
|
6668
|
-
const modelPath = modelFile.includes("/") ? modelFile :
|
|
6669
|
-
if (!
|
|
6565
|
+
const modelPath = modelFile.includes("/") ? modelFile : join8(PIPER_VOICES_DIR, modelFile);
|
|
6566
|
+
if (!existsSync9(modelPath)) {
|
|
6670
6567
|
throw new Error(
|
|
6671
6568
|
`Piper voice not found: ${modelPath}. Available: ${Object.keys(PIPER_VOICES).join(", ")}`
|
|
6672
6569
|
);
|
|
6673
6570
|
}
|
|
6674
|
-
const piperBin =
|
|
6571
|
+
const piperBin = join8(PIPER_VENV, "bin", "piper");
|
|
6675
6572
|
await new Promise((resolve2, reject) => {
|
|
6676
6573
|
const proc = spawn(
|
|
6677
6574
|
piperBin,
|
|
@@ -6695,7 +6592,7 @@ async function generatePiperTTS(text, voice) {
|
|
|
6695
6592
|
stderr += data.toString();
|
|
6696
6593
|
});
|
|
6697
6594
|
proc.on("close", (code) => {
|
|
6698
|
-
if (code === 0 &&
|
|
6595
|
+
if (code === 0 && existsSync9(wavPath)) {
|
|
6699
6596
|
resolve2();
|
|
6700
6597
|
} else {
|
|
6701
6598
|
reject(new Error(`Piper TTS failed (code ${code}): ${stderr}`));
|
|
@@ -6734,7 +6631,7 @@ async function generatePiperTTS(text, voice) {
|
|
|
6734
6631
|
reject(new Error(`ffmpeg spawn error: ${err.message}`));
|
|
6735
6632
|
});
|
|
6736
6633
|
});
|
|
6737
|
-
|
|
6634
|
+
unlinkSync(wavPath);
|
|
6738
6635
|
} catch (err) {
|
|
6739
6636
|
return {
|
|
6740
6637
|
filePath: wavPath,
|
|
@@ -6749,11 +6646,11 @@ async function generatePiperTTS(text, voice) {
|
|
|
6749
6646
|
};
|
|
6750
6647
|
}
|
|
6751
6648
|
async function generateEdgeTTS(text, voice, rate, pitch) {
|
|
6752
|
-
const tempDir =
|
|
6753
|
-
if (!
|
|
6754
|
-
|
|
6649
|
+
const tempDir = join8(tmpdir(), "tonnet-tts");
|
|
6650
|
+
if (!existsSync9(tempDir)) {
|
|
6651
|
+
mkdirSync7(tempDir, { recursive: true });
|
|
6755
6652
|
}
|
|
6756
|
-
const outputPath =
|
|
6653
|
+
const outputPath = join8(tempDir, `${randomUUID3()}.mp3`);
|
|
6757
6654
|
const args = ["--text", text, "--voice", voice, "--write-media", outputPath];
|
|
6758
6655
|
if (rate) {
|
|
6759
6656
|
args.push("--rate", rate);
|
|
@@ -6790,11 +6687,11 @@ async function generateOpenAITTS(text, voice) {
|
|
|
6790
6687
|
if (!apiKey) {
|
|
6791
6688
|
throw new Error("OPENAI_API_KEY not set. Use Edge TTS (free) or set API key.");
|
|
6792
6689
|
}
|
|
6793
|
-
const tempDir =
|
|
6794
|
-
if (!
|
|
6795
|
-
|
|
6690
|
+
const tempDir = join8(tmpdir(), "tonnet-tts");
|
|
6691
|
+
if (!existsSync9(tempDir)) {
|
|
6692
|
+
mkdirSync7(tempDir, { recursive: true });
|
|
6796
6693
|
}
|
|
6797
|
-
const outputPath =
|
|
6694
|
+
const outputPath = join8(tempDir, `${randomUUID3()}.mp3`);
|
|
6798
6695
|
const response = await fetchWithTimeout(OPENAI_TTS_URL, {
|
|
6799
6696
|
method: "POST",
|
|
6800
6697
|
headers: {
|
|
@@ -6827,11 +6724,11 @@ async function generateElevenLabsTTS(text, voiceId) {
|
|
|
6827
6724
|
if (!apiKey) {
|
|
6828
6725
|
throw new Error("ELEVENLABS_API_KEY not set. Use Edge TTS (free) or set API key.");
|
|
6829
6726
|
}
|
|
6830
|
-
const tempDir =
|
|
6831
|
-
if (!
|
|
6832
|
-
|
|
6727
|
+
const tempDir = join8(tmpdir(), "tonnet-tts");
|
|
6728
|
+
if (!existsSync9(tempDir)) {
|
|
6729
|
+
mkdirSync7(tempDir, { recursive: true });
|
|
6833
6730
|
}
|
|
6834
|
-
const outputPath =
|
|
6731
|
+
const outputPath = join8(tempDir, `${randomUUID3()}.mp3`);
|
|
6835
6732
|
const response = await fetchWithTimeout(`${ELEVENLABS_TTS_URL}/${voiceId}`, {
|
|
6836
6733
|
method: "POST",
|
|
6837
6734
|
headers: {
|
|
@@ -7043,7 +6940,7 @@ var telegramSendVoiceExecutor = async (params, context) => {
|
|
|
7043
6940
|
} finally {
|
|
7044
6941
|
if (generatedFile) {
|
|
7045
6942
|
try {
|
|
7046
|
-
|
|
6943
|
+
unlinkSync2(generatedFile);
|
|
7047
6944
|
} catch (e) {
|
|
7048
6945
|
}
|
|
7049
6946
|
}
|
|
@@ -7423,7 +7320,7 @@ import { Type as Type15 } from "@sinclair/typebox";
|
|
|
7423
7320
|
import {
|
|
7424
7321
|
completeSimple
|
|
7425
7322
|
} from "@mariozechner/pi-ai";
|
|
7426
|
-
import { readFileSync as
|
|
7323
|
+
import { readFileSync as readFileSync8, existsSync as existsSync10 } from "fs";
|
|
7427
7324
|
import { extname as extname3 } from "path";
|
|
7428
7325
|
var visionAnalyzeTool = {
|
|
7429
7326
|
name: "vision_analyze",
|
|
@@ -7495,7 +7392,7 @@ var visionAnalyzeExecutor = async (params, context) => {
|
|
|
7495
7392
|
}
|
|
7496
7393
|
throw error;
|
|
7497
7394
|
}
|
|
7498
|
-
if (!
|
|
7395
|
+
if (!existsSync10(validatedPath.absolutePath)) {
|
|
7499
7396
|
return {
|
|
7500
7397
|
success: false,
|
|
7501
7398
|
error: `File not found: ${filePath}`
|
|
@@ -7509,7 +7406,7 @@ var visionAnalyzeExecutor = async (params, context) => {
|
|
|
7509
7406
|
error: `Unsupported file type: ${ext}. Vision supports: .jpg, .jpeg, .png, .gif, .webp`
|
|
7510
7407
|
};
|
|
7511
7408
|
}
|
|
7512
|
-
data =
|
|
7409
|
+
data = readFileSync8(validatedPath.absolutePath);
|
|
7513
7410
|
source = `file:${filePath}`;
|
|
7514
7411
|
} else {
|
|
7515
7412
|
console.log(`\u{1F4F7} Downloading image from message ${messageId}...`);
|
|
@@ -8752,7 +8649,7 @@ var telegramCreateGroupExecutor = async (params, context) => {
|
|
|
8752
8649
|
// src/agent/tools/telegram/groups/set-chat-photo.ts
|
|
8753
8650
|
import { Type as Type29 } from "@sinclair/typebox";
|
|
8754
8651
|
import { Api as Api22 } from "telegram";
|
|
8755
|
-
import { readFileSync as
|
|
8652
|
+
import { readFileSync as readFileSync9 } from "fs";
|
|
8756
8653
|
var telegramSetChatPhotoTool = {
|
|
8757
8654
|
name: "telegram_set_chat_photo",
|
|
8758
8655
|
description: `Set or delete a group/channel profile photo. You need admin rights with change info permission. Provide a local image path to set, or use delete_photo to remove.`,
|
|
@@ -8821,7 +8718,7 @@ var telegramSetChatPhotoExecutor = async (params, context) => {
|
|
|
8821
8718
|
}
|
|
8822
8719
|
throw error;
|
|
8823
8720
|
}
|
|
8824
|
-
const fileBuffer =
|
|
8721
|
+
const fileBuffer = readFileSync9(validatedPath.absolutePath);
|
|
8825
8722
|
const file = await client.uploadFile({
|
|
8826
8723
|
file: new CustomFile(
|
|
8827
8724
|
validatedPath.filename,
|
|
@@ -9577,15 +9474,10 @@ var telegramGetFoldersExecutor = async (_params, context) => {
|
|
|
9577
9474
|
try {
|
|
9578
9475
|
const gramJsClient = context.bridge.getClient().getClient();
|
|
9579
9476
|
const result = await gramJsClient.invoke(new Api31.messages.GetDialogFilters());
|
|
9580
|
-
|
|
9581
|
-
|
|
9582
|
-
success: false,
|
|
9583
|
-
error: "Unexpected result type from dialog filters"
|
|
9584
|
-
};
|
|
9585
|
-
}
|
|
9586
|
-
const folders = result.filter((filter) => filter.className === "DialogFilter").map((filter) => ({
|
|
9477
|
+
const filterList = Array.isArray(result) ? result : result.filters ?? [];
|
|
9478
|
+
const folders = filterList.filter((filter) => filter.className === "DialogFilter").map((filter) => ({
|
|
9587
9479
|
id: filter.id,
|
|
9588
|
-
title: filter.title,
|
|
9480
|
+
title: filter.title?.text ?? filter.title,
|
|
9589
9481
|
emoji: filter.emoticon || null,
|
|
9590
9482
|
pinnedPeersCount: filter.pinnedPeers?.length || 0,
|
|
9591
9483
|
includedPeersCount: filter.includePeers?.length || 0,
|
|
@@ -9670,12 +9562,13 @@ var telegramCreateFolderExecutor = async (params, context) => {
|
|
|
9670
9562
|
includeBots = false
|
|
9671
9563
|
} = params;
|
|
9672
9564
|
const gramJsClient = context.bridge.getClient().getClient();
|
|
9673
|
-
const
|
|
9674
|
-
const
|
|
9675
|
-
const
|
|
9565
|
+
const result = await gramJsClient.invoke(new Api32.messages.GetDialogFilters());
|
|
9566
|
+
const filters = Array.isArray(result) ? result : result.filters ?? [];
|
|
9567
|
+
const usedIds = filters.filter((f) => typeof f.id === "number").map((f) => f.id);
|
|
9568
|
+
const newId = usedIds.length > 0 ? Math.max(...usedIds) + 1 : 2;
|
|
9676
9569
|
const filterData = {
|
|
9677
9570
|
id: newId,
|
|
9678
|
-
title,
|
|
9571
|
+
title: new Api32.TextWithEntities({ text: title, entities: [] }),
|
|
9679
9572
|
pinnedPeers: [],
|
|
9680
9573
|
includePeers: [],
|
|
9681
9574
|
excludePeers: [],
|
|
@@ -9732,14 +9625,9 @@ var telegramAddChatToFolderExecutor = async (params, context) => {
|
|
|
9732
9625
|
try {
|
|
9733
9626
|
const { folderId, chatId } = params;
|
|
9734
9627
|
const gramJsClient = context.bridge.getClient().getClient();
|
|
9735
|
-
const
|
|
9736
|
-
|
|
9737
|
-
|
|
9738
|
-
success: false,
|
|
9739
|
-
error: "Failed to get existing folders"
|
|
9740
|
-
};
|
|
9741
|
-
}
|
|
9742
|
-
const folder = filters.find((f) => f.id === folderId);
|
|
9628
|
+
const filtersResult = await gramJsClient.invoke(new Api33.messages.GetDialogFilters());
|
|
9629
|
+
const filterList = Array.isArray(filtersResult) ? filtersResult : filtersResult.filters ?? [];
|
|
9630
|
+
const folder = filterList.find((f) => f.id === folderId);
|
|
9743
9631
|
if (!folder || folder.className !== "DialogFilter") {
|
|
9744
9632
|
return {
|
|
9745
9633
|
success: false,
|
|
@@ -9763,7 +9651,7 @@ var telegramAddChatToFolderExecutor = async (params, context) => {
|
|
|
9763
9651
|
success: true,
|
|
9764
9652
|
data: {
|
|
9765
9653
|
folderId,
|
|
9766
|
-
folderTitle: folder.title,
|
|
9654
|
+
folderTitle: folder.title?.text ?? folder.title,
|
|
9767
9655
|
chatId,
|
|
9768
9656
|
totalChatsInFolder: updatedIncludePeers.length
|
|
9769
9657
|
}
|
|
@@ -11010,7 +10898,7 @@ var import_big_integer4 = __toESM(require_BigInteger(), 1);
|
|
|
11010
10898
|
import { Type as Type59 } from "@sinclair/typebox";
|
|
11011
10899
|
import { Api as Api51 } from "telegram";
|
|
11012
10900
|
import { CustomFile as CustomFile2 } from "telegram/client/uploads.js";
|
|
11013
|
-
import { readFileSync as
|
|
10901
|
+
import { readFileSync as readFileSync10, statSync } from "fs";
|
|
11014
10902
|
import { basename as basename2 } from "path";
|
|
11015
10903
|
var telegramSendStoryTool = {
|
|
11016
10904
|
name: "telegram_send_story",
|
|
@@ -11059,7 +10947,7 @@ var telegramSendStoryExecutor = async (params, context) => {
|
|
|
11059
10947
|
const filePath = validatedPath.absolutePath;
|
|
11060
10948
|
const fileName = basename2(filePath);
|
|
11061
10949
|
const fileSize = statSync(filePath).size;
|
|
11062
|
-
const fileBuffer =
|
|
10950
|
+
const fileBuffer = readFileSync10(filePath);
|
|
11063
10951
|
const isVideo = filePath.toLowerCase().match(/\.(mp4|mov|avi)$/);
|
|
11064
10952
|
const customFile = new CustomFile2(fileName, fileSize, filePath, fileBuffer);
|
|
11065
10953
|
const uploadedFile = await gramJsClient.uploadFile({
|
|
@@ -11128,8 +11016,8 @@ var telegramSendStoryExecutor = async (params, context) => {
|
|
|
11128
11016
|
|
|
11129
11017
|
// src/agent/tools/telegram/memory/memory-write.ts
|
|
11130
11018
|
import { Type as Type60 } from "@sinclair/typebox";
|
|
11131
|
-
import { appendFileSync as
|
|
11132
|
-
import { join as
|
|
11019
|
+
import { appendFileSync as appendFileSync2, writeFileSync as writeFileSync8, existsSync as existsSync11, mkdirSync as mkdirSync8 } from "fs";
|
|
11020
|
+
import { join as join9 } from "path";
|
|
11133
11021
|
var MEMORY_DIR2 = WORKSPACE_PATHS.MEMORY_DIR;
|
|
11134
11022
|
var MEMORY_FILE = WORKSPACE_PATHS.MEMORY;
|
|
11135
11023
|
var memoryWriteTool = {
|
|
@@ -11151,8 +11039,8 @@ var memoryWriteTool = {
|
|
|
11151
11039
|
})
|
|
11152
11040
|
};
|
|
11153
11041
|
function ensureMemoryDir2() {
|
|
11154
|
-
if (!
|
|
11155
|
-
|
|
11042
|
+
if (!existsSync11(MEMORY_DIR2)) {
|
|
11043
|
+
mkdirSync8(MEMORY_DIR2, { recursive: true });
|
|
11156
11044
|
}
|
|
11157
11045
|
}
|
|
11158
11046
|
function formatDate2(date) {
|
|
@@ -11162,7 +11050,7 @@ function formatDate2(date) {
|
|
|
11162
11050
|
return `${year}-${month}-${day}`;
|
|
11163
11051
|
}
|
|
11164
11052
|
function getDailyLogPath2() {
|
|
11165
|
-
return
|
|
11053
|
+
return join9(MEMORY_DIR2, `${formatDate2(/* @__PURE__ */ new Date())}.md`);
|
|
11166
11054
|
}
|
|
11167
11055
|
var memoryWriteExecutor = async (params, context) => {
|
|
11168
11056
|
try {
|
|
@@ -11194,10 +11082,10 @@ var memoryWriteExecutor = async (params, context) => {
|
|
|
11194
11082
|
entry += `
|
|
11195
11083
|
_Added: ${now.toISOString()}_
|
|
11196
11084
|
`;
|
|
11197
|
-
if (!
|
|
11085
|
+
if (!existsSync11(MEMORY_FILE)) {
|
|
11198
11086
|
writeFileSync8(MEMORY_FILE, "# MEMORY.md - Persistent Memory\n\n", "utf-8");
|
|
11199
11087
|
}
|
|
11200
|
-
|
|
11088
|
+
appendFileSync2(MEMORY_FILE, entry, "utf-8");
|
|
11201
11089
|
console.log(`\u{1F4DD} Memory written to MEMORY.md${section ? ` (section: ${section})` : ""}`);
|
|
11202
11090
|
return {
|
|
11203
11091
|
success: true,
|
|
@@ -11210,7 +11098,7 @@ _Added: ${now.toISOString()}_
|
|
|
11210
11098
|
};
|
|
11211
11099
|
} else {
|
|
11212
11100
|
const logPath = getDailyLogPath2();
|
|
11213
|
-
if (!
|
|
11101
|
+
if (!existsSync11(logPath)) {
|
|
11214
11102
|
const header = `# Daily Log - ${formatDate2(now)}
|
|
11215
11103
|
|
|
11216
11104
|
`;
|
|
@@ -11227,7 +11115,7 @@ ${content}
|
|
|
11227
11115
|
---
|
|
11228
11116
|
|
|
11229
11117
|
`;
|
|
11230
|
-
|
|
11118
|
+
appendFileSync2(logPath, entry, "utf-8");
|
|
11231
11119
|
console.log(`\u{1F4C5} Memory written to daily log${section ? ` (${section})` : ""}`);
|
|
11232
11120
|
return {
|
|
11233
11121
|
success: true,
|
|
@@ -11250,8 +11138,8 @@ ${content}
|
|
|
11250
11138
|
|
|
11251
11139
|
// src/agent/tools/telegram/memory/memory-read.ts
|
|
11252
11140
|
import { Type as Type61 } from "@sinclair/typebox";
|
|
11253
|
-
import { readFileSync as
|
|
11254
|
-
import { join as
|
|
11141
|
+
import { readFileSync as readFileSync12, existsSync as existsSync12, readdirSync as readdirSync2 } from "fs";
|
|
11142
|
+
import { join as join10 } from "path";
|
|
11255
11143
|
var MEMORY_DIR3 = WORKSPACE_PATHS.MEMORY_DIR;
|
|
11256
11144
|
var MEMORY_FILE2 = WORKSPACE_PATHS.MEMORY;
|
|
11257
11145
|
var memoryReadTool = {
|
|
@@ -11280,10 +11168,10 @@ var memoryReadExecutor = async (params, _context) => {
|
|
|
11280
11168
|
const { target, date } = params;
|
|
11281
11169
|
if (target === "list") {
|
|
11282
11170
|
const files = [];
|
|
11283
|
-
if (
|
|
11171
|
+
if (existsSync12(MEMORY_FILE2)) {
|
|
11284
11172
|
files.push("MEMORY.md (persistent)");
|
|
11285
11173
|
}
|
|
11286
|
-
if (
|
|
11174
|
+
if (existsSync12(MEMORY_DIR3)) {
|
|
11287
11175
|
const dailyLogs = readdirSync2(MEMORY_DIR3).filter((f) => f.endsWith(".md")).sort().reverse();
|
|
11288
11176
|
files.push(...dailyLogs.map((f) => `memory/${f}`));
|
|
11289
11177
|
}
|
|
@@ -11296,7 +11184,7 @@ var memoryReadExecutor = async (params, _context) => {
|
|
|
11296
11184
|
};
|
|
11297
11185
|
}
|
|
11298
11186
|
if (target === "persistent") {
|
|
11299
|
-
if (!
|
|
11187
|
+
if (!existsSync12(MEMORY_FILE2)) {
|
|
11300
11188
|
return {
|
|
11301
11189
|
success: true,
|
|
11302
11190
|
data: {
|
|
@@ -11305,7 +11193,7 @@ var memoryReadExecutor = async (params, _context) => {
|
|
|
11305
11193
|
}
|
|
11306
11194
|
};
|
|
11307
11195
|
}
|
|
11308
|
-
const content =
|
|
11196
|
+
const content = readFileSync12(MEMORY_FILE2, "utf-8");
|
|
11309
11197
|
return {
|
|
11310
11198
|
success: true,
|
|
11311
11199
|
data: {
|
|
@@ -11318,8 +11206,8 @@ var memoryReadExecutor = async (params, _context) => {
|
|
|
11318
11206
|
}
|
|
11319
11207
|
if (target === "daily") {
|
|
11320
11208
|
const targetDate = date || formatDate3(/* @__PURE__ */ new Date());
|
|
11321
|
-
const logPath =
|
|
11322
|
-
if (!
|
|
11209
|
+
const logPath = join10(MEMORY_DIR3, `${targetDate}.md`);
|
|
11210
|
+
if (!existsSync12(logPath)) {
|
|
11323
11211
|
return {
|
|
11324
11212
|
success: true,
|
|
11325
11213
|
data: {
|
|
@@ -11329,7 +11217,7 @@ var memoryReadExecutor = async (params, _context) => {
|
|
|
11329
11217
|
}
|
|
11330
11218
|
};
|
|
11331
11219
|
}
|
|
11332
|
-
const content =
|
|
11220
|
+
const content = readFileSync12(logPath, "utf-8");
|
|
11333
11221
|
return {
|
|
11334
11222
|
success: true,
|
|
11335
11223
|
data: {
|
|
@@ -11348,15 +11236,15 @@ var memoryReadExecutor = async (params, _context) => {
|
|
|
11348
11236
|
const todayStr = formatDate3(today);
|
|
11349
11237
|
const yesterdayStr = formatDate3(yesterday);
|
|
11350
11238
|
const result = {};
|
|
11351
|
-
const yesterdayPath =
|
|
11352
|
-
if (
|
|
11353
|
-
result[yesterdayStr] =
|
|
11239
|
+
const yesterdayPath = join10(MEMORY_DIR3, `${yesterdayStr}.md`);
|
|
11240
|
+
if (existsSync12(yesterdayPath)) {
|
|
11241
|
+
result[yesterdayStr] = readFileSync12(yesterdayPath, "utf-8");
|
|
11354
11242
|
} else {
|
|
11355
11243
|
result[yesterdayStr] = null;
|
|
11356
11244
|
}
|
|
11357
|
-
const todayPath =
|
|
11358
|
-
if (
|
|
11359
|
-
result[todayStr] =
|
|
11245
|
+
const todayPath = join10(MEMORY_DIR3, `${todayStr}.md`);
|
|
11246
|
+
if (existsSync12(todayPath)) {
|
|
11247
|
+
result[todayStr] = readFileSync12(todayPath, "utf-8");
|
|
11360
11248
|
} else {
|
|
11361
11249
|
result[todayStr] = null;
|
|
11362
11250
|
}
|
|
@@ -19336,7 +19224,7 @@ var journalUpdateExecutor = async (params) => {
|
|
|
19336
19224
|
// src/agent/tools/workspace/list.ts
|
|
19337
19225
|
import { Type as Type99 } from "@sinclair/typebox";
|
|
19338
19226
|
import { readdirSync as readdirSync3, lstatSync as lstatSync2 } from "fs";
|
|
19339
|
-
import { join as
|
|
19227
|
+
import { join as join11 } from "path";
|
|
19340
19228
|
var workspaceListTool = {
|
|
19341
19229
|
name: "workspace_list",
|
|
19342
19230
|
description: `List files and directories in your workspace.
|
|
@@ -19373,7 +19261,7 @@ function listDir(dirPath, recursive, filter) {
|
|
|
19373
19261
|
try {
|
|
19374
19262
|
const entries = readdirSync3(dirPath);
|
|
19375
19263
|
for (const entry of entries) {
|
|
19376
|
-
const fullPath =
|
|
19264
|
+
const fullPath = join11(dirPath, entry);
|
|
19377
19265
|
const stats = lstatSync2(fullPath);
|
|
19378
19266
|
const isDir = stats.isDirectory();
|
|
19379
19267
|
if (filter === "files" && isDir) continue;
|
|
@@ -19434,7 +19322,7 @@ var workspaceListExecutor = async (params, _context) => {
|
|
|
19434
19322
|
|
|
19435
19323
|
// src/agent/tools/workspace/read.ts
|
|
19436
19324
|
import { Type as Type100 } from "@sinclair/typebox";
|
|
19437
|
-
import { readFileSync as
|
|
19325
|
+
import { readFileSync as readFileSync13, lstatSync as lstatSync3 } from "fs";
|
|
19438
19326
|
var workspaceReadTool = {
|
|
19439
19327
|
name: "workspace_read",
|
|
19440
19328
|
description: `Read a file from your workspace.
|
|
@@ -19506,7 +19394,7 @@ var workspaceReadExecutor = async (params, _context) => {
|
|
|
19506
19394
|
}
|
|
19507
19395
|
};
|
|
19508
19396
|
}
|
|
19509
|
-
const content =
|
|
19397
|
+
const content = readFileSync13(
|
|
19510
19398
|
validated.absolutePath,
|
|
19511
19399
|
encoding === "base64" ? "base64" : "utf-8"
|
|
19512
19400
|
);
|
|
@@ -19536,8 +19424,8 @@ var workspaceReadExecutor = async (params, _context) => {
|
|
|
19536
19424
|
|
|
19537
19425
|
// src/agent/tools/workspace/write.ts
|
|
19538
19426
|
import { Type as Type101 } from "@sinclair/typebox";
|
|
19539
|
-
import { writeFileSync as writeFileSync9, appendFileSync as
|
|
19540
|
-
import { dirname as
|
|
19427
|
+
import { writeFileSync as writeFileSync9, appendFileSync as appendFileSync3, mkdirSync as mkdirSync9, existsSync as existsSync13 } from "fs";
|
|
19428
|
+
import { dirname as dirname6 } from "path";
|
|
19541
19429
|
var workspaceWriteTool = {
|
|
19542
19430
|
name: "workspace_write",
|
|
19543
19431
|
description: `Write a file to your workspace.
|
|
@@ -19581,9 +19469,9 @@ var workspaceWriteExecutor = async (params, _context) => {
|
|
|
19581
19469
|
try {
|
|
19582
19470
|
const { path, content, encoding = "utf-8", append = false, createDirs = true } = params;
|
|
19583
19471
|
const validated = validateWritePath(path);
|
|
19584
|
-
const parentDir =
|
|
19585
|
-
if (createDirs && !
|
|
19586
|
-
|
|
19472
|
+
const parentDir = dirname6(validated.absolutePath);
|
|
19473
|
+
if (createDirs && !existsSync13(parentDir)) {
|
|
19474
|
+
mkdirSync9(parentDir, { recursive: true });
|
|
19587
19475
|
}
|
|
19588
19476
|
let writeContent;
|
|
19589
19477
|
if (encoding === "base64") {
|
|
@@ -19600,7 +19488,7 @@ var workspaceWriteExecutor = async (params, _context) => {
|
|
|
19600
19488
|
};
|
|
19601
19489
|
}
|
|
19602
19490
|
if (append && validated.exists) {
|
|
19603
|
-
|
|
19491
|
+
appendFileSync3(validated.absolutePath, writeContent);
|
|
19604
19492
|
} else {
|
|
19605
19493
|
writeFileSync9(validated.absolutePath, writeContent);
|
|
19606
19494
|
}
|
|
@@ -19630,7 +19518,7 @@ var workspaceWriteExecutor = async (params, _context) => {
|
|
|
19630
19518
|
|
|
19631
19519
|
// src/agent/tools/workspace/delete.ts
|
|
19632
19520
|
import { Type as Type102 } from "@sinclair/typebox";
|
|
19633
|
-
import { unlinkSync as
|
|
19521
|
+
import { unlinkSync as unlinkSync3, rmdirSync, readdirSync as readdirSync4, rmSync } from "fs";
|
|
19634
19522
|
var PROTECTED_WORKSPACE_FILES = [
|
|
19635
19523
|
"SOUL.md",
|
|
19636
19524
|
"STRATEGY.md",
|
|
@@ -19686,7 +19574,7 @@ var workspaceDeleteExecutor = async (params, _context) => {
|
|
|
19686
19574
|
rmdirSync(validated.absolutePath);
|
|
19687
19575
|
}
|
|
19688
19576
|
} else {
|
|
19689
|
-
|
|
19577
|
+
unlinkSync3(validated.absolutePath);
|
|
19690
19578
|
}
|
|
19691
19579
|
return {
|
|
19692
19580
|
success: true,
|
|
@@ -19712,8 +19600,8 @@ var workspaceDeleteExecutor = async (params, _context) => {
|
|
|
19712
19600
|
|
|
19713
19601
|
// src/agent/tools/workspace/info.ts
|
|
19714
19602
|
import { Type as Type103 } from "@sinclair/typebox";
|
|
19715
|
-
import { lstatSync as lstatSync4, readdirSync as readdirSync5, existsSync as
|
|
19716
|
-
import { join as
|
|
19603
|
+
import { lstatSync as lstatSync4, readdirSync as readdirSync5, existsSync as existsSync14 } from "fs";
|
|
19604
|
+
import { join as join12 } from "path";
|
|
19717
19605
|
var MEMES_DIR = WORKSPACE_PATHS.MEMES_DIR;
|
|
19718
19606
|
var workspaceInfoTool = {
|
|
19719
19607
|
name: "workspace_info",
|
|
@@ -19738,7 +19626,7 @@ function getDirSize(dirPath) {
|
|
|
19738
19626
|
try {
|
|
19739
19627
|
const entries = readdirSync5(dirPath, { withFileTypes: true });
|
|
19740
19628
|
for (const entry of entries) {
|
|
19741
|
-
const fullPath =
|
|
19629
|
+
const fullPath = join12(dirPath, entry.name);
|
|
19742
19630
|
if (entry.isDirectory()) {
|
|
19743
19631
|
const subStats = getDirSize(fullPath);
|
|
19744
19632
|
count += subStats.count;
|
|
@@ -19765,11 +19653,11 @@ function formatBytes(bytes) {
|
|
|
19765
19653
|
var workspaceInfoExecutor = async (params, _context) => {
|
|
19766
19654
|
try {
|
|
19767
19655
|
const { detailed = false } = params;
|
|
19768
|
-
const memoryStats =
|
|
19769
|
-
const downloadsStats =
|
|
19770
|
-
const uploadsStats =
|
|
19771
|
-
const tempStats =
|
|
19772
|
-
const memesStats =
|
|
19656
|
+
const memoryStats = existsSync14(WORKSPACE_PATHS.MEMORY_DIR) ? getDirSize(WORKSPACE_PATHS.MEMORY_DIR) : { count: 0, size: 0 };
|
|
19657
|
+
const downloadsStats = existsSync14(WORKSPACE_PATHS.DOWNLOADS_DIR) ? getDirSize(WORKSPACE_PATHS.DOWNLOADS_DIR) : { count: 0, size: 0 };
|
|
19658
|
+
const uploadsStats = existsSync14(WORKSPACE_PATHS.UPLOADS_DIR) ? getDirSize(WORKSPACE_PATHS.UPLOADS_DIR) : { count: 0, size: 0 };
|
|
19659
|
+
const tempStats = existsSync14(WORKSPACE_PATHS.TEMP_DIR) ? getDirSize(WORKSPACE_PATHS.TEMP_DIR) : { count: 0, size: 0 };
|
|
19660
|
+
const memesStats = existsSync14(MEMES_DIR) ? getDirSize(MEMES_DIR) : { count: 0, size: 0 };
|
|
19773
19661
|
const totalSize = memoryStats.size + downloadsStats.size + uploadsStats.size + tempStats.size + memesStats.size;
|
|
19774
19662
|
const info = {
|
|
19775
19663
|
workspaceRoot: WORKSPACE_ROOT,
|
|
@@ -19805,11 +19693,11 @@ var workspaceInfoExecutor = async (params, _context) => {
|
|
|
19805
19693
|
};
|
|
19806
19694
|
if (detailed) {
|
|
19807
19695
|
info.files = {
|
|
19808
|
-
memory:
|
|
19809
|
-
downloads:
|
|
19810
|
-
uploads:
|
|
19811
|
-
temp:
|
|
19812
|
-
memes:
|
|
19696
|
+
memory: existsSync14(WORKSPACE_PATHS.MEMORY_DIR) ? readdirSync5(WORKSPACE_PATHS.MEMORY_DIR) : [],
|
|
19697
|
+
downloads: existsSync14(WORKSPACE_PATHS.DOWNLOADS_DIR) ? readdirSync5(WORKSPACE_PATHS.DOWNLOADS_DIR) : [],
|
|
19698
|
+
uploads: existsSync14(WORKSPACE_PATHS.UPLOADS_DIR) ? readdirSync5(WORKSPACE_PATHS.UPLOADS_DIR) : [],
|
|
19699
|
+
temp: existsSync14(WORKSPACE_PATHS.TEMP_DIR) ? readdirSync5(WORKSPACE_PATHS.TEMP_DIR) : [],
|
|
19700
|
+
memes: existsSync14(MEMES_DIR) ? readdirSync5(MEMES_DIR) : []
|
|
19813
19701
|
};
|
|
19814
19702
|
}
|
|
19815
19703
|
return {
|
|
@@ -19826,9 +19714,9 @@ var workspaceInfoExecutor = async (params, _context) => {
|
|
|
19826
19714
|
|
|
19827
19715
|
// src/agent/tools/workspace/rename.ts
|
|
19828
19716
|
import { Type as Type104 } from "@sinclair/typebox";
|
|
19829
|
-
import { renameSync
|
|
19830
|
-
import { dirname as
|
|
19831
|
-
import { mkdirSync as
|
|
19717
|
+
import { renameSync, existsSync as existsSync15 } from "fs";
|
|
19718
|
+
import { dirname as dirname7 } from "path";
|
|
19719
|
+
import { mkdirSync as mkdirSync10 } from "fs";
|
|
19832
19720
|
var workspaceRenameTool = {
|
|
19833
19721
|
name: "workspace_rename",
|
|
19834
19722
|
description: `Rename or move a file within your workspace.
|
|
@@ -19875,11 +19763,11 @@ var workspaceRenameExecutor = async (params, _context) => {
|
|
|
19875
19763
|
error: `Destination already exists: '${to}'. Use overwrite=true to replace.`
|
|
19876
19764
|
};
|
|
19877
19765
|
}
|
|
19878
|
-
const parentDir =
|
|
19879
|
-
if (!
|
|
19880
|
-
|
|
19766
|
+
const parentDir = dirname7(validatedTo.absolutePath);
|
|
19767
|
+
if (!existsSync15(parentDir)) {
|
|
19768
|
+
mkdirSync10(parentDir, { recursive: true });
|
|
19881
19769
|
}
|
|
19882
|
-
|
|
19770
|
+
renameSync(validatedFrom.absolutePath, validatedTo.absolutePath);
|
|
19883
19771
|
return {
|
|
19884
19772
|
success: true,
|
|
19885
19773
|
data: {
|
|
@@ -21814,6 +21702,7 @@ async function executeDeal(dealId, db, bridge) {
|
|
|
21814
21702
|
WHERE id = ?`
|
|
21815
21703
|
).run(txHash, dealId);
|
|
21816
21704
|
console.log(`\u2705 [Deal] #${dealId} completed - TON sent - TX: ${txHash.slice(0, 8)}...`);
|
|
21705
|
+
logDealToJournal(deal, db, txHash);
|
|
21817
21706
|
await bridge.sendMessage({
|
|
21818
21707
|
chatId: deal.chat_id,
|
|
21819
21708
|
text: `\u2705 **Deal #${dealId} completed!**
|
|
@@ -21884,6 +21773,7 @@ Thank you for trading! \u{1F389}`
|
|
|
21884
21773
|
WHERE id = ?`
|
|
21885
21774
|
).run(sentMsgId, dealId);
|
|
21886
21775
|
console.log(`\u2705 [Deal] #${dealId} completed - Gift transferred`);
|
|
21776
|
+
logDealToJournal(deal, db);
|
|
21887
21777
|
await bridge.sendMessage({
|
|
21888
21778
|
chatId: deal.chat_id,
|
|
21889
21779
|
text: `\u2705 **Deal #${dealId} completed!**
|
|
@@ -21933,6 +21823,40 @@ Thank you for trading! \u{1F389}`
|
|
|
21933
21823
|
};
|
|
21934
21824
|
}
|
|
21935
21825
|
}
|
|
21826
|
+
function logDealToJournal(deal, db, txHash) {
|
|
21827
|
+
try {
|
|
21828
|
+
const journal = new JournalStore(db);
|
|
21829
|
+
const agentGave = formatAsset(
|
|
21830
|
+
deal.agent_gives_type,
|
|
21831
|
+
deal.agent_gives_ton_amount,
|
|
21832
|
+
deal.agent_gives_gift_slug
|
|
21833
|
+
);
|
|
21834
|
+
const agentReceived = formatAsset(
|
|
21835
|
+
deal.user_gives_type,
|
|
21836
|
+
deal.user_gives_ton_amount,
|
|
21837
|
+
deal.user_gives_gift_slug
|
|
21838
|
+
);
|
|
21839
|
+
const isGiftTrade = deal.agent_gives_type === "gift" || deal.user_gives_type === "gift";
|
|
21840
|
+
journal.addEntry({
|
|
21841
|
+
type: isGiftTrade ? "gift" : "trade",
|
|
21842
|
+
action: deal.agent_gives_type === "gift" ? "sell_gift" : "buy_gift",
|
|
21843
|
+
asset_from: agentGave,
|
|
21844
|
+
asset_to: agentReceived,
|
|
21845
|
+
amount_from: deal.agent_gives_ton_amount ?? void 0,
|
|
21846
|
+
amount_to: deal.user_gives_ton_amount ?? void 0,
|
|
21847
|
+
counterparty: String(deal.user_telegram_id),
|
|
21848
|
+
platform: "telegram_deals",
|
|
21849
|
+
outcome: "neutral",
|
|
21850
|
+
// P&L computed later when floor prices are known
|
|
21851
|
+
tx_hash: txHash,
|
|
21852
|
+
tool_used: "deal_executor",
|
|
21853
|
+
chat_id: deal.chat_id,
|
|
21854
|
+
user_id: deal.user_telegram_id
|
|
21855
|
+
});
|
|
21856
|
+
} catch (error) {
|
|
21857
|
+
console.error(`\u26A0\uFE0F [Deal] Failed to log deal #${deal.id} to journal:`, error);
|
|
21858
|
+
}
|
|
21859
|
+
}
|
|
21936
21860
|
async function autoExecuteAfterVerification(dealId, db, bridge) {
|
|
21937
21861
|
console.log(`\u{1F504} [Deal] Auto-executing deal #${dealId} after verification...`);
|
|
21938
21862
|
const result = await executeDeal(dealId, db, bridge);
|
|
@@ -21987,7 +21911,13 @@ var dealVerifyPaymentExecutor = async (params, context) => {
|
|
|
21987
21911
|
}
|
|
21988
21912
|
const now = Math.floor(Date.now() / 1e3);
|
|
21989
21913
|
if (now > deal.expires_at) {
|
|
21990
|
-
context.db.prepare(`UPDATE deals SET status = 'expired' WHERE id =
|
|
21914
|
+
const expireResult = context.db.prepare(`UPDATE deals SET status = 'expired' WHERE id = ? AND status = 'accepted'`).run(params.dealId);
|
|
21915
|
+
if (expireResult.changes !== 1) {
|
|
21916
|
+
return {
|
|
21917
|
+
success: false,
|
|
21918
|
+
error: `Deal #${params.dealId} already transitioned by another process`
|
|
21919
|
+
};
|
|
21920
|
+
}
|
|
21991
21921
|
return {
|
|
21992
21922
|
success: false,
|
|
21993
21923
|
error: `Deal #${params.dealId} has expired (2 minutes elapsed)`
|
|
@@ -22023,14 +21953,20 @@ var dealVerifyPaymentExecutor = async (params, context) => {
|
|
|
22023
21953
|
error: `Payment verification failed: ${verification.error || "Transaction not found"}`
|
|
22024
21954
|
};
|
|
22025
21955
|
}
|
|
22026
|
-
context.db.prepare(
|
|
21956
|
+
const verifyResult = context.db.prepare(
|
|
22027
21957
|
`UPDATE deals SET
|
|
22028
21958
|
status = 'verified',
|
|
22029
21959
|
user_payment_tx_hash = ?,
|
|
22030
21960
|
user_payment_wallet = ?,
|
|
22031
21961
|
user_payment_verified_at = unixepoch()
|
|
22032
|
-
WHERE id =
|
|
21962
|
+
WHERE id = ? AND status = 'accepted'`
|
|
22033
21963
|
).run(verification.txHash, verification.playerWallet, params.dealId);
|
|
21964
|
+
if (verifyResult.changes !== 1) {
|
|
21965
|
+
return {
|
|
21966
|
+
success: false,
|
|
21967
|
+
error: `Deal #${params.dealId} already transitioned by another process (expected 'accepted')`
|
|
21968
|
+
};
|
|
21969
|
+
}
|
|
22034
21970
|
console.log(
|
|
22035
21971
|
`\u2705 [Deal] Payment verified for #${params.dealId} - TX: ${verification.txHash?.slice(0, 8)}...`
|
|
22036
21972
|
);
|
|
@@ -22076,13 +22012,19 @@ var dealVerifyPaymentExecutor = async (params, context) => {
|
|
|
22076
22012
|
error: `Gift not received yet. Expected: ${deal.user_gives_gift_slug} from user ${deal.user_telegram_id}. Please ensure user has sent the gift.`
|
|
22077
22013
|
};
|
|
22078
22014
|
}
|
|
22079
|
-
context.db.prepare(
|
|
22015
|
+
const giftVerifyResult = context.db.prepare(
|
|
22080
22016
|
`UPDATE deals SET
|
|
22081
22017
|
status = 'verified',
|
|
22082
22018
|
user_payment_gift_msgid = ?,
|
|
22083
22019
|
user_payment_verified_at = unixepoch()
|
|
22084
|
-
WHERE id =
|
|
22020
|
+
WHERE id = ? AND status = 'accepted'`
|
|
22085
22021
|
).run(matchingGift.msgId, params.dealId);
|
|
22022
|
+
if (giftVerifyResult.changes !== 1) {
|
|
22023
|
+
return {
|
|
22024
|
+
success: false,
|
|
22025
|
+
error: `Deal #${params.dealId} already transitioned by another process (expected 'accepted')`
|
|
22026
|
+
};
|
|
22027
|
+
}
|
|
22086
22028
|
console.log(`\u2705 [Deal] Gift verified for #${params.dealId} - msgId: ${matchingGift.msgId}`);
|
|
22087
22029
|
await autoExecuteAfterVerification(params.dealId, context.db, context.bridge);
|
|
22088
22030
|
return {
|
|
@@ -22562,25 +22504,25 @@ function registerAllTools(registry, config) {
|
|
|
22562
22504
|
}
|
|
22563
22505
|
|
|
22564
22506
|
// src/agent/tools/plugin-loader.ts
|
|
22565
|
-
import { readdirSync as readdirSync6, existsSync as
|
|
22566
|
-
import { join as
|
|
22507
|
+
import { readdirSync as readdirSync6, existsSync as existsSync16, statSync as statSync2 } from "fs";
|
|
22508
|
+
import { join as join13 } from "path";
|
|
22567
22509
|
import { pathToFileURL } from "url";
|
|
22568
22510
|
async function loadPlugins(registry) {
|
|
22569
22511
|
const pluginsDir = WORKSPACE_PATHS.PLUGINS_DIR;
|
|
22570
|
-
if (!
|
|
22512
|
+
if (!existsSync16(pluginsDir)) {
|
|
22571
22513
|
return 0;
|
|
22572
22514
|
}
|
|
22573
22515
|
const entries = readdirSync6(pluginsDir);
|
|
22574
22516
|
let totalRegistered = 0;
|
|
22575
22517
|
for (const entry of entries) {
|
|
22576
|
-
const entryPath =
|
|
22518
|
+
const entryPath = join13(pluginsDir, entry);
|
|
22577
22519
|
let modulePath = null;
|
|
22578
22520
|
const stat = statSync2(entryPath);
|
|
22579
22521
|
if (stat.isFile() && entry.endsWith(".js")) {
|
|
22580
22522
|
modulePath = entryPath;
|
|
22581
22523
|
} else if (stat.isDirectory()) {
|
|
22582
|
-
const indexPath =
|
|
22583
|
-
if (
|
|
22524
|
+
const indexPath = join13(entryPath, "index.js");
|
|
22525
|
+
if (existsSync16(indexPath)) {
|
|
22584
22526
|
modulePath = indexPath;
|
|
22585
22527
|
}
|
|
22586
22528
|
}
|
|
@@ -23865,7 +23807,7 @@ var TonnetApp = class {
|
|
|
23865
23807
|
apiId: this.config.telegram.api_id,
|
|
23866
23808
|
apiHash: this.config.telegram.api_hash,
|
|
23867
23809
|
phone: this.config.telegram.phone,
|
|
23868
|
-
sessionPath:
|
|
23810
|
+
sessionPath: join14(TELETON_ROOT, "telegram_session.txt"),
|
|
23869
23811
|
connectionRetries: TELEGRAM_CONNECTION_RETRIES,
|
|
23870
23812
|
autoReconnect: true,
|
|
23871
23813
|
floodSleepThreshold: TELEGRAM_FLOOD_SLEEP_THRESHOLD
|
|
@@ -23873,7 +23815,7 @@ var TonnetApp = class {
|
|
|
23873
23815
|
const VECTOR_DIMENSIONS = 512;
|
|
23874
23816
|
const memory = initializeMemory({
|
|
23875
23817
|
database: {
|
|
23876
|
-
path:
|
|
23818
|
+
path: join14(TELETON_ROOT, "memory.db"),
|
|
23877
23819
|
enableVectorSearch: false,
|
|
23878
23820
|
vectorDimensions: VECTOR_DIMENSIONS
|
|
23879
23821
|
},
|
|
@@ -23882,7 +23824,7 @@ var TonnetApp = class {
|
|
|
23882
23824
|
apiKey: "",
|
|
23883
23825
|
model: ""
|
|
23884
23826
|
},
|
|
23885
|
-
workspaceDir:
|
|
23827
|
+
workspaceDir: join14(TELETON_ROOT)
|
|
23886
23828
|
});
|
|
23887
23829
|
const db = getDatabase().getDb();
|
|
23888
23830
|
if (this.config.market.enabled || this.config.deals.enabled) {
|
|
@@ -23934,9 +23876,11 @@ ${blue} \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u250
|
|
|
23934
23876
|
}
|
|
23935
23877
|
const { migrateSessionsToDb } = await import("./migrate-F256Q7LW.js");
|
|
23936
23878
|
migrateSessionsToDb();
|
|
23879
|
+
const { cleanupOldTranscripts } = await import("./transcript-DF2Y6CFY.js");
|
|
23880
|
+
cleanupOldTranscripts(30);
|
|
23937
23881
|
const memory = initializeMemory({
|
|
23938
23882
|
database: {
|
|
23939
|
-
path:
|
|
23883
|
+
path: join14(TELETON_ROOT, "memory.db"),
|
|
23940
23884
|
enableVectorSearch: false,
|
|
23941
23885
|
vectorDimensions: 512
|
|
23942
23886
|
},
|
|
@@ -23945,7 +23889,7 @@ ${blue} \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u250
|
|
|
23945
23889
|
apiKey: "",
|
|
23946
23890
|
model: ""
|
|
23947
23891
|
},
|
|
23948
|
-
workspaceDir:
|
|
23892
|
+
workspaceDir: join14(TELETON_ROOT)
|
|
23949
23893
|
});
|
|
23950
23894
|
const indexResult = await memory.knowledge.indexAll();
|
|
23951
23895
|
const db = getDatabase();
|