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.
- package/README.md +40 -17
- package/dist/{bootstrap-NNEI3Z5H.js → bootstrap-PFBH6ALD.js} +11 -8
- package/dist/bridge-guards-HZTNH7IB.js +9 -0
- package/dist/{chunk-NH2CNRKJ.js → chunk-2UUGRY5B.js} +151 -159
- package/dist/{chunk-UMUONAD6.js → chunk-4MFN75ZK.js} +5941 -2716
- package/dist/{chunk-LC4TV3KL.js → chunk-4MG2AROG.js} +5 -7
- package/dist/{chunk-LZQOX6YY.js → chunk-6IFNQWIM.js} +7714 -8748
- package/dist/chunk-7KI25UJU.js +215 -0
- package/dist/chunk-AX5NBEHX.js +12 -0
- package/dist/{chunk-5LOHRZYY.js → chunk-BLUES3FJ.js} +80 -101
- package/dist/{chunk-CUE4UZXR.js → chunk-BT2I3ETV.js} +3 -3
- package/dist/chunk-CXTZPOTA.js +107 -0
- package/dist/{chunk-LVTKJQ7O.js → chunk-D3GT6YIY.js} +59 -7
- package/dist/chunk-EKCXKL5M.js +53 -0
- package/dist/{chunk-XDZDOKIF.js → chunk-F6S3L3OV.js} +3 -3
- package/dist/{chunk-C4NKJT2Z.js → chunk-J4WDJ7XS.js} +1 -1
- package/dist/{chunk-G7PCW63M.js → chunk-JYF2MM5I.js} +147 -113
- package/dist/{chunk-NVKBBTI6.js → chunk-K3QSIIMZ.js} +9 -6
- package/dist/{chunk-EYWNOHMJ.js → chunk-L653KKCR.js} +1 -0
- package/dist/chunk-OMQIAWEU.js +273 -0
- package/dist/chunk-PCT7GYBP.js +274 -0
- package/dist/chunk-QYZBWU2D.js +139 -0
- package/dist/{chunk-WTDAICGT.js → chunk-R6W4DJRK.js} +7 -7
- package/dist/{chunk-5SEMA47R.js → chunk-RILOEIK6.js} +1 -1
- package/dist/{chunk-6OOHHJ4N.js → chunk-TFTNZZDH.js} +20 -20
- package/dist/chunk-TTOZCZWE.js +96 -0
- package/dist/chunk-UJ54YT2T.js +12 -0
- package/dist/{chunk-GHMXWAXI.js → chunk-ULVL2W3D.js} +211 -445
- package/dist/{chunk-NQ6FZKCE.js → chunk-V3S3NXBQ.js} +3 -1
- package/dist/{chunk-H7MFXJZK.js → chunk-WSL4KIOI.js} +31 -26
- package/dist/{chunk-35MX4ZUI.js → chunk-Z5WY7BSB.js} +5 -5
- package/dist/{chunk-ALKAAG4O.js → chunk-ZGKE3OTA.js} +112 -49
- package/dist/{chunk-JROBTXWY.js → chunk-ZHRDETCX.js} +38 -4
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +272 -159
- package/dist/{client-5KD25NOP.js → client-S5UIK6OG.js} +10 -8
- package/dist/daily-logs-3WXGYAQF.js +25 -0
- package/dist/{get-my-gifts-Y7EN7RK4.js → get-my-gifts-3YSYM3LI.js} +3 -2
- package/dist/harden-permissions-PV5SGV5D.js +100 -0
- package/dist/index.d.ts +923 -0
- package/dist/index.js +29 -20
- package/dist/knowledge-RRWUIO3G.js +19 -0
- package/dist/{local-IHKJFQJS.js → local-MSZAXWUL.js} +3 -3
- package/dist/mcp-loader-OELDFR63.js +15 -0
- package/dist/{memory-QMJRM3XJ.js → memory-6U6HGRK2.js} +23 -12
- package/dist/memory-hook-T7Y235KY.js +19 -0
- package/dist/messages-KV5ADNJB.js +17 -0
- package/dist/{migrate-5VBAP52B.js → migrate-AX3HOKOO.js} +10 -7
- package/dist/{paths-XA2RJH4S.js → paths-WMVV7ZAJ.js} +1 -1
- package/dist/{server-WWGVDFPW.js → server-MFRYOGHR.js} +21 -23
- package/dist/{server-AJCOURH7.js → server-SFLCAZFR.js} +221 -27
- package/dist/{setup-server-VDY64CWW.js → setup-server-YWAPKZVE.js} +26 -26
- package/dist/{store-BY7S6IFN.js → store-PGHQASBC.js} +11 -8
- package/dist/{task-dependency-resolver-L6UUMTHK.js → task-dependency-resolver-YQKADDEU.js} +24 -10
- package/dist/{task-executor-XBNJLUCS.js → task-executor-LWAWD225.js} +4 -4
- package/dist/{tool-adapter-IVX2XQJE.js → tool-adapter-VKLUZSQS.js} +1 -1
- package/dist/{tool-index-FTERJSZK.js → tool-index-YEWDF5CK.js} +5 -5
- package/dist/{transcript-IM7G25OS.js → transcript-4Y3Z2BJ3.js} +3 -3
- package/dist/web/assets/Config-MNxA69ib.js +1 -0
- package/dist/web/assets/Conversations-Dk958paA.js +1 -0
- package/dist/web/assets/Dashboard-dM18fGOm.js +1 -0
- package/dist/web/assets/Hooks-D2griQnI.js +1 -0
- package/dist/web/assets/Mcp-CtWNzwsz.js +1 -0
- package/dist/web/assets/Memory-CfLwH45G.js +1 -0
- package/dist/web/assets/Plugins-3hoJprFo.js +1 -0
- package/dist/web/assets/SearchInput-CpcETdpE.js +1 -0
- package/dist/web/assets/Soul-BSxE73aK.js +1 -0
- package/dist/web/assets/Tasks-DkCkfu3A.js +1 -0
- package/dist/web/assets/TelegramSettingsPanel-BRzc5G6e.js +1 -0
- package/dist/web/assets/Tools-Du8B8Mb4.js +1 -0
- package/dist/web/assets/Wallet-BLILP2Gn.js +1 -0
- package/dist/web/assets/Workspace-qklcXpXV.js +1 -0
- package/dist/web/assets/index-BwEPTTKp.js +90 -0
- package/dist/web/assets/index-noejUsK7.css +1 -0
- package/dist/web/assets/{index.es-DitvF-9H.js → index.es-DdpKlnGb.js} +1 -1
- package/dist/web/assets/useToolManager-tdxkKn3H.js +1 -0
- package/dist/web/assets/utils-CnsbSMo4.js +1 -0
- package/dist/web/index.html +2 -2
- package/package.json +7 -12
- package/src/templates/HEARTBEAT.md +5 -0
- package/dist/memory-hook-VUNWZ3NY.js +0 -19
- package/dist/web/assets/index-BfYCdwLI.js +0 -80
- package/dist/web/assets/index-DmlyQVhR.css +0 -1
- package/dist/{chunk-WFTC3JJW.js → chunk-3NO7QU7W.js} +1 -1
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import {
|
|
2
|
+
sanitizeForContext
|
|
3
|
+
} from "./chunk-AX5NBEHX.js";
|
|
4
|
+
import {
|
|
5
|
+
getErrorMessage
|
|
6
|
+
} from "./chunk-3UFPFWYP.js";
|
|
7
|
+
import {
|
|
8
|
+
TOOL_EXECUTION_TIMEOUT_MS
|
|
9
|
+
} from "./chunk-R4YSJ4EY.js";
|
|
10
|
+
import {
|
|
11
|
+
createLogger
|
|
12
|
+
} from "./chunk-V3S3NXBQ.js";
|
|
13
|
+
|
|
14
|
+
// src/agent/tools/mcp-loader.ts
|
|
15
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
16
|
+
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
17
|
+
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
18
|
+
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
19
|
+
var log = createLogger("MCP");
|
|
20
|
+
var MCP_CONNECT_TIMEOUT_MS = 3e4;
|
|
21
|
+
function parseCommand(config) {
|
|
22
|
+
if (!config.command) throw new Error("No command specified");
|
|
23
|
+
if (config.args) {
|
|
24
|
+
return { command: config.command, args: config.args };
|
|
25
|
+
}
|
|
26
|
+
const parts = config.command.split(/\s+/);
|
|
27
|
+
return { command: parts[0], args: parts.slice(1) };
|
|
28
|
+
}
|
|
29
|
+
function extractText(content) {
|
|
30
|
+
return content.filter((c) => c.type === "text" && c.text).map((c) => c.text ?? "").join("\n");
|
|
31
|
+
}
|
|
32
|
+
async function loadMcpServers(config) {
|
|
33
|
+
const entries = Object.entries(config.servers).filter(([, cfg]) => cfg.enabled !== false);
|
|
34
|
+
if (entries.length === 0) return [];
|
|
35
|
+
const results = await Promise.allSettled(
|
|
36
|
+
entries.map(async ([name, serverConfig]) => {
|
|
37
|
+
let transport;
|
|
38
|
+
if (serverConfig.command) {
|
|
39
|
+
const { command, args } = parseCommand(serverConfig);
|
|
40
|
+
const safeEnv = {};
|
|
41
|
+
for (const key of ["PATH", "HOME", "NODE_PATH", "LANG", "TERM"]) {
|
|
42
|
+
if (process.env[key]) safeEnv[key] = process.env[key] ?? "";
|
|
43
|
+
}
|
|
44
|
+
const BLOCKED_ENV_KEYS = /* @__PURE__ */ new Set([
|
|
45
|
+
"LD_PRELOAD",
|
|
46
|
+
"NODE_OPTIONS",
|
|
47
|
+
"LD_LIBRARY_PATH",
|
|
48
|
+
"DYLD_INSERT_LIBRARIES",
|
|
49
|
+
"ELECTRON_RUN_AS_NODE"
|
|
50
|
+
]);
|
|
51
|
+
const filteredEnv = {};
|
|
52
|
+
for (const [k, v] of Object.entries(serverConfig.env ?? {})) {
|
|
53
|
+
if (BLOCKED_ENV_KEYS.has(k.toUpperCase())) {
|
|
54
|
+
log.warn({ key: k, server: name }, "Blocked dangerous env var for MCP server");
|
|
55
|
+
} else {
|
|
56
|
+
filteredEnv[k] = v;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
transport = new StdioClientTransport({
|
|
60
|
+
command,
|
|
61
|
+
args,
|
|
62
|
+
env: { ...safeEnv, ...filteredEnv },
|
|
63
|
+
stderr: "pipe"
|
|
64
|
+
});
|
|
65
|
+
} else if (serverConfig.url) {
|
|
66
|
+
transport = new StreamableHTTPClientTransport(new URL(serverConfig.url));
|
|
67
|
+
} else {
|
|
68
|
+
throw new Error(`MCP server "${name}": needs 'command' or 'url'`);
|
|
69
|
+
}
|
|
70
|
+
const client = new Client({ name: `teleton-${name}`, version: "1.0.0" });
|
|
71
|
+
let timeoutHandle;
|
|
72
|
+
try {
|
|
73
|
+
await Promise.race([
|
|
74
|
+
client.connect(transport),
|
|
75
|
+
new Promise((_, reject) => {
|
|
76
|
+
timeoutHandle = setTimeout(
|
|
77
|
+
() => reject(new Error(`Connection timed out after ${MCP_CONNECT_TIMEOUT_MS / 1e3}s`)),
|
|
78
|
+
MCP_CONNECT_TIMEOUT_MS
|
|
79
|
+
);
|
|
80
|
+
})
|
|
81
|
+
]).finally(() => clearTimeout(timeoutHandle));
|
|
82
|
+
} catch (error) {
|
|
83
|
+
if (serverConfig.url && transport instanceof StreamableHTTPClientTransport) {
|
|
84
|
+
await client.close().catch(() => {
|
|
85
|
+
});
|
|
86
|
+
log.info({ server: name }, "Streamable HTTP failed, falling back to SSE");
|
|
87
|
+
transport = new SSEClientTransport(new URL(serverConfig.url));
|
|
88
|
+
const fallbackClient = new Client({ name: `teleton-${name}`, version: "1.0.0" });
|
|
89
|
+
await Promise.race([
|
|
90
|
+
fallbackClient.connect(transport),
|
|
91
|
+
new Promise((_, reject) => {
|
|
92
|
+
timeoutHandle = setTimeout(
|
|
93
|
+
() => reject(
|
|
94
|
+
new Error(`SSE fallback timed out after ${MCP_CONNECT_TIMEOUT_MS / 1e3}s`)
|
|
95
|
+
),
|
|
96
|
+
MCP_CONNECT_TIMEOUT_MS
|
|
97
|
+
);
|
|
98
|
+
})
|
|
99
|
+
]).finally(() => clearTimeout(timeoutHandle));
|
|
100
|
+
return {
|
|
101
|
+
serverName: name,
|
|
102
|
+
client: fallbackClient,
|
|
103
|
+
scope: serverConfig.scope ?? "always"
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
return { serverName: name, client, scope: serverConfig.scope ?? "always" };
|
|
109
|
+
})
|
|
110
|
+
);
|
|
111
|
+
const connections = [];
|
|
112
|
+
for (let i = 0; i < results.length; i++) {
|
|
113
|
+
const result = results[i];
|
|
114
|
+
const [name] = entries[i];
|
|
115
|
+
if (result.status === "fulfilled") {
|
|
116
|
+
connections.push(result.value);
|
|
117
|
+
} else {
|
|
118
|
+
const reason = result.reason instanceof Error ? result.reason.stack ?? result.reason.message : result.reason;
|
|
119
|
+
log.warn({ server: name, reason }, `MCP server "${name}" failed to connect`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return connections;
|
|
123
|
+
}
|
|
124
|
+
async function registerMcpTools(connections, registry) {
|
|
125
|
+
let totalCount = 0;
|
|
126
|
+
const serverNames = [];
|
|
127
|
+
for (const conn of connections) {
|
|
128
|
+
try {
|
|
129
|
+
const { tools: mcpTools } = await conn.client.listTools();
|
|
130
|
+
if (!mcpTools || mcpTools.length === 0) continue;
|
|
131
|
+
const registryTools = [];
|
|
132
|
+
for (const mcpTool of mcpTools) {
|
|
133
|
+
const prefixedName = `mcp_${conn.serverName}_${mcpTool.name}`;
|
|
134
|
+
const executor = async (params) => {
|
|
135
|
+
try {
|
|
136
|
+
let timeoutHandle;
|
|
137
|
+
const result = await Promise.race([
|
|
138
|
+
conn.client.callTool({
|
|
139
|
+
name: mcpTool.name,
|
|
140
|
+
arguments: params
|
|
141
|
+
}),
|
|
142
|
+
new Promise((_, reject) => {
|
|
143
|
+
timeoutHandle = setTimeout(
|
|
144
|
+
() => reject(
|
|
145
|
+
new Error(
|
|
146
|
+
`MCP tool "${mcpTool.name}" timed out after ${TOOL_EXECUTION_TIMEOUT_MS / 1e3}s`
|
|
147
|
+
)
|
|
148
|
+
),
|
|
149
|
+
TOOL_EXECUTION_TIMEOUT_MS
|
|
150
|
+
);
|
|
151
|
+
})
|
|
152
|
+
]).finally(() => clearTimeout(timeoutHandle));
|
|
153
|
+
if (result.isError) {
|
|
154
|
+
const errorText = extractText(
|
|
155
|
+
result.content
|
|
156
|
+
);
|
|
157
|
+
return {
|
|
158
|
+
success: false,
|
|
159
|
+
error: sanitizeForContext(errorText) || "MCP tool returned error"
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
const text = extractText(result.content);
|
|
163
|
+
return { success: true, data: sanitizeForContext(text) };
|
|
164
|
+
} catch (innerError) {
|
|
165
|
+
return {
|
|
166
|
+
success: false,
|
|
167
|
+
error: `MCP tool "${mcpTool.name}" failed: ${getErrorMessage(innerError)}`
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
const schema = mcpTool.inputSchema ?? { type: "object", properties: {} };
|
|
172
|
+
if (!schema.properties || Object.keys(schema.properties).length === 0) {
|
|
173
|
+
log.warn(
|
|
174
|
+
{ tool: mcpTool.name, server: conn.serverName },
|
|
175
|
+
"MCP tool has no parameter schema \u2014 inputs will not be validated"
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
registryTools.push({
|
|
179
|
+
tool: {
|
|
180
|
+
name: prefixedName,
|
|
181
|
+
description: mcpTool.description || `MCP tool from ${conn.serverName}`,
|
|
182
|
+
parameters: schema
|
|
183
|
+
},
|
|
184
|
+
executor,
|
|
185
|
+
scope: conn.scope
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
const count = registry.registerPluginTools(`mcp_${conn.serverName}`, registryTools);
|
|
189
|
+
if (count > 0) {
|
|
190
|
+
totalCount += count;
|
|
191
|
+
serverNames.push(conn.serverName);
|
|
192
|
+
}
|
|
193
|
+
} catch (error) {
|
|
194
|
+
log.warn(`MCP server "${conn.serverName}" tool discovery failed: ${getErrorMessage(error)}`);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return { count: totalCount, names: serverNames };
|
|
198
|
+
}
|
|
199
|
+
async function closeMcpServers(connections) {
|
|
200
|
+
await Promise.allSettled(
|
|
201
|
+
connections.map(async (conn) => {
|
|
202
|
+
try {
|
|
203
|
+
await conn.client.close();
|
|
204
|
+
} catch (error) {
|
|
205
|
+
log.warn(`MCP server "${conn.serverName}" close failed: ${getErrorMessage(error)}`);
|
|
206
|
+
}
|
|
207
|
+
})
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export {
|
|
212
|
+
loadMcpServers,
|
|
213
|
+
registerMcpTools,
|
|
214
|
+
closeMcpServers
|
|
215
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// src/utils/sanitize.ts
|
|
2
|
+
function sanitizeForPrompt(text) {
|
|
3
|
+
return text.normalize("NFKC").replace(/[\x00-\x08\x0b\x0c\x0e-\x1f]/g, "").replace(/[\u00AD\u034F\u061C\u180E\u200B-\u200F\u2060-\u2064\uFEFF]/g, "").replace(/[\uFE00-\uFE0F]/g, "").replace(/[\u{E0000}-\u{E007F}]/gu, "").replace(/[\u{E0100}-\u{E01EF}]/gu, "").replace(/[\u202A-\u202E\u2066-\u2069]/g, "").replace(/[\r\n\u2028\u2029]+/g, " ").replace(/#{1,6}\s/g, "").replace(/<\/?[a-zA-Z_][^>]*>/g, "").replace(/`{3,}/g, "`").trim().slice(0, 128);
|
|
4
|
+
}
|
|
5
|
+
function sanitizeForContext(text) {
|
|
6
|
+
return text.normalize("NFKC").replace(/[\x00-\x08\x0b\x0c\x0e-\x1f]/g, "").replace(/[\u00AD\u034F\u061C\u180E\u200B-\u200F\u2060-\u2064\uFEFF]/g, "").replace(/[\uFE00-\uFE0F]/g, "").replace(/[\u{E0000}-\u{E007F}]/gu, "").replace(/[\u{E0100}-\u{E01EF}]/gu, "").replace(/[\u202A-\u202E\u2066-\u2069]/g, "").replace(/[\u2028\u2029]/g, "\n").replace(/<\/?[a-zA-Z_][^>]*>/g, "").replace(/`{3,}/g, "``").trim();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
sanitizeForPrompt,
|
|
11
|
+
sanitizeForContext
|
|
12
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getModelsForProvider
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-3NO7QU7W.js";
|
|
4
4
|
import {
|
|
5
5
|
generateWallet,
|
|
6
6
|
getWalletAddress,
|
|
@@ -9,34 +9,39 @@ import {
|
|
|
9
9
|
saveWallet,
|
|
10
10
|
walletExists,
|
|
11
11
|
writeRawConfig
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-ZHRDETCX.js";
|
|
13
13
|
import {
|
|
14
14
|
ConfigSchema,
|
|
15
|
-
DealsConfigSchema
|
|
15
|
+
DealsConfigSchema
|
|
16
|
+
} from "./chunk-2UUGRY5B.js";
|
|
17
|
+
import {
|
|
18
|
+
getErrorMessage
|
|
19
|
+
} from "./chunk-3UFPFWYP.js";
|
|
20
|
+
import {
|
|
16
21
|
ensureWorkspace,
|
|
17
22
|
isNewWorkspace
|
|
18
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-CXTZPOTA.js";
|
|
19
24
|
import {
|
|
20
25
|
TELEGRAM_MAX_MESSAGE_LENGTH
|
|
21
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-J4WDJ7XS.js";
|
|
22
27
|
import {
|
|
23
28
|
getClaudeCodeApiKey,
|
|
24
29
|
isClaudeCodeTokenValid
|
|
25
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-R6W4DJRK.js";
|
|
26
31
|
import {
|
|
27
32
|
getProviderMetadata,
|
|
28
33
|
getSupportedProviders,
|
|
29
34
|
validateApiKeyFormat
|
|
30
|
-
} from "./chunk-
|
|
35
|
+
} from "./chunk-TFTNZZDH.js";
|
|
31
36
|
import {
|
|
32
37
|
fetchWithTimeout
|
|
33
38
|
} from "./chunk-XQUHC3JZ.js";
|
|
34
39
|
import {
|
|
35
40
|
TELETON_ROOT
|
|
36
|
-
} from "./chunk-
|
|
41
|
+
} from "./chunk-L653KKCR.js";
|
|
37
42
|
import {
|
|
38
43
|
createLogger
|
|
39
|
-
} from "./chunk-
|
|
44
|
+
} from "./chunk-V3S3NXBQ.js";
|
|
40
45
|
|
|
41
46
|
// src/webui/routes/setup.ts
|
|
42
47
|
import { Hono } from "hono";
|
|
@@ -143,9 +148,9 @@ var TelegramAuthManager = class {
|
|
|
143
148
|
await this.saveSession(session);
|
|
144
149
|
log.info("Telegram authentication successful");
|
|
145
150
|
return { status: "authenticated", user };
|
|
146
|
-
} catch (
|
|
147
|
-
const
|
|
148
|
-
if (
|
|
151
|
+
} catch (error) {
|
|
152
|
+
const tgError = error;
|
|
153
|
+
if (tgError.errorMessage === "SESSION_PASSWORD_NEEDED") {
|
|
149
154
|
session.state = "2fa_required";
|
|
150
155
|
try {
|
|
151
156
|
const passwordResult = await session.client.invoke(new Api.account.GetPassword());
|
|
@@ -154,14 +159,14 @@ var TelegramAuthManager = class {
|
|
|
154
159
|
}
|
|
155
160
|
return { status: "2fa_required", passwordHint: session.passwordHint };
|
|
156
161
|
}
|
|
157
|
-
if (
|
|
162
|
+
if (tgError.errorMessage === "PHONE_CODE_INVALID") {
|
|
158
163
|
return { status: "invalid_code" };
|
|
159
164
|
}
|
|
160
|
-
if (
|
|
165
|
+
if (tgError.errorMessage === "PHONE_CODE_EXPIRED") {
|
|
161
166
|
session.state = "failed";
|
|
162
167
|
return { status: "expired" };
|
|
163
168
|
}
|
|
164
|
-
throw
|
|
169
|
+
throw error;
|
|
165
170
|
}
|
|
166
171
|
}
|
|
167
172
|
/**
|
|
@@ -186,12 +191,12 @@ var TelegramAuthManager = class {
|
|
|
186
191
|
await this.saveSession(session);
|
|
187
192
|
log.info("Telegram 2FA authentication successful");
|
|
188
193
|
return { status: "authenticated", user };
|
|
189
|
-
} catch (
|
|
190
|
-
const
|
|
191
|
-
if (
|
|
194
|
+
} catch (error) {
|
|
195
|
+
const tgError = error;
|
|
196
|
+
if (tgError.errorMessage === "PASSWORD_HASH_INVALID") {
|
|
192
197
|
return { status: "invalid_password" };
|
|
193
198
|
}
|
|
194
|
-
throw
|
|
199
|
+
throw error;
|
|
195
200
|
}
|
|
196
201
|
}
|
|
197
202
|
/**
|
|
@@ -319,9 +324,9 @@ var TelegramAuthManager = class {
|
|
|
319
324
|
};
|
|
320
325
|
}
|
|
321
326
|
return { status: "waiting" };
|
|
322
|
-
} catch (
|
|
323
|
-
const
|
|
324
|
-
if (
|
|
327
|
+
} catch (error) {
|
|
328
|
+
const tgError = error;
|
|
329
|
+
if (tgError.errorMessage === "SESSION_PASSWORD_NEEDED") {
|
|
325
330
|
session.state = "2fa_required";
|
|
326
331
|
try {
|
|
327
332
|
const passwordResult = await session.client.invoke(new Api.account.GetPassword());
|
|
@@ -330,7 +335,7 @@ var TelegramAuthManager = class {
|
|
|
330
335
|
}
|
|
331
336
|
return { status: "2fa_required", passwordHint: session.passwordHint };
|
|
332
337
|
}
|
|
333
|
-
throw
|
|
338
|
+
throw error;
|
|
334
339
|
}
|
|
335
340
|
}
|
|
336
341
|
/**
|
|
@@ -351,8 +356,8 @@ var TelegramAuthManager = class {
|
|
|
351
356
|
if (this.session.client.connected) {
|
|
352
357
|
await this.session.client.disconnect();
|
|
353
358
|
}
|
|
354
|
-
} catch (
|
|
355
|
-
log.warn({
|
|
359
|
+
} catch (error) {
|
|
360
|
+
log.warn({ error }, "Error disconnecting auth client");
|
|
356
361
|
}
|
|
357
362
|
this.session = null;
|
|
358
363
|
}
|
|
@@ -429,11 +434,8 @@ function createSetupRoutes(options) {
|
|
|
429
434
|
}
|
|
430
435
|
}
|
|
431
436
|
});
|
|
432
|
-
} catch (
|
|
433
|
-
return c.json(
|
|
434
|
-
{ success: false, error: err instanceof Error ? err.message : String(err) },
|
|
435
|
-
500
|
|
436
|
-
);
|
|
437
|
+
} catch (error) {
|
|
438
|
+
return c.json({ success: false, error: getErrorMessage(error) }, 500);
|
|
437
439
|
}
|
|
438
440
|
});
|
|
439
441
|
app.get("/providers", (c) => {
|
|
@@ -489,17 +491,14 @@ function createSetupRoutes(options) {
|
|
|
489
491
|
const body = await c.req.json();
|
|
490
492
|
const error = validateApiKeyFormat(body.provider, body.apiKey);
|
|
491
493
|
return c.json({ success: true, data: { valid: !error, error } });
|
|
492
|
-
} catch (
|
|
493
|
-
return c.json(
|
|
494
|
-
{ success: false, error: err instanceof Error ? err.message : String(err) },
|
|
495
|
-
400
|
|
496
|
-
);
|
|
494
|
+
} catch (error) {
|
|
495
|
+
return c.json({ success: false, error: getErrorMessage(error) }, 400);
|
|
497
496
|
}
|
|
498
497
|
});
|
|
499
498
|
app.post("/validate/bot-token", async (c) => {
|
|
500
499
|
try {
|
|
501
500
|
const body = await c.req.json();
|
|
502
|
-
if (!body.token ||
|
|
501
|
+
if (!body.token || !/^[0-9]+:[A-Za-z0-9_-]+$/.test(body.token)) {
|
|
503
502
|
return c.json({
|
|
504
503
|
success: true,
|
|
505
504
|
data: { valid: false, networkError: false, error: "Invalid format (expected id:hash)" }
|
|
@@ -528,11 +527,8 @@ function createSetupRoutes(options) {
|
|
|
528
527
|
data: { valid: false, networkError: true, error: "Could not reach Telegram API" }
|
|
529
528
|
});
|
|
530
529
|
}
|
|
531
|
-
} catch (
|
|
532
|
-
return c.json(
|
|
533
|
-
{ success: false, error: err instanceof Error ? err.message : String(err) },
|
|
534
|
-
400
|
|
535
|
-
);
|
|
530
|
+
} catch (error) {
|
|
531
|
+
return c.json({ success: false, error: getErrorMessage(error) }, 400);
|
|
536
532
|
}
|
|
537
533
|
});
|
|
538
534
|
app.post("/workspace/init", async (c) => {
|
|
@@ -554,11 +550,8 @@ function createSetupRoutes(options) {
|
|
|
554
550
|
success: true,
|
|
555
551
|
data: { created: !isNewWorkspace(workspace) === false, path: workspace.root }
|
|
556
552
|
});
|
|
557
|
-
} catch (
|
|
558
|
-
return c.json(
|
|
559
|
-
{ success: false, error: err instanceof Error ? err.message : String(err) },
|
|
560
|
-
500
|
|
561
|
-
);
|
|
553
|
+
} catch (error) {
|
|
554
|
+
return c.json({ success: false, error: getErrorMessage(error) }, 500);
|
|
562
555
|
}
|
|
563
556
|
});
|
|
564
557
|
app.get("/wallet/status", (c) => {
|
|
@@ -575,11 +568,8 @@ function createSetupRoutes(options) {
|
|
|
575
568
|
success: true,
|
|
576
569
|
data: { address: wallet.address, mnemonic: wallet.mnemonic }
|
|
577
570
|
});
|
|
578
|
-
} catch (
|
|
579
|
-
return c.json(
|
|
580
|
-
{ success: false, error: err instanceof Error ? err.message : String(err) },
|
|
581
|
-
500
|
|
582
|
-
);
|
|
571
|
+
} catch (error) {
|
|
572
|
+
return c.json({ success: false, error: getErrorMessage(error) }, 500);
|
|
583
573
|
}
|
|
584
574
|
});
|
|
585
575
|
app.post("/wallet/import", async (c) => {
|
|
@@ -593,11 +583,8 @@ function createSetupRoutes(options) {
|
|
|
593
583
|
saveWallet(wallet);
|
|
594
584
|
log2.info("TON wallet imported via setup UI");
|
|
595
585
|
return c.json({ success: true, data: { address: wallet.address } });
|
|
596
|
-
} catch (
|
|
597
|
-
return c.json(
|
|
598
|
-
{ success: false, error: err instanceof Error ? err.message : String(err) },
|
|
599
|
-
400
|
|
600
|
-
);
|
|
586
|
+
} catch (error) {
|
|
587
|
+
return c.json({ success: false, error: getErrorMessage(error) }, 400);
|
|
601
588
|
}
|
|
602
589
|
});
|
|
603
590
|
app.post("/telegram/send-code", async (c) => {
|
|
@@ -608,19 +595,19 @@ function createSetupRoutes(options) {
|
|
|
608
595
|
}
|
|
609
596
|
const result = await authManager.sendCode(body.apiId, body.apiHash, body.phone);
|
|
610
597
|
return c.json({ success: true, data: result });
|
|
611
|
-
} catch (
|
|
612
|
-
const
|
|
613
|
-
if (
|
|
598
|
+
} catch (error) {
|
|
599
|
+
const tgError = error;
|
|
600
|
+
if (tgError.seconds) {
|
|
614
601
|
return c.json(
|
|
615
602
|
{
|
|
616
603
|
success: false,
|
|
617
|
-
error: `Rate limited. Please wait ${
|
|
604
|
+
error: `Rate limited. Please wait ${tgError.seconds} seconds.`
|
|
618
605
|
},
|
|
619
606
|
429
|
|
620
607
|
);
|
|
621
608
|
}
|
|
622
609
|
return c.json(
|
|
623
|
-
{ success: false, error:
|
|
610
|
+
{ success: false, error: tgError.errorMessage || tgError.message || String(error) },
|
|
624
611
|
500
|
|
625
612
|
);
|
|
626
613
|
}
|
|
@@ -633,19 +620,19 @@ function createSetupRoutes(options) {
|
|
|
633
620
|
}
|
|
634
621
|
const result = await authManager.verifyCode(body.authSessionId, body.code);
|
|
635
622
|
return c.json({ success: true, data: result });
|
|
636
|
-
} catch (
|
|
637
|
-
const
|
|
638
|
-
if (
|
|
623
|
+
} catch (error) {
|
|
624
|
+
const tgError = error;
|
|
625
|
+
if (tgError.seconds) {
|
|
639
626
|
return c.json(
|
|
640
627
|
{
|
|
641
628
|
success: false,
|
|
642
|
-
error: `Rate limited. Please wait ${
|
|
629
|
+
error: `Rate limited. Please wait ${tgError.seconds} seconds.`
|
|
643
630
|
},
|
|
644
631
|
429
|
|
645
632
|
);
|
|
646
633
|
}
|
|
647
634
|
return c.json(
|
|
648
|
-
{ success: false, error:
|
|
635
|
+
{ success: false, error: tgError.errorMessage || tgError.message || String(error) },
|
|
649
636
|
500
|
|
650
637
|
);
|
|
651
638
|
}
|
|
@@ -658,19 +645,19 @@ function createSetupRoutes(options) {
|
|
|
658
645
|
}
|
|
659
646
|
const result = await authManager.verifyPassword(body.authSessionId, body.password);
|
|
660
647
|
return c.json({ success: true, data: result });
|
|
661
|
-
} catch (
|
|
662
|
-
const
|
|
663
|
-
if (
|
|
648
|
+
} catch (error) {
|
|
649
|
+
const tgError = error;
|
|
650
|
+
if (tgError.seconds) {
|
|
664
651
|
return c.json(
|
|
665
652
|
{
|
|
666
653
|
success: false,
|
|
667
|
-
error: `Rate limited. Please wait ${
|
|
654
|
+
error: `Rate limited. Please wait ${tgError.seconds} seconds.`
|
|
668
655
|
},
|
|
669
656
|
429
|
|
670
657
|
);
|
|
671
658
|
}
|
|
672
659
|
return c.json(
|
|
673
|
-
{ success: false, error:
|
|
660
|
+
{ success: false, error: tgError.errorMessage || tgError.message || String(error) },
|
|
674
661
|
500
|
|
675
662
|
);
|
|
676
663
|
}
|
|
@@ -686,19 +673,19 @@ function createSetupRoutes(options) {
|
|
|
686
673
|
return c.json({ success: false, error: "Session expired or invalid" }, 400);
|
|
687
674
|
}
|
|
688
675
|
return c.json({ success: true, data: result });
|
|
689
|
-
} catch (
|
|
690
|
-
const
|
|
691
|
-
if (
|
|
676
|
+
} catch (error) {
|
|
677
|
+
const tgError = error;
|
|
678
|
+
if (tgError.seconds) {
|
|
692
679
|
return c.json(
|
|
693
680
|
{
|
|
694
681
|
success: false,
|
|
695
|
-
error: `Rate limited. Please wait ${
|
|
682
|
+
error: `Rate limited. Please wait ${tgError.seconds} seconds.`
|
|
696
683
|
},
|
|
697
684
|
429
|
|
698
685
|
);
|
|
699
686
|
}
|
|
700
687
|
return c.json(
|
|
701
|
-
{ success: false, error:
|
|
688
|
+
{ success: false, error: tgError.errorMessage || tgError.message || String(error) },
|
|
702
689
|
500
|
|
703
690
|
);
|
|
704
691
|
}
|
|
@@ -711,16 +698,16 @@ function createSetupRoutes(options) {
|
|
|
711
698
|
}
|
|
712
699
|
const result = await authManager.startQrSession(body.apiId, body.apiHash);
|
|
713
700
|
return c.json({ success: true, data: result });
|
|
714
|
-
} catch (
|
|
715
|
-
const
|
|
716
|
-
if (
|
|
701
|
+
} catch (error) {
|
|
702
|
+
const tgError = error;
|
|
703
|
+
if (tgError.seconds) {
|
|
717
704
|
return c.json(
|
|
718
|
-
{ success: false, error: `Rate limited. Please wait ${
|
|
705
|
+
{ success: false, error: `Rate limited. Please wait ${tgError.seconds} seconds.` },
|
|
719
706
|
429
|
|
720
707
|
);
|
|
721
708
|
}
|
|
722
709
|
return c.json(
|
|
723
|
-
{ success: false, error:
|
|
710
|
+
{ success: false, error: tgError.errorMessage || tgError.message || String(error) },
|
|
724
711
|
500
|
|
725
712
|
);
|
|
726
713
|
}
|
|
@@ -733,16 +720,16 @@ function createSetupRoutes(options) {
|
|
|
733
720
|
}
|
|
734
721
|
const result = await authManager.refreshQrToken(body.authSessionId);
|
|
735
722
|
return c.json({ success: true, data: result });
|
|
736
|
-
} catch (
|
|
737
|
-
const
|
|
738
|
-
if (
|
|
723
|
+
} catch (error) {
|
|
724
|
+
const tgError = error;
|
|
725
|
+
if (tgError.seconds) {
|
|
739
726
|
return c.json(
|
|
740
|
-
{ success: false, error: `Rate limited. Please wait ${
|
|
727
|
+
{ success: false, error: `Rate limited. Please wait ${tgError.seconds} seconds.` },
|
|
741
728
|
429
|
|
742
729
|
);
|
|
743
730
|
}
|
|
744
731
|
return c.json(
|
|
745
|
-
{ success: false, error:
|
|
732
|
+
{ success: false, error: tgError.errorMessage || tgError.message || String(error) },
|
|
746
733
|
500
|
|
747
734
|
);
|
|
748
735
|
}
|
|
@@ -752,16 +739,13 @@ function createSetupRoutes(options) {
|
|
|
752
739
|
const body = await c.req.json().catch(() => ({ authSessionId: "" }));
|
|
753
740
|
await authManager.cancelSession(body.authSessionId);
|
|
754
741
|
return c.json({ success: true });
|
|
755
|
-
} catch (
|
|
756
|
-
return c.json(
|
|
757
|
-
{ success: false, error: err instanceof Error ? err.message : String(err) },
|
|
758
|
-
500
|
|
759
|
-
);
|
|
742
|
+
} catch (error) {
|
|
743
|
+
return c.json({ success: false, error: getErrorMessage(error) }, 500);
|
|
760
744
|
}
|
|
761
745
|
});
|
|
762
746
|
app.post("/embeddings/warmup", async (c) => {
|
|
763
747
|
try {
|
|
764
|
-
const { LocalEmbeddingProvider } = await import("./local-
|
|
748
|
+
const { LocalEmbeddingProvider } = await import("./local-MSZAXWUL.js");
|
|
765
749
|
const provider = new LocalEmbeddingProvider({});
|
|
766
750
|
const success = await provider.warmup();
|
|
767
751
|
return c.json({
|
|
@@ -770,10 +754,7 @@ function createSetupRoutes(options) {
|
|
|
770
754
|
dimensions: provider.dimensions
|
|
771
755
|
});
|
|
772
756
|
} catch (error) {
|
|
773
|
-
return c.json(
|
|
774
|
-
{ success: false, error: error instanceof Error ? error.message : String(error) },
|
|
775
|
-
500
|
|
776
|
-
);
|
|
757
|
+
return c.json({ success: false, error: getErrorMessage(error) }, 500);
|
|
777
758
|
}
|
|
778
759
|
});
|
|
779
760
|
app.get("/embeddings/status", (c) => {
|
|
@@ -814,6 +795,7 @@ function createSetupRoutes(options) {
|
|
|
814
795
|
}
|
|
815
796
|
},
|
|
816
797
|
telegram: {
|
|
798
|
+
...input.telegram.mode === "bot" ? { mode: "bot" } : {},
|
|
817
799
|
api_id: input.telegram.api_id,
|
|
818
800
|
api_hash: input.telegram.api_hash,
|
|
819
801
|
phone: input.telegram.phone,
|
|
@@ -896,11 +878,8 @@ function createSetupRoutes(options) {
|
|
|
896
878
|
writeFileSync2(configPath, YAML.stringify(config), { encoding: "utf-8", mode: 384 });
|
|
897
879
|
log2.info(`Configuration saved: ${configPath}`);
|
|
898
880
|
return c.json({ success: true, data: { path: configPath } });
|
|
899
|
-
} catch (
|
|
900
|
-
return c.json(
|
|
901
|
-
{ success: false, error: err instanceof Error ? err.message : String(err) },
|
|
902
|
-
400
|
|
903
|
-
);
|
|
881
|
+
} catch (error) {
|
|
882
|
+
return c.json({ success: false, error: getErrorMessage(error) }, 400);
|
|
904
883
|
}
|
|
905
884
|
});
|
|
906
885
|
return app;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
TELETON_ROOT
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-L653KKCR.js";
|
|
4
4
|
import {
|
|
5
5
|
createLogger
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-V3S3NXBQ.js";
|
|
7
7
|
|
|
8
8
|
// src/memory/embeddings/local.ts
|
|
9
9
|
import { pipeline, env } from "@huggingface/transformers";
|
|
@@ -42,7 +42,7 @@ async function ensureModelCached(model) {
|
|
|
42
42
|
}
|
|
43
43
|
const buffer = Buffer.from(await res.arrayBuffer());
|
|
44
44
|
const tmpPath = localPath + ".tmp";
|
|
45
|
-
writeFileSync(tmpPath, buffer);
|
|
45
|
+
writeFileSync(tmpPath, buffer, { mode: 384 });
|
|
46
46
|
renameSync(tmpPath, localPath);
|
|
47
47
|
}
|
|
48
48
|
}
|