@ouro.bot/cli 0.1.0-alpha.4 → 0.1.0-alpha.41
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/AdoptionSpecialist.ouro/agent.json +70 -9
- package/AdoptionSpecialist.ouro/psyche/SOUL.md +5 -2
- package/AdoptionSpecialist.ouro/psyche/identities/monty.md +2 -2
- package/README.md +117 -188
- package/assets/ouroboros.png +0 -0
- package/changelog.json +170 -0
- package/dist/heart/config.js +81 -8
- package/dist/heart/core.js +78 -45
- package/dist/heart/daemon/agent-discovery.js +81 -0
- package/dist/heart/daemon/daemon-cli.js +987 -77
- package/dist/heart/daemon/daemon-entry.js +14 -5
- package/dist/heart/daemon/daemon-runtime-sync.js +90 -0
- package/dist/heart/daemon/daemon.js +177 -9
- package/dist/heart/daemon/hatch-animation.js +35 -0
- package/dist/heart/daemon/hatch-flow.js +4 -20
- package/dist/heart/daemon/hooks/bundle-meta.js +92 -0
- package/dist/heart/daemon/launchd.js +134 -0
- package/dist/heart/daemon/message-router.js +15 -6
- package/dist/heart/daemon/ouro-bot-entry.js +0 -0
- package/dist/heart/daemon/ouro-bot-global-installer.js +128 -0
- package/dist/heart/daemon/ouro-entry.js +0 -0
- package/dist/heart/daemon/ouro-path-installer.js +178 -0
- package/dist/heart/daemon/ouro-uti.js +11 -2
- package/dist/heart/daemon/process-manager.js +1 -1
- package/dist/heart/daemon/run-hooks.js +37 -0
- package/dist/heart/daemon/runtime-metadata.js +118 -0
- package/dist/heart/daemon/sense-manager.js +266 -0
- package/dist/heart/daemon/specialist-orchestrator.js +129 -0
- package/dist/heart/daemon/specialist-prompt.js +99 -0
- package/dist/heart/daemon/specialist-tools.js +283 -0
- package/dist/heart/daemon/staged-restart.js +114 -0
- package/dist/heart/daemon/subagent-installer.js +10 -1
- package/dist/heart/daemon/update-checker.js +111 -0
- package/dist/heart/daemon/update-hooks.js +138 -0
- package/dist/heart/daemon/wrapper-publish-guard.js +86 -0
- package/dist/heart/identity.js +96 -4
- package/dist/heart/kicks.js +1 -19
- package/dist/heart/providers/anthropic.js +16 -2
- package/dist/heart/sense-truth.js +61 -0
- package/dist/heart/streaming.js +96 -21
- package/dist/mind/bundle-manifest.js +70 -0
- package/dist/mind/context.js +7 -7
- package/dist/mind/first-impressions.js +2 -1
- package/dist/mind/friends/channel.js +43 -0
- package/dist/mind/friends/store-file.js +19 -0
- package/dist/mind/friends/types.js +9 -1
- package/dist/mind/memory.js +10 -3
- package/dist/mind/pending.js +10 -2
- package/dist/mind/phrases.js +1 -0
- package/dist/mind/prompt.js +222 -7
- package/dist/mind/token-estimate.js +8 -12
- package/dist/nerves/cli-logging.js +15 -2
- package/dist/repertoire/ado-client.js +4 -2
- package/dist/repertoire/coding/feedback.js +134 -0
- package/dist/repertoire/coding/index.js +4 -1
- package/dist/repertoire/coding/manager.js +62 -4
- package/dist/repertoire/coding/spawner.js +3 -3
- package/dist/repertoire/coding/tools.js +41 -2
- package/dist/repertoire/data/ado-endpoints.json +188 -0
- package/dist/repertoire/tasks/index.js +2 -9
- package/dist/repertoire/tasks/transitions.js +1 -2
- package/dist/repertoire/tools-base.js +202 -219
- package/dist/repertoire/tools-bluebubbles.js +93 -0
- package/dist/repertoire/tools-teams.js +58 -25
- package/dist/repertoire/tools.js +55 -35
- package/dist/senses/bluebubbles-client.js +434 -0
- package/dist/senses/bluebubbles-entry.js +11 -0
- package/dist/senses/bluebubbles-media.js +338 -0
- package/dist/senses/bluebubbles-model.js +261 -0
- package/dist/senses/bluebubbles-mutation-log.js +74 -0
- package/dist/senses/bluebubbles-session-cleanup.js +72 -0
- package/dist/senses/bluebubbles.js +832 -0
- package/dist/senses/cli.js +327 -138
- package/dist/senses/debug-activity.js +127 -0
- package/dist/senses/inner-dialog.js +103 -55
- package/dist/senses/pipeline.js +124 -0
- package/dist/senses/teams.js +427 -112
- package/dist/senses/trust-gate.js +112 -2
- package/package.json +14 -3
- package/subagents/README.md +40 -53
- package/subagents/work-doer.md +26 -24
- package/subagents/work-merger.md +24 -30
- package/subagents/work-planner.md +34 -25
- package/dist/inner-worker-entry.js +0 -4
|
@@ -0,0 +1,338 @@
|
|
|
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.hydrateBlueBubblesAttachments = hydrateBlueBubblesAttachments;
|
|
37
|
+
const node_child_process_1 = require("node:child_process");
|
|
38
|
+
const fs = __importStar(require("node:fs/promises"));
|
|
39
|
+
const os = __importStar(require("node:os"));
|
|
40
|
+
const path = __importStar(require("node:path"));
|
|
41
|
+
const runtime_1 = require("../nerves/runtime");
|
|
42
|
+
const MAX_ATTACHMENT_BYTES = 8 * 1024 * 1024;
|
|
43
|
+
const AUDIO_EXTENSIONS = new Set([".mp3", ".wav", ".m4a", ".caf", ".ogg"]);
|
|
44
|
+
const IMAGE_EXTENSIONS = new Set([".jpg", ".jpeg", ".png", ".gif", ".webp", ".heic", ".heif"]);
|
|
45
|
+
const AUDIO_EXTENSION_BY_CONTENT_TYPE = {
|
|
46
|
+
"audio/wav": ".wav",
|
|
47
|
+
"audio/x-wav": ".wav",
|
|
48
|
+
"audio/mp3": ".mp3",
|
|
49
|
+
"audio/mpeg": ".mp3",
|
|
50
|
+
"audio/x-caf": ".caf",
|
|
51
|
+
"audio/caf": ".caf",
|
|
52
|
+
"audio/mp4": ".m4a",
|
|
53
|
+
"audio/x-m4a": ".m4a",
|
|
54
|
+
};
|
|
55
|
+
const AUDIO_INPUT_FORMAT_BY_CONTENT_TYPE = {
|
|
56
|
+
"audio/wav": "wav",
|
|
57
|
+
"audio/x-wav": "wav",
|
|
58
|
+
"audio/mp3": "mp3",
|
|
59
|
+
"audio/mpeg": "mp3",
|
|
60
|
+
};
|
|
61
|
+
const AUDIO_INPUT_FORMAT_BY_EXTENSION = {
|
|
62
|
+
".wav": "wav",
|
|
63
|
+
".mp3": "mp3",
|
|
64
|
+
};
|
|
65
|
+
const WHISPER_CPP_FORMULA = "whisper-cpp";
|
|
66
|
+
const WHISPER_CPP_MODEL_NAME = "ggml-base.en.bin";
|
|
67
|
+
const WHISPER_CPP_MODEL_URL = `https://huggingface.co/ggerganov/whisper.cpp/resolve/main/${WHISPER_CPP_MODEL_NAME}`;
|
|
68
|
+
const WHISPER_CPP_TOOLS_DIR = path.join(os.homedir(), ".agentstate", "tools", "whisper-cpp");
|
|
69
|
+
const WHISPER_CPP_MODELS_DIR = path.join(WHISPER_CPP_TOOLS_DIR, "models");
|
|
70
|
+
const WHISPER_CPP_MODEL_PATH = path.join(WHISPER_CPP_MODELS_DIR, WHISPER_CPP_MODEL_NAME);
|
|
71
|
+
function buildBlueBubblesApiUrl(baseUrl, endpoint, password) {
|
|
72
|
+
const root = baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`;
|
|
73
|
+
const url = new URL(endpoint.replace(/^\//, ""), root);
|
|
74
|
+
url.searchParams.set("password", password);
|
|
75
|
+
return url.toString();
|
|
76
|
+
}
|
|
77
|
+
function describeAttachment(attachment) {
|
|
78
|
+
return attachment.transferName?.trim() || attachment.guid?.trim() || "attachment";
|
|
79
|
+
}
|
|
80
|
+
function inferContentType(attachment, responseType) {
|
|
81
|
+
const normalizedResponseType = responseType?.split(";")[0]?.trim().toLowerCase();
|
|
82
|
+
if (normalizedResponseType) {
|
|
83
|
+
return normalizedResponseType;
|
|
84
|
+
}
|
|
85
|
+
return attachment.mimeType?.trim().toLowerCase() || undefined;
|
|
86
|
+
}
|
|
87
|
+
function isImageAttachment(attachment, contentType) {
|
|
88
|
+
if (contentType?.startsWith("image/"))
|
|
89
|
+
return true;
|
|
90
|
+
const extension = path.extname(attachment.transferName ?? "").toLowerCase();
|
|
91
|
+
return IMAGE_EXTENSIONS.has(extension);
|
|
92
|
+
}
|
|
93
|
+
function isAudioAttachment(attachment, contentType) {
|
|
94
|
+
if (contentType?.startsWith("audio/"))
|
|
95
|
+
return true;
|
|
96
|
+
const extension = path.extname(attachment.transferName ?? "").toLowerCase();
|
|
97
|
+
return AUDIO_EXTENSIONS.has(extension);
|
|
98
|
+
}
|
|
99
|
+
function sanitizeFilename(name) {
|
|
100
|
+
return path.basename(name).replace(/[\r\n"\\]/g, "_");
|
|
101
|
+
}
|
|
102
|
+
function fileExtensionForAudio(attachment, contentType) {
|
|
103
|
+
const transferExt = path.extname(attachment.transferName ?? "").toLowerCase();
|
|
104
|
+
if (transferExt) {
|
|
105
|
+
return transferExt;
|
|
106
|
+
}
|
|
107
|
+
if (contentType && AUDIO_EXTENSION_BY_CONTENT_TYPE[contentType]) {
|
|
108
|
+
return AUDIO_EXTENSION_BY_CONTENT_TYPE[contentType];
|
|
109
|
+
}
|
|
110
|
+
return ".audio";
|
|
111
|
+
}
|
|
112
|
+
function audioFormatForInput(contentType, attachment) {
|
|
113
|
+
const extension = path.extname(attachment?.transferName ?? "").toLowerCase();
|
|
114
|
+
return AUDIO_INPUT_FORMAT_BY_CONTENT_TYPE[contentType ?? ""] ?? AUDIO_INPUT_FORMAT_BY_EXTENSION[extension];
|
|
115
|
+
}
|
|
116
|
+
async function execFileText(file, args, timeout) {
|
|
117
|
+
return await new Promise((resolve, reject) => {
|
|
118
|
+
(0, node_child_process_1.execFile)(file, args, { timeout }, (error, stdout = "", stderr = "") => {
|
|
119
|
+
if (error) {
|
|
120
|
+
const detail = stderr.trim() || stdout.trim() || error.message;
|
|
121
|
+
reject(new Error(detail));
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
resolve(stdout);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
async function pathExists(targetPath) {
|
|
129
|
+
try {
|
|
130
|
+
await fs.access(targetPath);
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
async function resolveWhisperCppBinary(timeoutMs) {
|
|
138
|
+
try {
|
|
139
|
+
const existing = (await execFileText("which", ["whisper-cli"], timeoutMs)).trim();
|
|
140
|
+
if (existing) {
|
|
141
|
+
return existing;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
// fall through to managed install
|
|
146
|
+
}
|
|
147
|
+
let prefix = "";
|
|
148
|
+
try {
|
|
149
|
+
prefix = (await execFileText("brew", ["--prefix", WHISPER_CPP_FORMULA], timeoutMs)).trim();
|
|
150
|
+
if (prefix) {
|
|
151
|
+
const candidate = path.join(prefix, "bin", "whisper-cli");
|
|
152
|
+
if (await pathExists(candidate)) {
|
|
153
|
+
return candidate;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
// fall through to managed install
|
|
159
|
+
}
|
|
160
|
+
await execFileText("brew", ["install", WHISPER_CPP_FORMULA], Math.max(timeoutMs, 300_000));
|
|
161
|
+
prefix = (await execFileText("brew", ["--prefix", WHISPER_CPP_FORMULA], timeoutMs)).trim();
|
|
162
|
+
if (!prefix) {
|
|
163
|
+
throw new Error("whisper.cpp installed but brew did not return a usable prefix");
|
|
164
|
+
}
|
|
165
|
+
const candidate = path.join(prefix, "bin", "whisper-cli");
|
|
166
|
+
if (!await pathExists(candidate)) {
|
|
167
|
+
throw new Error("whisper.cpp installed but whisper-cli binary is missing");
|
|
168
|
+
}
|
|
169
|
+
return candidate;
|
|
170
|
+
}
|
|
171
|
+
async function ensureWhisperCppModel(timeoutMs, fetchImpl) {
|
|
172
|
+
try {
|
|
173
|
+
await fs.access(WHISPER_CPP_MODEL_PATH);
|
|
174
|
+
return WHISPER_CPP_MODEL_PATH;
|
|
175
|
+
}
|
|
176
|
+
catch {
|
|
177
|
+
await fs.mkdir(WHISPER_CPP_MODELS_DIR, { recursive: true });
|
|
178
|
+
const response = await fetchImpl(WHISPER_CPP_MODEL_URL, {
|
|
179
|
+
method: "GET",
|
|
180
|
+
signal: AbortSignal.timeout(Math.max(timeoutMs, 300_000)),
|
|
181
|
+
});
|
|
182
|
+
if (!response.ok) {
|
|
183
|
+
throw new Error(`failed to download whisper.cpp model: HTTP ${response.status}`);
|
|
184
|
+
}
|
|
185
|
+
await fs.writeFile(WHISPER_CPP_MODEL_PATH, Buffer.from(await response.arrayBuffer()));
|
|
186
|
+
return WHISPER_CPP_MODEL_PATH;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
async function convertAudioForWhisperCpp(sourcePath, outputPath, timeoutMs) {
|
|
190
|
+
try {
|
|
191
|
+
await execFileText("ffmpeg", ["-y", "-i", sourcePath, "-ar", "16000", "-ac", "1", "-c:a", "pcm_s16le", outputPath], Math.max(timeoutMs, 120_000));
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
catch (ffmpegError) {
|
|
195
|
+
try {
|
|
196
|
+
await execFileText("afconvert", ["-f", "WAVE", "-d", "LEI16@16000", "-c", "1", sourcePath, outputPath], Math.max(timeoutMs, 120_000));
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
catch (afconvertError) {
|
|
200
|
+
const ffmpegReason = ffmpegError.message;
|
|
201
|
+
const afconvertReason = afconvertError.message;
|
|
202
|
+
throw new Error(`failed to prepare audio for whisper.cpp (ffmpeg: ${ffmpegReason}; afconvert: ${afconvertReason})`);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
async function transcribeAudioWithWhisperCpp(params, modelFetchImpl = fetch) {
|
|
207
|
+
const workDir = await fs.mkdtemp(path.join(os.tmpdir(), "ouro-bb-audio-"));
|
|
208
|
+
const filename = sanitizeFilename(describeAttachment(params.attachment));
|
|
209
|
+
const extension = fileExtensionForAudio(params.attachment, params.contentType);
|
|
210
|
+
const audioPath = path.join(workDir, `${path.parse(filename).name}${extension}`);
|
|
211
|
+
const wavPath = path.join(workDir, `${path.parse(audioPath).name}.wav`);
|
|
212
|
+
const outputBase = path.join(workDir, path.parse(audioPath).name);
|
|
213
|
+
try {
|
|
214
|
+
await fs.writeFile(audioPath, params.buffer);
|
|
215
|
+
const whisperCliPath = await resolveWhisperCppBinary(params.timeoutMs);
|
|
216
|
+
const modelPath = await ensureWhisperCppModel(params.timeoutMs, modelFetchImpl);
|
|
217
|
+
await convertAudioForWhisperCpp(audioPath, wavPath, params.timeoutMs);
|
|
218
|
+
await execFileText(whisperCliPath, ["-m", modelPath, "-f", wavPath, "-oj", "-of", outputBase], Math.max(params.timeoutMs, 120_000));
|
|
219
|
+
const transcriptPath = `${outputBase}.json`;
|
|
220
|
+
const raw = await fs.readFile(transcriptPath, "utf8");
|
|
221
|
+
const parsed = JSON.parse(raw);
|
|
222
|
+
if (typeof parsed.text === "string") {
|
|
223
|
+
return parsed.text.trim();
|
|
224
|
+
}
|
|
225
|
+
if (Array.isArray(parsed.transcription)) {
|
|
226
|
+
return parsed.transcription
|
|
227
|
+
.map((entry) => (typeof entry?.text === "string" ? entry.text.trim() : ""))
|
|
228
|
+
.filter(Boolean)
|
|
229
|
+
.join(" ")
|
|
230
|
+
.trim();
|
|
231
|
+
}
|
|
232
|
+
return "";
|
|
233
|
+
}
|
|
234
|
+
finally {
|
|
235
|
+
await fs.rm(workDir, { recursive: true, force: true }).catch(() => undefined);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
async function downloadAttachment(attachment, config, channelConfig, fetchImpl) {
|
|
239
|
+
const guid = attachment.guid?.trim();
|
|
240
|
+
if (!guid) {
|
|
241
|
+
throw new Error("attachment guid missing");
|
|
242
|
+
}
|
|
243
|
+
if (typeof attachment.totalBytes === "number" && attachment.totalBytes > MAX_ATTACHMENT_BYTES) {
|
|
244
|
+
throw new Error(`attachment exceeds ${MAX_ATTACHMENT_BYTES} byte limit`);
|
|
245
|
+
}
|
|
246
|
+
const url = buildBlueBubblesApiUrl(config.serverUrl, `/api/v1/attachment/${encodeURIComponent(guid)}/download`, config.password);
|
|
247
|
+
const response = await fetchImpl(url, {
|
|
248
|
+
method: "GET",
|
|
249
|
+
signal: AbortSignal.timeout(channelConfig.requestTimeoutMs),
|
|
250
|
+
});
|
|
251
|
+
if (!response.ok) {
|
|
252
|
+
throw new Error(`HTTP ${response.status}`);
|
|
253
|
+
}
|
|
254
|
+
const buffer = Buffer.from(await response.arrayBuffer());
|
|
255
|
+
if (buffer.length > MAX_ATTACHMENT_BYTES) {
|
|
256
|
+
throw new Error(`attachment exceeds ${MAX_ATTACHMENT_BYTES} byte limit`);
|
|
257
|
+
}
|
|
258
|
+
return {
|
|
259
|
+
buffer,
|
|
260
|
+
contentType: inferContentType(attachment, response.headers.get("content-type")),
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
async function hydrateBlueBubblesAttachments(attachments, config, channelConfig, deps = {}) {
|
|
264
|
+
(0, runtime_1.emitNervesEvent)({
|
|
265
|
+
component: "senses",
|
|
266
|
+
event: "senses.bluebubbles_media_hydrate",
|
|
267
|
+
message: "hydrating bluebubbles attachments",
|
|
268
|
+
meta: {
|
|
269
|
+
attachmentCount: attachments.length,
|
|
270
|
+
preferAudioInput: deps.preferAudioInput ?? false,
|
|
271
|
+
},
|
|
272
|
+
});
|
|
273
|
+
const fetchImpl = deps.fetchImpl ?? fetch;
|
|
274
|
+
const modelFetchImpl = deps.modelFetchImpl ?? fetch;
|
|
275
|
+
const transcribeAudio = deps.transcribeAudio ?? ((params) => transcribeAudioWithWhisperCpp(params, modelFetchImpl));
|
|
276
|
+
const preferAudioInput = deps.preferAudioInput ?? false;
|
|
277
|
+
const inputParts = [];
|
|
278
|
+
const transcriptAdditions = [];
|
|
279
|
+
const notices = [];
|
|
280
|
+
for (const attachment of attachments) {
|
|
281
|
+
const name = describeAttachment(attachment);
|
|
282
|
+
try {
|
|
283
|
+
const downloaded = await downloadAttachment(attachment, config, channelConfig, fetchImpl);
|
|
284
|
+
const base64 = downloaded.buffer.toString("base64");
|
|
285
|
+
if (isImageAttachment(attachment, downloaded.contentType)) {
|
|
286
|
+
inputParts.push({
|
|
287
|
+
type: "image_url",
|
|
288
|
+
image_url: {
|
|
289
|
+
url: `data:${downloaded.contentType ?? "application/octet-stream"};base64,${base64}`,
|
|
290
|
+
detail: "auto",
|
|
291
|
+
},
|
|
292
|
+
});
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
if (isAudioAttachment(attachment, downloaded.contentType)) {
|
|
296
|
+
const audioFormat = audioFormatForInput(downloaded.contentType, attachment);
|
|
297
|
+
if (preferAudioInput && audioFormat) {
|
|
298
|
+
inputParts.push({
|
|
299
|
+
type: "input_audio",
|
|
300
|
+
input_audio: {
|
|
301
|
+
data: base64,
|
|
302
|
+
format: audioFormat,
|
|
303
|
+
},
|
|
304
|
+
});
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
const transcript = (await transcribeAudio({
|
|
308
|
+
attachment,
|
|
309
|
+
buffer: downloaded.buffer,
|
|
310
|
+
contentType: downloaded.contentType,
|
|
311
|
+
timeoutMs: channelConfig.requestTimeoutMs,
|
|
312
|
+
})).trim();
|
|
313
|
+
if (!transcript) {
|
|
314
|
+
notices.push(`attachment hydration failed for ${name}: empty audio transcript`);
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
transcriptAdditions.push(`voice note transcript: ${transcript}`);
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
inputParts.push({
|
|
321
|
+
type: "file",
|
|
322
|
+
file: {
|
|
323
|
+
file_data: base64,
|
|
324
|
+
filename: sanitizeFilename(name),
|
|
325
|
+
},
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
catch (error) {
|
|
329
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
330
|
+
notices.push(`attachment hydration failed for ${name}: ${reason}`);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
return {
|
|
334
|
+
inputParts,
|
|
335
|
+
transcriptAdditions,
|
|
336
|
+
notices,
|
|
337
|
+
};
|
|
338
|
+
}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeBlueBubblesEvent = normalizeBlueBubblesEvent;
|
|
4
|
+
const runtime_1 = require("../nerves/runtime");
|
|
5
|
+
function asRecord(value) {
|
|
6
|
+
return value && typeof value === "object" && !Array.isArray(value)
|
|
7
|
+
? value
|
|
8
|
+
: null;
|
|
9
|
+
}
|
|
10
|
+
function readString(record, key) {
|
|
11
|
+
if (!record)
|
|
12
|
+
return undefined;
|
|
13
|
+
const value = record[key];
|
|
14
|
+
return typeof value === "string" ? value : undefined;
|
|
15
|
+
}
|
|
16
|
+
function readNumber(record, key) {
|
|
17
|
+
if (!record)
|
|
18
|
+
return undefined;
|
|
19
|
+
const value = record[key];
|
|
20
|
+
return typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
|
21
|
+
}
|
|
22
|
+
function readBoolean(record, key) {
|
|
23
|
+
const value = record[key];
|
|
24
|
+
return typeof value === "boolean" ? value : undefined;
|
|
25
|
+
}
|
|
26
|
+
function normalizeHandle(raw) {
|
|
27
|
+
const trimmed = raw.trim();
|
|
28
|
+
if (!trimmed)
|
|
29
|
+
return "";
|
|
30
|
+
if (trimmed.includes("@"))
|
|
31
|
+
return trimmed.toLowerCase();
|
|
32
|
+
const compact = trimmed.replace(/[^\d+]/g, "");
|
|
33
|
+
return compact || trimmed;
|
|
34
|
+
}
|
|
35
|
+
function extractChatIdentifierFromGuid(chatGuid) {
|
|
36
|
+
if (!chatGuid)
|
|
37
|
+
return undefined;
|
|
38
|
+
const parts = chatGuid.split(";");
|
|
39
|
+
return parts.length >= 3 ? parts[2]?.trim() || undefined : undefined;
|
|
40
|
+
}
|
|
41
|
+
function buildChatRef(data, threadOriginatorGuid) {
|
|
42
|
+
void threadOriginatorGuid;
|
|
43
|
+
const chats = Array.isArray(data.chats) ? data.chats : [];
|
|
44
|
+
const chat = asRecord(chats[0]) ?? null;
|
|
45
|
+
const chatGuid = readString(chat, "guid");
|
|
46
|
+
const chatIdentifier = readString(chat, "chatIdentifier") ??
|
|
47
|
+
readString(chat, "identifier") ??
|
|
48
|
+
extractChatIdentifierFromGuid(chatGuid);
|
|
49
|
+
const displayName = readString(chat, "displayName")?.trim() || undefined;
|
|
50
|
+
const style = readNumber(chat, "style");
|
|
51
|
+
const isGroup = style === 43 || (chatGuid?.includes(";+;") ?? false) || Boolean(displayName);
|
|
52
|
+
const sessionKey = chatGuid?.trim()
|
|
53
|
+
? `chat:${chatGuid.trim()}`
|
|
54
|
+
: `chat_identifier:${(chatIdentifier ?? "unknown").trim()}`;
|
|
55
|
+
// Extract participant handles from chat.participants (when available from BB API)
|
|
56
|
+
const rawParticipants = Array.isArray(chat?.participants) ? chat.participants : [];
|
|
57
|
+
const participantHandles = rawParticipants
|
|
58
|
+
.map((p) => {
|
|
59
|
+
const rec = asRecord(p);
|
|
60
|
+
const addr = readString(rec, "address") ?? readString(rec, "id");
|
|
61
|
+
return addr ? normalizeHandle(addr) : "";
|
|
62
|
+
})
|
|
63
|
+
.filter(Boolean);
|
|
64
|
+
return {
|
|
65
|
+
chatGuid: chatGuid?.trim() || undefined,
|
|
66
|
+
chatIdentifier: chatIdentifier?.trim() || undefined,
|
|
67
|
+
displayName,
|
|
68
|
+
isGroup,
|
|
69
|
+
sessionKey,
|
|
70
|
+
sendTarget: chatGuid?.trim()
|
|
71
|
+
? { kind: "chat_guid", value: chatGuid.trim() }
|
|
72
|
+
: { kind: "chat_identifier", value: (chatIdentifier ?? "unknown").trim() },
|
|
73
|
+
participantHandles,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function extractSender(data, chat) {
|
|
77
|
+
const handle = asRecord(data.handle) ?? asRecord(data.sender) ?? null;
|
|
78
|
+
const rawId = readString(handle, "address") ??
|
|
79
|
+
readString(handle, "id") ??
|
|
80
|
+
readString(data, "senderId") ??
|
|
81
|
+
chat.chatIdentifier ??
|
|
82
|
+
chat.chatGuid ??
|
|
83
|
+
"unknown";
|
|
84
|
+
const externalId = normalizeHandle(rawId);
|
|
85
|
+
const displayName = externalId || rawId || "Unknown";
|
|
86
|
+
return {
|
|
87
|
+
provider: "imessage-handle",
|
|
88
|
+
externalId,
|
|
89
|
+
rawId,
|
|
90
|
+
displayName,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function extractAttachments(data) {
|
|
94
|
+
const raw = Array.isArray(data.attachments) ? data.attachments : [];
|
|
95
|
+
return raw
|
|
96
|
+
.map((entry) => asRecord(entry))
|
|
97
|
+
.filter((entry) => entry !== null)
|
|
98
|
+
.map((entry) => ({
|
|
99
|
+
guid: readString(entry, "guid"),
|
|
100
|
+
mimeType: readString(entry, "mimeType"),
|
|
101
|
+
transferName: readString(entry, "transferName"),
|
|
102
|
+
totalBytes: readNumber(entry, "totalBytes"),
|
|
103
|
+
height: readNumber(entry, "height"),
|
|
104
|
+
width: readNumber(entry, "width"),
|
|
105
|
+
}));
|
|
106
|
+
}
|
|
107
|
+
function formatAttachmentText(attachments) {
|
|
108
|
+
if (attachments.length === 0)
|
|
109
|
+
return "";
|
|
110
|
+
const [first] = attachments;
|
|
111
|
+
const mime = first.mimeType ?? "";
|
|
112
|
+
const label = mime.startsWith("image/")
|
|
113
|
+
? "image attachment"
|
|
114
|
+
: mime.startsWith("audio/")
|
|
115
|
+
? "audio attachment"
|
|
116
|
+
: "attachment";
|
|
117
|
+
const name = first.transferName ? `: ${first.transferName}` : "";
|
|
118
|
+
const dimensions = typeof first.width === "number" && typeof first.height === "number" && first.width > 0 && first.height > 0
|
|
119
|
+
? ` (${first.width}x${first.height})`
|
|
120
|
+
: "";
|
|
121
|
+
return `[${label}${name}${dimensions}]`;
|
|
122
|
+
}
|
|
123
|
+
function formatMessageText(data, attachments) {
|
|
124
|
+
const text = readString(data, "text")?.trim() ?? "";
|
|
125
|
+
const balloonBundleId = readString(data, "balloonBundleId")?.trim();
|
|
126
|
+
if (text) {
|
|
127
|
+
if (balloonBundleId === "com.apple.messages.URLBalloonProvider") {
|
|
128
|
+
return `${text}\n[link preview attached]`;
|
|
129
|
+
}
|
|
130
|
+
return text;
|
|
131
|
+
}
|
|
132
|
+
return formatAttachmentText(attachments);
|
|
133
|
+
}
|
|
134
|
+
function normalizeReactionName(value) {
|
|
135
|
+
if (typeof value !== "string")
|
|
136
|
+
return undefined;
|
|
137
|
+
const trimmed = value.trim();
|
|
138
|
+
return trimmed ? trimmed.toLowerCase() : undefined;
|
|
139
|
+
}
|
|
140
|
+
function stripPartPrefix(guid) {
|
|
141
|
+
if (!guid)
|
|
142
|
+
return undefined;
|
|
143
|
+
const trimmed = guid.trim();
|
|
144
|
+
const marker = trimmed.lastIndexOf("/");
|
|
145
|
+
return marker >= 0 ? trimmed.slice(marker + 1) : trimmed;
|
|
146
|
+
}
|
|
147
|
+
function buildMutationText(mutationType, data, reactionName) {
|
|
148
|
+
if (mutationType === "reaction") {
|
|
149
|
+
return `reacted with ${reactionName}`;
|
|
150
|
+
}
|
|
151
|
+
if (mutationType === "edit") {
|
|
152
|
+
const editedText = readString(data, "text")?.trim() ?? "";
|
|
153
|
+
return editedText ? `edited message: ${editedText}` : "edited a message";
|
|
154
|
+
}
|
|
155
|
+
if (mutationType === "unsend") {
|
|
156
|
+
return "unsent a message";
|
|
157
|
+
}
|
|
158
|
+
if (mutationType === "read") {
|
|
159
|
+
return "message marked as read";
|
|
160
|
+
}
|
|
161
|
+
return "message marked as delivered";
|
|
162
|
+
}
|
|
163
|
+
function detectMutationType(eventType, data, reactionName) {
|
|
164
|
+
if (reactionName)
|
|
165
|
+
return "reaction";
|
|
166
|
+
if (eventType === "updated-message") {
|
|
167
|
+
if (readNumber(data, "dateRetracted"))
|
|
168
|
+
return "unsend";
|
|
169
|
+
if (readNumber(data, "dateEdited"))
|
|
170
|
+
return "edit";
|
|
171
|
+
if (readNumber(data, "dateRead"))
|
|
172
|
+
return "read";
|
|
173
|
+
if (readBoolean(data, "isDelivered") || readNumber(data, "dateDelivered"))
|
|
174
|
+
return "delivery";
|
|
175
|
+
}
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
function normalizeBlueBubblesEvent(payload) {
|
|
179
|
+
const envelope = asRecord(payload);
|
|
180
|
+
const eventType = readString(envelope, "type")?.trim() ?? "";
|
|
181
|
+
const data = asRecord(envelope?.data);
|
|
182
|
+
if (!eventType || !data) {
|
|
183
|
+
(0, runtime_1.emitNervesEvent)({
|
|
184
|
+
level: "warn",
|
|
185
|
+
component: "senses",
|
|
186
|
+
event: "senses.bluebubbles_event_ignored",
|
|
187
|
+
message: "ignored invalid bluebubbles payload",
|
|
188
|
+
meta: { hasEnvelope: Boolean(envelope), eventType },
|
|
189
|
+
});
|
|
190
|
+
throw new Error("Invalid BlueBubbles payload");
|
|
191
|
+
}
|
|
192
|
+
const messageGuid = readString(data, "guid")?.trim();
|
|
193
|
+
if (!messageGuid) {
|
|
194
|
+
(0, runtime_1.emitNervesEvent)({
|
|
195
|
+
level: "warn",
|
|
196
|
+
component: "senses",
|
|
197
|
+
event: "senses.bluebubbles_event_ignored",
|
|
198
|
+
message: "ignored bluebubbles payload without guid",
|
|
199
|
+
meta: { eventType },
|
|
200
|
+
});
|
|
201
|
+
throw new Error("BlueBubbles payload is missing data.guid");
|
|
202
|
+
}
|
|
203
|
+
const threadOriginatorGuid = readString(data, "threadOriginatorGuid")?.trim() || undefined;
|
|
204
|
+
const chat = buildChatRef(data, threadOriginatorGuid);
|
|
205
|
+
const sender = extractSender(data, chat);
|
|
206
|
+
const timestamp = readNumber(data, "dateCreated") ?? Date.now();
|
|
207
|
+
const fromMe = readBoolean(data, "isFromMe") ?? false;
|
|
208
|
+
const attachments = extractAttachments(data);
|
|
209
|
+
const reactionName = normalizeReactionName(data.associatedMessageType);
|
|
210
|
+
const mutationType = detectMutationType(eventType, data, reactionName);
|
|
211
|
+
const requiresRepair = (readBoolean(data, "hasPayloadData") ?? false) ||
|
|
212
|
+
attachments.length > 0 ||
|
|
213
|
+
eventType === "updated-message";
|
|
214
|
+
const result = mutationType
|
|
215
|
+
? {
|
|
216
|
+
kind: "mutation",
|
|
217
|
+
eventType,
|
|
218
|
+
mutationType,
|
|
219
|
+
messageGuid,
|
|
220
|
+
targetMessageGuid: mutationType === "reaction"
|
|
221
|
+
? stripPartPrefix(readString(data, "associatedMessageGuid"))
|
|
222
|
+
: undefined,
|
|
223
|
+
timestamp,
|
|
224
|
+
fromMe,
|
|
225
|
+
sender,
|
|
226
|
+
chat,
|
|
227
|
+
shouldNotifyAgent: mutationType === "reaction" || mutationType === "edit" || mutationType === "unsend",
|
|
228
|
+
textForAgent: buildMutationText(mutationType, data, reactionName),
|
|
229
|
+
requiresRepair,
|
|
230
|
+
}
|
|
231
|
+
: {
|
|
232
|
+
kind: "message",
|
|
233
|
+
eventType,
|
|
234
|
+
messageGuid,
|
|
235
|
+
timestamp,
|
|
236
|
+
fromMe,
|
|
237
|
+
sender,
|
|
238
|
+
chat,
|
|
239
|
+
text: readString(data, "text")?.trim() ?? "",
|
|
240
|
+
textForAgent: formatMessageText(data, attachments),
|
|
241
|
+
attachments,
|
|
242
|
+
balloonBundleId: readString(data, "balloonBundleId")?.trim() || undefined,
|
|
243
|
+
hasPayloadData: readBoolean(data, "hasPayloadData") ?? false,
|
|
244
|
+
requiresRepair,
|
|
245
|
+
threadOriginatorGuid,
|
|
246
|
+
replyToGuid: threadOriginatorGuid,
|
|
247
|
+
};
|
|
248
|
+
(0, runtime_1.emitNervesEvent)({
|
|
249
|
+
component: "senses",
|
|
250
|
+
event: "senses.bluebubbles_event_normalized",
|
|
251
|
+
message: "normalized bluebubbles event",
|
|
252
|
+
meta: {
|
|
253
|
+
eventType,
|
|
254
|
+
kind: result.kind,
|
|
255
|
+
mutationType: result.kind === "mutation" ? result.mutationType : null,
|
|
256
|
+
sessionKey: result.chat.sessionKey,
|
|
257
|
+
fromMe,
|
|
258
|
+
},
|
|
259
|
+
});
|
|
260
|
+
return result;
|
|
261
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
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.getBlueBubblesMutationLogPath = getBlueBubblesMutationLogPath;
|
|
37
|
+
exports.recordBlueBubblesMutation = recordBlueBubblesMutation;
|
|
38
|
+
const fs = __importStar(require("node:fs"));
|
|
39
|
+
const path = __importStar(require("node:path"));
|
|
40
|
+
const runtime_1 = require("../nerves/runtime");
|
|
41
|
+
const identity_1 = require("../heart/identity");
|
|
42
|
+
const config_1 = require("../heart/config");
|
|
43
|
+
function getBlueBubblesMutationLogPath(agentName, sessionKey) {
|
|
44
|
+
return path.join((0, identity_1.getAgentRoot)(agentName), "state", "senses", "bluebubbles", "mutations", `${(0, config_1.sanitizeKey)(sessionKey)}.ndjson`);
|
|
45
|
+
}
|
|
46
|
+
function recordBlueBubblesMutation(agentName, event) {
|
|
47
|
+
const filePath = getBlueBubblesMutationLogPath(agentName, event.chat.sessionKey);
|
|
48
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
49
|
+
fs.appendFileSync(filePath, JSON.stringify({
|
|
50
|
+
recordedAt: new Date(event.timestamp).toISOString(),
|
|
51
|
+
eventType: event.eventType,
|
|
52
|
+
mutationType: event.mutationType,
|
|
53
|
+
messageGuid: event.messageGuid,
|
|
54
|
+
targetMessageGuid: event.targetMessageGuid ?? null,
|
|
55
|
+
chatGuid: event.chat.chatGuid ?? null,
|
|
56
|
+
chatIdentifier: event.chat.chatIdentifier ?? null,
|
|
57
|
+
sessionKey: event.chat.sessionKey,
|
|
58
|
+
shouldNotifyAgent: event.shouldNotifyAgent,
|
|
59
|
+
textForAgent: event.textForAgent,
|
|
60
|
+
fromMe: event.fromMe,
|
|
61
|
+
}) + "\n", "utf-8");
|
|
62
|
+
(0, runtime_1.emitNervesEvent)({
|
|
63
|
+
component: "senses",
|
|
64
|
+
event: "senses.bluebubbles_mutation_logged",
|
|
65
|
+
message: "recorded bluebubbles mutation to sidecar log",
|
|
66
|
+
meta: {
|
|
67
|
+
agentName,
|
|
68
|
+
mutationType: event.mutationType,
|
|
69
|
+
messageGuid: event.messageGuid,
|
|
70
|
+
path: filePath,
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
return filePath;
|
|
74
|
+
}
|