fix: show session title and workspace in /sessions picker
Read cwd from session.header (not only meta) and title from sessionTitle service or session/title events; list details in the message body and richer inline buttons. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+15
-14
@@ -4,6 +4,7 @@ import { isAuthorized } from './auth.js';
|
||||
import { TelegramClient, } from './client.js';
|
||||
import { BIND_CB_PREFIX, MSG, parseCommand } from './commands.js';
|
||||
import { markdownToHtml, splitMessage } from './format.js';
|
||||
import { buttonLabel, describeAgent, detailLines, displayLabel } from './label.js';
|
||||
const defaultSleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
function contentToText(content) {
|
||||
return content
|
||||
@@ -11,14 +12,6 @@ function contentToText(content) {
|
||||
.map((block) => block.text)
|
||||
.join('');
|
||||
}
|
||||
function shortLabel(agent, index) {
|
||||
const id = String(agent.id);
|
||||
const tail = id.length > 12 ? id.slice(-12) : id;
|
||||
const cwd = agent.session?.meta?.cwd;
|
||||
const cwdBit = cwd ? cwd.split(/[/\\]/).filter(Boolean).slice(-1)[0] : '';
|
||||
const base = cwdBit ? `${cwdBit} · ${tail}` : `session ${index + 1} · ${tail}`;
|
||||
return base.length > 60 ? `${base.slice(0, 57)}...` : base;
|
||||
}
|
||||
export class TelegramBridge {
|
||||
ctx;
|
||||
token;
|
||||
@@ -147,7 +140,7 @@ export class TelegramBridge {
|
||||
await this.client.sendMessage(chatId, MSG.GONE);
|
||||
return;
|
||||
}
|
||||
const label = shortLabel(agent, 0);
|
||||
const label = displayLabel(describeAgent(agent, 0, this.ctx));
|
||||
this.bindings.set(String(chatId), { chatId, sessionId: String(agent.id), label });
|
||||
await this.client.answerCallbackQuery(cq.id, '已附着');
|
||||
await this.client.sendMessage(chatId, MSG.BOUND(label));
|
||||
@@ -183,13 +176,21 @@ export class TelegramBridge {
|
||||
await this.client.sendMessage(chatId, MSG.NO_LIVE);
|
||||
return;
|
||||
}
|
||||
const described = agents.map((agent, i) => describeAgent(agent, i, this.ctx));
|
||||
const keyboard = {
|
||||
inline_keyboard: agents.map((agent, i) => {
|
||||
const label = shortLabel(agent, i);
|
||||
return [{ text: label, callback_data: `${BIND_CB_PREFIX}${String(agent.id)}` }];
|
||||
}),
|
||||
inline_keyboard: described.map((parts) => ([{
|
||||
text: buttonLabel(parts),
|
||||
callback_data: `${BIND_CB_PREFIX}${parts.sessionId}`,
|
||||
}])),
|
||||
};
|
||||
await this.client.sendMessage(chatId, `选择要遥控的本机会话(共 ${agents.length} 个):`, undefined, keyboard);
|
||||
const body = [
|
||||
`选择要遥控的本机会话(共 ${agents.length} 个):`,
|
||||
'',
|
||||
...described.map((parts) => detailLines(parts)),
|
||||
'',
|
||||
'点下方按钮附着对应会话。',
|
||||
].join('\n');
|
||||
await this.client.sendMessage(chatId, body, undefined, keyboard);
|
||||
}
|
||||
async sendStatus(chatId) {
|
||||
const binding = this.bindings.get(String(chatId));
|
||||
|
||||
Reference in New Issue
Block a user