appback-remoteagent 0.13.10 → 0.13.11

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.
Files changed (2) hide show
  1. package/dist/bot.js +56 -4
  2. package/package.json +1 -1
package/dist/bot.js CHANGED
@@ -1090,8 +1090,9 @@ async function runWithPendingAnimation(botToken, chatId, task) {
1090
1090
  if (progressChunks.length === 0 && normalized.documents.length === 0) {
1091
1091
  return;
1092
1092
  }
1093
- const extra = parseMode ? { parse_mode: parseMode } : undefined;
1094
- for (const chunk of progressChunks) {
1093
+ const rendered = formatProviderTelegramChunks(progressChunks, parseMode);
1094
+ const extra = rendered.parseMode ? { parse_mode: rendered.parseMode } : undefined;
1095
+ for (const chunk of rendered.chunks) {
1095
1096
  await sendTelegramMessage(botToken, chatId, chunk, extra);
1096
1097
  }
1097
1098
  if (normalized.documents.length > 0) {
@@ -1102,12 +1103,13 @@ async function runWithPendingAnimation(botToken, chatId, task) {
1102
1103
  const result = await task(helpers);
1103
1104
  const normalized = await normalizeTelegramDelivery(result.chunks);
1104
1105
  const chunks = flattenChunks(normalized.chunks, 3900);
1105
- const extra = result.parseMode ? { parse_mode: result.parseMode } : undefined;
1106
1106
  if (chunks.length === 0 && normalized.documents.length === 0) {
1107
1107
  await sendTelegramMessage(botToken, chatId, "Response was empty.");
1108
1108
  return;
1109
1109
  }
1110
- for (const chunk of chunks) {
1110
+ const rendered = formatProviderTelegramChunks(chunks, result.parseMode);
1111
+ const extra = rendered.parseMode ? { parse_mode: rendered.parseMode } : undefined;
1112
+ for (const chunk of rendered.chunks) {
1111
1113
  await sendTelegramMessage(botToken, chatId, chunk, extra);
1112
1114
  }
1113
1115
  if (normalized.documents.length > 0) {
@@ -1357,6 +1359,56 @@ function parseReportResponses(formattedBlocks, transform) {
1357
1359
  const chunks = transform(parsedBlocks.map((item) => item.text));
1358
1360
  return { kind, chunks };
1359
1361
  }
1362
+ function formatProviderTelegramChunks(chunks, explicitParseMode) {
1363
+ if (explicitParseMode) {
1364
+ return { chunks, parseMode: explicitParseMode };
1365
+ }
1366
+ return {
1367
+ chunks: chunks.map((chunk) => renderTelegramHtml(chunk)),
1368
+ parseMode: "HTML",
1369
+ };
1370
+ }
1371
+ function renderTelegramHtml(text) {
1372
+ const lines = text.split(/\r?\n/);
1373
+ const rendered = [];
1374
+ let codeFence;
1375
+ for (const line of lines) {
1376
+ if (/^```\w*\s*$/.test(line.trim())) {
1377
+ if (codeFence) {
1378
+ rendered.push(`<pre>${escapeTelegramHtml(codeFence.join("\n"))}</pre>`);
1379
+ codeFence = undefined;
1380
+ }
1381
+ else {
1382
+ codeFence = [];
1383
+ }
1384
+ continue;
1385
+ }
1386
+ if (codeFence) {
1387
+ codeFence.push(line);
1388
+ continue;
1389
+ }
1390
+ rendered.push(renderTelegramInlineHtml(line));
1391
+ }
1392
+ if (codeFence) {
1393
+ rendered.push(`<pre>${escapeTelegramHtml(codeFence.join("\n"))}</pre>`);
1394
+ }
1395
+ return rendered.join("\n");
1396
+ }
1397
+ function renderTelegramInlineHtml(line) {
1398
+ const parts = line.split(/(`[^`\n]+`)/g);
1399
+ return parts.map((part) => {
1400
+ if (part.startsWith("`") && part.endsWith("`") && part.length >= 2) {
1401
+ return `<code>${escapeTelegramHtml(part.slice(1, -1))}</code>`;
1402
+ }
1403
+ return escapeTelegramHtml(part);
1404
+ }).join("");
1405
+ }
1406
+ function escapeTelegramHtml(value) {
1407
+ return value
1408
+ .replace(/&/g, "&amp;")
1409
+ .replace(/</g, "&lt;")
1410
+ .replace(/>/g, "&gt;");
1411
+ }
1360
1412
  function looksLikeUntaggedIntentOnlyResponse(text) {
1361
1413
  const normalized = text.trim();
1362
1414
  if (!normalized) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "appback-remoteagent",
3
- "version": "0.13.10",
3
+ "version": "0.13.11",
4
4
  "description": "Personal installable session server for continuing local AI work across PC and Telegram",
5
5
  "license": "MIT",
6
6
  "type": "module",