telecoder 1.2.0 → 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 +142 -130
- package/CHANGELOG.md +683 -2
- package/README.md +36 -32
- package/dist/audio/transcribe.js +0 -9
- package/dist/bin/mcp-server.js +46 -61
- package/dist/bot/bot.js +162 -181
- package/dist/bot/command-catalog.js +263 -0
- package/dist/bot/deleted-threads.js +103 -0
- package/dist/bot/file-access.js +35 -26
- package/dist/bot/handlers/album.handler.js +128 -0
- package/dist/bot/handlers/{fork.handler.js → branch.handler.js} +267 -280
- package/dist/bot/handlers/command/access.js +1 -1
- package/dist/bot/handlers/command/admin.js +86 -110
- package/dist/bot/handlers/command/all-view.js +33 -0
- package/dist/bot/handlers/command/auto-approve.js +3 -3
- 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 +20 -69
- package/dist/bot/handlers/command/cleanup.js +329 -0
- package/dist/bot/handlers/command/model.js +40 -119
- package/dist/bot/handlers/command/prefs-scope.js +255 -90
- package/dist/bot/handlers/command/project.js +31 -109
- package/dist/bot/handlers/command/resume.js +8 -4
- package/dist/bot/handlers/command/session.js +74 -213
- package/dist/bot/handlers/command/settings.js +92 -447
- package/dist/bot/handlers/command/shared.js +32 -35
- package/dist/bot/handlers/command/tasks.js +263 -95
- package/dist/bot/handlers/command/thread.js +128 -0
- package/dist/bot/handlers/command/topic-store.js +14 -53
- package/dist/bot/handlers/command/topic.js +8 -61
- package/dist/bot/handlers/command/{cost.js → usage.js} +32 -59
- package/dist/bot/handlers/command-fallback.js +179 -0
- package/dist/bot/handlers/command.handler.js +96 -422
- package/dist/bot/handlers/{schedule.handler.js → loop.handler.js} +159 -73
- package/dist/bot/handlers/media-fallback.js +12 -7
- package/dist/bot/handlers/message/replies.js +10 -87
- package/dist/bot/handlers/message/shared.js +9 -31
- package/dist/bot/handlers/message/turn-notify.js +15 -49
- package/dist/bot/handlers/message/turn-runner.js +18 -103
- package/dist/bot/handlers/message.handler.js +59 -52
- package/dist/bot/handlers/newbot.handler.js +13 -4
- package/dist/bot/handlers/photo.handler.js +88 -129
- package/dist/bot/handlers/prompts.handler.js +11 -11
- package/dist/bot/handlers/running-note.js +2 -2
- package/dist/bot/handlers/session-guard.js +4 -4
- package/dist/bot/handlers/suggestion.handler.js +2 -2
- package/dist/bot/handlers/tree.handler.js +20 -20
- package/dist/bot/handlers/voice.handler.js +23 -85
- package/dist/bot/kept-threads.js +51 -0
- package/dist/bot/middleware/album-collector.js +69 -0
- package/dist/bot/middleware/auth.middleware.js +1 -1
- package/dist/bot/middleware/group-mention.middleware.js +11 -5
- package/dist/bot/middleware/queued-messages.js +143 -32
- package/dist/bot/middleware/stale-filter.js +0 -22
- package/dist/build-info.json +5 -5
- package/dist/claude/ask-user-form.js +517 -0
- package/dist/claude/ask-user.js +94 -26
- package/dist/claude/auto-topic-haiku.js +17 -0
- package/dist/claude/available-commands.js +22 -19
- package/dist/claude/background-hint.js +91 -0
- package/dist/claude/{fork-tree.js → branch-tree.js} +9 -9
- package/dist/claude/carry-over.js +0 -2
- package/dist/claude/ccr-shim.js +12 -10
- package/dist/claude/claude-auth.js +6 -10
- package/dist/claude/command-parser.js +49 -43
- package/dist/claude/cost-overlay-scraper.js +7 -2
- package/dist/claude/effort-level.js +5 -0
- package/dist/claude/enabled-plugins.js +12 -16
- package/dist/claude/in-flight-tracker.js +21 -0
- package/dist/claude/mcp-bridge.js +86 -58
- package/dist/claude/memory-guard.js +400 -0
- package/dist/claude/message-offsets.js +5 -5
- package/dist/claude/modal-relay.js +401 -34
- package/dist/claude/model-catalog.js +20 -3
- package/dist/claude/monitor-relay.js +130 -15
- package/dist/claude/native-commands.js +40 -0
- package/dist/claude/{pending-forks.js → pending-branches.js} +26 -26
- package/dist/claude/permission-gate.js +11 -10
- package/dist/claude/permission-mode.js +19 -45
- package/dist/claude/prewarm.js +70 -0
- package/dist/claude/pty-idle-reaper.js +96 -0
- package/dist/claude/pty-provider.js +473 -188
- package/dist/claude/pty-spawn-config.js +79 -32
- package/dist/claude/pty-watch.js +201 -0
- package/dist/claude/request-queue.js +7 -35
- package/dist/claude/rewind.js +111 -0
- package/dist/claude/scheduled-runner.js +1 -3
- package/dist/claude/scheduler.js +6 -2
- package/dist/claude/scope-guard.js +8 -3
- package/dist/claude/screen-marks.js +83 -0
- package/dist/claude/screen-render.js +96 -0
- package/dist/claude/session-history.js +4 -2
- package/dist/claude/session-jsonl.js +162 -15
- package/dist/claude/session-manager.js +29 -8
- package/dist/claude/session-move.js +70 -0
- package/dist/claude/shell-mode-gate.js +60 -0
- package/dist/claude/side-question.js +20 -17
- package/dist/claude/stage-images.js +5 -5
- package/dist/claude/tasks-overlay-scraper.js +143 -20
- package/dist/claude/thread-judge-haiku.js +88 -0
- package/dist/claude/tip-scraper.js +3 -4
- package/dist/claude/tui-modal.js +272 -27
- package/dist/claude/tui-state.js +74 -2
- package/dist/claude/turn-end.js +15 -1
- package/dist/claude/turn-prose.js +1 -1
- package/dist/claude/typed-answer.js +104 -0
- package/dist/claude/update-banner-relay.js +1 -1
- package/dist/cli/commands/doctor.js +48 -15
- package/dist/cli/commands/help.js +11 -2
- package/dist/cli/commands/init.js +16 -13
- package/dist/cli/commands/service.js +40 -8
- package/dist/cli/commands/start.js +10 -0
- package/dist/cli/commands/watch.js +322 -0
- package/dist/cli/dispatch.js +5 -0
- package/dist/cli/init/env-file.js +1 -1
- package/dist/cli/init/flow.js +114 -47
- package/dist/cli/init/prompter.js +8 -0
- package/dist/cli/init/telegram.js +35 -9
- package/dist/cli/service/render.js +3 -3
- package/dist/config.js +156 -131
- package/dist/index.js +107 -31
- package/dist/launcher.js +34 -7
- package/dist/providers/ccr-introspect.js +1 -8
- package/dist/providers/ccr-provider.js +19 -20
- package/dist/providers/claude-provider.js +4 -57
- package/dist/providers/prefs-sync.js +16 -59
- package/dist/providers/provider-router.js +24 -23
- package/dist/providers/spawn-settings.js +45 -0
- package/dist/providers/user-preferences.js +127 -19
- package/dist/restart-when-idle.js +27 -7
- package/dist/startup/auto-continue.js +2 -2
- package/dist/startup/auto-resume.js +3 -15
- package/dist/startup/notices.js +1 -1
- package/dist/startup/verify-token.js +4 -4
- package/dist/telegram/action-logger.js +3 -165
- package/dist/telegram/background-activity-card.js +1 -1
- package/dist/telegram/botname-settings.js +71 -125
- package/dist/telegram/client-options.js +6 -7
- package/dist/telegram/force-reply-tracker.js +55 -16
- package/dist/telegram/message-sender.js +92 -360
- package/dist/telegram/prompt-label.js +11 -5
- package/dist/telegram/streaming-turn.js +5 -7
- package/dist/telegram/table-lists.js +56 -0
- package/dist/telegram/task-list.js +4 -4
- package/dist/telegram/task-tracker.js +45 -126
- package/dist/telegram/terminal-renderer.js +1 -5
- package/dist/telegram/thread-titles.js +74 -2
- package/dist/telegram/threads-setup.js +1 -1
- package/dist/utils/admins.js +2 -2
- package/dist/utils/bot-icon.js +248 -0
- package/dist/utils/bot-token.js +8 -5
- package/dist/utils/build-info.js +3 -3
- package/dist/utils/caffeinate.js +6 -3
- package/dist/utils/claude-env.js +0 -1
- package/dist/utils/claude-version.js +2 -2
- package/dist/utils/config-home.js +3 -3
- package/dist/utils/download.js +41 -15
- package/dist/utils/exit-codes.js +11 -0
- package/dist/utils/format.js +3 -6
- package/dist/utils/home-project.js +1 -1
- package/dist/utils/idle-restart.js +1 -1
- package/dist/utils/install-mode.js +1 -1
- package/dist/utils/instance-config.js +1 -1
- package/dist/utils/instances.js +1 -1
- package/dist/utils/keyed-settings.js +2 -2
- package/dist/utils/memory-pressure.js +60 -0
- package/dist/utils/npm-version.js +2 -2
- package/dist/utils/resolve-claude-bin.js +13 -24
- package/dist/utils/respawn-backoff.js +9 -0
- package/dist/utils/stale-launcher.js +1 -1
- package/dist/utils/systemd.js +8 -8
- package/dist/utils/telegram-proxy.js +72 -0
- package/dist/utils/uploads-dir.js +27 -0
- package/dist/utils/verbosity.js +8 -8
- package/dist/utils/version-check.js +5 -5
- package/package.json +3 -4
- package/dist/bot/handlers/command/media.js +0 -197
- package/dist/bot/handlers/command/streaming-mode.js +0 -16
- package/dist/bot/handlers/message/throttle.js +0 -49
- package/dist/claude/agent-watchdog.js +0 -162
- package/dist/claude/agent.js +0 -1458
- package/dist/claude/held-query.js +0 -190
- package/dist/claude/mcp-tools.js +0 -354
- package/dist/claude/sdk-permission-gate.js +0 -77
- package/dist/claude/session-cost.js +0 -41
- package/dist/claude/system-prompt.js +0 -162
- package/dist/providers/sdk-provider.js +0 -37
- package/dist/telegram/telegraph-settings.js +0 -31
- package/dist/telegram/telegraph.js +0 -453
- package/dist/telegram/terminal-settings.js +0 -25
- package/dist/tts/tts-settings.js +0 -62
- package/dist/tts/tts.js +0 -245
- package/dist/tts/voice-reply.js +0 -78
- package/dist/utils/debug-agent.js +0 -117
- package/dist/utils/debug-watchdog.js +0 -121
- package/dist/utils/project-data-dir.js +0 -33
- package/dist/utils/reasoning-summary.js +0 -12
|
@@ -7,22 +7,19 @@ import { messageSender } from '../../telegram/message-sender.js';
|
|
|
7
7
|
import { closeTurn, relayCatchUpIfMissed } from './message/turn-notify.js';
|
|
8
8
|
import { isDuplicate, markProcessed } from '../../telegram/deduplication.js';
|
|
9
9
|
import { isStaleMessage } from '../middleware/stale-filter.js';
|
|
10
|
-
import { queueRequest
|
|
11
|
-
import { getStreamingMode } from './command.handler.js';
|
|
10
|
+
import { queueRequest } from '../../claude/request-queue.js';
|
|
12
11
|
import { downloadFileSecure, getTelegramFileUrl } from '../../utils/download.js';
|
|
12
|
+
import { telegramProxyUrl } from '../../telegram/client-options.js';
|
|
13
13
|
import { sanitizeError } from '../../utils/sanitize.js';
|
|
14
14
|
import { isValidImageFile, getFileType } from '../../utils/file-type.js';
|
|
15
15
|
import { getSessionKeyFromCtx } from '../../utils/session-key.js';
|
|
16
16
|
import { requireSession } from './session-guard.js';
|
|
17
17
|
import { progressCallbacks, withStreamingTurn } from '../../telegram/streaming-turn.js';
|
|
18
|
-
import {
|
|
18
|
+
import { ensureUploadsDir } from '../../utils/uploads-dir.js';
|
|
19
19
|
function sanitizeFileName(name) {
|
|
20
20
|
return path.basename(name).replace(/[^a-zA-Z0-9._-]/g, '_');
|
|
21
21
|
}
|
|
22
|
-
function
|
|
23
|
-
return ensureProjectDataDir(projectDir, 'uploads');
|
|
24
|
-
}
|
|
25
|
-
function pickLargestPhoto(photoSizes) {
|
|
22
|
+
export function pickLargestPhoto(photoSizes) {
|
|
26
23
|
return photoSizes.reduce((best, current) => {
|
|
27
24
|
const bestSize = best.file_size || 0;
|
|
28
25
|
const currentSize = current.file_size || 0;
|
|
@@ -35,7 +32,7 @@ async function downloadTelegramFile(ctx, fileId, destPath) {
|
|
|
35
32
|
throw new Error('Telegram did not provide file_path for this image.');
|
|
36
33
|
}
|
|
37
34
|
const fileUrl = getTelegramFileUrl(config.TELEGRAM_BOT_TOKEN, file.file_path);
|
|
38
|
-
await downloadFileSecure(fileUrl, destPath);
|
|
35
|
+
await downloadFileSecure(fileUrl, destPath, { proxyUrl: telegramProxyUrl() });
|
|
39
36
|
return file.file_path;
|
|
40
37
|
}
|
|
41
38
|
function getMediaType(filePath) {
|
|
@@ -57,55 +54,104 @@ async function handleSavedImage(ctx, savedPath, caption) {
|
|
|
57
54
|
const session = sessionManager.getSession(sessionKey);
|
|
58
55
|
if (!session)
|
|
59
56
|
return;
|
|
60
|
-
const relativePath = path.relative(session.workingDirectory, savedPath);
|
|
61
57
|
const captionText = caption?.trim();
|
|
62
58
|
const noteLines = [
|
|
63
|
-
'User
|
|
59
|
+
'User sent an image.',
|
|
64
60
|
`Saved at: ${savedPath}`,
|
|
65
|
-
`Relative path: ${relativePath}`,
|
|
66
61
|
captionText ? `Caption: "${captionText}"` : 'Caption: (none)',
|
|
67
62
|
'The image is attached as a vision input — you can see it directly.',
|
|
68
63
|
'If the caption includes a question or request, answer it. Otherwise, describe what you see and ask if they want any analysis or edits.',
|
|
69
64
|
];
|
|
70
65
|
const agentPrompt = noteLines.join('\n');
|
|
66
|
+
await runUploadTurn(ctx, sessionKey, agentPrompt, [imageAttachment(savedPath)]);
|
|
67
|
+
}
|
|
68
|
+
/** A saved image as vision input for the turn. */
|
|
69
|
+
export function imageAttachment(savedPath) {
|
|
71
70
|
// Read image as base64 for multimodal vision input
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
//
|
|
75
|
-
// what makes claude attach it in pty mode — so hand the provider that same
|
|
71
|
+
const data = fs.readFileSync(savedPath).toString('base64');
|
|
72
|
+
// savedPath is what the prompt names in "Saved at:", and naming it is
|
|
73
|
+
// what makes claude attach it — so hand the provider that same
|
|
76
74
|
// path rather than letting it stage a duplicate copy of the same picture.
|
|
77
|
-
|
|
75
|
+
return { data, mediaType: getMediaType(savedPath), path: savedPath };
|
|
76
|
+
}
|
|
77
|
+
/** Send the note an upload became to Claude as a turn, behind any turn already running. */
|
|
78
|
+
export async function runUploadTurn(ctx, sessionKey, agentPrompt, images) {
|
|
78
79
|
await queueRequest(sessionKey, agentPrompt, async () => {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
await withStreamingTurn(ctx, sessionKey, agentPrompt, async (abortController) => {
|
|
82
|
-
const response = await sendToAgent(sessionKey, agentPrompt, {
|
|
83
|
-
...progressCallbacks(ctx),
|
|
84
|
-
abortController,
|
|
85
|
-
images,
|
|
86
|
-
telegramCtx: ctx,
|
|
87
|
-
});
|
|
88
|
-
await messageSender.finishStreaming(ctx, response.text);
|
|
89
|
-
await relayCatchUpIfMissed(ctx, sessionKey, response.text || '');
|
|
90
|
-
await messageSender.sendCompletionNotification(ctx, Date.now() - startTime);
|
|
91
|
-
await closeTurn(ctx, sessionKey, response, agentPrompt);
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
await ctx.replyWithChatAction('typing');
|
|
96
|
-
const abortController = new AbortController();
|
|
97
|
-
setAbortController(sessionKey, abortController);
|
|
80
|
+
const startTime = Date.now();
|
|
81
|
+
await withStreamingTurn(ctx, sessionKey, agentPrompt, async (abortController) => {
|
|
98
82
|
const response = await sendToAgent(sessionKey, agentPrompt, {
|
|
83
|
+
...progressCallbacks(ctx),
|
|
99
84
|
abortController,
|
|
100
85
|
images,
|
|
101
86
|
telegramCtx: ctx,
|
|
102
87
|
});
|
|
103
|
-
await messageSender.
|
|
88
|
+
await messageSender.finishStreaming(ctx, response.text);
|
|
104
89
|
await relayCatchUpIfMissed(ctx, sessionKey, response.text || '');
|
|
90
|
+
await messageSender.sendCompletionNotification(ctx, Date.now() - startTime);
|
|
105
91
|
await closeTurn(ctx, sessionKey, response, agentPrompt);
|
|
106
|
-
}
|
|
92
|
+
});
|
|
107
93
|
});
|
|
108
94
|
}
|
|
95
|
+
/** Drop a download that turned out not to be an image, and say so. */
|
|
96
|
+
function requireValidImage(destPath) {
|
|
97
|
+
// Validate file content via magic bytes (defense against spoofed MIME types)
|
|
98
|
+
let isValid = false;
|
|
99
|
+
try {
|
|
100
|
+
isValid = isValidImageFile(destPath);
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
// Validation threw — treat as invalid
|
|
104
|
+
}
|
|
105
|
+
if (!isValid) {
|
|
106
|
+
if (fs.existsSync(destPath))
|
|
107
|
+
fs.unlinkSync(destPath);
|
|
108
|
+
throw new Error('Downloaded file is not a valid image.');
|
|
109
|
+
}
|
|
110
|
+
if (!fs.readFileSync(destPath).length) {
|
|
111
|
+
throw new Error('Downloaded image is empty.');
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Save a photo under `uploadsDir` and return where it went. `stamp` starts the
|
|
116
|
+
* file name, so photos saved together can be told apart.
|
|
117
|
+
*/
|
|
118
|
+
export async function savePhoto(ctx, uploadsDir, photo, stamp = String(Date.now())) {
|
|
119
|
+
const safeUniqueId = sanitizeFileName(photo.file_unique_id);
|
|
120
|
+
const destPath = path.join(uploadsDir, `photo_${stamp}_${safeUniqueId}.jpg`);
|
|
121
|
+
const filePath = await downloadTelegramFile(ctx, photo.file_id, destPath);
|
|
122
|
+
requireValidImage(destPath);
|
|
123
|
+
// Get actual file type from magic bytes instead of trusting extension
|
|
124
|
+
const actualType = getFileType(destPath);
|
|
125
|
+
const rawExt = actualType?.extension || path.extname(filePath) || '.jpg';
|
|
126
|
+
const ext = rawExt.startsWith('.') ? rawExt : `.${rawExt}`;
|
|
127
|
+
const finalPath = ext && ext !== '.jpg'
|
|
128
|
+
? destPath.replace(/\.jpg$/, ext)
|
|
129
|
+
: destPath;
|
|
130
|
+
if (finalPath !== destPath) {
|
|
131
|
+
fs.renameSync(destPath, finalPath);
|
|
132
|
+
}
|
|
133
|
+
return finalPath;
|
|
134
|
+
}
|
|
135
|
+
/** Save an image sent as a file under `uploadsDir` and return where it went. */
|
|
136
|
+
export async function saveImageDocument(ctx, uploadsDir, document, stamp = String(Date.now())) {
|
|
137
|
+
const originalName = document.file_name ? sanitizeFileName(document.file_name) : '';
|
|
138
|
+
const ext = originalName.includes('.') ? '' : '.jpg';
|
|
139
|
+
const baseName = originalName || `image_${stamp}_${document.file_unique_id}${ext}`;
|
|
140
|
+
const destPath = path.join(uploadsDir, `${stamp}_${baseName}`);
|
|
141
|
+
await downloadTelegramFile(ctx, document.file_id, destPath);
|
|
142
|
+
requireValidImage(destPath);
|
|
143
|
+
return destPath;
|
|
144
|
+
}
|
|
145
|
+
/** Save any other file under `uploadsDir` and return where it went. */
|
|
146
|
+
export async function saveDocument(ctx, uploadsDir, document, stamp = String(Date.now())) {
|
|
147
|
+
const originalName = document.file_name ? sanitizeFileName(document.file_name) : `file_${document.file_unique_id}`;
|
|
148
|
+
const destPath = path.join(uploadsDir, `${stamp}_${originalName}`);
|
|
149
|
+
await downloadTelegramFile(ctx, document.file_id, destPath);
|
|
150
|
+
if (!fs.existsSync(destPath) || fs.statSync(destPath).size === 0) {
|
|
151
|
+
throw new Error('Downloaded document is empty.');
|
|
152
|
+
}
|
|
153
|
+
return destPath;
|
|
154
|
+
}
|
|
109
155
|
export async function handlePhoto(ctx) {
|
|
110
156
|
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
111
157
|
const messageId = ctx.message?.message_id;
|
|
@@ -134,39 +180,8 @@ export async function handlePhoto(ctx) {
|
|
|
134
180
|
return;
|
|
135
181
|
}
|
|
136
182
|
const uploadsDir = ensureUploadsDir(session.workingDirectory);
|
|
137
|
-
const timestamp = Date.now();
|
|
138
|
-
const safeUniqueId = sanitizeFileName(largest.file_unique_id);
|
|
139
|
-
const fallbackName = `photo_${timestamp}_${safeUniqueId}.jpg`;
|
|
140
|
-
const destPath = path.join(uploadsDir, fallbackName);
|
|
141
183
|
try {
|
|
142
|
-
const
|
|
143
|
-
// Validate file content via magic bytes (defense against spoofed MIME types)
|
|
144
|
-
let isValid = false;
|
|
145
|
-
try {
|
|
146
|
-
isValid = isValidImageFile(destPath);
|
|
147
|
-
}
|
|
148
|
-
catch {
|
|
149
|
-
// Validation threw — treat as invalid
|
|
150
|
-
}
|
|
151
|
-
if (!isValid) {
|
|
152
|
-
if (fs.existsSync(destPath))
|
|
153
|
-
fs.unlinkSync(destPath);
|
|
154
|
-
throw new Error('Downloaded file is not a valid image.');
|
|
155
|
-
}
|
|
156
|
-
// Get actual file type from magic bytes instead of trusting extension
|
|
157
|
-
const actualType = getFileType(destPath);
|
|
158
|
-
const rawExt = actualType?.extension || path.extname(filePath) || '.jpg';
|
|
159
|
-
const ext = rawExt.startsWith('.') ? rawExt : `.${rawExt}`;
|
|
160
|
-
const finalPath = ext && ext !== '.jpg'
|
|
161
|
-
? destPath.replace(/\.jpg$/, ext)
|
|
162
|
-
: destPath;
|
|
163
|
-
if (finalPath !== destPath) {
|
|
164
|
-
fs.renameSync(destPath, finalPath);
|
|
165
|
-
}
|
|
166
|
-
const buffer = fs.readFileSync(finalPath);
|
|
167
|
-
if (!buffer.length) {
|
|
168
|
-
throw new Error('Downloaded image is empty.');
|
|
169
|
-
}
|
|
184
|
+
const finalPath = await savePhoto(ctx, uploadsDir, largest);
|
|
170
185
|
await handleSavedImage(ctx, finalPath, ctx.message?.caption);
|
|
171
186
|
}
|
|
172
187
|
catch (error) {
|
|
@@ -207,53 +222,19 @@ export async function handleTextDocument(ctx) {
|
|
|
207
222
|
return;
|
|
208
223
|
}
|
|
209
224
|
const uploadsDir = ensureUploadsDir(session.workingDirectory);
|
|
210
|
-
const timestamp = Date.now();
|
|
211
225
|
const originalName = document.file_name ? sanitizeFileName(document.file_name) : `file_${document.file_unique_id}`;
|
|
212
|
-
const destPath = path.join(uploadsDir, `${timestamp}_${originalName}`);
|
|
213
226
|
try {
|
|
214
|
-
await
|
|
215
|
-
if (!fs.existsSync(destPath) || fs.statSync(destPath).size === 0) {
|
|
216
|
-
throw new Error('Downloaded document is empty.');
|
|
217
|
-
}
|
|
218
|
-
const relativePath = path.relative(session.workingDirectory, destPath);
|
|
227
|
+
const destPath = await saveDocument(ctx, uploadsDir, document);
|
|
219
228
|
const caption = ctx.message?.caption?.trim();
|
|
220
229
|
const noteLines = [
|
|
221
|
-
`User
|
|
230
|
+
`User sent a file: ${document.file_name ?? originalName}`,
|
|
222
231
|
`Saved at: ${destPath}`,
|
|
223
|
-
`Relative path: ${relativePath}`,
|
|
224
232
|
caption ? `Caption: "${caption}"` : 'Caption: (none)',
|
|
225
233
|
'Use the Read tool to read its contents. For PDFs use Read with `pages` for large files.',
|
|
226
234
|
'If the caption asks a question, answer it based on the file. Otherwise summarize the contents and ask if they want a specific analysis.',
|
|
227
235
|
];
|
|
228
236
|
const agentPrompt = noteLines.join('\n');
|
|
229
|
-
await
|
|
230
|
-
if (getStreamingMode() === 'streaming') {
|
|
231
|
-
const startTime = Date.now();
|
|
232
|
-
await withStreamingTurn(ctx, sessionKey, agentPrompt, async (abortController) => {
|
|
233
|
-
const response = await sendToAgent(sessionKey, agentPrompt, {
|
|
234
|
-
...progressCallbacks(ctx),
|
|
235
|
-
abortController,
|
|
236
|
-
telegramCtx: ctx,
|
|
237
|
-
});
|
|
238
|
-
await messageSender.finishStreaming(ctx, response.text);
|
|
239
|
-
await relayCatchUpIfMissed(ctx, sessionKey, response.text || '');
|
|
240
|
-
await messageSender.sendCompletionNotification(ctx, Date.now() - startTime);
|
|
241
|
-
await closeTurn(ctx, sessionKey, response, agentPrompt);
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
else {
|
|
245
|
-
await ctx.replyWithChatAction('typing');
|
|
246
|
-
const abortController = new AbortController();
|
|
247
|
-
setAbortController(sessionKey, abortController);
|
|
248
|
-
const response = await sendToAgent(sessionKey, agentPrompt, {
|
|
249
|
-
abortController,
|
|
250
|
-
telegramCtx: ctx,
|
|
251
|
-
});
|
|
252
|
-
await messageSender.sendMessage(ctx, response.text);
|
|
253
|
-
await relayCatchUpIfMissed(ctx, sessionKey, response.text || '');
|
|
254
|
-
await closeTurn(ctx, sessionKey, response, agentPrompt);
|
|
255
|
-
}
|
|
256
|
-
});
|
|
237
|
+
await runUploadTurn(ctx, sessionKey, agentPrompt);
|
|
257
238
|
}
|
|
258
239
|
catch (error) {
|
|
259
240
|
const errorMessage = sanitizeError(error);
|
|
@@ -292,30 +273,8 @@ export async function handleImageDocument(ctx) {
|
|
|
292
273
|
return;
|
|
293
274
|
}
|
|
294
275
|
const uploadsDir = ensureUploadsDir(session.workingDirectory);
|
|
295
|
-
const timestamp = Date.now();
|
|
296
|
-
const originalName = document.file_name ? sanitizeFileName(document.file_name) : '';
|
|
297
|
-
const ext = originalName.includes('.') ? '' : '.jpg';
|
|
298
|
-
const baseName = originalName || `image_${timestamp}_${document.file_unique_id}${ext}`;
|
|
299
|
-
const destPath = path.join(uploadsDir, `${timestamp}_${baseName}`);
|
|
300
276
|
try {
|
|
301
|
-
await
|
|
302
|
-
// Validate file content via magic bytes (defense against spoofed MIME types)
|
|
303
|
-
let isValid = false;
|
|
304
|
-
try {
|
|
305
|
-
isValid = isValidImageFile(destPath);
|
|
306
|
-
}
|
|
307
|
-
catch {
|
|
308
|
-
// Validation threw — treat as invalid
|
|
309
|
-
}
|
|
310
|
-
if (!isValid) {
|
|
311
|
-
if (fs.existsSync(destPath))
|
|
312
|
-
fs.unlinkSync(destPath);
|
|
313
|
-
throw new Error('Downloaded file is not a valid image.');
|
|
314
|
-
}
|
|
315
|
-
const buffer = fs.readFileSync(destPath);
|
|
316
|
-
if (!buffer.length) {
|
|
317
|
-
throw new Error('Downloaded image is empty.');
|
|
318
|
-
}
|
|
277
|
+
const destPath = await saveImageDocument(ctx, uploadsDir, document);
|
|
319
278
|
await handleSavedImage(ctx, destPath, ctx.message?.caption);
|
|
320
279
|
}
|
|
321
280
|
catch (error) {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* any point in it.
|
|
4
4
|
*
|
|
5
5
|
* The list answers "what was this conversation about?" without paying for the
|
|
6
|
-
* replies again — that's the whole difference from /
|
|
6
|
+
* replies again — that's the whole difference from /history, which re-sends
|
|
7
7
|
* every reply in full and buries the prompts you came back to read. It keys
|
|
8
8
|
* each prompt by a letter the way /tree keys its points, and the buttons are
|
|
9
9
|
* just the letters. A letter opens its prompt — the exchange it started — and
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* 🌱 New branch from here carry on just after that reply, in a new
|
|
13
13
|
* conversation; this one stays in /resume
|
|
14
14
|
*
|
|
15
|
-
* which is the
|
|
15
|
+
* which is the 🌱 Branch button under that reply, without scrolling up to it.
|
|
16
16
|
* A prompt another branch already splits off at is marked 🌿, and 🌳 shows
|
|
17
17
|
* the tree, where that branch can be carried on.
|
|
18
18
|
*
|
|
@@ -34,7 +34,7 @@ import { sanitizeError } from '../../utils/sanitize.js';
|
|
|
34
34
|
import { findHistoryOwners } from '../../claude/session-history.js';
|
|
35
35
|
import { isProcessing } from '../../claude/request-queue.js';
|
|
36
36
|
import { lastAssistantTurnText, lastExchangeIn, sessionJsonlPath, userPromptsIn, } from '../../claude/session-jsonl.js';
|
|
37
|
-
import { splitsAlong, transcriptDir, treeOf } from '../../claude/
|
|
37
|
+
import { splitsAlong, transcriptDir, treeOf } from '../../claude/branch-tree.js';
|
|
38
38
|
import { EntityText, joinMessages, plain } from '../../telegram/entities.js';
|
|
39
39
|
import { replyFormatted } from '../../telegram/send.js';
|
|
40
40
|
import { buildLetterKeyboard, optionLetter } from '../../telegram/lettered-options.js';
|
|
@@ -42,7 +42,7 @@ import { cutLabel, promptLabel } from '../../telegram/prompt-label.js';
|
|
|
42
42
|
import { getSessionTopic } from './command.handler.js';
|
|
43
43
|
import { formatTimeAgo } from './command/shared.js';
|
|
44
44
|
import { NO_PROJECT_MESSAGE, whereChatIs } from './session-guard.js';
|
|
45
|
-
import { LEFT_ABOVE,
|
|
45
|
+
import { LEFT_ABOVE, loadBranch, replyQuote, youLine } from './branch.handler.js';
|
|
46
46
|
import { showTreeButton } from './tree.handler.js';
|
|
47
47
|
import { refuseWhileBusy, sendView } from './view.js';
|
|
48
48
|
// Most prompts are short (a median line of 72 characters across 40 recent
|
|
@@ -83,13 +83,13 @@ function readConversation(projectPath, sessionId) {
|
|
|
83
83
|
// A branch splitting off anywhere between one prompt and the next splits off
|
|
84
84
|
// during the first one's exchange.
|
|
85
85
|
const tree = treeOf(projectPath, sessionId);
|
|
86
|
-
const
|
|
87
|
-
const splits =
|
|
86
|
+
const branched = tree && tree.transcripts.size > 1 ? tree : undefined;
|
|
87
|
+
const splits = branched ? splitsAlong(branched, sessionId) : [];
|
|
88
88
|
const prompts = turns.map((p, i) => {
|
|
89
89
|
const next = turns[i + 1]?.line ?? Infinity;
|
|
90
90
|
return { ...p, branched: splits.some((s) => s.line >= p.line && s.line < next) };
|
|
91
91
|
});
|
|
92
|
-
return { projectPath, sessionId, raw, prompts, tree:
|
|
92
|
+
return { projectPath, sessionId, raw, prompts, tree: branched };
|
|
93
93
|
}
|
|
94
94
|
/**
|
|
95
95
|
* The conversation a button names by `session8`, in the chat's project — the
|
|
@@ -213,7 +213,7 @@ export function renderPrompt(conversation, prompt, n, running = false) {
|
|
|
213
213
|
...(prompt.branched ? [plain('🌿 Another branch splits off here.')] : []),
|
|
214
214
|
plain(''),
|
|
215
215
|
youLine(prompt.text, PROMPTS_MAX_CHARS),
|
|
216
|
-
// Cut without pointing at /
|
|
216
|
+
// Cut without pointing at /history: that shows the last few exchanges, which
|
|
217
217
|
// this one may not be among.
|
|
218
218
|
...(reply ? replyQuote(reply, PROMPT_REPLY_LEN, null) : []),
|
|
219
219
|
], '\n');
|
|
@@ -315,7 +315,7 @@ export async function handlePromptsCallback(ctx) {
|
|
|
315
315
|
/**
|
|
316
316
|
* Start a conversation in this chat from the transcript cut just after
|
|
317
317
|
* `prompt`'s reply: a branch, loaded straight away, the way /tree branches
|
|
318
|
-
* from a point and the
|
|
318
|
+
* from a point and the 🌱 under a reply does.
|
|
319
319
|
*/
|
|
320
320
|
async function onBranch(ctx, sessionKey, conversation, prompt, onIt) {
|
|
321
321
|
if (prompt.pending) {
|
|
@@ -325,7 +325,7 @@ async function onBranch(ctx, sessionKey, conversation, prompt, onIt) {
|
|
|
325
325
|
if (await refuseWhileBusy(ctx, sessionKey))
|
|
326
326
|
return;
|
|
327
327
|
const jsonl = cutAfter(conversation, prompt);
|
|
328
|
-
const
|
|
328
|
+
const branch = {
|
|
329
329
|
fromBotName: config.BOT_NAME,
|
|
330
330
|
fromBotId: BOT_ID,
|
|
331
331
|
fromChatId: ctx.chat?.id,
|
|
@@ -337,7 +337,7 @@ async function onBranch(ctx, sessionKey, conversation, prompt, onIt) {
|
|
|
337
337
|
};
|
|
338
338
|
// Above the banner is the conversation branched from, unless the chat had
|
|
339
339
|
// moved on from it before the tap.
|
|
340
|
-
await
|
|
340
|
+
await loadBranch(ctx, sessionKey, branch, onIt ? {} : { above: LEFT_ABOVE });
|
|
341
341
|
await ctx.answerCallbackQuery({ text: 'Branched.' });
|
|
342
342
|
}
|
|
343
343
|
//# sourceMappingURL=prompts.handler.js.map
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* A turn closes with the status line, which counts what runs. A command's
|
|
5
5
|
* answer doesn't, and lands below whatever said a task was running, so after
|
|
6
6
|
* a /btw or a /cost the chat reads as if nothing is going on. Under such an
|
|
7
|
-
* answer the background card comes down again
|
|
8
|
-
*
|
|
7
|
+
* answer the background card comes down again; without a card, a line says
|
|
8
|
+
* how many tasks run.
|
|
9
9
|
*/
|
|
10
10
|
import { isProcessing } from '../../claude/request-queue.js';
|
|
11
11
|
import { bringCardDown } from '../../telegram/background-activity-card.js';
|
|
@@ -16,8 +16,8 @@ import { taskListDisplay } from '../../telegram/task-list.js';
|
|
|
16
16
|
import { homeProject } from '../../utils/home-project.js';
|
|
17
17
|
/** Shown when a handler needs a working directory and no session supplies one. */
|
|
18
18
|
export const NO_PROJECT_MESSAGE = new EntityText()
|
|
19
|
-
.add('⚠️ No project set.\n\nIf the bot restarted, use ').code('/
|
|
20
|
-
.add(' to restore your last session.\nOr use ').code('/
|
|
19
|
+
.add('⚠️ No project set.\n\nIf the bot restarted, use ').code('/resume')
|
|
20
|
+
.add(' to restore your last session.\nOr use ').code('/dir').add(' to open a project first.')
|
|
21
21
|
.build();
|
|
22
22
|
/**
|
|
23
23
|
* Where the chat is: the conversation it's on — or, when a restart dropped
|
|
@@ -39,7 +39,7 @@ export function whereChatIs(sessionKey) {
|
|
|
39
39
|
*
|
|
40
40
|
* For commands that inspect or act on the current session but shouldn't
|
|
41
41
|
* silently revive a dead one — if the bot restarted, the user is told to
|
|
42
|
-
* /
|
|
42
|
+
* /resume rather than having a session rehydrated underneath them.
|
|
43
43
|
* Returns null after replying, so callers just early-return.
|
|
44
44
|
*/
|
|
45
45
|
export async function requireActiveSession(ctx, sessionKey) {
|
|
@@ -62,7 +62,7 @@ export async function requireActiveSession(ctx, sessionKey) {
|
|
|
62
62
|
*/
|
|
63
63
|
export async function requireSession(ctx, sessionKey) {
|
|
64
64
|
const { session: restoredSession, restored } = sessionManager.getOrRestoreSession(sessionKey);
|
|
65
|
-
// A bot made for one project starts there instead of asking for /
|
|
65
|
+
// A bot made for one project starts there instead of asking for /dir.
|
|
66
66
|
const home = restoredSession ? undefined : homeProject();
|
|
67
67
|
const session = restoredSession ?? (home ? sessionManager.createSession(sessionKey, home) : undefined);
|
|
68
68
|
if (!session) {
|
|
@@ -27,7 +27,7 @@ export async function handleSuggestionTapCallback(ctx) {
|
|
|
27
27
|
await ctx.answerCallbackQuery({ text: 'Session not found' });
|
|
28
28
|
return;
|
|
29
29
|
}
|
|
30
|
-
const { sessionKey
|
|
30
|
+
const { sessionKey } = keyInfo;
|
|
31
31
|
const entry = consumeSuggestion(id);
|
|
32
32
|
if (!entry) {
|
|
33
33
|
await ctx.answerCallbackQuery({ text: 'Suggestion expired or already used' });
|
|
@@ -79,6 +79,6 @@ export async function handleSuggestionTapCallback(ctx) {
|
|
|
79
79
|
// Dispatch through the normal pipeline. Lazy import avoids a circular
|
|
80
80
|
// import between this file and message.handler.ts.
|
|
81
81
|
const { dispatchPromptFromCallback, runQueuedTurn } = await import('./message.handler.js');
|
|
82
|
-
await runQueuedTurn(ctx, sessionKey, entry.text, 'Suggestion', () => dispatchPromptFromCallback(ctx, sessionKey,
|
|
82
|
+
await runQueuedTurn(ctx, sessionKey, entry.text, 'Suggestion', () => dispatchPromptFromCallback(ctx, sessionKey, entry.text));
|
|
83
83
|
}
|
|
84
84
|
//# sourceMappingURL=suggestion.handler.js.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* /tree — the branches of a
|
|
2
|
+
* /tree — the branches of a branched conversation, drawn in one message, and a
|
|
3
3
|
* way back to any point in them.
|
|
4
4
|
*
|
|
5
|
-
* The tree is read off the transcripts (see
|
|
5
|
+
* The tree is read off the transcripts (see branch-tree.ts), so it holds every
|
|
6
6
|
* branch still on disk: ones handed to sibling bots, and ones long gone from
|
|
7
7
|
* /resume. The message draws it whole, each point keyed by a letter the way
|
|
8
8
|
* /resume keys its sessions, and the buttons are just the letters. A letter
|
|
@@ -40,18 +40,18 @@ import { sessionManager } from '../../claude/session-manager.js';
|
|
|
40
40
|
import { findHistoryOwners } from '../../claude/session-history.js';
|
|
41
41
|
import { countJsonlLines } from '../../claude/message-offsets.js';
|
|
42
42
|
import { lastAssistantTurnText, lastExchangeIn, sessionJsonlPath } from '../../claude/session-jsonl.js';
|
|
43
|
-
import {
|
|
43
|
+
import { branchedConversations, nodeById, nodeWhereEnds, preorder, promptsIn, transcriptUpTo, treeByRoot, treeOf, } from '../../claude/branch-tree.js';
|
|
44
44
|
import { clearConversation } from '../../providers/provider-router.js';
|
|
45
45
|
import { EntityText, joinMessages, plain } from '../../telegram/entities.js';
|
|
46
46
|
import { replyFormatted } from '../../telegram/send.js';
|
|
47
47
|
import { taskListDisplay } from '../../telegram/task-list.js';
|
|
48
48
|
import { buildLetterKeyboard, buildLetteredKeyboard, letteredOptionLines, optionLetter, } from '../../telegram/lettered-options.js';
|
|
49
49
|
import { cutLabel, promptLabel } from '../../telegram/prompt-label.js';
|
|
50
|
-
import {
|
|
50
|
+
import { restoreTopic, getSessionTopic } from './command.handler.js';
|
|
51
51
|
import { formatTimeAgo } from './command/shared.js';
|
|
52
52
|
import { NO_PROJECT_MESSAGE, whereChatIs } from './session-guard.js';
|
|
53
53
|
import { refuseWhileBusy, sendView } from './view.js';
|
|
54
|
-
import { LEFT_ABOVE, buildBackOnBranchMarker,
|
|
54
|
+
import { LEFT_ABOVE, buildBackOnBranchMarker, loadBranch, postMarker, replyQuote, youLine, } from './branch.handler.js';
|
|
55
55
|
/**
|
|
56
56
|
* How far a line of the drawn tree may run. It sits in a code block so the
|
|
57
57
|
* branches line up, and a phone wraps a code block's lines — which would break
|
|
@@ -65,7 +65,7 @@ const MIN_LABEL_WIDTH = 8;
|
|
|
65
65
|
const MAX_TREE_NODES = 40;
|
|
66
66
|
/**
|
|
67
67
|
* How long a prompt can run before /tree shows only its start and its end —
|
|
68
|
-
* as long as /prompts and the status line let one run. Across the
|
|
68
|
+
* as long as /prompts and the status line let one run. Across the branched
|
|
69
69
|
* conversations on disk, the prompt naming a point has a median of 95
|
|
70
70
|
* characters, where a line of the tree has room for about 23; 93% fit in this.
|
|
71
71
|
*/
|
|
@@ -83,7 +83,7 @@ const NODE_TITLE_LEN = 60;
|
|
|
83
83
|
* away in the conversation it belongs to.
|
|
84
84
|
*/
|
|
85
85
|
const NODE_REPLY_LEN = 1200;
|
|
86
|
-
/**
|
|
86
|
+
/** Branched conversations the list offers when there is no tree to show. */
|
|
87
87
|
const MAX_LISTED_TREES = 8;
|
|
88
88
|
/** The first 8 characters of a tree's root: enough to find it among one project's trees. */
|
|
89
89
|
const rootKey = (tree) => tree.rootId.slice(0, 8);
|
|
@@ -267,7 +267,7 @@ export function renderNode(tree, node, sessionKey, hereSessionId) {
|
|
|
267
267
|
? [
|
|
268
268
|
plain(''),
|
|
269
269
|
youLine(exchange.user, PROMPT_MAX),
|
|
270
|
-
// Cut without pointing at /
|
|
270
|
+
// Cut without pointing at /history: that shows the chat's conversation,
|
|
271
271
|
// which this point may not be on.
|
|
272
272
|
...replyQuote(exchange.assistant, NODE_REPLY_LEN, null),
|
|
273
273
|
]
|
|
@@ -282,19 +282,19 @@ export function renderNode(tree, node, sessionKey, hereSessionId) {
|
|
|
282
282
|
return { text, keyboard };
|
|
283
283
|
}
|
|
284
284
|
/**
|
|
285
|
-
* The
|
|
286
|
-
* the chat is on one that was never
|
|
285
|
+
* The branched conversations in a project, for when there is no tree to show —
|
|
286
|
+
* the chat is on one that was never branched, or on none at all.
|
|
287
287
|
*/
|
|
288
288
|
export function renderTreeList(projectPath, intro) {
|
|
289
289
|
const project = path.basename(projectPath);
|
|
290
|
-
const conversations =
|
|
290
|
+
const conversations = branchedConversations(projectPath).slice(0, MAX_LISTED_TREES);
|
|
291
291
|
if (conversations.length === 0) {
|
|
292
292
|
return {
|
|
293
293
|
text: joinMessages([
|
|
294
294
|
...(intro ? [plain(intro), plain('')] : []),
|
|
295
|
-
new EntityText().add('🌳 No conversation in ').bold(project).add(' has been
|
|
295
|
+
new EntityText().add('🌳 No conversation in ').bold(project).add(' has been branched yet.').build(),
|
|
296
296
|
plain(''),
|
|
297
|
-
plain('Tap
|
|
297
|
+
plain('Tap 🌱 Branch under a reply to start one.'),
|
|
298
298
|
], '\n'),
|
|
299
299
|
keyboard: [],
|
|
300
300
|
};
|
|
@@ -306,7 +306,7 @@ export function renderTreeList(projectPath, intro) {
|
|
|
306
306
|
return {
|
|
307
307
|
text: joinMessages([
|
|
308
308
|
...(intro ? [plain(intro), plain('')] : []),
|
|
309
|
-
new EntityText().add('🌳 ').bold('
|
|
309
|
+
new EntityText().add('🌳 ').bold('Branched conversations').add(` · ${project}`).build(),
|
|
310
310
|
plain(''),
|
|
311
311
|
...letteredOptionLines(options).map(plain),
|
|
312
312
|
], '\n'),
|
|
@@ -324,8 +324,8 @@ function currentView(sessionKey) {
|
|
|
324
324
|
const intro = !where.sessionId
|
|
325
325
|
? undefined
|
|
326
326
|
: where.live
|
|
327
|
-
? "This conversation hasn't been
|
|
328
|
-
: "The conversation this chat left off in hasn't been
|
|
327
|
+
? "This conversation hasn't been branched yet."
|
|
328
|
+
: "The conversation this chat left off in hasn't been branched.";
|
|
329
329
|
return renderTreeList(where.projectPath, intro);
|
|
330
330
|
}
|
|
331
331
|
/** A button that draws `tree` in place of the message it's on: the way into it from another view. */
|
|
@@ -428,7 +428,7 @@ async function onCarryOn(ctx, sessionKey, tree, node, here) {
|
|
|
428
428
|
return;
|
|
429
429
|
}
|
|
430
430
|
clearConversation(sessionKey);
|
|
431
|
-
|
|
431
|
+
restoreTopic(sessionKey, carry.owner.entry.topic);
|
|
432
432
|
const file = sessionJsonlPath(tree.projectPath, carry.sessionId);
|
|
433
433
|
let jsonl = '';
|
|
434
434
|
try {
|
|
@@ -455,7 +455,7 @@ async function onBranch(ctx, sessionKey, tree, node, here) {
|
|
|
455
455
|
await ctx.answerCallbackQuery({ text: 'Branched.' });
|
|
456
456
|
}
|
|
457
457
|
/**
|
|
458
|
-
* Start a conversation in this chat from the transcript cut at `node`: a
|
|
458
|
+
* Start a conversation in this chat from the transcript cut at `node`: a branch,
|
|
459
459
|
* loaded straight away. From another bot's branch it is named as that bot's,
|
|
460
460
|
* so the banner says where it came from. False if the transcript is gone.
|
|
461
461
|
*/
|
|
@@ -464,7 +464,7 @@ async function branchFrom(ctx, sessionKey, tree, node, owner, topic = owner?.ent
|
|
|
464
464
|
if (!jsonl)
|
|
465
465
|
return false;
|
|
466
466
|
const fromOtherBot = owner && owner.botId !== BOT_ID;
|
|
467
|
-
const
|
|
467
|
+
const branch = {
|
|
468
468
|
fromBotName: fromOtherBot ? (findBotById(owner.botId)?.name ?? 'another bot') : config.BOT_NAME,
|
|
469
469
|
fromBotId: fromOtherBot ? owner.botId : BOT_ID,
|
|
470
470
|
fromChatId: ctx.chat?.id,
|
|
@@ -474,7 +474,7 @@ async function branchFrom(ctx, sessionKey, tree, node, owner, topic = owner?.ent
|
|
|
474
474
|
assistantPreview: lastAssistantTurnText(jsonl)?.substring(0, 200),
|
|
475
475
|
createdAt: new Date().toISOString(),
|
|
476
476
|
};
|
|
477
|
-
await
|
|
477
|
+
await loadBranch(ctx, sessionKey, branch, { above: LEFT_ABOVE });
|
|
478
478
|
return true;
|
|
479
479
|
}
|
|
480
480
|
//# sourceMappingURL=tree.handler.js.map
|