@ouro.bot/cli 0.1.0-alpha.1101 → 0.1.0-alpha.1103

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/changelog.json CHANGED
@@ -1,6 +1,18 @@
1
1
  {
2
2
  "_note": "This changelog is maintained as part of the PR/version-bump workflow. Agent-curated, not auto-generated. Agents read this file directly via read_file to understand what changed between versions.",
3
3
  "versions": [
4
+ {
5
+ "version": "0.1.0-alpha.1103",
6
+ "changes": [
7
+ "iMessage and Teams now tell the person when a turn fails, the way Telegram already did, instead of going silent or showing a raw error."
8
+ ]
9
+ },
10
+ {
11
+ "version": "0.1.0-alpha.1102",
12
+ "changes": [
13
+ "Every sense understands attachments the same way: voice notes are transcribed and images described in iMessage, Telegram and Teams alike, through one shared module. Teams now receives files, pictures and voice clips instead of dropping them. Image description uses the agent's MiniMax key whatever its chat provider. Storing a download and finishing a transcription are now logged. The Butler image carries whisper.cpp and ffmpeg."
14
+ ]
15
+ },
4
16
  {
5
17
  "version": "0.1.0-alpha.1101",
6
18
  "changes": [
@@ -1,3 +1,15 @@
1
+ # Speech-to-text for voice notes from every sense: whisper.cpp built for any x86-64/arm64 CPU, at a pinned, verified commit.
2
+ FROM node:22-bookworm-slim AS whisper
3
+ ARG WHISPER_CPP_VERSION=v1.8.7
4
+ ARG WHISPER_CPP_COMMIT=48f628a84833905ee4a0658ee6d4a5c915ce1997
5
+ RUN apt-get update \
6
+ && apt-get install -y --no-install-recommends ca-certificates git cmake make g++ \
7
+ && git clone --depth 1 --branch "$WHISPER_CPP_VERSION" https://github.com/ggml-org/whisper.cpp /src/whisper.cpp \
8
+ && test "$(git -C /src/whisper.cpp rev-parse HEAD)" = "$WHISPER_CPP_COMMIT" \
9
+ && cmake -S /src/whisper.cpp -B /src/build -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DGGML_NATIVE=OFF -DGGML_OPENMP=OFF -DWHISPER_BUILD_TESTS=OFF -DWHISPER_BUILD_SERVER=OFF -DWHISPER_SDL2=OFF \
10
+ && cmake --build /src/build --target whisper-cli -j"$(nproc)" \
11
+ && install -m 0755 /src/build/bin/whisper-cli /usr/local/bin/whisper-cli
12
+
1
13
  FROM node:22-bookworm-slim
2
14
 
3
15
  LABEL org.opencontainers.image.source="https://github.com/ourostack/ouroboros"
@@ -7,7 +19,7 @@ ARG TARGETARCH
7
19
  ARG SUPERCRONIC_AMD64_SHA256=5adff01c5a797663948e656d2b61d10932369ee437eb5cb54fa872b2960f222b
8
20
  ARG SUPERCRONIC_ARM64_SHA256=c0576a8eb092e3f79108ed0a2155a25c7766af78456e5a6070e54757ef513bfe
9
21
  RUN apt-get update \
10
- && apt-get install -y --no-install-recommends ca-certificates curl procps python3 make g++ git openssh-client sudo \
22
+ && apt-get install -y --no-install-recommends ca-certificates curl ffmpeg procps python3 make g++ git openssh-client sudo \
11
23
  && rm -rf /var/lib/apt/lists/* \
12
24
  && case "$TARGETARCH" in amd64) SUPERCRONIC_SHA256="$SUPERCRONIC_AMD64_SHA256" ;; arm64) SUPERCRONIC_SHA256="$SUPERCRONIC_ARM64_SHA256" ;; *) echo "unsupported architecture: $TARGETARCH" >&2; exit 1 ;; esac \
13
25
  && curl -fsSLo /usr/local/bin/supercronic "https://github.com/aptible/supercronic/releases/download/v0.2.46/supercronic-linux-${TARGETARCH}" \
@@ -18,6 +30,8 @@ RUN apt-get update \
18
30
  && groupadd --system --gid 10002 ouro-sync \
19
31
  && useradd --system --uid 10002 --gid 10002 --no-create-home --home-dir /nonexistent --shell /usr/sbin/nologin ouro-sync
20
32
 
33
+ COPY --from=whisper /usr/local/bin/whisper-cli /usr/local/bin/whisper-cli
34
+ RUN whisper-cli --help >/dev/null 2>&1 && ffmpeg -version >/dev/null
21
35
  WORKDIR /opt/ouro
22
36
  COPY package.json npm-shrinkwrap.json ./
23
37
  RUN npm ci --omit=dev --legacy-peer-deps --workspaces=false --no-audit --no-fund \
@@ -1,5 +1,5 @@
1
1
  {
2
- "runtimeVersion": "0.1.0-alpha.1101",
2
+ "runtimeVersion": "0.1.0-alpha.1103",
3
3
  "bundleSchemaVersion": 3,
4
4
  "lastUpdated": "2026-09-03T00:00:00.000Z"
5
5
  }
@@ -1,7 +1,7 @@
1
1
  <?xml version="1.0"?>
2
2
  <Container version="2">
3
3
  <Name>ouro-butler</Name>
4
- <Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.1101</Repository>
4
+ <Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.1103</Repository>
5
5
  <Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
6
6
  <Network>host</Network>
7
7
  <Shell>sh</Shell>
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.readBoundedResponse = readBoundedResponse;
37
+ exports.atomicWriteFile = atomicWriteFile;
38
+ exports.storeDownloadedAttachment = storeDownloadedAttachment;
39
+ const fs = __importStar(require("node:fs/promises"));
40
+ const path = __importStar(require("node:path"));
41
+ const node_crypto_1 = require("node:crypto");
42
+ const runtime_1 = require("../../nerves/runtime");
43
+ const store_1 = require("./store");
44
+ const originals_1 = require("./originals");
45
+ const downloaded_1 = require("./sources/downloaded");
46
+ // Download and keep an inbound file the same way for every sense: read no more than the limit, write it atomically, remember it.
47
+ async function readBoundedResponse(response, limit) {
48
+ const advertised = Number(response.headers.get("content-length"));
49
+ if (Number.isFinite(advertised) && advertised > limit)
50
+ throw new Error("advertised size exceeds limit");
51
+ if (!response.body)
52
+ throw new Error("empty response body");
53
+ const chunks = [];
54
+ let total = 0;
55
+ const reader = response.body.getReader();
56
+ try {
57
+ for (;;) {
58
+ const { done, value } = await reader.read();
59
+ if (done)
60
+ break;
61
+ total += value.byteLength;
62
+ if (total > limit)
63
+ throw new Error("download exceeds limit");
64
+ chunks.push(value);
65
+ }
66
+ }
67
+ finally {
68
+ await reader.cancel().catch(() => undefined);
69
+ }
70
+ return Buffer.concat(chunks.map((chunk) => Buffer.from(chunk)), total);
71
+ }
72
+ async function atomicWriteFile(filePath, buffer) {
73
+ const directory = path.dirname(filePath);
74
+ await fs.mkdir(directory, { recursive: true, mode: 0o700 });
75
+ const temporary = `${filePath}.${(0, node_crypto_1.randomUUID)()}.tmp`;
76
+ let handle;
77
+ try {
78
+ handle = await fs.open(temporary, "wx", 0o600);
79
+ await handle.writeFile(buffer);
80
+ await handle.sync();
81
+ await handle.close();
82
+ handle = undefined;
83
+ await fs.rename(temporary, filePath);
84
+ const directoryHandle = await fs.open(directory, "r");
85
+ try {
86
+ await directoryHandle.sync();
87
+ }
88
+ finally {
89
+ await directoryHandle.close();
90
+ }
91
+ }
92
+ finally {
93
+ await handle?.close().catch(() => undefined);
94
+ await fs.unlink(temporary).catch((error) => { if (error.code !== "ENOENT")
95
+ throw error; });
96
+ }
97
+ }
98
+ /** Keep a downloaded file as the original of an attachment record and remember it for the agent's attachment tools. */
99
+ async function storeDownloadedAttachment(input) {
100
+ const describe = (localPath) => ({
101
+ sourceId: input.sourceId,
102
+ displayName: input.displayName,
103
+ mimeType: input.mimeType,
104
+ byteCount: input.buffer.length,
105
+ localPath,
106
+ });
107
+ const provisional = (0, downloaded_1.buildDownloadedAttachmentRecord)(input.source, describe(path.resolve(input.agentRoot, "state", "attachments", ".pending", input.sourceId)));
108
+ const localPath = (0, originals_1.originalStoragePath)(input.agentRoot, provisional, provisional.mimeType);
109
+ await atomicWriteFile(localPath, input.buffer);
110
+ (0, runtime_1.emitNervesEvent)({ component: "engine", event: "engine.downloaded_attachment_stored", message: "downloaded attachment stored", meta: { source: input.source, byteCount: input.buffer.length } });
111
+ return (0, store_1.cacheRecentAttachment)(input.agentName, (0, downloaded_1.buildDownloadedAttachmentRecord)(input.source, describe(localPath)), input.agentRoot);
112
+ }
@@ -33,39 +33,44 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.telegramAttachmentSourceAdapter = void 0;
37
- exports.buildTelegramAttachmentRecord = buildTelegramAttachmentRecord;
36
+ exports.buildDownloadedAttachmentRecord = buildDownloadedAttachmentRecord;
37
+ exports.downloadedAttachmentSourceAdapter = downloadedAttachmentSourceAdapter;
38
38
  const path = __importStar(require("node:path"));
39
39
  const originals_1 = require("../originals");
40
40
  const types_1 = require("../types");
41
41
  const runtime_1 = require("../../../nerves/runtime");
42
- function buildTelegramAttachmentRecord(input, now = Date.now()) {
43
- if (!input.fileId.trim())
44
- throw new Error("Telegram attachment file id is required");
42
+ const SOURCE_LABEL = { telegram: "Telegram", teams: "Teams" };
43
+ function buildDownloadedAttachmentRecord(source, input, now = Date.now()) {
44
+ const label = SOURCE_LABEL[source];
45
+ if (!input.sourceId.trim())
46
+ throw new Error(`${label} attachment file id is required`);
45
47
  if (!path.isAbsolute(input.localPath))
46
- throw new Error("Telegram attachment local path must be absolute");
47
- (0, runtime_1.emitNervesEvent)({ component: "engine", event: "engine.telegram_attachment_record_built", message: "Telegram attachment record entered the shared attachment substrate", meta: {} });
48
+ throw new Error(`${label} attachment local path must be absolute`);
49
+ (0, runtime_1.emitNervesEvent)({ component: "engine", event: "engine.downloaded_attachment_record_built", message: `${label} attachment record entered the shared attachment substrate`, meta: { source } });
48
50
  return (0, types_1.createAttachmentRecord)({
49
- source: "telegram",
50
- sourceId: input.fileId,
51
+ source,
52
+ sourceId: input.sourceId,
51
53
  displayName: input.displayName,
52
54
  mimeType: input.mimeType,
53
55
  byteCount: input.byteCount,
54
56
  sourceData: { localPath: path.resolve(input.localPath) },
55
57
  }, now);
56
58
  }
57
- exports.telegramAttachmentSourceAdapter = {
58
- source: "telegram",
59
- async materializeOriginal({ attachment, agentRoot }) {
60
- if (attachment.source !== "telegram")
61
- throw new Error(`telegram adapter cannot materialize ${attachment.source} attachments`);
62
- const localPath = attachment.sourceData.localPath;
63
- if (typeof localPath !== "string" || !path.isAbsolute(localPath))
64
- throw new Error("Telegram attachment local path is invalid");
65
- const ownedRoot = path.resolve(agentRoot, "state", "attachments", "materialized", "telegram");
66
- if (!path.resolve(localPath).startsWith(`${ownedRoot}${path.sep}`))
67
- throw new Error("Telegram attachment local path is outside the owned attachment root");
68
- await (0, originals_1.ensureReadableFile)(localPath);
69
- return (0, originals_1.buildOriginalMaterializedAttachment)(attachment, localPath);
70
- },
71
- };
59
+ function downloadedAttachmentSourceAdapter(source) {
60
+ const label = SOURCE_LABEL[source];
61
+ return {
62
+ source,
63
+ async materializeOriginal({ attachment, agentRoot }) {
64
+ if (attachment.source !== source)
65
+ throw new Error(`${source} adapter cannot materialize ${attachment.source} attachments`);
66
+ const localPath = attachment.sourceData.localPath;
67
+ if (typeof localPath !== "string" || !path.isAbsolute(localPath))
68
+ throw new Error(`${label} attachment local path is invalid`);
69
+ const ownedRoot = path.resolve(agentRoot, "state", "attachments", "materialized", source);
70
+ if (!path.resolve(localPath).startsWith(`${ownedRoot}${path.sep}`))
71
+ throw new Error(`${label} attachment local path is outside the owned attachment root`);
72
+ await (0, originals_1.ensureReadableFile)(localPath);
73
+ return (0, originals_1.buildOriginalMaterializedAttachment)(attachment, localPath);
74
+ },
75
+ };
76
+ }
@@ -3,11 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getAttachmentSourceAdapter = getAttachmentSourceAdapter;
4
4
  const bluebubbles_1 = require("./bluebubbles");
5
5
  const cli_local_file_1 = require("./cli-local-file");
6
- const telegram_1 = require("./telegram");
6
+ const downloaded_1 = require("./downloaded");
7
7
  const ATTACHMENT_SOURCE_ADAPTERS = {
8
8
  bluebubbles: bluebubbles_1.blueBubblesAttachmentSourceAdapter,
9
9
  "cli-local-file": cli_local_file_1.cliLocalFileAttachmentSourceAdapter,
10
- telegram: telegram_1.telegramAttachmentSourceAdapter,
10
+ telegram: (0, downloaded_1.downloadedAttachmentSourceAdapter)("telegram"),
11
+ teams: (0, downloaded_1.downloadedAttachmentSourceAdapter)("teams"),
11
12
  };
12
13
  function getAttachmentSourceAdapter(source) {
13
14
  const adapter = ATTACHMENT_SOURCE_ADAPTERS[source];
@@ -0,0 +1,172 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.VOICE_NOTE_TRANSCRIPT_PREFIX = void 0;
37
+ exports.whisperCppTranscriptText = whisperCppTranscriptText;
38
+ exports.transcribeAudioFile = transcribeAudioFile;
39
+ exports.voiceNoteLine = voiceNoteLine;
40
+ const node_child_process_1 = require("node:child_process");
41
+ const fs = __importStar(require("node:fs/promises"));
42
+ const os = __importStar(require("node:os"));
43
+ const path = __importStar(require("node:path"));
44
+ const runtime_1 = require("../../nerves/runtime");
45
+ const identity_1 = require("../identity");
46
+ // One speech-to-text path for every sense: a voice note from iMessage, Telegram or Teams becomes text the same way.
47
+ const WHISPER_CPP_FORMULA = "whisper-cpp";
48
+ const WHISPER_CPP_MODEL_NAME = "ggml-base.en.bin";
49
+ const WHISPER_CPP_MODEL_URL = `https://huggingface.co/ggerganov/whisper.cpp/resolve/main/${WHISPER_CPP_MODEL_NAME}`;
50
+ exports.VOICE_NOTE_TRANSCRIPT_PREFIX = "voice note transcript: ";
51
+ /** The text of a whisper.cpp `-oj` transcript, or "" when it holds no speech. */
52
+ function whisperCppTranscriptText(raw) {
53
+ const parsed = JSON.parse(raw);
54
+ if (typeof parsed.text === "string")
55
+ return parsed.text.trim();
56
+ if (!Array.isArray(parsed.transcription))
57
+ return "";
58
+ return parsed.transcription
59
+ .map((entry) => (typeof entry?.text === "string" ? entry.text.trim() : ""))
60
+ .filter(Boolean)
61
+ .join(" ")
62
+ .trim();
63
+ }
64
+ async function execFileText(file, args, timeout) {
65
+ return await new Promise((resolve, reject) => {
66
+ (0, node_child_process_1.execFile)(file, args, { timeout }, (error, stdout = "", stderr = "") => {
67
+ if (error) {
68
+ reject(new Error(stderr.trim() || stdout.trim() || error.message));
69
+ return;
70
+ }
71
+ resolve(stdout);
72
+ });
73
+ });
74
+ }
75
+ async function pathExists(targetPath) {
76
+ try {
77
+ await fs.access(targetPath);
78
+ return true;
79
+ }
80
+ catch {
81
+ return false;
82
+ }
83
+ }
84
+ async function resolveWhisperCppBinary(timeoutMs) {
85
+ try {
86
+ const existing = (await execFileText("which", ["whisper-cli"], timeoutMs)).trim();
87
+ if (existing)
88
+ return existing;
89
+ }
90
+ catch {
91
+ // not on PATH; try Homebrew
92
+ }
93
+ let prefix = "";
94
+ try {
95
+ prefix = (await execFileText("brew", ["--prefix", WHISPER_CPP_FORMULA], timeoutMs)).trim();
96
+ if (prefix) {
97
+ const candidate = path.join(prefix, "bin", "whisper-cli");
98
+ if (await pathExists(candidate))
99
+ return candidate;
100
+ }
101
+ }
102
+ catch {
103
+ // not installed through Homebrew yet
104
+ }
105
+ try {
106
+ await execFileText("brew", ["install", WHISPER_CPP_FORMULA], Math.max(timeoutMs, 300_000));
107
+ }
108
+ catch (error) {
109
+ throw new Error(`whisper-cli is not on PATH and installing it with Homebrew failed (${error.message}); install whisper.cpp so whisper-cli is on PATH`);
110
+ }
111
+ prefix = (await execFileText("brew", ["--prefix", WHISPER_CPP_FORMULA], timeoutMs)).trim();
112
+ if (!prefix)
113
+ throw new Error("whisper.cpp installed but brew did not return a usable prefix");
114
+ const candidate = path.join(prefix, "bin", "whisper-cli");
115
+ if (!await pathExists(candidate))
116
+ throw new Error("whisper.cpp installed but whisper-cli binary is missing");
117
+ return candidate;
118
+ }
119
+ async function ensureWhisperCppModel(timeoutMs, fetchImpl) {
120
+ // Resolved per call: the tools root needs the agent identity, which is not known at module load.
121
+ const modelsDir = path.join((0, identity_1.getAgentToolsRoot)(), "whisper-cpp", "models");
122
+ const modelPath = path.join(modelsDir, WHISPER_CPP_MODEL_NAME);
123
+ if (await pathExists(modelPath))
124
+ return modelPath;
125
+ await fs.mkdir(modelsDir, { recursive: true });
126
+ const response = await fetchImpl(WHISPER_CPP_MODEL_URL, {
127
+ method: "GET",
128
+ signal: AbortSignal.timeout(Math.max(timeoutMs, 300_000)),
129
+ });
130
+ if (!response.ok)
131
+ throw new Error(`failed to download whisper.cpp model: HTTP ${response.status}`);
132
+ await fs.writeFile(modelPath, Buffer.from(await response.arrayBuffer()));
133
+ return modelPath;
134
+ }
135
+ async function convertToWhisperWav(sourcePath, outputPath, timeoutMs) {
136
+ try {
137
+ await execFileText("ffmpeg", ["-y", "-i", sourcePath, "-ar", "16000", "-ac", "1", "-c:a", "pcm_s16le", outputPath], Math.max(timeoutMs, 120_000));
138
+ }
139
+ catch (ffmpegError) {
140
+ try {
141
+ await execFileText("afconvert", ["-f", "WAVE", "-d", "LEI16@16000", "-c", "1", sourcePath, outputPath], Math.max(timeoutMs, 120_000));
142
+ }
143
+ catch (afconvertError) {
144
+ throw new Error(`failed to prepare audio for whisper.cpp (ffmpeg: ${ffmpegError.message}; afconvert: ${afconvertError.message})`);
145
+ }
146
+ }
147
+ }
148
+ /** Transcribe one audio file of any format ffmpeg reads. Returns "" when the audio holds no speech. */
149
+ async function transcribeAudioFile(audioPath, options) {
150
+ const workDir = await fs.mkdtemp(path.join(os.tmpdir(), "ouro-audio-"));
151
+ const wavPath = path.join(workDir, "audio.wav");
152
+ const outputBase = path.join(workDir, "audio");
153
+ try {
154
+ const whisperCliPath = await resolveWhisperCppBinary(options.timeoutMs);
155
+ const modelPath = await ensureWhisperCppModel(options.timeoutMs, options.fetchImpl ?? fetch);
156
+ await convertToWhisperWav(audioPath, wavPath, options.timeoutMs);
157
+ await execFileText(whisperCliPath, ["-m", modelPath, "-f", wavPath, "-oj", "-of", outputBase], Math.max(options.timeoutMs, 120_000));
158
+ const transcript = whisperCppTranscriptText(await fs.readFile(`${outputBase}.json`, "utf8"));
159
+ (0, runtime_1.emitNervesEvent)({ component: "senses", event: "senses.audio_transcribed", message: "audio transcribed with whisper.cpp", meta: { characters: transcript.length } });
160
+ return transcript;
161
+ }
162
+ finally {
163
+ await fs.rm(workDir, { recursive: true, force: true }).catch(() => undefined);
164
+ }
165
+ }
166
+ /** The line a sense adds to the turn for one voice note, or the notice when it held no speech. */
167
+ async function voiceNoteLine(name, audioPath, options) {
168
+ const transcript = (await transcribeAudioFile(audioPath, options)).trim();
169
+ return transcript
170
+ ? { line: `${exports.VOICE_NOTE_TRANSCRIPT_PREFIX}${transcript}` }
171
+ : { notice: `attachment hydration failed for ${name}: empty audio transcript` };
172
+ }
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.IMAGE_DESCRIPTION_TEXT = exports.ATTACHMENT_WORDS_TIMEOUT_MS = void 0;
37
+ exports.imageDescriptionPrompt = imageDescriptionPrompt;
38
+ exports.imageFileDataUrl = imageFileDataUrl;
39
+ exports.describeImage = describeImage;
40
+ exports.attachmentWords = attachmentWords;
41
+ exports.attachmentTurnLines = attachmentTurnLines;
42
+ const fs = __importStar(require("node:fs/promises"));
43
+ const runtime_1 = require("../../nerves/runtime");
44
+ const provider_credentials_1 = require("../provider-credentials");
45
+ const minimax_1 = require("../providers/minimax");
46
+ const minimax_vlm_1 = require("../providers/minimax-vlm");
47
+ const materialize_1 = require("./materialize");
48
+ const render_1 = require("./render");
49
+ const transcribe_audio_1 = require("./transcribe-audio");
50
+ // What an attachment says, in words, the same way for every sense: an image is described, a voice note is transcribed.
51
+ /** How long one inbound attachment may take to describe or transcribe. */
52
+ exports.ATTACHMENT_WORDS_TIMEOUT_MS = 120_000;
53
+ exports.IMAGE_DESCRIPTION_TEXT = {
54
+ description: (desc) => `[image description: ${desc}]`,
55
+ failure: (reason) => `[image description failed: ${reason}]`,
56
+ };
57
+ function imageDescriptionPrompt(userText) {
58
+ return `User message: "${userText ?? ""}"\n\nDescribe this image in detail, focusing on anything relevant to what the user said above.\nInclude any text visible in the image verbatim.`;
59
+ }
60
+ async function imageFileDataUrl(filePath, mimeType) {
61
+ const normalizedMime = mimeType?.trim().toLowerCase() || "image/jpeg";
62
+ return `data:${normalizedMime};base64,${(await fs.readFile(filePath)).toString("base64")}`;
63
+ }
64
+ /** Describe an image with the agent's MiniMax vision model. Throws a reason that names the fix. */
65
+ async function describeImage(agentName, params) {
66
+ const credential = await (0, provider_credentials_1.readProviderCredentialRecord)(agentName, "minimax");
67
+ const apiKey = credential.ok ? credential.record.credentials.apiKey : undefined;
68
+ if (!apiKey) {
69
+ throw new Error("image understanding needs a MiniMax API key in the agent vault — run `ouro auth --agent <agent> --provider minimax`");
70
+ }
71
+ return (0, minimax_vlm_1.minimaxVlmDescribe)({ apiKey: String(apiKey), baseURL: minimax_1.MINIMAX_PROVIDER_BASE_URL, ...params });
72
+ }
73
+ /** Turn stored attachments into words for a text-only turn. Other kinds stay listed in the attachment block for the tools. */
74
+ async function attachmentWords(records, context) {
75
+ const lines = [];
76
+ const notices = [];
77
+ for (const record of records) {
78
+ try {
79
+ if (record.kind === "image") {
80
+ const image = await (0, materialize_1.materializeAttachment)(context.agentName, record.id, { agentRoot: context.agentRoot, variant: "vision_safe" });
81
+ try {
82
+ const description = await describeImage(context.agentName, {
83
+ prompt: imageDescriptionPrompt(context.userText),
84
+ imageDataUrl: await imageFileDataUrl(image.path, image.mimeType),
85
+ attachmentGuid: record.id,
86
+ mimeType: image.mimeType,
87
+ });
88
+ lines.push(exports.IMAGE_DESCRIPTION_TEXT.description(description));
89
+ }
90
+ catch (error) {
91
+ lines.push(exports.IMAGE_DESCRIPTION_TEXT.failure(error instanceof Error ? error.message : String(error)));
92
+ }
93
+ }
94
+ else if (record.kind === "audio") {
95
+ const audio = await (0, materialize_1.materializeAttachment)(context.agentName, record.id, { agentRoot: context.agentRoot });
96
+ const result = await (0, transcribe_audio_1.voiceNoteLine)(record.displayName, audio.path, { timeoutMs: context.timeoutMs });
97
+ if (result.line)
98
+ lines.push(result.line);
99
+ if (result.notice)
100
+ notices.push(result.notice);
101
+ }
102
+ }
103
+ catch (error) {
104
+ notices.push(`attachment hydration failed for ${record.displayName}: ${error instanceof Error ? error.message : String(error)}`);
105
+ }
106
+ }
107
+ (0, runtime_1.emitNervesEvent)({
108
+ component: "senses",
109
+ event: "senses.attachment_words",
110
+ message: "attachments turned into words for the turn",
111
+ meta: { count: records.length, lines: lines.length, notices: notices.length },
112
+ });
113
+ return { lines, notices };
114
+ }
115
+ /** Everything a text-only turn shows about its attachments: the list for the tools, then what each one says. */
116
+ async function attachmentTurnLines(records, context) {
117
+ if (records.length === 0)
118
+ return [];
119
+ const words = await attachmentWords(records, context);
120
+ return [(0, render_1.renderAttachmentBlock)([...records]), ...words.lines, ...words.notices].filter(Boolean);
121
+ }
@@ -1,44 +1,8 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  Object.defineProperty(exports, "__esModule", { value: true });
36
3
  exports.attachmentToolDefinitions = void 0;
37
- const fs = __importStar(require("node:fs/promises"));
38
4
  const identity_1 = require("../heart/identity");
39
- const provider_credentials_1 = require("../heart/provider-credentials");
40
- const minimax_1 = require("../heart/providers/minimax");
41
- const minimax_vlm_1 = require("../heart/providers/minimax-vlm");
5
+ const understand_1 = require("../heart/attachments/understand");
42
6
  const store_1 = require("../heart/attachments/store");
43
7
  const materialize_1 = require("../heart/attachments/materialize");
44
8
  const runtime_1 = require("../nerves/runtime");
@@ -151,12 +115,6 @@ function normalizeMaterializeError(tool, attachmentId, reason) {
151
115
  ],
152
116
  });
153
117
  }
154
- async function buildImageDataUrl(filePath, mimeType) {
155
- const buffer = await fs.readFile(filePath);
156
- const encoded = buffer.toString("base64");
157
- const normalizedMime = mimeType?.trim().toLowerCase() || "image/jpeg";
158
- return `data:${normalizedMime};base64,${encoded}`;
159
- }
160
118
  exports.attachmentToolDefinitions = [
161
119
  {
162
120
  tool: {
@@ -279,10 +237,14 @@ exports.attachmentToolDefinitions = [
279
237
  const agentName = (0, identity_1.getAgentName)();
280
238
  try {
281
239
  const materialized = await (0, materialize_1.materializeAttachment)(agentName, attachmentId, { variant: "vision_safe" });
282
- const imageDataUrl = await buildImageDataUrl(materialized.path, materialized.mimeType);
283
- const credential = await (0, provider_credentials_1.readProviderCredentialRecord)(agentName, "minimax");
284
- const apiKey = credential.ok ? credential.record.credentials.apiKey : undefined;
285
- if (!apiKey) {
240
+ const imageDataUrl = await (0, understand_1.imageFileDataUrl)(materialized.path, materialized.mimeType);
241
+ let description;
242
+ try {
243
+ description = await (0, understand_1.describeImage)(agentName, { prompt, imageDataUrl, attachmentGuid: attachmentId, mimeType: materialized.mimeType });
244
+ }
245
+ catch (error) {
246
+ if (!/MiniMax API key/.test(normalizeThrownReason(error)))
247
+ throw error;
286
248
  return (0, tool_results_1.frictionToolResult)("describe_image", {
287
249
  kind: "external_blocker",
288
250
  recoverability: "blocked",
@@ -296,14 +258,6 @@ exports.attachmentToolDefinitions = [
296
258
  ],
297
259
  });
298
260
  }
299
- const description = await (0, minimax_vlm_1.minimaxVlmDescribe)({
300
- apiKey: String(apiKey),
301
- prompt,
302
- imageDataUrl,
303
- baseURL: minimax_1.MINIMAX_PROVIDER_BASE_URL,
304
- attachmentGuid: attachmentId,
305
- mimeType: materialized.mimeType,
306
- });
307
261
  (0, runtime_1.emitNervesEvent)({
308
262
  component: "tools",
309
263
  event: "tool.describe_image_success",