@ours.network/tg-connector 1.0.0 → 1.0.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.
- package/README.md +85 -9
- package/dist/cli.js +10 -7
- package/dist/connector.js +2528 -1240
- package/docs/selected-source-development.md +30 -0
- package/package.json +7 -6
package/README.md
CHANGED
|
@@ -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,58 @@ 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).
|
package/dist/cli.js
CHANGED
|
@@ -16,6 +16,8 @@ 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,
|
|
20
22
|
stateDir: resolve(homedir(), ".ours-telegram"),
|
|
21
23
|
pollTimeoutSec: 30,
|
|
@@ -55,6 +57,8 @@ function readFileConfig() {
|
|
|
55
57
|
return {};
|
|
56
58
|
}
|
|
57
59
|
const out2 = {};
|
|
60
|
+
if (typeof parsed.daemonInstanceId === "string") out2.daemonInstanceId = parsed.daemonInstanceId;
|
|
61
|
+
if (typeof parsed.daemonCredentialPath === "string") out2.daemonCredentialPath = parsed.daemonCredentialPath;
|
|
58
62
|
if (typeof parsed.daemonUrl === "string") out2.daemonUrl = parsed.daemonUrl;
|
|
59
63
|
if (typeof parsed.daemonStateDir === "string") out2.daemonStateDir = resolve(parsed.daemonStateDir);
|
|
60
64
|
if (typeof parsed.controlPort === "number" && Number.isFinite(parsed.controlPort)) out2.controlPort = parsed.controlPort;
|
|
@@ -108,6 +112,8 @@ function loadConfig() {
|
|
|
108
112
|
// rather than half-honoured.
|
|
109
113
|
daemonUrl: process.env.OURS_TG_DAEMON_URL ?? file.daemonUrl ?? DEFAULT_CONFIG.daemonUrl,
|
|
110
114
|
daemonStateDir: process.env.OURS_TG_DAEMON_STATE_DIR ?? file.daemonStateDir ?? DEFAULT_CONFIG.daemonStateDir,
|
|
115
|
+
daemonInstanceId: process.env.OURS_TG_DAEMON_ID ?? file.daemonInstanceId ?? DEFAULT_CONFIG.daemonInstanceId,
|
|
116
|
+
daemonCredentialPath: process.env.OURS_TG_DAEMON_CREDENTIAL_PATH ?? file.daemonCredentialPath ?? DEFAULT_CONFIG.daemonCredentialPath,
|
|
111
117
|
controlPort: envInt("OURS_TG_CONTROL_PORT") ?? file.controlPort ?? DEFAULT_CONFIG.controlPort,
|
|
112
118
|
stateDir: resolve(process.env.OURS_TG_STATE_DIR ?? file.stateDir ?? DEFAULT_CONFIG.stateDir),
|
|
113
119
|
pollTimeoutSec: envInt("OURS_TG_POLL_TIMEOUT") ?? file.pollTimeoutSec ?? DEFAULT_CONFIG.pollTimeoutSec,
|
|
@@ -138,6 +144,8 @@ function serviceEnvironment(config, stateDir) {
|
|
|
138
144
|
};
|
|
139
145
|
if (config.daemonUrl) env.OURS_TG_DAEMON_URL = config.daemonUrl;
|
|
140
146
|
if (config.daemonStateDir) env.OURS_TG_DAEMON_STATE_DIR = config.daemonStateDir;
|
|
147
|
+
if (config.daemonInstanceId) env.OURS_TG_DAEMON_ID = config.daemonInstanceId;
|
|
148
|
+
if (config.daemonCredentialPath) env.OURS_TG_DAEMON_CREDENTIAL_PATH = config.daemonCredentialPath;
|
|
141
149
|
return env;
|
|
142
150
|
}
|
|
143
151
|
function xmlText(value) {
|
|
@@ -671,7 +679,8 @@ function usage() {
|
|
|
671
679
|
out("");
|
|
672
680
|
out("Config precedence (per field): env var > config.json > default.");
|
|
673
681
|
out(" config.json: OURS_TG_CONFIG, else ~/.ours-telegram/config.json");
|
|
674
|
-
out(" env: OURS_TG_DAEMON_URL +
|
|
682
|
+
out(" env: OURS_TG_DAEMON_URL + OURS_TG_DAEMON_ID + OURS_TG_DAEMON_CREDENTIAL_PATH (V1),");
|
|
683
|
+
out(" legacy: OURS_TG_DAEMON_URL + OURS_TG_DAEMON_STATE_DIR; OURS_TG_CONTROL_PORT (3051),");
|
|
675
684
|
out(" OURS_TG_STATE_DIR, OURS_TG_POLL_TIMEOUT (30)");
|
|
676
685
|
}
|
|
677
686
|
async function main() {
|
|
@@ -688,12 +697,6 @@ async function main() {
|
|
|
688
697
|
}
|
|
689
698
|
};
|
|
690
699
|
process.on("exit", cleanup);
|
|
691
|
-
for (const sig of ["SIGTERM", "SIGINT"]) {
|
|
692
|
-
process.on(sig, () => {
|
|
693
|
-
cleanup();
|
|
694
|
-
process.exit(0);
|
|
695
|
-
});
|
|
696
|
-
}
|
|
697
700
|
await import(pathToFileURL(join2(dirname2(SELF), "connector.js")).href);
|
|
698
701
|
break;
|
|
699
702
|
}
|