@llblab/pi-telegram 0.46.0 → 0.47.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/BACKLOG.md +0 -1
- package/CHANGELOG.md +8 -0
- package/README.md +2 -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 +1608 -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 +116 -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 +1006 -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/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 +4 -2
- package/docs/outbound.md +1 -1
- package/docs/public-api.md +2 -2
- 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 +19 -0
- package/lib/generative-apps.ts +379 -13
- package/lib/menu-settings.ts +21 -5
- package/lib/outbound-markup.ts +16 -7
- 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/telegram-bridge/SKILL.md +1 -1
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telegram outbound voice delivery helpers
|
|
3
|
+
* Zones: telegram outbound, voice delivery
|
|
4
|
+
* Owns native Telegram voice upload orchestration across configured voice handlers, programmatic outbound voice handlers, and registered synthesis providers
|
|
5
|
+
*/
|
|
6
|
+
import { type TelegramTarget } from "./target.ts";
|
|
7
|
+
export interface TelegramVoiceReplyTurnView {
|
|
8
|
+
chatId: number;
|
|
9
|
+
replyToMessageId: number;
|
|
10
|
+
target?: TelegramTarget;
|
|
11
|
+
}
|
|
12
|
+
export interface TelegramVoiceReplySenderDeps {
|
|
13
|
+
execCommand: (command: string, args: string[], options?: {
|
|
14
|
+
cwd?: string;
|
|
15
|
+
timeout?: number;
|
|
16
|
+
signal?: AbortSignal;
|
|
17
|
+
stdin?: string;
|
|
18
|
+
retry?: number;
|
|
19
|
+
}) => Promise<{
|
|
20
|
+
stdout: string;
|
|
21
|
+
stderr: string;
|
|
22
|
+
code: number;
|
|
23
|
+
killed: boolean;
|
|
24
|
+
}>;
|
|
25
|
+
sendMultipart: (method: string, fields: Record<string, string>, fileField: string, filePath: string, fileName: string) => Promise<unknown>;
|
|
26
|
+
sendChatAction?: (chatId: number, action: string) => Promise<unknown>;
|
|
27
|
+
sendRecordVoiceAction?: (chatId: number) => Promise<unknown>;
|
|
28
|
+
isDeliveryActive?: () => boolean;
|
|
29
|
+
getHandlers?: () => unknown[] | undefined;
|
|
30
|
+
cwd?: string;
|
|
31
|
+
tempDir?: string;
|
|
32
|
+
recordRuntimeEvent?: (category: string, error: unknown, details?: Record<string, unknown>) => void;
|
|
33
|
+
}
|
|
34
|
+
export type TelegramOutboundProgrammaticVoiceHandler = (text: string, options?: {
|
|
35
|
+
lang?: string;
|
|
36
|
+
rate?: string;
|
|
37
|
+
}) => Promise<string>;
|
|
38
|
+
export interface TelegramVoiceReplySenderPorts<THandler = unknown> {
|
|
39
|
+
findVoiceHandlers?: (handlers: unknown[] | undefined) => THandler[];
|
|
40
|
+
generateVoiceFile?: (text: string, options: {
|
|
41
|
+
lang?: string;
|
|
42
|
+
rate?: string;
|
|
43
|
+
handler: THandler;
|
|
44
|
+
tempDir?: string;
|
|
45
|
+
cwd?: string;
|
|
46
|
+
execCommand: TelegramVoiceReplySenderDeps["execCommand"];
|
|
47
|
+
}) => Promise<string | undefined>;
|
|
48
|
+
getProgrammaticVoiceHandlers?: () => TelegramOutboundProgrammaticVoiceHandler[];
|
|
49
|
+
}
|
|
50
|
+
export declare function createTelegramVoiceReplySender<THandler = unknown>(deps: TelegramVoiceReplySenderDeps, ports?: TelegramVoiceReplySenderPorts<THandler>): (turn: TelegramVoiceReplyTurnView, text: string, options?: {
|
|
51
|
+
lang?: string;
|
|
52
|
+
rate?: string;
|
|
53
|
+
replyToPrompt?: boolean;
|
|
54
|
+
replyMarkup?: unknown;
|
|
55
|
+
}) => Promise<void>;
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telegram outbound voice delivery helpers
|
|
3
|
+
* Zones: telegram outbound, voice delivery
|
|
4
|
+
* Owns native Telegram voice upload orchestration across configured voice handlers, programmatic outbound voice handlers, and registered synthesis providers
|
|
5
|
+
*/
|
|
6
|
+
import { unlink } from "node:fs/promises";
|
|
7
|
+
import { basename, extname } from "node:path";
|
|
8
|
+
import { assertTelegramInlineKeyboardCallbackData } from "./keyboard.js";
|
|
9
|
+
import { withTelegramReplyParameters } from "./replies.js";
|
|
10
|
+
import { getTelegramTargetThreadParams, } from "./target.js";
|
|
11
|
+
import { getTelegramVoiceSynthesisProviders } from "./voice.js";
|
|
12
|
+
import { isTelegramApiCommitUnknownError } from "./telegram-api.js";
|
|
13
|
+
async function ensureTelegramVoiceFileFormat(filePath) {
|
|
14
|
+
const ext = extname(filePath).toLowerCase();
|
|
15
|
+
if (ext === ".opus" || ext === ".ogg")
|
|
16
|
+
return filePath;
|
|
17
|
+
throw new Error(`Voice synthesis provider must return .ogg or .opus files, got ${ext}. ` +
|
|
18
|
+
`Providers should handle format conversion internally.`);
|
|
19
|
+
}
|
|
20
|
+
async function sendVoiceChatAction(deps, chatId) {
|
|
21
|
+
if (deps.sendRecordVoiceAction) {
|
|
22
|
+
await deps.sendRecordVoiceAction(chatId).catch(() => { });
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
await deps.sendChatAction?.(chatId, "record_voice").catch(() => { });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export function createTelegramVoiceReplySender(deps, ports = {}) {
|
|
29
|
+
const uploadVoiceFile = async (turn, filePath, options) => {
|
|
30
|
+
if (deps.isDeliveryActive?.() === false)
|
|
31
|
+
return;
|
|
32
|
+
const voiceFilePath = await ensureTelegramVoiceFileFormat(filePath);
|
|
33
|
+
assertTelegramInlineKeyboardCallbackData(options?.replyMarkup);
|
|
34
|
+
if (deps.isDeliveryActive?.() === false)
|
|
35
|
+
return;
|
|
36
|
+
await sendVoiceChatAction(deps, turn.chatId);
|
|
37
|
+
if (deps.isDeliveryActive?.() === false)
|
|
38
|
+
return;
|
|
39
|
+
await withTelegramReplyParameters(turn.chatId, options?.replyToPrompt === false ? undefined : turn.replyToMessageId, turn.target, (replyParameters) => deps.sendMultipart("sendVoice", {
|
|
40
|
+
chat_id: String(turn.chatId),
|
|
41
|
+
...(replyParameters ? { reply_parameters: JSON.stringify(replyParameters) } : {}),
|
|
42
|
+
...(turn.target
|
|
43
|
+
? Object.fromEntries(Object.entries(getTelegramTargetThreadParams(turn.target)).map(([key, value]) => [key, String(value)]))
|
|
44
|
+
: {}),
|
|
45
|
+
...(options?.replyMarkup !== undefined && options.replyMarkup !== null
|
|
46
|
+
? {
|
|
47
|
+
reply_markup: typeof options.replyMarkup === "string"
|
|
48
|
+
? options.replyMarkup
|
|
49
|
+
: JSON.stringify(options.replyMarkup),
|
|
50
|
+
}
|
|
51
|
+
: {}),
|
|
52
|
+
}, "voice", voiceFilePath, basename(voiceFilePath)));
|
|
53
|
+
};
|
|
54
|
+
return async (turn, text, options) => {
|
|
55
|
+
for (const handler of ports.findVoiceHandlers?.(deps.getHandlers?.()) ??
|
|
56
|
+
[]) {
|
|
57
|
+
if (deps.isDeliveryActive?.() === false)
|
|
58
|
+
return;
|
|
59
|
+
try {
|
|
60
|
+
const filePath = await ports.generateVoiceFile?.(text, {
|
|
61
|
+
lang: options?.lang,
|
|
62
|
+
rate: options?.rate,
|
|
63
|
+
handler,
|
|
64
|
+
tempDir: deps.tempDir,
|
|
65
|
+
cwd: deps.cwd,
|
|
66
|
+
execCommand: deps.execCommand,
|
|
67
|
+
});
|
|
68
|
+
if (!filePath)
|
|
69
|
+
continue;
|
|
70
|
+
await uploadVoiceFile(turn, filePath, {
|
|
71
|
+
replyToPrompt: options?.replyToPrompt,
|
|
72
|
+
replyMarkup: options?.replyMarkup,
|
|
73
|
+
});
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
if (isTelegramApiCommitUnknownError(error))
|
|
78
|
+
throw error;
|
|
79
|
+
deps.recordRuntimeEvent?.("voice", error, {
|
|
80
|
+
phase: "template-handler-send",
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
for (const handler of ports.getProgrammaticVoiceHandlers?.() ?? []) {
|
|
85
|
+
if (deps.isDeliveryActive?.() === false)
|
|
86
|
+
return;
|
|
87
|
+
try {
|
|
88
|
+
const filePath = await handler(text, {
|
|
89
|
+
lang: options?.lang,
|
|
90
|
+
rate: options?.rate,
|
|
91
|
+
});
|
|
92
|
+
if (!filePath)
|
|
93
|
+
continue;
|
|
94
|
+
await uploadVoiceFile(turn, filePath, {
|
|
95
|
+
replyToPrompt: options?.replyToPrompt,
|
|
96
|
+
replyMarkup: options?.replyMarkup,
|
|
97
|
+
});
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
if (isTelegramApiCommitUnknownError(error))
|
|
102
|
+
throw error;
|
|
103
|
+
deps.recordRuntimeEvent?.("voice", error, {
|
|
104
|
+
phase: "programmatic-handler-send",
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const providers = getTelegramVoiceSynthesisProviders();
|
|
109
|
+
for (const provider of providers) {
|
|
110
|
+
if (deps.isDeliveryActive?.() === false)
|
|
111
|
+
return;
|
|
112
|
+
let voiceFilePath;
|
|
113
|
+
let originalFilePath;
|
|
114
|
+
try {
|
|
115
|
+
if (typeof provider !== "function") {
|
|
116
|
+
deps.recordRuntimeEvent?.("voice", new Error("Registered voice synthesis provider is not callable (policy-only object?)"), { phase: "voice-provider-skip" });
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
const providerResult = await provider(text, {
|
|
120
|
+
lang: options?.lang,
|
|
121
|
+
rate: options?.rate,
|
|
122
|
+
});
|
|
123
|
+
if (!providerResult) {
|
|
124
|
+
deps.recordRuntimeEvent?.("voice", new Error("Voice synthesis provider returned empty path"), { phase: "voice-provider-skip" });
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
voiceFilePath = providerResult;
|
|
128
|
+
originalFilePath = providerResult;
|
|
129
|
+
await uploadVoiceFile(turn, providerResult, {
|
|
130
|
+
replyToPrompt: options?.replyToPrompt,
|
|
131
|
+
replyMarkup: options?.replyMarkup,
|
|
132
|
+
});
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
if (isTelegramApiCommitUnknownError(error))
|
|
137
|
+
throw error;
|
|
138
|
+
deps.recordRuntimeEvent?.("voice", error, { phase: "send" });
|
|
139
|
+
}
|
|
140
|
+
finally {
|
|
141
|
+
if (voiceFilePath && voiceFilePath !== originalFilePath) {
|
|
142
|
+
await unlink(voiceFilePath).catch(() => { });
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
const errorMessage = "Failed to send voice reply: every voice synthesis provider and outbound voice handler failed.";
|
|
147
|
+
deps.recordRuntimeEvent?.("voice", new Error(errorMessage), {
|
|
148
|
+
phase: "send",
|
|
149
|
+
});
|
|
150
|
+
throw new Error(errorMessage);
|
|
151
|
+
};
|
|
152
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telegram outbound surface helpers
|
|
3
|
+
* Zones: telegram outbound, command templates, voice delivery
|
|
4
|
+
* Owns configured outbound handler execution, text transforms, public assistant-output reply composition and mutation fencing, voice-file generation/delivery, runtime-event bridge, and compatibility re-exports; assistant markup parsing lives in outbound-markup and button callback actions live in outbound-buttons
|
|
5
|
+
*/
|
|
6
|
+
import type { TelegramAssistantSegmentEvent } from "./activity.ts";
|
|
7
|
+
import * as Replies from "./replies.ts";
|
|
8
|
+
import type { TelegramPreparedPreviewDelivery } from "./preview.ts";
|
|
9
|
+
import type { TelegramEditMessageTextBody, TelegramSendMessageBody, TelegramSendRichMessageBody, TelegramSentMessage } from "./telegram-api.ts";
|
|
10
|
+
import { type TelegramButtonActionStore, type TelegramOutboundButtonBinding, type TelegramOutboundButtonMarkup } from "./outbound-buttons.ts";
|
|
11
|
+
import { type TelegramVoiceReplyItem } from "./outbound-markup.ts";
|
|
12
|
+
import type { TelegramTarget } from "./target.ts";
|
|
13
|
+
import { type CommandTemplateObjectConfig } from "./command-templates.ts";
|
|
14
|
+
/**
|
|
15
|
+
* Record a runtime event that appears in `/telegram-status`.
|
|
16
|
+
* Voice synthesis provider extensions can call this to surface diagnostics
|
|
17
|
+
* alongside pi-telegram's own events. Events are silently dropped
|
|
18
|
+
* when pi-telegram is not loaded.
|
|
19
|
+
*/
|
|
20
|
+
export type TelegramRuntimeEventRecorder = (category: string, error: unknown, details?: Record<string, unknown>) => void;
|
|
21
|
+
export declare function bindTelegramRuntimeEventRecorder(recorder: TelegramRuntimeEventRecorder): void;
|
|
22
|
+
export declare function recordTelegramRuntimeEvent(category: string, error: unknown, details?: Record<string, unknown>): void;
|
|
23
|
+
export type TelegramOutboundCommandTemplateConfig = string | CommandTemplateObjectConfig;
|
|
24
|
+
export interface TelegramOutboundHandlerConfig extends CommandTemplateObjectConfig {
|
|
25
|
+
type?: string;
|
|
26
|
+
match?: string | string[];
|
|
27
|
+
output?: string;
|
|
28
|
+
timeout?: number | string;
|
|
29
|
+
}
|
|
30
|
+
export { normalizeMarkdownAfterVoiceExtraction, planTelegramVoiceReply, stripTelegramCommentMarkupForDelivery, stripTelegramCommentMarkupForPreview, stripTelegramVoiceMarkupForPreview, type TelegramVoiceReplyItem, type TelegramVoiceReplyPlan, } from "./outbound-markup.ts";
|
|
31
|
+
export interface TelegramVoiceExecOptions {
|
|
32
|
+
cwd?: string;
|
|
33
|
+
timeout?: number;
|
|
34
|
+
signal?: AbortSignal;
|
|
35
|
+
stdin?: string;
|
|
36
|
+
retry?: number;
|
|
37
|
+
}
|
|
38
|
+
export interface TelegramVoiceExecResult {
|
|
39
|
+
stdout: string;
|
|
40
|
+
stderr: string;
|
|
41
|
+
code: number;
|
|
42
|
+
killed: boolean;
|
|
43
|
+
}
|
|
44
|
+
export interface TelegramVoiceReplyTurnView {
|
|
45
|
+
chatId: number;
|
|
46
|
+
replyToMessageId: number;
|
|
47
|
+
target?: TelegramTarget;
|
|
48
|
+
}
|
|
49
|
+
export interface TelegramVoiceReplySenderDeps {
|
|
50
|
+
execCommand: (command: string, args: string[], options?: TelegramVoiceExecOptions) => Promise<TelegramVoiceExecResult>;
|
|
51
|
+
sendMultipart: (method: string, fields: Record<string, string>, fileField: string, filePath: string, fileName: string) => Promise<unknown>;
|
|
52
|
+
sendTextReply?: (chatId: number, replyToMessageId: number | undefined, text: string, options?: {
|
|
53
|
+
parseMode?: "HTML";
|
|
54
|
+
}) => Promise<unknown>;
|
|
55
|
+
sendChatAction?: (chatId: number, action: string) => Promise<unknown>;
|
|
56
|
+
sendRecordVoiceAction?: (chatId: number) => Promise<unknown>;
|
|
57
|
+
isDeliveryActive?: () => boolean;
|
|
58
|
+
getHandlers?: () => TelegramOutboundHandlerConfig[] | undefined;
|
|
59
|
+
cwd?: string;
|
|
60
|
+
tempDir?: string;
|
|
61
|
+
recordRuntimeEvent?: (category: string, error: unknown, details?: Record<string, unknown>) => void;
|
|
62
|
+
}
|
|
63
|
+
export type TelegramOutboundProgrammaticHandler = (text: string, options?: {
|
|
64
|
+
lang?: string;
|
|
65
|
+
rate?: string;
|
|
66
|
+
}) => Promise<string>;
|
|
67
|
+
export interface TelegramOutboundHandlerRegistry {
|
|
68
|
+
handlers: Map<string, TelegramOutboundProgrammaticHandler[]>;
|
|
69
|
+
}
|
|
70
|
+
export declare function registerTelegramOutboundHandler(kind: string, handler: TelegramOutboundProgrammaticHandler): () => void;
|
|
71
|
+
export declare function getTelegramOutboundProgrammaticHandlers(kind: string): TelegramOutboundProgrammaticHandler[];
|
|
72
|
+
export interface TelegramOutboundTextReplyRuntimeDeps<TReplyMarkup = unknown> {
|
|
73
|
+
execCommand: TelegramVoiceReplySenderDeps["execCommand"];
|
|
74
|
+
getHandlers?: () => TelegramOutboundHandlerConfig[] | undefined;
|
|
75
|
+
sendTextReply: (chatId: number, replyToMessageId: number | undefined, text: string, options?: {
|
|
76
|
+
parseMode?: "HTML";
|
|
77
|
+
target?: TelegramTarget;
|
|
78
|
+
}) => Promise<number | undefined>;
|
|
79
|
+
sendMarkdownReply: (chatId: number, replyToMessageId: number | undefined, markdown: string, options?: {
|
|
80
|
+
replyMarkup?: TReplyMarkup;
|
|
81
|
+
target?: TelegramTarget;
|
|
82
|
+
}) => Promise<number | undefined>;
|
|
83
|
+
cwd?: string;
|
|
84
|
+
recordRuntimeEvent?: TelegramVoiceReplySenderDeps["recordRuntimeEvent"];
|
|
85
|
+
}
|
|
86
|
+
export interface TelegramInlineKeyboardLike {
|
|
87
|
+
inline_keyboard: Array<Array<{
|
|
88
|
+
text: string;
|
|
89
|
+
callback_data: string;
|
|
90
|
+
}>>;
|
|
91
|
+
}
|
|
92
|
+
export interface TelegramOutboundTextTransformOptions<TReplyMarkup = unknown> {
|
|
93
|
+
handlers?: TelegramOutboundHandlerConfig[];
|
|
94
|
+
cwd?: string;
|
|
95
|
+
execCommand: TelegramVoiceReplySenderDeps["execCommand"];
|
|
96
|
+
recordRuntimeEvent?: TelegramVoiceReplySenderDeps["recordRuntimeEvent"];
|
|
97
|
+
replyMarkup?: TReplyMarkup;
|
|
98
|
+
}
|
|
99
|
+
export interface TelegramOutboundTextTransformResult<TReplyMarkup = unknown> {
|
|
100
|
+
text: string;
|
|
101
|
+
replyMarkup?: TReplyMarkup;
|
|
102
|
+
}
|
|
103
|
+
export interface TelegramOutboundTextPreviewRuntimeDeps<TReplyMarkup = unknown> {
|
|
104
|
+
execCommand: TelegramVoiceReplySenderDeps["execCommand"];
|
|
105
|
+
getHandlers?: () => TelegramOutboundHandlerConfig[] | undefined;
|
|
106
|
+
finalizeMarkdownPreview: TelegramPreparedPreviewDelivery<TReplyMarkup>["finalizeMarkdownPreview"];
|
|
107
|
+
preparePreviewDelivery?: (isDeliveryActive: () => boolean) => TelegramPreparedPreviewDelivery<TReplyMarkup>;
|
|
108
|
+
cwd?: string;
|
|
109
|
+
recordRuntimeEvent?: TelegramVoiceReplySenderDeps["recordRuntimeEvent"];
|
|
110
|
+
}
|
|
111
|
+
export declare function findTelegramOutboundHandlers(handlers: TelegramOutboundHandlerConfig[] | undefined, type: string): TelegramOutboundHandlerConfig[];
|
|
112
|
+
export declare function generateTelegramVoiceReplyFile(text: string, options: {
|
|
113
|
+
lang?: string;
|
|
114
|
+
rate?: string;
|
|
115
|
+
handler?: TelegramOutboundHandlerConfig;
|
|
116
|
+
tempDir?: string;
|
|
117
|
+
cwd?: string;
|
|
118
|
+
execCommand: TelegramVoiceReplySenderDeps["execCommand"];
|
|
119
|
+
}): Promise<string | undefined>;
|
|
120
|
+
export declare function transformTelegramOutboundText(text: string, options: {
|
|
121
|
+
handlers?: TelegramOutboundHandlerConfig[];
|
|
122
|
+
cwd?: string;
|
|
123
|
+
execCommand: TelegramVoiceReplySenderDeps["execCommand"];
|
|
124
|
+
recordRuntimeEvent?: TelegramVoiceReplySenderDeps["recordRuntimeEvent"];
|
|
125
|
+
}): Promise<string>;
|
|
126
|
+
export declare function transformTelegramOutboundTextReply<TReplyMarkup = unknown>(text: string, options: TelegramOutboundTextTransformOptions<TReplyMarkup>): Promise<TelegramOutboundTextTransformResult<TReplyMarkup>>;
|
|
127
|
+
export declare function createTelegramOutboundTextReplyRuntime<TReplyMarkup = unknown>(deps: TelegramOutboundTextReplyRuntimeDeps<TReplyMarkup>): Pick<TelegramOutboundTextReplyRuntimeDeps<TReplyMarkup>, "sendTextReply" | "sendMarkdownReply">;
|
|
128
|
+
export declare function createTelegramOutboundTextPreviewRuntime<TReplyMarkup = unknown>(deps: TelegramOutboundTextPreviewRuntimeDeps<TReplyMarkup>): {
|
|
129
|
+
finalizeMarkdownPreview: TelegramPreparedPreviewDelivery<TReplyMarkup>["finalizeMarkdownPreview"];
|
|
130
|
+
preparePreviewDelivery: (isDeliveryActive: () => boolean) => TelegramPreparedPreviewDelivery<TReplyMarkup> | undefined;
|
|
131
|
+
};
|
|
132
|
+
export interface TelegramOutboundReplyPlan<TReplyMarkup = unknown> {
|
|
133
|
+
markdown: string;
|
|
134
|
+
replyMarkup?: TReplyMarkup;
|
|
135
|
+
voiceText?: string;
|
|
136
|
+
voiceReplies?: TelegramVoiceReplyItem[];
|
|
137
|
+
lang?: string;
|
|
138
|
+
rate?: string;
|
|
139
|
+
}
|
|
140
|
+
export { clearTelegramVoiceSynthesisProviders, clearTelegramVoiceTranscriptionProviders, computeVoicePromptContribution, computeVoiceTurnFlags, getTelegramVoiceReplyMode, getTelegramVoiceSynthesisProviders, getTelegramVoiceTranscriptionProviders, hasTelegramVoiceSynthesisProvider, hasTelegramVoiceTranscriptionProvider, isVoiceTurn, registerTelegramVoiceSynthesisProvider, registerTelegramVoiceTranscriptionProvider, shouldSuppressPreviewForVoice, type TelegramVoiceReplyMode, type TelegramVoiceSynthesisProvider, type TelegramVoiceSynthesisProviderResult, type TelegramVoiceTranscriptionFile, type TelegramVoiceTranscriptionProvider, type TelegramVoiceTranscriptionProviderResult, type TelegramVoiceTurnView, } from "./voice.ts";
|
|
141
|
+
export declare function createTelegramVoiceReplySender(deps: TelegramVoiceReplySenderDeps): (turn: import("./outbound-voice.ts").TelegramVoiceReplyTurnView, text: string, options?: {
|
|
142
|
+
lang?: string;
|
|
143
|
+
rate?: string;
|
|
144
|
+
replyToPrompt?: boolean;
|
|
145
|
+
replyMarkup?: unknown;
|
|
146
|
+
} | undefined) => Promise<void>;
|
|
147
|
+
export { createTelegramButtonActionStore, createTelegramButtonPromptTurn, createTelegramButtonReplyPlanner, handleTelegramButtonCallbackQuery, markTelegramButtonSelected, planTelegramButtonReply, type TelegramButtonActionStore, type TelegramButtonCallbackHandlerDeps, type TelegramButtonCallbackQuery, type TelegramButtonReplyPlan, type TelegramOutboundButtonAction, type TelegramOutboundButtonBinding, type TelegramOutboundButtonMarkup, type TelegramOutboundButtonStoredAction, } from "./outbound-buttons.ts";
|
|
148
|
+
export declare function createTelegramOutboundReplyPlanner(store: Pick<TelegramButtonActionStore, "register">, getRenderingMode?: () => "rich" | "html"): (markdown: string, options?: {
|
|
149
|
+
binding?: TelegramOutboundButtonBinding;
|
|
150
|
+
}) => TelegramOutboundReplyPlan<TelegramOutboundButtonMarkup>;
|
|
151
|
+
/**
|
|
152
|
+
* Create an artifact sender that delivers planned voice replies for a turn.
|
|
153
|
+
* Iterates over `voiceReplies` (or a single `voiceText`) and sends each as
|
|
154
|
+
* a Telegram voice message via the voice reply sender. Throws if no voice
|
|
155
|
+
* reply could be delivered.
|
|
156
|
+
*/
|
|
157
|
+
export declare function createTelegramOutboundReplyArtifactSender(deps: TelegramVoiceReplySenderDeps): (turn: TelegramVoiceReplyTurnView, plan: Pick<TelegramOutboundReplyPlan, "voiceText" | "voiceReplies" | "lang" | "rate" | "replyMarkup">, options?: {
|
|
158
|
+
replyToPrompt?: boolean;
|
|
159
|
+
isDeliveryActive?: () => boolean;
|
|
160
|
+
}) => Promise<void>;
|
|
161
|
+
export interface TelegramAssistantOutputMutationFence {
|
|
162
|
+
run: <TArgs extends unknown[], TResult>(mutation: (...args: TArgs) => Promise<TResult>, ...args: TArgs) => Promise<TResult>;
|
|
163
|
+
}
|
|
164
|
+
export interface TelegramAssistantOutputDeliveryAuthority<TTransportStamp> {
|
|
165
|
+
transportStamp: TTransportStamp;
|
|
166
|
+
route: "direct" | "follower" | "none";
|
|
167
|
+
directEpoch?: number | string;
|
|
168
|
+
followerGeneration?: string;
|
|
169
|
+
target?: TelegramTarget;
|
|
170
|
+
}
|
|
171
|
+
export declare function createTelegramAssistantOutputMutationFence(isAuthorityActive: () => boolean): TelegramAssistantOutputMutationFence;
|
|
172
|
+
export declare function createTelegramAssistantOutputSender<TTransportStamp, TReplyMarkup = unknown>(deps: {
|
|
173
|
+
recordOwnership?: Replies.TelegramReplyOwnershipRecorder["record"];
|
|
174
|
+
sendMessage: (body: TelegramSendMessageBody) => Promise<TelegramSentMessage>;
|
|
175
|
+
sendRichMessage: (body: TelegramSendRichMessageBody) => Promise<TelegramSentMessage>;
|
|
176
|
+
editMessage: (body: TelegramEditMessageTextBody) => Promise<unknown>;
|
|
177
|
+
getAssistantRenderingMode: () => "rich" | "html";
|
|
178
|
+
planButtonReply?: (markdown: string) => {
|
|
179
|
+
markdown: string;
|
|
180
|
+
replyMarkup?: TReplyMarkup;
|
|
181
|
+
};
|
|
182
|
+
execCommand: TelegramOutboundTextReplyRuntimeDeps<TReplyMarkup>["execCommand"];
|
|
183
|
+
getHandlers?: TelegramOutboundTextReplyRuntimeDeps<TReplyMarkup>["getHandlers"];
|
|
184
|
+
recordRuntimeEvent?: TelegramOutboundTextReplyRuntimeDeps<TReplyMarkup>["recordRuntimeEvent"];
|
|
185
|
+
}): (event: TelegramAssistantSegmentEvent, authority: TelegramAssistantOutputDeliveryAuthority<TTransportStamp>, isAuthorityActive: () => boolean) => Promise<void>;
|