@ours.network/tg-connector 0.1.1 → 0.1.3

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 (33) hide show
  1. package/README.md +62 -0
  2. package/dist/cli.js +35 -2
  3. package/dist/connector.js +105 -7
  4. package/dist/mufl_code/2DA1D5F860E42C605D92F1E24E2466C70EFDDBF057BBCBA52F0ECC639EFCA387.muflo +0 -0
  5. package/dist/mufl_code/core/CLUSTER_API.md +640 -0
  6. package/dist/mufl_code/core/CLUSTER_CONTRACT.md +121 -0
  7. package/dist/mufl_code/core/CLUSTER_INTRODUCTION_PLAN.md +200 -0
  8. package/dist/mufl_code/core/CONFIGURATION_DESIGN.md +35 -0
  9. package/dist/mufl_code/core/CONFIGURATION_PLAN.md +394 -0
  10. package/dist/mufl_code/core/DEVELOPMENT.md +168 -0
  11. package/dist/mufl_code/core/EPHEMERAL_INVITE_PLAN.md +465 -0
  12. package/dist/mufl_code/core/GROUP_CHAT_DESIGN.md +520 -0
  13. package/dist/mufl_code/core/LICENSE +98 -0
  14. package/dist/mufl_code/core/README.md +76 -0
  15. package/dist/mufl_code/core/a2a_capabilities.mm +350 -0
  16. package/dist/mufl_code/core/a2a_cluster.mm +601 -0
  17. package/dist/mufl_code/core/a2a_control.mm +89 -0
  18. package/dist/mufl_code/core/a2a_messaging.mm +2103 -0
  19. package/dist/mufl_code/core/a2a_monitoring.mm +94 -0
  20. package/dist/mufl_code/core/a2a_protocol.mm +231 -0
  21. package/dist/mufl_code/core/config.mufl +26 -0
  22. package/dist/mufl_code/core/release-notes/2.0.md +268 -0
  23. package/dist/mufl_code/core/release-notes/2.1.md +92 -0
  24. package/dist/mufl_code/core/release-notes/2.2.md +94 -0
  25. package/dist/mufl_code/core/release-notes/3.0.md +162 -0
  26. package/dist/mufl_code/core/release-notes/3.1.md +43 -0
  27. package/dist/mufl_code/core/release-notes/README.md +32 -0
  28. package/dist/mufl_code/core/tests/README.md +66 -0
  29. package/dist/mufl_code/core/tests/run.sh +67 -0
  30. package/dist/mufl_code/core/tests/test.mjs +467 -0
  31. package/dist/mufl_code/core/tests/test_actor.mu +287 -0
  32. package/dist/mufl_code/core/version.mm +24 -0
  33. package/package.json +4 -2
package/README.md CHANGED
@@ -167,6 +167,59 @@ distinct from `send_message`, so files and text are always separate messages.
167
167
  plane receives a forced **metadata-only** copy (`[file] <name> (<mime>, <N> B)`)
168
168
  — never the bytes.
169
169
 
170
+ ### Voice transcription (speech-to-text)
171
+
172
+ A Telegram **voice note** carries no caption, so a bridged agent (a text LLM)
173
+ would otherwise receive an empty `text` and an unreadable audio blob. With STT
174
+ enabled, the connector transcribes the voice note and delivers the transcript
175
+ **through the normal envelope as ordinary `text`**, so any agent understands a
176
+ spoken message with **zero agent-side changes**. A small `transcription` block is
177
+ added for provenance:
178
+
179
+ ```jsonc
180
+ {
181
+ "v": 2,
182
+ "text": "let's ship it friday", // the transcript (voice notes have no caption)
183
+ "transcription": {
184
+ "text": "let's ship it friday",
185
+ "engine": "openai", // best-effort label from the provider host
186
+ "model": "whisper-1",
187
+ "lang": "en", // only if the provider returns it
188
+ "status": "ok" // "ok" | "error" (on error: "error":"<reason>", no text)
189
+ }
190
+ }
191
+ ```
192
+
193
+ - **Opt-in.** Off by default (`sttEnabled:false`) — behaviour is then byte-identical
194
+ to today. Turn it on and supply a key (see [Configuration](#configuration)).
195
+ - **No transcoding.** Telegram voice is **OGG/Opus**, which OpenAI-compatible
196
+ transcription endpoints accept directly — the connector adds **no ffmpeg** and no
197
+ new dependency (just built-in `fetch`).
198
+ - **Provider-agnostic.** The endpoint is `{sttBaseUrl}/audio/transcriptions` with a
199
+ `Bearer` key — point it at OpenAI (`whisper-1`), Groq
200
+ (`whisper-large-v3-turbo`, faster/cheaper), or a **self-hosted** `whisper.cpp`
201
+ server. One config switch, no lock-in.
202
+ - **Audio forwarding.** By default a successfully transcribed voice note is
203
+ delivered as **text only** (no `send_file`, no `attachment` block — the
204
+ `transcription` block already signals it came from voice). Set
205
+ `forwardVoiceAudio:true` to also `send_file` the `.ogg` alongside the transcript.
206
+ - **Graceful degradation.** If STT is disabled, fails, times out, or the audio is
207
+ over `sttMaxBytes`, the bridge falls back to **today's exact behaviour** — the
208
+ `.ogg` is still forwarded via `send_file` and nothing the user sent is lost. When
209
+ STT was attempted and failed, the envelope adds `transcription.status:"error"`
210
+ (e.g. `error:"too_large"` for the size guard); the daemon logs a single line
211
+ **without the key** and keeps polling.
212
+ - **Cost & data egress.** Transcription bills to the configured provider
213
+ (whisper-1 ≈ **$0.006/min**, billed to the nearest second; operators pick the
214
+ provider and bear the cost). **Audio bytes leave the host** for that provider —
215
+ point `sttBaseUrl` at a self-hosted server to keep audio local. Per-message cost
216
+ and latency are bounded by `sttMaxBytes` and `sttTimeoutMs`.
217
+
218
+ **Secret handling.** Supply the key via `OURS_TG_STT_API_KEY` (preferred). If it
219
+ is placed in `config.json` instead, the file stays mode `0600` and the key is
220
+ **masked** whenever the daemon rewrites config — it is never persisted in clear
221
+ and never written to logs.
222
+
170
223
  ## Install
171
224
 
172
225
  Install the CLI globally from npm:
@@ -263,6 +316,15 @@ Precedence per field: **env var > `config.json` > default**. The config file is
263
316
  | poll timeout | `OURS_TG_POLL_TIMEOUT` | `30` (seconds, Telegram long-poll) |
264
317
  | attachment cap | `OURS_TG_ATTACHMENT_MAX_BYTES` | `10485760` (10 MB; larger inbound media forwarded as a metadata-only stub) |
265
318
  | outbound file cap | `OURS_TG_OUTBOUND_FILE_MAX_BYTES` | `52428800` (50 MB; a larger file from a contact is skipped + logged — Telegram's `sendDocument` limit) |
319
+ | STT enabled | `OURS_TG_STT_ENABLED` | `false` (master switch for voice transcription; off ⇒ byte-identical to today) |
320
+ | STT API key | `OURS_TG_STT_API_KEY` | `''` (secret; env preferred — masked if placed in `config.json`, never logged) |
321
+ | STT base URL | `OURS_TG_STT_BASE_URL` | `https://api.openai.com/v1` (OpenAI-compatible endpoint root; e.g. `https://api.groq.com/openai/v1` or a self-hosted whisper server) |
322
+ | STT model | `OURS_TG_STT_MODEL` | `whisper-1` (e.g. `whisper-large-v3-turbo` on Groq) |
323
+ | STT language | `OURS_TG_STT_LANGUAGE` | *(unset)* (optional ISO-639-1 hint; omit ⇒ provider auto-detects) |
324
+ | STT kinds | `OURS_TG_STT_KINDS` | `voice` (comma-list of attachment kinds to transcribe; e.g. `voice,audio`) |
325
+ | STT size guard | `OURS_TG_STT_MAX_BYTES` | `5242880` (5 MB; audio over this skips STT and is forwarded as a file — cost/latency guard) |
326
+ | STT timeout | `OURS_TG_STT_TIMEOUT_MS` | `60000` (per-transcription abort deadline, ms) |
327
+ | forward voice audio | `OURS_TG_FORWARD_VOICE_AUDIO` | `false` (also `send_file` the `.ogg` alongside a successful transcript) |
266
328
 
267
329
  The control API is bound to `127.0.0.1` and unauthenticated — it manages bot
268
330
  tokens, so do not expose the control port off-host.
package/dist/cli.js CHANGED
@@ -20,8 +20,18 @@ var DEFAULT_CONFIG = {
20
20
  pollTimeoutSec: 30,
21
21
  attachmentMaxBytes: 10 * 1024 * 1024,
22
22
  // 10 MB (encoded ≈ 13.5 MB; under Telegram's 20 MB bot-API download limit)
23
- outboundFileMaxBytes: 50 * 1024 * 1024
23
+ outboundFileMaxBytes: 50 * 1024 * 1024,
24
24
  // Telegram bot sendDocument upper bound
25
+ sttEnabled: false,
26
+ sttApiKey: "",
27
+ sttBaseUrl: "https://api.openai.com/v1",
28
+ sttModel: "whisper-1",
29
+ sttLanguage: "",
30
+ sttKinds: ["voice"],
31
+ sttMaxBytes: 5 * 1024 * 1024,
32
+ // 5 MB
33
+ sttTimeoutMs: 6e4,
34
+ forwardVoiceAudio: false
25
35
  };
26
36
  function configPath() {
27
37
  return process.env.OURS_TG_CONFIG ?? join(homedir(), ".ours-telegram", "config.json");
@@ -52,6 +62,15 @@ function readFileConfig() {
52
62
  if (typeof parsed.outboundFileMaxBytes === "number" && Number.isFinite(parsed.outboundFileMaxBytes)) {
53
63
  out2.outboundFileMaxBytes = parsed.outboundFileMaxBytes;
54
64
  }
65
+ if (typeof parsed.sttEnabled === "boolean") out2.sttEnabled = parsed.sttEnabled;
66
+ if (typeof parsed.sttApiKey === "string") out2.sttApiKey = parsed.sttApiKey;
67
+ if (typeof parsed.sttBaseUrl === "string") out2.sttBaseUrl = parsed.sttBaseUrl;
68
+ if (typeof parsed.sttModel === "string") out2.sttModel = parsed.sttModel;
69
+ if (typeof parsed.sttLanguage === "string") out2.sttLanguage = parsed.sttLanguage;
70
+ if (Array.isArray(parsed.sttKinds)) out2.sttKinds = parsed.sttKinds.filter((k) => typeof k === "string");
71
+ if (typeof parsed.sttMaxBytes === "number" && Number.isFinite(parsed.sttMaxBytes)) out2.sttMaxBytes = parsed.sttMaxBytes;
72
+ if (typeof parsed.sttTimeoutMs === "number" && Number.isFinite(parsed.sttTimeoutMs)) out2.sttTimeoutMs = parsed.sttTimeoutMs;
73
+ if (typeof parsed.forwardVoiceAudio === "boolean") out2.forwardVoiceAudio = parsed.forwardVoiceAudio;
55
74
  return out2;
56
75
  }
57
76
  function envInt(name) {
@@ -60,6 +79,11 @@ function envInt(name) {
60
79
  const n = parseInt(v, 10);
61
80
  return Number.isNaN(n) ? void 0 : n;
62
81
  }
82
+ function envBool(name) {
83
+ const v = process.env[name];
84
+ if (v === void 0) return void 0;
85
+ return v === "1" || v.toLowerCase() === "true";
86
+ }
63
87
  function loadConfig() {
64
88
  const file = readFileConfig();
65
89
  return {
@@ -68,7 +92,16 @@ function loadConfig() {
68
92
  stateDir: resolve(process.env.OURS_TG_STATE_DIR ?? file.stateDir ?? DEFAULT_CONFIG.stateDir),
69
93
  pollTimeoutSec: envInt("OURS_TG_POLL_TIMEOUT") ?? file.pollTimeoutSec ?? DEFAULT_CONFIG.pollTimeoutSec,
70
94
  attachmentMaxBytes: envInt("OURS_TG_ATTACHMENT_MAX_BYTES") ?? file.attachmentMaxBytes ?? DEFAULT_CONFIG.attachmentMaxBytes,
71
- outboundFileMaxBytes: envInt("OURS_TG_OUTBOUND_FILE_MAX_BYTES") ?? file.outboundFileMaxBytes ?? DEFAULT_CONFIG.outboundFileMaxBytes
95
+ outboundFileMaxBytes: envInt("OURS_TG_OUTBOUND_FILE_MAX_BYTES") ?? file.outboundFileMaxBytes ?? DEFAULT_CONFIG.outboundFileMaxBytes,
96
+ sttEnabled: envBool("OURS_TG_STT_ENABLED") ?? file.sttEnabled ?? DEFAULT_CONFIG.sttEnabled,
97
+ sttApiKey: process.env.OURS_TG_STT_API_KEY ?? file.sttApiKey ?? DEFAULT_CONFIG.sttApiKey,
98
+ sttBaseUrl: process.env.OURS_TG_STT_BASE_URL ?? file.sttBaseUrl ?? DEFAULT_CONFIG.sttBaseUrl,
99
+ sttModel: process.env.OURS_TG_STT_MODEL ?? file.sttModel ?? DEFAULT_CONFIG.sttModel,
100
+ sttLanguage: process.env.OURS_TG_STT_LANGUAGE ?? file.sttLanguage ?? DEFAULT_CONFIG.sttLanguage,
101
+ sttKinds: process.env.OURS_TG_STT_KINDS?.split(",").map((s) => s.trim()).filter(Boolean) ?? file.sttKinds ?? DEFAULT_CONFIG.sttKinds,
102
+ sttMaxBytes: envInt("OURS_TG_STT_MAX_BYTES") ?? file.sttMaxBytes ?? DEFAULT_CONFIG.sttMaxBytes,
103
+ sttTimeoutMs: envInt("OURS_TG_STT_TIMEOUT_MS") ?? file.sttTimeoutMs ?? DEFAULT_CONFIG.sttTimeoutMs,
104
+ forwardVoiceAudio: envBool("OURS_TG_FORWARD_VOICE_AUDIO") ?? file.forwardVoiceAudio ?? DEFAULT_CONFIG.forwardVoiceAudio
72
105
  };
73
106
  }
74
107
 
package/dist/connector.js CHANGED
@@ -18,8 +18,18 @@ var DEFAULT_CONFIG = {
18
18
  pollTimeoutSec: 30,
19
19
  attachmentMaxBytes: 10 * 1024 * 1024,
20
20
  // 10 MB (encoded ≈ 13.5 MB; under Telegram's 20 MB bot-API download limit)
21
- outboundFileMaxBytes: 50 * 1024 * 1024
21
+ outboundFileMaxBytes: 50 * 1024 * 1024,
22
22
  // Telegram bot sendDocument upper bound
23
+ sttEnabled: false,
24
+ sttApiKey: "",
25
+ sttBaseUrl: "https://api.openai.com/v1",
26
+ sttModel: "whisper-1",
27
+ sttLanguage: "",
28
+ sttKinds: ["voice"],
29
+ sttMaxBytes: 5 * 1024 * 1024,
30
+ // 5 MB
31
+ sttTimeoutMs: 6e4,
32
+ forwardVoiceAudio: false
23
33
  };
24
34
  function configPath() {
25
35
  return process.env.OURS_TG_CONFIG ?? join(homedir(), ".ours-telegram", "config.json");
@@ -50,6 +60,15 @@ function readFileConfig() {
50
60
  if (typeof parsed.outboundFileMaxBytes === "number" && Number.isFinite(parsed.outboundFileMaxBytes)) {
51
61
  out.outboundFileMaxBytes = parsed.outboundFileMaxBytes;
52
62
  }
63
+ if (typeof parsed.sttEnabled === "boolean") out.sttEnabled = parsed.sttEnabled;
64
+ if (typeof parsed.sttApiKey === "string") out.sttApiKey = parsed.sttApiKey;
65
+ if (typeof parsed.sttBaseUrl === "string") out.sttBaseUrl = parsed.sttBaseUrl;
66
+ if (typeof parsed.sttModel === "string") out.sttModel = parsed.sttModel;
67
+ if (typeof parsed.sttLanguage === "string") out.sttLanguage = parsed.sttLanguage;
68
+ if (Array.isArray(parsed.sttKinds)) out.sttKinds = parsed.sttKinds.filter((k) => typeof k === "string");
69
+ if (typeof parsed.sttMaxBytes === "number" && Number.isFinite(parsed.sttMaxBytes)) out.sttMaxBytes = parsed.sttMaxBytes;
70
+ if (typeof parsed.sttTimeoutMs === "number" && Number.isFinite(parsed.sttTimeoutMs)) out.sttTimeoutMs = parsed.sttTimeoutMs;
71
+ if (typeof parsed.forwardVoiceAudio === "boolean") out.forwardVoiceAudio = parsed.forwardVoiceAudio;
53
72
  return out;
54
73
  }
55
74
  function envInt(name) {
@@ -58,6 +77,11 @@ function envInt(name) {
58
77
  const n = parseInt(v, 10);
59
78
  return Number.isNaN(n) ? void 0 : n;
60
79
  }
80
+ function envBool(name) {
81
+ const v = process.env[name];
82
+ if (v === void 0) return void 0;
83
+ return v === "1" || v.toLowerCase() === "true";
84
+ }
61
85
  function loadConfig() {
62
86
  const file = readFileConfig();
63
87
  return {
@@ -66,7 +90,16 @@ function loadConfig() {
66
90
  stateDir: resolve(process.env.OURS_TG_STATE_DIR ?? file.stateDir ?? DEFAULT_CONFIG.stateDir),
67
91
  pollTimeoutSec: envInt("OURS_TG_POLL_TIMEOUT") ?? file.pollTimeoutSec ?? DEFAULT_CONFIG.pollTimeoutSec,
68
92
  attachmentMaxBytes: envInt("OURS_TG_ATTACHMENT_MAX_BYTES") ?? file.attachmentMaxBytes ?? DEFAULT_CONFIG.attachmentMaxBytes,
69
- outboundFileMaxBytes: envInt("OURS_TG_OUTBOUND_FILE_MAX_BYTES") ?? file.outboundFileMaxBytes ?? DEFAULT_CONFIG.outboundFileMaxBytes
93
+ outboundFileMaxBytes: envInt("OURS_TG_OUTBOUND_FILE_MAX_BYTES") ?? file.outboundFileMaxBytes ?? DEFAULT_CONFIG.outboundFileMaxBytes,
94
+ sttEnabled: envBool("OURS_TG_STT_ENABLED") ?? file.sttEnabled ?? DEFAULT_CONFIG.sttEnabled,
95
+ sttApiKey: process.env.OURS_TG_STT_API_KEY ?? file.sttApiKey ?? DEFAULT_CONFIG.sttApiKey,
96
+ sttBaseUrl: process.env.OURS_TG_STT_BASE_URL ?? file.sttBaseUrl ?? DEFAULT_CONFIG.sttBaseUrl,
97
+ sttModel: process.env.OURS_TG_STT_MODEL ?? file.sttModel ?? DEFAULT_CONFIG.sttModel,
98
+ sttLanguage: process.env.OURS_TG_STT_LANGUAGE ?? file.sttLanguage ?? DEFAULT_CONFIG.sttLanguage,
99
+ sttKinds: process.env.OURS_TG_STT_KINDS?.split(",").map((s) => s.trim()).filter(Boolean) ?? file.sttKinds ?? DEFAULT_CONFIG.sttKinds,
100
+ sttMaxBytes: envInt("OURS_TG_STT_MAX_BYTES") ?? file.sttMaxBytes ?? DEFAULT_CONFIG.sttMaxBytes,
101
+ sttTimeoutMs: envInt("OURS_TG_STT_TIMEOUT_MS") ?? file.sttTimeoutMs ?? DEFAULT_CONFIG.sttTimeoutMs,
102
+ forwardVoiceAudio: envBool("OURS_TG_FORWARD_VOICE_AUDIO") ?? file.forwardVoiceAudio ?? DEFAULT_CONFIG.forwardVoiceAudio
70
103
  };
71
104
  }
72
105
 
@@ -760,7 +793,10 @@ function buildAttachment(m, resolved, fileWireId) {
760
793
  }
761
794
  return { ...base, error: "attachment not resolved" };
762
795
  }
763
- function buildEnvelope(m, resolved, fileWireId) {
796
+ function buildEnvelope(m, resolved, fileWireId, transcription) {
797
+ const transcribed = transcription?.status === "ok" && typeof transcription.text === "string";
798
+ const text = transcribed && m.text === "" ? transcription.text : m.text;
799
+ const attachment = resolved ? buildAttachment(m, resolved, fileWireId) : void 0;
764
800
  const envelope = {
765
801
  v: ENVELOPE_VERSION,
766
802
  source: "telegram",
@@ -776,12 +812,47 @@ function buildEnvelope(m, resolved, fileWireId) {
776
812
  },
777
813
  reply_to: buildReply(m),
778
814
  forwarded_from: m.forwarded_from,
779
- text: m.text,
780
- attachment: buildAttachment(m, resolved, fileWireId)
815
+ text,
816
+ attachment,
817
+ transcription: transcription ?? void 0
781
818
  };
782
819
  return JSON.stringify(envelope);
783
820
  }
784
821
 
822
+ // src/stt.ts
823
+ async function transcribe(bytes, filename, mime, opts) {
824
+ if (!opts.apiKey) return { ok: false, error: "no STT api key configured" };
825
+ const aborter = new AbortController();
826
+ const timer = setTimeout(() => aborter.abort(), opts.timeoutMs);
827
+ try {
828
+ const form = new FormData();
829
+ form.set("file", new Blob([new Uint8Array(bytes)], { type: mime }), filename);
830
+ form.set("model", opts.model);
831
+ form.set("response_format", "json");
832
+ if (opts.language) form.set("language", opts.language);
833
+ const resp = await fetch(`${opts.baseUrl.replace(/\/$/, "")}/audio/transcriptions`, {
834
+ method: "POST",
835
+ headers: { Authorization: `Bearer ${opts.apiKey}` },
836
+ // fetch sets the multipart boundary
837
+ body: form,
838
+ signal: aborter.signal
839
+ });
840
+ if (!resp.ok) {
841
+ const detail = await resp.text().catch(() => "");
842
+ return { ok: false, error: `STT HTTP ${resp.status}${detail ? `: ${detail.slice(0, 200)}` : ""}` };
843
+ }
844
+ const body = await resp.json();
845
+ if (typeof body.text !== "string") return { ok: false, error: "STT response missing text" };
846
+ return { ok: true, text: body.text, lang: body.language };
847
+ } catch (err) {
848
+ const name = err?.name;
849
+ if (name === "AbortError") return { ok: false, error: `STT timeout after ${opts.timeoutMs}ms` };
850
+ return { ok: false, error: err instanceof Error ? err.message : String(err) };
851
+ } finally {
852
+ clearTimeout(timer);
853
+ }
854
+ }
855
+
785
856
  // src/routing.ts
786
857
  var ID_COMMAND_RE = /^\/id(?:@([A-Za-z0-9_]+))?$/i;
787
858
  function isIdCommand(text, botUsername) {
@@ -1030,9 +1101,36 @@ async function resolveAttachment(conn, d) {
1030
1101
  return { ok: false, reason: "error", detail: err instanceof Error ? err.message : String(err) };
1031
1102
  }
1032
1103
  }
1104
+ function sttEngineLabel(baseUrl) {
1105
+ try {
1106
+ return new URL(baseUrl).hostname.replace(/^api\./, "").split(".")[0];
1107
+ } catch {
1108
+ return "stt";
1109
+ }
1110
+ }
1033
1111
  async function forwardToNode(conn, m) {
1034
1112
  const { pkt, cfg } = conn;
1035
1113
  const resolved = m.attachment ? await resolveAttachment(conn, m.attachment) : void 0;
1114
+ let transcription;
1115
+ const kind = m.attachment?.kind;
1116
+ if (CONFIG.sttEnabled && kind && CONFIG.sttKinds.includes(kind) && resolved?.ok) {
1117
+ const engine = sttEngineLabel(CONFIG.sttBaseUrl);
1118
+ if (resolved.bytes.length > CONFIG.sttMaxBytes) {
1119
+ transcription = { status: "error", error: "too_large", engine, model: CONFIG.sttModel };
1120
+ } else {
1121
+ const meta = attachmentMeta(m.attachment, m.message_id);
1122
+ const r = await transcribe(resolved.bytes, meta.filename, meta.mime, {
1123
+ baseUrl: CONFIG.sttBaseUrl,
1124
+ apiKey: CONFIG.sttApiKey,
1125
+ model: CONFIG.sttModel,
1126
+ language: CONFIG.sttLanguage || void 0,
1127
+ timeoutMs: CONFIG.sttTimeoutMs
1128
+ });
1129
+ transcription = r.ok ? { status: "ok", text: r.text, engine, model: CONFIG.sttModel, lang: r.lang } : { status: "error", error: r.error, engine, model: CONFIG.sttModel };
1130
+ if (!r.ok) log(`[${cfg.name}] STT failed for ${kind} from ${m.from}: ${r.error}`);
1131
+ }
1132
+ }
1133
+ const sendAudio = !!resolved?.ok && !(transcription?.status === "ok" && !CONFIG.forwardVoiceAudio);
1036
1134
  const targets = [];
1037
1135
  if (cfg.peerCid) {
1038
1136
  targets.push(cfg.peerCid);
@@ -1047,7 +1145,7 @@ async function forwardToNode(conn, m) {
1047
1145
  }
1048
1146
  for (const target of targets) {
1049
1147
  let fileWireId;
1050
- if (m.attachment && resolved?.ok) {
1148
+ if (m.attachment && resolved?.ok && sendAudio) {
1051
1149
  const meta = attachmentMeta(m.attachment, m.message_id);
1052
1150
  const fileBytes = resolved.bytes;
1053
1151
  try {
@@ -1063,7 +1161,7 @@ async function forwardToNode(conn, m) {
1063
1161
  log(`[${cfg.name}] send_file to ${target} failed:`, String(err));
1064
1162
  }
1065
1163
  }
1066
- const body = buildEnvelope(m, resolved, fileWireId);
1164
+ const body = buildEnvelope(m, sendAudio ? resolved : void 0, fileWireId, transcription);
1067
1165
  try {
1068
1166
  const { deferred, queued } = await withScopeAsync(async (lt) => {
1069
1167
  const sent = await pkt.mutatingTx("::a2a_messaging::send_message", { contact: target, text: body }, lt);