@operad-io/telegram 0.3.1 → 0.4.0

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.
Files changed (2) hide show
  1. package/package.json +5 -5
  2. package/src/replies.ts +27 -2
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@operad-io/telegram",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./src/index.ts"
7
7
  },
8
8
  "dependencies": {
9
- "@operad-io/chat": "0.3.1",
10
- "@operad-io/engine": "0.3.1"
9
+ "@operad-io/chat": "0.4.0",
10
+ "@operad-io/engine": "0.4.0"
11
11
  },
12
12
  "description": "operad: the Telegram plugin, a channel and an outside source",
13
13
  "repository": {
@@ -23,7 +23,7 @@
23
23
  "LICENSE"
24
24
  ],
25
25
  "devDependencies": {
26
- "@operad-io/bot": "0.3.1",
27
- "@operad-io/dev": "0.3.1"
26
+ "@operad-io/bot": "0.4.0",
27
+ "@operad-io/dev": "0.4.0"
28
28
  }
29
29
  }
package/src/replies.ts CHANGED
@@ -15,7 +15,7 @@
15
15
  * the tool calls (ADR 0033 D7).
16
16
  */
17
17
 
18
- import { CHAT_TYPE, allEntries, allMessages, chatData } from "@operad-io/chat";
18
+ import { CHAT_TYPE, PRIVATE_FACT, PRIVATE_OFF_LINE, PRIVATE_ON_LINE, allEntries, allMessages, chatData, chatFacts, deliveryHeader, memoryWroteLine } from "@operad-io/chat";
19
19
  import { messageOf, type SourceContext } from "@operad-io/engine";
20
20
  import { BotApiError, type BotApi } from "./api.ts";
21
21
  import { TelegramEvents, type TelegramEvent } from "./events.ts";
@@ -182,14 +182,39 @@ export class ReplySender {
182
182
  if (target === undefined) return;
183
183
  const outgoing: Outgoing[] = [];
184
184
  for (const message of allMessages(this.ctx.store, chatId)) {
185
+ if (message.role === "delivery" && message.delivery !== undefined) {
186
+ // A routine's result: its header first, so it reads apart from conversation.
187
+ outgoing.push({ id: message.id, at: message.at, sequence: message.sequence, text: `**${deliveryHeader(message.delivery)}**\n\n${message.text}` });
188
+ continue;
189
+ }
190
+ if (message.role === "recap") {
191
+ // The recap on return goes as one message of its own.
192
+ outgoing.push({ id: message.id, at: message.at, sequence: message.sequence, text: message.text });
193
+ continue;
194
+ }
185
195
  if (message.role !== "assistant") continue;
186
- outgoing.push({ id: message.id, at: message.at, sequence: message.sequence, text: message.text });
196
+ // Only the line of what the reply saved to memory follows the answer; what it used stays in the transcript.
197
+ const saved = memoryWroteLine(message.memory);
198
+ outgoing.push({ id: message.id, at: message.at, sequence: message.sequence, text: saved === undefined ? message.text : `${message.text}\n\n${saved}` });
187
199
  }
188
200
  // A failed reply has no assistant message; its one failure entry is sent too.
189
201
  for (const entry of allEntries(this.ctx.store, chatId)) {
190
202
  if (entry.kind !== "failure" || entry.text === undefined) continue;
191
203
  outgoing.push({ id: `failure:${entry.sequence}`, at: entry.at, sequence: entry.sequence, text: entry.text });
192
204
  }
205
+ // A stretch that is not remembered starts and ends with a line. One turned on
206
+ // or off from Telegram is answered there as a command is, so only another client's is sent.
207
+ for (const fact of chatFacts(this.ctx.store, chatId)) {
208
+ if (fact.type !== PRIVATE_FACT) continue;
209
+ const by = fact.data.by;
210
+ if (typeof by === "object" && by !== null && "via" in by && by.via === TELEGRAM_SOURCE) continue;
211
+ outgoing.push({
212
+ id: `private:${fact.sequence}`,
213
+ at: fact.at,
214
+ sequence: fact.sequence,
215
+ text: fact.data.on === true ? PRIVATE_ON_LINE : PRIVATE_OFF_LINE,
216
+ });
217
+ }
193
218
  outgoing.sort((left, right) => left.sequence - right.sequence);
194
219
  for (const item of outgoing) {
195
220
  if (this.stopped) return;