teleton 0.8.0 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -11
- package/dist/{chunk-H36RFKRI.js → chunk-2IZU3REP.js} +572 -174
- package/dist/chunk-3UFPFWYP.js +12 -0
- package/dist/{chunk-NUGDTPE4.js → chunk-4L66JHQE.js} +2 -1
- package/dist/{chunk-TVRZJIZX.js → chunk-55SKE6YH.js} +4 -4
- package/dist/{setup-server-QXED3D2L.js → chunk-57URFK6M.js} +161 -210
- package/dist/chunk-5SEMA47R.js +75 -0
- package/dist/{chunk-JHYZYFZJ.js → chunk-7YKSXOQQ.js} +17 -2
- package/dist/{chunk-IJBWWQE4.js → chunk-C4NKJT2Z.js} +12 -0
- package/dist/{chunk-RQBAMUCV.js → chunk-GGXJLMOH.js} +1451 -743
- package/dist/{chunk-WIKM24GZ.js → chunk-H7MFXJZK.js} +7 -2
- package/dist/{chunk-U56QTM46.js → chunk-HEDJCLA6.js} +85 -44
- package/dist/{chunk-QVBSUYVX.js → chunk-J73TA3UM.js} +17 -9
- package/dist/{chunk-P36I6OIV.js → chunk-LC4TV3KL.js} +13 -2
- package/dist/{chunk-RCMD3U65.js → chunk-NQ6FZKCE.js} +13 -0
- package/dist/{chunk-SD4NLLYG.js → chunk-VYKW7FMV.js} +224 -93
- package/dist/chunk-W25Z7CM6.js +487 -0
- package/dist/{chunk-OJCLKU5Z.js → chunk-WFTC3JJW.js} +16 -0
- package/dist/{server-H3QA252W.js → chunk-XBSCYMKM.js} +369 -374
- package/dist/{chunk-PHSAHTK4.js → chunk-YOSUPUAJ.js} +75 -7
- package/dist/cli/index.js +67 -22
- package/dist/{client-LNZTDQSA.js → client-YOOHI776.js} +4 -4
- package/dist/{get-my-gifts-OMGKOEPM.js → get-my-gifts-Y7EN7RK4.js} +3 -3
- package/dist/index.js +15 -14
- package/dist/{memory-AS7WKGTW.js → memory-Q6EWGK2S.js} +7 -5
- package/dist/memory-hook-WUXJNVT5.js +18 -0
- package/dist/{migrate-POHWYEIW.js → migrate-WFU6COBN.js} +5 -5
- package/dist/server-GYZXKIKU.js +787 -0
- package/dist/server-YODFBZKG.js +392 -0
- package/dist/setup-server-IZBUOJRU.js +215 -0
- package/dist/{store-GAFULOOX.js → store-7M4XV6M5.js} +6 -6
- package/dist/{task-dependency-resolver-3FIKQ7Z6.js → task-dependency-resolver-L6UUMTHK.js} +3 -3
- package/dist/{task-executor-RUTFG6VG.js → task-executor-XBNJLUCS.js} +3 -3
- package/dist/{tasks-BEZ4QRI2.js → tasks-WQIKXDX5.js} +1 -1
- package/dist/{tool-adapter-IH5VGBOO.js → tool-adapter-IVX2XQJE.js} +1 -1
- package/dist/{tool-index-H3SHOJC3.js → tool-index-NYH57UWP.js} +9 -6
- package/dist/{transcript-IMNE6KU3.js → transcript-IM7G25OS.js} +2 -2
- package/dist/web/assets/index-BfYCdwLI.js +80 -0
- package/dist/web/assets/{index-BrVqauzj.css → index-DmlyQVhR.css} +1 -1
- package/dist/web/assets/{index.es-DkU1GvWU.js → index.es-DitvF-9H.js} +1 -1
- package/dist/web/index.html +2 -2
- package/package.json +14 -5
- package/dist/chunk-XBE4JB7C.js +0 -8
- package/dist/web/assets/index-DYeEkvJ6.js +0 -72
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createConfigRoutes,
|
|
3
|
+
createHooksRoutes,
|
|
4
|
+
createLogsRoutes,
|
|
5
|
+
createMarketplaceRoutes,
|
|
6
|
+
createMcpRoutes,
|
|
7
|
+
createMemoryRoutes,
|
|
8
|
+
createPluginsRoutes,
|
|
9
|
+
createSoulRoutes,
|
|
10
|
+
createStatusRoutes,
|
|
11
|
+
createTasksRoutes,
|
|
12
|
+
createTonProxyRoutes,
|
|
13
|
+
createToolsRoutes,
|
|
14
|
+
createWorkspaceRoutes,
|
|
15
|
+
logInterceptor
|
|
16
|
+
} from "./chunk-XBSCYMKM.js";
|
|
17
|
+
import "./chunk-WFTC3JJW.js";
|
|
18
|
+
import "./chunk-GGXJLMOH.js";
|
|
19
|
+
import "./chunk-7YKSXOQQ.js";
|
|
20
|
+
import "./chunk-55SKE6YH.js";
|
|
21
|
+
import "./chunk-W25Z7CM6.js";
|
|
22
|
+
import "./chunk-3UFPFWYP.js";
|
|
23
|
+
import "./chunk-7TECSLJ4.js";
|
|
24
|
+
import "./chunk-J73TA3UM.js";
|
|
25
|
+
import "./chunk-YOSUPUAJ.js";
|
|
26
|
+
import "./chunk-LC4TV3KL.js";
|
|
27
|
+
import "./chunk-VYKW7FMV.js";
|
|
28
|
+
import "./chunk-HEDJCLA6.js";
|
|
29
|
+
import "./chunk-VFA7QMCZ.js";
|
|
30
|
+
import "./chunk-C4NKJT2Z.js";
|
|
31
|
+
import "./chunk-XQUHC3JZ.js";
|
|
32
|
+
import "./chunk-R4YSJ4EY.js";
|
|
33
|
+
import "./chunk-EYWNOHMJ.js";
|
|
34
|
+
import {
|
|
35
|
+
createLogger
|
|
36
|
+
} from "./chunk-NQ6FZKCE.js";
|
|
37
|
+
import "./chunk-4L66JHQE.js";
|
|
38
|
+
import "./chunk-3RG5ZIWI.js";
|
|
39
|
+
|
|
40
|
+
// src/webui/server.ts
|
|
41
|
+
import { Hono } from "hono";
|
|
42
|
+
import { serve } from "@hono/node-server";
|
|
43
|
+
import { cors } from "hono/cors";
|
|
44
|
+
import { streamSSE } from "hono/streaming";
|
|
45
|
+
import { bodyLimit } from "hono/body-limit";
|
|
46
|
+
import { setCookie, getCookie, deleteCookie } from "hono/cookie";
|
|
47
|
+
import { existsSync, readFileSync } from "fs";
|
|
48
|
+
import { join, dirname, resolve, relative } from "path";
|
|
49
|
+
import { fileURLToPath } from "url";
|
|
50
|
+
|
|
51
|
+
// src/webui/middleware/auth.ts
|
|
52
|
+
import { randomBytes, timingSafeEqual } from "crypto";
|
|
53
|
+
var COOKIE_NAME = "teleton_session";
|
|
54
|
+
var COOKIE_MAX_AGE = 7 * 24 * 60 * 60;
|
|
55
|
+
function generateToken() {
|
|
56
|
+
return randomBytes(32).toString("base64url");
|
|
57
|
+
}
|
|
58
|
+
function maskToken(token) {
|
|
59
|
+
if (token.length < 12) return "****";
|
|
60
|
+
return `${token.slice(0, 4)}...${token.slice(-4)}`;
|
|
61
|
+
}
|
|
62
|
+
function safeCompare(a, b) {
|
|
63
|
+
if (!a || !b) return false;
|
|
64
|
+
const bufA = Buffer.from(a);
|
|
65
|
+
const bufB = Buffer.from(b);
|
|
66
|
+
if (bufA.length !== bufB.length) return false;
|
|
67
|
+
return timingSafeEqual(bufA, bufB);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// src/webui/server.ts
|
|
71
|
+
var log = createLogger("WebUI");
|
|
72
|
+
function findWebDist() {
|
|
73
|
+
const candidates = [
|
|
74
|
+
resolve("dist/web"),
|
|
75
|
+
// npm start / teleton start (from project root)
|
|
76
|
+
resolve("web")
|
|
77
|
+
// fallback
|
|
78
|
+
];
|
|
79
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
80
|
+
candidates.push(
|
|
81
|
+
resolve(__dirname, "web"),
|
|
82
|
+
// dist/web when __dirname = dist/
|
|
83
|
+
resolve(__dirname, "../dist/web")
|
|
84
|
+
// when running with tsx from src/
|
|
85
|
+
);
|
|
86
|
+
for (const candidate of candidates) {
|
|
87
|
+
if (existsSync(join(candidate, "index.html"))) {
|
|
88
|
+
return candidate;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
var WebUIServer = class {
|
|
94
|
+
app;
|
|
95
|
+
server = null;
|
|
96
|
+
deps;
|
|
97
|
+
authToken;
|
|
98
|
+
constructor(deps) {
|
|
99
|
+
this.deps = deps;
|
|
100
|
+
this.app = new Hono();
|
|
101
|
+
this.authToken = deps.config.auth_token || generateToken();
|
|
102
|
+
this.setupMiddleware();
|
|
103
|
+
this.setupRoutes();
|
|
104
|
+
}
|
|
105
|
+
/** Set an HttpOnly session cookie */
|
|
106
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Hono context type
|
|
107
|
+
setSessionCookie(c) {
|
|
108
|
+
setCookie(c, COOKIE_NAME, this.authToken, {
|
|
109
|
+
path: "/",
|
|
110
|
+
httpOnly: true,
|
|
111
|
+
sameSite: "Strict",
|
|
112
|
+
secure: false,
|
|
113
|
+
// localhost is HTTP
|
|
114
|
+
maxAge: COOKIE_MAX_AGE
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
setupMiddleware() {
|
|
118
|
+
this.app.use(
|
|
119
|
+
"*",
|
|
120
|
+
cors({
|
|
121
|
+
origin: this.deps.config.cors_origins,
|
|
122
|
+
credentials: true,
|
|
123
|
+
allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH"],
|
|
124
|
+
allowHeaders: ["Content-Type", "Authorization"],
|
|
125
|
+
maxAge: 3600
|
|
126
|
+
})
|
|
127
|
+
);
|
|
128
|
+
if (this.deps.config.log_requests) {
|
|
129
|
+
this.app.use("*", async (c, next) => {
|
|
130
|
+
const start = Date.now();
|
|
131
|
+
await next();
|
|
132
|
+
const duration = Date.now() - start;
|
|
133
|
+
log.info(`${c.req.method} ${c.req.path} \u2192 ${c.res.status} (${duration}ms)`);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
this.app.use(
|
|
137
|
+
"*",
|
|
138
|
+
bodyLimit({
|
|
139
|
+
maxSize: 2 * 1024 * 1024,
|
|
140
|
+
// 2MB
|
|
141
|
+
onError: (c) => c.json({ success: false, error: "Request body too large (max 2MB)" }, 413)
|
|
142
|
+
})
|
|
143
|
+
);
|
|
144
|
+
this.app.use("*", async (c, next) => {
|
|
145
|
+
await next();
|
|
146
|
+
c.res.headers.set("X-Content-Type-Options", "nosniff");
|
|
147
|
+
c.res.headers.set("X-Frame-Options", "DENY");
|
|
148
|
+
c.res.headers.set("Referrer-Policy", "strict-origin-when-cross-origin");
|
|
149
|
+
});
|
|
150
|
+
this.app.use("/api/*", async (c, next) => {
|
|
151
|
+
const cookieToken = getCookie(c, COOKIE_NAME);
|
|
152
|
+
if (cookieToken && safeCompare(cookieToken, this.authToken)) {
|
|
153
|
+
return next();
|
|
154
|
+
}
|
|
155
|
+
const authHeader = c.req.header("Authorization");
|
|
156
|
+
if (authHeader) {
|
|
157
|
+
const match = authHeader.match(/^Bearer\s+(.+)$/i);
|
|
158
|
+
if (match && safeCompare(match[1], this.authToken)) {
|
|
159
|
+
return next();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
const queryToken = c.req.query("token");
|
|
163
|
+
if (queryToken && safeCompare(queryToken, this.authToken)) {
|
|
164
|
+
return next();
|
|
165
|
+
}
|
|
166
|
+
return c.json({ success: false, error: "Unauthorized" }, 401);
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
setupRoutes() {
|
|
170
|
+
this.app.get("/health", (c) => c.json({ status: "ok" }));
|
|
171
|
+
this.app.get("/auth/exchange", (c) => {
|
|
172
|
+
const token = c.req.query("token");
|
|
173
|
+
if (!token || !safeCompare(token, this.authToken)) {
|
|
174
|
+
return c.json({ success: false, error: "Invalid token" }, 401);
|
|
175
|
+
}
|
|
176
|
+
this.setSessionCookie(c);
|
|
177
|
+
return c.redirect("/");
|
|
178
|
+
});
|
|
179
|
+
this.app.post("/auth/login", async (c) => {
|
|
180
|
+
try {
|
|
181
|
+
const body = await c.req.json();
|
|
182
|
+
if (!body.token || !safeCompare(body.token, this.authToken)) {
|
|
183
|
+
return c.json({ success: false, error: "Invalid token" }, 401);
|
|
184
|
+
}
|
|
185
|
+
this.setSessionCookie(c);
|
|
186
|
+
return c.json({ success: true });
|
|
187
|
+
} catch {
|
|
188
|
+
return c.json({ success: false, error: "Invalid request body" }, 400);
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
this.app.post("/auth/logout", (c) => {
|
|
192
|
+
deleteCookie(c, COOKIE_NAME, { path: "/" });
|
|
193
|
+
return c.json({ success: true });
|
|
194
|
+
});
|
|
195
|
+
this.app.get("/auth/check", (c) => {
|
|
196
|
+
const cookieToken = getCookie(c, COOKIE_NAME);
|
|
197
|
+
const authenticated = !!(cookieToken && safeCompare(cookieToken, this.authToken));
|
|
198
|
+
return c.json({ success: true, data: { authenticated } });
|
|
199
|
+
});
|
|
200
|
+
this.app.route("/api/status", createStatusRoutes(this.deps));
|
|
201
|
+
this.app.route("/api/tools", createToolsRoutes(this.deps));
|
|
202
|
+
this.app.route("/api/logs", createLogsRoutes(this.deps));
|
|
203
|
+
this.app.route("/api/memory", createMemoryRoutes(this.deps));
|
|
204
|
+
this.app.route("/api/soul", createSoulRoutes(this.deps));
|
|
205
|
+
this.app.route("/api/plugins", createPluginsRoutes(this.deps));
|
|
206
|
+
this.app.route("/api/mcp", createMcpRoutes(this.deps));
|
|
207
|
+
this.app.route("/api/workspace", createWorkspaceRoutes(this.deps));
|
|
208
|
+
this.app.route("/api/tasks", createTasksRoutes(this.deps));
|
|
209
|
+
this.app.route("/api/config", createConfigRoutes(this.deps));
|
|
210
|
+
this.app.route("/api/marketplace", createMarketplaceRoutes(this.deps));
|
|
211
|
+
this.app.route("/api/hooks", createHooksRoutes(this.deps));
|
|
212
|
+
this.app.route("/api/ton-proxy", createTonProxyRoutes(this.deps));
|
|
213
|
+
this.app.post("/api/agent/start", async (c) => {
|
|
214
|
+
const lifecycle = this.deps.lifecycle;
|
|
215
|
+
if (!lifecycle) {
|
|
216
|
+
return c.json({ error: "Agent lifecycle not available" }, 503);
|
|
217
|
+
}
|
|
218
|
+
const state = lifecycle.getState();
|
|
219
|
+
if (state === "running") {
|
|
220
|
+
return c.json({ state: "running" }, 409);
|
|
221
|
+
}
|
|
222
|
+
if (state === "stopping") {
|
|
223
|
+
return c.json({ error: "Agent is currently stopping, please wait" }, 409);
|
|
224
|
+
}
|
|
225
|
+
lifecycle.start().catch((err) => {
|
|
226
|
+
log.error({ err }, "Agent start failed");
|
|
227
|
+
});
|
|
228
|
+
return c.json({ state: "starting" });
|
|
229
|
+
});
|
|
230
|
+
this.app.post("/api/agent/stop", async (c) => {
|
|
231
|
+
const lifecycle = this.deps.lifecycle;
|
|
232
|
+
if (!lifecycle) {
|
|
233
|
+
return c.json({ error: "Agent lifecycle not available" }, 503);
|
|
234
|
+
}
|
|
235
|
+
const state = lifecycle.getState();
|
|
236
|
+
if (state === "stopped") {
|
|
237
|
+
return c.json({ state: "stopped" }, 409);
|
|
238
|
+
}
|
|
239
|
+
if (state === "starting") {
|
|
240
|
+
return c.json({ error: "Agent is currently starting, please wait" }, 409);
|
|
241
|
+
}
|
|
242
|
+
lifecycle.stop().catch((err) => {
|
|
243
|
+
log.error({ err }, "Agent stop failed");
|
|
244
|
+
});
|
|
245
|
+
return c.json({ state: "stopping" });
|
|
246
|
+
});
|
|
247
|
+
this.app.get("/api/agent/status", (c) => {
|
|
248
|
+
const lifecycle = this.deps.lifecycle;
|
|
249
|
+
if (!lifecycle) {
|
|
250
|
+
return c.json({ error: "Agent lifecycle not available" }, 503);
|
|
251
|
+
}
|
|
252
|
+
return c.json({
|
|
253
|
+
state: lifecycle.getState(),
|
|
254
|
+
uptime: lifecycle.getUptime(),
|
|
255
|
+
error: lifecycle.getError() ?? null
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
this.app.get("/api/agent/events", (c) => {
|
|
259
|
+
const lifecycle = this.deps.lifecycle;
|
|
260
|
+
if (!lifecycle) {
|
|
261
|
+
return c.json({ error: "Agent lifecycle not available" }, 503);
|
|
262
|
+
}
|
|
263
|
+
return streamSSE(c, async (stream) => {
|
|
264
|
+
let aborted = false;
|
|
265
|
+
stream.onAbort(() => {
|
|
266
|
+
aborted = true;
|
|
267
|
+
});
|
|
268
|
+
const now = Date.now();
|
|
269
|
+
await stream.writeSSE({
|
|
270
|
+
event: "status",
|
|
271
|
+
id: String(now),
|
|
272
|
+
data: JSON.stringify({
|
|
273
|
+
state: lifecycle.getState(),
|
|
274
|
+
error: lifecycle.getError() ?? null,
|
|
275
|
+
timestamp: now
|
|
276
|
+
}),
|
|
277
|
+
retry: 3e3
|
|
278
|
+
});
|
|
279
|
+
const onStateChange = (event) => {
|
|
280
|
+
if (aborted) return;
|
|
281
|
+
void stream.writeSSE({
|
|
282
|
+
event: "status",
|
|
283
|
+
id: String(event.timestamp),
|
|
284
|
+
data: JSON.stringify({
|
|
285
|
+
state: event.state,
|
|
286
|
+
error: event.error ?? null,
|
|
287
|
+
timestamp: event.timestamp
|
|
288
|
+
})
|
|
289
|
+
});
|
|
290
|
+
};
|
|
291
|
+
lifecycle.on("stateChange", onStateChange);
|
|
292
|
+
while (!aborted) {
|
|
293
|
+
await stream.sleep(3e4);
|
|
294
|
+
if (aborted) break;
|
|
295
|
+
await stream.writeSSE({
|
|
296
|
+
event: "ping",
|
|
297
|
+
data: ""
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
lifecycle.off("stateChange", onStateChange);
|
|
301
|
+
});
|
|
302
|
+
});
|
|
303
|
+
const webDist = findWebDist();
|
|
304
|
+
if (webDist) {
|
|
305
|
+
const indexHtml = readFileSync(join(webDist, "index.html"), "utf-8");
|
|
306
|
+
const mimeTypes = {
|
|
307
|
+
js: "application/javascript",
|
|
308
|
+
css: "text/css",
|
|
309
|
+
svg: "image/svg+xml",
|
|
310
|
+
png: "image/png",
|
|
311
|
+
jpg: "image/jpeg",
|
|
312
|
+
jpeg: "image/jpeg",
|
|
313
|
+
ico: "image/x-icon",
|
|
314
|
+
json: "application/json",
|
|
315
|
+
woff2: "font/woff2",
|
|
316
|
+
woff: "font/woff"
|
|
317
|
+
};
|
|
318
|
+
this.app.get("*", (c) => {
|
|
319
|
+
const filePath = resolve(join(webDist, c.req.path));
|
|
320
|
+
const rel = relative(webDist, filePath);
|
|
321
|
+
if (rel.startsWith("..") || resolve(filePath) !== filePath) {
|
|
322
|
+
return c.html(indexHtml);
|
|
323
|
+
}
|
|
324
|
+
try {
|
|
325
|
+
const content = readFileSync(filePath);
|
|
326
|
+
const ext = filePath.split(".").pop() || "";
|
|
327
|
+
if (mimeTypes[ext]) {
|
|
328
|
+
const immutable = c.req.path.startsWith("/assets/");
|
|
329
|
+
return c.body(content, 200, {
|
|
330
|
+
"Content-Type": mimeTypes[ext],
|
|
331
|
+
"Cache-Control": immutable ? "public, max-age=31536000, immutable" : "public, max-age=3600"
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
} catch {
|
|
335
|
+
}
|
|
336
|
+
return c.html(indexHtml);
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
this.app.onError((err, c) => {
|
|
340
|
+
log.error({ err }, "WebUI error");
|
|
341
|
+
return c.json(
|
|
342
|
+
{
|
|
343
|
+
success: false,
|
|
344
|
+
error: err.message || "Internal server error"
|
|
345
|
+
},
|
|
346
|
+
500
|
|
347
|
+
);
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
async start() {
|
|
351
|
+
return new Promise((resolve2, reject) => {
|
|
352
|
+
try {
|
|
353
|
+
logInterceptor.install();
|
|
354
|
+
this.server = serve(
|
|
355
|
+
{
|
|
356
|
+
fetch: this.app.fetch,
|
|
357
|
+
hostname: this.deps.config.host,
|
|
358
|
+
port: this.deps.config.port
|
|
359
|
+
},
|
|
360
|
+
(info) => {
|
|
361
|
+
const url = `http://${info.address}:${info.port}`;
|
|
362
|
+
log.info(`WebUI server running`);
|
|
363
|
+
log.info(`URL: ${url}/auth/exchange?token=${this.authToken}`);
|
|
364
|
+
log.info(`Token: ${maskToken(this.authToken)} (use Bearer header for API access)`);
|
|
365
|
+
resolve2();
|
|
366
|
+
}
|
|
367
|
+
);
|
|
368
|
+
} catch (error) {
|
|
369
|
+
logInterceptor.uninstall();
|
|
370
|
+
reject(error);
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
async stop() {
|
|
375
|
+
if (this.server) {
|
|
376
|
+
return new Promise((resolve2) => {
|
|
377
|
+
this.server.closeAllConnections();
|
|
378
|
+
this.server?.close(() => {
|
|
379
|
+
logInterceptor.uninstall();
|
|
380
|
+
log.info("WebUI server stopped");
|
|
381
|
+
resolve2();
|
|
382
|
+
});
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
getToken() {
|
|
387
|
+
return this.authToken;
|
|
388
|
+
}
|
|
389
|
+
};
|
|
390
|
+
export {
|
|
391
|
+
WebUIServer
|
|
392
|
+
};
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createSetupRoutes
|
|
3
|
+
} from "./chunk-57URFK6M.js";
|
|
4
|
+
import "./chunk-WFTC3JJW.js";
|
|
5
|
+
import "./chunk-7YKSXOQQ.js";
|
|
6
|
+
import "./chunk-YOSUPUAJ.js";
|
|
7
|
+
import "./chunk-VFA7QMCZ.js";
|
|
8
|
+
import "./chunk-C4NKJT2Z.js";
|
|
9
|
+
import "./chunk-XQUHC3JZ.js";
|
|
10
|
+
import "./chunk-R4YSJ4EY.js";
|
|
11
|
+
import {
|
|
12
|
+
TELETON_ROOT
|
|
13
|
+
} from "./chunk-EYWNOHMJ.js";
|
|
14
|
+
import {
|
|
15
|
+
createLogger
|
|
16
|
+
} from "./chunk-NQ6FZKCE.js";
|
|
17
|
+
import "./chunk-3RG5ZIWI.js";
|
|
18
|
+
|
|
19
|
+
// src/webui/setup-server.ts
|
|
20
|
+
import { Hono } from "hono";
|
|
21
|
+
import { serve } from "@hono/node-server";
|
|
22
|
+
import { cors } from "hono/cors";
|
|
23
|
+
import { bodyLimit } from "hono/body-limit";
|
|
24
|
+
import { existsSync, readFileSync } from "fs";
|
|
25
|
+
import { join, dirname, resolve, relative } from "path";
|
|
26
|
+
import { fileURLToPath } from "url";
|
|
27
|
+
import { exec } from "child_process";
|
|
28
|
+
import { platform } from "os";
|
|
29
|
+
import { randomBytes } from "crypto";
|
|
30
|
+
import { readFileSync as readYaml, writeFileSync } from "fs";
|
|
31
|
+
import YAML from "yaml";
|
|
32
|
+
var log = createLogger("Setup");
|
|
33
|
+
function findWebDist() {
|
|
34
|
+
const candidates = [resolve("dist/web"), resolve("web")];
|
|
35
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
36
|
+
candidates.push(resolve(__dirname, "web"), resolve(__dirname, "../dist/web"));
|
|
37
|
+
for (const candidate of candidates) {
|
|
38
|
+
if (existsSync(join(candidate, "index.html"))) {
|
|
39
|
+
return candidate;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
function autoOpenBrowser(url) {
|
|
45
|
+
const os = platform();
|
|
46
|
+
let cmd;
|
|
47
|
+
if (os === "darwin") {
|
|
48
|
+
cmd = `open "${url}"`;
|
|
49
|
+
} else if (os === "win32") {
|
|
50
|
+
cmd = `start "${url}"`;
|
|
51
|
+
} else {
|
|
52
|
+
cmd = `xdg-open "${url}"`;
|
|
53
|
+
}
|
|
54
|
+
exec(cmd, (err) => {
|
|
55
|
+
if (err) {
|
|
56
|
+
log.info(`Open this URL in your browser: ${url}`);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
var SetupServer = class {
|
|
61
|
+
constructor(port = 7777) {
|
|
62
|
+
this.port = port;
|
|
63
|
+
this.app = new Hono();
|
|
64
|
+
this.launchPromise = new Promise((resolve2) => {
|
|
65
|
+
this.launchResolve = resolve2;
|
|
66
|
+
});
|
|
67
|
+
this.setupMiddleware();
|
|
68
|
+
this.setupRoutes();
|
|
69
|
+
this.setupStaticServing();
|
|
70
|
+
}
|
|
71
|
+
app;
|
|
72
|
+
server = null;
|
|
73
|
+
launchResolve = null;
|
|
74
|
+
launchPromise;
|
|
75
|
+
/** Returns a promise that resolves with the auth token when the user clicks "Start Agent" */
|
|
76
|
+
waitForLaunch() {
|
|
77
|
+
return this.launchPromise;
|
|
78
|
+
}
|
|
79
|
+
setupMiddleware() {
|
|
80
|
+
this.app.use(
|
|
81
|
+
"*",
|
|
82
|
+
cors({
|
|
83
|
+
origin: [
|
|
84
|
+
"http://localhost:5173",
|
|
85
|
+
`http://localhost:${this.port}`,
|
|
86
|
+
"http://127.0.0.1:5173",
|
|
87
|
+
`http://127.0.0.1:${this.port}`
|
|
88
|
+
],
|
|
89
|
+
credentials: true,
|
|
90
|
+
allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH"],
|
|
91
|
+
allowHeaders: ["Content-Type"],
|
|
92
|
+
maxAge: 3600
|
|
93
|
+
})
|
|
94
|
+
);
|
|
95
|
+
this.app.use(
|
|
96
|
+
"*",
|
|
97
|
+
bodyLimit({
|
|
98
|
+
maxSize: 2 * 1024 * 1024,
|
|
99
|
+
onError: (c) => c.json({ success: false, error: "Request body too large (max 2MB)" }, 413)
|
|
100
|
+
})
|
|
101
|
+
);
|
|
102
|
+
this.app.use("*", async (c, next) => {
|
|
103
|
+
await next();
|
|
104
|
+
c.res.headers.set("X-Content-Type-Options", "nosniff");
|
|
105
|
+
c.res.headers.set("X-Frame-Options", "DENY");
|
|
106
|
+
c.res.headers.set("Referrer-Policy", "strict-origin-when-cross-origin");
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
setupRoutes() {
|
|
110
|
+
this.app.get("/health", (c) => c.json({ status: "ok" }));
|
|
111
|
+
this.app.route("/api/setup", createSetupRoutes());
|
|
112
|
+
this.app.get(
|
|
113
|
+
"/auth/check",
|
|
114
|
+
(c) => c.json({ success: true, data: { authenticated: false, setup: true } })
|
|
115
|
+
);
|
|
116
|
+
this.app.post("/api/setup/launch", async (c) => {
|
|
117
|
+
try {
|
|
118
|
+
const token = randomBytes(32).toString("hex");
|
|
119
|
+
const configPath = join(TELETON_ROOT, "config.yaml");
|
|
120
|
+
const raw = readYaml(configPath, "utf-8");
|
|
121
|
+
const config = YAML.parse(raw);
|
|
122
|
+
config.webui = { ...config.webui || {}, enabled: true, auth_token: token };
|
|
123
|
+
writeFileSync(configPath, YAML.stringify(config), { encoding: "utf-8", mode: 384 });
|
|
124
|
+
log.info("Launch requested \u2014 auth token generated");
|
|
125
|
+
const resolve2 = this.launchResolve;
|
|
126
|
+
this.launchResolve = null;
|
|
127
|
+
if (resolve2) {
|
|
128
|
+
setTimeout(() => resolve2(token), 500);
|
|
129
|
+
}
|
|
130
|
+
return c.json({ success: true, data: { token } });
|
|
131
|
+
} catch (err) {
|
|
132
|
+
return c.json(
|
|
133
|
+
{ success: false, error: err instanceof Error ? err.message : String(err) },
|
|
134
|
+
500
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
this.app.onError((err, c) => {
|
|
139
|
+
log.error({ err }, "Setup server error");
|
|
140
|
+
return c.json({ success: false, error: err.message || "Internal server error" }, 500);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
setupStaticServing() {
|
|
144
|
+
const webDist = findWebDist();
|
|
145
|
+
if (!webDist) return;
|
|
146
|
+
const indexHtml = readFileSync(join(webDist, "index.html"), "utf-8");
|
|
147
|
+
const mimeTypes = {
|
|
148
|
+
js: "application/javascript",
|
|
149
|
+
css: "text/css",
|
|
150
|
+
svg: "image/svg+xml",
|
|
151
|
+
png: "image/png",
|
|
152
|
+
jpg: "image/jpeg",
|
|
153
|
+
jpeg: "image/jpeg",
|
|
154
|
+
ico: "image/x-icon",
|
|
155
|
+
json: "application/json",
|
|
156
|
+
woff2: "font/woff2",
|
|
157
|
+
woff: "font/woff"
|
|
158
|
+
};
|
|
159
|
+
this.app.get("*", (c) => {
|
|
160
|
+
const filePath = resolve(join(webDist, c.req.path));
|
|
161
|
+
const rel = relative(webDist, filePath);
|
|
162
|
+
if (rel.startsWith("..") || resolve(filePath) !== filePath) {
|
|
163
|
+
return c.html(indexHtml);
|
|
164
|
+
}
|
|
165
|
+
try {
|
|
166
|
+
const content = readFileSync(filePath);
|
|
167
|
+
const ext = filePath.split(".").pop() || "";
|
|
168
|
+
if (mimeTypes[ext]) {
|
|
169
|
+
const immutable = c.req.path.startsWith("/assets/");
|
|
170
|
+
return c.body(content, 200, {
|
|
171
|
+
"Content-Type": mimeTypes[ext],
|
|
172
|
+
"Cache-Control": immutable ? "public, max-age=31536000, immutable" : "public, max-age=3600"
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
} catch {
|
|
176
|
+
}
|
|
177
|
+
return c.html(indexHtml);
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
async start() {
|
|
181
|
+
return new Promise((resolve2, reject) => {
|
|
182
|
+
try {
|
|
183
|
+
this.server = serve(
|
|
184
|
+
{
|
|
185
|
+
fetch: this.app.fetch,
|
|
186
|
+
hostname: "127.0.0.1",
|
|
187
|
+
port: this.port
|
|
188
|
+
},
|
|
189
|
+
() => {
|
|
190
|
+
const url = `http://localhost:${this.port}/setup`;
|
|
191
|
+
log.info(`Setup wizard: ${url}`);
|
|
192
|
+
autoOpenBrowser(url);
|
|
193
|
+
resolve2();
|
|
194
|
+
}
|
|
195
|
+
);
|
|
196
|
+
} catch (error) {
|
|
197
|
+
reject(error);
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
async stop() {
|
|
202
|
+
if (this.server) {
|
|
203
|
+
return new Promise((resolve2) => {
|
|
204
|
+
this.server.closeAllConnections();
|
|
205
|
+
this.server?.close(() => {
|
|
206
|
+
log.info("Setup server stopped");
|
|
207
|
+
resolve2();
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
export {
|
|
214
|
+
SetupServer
|
|
215
|
+
};
|
|
@@ -9,16 +9,16 @@ import {
|
|
|
9
9
|
saveSessionStore,
|
|
10
10
|
shouldResetSession,
|
|
11
11
|
updateSession
|
|
12
|
-
} from "./chunk-
|
|
13
|
-
import "./chunk-
|
|
14
|
-
import "./chunk-
|
|
12
|
+
} from "./chunk-55SKE6YH.js";
|
|
13
|
+
import "./chunk-VYKW7FMV.js";
|
|
14
|
+
import "./chunk-HEDJCLA6.js";
|
|
15
15
|
import "./chunk-VFA7QMCZ.js";
|
|
16
|
-
import "./chunk-
|
|
16
|
+
import "./chunk-C4NKJT2Z.js";
|
|
17
17
|
import "./chunk-XQUHC3JZ.js";
|
|
18
18
|
import "./chunk-R4YSJ4EY.js";
|
|
19
19
|
import "./chunk-EYWNOHMJ.js";
|
|
20
|
-
import "./chunk-
|
|
21
|
-
import "./chunk-
|
|
20
|
+
import "./chunk-NQ6FZKCE.js";
|
|
21
|
+
import "./chunk-4L66JHQE.js";
|
|
22
22
|
import "./chunk-3RG5ZIWI.js";
|
|
23
23
|
export {
|
|
24
24
|
getOrCreateSession,
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
MAX_DEPENDENTS_PER_TASK
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-C4NKJT2Z.js";
|
|
4
4
|
import {
|
|
5
5
|
BATCH_TRIGGER_DELAY_MS
|
|
6
6
|
} from "./chunk-R4YSJ4EY.js";
|
|
7
7
|
import {
|
|
8
8
|
createLogger
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-NQ6FZKCE.js";
|
|
10
10
|
import "./chunk-3RG5ZIWI.js";
|
|
11
11
|
|
|
12
12
|
// src/telegram/task-dependency-resolver.ts
|
|
@@ -104,7 +104,7 @@ var TaskDependencyResolver = class {
|
|
|
104
104
|
try {
|
|
105
105
|
const payload = JSON.parse(task.payload);
|
|
106
106
|
skipOnFailure = payload.skipOnParentFailure !== false;
|
|
107
|
-
} catch
|
|
107
|
+
} catch {
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
if (skipOnFailure) {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getErrorMessage
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-3UFPFWYP.js";
|
|
4
4
|
import {
|
|
5
5
|
MAX_JSON_FIELD_CHARS,
|
|
6
6
|
MAX_TOTAL_PROMPT_CHARS,
|
|
7
7
|
SECONDS_PER_DAY,
|
|
8
8
|
SECONDS_PER_HOUR
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-C4NKJT2Z.js";
|
|
10
10
|
import "./chunk-3RG5ZIWI.js";
|
|
11
11
|
|
|
12
12
|
// src/telegram/task-executor.ts
|
|
@@ -17,7 +17,7 @@ function truncateJson(data, maxChars = MAX_JSON_FIELD_CHARS) {
|
|
|
17
17
|
return str;
|
|
18
18
|
}
|
|
19
19
|
return str.slice(0, maxChars - 50) + "\n... [TRUNCATED - " + (str.length - maxChars + 50) + " chars omitted]";
|
|
20
|
-
} catch
|
|
20
|
+
} catch {
|
|
21
21
|
return "[Error serializing data]";
|
|
22
22
|
}
|
|
23
23
|
}
|