@qusic/pi-telegram 0.2.0 → 0.2.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qusic/pi-telegram",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Telegram bridge extension for Pi agent",
5
5
  "keywords": [
6
6
  "pi-package",
package/src/toolcall.ts CHANGED
@@ -4,8 +4,11 @@
4
4
  import { type createApi, MAX_MESSAGE_LENGTH } from "./api.ts";
5
5
 
6
6
  const EDIT_THROTTLE_MS = 500;
7
- const NAME_MAX = 64;
8
- const SUMMARY_MAX = 96;
7
+ // Heuristic for a compact mobile row; actual wrap depends on chat width and font.
8
+ const NAME_MAX = 24;
9
+ const SUMMARY_MAX = 24;
10
+ // A bare newline is a soft break in GFM and can render as a space.
11
+ const TOOL_LINE_BREAK = " \n";
9
12
 
10
13
  const STATUS_ICON = {
11
14
  running: "🔧",
@@ -121,7 +124,7 @@ export function createToolMessages(api: ToolApi) {
121
124
 
122
125
  async function flush(batch: ToolBatch): Promise<void> {
123
126
  for (const page of batch.pages) {
124
- const text = page.lines.map(renderLine).join("\n");
127
+ const text = page.lines.map(renderLine).join(TOOL_LINE_BREAK);
125
128
  if (text === page.lastText) continue;
126
129
  try {
127
130
  if (page.messageId === undefined) {
@@ -163,9 +166,9 @@ export function createToolMessages(api: ToolApi) {
163
166
  status: "running",
164
167
  };
165
168
  batch.calls.set(call.toolCallId, line);
166
- // Running and cancelled icons have the same length; reserve a newline
169
+ // Running and cancelled icons have the same length; reserve a break
167
170
  // so status edits never move a line between pages.
168
- const budget = renderLine(line).length + 1;
171
+ const budget = renderLine(line).length + TOOL_LINE_BREAK.length;
169
172
  let page = batch.pages.at(-1);
170
173
  if (!page || page.budget + budget > MAX_MESSAGE_LENGTH) {
171
174
  page = { lines: [], budget: 0, messageId: undefined, lastText: "" };
package/src/utils.ts CHANGED
@@ -62,8 +62,10 @@ export function getMessageText(message: AssistantMessage): string {
62
62
  let prevType: "text" | "thinking" = "text";
63
63
  for (const block of message.content) {
64
64
  if (block.type !== "text" && block.type !== "thinking") continue;
65
+ const content = block.type === "text" ? block.text : block.thinking;
66
+ if (!content.trim()) continue;
65
67
  const marker = block.type === prevType ? "" : SECTION_MARKER[block.type];
66
- parts.push(marker + (block.type === "text" ? block.text : block.thinking));
68
+ parts.push(marker + content);
67
69
  prevType = block.type;
68
70
  }
69
71
  return parts.join("\n\n").trim();