telecoder 0.0.0-stage → 1.3.0
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/.env.example +375 -0
- package/CHANGELOG.md +1867 -0
- package/LICENSE +22 -0
- package/README.md +130 -2
- package/dist/audio/transcribe.js +41 -0
- package/dist/bin/mcp-server.js +363 -0
- package/dist/bin/tool-result.js +22 -0
- package/dist/bot/access/group-access.js +147 -0
- package/dist/bot/bot.js +573 -0
- package/dist/bot/command-catalog.js +263 -0
- package/dist/bot/deleted-threads.js +103 -0
- package/dist/bot/file-access.js +150 -0
- package/dist/bot/handlers/album.handler.js +128 -0
- package/dist/bot/handlers/branch.handler.js +1096 -0
- package/dist/bot/handlers/command/access.js +407 -0
- package/dist/bot/handlers/command/admin.js +803 -0
- package/dist/bot/handlers/command/all-view.js +33 -0
- package/dist/bot/handlers/command/auto-approve.js +138 -0
- package/dist/bot/handlers/command/background.js +37 -0
- package/dist/bot/handlers/command/botname.js +76 -0
- package/dist/bot/handlers/command/btw.js +175 -0
- package/dist/bot/handlers/command/cleanup.js +329 -0
- package/dist/bot/handlers/command/model.js +226 -0
- package/dist/bot/handlers/command/prefs-scope.js +362 -0
- package/dist/bot/handlers/command/project.js +458 -0
- package/dist/bot/handlers/command/resume.js +325 -0
- package/dist/bot/handlers/command/session.js +299 -0
- package/dist/bot/handlers/command/settings.js +657 -0
- package/dist/bot/handlers/command/shared.js +207 -0
- package/dist/bot/handlers/command/tasks.js +681 -0
- package/dist/bot/handlers/command/thread.js +128 -0
- package/dist/bot/handlers/command/topic-store.js +74 -0
- package/dist/bot/handlers/command/topic.js +27 -0
- package/dist/bot/handlers/command/usage.js +382 -0
- package/dist/bot/handlers/command-fallback.js +179 -0
- package/dist/bot/handlers/command.handler.js +446 -0
- package/dist/bot/handlers/loop.handler.js +389 -0
- package/dist/bot/handlers/media-fallback.js +126 -0
- package/dist/bot/handlers/message/replies.js +56 -0
- package/dist/bot/handlers/message/shared.js +95 -0
- package/dist/bot/handlers/message/turn-notify.js +135 -0
- package/dist/bot/handlers/message/turn-runner.js +56 -0
- package/dist/bot/handlers/message.handler.js +114 -0
- package/dist/bot/handlers/newbot.handler.js +230 -0
- package/dist/bot/handlers/photo.handler.js +286 -0
- package/dist/bot/handlers/prompts.handler.js +343 -0
- package/dist/bot/handlers/running-note.js +44 -0
- package/dist/bot/handlers/session-guard.js +78 -0
- package/dist/bot/handlers/suggestion.handler.js +84 -0
- package/dist/bot/handlers/tree.handler.js +480 -0
- package/dist/bot/handlers/view.js +41 -0
- package/dist/bot/handlers/voice.handler.js +147 -0
- package/dist/bot/kept-threads.js +51 -0
- package/dist/bot/middleware/admin-only.js +49 -0
- package/dist/bot/middleware/album-collector.js +69 -0
- package/dist/bot/middleware/auth.middleware.js +122 -0
- package/dist/bot/middleware/group-mention.middleware.js +145 -0
- package/dist/bot/middleware/group-role.middleware.js +75 -0
- package/dist/bot/middleware/message-batcher.js +87 -0
- package/dist/bot/middleware/queued-messages.js +1082 -0
- package/dist/bot/middleware/stale-filter.js +9 -0
- package/dist/build-info.json +8 -0
- package/dist/claude/ask-user-form.js +517 -0
- package/dist/claude/ask-user.js +363 -0
- package/dist/claude/auto-approve.js +225 -0
- package/dist/claude/auto-topic-haiku.js +143 -0
- package/dist/claude/available-commands.js +156 -0
- package/dist/claude/background-hint.js +91 -0
- package/dist/claude/branch-tree.js +393 -0
- package/dist/claude/carry-over.js +25 -0
- package/dist/claude/ccr-shim.js +48 -0
- package/dist/claude/charter-judge.js +214 -0
- package/dist/claude/claude-auth.js +117 -0
- package/dist/claude/command-parser.js +206 -0
- package/dist/claude/cost-overlay-scraper.js +134 -0
- package/dist/claude/effort-level.js +5 -0
- package/dist/claude/enabled-plugins.js +52 -0
- package/dist/claude/in-flight-tracker.js +82 -0
- package/dist/claude/ipc-server.js +192 -0
- package/dist/claude/mcp-bridge.js +481 -0
- package/dist/claude/memory-guard.js +400 -0
- package/dist/claude/message-offsets.js +88 -0
- package/dist/claude/modal-relay.js +817 -0
- package/dist/claude/model-catalog.js +102 -0
- package/dist/claude/monitor-relay.js +712 -0
- package/dist/claude/native-commands.js +40 -0
- package/dist/claude/pending-branches.js +93 -0
- package/dist/claude/pending-suggestions.js +50 -0
- package/dist/claude/permission-gate.js +338 -0
- package/dist/claude/permission-mode.js +152 -0
- package/dist/claude/poll-user.js +51 -0
- package/dist/claude/prewarm.js +70 -0
- package/dist/claude/project-commands.js +69 -0
- package/dist/claude/prompt-hold.js +124 -0
- package/dist/claude/prompt-suggestion-scraper.js +89 -0
- package/dist/claude/pty-idle-reaper.js +96 -0
- package/dist/claude/pty-provider.js +2499 -0
- package/dist/claude/pty-spawn-config.js +343 -0
- package/dist/claude/pty-stream.js +363 -0
- package/dist/claude/pty-watch.js +201 -0
- package/dist/claude/request-queue.js +107 -0
- package/dist/claude/rewind.js +111 -0
- package/dist/claude/scheduled-runner.js +89 -0
- package/dist/claude/scheduler.js +241 -0
- package/dist/claude/scope-guard.js +279 -0
- package/dist/claude/screen-marks.js +83 -0
- package/dist/claude/screen-render.js +96 -0
- package/dist/claude/secret-request.js +576 -0
- package/dist/claude/session-history.js +288 -0
- package/dist/claude/session-jsonl.js +1067 -0
- package/dist/claude/session-manager.js +216 -0
- package/dist/claude/session-move.js +70 -0
- package/dist/claude/session-scan.js +270 -0
- package/dist/claude/setup-token.js +285 -0
- package/dist/claude/shell-mode-gate.js +60 -0
- package/dist/claude/side-call-options.js +45 -0
- package/dist/claude/side-question.js +252 -0
- package/dist/claude/stage-images.js +62 -0
- package/dist/claude/subagent-tools.js +12 -0
- package/dist/claude/synthetic-ctx.js +51 -0
- package/dist/claude/tasks-overlay-scraper.js +217 -0
- package/dist/claude/thread-judge-haiku.js +88 -0
- package/dist/claude/tip-scraper.js +77 -0
- package/dist/claude/tui-modal.js +746 -0
- package/dist/claude/tui-state.js +456 -0
- package/dist/claude/turn-end.js +105 -0
- package/dist/claude/turn-prose.js +64 -0
- package/dist/claude/typed-answer.js +104 -0
- package/dist/claude/update-banner-relay.js +70 -0
- package/dist/cli/commands/doctor.js +338 -0
- package/dist/cli/commands/help.js +34 -0
- package/dist/cli/commands/init.js +126 -0
- package/dist/cli/commands/service.js +710 -0
- package/dist/cli/commands/start.js +63 -0
- package/dist/cli/commands/version.js +11 -0
- package/dist/cli/commands/watch.js +322 -0
- package/dist/cli/dispatch.js +84 -0
- package/dist/cli/init/env-file.js +99 -0
- package/dist/cli/init/flow.js +705 -0
- package/dist/cli/init/prompter.js +124 -0
- package/dist/cli/init/telegram.js +120 -0
- package/dist/cli/service/render.js +212 -0
- package/dist/cli.js +18 -0
- package/dist/config-report.js +107 -0
- package/dist/config.js +525 -0
- package/dist/index.js +443 -0
- package/dist/launcher.js +960 -0
- package/dist/node-version-check.js +27 -0
- package/dist/providers/ccr-health.js +119 -0
- package/dist/providers/ccr-introspect.js +142 -0
- package/dist/providers/ccr-provider.js +59 -0
- package/dist/providers/claude-provider.js +10 -0
- package/dist/providers/prefs-sync.js +121 -0
- package/dist/providers/project-favorites.js +74 -0
- package/dist/providers/provider-router.js +128 -0
- package/dist/providers/provider-switch.js +91 -0
- package/dist/providers/spawn-settings.js +45 -0
- package/dist/providers/types.js +8 -0
- package/dist/providers/user-preferences.js +322 -0
- package/dist/restart-when-idle.js +173 -0
- package/dist/startup/auto-continue.js +67 -0
- package/dist/startup/auto-resume.js +161 -0
- package/dist/startup/notices.js +120 -0
- package/dist/startup/shared.js +44 -0
- package/dist/startup/verify-token.js +31 -0
- package/dist/telegram/access-request.js +153 -0
- package/dist/telegram/action-logger.js +522 -0
- package/dist/telegram/admin-mention.js +107 -0
- package/dist/telegram/background-activity-card.js +502 -0
- package/dist/telegram/botname-settings.js +282 -0
- package/dist/telegram/button-text.js +26 -0
- package/dist/telegram/client-options.js +26 -0
- package/dist/telegram/deduplication.js +33 -0
- package/dist/telegram/entities.js +295 -0
- package/dist/telegram/force-reply-tracker.js +96 -0
- package/dist/telegram/lettered-options.js +87 -0
- package/dist/telegram/markdown.js +362 -0
- package/dist/telegram/message-sender.js +1019 -0
- package/dist/telegram/prompt-label.js +148 -0
- package/dist/telegram/prompt-suggestion.js +54 -0
- package/dist/telegram/send.js +123 -0
- package/dist/telegram/streaming-turn.js +103 -0
- package/dist/telegram/suggestions-settings.js +30 -0
- package/dist/telegram/table-lists.js +56 -0
- package/dist/telegram/task-list.js +367 -0
- package/dist/telegram/task-tracker.js +128 -0
- package/dist/telegram/terminal-renderer.js +667 -0
- package/dist/telegram/thread-titles.js +262 -0
- package/dist/telegram/threads-setup.js +117 -0
- package/dist/utils/admins.js +143 -0
- package/dist/utils/agent-timer.js +55 -0
- package/dist/utils/atomic-write.js +24 -0
- package/dist/utils/bot-icon.js +248 -0
- package/dist/utils/bot-token.js +77 -0
- package/dist/utils/bounded-map.js +55 -0
- package/dist/utils/build-info.js +57 -0
- package/dist/utils/caffeinate.js +53 -0
- package/dist/utils/claude-env.js +53 -0
- package/dist/utils/claude-version.js +48 -0
- package/dist/utils/config-home.js +62 -0
- package/dist/utils/download.js +137 -0
- package/dist/utils/exit-codes.js +59 -0
- package/dist/utils/file-type.js +149 -0
- package/dist/utils/format.js +78 -0
- package/dist/utils/home-project.js +30 -0
- package/dist/utils/host-stall.js +51 -0
- package/dist/utils/id-list.js +44 -0
- package/dist/utils/idle-restart.js +92 -0
- package/dist/utils/install-mode.js +63 -0
- package/dist/utils/instance-config.js +148 -0
- package/dist/utils/instances.js +95 -0
- package/dist/utils/json-store.js +140 -0
- package/dist/utils/keyed-settings.js +62 -0
- package/dist/utils/legacy-env.js +35 -0
- package/dist/utils/memory-pressure.js +60 -0
- package/dist/utils/npm-version.js +134 -0
- package/dist/utils/prefs-relay.js +107 -0
- package/dist/utils/proc-children.js +102 -0
- package/dist/utils/resolve-bin.js +86 -0
- package/dist/utils/resolve-claude-bin.js +52 -0
- package/dist/utils/respawn-backoff.js +28 -0
- package/dist/utils/sanitize.js +91 -0
- package/dist/utils/session-key.js +37 -0
- package/dist/utils/stale-launcher.js +109 -0
- package/dist/utils/state-dir-migration.js +92 -0
- package/dist/utils/systemd.js +126 -0
- package/dist/utils/telegram-proxy.js +72 -0
- package/dist/utils/uploads-dir.js +27 -0
- package/dist/utils/user-roster.js +275 -0
- package/dist/utils/verbosity.js +118 -0
- package/dist/utils/version-check.js +166 -0
- package/dist/utils/workspace-guard.js +44 -0
- package/dist/worker-restart.js +141 -0
- package/instances.json.example +41 -0
- package/package.json +75 -4
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* /threadcleanup: delete the threads of a private chat that are done with, in one go.
|
|
3
|
+
*
|
|
4
|
+
* Telegram can't list a chat's threads to a bot, but the chat history has one
|
|
5
|
+
* entry per thread the bot has had a session in, with when it was last used.
|
|
6
|
+
* That's the list. A thread is left alone when deleting it could lose
|
|
7
|
+
* something: the thread /threadcleanup is sent in, a kept one (/threadkeep), one with a
|
|
8
|
+
* turn running, messages waiting or one set aside, a background task, a
|
|
9
|
+
* schedule, or one used more recently than the idle threshold (2 days, or
|
|
10
|
+
* what `/threadcleanup 7d` says).
|
|
11
|
+
*
|
|
12
|
+
* The rest are offered as a list of buttons to tick, and Haiku reads the end of
|
|
13
|
+
* each to guess which still have loose ends: those start unticked, marked ⚠️.
|
|
14
|
+
* Nothing goes until the Delete tap, and every thread is checked again then,
|
|
15
|
+
* since one may have come back to life in the meantime. Each is deleted the
|
|
16
|
+
* way /threaddelete does it; the transcripts stay on disk for /resume.
|
|
17
|
+
*
|
|
18
|
+
* Private chats only: a group's topics are everyone's, and go one at a time.
|
|
19
|
+
*/
|
|
20
|
+
import { randomBytes } from 'crypto';
|
|
21
|
+
import { sessionHistory } from '../../../claude/session-history.js';
|
|
22
|
+
import { scheduler } from '../../../claude/scheduler.js';
|
|
23
|
+
import { judgeThreads } from '../../../claude/thread-judge-haiku.js';
|
|
24
|
+
import { hasRunningTasks } from '../../../telegram/background-activity-card.js';
|
|
25
|
+
import { EntityText } from '../../../telegram/entities.js';
|
|
26
|
+
import { cutLabel } from '../../../telegram/prompt-label.js';
|
|
27
|
+
import { editCallbackMessage, editFormatted, replyFormatted } from '../../../telegram/send.js';
|
|
28
|
+
import { hasImplicitName, threadDisplayName, threadName } from '../../../telegram/thread-titles.js';
|
|
29
|
+
import { getSessionKeyFromCtx, parseSessionKey } from '../../../utils/session-key.js';
|
|
30
|
+
import { sanitizeError } from '../../../utils/sanitize.js';
|
|
31
|
+
import { isThreadForgotten } from '../../deleted-threads.js';
|
|
32
|
+
import { isThreadKept } from '../../kept-threads.js';
|
|
33
|
+
import { pendingWork } from '../../middleware/queued-messages.js';
|
|
34
|
+
import { deleteThread } from './thread.js';
|
|
35
|
+
import { parseCallback } from './shared.js';
|
|
36
|
+
const HOUR_MS = 60 * 60 * 1000;
|
|
37
|
+
const DAY_MS = 24 * HOUR_MS;
|
|
38
|
+
export const DEFAULT_MIN_IDLE_MS = 2 * DAY_MS;
|
|
39
|
+
/** Thread buttons in one list; Telegram takes 100 buttons, and a phone screen far fewer. */
|
|
40
|
+
export const MAX_ROWS = 40;
|
|
41
|
+
/** Lines of "left alone" before the rest are only counted. */
|
|
42
|
+
const MAX_SKIPPED_LINES = 15;
|
|
43
|
+
const MAX_LABEL_CHARS = 30;
|
|
44
|
+
/** How long a list's buttons keep working. */
|
|
45
|
+
const VIEW_TTL_MS = HOUR_MS;
|
|
46
|
+
const UNITS = { h: HOUR_MS, d: DAY_MS, w: 7 * DAY_MS };
|
|
47
|
+
/** The idle threshold an argument asks for: undefined for one that isn't one. */
|
|
48
|
+
export function parseMinIdle(arg) {
|
|
49
|
+
const a = arg.trim().toLowerCase();
|
|
50
|
+
if (a === '')
|
|
51
|
+
return DEFAULT_MIN_IDLE_MS;
|
|
52
|
+
if (a === '0' || a === 'any' || a === 'all')
|
|
53
|
+
return 0;
|
|
54
|
+
const m = /^(\d+)\s*([hdw])$/.exec(a);
|
|
55
|
+
return m ? Number(m[1]) * UNITS[m[2]] : undefined;
|
|
56
|
+
}
|
|
57
|
+
/** A span the short way: 45m, 5h, 3d, 2w. */
|
|
58
|
+
export function formatSpan(ms) {
|
|
59
|
+
if (ms < HOUR_MS)
|
|
60
|
+
return `${Math.max(1, Math.floor(ms / 60000))}m`;
|
|
61
|
+
if (ms < DAY_MS)
|
|
62
|
+
return `${Math.floor(ms / HOUR_MS)}h`;
|
|
63
|
+
if (ms < 14 * DAY_MS)
|
|
64
|
+
return `${Math.floor(ms / DAY_MS)}d`;
|
|
65
|
+
return `${Math.floor(ms / (7 * DAY_MS))}w`;
|
|
66
|
+
}
|
|
67
|
+
function nameOf(sessionKey, entry) {
|
|
68
|
+
const shown = hasImplicitName(sessionKey) ? undefined : threadDisplayName(sessionKey);
|
|
69
|
+
return shown || threadName(entry.topic ?? '', '', entry.projectName) || entry.projectName;
|
|
70
|
+
}
|
|
71
|
+
/** Why deleting this thread now could lose something, apart from how recently it was used. */
|
|
72
|
+
export function busyReason(sessionKey) {
|
|
73
|
+
if (isThreadKept(sessionKey))
|
|
74
|
+
return 'kept';
|
|
75
|
+
const work = pendingWork(sessionKey);
|
|
76
|
+
if (work)
|
|
77
|
+
return work;
|
|
78
|
+
if (hasRunningTasks(sessionKey))
|
|
79
|
+
return 'background task running';
|
|
80
|
+
if (scheduler.listSchedules(sessionKey).some((s) => !s.disabled))
|
|
81
|
+
return 'has a schedule';
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
/** This chat's threads, split into the ones to offer (idle longest first) and the ones left alone. */
|
|
85
|
+
export function surveyThreads(chatId, currentKey, minIdleMs, now = Date.now()) {
|
|
86
|
+
const rows = [];
|
|
87
|
+
const skipped = [];
|
|
88
|
+
for (const [sessionKey, entry] of sessionHistory.getAllActiveSessions()) {
|
|
89
|
+
const key = parseSessionKey(sessionKey);
|
|
90
|
+
if (key.chatId !== chatId || key.threadId === undefined || isThreadForgotten(sessionKey))
|
|
91
|
+
continue;
|
|
92
|
+
const name = nameOf(sessionKey, entry);
|
|
93
|
+
const idleMs = now - new Date(entry.lastActivity).getTime();
|
|
94
|
+
const reason = sessionKey === currentKey ? 'this thread'
|
|
95
|
+
: busyReason(sessionKey) ?? (idleMs < minIdleMs ? `active ${formatSpan(idleMs)} ago` : undefined);
|
|
96
|
+
if (reason) {
|
|
97
|
+
skipped.push({ name, reason });
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
rows.push({
|
|
101
|
+
sessionKey,
|
|
102
|
+
name,
|
|
103
|
+
idleMs,
|
|
104
|
+
lastActivity: entry.lastActivity,
|
|
105
|
+
summary: { topic: entry.topic, lastUserMessage: entry.lastMessagePreview, lastReply: entry.lastAssistantPreview },
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
rows.sort((a, b) => b.idleMs - a.idleMs);
|
|
109
|
+
return { rows, skipped };
|
|
110
|
+
}
|
|
111
|
+
const views = new Map();
|
|
112
|
+
function pruneViews(now) {
|
|
113
|
+
for (const [id, view] of views)
|
|
114
|
+
if (view.expiresAt <= now)
|
|
115
|
+
views.delete(id);
|
|
116
|
+
}
|
|
117
|
+
/** A thread starts ticked unless Haiku saw loose ends in it. */
|
|
118
|
+
export function buildView(chatId, minIdleMs, survey, verdicts, now = Date.now()) {
|
|
119
|
+
const rows = survey.rows.slice(0, MAX_ROWS).map((row, i) => ({ ...row, verdict: verdicts?.[i] }));
|
|
120
|
+
return {
|
|
121
|
+
id: randomBytes(4).toString('hex'),
|
|
122
|
+
chatId,
|
|
123
|
+
minIdleMs,
|
|
124
|
+
rows,
|
|
125
|
+
ticked: new Set(rows.flatMap((row, i) => (row.verdict === 'open' ? [] : [i]))),
|
|
126
|
+
skipped: survey.skipped,
|
|
127
|
+
more: Math.max(0, survey.rows.length - MAX_ROWS),
|
|
128
|
+
judged: rows.length === 0 ? 'no' : verdicts ? 'yes' : 'failed',
|
|
129
|
+
expiresAt: now + VIEW_TTL_MS,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function addSkipped(text, skipped) {
|
|
133
|
+
if (skipped.length === 0)
|
|
134
|
+
return;
|
|
135
|
+
text.newline(2).bold(`Left alone (${skipped.length}):`);
|
|
136
|
+
for (const s of skipped.slice(0, MAX_SKIPPED_LINES)) {
|
|
137
|
+
text.newline().add(`${s.reason === 'kept' ? '📌' : '•'} ${cutLabel(s.name, 48)}: `).italic(s.reason);
|
|
138
|
+
}
|
|
139
|
+
if (skipped.length > MAX_SKIPPED_LINES)
|
|
140
|
+
text.newline().italic(`…and ${skipped.length - MAX_SKIPPED_LINES} more`);
|
|
141
|
+
}
|
|
142
|
+
export function renderView(view) {
|
|
143
|
+
const text = new EntityText().add('🧹 ').bold('Clean up threads');
|
|
144
|
+
if (view.rows.length === 0) {
|
|
145
|
+
text.newline(2).add(view.minIdleMs > 0
|
|
146
|
+
? `No threads idle for ${formatSpan(view.minIdleMs)} or more to clean up.`
|
|
147
|
+
: 'No threads to clean up.');
|
|
148
|
+
addSkipped(text, view.skipped);
|
|
149
|
+
if (view.minIdleMs > 0 && view.skipped.some((s) => s.reason.startsWith('active '))) {
|
|
150
|
+
text.newline(2).add('💡 ').code('/threadcleanup 12h').add(' offers threads idle for less long.');
|
|
151
|
+
}
|
|
152
|
+
return { text: text.build(), keyboard: [] };
|
|
153
|
+
}
|
|
154
|
+
text.newline(2).add('Delete the ticked threads? ')
|
|
155
|
+
.add('Telegram can\'t undo this, but the conversations stay on disk, so ').code('/resume').add(' can still pick them up.');
|
|
156
|
+
if (view.judged === 'failed') {
|
|
157
|
+
text.newline(2).add('⚠️ Haiku couldn\'t check these for loose ends, so look them over.');
|
|
158
|
+
}
|
|
159
|
+
else if (view.rows.some((r) => r.verdict === 'open')) {
|
|
160
|
+
text.newline(2).add('⚠️ marks a thread where Haiku saw loose ends. Those start unticked.');
|
|
161
|
+
}
|
|
162
|
+
if (view.more > 0) {
|
|
163
|
+
text.newline(2).italic(`Showing the ${view.rows.length} idle longest. ${view.more} more after these: send /threadcleanup again.`);
|
|
164
|
+
}
|
|
165
|
+
addSkipped(text, view.skipped);
|
|
166
|
+
text.newline(2).add('💡 ').code('/threadkeep').add(' in a thread keeps it out of cleanups.');
|
|
167
|
+
const keyboard = view.rows.map((row, i) => [{
|
|
168
|
+
text: `${view.ticked.has(i) ? '☑️' : '⬜'} ${row.verdict === 'open' ? '⚠️ ' : ''}${cutLabel(row.name, MAX_LABEL_CHARS)} · ${formatSpan(row.idleMs)}`,
|
|
169
|
+
callback_data: `threadcleanup:${view.id}:t:${i}`,
|
|
170
|
+
}]);
|
|
171
|
+
if (view.rows.length > 1) {
|
|
172
|
+
keyboard.push([
|
|
173
|
+
{ text: '☑️ All', callback_data: `threadcleanup:${view.id}:all` },
|
|
174
|
+
{ text: '⬜ None', callback_data: `threadcleanup:${view.id}:none` },
|
|
175
|
+
]);
|
|
176
|
+
}
|
|
177
|
+
const count = view.ticked.size;
|
|
178
|
+
keyboard.push([
|
|
179
|
+
...(count > 0 ? [{ text: `🗑️ Delete ${count}`, callback_data: `threadcleanup:${view.id}:go` }] : []),
|
|
180
|
+
{ text: '✗ Cancel', callback_data: `threadcleanup:${view.id}:x` },
|
|
181
|
+
]);
|
|
182
|
+
return { text: text.build(), keyboard };
|
|
183
|
+
}
|
|
184
|
+
// ── /threadcleanup ─────────────────────────────────────────────────────────────
|
|
185
|
+
export async function handleThreadCleanup(ctx) {
|
|
186
|
+
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
187
|
+
if (!keyInfo)
|
|
188
|
+
return;
|
|
189
|
+
const { chatId, sessionKey } = keyInfo;
|
|
190
|
+
if (ctx.chat?.type !== 'private') {
|
|
191
|
+
await replyFormatted(ctx, new EntityText()
|
|
192
|
+
.add('🧹 ').code('/threadcleanup').add(' works in private chats, where every thread is yours. ')
|
|
193
|
+
.add('In a group, delete topics one at a time with ').code('/threaddelete').add('.').build());
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
const arg = (ctx.message?.text ?? '').split(' ').slice(1).join(' ');
|
|
197
|
+
const minIdleMs = parseMinIdle(arg);
|
|
198
|
+
if (minIdleMs === undefined) {
|
|
199
|
+
await replyFormatted(ctx, new EntityText()
|
|
200
|
+
.add('ℹ️ Usage: ').code('/threadcleanup').add(' offers threads idle for 2 days or more; ')
|
|
201
|
+
.code('/threadcleanup 12h').add(', ').code('/threadcleanup 7d').add(' or ').code('/threadcleanup 2w').add(' set the idle time, and ')
|
|
202
|
+
.code('/threadcleanup 0').add(' offers every idle thread.').build());
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
const now = Date.now();
|
|
206
|
+
pruneViews(now);
|
|
207
|
+
const survey = surveyThreads(chatId, sessionKey, minIdleMs, now);
|
|
208
|
+
if (survey.rows.length === 0) {
|
|
209
|
+
await replyFormatted(ctx, renderView(buildView(chatId, minIdleMs, survey, undefined, now)).text);
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
const shown = Math.min(survey.rows.length, MAX_ROWS);
|
|
213
|
+
const status = await ctx.reply(`🧹 Looking through ${shown} idle thread${shown === 1 ? '' : 's'} for loose ends…`);
|
|
214
|
+
const verdicts = await judgeThreads(survey.rows.slice(0, MAX_ROWS).map((r) => r.summary));
|
|
215
|
+
const view = buildView(chatId, minIdleMs, survey, verdicts);
|
|
216
|
+
views.set(view.id, view);
|
|
217
|
+
const { text, keyboard } = renderView(view);
|
|
218
|
+
await editFormatted(ctx.api, chatId, status.message_id, text, { reply_markup: { inline_keyboard: keyboard } });
|
|
219
|
+
}
|
|
220
|
+
// ── The buttons ──────────────────────────────────────────────────────────
|
|
221
|
+
/** Delete what's ticked, checking each thread again first. The report. */
|
|
222
|
+
export async function deleteTicked(api, view) {
|
|
223
|
+
const deleted = [];
|
|
224
|
+
const kept = [];
|
|
225
|
+
const failed = [];
|
|
226
|
+
for (const i of [...view.ticked].sort((a, b) => a - b)) {
|
|
227
|
+
const row = view.rows[i];
|
|
228
|
+
if (!row)
|
|
229
|
+
continue;
|
|
230
|
+
// Deleted some other way since the list went up.
|
|
231
|
+
if (isThreadForgotten(row.sessionKey)) {
|
|
232
|
+
deleted.push(row.name);
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
// Used again since then, which moves its history entry on.
|
|
236
|
+
const entry = sessionHistory.getLastSession(row.sessionKey);
|
|
237
|
+
const usedSince = entry !== undefined && entry.lastActivity > row.lastActivity;
|
|
238
|
+
const reason = busyReason(row.sessionKey) ?? (usedSince ? 'used since the list went up' : undefined);
|
|
239
|
+
if (reason) {
|
|
240
|
+
kept.push({ name: row.name, reason });
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
try {
|
|
244
|
+
const error = await deleteThread(api, row.sessionKey, '/threadcleanup');
|
|
245
|
+
if (error)
|
|
246
|
+
failed.push({ name: row.name, reason: error });
|
|
247
|
+
else
|
|
248
|
+
deleted.push(row.name);
|
|
249
|
+
}
|
|
250
|
+
catch (err) {
|
|
251
|
+
failed.push({ name: row.name, reason: sanitizeError(err) });
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
const text = new EntityText().add('🧹 ');
|
|
255
|
+
text.bold(deleted.length === 0 ? 'No threads deleted' : `Deleted ${deleted.length} thread${deleted.length === 1 ? '' : 's'}`);
|
|
256
|
+
for (const name of deleted.slice(0, MAX_ROWS))
|
|
257
|
+
text.newline().add(`• ${cutLabel(name, 48)}`);
|
|
258
|
+
if (kept.length > 0) {
|
|
259
|
+
text.newline(2).bold('Kept, since they changed:');
|
|
260
|
+
for (const s of kept)
|
|
261
|
+
text.newline().add(`• ${cutLabel(s.name, 48)}: `).italic(s.reason);
|
|
262
|
+
}
|
|
263
|
+
if (failed.length > 0) {
|
|
264
|
+
text.newline(2).bold('Couldn\'t delete:');
|
|
265
|
+
for (const s of failed)
|
|
266
|
+
text.newline().add(`• ${cutLabel(s.name, 48)}: `).italic(s.reason);
|
|
267
|
+
}
|
|
268
|
+
if (deleted.length > 0) {
|
|
269
|
+
text.newline(2).add('The conversations stay on disk: ').code('/resume').add(' picks any of them up again.');
|
|
270
|
+
}
|
|
271
|
+
return text.build();
|
|
272
|
+
}
|
|
273
|
+
export async function handleThreadCleanupCallback(ctx) {
|
|
274
|
+
const cb = parseCallback(ctx, 'threadcleanup:');
|
|
275
|
+
if (!cb)
|
|
276
|
+
return;
|
|
277
|
+
const m = /^threadcleanup:([0-9a-f]+):(t|all|none|go|x)(?::(\d+))?$/.exec(cb.data);
|
|
278
|
+
const view = m ? views.get(m[1]) : undefined;
|
|
279
|
+
if (!m || !view || view.chatId !== cb.chatId || view.expiresAt <= Date.now()) {
|
|
280
|
+
await ctx.answerCallbackQuery({ text: 'This list has expired. Send /threadcleanup again.' }).catch(() => { });
|
|
281
|
+
await ctx.editMessageReplyMarkup({ reply_markup: { inline_keyboard: [] } }).catch(() => { });
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
const action = m[2];
|
|
285
|
+
if (action === 'x') {
|
|
286
|
+
views.delete(view.id);
|
|
287
|
+
await ctx.answerCallbackQuery({ text: 'Nothing deleted.' }).catch(() => { });
|
|
288
|
+
await editCallbackMessage(ctx, new EntityText().add('👍 Nothing deleted.').build()).catch(() => { });
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
if (action === 'go') {
|
|
292
|
+
// Gone before the first delete, so a second tap can't start a second run.
|
|
293
|
+
views.delete(view.id);
|
|
294
|
+
await ctx.answerCallbackQuery({ text: 'Deleting…' }).catch(() => { });
|
|
295
|
+
await editCallbackMessage(ctx, `🧹 Deleting ${view.ticked.size} thread${view.ticked.size === 1 ? '' : 's'}…`).catch(() => { });
|
|
296
|
+
const report = await deleteTicked(ctx.api, view);
|
|
297
|
+
await editCallbackMessage(ctx, report).catch((err) => {
|
|
298
|
+
console.error('[ThreadCleanup] Could not post the report:', sanitizeError(err));
|
|
299
|
+
});
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
if (action === 't') {
|
|
303
|
+
const i = Number(m[3]);
|
|
304
|
+
if (i >= 0 && i < view.rows.length) {
|
|
305
|
+
if (view.ticked.has(i))
|
|
306
|
+
view.ticked.delete(i);
|
|
307
|
+
else
|
|
308
|
+
view.ticked.add(i);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
else if (action === 'all') {
|
|
312
|
+
view.ticked = new Set(view.rows.map((_, i) => i));
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
view.ticked = new Set();
|
|
316
|
+
}
|
|
317
|
+
await ctx.answerCallbackQuery().catch(() => { });
|
|
318
|
+
const { text, keyboard } = renderView(view);
|
|
319
|
+
await editCallbackMessage(ctx, text, { reply_markup: { inline_keyboard: keyboard } }).catch(() => { });
|
|
320
|
+
}
|
|
321
|
+
/** Test seam: forget every open list. */
|
|
322
|
+
export function resetCleanupViewsForTest() {
|
|
323
|
+
views.clear();
|
|
324
|
+
}
|
|
325
|
+
/** Test seam: an open list, by id. */
|
|
326
|
+
export function cleanupViewForTest(id) {
|
|
327
|
+
return views.get(id);
|
|
328
|
+
}
|
|
329
|
+
//# sourceMappingURL=cleanup.js.map
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* /model and /ccr — choosing which backend answers.
|
|
3
|
+
*
|
|
4
|
+
* Kept together because the model list is provider-scoped: switching provider
|
|
5
|
+
* changes what /model can offer, and both changes need the same pty restart.
|
|
6
|
+
*/
|
|
7
|
+
import { config } from '../../../config.js';
|
|
8
|
+
import { getModel, clearModel, getActiveProviderName, getAvailableProviders, getAvailableModels, } from '../../../providers/provider-router.js';
|
|
9
|
+
import { isPassthroughModelId, isPremiumModel, PREMIUM_MODEL_ICON } from '../../../claude/model-catalog.js';
|
|
10
|
+
import { switchProvider, switchRequiresConfirm } from '../../../providers/provider-switch.js';
|
|
11
|
+
import { EntityText } from '../../../telegram/entities.js';
|
|
12
|
+
import { replyFormatted, editCallbackMessage } from '../../../telegram/send.js';
|
|
13
|
+
import { getSessionKeyFromCtx } from '../../../utils/session-key.js';
|
|
14
|
+
import { userPreferences } from '../../../providers/user-preferences.js';
|
|
15
|
+
import { replyMd, parseCallback } from './shared.js';
|
|
16
|
+
import { parseScopeArg, isBareLevelWord, scopeSite, applyAtLevel, describeSource, levelHelp, EVERYWHERE_ADMIN_ONLY, } from './prefs-scope.js';
|
|
17
|
+
export async function handleModelCommand(ctx) {
|
|
18
|
+
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
19
|
+
if (!keyInfo)
|
|
20
|
+
return;
|
|
21
|
+
const { sessionKey } = keyInfo;
|
|
22
|
+
const text = ctx.message?.text || '';
|
|
23
|
+
// Aliases are all lowercase, but a hand-typed full ID may not be — match
|
|
24
|
+
// case-insensitively, then pass the original through so vendor-cased IDs
|
|
25
|
+
// reach the CLI intact.
|
|
26
|
+
const { value: rawArg, level: explicitLevel } = parseScopeArg(text.split(' ').slice(1).join(' '));
|
|
27
|
+
const args = rawArg.toLowerCase();
|
|
28
|
+
const providerName = getActiveProviderName(sessionKey);
|
|
29
|
+
const models = await getAvailableModels(sessionKey);
|
|
30
|
+
const validIds = models.map(m => m.id);
|
|
31
|
+
const site = scopeSite(ctx);
|
|
32
|
+
if (!args) {
|
|
33
|
+
const currentModel = getModel(sessionKey);
|
|
34
|
+
const asked = userPreferences.getModel(sessionKey);
|
|
35
|
+
// Two per row — the alias list is long enough now (fable/opus/sonnet/haiku
|
|
36
|
+
// plus opusplan, best and the [1m] variants) that one row each turns the
|
|
37
|
+
// picker into a scroll on mobile.
|
|
38
|
+
const buttons = models.map((m) => ({
|
|
39
|
+
text: m.id === (asked ?? currentModel) ? `✓ ${m.label}` : m.label,
|
|
40
|
+
callback_data: `model:${m.id}`,
|
|
41
|
+
}));
|
|
42
|
+
const keyboard = [];
|
|
43
|
+
for (let i = 0; i < buttons.length; i += 2) {
|
|
44
|
+
keyboard.push(buttons.slice(i, i + 2));
|
|
45
|
+
}
|
|
46
|
+
const picker = new EntityText()
|
|
47
|
+
.add('🤖 ').bold('Select Model').add(` (${providerName})`)
|
|
48
|
+
.newline(2)
|
|
49
|
+
.italic(`Current: ${currentModel}, ${describeSource(sessionKey, 'model')}`)
|
|
50
|
+
.newline(2);
|
|
51
|
+
models.forEach((m, i) => {
|
|
52
|
+
if (i > 0)
|
|
53
|
+
picker.newline();
|
|
54
|
+
picker.add('• ').bold(m.label).add(` - ${m.description || ''}`);
|
|
55
|
+
});
|
|
56
|
+
picker.add('\n\nOr ').code('/model <full-id>').add(' to pin an exact release, e.g. ')
|
|
57
|
+
.code('claude-opus-4-8').add('.');
|
|
58
|
+
picker.append(levelHelp('model', 'sonnet', site));
|
|
59
|
+
await replyFormatted(ctx, picker.build(), {
|
|
60
|
+
reply_markup: {
|
|
61
|
+
inline_keyboard: keyboard,
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
// A level word on its own has no model attached. Passthrough would
|
|
67
|
+
// otherwise take it at face value and hand the CLI `--model all`, which is
|
|
68
|
+
// a confusing way to learn the argument order.
|
|
69
|
+
if (isBareLevelWord(args)) {
|
|
70
|
+
await replyMd(ctx, `\`${args}\` says how far to apply a model, but it needs the model too.\n\n` +
|
|
71
|
+
`Try \`/model sonnet ${args}\`, or /model to pick one.`);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
// Anything off the catalog is taken at face value — the CLI accepts a full
|
|
75
|
+
// model name wherever it accepts an alias, and pinning an exact release is a
|
|
76
|
+
// legitimate thing to want. We can't verify it, so say so rather than
|
|
77
|
+
// pretending the choice was checked.
|
|
78
|
+
const known = validIds.includes(args);
|
|
79
|
+
if (!known && !isPassthroughModelId(rawArg)) {
|
|
80
|
+
await replyFormatted(ctx, new EntityText()
|
|
81
|
+
.add(`❌ "${rawArg}" isn't a usable model name.\n\n`)
|
|
82
|
+
.add(`Aliases: ${validIds.join(', ')}\n`)
|
|
83
|
+
.add('Or pass a full model ID (e.g. ').code('claude-opus-5').add(').')
|
|
84
|
+
.build());
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const level = explicitLevel ?? 'thread';
|
|
88
|
+
if (level === 'all' && !site.admin) {
|
|
89
|
+
await replyFormatted(ctx, new EntityText().add(`⛔ ${EVERYWHERE_ADMIN_ONLY}`).build());
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const chosen = known ? args : rawArg;
|
|
93
|
+
const { message, keyboard } = await applyAtLevel(ctx, {
|
|
94
|
+
sessionKey, setting: 'model', value: chosen, label: chosen, level, site,
|
|
95
|
+
});
|
|
96
|
+
appendPremiumNote(message, chosen, providerName);
|
|
97
|
+
if (!known) {
|
|
98
|
+
message.add("\n\n⚠️ Not a known alias — passed to the CLI as-is. If your install can't serve it, the next turn fails; /model to pick again.");
|
|
99
|
+
}
|
|
100
|
+
await replyFormatted(ctx, message.build(), {
|
|
101
|
+
...(keyboard ? { reply_markup: { inline_keyboard: keyboard } } : {}),
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
export async function handleModelCallback(ctx) {
|
|
105
|
+
const cb = parseCallback(ctx, 'model:');
|
|
106
|
+
if (!cb)
|
|
107
|
+
return;
|
|
108
|
+
const { sessionKey, data } = cb;
|
|
109
|
+
const model = data.replace('model:', '');
|
|
110
|
+
// Validate against current provider's models
|
|
111
|
+
const models = await getAvailableModels(sessionKey);
|
|
112
|
+
const validIds = models.map(m => m.id);
|
|
113
|
+
if (!validIds.includes(model)) {
|
|
114
|
+
await ctx.answerCallbackQuery({ text: 'Invalid model' });
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const modelInfo = models.find(m => m.id === model);
|
|
118
|
+
const displayName = modelInfo?.label || model;
|
|
119
|
+
const site = scopeSite(ctx);
|
|
120
|
+
await ctx.answerCallbackQuery({ text: `Model set to ${displayName}!` });
|
|
121
|
+
const { message, keyboard } = await applyAtLevel(ctx, {
|
|
122
|
+
sessionKey, setting: 'model', value: model, label: displayName, level: 'thread', site,
|
|
123
|
+
});
|
|
124
|
+
appendPremiumNote(message, model, getActiveProviderName(sessionKey));
|
|
125
|
+
await editCallbackMessage(ctx, message.build(), {
|
|
126
|
+
...(keyboard ? { reply_markup: { inline_keyboard: keyboard } } : {}),
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Said once, when a premium model is picked: from then on the status line's
|
|
131
|
+
* 💎 is the reminder, and it only works if it was explained here.
|
|
132
|
+
*/
|
|
133
|
+
function appendPremiumNote(confirmation, model, provider) {
|
|
134
|
+
if (provider === 'ccr' || !isPremiumModel(model))
|
|
135
|
+
return;
|
|
136
|
+
confirmation.newline(2).italic(`${PREMIUM_MODEL_ICON} ${model} costs more per turn than opus, so it uses up your plan's limits faster. ` +
|
|
137
|
+
`The footer shows ${PREMIUM_MODEL_ICON} while it's on; /model opus to switch back.`);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* The switch between Claude (Max) and CCR: each /ccr moves the chat to the
|
|
141
|
+
* other one. Designed for the common case of "I'm throttled on Max, send
|
|
142
|
+
* subsequent messages through CCR instead." Sticky — stays on CCR until the
|
|
143
|
+
* user toggles back.
|
|
144
|
+
*/
|
|
145
|
+
export async function handleCcrCommand(ctx) {
|
|
146
|
+
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
147
|
+
if (!keyInfo)
|
|
148
|
+
return;
|
|
149
|
+
const { sessionKey } = keyInfo;
|
|
150
|
+
if (!config.CCR_ENABLED) {
|
|
151
|
+
await replyMd(ctx, '⚠️ CCR is not enabled. Set `CCR_ENABLED=true` in `.env` and restart the bot.');
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const active = getActiveProviderName(sessionKey);
|
|
155
|
+
const next = active === 'ccr' ? 'claude' : 'ccr';
|
|
156
|
+
// If a live session owned by the other backend would be abandoned, confirm
|
|
157
|
+
// first (switching starts a fresh session — sessions can't cross backends).
|
|
158
|
+
if (switchRequiresConfirm(sessionKey, next)) {
|
|
159
|
+
await replyFormatted(ctx, buildSwitchConfirmText(sessionKey, next), {
|
|
160
|
+
reply_markup: { inline_keyboard: buildSwitchConfirmKeyboard(next) },
|
|
161
|
+
});
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
// switchProvider forks the session (clears the stale session_id and carries
|
|
165
|
+
// over a summary) so the next message starts clean on the new backend.
|
|
166
|
+
await switchProvider(sessionKey, next);
|
|
167
|
+
// Clear model — Claude and CCR share labels but CCR's mapping is different.
|
|
168
|
+
clearModel(sessionKey);
|
|
169
|
+
const label = next === 'ccr' ? 'CCR (routed)' : 'Claude (Max)';
|
|
170
|
+
await replyMd(ctx, `🔌 Switched provider to **${label}**.\n\n_Sticky — use /ccr again to switch back._`);
|
|
171
|
+
}
|
|
172
|
+
const MODEL_CLEARED_NOTE = 'Model selection cleared — use /model to pick a model.';
|
|
173
|
+
/** Confirmation body shown before a destructive provider switch. */
|
|
174
|
+
function buildSwitchConfirmText(sessionKey, target) {
|
|
175
|
+
const current = getActiveProviderName(sessionKey);
|
|
176
|
+
return new EntityText()
|
|
177
|
+
.add('🔀 ').bold(`Switch to ${target}?`)
|
|
178
|
+
.newline(2)
|
|
179
|
+
.add('Your current conversation runs on ').bold(current)
|
|
180
|
+
.add(". Sessions can't move between model backends, so I'll start a ")
|
|
181
|
+
.bold('fresh session')
|
|
182
|
+
.add(` on ${target} and carry over a short summary of this conversation for continuity.`)
|
|
183
|
+
.newline(2)
|
|
184
|
+
.add('Continue?')
|
|
185
|
+
.build();
|
|
186
|
+
}
|
|
187
|
+
function buildSwitchConfirmKeyboard(target) {
|
|
188
|
+
return [
|
|
189
|
+
[
|
|
190
|
+
{ text: '✓ Switch & carry over', callback_data: `provider_switch:${target}` },
|
|
191
|
+
{ text: '✗ Cancel', callback_data: 'provider_switch:cancel' },
|
|
192
|
+
],
|
|
193
|
+
];
|
|
194
|
+
}
|
|
195
|
+
/** Handles the confirm/cancel buttons from a provider-switch prompt. */
|
|
196
|
+
export async function handleProviderSwitchCallback(ctx) {
|
|
197
|
+
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
198
|
+
if (!keyInfo)
|
|
199
|
+
return;
|
|
200
|
+
const { sessionKey } = keyInfo;
|
|
201
|
+
const data = ctx.callbackQuery?.data;
|
|
202
|
+
if (!data || !data.startsWith('provider_switch:'))
|
|
203
|
+
return;
|
|
204
|
+
const target = data.replace('provider_switch:', '');
|
|
205
|
+
if (target === 'cancel') {
|
|
206
|
+
await ctx.answerCallbackQuery({ text: 'Cancelled' });
|
|
207
|
+
await ctx.editMessageReplyMarkup({ reply_markup: undefined });
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
const providers = getAvailableProviders();
|
|
211
|
+
if (!providers.includes(target)) {
|
|
212
|
+
await ctx.answerCallbackQuery({ text: 'Invalid provider' });
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
const provider = target;
|
|
216
|
+
await switchProvider(sessionKey, provider);
|
|
217
|
+
clearModel(sessionKey);
|
|
218
|
+
await ctx.answerCallbackQuery({ text: `Switched to ${provider}!` });
|
|
219
|
+
await editCallbackMessage(ctx, new EntityText()
|
|
220
|
+
.add('✅ Provider set to ').bold(provider)
|
|
221
|
+
.add('. Started a fresh session with a summary of the previous conversation carried over.')
|
|
222
|
+
.newline(2)
|
|
223
|
+
.italic(MODEL_CLEARED_NOTE)
|
|
224
|
+
.build());
|
|
225
|
+
}
|
|
226
|
+
//# sourceMappingURL=model.js.map
|