@ours.network/tg-connector 0.4.0 → 0.5.1-nightly.1

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 (96) hide show
  1. package/README.md +55 -128
  2. package/dist/cli.js +91 -117
  3. package/dist/connector.js +1511 -2487
  4. package/docs/voice-message-contract.md +8 -2
  5. package/package.json +4 -5
  6. package/dist/mufl_code/ED9CAFA60E1A0884E2CBC8E71BA8A137488A14763C57587D25AEC4BAD7F58C81.muflo +0 -0
  7. package/dist/mufl_code/actor.mu +0 -1937
  8. package/dist/mufl_code/config.mufl +0 -27
  9. package/dist/mufl_code/core/COMMERCIAL-LICENCE.md +0 -25
  10. package/dist/mufl_code/core/COMPATIBILITY.md +0 -221
  11. package/dist/mufl_code/core/CONTRIBUTING.md +0 -37
  12. package/dist/mufl_code/core/LICENSE +0 -98
  13. package/dist/mufl_code/core/NOTIFICATIONS_CONTRACT.md +0 -290
  14. package/dist/mufl_code/core/README.md +0 -91
  15. package/dist/mufl_code/core/SECURITY.md +0 -40
  16. package/dist/mufl_code/core/TRADEMARKS.md +0 -24
  17. package/dist/mufl_code/core/a2a_capabilities.mm +0 -449
  18. package/dist/mufl_code/core/a2a_cluster.mm +0 -601
  19. package/dist/mufl_code/core/a2a_control.mm +0 -90
  20. package/dist/mufl_code/core/a2a_messaging.mm +0 -4817
  21. package/dist/mufl_code/core/a2a_monitoring.mm +0 -94
  22. package/dist/mufl_code/core/a2a_notification_integration.mm +0 -144
  23. package/dist/mufl_code/core/a2a_notifications.mm +0 -1127
  24. package/dist/mufl_code/core/a2a_protocol.mm +0 -246
  25. package/dist/mufl_code/core/a2a_versions.mm +0 -801
  26. package/dist/mufl_code/core/config.mufl +0 -29
  27. package/dist/mufl_code/core/docs/.vitepress/config.mts +0 -58
  28. package/dist/mufl_code/core/docs/citations.json +0 -688
  29. package/dist/mufl_code/core/docs/guide/01-vendor-the-core.md +0 -50
  30. package/dist/mufl_code/core/docs/guide/02-configure-and-compile.md +0 -100
  31. package/dist/mufl_code/core/docs/guide/03-wire-the-host.md +0 -154
  32. package/dist/mufl_code/core/docs/guide/04-connect-and-message.md +0 -156
  33. package/dist/mufl_code/core/docs/guide/05-test-your-app.md +0 -75
  34. package/dist/mufl_code/core/docs/guide/index.md +0 -63
  35. package/dist/mufl_code/core/docs/how-it-works/capabilities-and-control.md +0 -77
  36. package/dist/mufl_code/core/docs/how-it-works/cluster.md +0 -65
  37. package/dist/mufl_code/core/docs/how-it-works/identity.md +0 -56
  38. package/dist/mufl_code/core/docs/how-it-works/invites-and-contacts.md +0 -76
  39. package/dist/mufl_code/core/docs/how-it-works/messaging.md +0 -55
  40. package/dist/mufl_code/core/docs/how-it-works/monitoring-and-config.md +0 -72
  41. package/dist/mufl_code/core/docs/how-it-works/overview.md +0 -45
  42. package/dist/mufl_code/core/docs/how-it-works/versioning.md +0 -116
  43. package/dist/mufl_code/core/docs/index.md +0 -27
  44. package/dist/mufl_code/core/docs/package-lock.json +0 -3467
  45. package/dist/mufl_code/core/docs/package.json +0 -15
  46. package/dist/mufl_code/core/docs/reference/contributing.md +0 -26
  47. package/dist/mufl_code/core/docs/reference/glossary.md +0 -108
  48. package/dist/mufl_code/core/docs/reference/implementations.md +0 -23
  49. package/dist/mufl_code/core/docs/reference/modules.md +0 -19
  50. package/dist/mufl_code/core/docs/scripts/check-citations.mjs +0 -36
  51. package/dist/mufl_code/core/docs/scripts/check-denylist.mjs +0 -30
  52. package/dist/mufl_code/core/docs/scripts/gen-llms.mjs +0 -32
  53. package/dist/mufl_code/core/docs/workflows/cluster.md +0 -89
  54. package/dist/mufl_code/core/docs/workflows/contact-exchange.md +0 -60
  55. package/dist/mufl_code/core/docs/workflows/contact-restore.md +0 -60
  56. package/dist/mufl_code/core/docs/workflows/control-verbs.md +0 -70
  57. package/dist/mufl_code/core/docs/workflows/index.md +0 -57
  58. package/dist/mufl_code/core/docs/workflows/introductions.md +0 -60
  59. package/dist/mufl_code/core/docs/workflows/messaging.md +0 -75
  60. package/dist/mufl_code/core/docs/workflows/monitoring.md +0 -84
  61. package/dist/mufl_code/core/docs/workflows/notifications.md +0 -109
  62. package/dist/mufl_code/core/release-notes/0.1.md +0 -60
  63. package/dist/mufl_code/core/release-notes/0.3.md +0 -22
  64. package/dist/mufl_code/core/release-notes/0.4.md +0 -97
  65. package/dist/mufl_code/core/tests/README.md +0 -83
  66. package/dist/mufl_code/core/tests/compat/README.md +0 -82
  67. package/dist/mufl_code/core/tests/compat/compat.mjs +0 -245
  68. package/dist/mufl_code/core/tests/compat/compat_peer.mjs +0 -146
  69. package/dist/mufl_code/core/tests/compat/run_compat.sh +0 -96
  70. package/dist/mufl_code/core/tests/corpus.mjs +0 -139
  71. package/dist/mufl_code/core/tests/corpus_actor.mu +0 -242
  72. package/dist/mufl_code/core/tests/fatcompile_actor.mu +0 -52
  73. package/dist/mufl_code/core/tests/mig.mjs +0 -805
  74. package/dist/mufl_code/core/tests/mig_actor.mu +0 -518
  75. package/dist/mufl_code/core/tests/migapp.mjs +0 -431
  76. package/dist/mufl_code/core/tests/migapp_actor.mu +0 -294
  77. package/dist/mufl_code/core/tests/mufl_semantics/run.sh +0 -69
  78. package/dist/mufl_code/core/tests/mufl_semantics/t11_three_version.mufl +0 -47
  79. package/dist/mufl_code/core/tests/mufl_semantics/t2_extra_fields.mufl +0 -11
  80. package/dist/mufl_code/core/tests/mufl_semantics/t7_runtime.mufl +0 -30
  81. package/dist/mufl_code/core/tests/mufl_semantics/t9_passthrough.mufl +0 -19
  82. package/dist/mufl_code/core/tests/mufl_semantics/t_str_order.mufl +0 -19
  83. package/dist/mufl_code/core/tests/notif.mjs +0 -755
  84. package/dist/mufl_code/core/tests/notif_actor.mu +0 -450
  85. package/dist/mufl_code/core/tests/protocol_container.mm +0 -18
  86. package/dist/mufl_code/core/tests/run.sh +0 -65
  87. package/dist/mufl_code/core/tests/run_corpus.sh +0 -51
  88. package/dist/mufl_code/core/tests/run_fatcompile.sh +0 -40
  89. package/dist/mufl_code/core/tests/run_mig.sh +0 -51
  90. package/dist/mufl_code/core/tests/run_migapp.sh +0 -51
  91. package/dist/mufl_code/core/tests/run_notif.sh +0 -57
  92. package/dist/mufl_code/core/tests/test.mjs +0 -750
  93. package/dist/mufl_code/core/tests/test_actor.mu +0 -564
  94. package/dist/mufl_code/core/tests/test_common.mjs +0 -93
  95. package/dist/mufl_code/core/version.mm +0 -24
  96. package/dist/mufl_code/protocol_container.mm +0 -18
package/README.md CHANGED
@@ -12,7 +12,7 @@ loop.
12
12
  chat B ─┤ Telegram │ (demux by chat-key) │
13
13
  topic#7 ┘ └──┬──────────┬──────────┬───────┘
14
14
  ▼ ▼ ▼
15
- identity A identity B identity C ← one packet per chat-key
15
+ identity A identity B identity C ← daemon identity per chat-key
16
16
  │ │ │ send_message
17
17
  ▼ ▼ ▼
18
18
  Agent X Agent X Agent Y ← same agent can serve many
@@ -24,7 +24,7 @@ Two layers:
24
24
  (`add_bot`). One token == one `getUpdates` poll loop (Telegram allows only one
25
25
  consumer per token). The loop demultiplexes each update to a route by **chat-key**
26
26
  (`chatId`, or `chatId:threadId` for a forum topic).
27
- - **Route** — one self-sovereign ADAPT identity (a packet) pinned to one chat-key,
27
+ - **Route** — one ours identity in the shared daemon pinned to one chat-key,
28
28
  bridged to one proxy agent. A route **references its bot by name**, so the token
29
29
  lives in exactly one place; many routes share a bot. The invite a route emits is
30
30
  byte-compatible with the ours `add_contact` tool.
@@ -47,7 +47,7 @@ customers; escalate refunds to a human").
47
47
  context). The connector mints a fresh identity, sets its name + bio, and prints
48
48
  an **invite blob**.
49
49
  3. You paste that blob into your proxy agent via its `add_contact`. The connector
50
- packet — already live on the broker — completes the encrypted-channel handshake.
50
+ route identity — already live through the daemon — completes the encrypted-channel handshake.
51
51
  4. From then on:
52
52
  - every message in that chat/topic is forwarded to its agent as a JSON
53
53
  **message envelope** (sender + chat metadata, reply/forward context, and any
@@ -67,11 +67,13 @@ both modes; Telegram voice notes retain the protocol MIME marker
67
67
  `audio/ogg; x-ours-kind=voice-message`, allowing the receiving daemon to invoke
68
68
  its native voice-transcription path even when no companion text is sent.
69
69
 
70
- Messages are end-to-end encrypted between the connector packet and the agent (ADAPT
70
+ Messages are end-to-end encrypted between the connector's route identity and the agent (ADAPT
71
71
  encrypted channels). The connector never persists message bodies to disk — only the
72
- bot registry (`bot name`, `token`, `@username`), the per-route seed + serialized
73
- packet state, and the route's Telegram side (`bot name`, `chat id`, `thread id`,
74
- `bio`, `peer cid`).
72
+ bot registry (`bot name`, `token`, `@username`) and route metadata (`bot name`,
73
+ `chat id`, `thread id`, `bio`, `peer cid`, and stable daemon lease). Those
74
+ persisted route names are also the connector's simple list of identities it
75
+ created. The list is organizational bookkeeping, not an authorization or
76
+ provenance boundary; identity keys and packet state stay in the shared daemon.
75
77
 
76
78
  ### Routing rules
77
79
 
@@ -109,85 +111,6 @@ In a **privacy-mode** group only the `/id@<bot_username>` form is delivered (see
109
111
  note above); in DMs and privacy-off groups bare `/id` works too. In a group with
110
112
  several bots, only the one named in `/id@<bot_username>` answers.
111
113
 
112
- ### Reply threading
113
-
114
- An agent's answer can arrive in Telegram **as a reply to the message that prompted
115
- it**, so a busy group chat stays readable. The mechanism is one mapping:
116
-
117
- 1. an inbound Telegram message is sent to the agent as ours `wire_id` **W**, and the
118
- route records `W → (chat id, message id)` in `messages.json` in its state dir;
119
- 2. the agent answers with `reply_to_wire_id = W` (the `send_message` tool already
120
- supports it);
121
- 3. the connector resolves **W** back to that Telegram message and sends with
122
- `reply_parameters.message_id`.
123
-
124
- **It only works when the agent fills `reply_to_wire_id`.** An agent that does not
125
- gets ordinary un-threaded messages — that is a property of the sender, not a
126
- connector fault, so it is worth putting in the persona of any role that writes to
127
- Telegram. If a pointer resolves to nothing (never mapped, or older than the 30-day
128
- retention below) the message is delivered **plain**; a "similar" or most-recent
129
- message is never substituted.
130
-
131
- The map is persistent (it survives a daemon restart), holds **no message content** —
132
- only chat/message ids, the contact id and the receipt state — and is pruned at
133
- **30 days** / 2000 rows per route, oldest first.
134
-
135
- ### Delivery & read receipts as reactions
136
-
137
- When the agent's node confirms a message, the connector puts a **reaction** on the
138
- originating Telegram message: 👀 when it was **delivered**, then 👌 once the agent
139
- has **read** it (its `get` path). Because a bot may hold **at most one reaction per
140
- message**, read *replaces* delivered rather than sitting beside it.
141
-
142
- The confirmations themselves are core 0.7.0 receipts, not something the connector
143
- invents: emission is gated on both sides' `core.receipts.*` capabilities (the
144
- connector declares `emit` and `receive`), and application is **monotonic** per
145
- (peer, message) over `unknown < sent < delivered < read` — a duplicate or
146
- out-of-order receipt changes nothing. Receipts are **best-effort UX**: a missing
147
- reaction does **not** mean the message failed to arrive, and a Telegram refusal on a
148
- reaction (reactions disabled in the chat, message deleted) is logged and never
149
- affects message delivery.
150
-
151
- > **The agent side has to emit them.** A peer only sends receipts if *it* advertises
152
- > `core.receipts.emit`. Against an agent node that does not, the reactions simply
153
- > never appear — everything else keeps working.
154
-
155
- Per **connection** (not per bot — `/receipts off` on one route leaves the others
156
- alone), in the route's own chat:
157
-
158
- ```
159
- /receipts on # turn delivery/read reactions on for this connection
160
- /receipts off # …and off
161
- /receipts status # show the current setting and emoji
162
- /emoji delivered <e> # set the "delivered" reaction
163
- /emoji read <e> # set the "read" reaction
164
- /emoji reset # back to 👀 / 👌
165
- ```
166
-
167
- Commands are parsed **in connector code**, never passed to the agent, and are
168
- answered in the chat. An emoji is validated against Telegram's fixed
169
- bot-reaction list **before** it is saved, with the valid set in the error —
170
- note that ✅ is *not* on that list, which is why the `read` default is 👌.
171
-
172
- ### Message formatting
173
-
174
- Formatting is preserved **in both directions**.
175
-
176
- - **Telegram → agent.** A message's `entities` / `caption_entities` (bold, italic,
177
- underline, strikethrough, spoiler, code, `pre` with its language, blockquote,
178
- links and mentions) are folded into **Markdown** in the message text, so the
179
- agent reads the formatting instead of losing it. Offsets are UTF-16 code units
180
- and are treated as such. A `custom_emoji` is premium-only and degrades to the
181
- stand-in glyph Telegram already put in the text. A message with no entities is
182
- passed through byte-for-byte.
183
- - **Agent → Telegram.** The agent's Markdown is rendered as `MarkdownV2`, escaping
184
- the **text leaves only** (all 18 reserved characters — one unescaped `.` would
185
- fail the whole send). Emphasis is deliberately conservative: `foo_bar_baz` and
186
- `2*3*4` stay literal. The 4096-character limit is applied to the **escaped**
187
- text. **If Telegram rejects the markup, the same text is resent with no
188
- `parse_mode`** and the original refusal is logged — the message always wins over
189
- its styling.
190
-
191
114
  ### Message envelope
192
115
 
193
116
  Each inbound Telegram message is forwarded to the agent as a single **JSON
@@ -242,7 +165,7 @@ distinct from `send_message`, so files and text are always separate messages.
242
165
  read files from the file channel and correlate by `attachment.wire_id`** — an
243
166
  agent that still expects inline base64 will not see the bytes.
244
167
  - **Outbound (agent → Telegram).** A file the agent sends arrives via
245
- `receive_file`, is stored in the packet's file inbox (same unread → processed →
168
+ `receive_file`, is stored in the daemon identity's file inbox (same unread → processed →
246
169
  gc lifecycle as messages, bytes included), and is delivered to the chat (and
247
170
  forum topic, if pinned) with Telegram **`sendDocument`** — preserving the
248
171
  original filename. Agent → Telegram file sending was previously unsupported.
@@ -279,8 +202,15 @@ added for provenance:
279
202
  }
280
203
  ```
281
204
 
282
- - **Opt-in.** Off by default (`sttEnabled:false`) — behaviour is then byte-identical
283
- to today. Turn it on and supply a key (see [Configuration](#configuration)).
205
+ - **Opt-in, and it covers THIS PROCESS ONLY.** Off by default
206
+ (`sttEnabled:false`), which means *the connector* sends no audio to a
207
+ speech-to-text provider. It does **not** mean the audio is never transcribed:
208
+ the connector is a client of an ours daemon, and **the daemon runs its own
209
+ speech-to-text** when the receiving side pulls a voice note — under
210
+ configuration this connector's operator does not control and may not know
211
+ exists. When the connector was its own host, `sttEnabled:false` did cover the
212
+ whole path; attached, it no longer can. Turn it on and supply a key to
213
+ transcribe here as well (see [Configuration](#configuration)).
284
214
  - **No transcoding.** Telegram voice is **OGG/Opus**, which OpenAI-compatible
285
215
  transcription endpoints accept directly — the connector adds **no ffmpeg** and no
286
216
  new dependency (just built-in `fetch`).
@@ -334,9 +264,11 @@ npm install
334
264
  npm run build
335
265
  ```
336
266
 
337
- Requires Node ≥ 20. The native ADAPT SDK (`@adapt-toolkit/sdk` +
338
- `@adapt-toolkit/sdk-native`, pinned to the version matching the shipped
339
- `.muflo`) is resolved from `node_modules` at runtime.
267
+ Requires Node ≥ 20, and **an ours daemon already running on this box** — the
268
+ connector attaches to it over `/api/v1` and drives it through
269
+ [`@ours.network/sdk`](https://www.npmjs.com/package/@ours.network/sdk). It runs
270
+ no engine of its own: there is no native ADAPT SDK and no MUFL packet here, so
271
+ nothing beyond `npm install` is resolved at runtime.
340
272
 
341
273
  ## Usage
342
274
 
@@ -349,7 +281,8 @@ ours-tg-connector add_bot supportbot 123456:ABC...
349
281
 
350
282
  ours-tg-connector list_bots # name, @username, masked token, route count
351
283
 
352
- # 2. create a route on that bot (auto-starts the daemon if needed) and print an invite
284
+ # 2. create a route on that bot (auto-starts the connector process if needed;
285
+ # the shared ours daemon must already be running) and print an invite
353
286
  ours-tg-connector add_new_connection \
354
287
  --name support \
355
288
  --bot supportbot \
@@ -366,10 +299,10 @@ ours-tg-connector add_new_connection \
366
299
  --bio "ACME forum, #billing topic"
367
300
 
368
301
  ours-tg-connector list_connections # routes grouped by bot
369
- ours-tg-connector remove_connection sales
302
+ ours-tg-connector remove_connection sales # removes the route and its name-listed daemon identity
370
303
  ours-tg-connector remove_bot supportbot # refused while any route still uses it
371
304
 
372
- # daemon lifecycle
305
+ # connector-process lifecycle (never starts or stops the shared ours daemon)
373
306
  ours-tg-connector start | stop | restart | status
374
307
  ours-tg-connector serve # foreground (debugging)
375
308
 
@@ -377,9 +310,6 @@ ours-tg-connector serve # foreground (debugging)
377
310
  ours-tg-connector install-service # systemd (Linux) / launchd (macOS)
378
311
  ours-tg-connector uninstall-service
379
312
 
380
- # manage a bridge from the ours messenger control plane
381
- ours-tg-connector cp_invite supportbot # invite to add the messenger as a contact
382
- ours-tg-connector bind_proxy supportbot <contact> # start binding it (prints a 6-digit code)
383
313
  ```
384
314
 
385
315
  `install-service` registers a **user-level** service running `serve`, bakes the
@@ -402,6 +332,13 @@ topic within that chat. `--bio` is the context the agent reads about this chat
402
332
  route for any chat the bot sees that no other route claims. Reuse the same `--bot`
403
333
  across routes to multiplex one bot over many chats/topics.
404
334
 
335
+ `remove_connection` releases that route's daemon lease, then removes the daemon
336
+ identity by its recorded route name and deletes the local route record. Because
337
+ the ownership list is intentionally name-only, an operator who manually removes
338
+ and recreates a same-name identity has deliberately replaced it; removing the
339
+ route can remove that replacement too. Use the `ours` operator CLI to repair
340
+ orphaned or deliberately replaced identities.
341
+
405
342
  ## Configuration
406
343
 
407
344
  Precedence per field: **env var > `config.json` > default**. The config file is
@@ -409,7 +346,8 @@ Precedence per field: **env var > `config.json` > default**. The config file is
409
346
 
410
347
  | field | env var | default |
411
348
  |----------------|---------------------------|-------------------------------------------------|
412
- | broker URL | `OURS_TG_BROKER_URL` | `wss://broker1.ours.network` |
349
+ | daemon URL | `OURS_TG_DAEMON_URL` | `''` (the SDK's own default selection) |
350
+ | daemon state dir | `OURS_TG_DAEMON_STATE_DIR` | `''` (the SDK's own default selection) |
413
351
  | control port | `OURS_TG_CONTROL_PORT` | `3051` (localhost only) |
414
352
  | state dir | `OURS_TG_STATE_DIR` | `~/.ours-telegram` |
415
353
  | poll timeout | `OURS_TG_POLL_TIMEOUT` | `30` (seconds, Telegram long-poll) |
@@ -419,7 +357,7 @@ Precedence per field: **env var > `config.json` > default**. The config file is
419
357
  | retry backoff | `OURS_TG_FETCH_RETRY_BASE_MS` | `300` (base delay between those retries; grows exponentially with jitter) |
420
358
  | attachment cap | `OURS_TG_ATTACHMENT_MAX_BYTES` | `10485760` (10 MB; larger inbound media forwarded as a metadata-only stub) |
421
359
  | outbound file cap | `OURS_TG_OUTBOUND_FILE_MAX_BYTES` | `52428800` (50 MB; a larger file from a contact is skipped + logged — Telegram's `sendDocument` limit) |
422
- | STT enabled | `OURS_TG_STT_ENABLED` | `false` (master switch for voice transcription; off ⇒ byte-identical to today) |
360
+ | STT enabled | `OURS_TG_STT_ENABLED` | `false` (whether **this connector** transcribes voice; the attached daemon runs its own STT regardless — see [Voice](#voice-messages--speech-to-text)) |
423
361
  | STT API key | `OURS_TG_STT_API_KEY` | `''` (secret; env preferred — masked if placed in `config.json`, never logged) |
424
362
  | STT base URL | `OURS_TG_STT_BASE_URL` | `https://api.openai.com/v1` (OpenAI-compatible endpoint root; e.g. `https://api.groq.com/openai/v1` or a self-hosted whisper server) |
425
363
  | STT model | `OURS_TG_STT_MODEL` | `whisper-1` (e.g. `whisper-large-v3-turbo` on Groq) |
@@ -429,39 +367,28 @@ Precedence per field: **env var > `config.json` > default**. The config file is
429
367
  | STT timeout | `OURS_TG_STT_TIMEOUT_MS` | `60000` (per-transcription abort deadline, ms) |
430
368
  | forward voice audio | `OURS_TG_FORWARD_VOICE_AUDIO` | `false` (also `send_file` the `.ogg` alongside a successful transcript) |
431
369
 
370
+ `OURS_TG_DAEMON_URL` and `OURS_TG_DAEMON_STATE_DIR` are a coherent pair: set
371
+ both or neither. SDK 2 refuses an explicitly selected endpoint without its state
372
+ directory before reading a daemon token. Legacy `OURS_INSTANCE` is rejected, and
373
+ `OURS_AUTOSTART`/`autoStart` are ignored. This connector never embeds or starts an
374
+ ours daemon; operate the shared daemon separately with `ours daemon start` or
375
+ `ours daemon install-service`.
376
+
432
377
  The control API is bound to `127.0.0.1` and unauthenticated — it manages bot
433
378
  tokens, so do not expose the control port off-host.
434
379
 
435
- ## Control plane (ours messenger)
436
-
437
- Each bridge is a self-sovereign ours node that can be **managed from the
438
- ours messenger control plane** over the encrypted a2a_control
439
- channel — no extra ports. The connector advertises an app manifest
440
- (`network.ours.telegram-connector`) with a `core.configuration` capability, so the
441
- messenger renders its generic config form for it. Two fields are configurable
442
- live (no restart):
443
-
444
- - **Allowed chat ID** — only this chat is proxied to the agent.
445
- - **Denial message** — what any other chat is told.
380
+ ## Control plane (removed)
446
381
 
447
- (The bot token is *not* CP-configurable: the messenger strips secret-field values
448
- on save, so the token stays set at connection creation.)
449
-
450
- Bind it once:
451
-
452
- ```sh
453
- # 1. add the messenger as a contact of the bridge node
454
- ours-tg-connector cp_invite supportbot
455
- # → paste the invite into the messenger (add contact / add node)
456
-
457
- # 2. start the bind ceremony for that contact; read out the 6-digit code
458
- ours-tg-connector bind_proxy supportbot <messenger-contact-name-or-cid>
459
- # → enter the code in the messenger Control Panel (out-of-band, 5 min, 3 tries)
460
- ```
382
+ The connector used to be a **managed node**: it advertised an app manifest
383
+ (`network.ours.telegram-connector`) and the ours messenger could bind to it over
384
+ the a2a_control channel and edit the allowed chat id and denial message live.
385
+ That is gone — messenger manageability was removed by ruling, and with it the
386
+ `cp_invite` and `bind_proxy` commands, the `get_manifest` / `get_config` /
387
+ `set_config` verbs, and the bind ceremony.
461
388
 
462
- Once bound, the messenger can pull the manifest, render the config form, and push
463
- changes (`get_manifest` / `get_config` / `set_config`). Config verbs are gated:
464
- only the bound control plane may read or write the configuration.
389
+ A route is configured when it is created (`add_new_connection`) and changed by
390
+ removing it and adding it back. There is no live reconfiguration path, and
391
+ nothing to bind.
465
392
 
466
393
  ## Learn more
467
394
 
package/dist/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
2
+ import { createRequire as __tgCreateRequire } from 'node:module'; const require = __tgCreateRequire(import.meta.url);
3
3
 
4
4
  // src/cli.ts
5
5
  import { spawn, spawnSync } from "node:child_process";
@@ -14,7 +14,8 @@ import * as fs from "node:fs";
14
14
  import { homedir } from "node:os";
15
15
  import { resolve, join, dirname } from "node:path";
16
16
  var DEFAULT_CONFIG = {
17
- brokerUrl: "wss://broker1.ours.network",
17
+ daemonUrl: "",
18
+ daemonStateDir: "",
18
19
  controlPort: 3051,
19
20
  stateDir: resolve(homedir(), ".ours-telegram"),
20
21
  pollTimeoutSec: 30,
@@ -54,7 +55,8 @@ function readFileConfig() {
54
55
  return {};
55
56
  }
56
57
  const out2 = {};
57
- if (typeof parsed.brokerUrl === "string") out2.brokerUrl = parsed.brokerUrl;
58
+ if (typeof parsed.daemonUrl === "string") out2.daemonUrl = parsed.daemonUrl;
59
+ if (typeof parsed.daemonStateDir === "string") out2.daemonStateDir = resolve(parsed.daemonStateDir);
58
60
  if (typeof parsed.controlPort === "number" && Number.isFinite(parsed.controlPort)) out2.controlPort = parsed.controlPort;
59
61
  if (typeof parsed.stateDir === "string") out2.stateDir = resolve(parsed.stateDir);
60
62
  if (typeof parsed.pollTimeoutSec === "number" && Number.isFinite(parsed.pollTimeoutSec)) {
@@ -101,7 +103,11 @@ function envBool(name) {
101
103
  function loadConfig() {
102
104
  const file = readFileConfig();
103
105
  return {
104
- brokerUrl: process.env.OURS_TG_BROKER_URL ?? file.brokerUrl ?? DEFAULT_CONFIG.brokerUrl,
106
+ // NOTE: no OURS_TG_BROKER_URL any more. The connector does not talk to a
107
+ // broker — the daemon does. A stale one in a config file is now ignored
108
+ // rather than half-honoured.
109
+ daemonUrl: process.env.OURS_TG_DAEMON_URL ?? file.daemonUrl ?? DEFAULT_CONFIG.daemonUrl,
110
+ daemonStateDir: process.env.OURS_TG_DAEMON_STATE_DIR ?? file.daemonStateDir ?? DEFAULT_CONFIG.daemonStateDir,
105
111
  controlPort: envInt("OURS_TG_CONTROL_PORT") ?? file.controlPort ?? DEFAULT_CONFIG.controlPort,
106
112
  stateDir: resolve(process.env.OURS_TG_STATE_DIR ?? file.stateDir ?? DEFAULT_CONFIG.stateDir),
107
113
  pollTimeoutSec: envInt("OURS_TG_POLL_TIMEOUT") ?? file.pollTimeoutSec ?? DEFAULT_CONFIG.pollTimeoutSec,
@@ -123,6 +129,52 @@ function loadConfig() {
123
129
  };
124
130
  }
125
131
 
132
+ // src/service-definition.ts
133
+ function serviceEnvironment(config, stateDir) {
134
+ const env = {
135
+ OURS_TG_CONTROL_PORT: String(config.controlPort),
136
+ OURS_TG_STATE_DIR: stateDir,
137
+ OURS_TG_POLL_TIMEOUT: String(config.pollTimeoutSec)
138
+ };
139
+ if (config.daemonUrl) env.OURS_TG_DAEMON_URL = config.daemonUrl;
140
+ if (config.daemonStateDir) env.OURS_TG_DAEMON_STATE_DIR = config.daemonStateDir;
141
+ return env;
142
+ }
143
+ function xmlText(value) {
144
+ return String(value).replace(/[&<>"']/g, (character) => ({
145
+ "&": "&amp;",
146
+ "<": "&lt;",
147
+ ">": "&gt;",
148
+ '"': "&quot;",
149
+ "'": "&apos;"
150
+ })[character]);
151
+ }
152
+ function launchdPlist(input) {
153
+ const envEntries = Object.entries(input.env).map(([key, value]) => ` <key>${xmlText(key)}</key><string>${xmlText(value)}</string>`).join("\n");
154
+ return `<?xml version="1.0" encoding="UTF-8"?>
155
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
156
+ <plist version="1.0">
157
+ <dict>
158
+ <key>Label</key><string>${xmlText(input.label)}</string>
159
+ <key>ProgramArguments</key>
160
+ <array>
161
+ <string>${xmlText(input.execPath)}</string>
162
+ <string>${xmlText(input.self)}</string>
163
+ <string>serve</string>
164
+ </array>
165
+ <key>EnvironmentVariables</key>
166
+ <dict>
167
+ ${envEntries}
168
+ </dict>
169
+ <key>RunAtLoad</key><true/>
170
+ <key>KeepAlive</key><true/>
171
+ <key>StandardOutPath</key><string>${xmlText(input.logPath)}</string>
172
+ <key>StandardErrorPath</key><string>${xmlText(input.logPath)}</string>
173
+ </dict>
174
+ </plist>
175
+ `;
176
+ }
177
+
126
178
  // src/routing.ts
127
179
  function looksLikeBotToken(s) {
128
180
  return /^\d+:[A-Za-z0-9_-]+$/.test(s);
@@ -204,7 +256,7 @@ async function cmdStart() {
204
256
  });
205
257
  child.unref();
206
258
  if (!child.pid) {
207
- err("failed to spawn the daemon.");
259
+ err("failed to spawn the connector.");
208
260
  process.exit(1);
209
261
  }
210
262
  fs2.writeFileSync(PID_PATH, String(child.pid));
@@ -212,11 +264,11 @@ async function cmdStart() {
212
264
  const ready = await waitForPort(PORT);
213
265
  if (ready) {
214
266
  out(`up on ${BASE}`);
215
- out(` broker: ${CONFIG.brokerUrl}`);
267
+ out(` daemon: ${CONFIG.daemonUrl || "(default selection)"}`);
216
268
  out(` state: ${STATE_DIR}`);
217
269
  out(` logs: ${LOG_PATH}`);
218
270
  } else {
219
- err(`daemon started (pid ${child.pid}) but control port ${PORT} did not open within 30s \u2014 check ${LOG_PATH}.`);
271
+ err(`connector started (pid ${child.pid}) but control port ${PORT} did not open within 30s \u2014 check ${LOG_PATH}.`);
220
272
  process.exit(1);
221
273
  }
222
274
  }
@@ -257,7 +309,7 @@ async function cmdStatus() {
257
309
  out("ours-tg-connector: running");
258
310
  if (pid) out(` pid: ${pid}`);
259
311
  out(` url: ${BASE} ${up ? "(reachable)" : "(port not answering!)"}`);
260
- out(` broker: ${CONFIG.brokerUrl}`);
312
+ out(` daemon: ${CONFIG.daemonUrl || "(default selection)"}`);
261
313
  out(` state: ${STATE_DIR}`);
262
314
  out(` logs: ${LOG_PATH}`);
263
315
  if (up) {
@@ -269,12 +321,12 @@ async function cmdStatus() {
269
321
  }
270
322
  }
271
323
  }
272
- async function ensureDaemon() {
324
+ async function ensureConnector() {
273
325
  if (await portOpen(PORT)) return;
274
- out("daemon not running \u2014 starting it\u2026");
326
+ out("connector not running \u2014 starting it\u2026");
275
327
  await cmdStart();
276
328
  if (!await portOpen(PORT)) {
277
- err("daemon did not come up; aborting.");
329
+ err("connector did not come up; aborting.");
278
330
  process.exit(1);
279
331
  }
280
332
  }
@@ -305,7 +357,7 @@ async function cmdAddBot(argv) {
305
357
  err(" ours-tg-connector add_bot --name supportbot --bot-token 123456:ABC...");
306
358
  process.exit(1);
307
359
  }
308
- await ensureDaemon();
360
+ await ensureConnector();
309
361
  let res;
310
362
  try {
311
363
  res = await fetch(`${BASE}/bots`, {
@@ -314,7 +366,7 @@ async function cmdAddBot(argv) {
314
366
  body: JSON.stringify({ name, botToken: token })
315
367
  });
316
368
  } catch (e) {
317
- err(`failed to reach the daemon control API: ${String(e)}`);
369
+ err(`failed to reach the connector control API: ${String(e)}`);
318
370
  process.exit(1);
319
371
  }
320
372
  const body = await res.json();
@@ -328,7 +380,7 @@ async function cmdAddBot(argv) {
328
380
  }
329
381
  async function cmdListBots() {
330
382
  if (!await portOpen(PORT)) {
331
- out("daemon not running \u2014 no live bots. (Persisted ones load on `start`.)");
383
+ out("connector not running \u2014 no live bots. (Persisted ones load on `start`.)");
332
384
  return;
333
385
  }
334
386
  const res = await fetch(`${BASE}/bots`);
@@ -351,7 +403,7 @@ async function cmdRemoveBot(name) {
351
403
  process.exit(1);
352
404
  }
353
405
  if (!await portOpen(PORT)) {
354
- err("daemon not running \u2014 start it first to remove a bot.");
406
+ err("connector not running \u2014 start it first to remove a bot.");
355
407
  process.exit(1);
356
408
  }
357
409
  const res = await fetch(`${BASE}/bots/${encodeURIComponent(name)}`, { method: "DELETE" });
@@ -389,7 +441,7 @@ async function cmdAddConnection(argv) {
389
441
  err('add_new_connection --payload-mode must be "plain" or "envelope"');
390
442
  process.exit(1);
391
443
  }
392
- await ensureDaemon();
444
+ await ensureConnector();
393
445
  let res;
394
446
  try {
395
447
  res = await fetch(`${BASE}/connections`, {
@@ -398,7 +450,7 @@ async function cmdAddConnection(argv) {
398
450
  body: JSON.stringify({ name, botName, chatId, threadId, label, bio, payloadMode })
399
451
  });
400
452
  } catch (e) {
401
- err(`failed to reach the daemon control API: ${String(e)}`);
453
+ err(`failed to reach the connector control API: ${String(e)}`);
402
454
  process.exit(1);
403
455
  }
404
456
  const body = await res.json();
@@ -427,7 +479,7 @@ async function cmdAddConnection(argv) {
427
479
  }
428
480
  async function cmdListConnections() {
429
481
  if (!await portOpen(PORT)) {
430
- out("daemon not running \u2014 no live connections. (Persisted ones load on `start`.)");
482
+ out("connector not running \u2014 no live connections. (Persisted ones load on `start`.)");
431
483
  return;
432
484
  }
433
485
  const res = await fetch(`${BASE}/connections`);
@@ -458,70 +510,26 @@ async function cmdListConnections() {
458
510
  }
459
511
  }
460
512
  }
461
- async function cmdCpInvite(name) {
462
- if (!name) {
463
- err("cp_invite requires a connection name.");
464
- process.exit(1);
465
- }
466
- if (!await portOpen(PORT)) {
467
- err("daemon not running \u2014 start it first.");
468
- process.exit(1);
469
- }
470
- const res = await fetch(`${BASE}/connections/${encodeURIComponent(name)}/cp-invite`, { method: "POST" });
471
- const body = await res.json();
472
- if (!body.ok || !body.invite) {
473
- err(`cp_invite failed: ${body.error ?? `HTTP ${res.status}`}`);
474
- process.exit(1);
475
- }
476
- out("");
477
- out(`Add the messenger control plane as a contact of "${name}".`);
478
- out("Paste this invite into the messenger (add contact / add node):");
479
- out("");
480
- out(body.invite);
481
- out("");
482
- out(`Once it is a contact, bind it: ours-tg-connector bind_proxy ${name} <contact-name-or-cid>`);
483
- }
484
- async function cmdBindProxy(name, contact) {
485
- if (!name || !contact) {
486
- err("bind_proxy requires <connection-name> <contact-name-or-cid>.");
487
- process.exit(1);
488
- }
489
- if (!await portOpen(PORT)) {
490
- err("daemon not running \u2014 start it first.");
491
- process.exit(1);
492
- }
493
- const res = await fetch(`${BASE}/connections/${encodeURIComponent(name)}/bind`, {
494
- method: "POST",
495
- headers: { "Content-Type": "application/json" },
496
- body: JSON.stringify({ contact })
497
- });
498
- const body = await res.json();
499
- if (!body.ok || !body.code) {
500
- err(`bind_proxy failed: ${body.error ?? `HTTP ${res.status}`}`);
501
- process.exit(1);
502
- }
503
- out("");
504
- out(`Verification code: ${body.code}`);
505
- out("");
506
- out("Enter it in the messenger Control Panel within 5 minutes (3 attempts).");
507
- out("Do NOT send it over ours \u2014 it must travel out-of-band (this terminal counts).");
508
- }
509
513
  async function cmdRemoveConnection(name) {
510
514
  if (!name) {
511
515
  err("remove_connection requires a connection name.");
512
516
  process.exit(1);
513
517
  }
514
518
  if (!await portOpen(PORT)) {
515
- err("daemon not running \u2014 start it first to remove a live connection.");
519
+ err("connector not running \u2014 start it first to remove a live connection.");
516
520
  process.exit(1);
517
521
  }
518
522
  const res = await fetch(`${BASE}/connections/${encodeURIComponent(name)}`, { method: "DELETE" });
519
523
  const body = await res.json();
520
524
  if (!body.ok) {
521
- err(`remove_connection failed: ${body.error ?? `HTTP ${res.status}`}`);
525
+ if (body.removed) {
526
+ err(`Removed connection "${body.removed}" locally, but its daemon identity was left behind: ${body.error ?? `HTTP ${res.status}`}`);
527
+ } else {
528
+ err(`remove_connection failed: ${body.error ?? `HTTP ${res.status}`}`);
529
+ }
522
530
  process.exit(1);
523
531
  }
524
- out(`Removed connection "${name}" and its state.`);
532
+ out(`Removed connection "${name}", its state, and its name-listed daemon identity.`);
525
533
  }
526
534
  var SYSTEMD_UNIT = "ours-telegram.service";
527
535
  var LAUNCHD_LABEL = "solutions.adaptframework.ours-telegram";
@@ -535,14 +543,7 @@ function run(cmd, args) {
535
543
  const r = spawnSync(cmd, args, { stdio: "inherit" });
536
544
  return r.status === 0;
537
545
  }
538
- function serviceEnv() {
539
- return {
540
- OURS_TG_BROKER_URL: CONFIG.brokerUrl,
541
- OURS_TG_CONTROL_PORT: String(CONFIG.controlPort),
542
- OURS_TG_STATE_DIR: STATE_DIR,
543
- OURS_TG_POLL_TIMEOUT: String(CONFIG.pollTimeoutSec)
544
- };
545
- }
546
+ var serviceEnv = () => serviceEnvironment(CONFIG, STATE_DIR);
546
547
  function installSystemd() {
547
548
  const unitPath = systemdUnitPath();
548
549
  fs2.mkdirSync(dirname2(unitPath), { recursive: true });
@@ -596,29 +597,13 @@ function installLaunchd() {
596
597
  const plistPath = launchdPlistPath();
597
598
  fs2.mkdirSync(dirname2(plistPath), { recursive: true });
598
599
  const env = serviceEnv();
599
- const envEntries = Object.entries(env).map(([k, v]) => ` <key>${k}</key><string>${v}</string>`).join("\n");
600
- const plist = `<?xml version="1.0" encoding="UTF-8"?>
601
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
602
- <plist version="1.0">
603
- <dict>
604
- <key>Label</key><string>${LAUNCHD_LABEL}</string>
605
- <key>ProgramArguments</key>
606
- <array>
607
- <string>${process.execPath}</string>
608
- <string>${SELF}</string>
609
- <string>serve</string>
610
- </array>
611
- <key>EnvironmentVariables</key>
612
- <dict>
613
- ${envEntries}
614
- </dict>
615
- <key>RunAtLoad</key><true/>
616
- <key>KeepAlive</key><true/>
617
- <key>StandardOutPath</key><string>${LOG_PATH}</string>
618
- <key>StandardErrorPath</key><string>${LOG_PATH}</string>
619
- </dict>
620
- </plist>
621
- `;
600
+ const plist = launchdPlist({
601
+ label: LAUNCHD_LABEL,
602
+ execPath: process.execPath,
603
+ self: SELF,
604
+ logPath: LOG_PATH,
605
+ env
606
+ });
622
607
  fs2.writeFileSync(plistPath, plist);
623
608
  out(`wrote ${plistPath}`);
624
609
  run("launchctl", ["unload", plistPath]);
@@ -675,22 +660,19 @@ function usage() {
675
660
  out(" list_connections list configured routes grouped by bot");
676
661
  out(" remove_connection <name> delete a route and its state");
677
662
  out("");
678
- out(" control plane (ours messenger):");
679
- out(" cp_invite <name> print an invite to add the messenger as a contact");
680
- out(" bind_proxy <name> <contact> start binding the messenger as control plane (prints a 6-digit code)");
681
- out("");
682
- out(" start start the daemon in the background");
683
- out(" stop stop the running daemon");
663
+ out(" start start the connector in the background");
664
+ out(" stop stop the running connector");
684
665
  out(" restart stop then start");
685
- out(" status show whether the daemon is running");
686
- out(" serve run the daemon in the foreground (used by start; handy for debugging)");
666
+ out(" status show whether the connector is running");
667
+ out(" serve run the connector in the foreground (used by start; handy for debugging)");
687
668
  out("");
688
669
  out(" install-service install + start a boot-persistent service (systemd/launchd)");
689
670
  out(" uninstall-service stop + remove that service");
690
671
  out("");
691
672
  out("Config precedence (per field): env var > config.json > default.");
692
673
  out(" config.json: OURS_TG_CONFIG, else ~/.ours-telegram/config.json");
693
- out(" env: OURS_TG_BROKER_URL, OURS_TG_CONTROL_PORT (3051), OURS_TG_STATE_DIR, OURS_TG_POLL_TIMEOUT (30)");
674
+ out(" env: OURS_TG_DAEMON_URL + OURS_TG_DAEMON_STATE_DIR (both, or neither), OURS_TG_CONTROL_PORT (3051),");
675
+ out(" OURS_TG_STATE_DIR, OURS_TG_POLL_TIMEOUT (30)");
694
676
  }
695
677
  async function main() {
696
678
  const cmd = process.argv[2] ?? "help";
@@ -741,14 +723,6 @@ async function main() {
741
723
  case "remove":
742
724
  await cmdRemoveConnection(process.argv[3]);
743
725
  break;
744
- case "cp_invite":
745
- case "cp-invite":
746
- await cmdCpInvite(process.argv[3]);
747
- break;
748
- case "bind_proxy":
749
- case "bind-proxy":
750
- await cmdBindProxy(process.argv[3], process.argv[4]);
751
- break;
752
726
  case "start":
753
727
  await cmdStart();
754
728
  break;