teleton 0.8.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/README.md +28 -11
  2. package/dist/{chunk-U56QTM46.js → chunk-3S4GGLLR.js} +28 -26
  3. package/dist/{chunk-NUGDTPE4.js → chunk-4L66JHQE.js} +2 -1
  4. package/dist/{chunk-H36RFKRI.js → chunk-5FNWBZ5K.js} +476 -143
  5. package/dist/{chunk-SD4NLLYG.js → chunk-7U7BOHCL.js} +80 -33
  6. package/dist/{chunk-QVBSUYVX.js → chunk-AYWEJCDB.js} +11 -3
  7. package/dist/{chunk-RQBAMUCV.js → chunk-CGOXE4WP.js} +1235 -201
  8. package/dist/{chunk-TVRZJIZX.js → chunk-KVXV7EF7.js} +3 -3
  9. package/dist/{chunk-WIKM24GZ.js → chunk-QBHRXLZS.js} +5 -0
  10. package/dist/{chunk-P36I6OIV.js → chunk-QV2GLOTK.js} +12 -1
  11. package/dist/{chunk-JHYZYFZJ.js → chunk-S6PHGKOC.js} +8 -1
  12. package/dist/{chunk-IJBWWQE4.js → chunk-UP55PXFH.js} +4 -0
  13. package/dist/cli/index.js +17 -16
  14. package/dist/{client-LNZTDQSA.js → client-MPHPIZB6.js} +2 -2
  15. package/dist/{get-my-gifts-OMGKOEPM.js → get-my-gifts-CC6HAVWB.js} +1 -1
  16. package/dist/index.js +11 -11
  17. package/dist/{memory-AS7WKGTW.js → memory-UBHM7ILG.js} +4 -4
  18. package/dist/{migrate-POHWYEIW.js → migrate-UBBEJ5BL.js} +4 -4
  19. package/dist/{server-H3QA252W.js → server-3FHI2SEB.js} +392 -51
  20. package/dist/{setup-server-QXED3D2L.js → setup-server-32XGDPE6.js} +157 -7
  21. package/dist/{store-GAFULOOX.js → store-M5IMUQCL.js} +5 -5
  22. package/dist/{task-dependency-resolver-3FIKQ7Z6.js → task-dependency-resolver-RR2O5S7B.js} +2 -2
  23. package/dist/{task-executor-RUTFG6VG.js → task-executor-6W5HRX5C.js} +2 -2
  24. package/dist/{tasks-BEZ4QRI2.js → tasks-WQIKXDX5.js} +1 -1
  25. package/dist/{tool-index-H3SHOJC3.js → tool-index-PMAOXWUA.js} +8 -5
  26. package/dist/{transcript-IMNE6KU3.js → transcript-NGDPSNIH.js} +1 -1
  27. package/dist/web/assets/index-BfYCdwLI.js +80 -0
  28. package/dist/web/assets/{index-BrVqauzj.css → index-DmlyQVhR.css} +1 -1
  29. package/dist/web/assets/{index.es-DkU1GvWU.js → index.es-DitvF-9H.js} +1 -1
  30. package/dist/web/index.html +2 -2
  31. package/package.json +11 -4
  32. package/dist/web/assets/index-DYeEkvJ6.js +0 -72
@@ -11,7 +11,7 @@ import {
11
11
  isNewWorkspace,
12
12
  saveWallet,
13
13
  walletExists
14
- } from "./chunk-JHYZYFZJ.js";
14
+ } from "./chunk-S6PHGKOC.js";
15
15
  import {
16
16
  getClaudeCodeApiKey,
17
17
  getProviderMetadata,
@@ -22,7 +22,7 @@ import {
22
22
  import "./chunk-VFA7QMCZ.js";
23
23
  import {
24
24
  TELEGRAM_MAX_MESSAGE_LENGTH
25
- } from "./chunk-IJBWWQE4.js";
25
+ } from "./chunk-UP55PXFH.js";
26
26
  import {
27
27
  fetchWithTimeout
28
28
  } from "./chunk-XQUHC3JZ.js";
@@ -110,6 +110,7 @@ var TelegramAuthManager = class {
110
110
  const id = randomBytes(16).toString("hex");
111
111
  const expiresAt = Date.now() + SESSION_TTL_MS;
112
112
  this.session = {
113
+ type: "phone",
113
114
  id,
114
115
  client,
115
116
  phone,
@@ -122,7 +123,7 @@ var TelegramAuthManager = class {
122
123
  createdAt: Date.now(),
123
124
  apiId,
124
125
  apiHash,
125
- timer: setTimeout(() => this.cleanup(), SESSION_TTL_MS)
126
+ timer: setTimeout(() => void this.cleanup(), SESSION_TTL_MS)
126
127
  };
127
128
  log.info("Telegram verification code sent");
128
129
  return { authSessionId: id, codeDelivery, fragmentUrl, codeLength, expiresAt };
@@ -132,7 +133,7 @@ var TelegramAuthManager = class {
132
133
  */
133
134
  async verifyCode(authSessionId, code) {
134
135
  const session = this.getSession(authSessionId);
135
- if (!session) return { status: "expired" };
136
+ if (!session || session.type !== "phone") return { status: "expired" };
136
137
  if (session.codeAttempts >= MAX_CODE_ATTEMPTS) {
137
138
  return { status: "too_many_attempts" };
138
139
  }
@@ -206,7 +207,7 @@ var TelegramAuthManager = class {
206
207
  */
207
208
  async resendCode(authSessionId) {
208
209
  const session = this.getSession(authSessionId);
209
- if (!session || session.state !== "code_sent") return null;
210
+ if (!session || session.type !== "phone" || session.state !== "code_sent") return null;
210
211
  const result = await session.client.invoke(
211
212
  new Api.auth.ResendCode({
212
213
  phoneNumber: session.phone,
@@ -235,6 +236,111 @@ var TelegramAuthManager = class {
235
236
  }
236
237
  return { codeDelivery: "sms" };
237
238
  }
239
+ /**
240
+ * Start QR code authentication session
241
+ */
242
+ async startQrSession(apiId, apiHash) {
243
+ await this.cleanup();
244
+ const gramLogger = new Logger(LogLevel.NONE);
245
+ const client = new TelegramClient(new StringSession(""), apiId, apiHash, {
246
+ connectionRetries: 3,
247
+ floodSleepThreshold: 0,
248
+ baseLogger: gramLogger
249
+ });
250
+ await client.connect();
251
+ const result = await client.invoke(
252
+ new Api.auth.ExportLoginToken({
253
+ apiId,
254
+ apiHash,
255
+ exceptIds: []
256
+ })
257
+ );
258
+ if (!(result instanceof Api.auth.LoginToken)) {
259
+ await client.disconnect();
260
+ throw new Error("Unexpected QR auth response");
261
+ }
262
+ const id = randomBytes(16).toString("hex");
263
+ const expiresAt = Date.now() + SESSION_TTL_MS;
264
+ this.session = {
265
+ type: "qr",
266
+ id,
267
+ client,
268
+ state: "qr_waiting",
269
+ passwordAttempts: 0,
270
+ createdAt: Date.now(),
271
+ apiId,
272
+ apiHash,
273
+ timer: setTimeout(() => void this.cleanup(), SESSION_TTL_MS)
274
+ };
275
+ log.info("QR code authentication session started");
276
+ return {
277
+ authSessionId: id,
278
+ token: result.token.toString("base64url"),
279
+ expires: result.expires,
280
+ expiresAt
281
+ };
282
+ }
283
+ /**
284
+ * Refresh QR token / check if scanned
285
+ */
286
+ async refreshQrToken(authSessionId) {
287
+ const session = this.getSession(authSessionId);
288
+ if (!session || session.type !== "qr") return { status: "expired" };
289
+ if (session.state === "2fa_required") {
290
+ return { status: "2fa_required", passwordHint: session.passwordHint };
291
+ }
292
+ try {
293
+ const result = await session.client.invoke(
294
+ new Api.auth.ExportLoginToken({
295
+ apiId: session.apiId,
296
+ apiHash: session.apiHash,
297
+ exceptIds: []
298
+ })
299
+ );
300
+ if (result instanceof Api.auth.LoginTokenSuccess) {
301
+ session.state = "authenticated";
302
+ const user = this.extractUser(result.authorization);
303
+ await this.saveSession(session);
304
+ log.info("QR code authentication successful");
305
+ return { status: "authenticated", user };
306
+ }
307
+ if (result instanceof Api.auth.LoginTokenMigrateTo) {
308
+ await session.client._switchDC(
309
+ result.dcId
310
+ );
311
+ const imported = await session.client.invoke(
312
+ new Api.auth.ImportLoginToken({ token: result.token })
313
+ );
314
+ if (imported instanceof Api.auth.LoginTokenSuccess) {
315
+ session.state = "authenticated";
316
+ const user = this.extractUser(imported.authorization);
317
+ await this.saveSession(session);
318
+ log.info("QR code authentication successful (after DC migration)");
319
+ return { status: "authenticated", user };
320
+ }
321
+ }
322
+ if (result instanceof Api.auth.LoginToken) {
323
+ return {
324
+ status: "waiting",
325
+ token: result.token.toString("base64url"),
326
+ expires: result.expires
327
+ };
328
+ }
329
+ return { status: "waiting" };
330
+ } catch (err) {
331
+ const error = err;
332
+ if (error.errorMessage === "SESSION_PASSWORD_NEEDED") {
333
+ session.state = "2fa_required";
334
+ try {
335
+ const passwordResult = await session.client.invoke(new Api.account.GetPassword());
336
+ session.passwordHint = passwordResult.hint ?? void 0;
337
+ } catch {
338
+ }
339
+ return { status: "2fa_required", passwordHint: session.passwordHint };
340
+ }
341
+ throw err;
342
+ }
343
+ }
238
344
  /**
239
345
  * Cancel and clean up session
240
346
  */
@@ -261,7 +367,7 @@ var TelegramAuthManager = class {
261
367
  getSession(id) {
262
368
  if (!this.session || this.session.id !== id) return null;
263
369
  if (Date.now() - this.session.createdAt > SESSION_TTL_MS) {
264
- this.cleanup();
370
+ void this.cleanup();
265
371
  return null;
266
372
  }
267
373
  return this.session;
@@ -596,6 +702,50 @@ function createSetupRoutes() {
596
702
  );
597
703
  }
598
704
  });
705
+ app.post("/telegram/qr-start", async (c) => {
706
+ try {
707
+ const body = await c.req.json();
708
+ if (!body.apiId || !body.apiHash) {
709
+ return c.json({ success: false, error: "Missing apiId or apiHash" }, 400);
710
+ }
711
+ const result = await authManager.startQrSession(body.apiId, body.apiHash);
712
+ return c.json({ success: true, data: result });
713
+ } catch (err) {
714
+ const error = err;
715
+ if (error.seconds) {
716
+ return c.json(
717
+ { success: false, error: `Rate limited. Please wait ${error.seconds} seconds.` },
718
+ 429
719
+ );
720
+ }
721
+ return c.json(
722
+ { success: false, error: error.errorMessage || error.message || String(err) },
723
+ 500
724
+ );
725
+ }
726
+ });
727
+ app.post("/telegram/qr-refresh", async (c) => {
728
+ try {
729
+ const body = await c.req.json();
730
+ if (!body.authSessionId) {
731
+ return c.json({ success: false, error: "Missing authSessionId" }, 400);
732
+ }
733
+ const result = await authManager.refreshQrToken(body.authSessionId);
734
+ return c.json({ success: true, data: result });
735
+ } catch (err) {
736
+ const error = err;
737
+ if (error.seconds) {
738
+ return c.json(
739
+ { success: false, error: `Rate limited. Please wait ${error.seconds} seconds.` },
740
+ 429
741
+ );
742
+ }
743
+ return c.json(
744
+ { success: false, error: error.errorMessage || error.message || String(err) },
745
+ 500
746
+ );
747
+ }
748
+ });
599
749
  app.delete("/telegram/session", async (c) => {
600
750
  try {
601
751
  const body = await c.req.json().catch(() => ({ authSessionId: "" }));
@@ -898,7 +1048,7 @@ var SetupServer = class {
898
1048
  if (this.server) {
899
1049
  return new Promise((resolve2) => {
900
1050
  this.server.closeAllConnections();
901
- this.server.close(() => {
1051
+ this.server?.close(() => {
902
1052
  log3.info("Setup server stopped");
903
1053
  resolve2();
904
1054
  });
@@ -9,16 +9,16 @@ import {
9
9
  saveSessionStore,
10
10
  shouldResetSession,
11
11
  updateSession
12
- } from "./chunk-TVRZJIZX.js";
13
- import "./chunk-SD4NLLYG.js";
14
- import "./chunk-U56QTM46.js";
12
+ } from "./chunk-KVXV7EF7.js";
13
+ import "./chunk-7U7BOHCL.js";
14
+ import "./chunk-3S4GGLLR.js";
15
15
  import "./chunk-VFA7QMCZ.js";
16
- import "./chunk-IJBWWQE4.js";
16
+ import "./chunk-UP55PXFH.js";
17
17
  import "./chunk-XQUHC3JZ.js";
18
18
  import "./chunk-R4YSJ4EY.js";
19
19
  import "./chunk-EYWNOHMJ.js";
20
20
  import "./chunk-RCMD3U65.js";
21
- import "./chunk-NUGDTPE4.js";
21
+ import "./chunk-4L66JHQE.js";
22
22
  import "./chunk-3RG5ZIWI.js";
23
23
  export {
24
24
  getOrCreateSession,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  MAX_DEPENDENTS_PER_TASK
3
- } from "./chunk-IJBWWQE4.js";
3
+ } from "./chunk-UP55PXFH.js";
4
4
  import {
5
5
  BATCH_TRIGGER_DELAY_MS
6
6
  } from "./chunk-R4YSJ4EY.js";
@@ -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 (e) {
107
+ } catch {
108
108
  }
109
109
  }
110
110
  if (skipOnFailure) {
@@ -6,7 +6,7 @@ import {
6
6
  MAX_TOTAL_PROMPT_CHARS,
7
7
  SECONDS_PER_DAY,
8
8
  SECONDS_PER_HOUR
9
- } from "./chunk-IJBWWQE4.js";
9
+ } from "./chunk-UP55PXFH.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 (e) {
20
+ } catch {
21
21
  return "[Error serializing data]";
22
22
  }
23
23
  }
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  TaskStore,
3
3
  getTaskStore
4
- } from "./chunk-NUGDTPE4.js";
4
+ } from "./chunk-4L66JHQE.js";
5
5
  import "./chunk-3RG5ZIWI.js";
6
6
  export {
7
7
  TaskStore,
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  serializeEmbedding
3
- } from "./chunk-U56QTM46.js";
3
+ } from "./chunk-3S4GGLLR.js";
4
4
  import "./chunk-VFA7QMCZ.js";
5
5
  import {
6
6
  TOOL_RAG_KEYWORD_WEIGHT,
7
7
  TOOL_RAG_MIN_SCORE,
8
8
  TOOL_RAG_VECTOR_WEIGHT
9
- } from "./chunk-IJBWWQE4.js";
9
+ } from "./chunk-UP55PXFH.js";
10
10
  import "./chunk-XQUHC3JZ.js";
11
11
  import "./chunk-R4YSJ4EY.js";
12
12
  import "./chunk-EYWNOHMJ.js";
@@ -139,7 +139,7 @@ var ToolIndex = class {
139
139
  const e = entries[i];
140
140
  insertTool.run(e.name, e.description, e.searchText);
141
141
  if (insertVec && embeddings[i]?.length > 0) {
142
- deleteVec.run(e.name);
142
+ deleteVec?.run(e.name);
143
143
  insertVec.run(e.name, serializeEmbedding(embeddings[i]));
144
144
  }
145
145
  }
@@ -227,6 +227,9 @@ var ToolIndex = class {
227
227
  }
228
228
  mergeResults(vectorResults, keywordResults, limit) {
229
229
  const byName = /* @__PURE__ */ new Map();
230
+ const hasVectorResults = vectorResults.length > 0;
231
+ const effectiveKeywordWeight = hasVectorResults ? TOOL_RAG_KEYWORD_WEIGHT : 1;
232
+ const effectiveVectorWeight = hasVectorResults ? TOOL_RAG_VECTOR_WEIGHT : 0;
230
233
  for (const r of vectorResults) {
231
234
  byName.set(r.name, { ...r, vectorScore: r.score });
232
235
  }
@@ -234,11 +237,11 @@ var ToolIndex = class {
234
237
  const existing = byName.get(r.name);
235
238
  if (existing) {
236
239
  existing.keywordScore = r.keywordScore;
237
- existing.score = TOOL_RAG_VECTOR_WEIGHT * (existing.vectorScore ?? 0) + TOOL_RAG_KEYWORD_WEIGHT * (r.keywordScore ?? 0);
240
+ existing.score = effectiveVectorWeight * (existing.vectorScore ?? 0) + effectiveKeywordWeight * (r.keywordScore ?? 0);
238
241
  } else {
239
242
  byName.set(r.name, {
240
243
  ...r,
241
- score: TOOL_RAG_KEYWORD_WEIGHT * (r.keywordScore ?? 0)
244
+ score: effectiveKeywordWeight * (r.keywordScore ?? 0)
242
245
  });
243
246
  }
244
247
  }
@@ -7,7 +7,7 @@ import {
7
7
  getTranscriptSize,
8
8
  readTranscript,
9
9
  transcriptExists
10
- } from "./chunk-P36I6OIV.js";
10
+ } from "./chunk-QV2GLOTK.js";
11
11
  import "./chunk-EYWNOHMJ.js";
12
12
  import "./chunk-RCMD3U65.js";
13
13
  import "./chunk-3RG5ZIWI.js";