@ouro.bot/cli 0.1.0-alpha.1101 → 0.1.0-alpha.1102
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 +6 -0
- package/deploy/unraid/Dockerfile +15 -1
- package/deploy/unraid/sanctuary.ouro/bundle-meta.json +1 -1
- package/deploy/unraid/sanctuary.xml +1 -1
- package/dist/heart/attachments/downloaded-store.js +112 -0
- package/dist/heart/attachments/sources/{telegram.js → downloaded.js} +29 -24
- package/dist/heart/attachments/sources/index.js +3 -2
- package/dist/heart/attachments/transcribe-audio.js +172 -0
- package/dist/heart/attachments/understand.js +121 -0
- package/dist/repertoire/tools-attachments.js +9 -55
- package/dist/senses/bluebubbles/client.js +2 -57
- package/dist/senses/bluebubbles/media.js +7 -140
- package/dist/senses/teams-attachments.js +68 -0
- package/dist/senses/teams.js +10 -1
- package/dist/senses/telegram-attachments.js +13 -71
- package/dist/senses/telegram.js +3 -2
- package/dist/senses/voice/whisper.js +3 -11
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/changelog.json
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
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.1102",
|
|
6
|
+
"changes": [
|
|
7
|
+
"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."
|
|
8
|
+
]
|
|
9
|
+
},
|
|
4
10
|
{
|
|
5
11
|
"version": "0.1.0-alpha.1101",
|
|
6
12
|
"changes": [
|
package/deploy/unraid/Dockerfile
CHANGED
|
@@ -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,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.
|
|
4
|
+
<Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.1102</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.
|
|
37
|
-
exports.
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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(
|
|
47
|
-
(0, runtime_1.emitNervesEvent)({ component: "engine", event: "engine.
|
|
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
|
|
50
|
-
sourceId: input.
|
|
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
|
-
|
|
58
|
-
source
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
|
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:
|
|
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
|
|
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
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
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",
|
|
@@ -1,37 +1,4 @@
|
|
|
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.BlueBubblesSendError = void 0;
|
|
37
4
|
exports.createBlueBubblesClient = createBlueBubblesClient;
|
|
@@ -40,8 +7,7 @@ const config_1 = require("../../heart/config");
|
|
|
40
7
|
const identity_1 = require("../../heart/identity");
|
|
41
8
|
const bluebubbles_health_diagnostics_1 = require("../../heart/daemon/bluebubbles-health-diagnostics");
|
|
42
9
|
const runtime_1 = require("../../nerves/runtime");
|
|
43
|
-
const
|
|
44
|
-
const minimax_vlm_1 = require("../../heart/providers/minimax-vlm");
|
|
10
|
+
const understand_1 = require("../../heart/attachments/understand");
|
|
45
11
|
const model_1 = require("./model");
|
|
46
12
|
const media_1 = require("./media");
|
|
47
13
|
const host_account_verifier_1 = require("./host-account-verifier");
|
|
@@ -701,28 +667,7 @@ function createBlueBubblesClient(config = (0, config_1.getBlueBubblesConfig)(),
|
|
|
701
667
|
const agentConfig = (0, identity_1.loadAgentConfig)();
|
|
702
668
|
const chatModel = agentConfig.humanFacing.model;
|
|
703
669
|
const chatProvider = agentConfig.humanFacing.provider;
|
|
704
|
-
const vlmDescribe =
|
|
705
|
-
if (chatProvider !== "minimax") {
|
|
706
|
-
throw new Error("VLM fallback requires a minimax credential for this agent — " +
|
|
707
|
-
"configure one or switch to a vision-capable chat model");
|
|
708
|
-
}
|
|
709
|
-
const { readProviderCredentialRecord } = await Promise.resolve().then(() => __importStar(require("../../heart/provider-credentials")));
|
|
710
|
-
const credential = await readProviderCredentialRecord((0, identity_1.getAgentName)(), "minimax");
|
|
711
|
-
const apiKey = credential.ok ? credential.record.credentials.apiKey : undefined;
|
|
712
|
-
if (!apiKey) {
|
|
713
|
-
throw new Error("VLM fallback: minimax API key not found in the agent vault — " +
|
|
714
|
-
"run `ouro auth --agent <agent> --provider minimax`");
|
|
715
|
-
}
|
|
716
|
-
return (0, minimax_vlm_1.minimaxVlmDescribe)({
|
|
717
|
-
apiKey: String(apiKey),
|
|
718
|
-
prompt: params.prompt,
|
|
719
|
-
imageDataUrl: params.imageDataUrl,
|
|
720
|
-
baseURL: minimax_1.MINIMAX_PROVIDER_BASE_URL,
|
|
721
|
-
attachmentGuid: params.attachmentGuid,
|
|
722
|
-
mimeType: params.mimeType,
|
|
723
|
-
chatModel: params.chatModel,
|
|
724
|
-
});
|
|
725
|
-
};
|
|
670
|
+
const vlmDescribe = (params) => (0, understand_1.describeImage)((0, identity_1.getAgentName)(), params);
|
|
726
671
|
// VLM prompt context wants the user's raw inbound text — NOT
|
|
727
672
|
// the agent-facing rendering, which now carries the attachment
|
|
728
673
|
// marker after the B2 fix. Pull it from the source payload.
|
|
@@ -35,28 +35,19 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.downloadBlueBubblesAttachment = exports.VLM_TEXT_WRAPPERS = void 0;
|
|
37
37
|
exports.hydrateBlueBubblesAttachments = hydrateBlueBubblesAttachments;
|
|
38
|
-
const node_child_process_1 = require("node:child_process");
|
|
39
38
|
const fs = __importStar(require("node:fs/promises"));
|
|
40
39
|
const os = __importStar(require("node:os"));
|
|
41
40
|
const path = __importStar(require("node:path"));
|
|
42
41
|
const runtime_1 = require("../../nerves/runtime");
|
|
43
42
|
const identity_1 = require("../../heart/identity");
|
|
43
|
+
const transcribe_audio_1 = require("../../heart/attachments/transcribe-audio");
|
|
44
|
+
const understand_1 = require("../../heart/attachments/understand");
|
|
44
45
|
const model_capabilities_1 = require("../../heart/model-capabilities");
|
|
45
46
|
const image_normalize_1 = require("../../heart/attachments/image-normalize");
|
|
46
47
|
const store_1 = require("../../heart/attachments/store");
|
|
47
48
|
const bluebubbles_1 = require("../../heart/attachments/sources/bluebubbles");
|
|
48
49
|
const attachment_download_1 = require("./attachment-download");
|
|
49
|
-
|
|
50
|
-
exports.VLM_TEXT_WRAPPERS = {
|
|
51
|
-
description: (desc) => `[image description: ${desc}]`,
|
|
52
|
-
failure: (reason) => `[image description failed: ${reason}]`,
|
|
53
|
-
};
|
|
54
|
-
// D3 prompt template. Included here (not templated out) because the contract
|
|
55
|
-
// is load-bearing — see planning doc section D3 and AX-4.
|
|
56
|
-
function buildVlmPrompt(userText) {
|
|
57
|
-
const body = userText ?? "";
|
|
58
|
-
return `User message: "${body}"\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
|
-
}
|
|
50
|
+
exports.VLM_TEXT_WRAPPERS = understand_1.IMAGE_DESCRIPTION_TEXT;
|
|
60
51
|
const AUDIO_EXTENSIONS = new Set([".mp3", ".wav", ".m4a", ".caf", ".ogg"]);
|
|
61
52
|
const AUDIO_EXTENSION_BY_CONTENT_TYPE = {
|
|
62
53
|
"audio/wav": ".wav",
|
|
@@ -78,19 +69,6 @@ const AUDIO_INPUT_FORMAT_BY_EXTENSION = {
|
|
|
78
69
|
".wav": "wav",
|
|
79
70
|
".mp3": "mp3",
|
|
80
71
|
};
|
|
81
|
-
const WHISPER_CPP_FORMULA = "whisper-cpp";
|
|
82
|
-
const WHISPER_CPP_MODEL_NAME = "ggml-base.en.bin";
|
|
83
|
-
const WHISPER_CPP_MODEL_URL = `https://huggingface.co/ggerganov/whisper.cpp/resolve/main/${WHISPER_CPP_MODEL_NAME}`;
|
|
84
|
-
// Lazy — getAgentToolsRoot() requires identity to be resolved, which isn't
|
|
85
|
-
// true at module-load time in most unit test contexts. Tests that only touch
|
|
86
|
-
// the image/VLM path shouldn't break because the audio path asked for a
|
|
87
|
-
// tools root they don't need.
|
|
88
|
-
function whisperCppPaths() {
|
|
89
|
-
const toolsDir = path.join((0, identity_1.getAgentToolsRoot)(), "whisper-cpp");
|
|
90
|
-
const modelsDir = path.join(toolsDir, "models");
|
|
91
|
-
const modelPath = path.join(modelsDir, WHISPER_CPP_MODEL_NAME);
|
|
92
|
-
return { toolsDir, modelsDir, modelPath };
|
|
93
|
-
}
|
|
94
72
|
function describeAttachment(attachment) {
|
|
95
73
|
return attachment.transferName?.trim() || attachment.guid?.trim() || "attachment";
|
|
96
74
|
}
|
|
@@ -117,124 +95,13 @@ function audioFormatForInput(contentType, attachment) {
|
|
|
117
95
|
const extension = path.extname(attachment?.transferName ?? "").toLowerCase();
|
|
118
96
|
return AUDIO_INPUT_FORMAT_BY_CONTENT_TYPE[contentType ?? ""] ?? AUDIO_INPUT_FORMAT_BY_EXTENSION[extension];
|
|
119
97
|
}
|
|
120
|
-
async function execFileText(file, args, timeout) {
|
|
121
|
-
return await new Promise((resolve, reject) => {
|
|
122
|
-
(0, node_child_process_1.execFile)(file, args, { timeout }, (error, stdout = "", stderr = "") => {
|
|
123
|
-
if (error) {
|
|
124
|
-
const detail = stderr.trim() || stdout.trim() || error.message;
|
|
125
|
-
reject(new Error(detail));
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
resolve(stdout);
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
async function pathExists(targetPath) {
|
|
133
|
-
try {
|
|
134
|
-
await fs.access(targetPath);
|
|
135
|
-
return true;
|
|
136
|
-
}
|
|
137
|
-
catch {
|
|
138
|
-
return false;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
async function resolveWhisperCppBinary(timeoutMs) {
|
|
142
|
-
try {
|
|
143
|
-
const existing = (await execFileText("which", ["whisper-cli"], timeoutMs)).trim();
|
|
144
|
-
if (existing) {
|
|
145
|
-
return existing;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
catch {
|
|
149
|
-
// fall through to managed install
|
|
150
|
-
}
|
|
151
|
-
let prefix = "";
|
|
152
|
-
try {
|
|
153
|
-
prefix = (await execFileText("brew", ["--prefix", WHISPER_CPP_FORMULA], timeoutMs)).trim();
|
|
154
|
-
if (prefix) {
|
|
155
|
-
const candidate = path.join(prefix, "bin", "whisper-cli");
|
|
156
|
-
if (await pathExists(candidate)) {
|
|
157
|
-
return candidate;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
catch {
|
|
162
|
-
// fall through to managed install
|
|
163
|
-
}
|
|
164
|
-
await execFileText("brew", ["install", WHISPER_CPP_FORMULA], Math.max(timeoutMs, 300_000));
|
|
165
|
-
prefix = (await execFileText("brew", ["--prefix", WHISPER_CPP_FORMULA], timeoutMs)).trim();
|
|
166
|
-
if (!prefix) {
|
|
167
|
-
throw new Error("whisper.cpp installed but brew did not return a usable prefix");
|
|
168
|
-
}
|
|
169
|
-
const candidate = path.join(prefix, "bin", "whisper-cli");
|
|
170
|
-
if (!await pathExists(candidate)) {
|
|
171
|
-
throw new Error("whisper.cpp installed but whisper-cli binary is missing");
|
|
172
|
-
}
|
|
173
|
-
return candidate;
|
|
174
|
-
}
|
|
175
|
-
async function ensureWhisperCppModel(timeoutMs, fetchImpl) {
|
|
176
|
-
const { modelsDir, modelPath } = whisperCppPaths();
|
|
177
|
-
try {
|
|
178
|
-
await fs.access(modelPath);
|
|
179
|
-
return modelPath;
|
|
180
|
-
}
|
|
181
|
-
catch {
|
|
182
|
-
await fs.mkdir(modelsDir, { recursive: true });
|
|
183
|
-
const response = await fetchImpl(WHISPER_CPP_MODEL_URL, {
|
|
184
|
-
method: "GET",
|
|
185
|
-
signal: AbortSignal.timeout(Math.max(timeoutMs, 300_000)),
|
|
186
|
-
});
|
|
187
|
-
if (!response.ok) {
|
|
188
|
-
throw new Error(`failed to download whisper.cpp model: HTTP ${response.status}`);
|
|
189
|
-
}
|
|
190
|
-
await fs.writeFile(modelPath, Buffer.from(await response.arrayBuffer()));
|
|
191
|
-
return modelPath;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
async function convertAudioForWhisperCpp(sourcePath, outputPath, timeoutMs) {
|
|
195
|
-
try {
|
|
196
|
-
await execFileText("ffmpeg", ["-y", "-i", sourcePath, "-ar", "16000", "-ac", "1", "-c:a", "pcm_s16le", outputPath], Math.max(timeoutMs, 120_000));
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
|
-
catch (ffmpegError) {
|
|
200
|
-
try {
|
|
201
|
-
await execFileText("afconvert", ["-f", "WAVE", "-d", "LEI16@16000", "-c", "1", sourcePath, outputPath], Math.max(timeoutMs, 120_000));
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
catch (afconvertError) {
|
|
205
|
-
const ffmpegReason = ffmpegError.message;
|
|
206
|
-
const afconvertReason = afconvertError.message;
|
|
207
|
-
throw new Error(`failed to prepare audio for whisper.cpp (ffmpeg: ${ffmpegReason}; afconvert: ${afconvertReason})`);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
98
|
async function transcribeAudioWithWhisperCpp(params, modelFetchImpl = fetch) {
|
|
212
99
|
const workDir = await fs.mkdtemp(path.join(os.tmpdir(), "ouro-bb-audio-"));
|
|
213
100
|
const filename = sanitizeFilename(describeAttachment(params.attachment));
|
|
214
|
-
const
|
|
215
|
-
const audioPath = path.join(workDir, `${path.parse(filename).name}${extension}`);
|
|
216
|
-
const wavPath = path.join(workDir, `${path.parse(audioPath).name}.wav`);
|
|
217
|
-
const outputBase = path.join(workDir, path.parse(audioPath).name);
|
|
101
|
+
const audioPath = path.join(workDir, `${path.parse(filename).name}${fileExtensionForAudio(params.attachment, params.contentType)}`);
|
|
218
102
|
try {
|
|
219
103
|
await fs.writeFile(audioPath, params.buffer);
|
|
220
|
-
|
|
221
|
-
const modelPath = await ensureWhisperCppModel(params.timeoutMs, modelFetchImpl);
|
|
222
|
-
await convertAudioForWhisperCpp(audioPath, wavPath, params.timeoutMs);
|
|
223
|
-
await execFileText(whisperCliPath, ["-m", modelPath, "-f", wavPath, "-oj", "-of", outputBase], Math.max(params.timeoutMs, 120_000));
|
|
224
|
-
const transcriptPath = `${outputBase}.json`;
|
|
225
|
-
const raw = await fs.readFile(transcriptPath, "utf8");
|
|
226
|
-
const parsed = JSON.parse(raw);
|
|
227
|
-
if (typeof parsed.text === "string") {
|
|
228
|
-
return parsed.text.trim();
|
|
229
|
-
}
|
|
230
|
-
if (Array.isArray(parsed.transcription)) {
|
|
231
|
-
return parsed.transcription
|
|
232
|
-
.map((entry) => (typeof entry?.text === "string" ? entry.text.trim() : ""))
|
|
233
|
-
.filter(Boolean)
|
|
234
|
-
.join(" ")
|
|
235
|
-
.trim();
|
|
236
|
-
}
|
|
237
|
-
return "";
|
|
104
|
+
return await (0, transcribe_audio_1.transcribeAudioFile)(audioPath, { timeoutMs: params.timeoutMs, fetchImpl: modelFetchImpl });
|
|
238
105
|
}
|
|
239
106
|
finally {
|
|
240
107
|
await fs.rm(workDir, { recursive: true, force: true }).catch(() => undefined);
|
|
@@ -311,7 +178,7 @@ async function hydrateBlueBubblesAttachments(attachments, config, channelConfig,
|
|
|
311
178
|
const normalizedMime = normalized.mimeType ?? persistedRecord.mimeType ?? "image/jpeg";
|
|
312
179
|
const dataUrl = `data:${normalizedMime};base64,${normalizedBuffer.toString("base64")}`;
|
|
313
180
|
const description = await deps.vlmDescribe({
|
|
314
|
-
prompt:
|
|
181
|
+
prompt: (0, understand_1.imageDescriptionPrompt)(deps.userText),
|
|
315
182
|
imageDataUrl: dataUrl,
|
|
316
183
|
attachmentGuid: attachment.guid,
|
|
317
184
|
mimeType: normalizedMime,
|
|
@@ -365,7 +232,7 @@ async function hydrateBlueBubblesAttachments(attachments, config, channelConfig,
|
|
|
365
232
|
notices.push(`attachment hydration failed for ${name}: empty audio transcript`);
|
|
366
233
|
continue;
|
|
367
234
|
}
|
|
368
|
-
transcriptAdditions.push(
|
|
235
|
+
transcriptAdditions.push(`${transcribe_audio_1.VOICE_NOTE_TRANSCRIPT_PREFIX}${transcript}`);
|
|
369
236
|
continue;
|
|
370
237
|
}
|
|
371
238
|
inputParts.push({
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MAX_TEAMS_ATTACHMENT_BYTES = void 0;
|
|
4
|
+
exports.ingestTeamsAttachments = ingestTeamsAttachments;
|
|
5
|
+
exports.teamsInboundText = teamsInboundText;
|
|
6
|
+
const node_crypto_1 = require("node:crypto");
|
|
7
|
+
const downloaded_store_1 = require("../heart/attachments/downloaded-store");
|
|
8
|
+
const understand_1 = require("../heart/attachments/understand");
|
|
9
|
+
const runtime_1 = require("../nerves/runtime");
|
|
10
|
+
// Files, pictures and voice clips someone sends the agent in Teams, kept and put into words like every other sense.
|
|
11
|
+
exports.MAX_TEAMS_ATTACHMENT_BYTES = 20_000_000;
|
|
12
|
+
const MAX_TEAMS_ATTACHMENTS_PER_MESSAGE = 8;
|
|
13
|
+
const FILE_DOWNLOAD_INFO = "application/vnd.microsoft.teams.file.download.info";
|
|
14
|
+
// The bot token only goes to Microsoft's own Bot Framework media hosts, never to an arbitrary contentUrl.
|
|
15
|
+
const BOT_MEDIA_HOST = /(^|\.)(botframework\.com|trafficmanager\.net|teams\.microsoft\.com|skype\.com)$/u;
|
|
16
|
+
function downloadFor(attachment) {
|
|
17
|
+
const contentType = attachment.contentType ?? "";
|
|
18
|
+
if (contentType === FILE_DOWNLOAD_INFO) {
|
|
19
|
+
const downloadUrl = attachment.content?.downloadUrl;
|
|
20
|
+
return typeof downloadUrl === "string" ? { url: downloadUrl, displayName: attachment.name || "file", needsBotToken: false } : null;
|
|
21
|
+
}
|
|
22
|
+
if (!/^(image|audio|video)\//u.test(contentType) || typeof attachment.contentUrl !== "string")
|
|
23
|
+
return null;
|
|
24
|
+
return { url: attachment.contentUrl, displayName: attachment.name || contentType.replace("/", "."), mimeType: contentType, needsBotToken: true };
|
|
25
|
+
}
|
|
26
|
+
async function ingestTeamsAttachments(input) {
|
|
27
|
+
const fetchImpl = input.fetch ?? globalThis.fetch;
|
|
28
|
+
const attachments = [];
|
|
29
|
+
const notices = [];
|
|
30
|
+
const downloads = (input.attachments ?? []).map(downloadFor).filter((download) => download !== null);
|
|
31
|
+
for (const download of downloads.slice(0, MAX_TEAMS_ATTACHMENTS_PER_MESSAGE)) {
|
|
32
|
+
try {
|
|
33
|
+
const url = new URL(download.url);
|
|
34
|
+
if (url.protocol !== "https:")
|
|
35
|
+
throw new Error("attachment URL is not https");
|
|
36
|
+
const headers = {};
|
|
37
|
+
if (download.needsBotToken && BOT_MEDIA_HOST.test(url.hostname)) {
|
|
38
|
+
const token = await input.getBotToken();
|
|
39
|
+
if (token)
|
|
40
|
+
headers.authorization = `Bearer ${token}`;
|
|
41
|
+
}
|
|
42
|
+
const response = await fetchImpl(url, { headers, signal: AbortSignal.timeout(30_000) });
|
|
43
|
+
if (!response.ok)
|
|
44
|
+
throw new Error(`download failed with HTTP ${response.status}`);
|
|
45
|
+
const buffer = await (0, downloaded_store_1.readBoundedResponse)(response, exports.MAX_TEAMS_ATTACHMENT_BYTES);
|
|
46
|
+
attachments.push(await (0, downloaded_store_1.storeDownloadedAttachment)({
|
|
47
|
+
agentName: input.agentName,
|
|
48
|
+
agentRoot: input.agentRoot,
|
|
49
|
+
source: "teams",
|
|
50
|
+
sourceId: (0, node_crypto_1.createHash)("sha256").update(download.url).digest("hex").slice(0, 32),
|
|
51
|
+
displayName: download.displayName,
|
|
52
|
+
mimeType: download.mimeType ?? response.headers.get("content-type") ?? undefined,
|
|
53
|
+
buffer,
|
|
54
|
+
}));
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
notices.push(`attachment unavailable: ${download.displayName} (${error instanceof Error ? error.message : String(error)})`);
|
|
58
|
+
(0, runtime_1.emitNervesEvent)({ level: "warn", component: "senses", event: "senses.teams_attachment_ingest_error", message: "Teams attachment ingestion failed", meta: { reason: error instanceof Error ? error.message : String(error) } });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return { attachments, notices };
|
|
62
|
+
}
|
|
63
|
+
/** The text the agent sees for a Teams message: what was typed, then its attachments in words. */
|
|
64
|
+
async function teamsInboundText(text, input) {
|
|
65
|
+
const ingested = await ingestTeamsAttachments(input);
|
|
66
|
+
const lines = await (0, understand_1.attachmentTurnLines)(ingested.attachments, { agentName: input.agentName, agentRoot: input.agentRoot, userText: text, timeoutMs: understand_1.ATTACHMENT_WORDS_TIMEOUT_MS });
|
|
67
|
+
return [text, ...lines, ...ingested.notices].filter(Boolean).join("\n");
|
|
68
|
+
}
|
package/dist/senses/teams.js
CHANGED
|
@@ -71,6 +71,7 @@ const runtime_1 = require("../nerves/runtime");
|
|
|
71
71
|
const proactive_content_guard_1 = require("./proactive-content-guard");
|
|
72
72
|
const turn_coordinator_1 = require("../heart/turn-coordinator");
|
|
73
73
|
const identity_1 = require("../heart/identity");
|
|
74
|
+
const teams_attachments_1 = require("./teams-attachments");
|
|
74
75
|
const mcp_manager_1 = require("../repertoire/mcp-manager");
|
|
75
76
|
const progress_story_1 = require("../heart/progress-story");
|
|
76
77
|
const tool_activity_callbacks_1 = require("../heart/tool-activity-callbacks");
|
|
@@ -1536,7 +1537,15 @@ function registerBotHandlers(app, label) {
|
|
|
1536
1537
|
botApi: app.id && api ? { id: app.id, conversations: api.conversations } : undefined,
|
|
1537
1538
|
teamsSendImage: (0, teams_image_1.createTeamsImageSender)((message) => ctx.send(message), activity.id, aiLabelEntities()),
|
|
1538
1539
|
};
|
|
1539
|
-
|
|
1540
|
+
const agentName = (0, identity_1.getAgentName)();
|
|
1541
|
+
const inboundText = await (0, teams_attachments_1.teamsInboundText)(text, {
|
|
1542
|
+
agentName,
|
|
1543
|
+
agentRoot: (0, identity_1.getAgentRoot)(agentName),
|
|
1544
|
+
attachments: activity.attachments,
|
|
1545
|
+
/* v8 ignore next -- live SDK token manager; ingestTeamsAttachments tests cover the token use @preserve */
|
|
1546
|
+
getBotToken: async () => (await app.tokenManager.getBotToken())?.toString(),
|
|
1547
|
+
});
|
|
1548
|
+
await handleTeamsMessage(inboundText, stream, convId, teamsContext, sendText);
|
|
1540
1549
|
}
|
|
1541
1550
|
catch (err) {
|
|
1542
1551
|
reportTeamsRequest("failed", convId, requestContext, { reason: "handler_failed" });
|
|
@@ -37,67 +37,16 @@ exports.MAX_TELEGRAM_ATTACHMENT_BYTES = void 0;
|
|
|
37
37
|
exports.ingestTelegramAttachments = ingestTelegramAttachments;
|
|
38
38
|
const fs = __importStar(require("node:fs/promises"));
|
|
39
39
|
const path = __importStar(require("node:path"));
|
|
40
|
-
const
|
|
40
|
+
const downloaded_store_1 = require("../heart/attachments/downloaded-store");
|
|
41
41
|
const store_1 = require("../heart/attachments/store");
|
|
42
42
|
const store_2 = require("../heart/attachments/store");
|
|
43
43
|
const originals_1 = require("../heart/attachments/originals");
|
|
44
44
|
const originals_2 = require("../heart/attachments/originals");
|
|
45
|
-
const
|
|
45
|
+
const downloaded_1 = require("../heart/attachments/sources/downloaded");
|
|
46
46
|
const runtime_1 = require("../nerves/runtime");
|
|
47
47
|
exports.MAX_TELEGRAM_ATTACHMENT_BYTES = 20_000_000;
|
|
48
48
|
const MAX_TELEGRAM_ATTACHMENTS_PER_MESSAGE = 8;
|
|
49
49
|
const SAFE_FILE_PATH = /^(?!\/)(?!.*(?:^|\/)\.\.(?:\/|$))[A-Za-z0-9._/-]{1,512}$/u;
|
|
50
|
-
async function readBounded(response, limit) {
|
|
51
|
-
const advertised = Number(response.headers.get("content-length"));
|
|
52
|
-
if (Number.isFinite(advertised) && advertised > limit)
|
|
53
|
-
throw new Error("advertised size exceeds limit");
|
|
54
|
-
if (!response.body)
|
|
55
|
-
throw new Error("empty response body");
|
|
56
|
-
const chunks = [];
|
|
57
|
-
let total = 0;
|
|
58
|
-
const reader = response.body.getReader();
|
|
59
|
-
try {
|
|
60
|
-
for (;;) {
|
|
61
|
-
const { done, value } = await reader.read();
|
|
62
|
-
if (done)
|
|
63
|
-
break;
|
|
64
|
-
total += value.byteLength;
|
|
65
|
-
if (total > limit)
|
|
66
|
-
throw new Error("download exceeds limit");
|
|
67
|
-
chunks.push(value);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
finally {
|
|
71
|
-
await reader.cancel().catch(() => undefined);
|
|
72
|
-
}
|
|
73
|
-
return Buffer.concat(chunks.map((chunk) => Buffer.from(chunk)), total);
|
|
74
|
-
}
|
|
75
|
-
async function atomicWrite(filePath, buffer) {
|
|
76
|
-
const directory = path.dirname(filePath);
|
|
77
|
-
await fs.mkdir(directory, { recursive: true, mode: 0o700 });
|
|
78
|
-
const temporary = `${filePath}.${(0, node_crypto_1.randomUUID)()}.tmp`;
|
|
79
|
-
let handle;
|
|
80
|
-
try {
|
|
81
|
-
handle = await fs.open(temporary, "wx", 0o600);
|
|
82
|
-
await handle.writeFile(buffer);
|
|
83
|
-
await handle.sync();
|
|
84
|
-
await handle.close();
|
|
85
|
-
handle = undefined;
|
|
86
|
-
await fs.rename(temporary, filePath);
|
|
87
|
-
const directoryHandle = await fs.open(directory, "r");
|
|
88
|
-
try {
|
|
89
|
-
await directoryHandle.sync();
|
|
90
|
-
}
|
|
91
|
-
finally {
|
|
92
|
-
await directoryHandle.close();
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
finally {
|
|
96
|
-
await handle?.close().catch(() => undefined);
|
|
97
|
-
await fs.unlink(temporary).catch((error) => { if (error.code !== "ENOENT")
|
|
98
|
-
throw error; });
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
50
|
async function ingestTelegramAttachments(input) {
|
|
102
51
|
const fetchImpl = input.fetch ?? globalThis.fetch;
|
|
103
52
|
const unique = [...new Map(input.attachments.map((attachment) => [attachment.fileId, attachment])).values()]
|
|
@@ -119,8 +68,8 @@ async function ingestTelegramAttachments(input) {
|
|
|
119
68
|
continue;
|
|
120
69
|
}
|
|
121
70
|
}
|
|
122
|
-
const recoverable = (0,
|
|
123
|
-
|
|
71
|
+
const recoverable = (0, downloaded_1.buildDownloadedAttachmentRecord)("telegram", {
|
|
72
|
+
sourceId: candidate.fileId,
|
|
124
73
|
displayName: candidate.displayName,
|
|
125
74
|
mimeType: candidate.mimeType,
|
|
126
75
|
byteCount: candidate.byteCount,
|
|
@@ -131,8 +80,8 @@ async function ingestTelegramAttachments(input) {
|
|
|
131
80
|
const stat = await fs.lstat(recoverablePath);
|
|
132
81
|
if (!stat.isFile() || stat.size > exports.MAX_TELEGRAM_ATTACHMENT_BYTES)
|
|
133
82
|
throw new Error("persisted attachment is invalid");
|
|
134
|
-
const recovered = (0, store_1.cacheRecentAttachment)(input.agentName, (0,
|
|
135
|
-
|
|
83
|
+
const recovered = (0, store_1.cacheRecentAttachment)(input.agentName, (0, downloaded_1.buildDownloadedAttachmentRecord)("telegram", {
|
|
84
|
+
sourceId: candidate.fileId,
|
|
136
85
|
displayName: candidate.displayName,
|
|
137
86
|
mimeType: candidate.mimeType,
|
|
138
87
|
byteCount: stat.size,
|
|
@@ -157,23 +106,16 @@ async function ingestTelegramAttachments(input) {
|
|
|
157
106
|
: (() => { throw new Error("attachment transport is unavailable"); })();
|
|
158
107
|
if (!response.ok)
|
|
159
108
|
throw new Error(`download failed with HTTP ${response.status}`);
|
|
160
|
-
const buffer = await
|
|
161
|
-
const
|
|
162
|
-
|
|
109
|
+
const buffer = await (0, downloaded_store_1.readBoundedResponse)(response, exports.MAX_TELEGRAM_ATTACHMENT_BYTES);
|
|
110
|
+
const record = await (0, downloaded_store_1.storeDownloadedAttachment)({
|
|
111
|
+
agentName: input.agentName,
|
|
112
|
+
agentRoot: input.agentRoot,
|
|
113
|
+
source: "telegram",
|
|
114
|
+
sourceId: candidate.fileId,
|
|
163
115
|
displayName: candidate.displayName,
|
|
164
116
|
mimeType: candidate.mimeType ?? response.headers.get("content-type") ?? undefined,
|
|
165
|
-
|
|
166
|
-
localPath: path.resolve(input.agentRoot, "state", "attachments", ".pending", candidate.fileId),
|
|
117
|
+
buffer,
|
|
167
118
|
});
|
|
168
|
-
const localPath = (0, originals_1.originalStoragePath)(input.agentRoot, provisional, provisional.mimeType);
|
|
169
|
-
await atomicWrite(localPath, buffer);
|
|
170
|
-
const record = (0, store_1.cacheRecentAttachment)(input.agentName, (0, telegram_1.buildTelegramAttachmentRecord)({
|
|
171
|
-
fileId: candidate.fileId,
|
|
172
|
-
displayName: candidate.displayName,
|
|
173
|
-
mimeType: provisional.mimeType,
|
|
174
|
-
byteCount: buffer.length,
|
|
175
|
-
localPath,
|
|
176
|
-
}), input.agentRoot);
|
|
177
119
|
attachments.push(record);
|
|
178
120
|
(0, runtime_1.emitNervesEvent)({ component: "senses", event: "senses.telegram_attachment_ingested", message: "Telegram attachment entered the shared attachment store", meta: { kind: record.kind, byteCount: buffer.length } });
|
|
179
121
|
}
|
package/dist/senses/telegram.js
CHANGED
|
@@ -98,8 +98,8 @@ const approval_store_1 = require("../heart/approval-store");
|
|
|
98
98
|
const tools_awaiting_1 = require("../repertoire/tools-awaiting");
|
|
99
99
|
const obligations_1 = require("../arc/obligations");
|
|
100
100
|
const orientation_frame_1 = require("../heart/orientation-frame");
|
|
101
|
-
const render_1 = require("../heart/attachments/render");
|
|
102
101
|
const telegram_attachments_1 = require("./telegram-attachments");
|
|
102
|
+
const understand_1 = require("../heart/attachments/understand");
|
|
103
103
|
const pending_1 = require("../mind/pending");
|
|
104
104
|
const relationship_authorization_1 = require("../repertoire/relationship-authorization");
|
|
105
105
|
const telegram_admission_1 = require("./telegram-admission");
|
|
@@ -1429,8 +1429,9 @@ function createTelegramSenseApp(options) {
|
|
|
1429
1429
|
attachments: message.attachments ?? [],
|
|
1430
1430
|
});
|
|
1431
1431
|
const attachmentIds = ingested.attachments.map((attachment) => attachment.id);
|
|
1432
|
+
const attachmentLines = await (0, understand_1.attachmentTurnLines)(ingested.attachments, { agentName: options.agentName, agentRoot, userText: message.text, timeoutMs: understand_1.ATTACHMENT_WORDS_TIMEOUT_MS });
|
|
1432
1433
|
return {
|
|
1433
|
-
text: (0, delegated_command_1.shieldDelegatedBanner)([message.text,
|
|
1434
|
+
text: (0, delegated_command_1.shieldDelegatedBanner)([message.text, ...attachmentLines, ...(message.attachmentNotices ?? []), ...ingested.notices].filter(Boolean).join("\n")),
|
|
1434
1435
|
attachmentIds,
|
|
1435
1436
|
};
|
|
1436
1437
|
};
|
|
@@ -41,24 +41,16 @@ const os = __importStar(require("os"));
|
|
|
41
41
|
const path = __importStar(require("path"));
|
|
42
42
|
const child_process_1 = require("child_process");
|
|
43
43
|
const runtime_1 = require("../../nerves/runtime");
|
|
44
|
+
const transcribe_audio_1 = require("../../heart/attachments/transcribe-audio");
|
|
44
45
|
const transcript_1 = require("./transcript");
|
|
45
46
|
function parseWhisperCppTranscriptJson(raw) {
|
|
46
|
-
let
|
|
47
|
+
let text;
|
|
47
48
|
try {
|
|
48
|
-
|
|
49
|
+
text = (0, transcribe_audio_1.whisperCppTranscriptText)(raw);
|
|
49
50
|
}
|
|
50
51
|
catch (error) {
|
|
51
52
|
throw new Error(`invalid whisper.cpp JSON: ${String(error)}`);
|
|
52
53
|
}
|
|
53
|
-
const text = typeof parsed.text === "string"
|
|
54
|
-
? parsed.text.trim()
|
|
55
|
-
: Array.isArray(parsed.transcription)
|
|
56
|
-
? parsed.transcription
|
|
57
|
-
.map((entry) => typeof entry.text === "string" ? entry.text.trim() : "")
|
|
58
|
-
.filter(Boolean)
|
|
59
|
-
.join(" ")
|
|
60
|
-
.trim()
|
|
61
|
-
: "";
|
|
62
54
|
if (!text) {
|
|
63
55
|
throw new Error("empty whisper.cpp transcript");
|
|
64
56
|
}
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ouro.bot/cli",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.1102",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@ouro.bot/cli",
|
|
9
|
-
"version": "0.1.0-alpha.
|
|
9
|
+
"version": "0.1.0-alpha.1102",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@anthropic-ai/sdk": "^0.78.0",
|
|
12
12
|
"@ouro.bot/friends": "0.1.0-alpha.18",
|