@ours.network/tg-connector 2.1.0 → 2.1.2
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 +3 -1
- package/dist/connector.js +151 -68
- package/docs/telegram-widgets.md +12 -3
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -219,7 +219,9 @@ that agent as a `telegram_widget_query` JSON message (untrusted data). Discover
|
|
|
219
219
|
the commands with `list_contact_commands`. Ordinary agent text is never turned
|
|
220
220
|
into a widget. Typed command rows are never posted to Telegram; the drain
|
|
221
221
|
consumes them and the SDK returns each command's result. Production Telegram
|
|
222
|
-
supports widgets in private chats only.
|
|
222
|
+
supports widgets in private chats only. Widget commands are accepted only from
|
|
223
|
+
the route's recorded agent, which the route takes from its contact list when it
|
|
224
|
+
has exactly one contact. See
|
|
223
225
|
[docs/telegram-widgets.md](docs/telegram-widgets.md) and
|
|
224
226
|
[examples/widget-choice.html](examples/widget-choice.html).
|
|
225
227
|
|
package/dist/connector.js
CHANGED
|
@@ -26208,9 +26208,9 @@ var L = 100 * 1024 * 1024;
|
|
|
26208
26208
|
var K = { brokerUrl: "wss://broker1.ours.network", port: 3050, stateDir: E(T(), ".ours"), gcIntervalMs: 36e5, historyMaxBytes: L, apiVisibility: "owner", apiAuthMode: "legacy" };
|
|
26209
26209
|
var $ = "daemon-token";
|
|
26210
26210
|
|
|
26211
|
-
// node_modules/@ours.network/sdk/dist/chunk-
|
|
26211
|
+
// node_modules/@ours.network/sdk/dist/chunk-JGK6W4GI.js
|
|
26212
26212
|
import { homedir as Te } from "node:os";
|
|
26213
|
-
import { isAbsolute as Oe, join as Se, resolve as
|
|
26213
|
+
import { isAbsolute as Oe, join as Se, resolve as pe } from "node:path";
|
|
26214
26214
|
import { randomBytes as W } from "node:crypto";
|
|
26215
26215
|
import { readFileSync as xe } from "node:fs";
|
|
26216
26216
|
import { homedir as Ne } from "node:os";
|
|
@@ -26235,7 +26235,7 @@ function w2(e2) {
|
|
|
26235
26235
|
if (t.username || t.password || t.hash) throw new Error("Daemon endpoint cannot contain credentials or fragment");
|
|
26236
26236
|
return t.origin + t.pathname.replace(/\/+$/, "") + t.search;
|
|
26237
26237
|
}
|
|
26238
|
-
function
|
|
26238
|
+
function u2(e2, t) {
|
|
26239
26239
|
if (!t.startsWith("/") || t.startsWith("//") || t.includes("#")) throw new Error("Invalid daemon route");
|
|
26240
26240
|
let n = new URL(e2), r = new URL(t, "http://daemon.invalid");
|
|
26241
26241
|
if (n.pathname = n.pathname.replace(/\/+$/, "") + r.pathname, r.search) {
|
|
@@ -26321,7 +26321,7 @@ var F = class {
|
|
|
26321
26321
|
this.leaseToken = t.leaseToken, this.clientPid = t.clientPid ?? process.pid, this.explicitApiToken = t.apiToken, this.credentialPath = t.credentialPath;
|
|
26322
26322
|
let n = t.fetch ?? globalThis.fetch;
|
|
26323
26323
|
this.fetchImpl = (r, i) => {
|
|
26324
|
-
let o = String(r) ===
|
|
26324
|
+
let o = String(r) === u2(this.base, "/api/v1/releaseLease"), s = [i?.signal, o ? t.requestSignal ? AbortSignal.timeout(5e3) : void 0 : t.requestSignal].filter((a) => a != null);
|
|
26325
26325
|
return n(r, { ...i, ...s.length ? { signal: AbortSignal.any(s) } : {} });
|
|
26326
26326
|
};
|
|
26327
26327
|
}
|
|
@@ -26332,7 +26332,7 @@ var F = class {
|
|
|
26332
26332
|
return { "x-ours-session-mode": this.sessionMode, "x-ours-lease-token": this.leaseToken, "x-ours-client-pid": String(this.clientPid), ...n ? { "x-ours-api-token": n } : {}, ...t };
|
|
26333
26333
|
}
|
|
26334
26334
|
async post(t, n, r = false) {
|
|
26335
|
-
let i = await this.fetchImpl(
|
|
26335
|
+
let i = await this.fetchImpl(u2(this.base, `/api/v1/${t}`), { redirect: "error", method: "POST", headers: this.headers({ "content-type": "application/json" }), body: JSON.stringify(n ?? {}), ...r ? { signal: AbortSignal.timeout(5e3) } : {} }), o;
|
|
26336
26336
|
try {
|
|
26337
26337
|
r ? o = await C(i) : o = await i.json();
|
|
26338
26338
|
} catch {
|
|
@@ -26351,7 +26351,7 @@ var F = class {
|
|
|
26351
26351
|
return o;
|
|
26352
26352
|
}
|
|
26353
26353
|
async get(t, n) {
|
|
26354
|
-
let r = await this.fetchImpl(
|
|
26354
|
+
let r = await this.fetchImpl(u2(this.base, t), { redirect: "error", headers: n ? this.headers() : {} }), i;
|
|
26355
26355
|
try {
|
|
26356
26356
|
i = await r.json();
|
|
26357
26357
|
} catch {
|
|
@@ -26362,7 +26362,7 @@ var F = class {
|
|
|
26362
26362
|
return i;
|
|
26363
26363
|
}
|
|
26364
26364
|
async resourcePosition(t, n) {
|
|
26365
|
-
let r = await this.fetchImpl(
|
|
26365
|
+
let r = await this.fetchImpl(u2(this.base, `/identities/${encodeURIComponent(t)}/resource-events?position=1`), { redirect: "error", headers: this.headers(), signal: n.signal });
|
|
26366
26366
|
if (!r.ok) throw new U(r.status);
|
|
26367
26367
|
let i = await C(r);
|
|
26368
26368
|
return le(i), i;
|
|
@@ -26382,7 +26382,7 @@ var F = class {
|
|
|
26382
26382
|
a(1e4);
|
|
26383
26383
|
let y2 = new URLSearchParams();
|
|
26384
26384
|
n.after !== void 0 && (y2.set("after", String(n.after)), y2.set("expectedGeneration", n.expectedGeneration));
|
|
26385
|
-
let h = await this.fetchImpl(
|
|
26385
|
+
let h = await this.fetchImpl(u2(this.base, `/identities/${encodeURIComponent(t)}/resource-events?${y2}`), { redirect: "error", headers: this.headers({ accept: "text/event-stream" }), signal: i });
|
|
26386
26386
|
if (i.aborted) throw h.body?.cancel(), i.reason;
|
|
26387
26387
|
if (!h.ok) throw new U(h.status);
|
|
26388
26388
|
if (!h.body || !h.headers.get("content-type")?.startsWith("text/event-stream")) throw new Error("Invalid resource stream response");
|
|
@@ -26398,11 +26398,11 @@ var F = class {
|
|
|
26398
26398
|
if (!N) break;
|
|
26399
26399
|
let j = v2.slice(0, N.index);
|
|
26400
26400
|
if (v2 = v2.slice(N.index + N[0].length), b2 -= Buffer.byteLength(j) + Buffer.byteLength(N[0]), Buffer.byteLength(j) > 512 * 1024) throw new Error("Resource frame exceeds limit");
|
|
26401
|
-
let oe = j.split(/\r?\n/).filter((
|
|
26401
|
+
let oe = j.split(/\r?\n/).filter((P) => P.startsWith("data:")).map((P) => P.slice(5).trimStart()).join(`
|
|
26402
26402
|
`);
|
|
26403
26403
|
if (!oe) continue;
|
|
26404
26404
|
let R2 = JSON.parse(oe);
|
|
26405
|
-
if (c(), j.split(/\r?\n/).some((
|
|
26405
|
+
if (c(), j.split(/\r?\n/).some((P) => P === "event: auth_required")) throw new U(401);
|
|
26406
26406
|
le(R2);
|
|
26407
26407
|
let K2 = R2.kind;
|
|
26408
26408
|
if (!["ready", "committed", "coverage", "resync"].includes(K2)) throw new Error("Invalid resource frame kind");
|
|
@@ -26418,6 +26418,18 @@ var F = class {
|
|
|
26418
26418
|
clearTimeout(o), r.abort(), i.removeEventListener("abort", g), await m2(), l?.releaseLock();
|
|
26419
26419
|
}
|
|
26420
26420
|
}
|
|
26421
|
+
ensureSessionIdentity(t) {
|
|
26422
|
+
return this.post("ensureSessionIdentity", t);
|
|
26423
|
+
}
|
|
26424
|
+
renameIdentity(t) {
|
|
26425
|
+
return this.post("renameIdentity", t);
|
|
26426
|
+
}
|
|
26427
|
+
promoteIdentity() {
|
|
26428
|
+
return this.post("promoteIdentity", {});
|
|
26429
|
+
}
|
|
26430
|
+
listLocalSessions() {
|
|
26431
|
+
return this.post("listLocalSessions", {});
|
|
26432
|
+
}
|
|
26421
26433
|
createIdentity(t) {
|
|
26422
26434
|
return this.post("createIdentity", t);
|
|
26423
26435
|
}
|
|
@@ -26598,7 +26610,7 @@ var F = class {
|
|
|
26598
26610
|
return this.get("/history-storage", true);
|
|
26599
26611
|
}
|
|
26600
26612
|
async readNotificationPage(t, n = {}) {
|
|
26601
|
-
let r = "/identities/" + encodeURIComponent(t) + "/notifications", i = n.kinds?.length ? "&kinds=" + encodeURIComponent(n.kinds.join(",")) : "", o = n.requestTimeoutMs === void 0 ? n.signal : AbortSignal.any([...n.signal ? [n.signal] : [], AbortSignal.timeout(n.requestTimeoutMs)]), s = await this.fetchImpl(
|
|
26613
|
+
let r = "/identities/" + encodeURIComponent(t) + "/notifications", i = n.kinds?.length ? "&kinds=" + encodeURIComponent(n.kinds.join(",")) : "", o = n.requestTimeoutMs === void 0 ? n.signal : AbortSignal.any([...n.signal ? [n.signal] : [], AbortSignal.timeout(n.requestTimeoutMs)]), s = await this.fetchImpl(u2(this.base, r + "?since=" + encodeURIComponent(String(n.since ?? "tip")) + i), { redirect: "error", headers: this.headers(), signal: o }), a;
|
|
26602
26614
|
try {
|
|
26603
26615
|
a = await s.json();
|
|
26604
26616
|
} catch {
|
|
@@ -26615,7 +26627,7 @@ var F = class {
|
|
|
26615
26627
|
for (; !n.signal?.aborted; ) {
|
|
26616
26628
|
let s;
|
|
26617
26629
|
try {
|
|
26618
|
-
let a = await this.fetchImpl(
|
|
26630
|
+
let a = await this.fetchImpl(u2(this.base, `${i}?since=${r}${o}`), { redirect: "error", headers: this.headers(), signal: n.requestTimeoutMs === void 0 ? n.signal : AbortSignal.any([...n.signal ? [n.signal] : [], AbortSignal.timeout(n.requestTimeoutMs)]) });
|
|
26619
26631
|
try {
|
|
26620
26632
|
s = await a.json();
|
|
26621
26633
|
} catch {
|
|
@@ -26631,7 +26643,7 @@ var F = class {
|
|
|
26631
26643
|
}
|
|
26632
26644
|
}
|
|
26633
26645
|
async fetchFile(t) {
|
|
26634
|
-
let n = await this.fetchImpl(
|
|
26646
|
+
let n = await this.fetchImpl(u2(this.base, `/files/${encodeURIComponent(t)}`), { redirect: "error", headers: this.headers() });
|
|
26635
26647
|
if (!n.ok) {
|
|
26636
26648
|
let r = `HTTP ${n.status}`;
|
|
26637
26649
|
try {
|
|
@@ -26644,7 +26656,7 @@ var F = class {
|
|
|
26644
26656
|
return new Uint8Array(await n.arrayBuffer());
|
|
26645
26657
|
}
|
|
26646
26658
|
async openFile(t) {
|
|
26647
|
-
let n = await this.fetchImpl(
|
|
26659
|
+
let n = await this.fetchImpl(u2(this.base, `/files/${encodeURIComponent(t)}`), { redirect: "error", headers: this.headers() });
|
|
26648
26660
|
if (!n.ok) {
|
|
26649
26661
|
let r = `HTTP ${n.status}`;
|
|
26650
26662
|
try {
|
|
@@ -26660,7 +26672,7 @@ var F = class {
|
|
|
26660
26672
|
async uploadFile(t, n) {
|
|
26661
26673
|
let r = t instanceof Uint8Array ? t.byteLength : n.size;
|
|
26662
26674
|
if (r === void 0) throw new Error("uploadFile: `size` is required when the body is a stream (the route needs Content-Length)");
|
|
26663
|
-
let i = await this.fetchImpl(
|
|
26675
|
+
let i = await this.fetchImpl(u2(this.base, "/files/upload"), { redirect: "error", method: "POST", headers: { ...this.headers(), "x-ours-filename": encodeURIComponent(n.filename), "Content-Type": n.mime || "application/octet-stream", "Content-Length": String(r) }, body: t, ...t instanceof Uint8Array ? {} : { duplex: "half" } });
|
|
26664
26676
|
if (!i.ok) {
|
|
26665
26677
|
let o = `HTTP ${i.status}`;
|
|
26666
26678
|
try {
|
|
@@ -26693,7 +26705,7 @@ var x = class extends Error {
|
|
|
26693
26705
|
function Ae(e2 = process.env) {
|
|
26694
26706
|
if (e2.OURS_CONFIG !== void 0) {
|
|
26695
26707
|
if (!e2.OURS_CONFIG.trim()) throw new x("OURS_CONFIG must name a client profile");
|
|
26696
|
-
return
|
|
26708
|
+
return pe(e2.OURS_CONFIG);
|
|
26697
26709
|
}
|
|
26698
26710
|
return Se(e2.HOME || Te(), ".ours-client", "profile.json");
|
|
26699
26711
|
}
|
|
@@ -26717,9 +26729,9 @@ function Re(e2) {
|
|
|
26717
26729
|
} catch {
|
|
26718
26730
|
return t("endpoint must equal serverUrl/daemon");
|
|
26719
26731
|
}
|
|
26720
|
-
return typeof n.expectedInstanceId != "string" || !/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(n.expectedInstanceId) ? t("expectedInstanceId must be a lowercase UUID") : typeof n.credentialPath != "string" || !Oe(n.credentialPath) ||
|
|
26732
|
+
return typeof n.expectedInstanceId != "string" || !/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(n.expectedInstanceId) ? t("expectedInstanceId must be a lowercase UUID") : typeof n.credentialPath != "string" || !Oe(n.credentialPath) || pe(n.credentialPath) !== n.credentialPath ? t("credentialPath must be an absolute normalized path") : Object.freeze({ serverUrl: r, endpoint: i, expectedInstanceId: n.expectedInstanceId, credentialPath: n.credentialPath });
|
|
26721
26733
|
}
|
|
26722
|
-
function
|
|
26734
|
+
function ue(e2 = process.env) {
|
|
26723
26735
|
let t = Ae(e2), n;
|
|
26724
26736
|
try {
|
|
26725
26737
|
n = JSON.parse(m(t).toString("utf8"));
|
|
@@ -26730,14 +26742,14 @@ function pe(e2 = process.env) {
|
|
|
26730
26742
|
if (["OURS_PORT", "OURS_STATE_DIR", "OURS_API_TOKEN", "OURS_DAEMON_ID", "OURS_DAEMON_URL", "OURS_DAEMON_CREDENTIAL_PATH"].some((o) => e2[o]?.trim())) throw new x("remove legacy OURS_PORT/STATE_DIR/API_TOKEN/DAEMON_ID/DAEMON_URL/DAEMON_CREDENTIAL_PATH environment selectors");
|
|
26731
26743
|
return Object.freeze({ ...r, configPath: t });
|
|
26732
26744
|
}
|
|
26733
|
-
var
|
|
26745
|
+
var p = class extends Error {
|
|
26734
26746
|
constructor(n, r) {
|
|
26735
26747
|
super(r);
|
|
26736
26748
|
this.code = n;
|
|
26737
26749
|
this.name = "DaemonSelectionError";
|
|
26738
26750
|
}
|
|
26739
26751
|
};
|
|
26740
|
-
var Y = class extends
|
|
26752
|
+
var Y = class extends p {
|
|
26741
26753
|
constructor(n, r, i = {}) {
|
|
26742
26754
|
super("DAEMON_UNAVAILABLE", `no ours daemon is running at ${D(n)} for state directory ${JSON.stringify(r)}. Install the daemon with \`npm install --global @ours.network/daemon\`, then start the shared daemon with \`ours-daemon start\` or install/start its per-user service through \`ours-daemon install-service\`. SDK applications attach to the shared daemon and do not start an embedded daemon.`);
|
|
26743
26755
|
this.endpoint = n;
|
|
@@ -26747,24 +26759,24 @@ var Y = class extends u2 {
|
|
|
26747
26759
|
};
|
|
26748
26760
|
var me = K.port;
|
|
26749
26761
|
var X = $;
|
|
26750
|
-
var
|
|
26751
|
-
var
|
|
26762
|
+
var Pe = ".ours";
|
|
26763
|
+
var ke = ["explicit", "environment", "config-file"];
|
|
26752
26764
|
function De(e2 = {}) {
|
|
26753
26765
|
let t = e2.env ?? process.env;
|
|
26754
|
-
if (t.OURS_TLS_CERT !== void 0 || t.OURS_TLS_KEY !== void 0) throw new
|
|
26755
|
-
if (e2.endpoint !== void 0 && new URL(e2.endpoint).protocol !== "http:" && new URL(e2.endpoint).protocol !== "https:") throw new
|
|
26766
|
+
if (t.OURS_TLS_CERT !== void 0 || t.OURS_TLS_KEY !== void 0) throw new p("INCOHERENT_SELECTION", "Daemon TLS is not supported in V1; remove OURS_TLS_CERT/OURS_TLS_KEY and explicitly configure HTTP");
|
|
26767
|
+
if (e2.endpoint !== void 0 && new URL(e2.endpoint).protocol !== "http:" && new URL(e2.endpoint).protocol !== "https:") throw new p("INCOHERENT_SELECTION", "Client requires an HTTP or HTTPS daemon endpoint");
|
|
26756
26768
|
let n = e2.readTextFile ?? ((y2) => xe(y2, "utf8")), r = e2.homeDir ?? Ne(), i = M2(t, "OURS_INSTANCE");
|
|
26757
|
-
if (i !== void 0) throw new
|
|
26769
|
+
if (i !== void 0) throw new p("INCOHERENT_SELECTION", `OURS_INSTANCE=${JSON.stringify(i)} is set, but named daemon instances are not implemented. Select the daemon with an explicit endpoint/port option or with OURS_PORT, and unset OURS_INSTANCE.`);
|
|
26758
26770
|
if (e2.stateDir !== void 0 && e2.expectStateDir !== void 0) {
|
|
26759
26771
|
let y2 = H(e2.stateDir), h = H(e2.expectStateDir);
|
|
26760
|
-
if (y2 !== h) throw new
|
|
26772
|
+
if (y2 !== h) throw new p("INCOHERENT_SELECTION", `stateDir ${JSON.stringify(y2)} and expectStateDir ${JSON.stringify(h)} name different directories. The state directory decides which token is read; the expected one decides which daemon that token may be sent to. Reconcile them, or pass only one.`);
|
|
26761
26773
|
}
|
|
26762
|
-
let o = $e(e2.configPath, M2(t, "OURS_CONFIG")), s = o ? Ue(o.value, n) : {}, a = fe(e2.port, Fe(M2(t, "OURS_PORT")), s.port, me), c = fe(e2.stateDir ?? e2.expectStateDir, M2(t, "OURS_STATE_DIR"), s.stateDir, J(r,
|
|
26763
|
-
Ce({ endpointSelected: e2.endpoint !== void 0 || a.source !== "default", endpointSource: f.source, stateDirIntentional:
|
|
26774
|
+
let o = $e(e2.configPath, M2(t, "OURS_CONFIG")), s = o ? Ue(o.value, n) : {}, a = fe(e2.port, Fe(M2(t, "OURS_PORT")), s.port, me), c = fe(e2.stateDir ?? e2.expectStateDir, M2(t, "OURS_STATE_DIR"), s.stateDir, J(r, Pe)), l = { value: H(c.value), source: c.source }, f = e2.endpoint !== void 0 ? { value: w2(e2.endpoint), source: "explicit" } : { value: `http://127.0.0.1:${a.value}`, source: a.source }, m2 = M2(t, "OURS_API_TOKEN");
|
|
26775
|
+
Ce({ endpointSelected: e2.endpoint !== void 0 || a.source !== "default", endpointSource: f.source, stateDirIntentional: ke.includes(l.source), stateDirSource: l.source, hasExplicitToken: e2.token !== void 0 && e2.token !== "", hasEnvToken: m2 !== void 0, requireExplicitSelection: e2.requireExplicitSelection === true, portSource: a.source });
|
|
26764
26776
|
let g = Le(e2.token, m2, s, l, e2.readTextFile);
|
|
26765
26777
|
return { baseUrl: f, port: a, stateDir: l, expectStateDir: e2.expectStateDir !== void 0 ? H(e2.expectStateDir) : l.value, ...g ? { token: g } : {}, ...o ? { configPath: o } : {} };
|
|
26766
26778
|
}
|
|
26767
|
-
function
|
|
26779
|
+
function pn(e2) {
|
|
26768
26780
|
return { baseUrl: e2.baseUrl.value, baseUrlSource: e2.baseUrl.source, port: e2.port.value, portSource: e2.port.source, stateDir: e2.stateDir.value, stateDirSource: e2.stateDir.source, expectStateDir: e2.expectStateDir, tokenSource: e2.token?.source ?? "none", configPath: e2.configPath?.value ?? null };
|
|
26769
26781
|
}
|
|
26770
26782
|
function Ce(e2) {
|
|
@@ -26777,7 +26789,7 @@ function Ce(e2) {
|
|
|
26777
26789
|
if (e2.hasExplicitToken && !e2.stateDirIntentional) throw $2("an explicit token was given, but the state directory is the built-in default, so there would be nothing to assert the daemon against before the token is sent. Pass expectStateDir (or stateDir) naming the state directory that token belongs to.");
|
|
26778
26790
|
}
|
|
26779
26791
|
function $2(e2) {
|
|
26780
|
-
return new
|
|
26792
|
+
return new p("INCOHERENT_SELECTION", e2);
|
|
26781
26793
|
}
|
|
26782
26794
|
function Le(e2, t, n, r, i) {
|
|
26783
26795
|
if (e2 !== void 0 && e2 !== "") return { value: e2, source: "explicit" };
|
|
@@ -26799,33 +26811,33 @@ function Ue(e2, t) {
|
|
|
26799
26811
|
try {
|
|
26800
26812
|
n = t(e2);
|
|
26801
26813
|
} catch {
|
|
26802
|
-
throw new
|
|
26814
|
+
throw new p("CONFIG_UNREADABLE", `the daemon config file ${JSON.stringify(e2)} could not be read.`);
|
|
26803
26815
|
}
|
|
26804
26816
|
let r;
|
|
26805
26817
|
try {
|
|
26806
26818
|
r = JSON.parse(n);
|
|
26807
26819
|
} catch {
|
|
26808
|
-
throw new
|
|
26820
|
+
throw new p("CONFIG_INVALID", `the daemon config file ${JSON.stringify(e2)} is not valid JSON.`);
|
|
26809
26821
|
}
|
|
26810
|
-
if (r === null || typeof r != "object" || Array.isArray(r)) throw new
|
|
26822
|
+
if (r === null || typeof r != "object" || Array.isArray(r)) throw new p("CONFIG_INVALID", `the daemon config file ${JSON.stringify(e2)} is not a JSON object.`);
|
|
26811
26823
|
let i = r, o = {}, s = i.port;
|
|
26812
26824
|
if (s !== void 0) {
|
|
26813
|
-
if (typeof s != "number" || !Number.isInteger(s) || s < 1 || s > 65535) throw new
|
|
26825
|
+
if (typeof s != "number" || !Number.isInteger(s) || s < 1 || s > 65535) throw new p("CONFIG_INVALID", `the daemon config file ${JSON.stringify(e2)} declares an invalid port; expected an integer 1-65535.`);
|
|
26814
26826
|
o.port = s;
|
|
26815
26827
|
}
|
|
26816
26828
|
let a = i.stateDir;
|
|
26817
26829
|
if (a !== void 0) {
|
|
26818
|
-
if (typeof a != "string" || a.trim() === "") throw new
|
|
26830
|
+
if (typeof a != "string" || a.trim() === "") throw new p("CONFIG_INVALID", `the daemon config file ${JSON.stringify(e2)} declares an invalid stateDir; expected a non-empty string.`);
|
|
26819
26831
|
o.stateDir = a;
|
|
26820
26832
|
}
|
|
26821
26833
|
let c = i.apiToken;
|
|
26822
26834
|
if (c !== void 0) {
|
|
26823
|
-
if (typeof c != "string" || c.trim() === "") throw new
|
|
26835
|
+
if (typeof c != "string" || c.trim() === "") throw new p("CONFIG_INVALID", `the daemon config file ${JSON.stringify(e2)} declares an invalid apiToken; expected a non-empty string.`);
|
|
26824
26836
|
o.apiToken = c;
|
|
26825
26837
|
}
|
|
26826
26838
|
let l = i.apiVisibility;
|
|
26827
26839
|
if (l !== void 0) {
|
|
26828
|
-
if (l !== "owner" && l !== "shared" && l !== "open") throw new
|
|
26840
|
+
if (l !== "owner" && l !== "shared" && l !== "open") throw new p("CONFIG_INVALID", `the daemon config file ${JSON.stringify(e2)} declares an unknown apiVisibility ${JSON.stringify(l)}; expected "owner", "shared" or "open".`);
|
|
26829
26841
|
o.apiVisibility = l;
|
|
26830
26842
|
}
|
|
26831
26843
|
return o;
|
|
@@ -26839,7 +26851,7 @@ function M2(e2, t) {
|
|
|
26839
26851
|
function Fe(e2) {
|
|
26840
26852
|
if (e2 === void 0) return;
|
|
26841
26853
|
let t = Number.parseInt(e2, 10);
|
|
26842
|
-
if (!Number.isInteger(t) || t < 1 || t > 65535) throw new
|
|
26854
|
+
if (!Number.isInteger(t) || t < 1 || t > 65535) throw new p("INCOHERENT_SELECTION", `OURS_PORT=${JSON.stringify(e2)} is not a TCP port between 1 and 65535.`);
|
|
26843
26855
|
return t;
|
|
26844
26856
|
}
|
|
26845
26857
|
function fe(e2, t, n, r) {
|
|
@@ -26852,21 +26864,21 @@ function $e(e2, t) {
|
|
|
26852
26864
|
async function Me(e2, t = {}) {
|
|
26853
26865
|
let n = t.fetch ?? globalThis.fetch, r = new AbortController(), i = setTimeout(() => r.abort(), t.timeoutMs ?? 5e3), o;
|
|
26854
26866
|
try {
|
|
26855
|
-
let a = await n(
|
|
26856
|
-
if (!a.ok) throw new
|
|
26867
|
+
let a = await n(u2(e2.baseUrl.value, "/state-dir"), { signal: r.signal, redirect: "error" });
|
|
26868
|
+
if (!a.ok) throw new p("INCOHERENT_SELECTION", `${D(u2(e2.baseUrl.value, "/state-dir"))} answered HTTP ${a.status}, so the daemon at that address could not be identified. Refusing to send a credential to it.`);
|
|
26857
26869
|
o = await a.json();
|
|
26858
26870
|
} catch (a) {
|
|
26859
|
-
throw a instanceof
|
|
26871
|
+
throw a instanceof p ? a : new Y(e2.baseUrl.value, e2.expectStateDir, { cause: a });
|
|
26860
26872
|
} finally {
|
|
26861
26873
|
clearTimeout(i);
|
|
26862
26874
|
}
|
|
26863
26875
|
let s = typeof o.stateDir == "string" ? H(o.stateDir) : null;
|
|
26864
|
-
if (s === null) throw new
|
|
26865
|
-
if (s !== e2.expectStateDir) throw new
|
|
26876
|
+
if (s === null) throw new p("INCOHERENT_SELECTION", `${D(u2(e2.baseUrl.value, "/state-dir"))} did not report a state directory, so this is not an ours daemon or not one this client understands. Refusing to send a credential to it.`);
|
|
26877
|
+
if (s !== e2.expectStateDir) throw new p("INCOHERENT_SELECTION", `the daemon at ${D(e2.baseUrl.value)} owns state directory ${JSON.stringify(s)}, but this selection expects ${JSON.stringify(e2.expectStateDir)}. The token belongs to the expected directory, so it is NOT being sent. Point the endpoint and the state directory at the same daemon.`);
|
|
26866
26878
|
}
|
|
26867
26879
|
async function Q(e2 = {}) {
|
|
26868
26880
|
if (e2.endpoint === void 0 && e2.port === void 0 && e2.stateDir === void 0 && e2.expectStateDir === void 0) {
|
|
26869
|
-
let g =
|
|
26881
|
+
let g = ue({ ...e2.env ?? process.env, ...e2.configPath === void 0 ? {} : { OURS_CONFIG: e2.configPath } });
|
|
26870
26882
|
return Q({ ...e2, endpoint: g.endpoint, expectedInstanceId: g.expectedInstanceId, credentialPath: g.credentialPath, sessionMode: "external", leaseToken: e2.leaseToken ?? W(32).toString("hex"), env: {} });
|
|
26871
26883
|
}
|
|
26872
26884
|
if ("serverCertificate" in e2 && e2.serverCertificate !== void 0) throw new Error("Custom serverCertificate is not supported; HTTPS uses Node certificate trust, including NODE_EXTRA_CA_CERTS");
|
|
@@ -26891,7 +26903,7 @@ async function Q(e2 = {}) {
|
|
|
26891
26903
|
if (i === "external") T2.includes("external-sessions-v1") || T2.push("external-sessions-v1");
|
|
26892
26904
|
else if (T2.includes("external-sessions-v1")) throw new Error("External capabilities require explicit sessionMode: external; refusing local-mode fallback");
|
|
26893
26905
|
{
|
|
26894
|
-
let b2 = await globalThis.fetch(
|
|
26906
|
+
let b2 = await globalThis.fetch(u2(h, "/selection"), { signal: s ? AbortSignal.any([s, AbortSignal.timeout(5e3)]) : AbortSignal.timeout(5e3), redirect: "error" }), _ = await C(b2);
|
|
26895
26907
|
if (!b2.ok || !_ || Object.keys(_).length !== 3 || Object.keys(_).some((O2) => !["schema", "instanceId", "capabilities"].includes(O2)) || _.schema !== 1 || _.instanceId !== a) throw new Error("Daemon instance selection metadata is absent, incompatible or mismatched");
|
|
26896
26908
|
let A2 = _.capabilities;
|
|
26897
26909
|
if (!Array.isArray(A2) || A2.some((O2) => typeof O2 != "string") || T2.some((O2) => !A2.includes(O2))) throw new Error("Daemon does not support the required capabilities; refusing local-mode fallback");
|
|
@@ -27977,6 +27989,10 @@ var WidgetStore = class {
|
|
|
27977
27989
|
return "claimed";
|
|
27978
27990
|
}
|
|
27979
27991
|
};
|
|
27992
|
+
async function routeForCommand(deps) {
|
|
27993
|
+
if (!deps.route().peerCid && deps.ensureBound) await deps.ensureBound("command");
|
|
27994
|
+
return deps.route();
|
|
27995
|
+
}
|
|
27980
27996
|
var stateSchema = { type: "string", maxLength: WIDGET_STATE_MAX_BYTES };
|
|
27981
27997
|
var SEND_SCHEMA = {
|
|
27982
27998
|
type: "object",
|
|
@@ -28036,7 +28052,7 @@ function recordResult(rec, extra = {}) {
|
|
|
28036
28052
|
};
|
|
28037
28053
|
}
|
|
28038
28054
|
async function sendWidgetCommand(deps, args, ctx) {
|
|
28039
|
-
const route = deps
|
|
28055
|
+
const route = await routeForCommand(deps);
|
|
28040
28056
|
const denied = authorize(route, ctx);
|
|
28041
28057
|
if (denied) return denied;
|
|
28042
28058
|
const o = asObject(args);
|
|
@@ -28119,7 +28135,7 @@ async function sendWidgetCommand(deps, args, ctx) {
|
|
|
28119
28135
|
return recordResult(rec);
|
|
28120
28136
|
}
|
|
28121
28137
|
async function updateWidgetCommand(deps, args, ctx) {
|
|
28122
|
-
const route = deps
|
|
28138
|
+
const route = await routeForCommand(deps);
|
|
28123
28139
|
const denied = authorize(route, ctx);
|
|
28124
28140
|
if (denied) return denied;
|
|
28125
28141
|
const o = asObject(args);
|
|
@@ -28259,14 +28275,31 @@ function attachmentMeta(d2, messageId) {
|
|
|
28259
28275
|
mime: d2.mime_type ?? defaults.mime
|
|
28260
28276
|
};
|
|
28261
28277
|
}
|
|
28262
|
-
function
|
|
28278
|
+
function describeFileSendFailure(err) {
|
|
28279
|
+
const e2 = err;
|
|
28280
|
+
if (e2 && e2.code === "FILE_TOO_LARGE" && e2.details) {
|
|
28281
|
+
const num = (v2) => typeof v2 === "number" && Number.isFinite(v2) ? v2 : void 0;
|
|
28282
|
+
const bytes = num(e2.details.bytes);
|
|
28283
|
+
const envelopeBytes = num(e2.details.envelopeBytes);
|
|
28284
|
+
const limit = num(e2.details.limit);
|
|
28285
|
+
return {
|
|
28286
|
+
error: `file not sent: too large for an Ours network transfer (${bytes ?? "?"} bytes; ${envelopeBytes ?? "?"}-byte envelope over the ${limit ?? "?"}-byte network transfer limit)`,
|
|
28287
|
+
error_code: "FILE_TOO_LARGE",
|
|
28288
|
+
...bytes !== void 0 ? { bytes } : {},
|
|
28289
|
+
...envelopeBytes !== void 0 ? { envelope_bytes: envelopeBytes } : {},
|
|
28290
|
+
...limit !== void 0 ? { limit } : {}
|
|
28291
|
+
};
|
|
28292
|
+
}
|
|
28293
|
+
return { error: "file transfer failed" };
|
|
28294
|
+
}
|
|
28295
|
+
function buildAttachment(m2, resolved, fileWireId, fileFailure) {
|
|
28263
28296
|
const d2 = m2.attachment;
|
|
28264
28297
|
if (!d2) return void 0;
|
|
28265
28298
|
const { filename, mime } = attachmentMeta(d2, m2.message_id);
|
|
28266
28299
|
const base = { kind: d2.kind, filename, mime, size: d2.file_size };
|
|
28267
28300
|
if (resolved?.ok) {
|
|
28268
28301
|
if (!fileWireId) {
|
|
28269
|
-
return { ...base, size: d2.file_size ?? resolved.bytes.length, error: "file transfer failed" };
|
|
28302
|
+
return { ...base, size: d2.file_size ?? resolved.bytes.length, ...fileFailure ?? { error: "file transfer failed" } };
|
|
28270
28303
|
}
|
|
28271
28304
|
return { ...base, size: d2.file_size ?? resolved.bytes.length, transport: "send_file", wire_id: fileWireId };
|
|
28272
28305
|
}
|
|
@@ -28275,10 +28308,10 @@ function buildAttachment(m2, resolved, fileWireId) {
|
|
|
28275
28308
|
}
|
|
28276
28309
|
return { ...base, error: "attachment not resolved" };
|
|
28277
28310
|
}
|
|
28278
|
-
function buildEnvelope(m2, resolved, fileWireId, transcription) {
|
|
28311
|
+
function buildEnvelope(m2, resolved, fileWireId, transcription, fileFailure) {
|
|
28279
28312
|
const transcribed = transcription?.status === "ok" && typeof transcription.text === "string";
|
|
28280
28313
|
const text2 = transcribed && m2.text === "" ? transcription.text : m2.text;
|
|
28281
|
-
const attachment = resolved ? buildAttachment(m2, resolved, fileWireId) : void 0;
|
|
28314
|
+
const attachment = resolved ? buildAttachment(m2, resolved, fileWireId, fileFailure) : void 0;
|
|
28282
28315
|
const envelope = {
|
|
28283
28316
|
v: ENVELOPE_VERSION,
|
|
28284
28317
|
source: "telegram",
|
|
@@ -28300,18 +28333,17 @@ function buildEnvelope(m2, resolved, fileWireId, transcription) {
|
|
|
28300
28333
|
};
|
|
28301
28334
|
return JSON.stringify(envelope);
|
|
28302
28335
|
}
|
|
28303
|
-
function buildPlainPayload(m2, resolved, fileWireId, transcription) {
|
|
28336
|
+
function buildPlainPayload(m2, resolved, fileWireId, transcription, fileFailure) {
|
|
28304
28337
|
const transcribed = transcription?.status === "ok" && typeof transcription.text === "string";
|
|
28305
28338
|
const text2 = transcribed && m2.text === "" ? transcription.text : m2.text;
|
|
28306
|
-
|
|
28339
|
+
const lost = m2.attachment && resolved?.ok && !fileWireId ? `[Telegram ${m2.attachment.kind} unavailable: ${fileFailure?.error ?? "file transfer failed"}]` : void 0;
|
|
28340
|
+
if (text2 !== "") return lost && fileFailure ? `${text2}
|
|
28341
|
+
${lost}` : text2;
|
|
28307
28342
|
if (m2.attachment && resolved && !resolved.ok) {
|
|
28308
28343
|
const status = resolved.reason === "too_large" ? "omitted" : "unavailable";
|
|
28309
28344
|
return `[Telegram ${m2.attachment.kind} ${status}: ${resolved.detail}]`;
|
|
28310
28345
|
}
|
|
28311
|
-
|
|
28312
|
-
return `[Telegram ${m2.attachment.kind} unavailable: file transfer failed]`;
|
|
28313
|
-
}
|
|
28314
|
-
return void 0;
|
|
28346
|
+
return lost;
|
|
28315
28347
|
}
|
|
28316
28348
|
|
|
28317
28349
|
// src/stt.ts
|
|
@@ -28906,6 +28938,47 @@ function singleFlight(task) {
|
|
|
28906
28938
|
return Object.assign(run, { idle: () => active ?? Promise.resolve() });
|
|
28907
28939
|
}
|
|
28908
28940
|
|
|
28941
|
+
// src/proxy-binding.ts
|
|
28942
|
+
var CONTAINER_ID = /^[0-9A-F]{64}$/;
|
|
28943
|
+
function makeProxyBinder(deps) {
|
|
28944
|
+
let chain = Promise.resolve();
|
|
28945
|
+
const evaluate = async (reason) => {
|
|
28946
|
+
if (deps.current()) return "kept";
|
|
28947
|
+
let contacts;
|
|
28948
|
+
try {
|
|
28949
|
+
contacts = await deps.listContacts();
|
|
28950
|
+
} catch (err) {
|
|
28951
|
+
deps.log(`proxy agent not bound (${reason}): listing contacts failed: ${String(err)}`);
|
|
28952
|
+
return "error";
|
|
28953
|
+
}
|
|
28954
|
+
if (deps.current()) return "kept";
|
|
28955
|
+
if (contacts.length === 0) return "none";
|
|
28956
|
+
if (contacts.length > 1) {
|
|
28957
|
+
deps.log(`proxy agent not bound (${reason}): the route has ${contacts.length} contacts; widgets stay unavailable until exactly one remains`);
|
|
28958
|
+
return "ambiguous";
|
|
28959
|
+
}
|
|
28960
|
+
const [only] = contacts;
|
|
28961
|
+
if (typeof only.container_id !== "string" || !CONTAINER_ID.test(only.container_id)) {
|
|
28962
|
+
deps.log(`proxy agent not bound (${reason}): the only contact has a malformed container id`);
|
|
28963
|
+
return "invalid";
|
|
28964
|
+
}
|
|
28965
|
+
try {
|
|
28966
|
+
deps.persist(only.container_id);
|
|
28967
|
+
} catch (err) {
|
|
28968
|
+
deps.log(`proxy agent not bound (${reason}): saving the binding failed: ${String(err)}`);
|
|
28969
|
+
return "error";
|
|
28970
|
+
}
|
|
28971
|
+
deps.commit(only.container_id);
|
|
28972
|
+
deps.log(`proxy agent bound (${reason}): "${only.name}" (${only.container_id})`);
|
|
28973
|
+
return "bound";
|
|
28974
|
+
};
|
|
28975
|
+
return (reason) => {
|
|
28976
|
+
const run = chain.then(() => evaluate(reason));
|
|
28977
|
+
chain = run.catch(() => void 0);
|
|
28978
|
+
return run;
|
|
28979
|
+
};
|
|
28980
|
+
}
|
|
28981
|
+
|
|
28909
28982
|
// src/connector.ts
|
|
28910
28983
|
var CONFIG = loadConfig();
|
|
28911
28984
|
var STATE_DIR = CONFIG.stateDir;
|
|
@@ -28929,11 +29002,21 @@ function makeConnection(client, dir, cfg, bot) {
|
|
|
28929
29002
|
drainMessages: singleFlight(() => forwardToTelegram(conn)),
|
|
28930
29003
|
drainFiles: singleFlight(() => forwardFilesToTelegram(conn)),
|
|
28931
29004
|
syncReceipts: singleFlight(() => syncReceiptHistory(conn)),
|
|
29005
|
+
bindProxy: makeProxyBinder({
|
|
29006
|
+
current: () => cfg.peerCid,
|
|
29007
|
+
listContacts: async () => (await client.listContacts()).contacts,
|
|
29008
|
+
persist: (peerCid) => writeMeta(dir, { ...cfg, peerCid }),
|
|
29009
|
+
commit: (peerCid) => {
|
|
29010
|
+
cfg.peerCid = peerCid;
|
|
29011
|
+
},
|
|
29012
|
+
log: (m2) => log(`[${cfg.name}] ${m2}`)
|
|
29013
|
+
}),
|
|
28932
29014
|
widgets: {
|
|
28933
29015
|
route: () => ({ name: cfg.name, chatId: cfg.chatId, threadId: cfg.threadId, peerCid: cfg.peerCid }),
|
|
28934
29016
|
tg: bot.tg,
|
|
28935
29017
|
store: new WidgetStore(dir, (m2) => log(`[${cfg.name}] ${m2}`)),
|
|
28936
|
-
log: (m2) => log(m2)
|
|
29018
|
+
log: (m2) => log(m2),
|
|
29019
|
+
ensureBound: (reason) => conn.bindProxy(reason)
|
|
28937
29020
|
},
|
|
28938
29021
|
watch: null,
|
|
28939
29022
|
watchHandle: null,
|
|
@@ -28967,7 +29050,7 @@ async function attachToDaemon() {
|
|
|
28967
29050
|
const client = await Q({ ...options, leaseToken: randomBytes2(24).toString("hex") });
|
|
28968
29051
|
try {
|
|
28969
29052
|
daemonIdentityNames = new Set((await client.identities()).map((row) => row.name));
|
|
28970
|
-
log(`attached to daemon ${JSON.stringify(legacy ?
|
|
29053
|
+
log(`attached to daemon ${JSON.stringify(legacy ? pn(legacy) : {
|
|
28971
29054
|
endpoint: CONFIG.daemonUrl,
|
|
28972
29055
|
instanceId: CONFIG.daemonInstanceId
|
|
28973
29056
|
})}`);
|
|
@@ -29172,13 +29255,8 @@ function watchRoute(conn) {
|
|
|
29172
29255
|
} else if (event === "contact_accepted" || event === "sibling_contact_added" || event === "local_contact_added") {
|
|
29173
29256
|
const name = String(ev.from ?? ev.name ?? "");
|
|
29174
29257
|
const cid = String(ev.container_id ?? ev.cid ?? "");
|
|
29175
|
-
|
|
29176
|
-
|
|
29177
|
-
writeMeta(conn.dir, cfg);
|
|
29178
|
-
log(`[${cfg.name}] proxy agent connected: "${name}" (${cid})`);
|
|
29179
|
-
} else {
|
|
29180
|
-
log(`[${cfg.name}] contact added: "${name}" (${cid})`);
|
|
29181
|
-
}
|
|
29258
|
+
log(`[${cfg.name}] contact added: "${name}" (${cid})`);
|
|
29259
|
+
await conn.bindProxy(event);
|
|
29182
29260
|
} else if (event === "contact_restored") {
|
|
29183
29261
|
log(`[${cfg.name}] contact "${String(ev.from ?? "")}" restored (re-keyed)`);
|
|
29184
29262
|
}
|
|
@@ -29239,17 +29317,20 @@ async function forwardToNode(conn, m2) {
|
|
|
29239
29317
|
for (const target of targets) {
|
|
29240
29318
|
const replyToWireId = m2.reply_to ? conn.map.findTelegramMessage(String(m2.chat_id), m2.reply_to.message_id) : void 0;
|
|
29241
29319
|
let fileWireId;
|
|
29320
|
+
let fileFailure;
|
|
29242
29321
|
if (m2.attachment && resolved?.ok && sendAudio) {
|
|
29243
29322
|
const meta = attachmentMeta(m2.attachment, m2.message_id);
|
|
29244
29323
|
try {
|
|
29324
|
+
const staged = await client.uploadFile(resolved.bytes, { filename: meta.filename, mime: meta.mime });
|
|
29245
29325
|
const r = await client.sendFile({
|
|
29246
29326
|
contact: target,
|
|
29247
|
-
|
|
29327
|
+
upload_id: staged.upload_id,
|
|
29248
29328
|
filename: meta.filename,
|
|
29249
29329
|
mime: meta.mime,
|
|
29250
29330
|
...replyToWireId ? { reply_to_wire_id: replyToWireId } : {}
|
|
29251
29331
|
});
|
|
29252
29332
|
fileWireId = "wire_id" in r ? r.wire_id : void 0;
|
|
29333
|
+
if (!fileWireId) fileFailure = { error: `file not sent (${r.kind})` };
|
|
29253
29334
|
if (fileWireId && m2.message_id > 0) {
|
|
29254
29335
|
conn.map.record(fileWireId, {
|
|
29255
29336
|
chatId: String(m2.chat_id),
|
|
@@ -29262,10 +29343,11 @@ async function forwardToNode(conn, m2) {
|
|
|
29262
29343
|
log(`[${cfg.name}] sent file ${fileWireId ?? "<unknown>"} but daemon history storage failed`);
|
|
29263
29344
|
}
|
|
29264
29345
|
} catch (err) {
|
|
29346
|
+
fileFailure = describeFileSendFailure(err);
|
|
29265
29347
|
log(`[${cfg.name}] send_file to ${target} failed:`, String(err));
|
|
29266
29348
|
}
|
|
29267
29349
|
}
|
|
29268
|
-
const body = cfg.payloadMode === "plain" ? buildPlainPayload(m2, resolved, fileWireId, transcription) : buildEnvelope(m2, sendAudio ? resolved : void 0, fileWireId, transcription);
|
|
29350
|
+
const body = cfg.payloadMode === "plain" ? buildPlainPayload(m2, resolved, fileWireId, transcription, fileFailure) : buildEnvelope(m2, sendAudio ? resolved : void 0, fileWireId, transcription, fileFailure);
|
|
29269
29351
|
if (body === void 0) continue;
|
|
29270
29352
|
try {
|
|
29271
29353
|
const sent = await client.sendMessage({
|
|
@@ -29599,6 +29681,7 @@ async function restoreConnection(name) {
|
|
|
29599
29681
|
connections.set(name, conn);
|
|
29600
29682
|
const conflict = registerRoute(conn);
|
|
29601
29683
|
if (conflict) throw new Error(conflict);
|
|
29684
|
+
await conn.bindProxy("restore");
|
|
29602
29685
|
await registerWidgetCommands(conn);
|
|
29603
29686
|
watchRoute(conn);
|
|
29604
29687
|
await Promise.all([conn.drainMessages(), conn.drainFiles(), conn.syncReceipts()]);
|
package/docs/telegram-widgets.md
CHANGED
|
@@ -50,9 +50,18 @@ A route offers widgets only when it is pinned to **one private chat**: a positiv
|
|
|
50
50
|
chat id with no topic. Catch-all, group and topic routes advertise no widget
|
|
51
51
|
commands, so `send_command` reports `unsupported_peer`.
|
|
52
52
|
|
|
53
|
-
Only the route's connected agent can use them. That is the
|
|
54
|
-
|
|
55
|
-
argument.
|
|
53
|
+
Only the route's connected agent can use them. That is the route's recorded
|
|
54
|
+
proxy agent (`peerCid`), and the command's sender must be that agent as
|
|
55
|
+
authenticated by ours, never by a name or an argument.
|
|
56
|
+
|
|
57
|
+
A route records its agent once, from the daemon's authenticated contact list, and
|
|
58
|
+
only when the route has **exactly one** contact. It checks when the route starts,
|
|
59
|
+
when a contact is added, and when a widget command arrives while no agent is
|
|
60
|
+
recorded. This also covers routes created before the binding was recorded. A
|
|
61
|
+
recorded agent is never replaced by later contacts. If the route has no contact or
|
|
62
|
+
several, or the contact list cannot be read, or the binding cannot be saved, no
|
|
63
|
+
agent is recorded and widget commands answer `not_authorized`; ordinary messages
|
|
64
|
+
are unaffected. The connector log names the reason (`proxy agent not bound ...`).
|
|
56
65
|
|
|
57
66
|
## Agent usage
|
|
58
67
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ours.network/tg-connector",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"description": "Bridge Telegram bots to ours.network agents \u2014 attaches to an already-running ours daemon and bridges one Telegram chat/topic to one agent per route. Run `ours-tg-connector add_new_connection`.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "FSL-1.1-Apache-2.0",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"test:v1-lifecycle": "node tests/v1-lifecycle.integration.mjs cli"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@ours.network/sdk": "
|
|
41
|
+
"@ours.network/sdk": "6.1.0",
|
|
42
42
|
"undici": "^7.28.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
@@ -47,6 +47,6 @@
|
|
|
47
47
|
"esbuild": "^0.24.2",
|
|
48
48
|
"tsx": "^4.19.0",
|
|
49
49
|
"typescript": "^5.5.4",
|
|
50
|
-
"@ours.network/daemon": "5.0
|
|
50
|
+
"@ours.network/daemon": "5.2.0"
|
|
51
51
|
}
|
|
52
52
|
}
|