omnius 1.0.85 → 1.0.87
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/dist/index.js +738 -10
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -607760,10 +607760,10 @@ function decodeHelpCallback(data) {
|
|
|
607760
607760
|
if (parts.length < 3) return null;
|
|
607761
607761
|
const action = parts[1];
|
|
607762
607762
|
const value2 = parts.slice(2).join(":");
|
|
607763
|
-
if (action !== "page" && action !== "detail" && action !== "back") return null;
|
|
607763
|
+
if (action !== "page" && action !== "detail" && action !== "back" && action !== "close") return null;
|
|
607764
607764
|
return { action, value: value2 };
|
|
607765
607765
|
}
|
|
607766
|
-
function buildToolListKeyboard(tools, page2, scope) {
|
|
607766
|
+
function buildToolListKeyboard(tools, page2, scope, countdown = null) {
|
|
607767
607767
|
const totalPages = Math.max(1, Math.ceil(tools.length / TOOLS_PER_PAGE));
|
|
607768
607768
|
const start2 = page2 * TOOLS_PER_PAGE;
|
|
607769
607769
|
const pageTools = tools.slice(start2, start2 + TOOLS_PER_PAGE);
|
|
@@ -607784,6 +607784,10 @@ function buildToolListKeyboard(tools, page2, scope) {
|
|
|
607784
607784
|
rows.push(currentRow);
|
|
607785
607785
|
}
|
|
607786
607786
|
const navRow = [];
|
|
607787
|
+
if (page2 === 0) {
|
|
607788
|
+
const closeLabel = countdown != null ? `✖ ${countdown}` : "✖ Close";
|
|
607789
|
+
navRow.push({ text: closeLabel, callback_data: encodeHelpCallback("close", "0") });
|
|
607790
|
+
}
|
|
607787
607791
|
if (page2 > 0) {
|
|
607788
607792
|
navRow.push({ text: "◀️ Back", callback_data: encodeHelpCallback("page", page2 - 1) });
|
|
607789
607793
|
}
|
|
@@ -607873,6 +607877,14 @@ function renderHelpMenuPage(scope, page2) {
|
|
|
607873
607877
|
const inline_keyboard = buildToolListKeyboard(tools, page2, scope);
|
|
607874
607878
|
return { text, replyMarkup: { inline_keyboard } };
|
|
607875
607879
|
}
|
|
607880
|
+
function renderHelpMenuPageWithCountdown(scope, page2, countdown) {
|
|
607881
|
+
const tools = buildScopedToolList(scope);
|
|
607882
|
+
const totalPages = Math.max(1, Math.ceil(tools.length / TOOLS_PER_PAGE));
|
|
607883
|
+
page2 = Math.max(0, Math.min(page2, totalPages - 1));
|
|
607884
|
+
const text = buildToolListText(tools, page2, scope);
|
|
607885
|
+
const inline_keyboard = buildToolListKeyboard(tools, page2, scope, countdown);
|
|
607886
|
+
return { text, replyMarkup: { inline_keyboard } };
|
|
607887
|
+
}
|
|
607876
607888
|
function renderHelpToolDetail(scope, toolName, returnPage) {
|
|
607877
607889
|
const tools = buildScopedToolList(scope);
|
|
607878
607890
|
const tool = tools.find((t2) => t2.name === toolName);
|
|
@@ -607892,29 +607904,32 @@ function handleHelpCallback(callbackData, currentState) {
|
|
|
607892
607904
|
const page2 = parseInt(value2, 10);
|
|
607893
607905
|
if (isNaN(page2)) return null;
|
|
607894
607906
|
render2 = renderHelpMenuPage(currentState.scope, page2);
|
|
607895
|
-
newState = { ...currentState, page: page2, view: "list", detailToolName: null };
|
|
607907
|
+
newState = { ...currentState, page: page2, view: "list", detailToolName: null, lastInteractionAt: Date.now() };
|
|
607896
607908
|
break;
|
|
607897
607909
|
}
|
|
607898
607910
|
case "detail": {
|
|
607899
607911
|
const detail = renderHelpToolDetail(currentState.scope, value2, currentState.page);
|
|
607900
607912
|
if (!detail) return null;
|
|
607901
607913
|
render2 = detail;
|
|
607902
|
-
newState = { ...currentState, view: "detail", detailToolName: value2 };
|
|
607914
|
+
newState = { ...currentState, view: "detail", detailToolName: value2, lastInteractionAt: Date.now() };
|
|
607903
607915
|
break;
|
|
607904
607916
|
}
|
|
607905
607917
|
case "back": {
|
|
607906
607918
|
const page2 = parseInt(value2, 10);
|
|
607907
607919
|
if (isNaN(page2)) return null;
|
|
607908
607920
|
render2 = renderHelpMenuPage(currentState.scope, page2);
|
|
607909
|
-
newState = { ...currentState, page: page2, view: "list", detailToolName: null };
|
|
607921
|
+
newState = { ...currentState, page: page2, view: "list", detailToolName: null, lastInteractionAt: Date.now() };
|
|
607910
607922
|
break;
|
|
607911
607923
|
}
|
|
607924
|
+
case "close": {
|
|
607925
|
+
return { render: null, newState: currentState, close: true };
|
|
607926
|
+
}
|
|
607912
607927
|
default:
|
|
607913
607928
|
return null;
|
|
607914
607929
|
}
|
|
607915
607930
|
return { render: render2, newState };
|
|
607916
607931
|
}
|
|
607917
|
-
var TOOLS_PER_PAGE, GRID_COLS, CALLBACK_PREFIX, MAX_CALLBACK_DATA, TELEGRAM_PUBLIC_HELP_COMMANDS, HelpMenuStateStore;
|
|
607932
|
+
var TOOLS_PER_PAGE, GRID_COLS, CALLBACK_PREFIX, MAX_CALLBACK_DATA, INACTIVITY_TIMEOUT_MS, COUNTDOWN_SECONDS, TELEGRAM_PUBLIC_HELP_COMMANDS, HelpMenuStateStore, HelpMenuTimerManager;
|
|
607918
607933
|
var init_telegram_help_menu = __esm({
|
|
607919
607934
|
"packages/cli/src/tui/telegram-help-menu.ts"() {
|
|
607920
607935
|
"use strict";
|
|
@@ -607923,6 +607938,8 @@ var init_telegram_help_menu = __esm({
|
|
|
607923
607938
|
GRID_COLS = 5;
|
|
607924
607939
|
CALLBACK_PREFIX = "help";
|
|
607925
607940
|
MAX_CALLBACK_DATA = 64;
|
|
607941
|
+
INACTIVITY_TIMEOUT_MS = 6e4;
|
|
607942
|
+
COUNTDOWN_SECONDS = 10;
|
|
607926
607943
|
TELEGRAM_PUBLIC_HELP_COMMANDS = /* @__PURE__ */ new Set(["help", "start", "auth", "call"]);
|
|
607927
607944
|
HelpMenuStateStore = class {
|
|
607928
607945
|
states = /* @__PURE__ */ new Map();
|
|
@@ -607948,6 +607965,505 @@ var init_telegram_help_menu = __esm({
|
|
|
607948
607965
|
}
|
|
607949
607966
|
}
|
|
607950
607967
|
};
|
|
607968
|
+
HelpMenuTimerManager = class {
|
|
607969
|
+
inactivityTimers = /* @__PURE__ */ new Map();
|
|
607970
|
+
countdownIntervals = /* @__PURE__ */ new Map();
|
|
607971
|
+
stateStore;
|
|
607972
|
+
callbacks;
|
|
607973
|
+
constructor(stateStore, callbacks) {
|
|
607974
|
+
this.stateStore = stateStore;
|
|
607975
|
+
this.callbacks = callbacks;
|
|
607976
|
+
}
|
|
607977
|
+
key(chatId, messageId) {
|
|
607978
|
+
return `${chatId}:${messageId}`;
|
|
607979
|
+
}
|
|
607980
|
+
/** Start the inactivity timer for a newly created menu */
|
|
607981
|
+
startTimer(state) {
|
|
607982
|
+
this.clearTimer(state.chatId, state.messageId);
|
|
607983
|
+
const k = this.key(state.chatId, state.messageId);
|
|
607984
|
+
const timer = setTimeout(() => {
|
|
607985
|
+
this.inactivityTimers.delete(k);
|
|
607986
|
+
this.startCountdown(state);
|
|
607987
|
+
}, INACTIVITY_TIMEOUT_MS);
|
|
607988
|
+
this.inactivityTimers.set(k, timer);
|
|
607989
|
+
}
|
|
607990
|
+
/** Reset the inactivity timer after user interaction */
|
|
607991
|
+
resetTimer(chatId, messageId) {
|
|
607992
|
+
const state = this.stateStore.get(chatId, messageId);
|
|
607993
|
+
if (!state) return;
|
|
607994
|
+
this.cancelCountdown(chatId, messageId);
|
|
607995
|
+
const updated = { ...state, lastInteractionAt: Date.now(), countdownValue: null };
|
|
607996
|
+
this.stateStore.set(updated);
|
|
607997
|
+
this.startTimer(updated);
|
|
607998
|
+
}
|
|
607999
|
+
/** Clear all timers for a menu (used when menu is closed or deleted) */
|
|
608000
|
+
clearTimer(chatId, messageId) {
|
|
608001
|
+
const k = this.key(chatId, messageId);
|
|
608002
|
+
const timer = this.inactivityTimers.get(k);
|
|
608003
|
+
if (timer) {
|
|
608004
|
+
clearTimeout(timer);
|
|
608005
|
+
this.inactivityTimers.delete(k);
|
|
608006
|
+
}
|
|
608007
|
+
this.cancelCountdown(chatId, messageId);
|
|
608008
|
+
}
|
|
608009
|
+
/** Start the 10-second countdown, updating the close button each second */
|
|
608010
|
+
startCountdown(state) {
|
|
608011
|
+
const k = this.key(state.chatId, state.messageId);
|
|
608012
|
+
let countdown = COUNTDOWN_SECONDS;
|
|
608013
|
+
const updatedState = { ...state, countdownValue: countdown, lastInteractionAt: Date.now() };
|
|
608014
|
+
this.stateStore.set(updatedState);
|
|
608015
|
+
this.updateCountdownButton(updatedState);
|
|
608016
|
+
const interval = setInterval(() => {
|
|
608017
|
+
countdown--;
|
|
608018
|
+
if (countdown <= 0) {
|
|
608019
|
+
clearInterval(interval);
|
|
608020
|
+
this.countdownIntervals.delete(k);
|
|
608021
|
+
this.deleteMenu(state.chatId, state.messageId);
|
|
608022
|
+
} else {
|
|
608023
|
+
const s2 = { ...state, countdownValue: countdown, lastInteractionAt: Date.now() };
|
|
608024
|
+
this.stateStore.set(s2);
|
|
608025
|
+
this.updateCountdownButton(s2);
|
|
608026
|
+
}
|
|
608027
|
+
}, 1e3);
|
|
608028
|
+
this.countdownIntervals.set(k, interval);
|
|
608029
|
+
}
|
|
608030
|
+
cancelCountdown(chatId, messageId) {
|
|
608031
|
+
const k = this.key(chatId, messageId);
|
|
608032
|
+
const interval = this.countdownIntervals.get(k);
|
|
608033
|
+
if (interval) {
|
|
608034
|
+
clearInterval(interval);
|
|
608035
|
+
this.countdownIntervals.delete(k);
|
|
608036
|
+
}
|
|
608037
|
+
}
|
|
608038
|
+
/** Update the close button to show countdown value */
|
|
608039
|
+
async updateCountdownButton(state) {
|
|
608040
|
+
try {
|
|
608041
|
+
let render2;
|
|
608042
|
+
if (state.view === "list") {
|
|
608043
|
+
render2 = renderHelpMenuPageWithCountdown(state.scope, state.page, state.countdownValue);
|
|
608044
|
+
} else {
|
|
608045
|
+
render2 = renderHelpToolDetail(state.scope, state.detailToolName, state.page);
|
|
608046
|
+
}
|
|
608047
|
+
if (!render2) return;
|
|
608048
|
+
await this.callbacks.editMessageText(
|
|
608049
|
+
state.chatId,
|
|
608050
|
+
state.messageId,
|
|
608051
|
+
render2.text,
|
|
608052
|
+
render2.replyMarkup
|
|
608053
|
+
);
|
|
608054
|
+
} catch {
|
|
608055
|
+
}
|
|
608056
|
+
}
|
|
608057
|
+
/** Delete the menu message and clean up state */
|
|
608058
|
+
async deleteMenu(chatId, messageId) {
|
|
608059
|
+
this.clearTimer(chatId, messageId);
|
|
608060
|
+
this.stateStore.delete(chatId, messageId);
|
|
608061
|
+
try {
|
|
608062
|
+
await this.callbacks.deleteMessage(chatId, messageId);
|
|
608063
|
+
} catch {
|
|
608064
|
+
}
|
|
608065
|
+
}
|
|
608066
|
+
/** Clean up all timers (for shutdown) */
|
|
608067
|
+
destroyAll() {
|
|
608068
|
+
for (const [k, timer] of this.inactivityTimers) {
|
|
608069
|
+
clearTimeout(timer);
|
|
608070
|
+
}
|
|
608071
|
+
this.inactivityTimers.clear();
|
|
608072
|
+
for (const [k, interval] of this.countdownIntervals) {
|
|
608073
|
+
clearInterval(interval);
|
|
608074
|
+
}
|
|
608075
|
+
this.countdownIntervals.clear();
|
|
608076
|
+
}
|
|
608077
|
+
};
|
|
608078
|
+
}
|
|
608079
|
+
});
|
|
608080
|
+
|
|
608081
|
+
// packages/cli/src/tui/telegram-stats-menu.ts
|
|
608082
|
+
function emptySnapshot() {
|
|
608083
|
+
return {
|
|
608084
|
+
totalInferences: 0,
|
|
608085
|
+
totalPromptTokens: 0,
|
|
608086
|
+
totalCompletionTokens: 0,
|
|
608087
|
+
totalTokens: 0,
|
|
608088
|
+
avgTokensPerSecond: 0,
|
|
608089
|
+
peakTokensPerSecond: 0,
|
|
608090
|
+
avgInferenceDurationMs: 0,
|
|
608091
|
+
totalInferenceDurationMs: 0,
|
|
608092
|
+
totalToolCalls: 0,
|
|
608093
|
+
successfulToolCalls: 0,
|
|
608094
|
+
failedToolCalls: 0,
|
|
608095
|
+
toolCallBreakdown: [],
|
|
608096
|
+
contextWindowSize: 0,
|
|
608097
|
+
estimatedContextTokens: 0,
|
|
608098
|
+
peakContextTokens: 0,
|
|
608099
|
+
contextUtilizationPct: 0,
|
|
608100
|
+
sessionDurationMs: 0,
|
|
608101
|
+
sessionStartAt: Date.now(),
|
|
608102
|
+
turnCount: 0,
|
|
608103
|
+
compactionCount: 0,
|
|
608104
|
+
model: "unknown",
|
|
608105
|
+
backend: "ollama",
|
|
608106
|
+
gpuName: null,
|
|
608107
|
+
gpuVramUsedMb: null,
|
|
608108
|
+
gpuVramTotalMb: null
|
|
608109
|
+
};
|
|
608110
|
+
}
|
|
608111
|
+
function fmtDuration(ms) {
|
|
608112
|
+
if (ms < 1e3) return `${Math.round(ms)}ms`;
|
|
608113
|
+
const s2 = ms / 1e3;
|
|
608114
|
+
if (s2 < 60) return `${s2.toFixed(1)}s`;
|
|
608115
|
+
const m2 = Math.floor(s2 / 60);
|
|
608116
|
+
const rs = Math.round(s2 % 60);
|
|
608117
|
+
if (m2 < 60) return `${m2}m ${rs}s`;
|
|
608118
|
+
const h = Math.floor(m2 / 60);
|
|
608119
|
+
const rm4 = m2 % 60;
|
|
608120
|
+
return `${h}h ${rm4}m`;
|
|
608121
|
+
}
|
|
608122
|
+
function fmtTokens2(n2) {
|
|
608123
|
+
if (n2 < 1e3) return String(n2);
|
|
608124
|
+
if (n2 < 1e6) return `${(n2 / 1e3).toFixed(1)}K`;
|
|
608125
|
+
return `${(n2 / 1e6).toFixed(2)}M`;
|
|
608126
|
+
}
|
|
608127
|
+
function fmtPct(n2) {
|
|
608128
|
+
return `${n2.toFixed(1)}%`;
|
|
608129
|
+
}
|
|
608130
|
+
function escapeHTML2(text) {
|
|
608131
|
+
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
608132
|
+
}
|
|
608133
|
+
function buildMetricEntries(snap, scope) {
|
|
608134
|
+
const entries = [];
|
|
608135
|
+
entries.push({
|
|
608136
|
+
icon: "🧠",
|
|
608137
|
+
label: "Model",
|
|
608138
|
+
value: escapeHTML2(snap.model),
|
|
608139
|
+
category: "inference"
|
|
608140
|
+
});
|
|
608141
|
+
entries.push({
|
|
608142
|
+
icon: "⚡",
|
|
608143
|
+
label: "Inferences",
|
|
608144
|
+
value: String(snap.totalInferences),
|
|
608145
|
+
detail: `Total duration: ${fmtDuration(snap.totalInferenceDurationMs)}`,
|
|
608146
|
+
category: "inference"
|
|
608147
|
+
});
|
|
608148
|
+
entries.push({
|
|
608149
|
+
icon: "🔤",
|
|
608150
|
+
label: "Tokens",
|
|
608151
|
+
value: fmtTokens2(snap.totalTokens),
|
|
608152
|
+
detail: `Prompt: ${fmtTokens2(snap.totalPromptTokens)} · Completion: ${fmtTokens2(snap.totalCompletionTokens)}`,
|
|
608153
|
+
category: "inference"
|
|
608154
|
+
});
|
|
608155
|
+
entries.push({
|
|
608156
|
+
icon: "🚀",
|
|
608157
|
+
label: "Avg Speed",
|
|
608158
|
+
value: `${snap.avgTokensPerSecond.toFixed(1)} tok/s`,
|
|
608159
|
+
detail: `Peak: ${snap.peakTokensPerSecond.toFixed(1)} tok/s`,
|
|
608160
|
+
category: "inference"
|
|
608161
|
+
});
|
|
608162
|
+
entries.push({
|
|
608163
|
+
icon: "⏱",
|
|
608164
|
+
label: "Avg Inference",
|
|
608165
|
+
value: fmtDuration(snap.avgInferenceDurationMs),
|
|
608166
|
+
category: "inference"
|
|
608167
|
+
});
|
|
608168
|
+
entries.push({
|
|
608169
|
+
icon: "🔧",
|
|
608170
|
+
label: "Tool Calls",
|
|
608171
|
+
value: String(snap.totalToolCalls),
|
|
608172
|
+
detail: `✅ ${snap.successfulToolCalls} · ❌ ${snap.failedToolCalls}`,
|
|
608173
|
+
category: "tools"
|
|
608174
|
+
});
|
|
608175
|
+
const topTools = snap.toolCallBreakdown.sort((a2, b) => b.count - a2.count).slice(0, scope === "admin" ? 5 : 3);
|
|
608176
|
+
for (const t2 of topTools) {
|
|
608177
|
+
entries.push({
|
|
608178
|
+
icon: "🔩",
|
|
608179
|
+
label: t2.name,
|
|
608180
|
+
value: `${t2.count}×`,
|
|
608181
|
+
detail: `Avg: ${fmtDuration(t2.avgDurationMs)}`,
|
|
608182
|
+
category: "tools"
|
|
608183
|
+
});
|
|
608184
|
+
}
|
|
608185
|
+
entries.push({
|
|
608186
|
+
icon: "📐",
|
|
608187
|
+
label: "Context Window",
|
|
608188
|
+
value: fmtTokens2(snap.contextWindowSize),
|
|
608189
|
+
category: "context"
|
|
608190
|
+
});
|
|
608191
|
+
entries.push({
|
|
608192
|
+
icon: "📊",
|
|
608193
|
+
label: "Context Used",
|
|
608194
|
+
value: fmtTokens2(snap.estimatedContextTokens),
|
|
608195
|
+
detail: `Utilization: ${fmtPct(snap.contextUtilizationPct)} · Peak: ${fmtTokens2(snap.peakContextTokens)}`,
|
|
608196
|
+
category: "context"
|
|
608197
|
+
});
|
|
608198
|
+
entries.push({
|
|
608199
|
+
icon: "🗜",
|
|
608200
|
+
label: "Compactions",
|
|
608201
|
+
value: String(snap.compactionCount),
|
|
608202
|
+
category: "context"
|
|
608203
|
+
});
|
|
608204
|
+
entries.push({
|
|
608205
|
+
icon: "🕐",
|
|
608206
|
+
label: "Session",
|
|
608207
|
+
value: fmtDuration(snap.sessionDurationMs),
|
|
608208
|
+
category: "session"
|
|
608209
|
+
});
|
|
608210
|
+
entries.push({
|
|
608211
|
+
icon: "🔄",
|
|
608212
|
+
label: "Turns",
|
|
608213
|
+
value: String(snap.turnCount),
|
|
608214
|
+
category: "session"
|
|
608215
|
+
});
|
|
608216
|
+
if (scope === "admin") {
|
|
608217
|
+
entries.push({
|
|
608218
|
+
icon: "🖥",
|
|
608219
|
+
label: "Backend",
|
|
608220
|
+
value: escapeHTML2(snap.backend),
|
|
608221
|
+
category: "system"
|
|
608222
|
+
});
|
|
608223
|
+
if (snap.gpuName) {
|
|
608224
|
+
entries.push({
|
|
608225
|
+
icon: "🎮",
|
|
608226
|
+
label: "GPU",
|
|
608227
|
+
value: escapeHTML2(snap.gpuName),
|
|
608228
|
+
category: "system"
|
|
608229
|
+
});
|
|
608230
|
+
}
|
|
608231
|
+
if (snap.gpuVramTotalMb != null) {
|
|
608232
|
+
const used = snap.gpuVramUsedMb ?? 0;
|
|
608233
|
+
entries.push({
|
|
608234
|
+
icon: "💾",
|
|
608235
|
+
label: "VRAM",
|
|
608236
|
+
value: `${Math.round(used)}/${Math.round(snap.gpuVramTotalMb)} MB`,
|
|
608237
|
+
detail: `Usage: ${fmtPct(used / snap.gpuVramTotalMb * 100)}`,
|
|
608238
|
+
category: "system"
|
|
608239
|
+
});
|
|
608240
|
+
}
|
|
608241
|
+
}
|
|
608242
|
+
return entries;
|
|
608243
|
+
}
|
|
608244
|
+
function encodeStatsCallback(action, value2) {
|
|
608245
|
+
return `${CB_PREFIX}${action}:${value2}`;
|
|
608246
|
+
}
|
|
608247
|
+
function decodeStatsCallback(data) {
|
|
608248
|
+
if (!data.startsWith(CB_PREFIX)) return null;
|
|
608249
|
+
const body = data.slice(CB_PREFIX.length);
|
|
608250
|
+
const colonIdx = body.indexOf(":");
|
|
608251
|
+
if (colonIdx === -1) return null;
|
|
608252
|
+
const action = body.slice(0, colonIdx);
|
|
608253
|
+
if (action !== "page" && action !== "close") return null;
|
|
608254
|
+
const value2 = parseInt(body.slice(colonIdx + 1), 10);
|
|
608255
|
+
if (isNaN(value2)) return null;
|
|
608256
|
+
return { action, value: value2 };
|
|
608257
|
+
}
|
|
608258
|
+
function buildStatsKeyboard(page2, totalPages, countdown) {
|
|
608259
|
+
const rows = [];
|
|
608260
|
+
const navRow = [];
|
|
608261
|
+
if (page2 === 0) {
|
|
608262
|
+
navRow.push({
|
|
608263
|
+
text: countdown != null ? `✖ Close (${countdown}s)` : "✖ Close",
|
|
608264
|
+
callback_data: encodeStatsCallback("close", 0)
|
|
608265
|
+
});
|
|
608266
|
+
}
|
|
608267
|
+
navRow.push({
|
|
608268
|
+
text: `${page2 + 1}/${totalPages}`,
|
|
608269
|
+
callback_data: encodeStatsCallback("page", page2)
|
|
608270
|
+
// current page = no-op refresh
|
|
608271
|
+
});
|
|
608272
|
+
if (page2 > 0) {
|
|
608273
|
+
navRow.unshift({ text: "◀️", callback_data: encodeStatsCallback("page", page2 - 1) });
|
|
608274
|
+
}
|
|
608275
|
+
if (page2 < totalPages - 1) {
|
|
608276
|
+
navRow.push({ text: "▶️", callback_data: encodeStatsCallback("page", page2 + 1) });
|
|
608277
|
+
}
|
|
608278
|
+
rows.push(navRow);
|
|
608279
|
+
return rows;
|
|
608280
|
+
}
|
|
608281
|
+
function buildStatsPageText(entries, page2, countdown) {
|
|
608282
|
+
const start2 = page2 * PAGE_SIZE;
|
|
608283
|
+
const pageEntries = entries.slice(start2, start2 + PAGE_SIZE);
|
|
608284
|
+
const lines = [];
|
|
608285
|
+
lines.push("<b>📊 Session Metrics</b>");
|
|
608286
|
+
lines.push("");
|
|
608287
|
+
let currentCategory = "";
|
|
608288
|
+
for (const e2 of pageEntries) {
|
|
608289
|
+
if (e2.category !== currentCategory) {
|
|
608290
|
+
currentCategory = e2.category;
|
|
608291
|
+
lines.push(`<b>${CATEGORY_LABELS2[e2.category]}</b>`);
|
|
608292
|
+
}
|
|
608293
|
+
let line = ` ${e2.icon} <b>${e2.label}:</b> ${e2.value}`;
|
|
608294
|
+
lines.push(line);
|
|
608295
|
+
if (e2.detail) {
|
|
608296
|
+
lines.push(` <i>${escapeHTML2(e2.detail)}</i>`);
|
|
608297
|
+
}
|
|
608298
|
+
}
|
|
608299
|
+
if (countdown != null) {
|
|
608300
|
+
lines.push("");
|
|
608301
|
+
lines.push(`<i>⏳ Auto-closing in ${countdown}s…</i>`);
|
|
608302
|
+
}
|
|
608303
|
+
return lines.join("\n");
|
|
608304
|
+
}
|
|
608305
|
+
function renderStatsMenu(scope, snapshot) {
|
|
608306
|
+
return renderStatsMenuPage(scope, 0, snapshot);
|
|
608307
|
+
}
|
|
608308
|
+
function renderStatsMenuPage(scope, page2, snapshot, countdown = null) {
|
|
608309
|
+
const entries = buildMetricEntries(snapshot, scope);
|
|
608310
|
+
const totalPages = Math.max(1, Math.ceil(entries.length / PAGE_SIZE));
|
|
608311
|
+
const safePage = Math.min(page2, totalPages - 1);
|
|
608312
|
+
const text = buildStatsPageText(entries, safePage, countdown);
|
|
608313
|
+
const keyboard = buildStatsKeyboard(safePage, totalPages, countdown);
|
|
608314
|
+
return { text, reply_markup: { inline_keyboard: keyboard } };
|
|
608315
|
+
}
|
|
608316
|
+
function handleStatsCallback(data, currentState, snapshot) {
|
|
608317
|
+
const decoded = decodeStatsCallback(data);
|
|
608318
|
+
if (!decoded) return null;
|
|
608319
|
+
switch (decoded.action) {
|
|
608320
|
+
case "page": {
|
|
608321
|
+
const page2 = decoded.value;
|
|
608322
|
+
const render2 = renderStatsMenuPage(currentState.scope, page2, snapshot);
|
|
608323
|
+
const newState = {
|
|
608324
|
+
...currentState,
|
|
608325
|
+
page: page2,
|
|
608326
|
+
lastInteractionAt: Date.now()
|
|
608327
|
+
};
|
|
608328
|
+
return { render: render2, newState };
|
|
608329
|
+
}
|
|
608330
|
+
case "close": {
|
|
608331
|
+
return { render: null, newState: currentState, close: true };
|
|
608332
|
+
}
|
|
608333
|
+
default:
|
|
608334
|
+
return null;
|
|
608335
|
+
}
|
|
608336
|
+
}
|
|
608337
|
+
var PAGE_SIZE, StatsMenuStateStore, CB_PREFIX, CATEGORY_LABELS2, INACTIVITY_TIMEOUT_MS2, COUNTDOWN_SECONDS2, StatsMenuTimerManager;
|
|
608338
|
+
var init_telegram_stats_menu = __esm({
|
|
608339
|
+
"packages/cli/src/tui/telegram-stats-menu.ts"() {
|
|
608340
|
+
"use strict";
|
|
608341
|
+
PAGE_SIZE = 6;
|
|
608342
|
+
StatsMenuStateStore = class {
|
|
608343
|
+
states = /* @__PURE__ */ new Map();
|
|
608344
|
+
key(chatId, messageId) {
|
|
608345
|
+
return `${chatId}:${messageId}`;
|
|
608346
|
+
}
|
|
608347
|
+
get(chatId, messageId) {
|
|
608348
|
+
return this.states.get(this.key(chatId, messageId));
|
|
608349
|
+
}
|
|
608350
|
+
set(state) {
|
|
608351
|
+
this.states.set(this.key(state.chatId, state.messageId), state);
|
|
608352
|
+
}
|
|
608353
|
+
delete(chatId, messageId) {
|
|
608354
|
+
this.states.delete(this.key(chatId, messageId));
|
|
608355
|
+
}
|
|
608356
|
+
prune(maxAgeMs) {
|
|
608357
|
+
const cutoff = Date.now() - maxAgeMs;
|
|
608358
|
+
for (const [k, v] of this.states) {
|
|
608359
|
+
if (v.lastInteractionAt < cutoff) this.states.delete(k);
|
|
608360
|
+
}
|
|
608361
|
+
}
|
|
608362
|
+
};
|
|
608363
|
+
CB_PREFIX = "st_";
|
|
608364
|
+
CATEGORY_LABELS2 = {
|
|
608365
|
+
inference: "🧠 Inference",
|
|
608366
|
+
tools: "🔧 Tools",
|
|
608367
|
+
context: "📐 Context",
|
|
608368
|
+
session: "🕐 Session",
|
|
608369
|
+
system: "🖥 System"
|
|
608370
|
+
};
|
|
608371
|
+
INACTIVITY_TIMEOUT_MS2 = 6e4;
|
|
608372
|
+
COUNTDOWN_SECONDS2 = 10;
|
|
608373
|
+
StatsMenuTimerManager = class {
|
|
608374
|
+
constructor(states, callbacks, getSnapshot) {
|
|
608375
|
+
this.states = states;
|
|
608376
|
+
this.callbacks = callbacks;
|
|
608377
|
+
this.getSnapshot = getSnapshot;
|
|
608378
|
+
}
|
|
608379
|
+
states;
|
|
608380
|
+
callbacks;
|
|
608381
|
+
getSnapshot;
|
|
608382
|
+
inactivityTimers = /* @__PURE__ */ new Map();
|
|
608383
|
+
countdownTimers = /* @__PURE__ */ new Map();
|
|
608384
|
+
countdownValues = /* @__PURE__ */ new Map();
|
|
608385
|
+
key(chatId, messageId) {
|
|
608386
|
+
return `${chatId}:${messageId}`;
|
|
608387
|
+
}
|
|
608388
|
+
startTimer(state) {
|
|
608389
|
+
this.resetTimer(state.chatId, state.messageId);
|
|
608390
|
+
}
|
|
608391
|
+
resetTimer(chatId, messageId) {
|
|
608392
|
+
const k = this.key(chatId, messageId);
|
|
608393
|
+
const existingInactivity = this.inactivityTimers.get(k);
|
|
608394
|
+
if (existingInactivity) clearTimeout(existingInactivity);
|
|
608395
|
+
this.cancelCountdown(chatId, messageId);
|
|
608396
|
+
this.inactivityTimers.set(
|
|
608397
|
+
k,
|
|
608398
|
+
setTimeout(() => {
|
|
608399
|
+
this.startCountdown(
|
|
608400
|
+
this.states.get(chatId, messageId) ?? {
|
|
608401
|
+
chatId,
|
|
608402
|
+
messageId,
|
|
608403
|
+
scope: "admin",
|
|
608404
|
+
page: 0,
|
|
608405
|
+
lastInteractionAt: Date.now()
|
|
608406
|
+
}
|
|
608407
|
+
);
|
|
608408
|
+
}, INACTIVITY_TIMEOUT_MS2)
|
|
608409
|
+
);
|
|
608410
|
+
}
|
|
608411
|
+
startCountdown(state) {
|
|
608412
|
+
const k = this.key(state.chatId, state.messageId);
|
|
608413
|
+
this.countdownValues.set(k, COUNTDOWN_SECONDS2);
|
|
608414
|
+
this.renderCountdown(state).catch(() => {
|
|
608415
|
+
});
|
|
608416
|
+
this.countdownTimers.set(
|
|
608417
|
+
k,
|
|
608418
|
+
setInterval(() => {
|
|
608419
|
+
const remaining = (this.countdownValues.get(k) ?? 0) - 1;
|
|
608420
|
+
if (remaining <= 0) {
|
|
608421
|
+
this.deleteMenu(state.chatId, state.messageId);
|
|
608422
|
+
return;
|
|
608423
|
+
}
|
|
608424
|
+
this.countdownValues.set(k, remaining);
|
|
608425
|
+
this.renderCountdown(state).catch(() => {
|
|
608426
|
+
});
|
|
608427
|
+
}, 1e3)
|
|
608428
|
+
);
|
|
608429
|
+
}
|
|
608430
|
+
cancelCountdown(chatId, messageId) {
|
|
608431
|
+
const k = this.key(chatId, messageId);
|
|
608432
|
+
const timer = this.countdownTimers.get(k);
|
|
608433
|
+
if (timer) {
|
|
608434
|
+
clearInterval(timer);
|
|
608435
|
+
this.countdownTimers.delete(k);
|
|
608436
|
+
this.countdownValues.delete(k);
|
|
608437
|
+
}
|
|
608438
|
+
}
|
|
608439
|
+
async renderCountdown(state) {
|
|
608440
|
+
const k = this.key(state.chatId, state.messageId);
|
|
608441
|
+
const countdown = this.countdownValues.get(k) ?? null;
|
|
608442
|
+
const snap = this.getSnapshot();
|
|
608443
|
+
const entries = buildMetricEntries(snap, state.scope);
|
|
608444
|
+
const totalPages = Math.max(1, Math.ceil(entries.length / PAGE_SIZE));
|
|
608445
|
+
const text = buildStatsPageText(entries, state.page, countdown);
|
|
608446
|
+
const keyboard = buildStatsKeyboard(state.page, totalPages, countdown);
|
|
608447
|
+
try {
|
|
608448
|
+
await this.callbacks.editMessageText(state.chatId, state.messageId, text, {
|
|
608449
|
+
inline_keyboard: keyboard
|
|
608450
|
+
});
|
|
608451
|
+
} catch {
|
|
608452
|
+
}
|
|
608453
|
+
}
|
|
608454
|
+
async deleteMenu(chatId, messageId) {
|
|
608455
|
+
const k = this.key(chatId, messageId);
|
|
608456
|
+
this.cancelCountdown(chatId, messageId);
|
|
608457
|
+
const inactivity = this.inactivityTimers.get(k);
|
|
608458
|
+
if (inactivity) clearTimeout(inactivity);
|
|
608459
|
+
this.inactivityTimers.delete(k);
|
|
608460
|
+
this.states.delete(chatId, messageId);
|
|
608461
|
+
try {
|
|
608462
|
+
await this.callbacks.deleteMessage(chatId, messageId);
|
|
608463
|
+
} catch {
|
|
608464
|
+
}
|
|
608465
|
+
}
|
|
608466
|
+
};
|
|
607951
608467
|
}
|
|
607952
608468
|
});
|
|
607953
608469
|
|
|
@@ -611623,6 +612139,8 @@ function splitTelegramReminderDue(raw) {
|
|
|
611623
612139
|
function telegramSyntheticHelpSignatures2() {
|
|
611624
612140
|
return [
|
|
611625
612141
|
{ signature: "/help", description: "Show Telegram command help" },
|
|
612142
|
+
{ signature: "/stats", description: "Show session metrics and inference statistics" },
|
|
612143
|
+
{ signature: "/metrics", description: "Alias for /stats — show session metrics" },
|
|
611626
612144
|
{ signature: "/start", description: "Show Telegram bridge status and authentication instructions" },
|
|
611627
612145
|
{ signature: "/auth <code>", description: "Authenticate this Telegram user as bot admin using the TUI code" },
|
|
611628
612146
|
{ signature: "/call", description: "Get the active voice call link when a call session is running" },
|
|
@@ -612368,6 +612886,7 @@ var init_telegram_bridge = __esm({
|
|
|
612368
612886
|
init_media_routing();
|
|
612369
612887
|
init_command_registry();
|
|
612370
612888
|
init_telegram_help_menu();
|
|
612889
|
+
init_telegram_stats_menu();
|
|
612371
612890
|
init_scoped_personality();
|
|
612372
612891
|
init_telegram_creative_tools();
|
|
612373
612892
|
init_omnius_directory();
|
|
@@ -612830,8 +613349,16 @@ External acquisition contract:
|
|
|
612830
613349
|
telegramToolButtonDir;
|
|
612831
613350
|
/** Interactive help menu state store (inline keyboard navigation) */
|
|
612832
613351
|
helpMenuStates = new HelpMenuStateStore();
|
|
613352
|
+
/** Auto-close timer manager for help menus (inactivity → countdown → delete) */
|
|
613353
|
+
helpMenuTimers = null;
|
|
612833
613354
|
/** Prune expired help menu states every 5 minutes */
|
|
612834
613355
|
helpMenuPruneTimer = null;
|
|
613356
|
+
/** Interactive stats menu state store (inline keyboard navigation) */
|
|
613357
|
+
statsMenuStates = new StatsMenuStateStore();
|
|
613358
|
+
/** Auto-close timer manager for stats menus (inactivity → countdown → delete) */
|
|
613359
|
+
statsMenuTimers = null;
|
|
613360
|
+
/** Prune expired stats menu states every 5 minutes */
|
|
613361
|
+
statsMenuPruneTimer = null;
|
|
612835
613362
|
/** Command handler for admin DM slash commands (wired from interactive.ts) */
|
|
612836
613363
|
commandHandler = null;
|
|
612837
613364
|
/** Callback fired after a Telegram user completes the TUI-only admin auth challenge */
|
|
@@ -612841,7 +613368,9 @@ External acquisition contract:
|
|
|
612841
613368
|
/** Telegram command menu names mapped back to canonical TUI command names. */
|
|
612842
613369
|
telegramCommandMap = /* @__PURE__ */ new Map([
|
|
612843
613370
|
["auth", "auth"],
|
|
612844
|
-
["start", "start"]
|
|
613371
|
+
["start", "start"],
|
|
613372
|
+
["stats", "stats"],
|
|
613373
|
+
["metrics", "stats"]
|
|
612845
613374
|
]);
|
|
612846
613375
|
/** TUI agent-view callbacks for Telegram sub-agent registration. */
|
|
612847
613376
|
subAgentViewCallbacks = null;
|
|
@@ -613116,6 +613645,10 @@ External acquisition contract:
|
|
|
613116
613645
|
const name10 = this.telegramSlashName(input);
|
|
613117
613646
|
return name10 === "help" || name10 === "h" || name10 === "commands" || name10 === "cmds";
|
|
613118
613647
|
}
|
|
613648
|
+
isTelegramStatsCommand(input) {
|
|
613649
|
+
const name10 = this.telegramSlashName(input);
|
|
613650
|
+
return name10 === "stats" || name10 === "metrics";
|
|
613651
|
+
}
|
|
613119
613652
|
isKnownTelegramSlash(input) {
|
|
613120
613653
|
const first2 = input.trim().split(/\s+/)[0] ?? "";
|
|
613121
613654
|
const botless = first2.startsWith("/") ? first2.slice(1).split("@")[0]?.toLowerCase() : "";
|
|
@@ -613267,7 +613800,7 @@ No scoped reflection artifact exists yet for this chat. Use <code>/reflect</code
|
|
|
613267
613800
|
...msg.chatType !== "private" ? { reply_to_message_id: msg.messageId } : {}
|
|
613268
613801
|
});
|
|
613269
613802
|
if (sent.ok && sent.result?.message_id) {
|
|
613270
|
-
|
|
613803
|
+
const state = {
|
|
613271
613804
|
chatId: msg.chatId,
|
|
613272
613805
|
messageId: sent.result.message_id,
|
|
613273
613806
|
scope,
|
|
@@ -613275,8 +613808,119 @@ No scoped reflection artifact exists yet for this chat. Use <code>/reflect</code
|
|
|
613275
613808
|
view: "list",
|
|
613276
613809
|
detailToolName: null,
|
|
613277
613810
|
fromUserId: msg.fromUserId ?? 0,
|
|
613278
|
-
createdAt: Date.now()
|
|
613279
|
-
|
|
613811
|
+
createdAt: Date.now(),
|
|
613812
|
+
lastInteractionAt: Date.now(),
|
|
613813
|
+
countdownValue: null
|
|
613814
|
+
};
|
|
613815
|
+
this.helpMenuStates.set(state);
|
|
613816
|
+
if (!this.helpMenuTimers) {
|
|
613817
|
+
this.helpMenuTimers = new HelpMenuTimerManager(this.helpMenuStates, {
|
|
613818
|
+
editMessageText: async (chatId, messageId, text, replyMarkup) => {
|
|
613819
|
+
await this.apiCall("editMessageText", {
|
|
613820
|
+
chat_id: chatId,
|
|
613821
|
+
message_id: messageId,
|
|
613822
|
+
text,
|
|
613823
|
+
parse_mode: "HTML",
|
|
613824
|
+
reply_markup: JSON.stringify(replyMarkup)
|
|
613825
|
+
});
|
|
613826
|
+
},
|
|
613827
|
+
deleteMessage: async (chatId, messageId) => {
|
|
613828
|
+
await this.apiCall("deleteMessage", {
|
|
613829
|
+
chat_id: chatId,
|
|
613830
|
+
message_id: messageId
|
|
613831
|
+
});
|
|
613832
|
+
}
|
|
613833
|
+
});
|
|
613834
|
+
}
|
|
613835
|
+
this.helpMenuTimers.startTimer(state);
|
|
613836
|
+
}
|
|
613837
|
+
}
|
|
613838
|
+
collectSessionMetricsSnapshot() {
|
|
613839
|
+
const snap = emptySnapshot();
|
|
613840
|
+
try {
|
|
613841
|
+
const runner = this.activeRunner;
|
|
613842
|
+
if (runner) {
|
|
613843
|
+
snap.model = runner.model ?? runner.modelName ?? "unknown";
|
|
613844
|
+
snap.backend = runner.backend ?? "ollama";
|
|
613845
|
+
snap.totalInferences = runner.inferenceCount ?? runner.totalInferences ?? 0;
|
|
613846
|
+
snap.totalPromptTokens = runner.totalPromptTokens ?? 0;
|
|
613847
|
+
snap.totalCompletionTokens = runner.totalCompletionTokens ?? 0;
|
|
613848
|
+
snap.totalTokens = snap.totalPromptTokens + snap.totalCompletionTokens;
|
|
613849
|
+
snap.totalInferenceDurationMs = runner.totalInferenceDurationMs ?? 0;
|
|
613850
|
+
snap.avgInferenceDurationMs = snap.totalInferences > 0 ? snap.totalInferenceDurationMs / snap.totalInferences : 0;
|
|
613851
|
+
snap.avgTokensPerSecond = runner.avgTokensPerSecond ?? 0;
|
|
613852
|
+
snap.peakTokensPerSecond = runner.peakTokensPerSecond ?? 0;
|
|
613853
|
+
snap.totalToolCalls = runner.toolCallCount ?? runner.totalToolCalls ?? 0;
|
|
613854
|
+
snap.successfulToolCalls = runner.successfulToolCalls ?? snap.totalToolCalls;
|
|
613855
|
+
snap.failedToolCalls = runner.failedToolCalls ?? 0;
|
|
613856
|
+
snap.toolCallBreakdown = runner.toolCallBreakdown ?? [];
|
|
613857
|
+
snap.contextWindowSize = runner.contextWindowSize ?? runner.maxContextTokens ?? 0;
|
|
613858
|
+
snap.estimatedContextTokens = runner.estimatedContextTokens ?? runner.latestEstimatedContextTokens ?? 0;
|
|
613859
|
+
snap.peakContextTokens = runner.peakEstimatedContextTokens ?? snap.estimatedContextTokens;
|
|
613860
|
+
snap.contextUtilizationPct = snap.contextWindowSize > 0 ? snap.estimatedContextTokens / snap.contextWindowSize * 100 : 0;
|
|
613861
|
+
snap.turnCount = runner.turnCount ?? 0;
|
|
613862
|
+
snap.compactionCount = runner.compactionCount ?? 0;
|
|
613863
|
+
snap.sessionStartAt = runner.sessionStartAt ?? Date.now();
|
|
613864
|
+
snap.sessionDurationMs = Date.now() - snap.sessionStartAt;
|
|
613865
|
+
}
|
|
613866
|
+
const env2 = this.envInfo;
|
|
613867
|
+
if (env2) {
|
|
613868
|
+
snap.gpuName = env2.gpuName ?? env2.gpu ?? null;
|
|
613869
|
+
snap.gpuVramUsedMb = env2.gpuVramUsedMb ?? env2.vramUsedMb ?? null;
|
|
613870
|
+
snap.gpuVramTotalMb = env2.gpuVramTotalMb ?? env2.vramTotalMb ?? null;
|
|
613871
|
+
}
|
|
613872
|
+
} catch {
|
|
613873
|
+
}
|
|
613874
|
+
if (snap.sessionDurationMs === 0 && snap.sessionStartAt > 0) {
|
|
613875
|
+
snap.sessionDurationMs = Date.now() - snap.sessionStartAt;
|
|
613876
|
+
}
|
|
613877
|
+
return snap;
|
|
613878
|
+
}
|
|
613879
|
+
async replyWithTelegramStats(msg, isAdmin) {
|
|
613880
|
+
const scope = isAdmin ? "admin" : "public";
|
|
613881
|
+
const snapshot = this.collectSessionMetricsSnapshot();
|
|
613882
|
+
const menu = renderStatsMenu(scope, snapshot);
|
|
613883
|
+
if (msg.guestQueryId) {
|
|
613884
|
+
const plainText = menu.text.replace(/<[^>]+>/g, "");
|
|
613885
|
+
await this.answerGuestQuery(msg.guestQueryId, plainText, { parseMode: "HTML" });
|
|
613886
|
+
return;
|
|
613887
|
+
}
|
|
613888
|
+
const sent = await this.apiCall("sendMessage", {
|
|
613889
|
+
chat_id: msg.chatId,
|
|
613890
|
+
text: menu.text,
|
|
613891
|
+
parse_mode: "HTML",
|
|
613892
|
+
reply_markup: JSON.stringify(menu.reply_markup),
|
|
613893
|
+
...msg.chatType !== "private" ? { reply_to_message_id: msg.messageId } : {}
|
|
613894
|
+
});
|
|
613895
|
+
if (sent.ok && sent.result?.message_id) {
|
|
613896
|
+
const state = {
|
|
613897
|
+
chatId: msg.chatId,
|
|
613898
|
+
messageId: sent.result.message_id,
|
|
613899
|
+
scope,
|
|
613900
|
+
page: 0,
|
|
613901
|
+
lastInteractionAt: Date.now()
|
|
613902
|
+
};
|
|
613903
|
+
this.statsMenuStates.set(state);
|
|
613904
|
+
if (!this.statsMenuTimers) {
|
|
613905
|
+
this.statsMenuTimers = new StatsMenuTimerManager(this.statsMenuStates, {
|
|
613906
|
+
editMessageText: async (chatId, messageId, text, replyMarkup) => {
|
|
613907
|
+
await this.apiCall("editMessageText", {
|
|
613908
|
+
chat_id: chatId,
|
|
613909
|
+
message_id: messageId,
|
|
613910
|
+
text,
|
|
613911
|
+
parse_mode: "HTML",
|
|
613912
|
+
reply_markup: JSON.stringify(replyMarkup)
|
|
613913
|
+
});
|
|
613914
|
+
},
|
|
613915
|
+
deleteMessage: async (chatId, messageId) => {
|
|
613916
|
+
await this.apiCall("deleteMessage", {
|
|
613917
|
+
chat_id: chatId,
|
|
613918
|
+
message_id: messageId
|
|
613919
|
+
});
|
|
613920
|
+
}
|
|
613921
|
+
}, () => this.collectSessionMetricsSnapshot());
|
|
613922
|
+
}
|
|
613923
|
+
this.statsMenuTimers.startTimer(state);
|
|
613280
613924
|
}
|
|
613281
613925
|
}
|
|
613282
613926
|
recordChatHistory(sessionKey, entry) {
|
|
@@ -617040,6 +617684,10 @@ ${TELEGRAM_PUBLIC_ORCHESTRATOR_CONTRACT}`);
|
|
|
617040
617684
|
await this.replyWithTelegramHelp(msg, isAdmin);
|
|
617041
617685
|
return;
|
|
617042
617686
|
}
|
|
617687
|
+
if (msg.text.trim().startsWith("/") && this.isTelegramStatsCommand(normalizedCommandText)) {
|
|
617688
|
+
await this.replyWithTelegramStats(msg, isAdmin);
|
|
617689
|
+
return;
|
|
617690
|
+
}
|
|
617043
617691
|
const telegramSlash = this.telegramSlashName(normalizedCommandText);
|
|
617044
617692
|
if (msg.text.trim().startsWith("/") && TELEGRAM_REFLECTION_SLASH_COMMANDS.has(telegramSlash)) {
|
|
617045
617693
|
await this.handleTelegramReflectionSlash(msg, normalizedCommandText);
|
|
@@ -619619,7 +620267,21 @@ Scoped workspace: ${scopedRoot}`,
|
|
|
619619
620267
|
alert2 = true;
|
|
619620
620268
|
return;
|
|
619621
620269
|
}
|
|
620270
|
+
if (result.close) {
|
|
620271
|
+
this.helpMenuStates.delete(chatId, messageId);
|
|
620272
|
+
this.helpMenuTimers?.deleteMenu(chatId, messageId);
|
|
620273
|
+
try {
|
|
620274
|
+
await this.apiCall("deleteMessage", {
|
|
620275
|
+
chat_id: chatId,
|
|
620276
|
+
message_id: messageId
|
|
620277
|
+
});
|
|
620278
|
+
} catch {
|
|
620279
|
+
}
|
|
620280
|
+
await this.answerCallbackQuery(callback.id).catch(() => false);
|
|
620281
|
+
return;
|
|
620282
|
+
}
|
|
619622
620283
|
this.helpMenuStates.set(result.newState);
|
|
620284
|
+
this.helpMenuTimers?.resetTimer(chatId, messageId);
|
|
619623
620285
|
await this.apiCall("editMessageText", {
|
|
619624
620286
|
chat_id: chatId,
|
|
619625
620287
|
message_id: messageId,
|
|
@@ -619640,6 +620302,72 @@ Scoped workspace: ${scopedRoot}`,
|
|
|
619640
620302
|
}
|
|
619641
620303
|
return;
|
|
619642
620304
|
}
|
|
620305
|
+
const statsDecoded = decodeStatsCallback(callback.data);
|
|
620306
|
+
if (statsDecoded) {
|
|
620307
|
+
let answerText2 = "";
|
|
620308
|
+
let alert2 = false;
|
|
620309
|
+
try {
|
|
620310
|
+
const chatId = callback.chatId;
|
|
620311
|
+
const messageId = callback.messageId;
|
|
620312
|
+
if (!chatId || !messageId) {
|
|
620313
|
+
answerText2 = "Cannot identify menu message.";
|
|
620314
|
+
alert2 = true;
|
|
620315
|
+
return;
|
|
620316
|
+
}
|
|
620317
|
+
const menuState = this.statsMenuStates.get(chatId, messageId);
|
|
620318
|
+
if (!menuState) {
|
|
620319
|
+
answerText2 = "This stats menu expired. Send /stats for a fresh one.";
|
|
620320
|
+
alert2 = true;
|
|
620321
|
+
return;
|
|
620322
|
+
}
|
|
620323
|
+
const isAdmin = this.isAdminActor(callback.fromUserId, callback.username);
|
|
620324
|
+
if (!isAdmin && menuState.scope === "admin") {
|
|
620325
|
+
answerText2 = "Only admin can interact with this menu.";
|
|
620326
|
+
alert2 = true;
|
|
620327
|
+
return;
|
|
620328
|
+
}
|
|
620329
|
+
const snapshot = this.collectSessionMetricsSnapshot();
|
|
620330
|
+
const result = handleStatsCallback(callback.data, menuState, snapshot);
|
|
620331
|
+
if (!result) {
|
|
620332
|
+
answerText2 = "Unknown menu action.";
|
|
620333
|
+
alert2 = true;
|
|
620334
|
+
return;
|
|
620335
|
+
}
|
|
620336
|
+
if (result.close) {
|
|
620337
|
+
this.statsMenuStates.delete(chatId, messageId);
|
|
620338
|
+
this.statsMenuTimers?.deleteMenu(chatId, messageId);
|
|
620339
|
+
try {
|
|
620340
|
+
await this.apiCall("deleteMessage", {
|
|
620341
|
+
chat_id: chatId,
|
|
620342
|
+
message_id: messageId
|
|
620343
|
+
});
|
|
620344
|
+
} catch {
|
|
620345
|
+
}
|
|
620346
|
+
await this.answerCallbackQuery(callback.id).catch(() => false);
|
|
620347
|
+
return;
|
|
620348
|
+
}
|
|
620349
|
+
this.statsMenuStates.set(result.newState);
|
|
620350
|
+
this.statsMenuTimers?.resetTimer(chatId, messageId);
|
|
620351
|
+
await this.apiCall("editMessageText", {
|
|
620352
|
+
chat_id: chatId,
|
|
620353
|
+
message_id: messageId,
|
|
620354
|
+
text: result.render.text,
|
|
620355
|
+
parse_mode: "HTML",
|
|
620356
|
+
reply_markup: JSON.stringify(result.render.reply_markup)
|
|
620357
|
+
});
|
|
620358
|
+
answerText2 = "";
|
|
620359
|
+
} catch (err) {
|
|
620360
|
+
answerText2 = err instanceof Error ? err.message : String(err);
|
|
620361
|
+
alert2 = true;
|
|
620362
|
+
} finally {
|
|
620363
|
+
if (answerText2) {
|
|
620364
|
+
await this.answerCallbackQuery(callback.id, answerText2.slice(0, 180), alert2).catch(() => false);
|
|
620365
|
+
} else {
|
|
620366
|
+
await this.answerCallbackQuery(callback.id).catch(() => false);
|
|
620367
|
+
}
|
|
620368
|
+
}
|
|
620369
|
+
return;
|
|
620370
|
+
}
|
|
619643
620371
|
let answerText = "Updated.";
|
|
619644
620372
|
let alert = false;
|
|
619645
620373
|
try {
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "omnius",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.87",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "omnius",
|
|
9
|
-
"version": "1.0.
|
|
9
|
+
"version": "1.0.87",
|
|
10
10
|
"bundleDependencies": [
|
|
11
11
|
"image-to-ascii"
|
|
12
12
|
],
|
package/package.json
CHANGED