@markusylisiurunen/tau 0.3.101 → 0.3.102

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 (63) hide show
  1. package/dist/core/config/ownership.js +3 -1
  2. package/dist/core/config/ownership.js.map +1 -1
  3. package/dist/core/config/schema.js +3 -1
  4. package/dist/core/config/schema.js.map +1 -1
  5. package/dist/core/history/migrations.js +6 -1
  6. package/dist/core/history/migrations.js.map +1 -1
  7. package/dist/core/static/tau_docs/config-reference.md +17 -5
  8. package/dist/core/static/tau_docs/credentials.md +4 -4
  9. package/dist/core/static/tau_docs/index.md +2 -1
  10. package/dist/core/static/tau_docs/manifest.json +1 -0
  11. package/dist/core/static/tau_docs/prompts-and-project-context.md +4 -4
  12. package/dist/core/static/tau_docs/session-protocol.md +1 -1
  13. package/dist/core/static/tau_docs/telegram-commands.md +55 -0
  14. package/dist/core/static/tau_docs/telegram.md +10 -38
  15. package/dist/core/static/tau_docs/tui.md +17 -11
  16. package/dist/core/subagents/claude_code_runner.mjs +65 -65
  17. package/dist/core/telegram/adapter.js +178 -61
  18. package/dist/core/telegram/adapter.js.map +1 -1
  19. package/dist/core/telegram/cli.js +1 -3
  20. package/dist/core/telegram/cli.js.map +1 -1
  21. package/dist/core/telegram/config.js +3 -1
  22. package/dist/core/telegram/config.js.map +1 -1
  23. package/dist/core/telegram/runtime.js +1 -1
  24. package/dist/core/telegram/runtime.js.map +1 -1
  25. package/dist/core/utils/scribe_transcription.js +283 -0
  26. package/dist/core/utils/scribe_transcription.js.map +1 -0
  27. package/dist/core/utils/speech_cleanup.js +198 -0
  28. package/dist/core/utils/speech_cleanup.js.map +1 -0
  29. package/dist/core/utils/speech_to_text.js +3 -3
  30. package/dist/core/utils/speech_to_text_keywords.js +5 -4
  31. package/dist/core/utils/speech_to_text_keywords.js.map +1 -1
  32. package/dist/core/version.js +1 -1
  33. package/dist/diff_tool/app/dist/assets/{core-CXVpaOO1.js → core-Cnp6wBC7.js} +1 -1
  34. package/dist/diff_tool/app/dist/assets/engine-oniguruma-ConHyUk6.js +1 -0
  35. package/dist/diff_tool/app/dist/assets/{highlights-DuJNYjEh.js → highlights-DeO0fGqQ.js} +1 -1
  36. package/dist/diff_tool/app/dist/assets/index-BDuQ2wXS.js +221 -0
  37. package/dist/diff_tool/app/dist/assets/langs-DDFHLNuJ.js +1 -0
  38. package/dist/diff_tool/app/dist/assets/{loader-bi21_x0K.js → loader-DrwOwtvp.js} +1 -1
  39. package/dist/diff_tool/app/dist/assets/{preload-helper-CRzLMJPS.js → preload-helper-DclECHGd.js} +1 -1
  40. package/dist/diff_tool/app/dist/assets/{shiki-D6ZyrNQD.js → shiki-CwKGJZFi.js} +2 -2
  41. package/dist/diff_tool/app/dist/assets/{stream-tokenizer-BdsyU_yB.js → stream-tokenizer-D4-m26wx.js} +1 -1
  42. package/dist/diff_tool/app/dist/assets/{themes-9lpTYI_i.js → themes-Do3waJhf.js} +2 -2
  43. package/dist/diff_tool/app/dist/index.html +2 -2
  44. package/dist/history/worker/index.js +77 -51
  45. package/dist/history/worker/index.js.map +1 -1
  46. package/dist/history/worker/migrations/0003_digest_schedule.sql +36 -0
  47. package/dist/history/worker/migrations/0004_recent_sessions.sql +1 -0
  48. package/dist/store/session_snapshot_migrations.js +14 -1
  49. package/dist/store/session_snapshot_migrations.js.map +1 -1
  50. package/dist/tui/chat_view.js +3 -1
  51. package/dist/tui/chat_view.js.map +1 -1
  52. package/dist/tui/listen_capture.js +7 -5
  53. package/dist/tui/listen_capture.js.map +1 -1
  54. package/dist/tui/session_chat_controller.js +93 -15
  55. package/dist/tui/session_chat_controller.js.map +1 -1
  56. package/dist/tui/ui/custom_editor.js +3 -0
  57. package/dist/tui/ui/custom_editor.js.map +1 -1
  58. package/package.json +8 -7
  59. package/dist/core/utils/gemini_transcription.js +0 -566
  60. package/dist/core/utils/gemini_transcription.js.map +0 -1
  61. package/dist/diff_tool/app/dist/assets/engine-oniguruma-Rz_7DPcV.js +0 -1
  62. package/dist/diff_tool/app/dist/assets/index-F9is7PUw.js +0 -221
  63. package/dist/diff_tool/app/dist/assets/langs-CTftvgbb.js +0 -1
@@ -5,6 +5,7 @@ import { TauSessionProtocolResponseError } from "../../transport/errors.js";
5
5
  import { formatAutoCompactThreshold, parseAutoCompactThreshold } from "../commands/auto_compact.js";
6
6
  import { getEffectiveAutoCompactThresholdTokens } from "../session/auto_compaction_threshold.js";
7
7
  import { formatAdaptiveNumber, formatTokenWindow } from "../utils/format.js";
8
+ import { cleanupSpeechTranscript } from "../utils/speech_cleanup.js";
8
9
  import { createSpeechToTextTranscription, SPEECH_TO_TEXT_CLIENT_MAX_DURATION_MS, } from "../utils/speech_to_text.js";
9
10
  import { collectSpeechToTextContext } from "../utils/speech_to_text_context.js";
10
11
  import { composeSpeechVocabulary } from "../utils/speech_to_text_keywords.js";
@@ -51,6 +52,7 @@ const TELEGRAM_REASONING_EFFORTS = [
51
52
  "xhigh",
52
53
  ];
53
54
  const NO_ACTIVE_SESSION_MESSAGE = "no active session. use /new.";
55
+ const TELEGRAM_NO_REASONING_EFFORT_MESSAGE = "no reasoning efforts are available through Telegram for this session.";
54
56
  const MIME_EXTENSION_BY_TYPE = {
55
57
  "application/pdf": ".pdf",
56
58
  "application/json": ".json",
@@ -88,6 +90,12 @@ function splitCommandText(text) {
88
90
  .map((part) => part.trim())
89
91
  .filter(Boolean);
90
92
  }
93
+ // Command text reaches handlers with its whitespace collapsed, so identifiers are compared the same
94
+ // way. Identifiers that become indistinguishable stay reachable through the picker.
95
+ function findByCommandValue(items, identifierOf, value) {
96
+ const matches = items.filter((item) => splitCommandText(identifierOf(item)).join(" ") === value);
97
+ return matches.length === 1 ? matches[0] : undefined;
98
+ }
91
99
  function stripCommandMention(command) {
92
100
  const mentionIndex = command.indexOf("@");
93
101
  if (mentionIndex === -1) {
@@ -359,16 +367,16 @@ function formatTelegramContextUsage(snapshot) {
359
367
  function getTelegramSessionCostTotal(snapshot) {
360
368
  return snapshot.costTotal;
361
369
  }
362
- function supportsReasoningEffort(snapshot, reasoning) {
370
+ function getSupportedReasoningEfforts(snapshot) {
363
371
  if (!snapshot.bootstrap.model.reasoning) {
364
- return false;
372
+ return [];
365
373
  }
366
374
  const persona = snapshot.catalog.personas.find((candidate) => candidate.id === snapshot.settings.personaId);
367
375
  if (!persona) {
368
- return false;
376
+ return [];
369
377
  }
370
378
  const allowed = persona.allowedReasoningLevels;
371
- return !allowed || allowed.length === 0 || allowed.includes(reasoning);
379
+ return TELEGRAM_REASONING_EFFORTS.filter((reasoning) => !allowed || allowed.length === 0 || allowed.includes(reasoning));
372
380
  }
373
381
  function formatTelegramSessionCost(total) {
374
382
  return `$${formatAdaptiveNumber(total, 2, 5)}`;
@@ -779,7 +787,7 @@ class TelegramAdapterImpl {
779
787
  allowedUserIds;
780
788
  allowedChatIds;
781
789
  botUsername;
782
- geminiApiKey;
790
+ speechCleanupStyle;
783
791
  openAIApiKey;
784
792
  elevenLabsApiKey;
785
793
  speechVoiceId;
@@ -800,6 +808,7 @@ class TelegramAdapterImpl {
800
808
  abortController = new AbortController();
801
809
  personaPickers = new Map();
802
810
  promptPickers = new Map();
811
+ effortPickers = new Map();
803
812
  activeSessionsByChat = new Map();
804
813
  sessionsByChat = new Map();
805
814
  chatsBySession = new Map();
@@ -836,7 +845,7 @@ class TelegramAdapterImpl {
836
845
  ? new Set(options.allowedChatIds)
837
846
  : undefined;
838
847
  this.botUsername = options.botUsername;
839
- this.geminiApiKey = options.geminiApiKey?.trim() || undefined;
848
+ this.speechCleanupStyle = options.speechCleanupStyle ?? "off";
840
849
  this.openAIApiKey = options.openAIApiKey?.trim() || undefined;
841
850
  this.elevenLabsApiKey = options.elevenLabsApiKey?.trim() || undefined;
842
851
  this.speechVoiceId = options.speechVoiceId;
@@ -924,6 +933,11 @@ class TelegramAdapterImpl {
924
933
  hiddenFromMenu: this.presets !== undefined && Object.keys(this.presets).length === 0,
925
934
  handler: async (chatId, args) => this.handlePersona(chatId, args),
926
935
  },
936
+ {
937
+ command: "/effort",
938
+ description: "choose the reasoning effort for future turns",
939
+ handler: async (chatId, args) => this.handleEffort(chatId, args),
940
+ },
927
941
  {
928
942
  command: "/prompt",
929
943
  description: "add a saved prompt without starting a turn",
@@ -956,13 +970,6 @@ class TelegramAdapterImpl {
956
970
  handler: async (chatId, args) => this.handleTtsPreference(chatId, false, args),
957
971
  },
958
972
  ];
959
- for (const reasoning of TELEGRAM_REASONING_EFFORTS) {
960
- definitions.push({
961
- command: `/effort_${reasoning}`,
962
- description: `set reasoning effort to ${reasoning}`,
963
- handler: async (chatId, args) => this.handleSetReasoning(chatId, reasoning, args),
964
- });
965
- }
966
973
  for (const projectId of this.allowedProjectIds) {
967
974
  definitions.push({
968
975
  command: `/use_${projectId}`,
@@ -1486,6 +1493,10 @@ class TelegramAdapterImpl {
1486
1493
  await this.handlePersonaCallback(chatId, callbackData, messageId);
1487
1494
  return true;
1488
1495
  }
1496
+ if (callbackData.startsWith("effort:")) {
1497
+ await this.handleEffortCallback(chatId, callbackData, messageId);
1498
+ return true;
1499
+ }
1489
1500
  if (callbackData.startsWith("prompt:")) {
1490
1501
  await this.handlePromptCallback(chatId, callbackData, messageId);
1491
1502
  return true;
@@ -1544,8 +1555,8 @@ class TelegramAdapterImpl {
1544
1555
  await this.reply(chatId, `usage: ${command}`);
1545
1556
  return;
1546
1557
  }
1547
- if (enabled && !this.geminiApiKey) {
1548
- await this.reply(chatId, "set GEMINI_API_KEY or apiKeys.google to enable voice responses.");
1558
+ if (enabled && !this.elevenLabsApiKey) {
1559
+ await this.reply(chatId, "set ELEVENLABS_API_KEY or apiKeys.elevenlabs to enable voice responses.");
1549
1560
  return;
1550
1561
  }
1551
1562
  try {
@@ -1556,11 +1567,27 @@ class TelegramAdapterImpl {
1556
1567
  await this.reply(chatId, `failed to save voice response preference: ${error instanceof Error ? error.message : String(error)}`);
1557
1568
  }
1558
1569
  }
1559
- async handlePersona(chatId, args) {
1560
- if (args.length > 0) {
1561
- await this.reply(chatId, "use /persona to choose a persona.");
1562
- return;
1570
+ getPersonaChoices(snapshot) {
1571
+ if (this.presets === undefined) {
1572
+ return snapshot.catalog.personas.map((persona) => ({
1573
+ key: persona.id,
1574
+ id: persona.id,
1575
+ label: persona.label || persona.id,
1576
+ }));
1563
1577
  }
1578
+ return Object.entries(this.presets).map(([key, preset]) => preset.source === "workspace"
1579
+ ? { key, id: null, label: preset.label }
1580
+ : {
1581
+ key,
1582
+ id: preset.persona,
1583
+ label: preset.label,
1584
+ overrides: {
1585
+ reasoning: preset.reasoning,
1586
+ autoCompactThresholdTokens: preset.autoCompactThresholdTokens,
1587
+ },
1588
+ });
1589
+ }
1590
+ async handlePersona(chatId, args) {
1564
1591
  if (this.presets !== undefined && Object.keys(this.presets).length === 0) {
1565
1592
  await this.reply(chatId, "this bot has no presets configured.");
1566
1593
  return;
@@ -1574,23 +1601,21 @@ class TelegramAdapterImpl {
1574
1601
  await this.reply(chatId, "the session is still preparing.");
1575
1602
  return;
1576
1603
  }
1577
- const catalog = snapshot.catalog.personas;
1578
- const personas = this.presets === undefined
1579
- ? catalog.map((persona) => ({ id: persona.id, label: persona.label || persona.id }))
1580
- : Object.values(this.presets).map((preset) => preset.source === "workspace"
1581
- ? { id: null, label: preset.label }
1582
- : {
1583
- id: preset.persona,
1584
- label: preset.label,
1585
- overrides: {
1586
- reasoning: preset.reasoning,
1587
- autoCompactThresholdTokens: preset.autoCompactThresholdTokens,
1588
- },
1589
- });
1604
+ const personas = this.getPersonaChoices(snapshot);
1590
1605
  if (personas.length === 0) {
1591
1606
  await this.reply(chatId, "this bot has no presets configured.");
1592
1607
  return;
1593
1608
  }
1609
+ if (args.length > 0) {
1610
+ const value = args.join(" ");
1611
+ const persona = findByCommandValue(personas, (choice) => choice.key, value);
1612
+ if (!persona) {
1613
+ await this.reply(chatId, `this session has no persona or preset called ${value}. use /persona to see the choices.`);
1614
+ return;
1615
+ }
1616
+ await this.applyPersona(chatId, session.id, persona);
1617
+ return;
1618
+ }
1594
1619
  this.personaPickers.set(chatId, {
1595
1620
  token: randomUUID(),
1596
1621
  sessionId: session.id,
@@ -1653,23 +1678,36 @@ class TelegramAdapterImpl {
1653
1678
  const persona = picker.personas[index];
1654
1679
  if (!persona)
1655
1680
  return;
1681
+ await this.applyPersona(chatId, picker.sessionId, persona, messageId);
1682
+ }
1683
+ async applyPersona(chatId, sessionId, persona, pickerMessageId) {
1656
1684
  let snapshot;
1657
1685
  try {
1658
- snapshot = await this.getSessionManagerForChat(chatId).setPersona(picker.sessionId, persona.id, persona.overrides);
1686
+ snapshot = await this.getSessionManagerForChat(chatId).setPersona(sessionId, persona.id, persona.overrides);
1659
1687
  }
1660
1688
  catch (error) {
1661
1689
  await this.reply(chatId, this.formatManagerError(error));
1662
1690
  return;
1663
1691
  }
1664
1692
  this.personaPickers.delete(chatId);
1665
- const text = `switched to ${persona.label}. this session is using ${snapshot.bootstrap.model.name || snapshot.bootstrap.model.id} with ${snapshot.settings.reasoning ?? "none"} reasoning.`;
1666
- await this.sendWithRetry((signal) => this.api.editMessage(chatId, messageId, text, { signal }));
1693
+ await this.sendSelectionResult(chatId, `switched to ${persona.label}. this session is using ${snapshot.bootstrap.model.name || snapshot.bootstrap.model.id} with ${snapshot.settings.reasoning ?? "none"} reasoning.`, pickerMessageId);
1667
1694
  }
1668
- async handlePrompt(chatId, args) {
1669
- if (args.length > 0) {
1670
- await this.reply(chatId, "use /prompt to choose a saved prompt.");
1695
+ // A picker's result replaces its message and removes the buttons, and a typed choice gets a reply.
1696
+ async sendSelectionResult(chatId, text, pickerMessageId) {
1697
+ if (pickerMessageId === undefined) {
1698
+ await this.reply(chatId, text);
1671
1699
  return;
1672
1700
  }
1701
+ for (const [index, chunk] of splitTelegramMessage(text).entries()) {
1702
+ if (index === 0) {
1703
+ await this.sendWithRetry((signal) => this.api.editMessage(chatId, pickerMessageId, chunk, { signal }));
1704
+ }
1705
+ else {
1706
+ await this.reply(chatId, chunk);
1707
+ }
1708
+ }
1709
+ }
1710
+ async handlePrompt(chatId, args) {
1673
1711
  const session = await this.requireActiveSession(chatId);
1674
1712
  if (!session)
1675
1713
  return;
@@ -1684,6 +1722,16 @@ class TelegramAdapterImpl {
1684
1722
  await this.reply(chatId, "this session has no saved prompts.");
1685
1723
  return;
1686
1724
  }
1725
+ if (args.length > 0) {
1726
+ const value = args.join(" ");
1727
+ const prompt = findByCommandValue(prompts, (candidate) => candidate.id, value);
1728
+ if (!prompt) {
1729
+ await this.reply(chatId, `this session has no saved prompt called ${value}. use /prompt to see the choices.`);
1730
+ return;
1731
+ }
1732
+ await this.applyPrompt(chatId, session.id, prompt.id);
1733
+ return;
1734
+ }
1687
1735
  this.promptPickers.set(chatId, { token: randomUUID(), sessionId: session.id, prompts });
1688
1736
  await this.showPromptPage(chatId, 0);
1689
1737
  }
@@ -1741,46 +1789,92 @@ class TelegramAdapterImpl {
1741
1789
  const prompt = picker.prompts[index];
1742
1790
  if (!prompt)
1743
1791
  return;
1792
+ await this.applyPrompt(chatId, picker.sessionId, prompt.id, messageId);
1793
+ }
1794
+ async applyPrompt(chatId, sessionId, promptId, pickerMessageId) {
1744
1795
  let text;
1745
1796
  try {
1746
- text = await this.getSessionManagerForChat(chatId).recordPrompt(picker.sessionId, prompt.id);
1797
+ text = await this.getSessionManagerForChat(chatId).recordPrompt(sessionId, promptId);
1747
1798
  }
1748
1799
  catch (error) {
1749
1800
  await this.reply(chatId, this.formatManagerError(error));
1750
1801
  return;
1751
1802
  }
1752
1803
  this.promptPickers.delete(chatId);
1753
- const chunks = splitTelegramMessage(`added this prompt to the conversation. send a message when you’re ready for Tau to respond.\n\n${text}`);
1754
- for (const [index, chunk] of chunks.entries()) {
1755
- if (index === 0) {
1756
- await this.sendWithRetry((signal) => this.api.editMessage(chatId, messageId, chunk, { signal }));
1757
- }
1758
- else {
1759
- await this.reply(chatId, chunk);
1760
- }
1761
- }
1804
+ await this.sendSelectionResult(chatId, `added this prompt to the conversation. send a message when you’re ready for Tau to respond.\n\n${text}`, pickerMessageId);
1762
1805
  }
1763
- async handleSetReasoning(chatId, reasoning, args) {
1806
+ async handleEffort(chatId, args) {
1807
+ const session = await this.requireActiveSession(chatId);
1808
+ if (!session)
1809
+ return;
1764
1810
  if (args.length > 0) {
1765
- await this.reply(chatId, `usage: /effort_${reasoning}`);
1811
+ await this.applyEffort(chatId, session.id, args.join(" "));
1766
1812
  return;
1767
1813
  }
1768
- const session = await this.requireActiveSession(chatId);
1769
- if (!session) {
1814
+ try {
1815
+ const snapshot = await this.getSessionManagerForChat(chatId).getSessionSnapshot(session.id);
1816
+ if (!snapshot) {
1817
+ await this.reply(chatId, "the session is still preparing.");
1818
+ return;
1819
+ }
1820
+ const efforts = getSupportedReasoningEfforts(snapshot);
1821
+ if (efforts.length === 0) {
1822
+ await this.reply(chatId, TELEGRAM_NO_REASONING_EFFORT_MESSAGE);
1823
+ return;
1824
+ }
1825
+ const token = randomUUID();
1826
+ this.effortPickers.set(chatId, { token, sessionId: session.id });
1827
+ await this.reply(chatId, `choose the reasoning effort for future turns. this session is using ${snapshot.settings.reasoning ?? "none"}.`, {
1828
+ replyMarkup: {
1829
+ inline_keyboard: [
1830
+ efforts.map((effort) => ({
1831
+ text: effort,
1832
+ callback_data: `effort:${token}:select:${effort}`,
1833
+ })),
1834
+ ],
1835
+ },
1836
+ });
1837
+ }
1838
+ catch (error) {
1839
+ await this.reply(chatId, this.formatManagerError(error));
1840
+ }
1841
+ }
1842
+ async handleEffortCallback(chatId, data, messageId) {
1843
+ const match = /^effort:([^:]+):select:([a-z]+)$/.exec(data);
1844
+ const picker = this.effortPickers.get(chatId);
1845
+ if (!match?.[2] ||
1846
+ !picker ||
1847
+ picker.token !== match[1] ||
1848
+ this.getActiveSession(chatId)?.id !== picker.sessionId ||
1849
+ messageId === undefined) {
1850
+ await this.reply(chatId, "this effort picker has expired. use /effort to open a new one.");
1770
1851
  return;
1771
1852
  }
1853
+ await this.applyEffort(chatId, picker.sessionId, match[2], messageId);
1854
+ }
1855
+ // The persona can change while a picker is open, so every choice is checked against the current
1856
+ // snapshot.
1857
+ async applyEffort(chatId, sessionId, value, pickerMessageId) {
1772
1858
  try {
1773
1859
  const sessionManager = this.getSessionManagerForChat(chatId);
1774
- const snapshot = await sessionManager.getSessionSnapshot(session.id);
1860
+ const snapshot = await sessionManager.getSessionSnapshot(sessionId);
1775
1861
  if (!snapshot) {
1776
- throw new TelegramSessionManagerError("not_ready", "session is still preparing");
1862
+ await this.reply(chatId, "the session is still preparing.");
1863
+ return;
1864
+ }
1865
+ const efforts = getSupportedReasoningEfforts(snapshot);
1866
+ if (efforts.length === 0) {
1867
+ await this.reply(chatId, TELEGRAM_NO_REASONING_EFFORT_MESSAGE);
1868
+ return;
1777
1869
  }
1778
- if (!supportsReasoningEffort(snapshot, reasoning)) {
1779
- await this.reply(chatId, `reasoning effort ${reasoning} is not supported by this session.`);
1870
+ const reasoning = efforts.find((effort) => effort === value);
1871
+ if (!reasoning) {
1872
+ await this.reply(chatId, `reasoning effort ${value} is not available through Telegram for this session. use /effort to see the choices.`);
1780
1873
  return;
1781
1874
  }
1782
- await sessionManager.setReasoning(session.id, reasoning);
1783
- await this.reply(chatId, `reasoning effort set to ${reasoning}.`);
1875
+ await sessionManager.setReasoning(sessionId, reasoning);
1876
+ this.effortPickers.delete(chatId);
1877
+ await this.sendSelectionResult(chatId, `reasoning effort set to ${reasoning} for future turns.`, pickerMessageId);
1784
1878
  }
1785
1879
  catch (error) {
1786
1880
  await this.reply(chatId, this.formatManagerError(error));
@@ -2022,10 +2116,10 @@ class TelegramAdapterImpl {
2022
2116
  }
2023
2117
  }
2024
2118
  getSpeechToTextApiKey() {
2025
- return this.geminiApiKey;
2119
+ return this.elevenLabsApiKey;
2026
2120
  }
2027
2121
  getSpeechToTextApiKeyErrorMessage(action) {
2028
- return `set GEMINI_API_KEY or apiKeys.google to ${action}`;
2122
+ return `set ELEVENLABS_API_KEY or apiKeys.elevenlabs to ${action}`;
2029
2123
  }
2030
2124
  async transcribeTelegramVoice(chatId, message, options = {}) {
2031
2125
  if (message.durationMs > SPEECH_TO_TEXT_CLIENT_MAX_DURATION_MS) {
@@ -2051,12 +2145,13 @@ class TelegramAdapterImpl {
2051
2145
  if (options.sessionId && !snapshot) {
2052
2146
  throw new Error("session is not ready for speech input");
2053
2147
  }
2148
+ const vocabulary = composeSpeechVocabulary(snapshot?.catalog.speechVocabulary ?? [], this.personalSpeechVocabulary ?? []);
2054
2149
  const transcription = createSpeechToTextTranscription({
2055
2150
  mode: "file",
2056
2151
  apiKey,
2057
2152
  openAIApiKey: this.openAIApiKey,
2058
2153
  context: snapshot ? collectSpeechToTextContext(snapshot) : undefined,
2059
- vocabulary: composeSpeechVocabulary(snapshot?.catalog.speechVocabulary ?? [], this.personalSpeechVocabulary ?? []),
2154
+ vocabulary,
2060
2155
  deps: {
2061
2156
  ...this.speechToTextDeps,
2062
2157
  fetchImpl: this.fetchImpl,
@@ -2067,6 +2162,28 @@ class TelegramAdapterImpl {
2067
2162
  audio: message.audio,
2068
2163
  mimeType: message.mimeType,
2069
2164
  }, { signal: this.abortController.signal });
2165
+ try {
2166
+ transcript = await cleanupSpeechTranscript({
2167
+ transcript,
2168
+ style: this.speechCleanupStyle,
2169
+ context: snapshot ? collectSpeechToTextContext(snapshot) : undefined,
2170
+ apiKey: this.openAIApiKey,
2171
+ vocabulary,
2172
+ signal: this.abortController.signal,
2173
+ fetchImpl: this.fetchImpl,
2174
+ });
2175
+ }
2176
+ catch (error) {
2177
+ this.abortController.signal.throwIfAborted();
2178
+ if (!options.silent) {
2179
+ await this.reply(chatId, `speech cleanup failed; using the original transcript: ${this.formatManagerError(error)}`).catch((error) => {
2180
+ this.log("warn", "failed to send speech cleanup warning", {
2181
+ chatId,
2182
+ cause: this.formatManagerError(error),
2183
+ });
2184
+ });
2185
+ }
2186
+ }
2070
2187
  }
2071
2188
  finally {
2072
2189
  transcription.abort();