@ours.network/tg-connector 1.0.0 → 1.0.1-nightly.10
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/README.md +90 -10
- package/dist/cli.js +17 -7
- package/dist/connector.js +2742 -1428
- package/docs/selected-source-development.md +30 -0
- package/package.json +9 -7
package/README.md
CHANGED
|
@@ -293,7 +293,7 @@ npm install
|
|
|
293
293
|
npm run build
|
|
294
294
|
```
|
|
295
295
|
|
|
296
|
-
Requires Node ≥
|
|
296
|
+
Requires Node ≥ 22, and **an ours daemon already running on this box** — the
|
|
297
297
|
connector attaches to it over `/api/v1` and drives it through
|
|
298
298
|
[`@ours.network/sdk`](https://www.npmjs.com/package/@ours.network/sdk). It runs
|
|
299
299
|
no engine of its own: there is no native ADAPT SDK and no MUFL packet here, so
|
|
@@ -361,8 +361,8 @@ topic within that chat. `--bio` is the context the agent reads about this chat
|
|
|
361
361
|
route for any chat the bot sees that no other route claims. Reuse the same `--bot`
|
|
362
362
|
across routes to multiplex one bot over many chats/topics.
|
|
363
363
|
|
|
364
|
-
`remove_connection`
|
|
365
|
-
identity by its recorded route name and deletes the local route record. Because
|
|
364
|
+
`remove_connection` stops and awaits that route’s active work, removes the daemon
|
|
365
|
+
identity by its recorded route name, terminally releases its owner, and deletes the local route record. Because
|
|
366
366
|
the ownership list is intentionally name-only, an operator who manually removes
|
|
367
367
|
and recreates a same-name identity has deliberately replaced it; removing the
|
|
368
368
|
route can remove that replacement too. Use the `ours` operator CLI to repair
|
|
@@ -376,7 +376,9 @@ Precedence per field: **env var > `config.json` > default**. The config file is
|
|
|
376
376
|
| field | env var | default |
|
|
377
377
|
|----------------|---------------------------|-------------------------------------------------|
|
|
378
378
|
| daemon URL | `OURS_TG_DAEMON_URL` | `''` (the SDK's own default selection) |
|
|
379
|
-
| daemon
|
|
379
|
+
| daemon UUID (`daemonInstanceId`) | `OURS_TG_DAEMON_ID` | unset |
|
|
380
|
+
| current credential file (`daemonCredentialPath`) | `OURS_TG_DAEMON_CREDENTIAL_PATH` | unset |
|
|
381
|
+
| daemon state dir (temporary legacy) | `OURS_TG_DAEMON_STATE_DIR` | `''` (the SDK's own default selection) |
|
|
380
382
|
| control port | `OURS_TG_CONTROL_PORT` | `3051` (localhost only) |
|
|
381
383
|
| state dir | `OURS_TG_STATE_DIR` | `~/.ours-telegram` |
|
|
382
384
|
| poll timeout | `OURS_TG_POLL_TIMEOUT` | `30` (seconds, Telegram long-poll) |
|
|
@@ -396,12 +398,31 @@ Precedence per field: **env var > `config.json` > default**. The config file is
|
|
|
396
398
|
| STT timeout | `OURS_TG_STT_TIMEOUT_MS` | `60000` (per-transcription abort deadline, ms) |
|
|
397
399
|
| forward voice audio | `OURS_TG_FORWARD_VOICE_AUDIO` | `false` (also `send_file` the `.ogg` alongside a successful transcript) |
|
|
398
400
|
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
401
|
+
For V1, set `OURS_TG_DAEMON_URL` to the daemon’s HTTP origin,
|
|
402
|
+
`OURS_TG_DAEMON_ID` to its configured lowercase UUID, and
|
|
403
|
+
`OURS_TG_DAEMON_CREDENTIAL_PATH` to its protected absolute current-token file.
|
|
404
|
+
Equivalent config fields are `daemonUrl`, `daemonInstanceId`, and
|
|
405
|
+
`daemonCredentialPath`. The SDK verifies public daemon identity/capability metadata
|
|
406
|
+
before reading the credential. HTTP identity selection is not cryptographic server
|
|
407
|
+
proof. The SDK rereads the protected file for requests, so atomic token replacement
|
|
408
|
+
does not require restarting the connector. Service installation carries these
|
|
409
|
+
non-secret selection values and paths; do not put the token bytes in configuration.
|
|
410
|
+
|
|
411
|
+
Each route uses its own persisted owner ID. Watch retries and daemon restart retain
|
|
412
|
+
that ID and never terminally release ownership. SIGINT/SIGTERM stop and await bot
|
|
413
|
+
polling, watches and route work before releasing each owner; permanent route
|
|
414
|
+
identities and siblings remain. A successful terminal release clears the persisted
|
|
415
|
+
owner ID, and the next normal connector start creates a fresh owner. Failed release
|
|
416
|
+
retains the exact ID and reports failed shutdown. A crash between daemon release
|
|
417
|
+
acknowledgement and metadata persistence can leave a retired ID on disk; restoration
|
|
418
|
+
then refuses rather than taking over automatically. Repair that residual explicitly.
|
|
419
|
+
|
|
420
|
+
Temporary legacy selection remains available without the V1 fields:
|
|
421
|
+
`OURS_TG_DAEMON_URL` and `OURS_TG_DAEMON_STATE_DIR` must be set together or both
|
|
422
|
+
omitted. Failed V1 selection/API requests never fall back to it. Legacy
|
|
423
|
+
`OURS_INSTANCE` is rejected, and `OURS_AUTOSTART`/`autoStart` are ignored.
|
|
424
|
+
This connector never embeds or starts an ours daemon; operate it separately with
|
|
425
|
+
`ours-daemon start` or `ours-daemon install-service`.
|
|
405
426
|
|
|
406
427
|
The control API is bound to `127.0.0.1` and unauthenticated — it manages bot
|
|
407
428
|
tokens, so do not expose the control port off-host.
|
|
@@ -459,3 +480,62 @@ The FSL permits any use **except a Competing Use** — broadly, offering a comme
|
|
|
459
480
|
**Audit status.** The core has not yet had an independent security audit. We're raising funding to commission one from a recognized firm and prove these guarantees, and we'll open-source the full core once it passes. Until then it's source-available and documented, but not independently audited — run anything critical on it at your own risk.
|
|
460
481
|
|
|
461
482
|
Copyright 2026 Adapt Framework Solutions Ltd.
|
|
483
|
+
|
|
484
|
+
## Container lifecycle verification
|
|
485
|
+
|
|
486
|
+
After building with the selected SDK/CLI artifacts installed, run
|
|
487
|
+
`npm run test:v1-lifecycle` inside an isolated Docker container with external
|
|
488
|
+
networking disabled. The existing test uses temporary daemon/connector state
|
|
489
|
+
and blocks Telegram transport through its shipped test fixture. It checks
|
|
490
|
+
lifecycle and token recovery, not real Telegram delivery; no working bot token
|
|
491
|
+
or account is needed. Real bot/chat acceptance remains a separate check.
|
|
492
|
+
|
|
493
|
+
## Optional startup provisioning
|
|
494
|
+
|
|
495
|
+
Host and container installations can place a private `provision.json` in
|
|
496
|
+
`OURS_TG_STATE_DIR` (the configured state directory). Without this file, startup
|
|
497
|
+
retains the normal CLI/control-API workflow and needs no Docker installation.
|
|
498
|
+
|
|
499
|
+
```json
|
|
500
|
+
{
|
|
501
|
+
"bots": [{"name": "primary", "botToken": "<bot-token>"}],
|
|
502
|
+
"connections": [{"name": "alerts", "botName": "primary", "chatId": "<chat-id>", "payloadMode": "plain"}]
|
|
503
|
+
}
|
|
504
|
+
```
|
|
505
|
+
|
|
506
|
+
Use mode `0600` and ownership matching the connector. Optional connection fields
|
|
507
|
+
are `threadId`, `label`, `bio` and `payloadMode` (default `envelope`). Startup
|
|
508
|
+
applies the document before readiness. Identical settings are a no-op; conflicting
|
|
509
|
+
existing settings cause startup to fail without overwriting those entries. Bot
|
|
510
|
+
tokens are compared in full. Newly created connection results, including invites,
|
|
511
|
+
are retained privately in `provision-output.json`. Partial successful additions
|
|
512
|
+
remain available for a subsequent retry; this is not a transactional batch.
|
|
513
|
+
Change existing settings using the normal connector tools.
|
|
514
|
+
|
|
515
|
+
### Build with selected SDK and CLI archives
|
|
516
|
+
|
|
517
|
+
Run in the build container with Node 22+, npm and tar available:
|
|
518
|
+
|
|
519
|
+
```sh
|
|
520
|
+
node scripts/build-selected.mjs --sdk /artifacts/ours.network-sdk-3.7.2.tgz --cli /artifacts/ours.network-cli-2.7.2.tgz --out-dir /artifacts/consumer
|
|
521
|
+
```
|
|
522
|
+
|
|
523
|
+
The recipe validates package names, installs and builds in disposable staging,
|
|
524
|
+
then writes one complete portable npm archive. Stdout is a JSON object with its
|
|
525
|
+
actual `filename`; build/npm logs go to stderr. Normal source manifests, locks
|
|
526
|
+
and installed dependencies are preserved. The installer must install the same
|
|
527
|
+
selected SDK and CLI archives alongside this package; its final dependency
|
|
528
|
+
versions come from those archives. Existing bundling choices are unchanged.
|
|
529
|
+
|
|
530
|
+
Focused build/install verification (two real builds, including changed bytes
|
|
531
|
+
under identical input names and versions, plus a missing-vendor negative check):
|
|
532
|
+
|
|
533
|
+
```sh
|
|
534
|
+
node scripts/check-build-selected.mjs --sdk /artifacts/ours.network-sdk-3.7.2.tgz --cli /artifacts/ours.network-cli-2.7.2.tgz
|
|
535
|
+
```
|
|
536
|
+
|
|
537
|
+
For development against the selected, unpublished SDK/CLI sources, see [selected-source development](docs/selected-source-development.md).
|
|
538
|
+
|
|
539
|
+
### Private Docker gateway listener
|
|
540
|
+
|
|
541
|
+
`OURS_TG_CONTROL_HOST=0.0.0.0` allows the installer nginx gateway to reach the control API over its private Docker network. The default remains `127.0.0.1`. This API has operator authority and no application authentication: never publish its container port or use this setting on an unprotected host. The supported installer gateway authenticates requests using the issued server credential before forwarding them. All containers on that network share the same trust boundary. `ours-tg-connector capabilities` advertises `telegram.gateway-listener-v1` for installer compatibility checks.
|
package/dist/cli.js
CHANGED
|
@@ -16,7 +16,10 @@ import { resolve, join, dirname } from "node:path";
|
|
|
16
16
|
var DEFAULT_CONFIG = {
|
|
17
17
|
daemonUrl: "",
|
|
18
18
|
daemonStateDir: "",
|
|
19
|
+
daemonInstanceId: "",
|
|
20
|
+
daemonCredentialPath: "",
|
|
19
21
|
controlPort: 3051,
|
|
22
|
+
controlHost: "127.0.0.1",
|
|
20
23
|
stateDir: resolve(homedir(), ".ours-telegram"),
|
|
21
24
|
pollTimeoutSec: 30,
|
|
22
25
|
tgForceIpv4: true,
|
|
@@ -55,6 +58,8 @@ function readFileConfig() {
|
|
|
55
58
|
return {};
|
|
56
59
|
}
|
|
57
60
|
const out2 = {};
|
|
61
|
+
if (typeof parsed.daemonInstanceId === "string") out2.daemonInstanceId = parsed.daemonInstanceId;
|
|
62
|
+
if (typeof parsed.daemonCredentialPath === "string") out2.daemonCredentialPath = parsed.daemonCredentialPath;
|
|
58
63
|
if (typeof parsed.daemonUrl === "string") out2.daemonUrl = parsed.daemonUrl;
|
|
59
64
|
if (typeof parsed.daemonStateDir === "string") out2.daemonStateDir = resolve(parsed.daemonStateDir);
|
|
60
65
|
if (typeof parsed.controlPort === "number" && Number.isFinite(parsed.controlPort)) out2.controlPort = parsed.controlPort;
|
|
@@ -102,12 +107,17 @@ function envBool(name) {
|
|
|
102
107
|
}
|
|
103
108
|
function loadConfig() {
|
|
104
109
|
const file = readFileConfig();
|
|
110
|
+
const controlHost = process.env.OURS_TG_CONTROL_HOST ?? "127.0.0.1";
|
|
111
|
+
if (controlHost !== "127.0.0.1" && controlHost !== "0.0.0.0") throw new Error("OURS_TG_CONTROL_HOST must be 127.0.0.1 or 0.0.0.0");
|
|
105
112
|
return {
|
|
106
113
|
// NOTE: no OURS_TG_BROKER_URL any more. The connector does not talk to a
|
|
107
114
|
// broker — the daemon does. A stale one in a config file is now ignored
|
|
108
115
|
// rather than half-honoured.
|
|
109
116
|
daemonUrl: process.env.OURS_TG_DAEMON_URL ?? file.daemonUrl ?? DEFAULT_CONFIG.daemonUrl,
|
|
110
117
|
daemonStateDir: process.env.OURS_TG_DAEMON_STATE_DIR ?? file.daemonStateDir ?? DEFAULT_CONFIG.daemonStateDir,
|
|
118
|
+
daemonInstanceId: process.env.OURS_TG_DAEMON_ID ?? file.daemonInstanceId ?? DEFAULT_CONFIG.daemonInstanceId,
|
|
119
|
+
daemonCredentialPath: process.env.OURS_TG_DAEMON_CREDENTIAL_PATH ?? file.daemonCredentialPath ?? DEFAULT_CONFIG.daemonCredentialPath,
|
|
120
|
+
controlHost,
|
|
111
121
|
controlPort: envInt("OURS_TG_CONTROL_PORT") ?? file.controlPort ?? DEFAULT_CONFIG.controlPort,
|
|
112
122
|
stateDir: resolve(process.env.OURS_TG_STATE_DIR ?? file.stateDir ?? DEFAULT_CONFIG.stateDir),
|
|
113
123
|
pollTimeoutSec: envInt("OURS_TG_POLL_TIMEOUT") ?? file.pollTimeoutSec ?? DEFAULT_CONFIG.pollTimeoutSec,
|
|
@@ -138,6 +148,8 @@ function serviceEnvironment(config, stateDir) {
|
|
|
138
148
|
};
|
|
139
149
|
if (config.daemonUrl) env.OURS_TG_DAEMON_URL = config.daemonUrl;
|
|
140
150
|
if (config.daemonStateDir) env.OURS_TG_DAEMON_STATE_DIR = config.daemonStateDir;
|
|
151
|
+
if (config.daemonInstanceId) env.OURS_TG_DAEMON_ID = config.daemonInstanceId;
|
|
152
|
+
if (config.daemonCredentialPath) env.OURS_TG_DAEMON_CREDENTIAL_PATH = config.daemonCredentialPath;
|
|
141
153
|
return env;
|
|
142
154
|
}
|
|
143
155
|
function xmlText(value) {
|
|
@@ -671,12 +683,16 @@ function usage() {
|
|
|
671
683
|
out("");
|
|
672
684
|
out("Config precedence (per field): env var > config.json > default.");
|
|
673
685
|
out(" config.json: OURS_TG_CONFIG, else ~/.ours-telegram/config.json");
|
|
674
|
-
out(" env: OURS_TG_DAEMON_URL +
|
|
686
|
+
out(" env: OURS_TG_DAEMON_URL + OURS_TG_DAEMON_ID + OURS_TG_DAEMON_CREDENTIAL_PATH (V1),");
|
|
687
|
+
out(" legacy: OURS_TG_DAEMON_URL + OURS_TG_DAEMON_STATE_DIR; OURS_TG_CONTROL_PORT (3051),");
|
|
675
688
|
out(" OURS_TG_STATE_DIR, OURS_TG_POLL_TIMEOUT (30)");
|
|
676
689
|
}
|
|
677
690
|
async function main() {
|
|
678
691
|
const cmd = process.argv[2] ?? "help";
|
|
679
692
|
switch (cmd) {
|
|
693
|
+
case "capabilities":
|
|
694
|
+
out(JSON.stringify({ capabilities: ["telegram.gateway-listener-v1"] }));
|
|
695
|
+
return;
|
|
680
696
|
case "serve":
|
|
681
697
|
case "run": {
|
|
682
698
|
fs2.mkdirSync(STATE_DIR, { recursive: true });
|
|
@@ -688,12 +704,6 @@ async function main() {
|
|
|
688
704
|
}
|
|
689
705
|
};
|
|
690
706
|
process.on("exit", cleanup);
|
|
691
|
-
for (const sig of ["SIGTERM", "SIGINT"]) {
|
|
692
|
-
process.on(sig, () => {
|
|
693
|
-
cleanup();
|
|
694
|
-
process.exit(0);
|
|
695
|
-
});
|
|
696
|
-
}
|
|
697
707
|
await import(pathToFileURL(join2(dirname2(SELF), "connector.js")).href);
|
|
698
708
|
break;
|
|
699
709
|
}
|