teleton 0.1.20 → 0.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/{chunk-Y4G7HSOQ.js → chunk-LFQSHHRU.js} +244 -556
- package/dist/{chunk-JDPS46IZ.js → chunk-Y5X6KZX5.js} +12 -22
- package/dist/cli/index.js +2 -2
- package/dist/index.js +2 -2
- package/dist/{memory-Q755V5UK.js → memory-RBJIBZ5L.js} +1 -1
- package/dist/{migrate-F256Q7LW.js → migrate-4Z74FLKS.js} +1 -1
- package/package.json +1 -1
- package/src/templates/SECURITY.md +2 -0
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
UserStore,
|
|
22
22
|
getDatabase,
|
|
23
23
|
initializeMemory
|
|
24
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-Y5X6KZX5.js";
|
|
25
25
|
import {
|
|
26
26
|
ALLOWED_EXTENSIONS,
|
|
27
27
|
MAX_FILE_SIZES,
|
|
@@ -1404,9 +1404,6 @@ var CasinoConfigSchema = z.object({
|
|
|
1404
1404
|
max_bet_percent: z.number().default(5),
|
|
1405
1405
|
min_bankroll: z.number().default(10),
|
|
1406
1406
|
cooldown_seconds: z.number().default(30),
|
|
1407
|
-
house_edge_percent: z.number().default(5),
|
|
1408
|
-
jackpot_threshold: z.number().default(100),
|
|
1409
|
-
jackpot_cooldown_hours: z.number().default(24),
|
|
1410
1407
|
payment_window_minutes: z.number().default(5),
|
|
1411
1408
|
max_payment_age_minutes: z.number().default(10),
|
|
1412
1409
|
tx_retention_days: z.number().default(30),
|
|
@@ -1879,6 +1876,11 @@ function writeSummaryToDailyLog(summary) {
|
|
|
1879
1876
|
${summary}`);
|
|
1880
1877
|
}
|
|
1881
1878
|
|
|
1879
|
+
// src/utils/sanitize.ts
|
|
1880
|
+
function sanitizeForPrompt(text) {
|
|
1881
|
+
return text.replace(/[\x00-\x08\x0b\x0c\x0e-\x1f]/g, "").replace(/[\r\n]+/g, " ").replace(/#{1,6}\s/g, "").replace(/<\/?[a-zA-Z_][^>]*>/g, "").trim().slice(0, 128);
|
|
1882
|
+
}
|
|
1883
|
+
|
|
1882
1884
|
// src/soul/loader.ts
|
|
1883
1885
|
var SOUL_PATHS = [WORKSPACE_PATHS.SOUL];
|
|
1884
1886
|
var STRATEGY_PATHS = [WORKSPACE_PATHS.STRATEGY];
|
|
@@ -2005,7 +2007,9 @@ You have a personal workspace at \`~/.teleton/workspace/\` where you can store a
|
|
|
2005
2007
|
- Rename downloaded files to meaningful names (e.g., "user_avatar.jpg" instead of "123_456_789.jpg")
|
|
2006
2008
|
`);
|
|
2007
2009
|
if (options.ownerName || options.ownerUsername) {
|
|
2008
|
-
const
|
|
2010
|
+
const safeOwnerName = options.ownerName ? sanitizeForPrompt(options.ownerName) : void 0;
|
|
2011
|
+
const safeOwnerUsername = options.ownerUsername ? sanitizeForPrompt(options.ownerUsername) : void 0;
|
|
2012
|
+
const ownerLabel = safeOwnerName && safeOwnerUsername ? `${safeOwnerName} (@${safeOwnerUsername})` : safeOwnerName || `@${safeOwnerUsername}`;
|
|
2009
2013
|
parts.push(
|
|
2010
2014
|
`
|
|
2011
2015
|
## Owner
|
|
@@ -2014,7 +2018,9 @@ When the owner gives instructions, follow them with higher trust.`
|
|
|
2014
2018
|
);
|
|
2015
2019
|
}
|
|
2016
2020
|
if (options.userName) {
|
|
2017
|
-
const
|
|
2021
|
+
const safeName = sanitizeForPrompt(options.userName);
|
|
2022
|
+
const safeUsername = options.senderUsername ? sanitizeForPrompt(options.senderUsername) : void 0;
|
|
2023
|
+
const userLabel = safeUsername ? `${safeName} (@${safeUsername})` : safeName;
|
|
2018
2024
|
parts.push(`
|
|
2019
2025
|
## Current User
|
|
2020
2026
|
You are chatting with: ${userLabel}`);
|
|
@@ -2156,10 +2162,10 @@ function formatTimestamp(timestamp) {
|
|
|
2156
2162
|
function buildSenderLabel(params) {
|
|
2157
2163
|
const parts = [];
|
|
2158
2164
|
if (params.senderName) {
|
|
2159
|
-
parts.push(params.senderName);
|
|
2165
|
+
parts.push(sanitizeForPrompt(params.senderName));
|
|
2160
2166
|
}
|
|
2161
2167
|
if (params.senderUsername) {
|
|
2162
|
-
parts.push(`@${params.senderUsername}`);
|
|
2168
|
+
parts.push(`@${sanitizeForPrompt(params.senderUsername)}`);
|
|
2163
2169
|
}
|
|
2164
2170
|
if (parts.length > 0) {
|
|
2165
2171
|
return parts.length === 2 ? `${parts[0]} (${parts[1]})` : parts[0];
|
|
@@ -2185,7 +2191,8 @@ function formatMessageEnvelope(params) {
|
|
|
2185
2191
|
const ts = formatTimestamp(params.timestamp);
|
|
2186
2192
|
parts.push(ts);
|
|
2187
2193
|
const header = `[${parts.join(" ")}]`;
|
|
2188
|
-
|
|
2194
|
+
const safeBody = params.body.replace(/<\/?user_message>/gi, "");
|
|
2195
|
+
let body = params.isGroup ? `${senderLabel}: <user_message>${safeBody}</user_message>` : `<user_message>${safeBody}</user_message>`;
|
|
2189
2196
|
if (params.hasMedia && params.mediaType) {
|
|
2190
2197
|
const mediaEmoji = {
|
|
2191
2198
|
photo: "\u{1F4F7}",
|
|
@@ -3320,7 +3327,7 @@ ${statsContext}`;
|
|
|
3320
3327
|
const providerMeta = getProviderMetadata(
|
|
3321
3328
|
this.config.agent.provider || "anthropic"
|
|
3322
3329
|
);
|
|
3323
|
-
const tools = this.toolRegistry?.
|
|
3330
|
+
const tools = this.toolRegistry?.getForContext(isGroup ?? false, providerMeta.toolLimit);
|
|
3324
3331
|
const maxIterations = this.config.agent.max_agentic_iterations || 5;
|
|
3325
3332
|
let iteration = 0;
|
|
3326
3333
|
let overflowResets = 0;
|
|
@@ -3535,23 +3542,23 @@ ${statsContext}`;
|
|
|
3535
3542
|
*/
|
|
3536
3543
|
clearHistory(chatId) {
|
|
3537
3544
|
const db = getDatabase().getDb();
|
|
3538
|
-
db.prepare(`DELETE FROM tg_messages WHERE chat_id = ?`).run(chatId);
|
|
3539
3545
|
db.prepare(
|
|
3540
3546
|
`
|
|
3541
|
-
DELETE FROM
|
|
3542
|
-
WHERE
|
|
3543
|
-
SELECT
|
|
3547
|
+
DELETE FROM tg_messages_fts
|
|
3548
|
+
WHERE rowid IN (
|
|
3549
|
+
SELECT rowid FROM tg_messages WHERE chat_id = ?
|
|
3544
3550
|
)
|
|
3545
3551
|
`
|
|
3546
3552
|
).run(chatId);
|
|
3547
3553
|
db.prepare(
|
|
3548
3554
|
`
|
|
3549
|
-
DELETE FROM
|
|
3550
|
-
WHERE
|
|
3551
|
-
SELECT
|
|
3555
|
+
DELETE FROM tg_messages_vec
|
|
3556
|
+
WHERE id IN (
|
|
3557
|
+
SELECT id FROM tg_messages WHERE chat_id = ?
|
|
3552
3558
|
)
|
|
3553
3559
|
`
|
|
3554
3560
|
).run(chatId);
|
|
3561
|
+
db.prepare(`DELETE FROM tg_messages WHERE chat_id = ?`).run(chatId);
|
|
3555
3562
|
resetSession(chatId);
|
|
3556
3563
|
console.log(`\u{1F5D1}\uFE0F Cleared history for chat ${chatId}`);
|
|
3557
3564
|
}
|
|
@@ -3645,7 +3652,7 @@ function markdownToTelegramHtml(markdown) {
|
|
|
3645
3652
|
html = html.replace(listPattern, (match) => {
|
|
3646
3653
|
const index = blockquotes.length;
|
|
3647
3654
|
const lineCount = match.split("\n").length;
|
|
3648
|
-
const content = match.replace(/\|\|([^|]+)\|\|/g, "<tg-spoiler>$1</tg-spoiler>").replace(/\*\*([^*]+)\*\*/g, "<b>$1</b>").replace(/__([^_]+)__/g, "<b>$1</b>").replace(/~~([^~]+)~~/g, "<s>$1</s>").replace(/(?<!\*)\*([^*]+)\*(?!\*)/g, "<i>$1</i>").replace(/(?<!_)_([^_]+)_(?!_)/g, "<i>$1</i>").replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2">$1</a>');
|
|
3655
|
+
const content = escapeHtml(match).replace(/\|\|([^|]+)\|\|/g, "<tg-spoiler>$1</tg-spoiler>").replace(/\*\*([^*]+)\*\*/g, "<b>$1</b>").replace(/__([^_]+)__/g, "<b>$1</b>").replace(/~~([^~]+)~~/g, "<s>$1</s>").replace(/(?<!\*)\*([^*]+)\*(?!\*)/g, "<i>$1</i>").replace(/(?<!_)_([^_]+)_(?!_)/g, "<i>$1</i>").replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2">$1</a>');
|
|
3649
3656
|
const tag = lineCount >= 15 ? "<blockquote expandable>" : "<blockquote>";
|
|
3650
3657
|
blockquotes.push(`${tag}${content}</blockquote>`);
|
|
3651
3658
|
return `\0BLOCKQUOTE${index}\0`;
|
|
@@ -3653,12 +3660,15 @@ function markdownToTelegramHtml(markdown) {
|
|
|
3653
3660
|
html = html.replace(/^(>.*(?:\n>.*)*)/gm, (match) => {
|
|
3654
3661
|
const index = blockquotes.length;
|
|
3655
3662
|
const lineCount = match.split("\n").length;
|
|
3656
|
-
let content =
|
|
3663
|
+
let content = escapeHtml(
|
|
3664
|
+
match.split("\n").map((line) => line.replace(/^>\s?/, "")).join("\n")
|
|
3665
|
+
);
|
|
3657
3666
|
content = content.replace(/\|\|([^|]+)\|\|/g, "<tg-spoiler>$1</tg-spoiler>").replace(/\*\*([^*]+)\*\*/g, "<b>$1</b>").replace(/__([^_]+)__/g, "<b>$1</b>").replace(/~~([^~]+)~~/g, "<s>$1</s>").replace(/(?<!\*)\*([^*]+)\*(?!\*)/g, "<i>$1</i>").replace(/(?<!_)_([^_]+)_(?!_)/g, "<i>$1</i>").replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2">$1</a>');
|
|
3658
3667
|
const tag = lineCount >= 15 ? "<blockquote expandable>" : "<blockquote>";
|
|
3659
3668
|
blockquotes.push(`${tag}${content}</blockquote>`);
|
|
3660
3669
|
return `\0BLOCKQUOTE${index}\0`;
|
|
3661
3670
|
});
|
|
3671
|
+
html = escapeHtml(html);
|
|
3662
3672
|
html = html.replace(/\|\|([^|]+)\|\|/g, "<tg-spoiler>$1</tg-spoiler>");
|
|
3663
3673
|
html = html.replace(/\*\*([^*]+)\*\*/g, "<b>$1</b>");
|
|
3664
3674
|
html = html.replace(/__([^_]+)__/g, "<b>$1</b>");
|
|
@@ -4336,15 +4346,16 @@ var PendingHistory = class _PendingHistory {
|
|
|
4336
4346
|
const lines = pending.map((msg) => {
|
|
4337
4347
|
let senderLabel;
|
|
4338
4348
|
if (msg.senderName && msg.senderUsername) {
|
|
4339
|
-
senderLabel = `${msg.senderName} (@${msg.senderUsername})`;
|
|
4349
|
+
senderLabel = `${sanitizeForPrompt(msg.senderName)} (@${sanitizeForPrompt(msg.senderUsername)})`;
|
|
4340
4350
|
} else if (msg.senderName) {
|
|
4341
|
-
senderLabel = msg.senderName;
|
|
4351
|
+
senderLabel = sanitizeForPrompt(msg.senderName);
|
|
4342
4352
|
} else if (msg.senderUsername) {
|
|
4343
|
-
senderLabel = `@${msg.senderUsername}`;
|
|
4353
|
+
senderLabel = `@${sanitizeForPrompt(msg.senderUsername)}`;
|
|
4344
4354
|
} else {
|
|
4345
4355
|
senderLabel = `User:${msg.senderId}`;
|
|
4346
4356
|
}
|
|
4347
|
-
|
|
4357
|
+
const safeText = msg.text.replace(/<\/?user_message>/gi, "");
|
|
4358
|
+
return `${senderLabel}: <user_message>${safeText}</user_message>`;
|
|
4348
4359
|
});
|
|
4349
4360
|
this.pendingMessages.delete(chatId);
|
|
4350
4361
|
return `[Chat messages since your last reply]
|
|
@@ -4798,8 +4809,8 @@ async function getWalletBalance(address4) {
|
|
|
4798
4809
|
try {
|
|
4799
4810
|
const endpoint = await getHttpEndpoint({ network: "mainnet" });
|
|
4800
4811
|
const client = new TonClient({ endpoint });
|
|
4801
|
-
const { Address:
|
|
4802
|
-
const addressObj =
|
|
4812
|
+
const { Address: Address19 } = await import("@ton/core");
|
|
4813
|
+
const addressObj = Address19.parse(address4);
|
|
4803
4814
|
const balance = await client.getBalance(addressObj);
|
|
4804
4815
|
const balanceFormatted = fromNano(balance);
|
|
4805
4816
|
return {
|
|
@@ -5668,14 +5679,18 @@ import { join as join14 } from "path";
|
|
|
5668
5679
|
import { validateToolCall } from "@mariozechner/pi-ai";
|
|
5669
5680
|
var ToolRegistry = class {
|
|
5670
5681
|
tools = /* @__PURE__ */ new Map();
|
|
5682
|
+
scopes = /* @__PURE__ */ new Map();
|
|
5671
5683
|
/**
|
|
5672
|
-
* Register a new tool
|
|
5684
|
+
* Register a new tool with optional scope
|
|
5673
5685
|
*/
|
|
5674
|
-
register(tool, executor) {
|
|
5686
|
+
register(tool, executor, scope) {
|
|
5675
5687
|
if (this.tools.has(tool.name)) {
|
|
5676
5688
|
throw new Error(`Tool "${tool.name}" is already registered`);
|
|
5677
5689
|
}
|
|
5678
5690
|
this.tools.set(tool.name, { tool, executor });
|
|
5691
|
+
if (scope && scope !== "always") {
|
|
5692
|
+
this.scopes.set(tool.name, scope);
|
|
5693
|
+
}
|
|
5679
5694
|
}
|
|
5680
5695
|
/**
|
|
5681
5696
|
* Get all registered tools for pi-ai
|
|
@@ -5694,6 +5709,19 @@ var ToolRegistry = class {
|
|
|
5694
5709
|
error: `Unknown tool: ${toolCall.name}`
|
|
5695
5710
|
};
|
|
5696
5711
|
}
|
|
5712
|
+
const scope = this.scopes.get(toolCall.name);
|
|
5713
|
+
if (scope === "dm-only" && context.isGroup) {
|
|
5714
|
+
return {
|
|
5715
|
+
success: false,
|
|
5716
|
+
error: `Tool "${toolCall.name}" is not available in group chats`
|
|
5717
|
+
};
|
|
5718
|
+
}
|
|
5719
|
+
if (scope === "group-only" && !context.isGroup) {
|
|
5720
|
+
return {
|
|
5721
|
+
success: false,
|
|
5722
|
+
error: `Tool "${toolCall.name}" is only available in group chats`
|
|
5723
|
+
};
|
|
5724
|
+
}
|
|
5697
5725
|
try {
|
|
5698
5726
|
const validatedArgs = validateToolCall(this.getAll(), toolCall);
|
|
5699
5727
|
const result = await registered.executor(validatedArgs, context);
|
|
@@ -5719,6 +5747,22 @@ var ToolRegistry = class {
|
|
|
5719
5747
|
);
|
|
5720
5748
|
return all.slice(0, toolLimit);
|
|
5721
5749
|
}
|
|
5750
|
+
/**
|
|
5751
|
+
* Get tools filtered by chat context (DM vs group) and provider limit.
|
|
5752
|
+
* - In groups: excludes "dm-only" tools (financial, private)
|
|
5753
|
+
* - In DMs: excludes "group-only" tools (moderation)
|
|
5754
|
+
*/
|
|
5755
|
+
getForContext(isGroup, toolLimit) {
|
|
5756
|
+
const excluded = isGroup ? "dm-only" : "group-only";
|
|
5757
|
+
const filtered = Array.from(this.tools.values()).filter((rt) => this.scopes.get(rt.tool.name) !== excluded).map((rt) => rt.tool);
|
|
5758
|
+
if (toolLimit !== null && filtered.length > toolLimit) {
|
|
5759
|
+
console.warn(
|
|
5760
|
+
`\u26A0\uFE0F Provider tool limit: ${toolLimit}, after scope filter: ${filtered.length}. Truncating to ${toolLimit} tools.`
|
|
5761
|
+
);
|
|
5762
|
+
return filtered.slice(0, toolLimit);
|
|
5763
|
+
}
|
|
5764
|
+
return filtered;
|
|
5765
|
+
}
|
|
5722
5766
|
/**
|
|
5723
5767
|
* Check if a tool is registered
|
|
5724
5768
|
*/
|
|
@@ -19805,26 +19849,18 @@ var CASINO_CONFIG = {
|
|
|
19805
19849
|
// Cooldown
|
|
19806
19850
|
cooldownSeconds: 30,
|
|
19807
19851
|
// Seconds between spins per user
|
|
19808
|
-
//
|
|
19809
|
-
houseEdgePercent: 5,
|
|
19810
|
-
// % of each bet goes to jackpot
|
|
19811
|
-
// Jackpot
|
|
19812
|
-
jackpotThreshold: 100,
|
|
19813
|
-
// Minimum TON to award jackpot
|
|
19814
|
-
jackpotCooldownHours: 24,
|
|
19815
|
-
// Hours between jackpot awards
|
|
19816
|
-
// Slot multipliers (40% house edge, 60% payout)
|
|
19852
|
+
// Slot multipliers
|
|
19817
19853
|
slot: {
|
|
19818
|
-
|
|
19854
|
+
topWin: { range: [64, 64], multiplier: 5 },
|
|
19819
19855
|
// 777
|
|
19820
19856
|
bigWin: { range: [60, 63], multiplier: 2.5 },
|
|
19821
19857
|
mediumWin: { range: [55, 59], multiplier: 1.8 },
|
|
19822
19858
|
smallWin: { range: [43, 54], multiplier: 1.2 }
|
|
19823
19859
|
// Values 1-42: no win
|
|
19824
19860
|
},
|
|
19825
|
-
// Dice multipliers
|
|
19861
|
+
// Dice multipliers
|
|
19826
19862
|
dice: {
|
|
19827
|
-
|
|
19863
|
+
topWin: { value: 6, multiplier: 2.5 },
|
|
19828
19864
|
bigWin: { value: 5, multiplier: 1.8 },
|
|
19829
19865
|
smallWin: { value: 4, multiplier: 1.3 }
|
|
19830
19866
|
// Values 1-3: no win
|
|
@@ -19852,11 +19888,6 @@ function initCasinoConfig(yaml) {
|
|
|
19852
19888
|
if (yaml.max_bet_percent !== void 0) CASINO_CONFIG.maxBetPercent = yaml.max_bet_percent;
|
|
19853
19889
|
if (yaml.min_bankroll !== void 0) CASINO_CONFIG.minBankroll = yaml.min_bankroll;
|
|
19854
19890
|
if (yaml.cooldown_seconds !== void 0) CASINO_CONFIG.cooldownSeconds = yaml.cooldown_seconds;
|
|
19855
|
-
if (yaml.house_edge_percent !== void 0)
|
|
19856
|
-
CASINO_CONFIG.houseEdgePercent = yaml.house_edge_percent;
|
|
19857
|
-
if (yaml.jackpot_threshold !== void 0) CASINO_CONFIG.jackpotThreshold = yaml.jackpot_threshold;
|
|
19858
|
-
if (yaml.jackpot_cooldown_hours !== void 0)
|
|
19859
|
-
CASINO_CONFIG.jackpotCooldownHours = yaml.jackpot_cooldown_hours;
|
|
19860
19891
|
if (yaml.payment_window_minutes !== void 0)
|
|
19861
19892
|
CASINO_CONFIG.paymentWindowMinutes = yaml.payment_window_minutes;
|
|
19862
19893
|
if (yaml.max_payment_age_minutes !== void 0)
|
|
@@ -19871,8 +19902,7 @@ function initCasinoConfig(yaml) {
|
|
|
19871
19902
|
}
|
|
19872
19903
|
function getSlotMultiplier(value) {
|
|
19873
19904
|
const { slot } = CASINO_CONFIG;
|
|
19874
|
-
if (value >= slot.
|
|
19875
|
-
return slot.jackpot.multiplier;
|
|
19905
|
+
if (value >= slot.topWin.range[0] && value <= slot.topWin.range[1]) return slot.topWin.multiplier;
|
|
19876
19906
|
if (value >= slot.bigWin.range[0] && value <= slot.bigWin.range[1]) return slot.bigWin.multiplier;
|
|
19877
19907
|
if (value >= slot.mediumWin.range[0] && value <= slot.mediumWin.range[1])
|
|
19878
19908
|
return slot.mediumWin.multiplier;
|
|
@@ -19882,14 +19912,14 @@ function getSlotMultiplier(value) {
|
|
|
19882
19912
|
}
|
|
19883
19913
|
function getDiceMultiplier(value) {
|
|
19884
19914
|
const { dice } = CASINO_CONFIG;
|
|
19885
|
-
if (value === dice.
|
|
19915
|
+
if (value === dice.topWin.value) return dice.topWin.multiplier;
|
|
19886
19916
|
if (value === dice.bigWin.value) return dice.bigWin.multiplier;
|
|
19887
19917
|
if (value === dice.smallWin.value) return dice.smallWin.multiplier;
|
|
19888
19918
|
return 0;
|
|
19889
19919
|
}
|
|
19890
19920
|
function getSlotInterpretation(value) {
|
|
19891
19921
|
const { slot } = CASINO_CONFIG;
|
|
19892
|
-
if (value >= slot.
|
|
19922
|
+
if (value >= slot.topWin.range[0] && value <= slot.topWin.range[1]) return "\u{1F3B0} 777! Top win!";
|
|
19893
19923
|
if (value >= slot.bigWin.range[0] && value <= slot.bigWin.range[1]) return "\u{1F38A} Big win!";
|
|
19894
19924
|
if (value >= slot.mediumWin.range[0] && value <= slot.mediumWin.range[1]) return "\u2728 Nice win!";
|
|
19895
19925
|
if (value >= slot.smallWin.range[0] && value <= slot.smallWin.range[1]) return "\u{1F3AF} Small win!";
|
|
@@ -19897,7 +19927,7 @@ function getSlotInterpretation(value) {
|
|
|
19897
19927
|
}
|
|
19898
19928
|
function getDiceInterpretation(value) {
|
|
19899
19929
|
const { dice } = CASINO_CONFIG;
|
|
19900
|
-
if (value === dice.
|
|
19930
|
+
if (value === dice.topWin.value) return "\u{1F3B2} 6! Top win!";
|
|
19901
19931
|
if (value === dice.bigWin.value) return "\u{1F38A} Big win (5)!";
|
|
19902
19932
|
if (value === dice.smallWin.value) return "\u2728 Nice win (4)!";
|
|
19903
19933
|
return `Dice: ${value}`;
|
|
@@ -19955,9 +19985,9 @@ var casinoBalanceExecutor = async (params, context) => {
|
|
|
19955
19985
|
message = `\u2705 Casino bankroll is healthy (${balance.toFixed(2)} TON)`;
|
|
19956
19986
|
canAcceptBets = true;
|
|
19957
19987
|
}
|
|
19958
|
-
const
|
|
19988
|
+
const maxMultiplier = CASINO_CONFIG.slot.topWin.multiplier;
|
|
19959
19989
|
const maxBetByPercent = balance * (CASINO_CONFIG.maxBetPercent / 100);
|
|
19960
|
-
const maxBetByCoverage = balance /
|
|
19990
|
+
const maxBetByCoverage = balance / maxMultiplier;
|
|
19961
19991
|
const maxBet = Math.min(maxBetByPercent, maxBetByCoverage);
|
|
19962
19992
|
return {
|
|
19963
19993
|
success: true,
|
|
@@ -19971,7 +20001,7 @@ var casinoBalanceExecutor = async (params, context) => {
|
|
|
19971
20001
|
maxBet: maxBet.toFixed(2),
|
|
19972
20002
|
minBankroll: CASINO_CONFIG.minBankroll,
|
|
19973
20003
|
maxBetPercent: CASINO_CONFIG.maxBetPercent,
|
|
19974
|
-
|
|
20004
|
+
maxMultiplier,
|
|
19975
20005
|
memoFormat: "{username}",
|
|
19976
20006
|
message
|
|
19977
20007
|
}
|
|
@@ -19994,7 +20024,19 @@ import { Api as Api53 } from "telegram";
|
|
|
19994
20024
|
// src/casino/payment-verifier.ts
|
|
19995
20025
|
import { TonClient as TonClient15, fromNano as fromNano8 } from "@ton/ton";
|
|
19996
20026
|
import { Address as Address16 } from "@ton/core";
|
|
20027
|
+
|
|
20028
|
+
// src/ton/endpoint.ts
|
|
19997
20029
|
import { getHttpEndpoint as getHttpEndpoint15 } from "@orbs-network/ton-access";
|
|
20030
|
+
var ENDPOINT_CACHE_TTL_MS = 6e4;
|
|
20031
|
+
var _cache = null;
|
|
20032
|
+
async function getCachedHttpEndpoint() {
|
|
20033
|
+
if (_cache && Date.now() - _cache.ts < ENDPOINT_CACHE_TTL_MS) {
|
|
20034
|
+
return _cache.url;
|
|
20035
|
+
}
|
|
20036
|
+
const url = await getHttpEndpoint15({ network: "mainnet" });
|
|
20037
|
+
_cache = { url, ts: Date.now() };
|
|
20038
|
+
return url;
|
|
20039
|
+
}
|
|
19998
20040
|
|
|
19999
20041
|
// src/casino/retry.ts
|
|
20000
20042
|
var DEFAULT_OPTIONS = {
|
|
@@ -20068,7 +20110,7 @@ function verifyMemo(memo, identifier) {
|
|
|
20068
20110
|
async function verifyPayment(db, params) {
|
|
20069
20111
|
try {
|
|
20070
20112
|
const { botWalletAddress, betAmount, requestTime, gameType, userId } = params;
|
|
20071
|
-
const endpoint = await
|
|
20113
|
+
const endpoint = await getCachedHttpEndpoint();
|
|
20072
20114
|
const client = new TonClient15({ endpoint });
|
|
20073
20115
|
const botAddress = Address16.parse(botWalletAddress);
|
|
20074
20116
|
const transactions = await withBlockchainRetry(
|
|
@@ -20169,67 +20211,10 @@ function updateCooldown(db, userId) {
|
|
|
20169
20211
|
).run(userId, now);
|
|
20170
20212
|
}
|
|
20171
20213
|
|
|
20172
|
-
// src/casino/jackpot-manager.ts
|
|
20173
|
-
function getJackpot(db) {
|
|
20174
|
-
const row = db.prepare("SELECT * FROM casino_jackpot WHERE id = 1").get();
|
|
20175
|
-
return row;
|
|
20176
|
-
}
|
|
20177
|
-
function addToJackpot(db, amount) {
|
|
20178
|
-
const now = Math.floor(Date.now() / 1e3);
|
|
20179
|
-
db.prepare(
|
|
20180
|
-
`
|
|
20181
|
-
UPDATE casino_jackpot
|
|
20182
|
-
SET amount = amount + ?,
|
|
20183
|
-
updated_at = ?
|
|
20184
|
-
WHERE id = 1
|
|
20185
|
-
`
|
|
20186
|
-
).run(amount, now);
|
|
20187
|
-
const updated = getJackpot(db);
|
|
20188
|
-
return updated.amount;
|
|
20189
|
-
}
|
|
20190
|
-
function awardJackpot(db, winnerId) {
|
|
20191
|
-
const jackpot = getJackpot(db);
|
|
20192
|
-
const amount = jackpot.amount;
|
|
20193
|
-
const now = Math.floor(Date.now() / 1e3);
|
|
20194
|
-
db.prepare(
|
|
20195
|
-
`
|
|
20196
|
-
UPDATE casino_jackpot
|
|
20197
|
-
SET amount = 0,
|
|
20198
|
-
last_winner_id = ?,
|
|
20199
|
-
last_won_at = ?,
|
|
20200
|
-
updated_at = ?
|
|
20201
|
-
WHERE id = 1
|
|
20202
|
-
`
|
|
20203
|
-
).run(winnerId, now, now);
|
|
20204
|
-
return { amount, winnerId };
|
|
20205
|
-
}
|
|
20206
|
-
function calculateHouseEdge(betAmount) {
|
|
20207
|
-
return betAmount * (CASINO_CONFIG.houseEdgePercent / 100);
|
|
20208
|
-
}
|
|
20209
|
-
function processBetForJackpot(db, betAmount) {
|
|
20210
|
-
const houseEdge = calculateHouseEdge(betAmount);
|
|
20211
|
-
addToJackpot(db, houseEdge);
|
|
20212
|
-
return houseEdge;
|
|
20213
|
-
}
|
|
20214
|
-
function shouldAwardDailyJackpot(db) {
|
|
20215
|
-
const jackpot = getJackpot(db);
|
|
20216
|
-
const cooldownSeconds = CASINO_CONFIG.jackpotCooldownHours * 60 * 60;
|
|
20217
|
-
const now = Math.floor(Date.now() / 1e3);
|
|
20218
|
-
if (jackpot.amount < CASINO_CONFIG.jackpotThreshold) {
|
|
20219
|
-
return false;
|
|
20220
|
-
}
|
|
20221
|
-
if (!jackpot.lastWonAt) {
|
|
20222
|
-
return true;
|
|
20223
|
-
}
|
|
20224
|
-
const timeSinceLastWin = now - jackpot.lastWonAt;
|
|
20225
|
-
return timeSinceLastWin >= cooldownSeconds;
|
|
20226
|
-
}
|
|
20227
|
-
|
|
20228
20214
|
// src/casino/payout-sender.ts
|
|
20229
20215
|
import { mnemonicToPrivateKey as mnemonicToPrivateKey11 } from "@ton/crypto";
|
|
20230
20216
|
import { WalletContractV5R1 as WalletContractV5R111, TonClient as TonClient16, toNano as toNano25, internal as internal9 } from "@ton/ton";
|
|
20231
20217
|
import { Address as Address17, SendMode as SendMode9 } from "@ton/core";
|
|
20232
|
-
import { getHttpEndpoint as getHttpEndpoint16 } from "@orbs-network/ton-access";
|
|
20233
20218
|
async function sendPayout(playerAddress, amount, message) {
|
|
20234
20219
|
try {
|
|
20235
20220
|
try {
|
|
@@ -20252,7 +20237,7 @@ async function sendPayout(playerAddress, amount, message) {
|
|
|
20252
20237
|
workchain: 0,
|
|
20253
20238
|
publicKey: keyPair.publicKey
|
|
20254
20239
|
});
|
|
20255
|
-
const endpoint = await
|
|
20240
|
+
const endpoint = await getCachedHttpEndpoint();
|
|
20256
20241
|
const client = new TonClient16({ endpoint });
|
|
20257
20242
|
const contract = client.open(wallet);
|
|
20258
20243
|
const seqno = await withBlockchainRetry(() => contract.getSeqno(), "getSeqno");
|
|
@@ -20294,7 +20279,7 @@ async function sendPayout(playerAddress, amount, message) {
|
|
|
20294
20279
|
}
|
|
20295
20280
|
function getWinMessage(multiplier, amount) {
|
|
20296
20281
|
if (multiplier >= 5) {
|
|
20297
|
-
return `\u{1F3B0}
|
|
20282
|
+
return `\u{1F3B0} 777! You won ${amount.toFixed(2)} TON (${multiplier}x)`;
|
|
20298
20283
|
} else if (multiplier >= 2.5) {
|
|
20299
20284
|
return `\u{1F38A} Big win! You won ${amount.toFixed(2)} TON (${multiplier}x)`;
|
|
20300
20285
|
} else if (multiplier >= 1.8) {
|
|
@@ -20448,11 +20433,9 @@ async function executeGame(config, params, context) {
|
|
|
20448
20433
|
error: `Failed to get ${config.gameType} result from Telegram.`
|
|
20449
20434
|
};
|
|
20450
20435
|
}
|
|
20451
|
-
const houseEdge = processBetForJackpot(context.db, bet_amount);
|
|
20452
20436
|
const multiplier = config.getMultiplier(gameValue);
|
|
20453
20437
|
const won = multiplier > 0;
|
|
20454
20438
|
const payoutAmount = won ? bet_amount * multiplier : 0;
|
|
20455
|
-
const jackpot = getJackpot(context.db);
|
|
20456
20439
|
const recordBet = context.db.transaction(() => {
|
|
20457
20440
|
context.db.prepare(
|
|
20458
20441
|
`INSERT INTO casino_users (telegram_id, wallet_address, total_bets, total_wagered, last_bet_at)
|
|
@@ -20526,8 +20509,6 @@ async function executeGame(config, params, context) {
|
|
|
20526
20509
|
bet_amount: bet_amount.toFixed(2),
|
|
20527
20510
|
player_username: username,
|
|
20528
20511
|
player_wallet: playerWallet,
|
|
20529
|
-
house_edge: houseEdge.toFixed(2),
|
|
20530
|
-
current_jackpot: jackpot.amount.toFixed(2),
|
|
20531
20512
|
payment_tx_hash: paymentVerification.txHash,
|
|
20532
20513
|
journal_id: journalId,
|
|
20533
20514
|
message_id: messageId,
|
|
@@ -20548,8 +20529,8 @@ var casinoSpinTool = {
|
|
|
20548
20529
|
name: "casino_spin",
|
|
20549
20530
|
description: `Execute a Teleton Casino slot machine spin with full security checks.
|
|
20550
20531
|
|
|
20551
|
-
Slot payout table
|
|
20552
|
-
- \u{1F3B0} 64 (777) =
|
|
20532
|
+
Slot payout table:
|
|
20533
|
+
- \u{1F3B0} 64 (777) = 5x bet
|
|
20553
20534
|
- \u{1F3B0} 60-63 = Big win (2.5x bet)
|
|
20554
20535
|
- \u{1F3B0} 55-59 = Medium win (1.8x bet)
|
|
20555
20536
|
- \u{1F3B0} 43-54 = Small win (1.2x bet)
|
|
@@ -20561,8 +20542,7 @@ Process:
|
|
|
20561
20542
|
3. Verifies TON payment with username as memo
|
|
20562
20543
|
4. Auto-discovers player wallet from transaction
|
|
20563
20544
|
5. Sends \u{1F3B0} slot machine animation
|
|
20564
|
-
6.
|
|
20565
|
-
7. AUTO-PAYOUT if player wins
|
|
20545
|
+
6. AUTO-PAYOUT if player wins
|
|
20566
20546
|
|
|
20567
20547
|
Tell the user: "Send X TON to [casino_address] with memo: your_username"`,
|
|
20568
20548
|
parameters: Type106.Object({
|
|
@@ -20590,7 +20570,7 @@ var casinoSpinExecutor = async (params, context) => {
|
|
|
20590
20570
|
gameType: "slot",
|
|
20591
20571
|
toolName: "casino_spin",
|
|
20592
20572
|
assetLabel: "SPIN",
|
|
20593
|
-
maxMultiplier: CASINO_CONFIG.slot.
|
|
20573
|
+
maxMultiplier: CASINO_CONFIG.slot.topWin.multiplier,
|
|
20594
20574
|
getMultiplier: getSlotMultiplier,
|
|
20595
20575
|
getInterpretation: getSlotInterpretation,
|
|
20596
20576
|
maxValue: 64
|
|
@@ -20607,7 +20587,7 @@ var casinoDiceTool = {
|
|
|
20607
20587
|
description: `Execute a Teleton Casino dice roll with full security checks.
|
|
20608
20588
|
|
|
20609
20589
|
Dice payout table:
|
|
20610
|
-
- \u{1F3B2} 6 =
|
|
20590
|
+
- \u{1F3B2} 6 = Best roll (2.5x bet)
|
|
20611
20591
|
- \u{1F3B2} 5 = Big win (1.8x bet)
|
|
20612
20592
|
- \u{1F3B2} 4 = Small win (1.3x bet)
|
|
20613
20593
|
- \u{1F3B2} 1-3 = No win
|
|
@@ -20646,7 +20626,7 @@ var casinoDiceExecutor = async (params, context) => {
|
|
|
20646
20626
|
gameType: "dice",
|
|
20647
20627
|
toolName: "casino_dice",
|
|
20648
20628
|
assetLabel: "DICE",
|
|
20649
|
-
maxMultiplier: CASINO_CONFIG.dice.
|
|
20629
|
+
maxMultiplier: CASINO_CONFIG.dice.topWin.multiplier,
|
|
20650
20630
|
getMultiplier: getDiceMultiplier,
|
|
20651
20631
|
getInterpretation: getDiceInterpretation,
|
|
20652
20632
|
maxValue: 6
|
|
@@ -20656,192 +20636,8 @@ var casinoDiceExecutor = async (params, context) => {
|
|
|
20656
20636
|
);
|
|
20657
20637
|
};
|
|
20658
20638
|
|
|
20659
|
-
// src/agent/tools/casino/payout.ts
|
|
20660
|
-
import { Type as Type108 } from "@sinclair/typebox";
|
|
20661
|
-
import { mnemonicToPrivateKey as mnemonicToPrivateKey12 } from "@ton/crypto";
|
|
20662
|
-
import { WalletContractV5R1 as WalletContractV5R112, TonClient as TonClient17, toNano as toNano26, internal as internal10 } from "@ton/ton";
|
|
20663
|
-
import { Address as Address18, SendMode as SendMode10 } from "@ton/core";
|
|
20664
|
-
import { getHttpEndpoint as getHttpEndpoint17 } from "@orbs-network/ton-access";
|
|
20665
|
-
var casinoPayoutTool = {
|
|
20666
|
-
name: "casino_payout",
|
|
20667
|
-
description: `Manual payout for Teleton Casino (backup tool - normally not needed).
|
|
20668
|
-
|
|
20669
|
-
NOTE: casino_spin and casino_dice already include AUTO-PAYOUT.
|
|
20670
|
-
Only use this tool if auto-payout failed and manual intervention is needed.
|
|
20671
|
-
|
|
20672
|
-
Slot payout table (40% house edge):
|
|
20673
|
-
- Value 64 (\u{1F3B0} 777 Jackpot): 5x bet
|
|
20674
|
-
- Values 60-63 (Big win): 2.5x bet
|
|
20675
|
-
- Values 55-59 (Medium win): 1.8x bet
|
|
20676
|
-
- Values 43-54 (Small win): 1.2x bet
|
|
20677
|
-
- Values 1-42: No payout
|
|
20678
|
-
|
|
20679
|
-
Sends TON to winner's address and updates journal entry.`,
|
|
20680
|
-
parameters: Type108.Object({
|
|
20681
|
-
player_address: Type108.String({
|
|
20682
|
-
description: "Player's TON wallet address to send winnings"
|
|
20683
|
-
}),
|
|
20684
|
-
bet_amount: Type108.Number({
|
|
20685
|
-
description: "Original bet amount in TON",
|
|
20686
|
-
minimum: 1e-3
|
|
20687
|
-
}),
|
|
20688
|
-
slot_value: Type108.Number({
|
|
20689
|
-
description: "Slot machine result (1-64)",
|
|
20690
|
-
minimum: 1,
|
|
20691
|
-
maximum: 64
|
|
20692
|
-
}),
|
|
20693
|
-
journal_entry_id: Type108.Optional(
|
|
20694
|
-
Type108.Number({
|
|
20695
|
-
description: "Journal entry ID to update with payout info"
|
|
20696
|
-
})
|
|
20697
|
-
)
|
|
20698
|
-
})
|
|
20699
|
-
};
|
|
20700
|
-
var casinoPayoutExecutor = async (params, context) => {
|
|
20701
|
-
try {
|
|
20702
|
-
const { player_address, bet_amount, slot_value, journal_entry_id } = params;
|
|
20703
|
-
if (!journal_entry_id || !context.db) {
|
|
20704
|
-
return {
|
|
20705
|
-
success: false,
|
|
20706
|
-
error: "Security restriction: casino_payout requires a journal_entry_id from a real spin/dice result."
|
|
20707
|
-
};
|
|
20708
|
-
}
|
|
20709
|
-
const journalEntry = context.db.prepare(
|
|
20710
|
-
`SELECT id, user_id, amount_from, pnl_ton FROM journal WHERE id = ? AND type IN ('casino_spin', 'casino_dice')`
|
|
20711
|
-
).get(journal_entry_id);
|
|
20712
|
-
if (!journalEntry) {
|
|
20713
|
-
return {
|
|
20714
|
-
success: false,
|
|
20715
|
-
error: `No casino spin/dice found with journal entry #${journal_entry_id}. Cannot send payout without a verified game.`
|
|
20716
|
-
};
|
|
20717
|
-
}
|
|
20718
|
-
if (Math.abs(journalEntry.amount_from - bet_amount) > 0.01) {
|
|
20719
|
-
return {
|
|
20720
|
-
success: false,
|
|
20721
|
-
error: `Bet amount mismatch: journal says ${journalEntry.amount_from} TON but requested ${bet_amount} TON.`
|
|
20722
|
-
};
|
|
20723
|
-
}
|
|
20724
|
-
const multiplier = getSlotMultiplier(slot_value);
|
|
20725
|
-
if (multiplier === 0) {
|
|
20726
|
-
if (journal_entry_id && context.db) {
|
|
20727
|
-
context.db.prepare(
|
|
20728
|
-
`
|
|
20729
|
-
UPDATE journal
|
|
20730
|
-
SET outcome = 'profit',
|
|
20731
|
-
amount_to = 0,
|
|
20732
|
-
pnl_ton = ?,
|
|
20733
|
-
closed_at = unixepoch()
|
|
20734
|
-
WHERE id = ?
|
|
20735
|
-
`
|
|
20736
|
-
).run(bet_amount, journal_entry_id);
|
|
20737
|
-
context.db.prepare(
|
|
20738
|
-
`
|
|
20739
|
-
UPDATE casino_users
|
|
20740
|
-
SET total_losses = total_losses + 1
|
|
20741
|
-
WHERE telegram_id = (
|
|
20742
|
-
SELECT user_id FROM journal WHERE id = ?
|
|
20743
|
-
)
|
|
20744
|
-
`
|
|
20745
|
-
).run(journal_entry_id);
|
|
20746
|
-
}
|
|
20747
|
-
return {
|
|
20748
|
-
success: true,
|
|
20749
|
-
data: {
|
|
20750
|
-
win: false,
|
|
20751
|
-
multiplier: 0,
|
|
20752
|
-
payout: 0,
|
|
20753
|
-
slot_value,
|
|
20754
|
-
message: `No win this time. Slot value: ${slot_value}`
|
|
20755
|
-
}
|
|
20756
|
-
};
|
|
20757
|
-
}
|
|
20758
|
-
const payout = bet_amount * multiplier;
|
|
20759
|
-
try {
|
|
20760
|
-
Address18.parse(player_address);
|
|
20761
|
-
} catch (e) {
|
|
20762
|
-
return {
|
|
20763
|
-
success: false,
|
|
20764
|
-
error: `Invalid player address: ${player_address}`
|
|
20765
|
-
};
|
|
20766
|
-
}
|
|
20767
|
-
const walletData = loadWallet();
|
|
20768
|
-
if (!walletData) {
|
|
20769
|
-
return {
|
|
20770
|
-
success: false,
|
|
20771
|
-
error: "Casino wallet not initialized. Contact admin."
|
|
20772
|
-
};
|
|
20773
|
-
}
|
|
20774
|
-
const keyPair = await mnemonicToPrivateKey12(walletData.mnemonic);
|
|
20775
|
-
const wallet = WalletContractV5R112.create({
|
|
20776
|
-
workchain: 0,
|
|
20777
|
-
publicKey: keyPair.publicKey
|
|
20778
|
-
});
|
|
20779
|
-
const endpoint = await getHttpEndpoint17({ network: "mainnet" });
|
|
20780
|
-
const client = new TonClient17({ endpoint });
|
|
20781
|
-
const contract = client.open(wallet);
|
|
20782
|
-
const seqno = await contract.getSeqno();
|
|
20783
|
-
const winType = getSlotInterpretation(slot_value);
|
|
20784
|
-
await contract.sendTransfer({
|
|
20785
|
-
seqno,
|
|
20786
|
-
secretKey: keyPair.secretKey,
|
|
20787
|
-
sendMode: SendMode10.PAY_GAS_SEPARATELY + SendMode10.IGNORE_ERRORS,
|
|
20788
|
-
messages: [
|
|
20789
|
-
internal10({
|
|
20790
|
-
to: Address18.parse(player_address),
|
|
20791
|
-
value: toNano26(payout),
|
|
20792
|
-
body: `${winType} You won ${payout} TON (${multiplier}x)`,
|
|
20793
|
-
bounce: false
|
|
20794
|
-
})
|
|
20795
|
-
]
|
|
20796
|
-
});
|
|
20797
|
-
if (journal_entry_id && context.db) {
|
|
20798
|
-
const profit = payout - bet_amount;
|
|
20799
|
-
context.db.prepare(
|
|
20800
|
-
`
|
|
20801
|
-
UPDATE journal
|
|
20802
|
-
SET outcome = 'loss',
|
|
20803
|
-
amount_to = ?,
|
|
20804
|
-
pnl_ton = ?,
|
|
20805
|
-
pnl_pct = ?,
|
|
20806
|
-
closed_at = unixepoch()
|
|
20807
|
-
WHERE id = ?
|
|
20808
|
-
`
|
|
20809
|
-
).run(payout, -profit, -(profit / bet_amount * 100), journal_entry_id);
|
|
20810
|
-
}
|
|
20811
|
-
if (context.db) {
|
|
20812
|
-
context.db.prepare(
|
|
20813
|
-
`
|
|
20814
|
-
UPDATE casino_users
|
|
20815
|
-
SET total_wins = total_wins + 1,
|
|
20816
|
-
total_won = total_won + ?
|
|
20817
|
-
WHERE telegram_id = (
|
|
20818
|
-
SELECT user_id FROM journal WHERE id = ?
|
|
20819
|
-
)
|
|
20820
|
-
`
|
|
20821
|
-
).run(payout, journal_entry_id || 0);
|
|
20822
|
-
}
|
|
20823
|
-
return {
|
|
20824
|
-
success: true,
|
|
20825
|
-
data: {
|
|
20826
|
-
win: true,
|
|
20827
|
-
multiplier,
|
|
20828
|
-
payout: payout.toFixed(2),
|
|
20829
|
-
slot_value,
|
|
20830
|
-
player_address,
|
|
20831
|
-
message: `${winType} Sent ${payout.toFixed(2)} TON (${multiplier}x) to ${player_address}`
|
|
20832
|
-
}
|
|
20833
|
-
};
|
|
20834
|
-
} catch (error) {
|
|
20835
|
-
console.error("Error in casino_payout:", error);
|
|
20836
|
-
return {
|
|
20837
|
-
success: false,
|
|
20838
|
-
error: error instanceof Error ? error.message : String(error)
|
|
20839
|
-
};
|
|
20840
|
-
}
|
|
20841
|
-
};
|
|
20842
|
-
|
|
20843
20639
|
// src/agent/tools/casino/leaderboard.ts
|
|
20844
|
-
import { Type as
|
|
20640
|
+
import { Type as Type108 } from "@sinclair/typebox";
|
|
20845
20641
|
var casinoLeaderboardTool = {
|
|
20846
20642
|
name: "casino_leaderboard",
|
|
20847
20643
|
description: `Show Teleton Casino leaderboard with top players.
|
|
@@ -20856,16 +20652,16 @@ Shows:
|
|
|
20856
20652
|
- Total amount wagered
|
|
20857
20653
|
- Total wins/losses
|
|
20858
20654
|
- Win rate percentage`,
|
|
20859
|
-
parameters:
|
|
20860
|
-
limit:
|
|
20861
|
-
|
|
20655
|
+
parameters: Type108.Object({
|
|
20656
|
+
limit: Type108.Optional(
|
|
20657
|
+
Type108.Number({
|
|
20862
20658
|
description: "Number of players to show (default: 10)",
|
|
20863
20659
|
minimum: 1,
|
|
20864
20660
|
maximum: 50
|
|
20865
20661
|
})
|
|
20866
20662
|
),
|
|
20867
|
-
type:
|
|
20868
|
-
|
|
20663
|
+
type: Type108.Optional(
|
|
20664
|
+
Type108.String({
|
|
20869
20665
|
description: "Leaderboard type: winners, losers, or wagered",
|
|
20870
20666
|
enum: ["winners", "losers", "wagered"]
|
|
20871
20667
|
})
|
|
@@ -20970,7 +20766,7 @@ ${formattedPlayers}`
|
|
|
20970
20766
|
};
|
|
20971
20767
|
|
|
20972
20768
|
// src/agent/tools/casino/my-stats.ts
|
|
20973
|
-
import { Type as
|
|
20769
|
+
import { Type as Type109 } from "@sinclair/typebox";
|
|
20974
20770
|
var casinoMyStatsTool = {
|
|
20975
20771
|
name: "casino_my_stats",
|
|
20976
20772
|
description: `Show the current player's personal Teleton Casino statistics.
|
|
@@ -20983,7 +20779,7 @@ Returns:
|
|
|
20983
20779
|
- Net profit/loss
|
|
20984
20780
|
- Win rate percentage
|
|
20985
20781
|
- Last bet timestamp`,
|
|
20986
|
-
parameters:
|
|
20782
|
+
parameters: Type109.Object({})
|
|
20987
20783
|
};
|
|
20988
20784
|
var casinoMyStatsExecutor = async (params, context) => {
|
|
20989
20785
|
try {
|
|
@@ -20997,7 +20793,6 @@ var casinoMyStatsExecutor = async (params, context) => {
|
|
|
20997
20793
|
total_losses,
|
|
20998
20794
|
total_wagered,
|
|
20999
20795
|
total_won,
|
|
21000
|
-
created_at,
|
|
21001
20796
|
last_bet_at
|
|
21002
20797
|
FROM casino_users
|
|
21003
20798
|
WHERE telegram_id = ?`
|
|
@@ -21013,7 +20808,6 @@ var casinoMyStatsExecutor = async (params, context) => {
|
|
|
21013
20808
|
}
|
|
21014
20809
|
const netPnL = playerStats.total_won - playerStats.total_wagered;
|
|
21015
20810
|
const winRate = playerStats.total_bets > 0 ? (playerStats.total_wins / playerStats.total_bets * 100).toFixed(1) : "0";
|
|
21016
|
-
const firstPlayDate = new Date(playerStats.created_at * 1e3).toLocaleDateString();
|
|
21017
20811
|
const lastPlayDate = playerStats.last_bet_at ? new Date(playerStats.last_bet_at * 1e3).toLocaleDateString() : "Never";
|
|
21018
20812
|
let statusEmoji = "\u{1F3AE}";
|
|
21019
20813
|
if (netPnL > 10) statusEmoji = "\u{1F911}";
|
|
@@ -21034,7 +20828,6 @@ var casinoMyStatsExecutor = async (params, context) => {
|
|
|
21034
20828
|
net_pnl: netPnL.toFixed(2),
|
|
21035
20829
|
net_pnl_positive: netPnL >= 0,
|
|
21036
20830
|
win_rate: winRate,
|
|
21037
|
-
first_play: firstPlayDate,
|
|
21038
20831
|
last_play: lastPlayDate,
|
|
21039
20832
|
status_emoji: statusEmoji,
|
|
21040
20833
|
message: `${statusEmoji} Teleton Casino Stats:
|
|
@@ -21055,148 +20848,8 @@ ${netPnL >= 0 ? "\u{1F4C8}" : "\u{1F4C9}"} Net P&L: ${netPnL >= 0 ? "+" : ""}${n
|
|
|
21055
20848
|
}
|
|
21056
20849
|
};
|
|
21057
20850
|
|
|
21058
|
-
// src/agent/tools/casino/jackpot.ts
|
|
21059
|
-
import { Type as Type111 } from "@sinclair/typebox";
|
|
21060
|
-
var casinoJackpotInfoTool = {
|
|
21061
|
-
name: "casino_jackpot_info",
|
|
21062
|
-
description: `View the current Teleton Casino daily jackpot status.
|
|
21063
|
-
|
|
21064
|
-
Returns:
|
|
21065
|
-
- Current jackpot amount (accumulated from 5% house edge)
|
|
21066
|
-
- Last winner and award date
|
|
21067
|
-
- Whether jackpot is ready to be awarded (100+ TON, 24h+ since last award)
|
|
21068
|
-
- Jackpot creation and update timestamps
|
|
21069
|
-
|
|
21070
|
-
The jackpot accumulates 5% of every bet. Once it reaches 100 TON and 24 hours have passed since last award, it can be distributed.`,
|
|
21071
|
-
parameters: Type111.Object({})
|
|
21072
|
-
};
|
|
21073
|
-
var casinoJackpotInfoExecutor = async (params, context) => {
|
|
21074
|
-
try {
|
|
21075
|
-
const jackpot = getJackpot(context.db);
|
|
21076
|
-
const shouldAward = shouldAwardDailyJackpot(context.db);
|
|
21077
|
-
const lastWinner = jackpot.lastWinnerId ? `User ${jackpot.lastWinnerId} (${new Date(jackpot.lastWonAt * 1e3).toLocaleString()})` : "Never awarded";
|
|
21078
|
-
return {
|
|
21079
|
-
success: true,
|
|
21080
|
-
data: {
|
|
21081
|
-
current_amount: jackpot.amount.toFixed(2),
|
|
21082
|
-
last_winner: lastWinner,
|
|
21083
|
-
ready_to_award: shouldAward,
|
|
21084
|
-
min_threshold: "100 TON",
|
|
21085
|
-
award_frequency: "24 hours",
|
|
21086
|
-
created_at: new Date(jackpot.createdAt * 1e3).toISOString(),
|
|
21087
|
-
updated_at: new Date(jackpot.updatedAt * 1e3).toISOString(),
|
|
21088
|
-
message: shouldAward ? `\u{1F3B0} Jackpot ready! ${jackpot.amount.toFixed(2)} TON can be awarded now.` : `\u{1F4B0} Current jackpot: ${jackpot.amount.toFixed(2)} TON`
|
|
21089
|
-
}
|
|
21090
|
-
};
|
|
21091
|
-
} catch (error) {
|
|
21092
|
-
console.error("Error in casino_jackpot_info:", error);
|
|
21093
|
-
return {
|
|
21094
|
-
success: false,
|
|
21095
|
-
error: error instanceof Error ? error.message : String(error)
|
|
21096
|
-
};
|
|
21097
|
-
}
|
|
21098
|
-
};
|
|
21099
|
-
var casinoAwardJackpotTool = {
|
|
21100
|
-
name: "casino_award_jackpot",
|
|
21101
|
-
description: `Award the Teleton Casino daily jackpot to a winner.
|
|
21102
|
-
|
|
21103
|
-
Process:
|
|
21104
|
-
1. Checks if jackpot is ready (100+ TON, 24h+ elapsed)
|
|
21105
|
-
2. Awards entire jackpot amount to winner's wallet
|
|
21106
|
-
3. Resets jackpot to 0
|
|
21107
|
-
4. Records winner in jackpot history
|
|
21108
|
-
5. Logs to journal
|
|
21109
|
-
|
|
21110
|
-
Requirements:
|
|
21111
|
-
- Jackpot must be >= 100 TON
|
|
21112
|
-
- Must be 24+ hours since last award (or never awarded)
|
|
21113
|
-
|
|
21114
|
-
Use this to manually award the jackpot or implement automated daily draws.`,
|
|
21115
|
-
parameters: Type111.Object({
|
|
21116
|
-
winner_telegram_id: Type111.String({
|
|
21117
|
-
description: "Winner's Telegram user ID"
|
|
21118
|
-
}),
|
|
21119
|
-
winner_wallet: Type111.String({
|
|
21120
|
-
description: "Winner's TON wallet address for payout"
|
|
21121
|
-
})
|
|
21122
|
-
})
|
|
21123
|
-
};
|
|
21124
|
-
var casinoAwardJackpotExecutor = async (params, context) => {
|
|
21125
|
-
try {
|
|
21126
|
-
const { winner_telegram_id, winner_wallet } = params;
|
|
21127
|
-
if (!shouldAwardDailyJackpot(context.db)) {
|
|
21128
|
-
const jackpot = getJackpot(context.db);
|
|
21129
|
-
return {
|
|
21130
|
-
success: false,
|
|
21131
|
-
error: `Jackpot not ready yet. Current: ${jackpot.amount.toFixed(2)} TON (minimum: 100 TON, 24h since last award required)`
|
|
21132
|
-
};
|
|
21133
|
-
}
|
|
21134
|
-
const { amount, winnerId } = awardJackpot(context.db, winner_telegram_id);
|
|
21135
|
-
if (amount === 0) {
|
|
21136
|
-
return {
|
|
21137
|
-
success: false,
|
|
21138
|
-
error: "Jackpot amount is 0 TON, nothing to award."
|
|
21139
|
-
};
|
|
21140
|
-
}
|
|
21141
|
-
const payoutResult = await sendPayout(
|
|
21142
|
-
winner_wallet,
|
|
21143
|
-
amount,
|
|
21144
|
-
`\u{1F3B0}\u{1F3B0}\u{1F3B0} TELETON CASINO DAILY JACKPOT! You won ${amount.toFixed(2)} TON! \u{1F3B0}\u{1F3B0}\u{1F3B0}`
|
|
21145
|
-
);
|
|
21146
|
-
if (!payoutResult.success) {
|
|
21147
|
-
context.db.prepare(
|
|
21148
|
-
"UPDATE casino_jackpot SET amount = ?, last_winner_id = NULL, last_won_at = NULL WHERE id = 1"
|
|
21149
|
-
).run(amount);
|
|
21150
|
-
return {
|
|
21151
|
-
success: false,
|
|
21152
|
-
error: `Failed to send payout: ${payoutResult.error}`
|
|
21153
|
-
};
|
|
21154
|
-
}
|
|
21155
|
-
context.db.prepare(
|
|
21156
|
-
`INSERT INTO journal (
|
|
21157
|
-
type, action, asset_from, asset_to, amount_from, amount_to,
|
|
21158
|
-
platform, reasoning, outcome, pnl_ton, tx_hash, tool_used,
|
|
21159
|
-
chat_id, user_id, timestamp
|
|
21160
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, unixepoch())`
|
|
21161
|
-
).run(
|
|
21162
|
-
"trade",
|
|
21163
|
-
"casino_jackpot_award",
|
|
21164
|
-
"JACKPOT",
|
|
21165
|
-
"TON",
|
|
21166
|
-
amount,
|
|
21167
|
-
amount,
|
|
21168
|
-
"telegram_casino",
|
|
21169
|
-
`Daily jackpot awarded to ${winner_telegram_id}`,
|
|
21170
|
-
"loss",
|
|
21171
|
-
// Casino lost (paid out jackpot)
|
|
21172
|
-
-amount,
|
|
21173
|
-
payoutResult.txHash,
|
|
21174
|
-
"casino_award_jackpot",
|
|
21175
|
-
null,
|
|
21176
|
-
// No specific chat
|
|
21177
|
-
winner_telegram_id
|
|
21178
|
-
);
|
|
21179
|
-
return {
|
|
21180
|
-
success: true,
|
|
21181
|
-
data: {
|
|
21182
|
-
amount: amount.toFixed(2),
|
|
21183
|
-
winner_id: winnerId,
|
|
21184
|
-
winner_wallet,
|
|
21185
|
-
payout_tx: payoutResult.txHash,
|
|
21186
|
-
message: `\u{1F3B0} Jackpot awarded! ${amount.toFixed(2)} TON sent to ${winner_wallet}`
|
|
21187
|
-
}
|
|
21188
|
-
};
|
|
21189
|
-
} catch (error) {
|
|
21190
|
-
console.error("Error in casino_award_jackpot:", error);
|
|
21191
|
-
return {
|
|
21192
|
-
success: false,
|
|
21193
|
-
error: error instanceof Error ? error.message : String(error)
|
|
21194
|
-
};
|
|
21195
|
-
}
|
|
21196
|
-
};
|
|
21197
|
-
|
|
21198
20851
|
// src/agent/tools/deals/propose.ts
|
|
21199
|
-
import { Type as
|
|
20852
|
+
import { Type as Type110 } from "@sinclair/typebox";
|
|
21200
20853
|
|
|
21201
20854
|
// src/deals/utils.ts
|
|
21202
20855
|
function generateDealId() {
|
|
@@ -21347,36 +21000,36 @@ BEFORE proposing:
|
|
|
21347
21000
|
3. This tool will REJECT deals that violate strategy
|
|
21348
21001
|
|
|
21349
21002
|
Deal expires in 2 minutes if not accepted.`,
|
|
21350
|
-
parameters:
|
|
21351
|
-
chatId:
|
|
21352
|
-
userId:
|
|
21353
|
-
userGivesType:
|
|
21354
|
-
userGivesTonAmount:
|
|
21355
|
-
|
|
21003
|
+
parameters: Type110.Object({
|
|
21004
|
+
chatId: Type110.String({ description: "Chat ID where to send proposal" }),
|
|
21005
|
+
userId: Type110.Number({ description: "Telegram user ID" }),
|
|
21006
|
+
userGivesType: Type110.Union([Type110.Literal("ton"), Type110.Literal("gift")]),
|
|
21007
|
+
userGivesTonAmount: Type110.Optional(
|
|
21008
|
+
Type110.Number({ description: "TON amount user gives (if type=ton)" })
|
|
21356
21009
|
),
|
|
21357
|
-
userGivesGiftId:
|
|
21358
|
-
|
|
21010
|
+
userGivesGiftId: Type110.Optional(
|
|
21011
|
+
Type110.String({ description: "Gift msgId user gives (if type=gift)" })
|
|
21359
21012
|
),
|
|
21360
|
-
userGivesGiftSlug:
|
|
21361
|
-
|
|
21013
|
+
userGivesGiftSlug: Type110.Optional(
|
|
21014
|
+
Type110.String({
|
|
21362
21015
|
description: "Gift's slug field from telegram_get_my_gifts (e.g. 'LolPop-425402'), NOT the title"
|
|
21363
21016
|
})
|
|
21364
21017
|
),
|
|
21365
|
-
userGivesValueTon:
|
|
21366
|
-
agentGivesType:
|
|
21367
|
-
agentGivesTonAmount:
|
|
21368
|
-
|
|
21018
|
+
userGivesValueTon: Type110.Number({ description: "Estimated TON value of what user gives" }),
|
|
21019
|
+
agentGivesType: Type110.Union([Type110.Literal("ton"), Type110.Literal("gift")]),
|
|
21020
|
+
agentGivesTonAmount: Type110.Optional(
|
|
21021
|
+
Type110.Number({ description: "TON amount you give (if type=ton)" })
|
|
21369
21022
|
),
|
|
21370
|
-
agentGivesGiftId:
|
|
21371
|
-
|
|
21023
|
+
agentGivesGiftId: Type110.Optional(
|
|
21024
|
+
Type110.String({ description: "Gift msgId you give (if type=gift)" })
|
|
21372
21025
|
),
|
|
21373
|
-
agentGivesGiftSlug:
|
|
21374
|
-
|
|
21026
|
+
agentGivesGiftSlug: Type110.Optional(
|
|
21027
|
+
Type110.String({
|
|
21375
21028
|
description: "Gift's slug field from telegram_get_my_gifts (e.g. 'LolPop-425402'), NOT the title"
|
|
21376
21029
|
})
|
|
21377
21030
|
),
|
|
21378
|
-
agentGivesValueTon:
|
|
21379
|
-
userUsername:
|
|
21031
|
+
agentGivesValueTon: Type110.Number({ description: "Estimated TON value of what you give" }),
|
|
21032
|
+
userUsername: Type110.Optional(Type110.String({ description: "User's @username for display" }))
|
|
21380
21033
|
})
|
|
21381
21034
|
};
|
|
21382
21035
|
var dealProposeExecutor = async (params, context) => {
|
|
@@ -21524,7 +21177,7 @@ async function sendInlineBotResult(bridge, chatId, botUsername, dealId) {
|
|
|
21524
21177
|
}
|
|
21525
21178
|
|
|
21526
21179
|
// src/agent/tools/deals/verify-payment.ts
|
|
21527
|
-
import { Type as
|
|
21180
|
+
import { Type as Type111 } from "@sinclair/typebox";
|
|
21528
21181
|
|
|
21529
21182
|
// src/deals/gift-detector.ts
|
|
21530
21183
|
var GiftDetector = class {
|
|
@@ -21588,16 +21241,16 @@ var GiftDetector = class {
|
|
|
21588
21241
|
};
|
|
21589
21242
|
|
|
21590
21243
|
// src/ton/transfer.ts
|
|
21591
|
-
import { mnemonicToPrivateKey as
|
|
21592
|
-
import { WalletContractV5R1 as
|
|
21593
|
-
import { Address as
|
|
21594
|
-
import { getHttpEndpoint as
|
|
21244
|
+
import { mnemonicToPrivateKey as mnemonicToPrivateKey12 } from "@ton/crypto";
|
|
21245
|
+
import { WalletContractV5R1 as WalletContractV5R112, TonClient as TonClient17, toNano as toNano26, internal as internal10 } from "@ton/ton";
|
|
21246
|
+
import { Address as Address18, SendMode as SendMode10 } from "@ton/core";
|
|
21247
|
+
import { getHttpEndpoint as getHttpEndpoint16 } from "@orbs-network/ton-access";
|
|
21595
21248
|
async function sendTon(params) {
|
|
21596
21249
|
try {
|
|
21597
21250
|
const { toAddress: toAddress2, amount, comment = "", bounce = false } = params;
|
|
21598
21251
|
let recipientAddress;
|
|
21599
21252
|
try {
|
|
21600
|
-
recipientAddress =
|
|
21253
|
+
recipientAddress = Address18.parse(toAddress2);
|
|
21601
21254
|
} catch (e) {
|
|
21602
21255
|
console.error(`Invalid recipient address: ${toAddress2}`, e);
|
|
21603
21256
|
return null;
|
|
@@ -21607,23 +21260,23 @@ async function sendTon(params) {
|
|
|
21607
21260
|
console.error("Wallet not initialized");
|
|
21608
21261
|
return null;
|
|
21609
21262
|
}
|
|
21610
|
-
const keyPair = await
|
|
21611
|
-
const wallet =
|
|
21263
|
+
const keyPair = await mnemonicToPrivateKey12(walletData.mnemonic);
|
|
21264
|
+
const wallet = WalletContractV5R112.create({
|
|
21612
21265
|
workchain: 0,
|
|
21613
21266
|
publicKey: keyPair.publicKey
|
|
21614
21267
|
});
|
|
21615
|
-
const endpoint = await
|
|
21616
|
-
const client = new
|
|
21268
|
+
const endpoint = await getHttpEndpoint16({ network: "mainnet" });
|
|
21269
|
+
const client = new TonClient17({ endpoint });
|
|
21617
21270
|
const contract = client.open(wallet);
|
|
21618
21271
|
const seqno = await contract.getSeqno();
|
|
21619
21272
|
await contract.sendTransfer({
|
|
21620
21273
|
seqno,
|
|
21621
21274
|
secretKey: keyPair.secretKey,
|
|
21622
|
-
sendMode:
|
|
21275
|
+
sendMode: SendMode10.PAY_GAS_SEPARATELY + SendMode10.IGNORE_ERRORS,
|
|
21623
21276
|
messages: [
|
|
21624
|
-
|
|
21277
|
+
internal10({
|
|
21625
21278
|
to: recipientAddress,
|
|
21626
|
-
value:
|
|
21279
|
+
value: toNano26(amount),
|
|
21627
21280
|
body: comment,
|
|
21628
21281
|
bounce
|
|
21629
21282
|
})
|
|
@@ -21890,8 +21543,8 @@ Updates deal status to 'verified' if successful.
|
|
|
21890
21543
|
Auto-triggers executor after verification.
|
|
21891
21544
|
|
|
21892
21545
|
IMPORTANT: Only call this for deals with status = 'accepted'.`,
|
|
21893
|
-
parameters:
|
|
21894
|
-
dealId:
|
|
21546
|
+
parameters: Type111.Object({
|
|
21547
|
+
dealId: Type111.String({ description: "Deal ID to verify payment for" })
|
|
21895
21548
|
})
|
|
21896
21549
|
};
|
|
21897
21550
|
var dealVerifyPaymentExecutor = async (params, context) => {
|
|
@@ -21903,6 +21556,13 @@ var dealVerifyPaymentExecutor = async (params, context) => {
|
|
|
21903
21556
|
error: `Deal #${params.dealId} not found`
|
|
21904
21557
|
};
|
|
21905
21558
|
}
|
|
21559
|
+
const adminIds = context.config?.telegram.admin_ids ?? [];
|
|
21560
|
+
if (context.senderId !== deal.user_telegram_id && !adminIds.includes(context.senderId)) {
|
|
21561
|
+
return {
|
|
21562
|
+
success: false,
|
|
21563
|
+
error: `\u26D4 You can only verify payment for your own deals.`
|
|
21564
|
+
};
|
|
21565
|
+
}
|
|
21906
21566
|
if (deal.status !== "accepted") {
|
|
21907
21567
|
return {
|
|
21908
21568
|
success: false,
|
|
@@ -22055,7 +21715,7 @@ var dealVerifyPaymentExecutor = async (params, context) => {
|
|
|
22055
21715
|
};
|
|
22056
21716
|
|
|
22057
21717
|
// src/agent/tools/deals/status.ts
|
|
22058
|
-
import { Type as
|
|
21718
|
+
import { Type as Type112 } from "@sinclair/typebox";
|
|
22059
21719
|
var dealStatusTool = {
|
|
22060
21720
|
name: "deal_status",
|
|
22061
21721
|
description: `Check the status and details of a deal by ID.
|
|
@@ -22067,8 +21727,8 @@ Shows:
|
|
|
22067
21727
|
- Timestamps (created, expires, verified, completed)
|
|
22068
21728
|
- Payment/transfer tracking info (TX hashes, msgIds)
|
|
22069
21729
|
- Profit calculation`,
|
|
22070
|
-
parameters:
|
|
22071
|
-
dealId:
|
|
21730
|
+
parameters: Type112.Object({
|
|
21731
|
+
dealId: Type112.String({ description: "Deal ID to check status for" })
|
|
22072
21732
|
})
|
|
22073
21733
|
};
|
|
22074
21734
|
var dealStatusExecutor = async (params, context) => {
|
|
@@ -22080,6 +21740,13 @@ var dealStatusExecutor = async (params, context) => {
|
|
|
22080
21740
|
error: `Deal #${params.dealId} not found`
|
|
22081
21741
|
};
|
|
22082
21742
|
}
|
|
21743
|
+
const adminIds = context.config?.telegram.admin_ids ?? [];
|
|
21744
|
+
if (context.senderId !== deal.user_telegram_id && !adminIds.includes(context.senderId)) {
|
|
21745
|
+
return {
|
|
21746
|
+
success: false,
|
|
21747
|
+
error: `\u26D4 You can only view your own deals.`
|
|
21748
|
+
};
|
|
21749
|
+
}
|
|
22083
21750
|
const createdAt = new Date(deal.created_at * 1e3).toISOString();
|
|
22084
21751
|
const expiresAt = new Date(deal.expires_at * 1e3).toISOString();
|
|
22085
21752
|
const verifiedAt = deal.user_payment_verified_at ? new Date(deal.user_payment_verified_at * 1e3).toISOString() : null;
|
|
@@ -22180,7 +21847,7 @@ ${deal.notes ? `
|
|
|
22180
21847
|
};
|
|
22181
21848
|
|
|
22182
21849
|
// src/agent/tools/deals/list.ts
|
|
22183
|
-
import { Type as
|
|
21850
|
+
import { Type as Type113 } from "@sinclair/typebox";
|
|
22184
21851
|
var dealListTool = {
|
|
22185
21852
|
name: "deal_list",
|
|
22186
21853
|
description: `List recent deals with optional filters.
|
|
@@ -22191,21 +21858,26 @@ Filters:
|
|
|
22191
21858
|
- limit: Max results (default 20)
|
|
22192
21859
|
|
|
22193
21860
|
Returns summary of each deal with ID, status, parties, trade details, timestamps.`,
|
|
22194
|
-
parameters:
|
|
22195
|
-
status:
|
|
22196
|
-
|
|
21861
|
+
parameters: Type113.Object({
|
|
21862
|
+
status: Type113.Optional(
|
|
21863
|
+
Type113.String({
|
|
22197
21864
|
description: "Filter by status: proposed, accepted, verified, completed, declined, expired, cancelled, failed"
|
|
22198
21865
|
})
|
|
22199
21866
|
),
|
|
22200
|
-
userId:
|
|
22201
|
-
limit:
|
|
22202
|
-
|
|
21867
|
+
userId: Type113.Optional(Type113.Number({ description: "Filter by user's Telegram ID" })),
|
|
21868
|
+
limit: Type113.Optional(
|
|
21869
|
+
Type113.Number({ description: "Max results to return (default 20)", minimum: 1, maximum: 100 })
|
|
22203
21870
|
)
|
|
22204
21871
|
})
|
|
22205
21872
|
};
|
|
22206
21873
|
var dealListExecutor = async (params, context) => {
|
|
22207
21874
|
try {
|
|
22208
|
-
const { status,
|
|
21875
|
+
const { status, limit = 20 } = params;
|
|
21876
|
+
let { userId } = params;
|
|
21877
|
+
const adminIds = context.config?.telegram.admin_ids ?? [];
|
|
21878
|
+
if (!adminIds.includes(context.senderId)) {
|
|
21879
|
+
userId = context.senderId;
|
|
21880
|
+
}
|
|
22209
21881
|
let query = `SELECT * FROM deals WHERE 1=1`;
|
|
22210
21882
|
const queryParams = [];
|
|
22211
21883
|
if (status) {
|
|
@@ -22297,7 +21969,7 @@ var dealListExecutor = async (params, context) => {
|
|
|
22297
21969
|
};
|
|
22298
21970
|
|
|
22299
21971
|
// src/agent/tools/deals/cancel.ts
|
|
22300
|
-
import { Type as
|
|
21972
|
+
import { Type as Type114 } from "@sinclair/typebox";
|
|
22301
21973
|
var dealCancelTool = {
|
|
22302
21974
|
name: "deal_cancel",
|
|
22303
21975
|
description: `Cancel an active deal (proposed or accepted status only).
|
|
@@ -22313,9 +21985,9 @@ Use this when:
|
|
|
22313
21985
|
- External circumstances make deal impossible
|
|
22314
21986
|
|
|
22315
21987
|
The deal status will be set to 'cancelled' and cannot be resumed.`,
|
|
22316
|
-
parameters:
|
|
22317
|
-
dealId:
|
|
22318
|
-
reason:
|
|
21988
|
+
parameters: Type114.Object({
|
|
21989
|
+
dealId: Type114.String({ description: "Deal ID to cancel" }),
|
|
21990
|
+
reason: Type114.Optional(Type114.String({ description: "Reason for cancellation (optional)" }))
|
|
22319
21991
|
})
|
|
22320
21992
|
};
|
|
22321
21993
|
var dealCancelExecutor = async (params, context) => {
|
|
@@ -22328,6 +22000,13 @@ var dealCancelExecutor = async (params, context) => {
|
|
|
22328
22000
|
error: `Deal #${dealId} not found`
|
|
22329
22001
|
};
|
|
22330
22002
|
}
|
|
22003
|
+
const adminIds = context.config?.telegram.admin_ids ?? [];
|
|
22004
|
+
if (context.senderId !== deal.user_telegram_id && !adminIds.includes(context.senderId)) {
|
|
22005
|
+
return {
|
|
22006
|
+
success: false,
|
|
22007
|
+
error: `\u26D4 You can only cancel your own deals.`
|
|
22008
|
+
};
|
|
22009
|
+
}
|
|
22331
22010
|
const cancellableStatuses = ["proposed", "accepted"];
|
|
22332
22011
|
if (!cancellableStatuses.includes(deal.status)) {
|
|
22333
22012
|
return {
|
|
@@ -22401,45 +22080,57 @@ function registerAllTools(registry, config) {
|
|
|
22401
22080
|
registry.register(telegramGetDialogsTool, telegramGetDialogsExecutor);
|
|
22402
22081
|
registry.register(telegramMarkAsReadTool, telegramMarkAsReadExecutor);
|
|
22403
22082
|
registry.register(telegramGetChatInfoTool, telegramGetChatInfoExecutor);
|
|
22404
|
-
registry.register(telegramJoinChannelTool, telegramJoinChannelExecutor);
|
|
22405
|
-
registry.register(telegramLeaveChannelTool, telegramLeaveChannelExecutor);
|
|
22083
|
+
registry.register(telegramJoinChannelTool, telegramJoinChannelExecutor, "dm-only");
|
|
22084
|
+
registry.register(telegramLeaveChannelTool, telegramLeaveChannelExecutor, "dm-only");
|
|
22406
22085
|
registry.register(telegramGetMeTool, telegramGetMeExecutor);
|
|
22407
22086
|
registry.register(telegramGetParticipantsTool, telegramGetParticipantsExecutor);
|
|
22408
|
-
registry.register(telegramKickUserTool, telegramKickUserExecutor);
|
|
22409
|
-
registry.register(telegramBanUserTool, telegramBanUserExecutor);
|
|
22410
|
-
registry.register(telegramUnbanUserTool, telegramUnbanUserExecutor);
|
|
22411
|
-
registry.register(telegramCreateGroupTool, telegramCreateGroupExecutor);
|
|
22412
|
-
registry.register(telegramSetChatPhotoTool, telegramSetChatPhotoExecutor);
|
|
22413
|
-
registry.register(telegramBlockUserTool, telegramBlockUserExecutor);
|
|
22414
|
-
registry.register(telegramGetBlockedTool, telegramGetBlockedExecutor);
|
|
22087
|
+
registry.register(telegramKickUserTool, telegramKickUserExecutor, "group-only");
|
|
22088
|
+
registry.register(telegramBanUserTool, telegramBanUserExecutor, "group-only");
|
|
22089
|
+
registry.register(telegramUnbanUserTool, telegramUnbanUserExecutor, "group-only");
|
|
22090
|
+
registry.register(telegramCreateGroupTool, telegramCreateGroupExecutor, "dm-only");
|
|
22091
|
+
registry.register(telegramSetChatPhotoTool, telegramSetChatPhotoExecutor, "group-only");
|
|
22092
|
+
registry.register(telegramBlockUserTool, telegramBlockUserExecutor, "dm-only");
|
|
22093
|
+
registry.register(telegramGetBlockedTool, telegramGetBlockedExecutor, "dm-only");
|
|
22415
22094
|
registry.register(telegramGetCommonChatsTool, telegramGetCommonChatsExecutor);
|
|
22416
|
-
registry.register(telegramSendStoryTool, telegramSendStoryExecutor);
|
|
22095
|
+
registry.register(telegramSendStoryTool, telegramSendStoryExecutor, "dm-only");
|
|
22417
22096
|
registry.register(telegramGetFoldersTool, telegramGetFoldersExecutor);
|
|
22418
22097
|
registry.register(telegramCreateFolderTool, telegramCreateFolderExecutor);
|
|
22419
22098
|
registry.register(telegramAddChatToFolderTool, telegramAddChatToFolderExecutor);
|
|
22420
|
-
registry.register(telegramCreateChannelTool, telegramCreateChannelExecutor);
|
|
22421
|
-
registry.register(telegramUpdateProfileTool, telegramUpdateProfileExecutor);
|
|
22422
|
-
registry.register(telegramSetBioTool, telegramSetBioExecutor);
|
|
22423
|
-
registry.register(telegramSetUsernameTool, telegramSetUsernameExecutor);
|
|
22099
|
+
registry.register(telegramCreateChannelTool, telegramCreateChannelExecutor, "dm-only");
|
|
22100
|
+
registry.register(telegramUpdateProfileTool, telegramUpdateProfileExecutor, "dm-only");
|
|
22101
|
+
registry.register(telegramSetBioTool, telegramSetBioExecutor, "dm-only");
|
|
22102
|
+
registry.register(telegramSetUsernameTool, telegramSetUsernameExecutor, "dm-only");
|
|
22424
22103
|
registry.register(telegramDeleteMessageTool, telegramDeleteMessageExecutor);
|
|
22425
22104
|
registry.register(telegramDownloadMediaTool, telegramDownloadMediaExecutor);
|
|
22426
22105
|
registry.register(visionAnalyzeTool, visionAnalyzeExecutor);
|
|
22427
|
-
registry.register(telegramGetStarsBalanceTool, telegramGetStarsBalanceExecutor);
|
|
22428
|
-
registry.register(
|
|
22106
|
+
registry.register(telegramGetStarsBalanceTool, telegramGetStarsBalanceExecutor, "dm-only");
|
|
22107
|
+
registry.register(
|
|
22108
|
+
telegramGetStarsTransactionsTool,
|
|
22109
|
+
telegramGetStarsTransactionsExecutor,
|
|
22110
|
+
"dm-only"
|
|
22111
|
+
);
|
|
22429
22112
|
registry.register(telegramGetAvailableGiftsTool, telegramGetAvailableGiftsExecutor);
|
|
22430
|
-
registry.register(telegramSendGiftTool, telegramSendGiftExecutor);
|
|
22113
|
+
registry.register(telegramSendGiftTool, telegramSendGiftExecutor, "dm-only");
|
|
22431
22114
|
registry.register(telegramGetMyGiftsTool, telegramGetMyGiftsExecutor);
|
|
22432
|
-
registry.register(
|
|
22433
|
-
|
|
22115
|
+
registry.register(
|
|
22116
|
+
telegramTransferCollectibleTool,
|
|
22117
|
+
telegramTransferCollectibleExecutor,
|
|
22118
|
+
"dm-only"
|
|
22119
|
+
);
|
|
22120
|
+
registry.register(
|
|
22121
|
+
telegramSetCollectiblePriceTool,
|
|
22122
|
+
telegramSetCollectiblePriceExecutor,
|
|
22123
|
+
"dm-only"
|
|
22124
|
+
);
|
|
22434
22125
|
registry.register(telegramGetResaleGiftsTool, telegramGetResaleGiftsExecutor);
|
|
22435
|
-
registry.register(telegramBuyResaleGiftTool, telegramBuyResaleGiftExecutor);
|
|
22436
|
-
registry.register(telegramSetGiftStatusTool, telegramSetGiftStatusExecutor);
|
|
22437
|
-
registry.register(memoryWriteTool, memoryWriteExecutor);
|
|
22126
|
+
registry.register(telegramBuyResaleGiftTool, telegramBuyResaleGiftExecutor, "dm-only");
|
|
22127
|
+
registry.register(telegramSetGiftStatusTool, telegramSetGiftStatusExecutor, "dm-only");
|
|
22128
|
+
registry.register(memoryWriteTool, memoryWriteExecutor, "dm-only");
|
|
22438
22129
|
registry.register(memoryReadTool, memoryReadExecutor);
|
|
22439
22130
|
registry.register(telegramGetUserInfoTool, telegramGetUserInfoExecutor);
|
|
22440
22131
|
registry.register(telegramCheckUsernameTool, telegramCheckUsernameExecutor);
|
|
22441
|
-
registry.register(telegramEditChannelInfoTool, telegramEditChannelInfoExecutor);
|
|
22442
|
-
registry.register(telegramInviteToChannelTool, telegramInviteToChannelExecutor);
|
|
22132
|
+
registry.register(telegramEditChannelInfoTool, telegramEditChannelInfoExecutor, "dm-only");
|
|
22133
|
+
registry.register(telegramInviteToChannelTool, telegramInviteToChannelExecutor, "dm-only");
|
|
22443
22134
|
if (config.market.enabled || config.deals.enabled) {
|
|
22444
22135
|
registry.register(marketGetFloorTool, marketGetFloorExecutor);
|
|
22445
22136
|
registry.register(marketSearchTool, marketSearchExecutor);
|
|
@@ -22449,12 +22140,12 @@ function registerAllTools(registry, config) {
|
|
|
22449
22140
|
registry.register(tonGetAddressTool, tonGetAddressExecutor);
|
|
22450
22141
|
registry.register(tonGetBalanceTool, tonGetBalanceExecutor);
|
|
22451
22142
|
registry.register(tonPriceTool, tonPriceExecutor);
|
|
22452
|
-
registry.register(tonSendTool, tonSendExecutor);
|
|
22143
|
+
registry.register(tonSendTool, tonSendExecutor, "dm-only");
|
|
22453
22144
|
registry.register(tonGetTransactionsTool, tonGetTransactionsExecutor);
|
|
22454
22145
|
registry.register(tonMyTransactionsTool, tonMyTransactionsExecutor);
|
|
22455
22146
|
registry.register(jettonBalancesTool, jettonBalancesExecutor);
|
|
22456
|
-
registry.register(jettonSwapTool, jettonSwapExecutor);
|
|
22457
|
-
registry.register(jettonSendTool, jettonSendExecutor);
|
|
22147
|
+
registry.register(jettonSwapTool, jettonSwapExecutor, "dm-only");
|
|
22148
|
+
registry.register(jettonSendTool, jettonSendExecutor, "dm-only");
|
|
22458
22149
|
registry.register(jettonInfoTool, jettonInfoExecutor);
|
|
22459
22150
|
registry.register(jettonPriceTool, jettonPriceExecutor);
|
|
22460
22151
|
registry.register(jettonSearchTool, jettonSearchExecutor);
|
|
@@ -22466,40 +22157,37 @@ function registerAllTools(registry, config) {
|
|
|
22466
22157
|
registry.register(dnsCheckTool, dnsCheckExecutor);
|
|
22467
22158
|
registry.register(dnsAuctionsTool, dnsAuctionsExecutor);
|
|
22468
22159
|
registry.register(dnsResolveTool, dnsResolveExecutor);
|
|
22469
|
-
registry.register(dnsStartAuctionTool, dnsStartAuctionExecutor);
|
|
22470
|
-
registry.register(dnsBidTool, dnsBidExecutor);
|
|
22471
|
-
registry.register(dnsLinkTool, dnsLinkExecutor);
|
|
22472
|
-
registry.register(dnsUnlinkTool, dnsUnlinkExecutor);
|
|
22160
|
+
registry.register(dnsStartAuctionTool, dnsStartAuctionExecutor, "dm-only");
|
|
22161
|
+
registry.register(dnsBidTool, dnsBidExecutor, "dm-only");
|
|
22162
|
+
registry.register(dnsLinkTool, dnsLinkExecutor, "dm-only");
|
|
22163
|
+
registry.register(dnsUnlinkTool, dnsUnlinkExecutor, "dm-only");
|
|
22473
22164
|
registry.register(dedustQuoteTool, dedustQuoteExecutor);
|
|
22474
|
-
registry.register(dedustSwapTool, dedustSwapExecutor);
|
|
22165
|
+
registry.register(dedustSwapTool, dedustSwapExecutor, "dm-only");
|
|
22475
22166
|
registry.register(dedustPoolsTool, dedustPoolsExecutor);
|
|
22476
22167
|
registry.register(dexQuoteTool, dexQuoteExecutor);
|
|
22477
|
-
registry.register(dexSwapTool, dexSwapExecutor);
|
|
22478
|
-
registry.register(journalLogTool, journalLogExecutor);
|
|
22168
|
+
registry.register(dexSwapTool, dexSwapExecutor, "dm-only");
|
|
22169
|
+
registry.register(journalLogTool, journalLogExecutor, "dm-only");
|
|
22479
22170
|
registry.register(journalQueryTool, journalQueryExecutor);
|
|
22480
|
-
registry.register(journalUpdateTool, journalUpdateExecutor);
|
|
22171
|
+
registry.register(journalUpdateTool, journalUpdateExecutor, "dm-only");
|
|
22481
22172
|
registry.register(workspaceListTool, workspaceListExecutor);
|
|
22482
22173
|
registry.register(workspaceReadTool, workspaceReadExecutor);
|
|
22483
|
-
registry.register(workspaceWriteTool, workspaceWriteExecutor);
|
|
22484
|
-
registry.register(workspaceDeleteTool, workspaceDeleteExecutor);
|
|
22174
|
+
registry.register(workspaceWriteTool, workspaceWriteExecutor, "dm-only");
|
|
22175
|
+
registry.register(workspaceDeleteTool, workspaceDeleteExecutor, "dm-only");
|
|
22485
22176
|
registry.register(workspaceInfoTool, workspaceInfoExecutor);
|
|
22486
|
-
registry.register(workspaceRenameTool, workspaceRenameExecutor);
|
|
22177
|
+
registry.register(workspaceRenameTool, workspaceRenameExecutor, "dm-only");
|
|
22487
22178
|
if (config.casino.enabled) {
|
|
22488
22179
|
registry.register(casinoBalanceTool, casinoBalanceExecutor);
|
|
22489
22180
|
registry.register(casinoSpinTool, casinoSpinExecutor);
|
|
22490
22181
|
registry.register(casinoDiceTool, casinoDiceExecutor);
|
|
22491
|
-
registry.register(casinoPayoutTool, casinoPayoutExecutor);
|
|
22492
22182
|
registry.register(casinoLeaderboardTool, casinoLeaderboardExecutor);
|
|
22493
22183
|
registry.register(casinoMyStatsTool, casinoMyStatsExecutor);
|
|
22494
|
-
registry.register(casinoJackpotInfoTool, casinoJackpotInfoExecutor);
|
|
22495
|
-
registry.register(casinoAwardJackpotTool, casinoAwardJackpotExecutor);
|
|
22496
22184
|
}
|
|
22497
22185
|
if (config.deals.enabled) {
|
|
22498
|
-
registry.register(dealProposeTool, dealProposeExecutor);
|
|
22499
|
-
registry.register(dealVerifyPaymentTool, dealVerifyPaymentExecutor);
|
|
22186
|
+
registry.register(dealProposeTool, dealProposeExecutor, "dm-only");
|
|
22187
|
+
registry.register(dealVerifyPaymentTool, dealVerifyPaymentExecutor, "dm-only");
|
|
22500
22188
|
registry.register(dealStatusTool, dealStatusExecutor);
|
|
22501
22189
|
registry.register(dealListTool, dealListExecutor);
|
|
22502
|
-
registry.register(dealCancelTool, dealCancelExecutor);
|
|
22190
|
+
registry.register(dealCancelTool, dealCancelExecutor, "dm-only");
|
|
22503
22191
|
}
|
|
22504
22192
|
}
|
|
22505
22193
|
|
|
@@ -23874,7 +23562,7 @@ ${blue} \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u250
|
|
|
23874
23562
|
`\u26A0\uFE0F Tool count (${this.toolCount}) exceeds ${providerMeta.displayName} limit (${providerMeta.toolLimit})`
|
|
23875
23563
|
);
|
|
23876
23564
|
}
|
|
23877
|
-
const { migrateSessionsToDb } = await import("./migrate-
|
|
23565
|
+
const { migrateSessionsToDb } = await import("./migrate-4Z74FLKS.js");
|
|
23878
23566
|
migrateSessionsToDb();
|
|
23879
23567
|
const { cleanupOldTranscripts } = await import("./transcript-DF2Y6CFY.js");
|
|
23880
23568
|
cleanupOldTranscripts(30);
|
|
@@ -24060,7 +23748,7 @@ ${blue} \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u250
|
|
|
24060
23748
|
const taskId = match[1];
|
|
24061
23749
|
const { getTaskStore } = await import("./tasks-M3QDPTGY.js");
|
|
24062
23750
|
const { executeScheduledTask } = await import("./task-executor-MNI4VIZL.js");
|
|
24063
|
-
const { getDatabase: getDatabase2 } = await import("./memory-
|
|
23751
|
+
const { getDatabase: getDatabase2 } = await import("./memory-RBJIBZ5L.js");
|
|
24064
23752
|
const db = getDatabase2().getDb();
|
|
24065
23753
|
const taskStore = getTaskStore(db);
|
|
24066
23754
|
const task = taskStore.getTask(taskId);
|
|
@@ -24135,7 +23823,7 @@ ${blue} \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u250
|
|
|
24135
23823
|
try {
|
|
24136
23824
|
const { getTaskStore } = await import("./tasks-M3QDPTGY.js");
|
|
24137
23825
|
const { TaskDependencyResolver } = await import("./task-dependency-resolver-CWG6DTU4.js");
|
|
24138
|
-
const { getDatabase: getDatabase2 } = await import("./memory-
|
|
23826
|
+
const { getDatabase: getDatabase2 } = await import("./memory-RBJIBZ5L.js");
|
|
24139
23827
|
const db = getDatabase2().getDb();
|
|
24140
23828
|
const taskStore = getTaskStore(db);
|
|
24141
23829
|
const match = message.text.match(/^\[TASK:([^\]]+)\]/);
|