@llblab/pi-kit 0.12.0 → 0.13.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.
Files changed (211) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +2 -2
  3. package/node_modules/@llblab/pi-state-flow/CHANGELOG.md +4 -0
  4. package/node_modules/@llblab/pi-state-flow/README.md +1 -1
  5. package/node_modules/@llblab/pi-state-flow/lib/telegram.ts +0 -1
  6. package/node_modules/@llblab/pi-state-flow/package.json +1 -1
  7. package/node_modules/@llblab/pi-telegram/AGENTS.md +5 -3
  8. package/node_modules/@llblab/pi-telegram/BACKLOG.md +0 -6
  9. package/node_modules/@llblab/pi-telegram/CHANGELOG.md +22 -0
  10. package/node_modules/@llblab/pi-telegram/README.md +6 -3
  11. package/node_modules/@llblab/pi-telegram/dist/api/activity.d.ts +6 -0
  12. package/node_modules/@llblab/pi-telegram/dist/api/activity.js +6 -0
  13. package/node_modules/@llblab/pi-telegram/dist/api/commands.d.ts +6 -0
  14. package/node_modules/@llblab/pi-telegram/dist/api/commands.js +6 -0
  15. package/node_modules/@llblab/pi-telegram/dist/api/delivery.d.ts +6 -0
  16. package/node_modules/@llblab/pi-telegram/dist/api/delivery.js +6 -0
  17. package/node_modules/@llblab/pi-telegram/dist/api/inbound.d.ts +6 -0
  18. package/node_modules/@llblab/pi-telegram/dist/api/inbound.js +6 -0
  19. package/node_modules/@llblab/pi-telegram/dist/api/keyboard.d.ts +6 -0
  20. package/node_modules/@llblab/pi-telegram/dist/api/keyboard.js +6 -0
  21. package/node_modules/@llblab/pi-telegram/dist/api/outbound.d.ts +6 -0
  22. package/node_modules/@llblab/pi-telegram/dist/api/outbound.js +6 -0
  23. package/node_modules/@llblab/pi-telegram/dist/api/sections.d.ts +7 -0
  24. package/node_modules/@llblab/pi-telegram/dist/api/sections.js +6 -0
  25. package/node_modules/@llblab/pi-telegram/dist/api/status.d.ts +6 -0
  26. package/node_modules/@llblab/pi-telegram/dist/api/status.js +6 -0
  27. package/node_modules/@llblab/pi-telegram/dist/api/updates.d.ts +6 -0
  28. package/node_modules/@llblab/pi-telegram/dist/api/updates.js +6 -0
  29. package/node_modules/@llblab/pi-telegram/dist/api/voice.d.ts +6 -0
  30. package/node_modules/@llblab/pi-telegram/dist/api/voice.js +6 -0
  31. package/node_modules/@llblab/pi-telegram/dist/index.d.ts +6 -0
  32. package/node_modules/@llblab/pi-telegram/dist/index.js +6 -0
  33. package/node_modules/@llblab/pi-telegram/dist/lib/activity-verbosity.d.ts +52 -0
  34. package/node_modules/@llblab/pi-telegram/dist/lib/activity-verbosity.js +596 -0
  35. package/node_modules/@llblab/pi-telegram/dist/lib/activity.d.ts +220 -0
  36. package/node_modules/@llblab/pi-telegram/dist/lib/activity.js +574 -0
  37. package/node_modules/@llblab/pi-telegram/dist/lib/agent-messages.d.ts +28 -0
  38. package/node_modules/@llblab/pi-telegram/dist/lib/agent-messages.js +86 -0
  39. package/node_modules/@llblab/pi-telegram/dist/lib/bindings.d.ts +250 -0
  40. package/node_modules/@llblab/pi-telegram/dist/lib/bindings.js +936 -0
  41. package/node_modules/@llblab/pi-telegram/dist/lib/bus-api.d.ts +18 -0
  42. package/node_modules/@llblab/pi-telegram/dist/lib/bus-api.js +254 -0
  43. package/node_modules/@llblab/pi-telegram/dist/lib/bus-follower.d.ts +464 -0
  44. package/node_modules/@llblab/pi-telegram/dist/lib/bus-follower.js +1689 -0
  45. package/node_modules/@llblab/pi-telegram/dist/lib/bus-leader.d.ts +292 -0
  46. package/node_modules/@llblab/pi-telegram/dist/lib/bus-leader.js +2242 -0
  47. package/node_modules/@llblab/pi-telegram/dist/lib/bus-transport.d.ts +64 -0
  48. package/node_modules/@llblab/pi-telegram/dist/lib/bus-transport.js +140 -0
  49. package/node_modules/@llblab/pi-telegram/dist/lib/bus.d.ts +518 -0
  50. package/node_modules/@llblab/pi-telegram/dist/lib/bus.js +2055 -0
  51. package/node_modules/@llblab/pi-telegram/dist/lib/channel-posts.d.ts +170 -0
  52. package/node_modules/@llblab/pi-telegram/dist/lib/channel-posts.js +611 -0
  53. package/node_modules/@llblab/pi-telegram/dist/lib/command-templates.d.ts +70 -0
  54. package/node_modules/@llblab/pi-telegram/dist/lib/command-templates.js +744 -0
  55. package/node_modules/@llblab/pi-telegram/dist/lib/commands.d.ts +541 -0
  56. package/node_modules/@llblab/pi-telegram/dist/lib/commands.js +1155 -0
  57. package/node_modules/@llblab/pi-telegram/dist/lib/config.d.ts +252 -0
  58. package/node_modules/@llblab/pi-telegram/dist/lib/config.js +889 -0
  59. package/node_modules/@llblab/pi-telegram/dist/lib/delivery.d.ts +163 -0
  60. package/node_modules/@llblab/pi-telegram/dist/lib/delivery.js +542 -0
  61. package/node_modules/@llblab/pi-telegram/dist/lib/extension.d.ts +7 -0
  62. package/node_modules/@llblab/pi-telegram/dist/lib/extension.js +1604 -0
  63. package/node_modules/@llblab/pi-telegram/dist/lib/generative-app-worker.mjs +104 -0
  64. package/node_modules/@llblab/pi-telegram/dist/lib/generative-apps.d.ts +212 -0
  65. package/node_modules/@llblab/pi-telegram/dist/lib/generative-apps.js +1006 -0
  66. package/node_modules/@llblab/pi-telegram/dist/lib/inbound.d.ts +91 -0
  67. package/node_modules/@llblab/pi-telegram/dist/lib/inbound.js +502 -0
  68. package/node_modules/@llblab/pi-telegram/dist/lib/journal.d.ts +665 -0
  69. package/node_modules/@llblab/pi-telegram/dist/lib/journal.js +3701 -0
  70. package/node_modules/@llblab/pi-telegram/dist/lib/keyboard.d.ts +23 -0
  71. package/node_modules/@llblab/pi-telegram/dist/lib/keyboard.js +37 -0
  72. package/node_modules/@llblab/pi-telegram/dist/lib/lifecycle.d.ts +157 -0
  73. package/node_modules/@llblab/pi-telegram/dist/lib/lifecycle.js +395 -0
  74. package/node_modules/@llblab/pi-telegram/dist/lib/locks.d.ts +164 -0
  75. package/node_modules/@llblab/pi-telegram/dist/lib/locks.js +1208 -0
  76. package/node_modules/@llblab/pi-telegram/dist/lib/logging.d.ts +50 -0
  77. package/node_modules/@llblab/pi-telegram/dist/lib/logging.js +274 -0
  78. package/node_modules/@llblab/pi-telegram/dist/lib/media.d.ts +181 -0
  79. package/node_modules/@llblab/pi-telegram/dist/lib/media.js +602 -0
  80. package/node_modules/@llblab/pi-telegram/dist/lib/menu-model.d.ts +217 -0
  81. package/node_modules/@llblab/pi-telegram/dist/lib/menu-model.js +663 -0
  82. package/node_modules/@llblab/pi-telegram/dist/lib/menu-queue.d.ts +37 -0
  83. package/node_modules/@llblab/pi-telegram/dist/lib/menu-queue.js +408 -0
  84. package/node_modules/@llblab/pi-telegram/dist/lib/menu-settings.d.ts +115 -0
  85. package/node_modules/@llblab/pi-telegram/dist/lib/menu-settings.js +595 -0
  86. package/node_modules/@llblab/pi-telegram/dist/lib/menu-status.d.ts +32 -0
  87. package/node_modules/@llblab/pi-telegram/dist/lib/menu-status.js +112 -0
  88. package/node_modules/@llblab/pi-telegram/dist/lib/menu-thinking.d.ts +29 -0
  89. package/node_modules/@llblab/pi-telegram/dist/lib/menu-thinking.js +82 -0
  90. package/node_modules/@llblab/pi-telegram/dist/lib/menu.d.ts +171 -0
  91. package/node_modules/@llblab/pi-telegram/dist/lib/menu.js +323 -0
  92. package/node_modules/@llblab/pi-telegram/dist/lib/model.d.ts +127 -0
  93. package/node_modules/@llblab/pi-telegram/dist/lib/model.js +409 -0
  94. package/node_modules/@llblab/pi-telegram/dist/lib/outbound-attachments.d.ts +241 -0
  95. package/node_modules/@llblab/pi-telegram/dist/lib/outbound-attachments.js +639 -0
  96. package/node_modules/@llblab/pi-telegram/dist/lib/outbound-buttons.d.ts +69 -0
  97. package/node_modules/@llblab/pi-telegram/dist/lib/outbound-buttons.js +248 -0
  98. package/node_modules/@llblab/pi-telegram/dist/lib/outbound-markup.d.ts +42 -0
  99. package/node_modules/@llblab/pi-telegram/dist/lib/outbound-markup.js +678 -0
  100. package/node_modules/@llblab/pi-telegram/dist/lib/outbound-voice.d.ts +55 -0
  101. package/node_modules/@llblab/pi-telegram/dist/lib/outbound-voice.js +152 -0
  102. package/node_modules/@llblab/pi-telegram/dist/lib/outbound.d.ts +185 -0
  103. package/node_modules/@llblab/pi-telegram/dist/lib/outbound.js +516 -0
  104. package/node_modules/@llblab/pi-telegram/dist/lib/ownership.d.ts +77 -0
  105. package/node_modules/@llblab/pi-telegram/dist/lib/ownership.js +174 -0
  106. package/node_modules/@llblab/pi-telegram/dist/lib/paths.d.ts +40 -0
  107. package/node_modules/@llblab/pi-telegram/dist/lib/paths.js +94 -0
  108. package/node_modules/@llblab/pi-telegram/dist/lib/pi.d.ts +72 -0
  109. package/node_modules/@llblab/pi-telegram/dist/lib/pi.js +121 -0
  110. package/node_modules/@llblab/pi-telegram/dist/lib/polling.d.ts +351 -0
  111. package/node_modules/@llblab/pi-telegram/dist/lib/polling.js +1196 -0
  112. package/node_modules/@llblab/pi-telegram/dist/lib/preview.d.ts +192 -0
  113. package/node_modules/@llblab/pi-telegram/dist/lib/preview.js +614 -0
  114. package/node_modules/@llblab/pi-telegram/dist/lib/prompt-templates.d.ts +24 -0
  115. package/node_modules/@llblab/pi-telegram/dist/lib/prompt-templates.js +118 -0
  116. package/node_modules/@llblab/pi-telegram/dist/lib/prompts.d.ts +57 -0
  117. package/node_modules/@llblab/pi-telegram/dist/lib/prompts.js +167 -0
  118. package/node_modules/@llblab/pi-telegram/dist/lib/queue.d.ts +766 -0
  119. package/node_modules/@llblab/pi-telegram/dist/lib/queue.js +1965 -0
  120. package/node_modules/@llblab/pi-telegram/dist/lib/recovery.d.ts +86 -0
  121. package/node_modules/@llblab/pi-telegram/dist/lib/recovery.js +285 -0
  122. package/node_modules/@llblab/pi-telegram/dist/lib/rendering.d.ts +20 -0
  123. package/node_modules/@llblab/pi-telegram/dist/lib/rendering.js +983 -0
  124. package/node_modules/@llblab/pi-telegram/dist/lib/replies.d.ts +214 -0
  125. package/node_modules/@llblab/pi-telegram/dist/lib/replies.js +737 -0
  126. package/node_modules/@llblab/pi-telegram/dist/lib/routing.d.ts +207 -0
  127. package/node_modules/@llblab/pi-telegram/dist/lib/routing.js +2282 -0
  128. package/node_modules/@llblab/pi-telegram/dist/lib/runtime.d.ts +172 -0
  129. package/node_modules/@llblab/pi-telegram/dist/lib/runtime.js +402 -0
  130. package/node_modules/@llblab/pi-telegram/dist/lib/sections.d.ts +165 -0
  131. package/node_modules/@llblab/pi-telegram/dist/lib/sections.js +327 -0
  132. package/node_modules/@llblab/pi-telegram/dist/lib/setup.d.ts +82 -0
  133. package/node_modules/@llblab/pi-telegram/dist/lib/setup.js +150 -0
  134. package/node_modules/@llblab/pi-telegram/dist/lib/skills.d.ts +8 -0
  135. package/node_modules/@llblab/pi-telegram/dist/lib/skills.js +12 -0
  136. package/node_modules/@llblab/pi-telegram/dist/lib/status.d.ts +442 -0
  137. package/node_modules/@llblab/pi-telegram/dist/lib/status.js +1000 -0
  138. package/node_modules/@llblab/pi-telegram/dist/lib/sync.d.ts +179 -0
  139. package/node_modules/@llblab/pi-telegram/dist/lib/sync.js +782 -0
  140. package/node_modules/@llblab/pi-telegram/dist/lib/target.d.ts +20 -0
  141. package/node_modules/@llblab/pi-telegram/dist/lib/target.js +27 -0
  142. package/node_modules/@llblab/pi-telegram/dist/lib/telegram-api.d.ts +541 -0
  143. package/node_modules/@llblab/pi-telegram/dist/lib/telegram-api.js +1159 -0
  144. package/node_modules/@llblab/pi-telegram/dist/lib/text-groups.d.ts +89 -0
  145. package/node_modules/@llblab/pi-telegram/dist/lib/text-groups.js +317 -0
  146. package/node_modules/@llblab/pi-telegram/dist/lib/thread-cleanup-manager.d.ts +288 -0
  147. package/node_modules/@llblab/pi-telegram/dist/lib/thread-cleanup-manager.js +560 -0
  148. package/node_modules/@llblab/pi-telegram/dist/lib/thread-display.d.ts +46 -0
  149. package/node_modules/@llblab/pi-telegram/dist/lib/thread-display.js +257 -0
  150. package/node_modules/@llblab/pi-telegram/dist/lib/thread-naming.d.ts +46 -0
  151. package/node_modules/@llblab/pi-telegram/dist/lib/thread-naming.js +78 -0
  152. package/node_modules/@llblab/pi-telegram/dist/lib/thread-reconciler.d.ts +239 -0
  153. package/node_modules/@llblab/pi-telegram/dist/lib/thread-reconciler.js +644 -0
  154. package/node_modules/@llblab/pi-telegram/dist/lib/threads.d.ts +621 -0
  155. package/node_modules/@llblab/pi-telegram/dist/lib/threads.js +3679 -0
  156. package/node_modules/@llblab/pi-telegram/dist/lib/time-injection.d.ts +15 -0
  157. package/node_modules/@llblab/pi-telegram/dist/lib/time-injection.js +56 -0
  158. package/node_modules/@llblab/pi-telegram/dist/lib/turns.d.ts +109 -0
  159. package/node_modules/@llblab/pi-telegram/dist/lib/turns.js +500 -0
  160. package/node_modules/@llblab/pi-telegram/dist/lib/updates.d.ts +1290 -0
  161. package/node_modules/@llblab/pi-telegram/dist/lib/updates.js +3634 -0
  162. package/node_modules/@llblab/pi-telegram/dist/lib/voice.d.ts +117 -0
  163. package/node_modules/@llblab/pi-telegram/dist/lib/voice.js +174 -0
  164. package/node_modules/@llblab/pi-telegram/dist/lib/workspace-admission.d.ts +264 -0
  165. package/node_modules/@llblab/pi-telegram/dist/lib/workspace-admission.js +1136 -0
  166. package/node_modules/@llblab/pi-telegram/dist/lib/workspace-retirement.d.ts +219 -0
  167. package/node_modules/@llblab/pi-telegram/dist/lib/workspace-retirement.js +587 -0
  168. package/node_modules/@llblab/pi-telegram/dist/lib/workspace-slots.d.ts +30 -0
  169. package/node_modules/@llblab/pi-telegram/dist/lib/workspace-slots.js +54 -0
  170. package/node_modules/@llblab/pi-telegram/dist/package.json +126 -0
  171. package/node_modules/@llblab/pi-telegram/dist/pi-telegram/index.js +1 -0
  172. package/node_modules/@llblab/pi-telegram/dist/skills/generated-control-surface/SKILL.md +107 -0
  173. package/node_modules/@llblab/pi-telegram/dist/skills/generated-control-surface/references/capability-adapters.md +27 -0
  174. package/node_modules/@llblab/pi-telegram/dist/skills/generated-control-surface/references/layout-and-state.md +37 -0
  175. package/node_modules/@llblab/pi-telegram/dist/skills/generative-apps/SKILL.md +115 -0
  176. package/node_modules/@llblab/pi-telegram/dist/skills/show-me/SKILL.md +166 -0
  177. package/node_modules/@llblab/pi-telegram/dist/skills/show-me/references/telegram-surfaces.md +43 -0
  178. package/node_modules/@llblab/pi-telegram/dist/skills/telegram-bridge/SKILL.md +129 -0
  179. package/node_modules/@llblab/pi-telegram/dist/skills/telegram-bridge/references/configuration.md +15 -0
  180. package/node_modules/@llblab/pi-telegram/dist/skills/telegram-bridge/references/delivery-and-threads.md +27 -0
  181. package/node_modules/@llblab/pi-telegram/dist/skills/telegram-bridge/references/diagnosis.md +18 -0
  182. package/node_modules/@llblab/pi-telegram/docs/README.md +2 -0
  183. package/node_modules/@llblab/pi-telegram/docs/architecture.md +4 -2
  184. package/node_modules/@llblab/pi-telegram/docs/compact-matrix-literal.md +10 -3
  185. package/node_modules/@llblab/pi-telegram/docs/generative-apps.md +15 -13
  186. package/node_modules/@llblab/pi-telegram/docs/multi-instance-bus.md +6 -4
  187. package/node_modules/@llblab/pi-telegram/docs/outbound.md +1 -1
  188. package/node_modules/@llblab/pi-telegram/docs/public-api.md +3 -3
  189. package/node_modules/@llblab/pi-telegram/lib/bindings.ts +89 -6
  190. package/node_modules/@llblab/pi-telegram/lib/bus-follower.ts +12 -5
  191. package/node_modules/@llblab/pi-telegram/lib/bus-leader.ts +44 -19
  192. package/node_modules/@llblab/pi-telegram/lib/bus.ts +4 -1
  193. package/node_modules/@llblab/pi-telegram/lib/commands.ts +2 -2
  194. package/node_modules/@llblab/pi-telegram/lib/config.ts +14 -7
  195. package/node_modules/@llblab/pi-telegram/lib/delivery.ts +38 -6
  196. package/node_modules/@llblab/pi-telegram/lib/extension.ts +7 -0
  197. package/node_modules/@llblab/pi-telegram/lib/generative-apps.ts +379 -13
  198. package/node_modules/@llblab/pi-telegram/lib/menu-settings.ts +20 -6
  199. package/node_modules/@llblab/pi-telegram/lib/outbound-markup.ts +16 -7
  200. package/node_modules/@llblab/pi-telegram/lib/status.ts +9 -15
  201. package/node_modules/@llblab/pi-telegram/lib/telegram-api.ts +12 -1
  202. package/node_modules/@llblab/pi-telegram/lib/thread-display.ts +96 -18
  203. package/node_modules/@llblab/pi-telegram/package.json +56 -13
  204. package/node_modules/@llblab/pi-telegram/scripts/build-dist.mjs +44 -0
  205. package/node_modules/@llblab/pi-telegram/scripts/measure-bus.mjs +8 -1
  206. package/node_modules/@llblab/pi-telegram/scripts/measure-workspace.mjs +8 -1
  207. package/node_modules/@llblab/pi-telegram/skills/generative-apps/SKILL.md +1 -1
  208. package/node_modules/@llblab/pi-telegram/skills/show-me/SKILL.md +1 -1
  209. package/node_modules/@llblab/pi-telegram/skills/show-me/references/telegram-surfaces.md +1 -1
  210. package/node_modules/@llblab/pi-telegram/skills/telegram-bridge/SKILL.md +1 -1
  211. package/package.json +5 -5
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Telegram bus-aware API runtime
3
+ * Zones: multi-instance bus, telegram api transport, live instance routing
4
+ * Wraps the direct Telegram Bot API runtime so follower instances can route outbound calls through the bus leader
5
+ */
6
+ import type { TelegramBridgeApiRuntime } from "./telegram-api.ts";
7
+ export type TelegramBusApiCall = (method: string, args: unknown[]) => Promise<unknown>;
8
+ export interface TelegramBusAwareApiRuntimeDeps {
9
+ directRuntime: TelegramBridgeApiRuntime;
10
+ ownsDirect: () => boolean;
11
+ callFollowerApi: TelegramBusApiCall;
12
+ getDefaultTarget?: () => {
13
+ chatId: number;
14
+ threadId?: number;
15
+ } | undefined;
16
+ }
17
+ export declare function createTelegramAggregateTypingActionSender(runtime: Pick<TelegramBridgeApiRuntime, "call">): (chatId: number) => Promise<unknown>;
18
+ export declare function createTelegramBusAwareApiRuntime(deps: TelegramBusAwareApiRuntimeDeps): TelegramBridgeApiRuntime;
@@ -0,0 +1,254 @@
1
+ /**
2
+ * Telegram bus-aware API runtime
3
+ * Zones: multi-instance bus, telegram api transport, live instance routing
4
+ * Wraps the direct Telegram Bot API runtime so follower instances can route outbound calls through the bus leader
5
+ */
6
+ import { markTelegramBusCrossTargetDelivery, stripTelegramBusApiMetadata, } from "./bus.js";
7
+ import { buildTelegramAnswerGuestQueryBody, isTelegramMessageNotModifiedError, } from "./telegram-api.js";
8
+ function asRecord(value) {
9
+ return value && typeof value === "object" && !Array.isArray(value)
10
+ ? value
11
+ : {};
12
+ }
13
+ function asBoolean(value) {
14
+ return Boolean(value);
15
+ }
16
+ function asSentMessage(value) {
17
+ return asRecord(value);
18
+ }
19
+ function withDefaultThreadTarget(body, target) {
20
+ if (target?.threadId === undefined)
21
+ return body;
22
+ if (body.message_thread_id !== undefined)
23
+ return body;
24
+ return body.chat_id === target.chatId
25
+ ? { ...body, message_thread_id: target.threadId }
26
+ : body;
27
+ }
28
+ function markFollowerCrossTargetDelivery(body, defaultTarget) {
29
+ if (!defaultTarget || body.chat_id !== defaultTarget.chatId)
30
+ return body;
31
+ const threadId = body.message_thread_id;
32
+ const isDifferentTarget = threadId === undefined
33
+ ? defaultTarget.threadId !== undefined
34
+ : threadId !== defaultTarget.threadId;
35
+ return isDifferentTarget ? markTelegramBusCrossTargetDelivery(body) : body;
36
+ }
37
+ function rejectTelegramDirectOwnership(method) {
38
+ return Promise.reject(new Error(`Telegram ${method} requires direct transport ownership.`));
39
+ }
40
+ export function createTelegramAggregateTypingActionSender(runtime) {
41
+ return (chatId) => runtime.call("sendChatAction", { chat_id: chatId, action: "typing" });
42
+ }
43
+ export function createTelegramBusAwareApiRuntime(deps) {
44
+ return {
45
+ call(method, body, options) {
46
+ return deps.ownsDirect()
47
+ ? deps.directRuntime.call(method, body, options)
48
+ : deps.callFollowerApi("call", [
49
+ method,
50
+ body,
51
+ options,
52
+ ]);
53
+ },
54
+ callMultipart(method, fields, fileField, filePath, fileName, options) {
55
+ return deps.ownsDirect()
56
+ ? deps.directRuntime.callMultipart(method, fields, fileField, filePath, fileName, options)
57
+ : deps.callFollowerApi("callMultipart", [
58
+ method,
59
+ fields,
60
+ fileField,
61
+ filePath,
62
+ fileName,
63
+ options,
64
+ ]);
65
+ },
66
+ downloadFile(fileId, suggestedName) {
67
+ return deps.ownsDirect()
68
+ ? deps.directRuntime.downloadFile(fileId, suggestedName)
69
+ : deps.callFollowerApi("downloadFile", [
70
+ fileId,
71
+ suggestedName,
72
+ ]);
73
+ },
74
+ deleteWebhook(signal) {
75
+ return deps.ownsDirect()
76
+ ? deps.directRuntime.deleteWebhook(signal)
77
+ : rejectTelegramDirectOwnership("deleteWebhook");
78
+ },
79
+ getUpdates(body, signal) {
80
+ return deps.ownsDirect()
81
+ ? deps.directRuntime.getUpdates(body, signal)
82
+ : rejectTelegramDirectOwnership("getUpdates");
83
+ },
84
+ setMyCommands(commands) {
85
+ return deps.ownsDirect()
86
+ ? deps.directRuntime.setMyCommands(commands)
87
+ : deps
88
+ .callFollowerApi("call", ["setMyCommands", { commands }])
89
+ .then(asBoolean);
90
+ },
91
+ sendChatAction(chatId, action, options) {
92
+ const body = withDefaultThreadTarget({
93
+ chat_id: chatId,
94
+ action,
95
+ ...(options?.message_thread_id !== undefined
96
+ ? { message_thread_id: options.message_thread_id }
97
+ : {}),
98
+ }, deps.getDefaultTarget?.());
99
+ return deps.ownsDirect()
100
+ ? deps.directRuntime.sendChatAction(chatId, action, options)
101
+ : deps
102
+ .callFollowerApi("call", ["sendChatAction", body])
103
+ .then(asBoolean);
104
+ },
105
+ sendTypingAction(chatId, options) {
106
+ const body = withDefaultThreadTarget({
107
+ chat_id: chatId,
108
+ action: "typing",
109
+ ...(options?.message_thread_id !== undefined
110
+ ? { message_thread_id: options.message_thread_id }
111
+ : {}),
112
+ }, deps.getDefaultTarget?.());
113
+ return deps.ownsDirect()
114
+ ? deps.directRuntime.sendTypingAction(chatId, options)
115
+ : deps
116
+ .callFollowerApi("call", ["sendChatAction", body])
117
+ .then(asBoolean);
118
+ },
119
+ sendRecordVoiceAction(chatId, options) {
120
+ const body = withDefaultThreadTarget({
121
+ chat_id: chatId,
122
+ action: "record_voice",
123
+ ...(options?.message_thread_id !== undefined
124
+ ? { message_thread_id: options.message_thread_id }
125
+ : {}),
126
+ }, deps.getDefaultTarget?.());
127
+ return deps.ownsDirect()
128
+ ? deps.directRuntime.sendRecordVoiceAction(chatId, options)
129
+ : deps
130
+ .callFollowerApi("call", ["sendChatAction", body])
131
+ .then(asBoolean);
132
+ },
133
+ sendMessageDraft(chatId, draftId, text, options) {
134
+ const body = {
135
+ chat_id: chatId,
136
+ draft_id: draftId,
137
+ };
138
+ if (text !== undefined)
139
+ body.text = text;
140
+ if (options?.parse_mode !== undefined)
141
+ body.parse_mode = options.parse_mode;
142
+ if (options?.entities !== undefined)
143
+ body.entities = options.entities;
144
+ if (options?.message_thread_id !== undefined) {
145
+ body.message_thread_id = options.message_thread_id;
146
+ }
147
+ const scopedBody = withDefaultThreadTarget(body, deps.getDefaultTarget?.());
148
+ return deps.ownsDirect()
149
+ ? deps.directRuntime.sendMessageDraft(chatId, draftId, text, options)
150
+ : deps
151
+ .callFollowerApi("call", ["sendMessageDraft", scopedBody])
152
+ .then(asBoolean);
153
+ },
154
+ sendMessage(body) {
155
+ return deps.ownsDirect()
156
+ ? deps.directRuntime.sendMessage(stripTelegramBusApiMetadata(body))
157
+ : deps
158
+ .callFollowerApi("call", [
159
+ "sendMessage",
160
+ markFollowerCrossTargetDelivery(body, deps.getDefaultTarget?.()),
161
+ ])
162
+ .then(asSentMessage);
163
+ },
164
+ sendRichMessage(body) {
165
+ return deps.ownsDirect()
166
+ ? deps.directRuntime.sendRichMessage(stripTelegramBusApiMetadata(body))
167
+ : deps
168
+ .callFollowerApi("call", [
169
+ "sendRichMessage",
170
+ markFollowerCrossTargetDelivery(body, deps.getDefaultTarget?.()),
171
+ ])
172
+ .then(asSentMessage);
173
+ },
174
+ sendRichMessageDraft(body) {
175
+ return deps.ownsDirect()
176
+ ? deps.directRuntime.sendRichMessageDraft(body)
177
+ : deps
178
+ .callFollowerApi("call", ["sendRichMessageDraft", body])
179
+ .then(asBoolean);
180
+ },
181
+ async editMessageText(body) {
182
+ if (deps.ownsDirect())
183
+ return deps.directRuntime.editMessageText(body);
184
+ try {
185
+ await deps.callFollowerApi("call", ["editMessageText", body]);
186
+ return "edited";
187
+ }
188
+ catch (error) {
189
+ if (isTelegramMessageNotModifiedError(error))
190
+ return "unchanged";
191
+ throw error;
192
+ }
193
+ },
194
+ async editMessageReplyMarkup(chatId, messageId, replyMarkup) {
195
+ if (deps.ownsDirect()) {
196
+ await deps.directRuntime.editMessageReplyMarkup(chatId, messageId, replyMarkup);
197
+ return;
198
+ }
199
+ await deps.callFollowerApi("call", [
200
+ "editMessageReplyMarkup",
201
+ { chat_id: chatId, message_id: messageId, reply_markup: replyMarkup },
202
+ ]);
203
+ },
204
+ async answerCallbackQuery(callbackQueryId, text) {
205
+ if (deps.ownsDirect()) {
206
+ await deps.directRuntime.answerCallbackQuery(callbackQueryId, text);
207
+ return;
208
+ }
209
+ await deps.callFollowerApi("call", [
210
+ "answerCallbackQuery",
211
+ {
212
+ callback_query_id: callbackQueryId,
213
+ ...(text !== undefined ? { text } : {}),
214
+ },
215
+ ]);
216
+ },
217
+ async answerGuestQuery(guestQueryId, text, options) {
218
+ if (deps.ownsDirect()) {
219
+ await deps.directRuntime.answerGuestQuery(guestQueryId, text, options);
220
+ return;
221
+ }
222
+ await deps.callFollowerApi("call", [
223
+ "answerGuestQuery",
224
+ buildTelegramAnswerGuestQueryBody(guestQueryId, text, options),
225
+ ]);
226
+ },
227
+ answerGuestQueryForInlineMessage(guestQueryId, text, options) {
228
+ // Guest answers can only be edited while this instance owns direct
229
+ // transport; follower forwarding cannot preserve the inline message id.
230
+ return deps.ownsDirect()
231
+ ? deps.directRuntime.answerGuestQueryForInlineMessage(guestQueryId, text, options)
232
+ : rejectTelegramDirectOwnership("answerGuestQueryForInlineMessage");
233
+ },
234
+ editGuestInlineMessage(inlineMessageId, content) {
235
+ return deps.ownsDirect()
236
+ ? deps.directRuntime.editGuestInlineMessage(inlineMessageId, content)
237
+ : rejectTelegramDirectOwnership("editGuestInlineMessage");
238
+ },
239
+ async deleteMessage(chatId, messageId) {
240
+ if (deps.ownsDirect())
241
+ return deps.directRuntime.deleteMessage(chatId, messageId);
242
+ await deps.callFollowerApi("call", [
243
+ "deleteMessage",
244
+ {
245
+ chat_id: chatId,
246
+ message_id: messageId,
247
+ },
248
+ ]);
249
+ },
250
+ prepareTempDir() {
251
+ return deps.directRuntime.prepareTempDir();
252
+ },
253
+ };
254
+ }