@llblab/pi-telegram 0.27.12 → 0.29.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/AGENTS.md +152 -258
- package/BACKLOG.md +1 -169
- package/CHANGELOG.md +398 -443
- package/README.md +10 -7
- package/api/updates.ts +5 -0
- package/docs/architecture.md +73 -28
- package/docs/multi-instance-bus.md +23 -5
- package/docs/outbound.md +2 -2
- package/docs/public-api.md +8 -7
- package/docs/ui-style.md +6 -6
- package/docs/updates.md +29 -11
- package/index.ts +358 -246
- package/lib/activity-verbosity.ts +26 -0
- package/lib/bindings.ts +240 -5
- package/lib/bus-follower.ts +436 -238
- package/lib/bus-leader.ts +395 -42
- package/lib/bus.ts +994 -153
- package/lib/commands.ts +184 -30
- package/lib/config.ts +23 -2
- package/lib/journal.ts +3140 -0
- package/lib/lifecycle.ts +4 -0
- package/lib/locks.ts +4 -2
- package/lib/media.ts +71 -32
- package/lib/menu-queue.ts +31 -17
- package/lib/menu.ts +5 -3
- package/lib/model.ts +51 -24
- package/lib/ownership.ts +42 -7
- package/lib/paths.ts +35 -0
- package/lib/polling.ts +591 -106
- package/lib/prompts.ts +20 -89
- package/lib/queue.ts +732 -143
- package/lib/routing.ts +291 -64
- package/lib/runtime.ts +26 -10
- package/lib/skills.ts +21 -0
- package/lib/status.ts +257 -18
- package/lib/sync.ts +131 -5
- package/lib/telegram-api.ts +41 -11
- package/lib/text-groups.ts +75 -35
- package/lib/threads.ts +112 -4
- package/lib/turns.ts +79 -14
- package/lib/updates.ts +3771 -223
- package/package.json +7 -3
- package/scripts/check-downgrade.mjs +435 -0
- package/skills/button-console/SKILL.md +139 -0
- package/skills/telegram-bridge/SKILL.md +138 -0
package/lib/prompts.ts
CHANGED
|
@@ -4,19 +4,16 @@
|
|
|
4
4
|
* Owns Telegram-specific system prompt suffixes injected into pi agent turns
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
import { getTelegramDiagnosticsDisplayPaths } from "./paths.ts";
|
|
10
|
-
import type { BeforeAgentStartEvent, ExtensionAPI } from "./pi.ts";
|
|
7
|
+
import type { BeforeAgentStartEvent } from "./pi.ts";
|
|
11
8
|
import { TELEGRAM_PREFIX } from "./turns.ts";
|
|
12
9
|
|
|
13
10
|
const LOCAL_SYSTEM_PROMPT_SUFFIX = `
|
|
14
11
|
|
|
15
|
-
Telegram bridge available. Do not use
|
|
12
|
+
Telegram bridge available. Load the \`telegram-bridge\` Skill for Telegram delivery, actions, Threaded Mode, or diagnosis. Do not use Telegram from local/TUI prompts unless explicitly asked.`;
|
|
16
13
|
|
|
17
14
|
const TELEGRAM_TURN_SYSTEM_PROMPT_SUFFIX = `
|
|
18
15
|
|
|
19
|
-
Telegram turn note:
|
|
16
|
+
Telegram turn note: Load and follow the \`telegram-bridge\` Skill.`;
|
|
20
17
|
|
|
21
18
|
export const TELEGRAM_ATTACH_PROMPT_SNIPPET =
|
|
22
19
|
"Queue files for the active Telegram reply; outside Telegram turns, send files directly to Telegram.";
|
|
@@ -37,7 +34,6 @@ export const TELEGRAM_MESSAGE_PROMPT_GUIDELINES = [
|
|
|
37
34
|
const TELEGRAM_MODEL_CONTEXT_TOOL_NAMES = new Set([
|
|
38
35
|
"telegram_attach",
|
|
39
36
|
"telegram_message",
|
|
40
|
-
"telegram_help",
|
|
41
37
|
]);
|
|
42
38
|
const TELEGRAM_MODEL_CONTEXT_MEMORY_KEY = Symbol.for(
|
|
43
39
|
"@llblab/pi-telegram:model-context-suspended-tools",
|
|
@@ -71,6 +67,23 @@ export interface TelegramModelContextAvailabilityRuntime {
|
|
|
71
67
|
reconcile: () => void;
|
|
72
68
|
}
|
|
73
69
|
|
|
70
|
+
export interface TelegramModelContextAvailabilityBinding
|
|
71
|
+
extends TelegramModelContextAvailabilityRuntime {
|
|
72
|
+
bind: (runtime: TelegramModelContextAvailabilityRuntime) => void;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function createTelegramModelContextAvailabilityBinding(): TelegramModelContextAvailabilityBinding {
|
|
76
|
+
let runtime: TelegramModelContextAvailabilityRuntime | undefined;
|
|
77
|
+
return {
|
|
78
|
+
bind(next) {
|
|
79
|
+
runtime = next;
|
|
80
|
+
},
|
|
81
|
+
reconcile() {
|
|
82
|
+
runtime?.reconcile();
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
74
87
|
export function createTelegramModelContextAvailabilityRuntime(deps: {
|
|
75
88
|
getActiveTools: () => string[];
|
|
76
89
|
setActiveTools: (names: string[]) => void;
|
|
@@ -118,88 +131,6 @@ export function createTelegramModelContextAvailabilityRuntime(deps: {
|
|
|
118
131
|
};
|
|
119
132
|
}
|
|
120
133
|
|
|
121
|
-
function buildTelegramHelpText(profileName?: string): string {
|
|
122
|
-
const diagnosticsPaths = getTelegramDiagnosticsDisplayPaths(profileName);
|
|
123
|
-
return `--- TELEGRAM BRIDGE HELP ---
|
|
124
|
-
|
|
125
|
-
How to understand Telegram turns:
|
|
126
|
-
- \`[telegram|thread:name|from:user|guest:group]\` marks Telegram origin and attributes.
|
|
127
|
-
- \`thread\` is the visible Thread identity in Threaded Mode; it is not a bus role.
|
|
128
|
-
- \`[reply]\` is quoted context only; act on the user's current instruction.
|
|
129
|
-
- \`[attachments]\` are local files; \`[outputs]\` are handler results/transcripts; \`[time]\` is wall-clock context.
|
|
130
|
-
- \`[voice] delivery: automatic voice\` means pi-telegram will synthesize ordinary assistant text for this turn; no \`[voice]\` line means no automatic voice policy.
|
|
131
|
-
|
|
132
|
-
How to answer Telegram turns:
|
|
133
|
-
- Reply in concise, scannable mobile Telegram Rich Markdown.
|
|
134
|
-
- Use \`$...$\` for inline math and \`$$...$$\` for block math.
|
|
135
|
-
- Real code blocks must stay literal.
|
|
136
|
-
- For generated/requested files, call \`telegram_attach(local_path)\`; do not only mention the path.
|
|
137
|
-
|
|
138
|
-
Assistant-authored Telegram actions:
|
|
139
|
-
- \`telegram_voice\` and \`telegram_button\` are hidden top-level HTML comments, not Pi tools.
|
|
140
|
-
- Put action comments at column zero, outside code, quotes, lists, and indented examples.
|
|
141
|
-
- Action payloads use either JSON or double-quoted attributes; the colon after the action name is optional and does not affect parsing. Voice accepts equivalent \`text\` or \`value\`: \`<!-- telegram_voice: {"value":"Short summary","lang":"en"} -->\` or \`<!-- telegram_voice text="Short summary" lang="en" -->\`.
|
|
142
|
-
- Keep the complete action in one top-level comment and include non-empty \`text\` or \`value\`; encode line breaks inside JSON strings as \`\\n\`.
|
|
143
|
-
- Keep voice text TTS-friendly; avoid raw Markdown, code, and tables in voice text.
|
|
144
|
-
- Voice delivery generates and attaches OGG automatically; do not also call \`telegram_attach\` for the same audio.
|
|
145
|
-
- Voice reply modes are compact: \`hidden\` emits no automatic context, \`mirror\` emits it for voice/audio input, and \`always\` emits it for every Telegram turn. Explicit \`telegram_voice\` remains available for an intentionally distinct spoken payload.
|
|
146
|
-
- Button payloads use \`label\` plus \`prompt\`, or compact \`value\` when both are identical: \`<!-- telegram_button: {"label":"Continue","prompt":"Continue with the current plan."} -->\` or \`<!-- telegram_button value="Continue" -->\`.
|
|
147
|
-
- Optional \`selected_style\` in either payload form controls the button after queue admission: \`primary\` (default, blue), \`success\` (green), or \`danger\` (red). It never suppresses the prompt.
|
|
148
|
-
- If hidden button comments form the whole reply, the bridge supplies the standard \`☑️ **Choose an option:**\` heading automatically.
|
|
149
|
-
|
|
150
|
-
Local/TUI direct delivery:
|
|
151
|
-
- Do not send Telegram actions from local/TUI prompts unless explicitly asked.
|
|
152
|
-
- Use \`telegram_attach\` for files and \`telegram_message\` for direct Markdown text.
|
|
153
|
-
- Direct delivery requires this Pi instance to own \`/telegram-connect\` or be registered with the Threaded Mode bus.
|
|
154
|
-
- For explicit targets, pass \`chat_id\` plus optional \`thread_id\`; registered followers default to their assigned Thread target.
|
|
155
|
-
- Do not use \`telegram_message\` for ordinary Telegram-originated replies; answer normally and let the bridge deliver the active turn reply.
|
|
156
|
-
|
|
157
|
-
Threaded Mode:
|
|
158
|
-
- pi-telegram supports private-chat Threaded Mode when Telegram exposes thread support for the bot.
|
|
159
|
-
- Product/user language is Thread; Bot API primitive names may still say topic.
|
|
160
|
-
- Threaded Mode has one leader transport and visible follower Pi processes joined manually through \`/telegram-connect\`.
|
|
161
|
-
- Thread names are bridge-assigned or preserved identities; do not invent rename prompts or use a rename tool.
|
|
162
|
-
- The \`All\` surface is for routing/control, not hidden Pi process creation.
|
|
163
|
-
|
|
164
|
-
Configurable handlers:
|
|
165
|
-
- \`telegram.json\` can add no-code \`inboundHandlers\`/\`outboundHandlers\` using command templates before writing an extension.
|
|
166
|
-
- For speech-to-text, configure an \`inboundHandlers\` entry matching \`type: "voice"\` or \`mime: "audio/*"\`; stdout becomes \`[outputs]\` prompt context.
|
|
167
|
-
- If command-template config is not enough, build a companion extension through the public pi-telegram APIs; do not import package-private \`lib/*\` paths.
|
|
168
|
-
|
|
169
|
-
Debugging pi-telegram:
|
|
170
|
-
- Inspect \`${diagnosticsPaths.state}\` for runtime state, roster, bindings, slots, reservations, and diagnostics.
|
|
171
|
-
- Inspect \`${diagnosticsPaths.logs}\` for redacted runtime event evidence.
|
|
172
|
-
- Use terminal \`telegram-status\` for compact human health; use \`telegram-status --debug\` for the full human-readable diagnostic dump.`;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
export function getTelegramHelpText(profileName?: string): string {
|
|
176
|
-
return buildTelegramHelpText(profileName);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
export function registerTelegramHelpTool(
|
|
180
|
-
pi: ExtensionAPI,
|
|
181
|
-
options: { getActiveProfileName?: () => string | undefined } = {},
|
|
182
|
-
): void {
|
|
183
|
-
pi.registerTool({
|
|
184
|
-
name: "telegram_help",
|
|
185
|
-
label: "Telegram Help",
|
|
186
|
-
description:
|
|
187
|
-
"Read pi-telegram usage guidance for delivery actions, Threaded Mode, handlers, formatting, and debugging.",
|
|
188
|
-
parameters: Type.Object({}),
|
|
189
|
-
async execute() {
|
|
190
|
-
return {
|
|
191
|
-
content: [
|
|
192
|
-
{
|
|
193
|
-
type: "text",
|
|
194
|
-
text: getTelegramHelpText(options.getActiveProfileName?.()),
|
|
195
|
-
},
|
|
196
|
-
],
|
|
197
|
-
details: {},
|
|
198
|
-
};
|
|
199
|
-
},
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
|
|
203
134
|
export function buildTelegramBridgeSystemPrompt(options: {
|
|
204
135
|
prompt: string;
|
|
205
136
|
systemPrompt: string;
|