omnius 1.0.74 → 1.0.75
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/index.js +115 -60
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -611640,7 +611640,7 @@ function renderTelegramSubAgentError(username, error) {
|
|
|
611640
611640
|
process.stdout.write(` ${c3.dim("│")} ${c3.red("✘")} @${username}: ${c3.dim(preview)}
|
|
611641
611641
|
`);
|
|
611642
611642
|
}
|
|
611643
|
-
var TELEGRAM_TOOL_ACTION_GROUPS, TELEGRAM_TOOL_ACTION_GROUP, TELEGRAM_TOOL_MUTATING_GROUPS, DEFAULT_TELEGRAM_TOOL_GROUP_POLICY, TELEGRAM_TOOL_BUTTON_LABELS, TELEGRAM_SAFETY_PROMPT, ADMIN_DM_PROMPT, ADMIN_GROUP_PROMPT, TELEGRAM_PUBLIC_SOUL_PROFILE, TELEGRAM_PUBLIC_ORCHESTRATOR_CONTRACT, TELEGRAM_PUBLIC_MEMORY_SCOPE_CONTRACT, TELEGRAM_PUBLIC_VISION_STACK_CONTRACT, GROUP_REPLY_DISCRETION_PROMPT, TELEGRAM_CHAT_MODE_PROMPT, ADMIN_CHAT_PROFILE_PROMPT, TELEGRAM_ACTION_RESPONSE_CONTRACT, TELEGRAM_EXTERNAL_ACQUISITION_CONTRACT, TELEGRAM_STUCK_SELF_TALK_PREFIXES, TELEGRAM_CHAT_HISTORY_LIMIT, TELEGRAM_CONTEXT_RECENT_DEFAULT, TELEGRAM_CONTEXT_LINE_LIMIT, TELEGRAM_CONTEXT_SAMPLE_LIMIT, TELEGRAM_MEMORY_CARD_LIMIT, TELEGRAM_MEMORY_NOTE_LIMIT, TELEGRAM_ASSOCIATIVE_FACT_LIMIT, TELEGRAM_ASSOCIATIVE_USER_FACT_LIMIT, TELEGRAM_ASSOCIATIVE_ACTION_LIMIT, TELEGRAM_ASSOCIATIVE_RELATION_LIMIT, TELEGRAM_MEMORY_STOPWORDS, TELEGRAM_MEMORY_GENERIC_QUERY_TOKENS, TELEGRAM_SUB_AGENT_BOUNDED_OPTIONS, TELEGRAM_PUBLIC_HELP_COMMANDS, TELEGRAM_REMINDER_SLASH_COMMANDS, TELEGRAM_REFLECTION_SLASH_COMMANDS, TELEGRAM_PUBLIC_BOT_COMMAND_NAMES, TELEGRAM_IMAGE_EXTENSIONS, MEDIA_CACHE_TTL_MS, TELEGRAM_CHANNEL_DMN_SWEEP_MS, TELEGRAM_CHANNEL_DMN_IDLE_AFTER_MS, TELEGRAM_CHANNEL_DMN_MIN_INTERVAL_MS, TELEGRAM_CHANNEL_DMN_MIN_MESSAGES, TELEGRAM_PUBLIC_TOOL_QUOTAS, TelegramBridge;
|
|
611643
|
+
var TELEGRAM_TOOL_ACTION_GROUPS, TELEGRAM_TOOL_ACTION_GROUP, TELEGRAM_TOOL_MUTATING_GROUPS, DEFAULT_TELEGRAM_TOOL_GROUP_POLICY, TELEGRAM_TOOL_BUTTON_LABELS, TELEGRAM_SAFETY_PROMPT, ADMIN_DM_PROMPT, ADMIN_GROUP_PROMPT, TELEGRAM_PUBLIC_SOUL_PROFILE, TELEGRAM_PUBLIC_ORCHESTRATOR_CONTRACT, TELEGRAM_PUBLIC_MEMORY_SCOPE_CONTRACT, TELEGRAM_PUBLIC_VISION_STACK_CONTRACT, GROUP_REPLY_DISCRETION_PROMPT, TELEGRAM_CHAT_MODE_PROMPT, ADMIN_CHAT_PROFILE_PROMPT, TELEGRAM_ACTION_RESPONSE_CONTRACT, TELEGRAM_EXTERNAL_ACQUISITION_CONTRACT, TELEGRAM_STUCK_SELF_TALK_PREFIXES, TELEGRAM_CHAT_HISTORY_LIMIT, TELEGRAM_CONTEXT_RECENT_DEFAULT, TELEGRAM_CONTEXT_LINE_LIMIT, TELEGRAM_CONTEXT_SAMPLE_LIMIT, TELEGRAM_MEMORY_CARD_LIMIT, TELEGRAM_MEMORY_NOTE_LIMIT, TELEGRAM_ASSOCIATIVE_FACT_LIMIT, TELEGRAM_ASSOCIATIVE_USER_FACT_LIMIT, TELEGRAM_ASSOCIATIVE_ACTION_LIMIT, TELEGRAM_ASSOCIATIVE_RELATION_LIMIT, TELEGRAM_MEMORY_STOPWORDS, TELEGRAM_MEMORY_GENERIC_QUERY_TOKENS, TELEGRAM_SUB_AGENT_BOUNDED_OPTIONS, TELEGRAM_PUBLIC_HELP_COMMANDS, TELEGRAM_REMINDER_SLASH_COMMANDS, TELEGRAM_REFLECTION_SLASH_COMMANDS, TELEGRAM_PUBLIC_BOT_COMMAND_NAMES, TELEGRAM_IMAGE_EXTENSIONS, MEDIA_CACHE_TTL_MS, TELEGRAM_CHANNEL_DMN_SWEEP_MS, TELEGRAM_CHANNEL_DMN_IDLE_AFTER_MS, TELEGRAM_CHANNEL_DMN_MIN_INTERVAL_MS, TELEGRAM_CHANNEL_DMN_MIN_MESSAGES, TELEGRAM_ALLOWED_UPDATES, TELEGRAM_PUBLIC_TOOL_QUOTAS, TelegramBridge;
|
|
611644
611644
|
var init_telegram_bridge = __esm({
|
|
611645
611645
|
"packages/cli/src/tui/telegram-bridge.ts"() {
|
|
611646
611646
|
"use strict";
|
|
@@ -612026,6 +612026,7 @@ External acquisition contract:
|
|
|
612026
612026
|
TELEGRAM_CHANNEL_DMN_IDLE_AFTER_MS = 10 * 60 * 1e3;
|
|
612027
612027
|
TELEGRAM_CHANNEL_DMN_MIN_INTERVAL_MS = 20 * 60 * 1e3;
|
|
612028
612028
|
TELEGRAM_CHANNEL_DMN_MIN_MESSAGES = 4;
|
|
612029
|
+
TELEGRAM_ALLOWED_UPDATES = ["message", "guest_message", "callback_query", "poll", "message_reaction", "message_reaction_count"];
|
|
612029
612030
|
TELEGRAM_PUBLIC_TOOL_QUOTAS = {
|
|
612030
612031
|
web: { limit: 20, windowMs: 60 * 6e4 },
|
|
612031
612032
|
media: { limit: 30, windowMs: 60 * 6e4 },
|
|
@@ -612055,6 +612056,8 @@ External acquisition contract:
|
|
|
612055
612056
|
repoRoot;
|
|
612056
612057
|
polling = false;
|
|
612057
612058
|
abortController = null;
|
|
612059
|
+
pollLoopPromise = null;
|
|
612060
|
+
pollFatalNotified = false;
|
|
612058
612061
|
lastUpdateId = 0;
|
|
612059
612062
|
state = {
|
|
612060
612063
|
active: false,
|
|
@@ -615671,70 +615674,114 @@ ${TELEGRAM_PUBLIC_ORCHESTRATOR_CONTRACT}`);
|
|
|
615671
615674
|
/** Start polling for Telegram messages */
|
|
615672
615675
|
async start() {
|
|
615673
615676
|
if (this.polling) throw new Error("Telegram bridge already active.");
|
|
615674
|
-
|
|
615675
|
-
|
|
615676
|
-
|
|
615677
|
-
|
|
615678
|
-
|
|
615679
|
-
|
|
615680
|
-
|
|
615681
|
-
|
|
615677
|
+
try {
|
|
615678
|
+
let me;
|
|
615679
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
615680
|
+
try {
|
|
615681
|
+
me = await this.apiCall("getMe");
|
|
615682
|
+
break;
|
|
615683
|
+
} catch (err) {
|
|
615684
|
+
if (attempt === 2) throw err;
|
|
615685
|
+
await new Promise((r2) => setTimeout(r2, 2e3 * (attempt + 1)));
|
|
615686
|
+
}
|
|
615682
615687
|
}
|
|
615683
|
-
|
|
615684
|
-
|
|
615685
|
-
throw new Error(`Invalid Telegram bot token: ${me?.description || "unknown error"}`);
|
|
615686
|
-
}
|
|
615687
|
-
if (me.result?.id) {
|
|
615688
|
-
const botUserId = Number(me.result.id);
|
|
615689
|
-
const globalLockDir = process.env["OMNIUS_TELEGRAM_LOCK_DIR"] ? resolve43(process.env["OMNIUS_TELEGRAM_LOCK_DIR"]) : resolve43(homedir40(), ".omnius", "telegram-runner-state");
|
|
615690
|
-
const lockDirs = /* @__PURE__ */ new Set([globalLockDir]);
|
|
615691
|
-
if (this.repoRoot) {
|
|
615692
|
-
lockDirs.add(resolve43(this.repoRoot, ".omnius", "telegram-runner-state"));
|
|
615688
|
+
if (!me?.ok) {
|
|
615689
|
+
throw new Error(`Invalid Telegram bot token: ${me?.description || "unknown error"}`);
|
|
615693
615690
|
}
|
|
615694
|
-
|
|
615695
|
-
|
|
615696
|
-
|
|
615697
|
-
|
|
615698
|
-
|
|
615691
|
+
if (me.result?.id) {
|
|
615692
|
+
const botUserId = Number(me.result.id);
|
|
615693
|
+
const globalLockDir = process.env["OMNIUS_TELEGRAM_LOCK_DIR"] ? resolve43(process.env["OMNIUS_TELEGRAM_LOCK_DIR"]) : resolve43(homedir40(), ".omnius", "telegram-runner-state");
|
|
615694
|
+
const lockDirs = /* @__PURE__ */ new Set([globalLockDir]);
|
|
615695
|
+
if (this.repoRoot) {
|
|
615696
|
+
lockDirs.add(resolve43(this.repoRoot, ".omnius", "telegram-runner-state"));
|
|
615699
615697
|
}
|
|
615700
|
-
|
|
615701
|
-
|
|
615702
|
-
|
|
615703
|
-
|
|
615704
|
-
|
|
615698
|
+
const claimed = [];
|
|
615699
|
+
try {
|
|
615700
|
+
for (const lockDir of lockDirs) {
|
|
615701
|
+
const lockFile = this.claimTelegramOwnerLock(lockDir, botUserId, me.result.username);
|
|
615702
|
+
claimed.push(lockFile);
|
|
615703
|
+
}
|
|
615704
|
+
this.telegramOwnerLockFiles = claimed;
|
|
615705
|
+
this.telegramOwnerLockFile = claimed[0] ?? null;
|
|
615706
|
+
} catch (e2) {
|
|
615707
|
+
for (const lockFile of claimed) this.releaseTelegramOwnerLock(lockFile);
|
|
615708
|
+
if (e2 instanceof Error && e2.message.startsWith("Telegram bot @")) throw e2;
|
|
615709
|
+
}
|
|
615710
|
+
}
|
|
615711
|
+
this.state = {
|
|
615712
|
+
active: true,
|
|
615713
|
+
botUserId: typeof me.result?.id === "number" ? me.result.id : void 0,
|
|
615714
|
+
botUsername: me.result?.username ?? "unknown",
|
|
615715
|
+
botFirstName: typeof me.result?.first_name === "string" ? me.result.first_name : void 0,
|
|
615716
|
+
supportsGuestQueries: Boolean(me.result?.supports_guest_queries),
|
|
615717
|
+
canReadAllGroupMessages: me.result?.can_read_all_group_messages === true,
|
|
615718
|
+
interactionMode: this.interactionMode,
|
|
615719
|
+
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
615720
|
+
messagesReceived: 0,
|
|
615721
|
+
messagesSent: 0,
|
|
615722
|
+
activeSubAgents: 0
|
|
615723
|
+
};
|
|
615724
|
+
this.botUserId = typeof me.result?.id === "number" ? me.result.id : this.botUserId;
|
|
615725
|
+
this.polling = true;
|
|
615726
|
+
this.pollFatalNotified = false;
|
|
615727
|
+
this.abortController = new AbortController();
|
|
615728
|
+
await this.prepareTelegramLongPolling();
|
|
615729
|
+
try {
|
|
615730
|
+
mkdirSync65(this.mediaCacheDir, { recursive: true });
|
|
615731
|
+
} catch {
|
|
615732
|
+
}
|
|
615733
|
+
try {
|
|
615734
|
+
this.ensureAllTelegramConversationsLoaded();
|
|
615735
|
+
} catch {
|
|
615705
615736
|
}
|
|
615737
|
+
this.mediaCacheCleanupTimer = setInterval(() => this.cleanupMediaCache(), 5 * 60 * 1e3);
|
|
615738
|
+
this.channelDmnTimer = setInterval(() => {
|
|
615739
|
+
this.runTelegramChannelDmnSweep("timer").catch(() => {
|
|
615740
|
+
});
|
|
615741
|
+
}, TELEGRAM_CHANNEL_DMN_SWEEP_MS);
|
|
615742
|
+
this.channelDmnTimer.unref?.();
|
|
615743
|
+
this.pollLoopPromise = this.pollLoop().catch((err) => {
|
|
615744
|
+
if (!this.polling) return;
|
|
615745
|
+
this.stopTelegramPollingAfterFatal(`unexpected poll-loop failure: ${err instanceof Error ? err.message : String(err)}`);
|
|
615746
|
+
}).finally(() => {
|
|
615747
|
+
this.pollLoopPromise = null;
|
|
615748
|
+
});
|
|
615749
|
+
} catch (err) {
|
|
615750
|
+
this.stop();
|
|
615751
|
+
throw err;
|
|
615706
615752
|
}
|
|
615707
|
-
|
|
615708
|
-
|
|
615709
|
-
|
|
615710
|
-
|
|
615711
|
-
|
|
615712
|
-
supportsGuestQueries: Boolean(me.result?.supports_guest_queries),
|
|
615713
|
-
canReadAllGroupMessages: me.result?.can_read_all_group_messages === true,
|
|
615714
|
-
interactionMode: this.interactionMode,
|
|
615715
|
-
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
615716
|
-
messagesReceived: 0,
|
|
615717
|
-
messagesSent: 0,
|
|
615718
|
-
activeSubAgents: 0
|
|
615719
|
-
};
|
|
615720
|
-
this.botUserId = typeof me.result?.id === "number" ? me.result.id : this.botUserId;
|
|
615721
|
-
this.polling = true;
|
|
615722
|
-
this.abortController = new AbortController();
|
|
615723
|
-
try {
|
|
615724
|
-
mkdirSync65(this.mediaCacheDir, { recursive: true });
|
|
615725
|
-
} catch {
|
|
615753
|
+
}
|
|
615754
|
+
async prepareTelegramLongPolling() {
|
|
615755
|
+
const webhook = await this.apiCall("deleteWebhook", { drop_pending_updates: false });
|
|
615756
|
+
if (webhook?.ok === false) {
|
|
615757
|
+
throw new Error(`Telegram long-polling setup failed while clearing webhook: ${this.telegramApiErrorDescription(webhook)}`);
|
|
615726
615758
|
}
|
|
615727
|
-
|
|
615728
|
-
this.
|
|
615729
|
-
|
|
615759
|
+
const probe = await this.apiCall("getUpdates", {
|
|
615760
|
+
offset: this.lastUpdateId + 1,
|
|
615761
|
+
timeout: 0,
|
|
615762
|
+
limit: 1,
|
|
615763
|
+
allowed_updates: TELEGRAM_ALLOWED_UPDATES
|
|
615764
|
+
});
|
|
615765
|
+
if (probe?.ok === false) {
|
|
615766
|
+
throw new Error(`Telegram polling startup failed: ${this.telegramApiErrorDescription(probe)}`);
|
|
615730
615767
|
}
|
|
615731
|
-
|
|
615732
|
-
|
|
615733
|
-
|
|
615734
|
-
|
|
615735
|
-
}
|
|
615736
|
-
|
|
615737
|
-
|
|
615768
|
+
}
|
|
615769
|
+
telegramApiErrorDescription(result) {
|
|
615770
|
+
if (!result) return "unknown Bot API error";
|
|
615771
|
+
const code8 = result["error_code"] !== void 0 ? `${result["error_code"]}: ` : "";
|
|
615772
|
+
return `${code8}${String(result["description"] || result["error"] || "unknown Bot API error")}`;
|
|
615773
|
+
}
|
|
615774
|
+
isFatalTelegramPollingError(result) {
|
|
615775
|
+
const code8 = Number(result?.["error_code"]);
|
|
615776
|
+
const description = String(result?.["description"] || "").toLowerCase();
|
|
615777
|
+
if (code8 === 401 || code8 === 404 || code8 === 409) return true;
|
|
615778
|
+
return description.includes("terminated by other getupdates") || description.includes("webhook") || description.includes("unauthorized") || description.includes("not found");
|
|
615779
|
+
}
|
|
615780
|
+
stopTelegramPollingAfterFatal(reason) {
|
|
615781
|
+
if (this.pollFatalNotified) return;
|
|
615782
|
+
this.pollFatalNotified = true;
|
|
615783
|
+
this.tuiWrite(() => renderWarning(`Telegram polling stopped: ${reason}`));
|
|
615784
|
+
this.stop();
|
|
615738
615785
|
}
|
|
615739
615786
|
/** Stop polling and kill all active sub-agents */
|
|
615740
615787
|
stop() {
|
|
@@ -619836,7 +619883,7 @@ ${caption}\r
|
|
|
619836
619883
|
const result = await this.apiCall("getUpdates", {
|
|
619837
619884
|
offset: this.lastUpdateId + 1,
|
|
619838
619885
|
timeout: 30,
|
|
619839
|
-
allowed_updates:
|
|
619886
|
+
allowed_updates: TELEGRAM_ALLOWED_UPDATES
|
|
619840
619887
|
});
|
|
619841
619888
|
if (result.ok && Array.isArray(result.result)) {
|
|
619842
619889
|
for (const update2 of result.result) {
|
|
@@ -619862,6 +619909,14 @@ ${caption}\r
|
|
|
619862
619909
|
this.onMessage(msg);
|
|
619863
619910
|
}
|
|
619864
619911
|
}
|
|
619912
|
+
} else if (result?.ok === false) {
|
|
619913
|
+
const reason = this.telegramApiErrorDescription(result);
|
|
619914
|
+
if (this.isFatalTelegramPollingError(result)) {
|
|
619915
|
+
this.stopTelegramPollingAfterFatal(reason);
|
|
619916
|
+
return;
|
|
619917
|
+
}
|
|
619918
|
+
this.tuiWrite(() => renderWarning(`Telegram polling warning: ${reason}`));
|
|
619919
|
+
await new Promise((r2) => setTimeout(r2, 5e3));
|
|
619865
619920
|
}
|
|
619866
619921
|
} catch (err) {
|
|
619867
619922
|
if (this.polling) {
|
|
@@ -619881,7 +619936,7 @@ ${caption}\r
|
|
|
619881
619936
|
options2.body = JSON.stringify(body);
|
|
619882
619937
|
}
|
|
619883
619938
|
const isLongPoll = method === "getUpdates";
|
|
619884
|
-
if (this.abortController) {
|
|
619939
|
+
if (isLongPoll && this.abortController) {
|
|
619885
619940
|
options2.signal = this.abortController.signal;
|
|
619886
619941
|
} else if (!isLongPoll) {
|
|
619887
619942
|
options2.signal = AbortSignal.timeout(3e4);
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "omnius",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.75",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "omnius",
|
|
9
|
-
"version": "1.0.
|
|
9
|
+
"version": "1.0.75",
|
|
10
10
|
"bundleDependencies": [
|
|
11
11
|
"image-to-ascii"
|
|
12
12
|
],
|
package/package.json
CHANGED