@llblab/pi-telegram 0.46.0 → 0.48.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 +4 -2
- package/BACKLOG.md +0 -6
- package/CHANGELOG.md +14 -0
- package/README.md +5 -2
- package/dist/api/activity.d.ts +6 -0
- package/dist/api/activity.js +6 -0
- package/dist/api/commands.d.ts +6 -0
- package/dist/api/commands.js +6 -0
- package/dist/api/delivery.d.ts +6 -0
- package/dist/api/delivery.js +6 -0
- package/dist/api/inbound.d.ts +6 -0
- package/dist/api/inbound.js +6 -0
- package/dist/api/keyboard.d.ts +6 -0
- package/dist/api/keyboard.js +6 -0
- package/dist/api/outbound.d.ts +6 -0
- package/dist/api/outbound.js +6 -0
- package/dist/api/sections.d.ts +7 -0
- package/dist/api/sections.js +6 -0
- package/dist/api/status.d.ts +6 -0
- package/dist/api/status.js +6 -0
- package/dist/api/updates.d.ts +6 -0
- package/dist/api/updates.js +6 -0
- package/dist/api/voice.d.ts +6 -0
- package/dist/api/voice.js +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/lib/activity-verbosity.d.ts +52 -0
- package/dist/lib/activity-verbosity.js +596 -0
- package/dist/lib/activity.d.ts +220 -0
- package/dist/lib/activity.js +574 -0
- package/dist/lib/agent-messages.d.ts +28 -0
- package/dist/lib/agent-messages.js +86 -0
- package/dist/lib/bindings.d.ts +250 -0
- package/dist/lib/bindings.js +936 -0
- package/dist/lib/bus-api.d.ts +18 -0
- package/dist/lib/bus-api.js +254 -0
- package/dist/lib/bus-follower.d.ts +464 -0
- package/dist/lib/bus-follower.js +1686 -0
- package/dist/lib/bus-leader.d.ts +292 -0
- package/dist/lib/bus-leader.js +2242 -0
- package/dist/lib/bus-transport.d.ts +64 -0
- package/dist/lib/bus-transport.js +140 -0
- package/dist/lib/bus.d.ts +518 -0
- package/dist/lib/bus.js +2055 -0
- package/dist/lib/channel-posts.d.ts +170 -0
- package/dist/lib/channel-posts.js +611 -0
- package/dist/lib/command-templates.d.ts +70 -0
- package/dist/lib/command-templates.js +744 -0
- package/dist/lib/commands.d.ts +541 -0
- package/dist/lib/commands.js +1155 -0
- package/dist/lib/config.d.ts +252 -0
- package/dist/lib/config.js +889 -0
- package/dist/lib/delivery.d.ts +163 -0
- package/dist/lib/delivery.js +542 -0
- package/dist/lib/extension.d.ts +7 -0
- package/dist/lib/extension.js +1604 -0
- package/dist/lib/generative-app-worker.mjs +104 -0
- package/dist/lib/generative-apps.d.ts +212 -0
- package/dist/lib/generative-apps.js +1006 -0
- package/dist/lib/inbound.d.ts +91 -0
- package/dist/lib/inbound.js +502 -0
- package/dist/lib/journal.d.ts +665 -0
- package/dist/lib/journal.js +3701 -0
- package/dist/lib/keyboard.d.ts +23 -0
- package/dist/lib/keyboard.js +37 -0
- package/dist/lib/lifecycle.d.ts +157 -0
- package/dist/lib/lifecycle.js +395 -0
- package/dist/lib/locks.d.ts +164 -0
- package/dist/lib/locks.js +1208 -0
- package/dist/lib/logging.d.ts +50 -0
- package/dist/lib/logging.js +274 -0
- package/dist/lib/media.d.ts +181 -0
- package/dist/lib/media.js +602 -0
- package/dist/lib/menu-model.d.ts +217 -0
- package/dist/lib/menu-model.js +663 -0
- package/dist/lib/menu-queue.d.ts +37 -0
- package/dist/lib/menu-queue.js +408 -0
- package/dist/lib/menu-settings.d.ts +115 -0
- package/dist/lib/menu-settings.js +595 -0
- package/dist/lib/menu-status.d.ts +32 -0
- package/dist/lib/menu-status.js +112 -0
- package/dist/lib/menu-thinking.d.ts +29 -0
- package/dist/lib/menu-thinking.js +82 -0
- package/dist/lib/menu.d.ts +171 -0
- package/dist/lib/menu.js +323 -0
- package/dist/lib/model.d.ts +127 -0
- package/dist/lib/model.js +409 -0
- package/dist/lib/outbound-attachments.d.ts +241 -0
- package/dist/lib/outbound-attachments.js +639 -0
- package/dist/lib/outbound-buttons.d.ts +69 -0
- package/dist/lib/outbound-buttons.js +248 -0
- package/dist/lib/outbound-markup.d.ts +42 -0
- package/dist/lib/outbound-markup.js +678 -0
- package/dist/lib/outbound-voice.d.ts +55 -0
- package/dist/lib/outbound-voice.js +152 -0
- package/dist/lib/outbound.d.ts +185 -0
- package/dist/lib/outbound.js +516 -0
- package/dist/lib/ownership.d.ts +77 -0
- package/dist/lib/ownership.js +174 -0
- package/dist/lib/paths.d.ts +40 -0
- package/dist/lib/paths.js +94 -0
- package/dist/lib/pi.d.ts +72 -0
- package/dist/lib/pi.js +121 -0
- package/dist/lib/polling.d.ts +351 -0
- package/dist/lib/polling.js +1196 -0
- package/dist/lib/preview.d.ts +192 -0
- package/dist/lib/preview.js +614 -0
- package/dist/lib/prompt-templates.d.ts +24 -0
- package/dist/lib/prompt-templates.js +118 -0
- package/dist/lib/prompts.d.ts +57 -0
- package/dist/lib/prompts.js +167 -0
- package/dist/lib/queue.d.ts +766 -0
- package/dist/lib/queue.js +1965 -0
- package/dist/lib/recovery.d.ts +86 -0
- package/dist/lib/recovery.js +285 -0
- package/dist/lib/rendering.d.ts +20 -0
- package/dist/lib/rendering.js +983 -0
- package/dist/lib/replies.d.ts +214 -0
- package/dist/lib/replies.js +737 -0
- package/dist/lib/routing.d.ts +207 -0
- package/dist/lib/routing.js +2282 -0
- package/dist/lib/runtime.d.ts +172 -0
- package/dist/lib/runtime.js +402 -0
- package/dist/lib/sections.d.ts +165 -0
- package/dist/lib/sections.js +327 -0
- package/dist/lib/setup.d.ts +82 -0
- package/dist/lib/setup.js +150 -0
- package/dist/lib/skills.d.ts +8 -0
- package/dist/lib/skills.js +12 -0
- package/dist/lib/status.d.ts +442 -0
- package/dist/lib/status.js +1008 -0
- package/dist/lib/sync.d.ts +179 -0
- package/dist/lib/sync.js +782 -0
- package/dist/lib/target.d.ts +20 -0
- package/dist/lib/target.js +27 -0
- package/dist/lib/telegram-api.d.ts +541 -0
- package/dist/lib/telegram-api.js +1159 -0
- package/dist/lib/text-groups.d.ts +89 -0
- package/dist/lib/text-groups.js +317 -0
- package/dist/lib/thread-cleanup-manager.d.ts +288 -0
- package/dist/lib/thread-cleanup-manager.js +560 -0
- package/dist/lib/thread-display.d.ts +46 -0
- package/dist/lib/thread-display.js +257 -0
- package/dist/lib/thread-naming.d.ts +46 -0
- package/dist/lib/thread-naming.js +78 -0
- package/dist/lib/thread-reconciler.d.ts +239 -0
- package/dist/lib/thread-reconciler.js +644 -0
- package/dist/lib/threads.d.ts +621 -0
- package/dist/lib/threads.js +3679 -0
- package/dist/lib/time-injection.d.ts +15 -0
- package/dist/lib/time-injection.js +56 -0
- package/dist/lib/turns.d.ts +109 -0
- package/dist/lib/turns.js +500 -0
- package/dist/lib/updates.d.ts +1290 -0
- package/dist/lib/updates.js +3634 -0
- package/dist/lib/voice.d.ts +117 -0
- package/dist/lib/voice.js +174 -0
- package/dist/lib/workspace-admission.d.ts +264 -0
- package/dist/lib/workspace-admission.js +1136 -0
- package/dist/lib/workspace-retirement.d.ts +219 -0
- package/dist/lib/workspace-retirement.js +587 -0
- package/dist/lib/workspace-slots.d.ts +30 -0
- package/dist/lib/workspace-slots.js +54 -0
- package/dist/package.json +126 -0
- package/dist/pi-telegram/index.js +1 -0
- package/dist/skills/generated-control-surface/SKILL.md +107 -0
- package/dist/skills/generated-control-surface/references/capability-adapters.md +27 -0
- package/dist/skills/generated-control-surface/references/layout-and-state.md +37 -0
- package/dist/skills/generative-apps/SKILL.md +115 -0
- package/dist/skills/show-me/SKILL.md +166 -0
- package/dist/skills/show-me/references/telegram-surfaces.md +43 -0
- package/dist/skills/telegram-bridge/SKILL.md +129 -0
- package/dist/skills/telegram-bridge/references/configuration.md +15 -0
- package/dist/skills/telegram-bridge/references/delivery-and-threads.md +27 -0
- package/dist/skills/telegram-bridge/references/diagnosis.md +18 -0
- package/docs/README.md +2 -0
- package/docs/architecture.md +1 -1
- package/docs/compact-matrix-literal.md +10 -3
- package/docs/generative-apps.md +15 -13
- package/docs/multi-instance-bus.md +6 -4
- package/docs/outbound.md +1 -1
- package/docs/public-api.md +3 -3
- package/lib/bindings.ts +89 -6
- package/lib/bus-follower.ts +7 -3
- package/lib/bus-leader.ts +44 -19
- package/lib/bus.ts +4 -1
- package/lib/commands.ts +2 -2
- package/lib/config.ts +14 -7
- package/lib/delivery.ts +38 -6
- package/lib/extension.ts +7 -0
- package/lib/generative-apps.ts +379 -13
- package/lib/menu-settings.ts +20 -6
- package/lib/outbound-markup.ts +16 -7
- package/lib/status.ts +15 -12
- package/lib/telegram-api.ts +12 -1
- package/lib/thread-display.ts +96 -18
- package/package.json +56 -13
- package/scripts/build-dist.mjs +44 -0
- package/scripts/measure-bus.mjs +8 -1
- package/scripts/measure-workspace.mjs +8 -1
- package/skills/generative-apps/SKILL.md +1 -1
- package/skills/show-me/SKILL.md +1 -1
- package/skills/show-me/references/telegram-surfaces.md +1 -1
- package/skills/telegram-bridge/SKILL.md +1 -1
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telegram setup prompt helpers
|
|
3
|
+
* Zones: pi agent command ui, telegram config
|
|
4
|
+
* Computes token-prefill defaults and prompt mode selection for /telegram-setup
|
|
5
|
+
*/
|
|
6
|
+
export const TELEGRAM_BOT_TOKEN_INPUT_PLACEHOLDER = "123456:ABCDEF...";
|
|
7
|
+
const TELEGRAM_BOT_TOKEN_ENV_VARS = [
|
|
8
|
+
"TELEGRAM_BOT_TOKEN",
|
|
9
|
+
"TELEGRAM_BOT_KEY",
|
|
10
|
+
"TELEGRAM_TOKEN",
|
|
11
|
+
"TELEGRAM_KEY",
|
|
12
|
+
];
|
|
13
|
+
/**
|
|
14
|
+
* Default submitted-token handling for structural callers that inject no
|
|
15
|
+
* reference port: plain literals pass through, while `$`-prefixed values fail
|
|
16
|
+
* closed instead of being sent to the Bot API as a literal token.
|
|
17
|
+
*/
|
|
18
|
+
function resolveSubmittedTelegramBotToken(value) {
|
|
19
|
+
const trimmed = value.trim();
|
|
20
|
+
if (!trimmed || trimmed.startsWith("$"))
|
|
21
|
+
return undefined;
|
|
22
|
+
return trimmed;
|
|
23
|
+
}
|
|
24
|
+
function describeSubmittedTelegramBotToken(value) {
|
|
25
|
+
return value.trim().startsWith("$")
|
|
26
|
+
? "Telegram bot token environment reference is unavailable in this setup environment."
|
|
27
|
+
: undefined;
|
|
28
|
+
}
|
|
29
|
+
function isTelegramPollingStartResult(value) {
|
|
30
|
+
return (!!value &&
|
|
31
|
+
typeof value === "object" &&
|
|
32
|
+
typeof value.ok === "boolean");
|
|
33
|
+
}
|
|
34
|
+
export function getTelegramBotTokenInputDefault(env = process.env, configToken) {
|
|
35
|
+
const trimmedConfigToken = configToken?.trim();
|
|
36
|
+
if (trimmedConfigToken)
|
|
37
|
+
return trimmedConfigToken;
|
|
38
|
+
for (const key of TELEGRAM_BOT_TOKEN_ENV_VARS) {
|
|
39
|
+
// Persist the originating alias rather than copying the resolved secret.
|
|
40
|
+
if (env[key]?.trim())
|
|
41
|
+
return `$${key}`;
|
|
42
|
+
}
|
|
43
|
+
return TELEGRAM_BOT_TOKEN_INPUT_PLACEHOLDER;
|
|
44
|
+
}
|
|
45
|
+
export function getTelegramBotTokenPromptSpec(env = process.env, configToken) {
|
|
46
|
+
const value = getTelegramBotTokenInputDefault(env, configToken);
|
|
47
|
+
return {
|
|
48
|
+
method: value === TELEGRAM_BOT_TOKEN_INPUT_PLACEHOLDER ? "input" : "editor",
|
|
49
|
+
value,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export async function runTelegramSetup(deps) {
|
|
53
|
+
if (!deps.hasUI)
|
|
54
|
+
return { status: "unavailable" };
|
|
55
|
+
const tokenPrompt = getTelegramBotTokenPromptSpec(deps.env, deps.config.botToken);
|
|
56
|
+
const token = tokenPrompt.method === "editor"
|
|
57
|
+
? await deps.promptEditor("Telegram bot token", tokenPrompt.value)
|
|
58
|
+
: await deps.promptInput("Telegram bot token", tokenPrompt.value);
|
|
59
|
+
if (!token)
|
|
60
|
+
return { status: "cancelled" };
|
|
61
|
+
const submittedToken = token.trim();
|
|
62
|
+
const resolveBotToken = deps.resolveBotToken ?? resolveSubmittedTelegramBotToken;
|
|
63
|
+
const describeBotToken = deps.describeBotToken ?? describeSubmittedTelegramBotToken;
|
|
64
|
+
const resolvedToken = resolveBotToken(submittedToken);
|
|
65
|
+
const nextConfig = {
|
|
66
|
+
...deps.config,
|
|
67
|
+
botToken: submittedToken,
|
|
68
|
+
};
|
|
69
|
+
if (!resolvedToken) {
|
|
70
|
+
deps.notify(describeBotToken(submittedToken) ?? "Invalid Telegram bot token", "error");
|
|
71
|
+
return { status: "validation-failed" };
|
|
72
|
+
}
|
|
73
|
+
let data;
|
|
74
|
+
try {
|
|
75
|
+
data = await deps.getMe(resolvedToken);
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
79
|
+
deps.notify(`Telegram API check failed: ${message}`, "error");
|
|
80
|
+
return { status: "validation-failed" };
|
|
81
|
+
}
|
|
82
|
+
if (!data.ok || !data.result) {
|
|
83
|
+
deps.notify(data.description || "Invalid Telegram bot token", "error");
|
|
84
|
+
return { status: "validation-failed" };
|
|
85
|
+
}
|
|
86
|
+
nextConfig.botId = data.result.id;
|
|
87
|
+
nextConfig.botUsername = data.result.username;
|
|
88
|
+
await deps.persistConfig(nextConfig);
|
|
89
|
+
deps.notify(`Telegram bot connected: @${nextConfig.botUsername ?? "unknown"}`, "info");
|
|
90
|
+
deps.notify("Send /start to your bot in Telegram to pair this extension with your account.", "info");
|
|
91
|
+
let startResult;
|
|
92
|
+
try {
|
|
93
|
+
startResult = await deps.startPolling();
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
97
|
+
deps.notify(`Telegram polling failed: ${message}`, "error");
|
|
98
|
+
deps.updateStatus();
|
|
99
|
+
return { status: "polling-failed", config: nextConfig };
|
|
100
|
+
}
|
|
101
|
+
if (isTelegramPollingStartResult(startResult) && startResult.message) {
|
|
102
|
+
deps.notify(startResult.message, startResult.ok ? "info" : "error");
|
|
103
|
+
}
|
|
104
|
+
deps.updateStatus();
|
|
105
|
+
if (isTelegramPollingStartResult(startResult) && !startResult.ok) {
|
|
106
|
+
return { status: "polling-failed", config: nextConfig };
|
|
107
|
+
}
|
|
108
|
+
return { status: "success", config: nextConfig };
|
|
109
|
+
}
|
|
110
|
+
export function createTelegramSetupPromptRuntime(deps) {
|
|
111
|
+
return async (ctx) => {
|
|
112
|
+
if (!ctx.hasUI)
|
|
113
|
+
return { status: "unavailable" };
|
|
114
|
+
if (!deps.setupGuard.start())
|
|
115
|
+
return { status: "busy" };
|
|
116
|
+
try {
|
|
117
|
+
return await runTelegramSetup({
|
|
118
|
+
hasUI: ctx.hasUI,
|
|
119
|
+
env: deps.env ?? process.env,
|
|
120
|
+
config: deps.getConfig(),
|
|
121
|
+
promptInput: (label, value) => ctx.ui.input(label, value),
|
|
122
|
+
promptEditor: (label, value) => ctx.ui.editor(label, value),
|
|
123
|
+
getMe: deps.getMe,
|
|
124
|
+
resolveBotToken: deps.resolveBotToken,
|
|
125
|
+
describeBotToken: deps.describeBotToken,
|
|
126
|
+
persistConfig: async (config) => {
|
|
127
|
+
const previousConfig = deps.getConfig();
|
|
128
|
+
deps.setConfig(config);
|
|
129
|
+
try {
|
|
130
|
+
await deps.persistConfig(config);
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
deps.setConfig(previousConfig);
|
|
134
|
+
throw error;
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
notify: (message, level) => ctx.ui.notify(message, level),
|
|
138
|
+
startPolling: () => deps.startPolling(ctx),
|
|
139
|
+
updateStatus: () => deps.updateStatus(ctx),
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
deps.recordRuntimeEvent?.("setup", error);
|
|
144
|
+
throw error;
|
|
145
|
+
}
|
|
146
|
+
finally {
|
|
147
|
+
deps.setupGuard.finish();
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bundled Telegram skill discovery
|
|
3
|
+
* Zones: pi agent, telegram guidance
|
|
4
|
+
* Owns source-checkout and installed-package skill path contribution
|
|
5
|
+
*/
|
|
6
|
+
import type { ExtensionAPI } from "./pi.ts";
|
|
7
|
+
export declare const TELEGRAM_SKILLS_PATH: string;
|
|
8
|
+
export declare function registerTelegramSkillDiscovery(pi: Pick<ExtensionAPI, "on">): void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bundled Telegram skill discovery
|
|
3
|
+
* Zones: pi agent, telegram guidance
|
|
4
|
+
* Owns source-checkout and installed-package skill path contribution
|
|
5
|
+
*/
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
export const TELEGRAM_SKILLS_PATH = fileURLToPath(new URL("../skills", import.meta.url));
|
|
8
|
+
export function registerTelegramSkillDiscovery(pi) {
|
|
9
|
+
pi.on("resources_discover", () => ({
|
|
10
|
+
skillPaths: [TELEGRAM_SKILLS_PATH],
|
|
11
|
+
}));
|
|
12
|
+
}
|
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telegram status rendering helpers
|
|
3
|
+
* Zones: telegram ui, pi agent diagnostics, tui
|
|
4
|
+
* Builds usage, cost, and context summaries for the interactive Telegram status view
|
|
5
|
+
*/
|
|
6
|
+
export type TelegramStatusQueueLane = "control" | "priority" | "default";
|
|
7
|
+
export interface TelegramUsageStats {
|
|
8
|
+
totalInput: number;
|
|
9
|
+
totalOutput: number;
|
|
10
|
+
totalCacheRead: number;
|
|
11
|
+
totalCacheWrite: number;
|
|
12
|
+
totalCost: number;
|
|
13
|
+
latestCacheHitRate?: number;
|
|
14
|
+
}
|
|
15
|
+
interface TelegramUsageMessage {
|
|
16
|
+
role: string;
|
|
17
|
+
usage?: {
|
|
18
|
+
input: number;
|
|
19
|
+
output: number;
|
|
20
|
+
cacheRead: number;
|
|
21
|
+
cacheWrite: number;
|
|
22
|
+
cost: {
|
|
23
|
+
total: number;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
interface TelegramStatusSessionEntry {
|
|
28
|
+
type: string;
|
|
29
|
+
message?: TelegramUsageMessage;
|
|
30
|
+
}
|
|
31
|
+
interface TelegramContextUsage {
|
|
32
|
+
contextWindow?: number;
|
|
33
|
+
percent: number | null;
|
|
34
|
+
}
|
|
35
|
+
export interface TelegramStatusActiveModel {
|
|
36
|
+
provider?: string;
|
|
37
|
+
id?: string;
|
|
38
|
+
contextWindow?: number;
|
|
39
|
+
}
|
|
40
|
+
export interface TelegramStatusLineProviderContext {
|
|
41
|
+
activeModel: TelegramStatusActiveModel | undefined;
|
|
42
|
+
}
|
|
43
|
+
export interface TelegramStatusLineProviderResult {
|
|
44
|
+
label: string;
|
|
45
|
+
value: string;
|
|
46
|
+
}
|
|
47
|
+
export type TelegramStatusLineProvider = (ctx: TelegramStatusLineProviderContext) => TelegramStatusLineProviderResult | undefined;
|
|
48
|
+
export interface TelegramStatusContext {
|
|
49
|
+
sessionManager: {
|
|
50
|
+
getEntries(): TelegramStatusSessionEntry[];
|
|
51
|
+
};
|
|
52
|
+
getContextUsage(): TelegramContextUsage | undefined;
|
|
53
|
+
isIdle?: () => boolean;
|
|
54
|
+
hasPendingMessages?: () => boolean;
|
|
55
|
+
isCompactionInProgress?: () => boolean;
|
|
56
|
+
modelRegistry: {
|
|
57
|
+
isUsingOAuth(model: TelegramStatusActiveModel): boolean;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export type TelegramRuntimeEventDetailValue = string | number | boolean | null;
|
|
61
|
+
export interface TelegramRuntimeEvent {
|
|
62
|
+
at: number;
|
|
63
|
+
category: string;
|
|
64
|
+
message: string;
|
|
65
|
+
details?: Record<string, TelegramRuntimeEventDetailValue>;
|
|
66
|
+
}
|
|
67
|
+
export interface TelegramRuntimeEventInput {
|
|
68
|
+
category: string;
|
|
69
|
+
error?: unknown;
|
|
70
|
+
message?: string;
|
|
71
|
+
details?: Record<string, unknown>;
|
|
72
|
+
}
|
|
73
|
+
export interface TelegramRuntimeEventRecorder {
|
|
74
|
+
record: (category: string, error: unknown, details?: Record<string, unknown>) => void;
|
|
75
|
+
getEvents: () => TelegramRuntimeEvent[];
|
|
76
|
+
clear: () => void;
|
|
77
|
+
}
|
|
78
|
+
export interface TelegramRuntimeEventRecorderOptions {
|
|
79
|
+
getBotToken: () => string | undefined;
|
|
80
|
+
maxEvents?: number;
|
|
81
|
+
now?: () => number;
|
|
82
|
+
}
|
|
83
|
+
export interface TelegramBridgeStatusBusFollower {
|
|
84
|
+
instanceId: string;
|
|
85
|
+
cwd?: string;
|
|
86
|
+
lastHeartbeatMs: number;
|
|
87
|
+
target?: {
|
|
88
|
+
chatId: number;
|
|
89
|
+
threadId?: number;
|
|
90
|
+
};
|
|
91
|
+
protocol?: {
|
|
92
|
+
protocolVersion: number;
|
|
93
|
+
runtimeBuild: string;
|
|
94
|
+
capabilities: string[];
|
|
95
|
+
};
|
|
96
|
+
slot?: string;
|
|
97
|
+
threadName?: string;
|
|
98
|
+
status?: string;
|
|
99
|
+
}
|
|
100
|
+
export interface TelegramBridgeStatusLocalBus {
|
|
101
|
+
leaderSocketPath?: string;
|
|
102
|
+
leaderTransport?: "pipe" | "socket";
|
|
103
|
+
followerSocketPath?: string;
|
|
104
|
+
followerTransport?: "pipe" | "socket";
|
|
105
|
+
followerRegistered?: boolean;
|
|
106
|
+
followerTarget?: {
|
|
107
|
+
chatId: number;
|
|
108
|
+
threadId?: number;
|
|
109
|
+
};
|
|
110
|
+
followerSlot?: string;
|
|
111
|
+
followerThreadName?: string;
|
|
112
|
+
leaderProtocol?: {
|
|
113
|
+
protocolVersion: number;
|
|
114
|
+
runtimeBuild: string;
|
|
115
|
+
capabilities: string[];
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
export interface TelegramBridgeStatusTopicTarget {
|
|
119
|
+
instanceId?: string;
|
|
120
|
+
status?: string;
|
|
121
|
+
target?: {
|
|
122
|
+
chatId: number;
|
|
123
|
+
threadId?: number;
|
|
124
|
+
};
|
|
125
|
+
slot?: string;
|
|
126
|
+
threadName?: string;
|
|
127
|
+
syncStatus?: string;
|
|
128
|
+
lastSyncObservedAtMs?: number;
|
|
129
|
+
lastSyncProbeAtMs?: number;
|
|
130
|
+
lastSyncError?: string;
|
|
131
|
+
lastReconcileAction?: string;
|
|
132
|
+
}
|
|
133
|
+
export interface TelegramBridgeStatusThreadReservation {
|
|
134
|
+
target?: {
|
|
135
|
+
chatId: number;
|
|
136
|
+
threadId?: number;
|
|
137
|
+
};
|
|
138
|
+
slot?: string;
|
|
139
|
+
reason?: string;
|
|
140
|
+
instanceId?: string;
|
|
141
|
+
expiresAtMs?: number;
|
|
142
|
+
lastReconcileAction?: string;
|
|
143
|
+
}
|
|
144
|
+
export interface TelegramBridgeStatusSyncObservation {
|
|
145
|
+
target?: {
|
|
146
|
+
chatId: number;
|
|
147
|
+
threadId?: number;
|
|
148
|
+
};
|
|
149
|
+
syncStatus: string;
|
|
150
|
+
observedAtMs: number;
|
|
151
|
+
instanceId?: string;
|
|
152
|
+
slot?: string;
|
|
153
|
+
lastSyncError?: string;
|
|
154
|
+
lastReconcileAction?: string;
|
|
155
|
+
}
|
|
156
|
+
export interface TelegramBridgeStatusSyncSlice {
|
|
157
|
+
status: string;
|
|
158
|
+
updatedAtMs?: number;
|
|
159
|
+
suspectAtMs?: number;
|
|
160
|
+
reason?: string;
|
|
161
|
+
lastReconcileAction?: string;
|
|
162
|
+
}
|
|
163
|
+
export interface TelegramBridgeThreadReconciliationState {
|
|
164
|
+
phase: string;
|
|
165
|
+
event: string;
|
|
166
|
+
atMs: number;
|
|
167
|
+
leaderEpoch?: number | string;
|
|
168
|
+
pendingProvisionCount: number;
|
|
169
|
+
syncActionCount: number;
|
|
170
|
+
cleanupActionCount: number;
|
|
171
|
+
}
|
|
172
|
+
export type TelegramBridgeBusRole = "leader" | "follower";
|
|
173
|
+
export type TelegramBridgeBusLifecyclePhase = "electing";
|
|
174
|
+
export interface TelegramBridgePollingState {
|
|
175
|
+
phase: string;
|
|
176
|
+
phaseStartedAtMs?: number;
|
|
177
|
+
currentUpdateId?: number;
|
|
178
|
+
startedAtMs?: number;
|
|
179
|
+
stoppedAtMs?: number;
|
|
180
|
+
lastSuccessfulResponseAtMs?: number;
|
|
181
|
+
lastSuccessfulResponseUpdateCount?: number;
|
|
182
|
+
stopReason?: string;
|
|
183
|
+
}
|
|
184
|
+
export interface TelegramBridgeInboundWorkerState {
|
|
185
|
+
phase: string;
|
|
186
|
+
generation: number;
|
|
187
|
+
phaseStartedAtMs?: number;
|
|
188
|
+
currentUpdateId?: number;
|
|
189
|
+
blockedReason?: string;
|
|
190
|
+
blockedInputCustody?: {
|
|
191
|
+
updateId: number;
|
|
192
|
+
kind: string;
|
|
193
|
+
};
|
|
194
|
+
journalEntryCount: number;
|
|
195
|
+
journalSerializedBytes: number;
|
|
196
|
+
oldestAdmittedAtMs?: number;
|
|
197
|
+
deferredClaimCount: number;
|
|
198
|
+
queuedClaimCount: number;
|
|
199
|
+
foreignQueuedCount: number;
|
|
200
|
+
foreignQueuedOwnerLiveness?: "alive" | "dead" | "unverifiable";
|
|
201
|
+
foreignQueuedOwner?: {
|
|
202
|
+
instanceId: string;
|
|
203
|
+
processId: number;
|
|
204
|
+
processBirthId: string;
|
|
205
|
+
sessionGeneration: number;
|
|
206
|
+
acquisitionId: string;
|
|
207
|
+
acquiredAtMs: number;
|
|
208
|
+
};
|
|
209
|
+
retryWaitCount: number;
|
|
210
|
+
failedCount: number;
|
|
211
|
+
nextRetryUpdateId?: number;
|
|
212
|
+
nextRetryAtMs?: number;
|
|
213
|
+
nextRetryAttemptCount?: number;
|
|
214
|
+
nextRetryFailureClass?: string;
|
|
215
|
+
failedUpdateId?: number;
|
|
216
|
+
failedFailureId?: string;
|
|
217
|
+
failedAttemptCount?: number;
|
|
218
|
+
failedClass?: string;
|
|
219
|
+
failedSummary?: string;
|
|
220
|
+
terminalFailureAtMs?: number;
|
|
221
|
+
unsettledExecutionCount: number;
|
|
222
|
+
lastCompletedUpdateId?: number;
|
|
223
|
+
lastCompletedAtMs?: number;
|
|
224
|
+
lastFailureAtMs?: number;
|
|
225
|
+
lastFailurePhase?: string;
|
|
226
|
+
}
|
|
227
|
+
export interface TelegramBridgeStatusLineState {
|
|
228
|
+
hasBotToken?: boolean;
|
|
229
|
+
botUsername?: string;
|
|
230
|
+
/** Redacted named-variable diagnostic when the stored token reference cannot resolve. */
|
|
231
|
+
botTokenDiagnostic?: string;
|
|
232
|
+
activeProfileName?: string;
|
|
233
|
+
diagnosticPaths?: {
|
|
234
|
+
state: string;
|
|
235
|
+
logs: string;
|
|
236
|
+
};
|
|
237
|
+
allowedUserId?: number;
|
|
238
|
+
botThreadMode?: "unknown" | "enabled" | "disabled";
|
|
239
|
+
botThreadModeUpdatedAtMs?: number;
|
|
240
|
+
botThreadModeAction?: string;
|
|
241
|
+
busRole?: TelegramBridgeBusRole;
|
|
242
|
+
busProtocol?: {
|
|
243
|
+
protocolVersion: number;
|
|
244
|
+
runtimeBuild: string;
|
|
245
|
+
capabilities: string[];
|
|
246
|
+
};
|
|
247
|
+
busLifecyclePhase?: TelegramBridgeBusLifecyclePhase;
|
|
248
|
+
instanceSlot?: string;
|
|
249
|
+
instanceThreadName?: string;
|
|
250
|
+
lockState?: string;
|
|
251
|
+
pollingActive: boolean;
|
|
252
|
+
polling?: TelegramBridgePollingState;
|
|
253
|
+
inboundWorker?: TelegramBridgeInboundWorkerState;
|
|
254
|
+
lastUpdateId?: number;
|
|
255
|
+
activeSourceMessageIds?: number[];
|
|
256
|
+
pendingDispatch: boolean;
|
|
257
|
+
compactionInProgress: boolean;
|
|
258
|
+
activeToolExecutions: number;
|
|
259
|
+
pendingModelSwitch: boolean;
|
|
260
|
+
queuedItems: Array<{
|
|
261
|
+
queueLane: TelegramStatusQueueLane;
|
|
262
|
+
}>;
|
|
263
|
+
busFollowers?: TelegramBridgeStatusBusFollower[];
|
|
264
|
+
localBus?: TelegramBridgeStatusLocalBus;
|
|
265
|
+
topicTargets?: TelegramBridgeStatusTopicTarget[];
|
|
266
|
+
threadReservations?: TelegramBridgeStatusThreadReservation[];
|
|
267
|
+
topicSyncObservations?: TelegramBridgeStatusSyncObservation[];
|
|
268
|
+
syncState?: Record<string, TelegramBridgeStatusSyncSlice | undefined>;
|
|
269
|
+
threadReconciliation?: TelegramBridgeThreadReconciliationState;
|
|
270
|
+
busNowMs?: number;
|
|
271
|
+
recentRuntimeEvents: TelegramRuntimeEvent[];
|
|
272
|
+
}
|
|
273
|
+
export interface TelegramStatusBarTheme {
|
|
274
|
+
fg: (token: "accent" | "dim" | "error" | "muted" | "warning" | "success", text: string) => string;
|
|
275
|
+
}
|
|
276
|
+
export interface TelegramStatusBarState {
|
|
277
|
+
hasBotToken: boolean;
|
|
278
|
+
pollingActive: boolean;
|
|
279
|
+
pollingStopReason?: string;
|
|
280
|
+
paired: boolean;
|
|
281
|
+
busRole?: TelegramBridgeBusRole;
|
|
282
|
+
followerRegistered?: boolean;
|
|
283
|
+
busLifecyclePhase?: TelegramBridgeBusLifecyclePhase;
|
|
284
|
+
instanceSlot?: string;
|
|
285
|
+
instanceThreadName?: string;
|
|
286
|
+
compactionInProgress: boolean;
|
|
287
|
+
processing: boolean;
|
|
288
|
+
processingStatus?: string;
|
|
289
|
+
queuedStatus: string;
|
|
290
|
+
error?: string;
|
|
291
|
+
}
|
|
292
|
+
export interface TelegramStatusRuntimeContext {
|
|
293
|
+
ui: {
|
|
294
|
+
theme: TelegramStatusBarTheme;
|
|
295
|
+
setStatus: (key: string, text: string) => void;
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
export interface TelegramStatusRuntimeDeps<TContext extends TelegramStatusRuntimeContext> {
|
|
299
|
+
statusKey?: string;
|
|
300
|
+
getStatusBarState: (ctx: TContext, error?: string) => TelegramStatusBarState;
|
|
301
|
+
getBridgeStatusLineState: () => TelegramBridgeStatusLineState;
|
|
302
|
+
}
|
|
303
|
+
export interface TelegramBridgeStatusConfig {
|
|
304
|
+
botToken?: string;
|
|
305
|
+
/** Caller-resolved token availability; falls back to raw presence. */
|
|
306
|
+
botHasToken?: boolean;
|
|
307
|
+
/** Caller-supplied redacted diagnostic for an unresolved token reference. */
|
|
308
|
+
botTokenDiagnostic?: string;
|
|
309
|
+
botUsername?: string;
|
|
310
|
+
allowedUserId?: number;
|
|
311
|
+
}
|
|
312
|
+
/** Narrow config-store view used to project resolved bot-token availability. */
|
|
313
|
+
export interface TelegramBridgeStatusConfigSource {
|
|
314
|
+
get: () => TelegramBridgeStatusConfig;
|
|
315
|
+
hasBotToken?: () => boolean;
|
|
316
|
+
getBotTokenDiagnostic?: () => string | undefined;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Project a config store into the status view without moving token-reference
|
|
320
|
+
* resolution into this structural leaf domain.
|
|
321
|
+
*/
|
|
322
|
+
export declare function createTelegramBridgeStatusConfigGetter(source: TelegramBridgeStatusConfigSource): () => TelegramBridgeStatusConfig;
|
|
323
|
+
export interface TelegramBridgeStatusRuntimeDeps<TQueueItem extends {
|
|
324
|
+
queueLane: TelegramStatusQueueLane;
|
|
325
|
+
}> {
|
|
326
|
+
statusKey?: string;
|
|
327
|
+
getConfig: () => TelegramBridgeStatusConfig;
|
|
328
|
+
getActiveProfileName?: () => string | undefined;
|
|
329
|
+
getDiagnosticPaths?: (profileName?: string) => {
|
|
330
|
+
state: string;
|
|
331
|
+
logs: string;
|
|
332
|
+
};
|
|
333
|
+
isPollingActive: () => boolean;
|
|
334
|
+
getPollingState?: () => TelegramBridgePollingState;
|
|
335
|
+
getInboundWorkerState?: () => TelegramBridgeInboundWorkerState | undefined;
|
|
336
|
+
getAcceptedThroughUpdateId?: () => number | undefined;
|
|
337
|
+
getActiveSourceMessageIds: () => number[] | undefined;
|
|
338
|
+
hasActiveTurn: () => boolean;
|
|
339
|
+
hasDispatchPending: () => boolean;
|
|
340
|
+
isCompactionInProgress: () => boolean;
|
|
341
|
+
getActiveToolExecutions: () => number;
|
|
342
|
+
hasPendingModelSwitch: () => boolean;
|
|
343
|
+
getQueuedItems: () => TQueueItem[];
|
|
344
|
+
getQueuedItemCount?: (items: TQueueItem[]) => number;
|
|
345
|
+
formatQueuedStatus: (items: TQueueItem[]) => string;
|
|
346
|
+
getRecentRuntimeEvents: () => TelegramRuntimeEvent[];
|
|
347
|
+
getRuntimeLockState?: () => string;
|
|
348
|
+
getBusRole?: () => TelegramBridgeBusRole | undefined;
|
|
349
|
+
getBusProtocol?: () => {
|
|
350
|
+
protocolVersion: number;
|
|
351
|
+
runtimeBuild: string;
|
|
352
|
+
capabilities: string[];
|
|
353
|
+
};
|
|
354
|
+
getBusLifecyclePhase?: () => TelegramBridgeBusLifecyclePhase | undefined;
|
|
355
|
+
getBotThreadMode?: () => {
|
|
356
|
+
threadMode: "unknown" | "enabled" | "disabled";
|
|
357
|
+
updatedAtMs?: number;
|
|
358
|
+
lastReconcileAction?: string;
|
|
359
|
+
} | undefined;
|
|
360
|
+
getBusFollowers?: () => TelegramBridgeStatusBusFollower[];
|
|
361
|
+
getLocalBus?: () => TelegramBridgeStatusLocalBus | undefined;
|
|
362
|
+
getTopicTargets?: () => TelegramBridgeStatusTopicTarget[];
|
|
363
|
+
getThreadReservations?: () => TelegramBridgeStatusThreadReservation[];
|
|
364
|
+
getTopicSyncObservations?: () => TelegramBridgeStatusSyncObservation[];
|
|
365
|
+
getSyncState?: () => Record<string, TelegramBridgeStatusSyncSlice | undefined>;
|
|
366
|
+
getThreadReconciliationState?: () => TelegramBridgeThreadReconciliationState | undefined;
|
|
367
|
+
getInstanceSlot?: () => string | undefined;
|
|
368
|
+
getInstanceThreadName?: () => string | undefined;
|
|
369
|
+
getNowMs?: () => number;
|
|
370
|
+
}
|
|
371
|
+
export interface TelegramBridgeStatusLineOptions {
|
|
372
|
+
verbose?: boolean;
|
|
373
|
+
}
|
|
374
|
+
export interface TelegramStatusRuntime<TContext extends TelegramStatusRuntimeContext> {
|
|
375
|
+
updateStatus: (ctx: TContext, error?: string) => void;
|
|
376
|
+
getStatusLines: (options?: TelegramBridgeStatusLineOptions) => string[];
|
|
377
|
+
getStatusState: () => TelegramBridgeStatusLineState;
|
|
378
|
+
}
|
|
379
|
+
export declare function redactTelegramRuntimeMessage(message: string, botToken: string | undefined): string;
|
|
380
|
+
export declare function recordStructuredTelegramRuntimeEvent(events: TelegramRuntimeEvent[], input: TelegramRuntimeEventInput, options: {
|
|
381
|
+
botToken?: string;
|
|
382
|
+
maxEvents: number;
|
|
383
|
+
now?: number;
|
|
384
|
+
}): void;
|
|
385
|
+
/**
|
|
386
|
+
* Register a compact extension-provided line for the Telegram status menu.
|
|
387
|
+
*
|
|
388
|
+
* Providers are synchronous and should return undefined when their line is not
|
|
389
|
+
* relevant for the active model. Errors are isolated so optional extension
|
|
390
|
+
* status cannot break the core Telegram menu.
|
|
391
|
+
*/
|
|
392
|
+
export declare function registerTelegramStatusLineProvider(provider: TelegramStatusLineProvider, options: {
|
|
393
|
+
id: string;
|
|
394
|
+
}): () => void;
|
|
395
|
+
export declare function getTelegramStatusLineProviderResults(ctx: TelegramStatusLineProviderContext): TelegramStatusLineProviderResult[];
|
|
396
|
+
export declare function clearTelegramStatusLineProviders(): void;
|
|
397
|
+
export declare function createTelegramRuntimeEventRecorder(options: TelegramRuntimeEventRecorderOptions): TelegramRuntimeEventRecorder;
|
|
398
|
+
export declare function buildTelegramRuntimeEventLines(events: TelegramRuntimeEvent[]): string[];
|
|
399
|
+
export declare function createTelegramStatusHtmlBuilder<TContext>(deps: {
|
|
400
|
+
getActiveModel: (ctx: TContext) => TelegramStatusActiveModel | undefined;
|
|
401
|
+
isCompactionInProgress?: () => boolean;
|
|
402
|
+
getBridgeStatusLineState?: () => TelegramBridgeStatusLineState;
|
|
403
|
+
}): (ctx: TContext & TelegramStatusContext) => string;
|
|
404
|
+
export declare function createTelegramStatusRuntime<TContext extends TelegramStatusRuntimeContext>(deps: TelegramStatusRuntimeDeps<TContext>): TelegramStatusRuntime<TContext>;
|
|
405
|
+
export declare function createTelegramBridgeStatusRuntime<TContext extends TelegramStatusRuntimeContext, TQueueItem extends {
|
|
406
|
+
queueLane: TelegramStatusQueueLane;
|
|
407
|
+
}>(deps: TelegramBridgeStatusRuntimeDeps<TQueueItem>): TelegramStatusRuntime<TContext>;
|
|
408
|
+
export interface TelegramRuntimeLogScope extends Record<string, unknown> {
|
|
409
|
+
instanceId: string;
|
|
410
|
+
role: string;
|
|
411
|
+
slot?: string;
|
|
412
|
+
threadName?: string;
|
|
413
|
+
lockState?: string;
|
|
414
|
+
}
|
|
415
|
+
export declare function createTelegramRuntimeLogScope(input: {
|
|
416
|
+
state: TelegramBridgeStatusLineState;
|
|
417
|
+
instanceId: string;
|
|
418
|
+
}): TelegramRuntimeLogScope;
|
|
419
|
+
export declare function createTelegramStatusSnapshot(state: TelegramBridgeStatusLineState): {
|
|
420
|
+
runtime: Record<string, unknown>;
|
|
421
|
+
liveRoster: Record<string, unknown>;
|
|
422
|
+
diagnostics: Record<string, unknown>;
|
|
423
|
+
};
|
|
424
|
+
export declare function createTelegramRuntimeDiagnosticsSnapshotScheduler(deps: {
|
|
425
|
+
persistSnapshot: () => Promise<void>;
|
|
426
|
+
recordError: (error: unknown) => void;
|
|
427
|
+
setTimer?: (callback: () => void, ms: number) => {
|
|
428
|
+
unref?: () => void;
|
|
429
|
+
};
|
|
430
|
+
}): () => void;
|
|
431
|
+
export declare function getTelegramStatusBarProcessingStatus(state: {
|
|
432
|
+
hasActiveTurn: boolean;
|
|
433
|
+
hasPendingDispatch: boolean;
|
|
434
|
+
hasPendingModelSwitch: boolean;
|
|
435
|
+
activeToolExecutions: number;
|
|
436
|
+
queuedItems: number;
|
|
437
|
+
}): string | undefined;
|
|
438
|
+
export declare function buildTelegramStatusBarText(theme: TelegramStatusBarTheme, state: TelegramStatusBarState): string;
|
|
439
|
+
export declare function buildTelegramBridgeStatusLines(state: TelegramBridgeStatusLineState, options?: TelegramBridgeStatusLineOptions): string[];
|
|
440
|
+
export declare function buildTelegramBridgeDiagnosticStatusLines(state: TelegramBridgeStatusLineState): string[];
|
|
441
|
+
export declare function buildStatusHtml(ctx: TelegramStatusContext, activeModel: TelegramStatusActiveModel | undefined, bridgeStatus?: TelegramBridgeStatusLineState): string;
|
|
442
|
+
export {};
|