@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,434 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createBlueBubblesClient = createBlueBubblesClient;
|
|
4
|
+
const node_crypto_1 = require("node:crypto");
|
|
5
|
+
const config_1 = require("../heart/config");
|
|
6
|
+
const identity_1 = require("../heart/identity");
|
|
7
|
+
const runtime_1 = require("../nerves/runtime");
|
|
8
|
+
const bluebubbles_model_1 = require("./bluebubbles-model");
|
|
9
|
+
const bluebubbles_media_1 = require("./bluebubbles-media");
|
|
10
|
+
function buildBlueBubblesApiUrl(baseUrl, endpoint, password) {
|
|
11
|
+
const root = baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`;
|
|
12
|
+
const url = new URL(endpoint.replace(/^\//, ""), root);
|
|
13
|
+
url.searchParams.set("password", password);
|
|
14
|
+
return url.toString();
|
|
15
|
+
}
|
|
16
|
+
function asRecord(value) {
|
|
17
|
+
return value && typeof value === "object" && !Array.isArray(value)
|
|
18
|
+
? value
|
|
19
|
+
: null;
|
|
20
|
+
}
|
|
21
|
+
function readString(record, key) {
|
|
22
|
+
const value = record[key];
|
|
23
|
+
return typeof value === "string" ? value : undefined;
|
|
24
|
+
}
|
|
25
|
+
function extractMessageGuid(payload) {
|
|
26
|
+
if (!payload || typeof payload !== "object")
|
|
27
|
+
return undefined;
|
|
28
|
+
const record = payload;
|
|
29
|
+
const data = record.data && typeof record.data === "object" && !Array.isArray(record.data)
|
|
30
|
+
? record.data
|
|
31
|
+
: null;
|
|
32
|
+
const candidates = [
|
|
33
|
+
record.messageGuid,
|
|
34
|
+
record.messageId,
|
|
35
|
+
record.guid,
|
|
36
|
+
data?.messageGuid,
|
|
37
|
+
data?.messageId,
|
|
38
|
+
data?.guid,
|
|
39
|
+
];
|
|
40
|
+
for (const candidate of candidates) {
|
|
41
|
+
if (typeof candidate === "string" && candidate.trim()) {
|
|
42
|
+
return candidate.trim();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
async function parseJsonBody(response) {
|
|
48
|
+
const raw = await response.text();
|
|
49
|
+
if (!raw.trim())
|
|
50
|
+
return null;
|
|
51
|
+
try {
|
|
52
|
+
return JSON.parse(raw);
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function buildRepairUrl(baseUrl, messageGuid, password) {
|
|
59
|
+
const url = buildBlueBubblesApiUrl(baseUrl, `/api/v1/message/${encodeURIComponent(messageGuid)}`, password);
|
|
60
|
+
const parsed = new URL(url);
|
|
61
|
+
parsed.searchParams.set("with", "attachments,payloadData,chats,messageSummaryInfo");
|
|
62
|
+
return parsed.toString();
|
|
63
|
+
}
|
|
64
|
+
function extractChatIdentifierFromGuid(chatGuid) {
|
|
65
|
+
const parts = chatGuid.split(";");
|
|
66
|
+
return parts.length >= 3 ? parts[2]?.trim() || undefined : undefined;
|
|
67
|
+
}
|
|
68
|
+
function extractChatGuid(value) {
|
|
69
|
+
const record = asRecord(value);
|
|
70
|
+
const candidates = [
|
|
71
|
+
record?.chatGuid,
|
|
72
|
+
record?.guid,
|
|
73
|
+
record?.chat_guid,
|
|
74
|
+
record?.identifier,
|
|
75
|
+
record?.chatIdentifier,
|
|
76
|
+
record?.chat_identifier,
|
|
77
|
+
];
|
|
78
|
+
for (const candidate of candidates) {
|
|
79
|
+
if (typeof candidate === "string" && candidate.trim()) {
|
|
80
|
+
return candidate.trim();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
function extractQueriedChatIdentifier(chat, chatGuid) {
|
|
86
|
+
const explicitIdentifier = readString(chat, "chatIdentifier")
|
|
87
|
+
?? readString(chat, "identifier")
|
|
88
|
+
?? readString(chat, "chat_identifier");
|
|
89
|
+
if (explicitIdentifier) {
|
|
90
|
+
return explicitIdentifier;
|
|
91
|
+
}
|
|
92
|
+
return extractChatIdentifierFromGuid(chatGuid);
|
|
93
|
+
}
|
|
94
|
+
function extractChatQueryRows(payload) {
|
|
95
|
+
const record = asRecord(payload);
|
|
96
|
+
const data = Array.isArray(record?.data) ? record.data : payload;
|
|
97
|
+
if (!Array.isArray(data)) {
|
|
98
|
+
return [];
|
|
99
|
+
}
|
|
100
|
+
return data.map((entry) => asRecord(entry)).filter((entry) => entry !== null);
|
|
101
|
+
}
|
|
102
|
+
async function resolveChatGuidForIdentifier(config, channelConfig, chatIdentifier) {
|
|
103
|
+
const trimmedIdentifier = chatIdentifier.trim();
|
|
104
|
+
if (!trimmedIdentifier)
|
|
105
|
+
return undefined;
|
|
106
|
+
const url = buildBlueBubblesApiUrl(config.serverUrl, "/api/v1/chat/query", config.password);
|
|
107
|
+
const response = await fetch(url, {
|
|
108
|
+
method: "POST",
|
|
109
|
+
headers: { "Content-Type": "application/json" },
|
|
110
|
+
body: JSON.stringify({
|
|
111
|
+
limit: 500,
|
|
112
|
+
offset: 0,
|
|
113
|
+
with: ["participants"],
|
|
114
|
+
}),
|
|
115
|
+
signal: AbortSignal.timeout(channelConfig.requestTimeoutMs),
|
|
116
|
+
});
|
|
117
|
+
if (!response.ok) {
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
const payload = await parseJsonBody(response);
|
|
121
|
+
const rows = extractChatQueryRows(payload);
|
|
122
|
+
for (const row of rows) {
|
|
123
|
+
const guid = extractChatGuid(row);
|
|
124
|
+
if (!guid)
|
|
125
|
+
continue;
|
|
126
|
+
const identifier = extractQueriedChatIdentifier(row, guid);
|
|
127
|
+
if (identifier === trimmedIdentifier || guid === trimmedIdentifier) {
|
|
128
|
+
return guid;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return undefined;
|
|
132
|
+
}
|
|
133
|
+
function collectPreviewStrings(value, out, depth = 0) {
|
|
134
|
+
if (depth > 4 || out.length >= 4)
|
|
135
|
+
return;
|
|
136
|
+
if (typeof value === "string") {
|
|
137
|
+
const trimmed = value.trim();
|
|
138
|
+
if (trimmed)
|
|
139
|
+
out.push(trimmed);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (Array.isArray(value)) {
|
|
143
|
+
for (const entry of value)
|
|
144
|
+
collectPreviewStrings(entry, out, depth + 1);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
const record = asRecord(value);
|
|
148
|
+
if (!record)
|
|
149
|
+
return;
|
|
150
|
+
const preferredKeys = ["title", "summary", "subtitle", "previewText", "siteName", "host", "url"];
|
|
151
|
+
for (const key of preferredKeys) {
|
|
152
|
+
if (out.length >= 4)
|
|
153
|
+
break;
|
|
154
|
+
collectPreviewStrings(record[key], out, depth + 1);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
function extractLinkPreviewText(data) {
|
|
158
|
+
const values = [];
|
|
159
|
+
collectPreviewStrings(data.payloadData, values);
|
|
160
|
+
collectPreviewStrings(data.messageSummaryInfo, values);
|
|
161
|
+
const unique = [...new Set(values.map((value) => value.trim()).filter(Boolean))];
|
|
162
|
+
if (unique.length === 0)
|
|
163
|
+
return undefined;
|
|
164
|
+
return unique.slice(0, 2).join(" — ");
|
|
165
|
+
}
|
|
166
|
+
function applyRepairNotice(event, notice) {
|
|
167
|
+
return {
|
|
168
|
+
...event,
|
|
169
|
+
requiresRepair: false,
|
|
170
|
+
repairNotice: notice,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
function hydrateTextForAgent(event, rawData) {
|
|
174
|
+
if (event.kind !== "message") {
|
|
175
|
+
return { ...event, requiresRepair: false };
|
|
176
|
+
}
|
|
177
|
+
if (event.balloonBundleId !== "com.apple.messages.URLBalloonProvider") {
|
|
178
|
+
return { ...event, requiresRepair: false };
|
|
179
|
+
}
|
|
180
|
+
const previewText = extractLinkPreviewText(rawData);
|
|
181
|
+
if (!previewText) {
|
|
182
|
+
return { ...event, requiresRepair: false };
|
|
183
|
+
}
|
|
184
|
+
const base = event.text.trim();
|
|
185
|
+
const textForAgent = base
|
|
186
|
+
? `${base}\n[link preview: ${previewText}]`
|
|
187
|
+
: `[link preview: ${previewText}]`;
|
|
188
|
+
return {
|
|
189
|
+
...event,
|
|
190
|
+
textForAgent,
|
|
191
|
+
requiresRepair: false,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
function extractRepairData(payload) {
|
|
195
|
+
const record = asRecord(payload);
|
|
196
|
+
return asRecord(record?.data) ?? record;
|
|
197
|
+
}
|
|
198
|
+
function providerSupportsAudioInput(provider) {
|
|
199
|
+
void provider;
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
async function resolveChatGuid(chat, config, channelConfig) {
|
|
203
|
+
return chat.chatGuid
|
|
204
|
+
?? await resolveChatGuidForIdentifier(config, channelConfig, chat.chatIdentifier ?? "");
|
|
205
|
+
}
|
|
206
|
+
function createBlueBubblesClient(config = (0, config_1.getBlueBubblesConfig)(), channelConfig = (0, config_1.getBlueBubblesChannelConfig)()) {
|
|
207
|
+
return {
|
|
208
|
+
async sendText(params) {
|
|
209
|
+
const trimmedText = params.text.trim();
|
|
210
|
+
if (!trimmedText) {
|
|
211
|
+
throw new Error("BlueBubbles send requires non-empty text.");
|
|
212
|
+
}
|
|
213
|
+
const resolvedChatGuid = await resolveChatGuid(params.chat, config, channelConfig);
|
|
214
|
+
if (!resolvedChatGuid) {
|
|
215
|
+
throw new Error("BlueBubbles send currently requires chat.chatGuid from the inbound event.");
|
|
216
|
+
}
|
|
217
|
+
const url = buildBlueBubblesApiUrl(config.serverUrl, "/api/v1/message/text", config.password);
|
|
218
|
+
const body = {
|
|
219
|
+
chatGuid: resolvedChatGuid,
|
|
220
|
+
tempGuid: (0, node_crypto_1.randomUUID)(),
|
|
221
|
+
message: trimmedText,
|
|
222
|
+
};
|
|
223
|
+
if (params.replyToMessageGuid?.trim()) {
|
|
224
|
+
body.method = "private-api";
|
|
225
|
+
body.selectedMessageGuid = params.replyToMessageGuid.trim();
|
|
226
|
+
body.partIndex = 0;
|
|
227
|
+
}
|
|
228
|
+
(0, runtime_1.emitNervesEvent)({
|
|
229
|
+
component: "senses",
|
|
230
|
+
event: "senses.bluebubbles_send_start",
|
|
231
|
+
message: "sending bluebubbles message",
|
|
232
|
+
meta: {
|
|
233
|
+
chatGuid: resolvedChatGuid,
|
|
234
|
+
hasReplyTarget: Boolean(params.replyToMessageGuid?.trim()),
|
|
235
|
+
},
|
|
236
|
+
});
|
|
237
|
+
const response = await fetch(url, {
|
|
238
|
+
method: "POST",
|
|
239
|
+
headers: { "Content-Type": "application/json" },
|
|
240
|
+
body: JSON.stringify(body),
|
|
241
|
+
signal: AbortSignal.timeout(channelConfig.requestTimeoutMs),
|
|
242
|
+
});
|
|
243
|
+
if (!response.ok) {
|
|
244
|
+
const errorText = await response.text().catch(() => "");
|
|
245
|
+
(0, runtime_1.emitNervesEvent)({
|
|
246
|
+
level: "error",
|
|
247
|
+
component: "senses",
|
|
248
|
+
event: "senses.bluebubbles_send_error",
|
|
249
|
+
message: "bluebubbles send failed",
|
|
250
|
+
meta: {
|
|
251
|
+
status: response.status,
|
|
252
|
+
reason: errorText || "unknown",
|
|
253
|
+
},
|
|
254
|
+
});
|
|
255
|
+
throw new Error(`BlueBubbles send failed (${response.status}): ${errorText || "unknown"}`);
|
|
256
|
+
}
|
|
257
|
+
const payload = await parseJsonBody(response);
|
|
258
|
+
const messageGuid = extractMessageGuid(payload);
|
|
259
|
+
(0, runtime_1.emitNervesEvent)({
|
|
260
|
+
component: "senses",
|
|
261
|
+
event: "senses.bluebubbles_send_end",
|
|
262
|
+
message: "bluebubbles message sent",
|
|
263
|
+
meta: {
|
|
264
|
+
chatGuid: resolvedChatGuid,
|
|
265
|
+
messageGuid: messageGuid ?? null,
|
|
266
|
+
},
|
|
267
|
+
});
|
|
268
|
+
return { messageGuid };
|
|
269
|
+
},
|
|
270
|
+
async editMessage(params) {
|
|
271
|
+
const messageGuid = params.messageGuid.trim();
|
|
272
|
+
const text = params.text.trim();
|
|
273
|
+
if (!messageGuid) {
|
|
274
|
+
throw new Error("BlueBubbles edit requires messageGuid.");
|
|
275
|
+
}
|
|
276
|
+
if (!text) {
|
|
277
|
+
throw new Error("BlueBubbles edit requires non-empty text.");
|
|
278
|
+
}
|
|
279
|
+
const editTimeoutMs = Math.max(channelConfig.requestTimeoutMs, 120000);
|
|
280
|
+
const url = buildBlueBubblesApiUrl(config.serverUrl, `/api/v1/message/${encodeURIComponent(messageGuid)}/edit`, config.password);
|
|
281
|
+
const response = await fetch(url, {
|
|
282
|
+
method: "POST",
|
|
283
|
+
headers: { "Content-Type": "application/json" },
|
|
284
|
+
body: JSON.stringify({
|
|
285
|
+
editedMessage: text,
|
|
286
|
+
backwardsCompatibilityMessage: params.backwardsCompatibilityMessage ?? `Edited to: ${text}`,
|
|
287
|
+
partIndex: typeof params.partIndex === "number" ? params.partIndex : 0,
|
|
288
|
+
}),
|
|
289
|
+
signal: AbortSignal.timeout(editTimeoutMs),
|
|
290
|
+
});
|
|
291
|
+
if (!response.ok) {
|
|
292
|
+
const errorText = await response.text().catch(() => "");
|
|
293
|
+
throw new Error(`BlueBubbles edit failed (${response.status}): ${errorText || "unknown"}`);
|
|
294
|
+
}
|
|
295
|
+
},
|
|
296
|
+
async setTyping(chat, typing) {
|
|
297
|
+
const resolvedChatGuid = await resolveChatGuid(chat, config, channelConfig);
|
|
298
|
+
if (!resolvedChatGuid) {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
const url = buildBlueBubblesApiUrl(config.serverUrl, `/api/v1/chat/${encodeURIComponent(resolvedChatGuid)}/typing`, config.password);
|
|
302
|
+
const response = await fetch(url, {
|
|
303
|
+
method: typing ? "POST" : "DELETE",
|
|
304
|
+
signal: AbortSignal.timeout(channelConfig.requestTimeoutMs),
|
|
305
|
+
});
|
|
306
|
+
if (!response.ok) {
|
|
307
|
+
const errorText = await response.text().catch(() => "");
|
|
308
|
+
throw new Error(`BlueBubbles typing failed (${response.status}): ${errorText || "unknown"}`);
|
|
309
|
+
}
|
|
310
|
+
},
|
|
311
|
+
async markChatRead(chat) {
|
|
312
|
+
const resolvedChatGuid = await resolveChatGuid(chat, config, channelConfig);
|
|
313
|
+
if (!resolvedChatGuid) {
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
const url = buildBlueBubblesApiUrl(config.serverUrl, `/api/v1/chat/${encodeURIComponent(resolvedChatGuid)}/read`, config.password);
|
|
317
|
+
const response = await fetch(url, {
|
|
318
|
+
method: "POST",
|
|
319
|
+
signal: AbortSignal.timeout(channelConfig.requestTimeoutMs),
|
|
320
|
+
});
|
|
321
|
+
if (!response.ok) {
|
|
322
|
+
const errorText = await response.text().catch(() => "");
|
|
323
|
+
throw new Error(`BlueBubbles read failed (${response.status}): ${errorText || "unknown"}`);
|
|
324
|
+
}
|
|
325
|
+
},
|
|
326
|
+
async repairEvent(event) {
|
|
327
|
+
if (!event.requiresRepair) {
|
|
328
|
+
(0, runtime_1.emitNervesEvent)({
|
|
329
|
+
component: "senses",
|
|
330
|
+
event: "senses.bluebubbles_repair_skipped",
|
|
331
|
+
message: "bluebubbles event repair skipped",
|
|
332
|
+
meta: {
|
|
333
|
+
kind: event.kind,
|
|
334
|
+
messageGuid: event.messageGuid,
|
|
335
|
+
},
|
|
336
|
+
});
|
|
337
|
+
return event;
|
|
338
|
+
}
|
|
339
|
+
(0, runtime_1.emitNervesEvent)({
|
|
340
|
+
component: "senses",
|
|
341
|
+
event: "senses.bluebubbles_repair_start",
|
|
342
|
+
message: "repairing bluebubbles event by guid",
|
|
343
|
+
meta: {
|
|
344
|
+
kind: event.kind,
|
|
345
|
+
messageGuid: event.messageGuid,
|
|
346
|
+
eventType: event.eventType,
|
|
347
|
+
},
|
|
348
|
+
});
|
|
349
|
+
const url = buildRepairUrl(config.serverUrl, event.messageGuid, config.password);
|
|
350
|
+
try {
|
|
351
|
+
const response = await fetch(url, {
|
|
352
|
+
method: "GET",
|
|
353
|
+
signal: AbortSignal.timeout(channelConfig.requestTimeoutMs),
|
|
354
|
+
});
|
|
355
|
+
if (!response.ok) {
|
|
356
|
+
const errorText = await response.text().catch(() => "");
|
|
357
|
+
const repaired = applyRepairNotice(event, `BlueBubbles repair failed: ${errorText || `HTTP ${response.status}`}`);
|
|
358
|
+
(0, runtime_1.emitNervesEvent)({
|
|
359
|
+
level: "warn",
|
|
360
|
+
component: "senses",
|
|
361
|
+
event: "senses.bluebubbles_repair_error",
|
|
362
|
+
message: "bluebubbles repair request failed",
|
|
363
|
+
meta: {
|
|
364
|
+
messageGuid: event.messageGuid,
|
|
365
|
+
status: response.status,
|
|
366
|
+
reason: errorText || "unknown",
|
|
367
|
+
},
|
|
368
|
+
});
|
|
369
|
+
return repaired;
|
|
370
|
+
}
|
|
371
|
+
const payload = await parseJsonBody(response);
|
|
372
|
+
const data = extractRepairData(payload);
|
|
373
|
+
if (!data || typeof data.guid !== "string") {
|
|
374
|
+
const repaired = applyRepairNotice(event, "BlueBubbles repair failed: invalid message payload");
|
|
375
|
+
(0, runtime_1.emitNervesEvent)({
|
|
376
|
+
level: "warn",
|
|
377
|
+
component: "senses",
|
|
378
|
+
event: "senses.bluebubbles_repair_error",
|
|
379
|
+
message: "bluebubbles repair returned unusable payload",
|
|
380
|
+
meta: {
|
|
381
|
+
messageGuid: event.messageGuid,
|
|
382
|
+
},
|
|
383
|
+
});
|
|
384
|
+
return repaired;
|
|
385
|
+
}
|
|
386
|
+
const normalized = (0, bluebubbles_model_1.normalizeBlueBubblesEvent)({
|
|
387
|
+
type: event.eventType,
|
|
388
|
+
data,
|
|
389
|
+
});
|
|
390
|
+
let hydrated = hydrateTextForAgent(normalized, data);
|
|
391
|
+
if (hydrated.kind === "message" &&
|
|
392
|
+
hydrated.balloonBundleId !== "com.apple.messages.URLBalloonProvider" &&
|
|
393
|
+
hydrated.attachments.length > 0) {
|
|
394
|
+
const media = await (0, bluebubbles_media_1.hydrateBlueBubblesAttachments)(hydrated.attachments, config, channelConfig, {
|
|
395
|
+
preferAudioInput: providerSupportsAudioInput((0, identity_1.loadAgentConfig)().provider),
|
|
396
|
+
});
|
|
397
|
+
const transcriptSuffix = media.transcriptAdditions.map((entry) => `[${entry}]`).join("\n");
|
|
398
|
+
const noticeSuffix = media.notices.map((entry) => `[${entry}]`).join("\n");
|
|
399
|
+
const combinedSuffix = [transcriptSuffix, noticeSuffix].filter(Boolean).join("\n");
|
|
400
|
+
hydrated = {
|
|
401
|
+
...hydrated,
|
|
402
|
+
inputPartsForAgent: media.inputParts.length > 0 ? media.inputParts : undefined,
|
|
403
|
+
textForAgent: [hydrated.textForAgent, combinedSuffix].filter(Boolean).join("\n"),
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
(0, runtime_1.emitNervesEvent)({
|
|
407
|
+
component: "senses",
|
|
408
|
+
event: "senses.bluebubbles_repair_end",
|
|
409
|
+
message: "bluebubbles event repaired",
|
|
410
|
+
meta: {
|
|
411
|
+
kind: hydrated.kind,
|
|
412
|
+
messageGuid: hydrated.messageGuid,
|
|
413
|
+
repairedFrom: event.kind,
|
|
414
|
+
},
|
|
415
|
+
});
|
|
416
|
+
return hydrated;
|
|
417
|
+
}
|
|
418
|
+
catch (error) {
|
|
419
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
420
|
+
(0, runtime_1.emitNervesEvent)({
|
|
421
|
+
level: "warn",
|
|
422
|
+
component: "senses",
|
|
423
|
+
event: "senses.bluebubbles_repair_error",
|
|
424
|
+
message: "bluebubbles repair threw",
|
|
425
|
+
meta: {
|
|
426
|
+
messageGuid: event.messageGuid,
|
|
427
|
+
reason,
|
|
428
|
+
},
|
|
429
|
+
});
|
|
430
|
+
return applyRepairNotice(event, `BlueBubbles repair failed: ${reason}`);
|
|
431
|
+
}
|
|
432
|
+
},
|
|
433
|
+
};
|
|
434
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Thin entrypoint for `npm run bluebubbles` / `node dist/senses/bluebubbles-entry.js --agent <name>`.
|
|
3
|
+
// Separated from bluebubbles.ts so the BlueBubbles adapter stays testable.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
if (!process.argv.includes("--agent")) {
|
|
6
|
+
// eslint-disable-next-line no-console -- pre-boot guard: --agent check before imports
|
|
7
|
+
console.error("Missing required --agent <name> argument.\nUsage: node dist/senses/bluebubbles-entry.js --agent ouroboros");
|
|
8
|
+
process.exit(1);
|
|
9
|
+
}
|
|
10
|
+
const bluebubbles_1 = require("./bluebubbles");
|
|
11
|
+
(0, bluebubbles_1.startBlueBubblesApp)();
|