omnius 1.0.183 → 1.0.185
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 +369 -63
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -574031,6 +574031,8 @@ var init_command_registry = __esm({
|
|
|
574031
574031
|
["/telegram", "Toggle Telegram bridge on/off (uses saved key)"],
|
|
574032
574032
|
["/telegram status", "Show Telegram bridge status"],
|
|
574033
574033
|
["/telegram stop", "Disconnect Telegram bridge"],
|
|
574034
|
+
["/telegram disable", "Persistently disable Telegram long polling"],
|
|
574035
|
+
["/telegram enable", "Re-enable Telegram long polling"],
|
|
574034
574036
|
["/telegram mode auto|chat|action", "Set Telegram interaction routing: auto, fast chat, or action sub-agent"],
|
|
574035
574037
|
["/telegram subagents <1-5>", "Set global Telegram work-slot limit across all chats/groups"],
|
|
574036
574038
|
["/telegram auth", "Show a TUI-only one-time code for Telegram admin authentication"],
|
|
@@ -591154,6 +591156,7 @@ __export(setup_exports, {
|
|
|
591154
591156
|
checkOllamaUpdate: () => checkOllamaUpdate,
|
|
591155
591157
|
checkPythonVenv: () => checkPythonVenv,
|
|
591156
591158
|
checkToolSupport: () => checkToolSupport,
|
|
591159
|
+
classifyOllamaThinkingTreatment: () => classifyOllamaThinkingTreatment,
|
|
591157
591160
|
computeInferenceScore: () => computeInferenceScore,
|
|
591158
591161
|
createExpandedVariant: () => createExpandedVariant,
|
|
591159
591162
|
createExpandedVariantAsync: () => createExpandedVariantAsync,
|
|
@@ -591181,6 +591184,7 @@ __export(setup_exports, {
|
|
|
591181
591184
|
repairAllExpandedVariants: () => repairAllExpandedVariants,
|
|
591182
591185
|
runElevatedCommand: () => runElevatedCommand,
|
|
591183
591186
|
runSetupWizard: () => runSetupWizard,
|
|
591187
|
+
shouldBakeNoThinkIntoOllamaModelfile: () => shouldBakeNoThinkIntoOllamaModelfile,
|
|
591184
591188
|
updateOllama: () => updateOllama
|
|
591185
591189
|
});
|
|
591186
591190
|
import * as readline from "node:readline";
|
|
@@ -592896,23 +592900,26 @@ ${c3.cyan(OMNIUS_FIRST_RUN_BANNER)}
|
|
|
592896
592900
|
const createModelfile = await ask(rl, ` Create optimized model "${c3.bold(customName)}" with ${ctx3.label} context? (Y/n) `);
|
|
592897
592901
|
if (createModelfile.toLowerCase() !== "n") {
|
|
592898
592902
|
try {
|
|
592899
|
-
const
|
|
592900
|
-
const modelfileContent = [
|
|
592901
|
-
`FROM ${selectedVariant.tag}`,
|
|
592902
|
-
`PARAMETER num_ctx ${ctx3.numCtx}`,
|
|
592903
|
-
`PARAMETER temperature 0`,
|
|
592904
|
-
`PARAMETER num_predict ${numPredict}`,
|
|
592905
|
-
`PARAMETER stop "<|endoftext|>"`
|
|
592906
|
-
].join("\n");
|
|
592903
|
+
const modelfileCandidates = expandedVariantContentCandidates(selectedVariant.tag, ctx3.numCtx);
|
|
592907
592904
|
const modelDir2 = join115(homedir37(), ".omnius", "models");
|
|
592908
592905
|
mkdirSync56(modelDir2, { recursive: true });
|
|
592909
592906
|
const modelfilePath = join115(modelDir2, `Modelfile.${customName}`);
|
|
592910
|
-
writeFileSync51(modelfilePath, modelfileContent + "\n", "utf8");
|
|
592911
592907
|
process.stdout.write(` ${c3.dim("Creating model...")} `);
|
|
592912
|
-
|
|
592913
|
-
|
|
592914
|
-
|
|
592915
|
-
|
|
592908
|
+
for (let i2 = 0; i2 < modelfileCandidates.length; i2++) {
|
|
592909
|
+
writeFileSync51(modelfilePath, modelfileCandidates[i2] + "\n", "utf8");
|
|
592910
|
+
try {
|
|
592911
|
+
execSync51(`ollama create ${customName} -f ${modelfilePath}`, {
|
|
592912
|
+
stdio: "pipe",
|
|
592913
|
+
timeout: 12e4
|
|
592914
|
+
});
|
|
592915
|
+
break;
|
|
592916
|
+
} catch (err) {
|
|
592917
|
+
if (i2 === 0 && modelfileCandidates.length > 1 && ollamaCreateNothinkRejected(err)) {
|
|
592918
|
+
continue;
|
|
592919
|
+
}
|
|
592920
|
+
throw err;
|
|
592921
|
+
}
|
|
592922
|
+
}
|
|
592916
592923
|
process.stdout.write(`${c3.green("✔")}
|
|
592917
592924
|
`);
|
|
592918
592925
|
setConfigValue("model", customName);
|
|
@@ -593495,6 +593502,29 @@ function parseShowNumCtx2(show) {
|
|
|
593495
593502
|
}
|
|
593496
593503
|
return 0;
|
|
593497
593504
|
}
|
|
593505
|
+
function classifyOllamaThinkingTreatment(modelName) {
|
|
593506
|
+
const normalized = modelName.replace(/^omnius-/i, "").replace(/:latest$/i, "").toLowerCase();
|
|
593507
|
+
if (/\bgpt[-_]?oss\b/.test(normalized)) return "gpt-oss-levels";
|
|
593508
|
+
if (/(?:^|[-_/:])(?:qwq|qvq)(?:[-_/:]|$)/.test(normalized) || /(?:^|[-_/:])thinking(?:[-_/:]|$)/.test(normalized) || /[-_]thinking(?:[-_/:]|$)/.test(normalized)) {
|
|
593509
|
+
return "thinking-only";
|
|
593510
|
+
}
|
|
593511
|
+
if (/(?:^|[-_/:])qwen3(?:[._-]?\d+)?(?:[-_/:]|$)/.test(normalized) || /(?:^|[-_/:])qwen3(?:vl|omni)(?:[-_/:]|$)/.test(normalized) || /deepseek[-_]?r1/.test(normalized) || /deepseek[-_]?v?3[._-]1/.test(normalized)) {
|
|
593512
|
+
return "toggleable";
|
|
593513
|
+
}
|
|
593514
|
+
return "none";
|
|
593515
|
+
}
|
|
593516
|
+
function shouldBakeNoThinkIntoOllamaModelfile(modelName) {
|
|
593517
|
+
return classifyOllamaThinkingTreatment(modelName) === "toggleable";
|
|
593518
|
+
}
|
|
593519
|
+
function parseShowNoThink(show) {
|
|
593520
|
+
const sources = [show.parameters, show.modelfile];
|
|
593521
|
+
for (const source of sources) {
|
|
593522
|
+
if (!source) continue;
|
|
593523
|
+
if (/\b(?:PARAMETER\s+)?nothink\s+(?:true|1|on|yes)\b/i.test(source)) return true;
|
|
593524
|
+
if (/\b(?:PARAMETER\s+)?think\s+(?:false|0|off|no)\b/i.test(source)) return true;
|
|
593525
|
+
}
|
|
593526
|
+
return false;
|
|
593527
|
+
}
|
|
593498
593528
|
async function checkExpandedVariant(modelName, backendUrl2) {
|
|
593499
593529
|
if (modelName.startsWith("omnius-")) return null;
|
|
593500
593530
|
try {
|
|
@@ -593574,7 +593604,7 @@ async function readExpandedVariantState(backendUrl2, modelName) {
|
|
|
593574
593604
|
if (baseModel && (baseModel.startsWith("/") || /blobs\/sha256[-:]/.test(baseModel))) {
|
|
593575
593605
|
baseModel = null;
|
|
593576
593606
|
}
|
|
593577
|
-
return { currentNumCtx, baseModel };
|
|
593607
|
+
return { currentNumCtx, baseModel, hasNoThink: parseShowNoThink(showData) };
|
|
593578
593608
|
} catch {
|
|
593579
593609
|
return null;
|
|
593580
593610
|
}
|
|
@@ -593582,50 +593612,93 @@ async function readExpandedVariantState(backendUrl2, modelName) {
|
|
|
593582
593612
|
function stripVariantTag(modelName) {
|
|
593583
593613
|
return modelName.replace(/:latest$/i, "");
|
|
593584
593614
|
}
|
|
593585
|
-
function createExpandedVariantContent(baseModel, numCtx) {
|
|
593615
|
+
function createExpandedVariantContent(baseModel, numCtx, options2 = {}) {
|
|
593586
593616
|
if (baseModel.startsWith("/") || /blobs\/sha256[-:]/.test(baseModel)) {
|
|
593587
593617
|
throw new Error(
|
|
593588
593618
|
`createExpandedVariantContent: refusing to use blob-path base "${baseModel}". Pass the user-facing model name (e.g. "qwen3.6:latest") instead.`
|
|
593589
593619
|
);
|
|
593590
593620
|
}
|
|
593591
593621
|
const numPredict = Math.min(16384, Math.max(2048, Math.floor(numCtx * 0.25)));
|
|
593592
|
-
|
|
593622
|
+
const lines = [
|
|
593593
593623
|
`FROM ${baseModel}`,
|
|
593594
593624
|
`PARAMETER num_ctx ${numCtx}`,
|
|
593625
|
+
...options2.includeNoThink ? [
|
|
593626
|
+
`# Keep toggleable reasoning models in direct-answer mode by default.`,
|
|
593627
|
+
`PARAMETER nothink true`
|
|
593628
|
+
] : [],
|
|
593595
593629
|
`PARAMETER temperature 0`,
|
|
593596
593630
|
`PARAMETER num_predict ${numPredict}`,
|
|
593597
593631
|
`PARAMETER stop "<|endoftext|>"`
|
|
593632
|
+
];
|
|
593633
|
+
return lines.join("\n");
|
|
593634
|
+
}
|
|
593635
|
+
function expandedVariantContentCandidates(baseModel, numCtx) {
|
|
593636
|
+
if (!shouldBakeNoThinkIntoOllamaModelfile(baseModel)) {
|
|
593637
|
+
return [createExpandedVariantContent(baseModel, numCtx)];
|
|
593638
|
+
}
|
|
593639
|
+
return [
|
|
593640
|
+
createExpandedVariantContent(baseModel, numCtx, { includeNoThink: true }),
|
|
593641
|
+
createExpandedVariantContent(baseModel, numCtx, { includeNoThink: false })
|
|
593642
|
+
];
|
|
593643
|
+
}
|
|
593644
|
+
function ollamaCreateNothinkRejected(err) {
|
|
593645
|
+
const anyErr = err;
|
|
593646
|
+
const text = [
|
|
593647
|
+
anyErr?.stderr?.toString?.() ?? "",
|
|
593648
|
+
anyErr?.stdout?.toString?.() ?? "",
|
|
593649
|
+
anyErr?.message ?? ""
|
|
593598
593650
|
].join("\n");
|
|
593651
|
+
return /nothink|unknown parameter|invalid parameter|unsupported parameter/i.test(text);
|
|
593599
593652
|
}
|
|
593600
593653
|
function createExpandedVariantNamed(targetModel, baseModel, specs, sizeGB, kvBytesPerToken, archMax) {
|
|
593601
593654
|
const ctx3 = calculateExpandedVariantContextWindow(specs, sizeGB, kvBytesPerToken, archMax);
|
|
593602
|
-
const
|
|
593655
|
+
const modelfileCandidates = expandedVariantContentCandidates(baseModel, ctx3.numCtx);
|
|
593603
593656
|
try {
|
|
593604
593657
|
const modelDir2 = join115(homedir37(), ".omnius", "models");
|
|
593605
593658
|
mkdirSync56(modelDir2, { recursive: true });
|
|
593606
593659
|
const modelfilePath = join115(modelDir2, `Modelfile.${targetModel}`);
|
|
593607
|
-
|
|
593608
|
-
|
|
593609
|
-
|
|
593610
|
-
|
|
593611
|
-
|
|
593612
|
-
|
|
593660
|
+
for (let i2 = 0; i2 < modelfileCandidates.length; i2++) {
|
|
593661
|
+
writeFileSync51(modelfilePath, modelfileCandidates[i2] + "\n", "utf8");
|
|
593662
|
+
try {
|
|
593663
|
+
execSync51(`ollama create ${targetModel} -f ${modelfilePath}`, {
|
|
593664
|
+
stdio: "pipe",
|
|
593665
|
+
timeout: 12e4
|
|
593666
|
+
});
|
|
593667
|
+
return targetModel;
|
|
593668
|
+
} catch (err) {
|
|
593669
|
+
if (i2 === 0 && modelfileCandidates.length > 1 && ollamaCreateNothinkRejected(err)) {
|
|
593670
|
+
continue;
|
|
593671
|
+
}
|
|
593672
|
+
throw err;
|
|
593673
|
+
}
|
|
593674
|
+
}
|
|
593675
|
+
return null;
|
|
593613
593676
|
} catch {
|
|
593614
593677
|
return null;
|
|
593615
593678
|
}
|
|
593616
593679
|
}
|
|
593617
593680
|
async function createExpandedVariantNamedAsync(targetModel, baseModel, specs, sizeGB, kvBytesPerToken, archMax) {
|
|
593618
593681
|
const ctx3 = calculateExpandedVariantContextWindow(specs, sizeGB, kvBytesPerToken, archMax);
|
|
593619
|
-
const
|
|
593682
|
+
const modelfileCandidates = expandedVariantContentCandidates(baseModel, ctx3.numCtx);
|
|
593620
593683
|
try {
|
|
593621
593684
|
const modelDir2 = join115(homedir37(), ".omnius", "models");
|
|
593622
593685
|
mkdirSync56(modelDir2, { recursive: true });
|
|
593623
593686
|
const modelfilePath = join115(modelDir2, `Modelfile.${targetModel}`);
|
|
593624
|
-
|
|
593625
|
-
|
|
593626
|
-
|
|
593627
|
-
|
|
593628
|
-
|
|
593687
|
+
for (let i2 = 0; i2 < modelfileCandidates.length; i2++) {
|
|
593688
|
+
writeFileSync51(modelfilePath, modelfileCandidates[i2] + "\n", "utf8");
|
|
593689
|
+
try {
|
|
593690
|
+
await execAsync2(`ollama create ${targetModel} -f ${modelfilePath}`, {
|
|
593691
|
+
timeout: 12e4
|
|
593692
|
+
});
|
|
593693
|
+
return targetModel;
|
|
593694
|
+
} catch (err) {
|
|
593695
|
+
if (i2 === 0 && modelfileCandidates.length > 1 && ollamaCreateNothinkRejected(err)) {
|
|
593696
|
+
continue;
|
|
593697
|
+
}
|
|
593698
|
+
throw err;
|
|
593699
|
+
}
|
|
593700
|
+
}
|
|
593701
|
+
return null;
|
|
593629
593702
|
} catch {
|
|
593630
593703
|
return null;
|
|
593631
593704
|
}
|
|
@@ -606952,6 +607025,10 @@ Clone a new voice: /voice clone <wav-file> [name]`);
|
|
|
606952
607025
|
renderWarning(
|
|
606953
607026
|
"OMNIUS_FORCE_NO_THINK=1 forces off regardless of /think setting"
|
|
606954
607027
|
);
|
|
607028
|
+
else if (cur && process.env["OMNIUS_ENABLE_THINKING"] !== "1")
|
|
607029
|
+
renderWarning(
|
|
607030
|
+
"OMNIUS_ENABLE_THINKING is not set; /think is saved but backend requests remain direct-answer mode."
|
|
607031
|
+
);
|
|
606955
607032
|
return "handled";
|
|
606956
607033
|
}
|
|
606957
607034
|
if (token === "auto") {
|
|
@@ -606990,6 +607067,11 @@ Clone a new voice: /voice clone <wav-file> [name]`);
|
|
|
606990
607067
|
renderInfo(
|
|
606991
607068
|
"Note: max_tokens will auto-raise to ≥4096 per request to prevent <think> truncation."
|
|
606992
607069
|
);
|
|
607070
|
+
if (process.env["OMNIUS_ENABLE_THINKING"] !== "1") {
|
|
607071
|
+
renderWarning(
|
|
607072
|
+
"Thinking is hard-disabled by default. Set OMNIUS_ENABLE_THINKING=1 before launch for /think on or /think auto to affect backend requests."
|
|
607073
|
+
);
|
|
607074
|
+
}
|
|
606993
607075
|
}
|
|
606994
607076
|
return "handled";
|
|
606995
607077
|
}
|
|
@@ -609199,6 +609281,27 @@ sleep 1
|
|
|
609199
609281
|
}
|
|
609200
609282
|
return "handled";
|
|
609201
609283
|
}
|
|
609284
|
+
if (parts[0] === "disable" || parts[0] === "disabled") {
|
|
609285
|
+
const hasGlobalFlagDisable = parts.includes("--global");
|
|
609286
|
+
const projectRootDisable = ctx3.repoRoot || process.cwd();
|
|
609287
|
+
const projectHasOmniusDisable = existsSync110(join122(projectRootDisable, ".omnius"));
|
|
609288
|
+
const wantsLocalDisable = hasGlobalFlagDisable ? false : isLocal || projectHasOmniusDisable;
|
|
609289
|
+
if (ctx3.isTelegramActive?.()) ctx3.telegramStop?.();
|
|
609290
|
+
ctx3.saveTelegramSettings?.({ enabled: false, local: wantsLocalDisable });
|
|
609291
|
+
renderInfo(`Telegram polling disabled${wantsLocalDisable ? " (project)" : " (global)"}.`);
|
|
609292
|
+
renderInfo("Use /telegram enable to allow polling again.");
|
|
609293
|
+
return "handled";
|
|
609294
|
+
}
|
|
609295
|
+
if (parts[0] === "enable" || parts[0] === "enabled") {
|
|
609296
|
+
const hasGlobalFlagEnable = parts.includes("--global");
|
|
609297
|
+
const projectRootEnable = ctx3.repoRoot || process.cwd();
|
|
609298
|
+
const projectHasOmniusEnable = existsSync110(join122(projectRootEnable, ".omnius"));
|
|
609299
|
+
const wantsLocalEnable = hasGlobalFlagEnable ? false : isLocal || projectHasOmniusEnable;
|
|
609300
|
+
ctx3.saveTelegramSettings?.({ enabled: true, local: wantsLocalEnable });
|
|
609301
|
+
renderInfo(`Telegram polling enabled${wantsLocalEnable ? " (project)" : " (global)"}.`);
|
|
609302
|
+
renderInfo("Use /telegram to start the bridge.");
|
|
609303
|
+
return "handled";
|
|
609304
|
+
}
|
|
609202
609305
|
if (parts[0] === "status") {
|
|
609203
609306
|
ctx3.telegramStatus?.();
|
|
609204
609307
|
return "handled";
|
|
@@ -609553,8 +609656,9 @@ sleep 1
|
|
|
609553
609656
|
"No .omnius/ in the current directory; this 'local' setting was written to ./.omnius/settings.json and only applies when omnius is invoked from this folder."
|
|
609554
609657
|
);
|
|
609555
609658
|
}
|
|
609659
|
+
const savedTelegramState = ctx3.getTelegramSettings?.(wantsLocal ? "project" : "global");
|
|
609556
609660
|
if (!ctx3.isTelegramActive?.() && settings.key)
|
|
609557
|
-
renderInfo("Use /telegram to start.");
|
|
609661
|
+
renderInfo(savedTelegramState?.enabled === false ? "Telegram polling is disabled; use /telegram enable before starting." : "Use /telegram to start.");
|
|
609558
609662
|
return "handled";
|
|
609559
609663
|
}
|
|
609560
609664
|
if (parts.length === 1 && parts[0] === "--global") {
|
|
@@ -609568,6 +609672,11 @@ sleep 1
|
|
|
609568
609672
|
renderInfo("Set one with /telegram --key <bot-token> --global, or use /telegram --key <bot-token> for this project.");
|
|
609569
609673
|
return "handled";
|
|
609570
609674
|
}
|
|
609675
|
+
if (settings.enabled === false) {
|
|
609676
|
+
renderWarning("Global Telegram polling is disabled.");
|
|
609677
|
+
renderInfo("Use /telegram enable --global before starting the shared bot.");
|
|
609678
|
+
return "handled";
|
|
609679
|
+
}
|
|
609571
609680
|
try {
|
|
609572
609681
|
await ctx3.telegramStart?.(settings.key, settings.admin, "global");
|
|
609573
609682
|
} catch (err) {
|
|
@@ -609593,6 +609702,11 @@ sleep 1
|
|
|
609593
609702
|
}
|
|
609594
609703
|
return "handled";
|
|
609595
609704
|
}
|
|
609705
|
+
if (settings.enabled === false) {
|
|
609706
|
+
renderWarning("Telegram polling is disabled.");
|
|
609707
|
+
renderInfo("Use /telegram enable to allow polling again.");
|
|
609708
|
+
return "handled";
|
|
609709
|
+
}
|
|
609596
609710
|
try {
|
|
609597
609711
|
const startProjectRoot = ctx3.repoRoot || process.cwd();
|
|
609598
609712
|
if (existsSync110(join122(startProjectRoot, ".omnius"))) {
|
|
@@ -609627,6 +609741,8 @@ sleep 1
|
|
|
609627
609741
|
renderInfo("Usage:");
|
|
609628
609742
|
renderInfo(" /telegram --key <token> Save bot token (project-local when .omnius/ exists)");
|
|
609629
609743
|
renderInfo(" /telegram --admin <id> Set admin filter (project-local by default)");
|
|
609744
|
+
renderInfo(" /telegram disable Disable long polling persistently");
|
|
609745
|
+
renderInfo(" /telegram enable Re-enable long polling");
|
|
609630
609746
|
renderInfo(" /telegram revoke [--global] Revoke saved admin access");
|
|
609631
609747
|
renderInfo(" /telegram Toggle on/off");
|
|
609632
609748
|
renderInfo(" /telegram --global Start/stop legacy shared global token explicitly");
|
|
@@ -610433,7 +610549,9 @@ async function showPlatformOnboardingMenu(ctx3, id) {
|
|
|
610433
610549
|
{ key: "telegram-admin", label: "Set admin user id", detail: "Restricts remote admin controls" },
|
|
610434
610550
|
{ key: "telegram-mode", label: "Interaction mode", detail: ctx3.getTelegramSettings?.()?.mode ?? "auto" },
|
|
610435
610551
|
{ key: "telegram-start", label: "Start bridge", detail: "Uses saved token" },
|
|
610436
|
-
{ key: "telegram-stop", label: "Stop bridge", detail: "Disconnect long polling" }
|
|
610552
|
+
{ key: "telegram-stop", label: "Stop bridge", detail: "Disconnect long polling" },
|
|
610553
|
+
{ key: "telegram-disable", label: "Disable polling", detail: "Persistently block getUpdates" },
|
|
610554
|
+
{ key: "telegram-enable", label: "Enable polling", detail: "Allow getUpdates again" }
|
|
610437
610555
|
] : [
|
|
610438
610556
|
{ key: "enable", label: "Enable adapter", detail: current.enabled ? "currently enabled" : "currently disabled" },
|
|
610439
610557
|
{ key: "disable", label: "Disable adapter", detail: current.enabled ? "currently enabled" : "currently disabled" },
|
|
@@ -610519,11 +610637,20 @@ async function showPlatformOnboardingMenu(ctx3, id) {
|
|
|
610519
610637
|
} else if (result.key === "telegram-start") {
|
|
610520
610638
|
const settings = ctx3.getTelegramSettings?.() ?? {};
|
|
610521
610639
|
if (!settings.key) renderWarning("No Telegram bot token configured.");
|
|
610522
|
-
else if (
|
|
610640
|
+
else if (settings.enabled === false) {
|
|
610641
|
+
renderWarning("Telegram polling is disabled. Use /telegram enable first.");
|
|
610642
|
+
} else if (ctx3.isTelegramActive?.()) {
|
|
610523
610643
|
renderWarning("Telegram bridge already active. Use /telegram stop before restarting.");
|
|
610524
610644
|
} else await ctx3.telegramStart?.(settings.key, settings.admin, settings.keyScope ?? "project");
|
|
610525
610645
|
} else if (result.key === "telegram-stop") {
|
|
610526
610646
|
ctx3.telegramStop?.();
|
|
610647
|
+
} else if (result.key === "telegram-disable") {
|
|
610648
|
+
if (ctx3.isTelegramActive?.()) ctx3.telegramStop?.();
|
|
610649
|
+
ctx3.saveTelegramSettings?.({ enabled: false });
|
|
610650
|
+
renderInfo("Telegram polling disabled.");
|
|
610651
|
+
} else if (result.key === "telegram-enable") {
|
|
610652
|
+
ctx3.saveTelegramSettings?.({ enabled: true });
|
|
610653
|
+
renderInfo("Telegram polling enabled.");
|
|
610527
610654
|
}
|
|
610528
610655
|
return;
|
|
610529
610656
|
}
|
|
@@ -630844,7 +630971,7 @@ function renderTelegramSubAgentError(username, error) {
|
|
|
630844
630971
|
process.stdout.write(` ${c3.dim("│")} ${c3.magenta("✘")} @${username}: ${c3.dim(preview)}
|
|
630845
630972
|
`);
|
|
630846
630973
|
}
|
|
630847
|
-
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_LINK_INTEGRITY_CONTRACT, TELEGRAM_INTERACTION_DECISION_RESPONSE_FORMAT, TELEGRAM_INTERACTION_DECISION_MINIMAL_SCHEMA, TELEGRAM_INTERACTION_DECISION_REPAIR_SCHEMA, TELEGRAM_CHAT_REPLY_RESPONSE_FORMAT, TELEGRAM_SPACED_URL_RE, TELEGRAM_HTTP_URL_RE, 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_SUB_AGENT_DEFAULT_LIMIT, TELEGRAM_SUB_AGENT_MAX_LIMIT, TELEGRAM_SUB_AGENT_BURST_CONTEXT_LIMIT, TELEGRAM_ADMIN_LIVE_PANEL_PAGES, TELEGRAM_ADMIN_LIVE_MUTATION_TOOLS, TELEGRAM_PUBLIC_HELP_COMMANDS2, 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;
|
|
630974
|
+
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_LINK_INTEGRITY_CONTRACT, TELEGRAM_INTERACTION_DECISION_RESPONSE_FORMAT, TELEGRAM_INTERACTION_DECISION_MINIMAL_SCHEMA, TELEGRAM_INTERACTION_DECISION_REPAIR_SCHEMA, TELEGRAM_CHAT_REPLY_RESPONSE_FORMAT, TELEGRAM_SPACED_URL_RE, TELEGRAM_HTTP_URL_RE, 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_SUB_AGENT_DEFAULT_LIMIT, TELEGRAM_SUB_AGENT_MAX_LIMIT, TELEGRAM_SUB_AGENT_BURST_CONTEXT_LIMIT, TELEGRAM_ADMIN_LIVE_PANEL_PAGES, TELEGRAM_ADMIN_LIVE_MUTATION_TOOLS, TELEGRAM_PUBLIC_HELP_COMMANDS2, 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_DEFAULT_LONG_POLL_TIMEOUT_SECONDS, TELEGRAM_DEFAULT_ROUTER_MODEL_CANDIDATES, TELEGRAM_PUBLIC_TOOL_QUOTAS, TelegramBridge;
|
|
630848
630975
|
var init_telegram_bridge = __esm({
|
|
630849
630976
|
"packages/cli/src/tui/telegram-bridge.ts"() {
|
|
630850
630977
|
"use strict";
|
|
@@ -631288,6 +631415,21 @@ Telegram link integrity contract:
|
|
|
631288
631415
|
TELEGRAM_CHANNEL_DMN_MIN_INTERVAL_MS = 20 * 60 * 1e3;
|
|
631289
631416
|
TELEGRAM_CHANNEL_DMN_MIN_MESSAGES = 4;
|
|
631290
631417
|
TELEGRAM_ALLOWED_UPDATES = ["message", "guest_message", "callback_query", "poll", "message_reaction", "message_reaction_count"];
|
|
631418
|
+
TELEGRAM_DEFAULT_LONG_POLL_TIMEOUT_SECONDS = 50;
|
|
631419
|
+
TELEGRAM_DEFAULT_ROUTER_MODEL_CANDIDATES = [
|
|
631420
|
+
"qwen3:0.6b",
|
|
631421
|
+
"qwen3:1.7b",
|
|
631422
|
+
"qwen3:4b",
|
|
631423
|
+
"qwen3:8b",
|
|
631424
|
+
"qwen2.5:3b",
|
|
631425
|
+
"qwen2.5:7b",
|
|
631426
|
+
"llama3.2:1b",
|
|
631427
|
+
"llama3.2:3b",
|
|
631428
|
+
"gemma3:1b",
|
|
631429
|
+
"gemma3:4b",
|
|
631430
|
+
"phi3:mini",
|
|
631431
|
+
"phi4-mini:latest"
|
|
631432
|
+
];
|
|
631291
631433
|
TELEGRAM_PUBLIC_TOOL_QUOTAS = {
|
|
631292
631434
|
web: { limit: 20, windowMs: 60 * 6e4 },
|
|
631293
631435
|
media: { limit: 30, windowMs: 60 * 6e4 },
|
|
@@ -631321,6 +631463,7 @@ Telegram link integrity contract:
|
|
|
631321
631463
|
pollLoopPromise = null;
|
|
631322
631464
|
pollFatalNotified = false;
|
|
631323
631465
|
lastUpdateId = 0;
|
|
631466
|
+
telegramRouterModelCache = null;
|
|
631324
631467
|
state = {
|
|
631325
631468
|
active: false,
|
|
631326
631469
|
botUserId: void 0,
|
|
@@ -635427,7 +635570,7 @@ ${this.quoteTelegramContextBlock(msg.text, 1200)}`,
|
|
|
635427
635570
|
},
|
|
635428
635571
|
inferenceKind,
|
|
635429
635572
|
sessionKey,
|
|
635430
|
-
{ stream: false, reason: "router-json" }
|
|
635573
|
+
{ stream: false, reason: "router-json", modelName: diagnostics?.backendModel }
|
|
635431
635574
|
);
|
|
635432
635575
|
const visible = jsonModeResult.choices.some(
|
|
635433
635576
|
(choice) => stripTelegramHiddenThinking(choice.message.content ?? "").trim().length > 0
|
|
@@ -635483,7 +635626,7 @@ ${this.quoteTelegramContextBlock(msg.text, 1200)}`,
|
|
|
635483
635626
|
suppressed,
|
|
635484
635627
|
inferenceKind,
|
|
635485
635628
|
sessionKey,
|
|
635486
|
-
{ stream: false, reason: "router-plain-retry" }
|
|
635629
|
+
{ stream: false, reason: "router-plain-retry", modelName: diagnostics?.backendModel }
|
|
635487
635630
|
);
|
|
635488
635631
|
if (diagnostics) {
|
|
635489
635632
|
const plainVisible = plainResult.choices.some(
|
|
@@ -635536,7 +635679,7 @@ ${this.quoteTelegramContextBlock(msg.text, 1200)}`,
|
|
|
635536
635679
|
* hard-deadline retire path becomes diagnosable instead of opaque
|
|
635537
635680
|
*/
|
|
635538
635681
|
async telegramObservableInference(backend, request, kind, sessionKey, options2 = {}) {
|
|
635539
|
-
const model = this.agentConfig?.model ?? "?";
|
|
635682
|
+
const model = options2.modelName ?? this.agentConfig?.model ?? "?";
|
|
635540
635683
|
const promptTokens = estimatePromptTokensFromRequest(request);
|
|
635541
635684
|
const broker = getModelBroker();
|
|
635542
635685
|
const trainCtx = await broker.getNctxTrain(model).catch(() => null);
|
|
@@ -635570,7 +635713,7 @@ ${this.quoteTelegramContextBlock(msg.text, 1200)}`,
|
|
|
635570
635713
|
if (!streamAllowed && process.env["OMNIUS_BROKER_TRACE"] === "1") {
|
|
635571
635714
|
this.tuiWrite(() => renderTelegramSubAgentEvent(
|
|
635572
635715
|
sessionKey,
|
|
635573
|
-
`inference ${id}: non-stream direct (${options2.reason ?? "requested"}) ${this.telegramInferenceRequestDiagnostic(requestWithCtx)}`
|
|
635716
|
+
`inference ${id}: non-stream direct (${options2.reason ?? "requested"}) ${this.telegramInferenceRequestDiagnostic(requestWithCtx, model)}`
|
|
635574
635717
|
));
|
|
635575
635718
|
}
|
|
635576
635719
|
} else if (typeof streamFn !== "function") {
|
|
@@ -635603,18 +635746,22 @@ ${this.quoteTelegramContextBlock(msg.text, 1200)}`,
|
|
|
635603
635746
|
this.deregisterTelegramInference(id);
|
|
635604
635747
|
}
|
|
635605
635748
|
}
|
|
635606
|
-
telegramBackendDiagnostic() {
|
|
635749
|
+
telegramBackendDiagnostic(modelOverride, routerModelSource, routerModelDetail) {
|
|
635607
635750
|
const config = this.agentConfig;
|
|
635608
635751
|
if (!config) return "backend=unconfigured model=?";
|
|
635609
|
-
|
|
635752
|
+
const model = modelOverride || config.model;
|
|
635753
|
+
const source = routerModelSource ? ` router_model_source=${routerModelSource}` : "";
|
|
635754
|
+
const detail = routerModelDetail ? ` router_model_detail=${compactTelegramRouterDiagnosticText(routerModelDetail, 180)}` : "";
|
|
635755
|
+
const main2 = model !== config.model ? ` main_model=${config.model}` : "";
|
|
635756
|
+
return `backend=${config.backendType} url=${config.backendUrl} model=${model}${main2}${source}${detail}`;
|
|
635610
635757
|
}
|
|
635611
|
-
telegramInferenceRequestDiagnostic(request) {
|
|
635758
|
+
telegramInferenceRequestDiagnostic(request, modelOverride) {
|
|
635612
635759
|
const responseFormat = request.responseFormat ?? request.response_format;
|
|
635613
635760
|
const responseFormatType = responseFormat && typeof responseFormat["type"] === "string" ? responseFormat["type"] : responseFormat ? "present" : "none";
|
|
635614
635761
|
const numCtx = request.numCtx;
|
|
635615
635762
|
const think = request.think;
|
|
635616
635763
|
const tools = Array.isArray(request.tools) ? request.tools.length : 0;
|
|
635617
|
-
return `${this.telegramBackendDiagnostic()} response_format=${responseFormatType} num_ctx=${Number.isFinite(numCtx) ? numCtx : "unset"} think=${think === void 0 ? "default" : String(think)} tools=${tools} timeoutMs=${Number.isFinite(request.timeoutMs) ? request.timeoutMs : "unset"}`;
|
|
635764
|
+
return `${this.telegramBackendDiagnostic(modelOverride)} response_format=${responseFormatType} num_ctx=${Number.isFinite(numCtx) ? numCtx : "unset"} think=${think === void 0 ? "default" : String(think)} tools=${tools} timeoutMs=${Number.isFinite(request.timeoutMs) ? request.timeoutMs : "unset"}`;
|
|
635618
635765
|
}
|
|
635619
635766
|
telegramStreamInactivityDiagnostic(request, inferenceId, inactivityMs, contentChars, thinkingChars) {
|
|
635620
635767
|
const entry = this.telegramActiveInferences.get(inferenceId);
|
|
@@ -635623,7 +635770,7 @@ ${this.quoteTelegramContextBlock(msg.text, 1200)}`,
|
|
|
635623
635770
|
const idle = entry ? `${((now - entry.lastTokenAt) / 1e3).toFixed(1)}s` : "unknown";
|
|
635624
635771
|
const ttfb = entry?.firstChunkAt !== void 0 ? `${((entry.firstChunkAt - entry.startTs) / 1e3).toFixed(1)}s` : "never";
|
|
635625
635772
|
const phase = entry?.firstChunkAt === void 0 ? "before-first-chunk" : "mid-stream";
|
|
635626
|
-
return `stream-inactivity: no chunks for ${(inactivityMs / 1e3).toFixed(0)}s (phase=${phase}; elapsed=${elapsed}; idle=${idle}; ttfb=${ttfb}; content=${contentChars}c thinking=${thinkingChars}c; ${this.telegramInferenceRequestDiagnostic(request)}; stream_endpoint=no-sse-chunk)`;
|
|
635773
|
+
return `stream-inactivity: no chunks for ${(inactivityMs / 1e3).toFixed(0)}s (phase=${phase}; elapsed=${elapsed}; idle=${idle}; ttfb=${ttfb}; content=${contentChars}c thinking=${thinkingChars}c; ${this.telegramInferenceRequestDiagnostic(request, entry?.model)}; stream_endpoint=no-sse-chunk)`;
|
|
635627
635774
|
}
|
|
635628
635775
|
/**
|
|
635629
635776
|
* Drive a chatCompletionStream to exhaustion, accumulating tokens into a
|
|
@@ -636162,6 +636309,114 @@ ${retryText}`,
|
|
|
636162
636309
|
this.dispatchQueuedTelegramSessionWorkSoon();
|
|
636163
636310
|
}
|
|
636164
636311
|
}
|
|
636312
|
+
telegramRouterAutoModelEnabled() {
|
|
636313
|
+
const raw = (process.env["OMNIUS_TG_ROUTER_AUTO_MODEL"] ?? "").trim().toLowerCase();
|
|
636314
|
+
return raw !== "0" && raw !== "false" && raw !== "off";
|
|
636315
|
+
}
|
|
636316
|
+
telegramRouterCandidateModels() {
|
|
636317
|
+
const raw = (process.env["OMNIUS_TG_ROUTER_MODEL_CANDIDATES"] ?? "").trim();
|
|
636318
|
+
const candidates = raw ? raw.split(/[,\s]+/).map((part) => part.trim()).filter(Boolean) : TELEGRAM_DEFAULT_ROUTER_MODEL_CANDIDATES;
|
|
636319
|
+
return Array.from(new Set(candidates));
|
|
636320
|
+
}
|
|
636321
|
+
normalizeOllamaModelNameForMatch(name10) {
|
|
636322
|
+
return name10.trim().toLowerCase().replace(/:latest$/, "");
|
|
636323
|
+
}
|
|
636324
|
+
async fetchOllamaInstalledModelNames(baseUrl) {
|
|
636325
|
+
const url = `${baseUrl.replace(/\/+$/, "")}/api/tags`;
|
|
636326
|
+
const timeoutFn = AbortSignal.timeout;
|
|
636327
|
+
const res = await fetch(url, {
|
|
636328
|
+
signal: typeof timeoutFn === "function" ? timeoutFn(2e3) : void 0
|
|
636329
|
+
});
|
|
636330
|
+
if (!res.ok) throw new Error(`ollama /api/tags returned HTTP ${res.status}`);
|
|
636331
|
+
const data = await res.json();
|
|
636332
|
+
return Array.isArray(data.models) ? data.models.map((model) => typeof model.name === "string" ? model.name : "").filter(Boolean) : [];
|
|
636333
|
+
}
|
|
636334
|
+
async resolveTelegramRouterBackend(config) {
|
|
636335
|
+
const explicit = (process.env["OMNIUS_TG_ROUTER_MODEL"] ?? "").trim();
|
|
636336
|
+
if (explicit && !/^(?:0|false|off|same|main)$/i.test(explicit)) {
|
|
636337
|
+
return {
|
|
636338
|
+
backend: new OllamaAgenticBackend(config.backendUrl, explicit, config.apiKey),
|
|
636339
|
+
model: explicit,
|
|
636340
|
+
source: "env",
|
|
636341
|
+
detail: "OMNIUS_TG_ROUTER_MODEL"
|
|
636342
|
+
};
|
|
636343
|
+
}
|
|
636344
|
+
if (config.backendType !== "ollama" || !this.telegramRouterAutoModelEnabled()) {
|
|
636345
|
+
return {
|
|
636346
|
+
backend: new OllamaAgenticBackend(config.backendUrl, config.model, config.apiKey),
|
|
636347
|
+
model: config.model,
|
|
636348
|
+
source: "main"
|
|
636349
|
+
};
|
|
636350
|
+
}
|
|
636351
|
+
const candidates = this.telegramRouterCandidateModels();
|
|
636352
|
+
const cacheKey = `${config.backendUrl}
|
|
636353
|
+
${config.model}
|
|
636354
|
+
${candidates.join(",")}`;
|
|
636355
|
+
const now = Date.now();
|
|
636356
|
+
if (this.telegramRouterModelCache && this.telegramRouterModelCache.cacheKey === cacheKey && now - this.telegramRouterModelCache.atMs < 6e4) {
|
|
636357
|
+
const cached = this.telegramRouterModelCache;
|
|
636358
|
+
return {
|
|
636359
|
+
backend: new OllamaAgenticBackend(config.backendUrl, cached.model, config.apiKey),
|
|
636360
|
+
model: cached.model,
|
|
636361
|
+
source: cached.source,
|
|
636362
|
+
detail: cached.detail
|
|
636363
|
+
};
|
|
636364
|
+
}
|
|
636365
|
+
try {
|
|
636366
|
+
const installed = await this.fetchOllamaInstalledModelNames(config.backendUrl);
|
|
636367
|
+
const installedByNormalized = /* @__PURE__ */ new Map();
|
|
636368
|
+
for (const name10 of installed) {
|
|
636369
|
+
installedByNormalized.set(this.normalizeOllamaModelNameForMatch(name10), name10);
|
|
636370
|
+
}
|
|
636371
|
+
for (const candidate of candidates) {
|
|
636372
|
+
const selected = installedByNormalized.get(this.normalizeOllamaModelNameForMatch(candidate));
|
|
636373
|
+
if (!selected) continue;
|
|
636374
|
+
const resolved = {
|
|
636375
|
+
cacheKey,
|
|
636376
|
+
atMs: now,
|
|
636377
|
+
model: selected,
|
|
636378
|
+
source: "auto-small",
|
|
636379
|
+
detail: "selected first installed OMNIUS_TG_ROUTER_MODEL_CANDIDATES entry from Ollama /api/tags"
|
|
636380
|
+
};
|
|
636381
|
+
this.telegramRouterModelCache = resolved;
|
|
636382
|
+
return {
|
|
636383
|
+
backend: new OllamaAgenticBackend(config.backendUrl, selected, config.apiKey),
|
|
636384
|
+
model: selected,
|
|
636385
|
+
source: "auto-small",
|
|
636386
|
+
detail: resolved.detail
|
|
636387
|
+
};
|
|
636388
|
+
}
|
|
636389
|
+
} catch (err) {
|
|
636390
|
+
const detail2 = `router model auto-detect failed: ${err instanceof Error ? err.message : String(err)}`;
|
|
636391
|
+
this.telegramRouterModelCache = {
|
|
636392
|
+
cacheKey,
|
|
636393
|
+
atMs: now,
|
|
636394
|
+
model: config.model,
|
|
636395
|
+
source: "main",
|
|
636396
|
+
detail: detail2
|
|
636397
|
+
};
|
|
636398
|
+
return {
|
|
636399
|
+
backend: new OllamaAgenticBackend(config.backendUrl, config.model, config.apiKey),
|
|
636400
|
+
model: config.model,
|
|
636401
|
+
source: "main",
|
|
636402
|
+
detail: detail2
|
|
636403
|
+
};
|
|
636404
|
+
}
|
|
636405
|
+
const detail = "no configured small router model was installed; using main model";
|
|
636406
|
+
this.telegramRouterModelCache = {
|
|
636407
|
+
cacheKey,
|
|
636408
|
+
atMs: now,
|
|
636409
|
+
model: config.model,
|
|
636410
|
+
source: "main",
|
|
636411
|
+
detail
|
|
636412
|
+
};
|
|
636413
|
+
return {
|
|
636414
|
+
backend: new OllamaAgenticBackend(config.backendUrl, config.model, config.apiKey),
|
|
636415
|
+
model: config.model,
|
|
636416
|
+
source: "main",
|
|
636417
|
+
detail
|
|
636418
|
+
};
|
|
636419
|
+
}
|
|
636165
636420
|
async inferTelegramInteractionDecision(msg, toolContext) {
|
|
636166
636421
|
const config = this.agentConfig;
|
|
636167
636422
|
const forcedRoute = this.interactionMode === "chat" || this.interactionMode === "action" ? this.interactionMode : null;
|
|
@@ -636190,11 +636445,8 @@ ${retryText}`,
|
|
|
636190
636445
|
};
|
|
636191
636446
|
return fallback;
|
|
636192
636447
|
}
|
|
636193
|
-
const
|
|
636194
|
-
|
|
636195
|
-
config.model,
|
|
636196
|
-
config.apiKey
|
|
636197
|
-
);
|
|
636448
|
+
const routerBackend = await this.resolveTelegramRouterBackend(config);
|
|
636449
|
+
const backend = routerBackend.backend;
|
|
636198
636450
|
const forcedLine = forcedRoute ? `The operator selected Telegram mode "${forcedRoute}". The route field must be "${forcedRoute}", but should_reply must still be inferred live from context.` : `The operator selected Telegram mode "auto". Infer route live from context.`;
|
|
636199
636451
|
const context2 = this.buildTelegramConversationContextStream(sessionKey, msg, isGroup ? 36 : 20, identitySalienceSignals);
|
|
636200
636452
|
const currentReplyContext = this.buildTelegramCurrentReplyContext(sessionKey, msg);
|
|
@@ -636334,7 +636586,13 @@ ${this.quoteTelegramContextBlock(msg.text, 1200)}`
|
|
|
636334
636586
|
} catch {
|
|
636335
636587
|
}
|
|
636336
636588
|
}
|
|
636337
|
-
const diagnostics = {
|
|
636589
|
+
const diagnostics = {
|
|
636590
|
+
backendType: config.backendType,
|
|
636591
|
+
backendUrl: config.backendUrl,
|
|
636592
|
+
backendModel: routerBackend.model,
|
|
636593
|
+
routerModelSource: routerBackend.source,
|
|
636594
|
+
routerModelDetail: routerBackend.detail
|
|
636595
|
+
};
|
|
636338
636596
|
const routerStartMs = Date.now();
|
|
636339
636597
|
try {
|
|
636340
636598
|
const result = await this.telegramRouterJsonCompletion(backend, {
|
|
@@ -636357,7 +636615,7 @@ ${this.quoteTelegramContextBlock(msg.text, 1200)}`
|
|
|
636357
636615
|
const routerLatencyMs = Date.now() - routerStartMs;
|
|
636358
636616
|
try {
|
|
636359
636617
|
const pidReg = getPidRegistry();
|
|
636360
|
-
const modelKey = this.agentConfig?.model ?? "?";
|
|
636618
|
+
const modelKey = routerBackend.model ?? this.agentConfig?.model ?? "?";
|
|
636361
636619
|
pidReg.sample(`tier1.${modelKey}`, routerLatencyMs);
|
|
636362
636620
|
pidReg.sample(`tier2.${modelKey}`, routerLatencyMs);
|
|
636363
636621
|
} catch {
|
|
@@ -636384,7 +636642,8 @@ ${this.quoteTelegramContextBlock(msg.text, 1200)}`
|
|
|
636384
636642
|
diagnosticNote: this.composeTelegramRouterDiagnosticNote(
|
|
636385
636643
|
void 0,
|
|
636386
636644
|
failureNarrative2,
|
|
636387
|
-
"router produced no visible attention decision content; repair/strict retry skipped for direct private/admin fail-open"
|
|
636645
|
+
"router produced no visible attention decision content; repair/strict retry skipped for direct private/admin fail-open",
|
|
636646
|
+
diagnostics
|
|
636388
636647
|
),
|
|
636389
636648
|
raw: text
|
|
636390
636649
|
}),
|
|
@@ -636458,7 +636717,8 @@ ${this.quoteTelegramContextBlock(msg.text, 1200)}`
|
|
|
636458
636717
|
diagnosticNote: this.composeTelegramRouterDiagnosticNote(
|
|
636459
636718
|
invalidRouterPreview,
|
|
636460
636719
|
failureNarrative,
|
|
636461
|
-
backendLivenessFailure ? "router backend failed during attention-decision recovery; no usable router decision was available" : dualEmptyVisible ? "router returned no visible decision content in JSON or plain mode; repair/strict retry skipped" : invalidRouterPreview ? "router produced an invalid attention decision payload; repair and strict retry did not recover it" : "router produced an empty attention decision payload; strict retry did not recover it"
|
|
636720
|
+
backendLivenessFailure ? "router backend failed during attention-decision recovery; no usable router decision was available" : dualEmptyVisible ? "router returned no visible decision content in JSON or plain mode; repair/strict retry skipped" : invalidRouterPreview ? "router produced an invalid attention decision payload; repair and strict retry did not recover it" : "router produced an empty attention decision payload; strict retry did not recover it",
|
|
636721
|
+
diagnostics
|
|
636462
636722
|
),
|
|
636463
636723
|
raw: text
|
|
636464
636724
|
}), reflectionNotes);
|
|
@@ -636472,7 +636732,8 @@ ${this.quoteTelegramContextBlock(msg.text, 1200)}`
|
|
|
636472
636732
|
diagnosticNote: this.composeTelegramRouterDiagnosticNote(
|
|
636473
636733
|
void 0,
|
|
636474
636734
|
failureNarrative,
|
|
636475
|
-
`router failed before live notes were generated: ${errMsg.slice(0, 160)}
|
|
636735
|
+
`router failed before live notes were generated: ${errMsg.slice(0, 160)}`,
|
|
636736
|
+
diagnostics
|
|
636476
636737
|
)
|
|
636477
636738
|
}), reflectionNotes);
|
|
636478
636739
|
return withRouterTelemetry(fallback);
|
|
@@ -636592,10 +636853,14 @@ ${this.quoteTelegramContextBlock(msg.text, 1200)}`
|
|
|
636592
636853
|
operatorHint
|
|
636593
636854
|
};
|
|
636594
636855
|
}
|
|
636595
|
-
composeTelegramRouterDiagnosticNote(invalidRouterPreview, failureNarrative, headline) {
|
|
636856
|
+
composeTelegramRouterDiagnosticNote(invalidRouterPreview, failureNarrative, headline, diagnostics) {
|
|
636596
636857
|
const segments = [];
|
|
636597
636858
|
segments.push(headline);
|
|
636598
|
-
segments.push(this.telegramBackendDiagnostic(
|
|
636859
|
+
segments.push(this.telegramBackendDiagnostic(
|
|
636860
|
+
diagnostics?.backendModel,
|
|
636861
|
+
diagnostics?.routerModelSource,
|
|
636862
|
+
diagnostics?.routerModelDetail
|
|
636863
|
+
));
|
|
636599
636864
|
if (failureNarrative.summary) segments.push(failureNarrative.summary);
|
|
636600
636865
|
if (invalidRouterPreview) segments.push(`invalid router output preview: ${invalidRouterPreview}`);
|
|
636601
636866
|
if (failureNarrative.detail) segments.push(`router-failure trace: ${failureNarrative.detail}`);
|
|
@@ -641830,10 +642095,12 @@ ${caption}\r
|
|
|
641830
642095
|
/** Long polling loop */
|
|
641831
642096
|
async pollLoop() {
|
|
641832
642097
|
while (this.polling) {
|
|
642098
|
+
const longPollTimeoutSeconds = this.telegramLongPollTimeoutSeconds();
|
|
641833
642099
|
try {
|
|
641834
642100
|
const result = await this.apiCall("getUpdates", {
|
|
641835
642101
|
offset: this.lastUpdateId + 1,
|
|
641836
|
-
timeout:
|
|
642102
|
+
timeout: longPollTimeoutSeconds,
|
|
642103
|
+
limit: 100,
|
|
641837
642104
|
allowed_updates: TELEGRAM_ALLOWED_UPDATES
|
|
641838
642105
|
});
|
|
641839
642106
|
if (result.ok && Array.isArray(result.result)) {
|
|
@@ -641875,7 +642142,7 @@ ${caption}\r
|
|
|
641875
642142
|
if (now - this.telegramPollWarningLastAtMs > 3e4) {
|
|
641876
642143
|
this.telegramPollWarningLastAtMs = now;
|
|
641877
642144
|
this.tuiWrite(() => renderWarning(
|
|
641878
|
-
`Telegram polling warning: getUpdates failed (${err instanceof Error ? err.message : String(err)}); retrying`
|
|
642145
|
+
`Telegram polling warning: getUpdates failed (${err instanceof Error ? err.message : String(err)}); long_poll_timeout=${longPollTimeoutSeconds}s client_deadline_ms=${this.telegramLongPollClientTimeoutMs(longPollTimeoutSeconds) ?? "none"}; retrying`
|
|
641879
642146
|
));
|
|
641880
642147
|
}
|
|
641881
642148
|
await new Promise((r2) => setTimeout(r2, 5e3));
|
|
@@ -641883,10 +642150,17 @@ ${caption}\r
|
|
|
641883
642150
|
}
|
|
641884
642151
|
}
|
|
641885
642152
|
}
|
|
641886
|
-
|
|
642153
|
+
telegramLongPollTimeoutSeconds() {
|
|
642154
|
+
const raw = Number.parseInt(process.env["OMNIUS_TG_LONG_POLL_TIMEOUT_SECONDS"] ?? "", 10);
|
|
642155
|
+
if (Number.isFinite(raw) && raw >= 0 && raw <= 120) return raw;
|
|
642156
|
+
return TELEGRAM_DEFAULT_LONG_POLL_TIMEOUT_SECONDS;
|
|
642157
|
+
}
|
|
642158
|
+
telegramLongPollClientTimeoutMs(serverTimeoutSeconds) {
|
|
641887
642159
|
const raw = Number.parseInt(process.env["OMNIUS_TG_LONG_POLL_CLIENT_TIMEOUT_MS"] ?? "", 10);
|
|
641888
|
-
if (Number.isFinite(raw)
|
|
641889
|
-
|
|
642160
|
+
if (!Number.isFinite(raw)) return null;
|
|
642161
|
+
const floor = Math.max(5e3, Math.floor((serverTimeoutSeconds ?? 0) * 1e3) + 5e3);
|
|
642162
|
+
if (raw >= floor && raw <= 3e5) return raw;
|
|
642163
|
+
return null;
|
|
641890
642164
|
}
|
|
641891
642165
|
/** Make a Telegram Bot API call with rate-limit retry */
|
|
641892
642166
|
async apiCall(method, body, _retryDepth = 0) {
|
|
@@ -641902,9 +642176,11 @@ ${caption}\r
|
|
|
641902
642176
|
if (isLongPoll && this.abortController) {
|
|
641903
642177
|
const timeoutFn = AbortSignal.timeout;
|
|
641904
642178
|
const anyFn = AbortSignal.any;
|
|
642179
|
+
const bodyTimeout = typeof body?.["timeout"] === "number" ? body["timeout"] : void 0;
|
|
642180
|
+
const clientTimeoutMs = this.telegramLongPollClientTimeoutMs(bodyTimeout);
|
|
641905
642181
|
const signals = [
|
|
641906
642182
|
this.abortController.signal,
|
|
641907
|
-
typeof timeoutFn === "function" ? timeoutFn(
|
|
642183
|
+
clientTimeoutMs && typeof timeoutFn === "function" ? timeoutFn(clientTimeoutMs) : void 0
|
|
641908
642184
|
].filter((signal) => signal instanceof AbortSignal);
|
|
641909
642185
|
options2.signal = typeof anyFn === "function" && signals.length > 1 ? anyFn(signals) : signals[0];
|
|
641910
642186
|
} else if (!isLongPoll) {
|
|
@@ -661562,9 +661838,14 @@ async function handleV1ChatCompletions(req2, res, ollamaUrl) {
|
|
|
661562
661838
|
return;
|
|
661563
661839
|
}
|
|
661564
661840
|
const callerProvidedThink = "think" in routedBody;
|
|
661565
|
-
const
|
|
661566
|
-
const finalThink = callerProvidedThink ? routedBody["think"] :
|
|
661841
|
+
const thinkingAllowed = process.env["OMNIUS_ENABLE_THINKING"] === "1" && process.env["OMNIUS_FORCE_NO_THINK"] !== "1";
|
|
661842
|
+
const finalThink = thinkingAllowed && callerProvidedThink ? routedBody["think"] : false;
|
|
661567
661843
|
const ollamaBody = { ...routedBody };
|
|
661844
|
+
if (finalThink === false && Array.isArray(ollamaBody["messages"])) {
|
|
661845
|
+
ollamaBody["messages"] = appendNoThinkDirectivesToMessages(
|
|
661846
|
+
ollamaBody["messages"]
|
|
661847
|
+
);
|
|
661848
|
+
}
|
|
661568
661849
|
const ollamaOptions = ollamaBody["options"] && typeof ollamaBody["options"] === "object" ? { ...ollamaBody["options"] } : {};
|
|
661569
661850
|
if (typeof ollamaBody["max_tokens"] === "number") {
|
|
661570
661851
|
ollamaOptions["num_predict"] = ollamaBody["max_tokens"];
|
|
@@ -663000,6 +663281,7 @@ async function handlePatchConfig(req2, res) {
|
|
|
663000
663281
|
settingsUpdate.voiceMode = updates["voiceMode"];
|
|
663001
663282
|
}
|
|
663002
663283
|
if (typeof updates["telegramKey"] === "string") settingsUpdate.telegramKey = updates["telegramKey"];
|
|
663284
|
+
if (typeof updates["telegramEnabled"] === "boolean") settingsUpdate.telegramEnabled = updates["telegramEnabled"];
|
|
663003
663285
|
if (typeof updates["telegramAdmin"] === "string") settingsUpdate.telegramAdmin = updates["telegramAdmin"];
|
|
663004
663286
|
if (typeof updates["cohere"] === "boolean") settingsUpdate.cohere = updates["cohere"];
|
|
663005
663287
|
if (updates["commandsMode"] === "auto" || updates["commandsMode"] === "manual") {
|
|
@@ -672865,6 +673147,7 @@ Log: ${nexusLogPath}`)
|
|
|
672865
673147
|
const subAgents = typeof source.telegramSubAgents === "number" ? source.telegramSubAgents : typeof savedSettings.telegramSubAgents === "number" ? savedSettings.telegramSubAgents : 2;
|
|
672866
673148
|
return {
|
|
672867
673149
|
key: nonEmptyTelegramSetting(source.telegramKey),
|
|
673150
|
+
enabled: source.telegramEnabled ?? savedSettings.telegramEnabled ?? true,
|
|
672868
673151
|
admin: nonEmptyTelegramSetting(source.telegramAdmin),
|
|
672869
673152
|
mode,
|
|
672870
673153
|
subAgents,
|
|
@@ -673446,6 +673729,20 @@ The user pasted a clipboard image saved at ${relPath}. Use the OCR, vision analy
|
|
|
673446
673729
|
},
|
|
673447
673730
|
// Telegram bridge
|
|
673448
673731
|
async telegramStart(token, adminId, scope = "project") {
|
|
673732
|
+
if (process.env["OMNIUS_TELEGRAM_DISABLED"] === "1") {
|
|
673733
|
+
writeContent(
|
|
673734
|
+
() => renderWarning("Telegram bridge disabled by OMNIUS_TELEGRAM_DISABLED=1.")
|
|
673735
|
+
);
|
|
673736
|
+
showPrompt();
|
|
673737
|
+
return;
|
|
673738
|
+
}
|
|
673739
|
+
if (telegramSettingsForScope(scope).enabled === false) {
|
|
673740
|
+
writeContent(
|
|
673741
|
+
() => renderWarning(`Telegram polling disabled in ${scope} settings. Use /telegram enable${scope === "global" ? " --global" : ""} to allow it.`)
|
|
673742
|
+
);
|
|
673743
|
+
showPrompt();
|
|
673744
|
+
return;
|
|
673745
|
+
}
|
|
673449
673746
|
if (telegramBridge?.isActive) {
|
|
673450
673747
|
writeContent(
|
|
673451
673748
|
() => renderWarning("Telegram bridge already active. Use /telegram stop before restarting.")
|
|
@@ -673654,6 +673951,9 @@ Respond concisely and safely. Remember: you are talking to the general public.`;
|
|
|
673654
673951
|
if (settings.key !== void 0) {
|
|
673655
673952
|
target.telegramKey = settings.key;
|
|
673656
673953
|
}
|
|
673954
|
+
if (settings.enabled !== void 0) {
|
|
673955
|
+
target.telegramEnabled = settings.enabled;
|
|
673956
|
+
}
|
|
673657
673957
|
if (settings.admin !== void 0) {
|
|
673658
673958
|
target.telegramAdmin = settings.admin === null ? "" : settings.admin;
|
|
673659
673959
|
}
|
|
@@ -673665,6 +673965,7 @@ Respond concisely and safely. Remember: you are talking to the general public.`;
|
|
|
673665
673965
|
}
|
|
673666
673966
|
const payload = {
|
|
673667
673967
|
...settings.key !== void 0 ? { telegramKey: settings.key } : {},
|
|
673968
|
+
...settings.enabled !== void 0 ? { telegramEnabled: settings.enabled } : {},
|
|
673668
673969
|
...settings.admin !== void 0 ? { telegramAdmin: settings.admin === null ? "" : settings.admin } : {},
|
|
673669
673970
|
...settings.mode !== void 0 ? { telegramMode: settings.mode } : {},
|
|
673670
673971
|
...settings.subAgents !== void 0 ? { telegramSubAgents: settings.subAgents } : {}
|
|
@@ -673719,6 +674020,10 @@ Respond concisely and safely. Remember: you are talking to the general public.`;
|
|
|
673719
674020
|
queuedSubAgents
|
|
673720
674021
|
)
|
|
673721
674022
|
);
|
|
674023
|
+
const effectiveTelegramSettings = telegramSettingsForScope(activeTelegramSettingsScope ?? "project");
|
|
674024
|
+
if (effectiveTelegramSettings.enabled === false || process.env["OMNIUS_TELEGRAM_DISABLED"] === "1") {
|
|
674025
|
+
writeContent(() => renderInfo("Telegram polling is disabled; auto-start and manual start are blocked."));
|
|
674026
|
+
}
|
|
673722
674027
|
},
|
|
673723
674028
|
telegramBeginAdminAuth() {
|
|
673724
674029
|
if (!telegramBridge?.isActive) return null;
|
|
@@ -675104,7 +675409,7 @@ Respond concisely and safely. Remember: you are talking to the general public.`;
|
|
|
675104
675409
|
}
|
|
675105
675410
|
}
|
|
675106
675411
|
const autoTelegramSettings = telegramSettingsForScope("project");
|
|
675107
|
-
if (!isResumed && autoTelegramSettings.key) {
|
|
675412
|
+
if (!isResumed && autoTelegramSettings.key && autoTelegramSettings.enabled !== false && process.env["OMNIUS_TELEGRAM_DISABLED"] !== "1") {
|
|
675108
675413
|
setTimeout(async () => {
|
|
675109
675414
|
try {
|
|
675110
675415
|
await commandCtx.telegramStart(
|
|
@@ -677335,6 +677640,7 @@ var init_config6 = __esm({
|
|
|
677335
677640
|
updateMode: "Update behaviour: auto (after task completion) or manual (/update only)",
|
|
677336
677641
|
// -- Integrations --
|
|
677337
677642
|
telegramKey: "Telegram bot API token for /telegram bridge",
|
|
677643
|
+
telegramEnabled: "Enable Telegram long polling / bridge auto-start (true/false)",
|
|
677338
677644
|
telegramAdmin: "Telegram admin user ID — only this user can interact with the bot"
|
|
677339
677645
|
};
|
|
677340
677646
|
SENSITIVE_KEYS = /* @__PURE__ */ new Set(["apiKey", "api_key", "secret", "password", "token", "telegramKey"]);
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "omnius",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.185",
|
|
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.185",
|
|
10
10
|
"bundleDependencies": [
|
|
11
11
|
"image-to-ascii"
|
|
12
12
|
],
|
package/package.json
CHANGED