@holon-run/agentinbox 1.4.0 → 1.4.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/dist/src/adapters.js
CHANGED
|
@@ -41,7 +41,7 @@ class AdapterRegistry {
|
|
|
41
41
|
defaultDelivery = new NoopDeliveryAdapter();
|
|
42
42
|
feishuDelivery = new feishu_1.FeishuDeliveryAdapter();
|
|
43
43
|
githubDelivery = new github_1.GithubDeliveryAdapter();
|
|
44
|
-
telegramDelivery
|
|
44
|
+
telegramDelivery;
|
|
45
45
|
homeDir;
|
|
46
46
|
remoteModuleRegistry;
|
|
47
47
|
constructor(store, appendSourceEvent, options) {
|
|
@@ -49,11 +49,11 @@ class AdapterRegistry {
|
|
|
49
49
|
this.remoteModuleRegistry = options?.remoteModuleRegistry ?? new remote_modules_1.RemoteSourceModuleRegistry({
|
|
50
50
|
githubCallClient: options?.githubCallClient,
|
|
51
51
|
});
|
|
52
|
+
this.telegramDelivery = new telegram_1.TelegramDeliveryAdapter(options?.telegramClient);
|
|
52
53
|
this.remoteSource = new remote_1.RemoteSourceRuntime(store, appendSourceEvent, {
|
|
53
54
|
homeDir: this.homeDir,
|
|
54
55
|
client: options?.remoteSourceClient,
|
|
55
56
|
moduleRegistry: this.remoteModuleRegistry,
|
|
56
|
-
telegramClient: options?.telegramClient,
|
|
57
57
|
});
|
|
58
58
|
}
|
|
59
59
|
sourceAdapterFor(type) {
|
|
@@ -5,7 +5,6 @@ const uxc_daemon_client_1 = require("@holon-run/uxc-daemon-client");
|
|
|
5
5
|
const paths_1 = require("../paths");
|
|
6
6
|
const util_1 = require("../util");
|
|
7
7
|
const remote_modules_1 = require("./remote_modules");
|
|
8
|
-
const telegram_1 = require("./telegram");
|
|
9
8
|
const REMOTE_SOURCE_TYPES = new Set([
|
|
10
9
|
"remote_source",
|
|
11
10
|
"github_repo",
|
|
@@ -71,14 +70,12 @@ class RemoteSourceRuntime {
|
|
|
71
70
|
errorCounts = new Map();
|
|
72
71
|
nextRetryAt = new Map();
|
|
73
72
|
homeDir;
|
|
74
|
-
telegramClient;
|
|
75
73
|
constructor(store, appendSourceEvent, options) {
|
|
76
74
|
this.store = store;
|
|
77
75
|
this.appendSourceEvent = appendSourceEvent;
|
|
78
76
|
this.moduleRegistry = options?.moduleRegistry ?? new remote_modules_1.RemoteSourceModuleRegistry();
|
|
79
77
|
this.client = options?.client ?? new RpcUxcRemoteSourceClient();
|
|
80
78
|
this.homeDir = options?.homeDir ?? (0, paths_1.resolveAgentInboxHome)(process.env);
|
|
81
|
-
this.telegramClient = options?.telegramClient ?? new telegram_1.TelegramBotApiClient();
|
|
82
79
|
}
|
|
83
80
|
async ensureSource(source) {
|
|
84
81
|
if (!REMOTE_SOURCE_TYPES.has(source.sourceType)) {
|
|
@@ -385,9 +382,6 @@ class RemoteSourceRuntime {
|
|
|
385
382
|
};
|
|
386
383
|
}
|
|
387
384
|
}
|
|
388
|
-
if (source.sourceType === "telegram_bot") {
|
|
389
|
-
return await this.syncTelegramSource(source);
|
|
390
|
-
}
|
|
391
385
|
const module = await this.moduleRegistry.resolve(source, this.homeDir);
|
|
392
386
|
const moduleSource = moduleInputSource(source);
|
|
393
387
|
module.validateConfig(moduleSource);
|
|
@@ -482,70 +476,6 @@ class RemoteSourceRuntime {
|
|
|
482
476
|
this.inFlight.delete(sourceId);
|
|
483
477
|
}
|
|
484
478
|
}
|
|
485
|
-
async syncTelegramSource(source) {
|
|
486
|
-
const config = (0, telegram_1.parseTelegramSourceConfig)(source);
|
|
487
|
-
const botToken = config.botToken ?? tokenFromEnv(config.tokenEnv);
|
|
488
|
-
if (!botToken) {
|
|
489
|
-
throw new Error("Telegram source requires config.botToken or tokenEnv");
|
|
490
|
-
}
|
|
491
|
-
const checkpoint = parseRemoteCheckpoint(source.checkpoint);
|
|
492
|
-
const updates = await this.telegramClient.getUpdates({
|
|
493
|
-
endpoint: config.endpoint,
|
|
494
|
-
botToken,
|
|
495
|
-
offset: checkpoint.telegramCursor?.nextOffset,
|
|
496
|
-
timeout: 0,
|
|
497
|
-
allowedUpdates: config.allowedUpdates,
|
|
498
|
-
});
|
|
499
|
-
let appended = 0;
|
|
500
|
-
let deduped = 0;
|
|
501
|
-
let nextOffset = checkpoint.telegramCursor?.nextOffset ?? 0;
|
|
502
|
-
for (const update of updates) {
|
|
503
|
-
const normalized = (0, telegram_1.normalizeTelegramBotUpdate)(source, config, update);
|
|
504
|
-
const updateId = numberFromUnknown(update.update_id);
|
|
505
|
-
if (updateId !== undefined) {
|
|
506
|
-
nextOffset = Math.max(nextOffset, updateId + 1);
|
|
507
|
-
}
|
|
508
|
-
if (!normalized) {
|
|
509
|
-
continue;
|
|
510
|
-
}
|
|
511
|
-
const result = await this.appendSourceEvent(normalized);
|
|
512
|
-
appended += result.appended;
|
|
513
|
-
deduped += result.deduped;
|
|
514
|
-
}
|
|
515
|
-
const latestSource = this.store.getSource(source.sourceId);
|
|
516
|
-
if (!latestSource) {
|
|
517
|
-
throw new Error(`unknown source: ${source.sourceId}`);
|
|
518
|
-
}
|
|
519
|
-
const observedAt = (0, util_1.nowIso)();
|
|
520
|
-
this.store.updateSourceRuntime(source.sourceId, {
|
|
521
|
-
status: latestSource.status === "paused" ? "paused" : "active",
|
|
522
|
-
checkpoint: JSON.stringify({
|
|
523
|
-
...checkpoint,
|
|
524
|
-
telegramCursor: { nextOffset },
|
|
525
|
-
managedRuntime: {
|
|
526
|
-
status: "running",
|
|
527
|
-
runId: null,
|
|
528
|
-
streamId: null,
|
|
529
|
-
lastError: null,
|
|
530
|
-
updatedAt: observedAt,
|
|
531
|
-
startedAt: checkpoint.managedRuntime?.startedAt ?? observedAt,
|
|
532
|
-
stoppedAt: null,
|
|
533
|
-
},
|
|
534
|
-
lastEventAt: observedAt,
|
|
535
|
-
lastError: null,
|
|
536
|
-
}),
|
|
537
|
-
});
|
|
538
|
-
this.errorCounts.delete(source.sourceId);
|
|
539
|
-
this.nextRetryAt.delete(source.sourceId);
|
|
540
|
-
return {
|
|
541
|
-
sourceId: source.sourceId,
|
|
542
|
-
sourceType: source.sourceType,
|
|
543
|
-
appended,
|
|
544
|
-
deduped,
|
|
545
|
-
eventsRead: updates.length,
|
|
546
|
-
note: "telegram getUpdates poll completed",
|
|
547
|
-
};
|
|
548
|
-
}
|
|
549
479
|
}
|
|
550
480
|
exports.RemoteSourceRuntime = RemoteSourceRuntime;
|
|
551
481
|
function normalizeExpandedSubscriptionPlan(value) {
|
|
@@ -601,25 +531,6 @@ function managedBindingForSource(source) {
|
|
|
601
531
|
function managedSourceBindingKey(namespace, sourceKey) {
|
|
602
532
|
return `${namespace}:${sourceKey}`;
|
|
603
533
|
}
|
|
604
|
-
function tokenFromEnv(name) {
|
|
605
|
-
if (!name) {
|
|
606
|
-
return null;
|
|
607
|
-
}
|
|
608
|
-
const value = process.env[name];
|
|
609
|
-
return typeof value === "string" && value.length > 0 ? value : null;
|
|
610
|
-
}
|
|
611
|
-
function numberFromUnknown(value) {
|
|
612
|
-
if (typeof value === "number" && Number.isFinite(value)) {
|
|
613
|
-
return value;
|
|
614
|
-
}
|
|
615
|
-
if (typeof value === "string" && value.trim().length > 0) {
|
|
616
|
-
const parsed = Number(value);
|
|
617
|
-
if (Number.isFinite(parsed)) {
|
|
618
|
-
return parsed;
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
return undefined;
|
|
622
|
-
}
|
|
623
534
|
function parseRemoteCheckpoint(checkpoint) {
|
|
624
535
|
if (!checkpoint) {
|
|
625
536
|
return {};
|
|
@@ -565,6 +565,7 @@ const TELEGRAM_BOT_MODULE = {
|
|
|
565
565
|
configSchema: [
|
|
566
566
|
{ name: "botToken", type: "string", required: false, description: "Telegram bot token. Prefer tokenEnv for shared/local configuration." },
|
|
567
567
|
{ name: "tokenEnv", type: "string", required: false, description: "Environment variable name containing the Telegram bot token." },
|
|
568
|
+
{ name: "uxcAuth", type: "string", required: false, description: "Optional UXC Telegram auth profile." },
|
|
568
569
|
{ name: "botUsername", type: "string", required: false, description: "Optional bot username used for source host identity." },
|
|
569
570
|
{ name: "chatIds", type: "string[]", required: false, description: "Optional Telegram chat ID allowlist." },
|
|
570
571
|
{ name: "allowedUpdates", type: "string[]", required: false, description: "Optional Telegram Bot API allowed_updates value." },
|
|
@@ -591,13 +592,10 @@ const TELEGRAM_BOT_MODULE = {
|
|
|
591
592
|
const config = (0, telegram_1.parseTelegramSourceConfig)(source);
|
|
592
593
|
return {
|
|
593
594
|
endpoint: config.endpoint ?? telegram_1.TELEGRAM_BOT_API_ENDPOINT,
|
|
594
|
-
operation_id: "getUpdates",
|
|
595
|
+
operation_id: "post:/getUpdates",
|
|
595
596
|
mode: "poll",
|
|
596
597
|
args: {
|
|
597
598
|
timeout: 5,
|
|
598
|
-
...(config.botToken ? { botToken: config.botToken } : {}),
|
|
599
|
-
...(config.tokenEnv ? { tokenEnv: config.tokenEnv } : {}),
|
|
600
|
-
...(config.chatIds && config.chatIds.length > 0 ? { chatIds: config.chatIds } : {}),
|
|
601
599
|
...(config.allowedUpdates && config.allowedUpdates.length > 0 ? { allowed_updates: config.allowedUpdates } : {}),
|
|
602
600
|
},
|
|
603
601
|
poll_config: {
|
|
@@ -611,6 +609,10 @@ const TELEGRAM_BOT_MODULE = {
|
|
|
611
609
|
item_key_pointer: "/update_id",
|
|
612
610
|
},
|
|
613
611
|
},
|
|
612
|
+
options: {
|
|
613
|
+
auth: config.uxcAuth,
|
|
614
|
+
artifact_compaction: false,
|
|
615
|
+
},
|
|
614
616
|
};
|
|
615
617
|
},
|
|
616
618
|
mapRawEvent(rawPayload, source) {
|
|
@@ -203,6 +203,7 @@ function parseTelegramSourceConfig(source) {
|
|
|
203
203
|
const config = source.config ?? {};
|
|
204
204
|
return {
|
|
205
205
|
endpoint: asString(config.endpoint) ?? asString(config.apiBaseUrl) ?? exports.TELEGRAM_BOT_API_ENDPOINT,
|
|
206
|
+
uxcAuth: asString(config.uxcAuth) ?? asString(config.credentialRef) ?? undefined,
|
|
206
207
|
botToken: asString(config.botToken) ?? undefined,
|
|
207
208
|
tokenEnv: asString(config.tokenEnv) ?? undefined,
|
|
208
209
|
botUsername: asString(config.botUsername) ?? undefined,
|