@ouro.bot/cli 0.1.0-alpha.1117 → 0.1.0-alpha.1119
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 +12 -0
- package/deploy/unraid/sanctuary.ouro/bundle-meta.json +1 -1
- package/deploy/unraid/sanctuary.xml +1 -1
- package/dist/heart/chat-interaction.js +38 -0
- package/dist/heart/daemon/sanctuary-telegram-authority-gateway.js +5 -16
- package/dist/heart/daemon/sanctuary-telegram-authority-service.js +1 -1
- package/dist/senses/bluebubbles/index.js +47 -41
- package/dist/senses/bluebubbles/model.js +14 -28
- package/dist/senses/shared-turn.js +1 -0
- package/dist/senses/teams.js +45 -19
- package/dist/senses/telegram-authority-transport.js +7 -8
- package/dist/senses/telegram-client.js +47 -12
- package/dist/senses/telegram-effect-adapter.js +1 -0
- package/dist/senses/telegram.js +16 -2
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/dist/senses/bluebubbles/reaction-policy.js +0 -47
package/changelog.json
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"_note": "This changelog is maintained as part of the PR/version-bump workflow. Agent-curated, not auto-generated. Agents read this file directly via read_file to understand what changed between versions.",
|
|
3
3
|
"versions": [
|
|
4
|
+
{
|
|
5
|
+
"version": "0.1.0-alpha.1119",
|
|
6
|
+
"changes": [
|
|
7
|
+
"A merge reaches npm and the container registry within minutes: the publish no longer waits for a second run of every test, the registry wait no longer holds up the container image, and the image builds each architecture on its own runner instead of emulating arm64."
|
|
8
|
+
]
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"version": "0.1.0-alpha.1118",
|
|
12
|
+
"changes": [
|
|
13
|
+
"Edits and reactions on iMessage, Telegram and Teams now reach the agent as turns, worded the same way everywhere; the agent decides whether to answer."
|
|
14
|
+
]
|
|
15
|
+
},
|
|
4
16
|
{
|
|
5
17
|
"version": "0.1.0-alpha.1117",
|
|
6
18
|
"changes": [
|
|
@@ -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.1119</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,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.renderChatInteraction = renderChatInteraction;
|
|
4
|
+
const runtime_1 = require("../nerves/runtime");
|
|
5
|
+
const EXCERPT_MAX_LENGTH = 80;
|
|
6
|
+
function excerpt(text) {
|
|
7
|
+
return text.length > EXCERPT_MAX_LENGTH ? `${text.slice(0, EXCERPT_MAX_LENGTH - 3)}...` : text;
|
|
8
|
+
}
|
|
9
|
+
function targetPhrase(target, eventName) {
|
|
10
|
+
const text = target.text?.trim();
|
|
11
|
+
if (text) {
|
|
12
|
+
const owner = target.fromAgent === true ? "your" : target.fromAgent === false ? "their" : "a";
|
|
13
|
+
return `${owner} message: "${excerpt(text)}"`;
|
|
14
|
+
}
|
|
15
|
+
if (target.fromAgent === true)
|
|
16
|
+
return "one of your messages (its text was not included)";
|
|
17
|
+
// Say plainly that the referent is missing, so the agent can ask instead of guessing what was meant.
|
|
18
|
+
return target.id
|
|
19
|
+
? `an unidentified message (target ${target.id}; its text could not be resolved)`
|
|
20
|
+
: `an unidentified message (the ${eventName} carried no target message reference)`;
|
|
21
|
+
}
|
|
22
|
+
/** The words the agent reads for an edit or a reaction. */
|
|
23
|
+
function renderChatInteraction(interaction) {
|
|
24
|
+
(0, runtime_1.emitNervesEvent)({ component: "senses", event: "senses.chat_interaction_rendered", message: "chat interaction rendered for the agent", meta: { kind: interaction.kind } });
|
|
25
|
+
if (interaction.kind === "edit") {
|
|
26
|
+
const before = interaction.previousText?.trim();
|
|
27
|
+
const after = interaction.newText.trim();
|
|
28
|
+
if (!after)
|
|
29
|
+
return "edited their message (the new text could not be read)";
|
|
30
|
+
return before
|
|
31
|
+
? `edited their message: "${excerpt(before)}" → "${after}"`
|
|
32
|
+
: `edited their message to: "${after}"`;
|
|
33
|
+
}
|
|
34
|
+
const phrase = targetPhrase(interaction.target, "reaction");
|
|
35
|
+
if (interaction.removed)
|
|
36
|
+
return `removed their ${interaction.label} reaction from ${phrase}`;
|
|
37
|
+
return interaction.verb ? `${interaction.verb} ${phrase}` : `reacted with ${interaction.label} to ${phrase}`;
|
|
38
|
+
}
|
|
@@ -40,6 +40,7 @@ const node_crypto_1 = require("node:crypto");
|
|
|
40
40
|
const fs = __importStar(require("node:fs"));
|
|
41
41
|
const path = __importStar(require("node:path"));
|
|
42
42
|
const runtime_1 = require("../../nerves/runtime");
|
|
43
|
+
const telegram_client_1 = require("../../senses/telegram-client");
|
|
43
44
|
const session_transaction_1 = require("../../mind/session-transaction");
|
|
44
45
|
const sanctuary_authority_codec_1 = require("./sanctuary-authority-codec");
|
|
45
46
|
const SCHEMA_VERSION = 1;
|
|
@@ -114,22 +115,10 @@ function updateCoordinates(update) {
|
|
|
114
115
|
callbackQueryId: callback.id,
|
|
115
116
|
};
|
|
116
117
|
}
|
|
117
|
-
const message = update
|
|
118
|
-
if (message
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
&& Number.isSafeInteger(message.from.id)
|
|
122
|
-
&& Number.isSafeInteger(message.chat.id)
|
|
123
|
-
&& Number.isSafeInteger(message.message_id)) {
|
|
124
|
-
return {
|
|
125
|
-
updateClass: "message",
|
|
126
|
-
userId: String(message.from.id),
|
|
127
|
-
chatId: String(message.chat.id),
|
|
128
|
-
messageId: String(message.message_id),
|
|
129
|
-
callbackQueryId: null,
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
return null;
|
|
118
|
+
const message = (0, telegram_client_1.telegramUpdateMessageCoordinates)(update);
|
|
119
|
+
if (message?.chatType !== "private")
|
|
120
|
+
return null;
|
|
121
|
+
return { updateClass: "message", userId: message.userId, chatId: message.chatId, messageId: message.messageId, callbackQueryId: null };
|
|
133
122
|
}
|
|
134
123
|
function initialState() {
|
|
135
124
|
return { schemaVersion: SCHEMA_VERSION, cursor: 0, records: {}, authorizedChats: {} };
|
|
@@ -108,7 +108,7 @@ class SanctuaryTelegramAuthorityService {
|
|
|
108
108
|
return await this.#api.request("getUpdates", {
|
|
109
109
|
offset: this.#gateway.cursor(),
|
|
110
110
|
timeout: 50,
|
|
111
|
-
allowed_updates: [
|
|
111
|
+
allowed_updates: [...telegram_client_1.TELEGRAM_ALLOWED_UPDATES],
|
|
112
112
|
});
|
|
113
113
|
}
|
|
114
114
|
catch (error) {
|
|
@@ -88,7 +88,6 @@ const processed_log_1 = require("./processed-log");
|
|
|
88
88
|
const semantic_receipts_1 = require("./semantic-receipts");
|
|
89
89
|
const runtime_state_1 = require("./runtime-state");
|
|
90
90
|
const session_cleanup_1 = require("./session-cleanup");
|
|
91
|
-
const reaction_policy_1 = require("./reaction-policy");
|
|
92
91
|
const latest_turn_1 = require("./latest-turn");
|
|
93
92
|
const active_turns_1 = require("./active-turns");
|
|
94
93
|
const trust_gate_1 = require("../trust-gate");
|
|
@@ -139,6 +138,15 @@ function adoptBlueBubblesSemanticObservation(keyHash, observedReservation, activ
|
|
|
139
138
|
}
|
|
140
139
|
return existing;
|
|
141
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* A capture seeded at startup already holds its causal place. Fold the recovery pass's fresh reservation into it now, so
|
|
143
|
+
* the lane schedules by the seeded order and a newer recovered turn never waits on an older capture's unfolded duplicate.
|
|
144
|
+
*/
|
|
145
|
+
function seededObservationReservation(keyHash, fresh) {
|
|
146
|
+
return semanticObservationGenerations.has(keyHash)
|
|
147
|
+
? adoptBlueBubblesSemanticObservation(keyHash, fresh, false).reservation
|
|
148
|
+
: fresh;
|
|
149
|
+
}
|
|
142
150
|
function suspendBlueBubblesSemanticObservation(generation) {
|
|
143
151
|
generation.retry = true;
|
|
144
152
|
generation.retainedAtMs = Date.now();
|
|
@@ -1917,6 +1925,7 @@ async function handleBlueBubblesNormalizedEvent(event, resolvedDeps, source, opt
|
|
|
1917
1925
|
...mcpOwner,
|
|
1918
1926
|
currentIngressEvidence: options.currentIngressEvidence,
|
|
1919
1927
|
},
|
|
1928
|
+
...(options.isReactionSignal ? { isReactionSignal: true } : {}),
|
|
1920
1929
|
},
|
|
1921
1930
|
callbacks: failoverAwareCallbacks,
|
|
1922
1931
|
sessionTurnLease,
|
|
@@ -2294,9 +2303,25 @@ function canonicalizeBlueBubblesEvent(event, capability) {
|
|
|
2294
2303
|
};
|
|
2295
2304
|
}
|
|
2296
2305
|
function isCaptureOnlyBlueBubblesMutation(capture) {
|
|
2297
|
-
return capture.event.kind === "
|
|
2298
|
-
|
|
2299
|
-
|
|
2306
|
+
return capture.event.kind === "unsend";
|
|
2307
|
+
}
|
|
2308
|
+
/** A reaction or an edit is speech to the agent: it arrives as a message carrying the shared rendering, aimed at the message it changes. */
|
|
2309
|
+
function blueBubblesInteractionAsMessage(event) {
|
|
2310
|
+
return {
|
|
2311
|
+
kind: "message",
|
|
2312
|
+
eventType: event.eventType,
|
|
2313
|
+
messageGuid: event.messageGuid,
|
|
2314
|
+
timestamp: event.timestamp,
|
|
2315
|
+
fromMe: event.fromMe,
|
|
2316
|
+
sender: event.sender,
|
|
2317
|
+
chat: event.chat,
|
|
2318
|
+
text: event.textForAgent,
|
|
2319
|
+
textForAgent: event.textForAgent,
|
|
2320
|
+
attachments: [],
|
|
2321
|
+
hasPayloadData: false,
|
|
2322
|
+
requiresRepair: false,
|
|
2323
|
+
...(event.targetMessageGuid ? { replyToGuid: event.targetMessageGuid } : {}),
|
|
2324
|
+
};
|
|
2300
2325
|
}
|
|
2301
2326
|
function isAuditOnlySemanticCapture(capture) {
|
|
2302
2327
|
return capture.event.kind === "read" || capture.event.kind === "delivery";
|
|
@@ -2344,7 +2369,7 @@ function semanticCaptureToNormalizedEvent(capture) {
|
|
|
2344
2369
|
const textForAgent = reaction
|
|
2345
2370
|
? (0, model_1.renderBlueBubblesReactionText)(reaction, { guid: targetMessageGuid })
|
|
2346
2371
|
: event.kind === "edit"
|
|
2347
|
-
?
|
|
2372
|
+
? (0, model_1.renderBlueBubblesEditText)(event.text)
|
|
2348
2373
|
: event.kind === "unsend"
|
|
2349
2374
|
? "unsent a message"
|
|
2350
2375
|
: event.kind === "read"
|
|
@@ -2395,32 +2420,9 @@ function seedBlueBubblesStartupSemanticObservations(deps = {}) {
|
|
|
2395
2420
|
}
|
|
2396
2421
|
return seeded;
|
|
2397
2422
|
}
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
return null;
|
|
2402
|
-
const input = {
|
|
2403
|
-
fromMe: event.fromMe,
|
|
2404
|
-
action: event.canonicalAction,
|
|
2405
|
-
canonicalValue: event.canonicalValue,
|
|
2406
|
-
};
|
|
2407
|
-
return { decision: (0, reaction_policy_1.classifyBlueBubblesReaction)(input) };
|
|
2408
|
-
}
|
|
2409
|
-
function captureOnlyHandledDisposition(capture, reactionDecision) {
|
|
2410
|
-
if (capture.event.kind !== "reaction") {
|
|
2411
|
-
return {
|
|
2412
|
-
outcome: capture.event.kind === "edit" ? "edit_capture_only" : "unsend_capture_only",
|
|
2413
|
-
detailCode: null,
|
|
2414
|
-
};
|
|
2415
|
-
}
|
|
2416
|
-
const classifiedOutcome = reactionDecision.outcome;
|
|
2417
|
-
if (classifiedOutcome === "capture_only_negative" || classifiedOutcome === "capture_only_question") {
|
|
2418
|
-
return {
|
|
2419
|
-
outcome: "capture_only_unknown",
|
|
2420
|
-
detailCode: classifiedOutcome,
|
|
2421
|
-
};
|
|
2422
|
-
}
|
|
2423
|
-
return { outcome: classifiedOutcome, detailCode: null };
|
|
2423
|
+
/** Only an unsend is kept without a turn: it takes words back and adds none for the agent to answer. */
|
|
2424
|
+
function captureOnlyHandledDisposition() {
|
|
2425
|
+
return { outcome: "unsend_capture_only", detailCode: null };
|
|
2424
2426
|
}
|
|
2425
2427
|
function auditOnlyHandledOutcome(kind) {
|
|
2426
2428
|
return kind === "read" ? "read_audit_only" : "delivery_audit_only";
|
|
@@ -2540,9 +2542,6 @@ async function handleCapturedBlueBubblesSemanticEvent(captured, resolvedDeps, so
|
|
|
2540
2542
|
};
|
|
2541
2543
|
try {
|
|
2542
2544
|
options.lifecycleSignal?.throwIfAborted();
|
|
2543
|
-
const reactionClassification = await classifyCapturedBlueBubblesReaction(captured);
|
|
2544
|
-
options.lifecycleSignal?.throwIfAborted();
|
|
2545
|
-
const reactionDecision = reactionClassification?.decision ?? null;
|
|
2546
2545
|
if (captured.capture.event.fromMe) {
|
|
2547
2546
|
(0, runtime_1.emitNervesEvent)({
|
|
2548
2547
|
component: "senses",
|
|
@@ -2609,7 +2608,8 @@ async function handleCapturedBlueBubblesSemanticEvent(captured, resolvedDeps, so
|
|
|
2609
2608
|
}
|
|
2610
2609
|
else {
|
|
2611
2610
|
const captureOnlyMutation = isCaptureOnlyBlueBubblesMutation(captured.capture);
|
|
2612
|
-
|
|
2611
|
+
// A reaction, edit or unsend carries what the turn needs in the webhook itself; only a routed message is re-fetched.
|
|
2612
|
+
const repaired = captured.normalized.kind === "mutation" && captured.normalized.chat.chatGuid?.trim()
|
|
2613
2613
|
? captured.normalized
|
|
2614
2614
|
: await resolvedDeps.createClient().repairEvent(captured.normalized);
|
|
2615
2615
|
options.lifecycleSignal?.throwIfAborted();
|
|
@@ -2633,7 +2633,7 @@ async function handleCapturedBlueBubblesSemanticEvent(captured, resolvedDeps, so
|
|
|
2633
2633
|
throw new Error("semantic_capture_routing_invalid");
|
|
2634
2634
|
}
|
|
2635
2635
|
const disposition = captureOnlyMutation
|
|
2636
|
-
? captureOnlyHandledDisposition(
|
|
2636
|
+
? captureOnlyHandledDisposition()
|
|
2637
2637
|
: { outcome: "message_observed", detailCode: null };
|
|
2638
2638
|
publishTerminalReceipt(disposition.outcome, disposition.detailCode);
|
|
2639
2639
|
semanticHandlingCompleted = true;
|
|
@@ -2646,7 +2646,7 @@ async function handleCapturedBlueBubblesSemanticEvent(captured, resolvedDeps, so
|
|
|
2646
2646
|
}
|
|
2647
2647
|
latestTurnCapability = promotion.capability;
|
|
2648
2648
|
if (captureOnlyMutation) {
|
|
2649
|
-
const disposition = captureOnlyHandledDisposition(
|
|
2649
|
+
const disposition = captureOnlyHandledDisposition();
|
|
2650
2650
|
publishTerminalReceipt(disposition.outcome, disposition.detailCode);
|
|
2651
2651
|
semanticHandlingCompleted = true;
|
|
2652
2652
|
return {
|
|
@@ -2656,8 +2656,13 @@ async function handleCapturedBlueBubblesSemanticEvent(captured, resolvedDeps, so
|
|
|
2656
2656
|
reason: "mutation_state_only",
|
|
2657
2657
|
};
|
|
2658
2658
|
}
|
|
2659
|
-
|
|
2660
|
-
|
|
2659
|
+
const interaction = identityGroundedRepaired.kind === "mutation"
|
|
2660
|
+
&& (identityGroundedRepaired.mutationType === "reaction" || identityGroundedRepaired.mutationType === "edit")
|
|
2661
|
+
? identityGroundedRepaired
|
|
2662
|
+
: null;
|
|
2663
|
+
const turnEvent = interaction ? blueBubblesInteractionAsMessage(interaction) : identityGroundedRepaired;
|
|
2664
|
+
if (turnEvent.kind === "mutation") {
|
|
2665
|
+
const outcome = auditOnlyHandledOutcome(turnEvent.mutationType);
|
|
2661
2666
|
publishTerminalReceipt(outcome);
|
|
2662
2667
|
semanticHandlingCompleted = true;
|
|
2663
2668
|
return {
|
|
@@ -2667,7 +2672,7 @@ async function handleCapturedBlueBubblesSemanticEvent(captured, resolvedDeps, so
|
|
|
2667
2672
|
reason: "mutation_state_only",
|
|
2668
2673
|
};
|
|
2669
2674
|
}
|
|
2670
|
-
const canonicalEvent = canonicalizeBlueBubblesEvent(
|
|
2675
|
+
const canonicalEvent = canonicalizeBlueBubblesEvent(turnEvent, latestTurnCapability);
|
|
2671
2676
|
const capturedOptions = {
|
|
2672
2677
|
...options,
|
|
2673
2678
|
latestTurnCapability,
|
|
@@ -2679,6 +2684,7 @@ async function handleCapturedBlueBubblesSemanticEvent(captured, resolvedDeps, so
|
|
|
2679
2684
|
orientationEvidence: captured.capture.event,
|
|
2680
2685
|
orientationConversationKind: canonicalEvent.chat.isGroup ? "group" : "one_to_one",
|
|
2681
2686
|
publishAcceptedReceipt,
|
|
2687
|
+
...(interaction?.mutationType === "reaction" ? { isReactionSignal: true } : {}),
|
|
2682
2688
|
};
|
|
2683
2689
|
let failedReplyVisible = false;
|
|
2684
2690
|
if (retryFailedReply) {
|
|
@@ -3216,7 +3222,7 @@ async function recoverCapturedBlueBubblesInboundMessages(deps = {}, options = {}
|
|
|
3216
3222
|
status: "ready",
|
|
3217
3223
|
capture,
|
|
3218
3224
|
normalized,
|
|
3219
|
-
observationReservation: reserveBlueBubblesObservation(normalized),
|
|
3225
|
+
observationReservation: seededObservationReservation(capture.keyHash, reserveBlueBubblesObservation(normalized)),
|
|
3220
3226
|
});
|
|
3221
3227
|
}
|
|
3222
3228
|
for (const prepared of preparedCandidates) {
|
|
@@ -3,7 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.BlueBubblesIgnoredEventError = void 0;
|
|
4
4
|
exports.describeBlueBubblesReaction = describeBlueBubblesReaction;
|
|
5
5
|
exports.renderBlueBubblesReactionText = renderBlueBubblesReactionText;
|
|
6
|
+
exports.renderBlueBubblesEditText = renderBlueBubblesEditText;
|
|
6
7
|
exports.normalizeBlueBubblesEvent = normalizeBlueBubblesEvent;
|
|
8
|
+
const chat_interaction_1 = require("../../heart/chat-interaction");
|
|
7
9
|
const runtime_1 = require("../../nerves/runtime");
|
|
8
10
|
const render_1 = require("../../heart/attachments/render");
|
|
9
11
|
const bluebubbles_1 = require("../../heart/attachments/sources/bluebubbles");
|
|
@@ -178,7 +180,6 @@ const REACTION_VOCABULARY = [
|
|
|
178
180
|
{ code: 2005, name: "question", verb: "questioned", noun: "question" },
|
|
179
181
|
{ code: 2006, name: "custom", verb: "reacted with custom emoji to", noun: "custom emoji" },
|
|
180
182
|
];
|
|
181
|
-
const REACTION_EXCERPT_MAX_LENGTH = 80;
|
|
182
183
|
function describeBlueBubblesReaction(raw, rawTransportValue = raw) {
|
|
183
184
|
const stripped = raw.startsWith("-") ? raw.slice(1) : raw;
|
|
184
185
|
const code = /^\d+$/.test(stripped) ? Number(stripped) : undefined;
|
|
@@ -197,36 +198,18 @@ function describeBlueBubblesReaction(raw, rawTransportValue = raw) {
|
|
|
197
198
|
noun: entry.noun,
|
|
198
199
|
};
|
|
199
200
|
}
|
|
200
|
-
function reactionExcerpt(text) {
|
|
201
|
-
return text.length > REACTION_EXCERPT_MAX_LENGTH
|
|
202
|
-
? `${text.slice(0, REACTION_EXCERPT_MAX_LENGTH - 3)}...`
|
|
203
|
-
: text;
|
|
204
|
-
}
|
|
205
|
-
function reactionTargetPhrase(target) {
|
|
206
|
-
const text = target.text?.trim();
|
|
207
|
-
if (text) {
|
|
208
|
-
const owner = target.fromMe === true ? "your" : target.fromMe === false ? "their" : "a";
|
|
209
|
-
return `${owner} message: "${reactionExcerpt(text)}"`;
|
|
210
|
-
}
|
|
211
|
-
// Never hand the agent a bare "reacted with love" stub — say plainly that the
|
|
212
|
-
// referent is missing so it can ask instead of guessing what was approved.
|
|
213
|
-
return target.guid
|
|
214
|
-
? `an unidentified message (target guid ${target.guid}; its text could not be resolved)`
|
|
215
|
-
: "an unidentified message (the reaction carried no target message reference)";
|
|
216
|
-
}
|
|
217
201
|
/**
|
|
218
202
|
* Render a reaction as speech the agent can act on: what the tapback was, whether
|
|
219
203
|
* it was added or removed, and which message it points at.
|
|
220
204
|
*/
|
|
221
205
|
function renderBlueBubblesReactionText(reaction, target) {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
: `reacted with ${reaction.raw} to ${phrase}`;
|
|
206
|
+
return (0, chat_interaction_1.renderChatInteraction)({
|
|
207
|
+
kind: "reaction",
|
|
208
|
+
label: reaction.action === "remove" ? reaction.noun ?? reaction.raw.replace(/^-/, "") : reaction.raw,
|
|
209
|
+
...(reaction.verb ? { verb: reaction.verb } : {}),
|
|
210
|
+
removed: reaction.action === "remove",
|
|
211
|
+
target: { ...(target.guid ? { id: `guid ${target.guid}` } : {}), ...(target.text ? { text: target.text } : {}), ...(typeof target.fromMe === "boolean" ? { fromAgent: target.fromMe } : {}) },
|
|
212
|
+
});
|
|
230
213
|
}
|
|
231
214
|
function stripPartPrefix(guid) {
|
|
232
215
|
if (!guid)
|
|
@@ -235,13 +218,16 @@ function stripPartPrefix(guid) {
|
|
|
235
218
|
const marker = trimmed.lastIndexOf("/");
|
|
236
219
|
return marker >= 0 ? trimmed.slice(marker + 1) : trimmed;
|
|
237
220
|
}
|
|
221
|
+
/** iMessage edits carry only the new text, aimed at the message they replace. */
|
|
222
|
+
function renderBlueBubblesEditText(newText) {
|
|
223
|
+
return (0, chat_interaction_1.renderChatInteraction)({ kind: "edit", newText: newText ?? "", target: {} });
|
|
224
|
+
}
|
|
238
225
|
// Reactions never reach here: `detectMutationType` returns "reaction" only when a
|
|
239
226
|
// reaction name was decoded, and that same name produces the descriptor the caller
|
|
240
227
|
// renders with `renderBlueBubblesReactionText` instead.
|
|
241
228
|
function buildMutationText(mutationType, data) {
|
|
242
229
|
if (mutationType === "edit") {
|
|
243
|
-
|
|
244
|
-
return editedText ? `edited message: ${editedText}` : "edited a message";
|
|
230
|
+
return renderBlueBubblesEditText(readString(data, "text"));
|
|
245
231
|
}
|
|
246
232
|
if (mutationType === "unsend") {
|
|
247
233
|
return "unsent a message";
|
|
@@ -634,6 +634,7 @@ async function runSenseTurnExclusive(options, owner) {
|
|
|
634
634
|
...(options.approvalCoordinatorFactory && !options.disablePersistence ? { approvalCoordinator: options.approvalCoordinatorFactory({ sessionPath: sessPath, baseSessionRevision }) } : {}),
|
|
635
635
|
...(options.latencyMode === "live" ? { skipKeptNotes: true } : {}),
|
|
636
636
|
...(options.orientationFrame ? { orientationFrame: options.orientationFrame } : {}),
|
|
637
|
+
...(options.isReactionSignal ? { isReactionSignal: true } : {}),
|
|
637
638
|
toolContext: {
|
|
638
639
|
signin: async () => undefined,
|
|
639
640
|
...(options.toolContext ? options.toolContext : {}),
|
package/dist/senses/teams.js
CHANGED
|
@@ -39,6 +39,8 @@ exports.stripMentions = stripMentions;
|
|
|
39
39
|
exports.splitMessage = splitMessage;
|
|
40
40
|
exports.sanitizeFeedbackComment = sanitizeFeedbackComment;
|
|
41
41
|
exports.buildFeedbackSyntheticText = buildFeedbackSyntheticText;
|
|
42
|
+
exports.buildReactionSyntheticText = buildReactionSyntheticText;
|
|
43
|
+
exports.buildEditSyntheticText = buildEditSyntheticText;
|
|
42
44
|
exports.buildWelcomeCard = buildWelcomeCard;
|
|
43
45
|
exports.createTeamsCallbacks = createTeamsCallbacks;
|
|
44
46
|
exports.reasoningStatus = reasoningStatus;
|
|
@@ -69,6 +71,7 @@ const context_1 = require("../mind/context");
|
|
|
69
71
|
const commands_1 = require("./commands");
|
|
70
72
|
const nerves_1 = require("../nerves");
|
|
71
73
|
const runtime_1 = require("../nerves/runtime");
|
|
74
|
+
const chat_interaction_1 = require("../heart/chat-interaction");
|
|
72
75
|
const proactive_content_guard_1 = require("./proactive-content-guard");
|
|
73
76
|
const turn_coordinator_1 = require("../heart/turn-coordinator");
|
|
74
77
|
const identity_1 = require("../heart/identity");
|
|
@@ -162,14 +165,23 @@ function sanitizeFeedbackComment(comment) {
|
|
|
162
165
|
const cleaned = comment.replace(/[\x00-\x1f\n\r]/g, "");
|
|
163
166
|
return cleaned.length > 200 ? cleaned.slice(0, 200) : cleaned;
|
|
164
167
|
}
|
|
165
|
-
//
|
|
168
|
+
// Teams names its reactions; the agent reads the emoji the person tapped.
|
|
169
|
+
const TEAMS_REACTION_EMOJI = { like: "👍", dislike: "👎", heart: "❤️", laugh: "😆", surprised: "😮", sad: "😢", angry: "😠" };
|
|
170
|
+
function teamsReaction(type, removed) {
|
|
171
|
+
return (0, chat_interaction_1.renderChatInteraction)({ kind: "reaction", label: TEAMS_REACTION_EMOJI[type] ?? type, removed, target: { fromAgent: true } });
|
|
172
|
+
}
|
|
173
|
+
// Build synthetic message text from a Teams feedback reaction (the thumbs on an AI-labeled reply).
|
|
166
174
|
function buildFeedbackSyntheticText(reaction, comment) {
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
175
|
+
const said = comment ? ` and commented: "${sanitizeFeedbackComment(comment)}"` : "";
|
|
176
|
+
return `[${teamsReaction(reaction === "like" ? "like" : "dislike", false)}${said}]`;
|
|
177
|
+
}
|
|
178
|
+
// Teams only tells a bot about reactions on the bot's own messages, so the target is always the agent's.
|
|
179
|
+
function buildReactionSyntheticText(added, removed) {
|
|
180
|
+
const change = added?.[0] ? { type: added[0].type, removed: false } : removed?.[0] ? { type: removed[0].type, removed: true } : null;
|
|
181
|
+
return change ? `[${teamsReaction(change.type, change.removed)}]` : null;
|
|
182
|
+
}
|
|
183
|
+
function buildEditSyntheticText(newText) {
|
|
184
|
+
return `[${(0, chat_interaction_1.renderChatInteraction)({ kind: "edit", newText, target: { fromAgent: false } })}]`;
|
|
173
185
|
}
|
|
174
186
|
// Build a welcome Adaptive Card with prompt starters for new bot installs.
|
|
175
187
|
function buildWelcomeCard() {
|
|
@@ -1293,19 +1305,12 @@ function registerBotHandlers(app, label) {
|
|
|
1293
1305
|
(0, runtime_1.emitNervesEvent)({ level: "warn", event: "channel.verify_state", component: "channels", message: `[${label}] verify-state failed for all connections`, meta: {} });
|
|
1294
1306
|
return { status: 412 };
|
|
1295
1307
|
}));
|
|
1296
|
-
//
|
|
1297
|
-
//
|
|
1298
|
-
/* v8 ignore start -- Teams SDK
|
|
1299
|
-
|
|
1308
|
+
// Edits, reactions and the thumbs feedback all reach the agent as a turn about an earlier message.
|
|
1309
|
+
// A reaction runs with isReactionSignal: the agent sees it and decides whether to answer.
|
|
1310
|
+
/* v8 ignore start -- Teams SDK activity handlers; require live SDK context @preserve */
|
|
1311
|
+
const runInteractionTurn = async (ctx, syntheticText, isReactionSignal) => {
|
|
1300
1312
|
const { stream, activity } = ctx;
|
|
1301
|
-
const reaction = activity.value?.actionValue?.reaction;
|
|
1302
|
-
const comment = activity.value?.actionValue?.feedback;
|
|
1303
1313
|
const convId = activity.conversation?.id || "unknown";
|
|
1304
|
-
// Validate payload — graceful no-op for malformed invocations
|
|
1305
|
-
if (activity.value?.actionName !== "feedback" || !reaction) {
|
|
1306
|
-
return undefined;
|
|
1307
|
-
}
|
|
1308
|
-
const syntheticText = buildFeedbackSyntheticText(reaction, comment);
|
|
1309
1314
|
await coordinateTeamsTurn(convId, syntheticText, {
|
|
1310
1315
|
aadObjectId: activity.from?.aadObjectId, userId: activity.from?.id,
|
|
1311
1316
|
tenantId: activity.conversation?.tenantId, replyToId: activity.replyToId,
|
|
@@ -1322,13 +1327,34 @@ function registerBotHandlers(app, label) {
|
|
|
1322
1327
|
const ctxSend = async (t) => {
|
|
1323
1328
|
await ctx.send({ type: "message", text: t, replyToId: activity.replyToId, entities: aiLabelEntities(), channelData: { feedbackLoopEnabled: true } });
|
|
1324
1329
|
};
|
|
1325
|
-
await handleTeamsMessage(syntheticText, stream, convId, teamsContext, ctxSend, { isReactionSignal: true, suppressEmptyStreamMessage: true });
|
|
1330
|
+
await handleTeamsMessage(syntheticText, stream, convId, teamsContext, ctxSend, isReactionSignal ? { isReactionSignal: true, suppressEmptyStreamMessage: true } : {});
|
|
1326
1331
|
}
|
|
1327
1332
|
catch (err) {
|
|
1328
1333
|
const msg = err instanceof Error ? err.message : String(err);
|
|
1329
1334
|
(0, runtime_1.emitNervesEvent)({ level: "error", event: "channel.feedback_handler_error", component: "channels", message: msg.slice(0, 200), meta: {} });
|
|
1330
1335
|
}
|
|
1331
1336
|
});
|
|
1337
|
+
};
|
|
1338
|
+
// SDK routes message/submitAction with actionName "feedback" to this event.
|
|
1339
|
+
app.on("message.submit.feedback", async (ctx) => {
|
|
1340
|
+
const reaction = ctx.activity.value?.actionValue?.reaction;
|
|
1341
|
+
// Validate payload — graceful no-op for malformed invocations
|
|
1342
|
+
if (ctx.activity.value?.actionName !== "feedback" || !reaction)
|
|
1343
|
+
return undefined;
|
|
1344
|
+
await runInteractionTurn(ctx, buildFeedbackSyntheticText(reaction, ctx.activity.value?.actionValue?.feedback), true);
|
|
1345
|
+
return undefined;
|
|
1346
|
+
});
|
|
1347
|
+
app.on("messageReaction", async (ctx) => {
|
|
1348
|
+
const text = buildReactionSyntheticText(ctx.activity.reactionsAdded, ctx.activity.reactionsRemoved);
|
|
1349
|
+
if (text)
|
|
1350
|
+
await runInteractionTurn(ctx, text, true);
|
|
1351
|
+
return undefined;
|
|
1352
|
+
});
|
|
1353
|
+
app.on("messageUpdate", async (ctx) => {
|
|
1354
|
+
// Teams also sends an update when a message is undeleted; only an edit carries new words.
|
|
1355
|
+
if (ctx.activity.channelData?.eventType !== "editMessage" || !ctx.activity.text)
|
|
1356
|
+
return undefined;
|
|
1357
|
+
await runInteractionTurn(ctx, buildEditSyntheticText(ctx.activity.text), false);
|
|
1332
1358
|
return undefined;
|
|
1333
1359
|
});
|
|
1334
1360
|
/* v8 ignore stop */
|
|
@@ -4,6 +4,7 @@ exports.createSanctuaryTelegramAuthorityTransport = createSanctuaryTelegramAutho
|
|
|
4
4
|
const node_crypto_1 = require("node:crypto");
|
|
5
5
|
const runtime_1 = require("../nerves/runtime");
|
|
6
6
|
const sanctuary_authority_codec_1 = require("../heart/daemon/sanctuary-authority-codec");
|
|
7
|
+
const telegram_client_1 = require("./telegram-client");
|
|
7
8
|
const root_host_approval_port_1 = require("./root-host-approval-port");
|
|
8
9
|
function isObject(value) {
|
|
9
10
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -14,9 +15,7 @@ function validPollBody(body) {
|
|
|
14
15
|
&& body.offset >= 0
|
|
15
16
|
&& body.timeout === 50
|
|
16
17
|
&& Array.isArray(body.allowed_updates)
|
|
17
|
-
&& body.allowed_updates.
|
|
18
|
-
&& body.allowed_updates[0] === "message"
|
|
19
|
-
&& body.allowed_updates[1] === "callback_query";
|
|
18
|
+
&& body.allowed_updates.join(",") === telegram_client_1.TELEGRAM_ALLOWED_UPDATES.join(",");
|
|
20
19
|
}
|
|
21
20
|
function rawUpdateDigest(update) {
|
|
22
21
|
return `tgu_${(0, node_crypto_1.createHash)("sha256")
|
|
@@ -74,14 +73,14 @@ function verifyObservation(artifact, update, verification) {
|
|
|
74
73
|
throw new Error("Sanctuary Telegram authority observation payload is invalid");
|
|
75
74
|
}
|
|
76
75
|
const callback = update.callback_query;
|
|
77
|
-
const message = update
|
|
78
|
-
if ((!callback && !message) || (callback && message) || (callback && (!callback.message || !callback.from))
|
|
76
|
+
const message = (0, telegram_client_1.telegramUpdateMessageCoordinates)(update);
|
|
77
|
+
if ((!callback && !message) || (callback && message) || (callback && (!callback.message || !callback.from))) {
|
|
79
78
|
throw new Error("Sanctuary Telegram authority observation update is unsupported");
|
|
80
79
|
}
|
|
81
80
|
const updateClass = callback ? "callback" : "message";
|
|
82
|
-
const userId =
|
|
83
|
-
const chatId =
|
|
84
|
-
const messageId =
|
|
81
|
+
const userId = callback ? String(callback.from.id) : message.userId;
|
|
82
|
+
const chatId = callback ? String(callback.message.chat.id) : message.chatId;
|
|
83
|
+
const messageId = callback ? String(callback.message.message_id) : message.messageId;
|
|
85
84
|
const callbackQueryId = callback ? callback.id : null;
|
|
86
85
|
if (payload.updateClass !== updateClass
|
|
87
86
|
|| payload.userId !== userId
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TELEGRAM_APPROVAL_TOMBSTONE_TTL_MS = exports.TELEGRAM_APPROVAL_TERMINAL_EDIT_TIMEOUT_MS = exports.TELEGRAM_APPROVAL_EXPIRED_TEXT = exports.TELEGRAM_APPROVAL_TTL_MS = exports.FileTelegramPendingApprovalStore = exports.FileTelegramUpdateInboxStore = exports.FileTelegramOffsetStore = exports.TelegramApiError = void 0;
|
|
3
|
+
exports.TELEGRAM_APPROVAL_TOMBSTONE_TTL_MS = exports.TELEGRAM_APPROVAL_TERMINAL_EDIT_TIMEOUT_MS = exports.TELEGRAM_APPROVAL_EXPIRED_TEXT = exports.TELEGRAM_APPROVAL_TTL_MS = exports.FileTelegramPendingApprovalStore = exports.FileTelegramUpdateInboxStore = exports.TELEGRAM_ALLOWED_UPDATES = exports.FileTelegramOffsetStore = exports.TelegramApiError = void 0;
|
|
4
|
+
exports.telegramUpdateMessageCoordinates = telegramUpdateMessageCoordinates;
|
|
4
5
|
exports.createTelegramLongPoll = createTelegramLongPoll;
|
|
5
6
|
exports.classifyTelegramPersistedApprovalState = classifyTelegramPersistedApprovalState;
|
|
6
7
|
exports.createTelegramApprovalTransport = createTelegramApprovalTransport;
|
|
@@ -12,6 +13,7 @@ const runtime_1 = require("../nerves/runtime");
|
|
|
12
13
|
const node_fs_1 = require("node:fs");
|
|
13
14
|
const node_crypto_1 = require("node:crypto");
|
|
14
15
|
const atomic_file_1 = require("../heart/atomic-file");
|
|
16
|
+
const chat_interaction_1 = require("../heart/chat-interaction");
|
|
15
17
|
class TelegramApiError extends Error {
|
|
16
18
|
status;
|
|
17
19
|
errorCode;
|
|
@@ -58,6 +60,19 @@ class FileTelegramOffsetStore {
|
|
|
58
60
|
}
|
|
59
61
|
}
|
|
60
62
|
exports.FileTelegramOffsetStore = FileTelegramOffsetStore;
|
|
63
|
+
/** Every update kind the bot asks Telegram for. The authority service, its transport check and the direct poller share it. */
|
|
64
|
+
exports.TELEGRAM_ALLOWED_UPDATES = ["message", "edited_message", "message_reaction", "callback_query"];
|
|
65
|
+
/** The person, chat and message an update is about: a message, an edit of one, or a reaction to one. */
|
|
66
|
+
function telegramUpdateMessageCoordinates(update) {
|
|
67
|
+
const message = update.message ?? update.edited_message;
|
|
68
|
+
const reaction = update.message_reaction;
|
|
69
|
+
const userId = message ? message.from?.id : reaction?.user?.id;
|
|
70
|
+
const chat = message?.chat ?? reaction?.chat;
|
|
71
|
+
const messageId = message ? message.message_id : reaction?.message_id;
|
|
72
|
+
if (!Number.isSafeInteger(userId) || !Number.isSafeInteger(chat?.id) || !Number.isSafeInteger(messageId))
|
|
73
|
+
return null;
|
|
74
|
+
return { userId: String(userId), chatId: String(chat.id), chatType: chat.type, messageId: String(messageId) };
|
|
75
|
+
}
|
|
61
76
|
const DEFAULT_TELEGRAM_INDETERMINATE_RETENTION_MS = 24 * 60 * 60 * 1_000;
|
|
62
77
|
const DEFAULT_TELEGRAM_MAX_INDETERMINATE_RECEIPTS = 1_000;
|
|
63
78
|
// Long-poll retry backoff. A transient failure (a Telegram 5xx, a dropped
|
|
@@ -79,7 +94,7 @@ function updateReceipt(update) {
|
|
|
79
94
|
return {
|
|
80
95
|
digest: `tgu_${(0, node_crypto_1.createHash)("sha256").update(`${TELEGRAM_UPDATE_DIGEST_DOMAIN}\0${JSON.stringify(update)}`, "utf8").digest("base64url")}`,
|
|
81
96
|
sequenceDigest: `tgs_${(0, node_crypto_1.createHash)("sha256").update(`${TELEGRAM_UPDATE_SEQUENCE_DOMAIN}\0${update.update_id}`, "utf8").digest("base64url")}`,
|
|
82
|
-
updateClass: update.callback_query ? "callback" : update
|
|
97
|
+
updateClass: update.callback_query ? "callback" : telegramUpdateMessageCoordinates(update) ? "message" : "other",
|
|
83
98
|
};
|
|
84
99
|
}
|
|
85
100
|
function sameReceipt(left, right) {
|
|
@@ -511,12 +526,36 @@ function createTelegramLongPoll(options) {
|
|
|
511
526
|
const author = reply.from?.is_bot ? "agent" : reply.from && String(reply.from.id) === userId ? "person" : reply.from ? "other" : undefined;
|
|
512
527
|
return { ...(quoted ? { replyToText: quoted.trim() } : {}), ...(author ? { replyToAuthor: author } : {}) };
|
|
513
528
|
};
|
|
529
|
+
const reactionChange = (reaction) => {
|
|
530
|
+
const key = (entry) => `${entry.type}:${entry.emoji ?? entry.custom_emoji_id ?? ""}`;
|
|
531
|
+
const label = (entry) => entry.emoji ?? (entry.type === "custom_emoji" ? "a custom emoji" : entry.type === "paid" ? "a paid star" : entry.type);
|
|
532
|
+
const oldKeys = new Set(reaction.old_reaction.map(key));
|
|
533
|
+
const newKeys = new Set(reaction.new_reaction.map(key));
|
|
534
|
+
const added = reaction.new_reaction.find((entry) => !oldKeys.has(key(entry)));
|
|
535
|
+
if (added)
|
|
536
|
+
return { label: label(added), removed: false };
|
|
537
|
+
const removed = reaction.old_reaction.find((entry) => !newKeys.has(key(entry)));
|
|
538
|
+
return removed ? { label: label(removed), removed: true } : null;
|
|
539
|
+
};
|
|
514
540
|
const authorizedMessage = (update, authority) => {
|
|
515
|
-
const
|
|
516
|
-
|
|
517
|
-
const chatId = message ? String(message.chat.id) : "";
|
|
518
|
-
if (!message || message.chat.type !== "private" || userId !== options.expectedUserId || chatId !== options.expectedChatId)
|
|
541
|
+
const coordinates = telegramUpdateMessageCoordinates(update);
|
|
542
|
+
if (!coordinates || coordinates.chatType !== "private" || coordinates.userId !== options.expectedUserId || coordinates.chatId !== options.expectedChatId)
|
|
519
543
|
return null;
|
|
544
|
+
const { userId, chatId, messageId } = coordinates;
|
|
545
|
+
const base = { updateId: update.update_id, messageId, userId, chatId, ...(authority ? { authority } : {}) };
|
|
546
|
+
if (update.message_reaction) {
|
|
547
|
+
const change = reactionChange(update.message_reaction);
|
|
548
|
+
if (!change)
|
|
549
|
+
return null;
|
|
550
|
+
const interaction = { kind: "reaction", ...change, target: { id: messageId } };
|
|
551
|
+
return { ...base, text: (0, chat_interaction_1.renderChatInteraction)(interaction), interaction, replyToMessageId: messageId };
|
|
552
|
+
}
|
|
553
|
+
if (update.edited_message) {
|
|
554
|
+
const newText = update.edited_message.text ?? update.edited_message.caption ?? "";
|
|
555
|
+
const interaction = { kind: "edit", newText, target: { id: messageId, fromAgent: false } };
|
|
556
|
+
return { ...base, text: (0, chat_interaction_1.renderChatInteraction)(interaction), interaction };
|
|
557
|
+
}
|
|
558
|
+
const message = update.message;
|
|
520
559
|
const attachments = inboundAttachments(message);
|
|
521
560
|
const attachmentCount = rawAttachmentCount(message);
|
|
522
561
|
const attachmentNotices = attachmentCount > attachments.length
|
|
@@ -526,17 +565,13 @@ function createTelegramLongPoll(options) {
|
|
|
526
565
|
if (typeof text !== "string" || (!text && attachmentCount === 0))
|
|
527
566
|
return null;
|
|
528
567
|
return {
|
|
529
|
-
|
|
530
|
-
messageId: String(message.message_id),
|
|
531
|
-
userId,
|
|
532
|
-
chatId,
|
|
568
|
+
...base,
|
|
533
569
|
text,
|
|
534
570
|
attachments,
|
|
535
571
|
...(attachmentNotices.length ? { attachmentNotices } : {}),
|
|
536
572
|
...(Number.isSafeInteger(message.reply_to_message?.message_id) && message.reply_to_message.message_id > 0
|
|
537
573
|
? { replyToMessageId: String(message.reply_to_message.message_id), ...repliedTo(message, userId) }
|
|
538
574
|
: {}),
|
|
539
|
-
...(authority ? { authority } : {}),
|
|
540
575
|
};
|
|
541
576
|
};
|
|
542
577
|
const unknownMessage = (update, authority) => {
|
|
@@ -621,7 +656,7 @@ function createTelegramLongPoll(options) {
|
|
|
621
656
|
const updates = await options.api.request("getUpdates", {
|
|
622
657
|
offset: nextUpdateId,
|
|
623
658
|
timeout: 50,
|
|
624
|
-
allowed_updates: [
|
|
659
|
+
allowed_updates: [...exports.TELEGRAM_ALLOWED_UPDATES],
|
|
625
660
|
}, requestSignal);
|
|
626
661
|
if (!Array.isArray(updates))
|
|
627
662
|
throw new Error("Telegram getUpdates result must be an array");
|
package/dist/senses/telegram.js
CHANGED
|
@@ -67,6 +67,7 @@ const sanctuary_house_1 = require("./sanctuary-house");
|
|
|
67
67
|
const sanctuary_acceptance_marker_1 = require("../heart/daemon/sanctuary-acceptance-marker");
|
|
68
68
|
const runtime_credentials_1 = require("../heart/runtime-credentials");
|
|
69
69
|
const runtime_1 = require("../nerves/runtime");
|
|
70
|
+
const chat_interaction_1 = require("../heart/chat-interaction");
|
|
70
71
|
const nerves_1 = require("../nerves");
|
|
71
72
|
const sanctuary_interactive_control_1 = require("./sanctuary-interactive-control");
|
|
72
73
|
const sanctuary_runtime_1 = require("./sanctuary-runtime");
|
|
@@ -1506,6 +1507,7 @@ function createTelegramSenseApp(options) {
|
|
|
1506
1507
|
},
|
|
1507
1508
|
userMessage: message.text,
|
|
1508
1509
|
ingressRelations,
|
|
1510
|
+
...(message.interaction?.kind === "reaction" ? { isReactionSignal: true } : {}),
|
|
1509
1511
|
...(message.replyToText ? { replyingTo: { text: message.replyToText, ...(message.replyToAuthor ? { author: message.replyToAuthor } : {}) } } : {}),
|
|
1510
1512
|
...(ingressReceipt ? { precommittedIngress: ingressReceipt } : {}),
|
|
1511
1513
|
turnMetricsObserver,
|
|
@@ -1641,8 +1643,20 @@ function createTelegramSenseApp(options) {
|
|
|
1641
1643
|
}
|
|
1642
1644
|
}
|
|
1643
1645
|
};
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
+
// Telegram tells the bot which message was reacted to, not what it said. The journal knows the agent's own messages.
|
|
1647
|
+
const nameReactionTarget = (message) => {
|
|
1648
|
+
const interaction = message.interaction;
|
|
1649
|
+
if (interaction?.kind !== "reaction" || !interaction.target.id)
|
|
1650
|
+
return message;
|
|
1651
|
+
const sent = (0, telegram_effect_adapter_1.resolveTelegramReply)(getEffectJournal(), { messageId: Number(interaction.target.id), friendId: configuredOwnerFriendId, sessionKey: configuredOwnerSessionKey });
|
|
1652
|
+
if (!sent?.text)
|
|
1653
|
+
return message;
|
|
1654
|
+
const named = { ...interaction, target: { ...interaction.target, text: sent.text, fromAgent: true } };
|
|
1655
|
+
return { ...message, interaction: named, text: (0, chat_interaction_1.renderChatInteraction)(named) };
|
|
1656
|
+
};
|
|
1657
|
+
const onMessage = (inbound) => runWithAcceptanceAuditOwner(async () => {
|
|
1658
|
+
const message = nameReactionTarget(inbound);
|
|
1659
|
+
const ownerDecision = !message.interaction && !message.attachments?.length && !message.attachmentNotices?.length ? admissionController?.parseOwnerDecision({
|
|
1646
1660
|
text: message.text,
|
|
1647
1661
|
...(message.replyToMessageId ? { replyToMessageId: Number(message.replyToMessageId) } : {}),
|
|
1648
1662
|
}) : null;
|
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.1119",
|
|
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.1119",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@anthropic-ai/sdk": "^0.78.0",
|
|
12
12
|
"@ouro.bot/friends": "0.1.0-alpha.18",
|
package/package.json
CHANGED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.classifyBlueBubblesReaction = classifyBlueBubblesReaction;
|
|
4
|
-
const runtime_1 = require("../../nerves/runtime");
|
|
5
|
-
const POSITIVE_REACTIONS = new Set([
|
|
6
|
-
"love",
|
|
7
|
-
"like",
|
|
8
|
-
"laugh",
|
|
9
|
-
"emphasize",
|
|
10
|
-
]);
|
|
11
|
-
function classifyBlueBubblesReaction(input) {
|
|
12
|
-
let decision;
|
|
13
|
-
if (input.fromMe) {
|
|
14
|
-
decision = { route: "capture_only", outcome: "ignored_self" };
|
|
15
|
-
}
|
|
16
|
-
else if (input.action === "remove") {
|
|
17
|
-
decision = { route: "capture_only", outcome: "capture_only_removal" };
|
|
18
|
-
}
|
|
19
|
-
else if (POSITIVE_REACTIONS.has(input.canonicalValue)) {
|
|
20
|
-
decision = { route: "capture_only", outcome: "capture_only_positive" };
|
|
21
|
-
}
|
|
22
|
-
else if (input.canonicalValue === "custom") {
|
|
23
|
-
decision = { route: "capture_only", outcome: "capture_only_custom" };
|
|
24
|
-
}
|
|
25
|
-
else if (input.canonicalValue === "unknown") {
|
|
26
|
-
decision = { route: "capture_only", outcome: "capture_only_unknown" };
|
|
27
|
-
}
|
|
28
|
-
else if (input.canonicalValue === "question") {
|
|
29
|
-
decision = { route: "capture_only", outcome: "capture_only_question" };
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
decision = { route: "capture_only", outcome: "capture_only_negative" };
|
|
33
|
-
}
|
|
34
|
-
(0, runtime_1.emitNervesEvent)({
|
|
35
|
-
component: "senses",
|
|
36
|
-
event: "senses.bluebubbles_reaction_policy_evaluated",
|
|
37
|
-
message: "evaluated bluebubbles reaction routing policy",
|
|
38
|
-
meta: {
|
|
39
|
-
action: input.action,
|
|
40
|
-
canonicalValue: input.canonicalValue,
|
|
41
|
-
fromMe: input.fromMe,
|
|
42
|
-
route: decision.route,
|
|
43
|
-
outcome: decision.outcome,
|
|
44
|
-
},
|
|
45
|
-
});
|
|
46
|
-
return decision;
|
|
47
|
-
}
|