teleton 0.7.2 → 0.7.3

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.
@@ -1,6 +1,3 @@
1
- import {
2
- getCachedHttpEndpoint
3
- } from "./chunk-QUAPFI2N.js";
4
1
  import {
5
2
  COINGECKO_API_URL,
6
3
  tonapiFetch
@@ -25,10 +22,55 @@ import { mnemonicNew, mnemonicToPrivateKey, mnemonicValidate } from "@ton/crypto
25
22
  import { WalletContractV5R1, TonClient, fromNano } from "@ton/ton";
26
23
  import { readFileSync, writeFileSync, existsSync, mkdirSync } from "fs";
27
24
  import { join, dirname } from "path";
25
+
26
+ // src/ton/endpoint.ts
27
+ var ENDPOINT_CACHE_TTL_MS = 6e4;
28
+ var ORBS_HOST = "ton.access.orbs.network";
29
+ var ORBS_TOPOLOGY_URL = `https://${ORBS_HOST}/mngr/nodes?npm_version=2.3.3`;
30
+ var TONCENTER_FALLBACK = `https://toncenter.com/api/v2/jsonRPC`;
31
+ var _cache = null;
32
+ async function discoverOrbsEndpoint() {
33
+ const res = await fetch(ORBS_TOPOLOGY_URL);
34
+ const nodes = await res.json();
35
+ const healthy = nodes.filter(
36
+ (n) => n.Healthy === "1" && n.Weight > 0 && n.Mngr?.health?.["v2-mainnet"]
37
+ );
38
+ if (healthy.length === 0) throw new Error("no healthy orbs nodes");
39
+ const totalWeight = healthy.reduce((sum, n) => sum + n.Weight, 0);
40
+ let r = Math.floor(Math.random() * totalWeight);
41
+ let chosen = healthy[0];
42
+ for (const node of healthy) {
43
+ r -= node.Weight;
44
+ if (r < 0) {
45
+ chosen = node;
46
+ break;
47
+ }
48
+ }
49
+ return `https://${ORBS_HOST}/${chosen.NodeId}/1/mainnet/toncenter-api-v2/jsonRPC`;
50
+ }
51
+ async function getCachedHttpEndpoint() {
52
+ if (_cache && Date.now() - _cache.ts < ENDPOINT_CACHE_TTL_MS) {
53
+ return _cache.url;
54
+ }
55
+ let url;
56
+ try {
57
+ url = await discoverOrbsEndpoint();
58
+ } catch {
59
+ url = TONCENTER_FALLBACK;
60
+ }
61
+ _cache = { url, ts: Date.now() };
62
+ return url;
63
+ }
64
+ function invalidateEndpointCache() {
65
+ _cache = null;
66
+ }
67
+
68
+ // src/ton/wallet-service.ts
28
69
  var log = createLogger("TON");
29
70
  var WALLET_FILE = join(TELETON_ROOT, "wallet.json");
30
71
  var _walletCache;
31
72
  var _keyPairCache = null;
73
+ var _tonClientCache = null;
32
74
  async function generateWallet() {
33
75
  const mnemonic = await mnemonicNew(24);
34
76
  const keyPair = await mnemonicToPrivateKey(mnemonic);
@@ -100,6 +142,19 @@ function getWalletAddress() {
100
142
  const wallet = loadWallet();
101
143
  return wallet?.address || null;
102
144
  }
145
+ async function getCachedTonClient() {
146
+ const endpoint = await getCachedHttpEndpoint();
147
+ if (_tonClientCache && _tonClientCache.endpoint === endpoint) {
148
+ return _tonClientCache.client;
149
+ }
150
+ const client = new TonClient({ endpoint });
151
+ _tonClientCache = { client, endpoint };
152
+ return client;
153
+ }
154
+ function invalidateTonClientCache() {
155
+ _tonClientCache = null;
156
+ invalidateEndpointCache();
157
+ }
103
158
  async function getKeyPair() {
104
159
  if (_keyPairCache) return _keyPairCache;
105
160
  const wallet = loadWallet();
@@ -109,8 +164,7 @@ async function getKeyPair() {
109
164
  }
110
165
  async function getWalletBalance(address) {
111
166
  try {
112
- const endpoint = await getCachedHttpEndpoint();
113
- const client = new TonClient({ endpoint });
167
+ const client = await getCachedTonClient();
114
168
  const { Address } = await import("@ton/core");
115
169
  const addressObj = Address.parse(address);
116
170
  const balance = await client.getBalance(addressObj);
@@ -174,6 +228,7 @@ var SessionResetPolicySchema = z.object({
174
228
  var AgentConfigSchema = z.object({
175
229
  provider: z.enum([
176
230
  "anthropic",
231
+ "claude-code",
177
232
  "openai",
178
233
  "google",
179
234
  "xai",
@@ -186,7 +241,7 @@ var AgentConfigSchema = z.object({
186
241
  ]).default("anthropic"),
187
242
  api_key: z.string().default(""),
188
243
  base_url: z.string().url().optional().describe("Base URL for local LLM server (e.g. http://localhost:11434/v1)"),
189
- model: z.string().default("claude-opus-4-5-20251101"),
244
+ model: z.string().default("claude-opus-4-6"),
190
245
  utility_model: z.string().optional().describe("Cheap model for summarization (auto-detected if omitted)"),
191
246
  max_tokens: z.number().default(4096),
192
247
  temperature: z.number().default(0.7),
@@ -409,12 +464,15 @@ export {
409
464
  ensureWorkspace,
410
465
  isNewWorkspace,
411
466
  loadTemplate,
467
+ getCachedHttpEndpoint,
412
468
  generateWallet,
413
469
  saveWallet,
414
470
  loadWallet,
415
471
  walletExists,
416
472
  importWallet,
417
473
  getWalletAddress,
474
+ getCachedTonClient,
475
+ invalidateTonClientCache,
418
476
  getKeyPair,
419
477
  getWalletBalance,
420
478
  getTonPrice
@@ -0,0 +1,107 @@
1
+ import {
2
+ createLogger
3
+ } from "./chunk-RCMD3U65.js";
4
+
5
+ // src/providers/claude-code-credentials.ts
6
+ import { readFileSync, existsSync } from "fs";
7
+ import { execSync } from "child_process";
8
+ import { homedir } from "os";
9
+ import { join } from "path";
10
+ var log = createLogger("ClaudeCodeCreds");
11
+ var cachedToken = null;
12
+ var cachedExpiresAt = 0;
13
+ function getClaudeConfigDir() {
14
+ return process.env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude");
15
+ }
16
+ function getCredentialsFilePath() {
17
+ return join(getClaudeConfigDir(), ".credentials.json");
18
+ }
19
+ function readCredentialsFile() {
20
+ const filePath = getCredentialsFilePath();
21
+ if (!existsSync(filePath)) return null;
22
+ try {
23
+ const raw = readFileSync(filePath, "utf-8");
24
+ return JSON.parse(raw);
25
+ } catch (e) {
26
+ log.warn({ err: e, path: filePath }, "Failed to parse Claude Code credentials file");
27
+ return null;
28
+ }
29
+ }
30
+ function readKeychainCredentials() {
31
+ const serviceNames = ["Claude Code-credentials", "Claude Code"];
32
+ for (const service of serviceNames) {
33
+ try {
34
+ const raw = execSync(`security find-generic-password -s "${service}" -w`, {
35
+ encoding: "utf-8",
36
+ stdio: ["pipe", "pipe", "pipe"]
37
+ }).trim();
38
+ return JSON.parse(raw);
39
+ } catch {
40
+ }
41
+ }
42
+ return null;
43
+ }
44
+ function readCredentials() {
45
+ if (process.platform === "darwin") {
46
+ const keychainCreds = readKeychainCredentials();
47
+ if (keychainCreds) return keychainCreds;
48
+ log.debug("Keychain read failed, falling back to credentials file");
49
+ }
50
+ return readCredentialsFile();
51
+ }
52
+ function extractToken(creds) {
53
+ const oauth = creds.claudeAiOauth;
54
+ if (!oauth?.accessToken) {
55
+ log.warn("Claude Code credentials found but missing accessToken");
56
+ return null;
57
+ }
58
+ return {
59
+ token: oauth.accessToken,
60
+ expiresAt: oauth.expiresAt ?? 0
61
+ };
62
+ }
63
+ function getClaudeCodeApiKey(fallbackKey) {
64
+ if (cachedToken && Date.now() < cachedExpiresAt) {
65
+ return cachedToken;
66
+ }
67
+ const creds = readCredentials();
68
+ if (creds) {
69
+ const extracted = extractToken(creds);
70
+ if (extracted) {
71
+ cachedToken = extracted.token;
72
+ cachedExpiresAt = extracted.expiresAt;
73
+ log.debug("Claude Code credentials loaded successfully");
74
+ return cachedToken;
75
+ }
76
+ }
77
+ if (fallbackKey && fallbackKey.length > 0) {
78
+ log.warn("Claude Code credentials not found, using fallback api_key from config");
79
+ return fallbackKey;
80
+ }
81
+ throw new Error("No Claude Code credentials found. Run 'claude login' or set api_key in config.");
82
+ }
83
+ function refreshClaudeCodeApiKey() {
84
+ cachedToken = null;
85
+ cachedExpiresAt = 0;
86
+ const creds = readCredentials();
87
+ if (creds) {
88
+ const extracted = extractToken(creds);
89
+ if (extracted) {
90
+ cachedToken = extracted.token;
91
+ cachedExpiresAt = extracted.expiresAt;
92
+ log.info("Claude Code credentials refreshed from disk");
93
+ return cachedToken;
94
+ }
95
+ }
96
+ log.warn("Failed to refresh Claude Code credentials from disk");
97
+ return null;
98
+ }
99
+ function isClaudeCodeTokenValid() {
100
+ return cachedToken !== null && Date.now() < cachedExpiresAt;
101
+ }
102
+
103
+ export {
104
+ getClaudeCodeApiKey,
105
+ refreshClaudeCodeApiKey,
106
+ isClaudeCodeTokenValid
107
+ };
@@ -7,8 +7,20 @@ var PROVIDER_REGISTRY = {
7
7
  keyPrefix: "sk-ant-",
8
8
  keyHint: "sk-ant-api03-...",
9
9
  consoleUrl: "https://console.anthropic.com/",
10
- defaultModel: "claude-opus-4-5-20251101",
11
- utilityModel: "claude-3-5-haiku-20241022",
10
+ defaultModel: "claude-opus-4-6",
11
+ utilityModel: "claude-haiku-4-5-20251001",
12
+ toolLimit: null,
13
+ piAiProvider: "anthropic"
14
+ },
15
+ "claude-code": {
16
+ id: "claude-code",
17
+ displayName: "Claude Code (Auto)",
18
+ envVar: "ANTHROPIC_API_KEY",
19
+ keyPrefix: "sk-ant-",
20
+ keyHint: "Auto-detected from Claude Code",
21
+ consoleUrl: "https://console.anthropic.com/",
22
+ defaultModel: "claude-opus-4-6",
23
+ utilityModel: "claude-haiku-4-5-20251001",
12
24
  toolLimit: null,
13
25
  piAiProvider: "anthropic"
14
26
  },
@@ -134,7 +146,7 @@ function getSupportedProviders() {
134
146
  function validateApiKeyFormat(provider, key) {
135
147
  const meta = PROVIDER_REGISTRY[provider];
136
148
  if (!meta) return `Unknown provider: ${provider}`;
137
- if (provider === "cocoon" || provider === "local") return void 0;
149
+ if (provider === "cocoon" || provider === "local" || provider === "claude-code") return void 0;
138
150
  if (!key || key.trim().length === 0) return "API key is required";
139
151
  if (meta.keyPrefix && !key.startsWith(meta.keyPrefix)) {
140
152
  return `Invalid format (should start with ${meta.keyPrefix})`;
@@ -20,24 +20,7 @@ function extractEmoji(sticker) {
20
20
  }
21
21
  var telegramGetMyGiftsTool = {
22
22
  name: "telegram_get_my_gifts",
23
- description: `Get Star Gifts you or another user has received.
24
-
25
- USAGE:
26
- - To view YOUR OWN gifts: omit both userId and viewSender
27
- - To view the SENDER's gifts (when user says "show me MY gifts"): set viewSender=true
28
- - To view a specific user's gifts: pass their userId
29
-
30
- PRESENTATION GUIDE:
31
- - For collectibles: Use "title + model" as display name (e.g., "Hypno Lollipop Telegram")
32
- - NFT link: t.me/nft/{slug} (e.g., t.me/nft/HypnoLollipop-63414)
33
- - Respond concisely: "You have a Hypno Lollipop Telegram \u{1F36D}"
34
- - Only give details (rarity, backdrop, pattern) when specifically asked
35
- - attributes.model.name = model, attributes.pattern.name = pattern, attributes.backdrop.name = backdrop
36
- - rarityPermille: divide by 10 to get percentage (7 = 0.7%)
37
-
38
- TRANSFER: Use msgId (for your own gifts) to transfer collectibles via telegram_transfer_collectible.
39
-
40
- NEVER dump all raw data. Keep responses natural and concise.`,
23
+ description: "Get Star Gifts received by you or another user. Set viewSender=true when sender says 'show MY gifts'. For collectibles: display as 'title + model', link as t.me/nft/{slug}. rarityPermille / 10 = %. Use msgId for transfers.",
41
24
  parameters: Type.Object({
42
25
  userId: Type.Optional(
43
26
  Type.String({
package/dist/cli/index.js CHANGED
@@ -1,9 +1,8 @@
1
1
  import {
2
2
  TelegramUserClient,
3
3
  main
4
- } from "../chunk-VSMUAU5X.js";
5
- import "../chunk-UDD7FYOU.js";
6
- import "../chunk-EHEV7FJ7.js";
4
+ } from "../chunk-BU453WX4.js";
5
+ import "../chunk-WIKM24GZ.js";
7
6
  import "../chunk-U7FQYCBQ.js";
8
7
  import {
9
8
  CONFIGURABLE_KEYS,
@@ -14,7 +13,7 @@ import {
14
13
  readRawConfig,
15
14
  setNestedValue,
16
15
  writeRawConfig
17
- } from "../chunk-JHKWHGBM.js";
16
+ } from "../chunk-A4GCOHCE.js";
18
17
  import {
19
18
  ConfigSchema,
20
19
  DealsConfigSchema,
@@ -25,18 +24,21 @@ import {
25
24
  loadWallet,
26
25
  saveWallet,
27
26
  walletExists
28
- } from "../chunk-NERLQY2H.js";
29
- import "../chunk-QUAPFI2N.js";
27
+ } from "../chunk-DAMCNMYL.js";
30
28
  import "../chunk-TSKJCWQQ.js";
31
29
  import {
32
30
  getErrorMessage
33
31
  } from "../chunk-XBE4JB7C.js";
34
- import "../chunk-ND2X5FWB.js";
32
+ import "../chunk-5PLZ3KSO.js";
33
+ import {
34
+ getClaudeCodeApiKey,
35
+ isClaudeCodeTokenValid
36
+ } from "../chunk-JQDLW7IE.js";
35
37
  import {
36
38
  getProviderMetadata,
37
39
  getSupportedProviders,
38
40
  validateApiKeyFormat
39
- } from "../chunk-LRCPA7SC.js";
41
+ } from "../chunk-RMLQS3X6.js";
40
42
  import "../chunk-OCLG5GKI.js";
41
43
  import "../chunk-RBU6JXD3.js";
42
44
  import "../chunk-UCN6TI25.js";
@@ -377,10 +379,15 @@ function sleep(ms) {
377
379
  }
378
380
  var MODEL_OPTIONS = {
379
381
  anthropic: [
382
+ {
383
+ value: "claude-opus-4-6",
384
+ name: "Claude Opus 4.6",
385
+ description: "Most capable, 1M ctx, $5/M"
386
+ },
380
387
  {
381
388
  value: "claude-opus-4-5-20251101",
382
389
  name: "Claude Opus 4.5",
383
- description: "Most capable, $5/M"
390
+ description: "Previous gen, 200K ctx, $5/M"
384
391
  },
385
392
  { value: "claude-sonnet-4-0", name: "Claude Sonnet 4", description: "Balanced, $3/M" },
386
393
  {
@@ -389,9 +396,9 @@ var MODEL_OPTIONS = {
389
396
  description: "Fast & cheap, $1/M"
390
397
  },
391
398
  {
392
- value: "claude-3-5-haiku-20241022",
393
- name: "Claude 3.5 Haiku",
394
- description: "Cheapest, $0.80/M"
399
+ value: "claude-haiku-4-5-20251001",
400
+ name: "Claude Haiku 4.5",
401
+ description: "Fast & cheap, $1/M"
395
402
  }
396
403
  ],
397
404
  openai: [
@@ -477,7 +484,7 @@ var MODEL_OPTIONS = {
477
484
  };
478
485
  async function onboardCommand(options = {}) {
479
486
  if (options.ui) {
480
- const { SetupServer } = await import("../setup-server-C7ZTPHD5.js");
487
+ const { SetupServer } = await import("../setup-server-BVVD2PR6.js");
481
488
  const port = parseInt(options.uiPort || "7777") || 7777;
482
489
  const url = `http://localhost:${port}/setup`;
483
490
  const blue2 = "\x1B[34m";
@@ -686,6 +693,56 @@ Teleton will connect to ${localBaseUrl}`,
686
693
  TON
687
694
  );
688
695
  STEPS[1].value = `${providerMeta.displayName} ${DIM(localBaseUrl)}`;
696
+ } else if (selectedProvider === "claude-code") {
697
+ let detected = false;
698
+ try {
699
+ const key = getClaudeCodeApiKey();
700
+ const valid = isClaudeCodeTokenValid();
701
+ apiKey = "";
702
+ detected = true;
703
+ const masked = key.length > 16 ? key.slice(0, 12) + "..." + key.slice(-4) : "***";
704
+ noteBox(
705
+ `Credentials auto-detected from Claude Code
706
+ Key: ${masked}
707
+ Status: ${valid ? GREEN("valid \u2713") : "expired (will refresh on use)"}
708
+ Token will auto-refresh when it expires.`,
709
+ "Claude Code",
710
+ TON
711
+ );
712
+ await confirm({
713
+ message: "Continue with auto-detected credentials?",
714
+ default: true,
715
+ theme: inquirerTheme
716
+ });
717
+ } catch (err) {
718
+ if (err instanceof CancelledError) throw err;
719
+ prompter.warn(
720
+ "Claude Code credentials not found. Make sure Claude Code is installed and authenticated (claude login)."
721
+ );
722
+ const useFallback = await confirm({
723
+ message: "Enter an API key manually instead?",
724
+ default: true,
725
+ theme: inquirerTheme
726
+ });
727
+ if (useFallback) {
728
+ apiKey = await password({
729
+ message: `Anthropic API Key (fallback)`,
730
+ theme: inquirerTheme,
731
+ validate: (value = "") => {
732
+ if (!value || value.trim().length === 0) return "API key is required";
733
+ return true;
734
+ }
735
+ });
736
+ } else {
737
+ throw new CancelledError();
738
+ }
739
+ }
740
+ if (detected) {
741
+ STEPS[1].value = `${providerMeta.displayName} ${DIM("auto-detected \u2713")}`;
742
+ } else {
743
+ const maskedKey = apiKey.length > 10 ? apiKey.slice(0, 6) + "..." + apiKey.slice(-4) : "***";
744
+ STEPS[1].value = `${providerMeta.displayName} ${DIM(maskedKey)}`;
745
+ }
689
746
  } else {
690
747
  const envApiKey = process.env.TELETON_API_KEY;
691
748
  if (options.apiKey) {
@@ -774,7 +831,8 @@ Get it at: ${providerMeta.consoleUrl}`,
774
831
  redraw(3);
775
832
  selectedModel = providerMeta.defaultModel;
776
833
  if (selectedFlow === "advanced" && selectedProvider !== "cocoon" && selectedProvider !== "local") {
777
- const providerModels = MODEL_OPTIONS[selectedProvider] || [];
834
+ const modelKey = selectedProvider === "claude-code" ? "anthropic" : selectedProvider;
835
+ const providerModels = MODEL_OPTIONS[modelKey] || [];
778
836
  const modelChoices = [
779
837
  ...providerModels,
780
838
  { value: "__custom__", name: "Custom", description: "Enter a model ID manually" }
@@ -1029,6 +1087,11 @@ Get it at: ${providerMeta.consoleUrl}`,
1029
1087
  console.log(RED(" \u2502") + " ".repeat(W) + RED("\u2502"));
1030
1088
  console.log(RED(` \u2514${"\u2500".repeat(W)}\u2518`));
1031
1089
  console.log();
1090
+ await confirm({
1091
+ message: "I have written down my seed phrase",
1092
+ default: true,
1093
+ theme: inquirerTheme
1094
+ });
1032
1095
  }
1033
1096
  STEPS[5].value = `${wallet.address.slice(0, 8)}...${wallet.address.slice(-4)}`;
1034
1097
  redraw(6);
@@ -8,8 +8,9 @@ import {
8
8
  loadContextFromTranscript,
9
9
  registerCocoonModels,
10
10
  registerLocalModels
11
- } from "./chunk-ND2X5FWB.js";
12
- import "./chunk-LRCPA7SC.js";
11
+ } from "./chunk-5PLZ3KSO.js";
12
+ import "./chunk-JQDLW7IE.js";
13
+ import "./chunk-RMLQS3X6.js";
13
14
  import "./chunk-OCLG5GKI.js";
14
15
  import "./chunk-VAUJSSD3.js";
15
16
  import "./chunk-4DU3C27M.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  telegramGetMyGiftsExecutor,
3
3
  telegramGetMyGiftsTool
4
- } from "./chunk-UDD7FYOU.js";
4
+ } from "./chunk-WIKM24GZ.js";
5
5
  import "./chunk-XBE4JB7C.js";
6
6
  import "./chunk-RCMD3U65.js";
7
7
  import "./chunk-QGM4M3NI.js";
package/dist/index.js CHANGED
@@ -1,17 +1,16 @@
1
1
  import {
2
2
  TeletonApp,
3
3
  main
4
- } from "./chunk-VSMUAU5X.js";
5
- import "./chunk-UDD7FYOU.js";
6
- import "./chunk-EHEV7FJ7.js";
4
+ } from "./chunk-BU453WX4.js";
5
+ import "./chunk-WIKM24GZ.js";
7
6
  import "./chunk-U7FQYCBQ.js";
8
- import "./chunk-JHKWHGBM.js";
9
- import "./chunk-NERLQY2H.js";
10
- import "./chunk-QUAPFI2N.js";
7
+ import "./chunk-A4GCOHCE.js";
8
+ import "./chunk-DAMCNMYL.js";
11
9
  import "./chunk-TSKJCWQQ.js";
12
10
  import "./chunk-XBE4JB7C.js";
13
- import "./chunk-ND2X5FWB.js";
14
- import "./chunk-LRCPA7SC.js";
11
+ import "./chunk-5PLZ3KSO.js";
12
+ import "./chunk-JQDLW7IE.js";
13
+ import "./chunk-RMLQS3X6.js";
15
14
  import "./chunk-OCLG5GKI.js";
16
15
  import "./chunk-RBU6JXD3.js";
17
16
  import "./chunk-UCN6TI25.js";
@@ -16,14 +16,13 @@ import {
16
16
  validateWritePath,
17
17
  writePluginSecret,
18
18
  writeRawConfig
19
- } from "./chunk-JHKWHGBM.js";
20
- import "./chunk-NERLQY2H.js";
21
- import "./chunk-QUAPFI2N.js";
19
+ } from "./chunk-A4GCOHCE.js";
20
+ import "./chunk-DAMCNMYL.js";
22
21
  import "./chunk-TSKJCWQQ.js";
23
22
  import {
24
23
  getErrorMessage
25
24
  } from "./chunk-XBE4JB7C.js";
26
- import "./chunk-LRCPA7SC.js";
25
+ import "./chunk-RMLQS3X6.js";
27
26
  import "./chunk-UCN6TI25.js";
28
27
  import "./chunk-XBKSS6DM.js";
29
28
  import "./chunk-RO62LO6Z.js";